feat(S-401): Test-drive and implement src/dispatch.ts
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import type { ClientName } from "./types.js";
|
||||
|
||||
export interface DispatchConfig {
|
||||
defaultClient?: ClientName;
|
||||
client?: ClientName;
|
||||
}
|
||||
|
||||
const CLIENT_NAMES: ClientName[] = ["codex", "claude", "opencode"];
|
||||
|
||||
export function resolveClient(
|
||||
prompt: string,
|
||||
config?: DispatchConfig
|
||||
): ClientName | null {
|
||||
// Explicit --client flag takes highest precedence
|
||||
if (config?.client && CLIENT_NAMES.includes(config.client)) {
|
||||
return config.client;
|
||||
}
|
||||
|
||||
const lower = prompt.toLowerCase();
|
||||
|
||||
// Check for "open code" before "opencode" to handle the spaced variant
|
||||
if (lower.includes("open code")) {
|
||||
return "opencode";
|
||||
}
|
||||
|
||||
if (lower.includes("claude")) {
|
||||
return "claude";
|
||||
}
|
||||
|
||||
if (lower.includes("codex")) {
|
||||
return "codex";
|
||||
}
|
||||
|
||||
if (lower.includes("opencode")) {
|
||||
return "opencode";
|
||||
}
|
||||
|
||||
return config?.defaultClient ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user