@tekmidian/pai 0.54.1 → 0.55.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.
Files changed (251) hide show
  1. package/dist/{aibroker-client-CNfIBrl5.mjs → aibroker-client-B8Wtasez.mjs} +1 -1
  2. package/dist/{aibroker-client-DzkTpVjx.mjs → aibroker-client-BK1h--W_.mjs} +3 -3
  3. package/dist/{aibroker-client-DzkTpVjx.mjs.map → aibroker-client-BK1h--W_.mjs.map} +1 -1
  4. package/dist/{indexer-backend-CdvCJCkD.mjs → async-CLvuY7b-.mjs} +7 -7
  5. package/dist/async-CLvuY7b-.mjs.map +1 -0
  6. package/dist/auto-route-CF8WNaoy.mjs +100 -0
  7. package/dist/auto-route-CF8WNaoy.mjs.map +1 -0
  8. package/dist/{chain-CZKlI0hq.mjs → chain-DogidBji.mjs} +4 -4
  9. package/dist/{chain-CZKlI0hq.mjs.map → chain-DogidBji.mjs.map} +1 -1
  10. package/dist/cli/index.mjs +22 -23
  11. package/dist/cli/index.mjs.map +1 -1
  12. package/dist/cli/program.d.mts.map +1 -1
  13. package/dist/cli/program.mjs +22 -23
  14. package/dist/{clusters-Cw_P6lO-.mjs → clusters-Ci1mseh2.mjs} +4 -36
  15. package/dist/clusters-Ci1mseh2.mjs.map +1 -0
  16. package/dist/{config-B3EPzRjf.mjs → config-B93YS8tP.mjs} +3 -3
  17. package/dist/{config-B3EPzRjf.mjs.map → config-B93YS8tP.mjs.map} +1 -1
  18. package/dist/{config-Bn9jpblO.mjs → config-D1omG_UU.mjs} +3 -3
  19. package/dist/{config-Bn9jpblO.mjs.map → config-D1omG_UU.mjs.map} +1 -1
  20. package/dist/{config-RjeVGJ7K.mjs → config-DCYWFaEi.mjs} +1 -1
  21. package/dist/{context-handover-cache-CXyH6QsC.mjs → context-handover-cache-k2kWbE6G.mjs} +82 -99
  22. package/dist/context-handover-cache-k2kWbE6G.mjs.map +1 -0
  23. package/dist/daemon/index.mjs +18 -24
  24. package/dist/daemon/index.mjs.map +1 -1
  25. package/dist/daemon-B7Y8GQnt.mjs +19 -0
  26. package/dist/{daemon-aJTxzg20.mjs → daemon-Cgrdvdo6.mjs} +97 -466
  27. package/dist/daemon-Cgrdvdo6.mjs.map +1 -0
  28. package/dist/daemon-mcp/index.mjs +10 -10
  29. package/dist/daemon-mcp/index.mjs.map +1 -1
  30. package/dist/{detector-DWXkeTlk.mjs → detector-3g7XuU1r.mjs} +5 -12
  31. package/dist/detector-3g7XuU1r.mjs.map +1 -0
  32. package/dist/detector-DgDn56j-.mjs +3 -0
  33. package/dist/{embeddings-ClqKtLZ8.mjs → embeddings-BNv3TQC5.mjs} +1 -1
  34. package/dist/{embeddings-DvRKcQyt.mjs → embeddings-DfrYNIng.mjs} +1 -1
  35. package/dist/{embeddings-DvRKcQyt.mjs.map → embeddings-DfrYNIng.mjs.map} +1 -1
  36. package/dist/factory-C9wGUe30.mjs +3 -0
  37. package/dist/factory-DiuntvwG.mjs +250 -0
  38. package/dist/factory-DiuntvwG.mjs.map +1 -0
  39. package/dist/{fallback-CCFIpPha.mjs → fallback-DS6AEJsU.mjs} +190 -132
  40. package/dist/fallback-DS6AEJsU.mjs.map +1 -0
  41. package/dist/federation-db-CJDw_Pwq.mjs +3 -0
  42. package/dist/{db-DJ8rk0VM.mjs → federation-db-w8e-sKjp.mjs} +5 -5
  43. package/dist/federation-db-w8e-sKjp.mjs.map +1 -0
  44. package/dist/{helpers-crDEr6S2.mjs → helpers-D9WkIf9R.mjs} +1 -1
  45. package/dist/{helpers-crDEr6S2.mjs.map → helpers-D9WkIf9R.mjs.map} +1 -1
  46. package/dist/hooks/capture-all-events.mjs.map +1 -1
  47. package/dist/hooks/capture-session-summary.mjs.map +1 -1
  48. package/dist/hooks/capture-tool-output.mjs.map +1 -1
  49. package/dist/hooks/context-compression-hook.mjs.map +1 -1
  50. package/dist/hooks/load-core-context.mjs +5 -0
  51. package/dist/hooks/load-core-context.mjs.map +2 -2
  52. package/dist/hooks/load-project-context.mjs.map +1 -1
  53. package/dist/hooks/post-compact-inject.mjs.map +1 -1
  54. package/dist/hooks/route-agents-to-worker.mjs.map +1 -1
  55. package/dist/hooks/route-edits-to-worker.mjs +1 -1
  56. package/dist/hooks/route-edits-to-worker.mjs.map +2 -2
  57. package/dist/hooks/security-validator.mjs +8367 -19
  58. package/dist/hooks/security-validator.mjs.map +4 -4
  59. package/dist/hooks/stop-hook.mjs.map +2 -2
  60. package/dist/hooks/whisper-rules.mjs.map +2 -2
  61. package/dist/hooks/worker-proxy.mjs.map +1 -1
  62. package/dist/hooks/worker-status-line.mjs.map +2 -2
  63. package/dist/hooks/worker-supervision.mjs.map +1 -1
  64. package/dist/index.d.mts +327 -100
  65. package/dist/index.d.mts.map +1 -1
  66. package/dist/index.mjs +7 -11
  67. package/dist/indexer-backend-Cc-_NK3q.mjs +1 -0
  68. package/dist/indexer-backend-DcDtin1O.mjs +5 -0
  69. package/dist/{ipc-client-C6NryMMb.mjs → ipc-client-Dasm515c.mjs} +2 -2
  70. package/dist/{ipc-client-C6NryMMb.mjs.map → ipc-client-Dasm515c.mjs.map} +1 -1
  71. package/dist/kg-entity-Cj8Q6YmU.mjs +29 -0
  72. package/dist/kg-entity-Cj8Q6YmU.mjs.map +1 -0
  73. package/dist/{latent-ideas-BfL4nCQ3.mjs → latent-ideas-BRy6HNwg.mjs} +4 -4
  74. package/dist/{latent-ideas-BfL4nCQ3.mjs.map → latent-ideas-BRy6HNwg.mjs.map} +1 -1
  75. package/dist/{link-boost-C5PaNdzm.mjs → link-boost-BptbAPuv.mjs} +1 -1
  76. package/dist/{link-boost-C5PaNdzm.mjs.map → link-boost-BptbAPuv.mjs.map} +1 -1
  77. package/dist/{main-resolver-Bt1f6jJc.mjs → main-resolver-Dx-pxic1.mjs} +56 -31
  78. package/dist/main-resolver-Dx-pxic1.mjs.map +1 -0
  79. package/dist/main-resolver-uDtK9p6e.mjs +7 -0
  80. package/dist/merge-BncjJTfb.mjs +3 -0
  81. package/dist/merge-xoyfZQ4W.mjs +6 -0
  82. package/dist/merge-xoyfZQ4W.mjs.map +1 -0
  83. package/dist/{migrate-CfERwXhY.mjs → migrate-BD7D8EEh.mjs} +21 -54
  84. package/dist/migrate-BD7D8EEh.mjs.map +1 -0
  85. package/dist/{neighborhood-CETR_P4y.mjs → neighborhood-D8uscnGy.mjs} +4 -25
  86. package/dist/neighborhood-D8uscnGy.mjs.map +1 -0
  87. package/dist/{note-context-DCcRWBoN.mjs → note-context-CgffaUMh.mjs} +3 -23
  88. package/dist/note-context-CgffaUMh.mjs.map +1 -0
  89. package/dist/{pai-home-ChAOupZc.mjs → pai-home-CeOIYltV.mjs} +2 -2
  90. package/dist/pai-home-CeOIYltV.mjs.map +1 -0
  91. package/dist/{pai-marker-B20KqhA8.mjs → pai-marker-D1MMswkz.mjs} +1 -1
  92. package/dist/{pai-marker-B20KqhA8.mjs.map → pai-marker-D1MMswkz.mjs.map} +1 -1
  93. package/dist/{planner-D3keWys5.mjs → planner-C2wWnZrZ.mjs} +7 -7
  94. package/dist/{planner-D3keWys5.mjs.map → planner-C2wWnZrZ.mjs.map} +1 -1
  95. package/dist/{postgres-CUSXWgTG.mjs → postgres-nvU5pShF.mjs} +863 -4
  96. package/dist/postgres-nvU5pShF.mjs.map +1 -0
  97. package/dist/{program-B3eRMhff.mjs → program-Cb-9J5Ie.mjs} +2260 -1399
  98. package/dist/program-Cb-9J5Ie.mjs.map +1 -0
  99. package/dist/query-feedback-COYCnvHQ.mjs +3 -0
  100. package/dist/{query-feedback-CTs_jx6i.mjs → query-feedback-xz5axTj3.mjs} +3 -3
  101. package/dist/query-feedback-xz5axTj3.mjs.map +1 -0
  102. package/dist/{db-Ddns80yf.mjs → registry-db-Bkpbp7Gf.mjs} +5 -5
  103. package/dist/registry-db-Bkpbp7Gf.mjs.map +1 -0
  104. package/dist/registry-db-DwXpf7yF.mjs +3 -0
  105. package/dist/registry-postgres-B07-hmn8.mjs +795 -0
  106. package/dist/registry-postgres-B07-hmn8.mjs.map +1 -0
  107. package/dist/registry-sqlite-CkGND_tm.mjs +593 -0
  108. package/dist/registry-sqlite-CkGND_tm.mjs.map +1 -0
  109. package/dist/{reranker-B5qUTamW.mjs → reranker-BS5gqGeF.mjs} +1 -1
  110. package/dist/{reranker-HHmhZk6v.mjs → reranker-CRVawoEh.mjs} +1 -1
  111. package/dist/{reranker-HHmhZk6v.mjs.map → reranker-CRVawoEh.mjs.map} +1 -1
  112. package/dist/router-BXOf_e9e.mjs +3 -0
  113. package/dist/{router-DBAZfE7X.mjs → router-BdxdsAvs.mjs} +2 -2
  114. package/dist/{router-DBAZfE7X.mjs.map → router-BdxdsAvs.mjs.map} +1 -1
  115. package/dist/{run-DLG25bzt.mjs → run-DkTrZejF.mjs} +234 -49
  116. package/dist/run-DkTrZejF.mjs.map +1 -0
  117. package/dist/{runtime-paths-B0P1TvUr.mjs → runtime-paths-BRwDeBEg.mjs} +1 -1
  118. package/dist/{runtime-paths-B0P1TvUr.mjs.map → runtime-paths-BRwDeBEg.mjs.map} +1 -1
  119. package/dist/search-BQHL5wDr.mjs +3 -0
  120. package/dist/search-BaTbyWjK.mjs +107 -0
  121. package/dist/search-BaTbyWjK.mjs.map +1 -0
  122. package/dist/{server-CGiHdaUp.mjs → server-CGuZFOeR.mjs} +4 -4
  123. package/dist/{server-CGiHdaUp.mjs.map → server-CGuZFOeR.mjs.map} +1 -1
  124. package/dist/{session-keepalive-DklS8VmU.mjs → session-keepalive-C5_69Av6.mjs} +7 -7
  125. package/dist/{session-keepalive-DklS8VmU.mjs.map → session-keepalive-C5_69Av6.mjs.map} +1 -1
  126. package/dist/skills/Plan/SKILL.md +1 -1
  127. package/dist/{sources-KBGEA_E6.mjs → sources-BBe3AZ-W.mjs} +8 -27
  128. package/dist/sources-BBe3AZ-W.mjs.map +1 -0
  129. package/dist/sqlite-D9p5a4qe.mjs +935 -0
  130. package/dist/sqlite-D9p5a4qe.mjs.map +1 -0
  131. package/dist/state-CwlGAKgF.mjs +3 -0
  132. package/dist/{state-DwrsOoMi.mjs → state-n13uPK5B.mjs} +6 -5
  133. package/dist/state-n13uPK5B.mjs.map +1 -0
  134. package/dist/{stop-words-BaMEGVeY.mjs → stop-words-ClCwO8mZ.mjs} +1 -1
  135. package/dist/{stop-words-BaMEGVeY.mjs.map → stop-words-ClCwO8mZ.mjs.map} +1 -1
  136. package/dist/{themes-BVoAnLZj.mjs → themes-B2v7RNnA.mjs} +3 -3
  137. package/dist/{themes-BVoAnLZj.mjs.map → themes-B2v7RNnA.mjs.map} +1 -1
  138. package/dist/{tools-BEqiJt_j.mjs → tools-Diro2s8J.mjs} +157 -398
  139. package/dist/tools-Diro2s8J.mjs.map +1 -0
  140. package/dist/{tools-BwsOTmjh.mjs → tools-KgL1rkPD.mjs} +4 -4
  141. package/dist/{trace-Cy8quQTm.mjs → trace-BRflVyBi.mjs} +1 -1
  142. package/dist/{trace-Cy8quQTm.mjs.map → trace-BRflVyBi.mjs.map} +1 -1
  143. package/dist/{utils-BD8g8oSf.mjs → utils-BrX9FLeK.mjs} +1 -1
  144. package/dist/{utils-CJymHkYm.mjs → utils-C9HsYDpO.mjs} +1 -1
  145. package/dist/{utils-CJymHkYm.mjs.map → utils-C9HsYDpO.mjs.map} +1 -1
  146. package/dist/{vault-indexer-C5i-OAyr.mjs → vault-indexer-DHYBpRZ5.mjs} +2 -2
  147. package/dist/{vault-indexer-C5i-OAyr.mjs.map → vault-indexer-DHYBpRZ5.mjs.map} +1 -1
  148. package/dist/{wakeup-Yk5lQ0jb.mjs → wakeup-D0uvqLsE.mjs} +95 -4
  149. package/dist/wakeup-D0uvqLsE.mjs.map +1 -0
  150. package/dist/work-queue-worker-DEbWsrDQ.mjs +11 -0
  151. package/dist/{work-queue-worker-utPp4hUv.mjs → work-queue-worker-DufMOtrL.mjs} +9 -9
  152. package/dist/work-queue-worker-DufMOtrL.mjs.map +1 -0
  153. package/dist/{zettelkasten-DezbXghl.mjs → zettelkasten-BPxSOalU.mjs} +4 -4
  154. package/dist/{zettelkasten-DezbXghl.mjs.map → zettelkasten-BPxSOalU.mjs.map} +1 -1
  155. package/docker/init.sql +5 -1
  156. package/docs/commands/README.md +5 -0
  157. package/docs/commands/audit.md +1 -1
  158. package/docs/commands/backup.md +1 -1
  159. package/docs/commands/clear-names.md +1 -1
  160. package/docs/commands/config.md +4 -4
  161. package/docs/commands/daemon.md +1 -1
  162. package/docs/commands/db.md +15 -1
  163. package/docs/commands/end.md +1 -1
  164. package/docs/commands/help.md +1 -1
  165. package/docs/commands/hooks-db.md +47 -0
  166. package/docs/commands/identity.md +1 -1
  167. package/docs/commands/kg.md +1 -1
  168. package/docs/commands/launch.md +1 -1
  169. package/docs/commands/mcp.md +1 -1
  170. package/docs/commands/memory.md +1 -1
  171. package/docs/commands/notify.md +1 -1
  172. package/docs/commands/observation.md +1 -1
  173. package/docs/commands/obsidian.md +1 -1
  174. package/docs/commands/pause.md +1 -1
  175. package/docs/commands/project.md +1 -1
  176. package/docs/commands/projects.md +1 -1
  177. package/docs/commands/registry.md +1 -1
  178. package/docs/commands/restore.md +1 -1
  179. package/docs/commands/session.md +2 -2
  180. package/docs/commands/sessions.md +1 -1
  181. package/docs/commands/setup.md +1 -1
  182. package/docs/commands/shell-init.md +1 -1
  183. package/docs/commands/skill.md +1 -1
  184. package/docs/commands/task.md +1 -1
  185. package/docs/commands/topic.md +1 -1
  186. package/docs/commands/update.md +1 -1
  187. package/docs/commands/worker.md +1 -1
  188. package/docs/commands/zettel.md +1 -1
  189. package/docs/design/postgres-only.md +438 -0
  190. package/docs/design/registry-method-map.md +174 -0
  191. package/package.json +1 -1
  192. package/src/hooks/pre-compact.sh +2 -40
  193. package/src/hooks/session-hooks-db.test.ts +93 -0
  194. package/src/hooks/session-stop.sh +2 -26
  195. package/src/hooks/ts/lib/edit-gate.test.ts +9 -0
  196. package/src/hooks/ts/lib/edit-gate.ts +5 -2
  197. package/src/hooks/ts/lib/plutil-guard.test.ts +54 -0
  198. package/src/hooks/ts/lib/plutil-guard.ts +43 -0
  199. package/src/hooks/ts/lib/worker-git-guard.test.ts +134 -0
  200. package/src/hooks/ts/lib/worker-git-guard.ts +103 -0
  201. package/src/hooks/ts/pre-tool-use/security-validator.test.ts +68 -0
  202. package/src/hooks/ts/pre-tool-use/security-validator.ts +69 -21
  203. package/src/hooks/ts/session-start/load-core-context.ts +13 -0
  204. package/src/hooks/ts/session-start/session-start-worker-guard.test.ts +13 -0
  205. package/dist/auto-route-CcD0OWWB.mjs +0 -86
  206. package/dist/auto-route-CcD0OWWB.mjs.map +0 -1
  207. package/dist/clusters-Cw_P6lO-.mjs.map +0 -1
  208. package/dist/context-handover-cache-CXyH6QsC.mjs.map +0 -1
  209. package/dist/daemon-CknQ6YGZ.mjs +0 -25
  210. package/dist/daemon-aJTxzg20.mjs.map +0 -1
  211. package/dist/db-BOBfewFH.mjs +0 -3
  212. package/dist/db-DJ8rk0VM.mjs.map +0 -1
  213. package/dist/db-DbY2O8QO.mjs +0 -3
  214. package/dist/db-Ddns80yf.mjs.map +0 -1
  215. package/dist/detect-Bf2z-oKB.mjs +0 -86
  216. package/dist/detect-Bf2z-oKB.mjs.map +0 -1
  217. package/dist/detector-CkwkXuGh.mjs +0 -5
  218. package/dist/detector-DWXkeTlk.mjs.map +0 -1
  219. package/dist/factory-Ba8j9K7q.mjs +0 -3
  220. package/dist/factory-Bt7TWQje.mjs +0 -150
  221. package/dist/factory-Bt7TWQje.mjs.map +0 -1
  222. package/dist/fallback-CCFIpPha.mjs.map +0 -1
  223. package/dist/indexer-backend-CdvCJCkD.mjs.map +0 -1
  224. package/dist/kg-entity-BSW7ra8i.mjs +0 -176
  225. package/dist/kg-entity-BSW7ra8i.mjs.map +0 -1
  226. package/dist/main-resolver-Bt1f6jJc.mjs.map +0 -1
  227. package/dist/main-resolver-DYHhw5Ig.mjs +0 -7
  228. package/dist/migrate-CfERwXhY.mjs.map +0 -1
  229. package/dist/neighborhood-CETR_P4y.mjs.map +0 -1
  230. package/dist/note-context-DCcRWBoN.mjs.map +0 -1
  231. package/dist/pai-home-ChAOupZc.mjs.map +0 -1
  232. package/dist/postgres-CUSXWgTG.mjs.map +0 -1
  233. package/dist/program-B3eRMhff.mjs.map +0 -1
  234. package/dist/query-feedback-Bm6XvCmg.mjs +0 -3
  235. package/dist/query-feedback-CTs_jx6i.mjs.map +0 -1
  236. package/dist/router-CremHKTI.mjs +0 -3
  237. package/dist/run-DLG25bzt.mjs.map +0 -1
  238. package/dist/search-B69cQwDB.mjs +0 -303
  239. package/dist/search-B69cQwDB.mjs.map +0 -1
  240. package/dist/search-fb-5ovj4.mjs +0 -4
  241. package/dist/sources-KBGEA_E6.mjs.map +0 -1
  242. package/dist/sqlite-By6r2YhZ.mjs +0 -271
  243. package/dist/sqlite-By6r2YhZ.mjs.map +0 -1
  244. package/dist/state-Ca0ltLgI.mjs +0 -3
  245. package/dist/state-DwrsOoMi.mjs.map +0 -1
  246. package/dist/sync-Btcb6xA4.mjs +0 -310
  247. package/dist/sync-Btcb6xA4.mjs.map +0 -1
  248. package/dist/tools-BEqiJt_j.mjs.map +0 -1
  249. package/dist/wakeup-Yk5lQ0jb.mjs.map +0 -1
  250. package/dist/work-queue-worker-DsdJx-jn.mjs +0 -14
  251. package/dist/work-queue-worker-utPp4hUv.mjs.map +0 -1
