@cydm/pie 4.3.5 → 4.3.6
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.
|
@@ -670,7 +670,7 @@ function hashText(input) {
|
|
|
670
670
|
function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
|
|
671
671
|
const IM_INPUT_PREFIX = connection.sourcePrefix;
|
|
672
672
|
const key = (id) => JSON.stringify([cfg.provider, id]);
|
|
673
|
-
const
|
|
673
|
+
const isManager = cfg.unattended === true;
|
|
674
674
|
const scopes = /* @__PURE__ */ new Set();
|
|
675
675
|
let forwardingEnabled = cfg.enabled === true;
|
|
676
676
|
let configurationFailed = false;
|
|
@@ -875,7 +875,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
875
875
|
}
|
|
876
876
|
ctx.on("terminal:input", (event) => {
|
|
877
877
|
const text = event.text?.trim() ?? "";
|
|
878
|
-
if (
|
|
878
|
+
if (isManager && /^\[pie-ipc\][^\n]*says:\s*\n?\[ipc-done\] requestId=[a-zA-Z0-9:-]+ (?:outcome=\S+ )?user_assigned=true(?:\s|$)/.test(text) && currentSessionId) {
|
|
879
879
|
const requestTag = /requestId=([a-zA-Z0-9:-]+)/.exec(text)?.[1] ?? "ipc-delivery";
|
|
880
880
|
stampDeliveryDestination(`ipc-done:${requestTag}`);
|
|
881
881
|
}
|
|
@@ -892,7 +892,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
892
892
|
return { action: "continue" };
|
|
893
893
|
});
|
|
894
894
|
function outboundRoleAllows(attribution) {
|
|
895
|
-
if (!
|
|
895
|
+
if (!isManager) return true;
|
|
896
896
|
if (attribution !== void 0) return true;
|
|
897
897
|
pruneDeliveryDestinations();
|
|
898
898
|
const scope = `s:${currentSessionId}:`;
|
|
@@ -933,7 +933,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
933
933
|
return;
|
|
934
934
|
}
|
|
935
935
|
}
|
|
936
|
-
if (inbound?.role === "user" &&
|
|
936
|
+
if (inbound?.role === "user" && isManager && currentSessionId) {
|
|
937
937
|
const userText = typeof inbound.content === "string" ? inbound.content : Array.isArray(inbound.content) ? inbound.content.map((block) => block && typeof block === "object" && typeof block.text === "string" ? block.text : "").join("") : "";
|
|
938
938
|
const stampedWake = /^\[pie-ipc\][^\n]*says:\s*\n?\[(?:ipc-done|ipc-check|ipc-done-check)\] (?:No completion notification arrived for |The completion notification for )?requestId=[a-zA-Z0-9:-]+ (?:outcome=\S+ )?(?:\([^)]*\) )?user_assigned=true(?:\s|$)/;
|
|
939
939
|
const wrappedNotify = stampedWake.exec(userText);
|
|
@@ -1016,7 +1016,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1016
1016
|
let sessionAnchorThreadId = sessionAnchor.threadId;
|
|
1017
1017
|
let stakeFlightToken;
|
|
1018
1018
|
const stakeWanted = () => {
|
|
1019
|
-
if (
|
|
1019
|
+
if (isManager) return false;
|
|
1020
1020
|
const current = resolveSessionAnchor(sessionId);
|
|
1021
1021
|
sessionAnchorThreadId = current.threadId;
|
|
1022
1022
|
return !current.messageId || !current.threadId;
|
|
@@ -1033,7 +1033,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1033
1033
|
};
|
|
1034
1034
|
const pinnedAnchor = replyTo ?? attributionAnchor;
|
|
1035
1035
|
let stakeGuard = 8;
|
|
1036
|
-
while (stakeGuard-- > 0 && !
|
|
1036
|
+
while (stakeGuard-- > 0 && !isManager) {
|
|
1037
1037
|
if (stakeFlightToken) break;
|
|
1038
1038
|
const refreshed0 = resolveSessionAnchor(sessionId);
|
|
1039
1039
|
if (refreshed0.threadId) {
|
|
@@ -1054,7 +1054,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1054
1054
|
sessionAnchorThreadId = refreshed.threadId;
|
|
1055
1055
|
if (!pinnedAnchor && refreshed.messageId && !refreshed.threadId) anchor = refreshed.messageId;
|
|
1056
1056
|
}
|
|
1057
|
-
if (!
|
|
1057
|
+
if (!isManager && !stakeFlightToken && !pinnedAnchor) {
|
|
1058
1058
|
const last = resolveSessionAnchor(sessionId);
|
|
1059
1059
|
if (!last.threadId) {
|
|
1060
1060
|
ctx.log(`im-forward: topic stake unavailable for ${sessionId}; dropping forward (seq=${sequence})`);
|
|
@@ -1069,7 +1069,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1069
1069
|
token.release?.();
|
|
1070
1070
|
anchorStakeFlights.delete(sessionId);
|
|
1071
1071
|
};
|
|
1072
|
-
let threadPlacement = attribution?.threadId ? { replyInThread: true } : !anchor && !
|
|
1072
|
+
let threadPlacement = attribution?.threadId ? { replyInThread: true } : !anchor && !isManager ? { replyInThread: true } : sessionAnchorThreadId ? { replyInThread: true, topicId: sessionAnchorThreadId } : { replyInThread: false };
|
|
1073
1073
|
const sendChunk = async (index) => {
|
|
1074
1074
|
const key2 = chunkKey(baseKey, index);
|
|
1075
1075
|
return providerCall(
|
|
@@ -1120,7 +1120,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1120
1120
|
return;
|
|
1121
1121
|
}
|
|
1122
1122
|
registerRoute(sent, sessionId);
|
|
1123
|
-
const legacyUpgrade = !
|
|
1123
|
+
const legacyUpgrade = !isManager && anchor !== void 0 && !sessionAnchor.threadId && sent.messageId !== anchor;
|
|
1124
1124
|
const stakeNeeded = stakeFlightToken !== void 0;
|
|
1125
1125
|
if (stakeNeeded) {
|
|
1126
1126
|
try {
|
|
@@ -1461,7 +1461,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1461
1461
|
return;
|
|
1462
1462
|
}
|
|
1463
1463
|
const unanchored = !meta.replyTo && !meta.threadId;
|
|
1464
|
-
if (
|
|
1464
|
+
if (isManager && unanchored) {
|
|
1465
1465
|
const residentRoute = {
|
|
1466
1466
|
messageId: "",
|
|
1467
1467
|
threadId: meta.threadId ?? null,
|
|
@@ -1495,7 +1495,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1495
1495
|
ctx.log(`im-forward: thread ownership unreadable for ${messageId}; dropping (fail closed)`);
|
|
1496
1496
|
return;
|
|
1497
1497
|
}
|
|
1498
|
-
if (
|
|
1498
|
+
if (isManager && event.chatType === "group" && meta.threadId) {
|
|
1499
1499
|
if (!scope.isCurrent()) {
|
|
1500
1500
|
releaseInvalidatedEvent();
|
|
1501
1501
|
return;
|
|
@@ -1505,7 +1505,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1505
1505
|
ctx.log(`im-forward: unowned-topic takeover lost the claim (${claim.reason}); ${messageId} dropped`);
|
|
1506
1506
|
return;
|
|
1507
1507
|
}
|
|
1508
|
-
ctx.log(`im-forward: unowned group topic ${meta.threadId} taken by
|
|
1508
|
+
ctx.log(`im-forward: unowned group topic ${meta.threadId} taken by manager (claimed)`);
|
|
1509
1509
|
await acceptRoutedMessage(
|
|
1510
1510
|
{ messageId: "", threadId: meta.threadId, sessionId, sentAt: Date.now() },
|
|
1511
1511
|
event,
|
|
@@ -1746,7 +1746,7 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
1746
1746
|
}
|
|
1747
1747
|
let consumerStartupInFlight = false;
|
|
1748
1748
|
function residentAliveSomewhere() {
|
|
1749
|
-
if (
|
|
1749
|
+
if (isManager) return false;
|
|
1750
1750
|
try {
|
|
1751
1751
|
const dir = path.join(resolveConfigDir(), "run", "ipc");
|
|
1752
1752
|
const entries = fs6.readdirSync(dir);
|
|
@@ -1785,7 +1785,7 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
1785
1785
|
}
|
|
1786
1786
|
function acquireClaimedSlot(binding) {
|
|
1787
1787
|
if (consumerLock) return true;
|
|
1788
|
-
if (!
|
|
1788
|
+
if (!isManager && residentAliveSomewhere()) {
|
|
1789
1789
|
ctx.log("im-forward: a live resident owns the feed class; standing down (dispatch mode)");
|
|
1790
1790
|
return false;
|
|
1791
1791
|
}
|
|
@@ -2006,7 +2006,7 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
2006
2006
|
// resident (this runtime, if unattended); anchored routing is
|
|
2007
2007
|
// table-based and explicit addressing always works. Unconditional:
|
|
2008
2008
|
// ownership is a capability axis, not route-table state.
|
|
2009
|
-
cfg.unattended ? "- note: unanchored DM/@app messages bind to this resident session; reply/thread messages route to their referenced session." : "- note: interactive host \u2014 only reply/thread-attributed or explicitly addressed messages enter (unanchored messages belong to the resident
|
|
2009
|
+
cfg.unattended ? "- note: unanchored DM/@app messages bind to this resident session; reply/thread messages route to their referenced session." : "- note: interactive host \u2014 only reply/thread-attributed or explicitly addressed messages enter (unanchored messages belong to the resident manager, if running)."
|
|
2010
2010
|
);
|
|
2011
2011
|
if (lastSendError)
|
|
2012
2012
|
lines.push(
|
|
@@ -576,7 +576,7 @@ function pieProc(ctx) {
|
|
|
576
576
|
ctx.registerTool({
|
|
577
577
|
name: "pie_proc",
|
|
578
578
|
label: "Pie worker processes",
|
|
579
|
-
description: "Controlled lifecycle for pie worker processes (
|
|
579
|
+
description: "Controlled lifecycle for pie worker processes (manager plan): spawn creates a bounded-shape pie worker \u2014 either a RESIDENT host (--json-events --idle, peer-addressable by worker name via ipc_send_notify) or a ONE-SHOT run (pie -p <task>, process exit is the completion). cwd must resolve inside the allowCwd roots configured in ~/.pie/pie-proc.json (symlinks resolved). Optional idle TTL retires idle RESIDENTS automatically (identity-verified; activity-aware). imForward accepts identity fields ONLY \u2014 executable selection is operator config. kill stops a worker gracefully (SIGTERM, bounded identity-verified escalation) and removes its generation; list shows workers with pid/session/cwd/liveness/last-active. Never use raw shell to start pie processes \u2014 this tool owns the audit trail, caps, and cleanup.",
|
|
580
580
|
parameters: Type.Object({
|
|
581
581
|
action: Type.Union([Type.Literal("spawn"), Type.Literal("kill"), Type.Literal("list")], { description: "spawn | kill | list" }),
|
|
582
582
|
name: Type.Optional(Type.String({ description: "Worker name ([a-z0-9-_], unique among alive workers)" })),
|
|
@@ -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,7 @@ 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 managerLiveness(pid, state) {
|
|
140
172
|
if (!pid || pid <= 0) return "dead";
|
|
141
173
|
try {
|
|
142
174
|
process.kill(pid, 0);
|
|
@@ -148,14 +180,14 @@ function conciergeLiveness(pid, state) {
|
|
|
148
180
|
if (cmd === void 0) {
|
|
149
181
|
return "unknown";
|
|
150
182
|
}
|
|
151
|
-
const sessionMatch = cmd.includes(state?.sessionId ?? "
|
|
183
|
+
const sessionMatch = cmd.includes(state?.sessionId ?? "manager-");
|
|
152
184
|
return /--idle/.test(cmd) && sessionMatch && /(pie|cli\.(js|ts|mjs))/i.test(cmd) ? "alive" : "dead";
|
|
153
185
|
} catch {
|
|
154
186
|
return "unknown";
|
|
155
187
|
}
|
|
156
188
|
}
|
|
157
189
|
function isConciergeAlive(pid, state) {
|
|
158
|
-
return
|
|
190
|
+
return managerLiveness(pid, state) === "alive";
|
|
159
191
|
}
|
|
160
192
|
function seedWorkspace(dir) {
|
|
161
193
|
fs.mkdirSync(path.join(dir, ".pie"), { recursive: true });
|
|
@@ -340,14 +372,14 @@ No IM forwarding config found. The first binding needs the interactive wizard (p
|
|
|
340
372
|
|
|
341
373
|
1) run pie inside a project directory, then Ctrl+R or /tools/im-forward setup to finish the wizard;
|
|
342
374
|
2) the wizard writes user-layer config (~/.pie/im-forward.json), shared by every pie;
|
|
343
|
-
3) run pie
|
|
375
|
+
3) run pie manager again.
|
|
344
376
|
|
|
345
|
-
To bind a separate app for the
|
|
377
|
+
To bind a separate app for the manager only, put a project-layer config at ~/.pie/manager/.pie/im-forward.json.
|
|
346
378
|
`);
|
|
347
379
|
return false;
|
|
348
380
|
}
|
|
349
381
|
function platformServiceName() {
|
|
350
|
-
return "dev.pie.
|
|
382
|
+
return "dev.pie.manager";
|
|
351
383
|
}
|
|
352
384
|
function xmlEscape(value) {
|
|
353
385
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
@@ -410,7 +442,7 @@ function installService(dir, state) {
|
|
|
410
442
|
const unitDir = path.join(os.homedir(), ".config", "systemd", "user");
|
|
411
443
|
fs.mkdirSync(unitDir, { recursive: true });
|
|
412
444
|
const unit = `[Unit]
|
|
413
|
-
Description=Pie
|
|
445
|
+
Description=Pie manager (resident im-forward host)
|
|
414
446
|
After=network-online.target
|
|
415
447
|
|
|
416
448
|
[Service]
|
|
@@ -579,7 +611,7 @@ async function stopConcierge(state) {
|
|
|
579
611
|
console.log("No recorded pid; nothing to do.");
|
|
580
612
|
return 0;
|
|
581
613
|
}
|
|
582
|
-
const liveness0 =
|
|
614
|
+
const liveness0 = managerLiveness(state.pid, state);
|
|
583
615
|
if (liveness0 === "dead") {
|
|
584
616
|
writeState({ sessionId: state.sessionId });
|
|
585
617
|
console.log("The process is no longer running.");
|
|
@@ -603,10 +635,10 @@ async function stopConcierge(state) {
|
|
|
603
635
|
if (!isConciergeAlive(state.pid, state)) break;
|
|
604
636
|
await new Promise((resolve2) => setTimeout(resolve2, 200));
|
|
605
637
|
}
|
|
606
|
-
const finalState =
|
|
638
|
+
const finalState = managerLiveness(state.pid, state);
|
|
607
639
|
if (finalState === "alive" || finalState === "unknown") {
|
|
608
640
|
console.error(
|
|
609
|
-
`Shutdown not confirmed (state: ${finalState}); the pid is kept. Retry with pie
|
|
641
|
+
`Shutdown not confirmed (state: ${finalState}); the pid is kept. Retry with pie manager stop or clean up manually.`
|
|
610
642
|
);
|
|
611
643
|
return 1;
|
|
612
644
|
}
|
|
@@ -625,7 +657,7 @@ function withStartLock(dir, fn) {
|
|
|
625
657
|
for (; ; ) {
|
|
626
658
|
if (Date.now() > deadline)
|
|
627
659
|
throw new Error(
|
|
628
|
-
"another pie
|
|
660
|
+
"another pie manager lifecycle command is in progress; retry shortly"
|
|
629
661
|
);
|
|
630
662
|
let latest = 0;
|
|
631
663
|
try {
|
|
@@ -703,13 +735,13 @@ function withStartLock(dir, fn) {
|
|
|
703
735
|
}
|
|
704
736
|
});
|
|
705
737
|
}
|
|
706
|
-
async function
|
|
738
|
+
async function runManagerCommand(args) {
|
|
707
739
|
const sub = args[0] ?? "";
|
|
708
740
|
const dir = workspaceDir();
|
|
709
741
|
if (sub === "status") {
|
|
710
742
|
const state = readState();
|
|
711
743
|
if (!state) {
|
|
712
|
-
console.log("Not initialized (run pie
|
|
744
|
+
console.log("Not initialized (run pie manager first).");
|
|
713
745
|
return;
|
|
714
746
|
}
|
|
715
747
|
console.log(`session: ${state.sessionId}`);
|
|
@@ -753,7 +785,7 @@ async function runConciergeCommand(args) {
|
|
|
753
785
|
`service: ${platformServiceName()} ${running ? "(running)" : "(stopped)"}`
|
|
754
786
|
);
|
|
755
787
|
} else {
|
|
756
|
-
const liveness =
|
|
788
|
+
const liveness = managerLiveness(state.pid, state);
|
|
757
789
|
const label = liveness === "alive" ? "(running)" : liveness === "unknown" ? "(alive, identity unverified)" : "(not running)";
|
|
758
790
|
console.log(`pid: ${state.pid ?? "-"} ${label}`);
|
|
759
791
|
}
|
|
@@ -868,20 +900,20 @@ async function runConciergeCommand(args) {
|
|
|
868
900
|
const state = readState();
|
|
869
901
|
if (!state) {
|
|
870
902
|
console.error(
|
|
871
|
-
"Run pie
|
|
903
|
+
"Run pie manager once to initialize (a stable session id is required)."
|
|
872
904
|
);
|
|
873
905
|
process.exitCode = 2;
|
|
874
906
|
return;
|
|
875
907
|
}
|
|
876
908
|
if (!imForwardConfigured(dir)) {
|
|
877
|
-
console.error("No IM config detected; complete the first pie
|
|
909
|
+
console.error("No IM config detected; complete the first pie manager initialization.");
|
|
878
910
|
process.exitCode = 2;
|
|
879
911
|
return;
|
|
880
912
|
}
|
|
881
|
-
const installLiveness =
|
|
913
|
+
const installLiveness = managerLiveness(state.pid, state);
|
|
882
914
|
if (installLiveness === "alive" || installLiveness === "unknown") {
|
|
883
915
|
console.log(
|
|
884
|
-
`A resident process is present (state: ${installLiveness}); run pie
|
|
916
|
+
`A resident process is present (state: ${installLiveness}); run pie manager stop before installing the service.`
|
|
885
917
|
);
|
|
886
918
|
process.exitCode = 2;
|
|
887
919
|
return;
|
|
@@ -894,7 +926,7 @@ async function runConciergeCommand(args) {
|
|
|
894
926
|
if (sub && sub !== "start") {
|
|
895
927
|
console.error(`Unknown subcommand: ${sub}`);
|
|
896
928
|
console.error(
|
|
897
|
-
"Usage: pie
|
|
929
|
+
"Usage: pie manager [status|stop|--install-service|--uninstall-service]"
|
|
898
930
|
);
|
|
899
931
|
process.exitCode = 2;
|
|
900
932
|
return;
|
|
@@ -902,20 +934,20 @@ async function runConciergeCommand(args) {
|
|
|
902
934
|
const existing = readState();
|
|
903
935
|
if (existing?.service) {
|
|
904
936
|
console.log(
|
|
905
|
-
"The
|
|
937
|
+
"The manager is managed by a system service (launchd/systemd/scheduled task). To take over manually, run --uninstall-service first."
|
|
906
938
|
);
|
|
907
939
|
return;
|
|
908
940
|
}
|
|
909
|
-
const startLiveness = existing ?
|
|
941
|
+
const startLiveness = existing ? managerLiveness(existing.pid, existing) : "dead";
|
|
910
942
|
if (existing && (startLiveness === "alive" || startLiveness === "unknown")) {
|
|
911
943
|
console.log(
|
|
912
|
-
`The
|
|
944
|
+
`The manager may already be running (pid ${existing.pid ?? "-"}, state: ${startLiveness}, session ${existing.sessionId}).`
|
|
913
945
|
);
|
|
914
946
|
return;
|
|
915
947
|
}
|
|
916
948
|
if (!imForwardConfigured(dir) && !process.stdin.isTTY) {
|
|
917
949
|
console.error(
|
|
918
|
-
"No IM config found and no terminal for the wizard; run pie
|
|
950
|
+
"No IM config found and no terminal for the wizard; run pie manager in a TTY."
|
|
919
951
|
);
|
|
920
952
|
process.exitCode = 2;
|
|
921
953
|
return;
|
|
@@ -941,14 +973,14 @@ async function runConciergeCommand(args) {
|
|
|
941
973
|
const lockedState = readState();
|
|
942
974
|
if (lockedState?.service) {
|
|
943
975
|
console.log(
|
|
944
|
-
"The
|
|
976
|
+
"The manager is managed by a system service (launchd/systemd/scheduled task). To take over manually, run --uninstall-service first."
|
|
945
977
|
);
|
|
946
978
|
return;
|
|
947
979
|
}
|
|
948
|
-
const lockedLiveness = lockedState ?
|
|
980
|
+
const lockedLiveness = lockedState ? managerLiveness(lockedState.pid, lockedState) : "dead";
|
|
949
981
|
if (lockedState && (lockedLiveness === "alive" || lockedLiveness === "unknown")) {
|
|
950
982
|
console.log(
|
|
951
|
-
`The
|
|
983
|
+
`The manager may already be running (pid ${lockedState.pid ?? "-"}, state: ${lockedLiveness}, session ${lockedState.sessionId}).`
|
|
952
984
|
);
|
|
953
985
|
return;
|
|
954
986
|
}
|
|
@@ -985,14 +1017,14 @@ async function runConciergeCommand(args) {
|
|
|
985
1017
|
const winnerPid = Math.min(...liveRivals);
|
|
986
1018
|
writeState({ ...state, pid: winnerPid });
|
|
987
1019
|
console.log(
|
|
988
|
-
`The
|
|
1020
|
+
`The manager is already running (concurrent starts converged on pid ${winnerPid}); this start's extra instance was terminated.`
|
|
989
1021
|
);
|
|
990
1022
|
return;
|
|
991
1023
|
}
|
|
992
1024
|
} catch {
|
|
993
1025
|
const winner = readState();
|
|
994
1026
|
if (winner && winner.pid && winner.pid !== pid && winner.sessionId === state.sessionId) {
|
|
995
|
-
const liveness =
|
|
1027
|
+
const liveness = managerLiveness(winner.pid, winner);
|
|
996
1028
|
if (liveness === "alive" || liveness === "unknown") {
|
|
997
1029
|
try {
|
|
998
1030
|
process.kill(pid, "SIGKILL");
|
|
@@ -1015,15 +1047,15 @@ async function runConciergeCommand(args) {
|
|
|
1015
1047
|
const ready = await waitForAgentReady(dir, 3e4, sinceOffset, sessionId);
|
|
1016
1048
|
if (ready) {
|
|
1017
1049
|
const now = readState();
|
|
1018
|
-
const stillOurs = now?.pid === pid && now.sessionId === sessionId &&
|
|
1050
|
+
const stillOurs = now?.pid === pid && now.sessionId === sessionId && managerLiveness(pid, now) === "alive";
|
|
1019
1051
|
if (stillOurs) {
|
|
1020
1052
|
console.log(`\u2713 Concierge ready \xB7 log ${logPath(dir)}`);
|
|
1021
1053
|
console.log(
|
|
1022
|
-
` Now just talk to it in your IM app; stop: pie
|
|
1054
|
+
` Now just talk to it in your IM app; stop: pie manager stop; status: pie manager status`
|
|
1023
1055
|
);
|
|
1024
1056
|
} else {
|
|
1025
1057
|
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
|
|
1058
|
+
`\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
1059
|
);
|
|
1028
1060
|
}
|
|
1029
1061
|
} else {
|
|
@@ -1035,5 +1067,5 @@ async function runConciergeCommand(args) {
|
|
|
1035
1067
|
}
|
|
1036
1068
|
export {
|
|
1037
1069
|
isTooBroadForWorkerSandbox,
|
|
1038
|
-
|
|
1070
|
+
runManagerCommand
|
|
1039
1071
|
};
|
package/dist/cli.js
CHANGED
|
@@ -84453,7 +84453,7 @@ async function loadJsonModeExtensions(params) {
|
|
|
84453
84453
|
// r17 P1: session naming on the resident host — im-forward's explicit
|
|
84454
84454
|
// addressing escape hatch ("<session name>: text") reads the session
|
|
84455
84455
|
// name; without these the json-events host returned undefined and a
|
|
84456
|
-
// cold-started
|
|
84456
|
+
// cold-started manager had NO intake route at all (its route table is
|
|
84457
84457
|
// empty until the first outbound forward, and --idle closes stdin —
|
|
84458
84458
|
// every inbound IM message hit "no route; ignoring" until something
|
|
84459
84459
|
// else happened to make the resident speak first).
|
|
@@ -86566,7 +86566,7 @@ var STABLE_CLI_COMMANDS = {
|
|
|
86566
86566
|
sessions: "sessions",
|
|
86567
86567
|
extensions: "extensions",
|
|
86568
86568
|
permissions: "permissions",
|
|
86569
|
-
|
|
86569
|
+
manager: "manager"
|
|
86570
86570
|
};
|
|
86571
86571
|
async function runWithJsonEventsConsoleIsolation(fn) {
|
|
86572
86572
|
const originalLog = console.log;
|
|
@@ -86781,10 +86781,10 @@ async function main() {
|
|
|
86781
86781
|
await runMemoryCommand(args.slice(1));
|
|
86782
86782
|
return;
|
|
86783
86783
|
}
|
|
86784
|
-
if (args[0] === STABLE_CLI_COMMANDS.
|
|
86785
|
-
const {
|
|
86784
|
+
if (args[0] === STABLE_CLI_COMMANDS.manager) {
|
|
86785
|
+
const { runManagerCommand } = await import("./chunks/manager-cli-JWCZEQXT.js");
|
|
86786
86786
|
try {
|
|
86787
|
-
await
|
|
86787
|
+
await runManagerCommand(args.slice(1));
|
|
86788
86788
|
} catch (error) {
|
|
86789
86789
|
console.error(error instanceof Error ? error.message : String(error));
|
|
86790
86790
|
process.exitCode = 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cydm/pie",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.6",
|
|
4
4
|
"description": "Pie AI Agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"test:skill-regressions": "node --test --test-force-exit --import tsx test/axi-bridge-lifecycle.test.ts test/bash-lifecycle.test.ts test/bash-powershell-display.test.ts test/skill-creator-runner.test.ts test/tui-use-contract.test.ts test/tui-use-runtime.test.ts test/tui-use-reap.test.ts test/tui-use-kill-escalation.test.ts test/browser-runtime.test.ts test/axi-stop-semantics.test.ts test/axi-page-routing.test.ts test/computer-use-axi.test.ts test/computer-evidence.test.ts test/interactive-lifecycle.test.ts",
|
|
21
21
|
"test:offline:post": "node --test --test-force-exit --import tsx test/remote-model-catalog.test.ts",
|
|
22
22
|
"test:offline": "node ../../scripts/run-cli-offline.mjs",
|
|
23
|
-
"test:offline:main": "node --test --test-concurrency=2 --test-force-exit --import tsx test/cli-attention.test.ts test/cron.test.ts test/cron-process.test.ts test/cron-poll-gate.test.ts test/memory-distill.test.ts test/memory-injection-freeze.test.ts test/memory-consumption-e2e.test.ts test/memory-frozen-matching.test.ts test/memory-soul-injection.test.ts test/config-dir-fail-closed.test.ts test/cron-concurrency.test.ts test/cron-dogfood.test.ts test/cron.terminal.test.ts test/cron-journey.terminal.test.ts test/builtin-extensions.test.ts test/im-forward.test.ts test/im-forward-cli.test.ts test/im-forward-integration.test.ts test/im-forward-dogfood.terminal.test.ts test/thread-registry.test.ts test/im-forward-event-hub.test.ts test/im-forward-session-anchors.test.ts test/extension-user-input.test.ts test/pie-ipc-pure.test.ts test/pie-ipc-discovery.test.ts test/pie-ipc-transport.test.ts test/pie-ipc-delivery.test.ts test/pie-ipc-extension.test.ts test/pie-ipc-e2e.test.ts test/pie-ipc-security.test.ts test/pie-ipc-dogfood.test.ts test/pie-ipc-resident-dispatch.test.ts test/pie-proc.test.ts test/pie-ipc-host.terminal.test.ts test/core-services.test.ts test/cli.test.ts test/cli-auto-compaction.test.ts test/execution-state-manager.test.ts test/queued-steer-execution-state.test.ts test/todo-steering-ownership.test.ts test/architecture-boundaries.test.ts test/attachment-resolver.test.ts test/kimi-attachment-provider.test.ts test/document-attachment-extension.test.ts test/auto-compact-overflow.test.ts test/auto-compaction-ui.test.ts test/tool-compaction-dogfood.terminal.test.ts test/hierarchical-command-system.test.ts test/mcp-adapter.test.ts test/herdr-agent-state.test.ts test/extensions-enablement.test.ts test/extension-selector-shortcuts.test.ts test/skill-tool-enablement.test.ts test/message-queue-unit.test.ts test/evals-harness.test.ts test/session-trace.test.ts test/json-events-event-sink.test.ts test/json-events-lifecycle-bridge.test.ts test/json-events-self-input.test.ts test/json-events-idle-mode.test.ts test/
|
|
23
|
+
"test:offline:main": "node --test --test-concurrency=2 --test-force-exit --import tsx test/cli-attention.test.ts test/cron.test.ts test/cron-process.test.ts test/cron-poll-gate.test.ts test/memory-distill.test.ts test/memory-injection-freeze.test.ts test/memory-consumption-e2e.test.ts test/memory-frozen-matching.test.ts test/memory-soul-injection.test.ts test/config-dir-fail-closed.test.ts test/cron-concurrency.test.ts test/cron-dogfood.test.ts test/cron.terminal.test.ts test/cron-journey.terminal.test.ts test/builtin-extensions.test.ts test/im-forward.test.ts test/im-forward-cli.test.ts test/im-forward-integration.test.ts test/im-forward-dogfood.terminal.test.ts test/thread-registry.test.ts test/im-forward-event-hub.test.ts test/im-forward-session-anchors.test.ts test/extension-user-input.test.ts test/pie-ipc-pure.test.ts test/pie-ipc-discovery.test.ts test/pie-ipc-transport.test.ts test/pie-ipc-delivery.test.ts test/pie-ipc-extension.test.ts test/pie-ipc-e2e.test.ts test/pie-ipc-security.test.ts test/pie-ipc-dogfood.test.ts test/pie-ipc-resident-dispatch.test.ts test/pie-proc.test.ts test/pie-ipc-host.terminal.test.ts test/core-services.test.ts test/cli.test.ts test/cli-auto-compaction.test.ts test/execution-state-manager.test.ts test/queued-steer-execution-state.test.ts test/todo-steering-ownership.test.ts test/architecture-boundaries.test.ts test/attachment-resolver.test.ts test/kimi-attachment-provider.test.ts test/document-attachment-extension.test.ts test/auto-compact-overflow.test.ts test/auto-compaction-ui.test.ts test/tool-compaction-dogfood.terminal.test.ts test/hierarchical-command-system.test.ts test/mcp-adapter.test.ts test/herdr-agent-state.test.ts test/extensions-enablement.test.ts test/extension-selector-shortcuts.test.ts test/skill-tool-enablement.test.ts test/message-queue-unit.test.ts test/evals-harness.test.ts test/session-trace.test.ts test/json-events-event-sink.test.ts test/json-events-lifecycle-bridge.test.ts test/json-events-self-input.test.ts test/json-events-idle-mode.test.ts test/manager-cli.test.ts test/json-events-sidechat-diagnostics.test.ts test/json-events-prewarm-shutdown.test.ts test/json-envelope-composition.test.ts test/subagent-session-store.test.ts test/supervisor-anchor-inject.test.ts test/runtime-mode-context.test.ts test/tool-policy.test.ts test/retry-policy.test.ts test/yolo-command.test.ts test/footer-lifecycle.test.ts test/footer-waiting-for-user.test.ts test/files-utils.test.ts test/source-size-guard.test.ts test/runtime-logger.test.ts test/release-readiness.test.ts test/package-artifacts.test.ts test/init-extension-contract.test.ts test/skills-runtime.test.ts test/skills-agents-discovery.test.ts test/skills-symlink.test.ts test/model-overrides.test.ts test/auth-storage.test.ts test/extension-register-provider.test.ts test/extension-reload.test.ts test/extension-terminal-input.test.ts test/extension-session-before-events.test.ts test/extension-widgets.test.ts test/extension-render-hint.test.ts test/extension-oauth-restore.test.ts test/cross-host-parity.test.ts test/tool-name-rendering.test.ts test/session-selector.test.ts test/tree-selector-pagination.test.ts test/context-report.test.ts test/context-signals.test.ts test/plan-cache-stability.test.ts test/cache-invalidation-trace.test.ts test/cache-retention.test.ts test/trace-report.test.ts test/boot-report.test.ts test/compaction-diff.test.ts test/entry-body-and-usage.test.ts test/session-control.test.ts test/terminal-title.test.ts test/interactive-controller-title.test.ts test/todo-title.terminal.test.ts test/host-envelope-dogfood.terminal.test.ts test/host-envelope-cross-mode.test.ts test/host-envelope-registry-lifecycle.test.ts test/host-envelope-migration-roundtrip.test.ts test/host-envelope-intake-order.test.ts test/plan-mode-extension.test.ts test/extension-interaction-signals.test.ts test/rendered-page-reader.test.ts test/tools-registry.test.ts test/system-prompt-contract.test.ts test/bash-yolo.test.ts test/bash-contract.test.ts test/bash-confirm-pending.test.ts test/interaction-status-lifecycle.test.ts test/bash-process-group.test.ts test/bash-artifact-sink.test.ts test/direct-bash.test.ts test/terminal-bell.test.ts test/ctrl-d-exit.test.ts test/session-display-title.test.ts test/calm-mode.test.ts test/stream-render-throttle.test.ts test/assistant-message-performance.test.ts test/streaming-split-parity.test.ts test/message-display-resync.test.ts test/project-root.test.ts test/guard-advisory-context.test.ts test/clear-command-usage.test.ts test/daily-agent-smoke.terminal.test.ts test/slash-menu-toggles.terminal.test.ts test/cli-args.test.ts test/session-resume-cwd.test.ts test/session-resume-restart.test.ts test/session-resume-picker.test.ts test/extensions-configured-paths.test.ts test/extensions-loader-path.test.ts test/file-picker.test.ts test/interrupt-recovery.test.ts test/mention-insert-regression.test.ts test/image-paste.test.ts test/clipboard-read-image.test.ts test/clipboard-races.test.ts test/clipboard-dogfood.terminal.test.ts test/mention-picker-navigation.test.ts test/pie-unity-rpc-skill.test.ts test/skill-creator-scripts.test.ts test/interactive-compact-command.test.ts test/computer-use-broker.test.ts test/computer-use-review-regressions.test.ts test/computer-use-safety.test.ts ../../scripts/node-test-diagnostics.test.js ../../scripts/offline-test-runner.test.js ../../scripts/unity-consumer.test.mjs ../../scripts/owned-process-cleanup.test.mjs",
|
|
24
24
|
"test:all": "npm run test:offline && npm run test:terminal:vitest",
|
|
25
25
|
"test:cron:tui": "node ../../scripts/run-with-env.mjs PIE_REAL_CRON_TUI=1 -- --test --import tsx test/cron.terminal.test.ts test/cron-journey.terminal.test.ts",
|
|
26
26
|
"test:ipc:tui": "node ../../scripts/run-with-env.mjs PIE_REAL_IPC_TUI=1 -- --test --import tsx test/pie-ipc-host.terminal.test.ts",
|