attention-manifest-protocol 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (627) hide show
  1. package/CHANGELOG.md +250 -226
  2. package/CHANGELOG.zh-CN.md +63 -39
  3. package/README.md +22 -1
  4. package/README.zh-CN.md +22 -1
  5. package/docs/probes/calibration-imported.json +141 -141
  6. package/docs/probes/eval-recorded-replay.json +597 -597
  7. package/docs/probes/eval-replay.json +124 -124
  8. package/docs/probes/eval-summary.json +42 -42
  9. package/docs/probes/runtime-eval.json +4230 -4230
  10. package/lib/attention/attention.d.ts +153 -0
  11. package/lib/attention/attention.js +209 -0
  12. package/lib/attention/budget.d.ts +31 -0
  13. package/lib/attention/budget.js +55 -0
  14. package/lib/attention/cognition.d.ts +230 -0
  15. package/lib/attention/cognition.js +245 -0
  16. package/lib/attention/index.d.ts +8 -0
  17. package/lib/attention/index.js +7 -0
  18. package/lib/attention/interrupts.d.ts +97 -0
  19. package/lib/attention/interrupts.js +151 -0
  20. package/lib/attention/resource.d.ts +167 -0
  21. package/lib/attention/resource.js +148 -0
  22. package/lib/attention/social.d.ts +74 -0
  23. package/lib/attention/social.js +153 -0
  24. package/lib/attention/socialTypes.d.ts +102 -0
  25. package/lib/attention/socialTypes.js +1 -0
  26. package/lib/authz/authz.d.ts +75 -0
  27. package/lib/authz/authz.js +176 -0
  28. package/lib/authz/index.d.ts +1 -0
  29. package/lib/authz/index.js +1 -0
  30. package/lib/bayes/calibration.d.ts +67 -0
  31. package/lib/bayes/calibration.js +114 -0
  32. package/lib/bayes/calibrationRegistry.d.ts +39 -0
  33. package/lib/bayes/calibrationRegistry.js +61 -0
  34. package/lib/bayes/calibrationSelection.d.ts +40 -0
  35. package/lib/bayes/calibrationSelection.js +89 -0
  36. package/lib/bayes/engine.d.ts +163 -0
  37. package/lib/bayes/engine.js +354 -0
  38. package/lib/bayes/index.d.ts +6 -0
  39. package/lib/bayes/index.js +6 -0
  40. package/lib/bayes/reliability.d.ts +27 -0
  41. package/lib/bayes/reliability.js +38 -0
  42. package/lib/bayes/scopedPriors.d.ts +34 -0
  43. package/lib/bayes/scopedPriors.js +70 -0
  44. package/lib/boundary/frame.d.ts +63 -0
  45. package/lib/boundary/frame.js +239 -0
  46. package/lib/boundary/ids.d.ts +8 -0
  47. package/lib/boundary/ids.js +12 -0
  48. package/lib/boundary/index.d.ts +12 -0
  49. package/lib/boundary/index.js +8 -0
  50. package/lib/boundary/refTable.d.ts +49 -0
  51. package/lib/boundary/refTable.js +92 -0
  52. package/lib/boundary/toolCall.d.ts +33 -0
  53. package/lib/boundary/toolCall.js +173 -0
  54. package/lib/concept/concept.d.ts +67 -0
  55. package/lib/concept/concept.js +1 -0
  56. package/lib/concept/conceptBudget.d.ts +56 -0
  57. package/lib/concept/conceptBudget.js +281 -0
  58. package/lib/concept/conceptBudgetTypes.d.ts +74 -0
  59. package/lib/concept/conceptBudgetTypes.js +1 -0
  60. package/lib/concept/index.d.ts +3 -0
  61. package/lib/concept/index.js +3 -0
  62. package/lib/concurrency/idempotency.d.ts +16 -0
  63. package/lib/concurrency/idempotency.js +21 -0
  64. package/lib/concurrency/index.d.ts +5 -0
  65. package/lib/concurrency/index.js +5 -0
  66. package/lib/concurrency/mutex.d.ts +13 -0
  67. package/lib/concurrency/mutex.js +26 -0
  68. package/lib/concurrency/namedLocks.d.ts +7 -0
  69. package/lib/concurrency/namedLocks.js +31 -0
  70. package/lib/concurrency/retry.d.ts +23 -0
  71. package/lib/concurrency/retry.js +38 -0
  72. package/lib/concurrency/worker.d.ts +42 -0
  73. package/lib/concurrency/worker.js +67 -0
  74. package/lib/context/agentContext.d.ts +58 -0
  75. package/lib/context/agentContext.js +197 -0
  76. package/lib/context/ast.d.ts +98 -0
  77. package/lib/context/ast.js +414 -0
  78. package/lib/context/contentStore.d.ts +16 -0
  79. package/lib/context/contentStore.js +61 -0
  80. package/lib/context/context.d.ts +15 -0
  81. package/lib/context/context.js +39 -0
  82. package/lib/context/contextIndex.d.ts +40 -0
  83. package/lib/context/contextIndex.js +64 -0
  84. package/lib/context/document.d.ts +102 -0
  85. package/lib/context/document.js +22 -0
  86. package/lib/context/fileStorePath.d.ts +1 -0
  87. package/lib/context/fileStorePath.js +13 -0
  88. package/lib/context/index.d.ts +22 -0
  89. package/lib/context/index.js +11 -0
  90. package/lib/context/lifecycle.d.ts +91 -0
  91. package/lib/context/lifecycle.js +163 -0
  92. package/lib/context/projections.d.ts +20 -0
  93. package/lib/context/projections.js +127 -0
  94. package/lib/context/workspace.d.ts +111 -0
  95. package/lib/context/workspace.js +318 -0
  96. package/lib/context/workspaceProtocol.d.ts +30 -0
  97. package/lib/context/workspaceProtocol.js +49 -0
  98. package/lib/context/workspaceService.d.ts +63 -0
  99. package/lib/context/workspaceService.js +352 -0
  100. package/lib/cooperation/board.d.ts +47 -0
  101. package/lib/cooperation/board.js +66 -0
  102. package/lib/cooperation/collaboration.d.ts +55 -0
  103. package/lib/cooperation/collaboration.js +1 -0
  104. package/lib/cooperation/index.d.ts +6 -0
  105. package/lib/cooperation/index.js +6 -0
  106. package/lib/cooperation/merge.d.ts +69 -0
  107. package/lib/cooperation/merge.js +109 -0
  108. package/lib/cooperation/metrics.d.ts +39 -0
  109. package/lib/cooperation/metrics.js +17 -0
  110. package/lib/cooperation/session.d.ts +75 -0
  111. package/lib/cooperation/session.js +74 -0
  112. package/lib/cooperation/unified.d.ts +38 -0
  113. package/lib/cooperation/unified.js +40 -0
  114. package/lib/database/adapter/adapters.d.ts +24 -0
  115. package/lib/database/adapter/adapters.js +31 -0
  116. package/lib/database/adapter/index.d.ts +4 -0
  117. package/lib/database/adapter/index.js +4 -0
  118. package/lib/database/adapter/runtimeSink.d.ts +20 -0
  119. package/lib/database/adapter/runtimeSink.js +50 -0
  120. package/lib/database/adapter/sessionStore.d.ts +11 -0
  121. package/lib/database/adapter/sessionStore.js +23 -0
  122. package/lib/database/adapter/turnStore.d.ts +10 -0
  123. package/lib/database/adapter/turnStore.js +15 -0
  124. package/lib/database/entity/agent.d.ts +133 -0
  125. package/lib/database/entity/agent.js +61 -0
  126. package/lib/database/entity/entity.d.ts +715 -0
  127. package/lib/database/entity/entity.js +372 -0
  128. package/lib/database/entity/handle.d.ts +31 -0
  129. package/lib/database/entity/handle.js +53 -0
  130. package/lib/database/entity/index.d.ts +32 -0
  131. package/lib/database/entity/index.js +22 -0
  132. package/lib/database/entity/message.d.ts +27 -0
  133. package/lib/database/entity/message.js +52 -0
  134. package/lib/database/entity/meta.d.ts +11 -0
  135. package/lib/database/entity/meta.js +1 -0
  136. package/lib/database/entity/object.d.ts +23 -0
  137. package/lib/database/entity/object.js +24 -0
  138. package/lib/database/entity/outbox.d.ts +9 -0
  139. package/lib/database/entity/outbox.js +5 -0
  140. package/lib/database/entity/process.d.ts +30 -0
  141. package/lib/database/entity/process.js +40 -0
  142. package/lib/database/entity/registry.d.ts +81 -0
  143. package/lib/database/entity/registry.js +91 -0
  144. package/lib/database/entity/runtimeApproval.d.ts +23 -0
  145. package/lib/database/entity/runtimeApproval.js +5 -0
  146. package/lib/database/entity/runtimeSession.d.ts +7 -0
  147. package/lib/database/entity/runtimeSession.js +5 -0
  148. package/lib/database/entity/runtimeTurn.d.ts +9 -0
  149. package/lib/database/entity/runtimeTurn.js +5 -0
  150. package/lib/database/entity/thread.d.ts +35 -0
  151. package/lib/database/entity/thread.js +55 -0
  152. package/lib/database/entity/window.d.ts +39 -0
  153. package/lib/database/entity/window.js +56 -0
  154. package/lib/database/entity/worker.d.ts +42 -0
  155. package/lib/database/entity/worker.js +58 -0
  156. package/lib/database/index.d.ts +6 -0
  157. package/lib/database/index.js +6 -0
  158. package/lib/database/repository/addressSpaceRepository.d.ts +18 -0
  159. package/lib/database/repository/addressSpaceRepository.js +40 -0
  160. package/lib/database/repository/agentRepository.d.ts +41 -0
  161. package/lib/database/repository/agentRepository.js +398 -0
  162. package/lib/database/repository/base.d.ts +31 -0
  163. package/lib/database/repository/base.js +23 -0
  164. package/lib/database/repository/executionRepository.d.ts +64 -0
  165. package/lib/database/repository/executionRepository.js +379 -0
  166. package/lib/database/repository/handleRepository.d.ts +35 -0
  167. package/lib/database/repository/handleRepository.js +57 -0
  168. package/lib/database/repository/index.d.ts +20 -0
  169. package/lib/database/repository/index.js +17 -0
  170. package/lib/database/repository/messageRepository.d.ts +33 -0
  171. package/lib/database/repository/messageRepository.js +45 -0
  172. package/lib/database/repository/objectRepository.d.ts +43 -0
  173. package/lib/database/repository/objectRepository.js +60 -0
  174. package/lib/database/repository/outboxRepository.d.ts +15 -0
  175. package/lib/database/repository/outboxRepository.js +51 -0
  176. package/lib/database/repository/processRepository.d.ts +31 -0
  177. package/lib/database/repository/processRepository.js +48 -0
  178. package/lib/database/repository/registryRepository.d.ts +72 -0
  179. package/lib/database/repository/registryRepository.js +95 -0
  180. package/lib/database/repository/repository.d.ts +322 -0
  181. package/lib/database/repository/repository.js +332 -0
  182. package/lib/database/repository/runtimeApprovalRepository.d.ts +14 -0
  183. package/lib/database/repository/runtimeApprovalRepository.js +35 -0
  184. package/lib/database/repository/runtimeSessionRepository.d.ts +9 -0
  185. package/lib/database/repository/runtimeSessionRepository.js +21 -0
  186. package/lib/database/repository/runtimeTurnRepository.d.ts +10 -0
  187. package/lib/database/repository/runtimeTurnRepository.js +32 -0
  188. package/lib/database/repository/socialRepository.d.ts +22 -0
  189. package/lib/database/repository/socialRepository.js +155 -0
  190. package/lib/database/repository/threadRepository.d.ts +29 -0
  191. package/lib/database/repository/threadRepository.js +48 -0
  192. package/lib/database/repository/windowRepository.d.ts +46 -0
  193. package/lib/database/repository/windowRepository.js +68 -0
  194. package/lib/database/repository/workerRepository.d.ts +38 -0
  195. package/lib/database/repository/workerRepository.js +61 -0
  196. package/lib/database/service/database.d.ts +55 -0
  197. package/lib/database/service/database.js +77 -0
  198. package/lib/database/service/handleService.d.ts +20 -0
  199. package/lib/database/service/handleService.js +34 -0
  200. package/lib/database/service/index.d.ts +16 -0
  201. package/lib/database/service/index.js +11 -0
  202. package/lib/database/service/messageService.d.ts +26 -0
  203. package/lib/database/service/messageService.js +40 -0
  204. package/lib/database/service/objectService.d.ts +32 -0
  205. package/lib/database/service/objectService.js +31 -0
  206. package/lib/database/service/processService.d.ts +22 -0
  207. package/lib/database/service/processService.js +45 -0
  208. package/lib/database/service/registryServices.d.ts +43 -0
  209. package/lib/database/service/registryServices.js +60 -0
  210. package/lib/database/service/service.d.ts +131 -0
  211. package/lib/database/service/service.js +153 -0
  212. package/lib/database/service/stepService.d.ts +23 -0
  213. package/lib/database/service/stepService.js +35 -0
  214. package/lib/database/service/threadService.d.ts +23 -0
  215. package/lib/database/service/threadService.js +48 -0
  216. package/lib/database/service/windowService.d.ts +15 -0
  217. package/lib/database/service/windowService.js +22 -0
  218. package/lib/database/service/workerService.d.ts +28 -0
  219. package/lib/database/service/workerService.js +34 -0
  220. package/lib/database/sql/index.d.ts +3 -0
  221. package/lib/database/sql/index.js +2 -0
  222. package/lib/database/sql/schema.d.ts +5 -0
  223. package/lib/database/sql/schema.js +416 -0
  224. package/lib/database/sql/sql.d.ts +290 -0
  225. package/lib/database/sql/sql.js +430 -0
  226. package/lib/database/store/database.d.ts +75 -0
  227. package/lib/database/store/database.js +143 -0
  228. package/lib/database/store/index.d.ts +3 -0
  229. package/lib/database/store/index.js +2 -0
  230. package/lib/database/store/store.d.ts +145 -0
  231. package/lib/database/store/store.js +192 -0
  232. package/lib/delegate/index.d.ts +2 -0
  233. package/lib/delegate/index.js +2 -0
  234. package/lib/delegate/team.d.ts +92 -0
  235. package/lib/delegate/team.js +200 -0
  236. package/lib/delegate/teamTypes.d.ts +43 -0
  237. package/lib/delegate/teamTypes.js +1 -0
  238. package/lib/diagnosis/checklist.d.ts +16 -0
  239. package/lib/diagnosis/checklist.js +61 -0
  240. package/lib/diagnosis/context.d.ts +19 -0
  241. package/lib/diagnosis/context.js +79 -0
  242. package/lib/diagnosis/frame.d.ts +34 -0
  243. package/lib/diagnosis/frame.js +230 -0
  244. package/lib/diagnosis/index.d.ts +5 -0
  245. package/lib/diagnosis/index.js +5 -0
  246. package/lib/diagnosis/router.d.ts +22 -0
  247. package/lib/diagnosis/router.js +47 -0
  248. package/lib/diagnosis/types.d.ts +78 -0
  249. package/lib/diagnosis/types.js +2 -0
  250. package/lib/error/agentError.d.ts +9 -0
  251. package/lib/error/agentError.js +13 -0
  252. package/lib/error/ampError.d.ts +14 -0
  253. package/lib/error/ampError.js +19 -0
  254. package/lib/error/authzError.d.ts +10 -0
  255. package/lib/error/authzError.js +11 -0
  256. package/lib/error/boundaryRejection.d.ts +16 -0
  257. package/lib/error/boundaryRejection.js +14 -0
  258. package/lib/error/index.d.ts +7 -0
  259. package/lib/error/index.js +7 -0
  260. package/lib/error/kernelError.d.ts +11 -0
  261. package/lib/error/kernelError.js +12 -0
  262. package/lib/error/mailboxError.d.ts +5 -0
  263. package/lib/error/mailboxError.js +6 -0
  264. package/lib/error/windowError.d.ts +8 -0
  265. package/lib/error/windowError.js +9 -0
  266. package/lib/evaluation/agreement.d.ts +22 -0
  267. package/lib/evaluation/agreement.js +82 -0
  268. package/lib/evaluation/index.d.ts +2 -0
  269. package/lib/evaluation/index.js +2 -0
  270. package/lib/evaluation/labels.d.ts +56 -0
  271. package/lib/evaluation/labels.js +206 -0
  272. package/lib/evidence/evidenceGraph.d.ts +37 -0
  273. package/lib/evidence/evidenceGraph.js +165 -0
  274. package/lib/evidence/index.d.ts +4 -0
  275. package/lib/evidence/index.js +2 -0
  276. package/lib/evidence/revalidation.d.ts +70 -0
  277. package/lib/evidence/revalidation.js +146 -0
  278. package/lib/execution/exec.d.ts +151 -0
  279. package/lib/execution/exec.js +282 -0
  280. package/lib/execution/handles.d.ts +25 -0
  281. package/lib/execution/handles.js +45 -0
  282. package/lib/execution/index.d.ts +3 -0
  283. package/lib/execution/index.js +3 -0
  284. package/lib/execution/pin.d.ts +60 -0
  285. package/lib/execution/pin.js +103 -0
  286. package/lib/frame/frame.d.ts +61 -0
  287. package/lib/frame/frame.js +1 -0
  288. package/lib/frame/index.d.ts +1 -0
  289. package/lib/frame/index.js +1 -0
  290. package/lib/goal/goal.d.ts +19 -0
  291. package/lib/goal/goal.js +21 -0
  292. package/lib/goal/index.d.ts +2 -0
  293. package/lib/goal/index.js +1 -0
  294. package/lib/goal/plan.d.ts +125 -0
  295. package/lib/goal/plan.js +60 -0
  296. package/lib/governance/attentionManifest.d.ts +279 -0
  297. package/lib/governance/attentionManifest.js +467 -0
  298. package/lib/governance/audit.d.ts +123 -0
  299. package/lib/governance/audit.js +263 -0
  300. package/lib/governance/budget.d.ts +219 -0
  301. package/lib/governance/budget.js +424 -0
  302. package/lib/governance/context.d.ts +159 -0
  303. package/lib/governance/context.js +229 -0
  304. package/lib/governance/control.d.ts +65 -0
  305. package/lib/governance/control.js +89 -0
  306. package/lib/governance/cooperation.d.ts +163 -0
  307. package/lib/governance/cooperation.js +350 -0
  308. package/lib/governance/credential.d.ts +117 -0
  309. package/lib/governance/credential.js +229 -0
  310. package/lib/governance/httpServer.d.ts +18 -0
  311. package/lib/governance/httpServer.js +74 -0
  312. package/lib/governance/index.d.ts +32 -0
  313. package/lib/governance/index.js +32 -0
  314. package/lib/governance/legal.d.ts +222 -0
  315. package/lib/governance/legal.js +371 -0
  316. package/lib/governance/matrix.d.ts +170 -0
  317. package/lib/governance/matrix.js +365 -0
  318. package/lib/governance/perspectives.d.ts +98 -0
  319. package/lib/governance/perspectives.js +340 -0
  320. package/lib/governance/signing.d.ts +131 -0
  321. package/lib/governance/signing.js +241 -0
  322. package/lib/governance/store.d.ts +33 -0
  323. package/lib/governance/store.js +89 -0
  324. package/lib/governance/switching.d.ts +183 -0
  325. package/lib/governance/switching.js +257 -0
  326. package/lib/governance/toolPolicy.d.ts +37 -0
  327. package/lib/governance/toolPolicy.js +42 -0
  328. package/lib/governance/transport.d.ts +76 -0
  329. package/lib/governance/transport.js +124 -0
  330. package/lib/governance/types.d.ts +218 -0
  331. package/lib/governance/types.js +72 -0
  332. package/lib/governance/workflow.d.ts +174 -0
  333. package/lib/governance/workflow.js +612 -0
  334. package/lib/index.d.ts +11 -0
  335. package/lib/index.js +11 -0
  336. package/lib/interaction/index.d.ts +1 -0
  337. package/lib/interaction/index.js +1 -0
  338. package/lib/interaction/interaction.d.ts +83 -0
  339. package/lib/interaction/interaction.js +256 -0
  340. package/lib/ipc/index.d.ts +4 -0
  341. package/lib/ipc/index.js +3 -0
  342. package/lib/ipc/mailbox.d.ts +37 -0
  343. package/lib/ipc/mailbox.js +77 -0
  344. package/lib/ipc/memorySocialStore.d.ts +14 -0
  345. package/lib/ipc/memorySocialStore.js +83 -0
  346. package/lib/ipc/social.d.ts +80 -0
  347. package/lib/ipc/social.js +1 -0
  348. package/lib/kernel/index.d.ts +2 -0
  349. package/lib/kernel/index.js +1 -0
  350. package/lib/kernel/scheduler.d.ts +195 -0
  351. package/lib/kernel/scheduler.js +334 -0
  352. package/lib/ledger/checkpoint.d.ts +116 -0
  353. package/lib/ledger/checkpoint.js +223 -0
  354. package/lib/ledger/index.d.ts +4 -0
  355. package/lib/ledger/index.js +4 -0
  356. package/lib/ledger/ledger.d.ts +21 -0
  357. package/lib/ledger/ledger.js +23 -0
  358. package/lib/ledger/persistence.d.ts +46 -0
  359. package/lib/ledger/persistence.js +106 -0
  360. package/lib/ledger/share.d.ts +29 -0
  361. package/lib/ledger/share.js +39 -0
  362. package/lib/lock/index.d.ts +2 -0
  363. package/lib/lock/index.js +1 -0
  364. package/lib/lock/lease.d.ts +23 -0
  365. package/lib/lock/lease.js +42 -0
  366. package/lib/manifest/agentCard.d.ts +35 -0
  367. package/lib/manifest/agentCard.js +38 -0
  368. package/lib/manifest/cardSign.d.ts +25 -0
  369. package/lib/manifest/cardSign.js +70 -0
  370. package/lib/manifest/federation.d.ts +64 -0
  371. package/lib/manifest/federation.js +187 -0
  372. package/lib/manifest/federationTypes.d.ts +51 -0
  373. package/lib/manifest/federationTypes.js +1 -0
  374. package/lib/manifest/index.d.ts +8 -0
  375. package/lib/manifest/index.js +8 -0
  376. package/lib/manifest/keys.d.ts +221 -0
  377. package/lib/manifest/keys.js +484 -0
  378. package/lib/manifest/manifest.d.ts +102 -0
  379. package/lib/manifest/manifest.js +1 -0
  380. package/lib/manifest/sign.d.ts +38 -0
  381. package/lib/manifest/sign.js +90 -0
  382. package/lib/manifest/trust.d.ts +54 -0
  383. package/lib/manifest/trust.js +87 -0
  384. package/lib/mission/index.d.ts +2 -0
  385. package/lib/mission/index.js +1 -0
  386. package/lib/mission/missionQueue.d.ts +19 -0
  387. package/lib/mission/missionQueue.js +62 -0
  388. package/lib/module/index.d.ts +9 -0
  389. package/lib/module/index.js +9 -0
  390. package/lib/module/llm/deepseek.d.ts +43 -0
  391. package/lib/module/llm/deepseek.js +162 -0
  392. package/lib/module/llm/llm.d.ts +64 -0
  393. package/lib/module/llm/llm.js +16 -0
  394. package/lib/module/mcp/client.d.ts +32 -0
  395. package/lib/module/mcp/client.js +84 -0
  396. package/lib/module/mcp/http.d.ts +32 -0
  397. package/lib/module/mcp/http.js +83 -0
  398. package/lib/module/mcp/protocol.d.ts +62 -0
  399. package/lib/module/mcp/protocol.js +20 -0
  400. package/lib/module/mcp/server.d.ts +22 -0
  401. package/lib/module/mcp/server.js +138 -0
  402. package/lib/module/mcp/transport.d.ts +19 -0
  403. package/lib/module/mcp/transport.js +16 -0
  404. package/lib/module/mcp/workspaceServer.d.ts +20 -0
  405. package/lib/module/mcp/workspaceServer.js +90 -0
  406. package/lib/module/sandbox/sandbox.d.ts +24 -0
  407. package/lib/module/sandbox/sandbox.js +5 -0
  408. package/lib/module/tool/mcpExecutor.d.ts +18 -0
  409. package/lib/module/tool/mcpExecutor.js +41 -0
  410. package/lib/module/tool/policy.d.ts +30 -0
  411. package/lib/module/tool/policy.js +23 -0
  412. package/lib/module/tool/redact.d.ts +9 -0
  413. package/lib/module/tool/redact.js +19 -0
  414. package/lib/module/tool/tool.d.ts +26 -0
  415. package/lib/module/tool/tool.js +24 -0
  416. package/lib/module/tool/workspaceExecutor.d.ts +12 -0
  417. package/lib/module/tool/workspaceExecutor.js +25 -0
  418. package/lib/policy/guard.d.ts +115 -0
  419. package/lib/policy/guard.js +154 -0
  420. package/lib/policy/index.d.ts +2 -0
  421. package/lib/policy/index.js +2 -0
  422. package/lib/policy/policy.d.ts +249 -0
  423. package/lib/policy/policy.js +364 -0
  424. package/lib/process/agent.d.ts +295 -0
  425. package/lib/process/agent.js +1 -0
  426. package/lib/process/agentService.d.ts +87 -0
  427. package/lib/process/agentService.js +128 -0
  428. package/lib/process/agentStore.d.ts +35 -0
  429. package/lib/process/agentStore.js +328 -0
  430. package/lib/process/executionStore.d.ts +79 -0
  431. package/lib/process/executionStore.js +71 -0
  432. package/lib/process/index.d.ts +5 -0
  433. package/lib/process/index.js +5 -0
  434. package/lib/process/process.d.ts +120 -0
  435. package/lib/process/process.js +111 -0
  436. package/lib/process/transitions.d.ts +11 -0
  437. package/lib/process/transitions.js +8 -0
  438. package/lib/progress/index.d.ts +2 -0
  439. package/lib/progress/index.js +1 -0
  440. package/lib/progress/progress.d.ts +26 -0
  441. package/lib/progress/progress.js +42 -0
  442. package/lib/protocol/a2a.d.ts +51 -0
  443. package/lib/protocol/a2a.js +79 -0
  444. package/lib/protocol/channel.d.ts +25 -0
  445. package/lib/protocol/channel.js +27 -0
  446. package/lib/protocol/envelope.d.ts +180 -0
  447. package/lib/protocol/envelope.js +495 -0
  448. package/lib/protocol/httpChannel.d.ts +33 -0
  449. package/lib/protocol/httpChannel.js +59 -0
  450. package/lib/protocol/index.d.ts +6 -0
  451. package/lib/protocol/index.js +6 -0
  452. package/lib/protocol/protocol.d.ts +120 -0
  453. package/lib/protocol/protocol.js +1 -0
  454. package/lib/protocol/wire.d.ts +12 -0
  455. package/lib/protocol/wire.js +55 -0
  456. package/lib/receipt/index.d.ts +1 -0
  457. package/lib/receipt/index.js +1 -0
  458. package/lib/receipt/receipt.d.ts +43 -0
  459. package/lib/receipt/receipt.js +1 -0
  460. package/lib/registry/content.d.ts +10 -0
  461. package/lib/registry/content.js +58 -0
  462. package/lib/registry/index.d.ts +4 -0
  463. package/lib/registry/index.js +2 -0
  464. package/lib/registry/registry.d.ts +109 -0
  465. package/lib/registry/registry.js +299 -0
  466. package/lib/runtime/action.d.ts +46 -0
  467. package/lib/runtime/action.js +39 -0
  468. package/lib/runtime/behavior.d.ts +110 -0
  469. package/lib/runtime/behavior.js +179 -0
  470. package/lib/runtime/behaviorTuning.d.ts +59 -0
  471. package/lib/runtime/behaviorTuning.js +95 -0
  472. package/lib/runtime/cognitiveRuntime.d.ts +189 -0
  473. package/lib/runtime/cognitiveRuntime.js +490 -0
  474. package/lib/runtime/escalation.d.ts +22 -0
  475. package/lib/runtime/escalation.js +15 -0
  476. package/lib/runtime/governedTask.d.ts +57 -0
  477. package/lib/runtime/governedTask.js +150 -0
  478. package/lib/runtime/index.d.ts +15 -0
  479. package/lib/runtime/index.js +15 -0
  480. package/lib/runtime/kernelRuntime.d.ts +33 -0
  481. package/lib/runtime/kernelRuntime.js +105 -0
  482. package/lib/runtime/operation.d.ts +30 -0
  483. package/lib/runtime/operation.js +1 -0
  484. package/lib/runtime/replay.d.ts +24 -0
  485. package/lib/runtime/replay.js +38 -0
  486. package/lib/runtime/routing.d.ts +12 -0
  487. package/lib/runtime/routing.js +44 -0
  488. package/lib/runtime/safety.d.ts +15 -0
  489. package/lib/runtime/safety.js +28 -0
  490. package/lib/runtime/session.d.ts +147 -0
  491. package/lib/runtime/session.js +214 -0
  492. package/lib/runtime/sessionStore.d.ts +24 -0
  493. package/lib/runtime/sessionStore.js +20 -0
  494. package/lib/runtime/telemetry.d.ts +24 -0
  495. package/lib/runtime/telemetry.js +33 -0
  496. package/lib/runtime/turnStore.d.ts +16 -0
  497. package/lib/runtime/turnStore.js +15 -0
  498. package/lib/scenario/index.d.ts +1 -0
  499. package/lib/scenario/index.js +1 -0
  500. package/lib/scenario/scenario.d.ts +52 -0
  501. package/lib/scenario/scenario.js +210 -0
  502. package/lib/semantic/canonical.d.ts +6 -0
  503. package/lib/semantic/canonical.js +22 -0
  504. package/lib/semantic/index.d.ts +2 -0
  505. package/lib/semantic/index.js +2 -0
  506. package/lib/semantic/sha256.d.ts +1 -0
  507. package/lib/semantic/sha256.js +66 -0
  508. package/lib/storage/appendLog.d.ts +145 -0
  509. package/lib/storage/appendLog.js +299 -0
  510. package/lib/storage/fileAppendSink.d.ts +7 -0
  511. package/lib/storage/fileAppendSink.js +34 -0
  512. package/lib/storage/index.d.ts +2 -0
  513. package/lib/storage/index.js +2 -0
  514. package/lib/store/bindCache.d.ts +9 -0
  515. package/lib/store/bindCache.js +18 -0
  516. package/lib/store/cache.d.ts +48 -0
  517. package/lib/store/cache.js +162 -0
  518. package/lib/store/context.d.ts +10 -0
  519. package/lib/store/context.js +27 -0
  520. package/lib/store/handleStore.d.ts +9 -0
  521. package/lib/store/handleStore.js +25 -0
  522. package/lib/store/index.d.ts +9 -0
  523. package/lib/store/index.js +8 -0
  524. package/lib/store/messageStore.d.ts +9 -0
  525. package/lib/store/messageStore.js +25 -0
  526. package/lib/store/objectStore.d.ts +9 -0
  527. package/lib/store/objectStore.js +25 -0
  528. package/lib/store/processStore.d.ts +9 -0
  529. package/lib/store/processStore.js +25 -0
  530. package/lib/store/threadStore.d.ts +9 -0
  531. package/lib/store/threadStore.js +25 -0
  532. package/lib/store/windowStore.d.ts +9 -0
  533. package/lib/store/windowStore.js +25 -0
  534. package/lib/structure/abstractSyntaxTree.d.ts +181 -0
  535. package/lib/structure/abstractSyntaxTree.js +400 -0
  536. package/lib/structure/avlTree.d.ts +125 -0
  537. package/lib/structure/avlTree.js +369 -0
  538. package/lib/structure/binarySearchTree.d.ts +125 -0
  539. package/lib/structure/binarySearchTree.js +306 -0
  540. package/lib/structure/binaryTree.d.ts +174 -0
  541. package/lib/structure/binaryTree.js +495 -0
  542. package/lib/structure/bloomFilter.d.ts +126 -0
  543. package/lib/structure/bloomFilter.js +177 -0
  544. package/lib/structure/compare.d.ts +55 -0
  545. package/lib/structure/compare.js +96 -0
  546. package/lib/structure/cuckooFilter.d.ts +149 -0
  547. package/lib/structure/cuckooFilter.js +267 -0
  548. package/lib/structure/deque.d.ts +117 -0
  549. package/lib/structure/deque.js +205 -0
  550. package/lib/structure/filterKey.d.ts +19 -0
  551. package/lib/structure/filterKey.js +28 -0
  552. package/lib/structure/hash.d.ts +129 -0
  553. package/lib/structure/hash.js +241 -0
  554. package/lib/structure/heap.d.ts +152 -0
  555. package/lib/structure/heap.js +227 -0
  556. package/lib/structure/index.d.ts +20 -0
  557. package/lib/structure/index.js +20 -0
  558. package/lib/structure/iterator.d.ts +6 -0
  559. package/lib/structure/iterator.js +16 -0
  560. package/lib/structure/lru.d.ts +235 -0
  561. package/lib/structure/lru.js +524 -0
  562. package/lib/structure/ordered.d.ts +89 -0
  563. package/lib/structure/ordered.js +336 -0
  564. package/lib/structure/priority.d.ts +499 -0
  565. package/lib/structure/priority.js +756 -0
  566. package/lib/structure/queue.d.ts +90 -0
  567. package/lib/structure/queue.js +154 -0
  568. package/lib/structure/redBlackTree.d.ts +142 -0
  569. package/lib/structure/redBlackTree.js +644 -0
  570. package/lib/structure/segmentTree.d.ts +129 -0
  571. package/lib/structure/segmentTree.js +205 -0
  572. package/lib/structure/stack.d.ts +77 -0
  573. package/lib/structure/stack.js +107 -0
  574. package/lib/structure/unordered.d.ts +99 -0
  575. package/lib/structure/unordered.js +341 -0
  576. package/lib/thread/index.d.ts +2 -0
  577. package/lib/thread/index.js +2 -0
  578. package/lib/thread/thread.d.ts +107 -0
  579. package/lib/thread/thread.js +81 -0
  580. package/lib/thread/transitions.d.ts +8 -0
  581. package/lib/thread/transitions.js +9 -0
  582. package/lib/types/common.d.ts +80 -0
  583. package/lib/types/common.js +5 -0
  584. package/lib/types/index.d.ts +23 -0
  585. package/lib/types/index.js +1 -0
  586. package/lib/warrant/epistemic.d.ts +141 -0
  587. package/lib/warrant/epistemic.js +1 -0
  588. package/lib/warrant/index.d.ts +3 -0
  589. package/lib/warrant/index.js +3 -0
  590. package/lib/warrant/inquiry.d.ts +69 -0
  591. package/lib/warrant/inquiry.js +119 -0
  592. package/lib/warrant/warrant.d.ts +46 -0
  593. package/lib/warrant/warrant.js +153 -0
  594. package/lib/window/compaction.d.ts +57 -0
  595. package/lib/window/compaction.js +334 -0
  596. package/lib/window/compactionTypes.d.ts +113 -0
  597. package/lib/window/compactionTypes.js +1 -0
  598. package/lib/window/index.d.ts +7 -0
  599. package/lib/window/index.js +3 -0
  600. package/lib/window/page.d.ts +16 -0
  601. package/lib/window/page.js +2 -0
  602. package/lib/window/window.d.ts +68 -0
  603. package/lib/window/window.js +194 -0
  604. package/package.json +22 -1
  605. package/src/authz/index.ts +1 -0
  606. package/src/concept/index.ts +3 -0
  607. package/src/concurrency/index.ts +5 -0
  608. package/src/cooperation/index.ts +6 -0
  609. package/src/delegate/index.ts +2 -0
  610. package/src/error/index.ts +7 -0
  611. package/src/evaluation/index.ts +2 -0
  612. package/src/execution/index.ts +3 -0
  613. package/src/frame/index.ts +1 -0
  614. package/src/index.ts +11 -0
  615. package/src/ledger/index.ts +4 -0
  616. package/src/manifest/index.ts +8 -0
  617. package/src/policy/index.ts +2 -0
  618. package/src/protocol/index.ts +6 -0
  619. package/src/receipt/index.ts +1 -0
  620. package/src/semantic/index.ts +2 -0
  621. package/src/storage/index.ts +2 -0
  622. package/src/structure/index.ts +20 -0
  623. package/src/thread/index.ts +2 -0
  624. package/src/warrant/index.ts +3 -0
  625. package/src/window/index.ts +7 -4
  626. package/tools/rewrite-declaration-extensions.ts +98 -0
  627. package/tsconfig.build.json +14 -0
