@cydm/pie 2.2.0 → 2.4.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/dist/builtin/extensions/ask-user/index.js +3 -3
- package/dist/builtin/extensions/computer-use/index.js +49 -12
- package/dist/builtin/extensions/computer-use/package.json +3 -0
- package/dist/builtin/extensions/computer-use/prebuilt/macos/arm64/pie-computer-use +0 -0
- package/dist/builtin/extensions/computer-use/prebuilt/macos/universal/pie-computer-use.app/Contents/MacOS/pie-computer-use +0 -0
- package/dist/builtin/extensions/computer-use/prebuilt/macos/x64/pie-computer-use +0 -0
- package/dist/builtin/extensions/computer-use/scripts/build-native.mjs +2 -1
- package/dist/builtin/extensions/computer-use/scripts/setup-helper.mjs +2 -2
- package/dist/builtin/extensions/computer-use/scripts/test-native-retention.mjs +204 -0
- package/dist/builtin/extensions/herdr-agent-state/index.js +272 -0
- package/dist/builtin/extensions/herdr-agent-state/package.json +11 -0
- package/dist/builtin/extensions/mcp-adapter/index.js +188 -74
- package/dist/builtin/extensions/plan-mode/index.js +3 -3
- package/dist/builtin/extensions/subagent/index.js +5 -5
- package/dist/builtin/extensions/todo/index.js +3 -3
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{cli-F2VCSVL4.js → cli-P4VG6ZZG.js} +48 -8
- package/dist/builtin/skills/skill-creator/scripts/pie_runner.mjs +33 -12
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +5 -7
- package/dist/chunks/{chunk-HH2Q2SNX.js → chunk-FKUEIYFQ.js} +8213 -7367
- package/dist/chunks/{chunk-G3SE3I2L.js → chunk-XVUV3IM2.js} +112 -40
- package/dist/chunks/{chunk-IM43UYVV.js → chunk-YRXXRLMQ.js} +75 -14
- package/dist/chunks/{chunk-QJH6YN2W.js → chunk-ZKHMNEXL.js} +1 -1
- package/dist/chunks/{src-QSP2OPHU.js → src-SXUQ7OY6.js} +2 -2
- package/dist/chunks/{test-stream-CVGWFLSX.js → test-stream-OD3B57AS.js} +1 -1
- package/dist/cli.js +1321 -894
- package/package.json +2 -2
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
import "../../../chunks/chunk-LZQXQOPJ.js";
|
|
3
|
+
|
|
4
|
+
// builtin/extensions/herdr-agent-state/index.ts
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
var AGENT_LABEL = "pie";
|
|
7
|
+
var SOURCE_ID = "pie";
|
|
8
|
+
var BLOCKING_TOOL_NAME = "ask_user_multi";
|
|
9
|
+
var REPORT_TIMEOUT_MS = 3e3;
|
|
10
|
+
var MAX_RESUME_ARGS = 64;
|
|
11
|
+
var MAX_RESUME_TOTAL_CHARS = 8192;
|
|
12
|
+
var RESUME_ARG_PATTERN = /^[A-Za-z0-9._:/=@,%+-]+$/;
|
|
13
|
+
var MESSAGE_MAX_CHARS = 120;
|
|
14
|
+
function readHerdrEnvironment(env = process.env) {
|
|
15
|
+
if (env.HERDR_ENV !== "1") return void 0;
|
|
16
|
+
const paneId = env.HERDR_PANE_ID;
|
|
17
|
+
const binPath = env.HERDR_BIN_PATH;
|
|
18
|
+
if (typeof paneId !== "string" || !paneId) return void 0;
|
|
19
|
+
if (typeof binPath !== "string" || !binPath) return void 0;
|
|
20
|
+
return { paneId, binPath };
|
|
21
|
+
}
|
|
22
|
+
function createReportSequencer(now = Date.now) {
|
|
23
|
+
let seq = now() * 1e3;
|
|
24
|
+
return () => {
|
|
25
|
+
seq += 1;
|
|
26
|
+
return seq;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function summarizeAskUserQuestion(args) {
|
|
30
|
+
if (!args || typeof args !== "object") return void 0;
|
|
31
|
+
const record = args;
|
|
32
|
+
let text = record.question;
|
|
33
|
+
if (typeof text !== "string" || !text.trim()) {
|
|
34
|
+
const questions = record.questions;
|
|
35
|
+
if (Array.isArray(questions) && questions.length > 0) {
|
|
36
|
+
const first = questions[0];
|
|
37
|
+
if (first && typeof first === "object") {
|
|
38
|
+
text = first.question;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (typeof text !== "string") return void 0;
|
|
43
|
+
const cleaned = text.replace(/\s+/g, " ").trim();
|
|
44
|
+
if (!cleaned) return void 0;
|
|
45
|
+
return cleaned.length > MESSAGE_MAX_CHARS ? `${cleaned.slice(0, MESSAGE_MAX_CHARS - 3)}...` : cleaned;
|
|
46
|
+
}
|
|
47
|
+
function buildResumeArgv(sessionId) {
|
|
48
|
+
const argv = ["pie", "chat", "--session-id", sessionId];
|
|
49
|
+
if (argv.length > MAX_RESUME_ARGS) return void 0;
|
|
50
|
+
if (argv.join(" ").length > MAX_RESUME_TOTAL_CHARS) return void 0;
|
|
51
|
+
for (const arg of argv) {
|
|
52
|
+
if (!RESUME_ARG_PATTERN.test(arg)) return void 0;
|
|
53
|
+
}
|
|
54
|
+
return argv;
|
|
55
|
+
}
|
|
56
|
+
function buildStateReportArgs(params) {
|
|
57
|
+
const args = [
|
|
58
|
+
"pane",
|
|
59
|
+
"report-agent",
|
|
60
|
+
params.paneId,
|
|
61
|
+
"--source",
|
|
62
|
+
params.source,
|
|
63
|
+
"--agent",
|
|
64
|
+
params.agent,
|
|
65
|
+
"--state",
|
|
66
|
+
params.state,
|
|
67
|
+
"--seq",
|
|
68
|
+
String(params.seq)
|
|
69
|
+
];
|
|
70
|
+
if (params.message) {
|
|
71
|
+
args.push("--message", params.message);
|
|
72
|
+
}
|
|
73
|
+
if (params.agentSessionId) {
|
|
74
|
+
args.push("--agent-session-id", params.agentSessionId);
|
|
75
|
+
}
|
|
76
|
+
if (params.resumeArgv && params.resumeArgv.length > 0) {
|
|
77
|
+
args.push("--", ...params.resumeArgv);
|
|
78
|
+
}
|
|
79
|
+
return args;
|
|
80
|
+
}
|
|
81
|
+
function buildSessionReportArgs(params) {
|
|
82
|
+
const args = [
|
|
83
|
+
"pane",
|
|
84
|
+
"report-agent-session",
|
|
85
|
+
params.paneId,
|
|
86
|
+
"--source",
|
|
87
|
+
params.source,
|
|
88
|
+
"--agent",
|
|
89
|
+
params.agent,
|
|
90
|
+
"--seq",
|
|
91
|
+
String(params.seq),
|
|
92
|
+
"--agent-session-id",
|
|
93
|
+
params.agentSessionId
|
|
94
|
+
];
|
|
95
|
+
if (params.resumeArgv?.length) args.push("--", ...params.resumeArgv);
|
|
96
|
+
return args;
|
|
97
|
+
}
|
|
98
|
+
function buildReleaseReportArgs(params) {
|
|
99
|
+
return [
|
|
100
|
+
"pane",
|
|
101
|
+
"release-agent",
|
|
102
|
+
params.paneId,
|
|
103
|
+
"--source",
|
|
104
|
+
params.source,
|
|
105
|
+
"--agent",
|
|
106
|
+
params.agent,
|
|
107
|
+
"--seq",
|
|
108
|
+
String(params.seq)
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
function spawnHerdrReport(binPath, args, timeoutMs = REPORT_TIMEOUT_MS) {
|
|
112
|
+
try {
|
|
113
|
+
const child = spawn(binPath, args, { detached: true, stdio: "ignore" });
|
|
114
|
+
let killTimer;
|
|
115
|
+
const clearTimers = () => {
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
if (killTimer) clearTimeout(killTimer);
|
|
118
|
+
};
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
try {
|
|
121
|
+
child.kill("SIGTERM");
|
|
122
|
+
killTimer = setTimeout(() => {
|
|
123
|
+
try {
|
|
124
|
+
if (child.exitCode === null && child.signalCode === null) child.kill("SIGKILL");
|
|
125
|
+
} catch {
|
|
126
|
+
}
|
|
127
|
+
}, 1e3);
|
|
128
|
+
killTimer.unref?.();
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}, timeoutMs);
|
|
132
|
+
timer.unref?.();
|
|
133
|
+
child.on("error", clearTimers);
|
|
134
|
+
child.on("exit", clearTimers);
|
|
135
|
+
child.unref();
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function attachHerdrReporter(host, herdr, transport = (args) => spawnHerdrReport(herdr.binPath, args), sequencer = createReportSequencer()) {
|
|
140
|
+
const nextSeq = sequencer;
|
|
141
|
+
let agentActive = false;
|
|
142
|
+
const blockingToolCalls = /* @__PURE__ */ new Map();
|
|
143
|
+
let blockedMessage;
|
|
144
|
+
let heldPane = false;
|
|
145
|
+
let lastSessionId;
|
|
146
|
+
let lastState;
|
|
147
|
+
let lastMessage;
|
|
148
|
+
function report(args) {
|
|
149
|
+
transport(args);
|
|
150
|
+
}
|
|
151
|
+
function publishState(options) {
|
|
152
|
+
const next = desiredState();
|
|
153
|
+
const unchanged = next.state === lastState && next.message === lastMessage && !options?.force && !options?.resumeArgv;
|
|
154
|
+
if (unchanged) return;
|
|
155
|
+
lastState = next.state;
|
|
156
|
+
lastMessage = next.message;
|
|
157
|
+
heldPane = true;
|
|
158
|
+
report(
|
|
159
|
+
buildStateReportArgs({
|
|
160
|
+
paneId: herdr.paneId,
|
|
161
|
+
source: SOURCE_ID,
|
|
162
|
+
agent: AGENT_LABEL,
|
|
163
|
+
state: next.state,
|
|
164
|
+
seq: nextSeq(),
|
|
165
|
+
message: next.message,
|
|
166
|
+
agentSessionId: lastSessionId,
|
|
167
|
+
resumeArgv: options?.resumeArgv
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
function publishSession(sessionId) {
|
|
172
|
+
const resumeArgv = buildResumeArgv(sessionId);
|
|
173
|
+
if (!heldPane) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
report(
|
|
177
|
+
buildSessionReportArgs({
|
|
178
|
+
paneId: herdr.paneId,
|
|
179
|
+
source: SOURCE_ID,
|
|
180
|
+
agent: AGENT_LABEL,
|
|
181
|
+
seq: nextSeq(),
|
|
182
|
+
agentSessionId: sessionId,
|
|
183
|
+
resumeArgv
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
function desiredState() {
|
|
188
|
+
if (blockingToolCalls.size > 0) {
|
|
189
|
+
return { state: "blocked", message: blockedMessage };
|
|
190
|
+
}
|
|
191
|
+
if (agentActive) {
|
|
192
|
+
return { state: "working" };
|
|
193
|
+
}
|
|
194
|
+
return { state: "idle" };
|
|
195
|
+
}
|
|
196
|
+
host.on("session:changed", (event) => {
|
|
197
|
+
const sessionId = typeof event.sessionId === "string" && event.sessionId ? event.sessionId : void 0;
|
|
198
|
+
const sessionIdChanged = sessionId !== lastSessionId;
|
|
199
|
+
lastSessionId = sessionId;
|
|
200
|
+
if (!heldPane) {
|
|
201
|
+
publishState({
|
|
202
|
+
force: true,
|
|
203
|
+
resumeArgv: sessionId ? buildResumeArgv(sessionId) : void 0
|
|
204
|
+
});
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (sessionIdChanged && sessionId) {
|
|
208
|
+
publishSession(sessionId);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
host.on("turn:start", () => {
|
|
212
|
+
agentActive = true;
|
|
213
|
+
publishState();
|
|
214
|
+
});
|
|
215
|
+
host.on("agent:end", () => {
|
|
216
|
+
agentActive = false;
|
|
217
|
+
blockingToolCalls.clear();
|
|
218
|
+
blockedMessage = void 0;
|
|
219
|
+
publishState();
|
|
220
|
+
});
|
|
221
|
+
host.on("tool:execution:start", (event) => {
|
|
222
|
+
if (event.toolName !== BLOCKING_TOOL_NAME) return;
|
|
223
|
+
const message = summarizeAskUserQuestion(event.args);
|
|
224
|
+
blockingToolCalls.set(event.toolCallId, message);
|
|
225
|
+
if (message) {
|
|
226
|
+
blockedMessage = message;
|
|
227
|
+
} else if (!blockedMessage) {
|
|
228
|
+
blockedMessage = "waiting for your answer";
|
|
229
|
+
}
|
|
230
|
+
publishState();
|
|
231
|
+
});
|
|
232
|
+
host.on("tool:execution:end", (event) => {
|
|
233
|
+
if (event.toolName !== BLOCKING_TOOL_NAME) return;
|
|
234
|
+
blockingToolCalls.delete(event.toolCallId);
|
|
235
|
+
blockedMessage = void 0;
|
|
236
|
+
for (const message of blockingToolCalls.values()) {
|
|
237
|
+
if (message) blockedMessage = message;
|
|
238
|
+
}
|
|
239
|
+
publishState();
|
|
240
|
+
});
|
|
241
|
+
host.registerCleanup?.((reason) => {
|
|
242
|
+
if (reason !== "shutdown") return;
|
|
243
|
+
if (!heldPane) return;
|
|
244
|
+
report(
|
|
245
|
+
buildReleaseReportArgs({
|
|
246
|
+
paneId: herdr.paneId,
|
|
247
|
+
source: SOURCE_ID,
|
|
248
|
+
agent: AGENT_LABEL,
|
|
249
|
+
seq: nextSeq()
|
|
250
|
+
})
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function herdrAgentStateExtension(ctx) {
|
|
255
|
+
const herdr = readHerdrEnvironment();
|
|
256
|
+
if (!herdr) return;
|
|
257
|
+
if (!ctx.hasUI) return;
|
|
258
|
+
ctx.log("herdr agent-state reporter enabled");
|
|
259
|
+
attachHerdrReporter(ctx, herdr);
|
|
260
|
+
}
|
|
261
|
+
export {
|
|
262
|
+
attachHerdrReporter,
|
|
263
|
+
buildReleaseReportArgs,
|
|
264
|
+
buildResumeArgv,
|
|
265
|
+
buildSessionReportArgs,
|
|
266
|
+
buildStateReportArgs,
|
|
267
|
+
createReportSequencer,
|
|
268
|
+
herdrAgentStateExtension as default,
|
|
269
|
+
readHerdrEnvironment,
|
|
270
|
+
spawnHerdrReport,
|
|
271
|
+
summarizeAskUserQuestion
|
|
272
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "herdr-agent-state-extension",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Report Pie interactive agent lifecycle state (working/idle/blocked), session identity, and resume command to the Herdr terminal workspace manager.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"pie": {
|
|
8
|
+
"name": "herdr-agent-state",
|
|
9
|
+
"main": "index.js"
|
|
10
|
+
}
|
|
11
|
+
}
|