@gotgenes/pi-subagents 5.5.0 → 5.7.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/CHANGELOG.md +31 -0
- package/docs/architecture/architecture.md +46 -38
- package/docs/plans/0070-extract-event-handlers.md +306 -0
- package/docs/plans/0072-inject-agent-manager-collaborators.md +2 -2
- package/docs/plans/0087-evolve-subagent-runtime-methods.md +240 -0
- package/docs/retro/0072-inject-agent-manager-collaborators.md +46 -0
- package/docs/retro/0084-extract-git-worktree-manager.md +37 -0
- package/package.json +1 -1
- package/src/agent-manager.ts +28 -23
- package/src/agent-runner.ts +18 -13
- package/src/index.ts +58 -51
- package/src/runtime.ts +48 -16
package/src/runtime.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Follows the same pattern as pi-permission-system's ExtensionRuntime.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { AgentActivity, AgentWidget } from "./ui/agent-widget.js";
|
|
9
|
+
import type { AgentActivity, AgentWidget, UICtx } from "./ui/agent-widget.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Narrow config subset read by AgentManager when constructing RunOptions.
|
|
@@ -23,27 +23,65 @@ export interface RunConfig {
|
|
|
23
23
|
* Created once inside `piSubagentsExtension()` via `createSubagentRuntime()`.
|
|
24
24
|
* Tests construct a fresh runtime per test for full isolation.
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
26
|
+
export class SubagentRuntime {
|
|
27
27
|
// ── Execution config (was module-scope in agent-runner.ts) ──────────────
|
|
28
28
|
/** Default max turns for all agents. undefined = unlimited. */
|
|
29
|
-
defaultMaxTurns: number | undefined;
|
|
29
|
+
defaultMaxTurns: number | undefined = undefined;
|
|
30
30
|
/** Additional turns allowed after the soft-limit steer message. */
|
|
31
|
-
graceTurns: number;
|
|
31
|
+
graceTurns: number = 5;
|
|
32
32
|
|
|
33
33
|
// ── Session state (was closure-scoped in index.ts) ───────────────────────
|
|
34
34
|
/** Active Pi session context — set on session_start, cleared on session_shutdown. */
|
|
35
|
-
currentCtx: { pi: unknown; ctx: unknown } | undefined;
|
|
35
|
+
currentCtx: { pi: unknown; ctx: unknown } | undefined = undefined;
|
|
36
36
|
/**
|
|
37
37
|
* Per-agent live activity state shared across the notification system,
|
|
38
38
|
* widget, and tool handlers. The Map itself is never replaced.
|
|
39
39
|
*/
|
|
40
|
-
readonly agentActivity: Map<string, AgentActivity
|
|
40
|
+
readonly agentActivity: Map<string, AgentActivity> = new Map();
|
|
41
41
|
/**
|
|
42
42
|
* Persistent widget reference. Null until constructed after AgentManager.
|
|
43
|
-
*
|
|
44
|
-
* complete after widget construction.
|
|
43
|
+
* Delegation methods use optional chaining so callers never need `widget!`.
|
|
45
44
|
*/
|
|
46
|
-
widget: AgentWidget | null;
|
|
45
|
+
widget: AgentWidget | null = null;
|
|
46
|
+
|
|
47
|
+
// ── Session-context methods ──────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
/** Store the active Pi session context (called from session_start). */
|
|
50
|
+
setSessionContext(pi: unknown, ctx: unknown): void {
|
|
51
|
+
this.currentCtx = { pi, ctx };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Clear the session context (called from session_shutdown). */
|
|
55
|
+
clearSessionContext(): void {
|
|
56
|
+
this.currentCtx = undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── Widget delegation methods ─────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/** Delegate to widget.setUICtx — no-op when widget is null. */
|
|
62
|
+
setUICtx(ctx: UICtx): void {
|
|
63
|
+
this.widget?.setUICtx(ctx);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Delegate to widget.onTurnStart — no-op when widget is null. */
|
|
67
|
+
onTurnStart(): void {
|
|
68
|
+
this.widget?.onTurnStart();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Delegate to widget.markFinished — no-op when widget is null. */
|
|
72
|
+
markFinished(id: string): void {
|
|
73
|
+
this.widget?.markFinished(id);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Delegate to widget.update — no-op when widget is null. */
|
|
77
|
+
updateWidget(): void {
|
|
78
|
+
this.widget?.update();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Delegate to widget.ensureTimer — no-op when widget is null. */
|
|
82
|
+
ensureTimer(): void {
|
|
83
|
+
this.widget?.ensureTimer();
|
|
84
|
+
}
|
|
47
85
|
}
|
|
48
86
|
|
|
49
87
|
/**
|
|
@@ -52,11 +90,5 @@ export interface SubagentRuntime {
|
|
|
52
90
|
* Call once at extension startup; pass the result to factories and handlers.
|
|
53
91
|
*/
|
|
54
92
|
export function createSubagentRuntime(): SubagentRuntime {
|
|
55
|
-
return
|
|
56
|
-
defaultMaxTurns: undefined,
|
|
57
|
-
graceTurns: 5,
|
|
58
|
-
currentCtx: undefined,
|
|
59
|
-
agentActivity: new Map(),
|
|
60
|
-
widget: null,
|
|
61
|
-
};
|
|
93
|
+
return new SubagentRuntime();
|
|
62
94
|
}
|