@reticlehq/server 2.12.0 → 2.13.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 (386) hide show
  1. package/SKILL.md +67 -109
  2. package/dist/bridge/auth-failure-reason.d.ts +6 -2
  3. package/dist/bridge/auth-failure-reason.js +15 -8
  4. package/dist/bridge/bridge.d.ts +18 -1
  5. package/dist/bridge/bridge.js +247 -164
  6. package/dist/bridge/pairing-token.d.ts +5 -0
  7. package/dist/bridge/pairing-token.js +28 -0
  8. package/dist/bridge/protocol-skew.d.ts +37 -0
  9. package/dist/bridge/protocol-skew.js +45 -0
  10. package/dist/capsule/capsule-store.d.ts +6 -6
  11. package/dist/capsule/causal-summary.js +7 -2
  12. package/dist/cli/cli-doctor.js +31 -1
  13. package/dist/cli/cli-launch.d.ts +11 -1
  14. package/dist/cli/cli-launch.js +59 -10
  15. package/dist/cli/cli-parse.d.ts +15 -1
  16. package/dist/cli/cli-parse.js +212 -8
  17. package/dist/cli/cli-verify.d.ts +1 -0
  18. package/dist/cli/cli-verify.js +3 -2
  19. package/dist/cli/cloud-cli.js +428 -259
  20. package/dist/cli/cloud-keystore.d.ts +37 -0
  21. package/dist/cli/cloud-keystore.js +97 -0
  22. package/dist/cli/cloud-kit.d.ts +37 -0
  23. package/dist/cli/cloud-kit.js +121 -0
  24. package/dist/cli/cloud-login.d.ts +17 -0
  25. package/dist/cli/cloud-login.js +183 -0
  26. package/dist/cli/cloud-session.d.ts +48 -0
  27. package/dist/cli/cloud-session.js +53 -0
  28. package/dist/cli/config-discovery.js +1 -0
  29. package/dist/cli/daemon-start-options.d.ts +32 -0
  30. package/dist/cli/daemon-start-options.js +38 -0
  31. package/dist/cli/device-flow.d.ts +76 -0
  32. package/dist/cli/device-flow.js +56 -0
  33. package/dist/cli/doctor-rows.d.ts +9 -0
  34. package/dist/cli/doctor-rows.js +9 -0
  35. package/dist/cli/drive-attach.d.ts +13 -0
  36. package/dist/cli/drive-attach.js +18 -0
  37. package/dist/cli/drive-command.js +7 -3
  38. package/dist/cli/mcp-command.js +51 -20
  39. package/dist/cli/project-name.d.ts +30 -0
  40. package/dist/cli/project-name.js +44 -0
  41. package/dist/cli/status-next-action.d.ts +14 -0
  42. package/dist/cli/status-next-action.js +4 -4
  43. package/dist/cli.d.ts +1 -0
  44. package/dist/cli.js +134 -80
  45. package/dist/cloud/cloud-config.d.ts +22 -1
  46. package/dist/cloud/cloud-config.js +64 -5
  47. package/dist/cloud/cloud-sync.d.ts +5 -5
  48. package/dist/cloud/cloud-sync.js +33 -2
  49. package/dist/cloud/sync-cycle.d.ts +110 -0
  50. package/dist/cloud/sync-cycle.js +270 -0
  51. package/dist/cloud/sync-daemon.d.ts +69 -0
  52. package/dist/cloud/sync-daemon.js +260 -0
  53. package/dist/cloud/sync-disk.d.ts +9 -0
  54. package/dist/cloud/sync-disk.js +191 -0
  55. package/dist/cloud/sync-hash.d.ts +2 -0
  56. package/dist/cloud/sync-hash.js +35 -0
  57. package/dist/crawl/crawl-tools.js +5 -3
  58. package/dist/crawl/crawl.d.ts +3 -0
  59. package/dist/crawl/crawl.js +5 -0
  60. package/dist/daemon/daemon-resolve.d.ts +43 -0
  61. package/dist/daemon/daemon-resolve.js +69 -0
  62. package/dist/daemon/dev-servers.d.ts +15 -0
  63. package/dist/daemon/dev-servers.js +68 -0
  64. package/dist/daemon/wake-decision.d.ts +32 -0
  65. package/dist/daemon/wake-decision.js +38 -0
  66. package/dist/domain/domain-tools.js +2 -2
  67. package/dist/events/contradictions.d.ts +18 -0
  68. package/dist/events/contradictions.js +134 -21
  69. package/dist/events/declared.d.ts +7 -4
  70. package/dist/events/declared.js +15 -6
  71. package/dist/events/echo-mismatch.js +64 -14
  72. package/dist/events/event-filters.d.ts +8 -0
  73. package/dist/events/event-filters.js +19 -2
  74. package/dist/events/predicate-eval.js +53 -5
  75. package/dist/events/predicate-precheck.d.ts +8 -0
  76. package/dist/events/predicate-precheck.js +41 -0
  77. package/dist/events/predicate-route.d.ts +14 -0
  78. package/dist/events/predicate-route.js +36 -8
  79. package/dist/events/predicate.d.ts +5 -0
  80. package/dist/events/predicate.js +37 -5
  81. package/dist/events/split-text-miss.d.ts +30 -0
  82. package/dist/events/split-text-miss.js +44 -0
  83. package/dist/flows/flake.d.ts +6 -6
  84. package/dist/flows/flow-memory-consult.d.ts +55 -0
  85. package/dist/flows/flow-memory-consult.js +38 -0
  86. package/dist/flows/flow-replay-run.d.ts +18 -7
  87. package/dist/flows/flow-replay-run.js +239 -22
  88. package/dist/flows/flow-replay.js +11 -2
  89. package/dist/flows/flow-step-runners.d.ts +8 -0
  90. package/dist/flows/flow-step-runners.js +8 -2
  91. package/dist/flows/flow-store-for-session.d.ts +31 -0
  92. package/dist/flows/flow-store-for-session.js +33 -0
  93. package/dist/flows/flow-tools.js +58 -32
  94. package/dist/flows/flows.d.ts +8 -0
  95. package/dist/flows/flows.js +468 -2
  96. package/dist/flows/heal-run.js +5 -2
  97. package/dist/flows/predicate-to-expect.d.ts +17 -12
  98. package/dist/flows/predicate-to-expect.js +30 -12
  99. package/dist/flows/recordings.d.ts +13 -1
  100. package/dist/flows/recordings.js +17 -2
  101. package/dist/flows/replay.d.ts +22 -2
  102. package/dist/flows/replay.js +28 -2
  103. package/dist/flows/verify-change-tools.js +5 -2
  104. package/dist/honesty/blind-spots.d.ts +55 -2
  105. package/dist/honesty/blind-spots.js +63 -3
  106. package/dist/honesty/honesty.d.ts +24 -0
  107. package/dist/honesty/honesty.js +25 -1
  108. package/dist/honesty/instrumentation-gaps.d.ts +9 -0
  109. package/dist/honesty/instrumentation-gaps.js +29 -2
  110. package/dist/honesty/verified.d.ts +2 -1
  111. package/dist/honesty/verified.js +16 -1
  112. package/dist/http-server.js +12 -0
  113. package/dist/impact/impact-recorder.d.ts +31 -8
  114. package/dist/impact/impact-recorder.js +104 -21
  115. package/dist/impact/impact-store.d.ts +15 -1
  116. package/dist/impact/impact-store.js +43 -2
  117. package/dist/index.js +113 -7
  118. package/dist/init/agent-rules.d.ts +13 -6
  119. package/dist/init/agent-rules.js +23 -12
  120. package/dist/init/astro-patch.d.ts +16 -0
  121. package/dist/init/astro-patch.js +28 -0
  122. package/dist/init/capabilities.d.ts +4 -1
  123. package/dist/init/capabilities.js +22 -2
  124. package/dist/init/confirm.d.ts +31 -7
  125. package/dist/init/confirm.js +48 -8
  126. package/dist/init/cra.d.ts +20 -4
  127. package/dist/init/cra.js +57 -17
  128. package/dist/init/csp-check.js +17 -2
  129. package/dist/init/csp-doctor.d.ts +8 -1
  130. package/dist/init/csp-doctor.js +8 -3
  131. package/dist/init/dev-script.d.ts +3 -1
  132. package/dist/init/dev-script.js +8 -5
  133. package/dist/init/format-generated.d.ts +18 -0
  134. package/dist/init/format-generated.js +39 -0
  135. package/dist/init/install-hint.d.ts +9 -0
  136. package/dist/init/install-hint.js +29 -0
  137. package/dist/init/mcp-clients.d.ts +7 -0
  138. package/dist/init/mcp-clients.js +7 -0
  139. package/dist/init/mcp.d.ts +1 -1
  140. package/dist/init/mcp.js +1 -1
  141. package/dist/init/node-io.js +11 -1
  142. package/dist/init/plan-framework.js +81 -45
  143. package/dist/init/plan.d.ts +20 -7
  144. package/dist/init/plan.js +20 -45
  145. package/dist/init/preflight.d.ts +28 -0
  146. package/dist/init/preflight.js +38 -0
  147. package/dist/init/run.d.ts +32 -9
  148. package/dist/init/run.js +141 -119
  149. package/dist/init/slash-command.d.ts +1 -1
  150. package/dist/init/snippets.js +41 -25
  151. package/dist/init/vite-config.d.ts +1 -1
  152. package/dist/init/vite-config.js +39 -25
  153. package/dist/init/workspace-apps.d.ts +17 -10
  154. package/dist/init/workspace-apps.js +110 -0
  155. package/dist/input/network-mock-tools.js +3 -6
  156. package/dist/input/real-input.js +25 -5
  157. package/dist/input/scroll-tools.js +4 -6
  158. package/dist/input/viewport-tools.js +5 -4
  159. package/dist/intent/inline-intent.d.ts +10 -19
  160. package/dist/intent/inline-intent.js +91 -1
  161. package/dist/intent/intent-shard-store.d.ts +72 -0
  162. package/dist/intent/intent-shard-store.js +203 -0
  163. package/dist/intent/intent-shard.d.ts +411 -0
  164. package/dist/intent/intent-shard.js +176 -0
  165. package/dist/intent/intent-store.d.ts +12 -0
  166. package/dist/intent/intent-store.js +21 -0
  167. package/dist/intent/intent-subject.d.ts +45 -0
  168. package/dist/intent/intent-subject.js +177 -0
  169. package/dist/intent/intent-tools.js +65 -2
  170. package/dist/intent/open-intents.d.ts +21 -0
  171. package/dist/intent/open-intents.js +15 -0
  172. package/dist/license/license-env.d.ts +29 -0
  173. package/dist/license/license-env.js +148 -0
  174. package/dist/loopback-agent.d.ts +31 -0
  175. package/dist/loopback-agent.js +57 -0
  176. package/dist/mcp/attach-memory.d.ts +18 -2
  177. package/dist/mcp/attach-memory.js +50 -7
  178. package/dist/mcp/client-identity.d.ts +31 -0
  179. package/dist/mcp/client-identity.js +51 -0
  180. package/dist/mcp/mcp-post-transport.d.ts +26 -0
  181. package/dist/mcp/mcp-post-transport.js +109 -0
  182. package/dist/mcp/mcp-proxy.d.ts +2 -1
  183. package/dist/mcp/mcp-proxy.js +52 -62
  184. package/dist/mcp/mcp.js +7 -1
  185. package/dist/mcp/proxy-backoff.d.ts +11 -0
  186. package/dist/mcp/proxy-backoff.js +13 -0
  187. package/dist/mcp/proxy-daemon-probe.d.ts +1 -0
  188. package/dist/mcp/proxy-daemon-probe.js +7 -1
  189. package/dist/mcp/proxy-handshake.d.ts +23 -0
  190. package/dist/mcp/proxy-handshake.js +31 -0
  191. package/dist/mcp/tool-catalog-cache.d.ts +8 -0
  192. package/dist/mcp/tool-catalog-cache.js +12 -0
  193. package/dist/memory/memory-tools.d.ts +2 -0
  194. package/dist/memory/memory-tools.js +82 -0
  195. package/dist/memory/project-memory.d.ts +34 -0
  196. package/dist/memory/project-memory.js +96 -0
  197. package/dist/oracles/propose-consequences.js +12 -3
  198. package/dist/pool/browser-pool.d.ts +63 -4
  199. package/dist/pool/browser-pool.js +113 -4
  200. package/dist/pool/playwright-launcher.js +9 -0
  201. package/dist/project/project-tools.js +3 -3
  202. package/dist/project/reticle-dir.d.ts +15 -2
  203. package/dist/project/reticle-dir.js +21 -4
  204. package/dist/runs/run-store.d.ts +10 -0
  205. package/dist/runs/run-store.js +10 -0
  206. package/dist/runs/verification-sync.d.ts +0 -11
  207. package/dist/runs/verification-sync.js +22 -1
  208. package/dist/runs/verify-server.d.ts +8 -1
  209. package/dist/runs/verify-server.js +14 -2
  210. package/dist/session/command-timeout.d.ts +5 -2
  211. package/dist/session/command-timeout.js +5 -4
  212. package/dist/session/lease-visibility.d.ts +67 -0
  213. package/dist/session/lease-visibility.js +76 -0
  214. package/dist/session/no-session-diagnosis.d.ts +23 -0
  215. package/dist/session/no-session-diagnosis.js +58 -17
  216. package/dist/session/no-session-next-action.d.ts +7 -0
  217. package/dist/session/no-session-next-action.js +42 -3
  218. package/dist/session/no-session-watch.d.ts +10 -6
  219. package/dist/session/no-session-watch.js +51 -19
  220. package/dist/session/pending-commands.d.ts +11 -1
  221. package/dist/session/pending-commands.js +12 -2
  222. package/dist/session/resolve-within.d.ts +34 -0
  223. package/dist/session/resolve-within.js +53 -0
  224. package/dist/session/session-info.d.ts +18 -0
  225. package/dist/session/session-info.js +11 -0
  226. package/dist/session/session-manager.d.ts +14 -0
  227. package/dist/session/session-manager.js +61 -3
  228. package/dist/session/session-mirror.d.ts +16 -0
  229. package/dist/session/session-mirror.js +22 -0
  230. package/dist/session/session-recommendation.d.ts +19 -5
  231. package/dist/session/session-recommendation.js +25 -9
  232. package/dist/session/session-successor.js +36 -1
  233. package/dist/session/session-tools.js +2 -2
  234. package/dist/session/session.d.ts +22 -2
  235. package/dist/session/session.js +87 -7
  236. package/dist/session/wall-clock.d.ts +12 -0
  237. package/dist/session/wall-clock.js +14 -0
  238. package/dist/setup/agent-configs.d.ts +96 -0
  239. package/dist/setup/agent-configs.js +333 -0
  240. package/dist/setup/agent-io.d.ts +9 -0
  241. package/dist/setup/agent-io.js +16 -0
  242. package/dist/setup/agent-writer.d.ts +51 -0
  243. package/dist/setup/agent-writer.js +115 -0
  244. package/dist/setup/approval-migration.d.ts +47 -0
  245. package/dist/setup/approval-migration.js +68 -0
  246. package/dist/setup/auto-approve.d.ts +85 -0
  247. package/dist/setup/auto-approve.js +150 -0
  248. package/dist/setup/bridge-port.d.ts +15 -0
  249. package/dist/setup/bridge-port.js +24 -0
  250. package/dist/setup/desktop-shape.d.ts +57 -0
  251. package/dist/setup/desktop-shape.js +63 -0
  252. package/dist/setup/dev-server-wait.d.ts +60 -0
  253. package/dist/setup/dev-server-wait.js +65 -0
  254. package/dist/setup/drive-agent.d.ts +71 -0
  255. package/dist/setup/drive-agent.js +171 -0
  256. package/dist/setup/drive-plan.d.ts +68 -0
  257. package/dist/setup/drive-plan.js +130 -0
  258. package/dist/setup/ensure-daemon.d.ts +29 -0
  259. package/dist/setup/ensure-daemon.js +58 -0
  260. package/dist/setup/init-runtime.d.ts +47 -0
  261. package/dist/setup/init-runtime.js +160 -0
  262. package/dist/setup/interrupt.d.ts +25 -0
  263. package/dist/setup/interrupt.js +40 -0
  264. package/dist/setup/license-key.d.ts +39 -0
  265. package/dist/setup/license-key.js +72 -0
  266. package/dist/setup/listeners.d.ts +37 -0
  267. package/dist/setup/listeners.js +85 -0
  268. package/dist/setup/node-effects.d.ts +60 -0
  269. package/dist/setup/node-effects.js +210 -0
  270. package/dist/setup/page-probe.d.ts +39 -0
  271. package/dist/setup/page-probe.js +49 -0
  272. package/dist/setup/relaunch.d.ts +36 -0
  273. package/dist/setup/relaunch.js +57 -0
  274. package/dist/setup/remaining-steps.d.ts +19 -0
  275. package/dist/setup/remaining-steps.js +31 -0
  276. package/dist/setup/run-setup.d.ts +99 -0
  277. package/dist/setup/run-setup.js +187 -0
  278. package/dist/setup/session-pick.d.ts +47 -0
  279. package/dist/setup/session-pick.js +51 -0
  280. package/dist/setup/setup-command.d.ts +45 -0
  281. package/dist/setup/setup-command.js +199 -0
  282. package/dist/setup/setup-options.d.ts +74 -0
  283. package/dist/setup/setup-options.js +67 -0
  284. package/dist/setup/transcripts.d.ts +16 -0
  285. package/dist/setup/transcripts.js +43 -0
  286. package/dist/status-payload.d.ts +14 -1
  287. package/dist/status-payload.js +23 -1
  288. package/dist/telemetry/daemon-telemetry.d.ts +8 -1
  289. package/dist/telemetry/daemon-telemetry.js +52 -5
  290. package/dist/telemetry/error-class.js +1 -1
  291. package/dist/telemetry/feedback-context.d.ts +9 -1
  292. package/dist/telemetry/feedback-context.js +60 -29
  293. package/dist/telemetry/feedback-local.d.ts +15 -0
  294. package/dist/telemetry/feedback-local.js +56 -0
  295. package/dist/telemetry/feedback.d.ts +11 -0
  296. package/dist/telemetry/feedback.js +19 -6
  297. package/dist/telemetry/init-telemetry.d.ts +2 -0
  298. package/dist/telemetry/init-telemetry.js +2 -0
  299. package/dist/telemetry/install-source.d.ts +14 -0
  300. package/dist/telemetry/install-source.js +30 -0
  301. package/dist/telemetry/license-activation.d.ts +7 -1
  302. package/dist/telemetry/license-activation.js +9 -5
  303. package/dist/telemetry/mcp-connection.js +7 -0
  304. package/dist/telemetry/project-profile.d.ts +12 -1
  305. package/dist/telemetry/project-profile.js +11 -6
  306. package/dist/telemetry/proxy-telemetry.d.ts +3 -0
  307. package/dist/telemetry/proxy-telemetry.js +21 -0
  308. package/dist/telemetry/session-metrics.d.ts +12 -0
  309. package/dist/telemetry/session-metrics.js +35 -1
  310. package/dist/telemetry/telemetry.js +17 -2
  311. package/dist/telemetry/tool-refused.d.ts +3 -1
  312. package/dist/telemetry/tool-refused.js +34 -2
  313. package/dist/tools/act-capsule.d.ts +10 -0
  314. package/dist/tools/act-capsule.js +8 -2
  315. package/dist/tools/act-danger.d.ts +2 -1
  316. package/dist/tools/act-danger.js +11 -3
  317. package/dist/tools/act-observation.d.ts +41 -0
  318. package/dist/tools/act-observation.js +36 -0
  319. package/dist/tools/act-preflight.d.ts +20 -0
  320. package/dist/tools/act-preflight.js +98 -0
  321. package/dist/tools/act-sequence-retry.d.ts +45 -0
  322. package/dist/tools/act-sequence-retry.js +58 -0
  323. package/dist/tools/act-sequence-tool.d.ts +13 -0
  324. package/dist/tools/act-sequence-tool.js +135 -0
  325. package/dist/tools/act-target.d.ts +14 -0
  326. package/dist/tools/act-target.js +47 -0
  327. package/dist/tools/act-tools.d.ts +21 -1
  328. package/dist/tools/act-tools.js +100 -213
  329. package/dist/tools/assert-verdict.js +22 -16
  330. package/dist/tools/browser-tools.js +6 -2
  331. package/dist/tools/dynamic-tools.js +24 -5
  332. package/dist/tools/error-recovery.d.ts +1 -0
  333. package/dist/tools/error-recovery.js +8 -0
  334. package/dist/tools/invoke-tool.js +59 -9
  335. package/dist/tools/lease-tools.d.ts +30 -4
  336. package/dist/tools/lease-tools.js +169 -5
  337. package/dist/tools/merged-name-redirect.d.ts +13 -0
  338. package/dist/tools/merged-name-redirect.js +22 -0
  339. package/dist/tools/numeric-bounds.d.ts +100 -0
  340. package/dist/tools/numeric-bounds.js +125 -0
  341. package/dist/tools/observe-tools.js +47 -40
  342. package/dist/tools/read-tools.js +28 -7
  343. package/dist/tools/real-input-attempt.d.ts +10 -0
  344. package/dist/tools/real-input-attempt.js +59 -1
  345. package/dist/tools/reconcile-tools.js +4 -4
  346. package/dist/tools/tool-kit.d.ts +12 -0
  347. package/dist/tools/tool-kit.js +6 -1
  348. package/dist/tools/tool-names.d.ts +2 -0
  349. package/dist/tools/tool-names.js +2 -0
  350. package/dist/tools/tools-helpers.d.ts +19 -0
  351. package/dist/tools/tools-helpers.js +46 -0
  352. package/dist/tools/tools.d.ts +2 -0
  353. package/dist/tools/tools.js +56 -8
  354. package/dist/update/reticle-deps.d.ts +9 -0
  355. package/dist/update/reticle-deps.js +27 -0
  356. package/dist/update/sdk-sync.d.ts +1 -2
  357. package/dist/update/sdk-sync.js +1 -21
  358. package/dist/update/update-nudge.d.ts +18 -0
  359. package/dist/update/update-nudge.js +20 -0
  360. package/dist/version/peer-announce.js +4 -2
  361. package/dist/version/sdk-fix.d.ts +47 -0
  362. package/dist/version/sdk-fix.js +127 -0
  363. package/dist/version/version-nudge.d.ts +14 -0
  364. package/dist/version/version-nudge.js +21 -0
  365. package/dist/version/version-skew.d.ts +38 -3
  366. package/dist/version/version-skew.js +83 -7
  367. package/dist/visual/visual-store.d.ts +6 -6
  368. package/dist/visual/visual-store.js +18 -16
  369. package/dist/visual/visual-tools.js +57 -12
  370. package/docs/cli/doctor.mdx +1 -0
  371. package/docs/cli/serve.mdx +4 -2
  372. package/docs/cli.mdx +7 -3
  373. package/docs/desktop.mdx +1 -1
  374. package/docs/docs.json +1 -1
  375. package/docs/getting-started.md +19 -3
  376. package/docs/index.mdx +9 -6
  377. package/docs/install-agentic.mdx +38 -12
  378. package/docs/install-manual.mdx +1 -1
  379. package/docs/packages.mdx +1 -1
  380. package/docs/skill-file.mdx +3 -3
  381. package/docs/telemetry-contract.md +108 -4
  382. package/docs/tools-act-sequence.mdx +16 -0
  383. package/docs/usage.md +1 -1
  384. package/package.json +4 -3
  385. package/dist/init/cursor.d.ts +0 -24
  386. package/dist/init/cursor.js +0 -80
