fnloom 0.1.0 → 0.3.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 (705) hide show
  1. package/README.md +133 -23
  2. package/package.json +13 -17
  3. package/packages/build/package.json +2 -2
  4. package/packages/cli/package.json +1 -1
  5. package/packages/cli/src/cli.ts +2 -1
  6. package/packages/cli/src/command.ts +2 -0
  7. package/packages/cli/src/commands/available.ts +63 -22
  8. package/packages/cli/src/commands/install.ts +182 -28
  9. package/packages/cli/src/commands/manage.ts +7 -5
  10. package/packages/cli/src/commands/store.ts +172 -0
  11. package/packages/cli/src/hub.ts +26 -7
  12. package/packages/cli/src/index.ts +3 -2
  13. package/packages/cli/src/io.ts +1 -0
  14. package/packages/cli/src/local.ts +6 -0
  15. package/packages/cli/src/premade.ts +80 -0
  16. package/packages/cli/src/testing.ts +2 -1
  17. package/packages/core/package.json +4 -4
  18. package/packages/core/src/context-files.ts +3 -1
  19. package/packages/core/src/context-graph.ts +4 -0
  20. package/packages/core/src/context-plan.ts +451 -0
  21. package/packages/core/src/context-questions.ts +305 -0
  22. package/packages/core/src/fn-facts.ts +32 -4
  23. package/packages/core/src/identity.ts +1 -1
  24. package/packages/core/src/index.ts +4 -1
  25. package/packages/core/src/link.ts +70 -0
  26. package/packages/core/src/manifest.ts +20 -1
  27. package/packages/core/src/model-calls.ts +11 -2
  28. package/packages/core/src/package.ts +10 -0
  29. package/packages/core/src/query.ts +3 -2
  30. package/packages/core/src/records/content.ts +10 -2
  31. package/packages/core/src/records/runs.ts +12 -0
  32. package/packages/core/src/records/systems.ts +87 -5
  33. package/packages/core/src/run.ts +5 -0
  34. package/packages/core/src/stores.ts +473 -0
  35. package/packages/core/src/suggestions.ts +3 -0
  36. package/packages/core/src/system-pages.ts +14 -1
  37. package/packages/core/src/web.ts +114 -9
  38. package/packages/hub/package.json +13 -12
  39. package/packages/hub/src/access/hits.ts +1 -1
  40. package/packages/hub/src/api/admin-ops.ts +36 -4
  41. package/packages/hub/src/api/auth.ts +8 -4
  42. package/packages/hub/src/api/person-ops.ts +6 -0
  43. package/packages/hub/src/api/store-ops.ts +54 -0
  44. package/packages/hub/src/api/testing/rig.ts +2 -2
  45. package/packages/hub/src/api/tls.ts +2 -2
  46. package/packages/hub/src/api/web/build5.ts +2 -1
  47. package/packages/hub/src/api/web/context-plans.ts +25 -0
  48. package/packages/hub/src/api/web/context-review.ts +43 -0
  49. package/packages/hub/src/api/web/index.ts +4 -0
  50. package/packages/hub/src/api/web/pages.ts +14 -1
  51. package/packages/hub/src/api/web/review.ts +16 -0
  52. package/packages/hub/src/api/web/systems.ts +14 -2
  53. package/packages/hub/src/boot/admin-fns.ts +8 -0
  54. package/packages/hub/src/boot/admin-secrets.ts +10 -4
  55. package/packages/hub/src/boot/env.ts +6 -1
  56. package/packages/hub/src/boot/hub-fns.ts +3 -3
  57. package/packages/hub/src/boot/hub-groups.ts +2 -2
  58. package/packages/hub/src/boot/identity.ts +1 -1
  59. package/packages/hub/src/boot/index.ts +9 -0
  60. package/packages/hub/src/boot/modules.ts +12 -3
  61. package/packages/hub/src/boot/person-fns.ts +5 -0
  62. package/packages/hub/src/boot/plan-fns.ts +39 -0
  63. package/packages/hub/src/boot/start.ts +2 -1
  64. package/packages/hub/src/catalog/catalog.ts +44 -14
  65. package/packages/hub/src/catalog/index.ts +6 -2
  66. package/packages/hub/src/chat/testing.ts +2 -2
  67. package/packages/hub/src/contextor/brought.ts +5 -3
  68. package/packages/hub/src/contextor/testing.ts +4 -4
  69. package/packages/hub/src/execution/create.ts +2 -0
  70. package/packages/hub/src/execution/env.ts +2 -0
  71. package/packages/hub/src/execution/errors.ts +12 -0
  72. package/packages/hub/src/execution/executors.ts +14 -2
  73. package/packages/hub/src/execution/index.ts +8 -0
  74. package/packages/hub/src/execution/link-handlers.ts +16 -4
  75. package/packages/hub/src/execution/runs.ts +212 -11
  76. package/packages/hub/src/execution/testing.ts +2 -1
  77. package/packages/hub/src/fns/search.ts +23 -4
  78. package/packages/hub/src/graph/graph.ts +2 -2
  79. package/packages/hub/src/index/index.ts +9 -2
  80. package/packages/hub/src/index/indexer.ts +67 -16
  81. package/packages/hub/src/index/search.ts +1 -0
  82. package/packages/hub/src/index/suggester.ts +2 -2
  83. package/packages/hub/src/link/build.ts +47 -10
  84. package/packages/hub/src/link/connections.ts +41 -3
  85. package/packages/hub/src/link/describer.ts +19 -2
  86. package/packages/hub/src/link/env.ts +10 -0
  87. package/packages/hub/src/link/handlers.ts +6 -0
  88. package/packages/hub/src/link/index.ts +16 -4
  89. package/packages/hub/src/link/lifecycle.ts +11 -4
  90. package/packages/hub/src/link/packages.ts +17 -4
  91. package/packages/hub/src/link/pairing.ts +2 -2
  92. package/packages/hub/src/link/process.ts +15 -4
  93. package/packages/hub/src/link/rig.ts +6 -2
  94. package/packages/hub/src/link/status.ts +14 -0
  95. package/packages/hub/src/link/supervisor.ts +17 -1
  96. package/packages/hub/src/link/systems.ts +16 -5
  97. package/packages/hub/src/models/roles.ts +74 -7
  98. package/packages/hub/src/query/columns.ts +4 -1
  99. package/packages/hub/src/query/contexts.ts +10 -3
  100. package/packages/hub/src/questions/apply.ts +163 -0
  101. package/packages/hub/src/questions/carry.ts +30 -0
  102. package/packages/hub/src/questions/duplicates.ts +181 -0
  103. package/packages/hub/src/questions/index.ts +112 -0
  104. package/packages/hub/src/questions/metadata.ts +142 -0
  105. package/packages/hub/src/questions/pending.ts +64 -0
  106. package/packages/hub/src/questions/plan-match.ts +79 -0
  107. package/packages/hub/src/questions/plan-prompts.ts +110 -0
  108. package/packages/hub/src/questions/planner.ts +382 -0
  109. package/packages/hub/src/questions/plans.ts +353 -0
  110. package/packages/hub/src/questions/review.ts +253 -0
  111. package/packages/hub/src/questions/setting.ts +50 -0
  112. package/packages/hub/src/questions/testing.ts +131 -0
  113. package/packages/hub/src/questions/worker.ts +182 -0
  114. package/packages/hub/src/resources/context.ts +58 -20
  115. package/packages/hub/src/resources/create.ts +16 -4
  116. package/packages/hub/src/resources/env.ts +4 -0
  117. package/packages/hub/src/resources/fns.ts +6 -2
  118. package/packages/hub/src/resources/index.ts +8 -2
  119. package/packages/hub/src/resources/testing.ts +18 -2
  120. package/packages/hub/src/store/codec.ts +23 -5
  121. package/packages/hub/src/store/context-status.ts +56 -0
  122. package/packages/hub/src/store/derived.ts +53 -0
  123. package/packages/hub/src/store/hybrid.ts +33 -6
  124. package/packages/hub/src/store/lists.ts +2 -1
  125. package/packages/hub/src/store/migrate-fn-names.ts +5 -2
  126. package/packages/hub/src/store/rows.ts +8 -1
  127. package/packages/hub/src/store/schema.ts +2 -1
  128. package/packages/hub/src/store/sqlite.ts +2 -1
  129. package/packages/hub/src/stores/backups.ts +163 -0
  130. package/packages/hub/src/stores/drivers.ts +100 -0
  131. package/packages/hub/src/stores/guard.ts +116 -0
  132. package/packages/hub/src/stores/host.ts +459 -0
  133. package/packages/hub/src/stores/moves.ts +380 -0
  134. package/packages/hub/src/stores/plugin.ts +42 -0
  135. package/packages/hub/src/stores/service.ts +340 -0
  136. package/packages/hub/src/stores/testing.ts +149 -0
  137. package/packages/sdk/AUTHORING.md +1813 -218
  138. package/packages/sdk/package.json +12 -8
  139. package/packages/sdk/src/build.ts +3 -0
  140. package/packages/sdk/src/client.ts +22 -0
  141. package/packages/sdk/src/ctx.ts +51 -17
  142. package/packages/sdk/src/declare.ts +36 -12
  143. package/packages/sdk/src/hub.ts +222 -10
  144. package/packages/sdk/src/impl.ts +3 -3
  145. package/packages/sdk/src/index.ts +6 -3
  146. package/packages/sdk/src/manifest.ts +5 -0
  147. package/packages/sdk/src/providers.ts +2 -2
  148. package/packages/sdk/src/server/asks.ts +12 -1
  149. package/packages/sdk/src/server/env.ts +13 -1
  150. package/packages/sdk/src/server/host.ts +81 -10
  151. package/packages/sdk/src/server/index.ts +21 -2
  152. package/packages/sdk/src/server/package.ts +11 -2
  153. package/packages/sdk/src/server/run.ts +6 -1
  154. package/packages/sdk/src/server/runtime.ts +78 -22
  155. package/packages/sdk/src/server/start-gate.ts +174 -0
  156. package/packages/sdk/src/server/store/checksum.ts +162 -0
  157. package/packages/sdk/src/server/store/engines.ts +400 -0
  158. package/packages/sdk/src/server/store/extend.ts +25 -0
  159. package/packages/sdk/src/server/store/keeper.ts +392 -0
  160. package/packages/sdk/src/server/store/link-driver.ts +142 -0
  161. package/packages/sdk/src/server/store/measure.ts +45 -0
  162. package/packages/sdk/src/server/store/migrations.ts +238 -0
  163. package/packages/sdk/src/server/store/move.ts +488 -0
  164. package/packages/sdk/src/server/store/portable.ts +288 -0
  165. package/packages/sdk/src/server/store/stable.ts +146 -0
  166. package/packages/sdk/src/server/store/tables.ts +28 -0
  167. package/packages/sdk/src/server/store/vectors.ts +185 -0
  168. package/packages/sdk/src/server/store/work-checks.ts +288 -0
  169. package/packages/sdk/src/server/store/work.ts +369 -0
  170. package/packages/sdk/src/server/table.ts +3 -1
  171. package/packages/sdk/src/server/testing.ts +116 -3
  172. package/packages/sdk/src/store.ts +91 -0
  173. package/packages/sdk/src/system.ts +58 -30
  174. package/packages/sdk/src/testing/hub.ts +18 -5
  175. package/packages/web/dist/assets/{ActorSettingsView-BuMYRDqv.js → ActorSettingsView-v2k7v454.js} +2 -2
  176. package/packages/web/dist/assets/{AdminLayout-sLjVTrmV.js → AdminLayout-B6Jrc_4W.js} +2 -2
  177. package/packages/web/dist/assets/{ApiServiceForm-BrMTU-7u.js → ApiServiceForm-CuuQgOJc.js} +2 -2
  178. package/packages/web/dist/assets/{ApiServiceView-BMF2zD6Q.js → ApiServiceView-7bTHSO_Z.js} +2 -2
  179. package/packages/web/dist/assets/{ApiServicesView-bjLAWO_j.js → ApiServicesView-BXi24n49.js} +2 -2
  180. package/packages/web/dist/assets/{AppPage-DSzDKCFz.js → AppPage-CFmKZS8G.js} +2 -2
  181. package/packages/web/dist/assets/{AutoPairPicker-nV38ALjl.js → AutoPairPicker-C61gihmh.js} +2 -2
  182. package/packages/web/dist/assets/{BrowserFrame-Bic7U7jN.js → BrowserFrame-Sq9EmQRT.js} +2 -2
  183. package/packages/web/dist/assets/{ChartVisual-DWw7WsfN.js → ChartVisual-C4mgw4wh.js} +4 -4
  184. package/packages/web/dist/assets/ChatPage-CAhHE03Z.js +4 -0
  185. package/packages/web/dist/assets/{CodeViewer-xHS3Xah9.js → CodeViewer-tUNXZB77.js} +2 -2
  186. package/packages/web/dist/assets/{ConfigWithCustom-DreTUdf0.js → ConfigWithCustom-D_-rY66L.js} +3 -3
  187. package/packages/web/dist/assets/{ConfirmDialog-DjQUzNqk.js → ConfirmDialog-Dd3E4sJt.js} +2 -2
  188. package/packages/web/dist/assets/{ConnectPage-CfRDrXvJ.js → ConnectPage-CX9acyQH.js} +2 -2
  189. package/packages/web/dist/assets/ContextItemPage-Cv4G0k_o.css +1 -0
  190. package/packages/web/dist/assets/ContextItemPage-rUI3-T_L.js +2 -0
  191. package/packages/web/dist/assets/ContextPage-C8u0UnYl.css +1 -0
  192. package/packages/web/dist/assets/ContextPage-CtefzyKg.js +3 -0
  193. package/packages/web/dist/assets/ContextRow-Chx99Xac.css +1 -0
  194. package/packages/web/dist/assets/ContextRow-DrtPumZ5.js +2 -0
  195. package/packages/web/dist/assets/{DataPage-wSIoGcb5.js → DataPage-DDSsxHro.js} +2 -2
  196. package/packages/web/dist/assets/DataTypePage-BW9fWaz8.js +2 -0
  197. package/packages/web/dist/assets/{DesignPage-DidMUX8m.js → DesignPage-6e0XbOFC.js} +2 -2
  198. package/packages/web/dist/assets/{ExplorePage-MUyVydVB.js → ExplorePage-B7ND0W0l.js} +2 -2
  199. package/packages/web/dist/assets/{FnList-CjQRwYaT.js → FnList-Bx6H-kux.js} +2 -2
  200. package/packages/web/dist/assets/{FnPill-BshAvm2I.js → FnPill-Cp3KuLmP.js} +2 -2
  201. package/packages/web/dist/assets/FnView-C0XZdnsS.js +2 -0
  202. package/packages/web/dist/assets/{FnsView-CeqIoaBT.js → FnsView-GTH3p7a0.js} +2 -2
  203. package/packages/web/dist/assets/{GinExprView-DYVUwZrd.js → GinExprView-DGxns6lH.js} +2 -2
  204. package/packages/web/dist/assets/{GinForm-D3mwMRTQ.js → GinForm-BDBUzuDP.js} +2 -2
  205. package/packages/web/dist/assets/{GinTypeView-C0YifSmE.js → GinTypeView-CUsymbVf.js} +2 -2
  206. package/packages/web/dist/assets/{GinValueView-HfEPq9le.js → GinValueView-jsKIfiEA.js} +2 -2
  207. package/packages/web/dist/assets/{GraphPage-ySnuA4Hp.js → GraphPage-BCcPPsHu.js} +2 -2
  208. package/packages/web/dist/assets/{GraphPanel-Cy5-KGo1.js → GraphPanel-9tztGHmu.js} +2 -2
  209. package/packages/web/dist/assets/{HubPicker-C_vA752L.js → HubPicker-EoOErgmk.js} +2 -2
  210. package/packages/web/dist/assets/{InboxApprovals-DcPCCmZ5.js → InboxApprovals-Dkq7DFp_.js} +2 -2
  211. package/packages/web/dist/assets/{InboxPage-C2DT2nuF.js → InboxPage-CHhslePq.js} +2 -2
  212. package/packages/web/dist/assets/{InjectedList-CJsEFEbz.js → InjectedList-CSWqRiON.js} +2 -2
  213. package/packages/web/dist/assets/InstallDialog-D-VwfZYF.js +2 -0
  214. package/packages/web/dist/assets/{InstallDialog-yWLZK_zN.css → InstallDialog-K-j0sdHm.css} +1 -1
  215. package/packages/web/dist/assets/InstanceTypes-CwVSAULg.css +1 -0
  216. package/packages/web/dist/assets/InstanceTypes-D3rAEiE7.js +2 -0
  217. package/packages/web/dist/assets/InstanceView-DoH8C-1j.js +2 -0
  218. package/packages/web/dist/assets/InstanceView-_9uE70tS.css +1 -0
  219. package/packages/web/dist/assets/{ItemHistory-CUGa8b6s.js → ItemHistory-NQAP69ma.js} +2 -2
  220. package/packages/web/dist/assets/LimitsView-DY2C9nYS.js +2 -0
  221. package/packages/web/dist/assets/ListSearch-BunVrDO0.js +2 -0
  222. package/packages/web/dist/assets/{LlmCallDetails-2yQftCqd.js → LlmCallDetails-BoVNDTVs.js} +2 -2
  223. package/packages/web/dist/assets/{LlmCallsView-DOHX3r0K.js → LlmCallsView-BGpV92RC.js} +2 -2
  224. package/packages/web/dist/assets/{LoadState-DeXfLvYv.js → LoadState-h-K9bTYc.js} +2 -2
  225. package/packages/web/dist/assets/{McpDialog-CA_0WKWF.js → McpDialog-DhOCk6_E.js} +2 -2
  226. package/packages/web/dist/assets/{McpServerForm-CAG8Wp2N.js → McpServerForm-Cor3fI7s.js} +2 -2
  227. package/packages/web/dist/assets/McpServerView-ewXRPEmZ.js +2 -0
  228. package/packages/web/dist/assets/McpServersView-Dd0xmfws.js +2 -0
  229. package/packages/web/dist/assets/{McpView-CC2oNOMa.js → McpView-GPXdCMne.js} +2 -2
  230. package/packages/web/dist/assets/{McpsView-CwJvyyxV.js → McpsView-DJIR2JX5.js} +2 -2
  231. package/packages/web/dist/assets/{MemoryDialog-Dbvh5uLq.js → MemoryDialog-BTeIHQyA.js} +2 -2
  232. package/packages/web/dist/assets/{ModelCallsView-RvnW3EBP.js → ModelCallsView-DMcnwF2S.js} +2 -2
  233. package/packages/web/dist/assets/{ModelPicker-DcjwQFHC.js → ModelPicker-CgkMFxSO.js} +2 -2
  234. package/packages/web/dist/assets/ModelsView-cMHygeiK.js +2 -0
  235. package/packages/web/dist/assets/{NotFoundPage-CeSwzTV-.js → NotFoundPage-Tk92K7HN.js} +2 -2
  236. package/packages/web/dist/assets/PairPage-D0BK8CCw.js +2 -0
  237. package/packages/web/dist/assets/PairPage-D_aPS1Ot.css +1 -0
  238. package/packages/web/dist/assets/{PanelHost-BkrFAnPa.js → PanelHost-C-gKrxAk.js} +2 -2
  239. package/packages/web/dist/assets/{PeopleView-D1QGPYp7.js → PeopleView-DRfeNWK5.js} +2 -2
  240. package/packages/web/dist/assets/PoliciesView-BRi-QAuo.js +2 -0
  241. package/packages/web/dist/assets/{RefusalList-DQoyUoPG.js → RefusalList-DVO0bmeB.js} +2 -2
  242. package/packages/web/dist/assets/{RemoteAuthFields-nxGWfmhf.js → RemoteAuthFields-CgiufuqQ.js} +2 -2
  243. package/packages/web/dist/assets/{ResourceViewer-Po24y4pj.js → ResourceViewer-Do0chYxU.js} +2 -2
  244. package/packages/web/dist/assets/ResourcesPage-BBx2u2mw.js +2 -0
  245. package/packages/web/dist/assets/{ResultGrid-uoq4yUYj.js → ResultGrid-Bj-0I5HY.js} +2 -2
  246. package/packages/web/dist/assets/{ReviewSummaryStrip-k3HevESg.js → ReviewSummaryStrip-DO3p64Qj.js} +2 -2
  247. package/packages/web/dist/assets/ReviewView-DZF9E1hb.js +3 -0
  248. package/packages/web/dist/assets/{RuleRow-CoXDA-SH.js → RuleRow-DX9v4iGP.js} +2 -2
  249. package/packages/web/dist/assets/{RunCard-CBSGdwdQ.js → RunCard-BnrtK2Yp.js} +2 -2
  250. package/packages/web/dist/assets/{RunDetails-CGhQQ6OI.js → RunDetails-DjR206q6.js} +2 -2
  251. package/packages/web/dist/assets/{RunDot-Ch_45985.js → RunDot-lHRICdM5.js} +2 -2
  252. package/packages/web/dist/assets/{RunPage-C_t20pB7.js → RunPage-CbAQ_WPR.js} +2 -2
  253. package/packages/web/dist/assets/{RunProgress-VrZUHUEC.js → RunProgress-C3-B4tQf.js} +2 -2
  254. package/packages/web/dist/assets/RunsView-DMkPmkqX.js +2 -0
  255. package/packages/web/dist/assets/ServiceRows-4WythFpF.js +2 -0
  256. package/packages/web/dist/assets/{ServiceRows-6BU4-MeL.css → ServiceRows-HPQ0pN6b.css} +1 -1
  257. package/packages/web/dist/assets/SettingsPage-BN4oSzoL.js +3 -0
  258. package/packages/web/dist/assets/{SignInPage-DrXZ1sG2.js → SignInPage-ByqGEZfj.js} +2 -2
  259. package/packages/web/dist/assets/{StatusBadge-Dpb9uG5e.js → StatusBadge-CXne0sRZ.js} +2 -2
  260. package/packages/web/dist/assets/StorePlacementStep-B6SwTmdM.js +2 -0
  261. package/packages/web/dist/assets/StorePlacementStep-D_G4e3ue.css +1 -0
  262. package/packages/web/dist/assets/{SystemConfig-72qKRkUk.js → SystemConfig-vQDL_eUl.js} +2 -2
  263. package/packages/web/dist/assets/{SystemPageHost-DLNg2FYK.js → SystemPageHost-DrMrEPyh.js} +2 -2
  264. package/packages/web/dist/assets/SystemView-Be6TBM4j.js +2 -0
  265. package/packages/web/dist/assets/{SystemView-C8ScHUe2.css → SystemView-_9q6eDfV.css} +1 -1
  266. package/packages/web/dist/assets/{SystemsView-B6HEL9VS.css → SystemsView-CWKnupLW.css} +1 -1
  267. package/packages/web/dist/assets/SystemsView-DZtT3laz.js +2 -0
  268. package/packages/web/dist/assets/{TableViewer-BQ7bYLOP.js → TableViewer-Boxx86f5.js} +3 -3
  269. package/packages/web/dist/assets/{ThemePicker-C2nJ21Vd.js → ThemePicker-CIg_oRQX.js} +2 -2
  270. package/packages/web/dist/assets/{TurnTree-CORdfTHj.js → TurnTree-Ecm0yA5g.js} +2 -2
  271. package/packages/web/dist/assets/UserMessage-BlnqZDVU.js +9 -0
  272. package/packages/web/dist/assets/{ValueVisual-aXEUaQ5Y.js → ValueVisual-C-MWpp7c.js} +2 -2
  273. package/packages/web/dist/assets/WidgetView-DX4ejNb6.js +3 -0
  274. package/packages/web/dist/assets/actor-names-OdvpVZeb.js +4 -0
  275. package/packages/web/dist/assets/{fn-modal-DqcxUhOQ.js → fn-modal-B98MR7JN.js} +2 -2
  276. package/packages/web/dist/assets/{fn-notices-BYaH6IoA.js → fn-notices-CfTa1E8y.js} +2 -2
  277. package/packages/web/dist/assets/{formats-DI__ADVG.js → formats-JwoKfXIq.js} +2 -2
  278. package/packages/web/dist/assets/index-6ScWTFy2.js +4 -0
  279. package/packages/web/dist/assets/{index-CSisx5mi.css → index-CEslGcrX.css} +1 -1
  280. package/packages/web/dist/assets/{labels-BhJpmLWA.js → labels-BFbk11BE.js} +2 -2
  281. package/packages/web/dist/assets/{layout-DQKldU13.js → layout-D1gf481r.js} +2 -2
  282. package/packages/web/dist/assets/{metrics-Cio5ykX6.js → metrics-CBPX3W5Y.js} +2 -2
  283. package/packages/web/dist/assets/{problems-BZY0Dwif.js → problems-t1E_ovSz.js} +2 -2
  284. package/packages/web/dist/assets/{push-payload-D5efGCzd.js → push-payload-BeU1ADYt.js} +64 -64
  285. package/packages/web/dist/assets/{record-edits-CveFEsal.js → record-edits-Bfsi4lU3.js} +2 -2
  286. package/packages/web/dist/assets/{remote-config-BkaarDf3.js → remote-config-BNQhSDzB.js} +2 -2
  287. package/packages/web/dist/assets/{review-CGUGvRV9.js → review-fP-l9D6H.js} +3 -3
  288. package/packages/web/dist/assets/routes-DV4IJpwe.js +4 -0
  289. package/packages/web/dist/assets/runs-CveC2kKo.js +2 -0
  290. package/packages/web/dist/assets/{shared-DTpYDMc_.js → shared-LbaIHjbV.js} +2 -2
  291. package/packages/web/dist/assets/{size-BwnshyOe.js → size-Bh__w5aI.js} +2 -2
  292. package/packages/web/dist/assets/{sources-Bm-TrxhL.js → sources-VPrtgLIi.js} +2 -2
  293. package/packages/web/dist/assets/src-CT3TeFaM.js +43 -0
  294. package/packages/web/dist/assets/state-xfQqaQPX.js +2 -0
  295. package/packages/web/dist/assets/{systems-DIp94AET.js → systems-BqE3WTSF.js} +2 -2
  296. package/packages/web/dist/assets/ui-BzgWquIU.js +17 -0
  297. package/packages/web/dist/assets/{ui-C7ZH_6oC.css → ui-DycHjPTZ.css} +1 -1
  298. package/packages/web/dist/assets/{url-BIg5IhGs.js → url-DKGcECT1.js} +2 -2
  299. package/packages/web/dist/assets/{widget-host-BCf6Tlt5.js → widget-host-B87MTaTn.js} +2 -2
  300. package/packages/web/dist/assets/{widgets-CrbkovMT.js → widgets-BBCuSS6E.js} +2 -2
  301. package/packages/web/dist/index.html +44 -44
  302. package/packages/web/dist/sw.js +1 -1
  303. package/packages/web/package.json +2 -2
  304. package/premade/claude.zip +0 -0
  305. package/premade/database.zip +0 -0
  306. package/premade/web.zip +0 -0
  307. package/scripts/dev-env.ts +4 -4
  308. package/scripts/run-stack.ts +3 -2
  309. package/scripts/stack.ts +115 -43
  310. package/scripts/start.ts +36 -17
  311. package/systems/api/package.json +3 -3
  312. package/systems/code/package.json +3 -3
  313. package/systems/embedder/package.json +1 -1
  314. package/systems/fs/client/fakes.ts +2 -0
  315. package/systems/fs/client/index.ts +4 -2
  316. package/systems/fs/client/machines/CoreHeatmap.vue +94 -0
  317. package/systems/fs/client/machines/MachineFiles.vue +121 -0
  318. package/systems/fs/client/machines/MachineMetrics.vue +330 -0
  319. package/systems/fs/client/machines/MachinesPage.vue +119 -0
  320. package/systems/fs/client/machines/TimeChart.vue +128 -0
  321. package/systems/fs/client/machines/fakes.ts +95 -0
  322. package/systems/fs/client/machines/files/ChangesPane.vue +90 -0
  323. package/systems/fs/client/machines/files/CodeView.vue +158 -0
  324. package/systems/fs/client/machines/files/CommentComposer.vue +86 -0
  325. package/systems/fs/client/machines/files/CommentThread.vue +115 -0
  326. package/systems/fs/client/machines/files/CommitPane.vue +80 -0
  327. package/systems/fs/client/machines/files/ComparePane.vue +81 -0
  328. package/systems/fs/client/machines/files/FileHistory.vue +89 -0
  329. package/systems/fs/client/machines/files/FilePane.vue +199 -0
  330. package/systems/fs/client/machines/files/FileTree.vue +26 -0
  331. package/systems/fs/client/machines/files/FolderPane.vue +154 -0
  332. package/systems/fs/client/machines/files/HistoryPane.vue +106 -0
  333. package/systems/fs/client/machines/files/ImageView.vue +160 -0
  334. package/systems/fs/client/machines/files/PatchView.vue +31 -0
  335. package/systems/fs/client/machines/files/QuickOpen.vue +67 -0
  336. package/systems/fs/client/machines/files/SearchPane.vue +87 -0
  337. package/systems/fs/client/machines/files/TreeNode.vue +72 -0
  338. package/systems/fs/client/machines/files/api.ts +127 -0
  339. package/systems/fs/client/machines/files/fake-kinds.ts +16 -0
  340. package/systems/fs/client/machines/files/fakes.ts +305 -0
  341. package/systems/fs/client/machines/files/ink.ts +117 -0
  342. package/systems/fs/client/machines/files/logic.ts +205 -0
  343. package/systems/fs/client/machines/files/state.ts +187 -0
  344. package/systems/fs/client/machines/files/viewers/CsvView.vue +29 -0
  345. package/systems/fs/client/machines/files/viewers/HexView.vue +27 -0
  346. package/systems/fs/client/machines/files/viewers/HtmlView.vue +17 -0
  347. package/systems/fs/client/machines/files/viewers/JsonNode.vue +45 -0
  348. package/systems/fs/client/machines/files/viewers/JsonView.vue +25 -0
  349. package/systems/fs/client/machines/metrics.ts +245 -0
  350. package/systems/fs/client/machines/palette.ts +97 -0
  351. package/systems/fs/client/preview/machines.ts +323 -0
  352. package/systems/fs/context/authoring/index.md +4 -0
  353. package/systems/fs/context/authoring/parts/actions.md +5 -1
  354. package/systems/fs/context/authoring/parts/actions.reference.md +6 -2
  355. package/systems/fs/context/authoring/parts/calling.md +5 -1
  356. package/systems/fs/context/authoring/parts/calling.reference.md +4 -0
  357. package/systems/fs/context/authoring/parts/client.md +9 -1
  358. package/systems/fs/context/authoring/parts/client.reference/client.md +4 -0
  359. package/systems/fs/context/authoring/parts/client.reference/resultview.md +56 -53
  360. package/systems/fs/context/authoring/parts/client.reference/{fnpillprops.md → textareaprops.md} +58 -4
  361. package/systems/fs/context/authoring/parts/client.reference.md +8 -4
  362. package/systems/fs/context/authoring/parts/context/questions.md +49 -0
  363. package/systems/fs/context/authoring/parts/context.md +23 -1
  364. package/systems/fs/context/authoring/parts/context.reference.md +27 -3
  365. package/systems/fs/context/authoring/parts/contract.md +10 -0
  366. package/systems/fs/context/authoring/parts/contract.reference.md +26 -9
  367. package/systems/fs/context/authoring/parts/core-types/access-ts.md +4 -0
  368. package/systems/fs/context/authoring/parts/core-types/admin-ts.md +5 -1
  369. package/systems/fs/context/authoring/parts/core-types/api-index-ts.md +4 -0
  370. package/systems/fs/context/authoring/parts/core-types/approvals-ts.md +11 -7
  371. package/systems/fs/context/authoring/parts/core-types/auto-pair-ts.md +4 -0
  372. package/systems/fs/context/authoring/parts/core-types/checks-ts.md +4 -0
  373. package/systems/fs/context/authoring/parts/core-types/claims-ts.md +4 -0
  374. package/systems/fs/context/authoring/parts/core-types/config-secrets-ts.md +4 -0
  375. package/systems/fs/context/authoring/parts/core-types/connections-ts.md +4 -0
  376. package/systems/fs/context/authoring/parts/core-types/context-files-ts.md +8 -0
  377. package/systems/fs/context/authoring/parts/core-types/context-graph-ts.md +5 -1
  378. package/systems/fs/context/authoring/parts/core-types/context-questions-ts.md +26 -0
  379. package/systems/fs/context/authoring/parts/core-types/contextdecl.md +9 -1
  380. package/systems/fs/context/authoring/parts/core-types/data-ts.md +4 -0
  381. package/systems/fs/context/authoring/parts/core-types/decisions-ts.md +4 -0
  382. package/systems/fs/context/authoring/parts/core-types/fn-block-ts.md +4 -0
  383. package/systems/fs/context/authoring/parts/core-types/fn-facts-ts.md +11 -0
  384. package/systems/fs/context/authoring/parts/core-types/gin-ts.md +4 -0
  385. package/systems/fs/context/authoring/parts/core-types/grants-ts.md +5 -1
  386. package/systems/fs/context/authoring/parts/core-types/lifecycle-ts.md +18 -5
  387. package/systems/fs/context/authoring/parts/core-types/link-ts.md +7 -3
  388. package/systems/fs/context/authoring/parts/core-types/llm-ts.md +4 -0
  389. package/systems/fs/context/authoring/parts/core-types/manifest.md +15 -2
  390. package/systems/fs/context/authoring/parts/core-types/manifestpatch.md +9 -1
  391. package/systems/fs/context/authoring/parts/core-types/mention-search-ts.md +4 -0
  392. package/systems/fs/context/authoring/parts/core-types/model-calls-ts.md +5 -1
  393. package/systems/fs/context/authoring/parts/core-types/model-names-ts.md +4 -0
  394. package/systems/fs/context/authoring/parts/core-types/modes-ts.md +4 -0
  395. package/systems/fs/context/authoring/parts/core-types/owner-runs-ts.md +4 -0
  396. package/systems/fs/context/authoring/parts/core-types/package-ts.md +9 -0
  397. package/systems/fs/context/authoring/parts/core-types/primitives-ts.md +4 -0
  398. package/systems/fs/context/authoring/parts/core-types/query-ts.md +4 -0
  399. package/systems/fs/context/authoring/parts/core-types/records-actors-ts.md +7 -3
  400. package/systems/fs/context/authoring/parts/core-types/records-chat-ts.md +4 -0
  401. package/systems/fs/context/authoring/parts/core-types/records-content-ts.md +4 -0
  402. package/systems/fs/context/authoring/parts/core-types/records-runs-ts.md +4 -0
  403. package/systems/fs/context/authoring/parts/core-types/records-systems-ts.md +4 -0
  404. package/systems/fs/context/authoring/parts/core-types/registries-ts.md +4 -0
  405. package/systems/fs/context/authoring/parts/core-types/remote-auth-ts.md +4 -0
  406. package/systems/fs/context/authoring/parts/core-types/resources-ts.md +5 -1
  407. package/systems/fs/context/authoring/parts/core-types/run-ts.md +7 -0
  408. package/systems/fs/context/authoring/parts/core-types/sensitivity-ts.md +5 -1
  409. package/systems/fs/context/authoring/parts/core-types/stores-ts.md +199 -0
  410. package/systems/fs/context/authoring/parts/core-types/system-events-ts.md +8 -1
  411. package/systems/fs/context/authoring/parts/core-types/system-pages-ts.md +4 -0
  412. package/systems/fs/context/authoring/parts/core-types/system-providers-ts.md +4 -0
  413. package/systems/fs/context/authoring/parts/core-types/validation-ts.md +4 -0
  414. package/systems/fs/context/authoring/parts/core-types/visuals-ts.md +4 -0
  415. package/systems/fs/context/authoring/parts/core-types/web-ts.md +4 -0
  416. package/systems/fs/context/authoring/parts/core-types/widgets-ts.md +4 -0
  417. package/systems/fs/context/authoring/parts/core-types.md +12 -2
  418. package/systems/fs/context/authoring/parts/ctx/update-result.md +33 -0
  419. package/systems/fs/context/authoring/parts/ctx.md +11 -1
  420. package/systems/fs/context/authoring/parts/ctx.reference/{hubai.md → adminnotices.md} +45 -4
  421. package/systems/fs/context/authoring/parts/ctx.reference/fnctx.md +21 -23
  422. package/systems/fs/context/authoring/parts/ctx.reference.md +8 -4
  423. package/systems/fs/context/authoring/parts/data.md +11 -6
  424. package/systems/fs/context/authoring/parts/data.reference.md +4 -0
  425. package/systems/fs/context/authoring/parts/examples/client-findview-vue.md +4 -0
  426. package/systems/fs/context/authoring/parts/examples/client-index-ts.md +4 -0
  427. package/systems/fs/context/authoring/parts/examples/client-notecard-vue.md +4 -0
  428. package/systems/fs/context/authoring/parts/examples/client-noteinput-vue.md +4 -0
  429. package/systems/fs/context/authoring/parts/examples/client-notespage-vue.md +4 -0
  430. package/systems/fs/context/authoring/parts/examples/client-reviewform-vue.md +4 -0
  431. package/systems/fs/context/authoring/parts/examples/client-wordcount-vue.md +4 -0
  432. package/systems/fs/context/authoring/parts/examples/package-json.md +4 -0
  433. package/systems/fs/context/authoring/parts/examples/server-env-ts.md +4 -0
  434. package/systems/fs/context/authoring/parts/examples/server-impl-ts.md +4 -0
  435. package/systems/fs/context/authoring/parts/examples/server-index-ts.md +4 -0
  436. package/systems/fs/context/authoring/parts/examples/server-main-ts.md +4 -0
  437. package/systems/fs/context/authoring/parts/examples/server-notes-test-ts.md +4 -0
  438. package/systems/fs/context/authoring/parts/examples/shared-index-ts.md +10 -0
  439. package/systems/fs/context/authoring/parts/examples/system-json.md +4 -0
  440. package/systems/fs/context/authoring/parts/examples/{systems-fs-shared-index-ts-lines-1-189.md → systems-fs-shared-index-ts-lines-1-178.md} +23 -30
  441. package/systems/fs/context/authoring/parts/examples/{systems-fs-shared-index-ts-lines-190-370.md → systems-fs-shared-index-ts-lines-179-382.md} +33 -6
  442. package/systems/fs/context/authoring/parts/examples/systems-fs-shared-index-ts-lines-383-567.md +210 -0
  443. package/systems/fs/context/authoring/parts/examples/systems-fs-shared-index-ts-lines-568-660.md +117 -0
  444. package/systems/fs/context/authoring/parts/examples/tsconfig-json.md +5 -1
  445. package/systems/fs/context/authoring/parts/examples.md +18 -11
  446. package/systems/fs/context/authoring/parts/fns.md +5 -1
  447. package/systems/fs/context/authoring/parts/fns.reference/fillclaims.md +5 -1
  448. package/systems/fs/context/authoring/parts/fns.reference/fn.md +6 -2
  449. package/systems/fs/context/authoring/parts/fns.reference.md +4 -0
  450. package/systems/fs/context/authoring/parts/folder.md +4 -0
  451. package/systems/fs/context/authoring/parts/gin.md +4 -0
  452. package/systems/fs/context/authoring/parts/gin.reference.md +4 -0
  453. package/systems/fs/context/authoring/parts/handlers-progress.md +5 -1
  454. package/systems/fs/context/authoring/parts/handlers-progress.reference.md +4 -0
  455. package/systems/fs/context/authoring/parts/hooks.md +5 -1
  456. package/systems/fs/context/authoring/parts/hooks.reference.md +5 -1
  457. package/systems/fs/context/authoring/parts/hub/context-questions.md +40 -0
  458. package/systems/fs/context/authoring/parts/hub/{hub-run-background.md → hub-ctx-from-resource.md} +51 -56
  459. package/systems/fs/context/authoring/parts/hub/hub-fns-load.md +35 -42
  460. package/systems/fs/context/authoring/parts/hub/hub-install-package.md +327 -0
  461. package/systems/fs/context/authoring/parts/hub/kinds-of-hub.md +8 -0
  462. package/systems/fs/context/authoring/parts/hub.md +14 -8
  463. package/systems/fs/context/authoring/parts/hub.reference.md +9 -0
  464. package/systems/fs/context/authoring/parts/internals/manifestof.md +4 -0
  465. package/systems/fs/context/authoring/parts/internals/permissionargs.md +4 -0
  466. package/systems/fs/context/authoring/parts/internals/usagefromwire.md +47 -2
  467. package/systems/fs/context/authoring/parts/internals.md +6 -2
  468. package/systems/fs/context/authoring/parts/kinds-agents.md +5 -1
  469. package/systems/fs/context/authoring/parts/kinds-agents.reference/authoringsession.md +4 -0
  470. package/systems/fs/context/authoring/parts/kinds-agents.reference/kind.md +7 -3
  471. package/systems/fs/context/authoring/parts/kinds-agents.reference.md +4 -0
  472. package/systems/fs/context/authoring/parts/lifecycle.md +8 -3
  473. package/systems/fs/context/authoring/parts/lifecycle.reference.md +6 -2
  474. package/systems/fs/context/authoring/parts/mentions.md +5 -1
  475. package/systems/fs/context/authoring/parts/mentions.reference.md +6 -2
  476. package/systems/fs/context/authoring/parts/mistakes.md +7 -2
  477. package/systems/fs/context/authoring/parts/named-types.md +4 -0
  478. package/systems/fs/context/authoring/parts/named-types.reference.md +6 -2
  479. package/systems/fs/context/authoring/parts/outcomes.md +5 -1
  480. package/systems/fs/context/authoring/parts/outcomes.reference.md +4 -0
  481. package/systems/fs/context/authoring/parts/owner-runs.md +5 -1
  482. package/systems/fs/context/authoring/parts/owner-runs.reference.md +36 -11
  483. package/systems/fs/context/authoring/parts/packaging.md +10 -3
  484. package/systems/fs/context/authoring/parts/packaging.reference.md +7 -2
  485. package/systems/fs/context/authoring/parts/providers.md +5 -1
  486. package/systems/fs/context/authoring/parts/providers.reference.md +5 -1
  487. package/systems/fs/context/authoring/parts/remote.md +5 -1
  488. package/systems/fs/context/authoring/parts/remote.reference.md +4 -0
  489. package/systems/fs/context/authoring/parts/resources.md +5 -1
  490. package/systems/fs/context/authoring/parts/resources.reference.md +4 -0
  491. package/systems/fs/context/authoring/parts/server.md +5 -1
  492. package/systems/fs/context/authoring/parts/server.reference.md +41 -20
  493. package/systems/fs/context/authoring/parts/settings-attachments.md +5 -1
  494. package/systems/fs/context/authoring/parts/settings-attachments.reference.md +4 -0
  495. package/systems/fs/context/authoring/parts/start.md +5 -1
  496. package/systems/fs/context/authoring/parts/state-forms.md +5 -1
  497. package/systems/fs/context/authoring/parts/state-forms.reference.md +4 -0
  498. package/systems/fs/context/authoring/parts/store/ctx-store.md +49 -0
  499. package/systems/fs/context/authoring/parts/store/declare.md +32 -0
  500. package/systems/fs/context/authoring/parts/store/engines.md +25 -0
  501. package/systems/fs/context/authoring/parts/store/migrations.md +53 -0
  502. package/systems/fs/context/authoring/parts/store/moves.md +38 -0
  503. package/systems/fs/context/authoring/parts/store/placement.md +25 -0
  504. package/systems/fs/context/authoring/parts/store/serve.md +30 -0
  505. package/systems/fs/context/authoring/parts/store/store-tables.md +24 -0
  506. package/systems/fs/context/authoring/parts/store/vectors.md +32 -0
  507. package/systems/fs/context/authoring/parts/store/when-to-use.md +27 -0
  508. package/systems/fs/context/authoring/parts/store/work.md +37 -0
  509. package/systems/fs/context/authoring/parts/store.md +65 -0
  510. package/systems/fs/context/authoring/parts/store.reference.md +459 -0
  511. package/systems/fs/context/authoring/parts/testing.md +14 -1
  512. package/systems/fs/context/authoring/parts/testing.reference/{memoryjournal.md → equal.md} +55 -48
  513. package/systems/fs/context/authoring/parts/testing.reference/fakehub.md +26 -45
  514. package/systems/fs/context/authoring/parts/testing.reference/{toolcall.md → kindprops.md} +111 -4
  515. package/systems/fs/context/authoring/parts/testing.reference/openmemorystore.md +105 -0
  516. package/systems/fs/context/authoring/parts/testing.reference.md +16 -9
  517. package/systems/fs/context/authoring/parts/widgets.md +5 -1
  518. package/systems/fs/context/authoring/parts/widgets.reference/hub-visuals.md +4 -0
  519. package/systems/fs/context/authoring/parts/widgets.reference/sourcecompatible.md +4 -0
  520. package/systems/fs/context/authoring/parts/widgets.reference.md +4 -0
  521. package/systems/fs/context/authoring/topics/begin.md +4 -0
  522. package/systems/fs/context/authoring/topics/client.md +4 -0
  523. package/systems/fs/context/authoring/topics/declare.md +4 -0
  524. package/systems/fs/context/authoring/topics/examples.md +4 -0
  525. package/systems/fs/context/authoring/topics/fns.md +4 -0
  526. package/systems/fs/context/authoring/topics/server.md +4 -0
  527. package/systems/fs/context/authoring/topics/types.md +8 -1
  528. package/systems/fs/context/comments/answer.md +21 -0
  529. package/systems/fs/context/comments/find.md +23 -0
  530. package/systems/fs/context/comments/read.md +26 -0
  531. package/systems/fs/context/comments.md +23 -0
  532. package/systems/fs/context/files-page.md +30 -0
  533. package/systems/fs/context/guide/attachments.md +16 -0
  534. package/systems/fs/context/guide/change.md +23 -0
  535. package/systems/fs/context/guide/commands.md +19 -0
  536. package/systems/fs/context/guide/documents.md +21 -0
  537. package/systems/fs/context/guide/find.md +25 -0
  538. package/systems/fs/context/guide/paths.md +24 -0
  539. package/systems/fs/context/guide/read.md +21 -0
  540. package/systems/fs/context/machine/history.md +25 -0
  541. package/systems/fs/context/machine/now.md +25 -0
  542. package/systems/fs/context/machine/processes.md +20 -0
  543. package/systems/fs/context/machine/recording.md +19 -0
  544. package/systems/fs/context/machine.md +24 -0
  545. package/systems/fs/package.json +5 -3
  546. package/systems/fs/server/files-page/browse.ts +391 -0
  547. package/systems/fs/server/files-page/comments.ts +439 -0
  548. package/systems/fs/server/files-page/fns.ts +158 -0
  549. package/systems/fs/server/files-page/git-view.ts +391 -0
  550. package/systems/fs/server/files-page/kinds.ts +56 -0
  551. package/systems/fs/server/impl.ts +66 -7
  552. package/systems/fs/server/main.ts +20 -4
  553. package/systems/fs/server/metrics/collector.ts +424 -0
  554. package/systems/fs/server/metrics/index.ts +181 -0
  555. package/systems/fs/server/metrics/os.ts +144 -0
  556. package/systems/fs/server/metrics/parsers.ts +268 -0
  557. package/systems/fs/server/metrics/rrd.ts +363 -0
  558. package/systems/fs/server/metrics/testing.ts +80 -0
  559. package/systems/fs/server/snapshots.ts +216 -33
  560. package/systems/fs/server/testing.ts +15 -9
  561. package/systems/fs/shared/files-page.ts +506 -0
  562. package/systems/fs/shared/index.ts +137 -10
  563. package/systems/fs/shared/metrics.ts +179 -0
  564. package/systems/fs/system.json +10 -1
  565. package/systems/google-calendar/package.json +1 -1
  566. package/systems/input/package.json +3 -3
  567. package/systems/mcp/package.json +3 -3
  568. package/systems/mcp/server/oauth.ts +1 -1
  569. package/systems/ollama/package.json +3 -3
  570. package/systems/schedule/package.json +3 -4
  571. package/systems/schedule/server/env.ts +1 -1
  572. package/systems/schedule/server/fns.ts +5 -4
  573. package/systems/schedule/server/impl.ts +2 -2
  574. package/systems/schedule/server/import.ts +189 -0
  575. package/systems/schedule/server/index.ts +2 -0
  576. package/systems/schedule/server/main.ts +3 -1
  577. package/systems/schedule/server/placements.ts +41 -0
  578. package/systems/schedule/server/store.ts +159 -79
  579. package/systems/schedule/server/timer.ts +142 -107
  580. package/systems/schedule/shared/index.ts +2 -1
  581. package/systems/schedule/system.json +5 -1
  582. package/systems/schedule/tsconfig.json +1 -1
  583. package/systems/template/package.json +1 -1
  584. package/systems/widgets/package.json +3 -3
  585. package/packages/web/dist/assets/ChatPage-7Yebk7rl.js +0 -4
  586. package/packages/web/dist/assets/ContextItemPage-B6rJG3OT.js +0 -2
  587. package/packages/web/dist/assets/ContextItemPage-BRsWxOmu.css +0 -1
  588. package/packages/web/dist/assets/ContextPage-CloIZ_2y.js +0 -2
  589. package/packages/web/dist/assets/ContextPage-rYKxjiVI.css +0 -1
  590. package/packages/web/dist/assets/ContextRow-Byz_7HG-.css +0 -1
  591. package/packages/web/dist/assets/ContextRow-Dvv8CTFk.js +0 -2
  592. package/packages/web/dist/assets/DataTypePage-Ba_zBV4b.js +0 -4
  593. package/packages/web/dist/assets/FnView-B8MGAOoB.js +0 -2
  594. package/packages/web/dist/assets/InstallDialog-C9GDoUI2.js +0 -2
  595. package/packages/web/dist/assets/InstanceTypes-D8Jcxn70.js +0 -2
  596. package/packages/web/dist/assets/InstanceTypes-DAowwLB7.css +0 -1
  597. package/packages/web/dist/assets/InstanceView-CuBD3JPU.css +0 -1
  598. package/packages/web/dist/assets/InstanceView-p7tMaylE.js +0 -2
  599. package/packages/web/dist/assets/LimitsView-DsZG6u5P.js +0 -2
  600. package/packages/web/dist/assets/ListSearch-BK4p7Nxa.js +0 -2
  601. package/packages/web/dist/assets/McpServerView-CD8qw6W_.js +0 -2
  602. package/packages/web/dist/assets/McpServersView-DNycG35u.js +0 -2
  603. package/packages/web/dist/assets/ModelsView-C_iN19xt.js +0 -2
  604. package/packages/web/dist/assets/PairPage-Bs2KuRjC.css +0 -1
  605. package/packages/web/dist/assets/PairPage-TEXPpsqi.js +0 -2
  606. package/packages/web/dist/assets/PoliciesView-BU1fudNF.js +0 -2
  607. package/packages/web/dist/assets/ResourcesPage-YluNBqIv.js +0 -2
  608. package/packages/web/dist/assets/ReviewView-79Z5rU1v.js +0 -3
  609. package/packages/web/dist/assets/RunsView-Dz9Xsvu5.js +0 -2
  610. package/packages/web/dist/assets/ServiceRows-DNzDiutg.js +0 -2
  611. package/packages/web/dist/assets/SettingsPage-CykfuYj1.js +0 -3
  612. package/packages/web/dist/assets/SystemView-Es5wtkYU.js +0 -2
  613. package/packages/web/dist/assets/SystemsView-CeuSFhlF.js +0 -2
  614. package/packages/web/dist/assets/UserMessage-qyc8dG5D.js +0 -9
  615. package/packages/web/dist/assets/WidgetView-BZyDyYRI.js +0 -3
  616. package/packages/web/dist/assets/index-Bv42jNvr.js +0 -4
  617. package/packages/web/dist/assets/routes-qP_j74V5.js +0 -4
  618. package/packages/web/dist/assets/runs-k76usGfd.js +0 -2
  619. package/packages/web/dist/assets/src-DLK1P7oz.js +0 -43
  620. package/packages/web/dist/assets/state-CjE-qA2w.js +0 -2
  621. package/packages/web/dist/assets/ui-W12UYhVu.js +0 -17
  622. package/systems/claude/client/FleetPage.vue +0 -132
  623. package/systems/claude/client/NewSessionForm.vue +0 -62
  624. package/systems/claude/client/SessionList.vue +0 -64
  625. package/systems/claude/client/SessionPage.vue +0 -199
  626. package/systems/claude/client/TaskList.vue +0 -61
  627. package/systems/claude/client/fakes.ts +0 -186
  628. package/systems/claude/client/host.ts +0 -23
  629. package/systems/claude/client/index.ts +0 -15
  630. package/systems/claude/client/logic.ts +0 -270
  631. package/systems/claude/client/state.ts +0 -344
  632. package/systems/claude/package.json +0 -23
  633. package/systems/claude/server/agent-sdk.ts +0 -379
  634. package/systems/claude/server/driver.ts +0 -153
  635. package/systems/claude/server/env.ts +0 -64
  636. package/systems/claude/server/fake-driver.ts +0 -112
  637. package/systems/claude/server/fleet.ts +0 -376
  638. package/systems/claude/server/impl.ts +0 -568
  639. package/systems/claude/server/index.ts +0 -8
  640. package/systems/claude/server/main.ts +0 -38
  641. package/systems/claude/server/preview.ts +0 -76
  642. package/systems/claude/server/questions.ts +0 -117
  643. package/systems/claude/server/transcript.ts +0 -83
  644. package/systems/claude/shared/index.ts +0 -262
  645. package/systems/claude/shared/session.ts +0 -284
  646. package/systems/claude/shared/shapes.ts +0 -106
  647. package/systems/claude/system.json +0 -18
  648. package/systems/claude/tsconfig.json +0 -6
  649. package/systems/database/package.json +0 -25
  650. package/systems/database/server/author.ts +0 -41
  651. package/systems/database/server/authoring.ts +0 -322
  652. package/systems/database/server/catalog.ts +0 -117
  653. package/systems/database/server/compile.ts +0 -332
  654. package/systems/database/server/dialects.ts +0 -17
  655. package/systems/database/server/drivers/database.ts +0 -71
  656. package/systems/database/server/drivers/index.ts +0 -23
  657. package/systems/database/server/drivers/postgres.ts +0 -157
  658. package/systems/database/server/drivers/sqlite.ts +0 -151
  659. package/systems/database/server/drivers/sqlserver.ts +0 -176
  660. package/systems/database/server/env.ts +0 -35
  661. package/systems/database/server/fixture.ts +0 -169
  662. package/systems/database/server/impl.ts +0 -793
  663. package/systems/database/server/index.ts +0 -7
  664. package/systems/database/server/instance.ts +0 -398
  665. package/systems/database/server/main.ts +0 -47
  666. package/systems/database/server/pick.ts +0 -97
  667. package/systems/database/server/queries.ts +0 -390
  668. package/systems/database/server/results.ts +0 -39
  669. package/systems/database/server/schema.ts +0 -59
  670. package/systems/database/server/table-fns.ts +0 -237
  671. package/systems/database/server/types.ts +0 -253
  672. package/systems/database/shared/index.ts +0 -544
  673. package/systems/database/shared/shapes.ts +0 -413
  674. package/systems/database/system.json +0 -14
  675. package/systems/database/tsconfig.json +0 -6
  676. package/systems/fs/context/authoring/parts/examples/systems-fs-shared-index-ts-lines-371-533.md +0 -183
  677. package/systems/fs/context/authoring/parts/hub/hub-auto-pair-revoke.md +0 -189
  678. package/systems/web/client/ReadView.vue +0 -110
  679. package/systems/web/client/SearchView.vue +0 -215
  680. package/systems/web/client/StatusChip.vue +0 -38
  681. package/systems/web/client/fakes.ts +0 -48
  682. package/systems/web/client/index.ts +0 -15
  683. package/systems/web/client/view.ts +0 -131
  684. package/systems/web/package.json +0 -22
  685. package/systems/web/server/chrome.ts +0 -121
  686. package/systems/web/server/crawl.ts +0 -333
  687. package/systems/web/server/env.ts +0 -63
  688. package/systems/web/server/guard.ts +0 -60
  689. package/systems/web/server/http.ts +0 -89
  690. package/systems/web/server/impl.ts +0 -203
  691. package/systems/web/server/index.ts +0 -71
  692. package/systems/web/server/loader.ts +0 -104
  693. package/systems/web/server/main.ts +0 -70
  694. package/systems/web/server/mentions.ts +0 -111
  695. package/systems/web/server/problem.ts +0 -72
  696. package/systems/web/server/renderer.ts +0 -243
  697. package/systems/web/server/robots.ts +0 -75
  698. package/systems/web/server/searches.ts +0 -29
  699. package/systems/web/server/tavily.ts +0 -144
  700. package/systems/web/server/testing.ts +0 -165
  701. package/systems/web/server/uploads.ts +0 -33
  702. package/systems/web/shared/index.ts +0 -343
  703. package/systems/web/shared/urls.ts +0 -60
  704. package/systems/web/system.json +0 -15
  705. package/systems/web/tsconfig.json +0 -6
