* Deepen query dispatch seam with command topology module * Stabilize SDK parity defaults and integration test gating * docs(architecture): record pre-project config policy and e2e gate * refactor(query): stop injecting native adapter in CLI dispatch path * fix(config): align workflow auto-chain typing and docs
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { normalizeQueryCommand } from './query-command-resolution-strategy.js';
|
|
import type { CommandTopology, CommandTopologyMatch } from './command-topology.js';
|
|
|
|
export type DispatchMode = 'native' | 'cjs' | 'error';
|
|
|
|
export interface DispatchPlan {
|
|
mode: DispatchMode;
|
|
normalized: { command: string; args: string[]; tokens: string[] };
|
|
matched: CommandTopologyMatch | null;
|
|
noMatchMessage?: string;
|
|
noMatchNormalized?: string;
|
|
noMatchAttempted?: string[];
|
|
noMatchHints?: string[];
|
|
}
|
|
|
|
export function planQueryDispatch(
|
|
queryArgv: string[],
|
|
topology: CommandTopology,
|
|
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 resolved = topology.resolve(queryArgv, !cjsFallbackEnabled);
|
|
|
|
if (resolved.kind === 'match') {
|
|
return { mode: 'native', normalized: { command: normCmd, args: normArgs, tokens: normalizedTokens }, matched: resolved };
|
|
}
|
|
|
|
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,
|
|
noMatchMessage: resolved.message,
|
|
noMatchNormalized: resolved.normalized,
|
|
noMatchAttempted: resolved.attempted,
|
|
noMatchHints: resolved.hints,
|
|
};
|
|
}
|