@cydm/pie 4.4.1 → 4.4.3

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 (47) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +6 -6
  2. package/dist/builtin/extensions/changelog/index.js +1 -1
  3. package/dist/builtin/extensions/cron/index.js +55 -7
  4. package/dist/builtin/extensions/document-attachments/index.js +1 -1
  5. package/dist/builtin/extensions/herdr-agent-state/index.js +1 -1
  6. package/dist/builtin/extensions/im-forward/README.md +3 -1
  7. package/dist/builtin/extensions/im-forward/index.js +98 -41
  8. package/dist/builtin/extensions/init/index.js +1 -1
  9. package/dist/builtin/extensions/mcp-adapter/index.js +2 -2
  10. package/dist/builtin/extensions/memory/index.js +9 -11
  11. package/dist/builtin/extensions/pie-ipc/index.js +306 -353
  12. package/dist/builtin/extensions/pie-proc/index.js +18 -12
  13. package/dist/builtin/extensions/plan-mode/index.js +6 -6
  14. package/dist/builtin/extensions/subagent/index.js +9 -11
  15. package/dist/builtin/extensions/todo/index.js +6 -6
  16. package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +24 -1
  17. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +86 -21
  18. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +6 -1
  19. package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
  20. package/dist/builtin/skills/chrome-devtools-axi/{cli-CHC7XYFU.js → cli-NLPMVDGG.js} +32 -4
  21. package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +220 -22
  22. package/dist/chunks/{auth-storage-RABPRJ6T.js → auth-storage-C3FZMT7J.js} +3 -3
  23. package/dist/chunks/{chunk-R7VO46EK.js → chunk-3W3SXVPB.js} +5 -4
  24. package/dist/chunks/{chunk-IPLMGAML.js → chunk-5KI4Y4LA.js} +1 -1
  25. package/dist/chunks/{chunk-YNTIOWCD.js → chunk-BLDI2GRF.js} +5 -5
  26. package/dist/chunks/{chunk-UCKOXAME.js → chunk-CBDQJMUI.js} +9 -44
  27. package/dist/chunks/chunk-CGSFBWOM.js +100 -0
  28. package/dist/chunks/{chunk-AKXEZH7K.js → chunk-JMKLTTZQ.js} +89 -107
  29. package/dist/chunks/{chunk-7LTQLJJF.js → chunk-LAJXWOKS.js} +15 -10
  30. package/dist/chunks/{chunk-RZGYXAJU.js → chunk-LZQXQOPJ.js} +1 -12
  31. package/dist/chunks/{chunk-EQOI6RZV.js → chunk-NHV2CALB.js} +3 -5
  32. package/dist/chunks/{chunk-OV7SLSHR.js → chunk-SW2E33UL.js} +2 -4
  33. package/dist/chunks/{chunk-BPSCGGVF.js → chunk-XXGYUYXI.js} +1 -1
  34. package/dist/chunks/{chunk-XO3NM7BB.js → chunk-Y3I2UV5Y.js} +3 -3
  35. package/dist/chunks/{chunk-IZDNZW3S.js → chunk-Z2FKA2ZH.js} +8 -8
  36. package/dist/chunks/chunk-ZPJ3BNQB.js +126 -0
  37. package/dist/chunks/{config-HF2PDLN5.js → config-4EOI5NOU.js} +2 -4
  38. package/dist/chunks/{manager-cli-BYCF4RKN.js → manager-cli-WEHNUV5T.js} +3 -5
  39. package/dist/chunks/{model-registry-7FNIUYPF.js → model-registry-3XAHXXTA.js} +5 -5
  40. package/dist/chunks/{src-OVWRBWKU.js → src-B44QWSGM.js} +4 -4
  41. package/dist/chunks/{src-A5YI46OD.js → src-CLE5ILN4.js} +6 -6
  42. package/dist/chunks/{src-OA3TP6DS.js → src-EGXFJ3WA.js} +5 -5
  43. package/dist/chunks/{src-TF2RAGRU.js → src-Q7LU27C2.js} +3 -3
  44. package/dist/chunks/{test-stream-7YZDGBPO.js → test-stream-OR3EJBNF.js} +3 -3
  45. package/dist/cli.js +128 -132
  46. package/package.json +3 -3
  47. package/dist/chunks/chunk-7KLWHWZD.js +0 -164
@@ -1,4 +1,9 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ claimOwnership,
4
+ pidDefinitelyDead,
5
+ readOwnership
6
+ } from "./chunk-ZPJ3BNQB.js";
2
7
 
