Adds the gh-style `--json[=field1,field2] --jq <expr>` contract on top of the
existing boolean `--json` flag.
- `AgentCommandMeta.jsonFields` declares the allowlist per command.
- `extractJsonFlag` parses both `--json` and `--json=<fields>` forms; the
comma-list is validated against the meta's allowlist in index.ts at parse
time. Unknown field exits with `Unknown JSON field` + a sorted
"Available fields:" suggestion list and status 2.
- `extractJqFlag` strips `--jq <expr>` before cmd-ts sees it. `--jq` requires
`--json` (rejected with status 2 otherwise).
- `jsonOutput` applies the field projection on the envelope: when `data` has
a single top-level array of objects, the allowlist filters each item;
otherwise it projects the top-level data object directly.
- `--jq` pipes the (post-projection) envelope through the system `jq`
binary via `spawnSync`. Failures surface as `Error: --jq failed: <msg>`,
not a raw stderr dump.
- `agent-help.formatForAgent` now emits `json_fields` when the meta declares
one, so agents can discover the allowlist via `--agent-help`.
- `findMetaByCommand` exported from agent-help so index.ts can do the lookup
for validation.
- Skills list meta now declares `jsonFields: ['name','plugin','disabled']`.
Plumbed through two pre-existing pieces:
- Carries the #371 fix (skills metas wired into agent-help; correct
`command:` labels) since the new validation depends on the meta path
matching the runtime command.
- Fixes `addPlugin` and `getAllSkillsFromPlugins` so they pass `workspacePath`
through to `resolvePluginSpecWithAutoRegister`. Without it, project-scope
marketplaces are invisible to the resolver and the verification gate's
install fails.
Verified end-to-end against `obra/superpowers`:
- Boolean `--json skills list` returns the full envelope.
- `--json=name,plugin skills list` narrows `.data.skills[*]` to those keys.
- `--json=bogus skills list` exits 2 with `Unknown JSON field` + sorted list.
- `--json --jq '.data.skills | map(.name)' skills list` pipes through jq.
- `--jq` without `--json` exits 2.
- `--agent-help "skills list"` exposes `json_fields` as an array.
Closes #376
Summary
Brings the gh-style
--json[=field1,field2] --jq <expr>contract toallagents:AgentCommandMeta.jsonFieldsdeclares a per-command allowlist.--json=<fields>is validated against it at parse time; an unknown field exits 2 with a sortedAvailable fields:suggestion list.--jq <expr>pipes the envelope through the systemjqbinary (spawnSync, errors surfaced asError: --jq failed: <msg>rather than raw stderr).--jqrequires--json.datahas a single top-level array of objects, the allowlist narrows each item; otherwise it projects the top-leveldatadirectly.--agent-helpnow emitsjson_fieldswhen a meta declares an allowlist, so agents can discover the contract.command:label correction, so the runtime command path (skills list) matches the meta path used for validation.addPlugin/getAllSkillsFromPluginsnow threadworkspacePathtoresolvePluginSpecWithAutoRegister— without it, project-scope marketplaces (used byobra/superpowers) are invisible and the install in the gate fails before list can return any skills.Test plan
bun run build,bun run typecheckbun test— 1191 pass / 0 fail--jsonfield allowlist with--jq/--templatefilters per command #376 (using stableobra/superpowers):--json skills listreturns full envelope withdata.skillsarray.--json=name,plugin skills list→.data.skills[0] | keys == ["name","plugin"].--json=bogus skills list→ exit 2,Unknown JSON field+Available fieldsprinted.--json --jq '.data.skills | map(.name)' skills list→ pipes through jq, returns array.--jqwithout--json→ exit 2.--agent-help "skills list"exposesjson_fieldsas an array.Closes #376