From 8c10edc8c6f5cb099dd3aa06da450d93f62c8fa5 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Sat, 28 Mar 2026 20:02:13 -0400 Subject: [PATCH] remove dead resolveCommand and resolvePromptPartsImpl --- packages/opencode/src/session/prompt.ts | 181 ------------------------ 1 file changed, 181 deletions(-) diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index e0e76bf3fa..35cbff2c53 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -823,57 +823,6 @@ export namespace SessionPrompt { return Provider.defaultModel() } - async function resolvePromptPartsImpl(template: string): Promise { - const parts: PromptInput["parts"] = [ - { - type: "text", - text: template, - }, - ] - const files = ConfigMarkdown.files(template) - const seen = new Set() - await Promise.all( - files.map(async (match) => { - const name = match[1] - if (seen.has(name)) return - seen.add(name) - const filepath = name.startsWith("~/") - ? path.join(os.homedir(), name.slice(2)) - : path.resolve(Instance.worktree, name) - - const stats = await fs.stat(filepath).catch(() => undefined) - if (!stats) { - const agent = await Agent.get(name) - if (agent) { - parts.push({ - type: "agent", - name: agent.name, - }) - } - return - } - - if (stats.isDirectory()) { - parts.push({ - type: "file", - url: pathToFileURL(filepath).href, - filename: name, - mime: "application/x-directory", - }) - return - } - - parts.push({ - type: "file", - url: pathToFileURL(filepath).href, - filename: name, - mime: "text/plain", - }) - }), - ) - return parts - } - async function handleSubtask(input: { task: MessageV2.SubtaskPart model: Provider.Model @@ -2024,136 +1973,6 @@ NOTE: At any point in time through this workflow you should feel free to ask the const placeholderRegex = /\$(\d+)/g const quoteTrimRegex = /^["']|["']$/g - async function resolveCommand(input: CommandInput): Promise<{ promptInput: PromptInput }> { - log.info("command", input) - const cmd = await Command.get(input.command) - if (!cmd) { - const available = await Command.list().then((cmds) => cmds.map((c) => c.name)) - const hint = available.length ? ` Available commands: ${available.join(", ")}` : "" - const error = new NamedError.Unknown({ message: `Command not found: "${input.command}".${hint}` }) - Bus.publish(Session.Event.Error, { - sessionID: input.sessionID, - error: error.toObject(), - }) - throw error - } - const agentName = cmd.agent ?? input.agent ?? (await Agent.defaultAgent()) - - const raw = input.arguments.match(argsRegex) ?? [] - const args = raw.map((arg) => arg.replace(quoteTrimRegex, "")) - - const templateCommand = await cmd.template - - const placeholders = templateCommand.match(placeholderRegex) ?? [] - let last = 0 - for (const item of placeholders) { - const value = Number(item.slice(1)) - if (value > last) last = value - } - - const withArgs = templateCommand.replaceAll(placeholderRegex, (_, index) => { - const position = Number(index) - const argIndex = position - 1 - if (argIndex >= args.length) return "" - if (position === last) return args.slice(argIndex).join(" ") - return args[argIndex] - }) - const usesArgumentsPlaceholder = templateCommand.includes("$ARGUMENTS") - let template = withArgs.replaceAll("$ARGUMENTS", input.arguments) - - if (placeholders.length === 0 && !usesArgumentsPlaceholder && input.arguments.trim()) { - template = template + "\n\n" + input.arguments - } - - const shellMatches = ConfigMarkdown.shell(template) - if (shellMatches.length > 0) { - const sh = Shell.preferred() - const results = await Promise.all( - shellMatches.map(async ([, cmd]) => { - const out = await Process.text([cmd], { shell: sh, nothrow: true }) - return out.text - }), - ) - let index = 0 - template = template.replace(bashRegex, () => results[index++]) - } - template = template.trim() - - const taskModel = await (async () => { - if (cmd.model) return Provider.parseModel(cmd.model) - if (cmd.agent) { - const cmdAgent = await Agent.get(cmd.agent) - if (cmdAgent?.model) return cmdAgent.model - } - if (input.model) return Provider.parseModel(input.model) - return await lastModelImpl(input.sessionID) - })() - - try { - await Provider.getModel(taskModel.providerID, taskModel.modelID) - } catch (e) { - if (Provider.ModelNotFoundError.isInstance(e)) { - const { providerID, modelID, suggestions } = e.data - const hint = suggestions?.length ? ` Did you mean: ${suggestions.join(", ")}?` : "" - Bus.publish(Session.Event.Error, { - sessionID: input.sessionID, - error: new NamedError.Unknown({ message: `Model not found: ${providerID}/${modelID}.${hint}` }).toObject(), - }) - } - throw e - } - const agent = await Agent.get(agentName) - if (!agent) { - const available = await Agent.list().then((agents) => agents.filter((a) => !a.hidden).map((a) => a.name)) - const hint = available.length ? ` Available agents: ${available.join(", ")}` : "" - const error = new NamedError.Unknown({ message: `Agent not found: "${agentName}".${hint}` }) - Bus.publish(Session.Event.Error, { - sessionID: input.sessionID, - error: error.toObject(), - }) - throw error - } - - const templateParts = await resolvePromptPartsImpl(template) - const isSubtask = (agent.mode === "subagent" && cmd.subtask !== false) || cmd.subtask === true - const parts = isSubtask - ? [ - { - type: "subtask" as const, - agent: agent.name, - description: cmd.description ?? "", - command: input.command, - model: { providerID: taskModel.providerID, modelID: taskModel.modelID }, - prompt: templateParts.find((y) => y.type === "text")?.text ?? "", - }, - ] - : [...templateParts, ...(input.parts ?? [])] - - const userAgent = isSubtask ? (input.agent ?? (await Agent.defaultAgent())) : agentName - const userModel = isSubtask - ? input.model - ? Provider.parseModel(input.model) - : await lastModelImpl(input.sessionID) - : taskModel - - await Plugin.trigger( - "command.execute.before", - { command: input.command, sessionID: input.sessionID, arguments: input.arguments }, - { parts }, - ) - - return { - promptInput: { - sessionID: input.sessionID, - messageID: input.messageID, - model: userModel, - agent: userAgent, - parts, - variant: input.variant, - }, - } - } - async function ensureTitle(input: { session: Session.Info history: MessageV2.WithParts[]