refactor(query): deepen runtime context/native adapter/output seams (#3076)
* refactor(query): deepen runtime context, native adapter, and cli output seams * chore(changeset): add fragment for query seam deepening continuation * refactor(query): converge internal command-resolution imports on canonical seam * refactor(query): remove dead seam wrappers and converge on canonical modules * docs(architecture): update context and adr for query seam completion * fix(query): preserve gsd-tools stderr in cli output and clarify static ws test scope * test(query): cover whitespace stderr and null exitCode fallback
This commit is contained in:
35
sdk/src/query/query-cli-output.ts
Normal file
35
sdk/src/query/query-cli-output.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { GSDError, exitCodeFor } from '../errors.js';
|
||||
import { GSDToolsError } from '../gsd-tools.js';
|
||||
import type { QueryDispatchResult } from './query-dispatch-contract.js';
|
||||
|
||||
export interface QueryCliAdapterOutput {
|
||||
exitCode: number;
|
||||
stdoutChunks: string[];
|
||||
stderrLines: string[];
|
||||
}
|
||||
|
||||
export function buildQueryCliOutputFromDispatch(out: QueryDispatchResult): QueryCliAdapterOutput {
|
||||
const stderrLines = [...out.stderr];
|
||||
const stdoutChunks: string[] = [];
|
||||
if (!out.ok) {
|
||||
stderrLines.push(out.error.message);
|
||||
return { exitCode: out.exit_code, stdoutChunks, stderrLines };
|
||||
}
|
||||
if (out.stdout) stdoutChunks.push(out.stdout);
|
||||
return { exitCode: 0, stdoutChunks, stderrLines };
|
||||
}
|
||||
|
||||
export function buildQueryCliOutputFromError(err: unknown): QueryCliAdapterOutput {
|
||||
const stdoutChunks: string[] = [];
|
||||
if (err instanceof GSDError) {
|
||||
return { stderrLines: [`Error: ${err.message}`], exitCode: exitCodeFor(err.classification), stdoutChunks };
|
||||
}
|
||||
if (err instanceof GSDToolsError) {
|
||||
// Prefer raw subprocess stderr when available so users see the original tool diagnostics.
|
||||
const stderrLines = err.stderr && err.stderr.trim().length > 0
|
||||
? err.stderr.split(/\r?\n/).filter(line => line.length > 0)
|
||||
: [`Error: ${err.message}`];
|
||||
return { stderrLines, exitCode: err.exitCode ?? 1, stdoutChunks };
|
||||
}
|
||||
return { stderrLines: [`Error: ${err instanceof Error ? err.message : String(err)}`], exitCode: 1, stdoutChunks };
|
||||
}
|
||||
Reference in New Issue
Block a user