@@ -1,7 +1,7 @@
1
- import { _ as writeYamlFileAtomic, d as readMainConfigRaw, f as writeMainConfigRaw, l as paiConfigFilePath, m as migrateMainConfigToYaml, n as CONFIG_FILE, r as DEFAULTS, s as loadConfig, u as paiConfigYamlFilePath, v as readJsonStrict, y as writeJsonAtomic } from "./config-Bn9jpblO.mjs";
2
- import { C as readWorkersSection, D as writeWorkersSection, E as resolveProviderKey, F as workersYamlPath, T as resolveModelCapability, _ as isModelCapability, a as DEFAULT_PANE, b as nativeAnthropicProvider, c as MODEL_CAPABILITIES, d as WorkersConfigError, h as expandHome, i as DEFAULT_LOG_DIR, l as PROVIDER_TAGS, o as DEFAULT_ROUTING, r as DEFAULT_CACHE_KEEPALIVE_SECS, s as DEFAULT_TREE, t as ANTHROPIC_NATIVE, v as keysDir, w as resolveCapability, x as providerCostTier, y as maskKey } from "./config-B3EPzRjf.mjs";
3
- import { A as contextLabel, D as UNLABELED, F as loadStatuses, M as isChatPane, N as isLive, O as ageOf, W as shortText, b as sessionTag, d as workerDepth, h as currentTabKey, j as contextPercent, k as alive, l as readInbox, o as parseWorkerReport, s as renderReport, u as sayToWorker, v as resolveSession, x as workerInScope } from "./run-DLG25bzt.mjs";
4
- import { b as workersLogDir, d as quotaSkipThreshold, g as eventsPath, p as resolveTarget, s as clearCooldown, u as probeQuota } from "./server-CGiHdaUp.mjs";
1
+ import { _ as writeYamlFileAtomic, d as readMainConfigRaw, f as writeMainConfigRaw, l as paiConfigFilePath, m as migrateMainConfigToYaml, n as CONFIG_FILE, r as DEFAULTS, s as loadConfig, u as paiConfigYamlFilePath, v as readJsonStrict, y as writeJsonAtomic } from "./config-D1omG_UU.mjs";
2
+ import { C as readWorkersSection, D as writeWorkersSection, E as resolveProviderKey, F as workersYamlPath, T as resolveModelCapability, _ as isModelCapability, a as DEFAULT_PANE, b as nativeAnthropicProvider, c as MODEL_CAPABILITIES, d as WorkersConfigError, h as expandHome, i as DEFAULT_LOG_DIR, l as PROVIDER_TAGS, o as DEFAULT_ROUTING, r as DEFAULT_CACHE_KEEPALIVE_SECS, s as DEFAULT_TREE, t as ANTHROPIC_NATIVE, v as keysDir, w as resolveCapability, x as providerCostTier, y as maskKey } from "./config-B93YS8tP.mjs";
3
+ import { A as contextLabel, D as UNLABELED, G as shortText, I as loadStatuses, M as elapsedOf, N as isChatPane, O as ageOf, P as isLive, T as appendLedger, b as sessionTag, d as workerDepth, h as currentTabKey, j as contextPercent, k as alive, l as readInbox, o as parseWorkerReport, s as renderReport, u as sayToWorker, v as resolveSession, x as workerInScope } from "./run-DkTrZejF.mjs";
4
+ import { _ as ledgerPath, b as workersLogDir, d as quotaSkipThreshold, g as eventsPath, p as resolveTarget, s as clearCooldown, u as probeQuota } from "./server-CGuZFOeR.mjs";
5
5
  import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, unlinkSync, writeFileSync } from "node:fs";
