opencode-hive 0.9.1 → 1.0.1
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 +216 -0
- package/dist/agents/architect.d.ts +12 -0
- package/dist/agents/forager.d.ts +5 -16
- package/dist/agents/hive.d.ts +6 -28
- package/dist/agents/hygienic.d.ts +12 -0
- package/dist/agents/index.d.ts +37 -10
- package/dist/agents/scout.d.ts +5 -14
- package/dist/agents/swarm.d.ts +12 -0
- package/dist/background/agent-gate.d.ts +64 -0
- package/dist/background/concurrency.d.ts +102 -0
- package/dist/background/index.d.ts +27 -0
- package/dist/background/manager.d.ts +154 -0
- package/dist/background/poller.d.ts +131 -0
- package/dist/background/store.d.ts +100 -0
- package/dist/background/types.d.ts +246 -0
- package/dist/hooks/variant-hook.d.ts +50 -0
- package/dist/index.js +4359 -1461
- package/dist/mcp/ast-grep.d.ts +2 -0
- package/dist/mcp/context7.d.ts +2 -0
- package/dist/mcp/grep-app.d.ts +2 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/types.d.ts +12 -0
- package/dist/mcp/websearch.d.ts +2 -0
- package/dist/skills/builtin.d.ts +13 -1
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/registry.generated.d.ts +1 -1
- package/dist/skills/types.d.ts +1 -1
- package/dist/tools/background-tools.d.ts +37 -0
- package/dist/utils/format.d.ts +16 -0
- package/dist/utils/prompt-budgeting.d.ts +112 -0
- package/dist/utils/prompt-file.d.ts +58 -0
- package/dist/utils/prompt-observability.d.ts +93 -0
- package/dist/utils/worker-prompt.d.ts +5 -4
- package/package.json +7 -1
- package/skills/brainstorming/SKILL.md +52 -0
- package/skills/dispatching-parallel-agents/SKILL.md +180 -0
- package/skills/executing-plans/SKILL.md +76 -0
- package/skills/onboarding/SKILL.md +61 -0
- package/skills/parallel-exploration/SKILL.md +286 -0
- package/skills/systematic-debugging/SKILL.md +296 -0
- package/skills/test-driven-development/SKILL.md +371 -0
- package/skills/verification-before-completion/SKILL.md +139 -0
- package/skills/writing-plans/SKILL.md +116 -0
- package/dist/agents/receiver.d.ts +0 -22
- package/dist/utils/agent-selector.d.ts +0 -29
- package/skills/hive-execution/SKILL.md +0 -147
|
@@ -0,0 +1,102 @@
|
|
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
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';
|
|
@@ -0,0 +1,154 @@
|
|
|
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 sequential ordering.
|
|
66
|
+
* Returns error if earlier tasks are still pending/in_progress.
|
|
67
|
+
*/
|
|
68
|
+
private checkHiveTaskOrdering;
|
|
69
|
+
/**
|
|
70
|
+
* Get a task by ID.
|
|
71
|
+
*/
|
|
72
|
+
getTask(taskId: string): BackgroundTaskRecord | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Get a task by idempotency key.
|
|
75
|
+
*/
|
|
76
|
+
getTaskByIdempotencyKey(key: string): BackgroundTaskRecord | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get a task by Hive feature and task folder.
|
|
79
|
+
*/
|
|
80
|
+
getTaskByHiveTask(feature: string, taskFolder: string): BackgroundTaskRecord | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Update task status.
|
|
83
|
+
*/
|
|
84
|
+
updateStatus(taskId: string, status: BackgroundTaskStatus, options?: {
|
|
85
|
+
errorMessage?: string;
|
|
86
|
+
}): BackgroundTaskRecord;
|
|
87
|
+
/**
|
|
88
|
+
* Notify the parent session that a background task completed.
|
|
89
|
+
*
|
|
90
|
+
* This intentionally uses session.prompt() so the parent agent "wakes up"
|
|
91
|
+
* and can continue the workflow (e.g., call background_output).
|
|
92
|
+
*/
|
|
93
|
+
private notifyParentSession;
|
|
94
|
+
/**
|
|
95
|
+
* Cancel a task.
|
|
96
|
+
*/
|
|
97
|
+
cancel(taskId: string): Promise<BackgroundTaskRecord>;
|
|
98
|
+
/**
|
|
99
|
+
* Cancel all active tasks for a parent session.
|
|
100
|
+
*/
|
|
101
|
+
cancelAll(parentSessionId: string): Promise<BackgroundTaskRecord[]>;
|
|
102
|
+
/**
|
|
103
|
+
* List all tasks, optionally filtered.
|
|
104
|
+
*/
|
|
105
|
+
list(filter?: {
|
|
106
|
+
status?: BackgroundTaskStatus | BackgroundTaskStatus[];
|
|
107
|
+
parentSessionId?: string;
|
|
108
|
+
hiveFeature?: string;
|
|
109
|
+
}): BackgroundTaskRecord[];
|
|
110
|
+
/**
|
|
111
|
+
* Get all active tasks.
|
|
112
|
+
*/
|
|
113
|
+
getActive(): BackgroundTaskRecord[];
|
|
114
|
+
/**
|
|
115
|
+
* Handle session idle event (task completion).
|
|
116
|
+
*/
|
|
117
|
+
handleSessionIdle(sessionId: string): void;
|
|
118
|
+
/**
|
|
119
|
+
* Handle message event (progress update).
|
|
120
|
+
*/
|
|
121
|
+
handleMessageEvent(sessionId: string, messageText?: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Get the agent gate for direct access.
|
|
124
|
+
*/
|
|
125
|
+
getAgentGate(): AgentGate;
|
|
126
|
+
/**
|
|
127
|
+
* Get the concurrency manager for direct access.
|
|
128
|
+
*/
|
|
129
|
+
getConcurrencyManager(): ConcurrencyManager;
|
|
130
|
+
/**
|
|
131
|
+
* Get the poller for direct access.
|
|
132
|
+
*/
|
|
133
|
+
getPoller(): BackgroundPoller;
|
|
134
|
+
/**
|
|
135
|
+
* Get observations for all active tasks from the poller.
|
|
136
|
+
*/
|
|
137
|
+
getObservations(): TaskObservation[];
|
|
138
|
+
/**
|
|
139
|
+
* Get observation for a specific task.
|
|
140
|
+
*/
|
|
141
|
+
getTaskObservation(taskId: string): TaskObservation | null;
|
|
142
|
+
/**
|
|
143
|
+
* Get task counts by status.
|
|
144
|
+
*/
|
|
145
|
+
getCounts(): Record<BackgroundTaskStatus, number>;
|
|
146
|
+
/**
|
|
147
|
+
* Shutdown the manager and clean up resources.
|
|
148
|
+
*/
|
|
149
|
+
shutdown(): void;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a new BackgroundManager.
|
|
153
|
+
*/
|
|
154
|
+
export declare function createBackgroundManager(options: BackgroundManagerOptions): BackgroundManager;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background Poller for session status and stability detection.
|
|
3
|
+
*
|
|
4
|
+
* This module provides READ-ONLY observation of background task sessions.
|
|
5
|
+
* It does NOT write to .hive - only updates in-memory task progress.
|
|
6
|
+
*
|
|
7
|
+
* Capabilities:
|
|
8
|
+
* - Track session status (running/idle)
|
|
9
|
+
* - Track message growth and last activity timestamps
|
|
10
|
+
* - Compute "maybe stuck" heuristics
|
|
11
|
+
* - Exponential backoff to avoid polling storms
|
|
12
|
+
*/
|
|
13
|
+
import { BackgroundTaskStore } from './store.js';
|
|
14
|
+
import { OpencodeClient } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for the background poller.
|
|
17
|
+
*/
|
|
18
|
+
export interface PollerConfig {
|
|
19
|
+
/** Base polling interval in ms (default: 5000) */
|
|
20
|
+
pollIntervalMs?: number;
|
|
21
|
+
/** Max polling interval with backoff (default: 30000) */
|
|
22
|
+
maxPollIntervalMs?: number;
|
|
23
|
+
/** Time before task is considered "maybe stuck" (default: 600000 = 10 min) */
|
|
24
|
+
stuckThresholdMs?: number;
|
|
25
|
+
/** Minimum runtime before stuck detection kicks in (default: 30000 = 30 sec) */
|
|
26
|
+
minRuntimeBeforeStuckMs?: number;
|
|
27
|
+
/** Consecutive stable polls before marking as stable (default: 3) */
|
|
28
|
+
stableCountThreshold?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Optional callbacks for reacting to observed session state.
|
|
32
|
+
*
|
|
33
|
+
* NOTE: Poller remains "read-only" with respect to `.hive`.
|
|
34
|
+
* These callbacks are intended for in-memory lifecycle transitions (e.g. marking
|
|
35
|
+
* a background task completed) handled by the owning manager.
|
|
36
|
+
*/
|
|
37
|
+
export interface PollerHandlers {
|
|
38
|
+
/**
|
|
39
|
+
* Invoked when the poller observes that a background session is idle/complete.
|
|
40
|
+
*
|
|
41
|
+
* The owning manager should:
|
|
42
|
+
* - transition the task to a terminal state
|
|
43
|
+
* - release any concurrency slot
|
|
44
|
+
* - cleanup poller state
|
|
45
|
+
*/
|
|
46
|
+
onSessionIdle?: (sessionId: string, reason: 'status' | 'stable') => void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Observation result for a single task.
|
|
50
|
+
*/
|
|
51
|
+
export interface TaskObservation {
|
|
52
|
+
taskId: string;
|
|
53
|
+
sessionId: string;
|
|
54
|
+
status: string;
|
|
55
|
+
messageCount: number;
|
|
56
|
+
lastActivityAt: string | null;
|
|
57
|
+
maybeStuck: boolean;
|
|
58
|
+
stablePolls: number;
|
|
59
|
+
isStable: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Background Poller - read-only observer for task sessions.
|
|
63
|
+
*
|
|
64
|
+
* IMPORTANT: This poller does NOT write to .hive.
|
|
65
|
+
* It only updates in-memory task progress for status reporting.
|
|
66
|
+
*/
|
|
67
|
+
export declare class BackgroundPoller {
|
|
68
|
+
private store;
|
|
69
|
+
private client;
|
|
70
|
+
private config;
|
|
71
|
+
private handlers;
|
|
72
|
+
private pollingState;
|
|
73
|
+
private pollInterval;
|
|
74
|
+
private isPolling;
|
|
75
|
+
private currentIntervalMs;
|
|
76
|
+
constructor(store: BackgroundTaskStore, client: OpencodeClient, config?: PollerConfig, handlers?: PollerHandlers);
|
|
77
|
+
/**
|
|
78
|
+
* Start the background poller.
|
|
79
|
+
* Automatically stops when no active tasks remain.
|
|
80
|
+
*/
|
|
81
|
+
start(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Stop the background poller.
|
|
84
|
+
*/
|
|
85
|
+
stop(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Check if poller is currently running.
|
|
88
|
+
*/
|
|
89
|
+
isRunning(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Get observations for all active tasks.
|
|
92
|
+
* This is a read-only snapshot of current state.
|
|
93
|
+
*/
|
|
94
|
+
getObservations(): TaskObservation[];
|
|
95
|
+
/**
|
|
96
|
+
* Get observation for a specific task.
|
|
97
|
+
*/
|
|
98
|
+
getTaskObservation(taskId: string): TaskObservation | null;
|
|
99
|
+
/**
|
|
100
|
+
* Perform a single poll cycle.
|
|
101
|
+
* Updates in-memory progress only - NO .hive writes.
|
|
102
|
+
*/
|
|
103
|
+
poll(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Poll a single task and update its progress.
|
|
106
|
+
* READ-ONLY: Only updates in-memory store, never writes .hive.
|
|
107
|
+
*/
|
|
108
|
+
private pollTask;
|
|
109
|
+
/**
|
|
110
|
+
* Build an observation from task and polling state.
|
|
111
|
+
*/
|
|
112
|
+
private buildObservation;
|
|
113
|
+
/**
|
|
114
|
+
* Adjust polling interval based on activity patterns.
|
|
115
|
+
* Uses exponential backoff when tasks are stable.
|
|
116
|
+
*/
|
|
117
|
+
private adjustPollingInterval;
|
|
118
|
+
/**
|
|
119
|
+
* Clean up polling state for a task.
|
|
120
|
+
* Call when task reaches terminal state.
|
|
121
|
+
*/
|
|
122
|
+
cleanupTask(taskId: string): void;
|
|
123
|
+
/**
|
|
124
|
+
* Clear all state (for testing or shutdown).
|
|
125
|
+
*/
|
|
126
|
+
clear(): void;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create a new BackgroundPoller instance.
|
|
130
|
+
*/
|
|
131
|
+
export declare function createPoller(store: BackgroundTaskStore, client: OpencodeClient, config?: PollerConfig, handlers?: PollerHandlers): BackgroundPoller;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory store for background task records.
|
|
3
|
+
*
|
|
4
|
+
* Provides:
|
|
5
|
+
* - CRUD operations for task records
|
|
6
|
+
* - Idempotency key lookups
|
|
7
|
+
* - State machine enforcement
|
|
8
|
+
* - Query methods for task filtering
|
|
9
|
+
*/
|
|
10
|
+
import { BackgroundTaskRecord, BackgroundTaskStatus, BackgroundTaskProgress } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* In-memory store for background tasks.
|
|
13
|
+
* Thread-safe for single-process Node.js (no concurrent access issues).
|
|
14
|
+
*/
|
|
15
|
+
export declare class BackgroundTaskStore {
|
|
16
|
+
private tasks;
|
|
17
|
+
private idempotencyIndex;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new task record.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Task creation options
|
|
22
|
+
* @returns The created task record
|
|
23
|
+
* @throws If idempotencyKey already exists (use getByIdempotencyKey first)
|
|
24
|
+
*/
|
|
25
|
+
create(options: {
|
|
26
|
+
agent: string;
|
|
27
|
+
description: string;
|
|
28
|
+
sessionId: string;
|
|
29
|
+
idempotencyKey?: string;
|
|
30
|
+
parentSessionId?: string;
|
|
31
|
+
parentMessageId?: string;
|
|
32
|
+
parentAgent?: string;
|
|
33
|
+
notifyParent?: boolean;
|
|
34
|
+
hiveFeature?: string;
|
|
35
|
+
hiveTaskFolder?: string;
|
|
36
|
+
workdir?: string;
|
|
37
|
+
}): BackgroundTaskRecord;
|
|
38
|
+
/**
|
|
39
|
+
* Get a task by ID.
|
|
40
|
+
*/
|
|
41
|
+
get(taskId: string): BackgroundTaskRecord | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Get a task by idempotency key.
|
|
44
|
+
*/
|
|
45
|
+
getByIdempotencyKey(key: string): BackgroundTaskRecord | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Get a task by Hive feature and task folder.
|
|
48
|
+
*/
|
|
49
|
+
getByHiveTask(feature: string, taskFolder: string): BackgroundTaskRecord | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Update task status with state machine enforcement.
|
|
52
|
+
*
|
|
53
|
+
* @param taskId - Task ID to update
|
|
54
|
+
* @param newStatus - New status
|
|
55
|
+
* @param updates - Additional field updates
|
|
56
|
+
* @returns Updated task record
|
|
57
|
+
* @throws If transition is invalid
|
|
58
|
+
*/
|
|
59
|
+
updateStatus(taskId: string, newStatus: BackgroundTaskStatus, updates?: Partial<Pick<BackgroundTaskRecord, 'errorMessage' | 'progress'>>): BackgroundTaskRecord;
|
|
60
|
+
/**
|
|
61
|
+
* Update task progress without changing status.
|
|
62
|
+
*/
|
|
63
|
+
updateProgress(taskId: string, progress: Partial<BackgroundTaskProgress>): BackgroundTaskRecord;
|
|
64
|
+
/**
|
|
65
|
+
* Delete a task.
|
|
66
|
+
*/
|
|
67
|
+
delete(taskId: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* List all tasks, optionally filtered.
|
|
70
|
+
*/
|
|
71
|
+
list(filter?: {
|
|
72
|
+
status?: BackgroundTaskStatus | BackgroundTaskStatus[];
|
|
73
|
+
parentSessionId?: string;
|
|
74
|
+
hiveFeature?: string;
|
|
75
|
+
}): BackgroundTaskRecord[];
|
|
76
|
+
/**
|
|
77
|
+
* Get all active (non-terminal) tasks.
|
|
78
|
+
*/
|
|
79
|
+
getActive(): BackgroundTaskRecord[];
|
|
80
|
+
/**
|
|
81
|
+
* Get task count by status.
|
|
82
|
+
*/
|
|
83
|
+
countByStatus(): Record<BackgroundTaskStatus, number>;
|
|
84
|
+
/**
|
|
85
|
+
* Clear all tasks (for testing).
|
|
86
|
+
*/
|
|
87
|
+
clear(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Get total task count.
|
|
90
|
+
*/
|
|
91
|
+
get size(): number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get or create the global store instance.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getStore(): BackgroundTaskStore;
|
|
97
|
+
/**
|
|
98
|
+
* Reset the global store (for testing).
|
|
99
|
+
*/
|
|
100
|
+
export declare function resetStore(): void;
|