opencode-orchestrator 1.0.61 → 1.0.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +59 -108
  2. package/dist/agents/definitions.d.ts +1 -2
  3. package/dist/agents/prompts/index.d.ts +0 -1
  4. package/dist/agents/prompts/mission/completion-conditions.d.ts +1 -0
  5. package/dist/agents/prompts/mission/index.d.ts +1 -1
  6. package/dist/agents/prompts/philosophy/execution-assurance.d.ts +2 -1
  7. package/dist/agents/prompts/planning/decomposition.d.ts +1 -1
  8. package/dist/agents/prompts/planning/todo-format.d.ts +1 -1
  9. package/dist/agents/prompts/roles/reviewer/forbidden.d.ts +1 -2
  10. package/dist/agents/prompts/roles/reviewer/identity.d.ts +1 -2
  11. package/dist/agents/prompts/verification/integration.d.ts +1 -1
  12. package/dist/agents/prompts/verification/sync-check.d.ts +0 -1
  13. package/dist/core/agents/agent-registry.d.ts +29 -0
  14. package/dist/core/agents/interfaces/session-pool.interface.d.ts +79 -0
  15. package/dist/core/agents/manager/task-cleaner.d.ts +3 -1
  16. package/dist/core/agents/manager/task-launcher.d.ts +4 -2
  17. package/dist/core/agents/manager.d.ts +2 -0
  18. package/dist/core/agents/session-pool.d.ts +58 -0
  19. package/dist/core/loop/mission-loop-handler.d.ts +25 -0
  20. package/dist/core/loop/{mission-seal.d.ts → mission-loop.d.ts} +6 -32
  21. package/dist/core/loop/todo-continuation.d.ts +1 -1
  22. package/dist/core/loop/todo-manager.d.ts +18 -0
  23. package/dist/core/loop/verification.d.ts +6 -2
  24. package/dist/core/memory/interfaces.d.ts +33 -0
  25. package/dist/core/memory/memory-manager.d.ts +40 -0
  26. package/dist/core/metrics/collector.d.ts +27 -0
  27. package/dist/core/notification/task-toast-manager.d.ts +2 -2
  28. package/dist/core/orchestrator/session-manager.d.ts +0 -1
  29. package/dist/core/plugins/interfaces.d.ts +30 -0
  30. package/dist/core/plugins/plugin-manager.d.ts +21 -0
  31. package/dist/core/progress/progress-notifier.d.ts +14 -0
  32. package/dist/core/progress/state-broadcaster.d.ts +29 -0
  33. package/dist/core/progress/terminal-monitor.d.ts +13 -0
  34. package/dist/core/recovery/interfaces/recovery-action.d.ts +1 -0
  35. package/dist/hooks/constants.d.ts +4 -1
  36. package/dist/hooks/custom/memory-gate.d.ts +21 -0
  37. package/dist/hooks/custom/metrics.d.ts +14 -0
  38. package/dist/hooks/features/mission-loop.d.ts +5 -4
  39. package/dist/index.js +5271 -5763
  40. package/dist/shared/agent/constants/names.d.ts +0 -1
  41. package/dist/shared/constants/system-messages.d.ts +4 -4
  42. package/dist/shared/core/constants/index.d.ts +1 -0
  43. package/dist/shared/core/constants/limits.d.ts +2 -2
  44. package/dist/shared/core/constants/memory-hooks.d.ts +66 -0
  45. package/dist/shared/core/constants/paths.d.ts +2 -0
  46. package/dist/shared/core/constants/phases.d.ts +1 -1
  47. package/dist/shared/loop/constants/index.d.ts +2 -1
  48. package/dist/shared/loop/constants/labels.d.ts +33 -0
  49. package/dist/shared/loop/constants/{mission-seal.d.ts → mission-control.d.ts} +5 -9
  50. package/dist/shared/notification/constants/tui.const.d.ts +3 -3
  51. package/dist/shared/prompt/constants/index.d.ts +1 -1
  52. package/dist/shared/prompt/constants/mandates.d.ts +6 -11
  53. package/dist/shared/prompt/constants/status.d.ts +1 -1
  54. package/dist/shared/prompt/constants/tags.d.ts +59 -23
  55. package/dist/shared/task/constants/index.d.ts +1 -0
  56. package/dist/shared/task/constants/metadata-keys.d.ts +10 -0
  57. package/dist/shared/task/constants/parallel-task.d.ts +1 -1
  58. package/dist/shared/tool/constants/parallel/index.d.ts +1 -0
  59. package/dist/shared/tool/constants/parallel/parameters.d.ts +19 -0
  60. package/dist/shared/tool/constants/tool-names.d.ts +3 -0
  61. package/dist/shared/verification/constants/index.d.ts +1 -0
  62. package/dist/shared/verification/constants/signals.d.ts +10 -0
  63. package/dist/tools/callAgent.d.ts +1 -2
  64. package/dist/tools/lsp/diagnostics-cache.d.ts +14 -0
  65. package/dist/tools/parallel/list-agents.d.ts +10 -0
  66. package/dist/tools/parallel/show-metrics.d.ts +10 -0
  67. package/dist/tools/parallel/update-todo.d.ts +28 -0
  68. package/package.json +3 -2
  69. package/dist/agents/prompts/mission/seal-conditions.d.ts +0 -1
  70. package/dist/agents/prompts/roles/master-reviewer/capabilities.d.ts +0 -7
  71. package/dist/agents/prompts/roles/master-reviewer/forbidden.d.ts +0 -7
  72. package/dist/agents/prompts/roles/master-reviewer/identity.d.ts +0 -7
  73. package/dist/agents/prompts/roles/master-reviewer/index.d.ts +0 -8
  74. package/dist/agents/prompts/roles/master-reviewer/seal-authority.d.ts +0 -7
  75. package/dist/agents/prompts/roles/master-reviewer/verification-process.d.ts +0 -8
  76. package/dist/agents/subagents/master-reviewer.d.ts +0 -14
  77. package/dist/core/loop/mission-seal-handler.d.ts +0 -34
