@posthog/wizard 2.77.0 → 2.78.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 +30 -15
- package/dist/{add-mcp-server-to-clients-BnRyE4pw.js → add-mcp-server-to-clients-JMv8LP-O.js} +6 -5
- package/dist/{add-mcp-server-to-clients-BnRyE4pw.js.map → add-mcp-server-to-clients-JMv8LP-O.js.map} +1 -1
- package/dist/agent-bCZ3i3fh.js +3085 -0
- package/dist/agent-bCZ3i3fh.js.map +1 -0
- package/dist/{agent-interface-Avtr_5M5.js → agent-interface-BAOIHuXS.js} +429 -378
- package/dist/agent-interface-BAOIHuXS.js.map +1 -0
- package/dist/{agent-prompt-loader-CHixNPgY.js → agent-prompt-loader-7Pd4CfZO.js} +6 -6
- package/dist/agent-prompt-loader-7Pd4CfZO.js.map +1 -0
- package/dist/analytics-BcV-WCM4.js +2 -0
- package/dist/{analytics-C67F2vee.js → analytics-CHCZ_qUR.js} +10 -6
- package/dist/analytics-CHCZ_qUR.js.map +1 -0
- package/dist/{api-Dj1yabTj.js → api-Diy_2fp8.js} +4 -17
- package/dist/api-Diy_2fp8.js.map +1 -0
- package/dist/bin.js +410 -68
- package/dist/bin.js.map +1 -1
- package/dist/{bounded-fs-CWRYuLAn.js → bounded-fs-Bx9zTe6m.js} +4 -4
- package/dist/bounded-fs-Bx9zTe6m.js.map +1 -0
- package/dist/check-screens.tsx +1 -1
- package/dist/{ci-install-CvXL5h13.js → ci-install-CDdQYsPe.js} +6 -5
- package/dist/ci-install-CDdQYsPe.js.map +1 -0
- package/dist/constants-jFI2SaE1.js +260 -0
- package/dist/constants-jFI2SaE1.js.map +1 -0
- package/dist/debug-Ch4BDOtD.js +171 -0
- package/dist/debug-Ch4BDOtD.js.map +1 -0
- package/dist/{debug-CziFS0cA.js → debug-M2gV2iDq.js} +1 -1
- 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-DCVbM06L.js +108 -0
- package/dist/endpoints-DCVbM06L.js.map +1 -0
- package/dist/{env-api-key-BZ5wE3Y4.js → env-api-key-Qx8NnYHm.js} +3 -3
- package/dist/env-api-key-Qx8NnYHm.js.map +1 -0
- package/dist/{environment-BEvsey6i.js → environment-B07Bmxae.js} +6 -6
- package/dist/environment-B07Bmxae.js.map +1 -0
- package/dist/{errors-BoJvrdw8.js → errors-CQ9kttJD.js} +27 -34
- package/dist/errors-CQ9kttJD.js.map +1 -0
- package/dist/{file-BoD3REGB.js → file-BcLTjU16.js} +2 -2
- package/dist/{file-BoD3REGB.js.map → file-BcLTjU16.js.map} +1 -1
- package/dist/{file-watcher-BPFazvG_.js → file-watcher-DWc_bTs6.js} +2 -2
- package/dist/{file-watcher-BPFazvG_.js.map → file-watcher-DWc_bTs6.js.map} +1 -1
- package/dist/{gateway-session-xPFv6p5c.js → gateway-CjoShdLa.js} +175 -20
- package/dist/gateway-CjoShdLa.js.map +1 -0
- package/dist/generate-version.cjs +1 -1
- package/dist/{headless-ui-CsmQrDIl.js → headless-ui-BFFmYC4v.js} +13 -2
- package/dist/headless-ui-BFFmYC4v.js.map +1 -0
- package/dist/{interactive-Dej-sxvR.js → interactive-D6zV7brJ.js} +2 -2
- package/dist/{interactive-Dej-sxvR.js.map → interactive-D6zV7brJ.js.map} +1 -1
- 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-_TwoMNbG.js +226 -0
- package/dist/logging-ui-_TwoMNbG.js.map +1 -0
- package/dist/mcp-DAgaoGk5.js +97 -0
- package/dist/mcp-DAgaoGk5.js.map +1 -0
- package/dist/{mcp-prompt-streaming-BU_kuur_.js → mcp-prompt-streaming-I2U_X7BC.js} +7 -6
- package/dist/mcp-prompt-streaming-I2U_X7BC.js.map +1 -0
- package/dist/{mint-failure-BrleGqMd.js → mint-failure-D4nd2XmZ.js} +82 -25
- package/dist/mint-failure-D4nd2XmZ.js.map +1 -0
- package/dist/models-DDdBJKwT.js +83 -0
- package/dist/models-DDdBJKwT.js.map +1 -0
- package/dist/{non-interactive-DcOjH2fw.js → non-interactive-Dzow7YKY.js} +3 -3
- package/dist/non-interactive-Dzow7YKY.js.map +1 -0
- package/dist/oauth-session-DJ8h6GFa.js +74 -0
- package/dist/oauth-session-DJ8h6GFa.js.map +1 -0
- package/dist/{orchestrator-tools-DXwr8Sp3.js → orchestrator-tools-szcdscwn.js} +4 -4
- package/dist/orchestrator-tools-szcdscwn.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-D3h5Ok0i.js} +329 -65
- package/dist/pi-D3h5Ok0i.js.map +1 -0
- package/dist/{playground-CDUUKLkC.js → playground-5AB4WgNF.js} +11 -7
- package/dist/playground-5AB4WgNF.js.map +1 -0
- package/dist/{posthog-Hc_-9wrr.js → posthog-DNn574nW.js} +8 -3
- package/dist/posthog-DNn574nW.js.map +1 -0
- package/dist/{provisioning-xfdjhFtA.js → provisioning-B8uSqRZk.js} +6 -5
- package/dist/provisioning-B8uSqRZk.js.map +1 -0
- package/dist/{queue-tools-C8y_xZJi.js → queue-tools-9OOVx5TE.js} +7 -86
- package/dist/queue-tools-9OOVx5TE.js.map +1 -0
- package/dist/{registry-DTmREJ-f.js → registry-8YG-kuXk.js} +265 -6
- package/dist/registry-8YG-kuXk.js.map +1 -0
- package/dist/run-agent-legacy-d7rWlzQR.js +3739 -0
- package/dist/run-agent-legacy-d7rWlzQR.js.map +1 -0
- package/dist/{security-Dw2oFJjP.js → security-Cg_4a7vB.js} +6 -6
- package/dist/security-Cg_4a7vB.js.map +1 -0
- package/dist/{setup-utils-fjJTBhaB.js → setup-utils-CmTCTPkX.js} +46 -18
- package/dist/setup-utils-CmTCTPkX.js.map +1 -0
- package/dist/smoke-test.sh +1 -1
- package/dist/{start-tui-UNe2xQ0U.js → start-tui-CB2PZs1x.js} +38 -44
- package/dist/start-tui-CB2PZs1x.js.map +1 -0
- package/dist/{steps-C2yqOk_h.js → steps-BZcXRJNY.js} +7 -7
- package/dist/{steps-C2yqOk_h.js.map → steps-BZcXRJNY.js.map} +1 -1
- package/dist/{store-Bic4Cr3L.js → store-UN7c-ASf.js} +18 -28
- package/dist/store-UN7c-ASf.js.map +1 -0
- package/dist/{subagent-Dz41vV9j.js → subagent-BofIDK-O.js} +8 -3
- package/dist/subagent-BofIDK-O.js.map +1 -0
- package/dist/{task-5-fw_Vw3.js → task-r9t1UhQP.js} +124 -36
- package/dist/task-r9t1UhQP.js.map +1 -0
- package/dist/{task-stream-dVzl6b_q.js → task-stream-CMUilu54.js} +45 -15
- package/dist/task-stream-CMUilu54.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-D6ruCtnv.js} +5 -5
- package/dist/telemetry-D6ruCtnv.js.map +1 -0
- package/dist/{terminal-9bvRa4Qt.js → terminal-DrGyci_a.js} +39 -74
- package/dist/terminal-DrGyci_a.js.map +1 -0
- package/dist/{tools-Dp6i9k70.js → tools-Dyfh9aCD.js} +11 -11
- package/dist/tools-Dyfh9aCD.js.map +1 -0
- package/dist/ui-BBVuTM1v.js +15 -0
- package/dist/ui-BBVuTM1v.js.map +1 -0
- package/dist/version-aXxpgRKx.js +6 -0
- package/dist/version-aXxpgRKx.js.map +1 -0
- package/dist/warlock-smoke-test.ts +2 -2
- package/dist/{wizard-abort-lE6umflt.js → wizard-abort-BBkiUxfS.js} +23 -20
- package/dist/wizard-abort-BBkiUxfS.js.map +1 -0
- package/dist/wizard-abort-BU4aLyvh.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-BTNJ6MGW.js → yara-hooks-DCeMDd1o.js} +19 -68
- package/dist/yara-hooks-DCeMDd1o.js.map +1 -0
- package/dist/yara-hooks-DSGuCU9A.js +2 -0
- package/package.json +1 -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/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/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 { a as AgentSignals, d as ErrorCodes, o as REMARK_INSTRUCTION, t as classifyRunFailure } from "./errors-CQ9kttJD.js";
|
|
2
|
+
import { a as getLogFilePath, s as logToFile } from "./debug-Ch4BDOtD.js";
|
|
3
|
+
import { t as VERSION } from "./version-aXxpgRKx.js";
|
|
4
|
+
import { Q as WIZARD_USER_AGENT, Y as WIZARD_REMARK_EVENT_NAME } from "./constants-jFI2SaE1.js";
|
|
5
|
+
import { n as analytics } from "./analytics-CHCZ_qUR.js";
|
|
6
|
+
import { n as currentAccessToken } from "./oauth-session-DJ8h6GFa.js";
|
|
7
|
+
import { l as gatewayAuth, o as withGatewayRemint, r as buildGatewayProvider, t as GATEWAY_PROVIDER } from "./gateway-CjoShdLa.js";
|
|
8
|
+
import { g as assembleCommandments, p as AgentOutputSignals } from "./agent-interface-BAOIHuXS.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,26 @@ 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/index.ts
|
|
224
382
|
/**
|
|
225
383
|
* The `pi` backend — the challenger. Drives pi.dev's coding agent
|
|
226
384
|
* (`@earendil-works/pi-coding-agent`) against the PostHog LLM gateway, behind
|
|
@@ -318,8 +476,16 @@ function extractText(message) {
|
|
|
318
476
|
* the MCP creates them) into the outro link, mirroring the anthropic path's
|
|
319
477
|
* signal parsing (#9). The marker carries the URL the MCP returned.
|
|
320
478
|
*/
|
|
321
|
-
function applyOutroMarkers(textBlock) {
|
|
322
|
-
const markers = [[AgentSignals.DASHBOARD_URL, (url) =>
|
|
479
|
+
function applyOutroMarkers(textBlock, emit) {
|
|
480
|
+
const markers = [[AgentSignals.DASHBOARD_URL, (url) => emit({
|
|
481
|
+
kind: "url",
|
|
482
|
+
which: "dashboard",
|
|
483
|
+
url
|
|
484
|
+
})], [AgentSignals.NOTEBOOK_URL, (url) => emit({
|
|
485
|
+
kind: "url",
|
|
486
|
+
which: "notebook",
|
|
487
|
+
url
|
|
488
|
+
})]];
|
|
323
489
|
for (const [marker, apply] of markers) {
|
|
324
490
|
const idx = textBlock.indexOf(marker);
|
|
325
491
|
if (idx === -1) continue;
|
|
@@ -351,17 +517,24 @@ function hasOpenTasks(store) {
|
|
|
351
517
|
const piBackend = {
|
|
352
518
|
name: "pi",
|
|
353
519
|
async run(inputs) {
|
|
354
|
-
|
|
520
|
+
if (inputs.signal?.aborted) return {
|
|
521
|
+
kind: "abort",
|
|
522
|
+
classification: "WIZARD_ABORT",
|
|
523
|
+
message: "Agent run cancelled"
|
|
524
|
+
};
|
|
525
|
+
const { config: runConfig, input, boot, emit, prompt, spinner } = inputs;
|
|
526
|
+
const config = runConfig.run;
|
|
355
527
|
const modelId = inputs.model;
|
|
528
|
+
const log = createEmitLog(emit);
|
|
356
529
|
const capture = createAioCapture({
|
|
357
|
-
enabled:
|
|
530
|
+
enabled: input.flags.captureAio,
|
|
358
531
|
projectApiKey: boot.credentials.projectApiKey,
|
|
359
532
|
apiHost: boot.credentials.host.apiHost,
|
|
360
533
|
runTags: boot.wizardMetadata
|
|
361
534
|
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
535
|
+
log.step("Initializing Wizard agent...");
|
|
536
|
+
log.step(`Verbose logs: ${getLogFilePath()}`);
|
|
537
|
+
log.success("Agent initialized. Let's get cooking!");
|
|
365
538
|
spinner.start(config.spinnerMessage ?? "Customizing your PostHog setup...");
|
|
366
539
|
const startTime = Date.now();
|
|
367
540
|
const signals = new AgentOutputSignals();
|
|
@@ -379,9 +552,12 @@ const piBackend = {
|
|
|
379
552
|
...runDurations(),
|
|
380
553
|
model: modelId
|
|
381
554
|
});
|
|
555
|
+
let mcpCleanup;
|
|
556
|
+
let aioFailed = true;
|
|
557
|
+
let cancellation;
|
|
382
558
|
try {
|
|
383
559
|
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
|
|
560
|
+
const refreshAuth = async () => gatewayAuth(boot.credentials.host, await currentAccessToken(boot.credentials), boot.programId);
|
|
385
561
|
const auth = await refreshAuth();
|
|
386
562
|
const providerInputs = (current) => ({
|
|
387
563
|
gatewayUrl: current.gatewayUrl,
|
|
@@ -397,29 +573,30 @@ const piBackend = {
|
|
|
397
573
|
registry.registerProvider(GATEWAY_PROVIDER, provider);
|
|
398
574
|
const model = registry.find(GATEWAY_PROVIDER, modelId);
|
|
399
575
|
if (!model) return {
|
|
400
|
-
|
|
576
|
+
kind: "failure",
|
|
577
|
+
classification: "WIZARD_API_ERROR",
|
|
401
578
|
message: "pi: gateway model could not be resolved"
|
|
402
579
|
};
|
|
403
580
|
const askState = { pending: false };
|
|
404
|
-
const { createSecurityExtension } = await import("./security-
|
|
581
|
+
const { createSecurityExtension } = await import("./security-Cg_4a7vB.js");
|
|
405
582
|
const security = createSecurityExtension({
|
|
406
|
-
disallowedTools:
|
|
583
|
+
disallowedTools: runConfig.disallowedTools,
|
|
407
584
|
getWizardAskPending: () => askState.pending,
|
|
408
585
|
triageProvider: boot.triageProvider,
|
|
409
|
-
workingDirectory:
|
|
586
|
+
workingDirectory: input.installDir
|
|
410
587
|
});
|
|
411
|
-
const { prewarmYaraScanner } = await import("./yara-hooks-
|
|
588
|
+
const { prewarmYaraScanner } = await import("./yara-hooks-DSGuCU9A.js");
|
|
412
589
|
prewarmYaraScanner();
|
|
413
590
|
const extensionFactories = [security.factory];
|
|
414
|
-
let mcpCleanup;
|
|
415
591
|
let mcpInstructions;
|
|
416
592
|
let posthogMcp = false;
|
|
417
593
|
try {
|
|
418
|
-
const { setupPostHogMcp, fetchInstructions } = await import("./mcp-
|
|
419
|
-
const
|
|
594
|
+
const { setupPostHogMcp, fetchInstructions } = await import("./mcp-DAgaoGk5.js");
|
|
595
|
+
const mcpToken = await currentAccessToken(boot.credentials);
|
|
596
|
+
const instructionsPromise = fetchInstructions(boot.credentials.host.mcpUrl, mcpToken, WIZARD_USER_AGENT);
|
|
420
597
|
const mcp = await setupPostHogMcp({
|
|
421
598
|
mcpUrl: boot.credentials.host.mcpUrl,
|
|
422
|
-
accessToken:
|
|
599
|
+
accessToken: mcpToken,
|
|
423
600
|
userAgent: WIZARD_USER_AGENT
|
|
424
601
|
});
|
|
425
602
|
extensionFactories.push(mcp.extensionFactory);
|
|
@@ -427,6 +604,10 @@ const piBackend = {
|
|
|
427
604
|
mcpInstructions = await instructionsPromise;
|
|
428
605
|
posthogMcp = true;
|
|
429
606
|
} catch (err) {
|
|
607
|
+
try {
|
|
608
|
+
mcpCleanup?.();
|
|
609
|
+
} catch {}
|
|
610
|
+
mcpCleanup = void 0;
|
|
430
611
|
logToFile(`[pi] PostHog MCP setup skipped: ${String(err)}`);
|
|
431
612
|
analytics.wizardCapture("mcp setup failed", {
|
|
432
613
|
harness: "pi",
|
|
@@ -435,10 +616,10 @@ const piBackend = {
|
|
|
435
616
|
});
|
|
436
617
|
}
|
|
437
618
|
const resourceLoader = new DefaultResourceLoader({
|
|
438
|
-
cwd:
|
|
619
|
+
cwd: input.installDir,
|
|
439
620
|
agentDir: getAgentDir(),
|
|
440
621
|
systemPrompt: assembleCommandments({
|
|
441
|
-
program:
|
|
622
|
+
program: runConfig.programId,
|
|
442
623
|
sequence: "linear",
|
|
443
624
|
harness: "pi",
|
|
444
625
|
caps: {
|
|
@@ -454,39 +635,43 @@ const piBackend = {
|
|
|
454
635
|
extensionFactories
|
|
455
636
|
});
|
|
456
637
|
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
|
-
|
|
638
|
+
const { createWizardPiTools } = await import("./tools-Dyfh9aCD.js");
|
|
639
|
+
const { createWizardPiTaskTools } = await import("./tasks-Bbv_lOBG.js");
|
|
640
|
+
const { createDispatchAgentTool } = await import("./subagent-BofIDK-O.js");
|
|
641
|
+
const wizardTaskTools = createWizardPiTaskTools((tasks) => emit({
|
|
642
|
+
kind: "tasks",
|
|
643
|
+
tasks
|
|
644
|
+
}));
|
|
645
|
+
const scrubbedBash = withMode(createBashToolDefinition(input.installDir, { spawnHook: (ctx) => ({
|
|
462
646
|
...ctx,
|
|
463
647
|
env: buildScrubbedEnv()
|
|
464
648
|
}) }), "sequential");
|
|
465
649
|
const customTools = [
|
|
466
|
-
withMode(createReadToolDefinition(
|
|
467
|
-
withMode(createEditToolDefinition(
|
|
468
|
-
withMode(createWriteToolDefinition(
|
|
650
|
+
withMode(createReadToolDefinition(input.installDir), "parallel"),
|
|
651
|
+
withMode(createEditToolDefinition(input.installDir), "sequential"),
|
|
652
|
+
withMode(createWriteToolDefinition(input.installDir), "sequential"),
|
|
469
653
|
scrubbedBash,
|
|
470
|
-
withMode(createLsToolDefinition(
|
|
471
|
-
withMode(createFindToolDefinition(
|
|
472
|
-
withMode(createGrepToolDefinition(
|
|
654
|
+
withMode(createLsToolDefinition(input.installDir), "parallel"),
|
|
655
|
+
withMode(createFindToolDefinition(input.installDir), "parallel"),
|
|
656
|
+
withMode(createGrepToolDefinition(input.installDir), "parallel"),
|
|
473
657
|
...createWizardPiTools({
|
|
474
|
-
workingDirectory:
|
|
658
|
+
workingDirectory: input.installDir,
|
|
475
659
|
skillsBaseUrl: boot.skillsBaseUrl,
|
|
476
660
|
triageProvider: boot.triageProvider,
|
|
661
|
+
emit,
|
|
477
662
|
detectPackageManager: config.detectPackageManager,
|
|
478
663
|
askBridge: inputs.askBridge,
|
|
479
664
|
maxQuestions: config.maxQuestions,
|
|
480
665
|
onAskPendingChange: (pending) => {
|
|
481
666
|
askState.pending = pending;
|
|
482
667
|
},
|
|
483
|
-
disallowedTools:
|
|
668
|
+
disallowedTools: runConfig.disallowedTools
|
|
484
669
|
}),
|
|
485
670
|
...wizardTaskTools.tools,
|
|
486
671
|
createDispatchAgentTool({
|
|
487
672
|
model,
|
|
488
673
|
modelRegistry: registry,
|
|
489
|
-
cwd:
|
|
674
|
+
cwd: input.installDir,
|
|
490
675
|
agentDir: getAgentDir(),
|
|
491
676
|
securityFactory: security.factory,
|
|
492
677
|
bashTool: scrubbedBash,
|
|
@@ -501,14 +686,18 @@ const piBackend = {
|
|
|
501
686
|
model,
|
|
502
687
|
modelRegistry: registry,
|
|
503
688
|
thinkingLevel: caps.thinkingLevel,
|
|
504
|
-
cwd:
|
|
505
|
-
sessionManager: SessionManager.inMemory(
|
|
689
|
+
cwd: input.installDir,
|
|
690
|
+
sessionManager: SessionManager.inMemory(input.installDir),
|
|
506
691
|
resourceLoader,
|
|
507
692
|
noTools: "builtin",
|
|
508
693
|
customTools
|
|
509
694
|
});
|
|
695
|
+
cancellation = bindPiCancellation(inputs.signal, agentSession, (error) => {
|
|
696
|
+
logToFile(`[pi] abort failed: ${String(error)}`);
|
|
697
|
+
});
|
|
510
698
|
await agentSession.bindExtensions({});
|
|
511
699
|
const turns = withGatewayRemint({
|
|
700
|
+
signal: inputs.signal,
|
|
512
701
|
session: agentSession,
|
|
513
702
|
registry,
|
|
514
703
|
auth,
|
|
@@ -530,10 +719,13 @@ const piBackend = {
|
|
|
530
719
|
const assistant = extractText(event.message).trim();
|
|
531
720
|
if (assistant) {
|
|
532
721
|
logToFile(`[pi] assistant: ${assistant.slice(0, 1e3)}`);
|
|
533
|
-
applyOutroMarkers(assistant);
|
|
722
|
+
applyOutroMarkers(assistant, emit);
|
|
534
723
|
const statusText = lastStatusLine(assistant);
|
|
535
724
|
if (statusText) {
|
|
536
|
-
|
|
725
|
+
emit({
|
|
726
|
+
kind: "status",
|
|
727
|
+
message: statusText
|
|
728
|
+
});
|
|
537
729
|
spinner.message(statusText);
|
|
538
730
|
}
|
|
539
731
|
for (const line of assistant.split("\n")) signals.push(line);
|
|
@@ -556,28 +748,66 @@ const piBackend = {
|
|
|
556
748
|
}
|
|
557
749
|
});
|
|
558
750
|
capture.setInitialPrompt(prompt);
|
|
751
|
+
let terminal = turns.terminalFailure();
|
|
559
752
|
try {
|
|
753
|
+
if (inputs.signal?.aborted) return {
|
|
754
|
+
kind: "abort",
|
|
755
|
+
classification: "WIZARD_ABORT",
|
|
756
|
+
message: "Agent run cancelled"
|
|
757
|
+
};
|
|
560
758
|
await turns.prompt(prompt);
|
|
759
|
+
terminal = turns.terminalFailure();
|
|
561
760
|
let continueNudges = 0;
|
|
562
|
-
while (continueNudges < MAX_CONTINUE_NUDGES && !security.state.criticalViolation && hasOpenTasks(wizardTaskTools.store)) {
|
|
761
|
+
while (continueNudges < MAX_CONTINUE_NUDGES && !security.state.criticalViolation && !inputs.signal?.aborted && !terminal && hasOpenTasks(wizardTaskTools.store)) {
|
|
563
762
|
continueNudges += 1;
|
|
564
763
|
logToFile(`[pi] completion guard: tasks still open, nudge ${continueNudges}/${MAX_CONTINUE_NUDGES}`);
|
|
565
764
|
await turns.prompt(CONTINUE_INSTRUCTION);
|
|
765
|
+
terminal = turns.terminalFailure();
|
|
566
766
|
}
|
|
567
|
-
if (!security.state.criticalViolation) try {
|
|
767
|
+
if (!security.state.criticalViolation && !terminal && !inputs.signal?.aborted) try {
|
|
568
768
|
await agentSession.prompt(REMARK_INSTRUCTION);
|
|
569
769
|
} catch (err) {
|
|
570
770
|
logToFile(`[pi] remark request failed: ${String(err)}`);
|
|
571
771
|
}
|
|
572
772
|
} finally {
|
|
573
|
-
|
|
574
|
-
|
|
773
|
+
try {
|
|
774
|
+
unsubscribe();
|
|
775
|
+
} catch {}
|
|
776
|
+
}
|
|
777
|
+
if (inputs.signal?.aborted) return {
|
|
778
|
+
kind: "abort",
|
|
779
|
+
classification: "WIZARD_ABORT",
|
|
780
|
+
message: "Agent run cancelled"
|
|
781
|
+
};
|
|
782
|
+
if (terminal && !security.state.criticalViolation) {
|
|
783
|
+
spinner.stop(config.errorMessage ?? `${config.integrationLabel} failed`);
|
|
784
|
+
captureAborted(terminal.classification);
|
|
785
|
+
if (terminal.status === 401) return {
|
|
786
|
+
kind: "decided_failure",
|
|
787
|
+
failure: {
|
|
788
|
+
code: ErrorCodes.AuthInvalidOrExpired,
|
|
789
|
+
message: "Authentication failed (401)",
|
|
790
|
+
detail: { providerMessage: terminal.message }
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
return terminal.classification === "WIZARD_ABORT" ? {
|
|
794
|
+
kind: "abort",
|
|
795
|
+
classification: "WIZARD_ABORT",
|
|
796
|
+
message: terminal.message
|
|
797
|
+
} : {
|
|
798
|
+
kind: "failure",
|
|
799
|
+
classification: terminal.classification,
|
|
800
|
+
message: terminal.message
|
|
801
|
+
};
|
|
575
802
|
}
|
|
576
803
|
if (security.state.criticalViolation) {
|
|
577
804
|
spinner.stop("Security violation detected");
|
|
578
805
|
logToFile(`[pi] terminated: YARA violation (blocked ${security.state.blockedCount} call(s))`);
|
|
579
806
|
captureAborted("WIZARD_YARA_VIOLATION");
|
|
580
|
-
return {
|
|
807
|
+
return {
|
|
808
|
+
kind: "failure",
|
|
809
|
+
classification: "WIZARD_YARA_VIOLATION"
|
|
810
|
+
};
|
|
581
811
|
}
|
|
582
812
|
const openTasks = hasOpenTasks(wizardTaskTools.store);
|
|
583
813
|
const failure = completionFailure({
|
|
@@ -589,21 +819,27 @@ const piBackend = {
|
|
|
589
819
|
logToFile(`[pi] no progress: ${assistantTurns} assistant turn(s), 0 tool calls`);
|
|
590
820
|
analytics.wizardCapture("agent no progress", { assistant_turns: assistantTurns });
|
|
591
821
|
captureAborted(failure);
|
|
592
|
-
return {
|
|
822
|
+
return {
|
|
823
|
+
kind: "failure",
|
|
824
|
+
classification: failure
|
|
825
|
+
};
|
|
593
826
|
}
|
|
594
827
|
if (failure === "WIZARD_INCOMPLETE_TASKS") {
|
|
595
828
|
spinner.stop("Agent stopped before finishing");
|
|
596
829
|
logToFile("[pi] incomplete: tasks left open");
|
|
597
830
|
analytics.wizardCapture("agent incomplete tasks", { open_tasks: true });
|
|
598
831
|
captureAborted(failure);
|
|
599
|
-
return {
|
|
832
|
+
return {
|
|
833
|
+
kind: "failure",
|
|
834
|
+
classification: failure
|
|
835
|
+
};
|
|
600
836
|
}
|
|
601
837
|
const remark = signals.remark();
|
|
602
838
|
if (remark) analytics.capture(WIZARD_REMARK_EVENT_NAME, { remark });
|
|
603
839
|
const skillFailure = signals.skillInstallFailure();
|
|
604
840
|
if (skillFailure !== void 0) analytics.wizardCapture("agent continued without skill", { detail: skillFailure });
|
|
605
841
|
try {
|
|
606
|
-
const planFile = path.join(
|
|
842
|
+
const planFile = path.join(input.installDir, ".posthog-events.json");
|
|
607
843
|
if (fs.existsSync(planFile)) await fs.promises.rm(planFile);
|
|
608
844
|
} catch (err) {
|
|
609
845
|
logToFile(`[pi] .posthog-events.json cleanup skipped: ${String(err)}`);
|
|
@@ -619,26 +855,54 @@ const piBackend = {
|
|
|
619
855
|
cache_read_input_tokens: stats.tokens.cacheRead
|
|
620
856
|
});
|
|
621
857
|
spinner.stop(config.successMessage ?? "PostHog integration complete");
|
|
622
|
-
|
|
858
|
+
aioFailed = false;
|
|
859
|
+
return { kind: "success" };
|
|
623
860
|
} catch (err) {
|
|
861
|
+
if (inputs.signal?.aborted) return {
|
|
862
|
+
kind: "abort",
|
|
863
|
+
classification: "WIZARD_ABORT",
|
|
864
|
+
message: "Agent run cancelled"
|
|
865
|
+
};
|
|
624
866
|
const message = err instanceof Error ? err.message : String(err);
|
|
625
867
|
logToFile(`[pi] run error: ${message}`);
|
|
626
868
|
spinner.stop(config.errorMessage ?? `${config.integrationLabel} failed`);
|
|
627
|
-
|
|
628
|
-
const
|
|
629
|
-
|
|
869
|
+
log.error(`pi backend error: ${message}`);
|
|
870
|
+
const coded = classifyRunFailure(err);
|
|
871
|
+
if (coded.coded && err instanceof Error) {
|
|
872
|
+
captureAborted("WIZARD_API_ERROR");
|
|
873
|
+
return {
|
|
874
|
+
kind: "decided_failure",
|
|
875
|
+
failure: {
|
|
876
|
+
code: coded.code,
|
|
877
|
+
message: coded.message,
|
|
878
|
+
error: err
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
const classification = runErrorType(message);
|
|
883
|
+
captureAborted(classification);
|
|
630
884
|
return {
|
|
631
|
-
|
|
632
|
-
|
|
885
|
+
kind: "failure",
|
|
886
|
+
classification,
|
|
887
|
+
message,
|
|
888
|
+
error: err instanceof Error ? err : void 0
|
|
633
889
|
};
|
|
890
|
+
} finally {
|
|
891
|
+
await cancellation?.settle();
|
|
892
|
+
try {
|
|
893
|
+
mcpCleanup?.();
|
|
894
|
+
} catch {}
|
|
895
|
+
try {
|
|
896
|
+
capture.finishPiRun(aioFailed);
|
|
897
|
+
} catch {}
|
|
634
898
|
}
|
|
635
899
|
},
|
|
636
900
|
async runTask(inputs) {
|
|
637
|
-
const { runPiTask } = await import("./task-
|
|
901
|
+
const { runPiTask } = await import("./task-r9t1UhQP.js");
|
|
638
902
|
return runPiTask(inputs);
|
|
639
903
|
}
|
|
640
904
|
};
|
|
641
905
|
//#endregion
|
|
642
|
-
export { piBackend as a,
|
|
906
|
+
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
907
|
|
|
644
|
-
//# sourceMappingURL=pi-
|
|
908
|
+
//# sourceMappingURL=pi-D3h5Ok0i.js.map
|