@cydm/pie 4.4.2 → 4.5.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 +6 -6
- package/dist/builtin/extensions/changelog/index.js +1 -1
- package/dist/builtin/extensions/cron/index.js +55 -7
- package/dist/builtin/extensions/document-attachments/index.js +1 -1
- package/dist/builtin/extensions/herdr-agent-state/index.js +1 -1
- package/dist/builtin/extensions/im-forward/README.md +3 -1
- package/dist/builtin/extensions/im-forward/index.js +364 -118
- package/dist/builtin/extensions/init/index.js +1 -1
- package/dist/builtin/extensions/mcp-adapter/index.js +2 -2
- package/dist/builtin/extensions/memory/index.js +9 -11
- package/dist/builtin/extensions/pie-ipc/index.js +70 -19
- package/dist/builtin/extensions/pie-proc/index.js +27 -13
- package/dist/builtin/extensions/plan-mode/index.js +6 -6
- package/dist/builtin/extensions/subagent/index.js +9 -11
- package/dist/builtin/extensions/todo/index.js +6 -6
- package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +24 -1
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +86 -21
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +6 -1
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{cli-CHC7XYFU.js → cli-NLPMVDGG.js} +32 -4
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +220 -22
- package/dist/chunks/{auth-storage-RABPRJ6T.js → auth-storage-C3FZMT7J.js} +3 -3
- package/dist/chunks/{chunk-OFLKAWI4.js → chunk-2CJIENLY.js} +90 -100
- package/dist/chunks/{chunk-R7VO46EK.js → chunk-3W3SXVPB.js} +5 -4
- package/dist/chunks/{chunk-IPLMGAML.js → chunk-5KI4Y4LA.js} +1 -1
- package/dist/chunks/{chunk-YNTIOWCD.js → chunk-BLDI2GRF.js} +5 -5
- package/dist/chunks/{chunk-UCKOXAME.js → chunk-CBDQJMUI.js} +9 -44
- package/dist/chunks/chunk-CGSFBWOM.js +100 -0
- package/dist/chunks/{chunk-7LTQLJJF.js → chunk-LAJXWOKS.js} +15 -10
- package/dist/chunks/{chunk-RZGYXAJU.js → chunk-LZQXQOPJ.js} +1 -12
- package/dist/chunks/{chunk-EQOI6RZV.js → chunk-NHV2CALB.js} +3 -5
- package/dist/chunks/{chunk-OV7SLSHR.js → chunk-SW2E33UL.js} +2 -4
- package/dist/chunks/{chunk-BPSCGGVF.js → chunk-XXGYUYXI.js} +1 -1
- package/dist/chunks/{chunk-XO3NM7BB.js → chunk-Y3I2UV5Y.js} +3 -3
- package/dist/chunks/{chunk-IZDNZW3S.js → chunk-Z2FKA2ZH.js} +8 -8
- package/dist/chunks/chunk-ZPJ3BNQB.js +126 -0
- package/dist/chunks/{config-HF2PDLN5.js → config-4EOI5NOU.js} +2 -4
- package/dist/chunks/{manager-cli-BYCF4RKN.js → manager-cli-2ATPC47M.js} +35 -5
- package/dist/chunks/manager-upgrade-5CPKTRJ7.js +562 -0
- package/dist/chunks/{model-registry-7FNIUYPF.js → model-registry-3XAHXXTA.js} +5 -5
- package/dist/chunks/{src-OVWRBWKU.js → src-B44QWSGM.js} +4 -4
- package/dist/chunks/{src-A5YI46OD.js → src-CLE5ILN4.js} +6 -6
- package/dist/chunks/{src-OA3TP6DS.js → src-EGXFJ3WA.js} +5 -5
- package/dist/chunks/{src-TF2RAGRU.js → src-Q7LU27C2.js} +3 -3
- package/dist/chunks/{test-stream-7YZDGBPO.js → test-stream-OR3EJBNF.js} +3 -3
- package/dist/cli.js +173 -136
- package/package.json +3 -3
- package/dist/chunks/chunk-7KLWHWZD.js +0 -164
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
readProcessCommandLine
|
|
4
|
+
} from "./chunk-X6LBWHK3.js";
|
|
5
|
+
import {
|
|
6
|
+
VERSION
|
|
7
|
+
} from "./chunk-CBDQJMUI.js";
|
|
8
|
+
import "./chunk-LZQXQOPJ.js";
|
|
9
|
+
|
|
10
|
+
// src/commands/manager-upgrade.ts
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import * as fs from "node:fs";
|
|
13
|
+
import * as os from "node:os";
|
|
14
|
+
import * as path from "node:path";
|
|
15
|
+
function upgradePaths(entryPath) {
|
|
16
|
+
const home = os.homedir() || process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
17
|
+
const override = process.env.PIE_IPC_CONFIG_DIR;
|
|
18
|
+
const agentDir = process.env.PIE_CODING_AGENT_DIR?.trim();
|
|
19
|
+
const raw = override !== void 0 ? override : agentDir || path.join(home, ".pie");
|
|
20
|
+
const configDir = process.platform === "win32" ? raw : path.resolve(raw === "~" ? home : raw.startsWith("~/") ? path.join(home, raw.slice(2)) : raw);
|
|
21
|
+
return {
|
|
22
|
+
workspaceDir: path.join(configDir, "manager"),
|
|
23
|
+
discoveryDir: path.join(configDir, "run", "ipc"),
|
|
24
|
+
stateFile: path.join(configDir, "manager", "manager.json"),
|
|
25
|
+
resultFile: path.join(configDir, "manager", "upgrade.json"),
|
|
26
|
+
lockFile: path.join(configDir, "manager", "upgrade.lock"),
|
|
27
|
+
entryPath
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function isDistInstall(entryPath) {
|
|
31
|
+
let resolved = path.resolve(entryPath);
|
|
32
|
+
try {
|
|
33
|
+
resolved = fs.realpathSync(resolved);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
return /node_modules[\\/]@cydm[\\/]pie[\\/]dist[\\/]cli\.(js|mjs)$/.test(resolved);
|
|
37
|
+
}
|
|
38
|
+
function versionDiffers(a, b) {
|
|
39
|
+
const canon = (v) => v.trim().replace(/^v/, "").split("+")[0];
|
|
40
|
+
return canon(a) !== canon(b);
|
|
41
|
+
}
|
|
42
|
+
function resolveNpm(nodePath) {
|
|
43
|
+
const prefix = path.dirname(path.dirname(nodePath));
|
|
44
|
+
for (const npmCli of [
|
|
45
|
+
path.join(prefix, "lib", "node_modules", "npm", "bin", "npm-cli.js"),
|
|
46
|
+
path.join(prefix, "node_modules", "npm", "bin", "npm-cli.js")
|
|
47
|
+
]) {
|
|
48
|
+
if (fs.existsSync(npmCli)) return { command: nodePath, prefixArgs: [npmCli], reason: `node + ${npmCli}` };
|
|
49
|
+
}
|
|
50
|
+
const sibling = path.join(path.dirname(nodePath), "npm");
|
|
51
|
+
if (fs.existsSync(sibling)) return { command: sibling, prefixArgs: [], reason: `sibling ${sibling}` };
|
|
52
|
+
return { command: "npm", prefixArgs: [], reason: "PATH npm" };
|
|
53
|
+
}
|
|
54
|
+
function runNpm(plan, args, timeoutMs) {
|
|
55
|
+
const child = spawnSync(plan.command, [...plan.prefixArgs, ...args], {
|
|
56
|
+
encoding: "utf8",
|
|
57
|
+
timeout: timeoutMs,
|
|
58
|
+
windowsHide: true,
|
|
59
|
+
cwd: os.tmpdir(),
|
|
60
|
+
maxBuffer: 8 * 1024 * 1024
|
|
61
|
+
});
|
|
62
|
+
const sanitize = (text) => text.replace(/[^\x20-\x7e\n\t]/g, "?").trim();
|
|
63
|
+
const stdout = sanitize(child.stdout ?? "");
|
|
64
|
+
const stderr = sanitize(child.stderr ?? "");
|
|
65
|
+
const lines = [stdout, stderr].join("\n").split("\n").filter(Boolean);
|
|
66
|
+
return { code: child.status, stdout, stderr, tail: lines.slice(-8).join("\n").slice(0, 1200) };
|
|
67
|
+
}
|
|
68
|
+
var STRICT_VERSION = /^\d+\.\d+\.\d+(?:[-+][\w.+-]+)?$/;
|
|
69
|
+
function parseViewVersion(stdout) {
|
|
70
|
+
const trimmed = stdout.trim();
|
|
71
|
+
if (!trimmed) return void 0;
|
|
72
|
+
try {
|
|
73
|
+
const parsed = JSON.parse(trimmed);
|
|
74
|
+
if (typeof parsed === "string" && STRICT_VERSION.test(parsed)) return parsed;
|
|
75
|
+
return void 0;
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
for (const line of trimmed.split("\n").reverse()) {
|
|
79
|
+
const bare = line.trim().replace(/^"|"$/g, "");
|
|
80
|
+
if (STRICT_VERSION.test(bare)) return bare;
|
|
81
|
+
}
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
function readDiscoveryEntry(discoveryDir, file) {
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(discoveryDir, file), "utf8"));
|
|
87
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return void 0;
|
|
88
|
+
return parsed;
|
|
89
|
+
} catch {
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function scanWorkers(discoveryDir) {
|
|
94
|
+
const out = [];
|
|
95
|
+
try {
|
|
96
|
+
const files = fs.readdirSync(discoveryDir).filter((f) => f.endsWith(".json"));
|
|
97
|
+
for (const file of files.slice(0, 256)) {
|
|
98
|
+
const parsed = readDiscoveryEntry(discoveryDir, file);
|
|
99
|
+
if (!parsed) continue;
|
|
100
|
+
if (typeof parsed.pid !== "number" || !Number.isInteger(parsed.pid) || parsed.pid <= 0) continue;
|
|
101
|
+
if (parsed.pid === process.pid) continue;
|
|
102
|
+
if (parsed.unattended !== true || parsed.isManager === true) continue;
|
|
103
|
+
try {
|
|
104
|
+
process.kill(parsed.pid, 0);
|
|
105
|
+
} catch {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
out.push({
|
|
109
|
+
pid: parsed.pid,
|
|
110
|
+
name: typeof parsed.displayName === "string" && parsed.displayName ? parsed.displayName : String(parsed.pid),
|
|
111
|
+
state: typeof parsed.state === "string" ? parsed.state : "?",
|
|
112
|
+
unattended: true,
|
|
113
|
+
file,
|
|
114
|
+
updatedAt: typeof parsed.updatedAt === "number" ? parsed.updatedAt : void 0
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
function partitionWorkers(peers) {
|
|
122
|
+
const recycle = [];
|
|
123
|
+
const skip = [];
|
|
124
|
+
for (const peer of peers) {
|
|
125
|
+
(peer.state === "idle" ? recycle : skip).push(peer);
|
|
126
|
+
}
|
|
127
|
+
return { recycle, skip };
|
|
128
|
+
}
|
|
129
|
+
function findManagerResident(discoveryDir, sessionId) {
|
|
130
|
+
try {
|
|
131
|
+
const files = fs.readdirSync(discoveryDir).filter((f) => f.endsWith(".json"));
|
|
132
|
+
for (const file of files.slice(0, 256)) {
|
|
133
|
+
const parsed = readDiscoveryEntry(discoveryDir, file);
|
|
134
|
+
if (!parsed || parsed.isManager !== true || typeof parsed.pid !== "number" || !Number.isInteger(parsed.pid) || parsed.pid <= 0) continue;
|
|
135
|
+
if (sessionId !== void 0 && typeof parsed.sessionId === "string" && parsed.sessionId !== sessionId) continue;
|
|
136
|
+
try {
|
|
137
|
+
process.kill(parsed.pid, 0);
|
|
138
|
+
} catch {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
pid: parsed.pid,
|
|
143
|
+
state: typeof parsed.state === "string" ? parsed.state : void 0,
|
|
144
|
+
startedAt: typeof parsed.startedAt === "number" ? parsed.startedAt : void 0,
|
|
145
|
+
version: typeof parsed.version === "string" ? parsed.version : void 0
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
}
|
|
150
|
+
return void 0;
|
|
151
|
+
}
|
|
152
|
+
function residentCommandLineLooksLikePie(pid, sessionToken) {
|
|
153
|
+
const cmdline = readProcessCommandLine(pid);
|
|
154
|
+
if (cmdline === void 0 || cmdline === "") return void 0;
|
|
155
|
+
if (!/json-events/.test(cmdline) || !/--idle/.test(cmdline)) return void 0;
|
|
156
|
+
if (sessionToken !== void 0 && !cmdline.includes(sessionToken)) return void 0;
|
|
157
|
+
return cmdline;
|
|
158
|
+
}
|
|
159
|
+
function processStartedAt(pid) {
|
|
160
|
+
if (process.platform !== "darwin" && process.platform !== "linux") return void 0;
|
|
161
|
+
try {
|
|
162
|
+
const out = spawnSync("ps", ["-p", String(pid), "-o", "lstart="], { encoding: "utf8", timeout: 5e3 });
|
|
163
|
+
const parsed = out.status === 0 ? Date.parse((out.stdout ?? "").trim()) : NaN;
|
|
164
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
165
|
+
} catch {
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function performUpgrade(paths, effects, options) {
|
|
170
|
+
const fromVersion = VERSION;
|
|
171
|
+
const build = (stage2, detail, extra = {}) => ({
|
|
172
|
+
ok: false,
|
|
173
|
+
stage: stage2,
|
|
174
|
+
fromVersion,
|
|
175
|
+
detail,
|
|
176
|
+
at: Date.now(),
|
|
177
|
+
...extra
|
|
178
|
+
});
|
|
179
|
+
const fail = (stage2, detail, extra = {}) => {
|
|
180
|
+
const result = build(stage2, detail, extra);
|
|
181
|
+
effects.writeResult(result);
|
|
182
|
+
return result;
|
|
183
|
+
};
|
|
184
|
+
if (!isDistInstall(paths.entryPath)) {
|
|
185
|
+
return fail("guard", "refused: the running pie is not a dist install (source/tsx runs do not upgrade via npm)");
|
|
186
|
+
}
|
|
187
|
+
if (!effects.tryLock()) {
|
|
188
|
+
return build("guard", "refused: another upgrade is already in progress (upgrade.lock held)");
|
|
189
|
+
}
|
|
190
|
+
let settled = false;
|
|
191
|
+
const finish = (result) => {
|
|
192
|
+
if (settled) return result;
|
|
193
|
+
settled = true;
|
|
194
|
+
effects.writeResult(result);
|
|
195
|
+
effects.unlock();
|
|
196
|
+
return result;
|
|
197
|
+
};
|
|
198
|
+
let stage = "guard";
|
|
199
|
+
try {
|
|
200
|
+
const state = effects.readState();
|
|
201
|
+
if (!state || typeof state.sessionId !== "string" || !state.sessionId) {
|
|
202
|
+
return finish(build("guard", "refused: no manager state found (run pie manager first)"));
|
|
203
|
+
}
|
|
204
|
+
const busy = effects.managerBusy();
|
|
205
|
+
if (busy.busy) {
|
|
206
|
+
return finish(build("guard", `refused: the manager is ${busy.state ?? "busy"} (an active turn would be cancelled); retry when idle`));
|
|
207
|
+
}
|
|
208
|
+
stage = "install";
|
|
209
|
+
const view = options.target === "latest" ? effects.npmViewLatest() : { version: options.target, tail: "" };
|
|
210
|
+
const toVersion = view.version;
|
|
211
|
+
if (!toVersion) {
|
|
212
|
+
return finish(build("install", `could not resolve the target version (${options.target}): ${view.tail || "npm view returned nothing usable"}`));
|
|
213
|
+
}
|
|
214
|
+
const differs = versionDiffers(fromVersion, toVersion);
|
|
215
|
+
const residency = effects.residentStatus(state);
|
|
216
|
+
if (!differs && !options.force) {
|
|
217
|
+
if (residency === "alive") {
|
|
218
|
+
return finish(build("guard", `already on ${toVersion} and the resident is running; use --force to reinstall`));
|
|
219
|
+
}
|
|
220
|
+
if (residency === "foreign" || residency === "unknown") {
|
|
221
|
+
return finish(build("guard", `the recorded resident pid cannot be verified (${residency}); refusing to restart blindly. Check pie manager status, then retry.`));
|
|
222
|
+
}
|
|
223
|
+
effects.log(`repair run: version ${toVersion} already installed but the resident is ${residency}; restarting without reinstall`);
|
|
224
|
+
return finish(await restartAndRecycle(effects, state, fromVersion, toVersion, (s) => {
|
|
225
|
+
stage = s;
|
|
226
|
+
}, build));
|
|
227
|
+
}
|
|
228
|
+
const install = effects.npmInstall(toVersion);
|
|
229
|
+
if (install.code !== 0) {
|
|
230
|
+
return finish(build("install", `npm install @cydm/pie@${toVersion} failed (exit ${install.code}):
|
|
231
|
+
${install.tail}`));
|
|
232
|
+
}
|
|
233
|
+
return finish(await restartAndRecycle(effects, state, fromVersion, toVersion, (s) => {
|
|
234
|
+
stage = s;
|
|
235
|
+
}, build));
|
|
236
|
+
} catch (error) {
|
|
237
|
+
return finish(build(stage, `unexpected error: ${error instanceof Error ? error.message : String(error)}`));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async function restartAndRecycle(effects, state, fromVersion, toVersion, setStage, build) {
|
|
241
|
+
setStage("restart");
|
|
242
|
+
let successorPid;
|
|
243
|
+
if (state.service === true) {
|
|
244
|
+
const restarted = effects.serviceRestart(state, toVersion);
|
|
245
|
+
if (!restarted.ok) {
|
|
246
|
+
return build("restart", `service restart not verified: ${restarted.detail ?? "unknown"}. The install succeeded; run pie manager upgrade again (repair) or restart the service manually.`);
|
|
247
|
+
}
|
|
248
|
+
successorPid = restarted.pid;
|
|
249
|
+
effects.log(`service mode: resident restarted via the service manager (pid ${successorPid ?? "?"})`);
|
|
250
|
+
} else {
|
|
251
|
+
const stopped = effects.terminateResident(state);
|
|
252
|
+
if (stopped === "foreign" || stopped === "unknown") {
|
|
253
|
+
return build("restart", `refused to signal the recorded pid (identity ${stopped} \u2014 pid reuse or unreadable process table); the install succeeded. Verify pie manager status and run pie manager upgrade again (repair).`);
|
|
254
|
+
}
|
|
255
|
+
if (stopped === "terminated" && typeof state.pid === "number") {
|
|
256
|
+
const exited = effects.waitExit(state.pid, 2e4);
|
|
257
|
+
if (!exited) effects.log(`old resident pid ${state.pid} did not exit within 20s; the successor spawn continues (pie manager start arbitrates duplicates)`);
|
|
258
|
+
}
|
|
259
|
+
const started = effects.startSuccessor();
|
|
260
|
+
if (!started.pid) {
|
|
261
|
+
return build("restart", `successor did not become ready: ${started.detail ?? "unknown"}. The old resident is gone and the install succeeded; run pie manager upgrade again (repair path restarts without reinstalling), or pie manager start manually.`);
|
|
262
|
+
}
|
|
263
|
+
successorPid = started.pid;
|
|
264
|
+
effects.log(`manual mode: successor resident verified (pid ${successorPid})`);
|
|
265
|
+
}
|
|
266
|
+
setStage("workers");
|
|
267
|
+
const { recycle, skip } = partitionWorkers(effects.scanWorkers());
|
|
268
|
+
const recycled = [];
|
|
269
|
+
const skipped = skip.map((w) => ({ pid: w.pid, name: w.name }));
|
|
270
|
+
for (const worker of recycle) {
|
|
271
|
+
const outcome = effects.retireWorkerIfStillIdle(worker);
|
|
272
|
+
if (outcome === "retired") recycled.push({ pid: worker.pid, name: worker.name });
|
|
273
|
+
else if (outcome === "busy") skipped.push({ pid: worker.pid, name: worker.name });
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
ok: true,
|
|
277
|
+
stage: "workers",
|
|
278
|
+
fromVersion,
|
|
279
|
+
toVersion,
|
|
280
|
+
workersRecycled: recycled,
|
|
281
|
+
workersSkipped: skipped,
|
|
282
|
+
at: Date.now()
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function readUpgradeResult(resultFile) {
|
|
286
|
+
try {
|
|
287
|
+
return JSON.parse(fs.readFileSync(resultFile, "utf8"));
|
|
288
|
+
} catch {
|
|
289
|
+
return void 0;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function writeResultAtomic(resultFile, result, log) {
|
|
293
|
+
try {
|
|
294
|
+
fs.mkdirSync(path.dirname(resultFile), { recursive: true });
|
|
295
|
+
const tmp = `${resultFile}.${process.pid}.tmp`;
|
|
296
|
+
fs.writeFileSync(tmp, `${JSON.stringify(result, null, " ")}
|
|
297
|
+
`);
|
|
298
|
+
fs.renameSync(tmp, resultFile);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
log(`upgrade: could not write the result file: ${error instanceof Error ? error.message : String(error)}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function tryLockWithReclamation(lockFile) {
|
|
304
|
+
const attempt = () => {
|
|
305
|
+
try {
|
|
306
|
+
fs.mkdirSync(path.dirname(lockFile), { recursive: true });
|
|
307
|
+
const tmp = `${lockFile}.${process.pid}.tmp`;
|
|
308
|
+
fs.writeFileSync(tmp, JSON.stringify({ pid: process.pid, at: Date.now() }));
|
|
309
|
+
fs.linkSync(tmp, lockFile);
|
|
310
|
+
try {
|
|
311
|
+
fs.rmSync(tmp, { force: true });
|
|
312
|
+
} catch {
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
} catch {
|
|
316
|
+
try {
|
|
317
|
+
fs.rmSync(`${lockFile}.${process.pid}.tmp`, { force: true });
|
|
318
|
+
} catch {
|
|
319
|
+
}
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
if (attempt()) return true;
|
|
324
|
+
let holderPid;
|
|
325
|
+
try {
|
|
326
|
+
const holder = JSON.parse(fs.readFileSync(lockFile, "utf8"));
|
|
327
|
+
if (typeof holder.pid === "number" && Number.isInteger(holder.pid) && holder.pid > 0) holderPid = holder.pid;
|
|
328
|
+
} catch {
|
|
329
|
+
}
|
|
330
|
+
if (holderPid === void 0) return false;
|
|
331
|
+
try {
|
|
332
|
+
process.kill(holderPid, 0);
|
|
333
|
+
return false;
|
|
334
|
+
} catch (error) {
|
|
335
|
+
if (error.code !== "ESRCH") return false;
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
fs.rmSync(lockFile, { force: true });
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
if (!attempt()) return false;
|
|
342
|
+
try {
|
|
343
|
+
const verify = JSON.parse(fs.readFileSync(lockFile, "utf8"));
|
|
344
|
+
return verify.pid === process.pid;
|
|
345
|
+
} catch {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function unlockOwned(lockFile) {
|
|
350
|
+
try {
|
|
351
|
+
const holder = JSON.parse(fs.readFileSync(lockFile, "utf8"));
|
|
352
|
+
if (holder.pid !== process.pid) return;
|
|
353
|
+
} catch {
|
|
354
|
+
}
|
|
355
|
+
try {
|
|
356
|
+
fs.rmSync(lockFile, { force: true });
|
|
357
|
+
} catch {
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function insideServiceCgroup() {
|
|
361
|
+
if (process.platform !== "linux") return false;
|
|
362
|
+
try {
|
|
363
|
+
return fs.readFileSync("/proc/self/cgroup", "utf8").includes("dev.pie.manager");
|
|
364
|
+
} catch {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function cliEffects(paths, log) {
|
|
369
|
+
const npm = resolveNpm(process.execPath);
|
|
370
|
+
const effects = {
|
|
371
|
+
npmInstall: (target) => runNpm(npm, ["install", "-g", `@cydm/pie@${target}`], 5 * 6e4),
|
|
372
|
+
npmViewLatest: () => {
|
|
373
|
+
const out = runNpm(npm, ["view", "@cydm/pie", "version", "--json"], 3e4);
|
|
374
|
+
if (out.code !== 0) return { tail: out.tail || `npm view exited ${out.code}` };
|
|
375
|
+
return { version: parseViewVersion(out.stdout), tail: out.tail };
|
|
376
|
+
},
|
|
377
|
+
readState: () => {
|
|
378
|
+
try {
|
|
379
|
+
return JSON.parse(fs.readFileSync(paths.stateFile, "utf8"));
|
|
380
|
+
} catch {
|
|
381
|
+
return void 0;
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
residentStatus: (state) => {
|
|
385
|
+
if (typeof state.pid === "number" && state.pid > 0) {
|
|
386
|
+
try {
|
|
387
|
+
process.kill(state.pid, 0);
|
|
388
|
+
} catch (error) {
|
|
389
|
+
return error.code === "ESRCH" ? "dead" : "unknown";
|
|
390
|
+
}
|
|
391
|
+
return residentCommandLineLooksLikePie(state.pid, state.sessionId) !== void 0 ? "alive" : "foreign";
|
|
392
|
+
}
|
|
393
|
+
const resident = findManagerResident(paths.discoveryDir, state.sessionId);
|
|
394
|
+
if (!resident) return "dead";
|
|
395
|
+
return residentCommandLineLooksLikePie(resident.pid, state.sessionId) !== void 0 ? "alive" : "unknown";
|
|
396
|
+
},
|
|
397
|
+
managerBusy: () => {
|
|
398
|
+
const state = effects.readState();
|
|
399
|
+
const resident = findManagerResident(paths.discoveryDir, state?.sessionId);
|
|
400
|
+
if (!resident) return { busy: false };
|
|
401
|
+
if (resident.state === "working" || resident.state === "blocked") return { busy: true, state: resident.state };
|
|
402
|
+
return { busy: false };
|
|
403
|
+
},
|
|
404
|
+
terminateResident: (state) => {
|
|
405
|
+
if (typeof state.pid === "number" && state.pid > 0) {
|
|
406
|
+
const status = effects.residentStatus(state);
|
|
407
|
+
if (status === "dead") return "dead";
|
|
408
|
+
if (status !== "alive") return status;
|
|
409
|
+
try {
|
|
410
|
+
process.kill(state.pid, process.platform === "win32" ? void 0 : "SIGTERM");
|
|
411
|
+
return "terminated";
|
|
412
|
+
} catch {
|
|
413
|
+
return "failed";
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const resident = findManagerResident(paths.discoveryDir, state.sessionId);
|
|
417
|
+
if (!resident) return "dead";
|
|
418
|
+
if (residentCommandLineLooksLikePie(resident.pid, state.sessionId) === void 0) return "unknown";
|
|
419
|
+
try {
|
|
420
|
+
process.kill(resident.pid, process.platform === "win32" ? void 0 : "SIGTERM");
|
|
421
|
+
return "terminated";
|
|
422
|
+
} catch {
|
|
423
|
+
return "failed";
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
waitExit: (pid, timeoutMs) => {
|
|
427
|
+
const deadline = Date.now() + timeoutMs;
|
|
428
|
+
while (Date.now() < deadline) {
|
|
429
|
+
try {
|
|
430
|
+
process.kill(pid, 0);
|
|
431
|
+
} catch {
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
|
|
435
|
+
}
|
|
436
|
+
try {
|
|
437
|
+
process.kill(pid, 0);
|
|
438
|
+
return false;
|
|
439
|
+
} catch {
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
startSuccessor: () => {
|
|
444
|
+
const child = spawnSync(
|
|
445
|
+
process.execPath,
|
|
446
|
+
[paths.entryPath, "manager", "start"],
|
|
447
|
+
{ encoding: "utf8", timeout: 9e4, windowsHide: true, cwd: paths.workspaceDir, env: process.env }
|
|
448
|
+
);
|
|
449
|
+
const out = `${child.stdout ?? ""}${child.stderr ?? ""}`.trim();
|
|
450
|
+
if (child.status !== 0) {
|
|
451
|
+
return { detail: out.slice(-400) || `pie manager start exited ${child.status}` };
|
|
452
|
+
}
|
|
453
|
+
const pidMatch = /Starting \(pid (\d+),/.exec(out);
|
|
454
|
+
if (!pidMatch) {
|
|
455
|
+
return { detail: out.slice(-400) || "pie manager start printed no pid line" };
|
|
456
|
+
}
|
|
457
|
+
const pid = Number(pidMatch[1]);
|
|
458
|
+
if (!/✓ Concierge ready/.test(out)) {
|
|
459
|
+
return { pid: void 0, detail: `pie manager start reported pid ${pid} but no readiness marker: ${out.slice(-300)}` };
|
|
460
|
+
}
|
|
461
|
+
try {
|
|
462
|
+
const recorded = JSON.parse(fs.readFileSync(paths.stateFile, "utf8"));
|
|
463
|
+
if (recorded.pid !== pid) return { pid: void 0, detail: `recorded state pid ${String(recorded.pid)} \u2260 started pid ${pid} (replaced or stopped concurrently)` };
|
|
464
|
+
process.kill(pid, 0);
|
|
465
|
+
} catch (error) {
|
|
466
|
+
return { pid: void 0, detail: `started pid ${pid} did not survive: ${error instanceof Error ? error.message : String(error)}` };
|
|
467
|
+
}
|
|
468
|
+
return { pid, detail: out.slice(-200) };
|
|
469
|
+
},
|
|
470
|
+
serviceRestart: (state, toVersion) => {
|
|
471
|
+
if (insideServiceCgroup()) {
|
|
472
|
+
try {
|
|
473
|
+
const unit = `dev.pie.manager-upgrade-${process.pid}`;
|
|
474
|
+
const delegated = spawnSync("systemd-run", ["--user", "--unit", unit, "--collect", "systemctl", "--user", "restart", "dev.pie.manager"], { encoding: "utf8", timeout: 2e4 });
|
|
475
|
+
return { ok: false, detail: `restart delegated to transient unit ${unit} (${delegated.status === 0 ? "accepted" : `systemd-run exit ${delegated.status}`}); the actor runs inside the service cgroup and cannot verify the outcome \u2014 check pie manager status afterwards` };
|
|
476
|
+
} catch (error) {
|
|
477
|
+
return { ok: false, detail: `could not delegate the service restart: ${error instanceof Error ? error.message : String(error)}` };
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const before = Date.now();
|
|
481
|
+
let restartDetail = "";
|
|
482
|
+
let restartFailed = false;
|
|
483
|
+
try {
|
|
484
|
+
if (process.platform === "darwin") {
|
|
485
|
+
const uid = process.getuid?.() ?? 501;
|
|
486
|
+
const r = spawnSync("launchctl", ["kickstart", "-k", `gui/${uid}/dev.pie.manager`], { encoding: "utf8", timeout: 2e4 });
|
|
487
|
+
restartDetail = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim();
|
|
488
|
+
restartFailed = r.status !== 0;
|
|
489
|
+
} else if (process.platform === "linux") {
|
|
490
|
+
const r = spawnSync("systemctl", ["--user", "restart", "dev.pie.manager"], { encoding: "utf8", timeout: 2e4 });
|
|
491
|
+
restartDetail = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim();
|
|
492
|
+
restartFailed = r.status !== 0;
|
|
493
|
+
} else if (process.platform === "win32") {
|
|
494
|
+
spawnSync("schtasks", ["/End", "/TN", "dev.pie.manager"], { encoding: "utf8", timeout: 2e4 });
|
|
495
|
+
const r = spawnSync("schtasks", ["/Run", "/TN", "dev.pie.manager"], { encoding: "utf8", timeout: 2e4 });
|
|
496
|
+
restartDetail = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim();
|
|
497
|
+
restartFailed = r.status !== 0;
|
|
498
|
+
} else {
|
|
499
|
+
return { ok: false, detail: `unsupported platform ${process.platform}` };
|
|
500
|
+
}
|
|
501
|
+
} catch (error) {
|
|
502
|
+
return { ok: false, detail: `service restart command failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
503
|
+
}
|
|
504
|
+
if (restartFailed) {
|
|
505
|
+
return { ok: false, detail: `service restart command failed: ${restartDetail.slice(0, 200) || "no output"}` };
|
|
506
|
+
}
|
|
507
|
+
const deadline = Date.now() + 3e4;
|
|
508
|
+
while (Date.now() < deadline) {
|
|
509
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1e3);
|
|
510
|
+
const resident = findManagerResident(paths.discoveryDir, state.sessionId);
|
|
511
|
+
if (resident && resident.startedAt !== void 0 && resident.startedAt >= before && resident.version === toVersion && residentCommandLineLooksLikePie(resident.pid, state.sessionId) !== void 0) {
|
|
512
|
+
return { ok: true, pid: resident.pid, detail: restartDetail.slice(0, 200) };
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return { ok: false, detail: `no fresh manager resident on ${toVersion} observed within 30s after the service restart (${restartDetail.slice(0, 200) || "no command output"})` };
|
|
516
|
+
},
|
|
517
|
+
scanWorkers: () => scanWorkers(paths.discoveryDir),
|
|
518
|
+
retireWorkerIfStillIdle: (peer) => {
|
|
519
|
+
const fresh = readDiscoveryEntry(paths.discoveryDir, peer.file);
|
|
520
|
+
if (!fresh || fresh.pid !== peer.pid) return "gone";
|
|
521
|
+
if (fresh.unattended !== true || fresh.isManager === true) return "foreign";
|
|
522
|
+
if (fresh.state !== "idle") return "busy";
|
|
523
|
+
if (residentCommandLineLooksLikePie(peer.pid) === void 0) return "foreign";
|
|
524
|
+
const updatedAt = typeof fresh.updatedAt === "number" ? fresh.updatedAt : peer.updatedAt;
|
|
525
|
+
const startedAt = processStartedAt(peer.pid);
|
|
526
|
+
if (updatedAt !== void 0 && startedAt !== void 0 && startedAt > updatedAt + 1e4) return "foreign";
|
|
527
|
+
try {
|
|
528
|
+
process.kill(peer.pid, process.platform === "win32" ? void 0 : "SIGTERM");
|
|
529
|
+
return "retired";
|
|
530
|
+
} catch {
|
|
531
|
+
return "gone";
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
writeResult: (result) => writeResultAtomic(paths.resultFile, result, log),
|
|
535
|
+
tryLock: () => tryLockWithReclamation(paths.lockFile),
|
|
536
|
+
unlock: () => unlockOwned(paths.lockFile),
|
|
537
|
+
log
|
|
538
|
+
};
|
|
539
|
+
return effects;
|
|
540
|
+
}
|
|
541
|
+
function parseTarget(raw) {
|
|
542
|
+
if (raw === void 0) return "latest";
|
|
543
|
+
if (raw === "latest") return raw;
|
|
544
|
+
return /^\d+\.\d+\.\d+(-[\w.-]+)?$/.test(raw.trim()) ? raw.trim() : void 0;
|
|
545
|
+
}
|
|
546
|
+
export {
|
|
547
|
+
cliEffects,
|
|
548
|
+
findManagerResident,
|
|
549
|
+
isDistInstall,
|
|
550
|
+
parseTarget,
|
|
551
|
+
parseViewVersion,
|
|
552
|
+
partitionWorkers,
|
|
553
|
+
performUpgrade,
|
|
554
|
+
processStartedAt,
|
|
555
|
+
readUpgradeResult,
|
|
556
|
+
residentCommandLineLooksLikePie,
|
|
557
|
+
resolveNpm,
|
|
558
|
+
runNpm,
|
|
559
|
+
scanWorkers,
|
|
560
|
+
upgradePaths,
|
|
561
|
+
versionDiffers
|
|
562
|
+
};
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
assertNoSecretSubstrings,
|
|
5
5
|
configuredRemoteCredentialValues,
|
|
6
6
|
loadResolvedModelsConfig
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-NHV2CALB.js";
|
|
8
|
+
import "./chunk-CBDQJMUI.js";
|
|
9
|
+
import "./chunk-3W3SXVPB.js";
|
|
10
|
+
import "./chunk-XXGYUYXI.js";
|
|
11
|
+
import "./chunk-LZQXQOPJ.js";
|
|
12
12
|
export {
|
|
13
13
|
ModelRegistry,
|
|
14
14
|
assertNoSecretSubstrings,
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
createToolCallerIdentity,
|
|
9
9
|
getAgentFailureMetadata,
|
|
10
10
|
getToolCallerIdentity
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-5KI4Y4LA.js";
|
|
12
|
+
import "./chunk-3W3SXVPB.js";
|
|
13
|
+
import "./chunk-XXGYUYXI.js";
|
|
14
|
+
import "./chunk-LZQXQOPJ.js";
|
|
15
15
|
export {
|
|
16
16
|
Agent,
|
|
17
17
|
agentLoop,
|
|
@@ -213,14 +213,14 @@ import {
|
|
|
213
213
|
understandFileWithModel,
|
|
214
214
|
validateTodos,
|
|
215
215
|
writeJournalNarrative
|
|
216
|
-
} from "./chunk-
|
|
217
|
-
import "./chunk-
|
|
218
|
-
import "./chunk-
|
|
216
|
+
} from "./chunk-BLDI2GRF.js";
|
|
217
|
+
import "./chunk-Y3I2UV5Y.js";
|
|
218
|
+
import "./chunk-5KI4Y4LA.js";
|
|
219
219
|
import {
|
|
220
220
|
hashText
|
|
221
|
-
} from "./chunk-
|
|
222
|
-
import "./chunk-
|
|
223
|
-
import "./chunk-
|
|
221
|
+
} from "./chunk-3W3SXVPB.js";
|
|
222
|
+
import "./chunk-XXGYUYXI.js";
|
|
223
|
+
import "./chunk-LZQXQOPJ.js";
|
|
224
224
|
export {
|
|
225
225
|
ANTONYM_PAIRS,
|
|
226
226
|
AskUserMultiParamsSchema,
|
|
@@ -142,11 +142,11 @@ import {
|
|
|
142
142
|
substituteArgs,
|
|
143
143
|
validateRetainedTailEntries,
|
|
144
144
|
verifyPreparedCompactionCommit
|
|
145
|
-
} from "./chunk-
|
|
146
|
-
import "./chunk-
|
|
147
|
-
import "./chunk-
|
|
148
|
-
import "./chunk-
|
|
149
|
-
import "./chunk-
|
|
145
|
+
} from "./chunk-Y3I2UV5Y.js";
|
|
146
|
+
import "./chunk-5KI4Y4LA.js";
|
|
147
|
+
import "./chunk-3W3SXVPB.js";
|
|
148
|
+
import "./chunk-XXGYUYXI.js";
|
|
149
|
+
import "./chunk-LZQXQOPJ.js";
|
|
150
150
|
export {
|
|
151
151
|
AGENTS_CONTEXT_FILE_NAME,
|
|
152
152
|
AgentSessionController,
|
|
@@ -62,11 +62,11 @@ import {
|
|
|
62
62
|
unregisterModel,
|
|
63
63
|
validateToolArguments,
|
|
64
64
|
validateToolCall
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-3W3SXVPB.js";
|
|
66
66
|
import {
|
|
67
67
|
Type
|
|
68
|
-
} from "./chunk-
|
|
69
|
-
import "./chunk-
|
|
68
|
+
} from "./chunk-XXGYUYXI.js";
|
|
69
|
+
import "./chunk-LZQXQOPJ.js";
|
|
70
70
|
export {
|
|
71
71
|
ANTHROPIC_PROMPT_CACHE_CAPABILITY,
|
|
72
72
|
AssistantMessageEventStream,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
EventStream
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-3W3SXVPB.js";
|
|
5
|
+
import "./chunk-XXGYUYXI.js";
|
|
6
|
+
import "./chunk-LZQXQOPJ.js";
|
|
7
7
|
|
|
8
8
|
// src/app/test-stream.ts
|
|
9
9
|
function parseSystemPromptExpectations(value) {
|