@tekmidian/pai 0.66.6 → 0.66.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 (118) hide show
  1. package/dist/{aibroker-client-WCZi_tn-.mjs → aibroker-client-BevXY1Zz.mjs} +3 -3
  2. package/dist/{aibroker-client-WCZi_tn-.mjs.map → aibroker-client-BevXY1Zz.mjs.map} +1 -1
  3. package/dist/{aibroker-client-Ck3p3k_-.mjs → aibroker-client-CxTpL_u7.mjs} +1 -1
  4. package/dist/{auto-route-BnizyALK.mjs → auto-route-BVeAp0fl.mjs} +1 -1
  5. package/dist/{auto-route-BnizyALK.mjs.map → auto-route-BVeAp0fl.mjs.map} +1 -1
  6. package/dist/{auto-route-D6fW1Q8z.mjs → auto-route-CboBqsN3.mjs} +1 -1
  7. package/dist/{chain-2_uoiEdD.mjs → chain-8hFKr23C.mjs} +3 -3
  8. package/dist/{chain-2_uoiEdD.mjs.map → chain-8hFKr23C.mjs.map} +1 -1
  9. package/dist/cli/index.mjs +16 -15
  10. package/dist/cli/index.mjs.map +1 -1
  11. package/dist/cli/program.mjs +15 -14
  12. package/dist/{config-CnsDMETf.mjs → config-UWtzLpXi.mjs} +1 -1
  13. package/dist/{config-Ddc4DIPk.mjs → config-sfaArCsl.mjs} +12 -3
  14. package/dist/config-sfaArCsl.mjs.map +1 -0
  15. package/dist/{context-handover-cache-SFkWucuT.mjs → context-handover-cache-Bb-H_mTa.mjs} +7 -8
  16. package/dist/{context-handover-cache-SFkWucuT.mjs.map → context-handover-cache-Bb-H_mTa.mjs.map} +1 -1
  17. package/dist/daemon/index.mjs +14 -13
  18. package/dist/daemon/index.mjs.map +1 -1
  19. package/dist/daemon-BXTn2EgV.mjs +19 -0
  20. package/dist/{daemon-vLtT3yaI.mjs → daemon-CkbX-hV7.mjs} +757 -20
  21. package/dist/daemon-CkbX-hV7.mjs.map +1 -0
  22. package/dist/daemon-mcp/index.mjs +12 -11
  23. package/dist/daemon-mcp/index.mjs.map +1 -1
  24. package/dist/embedding-gate-BVrr0BgS.mjs +378 -0
  25. package/dist/embedding-gate-BVrr0BgS.mjs.map +1 -0
  26. package/dist/embedding-gate-Crj8awk7.mjs +5 -0
  27. package/dist/embeddings-BuA7v4lk.mjs +3 -0
  28. package/dist/{embeddings-DMVzpvRZ.mjs → embeddings-DFl88_y-.mjs} +16 -2
  29. package/dist/{embeddings-DMVzpvRZ.mjs.map → embeddings-DFl88_y-.mjs.map} +1 -1
  30. package/dist/{env-DiolswKQ.mjs → env-DqTjeKoA.mjs} +1 -1
  31. package/dist/{env-DiolswKQ.mjs.map → env-DqTjeKoA.mjs.map} +1 -1
  32. package/dist/factory-XrH66erA.mjs +9 -0
  33. package/dist/{factory-CXFHwvcv.mjs → factory-mNBitkL_.mjs} +28 -6
  34. package/dist/factory-mNBitkL_.mjs.map +1 -0
  35. package/dist/{fallback-DNzd3jJc.mjs → fallback-DdC1_s2d.mjs} +4 -4
  36. package/dist/{fallback-DNzd3jJc.mjs.map → fallback-DdC1_s2d.mjs.map} +1 -1
  37. package/dist/hooks/block-sleep-poll.mjs +7 -2
  38. package/dist/hooks/block-sleep-poll.mjs.map +3 -3
  39. package/dist/hooks/context-compression-hook.mjs +2 -0
  40. package/dist/hooks/context-compression-hook.mjs.map +2 -2
  41. package/dist/hooks/load-core-context.mjs +5 -5
  42. package/dist/hooks/load-core-context.mjs.map +2 -2
  43. package/dist/hooks/load-project-context.mjs +2 -0
  44. package/dist/hooks/load-project-context.mjs.map +2 -2
  45. package/dist/hooks/post-compact-inject.mjs +2 -0
  46. package/dist/hooks/post-compact-inject.mjs.map +2 -2
  47. package/dist/hooks/route-agents-to-worker.mjs +2 -0
  48. package/dist/hooks/route-agents-to-worker.mjs.map +2 -2
  49. package/dist/hooks/security-validator.mjs +2 -0
  50. package/dist/hooks/security-validator.mjs.map +2 -2
  51. package/dist/hooks/whisper-rules.mjs +2 -0
  52. package/dist/hooks/whisper-rules.mjs.map +2 -2
  53. package/dist/hooks/worker-guard.mjs +82 -5
  54. package/dist/hooks/worker-guard.mjs.map +4 -4
  55. package/dist/hooks/worker-proxy.mjs +2 -0
  56. package/dist/hooks/worker-proxy.mjs.map +2 -2
  57. package/dist/hooks/worker-status-line.mjs +7 -2
  58. package/dist/hooks/worker-status-line.mjs.map +3 -3
  59. package/dist/hooks/worker-supervision.mjs +2 -0
  60. package/dist/hooks/worker-supervision.mjs.map +2 -2
  61. package/dist/{ipc-client-DkxRay-o.mjs → ipc-client-BgSzY9QJ.mjs} +2 -2
  62. package/dist/{ipc-client-DkxRay-o.mjs.map → ipc-client-BgSzY9QJ.mjs.map} +1 -1
  63. package/dist/main-resolver-CobQGm2B.mjs +7 -0
  64. package/dist/{main-resolver-SfGGg1DB.mjs → main-resolver-DEXky_Km.mjs} +6 -6
  65. package/dist/{main-resolver-SfGGg1DB.mjs.map → main-resolver-DEXky_Km.mjs.map} +1 -1
  66. package/dist/{planner-C-gzg7ye.mjs → planner-DBoB5GtC.mjs} +10 -9
  67. package/dist/{planner-C-gzg7ye.mjs.map → planner-DBoB5GtC.mjs.map} +1 -1
  68. package/dist/{postgres-BxmyQHoA.mjs → postgres-D-96lgE1.mjs} +84 -3
  69. package/dist/postgres-D-96lgE1.mjs.map +1 -0
  70. package/dist/postgres-TedJP3yF.mjs +7 -0
  71. package/dist/{program-CfG1T_ko.mjs → program-BXns_5kO.mjs} +211 -63
  72. package/dist/program-BXns_5kO.mjs.map +1 -0
  73. package/dist/{query-feedback-BPdapXKd.mjs → query-feedback-VI7Cl-Lr.mjs} +2 -2
  74. package/dist/{query-feedback-BPdapXKd.mjs.map → query-feedback-VI7Cl-Lr.mjs.map} +1 -1
  75. package/dist/router-CKn9e0fo.mjs +3 -0
  76. package/dist/{router-BaTbc9VX.mjs → router-dfjlaOMI.mjs} +2 -2
  77. package/dist/{router-BaTbc9VX.mjs.map → router-dfjlaOMI.mjs.map} +1 -1
  78. package/dist/{run-ChlIbDJ0.mjs → run-DPwQkRwh.mjs} +107 -9
  79. package/dist/run-DPwQkRwh.mjs.map +1 -0
  80. package/dist/{run-env-CQRnxNht.mjs → run-env-CkAmx3lb.mjs} +3 -3
  81. package/dist/{run-env-CQRnxNht.mjs.map → run-env-CkAmx3lb.mjs.map} +1 -1
  82. package/dist/{pai-home-UncxWxlX.mjs → runtime-paths-BiEi_gaG.mjs} +50 -2
  83. package/dist/runtime-paths-BiEi_gaG.mjs.map +1 -0
  84. package/dist/{sources-CM2g-CLT.mjs → sources-BxXbzpAJ.mjs} +1 -1
  85. package/dist/{sources-CM2g-CLT.mjs.map → sources-BxXbzpAJ.mjs.map} +1 -1
  86. package/dist/{zettelkasten-G0-ZTybr.mjs → zettelkasten-CzcPzEsL.mjs} +5 -3
  87. package/dist/{zettelkasten-BRIaHzFm.mjs → zettelkasten-wh2Yy1nS.mjs} +5 -4
  88. package/dist/zettelkasten-wh2Yy1nS.mjs.map +1 -0
  89. package/docker/docker-compose.yml +4 -0
  90. package/docs/commands/README.md +6 -0
  91. package/docs/commands/memory.md +52 -0
  92. package/docs/commands/worker.md +22 -0
  93. package/docs/install-linux.md +1 -0
  94. package/docs/memory.md +69 -0
  95. package/package.json +1 -1
  96. package/src/hooks/ts/lib/sleep-poll-gate.test.ts +2 -2
  97. package/src/hooks/ts/lib/sleep-poll-gate.ts +4 -4
  98. package/src/hooks/ts/lib/worker-guard-longwait.test.ts +48 -0
  99. package/src/hooks/ts/lib/worker-guard.ts +50 -6
  100. package/src/hooks/ts/pre-tool-use/block-sleep-poll.test.ts +1 -1
  101. package/src/hooks/ts/session-start/load-core-context.ts +11 -8
  102. package/src/hooks/ts/session-start/session-start-worker-guard.test.ts +34 -2
  103. package/dist/config-Ddc4DIPk.mjs.map +0 -1
  104. package/dist/daemon-BHQoEjt0.mjs +0 -18
  105. package/dist/daemon-vLtT3yaI.mjs.map +0 -1
  106. package/dist/embeddings-D0WOQpYR.mjs +0 -3
  107. package/dist/factory-CXFHwvcv.mjs.map +0 -1
  108. package/dist/factory-CnKsU6zX.mjs +0 -8
  109. package/dist/main-resolver-DrHtx8iW.mjs +0 -7
  110. package/dist/pai-home-UncxWxlX.mjs.map +0 -1
  111. package/dist/postgres-B2BEBT-J.mjs +0 -5
  112. package/dist/postgres-BxmyQHoA.mjs.map +0 -1
  113. package/dist/program-CfG1T_ko.mjs.map +0 -1
  114. package/dist/router-BK-hFeQ6.mjs +0 -3
  115. package/dist/run-ChlIbDJ0.mjs.map +0 -1
  116. package/dist/runtime-paths-Bw3Jk8qJ.mjs +0 -52
  117. package/dist/runtime-paths-Bw3Jk8qJ.mjs.map +0 -1
  118. package/dist/zettelkasten-BRIaHzFm.mjs.map +0 -1