3
8
  // builtin/extensions/im-forward/helpers.ts
4
9
  import * as nodeCrypto from "node:crypto";
@@ -561,7 +566,6 @@ var MAX_STATUS_FILE_BYTES = 128 * 1024;
561
566
  var MAX_DISPLAY_NAME_CHARS = 64;
562
567
  var MAX_STATUS_TEXT_FIELD_CHARS = 4096;
563
568
  var MAX_BODY_CHARS = 8e3;
564
- var MAX_STATUS_BODY_CHARS = 2e3;
565
569
  var STATUS_FILE_STALE_MS = 12e4;
566
570
  var HEARTBEAT_INTERVAL_MS = 2e4;
567
571
  var DEFAULT_SEND_WAIT_MS = 12e4;
@@ -589,9 +593,6 @@ function peerLabel(instanceId, displayName) {
589
593
  return instanceId.length > 12 ? instanceId.slice(0, 12) : instanceId;
590
594
  }
591
595
  var ENVELOPE_KINDS = /* @__PURE__ */ new Set([
592
- "hello",
593
- "bye",
594
- "ping",
595
596
  "message",
596
597
  "ack",
597
598
  "result",
@@ -773,6 +774,9 @@ function parseStatusFile(raw) {
773
774
  updatedAt: record.updatedAt,
774
775
  state: record.state
775
776
  };
777
+ if (typeof record.unattended === "boolean") file.unattended = record.unattended;
778
+ if (typeof record.isManager === "boolean") file.isManager = record.isManager;
779
+ if (typeof record.imBinding === "string" && record.imBinding.length <= 512 && !hasControlChars(record.imBinding)) file.imBinding = record.imBinding;
776
780
  if (Array.isArray(record.allowPeers) && record.allowPeers.length <= 1e3 && record.allowPeers.every((id) => typeof id === "string" && (id === "*" || isValidInstanceId(id)))) file.allowPeers = record.allowPeers;
777
781
  if (typeof record.secret === "string" && /^[a-f0-9]{64}$/.test(record.secret)) file.secret = record.secret;
778
782
  if (typeof record.sessionName === "string" && !hasControlChars(record.sessionName) && record.sessionName.length <= MAX_DISPLAY_NAME_CHARS) file.sessionName = record.sessionName;
@@ -780,8 +784,6 @@ function parseStatusFile(raw) {
780
784
  if (typeof record.blockedSince === "number" && Number.isSafeInteger(record.blockedSince) && record.blockedSince >= 0) file.blockedSince = record.blockedSince;
781
785
  if (typeof record.turnStartedAt === "number" && Number.isSafeInteger(record.turnStartedAt) && record.turnStartedAt >= 0) file.turnStartedAt = record.turnStartedAt;
782
786
  if (typeof record.undeliveredInjections === "number" && Number.isFinite(record.undeliveredInjections)) file.undeliveredInjections = Math.min(100, Math.max(0, Math.floor(record.undeliveredInjections)));
783
- if (typeof record.lastBodyText === "string" && record.lastBodyText.length <= MAX_STATUS_TEXT_FIELD_CHARS && !/[\u0000-\u0008\u000b-\u001f\u007f]/.test(record.lastBodyText)) file.lastBodyText = record.lastBodyText;
784
- if (typeof record.lastBodyAt === "number" && Number.isSafeInteger(record.lastBodyAt) && record.lastBodyAt >= 0) file.lastBodyAt = record.lastBodyAt;
785
787
  if (typeof record.port === "number" && Number.isInteger(record.port) && record.port > 0 && record.port <= 65535) file.port = record.port;
786
788
  return file;
787
789
  }
@@ -1138,7 +1140,6 @@ var IpcTransport = class {
1138
1140
  };
1139
1141
 
1140
1142
  // builtin/extensions/im-forward/event-hub.ts
1141
- import * as fs3 from "node:fs";
1142
1143
  import * as path3 from "node:path";
1143
1144
 
1144
1145
  // builtin/extensions/im-forward/address-book.ts
@@ -1229,8 +1230,10 @@ function resolveAddress(text, ownLiveName, book) {
1229
1230
  return { kind: "none" };
1230
1231
  }
1231
1232
  const body = text.trimStart().slice(name.length + 1).trim();
1233
+ if (!resolvedBook.complete) return { kind: "ambiguous", name, reason: "address book unreadable" };
1232
1234
  const foreignOwners = resolvedBook.names.get(name);
1233
1235
  if (foreignOwners && foreignOwners.size > 0) {
1236
+ if (foreignOwners.size > 1) return { kind: "ambiguous", name, reason: "duplicate live session name" };
1234
1237
  if (resolvedBook.selfPublished === name || live === name) return { kind: "ambiguous", name, reason: "duplicate live session name" };
1235
1238
  return { kind: "other", name };
1236
1239
  }
@@ -1244,6 +1247,36 @@ function resolveAddress(text, ownLiveName, book) {
1244
1247
  // builtin/extensions/im-forward/event-hub.ts
1245
1248
  var DISPATCH_PREFIX = "[im-forward-dispatch]";
1246
1249
  var dispatchReceiver;
1250
+ var imBinding;
1251
+ var bindingListeners = /* @__PURE__ */ new Set();
1252
+ function bindingChanged() {
1253
+ for (const fn of bindingListeners) {
1254
+ try {
1255
+ fn();
1256
+ } catch {
1257
+ }
1258
+ }
1259
+ }
1260
+ function onImBindingChanged(fn) {
1261
+ bindingListeners.add(fn);
1262
+ return () => {
1263
+ bindingListeners.delete(fn);
1264
+ };
1265
+ }
1266
+ function registerImBinding(value) {
1267
+ const token = Symbol(value);
1268
+ imBinding = { value, token };
1269
+ bindingChanged();
1270
+ return () => {
1271
+ if (imBinding?.token === token) {
1272
+ imBinding = void 0;
1273
+ bindingChanged();
1274
+ }
1275
+ };
1276
+ }
1277
+ function currentImBinding() {
1278
+ return imBinding?.value;
1279
+ }
1247
1280
  var turnImDriverOracle;
1248
1281
  function registerTurnImDriver(oracle) {
1249
1282
  turnImDriverOracle = oracle;
@@ -1266,7 +1299,6 @@ function takeDispatchFrame(text) {
1266
1299
  return true;
1267
1300
  }
1268
1301
  }
1269
- var LOCK_STALE_MS = 2e4;
1270
1302
  function hubDir() {
1271
1303
  return path3.join(addressBookRoot(), "im-forward");
1272
1304
  }
@@ -1274,116 +1306,64 @@ function lockPath(binding) {
1274
1306
  const safe = binding.replace(/[^a-zA-Z0-9._-]/g, "_");
1275
1307
  return path3.join(hubDir(), `consumer-${safe}.lock`);
1276
1308
  }
1277
- function pidAlive2(pid) {
1278
- if (!Number.isInteger(pid) || pid <= 0) return false;
1279
- try {
1280
- process.kill(pid, 0);
1281
- return true;
1282
- } catch (error) {
1283
- return error.code === "EPERM";
1284
- }
1285
- }
1286
1309
  function readLock(binding) {
1287
- try {
1288
- const parsed = JSON.parse(fs3.readFileSync(lockPath(binding), "utf8"));
1289
- if (typeof parsed.pid === "number" && typeof parsed.holder === "string" && typeof parsed.heartbeatAt === "number" && typeof parsed.binding === "string") {
1290
- return {
1291
- pid: parsed.pid,
1292
- holder: parsed.holder,
1293
- heartbeatAt: parsed.heartbeatAt,
1294
- binding: parsed.binding
1295
- };
1296
- }
1297
- return void 0;
1298
- } catch {
1299
- return void 0;
1300
- }
1310
+ return readOwnership(lockPath(binding), (v) => v.binding === binding);
1301
1311
  }
1302
- function lockAlive(info, now = Date.now()) {
1303
- if (!info) return false;
1304
- return pidAlive2(info.pid) && now - info.heartbeatAt < LOCK_STALE_MS;
1312
+ function lockAlive(info, _now = Date.now()) {
1313
+ return !!info && !pidDefinitelyDead(info.pid);
1305
1314
  }
1306
1315
  function tryClaimConsumer(binding, holder, onLost, shouldYield) {
1307
- const target = lockPath(binding);
1308
- const mine = JSON.stringify({ pid: process.pid, holder, heartbeatAt: Date.now(), binding });
1309
- const takeOver = () => {
1310
- const tmp = `${target}.${process.pid}.${Date.now()}.tmp`;
1311
- try {
1312
- fs3.mkdirSync(hubDir(), { recursive: true, mode: 448 });
1313
- fs3.writeFileSync(tmp, `${mine}
1314
- `);
1315
- try {
1316
- fs3.linkSync(tmp, target);
1317
- fs3.rmSync(tmp, { force: true });
1318
- return true;
1319
- } catch (error) {
1320
- fs3.rmSync(tmp, { force: true });
1321
- if (error.code !== "EEXIST") throw error;
1322
- return false;
1323
- }
1324
- } catch {
1325
- return false;
1326
- }
1327
- };
1328
- const existing = readLock(binding);
1329
- if (existing && lockAlive(existing)) return void 0;
1330
- if (existing) {
1331
- try {
1332
- fs3.rmSync(target, { force: true });
1333
- } catch {
1334
- }
1335
- }
1336
- if (!takeOver()) return void 0;
1337
- let released = false;
1338
- const heartbeatTimer = setInterval(() => {
1339
- if (released) return;
1340
- try {
1341
- const current = readLock(binding);
1342
- if (current && current.pid !== process.pid) {
1343
- released = true;
1344
- clearInterval(heartbeatTimer);
1345
- onLost?.();
1346
- return;
1347
- }
1348
- if (shouldYield?.() === true) {
1349
- released = true;
1350
- clearInterval(heartbeatTimer);
1351
- try {
1352
- if (readLock(binding)?.pid === process.pid) fs3.rmSync(target, { force: true });
1353
- } catch {
1354
- }
1355
- onLost?.();
1356
- return;
1357
- }
1358
- fs3.writeFileSync(target, `${JSON.stringify({ pid: process.pid, holder, heartbeatAt: Date.now(), binding })}
1359
- `);
1360
- } catch {
1361
- }
1362
- }, 5e3);
1363
- heartbeatTimer.unref();
1364
- return {
1365
- heartbeat: () => {
1316
+ try {
1317
+ const result = claimOwnership(
1318
+ lockPath(binding),
1319
+ { pid: process.pid, holder, heartbeatAt: Date.now(), binding },
1320
+ (v) => v.binding === binding
1321
+ );
1322
+ if ("holder" in result) return void 0;
1323
+ let stopped = false;
1324
+ let retiring = false;
1325
+ const release = () => {
1326
+ if (retiring) return;
1327
+ stopped = true;
1328
+ clearInterval(timer);
1366
1329
  try {
1367
- fs3.writeFileSync(target, `${JSON.stringify({ pid: process.pid, holder, heartbeatAt: Date.now(), binding })}
1368
- `);
1330
+ result.handle.release();
1369
1331
  } catch {
1370
1332
  }
1371
- },
1372
- release: () => {
1373
- if (released) return;
1374
- released = true;
1375
- clearInterval(heartbeatTimer);
1333
+ };
1334
+ const retire = () => {
1335
+ stopped = true;
1336
+ retiring = true;
1337
+ clearInterval(timer);
1338
+ if (!onLost) return;
1339
+ void Promise.resolve().then(onLost).then(() => {
1340
+ retiring = false;
1341
+ release();
1342
+ }).catch(() => {
1343
+ });
1344
+ };
1345
+ const heartbeat = () => {
1346
+ if (stopped) return;
1376
1347
  try {
1377
- const current = readLock(binding);
1378
- if (current && current.pid === process.pid) fs3.rmSync(target, { force: true });
1348
+ if (shouldYield?.() === true || !result.handle.heartbeat()) retire();
1379
1349
  } catch {
1350
+ retire();
1380
1351
  }
1381
- }
1382
- };
1352
+ };
1353
+ const timer = setInterval(heartbeat, 5e3);
1354
+ timer.unref();
1355
+ return { heartbeat, release };
1356
+ } catch {
1357
+ return void 0;
1358
+ }
1383
1359
  }
1384
1360
  function currentConsumer(binding) {
1385
- const info = readLock(binding);
1386
- return { info, alive: lockAlive(info) };
1361
+ try {
1362
+ const info = readLock(binding);
1363
+ return { info, alive: lockAlive(info) };
1364
+ } catch {
1365
+ return { info: void 0, alive: true };
1366
+ }
1387
1367
  }
1388
1368
 
1389
1369
  export {
@@ -1414,7 +1394,6 @@ export {
1414
1394
  IPC_PROTOCOL_VERSION,
1415
1395
  MAX_STATUS_FILE_BYTES,
1416
1396
  MAX_BODY_CHARS,
1417
- MAX_STATUS_BODY_CHARS,
1418
1397
  HEARTBEAT_INTERVAL_MS,
1419
1398
  DEFAULT_SEND_WAIT_MS,
1420
1399
  MAX_INBOX_MESSAGES,
@@ -1433,6 +1412,9 @@ export {
1433
1412
  signEnvelope,
1434
1413
  IpcTransport,
1435
1414
  DISPATCH_PREFIX,
1415
+ onImBindingChanged,
1416
+ registerImBinding,
1417
+ currentImBinding,
1436
1418
  registerTurnImDriver,
1437
1419
  isTurnUserImDriven,
1438
1420
  registerDispatchReceiver,
@@ -1,9 +1,8 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  getBuiltinDir,
4
- getConfigDir,
5
- init_config
6
- } from "./chunk-UCKOXAME.js";
4
+ getConfigDir
5
+ } from "./chunk-CBDQJMUI.js";
7
6
  import {
8
7
  classifyShellCommand,
9
8
  createSharedWebFetchTool,
@@ -11,18 +10,18 @@ import {
11
10
  createSharedWebSearchTool,
12
11
  defaultShellKindForPlatform,
13
12
  interpretShellExit
14
- } from "./chunk-YNTIOWCD.js";
13
+ } from "./chunk-BLDI2GRF.js";
15
14
  import {
16
15
  requestInteraction
17
- } from "./chunk-XO3NM7BB.js";
16
+ } from "./chunk-Y3I2UV5Y.js";
18
17
  import {
19
18
  EMPTY_ASSISTANT_CONTENT_ERROR,
20
19
  OPENAI_COMPAT_PROTOCOL_ERROR_CODE,
21
20
  getLogger
22
- } from "./chunk-R7VO46EK.js";
21
+ } from "./chunk-3W3SXVPB.js";
23
22
  import {
24
23
  Type
25
- } from "./chunk-BPSCGGVF.js";
24
+ } from "./chunk-XXGYUYXI.js";
26
25
 
27
26
  // src/runtime/retry-policy.ts
28
27
  var TRANSIENT_NETWORK_ERROR_PATTERN = /sse stream aborted|sse stream closed before end|sse stream ended before response completed|responses stream ended without a terminal event|(?:read\s+)?ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|ECONNREFUSED|(?:read\s+|write\s+)?EPIPE|socket hang up|request timeout|websocket upgrade refused|websocket handshake|websocket connection failed|websocket transport failed|connection closed before opening|client network socket disconnected before secure TLS connection was established|connection.?error|connection.?refused|other side closed|fetch failed|upstream.?connect|reset before headers|terminated/i;
@@ -1412,7 +1411,6 @@ ${commandNonzeroHint}`;
1412
1411
  }
1413
1412
 
1414
1413
  // src/capabilities/rendered-page-reader.ts
1415
- init_config();
1416
1414
  import { spawn as spawn2 } from "node:child_process";
1417
1415
  import { createRequire } from "node:module";
1418
1416
  import * as fs from "node:fs";
@@ -1426,7 +1424,9 @@ function resolveAxiCli() {
1426
1424
  }
1427
1425
  function resolveMcpScript() {
1428
1426
  const packageJson = require2.resolve("chrome-devtools-mcp/package.json");
1429
- return path.join(path.dirname(packageJson), "build", "src", "bin", "chrome-devtools-mcp.js");
1427
+ const pkg = JSON.parse(fs.readFileSync(packageJson, "utf8"));
1428
+ const rel = pkg.bin?.["chrome-devtools-mcp"] ?? "build/src/bin/chrome-devtools-mcp.js";
1429
+ return path.join(path.dirname(packageJson), rel);
1430
1430
  }
1431
1431
  function runAxi(args, options = {}) {
1432
1432
  const timeoutMs = options.timeoutMs ?? 6e4;
@@ -1529,6 +1529,12 @@ function createCliRenderedPageReader() {
1529
1529
  const session = `pie-web-research-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
1530
1530
  const env = { ...process.env, CHROME_DEVTOOLS_AXI_SESSION: session };
1531
1531
  delete env.CHROME_DEVTOOLS_AXI_PORT;
1532
+ env.CHROME_DEVTOOLS_AXI_FRESH = "1";
1533
+ delete env.CHROME_DEVTOOLS_AXI_AUTO_CONNECT;
1534
+ delete env.CHROME_DEVTOOLS_AXI_BROWSER_URL;
1535
+ delete env.CHROME_DEVTOOLS_AXI_USER_DATA_DIR;
1536
+ delete env.CHROME_DEVTOOLS_AXI_WS_HEADERS;
1537
+ delete env.CHROME_DEVTOOLS_AXI_MCP_SERVER_URL;
1532
1538
  if (!env.CHROME_DEVTOOLS_AXI_MCP_PATH?.trim()) env.CHROME_DEVTOOLS_AXI_MCP_PATH = resolveMcpScript();
1533
1539
  if (!env.CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS) env.CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS = "1";
1534
1540
  cleanStaleScreenshotDirs();
@@ -1617,7 +1623,6 @@ function createCliWebResearchHealthStore(configDir) {
1617
1623
  }
1618
1624
 
1619
1625
  // src/capabilities/index.ts
1620
- init_config();
1621
1626
  function createCliHostCapabilities(cwd, options = {}) {
1622
1627
  const bashTool = createBashTool(cwd, options.getBashEnv ? { getEnv: options.getBashEnv } : void 0);
1623
1628
  const healthStore = createCliWebResearchHealthStore(options.configDir ?? getConfigDir());
@@ -11,14 +11,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  if (typeof require !== "undefined") return require.apply(this, arguments);
12
12
  throw Error('Dynamic require of "' + x + '" is not supported');
13
13
  });
14
- var __esm = (fn, res, err) => function __init() {
15
- if (err) throw err[0];
16
- try {
17
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
18
- } catch (e) {
19
- throw err = [e], e;
20
- }
21
- };
22
14
  var __commonJS = (cb, mod) => function __require2() {
23
15
  try {
24
16
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
@@ -46,13 +38,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
46
38
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
47
39
  mod
48
40
  ));
49
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
50
41
 
51
42
  export {
52
43
  __require,
53
- __esm,
54
44
  __commonJS,
55
45
  __export,
56
- __toESM,
57
- __toCommonJS
46
+ __toESM
58
47
  };
@@ -1,17 +1,15 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
- getConfigDir,
4
- init_config
5
- } from "./chunk-UCKOXAME.js";
3
+ getConfigDir
4
+ } from "./chunk-CBDQJMUI.js";
6
5
  import {
7
6
  MODEL_CLASS_FALLBACK_ORDER,
8
7
  modelSupportsToolPurpose,
9
8
  requiredCapabilityForToolPurpose,
10
9
  sortToolModelCandidatesByCapability
11
- } from "./chunk-R7VO46EK.js";
10
+ } from "./chunk-3W3SXVPB.js";
12
11
 