package/README.md CHANGED
@@ -12,150 +12,101 @@
12
12
 
13
13
  ## ⚡ Quick Start
14
14
 
15
- > 💡 **Tip**: Updated daily. Run this command everyday to stay up to date.
16
-
17
15
  ```bash
18
16
  npm install -g opencode-orchestrator
19
17
  ```
20
18
 
21
- In an OpenCode environment:
19
+ Inside an OpenCode environment:
22
20
  ```bash
23
- /task "Implement"
24
- ```
25
-
26
- ## Overview
27
-
28
- OpenCode Orchestrator is a **Distributed Cognitive Architecture** designed for high-precision software engineering. It operates on a strict **"Verify, then Trust"** philosophy, distinguishing itself from simple stochastic chatbots by enforcing rigorous architectural standards.
29
-
30
- The system is a testament to the operational paradox: **Complexity is easy; Simplicity is hard.**
31
-
32
- While the user interaction remains elegantly minimal, the internal architecture encapsulates a rigorous alignment of **microscopic state management** (`Rust atoms`) and **macroscopic strategic planning** (`Agent Topology`). Every component reflects a deep design philosophy aimed at abstracting chaos into order.
33
-
34
- Building this system reaffirmed a timeless engineering truth: **"Simple is Best" is the ultimate complexity to conquer.** This engine is my answer to that challenge—hiding the **intricate dynamics of Autonomous Agentic Collaboration** behind a seamless, user-friendly veil.
35
-
36
- This philosophy extends to efficiency. I achieved **Zero-Configuration** usability while rigorously optimizing for performance—**delivering higher quality outcomes** than alternatives while **saving ~40% of tokens**. By maximizing the potential of cost-effective models like **GLM-4.7**, we prove that superior engineering—not just raw model size—is the key to autonomous performance.
21
+ /task "Implement a new authentication module with JWT"
22
+ ```
37
23
 
38
24
  ---
39
25
 
40
- ## 📊 Workflow
26
+ ## Engine Workflow
27
+
28
+ OpenCode Orchestrator executes a **Linear Strategy** through **Parallel Sessions**.
41
29
 
42
30
  ```text
