@posthog/wizard 2.77.0 → 2.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -26
- package/dist/{add-mcp-server-to-clients-BnRyE4pw.js → add-mcp-server-to-clients-amlJWW7W.js} +6 -5
- package/dist/{add-mcp-server-to-clients-BnRyE4pw.js.map → add-mcp-server-to-clients-amlJWW7W.js.map} +1 -1
- package/dist/agent-CNrEC-9v.js +3184 -0
- package/dist/agent-CNrEC-9v.js.map +1 -0
- package/dist/{agent-interface-Avtr_5M5.js → agent-interface-BXvmAm4c.js} +462 -385
- package/dist/agent-interface-BXvmAm4c.js.map +1 -0
- package/dist/{agent-prompt-loader-CHixNPgY.js → agent-prompt-loader-DiKUbhi_.js} +6 -6
- package/dist/agent-prompt-loader-DiKUbhi_.js.map +1 -0
- package/dist/analytics-DxwRi2Hf.js +2 -0
- package/dist/{analytics-C67F2vee.js → analytics-VRYdebXW.js} +10 -6
- package/dist/analytics-VRYdebXW.js.map +1 -0
- package/dist/{api-Dj1yabTj.js → api-DGuJTzjr.js} +4 -17
- package/dist/api-DGuJTzjr.js.map +1 -0
- package/dist/bin.js +415 -70
- package/dist/bin.js.map +1 -1
- package/dist/{bounded-fs-CWRYuLAn.js → bounded-fs-Cpn129A4.js} +4 -4
- package/dist/bounded-fs-Cpn129A4.js.map +1 -0
- package/dist/check-screens.tsx +1 -1
- package/dist/{ci-install-CvXL5h13.js → ci-install-BPA6gzEq.js} +6 -5
- package/dist/ci-install-BPA6gzEq.js.map +1 -0
- package/dist/constants-CuJfQEcC.js +260 -0
- package/dist/constants-CuJfQEcC.js.map +1 -0
- package/dist/{debug-CziFS0cA.js → debug-B9k4ideV.js} +1 -1
- package/dist/debug-Cj-8vfXY.js +171 -0
- package/dist/debug-Cj-8vfXY.js.map +1 -0
- package/dist/{defaults-4c4YwTmW.js → defaults-C6J7yL4O.js} +1 -1
- package/dist/{defaults-4c4YwTmW.js.map → defaults-C6J7yL4O.js.map} +1 -1
- package/dist/endpoints-DnIX0pZH.js +108 -0
- package/dist/endpoints-DnIX0pZH.js.map +1 -0
- package/dist/{env-api-key-BZ5wE3Y4.js → env-api-key-BWdKpGEr.js} +3 -3
- package/dist/env-api-key-BWdKpGEr.js.map +1 -0
- package/dist/{environment-BEvsey6i.js → environment-DZYUSCpV.js} +6 -6
- package/dist/environment-DZYUSCpV.js.map +1 -0
- package/dist/{errors-BoJvrdw8.js → errors-ddDE6MbA.js} +27 -76
- package/dist/errors-ddDE6MbA.js.map +1 -0
- package/dist/{file-BoD3REGB.js → file-dEhr-l3n.js} +3 -3
- package/dist/file-dEhr-l3n.js.map +1 -0
- package/dist/{file-watcher-BPFazvG_.js → file-watcher-CPM-Nn9L.js} +2 -2
- package/dist/{file-watcher-BPFazvG_.js.map → file-watcher-CPM-Nn9L.js.map} +1 -1
- package/dist/{gateway-session-xPFv6p5c.js → gateway-CVU1G0H3.js} +205 -20
- package/dist/gateway-CVU1G0H3.js.map +1 -0
- package/dist/generate-version.cjs +1 -1
- package/dist/{headless-ui-CsmQrDIl.js → headless-ui-pY2xB5ug.js} +13 -2
- package/dist/headless-ui-pY2xB5ug.js.map +1 -0
- package/dist/{interactive-Dej-sxvR.js → interactive-BOGlinZe.js} +2 -2
- package/dist/interactive-BOGlinZe.js.map +1 -0
- package/dist/{local-dev-DPZiIPCK.js → local-dev-McsurOC-.js} +2 -2
- package/dist/local-dev-McsurOC-.js.map +1 -0
- package/dist/logging-ui-CUxNYF2t.js +226 -0
- package/dist/logging-ui-CUxNYF2t.js.map +1 -0
- package/dist/mcp-JcsBBnWv.js +97 -0
- package/dist/mcp-JcsBBnWv.js.map +1 -0
- package/dist/{mcp-prompt-streaming-BU_kuur_.js → mcp-prompt-streaming-B-p_Pvb2.js} +7 -6
- package/dist/mcp-prompt-streaming-B-p_Pvb2.js.map +1 -0
- package/dist/{mint-failure-BrleGqMd.js → mint-failure-CZFZpHpW.js} +749 -130
- package/dist/mint-failure-CZFZpHpW.js.map +1 -0
- package/dist/models-DnAY67Lg.js +83 -0
- package/dist/models-DnAY67Lg.js.map +1 -0
- package/dist/{non-interactive-DcOjH2fw.js → non-interactive-DR1CWXY1.js} +3 -3
- package/dist/non-interactive-DR1CWXY1.js.map +1 -0
- package/dist/oauth-session-CQTFOk-I.js +74 -0
- package/dist/oauth-session-CQTFOk-I.js.map +1 -0
- package/dist/{orchestrator-tools-DXwr8Sp3.js → orchestrator-tools-CBdt-SXO.js} +4 -4
- package/dist/orchestrator-tools-CBdt-SXO.js.map +1 -0
- package/dist/{package-json-xt3eeyBI.js → package-json-DY70kkNp.js} +2 -2
- package/dist/package-json-DY70kkNp.js.map +1 -0
- package/dist/{pi-mY8I2XkG.js → pi-BtqcLX3y.js} +444 -81
- package/dist/pi-BtqcLX3y.js.map +1 -0
- package/dist/{playground-CDUUKLkC.js → playground-Dz-ZVjBk.js} +11 -7
- package/dist/playground-Dz-ZVjBk.js.map +1 -0
- package/dist/{posthog-Hc_-9wrr.js → posthog-6Uqw_Eux.js} +9 -4
- package/dist/posthog-6Uqw_Eux.js.map +1 -0
- package/dist/{provisioning-xfdjhFtA.js → provisioning-Zf7yPcEs.js} +6 -5
- package/dist/provisioning-Zf7yPcEs.js.map +1 -0
- package/dist/{queue-tools-C8y_xZJi.js → queue-tools-B7_aCyd-.js} +7 -86
- package/dist/queue-tools-B7_aCyd-.js.map +1 -0
- package/dist/{registry-DTmREJ-f.js → registry-B6iLGorH.js} +307 -48
- package/dist/registry-B6iLGorH.js.map +1 -0
- package/dist/run-agent-legacy-6WcYMaR9.js +3541 -0
- package/dist/run-agent-legacy-6WcYMaR9.js.map +1 -0
- package/dist/{security-Dw2oFJjP.js → security-lkBwWbrK.js} +17 -7
- package/dist/security-lkBwWbrK.js.map +1 -0
- package/dist/{setup-utils-fjJTBhaB.js → setup-utils-dCViCC6s.js} +47 -19
- package/dist/setup-utils-dCViCC6s.js.map +1 -0
- package/dist/smoke-test.sh +1 -1
- package/dist/{start-tui-UNe2xQ0U.js → start-tui-oCWMgsDP.js} +40 -46
- package/dist/start-tui-oCWMgsDP.js.map +1 -0
- package/dist/{steps-C2yqOk_h.js → steps-gx0Pq4I4.js} +7 -7
- package/dist/{steps-C2yqOk_h.js.map → steps-gx0Pq4I4.js.map} +1 -1
- package/dist/{store-Bic4Cr3L.js → store-xYy_6Ruv.js} +19 -29
- package/dist/store-xYy_6Ruv.js.map +1 -0
- package/dist/{subagent-Dz41vV9j.js → subagent-Bfy0sfhU.js} +8 -3
- package/dist/subagent-Bfy0sfhU.js.map +1 -0
- package/dist/{task-5-fw_Vw3.js → task-BOfw7GPc.js} +124 -36
- package/dist/task-BOfw7GPc.js.map +1 -0
- package/dist/{task-stream-dVzl6b_q.js → task-stream-kYlm9qd0.js} +47 -17
- package/dist/task-stream-kYlm9qd0.js.map +1 -0
- package/dist/{tasks-D1c2z1aw.js → tasks-Bbv_lOBG.js} +17 -13
- package/dist/tasks-Bbv_lOBG.js.map +1 -0
- package/dist/{telemetry-BRnxBRWK.js → telemetry-Bpv-Mh5B.js} +5 -5
- package/dist/telemetry-Bpv-Mh5B.js.map +1 -0
- package/dist/{terminal-9bvRa4Qt.js → terminal-D07EQ2y0.js} +41 -76
- package/dist/terminal-D07EQ2y0.js.map +1 -0
- package/dist/{tools-Dp6i9k70.js → tools-Cc41af5W.js} +11 -11
- package/dist/tools-Cc41af5W.js.map +1 -0
- package/dist/ui-CGXtC7Vn.js +15 -0
- package/dist/ui-CGXtC7Vn.js.map +1 -0
- package/dist/version-Cadof0Z_.js +6 -0
- package/dist/version-Cadof0Z_.js.map +1 -0
- package/dist/warlock-smoke-test.ts +2 -2
- package/dist/{wizard-abort-lE6umflt.js → wizard-abort-HDbP3YcS.js} +23 -20
- package/dist/wizard-abort-HDbP3YcS.js.map +1 -0
- package/dist/wizard-abort-Y-Ip2K4z.js +3 -0
- package/dist/{wizard-session-FSJCkTcP.js → wizard-session-2w4Ru-Wz.js} +12 -16
- package/dist/wizard-session-2w4Ru-Wz.js.map +1 -0
- package/dist/wizard-session-DGaUHOF3.js +2 -0
- package/dist/wizard-ui-DoyOZxK8.js +16 -0
- package/dist/wizard-ui-DoyOZxK8.js.map +1 -0
- package/dist/yara-hooks-B49RIk5d.js +2 -0
- package/dist/{yara-hooks-BTNJ6MGW.js → yara-hooks-DCfROpZt.js} +19 -68
- package/dist/yara-hooks-DCfROpZt.js.map +1 -0
- package/package.json +2 -1
- package/dist/agent-interface-Avtr_5M5.js.map +0 -1
- package/dist/agent-prompt-loader-CHixNPgY.js.map +0 -1
- package/dist/agent-runner-COOIUJCP.js +0 -6188
- package/dist/agent-runner-COOIUJCP.js.map +0 -1
- package/dist/analytics-C67F2vee.js.map +0 -1
- package/dist/analytics-CJA1uLlk.js +0 -2
- package/dist/api-Dj1yabTj.js.map +0 -1
- package/dist/bounded-fs-CWRYuLAn.js.map +0 -1
- package/dist/ci-install-CvXL5h13.js.map +0 -1
- package/dist/debug-B4kzIZPi.js +0 -754
- package/dist/debug-B4kzIZPi.js.map +0 -1
- package/dist/env-api-key-BZ5wE3Y4.js.map +0 -1
- package/dist/environment-BEvsey6i.js.map +0 -1
- package/dist/errors-BoJvrdw8.js.map +0 -1
- package/dist/file-BoD3REGB.js.map +0 -1
- package/dist/gateway-session-C118uACz.js +0 -2
- package/dist/gateway-session-xPFv6p5c.js.map +0 -1
- package/dist/headless-ui-CsmQrDIl.js.map +0 -1
- package/dist/interactive-Dej-sxvR.js.map +0 -1
- package/dist/local-dev-DPZiIPCK.js.map +0 -1
- package/dist/mcp-Cbuw_xss.js +0 -64
- package/dist/mcp-Cbuw_xss.js.map +0 -1
- package/dist/mcp-prompt-streaming-BU_kuur_.js.map +0 -1
- package/dist/mint-failure-BrleGqMd.js.map +0 -1
- package/dist/non-interactive-DcOjH2fw.js.map +0 -1
- package/dist/orchestrator-tools-DXwr8Sp3.js.map +0 -1
- package/dist/package-json-xt3eeyBI.js.map +0 -1
- package/dist/package-manager-DR23m5Jg.js +0 -290
- package/dist/package-manager-DR23m5Jg.js.map +0 -1
- package/dist/pi-mY8I2XkG.js.map +0 -1
- package/dist/playground-CDUUKLkC.js.map +0 -1
- package/dist/posthog-Hc_-9wrr.js.map +0 -1
- package/dist/provisioning-xfdjhFtA.js.map +0 -1
- package/dist/queue-tools-C8y_xZJi.js.map +0 -1
- package/dist/registry-DTmREJ-f.js.map +0 -1
- package/dist/security-Dw2oFJjP.js.map +0 -1
- package/dist/setup-utils-fjJTBhaB.js.map +0 -1
- package/dist/start-tui-UNe2xQ0U.js.map +0 -1
- package/dist/store-Bic4Cr3L.js.map +0 -1
- package/dist/subagent-Dz41vV9j.js.map +0 -1
- package/dist/task-5-fw_Vw3.js.map +0 -1
- package/dist/task-stream-dVzl6b_q.js.map +0 -1
- package/dist/tasks-D1c2z1aw.js.map +0 -1
- package/dist/telemetry-BRnxBRWK.js.map +0 -1
- package/dist/terminal-9bvRa4Qt.js.map +0 -1
- package/dist/tools-Dp6i9k70.js.map +0 -1
- package/dist/wizard-abort-CAcInAxg.js +0 -2
- package/dist/wizard-abort-lE6umflt.js.map +0 -1
- package/dist/wizard-session-CYvyYnti.js +0 -2
- package/dist/wizard-session-FSJCkTcP.js.map +0 -1
- package/dist/yara-hooks-BTNJ6MGW.js.map +0 -1
- package/dist/yara-hooks-CFY4pGcW.js +0 -2
|
@@ -1,11 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as getLogFilePath,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { s as ErrorCodes, t as classifyRunFailure } from "./errors-ddDE6MbA.js";
|
|
2
|
+
import { a as getLogFilePath, s as logToFile } from "./debug-Cj-8vfXY.js";
|
|
3
|
+
import { t as VERSION } from "./version-Cadof0Z_.js";
|
|
4
|
+
import { Q as WIZARD_USER_AGENT, Y as WIZARD_REMARK_EVENT_NAME } from "./constants-CuJfQEcC.js";
|
|
5
|
+
import { n as analytics } from "./analytics-VRYdebXW.js";
|
|
6
|
+
import { n as currentAccessToken } from "./oauth-session-CQTFOk-I.js";
|
|
7
|
+
import { c as REMARK_INSTRUCTION, f as gatewayAuth, o as withGatewayRemint, r as buildGatewayProvider, s as AgentSignals, t as GATEWAY_PROVIDER } from "./gateway-CVU1G0H3.js";
|
|
8
|
+
import { g as assembleCommandments, p as AgentOutputSignals } from "./agent-interface-BXvmAm4c.js";
|
|
6
9
|
import fs from "fs";
|
|
7
10
|
import path from "path";
|
|
8
|
-
|
|
11
|
+
function appendStatus(messages, message) {
|
|
12
|
+
if (messages.length > 0 && messages[messages.length - 1] === message) return messages;
|
|
13
|
+
return [...messages.slice(-9), message];
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/agent/runner/shared/progress-collector.ts
|
|
17
|
+
/**
|
|
18
|
+
* The agent's own record of what it reported.
|
|
19
|
+
*
|
|
20
|
+
* `runAgent` accumulates its final `RunSnapshot` here, independently of any
|
|
21
|
+
* observer, so a missing or throwing `onProgress` never makes the result
|
|
22
|
+
* incomplete. The emitter wraps the caller's callback: it applies the event
|
|
23
|
+
* here first, then hands a copy to the observer, and logs rather than
|
|
24
|
+
* propagates anything the observer throws.
|
|
25
|
+
*/
|
|
26
|
+
function createProgressCollector(onProgress) {
|
|
27
|
+
const snapshot = {
|
|
28
|
+
tasks: [],
|
|
29
|
+
statusMessages: [],
|
|
30
|
+
usage: {
|
|
31
|
+
inputTokens: 0,
|
|
32
|
+
outputTokens: 0,
|
|
33
|
+
cacheReadTokens: 0,
|
|
34
|
+
cacheCreationTokens: 0
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const apply = (event) => {
|
|
38
|
+
switch (event.kind) {
|
|
39
|
+
case "tasks":
|
|
40
|
+
snapshot.tasks = event.tasks.map((t) => ({ ...t }));
|
|
41
|
+
break;
|
|
42
|
+
case "status":
|
|
43
|
+
snapshot.statusMessages = appendStatus(snapshot.statusMessages, event.message);
|
|
44
|
+
break;
|
|
45
|
+
case "stage":
|
|
46
|
+
snapshot.stage = event.stage;
|
|
47
|
+
break;
|
|
48
|
+
case "url":
|
|
49
|
+
if (event.which === "dashboard") snapshot.dashboardUrl = event.url;
|
|
50
|
+
else snapshot.notebookUrl = event.url;
|
|
51
|
+
break;
|
|
52
|
+
case "usage":
|
|
53
|
+
snapshot.usage.inputTokens += event.delta.inputTokens;
|
|
54
|
+
snapshot.usage.outputTokens += event.delta.outputTokens;
|
|
55
|
+
snapshot.usage.cacheReadTokens += event.delta.cacheReadTokens;
|
|
56
|
+
snapshot.usage.cacheCreationTokens += event.delta.cacheCreationTokens;
|
|
57
|
+
break;
|
|
58
|
+
case "finalCost":
|
|
59
|
+
snapshot.finalCostUsd = event.usd;
|
|
60
|
+
break;
|
|
61
|
+
case "handoff":
|
|
62
|
+
snapshot.handoffText = event.text;
|
|
63
|
+
break;
|
|
64
|
+
default: break;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const emit = (event) => {
|
|
68
|
+
apply(event);
|
|
69
|
+
if (!onProgress) return;
|
|
70
|
+
try {
|
|
71
|
+
const observed = onProgress(structuredClone(event));
|
|
72
|
+
if (observed && typeof observed.then === "function") Promise.resolve(observed).catch((error) => {
|
|
73
|
+
try {
|
|
74
|
+
logToFile(`[agent] progress observer rejected on ${event.kind}:`, error);
|
|
75
|
+
} catch {}
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
try {
|
|
79
|
+
logToFile(`[agent] progress observer threw on ${event.kind}:`, error instanceof Error ? error.message : error);
|
|
80
|
+
} catch {}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
emit,
|
|
85
|
+
snapshot: () => ({
|
|
86
|
+
...snapshot,
|
|
87
|
+
tasks: snapshot.tasks.map((t) => ({ ...t })),
|
|
88
|
+
statusMessages: [...snapshot.statusMessages],
|
|
89
|
+
usage: { ...snapshot.usage }
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** The run spinner as a progress emitter. One per run, like `getUI().spinner()`. */
|
|
94
|
+
function createEmitSpinner(emit) {
|
|
95
|
+
return {
|
|
96
|
+
start: (message) => emit({
|
|
97
|
+
kind: "spinner",
|
|
98
|
+
action: "start",
|
|
99
|
+
message
|
|
100
|
+
}),
|
|
101
|
+
stop: (message) => emit({
|
|
102
|
+
kind: "spinner",
|
|
103
|
+
action: "stop",
|
|
104
|
+
message
|
|
105
|
+
}),
|
|
106
|
+
message: (message) => emit({
|
|
107
|
+
kind: "spinner",
|
|
108
|
+
action: "message",
|
|
109
|
+
message
|
|
110
|
+
})
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** `WizardUI.log` as a progress emitter. */
|
|
114
|
+
function createEmitLog(emit) {
|
|
115
|
+
return {
|
|
116
|
+
info: (message) => emit({
|
|
117
|
+
kind: "log",
|
|
118
|
+
level: "info",
|
|
119
|
+
message
|
|
120
|
+
}),
|
|
121
|
+
warn: (message) => emit({
|
|
122
|
+
kind: "log",
|
|
123
|
+
level: "warn",
|
|
124
|
+
message
|
|
125
|
+
}),
|
|
126
|
+
error: (message) => emit({
|
|
127
|
+
kind: "log",
|
|
128
|
+
level: "error",
|
|
129
|
+
message
|
|
130
|
+
}),
|
|
131
|
+
success: (message) => emit({
|
|
132
|
+
kind: "log",
|
|
133
|
+
level: "success",
|
|
134
|
+
message
|
|
135
|
+
}),
|
|
136
|
+
step: (message) => emit({
|
|
137
|
+
kind: "log",
|
|
138
|
+
level: "step",
|
|
139
|
+
message
|
|
140
|
+
})
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/agent/aio-capture.ts
|
|
9
145
|
/**
|
|
10
146
|
* aio-capture — mirror wizard LLM calls into the authenticated project's
|
|
11
147
|
* AI Observability tab as `$ai_generation` events. Gated on `--capture-aio`
|
|
@@ -35,7 +171,8 @@ const noop = (_) => void 0;
|
|
|
35
171
|
const NOOP = {
|
|
36
172
|
setInitialPrompt: noop,
|
|
37
173
|
captureFromAnthropicSDKMessage: noop,
|
|
38
|
-
captureFromPiMessageEndEvent: noop
|
|
174
|
+
captureFromPiMessageEndEvent: noop,
|
|
175
|
+
finishPiRun: noop
|
|
39
176
|
};
|
|
40
177
|
function createAioCapture(args) {
|
|
41
178
|
if (!args.enabled || !args.projectApiKey || !args.apiHost) return NOOP;
|
|
@@ -139,7 +276,7 @@ function createAioCapture(args) {
|
|
|
139
276
|
cacheCreationTokens: e.message.usage?.cache_creation_input_tokens,
|
|
140
277
|
latencyMs,
|
|
141
278
|
generationId: e.message.id,
|
|
142
|
-
isError:
|
|
279
|
+
isError: e.message.stopReason === "error" || e.message.stopReason === "aborted"
|
|
143
280
|
};
|
|
144
281
|
};
|
|
145
282
|
return {
|
|
@@ -191,15 +328,17 @@ function createAioCapture(args) {
|
|
|
191
328
|
});
|
|
192
329
|
lastAssistantContent = turn.outputChoices;
|
|
193
330
|
}
|
|
194
|
-
if (e?.type === "agent_end" && !e.willRetry) sendTraceEnd({ isError: false });
|
|
195
331
|
} catch (err) {
|
|
196
332
|
logToFile(`[aio-capture] pi compose failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
197
333
|
}
|
|
334
|
+
},
|
|
335
|
+
finishPiRun(isError) {
|
|
336
|
+
sendTraceEnd({ isError });
|
|
198
337
|
}
|
|
199
338
|
};
|
|
200
339
|
}
|
|
201
340
|
//#endregion
|
|
202
|
-
//#region src/
|
|
341
|
+
//#region src/agent/runner/harness/pi/completion.ts
|
|
203
342
|
/** Which completion guard should fail a pi run, or undefined for a clean finish. */
|
|
204
343
|
function completionFailure(args) {
|
|
205
344
|
if (args.toolCalls === 0) return "WIZARD_NO_PROGRESS";
|
|
@@ -220,7 +359,61 @@ function runErrorType(message) {
|
|
|
220
359
|
return "WIZARD_API_ERROR";
|
|
221
360
|
}
|
|
222
361
|
//#endregion
|
|
223
|
-
//#region src/
|
|
362
|
+
//#region src/agent/runner/harness/pi/cancellation.ts
|
|
363
|
+
/** Bind a host signal to Pi's abort-and-wait-for-idle operation. */
|
|
364
|
+
function bindPiCancellation(signal, session, onAbortError) {
|
|
365
|
+
let abortPromise;
|
|
366
|
+
const onAbort = () => {
|
|
367
|
+
abortPromise ??= Promise.resolve().then(() => session.abort()).catch((error) => {
|
|
368
|
+
try {
|
|
369
|
+
onAbortError?.(error);
|
|
370
|
+
} catch {}
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
374
|
+
if (signal?.aborted) onAbort();
|
|
375
|
+
return { async settle() {
|
|
376
|
+
signal?.removeEventListener("abort", onAbort);
|
|
377
|
+
await abortPromise;
|
|
378
|
+
} };
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/agent/runner/harness/pi/structured-output.ts
|
|
382
|
+
/** Apply the output contract at the provider boundary on every agent turn. */
|
|
383
|
+
function structuredOutputExtension(schema, api) {
|
|
384
|
+
return (pi) => {
|
|
385
|
+
pi.on("before_provider_request", (event) => {
|
|
386
|
+
const payload = event.payload;
|
|
387
|
+
const format = {
|
|
388
|
+
type: "json_schema",
|
|
389
|
+
schema
|
|
390
|
+
};
|
|
391
|
+
switch (api) {
|
|
392
|
+
case "anthropic-messages": return {
|
|
393
|
+
...payload,
|
|
394
|
+
output_config: {
|
|
395
|
+
...payload.output_config,
|
|
396
|
+
format
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
case "openai-responses": return {
|
|
400
|
+
...payload,
|
|
401
|
+
text: {
|
|
402
|
+
...payload.text,
|
|
403
|
+
format: {
|
|
404
|
+
...format,
|
|
405
|
+
name: "wizard_result",
|
|
406
|
+
strict: true
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
case "openai-completions": throw new Error("Structured output is not supported on Chat Completions");
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/agent/runner/harness/pi/index.ts
|
|
224
417
|
/**
|
|
225
418
|
* The `pi` backend — the challenger. Drives pi.dev's coding agent
|
|
226
419
|
* (`@earendil-works/pi-coding-agent`) against the PostHog LLM gateway, behind
|
|
@@ -303,23 +496,39 @@ function withMode(tool, mode) {
|
|
|
303
496
|
tool.executionMode = mode;
|
|
304
497
|
return tool;
|
|
305
498
|
}
|
|
306
|
-
/**
|
|
307
|
-
|
|
499
|
+
/**
|
|
500
|
+
* The text blocks of a pi AgentMessage (content is text/image blocks). A
|
|
501
|
+
* Responses model can send several message items in one turn, commentary
|
|
502
|
+
* before its answer, and each becomes its own block.
|
|
503
|
+
*/
|
|
504
|
+
function textBlocks(message) {
|
|
308
505
|
const content = message?.content;
|
|
309
|
-
if (typeof content === "string") return content;
|
|
506
|
+
if (typeof content === "string") return [content];
|
|
310
507
|
if (Array.isArray(content)) return content.filter((c) => {
|
|
311
508
|
const block = c;
|
|
312
509
|
return block?.type === "text" && typeof block.text === "string";
|
|
313
|
-
}).map((c) => c.text)
|
|
314
|
-
return
|
|
510
|
+
}).map((c) => c.text);
|
|
511
|
+
return [];
|
|
512
|
+
}
|
|
513
|
+
/** Pull plain text out of a pi AgentMessage. */
|
|
514
|
+
function extractText(message) {
|
|
515
|
+
return textBlocks(message).join("");
|
|
315
516
|
}
|
|
316
517
|
/**
|
|
317
518
|
* Surface `[DASHBOARD_URL]` / `[NOTEBOOK_URL]` markers the agent prints (after
|
|
318
519
|
* the MCP creates them) into the outro link, mirroring the anthropic path's
|
|
319
520
|
* signal parsing (#9). The marker carries the URL the MCP returned.
|
|
320
521
|
*/
|
|
321
|
-
function applyOutroMarkers(textBlock) {
|
|
322
|
-
const markers = [[AgentSignals.DASHBOARD_URL, (url) =>
|
|
522
|
+
function applyOutroMarkers(textBlock, emit) {
|
|
523
|
+
const markers = [[AgentSignals.DASHBOARD_URL, (url) => emit({
|
|
524
|
+
kind: "url",
|
|
525
|
+
which: "dashboard",
|
|
526
|
+
url
|
|
527
|
+
})], [AgentSignals.NOTEBOOK_URL, (url) => emit({
|
|
528
|
+
kind: "url",
|
|
529
|
+
which: "notebook",
|
|
530
|
+
url
|
|
531
|
+
})]];
|
|
323
532
|
for (const [marker, apply] of markers) {
|
|
324
533
|
const idx = textBlock.indexOf(marker);
|
|
325
534
|
if (idx === -1) continue;
|
|
@@ -351,21 +560,31 @@ function hasOpenTasks(store) {
|
|
|
351
560
|
const piBackend = {
|
|
352
561
|
name: "pi",
|
|
353
562
|
async run(inputs) {
|
|
354
|
-
|
|
563
|
+
if (inputs.signal?.aborted) return {
|
|
564
|
+
kind: "abort",
|
|
565
|
+
classification: "WIZARD_ABORT",
|
|
566
|
+
message: "Agent run cancelled"
|
|
567
|
+
};
|
|
568
|
+
const { config: runConfig, input, boot, emit, prompt, spinner, structured } = inputs;
|
|
569
|
+
const config = runConfig.run;
|
|
355
570
|
const modelId = inputs.model;
|
|
571
|
+
const log = createEmitLog(emit);
|
|
356
572
|
const capture = createAioCapture({
|
|
357
|
-
enabled:
|
|
573
|
+
enabled: input.flags.captureAio,
|
|
358
574
|
projectApiKey: boot.credentials.projectApiKey,
|
|
359
575
|
apiHost: boot.credentials.host.apiHost,
|
|
360
576
|
runTags: boot.wizardMetadata
|
|
361
577
|
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
578
|
+
if (!structured) {
|
|
579
|
+
log.step("Initializing Wizard agent...");
|
|
580
|
+
log.step(`Verbose logs: ${getLogFilePath()}`);
|
|
581
|
+
log.success("Agent initialized. Let's get cooking!");
|
|
582
|
+
}
|
|
365
583
|
spinner.start(config.spinnerMessage ?? "Customizing your PostHog setup...");
|
|
366
584
|
const startTime = Date.now();
|
|
367
585
|
const signals = new AgentOutputSignals();
|
|
368
586
|
let assistantTurns = 0;
|
|
587
|
+
let lastAssistantText = "";
|
|
369
588
|
let toolCalls = 0;
|
|
370
589
|
const runDurations = () => {
|
|
371
590
|
const durationMs = Date.now() - startTime;
|
|
@@ -379,9 +598,33 @@ const piBackend = {
|
|
|
379
598
|
...runDurations(),
|
|
380
599
|
model: modelId
|
|
381
600
|
});
|
|
601
|
+
const timedOutResult = (timeoutMs) => {
|
|
602
|
+
spinner.stop("Agent run timed out");
|
|
603
|
+
captureAborted("WIZARD_AGENTIC_DETECTION_TIMEOUT");
|
|
604
|
+
return {
|
|
605
|
+
kind: "failure",
|
|
606
|
+
classification: "WIZARD_AGENTIC_DETECTION_TIMEOUT",
|
|
607
|
+
message: `Agent run timed out after ${timeoutMs / 1e3}s`
|
|
608
|
+
};
|
|
609
|
+
};
|
|
610
|
+
let mcpCleanup;
|
|
611
|
+
let aioFailed = true;
|
|
612
|
+
let cancellation;
|
|
613
|
+
let timedOut = false;
|
|
614
|
+
let timeoutAbort;
|
|
615
|
+
let securityState;
|
|
616
|
+
const yaraViolationResult = () => {
|
|
617
|
+
spinner.stop("Security violation detected");
|
|
618
|
+
logToFile(`[pi] terminated: YARA violation (blocked ${securityState?.blockedCount} call(s))`);
|
|
619
|
+
captureAborted("WIZARD_YARA_VIOLATION");
|
|
620
|
+
return {
|
|
621
|
+
kind: "failure",
|
|
622
|
+
classification: "WIZARD_YARA_VIOLATION"
|
|
623
|
+
};
|
|
624
|
+
};
|
|
382
625
|
try {
|
|
383
626
|
const { createAgentSession, DefaultResourceLoader, SessionManager, AuthStorage, ModelRegistry, getAgentDir, createLsToolDefinition, createFindToolDefinition, createGrepToolDefinition, createBashToolDefinition, createReadToolDefinition, createEditToolDefinition, createWriteToolDefinition } = await import("@earendil-works/pi-coding-agent");
|
|
384
|
-
const refreshAuth = () => gatewayAuth(boot.credentials.host, boot.credentials
|
|
627
|
+
const refreshAuth = async () => gatewayAuth(boot.credentials.host, await currentAccessToken(boot.credentials), boot.programId);
|
|
385
628
|
const auth = await refreshAuth();
|
|
386
629
|
const providerInputs = (current) => ({
|
|
387
630
|
gatewayUrl: current.gatewayUrl,
|
|
@@ -392,34 +635,37 @@ const piBackend = {
|
|
|
392
635
|
modelId,
|
|
393
636
|
effort: inputs.thinkingLevel
|
|
394
637
|
});
|
|
395
|
-
const { provider, caps } = buildGatewayProvider(providerInputs(auth));
|
|
638
|
+
const { provider, caps, api } = buildGatewayProvider(providerInputs(auth));
|
|
396
639
|
const registry = ModelRegistry.inMemory(AuthStorage.create());
|
|
397
640
|
registry.registerProvider(GATEWAY_PROVIDER, provider);
|
|
398
641
|
const model = registry.find(GATEWAY_PROVIDER, modelId);
|
|
399
642
|
if (!model) return {
|
|
400
|
-
|
|
643
|
+
kind: "failure",
|
|
644
|
+
classification: "WIZARD_API_ERROR",
|
|
401
645
|
message: "pi: gateway model could not be resolved"
|
|
402
646
|
};
|
|
403
647
|
const askState = { pending: false };
|
|
404
|
-
const { createSecurityExtension } = await import("./security-
|
|
648
|
+
const { createSecurityExtension, READ_ONLY_PI_TOOLS } = await import("./security-lkBwWbrK.js");
|
|
405
649
|
const security = createSecurityExtension({
|
|
406
|
-
|
|
650
|
+
readOnly: config.readOnly,
|
|
651
|
+
disallowedTools: runConfig.disallowedTools,
|
|
407
652
|
getWizardAskPending: () => askState.pending,
|
|
408
653
|
triageProvider: boot.triageProvider,
|
|
409
|
-
workingDirectory:
|
|
654
|
+
workingDirectory: input.installDir
|
|
410
655
|
});
|
|
411
|
-
|
|
656
|
+
securityState = security.state;
|
|
657
|
+
const { prewarmYaraScanner } = await import("./yara-hooks-B49RIk5d.js");
|
|
412
658
|
prewarmYaraScanner();
|
|
413
659
|
const extensionFactories = [security.factory];
|
|
414
|
-
let mcpCleanup;
|
|
415
660
|
let mcpInstructions;
|
|
416
661
|
let posthogMcp = false;
|
|
417
|
-
try {
|
|
418
|
-
const { setupPostHogMcp, fetchInstructions } = await import("./mcp-
|
|
419
|
-
const
|
|
662
|
+
if (!config.readOnly) try {
|
|
663
|
+
const { setupPostHogMcp, fetchInstructions } = await import("./mcp-JcsBBnWv.js");
|
|
664
|
+
const mcpToken = await currentAccessToken(boot.credentials);
|
|
665
|
+
const instructionsPromise = fetchInstructions(boot.credentials.host.mcpUrl, mcpToken, WIZARD_USER_AGENT);
|
|
420
666
|
const mcp = await setupPostHogMcp({
|
|
421
667
|
mcpUrl: boot.credentials.host.mcpUrl,
|
|
422
|
-
accessToken:
|
|
668
|
+
accessToken: mcpToken,
|
|
423
669
|
userAgent: WIZARD_USER_AGENT
|
|
424
670
|
});
|
|
425
671
|
extensionFactories.push(mcp.extensionFactory);
|
|
@@ -427,6 +673,10 @@ const piBackend = {
|
|
|
427
673
|
mcpInstructions = await instructionsPromise;
|
|
428
674
|
posthogMcp = true;
|
|
429
675
|
} catch (err) {
|
|
676
|
+
try {
|
|
677
|
+
mcpCleanup?.();
|
|
678
|
+
} catch {}
|
|
679
|
+
mcpCleanup = void 0;
|
|
430
680
|
logToFile(`[pi] PostHog MCP setup skipped: ${String(err)}`);
|
|
431
681
|
analytics.wizardCapture("mcp setup failed", {
|
|
432
682
|
harness: "pi",
|
|
@@ -434,11 +684,12 @@ const piBackend = {
|
|
|
434
684
|
error: String(err).slice(0, 300)
|
|
435
685
|
});
|
|
436
686
|
}
|
|
687
|
+
if (structured) extensionFactories.push(structuredOutputExtension(structured.schema, api));
|
|
437
688
|
const resourceLoader = new DefaultResourceLoader({
|
|
438
|
-
cwd:
|
|
689
|
+
cwd: input.installDir,
|
|
439
690
|
agentDir: getAgentDir(),
|
|
440
691
|
systemPrompt: assembleCommandments({
|
|
441
|
-
program:
|
|
692
|
+
program: runConfig.programId,
|
|
442
693
|
sequence: "linear",
|
|
443
694
|
harness: "pi",
|
|
444
695
|
caps: {
|
|
@@ -454,39 +705,43 @@ const piBackend = {
|
|
|
454
705
|
extensionFactories
|
|
455
706
|
});
|
|
456
707
|
await resourceLoader.reload();
|
|
457
|
-
const { createWizardPiTools } = await import("./tools-
|
|
458
|
-
const { createWizardPiTaskTools } = await import("./tasks-
|
|
459
|
-
const { createDispatchAgentTool } = await import("./subagent-
|
|
460
|
-
const wizardTaskTools = createWizardPiTaskTools()
|
|
461
|
-
|
|
708
|
+
const { createWizardPiTools } = await import("./tools-Cc41af5W.js");
|
|
709
|
+
const { createWizardPiTaskTools } = await import("./tasks-Bbv_lOBG.js");
|
|
710
|
+
const { createDispatchAgentTool } = await import("./subagent-Bfy0sfhU.js");
|
|
711
|
+
const wizardTaskTools = createWizardPiTaskTools((tasks) => emit({
|
|
712
|
+
kind: "tasks",
|
|
713
|
+
tasks
|
|
714
|
+
}));
|
|
715
|
+
const scrubbedBash = withMode(createBashToolDefinition(input.installDir, { spawnHook: (ctx) => ({
|
|
462
716
|
...ctx,
|
|
463
717
|
env: buildScrubbedEnv()
|
|
464
718
|
}) }), "sequential");
|
|
465
719
|
const customTools = [
|
|
466
|
-
withMode(createReadToolDefinition(
|
|
467
|
-
withMode(createEditToolDefinition(
|
|
468
|
-
withMode(createWriteToolDefinition(
|
|
720
|
+
withMode(createReadToolDefinition(input.installDir), "parallel"),
|
|
721
|
+
withMode(createEditToolDefinition(input.installDir), "sequential"),
|
|
722
|
+
withMode(createWriteToolDefinition(input.installDir), "sequential"),
|
|
469
723
|
scrubbedBash,
|
|
470
|
-
withMode(createLsToolDefinition(
|
|
471
|
-
withMode(createFindToolDefinition(
|
|
472
|
-
withMode(createGrepToolDefinition(
|
|
724
|
+
withMode(createLsToolDefinition(input.installDir), "parallel"),
|
|
725
|
+
withMode(createFindToolDefinition(input.installDir), "parallel"),
|
|
726
|
+
withMode(createGrepToolDefinition(input.installDir), "parallel"),
|
|
473
727
|
...createWizardPiTools({
|
|
474
|
-
workingDirectory:
|
|
728
|
+
workingDirectory: input.installDir,
|
|
475
729
|
skillsBaseUrl: boot.skillsBaseUrl,
|
|
476
730
|
triageProvider: boot.triageProvider,
|
|
731
|
+
emit,
|
|
477
732
|
detectPackageManager: config.detectPackageManager,
|
|
478
733
|
askBridge: inputs.askBridge,
|
|
479
734
|
maxQuestions: config.maxQuestions,
|
|
480
735
|
onAskPendingChange: (pending) => {
|
|
481
736
|
askState.pending = pending;
|
|
482
737
|
},
|
|
483
|
-
disallowedTools:
|
|
738
|
+
disallowedTools: runConfig.disallowedTools
|
|
484
739
|
}),
|
|
485
740
|
...wizardTaskTools.tools,
|
|
486
741
|
createDispatchAgentTool({
|
|
487
742
|
model,
|
|
488
743
|
modelRegistry: registry,
|
|
489
|
-
cwd:
|
|
744
|
+
cwd: input.installDir,
|
|
490
745
|
agentDir: getAgentDir(),
|
|
491
746
|
securityFactory: security.factory,
|
|
492
747
|
bashTool: scrubbedBash,
|
|
@@ -496,19 +751,23 @@ const piBackend = {
|
|
|
496
751
|
SessionManager
|
|
497
752
|
}
|
|
498
753
|
})
|
|
499
|
-
];
|
|
754
|
+
].filter((tool) => !config.readOnly || READ_ONLY_PI_TOOLS.has(tool.name));
|
|
500
755
|
const { session: agentSession } = await createAgentSession({
|
|
501
756
|
model,
|
|
502
757
|
modelRegistry: registry,
|
|
503
758
|
thinkingLevel: caps.thinkingLevel,
|
|
504
|
-
cwd:
|
|
505
|
-
sessionManager: SessionManager.inMemory(
|
|
759
|
+
cwd: input.installDir,
|
|
760
|
+
sessionManager: SessionManager.inMemory(input.installDir),
|
|
506
761
|
resourceLoader,
|
|
507
762
|
noTools: "builtin",
|
|
508
763
|
customTools
|
|
509
764
|
});
|
|
765
|
+
cancellation = bindPiCancellation(inputs.signal, agentSession, (error) => {
|
|
766
|
+
logToFile(`[pi] abort failed: ${String(error)}`);
|
|
767
|
+
});
|
|
510
768
|
await agentSession.bindExtensions({});
|
|
511
769
|
const turns = withGatewayRemint({
|
|
770
|
+
signal: inputs.signal,
|
|
512
771
|
session: agentSession,
|
|
513
772
|
registry,
|
|
514
773
|
auth,
|
|
@@ -527,13 +786,25 @@ const piBackend = {
|
|
|
527
786
|
if (event.message?.role !== "assistant") break;
|
|
528
787
|
assistantTurns += 1;
|
|
529
788
|
turns.noteAssistantTurn(event.message);
|
|
530
|
-
const
|
|
789
|
+
const blocks = textBlocks(event.message);
|
|
790
|
+
const assistant = blocks.join("").trim();
|
|
791
|
+
lastAssistantText = (blocks.at(-1) ?? "").trim();
|
|
792
|
+
if (structured) inputs.middleware?.onMessage({
|
|
793
|
+
type: "assistant",
|
|
794
|
+
message: { content: blocks.map((text) => ({
|
|
795
|
+
type: "text",
|
|
796
|
+
text
|
|
797
|
+
})) }
|
|
798
|
+
});
|
|
531
799
|
if (assistant) {
|
|
532
800
|
logToFile(`[pi] assistant: ${assistant.slice(0, 1e3)}`);
|
|
533
|
-
applyOutroMarkers(assistant);
|
|
801
|
+
applyOutroMarkers(assistant, emit);
|
|
534
802
|
const statusText = lastStatusLine(assistant);
|
|
535
803
|
if (statusText) {
|
|
536
|
-
|
|
804
|
+
emit({
|
|
805
|
+
kind: "status",
|
|
806
|
+
message: statusText
|
|
807
|
+
});
|
|
537
808
|
spinner.message(statusText);
|
|
538
809
|
}
|
|
539
810
|
for (const line of assistant.split("\n")) signals.push(line);
|
|
@@ -544,6 +815,14 @@ const piBackend = {
|
|
|
544
815
|
toolCalls += 1;
|
|
545
816
|
const args = JSON.stringify(event.args ?? {}).slice(0, 200);
|
|
546
817
|
logToFile(`[pi] → ${event.toolName} ${args}`);
|
|
818
|
+
if (structured) inputs.middleware?.onMessage({
|
|
819
|
+
type: "assistant",
|
|
820
|
+
message: { content: [{
|
|
821
|
+
type: "tool_use",
|
|
822
|
+
name: event.toolName,
|
|
823
|
+
input: event.args
|
|
824
|
+
}] }
|
|
825
|
+
});
|
|
547
826
|
break;
|
|
548
827
|
}
|
|
549
828
|
case "tool_execution_end":
|
|
@@ -556,30 +835,68 @@ const piBackend = {
|
|
|
556
835
|
}
|
|
557
836
|
});
|
|
558
837
|
capture.setInitialPrompt(prompt);
|
|
838
|
+
let terminal = turns.terminalFailure();
|
|
839
|
+
const timeout = structured && setTimeout(() => {
|
|
840
|
+
timedOut = true;
|
|
841
|
+
timeoutAbort = agentSession.abort().catch((error) => {
|
|
842
|
+
logToFile(`[pi] timeout abort failed: ${String(error)}`);
|
|
843
|
+
});
|
|
844
|
+
}, structured.timeoutMs);
|
|
559
845
|
try {
|
|
846
|
+
if (inputs.signal?.aborted) return {
|
|
847
|
+
kind: "abort",
|
|
848
|
+
classification: "WIZARD_ABORT",
|
|
849
|
+
message: "Agent run cancelled"
|
|
850
|
+
};
|
|
560
851
|
await turns.prompt(prompt);
|
|
852
|
+
terminal = turns.terminalFailure();
|
|
561
853
|
let continueNudges = 0;
|
|
562
|
-
while (continueNudges < MAX_CONTINUE_NUDGES && !security.state.criticalViolation && hasOpenTasks(wizardTaskTools.store)) {
|
|
854
|
+
while (!structured && continueNudges < MAX_CONTINUE_NUDGES && !security.state.criticalViolation && !inputs.signal?.aborted && !terminal && hasOpenTasks(wizardTaskTools.store)) {
|
|
563
855
|
continueNudges += 1;
|
|
564
856
|
logToFile(`[pi] completion guard: tasks still open, nudge ${continueNudges}/${MAX_CONTINUE_NUDGES}`);
|
|
565
857
|
await turns.prompt(CONTINUE_INSTRUCTION);
|
|
858
|
+
terminal = turns.terminalFailure();
|
|
566
859
|
}
|
|
567
|
-
if (!security.state.criticalViolation) try {
|
|
860
|
+
if (!structured && !security.state.criticalViolation && !terminal && !inputs.signal?.aborted) try {
|
|
568
861
|
await agentSession.prompt(REMARK_INSTRUCTION);
|
|
569
862
|
} catch (err) {
|
|
570
863
|
logToFile(`[pi] remark request failed: ${String(err)}`);
|
|
571
864
|
}
|
|
572
865
|
} finally {
|
|
573
|
-
|
|
574
|
-
|
|
866
|
+
if (timeout) clearTimeout(timeout);
|
|
867
|
+
try {
|
|
868
|
+
unsubscribe();
|
|
869
|
+
} catch {}
|
|
575
870
|
}
|
|
576
|
-
if (
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
871
|
+
if (inputs.signal?.aborted) return {
|
|
872
|
+
kind: "abort",
|
|
873
|
+
classification: "WIZARD_ABORT",
|
|
874
|
+
message: "Agent run cancelled"
|
|
875
|
+
};
|
|
876
|
+
if (timedOut && structured && !security.state.criticalViolation) return timedOutResult(structured.timeoutMs);
|
|
877
|
+
if (terminal && !security.state.criticalViolation) {
|
|
878
|
+
spinner.stop(config.errorMessage ?? `${config.integrationLabel} failed`);
|
|
879
|
+
captureAborted(terminal.classification);
|
|
880
|
+
if (terminal.status === 401) return {
|
|
881
|
+
kind: "decided_failure",
|
|
882
|
+
failure: {
|
|
883
|
+
code: ErrorCodes.AuthInvalidOrExpired,
|
|
884
|
+
message: "Authentication failed (401)",
|
|
885
|
+
detail: { providerMessage: terminal.message }
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
return terminal.classification === "WIZARD_ABORT" ? {
|
|
889
|
+
kind: "abort",
|
|
890
|
+
classification: "WIZARD_ABORT",
|
|
891
|
+
message: terminal.message
|
|
892
|
+
} : {
|
|
893
|
+
kind: "failure",
|
|
894
|
+
classification: terminal.classification,
|
|
895
|
+
message: terminal.message
|
|
896
|
+
};
|
|
581
897
|
}
|
|
582
|
-
|
|
898
|
+
if (security.state.criticalViolation) return yaraViolationResult();
|
|
899
|
+
const openTasks = !structured && hasOpenTasks(wizardTaskTools.store);
|
|
583
900
|
const failure = completionFailure({
|
|
584
901
|
toolCalls,
|
|
585
902
|
openTasks
|
|
@@ -588,23 +905,30 @@ const piBackend = {
|
|
|
588
905
|
spinner.stop("Agent made no changes");
|
|
589
906
|
logToFile(`[pi] no progress: ${assistantTurns} assistant turn(s), 0 tool calls`);
|
|
590
907
|
analytics.wizardCapture("agent no progress", { assistant_turns: assistantTurns });
|
|
591
|
-
|
|
592
|
-
|
|
908
|
+
const classification = structured ? "WIZARD_INVALID_STRUCTURED_OUTPUT" : failure;
|
|
909
|
+
captureAborted(classification);
|
|
910
|
+
return {
|
|
911
|
+
kind: "failure",
|
|
912
|
+
classification
|
|
913
|
+
};
|
|
593
914
|
}
|
|
594
915
|
if (failure === "WIZARD_INCOMPLETE_TASKS") {
|
|
595
916
|
spinner.stop("Agent stopped before finishing");
|
|
596
917
|
logToFile("[pi] incomplete: tasks left open");
|
|
597
918
|
analytics.wizardCapture("agent incomplete tasks", { open_tasks: true });
|
|
598
919
|
captureAborted(failure);
|
|
599
|
-
return {
|
|
920
|
+
return {
|
|
921
|
+
kind: "failure",
|
|
922
|
+
classification: failure
|
|
923
|
+
};
|
|
600
924
|
}
|
|
601
925
|
const remark = signals.remark();
|
|
602
926
|
if (remark) analytics.capture(WIZARD_REMARK_EVENT_NAME, { remark });
|
|
603
927
|
const skillFailure = signals.skillInstallFailure();
|
|
604
928
|
if (skillFailure !== void 0) analytics.wizardCapture("agent continued without skill", { detail: skillFailure });
|
|
605
929
|
try {
|
|
606
|
-
const planFile = path.join(
|
|
607
|
-
if (fs.existsSync(planFile)) await fs.promises.rm(planFile);
|
|
930
|
+
const planFile = path.join(input.installDir, ".posthog-events.json");
|
|
931
|
+
if (!structured && fs.existsSync(planFile)) await fs.promises.rm(planFile);
|
|
608
932
|
} catch (err) {
|
|
609
933
|
logToFile(`[pi] .posthog-events.json cleanup skipped: ${String(err)}`);
|
|
610
934
|
}
|
|
@@ -619,26 +943,65 @@ const piBackend = {
|
|
|
619
943
|
cache_read_input_tokens: stats.tokens.cacheRead
|
|
620
944
|
});
|
|
621
945
|
spinner.stop(config.successMessage ?? "PostHog integration complete");
|
|
622
|
-
|
|
946
|
+
aioFailed = false;
|
|
947
|
+
if (!structured) return { kind: "success" };
|
|
948
|
+
try {
|
|
949
|
+
return {
|
|
950
|
+
kind: "success",
|
|
951
|
+
structuredOutput: JSON.parse(lastAssistantText)
|
|
952
|
+
};
|
|
953
|
+
} catch {
|
|
954
|
+
return { kind: "success" };
|
|
955
|
+
}
|
|
623
956
|
} catch (err) {
|
|
957
|
+
if (inputs.signal?.aborted) return {
|
|
958
|
+
kind: "abort",
|
|
959
|
+
classification: "WIZARD_ABORT",
|
|
960
|
+
message: "Agent run cancelled"
|
|
961
|
+
};
|
|
962
|
+
if (securityState?.criticalViolation) return yaraViolationResult();
|
|
963
|
+
if (timedOut && structured) return timedOutResult(structured.timeoutMs);
|
|
624
964
|
const message = err instanceof Error ? err.message : String(err);
|
|
625
965
|
logToFile(`[pi] run error: ${message}`);
|
|
626
966
|
spinner.stop(config.errorMessage ?? `${config.integrationLabel} failed`);
|
|
627
|
-
|
|
628
|
-
const
|
|
629
|
-
|
|
967
|
+
log.error(`pi backend error: ${message}`);
|
|
968
|
+
const coded = classifyRunFailure(err);
|
|
969
|
+
if (coded.coded && err instanceof Error) {
|
|
970
|
+
captureAborted("WIZARD_API_ERROR");
|
|
971
|
+
return {
|
|
972
|
+
kind: "decided_failure",
|
|
973
|
+
failure: {
|
|
974
|
+
code: coded.code,
|
|
975
|
+
message: coded.message,
|
|
976
|
+
error: err
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
const classification = runErrorType(message);
|
|
981
|
+
captureAborted(classification);
|
|
630
982
|
return {
|
|
631
|
-
|
|
632
|
-
|
|
983
|
+
kind: "failure",
|
|
984
|
+
classification,
|
|
985
|
+
message,
|
|
986
|
+
error: err instanceof Error ? err : void 0
|
|
633
987
|
};
|
|
988
|
+
} finally {
|
|
989
|
+
await cancellation?.settle();
|
|
990
|
+
await timeoutAbort;
|
|
991
|
+
try {
|
|
992
|
+
mcpCleanup?.();
|
|
993
|
+
} catch {}
|
|
994
|
+
try {
|
|
995
|
+
capture.finishPiRun(aioFailed);
|
|
996
|
+
} catch {}
|
|
634
997
|
}
|
|
635
998
|
},
|
|
636
999
|
async runTask(inputs) {
|
|
637
|
-
const { runPiTask } = await import("./task-
|
|
1000
|
+
const { runPiTask } = await import("./task-BOfw7GPc.js");
|
|
638
1001
|
return runPiTask(inputs);
|
|
639
1002
|
}
|
|
640
1003
|
};
|
|
641
1004
|
//#endregion
|
|
642
|
-
export { piBackend as a,
|
|
1005
|
+
export { piBackend as a, runErrorType as c, createEmitSpinner as d, createProgressCollector as f, lastStatusLine as i, createAioCapture as l, buildScrubbedEnv as n, withMode as o, appendStatus as p, extractText as r, bindPiCancellation as s, applyOutroMarkers as t, createEmitLog as u };
|
|
643
1006
|
|
|
644
|
-
//# sourceMappingURL=pi-
|
|
1007
|
+
//# sourceMappingURL=pi-BtqcLX3y.js.map
|