feat(monit-agent): accept --data body from stdin; drop --tool-spec DSL#34
Open
ysyneu wants to merge 1 commit into
Open
feat(monit-agent): accept --data body from stdin; drop --tool-spec DSL#34ysyneu wants to merge 1 commit into
ysyneu wants to merge 1 commit into
Conversation
The bespoke `--tool-spec 'name=<tool>,params={json}'` parser split each spec
on ',', shattering any params JSON containing commas (e.g. SQL `SELECT a, b`)
into "missing '=' in" errors, and forced shell-quoting hell for quoted SQL.
End-state, no transitional code:
- CLI-wide: `--data` now accepts `-` to read the JSON body from STDIN, in
addition to inline JSON. Resolved in genAssembleBody (the shared body
chokepoint), so all generated `--data` commands gain it uniformly. STDIN is
read ONLY when --data is exactly "-", never auto-read, so flag-only commands
don't block on an empty pipe.
- `monit-agent invoke`: removed the `--tool-spec` flag and parseToolSpecs.
Tools now come via the standard `--data` body
`{"tools":[{"tool":"<name>","params":{...}}, ...]}`, with `--target-locator`
(required) and `--target-kind` as typed flags that stamp the body. The 8-tool
cap and three-layer error handling are unchanged; the webapi wire shape is
unchanged server-side.
- Deleted parseToolSpecs and its docstring (parseKVSlice untouched).
- Regenerated zz_generated_*.go for the updated --data usage string.
The fc-safari monit-agent skill docs are updated in a separate PR to match.
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.
Problem
fduty monit-agent invokeused a repeatable--tool-spec 'name=<tool>,params={json}'flag. Its parser (parseToolSpecs) didstrings.Split(s, ","), which shattered anyparamsJSON containing commas (e.g. SQLSELECT a, b), producingError: invalid --tool-spec: missing '=' in " b". It also forced shell-quoting hell for SQL with quotes.End-state (no transitional code)
Fold
monit-agent invokeinto the standard--databody convention and make the whole CLI's--dataflag accept stdin.--datastdin source.--data -now reads the JSON body from STDIN, alongside inline--data '<json>'. Resolved once ingenAssembleBody(the shared body-assembly chokepoint ingen_support.go), so all 250 generated--datacommands gain it uniformly — not a per-command special case. STDIN is read only when--datais exactly-; it is never auto-read when--datais absent, so flag-only commands don't block on an empty pipe.monit-agent invokedrops the--tool-specflag and theparseToolSpecscall. Tools are now carried in the--databody{"tools":[{"tool":"<name>","params":{...}}, ... up to 8]}, with--target-locator(required) and--target-kind(optional) staying as typed flags that stamp the body (typed flags override matching--datakeys, mirroringgenAssembleBody). The "max 8 tools" check and the three-layer response/error handling are unchanged. The webapi request shape is unchanged server-side — only the client-side assembly oftoolschanged.parseToolSpecs(and its docstring).parseKVSliceleft untouched.New invocation shape
A no-arg tool:
{"tools":[{"tool":"os.overview"}]}.Verification
go build ./...— clean.go test -race ./...— all packages pass.monit_agent_test.go: happy-path via--data; a regression test proving aparamsvalue with an internal comma (SELECT a, b FROM t WHERE s='RUNNING') survives intact (the exact thing that broke before); a--data -stdin test; flag-overrides---data; malformed---datatable (invalid JSON, non-array tools, non-object entry, missing tool name, non-object params);>8tools rejected; missing locator/tools rejected; and an assertion that--tool-specno longer exists.command_test.goon a generated command (monit datasource-list):--data -reads stdin; inline--data+ typed-flag override; and a sentinel reader proving stdin is not read when--datais absent.gofmt/gci/go vetclean; generated files regenerated (only the--datausage string changed — verified zero other churn).monit-agent invoke --help: shows--dataand the heredoc form, no--tool-spec. Ran a real heredoc-over-stdin invocation against a local stub and confirmed the comma+quote SQL round-tripped intact into the request body.Note
The fc-safari
monit-agentskill docs are updated in a separate PR to match this new invocation shape.