feat(cli): phase-1 gaps — TOON output, mcp create, monit-query/agent, plural --channel#11
Merged
Conversation
Migrate from singular Int64Var to StringVar + parseIntSlice, routing through ListChangesInput.ChannelIDs []int64 to match the MCP surface and mirror the existing alert list --channel pattern.
Move --server-name empty-check inside runCommand closure to match the project convention established in alert.go (validation flows through the same error formatter as all other business-logic errors). Rewrite TestMCPCreateRejectsEmptyServerName to use execCommand + mockClient injection so it survives the guard moving inside runCommand without depending on real config or network. Add TestParseKVSlice table-driven tests covering nil/empty/single/multi/ value-with-equals/empty-value/empty-key/missing-equals cases.
Two-step on-box diagnostics surface: `catalog` discovers tools per target via /monit/tools/catalog, `invoke` runs up to 8 of them concurrently via /monit/tools/invoke. --tool-spec uses StringArray so params=<json> bodies with commas survive intact. Side-fix: extend test-helper resetFlagSet to also clear stringSlice and stringArray flags between execCommand calls; without it, a later test sees leftover repeated --flag entries from earlier ones.
CI failures since Phase 1 (commit f86006c) traced to a local-path replace directive that pointed at /Users/ysy/go/src/github.com/flashcatcloud/ flashduty-sdk — fine for the workstation that authored it, fatal for GitHub Actions runners that have no such path. The CLI legitimately depends on unreleased SDK methods (Phase 1's CreateMCPServer + Phase 2's MonitQuery / MonitAgent). Until both underlying SDK PRs (#12 mcp-server-create, #13 monit-types) merge and a v0.10.0 tag ships, we pin to a pseudo-version of the integration branch flashduty-sdk@dev/sdk-cli-phase2-deps (HEAD 3203385), which merges both feature branches together. Resolves to: v0.9.1-0.20260527160039-3203385df5ad When SDK v0.10.0 tags, the next commit on this PR just bumps the require to v0.10.0 and we delete the integration branch — no other CLI code change needed. The replace directive does not return.
Adds `--output-format table|json|toon` (persistent), with `--json` kept as
an alias for `--output-format json`. TOON (Token-Oriented Object Notation)
drops the per-row repeated keys JSON emits for uniform arrays — materially
fewer tokens for list output, which matters when an LLM agent consumes the
CLI's stdout.
Routes through sdk.Marshal(v, OutputFormatTOON) so the encoding is identical
to the Flashduty MCP server's toon path — one source of truth. The JSON path
is untouched (still indented via json.MarshalIndent), so existing `--json`
consumers get byte-identical output.
Mechanics:
- internal/output: Format enum {Table,JSON,TOON} + Structured() helper;
NewPrinter takes a Format; new TOONPrinter.
- internal/cli: resolveOutputFormat() (—output-format wins, —json alias,
unknown value errors via PersistentPreRunE so a typo fails fast);
marshalStructured() shared by WriteResultJSON / writeResult / whoami;
RunContext.JSON bool replaced by Format + Structured() — all command
sites that gated "machine vs human" now honor TOON too.
Tests: TOONPrinter key-dedup vs row count; resolveOutputFormat matrix
incl. invalid→error; existing printer tests migrated to the Format arg.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase-1 gap-closing for the fc-safari ai-sre agent path (see fc-safari PR #74 for the consumer side). Five additions to the
flashdutyCLI:--output-format toon— a token-efficient output mode for the LLM agent.mcp create— register an MCP server from the CLI.monit-query diagnose|rows+monit-agent catalog|invoke— datasource-side and on-box diagnostics subcommands the AI-SRE skills drive.change list --channel— comma-separated IDs (plural), matchingalert list.1. TOON output mode (
7da8c5b3)The agent reads CLI output as tokens. JSON repeats every key on every row of a list; TOON (Token-Oriented Object Notation) emits the key set once and then bare rows, so a 50-incident list costs far fewer tokens. This mirrors how the Flashduty MCP server already exposes TOON.
internal/output/format.go— newtype Format int{FormatTable,FormatJSON,FormatTOON} withStructured()(true for JSON + TOON).internal/output/toon.go—TOONPrinterdelegates toflashduty-sdk'sMarshal(data, sdk.OutputFormatTOON)(the SDK already vendorstoon-go; the CLI is thin wiring, not a new encoder).internal/cli/root.go— new persistent--output-format table|json|toonflag (inherited by every subcommand).--jsonis kept as an alias for--output-format json.resolveOutputFormat()makes--output-formatwin, falls back to--json, and errors on an unknown value (validated inPersistentPreRunE).marshalStructured()routes TOON throughsdk.Marshaland keepsjson.MarshalIndentfor the JSON path.internal/cli/command.go—RunContext.JSON boolbecameFormat output.Format+ aStructured()method; all list/total/result printers switch on it.JSON output is byte-for-byte unchanged — only TOON is new. Existing
--jsonconsumers and pipelines are unaffected.Tests:
internal/cli/output_format_test.go(resolution matrix incl. invalid→error),internal/output/toon_test.go(key-dedup vs row count), and the existing printer tests migrated to theFormatAPI.2.
mcp create(f86006c3, polished in5cca6fb2)New command under a new
mcpgroup. Registers an MCP server viaflashduty-sdk.CreateMCPServer. 11 flags:--server-name --description --transport --command --args --env --url --headers --connect-timeout --call-timeout --team-id.--envand--headersaccept repeatableKEY=VALUEparsed via a new sharedparseKVSlicehelper (8-case table test: nil / empty / single / multi / value-with-equals / empty-value / empty-key / missing-equals). Validation lives inside therunCommandclosure for uniform error rendering; the test exercises the actualRunEpath via thesaveAndResetGlobals+mockClientfixture.3. monit-query / monit-agent subcommands (
c04b7414,a09fa2c7)flashduty monit-query diagnose|rows— pre-clustered RCA findings and raw passthrough against a backing datasource.flashduty monit-agent catalog|invoke— discover and batch-run on-box diagnostic tools on a target host / mysql instance.These back the
monit-query/monit-agentAI-SRE skills.4.
change list --channelplural (9b542528)Migrated from singular
Int64Varto comma-separatedStringVar, routed through the SDK'sListChangesInput.ChannelIDs []int64. Mirrorsalert list --channel(already plural) so both commands share filter semantics and match the MCPquery_changes.channel_idsschema.Test plan
go test ./... -count=1green (incl. TOON + resolution tests)make checkclean (fmt + lint + test + build)bin/flashduty incident list --helpshows the inherited--output-formatflagbin/flashduty mcp create --helpshows all 11 flagsbin/flashduty change list --channel 100,200 --since 1h --output-format toonagainst a dev account routes throughchannel_idsGOOS=linux GOARCH=amd64 make build && file bin/flashdutyreportsELF 64-bit ... x86-64— needed by the fc-safari sandbox image bake