@bastani/atomic 0.9.38-alpha.1 → 0.9.38-alpha.3
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 +15 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +15 -2
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +4 -0
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +2 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/auth-storage-backends.d.ts +2 -0
- package/dist/core/auth-storage-backends.d.ts.map +1 -1
- package/dist/core/auth-storage-backends.js +12 -0
- package/dist/core/auth-storage-backends.js.map +1 -1
- package/dist/core/auth-storage.d.ts +5 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +46 -12
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +8 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/workflow-events.d.ts +2 -0
- package/dist/core/extensions/workflow-events.d.ts.map +1 -1
- package/dist/core/extensions/workflow-events.js.map +1 -1
- package/dist/core/model-runtime-streaming.d.ts +9 -2
- package/dist/core/model-runtime-streaming.d.ts.map +1 -1
- package/dist/core/model-runtime-streaming.js +121 -10
- package/dist/core/model-runtime-streaming.js.map +1 -1
- package/dist/core/model-runtime.d.ts +6 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +103 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +1 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +3 -0
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.js +95 -74
- package/dist/core/sdk.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-base.js +2 -1
- package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
- package/dist/modes/interactive/interactive-session-runtime.js +6 -0
- package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-tui.d.ts +1 -0
- package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-tui.js +9 -2
- package/dist/modes/interactive/interactive-tui.js.map +1 -1
- package/dist/modes/interactive/program-status-reporter.d.ts +4 -0
- package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -1
- package/dist/modes/interactive/program-status-reporter.js +45 -6
- package/dist/modes/interactive/program-status-reporter.js.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +2 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.js +9 -1
- package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +4 -0
- package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
- package/dist/modes/interactive-engine/protocol.js +39 -1
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-session-binding.js +10 -0
- package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
- package/docs/extensions/events.md +4 -0
- package/docs/providers.md +5 -1
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ProgramStatus, Terminal } from "@earendil-works/pi-tui";
|
|
2
2
|
import type { AgentSessionEvent } from "../../core/agent-session.js";
|
|
3
|
+
import type { UIPromptEndEvent, UIPromptStartEvent } from "../../core/extensions/agent-events.ts";
|
|
3
4
|
import type { WorkflowActivityFrame } from "../../core/extensions/workflow-events.js";
|
|
4
5
|
import type { JsonAgentSessionEvent } from "../json-event.ts";
|
|
5
6
|
export type BlockedStatus = {
|
|
@@ -18,14 +19,17 @@ export declare class ProgramStatusReporter {
|
|
|
18
19
|
private readonly failedRoots;
|
|
19
20
|
/** Epoch of the source whose ready snapshot is the baseline; frames before it describe history, not new outcomes. */
|
|
20
21
|
private baselineEpoch;
|
|
22
|
+
private cancellationAcknowledged;
|
|
21
23
|
private readonly getTerminal;
|
|
22
24
|
private readonly getSessionName;
|
|
23
25
|
constructor(getTerminal: () => Terminal, getSessionName: () => string | undefined);
|
|
24
26
|
handleEvent(event: AgentSessionEvent | JsonAgentSessionEvent): void;
|
|
27
|
+
handleUIPrompt(event: UIPromptStartEvent | UIPromptEndEvent | undefined): void;
|
|
25
28
|
handleWorkflowActivity(frame: WorkflowActivityFrame): void;
|
|
26
29
|
private recordOutcome;
|
|
27
30
|
setBlocked(source: string, status: BlockedStatus | undefined): void;
|
|
28
31
|
reset(): void;
|
|
32
|
+
resend(): void;
|
|
29
33
|
report(): void;
|
|
30
34
|
private currentStatus;
|
|
31
35
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program-status-reporter.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/program-status-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,qBAAqB,EAAwB,MAAM,0CAA0C,CAAC;AAC5G,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,MAAM,aAAa,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MAAM,MAAM,GAAG,SAAS,EAGhF;IAED,WAAW,CAAC,KAAK,EAAE,iBAAiB,GAAG,qBAAqB,GAAG,IAAI,CA6ClE;IAED,cAAc,CAAC,KAAK,EAAE,kBAAkB,GAAG,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAW7E;IAED,sBAAsB,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI,CA+BzD;IAED,OAAO,CAAC,aAAa;IAyBrB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI,CAIlE;IAED,KAAK,IAAI,IAAI,CAMZ;IAED,MAAM,IAAI,IAAI,CAGb;IAED,MAAM,IAAI,IAAI,CAMb;IAED,OAAO,CAAC,aAAa;IA0BrB;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;CAkB7B"}
|
|
@@ -6,6 +6,9 @@ function firstLine(text) {
|
|
|
6
6
|
function isSettledFailure(root) {
|
|
7
7
|
return root.state === "idle" && root.actionableBlockCount === 0 && root.needsAttention;
|
|
8
8
|
}
|
|
9
|
+
function isSettledCancellation(root) {
|
|
10
|
+
return root.state === "idle" && (root.endedStatus === "cancelled" || root.endedStatus === "killed");
|
|
11
|
+
}
|
|
9
12
|
export class ProgramStatusReporter {
|
|
10
13
|
runActive = false;
|
|
11
14
|
compacting = false;
|
|
@@ -18,6 +21,7 @@ export class ProgramStatusReporter {
|
|
|
18
21
|
failedRoots = new Set();
|
|
19
22
|
/** Epoch of the source whose ready snapshot is the baseline; frames before it describe history, not new outcomes. */
|
|
20
23
|
baselineEpoch;
|
|
24
|
+
cancellationAcknowledged = false;
|
|
21
25
|
getTerminal;
|
|
22
26
|
getSessionName;
|
|
23
27
|
constructor(getTerminal, getSessionName) {
|
|
@@ -32,9 +36,10 @@ export class ProgramStatusReporter {
|
|
|
32
36
|
break;
|
|
33
37
|
case "message_start":
|
|
34
38
|
// The user's next message answers a held workflow failure; lifecycle notices are custom messages.
|
|
35
|
-
if (event.message.role !== "user"
|
|
39
|
+
if (event.message.role !== "user")
|
|
36
40
|
return;
|
|
37
41
|
this.failedRoots.clear();
|
|
42
|
+
this.cancellationAcknowledged = true;
|
|
38
43
|
break;
|
|
39
44
|
case "message_end":
|
|
40
45
|
if (event.message.role !== "assistant")
|
|
@@ -75,9 +80,21 @@ export class ProgramStatusReporter {
|
|
|
75
80
|
}
|
|
76
81
|
this.report();
|
|
77
82
|
}
|
|
83
|
+
handleUIPrompt(event) {
|
|
84
|
+
if (event?.reason === "project_trust")
|
|
85
|
+
return;
|
|
86
|
+
this.setBlocked("ui-prompt", event?.type === "ui_prompt_start"
|
|
87
|
+
? {
|
|
88
|
+
kind: event.kind === "confirm" ? "permission" : "question",
|
|
89
|
+
message: event.kind === "confirm" ? "Waiting for approval" : "Waiting for input",
|
|
90
|
+
}
|
|
91
|
+
: undefined);
|
|
92
|
+
}
|
|
78
93
|
handleWorkflowActivity(frame) {
|
|
79
94
|
if (frame.kind === "snapshot") {
|
|
80
95
|
const sameSource = this.baselineEpoch === frame.cursor.epoch;
|
|
96
|
+
if (!sameSource)
|
|
97
|
+
this.cancellationAcknowledged = false;
|
|
81
98
|
if (frame.availability === "recovering" && sameSource) {
|
|
82
99
|
this.report();
|
|
83
100
|
return;
|
|
@@ -118,14 +135,21 @@ export class ProgramStatusReporter {
|
|
|
118
135
|
return;
|
|
119
136
|
}
|
|
120
137
|
this.failedRoots.delete(root.rootRunId);
|
|
138
|
+
if (isSettledCancellation(root) &&
|
|
139
|
+
(!previous || !isSettledCancellation(previous) || previous.endedStatus !== root.endedStatus)) {
|
|
140
|
+
this.cancellationAcknowledged = false;
|
|
141
|
+
}
|
|
121
142
|
const finished = previous !== undefined &&
|
|
122
143
|
previous.state !== "idle" &&
|
|
123
144
|
previous.reason !== "stopping" &&
|
|
124
145
|
root.state === "idle" &&
|
|
125
|
-
root.
|
|
146
|
+
root.endedStatus === "completed" &&
|
|
126
147
|
!root.needsAttention;
|
|
127
|
-
if (finished
|
|
128
|
-
this.
|
|
148
|
+
if (finished) {
|
|
149
|
+
this.cancellationAcknowledged = true;
|
|
150
|
+
if (this.restingStatus.state === "idle")
|
|
151
|
+
this.restingStatus = { state: "done" };
|
|
152
|
+
}
|
|
129
153
|
}
|
|
130
154
|
setBlocked(source, status) {
|
|
131
155
|
this.blocked.delete(source);
|
|
@@ -140,6 +164,10 @@ export class ProgramStatusReporter {
|
|
|
140
164
|
this.restingStatus = { state: "idle" };
|
|
141
165
|
this.report();
|
|
142
166
|
}
|
|
167
|
+
resend() {
|
|
168
|
+
this.lastReport = undefined;
|
|
169
|
+
this.report();
|
|
170
|
+
}
|
|
143
171
|
report() {
|
|
144
172
|
const status = { ...this.currentStatus(), app: APP_NAME };
|
|
145
173
|
const key = JSON.stringify(status);
|
|
@@ -161,6 +189,12 @@ export class ProgramStatusReporter {
|
|
|
161
189
|
if (!this.runActive && !workflowWorking && this.failedRoots.size > 0) {
|
|
162
190
|
return { state: "error", message: "Workflow failed" };
|
|
163
191
|
}
|
|
192
|
+
if (!this.runActive &&
|
|
193
|
+
!workflowWorking &&
|
|
194
|
+
[...this.roots.values()].some((root) => root.state === "idle" &&
|
|
195
|
+
(root.reason === "paused" || (!this.cancellationAcknowledged && isSettledCancellation(root))))) {
|
|
196
|
+
return { state: "idle" };
|
|
197
|
+
}
|
|
164
198
|
const status = this.runActive || workflowWorking ? { state: "working" } : this.restingStatus;
|
|
165
199
|
if (status.state === "working" || status.state === "done")
|
|
166
200
|
return { ...status, message: this.getSessionName() };
|
|
@@ -177,10 +211,15 @@ export class ProgramStatusReporter {
|
|
|
177
211
|
return undefined;
|
|
178
212
|
// A root that is still working cannot say whether its wait is a prompt or a manual decision.
|
|
179
213
|
const needsDecision = waiting.every((root) => root.reason === "manual_intervention");
|
|
214
|
+
const needsApproval = !needsDecision && waiting.some((root) => root.blockedPromptKind === "confirm");
|
|
180
215
|
return {
|
|
181
216
|
state: "blocked",
|
|
182
|
-
kind: "question",
|
|
183
|
-
message: needsDecision
|
|
217
|
+
kind: needsApproval ? "permission" : "question",
|
|
218
|
+
message: needsDecision
|
|
219
|
+
? "Workflow needs attention"
|
|
220
|
+
: needsApproval
|
|
221
|
+
? "Workflow needs approval"
|
|
222
|
+
: "Workflow waiting for input",
|
|
184
223
|
};
|
|
185
224
|
}
|
|
186
225
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program-status-reporter.js","sourceRoot":"","sources":["../../../src/modes/interactive/program-status-reporter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAO3C,SAAS,SAAS,CAAC,IAAwB;IAC1C,OAAO,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC;AACtD,CAAC;AAED,6GAA6G;AAC7G,SAAS,gBAAgB,CAAC,IAA0B;IACnD,OAAO,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,oBAAoB,KAAK,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC;AACxF,CAAC;AAED,MAAM,OAAO,qBAAqB;IACzB,SAAS,GAAG,KAAK,CAAC;IAClB,UAAU,GAAG,KAAK,CAAC;IACnB,SAAS,GAAkB,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC7C,aAAa,GAAkB,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IACxC,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IACpD,UAAU,CAAqB;IACtB,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAC;IACjE,sFAAsF;IACrE,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;IACjD,qHAAqH;IAC7G,aAAa,CAAqB;IAEzB,WAAW,CAAiB;IAC5B,cAAc,CAA2B;IAE1D,YAAY,WAA2B,EAAE,cAAwC;QAChF,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,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,CAAC,EAAE,CAAC;YACtE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC;QACvD,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;QACtG,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,MAAM;YAAE,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QAChH,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;OAIG;IACK,qBAAqB;QAC5B,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC9C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,oBAAoB,GAAG,CAAC,CACnE,CAAC;QACF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC3C,6FAA6F;QAC7F,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,qBAAqB,CAAC,CAAC;QACrF,OAAO;YACN,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,4BAA4B;SAClF,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { ProgramStatus, Terminal } from \"@earendil-works/pi-tui\";\nimport { APP_NAME } from \"../../config.js\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.js\";\nimport type { WorkflowActivityFrame, WorkflowRootActivity } from \"../../core/extensions/workflow-events.js\";\nimport type { JsonAgentSessionEvent } from \"../json-event.ts\";\n\nexport type BlockedStatus = { kind: NonNullable<ProgramStatus[\"kind\"]>; message: string };\n\nfunction firstLine(text: string | undefined): string {\n\treturn text?.split(/\\r?\\n/, 1)[0]?.trim() || \"Error\";\n}\n\n/** A root whose run ended failed (or blocked) and awaits inspection; no execution or open prompt remains. */\nfunction isSettledFailure(root: WorkflowRootActivity): boolean {\n\treturn root.state === \"idle\" && root.actionableBlockCount === 0 && root.needsAttention;\n}\n\nexport class ProgramStatusReporter {\n\tprivate runActive = false;\n\tprivate compacting = false;\n\tprivate runResult: ProgramStatus = { state: \"done\" };\n\tprivate restingStatus: ProgramStatus = { state: \"idle\" };\n\tprivate readonly blocked = new Map<string, BlockedStatus>();\n\tprivate lastReport: string | undefined;\n\tprivate readonly roots = new Map<string, WorkflowRootActivity>();\n\t/** Roots that failed while this session watched; held until the user's next input. */\n\tprivate readonly failedRoots = new Set<string>();\n\t/** Epoch of the source whose ready snapshot is the baseline; frames before it describe history, not new outcomes. */\n\tprivate baselineEpoch: string | undefined;\n\n\tprivate readonly getTerminal: () => Terminal;\n\tprivate readonly getSessionName: () => string | undefined;\n\n\tconstructor(getTerminal: () => Terminal, getSessionName: () => string | undefined) {\n\t\tthis.getTerminal = getTerminal;\n\t\tthis.getSessionName = getSessionName;\n\t}\n\n\thandleEvent(event: AgentSessionEvent | JsonAgentSessionEvent): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"agent_start\":\n\t\t\t\tthis.runActive = true;\n\t\t\t\tthis.runResult = { state: \"done\" };\n\t\t\t\tbreak;\n\t\t\tcase \"message_start\":\n\t\t\t\t// The user's next message answers a held workflow failure; lifecycle notices are custom messages.\n\t\t\t\tif (event.message.role !== \"user\" || this.failedRoots.size === 0) return;\n\t\t\t\tthis.failedRoots.clear();\n\t\t\t\tbreak;\n\t\t\tcase \"message_end\":\n\t\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\t\tthis.runResult =\n\t\t\t\t\tevent.message.stopReason === \"error\"\n\t\t\t\t\t\t? { state: \"error\", message: firstLine(event.message.errorMessage) }\n\t\t\t\t\t\t: { state: \"done\" };\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tthis.compacting = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.compacting = false;\n\t\t\t\tif (this.runActive) {\n\t\t\t\t\tif (event.aborted) this.runResult = { state: \"idle\" };\n\t\t\t\t\telse if (event.errorMessage) this.runResult = { state: \"error\", message: firstLine(event.errorMessage) };\n\t\t\t\t} else if (event.aborted) {\n\t\t\t\t\tthis.restingStatus = { state: \"idle\" };\n\t\t\t\t} else if (event.reason === \"manual\") {\n\t\t\t\t\tthis.restingStatus = event.errorMessage\n\t\t\t\t\t\t? { state: \"error\", message: firstLine(event.errorMessage) }\n\t\t\t\t\t\t: { state: \"done\" };\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"agent_settled\":\n\t\t\t\tthis.runActive = false;\n\t\t\t\tthis.restingStatus = event.aborted ? { state: \"idle\" } : this.runResult;\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tthis.report();\n\t}\n\n\thandleWorkflowActivity(frame: WorkflowActivityFrame): void {\n\t\tif (frame.kind === \"snapshot\") {\n\t\t\tconst sameSource = this.baselineEpoch === frame.cursor.epoch;\n\t\t\tif (frame.availability === \"recovering\" && sameSource) {\n\t\t\t\tthis.report();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst watched = sameSource ? new Map(this.roots) : new Map<string, WorkflowRootActivity>();\n\t\t\tthis.roots.clear();\n\t\t\tthis.baselineEpoch = frame.availability === \"ready\" ? frame.cursor.epoch : undefined;\n\t\t\tif (frame.availability === \"ready\") {\n\t\t\t\tfor (const root of frame.roots) {\n\t\t\t\t\tthis.roots.set(root.rootRunId, root);\n\t\t\t\t\tconst previous = watched.get(root.rootRunId);\n\t\t\t\t\tif (previous) this.recordOutcome(previous, root);\n\t\t\t\t}\n\t\t\t\tfor (const id of this.failedRoots) {\n\t\t\t\t\tconst root = this.roots.get(id);\n\t\t\t\t\tif (!root || !isSettledFailure(root)) this.failedRoots.delete(id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (frame.kind === \"changed\") {\n\t\t\tconst previous = this.roots.get(frame.root.rootRunId);\n\t\t\tthis.roots.set(frame.root.rootRunId, frame.root);\n\t\t\tif (this.baselineEpoch === frame.cursor.epoch) this.recordOutcome(previous, frame.root);\n\t\t} else {\n\t\t\tthis.roots.delete(frame.rootRunId);\n\t\t\tthis.failedRoots.delete(frame.rootRunId);\n\t\t}\n\t\tthis.report();\n\t}\n\n\tprivate recordOutcome(previous: WorkflowRootActivity | undefined, root: WorkflowRootActivity): void {\n\t\tif (isSettledFailure(root)) {\n\t\t\tif (!previous || !isSettledFailure(previous)) this.failedRoots.add(root.rootRunId);\n\t\t\treturn;\n\t\t}\n\t\tthis.failedRoots.delete(root.rootRunId);\n\t\tconst finished =\n\t\t\tprevious !== undefined &&\n\t\t\tprevious.state !== \"idle\" &&\n\t\t\tprevious.reason !== \"stopping\" &&\n\t\t\troot.state === \"idle\" &&\n\t\t\troot.reason !== \"paused\" &&\n\t\t\t!root.needsAttention;\n\t\tif (finished && this.restingStatus.state === \"idle\") this.restingStatus = { state: \"done\" };\n\t}\n\n\tsetBlocked(source: string, status: BlockedStatus | undefined): void {\n\t\tthis.blocked.delete(source);\n\t\tif (status) this.blocked.set(source, status);\n\t\tthis.report();\n\t}\n\n\treset(): void {\n\t\tthis.runActive = false;\n\t\tthis.compacting = false;\n\t\tthis.runResult = { state: \"done\" };\n\t\tthis.restingStatus = { state: \"idle\" };\n\t\tthis.report();\n\t}\n\n\treport(): void {\n\t\tconst status: ProgramStatus = { ...this.currentStatus(), app: APP_NAME };\n\t\tconst key = JSON.stringify(status);\n\t\tif (key === this.lastReport) return;\n\t\tthis.lastReport = key;\n\t\tthis.getTerminal().setProgramStatus(status);\n\t}\n\n\tprivate currentStatus(): ProgramStatus {\n\t\tconst blocked = [...this.blocked.values()].at(-1);\n\t\tif (blocked) return { state: \"blocked\", ...blocked };\n\t\tconst workflowBlocked = this.workflowBlockedStatus();\n\t\tif (workflowBlocked) return workflowBlocked;\n\t\tif (this.compacting) return { state: \"working\", message: \"Compacting context\" };\n\t\tconst workflowWorking = [...this.roots.values()].some((root) => root.state === \"working\");\n\t\tif (!this.runActive && !workflowWorking && this.failedRoots.size > 0) {\n\t\t\treturn { state: \"error\", message: \"Workflow failed\" };\n\t\t}\n\t\tconst status = this.runActive || workflowWorking ? { state: \"working\" as const } : this.restingStatus;\n\t\tif (status.state === \"working\" || status.state === \"done\") return { ...status, message: this.getSessionName() };\n\t\treturn status;\n\t}\n\n\t/**\n\t * A root waits for the user when it is blocked, or when a wait is open beside executing work: the\n\t * projection reports such a root as `working`. Fixed text only: prompts raised by workflows never\n\t * reach the terminal.\n\t */\n\tprivate workflowBlockedStatus(): ProgramStatus | undefined {\n\t\tconst waiting = [...this.roots.values()].filter(\n\t\t\t(root) => root.state === \"blocked\" || root.actionableBlockCount > 0,\n\t\t);\n\t\tif (waiting.length === 0) return undefined;\n\t\t// A root that is still working cannot say whether its wait is a prompt or a manual decision.\n\t\tconst needsDecision = waiting.every((root) => root.reason === \"manual_intervention\");\n\t\treturn {\n\t\t\tstate: \"blocked\",\n\t\t\tkind: \"question\",\n\t\t\tmessage: needsDecision ? \"Workflow needs attention\" : \"Workflow waiting for input\",\n\t\t};\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"program-status-reporter.js","sourceRoot":"","sources":["../../../src/modes/interactive/program-status-reporter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAQ3C,SAAS,SAAS,CAAC,IAAwB;IAC1C,OAAO,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,C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,CAAC,IAAI,CAAC,aAAa,CAAC;QACtG,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,MAAM;YAAE,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QAChH,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;OAIG;IACK,qBAAqB;QAC5B,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAC9C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,oBAAoB,GAAG,CAAC,CACnE,CAAC;QACF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAC3C,6FAA6F;QAC7F,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,qBAAqB,CAAC,CAAC;QACrF,MAAM,aAAa,GAAG,CAAC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,KAAK,SAAS,CAAC,CAAC;QACrG,OAAO;YACN,KAAK,EAAE,SAAS;YAChB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;YAC/C,OAAO,EAAE,aAAa;gBACrB,CAAC,CAAC,0BAA0B;gBAC5B,CAAC,CAAC,aAAa;oBACd,CAAC,CAAC,yBAAyB;oBAC3B,CAAC,CAAC,4BAA4B;SAChC,CAAC;IACH,CAAC;CACD","sourcesContent":["import type { ProgramStatus, Terminal } from \"@earendil-works/pi-tui\";\nimport { APP_NAME } from \"../../config.js\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.js\";\nimport type { UIPromptEndEvent, UIPromptStartEvent } from \"../../core/extensions/agent-events.ts\";\nimport type { WorkflowActivityFrame, WorkflowRootActivity } from \"../../core/extensions/workflow-events.js\";\nimport type { JsonAgentSessionEvent } from \"../json-event.ts\";\n\nexport type BlockedStatus = { kind: NonNullable<ProgramStatus[\"kind\"]>; message: string };\n\nfunction firstLine(text: string | undefined): string {\n\treturn text?.split(/\\r?\\n/, 1)[0]?.trim() || \"Error\";\n}\n\n/** A root whose run ended failed (or blocked) and awaits inspection; no execution or open prompt remains. */\nfunction isSettledFailure(root: WorkflowRootActivity): boolean {\n\treturn root.state === \"idle\" && root.actionableBlockCount === 0 && root.needsAttention;\n}\n\nfunction isSettledCancellation(root: WorkflowRootActivity): boolean {\n\treturn root.state === \"idle\" && (root.endedStatus === \"cancelled\" || root.endedStatus === \"killed\");\n}\n\nexport class ProgramStatusReporter {\n\tprivate runActive = false;\n\tprivate compacting = false;\n\tprivate runResult: ProgramStatus = { state: \"done\" };\n\tprivate restingStatus: ProgramStatus = { state: \"idle\" };\n\tprivate readonly blocked = new Map<string, BlockedStatus>();\n\tprivate lastReport: string | undefined;\n\tprivate readonly roots = new Map<string, WorkflowRootActivity>();\n\t/** Roots that failed while this session watched; held until the user's next input. */\n\tprivate readonly failedRoots = new Set<string>();\n\t/** Epoch of the source whose ready snapshot is the baseline; frames before it describe history, not new outcomes. */\n\tprivate baselineEpoch: string | undefined;\n\tprivate cancellationAcknowledged = false;\n\n\tprivate readonly getTerminal: () => Terminal;\n\tprivate readonly getSessionName: () => string | undefined;\n\n\tconstructor(getTerminal: () => Terminal, getSessionName: () => string | undefined) {\n\t\tthis.getTerminal = getTerminal;\n\t\tthis.getSessionName = getSessionName;\n\t}\n\n\thandleEvent(event: AgentSessionEvent | JsonAgentSessionEvent): void {\n\t\tswitch (event.type) {\n\t\t\tcase \"agent_start\":\n\t\t\t\tthis.runActive = true;\n\t\t\t\tthis.runResult = { state: \"done\" };\n\t\t\t\tbreak;\n\t\t\tcase \"message_start\":\n\t\t\t\t// The user's next message answers a held workflow failure; lifecycle notices are custom messages.\n\t\t\t\tif (event.message.role !== \"user\") return;\n\t\t\t\tthis.failedRoots.clear();\n\t\t\t\tthis.cancellationAcknowledged = true;\n\t\t\t\tbreak;\n\t\t\tcase \"message_end\":\n\t\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\t\tthis.runResult =\n\t\t\t\t\tevent.message.stopReason === \"error\"\n\t\t\t\t\t\t? { state: \"error\", message: firstLine(event.message.errorMessage) }\n\t\t\t\t\t\t: { state: \"done\" };\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_start\":\n\t\t\t\tthis.compacting = true;\n\t\t\t\tbreak;\n\t\t\tcase \"compaction_end\":\n\t\t\t\tthis.compacting = false;\n\t\t\t\tif (this.runActive) {\n\t\t\t\t\tif (event.aborted) this.runResult = { state: \"idle\" };\n\t\t\t\t\telse if (event.errorMessage) this.runResult = { state: \"error\", message: firstLine(event.errorMessage) };\n\t\t\t\t} else if (event.aborted) {\n\t\t\t\t\tthis.restingStatus = { state: \"idle\" };\n\t\t\t\t} else if (event.reason === \"manual\") {\n\t\t\t\t\tthis.restingStatus = event.errorMessage\n\t\t\t\t\t\t? { state: \"error\", message: firstLine(event.errorMessage) }\n\t\t\t\t\t\t: { state: \"done\" };\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"agent_settled\":\n\t\t\t\tthis.runActive = false;\n\t\t\t\tthis.restingStatus = event.aborted ? { state: \"idle\" } : this.runResult;\n\t\t\t\tbreak;\n\t\t\tcase \"session_info_changed\":\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t\tthis.report();\n\t}\n\n\thandleUIPrompt(event: UIPromptStartEvent | UIPromptEndEvent | undefined): void {\n\t\tif (event?.reason === \"project_trust\") return;\n\t\tthis.setBlocked(\n\t\t\t\"ui-prompt\",\n\t\t\tevent?.type === \"ui_prompt_start\"\n\t\t\t\t? {\n\t\t\t\t\t\tkind: event.kind === \"confirm\" ? \"permission\" : \"question\",\n\t\t\t\t\t\tmessage: event.kind === \"confirm\" ? \"Waiting for approval\" : \"Waiting for input\",\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\t);\n\t}\n\n\thandleWorkflowActivity(frame: WorkflowActivityFrame): void {\n\t\tif (frame.kind === \"snapshot\") {\n\t\t\tconst sameSource = this.baselineEpoch === frame.cursor.epoch;\n\t\t\tif (!sameSource) this.cancellationAcknowledged = false;\n\t\t\tif (frame.availability === \"recovering\" && sameSource) {\n\t\t\t\tthis.report();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst watched = sameSource ? new Map(this.roots) : new Map<string, WorkflowRootActivity>();\n\t\t\tthis.roots.clear();\n\t\t\tthis.baselineEpoch = frame.availability === \"ready\" ? frame.cursor.epoch : undefined;\n\t\t\tif (frame.availability === \"ready\") {\n\t\t\t\tfor (const root of frame.roots) {\n\t\t\t\t\tthis.roots.set(root.rootRunId, root);\n\t\t\t\t\tconst previous = watched.get(root.rootRunId);\n\t\t\t\t\tif (previous) this.recordOutcome(previous, root);\n\t\t\t\t}\n\t\t\t\tfor (const id of this.failedRoots) {\n\t\t\t\t\tconst root = this.roots.get(id);\n\t\t\t\t\tif (!root || !isSettledFailure(root)) this.failedRoots.delete(id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (frame.kind === \"changed\") {\n\t\t\tconst previous = this.roots.get(frame.root.rootRunId);\n\t\t\tthis.roots.set(frame.root.rootRunId, frame.root);\n\t\t\tif (this.baselineEpoch === frame.cursor.epoch) this.recordOutcome(previous, frame.root);\n\t\t} else {\n\t\t\tthis.roots.delete(frame.rootRunId);\n\t\t\tthis.failedRoots.delete(frame.rootRunId);\n\t\t}\n\t\tthis.report();\n\t}\n\n\tprivate recordOutcome(previous: WorkflowRootActivity | undefined, root: WorkflowRootActivity): void {\n\t\tif (isSettledFailure(root)) {\n\t\t\tif (!previous || !isSettledFailure(previous)) this.failedRoots.add(root.rootRunId);\n\t\t\treturn;\n\t\t}\n\t\tthis.failedRoots.delete(root.rootRunId);\n\t\tif (\n\t\t\tisSettledCancellation(root) &&\n\t\t\t(!previous || !isSettledCancellation(previous) || previous.endedStatus !== root.endedStatus)\n\t\t) {\n\t\t\tthis.cancellationAcknowledged = false;\n\t\t}\n\t\tconst finished =\n\t\t\tprevious !== undefined &&\n\t\t\tprevious.state !== \"idle\" &&\n\t\t\tprevious.reason !== \"stopping\" &&\n\t\t\troot.state === \"idle\" &&\n\t\t\troot.endedStatus === \"completed\" &&\n\t\t\t!root.needsAttention;\n\t\tif (finished) {\n\t\t\tthis.cancellationAcknowledged = true;\n\t\t\tif (this.restingStatus.state === \"idle\") this.restingStatus = { state: \"done\" };\n\t\t}\n\t}\n\n\tsetBlocked(source: string, status: BlockedStatus | undefined): void {\n\t\tthis.blocked.delete(source);\n\t\tif (status) this.blocked.set(source, status);\n\t\tthis.report();\n\t}\n\n\treset(): void {\n\t\tthis.runActive = false;\n\t\tthis.compacting = false;\n\t\tthis.runResult = { state: \"done\" };\n\t\tthis.restingStatus = { state: \"idle\" };\n\t\tthis.report();\n\t}\n\n\tresend(): void {\n\t\tthis.lastReport = undefined;\n\t\tthis.report();\n\t}\n\n\treport(): void {\n\t\tconst status: ProgramStatus = { ...this.currentStatus(), app: APP_NAME };\n\t\tconst key = JSON.stringify(status);\n\t\tif (key === this.lastReport) return;\n\t\tthis.lastReport = key;\n\t\tthis.getTerminal().setProgramStatus(status);\n\t}\n\n\tprivate currentStatus(): ProgramStatus {\n\t\tconst blocked = [...this.blocked.values()].at(-1);\n\t\tif (blocked) return { state: \"blocked\", ...blocked };\n\t\tconst workflowBlocked = this.workflowBlockedStatus();\n\t\tif (workflowBlocked) return workflowBlocked;\n\t\tif (this.compacting) return { state: \"working\", message: \"Compacting context\" };\n\t\tconst workflowWorking = [...this.roots.values()].some((root) => root.state === \"working\");\n\t\tif (!this.runActive && !workflowWorking && this.failedRoots.size > 0) {\n\t\t\treturn { state: \"error\", message: \"Workflow failed\" };\n\t\t}\n\t\tif (\n\t\t\t!this.runActive &&\n\t\t\t!workflowWorking &&\n\t\t\t[...this.roots.values()].some(\n\t\t\t\t(root) =>\n\t\t\t\t\troot.state === \"idle\" &&\n\t\t\t\t\t(root.reason === \"paused\" || (!this.cancellationAcknowledged && isSettledCancellation(root))),\n\t\t\t)\n\t\t) {\n\t\t\treturn { state: \"idle\" };\n\t\t}\n\t\tconst status = this.runActive || workflowWorking ? { state: \"working\" as const } : this.restingStatus;\n\t\tif (status.state === \"working\" || status.state === \"done\") return { ...status, message: this.getSessionName() };\n\t\treturn status;\n\t}\n\n\t/**\n\t * A root waits for the user when it is blocked, or when a wait is open beside executing work: the\n\t * projection reports such a root as `working`. Fixed text only: prompts raised by workflows never\n\t * reach the terminal.\n\t */\n\tprivate workflowBlockedStatus(): ProgramStatus | undefined {\n\t\tconst waiting = [...this.roots.values()].filter(\n\t\t\t(root) => root.state === \"blocked\" || root.actionableBlockCount > 0,\n\t\t);\n\t\tif (waiting.length === 0) return undefined;\n\t\t// A root that is still working cannot say whether its wait is a prompt or a manual decision.\n\t\tconst needsDecision = waiting.every((root) => root.reason === \"manual_intervention\");\n\t\tconst needsApproval = !needsDecision && waiting.some((root) => root.blockedPromptKind === \"confirm\");\n\t\treturn {\n\t\t\tstate: \"blocked\",\n\t\t\tkind: needsApproval ? \"permission\" : \"question\",\n\t\t\tmessage: needsDecision\n\t\t\t\t? \"Workflow needs attention\"\n\t\t\t\t: needsApproval\n\t\t\t\t\t? \"Workflow needs approval\"\n\t\t\t\t\t: \"Workflow waiting for input\",\n\t\t};\n\t}\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentSession } from "../../core/agent-session.js";
|
|
2
2
|
import type { AgentSessionRuntime } from "../../core/agent-session-runtime.ts";
|
|
3
3
|
import type { ResourceOverlap } from "../../core/diagnostics.ts";
|
|
4
|
+
import type { UIPromptEndEvent, UIPromptStartEvent } from "../../core/extensions/agent-events.ts";
|
|
4
5
|
import type { ExtensionUIContext } from "../../core/extensions/index.js";
|
|
5
6
|
import type { WorkflowActivityFrame } from "../../core/extensions/workflow-events.js";
|
|
6
7
|
import type { KeybindingsManager } from "../../core/keybindings.ts";
|
|
@@ -13,7 +14,7 @@ interface EngineMessageSource {
|
|
|
13
14
|
onKeybindingState?(listener: (state: EngineKeybindingState) => void): () => void;
|
|
14
15
|
}
|
|
15
16
|
export declare function attachInteractiveEngineKeybindingSync(runtime: EngineMessageSource, keybindings: KeybindingsManager, onState?: (state: EngineKeybindingState) => void): () => void;
|
|
16
|
-
export declare function attachInteractiveEngineHost(runtime: AgentSessionRuntime, ui: ExtensionUIContext, onDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void, tuiRendererLifecycle: TuiRendererLifecycle, setShortcutHandler?: (handler: (data: string) => boolean) => undefined | (() => void), keybindings?: KeybindingsManager, onWorkflowActivity?: (frame: WorkflowActivityFrame) => void): () => void;
|
|
17
|
+
export declare function attachInteractiveEngineHost(runtime: AgentSessionRuntime, ui: ExtensionUIContext, onDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void, tuiRendererLifecycle: TuiRendererLifecycle, setShortcutHandler?: (handler: (data: string) => boolean) => undefined | (() => void), keybindings?: KeybindingsManager, onWorkflowActivity?: (frame: WorkflowActivityFrame) => void, onUIPrompt?: (event: UIPromptStartEvent | UIPromptEndEvent | undefined) => void): () => void;
|
|
17
18
|
/**
|
|
18
19
|
* Observe workflow activity of a session whose extensions run in this process. An isolated host
|
|
19
20
|
* receives it from its engine child instead (see `attachInteractiveEngineHost`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-ui-bridge.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/extension-ui-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,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ACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAIhF;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,eAAe,EAAE,CAE3G;AAED,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,eAAe,EAAE,CAE7G;AAED,wBAAgB,sCAAsC,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,oBAAoB,EAAE,CAEpH;AAED,wBAAgB,4CAA4C,CAC3D,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,CAAC,UAAU,EAAE,SAAS,oBAAoB,EAAE,KAAK,IAAI,GAC7D,MAAM,IAAI,CAEZ;AAED,oEAAoE;AACpE,wBAAgB,4CAA4C,CAC3D,OAAO,EAAE,mBAAmB,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,GACpB,OAAO,CAAC,mBAAmB,EAAE,GAAG,IAAI,CAAC,CAIvC;AAED,kFAAkF;AAClF,wBAAgB,wCAAwC,CACvD,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,KAAK,IAAI,GACtD,MAAM,IAAI,CAEZ;AAED,mGAAmG;AACnG,wBAAgB,sCAAsC,CAAC,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAErH"}
|
|
@@ -17,10 +17,15 @@ export function attachInteractiveEngineKeybindingSync(runtime, keybindings, onSt
|
|
|
17
17
|
applyState(message.state);
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
export function attachInteractiveEngineHost(runtime, ui, onDiagnostic, tuiRendererLifecycle, setShortcutHandler, keybindings, onWorkflowActivity) {
|
|
20
|
+
export function attachInteractiveEngineHost(runtime, ui, onDiagnostic, tuiRendererLifecycle, setShortcutHandler, keybindings, onWorkflowActivity, onUIPrompt) {
|
|
21
21
|
if (!(runtime instanceof IsolatedInteractiveRuntime))
|
|
22
22
|
return () => { };
|
|
23
23
|
const disposeDiagnostic = runtime.onDiagnostic(onDiagnostic);
|
|
24
|
+
const disposeUIPrompts = runtime.onEngineMessage((message) => {
|
|
25
|
+
if (message.type === "engine_ui_prompt")
|
|
26
|
+
onUIPrompt?.(message.event);
|
|
27
|
+
});
|
|
28
|
+
const disposePromptGeneration = runtime.onGenerationEnded(() => onUIPrompt?.(undefined));
|
|
24
29
|
const disposeWorkflowActivity = onWorkflowActivity
|
|
25
30
|
? observeEngineWorkflowActivity(runtime, onWorkflowActivity)
|
|
26
31
|
: () => { };
|
|
@@ -68,6 +73,9 @@ export function attachInteractiveEngineHost(runtime, ui, onDiagnostic, tuiRender
|
|
|
68
73
|
disposeShortcutHandler?.();
|
|
69
74
|
disposeKeybindings();
|
|
70
75
|
disposeWorkflowActivity();
|
|
76
|
+
disposeUIPrompts();
|
|
77
|
+
disposePromptGeneration();
|
|
78
|
+
onUIPrompt?.(undefined);
|
|
71
79
|
disposeOwnership();
|
|
72
80
|
remoteComponents.dispose();
|
|
73
81
|
sessionPicker.dispose();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-ui-bridge.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/extension-ui-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAShE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,yBAAyB,EAA6B,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAOvE,MAAM,UAAU,qC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c,CAAC;QAClE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,wCAAwC,CACvD,OAA4B,EAC5B,QAAwD;IAExD,OAAO,OAAO,YAAY,0BAA0B,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAC7G,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,sCAAsC,CAAC,OAA4B,EAAE,QAAoB;IACxG,OAAO,OAAO,YAAY,0BAA0B,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAC3G,CAAC","sourcesContent":["import { type KeyId, matchesKey } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\nimport type { ResourceOverlap } from \"../../core/diagnostics.ts\";\nimport type { ExtensionUIContext } from \"../../core/extensions/index.js\";\nimport type { WorkflowActivityFrame } from \"../../core/extensions/workflow-events.js\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport type { RpcAutocompleteItem, RpcResourceExtension, RpcSlashCommand } from \"../rpc/rpc-types.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"./activity-watchdog.ts\";\nimport { EngineDialogHostController } from \"./engine-dialog-host.ts\";\nimport { InputFormHostController } from \"./input-form-host.ts\";\nimport { IsolatedInteractiveRuntime } from \"./isolated-runtime.js\";\nimport type { EngineExtensionShortcut, EngineKeybindingState, InteractiveEngineMessage } from \"./protocol.ts\";\nimport { RemoteComponentController, type TuiRendererLifecycle } from \"./remote-component.ts\";\nimport { registerRemoteProxyOwnership } from \"./remote-input-ownership.ts\";\nimport { SessionPickerHostController } from \"./session-picker-host.ts\";\n\ninterface EngineMessageSource {\n\tonEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void;\n\tonKeybindingState?(listener: (state: EngineKeybindingState) => void): () => void;\n}\n\nexport function attachInteractiveEngineKeybindingSync(\n\truntime: EngineMessageSource,\n\tkeybindings: KeybindingsManager,\n\tonState?: (state: EngineKeybindingState) => void,\n): () => void {\n\tconst applyState = (state: EngineKeybindingState): void => {\n\t\tkeybindings.setUserBindings(state.userBindings);\n\t\tonState?.(state);\n\t};\n\tif (runtime.onKeybindingState) return runtime.onKeybindingState(applyState);\n\treturn runtime.onEngineMessage((message) => {\n\t\tif (message.type === \"engine_keybindings_reloaded\") applyState(message.state);\n\t});\n}\n\nexport function attachInteractiveEngineHost(\n\truntime: AgentSessionRuntime,\n\tui: ExtensionUIContext,\n\tonDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void,\n\ttuiRendererLifecycle: TuiRendererLifecycle,\n\tsetShortcutHandler?: (handler: (data: string) => boolean) => undefined | (() => void),\n\tkeybindings?: KeybindingsManager,\n\tonWorkflowActivity?: (frame: WorkflowActivityFrame) => void,\n): () => void {\n\tif (!(runtime instanceof IsolatedInteractiveRuntime)) return () => {};\n\tconst disposeDiagnostic = runtime.onDiagnostic(onDiagnostic);\n\tconst disposeWorkflowActivity = onWorkflowActivity\n\t\t? observeEngineWorkflowActivity(runtime, onWorkflowActivity)\n\t\t: () => {};\n\t// Generation-owned: RPC dialogs mount real host components and must not\n\t// outlive, or answer through, a replacement engine child.\n\tconst dialogs = new EngineDialogHostController(runtime, ui);\n\tlet shortcuts: EngineExtensionShortcut[] = [];\n\tconst dispatchShortcut = (data: string): boolean => {\n\t\tconst shortcut = shortcuts.find(\n\t\t\t({ key, editorKeys }) =>\n\t\t\t\tmatchesKey(data, key as KeyId) && !editorKeys?.some((editorKey) => matchesKey(data, editorKey)),\n\t\t);\n\t\tif (!shortcut) return false;\n\t\tvoid runtime\n\t\t\t.invokeRemoteShortcut(shortcut.key)\n\t\t\t.catch((error: Error) =>\n\t\t\t\tonDiagnostic({ activity: undefined, elapsedMs: 0, level: \"unresponsive\", message: error.message }),\n\t\t\t);\n\t\treturn true;\n\t};\n\tlet disposeShortcutHandler: (() => void) | undefined;\n\tconst installShortcutHandler = (): void => {\n\t\tdisposeShortcutHandler?.();\n\t\tconst dispose = setShortcutHandler?.(dispatchShortcut);\n\t\tdisposeShortcutHandler = typeof dispose === \"function\" ? dispose : undefined;\n\t};\n\tconst applyState = (state: EngineKeybindingState): void => {\n\t\tshortcuts = [...state.shortcuts];\n\t\tinstallShortcutHandler();\n\t};\n\tinstallShortcutHandler();\n\tconst disposeKeybindings = keybindings\n\t\t? attachInteractiveEngineKeybindingSync(runtime, keybindings, applyState)\n\t\t: runtime.onEngineMessage((message) => {\n\t\t\t\tif (message.type === \"engine_keybindings_reloaded\") applyState(message.state);\n\t\t\t});\n\tconst remoteComponents = new RemoteComponentController(runtime, ui, tuiRendererLifecycle);\n\t// Ctrl+C must reach the host while a remote proxy owns input, so publish the\n\t// only component that can answer that question exactly.\n\tconst disposeOwnership = registerRemoteProxyOwnership(runtime, remoteComponents);\n\tconst sessionPicker = new SessionPickerHostController(runtime, ui);\n\tconst inputForm = new InputFormHostController(runtime, ui);\n\tlet disposed = false;\n\treturn () => {\n\t\tif (disposed) return;\n\t\tdisposed = true;\n\t\tdisposeShortcutHandler?.();\n\t\tdisposeKeybindings();\n\t\tdisposeWorkflowActivity();\n\t\tdisposeOwnership();\n\t\tremoteComponents.dispose();\n\t\tsessionPicker.dispose();\n\t\tinputForm.dispose();\n\t\tdialogs.dispose();\n\t\tdisposeDiagnostic();\n\t};\n}\n\nconst unavailableWorkflowActivity: WorkflowActivityFrame = {\n\tkind: \"snapshot\",\n\tcursor: { epoch: \"\", revision: 0 },\n\tavailability: \"unavailable\",\n};\n\n/** The engine child owns the workflow runs; a dead generation's runs are gone with it. */\nfunction observeEngineWorkflowActivity(\n\truntime: IsolatedInteractiveRuntime,\n\tobserver: (frame: WorkflowActivityFrame) => void,\n): () => void {\n\t// The runtime replays the engine's current snapshot: the engine published it at bind time, which can\n\t// be long before this observer attaches.\n\tconst disposeMessages = runtime.onWorkflowActivity(observer);\n\tconst disposeEnded = runtime.onGenerationEnded(() => observer(unavailableWorkflowActivity));\n\treturn () => {\n\t\tdisposeMessages();\n\t\tdisposeEnded();\n\t};\n}\n\n/**\n * Observe workflow activity of a session whose extensions run in this process. An isolated host\n * receives it from its engine child instead (see `attachInteractiveEngineHost`).\n */\nexport function observeLocalWorkflowActivity(\n\truntime: AgentSessionRuntime,\n\tsession: AgentSession,\n\tobserver: (frame: WorkflowActivityFrame) => void,\n): () => void {\n\tif (runtime instanceof IsolatedInteractiveRuntime) return () => {};\n\tconst subscription = session.workflows.observe(observer);\n\treturn () => subscription.dispose();\n}\n\n/** Route host-owned trust waits to the runner that actually owns the subscribers. */\nexport function withHostProjectTrustPrompt<T>(\n\truntime: AgentSessionRuntime,\n\tkind: \"select\" | \"confirm\" | \"input\",\n\ttitle: string,\n\trun: () => Promise<T>,\n): Promise<T> {\n\treturn runtime instanceof IsolatedInteractiveRuntime\n\t\t? runtime.withProjectTrustPrompt(kind, title, run)\n\t\t: runtime.session.extensionRunner.withProjectTrustPrompt(kind, title, run);\n}\n\nexport async function waitForInteractiveEngineBound(runtime: AgentSessionRuntime): Promise<void> {\n\tif (!(runtime instanceof IsolatedInteractiveRuntime)) return;\n\tawait runtime.waitUntilBound();\n\tawait runtime.initializeFromEngine();\n}\n\nexport async function waitForInteractiveEngineProjectTrust(runtime: AgentSessionRuntime): Promise<void> {\n\tif (!(runtime instanceof IsolatedInteractiveRuntime)) return;\n\tawait runtime.waitUntilProjectTrustSettled();\n}\n\nexport function interruptBlockedInteractiveEngine(runtime: AgentSessionRuntime): boolean {\n\treturn runtime instanceof IsolatedInteractiveRuntime && runtime.interruptBlockedCallback();\n}\n\n/**\n * True when the interactive engine still owes a cooperative abort or the\n * heartbeat watchdog has declared it unresponsive, i.e. when the explicit\n * Ctrl+C escape hatch promised by the watchdog copy applies.\n */\nexport function interactiveEngineNeedsExplicitTermination(runtime: AgentSessionRuntime): boolean {\n\treturn runtime instanceof IsolatedInteractiveRuntime && runtime.needsExplicitTermination();\n}\n\n/**\n * Explicitly terminate an unresponsive interactive engine and start recovery.\n * Only ever reached from a deliberate user action (Ctrl+C) — never from Escape.\n */\nexport function terminateInteractiveEngine(runtime: AgentSessionRuntime): boolean {\n\tif (!interactiveEngineNeedsExplicitTermination(runtime)) return false;\n\tvoid (runtime as IsolatedInteractiveRuntime).terminateAndRecover();\n\treturn true;\n}\n\n/**\n * Command catalog the engine child exposes to the isolated host. Returns an\n * empty list for non-isolated runtimes so callers can merge unconditionally.\n */\nexport function getInteractiveEngineRemoteCommands(runtime: AgentSessionRuntime): readonly RpcSlashCommand[] {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.getRemoteCommands() : [];\n}\n\nexport function getInteractiveEngineResourceOverlaps(runtime: AgentSessionRuntime): readonly ResourceOverlap[] {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.getResourceOverlaps() : [];\n}\n\nexport function getInteractiveEngineResourceExtensions(runtime: AgentSessionRuntime): readonly RpcResourceExtension[] {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.getResourceExtensions() : [];\n}\n\nexport function onInteractiveEngineResourceExtensionsChanged(\n\truntime: AgentSessionRuntime,\n\tlistener: (extensions: readonly RpcResourceExtension[]) => void,\n): () => void {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.onResourceExtensionsChanged(listener) : () => {};\n}\n\n/** Evaluate an engine-child command's live argument completions. */\nexport function getInteractiveEngineRemoteCommandCompletions(\n\truntime: AgentSessionRuntime,\n\tcommandName: string,\n\targumentPrefix: string,\n): Promise<RpcAutocompleteItem[] | null> {\n\treturn runtime instanceof IsolatedInteractiveRuntime\n\t\t? runtime.getRemoteCommandCompletions(commandName, argumentPrefix)\n\t\t: Promise.resolve(null);\n}\n\n/** Subscribe to engine-child command catalog changes. No-op when not isolated. */\nexport function onInteractiveEngineRemoteCommandsChanged(\n\truntime: AgentSessionRuntime,\n\tlistener: (commands: readonly RpcSlashCommand[]) => void,\n): () => void {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.onRemoteCommandsChanged(listener) : () => {};\n}\n\n/** Subscribe to fresh engine session stats, so the footer can repaint. No-op when not isolated. */\nexport function onInteractiveEngineSessionStatsChanged(runtime: AgentSessionRuntime, listener: () => void): () => void {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.onSessionStatsChanged(listener) : () => {};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"extension-ui-bridge.js","sourceRoot":"","sources":["../../../src/modes/interactive-engine/extension-ui-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAUhE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,yBAAyB,EAA6B,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAOvE,MAAM,UAAU,qCAAqC,CACpD,OAA4B,EAC5B,WAA+B,EAC/B,OAAgD;IAEhD,MAAM,UAAU,GAAG,CAAC,KAA4B,EAAQ,EAAE;QACzD,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAChD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC;IACF,IAAI,OAAO,CAAC,iBAAiB;QAAE,OAAO,OAAO,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAC5E,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE,EAAE;QAC1C,IAAI,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O,CAAC,2BAA2B,CAAC,WAAW,EAAE,cAAc,CAAC;QAClE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,wCAAwC,CACvD,OAA4B,EAC5B,QAAwD;IAExD,OAAO,OAAO,YAAY,0BAA0B,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAC7G,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,sCAAsC,CAAC,OAA4B,EAAE,QAAoB;IACxG,OAAO,OAAO,YAAY,0BAA0B,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAC3G,CAAC","sourcesContent":["import { type KeyId, matchesKey } from \"@earendil-works/pi-tui\";\nimport type { AgentSession } from \"../../core/agent-session.js\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\nimport type { ResourceOverlap } from \"../../core/diagnostics.ts\";\nimport type { UIPromptEndEvent, UIPromptStartEvent } from \"../../core/extensions/agent-events.ts\";\nimport type { ExtensionUIContext } from \"../../core/extensions/index.js\";\nimport type { WorkflowActivityFrame } from \"../../core/extensions/workflow-events.js\";\nimport type { KeybindingsManager } from \"../../core/keybindings.ts\";\nimport type { RpcAutocompleteItem, RpcResourceExtension, RpcSlashCommand } from \"../rpc/rpc-types.ts\";\nimport type { ActivityWatchdogDiagnostic } from \"./activity-watchdog.ts\";\nimport { EngineDialogHostController } from \"./engine-dialog-host.ts\";\nimport { InputFormHostController } from \"./input-form-host.ts\";\nimport { IsolatedInteractiveRuntime } from \"./isolated-runtime.js\";\nimport type { EngineExtensionShortcut, EngineKeybindingState, InteractiveEngineMessage } from \"./protocol.ts\";\nimport { RemoteComponentController, type TuiRendererLifecycle } from \"./remote-component.ts\";\nimport { registerRemoteProxyOwnership } from \"./remote-input-ownership.ts\";\nimport { SessionPickerHostController } from \"./session-picker-host.ts\";\n\ninterface EngineMessageSource {\n\tonEngineMessage(listener: (message: InteractiveEngineMessage) => void): () => void;\n\tonKeybindingState?(listener: (state: EngineKeybindingState) => void): () => void;\n}\n\nexport function attachInteractiveEngineKeybindingSync(\n\truntime: EngineMessageSource,\n\tkeybindings: KeybindingsManager,\n\tonState?: (state: EngineKeybindingState) => void,\n): () => void {\n\tconst applyState = (state: EngineKeybindingState): void => {\n\t\tkeybindings.setUserBindings(state.userBindings);\n\t\tonState?.(state);\n\t};\n\tif (runtime.onKeybindingState) return runtime.onKeybindingState(applyState);\n\treturn runtime.onEngineMessage((message) => {\n\t\tif (message.type === \"engine_keybindings_reloaded\") applyState(message.state);\n\t});\n}\n\nexport function attachInteractiveEngineHost(\n\truntime: AgentSessionRuntime,\n\tui: ExtensionUIContext,\n\tonDiagnostic: (diagnostic: ActivityWatchdogDiagnostic) => void,\n\ttuiRendererLifecycle: TuiRendererLifecycle,\n\tsetShortcutHandler?: (handler: (data: string) => boolean) => undefined | (() => void),\n\tkeybindings?: KeybindingsManager,\n\tonWorkflowActivity?: (frame: WorkflowActivityFrame) => void,\n\tonUIPrompt?: (event: UIPromptStartEvent | UIPromptEndEvent | undefined) => void,\n): () => void {\n\tif (!(runtime instanceof IsolatedInteractiveRuntime)) return () => {};\n\tconst disposeDiagnostic = runtime.onDiagnostic(onDiagnostic);\n\tconst disposeUIPrompts = runtime.onEngineMessage((message) => {\n\t\tif (message.type === \"engine_ui_prompt\") onUIPrompt?.(message.event);\n\t});\n\tconst disposePromptGeneration = runtime.onGenerationEnded(() => onUIPrompt?.(undefined));\n\tconst disposeWorkflowActivity = onWorkflowActivity\n\t\t? observeEngineWorkflowActivity(runtime, onWorkflowActivity)\n\t\t: () => {};\n\t// Generation-owned: RPC dialogs mount real host components and must not\n\t// outlive, or answer through, a replacement engine child.\n\tconst dialogs = new EngineDialogHostController(runtime, ui);\n\tlet shortcuts: EngineExtensionShortcut[] = [];\n\tconst dispatchShortcut = (data: string): boolean => {\n\t\tconst shortcut = shortcuts.find(\n\t\t\t({ key, editorKeys }) =>\n\t\t\t\tmatchesKey(data, key as KeyId) && !editorKeys?.some((editorKey) => matchesKey(data, editorKey)),\n\t\t);\n\t\tif (!shortcut) return false;\n\t\tvoid runtime\n\t\t\t.invokeRemoteShortcut(shortcut.key)\n\t\t\t.catch((error: Error) =>\n\t\t\t\tonDiagnostic({ activity: undefined, elapsedMs: 0, level: \"unresponsive\", message: error.message }),\n\t\t\t);\n\t\treturn true;\n\t};\n\tlet disposeShortcutHandler: (() => void) | undefined;\n\tconst installShortcutHandler = (): void => {\n\t\tdisposeShortcutHandler?.();\n\t\tconst dispose = setShortcutHandler?.(dispatchShortcut);\n\t\tdisposeShortcutHandler = typeof dispose === \"function\" ? dispose : undefined;\n\t};\n\tconst applyState = (state: EngineKeybindingState): void => {\n\t\tshortcuts = [...state.shortcuts];\n\t\tinstallShortcutHandler();\n\t};\n\tinstallShortcutHandler();\n\tconst disposeKeybindings = keybindings\n\t\t? attachInteractiveEngineKeybindingSync(runtime, keybindings, applyState)\n\t\t: runtime.onEngineMessage((message) => {\n\t\t\t\tif (message.type === \"engine_keybindings_reloaded\") applyState(message.state);\n\t\t\t});\n\tconst remoteComponents = new RemoteComponentController(runtime, ui, tuiRendererLifecycle);\n\t// Ctrl+C must reach the host while a remote proxy owns input, so publish the\n\t// only component that can answer that question exactly.\n\tconst disposeOwnership = registerRemoteProxyOwnership(runtime, remoteComponents);\n\tconst sessionPicker = new SessionPickerHostController(runtime, ui);\n\tconst inputForm = new InputFormHostController(runtime, ui);\n\tlet disposed = false;\n\treturn () => {\n\t\tif (disposed) return;\n\t\tdisposed = true;\n\t\tdisposeShortcutHandler?.();\n\t\tdisposeKeybindings();\n\t\tdisposeWorkflowActivity();\n\t\tdisposeUIPrompts();\n\t\tdisposePromptGeneration();\n\t\tonUIPrompt?.(undefined);\n\t\tdisposeOwnership();\n\t\tremoteComponents.dispose();\n\t\tsessionPicker.dispose();\n\t\tinputForm.dispose();\n\t\tdialogs.dispose();\n\t\tdisposeDiagnostic();\n\t};\n}\n\nconst unavailableWorkflowActivity: WorkflowActivityFrame = {\n\tkind: \"snapshot\",\n\tcursor: { epoch: \"\", revision: 0 },\n\tavailability: \"unavailable\",\n};\n\n/** The engine child owns the workflow runs; a dead generation's runs are gone with it. */\nfunction observeEngineWorkflowActivity(\n\truntime: IsolatedInteractiveRuntime,\n\tobserver: (frame: WorkflowActivityFrame) => void,\n): () => void {\n\t// The runtime replays the engine's current snapshot: the engine published it at bind time, which can\n\t// be long before this observer attaches.\n\tconst disposeMessages = runtime.onWorkflowActivity(observer);\n\tconst disposeEnded = runtime.onGenerationEnded(() => observer(unavailableWorkflowActivity));\n\treturn () => {\n\t\tdisposeMessages();\n\t\tdisposeEnded();\n\t};\n}\n\n/**\n * Observe workflow activity of a session whose extensions run in this process. An isolated host\n * receives it from its engine child instead (see `attachInteractiveEngineHost`).\n */\nexport function observeLocalWorkflowActivity(\n\truntime: AgentSessionRuntime,\n\tsession: AgentSession,\n\tobserver: (frame: WorkflowActivityFrame) => void,\n): () => void {\n\tif (runtime instanceof IsolatedInteractiveRuntime) return () => {};\n\tconst subscription = session.workflows.observe(observer);\n\treturn () => subscription.dispose();\n}\n\n/** Route host-owned trust waits to the runner that actually owns the subscribers. */\nexport function withHostProjectTrustPrompt<T>(\n\truntime: AgentSessionRuntime,\n\tkind: \"select\" | \"confirm\" | \"input\",\n\ttitle: string,\n\trun: () => Promise<T>,\n): Promise<T> {\n\treturn runtime instanceof IsolatedInteractiveRuntime\n\t\t? runtime.withProjectTrustPrompt(kind, title, run)\n\t\t: runtime.session.extensionRunner.withProjectTrustPrompt(kind, title, run);\n}\n\nexport async function waitForInteractiveEngineBound(runtime: AgentSessionRuntime): Promise<void> {\n\tif (!(runtime instanceof IsolatedInteractiveRuntime)) return;\n\tawait runtime.waitUntilBound();\n\tawait runtime.initializeFromEngine();\n}\n\nexport async function waitForInteractiveEngineProjectTrust(runtime: AgentSessionRuntime): Promise<void> {\n\tif (!(runtime instanceof IsolatedInteractiveRuntime)) return;\n\tawait runtime.waitUntilProjectTrustSettled();\n}\n\nexport function interruptBlockedInteractiveEngine(runtime: AgentSessionRuntime): boolean {\n\treturn runtime instanceof IsolatedInteractiveRuntime && runtime.interruptBlockedCallback();\n}\n\n/**\n * True when the interactive engine still owes a cooperative abort or the\n * heartbeat watchdog has declared it unresponsive, i.e. when the explicit\n * Ctrl+C escape hatch promised by the watchdog copy applies.\n */\nexport function interactiveEngineNeedsExplicitTermination(runtime: AgentSessionRuntime): boolean {\n\treturn runtime instanceof IsolatedInteractiveRuntime && runtime.needsExplicitTermination();\n}\n\n/**\n * Explicitly terminate an unresponsive interactive engine and start recovery.\n * Only ever reached from a deliberate user action (Ctrl+C) — never from Escape.\n */\nexport function terminateInteractiveEngine(runtime: AgentSessionRuntime): boolean {\n\tif (!interactiveEngineNeedsExplicitTermination(runtime)) return false;\n\tvoid (runtime as IsolatedInteractiveRuntime).terminateAndRecover();\n\treturn true;\n}\n\n/**\n * Command catalog the engine child exposes to the isolated host. Returns an\n * empty list for non-isolated runtimes so callers can merge unconditionally.\n */\nexport function getInteractiveEngineRemoteCommands(runtime: AgentSessionRuntime): readonly RpcSlashCommand[] {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.getRemoteCommands() : [];\n}\n\nexport function getInteractiveEngineResourceOverlaps(runtime: AgentSessionRuntime): readonly ResourceOverlap[] {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.getResourceOverlaps() : [];\n}\n\nexport function getInteractiveEngineResourceExtensions(runtime: AgentSessionRuntime): readonly RpcResourceExtension[] {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.getResourceExtensions() : [];\n}\n\nexport function onInteractiveEngineResourceExtensionsChanged(\n\truntime: AgentSessionRuntime,\n\tlistener: (extensions: readonly RpcResourceExtension[]) => void,\n): () => void {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.onResourceExtensionsChanged(listener) : () => {};\n}\n\n/** Evaluate an engine-child command's live argument completions. */\nexport function getInteractiveEngineRemoteCommandCompletions(\n\truntime: AgentSessionRuntime,\n\tcommandName: string,\n\targumentPrefix: string,\n): Promise<RpcAutocompleteItem[] | null> {\n\treturn runtime instanceof IsolatedInteractiveRuntime\n\t\t? runtime.getRemoteCommandCompletions(commandName, argumentPrefix)\n\t\t: Promise.resolve(null);\n}\n\n/** Subscribe to engine-child command catalog changes. No-op when not isolated. */\nexport function onInteractiveEngineRemoteCommandsChanged(\n\truntime: AgentSessionRuntime,\n\tlistener: (commands: readonly RpcSlashCommand[]) => void,\n): () => void {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.onRemoteCommandsChanged(listener) : () => {};\n}\n\n/** Subscribe to fresh engine session stats, so the footer can repaint. No-op when not isolated. */\nexport function onInteractiveEngineSessionStatsChanged(runtime: AgentSessionRuntime, listener: () => void): () => void {\n\treturn runtime instanceof IsolatedInteractiveRuntime ? runtime.onSessionStatsChanged(listener) : () => {};\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CallbackActivity } from "../../core/callback-activity.ts";
|
|
2
|
+
import type { UIPromptEndEvent, UIPromptStartEvent } from "../../core/extensions/agent-events.ts";
|
|
2
3
|
import type { HostInputFormField, HostSessionPickerRow, WidgetScrollRequest, WidgetScrollState } from "../../core/extensions/ui-types.js";
|
|
3
4
|
import type { WorkflowActivityFrame } from "../../core/extensions/workflow-events.js";
|
|
4
5
|
import type { KeyId } from "../../core/keybindings.ts";
|
|
@@ -94,6 +95,9 @@ export type InteractiveEngineMessage = {
|
|
|
94
95
|
| {
|
|
95
96
|
type: "engine_workflow_activity";
|
|
96
97
|
frame: WorkflowActivityFrame;
|
|
98
|
+
} | {
|
|
99
|
+
type: "engine_ui_prompt";
|
|
100
|
+
event: UIPromptStartEvent | UIPromptEndEvent;
|
|
97
101
|
}
|
|
98
102
|
/**
|
|
99
103
|
* The child took ownership of a correlated RPC request: it has parsed the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive-engine/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAwB,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,EACX,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAwB,MAAM,0CAA0C,CAAC;AAC5G,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,IAAI,CAAC;AAErD,MAAM,WAAW,UAAU;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,EAAE,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpF,MAAM,WAAW,0BAA0B;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnF,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAA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W,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC3E;IAAE,IAAI,EAAE,0BAA0B,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACzF;IAAE,IAAI,EAAE,0BAA0B,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAY7D,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,IAAI,SAAS,CAIhG;AAwPD,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAsMhG;AAED,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,yBAAyB,GAAG,SAAS,CAElG;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAkHhG;AAED,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,wBAAwB,GAAG,wBAAwB,GAAG,yBAAyB,GACtF,MAAM,CAER;AAED,eAAO,MAAM,iCAAiC,wCAAkC,CAAC"}
|
|
@@ -44,6 +44,8 @@ const WORKFLOW_ACTIVITY_REASONS = [
|
|
|
44
44
|
"paused",
|
|
45
45
|
"quiescent",
|
|
46
46
|
];
|
|
47
|
+
const WORKFLOW_PROMPT_KINDS = ["input", "confirm", "select", "editor", "custom"];
|
|
48
|
+
const WORKFLOW_ENDED_STATUSES = ["completed", "cancelled", "killed", "failed"];
|
|
47
49
|
function parseWorkflowRoot(value) {
|
|
48
50
|
if (!isJsonObject(value) ||
|
|
49
51
|
typeof value.rootRunId !== "string" ||
|
|
@@ -54,7 +56,11 @@ function parseWorkflowRoot(value) {
|
|
|
54
56
|
!WORKFLOW_ACTIVITY_REASONS.includes(value.reason) ||
|
|
55
57
|
typeof value.activeExecutionCount !== "number" ||
|
|
56
58
|
typeof value.actionableBlockCount !== "number" ||
|
|
57
|
-
typeof value.needsAttention !== "boolean"
|
|
59
|
+
typeof value.needsAttention !== "boolean" ||
|
|
60
|
+
(value.blockedPromptKind !== undefined &&
|
|
61
|
+
(typeof value.blockedPromptKind !== "string" || !WORKFLOW_PROMPT_KINDS.includes(value.blockedPromptKind))) ||
|
|
62
|
+
(value.endedStatus !== undefined &&
|
|
63
|
+
(typeof value.endedStatus !== "string" || !WORKFLOW_ENDED_STATUSES.includes(value.endedStatus))))
|
|
58
64
|
return undefined;
|
|
59
65
|
return {
|
|
60
66
|
rootRunId: value.rootRunId,
|
|
@@ -64,6 +70,12 @@ function parseWorkflowRoot(value) {
|
|
|
64
70
|
activeExecutionCount: value.activeExecutionCount,
|
|
65
71
|
actionableBlockCount: value.actionableBlockCount,
|
|
66
72
|
needsAttention: value.needsAttention,
|
|
73
|
+
...(value.blockedPromptKind !== undefined
|
|
74
|
+
? { blockedPromptKind: value.blockedPromptKind }
|
|
75
|
+
: {}),
|
|
76
|
+
...(value.endedStatus !== undefined
|
|
77
|
+
? { endedStatus: value.endedStatus }
|
|
78
|
+
: {}),
|
|
67
79
|
};
|
|
68
80
|
}
|
|
69
81
|
function parseWorkflowActivityFrame(value) {
|
|
@@ -266,6 +278,32 @@ export function parseInteractiveEngineMessage(line) {
|
|
|
266
278
|
return isCallbackActivity(value.activity) ? { type: value.type, activity: value.activity } : undefined;
|
|
267
279
|
case "engine_activity_finished":
|
|
268
280
|
return typeof value.activityId === "string" ? { type: value.type, activityId: value.activityId } : undefined;
|
|
281
|
+
case "engine_ui_prompt": {
|
|
282
|
+
const event = value.event;
|
|
283
|
+
if (!event || !isJsonObject(event))
|
|
284
|
+
return undefined;
|
|
285
|
+
if (event.type !== "ui_prompt_start" && event.type !== "ui_prompt_end")
|
|
286
|
+
return undefined;
|
|
287
|
+
if (event.reason !== "ui_prompt" && event.reason !== "project_trust")
|
|
288
|
+
return undefined;
|
|
289
|
+
if (event.kind !== "select" &&
|
|
290
|
+
event.kind !== "confirm" &&
|
|
291
|
+
event.kind !== "input" &&
|
|
292
|
+
event.kind !== "editor" &&
|
|
293
|
+
event.kind !== "custom")
|
|
294
|
+
return undefined;
|
|
295
|
+
if (event.title !== undefined && typeof event.title !== "string")
|
|
296
|
+
return undefined;
|
|
297
|
+
return {
|
|
298
|
+
type: value.type,
|
|
299
|
+
event: {
|
|
300
|
+
type: event.type,
|
|
301
|
+
reason: event.reason,
|
|
302
|
+
kind: event.kind,
|
|
303
|
+
...(event.title === undefined ? {} : { title: event.title }),
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
}
|
|
269
307
|
case "engine_workflow_activity": {
|
|
270
308
|
const frame = parseWorkflowActivityFrame(value.frame);
|
|
271
309
|
return frame ? { type: value.type, frame } : undefined;
|