@@ -0,0 +1,416 @@
1
+ /**
2
+ * DDL for the SQLite store. Migrations live in the store, not here.
3
+ */
4
+ export const MetaSchema = `
5
+ CREATE TABLE IF NOT EXISTS meta (
6
+ key TEXT PRIMARY KEY,
7
+ value TEXT NOT NULL
8
+ );
9
+ `;
10
+ export const Schema = `
11
+ CREATE TABLE IF NOT EXISTS objects (
12
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
13
+ kind TEXT NOT NULL,
14
+ id TEXT NOT NULL,
15
+ body TEXT NOT NULL,
16
+ hash TEXT NOT NULL,
17
+ prev TEXT NOT NULL,
18
+ at TEXT NOT NULL,
19
+ UNIQUE(kind, id)
20
+ );
21
+ CREATE INDEX IF NOT EXISTS objects_kind_seq ON objects(kind, seq);
22
+
23
+ CREATE TABLE IF NOT EXISTS processes (
24
+ pid INTEGER PRIMARY KEY AUTOINCREMENT,
25
+ id TEXT NOT NULL UNIQUE,
26
+ name TEXT NOT NULL,
27
+ role TEXT,
28
+ state TEXT NOT NULL CHECK(state IN ('created','running','idle','suspended','terminated')),
29
+ priority INTEGER NOT NULL DEFAULT 0,
30
+ budget TEXT NOT NULL,
31
+ used TEXT NOT NULL,
32
+ parent_pid INTEGER REFERENCES processes(pid),
33
+ created_at TEXT NOT NULL,
34
+ started_at TEXT,
35
+ terminated_at TEXT,
36
+ exit_code TEXT,
37
+ exit_note TEXT,
38
+ version INTEGER NOT NULL DEFAULT 0
39
+ );
40
+ CREATE INDEX IF NOT EXISTS processes_state ON processes(state, priority DESC);
41
+
42
+ CREATE TABLE IF NOT EXISTS threads (
43
+ tid INTEGER PRIMARY KEY AUTOINCREMENT,
44
+ id TEXT NOT NULL UNIQUE,
45
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
46
+ goal TEXT NOT NULL,
47
+ statement TEXT NOT NULL,
48
+ success TEXT NOT NULL,
49
+ state TEXT NOT NULL CHECK(state IN ('ready','running','blocked','done','failed','abandoned')),
50
+ priority INTEGER NOT NULL DEFAULT 0,
51
+ quantum_ms INTEGER NOT NULL DEFAULT 1000,
52
+ slice_used_ms INTEGER NOT NULL DEFAULT 0,
53
+ budget TEXT NOT NULL,
54
+ used TEXT NOT NULL,
55
+ blocked_on TEXT,
56
+ wake_at TEXT,
57
+ created_at TEXT NOT NULL,
58
+ finished_at TEXT,
59
+ exit_note TEXT,
60
+ owner_worker TEXT,
61
+ lease INTEGER NOT NULL DEFAULT 0,
62
+ version INTEGER NOT NULL DEFAULT 0
63
+ );
64
+ CREATE INDEX IF NOT EXISTS threads_ready ON threads(state, priority DESC, tid);
65
+ CREATE INDEX IF NOT EXISTS threads_pid ON threads(pid, state);
66
+ CREATE UNIQUE INDEX IF NOT EXISTS threads_one_running_per_process ON threads(pid) WHERE state = 'running';
67
+
68
+ CREATE TABLE IF NOT EXISTS steps (
69
+ step_id INTEGER PRIMARY KEY AUTOINCREMENT,
70
+ pid INTEGER NOT NULL,
71
+ tid INTEGER NOT NULL,
72
+ at TEXT NOT NULL,
73
+ outcome TEXT NOT NULL,
74
+ usage TEXT NOT NULL,
75
+ note TEXT,
76
+ receipt_id TEXT
77
+ );
78
+ CREATE INDEX IF NOT EXISTS steps_pid ON steps(pid, step_id);
79
+
80
+ /* Address space: which immutable objects a process can see. Inherited rows are
81
+ copy-on-write views of the parent's warrant; writing creates a new object. */
82
+ CREATE TABLE IF NOT EXISTS process_objects (
83
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
84
+ seq INTEGER NOT NULL REFERENCES objects(seq) ON DELETE CASCADE,
85
+ role TEXT NOT NULL CHECK(role IN ('own','inherited','mapped','joined')),
86
+ mode TEXT NOT NULL CHECK(mode IN ('read','write')),
87
+ attached_at TEXT NOT NULL,
88
+ PRIMARY KEY (pid, seq)
89
+ );
90
+ CREATE INDEX IF NOT EXISTS process_objects_pid ON process_objects(pid, seq);
91
+
92
+ /* Capability table: a handle is an unforgeable row over ANY resource, carrying
93
+ rights, scope and expiry. Ownership is implicit for the owner process; every
94
+ other subject needs a row here. Grants create a child row in another subject,
95
+ and revoke walks the tree, so a revoked parent invalidates every grant below
96
+ it. This is the only isolation mechanism a logical process has. */
97
+ CREATE TABLE IF NOT EXISTS handles (
98
+ hid INTEGER PRIMARY KEY AUTOINCREMENT,
99
+ id TEXT NOT NULL UNIQUE,
100
+ subject_kind TEXT NOT NULL CHECK(subject_kind IN ('host','process','thread')),
101
+ subject_id TEXT NOT NULL,
102
+ subject_pid INTEGER,
103
+ resource_kind TEXT NOT NULL CHECK(resource_kind IN ('object','process','thread','mailbox','budget')),
104
+ resource_id TEXT NOT NULL,
105
+ owner_pid INTEGER,
106
+ rights TEXT NOT NULL,
107
+ scope TEXT NOT NULL CHECK(scope IN ('process','thread','shared')),
108
+ parent_hid INTEGER REFERENCES handles(hid),
109
+ refcount INTEGER NOT NULL DEFAULT 1,
110
+ expires_at TEXT,
111
+ revoked_at TEXT,
112
+ granted_by TEXT,
113
+ created_at TEXT NOT NULL
114
+ );
115
+ CREATE INDEX IF NOT EXISTS handles_subject ON handles(subject_kind, subject_id, resource_kind, resource_id);
116
+ CREATE INDEX IF NOT EXISTS handles_parent ON handles(parent_hid);
117
+
118
+ /* Inter-process messages: bounded mailbox per recipient, delivered exactly once
119
+ by delivered_at; the delivery writes a receipt object so the exchange is in
120
+ the evidence chain. Intra-process traffic uses the blackboard, not this table. */
121
+ CREATE TABLE IF NOT EXISTS messages (
122
+ msg_id INTEGER PRIMARY KEY AUTOINCREMENT,
123
+ id TEXT NOT NULL UNIQUE,
124
+ from_pid INTEGER NOT NULL REFERENCES processes(pid),
125
+ from_tid INTEGER NOT NULL,
126
+ to_pid INTEGER NOT NULL REFERENCES processes(pid),
127
+ to_tid INTEGER,
128
+ kind TEXT NOT NULL CHECK(kind IN ('request','response','event','signal')),
129
+ body TEXT NOT NULL,
130
+ correlation_id TEXT,
131
+ at TEXT NOT NULL,
132
+ delivered_at TEXT,
133
+ receipt_id TEXT
134
+ );
135
+ CREATE INDEX IF NOT EXISTS messages_inbox ON messages(to_pid, delivered_at, msg_id);
136
+
137
+ /* Worker registry: every kernel instance that touches the store has an entry
138
+ and a heartbeat. A thread is owned by exactly one worker (fencing lease), so
139
+ another worker can recover it only after the owner's lease expires. */
140
+ CREATE TABLE IF NOT EXISTS workers (
141
+ worker_id TEXT PRIMARY KEY,
142
+ host TEXT,
143
+ pid INTEGER,
144
+ started_at TEXT NOT NULL,
145
+ heartbeat_at TEXT NOT NULL,
146
+ expires_at TEXT NOT NULL
147
+ );
148
+ CREATE INDEX IF NOT EXISTS workers_expiry ON workers(expires_at);
149
+
150
+ /* Idempotency: external effects and message sends are keyed, so a retry after a
151
+ crash returns the stored result instead of performing the effect twice. */
152
+ CREATE TABLE IF NOT EXISTS idempotency (
153
+ key TEXT PRIMARY KEY,
154
+ result TEXT NOT NULL,
155
+ created_at TEXT NOT NULL
156
+ );
157
+
158
+ /* Context window: a per-thread address space. Pages point at immutable objects;
159
+ the page table is durable so a restart can rebuild the resident set instead
160
+ of pretending the model still remembers it. */
161
+ CREATE TABLE IF NOT EXISTS windows (
162
+ tid INTEGER PRIMARY KEY,
163
+ capacity_tokens INTEGER NOT NULL,
164
+ used_tokens INTEGER NOT NULL,
165
+ updated_at TEXT NOT NULL
166
+ );
167
+
168
+ CREATE TABLE IF NOT EXISTS window_pages (
169
+ tid INTEGER NOT NULL,
170
+ page_id TEXT NOT NULL,
171
+ object_kind TEXT NOT NULL,
172
+ object_id TEXT NOT NULL,
173
+ tokens INTEGER NOT NULL,
174
+ pinned INTEGER NOT NULL,
175
+ last_used INTEGER NOT NULL,
176
+ PRIMARY KEY (tid, page_id)
177
+ );
178
+ CREATE INDEX IF NOT EXISTS window_pages_tid ON window_pages(tid, last_used);
179
+
180
+ /* Cross-worker mutual exclusion for a named resource (file, session, tab).
181
+ A lease is a capability's sibling: permission says "may", a lock says "now". */
182
+ CREATE TABLE IF NOT EXISTS resource_locks (
183
+ name TEXT PRIMARY KEY,
184
+ holder TEXT NOT NULL,
185
+ fencing INTEGER NOT NULL DEFAULT 0,
186
+ acquired_at TEXT NOT NULL,
187
+ expires_at TEXT NOT NULL
188
+ );
189
+
190
+ /* Registry: concepts and modules are data, not only directories.
191
+ Each declaration writes an object; the row keeps the latest version and the
192
+ object seq, so "this module exists" is a checkable claim, not a convention. */
193
+ CREATE TABLE IF NOT EXISTS concepts (
194
+ cid INTEGER PRIMARY KEY AUTOINCREMENT,
195
+ id TEXT NOT NULL UNIQUE,
196
+ label TEXT NOT NULL,
197
+ definition TEXT NOT NULL,
198
+ status TEXT NOT NULL CHECK(status IN ('proposed','active','deprecated')),
199
+ version INTEGER NOT NULL,
200
+ object_seq INTEGER,
201
+ digest TEXT,
202
+ created_at TEXT NOT NULL,
203
+ updated_at TEXT NOT NULL
204
+ );
205
+
206
+ CREATE TABLE IF NOT EXISTS modules (
207
+ mid INTEGER PRIMARY KEY AUTOINCREMENT,
208
+ id TEXT NOT NULL UNIQUE,
209
+ kind TEXT NOT NULL CHECK(kind IN ('kernel','database','domain','protocol','module','structure','tool','boundary')),
210
+ entry TEXT NOT NULL,
211
+ description TEXT NOT NULL,
212
+ status TEXT NOT NULL CHECK(status IN ('planned','active','deprecated')),
213
+ version INTEGER NOT NULL,
214
+ object_seq INTEGER,
215
+ digest TEXT,
216
+ content_digest TEXT,
217
+ created_at TEXT NOT NULL,
218
+ updated_at TEXT NOT NULL
219
+ );
220
+
221
+ CREATE TABLE IF NOT EXISTS module_concepts (
222
+ mid INTEGER NOT NULL REFERENCES modules(mid) ON DELETE CASCADE,
223
+ cid INTEGER NOT NULL REFERENCES concepts(cid) ON DELETE CASCADE,
224
+ role TEXT NOT NULL CHECK(role IN ('owns','uses','constrains','implements')),
225
+ PRIMARY KEY (mid, cid, role)
226
+ );
227
+
228
+ CREATE TABLE IF NOT EXISTS module_dependencies (
229
+ mid INTEGER NOT NULL REFERENCES modules(mid) ON DELETE CASCADE,
230
+ depends_on_mid INTEGER NOT NULL REFERENCES modules(mid) ON DELETE CASCADE,
231
+ reason TEXT,
232
+ PRIMARY KEY (mid, depends_on_mid)
233
+ );
234
+
235
+ CREATE TABLE IF NOT EXISTS attestations (
236
+ aid INTEGER PRIMARY KEY AUTOINCREMENT,
237
+ subject_kind TEXT NOT NULL CHECK(subject_kind IN ('concept','module')),
238
+ subject_id TEXT NOT NULL,
239
+ claim_id TEXT NOT NULL,
240
+ object_seq INTEGER,
241
+ at TEXT NOT NULL
242
+ );
243
+ CREATE INDEX IF NOT EXISTS attestations_subject ON attestations(subject_kind, subject_id);
244
+
245
+ /* Person layer: an agent is a person, not a prompt.
246
+ Self is narrative (versioned), roles are social positions, memory is typed,
247
+ affect is state, relationships and institutions constitute the social person. */
248
+ CREATE TABLE IF NOT EXISTS person_profiles (
249
+ pid INTEGER PRIMARY KEY REFERENCES processes(pid) ON DELETE CASCADE,
250
+ name TEXT NOT NULL,
251
+ narrative TEXT NOT NULL DEFAULT '',
252
+ values_json TEXT NOT NULL DEFAULT '[]',
253
+ constraints_json TEXT NOT NULL DEFAULT '[]',
254
+ life_chapter TEXT NOT NULL DEFAULT 'starting',
255
+ updated_at TEXT NOT NULL,
256
+ version INTEGER NOT NULL DEFAULT 1
257
+ );
258
+
259
+ CREATE TABLE IF NOT EXISTS self_narratives (
260
+ snid INTEGER PRIMARY KEY AUTOINCREMENT,
261
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
262
+ version INTEGER NOT NULL,
263
+ identity_json TEXT NOT NULL DEFAULT '{}',
264
+ narrative TEXT NOT NULL,
265
+ at TEXT NOT NULL,
266
+ object_seq INTEGER,
267
+ UNIQUE(pid, version)
268
+ );
269
+
270
+ CREATE TABLE IF NOT EXISTS roles (
271
+ rid INTEGER PRIMARY KEY AUTOINCREMENT,
272
+ id TEXT NOT NULL UNIQUE,
273
+ label TEXT NOT NULL,
274
+ obligations_json TEXT NOT NULL DEFAULT '[]',
275
+ permissions_json TEXT NOT NULL DEFAULT '[]',
276
+ audiences_json TEXT NOT NULL DEFAULT '[]',
277
+ scripts_json TEXT NOT NULL DEFAULT '[]',
278
+ status TEXT NOT NULL CHECK(status IN ('active','retired')) DEFAULT 'active',
279
+ created_at TEXT NOT NULL
280
+ );
281
+
282
+ CREATE TABLE IF NOT EXISTS person_roles (
283
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
284
+ rid INTEGER NOT NULL REFERENCES roles(rid) ON DELETE CASCADE,
285
+ salience REAL NOT NULL DEFAULT 0.5,
286
+ active INTEGER NOT NULL DEFAULT 0,
287
+ since TEXT NOT NULL,
288
+ PRIMARY KEY (pid, rid)
289
+ );
290
+ CREATE UNIQUE INDEX IF NOT EXISTS person_roles_one_active ON person_roles(pid) WHERE active = 1;
291
+
292
+ CREATE TABLE IF NOT EXISTS memories (
293
+ mem_id INTEGER PRIMARY KEY AUTOINCREMENT,
294
+ id TEXT NOT NULL UNIQUE,
295
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
296
+ role_id TEXT,
297
+ kind TEXT NOT NULL CHECK(kind IN ('episodic','semantic','procedural','social','affective')),
298
+ content TEXT NOT NULL,
299
+ salience REAL NOT NULL DEFAULT 0.5,
300
+ at TEXT NOT NULL,
301
+ refs_json TEXT NOT NULL DEFAULT '[]',
302
+ source TEXT,
303
+ consolidated INTEGER NOT NULL DEFAULT 0
304
+ );
305
+ CREATE INDEX IF NOT EXISTS memories_pid ON memories(pid, salience DESC, at DESC);
306
+
307
+ CREATE TABLE IF NOT EXISTS affect_states (
308
+ pid INTEGER PRIMARY KEY REFERENCES processes(pid) ON DELETE CASCADE,
309
+ valence REAL NOT NULL DEFAULT 0,
310
+ arousal REAL NOT NULL DEFAULT 0,
311
+ stress REAL NOT NULL DEFAULT 0,
312
+ fatigue REAL NOT NULL DEFAULT 0,
313
+ mood TEXT NOT NULL DEFAULT 'neutral',
314
+ updated_at TEXT NOT NULL
315
+ );
316
+
317
+ CREATE TABLE IF NOT EXISTS relationships (
318
+ rel_id INTEGER PRIMARY KEY AUTOINCREMENT,
319
+ id TEXT NOT NULL UNIQUE,
320
+ from_pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
321
+ to_pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
322
+ kind TEXT NOT NULL,
323
+ trust REAL NOT NULL DEFAULT 0.5,
324
+ attachment REAL NOT NULL DEFAULT 0.5,
325
+ obligations_json TEXT NOT NULL DEFAULT '[]',
326
+ since TEXT NOT NULL,
327
+ last_contact TEXT
328
+ );
329
+ CREATE UNIQUE INDEX IF NOT EXISTS relationships_pair ON relationships(from_pid, to_pid, kind);
330
+
331
+ CREATE TABLE IF NOT EXISTS institutions (
332
+ iid INTEGER PRIMARY KEY AUTOINCREMENT,
333
+ id TEXT NOT NULL UNIQUE,
334
+ name TEXT NOT NULL,
335
+ norms_json TEXT NOT NULL DEFAULT '[]'
336
+ );
337
+
338
+ CREATE TABLE IF NOT EXISTS memberships (
339
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
340
+ iid INTEGER NOT NULL REFERENCES institutions(iid) ON DELETE CASCADE,
341
+ role TEXT NOT NULL,
342
+ status TEXT NOT NULL CHECK(status IN ('active','left')) DEFAULT 'active',
343
+ since TEXT NOT NULL,
344
+ PRIMARY KEY (pid, iid)
345
+ );
346
+
347
+ CREATE TABLE IF NOT EXISTS background_processes (
348
+ bpid INTEGER PRIMARY KEY AUTOINCREMENT,
349
+ id TEXT NOT NULL UNIQUE,
350
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
351
+ kind TEXT NOT NULL CHECK(kind IN ('habit','emotion','monitor','drive')),
352
+ label TEXT NOT NULL,
353
+ intensity REAL NOT NULL DEFAULT 0.5,
354
+ trigger TEXT,
355
+ script TEXT,
356
+ status TEXT NOT NULL CHECK(status IN ('active','paused','retired')) DEFAULT 'active',
357
+ updated_at TEXT NOT NULL
358
+ );
359
+ CREATE INDEX IF NOT EXISTS background_pid ON background_processes(pid, status, intensity DESC);
360
+
361
+ CREATE TABLE IF NOT EXISTS life_events (
362
+ ev_id INTEGER PRIMARY KEY AUTOINCREMENT,
363
+ id TEXT NOT NULL UNIQUE,
364
+ pid INTEGER NOT NULL REFERENCES processes(pid) ON DELETE CASCADE,
365
+ kind TEXT NOT NULL,
366
+ summary TEXT NOT NULL,
367
+ at TEXT NOT NULL,
368
+ role_id TEXT,
369
+ impact REAL NOT NULL DEFAULT 0.5,
370
+ narrative_version INTEGER
371
+ );
372
+ CREATE INDEX IF NOT EXISTS life_events_pid ON life_events(pid, at DESC);
373
+
374
+ /* Transactional outbox for runtime receipts/events. Rows are written by the
375
+ application transaction and dispatched later; this keeps the runtime sink
376
+ observable without making the domain depend on SQLite. */
377
+ CREATE TABLE IF NOT EXISTS outbox (
378
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
379
+ topic TEXT NOT NULL,
380
+ payload TEXT NOT NULL,
381
+ created_at TEXT NOT NULL,
382
+ dispatched_at TEXT
383
+ );
384
+ CREATE INDEX IF NOT EXISTS outbox_pending ON outbox(dispatched_at, id);
385
+
386
+ /* Runtime session snapshots (attention state + priors + history). */
387
+ CREATE TABLE IF NOT EXISTS runtime_sessions (
388
+ pid INTEGER PRIMARY KEY,
389
+ data TEXT NOT NULL,
390
+ updated_at TEXT NOT NULL
391
+ );
392
+
393
+ /* Queryable turn snapshots (JSON includes actions/operations/behavior). */
394
+ CREATE TABLE IF NOT EXISTS runtime_turns (
395
+ id TEXT PRIMARY KEY,
396
+ pid INTEGER NOT NULL,
397
+ session_id TEXT,
398
+ data TEXT NOT NULL,
399
+ created_at TEXT NOT NULL
400
+ );
401
+ CREATE INDEX IF NOT EXISTS runtime_turns_pid ON runtime_turns(pid, created_at DESC);
402
+
403
+ /* Independent approval audit rows; the outbox carries the dispatch copy. */
404
+ CREATE TABLE IF NOT EXISTS runtime_approvals (
405
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
406
+ pid INTEGER NOT NULL,
407
+ turn_id TEXT NOT NULL,
408
+ operation_id TEXT NOT NULL,
409
+ tool TEXT NOT NULL,
410
+ risk TEXT NOT NULL,
411
+ decision TEXT NOT NULL,
412
+ status TEXT NOT NULL,
413
+ created_at TEXT NOT NULL
414
+ );
415
+ CREATE INDEX IF NOT EXISTS runtime_approvals_pid ON runtime_approvals(pid, id DESC);
416
+ `;
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Generic SQL layer for one table.
3
+ *
4
+ * Every concrete table adapter extends {@link Sql} and supplies its
5
+ * {@link TableMeta}. The base class owns the statement shapes shared by all
6
+ * tables: primary-key lookup, list, count, insert, update, delete, upsert and
7
+ * existence checks. Table-specific queries belong in a concrete subclass and
8
+ * use the protected `query`, `queryOne`, `run` and `quote` helpers.
9
+ *
10
+ * Parameters are always bound; identifiers come from trusted {@link TableMeta}
11
+ * values and are validated before they are interpolated.
12
+ */
13
+ import type { DatabaseSync } from "node:sqlite";
14
+ import type { PrimaryKey } from "../entity/entity.js";
15
+ import type { TableMeta } from "../entity/meta.js";
16
+ /**
17
+ * Value accepted by a SQLite bound parameter.
18
+ */
19
+ export type SqlParameter = string | number | bigint | null | Uint8Array;
20
+ /**
21
+ * Result of an INSERT, UPDATE or DELETE statement.
22
+ */
23
+ export interface MutationResult {
24
+ /**
25
+ * Number of rows changed by the statement.
26
+ */
27
+ readonly changes: number;
28
+ /**
29
+ * SQLite rowid generated by an INSERT, or zero when none was generated.
30
+ */
31
+ readonly lastInsertRowid: number | bigint;
32
+ }
33
+ /**
34
+ * Options for a generated SELECT.
35
+ */
36
+ export interface SelectOptions {
37
+ /**
38
+ * Optional SQL after WHERE.
39
+ */
40
+ readonly where?: string;
41
+ /**
42
+ * Bound values for the WHERE fragment.
43
+ */
44
+ readonly params?: readonly SqlParameter[];
45
+ /**
46
+ * Full ORDER BY fragment, for example a value returned by `Sort.toSql()`.
47
+ */
48
+ readonly orderBy?: string;
49
+ /**
50
+ * Maximum row count.
51
+ */
52
+ readonly limit?: number;
53
+ /**
54
+ * Number of rows to skip.
55
+ */
56
+ readonly offset?: number;
57
+ /**
58
+ * Optional column projection.
59
+ */
60
+ readonly columns?: readonly string[];
61
+ }
62
+ /**
63
+ * Convert a JavaScript value into a value `node:sqlite` can bind.
64
+ *
65
+ * Booleans become `1`/`0`, `undefined` becomes `NULL`, and unsupported object
66
+ * types fail early instead of being stringified silently.
67
+ *
68
+ * @param value - Value from a repository or service.
69
+ * @returns A bindable SQLite parameter.
70
+ * @throws TypeError when the value has no SQLite representation.
71
+ */
72
+ export declare const toSqlParameter: (value: unknown) => SqlParameter;
73
+ /**
74
+ * Validate a SQL identifier before it is interpolated into a statement.
75
+ *
76
+ * @param identifier - Table or column name.
77
+ * @returns The identifier unchanged.
78
+ * @throws Error when the identifier contains anything except letters, digits
79
+ * and underscores, or when it starts with a digit.
80
+ */
81
+ export declare const assertSqlIdentifier: (identifier: string) => string;
82
+ /**
83
+ * Abstract CRUD adapter for a single table.
84
+ *
85
+ * @typeParam TEntity - Row shape returned by the table.
86
+ * @typeParam TKey - Primary-key type.
87
+ */
88
+ export declare abstract class Sql<TEntity extends object, TKey extends PrimaryKey = PrimaryKey> {
89
+ protected readonly db: DatabaseSync;
90
+ readonly meta: TableMeta;
91
+ private readonly columnSet;
92
+ /**
93
+ * Create a table adapter.
94
+ *
95
+ * @param db - Open SQLite connection.
96
+ * @param meta - Table, primary key and column metadata.
97
+ */
98
+ protected constructor(db: DatabaseSync, meta: TableMeta);
99
+ /**
100
+ * Physical table name.
101
+ */
102
+ get table(): string;
103
+ /**
104
+ * Primary-key column name.
105
+ */
106
+ get primaryKey(): string;
107
+ /**
108
+ * Columns allowed in generated statements.
109
+ */
110
+ get columns(): readonly string[];
111
+ /**
112
+ * Find one row by primary key.
113
+ *
114
+ * @param id - Primary-key value.
115
+ * @returns The row, or `undefined` when absent.
116
+ */
117
+ findById(id: TKey): TEntity | undefined;
118
+ /**
119
+ * Read rows in unspecified order.
120
+ *
121
+ * @param limit - Maximum row count.
122
+ * @returns Matching rows.
123
+ */
124
+ all(limit?: number): TEntity[];
125
+ /**
126
+ * Read rows with a trusted SQL WHERE fragment.
127
+ *
128
+ * The fragment is not analyzed; callers must pass only literals and
129
+ * placeholders, never interpolated user input.
130
+ *
131
+ * @param clause - SQL after `WHERE`.
132
+ * @param params - Bound values for the clause.
133
+ * @returns Matching rows.
134
+ */
135
+ where(clause: string, ...params: SqlParameter[]): TEntity[];
136
+ /**
137
+ * Read rows with optional filtering, ordering and pagination.
138
+ *
139
+ * @param options - Select options.
140
+ * @returns Matching rows.
141
+ */
142
+ select(options?: SelectOptions): TEntity[];
143
+ /**
144
+ * Count rows, optionally restricted by a WHERE fragment.
145
+ *
146
+ * @param clause - Optional SQL after `WHERE`.
147
+ * @param params - Bound values for the clause.
148
+ * @returns Number of matching rows.
149
+ */
150
+ count(clause?: string, ...params: SqlParameter[]): number;
151
+ /**
152
+ * Test whether a primary key exists.
153
+ *
154
+ * @param id - Primary-key value.
155
+ * @returns `true` when the row exists.
156
+ */
157
+ exists(id: TKey): boolean;
158
+ /**
159
+ * Insert one row.
160
+ *
161
+ * @param values - Column values; unknown keys are rejected.
162
+ * @returns Mutation metadata.
163
+ */
164
+ insert(values: Readonly<Record<string, unknown>>): MutationResult;
165
+ /**
166
+ * Update one row by primary key.
167
+ *
168
+ * @param id - Primary-key value.
169
+ * @param values - Column values; the primary key is ignored.
170
+ * @returns Number of changed rows.
171
+ */
172
+ update(id: TKey, values: Readonly<Record<string, unknown>>): number;
173
+ /**
174
+ * Update rows selected by a trusted WHERE fragment.
175
+ *
176
+ * @param clause - SQL after `WHERE`.
177
+ * @param values - Column values; the primary key is ignored.
178
+ * @param params - Bound values for the clause.
179
+ * @returns Number of changed rows.
180
+ */
181
+ updateWhere(clause: string, values: Readonly<Record<string, unknown>>, ...params: SqlParameter[]): number;
182
+ /**
183
+ * Delete one row by primary key.
184
+ *
185
+ * @param id - Primary-key value.
186
+ * @returns Number of deleted rows.
187
+ */
188
+ delete(id: TKey): number;
189
+ /**
190
+ * Delete rows selected by a trusted WHERE fragment.
191
+ *
192
+ * @param clause - SQL after `WHERE`.
193
+ * @param params - Bound values for the clause.
194
+ * @returns Number of deleted rows.
195
+ */
196
+ deleteWhere(clause: string, ...params: SqlParameter[]): number;
197
+ /**
198
+ * Insert a row, replacing conflicting columns on a conflict.
199
+ *
200
+ * @param values - Column values; conflict columns must be present.
201
+ * @param conflictColumns - Unique columns; defaults to the primary key.
202
+ * @returns Mutation metadata.
203
+ */
204
+ upsert(values: Readonly<Record<string, unknown>>, conflictColumns?: readonly string[]): MutationResult;
205
+ /**
206
+ * Build a SELECT column list.
207
+ *
208
+ * @param columns - Optional columns; omitted means all columns.
209
+ * @returns SQL column list.
210
+ */
211
+ private selectList;
212
+ /**
213
+ * Execute a trusted statement with bound parameters.
214
+ *
215
+ * @param sql - Complete SQL statement.
216
+ * @param params - Bound values.
217
+ * @returns Mutation metadata.
218
+ */
219
+ protected run(sql: string, ...params: SqlParameter[]): MutationResult;
220
+ /**
221
+ * Read rows from a trusted statement.
222
+ *
223
+ * @typeParam TRow - Row shape.
224
+ * @param sql - Complete SQL statement.
225
+ * @param params - Bound values.
226
+ * @returns Rows.
227
+ */
228
+ query<TRow>(sql: string, ...params: SqlParameter[]): TRow[];
229
+ /**
230
+ * Read one row from a trusted statement.
231
+ *
232
+ * @typeParam TRow - Row shape.
233
+ * @param sql - Complete SQL statement.
234
+ * @param params - Bound values.
235
+ * @returns The row, or `undefined`.
236
+ */
237
+ queryOne<TRow>(sql: string, ...params: SqlParameter[]): TRow | undefined;
238
+ /**
239
+ * Quote an identifier after validating it.
240
+ *
241
+ * @param identifier - Table or column name.
242
+ * @returns Double-quoted identifier.
243
+ */
244
+ protected quote(identifier: string): string;
245
+ /**
246
+ * Check that the table metadata is internally consistent.
247
+ */
248
+ private assertMeta;
249
+ /**
250
+ * Select writable columns from a value map.
251
+ *
252
+ * @param values - Caller-supplied values.
253
+ * @param includePrimaryKey - Whether the primary key is writable.
254
+ * @returns Ordered column names.
255
+ */
256
+ private collectColumns;
257
+ /**
258
+ * Build bound parameters in column order.
259
+ *
260
+ * @param values - Caller-supplied values.
261
+ * @param columns - Ordered column names.
262
+ * @returns Bindable parameters.
263
+ */
264
+ private collectParams;
265
+ /**
266
+ * Validate and normalize a LIMIT value.
267
+ *
268
+ * @param limit - Requested row count.
269
+ * @returns A non-negative integer.
270
+ */
271
+ private normalizeLimit;
272
+ }
273
+ /**
274
+ * Concrete SQL adapter for a table that only needs generated CRUD statements.
275
+ *
276
+ * Table-specific operations can instead subclass {@link Sql} and use the
277
+ * public query helpers.
278
+ *
279
+ * @typeParam TEntity - Row shape returned by the table.
280
+ * @typeParam TKey - Primary-key type.
281
+ */
282
+ export declare class TableSql<TEntity extends object, TKey extends PrimaryKey = PrimaryKey> extends Sql<TEntity, TKey> {
283
+ /**
284
+ * Create a generated table adapter.
285
+ *
286
+ * @param db - Open SQLite connection.
287
+ * @param meta - Table, primary key and column metadata.
288
+ */
289
+ constructor(db: DatabaseSync, meta: TableMeta);
290
+ }