@oyasmi/pipiclaw 0.9.4-beta.2 → 0.9.5-beta.2

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 (405) hide show
  1. package/README.en.md +28 -22
  2. package/README.md +27 -21
  3. package/dist/agent/builtin-commands.d.ts +7 -2
  4. package/dist/agent/builtin-commands.js +19 -23
  5. package/dist/agent/channel-runner.d.ts +13 -13
  6. package/dist/agent/channel-runner.js +93 -76
  7. package/dist/agent/maintenance-context.d.ts +6 -5
  8. package/dist/agent/maintenance-context.js +15 -15
  9. package/dist/agent/prompt/manifest.js +1 -1
  10. package/dist/agent/prompt/resources.d.ts +1 -1
  11. package/dist/agent/prompt/resources.js +1 -1
  12. package/dist/agent/prompt/sections.js +4 -4
  13. package/dist/agent/runner-factory.d.ts +6 -6
  14. package/dist/agent/runner-factory.js +6 -7
  15. package/dist/agent/session/compaction-input.d.ts +6 -0
  16. package/dist/agent/session/compaction-input.js +75 -0
  17. package/dist/agent/session/compaction-snapshot.d.ts +30 -0
  18. package/dist/agent/session/compaction-snapshot.js +154 -0
  19. package/dist/agent/session/compaction-summary.d.ts +39 -0
  20. package/dist/agent/session/compaction-summary.js +158 -0
  21. package/dist/agent/session/compaction.d.ts +35 -0
  22. package/dist/agent/session/compaction.js +294 -0
  23. package/dist/agent/session/context-input.d.ts +15 -0
  24. package/dist/agent/session/context-input.js +82 -0
  25. package/dist/agent/session/context-snapshot.d.ts +11 -0
  26. package/dist/agent/session/context-snapshot.js +72 -0
  27. package/dist/agent/session/event-guards.d.ts +2 -0
  28. package/dist/agent/session/event-guards.js +4 -0
  29. package/dist/agent/session/request-tools.d.ts +3 -0
  30. package/dist/agent/session/request-tools.js +20 -0
  31. package/dist/agent/session/session-adapter.d.ts +2 -1
  32. package/dist/agent/session/session-adapter.js +6 -3
  33. package/dist/agent/session/session-events.d.ts +5 -4
  34. package/dist/agent/session/session-events.js +46 -59
  35. package/dist/agent/session/session-host.d.ts +29 -41
  36. package/dist/agent/session/session-host.js +86 -69
  37. package/dist/agent/session/settings-diagnostics.d.ts +5 -0
  38. package/dist/agent/session/settings-diagnostics.js +21 -0
  39. package/dist/agent/status-render.js +5 -2
  40. package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
  41. package/dist/{runtime → agent}/stop-watchdog.js +7 -3
  42. package/dist/agent/turn/progress-formatter.d.ts +1 -3
  43. package/dist/agent/turn/progress-formatter.js +3 -22
  44. package/dist/agent/turn/task-digest.d.ts +4 -2
  45. package/dist/agent/turn/task-digest.js +7 -4
  46. package/dist/agent/turn/turn-context.d.ts +11 -7
  47. package/dist/agent/turn/turn-context.js +26 -18
  48. package/dist/agent/turn/turn-finish.d.ts +17 -5
  49. package/dist/agent/turn/turn-finish.js +51 -77
  50. package/dist/agent/turn/turn-input.d.ts +2 -2
  51. package/dist/agent/turn/turn-input.js +4 -3
  52. package/dist/agent/turn/turn-output.d.ts +19 -0
  53. package/dist/agent/turn/turn-output.js +41 -0
  54. package/dist/agent/turn/turn-pipeline.d.ts +11 -8
  55. package/dist/agent/turn/turn-pipeline.js +54 -55
  56. package/dist/agent/turn/turn-prompt.d.ts +1 -1
  57. package/dist/agent/turn/turn-recovery.d.ts +11 -10
  58. package/dist/agent/turn/turn-recovery.js +14 -29
  59. package/dist/agent/types.d.ts +31 -12
  60. package/dist/agent/types.js +2 -1
  61. package/dist/app/auth-command.js +1 -1
  62. package/dist/app/home.js +31 -15
  63. package/dist/channel/active-session-store.d.ts +14 -12
  64. package/dist/channel/active-session-store.js +29 -25
  65. package/dist/channel/attachments.d.ts +25 -0
  66. package/dist/channel/attachments.js +56 -0
  67. package/dist/channel/channel-context.d.ts +87 -96
  68. package/dist/channel/channel-context.js +1 -66
  69. package/dist/channel/channel-event.d.ts +51 -41
  70. package/dist/channel/channel-event.js +6 -11
  71. package/dist/channel/channel-id.d.ts +22 -0
  72. package/dist/channel/channel-id.js +13 -0
  73. package/dist/channel/channel-index.d.ts +17 -34
  74. package/dist/channel/channel-index.js +41 -80
  75. package/dist/channel/config.d.ts +10 -0
  76. package/dist/channel/config.js +55 -0
  77. package/dist/channel/ingress.d.ts +101 -0
  78. package/dist/channel/ingress.js +5 -0
  79. package/dist/channel/store.d.ts +13 -15
  80. package/dist/channel/store.js +21 -25
  81. package/dist/channel/transport.d.ts +99 -0
  82. package/dist/channel/turn-context.d.ts +23 -0
  83. package/dist/channel/turn-context.js +1 -0
  84. package/dist/commands/catalog.d.ts +4 -7
  85. package/dist/commands/catalog.js +24 -31
  86. package/dist/commands/router.d.ts +23 -12
  87. package/dist/commands/router.js +22 -24
  88. package/dist/config/settings.d.ts +5 -4
  89. package/dist/desk/bindings.d.ts +6 -0
  90. package/dist/desk/bindings.js +105 -0
  91. package/dist/desk/commands.d.ts +81 -0
  92. package/dist/desk/commands.js +145 -0
  93. package/dist/desk/default.d.ts +4 -0
  94. package/dist/desk/default.js +11 -0
  95. package/dist/desk/paths.d.ts +41 -0
  96. package/dist/desk/paths.js +81 -0
  97. package/dist/desk/registry.d.ts +17 -0
  98. package/dist/desk/registry.js +191 -0
  99. package/dist/desk/startup-error.d.ts +4 -0
  100. package/dist/desk/startup-error.js +7 -0
  101. package/dist/desk/types.d.ts +72 -0
  102. package/dist/desk/types.js +7 -0
  103. package/dist/dingtalk/bot.d.ts +18 -35
  104. package/dist/dingtalk/bot.js +21 -204
  105. package/dist/dingtalk/channel-ids.d.ts +15 -0
  106. package/dist/dingtalk/channel-ids.js +39 -0
  107. package/dist/dingtalk/config.d.ts +6 -3
  108. package/dist/dingtalk/config.js +13 -25
  109. package/dist/dingtalk/connection.d.ts +1 -0
  110. package/dist/dingtalk/connection.js +5 -4
  111. package/dist/dingtalk/conversation-meta.d.ts +10 -5
  112. package/dist/dingtalk/conversation-meta.js +72 -50
  113. package/dist/dingtalk/delivery.d.ts +30 -14
  114. package/dist/dingtalk/delivery.js +189 -62
  115. package/dist/dingtalk/inbound-media.d.ts +2 -18
  116. package/dist/dingtalk/inbound-media.js +0 -53
  117. package/dist/dingtalk/inbound.d.ts +10 -11
  118. package/dist/dingtalk/inbound.js +12 -19
  119. package/dist/dingtalk/media.d.ts +9 -11
  120. package/dist/dingtalk/media.js +18 -31
  121. package/dist/dingtalk/progress.d.ts +8 -0
  122. package/dist/dingtalk/progress.js +20 -0
  123. package/dist/dingtalk/response-mode.d.ts +13 -0
  124. package/dist/dingtalk/response-mode.js +31 -0
  125. package/dist/dingtalk/transport.d.ts +47 -0
  126. package/dist/dingtalk/transport.js +71 -0
  127. package/dist/events/commands.d.ts +7 -2
  128. package/dist/events/commands.js +40 -22
  129. package/dist/events/pre-action-error.d.ts +10 -0
  130. package/dist/events/pre-action-error.js +10 -0
  131. package/dist/events/types.d.ts +20 -2
  132. package/dist/events/watcher.d.ts +14 -7
  133. package/dist/events/watcher.js +49 -26
  134. package/dist/index.d.ts +4 -2
  135. package/dist/jobs/completion-wake.d.ts +14 -0
  136. package/dist/jobs/completion-wake.js +36 -0
  137. package/dist/jobs/manager.d.ts +27 -22
  138. package/dist/jobs/manager.js +58 -91
  139. package/dist/jobs/record.d.ts +2 -0
  140. package/dist/jobs/record.js +2 -0
  141. package/dist/log.d.ts +0 -1
  142. package/dist/log.js +1 -1
  143. package/dist/main.js +10 -3
  144. package/dist/memory/boundary-work.d.ts +17 -0
  145. package/dist/memory/boundary-work.js +162 -0
  146. package/dist/memory/commands.d.ts +4 -3
  147. package/dist/memory/commands.js +16 -16
  148. package/dist/memory/desk-memory-queue.d.ts +18 -0
  149. package/dist/memory/desk-memory-queue.js +33 -0
  150. package/dist/memory/index-budget.d.ts +3 -3
  151. package/dist/memory/index-budget.js +3 -3
  152. package/dist/memory/journal.d.ts +6 -6
  153. package/dist/memory/journal.js +14 -14
  154. package/dist/memory/lifecycle.d.ts +14 -21
  155. package/dist/memory/lifecycle.js +73 -103
  156. package/dist/memory/maintenance-state.d.ts +14 -15
  157. package/dist/memory/maintenance-state.js +43 -42
  158. package/dist/memory/reflect-job.d.ts +5 -4
  159. package/dist/memory/reflect-job.js +21 -15
  160. package/dist/memory/reflect.d.ts +2 -1
  161. package/dist/memory/reflect.js +13 -12
  162. package/dist/memory/render.d.ts +1 -1
  163. package/dist/memory/render.js +2 -2
  164. package/dist/memory/review-log.d.ts +4 -4
  165. package/dist/memory/review-log.js +5 -5
  166. package/dist/memory/scheduler.d.ts +12 -19
  167. package/dist/memory/scheduler.js +28 -64
  168. package/dist/memory/session-corpus.d.ts +4 -1
  169. package/dist/memory/session-corpus.js +70 -29
  170. package/dist/memory/session-search.d.ts +11 -3
  171. package/dist/memory/session-search.js +14 -11
  172. package/dist/memory/sidecar-worker.d.ts +1 -0
  173. package/dist/memory/sidecar-worker.js +57 -76
  174. package/dist/memory/source-window.d.ts +0 -6
  175. package/dist/memory/source-window.js +0 -20
  176. package/dist/memory/store.d.ts +12 -12
  177. package/dist/memory/store.js +44 -44
  178. package/dist/paths.d.ts +2 -0
  179. package/dist/paths.js +2 -0
  180. package/dist/playbooks/agent-delegation.md +16 -16
  181. package/dist/playbooks/background-jobs.md +5 -3
  182. package/dist/playbooks/event-scheduling.md +7 -5
  183. package/dist/playbooks/memory-and-learning.md +16 -12
  184. package/dist/playbooks/outbound-media.md +1 -1
  185. package/dist/playbooks/runtime-orientation.md +35 -23
  186. package/dist/playbooks/task-lead.md +13 -11
  187. package/dist/runtime/bootstrap.d.ts +36 -13
  188. package/dist/runtime/bootstrap.js +310 -138
  189. package/dist/runtime/channel-queue.d.ts +23 -0
  190. package/dist/{dingtalk → runtime}/channel-queue.js +20 -9
  191. package/dist/runtime/daemon-lock.d.ts +12 -0
  192. package/dist/runtime/daemon-lock.js +28 -0
  193. package/dist/runtime/desk-runtime.d.ts +131 -0
  194. package/dist/runtime/desk-runtime.js +402 -0
  195. package/dist/runtime/durable-dispatch.d.ts +11 -5
  196. package/dist/runtime/durable-dispatch.js +20 -8
  197. package/dist/runtime/inbound-images.d.ts +32 -10
  198. package/dist/runtime/inbound-images.js +95 -21
  199. package/dist/runtime/ingress-busy.d.ts +26 -0
  200. package/dist/runtime/ingress-busy.js +211 -0
  201. package/dist/runtime/ingress-commands.d.ts +7 -0
  202. package/dist/runtime/ingress-commands.js +162 -0
  203. package/dist/runtime/ingress-deps.d.ts +62 -0
  204. package/dist/runtime/ingress-deps.js +1 -0
  205. package/dist/runtime/ingress.d.ts +22 -0
  206. package/dist/runtime/ingress.js +376 -0
  207. package/dist/runtime/request-execution.d.ts +19 -0
  208. package/dist/runtime/request-execution.js +88 -0
  209. package/dist/runtime/shutdown.d.ts +13 -5
  210. package/dist/runtime/shutdown.js +10 -4
  211. package/dist/runtime/task-driver.d.ts +38 -22
  212. package/dist/runtime/task-driver.js +142 -116
  213. package/dist/runtime/task-spawn.d.ts +4 -4
  214. package/dist/runtime/task-spawn.js +6 -5
  215. package/dist/runtime/task-wake.d.ts +6 -4
  216. package/dist/runtime/task-wake.js +7 -7
  217. package/dist/runtime/transports.d.ts +32 -0
  218. package/dist/runtime/transports.js +101 -0
  219. package/dist/runtime/turn-run.d.ts +18 -9
  220. package/dist/runtime/turn-run.js +302 -71
  221. package/dist/runtime/wake-coalescing.d.ts +11 -3
  222. package/dist/runtime/wake-coalescing.js +10 -0
  223. package/dist/security/config.js +5 -10
  224. package/dist/security/logger.js +1 -1
  225. package/dist/security/path-guard.js +7 -63
  226. package/dist/security/types.d.ts +27 -30
  227. package/dist/security/types.js +0 -1
  228. package/dist/shared/atomic-file.d.ts +2 -0
  229. package/dist/shared/atomic-file.js +14 -1
  230. package/dist/shared/file-lock.d.ts +35 -0
  231. package/dist/shared/file-lock.js +195 -0
  232. package/dist/shared/with-timeout.d.ts +2 -0
  233. package/dist/shared/with-timeout.js +21 -0
  234. package/dist/skills/loader.d.ts +1 -1
  235. package/dist/skills/loader.js +2 -2
  236. package/dist/skills/workspace.js +2 -2
  237. package/dist/subagents/completion-wake.d.ts +11 -2
  238. package/dist/subagents/completion-wake.js +22 -9
  239. package/dist/subagents/discovery.js +1 -1
  240. package/dist/subagents/dispatch.d.ts +0 -10
  241. package/dist/subagents/dispatch.js +10 -28
  242. package/dist/subagents/external/dispatch.js +1 -1
  243. package/dist/subagents/external/run.d.ts +1 -1
  244. package/dist/subagents/external/run.js +3 -3
  245. package/dist/subagents/internal/run.js +1 -1
  246. package/dist/subagents/internal/worker.js +6 -14
  247. package/dist/subagents/run-archive.d.ts +11 -0
  248. package/dist/subagents/run-archive.js +49 -0
  249. package/dist/subagents/run-record.d.ts +9 -8
  250. package/dist/subagents/run-record.js +3 -3
  251. package/dist/subagents/run-registry.d.ts +5 -3
  252. package/dist/subagents/run-registry.js +22 -45
  253. package/dist/subagents/runs.d.ts +23 -13
  254. package/dist/subagents/runs.js +75 -82
  255. package/dist/subagents/task-envelope.js +9 -11
  256. package/dist/subagents/types.d.ts +6 -5
  257. package/dist/tasks/board.d.ts +1 -1
  258. package/dist/tasks/board.js +2 -2
  259. package/dist/tasks/bound-work.d.ts +2 -2
  260. package/dist/tasks/bound-work.js +7 -7
  261. package/dist/tasks/brief.d.ts +1 -1
  262. package/dist/tasks/brief.js +9 -9
  263. package/dist/tasks/commands.d.ts +11 -2
  264. package/dist/tasks/commands.js +66 -41
  265. package/dist/tasks/contract.d.ts +0 -2
  266. package/dist/tasks/contract.js +1 -3
  267. package/dist/tasks/create.d.ts +3 -1
  268. package/dist/tasks/create.js +10 -4
  269. package/dist/tasks/frontmatter.d.ts +6 -2
  270. package/dist/tasks/frontmatter.js +10 -10
  271. package/dist/tasks/loop-log.d.ts +7 -13
  272. package/dist/tasks/loop-log.js +14 -17
  273. package/dist/tasks/mutation-lock.d.ts +7 -5
  274. package/dist/tasks/mutation-lock.js +32 -9
  275. package/dist/tasks/session-path.d.ts +3 -3
  276. package/dist/tasks/session-path.js +5 -5
  277. package/dist/tasks/steer.d.ts +5 -5
  278. package/dist/tasks/steer.js +42 -40
  279. package/dist/tasks/store.d.ts +11 -11
  280. package/dist/tasks/store.js +32 -29
  281. package/dist/tools/bash.d.ts +5 -5
  282. package/dist/tools/bash.js +19 -18
  283. package/dist/tools/contract/names.d.ts +7 -0
  284. package/dist/tools/contract/names.js +22 -0
  285. package/dist/tools/edit.js +1 -1
  286. package/dist/tools/event-manage.d.ts +3 -1
  287. package/dist/tools/event-manage.js +34 -33
  288. package/dist/tools/glob.js +5 -5
  289. package/dist/tools/grep.js +2 -2
  290. package/dist/tools/index.d.ts +9 -8
  291. package/dist/tools/index.js +12 -16
  292. package/dist/tools/job.d.ts +4 -2
  293. package/dist/tools/job.js +11 -8
  294. package/dist/tools/memory-manage.d.ts +5 -3
  295. package/dist/tools/memory-manage.js +24 -24
  296. package/dist/tools/read.js +1 -1
  297. package/dist/tools/registry.d.ts +12 -8
  298. package/dist/tools/registry.js +13 -9
  299. package/dist/tools/send-media.d.ts +2 -2
  300. package/dist/tools/send-media.js +3 -3
  301. package/dist/tools/session-search.d.ts +3 -1
  302. package/dist/tools/session-search.js +8 -6
  303. package/dist/tools/subagent-manage.d.ts +2 -8
  304. package/dist/tools/subagent-manage.js +19 -15
  305. package/dist/tools/subagent.js +1 -1
  306. package/dist/tools/task-manage/create.js +1 -1
  307. package/dist/tools/task-manage/factory.js +2 -2
  308. package/dist/tools/task-manage/lifecycle.js +3 -1
  309. package/dist/tools/task-manage/log-view.js +2 -2
  310. package/dist/tools/task-manage/shared.js +3 -3
  311. package/dist/tools/task-manage/step-end.js +3 -3
  312. package/dist/tools/task-manage/types.d.ts +8 -3
  313. package/dist/tools/web-cache.d.ts +3 -3
  314. package/dist/tools/web-cache.js +12 -12
  315. package/dist/tools/web-fetch.d.ts +2 -2
  316. package/dist/tools/web-fetch.js +7 -7
  317. package/dist/tools/write-content.js +1 -1
  318. package/dist/tui/cli.d.ts +17 -5
  319. package/dist/tui/cli.js +90 -27
  320. package/dist/tui/client.d.ts +26 -0
  321. package/dist/tui/client.js +157 -0
  322. package/dist/tui/colors.d.ts +0 -1
  323. package/dist/tui/colors.js +0 -1
  324. package/dist/tui/commands.d.ts +10 -51
  325. package/dist/tui/commands.js +16 -39
  326. package/dist/tui/frontend.d.ts +2 -2
  327. package/dist/tui/frontend.js +2 -2
  328. package/dist/tui/pitui-frontend.d.ts +0 -2
  329. package/dist/tui/pitui-frontend.js +1 -6
  330. package/dist/tui/render.d.ts +62 -0
  331. package/dist/tui/render.js +123 -0
  332. package/dist/tui/session.d.ts +92 -0
  333. package/dist/tui/session.js +317 -0
  334. package/dist/usage/ledger.d.ts +5 -0
  335. package/dist/usage/ledger.js +2 -0
  336. package/dist/usage/render.d.ts +6 -1
  337. package/dist/usage/render.js +18 -13
  338. package/dist/webapi/auth.d.ts +13 -0
  339. package/dist/webapi/auth.js +29 -0
  340. package/dist/webapi/config.d.ts +29 -0
  341. package/dist/webapi/config.js +100 -0
  342. package/dist/webapi/errors.d.ts +39 -0
  343. package/dist/webapi/errors.js +32 -0
  344. package/dist/webapi/http.d.ts +25 -0
  345. package/dist/webapi/http.js +4 -0
  346. package/dist/webapi/ids.d.ts +9 -0
  347. package/dist/webapi/ids.js +20 -0
  348. package/dist/webapi/input.d.ts +17 -0
  349. package/dist/webapi/input.js +229 -0
  350. package/dist/webapi/items.d.ts +37 -0
  351. package/dist/webapi/items.js +48 -0
  352. package/dist/webapi/key-command.d.ts +2 -0
  353. package/dist/webapi/key-command.js +110 -0
  354. package/dist/webapi/limits.d.ts +47 -0
  355. package/dist/webapi/limits.js +48 -0
  356. package/dist/webapi/request-policy.d.ts +17 -0
  357. package/dist/webapi/request-policy.js +160 -0
  358. package/dist/webapi/response-record.d.ts +68 -0
  359. package/dist/webapi/response-record.js +58 -0
  360. package/dist/webapi/response-state.d.ts +90 -0
  361. package/dist/webapi/response-state.js +347 -0
  362. package/dist/webapi/routes/conversations.d.ts +8 -0
  363. package/dist/webapi/routes/conversations.js +80 -0
  364. package/dist/webapi/routes/models.d.ts +3 -0
  365. package/dist/webapi/routes/models.js +12 -0
  366. package/dist/webapi/routes/responses.d.ts +8 -0
  367. package/dist/webapi/routes/responses.js +118 -0
  368. package/dist/webapi/routes/websocket.d.ts +9 -0
  369. package/dist/webapi/routes/websocket.js +328 -0
  370. package/dist/webapi/server.d.ts +24 -0
  371. package/dist/webapi/server.js +229 -0
  372. package/dist/webapi/service.d.ts +130 -0
  373. package/dist/webapi/service.js +588 -0
  374. package/dist/webapi/store.d.ts +46 -0
  375. package/dist/webapi/store.js +245 -0
  376. package/dist/webapi/stream.d.ts +13 -0
  377. package/dist/webapi/stream.js +76 -0
  378. package/dist/webapi/transport.d.ts +43 -0
  379. package/dist/webapi/transport.js +100 -0
  380. package/package.json +9 -2
  381. package/dist/channel/channel-paths.d.ts +0 -16
  382. package/dist/channel/channel-paths.js +0 -53
  383. package/dist/channel/commands.d.ts +0 -32
  384. package/dist/channel/commands.js +0 -109
  385. package/dist/channel/project-scope-store.d.ts +0 -51
  386. package/dist/channel/project-scope-store.js +0 -112
  387. package/dist/dingtalk/channel-queue.d.ts +0 -19
  388. package/dist/dingtalk/handler.d.ts +0 -90
  389. package/dist/memory/channel-maintenance-queue.d.ts +0 -5
  390. package/dist/memory/channel-maintenance-queue.js +0 -8
  391. package/dist/runtime/task-migration.d.ts +0 -30
  392. package/dist/runtime/task-migration.js +0 -465
  393. package/dist/runtime/turn-handler.d.ts +0 -47
  394. package/dist/runtime/turn-handler.js +0 -318
  395. package/dist/security/project-scope.d.ts +0 -45
  396. package/dist/security/project-scope.js +0 -105
  397. package/dist/tui/app.d.ts +0 -16
  398. package/dist/tui/app.js +0 -166
  399. package/dist/tui/terminal-context.d.ts +0 -27
  400. package/dist/tui/terminal-context.js +0 -84
  401. package/dist/tui/terminal-media-sender.d.ts +0 -9
  402. package/dist/tui/terminal-media-sender.js +0 -15
  403. package/dist/tui/turn-controller.d.ts +0 -64
  404. package/dist/tui/turn-controller.js +0 -311
  405. /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