@@ -0,0 +1,176 @@
1
+ /**
2
+ * The sharded intent store: one small file per subject, plus an index cheap enough to always load.
3
+ *
4
+ * ## Why this exists
5
+ *
6
+ * `.reticle/intent.json` was a single object that reached 141 entries and 109KB. Parsing that is
7
+ * nothing; READING it is the cost, and reading is what this store is for. An agent wanting the two
8
+ * rules about checkout pulled 139 irrelevant ones through its context to find them, and an agent
9
+ * changing one rewrote the whole file — which is both slow to review and a lost write whenever two
10
+ * sessions touch different subjects at once.
11
+ *
12
+ * ## The shape
13
+ *
14
+ * .reticle/intent/index.json every id, its subject and one line of prose
15
+ * .reticle/intent/<subject>.json the full records for that subject
16
+ *
17
+ * The index is the whole point: it answers "what do we know, and where does it live?" without
18
+ * opening anything, and detail is then fetched for the one subject in play. Measured on the real
19
+ * corpus, that is 109KB all-or-nothing becoming an index plus one shard — and the largest shard is
20
+ * under 10KB once the unsorted bucket is set aside.
21
+ *
22
+ * The index is NOT tiny, and measuring beat guessing twice over. With full statements it came to
23
+ * 36KB for 141 entries; summarising them saved 7%, because the bulk is not the prose but the ids —
24
+ * `inline:signing-in-with-the-email-password-created-earli-6ca804e9` is 63 characters before the
25
+ * statement starts. So the honest numbers are: 109KB all-or-nothing becomes a 33KB index plus one
26
+ * ~10KB shard, and the real win is that a READ and a WRITE are both bounded to one subject rather
27
+ * than the whole corpus.
28
+ *
29
+ * The index is therefore the part that does not scale forever. At ten times this size it needs a
30
+ * second tier — subjects and counts, with ids fetched per subject — rather than a longer single
31
+ * read. Recorded here because the next person will hit it, and the shape of the fix is already
32
+ * visible.
33
+ *
34
+ * ## What the records carry that the old ones did not
35
+ *
36
+ * The legacy file was written BY verification, AT verification time, in verification's vocabulary: a
37
+ * statement, a predicate, and whether a verdict discharged it. Of 141 entries, four named a surface.
38
+ * There was nowhere to put the reason a thing must be true, who decided it, or when — so the
39
+ * business case somebody states once and then forgets had no home and was never captured.
40
+ *
41
+ * `why`, `source` and `subject` are that home. They are optional because a migrated record cannot
42
+ * invent them, and a store that rejected incomplete records would simply not be written to.
43
+ */
44
+ import { z } from 'zod';
45
+ import { IntentSchema } from '@reticlehq/core';
46
+ import { subjectFor, UNSORTED_SUBJECT } from './intent-subject.js';
47
+ export const INTENT_SHARD_VERSION = 1;
48
+ /** Byte-stable writes: an unchanged shard produces no diff, so the ones that DID change stand out. */
49
+ const JSON_INDENT = 2;
50
+ /**
51
+ * How settled a record is.
52
+ *
53
+ * Separate from the legacy `state`, which only ever described the VERIFICATION lifecycle
54
+ * (declared → bound → proved). A rule can be agreed with the customer months before anything can
55
+ * prove it, and collapsing those two axes is what made the old file an assertion log rather than a
56
+ * memory.
57
+ */
58
+ export const IntentStatus = {
59
+ /** Captured, not yet confirmed by anyone. What an agent writes while building. */
60
+ PROPOSED: 'proposed',
61
+ /** Confirmed as something that must hold. May have no way to prove it yet. */
62
+ AGREED: 'agreed',
63
+ /** A verdict has actually shown it holds. */
64
+ PROVED: 'proved',
65
+ /** Believed out of date — kept, because deleting the record loses the fact it was ever true. */
66
+ STALE: 'stale',
67
+ };
68
+ export const IntentRecordSchema = IntentSchema.extend({
69
+ /** Which shard this lives in. Stored as well as implied, so a file read alone is self-describing. */
70
+ subject: z.string().min(1),
71
+ status: z.enum([
72
+ IntentStatus.PROPOSED,
73
+ IntentStatus.AGREED,
74
+ IntentStatus.PROVED,
75
+ IntentStatus.STALE,
76
+ ]),
77
+ /** WHY it must be true. The half the old file had no room for. */
78
+ why: z.string().optional(),
79
+ /** Where it came from — "the user, in conversation" beats an anonymous assertion in six months. */
80
+ source: z.string().optional(),
81
+ /** When it was last touched, so a stale-looking record can be told from an untouched one. */
82
+ updatedAt: z.number().optional(),
83
+ });
84
+ export const IntentShardSchema = z.object({
85
+ version: z.literal(INTENT_SHARD_VERSION),
86
+ subject: z.string().min(1),
87
+ intents: z.record(z.string(), IntentRecordSchema),
88
+ });
89
+ /**
90
+ * How much of a statement the index carries.
91
+ *
92
+ * The index exists to answer WHICH SHARD, and a clause is enough to decide that; the sentence is one
93
+ * file away. Ellipsis included so a truncated line is never mistaken for the whole intent.
94
+ *
95
+ * Worth 7% on the real corpus rather than the large saving expected — the ids dominate — but it also
96
+ * bounds the damage a future 500-character statement can do to a file meant to be read every
97
+ * session, which is the reason to keep it.
98
+ */
99
+ const SUMMARY_MAX = 72;
100
+ export const summarise = (statement) => statement.length <= SUMMARY_MAX ? statement : `${statement.slice(0, SUMMARY_MAX - 1).trimEnd()}…`;
101
+ /** One line per intent: enough to decide whether to open the shard, and no more. */
102
+ export const IntentIndexEntrySchema = z.object({
103
+ id: z.string().min(1),
104
+ subject: z.string().min(1),
105
+ statement: z.string().min(1),
106
+ status: z.enum([
107
+ IntentStatus.PROPOSED,
108
+ IntentStatus.AGREED,
109
+ IntentStatus.PROVED,
110
+ IntentStatus.STALE,
111
+ ]),
112
+ });
113
+ export const IntentIndexSchema = z.object({
114
+ version: z.literal(INTENT_SHARD_VERSION),
115
+ entries: z.array(IntentIndexEntrySchema),
116
+ });
117
+ export const emptyShard = (subject) => ({
118
+ version: INTENT_SHARD_VERSION,
119
+ subject,
120
+ intents: {},
121
+ });
122
+ export const emptyIndex = () => ({ version: INTENT_SHARD_VERSION, entries: [] });
123
+ /** The verification lifecycle a legacy record carried, mapped onto the settledness axis. */
124
+ export const statusFromState = (state) => 'proved' === state ? IntentStatus.PROVED : IntentStatus.AGREED;
125
+ /**
126
+ * Turn a legacy intent into a record, inferring only what can be inferred.
127
+ *
128
+ * `why` and `source` are left ABSENT rather than filled with the statement or a placeholder. A
129
+ * record that claims to carry a reason it does not have is worse than one that admits the gap: the
130
+ * gap is a prompt to write the reason down, and a placeholder is a reason to stop looking.
131
+ */
132
+ export const recordFromIntent = (intent) => ({
133
+ ...intent,
134
+ subject: subjectFor({ surface: intent.surface, binding: intent.binding }),
135
+ status: statusFromState(intent.state),
136
+ });
137
+ /** Build the index from the shards. Derived, never hand-maintained — two sources would disagree. */
138
+ export const indexFrom = (shards) => ({
139
+ version: INTENT_SHARD_VERSION,
140
+ entries: shards
141
+ .flatMap((s) => Object.values(s.intents))
142
+ .map((r) => ({
143
+ id: r.id,
144
+ subject: r.subject,
145
+ statement: summarise(r.statement),
146
+ status: r.status,
147
+ }))
148
+ .sort((a, b) => a.subject.localeCompare(b.subject) || a.id.localeCompare(b.id)),
149
+ });
150
+ /** Group records into shards by their own subject. */
151
+ export const shardsFrom = (records) => {
152
+ const bySubject = new Map();
153
+ for (const r of records) {
154
+ const subject = '' === r.subject ? UNSORTED_SUBJECT : r.subject;
155
+ const shard = bySubject.get(subject) ?? emptyShard(subject);
156
+ shard.intents[r.id] = r;
157
+ bySubject.set(subject, shard);
158
+ }
159
+ return [...bySubject.values()].sort((a, b) => a.subject.localeCompare(b.subject));
160
+ };
161
+ /** Serialise byte-stably, with keys sorted so a re-save of unchanged data is a no-op diff. */
162
+ export const serialise = (value) => `${JSON.stringify(value, (_k, v) => sortKeys(v), JSON_INDENT)}\n`;
163
+ const sortKeys = (value) => {
164
+ if (Array.isArray(value) || null === value || typeof value !== 'object')
165
+ return value;
166
+ return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)));
167
+ };
168
+ /** Read + validate one JSON file, failing soft: a hand-merged file with a conflict marker is real. */
169
+ export const readJsonFile = async (fs, path, parse, fallback) => {
170
+ try {
171
+ return parse(JSON.parse(await fs.readFile(path)));
172
+ }
173
+ catch {
174
+ return fallback;
175
+ }
176
+ };
@@ -22,6 +22,18 @@ export declare class IntentStore {
22
22
  surface?: IntentSurface;
23
23
  }[]): Promise<Intent[]>;