13
12
  // src/core/model-registry.ts
14
- init_config();
15
13
  import * as fs from "fs";
16
14
  import * as path from "path";
17
15
  import { createHash, createHmac, randomBytes } from "node:crypto";
@@ -1,11 +1,9 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
- getConfigDir,
4
- init_config
5
- } from "./chunk-UCKOXAME.js";
3
+ getConfigDir
4
+ } from "./chunk-CBDQJMUI.js";
6
5
 
7
6
  // src/core/auth-storage.ts
8
- init_config();
9
7
  import * as fs from "fs";
10
8
  import * as path from "path";
11
9
  var AUTH_LOCK_WRITE_GRACE_MS = 1e3;
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  __export
4
- } from "./chunk-RZGYXAJU.js";
4
+ } from "./chunk-LZQXQOPJ.js";
5
5
 
6
6
  // ../../node_modules/@sinclair/typebox/build/esm/value/guard/guard.mjs
7
7
  function IsAsyncIterator(value) {
@@ -2,17 +2,17 @@ import { createRequire as __createRequire } from "node:module"; const require =
2
2
  import {
3
3
  createAgentOperationError,
4
4
  getAgentFailureMetadata
5
- } from "./chunk-IPLMGAML.js";
5
+ } from "./chunk-5KI4Y4LA.js";
6
6
  import {
7
7
  FileSystemGateway,
8
8
  detectPlatform,
9
9
  getFileSystemGateway,
10
10
  getPlatformConfig,
11
11
  streamSimple
12
- } from "./chunk-R7VO46EK.js";
12
+ } from "./chunk-3W3SXVPB.js";
13
13
  import {
14
14
  Type
15
- } from "./chunk-BPSCGGVF.js";
15
+ } from "./chunk-XXGYUYXI.js";
16
16
 
