@cydm/pie 4.5.1 → 4.6.1

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.
@@ -0,0 +1,30 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import "./chunk-LZQXQOPJ.js";
3
+
4
+ // src/app/host-image-fallback.ts
5
+ import * as os from "node:os";
6
+ async function describeImageViaUnderstandingChain(options) {
7
+ try {
8
+ const { understandReadFile } = await import("./read-file-understanding-FMPXR6EJ.js");
9
+ const ext = options.filePath.toLowerCase().split(".").pop() ?? "";
10
+ const mimeType = ext === "png" ? "image/png" : ext === "gif" ? "image/gif" : ext === "webp" ? "image/webp" : "image/jpeg";
11
+ const result = await understandReadFile(
12
+ {
13
+ configDir: process.env.PIE_CODING_AGENT_DIR || os.homedir() + "/.pie",
14
+ cwd: process.cwd(),
15
+ getAgentModel: options.getAgentModel,
16
+ getSessionId: () => void 0,
17
+ resolveToolModel: (purpose, current) => options.modelRegistry.resolveToolModel(purpose, current),
18
+ resolveToolModelCandidates: (purpose, current) => options.modelRegistry.resolveToolModelCandidates(purpose, current)
19
+ },
20
+ { absolutePath: options.filePath, displayPath: options.displayName, mimeType, kind: "image" }
21
+ );
22
+ if (result.isError) return void 0;
23
+ return result.content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim() || void 0;
24
+ } catch {
25
+ return void 0;
26
+ }
27
+ }
28
+ export {
29
+ describeImageViaUnderstandingChain
30
+ };
@@ -358,6 +358,11 @@ function seedProcConfig(launchCwd) {
358
358
  } catch {
359
359
  return { state: "exists", file, root };
360
360
  }
361
+ const userLayer = path2.join(os.homedir(), ".pie", "pie-proc.json");
362
+ try {
363
+ if (fs2.existsSync(userLayer)) return { state: "user-layer", file: userLayer, root };
364
+ } catch {
365
+ }
361
366
  if (isTooBroadForWorkerSandbox(resolved)) {
362
367
  return { state: "too-broad", file, root };
363
368
  }
@@ -889,7 +894,7 @@ function withStartLock(dir, fn) {
889
894
  });
890
895
  }
