@cavelang/cli 0.27.14 → 0.29.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 (321) hide show
  1. package/Authors.md +5 -0
  2. package/License.md +6 -0
  3. package/README.md +122 -24
  4. package/dist/internal/act/action.d.ts +69 -0
  5. package/dist/internal/act/action.d.ts.map +1 -0
  6. package/dist/internal/act/action.js +201 -0
  7. package/dist/internal/act/action.js.map +1 -0
  8. package/dist/internal/act/declare.d.ts +102 -0
  9. package/dist/internal/act/declare.d.ts.map +1 -0
  10. package/dist/internal/act/declare.js +270 -0
  11. package/dist/internal/act/declare.js.map +1 -0
  12. package/dist/internal/act/engine.d.ts +103 -0
  13. package/dist/internal/act/engine.d.ts.map +1 -0
  14. package/dist/internal/act/engine.js +298 -0
  15. package/dist/internal/act/engine.js.map +1 -0
  16. package/dist/internal/act/index.d.ts +27 -0
  17. package/dist/internal/act/index.d.ts.map +1 -0
  18. package/dist/internal/act/index.js +25 -0
  19. package/dist/internal/act/index.js.map +1 -0
  20. package/dist/internal/automate/automation.d.ts +78 -0
  21. package/dist/internal/automate/automation.d.ts.map +1 -0
  22. package/dist/internal/automate/automation.js +135 -0
  23. package/dist/internal/automate/automation.js.map +1 -0
  24. package/dist/internal/automate/declare.d.ts +84 -0
  25. package/dist/internal/automate/declare.d.ts.map +1 -0
  26. package/dist/internal/automate/declare.js +233 -0
  27. package/dist/internal/automate/declare.js.map +1 -0
  28. package/dist/internal/automate/engine.d.ts +125 -0
  29. package/dist/internal/automate/engine.d.ts.map +1 -0
  30. package/dist/internal/automate/engine.js +388 -0
  31. package/dist/internal/automate/engine.js.map +1 -0
  32. package/dist/internal/automate/index.d.ts +28 -0
  33. package/dist/internal/automate/index.d.ts.map +1 -0
  34. package/dist/internal/automate/index.js +26 -0
  35. package/dist/internal/automate/index.js.map +1 -0
  36. package/dist/internal/automate/main.d.ts +26 -0
  37. package/dist/internal/automate/main.d.ts.map +1 -0
  38. package/dist/internal/automate/main.js +298 -0
  39. package/dist/internal/automate/main.js.map +1 -0
  40. package/dist/internal/connect/index.d.ts +26 -0
  41. package/dist/internal/connect/index.d.ts.map +1 -0
  42. package/dist/internal/connect/index.js +24 -0
  43. package/dist/internal/connect/index.js.map +1 -0
  44. package/dist/internal/connect/main.d.ts +23 -0
  45. package/dist/internal/connect/main.d.ts.map +1 -0
  46. package/dist/internal/connect/main.js +330 -0
  47. package/dist/internal/connect/main.js.map +1 -0
  48. package/dist/internal/connect/run.d.ts +85 -0
  49. package/dist/internal/connect/run.d.ts.map +1 -0
  50. package/dist/internal/connect/run.js +242 -0
  51. package/dist/internal/connect/run.js.map +1 -0
  52. package/dist/internal/connect/source.d.ts +44 -0
  53. package/dist/internal/connect/source.d.ts.map +1 -0
  54. package/dist/internal/connect/source.js +215 -0
  55. package/dist/internal/connect/source.js.map +1 -0
  56. package/dist/internal/connect/template.d.ts +69 -0
  57. package/dist/internal/connect/template.d.ts.map +1 -0
  58. package/dist/internal/connect/template.js +221 -0
  59. package/dist/internal/connect/template.js.map +1 -0
  60. package/dist/internal/eval/index.d.ts +28 -0
  61. package/dist/internal/eval/index.d.ts.map +1 -0
  62. package/dist/internal/eval/index.js +27 -0
  63. package/dist/internal/eval/index.js.map +1 -0
  64. package/dist/internal/eval/judge.d.ts +30 -0
  65. package/dist/internal/eval/judge.d.ts.map +1 -0
  66. package/dist/internal/eval/judge.js +101 -0
  67. package/dist/internal/eval/judge.js.map +1 -0
  68. package/dist/internal/eval/loop.d.ts +64 -0
  69. package/dist/internal/eval/loop.d.ts.map +1 -0
  70. package/dist/internal/eval/loop.js +123 -0
  71. package/dist/internal/eval/loop.js.map +1 -0
  72. package/dist/internal/eval/main.d.ts +17 -0
  73. package/dist/internal/eval/main.d.ts.map +1 -0
  74. package/dist/internal/eval/main.js +236 -0
  75. package/dist/internal/eval/main.js.map +1 -0
  76. package/dist/internal/eval/queries.d.ts +74 -0
  77. package/dist/internal/eval/queries.d.ts.map +1 -0
  78. package/dist/internal/eval/queries.js +161 -0
  79. package/dist/internal/eval/queries.js.map +1 -0
  80. package/dist/internal/eval/run.d.ts +143 -0
  81. package/dist/internal/eval/run.d.ts.map +1 -0
  82. package/dist/internal/eval/run.js +376 -0
  83. package/dist/internal/eval/run.js.map +1 -0
  84. package/dist/internal/eval/score.d.ts +81 -0
  85. package/dist/internal/eval/score.d.ts.map +1 -0
  86. package/dist/internal/eval/score.js +126 -0
  87. package/dist/internal/eval/score.js.map +1 -0
  88. package/dist/internal/eval/suite.d.ts +66 -0
  89. package/dist/internal/eval/suite.d.ts.map +1 -0
  90. package/dist/internal/eval/suite.js +130 -0
  91. package/dist/internal/eval/suite.js.map +1 -0
  92. package/dist/internal/ingest/context.d.ts +20 -0
  93. package/dist/internal/ingest/context.d.ts.map +1 -0
  94. package/dist/internal/ingest/context.js +59 -0
  95. package/dist/internal/ingest/context.js.map +1 -0
  96. package/dist/internal/ingest/files.d.ts +46 -0
  97. package/dist/internal/ingest/files.d.ts.map +1 -0
  98. package/dist/internal/ingest/files.js +115 -0
  99. package/dist/internal/ingest/files.js.map +1 -0
  100. package/dist/internal/ingest/index.d.ts +31 -0
  101. package/dist/internal/ingest/index.d.ts.map +1 -0
  102. package/dist/internal/ingest/index.js +29 -0
  103. package/dist/internal/ingest/index.js.map +1 -0
  104. package/dist/internal/ingest/main.d.ts +12 -0
  105. package/dist/internal/ingest/main.d.ts.map +1 -0
  106. package/dist/internal/ingest/main.js +180 -0
  107. package/dist/internal/ingest/main.js.map +1 -0
  108. package/dist/internal/ingest/prompt.d.ts +32 -0
  109. package/dist/internal/ingest/prompt.d.ts.map +1 -0
  110. package/dist/internal/ingest/prompt.js +75 -0
  111. package/dist/internal/ingest/prompt.js.map +1 -0
  112. package/dist/internal/ingest/run.d.ts +142 -0
  113. package/dist/internal/ingest/run.d.ts.map +1 -0
  114. package/dist/internal/ingest/run.js +350 -0
  115. package/dist/internal/ingest/run.js.map +1 -0
  116. package/dist/internal/ingest/web.d.ts +48 -0
  117. package/dist/internal/ingest/web.d.ts.map +1 -0
  118. package/dist/internal/ingest/web.js +140 -0
  119. package/dist/internal/ingest/web.js.map +1 -0
  120. package/dist/internal/loop/demo.d.ts +22 -0
  121. package/dist/internal/loop/demo.d.ts.map +1 -0
  122. package/dist/internal/loop/demo.js +67 -0
  123. package/dist/internal/loop/demo.js.map +1 -0
  124. package/dist/internal/loop/index.d.ts +20 -0
  125. package/dist/internal/loop/index.d.ts.map +1 -0
  126. package/dist/internal/loop/index.js +17 -0
  127. package/dist/internal/loop/index.js.map +1 -0
  128. package/dist/internal/loop/llm.d.ts +99 -0
  129. package/dist/internal/loop/llm.d.ts.map +1 -0
  130. package/dist/internal/loop/llm.js +231 -0
  131. package/dist/internal/loop/llm.js.map +1 -0
  132. package/dist/internal/loop/reconstruct.d.ts +87 -0
  133. package/dist/internal/loop/reconstruct.d.ts.map +1 -0
  134. package/dist/internal/loop/reconstruct.js +157 -0
  135. package/dist/internal/loop/reconstruct.js.map +1 -0
  136. package/dist/internal/loop/sqlite.d.ts +13 -0
  137. package/dist/internal/loop/sqlite.d.ts.map +1 -0
  138. package/dist/internal/loop/sqlite.js +33 -0
  139. package/dist/internal/loop/sqlite.js.map +1 -0
  140. package/dist/internal/loop/store.d.ts +50 -0
  141. package/dist/internal/loop/store.d.ts.map +1 -0
  142. package/dist/internal/loop/store.js +100 -0
  143. package/dist/internal/loop/store.js.map +1 -0
  144. package/dist/internal/mcp/bin.d.ts +7 -0
  145. package/dist/internal/mcp/bin.d.ts.map +1 -0
  146. package/dist/internal/mcp/bin.js +8 -0
  147. package/dist/internal/mcp/bin.js.map +1 -0
  148. package/dist/internal/mcp/index.d.ts +25 -0
  149. package/dist/internal/mcp/index.d.ts.map +1 -0
  150. package/dist/internal/mcp/index.js +23 -0
  151. package/dist/internal/mcp/index.js.map +1 -0
  152. package/dist/internal/mcp/main.d.ts +23 -0
  153. package/dist/internal/mcp/main.d.ts.map +1 -0
  154. package/dist/internal/mcp/main.js +156 -0
  155. package/dist/internal/mcp/main.js.map +1 -0
  156. package/dist/internal/mcp/server.d.ts +92 -0
  157. package/dist/internal/mcp/server.d.ts.map +1 -0
  158. package/dist/internal/mcp/server.js +251 -0
  159. package/dist/internal/mcp/server.js.map +1 -0
  160. package/dist/internal/mcp/tools.d.ts +91 -0
  161. package/dist/internal/mcp/tools.d.ts.map +1 -0
  162. package/dist/internal/mcp/tools.js +584 -0
  163. package/dist/internal/mcp/tools.js.map +1 -0
  164. package/dist/internal/rules/declare.d.ts +58 -0
  165. package/dist/internal/rules/declare.d.ts.map +1 -0
  166. package/dist/internal/rules/declare.js +152 -0
  167. package/dist/internal/rules/declare.js.map +1 -0
  168. package/dist/internal/rules/engine.d.ts +125 -0
  169. package/dist/internal/rules/engine.d.ts.map +1 -0
  170. package/dist/internal/rules/engine.js +575 -0
  171. package/dist/internal/rules/engine.js.map +1 -0
  172. package/dist/internal/rules/index.d.ts +23 -0
  173. package/dist/internal/rules/index.d.ts.map +1 -0
  174. package/dist/internal/rules/index.js +21 -0
  175. package/dist/internal/rules/index.js.map +1 -0
  176. package/dist/internal/rules/rule.d.ts +88 -0
  177. package/dist/internal/rules/rule.d.ts.map +1 -0
  178. package/dist/internal/rules/rule.js +221 -0
  179. package/dist/internal/rules/rule.js.map +1 -0
  180. package/dist/internal/shape/check.d.ts +118 -0
  181. package/dist/internal/shape/check.d.ts.map +1 -0
  182. package/dist/internal/shape/check.js +331 -0
  183. package/dist/internal/shape/check.js.map +1 -0
  184. package/dist/internal/shape/client.d.ts +31 -0
  185. package/dist/internal/shape/client.d.ts.map +1 -0
  186. package/dist/internal/shape/client.js +170 -0
  187. package/dist/internal/shape/client.js.map +1 -0
  188. package/dist/internal/shape/gate.d.ts +33 -0
  189. package/dist/internal/shape/gate.d.ts.map +1 -0
  190. package/dist/internal/shape/gate.js +0 -0
  191. package/dist/internal/shape/gate.js.map +1 -0
  192. package/dist/internal/shape/index.d.ts +27 -0
  193. package/dist/internal/shape/index.d.ts.map +1 -0
  194. package/dist/internal/shape/index.js +23 -0
  195. package/dist/internal/shape/index.js.map +1 -0
  196. package/dist/internal/shape/suggest.d.ts +82 -0
  197. package/dist/internal/shape/suggest.d.ts.map +1 -0
  198. package/dist/internal/shape/suggest.js +374 -0
  199. package/dist/internal/shape/suggest.js.map +1 -0
  200. package/dist/internal/sync/index.d.ts +22 -0
  201. package/dist/internal/sync/index.d.ts.map +1 -0
  202. package/dist/internal/sync/index.js +21 -0
  203. package/dist/internal/sync/index.js.map +1 -0
  204. package/dist/internal/sync/sync.d.ts +95 -0
  205. package/dist/internal/sync/sync.d.ts.map +1 -0
  206. package/dist/internal/sync/sync.js +342 -0
  207. package/dist/internal/sync/sync.js.map +1 -0
  208. package/dist/internal/view/api.d.ts +196 -0
  209. package/dist/internal/view/api.d.ts.map +1 -0
  210. package/dist/internal/view/api.js +189 -0
  211. package/dist/internal/view/api.js.map +1 -0
  212. package/dist/internal/view/index.d.ts +33 -0
  213. package/dist/internal/view/index.d.ts.map +1 -0
  214. package/dist/internal/view/index.js +30 -0
  215. package/dist/internal/view/index.js.map +1 -0
  216. package/dist/internal/view/main.d.ts +11 -0
  217. package/dist/internal/view/main.d.ts.map +1 -0
  218. package/dist/internal/view/main.js +98 -0
  219. package/dist/internal/view/main.js.map +1 -0
  220. package/dist/internal/view/page.d.ts +14 -0
  221. package/dist/internal/view/page.d.ts.map +1 -0
  222. package/dist/internal/view/page.js +370 -0
  223. package/dist/internal/view/page.js.map +1 -0
  224. package/dist/internal/view/report.d.ts +52 -0
  225. package/dist/internal/view/report.d.ts.map +1 -0
  226. package/dist/internal/view/report.js +367 -0
  227. package/dist/internal/view/report.js.map +1 -0
  228. package/dist/internal/view/scope.d.ts +11 -0
  229. package/dist/internal/view/scope.d.ts.map +1 -0
  230. package/dist/internal/view/scope.js +41 -0
  231. package/dist/internal/view/scope.js.map +1 -0
  232. package/dist/internal/view/server.d.ts +35 -0
  233. package/dist/internal/view/server.d.ts.map +1 -0
  234. package/dist/internal/view/server.js +141 -0
  235. package/dist/internal/view/server.js.map +1 -0
  236. package/dist/src/act.d.ts +3 -0
  237. package/dist/src/act.d.ts.map +1 -0
  238. package/dist/src/act.js +3 -0
  239. package/dist/src/act.js.map +1 -0
  240. package/dist/src/automate.d.ts +3 -0
  241. package/dist/src/automate.d.ts.map +1 -0
  242. package/dist/src/automate.js +3 -0
  243. package/dist/src/automate.js.map +1 -0
  244. package/dist/src/cli.d.ts +24 -17
  245. package/dist/src/cli.d.ts.map +1 -1
  246. package/dist/src/cli.js +408 -107
  247. package/dist/src/cli.js.map +1 -1
  248. package/dist/src/commands.d.ts +104 -0
  249. package/dist/src/commands.d.ts.map +1 -0
  250. package/dist/src/commands.js +33 -0
  251. package/dist/src/commands.js.map +1 -0
  252. package/dist/src/connect.d.ts +3 -0
  253. package/dist/src/connect.d.ts.map +1 -0
  254. package/dist/src/connect.js +3 -0
  255. package/dist/src/connect.js.map +1 -0
  256. package/dist/src/dispatch.d.ts +14 -0
  257. package/dist/src/dispatch.d.ts.map +1 -0
  258. package/dist/src/dispatch.js +116 -0
  259. package/dist/src/dispatch.js.map +1 -0
  260. package/dist/src/doctor.d.ts +45 -0
  261. package/dist/src/doctor.d.ts.map +1 -0
  262. package/dist/src/doctor.js +284 -0
  263. package/dist/src/doctor.js.map +1 -0
  264. package/dist/src/eval.d.ts +3 -0
  265. package/dist/src/eval.d.ts.map +1 -0
  266. package/dist/src/eval.js +3 -0
  267. package/dist/src/eval.js.map +1 -0
  268. package/dist/src/index.d.ts +9 -2
  269. package/dist/src/index.d.ts.map +1 -1
  270. package/dist/src/index.js +6 -2
  271. package/dist/src/index.js.map +1 -1
  272. package/dist/src/ingest.d.ts +3 -0
  273. package/dist/src/ingest.d.ts.map +1 -0
  274. package/dist/src/ingest.js +3 -0
  275. package/dist/src/ingest.js.map +1 -0
  276. package/dist/src/loop.d.ts +3 -0
  277. package/dist/src/loop.d.ts.map +1 -0
  278. package/dist/src/loop.js +3 -0
  279. package/dist/src/loop.js.map +1 -0
  280. package/dist/src/main.d.ts +1 -1
  281. package/dist/src/main.d.ts.map +1 -1
  282. package/dist/src/main.js +3 -75
  283. package/dist/src/main.js.map +1 -1
  284. package/dist/src/mcp.d.ts +3 -0
  285. package/dist/src/mcp.d.ts.map +1 -0
  286. package/dist/src/mcp.js +3 -0
  287. package/dist/src/mcp.js.map +1 -0
  288. package/dist/src/rules.d.ts +3 -0
  289. package/dist/src/rules.d.ts.map +1 -0
  290. package/dist/src/rules.js +3 -0
  291. package/dist/src/rules.js.map +1 -0
  292. package/dist/src/shape.d.ts +3 -0
  293. package/dist/src/shape.d.ts.map +1 -0
  294. package/dist/src/shape.js +3 -0
  295. package/dist/src/shape.js.map +1 -0
  296. package/dist/src/sync.d.ts +3 -0
  297. package/dist/src/sync.d.ts.map +1 -0
  298. package/dist/src/sync.js +3 -0
  299. package/dist/src/sync.js.map +1 -0
  300. package/dist/src/view.d.ts +3 -0
  301. package/dist/src/view.d.ts.map +1 -0
  302. package/dist/src/view.js +3 -0
  303. package/dist/src/view.js.map +1 -0
  304. package/package.json +81 -21
  305. package/src/act.ts +2 -0
  306. package/src/automate.ts +2 -0
  307. package/src/cli.ts +416 -102
  308. package/src/commands.ts +48 -0
  309. package/src/connect.ts +2 -0
  310. package/src/dispatch.ts +141 -0
  311. package/src/doctor.ts +370 -0
  312. package/src/eval.ts +2 -0
  313. package/src/index.ts +9 -2
  314. package/src/ingest.ts +2 -0
  315. package/src/loop.ts +2 -0
  316. package/src/main.ts +3 -66
  317. package/src/mcp.ts +2 -0
  318. package/src/rules.ts +2 -0
  319. package/src/shape.ts +2 -0
  320. package/src/sync.ts +2 -0
  321. package/src/view.ts +2 -0