17
17
  // ../../packages/agent-framework/src/skills/parser.ts
18
18
  function parseFrontmatter(yaml) {
@@ -147,7 +147,7 @@ function pathContains(parent, child) {
147
147
  }
148
148
  async function readExcludeCwds() {
149
149
  try {
150
- const { getSettingsPath } = await import("./config-HF2PDLN5.js");
150
+ const { getSettingsPath } = await import("./config-4EOI5NOU.js");
151
151
  const raw = JSON.parse(fs.readFileSync(getSettingsPath(), "utf8"));
152
152
  const list = raw?.extensions?.memory?.excludeCwds;
153
153
  if (!Array.isArray(list)) return [];
@@ -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-7FNIUYPF.js");
175
- const { AuthStorage } = await import("./auth-storage-RABPRJ6T.js");
176
- const { getSessionsDir } = await import("./config-HF2PDLN5.js");
177
- const { FileSessionStore } = await import("./src-OA3TP6DS.js");
178
- const { MemoryStore, runDistillation } = await import("./src-A5YI46OD.js");
174
+ const { ModelRegistry } = await import("./model-registry-3XAHXXTA.js");
175
+ const { AuthStorage } = await import("./auth-storage-C3FZMT7J.js");
176
+ const { getSessionsDir } = await import("./config-4EOI5NOU.js");
177
+ const { FileSessionStore } = await import("./src-EGXFJ3WA.js");
178
+ const { MemoryStore, runDistillation } = await import("./src-CLE5ILN4.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-TF2RAGRU.js");
193
+ const { completeSimple } = await import("./src-Q7LU27C2.js");
194
194
  const message = await withModelTimeout(
195
195
  completeSimple(
196
196
  resolved.model,
@@ -255,7 +255,7 @@ async function runDistillAuto(memoryRoot, days = 7, runner) {
255
255
  } catch {
256
256
  }
257
257
  };
258
- const { MemoryStore, todayKey } = await import("./src-A5YI46OD.js");
258
+ const { MemoryStore, todayKey } = await import("./src-CLE5ILN4.js");
259
259
  const store = new MemoryStore(memoryRoot);
260
260
  const today = todayKey(Date.now());
261
261
  const dates = [];
@@ -0,0 +1,126 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+
3
+ // src/core/node-ownership-lock.ts
4
+ import * as fs from "node:fs";
5
+ import * as path from "node:path";
6
+ import { randomUUID } from "node:crypto";
7
+ function pidDefinitelyDead(pid) {
8
+ if (!Number.isInteger(pid) || pid <= 0) return false;
9
+ try {
10
+ process.kill(pid, 0);
11
+ return false;
12
+ } catch (error) {
13
+ return error.code === "ESRCH";
14
+ }
15
+ }
16
+ function withOwnershipMutex(lock, fn) {
17
+ fs.mkdirSync(path.dirname(lock), { recursive: true, mode: 448 });
18
+ const token = randomUUID();
19
+ const candidate = `${lock}.acquire.${token}`;
20
+ fs.mkdirSync(candidate, { mode: 448 });
21
+ try {
22
+ fs.writeFileSync(path.join(candidate, `held.${token}`), JSON.stringify({ version: 1, pid: process.pid }), { flag: "wx", mode: 384 });
23
+ const deadline = process.hrtime.bigint() + 2000000000n;
24
+ for (; ; ) {
25
+ try {
26
+ fs.renameSync(candidate, lock);
27
+ break;
28
+ } catch (error) {
29
+ if (!["EEXIST", "ENOTEMPTY", "EPERM", "ENOTDIR"].includes(error.code ?? "")) throw error;
30
+ if (process.hrtime.bigint() >= deadline) throw new Error(`Ownership mutex contention: ${lock}`);
31
+ try {
32
+ const entries = fs.readdirSync(lock);
33
+ if (entries.every((name) => {
34
+ if (!/^held\.[a-f0-9-]+$/.test(name)) return false;
35
+ const value = JSON.parse(fs.readFileSync(path.join(lock, name), "utf8"));
36
+ return value?.version === 1 && pidDefinitelyDead(value.pid);
37
+ })) {
38
+ for (const name of entries) {
39
+ try {
40
+ fs.unlinkSync(path.join(lock, name));
41
+ } catch (e) {
42
+ if (e.code !== "ENOENT") throw e;
43
+ }
44
+ }
45
+ fs.rmdirSync(lock);
46
+ }
47
+ } catch {
48
+ }
49
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 3);
50
+ }
51
+ }
52
+ try {
53
+ return fn();
54
+ } finally {
55
+ try {
56
+ fs.unlinkSync(path.join(lock, `held.${token}`));
57
+ } catch {
58
+ }
59
+ try {
60
+ fs.rmdirSync(lock);
61
+ } catch {
62
+ }
63
+ }
64
+ } finally {
65
+ fs.rmSync(candidate, { recursive: true, force: true });
66
+ }
67
+ }
68
+ function readOwnership(target, valid) {
69
+ let raw;
70
+ try {
71
+ raw = fs.readFileSync(target, "utf8");
72
+ } catch (error) {
73
+ if (error.code === "ENOENT") return void 0;
74
+ throw error;
75
+ }
76
+ const value = JSON.parse(raw);
77
+ if (!value || !Number.isInteger(value.pid) || value.pid <= 0 || typeof value.holder !== "string" || !Number.isFinite(value.heartbeatAt) || value.generation !== void 0 && typeof value.generation !== "string" || !valid(value)) {
78
+ throw new Error(`Invalid ownership record: ${target}`);
79
+ }
80
+ return value;
81
+ }
82
+ function claimOwnership(target, mine, valid) {
83
+ const mutex = `${target}.mutex`;
84
+ const generation = randomUUID();
85
+ const publish = () => {
86
+ const tmp = `${target}.${randomUUID()}.tmp`;
87
+ try {
88
+ fs.writeFileSync(tmp, `${JSON.stringify({ ...mine, generation, heartbeatAt: Date.now() })}
89
+ `, { flag: "wx", mode: 384 });
90
+ fs.renameSync(tmp, target);
91
+ } finally {
92
+ fs.rmSync(tmp, { force: true });
93
+ }
94
+ };
95
+ const holder = withOwnershipMutex(mutex, () => {
96
+ const current = readOwnership(target, valid);
97
+ if (current && !pidDefinitelyDead(current.pid)) return current;
98
+ publish();
99
+ return void 0;
100
+ });
101
+ if (holder) return { holder };
102
+ let released = false;
103
+ return { handle: {
104
+ heartbeat: () => {
105
+ if (released) return false;
106
+ return withOwnershipMutex(mutex, () => {
107
+ if (readOwnership(target, valid)?.generation !== generation) return false;
108
+ publish();
109
+ return true;
110
+ });
111
+ },
112
+ release: () => {
113
+ if (released) return;
114
+ released = true;
115
+ withOwnershipMutex(mutex, () => {
116
+ if (readOwnership(target, valid)?.generation === generation) fs.unlinkSync(target);
117
+ });
118
+ }
119
+ } };
120
+ }
121
+
122
+ export {
123
+ pidDefinitelyDead,
124
+ readOwnership,
125
+ claimOwnership
126
+ };
@@ -18,13 +18,11 @@ import {
18
18
  getSessionsDir,
19
19
  getSettingsPath,
20
20
  getThemesDir,
21
- init_config,
22
21
  isBunRuntime,
23
22
  migrateConfigFromAgentDir,
24
23
  resolveSessionsDirOverride
25
- } from "./chunk-UCKOXAME.js";
26
- import "./chunk-RZGYXAJU.js";
27
- init_config();
24
+ } from "./chunk-CBDQJMUI.js";
25
+ import "./chunk-LZQXQOPJ.js";
28
26
  export {
29
27
  APP_NAME,
30
28
  CONFIG_DIR_NAME,
@@ -3,10 +3,9 @@ import {
3
3
  readProcessCommandLine
4
4
  } from "./chunk-X6LBWHK3.js";
5
5
  import {
6
- getConfigDir,
7
- init_config
8
- } from "./chunk-UCKOXAME.js";
9
- import "./chunk-RZGYXAJU.js";
6
+ getConfigDir
7
+ } from "./chunk-CBDQJMUI.js";
8
+ import "./chunk-LZQXQOPJ.js";
10
9
 
11
10
  // src/commands/manager-cli.ts
12
11
  import { spawn, execFileSync } from "node:child_process";
@@ -14,7 +13,6 @@ import { createRequire } from "node:module";
14
13
  import * as fs from "node:fs";
15
14
  import * as os from "node:os";
16
15
  import * as path from "node:path";
17
- init_config();
18
16
  var require_ = createRequire(import.meta.url);
19
17
  var CRON_SECTION_MARKER = "## \u5B9A\u65F6\u4EFB\u52A1";
20
18
  var CRON_SECTION = `