@sema-agent/server 1.323.0 → 2.0.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 (539) hide show
  1. package/dist/approval-hmac.d.ts +40 -0
  2. package/dist/approval-hmac.js +67 -0
  3. package/dist/approval.d.ts +31 -0
  4. package/dist/approval.js +72 -4
  5. package/dist/audit.d.ts +26 -0
  6. package/dist/audit.js +40 -1
  7. package/dist/auth-bridge.d.ts +10 -0
  8. package/dist/auth-bridge.js +47 -4
  9. package/dist/auth-keys.d.ts +19 -0
  10. package/dist/auth-keys.js +13 -0
  11. package/dist/bake-runner/main.d.ts +5 -0
  12. package/dist/bake-runner/main.js +43 -4
  13. package/dist/bake-runner/protocol.d.ts +57 -0
  14. package/dist/bake-runner/protocol.js +58 -3
  15. package/dist/bake-runner/runner.d.ts +54 -0
  16. package/dist/bake-runner/runner.js +87 -5
  17. package/dist/bench/l8/artifact.d.ts +63 -0
  18. package/dist/bench/l8/artifact.js +61 -2
  19. package/dist/bench/l8/escape.d.ts +36 -0
  20. package/dist/bench/l8/escape.js +25 -0
  21. package/dist/bench/l8/index.d.ts +14 -0
  22. package/dist/bench/l8/index.js +14 -0
  23. package/dist/bench/l8/probes.d.ts +74 -0
  24. package/dist/bench/l8/probes.js +60 -0
  25. package/dist/bench/l8/run-probes.d.ts +43 -0
  26. package/dist/bench/l8/run-probes.js +45 -2
  27. package/dist/bench/s1/arms.d.ts +126 -0
  28. package/dist/bench/s1/arms.js +188 -13
  29. package/dist/bench/s1/live-deps.d.ts +66 -0
  30. package/dist/bench/s1/live-deps.js +249 -11
  31. package/dist/bench/s1/oracle.d.ts +49 -0
  32. package/dist/bench/s1/oracle.js +36 -1
  33. package/dist/bench/s1/repair-oracle-adapter.d.ts +33 -0
  34. package/dist/bench/s1/repair-oracle-adapter.js +30 -0
  35. package/dist/bench/s1/reviewer.d.ts +38 -0
  36. package/dist/bench/s1/reviewer.js +34 -0
  37. package/dist/bench/s1/row.d.ts +77 -0
  38. package/dist/bench/s1/row.js +62 -0
  39. package/dist/bench/s1/run-firm.d.ts +47 -0
  40. package/dist/bench/s1/run-firm.js +70 -4
  41. package/dist/bench/s1/runner-ctx.d.ts +71 -0
  42. package/dist/bench/s1/runner-ctx.js +36 -0
  43. package/dist/bench/s1/tasks.d.ts +108 -0
  44. package/dist/bench/s1/tasks.js +115 -0
  45. package/dist/boot-reclaim.d.ts +19 -0
  46. package/dist/boot-reclaim.js +20 -0
  47. package/dist/brain.d.ts +25 -0
  48. package/dist/brain.js +61 -1
  49. package/dist/budget.d.ts +66 -0
  50. package/dist/budget.js +128 -4
  51. package/dist/capabilities/builtin-tools.d.ts +3 -0
  52. package/dist/capabilities/builtin-tools.js +3 -0
  53. package/dist/capabilities/center-plugins.d.ts +17 -1
  54. package/dist/capabilities/center-plugins.js +45 -4
  55. package/dist/capabilities/center-prompts.d.ts +46 -0
  56. package/dist/capabilities/center-prompts.js +57 -3
  57. package/dist/capabilities/code-review-council.d.ts +28 -0
  58. package/dist/capabilities/code-review-council.js +40 -7
  59. package/dist/capabilities/collab-wire.d.ts +2 -0
  60. package/dist/capabilities/collab-workflows.d.ts +7 -0
  61. package/dist/capabilities/collab-workflows.js +44 -1
  62. package/dist/capabilities/oa-tools.d.ts +6 -0
  63. package/dist/capabilities/oa-tools.js +10 -0
  64. package/dist/capabilities/prompt.d.ts +14 -0
  65. package/dist/capabilities/prompt.js +14 -0
  66. package/dist/capabilities/prompts/code-review.d.ts +14 -0
  67. package/dist/capabilities/prompts/code-review.js +14 -0
  68. package/dist/capabilities/prompts/identity.d.ts +6 -0
  69. package/dist/capabilities/prompts/identity.js +6 -0
  70. package/dist/capabilities/prompts/team.d.ts +4 -0
  71. package/dist/capabilities/prompts/team.js +4 -0
  72. package/dist/capabilities/repo-tools.d.ts +11 -0
  73. package/dist/capabilities/repo-tools.js +8 -0
  74. package/dist/capabilities/sandbox-file-send.d.ts +95 -0
  75. package/dist/capabilities/sandbox-file-send.js +91 -3
  76. package/dist/capabilities/scenarios.d.ts +130 -0
  77. package/dist/capabilities/scenarios.js +180 -7
  78. package/dist/capabilities/select-environment-tool.d.ts +7 -0
  79. package/dist/capabilities/select-environment-tool.js +30 -0
  80. package/dist/capabilities/send-user-file-tool.d.ts +33 -0
  81. package/dist/capabilities/send-user-file-tool.js +65 -1
  82. package/dist/capabilities/skills.d.ts +29 -0
  83. package/dist/capabilities/skills.js +13 -2
  84. package/dist/capabilities/team.d.ts +22 -0
  85. package/dist/capabilities/team.js +22 -2
  86. package/dist/capabilities/tool-defer.d.ts +26 -0
  87. package/dist/capabilities/tool-defer.js +3 -0
  88. package/dist/config-center/apply-effective.d.ts +65 -0
  89. package/dist/config-center/apply-effective.js +204 -12
  90. package/dist/config-center/http-client.d.ts +34 -0
  91. package/dist/config-center/http-client.js +68 -0
  92. package/dist/config-center/restart-signal.d.ts +22 -0
  93. package/dist/config-center/restart-signal.js +39 -0
  94. package/dist/config-center/skills-mcp.d.ts +20 -1
  95. package/dist/config-center/skills-mcp.js +42 -7
  96. package/dist/config-center/types.d.ts +92 -1
  97. package/dist/config-lkg.d.ts +12 -0
  98. package/dist/config-lkg.js +41 -0
  99. package/dist/config-provider.d.ts +78 -0
  100. package/dist/config-provider.js +165 -2
  101. package/dist/config-types.d.ts +546 -0
  102. package/dist/config.d.ts +64 -0
  103. package/dist/config.js +455 -60
  104. package/dist/degenerate-instrument.d.ts +38 -0
  105. package/dist/degenerate-instrument.js +55 -3
  106. package/dist/elicitation.d.ts +39 -0
  107. package/dist/elicitation.js +87 -3
  108. package/dist/env-facts.d.ts +61 -0
  109. package/dist/env-facts.js +73 -7
  110. package/dist/fleet/fleet-bus.d.ts +185 -0
  111. package/dist/fleet/fleet-bus.js +333 -27
  112. package/dist/fleet/subagent-tail-bus.d.ts +11 -0
  113. package/dist/fleet/subagent-tail-bus.js +33 -2
  114. package/dist/fleet-client.d.ts +38 -0
  115. package/dist/fleet-client.js +44 -9
  116. package/dist/fleet-lease.d.ts +46 -0
  117. package/dist/fleet-lease.js +73 -5
  118. package/dist/hooks/branch-transcript.d.ts +8 -0
  119. package/dist/hooks/branch-transcript.js +33 -0
  120. package/dist/hooks/cc-stop-prompt.d.ts +42 -0
  121. package/dist/hooks/cc-stop-prompt.js +43 -1
  122. package/dist/hooks/hook-llm.d.ts +15 -0
  123. package/dist/hooks/hook-llm.js +47 -0
  124. package/dist/hooks/hook-runner.d.ts +89 -0
  125. package/dist/hooks/hook-runner.js +327 -18
  126. package/dist/http/idempotency.d.ts +31 -0
  127. package/dist/http/idempotency.js +34 -0
  128. package/dist/http/principal-gate.d.ts +17 -0
  129. package/dist/http/principal-gate.js +35 -3
  130. package/dist/http/route-ctx.d.ts +36 -0
  131. package/dist/http/routes/approvals-assistant.d.ts +25 -0
  132. package/dist/http/routes/approvals-assistant.js +253 -23
  133. package/dist/http/routes/attachments.js +22 -4
  134. package/dist/http/routes/capabilities.d.ts +7 -0
  135. package/dist/http/routes/capabilities.js +202 -1
  136. package/dist/http/routes/fleet.d.ts +6 -0
  137. package/dist/http/routes/fleet.js +94 -5
  138. package/dist/http/routes/images.d.ts +17 -0
  139. package/dist/http/routes/images.js +222 -14
  140. package/dist/http/routes/leader.d.ts +7 -0
  141. package/dist/http/routes/leader.js +10 -0
  142. package/dist/http/routes/memory-policy.d.ts +6 -0
  143. package/dist/http/routes/memory-policy.js +38 -6
  144. package/dist/http/routes/notify-wake.d.ts +10 -0
  145. package/dist/http/routes/notify-wake.js +19 -3
  146. package/dist/http/routes/observability.d.ts +6 -0
  147. package/dist/http/routes/observability.js +19 -2
  148. package/dist/http/routes/runs.d.ts +15 -0
  149. package/dist/http/routes/runs.js +464 -41
  150. package/dist/http/routes/session-sync.d.ts +15 -0
  151. package/dist/http/routes/session-sync.js +229 -19
  152. package/dist/http/routes/sessions-list.d.ts +6 -0
  153. package/dist/http/routes/sessions-list.js +35 -4
  154. package/dist/http/routes/sessions.d.ts +14 -0
  155. package/dist/http/routes/sessions.js +176 -31
  156. package/dist/http/routes/side-query.d.ts +8 -0
  157. package/dist/http/routes/side-query.js +26 -1
  158. package/dist/http/routes/tasks.d.ts +18 -0
  159. package/dist/http/routes/tasks.js +501 -38
  160. package/dist/http/routes/trace-usage.d.ts +10 -0
  161. package/dist/http/routes/trace-usage.js +66 -14
  162. package/dist/http/routes/workflows.d.ts +12 -0
  163. package/dist/http/routes/workflows.js +180 -19
  164. package/dist/http/run-meta.d.ts +11 -0
  165. package/dist/http/run-meta.js +6 -0
  166. package/dist/http/send.d.ts +19 -0
  167. package/dist/http/send.js +11 -0
  168. package/dist/http/server.d.ts +255 -0
  169. package/dist/http/server.js +921 -75
  170. package/dist/http/sse-log.d.ts +15 -0
  171. package/dist/http/sse-log.js +16 -0
  172. package/dist/http/tar.d.ts +9 -0
  173. package/dist/http/tar.js +21 -5
  174. package/dist/http/wire-gate.d.ts +9 -0
  175. package/dist/http/wire-gate.js +9 -0
  176. package/dist/http/wire-types.d.ts +187 -0
  177. package/dist/http/workspace-content.d.ts +8 -0
  178. package/dist/http/workspace-content.js +10 -0
  179. package/dist/images/bake-validate.d.ts +63 -0
  180. package/dist/images/bake-validate.js +71 -1
  181. package/dist/images/manifest.d.ts +19 -0
  182. package/dist/images/manifest.js +6 -1
  183. package/dist/index.d.ts +1 -5
  184. package/dist/index.js +10 -5
  185. package/dist/key-resolver.d.ts +23 -0
  186. package/dist/key-resolver.js +27 -2
  187. package/dist/leader/diffout.d.ts +23 -0
  188. package/dist/leader/diffout.js +8 -1
  189. package/dist/leader/diffup.d.ts +32 -0
  190. package/dist/leader/diffup.js +43 -0
  191. package/dist/leader/endpoint.d.ts +20 -0
  192. package/dist/leader/endpoint.js +25 -2
  193. package/dist/leader/fanout.d.ts +60 -0
  194. package/dist/leader/fanout.js +29 -3
  195. package/dist/leader/grader-env-factory.d.ts +74 -0
  196. package/dist/leader/grader-env-factory.js +62 -3
  197. package/dist/leader/leader.d.ts +97 -0
  198. package/dist/leader/leader.js +151 -4
  199. package/dist/leader/merge.d.ts +94 -0
  200. package/dist/leader/merge.js +112 -9
  201. package/dist/leader/planner.d.ts +52 -0
  202. package/dist/leader/planner.js +47 -3
  203. package/dist/leader/repair-oracle.d.ts +61 -0
  204. package/dist/leader/repair-oracle.js +59 -1
  205. package/dist/leader/repair-wire.d.ts +78 -0
  206. package/dist/leader/repair-wire.js +79 -2
  207. package/dist/leader/wire.d.ts +79 -0
  208. package/dist/leader/wire.js +255 -8
  209. package/dist/lsp/e2b-bridge.d.ts +16 -0
  210. package/dist/lsp/e2b-bridge.js +32 -4
  211. package/dist/lsp/e2b-manager.d.ts +10 -0
  212. package/dist/lsp/e2b-manager.js +18 -2
  213. package/dist/lsp/lsp-frames.d.ts +12 -0
  214. package/dist/lsp/lsp-frames.js +12 -0
  215. package/dist/lsp/manager.d.ts +12 -0
  216. package/dist/lsp/manager.js +35 -2
  217. package/dist/lsp/types.d.ts +10 -0
  218. package/dist/lsp/ws-transport.d.ts +12 -0
  219. package/dist/lsp/ws-transport.js +53 -5
  220. package/dist/lsp-evict.d.ts +14 -0
  221. package/dist/lsp-evict.js +15 -1
  222. package/dist/main.js +2132 -96
  223. package/dist/memory-export.d.ts +1 -0
  224. package/dist/memory-export.js +4 -0
  225. package/dist/memory-scope.d.ts +49 -0
  226. package/dist/memory-scope.js +87 -4
  227. package/dist/memory-sync-client.d.ts +24 -0
  228. package/dist/memory-sync-client.js +41 -2
  229. package/dist/memory-sync.d.ts +23 -0
  230. package/dist/memory-sync.js +70 -1
  231. package/dist/model-select.d.ts +39 -0
  232. package/dist/model-select.js +42 -1
  233. package/dist/observability/cost-quota.d.ts +20 -0
  234. package/dist/observability/cost-quota.js +4 -0
  235. package/dist/observability/cost-taxonomy.d.ts +45 -0
  236. package/dist/observability/cost-taxonomy.js +34 -0
  237. package/dist/observability/logger.d.ts +1 -0
  238. package/dist/observability/logger.js +6 -0
  239. package/dist/observability/metrics.d.ts +13 -0
  240. package/dist/observability/metrics.js +63 -0
  241. package/dist/observability/otel-exporter.d.ts +9 -0
  242. package/dist/observability/otel-exporter.js +11 -3
  243. package/dist/observability/principal-context.d.ts +9 -0
  244. package/dist/observability/principal-context.js +9 -0
  245. package/dist/observability/prompt-manifest.d.ts +37 -0
  246. package/dist/observability/prompt-manifest.js +35 -1
  247. package/dist/observability/rate-limit.d.ts +10 -0
  248. package/dist/observability/rate-limit.js +1 -0
  249. package/dist/observability/tool-trace.d.ts +24 -0
  250. package/dist/observability/tool-trace.js +41 -1
  251. package/dist/orchestration/hardened-vm-runner.d.ts +107 -0
  252. package/dist/orchestration/hardened-vm-runner.js +119 -4
  253. package/dist/orchestration/hardened-vm-worker-runner.d.ts +14 -0
  254. package/dist/orchestration/hardened-vm-worker-runner.js +26 -1
  255. package/dist/orchestration/hardened-vm-worker.js +27 -0
  256. package/dist/orchestration/subagent-steer.d.ts +44 -0
  257. package/dist/orchestration/subagent-steer.js +45 -1
  258. package/dist/orchestration/workflow-agent-steer.d.ts +54 -0
  259. package/dist/orchestration/workflow-agent-steer.js +80 -1
  260. package/dist/orchestration/workflow-completion-inbox.d.ts +189 -2
  261. package/dist/orchestration/workflow-completion-inbox.js +283 -32
  262. package/dist/orchestration/workflow-notify-journal.d.ts +132 -1
  263. package/dist/orchestration/workflow-notify-journal.js +187 -13
  264. package/dist/parked-decide.d.ts +61 -0
  265. package/dist/parked-decide.js +58 -1
  266. package/dist/per-task-image.d.ts +54 -0
  267. package/dist/per-task-image.js +41 -0
  268. package/dist/plan-cache-probe.d.ts +35 -0
  269. package/dist/plan-cache-probe.js +18 -3
  270. package/dist/plugins/approval-exemption-store.d.ts +7 -0
  271. package/dist/plugins/approval-exemption-store.js +28 -2
  272. package/dist/plugins/approval-store-sql.d.ts +64 -0
  273. package/dist/plugins/approval-store-sql.js +32 -0
  274. package/dist/plugins/background-agent-store-sql.d.ts +55 -0
  275. package/dist/plugins/background-agent-store-sql.js +91 -4
  276. package/dist/plugins/background-shell-support.d.ts +98 -0
  277. package/dist/plugins/background-shell-support.js +117 -13
  278. package/dist/plugins/blob-backend.d.ts +104 -0
  279. package/dist/plugins/blob-backend.js +163 -6
  280. package/dist/plugins/breaker-state-sql.d.ts +65 -1
  281. package/dist/plugins/breaker-state-sql.js +46 -8
  282. package/dist/plugins/caching-session-store.d.ts +42 -0
  283. package/dist/plugins/caching-session-store.js +63 -3
  284. package/dist/plugins/checkpoint-store-sql.d.ts +179 -0
  285. package/dist/plugins/checkpoint-store-sql.js +239 -11
  286. package/dist/plugins/file-outcome-sink.d.ts +4 -0
  287. package/dist/plugins/file-outcome-sink.js +9 -0
  288. package/dist/plugins/file-resume-anchor-store.d.ts +20 -0
  289. package/dist/plugins/file-resume-anchor-store.js +43 -4
  290. package/dist/plugins/file-run-store.d.ts +90 -0
  291. package/dist/plugins/file-run-store.js +145 -13
  292. package/dist/plugins/file-snapshot-store-sql.d.ts +133 -1
  293. package/dist/plugins/file-snapshot-store-sql.js +178 -10
  294. package/dist/plugins/file-workflow-journal-store.d.ts +10 -0
  295. package/dist/plugins/file-workflow-journal-store.js +10 -0
  296. package/dist/plugins/fork-routing-session-store.d.ts +47 -0
  297. package/dist/plugins/fork-routing-session-store.js +51 -3
  298. package/dist/plugins/host-platform.d.ts +69 -0
  299. package/dist/plugins/host-platform.js +81 -2
  300. package/dist/plugins/image-bake-store-sql.d.ts +136 -1
  301. package/dist/plugins/image-bake-store-sql.js +241 -7
  302. package/dist/plugins/image-index-sql.d.ts +46 -0
  303. package/dist/plugins/image-index-sql.js +113 -4
  304. package/dist/plugins/k8s-bg-scripts.d.ts +34 -0
  305. package/dist/plugins/k8s-bg-scripts.js +88 -4
  306. package/dist/plugins/k8s-exec-protocol.d.ts +33 -0
  307. package/dist/plugins/k8s-exec-protocol.js +41 -0
  308. package/dist/plugins/local-checkpoint-store.d.ts +40 -0
  309. package/dist/plugins/local-checkpoint-store.js +86 -7
  310. package/dist/plugins/local-session-store.d.ts +157 -0
  311. package/dist/plugins/local-session-store.js +289 -34
  312. package/dist/plugins/local-task-attachment-store.js +14 -2
  313. package/dist/plugins/mailbox-store-sql.d.ts +38 -0
  314. package/dist/plugins/mailbox-store-sql.js +39 -6
  315. package/dist/plugins/memory-engine-pg.d.ts +30 -0
  316. package/dist/plugins/memory-engine-pg.js +122 -4
  317. package/dist/plugins/memory-engine-tidb.d.ts +26 -0
  318. package/dist/plugins/memory-engine-tidb.js +115 -5
  319. package/dist/plugins/memory-engine-vector-util.d.ts +5 -0
  320. package/dist/plugins/memory-engine-vector-util.js +5 -0
  321. package/dist/plugins/memory-resume-anchor-store.d.ts +8 -0
  322. package/dist/plugins/memory-resume-anchor-store.js +17 -0
  323. package/dist/plugins/memory-run-store.d.ts +63 -0
  324. package/dist/plugins/memory-run-store.js +73 -8
  325. package/dist/plugins/memory-session-policy-store.d.ts +17 -0
  326. package/dist/plugins/memory-session-policy-store.js +17 -0
  327. package/dist/plugins/memory-sync-store-pg.d.ts +42 -0
  328. package/dist/plugins/memory-sync-store-pg.js +45 -2
  329. package/dist/plugins/memory-sync-store-tidb.d.ts +9 -0
  330. package/dist/plugins/memory-sync-store-tidb.js +31 -1
  331. package/dist/plugins/outcome-ledger-sql.d.ts +63 -0
  332. package/dist/plugins/outcome-ledger-sql.js +97 -3
  333. package/dist/plugins/pg-approval-store.d.ts +7 -0
  334. package/dist/plugins/pg-approval-store.js +7 -0
  335. package/dist/plugins/pg-breaker-state.d.ts +6 -0
  336. package/dist/plugins/pg-breaker-state.js +6 -0
  337. package/dist/plugins/pg-checkpoint-store.d.ts +8 -0
  338. package/dist/plugins/pg-checkpoint-store.js +8 -0
  339. package/dist/plugins/pg-cost-quota.d.ts +17 -0
  340. package/dist/plugins/pg-cost-quota.js +6 -0
  341. package/dist/plugins/pg-file-snapshot-store.d.ts +6 -0
  342. package/dist/plugins/pg-file-snapshot-store.js +6 -0
  343. package/dist/plugins/pg-image-bake.d.ts +9 -0
  344. package/dist/plugins/pg-image-bake.js +9 -0
  345. package/dist/plugins/pg-image-index.d.ts +9 -0
  346. package/dist/plugins/pg-image-index.js +9 -0
  347. package/dist/plugins/pg-outcome-ledger.d.ts +9 -0
  348. package/dist/plugins/pg-outcome-ledger.js +9 -0
  349. package/dist/plugins/pg-pool.d.ts +50 -0
  350. package/dist/plugins/pg-pool.js +78 -0
  351. package/dist/plugins/pg-query.d.ts +11 -0
  352. package/dist/plugins/pg-rate-limiter.d.ts +23 -0
  353. package/dist/plugins/pg-rate-limiter.js +12 -2
  354. package/dist/plugins/pg-resume-anchor-store.d.ts +5 -0
  355. package/dist/plugins/pg-resume-anchor-store.js +5 -0
  356. package/dist/plugins/pg-run-store.d.ts +7 -0
  357. package/dist/plugins/pg-run-store.js +7 -0
  358. package/dist/plugins/pg-safe-json.d.ts +13 -0
  359. package/dist/plugins/pg-safe-json.js +40 -4
  360. package/dist/plugins/pg-session-policy-store.d.ts +5 -0
  361. package/dist/plugins/pg-session-policy-store.js +5 -0
  362. package/dist/plugins/pg-session-storage.d.ts +72 -0
  363. package/dist/plugins/pg-session-storage.js +152 -20
  364. package/dist/plugins/pg-session-store.d.ts +10 -0
  365. package/dist/plugins/pg-session-store.js +10 -0
  366. package/dist/plugins/pg-tool-result-store.d.ts +7 -0
  367. package/dist/plugins/pg-tool-result-store.js +7 -0
  368. package/dist/plugins/pg-workflow-journal-store.d.ts +7 -0
  369. package/dist/plugins/pg-workflow-journal-store.js +7 -0
  370. package/dist/plugins/pg-workflow-run-store.d.ts +7 -0
  371. package/dist/plugins/pg-workflow-run-store.js +7 -0
  372. package/dist/plugins/posix-shell-fs.d.ts +3 -0
  373. package/dist/plugins/posix-shell-fs.js +31 -1
  374. package/dist/plugins/remote-env-adb.d.ts +25 -0
  375. package/dist/plugins/remote-env-adb.js +95 -12
  376. package/dist/plugins/remote-env-e2b.d.ts +146 -0
  377. package/dist/plugins/remote-env-e2b.js +371 -40
  378. package/dist/plugins/remote-env-file-error.d.ts +34 -0
  379. package/dist/plugins/remote-env-file-error.js +37 -0
  380. package/dist/plugins/remote-env-host.d.ts +151 -0
  381. package/dist/plugins/remote-env-host.js +468 -70
  382. package/dist/plugins/remote-env-k8s.d.ts +135 -0
  383. package/dist/plugins/remote-env-k8s.js +318 -32
  384. package/dist/plugins/remote-env-local-docker.d.ts +65 -0
  385. package/dist/plugins/remote-env-local-docker.js +149 -24
  386. package/dist/plugins/remote-env-ssh.d.ts +35 -0
  387. package/dist/plugins/remote-env-ssh.js +117 -20
  388. package/dist/plugins/remote-scratchpad.d.ts +38 -0
  389. package/dist/plugins/remote-scratchpad.js +32 -2
  390. package/dist/plugins/remote-shell.d.ts +22 -0
  391. package/dist/plugins/remote-shell.js +27 -1
  392. package/dist/plugins/resume-anchor-store-sql.d.ts +28 -0
  393. package/dist/plugins/resume-anchor-store-sql.js +11 -0
  394. package/dist/plugins/roster-store-sql.d.ts +27 -0
  395. package/dist/plugins/roster-store-sql.js +54 -0
  396. package/dist/plugins/run-store-sql.d.ts +194 -0
  397. package/dist/plugins/run-store-sql.js +210 -9
  398. package/dist/plugins/s3-presign.d.ts +20 -0
  399. package/dist/plugins/s3-presign.js +49 -2
  400. package/dist/plugins/scheduler-support.d.ts +12 -0
  401. package/dist/plugins/scheduler-support.js +75 -3
  402. package/dist/plugins/send-file-ledger.d.ts +15 -0
  403. package/dist/plugins/send-file-ledger.js +53 -4
  404. package/dist/plugins/send-user-file.d.ts +77 -0
  405. package/dist/plugins/send-user-file.js +92 -4
  406. package/dist/plugins/session-policy-store-sql.d.ts +15 -0
  407. package/dist/plugins/session-policy-store-sql.js +75 -3
  408. package/dist/plugins/session-store.d.ts +45 -0
  409. package/dist/plugins/session-store.js +51 -0
  410. package/dist/plugins/sql-driver.d.ts +77 -0
  411. package/dist/plugins/sql-driver.js +4 -0
  412. package/dist/plugins/sql-escape.d.ts +8 -0
  413. package/dist/plugins/sql-escape.js +8 -0
  414. package/dist/plugins/sql-row-helpers.d.ts +25 -0
  415. package/dist/plugins/sql-row-helpers.js +25 -0
  416. package/dist/plugins/store-backend.d.ts +103 -0
  417. package/dist/plugins/store-backend.js +120 -27
  418. package/dist/plugins/store-contracts.d.ts +62 -0
  419. package/dist/plugins/store-contracts.js +3 -0
  420. package/dist/plugins/task-attachment-store.d.ts +60 -0
  421. package/dist/plugins/task-attachment-store.js +49 -3
  422. package/dist/plugins/task-list-store-sql.d.ts +25 -0
  423. package/dist/plugins/task-list-store-sql.js +21 -0
  424. package/dist/plugins/tidb-approval-store.d.ts +6 -0
  425. package/dist/plugins/tidb-approval-store.js +6 -0
  426. package/dist/plugins/tidb-breaker-state.d.ts +5 -0
  427. package/dist/plugins/tidb-breaker-state.js +5 -0
  428. package/dist/plugins/tidb-checkpoint-store.d.ts +7 -0
  429. package/dist/plugins/tidb-checkpoint-store.js +7 -0
  430. package/dist/plugins/tidb-cost-quota.d.ts +6 -0
  431. package/dist/plugins/tidb-cost-quota.js +1 -0
  432. package/dist/plugins/tidb-file-snapshot-store.d.ts +6 -0
  433. package/dist/plugins/tidb-file-snapshot-store.js +6 -0
  434. package/dist/plugins/tidb-image-bake.d.ts +8 -0
  435. package/dist/plugins/tidb-image-bake.js +8 -0
  436. package/dist/plugins/tidb-image-index.d.ts +8 -0
  437. package/dist/plugins/tidb-image-index.js +8 -0
  438. package/dist/plugins/tidb-outcome-ledger.d.ts +10 -0
  439. package/dist/plugins/tidb-outcome-ledger.js +10 -0
  440. package/dist/plugins/tidb-pool.d.ts +56 -0
  441. package/dist/plugins/tidb-pool.js +181 -1
  442. package/dist/plugins/tidb-rate-limiter.d.ts +11 -0
  443. package/dist/plugins/tidb-rate-limiter.js +5 -2
  444. package/dist/plugins/tidb-resume-anchor-store.d.ts +5 -0
  445. package/dist/plugins/tidb-resume-anchor-store.js +5 -0
  446. package/dist/plugins/tidb-run-store.d.ts +7 -0
  447. package/dist/plugins/tidb-run-store.js +7 -0
  448. package/dist/plugins/tidb-session-policy-store.d.ts +5 -0
  449. package/dist/plugins/tidb-session-policy-store.js +5 -0
  450. package/dist/plugins/tidb-session-storage.d.ts +43 -0
  451. package/dist/plugins/tidb-session-storage.js +62 -3
  452. package/dist/plugins/tidb-session-store.d.ts +142 -0
  453. package/dist/plugins/tidb-session-store.js +264 -16
  454. package/dist/plugins/tidb-tool-result-store.d.ts +5 -0
  455. package/dist/plugins/tidb-tool-result-store.js +7 -0
  456. package/dist/plugins/tidb-workflow-journal-store.d.ts +7 -0
  457. package/dist/plugins/tidb-workflow-journal-store.js +7 -0
  458. package/dist/plugins/tidb-workflow-run-store.d.ts +8 -0
  459. package/dist/plugins/tidb-workflow-run-store.js +8 -0
  460. package/dist/plugins/tool-result-store-sql.d.ts +58 -0
  461. package/dist/plugins/tool-result-store-sql.js +38 -2
  462. package/dist/plugins/web-search.d.ts +35 -0
  463. package/dist/plugins/web-search.js +45 -9
  464. package/dist/plugins/workflow-journal-limits.d.ts +10 -0
  465. package/dist/plugins/workflow-journal-limits.js +10 -0
  466. package/dist/plugins/workflow-journal-store-sql.d.ts +78 -0
  467. package/dist/plugins/workflow-journal-store-sql.js +58 -2
  468. package/dist/plugins/workflow-run-store-sql.d.ts +84 -0
  469. package/dist/plugins/workflow-run-store-sql.js +84 -6
  470. package/dist/plugins/worktree-isolation.d.ts +45 -0
  471. package/dist/plugins/worktree-isolation.js +105 -6
  472. package/dist/plugins/write-behind-counter.d.ts +56 -1
  473. package/dist/plugins/write-behind-counter.js +53 -14
  474. package/dist/principal-jwt.d.ts +24 -0
  475. package/dist/principal-jwt.js +60 -5
  476. package/dist/project-memory.d.ts +22 -0
  477. package/dist/project-memory.js +144 -15
  478. package/dist/prompts-domain-validate.d.ts +28 -0
  479. package/dist/prompts-domain-validate.js +42 -1
  480. package/dist/question.d.ts +33 -0
  481. package/dist/question.js +69 -2
  482. package/dist/resource-suspend.d.ts +21 -0
  483. package/dist/resource-suspend.js +16 -0
  484. package/dist/router/route-orchestration.d.ts +78 -0
  485. package/dist/router/route-orchestration.js +77 -0
  486. package/dist/run-local.d.ts +32 -0
  487. package/dist/run-local.js +172 -8
  488. package/dist/runs.d.ts +189 -4
  489. package/dist/runs.js +465 -24
  490. package/dist/runtime-caps-resolver.d.ts +106 -0
  491. package/dist/runtime-caps-resolver.js +89 -4
  492. package/dist/runtime-governance.d.ts +84 -0
  493. package/dist/runtime-governance.js +127 -1
  494. package/dist/sandbox-pkg-source.d.ts +23 -0
  495. package/dist/sandbox-pkg-source.js +37 -0
  496. package/dist/sealed-key.d.ts +54 -0
  497. package/dist/sealed-key.js +68 -3
  498. package/dist/security.d.ts +108 -0
  499. package/dist/security.js +145 -6
  500. package/dist/sema-registry.d.ts +21 -0
  501. package/dist/sema-registry.js +21 -0
  502. package/dist/session-leaf-bus.d.ts +31 -0
  503. package/dist/session-leaf-bus.js +32 -0
  504. package/dist/session-sync-content.d.ts +46 -0
  505. package/dist/session-sync-content.js +47 -1
  506. package/dist/session-sync-kernel.d.ts +89 -0
  507. package/dist/session-sync-kernel.js +48 -3
  508. package/dist/session-sync.d.ts +125 -0
  509. package/dist/session-sync.js +181 -8
  510. package/dist/session-titler.d.ts +26 -0
  511. package/dist/session-titler.js +41 -7
  512. package/dist/session-watch.d.ts +53 -1
  513. package/dist/session-watch.js +73 -9
  514. package/dist/sighup-idle.d.ts +30 -0
  515. package/dist/sighup-idle.js +12 -1
  516. package/dist/spec-fields.d.ts +91 -3
  517. package/dist/spec-fields.js +116 -4
  518. package/dist/task-cwd.d.ts +50 -0
  519. package/dist/task-cwd.js +68 -1
  520. package/dist/task-mcp.d.ts +47 -0
  521. package/dist/task-mcp.js +29 -0
  522. package/dist/task-settings.d.ts +175 -0
  523. package/dist/task-settings.js +226 -11
  524. package/dist/task-workflow.d.ts +67 -0
  525. package/dist/task-workflow.js +75 -8
  526. package/dist/tool-approval.d.ts +91 -0
  527. package/dist/tool-approval.js +215 -0
  528. package/dist/trace/artifacts.d.ts +9 -0
  529. package/dist/trace/artifacts.js +30 -5
  530. package/dist/trace/core-keyset-guard.d.ts +18 -0
  531. package/dist/trace/ledger-sink.d.ts +43 -0
  532. package/dist/trace/ledger-sink.js +64 -5
  533. package/dist/trace/project.d.ts +133 -0
  534. package/dist/trace/project.js +189 -2
  535. package/dist/trace/redact.d.ts +19 -0
  536. package/dist/trace/redact.js +66 -9
  537. package/dist/usage-analytics.d.ts +26 -0
  538. package/dist/usage-analytics.js +26 -3
  539. package/package.json +1 -1