package/Authors.md ADDED
@@ -0,0 +1,5 @@
1
+ # Authors
2
+
3
+ By adding their name to this file, all listed authors confirm they have copyright over their contributions to this project and are waiving these rights, placing their work in the public domain in accordance with the CC0 1.0 Universal Public Domain Dedication.
4
+
5
+ - Mirek Rusin (Switzerland)
package/License.md ADDED
@@ -0,0 +1,6 @@
1
+ # CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
2
+
3
+ To the extent possible under law, the authors listed in [Authors.md](./Authors.md) have waived all copyright and related or neighboring rights to this software and associated documentation files (the "Software").
4
+
5
+ For more information, please see:
6
+ https://creativecommons.org/publicdomain/zero/1.0/
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @cavelang/cli
2
2
 
3
3
  The `cave` command — the whole stack behind one binary. Runs directly from
4
- TypeScript sources via Node's type stripping; no build step.
4
+ TypeScript sources in the workspace; npm releases contain emitted JavaScript.
5
5
 
6
6
  ```
7
7
  $ echo 'auth USES jwt @ 90%' | pnpm exec cave parse
@@ -15,60 +15,158 @@ $ pnpm exec cave query --db knowledge.db '?x USES jwt'
15
15
  ?x = api/gateway
16
16
 
17
17
  $ pnpm exec cave query --db knowledge.db '?cause CAUSE app/crash' 'WHERE conf >= 0.7'
18
- $ pnpm exec cave export --db knowledge.db --current
18
+ $ pnpm exec cave export --db knowledge.db --current --max-sensitivity internal
19
19
  $ pnpm exec cave demo
20
20
  ```
