@cydm/pie 4.3.5 → 4.3.7
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/cron/index.js +7 -1
- package/dist/builtin/extensions/im-forward/index.js +101 -83
- package/dist/builtin/extensions/mcp-adapter/index.js +7 -1
- package/dist/builtin/extensions/memory/index.js +5 -5
- package/dist/builtin/extensions/pie-ipc/index.js +1 -1
- package/dist/builtin/extensions/pie-proc/index.js +3 -2
- 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/chunks/{chunk-J2LGVYH2.js → chunk-2SAFRLFJ.js} +28 -13
- package/dist/chunks/{chunk-JQRZLVPY.js → chunk-6JEYRAQM.js} +1898 -1692
- package/dist/chunks/{chunk-NCP264ZE.js → chunk-B4N5LJMD.js} +1 -1
- package/dist/chunks/{chunk-PFXSA2LK.js → chunk-BJ4XN5VX.js} +5 -5
- package/dist/chunks/{chunk-H5G55G3R.js → chunk-N3BWFAMZ.js} +11 -1
- package/dist/chunks/{chunk-QX6WS73C.js → chunk-VHKMWOG3.js} +1 -1
- package/dist/chunks/{chunk-PC6HUZAD.js → chunk-WZLO5V2X.js} +3 -3
- package/dist/chunks/{chunk-BK36Y35W.js → chunk-XMOWWL4B.js} +2 -2
- package/dist/chunks/{concierge-cli-MCHXTFBA.js → manager-cli-QNMCCIFG.js} +322 -44
- package/dist/chunks/{model-registry-YA6U366L.js → model-registry-NKE3BRSZ.js} +2 -2
- package/dist/chunks/{src-ODLT57PQ.js → src-46R5ZFOU.js} +2 -2
- package/dist/chunks/{src-VPMIQGEW.js → src-4EQ7PBEI.js} +3 -3
- package/dist/chunks/{src-XSLD2IQ2.js → src-BHIH4VLE.js} +1 -1
- package/dist/chunks/{src-AQ4H43UM.js → src-UVULNQOO.js} +4 -4
- package/dist/chunks/{test-stream-GIUD5JWS.js → test-stream-FC6ZRENI.js} +1 -1
- package/dist/cli.js +347 -208
- package/package.json +3 -3
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./chunk-ILUHTKF3.js";
|
|
8
8
|
import "./chunk-LZQXQOPJ.js";
|
|
9
9
|
|
|
10
|
-
// src/commands/
|
|
10
|
+
// src/commands/manager-cli.ts
|
|
11
11
|
import { spawn, execFileSync } from "node:child_process";
|
|
12
12
|
import { createRequire } from "node:module";
|
|
13
13
|
import * as fs from "node:fs";
|
|
@@ -21,7 +21,7 @@ ${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
|
|
24
|
+
var SEED_AGENTS_MD = `# Pie Manager (manager)
|
|
25
25
|
|
|
26
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
|
|
|
@@ -48,12 +48,39 @@ var SEED_AGENTS_MD = `# Pie Concierge (manager)
|
|
|
48
48
|
- \u6D88\u606F\u6CA1\u6536\u5230 reaction \u65F6\u4E0D\u8981\u8BA9\u5B83\u60AC\u7740\uFF1A\u540C\u4E00\u4EFD\u6B63\u6587\u518D\u53D1\u4E00\u6B21\u5373\u53EF\uFF08\u4E0D\u5E26\u5F15\u7528\uFF09\uFF0C\u6216\u52A0 \`\u4F1A\u8BDD\u540D:\` \u6307\u5B9A\u76EE\u6807\u3002
|
|
49
49
|
${CRON_SECTION}`;
|
|
50
50
|
function workspaceDir() {
|
|
51
|
-
|
|
51
|
+
const dir = path.join(os.homedir(), ".pie", "manager");
|
|
52
|
+
migrateLegacyWorkspace(dir);
|
|
53
|
+
return dir;
|
|
54
|
+
}
|
|
55
|
+
var migrationChecked = false;
|
|
56
|
+
function migrateLegacyWorkspace(newDir) {
|
|
57
|
+
if (migrationChecked) return;
|
|
58
|
+
migrationChecked = true;
|
|
59
|
+
const legacy = path.join(os.homedir(), ".pie", "concierge");
|
|
60
|
+
if (!fs.existsSync(legacy)) return;
|
|
61
|
+
if (fs.existsSync(newDir)) {
|
|
62
|
+
console.warn(`Both ~/.pie/manager and the legacy ~/.pie/concierge exist; leaving the legacy directory untouched. Merge manually if needed.`);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
fs.mkdirSync(path.dirname(newDir), { recursive: true });
|
|
67
|
+
fs.renameSync(legacy, newDir);
|
|
68
|
+
const legacyState = path.join(newDir, "concierge.json");
|
|
69
|
+
if (fs.existsSync(legacyState)) {
|
|
70
|
+
try {
|
|
71
|
+
fs.renameSync(legacyState, path.join(newDir, "manager.json"));
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
console.log(`Migrated the workspace: ~/.pie/concierge \u2192 ~/.pie/manager (history and role card preserved).`);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.warn(`Workspace migration failed (${error instanceof Error ? error.message : String(error)}); using a fresh ~/.pie/manager.`);
|
|
78
|
+
}
|
|
52
79
|
}
|
|
53
80
|
function ensureSessionToken(dir) {
|
|
54
81
|
const tokenFile = path.join(dir, "session-token");
|
|
55
82
|
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
56
|
-
const mine = `
|
|
83
|
+
const mine = `manager-${os.hostname().split(".")[0]}-${Math.random().toString(36).slice(2, 8)}`;
|
|
57
84
|
const tmp = `${tokenFile}.${process.pid}.${attempt}.tmp`;
|
|
58
85
|
let tmpKept = false;
|
|
59
86
|
try {
|
|
@@ -112,10 +139,15 @@ function ensureSessionToken(dir) {
|
|
|
112
139
|
}
|
|
113
140
|
}
|
|
114
141
|
}
|
|
115
|
-
throw new Error("cannot establish the
|
|
142
|
+
throw new Error("cannot establish the manager workspace token; retry");
|
|
116
143
|
}
|
|
117
144
|
function statePath(dir = workspaceDir()) {
|
|
118
|
-
|
|
145
|
+
const current = path.join(dir, "manager.json");
|
|
146
|
+
if (!fs.existsSync(current)) {
|
|
147
|
+
const legacy = path.join(dir, "concierge.json");
|
|
148
|
+
if (fs.existsSync(legacy)) return legacy;
|
|
149
|
+
}
|
|
150
|
+
return current;
|
|
119
151
|
}
|
|
120
152
|
function logPath(dir = workspaceDir()) {
|
|
121
153
|
return path.join(dir, "log.jsonl");
|
|
@@ -136,7 +168,17 @@ function writeState(state, dir = workspaceDir()) {
|
|
|
136
168
|
fs.writeFileSync(tmp, JSON.stringify(state, null, " "));
|
|
137
169
|
fs.renameSync(tmp, statePath(dir));
|
|
138
170
|
}
|
|
139
|
-
function
|
|
171
|
+
function liveAttachOwners(state) {
|
|
172
|
+
return (state.attachOwners ?? []).filter((owner) => {
|
|
173
|
+
try {
|
|
174
|
+
process.kill(owner.pid, 0);
|
|
175
|
+
return true;
|
|
176
|
+
} catch {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function managerLiveness(pid, state) {
|
|
140
182
|
if (!pid || pid <= 0) return "dead";
|
|
141
183
|
try {
|
|
142
184
|
process.kill(pid, 0);
|
|
@@ -148,14 +190,14 @@ function conciergeLiveness(pid, state) {
|
|
|
148
190
|
if (cmd === void 0) {
|
|
149
191
|
return "unknown";
|
|
150
192
|
}
|
|
151
|
-
const sessionMatch = cmd.includes(state?.sessionId ?? "
|
|
193
|
+
const sessionMatch = cmd.includes(state?.sessionId ?? "manager-");
|
|
152
194
|
return /--idle/.test(cmd) && sessionMatch && /(pie|cli\.(js|ts|mjs))/i.test(cmd) ? "alive" : "dead";
|
|
153
195
|
} catch {
|
|
154
196
|
return "unknown";
|
|
155
197
|
}
|
|
156
198
|
}
|
|
157
199
|
function isConciergeAlive(pid, state) {
|
|
158
|
-
return
|
|
200
|
+
return managerLiveness(pid, state) === "alive";
|
|
159
201
|
}
|
|
160
202
|
function seedWorkspace(dir) {
|
|
161
203
|
fs.mkdirSync(path.join(dir, ".pie"), { recursive: true });
|
|
@@ -284,7 +326,7 @@ function spawnResident(state, dir) {
|
|
|
284
326
|
// PIE_PROC_CURATED_NAME: the resident's display name is manager from the
|
|
285
327
|
// very first composition (v2 Phase 1.3) — never the first IM/terminal
|
|
286
328
|
// message title, never a flip-flopping derived label.
|
|
287
|
-
env:
|
|
329
|
+
env: managerSpawnEnv()
|
|
288
330
|
});
|
|
289
331
|
child.unref();
|
|
290
332
|
writeState({ ...state, pid: child.pid, startedAt: Date.now() });
|
|
@@ -340,14 +382,38 @@ No IM forwarding config found. The first binding needs the interactive wizard (p
|
|
|
340
382
|
|
|
341
383
|
1) run pie inside a project directory, then Ctrl+R or /tools/im-forward setup to finish the wizard;
|
|
342
384
|
2) the wizard writes user-layer config (~/.pie/im-forward.json), shared by every pie;
|
|
343
|
-
3) run pie
|
|
385
|
+
3) run pie manager again.
|
|
344
386
|
|
|
345
|
-
To bind a separate app for the
|
|
387
|
+
To bind a separate app for the manager only, put a project-layer config at ~/.pie/manager/.pie/im-forward.json.
|
|
346
388
|
`);
|
|
347
389
|
return false;
|
|
348
390
|
}
|
|
391
|
+
var ATTACH_SIGNAL_CODES = {
|
|
392
|
+
SIGHUP: 1,
|
|
393
|
+
SIGINT: 2,
|
|
394
|
+
SIGQUIT: 3,
|
|
395
|
+
SIGABRT: 6,
|
|
396
|
+
SIGKILL: 9,
|
|
397
|
+
SIGTERM: 15
|
|
398
|
+
};
|
|
399
|
+
function managerSpawnEnv() {
|
|
400
|
+
const env = { ...process.env, PIE_PROC_CURATED_NAME: "manager" };
|
|
401
|
+
try {
|
|
402
|
+
const configPath = path.join(workspaceDir(), "config.json");
|
|
403
|
+
const parsed = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
404
|
+
const provider = typeof parsed.provider === "string" ? parsed.provider.trim() : "";
|
|
405
|
+
const modelId = typeof parsed.modelId === "string" ? parsed.modelId.trim() : "";
|
|
406
|
+
if (provider && modelId) {
|
|
407
|
+
env.PIE_DEFAULT_PROVIDER = provider;
|
|
408
|
+
env.PIE_DEFAULT_MODEL = modelId;
|
|
409
|
+
env.PIE_MANAGER_BOOTSTRAP = "1";
|
|
410
|
+
}
|
|
411
|
+
} catch {
|
|
412
|
+
}
|
|
413
|
+
return env;
|
|
414
|
+
}
|
|
349
415
|
function platformServiceName() {
|
|
350
|
-
return "dev.pie.
|
|
416
|
+
return "dev.pie.manager";
|
|
351
417
|
}
|
|
352
418
|
function xmlEscape(value) {
|
|
353
419
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
@@ -370,7 +436,21 @@ function installService(dir, state) {
|
|
|
370
436
|
const entry = cliEntry();
|
|
371
437
|
const logFile = logPath(dir);
|
|
372
438
|
const servicePath = process.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin";
|
|
439
|
+
const normalizeRoot = (value) => {
|
|
440
|
+
if (typeof value !== "string" || value.length === 0) return void 0;
|
|
441
|
+
const home = os.homedir() || process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
442
|
+
if (value === "~") return home;
|
|
443
|
+
if (value.startsWith("~/")) return path.resolve(path.join(home, value.slice(2)));
|
|
444
|
+
if (path.isAbsolute(value)) return value;
|
|
445
|
+
return path.resolve(value);
|
|
446
|
+
};
|
|
447
|
+
const serviceEnv = [
|
|
448
|
+
["PIE_PROC_CURATED_NAME", "manager"],
|
|
449
|
+
["PIE_CODING_AGENT_DIR", normalizeRoot(process.env.PIE_CODING_AGENT_DIR)],
|
|
450
|
+
["PIE_IPC_CONFIG_DIR", normalizeRoot(process.env.PIE_IPC_CONFIG_DIR)]
|
|
451
|
+
];
|
|
373
452
|
if (process.platform === "darwin") {
|
|
453
|
+
const envPlist = serviceEnv.filter(([, v]) => typeof v === "string" && v.length > 0).map(([k, v]) => ` <key>${k}</key><string>${xmlEscape(v)}</string>`).join("\n");
|
|
374
454
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
375
455
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
376
456
|
<plist version="1.0"><dict>
|
|
@@ -383,6 +463,7 @@ function installService(dir, state) {
|
|
|
383
463
|
</array>
|
|
384
464
|
<key>EnvironmentVariables</key><dict>
|
|
385
465
|
<key>PATH</key><string>${xmlEscape(servicePath)}</string>
|
|
466
|
+
${envPlist}
|
|
386
467
|
</dict>
|
|
387
468
|
<key>WorkingDirectory</key><string>${xmlEscape(dir)}</string>
|
|
388
469
|
<key>RunAtLoad</key><true/>
|
|
@@ -410,11 +491,12 @@ function installService(dir, state) {
|
|
|
410
491
|
const unitDir = path.join(os.homedir(), ".config", "systemd", "user");
|
|
411
492
|
fs.mkdirSync(unitDir, { recursive: true });
|
|
412
493
|
const unit = `[Unit]
|
|
413
|
-
Description=Pie
|
|
494
|
+
Description=Pie manager (resident im-forward host)
|
|
414
495
|
After=network-online.target
|
|
415
496
|
|
|
416
497
|
[Service]
|
|
417
498
|
Environment=${systemdEnvironmentToken(`PATH=${servicePath}`)}
|
|
499
|
+
${serviceEnv.filter(([, v]) => typeof v === "string" && v.length > 0).map(([k, v]) => `Environment=${systemdEnvironmentToken(`${k}=${v}`)}`).join("\n")}
|
|
418
500
|
# r26 P2: the ':' prefix disables systemd's variable expansion for this
|
|
419
501
|
# command line \u2014 install paths may legitimately contain literal '$' runs,
|
|
420
502
|
# and quotes do NOT protect them (undefined vars expand to empty strings).
|
|
@@ -440,7 +522,8 @@ WantedBy=default.target`;
|
|
|
440
522
|
return;
|
|
441
523
|
}
|
|
442
524
|
if (process.platform === "win32") {
|
|
443
|
-
const
|
|
525
|
+
const envSets = serviceEnv.filter(([, v]) => typeof v === "string" && v.length > 0).map(([k, v]) => `set "${k}=${v}" && `).join("");
|
|
526
|
+
const cmd = `cd /d "${dir}" && ${envSets}"${process.execPath}" "${entry}" --json-events --idle --session-id ${state.sessionId} >> "${logFile}" 2>&1`;
|
|
444
527
|
execFileSync("schtasks", [
|
|
445
528
|
"/Create",
|
|
446
529
|
"/TN",
|
|
@@ -574,14 +657,83 @@ function uninstallService() {
|
|
|
574
657
|
}
|
|
575
658
|
throw new Error(`unsupported platform: ${process.platform}`);
|
|
576
659
|
}
|
|
660
|
+
function withStartLockSync(dir, fn) {
|
|
661
|
+
const locks = startLockDir(dir);
|
|
662
|
+
fs.mkdirSync(locks, { recursive: true });
|
|
663
|
+
let latest = 0;
|
|
664
|
+
try {
|
|
665
|
+
for (const entry of fs.readdirSync(locks)) {
|
|
666
|
+
const m = /^start\.r(\d+)\.json$/.exec(entry);
|
|
667
|
+
if (m) latest = Math.max(latest, Number(m[1]));
|
|
668
|
+
}
|
|
669
|
+
} catch {
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
if (latest > 0) {
|
|
673
|
+
const latestPath = path.join(locks, `start.r${latest}.json`);
|
|
674
|
+
let holderBlocking = false;
|
|
675
|
+
try {
|
|
676
|
+
if (fs.existsSync(`${latestPath}.released`)) holderBlocking = false;
|
|
677
|
+
else {
|
|
678
|
+
const content = JSON.parse(fs.readFileSync(latestPath, "utf8"));
|
|
679
|
+
if (typeof content.pid === "number" && content.pid > 0) {
|
|
680
|
+
try {
|
|
681
|
+
process.kill(content.pid, 0);
|
|
682
|
+
holderBlocking = true;
|
|
683
|
+
} catch {
|
|
684
|
+
holderBlocking = false;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
} catch {
|
|
689
|
+
holderBlocking = false;
|
|
690
|
+
}
|
|
691
|
+
if (holderBlocking) return false;
|
|
692
|
+
}
|
|
693
|
+
const next = latest + 1;
|
|
694
|
+
const target = path.join(locks, `start.r${next}.json`);
|
|
695
|
+
const tmp = `${target}.${process.pid}.${Date.now().toString(36)}.tmp`;
|
|
696
|
+
try {
|
|
697
|
+
fs.writeFileSync(tmp, JSON.stringify({ pid: process.pid, at: Date.now() }));
|
|
698
|
+
fs.linkSync(tmp, target);
|
|
699
|
+
} catch (error) {
|
|
700
|
+
try {
|
|
701
|
+
fs.rmSync(tmp, { force: true });
|
|
702
|
+
} catch {
|
|
703
|
+
}
|
|
704
|
+
return false;
|
|
705
|
+
} finally {
|
|
706
|
+
try {
|
|
707
|
+
fs.rmSync(tmp, { force: true });
|
|
708
|
+
} catch {
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
try {
|
|
712
|
+
return fn();
|
|
713
|
+
} finally {
|
|
714
|
+
try {
|
|
715
|
+
const relTmp = `${target}.released.${process.pid}.tmp`;
|
|
716
|
+
fs.writeFileSync(relTmp, String(Date.now()));
|
|
717
|
+
try {
|
|
718
|
+
fs.linkSync(relTmp, `${target}.released`);
|
|
719
|
+
} catch {
|
|
720
|
+
}
|
|
721
|
+
try {
|
|
722
|
+
fs.rmSync(relTmp, { force: true });
|
|
723
|
+
} catch {
|
|
724
|
+
}
|
|
725
|
+
} catch {
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
577
729
|
async function stopConcierge(state) {
|
|
578
730
|
if (!state.pid) {
|
|
579
731
|
console.log("No recorded pid; nothing to do.");
|
|
580
732
|
return 0;
|
|
581
733
|
}
|
|
582
|
-
const liveness0 =
|
|
734
|
+
const liveness0 = managerLiveness(state.pid, state);
|
|
583
735
|
if (liveness0 === "dead") {
|
|
584
|
-
writeState({ sessionId: state.sessionId });
|
|
736
|
+
writeState({ sessionId: state.sessionId, attachOwners: state.attachOwners });
|
|
585
737
|
console.log("The process is no longer running.");
|
|
586
738
|
return 0;
|
|
587
739
|
}
|
|
@@ -603,14 +755,14 @@ async function stopConcierge(state) {
|
|
|
603
755
|
if (!isConciergeAlive(state.pid, state)) break;
|
|
604
756
|
await new Promise((resolve2) => setTimeout(resolve2, 200));
|
|
605
757
|
}
|
|
606
|
-
const finalState =
|
|
758
|
+
const finalState = managerLiveness(state.pid, state);
|
|
607
759
|
if (finalState === "alive" || finalState === "unknown") {
|
|
608
760
|
console.error(
|
|
609
|
-
`Shutdown not confirmed (state: ${finalState}); the pid is kept. Retry with pie
|
|
761
|
+
`Shutdown not confirmed (state: ${finalState}); the pid is kept. Retry with pie manager stop or clean up manually.`
|
|
610
762
|
);
|
|
611
763
|
return 1;
|
|
612
764
|
}
|
|
613
|
-
writeState({ sessionId: state.sessionId });
|
|
765
|
+
writeState({ sessionId: state.sessionId, attachOwners: state.attachOwners });
|
|
614
766
|
console.log("Stopped.");
|
|
615
767
|
return 0;
|
|
616
768
|
}
|
|
@@ -625,7 +777,7 @@ function withStartLock(dir, fn) {
|
|
|
625
777
|
for (; ; ) {
|
|
626
778
|
if (Date.now() > deadline)
|
|
627
779
|
throw new Error(
|
|
628
|
-
"another pie
|
|
780
|
+
"another pie manager lifecycle command is in progress; retry shortly"
|
|
629
781
|
);
|
|
630
782
|
let latest = 0;
|
|
631
783
|
try {
|
|
@@ -703,13 +855,13 @@ function withStartLock(dir, fn) {
|
|
|
703
855
|
}
|
|
704
856
|
});
|
|
705
857
|
}
|
|
706
|
-
async function
|
|
858
|
+
async function runManagerCommand(args) {
|
|
707
859
|
const sub = args[0] ?? "";
|
|
708
860
|
const dir = workspaceDir();
|
|
709
861
|
if (sub === "status") {
|
|
710
862
|
const state = readState();
|
|
711
863
|
if (!state) {
|
|
712
|
-
console.log("Not initialized (run pie
|
|
864
|
+
console.log("Not initialized (run pie manager first).");
|
|
713
865
|
return;
|
|
714
866
|
}
|
|
715
867
|
console.log(`session: ${state.sessionId}`);
|
|
@@ -753,7 +905,7 @@ async function runConciergeCommand(args) {
|
|
|
753
905
|
`service: ${platformServiceName()} ${running ? "(running)" : "(stopped)"}`
|
|
754
906
|
);
|
|
755
907
|
} else {
|
|
756
|
-
const liveness =
|
|
908
|
+
const liveness = managerLiveness(state.pid, state);
|
|
757
909
|
const label = liveness === "alive" ? "(running)" : liveness === "unknown" ? "(alive, identity unverified)" : "(not running)";
|
|
758
910
|
console.log(`pid: ${state.pid ?? "-"} ${label}`);
|
|
759
911
|
}
|
|
@@ -850,7 +1002,7 @@ async function runConciergeCommand(args) {
|
|
|
850
1002
|
if (toreDown) {
|
|
851
1003
|
const state = readState();
|
|
852
1004
|
if (state && state.service) {
|
|
853
|
-
writeState({ sessionId: state.sessionId,
|
|
1005
|
+
writeState({ sessionId: state.sessionId, attachOwners: state.attachOwners });
|
|
854
1006
|
} else if (state) {
|
|
855
1007
|
console.log("No service-managed state detected; a manual instance, if present, is unaffected.");
|
|
856
1008
|
}
|
|
@@ -868,20 +1020,28 @@ async function runConciergeCommand(args) {
|
|
|
868
1020
|
const state = readState();
|
|
869
1021
|
if (!state) {
|
|
870
1022
|
console.error(
|
|
871
|
-
"Run pie
|
|
1023
|
+
"Run pie manager once to initialize (a stable session id is required)."
|
|
872
1024
|
);
|
|
873
1025
|
process.exitCode = 2;
|
|
874
1026
|
return;
|
|
875
1027
|
}
|
|
876
1028
|
if (!imForwardConfigured(dir)) {
|
|
877
|
-
console.error("No IM config detected; complete the first pie
|
|
1029
|
+
console.error("No IM config detected; complete the first pie manager initialization.");
|
|
878
1030
|
process.exitCode = 2;
|
|
879
1031
|
return;
|
|
880
1032
|
}
|
|
881
|
-
const installLiveness =
|
|
1033
|
+
const installLiveness = managerLiveness(state.pid, state);
|
|
882
1034
|
if (installLiveness === "alive" || installLiveness === "unknown") {
|
|
883
1035
|
console.log(
|
|
884
|
-
`A resident process is present (state: ${installLiveness}); run pie
|
|
1036
|
+
`A resident process is present (state: ${installLiveness}); run pie manager stop before installing the service.`
|
|
1037
|
+
);
|
|
1038
|
+
process.exitCode = 2;
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
const installLiveOwners = liveAttachOwners(state);
|
|
1042
|
+
if (installLiveOwners.length > 0) {
|
|
1043
|
+
console.log(
|
|
1044
|
+
`An attach TUI owns the session right now (pid ${installLiveOwners[0].pid}); detach it before installing the service.`
|
|
885
1045
|
);
|
|
886
1046
|
process.exitCode = 2;
|
|
887
1047
|
return;
|
|
@@ -891,10 +1051,121 @@ async function runConciergeCommand(args) {
|
|
|
891
1051
|
});
|
|
892
1052
|
return;
|
|
893
1053
|
}
|
|
1054
|
+
if (sub === "attach") {
|
|
1055
|
+
const force = args.includes("--force");
|
|
1056
|
+
let claimedState;
|
|
1057
|
+
let claimError;
|
|
1058
|
+
await withStartLock(dir, async () => {
|
|
1059
|
+
const state2 = readState();
|
|
1060
|
+
if (!state2) {
|
|
1061
|
+
console.error("No manager session yet (run pie manager start first).");
|
|
1062
|
+
claimError = 2;
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
if (state2.service) {
|
|
1066
|
+
if (!force) {
|
|
1067
|
+
console.error(
|
|
1068
|
+
"The manager is owned by a system service (launchd/systemd). A service resident restarts through pid gaps and can silently lose turns alongside an attach TUI."
|
|
1069
|
+
);
|
|
1070
|
+
console.error("Uninstall the service first (pie manager --uninstall-service), or attach anyway with --force.");
|
|
1071
|
+
claimError = 2;
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
console.warn("--force: attaching alongside the service-owned resident; concurrent turns may be lost.");
|
|
1075
|
+
}
|
|
1076
|
+
const liveness = state2.pid ? managerLiveness(state2.pid, state2) : "dead";
|
|
1077
|
+
if (liveness === "alive" || liveness === "unknown") {
|
|
1078
|
+
if (!force) {
|
|
1079
|
+
console.error(
|
|
1080
|
+
`The manager daemon is running (pid ${state2.pid ?? "-"}, state: ${liveness}). Two writers on one session can lose turns when both are active.`
|
|
1081
|
+
);
|
|
1082
|
+
console.error("Stop it first (pie manager stop), or attach anyway with --force.");
|
|
1083
|
+
claimError = 2;
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
console.warn("--force: attaching alongside the live daemon; concurrent turns may be lost.");
|
|
1087
|
+
}
|
|
1088
|
+
const liveOthers = liveAttachOwners(state2).filter((o) => o.pid !== process.pid);
|
|
1089
|
+
if (liveOthers.length > 0) {
|
|
1090
|
+
if (!force) {
|
|
1091
|
+
console.error(
|
|
1092
|
+
`Another attach TUI already owns this session (pid ${liveOthers[0].pid}, started ${new Date(liveOthers[0].startedAt).toISOString()}).`
|
|
1093
|
+
);
|
|
1094
|
+
console.error("Detach it first, or attach anyway with --force.");
|
|
1095
|
+
claimError = 2;
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
console.warn("--force: attaching alongside another attach TUI; concurrent turns may be lost.");
|
|
1099
|
+
}
|
|
1100
|
+
const priorOwners = liveAttachOwners(state2);
|
|
1101
|
+
writeState({ ...state2, attachOwners: [...priorOwners, { pid: process.pid, startedAt: Date.now() }] });
|
|
1102
|
+
claimedState = state2;
|
|
1103
|
+
});
|
|
1104
|
+
if (claimError !== void 0 || !claimedState) {
|
|
1105
|
+
process.exitCode = claimError ?? 2;
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
const state = claimedState;
|
|
1109
|
+
let ownerPid = process.pid;
|
|
1110
|
+
let childPid;
|
|
1111
|
+
const removeOwnerEntry = () => {
|
|
1112
|
+
const current = readState();
|
|
1113
|
+
if (!current?.attachOwners) return;
|
|
1114
|
+
const rest = current.attachOwners.filter((o) => o.pid !== ownerPid && o.pid !== childPid);
|
|
1115
|
+
writeState(rest.length > 0 ? { ...current, attachOwners: rest } : { ...current, attachOwners: void 0 });
|
|
1116
|
+
};
|
|
1117
|
+
const clearAttachOwner = () => {
|
|
1118
|
+
try {
|
|
1119
|
+
if (childPid) {
|
|
1120
|
+
try {
|
|
1121
|
+
process.kill(childPid, 0);
|
|
1122
|
+
return;
|
|
1123
|
+
} catch {
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
withStartLockSync(dir, removeOwnerEntry);
|
|
1127
|
+
} catch {
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
process.on("exit", clearAttachOwner);
|
|
1131
|
+
const { spawn: spawn2 } = await import("node:child_process");
|
|
1132
|
+
const entry = cliEntry();
|
|
1133
|
+
if (!entry) {
|
|
1134
|
+
console.error("cannot resolve the pie entry point");
|
|
1135
|
+
process.exitCode = 2;
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
const loaderAbs = resolveTsxLoaderUrl();
|
|
1139
|
+
const passthrough = loaderAbs ? ["--import", loaderAbs] : process.execArgv.filter((a) => a !== "--import" && !a.startsWith("--import="));
|
|
1140
|
+
const child = spawn2(process.execPath, [...passthrough, entry, "--session-id", state.sessionId], {
|
|
1141
|
+
cwd: dir,
|
|
1142
|
+
stdio: "inherit",
|
|
1143
|
+
env: managerSpawnEnv()
|
|
1144
|
+
});
|
|
1145
|
+
if (child.pid) {
|
|
1146
|
+
childPid = child.pid;
|
|
1147
|
+
await withStartLock(dir, async () => {
|
|
1148
|
+
const current = readState();
|
|
1149
|
+
if (!current) return;
|
|
1150
|
+
const others = (current.attachOwners ?? []).filter((o) => o.pid !== process.pid);
|
|
1151
|
+
writeState({ ...current, attachOwners: [...others, { pid: child.pid, startedAt: Date.now() }] });
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
const code = await new Promise((resolve2, reject) => {
|
|
1155
|
+
child.on("error", reject);
|
|
1156
|
+
child.on("exit", (code2, signal) => {
|
|
1157
|
+
const signo = signal ? ATTACH_SIGNAL_CODES[signal] : void 0;
|
|
1158
|
+
resolve2(signo !== void 0 ? 128 + signo : code2 ?? 0);
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
clearAttachOwner();
|
|
1162
|
+
if (code) process.exitCode = code;
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
894
1165
|
if (sub && sub !== "start") {
|
|
895
1166
|
console.error(`Unknown subcommand: ${sub}`);
|
|
896
1167
|
console.error(
|
|
897
|
-
"Usage: pie
|
|
1168
|
+
"Usage: pie manager [start|status|stop|attach|--install-service|--uninstall-service]"
|
|
898
1169
|
);
|
|
899
1170
|
process.exitCode = 2;
|
|
900
1171
|
return;
|
|
@@ -902,20 +1173,20 @@ async function runConciergeCommand(args) {
|
|
|
902
1173
|
const existing = readState();
|
|
903
1174
|
if (existing?.service) {
|
|
904
1175
|
console.log(
|
|
905
|
-
"The
|
|
1176
|
+
"The manager is managed by a system service (launchd/systemd/scheduled task). To take over manually, run --uninstall-service first."
|
|
906
1177
|
);
|
|
907
1178
|
return;
|
|
908
1179
|
}
|
|
909
|
-
const startLiveness = existing ?
|
|
1180
|
+
const startLiveness = existing ? managerLiveness(existing.pid, existing) : "dead";
|
|
910
1181
|
if (existing && (startLiveness === "alive" || startLiveness === "unknown")) {
|
|
911
1182
|
console.log(
|
|
912
|
-
`The
|
|
1183
|
+
`The manager may already be running (pid ${existing.pid ?? "-"}, state: ${startLiveness}, session ${existing.sessionId}).`
|
|
913
1184
|
);
|
|
914
1185
|
return;
|
|
915
1186
|
}
|
|
916
1187
|
if (!imForwardConfigured(dir) && !process.stdin.isTTY) {
|
|
917
1188
|
console.error(
|
|
918
|
-
"No IM config found and no terminal for the wizard; run pie
|
|
1189
|
+
"No IM config found and no terminal for the wizard; run pie manager in a TTY."
|
|
919
1190
|
);
|
|
920
1191
|
process.exitCode = 2;
|
|
921
1192
|
return;
|
|
@@ -941,14 +1212,21 @@ async function runConciergeCommand(args) {
|
|
|
941
1212
|
const lockedState = readState();
|
|
942
1213
|
if (lockedState?.service) {
|
|
943
1214
|
console.log(
|
|
944
|
-
"The
|
|
1215
|
+
"The manager is managed by a system service (launchd/systemd/scheduled task). To take over manually, run --uninstall-service first."
|
|
1216
|
+
);
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
const lockedLiveness = lockedState ? managerLiveness(lockedState.pid, lockedState) : "dead";
|
|
1220
|
+
const lockedLiveOwners = lockedState ? liveAttachOwners(lockedState).filter((o) => o.pid !== process.pid) : [];
|
|
1221
|
+
if (lockedLiveOwners.length > 0) {
|
|
1222
|
+
console.log(
|
|
1223
|
+
`An attach TUI owns the session right now (pid ${lockedLiveOwners[0].pid}). Detach it before starting the daemon.`
|
|
945
1224
|
);
|
|
946
1225
|
return;
|
|
947
1226
|
}
|
|
948
|
-
const lockedLiveness = lockedState ? conciergeLiveness(lockedState.pid, lockedState) : "dead";
|
|
949
1227
|
if (lockedState && (lockedLiveness === "alive" || lockedLiveness === "unknown")) {
|
|
950
1228
|
console.log(
|
|
951
|
-
`The
|
|
1229
|
+
`The manager may already be running (pid ${lockedState.pid ?? "-"}, state: ${lockedLiveness}, session ${lockedState.sessionId}).`
|
|
952
1230
|
);
|
|
953
1231
|
return;
|
|
954
1232
|
}
|
|
@@ -967,7 +1245,7 @@ async function runConciergeCommand(args) {
|
|
|
967
1245
|
});
|
|
968
1246
|
const token2 = `--session-id ${state.sessionId}`;
|
|
969
1247
|
const rivals = String(listing).split("\n").map((line) => line.trim()).filter(
|
|
970
|
-
(line) => line.includes(token2) && line.includes("--idle") && line.includes("json-events")
|
|
1248
|
+
(line) => line.includes(token2) && line.includes("--idle") && line.includes("json-events") || line.includes(token2) && line.includes("manager") && line.includes("attach")
|
|
971
1249
|
).map((line) => Number(line.split(/\s+/)[0])).filter((p) => Number.isFinite(p) && p > 0 && p !== pid);
|
|
972
1250
|
const liveRivals = rivals.filter((rival) => {
|
|
973
1251
|
try {
|
|
@@ -985,14 +1263,14 @@ async function runConciergeCommand(args) {
|
|
|
985
1263
|
const winnerPid = Math.min(...liveRivals);
|
|
986
1264
|
writeState({ ...state, pid: winnerPid });
|
|
987
1265
|
console.log(
|
|
988
|
-
`The
|
|
1266
|
+
`The manager is already running (concurrent starts converged on pid ${winnerPid}); this start's extra instance was terminated.`
|
|
989
1267
|
);
|
|
990
1268
|
return;
|
|
991
1269
|
}
|
|
992
1270
|
} catch {
|
|
993
1271
|
const winner = readState();
|
|
994
1272
|
if (winner && winner.pid && winner.pid !== pid && winner.sessionId === state.sessionId) {
|
|
995
|
-
const liveness =
|
|
1273
|
+
const liveness = managerLiveness(winner.pid, winner);
|
|
996
1274
|
if (liveness === "alive" || liveness === "unknown") {
|
|
997
1275
|
try {
|
|
998
1276
|
process.kill(pid, "SIGKILL");
|
|
@@ -1015,15 +1293,15 @@ async function runConciergeCommand(args) {
|
|
|
1015
1293
|
const ready = await waitForAgentReady(dir, 3e4, sinceOffset, sessionId);
|
|
1016
1294
|
if (ready) {
|
|
1017
1295
|
const now = readState();
|
|
1018
|
-
const stillOurs = now?.pid === pid && now.sessionId === sessionId &&
|
|
1296
|
+
const stillOurs = now?.pid === pid && now.sessionId === sessionId && managerLiveness(pid, now) === "alive";
|
|
1019
1297
|
if (stillOurs) {
|
|
1020
1298
|
console.log(`\u2713 Concierge ready \xB7 log ${logPath(dir)}`);
|
|
1021
1299
|
console.log(
|
|
1022
|
-
` Now just talk to it in your IM app; stop: pie
|
|
1300
|
+
` Now just talk to it in your IM app; stop: pie manager stop; status: pie manager status`
|
|
1023
1301
|
);
|
|
1024
1302
|
} else {
|
|
1025
1303
|
console.log(
|
|
1026
|
-
`\u26A0 agent.ready appeared, but the recorded state is no longer this start (pid ${pid} may have been stopped or replaced); confirm with pie
|
|
1304
|
+
`\u26A0 agent.ready appeared, but the recorded state is no longer this start (pid ${pid} may have been stopped or replaced); confirm with pie manager status.`
|
|
1027
1305
|
);
|
|
1028
1306
|
}
|
|
1029
1307
|
} else {
|
|
@@ -1035,5 +1313,5 @@ async function runConciergeCommand(args) {
|
|
|
1035
1313
|
}
|
|
1036
1314
|
export {
|
|
1037
1315
|
isTooBroadForWorkerSandbox,
|
|
1038
|
-
|
|
1316
|
+
runManagerCommand
|
|
1039
1317
|
};
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
assertNoSecretSubstrings,
|
|
5
5
|
configuredRemoteCredentialValues,
|
|
6
6
|
loadResolvedModelsConfig
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VHKMWOG3.js";
|
|
8
8
|
import "./chunk-ILUHTKF3.js";
|
|
9
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-6JEYRAQM.js";
|
|
10
10
|
import "./chunk-XXGYUYXI.js";
|
|
11
11
|
import "./chunk-LZQXQOPJ.js";
|
|
12
12
|
export {
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
createToolCallerIdentity,
|
|
9
9
|
getAgentFailureMetadata,
|
|
10
10
|
getToolCallerIdentity
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-B4N5LJMD.js";
|
|
12
|
+
import "./chunk-6JEYRAQM.js";
|
|
13
13
|
import "./chunk-XXGYUYXI.js";
|
|
14
14
|
import "./chunk-LZQXQOPJ.js";
|
|
15
15
|
export {
|
|
@@ -142,9 +142,9 @@ import {
|
|
|
142
142
|
substituteArgs,
|
|
143
143
|
validateRetainedTailEntries,
|
|
144
144
|
verifyPreparedCompactionCommit
|
|
145
|
-
} from "./chunk-
|
|
146
|
-
import "./chunk-
|
|
147
|
-
import "./chunk-
|
|
145
|
+
} from "./chunk-XMOWWL4B.js";
|
|
146
|
+
import "./chunk-B4N5LJMD.js";
|
|
147
|
+
import "./chunk-6JEYRAQM.js";
|
|
148
148
|
import "./chunk-XXGYUYXI.js";
|
|
149
149
|
import "./chunk-LZQXQOPJ.js";
|
|
150
150
|
export {
|