@cydm/pie 4.3.6 → 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.
Files changed (27) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +4 -4
  2. package/dist/builtin/extensions/cron/index.js +7 -1
  3. package/dist/builtin/extensions/im-forward/index.js +86 -68
  4. package/dist/builtin/extensions/mcp-adapter/index.js +7 -1
  5. package/dist/builtin/extensions/memory/index.js +5 -5
  6. package/dist/builtin/extensions/pie-ipc/index.js +1 -1
  7. package/dist/builtin/extensions/pie-proc/index.js +2 -1
  8. package/dist/builtin/extensions/plan-mode/index.js +4 -4
  9. package/dist/builtin/extensions/subagent/index.js +5 -5
  10. package/dist/builtin/extensions/todo/index.js +4 -4
  11. package/dist/chunks/{chunk-J2LGVYH2.js → chunk-2SAFRLFJ.js} +28 -13
  12. package/dist/chunks/{chunk-JQRZLVPY.js → chunk-6JEYRAQM.js} +1898 -1692
  13. package/dist/chunks/{chunk-NCP264ZE.js → chunk-B4N5LJMD.js} +1 -1
  14. package/dist/chunks/{chunk-PFXSA2LK.js → chunk-BJ4XN5VX.js} +5 -5
  15. package/dist/chunks/{chunk-H5G55G3R.js → chunk-N3BWFAMZ.js} +11 -1
  16. package/dist/chunks/{chunk-QX6WS73C.js → chunk-VHKMWOG3.js} +1 -1
  17. package/dist/chunks/{chunk-PC6HUZAD.js → chunk-WZLO5V2X.js} +3 -3
  18. package/dist/chunks/{chunk-BK36Y35W.js → chunk-XMOWWL4B.js} +2 -2
  19. package/dist/chunks/{manager-cli-JWCZEQXT.js → manager-cli-QNMCCIFG.js} +253 -7
  20. package/dist/chunks/{model-registry-YA6U366L.js → model-registry-NKE3BRSZ.js} +2 -2
  21. package/dist/chunks/{src-ODLT57PQ.js → src-46R5ZFOU.js} +2 -2
  22. package/dist/chunks/{src-VPMIQGEW.js → src-4EQ7PBEI.js} +3 -3
  23. package/dist/chunks/{src-XSLD2IQ2.js → src-BHIH4VLE.js} +1 -1
  24. package/dist/chunks/{src-AQ4H43UM.js → src-UVULNQOO.js} +4 -4
  25. package/dist/chunks/{test-stream-GIUD5JWS.js → test-stream-FC6ZRENI.js} +1 -1
  26. package/dist/cli.js +343 -204
  27. package/package.json +3 -3
@@ -4,7 +4,7 @@ import {
4
4
  disposeModelTransports,
5
5
  streamSimple,
6
6
  validateToolArguments
7
- } from "./chunk-JQRZLVPY.js";
7
+ } from "./chunk-6JEYRAQM.js";
8
8
 
9
9
  // ../../packages/agent-core/src/failure.ts
