fix(query/agent-skills): emit raw <agent_skills> block instead of JSON-wrapped string (#2917)
* fix(query/agent-skills): emit raw <agent_skills> block instead of JSON-wrapped string The CLI dispatcher (`cli.ts`) JSON-stringifies all query handler results via `console.log(JSON.stringify(result.data, null, 2))`. For the `agent-skills` handler this produced a JSON-quoted string literal — e.g. `"<agent_skills>\n…</agent_skills>"` — which workflows embedded verbatim via `$(gsd-sdk query agent-skills gsd-planner)`, breaking all `<agent_skills>` injection into spawned subagent prompts. Fix: add an optional `format: 'json' | 'text'` field to `QueryResult`. When a handler returns `format: 'text'` and `--pick` is not active, the CLI writes the string directly via `process.stdout.write` instead of JSON-stringifying it. `agentSkills` sets `format: 'text'` for non-empty blocks. Regression guard: two new CLI integration tests in `skills.test.ts` spawn the CLI as a child process and assert that (a) a mapped agent type receives the raw XML block on stdout and (b) an unmapped agent type produces the existing JSON empty-string output. Fixes #2914. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * docs(changelog): add #2917 entry under Unreleased Fixed --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,16 @@ import { GSDError, ErrorClassification } from '../errors.js';
|
||||
/** Structured result returned by all query handlers. */
|
||||
export interface QueryResult<T = unknown> {
|
||||
data: T;
|
||||
/**
|
||||
* Output format hint for the CLI dispatcher.
|
||||
* `'text'` — write `data` as-is to stdout (no JSON-stringify).
|
||||
* `'json'` (default) — JSON-stringify as usual.
|
||||
*
|
||||
* Only meaningful when `data` is a string and the consumer is the CLI.
|
||||
* Used by `agent-skills` so workflows embedding `$(gsd-sdk query …)` receive
|
||||
* a raw `<agent_skills>` XML block rather than a JSON-quoted string.
|
||||
*/
|
||||
format?: 'json' | 'text';
|
||||
}
|
||||
|
||||
/** Signature for a query handler function. */
|
||||
|
||||
Reference in New Issue
Block a user