6
6
  import { homedir } from "node:os";
7
7
  import { basename, join, relative, resolve } from "node:path";
@@ -819,11 +819,11 @@ function goalOf(s, max = 40) {
819
819
  function paneStatusRow(s, now = /* @__PURE__ */ new Date(), columns = null) {
820
820
  const model = shortModel(s.model);
821
821
  const started = String(s.started ?? "").slice(11, 16);
822
- const age = ageOf(s.started, now);
822
+ const elapsed = elapsedOf(s.started, now);
823
823
  const tail = [
824
824
  model,
825
825
  started ? `started ${started}` : "",
826
- age
826
+ elapsed
827
827
  ].filter(Boolean).join(" · ");
828
828
  return `${goalOf(s, columns !== null ? Math.max(1, columns - tail.length - 3) : 40)} · ${tail}`;
829
829
  }
@@ -1087,6 +1087,11 @@ async function followWorkers(logDir, target, showAll, autoExit, env = process.en
1087
1087
  const c = makeColor(color);
1088
1088
  const out_ = io?.stdout ?? process.stdout;
1089
1089
  const in_ = io?.stdin ?? process.stdin;
1090
+ const safeWrite = (s) => {
1091
+ try {
1092
+ out_.write(s);
1093
+ } catch {}
1094
+ };
1090
1095
  const tty = out_.isTTY === true || env.FORCE_TTY === "1";
1091
1096
  const term = env.ITERM_SESSION_ID ?? "";
1092
1097
  const scopeTab = target || showAll ? "" : currentTabKey(env);
@@ -1098,6 +1103,9 @@ async function followWorkers(logDir, target, showAll, autoExit, env = process.en
1098
1103
  const started = Date.now();
1099
1104
  let idleSince = null;
1100
1105
  let aborted = false;
1106
+ let exitReason = "aborted";
1107
+ let consecutiveErrors = 0;
1108
+ const MAX_CONSECUTIVE_ERRORS = 10;
1101
1109
  let lastEventAt = Date.now();
1102
1110
  let meterStatus = null;
1103
1111
  let paneStatus;
@@ -1116,7 +1124,7 @@ async function followWorkers(logDir, target, showAll, autoExit, env = process.en
1116
1124
  * inserted above the fixed prompt/ticker rows (chatui.chatInsertLine). */
1117
1125
  const out = (line, keep = true) => {
1118
1126
  if (!chat) {
1119
- out_.write(line + "\n");
1127
+ safeWrite(line + "\n");
1120
1128
  return;
1121
1129
  }
1122
1130
  if (keep) {
@@ -1124,24 +1132,22 @@ async function followWorkers(logDir, target, showAll, autoExit, env = process.en
1124
1132
  if (retained.length > RETAIN_CAP) retained.splice(0, retained.length - RETAIN_CAP);
1125
1133
  }
1126
1134
  const r = chatInsertLine(line, fill, regionRows());
1127
- out_.write(r.seq);
1135
+ safeWrite(r.seq);
1128
1136
  fill = r.fill;
1129
1137
  };
1130
1138
  const eraseLiveness = () => {
1131
1139
  if (chat) return;
1132
- if (tty) out_.write("\r\x1B[K");
1140
+ if (tty) safeWrite("\r\x1B[K");
1133
1141
  };
1134
1142
  let ticker = initialFollowState();
1135
1143
  const writeLiveness = () => {
1136
1144
  if (!tty) return;
1137
1145
  const secs = Math.max(0, Math.floor((Date.now() - lastEventAt) / 1e3));
1138
- if (chat) {
1139
- const text = paneStatus ? paneStatusRow(paneStatus, /* @__PURE__ */ new Date(), columns()) : tickerText(secs, ticker.intent, ticker.tool);
1140
- out_.write(chatTickerRow(text, rows, promptCursorCol()));
1141
- } else {
1146
+ if (chat) safeWrite(chatTickerRow(paneStatus ? paneStatusRow(paneStatus, /* @__PURE__ */ new Date(), columns()) : tickerText(secs, ticker.intent, ticker.tool), rows, promptCursorCol()));
1147
+ else {
1142
1148
  const meter = meterStatus ? contextMeter(c, meterStatus) : null;
1143
- out_.write("\r\x1B[K");
1144
- out_.write(tickerText(secs, ticker.intent, ticker.tool, meter));
1149
+ safeWrite("\r\x1B[K");
1150
+ safeWrite(tickerText(secs, ticker.intent, ticker.tool, meter));
1145
1151
  }
1146
1152
  };
1147
1153
  const runningIds = () => loadStatuses(logDir).filter((s) => isLive(s) && (target !== null || showAll || (scopeTab ? workerInScope(s, term) : true))).map((s) => s.id);
@@ -1267,7 +1273,7 @@ async function followWorkers(logDir, target, showAll, autoExit, env = process.en
1267
1273
  if (!chat) return;
1268
1274
  const line = rlIn?.line ?? "";
1269
1275
  const cur = rlIn?.cursor;
1270
- out_.write(chatPromptRow(rows, line, (s) => c("dim", s), cur));
1276
+ safeWrite(chatPromptRow(rows, line, (s) => c("dim", s), cur));
1271
1277
  };
1272
1278
  if (chat) {
1273
1279
  const echoOperator = (text) => {
@@ -1348,13 +1354,13 @@ async function followWorkers(logDir, target, showAll, autoExit, env = process.en
1348
1354
  rlIn.on("close", () => {
1349
1355
  aborted = true;
1350
1356
  });
1351
- out_.write(chatEnter(rows, columns() ?? 0, (s) => c("dim", s)));
1357
+ safeWrite(chatEnter(rows, columns() ?? 0, (s) => c("dim", s)));
1352
1358
  drawPrompt();
1353
1359
  if (terminalIn) in_.on("keypress", () => drawPrompt());
1354
1360
  onResize = () => {
1355
1361
  if (typeof out_.rows === "number") rows = out_.rows;
1356
1362
  fill = 0;
1357
- out_.write("\x1B[2J" + chatScrollRegion(rows) + chatBlankRow(rows, columns() ?? 0, (s) => c("dim", s)));
1363
+ safeWrite("\x1B[2J" + chatScrollRegion(rows) + chatBlankRow(rows, columns() ?? 0, (s) => c("dim", s)));
1358
1364
  for (const ln of retained.slice(-regionRows())) out(ln, false);
1359
1365
  drawPrompt();
1360
1366
  };
@@ -1368,133 +1374,185 @@ async function followWorkers(logDir, target, showAll, autoExit, env = process.en
1368
1374
  try {
1369
1375
  for (;;) {
1370
1376
  if (aborted) return;
1371
- const statuses = new Map(loadStatuses(logDir).map((s) => [s.id, s]));
1372
- if (target) paneStatus = statuses.get(target) ?? paneStatus;
1373
- const wanted = target ? [target] : runningIds();
1374
- for (const wid of wanted) {
1375
- if (handles.has(wid) || finished.has(wid)) continue;
1376
- const path = eventsPath(logDir, wid);
1377
- const st = statuses.get(wid) ?? {
1378
- id: wid,
1379
- label: "",
1380
- cwd: "",
1381
- provider: ""
1382
- };
1383
- if (existsSync(path)) {
1384
- const multi = target === null || handles.size > 0;
1385
- handles.set(wid, attachHandle(wid, path, st, multi));
1386
- states.set(wid, states.get(wid) ?? initialFollowState());
1387
- } else if (!seenHeader.has(wid)) {
1388
- out(headerLine(c, st));
1389
- seenHeader.add(wid);
1390
- }
1391
- }
1392
- const multi = handles.size > 1 || target === null;
1393
- let progressed = false;
1394
- for (const [wid, h] of [...handles.entries()]) {
1395
- const st = statuses.get(wid) ?? {
1396
- id: wid,
1397
- label: "",
1398
- cwd: "",
1399
- provider: ""
1400
- };
1401
- const buffer = Buffer.alloc(65536);
1402
- for (;;) {
1403
- let n;
1404
- try {
1405
- n = readSync(h.fd, buffer, 0, buffer.length, null);
1406
- } catch {
1407
- n = 0;
1408
- }
1409
- if (n <= 0) break;
1410
- h.buf += buffer.toString("utf8", 0, n);
1377
+ let outcome;
1378
+ try {
1379
+ outcome = await runOneTick();
1380
+ consecutiveErrors = 0;
1381
+ } catch (e) {
1382
+ consecutiveErrors++;
1383
+ const msg = e instanceof Error ? e.message : String(e);
1384
+ try {
1385
+ noteLine(c("red", `» follow error: ${msg}`));
1386
+ } catch {}
1387
+ process.stderr.write(`pai worker follow: ${msg}\n`);
1388
+ if (consecutiveErrors < MAX_CONSECUTIVE_ERRORS) {
1389
+ await sleep(200);
1390
+ continue;
1411
1391
  }
1412
- const lines = h.buf.split("\n");
1413
- h.buf = lines.pop() ?? "";
1414
- for (const line of lines) {
1415
- if (!line.trim()) continue;
1416
- progressed = true;
1417
- let e;
1392
+ exitReason = `error: ${msg}`.slice(0, 200);
1393
+ if (chat && rlIn) {
1418
1394
  try {
1419
- e = JSON.parse(line);
1420
- } catch {
1421
- continue;
1422
- }
1423
- emitEvent(e, wid, st, multi);
1395
+ noteLine(c("dim", "» follow crashed — press enter to close this pane"));
1396
+ } catch {}
1397
+ await Promise.race([new Promise((resolve) => rlIn.once("line", () => resolve())), sleep(6e4)]);
1424
1398
  }
1425
- if (workerEnded(finished.has(wid), st.state, alive(st.pid))) {
1426
- if (!finished.has(wid)) {
1427
- eraseLiveness();
1428
- out(`${multi ? c("cyan", wid.slice(-4)) + c("dim", " ┃ ") : " "}${c("red", "✗ " + (st.state || "ended"))} · ${st.last ?? ""}`);
1429
- finished.add(wid);
1430
- }
1431
- closeSync(h.fd);
1432
- handles.delete(wid);
1399
+ return;
1400
+ }
1401
+ if (outcome.done) {
1402
+ exitReason = outcome.reason;
1403
+ return;
1404
+ }
1405
+ }
1406
+ } finally {
1407
+ rlIn?.close();
1408
+ process.removeListener("SIGINT", onInt);
1409
+ if (onResize) out_.removeListener?.("resize", onResize);
1410
+ if (chat) safeWrite(chatLeave(rows));
1411
+ for (const h of handles.values()) try {
1412
+ closeSync(h.fd);
1413
+ } catch {}
1414
+ if (target !== null) appendLedger(ledgerPath(logDir), "PANE-CLOSED", {
1415
+ id: target,
1416
+ reason: exitReason,
1417
+ secs: Math.floor((Date.now() - started) / 1e3)
1418
+ });
1419
+ }
1420
+ /**
1421
+ * One poll of the loop: attach new handles, drain them, check exit
1422
+ * conditions. Returning (rather than throwing) `done: true` is how a
1423
+ * normal end is told apart from the error path above — everything in here
1424
+ * that can throw (rendering, terminal writes) is still covered by that
1425
+ * path, so one bad event or write never takes the whole pane down with it.
1426
+ */
1427
+ async function runOneTick() {
1428
+ const statuses = new Map(loadStatuses(logDir).map((s) => [s.id, s]));
1429
+ if (target) paneStatus = statuses.get(target) ?? paneStatus;
1430
+ const wanted = target ? [target] : runningIds();
1431
+ for (const wid of wanted) {
1432
+ if (handles.has(wid) || finished.has(wid)) continue;
1433
+ const path = eventsPath(logDir, wid);
1434
+ const st = statuses.get(wid) ?? {
1435
+ id: wid,
1436
+ label: "",
1437
+ cwd: "",
1438
+ provider: ""
1439
+ };
1440
+ if (existsSync(path)) {
1441
+ const multi = target === null || handles.size > 0;
1442
+ handles.set(wid, attachHandle(wid, path, st, multi));
1443
+ states.set(wid, states.get(wid) ?? initialFollowState());
1444
+ } else if (!seenHeader.has(wid)) {
1445
+ out(headerLine(c, st));
1446
+ seenHeader.add(wid);
1447
+ }
1448
+ }
1449
+ const multi = handles.size > 1 || target === null;
1450
+ let progressed = false;
1451
+ for (const [wid, h] of [...handles.entries()]) {
1452
+ const st = statuses.get(wid) ?? {
1453
+ id: wid,
1454
+ label: "",
1455
+ cwd: "",
1456
+ provider: ""
1457
+ };
1458
+ const buffer = Buffer.alloc(65536);
1459
+ for (;;) {
1460
+ let n;
1461
+ try {
1462
+ n = readSync(h.fd, buffer, 0, buffer.length, null);
1463
+ } catch {
1464
+ n = 0;
1433
1465
  }
1466
+ if (n <= 0) break;
1467
+ h.buf += buffer.toString("utf8", 0, n);
1434
1468
  }
1435
- for (const wid of [...handles.keys()]) {
1436
- const st = statuses.get(wid) ?? {
1437
- id: wid,
1438
- label: "",
1439
- cwd: "",
1440
- provider: ""
1441
- };
1442
- const msgs = readInbox(logDir, wid);
1443
- const seenN = inboxSeen.get(wid) ?? 0;
1444
- if (msgs.length > seenN) {
1445
- for (const m of msgs.slice(seenN)) emitEvent({
1446
- type: "handoff",
1447
- from: m.from,
1448
- kind: m.kind,
1449
- text: m.text,
1450
- _ts: m._ts
1451
- }, wid, st, multi);
1452
- inboxSeen.set(wid, msgs.length);
1453
- progressed = true;
1469
+ const lines = h.buf.split("\n");
1470
+ h.buf = lines.pop() ?? "";
1471
+ for (const line of lines) {
1472
+ if (!line.trim()) continue;
1473
+ progressed = true;
1474
+ let e;
1475
+ try {
1476
+ e = JSON.parse(line);
1477
+ } catch {
1478
+ continue;
1454
1479
  }
1480
+ emitEvent(e, wid, st, multi);
1455
1481
  }
1456
- const lingerOn = target;
1457
- if (lingerOn !== null && finished.has(lingerOn)) {
1458
- if (autoExit) {
1459
- if (holdAutoExit(promptText())) {
1460
- writeLiveness();
1461
- await sleep(250);
1462
- continue;
1463
- }
1464
- const until = Date.now() + autoExit * 1e3;
1465
- while (Date.now() < until && !aborted && target === lingerOn && !holdAutoExit(promptText())) {
1466
- writeLiveness();
1467
- await sleep(250);
1468
- }
1469
- if (aborted || target !== lingerOn || holdAutoExit(promptText())) continue;
1482
+ if (workerEnded(finished.has(wid), st.state, alive(st.pid))) {
1483
+ if (!finished.has(wid)) {
1470
1484
  eraseLiveness();
1471
- out(c("dim", "closing"));
1472
- return;
1485
+ out(`${multi ? c("cyan", wid.slice(-4)) + c("dim", " ┃ ") : " "}${c("red", "✗ " + (st.state || "ended"))} · ${st.last ?? ""}`);
1486
+ finished.add(wid);
1473
1487
  }
1474
- if (rlIn === null) return;
1488
+ closeSync(h.fd);
1489
+ handles.delete(wid);
1475
1490
  }
1476
- if (autoExit && !target) {
1477
- if (runningIds().length) idleSince = null;
1478
- else if (idleSince === null) idleSince = Date.now();
1479
- else if (Date.now() - started >= 3e4 && Date.now() - idleSince >= autoExit * 1e3) {
1480
- eraseLiveness();
1481
- out(c("dim", "closing"));
1482
- return;
1491
+ }
1492
+ for (const wid of [...handles.keys()]) {
1493
+ const st = statuses.get(wid) ?? {
1494
+ id: wid,
1495
+ label: "",
1496
+ cwd: "",
1497
+ provider: ""
1498
+ };
1499
+ const msgs = readInbox(logDir, wid);
1500
+ const seenN = inboxSeen.get(wid) ?? 0;
1501
+ if (msgs.length > seenN) {
1502
+ for (const m of msgs.slice(seenN)) emitEvent({
1503
+ type: "handoff",
1504
+ from: m.from,
1505
+ kind: m.kind,
1506
+ text: m.text,
1507
+ _ts: m._ts
1508
+ }, wid, st, multi);
1509
+ inboxSeen.set(wid, msgs.length);
1510
+ progressed = true;
1511
+ }
1512
+ }
1513
+ const lingerOn = target;
1514
+ if (lingerOn !== null && finished.has(lingerOn)) {
1515
+ if (autoExit) {
1516
+ if (holdAutoExit(promptText())) {
1517
+ writeLiveness();
1518
+ await sleep(250);
1519
+ return { done: false };
1520
+ }
1521
+ const until = Date.now() + autoExit * 1e3;
1522
+ while (Date.now() < until && !aborted && target === lingerOn && !holdAutoExit(promptText())) {
1523
+ writeLiveness();
1524
+ await sleep(250);
1483
1525
  }
1526
+ if (aborted || target !== lingerOn || holdAutoExit(promptText())) return { done: false };
1527
+ eraseLiveness();
1528
+ out(c("dim", "closing"));
1529
+ return {
1530
+ done: true,
1531
+ reason: "worker-ended"
1532
+ };
1484
1533
  }
1485
- if (!progressed) {
1486
- writeLiveness();
1487
- await sleep(500);
1534
+ if (rlIn === null) return {
1535
+ done: true,
1536
+ reason: "worker-ended"
1537
+ };
1538
+ }
1539
+ if (autoExit && !target) {
1540
+ if (runningIds().length) idleSince = null;
1541
+ else if (idleSince === null) idleSince = Date.now();
1542
+ else if (Date.now() - started >= 3e4 && Date.now() - idleSince >= autoExit * 1e3) {
1543
+ eraseLiveness();
1544
+ out(c("dim", "closing"));
1545
+ return {
1546
+ done: true,
1547
+ reason: "idle"
1548
+ };
1488
1549
  }
1489
1550
  }
1490
- } finally {
1491
- rlIn?.close();
1492
- process.removeListener("SIGINT", onInt);
1493
- if (onResize) out_.removeListener?.("resize", onResize);
1494
- if (chat) out_.write(chatLeave(rows));
1495
- for (const h of handles.values()) try {
1496
- closeSync(h.fd);
1497
- } catch {}
1551
+ if (!progressed) {
1552
+ writeLiveness();
1553
+ await sleep(500);
1554
+ }
1555
+ return { done: false };
1498
1556
  }
1499
1557
  }
1500
1558
  function sleep(ms) {
@@ -2077,4 +2135,4 @@ function fallbackStatusText(s) {
2077
2135
 
2078
2136
  //#endregion
2079
2137
  export { getConfigValueOp as A, psOutput as C, resolveSpecPath as D, readSpecPrompt as E, setConfigValueOp as M, unsetConfigValueOp as N, MainConfigOpsError as O, followWorkers as S, statusLineOutput as T, setWorkersEnabled as _, addProvider as a, updateProvider as b, describeModels as c, removeProvider as d, resolveProviderName as f, setProviderModel as g, setProviderEnabled as h, fallbackStatusText as i, listConfigOp as j, formatConfigGetOutput as k, describeProviders as l, setClass as m, fallbackOn as n, classTargetText as o, setCapabilityPreference as p, fallbackStatus as r, describeCapabilities as s, fallbackOff as t, modelPrefsText as u, unsetCapabilityPreference as v, replayOutput as w, useProvider as x, unsetClass as y };
2080
- //# sourceMappingURL=fallback-CCFIpPha.mjs.map
2138
+ //# sourceMappingURL=fallback-DS6AEJsU.mjs.map