@cydm/pie 4.9.0 → 4.10.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 +4 -4
- package/dist/builtin/extensions/im-forward/index.js +65 -33
- package/dist/builtin/extensions/memory/index.js +5 -5
- package/dist/builtin/extensions/pie-ipc/index.js +5 -5
- package/dist/builtin/extensions/pie-proc/index.js +336 -102
- package/dist/builtin/extensions/plan-mode/index.js +4 -4
- package/dist/builtin/extensions/subagent/index.js +5 -5
- package/dist/builtin/extensions/todo/index.js +4 -4
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +83 -10
- package/dist/chunks/{chunk-LRHNAG4V.js → chunk-5QMS6RQC.js} +7 -2
- package/dist/chunks/{chunk-EEC5PJTC.js → chunk-7LICWWUE.js} +3 -3
- package/dist/chunks/{chunk-BA4Z27XT.js → chunk-BQWHLYYZ.js} +1 -1
- package/dist/chunks/{chunk-Z5KL6AO2.js → chunk-BTUMBUDU.js} +2 -2
- package/dist/chunks/{chunk-WYXUF4MP.js → chunk-FC5AN5QP.js} +22 -1
- package/dist/chunks/{chunk-4UIUMTHG.js → chunk-G2K4GY6N.js} +1 -1
- package/dist/chunks/{chunk-DBDU3RRN.js → chunk-HK3FHIAH.js} +3 -3
- package/dist/chunks/{chunk-WBL73KRI.js → chunk-KWK7KTSZ.js} +1 -0
- package/dist/chunks/{chunk-PN6B54VT.js → chunk-XMTRKMBG.js} +6 -6
- package/dist/chunks/{host-image-fallback-RASJSVZY.js → host-image-fallback-3TEMOQM5.js} +1 -1
- package/dist/chunks/{model-registry-5TLYILYR.js → model-registry-QKJ3YVDS.js} +2 -2
- package/dist/chunks/{read-file-understanding-VPKDBV23.js → read-file-understanding-N2ZZQLTZ.js} +5 -5
- package/dist/chunks/{src-6QGGDHIW.js → src-3PSR2AAX.js} +3 -3
- package/dist/chunks/{src-2XI5P62J.js → src-D5GN4Q5O.js} +2 -2
- package/dist/chunks/{src-DI4MCAGT.js → src-F5N6O2HR.js} +4 -4
- package/dist/chunks/{src-CCEENRKC.js → src-TIDKYA5F.js} +1 -1
- package/dist/chunks/{test-stream-SYVWIPPW.js → test-stream-JAJHK44G.js} +1 -1
- package/dist/cli.js +2376 -1043
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
liveSessionHolder
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-KWK7KTSZ.js";
|
|
5
5
|
import {
|
|
6
6
|
registerWorkerLifecycleBridge
|
|
7
7
|
} from "../../../chunks/chunk-6WKBQZWM.js";
|
|
@@ -9,7 +9,11 @@ import {
|
|
|
9
9
|
readProcessCommandLine
|
|
10
10
|
} from "../../../chunks/chunk-7RJXKN7N.js";
|
|
11
11
|
import "../../../chunks/chunk-ZPJ3BNQB.js";
|
|
12
|
+
import {
|
|
13
|
+
loadResolvedModelsConfig
|
|
14
|
+
} from "../../../chunks/chunk-FC5AN5QP.js";
|
|
12
15
|
import "../../../chunks/chunk-CBDQJMUI.js";
|
|
16
|
+
import "../../../chunks/chunk-G2K4GY6N.js";
|
|
13
17
|
import {
|
|
14
18
|
Type
|
|
15
19
|
} from "../../../chunks/chunk-XXGYUYXI.js";
|
|
@@ -19,9 +23,9 @@ import "../../../chunks/chunk-LZQXQOPJ.js";
|
|
|
19
23
|
import { execFileSync, spawn } from "node:child_process";
|
|
20
24
|
import { createRequire } from "node:module";
|
|
21
25
|
import { fileURLToPath } from "node:url";
|
|
22
|
-
import * as
|
|
26
|
+
import * as fs3 from "node:fs";
|
|
23
27
|
import * as os from "node:os";
|
|
24
|
-
import * as
|
|
28
|
+
import * as path3 from "node:path";
|
|
25
29
|
|
|
26
30
|
// builtin/extensions/pie-proc/panel-bridge.ts
|
|
27
31
|
import * as fs from "node:fs";
|
|
@@ -133,7 +137,7 @@ function registerPieProcPanelBridge(deps) {
|
|
|
133
137
|
try {
|
|
134
138
|
const hasWorkerIm = fs.existsSync(path.join(deps.pieProcDir(), "agents", info.name, "im-forward.json"));
|
|
135
139
|
const inheritIm = !hasWorkerIm && deps.canInheritImForward();
|
|
136
|
-
const res = deps.spawnResumeWorker({ name: info.name, cwd: info.cwd, resumeSessionId: sessionId, inheritIm });
|
|
140
|
+
const res = await deps.spawnResumeWorker({ name: info.name, cwd: info.cwd, resumeSessionId: sessionId, inheritIm });
|
|
137
141
|
const detail = res.content[0]?.text ?? "spawned";
|
|
138
142
|
const pidMatch = /\bpid (\d+)\b/.exec(detail);
|
|
139
143
|
return { ok: res.isError !== true, detail, name: info.name, ...pidMatch ? { pid: Number(pidMatch[1]) } : {} };
|
|
@@ -144,6 +148,241 @@ function registerPieProcPanelBridge(deps) {
|
|
|
144
148
|
});
|
|
145
149
|
}
|
|
146
150
|
|
|
151
|
+
// builtin/extensions/pie-proc/spawn-model.ts
|
|
152
|
+
import * as fs2 from "node:fs";
|
|
153
|
+
import * as path2 from "node:path";
|
|
154
|
+
var SPAWN_THINKING_LEVELS = /* @__PURE__ */ new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
|
155
|
+
var MODEL_REF_RE = /^[^/\s]+\/\S+$/;
|
|
156
|
+
function collectModelRefsFromRaw(raw) {
|
|
157
|
+
const refs = /* @__PURE__ */ new Set();
|
|
158
|
+
if (!raw || typeof raw !== "object") return refs;
|
|
159
|
+
const doc = raw;
|
|
160
|
+
if (doc.providers && typeof doc.providers === "object") {
|
|
161
|
+
for (const [provider, cfg] of Object.entries(doc.providers)) {
|
|
162
|
+
if (!Array.isArray(cfg?.models)) continue;
|
|
163
|
+
for (const m of cfg.models) {
|
|
164
|
+
if (typeof m?.id === "string" && m.id.trim()) {
|
|
165
|
+
refs.add(`${provider.trim()}/${m.id.trim()}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (doc.defaults && typeof doc.defaults === "object") {
|
|
171
|
+
if (typeof doc.defaults.provider === "string" && typeof doc.defaults.modelId === "string") {
|
|
172
|
+
refs.add(`${doc.defaults.provider.trim()}/${doc.defaults.modelId.trim()}`);
|
|
173
|
+
}
|
|
174
|
+
if (doc.defaults.modelClasses && typeof doc.defaults.modelClasses === "object") {
|
|
175
|
+
for (const cls of Object.values(doc.defaults.modelClasses)) {
|
|
176
|
+
if (typeof cls?.provider === "string" && typeof cls?.modelId === "string") {
|
|
177
|
+
refs.add(`${cls.provider.trim()}/${cls.modelId.trim()}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return refs;
|
|
183
|
+
}
|
|
184
|
+
function readKnownModelRefs(modelsPath) {
|
|
185
|
+
if (!fs2.existsSync(modelsPath)) return void 0;
|
|
186
|
+
try {
|
|
187
|
+
const resolved = loadResolvedModelsConfig(modelsPath);
|
|
188
|
+
const refs = collectModelRefsFromRaw(resolved.config);
|
|
189
|
+
if (refs.size > 0) return refs;
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const raw = JSON.parse(fs2.readFileSync(modelsPath, "utf8"));
|
|
194
|
+
const refs = collectModelRefsFromRaw(raw);
|
|
195
|
+
return refs.size > 0 ? refs : void 0;
|
|
196
|
+
} catch {
|
|
197
|
+
return void 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function validateSpawnModelParams(opts) {
|
|
201
|
+
let model;
|
|
202
|
+
let thinkingLevel;
|
|
203
|
+
if (opts.thinkingLevel !== void 0) {
|
|
204
|
+
const normalized = opts.thinkingLevel.trim();
|
|
205
|
+
if (!SPAWN_THINKING_LEVELS.has(normalized)) {
|
|
206
|
+
throw new Error(`invalid thinkingLevel "${opts.thinkingLevel}" (expected one of: ${[...SPAWN_THINKING_LEVELS].join(", ")})`);
|
|
207
|
+
}
|
|
208
|
+
thinkingLevel = normalized;
|
|
209
|
+
}
|
|
210
|
+
if (opts.model !== void 0) {
|
|
211
|
+
const normalized = opts.model.trim();
|
|
212
|
+
if (!MODEL_REF_RE.test(normalized)) {
|
|
213
|
+
throw new Error(`invalid model "${opts.model}" (expected "provider/modelId")`);
|
|
214
|
+
}
|
|
215
|
+
const workerModels = path2.join(opts.pieDir, "models.json");
|
|
216
|
+
const parentModels = path2.join(opts.parentConfigDir, "models.json");
|
|
217
|
+
const known = readKnownModelRefs(workerModels) ?? readKnownModelRefs(parentModels);
|
|
218
|
+
if (known && known.size > 0) {
|
|
219
|
+
if (known.has(normalized)) {
|
|
220
|
+
model = normalized;
|
|
221
|
+
} else {
|
|
222
|
+
const lowerTarget = normalized.toLowerCase();
|
|
223
|
+
const ciMatches = [...known].filter((ref) => ref.toLowerCase() === lowerTarget);
|
|
224
|
+
if (ciMatches.length === 1) {
|
|
225
|
+
model = ciMatches[0];
|
|
226
|
+
} else if (ciMatches.length > 1) {
|
|
227
|
+
throw new Error(`model "${normalized}" is ambiguous (matches: ${ciMatches.join(", ")}); use exact casing`);
|
|
228
|
+
} else {
|
|
229
|
+
const sample = [...known].slice(0, 8).join(", ");
|
|
230
|
+
throw new Error(`model "${normalized}" not found in models.json (available examples: ${sample})`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
model = normalized;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return { model, thinkingLevel };
|
|
238
|
+
}
|
|
239
|
+
function readSettingsDefaults(settingsPath) {
|
|
240
|
+
try {
|
|
241
|
+
if (!fs2.existsSync(settingsPath)) return {};
|
|
242
|
+
const raw = JSON.parse(fs2.readFileSync(settingsPath, "utf8"));
|
|
243
|
+
const provider = typeof raw.defaultProvider === "string" ? raw.defaultProvider.trim() : "";
|
|
244
|
+
const modelId = typeof raw.defaultModel === "string" ? raw.defaultModel.trim() : "";
|
|
245
|
+
const thinking = typeof raw.defaultThinkingLevel === "string" && SPAWN_THINKING_LEVELS.has(raw.defaultThinkingLevel.trim()) ? raw.defaultThinkingLevel.trim() : void 0;
|
|
246
|
+
return {
|
|
247
|
+
...provider && modelId ? { model: `${provider}/${modelId}` } : {},
|
|
248
|
+
...thinking ? { thinkingLevel: thinking } : {}
|
|
249
|
+
};
|
|
250
|
+
} catch {
|
|
251
|
+
return {};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function readModelsJsonDefault(modelsPath) {
|
|
255
|
+
const known = readKnownModelRefs(modelsPath);
|
|
256
|
+
if (!known || known.size === 0) return void 0;
|
|
257
|
+
try {
|
|
258
|
+
const raw = JSON.parse(fs2.readFileSync(modelsPath, "utf8"));
|
|
259
|
+
if (typeof raw.defaults?.provider === "string" && typeof raw.defaults?.modelId === "string") {
|
|
260
|
+
const ref = `${raw.defaults.provider.trim()}/${raw.defaults.modelId.trim()}`;
|
|
261
|
+
if (MODEL_REF_RE.test(ref)) return ref;
|
|
262
|
+
}
|
|
263
|
+
} catch {
|
|
264
|
+
}
|
|
265
|
+
return [...known][0];
|
|
266
|
+
}
|
|
267
|
+
function readSessionHeadModel(sessionsDir, sessionId) {
|
|
268
|
+
try {
|
|
269
|
+
const headPath = path2.join(sessionsDir, sessionId, "head.json");
|
|
270
|
+
if (!fs2.existsSync(headPath)) return {};
|
|
271
|
+
const parsed = JSON.parse(fs2.readFileSync(headPath, "utf8"));
|
|
272
|
+
const meta = parsed.metadata;
|
|
273
|
+
const provider = typeof meta?.provider === "string" ? meta.provider.trim() : "";
|
|
274
|
+
const modelId = typeof meta?.modelId === "string" ? meta.modelId.trim() : "";
|
|
275
|
+
const thinking = typeof meta?.thinkingLevel === "string" && SPAWN_THINKING_LEVELS.has(meta.thinkingLevel.trim()) ? meta.thinkingLevel.trim() : void 0;
|
|
276
|
+
return {
|
|
277
|
+
...provider && modelId ? { model: `${provider}/${modelId}` } : {},
|
|
278
|
+
...thinking ? { thinkingLevel: thinking } : {}
|
|
279
|
+
};
|
|
280
|
+
} catch {
|
|
281
|
+
return {};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function predictWorkerModel(opts) {
|
|
285
|
+
const projectDefaults = readSettingsDefaults(path2.join(opts.cwd, ".pie", "settings.json"));
|
|
286
|
+
const workerDefaults = readSettingsDefaults(path2.join(opts.pieDir, "settings.json"));
|
|
287
|
+
const fallbackModel = readModelsJsonDefault(path2.join(opts.pieDir, "models.json"));
|
|
288
|
+
const model = opts.explicitModel ?? opts.resumed?.model ?? projectDefaults.model ?? workerDefaults.model ?? fallbackModel;
|
|
289
|
+
const thinkingLevel = opts.explicitThinking ?? opts.resumed?.thinkingLevel ?? projectDefaults.thinkingLevel ?? workerDefaults.thinkingLevel;
|
|
290
|
+
return { model, thinkingLevel };
|
|
291
|
+
}
|
|
292
|
+
function isPidAlive(pid) {
|
|
293
|
+
if (!Number.isSafeInteger(pid) || pid <= 1) return false;
|
|
294
|
+
try {
|
|
295
|
+
process.kill(pid, 0);
|
|
296
|
+
return true;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
return error.code === "EPERM";
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function readLiveWorkerPeer(ipcRoot, sessionId, pid) {
|
|
302
|
+
try {
|
|
303
|
+
const dir = path2.join(ipcRoot, "run", "ipc");
|
|
304
|
+
if (!fs2.existsSync(dir)) return void 0;
|
|
305
|
+
for (const file of fs2.readdirSync(dir)) {
|
|
306
|
+
if (!file.endsWith(".json")) continue;
|
|
307
|
+
try {
|
|
308
|
+
const parsed = JSON.parse(fs2.readFileSync(path2.join(dir, file), "utf8"));
|
|
309
|
+
if (parsed.pid !== pid || parsed.sessionId !== sessionId) continue;
|
|
310
|
+
if (!isPidAlive(pid)) return void 0;
|
|
311
|
+
return {
|
|
312
|
+
model: typeof parsed.model === "string" && parsed.model ? parsed.model : void 0,
|
|
313
|
+
thinkingLevel: typeof parsed.thinkingLevel === "string" && parsed.thinkingLevel ? parsed.thinkingLevel : void 0,
|
|
314
|
+
effectiveThinkingLevel: typeof parsed.effectiveThinkingLevel === "string" && parsed.effectiveThinkingLevel ? parsed.effectiveThinkingLevel : void 0,
|
|
315
|
+
state: typeof parsed.state === "string" && parsed.state ? parsed.state : void 0
|
|
316
|
+
};
|
|
317
|
+
} catch {
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
} catch {
|
|
321
|
+
}
|
|
322
|
+
return void 0;
|
|
323
|
+
}
|
|
324
|
+
async function waitForWorkerIpcReady(opts) {
|
|
325
|
+
const rawEnv = process.env.PIE_PROC_SPAWN_READY_WAIT_MS;
|
|
326
|
+
const envWait = rawEnv !== void 0 ? Number(rawEnv) : Number.NaN;
|
|
327
|
+
const timeoutMs = Number.isFinite(envWait) && envWait >= 0 ? envWait : opts.timeoutMs ?? 3e3;
|
|
328
|
+
const pollMs = opts.pollIntervalMs ?? 100;
|
|
329
|
+
if (timeoutMs <= 0) {
|
|
330
|
+
return { peer: readLiveWorkerPeer(opts.ipcRoot, opts.sessionId, opts.pid), exitedEarly: !isPidAlive(opts.pid) };
|
|
331
|
+
}
|
|
332
|
+
const deadline = Date.now() + timeoutMs;
|
|
333
|
+
while (Date.now() <= deadline) {
|
|
334
|
+
const peer = readLiveWorkerPeer(opts.ipcRoot, opts.sessionId, opts.pid);
|
|
335
|
+
if (peer) return { peer, exitedEarly: false };
|
|
336
|
+
if (!isPidAlive(opts.pid)) return { exitedEarly: true };
|
|
337
|
+
const remaining = deadline - Date.now();
|
|
338
|
+
if (remaining <= 0) break;
|
|
339
|
+
await new Promise((resolve2) => setTimeout(resolve2, Math.min(pollMs, remaining)));
|
|
340
|
+
}
|
|
341
|
+
return { peer: readLiveWorkerPeer(opts.ipcRoot, opts.sessionId, opts.pid), exitedEarly: !isPidAlive(opts.pid) };
|
|
342
|
+
}
|
|
343
|
+
function formatSpawnModelSummary(opts) {
|
|
344
|
+
const model = opts.livePeer?.model ?? opts.predicted.model ?? "unconfigured";
|
|
345
|
+
const thinking = opts.livePeer?.effectiveThinkingLevel ?? opts.livePeer?.thinkingLevel ?? opts.predicted.thinkingLevel;
|
|
346
|
+
const base = thinking ? `${model} (${thinking})` : model;
|
|
347
|
+
if (opts.kind === "resident" && !opts.livePeer) return `${base} [starting]`;
|
|
348
|
+
return base;
|
|
349
|
+
}
|
|
350
|
+
async function buildSpawnReceipt(opts) {
|
|
351
|
+
const resumed = opts.resumeSessionId && opts.resumeSessionsDir ? readSessionHeadModel(opts.resumeSessionsDir, opts.resumeSessionId) : void 0;
|
|
352
|
+
const predicted = predictWorkerModel({
|
|
353
|
+
pieDir: opts.pieDir,
|
|
354
|
+
cwd: opts.cwd,
|
|
355
|
+
explicitModel: opts.explicitModel,
|
|
356
|
+
explicitThinking: opts.explicitThinking,
|
|
357
|
+
resumed
|
|
358
|
+
});
|
|
359
|
+
const ready = opts.kind === "resident" ? await waitForWorkerIpcReady({ ipcRoot: opts.ipcRoot, sessionId: opts.sessionId, pid: opts.pid }) : { peer: void 0, exitedEarly: false };
|
|
360
|
+
const modelLabel = formatSpawnModelSummary({ livePeer: ready.peer, predicted, kind: opts.kind });
|
|
361
|
+
const bootNote = ready.exitedEarly ? " WARNING: worker process exited during startup \u2014 inspect log." : "";
|
|
362
|
+
const ttlPart = opts.kind === "resident" && opts.ttlMs ? `, idle TTL ${Math.round(opts.ttlMs / 1e3)}s` : "";
|
|
363
|
+
const text = `Spawned ${opts.kind} worker "${opts.name}" (pid ${opts.pid}, peer name "${opts.name}", session ${opts.sessionId}, model: ${modelLabel}, cwd ${opts.cwd}${ttlPart}).${bootNote} Resident workers accept ipc_send_notify by peer name "${opts.name}"; their stdout events are at ${opts.logPath}.`;
|
|
364
|
+
return { modelLabel, text };
|
|
365
|
+
}
|
|
366
|
+
function inheritWorkerConfigFiles(pieDir, parentConfigDir) {
|
|
367
|
+
for (const file of ["models.json", "config.json", "auth.json", "settings.json"]) {
|
|
368
|
+
const dst = path2.join(pieDir, file);
|
|
369
|
+
const src = path2.join(parentConfigDir, file);
|
|
370
|
+
if (!fs2.existsSync(dst) && fs2.existsSync(src)) {
|
|
371
|
+
try {
|
|
372
|
+
fs2.copyFileSync(src, dst);
|
|
373
|
+
} catch {
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function liveWorkerModelLabel(ipcRoot, sessionId, pid) {
|
|
379
|
+
if (pid <= 0) return void 0;
|
|
380
|
+
const peer = readLiveWorkerPeer(ipcRoot, sessionId, pid);
|
|
381
|
+
if (!peer?.model) return void 0;
|
|
382
|
+
const lvl = peer.effectiveThinkingLevel ?? peer.thinkingLevel;
|
|
383
|
+
return lvl ? `${peer.model} (${lvl})` : peer.model;
|
|
384
|
+
}
|
|
385
|
+
|
|
147
386
|
// builtin/extensions/pie-proc/index.ts
|
|
148
387
|
var require_ = createRequire(import.meta.url);
|
|
149
388
|
function resolveOperatorSessionsDir() {
|
|
@@ -153,11 +392,11 @@ function resolveOperatorSessionsDir() {
|
|
|
153
392
|
} catch {
|
|
154
393
|
const override = process.env.PIE_SESSIONS_DIR;
|
|
155
394
|
if (override !== void 0 && override !== "") {
|
|
156
|
-
if (override === "~") return
|
|
157
|
-
if (override.startsWith("~/")) return
|
|
158
|
-
if (
|
|
395
|
+
if (override === "~") return path3.join(os.homedir(), ".pie", "sessions");
|
|
396
|
+
if (override.startsWith("~/")) return path3.join(os.homedir(), override.slice(2));
|
|
397
|
+
if (path3.isAbsolute(override)) return override;
|
|
159
398
|
}
|
|
160
|
-
return
|
|
399
|
+
return path3.join(os.homedir(), ".pie", "sessions");
|
|
161
400
|
}
|
|
162
401
|
}
|
|
163
402
|
var DEFAULT_MAX_WORKERS = 50;
|
|
@@ -167,20 +406,20 @@ var ONESHOT_TASK_ENV = "PIE_PROC_ONESHOT_TASK";
|
|
|
167
406
|
var LAUNCH_TOKEN_ENV = "PIE_PROC_LAUNCH_TOKEN";
|
|
168
407
|
function configDirRoot() {
|
|
169
408
|
const env = process.env.PIE_CODING_AGENT_DIR;
|
|
170
|
-
if (!env) return
|
|
171
|
-
return
|
|
409
|
+
if (!env) return path3.join(os.homedir(), ".pie");
|
|
410
|
+
return path3.resolve(expandTilde(env));
|
|
172
411
|
}
|
|
173
412
|
function expandTilde(p) {
|
|
174
|
-
return p === "~" ? os.homedir() : p.startsWith("~/") ?
|
|
413
|
+
return p === "~" ? os.homedir() : p.startsWith("~/") ? path3.join(os.homedir(), p.slice(2)) : p;
|
|
175
414
|
}
|
|
176
415
|
function configCandidates() {
|
|
177
|
-
const candidates = [
|
|
416
|
+
const candidates = [path3.join(configDirRoot(), "pie-proc.json")];
|
|
178
417
|
const pinnedRoot = process.env.PIE_PROC_REGISTRY_ROOT;
|
|
179
418
|
if (pinnedRoot) {
|
|
180
|
-
const pinDerived =
|
|
419
|
+
const pinDerived = path3.join(path3.dirname(path3.resolve(expandTilde(pinnedRoot))), "pie-proc.json");
|
|
181
420
|
if (!candidates.includes(pinDerived)) candidates.push(pinDerived);
|
|
182
|
-
} else if (configDirRoot() !==
|
|
183
|
-
candidates.push(
|
|
421
|
+
} else if (configDirRoot() !== path3.join(os.homedir(), ".pie")) {
|
|
422
|
+
candidates.push(path3.join(os.homedir(), ".pie", "pie-proc.json"));
|
|
184
423
|
}
|
|
185
424
|
return candidates;
|
|
186
425
|
}
|
|
@@ -188,7 +427,7 @@ function readConfig() {
|
|
|
188
427
|
const candidates = configCandidates();
|
|
189
428
|
for (const file of candidates) {
|
|
190
429
|
try {
|
|
191
|
-
const raw = JSON.parse(
|
|
430
|
+
const raw = JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
192
431
|
return {
|
|
193
432
|
allowCwd: Array.isArray(raw.allowCwd) ? raw.allowCwd.map(expandTilde) : [],
|
|
194
433
|
maxWorkers: typeof raw.maxWorkers === "number" && raw.maxWorkers > 0 ? Math.floor(raw.maxWorkers) : DEFAULT_CONFIG.maxWorkers,
|
|
@@ -196,21 +435,21 @@ function readConfig() {
|
|
|
196
435
|
defaultTtlMs: typeof raw.defaultTtlMs === "number" && raw.defaultTtlMs >= 0 ? Math.floor(raw.defaultTtlMs) : DEFAULT_CONFIG.defaultTtlMs
|
|
197
436
|
};
|
|
198
437
|
} catch {
|
|
199
|
-
if (
|
|
438
|
+
if (fs3.existsSync(file)) return { ...DEFAULT_CONFIG };
|
|
200
439
|
}
|
|
201
440
|
}
|
|
202
441
|
return { ...DEFAULT_CONFIG };
|
|
203
442
|
}
|
|
204
443
|
function pieProcDir() {
|
|
205
444
|
const pinned = process.env.PIE_PROC_REGISTRY_ROOT;
|
|
206
|
-
if (pinned) return
|
|
207
|
-
return
|
|
445
|
+
if (pinned) return path3.resolve(expandTilde(pinned));
|
|
446
|
+
return path3.join(configDirRoot(), "pie-proc");
|
|
208
447
|
}
|
|
209
448
|
function registryFile() {
|
|
210
|
-
return
|
|
449
|
+
return path3.join(pieProcDir(), "workers.json");
|
|
211
450
|
}
|
|
212
451
|
function revisionFile(n) {
|
|
213
|
-
return
|
|
452
|
+
return path3.join(pieProcDir(), `workers.r${n}.json`);
|
|
214
453
|
}
|
|
215
454
|
function parseRegistry(rawText, file, revision) {
|
|
216
455
|
let raw;
|
|
@@ -242,7 +481,7 @@ function parseRegistry(rawText, file, revision) {
|
|
|
242
481
|
function latestRevisionOnDisk() {
|
|
243
482
|
let max = 0;
|
|
244
483
|
try {
|
|
245
|
-
for (const entry of
|
|
484
|
+
for (const entry of fs3.readdirSync(pieProcDir())) {
|
|
246
485
|
const match = /^workers\.r(\d+)\.json$/.exec(entry);
|
|
247
486
|
if (match) max = Math.max(max, Number(match[1]));
|
|
248
487
|
}
|
|
@@ -256,7 +495,7 @@ function readRegistryUncached() {
|
|
|
256
495
|
if (latest > 0) {
|
|
257
496
|
const file2 = revisionFile(latest);
|
|
258
497
|
try {
|
|
259
|
-
return parseRegistry(
|
|
498
|
+
return parseRegistry(fs3.readFileSync(file2, "utf8"), file2, latest);
|
|
260
499
|
} catch (error) {
|
|
261
500
|
if (error.code === "ENOENT") continue;
|
|
262
501
|
throw error;
|
|
@@ -264,7 +503,7 @@ function readRegistryUncached() {
|
|
|
264
503
|
}
|
|
265
504
|
const file = registryFile();
|
|
266
505
|
try {
|
|
267
|
-
return parseRegistry(
|
|
506
|
+
return parseRegistry(fs3.readFileSync(file, "utf8"), file, 0);
|
|
268
507
|
} catch (error) {
|
|
269
508
|
if (error.code === "ENOENT") return { revision: 0, workers: [] };
|
|
270
509
|
throw error;
|
|
@@ -275,7 +514,7 @@ function readRegistryUncached() {
|
|
|
275
514
|
function compactRevisions(_current) {
|
|
276
515
|
}
|
|
277
516
|
function casRegistry(mutate) {
|
|
278
|
-
|
|
517
|
+
fs3.mkdirSync(pieProcDir(), { recursive: true });
|
|
279
518
|
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
280
519
|
const snapshot = readRegistryUncached();
|
|
281
520
|
const outcome = mutate(snapshot);
|
|
@@ -286,26 +525,26 @@ function casRegistry(mutate) {
|
|
|
286
525
|
const nextRevision = snapshot.revision + 1;
|
|
287
526
|
const target = revisionFile(nextRevision);
|
|
288
527
|
const tmp = `${target}.${process.pid}.${Date.now().toString(36)}-${attempt}.tmp`;
|
|
289
|
-
|
|
528
|
+
fs3.writeFileSync(tmp, JSON.stringify({ version: 2, revision: nextRevision, workers: outcome.next }, null, " "));
|
|
290
529
|
if (latestRevisionOnDisk() > snapshot.revision) {
|
|
291
530
|
try {
|
|
292
|
-
|
|
531
|
+
fs3.rmSync(tmp, { force: true });
|
|
293
532
|
} catch {
|
|
294
533
|
}
|
|
295
534
|
continue;
|
|
296
535
|
}
|
|
297
536
|
try {
|
|
298
|
-
|
|
537
|
+
fs3.linkSync(tmp, target);
|
|
299
538
|
} catch (error) {
|
|
300
539
|
try {
|
|
301
|
-
|
|
540
|
+
fs3.rmSync(tmp, { force: true });
|
|
302
541
|
} catch {
|
|
303
542
|
}
|
|
304
543
|
if (error.code === "EEXIST") continue;
|
|
305
544
|
throw error;
|
|
306
545
|
}
|
|
307
546
|
try {
|
|
308
|
-
|
|
547
|
+
fs3.rmSync(tmp, { force: true });
|
|
309
548
|
} catch {
|
|
310
549
|
}
|
|
311
550
|
compactRevisions(nextRevision);
|
|
@@ -399,7 +638,7 @@ function verifyProcessEnvOwnership(pid, marker, pieDir) {
|
|
|
399
638
|
if (process.platform === "linux") {
|
|
400
639
|
let raw2;
|
|
401
640
|
try {
|
|
402
|
-
raw2 =
|
|
641
|
+
raw2 = fs3.readFileSync(`/proc/${pid}/environ`, "utf8");
|
|
403
642
|
} catch {
|
|
404
643
|
return "unverified";
|
|
405
644
|
}
|
|
@@ -469,9 +708,9 @@ function workerLiveness(record, opts = {}) {
|
|
|
469
708
|
return "dead";
|
|
470
709
|
}
|
|
471
710
|
function canonicalDir(dir) {
|
|
472
|
-
const resolved =
|
|
473
|
-
const real =
|
|
474
|
-
const stat =
|
|
711
|
+
const resolved = path3.resolve(expandTilde(dir));
|
|
712
|
+
const real = fs3.realpathSync(resolved);
|
|
713
|
+
const stat = fs3.statSync(real);
|
|
475
714
|
if (!stat.isDirectory()) throw new Error(`"${dir}" is not a directory`);
|
|
476
715
|
return real;
|
|
477
716
|
}
|
|
@@ -480,19 +719,19 @@ function cwdAllowedOrThrow(cwd, allow) {
|
|
|
480
719
|
for (const root of allow) {
|
|
481
720
|
try {
|
|
482
721
|
const canonicalRoot = canonicalDir(root);
|
|
483
|
-
if (canonical === canonicalRoot || canonical.startsWith(canonicalRoot +
|
|
722
|
+
if (canonical === canonicalRoot || canonical.startsWith(canonicalRoot + path3.sep)) return canonical;
|
|
484
723
|
} catch {
|
|
485
724
|
}
|
|
486
725
|
}
|
|
487
726
|
const file = configCandidates()[0];
|
|
488
727
|
let exists = false;
|
|
489
728
|
try {
|
|
490
|
-
exists =
|
|
729
|
+
exists = fs3.existsSync(file);
|
|
491
730
|
} catch {
|
|
492
731
|
}
|
|
493
732
|
const effective = configCandidates().find((c) => {
|
|
494
733
|
try {
|
|
495
|
-
return
|
|
734
|
+
return fs3.existsSync(c);
|
|
496
735
|
} catch {
|
|
497
736
|
return false;
|
|
498
737
|
}
|
|
@@ -523,10 +762,10 @@ function sanitizeImForward(raw) {
|
|
|
523
762
|
}
|
|
524
763
|
function readUserImForwardIdentity() {
|
|
525
764
|
try {
|
|
526
|
-
const candidates = [
|
|
765
|
+
const candidates = [path3.join(configDirRoot(), "im-forward.json")];
|
|
527
766
|
for (const file of candidates) {
|
|
528
767
|
try {
|
|
529
|
-
const parsed = JSON.parse(
|
|
768
|
+
const parsed = JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
530
769
|
const provider = typeof parsed.provider === "string" ? parsed.provider : "feishu";
|
|
531
770
|
const settings = parsed.providers?.[provider];
|
|
532
771
|
if (!settings) continue;
|
|
@@ -543,12 +782,12 @@ function readUserImForwardIdentity() {
|
|
|
543
782
|
return void 0;
|
|
544
783
|
}
|
|
545
784
|
function cliEntry() {
|
|
546
|
-
const moduleDir =
|
|
785
|
+
const moduleDir = path3.dirname(fileURLToPath(import.meta.url));
|
|
547
786
|
for (const rel of ["../../../src/cli.ts", "../../../cli.js"]) {
|
|
548
|
-
const candidate =
|
|
787
|
+
const candidate = path3.resolve(moduleDir, rel);
|
|
549
788
|
try {
|
|
550
|
-
const real =
|
|
551
|
-
if (
|
|
789
|
+
const real = fs3.realpathSync(candidate);
|
|
790
|
+
if (fs3.statSync(real).isFile()) return real;
|
|
552
791
|
} catch {
|
|
553
792
|
}
|
|
554
793
|
}
|
|
@@ -558,10 +797,10 @@ function loaderArgs() {
|
|
|
558
797
|
for (let i = 0; i < process.execArgv.length - 1; i += 1) {
|
|
559
798
|
if (process.execArgv[i] === "--import") {
|
|
560
799
|
const target = process.execArgv[i + 1];
|
|
561
|
-
if (target && !
|
|
800
|
+
if (target && !path3.isAbsolute(target) && !target.startsWith("file:")) {
|
|
562
801
|
try {
|
|
563
|
-
const pkgRoot =
|
|
564
|
-
return ["--import",
|
|
802
|
+
const pkgRoot = path3.dirname(require_.resolve(`${target}/package.json`, { paths: [path3.dirname(cliEntry())] }));
|
|
803
|
+
return ["--import", path3.join(pkgRoot, "dist", "loader.mjs")];
|
|
565
804
|
} catch {
|
|
566
805
|
return [];
|
|
567
806
|
}
|
|
@@ -572,7 +811,7 @@ function loaderArgs() {
|
|
|
572
811
|
return [];
|
|
573
812
|
}
|
|
574
813
|
function logDir() {
|
|
575
|
-
return
|
|
814
|
+
return path3.join(pieProcDir(), "logs");
|
|
576
815
|
}
|
|
577
816
|
var toolText = (text, isError = false) => ({ content: [{ type: "text", text }], details: {}, ...isError ? { isError: true } : {} });
|
|
578
817
|
function pieProc(ctx) {
|
|
@@ -584,18 +823,18 @@ function pieProc(ctx) {
|
|
|
584
823
|
const observeActivity = (record) => {
|
|
585
824
|
const logTime = (() => {
|
|
586
825
|
try {
|
|
587
|
-
return
|
|
826
|
+
return fs3.statSync(path3.join(logDir(), `${record.name}.jsonl`)).mtimeMs;
|
|
588
827
|
} catch {
|
|
589
828
|
return record.lastActiveAt;
|
|
590
829
|
}
|
|
591
830
|
})();
|
|
592
831
|
if (record.pid === 0) return logTime;
|
|
593
|
-
const statusRoot =
|
|
832
|
+
const statusRoot = path3.join(path3.resolve(expandTilde(process.env.PIE_IPC_CONFIG_DIR ?? configDirRoot())), "run", "ipc");
|
|
594
833
|
try {
|
|
595
|
-
for (const file of
|
|
834
|
+
for (const file of fs3.readdirSync(statusRoot)) {
|
|
596
835
|
if (!file.endsWith(".json")) continue;
|
|
597
836
|
try {
|
|
598
|
-
const status = JSON.parse(
|
|
837
|
+
const status = JSON.parse(fs3.readFileSync(path3.join(statusRoot, file), "utf8"));
|
|
599
838
|
if (status.sessionId === record.sessionId && status.state === "working") return Date.now();
|
|
600
839
|
} catch {
|
|
601
840
|
}
|
|
@@ -751,7 +990,7 @@ function pieProc(ctx) {
|
|
|
751
990
|
ctx.registerCleanup?.(() => {
|
|
752
991
|
clearInterval(sweepTimer);
|
|
753
992
|
});
|
|
754
|
-
const spawnWorker = (params) => {
|
|
993
|
+
const spawnWorker = async (params) => {
|
|
755
994
|
if (!safeName(params.name)) throw new Error(`invalid worker name "${params.name}" (use [a-z0-9-_], max 48)`);
|
|
756
995
|
if (params.kind === "oneshot" && (typeof params.task !== "string" || !params.task.trim())) throw new Error("oneshot spawn requires a non-empty task");
|
|
757
996
|
if (params.kind === "oneshot" && params.task.startsWith("-")) throw new Error(`oneshot task must not start with "-" (got "${params.task.slice(0, 20)}\u2026")`);
|
|
@@ -761,16 +1000,17 @@ function pieProc(ctx) {
|
|
|
761
1000
|
const canonicalCwd = cwdAllowedOrThrow(params.cwd, currentConfig().allowCwd);
|
|
762
1001
|
const entry = cliEntry();
|
|
763
1002
|
if (!entry) throw new Error("cannot resolve a trusted pie entry point (refusing to spawn)");
|
|
1003
|
+
const validatedModel = validateSpawnModelParams({ model: params.model, thinkingLevel: params.thinkingLevel, pieDir: path3.join(pieProcDir(), "agents", params.name), parentConfigDir: configDirRoot() });
|
|
764
1004
|
let resumeSessionId;
|
|
765
1005
|
let resumeSessionsDir;
|
|
766
1006
|
if (params.resumeSessionId) {
|
|
767
1007
|
if (!/^[A-Za-z0-9][A-Za-z0-9-_]{5,63}$/.test(params.resumeSessionId)) throw new Error(`invalid resumeSessionId "${params.resumeSessionId}"`);
|
|
768
1008
|
const operatorSessionsDir = resolveOperatorSessionsDir();
|
|
769
|
-
const workerSessionsDir =
|
|
1009
|
+
const workerSessionsDir = path3.join(pieProcDir(), "agents", params.name, "sessions");
|
|
770
1010
|
let recordedCwd;
|
|
771
1011
|
for (const dir of [workerSessionsDir, operatorSessionsDir]) {
|
|
772
1012
|
try {
|
|
773
|
-
const head = JSON.parse(
|
|
1013
|
+
const head = JSON.parse(fs3.readFileSync(path3.join(dir, params.resumeSessionId, "head.json"), "utf8"));
|
|
774
1014
|
recordedCwd = head.metadata?.cwd;
|
|
775
1015
|
resumeSessionsDir = dir;
|
|
776
1016
|
break;
|
|
@@ -781,7 +1021,7 @@ function pieProc(ctx) {
|
|
|
781
1021
|
if (typeof recordedCwd !== "string" || !recordedCwd) throw new Error(`session "${params.resumeSessionId}" has no recorded cwd; resume requires one`);
|
|
782
1022
|
let canonicalRecorded = recordedCwd;
|
|
783
1023
|
try {
|
|
784
|
-
canonicalRecorded =
|
|
1024
|
+
canonicalRecorded = fs3.realpathSync(recordedCwd);
|
|
785
1025
|
} catch {
|
|
786
1026
|
}
|
|
787
1027
|
if (canonicalRecorded !== canonicalCwd) throw new Error(`resume cwd mismatch: session recorded "${recordedCwd}" but spawn cwd is "${params.cwd}" \u2014 resume in the session's own directory`);
|
|
@@ -858,21 +1098,12 @@ function pieProc(ctx) {
|
|
|
858
1098
|
});
|
|
859
1099
|
let child;
|
|
860
1100
|
try {
|
|
861
|
-
const pieDir =
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
const dst = path2.join(pieDir, file);
|
|
865
|
-
const src = path2.join(configDirRoot(), file);
|
|
866
|
-
if (!fs2.existsSync(dst) && fs2.existsSync(src)) {
|
|
867
|
-
try {
|
|
868
|
-
fs2.copyFileSync(src, dst);
|
|
869
|
-
} catch {
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
1101
|
+
const pieDir = path3.join(pieProcDir(), "agents", params.name);
|
|
1102
|
+
fs3.mkdirSync(pieDir, { recursive: true });
|
|
1103
|
+
inheritWorkerConfigFiles(pieDir, configDirRoot());
|
|
873
1104
|
if (imForward) {
|
|
874
|
-
const imFile =
|
|
875
|
-
if (!
|
|
1105
|
+
const imFile = path3.join(pieDir, "im-forward.json");
|
|
1106
|
+
if (!fs3.existsSync(imFile)) {
|
|
876
1107
|
const provider = typeof imForward.provider === "string" && imForward.provider.trim() ? imForward.provider : "feishu";
|
|
877
1108
|
const providerSettings = {};
|
|
878
1109
|
for (const key of ["chatId", "openId", "allowUsers", "larkCliProfile"]) {
|
|
@@ -884,26 +1115,15 @@ function pieProc(ctx) {
|
|
|
884
1115
|
providers: { [provider]: providerSettings }
|
|
885
1116
|
};
|
|
886
1117
|
if (typeof imForward.retryBackoffMs === "number") doc.retryBackoffMs = imForward.retryBackoffMs;
|
|
887
|
-
|
|
1118
|
+
fs3.writeFileSync(imFile, JSON.stringify(doc, null, " "));
|
|
888
1119
|
}
|
|
889
1120
|
}
|
|
890
|
-
|
|
891
|
-
const logFile =
|
|
892
|
-
const
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
"--idle",
|
|
897
|
-
"--session-id",
|
|
898
|
-
sessionId,
|
|
899
|
-
// 4.4.1 resume: --resume-required makes a failed load a HARD exit
|
|
900
|
-
// (never silently mint a same-id empty session); --worker-token
|
|
901
|
-
// keeps argv liveness matching on the per-launch token even when
|
|
902
|
-
// --session-id carries a reusable business session id.
|
|
903
|
-
...resumeSessionId ? ["--resume-required", "--worker-token", launchToken] : []
|
|
904
|
-
] : [...loaderArgs(), entry, "--session-id", sessionId];
|
|
905
|
-
const inheritedIpcRoot = path2.resolve(expandTilde(process.env.PIE_IPC_CONFIG_DIR ?? configDirRoot()));
|
|
906
|
-
const inheritedRegistryRoot = path2.resolve(expandTilde(process.env.PIE_PROC_REGISTRY_ROOT ?? pieProcDir()));
|
|
1121
|
+
fs3.mkdirSync(logDir(), { recursive: true });
|
|
1122
|
+
const logFile = fs3.openSync(path3.join(logDir(), `${params.name}.jsonl`), "a");
|
|
1123
|
+
const modelArgs = [...validatedModel.model ? ["--model", validatedModel.model] : [], ...validatedModel.thinkingLevel ? ["--thinking", validatedModel.thinkingLevel] : []];
|
|
1124
|
+
const args = params.kind === "resident" ? [...loaderArgs(), entry, "--json-events", "--idle", "--session-id", sessionId, ...resumeSessionId ? ["--resume-required", "--worker-token", launchToken] : [], ...modelArgs] : [...loaderArgs(), entry, "--session-id", sessionId, ...modelArgs];
|
|
1125
|
+
const inheritedIpcRoot = path3.resolve(expandTilde(process.env.PIE_IPC_CONFIG_DIR ?? configDirRoot()));
|
|
1126
|
+
const inheritedRegistryRoot = path3.resolve(expandTilde(process.env.PIE_PROC_REGISTRY_ROOT ?? pieProcDir()));
|
|
907
1127
|
const { PIE_DEFAULT_PROVIDER: _p, PIE_DEFAULT_MODEL: _m, PIE_MANAGER_BOOTSTRAP: _b, PIE_PROC_CURATED_NAME: _c, ...inheritedEnv } = process.env;
|
|
908
1128
|
const childEnv = {
|
|
909
1129
|
...inheritedEnv,
|
|
@@ -923,6 +1143,7 @@ function pieProc(ctx) {
|
|
|
923
1143
|
}
|
|
924
1144
|
}
|
|
925
1145
|
if (resumeSessionId && resumeSessionsDir !== void 0) childEnv.PIE_SESSIONS_DIR = resumeSessionsDir;
|
|
1146
|
+
else if (params.kind === "resident") childEnv.PIE_SESSIONS_DIR = resolveOperatorSessionsDir();
|
|
926
1147
|
try {
|
|
927
1148
|
child = spawn(process.execPath, args, {
|
|
928
1149
|
cwd: canonicalCwd,
|
|
@@ -936,12 +1157,12 @@ function pieProc(ctx) {
|
|
|
936
1157
|
});
|
|
937
1158
|
} finally {
|
|
938
1159
|
try {
|
|
939
|
-
|
|
1160
|
+
fs3.closeSync(logFile);
|
|
940
1161
|
} catch {
|
|
941
1162
|
}
|
|
942
1163
|
}
|
|
943
1164
|
if (typeof child.pid !== "number") {
|
|
944
|
-
throw new Error(`worker spawn failed (no pid) \u2014 see ${
|
|
1165
|
+
throw new Error(`worker spawn failed (no pid) \u2014 see ${path3.join(logDir(), `${params.name}.jsonl`)}`);
|
|
945
1166
|
}
|
|
946
1167
|
child.unref();
|
|
947
1168
|
const record = {
|
|
@@ -981,8 +1202,23 @@ function pieProc(ctx) {
|
|
|
981
1202
|
releaseReservation(generation);
|
|
982
1203
|
throw error instanceof Error ? error : new Error(String(error));
|
|
983
1204
|
}
|
|
984
|
-
|
|
985
|
-
|
|
1205
|
+
const receipt = await buildSpawnReceipt({
|
|
1206
|
+
name: params.name,
|
|
1207
|
+
kind: params.kind,
|
|
1208
|
+
pid: record.pid,
|
|
1209
|
+
sessionId,
|
|
1210
|
+
cwd: record.cwd,
|
|
1211
|
+
pieDir,
|
|
1212
|
+
ipcRoot: inheritedIpcRoot,
|
|
1213
|
+
logPath: path3.join(logDir(), `${params.name}.jsonl`),
|
|
1214
|
+
ttlMs: params.ttlMs,
|
|
1215
|
+
explicitModel: validatedModel.model,
|
|
1216
|
+
explicitThinking: validatedModel.thinkingLevel,
|
|
1217
|
+
resumeSessionId,
|
|
1218
|
+
resumeSessionsDir
|
|
1219
|
+
});
|
|
1220
|
+
ctx.log(`pie-proc: spawned ${params.kind} worker "${params.name}" (pid ${record.pid}, model ${receipt.modelLabel}, cwd ${record.cwd}, gen ${generation})`);
|
|
1221
|
+
return toolText(receipt.text);
|
|
986
1222
|
} catch (error) {
|
|
987
1223
|
releaseReservation(generation);
|
|
988
1224
|
throw error instanceof Error ? error : new Error(String(error));
|
|
@@ -1087,6 +1323,8 @@ function pieProc(ctx) {
|
|
|
1087
1323
|
cwd: Type.Optional(Type.String({ description: "spawn: working directory (must resolve under an allowCwd root)" })),
|
|
1088
1324
|
kind: Type.Optional(Type.Union([Type.Literal("resident"), Type.Literal("oneshot")], { description: "spawn: resident (default) or oneshot" })),
|
|
1089
1325
|
task: Type.Optional(Type.String({ description: "oneshot: the task prompt (non-empty, must not start with '-')" })),
|
|
1326
|
+
model: Type.Optional(Type.String({ description: "spawn: optional per-worker model override as 'provider/modelId' (validated against models.json; overrides default/resumed model when set)" })),
|
|
1327
|
+
thinkingLevel: Type.Optional(Type.String({ description: "spawn: optional thinking level override (off|minimal|low|medium|high|xhigh|max)" })),
|
|
1090
1328
|
ttlMs: Type.Optional(Type.Number({ description: "spawn (resident only): idle TTL in ms (0 = never reap)", minimum: 0, maximum: 864e5 })),
|
|
1091
1329
|
force: Type.Optional(Type.Boolean({ description: "kill: skip graceful SIGTERM" })),
|
|
1092
1330
|
imForward: Type.Optional(Type.Union([Type.Literal("inherit"), Type.Record(Type.String(), Type.Unknown())], { description: "spawn (resident only): IM identity binding \u2014 'inherit' copies the operator's user-layer IM identity verbatim (recommended: open_ids are per-app, hand copies break silently), or an object of identity fields only (enabled/provider/chatId/openId/allowUsers/larkCliProfile/inherit)" })),
|
|
@@ -1100,17 +1338,11 @@ function pieProc(ctx) {
|
|
|
1100
1338
|
const action = args.action;
|
|
1101
1339
|
if (action === "list") {
|
|
1102
1340
|
const snap = readRegistryUncached();
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
session: w.sessionId,
|
|
1107
|
-
|
|
1108
|
-
kind: w.kind,
|
|
1109
|
-
status: w.pid === 0 ? `pending (reserver ${w.reserverPid ?? "?"})` : workerLiveness(w),
|
|
1110
|
-
idleSeconds: Math.round((Date.now() - Math.max(w.lastActiveAt, observeActivity(w))) / 1e3),
|
|
1111
|
-
ttlMs: w.kind === "resident" ? w.ttlMs ?? currentConfig().defaultTtlMs : 0,
|
|
1112
|
-
im: Boolean(w.imForward)
|
|
1113
|
-
}));
|
|
1341
|
+
const ipcRoot = path3.resolve(expandTilde(process.env.PIE_IPC_CONFIG_DIR ?? configDirRoot()));
|
|
1342
|
+
const rows = snap.workers.map((w) => {
|
|
1343
|
+
const model = liveWorkerModelLabel(ipcRoot, w.sessionId, w.pid);
|
|
1344
|
+
return { name: w.name, pid: w.pid, session: w.sessionId, cwd: w.cwd, kind: w.kind, ...model ? { model } : {}, status: w.pid === 0 ? `pending (reserver ${w.reserverPid ?? "?"})` : workerLiveness(w), idleSeconds: Math.round((Date.now() - Math.max(w.lastActiveAt, observeActivity(w))) / 1e3), ttlMs: w.kind === "resident" ? w.ttlMs ?? currentConfig().defaultTtlMs : 0, im: Boolean(w.imForward) };
|
|
1345
|
+
});
|
|
1114
1346
|
return { content: [{ type: "text", text: rows.length === 0 ? "No pie-proc workers registered." : JSON.stringify(rows, null, 2) }], details: {} };
|
|
1115
1347
|
}
|
|
1116
1348
|
if (action === "spawn") {
|
|
@@ -1124,6 +1356,8 @@ function pieProc(ctx) {
|
|
|
1124
1356
|
kind: args.kind ?? "resident",
|
|
1125
1357
|
ttlMs: typeof args.ttlMs === "number" ? args.ttlMs : void 0,
|
|
1126
1358
|
task: args.task,
|
|
1359
|
+
model: typeof args.model === "string" ? args.model : void 0,
|
|
1360
|
+
thinkingLevel: typeof args.thinkingLevel === "string" ? args.thinkingLevel : void 0,
|
|
1127
1361
|
imForward: args.imForward,
|
|
1128
1362
|
resumeSessionId: args.resumeSessionId
|
|
1129
1363
|
});
|