21
21
 
22
+ ## Programmatic feature subpaths
23
+
24
+ The package manifest is the entry-point registry. Every published entry point
25
+ is documented here and follows the CLI package's semantic-versioning promise:
26
+
27
+ | Entry point | Contract |
28
+ |---|---|
29
+ | `@cavelang/cli` | Buffered command functions plus the shared dispatcher and command registry. |
30
+ | `@cavelang/cli/main` | Executable process entry point; prefer the `cave` binary from package scripts. |
31
+ | `@cavelang/cli/act` | Action declarations and governed execution. |
32
+ | `@cavelang/cli/automate` | Event-driven automation declarations and settling. |
33
+ | `@cavelang/cli/connect` | Deterministic structured-source ingestion. |
34
+ | `@cavelang/cli/eval` | Golden-fixture extraction and reconstruction evaluation. |
35
+ | `@cavelang/cli/ingest` | LLM-driven document ingestion. |
36
+ | `@cavelang/cli/loop` | Active memory reconstruction. |
37
+ | `@cavelang/cli/mcp` | MCP tools, scopes, and stdio server. |
38
+ | `@cavelang/cli/rules` | Rule declarations and forward chaining. |
39
+ | `@cavelang/cli/shape` | Expectations, health checks, and typed-client generation. |
40
+ | `@cavelang/cli/sync` | Store synchronization and annotated interchange. |
41
+ | `@cavelang/cli/view` | Read-only view models, HTTP serving, and cited reports. |
42
+
43
+ For example:
44
+
45
+ ```ts
46
+ import { declareRules, derive } from '@cavelang/cli/rules'
47
+ import { createServer } from '@cavelang/cli/mcp'
48
+ ```
49
+
50
+ The source modules remain separate private workspace packages for focused
51
+ ownership and tests. See [the package migration table](../../PACKAGE_SURFACES.md)
52
+ when updating an import from a former standalone package name.
53
+
22
54
  ## Commands
23
55
 
