forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
Description
Summary
Merge sst/opencode#6478 into our fork. This PR combines three related improvements to slash commands and subtask handling:
- Parallel subtask execution - Slash commands can spawn multiple subagents concurrently
- Model inheritance fix - Proper model/agent context restoration after subtask completion
- New plugin hook -
command.execute.beforefor plugin extensibility
Problem/Context
Currently, subtasks execute sequentially and lose parent session context (agent/model) after completion. This limits the power of slash commands and plugins. The upstream PR addresses these issues by:
- Allowing parallel subtask execution via
Promise.all() - Tracking parent agent/model in
SubtaskPartschema - Adding
command.execute.beforehook for pre-execution plugin logic - Fixing model resolution chain: Command Frontmatter → Agent → Session → Default
This also enables the subtask2 plugin which provides advanced slash command capabilities like multi-step workflows and parallel model comparison (A/B testing with different models).
Acceptance Criteria
- All changes from upstream PR add command.execute.before hook + allow parallel subtasks + fix model inheritance anomalyco/opencode#6478 are merged
-
SubtaskPartschema includesmodel,parentAgent, andparentModelfields - Subtasks execute in parallel when multiple are queued
- Parent agent/model context is restored after subtask completion
-
command.execute.beforehook is available in plugin system - Model inheritance follows correct priority: command → agent → session → default
- Existing tests pass
- Manual testing confirms subtask behavior works correctly
Implementation Details
Files Modified
| File | Changes |
|---|---|
packages/opencode/src/session/message-v2.ts |
Add model, parentAgent, parentModel to SubtaskPart schema |
packages/opencode/src/session/prompt.ts |
Refactor subtask handling for parallel execution, fix model inheritance |
packages/opencode/src/tool/task.ts |
Update model resolution to use ctx.extra.model |
packages/plugin/src/index.ts |
Add command.execute.before hook type |
packages/sdk/js/src/v2/gen/types.gen.ts |
Update generated types for SubtaskPart |
Key Code Changes
Parallel Subtask Execution (prompt.ts):
// Filter subtasks from other task types
const subtasks = tasks.filter((t) => t.type === "subtask")
const otherTasks = tasks.filter((t) => t.type !== "subtask")
// Execute all subtasks in parallel
await Promise.all(subtasks.map(executeSubtask))Model Inheritance Fix (prompt.ts):
// Restore parent context after subtask
agent: subtasks[0]?.parentAgent ?? lastUser.agent,
model: subtasks[0]?.parentModel ?? lastUser.model,New Plugin Hook (index.ts):
"command.execute.before"?: (
input: { command: string; sessionID: string; arguments: string },
output: { parts: Part[] },
) => Promise<void>Related PRs (Merged into anomalyco#6478)
- sst/opencode#6411 -
command.execute.beforeand parallel subtasks - sst/opencode#5726 - Restore session agent/model on subtask return
Tasks
- Fetch upstream changes from
sst/opencode - Cherry-pick or merge PR add command.execute.before hook + allow parallel subtasks + fix model inheritance anomalyco/opencode#6478 commits
- Resolve any conflicts with fork-specific changes
- Verify
SubtaskPartschema changes inmessage-v2.ts - Verify prompt.ts parallel execution logic
- Verify task.ts model resolution changes
- Verify plugin hook additions
- Run
bun testinpackages/opencode - Manual test: Create subtask command and verify parallel execution
- Manual test: Verify model inheritance works correctly
- Update fork sync documentation if needed
External References
- Upstream PR: add command.execute.before hook + allow parallel subtasks + fix model inheritance anomalyco/opencode#6478
- Author: @spoons-and-mirrors
- Related Plugin: subtask2 - Advanced slash command handler that leverages these changes
- Merged PRs:
Notes
- PR stats: +193 additions, -130 deletions across 5 files
- The PR is currently OPEN in upstream
- Consider waiting for upstream merge or merge early if we need the functionality