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:
32
sdk/src/query/query-command-diagnosis.ts
Normal file
32
sdk/src/query/query-command-diagnosis.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { explainQueryCommandNoMatch, type QueryCommandRegistryLike } from './query-command-semantics.js';
|
||||
import { UNKNOWN_COMMAND_HINTS } from './query-unknown-command-hints.js';
|
||||
import { describeFallbackDisabledPolicy } from './query-fallback-policy.js';
|
||||
|
||||
export interface UnknownCommandDiagnosis {
|
||||
normalized: string;
|
||||
attempted: string[];
|
||||
hints: string[];
|
||||
message: string;
|
||||
}
|
||||
|
||||
export function diagnoseUnknownCommand(
|
||||
command: string,
|
||||
args: string[],
|
||||
registry: QueryCommandRegistryLike,
|
||||
fallbackRestricted: boolean,
|
||||
): UnknownCommandDiagnosis {
|
||||
const noMatch = explainQueryCommandNoMatch(command, args, registry);
|
||||
const normalized = [noMatch.normalized.command, ...noMatch.normalized.args].join(' ');
|
||||
const attempted = noMatch.attempted.dotted.slice(0, 2);
|
||||
const hints = [...UNKNOWN_COMMAND_HINTS];
|
||||
const attemptedSuffix = attempted.length > 0 ? ` Attempted dotted: ${attempted.join(' | ')}.` : '';
|
||||
const fallbackClause = fallbackRestricted ? `${describeFallbackDisabledPolicy()} ` : '';
|
||||
const message = `Error: Unknown command: "${normalized}". ${hints[0]} ${hints[1]} ${fallbackClause}${hints[2]}${attemptedSuffix}`;
|
||||
|
||||
return {
|
||||
normalized,
|
||||
attempted,
|
||||
hints,
|
||||
message,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user