56
+ ### JSON compatibility
57
+
58
+ JSON that contains claims is storage-independent and versioned. `cave query
59
+ --json` emits a `cave.query-page/v1` object whose `matches` are
60
+ `cave.query-match/v1` objects and whose `claim` and `support` members are
61
+ `cave.claim/v1`; its optional `next` value is an opaque continuation. Resolve,
62
+ rule, action, and health JSON
63
+ replace any nested database rows with the same claim record and never expose
64
+ `claim_key`, `raw_line`, or `value_text` columns. New optional fields may be
65
+ added within a version; incompatible shape changes require a new version.
66
+
67
+ `cave parse --json` is the parser AST/debug surface, not a persisted claim
68
+ record. `cave export` remains canonical CAVE text (with optional `;@` identity
69
+ annotations), which is the language interchange contract rather than JSON.
70
+
24
71
  Every command answers `--help` with its options and examples (also
25
72
  `cave help <command>`). `--db` is optional everywhere: it defaults to
26
73
  `$CAVE_DB`, or `cave.db` in the current directory.
27
74
 
75
+ All commands—synchronous, asynchronous, and long-running—enter through one
76
+ promise-based dispatcher. It owns argument-exception formatting, stdout and
77
+ stderr routing, exit codes, and SIGINT/SIGTERM propagation. Servers, watchers,
78
+ timers, protocol readers, and stores finish their cleanup before a signal exit
79
+ is reported. Unexpected errors are one-line and stack-free by default; set
80
+ `CAVE_DEBUG=1` to include the diagnostic stack.
81
+
28
82
  | Command | Flags | Behavior |
29
83
  |---|---|---|
30
84
  | `parse [file…]` | `--json` | Lint (stdin by default). Exit 1 when diagnostics exist; `--json` dumps the AST document. |
31
85
  | `highlight [file…]` | | ANSI syntax colors from the tree-sitter grammar's own highlight query (see [`@cavelang/highlight`](../highlight)); `cave export` colors the same way on a terminal. |
32
86
  | `add [--db p] [file…]` | `--strict`, `--check`, `--no-prelude`, `--no-src` | Ingest. Lenient by default (problems on stderr, valid lines land); `--strict` rolls back on any problem; `--check` is the shape gate (spec §20.3) — the append rolls back if it introduces new expectation violations; `--no-prelude` starts from an empty registry instead of the standard §5.5 pairs. Claims without a `@src:` context are stamped `@src:cli` (spec §9.5); `--no-src` opts out. |
33
87
  | `import [--db p] [file…]` | `--strict`, `--no-prelude` | Restore/merge a database from CAVE text — `add` minus provenance stamping, because canonical text *is* the interchange format and replayed claims must keep their exported claim keys (spec §9.5). |
34
- | `query [--db p] <pattern…>` | `--json`, `--all`, `--aliases`, `--as-of <t>`, `--resolve`, `--no-prelude` | CAVE-Q. Extra positionals join as lines, so `WHERE` filters ride as separate arguments. Bindings print as `?x = value`; fully bound patterns print the matched raw line (or the pattern itself for transitive matches, which carry no row). `--aliases` widens matching through the §13.6 closure; `--as-of <t>` reconstructs belief at a past date/timestamp/tx (spec §12.3); `--resolve` matches only the winners the §26 resolution policy picks among contested facts (incompatible with `--all`). `--no-prelude` aligns the read-time registry with a store written via `add --no-prelude`. |
88
+ | `query [--db p] <pattern…>` | `--json`, `--limit <n>`, `--cursor <t>`, `--all`, `--aliases`, `--as-of <t>`, `--at <t>`, `--resolve`, `--no-prelude` | Bounded CAVE-Q page (100 matches by default, maximum 1,000). Extra positionals join as lines, so `WHERE` filters ride as separate arguments. Bindings print as `?x = value`; fully bound patterns print the matched raw line (or the pattern itself for transitive matches, which carry no row). Human output ends with `next: <token>` when another page exists; pass it to `--cursor` to continue the first page's frozen transaction snapshot. `--aliases` widens matching through the §13.6 closure; `--as-of <t>` reconstructs belief at a past date/timestamp/tx (spec §12.3); `--at <t>` selects valid-time claims and interpolates trajectories (spec §32.4); `--resolve` matches only the winners the §26 resolution policy picks among contested facts (incompatible with `--all`). `--no-prelude` aligns the read-time registry with a store written via `add --no-prelude`. |
35
89
  | `resolve [--db p]` | `--aliases`, `--policy`, `--json`, `--no-prelude` | Contested facts under the §26 resolution policy: every fact more than one belief series speaks about, candidates ranked (precedence class, reliability-weighted confidence, tx) with the winner first — what `query --resolve` would match. `--policy` prints the effective policy instead: the built-in precedence ladder merged with in-band `source/<name> HAS precedence:` / `HAS reliability:` declarations. |
36
90
  | `derive [--db p] [rules.cave…]` | `--dry-run`, `--full`, `--aliases`, `--min-conf <p>`, `--max-passes <n>`, `--list`, `--retract <r>`, `--json`, `--no-prelude` | Declare and fire rules (spec §24, see [`@cavelang/rules`](../rules)): `premises => conclusion` forward chaining over current beliefs, `BECAUSE`/`VIA` lineage, watermark-incremental and idempotent; retracts conclusions whose premises no longer hold. |
37
91
  | `act [--db p] <name> [p=v…]` | `--declare`, `--list`, `--retract <n>`, `--dry-run`, `--no-check`, `--aliases`, `--hooks <file>`, `--json`, `--no-prelude` | Execute an action template (spec §25, see [`@cavelang/act`](../act)): validate parameters, check CAVE-Q preconditions against current belief, append effects atomically with lineage inside the §20.3 shape gate; out-of-band hooks fire after commit. |
38
- | `automate [--db p]` | see `cave automate --help` | The event-driven loop (spec §29, see [`@cavelang/automate`](../automate)): in-band `automation/<name>` trigger patterns over new claims fire rules, actions, out-of-band hooks and agent prompts; `--once` for cron, `--declare`/`--list`/`--retract` for the lifecycle; the daemon polls `MAX(tx)` and settles on change. |
92
+ | `automate [--db p]` | `--once`, `--declare`, `--list`, `--retract <n>`, `--hooks <file>`, `--agent <template>`, `--json`, `--no-prelude` | The event-driven loop (spec §29, see [`@cavelang/automate`](../automate)): in-band `automation/<name>` trigger patterns over new claims fire rules, actions, out-of-band hooks and agent prompts; `--once` for cron, `--declare`/`--list`/`--retract` for the lifecycle; the daemon polls `MAX(tx)` and settles on change. |
39
93
  | `check [--db p]` | `--stale <days>`, `--json`, `--no-prelude` | Knowledge health report (spec §20, see [`@cavelang/shape`](../shape)): shape violations against in-band `EXPECTS` declarations, stale current beliefs (default horizon 90 days), review candidates (conf 0.3–0.7), alias disagreements, coverage stats. Exit 1 on violations; everything else is advisory. |
94
+ | `backup [--db p] --out <file>` | `--force`; `--verify <file>`, `--sha256 <hex>` | Create an online, exact SQLite snapshot with `VACUUM INTO`, verify it, and publish atomically; or verify a prior snapshot (spec §13.2.2). |
95
+ | `restore <snapshot> --db <path>` | `--force`, `--sha256 <hex>` | Verify and atomically restore exact snapshot bytes; refuses active/stale WAL, SHM, and rollback-journal sidecars (spec §13.2.2). |
96
+ | `generate [--db p]` | `--out <file>`, `--version <n>`, `--no-prelude` | Deterministic versioned TypeScript interfaces and store-backed readers from current `EXPECTS` claims (spec §20.4, see [`@cavelang/shape`](../shape)); embeds normalized schema and SHA-256, fails on ambiguous/unsupported expectations before writing. |
40
97
  | `suggest-alias [--db p]` | `--min <s>`, `--limit <n>`, `--agent <template>`, `--timeout <s>`, `--write`, `--json`, `--no-prelude` | Alias discovery (spec §27, see [`@cavelang/shape`](../shape)): same-entity candidates from string/graph similarity as suggested `ALIAS` claims at review-band confidence (0.3–0.5). Prints pipeable CAVE text; `--write` appends stamped `@src:suggest/alias`; `--agent` runs an LLM judge over the candidates (the ingest/eval shell contract). Pairs with any recorded `ALIAS` history are never re-suggested. |
