* refactor(query): deepen command definition seam and fold fallback mapping cleanup * refactor(query): add shared dispatch formatting module seam * fix(query): restore QueryResult type import in dispatch deps * test/query: align raw-output policy and definition normalization contracts * refactor(query): deepen diagnosis, invariant report, and error taxonomy seams * refactor(query): deepen dispatch plan, fallback bridge, policy snapshot, and hints seams * refactor(query): deepen validation, fallback policy, capability, and result builder seams * refactor(query): deepen resolution strategy, output classifier, observability, and policy-capability seams * refactor(query): finalize deep strategy/classifier/observability/capability seams * test/query: address coderabbit inline and out-of-diff dispatch nits * fix(query): address remaining coderabbit input-validation and bridge stderr threads * fix(query): address remaining coderabbit dispatch and strategy/output nits
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { formatSuccess } from './query-dispatch-formatting.js';
|
|
import type { QueryDispatchResult } from './query-dispatch-contract.js';
|
|
import { mapFallbackDispatchError, toDispatchFailure } from './query-dispatch-error-mapper.js';
|
|
import { runFallbackBridge } from './query-fallback-bridge-adapter.js';
|
|
import { fallbackBridgeNotices } from './query-dispatch-observability.js';
|
|
|
|
export interface RunCjsFallbackDispatchInput {
|
|
projectDir: string;
|
|
gsdToolsPath: string;
|
|
normCmd: string;
|
|
normArgs: string[];
|
|
ws?: string;
|
|
pickField?: string;
|
|
}
|
|
|
|
|
|
function formatFallbackOutput(data: unknown, mode: 'json' | 'text', pickField?: string): string | undefined {
|
|
if (mode === 'text') {
|
|
const text = String(data ?? '');
|
|
if (!text.trim()) return undefined;
|
|
}
|
|
return formatSuccess(data, mode, pickField);
|
|
}
|
|
|
|
export async function runCjsFallbackDispatch(input: RunCjsFallbackDispatchInput): Promise<QueryDispatchResult> {
|
|
const { projectDir, gsdToolsPath, normCmd, normArgs, ws, pickField } = input;
|
|
const stderr = fallbackBridgeNotices(normCmd);
|
|
|
|
try {
|
|
const fallback = await runFallbackBridge({ projectDir, gsdToolsPath, normCmd, normArgs, ws });
|
|
if (fallback.stderr.trim()) stderr.push(fallback.stderr.trimEnd());
|
|
return {
|
|
ok: true,
|
|
stderr,
|
|
stdout: formatFallbackOutput(fallback.output, fallback.mode, pickField) ?? '',
|
|
exit_code: 0,
|
|
};
|
|
} catch (err) {
|
|
return toDispatchFailure(
|
|
mapFallbackDispatchError(err, normCmd, normArgs),
|
|
stderr,
|
|
);
|
|
}
|
|
}
|