Parent: #158
Objective
Reduce our async task tool's invasion of upstream files from +603 lines in session/index.ts and +356 lines in session/prompt.ts to approximately +10 lines and +50 lines respectively, following the pattern established by upstream PR anomalyco#7206.
Why This Matters
session/index.ts and session/prompt.ts are the most actively developed files in upstream OpenCode:
prompt.ts: 78 commits in 3 months (~every other day)
index.ts: 18 commits in 3 months (~twice/week)
Our current 603-line diff in index.ts means every upstream sync will conflict. Reducing to ~10 lines makes conflicts rare and trivially resolvable.
Upstream PR anomalyco#7206 (IgorWarzocha/async-subagents) achieves async subagent execution with:
session/index.ts: +9 lines (thin hooks only)
session/prompt.ts: +108 lines
tool/task.ts: +238 lines (bulk of implementation)
- New additive files for TUI + config
Implementation Plan
Step 1: Analyze current implementation
Step 2: Extract into additive files
- Create
session/async-tasks.ts — all async state management (task slots, completion tracking, auto-wakeup logic)
- Keep
session/tools.ts — already extracted tool resolution (good)
- Keep
tool/task.ts and tool/check_task.ts — already separate (good)
- Keep
util/tasks.ts — already separate (good)
Step 3: Minimize session/index.ts to thin hooks
Target: ~10 lines total, consisting of:
- Import async-tasks module
- Hook into session start/end lifecycle
- Hook into message processing for task completion notifications
Step 4: Minimize session/prompt.ts
Target: ~50 lines total:
- System prompt injection for async task context
- Tool registration (task + check_task)
Step 5: Verify functionality
- All async task features work: background execution, slot concurrency (max 5), check_task polling, auto-wakeup on completion
- Run full test suite
- Manual testing with multi-agent workflows
Acceptance Criteria
Files Involved
packages/opencode/src/session/index.ts — REDUCE from +603 to ~+10
packages/opencode/src/session/prompt.ts — REDUCE from +356 to ~+50
packages/opencode/src/session/async-tasks.ts — NEW (extracted state management)
packages/opencode/src/session/tools.ts — KEEP (already extracted)
packages/opencode/src/tool/task.ts — KEEP (already separate)
packages/opencode/src/tool/check_task.ts — KEEP (already separate)
packages/opencode/src/util/tasks.ts — KEEP (already separate)
References
Parent: #158
Objective
Reduce our async task tool's invasion of upstream files from +603 lines in
session/index.tsand +356 lines insession/prompt.tsto approximately +10 lines and +50 lines respectively, following the pattern established by upstream PR anomalyco#7206.Why This Matters
session/index.tsandsession/prompt.tsare the most actively developed files in upstream OpenCode:prompt.ts: 78 commits in 3 months (~every other day)index.ts: 18 commits in 3 months (~twice/week)Our current 603-line diff in
index.tsmeans every upstream sync will conflict. Reducing to ~10 lines makes conflicts rare and trivially resolvable.Reference: PR anomalyco#7206 Pattern
Upstream PR anomalyco#7206 (IgorWarzocha/async-subagents) achieves async subagent execution with:
session/index.ts: +9 lines (thin hooks only)session/prompt.ts: +108 linestool/task.ts: +238 lines (bulk of implementation)Implementation Plan
Step 1: Analyze current implementation
session/index.ts— classify as "state management", "lifecycle hook", "tool resolution", "event handling"session/prompt.ts— classify similarlyStep 2: Extract into additive files
session/async-tasks.ts— all async state management (task slots, completion tracking, auto-wakeup logic)session/tools.ts— already extracted tool resolution (good)tool/task.tsandtool/check_task.ts— already separate (good)util/tasks.ts— already separate (good)Step 3: Minimize session/index.ts to thin hooks
Target: ~10 lines total, consisting of:
Step 4: Minimize session/prompt.ts
Target: ~50 lines total:
Step 5: Verify functionality
Acceptance Criteria
session/index.tsdiff ≤20 lines vs upstreamsession/prompt.tsdiff ≤50 lines vs upstreamFiles Involved
packages/opencode/src/session/index.ts— REDUCE from +603 to ~+10packages/opencode/src/session/prompt.ts— REDUCE from +356 to ~+50packages/opencode/src/session/async-tasks.ts— NEW (extracted state management)packages/opencode/src/session/tools.ts— KEEP (already extracted)packages/opencode/src/tool/task.ts— KEEP (already separate)packages/opencode/src/tool/check_task.ts— KEEP (already separate)packages/opencode/src/util/tasks.ts— KEEP (already separate)References