wepscli 0.1.0 → 0.1.5

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 (43) hide show
  1. package/README.md +9 -8
  2. package/dist/WEPSCLI-shell/agent-runtime-events.js +194 -0
  3. package/dist/WEPSCLI-shell/agent-runtime-events.js.map +1 -0
  4. package/dist/WEPSCLI-shell/agent-runtime-helpers.js +117 -0
  5. package/dist/WEPSCLI-shell/agent-runtime-helpers.js.map +1 -0
  6. package/dist/WEPSCLI-shell/agent-runtime-types.js +1 -0
  7. package/dist/WEPSCLI-shell/agent-runtime-types.js.map +1 -0
  8. package/dist/WEPSCLI-shell/agent-runtime.js +42 -294
  9. package/dist/WEPSCLI-shell/agent-runtime.js.map +1 -1
  10. package/dist/WEPSCLI-shell/approval-overlay.js.map +1 -1
  11. package/dist/WEPSCLI-shell/chat-components.js +13 -6
  12. package/dist/WEPSCLI-shell/chat-components.js.map +1 -1
  13. package/dist/WEPSCLI-shell/file-change-preview.js.map +1 -1
  14. package/dist/WEPSCLI-shell/runtime-recovery.js.map +1 -1
  15. package/dist/WEPSCLI-shell/session-consistency.js +9 -0
  16. package/dist/WEPSCLI-shell/session-consistency.js.map +1 -0
  17. package/dist/WEPSCLI-shell/shell-app.js +169 -259
  18. package/dist/WEPSCLI-shell/shell-app.js.map +1 -1
  19. package/dist/WEPSCLI-shell/shell-keyboard.js +135 -0
  20. package/dist/WEPSCLI-shell/shell-keyboard.js.map +1 -0
  21. package/dist/WEPSCLI-shell/shell-modes.js.map +1 -1
  22. package/dist/WEPSCLI-shell/shell-prompt-controller.js +93 -0
  23. package/dist/WEPSCLI-shell/shell-prompt-controller.js.map +1 -0
  24. package/dist/WEPSCLI-shell/shell-status.js +16 -0
  25. package/dist/WEPSCLI-shell/shell-status.js.map +1 -0
  26. package/dist/WEPSCLI-shell/skill-commands.js +7 -0
  27. package/dist/WEPSCLI-shell/skill-commands.js.map +1 -0
  28. package/dist/WEPSCLI-shell/slash-commands.js +68 -7
  29. package/dist/WEPSCLI-shell/slash-commands.js.map +1 -1
  30. package/dist/WEPSCLI-shell/tool-approval.js.map +1 -1
  31. package/dist/WEPSCLI-shell/tool-diff.js.map +1 -1
  32. package/dist/WEPSCLI-shell/tool-file-changes.js.map +1 -1
  33. package/dist/WEPSCLI-shell/tool-message-detail.js.map +1 -1
  34. package/dist/WEPSCLI-shell/tool-messages.js.map +1 -1
  35. package/dist/WEPSCLI-shell/transcript-panel.js.map +1 -1
  36. package/dist/config.js +3 -0
  37. package/dist/config.js.map +1 -1
  38. package/dist/main.js.map +1 -1
  39. package/dist/skills/skill-add-flow.js +88 -0
  40. package/dist/skills/skill-add-flow.js.map +1 -0
  41. package/dist/skills/skill-service.js +123 -0
  42. package/dist/skills/skill-service.js.map +1 -0
  43. package/package.json +28 -24
package/README.md CHANGED
@@ -210,14 +210,15 @@ The composer supports a small slash‑command palette. Type `/` to see suggestio
210
210
 
211
211
  Built‑in commands:
212
212
 
213
- - `/new` – start a new shell session.
214
- - `/providers` – open the provider picker overlay.
215
- - `/provider add` – open the guided provider setup flow inside the shell.
216
- - `/models` – open the model picker for the active provider.
217
- - `/sessions` – choose from recent sessions.
218
- - `/review` queue a "review current change" prompt template into the composer.
219
- - `/debug` – queue a "debug current issue" prompt template.
220
- - `/provider-check` – queue a provider configuration inspection task.
213
+ - `/new` – start a new shell session.
214
+ - `/retry` – resend the last prompt in the current session.
215
+ - `/provider` or `/providers` – open the provider picker overlay.
216
+ - `/provider add` – open the guided provider setup flow inside the shell.
217
+ - `/model` or `/models` open the model picker for the active provider.
218
+ - `/session`, `/sessions`, or `/resume` choose from recent sessions.
219
+ - `/review` – queue a "review current change" prompt template into the composer.
220
+ - `/debug` – queue a "debug current issue" prompt template.
221
+ - `/provider-check` – queue a provider configuration inspection task.
221
222
 
222
223
  Unknown commands are echoed into the timeline as informational system messages.
223
224
 
