@osolmaz/pi-workflows 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +78 -110
  2. package/dist/builtins/autoimplement.workflow.js +3 -1
  3. package/dist/builtins/autoimplement.workflow.js.map +1 -1
  4. package/dist/builtins/change-verification.workflow.js +7 -2
  5. package/dist/builtins/change-verification.workflow.js.map +1 -1
  6. package/dist/builtins/metadata.d.ts +22 -0
  7. package/dist/builtins/metadata.js +10 -0
  8. package/dist/builtins/metadata.js.map +1 -0
  9. package/dist/builtins/monitor.workflow.js +4 -1
  10. package/dist/builtins/monitor.workflow.js.map +1 -1
  11. package/dist/builtins/sanity-check.workflow.js +4 -1
  12. package/dist/builtins/sanity-check.workflow.js.map +1 -1
  13. package/dist/builtins/workspace-preparation.workflow.js +3 -1
  14. package/dist/builtins/workspace-preparation.workflow.js.map +1 -1
  15. package/dist/controllers/index.d.ts +0 -1
  16. package/dist/controllers/index.js +0 -1
  17. package/dist/controllers/index.js.map +1 -1
  18. package/dist/controllers/sqlite.d.ts +51 -0
  19. package/dist/controllers/sqlite.js +433 -57
  20. package/dist/controllers/sqlite.js.map +1 -1
  21. package/dist/controllers/store.d.ts +1 -0
  22. package/dist/extension/controller-command.d.ts +22 -0
  23. package/dist/extension/controller-command.js +32 -0
  24. package/dist/extension/controller-command.js.map +1 -0
  25. package/dist/extension/index.d.ts +2 -9
  26. package/dist/extension/index.js +876 -3447
  27. package/dist/extension/index.js.map +1 -1
  28. package/dist/extension/message-card.d.ts +13 -0
  29. package/dist/extension/message-card.js +46 -0
  30. package/dist/extension/message-card.js.map +1 -0
  31. package/dist/extension/step-message.d.ts +5 -6
  32. package/dist/extension/step-message.js +41 -52
  33. package/dist/extension/step-message.js.map +1 -1
  34. package/dist/host/child-worker-supervisor.d.ts +50 -0
  35. package/dist/host/child-worker-supervisor.js +159 -0
  36. package/dist/host/child-worker-supervisor.js.map +1 -0
  37. package/dist/host/client.d.ts +48 -0
  38. package/dist/host/client.js +216 -0
  39. package/dist/host/client.js.map +1 -0
  40. package/dist/host/controller-worker-entry.d.ts +2 -0
  41. package/dist/host/controller-worker-entry.js +244 -0
  42. package/dist/host/controller-worker-entry.js.map +1 -0
  43. package/dist/host/controller-worker-protocol.d.ts +36 -0
  44. package/dist/host/controller-worker-protocol.js +49 -0
  45. package/dist/host/controller-worker-protocol.js.map +1 -0
  46. package/dist/host/controller-worker-supervisor.d.ts +21 -0
  47. package/dist/host/controller-worker-supervisor.js +54 -0
  48. package/dist/host/controller-worker-supervisor.js.map +1 -0
  49. package/dist/host/host-entry.d.ts +2 -0
  50. package/dist/host/host-entry.js +23 -0
  51. package/dist/host/host-entry.js.map +1 -0
  52. package/dist/host/processes.d.ts +17 -12
  53. package/dist/host/processes.js +154 -50
  54. package/dist/host/processes.js.map +1 -1
  55. package/dist/host/protocol.d.ts +38 -0
  56. package/dist/host/protocol.js +156 -0
  57. package/dist/host/protocol.js.map +1 -0
  58. package/dist/host/resolver-entry.d.ts +49 -0
  59. package/dist/host/resolver-entry.js +149 -0
  60. package/dist/host/resolver-entry.js.map +1 -0
  61. package/dist/host/rpc-executor.d.ts +14 -3
  62. package/dist/host/rpc-executor.js +63 -30
  63. package/dist/host/rpc-executor.js.map +1 -1
  64. package/dist/host/runner.d.ts +95 -29
  65. package/dist/host/runner.js +2311 -348
  66. package/dist/host/runner.js.map +1 -1
  67. package/dist/host/state.d.ts +174 -0
  68. package/dist/host/state.js +689 -0
  69. package/dist/host/state.js.map +1 -0
  70. package/dist/host/worker-entry.d.ts +10 -0
  71. package/dist/host/worker-entry.js +446 -0
  72. package/dist/host/worker-entry.js.map +1 -0
  73. package/dist/host/worker-protocol.d.ts +31 -0
  74. package/dist/host/worker-protocol.js +122 -0
  75. package/dist/host/worker-protocol.js.map +1 -0
  76. package/dist/host/worker-store.d.ts +80 -0
  77. package/dist/host/worker-store.js +91 -0
  78. package/dist/host/worker-store.js.map +1 -0
  79. package/dist/host/worker-supervisor.d.ts +22 -0
  80. package/dist/host/worker-supervisor.js +54 -0
  81. package/dist/host/worker-supervisor.js.map +1 -0
  82. package/dist/render/canvas.d.ts +2 -1
  83. package/dist/render/canvas.js +40 -15
  84. package/dist/render/canvas.js.map +1 -1
  85. package/dist/render/graph-render.d.ts +7 -3
  86. package/dist/render/graph-render.js +125 -74
  87. package/dist/render/graph-render.js.map +1 -1
  88. package/dist/state/database.js +3 -1
  89. package/dist/state/database.js.map +1 -1
  90. package/dist/state/index.d.ts +1 -0
  91. package/dist/state/index.js +1 -0
  92. package/dist/state/index.js.map +1 -1
  93. package/dist/state/schema.d.ts +1 -1
  94. package/dist/state/schema.js +171 -3
  95. package/dist/state/schema.js.map +1 -1
  96. package/dist/state/viewer.d.ts +46 -0
  97. package/dist/state/viewer.js +249 -0
  98. package/dist/state/viewer.js.map +1 -0
  99. package/dist/viewer/cli.d.ts +1 -1
  100. package/dist/viewer/cli.js +47 -18
  101. package/dist/viewer/cli.js.map +1 -1
  102. package/dist/workflows/composition.js +25 -2
  103. package/dist/workflows/composition.js.map +1 -1
  104. package/dist/workflows/definition.d.ts +3 -1
  105. package/dist/workflows/definition.js +25 -0
  106. package/dist/workflows/definition.js.map +1 -1
  107. package/dist/workflows/engine.d.ts +1 -0
  108. package/dist/workflows/engine.js +157 -42
  109. package/dist/workflows/engine.js.map +1 -1
  110. package/dist/workflows/errors.d.ts +3 -1
  111. package/dist/workflows/errors.js +4 -7
  112. package/dist/workflows/errors.js.map +1 -1
  113. package/dist/workflows/human-decision.d.ts +3 -0
  114. package/dist/workflows/human-decision.js +31 -0
  115. package/dist/workflows/human-decision.js.map +1 -1
  116. package/dist/workflows/index.d.ts +1 -1
  117. package/dist/workflows/index.js +1 -1
  118. package/dist/workflows/index.js.map +1 -1
  119. package/dist/workflows/schema.js +17 -6
  120. package/dist/workflows/schema.js.map +1 -1
  121. package/dist/{viewer → workflows}/session-reducer.d.ts +3 -1
  122. package/dist/{viewer → workflows}/session-reducer.js +4 -0
  123. package/dist/workflows/session-reducer.js.map +1 -0
  124. package/dist/workflows/store.d.ts +87 -1
  125. package/dist/workflows/store.js +892 -93
  126. package/dist/workflows/store.js.map +1 -1
  127. package/dist/workflows/tool-input.d.ts +0 -26
  128. package/dist/workflows/tool-input.js +2 -50
  129. package/dist/workflows/tool-input.js.map +1 -1
  130. package/dist/workflows/types.d.ts +36 -4
  131. package/docs/2026-08-30-out-of-process-workflow-host-plan.md +353 -0
  132. package/docs/CONTROLLERS.md +11 -11
  133. package/docs/DEFERRED_TURNS.md +23 -2
  134. package/docs/SQLITE_STATE.md +41 -31
  135. package/docs/WORKFLOW_HOST.md +452 -0
  136. package/docs/development.md +46 -30
  137. package/docs/live-replay-protocol.md +129 -100
  138. package/docs/plans/2026-08-27-workflow-terminal-restart-plan.md +42 -0
  139. package/docs/plans/2026-08-28-piw-incremental-viewer-plan.md +293 -0
  140. package/docs/plans/piw-viewer-experience-implementation-plan.md +11 -1
  141. package/docs/plans/tui-viewer-implementation-plan.md +5 -0
  142. package/docs/tui-viewer.md +18 -3
  143. package/docs/workflows.md +162 -210
  144. package/examples/workflows/command-batch.workflow.ts +2 -0
  145. package/examples/workflows/shell.workflow.ts +2 -1
  146. package/herdr-plugin.toml +1 -1
  147. package/package.json +1 -1
  148. package/src/builtins/autoimplement.workflow.ts +3 -0
  149. package/src/builtins/change-verification.workflow.ts +7 -2
  150. package/src/builtins/metadata.ts +9 -0
  151. package/src/builtins/monitor.workflow.ts +4 -0
  152. package/src/builtins/sanity-check.workflow.ts +4 -0
  153. package/src/builtins/workspace-preparation.workflow.ts +3 -1
  154. package/src/controllers/index.ts +0 -5
  155. package/src/controllers/sqlite.ts +709 -76
  156. package/src/controllers/store.ts +1 -0
  157. package/src/extension/controller-command.ts +45 -0
  158. package/src/extension/index.ts +944 -4163
  159. package/src/extension/message-card.ts +61 -0
  160. package/src/extension/step-message.ts +58 -63
  161. package/src/host/child-worker-supervisor.ts +183 -0
  162. package/src/host/client.ts +293 -0
  163. package/src/host/controller-worker-entry.ts +311 -0
  164. package/src/host/controller-worker-protocol.ts +104 -0
  165. package/src/host/controller-worker-supervisor.ts +79 -0
  166. package/src/host/host-entry.ts +23 -0
  167. package/src/host/processes.ts +171 -54
  168. package/src/host/protocol.ts +196 -0
  169. package/src/host/resolver-entry.ts +241 -0
  170. package/src/host/rpc-executor.ts +76 -34
  171. package/src/host/runner.ts +2813 -422
  172. package/src/host/state.ts +1160 -0
  173. package/src/host/worker-entry.ts +533 -0
  174. package/src/host/worker-protocol.ts +165 -0
  175. package/src/host/worker-store.ts +229 -0
  176. package/src/host/worker-supervisor.ts +74 -0
  177. package/src/render/canvas.ts +44 -10
  178. package/src/render/graph-render.ts +145 -90
  179. package/src/state/database.ts +2 -1
  180. package/src/state/index.ts +14 -0
  181. package/src/state/schema.ts +171 -3
  182. package/src/state/viewer.ts +356 -0
  183. package/src/viewer/cli.ts +49 -17
  184. package/src/workflows/composition.ts +36 -2
  185. package/src/workflows/definition.ts +32 -0
  186. package/src/workflows/engine.ts +157 -54
  187. package/src/workflows/errors.ts +11 -2
  188. package/src/workflows/human-decision.ts +49 -0
  189. package/src/workflows/index.ts +2 -0
  190. package/src/workflows/schema.ts +19 -6
  191. package/src/{viewer → workflows}/session-reducer.ts +11 -1
  192. package/src/workflows/store.ts +1316 -108
  193. package/src/workflows/tool-input.ts +3 -69
  194. package/src/workflows/types.ts +32 -4
  195. package/dist/controllers/workflow-engine-scheduler.d.ts +0 -29
  196. package/dist/controllers/workflow-engine-scheduler.js +0 -175
  197. package/dist/controllers/workflow-engine-scheduler.js.map +0 -1
  198. package/dist/extension/controller-host.d.ts +0 -48
  199. package/dist/extension/controller-host.js +0 -110
  200. package/dist/extension/controller-host.js.map +0 -1
  201. package/dist/extension/deferred-turn-coordinator.d.ts +0 -32
  202. package/dist/extension/deferred-turn-coordinator.js +0 -143
  203. package/dist/extension/deferred-turn-coordinator.js.map +0 -1
  204. package/dist/extension/deferred-turn.d.ts +0 -44
  205. package/dist/extension/deferred-turn.js +0 -110
  206. package/dist/extension/deferred-turn.js.map +0 -1
  207. package/dist/extension/executor.d.ts +0 -86
  208. package/dist/extension/executor.js +0 -311
  209. package/dist/extension/executor.js.map +0 -1
  210. package/dist/extension/follow-up-coordinator.d.ts +0 -27
  211. package/dist/extension/follow-up-coordinator.js +0 -131
  212. package/dist/extension/follow-up-coordinator.js.map +0 -1
  213. package/dist/extension/recorder.d.ts +0 -84
  214. package/dist/extension/recorder.js +0 -528
  215. package/dist/extension/recorder.js.map +0 -1
  216. package/dist/extension/restart-policy.d.ts +0 -38
  217. package/dist/extension/restart-policy.js +0 -116
  218. package/dist/extension/restart-policy.js.map +0 -1
  219. package/dist/extension/session-events.d.ts +0 -133
  220. package/dist/extension/session-events.js +0 -61
  221. package/dist/extension/session-events.js.map +0 -1
  222. package/dist/extension/terminal-decision.d.ts +0 -51
  223. package/dist/extension/terminal-decision.js +0 -110
  224. package/dist/extension/terminal-decision.js.map +0 -1
  225. package/dist/viewer/session-reducer.js.map +0 -1
  226. package/src/controllers/workflow-engine-scheduler.ts +0 -246
  227. package/src/extension/controller-host.ts +0 -167
  228. package/src/extension/deferred-turn-coordinator.ts +0 -171
  229. package/src/extension/deferred-turn.ts +0 -166
  230. package/src/extension/executor.ts +0 -411
  231. package/src/extension/follow-up-coordinator.ts +0 -151
  232. package/src/extension/recorder.ts +0 -655
  233. package/src/extension/restart-policy.ts +0 -163
  234. package/src/extension/session-events.ts +0 -121
  235. package/src/extension/terminal-decision.ts +0 -172
@@ -1,311 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- const DEFAULT_MAX_NUDGES = 2;
3
- /**
4
- * AgentStepExecutor that runs steps inside the current pi conversation. The
5
- * engine hands it a prompt; it delivers the prompt as a model-facing workflow
6
- * message and resolves once the model submits an accepted output through the `workflow`
7
- * tool. If the agent settles without submitting, it nudges the model a
8
- * bounded number of times before failing the step.
9
- */
10
- export class ConversationStepExecutor {
11
- assistantMessageMode = "visible";
12
- sendPrompt;
13
- maxNudges;
14
- conversation;
15
- onAbort;
16
- pending = null;
17
- streaming = false;
18
- heldByUser = false;
19
- constructor(options) {
20
- this.sendPrompt = options.sendPrompt;
21
- this.maxNudges = options.maxNudges ?? DEFAULT_MAX_NUDGES;
22
- this.conversation = options.conversation;
23
- this.onAbort = options.onAbort;
24
- }
25
- /** Track agent streaming state (wire to agent_start / agent_settled). */
26
- setStreaming(streaming) {
27
- this.streaming = streaming;
28
- }
29
- get pendingStepId() {
30
- return this.pending?.request.contract.nodeId ?? null;
31
- }
32
- get pendingCompletion() {
33
- return this.pending === null ? null : completionKind(this.pending.request);
34
- }
35
- /**
36
- * Hold the pending step for the user: no nudges are sent while held, so an
37
- * escape-interrupted conversation stays quiet until the user resumes.
38
- */
39
- hold() {
40
- this.heldByUser = true;
41
- }
42
- get held() {
43
- return this.heldByUser;
44
- }
45
- /**
46
- * Release a user hold. When a step is still pending, its prompt is
47
- * re-delivered so the model picks the step back up.
48
- */
49
- release() {
50
- if (!this.heldByUser) {
51
- return;
52
- }
53
- this.heldByUser = false;
54
- const pending = this.pending;
55
- if (!pending) {
56
- return;
57
- }
58
- try {
59
- this.conversation?.beginAttempt?.(pending.request.contract);
60
- this.sendPrompt(this.delivery(pending.request, pending.request.prompt, "resume"));
61
- }
62
- catch (error) {
63
- this.clearPending();
64
- pending.reject(error);
65
- }
66
- }
67
- async runAgentStep(request, signal) {
68
- if (this.pending) {
69
- throw new Error("Another workflow step is already awaiting output");
70
- }
71
- if (completionKind(request) === "assistant") {
72
- const recovered = this.conversation?.recoverAssistant?.(request.contract);
73
- if (recovered !== undefined) {
74
- return recovered;
75
- }
76
- }
77
- return await new Promise((resolve, reject) => {
78
- const onAbort = () => {
79
- const reason = signal.reason ?? new Error("Workflow step aborted");
80
- if (this.pending?.request !== request) {
81
- return;
82
- }
83
- this.clearPending();
84
- try {
85
- this.onAbort?.(request.contract, reason);
86
- }
87
- finally {
88
- reject(reason);
89
- }
90
- };
91
- signal.addEventListener("abort", onAbort, { once: true });
92
- let markCleared;
93
- const cleared = new Promise((resolveCleared) => {
94
- markCleared = resolveCleared;
95
- });
96
- this.conversation?.beginAttempt?.(request.contract);
97
- this.pending = {
98
- request,
99
- resolve,
100
- reject,
101
- nudgesSent: 0,
102
- mark: this.conversation?.mark() ?? null,
103
- cleanup: () => signal.removeEventListener("abort", onAbort),
104
- cleared,
105
- markCleared,
106
- };
107
- if (signal.aborted) {
108
- onAbort();
109
- return;
110
- }
111
- try {
112
- this.sendPrompt(this.delivery(request, request.prompt, "step"));
113
- }
114
- catch (error) {
115
- // A failed delivery must not leave the step installed, or every
116
- // subsequent agent node would fail with "already awaiting output".
117
- this.clearPending();
118
- reject(error);
119
- }
120
- });
121
- }
122
- /** Called by the `workflow` tool when the model submits a step output. */
123
- async submit(stepId, attemptId, output) {
124
- const pending = this.pending;
125
- if (!pending) {
126
- return {
127
- accepted: false,
128
- message: "No workflow step is awaiting output. Do not call the workflow tool outside an active workflow step.",
129
- };
130
- }
131
- const expected = pending.request.contract.nodeId;
132
- if (stepId !== expected) {
133
- return {
134
- accepted: false,
135
- message: `Wrong step id ${JSON.stringify(stepId)}; the pending step is ${JSON.stringify(expected)}.`,
136
- };
137
- }
138
- // Loops revisit the same node id, so a delayed duplicate submission from
139
- // an earlier attempt would otherwise be accepted as this attempt's output.
140
- const expectedAttempt = pending.request.contract.attemptId;
141
- if (attemptId !== expectedAttempt) {
142
- return {
143
- accepted: false,
144
- message: `Stale attempt id ${JSON.stringify(attemptId)} for step ${JSON.stringify(stepId)}; the pending attempt is ${JSON.stringify(expectedAttempt)}. Use the attempt id from the latest step contract.`,
145
- };
146
- }
147
- if (completionKind(pending.request) === "assistant") {
148
- return {
149
- accepted: false,
150
- message: "This step completes with a normal assistant response. Do not submit workflow output.",
151
- };
152
- }
153
- // Race validation against the step being cleared: a hung `validate`
154
- // callback must not leave this tool call (and therefore pi) blocked after
155
- // a timeout or cancel already resolved the run.
156
- const result = await Promise.race([
157
- pending.request.accept(output),
158
- pending.cleared.then(() => null),
159
- ]);
160
- // The step may have timed out or been cancelled (and a newer step
161
- // installed) while validation was awaited; a stale submission must not
162
- // clear or resolve the newer pending step.
163
- if (result === null || this.pending !== pending) {
164
- return {
165
- accepted: false,
166
- message: `Step ${JSON.stringify(stepId)} is no longer awaiting output.`,
167
- };
168
- }
169
- if (!result.ok) {
170
- return {
171
- accepted: false,
172
- message: `Output rejected for step ${JSON.stringify(stepId)}: ${result.error}`,
173
- };
174
- }
175
- this.clearPending();
176
- const conversation = pending.mark !== null ? this.conversation?.rangeSince(pending.mark) : undefined;
177
- pending.resolve({
178
- output: result.value,
179
- ...(conversation !== undefined ? { conversation } : {}),
180
- });
181
- return {
182
- accepted: true,
183
- message: `Output accepted for step ${JSON.stringify(stepId)}.`,
184
- };
185
- }
186
- /** Keep the latest finalized assistant message for an assistant-output step. */
187
- handleMessageEnd(message) {
188
- const pending = this.pending;
189
- if (pending === null || completionKind(pending.request) !== "assistant") {
190
- return;
191
- }
192
- const assistant = assistantMessageLike(message);
193
- if (assistant !== undefined) {
194
- pending.assistantMessage = assistant;
195
- }
196
- }
197
- /**
198
- * Called when the agent settles. Returns true when a nudge was sent, false
199
- * when there was nothing to do. Submitted steps use bounded nudges;
200
- * assistant-output steps accept or fail the one visible response.
201
- */
202
- handleAgentSettled() {
203
- const pending = this.pending;
204
- if (!pending) {
205
- return false;
206
- }
207
- if (this.heldByUser) {
208
- // The user interrupted deliberately; reminding the model now would
209
- // steal the conversation back. The step waits for an explicit resume.
210
- return false;
211
- }
212
- if (completionKind(pending.request) === "assistant") {
213
- try {
214
- const output = visibleAssistantText(pending.assistantMessage, pending.request.contract.maxOutputChars);
215
- const conversation = pending.mark !== null ? this.conversation?.rangeSince(pending.mark) : undefined;
216
- const assistantMessage = {
217
- sha256: createHash("sha256").update(output).digest("hex"),
218
- ...(conversation?.lastEntryId !== undefined ? { entryId: conversation.lastEntryId } : {}),
219
- ...(pending.request.contract.maxOutputChars !== undefined
220
- ? { maxChars: pending.request.contract.maxOutputChars }
221
- : {}),
222
- };
223
- this.clearPending();
224
- pending.resolve({
225
- output,
226
- assistantMessage,
227
- ...(conversation !== undefined ? { conversation } : {}),
228
- });
229
- }
230
- catch (error) {
231
- this.clearPending();
232
- pending.reject(error);
233
- }
234
- return false;
235
- }
236
- if (pending.nudgesSent >= this.maxNudges) {
237
- this.clearPending();
238
- pending.reject(new Error(`Agent settled ${pending.nudgesSent + 1} times without submitting step ${JSON.stringify(pending.request.contract.nodeId)} via the workflow tool`));
239
- return false;
240
- }
241
- pending.nudgesSent += 1;
242
- const { nodeId, attemptId } = pending.request.contract;
243
- try {
244
- this.conversation?.beginAttempt?.(pending.request.contract);
245
- this.sendPrompt(this.delivery(pending.request, [
246
- `Reminder: workflow step ${JSON.stringify(nodeId)} is still awaiting your output.`,
247
- "Complete it by calling the `workflow` tool with:",
248
- `{"action": "submit", "step": ${JSON.stringify(nodeId)}, "attempt": ${JSON.stringify(attemptId)}, "output": <your result>}`,
249
- `Expected output: ${pending.request.contract.expectedOutput ?? "a JSON object with your result"}`,
250
- ].join("\n"), "reminder"));
251
- }
252
- catch (error) {
253
- // No reminder turn was started, so nothing would settle the step; fail
254
- // it promptly instead of waiting out the node timeout.
255
- this.clearPending();
256
- pending.reject(error);
257
- return false;
258
- }
259
- return true;
260
- }
261
- delivery(request, prompt, kind) {
262
- return {
263
- prompt,
264
- contract: request.contract,
265
- ...(request.presentation !== undefined ? { presentation: request.presentation } : {}),
266
- kind,
267
- streaming: this.streaming,
268
- };
269
- }
270
- clearPending() {
271
- this.pending?.cleanup();
272
- this.pending?.markCleared();
273
- this.pending = null;
274
- }
275
- }
276
- function completionKind(request) {
277
- return request.contract.completion;
278
- }
279
- function assistantMessageLike(message) {
280
- if (message === null || typeof message !== "object")
281
- return undefined;
282
- const candidate = message;
283
- if (candidate.role !== "assistant" || !Array.isArray(candidate.content))
284
- return undefined;
285
- if (typeof candidate.stopReason !== "string")
286
- return undefined;
287
- return candidate;
288
- }
289
- /** Extract the exact visible text blocks from one finalized assistant message. */
290
- export function visibleAssistantText(message, maxChars) {
291
- const assistant = assistantMessageLike(message);
292
- if (assistant === undefined) {
293
- throw new Error("Assistant step settled without a final assistant message");
294
- }
295
- if (assistant.stopReason !== "stop" && assistant.stopReason !== "length") {
296
- throw new Error(assistant.errorMessage?.trim() ||
297
- `Assistant step stopped with ${JSON.stringify(assistant.stopReason)} before a final response`);
298
- }
299
- const text = assistant.content
300
- .filter((part) => part.type === "text")
301
- .map((part) => part.text)
302
- .join("\n");
303
- if (text.trim().length === 0) {
304
- throw new Error("Assistant step returned no visible text");
305
- }
306
- if (maxChars !== undefined && text.length > maxChars) {
307
- throw new Error(`Assistant response has ${text.length} characters, above the configured limit of ${maxChars}`);
308
- }
309
- return text;
310
- }
311
- //# sourceMappingURL=executor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/extension/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA8DzC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B;;;;;;GAMG;AACH,MAAM,OAAO,wBAAwB;IAC1B,oBAAoB,GAAG,SAAkB,CAAC;IAClC,UAAU,CAAqC;IAC/C,SAAS,CAAS;IAClB,YAAY,CAAgC;IAC5C,OAAO,CAA6C;IAC7D,OAAO,GAAuB,IAAI,CAAC;IACnC,SAAS,GAAG,KAAK,CAAC;IAClB,UAAU,GAAG,KAAK,CAAC;IAE3B,YAAY,OAAwC;QAClD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;QACzD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;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AAC,0BAA0B,CAChG,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO;SAC3B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;SACtC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;SACxB,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,0BAA0B,IAAI,CAAC,MAAM,8CAA8C,QAAQ,EAAE,CAC9F,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,27 +0,0 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import type { LeaseClaim } from "../state/mutation.js";
3
- import type { WorkflowFollowUpRecord } from "../workflows/settings.js";
4
- import { WorkflowRunStore } from "../workflows/store.js";
5
- export type FollowUpDelivery = {
6
- followUp: WorkflowFollowUpRecord;
7
- claim: LeaseClaim;
8
- };
9
- export declare class FollowUpCoordinator {
10
- private readonly store;
11
- private readonly ownerId;
12
- private readonly sendUserMessage;
13
- private pending;
14
- private synchronizing;
15
- constructor(store: WorkflowRunStore, ownerId: string, sendUserMessage: (text: string, options?: {
16
- deliverAs?: "followUp";
17
- }) => void);
18
- synchronize(ctx: ExtensionContext, workflowActive: boolean): Promise<void>;
19
- clear(): void;
20
- private releaseClaim;
21
- }
22
- export declare function followUpMessageText(followUp: Pick<WorkflowFollowUpRecord, "followUpId" | "prompt">): string;
23
- export declare function findFollowUpEntryId(entries: readonly unknown[], followUpId: string): string | undefined;
24
- export declare function findSettledPresentationEntries(entries: readonly unknown[], runId: string): {
25
- presentationEntryId: string;
26
- assistantEntryId: string;
27
- } | undefined;
@@ -1,131 +0,0 @@
1
- import { WorkflowRunStore } from "../workflows/store.js";
2
- const FOLLOW_UP_ID_PREFIX = "pi-workflows-follow-up:";
3
- export class FollowUpCoordinator {
4
- store;
5
- ownerId;
6
- sendUserMessage;
7
- pending;
8
- synchronizing = false;
9
- constructor(store, ownerId, sendUserMessage) {
10
- this.store = store;
11
- this.ownerId = ownerId;
12
- this.sendUserMessage = sendUserMessage;
13
- }
14
- async synchronize(ctx, workflowActive) {
15
- if (this.synchronizing)
16
- return;
17
- this.synchronizing = true;
18
- try {
19
- const sessionId = ctx.sessionManager.getSessionId();
20
- if (this.pending !== undefined) {
21
- const entryId = findFollowUpEntryId(ctx.sessionManager.getBranch(), this.pending.followUp.followUpId);
22
- if (entryId === undefined)
23
- return;
24
- this.store.markFollowUpSent(this.pending.followUp.followUpId, this.pending.claim, entryId);
25
- this.releaseClaim(this.pending.claim);
26
- this.pending = undefined;
27
- }
28
- if (!ctx.isIdle() || workflowActive)
29
- return;
30
- const claimed = this.store.claimNextFollowUp(sessionId, this.ownerId);
31
- if (claimed === undefined)
32
- return;
33
- const entryId = findFollowUpEntryId(ctx.sessionManager.getBranch(), claimed.followUp.followUpId);
34
- if (entryId !== undefined) {
35
- this.store.markFollowUpSent(claimed.followUp.followUpId, claimed.claim, entryId);
36
- this.releaseClaim(claimed.claim);
37
- return;
38
- }
39
- this.pending = claimed;
40
- try {
41
- this.sendUserMessage(followUpMessageText(claimed.followUp));
42
- }
43
- catch (error) {
44
- this.pending = undefined;
45
- this.releaseClaim(claimed.claim);
46
- throw error;
47
- }
48
- }
49
- finally {
50
- this.synchronizing = false;
51
- }
52
- }
53
- clear() {
54
- this.pending = undefined;
55
- }
56
- releaseClaim(claim) {
57
- try {
58
- this.store.releaseFollowUpClaim(claim);
59
- }
60
- catch {
61
- // The lease can expire or move after delivery evidence is saved.
62
- }
63
- }
64
- }
65
- export function followUpMessageText(followUp) {
66
- return `${followUp.prompt}\n\n<!-- ${FOLLOW_UP_ID_PREFIX}${followUp.followUpId} -->`;
67
- }
68
- export function findFollowUpEntryId(entries, followUpId) {
69
- const idText = `${FOLLOW_UP_ID_PREFIX}${followUpId}`;
70
- for (let index = entries.length - 1; index >= 0; index -= 1) {
71
- const entry = entries[index];
72
- if (!isRecord(entry) || entry.type !== "message" || typeof entry.id !== "string")
73
- continue;
74
- const message = entry.message;
75
- if (!isRecord(message) || message.role !== "user")
76
- continue;
77
- if (messageText(message.content).includes(idText))
78
- return entry.id;
79
- }
80
- return undefined;
81
- }
82
- export function findSettledPresentationEntries(entries, runId) {
83
- for (let index = entries.length - 1; index >= 0; index -= 1) {
84
- const entry = entries[index];
85
- if (!isPresentationEntry(entry, runId))
86
- continue;
87
- for (let childIndex = index + 1; childIndex < entries.length; childIndex += 1) {
88
- const child = entries[childIndex];
89
- if (!isRecord(child) || child.type !== "message" || typeof child.id !== "string")
90
- continue;
91
- const message = child.message;
92
- if (!isRecord(message))
93
- continue;
94
- if (message.role === "user")
95
- break;
96
- if (message.role === "assistant" &&
97
- (message.stopReason === "stop" || message.stopReason === "length")) {
98
- return { presentationEntryId: entry.id, assistantEntryId: child.id };
99
- }
100
- }
101
- }
102
- return undefined;
103
- }
104
- function isPresentationEntry(value, runId) {
105
- if (!isRecord(value) || typeof value.id !== "string")
106
- return false;
107
- if (value.type === "custom_message") {
108
- return (value.customType === "pi-workflows-presentation" &&
109
- isRecord(value.details) &&
110
- value.details.runId === runId);
111
- }
112
- if (value.type !== "message" || !isRecord(value.message))
113
- return false;
114
- return (value.message.role === "custom" &&
115
- value.message.customType === "pi-workflows-presentation" &&
116
- isRecord(value.message.details) &&
117
- value.message.details.runId === runId);
118
- }
119
- function messageText(value) {
120
- if (typeof value === "string")
121
- return value;
122
- if (!Array.isArray(value))
123
- return "";
124
- return value
125
- .flatMap((item) => isRecord(item) && item.type === "text" && typeof item.text === "string" ? [item.text] : [])
126
- .join("\n");
127
- }
128
- function isRecord(value) {
129
- return typeof value === "object" && value !== null && !Array.isArray(value);
130
- }
131
- //# sourceMappingURL=follow-up-coordinator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"follow-up-coordinator.js","sourceRoot":"","sources":["../../src/extension/follow-up-coordinator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAOtD,MAAM,OAAO,mBAAmB;IAKX,KAAK;IACL,OAAO;IACP,eAAe;IAN1B,OAAO,CAA+B;IACtC,aAAa,GAAG,KAAK,CAAC;IAE9B,YACmB,KAAuB,EACvB,OAAe,EACf,eAA6E;qBAF7E,KAAK;uBACL,OAAO;+BACP,eAAe;IAC/B,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,GAAqB,EAAE,cAAuB;QAC9D,IAAI,IAAI,CAAC,aAAa;YAAE,OAAO;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC;YACpD,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC/B,MAAM,OAAO,GAAG,mBAAmB,CACjC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,EAC9B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CACjC,CAAC;gBACF,IAAI,OAAO,KAAK,SAAS;oBAAE,OAAO;gBAClC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;gBAC3F,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBACtC,IAAI,CAAC,O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AAO,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,OAAO,CACL,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;QAC/B,KAAK,CAAC,OAAO,CAAC,UAAU,KAAK,2BAA2B;QACxD,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAC/B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,KAAK,KAAK,CACtC,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,OAAO,KAAK;SACT,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAChB,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAC3F;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
@@ -1,84 +0,0 @@
1
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { type WorkflowRunStore } from "../workflows/store.js";
3
- import type { AgentStepContract, ConversationRange } from "../workflows/types.js";
4
- import { type MessageEndEventLike, type MessageStartEventLike, type MessageUpdateEventLike, type ToolExecutionEndEventLike, type ToolExecutionStartEventLike, type ToolExecutionUpdateEventLike, type TurnEndEventLike, type TurnStartEventLike } from "./session-events.js";
5
- type RecordedEntry = {
6
- id: string;
7
- entry: Record<string, unknown>;
8
- claimed: boolean;
9
- };
10
- /**
11
- * Records settled Pi entries and normalized temporal events in SQLite.
12
- */
13
- export declare class SessionRecorder {
14
- private readonly store;
15
- private readonly runId;
16
- /** Capture segment for this recorder after an ownership handoff. */
17
- private segmentId;
18
- private cursor;
19
- private readonly recorded;
20
- private readonly unclaimedEntries;
21
- private bound;
22
- private acceptingEntries;
23
- private acceptingEvents;
24
- private entryChain;
25
- private stopPromise;
26
- private nextEventSeq;
27
- private nextTurnId;
28
- private nextMessageId;
29
- private currentAttempt;
30
- private currentTurn;
31
- private currentMessage;
32
- private lastFinishedAttempt;
33
- private finishPromise;
34
- private resolveFinish;
35
- private finishTimer;
36
- private readonly messageOwners;
37
- private readonly stableMessageOwners;
38
- private readonly toolOwners;
39
- private readonly turnToolCallIds;
40
- private eventQueue;
41
- private readonly pendingMessageEnds;
42
- private outstandingRecords;
43
- private outstandingBytes;
44
- private flushTimer;
45
- private flushPromise;
46
- private captureFailure;
47
- constructor(store: WorkflowRunStore, runId: string);
48
- bind(ctx: ExtensionContext): Promise<void>;
49
- /** Fix the owner before the executor delivers an agent-step prompt. */
50
- beginAttempt(contract: AgentStepContract): void;
51
- /** Release ownership of the turn that Pi has fully settled. */
52
- settleAttempt(): void;
53
- handleTurnStart(event: TurnStartEventLike): void;
54
- handleTurnEnd(event: TurnEndEventLike, ctx: ExtensionContext): Promise<void>;
55
- handleMessageStart(event: MessageStartEventLike, ctx: ExtensionContext): Promise<void>;
56
- handleMessageUpdate(event: MessageUpdateEventLike): void;
57
- handleMessageEnd(event: MessageEndEventLike): void;
58
- handleToolStart(event: ToolExecutionStartEventLike): void;
59
- handleToolUpdate(_event: ToolExecutionUpdateEventLike): void;
60
- handleToolEnd(event: ToolExecutionEndEventLike): void;
61
- /** Flush new entries on the current branch into the bundle. */
62
- record(ctx: ExtensionContext): Promise<RecordedEntry[]>;
63
- /** Record durable entries, then release deferred message-end events in order. */
64
- synchronize(ctx: ExtensionContext): Promise<void>;
65
- /**
66
- * Finalize immediately when no Pi turn is active. Otherwise wait for
67
- * `turn_end`, which is the last documented lifecycle boundary needed to
68
- * include the workflow tool result and any following assistant output.
69
- */
70
- finish(): Promise<void>;
71
- stop(): Promise<void>;
72
- mark(): number;
73
- rangeSince(mark: number): ConversationRange | undefined;
74
- private ownerForMessage;
75
- private claimEntry;
76
- private enqueue;
77
- private queuedBytes;
78
- private scheduleFlush;
79
- private startFlush;
80
- private flushAllEvents;
81
- private clearFlushTimer;
82
- private failCapture;
83
- }
84
- export {};