refactor(query): deepen command/dispatch seams and resolve coderabbit findings
* 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
This commit is contained in:
31
sdk/src/query/query-fallback-output-classifier.ts
Normal file
31
sdk/src/query/query-fallback-output-classifier.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
export interface FallbackOutputClassification {
|
||||
mode: 'json' | 'text';
|
||||
output: unknown;
|
||||
}
|
||||
|
||||
async function parseCliQueryJsonOutput(raw: string, projectDir: string): Promise<unknown> {
|
||||
const trimmed = raw.trim();
|
||||
if (trimmed === '') return null;
|
||||
let jsonStr = trimmed;
|
||||
if (jsonStr.startsWith('@file:')) {
|
||||
const rel = jsonStr.slice(6).trim();
|
||||
const { resolvePathUnderProject } = await import('./helpers.js');
|
||||
const filePath = await resolvePathUnderProject(projectDir, rel);
|
||||
jsonStr = await readFile(filePath, 'utf-8');
|
||||
}
|
||||
return JSON.parse(jsonStr);
|
||||
}
|
||||
|
||||
export async function classifyFallbackOutput(raw: string, projectDir: string): Promise<FallbackOutputClassification> {
|
||||
if (raw.trim() === '') {
|
||||
return { mode: 'text', output: raw };
|
||||
}
|
||||
try {
|
||||
const output = await parseCliQueryJsonOutput(raw, projectDir);
|
||||
return { mode: 'json', output };
|
||||
} catch {
|
||||
return { mode: 'text', output: raw };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user