@@ -0,0 +1,194 @@
1
+ import { createCompactingRuntimeState, createErrorRuntimeState, createInterruptedRuntimeState, createRetryingRuntimeState, createRunningRuntimeState } from "./runtime-status.js";
2
+ import { getRuntimeRecoveryHint } from "./runtime-recovery.js";
3
+ import { createMessageId, extractAssistantReasoning, extractAssistantVisibleText, extractUserText, formatTime } from "./agent-runtime-helpers.js";
4
+ import { createToolMessageState, updateToolMessageState } from "./tool-messages.js";
5
+ export function handleAgentSessionEvent(event, context) {
6
+ const {
7
+ sessionId,
8
+ record,
9
+ callbacks
10
+ } = context;
11
+ switch (event.type) {
12
+ case "message_start":
13
+ if (event.message.role === "user") {
14
+ const text = extractUserText(event.message);
15
+ if (text) {
16
+ callbacks.appendMessage(sessionId, {
17
+ id: createMessageId(record, "user"),
18
+ role: "user",
19
+ content: text,
20
+ time: formatTime(event.message.timestamp)
21
+ });
22
+ }
23
+ return;
24
+ }
25
+ if (event.message.role === "assistant") {
26
+ record.streamingAssistantMessageId = undefined;
27
+ record.streamingReasoningMessageId = undefined;
28
+ }
29
+ return;
30
+ case "message_update":
31
+ if (event.assistantMessageEvent.type === "thinking_delta") {
32
+ if (!record.streamingReasoningMessageId) {
33
+ record.streamingReasoningMessageId = record.streamingAssistantMessageId ? context.insertReasoningMessageBefore(record.streamingAssistantMessageId, event.assistantMessageEvent.delta) : (() => {
34
+ const id = createMessageId(record, "assistant");
35
+ callbacks.appendMessage(sessionId, {
36
+ id,
37
+ role: "assistant",
38
+ content: event.assistantMessageEvent.delta,
39
+ time: formatTime(),
40
+ kind: "reasoning",
41
+ collapsible: true,
42
+ expanded: false
43
+ });
44
+ return id;
45
+ })();
46
+ return;
47
+ }
48
+ callbacks.patchMessage(sessionId, record.streamingReasoningMessageId, {
49
+ appendContent: event.assistantMessageEvent.delta
50
+ });
51
+ return;
52
+ }
53
+ if (event.assistantMessageEvent.type === "text_delta" && record.streamingAssistantMessageId) {
54
+ callbacks.patchMessage(sessionId, record.streamingAssistantMessageId, {
55
+ appendContent: event.assistantMessageEvent.delta
56
+ });
57
+ return;
58
+ }
59
+ if (event.assistantMessageEvent.type === "text_delta") {
60
+ const messageId = createMessageId(record, "assistant");
61
+ record.streamingAssistantMessageId = messageId;
62
+ callbacks.appendMessage(sessionId, {
63
+ id: messageId,
64
+ role: "assistant",
65
+ content: event.assistantMessageEvent.delta,
66
+ time: formatTime()
67
+ });
68
+ }
69
+ return;
70
+ case "message_end":
71
+ if (event.message.role === "assistant") {
72
+ const finalMessage = event.message;
73
+ const content = extractAssistantVisibleText(finalMessage);
74
+ const reasoning = extractAssistantReasoning(finalMessage);
75
+ const messageId = record.streamingAssistantMessageId;
76
+ const reasoningMessageId = record.streamingReasoningMessageId;
77
+ record.streamingAssistantMessageId = undefined;
78
+ record.streamingReasoningMessageId = undefined;
79
+ if (messageId) {
80
+ callbacks.patchMessage(sessionId, messageId, {
81
+ content,
82
+ time: formatTime(finalMessage.timestamp)
83
+ });
84
+ } else if (content) {
85
+ callbacks.appendMessage(sessionId, {
86
+ id: createMessageId(record, "assistant"),
87
+ role: "assistant",
88
+ content,
89
+ time: formatTime(finalMessage.timestamp)
90
+ });
91
+ }
92
+ if (reasoning) {
93
+ if (reasoningMessageId) {
94
+ callbacks.patchMessage(sessionId, reasoningMessageId, {
95
+ content: reasoning,
96
+ time: formatTime(finalMessage.timestamp)
97
+ });
98
+ } else if (messageId) {
99
+ context.insertReasoningMessageBefore(messageId, reasoning);
100
+ } else {
101
+ context.appendReasoningMessage(reasoning);
102
+ }
103
+ }
104
+ if (finalMessage.stopReason === "aborted") {
105
+ context.setRuntimeState(createInterruptedRuntimeState("Interrupted - ready", "The current request was cancelled."));
106
+ } else if (finalMessage.stopReason === "error" && finalMessage.errorMessage) {
107
+ context.applyRecoveryState(finalMessage.errorMessage, "Request failed - ready");
108
+ }
109
+ }
110
+ return;
111
+ case "tool_execution_start":
112
+ {
113
+ const tool = createToolMessageState(event.toolCallId, event.toolName, event.args);
114
+ const messageId = context.appendToolMessage(tool);
115
+ record.toolMessageIds.set(event.toolCallId, messageId);
116
+ record.toolStates.set(event.toolCallId, tool);
117
+ return;
118
+ }
119
+ case "tool_execution_update":
120
+ {
121
+ const messageId = record.toolMessageIds.get(event.toolCallId);
122
+ const tool = record.toolStates.get(event.toolCallId);
123
+ if (!messageId || !tool) {
124
+ return;
125
+ }
126
+ const nextTool = updateToolMessageState(tool, {
127
+ args: event.args,
128
+ output: event.partialResult
129
+ });
130
+ record.toolStates.set(event.toolCallId, nextTool);
131
+ callbacks.patchMessage(sessionId, messageId, {
132
+ tool: nextTool
133
+ });
134
+ return;
135
+ }
136
+ case "tool_execution_end":
137
+ {
138
+ const messageId = record.toolMessageIds.get(event.toolCallId);
139
+ const tool = record.toolStates.get(event.toolCallId);
140
+ record.toolMessageIds.delete(event.toolCallId);
141
+ record.toolStates.delete(event.toolCallId);
142
+ const nextTool = updateToolMessageState(tool ?? createToolMessageState(event.toolCallId, event.toolName, undefined), {
143
+ status: event.isError ? "failed" : "completed",
144
+ output: event.result
145
+ });
146
+ if (messageId) {
147
+ callbacks.patchMessage(sessionId, messageId, {
148
+ tool: nextTool,
149
+ time: formatTime()
150
+ });
151
+ return;
152
+ }
153
+ context.appendToolMessage(nextTool);
154
+ return;
155
+ }
156
+ case "auto_compaction_start":
157
+ context.setRuntimeState(createCompactingRuntimeState(event.reason === "overflow" ? "Compacting after overflow" : "Compacting context"));
158
+ context.appendSystemMessage("Compacting context...");
159
+ return;
160
+ case "auto_compaction_end":
161
+ if (event.errorMessage) {
162
+ context.applyRecoveryState(event.errorMessage, "Compaction failed - ready");
163
+ } else if (event.aborted) {
164
+ context.setRuntimeState(createInterruptedRuntimeState("Compaction cancelled - ready", "You can continue with a new prompt."));
165
+ } else if (event.willRetry) {
166
+ context.setRuntimeState(createRetryingRuntimeState("Retrying after compaction"));
167
+ } else if (record.activePrompts > 0) {
168
+ context.setRuntimeState(createRunningRuntimeState());
169
+ }
170
+ context.appendSystemMessage(event.errorMessage ? `Compaction failed: ${event.errorMessage}` : event.aborted ? "Compaction aborted." : event.result ? "Context compacted." : "Compaction skipped.");
171
+ return;
172
+ case "auto_retry_start":
173
+ context.setRuntimeState(createRetryingRuntimeState(`Retrying (${event.attempt}/${event.maxAttempts})`, event.errorMessage));
174
+ context.appendSystemMessage(`Retrying request (${event.attempt}/${event.maxAttempts}) after error: ${event.errorMessage}`);
175
+ return;
176
+ case "auto_retry_end":
177
+ if (!event.success) {
178
+ const finalError = event.finalError ?? "Retry cancelled";
179
+ context.setRuntimeState(finalError.toLowerCase().includes("cancel") ? createInterruptedRuntimeState("Retry cancelled - ready", finalError) : createErrorRuntimeState("Retry failed - ready", finalError));
180
+ context.appendSystemMessage(`Retry failed: ${finalError}`);
181
+ if (!finalError.toLowerCase().includes("cancel")) {
182
+ const hint = getRuntimeRecoveryHint(finalError);
183
+ if (hint?.nextStep) {
184
+ context.appendSystemMessage(hint.nextStep);
185
+ }
186
+ }
187
+ } else if (record.activePrompts > 0) {
188
+ context.setRuntimeState(createRunningRuntimeState());
189
+ }
190
+ return;
191
+ default:
192
+ return;
193
+ }
194
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createCompactingRuntimeState","createErrorRuntimeState","createInterruptedRuntimeState","createRetryingRuntimeState","createRunningRuntimeState","getRuntimeRecoveryHint","createMessageId","extractAssistantReasoning","extractAssistantVisibleText","extractUserText","formatTime","createToolMessageState","updateToolMessageState","handleAgentSessionEvent","event","context","sessionId","record","callbacks","type","message","role","text","appendMessage","id","content","time","timestamp","streamingAssistantMessageId","undefined","streamingReasoningMessageId","assistantMessageEvent","insertReasoningMessageBefore","delta","kind","collapsible","expanded","patchMessage","appendContent","messageId","finalMessage","reasoning","reasoningMessageId","appendReasoningMessage","stopReason","setRuntimeState","errorMessage","applyRecoveryState","tool","toolCallId","toolName","args","appendToolMessage","toolMessageIds","set","toolStates","get","nextTool","output","partialResult","delete","status","isError","result","reason","appendSystemMessage","aborted","willRetry","activePrompts","attempt","maxAttempts","success","finalError","toLowerCase","includes","hint","nextStep"],"sources":["agent-runtime-events.ts"],"sourcesContent":["import type { AgentSessionEvent } from \"@mariozechner/pi-coding-agent\";\nimport type { AssistantMessage, UserMessage } from \"@mariozechner/pi-ai\";\nimport {\n\tcreateCompactingRuntimeState,\n\tcreateErrorRuntimeState,\n\tcreateInterruptedRuntimeState,\n\tcreateRetryingRuntimeState,\n\tcreateRunningRuntimeState,\n\ttype RuntimeSessionState,\n} from \"./runtime-status.js\";\nimport { getRuntimeRecoveryHint } from \"./runtime-recovery.js\";\nimport type { RuntimeCallbacks, RuntimeSessionRecord } from \"./agent-runtime-types.js\";\nimport {\n\tcreateMessageId,\n\textractAssistantReasoning,\n\textractAssistantVisibleText,\n\textractUserText,\n\tformatTime,\n} from \"./agent-runtime-helpers.js\";\nimport { createToolMessageState, updateToolMessageState, type ToolMessageState } from \"./tool-messages.js\";\n\nexport interface AgentRuntimeEventHandlerContext {\n\tsessionId: string;\n\trecord: RuntimeSessionRecord;\n\tcallbacks: RuntimeCallbacks;\n\tappendToolMessage: (tool: ToolMessageState) => string;\n\tappendReasoningMessage: (content: string) => void;\n\tinsertReasoningMessageBefore: (beforeMessageId: string, content: string) => string;\n\tappendSystemMessage: (content: string) => void;\n\tapplyRecoveryState: (message: string, fallbackLabel: string) => void;\n\tsetRuntimeState: (state: RuntimeSessionState) => void;\n}\n\nexport function handleAgentSessionEvent(\n\tevent: AgentSessionEvent,\n\tcontext: AgentRuntimeEventHandlerContext,\n): void {\n\tconst { sessionId, record, callbacks } = context;\n\n\tswitch (event.type) {\n\t\tcase \"message_start\":\n\t\t\tif (event.message.role === \"user\") {\n\t\t\t\tconst text = extractUserText(event.message as UserMessage);\n\t\t\t\tif (text) {\n\t\t\t\t\tcallbacks.appendMessage(sessionId, {\n\t\t\t\t\t\tid: createMessageId(record, \"user\"),\n\t\t\t\t\t\trole: \"user\",\n\t\t\t\t\t\tcontent: text,\n\t\t\t\t\t\ttime: formatTime((event.message as UserMessage).timestamp),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\trecord.streamingAssistantMessageId = undefined;\n\t\t\t\trecord.streamingReasoningMessageId = undefined;\n\t\t\t}\n\t\t\treturn;\n\n\t\tcase \"message_update\":\n\t\t\tif (event.assistantMessageEvent.type === \"thinking_delta\") {\n\t\t\t\tif (!record.streamingReasoningMessageId) {\n\t\t\t\t\trecord.streamingReasoningMessageId = record.streamingAssistantMessageId\n\t\t\t\t\t\t? context.insertReasoningMessageBefore(\n\t\t\t\t\t\t\t\trecord.streamingAssistantMessageId,\n\t\t\t\t\t\t\t\tevent.assistantMessageEvent.delta,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: (() => {\n\t\t\t\t\t\t\t\tconst id = createMessageId(record, \"assistant\");\n\t\t\t\t\t\t\t\tcallbacks.appendMessage(sessionId, {\n\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\t\t\tcontent: event.assistantMessageEvent.delta,\n\t\t\t\t\t\t\t\t\ttime: formatTime(),\n\t\t\t\t\t\t\t\t\tkind: \"reasoning\",\n\t\t\t\t\t\t\t\t\tcollapsible: true,\n\t\t\t\t\t\t\t\t\texpanded: false,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\treturn id;\n\t\t\t\t\t\t\t})();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcallbacks.patchMessage(sessionId, record.streamingReasoningMessageId, {\n\t\t\t\t\tappendContent: event.assistantMessageEvent.delta,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (event.assistantMessageEvent.type === \"text_delta\" && record.streamingAssistantMessageId) {\n\t\t\t\tcallbacks.patchMessage(sessionId, record.streamingAssistantMessageId, {\n\t\t\t\t\tappendContent: event.assistantMessageEvent.delta,\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.assistantMessageEvent.type === \"text_delta\") {\n\t\t\t\tconst messageId = createMessageId(record, \"assistant\");\n\t\t\t\trecord.streamingAssistantMessageId = messageId;\n\t\t\t\tcallbacks.appendMessage(sessionId, {\n\t\t\t\t\tid: messageId,\n\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\tcontent: event.assistantMessageEvent.delta,\n\t\t\t\t\ttime: formatTime(),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\n\t\tcase \"message_end\":\n\t\t\tif (event.message.role === \"assistant\") {\n\t\t\t\tconst finalMessage = event.message as AssistantMessage;\n\t\t\t\tconst content = extractAssistantVisibleText(finalMessage);\n\t\t\t\tconst reasoning = extractAssistantReasoning(finalMessage);\n\t\t\t\tconst messageId = record.streamingAssistantMessageId;\n\t\t\t\tconst reasoningMessageId = record.streamingReasoningMessageId;\n\t\t\t\trecord.streamingAssistantMessageId = undefined;\n\t\t\t\trecord.streamingReasoningMessageId = undefined;\n\t\t\t\tif (messageId) {\n\t\t\t\t\tcallbacks.patchMessage(sessionId, messageId, {\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttime: formatTime(finalMessage.timestamp),\n\t\t\t\t\t});\n\t\t\t\t} else if (content) {\n\t\t\t\t\tcallbacks.appendMessage(sessionId, {\n\t\t\t\t\t\tid: createMessageId(record, \"assistant\"),\n\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t\ttime: formatTime(finalMessage.timestamp),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (reasoning) {\n\t\t\t\t\tif (reasoningMessageId) {\n\t\t\t\t\t\tcallbacks.patchMessage(sessionId, reasoningMessageId, {\n\t\t\t\t\t\t\tcontent: reasoning,\n\t\t\t\t\t\t\ttime: formatTime(finalMessage.timestamp),\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (messageId) {\n\t\t\t\t\t\tcontext.insertReasoningMessageBefore(messageId, reasoning);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontext.appendReasoningMessage(reasoning);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (finalMessage.stopReason === \"aborted\") {\n\t\t\t\t\tcontext.setRuntimeState(\n\t\t\t\t\t\tcreateInterruptedRuntimeState(\"Interrupted - ready\", \"The current request was cancelled.\"),\n\t\t\t\t\t);\n\t\t\t\t} else if (finalMessage.stopReason === \"error\" && finalMessage.errorMessage) {\n\t\t\t\t\tcontext.applyRecoveryState(finalMessage.errorMessage, \"Request failed - ready\");\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\n\t\tcase \"tool_execution_start\": {\n\t\t\tconst tool = createToolMessageState(event.toolCallId, event.toolName, event.args);\n\t\t\tconst messageId = context.appendToolMessage(tool);\n\t\t\trecord.toolMessageIds.set(event.toolCallId, messageId);\n\t\t\trecord.toolStates.set(event.toolCallId, tool);\n\t\t\treturn;\n\t\t}\n\n\t\tcase \"tool_execution_update\": {\n\t\t\tconst messageId = record.toolMessageIds.get(event.toolCallId);\n\t\t\tconst tool = record.toolStates.get(event.toolCallId);\n\t\t\tif (!messageId || !tool) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst nextTool = updateToolMessageState(tool, {\n\t\t\t\targs: event.args,\n\t\t\t\toutput: event.partialResult,\n\t\t\t});\n\t\t\trecord.toolStates.set(event.toolCallId, nextTool);\n\t\t\tcallbacks.patchMessage(sessionId, messageId, {\n\t\t\t\ttool: nextTool,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tcase \"tool_execution_end\": {\n\t\t\tconst messageId = record.toolMessageIds.get(event.toolCallId);\n\t\t\tconst tool = record.toolStates.get(event.toolCallId);\n\t\t\trecord.toolMessageIds.delete(event.toolCallId);\n\t\t\trecord.toolStates.delete(event.toolCallId);\n\t\t\tconst nextTool = updateToolMessageState(\n\t\t\t\ttool ?? createToolMessageState(event.toolCallId, event.toolName, undefined),\n\t\t\t\t{\n\t\t\t\t\tstatus: event.isError ? \"failed\" : \"completed\",\n\t\t\t\t\toutput: event.result,\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (messageId) {\n\t\t\t\tcallbacks.patchMessage(sessionId, messageId, {\n\t\t\t\t\ttool: nextTool,\n\t\t\t\t\ttime: formatTime(),\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcontext.appendToolMessage(nextTool);\n\t\t\treturn;\n\t\t}\n\n\t\tcase \"auto_compaction_start\":\n\t\t\tcontext.setRuntimeState(\n\t\t\t\tcreateCompactingRuntimeState(\n\t\t\t\t\tevent.reason === \"overflow\" ? \"Compacting after overflow\" : \"Compacting context\",\n\t\t\t\t),\n\t\t\t);\n\t\t\tcontext.appendSystemMessage(\"Compacting context...\");\n\t\t\treturn;\n\n\t\tcase \"auto_compaction_end\":\n\t\t\tif (event.errorMessage) {\n\t\t\t\tcontext.applyRecoveryState(event.errorMessage, \"Compaction failed - ready\");\n\t\t\t} else if (event.aborted) {\n\t\t\t\tcontext.setRuntimeState(\n\t\t\t\t\tcreateInterruptedRuntimeState(\"Compaction cancelled - ready\", \"You can continue with a new prompt.\"),\n\t\t\t\t);\n\t\t\t} else if (event.willRetry) {\n\t\t\t\tcontext.setRuntimeState(createRetryingRuntimeState(\"Retrying after compaction\"));\n\t\t\t} else if (record.activePrompts > 0) {\n\t\t\t\tcontext.setRuntimeState(createRunningRuntimeState());\n\t\t\t}\n\t\t\tcontext.appendSystemMessage(\n\t\t\t\tevent.errorMessage\n\t\t\t\t\t? `Compaction failed: ${event.errorMessage}`\n\t\t\t\t\t: event.aborted\n\t\t\t\t\t\t? \"Compaction aborted.\"\n\t\t\t\t\t\t: event.result\n\t\t\t\t\t\t\t? \"Context compacted.\"\n\t\t\t\t\t\t\t: \"Compaction skipped.\",\n\t\t\t);\n\t\t\treturn;\n\n\t\tcase \"auto_retry_start\":\n\t\t\tcontext.setRuntimeState(\n\t\t\t\tcreateRetryingRuntimeState(\n\t\t\t\t\t`Retrying (${event.attempt}/${event.maxAttempts})`,\n\t\t\t\t\tevent.errorMessage,\n\t\t\t\t),\n\t\t\t);\n\t\t\tcontext.appendSystemMessage(\n\t\t\t\t`Retrying request (${event.attempt}/${event.maxAttempts}) after error: ${event.errorMessage}`,\n\t\t\t);\n\t\t\treturn;\n\n\t\tcase \"auto_retry_end\":\n\t\t\tif (!event.success) {\n\t\t\t\tconst finalError = event.finalError ?? \"Retry cancelled\";\n\t\t\t\tcontext.setRuntimeState(\n\t\t\t\t\tfinalError.toLowerCase().includes(\"cancel\")\n\t\t\t\t\t\t? createInterruptedRuntimeState(\"Retry cancelled - ready\", finalError)\n\t\t\t\t\t\t: createErrorRuntimeState(\"Retry failed - ready\", finalError),\n\t\t\t\t);\n\t\t\t\tcontext.appendSystemMessage(`Retry failed: ${finalError}`);\n\t\t\t\tif (!finalError.toLowerCase().includes(\"cancel\")) {\n\t\t\t\t\tconst hint = getRuntimeRecoveryHint(finalError);\n\t\t\t\t\tif (hint?.nextStep) {\n\t\t\t\t\t\tcontext.appendSystemMessage(hint.nextStep);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (record.activePrompts > 0) {\n\t\t\t\tcontext.setRuntimeState(createRunningRuntimeState());\n\t\t\t}\n\t\t\treturn;\n\n\t\tdefault:\n\t\t\treturn;\n\t}\n}\n"],"mappings":"AAEA,SACCA,4BAA4B,EAC5BC,uBAAuB,EACvBC,6BAA6B,EAC7BC,0BAA0B,EAC1BC,yBAAyB,QAEnB,qBAAqB;AAC5B,SAASC,sBAAsB,QAAQ,uBAAuB;AAE9D,SACCC,eAAe,EACfC,yBAAyB,EACzBC,2BAA2B,EAC3BC,eAAe,EACfC,UAAU,QACJ,4BAA4B;AACnC,SAASC,sBAAsB,EAAEC,sBAAsB,QAA+B,oBAAoB;AAc1G,OAAO,SAASC,uBAAuBA,CACtCC,KAAwB,EACxBC,OAAwC,EACjC;EACP,MAAM;IAAEC,SAAS;IAAEC,MAAM;IAAEC;EAAU,CAAC,GAAGH,OAAO;EAEhD,QAAQD,KAAK,CAACK,IAAI;IACjB,KAAK,eAAe;MACnB,IAAIL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,CAACmD,aAAa,GAAG,CAAC,EAAE;QACpCrD,OAAO,CAAC8B,eAAe,CAACzC,yBAAyB,CAAC,CAAC,CAAC;MACrD;MACA;IAED;MACC;EACF;AACD","ignoreList":[]}
@@ -0,0 +1,117 @@
1
+ import { join } from "node:path";
2
+ let codingAgentRuntimePromise;
3
+ export async function loadCodingAgentRuntime() {
4
+ if (!codingAgentRuntimePromise) {
5
+ codingAgentRuntimePromise = import("@mariozechner/pi-coding-agent").then(module => module);
6
+ }
7
+ return codingAgentRuntimePromise;
8
+ }
9
+ export function formatTime(timestamp) {
10
+ return new Date(timestamp ?? Date.now()).toLocaleTimeString("en-US", {
11
+ hour: "2-digit",
12
+ minute: "2-digit"
13
+ });
14
+ }
15
+ export function createMessageId(record, role) {
16
+ record.sequence += 1;
17
+ return `runtime:${role}:${record.sequence}`;
18
+ }
19
+ function guessReasoningSupport(modelId) {
20
+ const value = modelId.toLowerCase();
21
+ return ["gpt-5", "gpt-4.1", "o1", "o3", "o4", "claude-3-7", "claude-sonnet-4", "claude-opus-4", "gemini-2.5", "reasoner", "thinking"].some(token => value.includes(token));
22
+ }
23
+ function extractTextBlocks(content) {
24
+ return content.map(item => {
25
+ if (item.type === "text" && typeof item.text === "string") {
26
+ return item.text;
27
+ }
28
+ if (item.type === "image") {
29
+ return "[image]";
30
+ }
31
+ if (item.type === "thinking" && typeof item.thinking === "string") {
32
+ return item.thinking;
33
+ }
34
+ return "";
35
+ }).filter(Boolean).join("\n\n");
36
+ }
37
+ function summarizeSkillBlock(text) {
38
+ const match = text.match(/^<skill name="([^"]+)" location="([^"]+)">\n[\s\S]*?\n<\/skill>(?:\n\n([\s\S]+))?$/);
39
+ if (!match) {
40
+ return undefined;
41
+ }
42
+ const skillName = match[1];
43
+ const userMessage = match[3]?.trim();
44
+ return userMessage ? `/skill:${skillName}\n${userMessage}` : `/skill:${skillName}`;
45
+ }
46
+ export function extractUserText(message) {
47
+ const content = typeof message.content === "string" ? message.content : extractTextBlocks(message.content);
48
+ return summarizeSkillBlock(content) ?? content;
49
+ }
50
+ export function extractAssistantVisibleText(message) {
51
+ const text = extractTextBlocks(message.content.filter(item => item.type === "text").map(item => ({
52
+ type: item.type,
53
+ text: item.text
54
+ })));
55
+ if (text) {
56
+ return text;
57
+ }
58
+ if (message.errorMessage) {
59
+ return message.errorMessage;
60
+ }
61
+ return "";
62
+ }
63
+ export function extractAssistantReasoning(message) {
64
+ return extractTextBlocks(message.content.filter(item => item.type === "thinking").map(item => ({
65
+ type: item.type,
66
+ thinking: item.thinking
67
+ })));
68
+ }
69
+ export function formatRuntimeError(error) {
70
+ return error instanceof Error ? error.message : String(error);
71
+ }
72
+ export function formatCompactionResultMessage(result) {
73
+ if (typeof result.tokensBefore === "number" && Number.isFinite(result.tokensBefore)) {
74
+ return `Context compacted from ${result.tokensBefore.toLocaleString("en-US")} tokens.`;
75
+ }
76
+ return "Context compacted.";
77
+ }
78
+ export function cancellationToolOutput(reason) {
79
+ return {
80
+ content: [{
81
+ type: "text",
82
+ text: reason
83
+ }]
84
+ };
85
+ }
86
+ export function toModelDefinition(model) {
87
+ return {
88
+ id: model.id,
89
+ name: model.name,
90
+ reasoning: guessReasoningSupport(model.id),
91
+ input: ["text", "image"],
92
+ cost: {
93
+ input: 0,
94
+ output: 0,
95
+ cacheRead: 0,
96
+ cacheWrite: 0
97
+ },
98
+ contextWindow: 128_000,
99
+ maxTokens: 16_384
100
+ };
101
+ }
102
+ export function getRuntimeSessionDir(cwd, agentDir) {
103
+ const safePath = `--${cwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
104
+ return join(agentDir, "sessions", safePath);
105
+ }
106
+ export function installBeforeToolCallHook(session, handler) {
107
+ if (typeof session.addBeforeToolCall === "function") {
108
+ return session.addBeforeToolCall(handler);
109
+ }
110
+ if (typeof session.agent?.setBeforeToolCall === "function") {
111
+ session.agent.setBeforeToolCall(handler);
112
+ return () => {
113
+ session.agent.setBeforeToolCall?.(undefined);
114
+ };
115
+ }
116
+ throw new Error("The installed pi-coding-agent runtime does not expose a before-tool-call hook API.");
117
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"names":["join","codingAgentRuntimePromise","loadCodingAgentRuntime","then","module","formatTime","timestamp","Date","now","toLocaleTimeString","hour","minute","createMessageId","record","role","sequence","guessReasoningSupport","modelId","value","toLowerCase","some","token","includes","extractTextBlocks","content","map","item","type","text","thinking","filter","Boolean","summarizeSkillBlock","match","undefined","skillName","userMessage","trim","extractUserText","message","extractAssistantVisibleText","errorMessage","extractAssistantReasoning","formatRuntimeError","error","Error","String","formatCompactionResultMessage","result","tokensBefore","Number","isFinite","toLocaleString","cancellationToolOutput","reason","toModelDefinition","model","id","name","reasoning","input","cost","output","cacheRead","cacheWrite","contextWindow","maxTokens","getRuntimeSessionDir","cwd","agentDir","safePath","replace","installBeforeToolCallHook","session","handler","addBeforeToolCall","agent","setBeforeToolCall"],"sources":["agent-runtime-helpers.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport type { AgentSession } from \"@mariozechner/pi-coding-agent\";\nimport type { AssistantMessage, UserMessage } from \"@mariozechner/pi-ai\";\nimport type { DiscoveredModel } from \"../provider-profiles/index.js\";\nimport type {\n\tBeforeToolCallHandler,\n\tCodingAgentRuntime,\n\tProviderModelDefinition,\n\tRuntimeSessionRecord,\n} from \"./agent-runtime-types.js\";\nimport type { ChatMessage } from \"./chat-components.js\";\n\nlet codingAgentRuntimePromise: Promise<CodingAgentRuntime> | undefined;\n\nexport async function loadCodingAgentRuntime(): Promise<CodingAgentRuntime> {\n\tif (!codingAgentRuntimePromise) {\n\t\tcodingAgentRuntimePromise = import(\"@mariozechner/pi-coding-agent\").then((module) => module as CodingAgentRuntime);\n\t}\n\treturn codingAgentRuntimePromise;\n}\n\nexport function formatTime(timestamp?: number): string {\n\treturn new Date(timestamp ?? Date.now()).toLocaleTimeString(\"en-US\", {\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t});\n}\n\nexport function createMessageId(record: RuntimeSessionRecord, role: ChatMessage[\"role\"]): string {\n\trecord.sequence += 1;\n\treturn `runtime:${role}:${record.sequence}`;\n}\n\nfunction guessReasoningSupport(modelId: string): boolean {\n\tconst value = modelId.toLowerCase();\n\treturn [\n\t\t\"gpt-5\",\n\t\t\"gpt-4.1\",\n\t\t\"o1\",\n\t\t\"o3\",\n\t\t\"o4\",\n\t\t\"claude-3-7\",\n\t\t\"claude-sonnet-4\",\n\t\t\"claude-opus-4\",\n\t\t\"gemini-2.5\",\n\t\t\"reasoner\",\n\t\t\"thinking\",\n\t].some((token) => value.includes(token));\n}\n\nfunction extractTextBlocks(content: Array<{ type: string; [key: string]: unknown }>): string {\n\treturn content\n\t\t.map((item) => {\n\t\t\tif (item.type === \"text\" && typeof item.text === \"string\") {\n\t\t\t\treturn item.text;\n\t\t\t}\n\t\t\tif (item.type === \"image\") {\n\t\t\t\treturn \"[image]\";\n\t\t\t}\n\t\t\tif (item.type === \"thinking\" && typeof item.thinking === \"string\") {\n\t\t\t\treturn item.thinking;\n\t\t\t}\n\t\t\treturn \"\";\n\t\t})\n\t\t.filter(Boolean)\n\t\t.join(\"\\n\\n\");\n}\n\nfunction summarizeSkillBlock(text: string): string | undefined {\n\tconst match = text.match(/^<skill name=\"([^\"]+)\" location=\"([^\"]+)\">\\n[\\s\\S]*?\\n<\\/skill>(?:\\n\\n([\\s\\S]+))?$/);\n\tif (!match) {\n\t\treturn undefined;\n\t}\n\n\tconst skillName = match[1];\n\tconst userMessage = match[3]?.trim();\n\treturn userMessage ? `/skill:${skillName}\\n${userMessage}` : `/skill:${skillName}`;\n}\n\nexport function extractUserText(message: UserMessage): string {\n\tconst content =\n\t\ttypeof message.content === \"string\"\n\t\t\t? message.content\n\t\t\t: extractTextBlocks(message.content as unknown as Array<{ type: string; [key: string]: unknown }>);\n\treturn summarizeSkillBlock(content) ?? content;\n}\n\nexport function extractAssistantVisibleText(message: AssistantMessage): string {\n\tconst text = extractTextBlocks(\n\t\tmessage.content\n\t\t\t.filter((item): item is Extract<AssistantMessage[\"content\"][number], { type: \"text\" }> => item.type === \"text\")\n\t\t\t.map((item) => ({ type: item.type, text: item.text })),\n\t);\n\tif (text) {\n\t\treturn text;\n\t}\n\tif (message.errorMessage) {\n\t\treturn message.errorMessage;\n\t}\n\treturn \"\";\n}\n\nexport function extractAssistantReasoning(message: AssistantMessage): string {\n\treturn extractTextBlocks(\n\t\tmessage.content\n\t\t\t.filter((item): item is Extract<AssistantMessage[\"content\"][number], { type: \"thinking\" }> => item.type === \"thinking\")\n\t\t\t.map((item) => ({ type: item.type, thinking: item.thinking })),\n\t);\n}\n\nexport function formatRuntimeError(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nexport function formatCompactionResultMessage(result: { tokensBefore?: number }): string {\n\tif (typeof result.tokensBefore === \"number\" && Number.isFinite(result.tokensBefore)) {\n\t\treturn `Context compacted from ${result.tokensBefore.toLocaleString(\"en-US\")} tokens.`;\n\t}\n\treturn \"Context compacted.\";\n}\n\nexport function cancellationToolOutput(reason: string): { content: Array<{ type: \"text\"; text: string }> } {\n\treturn {\n\t\tcontent: [{ type: \"text\", text: reason }],\n\t};\n}\n\nexport function toModelDefinition(model: DiscoveredModel): ProviderModelDefinition {\n\treturn {\n\t\tid: model.id,\n\t\tname: model.name,\n\t\treasoning: guessReasoningSupport(model.id),\n\t\tinput: [\"text\", \"image\"],\n\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: 128_000,\n\t\tmaxTokens: 16_384,\n\t};\n}\n\nexport function getRuntimeSessionDir(cwd: string, agentDir: string): string {\n\tconst safePath = `--${cwd.replace(/^[/\\\\]/, \"\").replace(/[/\\\\:]/g, \"-\")}--`;\n\treturn join(agentDir, \"sessions\", safePath);\n}\n\nexport function installBeforeToolCallHook(session: AgentSession, handler: BeforeToolCallHandler): () => void {\n\tif (typeof session.addBeforeToolCall === \"function\") {\n\t\treturn session.addBeforeToolCall(handler);\n\t}\n\n\tif (typeof session.agent?.setBeforeToolCall === \"function\") {\n\t\tsession.agent.setBeforeToolCall(handler);\n\t\treturn () => {\n\t\t\tsession.agent.setBeforeToolCall?.(undefined);\n\t\t};\n\t}\n\n\tthrow new Error(\"The installed pi-coding-agent runtime does not expose a before-tool-call hook API.\");\n}\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,WAAW;AAYhC,IAAIC,yBAAkE;AAEtE,OAAO,eAAeC,sBAAsBA,CAAA,EAAgC;EAC3E,IAAI,CAACD,yBAAyB,EAAE;IAC/BA,yBAAyB,GAAG,MAAM,CAAC,+BAA+B,CAAC,CAACE,IAAI,CAAEC,MAAM,IAAKA,MAA4B,CAAC;EACnH;EACA,OAAOH,yBAAyB;AACjC;AAEA,OAAO,SAASI,UAAUA,CAACC,SAAkB,EAAU;EACtD,OAAO,IAAIC,IAAI,CAACD,SAAS,IAAIC,IAAI,CAACC,GAAG,CAAC,CAAC,CAAC,CAACC,kBAAkB,CAAC,OAAO,EAAE;IACpEC,IAAI,EAAE,SAAS;IACfC,MAAM,EAAE;EACT,CAAC,CAAC;AACH;AAEA,OAAO,SAASC,eAAeA,CAACC,MAA4B,EAAEC,IAAyB,EAAU;EAChGD,MAAM,CAACE,QAAQ,IAAI,CAAC;EACpB,OAAO,WAAWD,IAAI,IAAID,MAAM,CAACE,QAAQ,EAAE;AAC5C;AAEA,SAASC,qBAAqBA,CAACC,OAAe,EAAW;EACxD,MAAMC,KAAK,GAAGD,OAAO,CAACE,WAAW,CAAC,CAAC;EACnC,OAAO,CACN,OAAO,EACP,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,UAAU,EACV,UAAU,CACV,CAACC,IAAI,CAAEC,KAAK,IAAKH,KAAK,CAACI,QAAQ,CAACD,KAAK,CAAC,CAAC;AACzC;AAEA,SAASE,iBAAiBA,CAACC,OAAwD,EAAU;EAC5F,OAAOA,OAAO,CACZC,GA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Storage, AgentSession, ModelRegistry } from \"@mariozechner/pi-coding-agent\";\nimport type { ChatMessage } from \"./chat-components.js\";\nimport type { RuntimeSessionState } from \"./runtime-status.js\";\nimport type { TranscriptMessagePatch } from \"./transcript-state.js\";\nimport type { ToolApprovalDecision, ToolApprovalRequest } from \"./tool-approval.js\";\nimport type { ToolMessageState } from \"./tool-messages.js\";\n\nexport interface RuntimeSelection {\n\tprofileId?: string;\n\tmodelId?: string;\n}\n\nexport interface RuntimeCallbacks {\n\tappendMessage(sessionId: string, message: ChatMessage): void;\n\tinsertMessageBefore(sessionId: string, beforeMessageId: string, message: ChatMessage): void;\n\treplaceMessages(sessionId: string, messages: ChatMessage[]): void;\n\tpatchMessage(sessionId: string, messageId: string, patch: TranscriptMessagePatch): void;\n\topenApproval(sessionId: string, request: ToolApprovalRequest): void;\n\tcloseApproval(sessionId: string, requestId: string): void;\n\tupdateRuntimeState(sessionId: string, state: RuntimeSessionState): void;\n\tupdateSessionBinding(sessionId: string, binding: { runtimeSessionFile?: string }): void;\n}\n\nexport interface RuntimeSessionRecord {\n\tsession: AgentSession;\n\tunsubscribe: () => void;\n\tremoveBeforeToolCallHook: () => void;\n\tmodelRegistry: ModelRegistry;\n\tauthStorage: AuthStorage;\n\tactiveProfileId?: string;\n\tactiveModelId?: string;\n\tstreamingAssistantMessageId?: string;\n\tstreamingReasoningMessageId?: string;\n\ttoolMessageIds: Map<string, string>;\n\ttoolStates: Map<string, ToolMessageState>;\n\tactivePrompts: number;\n\truntimeState: RuntimeSessionState;\n\tsequence: number;\n}\n\nexport interface PendingApprovalRecord {\n\tsessionId: string;\n\tresolve: (decision: ToolApprovalDecision) => void;\n}\n\nexport interface RuntimeSessionBinding {\n\truntimeSessionFile?: string;\n}\n\nexport type BeforeToolCallHandler = (\n\tcontext: {\n\t\ttoolCall: { id: string; name: string; arguments: unknown };\n\t\targs: unknown;\n\t},\n\tsignal?: AbortSignal,\n) => Promise<{ block?: boolean; reason?: string } | undefined>;\n\nexport type ProviderRegistrationConfig = Parameters<ModelRegistry[\"registerProvider\"]>[1];\nexport type ProviderModelDefinition = NonNullable<ProviderRegistrationConfig[\"models\"]>[number];\n\nexport type CodingAgentRuntime = {\n\tAuthStorage: typeof import(\"@mariozechner/pi-coding-agent\").AuthStorage;\n\tcreateAgentSession: typeof import(\"@mariozechner/pi-coding-agent\").createAgentSession;\n\tModelRegistry: typeof import(\"@mariozechner/pi-coding-agent\").ModelRegistry;\n\tSessionManager: typeof import(\"@mariozechner/pi-coding-agent\").SessionManager;\n\tSettingsManager: typeof import(\"@mariozechner/pi-coding-agent\").SettingsManager;\n};\n"],"mappings":"","ignoreList":[]}