forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
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.
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)- New additive files for TUI + config
Implementation Plan
Step 1: Analyze current implementation
- Map every change we made to
session/index.ts— classify as "state management", "lifecycle hook", "tool resolution", "event handling" - Map every change to
session/prompt.ts— classify similarly - Compare against PR feat(tui): fire-and-forget async subagent tasks anomalyco/opencode#7206's approach for each category
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.tsandtool/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
-
session/index.tsdiff ≤20 lines vs upstream -
session/prompt.tsdiff ≤50 lines vs upstream - All async task functionality preserved
- New additive files contain bulk of implementation
- Tests pass
- Manual verification with real subagent workflows
Files 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
- Upstream PR feat(tui): fire-and-forget async subagent tasks anomalyco/opencode#7206: feat(tui): fire-and-forget async subagent tasks anomalyco/opencode#7206
- Upstream issue [feat] True Async/Background Sub-Agent Delegation anomalyco/opencode#5887: True async/background sub-agent delegation
- Clouder0/overcode: Even more invasive approach (2,881 lines in prompt.ts) — anti-pattern
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels