@gotgenes/pi-subagents 16.0.0 → 16.1.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/CHANGELOG.md +14 -0
- package/dist/public.d.ts +19 -22
- package/docs/architecture/architecture.md +49 -17
- package/docs/plans/0373-extract-subagent-state.md +250 -0
- package/docs/plans/0381-replace-concurrency-queue-with-limiter.md +267 -0
- package/docs/plans/0403-abort-subagents-on-interrupt.md +180 -0
- package/docs/retro/0373-extract-subagent-state.md +94 -0
- package/docs/retro/0381-replace-concurrency-queue-with-limiter.md +95 -0
- package/docs/retro/0400-include-parent-prompt-in-replace-mode.md +40 -0
- package/docs/retro/0403-abort-subagents-on-interrupt.md +49 -0
- package/package.json +1 -1
- package/src/handlers/index.ts +1 -0
- package/src/handlers/interrupt.ts +49 -0
- package/src/index.ts +13 -16
- package/src/lifecycle/concurrency-limiter.ts +55 -0
- package/src/lifecycle/subagent-manager.ts +57 -51
- package/src/lifecycle/subagent-state.ts +156 -0
- package/src/lifecycle/subagent.ts +86 -163
- package/src/observation/record-observer.ts +15 -13
- package/src/lifecycle/concurrency-queue.ts +0 -63
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* concurrency-queue.ts — Manages background agent scheduling with a configurable concurrency limit.
|
|
3
|
-
*
|
|
4
|
-
* Stores agent IDs (not full agent objects) and decides *when* to start them.
|
|
5
|
-
* The startAgent callback provided at construction handles the actual agent lifecycle.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export class ConcurrencyQueue {
|
|
9
|
-
private queue: string[] = [];
|
|
10
|
-
private running = 0;
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
private readonly getMaxConcurrent: () => number,
|
|
14
|
-
private readonly startAgent: (id: string) => void,
|
|
15
|
-
) {}
|
|
16
|
-
|
|
17
|
-
/** Whether the concurrency limit has been reached. */
|
|
18
|
-
isFull(): boolean {
|
|
19
|
-
return this.running >= this.getMaxConcurrent();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Add an agent ID to the wait queue. */
|
|
23
|
-
enqueue(id: string): void {
|
|
24
|
-
this.queue.push(id);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Remove an agent ID from the queue (e.g., aborted before starting). Returns true if found. */
|
|
28
|
-
dequeue(id: string): boolean {
|
|
29
|
-
const idx = this.queue.indexOf(id);
|
|
30
|
-
if (idx === -1) return false;
|
|
31
|
-
this.queue.splice(idx, 1);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Increment the running count. Called when an agent transitions to running. */
|
|
36
|
-
markStarted(): void {
|
|
37
|
-
this.running++;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Decrement the running count and drain the queue. Called when a background agent finishes. */
|
|
41
|
-
markFinished(): void {
|
|
42
|
-
this.running--;
|
|
43
|
-
this.drain();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Start queued agents until the concurrency limit is reached. */
|
|
47
|
-
drain(): void {
|
|
48
|
-
while (this.queue.length > 0 && !this.isFull()) {
|
|
49
|
-
const id = this.queue.shift()!;
|
|
50
|
-
this.startAgent(id);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Snapshot of queued IDs for iteration (e.g., abortAll). */
|
|
55
|
-
get queuedIds(): readonly string[] {
|
|
56
|
-
return this.queue;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Clear the queue without starting any agents. */
|
|
60
|
-
clear(): void {
|
|
61
|
-
this.queue = [];
|
|
62
|
-
}
|
|
63
|
-
}
|