10
10
  function getAgentFailureMetadata(error) {
@@ -171,11 +171,11 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false) {
171
171
  let result;
172
172
  let ledger;
173
173
  try {
174
- const { ModelRegistry } = await import("./model-registry-YA6U366L.js");
174
+ const { ModelRegistry } = await import("./model-registry-NKE3BRSZ.js");
175
175
  const { AuthStorage } = await import("./auth-storage-3EGM3VTK.js");
176
176
  const { getSessionsDir } = await import("./config-74AUVDLT.js");
177
- const { FileSessionStore } = await import("./src-VPMIQGEW.js");
178
- const { MemoryStore, runDistillation } = await import("./src-AQ4H43UM.js");
177
+ const { FileSessionStore } = await import("./src-4EQ7PBEI.js");
178
+ const { MemoryStore, runDistillation } = await import("./src-UVULNQOO.js");
179
179
  const store = new MemoryStore(memoryRoot);
180
180
  ledger = store;
181
181
  const registry = new ModelRegistry(AuthStorage.create());
@@ -190,7 +190,7 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false) {
190
190
  if (!resolved.model || !resolved.apiKey) {
191
191
  throw new Error(`no complete model/key pair for class ${modelClass}${resolved.fallbackReason ? `: ${resolved.fallbackReason}` : ""}`);
192
192
  }
193
- const { completeSimple } = await import("./src-XSLD2IQ2.js");
193
+ const { completeSimple } = await import("./src-BHIH4VLE.js");
194
194
  const message = await withModelTimeout(
195
195
  completeSimple(
196
196
  resolved.model,
@@ -252,7 +252,7 @@ async function runDistillAuto(memoryRoot, days = 7) {
252
252
  } catch {
253
253
  }
254
254
  };
255
- const { MemoryStore, todayKey } = await import("./src-AQ4H43UM.js");
255
+ const { MemoryStore, todayKey } = await import("./src-UVULNQOO.js");
256
256
  const store = new MemoryStore(memoryRoot);
257
257
  const today = todayKey(Date.now());
258
258
  const dates = [];
@@ -611,7 +611,7 @@ function lockAlive(info, now = Date.now()) {
611
611
  if (!info) return false;
612
612
  return pidAlive(info.pid) && now - info.heartbeatAt < LOCK_STALE_MS;
613
613
  }
614
- function tryClaimConsumer(binding, holder, onLost) {
614
+ function tryClaimConsumer(binding, holder, onLost, shouldYield) {
615
615
  const target = lockPath(binding);
616
616
  const mine = JSON.stringify({ pid: process.pid, holder, heartbeatAt: Date.now(), binding });
617
617
  const takeOver = () => {
@@ -653,6 +653,16 @@ function tryClaimConsumer(binding, holder, onLost) {
653
653
  onLost?.();
654
654
  return;
655
655
  }
656
+ if (shouldYield?.() === true) {
657
+ released = true;
658
+ clearInterval(heartbeatTimer);
659
+ try {
660
+ if (readLock(binding)?.pid === process.pid) fs2.rmSync(target, { force: true });
661
+ } catch {
662
+ }
663
+ onLost?.();
664
+ return;
665
+ }
656
666
  fs2.writeFileSync(target, `${JSON.stringify({ pid: process.pid, holder, heartbeatAt: Date.now(), binding })}
657
667
  `);
658
668
  } catch {
@@ -7,7 +7,7 @@ import {
7
7
  modelSupportsToolPurpose,
8
8
  requiredCapabilityForToolPurpose,
9
9
  sortToolModelCandidatesByCapability
10
- } from "./chunk-JQRZLVPY.js";
10
+ } from "./chunk-6JEYRAQM.js";
11
11
 
12
12
  // src/core/model-registry.ts
13
13
  import * as fs from "fs";
@@ -13,11 +13,11 @@ import {
13
13
  parseEntryIdSeq,
14
14
  readAncestryPage,
15
15
  requestInteraction
16
- } from "./chunk-BK36Y35W.js";
16
+ } from "./chunk-XMOWWL4B.js";
17
17
  import {
18
18
  Agent,
19
19
  getToolCallerIdentity
20
- } from "./chunk-NCP264ZE.js";
20
+ } from "./chunk-B4N5LJMD.js";
21
21
  import {
22
22
  AssistantMessageEventStream,
23
23
  completeSimple,
@@ -25,7 +25,7 @@ import {
25
25
  getFileSystem,
26
26
  hashText,
27
27
  streamSimple
28
- } from "./chunk-JQRZLVPY.js";
28
+ } from "./chunk-6JEYRAQM.js";
29
29
  import {
30
30
  Type
31
31
  } from "./chunk-XXGYUYXI.js";
@@ -2,14 +2,14 @@ import { createRequire as __createRequire } from "node:module"; const require =
2
2
  import {
3
3
  createAgentOperationError,
4
4
  getAgentFailureMetadata
5
- } from "./chunk-NCP264ZE.js";
5
+ } from "./chunk-B4N5LJMD.js";
6
6
  import {
7
7
  FileSystemGateway,
8
8
  detectPlatform,
9
9
  getFileSystemGateway,
10
10
  getPlatformConfig,
11
11
  streamSimple
12
- } from "./chunk-JQRZLVPY.js";
12
+ } from "./chunk-6JEYRAQM.js";
13
13
  import {
14
14
  Type
15
15
  } from "./chunk-XXGYUYXI.js";
@@ -168,6 +168,16 @@ function writeState(state, dir = workspaceDir()) {
168
168
  fs.writeFileSync(tmp, JSON.stringify(state, null, " "));
169
169
  fs.renameSync(tmp, statePath(dir));
170
170
  }
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
+ }
171
181
  function managerLiveness(pid, state) {
172
182
  if (!pid || pid <= 0) return "dead";
173
183
  try {
@@ -316,7 +326,7 @@ function spawnResident(state, dir) {
316
326
  // PIE_PROC_CURATED_NAME: the resident's display name is manager from the
317
327
  // very first composition (v2 Phase 1.3) — never the first IM/terminal
318
328
  // message title, never a flip-flopping derived label.
319
- env: { ...process.env, PIE_PROC_CURATED_NAME: "manager" }
329
+ env: managerSpawnEnv()
320
330
  });
321
331
  child.unref();
322
332
  writeState({ ...state, pid: child.pid, startedAt: Date.now() });
@@ -378,6 +388,30 @@ To bind a separate app for the manager only, put a project-layer config at ~/.pi
378
388
  `);
379
389
  return false;
380
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
+ }
381
415
  function platformServiceName() {
382
416
  return "dev.pie.manager";
383
417
  }
@@ -402,7 +436,21 @@ function installService(dir, state) {
402
436
  const entry = cliEntry();
403
437
  const logFile = logPath(dir);
404
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
+ ];
405
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");
406
454
  const plist = `<?xml version="1.0" encoding="UTF-8"?>
407
455
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
408
456
  <plist version="1.0"><dict>
@@ -415,6 +463,7 @@ function installService(dir, state) {
415
463
  </array>
416
464
  <key>EnvironmentVariables</key><dict>
417
465
  <key>PATH</key><string>${xmlEscape(servicePath)}</string>
466
+ ${envPlist}
418
467
  </dict>
419
468
  <key>WorkingDirectory</key><string>${xmlEscape(dir)}</string>
420
469
  <key>RunAtLoad</key><true/>
@@ -447,6 +496,7 @@ After=network-online.target
447
496
 
448
497
  [Service]
449
498
  Environment=${systemdEnvironmentToken(`PATH=${servicePath}`)}
499
+ ${serviceEnv.filter(([, v]) => typeof v === "string" && v.length > 0).map(([k, v]) => `Environment=${systemdEnvironmentToken(`${k}=${v}`)}`).join("\n")}
450
500
  # r26 P2: the ':' prefix disables systemd's variable expansion for this
451
501
  # command line \u2014 install paths may legitimately contain literal '$' runs,
452
502
  # and quotes do NOT protect them (undefined vars expand to empty strings).
@@ -472,7 +522,8 @@ WantedBy=default.target`;
472
522
  return;
473
523
  }
474
524
  if (process.platform === "win32") {
475
- const cmd = `cd /d "${dir}" && "${process.execPath}" "${entry}" --json-events --idle --session-id ${state.sessionId} >> "${logFile}" 2>&1`;
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`;
476
527
  execFileSync("schtasks", [
477
528
  "/Create",
478
529
  "/TN",
@@ -606,6 +657,75 @@ function uninstallService() {
606
657
  }
607
658
  throw new Error(`unsupported platform: ${process.platform}`);
608
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
+ }
609
729
  async function stopConcierge(state) {
610
730
  if (!state.pid) {
611
731
  console.log("No recorded pid; nothing to do.");
@@ -613,7 +733,7 @@ async function stopConcierge(state) {
613
733
  }
614
734
  const liveness0 = managerLiveness(state.pid, state);
615
735
  if (liveness0 === "dead") {
616
- writeState({ sessionId: state.sessionId });
736
+ writeState({ sessionId: state.sessionId, attachOwners: state.attachOwners });
617
737
  console.log("The process is no longer running.");
618
738
  return 0;
619
739
  }
@@ -642,7 +762,7 @@ async function stopConcierge(state) {
642
762
  );
643
763
  return 1;
644
764
  }
645
- writeState({ sessionId: state.sessionId });
765
+ writeState({ sessionId: state.sessionId, attachOwners: state.attachOwners });
646
766
  console.log("Stopped.");
647
767
  return 0;
648
768
  }
@@ -882,7 +1002,7 @@ async function runManagerCommand(args) {
882
1002
  if (toreDown) {
883
1003
  const state = readState();
884
1004
  if (state && state.service) {
885
- writeState({ sessionId: state.sessionId, service: void 0 });
1005
+ writeState({ sessionId: state.sessionId, attachOwners: state.attachOwners });
886
1006
  } else if (state) {
887
1007
  console.log("No service-managed state detected; a manual instance, if present, is unaffected.");
888
1008
  }
@@ -918,15 +1038,134 @@ async function runManagerCommand(args) {
918
1038
  process.exitCode = 2;
919
1039
  return;
920
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.`
1045
+ );
1046
+ process.exitCode = 2;
1047
+ return;
1048
+ }
921
1049
  installService(dir, state);
922
1050
  writeState({ ...state, pid: void 0, service: true });
923
1051
  });
924
1052
  return;
925
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
+ }
926
1165
  if (sub && sub !== "start") {
927
1166
  console.error(`Unknown subcommand: ${sub}`);
928
1167
  console.error(
929
- "Usage: pie manager [status|stop|--install-service|--uninstall-service]"
1168
+ "Usage: pie manager [start|status|stop|attach|--install-service|--uninstall-service]"
930
1169
  );
931
1170
  process.exitCode = 2;
932
1171
  return;
@@ -978,6 +1217,13 @@ async function runManagerCommand(args) {
978
1217
  return;
979
1218
  }
980
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.`
1224
+ );
1225
+ return;
1226
+ }
981
1227
  if (lockedState && (lockedLiveness === "alive" || lockedLiveness === "unknown")) {
982
1228
  console.log(
983
1229
  `The manager may already be running (pid ${lockedState.pid ?? "-"}, state: ${lockedLiveness}, session ${lockedState.sessionId}).`
@@ -999,7 +1245,7 @@ async function runManagerCommand(args) {
999
1245
  });
1000
1246
  const token2 = `--session-id ${state.sessionId}`;
1001
1247
  const rivals = String(listing).split("\n").map((line) => line.trim()).filter(
1002
- (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")
1003
1249
  ).map((line) => Number(line.split(/\s+/)[0])).filter((p) => Number.isFinite(p) && p > 0 && p !== pid);
1004
1250
  const liveRivals = rivals.filter((rival) => {
1005
1251
  try {
@@ -4,9 +4,9 @@ import {
4
4
  assertNoSecretSubstrings,
5
5
  configuredRemoteCredentialValues,
6
6
  loadResolvedModelsConfig
7
- } from "./chunk-QX6WS73C.js";
7
+ } from "./chunk-VHKMWOG3.js";
8
8
  import "./chunk-ILUHTKF3.js";
9
- import "./chunk-JQRZLVPY.js";
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-NCP264ZE.js";
12
- import "./chunk-JQRZLVPY.js";
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-BK36Y35W.js";
146
- import "./chunk-NCP264ZE.js";
147
- import "./chunk-JQRZLVPY.js";
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 {
@@ -62,7 +62,7 @@ import {
62
62
  unregisterModel,
63
63
  validateToolArguments,
64
64
  validateToolCall
65
- } from "./chunk-JQRZLVPY.js";
65
+ } from "./chunk-6JEYRAQM.js";
66
66
  import {
67
67
  Type
68
68
  } from "./chunk-XXGYUYXI.js";
@@ -210,12 +210,12 @@ import {
210
210
  understandFileWithModel,
211
211
  validateTodos,
212
212
  writeJournalNarrative
213
- } from "./chunk-PC6HUZAD.js";
214
- import "./chunk-BK36Y35W.js";
215
- import "./chunk-NCP264ZE.js";
213
+ } from "./chunk-WZLO5V2X.js";
214
+ import "./chunk-XMOWWL4B.js";
215
+ import "./chunk-B4N5LJMD.js";
216
216
  import {
217
217
  hashText
218
- } from "./chunk-JQRZLVPY.js";
218
+ } from "./chunk-6JEYRAQM.js";
219
219
  import "./chunk-XXGYUYXI.js";
220
220
  import "./chunk-LZQXQOPJ.js";
221
221
  export {
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  EventStream
4
- } from "./chunk-JQRZLVPY.js";
4
+ } from "./chunk-6JEYRAQM.js";
5
5
  import "./chunk-XXGYUYXI.js";
6
6
  import "./chunk-LZQXQOPJ.js";
7
7