24
24
  /** Attach the predicate that would prove an intent. False when the id names nothing. */
25
+ /**
26
+ * File a record under where it turned out to be about.
27
+ *
28
+ * Separate from `declare` because the two happen at different MOMENTS and know different things.
29
+ * An inline intent is declared BEFORE the action — deliberately, so a verdict can see it open —
30
+ * and at that instant the agent is still on the page it is leaving. The route that describes what
31
+ * the intent is ABOUT only exists after the consequence lands.
32
+ *
33
+ * Write-once: an existing surface is never overwritten. A record placed by an agent that named its
34
+ * own subject must not be re-filed by a later run that happened to be somewhere else.
35
+ */
36
+ place(id: string, surface: IntentSurface): Promise<boolean>;
25
37
  bind(id: string, binding: unknown): Promise<boolean>;
26
38
  /**
27
39
  * Record that a verdict proved an intent.
@@ -80,6 +80,27 @@ export class IntentStore {
80
80
  });
81
81
  }
82
82
  /** Attach the predicate that would prove an intent. False when the id names nothing. */
83
+ /**
84
+ * File a record under where it turned out to be about.
85
+ *
86
+ * Separate from `declare` because the two happen at different MOMENTS and know different things.
87
+ * An inline intent is declared BEFORE the action — deliberately, so a verdict can see it open —
88
+ * and at that instant the agent is still on the page it is leaving. The route that describes what
89
+ * the intent is ABOUT only exists after the consequence lands.
90
+ *
91
+ * Write-once: an existing surface is never overwritten. A record placed by an agent that named its
92
+ * own subject must not be re-filed by a later run that happened to be somewhere else.
93
+ */
94
+ async place(id, surface) {
95
+ return withFileLock(this.#path(), async () => {
96
+ const file = await this.#load();
97
+ const existing = file.intents[id];
98
+ if (existing === undefined || existing.surface !== undefined)
99
+ return false;
100
+ await this.#save(upsertIntent(file, { ...existing, surface }));
101
+ return true;
102
+ });
103
+ }
83
104
  async bind(id, binding) {
84
105
  return withFileLock(this.#path(), async () => {
85
106
  const file = await this.#load();
@@ -0,0 +1,45 @@
1
+ /**
2
+ * What an intent is ABOUT — the key the store shards on, and the thing that makes it retrievable.
3
+ *
4
+ * `.reticle/intent.json` reached 141 entries and 109KB as one object. That is not expensive to
5
+ * parse; it is expensive to READ, which is the operation that matters here. An agent that wants the
6
+ * two rules about checkout has to pull 139 irrelevant ones through its context to find them, and an
7
+ * agent that wants to change one has to rewrite the whole file.
8
+ *
9
+ * Sharding by subject fixes both, but only if the subject is DERIVABLE. A store that requires every
10
+ * caller to invent a category is one where everything lands in whatever the first caller typed. So
11
+ * the subject is inferred from evidence the intent already carries, in falling order of reliability:
12
+ *
13
+ * 1. an explicit subject, when the caller knows one
14
+ * 2. the flow it belongs to — the strongest signal, because a flow IS a feature
15
+ * 3. the route it touches, which is how the product is navigated and therefore how it is discussed
16
+ * 4. the feature directory of the FILE its verdict acted on — the grouping the codebase already
17
+ * states about itself
18
+ * 5. the API path its binding asserts on, which names the domain even when the UI does not
19
+ * 6. failing all of that, a single shared bucket — visibly unsorted rather than silently misfiled
20
+ *
21
+ * Nothing here guesses from prose. A statement is a sentence written for a human, and clustering
22
+ * sentences is exactly the kind of plausible-looking inference that puts "sign-in works" under
23
+ * `settings` and leaves nobody able to explain why.
24
+ */
25
+ /** Where an intent goes when nothing about it says where it belongs. Deliberately obvious. */
26
+ export declare const UNSORTED_SUBJECT = "unsorted";
27
+ /** Shape enough of an intent to derive a subject, without importing the whole record. */
28
+ export interface SubjectEvidence {
29
+ subject?: string | undefined;
30
+ surface?: {
31
+ route?: string | undefined;
32
+ flow?: string | undefined;
33
+ files?: string[] | undefined;
34
+ } | undefined;
35
+ binding?: unknown;
36
+ }
37
+ /** A filesystem- and URL-safe slug. Same rules as a project id, for the same reasons. */
38
+ export declare const slugifySubject: (raw: string) => string;
39
+ /**
40
+ * The subject for one intent, by the ladder above.
41
+ *
42
+ * Total: it always returns something, because a store that can refuse to place a record is a store
43
+ * that loses records.
44
+ */
45
+ export declare const subjectFor: (evidence: SubjectEvidence) => string;
@@ -0,0 +1,177 @@
1
+ /**
2
+ * What an intent is ABOUT — the key the store shards on, and the thing that makes it retrievable.
3
+ *
4
+ * `.reticle/intent.json` reached 141 entries and 109KB as one object. That is not expensive to
5
+ * parse; it is expensive to READ, which is the operation that matters here. An agent that wants the
6
+ * two rules about checkout has to pull 139 irrelevant ones through its context to find them, and an
7
+ * agent that wants to change one has to rewrite the whole file.
8
+ *
9
+ * Sharding by subject fixes both, but only if the subject is DERIVABLE. A store that requires every
10
+ * caller to invent a category is one where everything lands in whatever the first caller typed. So
11
+ * the subject is inferred from evidence the intent already carries, in falling order of reliability:
12
+ *
13
+ * 1. an explicit subject, when the caller knows one
14
+ * 2. the flow it belongs to — the strongest signal, because a flow IS a feature
15
+ * 3. the route it touches, which is how the product is navigated and therefore how it is discussed
16
+ * 4. the feature directory of the FILE its verdict acted on — the grouping the codebase already
17
+ * states about itself
18
+ * 5. the API path its binding asserts on, which names the domain even when the UI does not
19
+ * 6. failing all of that, a single shared bucket — visibly unsorted rather than silently misfiled
20
+ *
21
+ * Nothing here guesses from prose. A statement is a sentence written for a human, and clustering
22
+ * sentences is exactly the kind of plausible-looking inference that puts "sign-in works" under
23
+ * `settings` and leaves nobody able to explain why.
24
+ */
25
+ /** Where an intent goes when nothing about it says where it belongs. Deliberately obvious. */
26
+ export const UNSORTED_SUBJECT = 'unsorted';
27
+ /** The longest a subject may be. It is a filename, and it is read in a directory listing. */
28
+ const MAX_SUBJECT = 40;
29
+ /** A filesystem- and URL-safe slug. Same rules as a project id, for the same reasons. */
30
+ export const slugifySubject = (raw) => {
31
+ const slug = raw
32
+ .toLowerCase()
33
+ .replace(/[^a-z0-9]+/g, '-')
34
+ .replace(/^-+|-+$/g, '')
35
+ .slice(0, MAX_SUBJECT)
36
+ .replace(/-+$/g, '');
37
+ return 0 === slug.length ? UNSORTED_SUBJECT : slug;
38
+ };
39
+ /** The first path segment of a route or URL — `/issues?x=1` and `/v1/issues` both give `issues`. */
40
+ const firstSegment = (path) => {
41
+ const clean = path.split(/[?#]/)[0] ?? '';
42
+ for (const part of clean.split('/')) {
43
+ // Skip empties, the API version prefix, and anything that is plainly an id rather than a name.
44
+ if ('' === part || /^v\d+$/i.test(part) || /^\d+$/.test(part))
45
+ continue;
46
+ /*
47
+ * A QUERY FRAGMENT is not a path segment.
48
+ *
49
+ * A `net` predicate's `urlContains` is frequently a filter rather than a URL —
50
+ * `category=vulnerability%2Csevere`, `projectId=storefront` — and with no `?` to split on, the
51
+ * whole thing survived as a "path" and was slugified into a subject. Measured on a real corpus:
52
+ * six of thirty-four subjects were query values, one record each, and together they made the
53
+ * coverage map read as a product with two dozen tiny unrelated areas.
54
+ *
55
+ * Skipped rather than aborting the walk, so a binding that asserts a filter AND a route still
56
+ * finds the route.
57
+ */
58
+ if (part.includes('=') || part.includes('&'))
59
+ continue;
60
+ return part;
61
+ }
62
+ return undefined;
63
+ };
64
+ /** Walk a binding predicate tree for the first route or URL it mentions. */
65
+ const fromBinding = (binding) => {
66
+ if (typeof binding !== 'object' || null === binding)
67
+ return undefined;
68
+ const node = binding;
69
+ const direct = node['pathname'] ?? node['urlContains'] ?? node['path'];
70
+ if ('string' === typeof direct) {
71
+ const seg = firstSegment(direct);
72
+ if (seg !== undefined)
73
+ return seg;
74
+ }
75
+ const nested = node['predicates'] ?? node['of'];
76
+ if (Array.isArray(nested)) {
77
+ for (const child of nested) {
78
+ const found = fromBinding(child);
79
+ if (found !== undefined)
80
+ return found;
81
+ }
82
+ }
83
+ return undefined;
84
+ };
85
+ /**
86
+ * Directory names that group CODE rather than name a feature.
87
+ *
88
+ * `src/ui/input.tsx` is every screen's shared control; filing knowledge under `ui` would put
89
+ * sign-in, billing and issues in one bucket named after a folder. Walked past rather than accepted,
90
+ * and if every directory is generic the file yields nothing — which is honest, because it genuinely
91
+ * did not say what the record is about.
92
+ */
93
+ const GENERIC_DIRS = new Set([
94
+ 'src',
95
+ 'app',
96
+ 'apps',
97
+ 'lib',
98
+ 'libs',
99
+ 'packages',
100
+ 'components',
101
+ 'ui',
102
+ 'utils',
103
+ 'util',
104
+ 'helpers',
105
+ 'shared',
106
+ 'common',
107
+ 'core',
108
+ 'pages',
109
+ 'features',
110
+ 'modules',
111
+ 'screens',
112
+ 'views',
113
+ 'test',
114
+ 'tests',
115
+ '__tests__',
116
+ 'dist',
117
+ 'build',
118
+ 'node_modules',
119
+ ]);
120
+ /**
121
+ * The feature a file belongs to: the deepest directory that names something.
122
+ *
123
+ * A codebase already groups itself by feature, and the directory a file sits in is that grouping
124
+ * stated by the people who wrote it — structural evidence, not an inference from prose. Measured
125
+ * against the alternative before being written: 29 unsorted records carried a testid, and using the
126
+ * testid's prefix would have produced `confirm`, `new` and `delete` — verbs rather than areas.
127
+ */
128
+ const featureOfFile = (file) => {
129
+ // Windows paths arrive from Windows machines; splitting on `/` alone leaves one long segment.
130
+ const parts = file.split(/[/\\]/).filter((p) => p !== '');
131
+ // The last part is the filename, never a feature.
132
+ for (let i = parts.length - 2; i >= 0; i--) {
133
+ const dir = parts[i];
134
+ if (dir === undefined || GENERIC_DIRS.has(dir.toLowerCase()))
135
+ continue;
136
+ return dir;
137
+ }
138
+ return undefined;
139
+ };
140
+ /**
141
+ * The subject for one intent, by the ladder above.
142
+ *
143
+ * Total: it always returns something, because a store that can refuse to place a record is a store
144
+ * that loses records.
145
+ */
146
+ export const subjectFor = (evidence) => {
147
+ const explicit = evidence.subject;
148
+ if ('string' === typeof explicit && explicit.trim() !== '')
149
+ return slugifySubject(explicit);
150
+ const flow = evidence.surface?.flow;
151
+ if ('string' === typeof flow && flow.trim() !== '')
152
+ return slugifySubject(flow);
153
+ const route = evidence.surface?.route;
154
+ if ('string' === typeof route) {
155
+ const seg = firstSegment(route);
156
+ if (seg !== undefined)
157
+ return slugifySubject(seg);
158
+ }
159
+ /*
160
+ * The file, before the binding. A path names the feature the code lives in; a binding's API path
161
+ * names the domain only indirectly, and its element predicates name controls rather than areas.
162
+ */
163
+ const files = evidence.surface?.files;
164
+ if (Array.isArray(files)) {
165
+ for (const file of files) {
166
+ if ('string' !== typeof file || '' === file)
167
+ continue;
168
+ const feature = featureOfFile(file);
169
+ if (feature !== undefined)
170
+ return slugifySubject(feature);
171
+ }
172
+ }
173
+ const bound = fromBinding(evidence.binding);
174
+ if (bound !== undefined)
175
+ return slugifySubject(bound);
176
+ return UNSORTED_SUBJECT;
177
+ };
@@ -1,5 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { IntentStore } from './intent-store.js';
3
+ import { IntentShardStore } from './intent-shard-store.js';
4
+ import { IntentStatus } from './intent-shard.js';
3
5
  import { ReticleTool } from '../tools/tool-names.js';
4
6
  import { sessionIdShape } from '../tools/tool-kit.js';
5
7
  import { sessionRoot } from '../project/session-root.js';
@@ -17,10 +19,16 @@ import { asString } from '../tools/tools-helpers.js';
17
19
  const DECLARE = 'declare';
18
20
  const LIST = 'list';
19
21
  const BIND = 'bind';
22
+ /* The sharded store's surface. Same tool, because a second tool name is a second thing to discover. */
23
+ const INDEX = 'index';
24
+ const SUBJECT = 'subject';
25
+ const GET = 'get';
26
+ const RECORD = 'record';
27
+ const MIGRATE = 'migrate';
20
28
  export const INTENT_TOOLS = [
21
29
  {
22
30
  name: ReticleTool.INTENT,
23
- description: 'Record what a change is SUPPOSED to make true, in your own words, while you still know — then verification does not have to re-derive it from the DOM later. { action:"declare", intents:[{ id, statement, surface? }] } takes prose and needs NO predicate: at declare time there is often no route, no ref and no code yet, and a predicate demanded there is just a mechanism. Declare EARLY (as you build) and batch them — one call per feature is the whole budget. { action:"bind", id, binding } attaches the predicate that would prove it once you know how; an intent with no binding is not a failure, it is the most interesting row in the ledger — something meant that nothing can currently prove. { action:"list" } returns what is still open. Stored in .reticle/intent.json, git-checked so a human sees in review if an intent was later narrowed to match what was easy to prove.',
31
+ description: 'Record what a change is SUPPOSED to make true, as a durable statement ABOUT THE PRODUCT that a teammate who was not here will understand in six months — name the behaviour, not this run or its step number, and never "renders cleanly", which nothing can check. It is SHARED memory: pooled per project and read back by later agents. Capture it while you still know — then verification does not have to re-derive it from the DOM later. { action:"declare", intents:[{ id, statement, surface? }] } takes prose and needs NO predicate: at declare time there is often no route, no ref and no code yet, and a predicate demanded there is just a mechanism. Declare EARLY (as you build) and batch them — one call per feature is the whole budget. { action:"bind", id, binding } attaches the predicate that would prove it once you know how; an intent with no binding is not a failure, it is the most interesting row in the ledger — something meant that nothing can currently prove. { action:"list" } returns what is still open. Stored in .reticle/intent.json, git-checked so a human sees in review if an intent was later narrowed to match what was easy to prove.',
24
32
  example: {
25
33
  action: DECLARE,
26
34
  intents: [
@@ -28,7 +36,24 @@ export const INTENT_TOOLS = [
28
36
  ],
29
37
  },
30
38
  inputSchema: {
31
- action: z.enum([DECLARE, LIST, BIND]),
39
+ action: z.enum([DECLARE, LIST, BIND, INDEX, SUBJECT, GET, RECORD, MIGRATE]),
40
+ subject: z
41
+ .string()
42
+ .optional()
43
+ .describe('subject/record: what the intent is ABOUT — the shard it lives in.'),
44
+ statement: z.string().optional().describe('record only: what must be true, in prose.'),
45
+ why: z
46
+ .string()
47
+ .optional()
48
+ .describe('record only: WHY it must be true. The thing somebody says once and forgets.'),
49
+ source: z
50
+ .string()
51
+ .optional()
52
+ .describe('record only: where it came from — a person, a ticket, a conversation.'),
53
+ status: z
54
+ .enum([IntentStatus.PROPOSED, IntentStatus.AGREED, IntentStatus.PROVED, IntentStatus.STALE])
55
+ .optional()
56
+ .describe('record only: how settled it is. Defaults to proposed.'),
32
57
  intents: z
33
58
  .array(z.object({
34
59
  id: z.string(),
@@ -57,11 +82,49 @@ export const INTENT_TOOLS = [
57
82
  .describe('The intents this call declared, or on `list` everything still open — each { id, statement, state, declaredAt, binding?, surface?, provenBy?, amended? }. `state` is declared (prose only), bound (a predicate exists), or proved (a verdict satisfied it).'),
58
83
  bound: z.boolean().optional().describe('bind only: false when the id names no intent.'),
59
84
  path: z.string().optional().describe('Where the ledger was written.'),
85
+ entries: z
86
+ .array(z.unknown())
87
+ .optional()
88
+ .describe('index only: one line per intent — { id, subject, statement (summarised), status }. The cheap read: enough to decide WHICH subject to open, without loading any of them.'),
89
+ records: z
90
+ .array(z.unknown())
91
+ .optional()
92
+ .describe('subject only: every full record for that subject.'),
93
+ record: z.unknown().optional().describe('get/record: the single full record, or null.'),
94
+ migrated: z
95
+ .number()
96
+ .optional()
97
+ .describe('migrate only: how many flat-file intents were folded into shards.'),
98
+ subjects: z
99
+ .array(z.string())
100
+ .optional()
101
+ .describe('migrate only: which subjects received them.'),
60
102
  },
61
103
  handler: async (deps, args) => {
62
104
  const root = sessionRoot(deps, asString(args['sessionId']));
63
105
  const store = new IntentStore(deps.fs, root, { now: deps.now });
106
+ const shards = new IntentShardStore(deps.fs, root, { now: deps.now });
64
107
  const action = asString(args['action']);
108
+ if (INDEX === action)
109
+ return { entries: (await shards.index()).entries, path: root };
110
+ if (SUBJECT === action)
111
+ return { records: await shards.subject(asString(args['subject']) ?? ''), path: root };
112
+ if (GET === action)
113
+ return { record: await shards.get(asString(args['id']) ?? '') };
114
+ if (MIGRATE === action)
115
+ return { ...(await shards.migrate()), path: root };
116
+ if (RECORD === action) {
117
+ const written = await shards.record({
118
+ id: asString(args['id']) ?? '',
119
+ statement: asString(args['statement']) ?? '',
120
+ subject: asString(args['subject']),
121
+ why: asString(args['why']),
122
+ source: asString(args['source']),
123
+ status: asString(args['status']),
124
+ binding: args['binding'],
125
+ });
126
+ return { record: written, path: root };
127
+ }
65
128
  if (BIND === action) {
66
129
  const id = asString(args['id']) ?? '';
67
130
  return { bound: await store.bind(id, args['binding']) };
@@ -19,3 +19,24 @@ export declare function openSessionIntents(deps: ToolDeps, sessionId: string | u
19
19
  * same reason it is shared above.
20
20
  */
21
21
  export declare function allSessionIntents(deps: ToolDeps, sessionId: string | undefined): Promise<Intent[]>;
22
+ /** What the ledger still owes once this verdict's own intent is discharged, and how old it is. */
23
+ export interface IntentDebt {
24
+ openIntentCount: number;
25
+ /**
26
+ * Age of the OLDEST open intent, in ms. Absent when nothing is open.
27
+ *
28
+ * A count alone cannot tell "declared a minute ago and not proved yet" from "this project has
29
+ * owed eighteen things since last week", and only the first is actionable on the result being
30
+ * read. A number that is always large is one people learn to skip, which is how an honest gap
31
+ * gets filtered out along with the noise.
32
+ */
33
+ oldestOpenIntentAgeMs?: number;
34
+ }
35
+ /**
36
+ * The debt a verdict should report, MINUS the intent it is about to discharge.
37
+ *
38
+ * The discharge happens after the gaps are built, so counting the raw ledger would include the
39
+ * intent this very call proves — measured live: an inline intent was declared, asserted and proved
40
+ * by one verdict, and the result still said "1 declared intent(s) are still unproved".
41
+ */
42
+ export declare function intentDebt(open: readonly Intent[], dischargedId: string | undefined, now: number): IntentDebt;
@@ -23,3 +23,18 @@ export async function openSessionIntents(deps, sessionId) {
23
23
  export async function allSessionIntents(deps, sessionId) {
24
24
  return new IntentStore(deps.fs, sessionRoot(deps, sessionId), { now: deps.now }).read();
25
25
  }
26
+ /**
27
+ * The debt a verdict should report, MINUS the intent it is about to discharge.
28
+ *
29
+ * The discharge happens after the gaps are built, so counting the raw ledger would include the
30
+ * intent this very call proves — measured live: an inline intent was declared, asserted and proved
31
+ * by one verdict, and the result still said "1 declared intent(s) are still unproved".
32
+ */
33
+ export function intentDebt(open, dischargedId, now) {
34
+ const stillOpen = open.filter((i) => dischargedId === undefined || i.id !== dischargedId);
35
+ const oldest = stillOpen.reduce((min, i) => (min === undefined || i.declaredAt < min ? i.declaredAt : min), undefined);
36
+ return {
37
+ openIntentCount: stillOpen.length,
38
+ ...(oldest === undefined ? {} : { oldestOpenIntentAgeMs: now - oldest }),
39
+ };
40
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Find an enterprise licence key the customer actually placed, wherever they reasonably placed it.
3
+ *
4
+ * The daemon folded in `<cwd>/.env` and nothing else. It is spawned without an explicit `cwd`, so it
5
+ * inherits whatever directory the editor launched the MCP server from — in a monorepo that is the
6
+ * workspace root while the key sits in the app's own `.env`, and under some editors it is the user's
7
+ * home. The key was never read, `describeLicense` reported `missing`, and every event that customer
8
+ * produced said they had no licence, which is indistinguishable from a customer who has none.
9
+ *
10
+ * That is the worst shape a licensing bug can take. A key that fails LOUDLY gets reported by the
11
+ * customer within the hour. A key that silently fails to register leaves them believing they are
12
+ * licensed and us believing they are not, and neither side finds out.
13
+ *
14
+ * Two directions, because the field hits both: DOWN one level into app directories (the daemon
15
+ * starts at the workspace root) and UP to the project root (the editor starts inside the app).
16
+ *
17
+ * ONLY the licence key is ever taken out of a file found this way, and that restriction is the point
18
+ * rather than an optimisation. Bulk-importing a `.env` discovered by walking would let a directory
19
+ * the caller never named rebind the daemon's port, its telemetry gate or its allowed origins — a far
20
+ * worse bug than the one this fixes. `loadDotEnv` still owns the local file, where importing
21
+ * everything is what the caller asked for.
22
+ */
23
+ /**
24
+ * The key, or undefined. Never throws, never mutates anything the caller did not ask it to.
25
+ *
26
+ * A key already present in `env` always wins: that is the operator stating it explicitly, and a file
27
+ * silently overriding it is the surprise `loadDotEnv` already refuses to cause.
28
+ */
29
+ export declare function licenseKeyFromEnvFiles(startDir: string, env?: NodeJS.ProcessEnv): string | undefined;