41
98
  | `sync [--db p] <source>` | `--as <label>`, `--into <label>`, `--dry-run`, `--no-record`, `--json`, `--no-prelude` | Store merge (spec §28, see [`@cavelang/sync`](../sync)): another CAVE store file — or `;@`-annotated canonical text, `-` for stdin — merges by row identity; present rows skip, re-runs merge nothing, effective merges append a `SYNCED-INTO` record (`--no-record` for checkouts, spec §28.6). |
42
- | `export [--db p]` | `--out <file>`, `--current`, `--tx`, `--no-prelude` | Canonical CAVE text — all rows in tx order, or current beliefs only. `--tx` precedes every claim line with its `;@` transaction annotation (spec §28.4), so the text carries row identity: the committed, reviewable store text of the §28.6 branching convention. Stdout by default; `--out` writes a file and reports the claim count. |
43
- | `serve [--db p]` | `--port <n>`, `--host <a>`, `--no-prelude` | The human read surface (spec §30, see [`@cavelang/view`](../view)): one static, self-contained page over the store — §20.2 coverage/frontier dashboard, entity 360, topic browse, belief-history timelines, `BECAUSE`/`VIA` lineage trees, FTS search. Strictly read-only (GET only), localhost by default, every request reads the live store. |
44
- | `mcp [--db p]` | `--read-only`, `--tools <list>`, `--no-prelude`, `--src <ctx>`, `--no-src` | Serve the engine as an MCP server on stdio (see [`@cavelang/mcp`](../mcp)) — tools for add/query/fuse/search/about/neighbors/reconstruct/derive/export/lint, with the §22 spec card as server instructions. `--read-only` / `--tools <list>` narrow the served tool surface (the agent permission boundary), composing by intersection. Appends are stamped `@src:agent/<client-name>` (spec §9.5); `--src` replaces the stamp, `--no-src` disables it. |
45
- | `ingest [--db p] <globs/urls…>` | see `cave ingest --help` | LLM-driven ingestion of files and web pages (fetched and readability-extracted) through any headless agent (see [`@cavelang/ingest`](../ingest)): batching, instructions markdown, hybrid knowledge context, MCP or stdout agents, incremental digests, `--plan` NDJSON for SDK drivers. |
46
- | `eval <suite…>` | see `cave eval --help` | Golden-fixture extraction/query evals (ROADMAP item 9, see [`@cavelang/eval`](../eval)): N fresh-store runs against any agent, claim-key + value scoring with §9.5 actor-stamp normalization, CAVE-Q expectations, optional LLM judge, `--min` CI gate. |
47
- | `connect <source>` | see `cave connect --help` | Deterministic structured ingestion (spec §23, see [`@cavelang/connect`](../connect)): CSV/TSV/JSON/JSONL/SQLite/URL records through `?field` mapping templates, per-record digests, `--watch`, `--prune`, query-time `--query` overlay. |
48
- | `reconstruct [--db p] <seed…>` | `--query <text>`, `--agent <template>`, `--steps <n>`, `--claims <n>`, `--timeout <s>`, `--trace`, `--no-prelude` | Active memory reconstruction from seed cues (spec §18, see [`@cavelang/loop`](../loop)): best-first traversal collecting related claims as canonical CAVE text; the heuristic policy by default, an LLM select/stop policy with `--agent` (ROADMAP item 10). |
99
+ | `export [--db p]` | `--out <file>`, `--current`, `--tx`, `--max-sensitivity <level>`, `--no-prelude` | Sensitivity-scoped canonical CAVE text (spec §9.7) — default maximum `internal`; select `restricted` for complete portable history or a replica. `--current` compacts but never sanitizes permanent history (§9.6). `--tx` precedes every claim line with its `;@` transaction annotation (spec §28.4). Stdout by default; `--out` writes a file and reports the claim count. |
100
+ | `report [--db p] [template…]` | `--out <file>`, `--aliases`, `--resolve`, `--as-of <t>`, `--at <t>`, `--max-sensitivity <level>`, `--no-prelude` | Render sensitivity-scoped cited Markdown from fenced and inline CAVE-Q templates (spec §9.7, §31, see [`@cavelang/view`](../view)). Every query uses the same audience, alias, resolution, transaction-time, and valid-time snapshot options. |
101
+ | `serve [--db p]` | `--port <n>`, `--host <a>`, `--max-sensitivity <level>`, `--no-prelude` | The sensitivity-scoped human read surface (spec §9.7, §30, see [`@cavelang/view`](../view)): one static page whose counts, aliases, history, lineage, and search are computed only from visible rows. Strictly read-only (GET only), localhost by default. |
102
+ | `mcp [--db p]` | `--read-only`, `--permissions <list>`, `--tools <list>`, `--hooks <file>`, `--no-prelude`, `--src <ctx>`, `--no-src` | Serve the engine as an MCP server on stdio (see [`@cavelang/mcp`](../mcp)) — static tools for add/query/fuse/search/about/neighbors/reconstruct/derive/export/lint plus one generated `act_<name>` tool per current action. Permission classes separate `read`, ephemeral `evaluate`, durable `record`, and effect-capable `action`; `--read-only` keeps only read/evaluate. Permission, tool, and read-only scopes intersect. `--hooks` supplies reviewed out-of-band commands for action tools. Appends are stamped `@src:agent/<client-name>` (spec §9.5); `--src` replaces the stamp, `--no-src` disables it. |
103
+ | `ingest [--db p] <globs/urls…>` | `--agent <template>`, `--stdout`, `--lenient`, `--plan`, `--dry-run`, `--json`, `--no-prelude` | LLM-driven ingestion of files and web pages (fetched and readability-extracted) through any headless agent (see [`@cavelang/ingest`](../ingest)): strict atomic staging by default; explicit lenient partial progress with a complete per-source manifest; isolated URL outcomes classified as retryable network/HTTP or permanent HTTP failures; batching, hybrid context, MCP or stdout agents, incremental retry digests, and `--plan` NDJSON for SDK drivers. |
104
+ | `eval <suite…>` | `--agent <template>`, `--judge <template>`, `--runs <n>`, `--stdout`, `--min <p>`, `--json`, `--no-prelude` | Golden-fixture extraction/query evals (see [`@cavelang/eval`](../eval)): N fresh-store runs against any agent, claim-key + value scoring with §9.5 actor-stamp normalization, CAVE-Q expectations, optional LLM judge, `--min` CI gate. |
105
+ | `connect <source>` | `--map <file>`, `--key <field>`, `--watch`, `--prune`, `--query <pattern>`, `--dry-run`, `--no-prelude` | Deterministic structured ingestion (spec §9.8, §23, see [`@cavelang/connect`](../connect)): CSV/TSV/JSON/JSONL/SQLite/URL records through `?field` templates, physical source identity and CSV/TSV/JSONL line spans, per-record digests, `--watch`, `--prune`, query-time overlay. |
106
+ | `reconstruct [--db p] <seed…>` | `--query <text>`, `--agent <template>`, `--steps <n>`, `--claims <n>`, `--timeout <s>`, `--trace`, `--no-prelude` | Active memory reconstruction from seed cues (spec §18, see [`@cavelang/loop`](../loop)): best-first traversal collecting related claims as canonical CAVE text; the heuristic policy by default, an LLM select/stop policy with `--agent`. |
107
+ | `doctor [--db p]` | `--hooks <file>`, `--json` | Read-only runtime, package-layout, configuration, and store-health diagnostics. Missing optional configuration is advisory; unsupported runtimes, broken assets, malformed configured hooks, and unreadable or corrupt stores fail. Reports identify configuration sources but never expose paths, hook content, URLs, or environment values, so both human and `cave.doctor/v1` JSON output are safe to share. |
49
108
  | `demo` | | The cave-loop multi-hop recovery demo (§18). |
