opencode-hive 1.0.7 → 1.2.0
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.
- package/README.md +5 -34
- package/dist/agents/architect.d.ts +1 -1
- package/dist/agents/forager.d.ts +1 -1
- package/dist/agents/hive.d.ts +1 -1
- package/dist/agents/hygienic.d.ts +1 -1
- package/dist/agents/scout.d.ts +1 -1
- package/dist/agents/swarm.d.ts +1 -1
- package/dist/index.js +1438 -2167
- package/dist/skills/registry.generated.d.ts +1 -1
- package/package.json +1 -1
- package/skills/agents-md-mastery/SKILL.md +253 -0
- package/skills/brainstorming/SKILL.md +1 -0
- package/skills/dispatching-parallel-agents/SKILL.md +3 -3
- package/skills/docker-mastery/SKILL.md +346 -0
- package/skills/executing-plans/SKILL.md +8 -3
- package/skills/parallel-exploration/SKILL.md +18 -133
- package/skills/test-driven-development/SKILL.md +1 -1
- package/skills/writing-plans/SKILL.md +7 -0
- package/dist/background/agent-gate.d.ts +0 -64
- package/dist/background/concurrency.d.ts +0 -102
- package/dist/background/index.d.ts +0 -27
- package/dist/background/manager.d.ts +0 -169
- package/dist/background/poller.d.ts +0 -131
- package/dist/background/store.d.ts +0 -100
- package/dist/background/types.d.ts +0 -246
- package/dist/tools/background-tools.d.ts +0 -37
- package/skills/onboarding/SKILL.md +0 -61
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: parallel-exploration
|
|
3
|
-
description: Use when you need parallel, read-only exploration with
|
|
3
|
+
description: Use when you need parallel, read-only exploration with task() (Scout fan-out)
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Parallel Exploration (Scout Fan-Out)
|
|
@@ -13,11 +13,7 @@ When you need to answer "where/how does X work?" across multiple domains (codeba
|
|
|
13
13
|
|
|
14
14
|
**Safe in Planning mode:** This is read-only exploration. It is OK to use during exploratory research even when there is no feature, no plan, and no approved tasks.
|
|
15
15
|
|
|
16
|
-
**This skill is for read-only research.** For parallel implementation work, use `hive_skill("dispatching-parallel-agents")` with `
|
|
17
|
-
|
|
18
|
-
**Two valid execution paths:**
|
|
19
|
-
- **Path A (Hive background tools):** Use `hive_background_task`, `hive_background_output`, `hive_background_cancel` when available.
|
|
20
|
-
- **Path B (Task mode):** Use native `task()` for delegation when background tools are not registered.
|
|
16
|
+
**This skill is for read-only research.** For parallel implementation work, use `hive_skill("dispatching-parallel-agents")` with `hive_worktree_create`.
|
|
21
17
|
|
|
22
18
|
## When to Use
|
|
23
19
|
|
|
@@ -56,51 +52,16 @@ Split your investigation into 2-4 independent sub-questions. Good decomposition:
|
|
|
56
52
|
- "What is X?" then "How is X used?" (second depends on first)
|
|
57
53
|
- "Find the bug" then "Fix the bug" (not read-only)
|
|
58
54
|
|
|
59
|
-
### 2. Spawn
|
|
55
|
+
### 2. Spawn Tasks (Fan-Out)
|
|
60
56
|
|
|
61
57
|
Launch all tasks before waiting for any results:
|
|
62
58
|
|
|
63
59
|
```typescript
|
|
64
|
-
// Path A: Hive background tools (when available)
|
|
65
|
-
// Fan-out: spawn all tasks first
|
|
66
|
-
hive_background_task({
|
|
67
|
-
agent: "scout-researcher",
|
|
68
|
-
description: "Find hive_background_task implementation",
|
|
69
|
-
prompt: `Where is hive_background_task implemented and registered?
|
|
70
|
-
- Find the tool definition
|
|
71
|
-
- Find the plugin registration
|
|
72
|
-
- Return file paths with line numbers`,
|
|
73
|
-
sync: false
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
hive_background_task({
|
|
77
|
-
agent: "scout-researcher",
|
|
78
|
-
description: "Analyze background task concurrency",
|
|
79
|
-
prompt: `How does background task concurrency/queueing work?
|
|
80
|
-
- Find the manager/scheduler code
|
|
81
|
-
- Document the concurrency model
|
|
82
|
-
- Return file paths with evidence`,
|
|
83
|
-
sync: false
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
hive_background_task({
|
|
87
|
-
agent: "scout-researcher",
|
|
88
|
-
description: "Find parent notification mechanism",
|
|
89
|
-
prompt: `How does parent notification work for background tasks?
|
|
90
|
-
- Where is the notification built?
|
|
91
|
-
- How is it sent to the parent session?
|
|
92
|
-
- Return file paths with evidence`,
|
|
93
|
-
sync: false
|
|
94
|
-
})
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
// Path B: Task mode (native task tool)
|
|
99
60
|
// Parallelize by issuing multiple task() calls in the same assistant message.
|
|
100
61
|
task({
|
|
101
62
|
subagent_type: 'scout-researcher',
|
|
102
|
-
description: 'Find
|
|
103
|
-
prompt: `Where
|
|
63
|
+
description: 'Find API route implementation',
|
|
64
|
+
prompt: `Where are API routes implemented and registered?
|
|
104
65
|
- Find the tool definition
|
|
105
66
|
- Find the plugin registration
|
|
106
67
|
- Return file paths with line numbers`,
|
|
@@ -126,8 +87,7 @@ task({
|
|
|
126
87
|
```
|
|
127
88
|
|
|
128
89
|
**Key points:**
|
|
129
|
-
- Use `
|
|
130
|
-
- Use `sync: false` to return immediately (non-blocking)
|
|
90
|
+
- Use `subagent_type: 'scout-researcher'` for read-only exploration
|
|
131
91
|
- Give each task a clear, focused `description`
|
|
132
92
|
- Make prompts specific about what evidence to return
|
|
133
93
|
|
|
@@ -142,35 +102,7 @@ You'll receive a `<system-reminder>` notification when each task completes.
|
|
|
142
102
|
|
|
143
103
|
### 4. Collect Results
|
|
144
104
|
|
|
145
|
-
When
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
// Path A: Hive background tools
|
|
149
|
-
// Get output from completed task
|
|
150
|
-
hive_background_output({
|
|
151
|
-
task_id: "task-abc123",
|
|
152
|
-
block: false // Don't wait, task already done
|
|
153
|
-
})
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
**For incremental output (long-running tasks):**
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
// First call - get initial output
|
|
160
|
-
hive_background_output({
|
|
161
|
-
task_id: "task-abc123",
|
|
162
|
-
block: true, // Wait for output
|
|
163
|
-
timeout: 30000 // 30 second timeout
|
|
164
|
-
})
|
|
165
|
-
// Returns: { output: "...", cursor: "5" }
|
|
166
|
-
|
|
167
|
-
// Later call - get new output since cursor
|
|
168
|
-
hive_background_output({
|
|
169
|
-
task_id: "task-abc123",
|
|
170
|
-
cursor: "5", // Resume from message 5
|
|
171
|
-
block: true
|
|
172
|
-
})
|
|
173
|
-
```
|
|
105
|
+
When each task completes, its result is returned directly. Collect the outputs from each task and proceed to synthesis.
|
|
174
106
|
|
|
175
107
|
### 5. Synthesize Findings
|
|
176
108
|
|
|
@@ -181,16 +113,7 @@ Combine results from all tasks:
|
|
|
181
113
|
|
|
182
114
|
### 6. Cleanup (If Needed)
|
|
183
115
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
// Path A: Hive background tools
|
|
188
|
-
// Cancel specific task
|
|
189
|
-
hive_background_cancel({ task_id: "task-abc123" })
|
|
190
|
-
|
|
191
|
-
// Cancel all your background tasks
|
|
192
|
-
hive_background_cancel({ all: true })
|
|
193
|
-
```
|
|
116
|
+
No manual cancellation is required in task mode.
|
|
194
117
|
|
|
195
118
|
## Prompt Templates
|
|
196
119
|
|
|
@@ -238,48 +161,20 @@ Return:
|
|
|
238
161
|
|
|
239
162
|
## Real Example
|
|
240
163
|
|
|
241
|
-
**Investigation:** "How does the
|
|
164
|
+
**Investigation:** "How does the API routing system work?"
|
|
242
165
|
|
|
243
166
|
**Decomposition:**
|
|
244
|
-
1. Implementation: Where
|
|
245
|
-
2.
|
|
246
|
-
3. Notifications: How
|
|
167
|
+
1. Implementation: Where are API routes defined?
|
|
168
|
+
2. Routing: How does route registration work?
|
|
169
|
+
3. Notifications: How are errors surfaced to the caller?
|
|
247
170
|
|
|
248
171
|
**Fan-out:**
|
|
249
172
|
```typescript
|
|
250
|
-
// Path A: Hive background tools
|
|
251
|
-
// Task 1: Implementation
|
|
252
|
-
hive_background_task({
|
|
253
|
-
agent: "scout-researcher",
|
|
254
|
-
description: "Find hive_background_task implementation",
|
|
255
|
-
prompt: "Where is hive_background_task implemented? Find tool definition and registration.",
|
|
256
|
-
sync: false
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
// Task 2: Concurrency
|
|
260
|
-
hive_background_task({
|
|
261
|
-
agent: "scout-researcher",
|
|
262
|
-
description: "Analyze concurrency model",
|
|
263
|
-
prompt: "How does background task concurrency work? Find the manager/scheduler.",
|
|
264
|
-
sync: false
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
// Task 3: Notifications
|
|
268
|
-
hive_background_task({
|
|
269
|
-
agent: "scout-researcher",
|
|
270
|
-
description: "Find notification mechanism",
|
|
271
|
-
prompt: "How are parent sessions notified of task completion?",
|
|
272
|
-
sync: false
|
|
273
|
-
})
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
```typescript
|
|
277
|
-
// Path B: Task mode (native task tool)
|
|
278
173
|
// Parallelize by issuing multiple task() calls in the same assistant message.
|
|
279
174
|
task({
|
|
280
175
|
subagent_type: 'scout-researcher',
|
|
281
|
-
description: 'Find
|
|
282
|
-
prompt: 'Where
|
|
176
|
+
description: 'Find API route implementation',
|
|
177
|
+
prompt: 'Where are API routes implemented? Find tool definition and registration.',
|
|
283
178
|
});
|
|
284
179
|
|
|
285
180
|
task({
|
|
@@ -307,20 +202,12 @@ task({
|
|
|
307
202
|
**Spawning sequentially (defeats the purpose):**
|
|
308
203
|
```typescript
|
|
309
204
|
// BAD: Wait for each before spawning next
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
```typescript
|
|
315
|
-
// GOOD: Spawn all, then collect
|
|
316
|
-
hive_background_task({ ..., sync: false }) // Returns immediately
|
|
317
|
-
hive_background_task({ ..., sync: false }) // Returns immediately
|
|
318
|
-
hive_background_task({ ..., sync: false }) // Returns immediately
|
|
319
|
-
// ... later, collect results with hive_background_output
|
|
205
|
+
await task({ ... });
|
|
206
|
+
await task({ ... });
|
|
320
207
|
```
|
|
321
208
|
|
|
322
209
|
```typescript
|
|
323
|
-
// GOOD
|
|
210
|
+
// GOOD: Spawn all in the same assistant message
|
|
324
211
|
task({ ... });
|
|
325
212
|
task({ ... });
|
|
326
213
|
task({ ... });
|
|
@@ -349,7 +236,5 @@ task({ ... });
|
|
|
349
236
|
|
|
350
237
|
After using this pattern, verify:
|
|
351
238
|
- [ ] All tasks spawned before collecting any results (true fan-out)
|
|
352
|
-
- [ ]
|
|
353
|
-
- [ ] Successfully retrieved output with `hive_background_output` (Path A)
|
|
354
|
-
- [ ] Verified `task()` fan-out pattern used when in task mode (Path B)
|
|
239
|
+
- [ ] Verified `task()` fan-out pattern used for parallel exploration
|
|
355
240
|
- [ ] Synthesized findings into coherent answer
|
|
@@ -356,7 +356,7 @@ Never fix bugs without a test.
|
|
|
356
356
|
|
|
357
357
|
## Testing Anti-Patterns
|
|
358
358
|
|
|
359
|
-
When adding mocks or test utilities,
|
|
359
|
+
When adding mocks or test utilities, avoid common pitfalls:
|
|
360
360
|
- Testing mock behavior instead of real behavior
|
|
361
361
|
- Adding test-only methods to production classes
|
|
362
362
|
- Mocking without understanding dependencies
|
|
@@ -111,6 +111,12 @@ Always include **Depends on** for each task. Use `none` to enable parallel start
|
|
|
111
111
|
**Verify**:
|
|
112
112
|
- [ ] Run: `{command}` → {expected}
|
|
113
113
|
- [ ] {Additional acceptance criteria}
|
|
114
|
+
|
|
115
|
+
All verification MUST be agent-executable (no human intervention):
|
|
116
|
+
✅ `bun test` → all pass
|
|
117
|
+
✅ `curl -X POST /api/x` → 201
|
|
118
|
+
❌ "User manually tests..."
|
|
119
|
+
❌ "Visually confirm..."
|
|
114
120
|
````
|
|
115
121
|
|
|
116
122
|
## Remember
|
|
@@ -119,6 +125,7 @@ Always include **Depends on** for each task. Use `none` to enable parallel start
|
|
|
119
125
|
- Exact commands with expected output
|
|
120
126
|
- Reference relevant skills with @ syntax
|
|
121
127
|
- DRY, YAGNI, TDD, frequent commits
|
|
128
|
+
- All acceptance criteria must be agent-executable (zero human intervention)
|
|
122
129
|
|
|
123
130
|
## Execution Handoff
|
|
124
131
|
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent discovery and capability gating for background tasks.
|
|
3
|
-
*
|
|
4
|
-
* Provides:
|
|
5
|
-
* - Dynamic agent discovery from OpenCode registry
|
|
6
|
-
* - Validation that requested agents exist
|
|
7
|
-
* - Safety gating to prevent recursion (orchestrator agents spawning themselves)
|
|
8
|
-
* - Encapsulated logic for tool layer consumption
|
|
9
|
-
*/
|
|
10
|
-
import { OpencodeClient, AgentInfo, AgentValidationResult } from './types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Options for agent validation.
|
|
13
|
-
*/
|
|
14
|
-
export interface AgentValidationOptions {
|
|
15
|
-
/** Allow restricted agents (requires explicit opt-in) */
|
|
16
|
-
allowRestricted?: boolean;
|
|
17
|
-
/** Custom blocked agents (merged with defaults) */
|
|
18
|
-
additionalBlocked?: string[];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Agent discovery and gating service.
|
|
22
|
-
* Validates agents exist and are safe to spawn as background workers.
|
|
23
|
-
*/
|
|
24
|
-
export declare class AgentGate {
|
|
25
|
-
private client;
|
|
26
|
-
private cachedAgents;
|
|
27
|
-
private cacheExpiry;
|
|
28
|
-
private readonly cacheTtlMs;
|
|
29
|
-
constructor(client: OpencodeClient);
|
|
30
|
-
/**
|
|
31
|
-
* Get all available agents from OpenCode registry.
|
|
32
|
-
* Results are cached for performance.
|
|
33
|
-
*/
|
|
34
|
-
discoverAgents(): Promise<AgentInfo[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Validate that an agent exists and is safe to spawn.
|
|
37
|
-
*
|
|
38
|
-
* @param agentName - Name of the agent to validate
|
|
39
|
-
* @param options - Validation options
|
|
40
|
-
* @returns Validation result with agent info if valid
|
|
41
|
-
*/
|
|
42
|
-
validate(agentName: string, options?: AgentValidationOptions): Promise<AgentValidationResult>;
|
|
43
|
-
/**
|
|
44
|
-
* Get a list of agents suitable for background work.
|
|
45
|
-
* Filters out orchestrator and restricted agents.
|
|
46
|
-
*/
|
|
47
|
-
getWorkerAgents(): Promise<AgentInfo[]>;
|
|
48
|
-
/**
|
|
49
|
-
* Clear the agent cache (for testing or forced refresh).
|
|
50
|
-
*/
|
|
51
|
-
clearCache(): void;
|
|
52
|
-
/**
|
|
53
|
-
* Check if an agent name is blocked.
|
|
54
|
-
*/
|
|
55
|
-
isBlocked(agentName: string): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Check if an agent name is restricted.
|
|
58
|
-
*/
|
|
59
|
-
isRestricted(agentName: string): boolean;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create a new AgentGate instance.
|
|
63
|
-
*/
|
|
64
|
-
export declare function createAgentGate(client: OpencodeClient): AgentGate;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Concurrency Manager for background task execution.
|
|
3
|
-
*
|
|
4
|
-
* Provides:
|
|
5
|
-
* - Per-agent or per-model concurrency limiting
|
|
6
|
-
* - Queueing with FIFO ordering
|
|
7
|
-
* - Proper slot release and handoff
|
|
8
|
-
* - Rate limiting with exponential backoff
|
|
9
|
-
* - Timeout handling to prevent indefinite starvation
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Configuration for concurrency limits.
|
|
13
|
-
*/
|
|
14
|
-
export interface ConcurrencyConfig {
|
|
15
|
-
/** Default concurrent tasks per key (default: 3) */
|
|
16
|
-
defaultLimit?: number;
|
|
17
|
-
/** Per-agent limits: { "forager": 2, "explorer": 1 } */
|
|
18
|
-
agentLimits?: Record<string, number>;
|
|
19
|
-
/** Per-model limits: { "anthropic/claude-sonnet": 2 } */
|
|
20
|
-
modelLimits?: Record<string, number>;
|
|
21
|
-
/** Maximum wait time in queue before rejection (default: 300000 = 5 min) */
|
|
22
|
-
queueTimeoutMs?: number;
|
|
23
|
-
/** Minimum delay between task starts for same key (default: 1000 = 1 sec) */
|
|
24
|
-
minDelayBetweenStartsMs?: number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Concurrency Manager for background tasks.
|
|
28
|
-
*
|
|
29
|
-
* Uses a key-based system where keys can be:
|
|
30
|
-
* - Agent names: "forager", "explorer"
|
|
31
|
-
* - Model identifiers: "anthropic/claude-sonnet"
|
|
32
|
-
* - Custom keys: "hive-task"
|
|
33
|
-
*/
|
|
34
|
-
export declare class ConcurrencyManager {
|
|
35
|
-
private config;
|
|
36
|
-
private counts;
|
|
37
|
-
private queues;
|
|
38
|
-
private lastStartTimes;
|
|
39
|
-
constructor(config?: ConcurrencyConfig);
|
|
40
|
-
/**
|
|
41
|
-
* Get the concurrency limit for a key.
|
|
42
|
-
* Checks model limits, then agent limits, then default.
|
|
43
|
-
*/
|
|
44
|
-
getLimit(key: string): number;
|
|
45
|
-
/**
|
|
46
|
-
* Acquire a concurrency slot for the given key.
|
|
47
|
-
* Returns immediately if slot is available, otherwise queues.
|
|
48
|
-
*
|
|
49
|
-
* @throws Error if queue timeout is exceeded
|
|
50
|
-
*/
|
|
51
|
-
acquire(key: string): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* Release a concurrency slot.
|
|
54
|
-
* If there are waiters, hands off to the next one.
|
|
55
|
-
*/
|
|
56
|
-
release(key: string): void;
|
|
57
|
-
/**
|
|
58
|
-
* Try to acquire without waiting.
|
|
59
|
-
* Returns true if slot was acquired, false otherwise.
|
|
60
|
-
*/
|
|
61
|
-
tryAcquire(key: string): boolean;
|
|
62
|
-
/**
|
|
63
|
-
* Cancel all waiting entries for a key.
|
|
64
|
-
*/
|
|
65
|
-
cancelWaiters(key: string): number;
|
|
66
|
-
/**
|
|
67
|
-
* Clear all state. Used during shutdown.
|
|
68
|
-
*/
|
|
69
|
-
clear(): void;
|
|
70
|
-
/**
|
|
71
|
-
* Get current slot count for a key.
|
|
72
|
-
*/
|
|
73
|
-
getCount(key: string): number;
|
|
74
|
-
/**
|
|
75
|
-
* Get queue length for a key.
|
|
76
|
-
*/
|
|
77
|
-
getQueueLength(key: string): number;
|
|
78
|
-
/**
|
|
79
|
-
* Get available slots for a key.
|
|
80
|
-
*/
|
|
81
|
-
getAvailable(key: string): number;
|
|
82
|
-
/**
|
|
83
|
-
* Check if a key is at capacity.
|
|
84
|
-
*/
|
|
85
|
-
isAtCapacity(key: string): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Get status summary for all keys.
|
|
88
|
-
*/
|
|
89
|
-
getStatus(): Record<string, {
|
|
90
|
-
count: number;
|
|
91
|
-
limit: number;
|
|
92
|
-
queued: number;
|
|
93
|
-
}>;
|
|
94
|
-
/**
|
|
95
|
-
* Enforce rate limiting (minimum delay between starts).
|
|
96
|
-
*/
|
|
97
|
-
private enforceRateLimit;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Create a new ConcurrencyManager instance.
|
|
101
|
-
*/
|
|
102
|
-
export declare function createConcurrencyManager(config?: ConcurrencyConfig): ConcurrencyManager;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Background tasking module for Hive worker execution.
|
|
3
|
-
*
|
|
4
|
-
* Provides the internal background task management capabilities used by:
|
|
5
|
-
* - background_task / background_output / background_cancel tools (Task 04)
|
|
6
|
-
* - hive_exec_start integration (Task 05)
|
|
7
|
-
*
|
|
8
|
-
* Core capabilities:
|
|
9
|
-
* 1. In-memory store with state machine enforcement
|
|
10
|
-
* 2. Idempotency support for safe retries
|
|
11
|
-
* 3. Dynamic agent discovery and gating
|
|
12
|
-
* 4. Hive task persistence via TaskService
|
|
13
|
-
* 5. Concurrency limiting with queueing (Task 06)
|
|
14
|
-
* 6. Polling/stability detection - READ-ONLY (Task 06)
|
|
15
|
-
* 7. Sequential ordering enforcement for Hive tasks (Task 06)
|
|
16
|
-
*/
|
|
17
|
-
export type { BackgroundTaskStatus, BackgroundTaskRecord, BackgroundTaskProgress, SpawnOptions, SpawnResult, OpencodeClient, AgentInfo, AgentValidationResult, } from './types.js';
|
|
18
|
-
export { VALID_TRANSITIONS, isTerminalStatus, isValidTransition, } from './types.js';
|
|
19
|
-
export { BackgroundTaskStore, getStore, resetStore, } from './store.js';
|
|
20
|
-
export type { AgentValidationOptions, } from './agent-gate.js';
|
|
21
|
-
export { AgentGate, createAgentGate, } from './agent-gate.js';
|
|
22
|
-
export type { ConcurrencyConfig, } from './concurrency.js';
|
|
23
|
-
export { ConcurrencyManager, createConcurrencyManager, } from './concurrency.js';
|
|
24
|
-
export type { PollerConfig, TaskObservation, } from './poller.js';
|
|
25
|
-
export { BackgroundPoller, createPoller, } from './poller.js';
|
|
26
|
-
export type { BackgroundManagerOptions, } from './manager.js';
|
|
27
|
-
export { BackgroundManager, createBackgroundManager, } from './manager.js';
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Background task manager for Hive worker execution.
|
|
3
|
-
*
|
|
4
|
-
* Provides the main API for:
|
|
5
|
-
* - Spawning background tasks with idempotency
|
|
6
|
-
* - Managing task lifecycle (start, complete, cancel)
|
|
7
|
-
* - Persisting Hive-linked task metadata via TaskService
|
|
8
|
-
* - Querying task status
|
|
9
|
-
* - Concurrency limiting with queueing
|
|
10
|
-
* - Polling/stability detection (read-only)
|
|
11
|
-
* - Sequential ordering enforcement for Hive tasks
|
|
12
|
-
*/
|
|
13
|
-
import { BackgroundTaskStore } from './store.js';
|
|
14
|
-
import { AgentGate } from './agent-gate.js';
|
|
15
|
-
import { ConcurrencyManager, ConcurrencyConfig } from './concurrency.js';
|
|
16
|
-
import { BackgroundPoller, PollerConfig, TaskObservation } from './poller.js';
|
|
17
|
-
import { BackgroundTaskRecord, BackgroundTaskStatus, OpencodeClient, SpawnOptions, SpawnResult } from './types.js';
|
|
18
|
-
/**
|
|
19
|
-
* Options for creating a BackgroundManager.
|
|
20
|
-
*/
|
|
21
|
-
export interface BackgroundManagerOptions {
|
|
22
|
-
/** OpenCode client for session management */
|
|
23
|
-
client: OpencodeClient;
|
|
24
|
-
/** Project root directory for TaskService */
|
|
25
|
-
projectRoot: string;
|
|
26
|
-
/** Optional custom store (defaults to global singleton) */
|
|
27
|
-
store?: BackgroundTaskStore;
|
|
28
|
-
/** Concurrency configuration */
|
|
29
|
-
concurrency?: ConcurrencyConfig;
|
|
30
|
-
/** Poller configuration */
|
|
31
|
-
poller?: PollerConfig;
|
|
32
|
-
/** Enforce sequential execution for Hive tasks (default: true) */
|
|
33
|
-
enforceHiveSequential?: boolean;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Background task manager.
|
|
37
|
-
* Coordinates between in-memory store, agent validation, Hive persistence,
|
|
38
|
-
* concurrency limiting, and polling/stability detection.
|
|
39
|
-
*/
|
|
40
|
-
export declare class BackgroundManager {
|
|
41
|
-
private store;
|
|
42
|
-
private agentGate;
|
|
43
|
-
private client;
|
|
44
|
-
private taskService;
|
|
45
|
-
private concurrencyManager;
|
|
46
|
-
private poller;
|
|
47
|
-
private enforceHiveSequential;
|
|
48
|
-
constructor(options: BackgroundManagerOptions);
|
|
49
|
-
/**
|
|
50
|
-
* Spawn a new background task.
|
|
51
|
-
*
|
|
52
|
-
* Handles idempotency:
|
|
53
|
-
* - If idempotencyKey is provided and exists, returns existing task
|
|
54
|
-
* - Otherwise creates new task
|
|
55
|
-
*
|
|
56
|
-
* For Hive-linked tasks (hiveFeature + hiveTaskFolder provided):
|
|
57
|
-
* - Enforces sequential ordering (blocks if earlier tasks pending)
|
|
58
|
-
* - Persists idempotencyKey and workerSession to .hive task status.json
|
|
59
|
-
*
|
|
60
|
-
* @param options - Spawn options
|
|
61
|
-
* @returns Spawn result with task record
|
|
62
|
-
*/
|
|
63
|
-
spawn(options: SpawnOptions): Promise<SpawnResult>;
|
|
64
|
-
/**
|
|
65
|
-
* Check if a Hive task can be started based on dependency constraints.
|
|
66
|
-
*
|
|
67
|
-
* Hybrid enforcement:
|
|
68
|
-
* 1. If task has explicit dependsOn array, check all deps have status 'done'
|
|
69
|
-
* 2. If task has no dependsOn (legacy/undefined), fall back to numeric sequential ordering
|
|
70
|
-
*
|
|
71
|
-
* Only 'done' status satisfies a dependency - cancelled/failed/blocked/partial do NOT.
|
|
72
|
-
*/
|
|
73
|
-
private checkHiveTaskOrdering;
|
|
74
|
-
/**
|
|
75
|
-
* Check if all dependencies are satisfied (status === 'done').
|
|
76
|
-
* Only 'done' counts as satisfied - cancelled/failed/blocked/partial do NOT.
|
|
77
|
-
*/
|
|
78
|
-
private checkDependencies;
|
|
79
|
-
/**
|
|
80
|
-
* Legacy numeric sequential ordering check.
|
|
81
|
-
* Used when task has no dependsOn field (backwards compatibility).
|
|
82
|
-
*/
|
|
83
|
-
private checkNumericOrdering;
|
|
84
|
-
/**
|
|
85
|
-
* Get a task by ID.
|
|
86
|
-
*/
|
|
87
|
-
getTask(taskId: string): BackgroundTaskRecord | undefined;
|
|
88
|
-
/**
|
|
89
|
-
* Get a task by idempotency key.
|
|
90
|
-
*/
|
|
91
|
-
getTaskByIdempotencyKey(key: string): BackgroundTaskRecord | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Get a task by Hive feature and task folder.
|
|
94
|
-
*/
|
|
95
|
-
getTaskByHiveTask(feature: string, taskFolder: string): BackgroundTaskRecord | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* Update task status.
|
|
98
|
-
*/
|
|
99
|
-
updateStatus(taskId: string, status: BackgroundTaskStatus, options?: {
|
|
100
|
-
errorMessage?: string;
|
|
101
|
-
}): BackgroundTaskRecord;
|
|
102
|
-
/**
|
|
103
|
-
* Notify the parent session that a background task completed.
|
|
104
|
-
*
|
|
105
|
-
* This intentionally uses session.prompt() so the parent agent "wakes up"
|
|
106
|
-
* and can continue the workflow (e.g., call background_output).
|
|
107
|
-
*/
|
|
108
|
-
private notifyParentSession;
|
|
109
|
-
/**
|
|
110
|
-
* Cancel a task.
|
|
111
|
-
*/
|
|
112
|
-
cancel(taskId: string): Promise<BackgroundTaskRecord>;
|
|
113
|
-
/**
|
|
114
|
-
* Cancel all active tasks for a parent session.
|
|
115
|
-
*/
|
|
116
|
-
cancelAll(parentSessionId: string): Promise<BackgroundTaskRecord[]>;
|
|
117
|
-
/**
|
|
118
|
-
* List all tasks, optionally filtered.
|
|
119
|
-
*/
|
|
120
|
-
list(filter?: {
|
|
121
|
-
status?: BackgroundTaskStatus | BackgroundTaskStatus[];
|
|
122
|
-
parentSessionId?: string;
|
|
123
|
-
hiveFeature?: string;
|
|
124
|
-
}): BackgroundTaskRecord[];
|
|
125
|
-
/**
|
|
126
|
-
* Get all active tasks.
|
|
127
|
-
*/
|
|
128
|
-
getActive(): BackgroundTaskRecord[];
|
|
129
|
-
/**
|
|
130
|
-
* Handle session idle event (task completion).
|
|
131
|
-
*/
|
|
132
|
-
handleSessionIdle(sessionId: string): void;
|
|
133
|
-
/**
|
|
134
|
-
* Handle message event (progress update).
|
|
135
|
-
*/
|
|
136
|
-
handleMessageEvent(sessionId: string, messageText?: string): void;
|
|
137
|
-
/**
|
|
138
|
-
* Get the agent gate for direct access.
|
|
139
|
-
*/
|
|
140
|
-
getAgentGate(): AgentGate;
|
|
141
|
-
/**
|
|
142
|
-
* Get the concurrency manager for direct access.
|
|
143
|
-
*/
|
|
144
|
-
getConcurrencyManager(): ConcurrencyManager;
|
|
145
|
-
/**
|
|
146
|
-
* Get the poller for direct access.
|
|
147
|
-
*/
|
|
148
|
-
getPoller(): BackgroundPoller;
|
|
149
|
-
/**
|
|
150
|
-
* Get observations for all active tasks from the poller.
|
|
151
|
-
*/
|
|
152
|
-
getObservations(): TaskObservation[];
|
|
153
|
-
/**
|
|
154
|
-
* Get observation for a specific task.
|
|
155
|
-
*/
|
|
156
|
-
getTaskObservation(taskId: string): TaskObservation | null;
|
|
157
|
-
/**
|
|
158
|
-
* Get task counts by status.
|
|
159
|
-
*/
|
|
160
|
-
getCounts(): Record<BackgroundTaskStatus, number>;
|
|
161
|
-
/**
|
|
162
|
-
* Shutdown the manager and clean up resources.
|
|
163
|
-
*/
|
|
164
|
-
shutdown(): void;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Create a new BackgroundManager.
|
|
168
|
-
*/
|
|
169
|
-
export declare function createBackgroundManager(options: BackgroundManagerOptions): BackgroundManager;
|