@cydm/pie 4.3.2 → 4.3.4
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/im-forward/index.js +171 -759
- package/dist/builtin/extensions/pie-ipc/index.js +27 -4
- package/dist/chunks/chunk-HT6J4QOC.js +1054 -0
- package/dist/chunks/{concierge-cli-CQMIAGWJ.js → concierge-cli-MCHXTFBA.js} +11 -4
- package/dist/cli.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/chunk-GJLSYBFN.js +0 -359
|
@@ -21,9 +21,9 @@ ${CRON_SECTION_MARKER}
|
|
|
21
21
|
- \u4F60\u6240\u5728\u7684\u65E0\u503C\u5B88\u5BBF\u4E3B\u53EF\u4EE5\u81EA\u5DF1\u7528 cron_manage\uFF08\u65E0\u4EBA\u503C\u5B88\u4E0A\u81EA\u52A8\u6388\u6743\u5E76\u7559\u75D5\uFF0C\u4E0D\u5FC5\u7B49\u4EBA\u786E\u8BA4\uFF09\u3002\u9002\u5408\u201C\u6BCF\u5929 9 \u70B9\u7ED9\u6211\u7B80\u62A5\u201D\u8FD9\u7C7B\u56FA\u5B9A\u8282\u594F\u7684\u4E8B\uFF1B\u4E0D\u9002\u5408\u62FF\u6765\u4EE3\u66FF worker \u5E72\u6D3B\u3002
|
|
22
22
|
- \u5BBF\u4E3B\u91CD\u542F\u540E\uFF08\u5C24\u5176\u5D29\u6E83/\u65AD\u7535/OOM \u4E4B\u540E\uFF09\u7684\u7B2C\u4E00\u6B21\u5BF9\u8BDD\uFF0C\u5148\u7528 cron_manage list \u770B\u4E00\u773C\uFF1A\u82E5\u6709 blocked \u7684\u4EFB\u52A1\uFF0C\u8BF4\u660E\u4E0A\u6B21\u6267\u884C\u7ED3\u679C\u4E0D\u786E\u5B9A\uFF0C\u8981\u539F\u6837\u544A\u8BC9\u7528\u6237\u5E76\u7B49\u4ED6\u51B3\u5B9A\u662F\u5426 resume\uFF1B**\u4E0D\u8981\u81EA\u4F5C\u4E3B\u5F20 resume\uFF0C\u4E5F\u4E0D\u8981\u5220\u4E86\u91CD\u5EFA**\uFF08\u91CD\u5EFA\u4F1A\u4E22\u6389\u4E0D\u786E\u5B9A\u6267\u884C\u7684\u8BB0\u5F55\uFF09\u3002
|
|
23
23
|
`;
|
|
24
|
-
var SEED_AGENTS_MD = `# Pie Concierge
|
|
24
|
+
var SEED_AGENTS_MD = `# Pie Concierge (manager)
|
|
25
25
|
|
|
26
|
-
\u4F60\u662F\u7528\u6237\u7684\u5E38\u9A7B
|
|
26
|
+
\u4F60\u662F\u7528\u6237\u7684\u5E38\u9A7B manager pie\uFF1A\u7ED1\u5B9A IM\uFF08\u5E73\u53F0\u65E0\u5173\uFF09\uFF0C\u65E0\u4EBA\u503C\u5B88\uFF0C\u901A\u8FC7 IM \u4E0E\u7528\u6237\u5BF9\u8BDD\u3002
|
|
27
27
|
|
|
28
28
|
## \u89D2\u8272\u51C6\u5219
|
|
29
29
|
|
|
@@ -176,6 +176,13 @@ function seedWorkspace(dir) {
|
|
|
176
176
|
if (current.includes(v1Marker) && !current.includes(v2Marker)) {
|
|
177
177
|
fs.writeFileSync(agents, SEED_AGENTS_MD);
|
|
178
178
|
}
|
|
179
|
+
const oldV2Intro = "\u4F60\u662F\u7528\u6237\u7684\u5E38\u9A7B\u7BA1\u5BB6 pie";
|
|
180
|
+
const newV2Intro = "\u4F60\u662F\u7528\u6237\u7684\u5E38\u9A7B manager pie";
|
|
181
|
+
if (current.includes(oldV2Intro) && !current.includes(newV2Intro)) {
|
|
182
|
+
fs.writeFileSync(agents, SEED_AGENTS_MD);
|
|
183
|
+
} else if (current.includes("\u7BA1\u5BB6") && current.includes(v2Marker) && !current.includes(newV2Intro)) {
|
|
184
|
+
fs.appendFileSync(agents, "\n> \u6CE8\u610F\uFF1A\u5E38\u9A7B\u89D2\u8272\u5DF2\u66F4\u540D manager\uFF08\u539F\u300C\u7BA1\u5BB6\u300D\uFF09\u3002\u5982\u9700\u65B0\u7248\u89D2\u8272\u5361\u53EF\u624B\u52A8\u66F4\u65B0\u3002\n");
|
|
185
|
+
}
|
|
179
186
|
}
|
|
180
187
|
function isTooBroadForWorkerSandbox(input) {
|
|
181
188
|
let resolved;
|
|
@@ -274,10 +281,10 @@ function spawnResident(state, dir) {
|
|
|
274
281
|
detached: true,
|
|
275
282
|
stdio: ["ignore", out, out],
|
|
276
283
|
windowsHide: true,
|
|
277
|
-
// PIE_PROC_CURATED_NAME: the resident's display name is
|
|
284
|
+
// PIE_PROC_CURATED_NAME: the resident's display name is manager from the
|
|
278
285
|
// very first composition (v2 Phase 1.3) — never the first IM/terminal
|
|
279
286
|
// message title, never a flip-flopping derived label.
|
|
280
|
-
env: { ...process.env, PIE_PROC_CURATED_NAME: "
|
|
287
|
+
env: { ...process.env, PIE_PROC_CURATED_NAME: "manager" }
|
|
281
288
|
});
|
|
282
289
|
child.unref();
|
|
283
290
|
writeState({ ...state, pid: child.pid, startedAt: Date.now() });
|
package/dist/cli.js
CHANGED
|
@@ -86782,7 +86782,7 @@ async function main() {
|
|
|
86782
86782
|
return;
|
|
86783
86783
|
}
|
|
86784
86784
|
if (args[0] === STABLE_CLI_COMMANDS.concierge) {
|
|
86785
|
-
const { runConciergeCommand } = await import("./chunks/concierge-cli-
|
|
86785
|
+
const { runConciergeCommand } = await import("./chunks/concierge-cli-MCHXTFBA.js");
|
|
86786
86786
|
try {
|
|
86787
86787
|
await runConciergeCommand(args.slice(1));
|
|
86788
86788
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// builtin/extensions/pie-ipc/pure.ts
|
|
4
|
-
import { randomBytes } from "node:crypto";
|
|
5
|
-
var IPC_PROTOCOL_VERSION = 2;
|
|
6
|
-
var INSTANCE_ID_PATTERN = /^pie-[a-z0-9]{12}$/;
|
|
7
|
-
var MAX_STATUS_FILE_BYTES = 128 * 1024;
|
|
8
|
-
var MAX_DISPLAY_NAME_CHARS = 64;
|
|
9
|
-
var MAX_STATUS_TEXT_FIELD_CHARS = 4096;
|
|
10
|
-
var MAX_BODY_CHARS = 8e3;
|
|
11
|
-
var MAX_STATUS_BODY_CHARS = 2e3;
|
|
12
|
-
var STATUS_FILE_STALE_MS = 12e4;
|
|
13
|
-
var HEARTBEAT_INTERVAL_MS = 2e4;
|
|
14
|
-
var DEFAULT_SEND_WAIT_MS = 12e4;
|
|
15
|
-
var MAX_SEEN_ENVELOPE_IDS = 1e3;
|
|
16
|
-
var MAX_INBOX_MESSAGES = 100;
|
|
17
|
-
var MAX_INFLIGHT_SENDS = 8;
|
|
18
|
-
var INSTANCE_ID_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
19
|
-
function generateInstanceId(randomSource = defaultRandomBytes) {
|
|
20
|
-
const bytes = randomSource(12);
|
|
21
|
-
let id = "";
|
|
22
|
-
for (const byte of bytes) {
|
|
23
|
-
id += INSTANCE_ID_ALPHABET[byte % INSTANCE_ID_ALPHABET.length];
|
|
24
|
-
}
|
|
25
|
-
return `pie-${id}`;
|
|
26
|
-
}
|
|
27
|
-
function defaultRandomBytes(count) {
|
|
28
|
-
return randomBytes(count);
|
|
29
|
-
}
|
|
30
|
-
function isValidInstanceId(id) {
|
|
31
|
-
return INSTANCE_ID_PATTERN.test(id);
|
|
32
|
-
}
|
|
33
|
-
function peerLabel(instanceId, displayName) {
|
|
34
|
-
const name = displayName?.trim();
|
|
35
|
-
if (name) return name;
|
|
36
|
-
return instanceId.length > 12 ? instanceId.slice(0, 12) : instanceId;
|
|
37
|
-
}
|
|
38
|
-
var ENVELOPE_KINDS = /* @__PURE__ */ new Set([
|
|
39
|
-
"hello",
|
|
40
|
-
"bye",
|
|
41
|
-
"ping",
|
|
42
|
-
"message",
|
|
43
|
-
"ack",
|
|
44
|
-
"result",
|
|
45
|
-
"state.get",
|
|
46
|
-
"state",
|
|
47
|
-
"result.get",
|
|
48
|
-
"control"
|
|
49
|
-
]);
|
|
50
|
-
var LIFECYCLE_STATES = /* @__PURE__ */ new Set(["working", "idle", "blocked"]);
|
|
51
|
-
function parseEnvelope(raw) {
|
|
52
|
-
let parsed;
|
|
53
|
-
try {
|
|
54
|
-
parsed = JSON.parse(raw);
|
|
55
|
-
} catch {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
|
|
59
|
-
const record = parsed;
|
|
60
|
-
if (typeof record.v !== "number" || record.v !== IPC_PROTOCOL_VERSION) return null;
|
|
61
|
-
if (typeof record.id !== "string" || !/^[a-zA-Z0-9:-]{1,128}$/.test(record.id)) return null;
|
|
62
|
-
if (typeof record.from !== "string" || !isValidInstanceId(record.from)) return null;
|
|
63
|
-
if (typeof record.to !== "string" || !isValidInstanceId(record.to)) return null;
|
|
64
|
-
if (record.text !== void 0 && (typeof record.text !== "string" || record.text.length > MAX_BODY_CHARS + 100)) return null;
|
|
65
|
-
if (record.sessionId !== void 0 && (typeof record.sessionId !== "string" || record.sessionId.length > 256)) return null;
|
|
66
|
-
if (record.replyTo !== void 0 && (typeof record.replyTo !== "string" || !/^[a-zA-Z0-9:-]{1,128}$/.test(record.replyTo))) return null;
|
|
67
|
-
if (record.waitMs !== void 0 && (typeof record.waitMs !== "number" || !Number.isFinite(record.waitMs) || record.waitMs < 0 || record.waitMs > 6e5)) return null;
|
|
68
|
-
if (record.notifyCompletion !== void 0 && typeof record.notifyCompletion !== "boolean") return null;
|
|
69
|
-
if (record.subscriberSession !== void 0 && (typeof record.subscriberSession !== "string" || record.subscriberSession.length > 256)) return null;
|
|
70
|
-
if (typeof record.kind !== "string" || !ENVELOPE_KINDS.has(record.kind)) return null;
|
|
71
|
-
if (typeof record.createdAt !== "number" || !Number.isSafeInteger(record.createdAt) || record.createdAt < 0) return null;
|
|
72
|
-
const envelope = {
|
|
73
|
-
v: record.v,
|
|
74
|
-
id: record.id,
|
|
75
|
-
from: record.from,
|
|
76
|
-
to: record.to,
|
|
77
|
-
kind: record.kind,
|
|
78
|
-
createdAt: record.createdAt
|
|
79
|
-
};
|
|
80
|
-
if (typeof record.auth === "string" && /^[a-f0-9]{64}$/.test(record.auth)) envelope.auth = record.auth;
|
|
81
|
-
if (typeof record.sessionId === "string") envelope.sessionId = record.sessionId;
|
|
82
|
-
if (typeof record.text === "string") envelope.text = record.text;
|
|
83
|
-
if (typeof record.replyTo === "string") envelope.replyTo = record.replyTo;
|
|
84
|
-
if (typeof record.waitMs === "number" && Number.isFinite(record.waitMs)) envelope.waitMs = record.waitMs;
|
|
85
|
-
if (record.notifyCompletion === true) envelope.notifyCompletion = true;
|
|
86
|
-
if (record.control === true) envelope.control = true;
|
|
87
|
-
if (record.userAssigned === true) envelope.userAssigned = true;
|
|
88
|
-
if (typeof record.subscriberSession === "string") envelope.subscriberSession = record.subscriberSession;
|
|
89
|
-
return envelope;
|
|
90
|
-
}
|
|
91
|
-
var FrameTooLargeError = class extends Error {
|
|
92
|
-
constructor() {
|
|
93
|
-
super("pie-ipc frame exceeds byte cap");
|
|
94
|
-
this.name = "FrameTooLargeError";
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var FrameDecoder = class {
|
|
98
|
-
buffer = "";
|
|
99
|
-
get partial() {
|
|
100
|
-
return this.buffer.length > 0;
|
|
101
|
-
}
|
|
102
|
-
push(chunk) {
|
|
103
|
-
this.buffer += chunk;
|
|
104
|
-
if (this.buffer.split("\n").some((line) => Buffer.byteLength(line, "utf8") > 64 * 1024)) {
|
|
105
|
-
this.buffer = "";
|
|
106
|
-
throw new FrameTooLargeError();
|
|
107
|
-
}
|
|
108
|
-
const envelopes = [];
|
|
109
|
-
let newline = this.buffer.indexOf("\n");
|
|
110
|
-
while (newline !== -1) {
|
|
111
|
-
const line = this.buffer.slice(0, newline).trim();
|
|
112
|
-
this.buffer = this.buffer.slice(newline + 1);
|
|
113
|
-
if (line) {
|
|
114
|
-
const envelope = parseEnvelope(line);
|
|
115
|
-
if (envelope) envelopes.push(envelope);
|
|
116
|
-
}
|
|
117
|
-
newline = this.buffer.indexOf("\n");
|
|
118
|
-
}
|
|
119
|
-
return envelopes;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
var WRAP_PREFIX = "[pie-ipc]";
|
|
123
|
-
function wrapInboundText(fromLabel, text, at = Date.now(), messageId) {
|
|
124
|
-
const stamp = new Date(at).toISOString().slice(11, 19);
|
|
125
|
-
const marker = messageId ? ` #${clipMarker(messageId)} ` : " ";
|
|
126
|
-
return `${WRAP_PREFIX} ${stamp}${marker}peer "${clipLabel(fromLabel)}" says:
|
|
127
|
-
${clipBody(text, MAX_BODY_CHARS)}`;
|
|
128
|
-
}
|
|
129
|
-
function isWrappedInboundText(text) {
|
|
130
|
-
return text.startsWith(`${WRAP_PREFIX} `);
|
|
131
|
-
}
|
|
132
|
-
function wrappedMessageMarker(text) {
|
|
133
|
-
if (!isWrappedInboundText(text)) return null;
|
|
134
|
-
const firstLine = text.split("\n", 1)[0];
|
|
135
|
-
const match = / #(\S+) peer "/.exec(firstLine);
|
|
136
|
-
return match ? match[1] : null;
|
|
137
|
-
}
|
|
138
|
-
function clipMarker(id) {
|
|
139
|
-
const clipped = id;
|
|
140
|
-
return clipped || "noid";
|
|
141
|
-
}
|
|
142
|
-
function clipLabel(label) {
|
|
143
|
-
const collapsed = label.replace(/\s+/g, " ").trim().slice(0, 60);
|
|
144
|
-
return collapsed || "unknown";
|
|
145
|
-
}
|
|
146
|
-
function clipBody(text, maxChars = MAX_BODY_CHARS) {
|
|
147
|
-
if (text.length <= maxChars) return text;
|
|
148
|
-
return `${text.slice(0, maxChars)}\u2026[truncated ${text.length - maxChars} chars]`;
|
|
149
|
-
}
|
|
150
|
-
var BoundedIdSet = class {
|
|
151
|
-
constructor(max = MAX_SEEN_ENVELOPE_IDS) {
|
|
152
|
-
this.max = max;
|
|
153
|
-
}
|
|
154
|
-
max;
|
|
155
|
-
seen = /* @__PURE__ */ new Map();
|
|
156
|
-
/** Returns true when the id is new (and records it). */
|
|
157
|
-
add(id, now = Date.now()) {
|
|
158
|
-
if (this.seen.has(id)) return false;
|
|
159
|
-
this.seen.set(id, now);
|
|
160
|
-
if (this.seen.size > this.max) {
|
|
161
|
-
const drop = Math.max(1, Math.floor(this.max / 4));
|
|
162
|
-
let dropped = 0;
|
|
163
|
-
for (const key of this.seen.keys()) {
|
|
164
|
-
if (dropped >= drop) break;
|
|
165
|
-
this.seen.delete(key);
|
|
166
|
-
dropped += 1;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
has(id) {
|
|
172
|
-
return this.seen.has(id);
|
|
173
|
-
}
|
|
174
|
-
get size() {
|
|
175
|
-
return this.seen.size;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
var signalAliveCheck = (pid) => {
|
|
179
|
-
try {
|
|
180
|
-
process.kill(pid, 0);
|
|
181
|
-
return true;
|
|
182
|
-
} catch (error) {
|
|
183
|
-
return error.code === "EPERM";
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
function peerHealth(file, now = Date.now(), aliveCheck = signalAliveCheck) {
|
|
187
|
-
if (Number.isInteger(file.pid) && file.pid > 0 && !aliveCheck(file.pid)) return "dead";
|
|
188
|
-
if (now - file.updatedAt > STATUS_FILE_STALE_MS) return "stale";
|
|
189
|
-
return "alive";
|
|
190
|
-
}
|
|
191
|
-
function parseStatusFile(raw) {
|
|
192
|
-
let parsed;
|
|
193
|
-
try {
|
|
194
|
-
parsed = JSON.parse(raw);
|
|
195
|
-
} catch {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
|
|
199
|
-
const record = parsed;
|
|
200
|
-
if (record.schema !== 1) return null;
|
|
201
|
-
if (typeof record.instanceId !== "string" || !isValidInstanceId(record.instanceId)) return null;
|
|
202
|
-
if (typeof record.pid !== "number" || !Number.isInteger(record.pid) || record.pid <= 0 || record.pid > 99999999) return null;
|
|
203
|
-
if (typeof record.protocol !== "number" || record.protocol !== IPC_PROTOCOL_VERSION) return null;
|
|
204
|
-
if (typeof record.displayName !== "string" || !record.displayName || record.displayName.length > MAX_DISPLAY_NAME_CHARS) return null;
|
|
205
|
-
if (hasControlChars(record.displayName)) return null;
|
|
206
|
-
if (record.sessionId !== null && (typeof record.sessionId !== "string" || record.sessionId.length > 256 || hasControlChars(record.sessionId))) return null;
|
|
207
|
-
if (typeof record.cwd !== "string" || record.cwd.length > MAX_STATUS_TEXT_FIELD_CHARS || hasControlChars(record.cwd)) return null;
|
|
208
|
-
if (typeof record.startedAt !== "number" || !Number.isSafeInteger(record.startedAt) || record.startedAt < 0) return null;
|
|
209
|
-
if (typeof record.updatedAt !== "number" || !Number.isSafeInteger(record.updatedAt) || record.updatedAt < 0) return null;
|
|
210
|
-
if (typeof record.state !== "string" || !LIFECYCLE_STATES.has(record.state)) return null;
|
|
211
|
-
const file = {
|
|
212
|
-
schema: 1,
|
|
213
|
-
instanceId: record.instanceId,
|
|
214
|
-
pid: record.pid,
|
|
215
|
-
protocol: record.protocol,
|
|
216
|
-
displayName: record.displayName,
|
|
217
|
-
sessionId: record.sessionId,
|
|
218
|
-
cwd: record.cwd,
|
|
219
|
-
startedAt: record.startedAt,
|
|
220
|
-
updatedAt: record.updatedAt,
|
|
221
|
-
state: record.state
|
|
222
|
-
};
|
|
223
|
-
if (Array.isArray(record.allowPeers) && record.allowPeers.length <= 1e3 && record.allowPeers.every((id) => typeof id === "string" && (id === "*" || isValidInstanceId(id)))) file.allowPeers = record.allowPeers;
|
|
224
|
-
if (typeof record.secret === "string" && /^[a-f0-9]{64}$/.test(record.secret)) file.secret = record.secret;
|
|
225
|
-
if (typeof record.sessionName === "string" && !hasControlChars(record.sessionName) && record.sessionName.length <= MAX_DISPLAY_NAME_CHARS) file.sessionName = record.sessionName;
|
|
226
|
-
if (typeof record.currentTool === "string" && !hasControlChars(record.currentTool) && record.currentTool.length <= 200) file.currentTool = record.currentTool;
|
|
227
|
-
if (typeof record.blockedSince === "number" && Number.isSafeInteger(record.blockedSince) && record.blockedSince >= 0) file.blockedSince = record.blockedSince;
|
|
228
|
-
if (typeof record.turnStartedAt === "number" && Number.isSafeInteger(record.turnStartedAt) && record.turnStartedAt >= 0) file.turnStartedAt = record.turnStartedAt;
|
|
229
|
-
if (typeof record.undeliveredInjections === "number" && Number.isFinite(record.undeliveredInjections)) file.undeliveredInjections = Math.min(100, Math.max(0, Math.floor(record.undeliveredInjections)));
|
|
230
|
-
if (typeof record.lastBodyText === "string" && record.lastBodyText.length <= MAX_STATUS_TEXT_FIELD_CHARS && !/[\u0000-\u0008\u000b-\u001f\u007f]/.test(record.lastBodyText)) file.lastBodyText = record.lastBodyText;
|
|
231
|
-
if (typeof record.lastBodyAt === "number" && Number.isSafeInteger(record.lastBodyAt) && record.lastBodyAt >= 0) file.lastBodyAt = record.lastBodyAt;
|
|
232
|
-
if (typeof record.port === "number" && Number.isInteger(record.port) && record.port > 0 && record.port <= 65535) file.port = record.port;
|
|
233
|
-
return file;
|
|
234
|
-
}
|
|
235
|
-
function hasControlChars(text) {
|
|
236
|
-
return /[\u0000-\u001f\u007f]/.test(text);
|
|
237
|
-
}
|
|
238
|
-
var BLOCKING_TOOL_NAMES = /* @__PURE__ */ new Set(["ask_user_multi"]);
|
|
239
|
-
function isBlockingTool(toolName) {
|
|
240
|
-
return BLOCKING_TOOL_NAMES.has(toolName);
|
|
241
|
-
}
|
|
242
|
-
function foldLifecycleEvent(current, event, now = Date.now()) {
|
|
243
|
-
switch (event.type) {
|
|
244
|
-
case "turn:start":
|
|
245
|
-
case "agent:start": {
|
|
246
|
-
const next = { state: "working", turnStartedAt: now };
|
|
247
|
-
if (current.blockedSince !== void 0) next.blockedSince = current.blockedSince;
|
|
248
|
-
return next;
|
|
249
|
-
}
|
|
250
|
-
case "tool:execution:start": {
|
|
251
|
-
if (current.state === "idle") return { ...current, state: "working", turnStartedAt: current.turnStartedAt ?? now };
|
|
252
|
-
if (event.toolName && isBlockingTool(event.toolName) && current.state !== "blocked") {
|
|
253
|
-
return { ...current, state: "blocked", blockedSince: now, currentTool: event.toolName };
|
|
254
|
-
}
|
|
255
|
-
return { ...current, currentTool: event.toolName };
|
|
256
|
-
}
|
|
257
|
-
case "tool:execution:end": {
|
|
258
|
-
if (current.state === "blocked" && (!event.toolName || isBlockingTool(event.toolName))) {
|
|
259
|
-
return { ...current, state: "working", blockedSince: void 0, currentTool: void 0 };
|
|
260
|
-
}
|
|
261
|
-
return current;
|
|
262
|
-
}
|
|
263
|
-
case "turn:completed":
|
|
264
|
-
case "turn:failed":
|
|
265
|
-
case "turn:cancelled":
|
|
266
|
-
case "agent:end": {
|
|
267
|
-
if (current.state === "idle") return current;
|
|
268
|
-
return { state: "idle" };
|
|
269
|
-
}
|
|
270
|
-
default:
|
|
271
|
-
return current;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
function resolveIpcConfig(configLayers) {
|
|
275
|
-
const problems = [];
|
|
276
|
-
let invalidConfig = false;
|
|
277
|
-
const merged = {};
|
|
278
|
-
for (const layer of configLayers) {
|
|
279
|
-
if (layer.content === void 0) continue;
|
|
280
|
-
try {
|
|
281
|
-
const parsed = JSON.parse(layer.content);
|
|
282
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
283
|
-
problems.push(`${layer.file}: root is not an object`);
|
|
284
|
-
invalidConfig = true;
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
Object.assign(merged, parsed);
|
|
288
|
-
} catch (error) {
|
|
289
|
-
problems.push(`${layer.file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
290
|
-
invalidConfig = true;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (merged.enabled !== void 0 && typeof merged.enabled !== "boolean") {
|
|
294
|
-
problems.push("pie-ipc: enabled must be a boolean");
|
|
295
|
-
invalidConfig = true;
|
|
296
|
-
}
|
|
297
|
-
if (invalidConfig || merged.enabled === false) return { config: null, problems };
|
|
298
|
-
const config = { enabled: true, allowPeers: ["*"], autoInject: true };
|
|
299
|
-
if (typeof merged.displayName === "string" && merged.displayName.trim()) {
|
|
300
|
-
config.displayName = merged.displayName.replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, 60);
|
|
301
|
-
}
|
|
302
|
-
const envName = process.env.PIE_IPC_DISPLAY_NAME;
|
|
303
|
-
if (typeof envName === "string" && envName.trim()) {
|
|
304
|
-
config.displayName = envName.replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, 60);
|
|
305
|
-
}
|
|
306
|
-
if (Array.isArray(merged.allowPeers)) {
|
|
307
|
-
config.allowPeers = merged.allowPeers.filter((id) => typeof id === "string" && (id === "*" || isValidInstanceId(id))).slice(0, 1e3);
|
|
308
|
-
} else if (merged.allowPeers !== void 0) {
|
|
309
|
-
config.allowPeers = [];
|
|
310
|
-
problems.push("pie-ipc: allowPeers must be an array");
|
|
311
|
-
}
|
|
312
|
-
if (merged.autoInject !== void 0) config.autoInject = merged.autoInject === true;
|
|
313
|
-
if (typeof merged.maxBodyChars === "number" && Number.isFinite(merged.maxBodyChars)) {
|
|
314
|
-
const bounded = Math.min(Math.max(Math.floor(merged.maxBodyChars), 100), MAX_BODY_CHARS);
|
|
315
|
-
if (bounded !== merged.maxBodyChars) {
|
|
316
|
-
problems.push(`pie-ipc: maxBodyChars clamped to ${bounded}`);
|
|
317
|
-
}
|
|
318
|
-
config.maxBodyChars = bounded;
|
|
319
|
-
}
|
|
320
|
-
return { config, problems };
|
|
321
|
-
}
|
|
322
|
-
function assistantBodyText(message) {
|
|
323
|
-
if (message?.role !== "assistant" || !Array.isArray(message.content)) return "";
|
|
324
|
-
let text = "";
|
|
325
|
-
let hasToolCalls = false;
|
|
326
|
-
for (const block of message.content) {
|
|
327
|
-
if (typeof block !== "object" || block === null) continue;
|
|
328
|
-
const record = block;
|
|
329
|
-
if (record.type === "text" && typeof record.text === "string") text += record.text;
|
|
330
|
-
else if (record.type === "toolCall") hasToolCalls = true;
|
|
331
|
-
}
|
|
332
|
-
if (hasToolCalls) return "";
|
|
333
|
-
return text.trim();
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export {
|
|
337
|
-
IPC_PROTOCOL_VERSION,
|
|
338
|
-
MAX_STATUS_FILE_BYTES,
|
|
339
|
-
MAX_BODY_CHARS,
|
|
340
|
-
MAX_STATUS_BODY_CHARS,
|
|
341
|
-
HEARTBEAT_INTERVAL_MS,
|
|
342
|
-
DEFAULT_SEND_WAIT_MS,
|
|
343
|
-
MAX_INBOX_MESSAGES,
|
|
344
|
-
MAX_INFLIGHT_SENDS,
|
|
345
|
-
generateInstanceId,
|
|
346
|
-
isValidInstanceId,
|
|
347
|
-
peerLabel,
|
|
348
|
-
FrameDecoder,
|
|
349
|
-
wrapInboundText,
|
|
350
|
-
isWrappedInboundText,
|
|
351
|
-
wrappedMessageMarker,
|
|
352
|
-
clipBody,
|
|
353
|
-
BoundedIdSet,
|
|
354
|
-
peerHealth,
|
|
355
|
-
parseStatusFile,
|
|
356
|
-
foldLifecycleEvent,
|
|
357
|
-
resolveIpcConfig,
|
|
358
|
-
assistantBodyText
|
|
359
|
-
};
|