50
109
  | `version` | | Print the cave version. |
51
110
  | `help [command]` | | The overview, or one command's options and examples. |
52
111
 
53
- ## Text backup / interchange
112
+ All query-time arguments share one UTC parser. For example,
113
+ `--at 2026-07-02T12:00:00` and `--at 2026-07-02T12:00:00Z` select the same
114
+ instant on every host; explicit numeric offsets such as `+02:00` are honored.
115
+ The same rule applies to `--as-of` and CAVE-Q `WHERE tx` timestamps.
116
+
117
+ Shape declarations may add `#cardinality:one` or an attribute
118
+ `#unit:<unit>` tag. `cave check` reports the observed count and normalized
119
+ units when those constraints fail; declarations without either tag keep the
120
+ compatible one-or-more presence check.
121
+
122
+ ## Exact backup and portable interchange
54
123
 
124
+ For row identity, transaction time, provenance, lineage, and full history:
125
+
126
+ ```sh
127
+ cave backup --db knowledge.db --out knowledge.snapshot.db
128
+ cave backup --verify knowledge.snapshot.db --sha256 <recorded-hex>
129
+ cave restore knowledge.snapshot.db --db restored.db --sha256 <recorded-hex>
55
130
  ```
56
- $ cave export --db knowledge.db --out backup.cave
131
+
132
+ Backup is an online, consistent SQLite snapshot safe with WAL and concurrent
133
+ readers/writers. CAVE verifies and atomically publishes it. Stop all users of
134
+ the destination before restore; a WAL/SHM/journal sidecar makes restore refuse rather
135
+ than guess. Failed creation or restore leaves the previous destination intact.
136
+
137
+ For portable, reviewable CAVE text:
138
+
139
+ ```
140
+ $ cave export --db knowledge.db --max-sensitivity restricted --out backup.cave
57
141
  exported 812 claim(s) to backup.cave
58
142
 
59
143
  $ cave import --db restored.db backup.cave
60
144
  added 812 claim(s), 37 edge(s)
61
145
  ```
62
146
 
