* 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
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import type { QueryRegistry } from './registry.js';
|
|
import {
|
|
normalizeQueryCommand,
|
|
resolveQueryCommand,
|
|
type QueryCommandResolution,
|
|
} from './query-command-resolution-strategy.js';
|
|
|
|
export type DispatchMode = 'native' | 'cjs' | 'error';
|
|
|
|
export interface DispatchPlan {
|
|
mode: DispatchMode;
|
|
normalized: { command: string; args: string[]; tokens: string[] };
|
|
matched: QueryCommandResolution | null;
|
|
}
|
|
|
|
export function planQueryDispatch(
|
|
queryArgv: string[],
|
|
registry: QueryRegistry,
|
|
cjsFallbackEnabled: boolean,
|
|
): DispatchPlan {
|
|
const queryCommand = queryArgv[0];
|
|
if (!queryCommand) {
|
|
return { mode: 'error', normalized: { command: '', args: [], tokens: [] }, matched: null };
|
|
}
|
|
|
|
const [normCmd, normArgs] = normalizeQueryCommand(queryCommand, queryArgv.slice(1));
|
|
const normalizedTokens = [normCmd, ...normArgs];
|
|
const matched = resolveQueryCommand(queryCommand, queryArgv.slice(1), registry);
|
|
if (matched) {
|
|
return { mode: 'native', normalized: { command: normCmd, args: normArgs, tokens: normalizedTokens }, matched };
|
|
}
|
|
if (cjsFallbackEnabled) {
|
|
return { mode: 'cjs', normalized: { command: normCmd, args: normArgs, tokens: normalizedTokens }, matched: null };
|
|
}
|
|
return { mode: 'error', normalized: { command: normCmd, args: normArgs, tokens: normalizedTokens }, matched: null };
|
|
}
|