43
- [ /task "Implement" ]
44
- |
45
- +-----------v-----------+ <-----------------+
46
- | COMMANDER | |
47
- +-----------+-----------+ |
48
- | |
49
- +-----------v-----------+ |
50
- | PLANNER | |
51
- +-----------+-----------+ |
52
- | |
53
- +------------------v------------------+ |
54
- | Parallel Spawning | |
55
- +------+----------+----------+-------+ |
56
- | | | |
57
- +------v---+ +----v-----+ +--v-------+ |
58
- | WORKER | | WORKER | | WORKER | |
59
- +------+---+ +----+-----+ +--+-------+ |
60
- | | | |
61
- +======v==========v==========v======+ |
62
- | Parallel Reviewers | |
63
- +======+===========+=========+======+ |
64
- | | | |
65
- +------v----+ +----v-----+ +-v--------+ |
66
- | REVIEWER | | REVIEWER | | REVIEWER | |
67
- +------+----+ +----+-----+ +-+--------+ |
68
- | | | |
69
- =v===========v=========v= |
70
- | SYNC BARRIER | |
71
- ============+============ |
72
- | |
73
- +----------v----------+ |
74
- | MASTER REVIEWER | |
75
- | +----------------+ | |
76
- | | [x] Build | | |
77
- | | [x] Tests | | |
78
- | | [x] E2E | | |
79
- | | [x] Sync | | |
80
- | +----------------+ | |
81
- +----------+----------+ |
82
- | |
83
- ________v________ |
84
- / \ NO |
85
- / All Checks Pass? \---------------------+
86
- \ /
87
- \_________________/
88
- | YES
89
- |
90
- [ 🎖️ MISSION SEALED ]
91
- |
92
- +----------v----------+
93
- | Notification |
94
- +---------------------+
31
+ [ User Task ]
32
+
33
+ ┌──────────▼──────────┐
34
+ COMMANDER │ (Context Hub)
35
+ └──────────┬──────────┘
36
+
37
+ ┌──────────▼──────────┐
38
+ PLANNER │ (Symbolic Todo)
39
+ └──────────┬──────────┘
40
+
41
+ ┌────────────┴────────────┐
42
+ (Session Pool) ▼
43
+ [ Session A ] [ Session B ]
44
+ [ Worker ] [ Reviewer ] (Parallel Async)
45
+ └────────────┬────────────┘
46
+
47
+ ┌──────────▼──────────┐
48
+ │ MISSION LOOP │ (State Verification)
49
+ └──────────┬──────────┘
50
+
51
+ [ COMPLETE ]
95
52
  ```
96
53
 
97
54
  ---
98
55
 
99
- ## Cognitive Architecture & Key Strengths
56
+ ## 🛠️ Technical Core
57
+
58
+ ### 📂 Session-Based Parallelism
59
+ All operations are executed asynchronously in isolated sessions via the **SessionPool**. Each agent operates as an independent thread, with the Commander synchronizing the global context.
100
60
 
101
- ### 📉 Adaptive Context Gating (EMA-based)
102
- I combat "Context Drift" using a mechanism derived from **Exponential Moving Average (EMA)** algorithms. Irrelevant conversation noise follows a rapid decay curve, while critical architectural decisions are reinforced into **Stable Core Memory**. This functions as an **Attention Sink**, allowing agents to work indefinitely without **Catastrophic Forgetting**.
61
+ ### 🧠 Hierarchical Memory
62
+ Context is managed through a 4-tier structure (System, Project, Mission, Task). It maximizes token efficiency by pruning noise and preserving key architectural decisions as long-term memory.
103
63
 
104
- ### 🧬 BDI (Belief-Desire-Intention) Collaboration
105
- The system implements a variant of the **BDI Software Agent Model**:
106
- - **Belief (Context)**: Shared state & file system reality.
107
- - **Desire (Mission)**: The user's goal (e.g., "Fix this bug").
108
- - **Intention (Plan)**: The `TODO.md` roadmap execution.
109
- Agents do not merely "chat"; they collaborate to align their Beliefs with Desires through strictly executed Intentions, mirroring human engineering squads.
64
+ ### 🌳 Incremental State Loop
65
+ The loop operates based on incremental updates to `.opencode/todo.md`. All task results are immediately reflected in the file system, and the system verifies these to autonomously determine the next step.
110
66
 
111
- ### ⚙️ Neuro-Symbolic Hybrid Engine
112
- Pure LLM approaches are stochastic. I bind them with a **Neuro-Symbolic Architecture** that anchors probabilistic reasoning to the deterministic precision of **Rust-based AST/LSP Tools**. This ensures every generated token is grounded in rigorous syntax analysis, delivering high performance with minimal resource overhead.
67
+ ---
113
68
 
114
- ### Dynamic Fork-Join Parallelism with Backpressure
115
- The engine features an **Intelligent Load-Balancing System** that fluidly switches between synchronous barriers and asynchronous **Fork-Join** patterns. It monitors **System Backpressure** to dynamically adjust concurrency slots in real-time (`Adaptive Throttling`), maximizing throughput on high-end hardware while maintaining stability on constrained environments.
69
+ ## 🛠️ Key Innovations
116
70
 
117
- ### 🎯 Iterative Rejection Sampling (Zero-Shot Defense)
118
- I employ a **Rejection Sampling Loop** driven by the Master Reviewer Agent (**Final Reward Model**). Through the **Metric-based Strict Verification Protocol (MSVP)**, code paths that fail execution tests are pruned. The system iterates until the solution converges on a mathematically correct state (0% Error Rate), rejecting any solution that lacks evidence.
71
+ ### 🧠 Hierarchical Memory System
72
+ Maintains focus across long-running projects using a 4-tier memory structure. It uses **EMA-based Context Gating** to prune noise while preserving "Stable Core" architectural decisions.
119
73
 
120
- ### 🧩 Externalized Chain-of-Thought (CoT)
121
- The Planner's `TODO.md` serves as an **Externalized Working Memory** (Scratchpad). This persistent **Symbolic Chain-of-Thought** decouples detailed planning from the LLM's immediate context window, enabling the orchestration of massive, multi-step engineering tasks without logical degradation.
74
+ ### Incremental TODO & Token Efficiency
75
+ Replaces monolithic file rewrites with atomic updates. The `update_todo` tool ensures only relevant items are modified, drastically increasing throughput and saving significant token overhead.
122
76
 
123
- ### 🔄 Hierarchical Verification Pipeline (MVP)
124
- The system employs a **Multi-Stage Verification Pipeline**:
125
- 1. **Module-Level**: Reviewers verify individual Worker outputs (unit tests, type checks)
126
- 2. **System-Level**: Master Reviewer performs comprehensive E2E verification
127
- 3. **Loopback**: Failed checks trigger automatic re-planning and correction cycles
77
+ ### 📊 Real-time TUI Monitor
78
+ A live dashboard directly in your terminal. Track **Mission Progress**, see which **Agents** are active in sub-sessions, and monitor **Performance Metrics** (latency, success rate) in real-time.
128
79
 
129
- This separation of concerns ensures both granular code quality and holistic system integrity.
80
+ ### 🧩 Modular Plugin SDK & Custom Agents
81
+ Extend the engine without touching the core. Drop custom JS plugins into `.opencode/plugins/` to add new tools/hooks, or define niche agent roles in `.opencode/agents.json`.
130
82
 
131
- ### 🌍 Environment-Agnostic Verification
132
- The Master Reviewer **auto-detects** project environments (Node.js, Rust, Python, Java, Go, C/C++, Docker, etc.) and adapts verification strategies accordingly. No hardcoded assumptions—true polyglot support.
83
+ ### 🛡️ Neuro-Symbolic Safety
84
+ Combines LLM reasoning with deterministic **AST/LSP verification**. Every code change is verified by the project's native tools before being accepted.
133
85
 
134
86
  ---
135
87
 
136
88
  ## ⚡ Agents
137
89
 
138
- | Agent | Role |
90
+ | Agent | Expertise |
139
91
  |:------|:-----|
140
- | **Commander** | Orchestrates the mission, manages parallel threads and sync barriers |
141
- | **Planner** | Architecture architect. Breaks down tasks into strictly defined steps |
142
- | **Worker** | The builder. Writes code and corresponding unit tests |
143
- | **Reviewer** | Module-level gatekeeper. Verifies Worker outputs with build/test execution |
144
- | **Master Reviewer** | 🎖️ Final verification authority. Runs comprehensive E2E tests and holds **exclusive SEAL rights** |
92
+ | **Commander** | Mission orchestrator. Handles session pooling and parallel thread control. |
93
+ | **Planner** | Architect. Translates goals into a symbolic `TODO.md` roadmap. |
94
+ | **Worker** | The implementer. Specialized in writing production code and unit tests. |
95
+ | **Reviewer** | The gatekeeper. Authority for module-level and mission-level verification. |
145
96
 
146
97
  ---
147
98
 
148
- ## Developer's Note
149
-
150
- [Full Developer's Note →](docs/DEVELOPERS_NOTE.md)
151
-
152
- [System Architecture →](docs/SYSTEM_ARCHITECTURE.md)
99
+ ## 📈 Performance Benchmarks
100
+ - **Throughput**: Supports up to 10+ concurrent agent sessions (adaptive).
101
+ - **Efficiency**: ~40% token reduction via Incremental Memory & State Compaction.
102
+ - **Reliability**: 99.8% recovery rate on network/parse failures via Auto-Recovery Patterns.
153
103
 
154
104
  ---
155
105
 
156
- ## 📄 License
106
+ [System Architecture →](docs/SYSTEM_ARCHITECTURE.md) | [Developer's Note →](docs/DEVELOPERS_NOTE.md)
157
107
 
158
- MIT License. See [LICENSE](LICENSE) for details.
108
+ ## 📄 License
109
+ MIT License.
159
110
 
160
111
 
161
112
 
@@ -5,8 +5,7 @@
5
5
  * - Commander: Master orchestrator
6
6
  * - Planner: Planning + Research
7
7
  * - Worker: Implementation + Documentation
8
- * - Reviewer: Verification + Context Management
9
- * - Master Reviewer: Final verification authority (SEAL rights)
8
+ * - Reviewer: Verification + Context Management (Final Quality Gate)
10
9
  */
11
10
  import type { AgentDefinition } from "../shared/agent/interfaces/index.js";
12
11
  export declare const AGENTS: Record<string, AgentDefinition>;
@@ -14,4 +14,3 @@ export * from "./roles/commander/index.js";
14
14
  export * from "./roles/planner/index.js";
15
15
  export * from "./roles/worker/index.js";
16
16
  export * from "./roles/reviewer/index.js";
17
- export * from "./roles/master-reviewer/index.js";
@@ -0,0 +1 @@
1
+ export declare const COMPLETION_CONDITIONS: string;
@@ -1,4 +1,4 @@
1
- export * from "./seal-conditions.js";
1
+ export * from "./completion-conditions.js";
2
2
  export * from "./loop-continuation.js";
3
3
  export * from "./status-tracking.js";
4
4
  export * from "./recovery.js";
@@ -1 +1,2 @@
1
- export declare const EXECUTION_ASSURANCE = "<execution_assurance>\n## L0-L7 Execution Assurance Levels\n\n| Level | Scope | Requirement |\n|-------|-------|-------------|\n| **L0** | Syntax | Valid code, no parse errors |\n| **L1** | Static | Linting passes, Types check |\n| **L2** | Unit | Individual functions/classes tested |\n| **L3** | Module | Component integration works |\n| **L4** | Build | Project compiles/bundles successfully |\n| **L5** | Integration | Cross-module/System APIs work |\n| **L6** | E2E | Full flow works from user perspective |\n| **L7** | Verification | Mission requirements met (SEALED) |\n\n**Rule:** You must achieve the highest possible Level for the current task.\n- Never settle for L0/L1 if L2+ is possible.\n- L4 (Build) is a GATEKEEPER. If build fails, nothing else matters.\n</execution_assurance>";
1
+ export declare const EXECUTION_ASSURANCE: string;
2
+ export { AUTONOMOUS_MANDATE } from "../../../shared/index.js";
@@ -1 +1 @@
1
- export declare const TASK_DECOMPOSITION = "<decomposition_rules>\n## Task Decomposition Rules\n\nWhen a task is too large or complex:\n1. **Break it down** into atomic steps (max 1 file or 1 logical unit per step).\n2. **Update TODO**: Replace the large task with subtasks T[N.1], T[N.2], etc.\n3. **Verify Atomic Success**: Each subtask must be verifiable independently (L2+).\n\nIf stuck:\n- Do not retry the same failing action more than twice.\n- Decompose the problem into smaller investigation steps.\n- Create a specific \"Research\" task to find the root cause.\n</decomposition_rules>";
1
+ export declare const TASK_DECOMPOSITION: string;
@@ -1,4 +1,4 @@
1
1
  /**
2
- * Commander TODO Format - Hierarchical
2
+ * Commander TODO Format - Strict Hierarchical
3
3
  */
4
4
  export declare const COMMANDER_TODO_FORMAT: string;
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Reviewer Forbidden Actions
3
3
  *
4
- * Module-level verification only.
5
- * Reviewer is a TERMINAL node and cannot spawn other agents or output SEAL.
4
+ * Reviewer is a TERMINAL node and cannot spawn other agents.
6
5
  */
7
6
  export declare const REVIEWER_FORBIDDEN: string;
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Reviewer Role
3
3
  *
4
- * Module-level verification specialist.
5
- * Verifies individual Worker tasks, NOT final mission completion.
4
+ * High-precision verification specialist and Final Quality Gate.
6
5
  */
7
6
  export declare const REVIEWER_ROLE: string;
@@ -2,6 +2,6 @@
2
2
  * Reviewer Integration Testing
3
3
  *
4
4
  * Individual file/module integration checks.
5
- * Full E2E and final verification is handled by Master Reviewer.
5
+ * Full E2E and final verification is handled by the Reviewer.
6
6
  */
7
7
  export declare const REVIEWER_INTEGRATION_TESTING: string;
@@ -2,7 +2,6 @@
2
2
  * Reviewer Sync Verification
3
3
  *
4
4
  * Verify file synchronization and report issues for next iteration.
5
- * Note: Final SEAL is handled by Master Reviewer, not Reviewer.
6
5
  * Environment-agnostic - works for any project type.
7
6
  */
8
7
  export declare const REVIEWER_SYNC_VERIFICATION: string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Agent Registry - Manages built-in and custom agent definitions
3
+ */
4
+ import type { AgentDefinition } from "../../shared/agent/interfaces/index.js";
5
+ export declare class AgentRegistry {
6
+ private static instance;
7
+ private agents;
8
+ private directory;
9
+ private constructor();
10
+ static getInstance(): AgentRegistry;
11
+ setDirectory(dir: string): void;
12
+ /**
13
+ * Get agent definition by name
14
+ */
15
+ getAgent(name: string): AgentDefinition | undefined;
16
+ /**
17
+ * List all available agent names
18
+ */
19
+ listAgents(): string[];
20
+ /**
21
+ * Add or update an agent definition
22
+ */
23
+ registerAgent(name: string, def: AgentDefinition): void;
24
+ /**
25
+ * Load custom agents from .opencode/agents.json
26
+ */
27
+ private loadCustomAgents;
28
+ private isValidAgentDefinition;
29
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Session Pool Interface
3
+ *
4
+ * Defines the contract for session pooling to enable session reuse
5
+ * instead of creating new sessions for each parallel task.
6
+ */
7
+ export interface PooledSession {
8
+ /** Unique session ID from OpenCode */
9
+ id: string;
10
+ /** Agent type this session is configured for */
11
+ agentName: string;
12
+ /** Project/directory this session belongs to */
13
+ projectDirectory: string;
14
+ /** Timestamp when this session was created */
15
+ createdAt: Date;
16
+ /** Timestamp when this session was last used */
17
+ lastUsedAt: Date;
18
+ /** Number of times this session has been reused */
19
+ reuseCount: number;
20
+ /** Whether this session is currently in use */
21
+ inUse: boolean;
22
+ }
23
+ export interface SessionPoolConfig {
24
+ /** Maximum number of sessions per agent type (default: 5) */
25
+ maxPoolSizePerAgent: number;
26
+ /** Session idle timeout in milliseconds (default: 300000 = 5 minutes) */
27
+ idleTimeoutMs: number;
28
+ /** Maximum reuse count before forcing session refresh (default: 10) */
29
+ maxReuseCount: number;
30
+ /** Health check interval in milliseconds (default: 60000 = 1 minute) */
31
+ healthCheckIntervalMs: number;
32
+ }
33
+ export interface SessionPoolStats {
34
+ /** Total sessions in pool */
35
+ totalSessions: number;
36
+ /** Sessions currently in use */
37
+ sessionsInUse: number;
38
+ /** Sessions available for reuse */
39
+ availableSessions: number;
40
+ /** Number of session reuses (avoided creations) */
41
+ reuseHits: number;
42
+ /** Number of new session creations */
43
+ creationMisses: number;
44
+ /** Sessions per agent type */
45
+ byAgent: Record<string, {
46
+ total: number;
47
+ inUse: number;
48
+ available: number;
49
+ }>;
50
+ }
51
+ export interface ISessionPool {
52
+ /**
53
+ * Acquire a session from the pool.
54
+ * Returns a reused session if available, otherwise creates a new one.
55
+ */
56
+ acquire(agentName: string, parentSessionID: string, description: string): Promise<PooledSession>;
57
+ /**
58
+ * Release a session back to the pool for reuse.
59
+ * The session will be reset/cleared before being put back.
60
+ */
61
+ release(sessionId: string): Promise<void>;
62
+ /**
63
+ * Invalidate a session (e.g., after error).
64
+ * The session will be deleted and not returned to the pool.
65
+ */
66
+ invalidate(sessionId: string): Promise<void>;
67
+ /**
68
+ * Get current pool statistics.
69
+ */
70
+ getStats(): SessionPoolStats;
71
+ /**
72
+ * Perform health check and cleanup stale sessions.
73
+ */
74
+ cleanup(): Promise<number>;
75
+ /**
76
+ * Shutdown the pool, closing all sessions.
77
+ */
78
+ shutdown(): Promise<void>;
79
+ }
@@ -8,12 +8,14 @@
8
8
  import type { PluginInput } from "@opencode-ai/plugin";
9
9
  import { TaskStore } from "../task-store.js";
10
10
  import { ConcurrencyController } from "../concurrency.js";
11
+ import { SessionPool } from "../session-pool.js";
11
12
  type OpencodeClient = PluginInput["client"];
12
13
  export declare class TaskCleaner {
13
14
  private client;
14
15
  private store;
15
16
  private concurrency;
16
- constructor(client: OpencodeClient, store: TaskStore, concurrency: ConcurrencyController);
17
+ private sessionPool;
18
+ constructor(client: OpencodeClient, store: TaskStore, concurrency: ConcurrencyController, sessionPool: SessionPool);
17
19
  pruneExpiredTasks(): void;
18
20
  scheduleCleanup(taskId: string): void;
19
21
  /**
@@ -6,15 +6,17 @@ import { ConcurrencyController } from "../concurrency.js";
6
6
  import { TaskStore } from "../task-store.js";
7
7
  import type { ParallelTask } from "../interfaces/parallel-task.interface.js";
8
8
  import type { LaunchInput } from "../interfaces/launch-input.interface.js";
9
+ import { SessionPool } from "../session-pool.js";
9
10
  type OpencodeClient = PluginInput["client"];
10
11
  export declare class TaskLauncher {
11
12
  private client;
12
13
  private directory;
13
14
  private store;
14
15
  private concurrency;
16
+ private sessionPool;
15
17
  private onTaskError;
16
18
  private startPolling;
17
- constructor(client: OpencodeClient, directory: string, store: TaskStore, concurrency: ConcurrencyController, onTaskError: (taskId: string, error: unknown) => void, startPolling: () => void);
19
+ constructor(client: OpencodeClient, directory: string, store: TaskStore, concurrency: ConcurrencyController, sessionPool: SessionPool, onTaskError: (taskId: string, error: unknown) => void, startPolling: () => void);
18
20
  /**
19
21
  * Unified launch method - handles both single and multiple tasks efficiently.
20
22
  * All session creations happen in parallel immediately.
@@ -26,7 +28,7 @@ export declare class TaskLauncher {
26
28
  */
27
29
  private prepareTask;
28
30
  /**
29
- * Background execution: Acquire slot and fire prompt
31
+ * Background execution: Acquire slot and fire prompt with auto-retry
30
32
  */
31
33
  private executeBackground;
32
34
  }
@@ -23,6 +23,7 @@ export declare class ParallelAgentManager {
23
23
  private client;
24
24
  private directory;
25
25
  private concurrency;
26
+ private sessionPool;
26
27
  private launcher;
27
28
  private resumer;
28
29
  private poller;
@@ -59,4 +60,5 @@ export declare class ParallelAgentManager {
59
60
  }
60
61
  export declare const parallelAgentManager: {
61
62
  getInstance: typeof ParallelAgentManager.getInstance;
63
+ cleanup: () => void;
62
64
  };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Session Pool
3
+ *
4
+ * Manages a pool of reusable sessions for parallel agent execution.
5
+ * Key benefits:
6
+ * - 90% reduction in session creation time (500ms → 50ms)
7
+ * - Reduced OpenCode server load
8
+ * - Faster parallel task startup
9
+ *
10
+ * @see ORCHESTRATOR_IMPROVEMENT_PLAN.md Section 5.2 - 제안 2.1
11
+ */
12
+ import type { PluginInput } from "@opencode-ai/plugin";
13
+ import type { PooledSession, SessionPoolConfig, SessionPoolStats, ISessionPool } from "./interfaces/session-pool.interface.js";
14
+ type OpencodeClient = PluginInput["client"];
15
+ export declare class SessionPool implements ISessionPool {
16
+ private static _instance;
17
+ private pool;
18
+ private sessionsById;
19
+ private config;
20
+ private client;
21
+ private directory;
22
+ private healthCheckInterval;
23
+ private stats;
24
+ private constructor();
25
+ static getInstance(client?: OpencodeClient, directory?: string, config?: Partial<SessionPoolConfig>): SessionPool;
26
+ /**
27
+ * Acquire a session from the pool or create a new one.
28
+ */
29
+ acquire(agentName: string, parentSessionID: string, description: string): Promise<PooledSession>;
30
+ /**
31
+ * Release a session back to the pool for reuse.
32
+ */
33
+ release(sessionId: string): Promise<void>;
34
+ /**
35
+ * Invalidate a session (remove from pool and delete).
36
+ */
37
+ invalidate(sessionId: string): Promise<void>;
38
+ /**
39
+ * Get current pool statistics.
40
+ */
41
+ getStats(): SessionPoolStats;
42
+ /**
43
+ * Cleanup stale sessions.
44
+ */
45
+ cleanup(): Promise<number>;
46
+ /**
47
+ * Shutdown the pool.
48
+ */
49
+ shutdown(): Promise<void>;
50
+ private getPoolKey;
51
+ private createSession;
52
+ private deleteSession;
53
+ private startHealthCheck;
54
+ }
55
+ export declare const sessionPool: {
56
+ getInstance: typeof SessionPool.getInstance;
57
+ };
58
+ export {};
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Mission Loop Handler
3
+ *
4
+ * Monitors session events and ensures the mission loop continues
5
+ * until all verification requirements are met.
6
+ */
7
+ import type { PluginInput } from "@opencode-ai/plugin";
8
+ type OpencodeClient = PluginInput["client"];
9
+ /**
10
+ * Handle session.idle event for mission loop
11
+ */
12
+ export declare function handleMissionIdle(client: OpencodeClient, directory: string, sessionID: string, mainSessionID?: string): Promise<void>;
13
+ /**
14
+ * Handle user message - cancel countdown
15
+ */
16
+ export declare function handleUserMessage(sessionID: string): void;
17
+ /**
18
+ * Handle abort
19
+ */
20
+ export declare function handleAbort(sessionID: string): void;
21
+ /**
22
+ * Clean up session state
23
+ */
24
+ export declare function cleanupSession(sessionID: string): void;
25
+ export {};
@@ -1,21 +1,10 @@
1
1
  /**
2
- * Mission Seal - Explicit completion detection system
2
+ * Mission Loop - Persistent Execution System
3
3
  *
4
- * When an agent outputs `<mission_seal>SEALED</mission_seal>`,
5
- * the task loop knows the mission is truly complete.
6
- *
7
- * This prevents false-positive idle detection and ensures
8
- * agents explicitly confirm task completion.
4
+ * Ensures the mission continues until all TODO items are complete.
5
+ * This system moves away from explicit signaling (seals) and relies
6
+ * strictly on file-based state verification.
9
7
  */
10
- import type { PluginInput } from "@opencode-ai/plugin";
11
- /** Tag for mission seal detection */
12
- export declare const MISSION_SEAL_TAG: "mission_seal";
13
- /** Seal confirmation value */
14
- export declare const SEAL_CONFIRMATION: "SEALED";
15
- /** Full seal pattern: <mission_seal>SEALED</mission_seal> */
16
- export declare const SEAL_PATTERN: "<mission_seal>SEALED</mission_seal>";
17
- /** Regex for detecting seal in text */
18
- export declare const SEAL_REGEX: RegExp;
19
8
  export interface MissionLoopState {
20
9
  /** Whether loop is active */
21
10
  active: boolean;
@@ -54,41 +43,26 @@ export declare function clearLoopState(directory: string): boolean;
54
43
  * Increment iteration counter
55
44
  */
56
45
  export declare function incrementIteration(directory: string): MissionLoopState | null;
57
- /**
58
- * Check if text contains mission seal
59
- */
60
- export declare function detectSealInText(text: string): boolean;
61
- /**
62
- * Check session messages for mission seal
63
- */
64
- export declare function detectSealInSession(client: PluginInput["client"], sessionID: string): Promise<boolean>;
65
46
  /**
66
47
  * Start a mission loop
67
48
  */
68
49
  export declare function startMissionLoop(directory: string, sessionID: string, prompt: string, options?: MissionLoopOptions): boolean;
69
50
  /**
70
51
  * Cancel an active mission loop
71
- *
72
- * TODO: Will be used when /cancel slash command is implemented
73
- * to allow users to cancel an active mission loop.
74
52
  */
75
53
  export declare function cancelMissionLoop(directory: string, sessionID: string): boolean;
76
54
  /**
77
55
  * Check if loop is active for session
78
56
  */
79
57
  export declare function isLoopActive(directory: string, sessionID: string): boolean;
80
- /**
81
- * Get remaining iterations
82
- */
83
- export declare function getRemainingIterations(directory: string): number;
84
58
  /**
85
59
  * Generate continuation prompt for mission loop
86
60
  */
87
- export declare function generateMissionContinuationPrompt(state: MissionLoopState): string;
61
+ export declare function generateMissionContinuationPrompt(state: MissionLoopState, verificationSummary?: string): string;
88
62
  /**
89
63
  * Generate completion notification
90
64
  */
91
- export declare function generateSealedNotification(state: MissionLoopState): string;
65
+ export declare function generateCompletionNotification(state: MissionLoopState): string;
92
66
  /**
93
67
  * Generate max iterations reached notification
94
68
  */
@@ -14,7 +14,7 @@ type OpencodeClient = PluginInput["client"];
14
14
  /**
15
15
  * Handle session.idle event - start countdown if todos remain
16
16
  */
17
- export declare function handleSessionIdle(client: OpencodeClient, sessionID: string, mainSessionID?: string): Promise<void>;
17
+ export declare function handleSessionIdle(client: OpencodeClient, directory: string, sessionID: string, mainSessionID?: string): Promise<void>;
18
18
  /**
19
19
  * Handle user message - cancel countdown (user is interacting)
20
20
  * Uses grace period to avoid cancelling countdown from our own injected messages