63
- The text round trip preserves every claim with its metadata, the **full
64
- belief-series order** (rows export in tx order and re-ingest with fresh
65
- monotonic tx ids, so latest-tx-wins resolution is unchanged),
147
+ With the explicit `restricted` ceiling, the text round trip preserves every
148
+ claim with its metadata and the **belief-series order** (rows export in tx
149
+ order and re-ingest with fresh monotonic tx ids, so latest-tx-wins resolution
150
+ is unchanged),
66
151
  qualifier/grouping edges, and in-band registry declarations (`REVERSE`,
67
- `X IS verb`) — a restored database answers queries identically, inverse
68
- reads included. Original transaction timestamps are re-minted: canonical
69
- CAVE text carries no transaction identity. Use `--current` for a compact
70
- backup of current beliefs only (history intentionally dropped).
71
-
72
- Everything is testable without spawning: each command is a pure function
73
- `(argv) → { code, out, err }` (`@cavelang/cli` exports them), and `main.ts` is
74
- a four-line dispatcher. Tests cover both layers.
152
+ `RENAMED-TO`, `X IS verb`) — a restored database answers current-belief and
153
+ graph queries equivalently, including inverse and lifecycle spellings. Original
154
+ transaction timestamps are re-minted: canonical CAVE text carries no transaction
155
+ identity, so original as-of boundaries and staleness are not preserved. Use
156
+ `--current` for a compact
157
+ view of current beliefs only (history intentionally omitted from that
158
+ view). Lower ceilings use the order `public < internal < confidential <
159
+ restricted`; unlabeled rows are `internal`, while malformed or unknown labels
160
+ fail closed as `restricted`. Filtering is not a sanitization tool: current
161
+ claim text and every other
162
+ database, export, sync peer, backup, snapshot, or clone may still retain
163
+ sensitive content. CAVE has no claim-level redact command (§9.6); after an
164
+ accidental secret ingest, rotate it, stop sync, rebuild a reviewed safe store,
165
+ then explicitly destroy or expire every affected copy with the relevant
166
+ storage provider's confirmation.
167
+
168
+ Everything is testable without spawning: individual buffered commands expose
169
+ `(argv) → { code, out, err }`, while `dispatch(argv, runtime)` exercises the
170
+ same awaited path as the binary with injectable streams and an abort signal.
171
+ `main.ts` only hands process arguments to `runCli` and assigns its final exit
172
+ code.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Action parsing (spec §25.1) — the §24.1 rule line put in the caller's
3
+ * hands:
4
+ *
5
+ * ```cave
6
+ * ?service, ?version, ?service IS service => ?service HAS deployed-version: ?version
7
+ * ```
8
+ *
9
+ * The left side is a comma-separated list of **parameter declarations**
10
+ * (a segment that is one bare `?name` token), §24.1 **premises** —
11
+ * CAVE-Q patterns and `?var op value` constraints, verbatim — and may be
12
+ * empty. The right side is a comma-separated list of one or more
13
+ * **effect templates**: ordinary claim lines whose subject, object, or
14
+ * value slots may be variables bound by a parameter or a pattern
15
+ * premise. A parameter with no other mention is legal — it may
16
+ * parameterize the action's hook (spec §25.4).
17
+ *
18
+ * Unlike a rule, an action is identified by *name*, not content digest:
19
+ * `action/<name>` is the declaration subject and the body evolves as an
20
+ * ordinary belief series under one claim key.
21
+ */
22
+ import { type Ast } from '@cavelang/parser';
23
+ import { Rule } from '@cavelang/cli/rules';
24
+ /** Attribute of action declaration claims: `action/<name> HAS action: …`. */
25
+ export declare const actionAttribute = "action";
26
+ /** Attribute of hook reference claims: `action/<name> HAS hook: <name>` (§25.4). */
27
+ export declare const hookAttribute = "hook";
28
+ /** Subject prefix of action declarations. */
29
+ export declare const subjectPrefix = "action/";
30
+ /** Declaration subject of an action: its name under the `action/` scope. */
31
+ export declare const actionSubject: (name: string) => string;
32
+ /** Action name of a declaration subject, `undefined` when out of scope. */
33
+ export declare const actionName: (subject: string) => undefined | string;
34
+ /**
35
+ * Parameter names become CLI `param=value` keys, MCP schema properties
36
+ * and `{param}` hook placeholders, so they are restricted beyond CAVE-Q
37
+ * variable syntax; `action` is reserved for the hook's `{action}`
38
+ * placeholder.
39
+ */
40
+ export declare const paramNameRe: RegExp;
41
+ export type Action = {
42
+ readonly name: string;
43
+ /** Declaration subject, `action/<name>`. */
44
+ readonly subject: string;
45
+ /** Normalized body text — single-spaced tokens, comment dropped. */
46
+ readonly text: string;
47
+ /** Parameter names, in declaration order. */
48
+ readonly params: readonly string[];
49
+ readonly premises: readonly Rule.Premise[];
50
+ /** Effect templates — ordinary claims whose terms may be `?var`s. */
51
+ readonly effects: readonly Ast.Full[];
52
+ };
53
+ export type t = Action;
54
+ export type Parsed = {
55
+ readonly ok: true;
56
+ readonly action: Action;
57
+ } | {
58
+ readonly ok: false;
59
+ readonly problems: readonly string[];
60
+ };
61
+ /** Variables an effect template references (subject/object/value slots). */
62
+ export declare const effectVariables: (effect: Ast.Full) => string[];
63
+ /**
64
+ * Parses one action body. Problems are returned, never thrown — a stored
65
+ * declaration that fails to parse is reported and skipped, mirroring
66
+ * rules (§24.1) and the lenient ingest surfaces (spec §1.6).
67
+ */
68
+ export declare const parse: (subject: string, body: string) => Parsed;
69
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAwB,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC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AM,EAAE,MAAM,MAAM,KAAG,MA4ErD,CAAA"}
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Action parsing (spec §25.1) — the §24.1 rule line put in the caller's
3
+ * hands:
4
+ *
5
+ * ```cave
6
+ * ?service, ?version, ?service IS service => ?service HAS deployed-version: ?version
7
+ * ```
8
+ *
9
+ * The left side is a comma-separated list of **parameter declarations**
10
+ * (a segment that is one bare `?name` token), §24.1 **premises** —
11
+ * CAVE-Q patterns and `?var op value` constraints, verbatim — and may be
12
+ * empty. The right side is a comma-separated list of one or more
13
+ * **effect templates**: ordinary claim lines whose subject, object, or
14
+ * value slots may be variables bound by a parameter or a pattern
15
+ * premise. A parameter with no other mention is legal — it may
16
+ * parameterize the action's hook (spec §25.4).
17
+ *
18
+ * Unlike a rule, an action is identified by *name*, not content digest:
19
+ * `action/<name>` is the declaration subject and the body evolves as an
20
+ * ordinary belief series under one claim key.
21
+ */
22
+ import { Claim } from '@cavelang/core';
23
+ import { parseDocument, Token } from '@cavelang/parser';
24
+ import { Rule } from '@cavelang/cli/rules';
25
+ /** Attribute of action declaration claims: `action/<name> HAS action: …`. */
26
+ export const actionAttribute = 'action';
27
+ /** Attribute of hook reference claims: `action/<name> HAS hook: <name>` (§25.4). */
28
+ export const hookAttribute = 'hook';
29
+ /** Subject prefix of action declarations. */
30
+ export const subjectPrefix = 'action/';
31
+ /** Declaration subject of an action: its name under the `action/` scope. */
32
+ export const actionSubject = (name) => name.startsWith(subjectPrefix) ? name : `${subjectPrefix}${name}`;
33
+ /** Action name of a declaration subject, `undefined` when out of scope. */
34
+ export const actionName = (subject) => subject.startsWith(subjectPrefix) && subject.length > subjectPrefix.length ?
35
+ subject.slice(subjectPrefix.length) :
36
+ undefined;
37
+ /**
38
+ * Parameter names become CLI `param=value` keys, MCP schema properties
39
+ * and `{param}` hook placeholders, so they are restricted beyond CAVE-Q
40
+ * variable syntax; `action` is reserved for the hook's `{action}`
41
+ * placeholder.
42
+ */
43
+ export const paramNameRe = /^[A-Za-z][A-Za-z0-9_-]*$/;
44
+ const isVariableToken = (token) => token.kind === 'word' && token.text.startsWith('?') && token.text.length > 1;
45
+ /** Variables an effect template references (subject/object/value slots). */
46
+ export const effectVariables = (effect) => {
47
+ const names = [];
48
+ const term = (candidate) => {
49
+ if (candidate.kind === 'entity' && candidate.text.startsWith('?') && candidate.text.length > 1) {
50
+ names.push(candidate.text.slice(1));
51
+ }
52
+ };
53
+ term(effect.subject);
54
+ switch (effect.payload.kind) {
55
+ case 'relation':
56
+ term(effect.payload.object);
57
+ break;
58
+ case 'attribute':
59
+ case 'metric': {
60
+ const value = effect.payload.value;
61
+ if (value.kind === 'atom' && value.raw.startsWith('?') && value.raw.length > 1) {
62
+ names.push(value.raw.slice(1));
63
+ }
64
+ break;
65
+ }
66
+ default:
67
+ break;
68
+ }
69
+ return names;
70
+ };
71
+ const parseEffect = (segment, bound) => {
72
+ const problems = [];
73
+ const text = Rule.normalizeSegment(segment);
74
+ if (text === '') {
75
+ return { problems: ['empty effect — remove the extra comma'] };
76
+ }
77
+ const tokens = Token.tokenize(segment);
78
+ if (tokens.some(token => token.kind === 'word' && token.text === '_')) {
79
+ problems.push('effect slots must be bound — "_" is not allowed on the right side (spec §25.1)');
80
+ }
81
+ for (const token of tokens) {
82
+ if (token.kind === 'word' && /^\?.+:$/.test(token.text)) {
83
+ problems.push(`variables cannot name attributes (${token.text})`);
84
+ }
85
+ }
86
+ const document = parseDocument(text);
87
+ const claimLine = document.lines.find(entry => entry.kind === 'claim');
88
+ if (document.diagnostics.length > 0 || claimLine === undefined || claimLine.kind !== 'claim') {
89
+ problems.push(`cannot parse effect ${JSON.stringify(text)} as a claim` +
90
+ document.diagnostics.map(diagnostic => ` — ${diagnostic.message}`).join(''));
91
+ return { problems };
92
+ }
93
+ const effect = claimLine.claim;
94
+ for (const context of effect.meta.contexts) {
95
+ if (context.includes('?')) {
96
+ problems.push(`variables cannot appear in effect contexts (@${context})`);
97
+ }
98
+ }
99
+ for (const tag of effect.meta.tags) {
100
+ if (tag.key.includes('?') || tag.value?.includes('?') === true) {
101
+ problems.push(`variables cannot appear in effect tags (#${tag.key}${tag.value === undefined ? '' : `:${tag.value}`})`);
102
+ }
103
+ }
104
+ for (const name of effectVariables(effect)) {
105
+ if (!bound.has(name)) {
106
+ problems.push(`effect variable ?${name} is neither a parameter nor bound by a pattern premise (spec §25.1)`);
107
+ }
108
+ }
109
+ return problems.length > 0 ? { problems } : { effect, problems: [] };
110
+ };
111
+ /** Splits `text` at its top-level commas — literal-protected, like §24.1. */
112
+ const splitSegments = (text) => {
113
+ const segments = [];
114
+ let cursor = 0;
115
+ for (const at of Rule.topLevel(text, ',')) {
116
+ segments.push(text.slice(cursor, at));
117
+ cursor = at + 1;
118
+ }
119
+ segments.push(text.slice(cursor));
120
+ return segments;
121
+ };
122
+ /**
123
+ * Parses one action body. Problems are returned, never thrown — a stored
124
+ * declaration that fails to parse is reported and skipped, mirroring
125
+ * rules (§24.1) and the lenient ingest surfaces (spec §1.6).
126
+ */
127
+ export const parse = (subject, body) => {
128
+ const problems = [];
129
+ const name = actionName(subject);
130
+ if (name === undefined) {
131
+ return { ok: false, problems: [`declaration subject ${JSON.stringify(subject)} is not under ${subjectPrefix} (spec §25.1)`] };
132
+ }
133
+ const { head } = Token.splitComment(body);
134
+ const arrows = Rule.topLevel(head, '=>');
135
+ if (arrows.length === 0) {
136
+ return { ok: false, problems: ['not an action — no top-level "=>" (spec §25.1)'] };
137
+ }
138
+ if (arrows.length > 1) {
139
+ return { ok: false, problems: ['an action has exactly one "=>" (spec §25.1)'] };
140
+ }
141
+ const leftText = head.slice(0, arrows[0]);
142
+ const rightText = head.slice(arrows[0] + 2);
143
+ const params = [];
144
+ const premises = [];
145
+ const bound = new Set();
146
+ if (leftText.trim() !== '') {
147
+ for (const segment of splitSegments(leftText)) {
148
+ const tokens = Token.tokenize(segment);
149
+ if (tokens.length === 1 && isVariableToken(tokens[0])) {
150
+ const param = tokens[0].text.slice(1);
151
+ if (!paramNameRe.test(param)) {
152
+ problems.push(`parameter ?${param} — names are letters, digits, _ and - and start with a letter (spec §25.1)`);
153
+ continue;
154
+ }
155
+ if (param === 'action') {
156
+ problems.push('parameter ?action — the name is reserved for the {action} hook placeholder (spec §25.4)');
157
+ continue;
158
+ }
159
+ if (params.includes(param)) {
160
+ problems.push(`parameter ?${param} is declared twice`);
161
+ continue;
162
+ }
163
+ params.push(param);
164
+ bound.add(param);
165
+ continue;
166
+ }
167
+ const { premise, problem } = Rule.parsePremise(segment, bound);
168
+ if (problem !== undefined) {
169
+ problems.push(problem);
170
+ continue;
171
+ }
172
+ premises.push(premise);
173
+ if (premise.kind === 'pattern') {
174
+ Rule.patternVariables(premise.pattern).forEach(variable => bound.add(variable));
175
+ }
176
+ }
177
+ }
178
+ const effects = [];
179
+ const effectTexts = [];
180
+ for (const segment of splitSegments(rightText)) {
181
+ const { effect, problems: effectProblems } = parseEffect(segment, bound);
182
+ problems.push(...effectProblems);
183
+ if (effect !== undefined) {
184
+ effects.push(effect);
185
+ effectTexts.push(Rule.normalizeSegment(segment));
186
+ }
187
+ }
188
+ if (effects.length === 0 && problems.length === 0) {
189
+ problems.push('an action needs at least one effect (spec §25.1)');
190
+ }
191
+ if (problems.length > 0) {
192
+ return { ok: false, problems };
193
+ }
194
+ const left = [
195
+ ...params.map(param => `?${param}`),
196
+ ...premises.map(premise => premise.text)
197
+ ].join(', ');
198
+ const text = `${left === '' ? '' : `${left} `}=> ${effectTexts.join(', ')}`;
199
+ return { ok: true, action: { name, subject, text, params, premises, effects } };
200
+ };
201
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","sourceRoot":"","sources":["../../src/action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAY,MAAM,kBAAkB,CAAA;AACjE,OAA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,OAAO,CAAC,IAAI,CAAC;KACzC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACZ,MAAM,IAAI,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;IAC3E,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAA;AACjF,CAAC,CAAA"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Action lifecycle (spec §25.1) — declaring actions from a CAVE document,
3
+ * resolving and listing what a store currently believes its actions are,
4
+ * and retracting a declaration.
5
+ *
6
+ * An action file is an ordinary CAVE document: top-level
7
+ * `action/<name> HAS action: `…`` claims are the declarations; everything
8
+ * else — parameter docs (`action/<name>/<param> IS param`), hook
9
+ * references (`HAS hook:`), verb declarations, comments — is prelude,
10
+ * ingested first. Declaring is idempotent: an unchanged declaration (or
11
+ * prelude) appends nothing.
12
+ *
13
+ * Unlike rules, an action's identity is its *name*: the declaration
14
+ * evolves as one belief series per subject, and because a declaration may
15
+ * also be appended by other surfaces (`cave add`, an agent's `cave_add`),
16
+ * whose §9.5 stamps fork the series per actor, resolution takes the
17
+ * newest current row across every series of the subject — latest belief
18
+ * wins, whoever appended it.
19
+ */
20
+ import { Row, type Store } from '@cavelang/store';
21
+ import * as Action from './action.ts';
22
+ /** Source context stamped on declarations and bookkeeping (spec §9.5). */
23
+ export declare const provenanceContext = "src:cave-act";
24
+ /**
25
+ * The newest current row of `attribute` on `subject`, across every
26
+ * belief series (§9.5 stamps make one series per appending actor).
27
+ * @returns the winner even when it is retracted or negated — callers
28
+ * decide whether a disabled declaration matters.
29
+ */
30
+ export declare const currentAttribute: (store: Store, subject: string, attribute: string) => undefined | Row.t;
31
+ export type Loaded = {
32
+ readonly action: Action.t;
33
+ /** The declaration row — target of effect rows' `VIA` edges (§25.2). */
34
+ readonly row: Row.t;
35
+ /** Declaration comment — the action's description. */
36
+ readonly description?: string;
37
+ };
38
+ /**
39
+ * Resolves one action by name (or full subject) to its current
40
+ * declaration. @returns `undefined` when unknown, retracted, or negated;
41
+ * problems when the stored body does not parse.
42
+ */
43
+ export declare const loadAction: (store: Store, name: string) => undefined | {
44
+ loaded?: Loaded;
45
+ problems: readonly string[];
46
+ };
47
+ /** The hook name the action currently references, if any (§25.4). */
48
+ export declare const currentHook: (store: Store, subject: string) => undefined | string;
49
+ export type ListedParam = {
50
+ readonly name: string;
51
+ readonly doc?: string;
52
+ };
53
+ export type ListedAction = {
54
+ /** Declaration subject, `action/<name>`. */
55
+ readonly subject: string;
56
+ readonly name: string;
57
+ readonly text: string;
58
+ readonly description?: string;
59
+ readonly params: readonly ListedParam[];
60
+ readonly hook?: string;
61
+ readonly ok: boolean;
62
+ readonly problems: readonly string[];
63
+ };
64
+ /** Current positive actions of a store, in declaration order. */
65
+ export declare const listActions: (store: Store) => ListedAction[];
66
+ export type Declaration = {
67
+ /** Actions newly declared (or re-declared after a change/retraction). */
68
+ readonly declared: number;
69
+ /** Actions whose declaration is already current — nothing appended. */
70
+ readonly unchanged: number;
71
+ /** Claims appended by the file's prelude (0 when unchanged). */
72
+ readonly prelude: number;
73
+ readonly actions: readonly Action.t[];
74
+ readonly problems: readonly {
75
+ line: number;
76
+ message: string;
77
+ }[];
78
+ };
79
+ /**
80
+ * Declares the actions of a CAVE document into the store — prelude
81
+ * first, then one normalized `action/<name> HAS action: …` claim per
82
+ * declaration (§25.1), each skipped when already current. Declarations
83
+ * re-emit in the normalized form; metadata beyond the description
84
+ * comment is not preserved — append exotic declarations with `cave add`.
85
+ */
86
+ export declare const declareActions: (store: Store, text: string) => Declaration;
87
+ export type Retraction = {
88
+ readonly ok: true;
89
+ readonly subject: string;
90
+ readonly retracted: number;
91
+ } | {
92
+ readonly ok: false;
93
+ readonly error: string;
94
+ };
95
+ /**
96
+ * Retracts an action's declaration — by name or subject — disabling it.
97
+ * Every current positive series of the declaration is retracted (§9.5
98
+ * stamps fork one per appending actor). Effects of past executions are
99
+ * recorded knowledge and stay untouched (spec §25.1; contrast §24.5).
100
+ */
101
+ export declare const retractAction: (store: Store, ref: string) => Retraction;
102
+ //# sourceMappingURL=declare.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declare.d.ts","sourceRoot":"","sources":["../../src/declare.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,EAAE,GAAG,EAAE,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,iBAAiB,CAAA;AAe/C;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,KAAK,EAAE,SAAS,MAAM,EAAE,WAAW,MAAM,KAAG,SAAS,GAAG,GAAG,CAAC,CASnG,CAAA;AAqBD,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACzB,wEAAwE;IACxE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;IACnB,sDAAsD;IACtD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,KAAK,EAAE,MAAM,MAAM,KAAG,SAAS,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CAkBjH,CAAA;AAED,qEAAqE;AACrE,eAAO,MAAM,WAAW,GAAI,OAAO,KAAK,EAAE,SAAS,MAAM,KAAG,SAAS,GAAG,MAGvE,CAAA;AAcD,MAAM,MAAM,WAAW,GAAG;IACx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