@@ -15,33 +15,34 @@ _Every code sample is a compiled file of the repository, so it is correct for th
15
15
  4. [Types with gin](#4-types-with-gin)
16
16
  5. [Named types and methods](#5-named-types-and-methods)
17
17
  6. [Stored types and the data system](#6-stored-types-and-the-data-system)
18
- 7. [Fns](#7-fns)
19
- 8. [Handlers and progress](#8-handlers-and-progress)
20
- 9. [Session state, forms and display](#9-session-state-forms-and-display)
21
- 10. [Outcomes: done, invalid input, failed, paused, cancelled, undo](#10-outcomes-done-invalid-input-failed-paused-cancelled-undo)
22
- 11. [Kinds and agents](#11-kinds-and-agents)
23
- 12. [Settings and attachments](#12-settings-and-attachments)
24
- 13. [Context and commands](#13-context-and-commands)
25
- 14. [Hooks](#14-hooks)
26
- 15. [Mentions](#15-mentions)
27
- 16. [Actions](#16-actions)
28
- 17. [Model providers](#17-model-providers)
29
- 18. [Resources, embedders and sectioners](#18-resources-embedders-and-sectioners)
30
- 19. [The hub contract](#19-the-hub-contract)
31
- 20. [The server: serve and the implementation](#20-the-server-serve-and-the-implementation)
32
- 21. [The run context and services](#21-the-run-context-and-services)
33
- 22. [Calling other fns](#22-calling-other-fns)
34
- 23. [Config, events, lifecycle and data](#23-config-events-lifecycle-and-data)
35
- 24. [Runs a system starts by itself, and notices](#24-runs-a-system-starts-by-itself-and-notices)
36
- 25. [Remote services: fleets, sign-in and connections per instance](#25-remote-services-fleets-sign-in-and-connections-per-instance)
37
- 26. [The client: renderers, inputs, resource views and pages](#26-the-client-renderers-inputs-resource-views-and-pages)
38
- 27. [Visuals and widgets](#27-visuals-and-widgets)
39
- 28. [Packaging: system.json, build, pack, install](#28-packaging-systemjson-build-pack-install)
40
- 29. [Testing](#29-testing)
41
- 30. [Common mistakes](#30-common-mistakes)
42
- 31. [Worked examples](#31-worked-examples)
43
- 32. [Runtime internals](#32-runtime-internals)
44
- 33. [Core types](#33-core-types)
18
+ 7. [A store of the system’s own](#7-a-store-of-the-systems-own)
19
+ 8. [Fns](#8-fns)
20
+ 9. [Handlers and progress](#9-handlers-and-progress)
21
+ 10. [Session state, forms and display](#10-session-state-forms-and-display)
22
+ 11. [Outcomes: done, invalid input, failed, paused, cancelled, undo](#11-outcomes-done-invalid-input-failed-paused-cancelled-undo)
23
+ 12. [Kinds and agents](#12-kinds-and-agents)
24
+ 13. [Settings and attachments](#13-settings-and-attachments)
25
+ 14. [Context and commands](#14-context-and-commands)
26
+ 15. [Hooks](#15-hooks)
27
+ 16. [Mentions](#16-mentions)
28
+ 17. [Actions](#17-actions)
29
+ 18. [Model providers](#18-model-providers)
30
+ 19. [Resources, embedders and sectioners](#19-resources-embedders-and-sectioners)
31
+ 20. [The hub contract](#20-the-hub-contract)
32
+ 21. [The server: serve and the implementation](#21-the-server-serve-and-the-implementation)
33
+ 22. [The run context and services](#22-the-run-context-and-services)
34
+ 23. [Calling other fns](#23-calling-other-fns)
35
+ 24. [Config, events, lifecycle and data](#24-config-events-lifecycle-and-data)
36
+ 25. [Runs a system starts by itself, and notices](#25-runs-a-system-starts-by-itself-and-notices)
37
+ 26. [Remote services: fleets, sign-in and connections per instance](#26-remote-services-fleets-sign-in-and-connections-per-instance)
38
+ 27. [The client: renderers, inputs, resource views and pages](#27-the-client-renderers-inputs-resource-views-and-pages)
39
+ 28. [Visuals and widgets](#28-visuals-and-widgets)
40
+ 29. [Packaging: system.json, build, pack, install](#29-packaging-systemjson-build-pack-install)
41
+ 30. [Testing](#30-testing)
42
+ 31. [Common mistakes](#31-common-mistakes)
43
+ 32. [Worked examples](#32-worked-examples)
44
+ 33. [Runtime internals](#33-runtime-internals)
45
+ 34. [Core types](#34-core-types)
45
46
 
46
47
  ## 1. Start here
47
48
 
@@ -82,7 +83,7 @@ Four rules hold everywhere; the compiler enforces the first three:
82
83
  records of a stored type (`type({ records })`), read and written with `ctx.data` and searched by the hub's database
83
84
  (**Stored types and the data system**). Never keep it in a file or database of the system's own, and never load a
84
85
  whole set to filter or search it in code: every read is a query with a page. A system's folder (`ctx.dataDir`) holds
85
- only its own config, keys and caches.
86
+ only its own keys and caches, and working tables only its code reads go in a store of its own (`store()`).
86
87
 
87
88
  The worked example throughout is the **notes** system (`scripts/docs/example`, shown whole in **Worked examples**): notes with
88
89
  titles and tags, kept and searched by the hub as records of a stored type. Every code sample in this guide is a region of a file
@@ -564,6 +565,12 @@ _From `scripts/docs/example/shared/index.ts`:_
564
565
  description: 'How to keep notes here: search before adding, short titles, lowercase tags.',
565
566
  content: 'Search with notes/find before adding a note, so you do not add one twice. Keep titles short and tags lowercase.',
566
567
  fns: [fns.find, fns.add],
568
+ // the one question it answers (searches compare with it) and when a model should read it
569
+ question: 'How should notes be added and tagged here?',
570
+ when: 'When adding, titling or tagging a note.',
571
+ // when its text last changed, and who would ask it: a system's own guide is asked by `system`
572
+ lastModified: Date.parse('2026-11-28'),
573
+ askedBy: 'system',
567
574
  // for the graph contextor: how much it counts, a short form for tight budgets, and what it relates to
568
575
  weight: 1.2,
569
576
  summary: 'Search before adding; short titles; lowercase tags.',
@@ -745,6 +752,11 @@ interface SystemContract<N extends string, C extends ContractShape> extends Syst
745
752
  readonly defs: C;
746
753
  /** Add declarations: any sections, given directly or built from the refs so far. */
747
754
  with<const P extends Partial<ContractShape>>(part: P | ((self: SystemRefs<N, C>) => P)): SystemContract<N, Merge<C, P>>;
755
+ /**
756
+ * Type an implementation against this contract, with the store's tables as `Db` (`notes.implement<NotesDb>({ ... })`),
757
+ * so `ctx.store` is Kysely over them. It returns the implementation as given; `SystemImpl<C, Db>` is the same type.
758
+ */
759
+ readonly implement: Implement<C>;
748
760
  }
749
761
  ```
750
762
 
@@ -803,6 +815,11 @@ interface ContractShape {
803
815
  * fns act as them. `undefined` for a system everyone shares. The implementation then serves `connect`.
804
816
  */
805
817
  connect: ConnectDecl | undefined;
818
+ /**
819
+ * The system's own SQL store (`store()`), or `undefined` for a system that keeps nothing of its own. Its code sees it
820
+ * as `ctx.store`, typed by the table interface given to `implement<Db>`.
821
+ */
822
+ store: StoreDecl | undefined;
806
823
  /** The system's name (`schedule`), so what is computed from the contract alone (the refs its ctxs take) is named. */
807
824
  system: string;
808
825
  /** Its declared pages, by segment (`system(name, { pages })`), so links to them are refs (`contract.page.item`). */
@@ -810,16 +827,16 @@ interface ContractShape {
810
827
  }
811
828
  ```
812
829
 
813
- Refers to: [`ConnectDecl`](#core-connectdecl), [`SystemPageDecl`](#core-systempagedecl).
830
+ Refers to: [`ConnectDecl`](#core-connectdecl), [`StoreDecl`](#core-storedecl), [`SystemPageDecl`](#core-systempagedecl).
814
831
 
815
832
  #### `ContractSection`
816
833
 
817
834
  type · `import { ContractSection } from '@harness/sdk'`
818
835
 
819
- The sections of a contract that add named declarations (all but `config`, `connect`, `system` and `pages`).
836
+ The sections of a contract that add named declarations (all but `config`, `connect`, `store`, `system` and `pages`).
820
837
 
821
838
  ```ts
822
- type ContractSection = Exclude<keyof ContractShape, 'config' | 'connect' | 'system' | 'pages'>;
839
+ type ContractSection = Exclude<keyof ContractShape, 'config' | 'connect' | 'store' | 'system' | 'pages'>;
823
840
  ```
824
841
 
825
842
  #### `CONTRACT_SECTIONS`
@@ -853,6 +870,7 @@ interface EmptyContract<N extends string = string, S extends string = never> {
853
870
  config: GinType<{}>;
854
871
  types: {}; settings: {}; attachments: {}; kinds: {}; fns: {}; context: {}; hooks: {}; mentions: {}; sectioners: {}; actions: {}; providers: {};
855
872
  connect: undefined;
873
+ store: undefined;
856
874
  system: N;
857
875
  pages: { [K in S]: SystemPageDecl };
858
876
  }
@@ -864,8 +882,8 @@ Refers to: [`SystemPageDecl`](#core-systempagedecl).
864
882
 
865
883
  type · `import { Merge } from '@harness/sdk'`
866
884
 
867
- A contract with more sections merged in: `config` and `connect` are replaced, `system` and `pages` are kept (they are
868
- declared once, by `system()`), every other section adds to what was declared.
885
+ A contract with more sections merged in: `config`, `connect` and `store` are replaced, `system` and `pages` are kept
886
+ (they are declared once, by `system()`), every other section adds to what was declared.
869
887
 
870
888
  ```ts
871
889
  type Merge<C extends ContractShape, P extends Partial<ContractShape>> = {
@@ -873,13 +891,15 @@ type Merge<C extends ContractShape, P extends Partial<ContractShape>> = {
873
891
  ? (P extends { config: infer X extends GinType<object> } ? X : C['config'])
874
892
  : K extends 'connect'
875
893
  ? (P extends { connect: infer X extends ConnectDecl } ? X : C['connect'])
876
- : K extends 'system' | 'pages'
877
- ? C[K]
878
- : Simplify<C[K] & (K extends keyof P ? NonNullable<P[K]> : {})>;
894
+ : K extends 'store'
895
+ ? (P extends { store: infer X extends StoreDecl } ? X : C['store'])
896
+ : K extends 'system' | 'pages'
897
+ ? C[K]
898
+ : Simplify<C[K] & (K extends keyof P ? NonNullable<P[K]> : {})>;
879
899
  };
880
900
  ```
881
901
 
882
- Refers to: [`ConnectDecl`](#core-connectdecl).
902
+ Refers to: [`ConnectDecl`](#core-connectdecl), [`StoreDecl`](#core-storedecl).
883
903
 
884
904
  #### `AnyContract`
885
905
 
@@ -1774,9 +1794,9 @@ type · `import { MethodImpl } from '@harness/sdk'`
1774
1794
  A method's implementation: a native fn that also gets the value it was called on.
1775
1795
 
1776
1796
  ```ts
1777
- type MethodImpl<V, T extends FnTypes, Cfg = unknown, O extends Own = Own> =
1797
+ type MethodImpl<V, T extends FnTypes, Cfg = unknown, O extends AnyOwn = Own> =
1778
1798
  { run(self: V, args: T['args'], ctx: FnCtx<T, Cfg, O>): Promise<Outcome<T>> } &
1779
- ([T['undo']] extends [never] ? { undo?: never } : { undo(payload: T['undo'], ctx: UndoCtx<Cfg>): Promise<UndoOutcome> });
1799
+ ([T['undo']] extends [never] ? { undo?: never } : { undo(payload: T['undo'], ctx: UndoCtx<Cfg, O['store']>): Promise<UndoOutcome> });
1780
1800
  ```
1781
1801
 
1782
1802
  Refers to: [`UndoOutcome`](#core-undooutcome).
@@ -1786,9 +1806,10 @@ Refers to: [`UndoOutcome`](#core-undooutcome).
1786
1806
  **Where data lives.** Data a system keeps for people (notes, tasks, contacts, anything shared or looked up later)
1787
1807
  lives in the hub as **records of a stored type**, never in a file or database of the system's own. The hub keeps them,
1788
1808
  checks each against the type, versions every change, controls who sees them, searches them in its database (by words
1789
- and by meaning) and shows them on the Data page, where people browse, filter, edit and turn them into widgets. A
1790
- system's own folder (`ctx.dataDir`) holds only what is the system's alone: its keys, a cache, a working copy of
1791
- something it syncs. An external database stays where it is (the database system reads it).
1809
+ and by meaning) and shows them on the Data page, where people browse, filter, edit and turn them into widgets. Working
1810
+ tables only the system's code reads (a queue, an index, vectors it searches itself) go in a store of its own (**A store
1811
+ of the system’s own**), and its own folder (`ctx.dataDir`) holds only files that are the system's alone: its keys, a
1812
+ cache, a working copy of something it syncs. An external database stays where it is (the database system reads it).
1792
1813
 
1793
1814
  A type is **stored** when it declares `records`:
1794
1815
 
@@ -2032,7 +2053,632 @@ interface RecordFind {
2032
2053
 
2033
2054
  Refers to: [`ListQuery`](#core-listquery).
2034
2055
 
2035
- ## 7. Fns
2056
+ ## 7. A store of the system’s own
2057
+
2058
+ **A store of the system's own.** Some systems keep working tables of their own: a timer's queue, an index of the
2059
+ copies they keep, vectors they manage themselves. That is a **store**: the system's private SQL database, declared in
2060
+ its contract and opened by the SDK wherever the admin placed it. Each question below is its own context item.
2061
+
2062
+ ### When should a system keep a store instead of hub records?
2063
+
2064
+ Data people see, search and share stays in hub records (**Stored types and the data system**): the hub checks,
2065
+ versions, shares and searches them, and shows them on the Data page. A store is for what only the system's code
2066
+ reads: a queue of work, an index, bookkeeping, vectors it searches itself. Nobody browses a store, and the hub never
2067
+ searches it. Files the system keeps for itself (keys, a cache, copies too big for a table) stay in its data folder
2068
+ (`ctx.dataDir`, **Config, events, lifecycle and data**), and a store can index them. Never keep a SQLite file of your
2069
+ own in the data folder: a store is that database, placed, migrated, backed up and moved by the hub.
2070
+
2071
+ ### How do I declare a store in a system's contract?
2072
+
2073
+ ```ts
2074
+ export const notes = system('notes', { description: 'Keeps notes and finds them by meaning.' })
2075
+ .with({ store: store({ description: 'Notes and their embeddings.', vectors: true }) });
2076
+ ```
2077
+
2078
+ - `description`: what the store holds, shown when the system is installed and on its Storage panel.
2079
+ - `vectors`: whether it keeps vectors (`ctx.store.vectors(name)`); an external database must then be able to hold
2080
+ them (pgvector, SQL Server 2025).
2081
+ - `engines`: the engines it may run on (default all: `sqlite`, `postgres`, `sqlserver`).
2082
+
2083
+ A contract declares at most one store. Its tables come from the migrations the server hands to `serve`.
2084
+
2085
+ ### Where does a system's store live?
2086
+
2087
+ **Where it lives is the admin's choice**, made when the system is installed: with the system (the default: SQLite
2088
+ with sqlite-vec in its data folder), on the hub (SQLite in the hub's data folder; the system's statements go over
2089
+ its link), or in an external Postgres or SQL Server database, in a schema the admin names. The hub tells the system
2090
+ in its welcome; the system's code is the same in every placement, so never branch on where the store is.
2091
+
2092
+ ### What happens to a system's store when an admin moves it?
2093
+
2094
+ A move (Admin › Systems › <system> › Storage, or `fnloom system store move`) holds calls to the system, gives runs
2095
+ still going a minute to finish (then asks the admin to cancel them or keep waiting), closes the store and copies it: a
2096
+ SQLite copy between the hub and the system, or, to or from Postgres or SQL Server, the same migrations on an empty
2097
+ schema and then every table and vector set copied in pages, with row counts checked. The copy runs in the system's
2098
+ own process (it reaches its file, the external database and the hub's file), and the store opens on its new side
2099
+ before calls go again; the old copy is kept as a backup until the admin deletes it. A move that fails part-way leaves
2100
+ the store where it was.
2101
+
2102
+ What this means for an author:
2103
+
2104
+ - Nothing in the system's code changes for a move: `ctx.store` waits while it happens and then runs on the new side.
2105
+ - Keep what a store holds in its tables and vector sets. Files the system writes beside it stay where they are.
2106
+ - A store with vectors can't move to an engine that can't hold them (no pgvector, SQL Server before 2025, or a vector
2107
+ set larger than the engine takes: 1998 numbers on SQL Server, 8192 on SQLite, 16000 on Postgres), and the move is
2108
+ refused before it starts. Pick vector sizes every engine you list in `engines` takes.
2109
+ - When the system is removed, its store is kept by default (listed as orphaned) and picked up again when the
2110
+ instance comes back; the admin can delete it with the removal instead.
2111
+
2112
+ ### How do I write a store's tables and migrations?
2113
+
2114
+ The server writes the tables as a TypeScript interface (Kysely's view of them) and an ordered list of
2115
+ `migration(id, up)`, forward only; ids never change once shipped:
2116
+
2117
+ ```ts
2118
+ export interface NotesDb extends StoreDb {
2119
+ notes: { id: string; title: string; tags: string[] | null; created_at: Date };
2120
+ }
2121
+
2122
+ export const migrations = [
2123
+ migration('001-notes', async (db) => {
2124
+ await db.schema.createTable('notes')
2125
+ .addColumn('id', 'text', (c) => c.primaryKey())
2126
+ .addColumn('title', 'text', (c) => c.notNull())
2127
+ .addColumn('created_at', t.timestamp(), (c) => c.notNull())
2128
+ .execute();
2129
+ await db.vectors.create('note_text', { dimensions: 1024 });
2130
+ }),
2131
+ migration('002-tags', async (db) => {
2132
+ await db.schema.alterTable('notes').addColumn('tags', t.json()).execute();
2133
+ }),
2134
+ ];
2135
+ ```
2136
+
2137
+ - `t.json()`, `t.timestamp()` and `t.bool()` are the column types engines disagree on; each becomes the engine's own
2138
+ (`jsonb`, `timestamptz`, `boolean` on Postgres; text, milliseconds and 0 or 1 on SQLite) and is read back as the
2139
+ system wrote it (the parsed value, a `Date`, a boolean). Every other type (`text`, `integer`, `real`) is written as
2140
+ Kysely takes it.
2141
+ - `db.vectors.create(name, { dimensions })` makes a set of vectors (sqlite-vec `vec0`, pgvector, `VECTOR(n)`).
2142
+ - What ran is recorded inside the store, each id with a checksum of its code. A migration changed or removed after it
2143
+ ran is refused, and the system stays down with that error: add a new migration instead.
2144
+ - A SQLite store is snapshotted before pending migrations run (the last three kept); a migration that fails puts the
2145
+ snapshot back and the system reports its store `failed`.
2146
+
2147
+ ### How does a migration handle what differs between engines?
2148
+
2149
+ A migration knows its engine (`db.engine`), for what `t` doesn't cover: an identity column (`autoIncrement()` on
2150
+ SQLite, `generatedByDefaultAsIdentity()` on Postgres, `identity()` on SQL Server), or long text that SQL Server must
2151
+ index or call `nvarchar(max)`. Keys and anything indexed are `varchar(n)`; times as numbers are `bigint`, which
2152
+ Postgres reads back as text, so parse them with `z.coerce.number()`.
2153
+
2154
+ ### What does a system with a store need before it takes calls?
2155
+
2156
+ **`serve` takes the migrations, and nothing runs until the store is ready.** Hand them to `serve` with
2157
+ `store: { migrations }`. The store opens where the hub says and its pending migrations run before the system takes a
2158
+ call or runs `started`; until then the hub holds calls to it (fn runs, hooks, firings, authoring) for up to two minutes,
2159
+ then refuses them with "<system> is getting its storage ready". A system with a store lists `better-sqlite3` and
2160
+ `sqlite-vec` in its `system.json` `server.external` (and `pg`, or `tedious` and `tarn`, to run on an external
2161
+ database): they carry native code, so the installer fetches them beside the bundle. A system the hub runs from its
2162
+ source folder gets the Postgres and SQL Server drivers from the hub instead, which installs them into its drivers
2163
+ folder when the store is placed there (they are not in the base install); the versions it installs are the ones the
2164
+ system's `server.external` names.
2165
+
2166
+ ### How does a fn read and write its system's store?
2167
+
2168
+ **In code it is `ctx.store`**: Kysely over the tables (typed when the implementation is `contract.implement<NotesDb>`),
2169
+ plus `vectors(name)`. Transactions carry vectors too:
2170
+
2171
+ ```ts
2172
+ export const createImpl = () => notes.implement<NotesDb>({
2173
+ fns: {
2174
+ add: {
2175
+ async run({ title, body }, ctx) {
2176
+ const id = crypto.randomUUID();
2177
+ await ctx.store.transaction().execute(async (tx) => {
2178
+ await tx.insertInto('notes').values({ id, title, tags: null, created_at: new Date() }).execute();
2179
+ await tx.vectors('note_text').upsert(id, await embed(ctx, body));
2180
+ });
2181
+ return ctx.done({ id });
2182
+ },
2183
+ },
2184
+ },
2185
+ });
2186
+ ```
2187
+
2188
+ `ctx.store` is one object for the system's whole life, so code may keep it (a timer or a queue set up in
2189
+ `started`): each statement waits while the store is being opened, migrated or moved, as a held call does, and then
2190
+ runs on the connection open at that moment, on whichever side and engine the store is on.
2191
+
2192
+ Inside a transaction, use its `tx` for every statement: the store is one connection, so a statement on `ctx.store`
2193
+ waits for the transaction to end. On the hub, a transaction holds the store's file for itself under a lease (30
2194
+ seconds between statements); one that goes quiet longer is rolled back. Keep transactions short, and never wait on a
2195
+ person or a model inside one.
2196
+
2197
+ ### How does a system keep vectors in its store and find the nearest ones?
2198
+
2199
+ Declare the store with `vectors: true`, and make each set in a migration with `db.vectors.create(name, { dimensions })`
2200
+ (a name of lowercase letters, digits and underscores). Then `ctx.store.vectors(name)` (or `tx.vectors(name)` in a
2201
+ transaction) has three methods, each keyed by a string the system chooses (usually a row's id):
2202
+
2203
+ - `upsert(key, vector)` adds or replaces one vector; a vector of another size than its set is refused.
2204
+ - `remove(keys)` removes one key or a list of them.
2205
+ - `nearest(vector, { k?, keys? })` gives the `k` nearest (default 10, at most 4096), each `{ key, distance, score }`:
2206
+ cosine distance, and `score` as a similarity from 0 to 1. `keys` limits the search to those keys.
2207
+
2208
+ Make the vectors with the hub's embedders (`ctx.llm.embed(texts)`), never by calling a model provider directly.
2209
+ Every engine computes cosine distance the same way, so the results don't change when the store moves.
2210
+
2211
+ ### How do I type the tables of one part of a system on their own?
2212
+
2213
+ `storeTables<IndexTables>(ctx.store)` is Kysely's query builders over the store's executor (and
2214
+ `storeTables<IndexTables>(tx)` inside a transaction), typed by that part's interface (an index, a queue) whatever
2215
+ `implement<Db>` says, with no cast.
2216
+
2217
+ ### How do I run a work queue in a system's store?
2218
+
2219
+ `storeWorkBackend(ctx.store)` is `@ayepi/work`'s Queue, Store and PubSub over the store, to spread into `createWork`;
2220
+ its tables are `workMigrations('002-work')`, listed with the system's own migrations:
2221
+
2222
+ ```ts
2223
+ export const migrations = [migration('001-notes', ...), ...workMigrations('002-work')];
2224
+
2225
+ const backend = storeWorkBackend(ctx.store);
2226
+ const work = createWork({ work: [due] as const, ...backend });
2227
+ ```
2228
+
2229
+ It keeps `@ayepi/sqlite`'s semantics in SQL every engine and the hub's guard take: leases with redelivery (a lapsed
2230
+ lease comes back as the next attempt), a claim no two workers can both win, dedupe keys, dead letters
2231
+ (`backend.queue.dead()`), keys with a time to live, an atomic `setIfNotExists` and `increment`. Its queue moves with
2232
+ the store. PubSub stays in the process (an instance is one process). The engine counts an item's delay from when it
2233
+ was enqueued and writes it to the store a moment later; wait for its `queued` event (`onEvent`) before moving a
2234
+ test's clock on. `workTables(ctx.store)` reads the tables themselves. Testing a store and its work queue is in
2235
+ **Testing**.
2236
+
2237
+ ### Reference: a store of the system’s own
2238
+
2239
+ #### `store`
2240
+
2241
+ function · `import { store } from '@harness/sdk'`
2242
+
2243
+ Declare the system's store (`.with({ store: store({ ... }) })`): what it holds, whether it keeps vectors, and the
2244
+ engines it may run on (default every one; `['sqlite']` keeps it on the hub or with the system). Its migrations are
2245
+ the server's (`serve(..., { store: { migrations } })`).
2246
+
2247
+ ```ts
2248
+ function store(input: z.input<typeof StoreDecl>): StoreDecl;
2249
+ ```
2250
+
2251
+ Refers to: [`StoreDecl`](#core-storedecl).
2252
+
2253
+ #### `StoreDb`
2254
+
2255
+ interface · `import { StoreDb } from '@harness/sdk'`
2256
+
2257
+ The tables every store has, which a system's own table interface extends (`interface NotesDb extends StoreDb`). The
2258
+ SDK keeps them; a system reads them at most.
2259
+
2260
+ ```ts
2261
+ interface StoreDb {
2262
+ _store_migrations: StoreMigrationRow;
2263
+ }
2264
+ ```
2265
+
2266
+ #### `StoreMigrationRow`
2267
+
2268
+ interface · `import { StoreMigrationRow } from '@harness/sdk'`
2269
+
2270
+ A row of `_store_migrations`, the table every store keeps its applied migrations in.
2271
+
2272
+ ```ts
2273
+ interface StoreMigrationRow {
2274
+ /** The migration's id. */
2275
+ name: string;
2276
+ /** When it ran, as ISO text (Kysely's own column). */
2277
+ timestamp: string;
2278
+ /** The checksum of its code when it ran: a later change to it is refused. */
2279
+ checksum: string | null;
2280
+ }
2281
+ ```
2282
+
2283
+ #### `SystemStore`
2284
+
2285
+ type · `import { SystemStore } from '@harness/sdk'`
2286
+
2287
+ `ctx.store`: Kysely over the store's tables (`Db`), the same in every placement, plus its vectors. Its transactions
2288
+ carry vectors too. On the hub a transaction holds the store's file for itself under a lease (30 s by default between
2289
+ statements); a quiet one is rolled back.
2290
+
2291
+ ```ts
2292
+ type SystemStore<Db> = Omit<Kysely<Db>, 'transaction'> & {
2293
+ /** The engine it runs on. */
2294
+ readonly engine: StoreEngine;
2295
+ transaction(): StoreTransactionBuilder<Db>;
2296
+ vectors(name: string): StoreVectors;
2297
+ };
2298
+ ```
2299
+
2300
+ Refers to: [`StoreEngine`](#core-storeengine).
2301
+
2302
+ #### `StoreTransaction`
2303
+
2304
+ type · `import { StoreTransaction } from '@harness/sdk'`
2305
+
2306
+ A transaction on the store: Kysely's, plus vectors in the same transaction.
2307
+
2308
+ ```ts
2309
+ type StoreTransaction<Db> = Transaction<Db> & {
2310
+ vectors(name: string): StoreVectors;
2311
+ };
2312
+ ```
2313
+
2314
+ #### `StoreTransactionBuilder`
2315
+
2316
+ interface · `import { StoreTransactionBuilder } from '@harness/sdk'`
2317
+
2318
+ `ctx.store.transaction()`: run a function in one transaction; it commits when the function resolves, else rolls back.
2319
+
2320
+ ```ts
2321
+ interface StoreTransactionBuilder<Db> {
2322
+ execute<T>(fn: (tx: StoreTransaction<Db>) => Promise<T>): Promise<T>;
2323
+ }
2324
+ ```
2325
+
2326
+ #### `StoreVectors`
2327
+
2328
+ interface · `import { StoreVectors } from '@harness/sdk'`
2329
+
2330
+ A named set of vectors in the store (`ctx.store.vectors('note_text')`), each kept under a text key, all of the size
2331
+ its migration made it with (`db.vectors.create(name, { dimensions })`). On SQLite it is a sqlite-vec `vec0` table,
2332
+ on Postgres a pgvector column, on SQL Server 2025 a `VECTOR` column; distance is cosine everywhere.
2333
+
2334
+ ```ts
2335
+ interface StoreVectors {
2336
+ /** Add or replace the vector kept under `key`. */
2337
+ upsert(key: string, vector: readonly number[]): Promise<void>;
2338
+ /** Remove the vectors under these keys (missing ones are skipped). */
2339
+ remove(keys: string | readonly string[]): Promise<void>;
2340
+ /** The `k` nearest (default 10), nearest first; with `keys`, only among those. */
2341
+ nearest(vector: readonly number[], options?: { readonly k?: number; readonly keys?: readonly string[] }): Promise<VectorHit[]>;
2342
+ }
2343
+ ```
2344
+
2345
+ #### `VectorHit`
2346
+
2347
+ interface · `import { VectorHit } from '@harness/sdk'`
2348
+
2349
+ One vector found near another: its key, its cosine distance (0 the same, 2 opposite) and a similarity score in [0, 1].
2350
+
2351
+ ```ts
2352
+ interface VectorHit {
2353
+ readonly key: string;
2354
+ readonly distance: number;
2355
+ readonly score: number;
2356
+ }
2357
+ ```
2358
+
2359
+ #### `migration`
2360
+
2361
+ function · `import { migration } from '@harness/sdk/server'`
2362
+
2363
+ A migration: an id that never changes once shipped (ids sort as text, so `001-notes`, `002-tags`), and what it does.
2364
+ Forward only. Its checksum is taken from its code, so changing a shipped migration is refused at the next start:
2365
+ add a new one instead.
2366
+
2367
+ ```ts
2368
+ function migration(id: string, up: (db: MigrationDb) => Promise<void>): Migration;
2369
+ ```
2370
+
2371
+ #### `Migration`
2372
+
2373
+ interface · `import { Migration } from '@harness/sdk/server'`
2374
+
2375
+ One migration: its id (fixed once shipped), what it does, and the checksum of that code.
2376
+
2377
+ ```ts
2378
+ interface Migration {
2379
+ readonly id: MigrationId;
2380
+ readonly up: (db: MigrationDb) => Promise<void>;
2381
+ readonly checksum: string;
2382
+ }
2383
+ ```
2384
+
2385
+ Refers to: [`MigrationId`](#core-migrationid).
2386
+
2387
+ #### `MigrationDb`
2388
+
2389
+ type · `import { MigrationDb } from '@harness/sdk/server'`
2390
+
2391
+ What a migration gets: Kysely over the store (any table: a migration makes them, so it can't be typed by them) and
2392
+ its vector sets. Write the schema with Kysely's builder (`db.schema.createTable(...)`), using `t` for the column
2393
+ types that differ between engines, and `engine` for what `t` doesn't cover (an identity column, SQL Server's long
2394
+ text).
2395
+
2396
+ ```ts
2397
+ type MigrationDb = AnyKysely & { readonly vectors: MigrationVectors; readonly engine: StoreEngine };
2398
+ ```
2399
+
2400
+ Refers to: [`StoreEngine`](#core-storeengine).
2401
+
2402
+ #### `MigrationVectors`
2403
+
2404
+ interface · `import { MigrationVectors } from '@harness/sdk/server'`
2405
+
2406
+ Vector sets, as a migration makes and drops them.
2407
+
2408
+ ```ts
2409
+ interface MigrationVectors {
2410
+ /** Make a vector set whose vectors have `dimensions` numbers (sqlite-vec `vec0`, pgvector, SQL Server `VECTOR`). */
2411
+ create(name: string, options: { readonly dimensions: number }): Promise<void>;
2412
+ /** Drop a vector set and every vector in it. */
2413
+ drop(name: string): Promise<void>;
2414
+ }
2415
+ ```
2416
+
2417
+ #### `MigrationFailed`
2418
+
2419
+ class · `import { MigrationFailed } from '@harness/sdk/server'`
2420
+
2421
+ A migration that failed as it ran.
2422
+
2423
+ ```ts
2424
+ class MigrationFailed extends Error {
2425
+ readonly name: "MigrationFailed";
2426
+ readonly migration: string;
2427
+ constructor(migration: string, cause: unknown);
2428
+ }
2429
+ ```
2430
+
2431
+ #### `MigrationRefused`
2432
+
2433
+ class · `import { MigrationRefused } from '@harness/sdk/server'`
2434
+
2435
+ A migration the store's record refuses: one that ran and is gone from the list, or whose code changed.
2436
+
2437
+ ```ts
2438
+ class MigrationRefused extends Error {
2439
+ readonly name: "MigrationRefused";
2440
+ }
2441
+ ```
2442
+
2443
+ #### `t`
2444
+
2445
+ const · `import { t } from '@harness/sdk/server'`
2446
+
2447
+ Portable column types for migrations: `addColumn('created_at', t.timestamp(), (c) => c.notNull())`. Every other type
2448
+ (`text`, `integer`, `real`, `blob`) is the same on every engine and is written as Kysely takes it.
2449
+
2450
+ ```ts
2451
+ const t: { json: () => RawBuilder<unknown>; timestamp: () => RawBuilder<unknown>; bool: () => RawBuilder<unknown>; };
2452
+ ```
2453
+
2454
+ #### `StoreServeOptions`
2455
+
2456
+ interface · `import { StoreServeOptions } from '@harness/sdk/server'`
2457
+
2458
+ What `serve` takes for a system with a store: its migrations, in order.
2459
+
2460
+ ```ts
2461
+ interface StoreServeOptions {
2462
+ readonly migrations: readonly Migration[];
2463
+ }
2464
+ ```
2465
+
2466
+ #### `STORE_DRIVER_MODULES`
2467
+
2468
+ const · `import { STORE_DRIVER_MODULES } from '@harness/sdk/server'`
2469
+
2470
+ The packages a store's engines load, only when a store opens on them. A server bundle leaves them out (better-sqlite3
2471
+ and sqlite-vec carry native code), so a system with a store lists them in `system.json` `server.external`:
2472
+ better-sqlite3 and sqlite-vec always, pg for Postgres, tedious and tarn for SQL Server.
2473
+
2474
+ ```ts
2475
+ const STORE_DRIVER_MODULES: readonly ["better-sqlite3", "sqlite-vec", "pg", "tedious", "tarn"];
2476
+ ```
2477
+
2478
+ #### `storeTables`
2479
+
2480
+ function · `import { storeTables } from '@harness/sdk/server'`
2481
+
2482
+ Kysely's query builders over a store or one of its transactions (`ctx.store`, a `tx`), typed by `T`.
2483
+
2484
+ ```ts
2485
+ function storeTables<T>(source: { getExecutor(): QueryExecutor; }): QueryCreator<T>;
2486
+ ```
2487
+
2488
+ #### `StoreSource`
2489
+
2490
+ interface · `import { StoreSource } from '@harness/sdk/server'`
2491
+
2492
+ What a view of a store needs: its engine, its query executor and its transactions. `ctx.store` is one.
2493
+
2494
+ ```ts
2495
+ interface StoreSource {
2496
+ readonly engine: StoreEngine;
2497
+ getExecutor(): QueryExecutor;
2498
+ transaction(): { execute<T>(fn: (tx: { getExecutor(): QueryExecutor }) => Promise<T>): Promise<T> };
2499
+ }
2500
+ ```
2501
+
2502
+ Refers to: [`StoreEngine`](#core-storeengine).
2503
+
2504
+ #### `storeWorkBackend`
2505
+
2506
+ function · `import { storeWorkBackend } from '@harness/sdk/server'`
2507
+
2508
+ `@ayepi/work`'s Queue, Store and PubSub over a system's store (`ctx.store`), on every engine and placement. Its
2509
+ tables come from `workMigrations()` in the system's migrations.
2510
+
2511
+ ```ts
2512
+ const backend = storeWorkBackend(ctx.store, { now: () => clock.now() });
2513
+ const work = createWork({ work: [due] as const, ...backend });
2514
+ ```
2515
+
2516
+ ```ts
2517
+ function storeWorkBackend(source: WorkStoreSource, options?: StoreWorkOptions): StoreWorkBackend;
2518
+ ```
2519
+
2520
+ #### `workMigrations`
2521
+
2522
+ function · `import { workMigrations } from '@harness/sdk/server'`
2523
+
2524
+ The work backend's tables, as migrations to put in the system's own list (`[...mine, ...workMigrations('002-work')]`).
2525
+ `id` is the first part of their ids (default `work`), so they sort where the system lists them; once shipped it never
2526
+ changes. Keys and names are `varchar` (SQL Server can't index longer text), bodies and values the engine's long text,
2527
+ times `bigint` milliseconds.
2528
+
2529
+ ```ts
2530
+ function workMigrations(id?: string): Migration[];
2531
+ ```
2532
+
2533
+ #### `workTables`
2534
+
2535
+ function · `import { workTables } from '@harness/sdk/server'`
2536
+
2537
+ Kysely over the work backend's tables on a store or one of its transactions (anything with `getExecutor()`, such
2538
+ as `ctx.store` or a `tx`), typed by `WorkTables` whatever the system's own table interface is. For a system's own
2539
+ reads and writes of them (an import, a look at the queue); the backend itself is `storeWorkBackend`.
2540
+
2541
+ ```ts
2542
+ function workTables(source: { getExecutor(): QueryExecutor; }): QueryCreator<WorkTables>;
2543
+ ```
2544
+
2545
+ #### `WorkTables`
2546
+
2547
+ interface · `import { WorkTables } from '@harness/sdk/server'`
2548
+
2549
+ The work backend's tables, as Kysely sees them.
2550
+
2551
+ ```ts
2552
+ interface WorkTables {
2553
+ work_queue: {
2554
+ id: Generated<number>;
2555
+ /** Which queue in the shared table. */
2556
+ name: string;
2557
+ body: string;
2558
+ /** When it may be leased (ms since 1970). */
2559
+ visible_at: number;
2560
+ /** The token of the lease that holds it, if one does. */
2561
+ lease_token: string | null;
2562
+ /** When that lease lapses (ms). */
2563
+ lease_until: number | null;
2564
+ /** Deliveries so far (the next one is `attempt + 1`). */
2565
+ attempt: number;
2566
+ dedupe_key: string | null;
2567
+ };
2568
+ work_queue_dead: { id: Generated<number>; name: string; body: string; error: string; at: number };
2569
+ work_kv: { key: string; value: string; expires_at: number | null };
2570
+ }
2571
+ ```
2572
+
2573
+ #### `WorkStoreSource`
2574
+
2575
+ type · `import { WorkStoreSource } from '@harness/sdk/server'`
2576
+
2577
+ What the backend needs of a store (`StoreSource`): its engine, its query executor and its transactions. `ctx.store`
2578
+ is one, in every placement; the backend types its own tables over the store's executor, so a system's table
2579
+ interface need not list them.
2580
+
2581
+ ```ts
2582
+ type WorkStoreSource = StoreSource;
2583
+ ```
2584
+
2585
+ #### `StoreWorkOptions`
2586
+
2587
+ interface · `import { StoreWorkOptions } from '@harness/sdk/server'`
2588
+
2589
+ Options for `storeWorkBackend`.
2590
+
2591
+ ```ts
2592
+ interface StoreWorkOptions {
2593
+ /** The clock leases, delays and expiry read (default `Date.now`). */
2594
+ readonly now?: () => number;
2595
+ /** Which queue in the shared table (default `'default'`). */
2596
+ readonly queue?: { readonly name?: string };
2597
+ /** Delete expired keys once every this many writes (default 1000). Reads never return an expired key anyway. */
2598
+ readonly sweepEvery?: number;
2599
+ }
2600
+ ```
2601
+
2602
+ #### `StoreWorkBackend`
2603
+
2604
+ interface · `import { StoreWorkBackend } from '@harness/sdk/server'`
2605
+
2606
+ The three ports, to spread into `createWork`.
2607
+
2608
+ ```ts
2609
+ interface StoreWorkBackend extends Backend {
2610
+ readonly queue: StoreWorkQueue;
2611
+ readonly store: StoreWorkStore;
2612
+ readonly pubsub: StoreWorkPubSub;
2613
+ }
2614
+ ```
2615
+
2616
+ #### `StoreWorkQueue`
2617
+
2618
+ interface · `import { StoreWorkQueue } from '@harness/sdk/server'`
2619
+
2620
+ The Queue over a store, plus a look at its dead letters. Every operation is async.
2621
+
2622
+ ```ts
2623
+ interface StoreWorkQueue extends Queue {
2624
+ push(body: string, opts?: { readonly delay?: number; readonly dedupeKey?: string }): Promise<void>;
2625
+ pop(max: number, visibility: number): Promise<PulledWork[]>;
2626
+ heartbeat(pulled: PulledWork, visibility: number): Promise<void>;
2627
+ ack(pulled: PulledWork): Promise<void>;
2628
+ fail(pulled: PulledWork, delay?: number): Promise<void>;
2629
+ deadLetter(body: string, error: string): Promise<void>;
2630
+ /** Items in the queue, leased or not. */
2631
+ size(): Promise<number>;
2632
+ /** Dead-lettered bodies, oldest first (up to `limit`, default 100). */
2633
+ dead(limit?: number): Promise<StoreDeadLetter[]>;
2634
+ }
2635
+ ```
2636
+
2637
+ #### `StoreWorkStore`
2638
+
2639
+ interface · `import { StoreWorkStore } from '@harness/sdk/server'`
2640
+
2641
+ The Store over a store's table. Every operation is async.
2642
+
2643
+ ```ts
2644
+ interface StoreWorkStore extends Store {
2645
+ get(key: string): Promise<string | undefined>;
2646
+ set(key: string, value: string, ttl?: number): Promise<void>;
2647
+ delete(key: string): Promise<void>;
2648
+ setIfNotExists(key: string, value: string, ttl?: number): Promise<boolean>;
2649
+ increment(key: string, by: number, ttl?: number): Promise<number>;
2650
+ }
2651
+ ```
2652
+
2653
+ #### `StoreWorkPubSub`
2654
+
2655
+ interface · `import { StoreWorkPubSub } from '@harness/sdk/server'`
2656
+
2657
+ In-process pub/sub: every subscriber in this process hears every publish.
2658
+
2659
+ ```ts
2660
+ interface StoreWorkPubSub extends PubSub {
2661
+ /** Drop every subscriber. */
2662
+ close(): void;
2663
+ }
2664
+ ```
2665
+
2666
+ #### `StoreDeadLetter`
2667
+
2668
+ interface · `import { StoreDeadLetter } from '@harness/sdk/server'`
2669
+
2670
+ A dead-lettered body, as `dead()` lists it.
2671
+
2672
+ ```ts
2673
+ interface StoreDeadLetter {
2674
+ readonly body: string;
2675
+ readonly error: string;
2676
+ /** When it was dead-lettered (ms since 1970). */
2677
+ readonly at: number;
2678
+ }
2679
+ ```
2680
+
2681
+ ## 8. Fns
2036
2682
 
2037
2683
  A **fn** is something people, agents and code can run: a name, a description, typed args and a typed result. A
2038
2684
  **native** fn is implemented in code by its own system and declared with `fn({ … })`. Only `description`, `args` and
@@ -2578,7 +3224,7 @@ What a fn's validation hooks get (`fn({ validate })`): the system's context, the
2578
3224
  its session and time), and for an output check which attempt this is (1 for the first result).
2579
3225
 
2580
3226
  ```ts
2581
- interface ValidateCtx<Cfg = unknown, O extends Own = Own> extends SystemCtx<Cfg, O> {
3227
+ interface ValidateCtx<Cfg = unknown, O extends AnyOwn = Own> extends SystemCtx<Cfg, O> {
2582
3228
  readonly run: RunInfo;
2583
3229
  /** The attempt whose result is checked; 1 for an input check. */
2584
3230
  readonly attempt: number;
@@ -2595,7 +3241,7 @@ What a `preview` gets: the system context, the run waiting for approval and whom
2595
3241
  change anything: it reads what the run would touch and says so.
2596
3242
 
2597
3243
  ```ts
2598
- interface PreviewCtx<Cfg = unknown, O extends Own = Own> extends SystemCtx<Cfg, O> {
3244
+ interface PreviewCtx<Cfg = unknown, O extends AnyOwn = Own> extends SystemCtx<Cfg, O> {
2599
3245
  readonly run: RunId;
2600
3246
  readonly user: UserInfo;
2601
3247
  }
@@ -2851,7 +3497,7 @@ What a fn's `claims(args, ctx)` gets: the system context, the person whose turn
2851
3497
  made it and its chat. The call isn't a run yet, so it has no run of its own.
2852
3498
 
2853
3499
  ```ts
2854
- interface ClaimsCtx<Cfg = unknown, O extends Own = Own> extends SystemCtx<Cfg, O> {
3500
+ interface ClaimsCtx<Cfg = unknown, O extends AnyOwn = Own> extends SystemCtx<Cfg, O> {
2855
3501
  readonly user: UserInfo;
2856
3502
  /** The agent run that made the call. */
2857
3503
  readonly caller: RunId;
@@ -3010,7 +3656,7 @@ class MissingExamplesError extends Error {
3010
3656
  }
3011
3657
  ```
3012
3658
 
3013
- ## 8. Handlers and progress
3659
+ ## 9. Handlers and progress
3014
3660
 
3015
3661
  ### Handlers
3016
3662
 
@@ -3277,7 +3923,7 @@ P extends StepsProgress<infer S> ? { steps: { [K in keyof S]: StepWire } } :
3277
3923
  undefined;
3278
3924
  ```
3279
3925
 
3280
- ## 9. Session state, forms and display
3926
+ ## 10. Session state, forms and display
3281
3927
 
3282
3928
  ### Session state
3283
3929
 
@@ -3382,7 +4028,7 @@ interface SessionState<S extends object> {
3382
4028
  }
3383
4029
  ```
3384
4030
 
3385
- ## 10. Outcomes: done, invalid input, failed, paused, cancelled, undo
4031
+ ## 11. Outcomes: done, invalid input, failed, paused, cancelled, undo
3386
4032
 
3387
4033
  Every run ends in an **outcome**, built with the ctx helpers, which are typed to the fn (its result, undo and resume
3388
4034
  types). Return exactly one; never throw to report something the caller should hear.
@@ -3759,7 +4405,7 @@ type SettledRunStatus = { [S in RunStatus]: (typeof SETTLED_BY_STATUS)[S] extend
3759
4405
 
3760
4406
  Refers to: [`RunStatus`](#core-runstatus).
3761
4407
 
3762
- ## 11. Kinds and agents
4408
+ ## 12. Kinds and agents
3763
4409
 
3764
4410
  ### Kinds
3765
4411
 
@@ -4060,12 +4706,12 @@ A kind's implementation. The payload is typed; a fn's args and result aren't (th
4060
4706
  arrive as JSON the hub has already checked against `describe`'s types.
4061
4707
 
4062
4708
  ```ts
4063
- interface KindImpl<P, Cfg = unknown, O extends Own = Own> {
4709
+ interface KindImpl<P, Cfg = unknown, O extends AnyOwn = Own> {
4064
4710
  /** Problems with a payload beyond its type (an unknown fn, a program that doesn't type-check). */
4065
4711
  check(payload: P, ctx: KindCheckCtx): Promise<string[]>;
4066
4712
  describe(payload: P, ctx: KindCheckCtx): Promise<KindDescription>;
4067
4713
  run(payload: P, args: Json, ctx: KindRunCtx<Cfg, O>): Promise<Outcome<UntypedFn>>;
4068
- undo?(payload: P, undo: Json, ctx: UndoCtx<Cfg>): Promise<UndoOutcome>;
4714
+ undo?(payload: P, undo: Json, ctx: UndoCtx<Cfg, O['store']>): Promise<UndoOutcome>;
4069
4715
  /** What a run of a payload's fn would do, for a fn `describe` gave an `approval` with a preview (a write query). */
4070
4716
  preview?(payload: P, args: Json, ctx: PreviewCtx<Cfg, O>): Promise<PreviewAnswer>;
4071
4717
  /**
@@ -4116,7 +4762,7 @@ interface · `import { KindRunCtx } from '@harness/sdk'`
4116
4762
  A kind's run context: like `FnCtx`, but calls are by name (limited to the deps `describe` returned).
4117
4763
 
4118
4764
  ```ts
4119
- interface KindRunCtx<Cfg = unknown, O extends Own = Own> extends Omit<FnCtx<UntypedFn, Cfg, O>, 'fns' | 'handlers' | 'progress'> {
4765
+ interface KindRunCtx<Cfg = unknown, O extends AnyOwn = Own> extends Omit<FnCtx<UntypedFn, Cfg, O>, 'fns' | 'handlers' | 'progress'> {
4120
4766
  call(fn: QualifiedName, args: Json, options?: { key?: string; background?: boolean }): FnCall<Json>;
4121
4767
  handler(name: string, args: Json): Promise<Json>;
4122
4768
  progress(state: { fraction: number; message?: string } | { step: string; status: StepStatus; detail?: string }): void;
@@ -4684,7 +5330,7 @@ The authoring agents' tunables.
4684
5330
  const authoringEnv: Env<EnvOutput<{}, { readonly HARNESS_AUTHORING_FIXES: z.ZodDefault<z.ZodCoercedNumber<unknown>>; readonly HARNESS_AUTHORING_ROUNDS: z.ZodDefault<z.ZodCoercedNumber<unknown>>; readonly HARNESS_AUTHORING_MAX_TOKENS: z.ZodDefault<z.ZodCoercedNumber<unknown>>; }>>;
4685
5331
  ```
4686
5332
 
4687
- ## 12. Settings and attachments
5333
+ ## 13. Settings and attachments
4688
5334
 
4689
5335
  ### Settings
4690
5336
 
@@ -4809,7 +5455,7 @@ interface AttachmentRef<N extends QualifiedName, T> {
4809
5455
 
4810
5456
  Refers to: [`QualifiedName`](#core-qualifiedname).
4811
5457
 
4812
- ## 13. Context and commands
5458
+ ## 14. Context and commands
4813
5459
 
4814
5460
  **Context** is text for the LLM: a guide, a skill, a reference, the state of something. The hub suggests it when a
4815
5461
  message is about it, an agent can always have it (`agent({ context })`), it can be injected into agents' system
@@ -4838,6 +5484,8 @@ prompts (`inject`), and a person loads it with a `/command`. `context({ descript
4838
5484
  be used. `mode: 'tools' | 'static'` only when the text is true in one chat mode.
4839
5485
  - An agent says how it takes its injected section: `agent({ injected: { detail: 'summary', maxTokens: 600 } })`, or
4840
5486
  `injected: 'none'`. A hook says what its block means with `hook({ explains })`, injected with its system's items.
5487
+ - `question`, `when`, `lastModified` and `askedBy`: the one question the item answers, when it is worth reading, when
5488
+ its text last changed and who would ask it (**How do I write a context item as one question?**, below).
4841
5489
  - For the graph contextor (the one small local models use): `weight` (0 to 2, default 1) is how much it counts,
4842
5490
  `summary` a short form sent when the budget allows only a little, `parent` and `next` place it in a hierarchy or a
4843
5491
  chain of pieces, and `links` are weighted edges (`{ to, relation, weight? }`) to other context, fns, named types or
@@ -4852,6 +5500,12 @@ context: {
4852
5500
  description: 'How to keep notes here: search before adding, short titles, lowercase tags.',
4853
5501
  content: 'Search with notes/find before adding a note, so you do not add one twice. Keep titles short and tags lowercase.',
4854
5502
  fns: [fns.find, fns.add],
5503
+ // the one question it answers (searches compare with it) and when a model should read it
5504
+ question: 'How should notes be added and tagged here?',
5505
+ when: 'When adding, titling or tagging a note.',
5506
+ // when its text last changed, and who would ask it: a system's own guide is asked by `system`
5507
+ lastModified: Date.parse('2026-11-28'),
5508
+ askedBy: 'system',
4855
5509
  // for the graph contextor: how much it counts, a short form for tight budgets, and what it relates to
4856
5510
  weight: 1.2,
4857
5511
  summary: 'Search before adding; short titles; lowercase tags.',
@@ -4895,6 +5549,10 @@ key: guide
4895
5549
  title: Notes guide
4896
5550
  description: Where to start with notes.
4897
5551
  summary: The index of the notes guide; pick the part you need.
5552
+ question: How do I keep and find notes?
5553
+ when: When the person wants to write down, change or look up a note.
5554
+ lastModified: 2026-11-28
5555
+ askedBy: system
4898
5556
  choices:
4899
5557
  - to: notes/guide.adding
4900
5558
  when: You are adding or editing a note.
@@ -4909,6 +5567,38 @@ with `HARNESS_CONTEXT_WATCH=true` (development) it watches the folder and sends
4909
5567
  item to one idea with a short summary, start with a shallow index whose `choices` are worded as decisions, and let a
4910
5568
  small model walk the graph a step at a time instead of reading one long list.
4911
5569
 
5570
+ ### How do I write a context item as one question?
5571
+
5572
+ The hub treats every context item as the answer to one question, and searches compare a request's meaning with each
5573
+ item's question (or with its content, when it has none). So the question is how an item is found, and how the hub
5574
+ tells that two items say the same thing. Give every item, in the contract or in a context file's header:
5575
+
5576
+ - `question`: the one question it answers, worded the way someone who needs it would ask, ending with its only `?`
5577
+ ("How do I keep a fn's results in a table?"). Not a title ("Tables"), and not two questions joined ("What is a
5578
+ table, and how do I add one?").
5579
+ - `when`: the situations it is for, written for a model that decides whether to read it ("When the person asks to
5580
+ change how a fn retries."). Start with "When", and name what the request would be about rather than the words it
5581
+ would use.
5582
+ - `lastModified`: when its text last changed, in ms since the epoch (`Date.parse('2026-11-28')`); a context file may
5583
+ write the date (`2026-11-28`) or an ISO time. Change it with the text. Without it the hub uses when it first saw
5584
+ this version of the item. Of two items that say the same thing, the older is the one marked as a possible duplicate.
5585
+ - `askedBy` (optional): who would ask it. `system` for how a piece of software or the harness works or is used (a
5586
+ system's guides are this), `person` for a person's own life, work or choices, `research` for a fact that could be
5587
+ looked up.
5588
+
5589
+ **One item per question.** When an item answers several questions (how to declare a thing, and how to test it, and
5590
+ what goes wrong), write one item for each, and keep them together with links: a short overview item whose `imports`
5591
+ name the others loads them all, each item's `fns` bring what its answer needs, and `parent`, `next` and `choices` let a
5592
+ model walk from one to the next. The hub's metadata model splits a hub item that answers several questions on its own
5593
+ (an admin can ask it to split a system's item too, which hides the original), so a system that writes one item per
5594
+ question keeps control of its own wording.
5595
+
5596
+ **What the hub does with them.** Every item has a status: `active` (in use), `hidden`, `pending_approval` (an admin
5597
+ chose to approve new context from systems first, in Admin › Context › Review), `pending_removal` (a new contract no
5598
+ longer declares it; it keeps working until an admin confirms the removal), `not_applicable` and `pending_plan` (the
5599
+ questions of plans `hub/ctx_plan` makes). A decision model compares a new or changed item with its nearest neighbours
5600
+ and flags possible duplicates and contradictions for Review.
5601
+
4912
5602
  ### Reference: context and commands
4913
5603
 
4914
5604
  #### `CONTEXT_FOLDER`
@@ -5138,10 +5828,22 @@ interface ContextInput<Args extends Record<string, ArgDef<boolean>>> {
5138
5828
  next?: AnyContextRef;
5139
5829
  /** Weighted links to other context, fns, types and resources. */
5140
5830
  links?: ContextLinkDef[];
5831
+ /**
5832
+ * The one question it answers, worded the way someone who needs it would ask ("How do I keep a fn's results in a
5833
+ * table?"). Searches compare a request's meaning with each item's question, so a good question is how an item is
5834
+ * found. Without one the hub searches its content instead. Write one item per question.
5835
+ */
5836
+ question?: string;
5837
+ /** When reading it is the right thing to do, for a model: "When the person asks to change how a fn retries." */
5838
+ when?: string;
5839
+ /** When its text last changed, in ms since the epoch (`Date.parse('2026-11-28')`); the hub uses when it first saw this version when absent. */
5840
+ lastModified?: number;
5841
+ /** Who would ask its question: `person` (their own choices), `system` (how software or the harness works: a system's guides) or `research` (a fact to look up). */
5842
+ askedBy?: ContextAskedBy;
5141
5843
  }
5142
5844
  ```
5143
5845
 
5144
- Refers to: [`Audience`](#core-audience).
5846
+ Refers to: [`Audience`](#core-audience), [`ContextAskedBy`](#core-contextaskedby).
5145
5847
 
5146
5848
  #### `ContextDef`
5147
5849
 
@@ -5176,12 +5878,20 @@ interface ContextDef<A, Dynamic extends boolean> {
5176
5878
  /** The next piece of a chain (a long text in ordered pieces). */
5177
5879
  readonly next: AnyContextRef | undefined;
5178
5880
  readonly links: readonly ContextLinkDef[];
5881
+ /** The one question it answers, as someone who needs it would ask; searches compare with it. */
5882
+ readonly question: string | undefined;
5883
+ /** When it is the right thing to read, for a model ("When the person asks to change how a fn retries."). */
5884
+ readonly when: string | undefined;
5885
+ /** When its text last changed (ms since the epoch); the hub uses when it first saw this version when absent. */
5886
+ readonly lastModified: number | undefined;
5887
+ /** Who would ask its question: `person`, `system` (a system's own guides) or `research`. */
5888
+ readonly askedBy: ContextAskedBy | undefined;
5179
5889
  /** Phantom: the command's args. Never set at runtime. */
5180
5890
  readonly argsType?: A;
5181
5891
  }
5182
5892
  ```
5183
5893
 
5184
- Refers to: [`Audience`](#core-audience).
5894
+ Refers to: [`Audience`](#core-audience), [`ContextAskedBy`](#core-contextaskedby).
5185
5895
 
5186
5896
  #### `AnyContextDef`
5187
5897
 
@@ -5198,7 +5908,7 @@ type · `import { ContextImpl } from '@harness/sdk'`
5198
5908
  A dynamic context's implementation: its content for these args.
5199
5909
 
5200
5910
  ```ts
5201
- type ContextImpl<A, Cfg = unknown, O extends Own = Own> = (args: A, ctx: SystemCtx<Cfg, O> & Partial<AskerCtx> & Pick<AskerCtx, 'user' | 'time'>) => Promise<string>;
5911
+ type ContextImpl<A, Cfg = unknown, O extends AnyOwn = Own> = (args: A, ctx: SystemCtx<Cfg, O> & Partial<AskerCtx> & Pick<AskerCtx, 'user' | 'time'>) => Promise<string>;
5202
5912
  ```
5203
5913
 
5204
5914
  #### `ContextLinkDef`
@@ -5356,7 +6066,7 @@ const agents: { readonly all: "*"; readonly of: <const S extends string>(system:
5356
6066
 
5357
6067
  Refers to: [`QualifiedName`](#core-qualifiedname).
5358
6068
 
5359
- ## 14. Hooks
6069
+ ## 15. Hooks
5360
6070
 
5361
6071
  A **hook** adds information to each user message before the LLM sees it (the git branch, the pinned notes, the open
5362
6072
  ticket). Declare it with `hook({ description, order?, timeout? })`: lower `order` runs first (default 100), and after
@@ -5435,7 +6145,7 @@ type · `import { HookImpl } from '@harness/sdk'`
5435
6145
  A hook's implementation.
5436
6146
 
5437
6147
  ```ts
5438
- type HookImpl<Cfg = unknown, O extends Own = Own> = (input: HookInput, ctx: SystemCtx<Cfg, O>) => Promise<HookContribution[]>;
6148
+ type HookImpl<Cfg = unknown, O extends AnyOwn = Own> = (input: HookInput, ctx: SystemCtx<Cfg, O>) => Promise<HookContribution[]>;
5439
6149
  ```
5440
6150
 
5441
6151
  Refers to: [`HookInput`](#core-hookinput).
@@ -5492,7 +6202,7 @@ type AnyHookRef = HookRef<QualifiedName>;
5492
6202
 
5493
6203
  Refers to: [`QualifiedName`](#core-qualifiedname).
5494
6204
 
5495
- ## 15. Mentions
6205
+ ## 16. Mentions
5496
6206
 
5497
6207
  A **mention provider** lets people point at things the system knows with `@` in the chat (a file, a database row, a
5498
6208
  note). Declare it with `mention({ title, description, target, of? })`: `target` is the gin type of the key that gets
@@ -5588,7 +6298,7 @@ interface · `import { MentionImpl } from '@harness/sdk'`
5588
6298
  A mention provider's implementation.
5589
6299
 
5590
6300
  ```ts
5591
- interface MentionImpl<T, V, Cfg = unknown, O extends Own = Own> {
6301
+ interface MentionImpl<T, V, Cfg = unknown, O extends AnyOwn = Own> {
5592
6302
  /** Results for what the person typed after `@`. */
5593
6303
  search(query: string, ctx: MentionCtx<Cfg, O>): Promise<MentionOption<T>[]>;
5594
6304
  /** The hover card, asked for when hovered so it is current; `undefined` when the thing no longer exists. */
@@ -5624,7 +6334,7 @@ interface · `import { MentionCtx } from '@harness/sdk'`
5624
6334
  What a mention provider's implementation gets: the person mentioning, so results are limited to what they may see.
5625
6335
 
5626
6336
  ```ts
5627
- interface MentionCtx<Cfg = unknown, O extends Own = Own> extends SystemCtx<Cfg, O>, AskerCtx {}
6337
+ interface MentionCtx<Cfg = unknown, O extends AnyOwn = Own> extends SystemCtx<Cfg, O>, AskerCtx {}
5628
6338
  ```
5629
6339
 
5630
6340
  #### `MentionRef`
@@ -5643,7 +6353,7 @@ interface MentionRef<N extends QualifiedName, T> {
5643
6353
 
5644
6354
  Refers to: [`QualifiedName`](#core-qualifiedname).
5645
6355
 
5646
- ## 16. Actions
6356
+ ## 17. Actions
5647
6357
 
5648
6358
  An **action** is a typed message the system's renderers send it ("pin", "approve", "load more"). Declare it with
5649
6359
  `action({ description, input, returns?, state?, expires? })`: without `returns` it returns nothing, `state` declares
@@ -5721,7 +6431,7 @@ type · `import { ActionImpl } from '@harness/sdk'`
5721
6431
  An action's implementation.
5722
6432
 
5723
6433
  ```ts
5724
- type ActionImpl<I, R, St extends object, Cfg = unknown, O extends Own = Own> = (input: I, ctx: ActionCtx<St, Cfg, O>) => Promise<R>;
6434
+ type ActionImpl<I, R, St extends object, Cfg = unknown, O extends AnyOwn = Own> = (input: I, ctx: ActionCtx<St, Cfg, O>) => Promise<R>;
5725
6435
  ```
5726
6436
 
5727
6437
  #### `ActionCtx`
@@ -5731,7 +6441,7 @@ interface · `import { ActionCtx } from '@harness/sdk'`
5731
6441
  What an action's implementation gets.
5732
6442
 
5733
6443
  ```ts
5734
- interface ActionCtx<St extends object, Cfg = unknown, O extends Own = Own> extends SystemCtx<Cfg, O>, AskerCtx, Omit<Services, 'log' | 'llm' | 'resources' | 'types'> {
6444
+ interface ActionCtx<St extends object, Cfg = unknown, O extends AnyOwn = Own> extends SystemCtx<Cfg, O>, AskerCtx, Omit<Services, 'log' | 'llm' | 'resources' | 'types'> {
5735
6445
  readonly delivery: DeliveryId;
5736
6446
  /** The run whose renderer sent it, if any. */
5737
6447
  readonly run: RunId | undefined;
@@ -5759,7 +6469,7 @@ interface ActionRef<N extends QualifiedName, I, R> {
5759
6469
 
5760
6470
  Refers to: [`QualifiedName`](#core-qualifiedname).
5761
6471
 
5762
- ## 17. Model providers
6472
+ ## 18. Model providers
5763
6473
 
5764
6474
  A system can bring **model providers**: models whose calls run in the system (a GPU box, a private API, a gateway the
5765
6475
  hub can't reach). Declare each in the contract with `provider({ description, models })`: every model's id, abilities
@@ -5862,7 +6572,7 @@ The implementation of a declared provider: make the aeye `Provider` for the curr
5862
6572
  the config changes, and kept otherwise.
5863
6573
 
5864
6574
  ```ts
5865
- type ProviderImpl<Cfg = unknown, O extends Own = Own> = (ctx: SystemCtx<Cfg, O>) => Provider;
6575
+ type ProviderImpl<Cfg = unknown, O extends AnyOwn = Own> = (ctx: SystemCtx<Cfg, O>) => Provider;
5866
6576
  ```
5867
6577
 
5868
6578
  #### `ProviderRef`
@@ -5880,7 +6590,7 @@ interface ProviderRef<N extends QualifiedName> {
5880
6590
 
5881
6591
  Refers to: [`QualifiedName`](#core-qualifiedname).
5882
6592
 
5883
- ## 18. Resources, embedders and sectioners
6593
+ ## 19. Resources, embedders and sectioners
5884
6594
 
5885
6595
  ### Resources
5886
6596
 
@@ -6038,7 +6748,7 @@ function sectionKeys(paths: readonly (readonly string[])[]): SectionKey[];
6038
6748
 
6039
6749
  Refers to: [`SectionKey`](#core-sectionkey).
6040
6750
 
6041
- ## 19. The hub contract
6751
+ ## 20. The hub contract
6042
6752
 
6043
6753
  The hub is a system too, named `hub`, declared with the same SDK as the contract `hub` (`import { hub } from
6044
6754
  '@harness/sdk'`). Systems use it like any other contract: depend on its fns (`deps: { ask: hub.fns.ask_user }`), give
@@ -6073,7 +6783,7 @@ This is the hub contract as the SDK declares it now:
6073
6783
  - `hub/ctx_search`: Search context (guides, memories, pieces of files) by words or meaning, a page at a time. Tags: `read`.
6074
6784
 
6075
6785
  ```text
6076
- (obj{ text?, systems?, origins?, scopes?, tags?, names?, niches?, order?, offset?, limit? … }) => obj{ items, next?, filtered?, loaded?, missing? … }
6786
+ (obj{ text?, systems?, origins?, scopes?, tags?, names?, niches?, returnNotApplicable?, semanticOver?, order?, offset?, limit? … }) => obj{ items, next?, filtered?, loaded?, missing? … }
6077
6787
  ```
6078
6788
  - `hub/fns_examples`: A page of one fn's example calls (its args, the result when kept, and what each shows), the closest to what you are about to do first. Tags: `read`.
6079
6789
 
@@ -6137,6 +6847,29 @@ This is the hub contract as the SDK declares it now:
6137
6847
  metadataOnly?: bool
6138
6848
  }) => obj{ loaded, fns, fnsRefused, refused, cards, crawled, skipped, stop, depth, decisions, tokens, calls, metadataOnly … }
6139
6849
  ```
6850
+ - `hub/ctx_plan`: Turn a request into a decision tree of the questions that must be answered before it can be planned: each question with its options, and the questions each option raises if it is chosen. The person answers it on the plan's card. Tags: `read`.
6851
+
6852
+ ```text
6853
+ (obj{ description, limits? … }) => obj{ description, limits, stop, cost, time, startedAt, updatedAt, roots, questions, counts, revision … }
6854
+ ```
6855
+ - `hub/ctx_plan_get`: A plan made by hub/ctx_plan as it is now (its questions, options, answers and what is ruled out), or the same as markdown. Tags: `read`.
6856
+
6857
+ ```text
6858
+ (obj{
6859
+ /* The run of hub/ctx_plan that made the plan (its id, such as run_01HZX3). */ run: text,
6860
+ /* `plan` (the default): the plan itself; `markdown`: the questions, answers and what was ruled out, as markdown to read or share. */ format?: enum<text>{plan, markdown}
6861
+ }) => obj{ run, plan, markdown? … }
6862
+ ```
6863
+ - `hub/ctx_answer`: Answer questions of a plan made by hub/ctx_plan: pick one or more options of each, with the person's own words. Questions under options not picked are ruled out, each with the reason.
6864
+
6865
+ ```text
6866
+ (obj{ run, answers?, reasons? … }) => obj{ run, plan, changed, deeper, skipped … }
6867
+ ```
6868
+ - `hub/ctx_plan_expand`: Plan deeper: go on with a plan made by hub/ctx_plan under one of its questions (or the whole plan) with limits of its own, or write the options under a question again after its answer changed. Tags: `read`.
6869
+
6870
+ ```text
6871
+ (obj{ run, under?, replan?, limits? … }) => obj{ run, plan, markdown? … }
6872
+ ```
6140
6873
  - `hub/search_resources`: Search files and other resources by meaning and words. Tags: `read`.
6141
6874
 
6142
6875
  ```text
@@ -6318,7 +7051,7 @@ This is the hub contract as the SDK declares it now:
6318
7051
  - `hub/run_get`: One run: its fn, args, status, result or error, cost and timings. Tags: `read`.
6319
7052
 
6320
7053
  ```text
6321
- (obj{/* run id */ run: text}) => obj{ id, fn, fnVersion, kind, system, instance?, parent?, root, turn, session?, key, actor, caller, connection?, llmCall?, toolCallId?, args, repairs?, test?, status, text?, outcome?, progress?, allowed, cost, totalCost, priority, background, attempt, errors, undo?, resume?, stateChanges, tokens?, createdAt, approvedAt?, startedAt?, endedAt? … }
7054
+ (obj{/* run id */ run: text}) => obj{ id, fn, fnVersion, kind, system, instance?, parent?, root, turn, session?, key, actor, caller, connection?, llmCall?, toolCallId?, args, repairs?, test?, status, awaitingSystem?, text?, outcome?, progress?, allowed, cost, totalCost, priority, background, attempt, errors, undo?, resume?, stateChanges, tokens?, createdAt, approvedAt?, startedAt?, endedAt?, resultRevision?, resultUpdatedAt?, resultUpdatedBy? … }
6322
7055
  ```
6323
7056
  - `hub/run_tree`: The tree of runs a turn made: each run with the runs it called. Tags: `read`.
6324
7057
 
@@ -6373,12 +7106,12 @@ This is the hub contract as the SDK declares it now:
6373
7106
  - `hub/systems_list`: Every system: whether it is connected, its version, instances and what it offers. Tags: `read`.
6374
7107
 
6375
7108
  ```text
6376
- (obj{ query? … }) => list<obj{ name, description, about?, status, enabled, version, manifestHash, defaultInstance?, actor, stage?, keyFingerprint, config?, installed?, host?, pairedAt?, pairedBy?, lastSeenAt?, address?, counts, instanceMode, needsConfig, configType?, configSecrets?, instances … }>
7109
+ (obj{ query? … }) => list<obj{ name, description, about?, status, enabled, version, manifestHash, defaultInstance?, actor, stage?, keyFingerprint, config?, installed?, host?, pairedAt?, pairedBy?, lastSeenAt?, address?, counts, instanceMode, needsConfig, configType?, configSecrets?, store?, instances … }>
6377
7110
  ```
6378
7111
  - `hub/system_get`: One system: its status, version, instances, config state and what it offers. Tags: `read`.
6379
7112
 
6380
7113
  ```text
6381
- (obj{system: text}) => obj{ name, description, about?, status, enabled, version, manifestHash, defaultInstance?, actor, stage?, keyFingerprint, config?, installed?, host?, pairedAt?, pairedBy?, lastSeenAt?, address?, counts, instanceMode, needsConfig, configType?, configSecrets?, instances … }
7114
+ (obj{system: text}) => obj{ name, description, about?, status, enabled, version, manifestHash, defaultInstance?, actor, stage?, keyFingerprint, config?, installed?, host?, pairedAt?, pairedBy?, lastSeenAt?, address?, counts, instanceMode, needsConfig, configType?, configSecrets?, store?, instances … }
6382
7115
  ```
6383
7116
  - `hub/system_fns`: A system's fns, with whether each can be used now and its running numbers. Tags: `read`.
6384
7117
 
@@ -6400,7 +7133,7 @@ This is the hub contract as the SDK declares it now:
6400
7133
  - `hub/model_roles`: Which model (and provider) the hub uses for each job: chat, transcription, dictation, speech, describing images, reading text in them. Tags: `read`.
6401
7134
 
6402
7135
  ```text
6403
- (obj) => list<obj{ role, choice?, from, resolved? … }>
7136
+ (obj) => list<obj{ role, choice?, from, resolved?, fallback? … }>
6404
7137
  ```
6405
7138
  - `hub/model_limits`: Each model's context window, output limit, reasoning reserve and characters per token, with where each came from. Tags: `read`.
6406
7139
 
@@ -6478,9 +7211,9 @@ This is the hub contract as the SDK declares it now:
6478
7211
  - `hub/remember`: Keep a fact for later as a memory (a context item): for this chat, for the person in all their chats, or for everyone.
6479
7212
 
6480
7213
  ```text
6481
- (obj{ text, title?, scope?, about?, weight?, summary?, tags?, fns?, suggestFns?, command?, visible?, suggest?, parent? … }) => obj{name: text}
7214
+ (obj{ text, title?, scope?, about?, question?, when?, weight?, summary?, tags?, fns?, suggestFns?, command?, visible?, suggest?, parent? … }) => obj{name: text}
6482
7215
  ```
6483
- - `hub/forget`: Forget a memory.
7216
+ - `hub/forget`: Forget a memory: it is hidden, so no search or agent finds it any more (an admin, or the person who wrote it, can restore it).
6484
7217
 
6485
7218
  ```text
6486
7219
  (obj{name: text}) => obj{ok: bool}
@@ -6517,7 +7250,7 @@ This is the hub contract as the SDK declares it now:
6517
7250
  - `hub/memory_update`: Change a memory: its text, title, weight, tags, the fns it brings or where it applies.
6518
7251
 
6519
7252
  ```text
6520
- (obj{ text?, title?, about?, weight?, summary?, tags?, fns?, suggestFns?, command?, visible?, suggest?, parent?, name, clear? … }) => obj{name: text}
7253
+ (obj{ text?, title?, about?, question?, when?, weight?, summary?, tags?, fns?, suggestFns?, command?, visible?, suggest?, parent?, name, clear? … }) => obj{name: text}
6521
7254
  ```
6522
7255
  - `hub/ctx_link`: Link a context item to another item (context, fn, type or resource), with a relation and weight.
6523
7256
 
@@ -6880,15 +7613,7 @@ This is the hub contract as the SDK declares it now:
6880
7613
  - `hub/approve_pairing`: Approve or refuse a system that asked to pair with the hub, optionally naming its instance and setting its config. Tags: `admin`.
6881
7614
 
6882
7615
  ```text
6883
- (obj{
6884
- /* pairing id */ pairing: text,
6885
- approve: bool,
6886
- instance?: text,
6887
- config?: any,
6888
- autoPair?: obj{
6889
- expiresIn?: nullable<num{whole=true, min=0}>
6890
- }
6891
- }) => obj{system?: text}
7616
+ (obj{ pairing, approve, instance?, config?, autoPair?, store? … }) => obj{system?: text}
6892
7617
  ```
6893
7618
  - `hub/create_pairing_token`: Make a one-time pairing token a new system can pair with, optionally for one system name. Tags: `admin`.
6894
7619
 
@@ -6922,19 +7647,15 @@ This is the hub contract as the SDK declares it now:
6922
7647
  on: bool
6923
7648
  }) => obj{on: bool}
6924
7649
  ```
6925
- - `hub/remove_system`: Remove a system; its fns become unavailable until it pairs again. Tags: `admin`.
7650
+ - `hub/remove_system`: Remove a system; its fns become unavailable until it pairs again. Its own store is kept unless `keepStore` is false. Tags: `admin`.
6926
7651
 
6927
7652
  ```text
6928
- (obj{system: text}) => obj{fnsUnavailable: num{whole=true}}
7653
+ (obj{system: text, keepStore?: bool}) => obj{fnsUnavailable: num{whole=true}}
6929
7654
  ```
6930
7655
  - `hub/install_system`: Install a system from a folder, a package or a git repository, and start it. Tags: `admin`.
6931
7656
 
6932
7657
  ```text
6933
- (obj{
6934
- source: or<obj{path: text}, obj{package: text, version: text}, obj{git: text, ref: text}, obj{zip: text, file: text}>,
6935
- config?: any,
6936
- autoStart?: bool
6937
- }) => obj{name: text}
7658
+ (obj{ source, config?, autoStart?, store? … }) => obj{name: text}
6938
7659
  ```
6939
7660
  - `hub/start_system`: Start an installed system. Tags: `admin`.
6940
7661
 
@@ -6963,14 +7684,14 @@ This is the hub contract as the SDK declares it now:
6963
7684
  - `hub/set_model_role`: Choose the model (and provider) for a job: chat, transcription, dictation (or the browser's own), speech, describing images, reading text in them. Tags: `admin`.
6964
7685
 
6965
7686
  ```text
6966
- (obj{ role, engine?, language?, model?, provider?, threshold? … }) => obj{ role, choice?, from, resolved? … }
7687
+ (obj{ role, engine?, language?, model?, provider?, threshold? … }) => obj{ role, choice?, from, resolved?, fallback? … }
6967
7688
  ```
6968
7689
  - `hub/clear_model_role`: Clear a job's model choice, so it falls back to the hub's default (or is off). Tags: `admin`.
6969
7690
 
6970
7691
  ```text
6971
7692
  (obj{
6972
- role: enum<text>{chat, transcribe, dictate, speak, describe, ocr, decide}
6973
- }) => obj{ role, choice?, from, resolved? … }
7693
+ role: enum<text>{chat, transcribe, dictate, speak, describe, ocr, decide, metadata, plan}
7694
+ }) => obj{ role, choice?, from, resolved?, fallback? … }
6974
7695
  ```
6975
7696
  - `hub/set_model_limits`: Set a model's context window, output limit, reasoning reserve or characters per token; with every field absent, clear them. Tags: `admin`.
6976
7697
 
@@ -7021,23 +7742,17 @@ This is the hub contract as the SDK declares it now:
7021
7742
  - `hub/install_package`: Install a system package zip (made by `harness system pack`), pair it, configure it and start it. Tags: `admin`.
7022
7743
 
7023
7744
  ```text
7024
- (obj{
7025
- zip: obj{hash: text, size: num{whole=true, min=0}, mime: text},
7026
- instance?: text,
7027
- config?: any,
7028
- data?: obj{hash: text, size: num{whole=true, min=0}, mime: text},
7029
- autoStart?: bool
7030
- }) => obj{system: text, instance: text}
7745
+ (obj{ zip, instance?, config?, data?, autoStart?, store? … }) => obj{system: text, instance: text}
7031
7746
  ```
7032
7747
  - `hub/add_instance`: Add an instance of a bundled fleet system (an MCP server, an API service) with its config: installed, paired and started on the hub machine. Tags: `admin`.
7033
7748
 
7034
7749
  ```text
7035
- (obj{system: text, instance: text, description?: text, config: any}) => obj{system: text, instance: text}
7750
+ (obj{ system, instance, description?, config, store? … }) => obj{system: text, instance: text}
7036
7751
  ```
7037
- - `hub/remove_instance`: Remove one instance of a system. Tags: `admin`.
7752
+ - `hub/remove_instance`: Remove one instance of a system. Its own store is kept unless `keepStore` is false. Tags: `admin`.
7038
7753
 
7039
7754
  ```text
7040
- (obj{system: text, instance: text}) => obj{ok: bool}
7755
+ (obj{system: text, instance: text, keepStore?: bool}) => obj{ok: bool}
7041
7756
  ```
7042
7757
  - `hub/suggest_decision_set`: Choose who picks what each message is offered: none (no model: the best by similarity over the threshold), a decision model (one yes/no question per candidate, the decide role's threshold), or an LLM; how many candidates it sees and picks; and a model's action: suggest (cards the chat model may load, the default) or load (what it picks is loaded for the turn: fns join the tools, context is brought into the message). Tags: `admin`.
7043
7758
 
@@ -7079,6 +7794,81 @@ This is the hub contract as the SDK declares it now:
7079
7794
  order?: nullable<num{whole=true, min=0, max=1000}>
7080
7795
  }) => obj{ agent, context, source, system, via, title, detail, text, tokens, order, on, leftOut?, switched? … }
7081
7796
  ```
7797
+ - `hub/ctx_status`: Change the status of up to 200 context items at once, with a reason kept in each item's history: approve (an item waiting for approval goes into use), hide (switch an item off), restore (a hidden, ruled-out or pending-removal item goes back into use; for pending removal this rejects the removal) or confirm_removal (an item waiting for removal is removed for good, with its links). Tags: `admin`.
7798
+
7799
+ ```text
7800
+ (obj{
7801
+ names: list<text>,
7802
+ action: enum<text>{approve, hide, restore, confirm_removal},
7803
+ reason?: text{minLength=1, maxLength=500}
7804
+ }) => obj{
7805
+ changed: list<obj{
7806
+ name: text,
7807
+ status: or<enum<text>{active, hidden, not_applicable, pending_approval, pending_removal, pending_plan}, literal<text>{value="removed"}>
7808
+ }>,
7809
+ skipped: list<obj{name: text, reason: text}>
7810
+ }
7811
+ ```
7812
+ - `hub/ctx_merge`: Merge two context items that say the same thing: keep one, point the links that people drew to the other and the mentions of it at the kept one, move its own drawn links to the kept one, and hide the other (it can be restored with hub/ctx_status). Tags: `admin`.
7813
+
7814
+ ```text
7815
+ (obj{
7816
+ keep: text,
7817
+ drop: text,
7818
+ reason?: text{minLength=1, maxLength=500}
7819
+ }) => obj{
7820
+ kept: text,
7821
+ hidden: text,
7822
+ links: num{whole=true, min=0},
7823
+ mentions: num{whole=true, min=0}
7824
+ }
7825
+ ```
7826
+ - `hub/ctx_not_duplicate`: Tell the hub that two context items flagged as possible duplicates are different: the flag is cleared and the pair is remembered, so the check never flags them again. Tags: `admin`.
7827
+
7828
+ ```text
7829
+ (obj{name: text, of: text}) => obj{ok: bool}
7830
+ ```
7831
+ - `hub/ctx_reextract`: Fill the metadata of up to 20 context items again now with the metadata model: the question each answers, when it is worth reading, who would ask it, and when its answer should be checked again; an item that answers several separate questions is split into one item per question (the original is hidden so its text doesn't show twice). Each item is then checked again for duplicates and contradictions when a decision model is set. Tags: `admin`.
7832
+
7833
+ ```text
7834
+ (obj{names: list<text>}) => obj{
7835
+ done: list<obj{
7836
+ name: text,
7837
+ fields: list<enum<text>{question, when, askedBy, validUntil}>,
7838
+ split?: list<text>
7839
+ }>,
7840
+ failed: list<obj{name: text, reason: text}>
7841
+ }
7842
+ ```
7843
+ - `hub/ctx_new_status_set`: Choose what new context from systems and from documents starts as: active (in use at once, the default), pending_approval (each new item waits in Review until an admin approves it) or hidden (off until an admin restores it). Items that exist keep their status; memories are always in use at once. Tags: `admin`.
7844
+
7845
+ ```text
7846
+ (obj{
7847
+ value: enum<text>{active, pending_approval, hidden}
7848
+ }) => obj{
7849
+ value: enum<text>{active, pending_approval, hidden},
7850
+ setBy?: text,
7851
+ updatedAt?: num{whole=true}
7852
+ }
7853
+ ```
7854
+ - `hub/system_store_move`: Move a system's own store to another place: on the hub, with the system, or an external Postgres or SQL Server database (its connection kept encrypted). Calls to the system wait while it moves, and the old copy is kept as a backup. Tags: `admin`.
7855
+
7856
+ ```text
7857
+ (obj{ system, instance?, to, runs? … }) => obj{ move, system, instance, from, to, phase, runs, running, asking?, progress, startedAt, endedAt?, by, backups, error? … }
7858
+ ```
7859
+ - `hub/system_store_move_answer`: Answer a store move that waits on runs still going: cancel them, or keep waiting until they finish. Tags: `admin`.
7860
+
7861
+ ```text
7862
+ (obj{system: text, instance?: text, answer: enum<text>{cancel, wait}}) => obj{ move, system, instance, from, to, phase, runs, running, asking?, progress, startedAt, endedAt?, by, backups, error? … }
7863
+ ```
7864
+ - `hub/system_store_backup_delete`: Delete one backup of a system's store: an old copy a move left, or a store kept when its instance was removed. Tags: `admin`.
7865
+
7866
+ ```text
7867
+ (obj{system: text, instance?: text, backup: text}) => obj{
7868
+ deleted: literal<bool>{value=true},
7869
+ note?: text
7870
+ }
7871
+ ```
7082
7872
  - `hub/budgets_list`: Every budget rule with what it has spent so far. Tags: `admin`, `read`.
7083
7873
 
7084
7874
  ```text
@@ -7179,7 +7969,7 @@ This is the hub contract as the SDK declares it now:
7179
7969
  ```text
7180
7970
  (obj{
7181
7971
  status?: enum<text>{pending, approved, rejected, expired}
7182
- }) => list<obj{ id, name, keyFingerprint, publicKey, version, address, method, code?, replaces?, description?, instance?, configType?, configSecrets?, status, createdAt, expiresAt … }>
7972
+ }) => list<obj{ id, name, keyFingerprint, publicKey, version, address, method, code?, replaces?, description?, instance?, configType?, configSecrets?, store?, status, createdAt, expiresAt … }>
7183
7973
  ```
7184
7974
  - `hub/auto_pairs_list`: The auto-pair secrets granted, optionally for one system. Tags: `admin`, `read`.
7185
7975
 
@@ -7199,7 +7989,7 @@ This is the hub contract as the SDK declares it now:
7199
7989
  - `hub/instances_list`: One system's instances, with their status, version, config (secrets masked) and host. Tags: `admin`, `read`.
7200
7990
 
7201
7991
  ```text
7202
- (obj{system: text}) => list<obj{ system, instance, description, status, keyFingerprint, version, manifestHash, config?, installed?, host?, dirs?, pairedAt?, pairedBy?, lastSeenAt?, address?, connect? … }>
7992
+ (obj{system: text}) => list<obj{ system, instance, description, status, keyFingerprint, version, manifestHash, config?, installed?, host?, dirs?, pairedAt?, pairedBy?, lastSeenAt?, address?, connect?, store? … }>
7203
7993
  ```
7204
7994
  - `hub/suggest_decision_get`: The suggestions setting: who picks what each message is offered (a decision model, an LLM, or none: the best by similarity over the threshold), and its limits. Tags: `admin`, `read`.
7205
7995
 
@@ -7221,6 +8011,40 @@ This is the hub contract as the SDK declares it now:
7221
8011
  fnMode?: enum<text>{none, read, write, delete, auto}
7222
8012
  }) => obj{ injections, targets … }
7223
8013
  ```
8014
+ - `hub/ctx_review`: The context Review queue: items that may say the same as another item (possible duplicates), items whose answers disagree with another item (contradictions), new items waiting for an admin's approval, and items whose system or document dropped them, waiting for an admin to confirm their removal. Each entry has the item (name, title, question, status and why, when it last changed, the start of its text), and for a duplicate or a contradiction the other item and the reason the decision model gave; the page also counts each kind. Tags: `admin`, `read`.
8015
+
8016
+ ```text
8017
+ (obj{
8018
+ kinds?: list<enum<text>{duplicate, contradiction, pending_approval, pending_removal}>,
8019
+ systems?: list<text{minLength=1}>,
8020
+ limit?: num{whole=true, min=1, max=200},
8021
+ cursor?: text
8022
+ }) => obj{ items, next?, counts … }
8023
+ ```
8024
+ - `hub/ctx_new_status_get`: What new context from systems and from documents starts as: active (in use at once, the default), pending approval (an admin approves each item first) or hidden. Memories are always in use at once. Tags: `admin`, `read`.
8025
+
8026
+ ```text
8027
+ (obj) => obj{
8028
+ value: enum<text>{active, pending_approval, hidden},
8029
+ setBy?: text,
8030
+ updatedAt?: num{whole=true}
8031
+ }
8032
+ ```
8033
+ - `hub/system_store`: A system's own store (its private database, for systems whose contract declares one): what it holds, where it lives (on the hub, with the system, or an external Postgres or SQL Server database), its state and migrations, its size, its backups and its current or last move. Tags: `admin`, `read`.
8034
+
8035
+ ```text
8036
+ (obj{system: text, instance?: text}) => obj{ system, instance, decl, placement, status?, holding, measure?, file?, backups?, move? … }
8037
+ ```
8038
+ - `hub/system_store_move_state`: How a system store's move stands: its phase (draining, waiting on runs, copying, switching, done or failed), the runs still going, tables and bytes copied so far, and why it failed. Tags: `admin`, `read`.
8039
+
8040
+ ```text
8041
+ (obj{system: text, instance?: text}) => obj{ move? … }
8042
+ ```
8043
+ - `hub/system_store_backups`: A system store's backups, newest first: old copies moves left behind, and stores kept when their instance was removed (orphaned). Tags: `admin`, `read`.
8044
+
8045
+ ```text
8046
+ (obj{system: text, instance?: text}) => list<obj{ id, system, instance, where, bytes?, at, reason, orphaned? … }>
8047
+ ```
7224
8048
 
7225
8049
  #### Kinds of `hub`
7226
8050
 
@@ -7304,6 +8128,29 @@ This is the hub contract as the SDK declares it now:
7304
8128
  - `hub/paragraphs`: One section per paragraph. Matches: `{"format":"text"}`.
7305
8129
  - `hub/tables`: One section per table (large tables in row groups, the header repeated). Matches: `{"form":"table"}`.
7306
8130
 
8131
+ ### Which hub fns work with context questions, statuses and plans?
8132
+
8133
+ Every context item is the answer to one question, with a status (**Context and commands**). These hub fns work with
8134
+ that; give them to an agent (`tools: [hub.fns.ctx_plan]`) or depend on them like any other hub fn:
8135
+
8136
+ - **Finding:** `hub/ctx_search` compares a request with each item's question (`semanticOver: 'content'` compares with
8137
+ the text instead), returns items in use (`active` and `pending_removal`), and with `returnNotApplicable: true` also
8138
+ the questions a plan ruled out. A hit carries its question and, for an answered question, its answer in short.
8139
+ `hub/ctx_load` and `hub/ctx_crawl` load what was found.
8140
+ - **Planning:** `hub/ctx_plan` turns a request (`description`, with optional `limits`: `openQuestions` 60, `depth` 6,
8141
+ `minutes` 10, `cost` 2 dollars by default) into a decision tree: the questions that must be answered before the work
8142
+ can be planned, each with options, and the questions each option raises. Every question is a context item (named
8143
+ like `hub/plan.q-1a2b3c4d`), shared between plans. The person answers on the plan's card; `hub/ctx_plan_get` reads
8144
+ the plan as it is now (or as markdown), `hub/ctx_answer` picks options for the person when they answer in the chat
8145
+ (questions under options not picked become `not_applicable`, each with why), and `hub/ctx_plan_expand` plans deeper
8146
+ under one question or writes its options again after its answer changed. Planning needs the plan and decision models.
8147
+ - **Review (admins):** `hub/ctx_review` lists possible duplicates, contradictions, items waiting for approval and items
8148
+ waiting for their removal to be confirmed; `hub/ctx_status` approves, hides, restores or confirms the removal of up
8149
+ to 200 items; `hub/ctx_merge` keeps one of two duplicates and hides the other; `hub/ctx_not_duplicate` clears a
8150
+ wrong flag for good; `hub/ctx_reextract` fills an item's question and `when` again with the metadata model (splitting
8151
+ it when it answers several questions); `hub/ctx_new_status_get` and `hub/ctx_new_status_set` read and choose what new
8152
+ context from systems and documents starts as.
8153
+
7307
8154
  ### Reference: the hub contract
7308
8155
 
7309
8156
  #### `hub`
@@ -7561,6 +8408,11 @@ const ADMIN_READ_ENDPOINTS = {
7561
8408
  suggest_decision_get: suggestionsSlice.endpoints.suggestDecision,
7562
8409
  search_decision_get: suggestionsSlice.endpoints.searchDecisions,
7563
8410
  ctx_injections_list: injectionsSlice.endpoints.injections,
8411
+ ctx_review: contextReviewSlice.endpoints.contextReview,
8412
+ ctx_new_status_get: contextReviewSlice.endpoints.newContextStatus,
8413
+ system_store: systemsSlice.endpoints.systemStore,
8414
+ system_store_move_state: systemsSlice.endpoints.systemStoreMoveState,
8415
+ system_store_backups: systemsSlice.endpoints.systemStoreBackups,
7564
8416
  } as const satisfies Record<string, EndpointLike>;
7565
8417
  ```
7566
8418
 
@@ -7769,7 +8621,7 @@ it left them; the undo payload is how they were before).
7769
8621
  const AllowedRuns: ObjType<{ fn: `${string}/${string}`; allowed: boolean; }>;
7770
8622
  ```
7771
8623
 
7772
- ## 20. The server: serve and the implementation
8624
+ ## 21. The server: serve and the implementation
7773
8625
 
7774
8626
  `serve(contract, impl, options, host?)` (from `@harness/sdk/server`) connects to the hub, pairs the first time, sends the
7775
8627
  manifest (or nothing when the hub already has this version of it), and serves the implementation over the link. It
@@ -7882,7 +8734,7 @@ against the contract and this process's instance here (a mismatch throws `Packag
7882
8734
  connects). A static fn with no example is refused too (`MissingExamplesError`, from the host), so every fn has one.
7883
8735
 
7884
8736
  ```ts
7885
- function serve<N extends string, C extends ContractShape>(contract: SystemContract<N, C>, impl: SystemImpl<C>, options: ServeOptions, host?: SystemHost): Promise<RunningSystem<N>>;
8737
+ function serve<N extends string, C extends ContractShape, Db extends StoreDb = StoreDb>(contract: SystemContract<N, C>, impl: SystemImpl<C, Db>, options: ServeOptions, host?: SystemHost): Promise<RunningSystem<N>>;
7886
8738
  ```
7887
8739
 
7888
8740
  #### `ServeOptions`
@@ -7927,6 +8779,12 @@ interface ServeOptions {
7927
8779
  * with `HARNESS_CONTEXT_WATCH` its changes go to the hub live.
7928
8780
  */
7929
8781
  context?: string | false;
8782
+ /**
8783
+ * For a contract that declares a store (`store()`): its migrations, in order (`[migration('001-notes', ...)]`). The
8784
+ * store opens where the hub says, its pending migrations run, and only then does the system take calls and run
8785
+ * `started`. Required with a store, refused without one.
8786
+ */
8787
+ store?: StoreServeOptions;
7930
8788
  }
7931
8789
  ```
7932
8790
 
@@ -8013,7 +8871,7 @@ const, type · `import { RunningStatus } from '@harness/sdk/server'`
8013
8871
  Where a running system is (`RunningSystem.status`).
8014
8872
 
8015
8873
  ```ts
8016
- type RunningStatus = "pairing" | "needs-config" | "connected" | "disconnected" | "stopped" | "connecting";
8874
+ type RunningStatus = "pairing" | "stopped" | "needs-config" | "connected" | "disconnected" | "connecting";
8017
8875
  ```
8018
8876
 
8019
8877
  #### `SystemImpl`
@@ -8022,26 +8880,26 @@ type · `import { SystemImpl } from '@harness/sdk'`
8022
8880
 
8023
8881
  A system's implementation, computed from its contract. It must implement exactly what the contract declares: every
8024
8882
  native fn, every method of its types, every kind, every dynamic context, hook, mention provider,
8025
- sectioner, action and model provider.
8883
+ sectioner, action and model provider. `Db` is its store's tables, for a contract that declares a store (`ctx.store`).
8026
8884
 
8027
8885
  ```ts
8028
- type SystemImpl<C extends ContractShape> =
8029
- Needs<'fns', { readonly [K in NativeFnKeys<C['fns']>]: FnImpl<TypesOf<C['fns'][K]>, ConfigOf<C>, OwnOf<C>> }> &
8030
- Needs<'kinds', { readonly [K in keyof C['kinds']]: C['kinds'][K] extends KindDef<infer P> ? KindImpl<P, ConfigOf<C>, OwnOf<C>> : never }> &
8031
- Needs<'context', { readonly [K in DynamicContextKeys<C['context']>]: C['context'][K] extends ContextDef<infer A, true> ? ContextImpl<A, ConfigOf<C>, OwnOf<C>> : never }> &
8032
- Needs<'hooks', { readonly [K in keyof C['hooks']]: HookImpl<ConfigOf<C>, OwnOf<C>> }> &
8033
- Needs<'mentions', { readonly [K in keyof C['mentions']]: C['mentions'][K] extends MentionDef<infer T, infer V> ? MentionImpl<T, V, ConfigOf<C>, OwnOf<C>> : never }> &
8034
- Needs<'types', { readonly [K in TypesWithMethods<C['types']>]: C['types'][K] extends TypeDef<infer V, infer M extends Methods> ? { readonly [J in keyof M]: MethodImpl<V, TypesOf<M[J]>, ConfigOf<C>, OwnOf<C>> } : never }> &
8886
+ type SystemImpl<C extends ContractShape, Db extends StoreDb = StoreDb> =
8887
+ Needs<'fns', { readonly [K in NativeFnKeys<C['fns']>]: FnImpl<TypesOf<C['fns'][K]>, ConfigOf<C>, OwnOf<C, Db>> }> &
8888
+ Needs<'kinds', { readonly [K in keyof C['kinds']]: C['kinds'][K] extends KindDef<infer P> ? KindImpl<P, ConfigOf<C>, OwnOf<C, Db>> : never }> &
8889
+ Needs<'context', { readonly [K in DynamicContextKeys<C['context']>]: C['context'][K] extends ContextDef<infer A, true> ? ContextImpl<A, ConfigOf<C>, OwnOf<C, Db>> : never }> &
8890
+ Needs<'hooks', { readonly [K in keyof C['hooks']]: HookImpl<ConfigOf<C>, OwnOf<C, Db>> }> &
8891
+ Needs<'mentions', { readonly [K in keyof C['mentions']]: C['mentions'][K] extends MentionDef<infer T, infer V> ? MentionImpl<T, V, ConfigOf<C>, OwnOf<C, Db>> : never }> &
8892
+ Needs<'types', { readonly [K in TypesWithMethods<C['types']>]: C['types'][K] extends TypeDef<infer V, infer M extends Methods> ? { readonly [J in keyof M]: MethodImpl<V, TypesOf<M[J]>, ConfigOf<C>, OwnOf<C, Db>> } : never }> &
8035
8893
  Needs<'sectioners', { readonly [K in keyof C['sectioners']]: SectionerImpl }> &
8036
- Needs<'actions', { readonly [K in keyof C['actions']]: C['actions'][K] extends ActionDef<infer I, infer R, infer St> ? ActionImpl<I, R, St, ConfigOf<C>, OwnOf<C>> : never }> &
8037
- Needs<'providers', { readonly [K in keyof C['providers']]: ProviderImpl<ConfigOf<C>, OwnOf<C>> }> &
8038
- (C['connect'] extends ConnectDecl ? { readonly connect: ConnectImpl<ConfigOf<C>, OwnOf<C>> } : { readonly connect?: never }) &
8894
+ Needs<'actions', { readonly [K in keyof C['actions']]: C['actions'][K] extends ActionDef<infer I, infer R, infer St> ? ActionImpl<I, R, St, ConfigOf<C>, OwnOf<C, Db>> : never }> &
8895
+ Needs<'providers', { readonly [K in keyof C['providers']]: ProviderImpl<ConfigOf<C>, OwnOf<C, Db>> }> &
8896
+ (C['connect'] extends ConnectDecl ? { readonly connect: ConnectImpl<ConfigOf<C>, OwnOf<C, Db>> } : { readonly connect?: never }) &
8039
8897
  {
8040
8898
  /** Resources this system serves. */
8041
8899
  readonly resources?: ResourceProvider;
8042
8900
  /** Hub events to receive. */
8043
- readonly events?: EventHandlers<ConfigOf<C>, OwnOf<C>>;
8044
- readonly lifecycle?: Lifecycle<ConfigOf<C>, OwnOf<C>>;
8901
+ readonly events?: EventHandlers<ConfigOf<C>, OwnOf<C, Db>>;
8902
+ readonly lifecycle?: Lifecycle<ConfigOf<C>, OwnOf<C, Db>>;
8045
8903
  };
8046
8904
  ```
8047
8905
 
@@ -8060,7 +8918,7 @@ that clash run one after another. `check` exactly when it declares `check`: what
8060
8918
  their type, asked by the hub before the policies and any approval.
8061
8919
 
8062
8920
  ```ts
8063
- type FnImpl<T extends FnTypes, Cfg = unknown, O extends Own = Own> =
8921
+ type FnImpl<T extends FnTypes, Cfg = unknown, O extends AnyOwn = Own> =
8064
8922
  {
8065
8923
  run(args: T['args'], ctx: FnCtx<T, Cfg, O>): Promise<Outcome<T>>;
8066
8924
  preview?(args: T['args'], ctx: PreviewCtx<Cfg, O>): Promise<PreviewAnswer>;
@@ -8068,7 +8926,7 @@ type FnImpl<T extends FnTypes, Cfg = unknown, O extends Own = Own> =
8068
8926
  claims?(args: T['args'], ctx: ClaimsCtx<Cfg, O>): ToolClaims | Promise<ToolClaims>;
8069
8927
  } &
8070
8928
  CheckImpl<T, Cfg> &
8071
- ([T['undo']] extends [never] ? { undo?: never } : { undo(payload: T['undo'], ctx: UndoCtx<Cfg>): Promise<UndoOutcome> });
8929
+ ([T['undo']] extends [never] ? { undo?: never } : { undo(payload: T['undo'], ctx: UndoCtx<Cfg, O['store']>): Promise<UndoOutcome> });
8072
8930
  ```
8073
8931
 
8074
8932
  Refers to: [`PreviewAnswer`](#core-previewanswer), [`SensitivityFlag`](#core-sensitivityflag), [`UndoOutcome`](#core-undooutcome).
@@ -8083,7 +8941,7 @@ query, or the form) into the account and credentials, or a problem in words; `di
8083
8941
  where the provider can (best effort).
8084
8942
 
8085
8943
  ```ts
8086
- interface ConnectImpl<Cfg, O extends Own = Own> {
8944
+ interface ConnectImpl<Cfg, O extends AnyOwn = Own> {
8087
8945
  start(request: ConnectStart, ctx: SystemCtx<Cfg, O>): Promise<{ url: string }> | { url: string };
8088
8946
  finish(request: ConnectFinish, ctx: SystemCtx<Cfg, O>): Promise<ConnectResult>;
8089
8947
  disconnect(connection: Pick<RunConnection, 'id' | 'owner' | 'credentials'>, ctx: SystemCtx<Cfg, O>): Promise<void>;
@@ -8176,6 +9034,11 @@ const SYSTEM_ENV = {
8176
9034
  pairingToken: 'HARNESS_PAIRING_TOKEN',
8177
9035
  supervised: 'HARNESS_SUPERVISED',
8178
9036
  restartCode: 'HARNESS_RESTART_CODE',
9037
+ /**
9038
+ * The hub's folder of database drivers (`pg`, `tedious`, `tarn`), which it installs when a store is placed in
9039
+ * Postgres or SQL Server: a store that opens there loads them from it when the system has none of its own.
9040
+ */
9041
+ storeDrivers: 'HARNESS_STORE_DRIVERS',
8179
9042
  } as const;
8180
9043
  ```
8181
9044
 
@@ -8229,7 +9092,7 @@ Runs systems. `LinkHost` is the real one; tests pass their own.
8229
9092
 
8230
9093
  ```ts
8231
9094
  interface SystemHost {
8232
- start<N extends string, C extends ContractShape>(contract: SystemContract<N, C>, impl: SystemImpl<C>, options: ServeOptions): Promise<RunningSystem<N>>;
9095
+ start<N extends string, C extends ContractShape, Db extends StoreDb = StoreDb>(contract: SystemContract<N, C>, impl: SystemImpl<C, Db>, options: ServeOptions): Promise<RunningSystem<N>>;
8233
9096
  }
8234
9097
  ```
8235
9098
 
@@ -8242,7 +9105,7 @@ Runs systems over the WebSocket link.
8242
9105
  ```ts
8243
9106
  class LinkHost implements SystemHost {
8244
9107
  constructor(deps: LinkHostDeps = {});
8245
- start<N extends string, C extends ContractShape>(contract: SystemContract<N, C>, impl: SystemImpl<C>, options: ServeOptions): Promise<RunningSystem<N>>;
9108
+ start<N extends string, C extends ContractShape, Db extends StoreDb = StoreDb>(contract: SystemContract<N, C>, impl: SystemImpl<C, Db>, options: ServeOptions): Promise<RunningSystem<N>>;
8246
9109
  }
8247
9110
  ```
8248
9111
 
@@ -8274,6 +9137,12 @@ interface LinkHostDeps {
8274
9137
  readonly folders?: (dirs: readonly string[]) => Promise<void>;
8275
9138
  /** Refuse a contract with a static fn that has no example (`checkExamples`). Default true; a test hub's fixtures may skip it. */
8276
9139
  readonly requireExamples?: boolean;
9140
+ /**
9141
+ * Opens the store with the system (the `system` placement): a test's store in memory (`openMemoryStore`) or in a
9142
+ * folder of its own (`localStoreConnect(dir)`). Default: SQLite in `<data>/store/store.db`. A store on the hub or in
9143
+ * an external database always opens on the real engines, so a move between placements works the same in a test.
9144
+ */
9145
+ readonly storeConnect?: () => Promise<StoreConnection>;
8277
9146
  }
8278
9147
  ```
8279
9148
 
@@ -8428,7 +9297,7 @@ Turns text into a QR code drawn with UTF-8 block characters.
8428
9297
  type QrRenderer = (text: string) => Promise<string>;
8429
9298
  ```
8430
9299
 
8431
- ## 21. The run context and services
9300
+ ## 22. The run context and services
8432
9301
 
8433
9302
  Every implementation gets a context (`ctx`) typed by what it implements.
8434
9303
 
@@ -8503,6 +9372,22 @@ the card a form: the approver fills a value of the gin type `type`, and the run
8503
9372
  `ctx.decide(question, candidates, { max })` (`Decisions`, runs only) asks the admin's decision model to pick
8504
9373
  candidates to reuse (each `{ id, text, score }`); `by: 'off'` or `'failed'` means go by the scores yourself.
8505
9374
 
9375
+ ### How does a fn change the result of a run that already finished?
9376
+
9377
+ A run's saved result is what its card, the chat and anyone reading the run see. When a card lets a person make a
9378
+ choice after the run is done (pick an option, tick off a step, accept a suggestion), the choice should change that
9379
+ result, so the card shows it as it is now after a reload and a model reading the run later sees it too.
9380
+ `ctx.updateResult(fn, run, result)` (`ResultUpdates`, on every run, action and system context) does that:
9381
+
9382
+ - `fn` is the ref of the run's fn; its result type checks the new value, in the system and again in the hub.
9383
+ - `run` is the run's id. An action a renderer sent gets it as `ctx.run`; a fn the card runs takes it as an arg.
9384
+ - `result` replaces the whole saved result: read what you need from the card's action, build the new value and pass
9385
+ all of it.
9386
+
9387
+ It resolves with how many times that run's result has been changed since it finished, and every chat showing the run
9388
+ redraws it. It refuses a run of another system, and a run that isn't `done`. Changes to one run's result go one at a
9389
+ time, in the order they were asked. Use it for a choice made on a result; a new piece of work is a new run.
9390
+
8506
9391
  ### Reference: the run context and services
8507
9392
 
8508
9393
  #### `FnCtx`
@@ -8513,11 +9398,13 @@ What a run gets besides its args. Typed by its fn: only its deps can be called,
8513
9398
  progress steps can be reported, and the outcome helpers take its result, undo and resume types.
8514
9399
 
8515
9400
  ```ts
8516
- interface FnCtx<T extends FnTypes, Cfg = unknown, O extends Own = Own> extends Services, Proposals, Decisions, Fleets, FnSearch, RunNotices<O> {
9401
+ interface FnCtx<T extends FnTypes, Cfg = unknown, O extends AnyOwn = Own> extends Services, Proposals, Decisions, Fleets, FnSearch, RunNotices<O> {
8517
9402
  /** The system's config, as it was when this run started. */
8518
9403
  readonly config: Cfg;
8519
9404
  /** Which run this is, whom it acts for, and where it sits in the tree. */
8520
9405
  readonly run: RunInfo;
9406
+ /** The system's own store, as in `SystemCtx.store`. */
9407
+ readonly store: O['store'];
8521
9408
  readonly budget: BudgetInfo;
8522
9409
  /** Aborts on cancel or timeout. */
8523
9410
  readonly signal: AbortSignal;
@@ -8587,7 +9474,7 @@ interface · `import { Services } from '@harness/sdk'`
8587
9474
  What every run, undo and action gets from the hub.
8588
9475
 
8589
9476
  ```ts
8590
- interface Services extends SystemPlace, AiSource, AdminNotices {
9477
+ interface Services extends SystemPlace, AiSource, AdminNotices, ResultUpdates {
8591
9478
  /** LLM calls through the hub, counted against the run's budget. */
8592
9479
  readonly llm: Llm;
8593
9480
  readonly files: Files;
@@ -8620,7 +9507,7 @@ Refers to: [`Link`](#core-link), [`QualifiedName`](#core-qualifiedname).
8620
9507
  interface · `import { SystemCtx } from '@harness/sdk'`
8621
9508
 
8622
9509
  ```ts
8623
- interface SystemCtx<Cfg = unknown, O extends Own = Own> extends SystemPlace, Proposals, Fleets, FnSearch, AiSource, AdminNotices, InstanceConnects, OwnerRuns<O> {
9510
+ interface SystemCtx<Cfg = unknown, O extends AnyOwn = Own> extends SystemPlace, Proposals, Fleets, FnSearch, AiSource, AdminNotices, ResultUpdates, InstanceConnects, OwnerRuns<O> {
8624
9511
  readonly system: string;
8625
9512
  /** The system's current config. */
8626
9513
  readonly config: Cfg;
@@ -8629,6 +9516,11 @@ interface SystemCtx<Cfg = unknown, O extends Own = Own> extends SystemPlace, Pro
8629
9516
  readonly types: Types;
8630
9517
  /** Records of stored types, as the system itself (no run, so no person: `person` types are refused). */
8631
9518
  readonly data: Data;
9519
+ /**
9520
+ * The system's own store (`store()` in its contract): Kysely over its tables plus `vectors(name)`, open and migrated
9521
+ * before anything runs. `undefined` for a system that declares none. Typed by the tables given to `implement<Db>`.
9522
+ */
9523
+ readonly store: O['store'];
8632
9524
  readonly log: Log;
8633
9525
  readonly signal: AbortSignal;
8634
9526
  }
@@ -8658,11 +9550,13 @@ Refers to: [`InstanceName`](#core-instancename).
8658
9550
 
8659
9551
  interface · `import { UndoCtx } from '@harness/sdk'`
8660
9552
 
8661
- What an undo implementation gets.
9553
+ What an undo implementation gets; `S` is what its `store` is (`Own['store']`).
8662
9554
 
8663
9555
  ```ts
8664
- interface UndoCtx<Cfg = unknown> extends Services {
9556
+ interface UndoCtx<Cfg = unknown, S = Own['store']> extends Services {
8665
9557
  readonly config: Cfg;
9558
+ /** The system's own store, as in `SystemCtx.store`. */
9559
+ readonly store: S;
8666
9560
  readonly run: RunInfo;
8667
9561
  readonly signal: AbortSignal;
8668
9562
  }
@@ -9007,6 +9901,28 @@ interface AdminNotices {
9007
9901
 
9008
9902
  Refers to: [`AdminNotice`](#core-adminnotice).
9009
9903
 
9904
+ #### `ResultUpdates`
9905
+
9906
+ interface · `import { ResultUpdates } from '@harness/sdk'`
9907
+
9908
+ Changing what a finished run of this system produced (Phil: "The component system should support updating fn
9909
+ results"): a run's card lets a person make a choice (pick an option, mark a step done), the card sends an action or
9910
+ runs a fn, and that replaces the earlier run's saved result, so the card, the chat and anyone reading the run see the
9911
+ result as it is now. Only the system's own runs, only finished ones, and the value must fit the fn's result type.
9912
+
9913
+ ```ts
9914
+ interface ResultUpdates {
9915
+ /**
9916
+ * Replace the saved result of a finished (`done`) run of one of this system's fns: `fn` is that run's fn (its result
9917
+ * type checks the value, here and in the hub). Every chat showing the run redraws it. Resolves with how many times
9918
+ * the result has been changed since the run finished; rejects for a run that isn't this system's or isn't done.
9919
+ */
9920
+ updateResult<R>(fn: FnRef<QualifiedName, unknown, R, Handlers>, run: RunId, result: R): Promise<number>;
9921
+ }
9922
+ ```
9923
+
9924
+ Refers to: [`QualifiedName`](#core-qualifiedname), [`RunId`](#core-runid).
9925
+
9010
9926
  #### `hubAi`
9011
9927
 
9012
9928
  function · `import { hubAi } from '@harness/sdk/server'`
@@ -9303,7 +10219,7 @@ function wireRequest(request: Request): LlmRequest;
9303
10219
 
9304
10220
  Refers to: [`LlmRequest`](#core-llmrequest).
9305
10221
 
9306
- ## 22. Calling other fns
10222
+ ## 23. Calling other fns
9307
10223
 
9308
10224
  A fn calls another fn (of its own system, another system or the hub) by declaring it as a **dep** with its ref, then
9309
10225
  calling it through `ctx.fns`. Nothing else can be called, and the args, result and handlers are typed by the ref:
@@ -9478,7 +10394,7 @@ class HandlerFailed extends Error {
9478
10394
 
9479
10395
  Refers to: [`FnError`](#core-fnerror).
9480
10396
 
9481
- ## 23. Config, events, lifecycle and data
10397
+ ## 24. Config, events, lifecycle and data
9482
10398
 
9483
10399
  ### Config
9484
10400
 
@@ -9536,8 +10452,9 @@ lifecycle: {
9536
10452
  The hub gives each installed instance its own folders, outside the package, so upgrades and rollbacks keep them:
9537
10453
  `<hub data>/systems/<name>/instances/<instance>/{state,data,cache}`. Code reaches them through every context:
9538
10454
 
9539
- - `ctx.dataDir`: what is the system's alone (its keys, a working copy of something it syncs). Data kept for people is
9540
- never here: it is hub records (**Stored types and the data system**). The hub exports this folder with the
10455
+ - `ctx.dataDir`: files that are the system's alone (its keys, a working copy of something it syncs). Data kept for
10456
+ people is never here: it is hub records (**Stored types and the data system**). Tables the system's code keeps for
10457
+ itself are a store (**A store of the system’s own**), never a database file of its own here. The hub exports this folder with the
9541
10458
  instance's config (`harness system export-data`) and installs it back.
9542
10459
  - `ctx.cacheDir`: what can be made again (client builds, indexes). Never exported; may be cleared.
9543
10460
  - `ctx.instance`: this instance's name, `main` for a system that runs one copy. Several copies of one system can be
@@ -9557,7 +10474,7 @@ interface · `import { Lifecycle } from '@harness/sdk'`
9557
10474
  Moments in a system's life. All optional; each gets the system's context with its current config.
9558
10475
 
9559
10476
  ```ts
9560
- interface Lifecycle<Cfg, O extends Own = Own> {
10477
+ interface Lifecycle<Cfg, O extends AnyOwn = Own> {
9561
10478
  /** The first time it connects after being paired or installed (with a valid config). */
9562
10479
  installed?(ctx: SystemCtx<Cfg, O>): Promise<void>;
9563
10480
  /** Every time it connects with a valid config and its contract is imported. */
@@ -9590,14 +10507,14 @@ type · `import { EventHandlers } from '@harness/sdk'`
9590
10507
  Hub events a system handles, by event type. Subscriptions follow the handlers given.
9591
10508
 
9592
10509
  ```ts
9593
- type EventHandlers<Cfg, O extends Own = Own> = {
10510
+ type EventHandlers<Cfg, O extends AnyOwn = Own> = {
9594
10511
  readonly [E in SystemEvent['type']]?: (event: Extract<SystemEvent, { type: E }>, ctx: SystemCtx<Cfg, O>) => Promise<void>;
9595
10512
  };
9596
10513
  ```
9597
10514
 
9598
10515
  Refers to: [`SystemEvent`](#core-systemevent).
9599
10516
 
9600
- ## 24. Runs a system starts by itself, and notices
10517
+ ## 25. Runs a system starts by itself, and notices
9601
10518
 
9602
10519
  A system that owns a kind can run its people's fns of that kind later by itself, outside any chat, and tell those
9603
10520
  people how each run went. It declares the `runs` hub grant (`grants: { hub: ['runs', …] }`); the review page flags it
@@ -9647,29 +10564,50 @@ undoing the run saves its last version again.
9647
10564
  type · `import { OwnOf } from '@harness/sdk'`
9648
10565
 
9649
10566
  What a contract's implementation calls its own (`Own`): the refs of its kinds and of its pages, so `ctx.runs` and
9650
- notices take those and nothing of another system's.
10567
+ notices take those and nothing of another system's, and its store over its own tables (`Db`) when it declares a
10568
+ store. Without one it is the plain context's store type (`undefined` at run time), so such a context still fits
10569
+ where a plain `SystemCtx` is taken and the other way round.
9651
10570
 
9652
10571
  ```ts
9653
- type OwnOf<C extends ContractShape> = Own<
10572
+ type OwnOf<C extends ContractShape, Db extends StoreDb = StoreDb> = Own<
9654
10573
  { [K in keyof C['kinds']]: C['kinds'][K] extends KindDef<infer P> ? KindRef<Q<C['system'], K>, P> : never }[keyof C['kinds']],
9655
- { [K in keyof C['pages']]: PageRef<Q<C['system'], K>> }[keyof C['pages']]
10574
+ { [K in keyof C['pages']]: PageRef<Q<C['system'], K>> }[keyof C['pages']],
10575
+ C['store'] extends StoreDecl ? SystemStore<Db> : SystemStore<StoreDb> | undefined
9656
10576
  >;
9657
10577
  ```
9658
10578
 
10579
+ Refers to: [`StoreDecl`](#core-storedecl).
10580
+
9659
10581
  #### `Own`
9660
10582
 
9661
10583
  interface · `import { Own } from '@harness/sdk'`
9662
10584
 
9663
- What a ctx knows of its own contract: the refs of its kinds and of its pages. `SystemImpl<Defs>` types every ctx it
9664
- hands out with its own (`OwnOf`), so another system's kind, fn or page doesn't fit where only its own do.
10585
+ What a ctx knows of its own contract: the refs of its kinds and of its pages, and its store's tables. `SystemImpl<Defs>`
10586
+ types every ctx it hands out with its own (`OwnOf`), so another system's kind, fn or page doesn't fit where only its
10587
+ own do, and `ctx.store` is typed by the system's table interface (`implement<Db>`), or absent without a store.
9665
10588
 
9666
10589
  ```ts
9667
- interface Own<K extends AnyKindRef = AnyKindRef, P extends AnyPageRef = AnyPageRef> {
10590
+ interface Own<K extends AnyKindRef = AnyKindRef, P extends AnyPageRef = AnyPageRef, S = SystemStore<StoreDb> | undefined> {
9668
10591
  readonly kinds: K;
9669
10592
  readonly pages: P;
10593
+ /**
10594
+ * What `ctx.store` is (a type only): the store over the system's own tables (`SystemStore<Db>`) for a contract that
10595
+ * declares one; for one that doesn't, the plain context's (it is `undefined` at run time).
10596
+ */
10597
+ readonly store: S;
9670
10598
  }
9671
10599
  ```
9672
10600
 
10601
+ #### `AnyOwn`
10602
+
10603
+ type · `import { AnyOwn } from '@harness/sdk'`
10604
+
10605
+ What any context's own refs and store may be: the bound every `O` takes, so one with a typed store fits too.
10606
+
10607
+ ```ts
10608
+ type AnyOwn = Own<AnyKindRef, AnyPageRef, unknown>;
10609
+ ```
10610
+
9673
10611
  #### `KindRuns`
9674
10612
 
9675
10613
  interface · `import { KindRuns } from '@harness/sdk'`
@@ -9684,7 +10622,7 @@ await ctx.runs.notify(items[0], { title: 'Weekly summary ran', body: '12 rows',
9684
10622
  ```
9685
10623
 
9686
10624
  ```ts
9687
- interface KindRuns<O extends Own = Own> {
10625
+ interface KindRuns<O extends AnyOwn = Own> {
9688
10626
  /** The fns of one of this system's kinds, with owner, title, version and parsed payload, a page at a time. */
9689
10627
  kindFns<K extends O['kinds']>(kind: K, query?: { readonly changedSince?: Timestamp; readonly cursor?: string }): Promise<{ readonly items: Array<KindFn<K>>; readonly cursor?: string }>;
9690
10628
  /**
@@ -9766,7 +10704,7 @@ interface · `import { OwnerRuns } from '@harness/sdk'`
9766
10704
  `ctx.runs`: in a system's context (hooks, events, lifecycle, timers), never in a run's.
9767
10705
 
9768
10706
  ```ts
9769
- interface OwnerRuns<O extends Own = Own> {
10707
+ interface OwnerRuns<O extends AnyOwn = Own> {
9770
10708
  /** Runs of this system's own kinds' fns, as their owners, and notices to those owners. Needs the `runs` grant. */
9771
10709
  readonly runs: KindRuns<O>;
9772
10710
  }
@@ -9779,7 +10717,7 @@ interface · `import { RunNotices } from '@harness/sdk'`
9779
10717
  `ctx.notify`: in a run's context only.
9780
10718
 
9781
10719
  ```ts
9782
- interface RunNotices<O extends Own = Own> {
10720
+ interface RunNotices<O extends AnyOwn = Own> {
9783
10721
  /** Notify the person this run is for (inbox and push), never anyone else. The run's settled event says it did (`notified`). */
9784
10722
  notify(notice: Notice<O>): Promise<void>;
9785
10723
  }
@@ -9792,7 +10730,7 @@ interface · `import { Notice } from '@harness/sdk'`
9792
10730
  A notice to one person: the owner of a kind fn (`runs.notify`) or the person a run is for (`ctx.notify`).
9793
10731
 
9794
10732
  ```ts
9795
- interface Notice<O extends Own = Own> {
10733
+ interface Notice<O extends AnyOwn = Own> {
9796
10734
  readonly title: string;
9797
10735
  /** At most `NOTIFICATION_BODY` (160) characters; longer is clamped on a word boundary. */
9798
10736
  readonly body: string;
@@ -9816,7 +10754,7 @@ type · `import { NoticeLink } from '@harness/sdk'`
9816
10754
  Where a notice leads: a run of the person's, or one of this system's own pages (a ref, with more path and a query).
9817
10755
 
9818
10756
  ```ts
9819
- type NoticeLink<O extends Own = Own> =
10757
+ type NoticeLink<O extends AnyOwn = Own> =
9820
10758
  | { readonly run: RunId }
9821
10759
  | { readonly page: O['pages']; readonly path?: readonly string[]; readonly query?: Readonly<Record<string, string>> };
9822
10760
  ```
@@ -9853,7 +10791,7 @@ type AnyPageRef = PageRef<QualifiedName>;
9853
10791
 
9854
10792
  Refers to: [`QualifiedName`](#core-qualifiedname).
9855
10793
 
9856
- ## 25. Remote services: fleets, sign-in and connections per instance
10794
+ ## 26. Remote services: fleets, sign-in and connections per instance
9857
10795
 
9858
10796
  A system that calls a remote service it was set up for (an MCP server) is a fleet: one instance per service, added from
9859
10797
  the browser with its config (`instances: "many"` in `system.json`). A system that authors code calling many services
@@ -10061,7 +10999,7 @@ Headers with the secret ones masked (`••••` and their last four characte
10061
10999
  function maskHeaders(headers: Readonly<Record<string, string>>, secret: ReadonlySet<string>): Record<string, string>;
10062
11000
  ```
10063
11001
 
10064
- ## 26. The client: renderers, inputs, resource views and pages
11002
+ ## 27. The client: renderers, inputs, resource views and pages
10065
11003
 
10066
11004
  A system can draw its things in the chat with **Vue 3 components**. `client(contract, renderers)` in `client/index.ts`
10067
11005
  (default export) registers them, and each component's props are typed by the contract, so a component with the wrong
@@ -10188,6 +11126,10 @@ viewer either replaces the hub's preview for its format (`mode: 'replace'`) or a
10188
11126
  `label`); a bare component replaces. `view.forms` lists the forms the hub made of the resource and `view.text(form)` reads
10189
11127
  one (the notes system's `client/WordCount.vue` adds a Words tab to every markdown resource). Inside any
10190
11128
  renderer, `inject(RESOURCE_VIEWER)` gives the component that shows any resource (`<ResourceViewer :uri="uri" compact />`).
11129
+ A renderer or page that draws code itself (line numbers, change bars, a selection) highlights it with the app's Shiki
11130
+ through `inject(CODE_HIGHLIGHTER)` (`CodeHighlighter`): `tokens(code, language)` answers at once with what is loaded,
11131
+ as `CodeToken`s drawn as text with the `tok-<kind>` classes, and `prepare(language)` resolves true once a grammar has
11132
+ loaded and `tokens` would answer better.
10191
11133
 
10192
11134
  **Look.** Renderers sit inside the chat, so use its design tokens (`var(--space-2)`, `var(--surface)`, `var(--border)`,
10193
11135
  `var(--text-dim)`, `var(--accent)`, `var(--danger)`, `var(--radius)`, `var(--text-sm)`, …) in scoped styles, so they
@@ -11267,6 +12209,55 @@ interface SharedComponents {
11267
12209
  }
11268
12210
  ```
11269
12211
 
12212
+ #### `CODE_HIGHLIGHTER`
12213
+
12214
+ const · `import { CODE_HIGHLIGHTER } from '@harness/sdk'`
12215
+
12216
+ Where the app provides its highlighter. A global symbol, so a system's own bundle finds the app's.
12217
+
12218
+ ```ts
12219
+ const CODE_HIGHLIGHTER: InjectionKey<CodeHighlighter>;
12220
+ ```
12221
+
12222
+ #### `CodeHighlighter`
12223
+
12224
+ interface · `import { CodeHighlighter } from '@harness/sdk'`
12225
+
12226
+ The app's syntax highlighter (Shiki, loading each language's grammar the first time it is drawn), for a page or
12227
+ renderer that draws code itself (line numbers, change bars, selections): `inject(CODE_HIGHLIGHTER)`. `tokens` answers
12228
+ at once with what is loaded; `prepare` loads a language and resolves true once `tokens` would answer better.
12229
+
12230
+ ```ts
12231
+ interface CodeHighlighter {
12232
+ tokens(code: string, language: string): readonly CodeToken[];
12233
+ prepare(language: string): Promise<boolean>;
12234
+ knows(language: string): boolean;
12235
+ }
12236
+ ```
12237
+
12238
+ #### `CodeToken`
12239
+
12240
+ interface · `import { CodeToken } from '@harness/sdk'`
12241
+
12242
+ A run of code of one kind, drawn as text (never as HTML).
12243
+
12244
+ ```ts
12245
+ interface CodeToken {
12246
+ readonly kind: CodeTokenKind;
12247
+ readonly text: string;
12248
+ }
12249
+ ```
12250
+
12251
+ #### `CodeTokenKind`
12252
+
12253
+ type · `import { CodeTokenKind } from '@harness/sdk'`
12254
+
12255
+ What a highlighted piece of code is, which picks its colour.
12256
+
12257
+ ```ts
12258
+ type CodeTokenKind = 'plain' | 'comment' | 'string' | 'number' | 'keyword' | 'literal';
12259
+ ```
12260
+
11270
12261
  #### `FrameProps`
11271
12262
 
11272
12263
  interface · `import { FrameProps } from '@harness/sdk'`
@@ -11674,7 +12665,7 @@ A place inside the app: a path or a relative path. Never `//host`, nor `/\host`,
11674
12665
  const APP_PATH: RegExp;
11675
12666
  ```
11676
12667
 
11677
- ## 27. Visuals and widgets
12668
+ ## 28. Visuals and widgets
11678
12669
 
11679
12670
  A fn that returns a `ResultTable` (a database query, `hub/records_table`, any fn of that shape) is drawn by the result
11680
12671
  view, which offers every **visual** that can draw it: a table, value cards and twelve chart families (part of a whole,
@@ -12568,7 +13559,7 @@ interface WidgetDraft {
12568
13559
 
12569
13560
  Refers to: [`WidgetSpec`](#core-widgetspec).
12570
13561
 
12571
- ## 28. Packaging: system.json, build, pack, install
13562
+ ## 29. Packaging: system.json, build, pack, install
12572
13563
 
12573
13564
  ### `system.json`
12574
13565
 
@@ -12699,13 +13690,16 @@ Every command, read from the CLI itself:
12699
13690
  | `harness system build [dir] [--skip-typecheck] [--hub <url>] [--token <token>]` | Typecheck a system, check its name and context, and bundle its server and client into dist/. |
12700
13691
  | `harness test [dir] [--previews] [--json] [--filter <text>]` | Run a system's own tests (the SDK test kit); --previews also shoots its components into a gallery. |
12701
13692
  | `harness system pack [dir] [--out <file>] [--skip-typecheck]` | Build if needed, then zip dist/ with every file hashed into a package the hub installs. |
12702
- | `harness system install <zip \| folder \| premade-name \| npm-spec> [--config <file.json>] [--instance <name>] [--data <export.zip>] [--no-start] [--wait <ms>]` | Install a package zip, a folder, a premade system by name or an npm package on a hub, which pairs, configures and starts it. |
13693
+ | `harness system install <zip \| folder \| premade-name \| npm-spec> [--config <file.json>] [--instance <name>] [--data <export.zip>] [--no-start] [--wait <ms>] [--store system\|hub\|external [--store-engine postgres\|sqlserver --store-url-env <VAR> \| --store-url <url> --store-schema <schema>]]` | Install a package zip, a folder, a premade system by name or an npm package on a hub, which pairs, configures and starts it. |
12703
13694
  | `harness system export-data <system> [--instance <name>] [--out <file>] [--with-secrets --yes]` | Download an installed instance’s data folder as a zip (its config too, with --with-secrets --yes). |
12704
13695
  | `harness system list` | List the hub’s systems and their instances. |
12705
13696
  | `harness system start <system> [--instance <name>]` | Start an installed system (every instance, or one with --instance). |
12706
13697
  | `harness system stop <system> [--instance <name>]` | Stop an installed system (every instance, or one with --instance). |
12707
13698
  | `harness system upgrade <system> [--version <version>]` | Upgrade an installed system from its npm or git source (a zip upgrades by installing a newer zip). |
12708
- | `harness system uninstall <system> [--instance <name>]` | Stop and remove an installed system’s instances (one with --instance); their data folders stay. |
13699
+ | `harness system uninstall <system> [--instance <name>] [--delete-store]` | Stop and remove an installed system’s instances (one with --instance); their data folders stay, and so does each one’s own store unless --delete-store. |
13700
+ | `harness system store <system> [--instance <name>]` | Show a system’s own store: where it lives, its state, size and tables, its migrations, its backups and its move. |
13701
+ | `harness system store move <system> --to hub\|system\|external [--engine postgres\|sqlserver --url <url\|-> --schema <name>] [--instance <name>] [--cancel-runs \| --keep-waiting]` | Move a system’s store to the hub, the system, or an external database, and follow the move until it ends. |
13702
+ | `harness system store answer <system> cancel\|wait [--instance <name>]` | Answer a store move waiting on runs still going: cancel them, or keep waiting until they finish. |
12709
13703
  | `harness mcp <slug> [--hub <url>] (the secret in HARNESS_MCP_SECRET)` | Bridge a hub MCP to stdin and stdout, for MCP clients that speak stdio only. |
12710
13704
 
12711
13705
  `harness system new` fills the name in everywhere the template has `template`: as is in strings and paths, in camel
@@ -12805,8 +13799,9 @@ Refers to: [`InstanceName`](#core-instancename), [`SystemPackageManifest`](#core
12805
13799
  function · `import { packageProblems } from '@harness/sdk/server'`
12806
13800
 
12807
13801
  What is wrong with a package for the contract it ships: the contract's name must be the manifest's, the manifest
12808
- must speak this SDK's link protocol (its format is checked by the schema), and a system that runs one instance
12809
- (`instances: 'one'`) runs only as `main`. Empty when they agree.
13802
+ must speak this SDK's link protocol (its format is checked by the schema), a system that runs one instance
13803
+ (`instances: 'one'`) runs only as `main`, and a system with a store lists its SQLite drivers in `server.external`.
13804
+ Empty when they agree.
12810
13805
 
12811
13806
  ```ts
12812
13807
  function packageProblems(contract: AnyContract, manifest: SystemPackageManifest, instance?: InstanceName): string[];
@@ -12945,7 +13940,7 @@ interface AuthoredText {
12945
13940
  }
12946
13941
  ```
12947
13942
 
12948
- ## 29. Testing
13943
+ ## 30. Testing
12949
13944
 
12950
13945
  Every system tests itself with the SDK's **test kit** (`@harness/sdk/testing`), in vitest, with no setup:
12951
13946
 
@@ -12973,6 +13968,15 @@ Every system tests itself with the SDK's **test kit** (`@harness/sdk/testing`),
12973
13968
  - **Data.** The fake hub answers `ctx.data` from records in memory, like the hub (filters, sorts, text search, pages,
12974
13969
  versions, `expect`, person-owned types refused outside runs): `kit.records('<Type>')` reads what runs saved, and
12975
13970
  `kit.hub.data.save(...)` puts records in first. Another system's stored type goes in `kit.hub.storedTypes`.
13971
+ - **A store.** A system with a store gets one from the kit: SQLite in memory by default, migrated with the
13972
+ migrations given in `serve` (`testHub(contract, impl, { serve: { store: { migrations } } })`). Put it in a real
13973
+ file with `host: { storeConnect: localStoreConnect(dir) }`, or on the hub with `hub: { store: { placement: 'hub' } }`
13974
+ and `stores` (the hub's own store host for a system's tests: `hubStores(dir).endpoints(ref)` from
13975
+ `@harness/hub/stores/testing`); run a system's tests in both, and in Postgres or SQL Server as live tests.
13976
+ `kit.hub.storeStatuses` is what the system reported of its store. Without a hub, `testStore(migrations)` gives a
13977
+ migrated store (`{ store, close }`) for a unit test; a hand-made context whose code never touches the store spreads
13978
+ in `store: NO_STORE`, which refuses every statement. Code over the work backend runs `WORK_BACKEND_CHECKS` (the
13979
+ queue and store semantics each placement must keep), each check against a fresh queue on the store under test.
12976
13980
  - **Sensitive files, claims and mentions.** `kit.flags('<fn>', args)` gives the flags its `flags` hook answers, as
12977
13981
  the hub asks before a run. `kit.claims('<fn>', args)` gives what an agent's call would operate on: its
12978
13982
  `parallelClaims` filled from the args, joined with what its `claims` hook answers. `kit.mentions('<provider>', query)` gives a mention provider's options and the resource searches
@@ -13111,6 +14115,8 @@ class FakeHub {
13111
14115
  readonly progress: Array<HubBody<'progress'>>;
13112
14116
  readonly allowed: Array<HubBody<'allow'>>;
13113
14117
  readonly undos: Array<HubBody<'undoWith'>>;
14118
+ /** The finished runs' results the system replaced (`ctx.updateResult`). */
14119
+ readonly resultUpdates: Array<HubBody<'updateResult'>>;
13114
14120
  readonly attachments: Array<HubBody<'attach'>>;
13115
14121
  readonly logs: LogLine[];
13116
14122
  /** Refreshed (or expired) credentials systems handed back (`connectionUpdate`). */
@@ -13158,6 +14164,16 @@ class FakeHub {
13158
14164
  readonly exampleChanges: Array<HubBody<'examples'>>;
13159
14165
  /** Pairing tokens approved install runs asked for (`grantPairing`), with the grant the fake hub made. */
13160
14166
  readonly pairingGrants: Array<PairingGrantRequest & PairingGrant>;
14167
+ /** What the system reported about its store (`storeStatus`), in order. */
14168
+ readonly storeStatuses: StoreStatusReport[];
14169
+ /** Called with each store status the system reports (after it is kept in `storeStatuses`), as the hub would hear it. */
14170
+ onStoreStatus: (report: StoreStatusReport) => void | Promise<void>;
14171
+ /** How far store moves got, as the system reported it (`storeMoveProgress`), in order. */
14172
+ readonly storeMoves: Array<HubBody<'storeMoveProgress'>>;
14173
+ /** Called with each move progress report, as the hub would hear it. */
14174
+ onStoreMoveProgress: (report: HubBody<'storeMoveProgress'>) => void | Promise<void>;
14175
+ /** The store the hub keeps for the system, when its welcome puts it on the hub. Default: every call refused. */
14176
+ stores: FakeStoreEndpoints;
13161
14177
  /** Paired keys by system name. */
13162
14178
  readonly keys: Map<string, string>;
13163
14179
  /** Session state by owner (`run:<id>` / `delivery:<id>`). */
@@ -13287,7 +14303,7 @@ class FakeHub {
13287
14303
  }
13288
14304
  ```
13289
14305
 
13290
- Refers to: [`ActorId`](#core-actorid), [`AdminNotice`](#core-adminnotice), [`ArgsCheckAnswer`](#core-argscheckanswer), [`ClaimsAnswer`](#core-claimsanswer), [`ConfigValue`](#core-configvalue), [`ConnectResult`](#core-connectresult), [`ContentRef`](#core-contentref), [`DecideAnswer`](#core-decideanswer), [`FlagsAnswer`](#core-flagsanswer), [`FleetInstance`](#core-fleetinstance), [`HandlerAnswer`](#core-handleranswer), [`Hello`](#core-hello), [`HubLinkSpec`](#core-hublinkspec), [`HubModelInfo`](#core-hubmodelinfo), [`InstanceName`](#core-instancename), [`Json`](#core-json), [`JsonObject`](#core-jsonobject), [`KindEstimateAnswer`](#core-kindestimateanswer), [`KindFnShape`](#core-kindfnshape), [`KindFnWire`](#core-kindfnwire), [`LinkSession`](#core-linksession), [`LlmForward`](#core-llmforward), [`LlmForwardChunk`](#core-llmforwardchunk), [`LogLine`](#core-logline), [`Manifest`](#core-manifest), [`ManifestPatch`](#core-manifestpatch), [`MentionResourceSearch`](#core-mentionresourcesearch), [`ModelForward`](#core-modelforward), [`ModelForwardResult`](#core-modelforwardresult), [`OutcomeWire`](#core-outcomewire), [`PairingGrant`](#core-pairinggrant), [`PairingGrantRequest`](#core-pairinggrantrequest), [`PairingId`](#core-pairingid), [`PairingInfo`](#core-pairinginfo), [`PreviewAnswer`](#core-previewanswer), [`ProposedRun`](#core-proposedrun), [`QualifiedName`](#core-qualifiedname), [`ResourceHit`](#core-resourcehit), [`ResourceRead`](#core-resourceread), [`RunControl`](#core-runcontrol), [`RunInfo`](#core-runinfo), [`RunRequest`](#core-runrequest), [`RunSettled`](#core-runsettled), [`Section`](#core-section), [`StartedRun`](#core-startedrun), [`StateOwner`](#core-stateowner), [`SystemLinkSpec`](#core-systemlinkspec), [`TypeDefinitions`](#core-typedefinitions).
14306
+ Refers to: [`ActorId`](#core-actorid), [`AdminNotice`](#core-adminnotice), [`ArgsCheckAnswer`](#core-argscheckanswer), [`ClaimsAnswer`](#core-claimsanswer), [`ConfigValue`](#core-configvalue), [`ConnectResult`](#core-connectresult), [`ContentRef`](#core-contentref), [`DecideAnswer`](#core-decideanswer), [`FlagsAnswer`](#core-flagsanswer), [`FleetInstance`](#core-fleetinstance), [`HandlerAnswer`](#core-handleranswer), [`Hello`](#core-hello), [`HubLinkSpec`](#core-hublinkspec), [`HubModelInfo`](#core-hubmodelinfo), [`InstanceName`](#core-instancename), [`Json`](#core-json), [`JsonObject`](#core-jsonobject), [`KindEstimateAnswer`](#core-kindestimateanswer), [`KindFnShape`](#core-kindfnshape), [`KindFnWire`](#core-kindfnwire), [`LinkSession`](#core-linksession), [`LlmForward`](#core-llmforward), [`LlmForwardChunk`](#core-llmforwardchunk), [`LogLine`](#core-logline), [`Manifest`](#core-manifest), [`ManifestPatch`](#core-manifestpatch), [`MentionResourceSearch`](#core-mentionresourcesearch), [`ModelForward`](#core-modelforward), [`ModelForwardResult`](#core-modelforwardresult), [`OutcomeWire`](#core-outcomewire), [`PairingGrant`](#core-pairinggrant), [`PairingGrantRequest`](#core-pairinggrantrequest), [`PairingId`](#core-pairingid), [`PairingInfo`](#core-pairinginfo), [`PreviewAnswer`](#core-previewanswer), [`ProposedRun`](#core-proposedrun), [`QualifiedName`](#core-qualifiedname), [`ResourceHit`](#core-resourcehit), [`ResourceRead`](#core-resourceread), [`RunControl`](#core-runcontrol), [`RunInfo`](#core-runinfo), [`RunRequest`](#core-runrequest), [`RunSettled`](#core-runsettled), [`Section`](#core-section), [`StartedRun`](#core-startedrun), [`StateOwner`](#core-stateowner), [`StoreStatusReport`](#core-storestatusreport), [`SystemLinkSpec`](#core-systemlinkspec), [`TypeDefinitions`](#core-typedefinitions).
13291
14307
 
13292
14308
  #### `FakeHubOptions`
13293
14309
 
@@ -13315,10 +14331,12 @@ interface FakeHubOptions {
13315
14331
  autoPair?: AutoPairGrant;
13316
14332
  /** Refuse every hello that brings an auto-pair secret, as the hub does for an expired or revoked one. */
13317
14333
  refuseAutoPair?: boolean;
14334
+ /** Where the welcome says the system's store lives (default absent: with the system). */
14335
+ store?: StoreOpen;
13318
14336
  }
13319
14337
  ```
13320
14338
 
13321
- Refers to: [`AutoPairGrant`](#core-autopairgrant), [`InstanceName`](#core-instancename).
14339
+ Refers to: [`AutoPairGrant`](#core-autopairgrant), [`InstanceName`](#core-instancename), [`StoreOpen`](#core-storeopen).
13322
14340
 
13323
14341
  #### `FakeProcess`
13324
14342
 
@@ -13362,13 +14380,13 @@ const TEST_PLACE: SystemPlace;
13362
14380
 
13363
14381
  const · `import { NO_ASKS } from '@harness/sdk/server/testing'`
13364
14382
 
13365
- `ctx.propose`, `ctx.decide`, `ctx.ai`, `ctx.runs` and `ctx.notify` for a hand-made test context that has no hub:
14383
+ `ctx.propose`, `ctx.decide`, `ctx.ai`, `ctx.runs`, `ctx.notify` and `ctx.store` (none) for a hand-made test context that has no hub:
13366
14384
  proposing and starting runs fail (the test didn't expect them), the decision model is off, notices and kind fns are
13367
14385
  none, and `ctx.ai()` is an aeye `AI` over `FakeModelLink` answering `ok`.
13368
14386
  Spread it in beside `TEST_PLACE`; `FakeHub` serves the real ones.
13369
14387
 
13370
14388
  ```ts
13371
- const NO_ASKS: Proposals & Decisions & Fleets & FnSearch & AiSource & AdminNotices & InstanceConnects & OwnerRuns & RunNotices;
14389
+ const NO_ASKS: Proposals & Decisions & Fleets & FnSearch & AiSource & AdminNotices & ResultUpdates & InstanceConnects & OwnerRuns & RunNotices & { readonly store: undefined };
13372
14390
  ```
13373
14391
 
13374
14392
  #### `HubBody`
@@ -13720,7 +14738,7 @@ function · `import { testHub } from '@harness/sdk/testing'`
13720
14738
  Serve a system to a fake hub in memory and wait until it is ready (connected, configured, its contract imported).
13721
14739
 
13722
14740
  ```ts
13723
- function testHub<N extends string, C extends ContractShape>(contract: SystemContract<N, C>, impl: SystemImpl<C>, options?: TestHubOptions): Promise<TestSystem<N, C>>;
14741
+ function testHub<N extends string, C extends ContractShape, Db extends StoreDb = StoreDb>(contract: SystemContract<N, C>, impl: SystemImpl<C, Db>, options?: TestHubOptions): Promise<TestSystem<N, C>>;
13724
14742
  ```
13725
14743
 
13726
14744
  #### `TestSystem`
@@ -13803,6 +14821,13 @@ interface TestHubOptions {
13803
14821
  readonly serve?: Partial<Omit<ServeOptions, 'hub' | 'state'>>;
13804
14822
  /** Records the hub keeps before the system starts (what a restarted system finds), as stored. */
13805
14823
  readonly records?: readonly DataRecord[];
14824
+ /**
14825
+ * For a system with a store on the hub (`hub: { store: { placement: 'hub' } }`): what answers its store endpoints,
14826
+ * such as the hub's own store host. A store with the system lives in memory unless `host.storeConnect` says where.
14827
+ */
14828
+ readonly stores?: FakeStoreEndpoints;
14829
+ /** More of the link host's seams (`storeConnect`, `now`, …). */
14830
+ readonly host?: Partial<LinkHostDeps>;
13806
14831
  }
13807
14832
  ```
13808
14833
 
@@ -13815,7 +14840,7 @@ function · `import { callFn } from '@harness/sdk/testing'`
13815
14840
  Serve a system, call one fn and stop: the typed result, its progress and what it asked the hub for.
13816
14841
 
13817
14842
  ```ts
13818
- function callFn<N extends string, C extends ContractShape, K extends FnNameOf<C>>(contract: SystemContract<N, C>, impl: SystemImpl<C>, name: K, args: FnArgsOf<C, K>, options?: TestHubOptions): Promise<TestCall<FnResultOf<C, K>>>;
14843
+ function callFn<N extends string, C extends ContractShape, K extends FnNameOf<C>, Db extends StoreDb = StoreDb>(contract: SystemContract<N, C>, impl: SystemImpl<C, Db>, name: K, args: FnArgsOf<C, K>, options?: TestHubOptions): Promise<TestCall<FnResultOf<C, K>>>;
13819
14844
  ```
13820
14845
 
13821
14846
  #### `CallNotDone`
@@ -14491,7 +15516,156 @@ type StoredTypeDecl = TypeDecl & { readonly records: RecordStorage };
14491
15516
 
14492
15517
  Refers to: [`RecordStorage`](#core-recordstorage), [`TypeDecl`](#core-typedecl).
14493
15518
 
14494
- ## 30. Common mistakes
15519
+ #### `FakeStoreEndpoints`
15520
+
15521
+ interface · `import { FakeStoreEndpoints } from '@harness/sdk/server/testing'`
15522
+
15523
+ A store the hub keeps, as the fake hub answers its endpoints (`FakeHub.stores`). The hub's own store host fits it;
15524
+ by default every call is refused, as a hub that keeps no store for the system would.
15525
+
15526
+ ```ts
15527
+ interface FakeStoreEndpoints {
15528
+ open(): Promise<{ bytes: number }>;
15529
+ run(statement: StoreStatement): Promise<StoreResult>;
15530
+ begin(): Promise<StoreLease>;
15531
+ commit(lease: StoreLeaseId): Promise<void>;
15532
+ rollback(lease: StoreLeaseId): Promise<void>;
15533
+ snapshot(): Promise<StoreSnapshotName>;
15534
+ restore(snapshot: StoreSnapshotName): Promise<void>;
15535
+ /** A move from the hub: a whole copy of the store, its size and sha-256. */
15536
+ export?(move: StoreMoveId): Promise<{ bytes: number; hash: string }>;
15537
+ /** A chunk of that copy, base64. */
15538
+ download?(move: StoreMoveId, offset: number, length: number): Promise<{ chunk: string }>;
15539
+ /** A move to the hub: a chunk of the copy, base64. */
15540
+ upload?(move: StoreMoveId, offset: number, chunk: string): Promise<void>;
15541
+ /** The copy is all sent. */
15542
+ uploadDone?(move: StoreMoveId, bytes: number, hash: string): Promise<void>;
15543
+ }
15544
+ ```
15545
+
15546
+ Refers to: [`StoreLease`](#core-storelease), [`StoreLeaseId`](#core-storeleaseid), [`StoreMoveId`](#core-storemoveid), [`StoreResult`](#core-storeresult), [`StoreSnapshotName`](#core-storesnapshotname), [`StoreStatement`](#core-storestatement).
15547
+
15548
+ #### `NO_STORE`
15549
+
15550
+ const · `import { NO_STORE } from '@harness/sdk/server/testing'`
15551
+
15552
+ `ctx.store` for a hand-made test context of a system that declares a store, when the code under test never touches
15553
+ it: every statement is refused, saying so. Spread it in beside `NO_ASKS` (`{ ...NO_ASKS, store: NO_STORE }`).
15554
+
15555
+ ```ts
15556
+ const NO_STORE: SystemStore<StoreDb>;
15557
+ ```
15558
+
15559
+ #### `testStore`
15560
+
15561
+ function · `import { testStore } from '@harness/sdk/server/testing'`
15562
+
15563
+ A store for a unit test without a hub: SQLite in memory (or a real file in `dir`), migrated with `migrations`, as
15564
+ `ctx.store` would be. Close it when the test is done.
15565
+
15566
+ ```ts
15567
+ function testStore(migrations: readonly Migration[], options?: { readonly dir?: string; }): Promise<{ readonly store: SystemStore<StoreDb>; close(): Promise<void>; }>;
15568
+ ```
15569
+
15570
+ #### `localStoreConnect`
15571
+
15572
+ function · `import { localStoreConnect } from '@harness/sdk/server/testing'`
15573
+
15574
+ A `LinkHostDeps.storeConnect` that keeps a store with the system as a real SQLite file in `dir` (`<dir>/store/store.db`).
15575
+
15576
+ ```ts
15577
+ function localStoreConnect(dir: string, now?: () => number): () => Promise<StoreConnection>;
15578
+ ```
15579
+
15580
+ #### `openMemoryStore`
15581
+
15582
+ function · `import { openMemoryStore } from '@harness/sdk/server/testing'`
15583
+
15584
+ A store with the system held in memory (SQLite `:memory:` with sqlite-vec), for tests: gone once it closes. It is
15585
+ measured like a file (its size is its pages), but a move refuses it: there is no file to copy, and closing it for the
15586
+ copy would lose it.
15587
+
15588
+ ```ts
15589
+ function openMemoryStore(): Promise<StoreConnection>;
15590
+ ```
15591
+
15592
+ #### `StoreConnection`
15593
+
15594
+ interface · `import { StoreConnection } from '@harness/sdk/server/testing'`
15595
+
15596
+ An open store connection: Kysely over it, where its tables are, and what its engine can do besides.
15597
+
15598
+ ```ts
15599
+ interface StoreConnection {
15600
+ readonly db: AnyKysely;
15601
+ readonly place: StorePlace;
15602
+ readonly plugin: PortablePlugin;
15603
+ /** Set on a store held in memory (a test's): it has no file, so it is measured but can't be moved. */
15604
+ readonly memory?: true;
15605
+ /** Copy the store aside before migrations (SQLite only); returns the snapshot's name. */
15606
+ snapshot?(): Promise<string>;
15607
+ /** Count its tables' rows (and size a SQLite file) for the Storage panel; absent on the hub, which measures it itself. */
15608
+ measure?(now: number): Promise<StoreMeasure>;
15609
+ /**
15610
+ * Fold a SQLite file's write-ahead log into the file itself and empty the log (`wal_checkpoint(TRUNCATE)`), so a
15611
+ * copy of the data folder taken now has the whole store in `store.db`, with or without its `-wal`. Only a store with
15612
+ * the system has one: the hub's file is the hub's, and an external database isn't in the folder.
15613
+ */
15614
+ checkpoint?(): Promise<void>;
15615
+ /** Put a snapshot back in place of the store; the connection is closed by then and must not be used again. */
15616
+ restore?(snapshot: string): Promise<void>;
15617
+ close(): Promise<void>;
15618
+ }
15619
+ ```
15620
+
15621
+ Refers to: [`StoreMeasure`](#core-storemeasure).
15622
+
15623
+ #### `WORK_BACKEND_CHECKS`
15624
+
15625
+ const · `import { WORK_BACKEND_CHECKS } from '@harness/sdk/server/testing'`
15626
+
15627
+ ```ts
15628
+ const WORK_BACKEND_CHECKS: readonly WorkBackendCheck[];
15629
+ ```
15630
+
15631
+ #### `WorkBackendCheck`
15632
+
15633
+ interface · `import { WorkBackendCheck } from '@harness/sdk/server/testing'`
15634
+
15635
+ One check: its name, and the run that throws when the backend gets it wrong.
15636
+
15637
+ ```ts
15638
+ interface WorkBackendCheck {
15639
+ readonly name: string;
15640
+ run(make: WorkBackendMaker): Promise<void>;
15641
+ }
15642
+ ```
15643
+
15644
+ #### `WorkBackendMaker`
15645
+
15646
+ type · `import { WorkBackendMaker } from '@harness/sdk/server/testing'`
15647
+
15648
+ Makes a backend over the store under test: a check passes its clock, queue name and options.
15649
+
15650
+ ```ts
15651
+ type WorkBackendMaker = (options: StoreWorkOptions) => StoreWorkBackend | Promise<StoreWorkBackend>;
15652
+ ```
15653
+
15654
+ #### `CheckClock`
15655
+
15656
+ class · `import { CheckClock } from '@harness/sdk/server/testing'`
15657
+
15658
+ A clock a check moves by hand.
15659
+
15660
+ ```ts
15661
+ class CheckClock {
15662
+ t: number;
15663
+ readonly now: () => number;
15664
+ advance(ms: number): void;
15665
+ }
15666
+ ```
15667
+
15668
+ ## 31. Common mistakes
14495
15669
 
14496
15670
  ### Mistakes the compiler refuses
14497
15671
 
@@ -14922,7 +16096,8 @@ reason given. If you see one of these errors, the fix is in the reason.
14922
16096
  - **Keeping data in the system.** Notes, tasks, contacts, anything kept for people or looked up later, are records of a
14923
16097
  stored type (`type({ records })`, `ctx.data`), so the hub checks, versions, shares and searches them. A JSON file or
14924
16098
  a SQLite database in `ctx.dataDir` is invisible to the hub: no search, no Data page, no widgets, no access rules.
14925
- `ctx.dataDir` is for the system's own keys, caches and working copies.
16099
+ `ctx.dataDir` is for the system's own keys, caches and working copies; tables only its code reads (a queue, an
16100
+ index) go in its store (`store()`, `ctx.store`), which the hub places, migrates, backs up and moves.
14926
16101
  - **Loading everything to filter it.** `ctx.data.find` with `filters`, `sort`, `limit` and `search` runs in the hub's
14927
16102
  database; a loop over every record (or `limit: 200` and a filter in code) doesn't scale and misses pages. Walk many
14928
16103
  records a page at a time with `cursor`.
@@ -14939,7 +16114,7 @@ reason given. If you see one of these errors, the fix is in the reason.
14939
16114
  - **Vague descriptions.** The LLM picks fns by their description and fills args from their types and docs: say exactly
14940
16115
  what the fn does and give examples for args that are easy to get wrong.
14941
16116
 
14942
- ## 31. Worked examples
16117
+ ## 32. Worked examples
14943
16118
 
14944
16119
  ### The notes system, whole
14945
16120
 
@@ -15983,6 +17158,12 @@ export const notes = system('notes', {
15983
17158
  description: 'How to keep notes here: search before adding, short titles, lowercase tags.',
15984
17159
  content: 'Search with notes/find before adding a note, so you do not add one twice. Keep titles short and tags lowercase.',
15985
17160
  fns: [fns.find, fns.add],
17161
+ // the one question it answers (searches compare with it) and when a model should read it
17162
+ question: 'How should notes be added and tagged here?',
17163
+ when: 'When adding, titling or tagging a note.',
17164
+ // when its text last changed, and who would ask it: a system's own guide is asked by `system`
17165
+ lastModified: Date.parse('2026-11-28'),
17166
+ askedBy: 'system',
15986
17167
  // for the graph contextor: how much it counts, a short form for tight budgets, and what it relates to
15987
17168
  weight: 1.2,
15988
17169
  summary: 'Search before adding; short titles; lowercase tags.',
@@ -16093,7 +17274,7 @@ The fs system (`systems/fs`) gives agents files and a shell over chosen folders.
16093
17274
  real system's declarations: a named type with a method, a setting, an attachment, fns with status words, undo, state,
16094
17275
  progress and handlers, a hook, a mention provider, static and dynamic context, and an agent.
16095
17276
 
16096
- #### `systems/fs/shared/index.ts`, lines 1-189
17277
+ #### `systems/fs/shared/index.ts`, lines 1-178
16097
17278
 
16098
17279
  ```ts
16099
17280
  /**
@@ -16103,10 +17284,13 @@ progress and handlers, a hook, a mention provider, static and dynamic context, a
16103
17284
  * implements it and its client draws it.
16104
17285
  */
16105
17286
  import { ChangeSet, SensitivityRule } from '@harness/core';
16106
- import { type Infer, type ValueOf, agent, agents, arg, attachment, context, fn, ginAs, g, handler, hook, hub, linear, mention, setting, system, type } from '@harness/sdk';
17287
+ import { type Infer, type ValueOf, agent, agents, arg, attachment, context, fn, ginAs, g, handler, hook, hub, linear, mention, setting, store, system, type } from '@harness/sdk';
17288
+ import { FILES_PAGE_FNS } from './files-page.ts';
16107
17289
  import { HostedState, HostedStatus, InstallArgs, InstallResult, RestartArgs, StatusArgs, StopArgs, StopResult } from './hosting.ts';
17290
+ import { MACHINES_PAGE, MachineNow, MachineNowArgs, MetricsConfig, MetricsList, MetricsRead, MetricsReadArgs, TopProcesses } from './metrics.ts';
16108
17291
 
16109
17292
  export * from './hosting.ts';
17293
+ export * from './metrics.ts';
16110
17294
 
16111
17295
  /** A file or folder under one of the roots. */
16112
17296
  export const Entry = type({
@@ -16188,6 +17372,8 @@ export const fs = system('fs', {
16188
17372
  'Its fns read, list and search files (fs/read, fs/list, fs/glob, fs/grep), change them (fs/write, fs/edit, fs/remove: each may ask the person first, and each can be undone) and run bash commands (fs/bash, fs/cd).',
16189
17373
  'Reach for it to look at or change the person\'s files, and to keep a lasting document they can open later (a note, a list, a summary) as a markdown file. It defines no fn kinds.',
16190
17374
  'A file the person attached to a chat message is not an fs file: it is a hub resource, read with the hub\'s resource fns. Its fns for installing and hosting systems (fs/install_system, fs/system_status, fs/restart_system, fs/stop_system, fs/restart) are for admins and system authors.',
17375
+ 'People leave comments on files (on lines, selected text or marked areas of pictures) from the Files tab of the Machines page: fs/commented_files lists the files with comments, fs/comments and fs/comment read them, fs/comment_reply and fs/comment_resolve answer them.',
17376
+ 'When an admin turned on recording, it also says what its machine is doing (fs/machine_now, fs/metrics_list, fs/metrics_read: CPU, memory, drives, network, disk and GPU over time, and fs/processes for admins).',
16191
17377
  'Load its guide (fs/guide) before the first file change.',
16192
17378
  ].join(' '),
16193
17379
  // its authoring agents use models; installs wait for an admin and pair what they start; it keeps each person's cwd,
@@ -16198,9 +17384,14 @@ export const fs = system('fs', {
16198
17384
  { name: 'files', title: 'Files', description: 'Read, write, edit, delete and search files under the roots, and ask questions about the code.' },
16199
17385
  { name: 'shell', title: 'Shell', description: 'Run commands (builds, tests, git) in a working folder; each command lists the files it changed.' },
16200
17386
  { name: 'systems', title: 'Systems', description: 'Install, check, restart and stop the systems this machine hosts, and restart fs itself.' },
17387
+ { name: 'machine', title: 'Machine', description: 'What this machine is doing: CPU, memory, drives, network, disk, GPU and its busiest processes, now and over time.' },
16201
17388
  ],
17389
+ // the Machines page: pick one of the connected fs machines, then its metrics or its files (client/MachinesPage.vue)
17390
+ pages: [{ segment: MACHINES_PAGE, title: 'Machines', description: 'Each connected machine: its CPU, memory, drives, network, disk and GPU over time, and its files.', icon: 'monitor', nav: 'main', component: 'MachinesPage' }],
16202
17391
  })
16203
17392
  .with({
17393
+ // the undo snapshots' index; the copies themselves stay files in its data folder
17394
+ store: store({ description: 'The undo snapshots\' index: which file each kept copy was taken of, when, and its size. The copies stay files in its data folder.' }),
16204
17395
  // set by an admin in the hub; the server gets it typed when it starts
16205
17396
  config: g.obj({
16206
17397
  // the folders it serves and works in; nothing outside them is reachable
@@ -16219,6 +17410,8 @@ export const fs = system('fs', {
16219
17410
  commandEnv: g.field(g.optional(g.list(g.text({ minLength: 1 }))), { docs: 'Env variables commands also get, by name. Others are never passed on.' }),
16220
17411
  // how many undo copies fs keeps (server/snapshots.ts); left out: SNAPSHOT_DEFAULTS
16221
17412
  snapshots: g.field(g.optional(SnapshotLimits), { docs: 'How many undo copies to keep per file, and how much space they may use in all.' }),
17413
+ // whether this machine records its metrics into the store (server/metrics/); left out: it doesn't
17414
+ metrics: g.field(g.optional(MetricsConfig), { docs: 'Record this machine\'s metrics (CPU, memory, drives, network, disk, GPU, busiest processes) for the Machines page and the metrics fns.' }),
16222
17415
  }),
16223
17416
  types: { Entry },
16224
17417
  settings: {
@@ -16262,6 +17455,11 @@ export const fs = system('fs', {
16262
17455
  effects: { mode: 'write', free: true },
16263
17456
  // the hub asks which sensitive files a call touches first (server/sensitive.ts)
16264
17457
  flags: true,
17458
+ ```
17459
+
17460
+ #### `systems/fs/shared/index.ts`, lines 179-382
17461
+
17462
+ ```ts
16265
17463
  args: g.obj({ path: path(), text: hub.types.LongText }),
16266
17464
  // two changes to one file in the same step run in the model's order (server/impl.ts fileClaims)
16267
17465
  dynamicClaims: true,
@@ -16285,11 +17483,6 @@ export const fs = system('fs', {
16285
17483
  effects: { mode: 'write', free: true },
16286
17484
  // the hub asks which sensitive files a call touches first (server/sensitive.ts)
16287
17485
  flags: true,
16288
- ```
16289
-
16290
- #### `systems/fs/shared/index.ts`, lines 190-370
16291
-
16292
- ```ts
16293
17486
  args: g.obj({ path: path(), find: g.text({ minLength: 1 }), replace: g.text(), all: g.optional(g.bool()) }),
16294
17487
  // two changes to one file in the same step run in the model's order (server/impl.ts fileClaims)
16295
17488
  dynamicClaims: true,
@@ -16473,7 +17666,7 @@ export const fs = system('fs', {
16473
17666
  }),
16474
17667
  ```
16475
17668
 
16476
- #### `systems/fs/shared/index.ts`, lines 371-533
17669
+ #### `systems/fs/shared/index.ts`, lines 383-567
16477
17670
 
16478
17671
  ```ts
16479
17672
  system_status: fn({
@@ -16526,6 +17719,99 @@ export const fs = system('fs', {
16526
17719
  },
16527
17720
  tags: ['systems'],
16528
17721
  }),
17722
+ metrics_list: fn({
17723
+ group: 'machine',
17724
+ description: 'The metrics this machine records (CPU, memory, drives, network, disk, GPU), each with its unit and the time span it holds, and the machine itself.',
17725
+ instructions: 'Call it first to learn the metric names before fs/metrics_read: they are `cpu` (all cores) and `cpu.<n>` (each core), `memory`, `drive.<name>.free`, `net.<adapter>.rx` and `.tx`, `disk.read` and `disk.write`, `gpu.<n>.use`, `.memory`, `.temp` and `.power`, and `processes`. `recording: false` means the machine records nothing new (an admin turns it on in this fs\'s config); what it recorded before is still listed. `from` and `to` say how far back each metric goes.',
17726
+ examples: [
17727
+ {
17728
+ args: {},
17729
+ result: {
17730
+ recording: true,
17731
+ machine: { hostname: 'studio', platform: 'win32', cpuModel: 'AMD Ryzen 9 7950X', cores: 32, memory: 68_719_476_736, uptime: 86_400 },
17732
+ syncEvery: 60_000,
17733
+ metrics: [{ name: 'cpu', label: 'CPU, all cores', unit: 'percent', from: new Date('2026-11-01T00:00:00Z'), to: new Date('2026-11-28T12:00:00Z') }],
17734
+ },
17735
+ note: 'One metric shown; a machine lists dozens.',
17736
+ },
17737
+ ],
17738
+ effects: { mode: 'read', free: true },
17739
+ args: g.obj({}),
17740
+ returns: MetricsList,
17741
+ status: {
17742
+ active: { one: 'Listing the machine\'s metrics…', many: 'Listing metrics on {n} machines…' },
17743
+ retry: { one: 'Retrying the metrics list…', many: 'Retrying {n} metrics lists…' },
17744
+ done: { one: 'Listed the machine\'s metrics', many: 'Listed metrics on {n} machines' },
17745
+ failed: { one: 'Listing the metrics failed', many: '{n} metrics lists failed' },
17746
+ },
17747
+ tags: ['read', 'machine'],
17748
+ }),
17749
+ metrics_read: fn({
17750
+ group: 'machine',
17751
+ description: 'Read metrics of this machine over a timeframe: each metric\'s average and maximum per point, with the seconds between points.',
17752
+ instructions: 'Name metrics from fs/metrics_list; a trailing `*` takes every metric that starts with what comes before it (`cpu.*` is every core, `net.*` every adapter, `gpu.0.*` all of the first GPU). Give the timeframe as `last` (`30m`, `6h`, `7d`, `1y`) or as `from` and `to`. The step follows the timeframe (5 seconds within the last hour, a minute within 2 days, 10 minutes within 31 days, an hour beyond), and `points` caps how many points each metric gets. `null` in `avg` and `max` means nothing was recorded then (the machine was off or not recording). Units: percent, bytes, bytes/s, celsius, watts, count.',
17753
+ examples: [
17754
+ { args: { metrics: ['cpu', 'memory'], last: '6h' }, note: 'CPU and memory over the last six hours.' },
17755
+ { args: { metrics: ['cpu.*'], last: '1h', points: 60 }, note: 'Each core over the last hour, one point a minute.' },
17756
+ {
17757
+ args: { metrics: ['gpu.0.temp'], from: new Date('2026-11-27T00:00:00Z'), to: new Date('2026-11-28T00:00:00Z'), points: 24 },
17758
+ result: { step: 3600, from: new Date('2026-11-27T00:00:00Z'), to: new Date('2026-11-28T00:00:00Z'), series: new Map([['gpu.0.temp', { unit: 'celsius' as const, start: new Date('2026-11-27T00:00:00Z'), avg: [41, 43, null], max: [55, 61, null] }]]) },
17759
+ note: 'One day, a point an hour (cut to three points here); the null is an hour nothing was recorded.',
17760
+ },
17761
+ ],
17762
+ effects: { mode: 'read', free: true },
17763
+ args: MetricsReadArgs,
17764
+ returns: MetricsRead,
17765
+ status: {
17766
+ active: { one: 'Reading the machine\'s metrics…', many: 'Reading metrics on {n} machines…' },
17767
+ retry: { one: 'Retrying the metrics read…', many: 'Retrying {n} metrics reads…' },
17768
+ done: { one: 'Read the machine\'s metrics', many: 'Read metrics on {n} machines' },
17769
+ failed: { one: 'Reading the metrics failed', many: '{n} metrics reads failed' },
17770
+ },
17771
+ tags: ['read', 'machine'],
17772
+ }),
17773
+ machine_now: fn({
17774
+ group: 'machine',
17775
+ description: 'What this machine is doing now: its latest sample of CPU (in total and per core), memory, drives, network, disk and GPU.',
17776
+ instructions: 'Use it for "how busy is it right now" questions; for how it went over time use fs/metrics_read, and for which programs are busy fs/processes. `recording: false` means the machine records no metrics, so there is no sample. Network and disk are bytes per second; CPU and GPU use are percent.',
17777
+ examples: [
17778
+ { args: {}, note: 'The latest sample.' },
17779
+ { args: { since: new Date('2026-11-28T12:00:00Z') }, note: 'Also every sample taken since then, from the last few minutes.' },
17780
+ ],
17781
+ effects: { mode: 'read', free: true },
17782
+ args: MachineNowArgs,
17783
+ returns: MachineNow,
17784
+ status: {
17785
+ active: { one: 'Looking at the machine…', many: 'Looking at {n} machines…' },
17786
+ retry: { one: 'Looking at the machine again…', many: 'Looking at {n} machines again…' },
17787
+ done: { one: 'Looked at the machine', many: 'Looked at {n} machines' },
17788
+ failed: { one: 'Looking at the machine failed', many: '{n} machine looks failed' },
17789
+ },
17790
+ tags: ['read', 'machine'],
17791
+ }),
17792
+ processes: fn({
17793
+ group: 'machine',
17794
+ description: 'The busiest processes on this machine now: the 15 using the most CPU and the 15 using the most memory, with their ids. For admins.',
17795
+ instructions: 'Use it to find which program makes the machine busy or uses its memory. CPU is % of one core, so a process using several cores passes 100. It works only while the machine records metrics; the list is at most a few seconds old (`at`).',
17796
+ examples: [
17797
+ {
17798
+ args: {},
17799
+ result: { at: new Date('2026-11-28T12:00:05Z'), count: 312, byCpu: [{ pid: 4120, name: 'node', cpu: 87.5, memory: 412_000_000 }], byMemory: [{ pid: 9001, name: 'chrome', cpu: 3.1, memory: 1_800_000_000 }] },
17800
+ note: 'One process of each list shown.',
17801
+ },
17802
+ ],
17803
+ effects: { mode: 'read', free: true },
17804
+ args: g.obj({}),
17805
+ returns: TopProcesses,
17806
+ status: {
17807
+ active: { one: 'Listing the busiest processes…', many: 'Listing processes on {n} machines…' },
17808
+ retry: { one: 'Retrying the process list…', many: 'Retrying {n} process lists…' },
17809
+ done: { one: 'Listed the busiest processes', many: 'Listed processes on {n} machines' },
17810
+ failed: { one: 'Listing the processes failed', many: '{n} process lists failed' },
17811
+ },
17812
+ // only admins see and run it (the hub's ADMIN_TAG): process names and ids say what everyone on the machine runs
17813
+ tags: ['admin', 'read', 'machine'],
17814
+ }),
16529
17815
  },
16530
17816
  hooks: {
16531
17817
  git: hook({
@@ -16544,27 +17830,44 @@ export const fs = system('fs', {
16544
17830
  files: mention({ title: 'Files', description: 'Files and folders under the roots.', target: FileTarget, of: types.Entry }),
16545
17831
  },
16546
17832
  context: {
17833
+ // the guide is one question that brings its answers: each step is an item of its own in `context/guide/`
17834
+ // (one question each), imported so loading the guide loads them all
16547
17835
  guide: context({
16548
17836
  description: 'How to work with the person\'s files: find, read, then change; keeping notes and lists as files; running commands.',
17837
+ question: 'How do I work with the person\'s files?',
17838
+ when: 'When a request involves the person\'s files or folders in any way: finding, reading, changing, keeping a document, or running a command, and before the first change.',
17839
+ lastModified: Date.parse('2026-11-28'),
17840
+ askedBy: 'system',
16549
17841
  content: [
16550
- 'The fs system works only inside the folders an admin chose (its roots). Paths are relative to the first root (`notes/todo.md`), or start with a root\'s name when there are several; `/` is outside the roots and is refused. Start with fs/list on `.` to see the first root.',
16551
- '',
16552
- 'To find something: fs/glob finds files by name (`*.md`, `notes/**`), fs/grep finds lines inside files by a regular expression (case-sensitive; write `[Rr]eport` for either case, never `(?i)`), fs/list shows one folder. Don\'t guess a path: look first. When the request is about when files are from ("this year\'s", "the newest"), list the folder: fs/list gives every file with its modified time, which a search by meaning doesn\'t.',
16553
- 'To read: fs/read, a window at a time for long files (`offset`, `limit`). Say only what you read. fs/read reads text only: read a pdf or other document with hub/resource_read, and look at a picture (or a pdf page with no text) with hub/resource_send, each by the file\'s `file://` uri (as fs/list gives its path).',
16554
- 'To change: fs/edit replaces exact text (copy `find` from what fs/read gave, spaces included); fs/write writes a whole new file; fs/remove deletes one file. Each may ask the person first, and each can be undone with the turn.',
16555
- 'To keep a document for the person (a list, a summary, notes from this chat): write a markdown file, for example fs/write with {"path":"notes/ideas.md","text":"# Ideas\\n\\n- First idea\\n- Second idea\\n"}, then tell them the path. Check the result (`created`) before saying it is saved.',
16556
- 'To run a program, a build, tests or git: fs/bash runs a bash command (not PowerShell); set the folder once with fs/cd. Check `exitCode`: anything but 0 means the command failed. A command your shell setting does not mark safe asks the person first, and what it changes can\'t be undone.',
17842
+ 'The fs system works only inside the folders an admin chose (its roots). Work in this order: look, read, then change, and check each result before saying it is done. Each step answers one question, and loads with this guide:',
16557
17843
  '',
16558
- 'A file the person attached to a chat message is a hub resource, not an fs file: read it with hub/resource_read or look at it with hub/resource_send, not fs/read.',
17844
+ '- How do I write a path for the files system? (fs/guide.paths)',
17845
+ '- How do I find a file or a line in the person\'s files? (fs/guide.find)',
17846
+ '- How do I read one of the person\'s files? (fs/guide.read)',
17847
+ '- How do I change one of the person\'s files? (fs/guide.change)',
17848
+ '- How do I keep a note, a list or a summary for the person as a file? (fs/guide.documents)',
17849
+ '- How do I run a command, a build, tests or git on the person\'s machine? (fs/guide.commands)',
17850
+ '- How do I read a file the person attached to a chat message? (fs/guide.attachments)',
16559
17851
  ].join('\n'),
17852
+ imports: ['paths', 'find', 'read', 'change', 'documents', 'commands', 'attachments'].map((step) => ({ ref: 'context' as const, name: `fs/guide.${step}` as const })),
16560
17853
  // the guide brings the fns it is about, so finding it finds them
16561
17854
  fns: [fns.read, fns.list, fns.glob, fns.grep, fns.edit, fns.write, fns.bash, fns.cd, fns.remove],
16562
17855
  }),
16563
17856
  // what every chat agent is told about files, in its system prompt (plan injected-context, section 5)
17857
+ ```
17858
+
17859
+ #### `systems/fs/shared/index.ts`, lines 568-660
17860
+
17861
+ ```ts
16564
17862
  basics: context({
16565
17863
  title: 'Files',
16566
17864
  description: 'Where the files system works (its roots), how paths are written, what can be undone, and that an attached file is not one of its files.',
16567
17865
  summary: 'The files system works only in folders an admin chose: paths are relative to the first root, never `/`. Load fs/guide first.',
17866
+ // it sits in every chat agent's prompt, so its one question is the least a model must know about files
17867
+ question: 'What must every chat agent know before it touches the person\'s files?',
17868
+ when: 'Always, in every chat: it is in each chat agent\'s system prompt, so a model knows where the files system works before any request about files.',
17869
+ lastModified: Date.parse('2026-11-28'),
17870
+ askedBy: 'system',
16568
17871
  content: [
16569
17872
  'The **files system** (`fs`) works only inside a few folders of the person\'s machine an admin chose (its roots). Paths are relative to the first root (`notes/todo.md`) or start with a root\'s name; `/` is outside the roots and is refused. Look before you guess a path: fs/list on `.` shows the first root, fs/glob finds files by name, and fs/read reads one.',
16570
17873
  'fs/write, fs/edit and fs/remove may ask the person first, and what they change can be undone with the turn; what fs/bash changes can\'t. To keep a document for the person (a note, a list, a summary), write a markdown file and tell them its path.',
@@ -16575,12 +17878,20 @@ export const fs = system('fs', {
16575
17878
  }),
16576
17879
  tree: context({
16577
17880
  description: 'The folder tree of a root, as it is now.',
17881
+ question: 'What does the folder tree of the person\'s roots look like right now?',
17882
+ when: 'When the person runs /tree, or the work needs the layout of a root at a glance before finding or changing files.',
17883
+ lastModified: Date.parse('2026-11-28'),
17884
+ askedBy: 'system',
16578
17885
  command: { name: 'tree', args: { root: arg('Which root (default: all)', { required: false }) } },
16579
17886
  }),
16580
17887
  // the start of writing a system: it loads the guide's index (`context/authoring/`, a graph of the SDK guide) with
16581
17888
  // it, and says where the template is on this machine, with the fns to write and install a system
16582
17889
  'system-authoring': context({
16583
17890
  description: 'How to write and install a harness system: the index of its guide, where the template system is, and how to copy it.',
17891
+ question: 'How do I start writing a new harness system on this machine?',
17892
+ when: 'When the person runs /new-system or asks to make a new harness system (fns, types, context and screens the hub adds), before reading the guide\'s parts.',
17893
+ lastModified: Date.parse('2026-11-28'),
17894
+ askedBy: 'system',
16584
17895
  command: { name: 'new-system' },
16585
17896
  imports: [{ ref: 'context', name: 'fs/authoring' }],
16586
17897
  fns: [fns.read, fns.write, fns.edit, fns.bash, fns.install_system, fns.system_status],
@@ -16616,7 +17927,9 @@ export const fs = system('fs', {
16616
17927
  context: [ctx.guide],
16617
17928
  }),
16618
17929
  },
16619
- }));
17930
+ }))
17931
+ // the Machines page's Files tab: browsing, git and comments (`files-page.ts`)
17932
+ .with({ fns: FILES_PAGE_FNS });
16620
17933
 
16621
17934
  /** The fs contract's type. */
16622
17935
  export type FsContract = typeof fs;
@@ -16641,7 +17954,7 @@ export type PreviousValue = Infer<typeof Previous>;
16641
17954
  export type BashOutput = Infer<typeof BashResult>;
16642
17955
  ```
16643
17956
 
16644
- ## 32. Runtime internals
17957
+ ## 33. Runtime internals
16645
17958
 
16646
17959
  The rest of what the SDK exports: the pieces `serve` is built from (the manifest builder, keys, the outcome journal, the
16647
17960
  link transport, the LLM wire, the MCP face, files and process control, client bundles). A system rarely uses these
@@ -18244,7 +19557,48 @@ interface RedirectProblems {
18244
19557
  }
18245
19558
  ```
18246
19559
 
18247
- ## 33. Core types
19560
+ #### `localStorePaths`
19561
+
19562
+ function · `import { localStorePaths } from '@harness/sdk/server'`
19563
+
19564
+ Where a store with the system keeps its files, in the instance's data folder.
19565
+
19566
+ ```ts
19567
+ function localStorePaths(dataDir: string): LocalStorePaths;
19568
+ ```
19569
+
19570
+ #### `LocalStorePaths`
19571
+
19572
+ interface · `import { LocalStorePaths } from '@harness/sdk/server'`
19573
+
19574
+ Where a store with the system keeps its files, in the instance's data folder.
19575
+
19576
+ ```ts
19577
+ interface LocalStorePaths {
19578
+ /** `<data>/store`: everything of the store's, so deleting the store is deleting this folder. */
19579
+ readonly dir: string;
19580
+ /** The store's file. */
19581
+ readonly file: string;
19582
+ /** Copies made before migrations run. */
19583
+ readonly snapshots: string;
19584
+ /** Old copies a move left behind, kept until the admin deletes them. */
19585
+ readonly backups: string;
19586
+ /** Where a move builds and receives copies; emptied when it ends. */
19587
+ readonly moving: string;
19588
+ }
19589
+ ```
19590
+
19591
+ #### `fileHash`
19592
+
19593
+ function · `import { fileHash } from '@harness/sdk/server'`
19594
+
19595
+ The sha-256 of a file, hex.
19596
+
19597
+ ```ts
19598
+ function fileHash(file: string): Promise<string>;
19599
+ ```
19600
+
19601
+ ## 34. Core types
18248
19602
 
18249
19603
  The wire shapes from `@harness/core` that the SDK's declarations refer to, each resolved to plain TypeScript. Each is a
18250
19604
  zod schema in core with its type inferred from it; import the type (and the schema, to parse) from `@harness/core`.
@@ -18293,7 +19647,7 @@ type HubModelInfo = {
18293
19647
  name: string;
18294
19648
  capabilities: string[];
18295
19649
  tier: "flagship" | "efficient" | "legacy" | "experimental";
18296
- roles: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[];
19650
+ roles: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[];
18297
19651
  contextWindow?: number | undefined;
18298
19652
  pricing?: {
18299
19653
  input: number;
@@ -18416,7 +19770,7 @@ type ApprovalPreview = {
18416
19770
  grants?: {
18417
19771
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
18418
19772
  models?: {
18419
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
19773
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
18420
19774
  models?: string[] | undefined;
18421
19775
  perRun?: number | undefined;
18422
19776
  perDay?: number | undefined;
@@ -18492,8 +19846,8 @@ type ApprovalPreview = {
18492
19846
  lead?: string | undefined;
18493
19847
  tail?: string | undefined;
18494
19848
  }[];
18495
- grants?: "added" | "changed" | "widened" | "narrowed" | undefined;
18496
- config?: "removed" | "added" | "changed" | undefined;
19849
+ grants?: "changed" | "added" | "widened" | "narrowed" | undefined;
19850
+ config?: "changed" | "removed" | "added" | undefined;
18497
19851
  } | undefined;
18498
19852
  };
18499
19853
  ```
@@ -18593,7 +19947,7 @@ type ApprovedRun = {
18593
19947
  grants?: {
18594
19948
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
18595
19949
  models?: {
18596
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
19950
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
18597
19951
  models?: string[] | undefined;
18598
19952
  perRun?: number | undefined;
18599
19953
  perDay?: number | undefined;
@@ -18669,8 +20023,8 @@ type ApprovedRun = {
18669
20023
  lead?: string | undefined;
18670
20024
  tail?: string | undefined;
18671
20025
  }[];
18672
- grants?: "added" | "changed" | "widened" | "narrowed" | undefined;
18673
- config?: "removed" | "added" | "changed" | undefined;
20026
+ grants?: "changed" | "added" | "widened" | "narrowed" | undefined;
20027
+ config?: "changed" | "removed" | "added" | undefined;
18674
20028
  } | undefined;
18675
20029
  };
18676
20030
  };
@@ -18744,7 +20098,7 @@ type PairingGrantRequest = {
18744
20098
  grants?: {
18745
20099
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
18746
20100
  models?: {
18747
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
20101
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
18748
20102
  models?: string[] | undefined;
18749
20103
  perRun?: number | undefined;
18750
20104
  perDay?: number | undefined;
@@ -19063,6 +20417,7 @@ type ContextFileHeader = {
19063
20417
  suggest: "user" | "llm" | "none" | "both";
19064
20418
  visible: "user" | "llm" | "none" | "both";
19065
20419
  tags: string[];
20420
+ when?: string | undefined;
19066
20421
  title?: string | undefined;
19067
20422
  links?: {
19068
20423
  to: {
@@ -19083,8 +20438,10 @@ type ContextFileHeader = {
19083
20438
  weight: number;
19084
20439
  }[] | undefined;
19085
20440
  weight?: number | undefined;
20441
+ question?: string | undefined;
19086
20442
  niche?: "admin" | "developer" | "reference" | undefined;
19087
20443
  next?: `${string}/${string}` | undefined;
20444
+ askedBy?: "person" | "system" | "research" | undefined;
19088
20445
  inject?: {
19089
20446
  into: string[];
19090
20447
  order: number;
@@ -19105,6 +20462,7 @@ type ContextFileHeader = {
19105
20462
  to: `${string}/${string}`;
19106
20463
  when: string;
19107
20464
  }[] | undefined;
20465
+ lastModified?: number | undefined;
19108
20466
  };
19109
20467
  ```
19110
20468
 
@@ -19142,6 +20500,16 @@ const, type · declared in `packages/core/src/context-graph.ts`
19142
20500
  type DeclarableRelation = "next" | "about" | "parent" | "imports" | "brings" | "suggests" | "related";
19143
20501
  ```
19144
20502
 
20503
+ ### From `packages/core/src/context-questions.ts`
20504
+
20505
+ #### <a id="core-contextaskedby"></a>`ContextAskedBy`
20506
+
20507
+ const, type · declared in `packages/core/src/context-questions.ts`
20508
+
20509
+ ```ts
20510
+ type ContextAskedBy = "person" | "system" | "research";
20511
+ ```
20512
+
19145
20513
  ### From `packages/core/src/data.ts`
19146
20514
 
19147
20515
  #### <a id="core-datarecord"></a>`DataRecord`
@@ -19530,6 +20898,10 @@ type FnSearchPage = {
19530
20898
  path: string[];
19531
20899
  title: string;
19532
20900
  } | undefined;
20901
+ question?: string | undefined;
20902
+ answer?: string | undefined;
20903
+ status?: "active" | "hidden" | "not_applicable" | "pending_approval" | "pending_removal" | "pending_plan" | undefined;
20904
+ statusReason?: string | undefined;
19533
20905
  niche?: "admin" | "developer" | "reference" | undefined;
19534
20906
  blocked?: {
19535
20907
  code: "paused" | "system-needs-config" | "system-disconnected" | "system-removed" | "kind-missing" | "kind-system-disconnected" | "dep-unavailable" | "disabled" | "held" | "role-unset" | "no-such-fn" | "not-a-name" | "other-system" | "not-for-model" | "connect-account";
@@ -19614,6 +20986,9 @@ type FnSearchQuery = {
19614
20986
  op: "empty" | "notEmpty";
19615
20987
  })[] | undefined;
19616
20988
  off?: boolean | undefined;
20989
+ statuses?: ("active" | "hidden" | "not_applicable" | "pending_approval" | "pending_removal")[] | undefined;
20990
+ returnNotApplicable?: boolean | undefined;
20991
+ semanticOver?: "question" | "content" | undefined;
19617
20992
  scopes?: ("user" | "session" | "everyone")[] | undefined;
19618
20993
  available?: boolean | undefined;
19619
20994
  niches?: ("admin" | "developer" | "reference")[] | undefined;
@@ -19681,7 +21056,7 @@ grants gets the base only. The hub refuses (and logs as a `RefusalRecord`) anyth
19681
21056
  type SystemGrants = {
19682
21057
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
19683
21058
  models?: {
19684
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
21059
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
19685
21060
  models?: string[] | undefined;
19686
21061
  perRun?: number | undefined;
19687
21062
  perDay?: number | undefined;
@@ -19815,7 +21190,7 @@ type PreviewAnswer = {
19815
21190
  grants?: {
19816
21191
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
19817
21192
  models?: {
19818
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
21193
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
19819
21194
  models?: string[] | undefined;
19820
21195
  perRun?: number | undefined;
19821
21196
  perDay?: number | undefined;
@@ -19891,8 +21266,8 @@ type PreviewAnswer = {
19891
21266
  lead?: string | undefined;
19892
21267
  tail?: string | undefined;
19893
21268
  }[];
19894
- grants?: "added" | "changed" | "widened" | "narrowed" | undefined;
19895
- config?: "removed" | "added" | "changed" | undefined;
21269
+ grants?: "changed" | "added" | "widened" | "narrowed" | undefined;
21270
+ config?: "changed" | "removed" | "added" | undefined;
19896
21271
  } | undefined;
19897
21272
  };
19898
21273
  contract?: {
@@ -20075,7 +21450,7 @@ type PreviewAnswer = {
20075
21450
  promptExamples?: number | undefined;
20076
21451
  group?: string | undefined;
20077
21452
  flags?: boolean | undefined;
20078
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
21453
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
20079
21454
  live?: {
20080
21455
  every: number;
20081
21456
  } | undefined;
@@ -20138,6 +21513,10 @@ type PreviewAnswer = {
20138
21513
  relation: "next" | "about" | "parent" | "imports" | "brings" | "suggests" | "related";
20139
21514
  weight: number;
20140
21515
  }[] | undefined;
21516
+ question?: string | undefined;
21517
+ when?: string | undefined;
21518
+ lastModified?: number | undefined;
21519
+ askedBy?: "person" | "system" | "research" | undefined;
20141
21520
  }[];
20142
21521
  hooks: {
20143
21522
  name: string;
@@ -20299,7 +21678,7 @@ type PreviewAnswer = {
20299
21678
  grants?: {
20300
21679
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
20301
21680
  models?: {
20302
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
21681
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
20303
21682
  models?: string[] | undefined;
20304
21683
  perRun?: number | undefined;
20305
21684
  perDay?: number | undefined;
@@ -20330,6 +21709,11 @@ type PreviewAnswer = {
20330
21709
  title: string;
20331
21710
  description: string;
20332
21711
  }[] | undefined;
21712
+ store?: {
21713
+ description: string;
21714
+ vectors: boolean;
21715
+ engines: ("sqlite" | "postgres" | "sqlserver")[];
21716
+ } | undefined;
20333
21717
  about?: string | undefined;
20334
21718
  } | undefined;
20335
21719
  ask?: {
@@ -20624,7 +22008,7 @@ type RunRequest = {
20624
22008
  grants?: {
20625
22009
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
20626
22010
  models?: {
20627
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
22011
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
20628
22012
  models?: string[] | undefined;
20629
22013
  perRun?: number | undefined;
20630
22014
  perDay?: number | undefined;
@@ -20700,8 +22084,8 @@ type RunRequest = {
20700
22084
  lead?: string | undefined;
20701
22085
  tail?: string | undefined;
20702
22086
  }[];
20703
- grants?: "added" | "changed" | "widened" | "narrowed" | undefined;
20704
- config?: "removed" | "added" | "changed" | undefined;
22087
+ grants?: "changed" | "added" | "widened" | "narrowed" | undefined;
22088
+ config?: "changed" | "removed" | "added" | undefined;
20705
22089
  } | undefined;
20706
22090
  };
20707
22091
  } | undefined;
@@ -21059,6 +22443,10 @@ type ContextDecl = {
21059
22443
  relation: "next" | "about" | "parent" | "imports" | "brings" | "suggests" | "related";
21060
22444
  weight: number;
21061
22445
  }[] | undefined;
22446
+ question?: string | undefined;
22447
+ when?: string | undefined;
22448
+ lastModified?: number | undefined;
22449
+ askedBy?: "person" | "system" | "research" | undefined;
21062
22450
  };
21063
22451
  ```
21064
22452
 
@@ -21172,7 +22560,7 @@ type FnDecl = {
21172
22560
  promptExamples?: number | undefined;
21173
22561
  group?: string | undefined;
21174
22562
  flags?: boolean | undefined;
21175
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
22563
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
21176
22564
  live?: {
21177
22565
  every: number;
21178
22566
  } | undefined;
@@ -21648,7 +23036,7 @@ type Manifest = {
21648
23036
  promptExamples?: number | undefined;
21649
23037
  group?: string | undefined;
21650
23038
  flags?: boolean | undefined;
21651
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
23039
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
21652
23040
  live?: {
21653
23041
  every: number;
21654
23042
  } | undefined;
@@ -21711,6 +23099,10 @@ type Manifest = {
21711
23099
  relation: "next" | "about" | "parent" | "imports" | "brings" | "suggests" | "related";
21712
23100
  weight: number;
21713
23101
  }[] | undefined;
23102
+ question?: string | undefined;
23103
+ when?: string | undefined;
23104
+ lastModified?: number | undefined;
23105
+ askedBy?: "person" | "system" | "research" | undefined;
21714
23106
  }[];
21715
23107
  hooks: {
21716
23108
  name: string;
@@ -21872,7 +23264,7 @@ type Manifest = {
21872
23264
  grants?: {
21873
23265
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
21874
23266
  models?: {
21875
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
23267
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
21876
23268
  models?: string[] | undefined;
21877
23269
  perRun?: number | undefined;
21878
23270
  perDay?: number | undefined;
@@ -21903,6 +23295,11 @@ type Manifest = {
21903
23295
  title: string;
21904
23296
  description: string;
21905
23297
  }[] | undefined;
23298
+ store?: {
23299
+ description: string;
23300
+ vectors: boolean;
23301
+ engines: ("sqlite" | "postgres" | "sqlserver")[];
23302
+ } | undefined;
21906
23303
  about?: string | undefined;
21907
23304
  };
21908
23305
  ```
@@ -22092,7 +23489,7 @@ type ManifestPatch = {
22092
23489
  promptExamples?: number | undefined;
22093
23490
  group?: string | undefined;
22094
23491
  flags?: boolean | undefined;
22095
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
23492
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
22096
23493
  live?: {
22097
23494
  every: number;
22098
23495
  } | undefined;
@@ -22155,6 +23552,10 @@ type ManifestPatch = {
22155
23552
  relation: "next" | "about" | "parent" | "imports" | "brings" | "suggests" | "related";
22156
23553
  weight: number;
22157
23554
  }[] | undefined;
23555
+ question?: string | undefined;
23556
+ when?: string | undefined;
23557
+ lastModified?: number | undefined;
23558
+ askedBy?: "person" | "system" | "research" | undefined;
22158
23559
  }[] | undefined;
22159
23560
  hooks?: {
22160
23561
  name: string;
@@ -22614,7 +24015,7 @@ type ModelForwardResult = ({
22614
24015
  const, type · declared in `packages/core/src/model-calls.ts`
22615
24016
 
22616
24017
  ```ts
22617
- type ModelRole = "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide";
24018
+ type ModelRole = "metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan";
22618
24019
  ```
22619
24020
 
22620
24021
  ### From `packages/core/src/model-names.ts`
@@ -22785,6 +24186,11 @@ type PairingInfo = {
22785
24186
  instance: InstanceName;
22786
24187
  configType?: TypeDef$1<any> | undefined;
22787
24188
  configSecrets?: string[] | undefined;
24189
+ store?: {
24190
+ description: string;
24191
+ vectors: boolean;
24192
+ engines: ("sqlite" | "postgres" | "sqlserver")[];
24193
+ } | undefined;
22788
24194
  };
22789
24195
  ```
22790
24196
 
@@ -23141,7 +24547,7 @@ type Approval = {
23141
24547
  grants?: {
23142
24548
  hub: ("search" | "embed" | "fns" | "settings" | "state" | "resources" | "approvals" | "connections" | "decide" | "data" | "runs" | "ai")[];
23143
24549
  models?: {
23144
- roles?: ("ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide")[] | undefined;
24550
+ roles?: ("metadata" | "ocr" | "chat" | "transcribe" | "dictate" | "speak" | "describe" | "decide" | "plan")[] | undefined;
23145
24551
  models?: string[] | undefined;
23146
24552
  perRun?: number | undefined;
23147
24553
  perDay?: number | undefined;
@@ -23217,8 +24623,8 @@ type Approval = {
23217
24623
  lead?: string | undefined;
23218
24624
  tail?: string | undefined;
23219
24625
  }[];
23220
- grants?: "added" | "changed" | "widened" | "narrowed" | undefined;
23221
- config?: "removed" | "added" | "changed" | undefined;
24626
+ grants?: "changed" | "added" | "widened" | "narrowed" | undefined;
24627
+ config?: "changed" | "removed" | "added" | undefined;
23222
24628
  } | undefined;
23223
24629
  } | undefined;
23224
24630
  proposed?: boolean | undefined;
@@ -24032,7 +25438,7 @@ A change seen by a watch.
24032
25438
  ```ts
24033
25439
  type ResourceChange = {
24034
25440
  uri: `${string}://${string}`;
24035
- change: "removed" | "added" | "changed";
25441
+ change: "changed" | "removed" | "added";
24036
25442
  version?: string | undefined;
24037
25443
  };
24038
25444
  ```
@@ -24540,6 +25946,9 @@ type RunUpdate = {
24540
25946
  total: number;
24541
25947
  } | {
24542
25948
  type: "background";
25949
+ } | {
25950
+ type: "result";
25951
+ revision: number;
24543
25952
  };
24544
25953
  ```
24545
25954
 
@@ -24651,6 +26060,189 @@ type SensitivityFlag = {
24651
26060
  };
24652
26061
  ```
24653
26062
 
26063
+ ### From `packages/core/src/stores.ts`
26064
+
26065
+ #### <a id="core-migrationid"></a>`MigrationId`
26066
+
26067
+ const, type · declared in `packages/core/src/stores.ts`
26068
+
26069
+ A migration's id: what it is known by forever once shipped (`001-notes`). Sorted as text, so they apply in order.
26070
+
26071
+ ```ts
26072
+ type MigrationId = string;
26073
+ ```
26074
+
26075
+ #### <a id="core-storedecl"></a>`StoreDecl`
26076
+
26077
+ const, type · declared in `packages/core/src/stores.ts`
26078
+
26079
+ A system's store, as its contract declares it (`store({ description, vectors, engines })`): what it holds, whether
26080
+ it keeps vectors (`ctx.store.vectors(name)`), and which engines it may run on. Installing refuses a placement on an
26081
+ engine the store does not accept.
26082
+
26083
+ ```ts
26084
+ type StoreDecl = {
26085
+ description: string;
26086
+ vectors: boolean;
26087
+ engines: ("sqlite" | "postgres" | "sqlserver")[];
26088
+ };
26089
+ ```
26090
+
26091
+ #### <a id="core-storeengine"></a>`StoreEngine`
26092
+
26093
+ const, type · declared in `packages/core/src/stores.ts`
26094
+
26095
+ The engines a store can run on. SQLite (with sqlite-vec) serves both the `system` and the `hub` placement.
26096
+
26097
+ ```ts
26098
+ type StoreEngine = "sqlite" | "postgres" | "sqlserver";
26099
+ ```
26100
+
26101
+ #### <a id="core-storelease"></a>`StoreLease`
26102
+
26103
+ const, type · declared in `packages/core/src/stores.ts`
26104
+
26105
+ A transaction the hub opened for the system: its lease, and when it lapses unless a statement renews it.
26106
+
26107
+ ```ts
26108
+ type StoreLease = {
26109
+ lease: string;
26110
+ expiresAt: number;
26111
+ };
26112
+ ```
26113
+
26114
+ #### <a id="core-storeleaseid"></a>`StoreLeaseId`
26115
+
26116
+ const, type · declared in `packages/core/src/stores.ts`
26117
+
26118
+ A transaction lease's id, from `storeBegin`.
26119
+
26120
+ ```ts
26121
+ type StoreLeaseId = string;
26122
+ ```
26123
+
26124
+ #### <a id="core-storemeasure"></a>`StoreMeasure`
26125
+
26126
+ const, type · declared in `packages/core/src/stores.ts`
26127
+
26128
+ How big a store is, as measured when it was last counted: its size in bytes (SQLite files only: an external
26129
+ database's size isn't measured), and each table's row count.
26130
+
26131
+ ```ts
26132
+ type StoreMeasure = {
26133
+ tables: {
26134
+ name: string;
26135
+ rows: number;
26136
+ }[];
26137
+ at: number;
26138
+ bytes?: number | undefined;
26139
+ more?: boolean | undefined;
26140
+ };
26141
+ ```
26142
+
26143
+ #### <a id="core-storemoveid"></a>`StoreMoveId`
26144
+
26145
+ const, type · declared in `packages/core/src/stores.ts`
26146
+
26147
+ A move's id.
26148
+
26149
+ ```ts
26150
+ type StoreMoveId = string;
26151
+ ```
26152
+
26153
+ #### <a id="core-storeopen"></a>`StoreOpen`
26154
+
26155
+ const, type · declared in `packages/core/src/stores.ts`
26156
+
26157
+ Where to open the store, as the hub tells the system in its welcome. The system never chooses: an external
26158
+ database's connection comes revealed here, as config secrets do in `configure`.
26159
+
26160
+ ```ts
26161
+ type StoreOpen = {
26162
+ placement: "system";
26163
+ } | {
26164
+ placement: "hub";
26165
+ } | {
26166
+ placement: "external";
26167
+ engine: "postgres" | "sqlserver";
26168
+ connection: string;
26169
+ schema: string;
26170
+ };
26171
+ ```
26172
+
26173
+ #### <a id="core-storeresult"></a>`StoreResult`
26174
+
26175
+ const, type · declared in `packages/core/src/stores.ts`
26176
+
26177
+ What a statement gave: its rows (for a statement that reads), how many rows it changed, and the last rowid it made.
26178
+
26179
+ ```ts
26180
+ type StoreResult = {
26181
+ rows: Record<string, string | number | {
26182
+ $bytes: string;
26183
+ } | null>[];
26184
+ changes?: number | undefined;
26185
+ insertId?: number | undefined;
26186
+ };
26187
+ ```
26188
+
26189
+ #### <a id="core-storesnapshotname"></a>`StoreSnapshotName`
26190
+
26191
+ const, type · declared in `packages/core/src/stores.ts`
26192
+
26193
+ A snapshot of a store the hub holds (`VACUUM INTO`), named so it can be restored.
26194
+
26195
+ ```ts
26196
+ type StoreSnapshotName = string;
26197
+ ```
26198
+
26199
+ #### <a id="core-storestatement"></a>`StoreStatement`
26200
+
26201
+ const, type · declared in `packages/core/src/stores.ts`
26202
+
26203
+ One compiled statement (the SQL text and its parameters), run alone or inside the lease's transaction.
26204
+
26205
+ ```ts
26206
+ type StoreStatement = {
26207
+ sql: string;
26208
+ params: (string | number | {
26209
+ $bytes: string;
26210
+ } | null)[];
26211
+ lease?: string | undefined;
26212
+ };
26213
+ ```
26214
+
26215
+ #### <a id="core-storestatusreport"></a>`StoreStatusReport`
26216
+
26217
+ const, type · declared in `packages/core/src/stores.ts`
26218
+
26219
+ What a system reports about its store (`storeStatus` on the link), each time its state changes.
26220
+
26221
+ ```ts
26222
+ type StoreStatusReport = {
26223
+ state: "failed" | "preparing" | "migrating" | "ready" | "moving";
26224
+ engine: "sqlite" | "postgres" | "sqlserver";
26225
+ migrations: {
26226
+ applied: {
26227
+ id: string;
26228
+ checksum: string;
26229
+ at: number;
26230
+ }[];
26231
+ pending: string[];
26232
+ };
26233
+ error?: string | undefined;
26234
+ measure?: {
26235
+ tables: {
26236
+ name: string;
26237
+ rows: number;
26238
+ }[];
26239
+ at: number;
26240
+ bytes?: number | undefined;
26241
+ more?: boolean | undefined;
26242
+ } | undefined;
26243
+ };
26244
+ ```
26245
+
24654
26246
  ### From `packages/core/src/system-events.ts`
24655
26247
 
24656
26248
  #### <a id="core-systemevent"></a>`SystemEvent`
@@ -24708,13 +26300,16 @@ type SystemEvent = {
24708
26300
  total: number;
24709
26301
  } | {
24710
26302
  type: "background";
26303
+ } | {
26304
+ type: "result";
26305
+ revision: number;
24711
26306
  };
24712
26307
  notified?: boolean | undefined;
24713
26308
  } | {
24714
26309
  type: "resources";
24715
26310
  changes: {
24716
26311
  uri: `${string}://${string}`;
24717
- change: "removed" | "added" | "changed";
26312
+ change: "changed" | "removed" | "added";
24718
26313
  version?: string | undefined;
24719
26314
  }[];
24720
26315
  } | {