@@ -3,7 +3,7 @@ import { parseLocalTime } from "../shared/local-time.js";
3
3
  import { recencyBoostByAge, tokenizeRecallText } from "./search.js";
4
4
  import { buildSessionCorpus } from "./session-corpus.js";
5
5
  import { runSidecarTask } from "./sidecar-worker.js";
6
- const SESSION_SEARCH_SUMMARY_SYSTEM_PROMPT = `You summarize current-channel transcript search hits for Pipiclaw.
6
+ const SESSION_SEARCH_SUMMARY_SYSTEM_PROMPT = `You summarize transcript search hits from one Pipiclaw desk's conversations.
7
7
 
8
8
  Return plain text only.
9
9
 
@@ -116,7 +116,7 @@ ${query}
116
116
  Transcript hit:
117
117
  ${fallback}`,
118
118
  timeoutMs: request.timeoutMs,
119
- usageContext: request.channelId ? { channelId: request.channelId } : undefined,
119
+ usageContext: request.channelId ? { channelId: request.channelId, desk: request.desk } : undefined,
120
120
  parse: (text) => text.trim(),
121
121
  });
122
122
  return result.output || fallback;
@@ -128,7 +128,10 @@ ${fallback}`,
128
128
  function toResult(request, document, score, matches, summary) {
129
129
  return {
130
130
  source: document.source,
131
- path: relative(request.channelDir, document.path) || document.path,
131
+ path: relative(request.deskDir, document.path) || document.path,
132
+ ...(document.conversation
133
+ ? { conversation: document.conversation, channel: request.describeConversation?.(document.conversation) }
134
+ : {}),
132
135
  when: document.timestamp,
133
136
  role: document.role,
134
137
  score: Number(score.toFixed(3)),
@@ -139,11 +142,11 @@ function toResult(request, document, score, matches, summary) {
139
142
  const CORPUS_CACHE_TTL_MS = 30_000;
140
143
  const CORPUS_CACHE_MAX_CHANNELS = 8;
141
144
  const corpusCache = new Map();
142
- function corpusCacheKey(channelDir, maxFiles, maxCharsPerChunk) {
143
- return JSON.stringify([channelDir, maxFiles, maxCharsPerChunk]);
145
+ function corpusCacheKey(deskDir, maxFiles, maxCharsPerChunk) {
146
+ return JSON.stringify([deskDir, maxFiles, maxCharsPerChunk]);
144
147
  }
145
- async function getCachedCorpus(channelDir, maxFiles, maxCharsPerChunk) {
146
- const key = corpusCacheKey(channelDir, maxFiles, maxCharsPerChunk);
148
+ async function getCachedCorpus(deskDir, maxFiles, maxCharsPerChunk) {
149
+ const key = corpusCacheKey(deskDir, maxFiles, maxCharsPerChunk);
147
150
  const cached = corpusCache.get(key);
148
151
  if (cached && Date.now() - cached.timestamp < CORPUS_CACHE_TTL_MS) {
149
152
  corpusCache.delete(key);
@@ -151,12 +154,12 @@ async function getCachedCorpus(channelDir, maxFiles, maxCharsPerChunk) {
151
154
  return cached.documents;
152
155
  }
153
156
  const documents = await buildSessionCorpus({
154
- channelDir,
157
+ deskDir,
155
158
  maxFiles,
156
159
  maxCharsPerDocument: maxCharsPerChunk,
157
160
  });
158
161
  corpusCache.delete(key);
159
- corpusCache.set(key, { channelDir, maxFiles, maxCharsPerChunk, documents, timestamp: Date.now() });
162
+ corpusCache.set(key, { deskDir, maxFiles, maxCharsPerChunk, documents, timestamp: Date.now() });
160
163
  if (corpusCache.size > CORPUS_CACHE_MAX_CHANNELS) {
161
164
  const oldestKey = corpusCache.keys().next().value;
162
165
  if (oldestKey)
@@ -164,12 +167,12 @@ async function getCachedCorpus(channelDir, maxFiles, maxCharsPerChunk) {
164
167
  }
165
168
  return documents;
166
169
  }
167
- export async function searchChannelSessions(request) {
170
+ export async function searchDeskSessions(request) {
168
171
  const limit = clampInteger(request.limit, 1, 5);
169
172
  const maxChunks = clampInteger(request.maxChunks, 1, 500);
170
173
  const query = request.query.trim();
171
174
  const roleFilter = normalizeRoleFilter(request.roleFilter);
172
- const documents = (await getCachedCorpus(request.channelDir, request.maxFiles, request.maxCharsPerChunk))
175
+ const documents = (await getCachedCorpus(request.deskDir, request.maxFiles, request.maxCharsPerChunk))
173
176
  .filter((document) => roleFilter.size === 0 || roleFilter.has(document.role))
174
177
  .sort(sortRecentDocuments)
175
178
  .slice(0, maxChunks);
@@ -11,6 +11,7 @@ export interface SidecarTask<T> {
11
11
  /** Attributes this task's LLM spend to a channel in the usage ledger. */
12
12
  usageContext?: {
13
13
  channelId: string;
14
+ desk?: string;
14
15
  correlationId?: string;
15
16
  };
16
17
  /**
@@ -3,6 +3,7 @@ import { streamSimple } from "@earendil-works/pi-ai/compat";
3
3
  import { convertToLlm } from "@earendil-works/pi-coding-agent";
4
4
  import { formatModelReference } from "../models/reference.js";
5
5
  import { extractAssistantText } from "../shared/text-utils.js";
6
+ import { withAbortSignal } from "../shared/with-timeout.js";
6
7
  import { getUsageLedger } from "../usage/ledger.js";
7
8
  const SIDE_CAR_RETRY_DELAY_MS = 2_000;
8
9
  const SIDE_CAR_MAX_ATTEMPTS = 2;
@@ -64,6 +65,7 @@ function recordSidecarUsage(task, message) {
64
65
  return;
65
66
  getUsageLedger().record({
66
67
  channelId: task.usageContext?.channelId ?? "",
68
+ desk: task.usageContext?.desk,
67
69
  kind: "sidecar",
68
70
  model: formatModelReference(task.model),
69
71
  label: task.name,
@@ -85,87 +87,56 @@ function recordSidecarUsage(task, message) {
85
87
  });
86
88
  }
87
89
  export async function runSidecarTask(task) {
88
- const apiKey = await task.resolveApiKey(task.model);
89
- const worker = new Agent({
90
- initialState: {
91
- systemPrompt: task.systemPrompt,
92
- model: task.model,
93
- thinkingLevel: "off",
94
- tools: [],
95
- },
96
- convertToLlm,
97
- getApiKey: async () => apiKey,
98
- streamFn: streamSimple,
99
- });
90
+ const controller = new AbortController();
91
+ const signal = task.signal ? AbortSignal.any([task.signal, controller.signal]) : controller.signal;
92
+ const timeout = task.timeoutMs && task.timeoutMs > 0
93
+ ? setTimeout(() => controller.abort(new SidecarTimeoutError(task.name, task.timeoutMs)), task.timeoutMs)
94
+ : undefined;
95
+ let worker;
100
96
  const abortWorker = () => {
101
97
  try {
102
- worker.abort();
98
+ worker?.abort();
103
99
  }
104
100
  catch {
105
- /* ignore */
101
+ /* cancellation still releases the caller */
106
102
  }
107
103
  };
108
- let removeAbortListener = () => { };
109
- let timeoutHandle = null;
110
- const runPromise = (async () => {
111
- await worker.prompt(task.prompt);
112
- await worker.waitForIdle();
113
- const lastMessage = worker.state.messages[worker.state.messages.length - 1];
114
- if (!lastMessage || lastMessage.role !== "assistant") {
115
- throw new Error(`Sidecar task "${task.name}" returned no assistant message`);
116
- }
117
- if (lastMessage.stopReason === "error" || lastMessage.stopReason === "aborted") {
118
- // Record before throwing: a timed-out or aborted rerank still consumed provider tokens.
119
- // Skipping it made every timeout invisible spend — `/usage`'s sidecar line was
120
- // systematically low by exactly the calls we were paying for and discarding.
104
+ signal.addEventListener("abort", abortWorker, { once: true });
105
+ try {
106
+ return await withAbortSignal(signal, async () => {
107
+ // Auth is part of the same deadline as inference. A late credential cannot start a request.
108
+ const apiKey = await task.resolveApiKey(task.model);
109
+ signal.throwIfAborted();
110
+ worker = new Agent({
111
+ initialState: { systemPrompt: task.systemPrompt, model: task.model, thinkingLevel: "off", tools: [] },
112
+ convertToLlm,
113
+ getApiKey: async () => apiKey,
114
+ streamFn: streamSimple,
115
+ });
116
+ await worker.prompt(task.prompt);
117
+ await worker.waitForIdle();
118
+ const lastMessage = worker.state.messages[worker.state.messages.length - 1];
119
+ if (!lastMessage || lastMessage.role !== "assistant") {
120
+ throw new Error(`Sidecar task "${task.name}" returned no assistant message`);
121
+ }
121
122
  recordSidecarUsage(task, lastMessage);
122
- throw new Error(lastMessage.errorMessage || `Sidecar task "${task.name}" failed`);
123
- }
124
- recordSidecarUsage(task, lastMessage);
125
- const rawText = extractAssistantText(lastMessage);
126
- try {
127
- return {
128
- output: task.parse(rawText),
129
- rawText,
130
- };
131
- }
132
- catch (error) {
133
- throw new SidecarParseError(task.name, rawText, error);
134
- }
135
- })();
136
- void runPromise.catch(() => { });
137
- const blockers = [];
138
- if (task.timeoutMs && task.timeoutMs > 0) {
139
- blockers.push(new Promise((_, reject) => {
140
- timeoutHandle = setTimeout(() => {
141
- abortWorker();
142
- reject(new SidecarTimeoutError(task.name, task.timeoutMs));
143
- }, task.timeoutMs);
144
- }));
145
- }
146
- if (task.signal) {
147
- const signal = task.signal;
148
- blockers.push(new Promise((_, reject) => {
149
- const abort = () => {
150
- abortWorker();
151
- reject(createAbortError(task.name, signal.reason));
152
- };
153
- if (signal.aborted) {
154
- abort();
155
- return;
123
+ signal.throwIfAborted();
124
+ if (lastMessage.stopReason === "error" || lastMessage.stopReason === "aborted") {
125
+ throw new Error(lastMessage.errorMessage || `Sidecar task "${task.name}" failed`);
156
126
  }
157
- signal.addEventListener("abort", abort, { once: true });
158
- removeAbortListener = () => signal.removeEventListener("abort", abort);
159
- }));
160
- }
161
- try {
162
- return blockers.length > 0 ? await Promise.race([runPromise, ...blockers]) : await runPromise;
127
+ const rawText = extractAssistantText(lastMessage);
128
+ try {
129
+ return { output: task.parse(rawText), rawText };
130
+ }
131
+ catch (error) {
132
+ throw new SidecarParseError(task.name, rawText, error);
133
+ }
134
+ });
163
135
  }
164
136
  finally {
165
- if (timeoutHandle) {
166
- clearTimeout(timeoutHandle);
167
- }
168
- removeAbortListener();
137
+ if (timeout)
138
+ clearTimeout(timeout);
139
+ signal.removeEventListener("abort", abortWorker);
169
140
  }
170
141
  }
171
142
  /** Appends a non-empty repair hint to the original prompt, or returns it unchanged. */
@@ -178,12 +149,16 @@ export async function runRetriedSidecarTask(task) {
178
149
  // this prompt instead of the original.
179
150
  let repairedPrompt;
180
151
  let attempt = 0;
152
+ const deadline = task.timeoutMs && task.timeoutMs > 0 ? Date.now() + task.timeoutMs : undefined;
181
153
  for (;;) {
182
154
  attempt += 1;
183
155
  if (isExternalAbort(task)) {
184
156
  throw createAbortError(task.name, task.signal?.reason);
185
157
  }
186
- const current = repairedPrompt === undefined ? task : { ...task, prompt: repairedPrompt };
158
+ const remaining = deadline === undefined ? task.timeoutMs : deadline - Date.now();
159
+ if (remaining !== undefined && remaining <= 0)
160
+ throw new SidecarTimeoutError(task.name, task.timeoutMs);
161
+ const current = { ...task, prompt: repairedPrompt ?? task.prompt, timeoutMs: remaining };
187
162
  try {
188
163
  return await runSidecarTask(current);
189
164
  }
@@ -191,17 +166,23 @@ export async function runRetriedSidecarTask(task) {
191
166
  // A parse failure is recoverable exactly once when the caller supplies a
192
167
  // repair hint: retry with the nudge appended so a malformed-but-fixable
193
168
  // output (e.g. a misspelled JSON key) gets one targeted correction pass.
194
- if (error instanceof SidecarParseError && repairedPrompt === undefined && typeof task.repair === "function") {
169
+ if (error instanceof SidecarParseError &&
170
+ attempt < SIDE_CAR_MAX_ATTEMPTS &&
171
+ repairedPrompt === undefined &&
172
+ typeof task.repair === "function") {
195
173
  repairedPrompt = withRepairSuffix(task.prompt, task.repair(error));
196
- await delay(SIDE_CAR_RETRY_DELAY_MS, task);
174
+ await delay(Math.min(SIDE_CAR_RETRY_DELAY_MS, Math.max(0, (deadline ?? Number.POSITIVE_INFINITY) - Date.now())), task);
197
175
  continue;
198
176
  }
199
177
  // Parse failures are otherwise fatal — a blind retry would reproduce the
200
178
  // same bad output. Transient failures get the standard retry budget.
201
- if (attempt >= SIDE_CAR_MAX_ATTEMPTS || error instanceof SidecarParseError || isExternalAbort(task)) {
179
+ if (attempt >= SIDE_CAR_MAX_ATTEMPTS ||
180
+ error instanceof SidecarParseError ||
181
+ error instanceof SidecarTimeoutError ||
182
+ isExternalAbort(task)) {
202
183
  throw error;
203
184
  }
204
- await delay(SIDE_CAR_RETRY_DELAY_MS, task);
185
+ await delay(Math.min(SIDE_CAR_RETRY_DELAY_MS, Math.max(0, (deadline ?? Number.POSITIVE_INFINITY) - Date.now())), task);
205
186
  }
206
187
  }
207
188
  }
@@ -16,9 +16,3 @@ export declare function buildIncrementalMemorySourceWindow(options: {
16
16
  sourceKind: Extract<MemorySourceKind, "idle" | "new-session" | "shutdown">;
17
17
  fallbackMessages?: AgentMessage[];
18
18
  }): MemorySourceWindow;
19
- export declare function buildCompactionMemorySourceWindow(options: {
20
- entries: SessionEntry[];
21
- messagesToSummarize: AgentMessage[];
22
- firstKeptEntryId?: string;
23
- lastEntryId?: string;
24
- }): MemorySourceWindow;
@@ -37,23 +37,3 @@ export function buildIncrementalMemorySourceWindow(options) {
37
37
  windowId: createWindowId(options.sourceKind, options.lastEntryId, throughEntryId, messages),
38
38
  };
39
39
  }
40
- export function buildCompactionMemorySourceWindow(options) {
41
- const boundaryIndex = options.firstKeptEntryId
42
- ? options.entries.findIndex((entry) => entry.id === options.firstKeptEntryId)
43
- : -1;
44
- const coveredEntries = boundaryIndex >= 0 ? options.entries.slice(0, boundaryIndex) : [];
45
- const incrementalEntries = entriesSince(coveredEntries, options.lastEntryId);
46
- const throughEntryId = incrementalEntries.at(-1)?.id ?? coveredEntries.at(-1)?.id;
47
- const incrementalMessages = messagesFromEntries(incrementalEntries);
48
- const messages = incrementalMessages.length > 0 || options.lastEntryId !== undefined
49
- ? incrementalMessages
50
- : [...options.messagesToSummarize];
51
- return {
52
- sourceKind: "compaction",
53
- fromEntryId: options.lastEntryId,
54
- throughEntryId,
55
- entries: incrementalEntries,
56
- messages,
57
- windowId: createWindowId("compaction", options.lastEntryId, throughEntryId, messages),
58
- };
59
- }
@@ -40,9 +40,9 @@ export interface MemoryTombstoneRecord {
40
40
  */
41
41
  revoked?: boolean;
42
42
  }
43
- export declare function getChannelMemoryDir(channelDir: string): string;
44
- export declare function getChannelMemoryIndexPath(channelDir: string): string;
45
- export declare function getMemoryEntryPath(channelDir: string, name: string): string;
43
+ export declare function getMemoryDir(deskDir: string): string;
44
+ export declare function getMemoryIndexPath(deskDir: string): string;
45
+ export declare function getMemoryEntryPath(deskDir: string, name: string): string;
46
46
  export declare function isValidMemoryName(name: string): boolean;
47
47
  /** Slugify free text into a memory name; falls back to `m-<hash6>` when nothing usable remains. */
48
48
  export declare function slugifyMemoryName(text: string): string;
@@ -53,16 +53,16 @@ export declare function parseMemoryFile(name: string, raw: string, fallbackDate:
53
53
  export declare function serializeMemoryEntry(entry: MemoryEntry): string;
54
54
  /** Test seam: drop the parse cache so a fixture rewritten in place is re-read. */
55
55
  export declare function clearMemoryStoreCache(): void;
56
- export declare function listMemoryEntries(channelDir: string): Promise<MemoryEntry[]>;
57
- export declare function readMemoryEntry(channelDir: string, name: string): Promise<MemoryEntry | undefined>;
56
+ export declare function listMemoryEntries(deskDir: string): Promise<MemoryEntry[]>;
57
+ export declare function readMemoryEntry(deskDir: string, name: string): Promise<MemoryEntry | undefined>;
58
58
  export declare function renderMemoryIndex(entries: MemoryEntry[]): string;
59
59
  export declare function renderIndexLine(entry: MemoryEntry): string;
60
- export declare function rebuildMemoryIndex(channelDir: string): Promise<MemoryEntry[]>;
61
- export declare function readMemoryTombstoneRecords(channelDir: string): Promise<MemoryTombstoneRecord[]>;
62
- export declare function appendMemoryTombstoneRecord(channelDir: string, record: MemoryTombstoneRecord): Promise<void>;
63
- export declare function isDescriptionTombstoned(channelDir: string, description: string): Promise<boolean>;
60
+ export declare function rebuildMemoryIndex(deskDir: string): Promise<MemoryEntry[]>;
61
+ export declare function readMemoryTombstoneRecords(deskDir: string): Promise<MemoryTombstoneRecord[]>;
62
+ export declare function appendMemoryTombstoneRecord(deskDir: string, record: MemoryTombstoneRecord): Promise<void>;
63
+ export declare function isDescriptionTombstoned(deskDir: string, description: string): Promise<boolean>;
64
64
  /** Cancel the tombstone for `description` (append-only): a user re-authorized the fact. */
65
- export declare function revokeMemoryTombstone(channelDir: string, description: string, today?: string): Promise<void>;
65
+ export declare function revokeMemoryTombstone(deskDir: string, description: string, today?: string): Promise<void>;
66
66
  /**
67
67
  * Mechanical store mutations. Policy — per-pass caps, confidence bars, user-source protection —
68
68
  * lives in the reflect pass (spec 050, D7), never here.
@@ -105,7 +105,7 @@ export interface ApplyMemoryOpsResult {
105
105
  used: string;
106
106
  }>;
107
107
  }
108
- export declare function applyMemoryOps(channelDir: string, ops: MemoryStoreOp[], options?: {
108
+ export declare function applyMemoryOps(deskDir: string, ops: MemoryStoreOp[], options?: {
109
109
  today?: string;
110
110
  }): Promise<ApplyMemoryOpsResult>;
111
111
  /**
@@ -114,4 +114,4 @@ export declare function applyMemoryOps(channelDir: string, ops: MemoryStoreOp[],
114
114
  * tokens on an entry about to disappear. No tombstone: probation lapsing means "not needed
115
115
  * right now", not "must never be learned again" (037, D8's rationale, carried over unchanged).
116
116
  */
117
- export declare function expireProbationaryEntries(channelDir: string, today?: string): Promise<string[]>;
117
+ export declare function expireProbationaryEntries(deskDir: string, today?: string): Promise<string[]>;
@@ -13,17 +13,17 @@ export const MEMORY_TYPE_ORDER = MEMORY_TYPES;
13
13
  const NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
14
14
  const MAX_NAME_LENGTH = 60;
15
15
  const MAX_SLUG_WORDS = 6;
16
- export function getChannelMemoryDir(channelDir) {
17
- return join(channelDir, "memory");
16
+ export function getMemoryDir(deskDir) {
17
+ return join(deskDir, "memory");
18
18
  }
19
- export function getChannelMemoryIndexPath(channelDir) {
20
- return join(channelDir, "MEMORY.md");
19
+ export function getMemoryIndexPath(deskDir) {
20
+ return join(deskDir, "MEMORY.md");
21
21
  }
22
- export function getMemoryEntryPath(channelDir, name) {
23
- return join(getChannelMemoryDir(channelDir), `${name}.md`);
22
+ export function getMemoryEntryPath(deskDir, name) {
23
+ return join(getMemoryDir(deskDir), `${name}.md`);
24
24
  }
25
- function getTombstonesPath(channelDir) {
26
- return join(getChannelMemoryDir(channelDir), ".tombstones.jsonl");
25
+ function getTombstonesPath(deskDir) {
26
+ return join(getMemoryDir(deskDir), ".tombstones.jsonl");
27
27
  }
28
28
  // -------------------------------------------------------------------------------------------------
29
29
  // Names
@@ -157,8 +157,8 @@ const fileCache = new Map();
157
157
  export function clearMemoryStoreCache() {
158
158
  fileCache.clear();
159
159
  }
160
- export async function listMemoryEntries(channelDir) {
161
- const dir = getChannelMemoryDir(channelDir);
160
+ export async function listMemoryEntries(deskDir) {
161
+ const dir = getMemoryDir(deskDir);
162
162
  let names;
163
163
  try {
164
164
  names = await readdir(dir);
@@ -199,8 +199,8 @@ export async function listMemoryEntries(channelDir) {
199
199
  entries.sort((a, b) => a.name.localeCompare(b.name));
200
200
  return entries;
201
201
  }
202
- export async function readMemoryEntry(channelDir, name) {
203
- const path = getMemoryEntryPath(channelDir, name);
202
+ export async function readMemoryEntry(deskDir, name) {
203
+ const path = getMemoryEntryPath(deskDir, name);
204
204
  const raw = await readOptionalTextFile(path);
205
205
  if (!raw) {
206
206
  return undefined;
@@ -218,7 +218,7 @@ export async function readMemoryEntry(channelDir, name) {
218
218
  // Index generation
219
219
  // -------------------------------------------------------------------------------------------------
220
220
  export function renderMemoryIndex(entries) {
221
- const lines = ["# Channel Memory", ""];
221
+ const lines = ["# Desk Memory", ""];
222
222
  for (const type of MEMORY_TYPE_ORDER) {
223
223
  const group = entries.filter((entry) => entry.type === type).sort((a, b) => a.name.localeCompare(b.name));
224
224
  if (group.length === 0) {
@@ -231,7 +231,7 @@ export function renderMemoryIndex(entries) {
231
231
  lines.push("");
232
232
  }
233
233
  if (lines.length === 2) {
234
- lines.push("_No stored memory in this channel yet._", "");
234
+ lines.push("_No stored memory in this desk yet._", "");
235
235
  }
236
236
  return `${lines.join("\n").trimEnd()}\n`;
237
237
  }
@@ -239,16 +239,16 @@ export function renderIndexLine(entry) {
239
239
  const marker = entry.body.trim() ? " (+)" : "";
240
240
  return `- ${entry.name} — ${entry.description}${marker}`;
241
241
  }
242
- export async function rebuildMemoryIndex(channelDir) {
243
- const entries = await listMemoryEntries(channelDir);
244
- await writeFileAtomically(getChannelMemoryIndexPath(channelDir), renderMemoryIndex(entries));
242
+ export async function rebuildMemoryIndex(deskDir) {
243
+ const entries = await listMemoryEntries(deskDir);
244
+ await writeFileAtomically(getMemoryIndexPath(deskDir), renderMemoryIndex(entries));
245
245
  return entries;
246
246
  }
247
247
  // -------------------------------------------------------------------------------------------------
248
248
  // Tombstones
249
249
  // -------------------------------------------------------------------------------------------------
250
- export async function readMemoryTombstoneRecords(channelDir) {
251
- const raw = await readOptionalTextFile(getTombstonesPath(channelDir));
250
+ export async function readMemoryTombstoneRecords(deskDir) {
251
+ const raw = await readOptionalTextFile(getTombstonesPath(deskDir));
252
252
  if (!raw) {
253
253
  return [];
254
254
  }
@@ -269,15 +269,15 @@ export async function readMemoryTombstoneRecords(channelDir) {
269
269
  }
270
270
  return records;
271
271
  }
272
- export async function appendMemoryTombstoneRecord(channelDir, record) {
273
- const path = getTombstonesPath(channelDir);
274
- await mkdir(getChannelMemoryDir(channelDir), { recursive: true });
272
+ export async function appendMemoryTombstoneRecord(deskDir, record) {
273
+ const path = getTombstonesPath(deskDir);
274
+ await mkdir(getMemoryDir(deskDir), { recursive: true });
275
275
  await appendFile(path, `${JSON.stringify(record)}\n`, "utf-8");
276
276
  }
277
- export async function isDescriptionTombstoned(channelDir, description) {
277
+ export async function isDescriptionTombstoned(deskDir, description) {
278
278
  const hash = hashMemoryContent(description);
279
279
  let tombstoned = false;
280
- for (const record of await readMemoryTombstoneRecords(channelDir)) {
280
+ for (const record of await readMemoryTombstoneRecords(deskDir)) {
281
281
  if (record.contentHash === hash) {
282
282
  tombstoned = record.revoked !== true;
283
283
  }
@@ -285,15 +285,15 @@ export async function isDescriptionTombstoned(channelDir, description) {
285
285
  return tombstoned;
286
286
  }
287
287
  /** Cancel the tombstone for `description` (append-only): a user re-authorized the fact. */
288
- export async function revokeMemoryTombstone(channelDir, description, today = localDayKey()) {
289
- await appendMemoryTombstoneRecord(channelDir, {
288
+ export async function revokeMemoryTombstone(deskDir, description, today = localDayKey()) {
289
+ await appendMemoryTombstoneRecord(deskDir, {
290
290
  contentHash: hashMemoryContent(description),
291
291
  deletedAt: today,
292
292
  reason: "re-authorized by explicit user save",
293
293
  revoked: true,
294
294
  });
295
295
  }
296
- export async function applyMemoryOps(channelDir, ops, options = {}) {
296
+ export async function applyMemoryOps(deskDir, ops, options = {}) {
297
297
  const today = options.today ?? localDayKey();
298
298
  const result = {
299
299
  added: [],
@@ -308,8 +308,8 @@ export async function applyMemoryOps(channelDir, ops, options = {}) {
308
308
  if (ops.length === 0) {
309
309
  return result;
310
310
  }
311
- await mkdir(getChannelMemoryDir(channelDir), { recursive: true });
312
- const existing = await listMemoryEntries(channelDir);
311
+ await mkdir(getMemoryDir(deskDir), { recursive: true });
312
+ const existing = await listMemoryEntries(deskDir);
313
313
  const byName = new Map(existing.map((entry) => [entry.name, entry]));
314
314
  const liveNames = new Set(byName.keys());
315
315
  for (const op of ops) {
@@ -322,7 +322,7 @@ export async function applyMemoryOps(channelDir, ops, options = {}) {
322
322
  }
323
323
  if (entry.expires) {
324
324
  const next = { ...entry, expires: undefined, updated: today };
325
- await writeEntryFile(channelDir, next);
325
+ await writeEntryFile(deskDir, next);
326
326
  byName.set(name, next);
327
327
  }
328
328
  result.touched.push(name);
@@ -343,13 +343,13 @@ export async function applyMemoryOps(channelDir, ops, options = {}) {
343
343
  // Recording the tombstone before the delete means the worst case after a failure here is
344
344
  // the reverse — file still present, already tombstoned — which is recoverable: the file
345
345
  // is still there to retry deleting, and it is already protected from re-learning either way.
346
- await appendMemoryTombstoneRecord(channelDir, {
346
+ await appendMemoryTombstoneRecord(deskDir, {
347
347
  name: op.name,
348
348
  contentHash: hashMemoryContent(entry.description),
349
349
  deletedAt: today,
350
350
  reason: op.reason?.trim() || "deleted",
351
351
  });
352
- await rm(getMemoryEntryPath(channelDir, op.name), { force: true });
352
+ await rm(getMemoryEntryPath(deskDir, op.name), { force: true });
353
353
  byName.delete(op.name);
354
354
  liveNames.delete(op.name);
355
355
  result.deleted.push(op.name);
@@ -375,7 +375,7 @@ export async function applyMemoryOps(channelDir, ops, options = {}) {
375
375
  expires: op.expires === undefined ? entry.expires : op.expires === null ? undefined : op.expires,
376
376
  malformed: false,
377
377
  };
378
- await writeEntryFile(channelDir, next);
378
+ await writeEntryFile(deskDir, next);
379
379
  byName.set(op.name, next);
380
380
  result.updated.push(op.name);
381
381
  continue;
@@ -393,7 +393,7 @@ export async function applyMemoryOps(channelDir, ops, options = {}) {
393
393
  // the user deleted. It must not also block the user's own explicit `memory_save` (source
394
394
  // "user") — that path is the user re-authorizing the fact, and a successful save here
395
395
  // revokes the tombstone so the background pass stops fighting it too.
396
- const tombstoned = await isDescriptionTombstoned(channelDir, description);
396
+ const tombstoned = await isDescriptionTombstoned(deskDir, description);
397
397
  if (tombstoned && op.source !== "user") {
398
398
  result.skippedTombstone++;
399
399
  continue;
@@ -414,20 +414,20 @@ export async function applyMemoryOps(channelDir, ops, options = {}) {
414
414
  body: op.details?.trim() ?? "",
415
415
  malformed: false,
416
416
  };
417
- await writeEntryFile(channelDir, entry);
417
+ await writeEntryFile(deskDir, entry);
418
418
  if (tombstoned && op.source === "user") {
419
- await revokeMemoryTombstone(channelDir, description, today);
419
+ await revokeMemoryTombstone(deskDir, description, today);
420
420
  }
421
421
  byName.set(name, entry);
422
422
  liveNames.add(name);
423
423
  result.added.push(name);
424
424
  }
425
- await rebuildMemoryIndex(channelDir);
425
+ await rebuildMemoryIndex(deskDir);
426
426
  return result;
427
427
  }
428
- async function writeEntryFile(channelDir, entry) {
429
- await mkdir(getChannelMemoryDir(channelDir), { recursive: true });
430
- await writeFileAtomically(getMemoryEntryPath(channelDir, entry.name), serializeMemoryEntry(entry));
428
+ async function writeEntryFile(deskDir, entry) {
429
+ await mkdir(getMemoryDir(deskDir), { recursive: true });
430
+ await writeFileAtomically(getMemoryEntryPath(deskDir, entry.name), serializeMemoryEntry(entry));
431
431
  }
432
432
  /**
433
433
  * Spec 050, D6/D8: a probationary entry nobody touched before `expires` is removed —
@@ -435,15 +435,15 @@ async function writeEntryFile(channelDir, entry) {
435
435
  * tokens on an entry about to disappear. No tombstone: probation lapsing means "not needed
436
436
  * right now", not "must never be learned again" (037, D8's rationale, carried over unchanged).
437
437
  */
438
- export async function expireProbationaryEntries(channelDir, today = localDayKey()) {
439
- const entries = await listMemoryEntries(channelDir);
438
+ export async function expireProbationaryEntries(deskDir, today = localDayKey()) {
439
+ const entries = await listMemoryEntries(deskDir);
440
440
  const expired = entries.filter((entry) => entry.expires && entry.expires < today);
441
441
  if (expired.length === 0) {
442
442
  return [];
443
443
  }
444
444
  for (const entry of expired) {
445
- await rm(getMemoryEntryPath(channelDir, entry.name), { force: true });
445
+ await rm(getMemoryEntryPath(deskDir, entry.name), { force: true });
446
446
  }
447
- await rebuildMemoryIndex(channelDir);
447
+ await rebuildMemoryIndex(deskDir);
448
448
  return expired.map((entry) => entry.name);
449
449
  }
package/dist/paths.d.ts CHANGED
@@ -8,6 +8,8 @@ export declare const DEFAULT_APP_HOME_DIR: string;
8
8
  export declare const APP_HOME_DIR: string;
9
9
  export declare const WORKSPACE_DIR: string;
10
10
  export declare const STATE_DIR: string;
11
+ /** Where the daemon's Web API listens on this machine (spec 061, D4): the terminal connects here. */
12
+ export declare const webapiSocketPath: (appHomeDir: string) => string;
11
13
  export declare const EVENT_STATE_DIR: string;
12
14
  export declare const EVENT_HISTORY_PATH: string;
13
15
  export declare const LOG_STATE_DIR: string;
package/dist/paths.js CHANGED
@@ -26,6 +26,8 @@ export const DEFAULT_APP_HOME_DIR = join(homedir(), `.${APP_NAME}`);
26
26
  export const APP_HOME_DIR = process.env.PIPICLAW_HOME ?? DEFAULT_APP_HOME_DIR;
27
27
  export const WORKSPACE_DIR = join(APP_HOME_DIR, "workspace");
28
28
  export const STATE_DIR = join(APP_HOME_DIR, "state");
29
+ /** Where the daemon's Web API listens on this machine (spec 061, D4): the terminal connects here. */
30
+ export const webapiSocketPath = (appHomeDir) => join(appHomeDir, "state", "webapi", "api.sock");
29
31
  export const EVENT_STATE_DIR = join(STATE_DIR, "events");
30
32
  export const EVENT_HISTORY_PATH = join(EVENT_STATE_DIR, "history.jsonl");
31
33
  export const LOG_STATE_DIR = join(STATE_DIR, "logs");