@@ -7490,6 +7490,7 @@ var DEFAULTS = {
7490
7490
  connectionTimeoutMs: 5e3
7491
7491
  },
7492
7492
  embeddingModel: "Snowflake/snowflake-arctic-embed-m-v1.5",
7493
+ embedding: { backend: "transformers-cpu-q8", ollama: { baseUrl: "http://127.0.0.1:11434" } },
7493
7494
  logLevel: "info",
7494
7495
  notifications: DEFAULT_NOTIFICATION_CONFIG,
7495
7496
  tasks: DEFAULT_TASK_CONFIG,
@@ -7497,6 +7498,7 @@ var DEFAULTS = {
7497
7498
  // guess here is an address that can be mailed without review.
7498
7499
  identity: { selfEmails: [] },
7499
7500
  sessions: { cacheKeepalive: { ...DEFAULT_SESSIONS_CACHE_KEEPALIVE } },
7501
+ dashboard: { enabled: true, port: 8770, bind: "127.0.0.1" },
7500
7502
  search: {
7501
7503
  mode: "keyword",
7502
7504
  rerank: true,
@@ -7519,7 +7521,48 @@ var CONFIG_DIR = dirname2(CONFIG_FILE);
7519
7521
  // src/workers/workers-config.ts
7520
7522
  var import_yaml3 = __toESM(require_dist(), 1);
7521
7523
 
7524
+ // src/workers/status.ts
7525
+ var SLEEP_FLOOR_SECS = 60;
7526
+ function sleepUnitMultiplier(unit) {
7527
+ return unit === "m" ? 60 : unit === "h" ? 3600 : unit === "d" ? 86400 : 1;
7528
+ }
7529
+ var SLEEP_SEGMENT_RE = /(?:^|[;&|\n(){]|\bdo\b|\bthen\b)\s*sleep\s+([0-9]+(?:\.[0-9]+)?)([smhd]?)(?=\s*(?:$|[;&|)\n]))/g;
7530
+ var LOOP_RE = /\b(for|while|until)\b([^;\n]*)[;\n]\s*do\b([\s\S]*?)\bdone\b/g;
7531
+ function sleepSum(text) {
7532
+ let sum = 0;
7533
+ for (const m of text.matchAll(SLEEP_SEGMENT_RE)) {
7534
+ const secs = Number(m[1]) * sleepUnitMultiplier(m[2]);
7535
+ if (Number.isFinite(secs)) sum += secs;
7536
+ }
7537
+ return sum;
7538
+ }
7539
+ function forIterations(header) {
7540
+ const words = header.replace(/^\s*\w+\s+in\s+/, "").trim();
7541
+ if (words === header.trim() || /[$`*?]/.test(words)) return null;
7542
+ const range = /^\{(-?\d+)\.\.(-?\d+)\}$/.exec(words);
7543
+ if (range) return Math.abs(Number(range[2]) - Number(range[1])) + 1;
7544
+ return words ? words.split(/\s+/).length : 0;
7545
+ }
7546
+ function totalSleepSecs(command) {
7547
+ let total = sleepSum(command);
7548
+ for (const m of command.matchAll(LOOP_RE)) {
7549
+ const body = sleepSum(m[3]);
7550
+ if (body === 0) continue;
7551
+ if (m[1] === "for") {
7552
+ const n = forIterations(m[2]);
7553
+ total += n === null ? Math.max(SLEEP_FLOOR_SECS, body) : body * (n - 1);
7554
+ } else if (!/\bkill\s+-0\b/.test(m[2])) {
7555
+ total += SLEEP_FLOOR_SECS;
7556
+ }
7557
+ }
7558
+ return total;
7559
+ }
7560
+
7561
+ // src/workers/wait-on.ts
7562
+ var WAIT_RECIPE = "`nohup sh -c 'CMD; echo $? > /tmp/job.rc' > /tmp/job.log 2>&1 & echo $! > /tmp/job.pid`, then repeat `pai worker wait-on $(cat /tmp/job.pid) --log /tmp/job.log` (each call returns within 2 min; do other work between calls) until it exits 0";
7563
+
7522
7564
  // src/hooks/ts/lib/sleep-poll-gate.ts
7565
+ var BACKGROUND_WORKER_REASON = "run_in_background is blocked in a worker: ending your turn ends this process and kills the job, there is no completion notification. Run a long job detached: " + WAIT_RECIPE + ".";
7523
7566
  function renderDecision(d) {
7524
7567
  if (d.decision === "allow") {
7525
7568
  return JSON.stringify({
@@ -7715,7 +7758,7 @@ function gitSub(args) {
7715
7758
  }
7716
7759
  var PATTERN_KILL = /* @__PURE__ */ new Set(["pkill", "killall"]);
7717
7760
  var PATTERN_KILL_REASON = "pattern-based process kill blocked: kill only what you started, by PID (`cmd & echo $! > /tmp/x.pid`, then `kill $(cat /tmp/x.pid)`), never by name or pattern; other workers' command lines contain your spec text";
7718
- function decideSegment(seg, st, ctx) {
7761
+ function decideSegment(seg, st, ctx, detached = false) {
7719
7762
  const words = stripPrefix(seg.words);
7720
7763
  const [cmd, ...args] = words;
7721
7764
  const boundary = ctx.worktreeRoot ?? ctx.cwd;
@@ -7726,7 +7769,7 @@ function decideSegment(seg, st, ctx) {
7726
7769
  }
7727
7770
  if (!cmd) return ALLOW;
7728
7771
  if ((cmd === "bash" || cmd === "sh" || cmd === "zsh") && args[0] === "-c" && args[1]) {
7729
- return decideCommand(args[1], { ...ctx, cwd: st.cwd });
7772
+ return decideCommand(args[1], { ...ctx, cwd: st.cwd }, detached);
7730
7773
  }
7731
7774
  const pos = args.filter((a) => !isFlag(a));
7732
7775
  if (PATTERN_KILL.has(cmd) || cmd === "xargs" && args.includes("kill") || cmd === "kill" && /pgrep|pidof/.test(args.join(" "))) {
@@ -7796,10 +7839,41 @@ function decideSegment(seg, st, ctx) {
7796
7839
  }
7797
7840
  return ALLOW;
7798
7841
  }
7799
- function decideCommand(command, ctx) {
7842
+ var MAX_FOREGROUND_SECS = 120;
7843
+ var WAIT_REASON_TAIL = "calls longer than 2 min block operator messages and supervision; long jobs run fine detached: " + WAIT_RECIPE + ".";
7844
+ var unitSecs = (u) => u === "m" ? 60 : u === "h" ? 3600 : u === "d" ? 86400 : 1;
7845
+ function longestTimeoutSecs(segs) {
7846
+ let longest = 0;
7847
+ for (const seg of segs) {
7848
+ const [cmd, ...args] = stripPrefix(seg.words);
7849
+ if (cmd !== "timeout" && cmd !== "gtimeout") continue;
7850
+ for (let i = 0; i < args.length; i++) {
7851
+ if (/^-[sk]$/.test(args[i])) i++;
7852
+ else if (!isFlag(args[i])) {
7853
+ const m = /^(\d+(?:\.\d+)?)([smhd]?)$/.exec(args[i]);
7854
+ if (m) longest = Math.max(longest, Number(m[1]) * unitSecs(m[2]));
7855
+ break;
7856
+ }
7857
+ }
7858
+ }
7859
+ return longest;
7860
+ }
7861
+ function longWaitReason(command, segs) {
7862
+ const fg = segs.filter((s2) => s2.words[0] !== "nohup");
7863
+ const t = longestTimeoutSecs(fg);
7864
+ if (t > MAX_FOREGROUND_SECS) return `timeout ${t}s blocked: ${WAIT_REASON_TAIL}`;
7865
+ const bare = command.replace(/'[^']*'|"[^"]*"/g, "''").replace(/\bnohup\b[^;&|\n]*/g, "");
7866
+ const s = totalSleepSecs(bare);
7867
+ if (s > MAX_FOREGROUND_SECS) return `sleep ${s}s blocked: ${WAIT_REASON_TAIL}`;
7868
+ return null;
7869
+ }
7870
+ function decideCommand(command, ctx, detached = false) {
7800
7871
  const st = { cwd: ctx.cwd, raw: command };
7801
- for (const seg of parseCommand(command)) {
7802
- const d = decideSegment(seg, st, ctx);
7872
+ const segs = parseCommand(command);
7873
+ const long = detached ? null : longWaitReason(command, segs);
7874
+ if (long) return deny(long);
7875
+ for (const seg of segs) {
7876
+ const d = decideSegment(seg, st, ctx, seg.words[0] === "nohup");
7803
7877
  if (d.decision === "deny") return d;
7804
7878
  }
7805
7879
  return ALLOW;
@@ -7812,6 +7886,9 @@ function decideWorkerGuard(input, env, ctx) {
7812
7886
  return deny(`${tool} blocked: this worker runs with --no-browser`);
7813
7887
  }
7814
7888
  if (tool === "Bash") {
7889
+ if (typeof ti.timeout === "number" && ti.timeout > MAX_FOREGROUND_SECS * 1e3) {
7890
+ return deny(`Bash timeout ${ti.timeout} ms blocked: ${WAIT_REASON_TAIL}`);
7891
+ }
7815
7892
  return typeof ti.command === "string" ? decideCommand(ti.command, ctx()) : ALLOW;
7816
7893
  }
7817
7894
  if (tool === "Edit" || tool === "Write" || tool === "MultiEdit" || tool === "NotebookEdit") {