@nklisch/pi-enhanced 0.2.7 → 0.3.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 +10 -0
- package/node_modules/@nklisch/pi-clearance/native/clearance-core.linux-x64-gnu.node +0 -0
- package/node_modules/@nklisch/pi-clearance/native/clearance-core.win32-x64-msvc.node +0 -0
- package/node_modules/@nklisch/pi-plugins/README.md +4 -2
- package/node_modules/@nklisch/pi-plugins/dist/hooks.js +81 -8
- package/node_modules/@nklisch/pi-plugins/dist/hooks.js.map +1 -1
- package/node_modules/@nklisch/pi-plugins/dist/mcp.js +32 -1
- package/node_modules/@nklisch/pi-plugins/dist/mcp.js.map +1 -1
- package/node_modules/@nklisch/pi-plugins/dist/pi/plugin-manager.d.ts +10 -4
- package/node_modules/@nklisch/pi-plugins/dist/pi/plugin-manager.js +144 -10
- package/node_modules/@nklisch/pi-plugins/dist/pi/plugin-manager.js.map +1 -1
- package/node_modules/@nklisch/pi-plugins/dist/runtime-discovery.js +40 -14
- package/node_modules/@nklisch/pi-plugins/dist/runtime-discovery.js.map +1 -1
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/CHANGELOG.md +19 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/README.md +75 -47
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/dist/public.d.ts +171 -140
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/dist/settings.d.ts +2 -2
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/docs/FORK-MAINTENANCE.md +8 -7
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/docs/VISION.md +12 -10
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/docs/architecture/architecture.md +111 -104
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/docs/comparison-with-upstream.md +3 -3
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/docs/decisions/0004-reconsider-ui-direction.md +5 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/package.json +1 -1
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/config/custom-agents.ts +31 -4
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/config/default-agents.ts +1 -1
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/config/invocation-config.ts +7 -4
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/index.ts +18 -9
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/layered-settings.ts +2 -2
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/child-lifecycle.ts +10 -63
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/concurrency-limiter.ts +122 -76
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/create-subagent-session.ts +3 -5
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/lifecycle-interceptor.ts +4 -3
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/run-listeners.ts +2 -23
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/subagent-manager.ts +177 -252
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/subagent-session.ts +90 -280
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/subagent-state.ts +153 -239
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/subagent.ts +569 -700
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/lifecycle/workspace.ts +1 -1
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/observation/notification.ts +78 -122
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/observation/renderer.ts +15 -42
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/observation/subagent-events-observer.ts +44 -95
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/service/service-adapter.ts +157 -90
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/service/service.ts +60 -68
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/session/conversation.ts +3 -3
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/session/query-source.ts +28 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/session/query.ts +327 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/settings.ts +1 -1
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/agent-tool.ts +171 -249
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/get-result-tool.ts +51 -94
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/helpers.ts +9 -6
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/list-tool.ts +46 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/parent-tool-registry.ts +17 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/query-session-tool.ts +330 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/result-renderer.ts +27 -111
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/resume-tool.ts +105 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/spawn-config.ts +26 -8
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/steer-tool.ts +27 -111
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/stop-tool.ts +53 -0
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/types.ts +11 -5
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/ui/agent-widget.ts +33 -27
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/ui/display.ts +6 -3
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/ui/session-navigation.ts +121 -10
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/ui/session-navigator.ts +430 -112
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/ui/subagents-settings.ts +1 -1
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/ui/widget-renderer.ts +8 -9
- package/node_modules/@nklisch/pi-plugins/package.json +2 -2
- package/package.json +1 -1
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/background-spawner.ts +0 -81
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/foreground-runner.ts +0 -149
- package/node_modules/@nklisch/pi-plugins/node_modules/@nklisch/pi-subagents/src/tools/get-result-report.ts +0 -77
|
@@ -1,249 +1,163 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* subagent-state.ts — SubagentState value object: lifecycle status, metrics, and live activity.
|
|
3
|
-
*
|
|
4
|
-
* Owns the passive, readable state of a subagent — status, result, error,
|
|
5
|
-
* timestamps, stats (toolUses, lifetimeUsage, compactionCount), and live-activity
|
|
6
|
-
* fields (turnCount, activeTools, responseText) — together with the transition
|
|
7
|
-
* methods (markRunning, markCompleted, …), accumulation methods
|
|
8
|
-
* (incrementToolUses, addUsage, incrementCompactions), and live-activity
|
|
9
|
-
* transition methods (incrementTurnCount, addActiveTool, removeActiveTool,
|
|
10
|
-
* resetResponseText, appendResponseText) that mutate them.
|
|
11
|
-
*
|
|
12
|
-
* State is encapsulated behind getters; external code reads through them but
|
|
13
|
-
* mutates only via the transition/accumulation methods. The value object owns
|
|
14
|
-
* all of its own mutations — no field is written from outside.
|
|
15
|
-
*
|
|
16
|
-
* Subagent holds one of these privately and delegates its getters and mutation
|
|
17
|
-
* methods to it. Extracting it lets the lifecycle state machine and the
|
|
18
|
-
* session-event observer be unit-tested without constructing an executor.
|
|
19
|
-
*/
|
|
1
|
+
/** Authoritative coarse lifecycle state and metrics for one subagent record. */
|
|
20
2
|
|
|
21
3
|
import type { LifetimeUsage } from "#src/lifecycle/usage";
|
|
22
4
|
import { addUsage } from "#src/lifecycle/usage";
|
|
23
5
|
|
|
24
|
-
export type SubagentStatus =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
export type SubagentStatus = "queued" | "running" | "completed" | "stopped" | "error";
|
|
7
|
+
|
|
8
|
+
export type SubagentTerminalReason =
|
|
9
|
+
| "completed"
|
|
10
|
+
| "explicit_stop"
|
|
11
|
+
| "parent_cancelled"
|
|
12
|
+
| "runtime_timeout"
|
|
13
|
+
| "turn_limit_graceful"
|
|
14
|
+
| "turn_limit_hard"
|
|
15
|
+
| "lifecycle_abort"
|
|
16
|
+
| "provider_failure"
|
|
17
|
+
| "execution_failure"
|
|
18
|
+
| "workspace_teardown_failure";
|
|
19
|
+
|
|
20
|
+
export type SubagentStopReason = "explicit_stop" | "parent_cancelled" | "runtime_timeout";
|
|
32
21
|
|
|
33
22
|
export interface SubagentStateInit {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
status?: SubagentStatus;
|
|
24
|
+
result?: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
startedAt?: number;
|
|
27
|
+
completedAt?: number;
|
|
28
|
+
consumedAt?: number;
|
|
29
|
+
terminalReason?: SubagentTerminalReason;
|
|
30
|
+
toolUses?: number;
|
|
31
|
+
lifetimeUsage?: LifetimeUsage;
|
|
32
|
+
compactionCount?: number;
|
|
33
|
+
turnCount?: number;
|
|
34
|
+
activeTools?: ReadonlyMap<string, string>;
|
|
35
|
+
responseText?: string;
|
|
43
36
|
}
|
|
44
37
|
|
|
45
38
|
export class SubagentState {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Transition to aborted state.
|
|
172
|
-
* Always sets result and completedAt (??=). Only changes status if not stopped.
|
|
173
|
-
*/
|
|
174
|
-
markAborted(result: string, completedAt?: number): void {
|
|
175
|
-
this._result = result;
|
|
176
|
-
this._completedAt ??= completedAt ?? Date.now();
|
|
177
|
-
if (this._status !== "stopped") {
|
|
178
|
-
this._status = "aborted";
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Transition to steered state.
|
|
184
|
-
* Always sets result and completedAt (??=). Only changes status if not stopped.
|
|
185
|
-
*/
|
|
186
|
-
markSteered(result: string, completedAt?: number): void {
|
|
187
|
-
this._result = result;
|
|
188
|
-
this._completedAt ??= completedAt ?? Date.now();
|
|
189
|
-
if (this._status !== "stopped") {
|
|
190
|
-
this._status = "steered";
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Transition to error state.
|
|
196
|
-
* Always sets error (formatted) and completedAt (??=). Only changes status if not stopped.
|
|
197
|
-
*/
|
|
198
|
-
markError(error: unknown, completedAt?: number): void {
|
|
199
|
-
this.markFailed(error, undefined, completedAt);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** Record a failure together with any partial output produced before it. */
|
|
203
|
-
markFailed(error: unknown, partialResult?: string, completedAt?: number): void {
|
|
204
|
-
this._error = error instanceof Error ? error.message : String(error);
|
|
205
|
-
this._result = partialResult?.trim() ? partialResult : undefined;
|
|
206
|
-
this._completedAt ??= completedAt ?? Date.now();
|
|
207
|
-
if (this._status !== "stopped") {
|
|
208
|
-
this._status = "error";
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** Record that the parent collected the outcome. Idempotent. */
|
|
213
|
-
markConsumed(at?: number): void {
|
|
214
|
-
this._consumedAt ??= at ?? Date.now();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/** Claim the next terminal outcome for a blocking direct-result request. */
|
|
218
|
-
beginResultWait(): void {
|
|
219
|
-
this._pendingResultWaits++;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/** Release one direct-result claim after its wait returns or is interrupted. */
|
|
223
|
-
endResultWait(): void {
|
|
224
|
-
this._pendingResultWaits = Math.max(0, this._pendingResultWaits - 1);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/** Transition to stopped state. Always valid — no guard. */
|
|
228
|
-
markStopped(completedAt?: number): void {
|
|
229
|
-
this._status = "stopped";
|
|
230
|
-
this._completedAt = completedAt ?? Date.now();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** Stop an agent before the limiter admitted it. */
|
|
234
|
-
stopQueued(completedAt?: number): void {
|
|
235
|
-
if (this._status === "queued") this._stoppedWhileQueued = true;
|
|
236
|
-
this.markStopped(completedAt);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/** Reset for resume: running status, new startedAt, clear completedAt/result/error. */
|
|
240
|
-
resetForResume(startedAt: number): void {
|
|
241
|
-
this._status = "running";
|
|
242
|
-
this._startedAt = startedAt;
|
|
243
|
-
this._completedAt = undefined;
|
|
244
|
-
this._result = undefined;
|
|
245
|
-
this._error = undefined;
|
|
246
|
-
this._consumedAt = undefined;
|
|
247
|
-
this._stoppedWhileQueued = false;
|
|
248
|
-
}
|
|
39
|
+
private _status: SubagentStatus;
|
|
40
|
+
get status(): SubagentStatus { return this._status; }
|
|
41
|
+
|
|
42
|
+
private _result?: string;
|
|
43
|
+
get result(): string | undefined { return this._result; }
|
|
44
|
+
|
|
45
|
+
private _error?: string;
|
|
46
|
+
get error(): string | undefined { return this._error; }
|
|
47
|
+
|
|
48
|
+
private _startedAt: number;
|
|
49
|
+
get startedAt(): number { return this._startedAt; }
|
|
50
|
+
|
|
51
|
+
private _completedAt?: number;
|
|
52
|
+
get completedAt(): number | undefined { return this._completedAt; }
|
|
53
|
+
|
|
54
|
+
private _consumedAt?: number;
|
|
55
|
+
get consumedAt(): number | undefined { return this._consumedAt; }
|
|
56
|
+
get consumed(): boolean { return this._consumedAt != null; }
|
|
57
|
+
|
|
58
|
+
private _terminalReason?: SubagentTerminalReason;
|
|
59
|
+
get terminalReason(): SubagentTerminalReason | undefined { return this._terminalReason; }
|
|
60
|
+
|
|
61
|
+
private _toolUses: number;
|
|
62
|
+
get toolUses(): number { return this._toolUses; }
|
|
63
|
+
|
|
64
|
+
private _lifetimeUsage: LifetimeUsage;
|
|
65
|
+
get lifetimeUsage(): Readonly<LifetimeUsage> { return this._lifetimeUsage; }
|
|
66
|
+
|
|
67
|
+
private _compactionCount: number;
|
|
68
|
+
get compactionCount(): number { return this._compactionCount; }
|
|
69
|
+
|
|
70
|
+
private _turnCount: number;
|
|
71
|
+
get turnCount(): number { return this._turnCount; }
|
|
72
|
+
|
|
73
|
+
private _activeTools: Map<string, string>;
|
|
74
|
+
get activeTools(): ReadonlyMap<string, string> { return this._activeTools; }
|
|
75
|
+
private _toolKeySeq = 0;
|
|
76
|
+
|
|
77
|
+
private _responseText: string;
|
|
78
|
+
get responseText(): string { return this._responseText; }
|
|
79
|
+
|
|
80
|
+
constructor(init: SubagentStateInit = {}) {
|
|
81
|
+
this._status = init.status ?? "queued";
|
|
82
|
+
this._result = init.result;
|
|
83
|
+
this._error = init.error;
|
|
84
|
+
this._startedAt = init.startedAt ?? Date.now();
|
|
85
|
+
this._completedAt = init.completedAt;
|
|
86
|
+
this._consumedAt = init.consumedAt;
|
|
87
|
+
this._terminalReason = init.terminalReason;
|
|
88
|
+
this._toolUses = init.toolUses ?? 0;
|
|
89
|
+
this._lifetimeUsage = { ...(init.lifetimeUsage ?? { input: 0, output: 0, cacheWrite: 0 }) };
|
|
90
|
+
this._compactionCount = init.compactionCount ?? 0;
|
|
91
|
+
this._turnCount = init.turnCount ?? 1;
|
|
92
|
+
this._activeTools = new Map(init.activeTools ?? []);
|
|
93
|
+
this._responseText = init.responseText ?? "";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
incrementToolUses(): void { this._toolUses++; }
|
|
97
|
+
addUsage(delta: { input: number; output: number; cacheWrite: number }): void { addUsage(this._lifetimeUsage, delta); }
|
|
98
|
+
incrementCompactions(): void { this._compactionCount++; }
|
|
99
|
+
incrementTurnCount(): void { this._turnCount++; }
|
|
100
|
+
|
|
101
|
+
addActiveTool(toolName: string): void {
|
|
102
|
+
this._activeTools.set(`${toolName}_${++this._toolKeySeq}`, toolName);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
removeActiveTool(toolName: string): void {
|
|
106
|
+
for (const [key, name] of this._activeTools) {
|
|
107
|
+
if (name === toolName) {
|
|
108
|
+
this._activeTools.delete(key);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
resetResponseText(): void { this._responseText = ""; }
|
|
115
|
+
appendResponseText(delta: string): void { this._responseText += delta; }
|
|
116
|
+
|
|
117
|
+
markRunning(startedAt: number): void {
|
|
118
|
+
this._status = "running";
|
|
119
|
+
this._startedAt = startedAt;
|
|
120
|
+
this._completedAt = undefined;
|
|
121
|
+
this._result = undefined;
|
|
122
|
+
this._error = undefined;
|
|
123
|
+
this._consumedAt = undefined;
|
|
124
|
+
this._terminalReason = undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
markCompleted(result: string, reason: "completed" | "turn_limit_graceful", completedAt = Date.now()): void {
|
|
128
|
+
this._status = "completed";
|
|
129
|
+
this._result = result;
|
|
130
|
+
this._error = undefined;
|
|
131
|
+
this._completedAt = completedAt;
|
|
132
|
+
this._terminalReason = reason;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
markStopped(result: string | undefined, reason: SubagentStopReason | "turn_limit_hard" | "lifecycle_abort", completedAt = Date.now()): void {
|
|
136
|
+
this._status = "stopped";
|
|
137
|
+
this._result = result;
|
|
138
|
+
this._completedAt = completedAt;
|
|
139
|
+
this._terminalReason = reason;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
markError(error: unknown, reason: "provider_failure" | "execution_failure" | "workspace_teardown_failure", result?: string, completedAt = Date.now()): void {
|
|
143
|
+
this._status = "error";
|
|
144
|
+
this._error = error instanceof Error ? error.message : String(error);
|
|
145
|
+
this._result = result?.trim() ? result : undefined;
|
|
146
|
+
this._completedAt = completedAt;
|
|
147
|
+
this._terminalReason = reason;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
markConsumed(at = Date.now()): void { this._consumedAt ??= at; }
|
|
151
|
+
|
|
152
|
+
resetForResume(): void {
|
|
153
|
+
this._status = "queued";
|
|
154
|
+
this._completedAt = undefined;
|
|
155
|
+
this._result = undefined;
|
|
156
|
+
this._error = undefined;
|
|
157
|
+
this._consumedAt = undefined;
|
|
158
|
+
this._terminalReason = undefined;
|
|
159
|
+
this._responseText = "";
|
|
160
|
+
this._activeTools.clear();
|
|
161
|
+
this._turnCount = 1;
|
|
162
|
+
}
|
|
249
163
|
}
|