* 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
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { TRANSPORT_RAW_COMMANDS } from './query/query-policy-capability.js';
|
|
|
|
export type TransportMode = 'json' | 'raw';
|
|
|
|
export interface TransportPolicy {
|
|
preferNative: boolean;
|
|
allowFallbackToSubprocess: boolean;
|
|
outputMode: TransportMode;
|
|
}
|
|
|
|
const DEFAULT_POLICY: TransportPolicy = {
|
|
preferNative: true,
|
|
allowFallbackToSubprocess: true,
|
|
outputMode: 'json',
|
|
};
|
|
|
|
const BUILTIN_COMMAND_POLICY: Record<string, Partial<TransportPolicy>> = Object.fromEntries(
|
|
TRANSPORT_RAW_COMMANDS.map((command) => [command, { outputMode: 'raw' as const }]),
|
|
);
|
|
|
|
const COMMAND_POLICY_OVERRIDES: Record<string, Partial<TransportPolicy>> = {};
|
|
|
|
export function resolveTransportPolicy(command: string): TransportPolicy {
|
|
const override = {
|
|
...(BUILTIN_COMMAND_POLICY[command] ?? {}),
|
|
...(COMMAND_POLICY_OVERRIDES[command] ?? {}),
|
|
};
|
|
return {
|
|
preferNative: override.preferNative ?? DEFAULT_POLICY.preferNative,
|
|
allowFallbackToSubprocess:
|
|
override.allowFallbackToSubprocess ?? DEFAULT_POLICY.allowFallbackToSubprocess,
|
|
outputMode: override.outputMode ?? DEFAULT_POLICY.outputMode,
|
|
};
|
|
}
|
|
|
|
export function setTransportPolicy(command: string, override: Partial<TransportPolicy>): void {
|
|
COMMAND_POLICY_OVERRIDES[command] = { ...(COMMAND_POLICY_OVERRIDES[command] ?? {}), ...override };
|
|
}
|
|
|
|
export function clearTransportPolicy(command?: string): void {
|
|
if (command) {
|
|
delete COMMAND_POLICY_OVERRIDES[command];
|
|
return;
|
|
}
|
|
for (const key of Object.keys(COMMAND_POLICY_OVERRIDES)) {
|
|
delete COMMAND_POLICY_OVERRIDES[key];
|
|
}
|
|
}
|