891
896
  async function runUpgradeCommand(args) {
892
- const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-YVHK3XZE.js");
897
+ const { upgradePaths, performUpgrade, cliEffects, parseTarget } = await import("./manager-upgrade-LSTOHBUV.js");
893
898
  const targetIdx = args.indexOf("--target");
894
899
  if (targetIdx >= 0 && typeof args[targetIdx + 1] !== "string") {
895
900
  console.error('--target expects "latest" or an x.y.z version (no value given)');
@@ -1355,6 +1360,10 @@ async function runManagerCommand(args) {
1355
1360
  console.log(
1356
1361
  `Seeded pie-proc config: allowCwd = ${path2.resolve(process.cwd())} (dispatching works now; edit ${procSeed.file} to add roots \u2014 it applies on the next spawn)`
1357
1362
  );
1363
+ } else if (procSeed.state === "user-layer") {
1364
+ console.log(
1365
+ `pie-proc config: using the user layer (${procSeed.file}) \u2014 worker roots and caps come from there; edit it to change what the manager may dispatch.`
1366
+ );
1358
1367
  } else if (procSeed.state === "too-broad") {
1359
1368
  console.log(
1360
1369
  `Did not seed pie-proc config (the current directory ${path2.resolve(process.cwd())} is too broad). To dispatch work, write ${procSeed.file}: {"allowCwd": ["/your/project"]}`
@@ -241,23 +241,35 @@ async function performUpgrade(paths, effects, options) {
241
241
  return finish(build("guard", `the recorded resident pid cannot be verified (${residency}); refusing to restart blindly. Check pie manager status, then retry.`));
242
242
  }
243
243
  effects.log(`repair run: version ${toVersion} already installed but the resident is ${residency}; restarting without reinstall`);
244
- return finish(await restartAndRecycle(effects, state, fromVersion, toVersion, (s) => {
244
+ return finish(await restartAndRecycle(effects, paths, state, fromVersion, toVersion, (s) => {
245
245
  stage = s;
246
246
  }, build));
247
247
  }
248
+ if (effects.preInstallStop) {
249
+ const stopped = effects.preInstallStop(state);
250
+ if (stopped === "refused") {
251
+ return finish(build("install", "refused: could not stop the resident/workers before install (Windows file locks); check pie manager status and retry"));
252
+ }
253
+ if (stopped === "stopped") effects.log("windows: resident/workers stopped before install (native-module file locks)");
254
+ }
248
255
  const install = effects.npmInstall(toVersion);
249
256
  if (install.code !== 0) {
250
257
  return finish(build("install", `npm install @cydm/pie@${toVersion} failed (exit ${install.code}):
251
258
  ${install.tail}`));
252
259
  }
253
- return finish(await restartAndRecycle(effects, state, fromVersion, toVersion, (s) => {
260
+ const target = effects.installTargetCheck();
261
+ if (!target.ok) {
262
+ return finish(build("install", `install target mismatch \u2014 restart skipped:
263
+ ${target.detail}`));
264
+ }
265
+ return finish(await restartAndRecycle(effects, paths, state, fromVersion, toVersion, (s) => {
254
266
  stage = s;
255
267
  }, build));
256
268
  } catch (error) {
257
269
  return finish(build(stage, `unexpected error: ${error instanceof Error ? error.message : String(error)}`));
258
270
  }
259
271
  }
260
- async function restartAndRecycle(effects, state, fromVersion, toVersion, setStage, build) {
272
+ async function restartAndRecycle(effects, paths, state, fromVersion, toVersion, setStage, build) {
261
273
  setStage("restart");
262
274
  let successorPid;
263
275
  if (state.service === true) {
@@ -282,6 +294,11 @@ async function restartAndRecycle(effects, state, fromVersion, toVersion, setStag
282
294
  }
283
295
  successorPid = started.pid;
284
296
  effects.log(`manual mode: successor resident verified (pid ${successorPid})`);
297
+ const successor = findManagerResident(paths.discoveryDir, state.sessionId);
298
+ if (successor && successor.version && successor.pid === started.pid && successor.version !== toVersion) {
299
+ return build("restart", `successor became ready on pid ${successor.pid} but reports version ${successor.version}, expected ${toVersion} \u2014 the restart launched OLD code. The install target check passed yet the entry differs; inspect the entry path and npm prefixes before retrying.`);
300
+ }
301
+ if (successor && !successor.version) effects.log(`manual mode: successor discovery entry carries no version \u2014 upgrade success verified by readiness marker only`);
285
302
  }
286
303
  setStage("workers");
287
304
  const { recycle, skip } = partitionWorkers(effects.scanWorkers());
@@ -389,6 +406,42 @@ function cliEffects(paths, log) {
389
406
  const npm = resolveNpm(process.execPath);
390
407
  const effects = {
391
408
  npmInstall: (target) => runNpm(npm, ["install", "-g", `@cydm/pie@${target}`], 5 * 6e4),
409
+ installTargetCheck: () => {
410
+ try {
411
+ const rootRaw = spawnSync(npm.command, [...npm.prefixArgs, "root", "-g"], { encoding: "utf8", timeout: 3e4, windowsHide: true });
412
+ const npmRoot = String(rootRaw.stdout ?? "").trim().split(/\r?\n/).filter(Boolean).pop() ?? "";
413
+ if (rootRaw.status !== 0 || !npmRoot) return { ok: false, detail: `npm root -g failed (exit ${rootRaw.status}): ${String(rootRaw.stderr ?? "").slice(-200)}` };
414
+ let entry;
415
+ try {
416
+ entry = fs.realpathSync(paths.entryPath);
417
+ } catch {
418
+ return { ok: false, detail: `entry ${paths.entryPath} is not resolvable` };
419
+ }
420
+ let dir = path.dirname(entry);
421
+ let pkgRoot;
422
+ for (let i = 0; i < 6 && dir; i += 1) {
423
+ if (fs.existsSync(path.join(dir, "package.json"))) {
424
+ pkgRoot = dir;
425
+ break;
426
+ }
427
+ const parent = path.dirname(dir);
428
+ if (parent === dir) break;
429
+ dir = parent;
430
+ }
431
+ let installedPkg;
432
+ try {
433
+ installedPkg = fs.realpathSync(path.join(npmRoot, "@cydm", "pie"));
434
+ } catch {
435
+ return { ok: false, detail: `npm root ${npmRoot} has no @cydm/pie installed (realpath failed) \u2014 the install did not land in this npm's global tree.` };
436
+ }
437
+ if (pkgRoot === void 0 || installedPkg !== pkgRoot) {
438
+ return { ok: false, detail: `npm installed ${installedPkg} but the running entry resolves to ${pkgRoot ?? path.dirname(entry)} \u2014 a different prefix owns this Pie (multi-Node or custom npm prefix); the restart would keep the OLD code. Install with the npm that owns ${pkgRoot ?? entry} or fix the entry resolution.` };
439
+ }
440
+ return { ok: true, detail: `install target verified: ${pkgRoot}` };
441
+ } catch (error) {
442
+ return { ok: false, detail: `install-target check errored: ${error instanceof Error ? error.message : String(error)}` };
443
+ }
444
+ },
392
445
  npmViewLatest: () => {
393
446
  const out = runNpm(npm, ["view", "@cydm/pie", "version", "--json"], 3e4);
394
447
  if (out.code !== 0) return { tail: out.tail || `npm view exited ${out.code}` };
@@ -554,6 +607,36 @@ function cliEffects(paths, log) {
554
607
  writeResult: (result) => writeResultAtomic(paths.resultFile, result, log),
555
608
  tryLock: () => tryLockWithReclamation(paths.lockFile),
556
609
  unlock: () => unlockOwned(paths.lockFile),
610
+ ...process.platform === "win32" ? { preInstallStop: (state) => {
611
+ let touched = false;
612
+ for (const peer of partitionWorkers(effects.scanWorkers()).recycle) {
613
+ if (effects.retireWorkerIfStillIdle(peer) === "retired") {
614
+ touched = true;
615
+ effects.log(`windows pre-install: retired idle worker pid ${peer.pid} (${peer.name})`);
616
+ }
617
+ }
618
+ if (state.service === true) {
619
+ try {
620
+ spawnSync("schtasks", ["/End", "/TN", "dev.pie.manager"], { encoding: "utf8", timeout: 2e4, windowsHide: true });
621
+ touched = true;
622
+ } catch (error) {
623
+ log(`windows pre-install: schtasks /End failed: ${error instanceof Error ? error.message : String(error)}`);
624
+ return "refused";
625
+ }
626
+ } else {
627
+ const status = effects.residentStatus(state);
628
+ if (status === "foreign" || status === "unknown") return "refused";
629
+ if (status === "alive") {
630
+ const stopped = effects.terminateResident(state);
631
+ if (stopped !== "terminated" && stopped !== "dead") return "refused";
632
+ if (stopped === "terminated" && typeof state.pid === "number") {
633
+ if (!effects.waitExit(state.pid, 2e4)) log(`windows pre-install: resident pid ${state.pid} did not exit within 20s; npm may still hit file locks`);
634
+ }
635
+ touched = true;
636
+ }
637
+ }
638
+ return touched ? "stopped" : "unnecessary";
639
+ } } : {},
557
640
  log
558
641
  };
559
642
  return effects;
@@ -0,0 +1,14 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ understandReadFile
4
+ } from "./chunk-4PR34UZF.js";
5
+ import "./chunk-BLDI2GRF.js";
6
+ import "./chunk-Y3I2UV5Y.js";
7
+ import "./chunk-5KI4Y4LA.js";
8
+ import "./chunk-3W3SXVPB.js";
9
+ import "./chunk-XXGYUYXI.js";
10
+ import "./chunk-F7EBZTZO.js";
11
+ import "./chunk-LZQXQOPJ.js";
12
+ export {
13
+ understandReadFile
14
+ };