@@ -1,7 +1,10 @@
1
1
  import { type Checkpoint, type CheckpointSummary, type CheckpointToken, type ReopenReason, type ResolveExpectation, type ResumeOutcome } from "@sema-agent/core";
2
2
  import { type PendingCheckpoint } from "./tidb-checkpoint-store.js";
3
3
  export interface LocalCheckpointStoreOptions {
4
+ /** taskId join for the pending card (the local FileRunStore's `getActiveTaskId`). Absent ⇒ `taskId: null`. */
4
5
  getActiveTaskId?: (sessionId: string) => Promise<string | undefined>;
6
+ /** E21 owner guard (the LocalSessionStore's `ownerOf`). Absent ⇒ owner guard degrades to null-owner-only
7
+ * (a non-null owner with no owner source purges NOTHING — fail-closed, mirrors the SQL EXISTS guard). */
5
8
  ownerOf?: (sessionId: string) => Promise<string | null | undefined>;
6
9
  }
7
10
  export declare class LocalCheckpointStore {
@@ -11,9 +14,18 @@ export declare class LocalCheckpointStore {
11
14
  private readonly ctxDir;
12
15
  private readonly tmpDir;
13
16
  private readonly scopes;
17
+ /** [868] sessionId → every token ever put for it — the service-side index that stands in for the SQL twins'
18
+ * `WHERE checkpoint.session_id = ?` on NON-pending rows (core's File store enumerates pending only via
19
+ * listByScope; get(token) is the sole read for resolved/expired rows, so cross-status session queries need
20
+ * this registry). Registered BEFORE the inner put (same crash direction as the scopes registry: a stale
21
+ * index entry is a harmless empty lookup; an unindexed EXPIRED row would silently disable the
22
+ * failSuspendedWithExpiredCheckpoint leg — the bad direction). Persisted so a restart keeps the
23
+ * suspend→crash→expire-later lifecycle visible. Entries are never dropped while the inner row exists
24
+ * (a `resolved` row can be reopen()ed back to pending — pruning it would be wrong). */
14
25
  private readonly sessionTokens;
15
26
  private readonly opts;
16
27
  constructor(root: string, opts?: LocalCheckpointStoreOptions);
28
+ /** Persist the session→tokens index (whole-file atomic replace — puts are per-suspend, low frequency). */
17
29
  private persistSessionTokens;
18
30
  put(token: CheckpointToken, cp: Checkpoint): Promise<void>;
19
31
  get(token: CheckpointToken): Promise<Checkpoint | null>;
@@ -27,21 +39,49 @@ export declare class LocalCheckpointStore {
27
39
  reap(scope: string, cutoff: number): Promise<number>;
28
40
  listByScope(scope: string): Promise<CheckpointSummary[]>;
29
41
  close(): void;
42
+ /** C4-B:注册表损坏时从**数据本体**懒重建 scope 集(core 1.424 `listScopes?` = 「有 ≥1 条 pending 的
43
+ * distinct scope 集」,与 listByScope 可见面对齐 —— 恰好是本注册表要的内容)。一次性:重建后回写
44
+ * sidecar,恢复正常路径。seam 缺席(第三方旧 inner)⇒ 保持 C 案的可见降级,不装恢复了。 */
30
45
  private scopeRegistryCorrupt;
31
46
  private ensureScopesRebuilt;
47
+ /** All still-pending checkpoints across the registered scopes (summary + full row via get). */
32
48
  private pendings;
49
+ /** Operator approval queue — the same NON-secret card as the SQL twins (never the token). */
33
50
  listPending(scope?: string): Promise<PendingCheckpoint[]>;
34
51
  findPendingTokenBySession(sessionId: string, scope?: string): Promise<CheckpointToken | null>;
52
+ /** [868] read-only probe face: does this session have an EXPIRED checkpoint row? The local twin of the SQL
53
+ * `EXISTS (SELECT 1 FROM checkpoint ce WHERE ce.session_id = ? AND ce.status = 'expired')` that drives the
54
+ * run stores' failSuspendedWithExpiredCheckpoint. Scans the session→token index (get(token) is the only
55
+ * cross-status read core's File store offers); an index entry whose inner row vanished is pruned lazily.
56
+ * Backed by a persisted registry, so it stays honest — never a guessed "true".
57
+ * ⚠️ 存量限制(codex M2,如实):索引随 put 增量建立,无升级迁移——本版本部署前已存在的 checkpoint 不在
58
+ * 索引里,其 expired 对本探针不可见(core File store 的 listByScope 是 pending-only,无法枚举历史行回填)。
59
+ * 旧存量锁死的恢复把手 = cancel verb([868]①,不依赖本索引);增量行全覆盖。 */
35
60
  hasExpiredBySession(sessionId: string): Promise<boolean>;
61
+ /** `undefined` = no pending row; else the owner scope (local scopes are always strings — never null). */
36
62
  peekPendingScope(sessionId: string): Promise<string | null | undefined>;
63
+ /**
64
+ * design/80 D-D global expiry sweep — same kind-split as the TiDB twin: the deadline branch abort-expires
65
+ * every kind EXCEPT a human/irreversible_ask approval gate (those get the graceful resolve-DENY via
66
+ * listExpiredApprovalGates), with the AskUserQuestion carve-back (denying a question is incoherent → expire);
67
+ * the terminal_at branch (derived read-time via the SAME formula the TiDB put stamps) abort-expires ANY kind.
68
+ */
37
69
  reapExpired(cutoff: number): Promise<number>;
70
+ /** design/80 D-D SLA deny-sweep input — pending human/irreversible_ask gates past deadline (excl. AskUserQuestion). */
38
71
  listExpiredApprovalGates(cutoff: number, limit?: number): Promise<Array<{
39
72
  sessionId: string;
40
73
  scope: string;
41
74
  }>>;
42
75
  putCtx(sessionId: string, ctx: unknown): Promise<void>;
43
76
  getCtx<T = unknown>(sessionId: string): Promise<T | null>;
77
+ /** GC ctx files whose lifecycle is over — same three guards as the SQL twins (stale ∧ no pending ∧ no active run). */
44
78
  reapCtx(cutoff: number): Promise<number>;
79
+ /**
80
+ * E21 session purge — functional contract: a deleted session has no resumable future. Expires every pending
81
+ * gate of the session (all scopes) + unlinks its ctx file. Owner guard mirrors the SQL EXISTS guard: with an
82
+ * `ownerOf` source the owner must null-safe-match; without one, only an ownerless call (owner=null) purges.
83
+ * Returns the number of gates expired. (Terminal ledger history stays on disk — local transcripts posture.)
84
+ */
45
85
  deleteBySession(sessionId: string, owner: string | null): Promise<number>;
46
86
  }
47
87
  //# sourceMappingURL=local-checkpoint-store.d.ts.map
@@ -1,11 +1,35 @@
1
+ /**
2
+ * LOCAL (file-backed) checkpoint store — EnterPlanMode / durable HITL for the TOC local lane.
3
+ *
4
+ * Shape: core's `FileCheckpointStore` (crash-safe ledger+snapshot, per-token CAS — the ENGINE contract) is the
5
+ * inner authority; this wrapper adds the SERVICE half the SQL twins carry (operator queue / session lookups /
6
+ * resume ctx / reapers) WITHOUT re-implementing any core abstraction ([[core-service-boundary]]: engine contract
7
+ * stays core's; wire/ops glue is ours).
8
+ *
9
+ * Enumeration seam: core's File store exposes only `listByScope(scope)` (pending-only summaries) + `get(token)`.
10
+ * Cross-scope queries (fleet listPending / reapExpired / session lookups) therefore ride a service-side SCOPES
11
+ * REGISTRY: `put` records each scope once into `checkpoint-scopes.json` (registered BEFORE the inner put so a
12
+ * crash can't leave an unenumerable pending row; a scope whose rows are gone is harmless — its listByScope is
13
+ * simply empty). Projection fields come from `get(token)` (the full Checkpoint), so listPending serves the same
14
+ * non-secret card as the SQL twins (shared `boundedToolInput` bound, same severity-DESC sort).
15
+ *
16
+ * Honest degrades (documented, single-user local lane):
17
+ * - `deleteBySession` EXPIRES the session's pending gates + unlinks its ctx file — the ledger/snapshot keeps
18
+ * terminal history like the local tool-result/transcript stores do (no physical row delete primitive in
19
+ * core's File store; the E21 functional contract — "a deleted session has no resumable future" — holds).
20
+ * - `taskId` on the pending card comes from an injected `getActiveTaskId` (the local FileRunStore) — `null`
21
+ * when not wired, which every consumer already tolerates.
22
+ */
1
23
  import { createHash } from "node:crypto";
2
24
  import { existsSync, readFileSync, readdirSync, renameSync, unlinkSync, mkdirSync } from "node:fs";
3
25
  import { join } from "node:path";
4
26
  import { FileCheckpointStore, atomicWriteFile, sanitizePathComponent, } from "@sema-agent/core";
5
27
  import { boundedToolInput, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS } from "./tidb-checkpoint-store.js";
28
+ /** design/80 D-D read-time twin of the TiDB put-time `terminal_at` column (same formula — anti-drift). */
6
29
  function terminalAtOf(cp) {
7
30
  return Math.max(cp.createdAt + TERMINAL_BACKSTOP_MS, (cp.deadline ?? 0) + TERMINAL_GRACE_MS);
8
31
  }
32
+ /** Collision-proof ctx filename: readable prefix + content hash of the FULL sessionId (sanitize can collide). */
9
33
  function ctxFileOf(sessionId) {
10
34
  return `${sanitizePathComponent(sessionId).slice(0, 48)}-${createHash("sha256").update(sessionId).digest("hex").slice(0, 12)}.json`;
11
35
  }
@@ -16,6 +40,14 @@ export class LocalCheckpointStore {
16
40
  ctxDir;
17
41
  tmpDir;
18
42
  scopes = new Set();
43
+ /** [868] sessionId → every token ever put for it — the service-side index that stands in for the SQL twins'
44
+ * `WHERE checkpoint.session_id = ?` on NON-pending rows (core's File store enumerates pending only via
45
+ * listByScope; get(token) is the sole read for resolved/expired rows, so cross-status session queries need
46
+ * this registry). Registered BEFORE the inner put (same crash direction as the scopes registry: a stale
47
+ * index entry is a harmless empty lookup; an unindexed EXPIRED row would silently disable the
48
+ * failSuspendedWithExpiredCheckpoint leg — the bad direction). Persisted so a restart keeps the
49
+ * suspend→crash→expire-later lifecycle visible. Entries are never dropped while the inner row exists
50
+ * (a `resolved` row can be reopen()ed back to pending — pruning it would be wrong). */
19
51
  sessionTokens = new Map();
20
52
  opts;
21
53
  constructor(root, opts = {}) {
@@ -36,11 +68,18 @@ export class LocalCheckpointStore {
36
68
  this.scopes.add(s);
37
69
  }
38
70
  catch (e) {
71
+ // C4(clay 裁 2026-07-26,C 先行 + B 根治):此前这里静默吞 ⇒ 存量待决审批整体从枚举面隐身,
72
+ // 操作员看到的是**空列表而不是错误**,没人会对空列表排障。处置两层:
73
+ // ①fail-visible(C):warn 大声 + 坏文件改名隔离留证(也防下一次 put 的整写把证据盖掉);
74
+ // ②重建(B,core 1.424 `listScopes?` seam,[1800]② 索 → [1803] 交付):constructor 是同步的,
75
+ // 重建挂在读路径懒执行一次(见 ensureScopesRebuilt)—— 从数据本体枚举 pending scope 集,
76
+ // 枚举面完整恢复,不再依赖「下次 suspend 自愈」只救新件。
39
77
  const quarantine = `${this.scopesPath}.corrupt-${Date.now()}`;
40
78
  try {
41
79
  renameSync(this.scopesPath, quarantine);
42
80
  }
43
81
  catch {
82
+ /* 移不动就留原地 —— warn 里已给路径,人工可查 */
44
83
  }
45
84
  this.scopeRegistryCorrupt = true;
46
85
  console.warn(`LocalCheckpointStore: checkpoint-scopes.json is corrupt (${e instanceof Error ? e.message : String(e)}) — ` +
@@ -60,17 +99,23 @@ export class LocalCheckpointStore {
60
99
  }
61
100
  }
62
101
  catch {
102
+ /* a corrupt index only narrows hasExpiredBySession (fail-safe: the reaper skips, cancel still works) */
63
103
  }
64
104
  }
65
105
  }
106
+ /** Persist the session→tokens index (whole-file atomic replace — puts are per-suspend, low frequency). */
66
107
  persistSessionTokens() {
67
108
  atomicWriteFile(this.tmpDir, this.sessionTokensPath, JSON.stringify(Object.fromEntries([...this.sessionTokens].map(([sid, set]) => [sid, [...set]]))));
68
109
  }
110
+ // ─────────── core CheckpointStore contract — delegated to core's File store (the engine authority) ───────────
69
111
  async put(token, cp) {
112
+ // Register the scope BEFORE the inner commit: a crash between the two leaves a stale scope entry
113
+ // (harmless empty enumeration), never an unenumerable pending checkpoint (the bad direction).
70
114
  if (!this.scopes.has(cp.scope)) {
71
115
  this.scopes.add(cp.scope);
72
116
  atomicWriteFile(this.tmpDir, this.scopesPath, JSON.stringify([...this.scopes]));
73
117
  }
118
+ // [868] session→token index, same before-the-inner-put crash rationale (see the field doc).
74
119
  if (!this.sessionTokens.get(cp.sessionId)?.has(token)) {
75
120
  const set = this.sessionTokens.get(cp.sessionId) ?? new Set();
76
121
  set.add(token);
@@ -103,13 +148,17 @@ export class LocalCheckpointStore {
103
148
  close() {
104
149
  this.inner.close();
105
150
  }
151
+ // ─────────── service extensions (the SQL twins' operator/ops half) ───────────
152
+ /** C4-B:注册表损坏时从**数据本体**懒重建 scope 集(core 1.424 `listScopes?` = 「有 ≥1 条 pending 的
153
+ * distinct scope 集」,与 listByScope 可见面对齐 —— 恰好是本注册表要的内容)。一次性:重建后回写
154
+ * sidecar,恢复正常路径。seam 缺席(第三方旧 inner)⇒ 保持 C 案的可见降级,不装恢复了。 */
106
155
  scopeRegistryCorrupt = false;
107
156
  async ensureScopesRebuilt() {
108
157
  if (!this.scopeRegistryCorrupt)
109
158
  return;
110
159
  const listScopes = this.inner.listScopes;
111
160
  if (typeof listScopes !== "function")
112
- return;
161
+ return; // 无 seam:维持已 warn 的降级
113
162
  const rebuilt = await listScopes.call(this.inner);
114
163
  for (const s of rebuilt)
115
164
  this.scopes.add(s);
@@ -117,6 +166,7 @@ export class LocalCheckpointStore {
117
166
  atomicWriteFile(this.tmpDir, this.scopesPath, JSON.stringify([...this.scopes]));
118
167
  console.warn(`LocalCheckpointStore: scope registry REBUILT from the data plane (${rebuilt.length} scope(s) with pending gates) — enumeration restored`);
119
168
  }
169
+ /** All still-pending checkpoints across the registered scopes (summary + full row via get). */
120
170
  async pendings(scope) {
121
171
  await this.ensureScopesRebuilt();
122
172
  const out = [];
@@ -130,6 +180,7 @@ export class LocalCheckpointStore {
130
180
  }
131
181
  return out;
132
182
  }
183
+ /** Operator approval queue — the same NON-secret card as the SQL twins (never the token). */
133
184
  async listPending(scope) {
134
185
  const rows = [];
135
186
  for (const { cp } of await this.pendings(scope)) {
@@ -150,6 +201,7 @@ export class LocalCheckpointStore {
150
201
  riskDescriptor: gate?.riskDescriptor ?? null,
151
202
  });
152
203
  }
204
+ // Same triage order as the SQL twins: severity DESC, then oldest-first within a tier.
153
205
  return rows.sort((a, b) => (b.riskDescriptor?.severity ?? 0) - (a.riskDescriptor?.severity ?? 0) || a.createdAt - b.createdAt);
154
206
  }
155
207
  async findPendingTokenBySession(sessionId, scope) {
@@ -158,6 +210,14 @@ export class LocalCheckpointStore {
158
210
  return token;
159
211
  return null;
160
212
  }
213
+ /** [868] read-only probe face: does this session have an EXPIRED checkpoint row? The local twin of the SQL
214
+ * `EXISTS (SELECT 1 FROM checkpoint ce WHERE ce.session_id = ? AND ce.status = 'expired')` that drives the
215
+ * run stores' failSuspendedWithExpiredCheckpoint. Scans the session→token index (get(token) is the only
216
+ * cross-status read core's File store offers); an index entry whose inner row vanished is pruned lazily.
217
+ * Backed by a persisted registry, so it stays honest — never a guessed "true".
218
+ * ⚠️ 存量限制(codex M2,如实):索引随 put 增量建立,无升级迁移——本版本部署前已存在的 checkpoint 不在
219
+ * 索引里,其 expired 对本探针不可见(core File store 的 listByScope 是 pending-only,无法枚举历史行回填)。
220
+ * 旧存量锁死的恢复把手 = cancel verb([868]①,不依赖本索引);增量行全覆盖。 */
161
221
  async hasExpiredBySession(sessionId) {
162
222
  const tokens = this.sessionTokens.get(sessionId);
163
223
  if (!tokens)
@@ -166,7 +226,7 @@ export class LocalCheckpointStore {
166
226
  for (const t of [...tokens]) {
167
227
  const cp = await this.inner.get(t);
168
228
  if (!cp) {
169
- tokens.delete(t);
229
+ tokens.delete(t); // inner row gone (e.g. a wiped data plane) — the index entry is stale
170
230
  pruned = true;
171
231
  continue;
172
232
  }
@@ -180,16 +240,24 @@ export class LocalCheckpointStore {
180
240
  this.persistSessionTokens();
181
241
  }
182
242
  catch {
243
+ /* best-effort — a stale on-disk entry is re-pruned on the next scan */
183
244
  }
184
245
  }
185
246
  return false;
186
247
  }
248
+ /** `undefined` = no pending row; else the owner scope (local scopes are always strings — never null). */
187
249
  async peekPendingScope(sessionId) {
188
250
  for (const { cp } of await this.pendings())
189
251
  if (cp.sessionId === sessionId)
190
252
  return cp.scope;
191
253
  return undefined;
192
254
  }
255
+ /**
256
+ * design/80 D-D global expiry sweep — same kind-split as the TiDB twin: the deadline branch abort-expires
257
+ * every kind EXCEPT a human/irreversible_ask approval gate (those get the graceful resolve-DENY via
258
+ * listExpiredApprovalGates), with the AskUserQuestion carve-back (denying a question is incoherent → expire);
259
+ * the terminal_at branch (derived read-time via the SAME formula the TiDB put stamps) abort-expires ANY kind.
260
+ */
193
261
  async reapExpired(cutoff) {
194
262
  let n = 0;
195
263
  for (const { token, cp } of await this.pendings()) {
@@ -204,6 +272,7 @@ export class LocalCheckpointStore {
204
272
  }
205
273
  return n;
206
274
  }
275
+ /** design/80 D-D SLA deny-sweep input — pending human/irreversible_ask gates past deadline (excl. AskUserQuestion). */
207
276
  async listExpiredApprovalGates(cutoff, limit = 100) {
208
277
  const hits = [];
209
278
  for (const { cp } of await this.pendings()) {
@@ -221,6 +290,7 @@ export class LocalCheckpointStore {
221
290
  .slice(0, limit)
222
291
  .map(({ sessionId, scope }) => ({ sessionId, scope }));
223
292
  }
293
+ // ─────────── checkpoint ctx (resume rebuild inputs; sessionId-keyed, one JSON file per session) ───────────
224
294
  async putCtx(sessionId, ctx) {
225
295
  const rec = { sessionId, updatedAt: Date.now(), ctx };
226
296
  atomicWriteFile(this.tmpDir, join(this.ctxDir, ctxFileOf(sessionId)), JSON.stringify(rec));
@@ -231,12 +301,13 @@ export class LocalCheckpointStore {
231
301
  return null;
232
302
  try {
233
303
  const rec = JSON.parse(readFileSync(p, "utf8"));
234
- return rec.sessionId === sessionId ? (rec.ctx ?? null) : null;
304
+ return rec.sessionId === sessionId ? (rec.ctx ?? null) : null; // hash-collision paranoia: verify the embedded id
235
305
  }
236
306
  catch {
237
- return null;
307
+ return null; // a torn/corrupt ctx reads as absent — the resume 409s "resume context missing" (fail-loud upstream)
238
308
  }
239
309
  }
310
+ /** GC ctx files whose lifecycle is over — same three guards as the SQL twins (stale ∧ no pending ∧ no active run). */
240
311
  async reapCtx(cutoff) {
241
312
  let n = 0;
242
313
  for (const f of readdirSync(this.ctxDir)) {
@@ -248,7 +319,7 @@ export class LocalCheckpointStore {
248
319
  rec = JSON.parse(readFileSync(p, "utf8"));
249
320
  }
250
321
  catch {
251
- continue;
322
+ continue; // unreadable ⇒ leave for inspection (never a blind unlink)
252
323
  }
253
324
  if (rec.updatedAt >= cutoff)
254
325
  continue;
@@ -261,20 +332,27 @@ export class LocalCheckpointStore {
261
332
  n++;
262
333
  }
263
334
  catch {
335
+ /* racing unlink is fine */
264
336
  }
265
337
  }
266
338
  return n;
267
339
  }
340
+ /**
341
+ * E21 session purge — functional contract: a deleted session has no resumable future. Expires every pending
342
+ * gate of the session (all scopes) + unlinks its ctx file. Owner guard mirrors the SQL EXISTS guard: with an
343
+ * `ownerOf` source the owner must null-safe-match; without one, only an ownerless call (owner=null) purges.
344
+ * Returns the number of gates expired. (Terminal ledger history stays on disk — local transcripts posture.)
345
+ */
268
346
  async deleteBySession(sessionId, owner) {
269
347
  if (this.opts.ownerOf) {
270
348
  const actual = await this.opts.ownerOf(sessionId);
271
349
  if (actual === undefined)
272
- return 0;
350
+ return 0; // no session row ⇒ EXISTS guard fails ⇒ purge nothing
273
351
  if ((actual ?? null) !== (owner ?? null))
274
352
  return 0;
275
353
  }
276
354
  else if (owner !== null) {
277
- return 0;
355
+ return 0; // no owner source to verify a non-null owner against — fail-closed
278
356
  }
279
357
  let n = 0;
280
358
  for (const { token, cp } of await this.pendings()) {
@@ -287,6 +365,7 @@ export class LocalCheckpointStore {
287
365
  unlinkSync(p);
288
366
  }
289
367
  catch {
368
+ /* best-effort ctx unlink */
290
369
  }
291
370
  return n;
292
371
  }
@@ -3,45 +3,157 @@ import type { SessionSummary } from "./store-contracts.js";
3
3
  import { type StagingHandle } from "../session-sync-kernel.js";
4
4
  export declare class LocalSessionStore implements SessionStore {
5
5
  private readonly repo;
6
+ /** In-flight acquisitions keyed by id, so concurrent acquire(sameId) in one process share one (mirrors TiDBSessionStore). */
6
7
  private readonly pending;
8
+ /** Service-side owner scope per session (core's repo has no owner column). Registered-ownerless ⇒ null; absent ⇒ undefined. */
7
9
  private readonly owners;
10
+ /** Last-activity marker (touch) for ordering — the keyset sort key for {@link listSessions}. PERSISTED to a JSON
11
+ * sidecar under {@link dataDir} (when given) so the /resume picker's newest-first order SURVIVES a service restart:
12
+ * without persistence the map starts EMPTY on boot and every session degrades to `createdAt` ordering (the picker
13
+ * shows the wrong "most recent" — TOC-review #10). In-memory only (no sidecar) when `dataDir` is absent (the
14
+ * process-local `InMemorySessionRepo` case, where the sessions themselves are lost on restart anyway). */
8
15
  private readonly lastActivity;
16
+ /** K-5c (core 1.155 SessionStore.noteTaskRun seam): the latest task run per session, recorded by core's Runner at
17
+ * runTask START (so a running/suspended run surfaces too) → projected as `lastRunId` on listSessions. The cloud
18
+ * TiDB/PG twins derive it from `task_run`; the local backend has no runs ledger, so this is an in-memory map.
19
+ * ⚠️ IN-MEMORY BEST-EFFORT (honest degrade, NOT sidecar-persisted — review Q6): it covers the PRIMARY /resume use
20
+ * case (re-attach to a RUNNING run — recorded at the run's start, the process can't have restarted while that run
21
+ * is still live), and is LOST on a process restart. That's acceptable: a session whose last run predates a restart
22
+ * has only TERMINAL runs (no live tail to re-attach), so `lastRunId` falls back to null and the shell uses its
23
+ * no-anchor path — same posture as the other local degrades here (runCount:0, lastStatus:""). Persisting it would
24
+ * need a sidecar-format change (the #10 clobber area); deferred until a real local-file-backed need. */
9
25
  private readonly lastTaskRun;
26
+ /** 2c P1d-β — live staged-import handles keyed by stagingId, so a local staging's in-memory buffer is readable via
27
+ * readStagedEntries (the durable twins re-read the staged session_event rows; local has no such rows). */
10
28
  private readonly stagings;
29
+ /** Lazy one-shot load of the persisted lastActivity sidecar (memoized; only the first reader pays the read). */
11
30
  private loaded?;
31
+ /** A pending debounced sidecar flush (coalesces a burst of touch() into one write). undefined ⇒ no flush queued. */
12
32
  private flushTimer?;
33
+ /** Serializes sidecar writes (bug B): the in-flight write promise. A flush() while one is running CHAINS after it
34
+ * (re-checking the dirty flag) so an older snapshot can never rename after a newer one (lost-update). */
13
35
  private writeChain;
36
+ /** Set by touch/delete when the map mutated; cleared by a write that captured the change. A write that ran while this
37
+ * is set re-runs (a touch that landed during an active write isn't dropped). Drives the chain's re-run guard (bug B). */
14
38
  private dirty;
39
+ /** Monotonic per-write counter — feeds a UNIQUE tmp filename per write so overlapping writes can't share one tmp path
40
+ * and tear each other's bytes (bug B). */
15
41
  private writeSeq;
42
+ /** Last time a sidecar-write error was warned (bug D): throttle the best-effort warn so a persistently-failing disk
43
+ * doesn't spam the log on every debounced flush. 0 ⇒ never warned. */
16
44
  private lastWarnAt;
45
+ /** Absolute path to the lastActivity JSON sidecar, or undefined when not persisting (in-memory-only deployment). */
17
46
  private readonly sidecarPath?;
47
+ /** Auto-title map + its own LIGHT sidecar (`session-titles.json`). Separate file from the
48
+ * lastActivity sidecar ON PURPOSE (that format is a #10 clobber area); titles are write-once + ultra-low-rate
49
+ * (one per session, ever), so a plain read-modify-write with tmp+rename per write is enough — no debounce.
50
+ *
51
+ * 🔴 CROSS-INSTANCE (fixed 2026-07-25, blackboard [1684] — core's "per-instance state" defect class):
52
+ * these three used to be INSTANCE fields, which is exactly the shape core described — «the backend is shared
53
+ * more widely than the object, but the state and the lock hang off the object». Two `LocalSessionStore`s over
54
+ * the SAME dataDir each held their own `titles` map and their own write chain, so a real concurrency probe
55
+ * (`test/file-stores-cross-instance-concurrency.test.ts`) showed **BOTH winning** the write-once IS-NULL gate
56
+ * (`wins=2`): each checked its own map, both saw absent, both returned `true`, and the second whole-map
57
+ * snapshot silently clobbered the first title. That is core's A-class (CAS double-win) and B-class
58
+ * (lost update) stacked. Fix per core's prescription: state + lock live at MODULE level, keyed by the resolved
59
+ * sidecar path, so any number of instances over one dataDir collapse to a single authority.
60
+ * Sharing key = the resolved path; NO sidecar (in-memory deployment) ⇒ no shared backend exists ⇒ that case
61
+ * keeps genuinely per-instance state (see {@link titleState}). */
18
62
  private readonly titleSidecarPath?;
63
+ /** Per-instance fallback used ONLY when there is no sidecar path (nothing is shared, so nothing to collapse). */
19
64
  private readonly ownTitleState;
65
+ /** @param repo the core SessionRepo this store projects into the §0.5 SessionStore shape.
66
+ * @param dataDir the SAME data dir the file-backed repo persists under (LocalBackend passes `fileBackend.root`).
67
+ * When given, lastActivity is persisted to `<dataDir>/session-last-activity.json` so it survives a
68
+ * restart (the file-backed deployment); omit it for the in-memory deployment (nothing survives). */
20
69
  constructor(repo: SessionRepo, dataDir?: string);
70
+ /** 该实例应当使用的 title 状态:有 sidecar ⇒ 按路径共享的那份;无 sidecar ⇒ 自己那份(无共享后端)。 */
21
71
  private get titleState();
72
+ /** Lazy one-shot hydrate of the persisted titles (mirrors ensureLoaded's posture: missing file silent, torn warn). */
22
73
  private ensureTitlesLoaded;
74
+ /** Chained snapshot write of the titles sidecar (the chain guarantees the LAST rename carries the
75
+ * NEWEST map state: each link re-snapshots the SHARED map at write time, so an overtaken writer is harmless). */
23
76
  private persistTitles;
77
+ /** Cheap pre-LLM probe (local twin). The map write needs no session_meta row, so there is
78
+ * no "none" (register-lag) dimension here — two states only. */
24
79
  probeTitle(sessionId: string): Promise<"none" | "untitled" | "titled">;
80
+ /** Write-once auto-title (the local twin of the SQL setTitleIfNull). Persists the whole
81
+ * (small) map via a SERIALIZED tmp+rename snapshot; a write failure keeps the in-memory title (degrades to
82
+ * re-title after restart). */
25
83
  setTitleIfNull(sessionId: string, title: string): Promise<boolean>;
84
+ /** Best-effort, one-shot hydrate of the persisted lastActivity map (no-op when not persisting / no sidecar yet). A
85
+ * read/parse error degrades to an empty map (createdAt ordering) rather than failing the list — the picker still
86
+ * works, just without restart-persisted recency. Memoized so concurrent listSessions share one read. */
26
87
  private ensureLoaded;
88
+ /** Queue a debounced, best-effort atomic write of the lastActivity map to the sidecar (coalesces touch bursts). The
89
+ * write is fire-and-forget: a persistence failure must NEVER break the run path (touch is on the hot acquire path),
90
+ * so errors are swallowed — the worst case is a restart falling back to createdAt ordering for un-flushed touches. */
27
91
  private scheduleFlush;
92
+ /** Atomic best-effort write of the lastActivity map. SERIALIZED via {@link writeChain} (bug B): overlapping flushes
93
+ * chain instead of racing, so an older snapshot can never rename after a newer one (lost-update), and a unique tmp
94
+ * name per write means two writes can't tear each other's bytes. Returns the chain so callers (dispose) can await the
95
+ * final write (bug C). Each link HYDRATES the disk sidecar first (bug A) and writes the UNION of disk + in-process —
96
+ * the `has(id)` live-wins guard in ensureLoaded() keeps in-process touches authoritative — so a fresh-boot flush
97
+ * before any list never CLOBBERS the prior boot's recency for not-yet-touched sessions. */
28
98
  private flush;
99
+ /** One serialized sidecar write: hydrate-then-merge (bug A), snapshot, atomic tmp+rename with a UNIQUE tmp name (bug
100
+ * B). Clears {@link dirty} for the change it captured; re-runs once if a touch landed mid-write so it's not dropped. */
29
101
  private doFlush;
102
+ /** Throttled best-effort warn for a sidecar I/O failure (bug D): never throws, at most once per ~minute so a
103
+ * persistently-failing disk doesn't spam the log on every debounced flush. */
30
104
  private warnSidecar;
31
105
  acquire(sessionId?: string, opts?: {
32
106
  requireExisting?: boolean;
33
107
  }): Promise<AcquiredSession>;
34
108
  private load;
109
+ /** Idempotently record a session's owner — never overwrites an existing owner (mirrors TiDBSessionStore.register).
110
+ * TiDB parity: register INSERTs a session_meta row so the session EXISTS (forkable) even before its
111
+ * first acquire/run — so we also ensure an EMPTY repo session exists (open if present → never overwrite history;
112
+ * create if not), else `ownerOf` would say a registered-but-never-acquired session exists while `fork` 404s it. */
35
113
  register(sessionId: string, owner: string | null): Promise<void>;
114
+ /** Owner of a session: `null` if registered ownerless, `undefined` if no such session (mirrors TiDBSessionStore.ownerOf).
115
+ *
116
+ * S3 修(clay 裁 2026-07-26:**local=单用户,多租户走云** ⇒ 跨重启不承诺 owner 隔离):`owners` 是纯内存
117
+ * Map,重启后失忆——曾把「失忆」答成 `undefined`(=「无此会话」),让 DELETE /v1/sessions 的 route 门短路成
118
+ * already-gone、checkpoint 的 EXISTS 镜像门 return 0 ⇒ **E21 对盘上老会话整体 no-op 且无人知道**。
119
+ * 现在 Map miss 时探 repo:盘上在 ⇒ 按 load() 两处懒回填早已写下的同一判据回填 `null`(registered
120
+ * ownerless);repo 真没有才 `undefined`。SQL 孪生无此形(owner 在 session_meta 行,重启无损)。 */
36
121
  ownerOf(sessionId: string): Promise<string | null | undefined>;
122
+ /** [1196] 六轮复审:owner+leafId 原子快照——单线程 JS 内两同步/顺序读之间无 await 打断 owner 判定
123
+ * (owner 先取快照,leaf 读后 owner 复核,变了=undefined 视作删除中,调用方按删处理)。 */
37
124
  getHead(sessionId: string): Promise<{
38
125
  owner: string | null;
39
126
  leafId: string | null;
40
127
  } | undefined>;
128
+ /** 2c P1d-β — re-stamp the service-side owner scope WITHOUT rewriting entries (the staged-commit `identical` path:
129
+ * the log is already present & equal, so only the owner needs re-stamping to the importing principal, §9). */
41
130
  restampOwner(sessionId: string, owner: string | null): void;
42
131
  touch(sessionId: string): Promise<void>;
132
+ /** E18 — the session's current leaf SessionTreeEntry.id (@see TiDBSessionStore.getLeafId). Reads the repo's storage
133
+ * leaf (no acquire-lock; InMemory/File repo reads don't lock). null when the session doesn't exist / has no leaf. */
43
134
  getLeafId(sessionId: string): Promise<string | null>;
135
+ /** Durable history is retained by the repo; just drop the in-flight cache entry (mirrors TiDBSessionStore.release). */
44
136
  release(sessionId: string): Promise<void>;
137
+ /**
138
+ * P0.5 variant-2 (E16, clay 2026-06-26) — enumerate the caller's sessions (CC /resume picker) from the SESSION
139
+ * abstraction (`repo.list()`), keyset-paginated newest-first by last activity. Session IDENTITY comes from the
140
+ * repo (one entry per persisted session); a {@link SessionSummary} is SYNTHESIZED per id so the wire shape is
141
+ * byte-identical to {@link TiDBSessionStore.listSessions} (the run picker doesn't drift):
142
+ * - `owner` — the service-side owner map (process-local; null when unknown/ownerless). Owner FILTERING
143
+ * is best-effort here (the in-memory map IS the source of truth; a single-user local
144
+ * deployment runs REQUIRE_PRINCIPAL=off so the principal path passes owner=null and every
145
+ * null-owner session lists). The route already owner-gates at the HTTP layer.
146
+ * - `firstActivityAt` — the session's `createdAt` (repo metadata).
147
+ * - `lastActivityAt` — the touch marker (falls back to `createdAt`); the keyset sort key.
148
+ * - `objectivePreview`— the last USER-text entry, synthesized from the session tree (no run ledger).
149
+ * - `runCount`/`lastStatus` — DEGRADED (0 / ""): the session abstraction has no runs ledger; the TiDB twin
150
+ * LEFT-JOINs `task_run` for these, which the local backend (MemoryRunStore, separate
151
+ * ledger) intentionally does NOT correlate here (variant-2 is session-abstraction-only).
152
+ *
153
+ * Keyset matches the contract: STRICTLY older than the cursor, ties broken by id DESC; `limit` is honored after
154
+ * the in-memory sort. Cheap (a local single-user store holds few sessions). Errors reading one session's entries
155
+ * degrade that row's preview to null rather than failing the whole list.
156
+ */
45
157
  listSessions(opts: {
46
158
  owner?: string;
47
159
  cursor?: {
@@ -51,22 +163,67 @@ export declare class LocalSessionStore implements SessionStore {
51
163
  limit: number;
52
164
  q?: string;
53
165
  }): Promise<SessionSummary[]>;
166
+ /** K-5c (core 1.155 SessionStore seam): core's Runner calls this at runTask START with the run's taskId, so the
167
+ * latest run surfaces as `lastRunId` on listSessions even while it is still running/suspended (the local backend
168
+ * has no runs ledger to derive it from, unlike the TiDB/PG twins). In-memory, last-write-wins per session. */
54
169
  noteTaskRun(sessionId: string, taskId: string): void;
170
+ /** Synthesize a session's objective preview = the most-recent USER text message (the objective the run last saw).
171
+ * Reads the session's entries through the repo; any read error degrades to null (never fails the list). */
55
172
  private previewOf;
173
+ /** E17 — fork a session's WHOLE history to a NEW id owned by `owner` (core SessionRepo.fork). Returns the new id,
174
+ * or null if the source does not exist (the route maps that to 404). */
56
175
  fork(sourceId: string, owner: string | null): Promise<string | null>;
176
+ /** 2c session-sync — EXPORT a session's full durable entry log (core `SessionRepo.exportEntries`; the
177
+ * in-memory/file repo holds the whole log so there is no floor to bypass). null if the source is unknown / the
178
+ * underlying repo lacks the optional seam. The owner is NOT exported — import re-stamps it. */
57
179
  exportEntries(sessionId: string): Promise<SessionTreeEntry[] | null>;
180
+ /** 2c session-sync P1d-α (PULL streaming) — the IDS-ONLY projection of the full durable log (@see
181
+ * TiDBSessionStore.listEntryIds). The local repo holds the whole log in memory/file so there is no floor to bypass;
182
+ * ids are the `exportEntries` ids in order. null if the source is unknown / the repo lacks the export seam. */
58
183
  listEntryIds(sessionId: string): Promise<string[] | null>;
184
+ /** 2c session-sync P1d-α (PULL streaming) — STREAM the full durable log as an async generator (@see
185
+ * TiDBSessionStore.exportEntriesStream). The LOCAL twin has no cross-instance buffering hazard (an in-memory map /
186
+ * single-process file repo), so it reads the whole log via the repo's `exportEntries` then yields it lazily, SLICED
187
+ * after `opts.afterSeq` (the LOCAL backend's native seq = the 0-based dense ARRAY INDEX of the entry in the
188
+ * oldest-first log; afterSeq=k → entries at index > k = `slice(k+1)`). afterSeq is a BACKEND-NATIVE seq cursor (a
189
+ * resume is always same-backend), so the local 0-based-index base needn't match the durable backends' `seq` column
190
+ * base. Resolves to null (NOT an empty iterable) for an unknown session — mirrors {@link exportEntries}.
191
+ * `opts.batchSize` is accepted for API parity but has no effect locally (the whole log is already in hand). */
59
192
  exportEntriesStream(sessionId: string, opts?: {
60
193
  afterSeq?: number;
61
194
  batchSize?: number;
62
195
  }): Promise<AsyncIterable<SessionTreeEntry> | null>;
196
+ /** 2c session-sync — IMPORT a verbatim entry log into `sessionId` via core `SessionRepo.importEntries`
197
+ * (which runs the `validateEntriesForImport` fail-closed gate before writing). `owner` is the authenticated
198
+ * importing principal (re-stamped into the service-side owner map; core's local repo has no owner column, §9).
199
+ * `owner=null` (single-user local) is passed as `undefined` to the core seam (its owner param is `string | undefined`). */
63
200
  importEntries(sessionId: string, owner: string | null, entries: SessionTreeEntry[]): Promise<void>;
201
+ /** 2c session-sync (§7/§8) — IDEMPOTENT REPLACE. The local twin's replace is DELETE-then-IMPORT: core's
202
+ * InMemorySessionRepo / FileSessionRepo expose no single replace primitive, but the local backend is single-writer
203
+ * with NO compaction floor / cross-instance race (a process-local in-memory map / a single-process file repo), so
204
+ * deleteSession-then-importEntries is effectively atomic for the local case (no concurrent reader can observe the
205
+ * gap, unlike the durable cross-instance backends which do it in ONE SQL txn). Both halves are best-effort feature-
206
+ * gated: a repo lacking either seam throws the same clear error importEntries does (no silent half-write). */
64
207
  replaceEntries(sessionId: string, owner: string | null, entries: SessionTreeEntry[]): Promise<void>;
208
+ /** 2c session-sync P1d-β (PUSH streaming) — begin a STAGED import. The LOCAL backend is single-writer with no
209
+ * cross-instance / cross-replica concurrency story (the durable twins carry that), so the staging handle simply
210
+ * ACCUMULATES the streamed batches in memory then, on commit, runs the SAME validate-first → replaceEntries the
211
+ * whole-bundle local import uses (effectively atomic locally — no concurrent reader can observe the gap). Keep it
212
+ * simple per §1: the durable twins are where the SHADOW-id swap + bounded-memory + concurrency matter. */
65
213
  beginImportStaging(realSessionId: string, token: string): StagingHandle;
214
+ /** 2c P1d-β (staged-row inspection) — the in-memory staged entries for a local staging id. No longer the import gate
215
+ * (the per-line StreamingImportValidator validates during the Phase-B stream); a tests/diagnostics seam. [] for an
216
+ * unknown/finished staging id (mirrors the durable twins' empty-set return). */
66
217
  readStagedEntries(stagingId: string): Promise<SessionTreeEntry[]>;
218
+ /** Drop a finished/aborted local staging handle from the registry (called by the handle on commit/abort). */
67
219
  forgetStaging(stagingId: string): void;
220
+ /** E21 — purge a session's conversation history (core SessionRepo.delete), owner-guarded (single-user: owner=null
221
+ * matches). Idempotent: a missing/wrong-owner session is a no-op returning false. The runs-ledger / checkpoint /
222
+ * tool-result rows are purged separately by the route's purgeSession coordinator. */
68
223
  deleteSession(sessionId: string, owner: string | null): Promise<boolean>;
69
224
  get size(): number;
225
+ /** Graceful shutdown: AWAIT the final sidecar write (bug C) so a restart doesn't lose the last debounced-but-unwritten
226
+ * touch. Cancels any queued debounce, then awaits a flush (which chains after any in-flight write and merges disk). */
70
227
  dispose(): Promise<void>;
71
228
  }
72
229
  //# sourceMappingURL=local-session-store.d.ts.map