refactor: wave 1 - extract leaf modules, rename catch-all files, split index.ts hooks

- Split 25+ index.ts files into hook.ts + extracted modules
- Rename all catch-all utils.ts/helpers.ts to domain-specific names
- Split src/tools/lsp/ into ~15 focused modules
- Split src/tools/delegate-task/ into ~18 focused modules
- Separate shared types from implementation
- 155 files changed, 60+ new files created
- All typecheck clean, 61 tests pass
This commit is contained in:
YeonGyu-Kim
2026-02-08 13:57:26 +09:00
parent 7a15c1f3f9
commit df03300211
156 changed files with 7280 additions and 6771 deletions
@@ -0,0 +1,59 @@
import type { DelegateTaskArgs, OpencodeClient } from "./types"
import { isPlanAgent } from "./constants"
import { promptWithModelSuggestionRetry } from "../../shared"
import { formatDetailedError } from "./error-formatting"
export async function sendSyncPrompt(
client: OpencodeClient,
input: {
sessionID: string
agentToUse: string
args: DelegateTaskArgs
systemContent: string | undefined
categoryModel: { providerID: string; modelID: string; variant?: string } | undefined
toastManager: { removeTask: (id: string) => void } | null | undefined
taskId: string | undefined
}
): Promise<string | null> {
try {
const allowTask = isPlanAgent(input.agentToUse)
await promptWithModelSuggestionRetry(client, {
path: { id: input.sessionID },
body: {
agent: input.agentToUse,
system: input.systemContent,
tools: {
task: allowTask,
call_omo_agent: true,
question: false,
},
parts: [{ type: "text", text: input.args.prompt }],
...(input.categoryModel ? { model: { providerID: input.categoryModel.providerID, modelID: input.categoryModel.modelID } } : {}),
...(input.categoryModel?.variant ? { variant: input.categoryModel.variant } : {}),
},
})
} catch (promptError) {
if (input.toastManager && input.taskId !== undefined) {
input.toastManager.removeTask(input.taskId)
}
const errorMessage = promptError instanceof Error ? promptError.message : String(promptError)
if (errorMessage.includes("agent.name") || errorMessage.includes("undefined")) {
return formatDetailedError(new Error(`Agent "${input.agentToUse}" not found. Make sure the agent is registered in your opencode.json or provided by a plugin.`), {
operation: "Send prompt to agent",
args: input.args,
sessionID: input.sessionID,
agent: input.agentToUse,
category: input.args.category,
})
}
return formatDetailedError(promptError, {
operation: "Send prompt",
args: input.args,
sessionID: input.sessionID,
agent: input.agentToUse,
category: input.args.category,
})
}
return null
}