GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — respect subagent in command, add `subtask` flag (#2569) · fsinbad/opencode@16d66c2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode/src
    • command
      • index.ts
    • config
      • config.ts
    • session
      • prompt.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/command/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/command/index.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export namespace Command {
1010
agent: z.string().optional(),
1111
model: z.string().optional(),
1212
template: z.string(),
13+
subtask: z.boolean().optional(),
1314
})
1415
.openapi({
1516
ref: "Command",
@@ -28,6 +29,7 @@ export namespace Command {
2829
model: command.model,
2930
description: command.description,
3031
template: command.template,
32+
subtask: command.subtask,
3133
}
3234
}
3335

Collapse file

‎packages/opencode/src/config/config.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/config/config.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export namespace Config {
244244
description: z.string().optional(),
245245
agent: z.string().optional(),
246246
model: z.string().optional(),
247+
subtask: z.boolean().optional(),
247248
})
248249
export type Command = z.infer<typeof Command>
249250

Collapse file

‎packages/opencode/src/session/prompt.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/session/prompt.ts
+119-6Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { MCP } from "../mcp"
3838
import { LSP } from "../lsp"
3939
import { ReadTool } from "../tool/read"
4040
import { ListTool } from "../tool/ls"
41+
import { TaskTool } from "../tool/task"
4142
import { FileTime } from "../file/time"
4243
import { Permission } from "../permission"
4344
import { Snapshot } from "../snapshot"
@@ -1315,7 +1316,7 @@ export namespace SessionPrompt {
13151316
export async function command(input: CommandInput) {
13161317
log.info("command", input)
13171318
const command = await Command.get(input.command)
1318-
const agent = command.agent ?? input.agent ?? "build"
1319+
const agentName = command.agent ?? input.agent ?? "build"
13191320

13201321
let template = command.template.replace("$ARGUMENTS", input.arguments)
13211322

@@ -1385,22 +1386,134 @@ export namespace SessionPrompt {
13851386
return Provider.parseModel(command.model)
13861387
}
13871388
if (command.agent) {
1388-
const agent = await Agent.get(command.agent)
1389-
if (agent.model) {
1390-
return agent.model
1389+
const cmdAgent = await Agent.get(command.agent)
1390+
if (cmdAgent.model) {
1391+
return cmdAgent.model
13911392
}
13921393
}
13931394
if (input.model) {
13941395
return Provider.parseModel(input.model)
13951396
}
1396-
return undefined
1397+
return await Provider.defaultModel()
13971398
})()
13981399

1400+
const agent = await Agent.get(agentName)
1401+
if (agent.mode === "subagent" || command.subtask) {
1402+
using abort = lock(input.sessionID)
1403+
1404+
const userMsg: MessageV2.User = {
1405+
id: Identifier.ascending("message"),
1406+
sessionID: input.sessionID,
1407+
time: {
1408+
created: Date.now(),
1409+
},
1410+
role: "user",
1411+
}
1412+
await Session.updateMessage(userMsg)
1413+
const userPart: MessageV2.Part = {
1414+
type: "text",
1415+
id: Identifier.ascending("part"),
1416+
messageID: userMsg.id,
1417+
sessionID: input.sessionID,
1418+
text: "The following tool was executed by the user",
1419+
synthetic: true,
1420+
}
1421+
await Session.updatePart(userPart)
1422+
1423+
const assistantMsg: MessageV2.Assistant = {
1424+
id: Identifier.ascending("message"),
1425+
sessionID: input.sessionID,
1426+
system: [],
1427+
mode: agentName,
1428+
cost: 0,
1429+
path: {
1430+
cwd: Instance.directory,
1431+
root: Instance.worktree,
1432+
},
1433+
time: {
1434+
created: Date.now(),
1435+
},
1436+
role: "assistant",
1437+
tokens: {
1438+
input: 0,
1439+
output: 0,
1440+
reasoning: 0,
1441+
cache: { read: 0, write: 0 },
1442+
},
1443+
modelID: model.modelID,
1444+
providerID: model.providerID,
1445+
}
1446+
await Session.updateMessage(assistantMsg)
1447+
1448+
const args = {
1449+
description: "Consulting " + agent.name,
1450+
subagent_type: agent.name,
1451+
prompt: template,
1452+
}
1453+
const toolPart: MessageV2.ToolPart = {
1454+
type: "tool",
1455+
id: Identifier.ascending("part"),
1456+
messageID: assistantMsg.id,
1457+
sessionID: input.sessionID,
1458+
tool: "task",
1459+
callID: ulid(),
1460+
state: {
1461+
status: "running",
1462+
time: {
1463+
start: Date.now(),
1464+
},
1465+
input: {
1466+
description: args.description,
1467+
subagent_type: args.subagent_type,
1468+
// truncate prompt to preserve context
1469+
prompt: args.prompt.length > 100 ? args.prompt.substring(0, 97) + "..." : args.prompt,
1470+
},
1471+
},
1472+
}
1473+
await Session.updatePart(toolPart)
1474+
1475+
const result = await TaskTool.init().then((t) =>
1476+
t.execute(args, {
1477+
sessionID: input.sessionID,
1478+
abort: abort.signal,
1479+
agent: agent.name,
1480+
messageID: assistantMsg.id,
1481+
extra: {},
1482+
metadata: async (metadata) => {
1483+
if (toolPart.state.status === "running") {
1484+
toolPart.state.metadata = metadata.metadata
1485+
toolPart.state.title = metadata.title
1486+
await Session.updatePart(toolPart)
1487+
}
1488+
},
1489+
}),
1490+
)
1491+
1492+
assistantMsg.time.completed = Date.now()
1493+
await Session.updateMessage(assistantMsg)
1494+
if (toolPart.state.status === "running") {
1495+
toolPart.state = {
1496+
status: "completed",
1497+
time: {
1498+
...toolPart.state.time,
1499+
end: Date.now(),
1500+
},
1501+
input: toolPart.state.input,
1502+
title: "",
1503+
metadata: result.metadata,
1504+
output: result.output,
1505+
}
1506+
await Session.updatePart(toolPart)
1507+
}
1508+
1509+
return { info: assistantMsg, parts: [toolPart] }
1510+
}
1511+
13991512
return prompt({
14001513
sessionID: input.sessionID,
14011514
messageID: input.messageID,
14021515
model,
1403-
agent,
1516+
agent: agentName,
14041517
parts,
14051518
})
14061519
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.