trellis 3.1.35 → 3.2.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 (287) hide show
  1. package/CHANGELOG.md +23 -5
  2. package/README.md +63 -156
  3. package/bin/trellis.mjs +2 -75
  4. package/dist/{better-sqlite-backend-ahx5p0br.js → better-sqlite-backend-2P4F6AOJ.js} +91 -29
  5. package/dist/boot-middleware-MHLHFCUC.js +9 -0
  6. package/dist/browser/index.d.ts +18 -0
  7. package/dist/browser/index.d.ts.map +1 -0
  8. package/dist/browser/index.js +95 -0
  9. package/dist/{index-53f3b8p8.js → chunk-2W3MHTMG.js} +552 -213
  10. package/dist/chunk-44FFQKQX.js +142 -0
  11. package/dist/chunk-4HYPLFJD.js +150 -0
  12. package/dist/chunk-4XIVMVHC.js +361 -0
  13. package/dist/{index-yp88he8n.js → chunk-6CTA6MCE.js} +88 -64
  14. package/dist/chunk-6GEZ6DN5.js +394 -0
  15. package/dist/chunk-7ZFRVCUE.js +211 -0
  16. package/dist/chunk-CAG4FULI.js +121 -0
  17. package/dist/chunk-FF36CQHZ.js +61 -0
  18. package/dist/{index-h32txmxe.js → chunk-FKQO5A3H.js} +6 -13
  19. package/dist/{index-nq520y6k.js → chunk-FWRS4CSC.js} +46 -32
  20. package/dist/chunk-GFZCJ4EH.js +108 -0
  21. package/dist/chunk-GLM4HGN4.js +55 -0
  22. package/dist/{index-4cdr7x2x.js → chunk-GU374KWZ.js} +182 -111
  23. package/dist/chunk-H6JB3PZ3.js +45 -0
  24. package/dist/chunk-IZX2PLIB.js +1240 -0
  25. package/dist/chunk-J2TXUFCZ.js +289 -0
  26. package/dist/chunk-J3WYZO3Q.js +211 -0
  27. package/dist/{index-xzym9w0m.js → chunk-JA7AIHRK.js} +12 -7
  28. package/dist/chunk-JHHEXEDM.js +162 -0
  29. package/dist/chunk-JUEMDWLU.js +233 -0
  30. package/dist/chunk-KFQGP6VL.js +33 -0
  31. package/dist/chunk-KIJITUZB.js +419 -0
  32. package/dist/{index-4wxa8xz4.js → chunk-KQ4A2D2P.js} +162 -23
  33. package/dist/chunk-KSU2GW22.js +958 -0
  34. package/dist/{index-rv1p47gp.js → chunk-L5N5PR2S.js} +3015 -2480
  35. package/dist/{index-h9e2efx4.js → chunk-LNUIGRDZ.js} +71 -55
  36. package/dist/{index-skhn0agf.js → chunk-MLC5BUYO.js} +19 -20
  37. package/dist/chunk-MPXUVGT3.js +104 -0
  38. package/dist/chunk-N6MYZT4O.js +68 -0
  39. package/dist/chunk-O2AV5WMN.js +48 -0
  40. package/dist/chunk-PZ4XYZ4J.js +143 -0
  41. package/dist/chunk-QB5ISE47.js +419 -0
  42. package/dist/chunk-RSWUFTO2.js +857 -0
  43. package/dist/chunk-S3XLFZ27.js +1095 -0
  44. package/dist/{index-w5wccer3.js → chunk-S6GBJ2ZB.js} +28 -12
  45. package/dist/{index-7pjz3tsy.js → chunk-SGMDTWJJ.js} +57 -15
  46. package/dist/chunk-SPSPV5BC.js +390 -0
  47. package/dist/chunk-TCKXSOBP.js +123 -0
  48. package/dist/chunk-UBGUDMUV.js +59 -0
  49. package/dist/{index-wt8rz4gn.js → chunk-UQISRW6T.js} +97 -26
  50. package/dist/chunk-USEINYUL.js +12 -0
  51. package/dist/{index-bmyt7k8n.js → chunk-UZRUP7QW.js} +12 -4
  52. package/dist/{index-xhcp6xrn.js → chunk-VBYUTRXX.js} +695 -514
  53. package/dist/{index-vkpkfwhq.js → chunk-VDAKEOML.js} +234 -194
  54. package/dist/chunk-WXSWA3MV.js +0 -0
  55. package/dist/{index-n9f2qyh5.js → chunk-X5FLTRUB.js} +55 -33
  56. package/dist/{index-h7zxhhhh.js → chunk-XMQ7G77X.js} +46 -38
  57. package/dist/{index-w7ng765c.js → chunk-YCM7ZYEZ.js} +102 -49
  58. package/dist/cli/deploy-cli.d.ts +18 -0
  59. package/dist/cli/deploy-cli.d.ts.map +1 -0
  60. package/dist/cli/errors.d.ts +6 -0
  61. package/dist/cli/errors.d.ts.map +1 -0
  62. package/dist/cli/examples.d.ts +23 -0
  63. package/dist/cli/examples.d.ts.map +1 -0
  64. package/dist/cli/index.d.ts +1 -1
  65. package/dist/cli/index.d.ts.map +1 -1
  66. package/dist/cli/index.js +2426 -6225
  67. package/dist/client/index.browser.d.ts +29 -0
  68. package/dist/client/index.browser.d.ts.map +1 -0
  69. package/dist/client/index.browser.js +64 -0
  70. package/dist/client/index.d.ts +6 -1
  71. package/dist/client/index.d.ts.map +1 -1
  72. package/dist/client/index.js +41 -21
  73. package/dist/client/live.d.ts +67 -0
  74. package/dist/client/live.d.ts.map +1 -0
  75. package/dist/client/reactive.d.ts +31 -0
  76. package/dist/client/reactive.d.ts.map +1 -0
  77. package/dist/client/sdk.browser.d.ts +104 -0
  78. package/dist/client/sdk.browser.d.ts.map +1 -0
  79. package/dist/client/sdk.browser.js +9 -0
  80. package/dist/client/sdk.d.ts +26 -2
  81. package/dist/client/sdk.d.ts.map +1 -1
  82. package/dist/client/sdk.js +9 -0
  83. package/dist/client/vcs-client.d.ts +129 -0
  84. package/dist/client/vcs-client.d.ts.map +1 -0
  85. package/dist/cms/index.js +171 -163
  86. package/dist/{config-8hczw0rs.js → config-PFTP67TR.js} +8 -9
  87. package/dist/core/computation/index.d.ts +5 -0
  88. package/dist/core/computation/index.d.ts.map +1 -0
  89. package/dist/core/computation/rollup.d.ts +18 -0
  90. package/dist/core/computation/rollup.d.ts.map +1 -0
  91. package/dist/core/index.d.ts +5 -0
  92. package/dist/core/index.d.ts.map +1 -1
  93. package/dist/core/index.js +171 -104
  94. package/dist/core/kernel/boot-middleware.d.ts +10 -0
  95. package/dist/core/kernel/boot-middleware.d.ts.map +1 -0
  96. package/dist/core/kernel/logic-middleware.d.ts +7 -1
  97. package/dist/core/kernel/logic-middleware.d.ts.map +1 -1
  98. package/dist/core/kernel/trellis-kernel.d.ts.map +1 -1
  99. package/dist/core/ontology/types.d.ts +5 -0
  100. package/dist/core/ontology/types.d.ts.map +1 -1
  101. package/dist/core/persist/better-sqlite-backend.d.ts +9 -2
  102. package/dist/core/persist/better-sqlite-backend.d.ts.map +1 -1
  103. package/dist/core/persist/factory.d.ts +6 -7
  104. package/dist/core/persist/factory.d.ts.map +1 -1
  105. package/dist/core/persist/factory.js +2 -3
  106. package/dist/core/persist/sqljs-backend.js +2 -3
  107. package/dist/db/index.d.ts +4 -1
  108. package/dist/db/index.d.ts.map +1 -1
  109. package/dist/db/index.js +67 -54
  110. package/dist/db/inspector.js +11 -19
  111. package/dist/db/trellis.css +1 -1
  112. package/dist/decisions/index.js +9 -10
  113. package/dist/deploy-LQ7GUGJ5.js +9 -0
  114. package/dist/deploy-YNVG5E4E.js +9 -0
  115. package/dist/deploy-cli-24BCHAXY.js +67 -0
  116. package/dist/deploy-cli-C35HTITO.js +67 -0
  117. package/dist/embeddings/auto-embed.d.ts +2 -2
  118. package/dist/embeddings/auto-embed.d.ts.map +1 -1
  119. package/dist/embeddings/index.js +20 -22
  120. package/dist/embeddings/search.d.ts +2 -1
  121. package/dist/embeddings/search.d.ts.map +1 -1
  122. package/dist/embeddings/store.d.ts +25 -4
  123. package/dist/embeddings/store.d.ts.map +1 -1
  124. package/dist/engine.d.ts +59 -19
  125. package/dist/engine.d.ts.map +1 -1
  126. package/dist/import-UZEKXU3B.js +10 -0
  127. package/dist/index.js +102 -93
  128. package/dist/launch-explorer-HZ4ZJA4X.js +95 -0
  129. package/dist/links/index.js +24 -26
  130. package/dist/mcp/server.d.ts.map +1 -1
  131. package/dist/plugins/agent-memory/index.js +316 -0
  132. package/dist/plugins/idea-garden/index.js +165 -0
  133. package/dist/plugins/plan-approval/index.js +579 -0
  134. package/dist/plugins/proactive-watcher/index.js +194 -0
  135. package/dist/{index-2r4jxwnb.js → query-XYLTJYSA.js} +14 -15
  136. package/dist/react/index.js +39 -70
  137. package/dist/react/realtime.js +11 -0
  138. package/dist/react/schema-hooks.js +87 -0
  139. package/dist/realtime/broadcast-channel-transport.d.ts +43 -0
  140. package/dist/realtime/broadcast-channel-transport.d.ts.map +1 -0
  141. package/dist/realtime/durable-object-relay-transport.d.ts +96 -0
  142. package/dist/realtime/durable-object-relay-transport.d.ts.map +1 -0
  143. package/dist/realtime/index.d.ts +44 -0
  144. package/dist/realtime/index.d.ts.map +1 -0
  145. package/dist/realtime/index.js +40 -0
  146. package/dist/realtime/memory-hub.d.ts +32 -0
  147. package/dist/realtime/memory-hub.d.ts.map +1 -0
  148. package/dist/realtime/persistent-channel.d.ts +105 -0
  149. package/dist/realtime/persistent-channel.d.ts.map +1 -0
  150. package/dist/realtime/presence.d.ts +73 -0
  151. package/dist/realtime/presence.d.ts.map +1 -0
  152. package/dist/realtime/relay-persistence.d.ts +37 -0
  153. package/dist/realtime/relay-persistence.d.ts.map +1 -0
  154. package/dist/realtime/relay-persistence.js +107 -0
  155. package/dist/realtime/relay-server.d.ts +103 -0
  156. package/dist/realtime/relay-server.d.ts.map +1 -0
  157. package/dist/realtime/room.d.ts +98 -0
  158. package/dist/realtime/room.d.ts.map +1 -0
  159. package/dist/realtime/text.d.ts +73 -0
  160. package/dist/realtime/text.d.ts.map +1 -0
  161. package/dist/realtime/types.d.ts +89 -0
  162. package/dist/realtime/types.d.ts.map +1 -0
  163. package/dist/realtime/websocket-relay-transport.d.ts +28 -0
  164. package/dist/realtime/websocket-relay-transport.d.ts.map +1 -0
  165. package/dist/realtime.bundle.js +1100 -0
  166. package/dist/{remote-manager-xvbg4230.js → remote-manager-ODE3T2KR.js} +25 -15
  167. package/dist/scaffold/seed.d.ts.map +1 -1
  168. package/dist/scaffold/write.d.ts +1 -1
  169. package/dist/scaffold/write.d.ts.map +1 -1
  170. package/dist/schema/define.d.ts +137 -0
  171. package/dist/schema/define.d.ts.map +1 -0
  172. package/dist/schema/entity-projection.d.ts +34 -0
  173. package/dist/schema/entity-projection.d.ts.map +1 -0
  174. package/dist/schema/eql.d.ts +46 -0
  175. package/dist/schema/eql.d.ts.map +1 -0
  176. package/dist/schema/index.d.ts +21 -0
  177. package/dist/schema/index.d.ts.map +1 -0
  178. package/dist/schema/index.js +46 -0
  179. package/dist/schema/kernel-resolve.d.ts +21 -0
  180. package/dist/schema/kernel-resolve.d.ts.map +1 -0
  181. package/dist/schema/mutations.d.ts +20 -0
  182. package/dist/schema/mutations.d.ts.map +1 -0
  183. package/dist/schema/resolve.d.ts +21 -0
  184. package/dist/schema/resolve.d.ts.map +1 -0
  185. package/dist/server/deploy-meta.d.ts +25 -0
  186. package/dist/server/deploy-meta.d.ts.map +1 -0
  187. package/dist/server/deploy.d.ts +7 -2
  188. package/dist/server/deploy.d.ts.map +1 -1
  189. package/dist/server/index.d.ts +7 -2
  190. package/dist/server/index.d.ts.map +1 -1
  191. package/dist/server/index.js +100 -58
  192. package/dist/server/node-adapter.js +5 -104
  193. package/dist/server/realtime.d.ts +14 -3
  194. package/dist/server/realtime.d.ts.map +1 -1
  195. package/dist/server/server.d.ts +8 -16
  196. package/dist/server/server.d.ts.map +1 -1
  197. package/dist/server/sprites.d.ts +18 -1
  198. package/dist/server/sprites.d.ts.map +1 -1
  199. package/dist/server/tenancy.d.ts +4 -0
  200. package/dist/server/tenancy.d.ts.map +1 -1
  201. package/dist/server/usage-meter.d.ts +53 -0
  202. package/dist/server/usage-meter.d.ts.map +1 -0
  203. package/dist/server-MB3OPSPI.js +18 -0
  204. package/dist/server-ZVWGLLRF.js +18 -0
  205. package/dist/sprites-KQGTGM6W.js +27 -0
  206. package/dist/{sprites-vc4qbrp1.js → sprites-RU3E4XQN.js} +6 -7
  207. package/dist/svelte/index.d.ts +17 -0
  208. package/dist/svelte/index.d.ts.map +1 -0
  209. package/dist/svelte/index.js +51 -0
  210. package/dist/svelte/schema-hooks.d.ts +45 -0
  211. package/dist/svelte/schema-hooks.d.ts.map +1 -0
  212. package/dist/svelte/schema-hooks.js +71 -0
  213. package/dist/svelte/stores.d.ts +78 -0
  214. package/dist/svelte/stores.d.ts.map +1 -0
  215. package/dist/sync/http-transport.d.ts +3 -3
  216. package/dist/sync/http-transport.d.ts.map +1 -1
  217. package/dist/sync/index.d.ts +15 -1
  218. package/dist/sync/index.d.ts.map +1 -1
  219. package/dist/sync/index.js +617 -0
  220. package/dist/sync/memory-room.d.ts +37 -0
  221. package/dist/sync/memory-room.d.ts.map +1 -0
  222. package/dist/sync/memory-transport.d.ts +3 -3
  223. package/dist/sync/memory-transport.d.ts.map +1 -1
  224. package/dist/sync/partykit-room.d.ts +40 -0
  225. package/dist/sync/partykit-room.d.ts.map +1 -0
  226. package/dist/sync/partykit-transport.d.ts +84 -0
  227. package/dist/sync/partykit-transport.d.ts.map +1 -0
  228. package/dist/sync/room-core.d.ts +53 -0
  229. package/dist/sync/room-core.d.ts.map +1 -0
  230. package/dist/sync/sync-engine.d.ts +40 -2
  231. package/dist/sync/sync-engine.d.ts.map +1 -1
  232. package/dist/sync/sync-room-server.d.ts +39 -0
  233. package/dist/sync/sync-room-server.d.ts.map +1 -0
  234. package/dist/sync/types.d.ts +70 -3
  235. package/dist/sync/types.d.ts.map +1 -1
  236. package/dist/sync/vcs-sync-peer.d.ts +63 -0
  237. package/dist/sync/vcs-sync-peer.d.ts.map +1 -0
  238. package/dist/sync/ws-transport.d.ts +2 -2
  239. package/dist/sync/ws-transport.d.ts.map +1 -1
  240. package/dist/tenancy-NBLLGCNJ.js +14 -0
  241. package/dist/tenancy-POMWQP6M.js +16 -0
  242. package/dist/ui/client.html +355 -67
  243. package/dist/ui/launch-explorer.d.ts +22 -0
  244. package/dist/ui/launch-explorer.d.ts.map +1 -0
  245. package/dist/ui/server.d.ts +1 -1
  246. package/dist/ui/server.d.ts.map +1 -1
  247. package/dist/vcs/blob-store.d.ts.map +1 -1
  248. package/dist/vcs/idb-op-log.d.ts +67 -0
  249. package/dist/vcs/idb-op-log.d.ts.map +1 -0
  250. package/dist/vcs/index.d.ts +1 -0
  251. package/dist/vcs/index.d.ts.map +1 -1
  252. package/dist/vcs/index.js +81 -72
  253. package/dist/vcs/issue.d.ts +22 -5
  254. package/dist/vcs/issue.d.ts.map +1 -1
  255. package/dist/vcs/lane-materialize.d.ts +5 -0
  256. package/dist/vcs/lane-materialize.d.ts.map +1 -1
  257. package/dist/vcs/op-log.d.ts +28 -2
  258. package/dist/vcs/op-log.d.ts.map +1 -1
  259. package/dist/vcs/ops.d.ts +10 -0
  260. package/dist/vcs/ops.d.ts.map +1 -1
  261. package/dist/vcs/types.d.ts +2 -0
  262. package/dist/vcs/types.d.ts.map +1 -1
  263. package/dist/{vm-config-6xhsj6b3.js → vm-config-JI4OXKDQ.js} +9 -10
  264. package/dist/vue/hooks.d.ts +64 -0
  265. package/dist/vue/hooks.d.ts.map +1 -0
  266. package/dist/vue/index.d.ts +19 -0
  267. package/dist/vue/index.d.ts.map +1 -0
  268. package/dist/vue/index.js +59 -0
  269. package/dist/vue/schema-hooks.d.ts +41 -0
  270. package/dist/vue/schema-hooks.d.ts.map +1 -0
  271. package/dist/vue/schema-hooks.js +64 -0
  272. package/package.json +130 -17
  273. package/dist/deploy-999q207z.js +0 -10
  274. package/dist/engine-y0724kjq.js +0 -8
  275. package/dist/import-s2b8e0ft.js +0 -11
  276. package/dist/index-a76rekgs.js +0 -67
  277. package/dist/index-c9h37r6h.js +0 -1
  278. package/dist/index-hr9qvv77.js +0 -860
  279. package/dist/index-k5b0xskw.js +0 -1
  280. package/dist/index-nzb3am4f.js +0 -80
  281. package/dist/index-wncptktd.js +0 -292
  282. package/dist/index-y6a4kj0p.js +0 -43
  283. package/dist/index-yhwjgfvj.js +0 -342
  284. package/dist/sdk-bepky0xs.js +0 -16
  285. package/dist/server-szdjx0nt.js +0 -13
  286. package/dist/sqlite-backend-0vsmc6qj.js +0 -8
  287. package/dist/tenancy-pjm32b4v.js +0 -14
@@ -1,11 +1,10 @@
1
- // @bun
2
1
  import {
3
2
  QueryEngine
4
- } from "./index-yp88he8n.js";
3
+ } from "./chunk-6CTA6MCE.js";
5
4
  import {
6
5
  EAVStore,
7
6
  init_eav_store
8
- } from "./index-yhwjgfvj.js";
7
+ } from "./chunk-4XIVMVHC.js";
9
8
 
10
9
  // src/core/kernel/trellis-kernel.ts
11
10
  init_eav_store();
@@ -302,8 +301,7 @@ async function hashOp(kind, timestamp, agentId, previousHash, payload) {
302
301
  const hex = Array.from(new Uint8Array(hashBuf)).map((b) => b.toString(16).padStart(2, "0")).join("");
303
302
  return `trellis:op:${hex}`;
304
303
  }
305
-
306
- class TrellisKernel {
304
+ var TrellisKernel = class {
307
305
  store;
308
306
  backend;
309
307
  middleware;
@@ -311,11 +309,11 @@ class TrellisKernel {
311
309
  snapshotThreshold;
312
310
  opsSinceSnapshot = 0;
313
311
  _booted = false;
314
- ontologies = new Map;
312
+ ontologies = /* @__PURE__ */ new Map();
315
313
  workspaceConfig = null;
316
314
  autoReplay = true;
317
315
  constructor(config) {
318
- this.store = new EAVStore;
316
+ this.store = new EAVStore();
319
317
  this.backend = config.backend;
320
318
  this.agentId = config.agentId;
321
319
  this.middleware = config.middleware ?? [];
@@ -325,6 +323,13 @@ class TrellisKernel {
325
323
  this.ontologies.set(schema["@id"], schema);
326
324
  }
327
325
  }
326
+ // -------------------------------------------------------------------------
327
+ // Lifecycle
328
+ // -------------------------------------------------------------------------
329
+ /**
330
+ * Initialize the backend and replay persisted state.
331
+ * Loads latest snapshot if available, then replays ops after it.
332
+ */
328
333
  boot() {
329
334
  this.backend.init();
330
335
  if (!this.autoReplay) {
@@ -352,6 +357,9 @@ class TrellisKernel {
352
357
  this._booted = true;
353
358
  return { opsReplayed, fromSnapshot };
354
359
  }
360
+ /**
361
+ * Close the backend connection.
362
+ */
355
363
  close() {
356
364
  this.backend.close?.();
357
365
  this._booted = false;
@@ -359,12 +367,25 @@ class TrellisKernel {
359
367
  isBooted() {
360
368
  return this._booted;
361
369
  }
370
+ // -------------------------------------------------------------------------
371
+ // Mutations
372
+ // -------------------------------------------------------------------------
373
+ /**
374
+ * Apply a mutation to the graph. Creates an op, runs it through middleware,
375
+ * decomposes into EAV primitives, persists, and returns the result.
376
+ */
362
377
  async mutate(kind, payload, ctx) {
363
- const timestamp = new Date().toISOString();
378
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
364
379
  const lastOp = this.backend.getLastOp();
365
380
  const agentId = ctx?.agentId ?? this.agentId;
366
381
  const payloadStr = JSON.stringify(payload);
367
- const hash = await hashOp(kind, timestamp, agentId, lastOp?.hash, payloadStr);
382
+ const hash = await hashOp(
383
+ kind,
384
+ timestamp,
385
+ agentId,
386
+ lastOp?.hash,
387
+ payloadStr
388
+ );
368
389
  const op = {
369
390
  hash,
370
391
  kind,
@@ -373,8 +394,8 @@ class TrellisKernel {
373
394
  previousHash: lastOp?.hash,
374
395
  facts: [...payload.facts ?? []],
375
396
  links: [...payload.links ?? []],
376
- deleteFacts: payload.deleteFacts?.length ? [...payload.deleteFacts] : undefined,
377
- deleteLinks: payload.deleteLinks?.length ? [...payload.deleteLinks] : undefined
397
+ deleteFacts: payload.deleteFacts?.length ? [...payload.deleteFacts] : void 0,
398
+ deleteLinks: payload.deleteLinks?.length ? [...payload.deleteLinks] : void 0
378
399
  };
379
400
  const extOp = op;
380
401
  if (payload.meta) {
@@ -415,34 +436,64 @@ class TrellisKernel {
415
436
  linksDelta: { added: linksAdded, deleted: linksDeleted }
416
437
  };
417
438
  }
439
+ /**
440
+ * Create a snapshot of the current store state.
441
+ */
418
442
  checkpoint() {
419
443
  const lastOp = this.backend.getLastOp();
420
- if (!lastOp)
421
- return;
444
+ if (!lastOp) return;
422
445
  this.backend.saveSnapshot(lastOp.hash, this.store.snapshot());
423
446
  this.opsSinceSnapshot = 0;
424
447
  }
448
+ // -------------------------------------------------------------------------
449
+ // Queries
450
+ // -------------------------------------------------------------------------
451
+ /**
452
+ * Get the underlying EAV store for direct queries.
453
+ */
425
454
  getStore() {
426
455
  return this.store;
427
456
  }
457
+ /**
458
+ * Get the persistence backend.
459
+ */
428
460
  getBackend() {
429
461
  return this.backend;
430
462
  }
463
+ /**
464
+ * Get the agent ID.
465
+ */
431
466
  getAgentId() {
432
467
  return this.agentId;
433
468
  }
469
+ /**
470
+ * Read all persisted ops.
471
+ */
434
472
  readAllOps() {
435
473
  return this.backend.readAll();
436
474
  }
475
+ /**
476
+ * Get the last persisted op.
477
+ */
437
478
  getLastOp() {
438
479
  return this.backend.getLastOp();
439
480
  }
481
+ /**
482
+ * Create a QueryEngine bound to this kernel's store.
483
+ */
440
484
  createQueryEngine() {
441
485
  return new QueryEngine(this.store);
442
486
  }
487
+ /**
488
+ * Execute an EQL-S query, routing through middleware handleQuery hooks.
489
+ * If no middleware intercepts, the query runs directly against the store.
490
+ */
443
491
  async query(q) {
444
492
  const engine = new QueryEngine(this.store);
445
- const ctx = { agentId: this.agentId };
493
+ const ctx = {
494
+ agentId: this.agentId,
495
+ store: this.store
496
+ };
446
497
  const chain = this.middleware.filter((m) => m.handleQuery);
447
498
  if (chain.length === 0) {
448
499
  return engine.execute(q);
@@ -460,9 +511,13 @@ class TrellisKernel {
460
511
  result = next(q, ctx);
461
512
  return result;
462
513
  }
514
+ /**
515
+ * Time-travel: reconstruct the store state at a specific op hash.
516
+ * Returns a new EAVStore with state replayed up to (and including) that op.
517
+ */
463
518
  timeTravel(opHash) {
464
519
  const ops = this.backend.readUntil(opHash);
465
- const snapshot = new EAVStore;
520
+ const snapshot = new EAVStore();
466
521
  for (const op of ops) {
467
522
  if (op.deleteFacts && op.deleteFacts.length > 0) {
468
523
  snapshot.deleteFacts(op.deleteFacts);
@@ -479,10 +534,17 @@ class TrellisKernel {
479
534
  }
480
535
  return snapshot;
481
536
  }
537
+ // -------------------------------------------------------------------------
538
+ // Entity CRUD (high-level graph operations)
539
+ // -------------------------------------------------------------------------
540
+ /**
541
+ * Create a new entity with the given type and attributes.
542
+ * Returns the entity ID.
543
+ */
482
544
  async createEntity(entityId, type, attributes = {}, links) {
483
545
  const facts = [
484
546
  { e: entityId, a: "type", v: type },
485
- { e: entityId, a: "createdAt", v: new Date().toISOString() }
547
+ { e: entityId, a: "createdAt", v: (/* @__PURE__ */ new Date()).toISOString() }
486
548
  ];
487
549
  for (const [attr, value] of Object.entries(attributes)) {
488
550
  facts.push({ e: entityId, a: attr, v: value });
@@ -494,13 +556,15 @@ class TrellisKernel {
494
556
  }));
495
557
  return this.mutate("addFacts", {
496
558
  facts,
497
- links: linkRecords.length > 0 ? linkRecords : undefined
559
+ links: linkRecords.length > 0 ? linkRecords : void 0
498
560
  });
499
561
  }
562
+ /**
563
+ * Get an entity by ID, returning all its facts and links.
564
+ */
500
565
  getEntity(entityId) {
501
566
  const facts = this.store.getFactsByEntity(entityId);
502
- if (facts.length === 0)
503
- return null;
567
+ if (facts.length === 0) return null;
504
568
  const typeFact = facts.find((f2) => f2.a === "type");
505
569
  return {
506
570
  id: entityId,
@@ -509,6 +573,9 @@ class TrellisKernel {
509
573
  links: this.store.getLinksByEntity(entityId)
510
574
  };
511
575
  }
576
+ /**
577
+ * Update an entity's attributes. Deletes old values and adds new ones.
578
+ */
512
579
  async updateEntity(entityId, updates) {
513
580
  const existingFacts = this.store.getFactsByEntity(entityId);
514
581
  const deleteFacts = [];
@@ -520,12 +587,15 @@ class TrellisKernel {
520
587
  }
521
588
  const updatedAtFacts = existingFacts.filter((f2) => f2.a === "updatedAt");
522
589
  deleteFacts.push(...updatedAtFacts);
523
- addFacts.push({ e: entityId, a: "updatedAt", v: new Date().toISOString() });
590
+ addFacts.push({ e: entityId, a: "updatedAt", v: (/* @__PURE__ */ new Date()).toISOString() });
524
591
  return this.mutate("addFacts", {
525
592
  facts: addFacts,
526
593
  deleteFacts
527
594
  });
528
595
  }
596
+ /**
597
+ * Delete an entity and all its facts and links.
598
+ */
529
599
  async deleteEntity(entityId) {
530
600
  const facts = this.store.getFactsByEntity(entityId);
531
601
  const links = this.store.getLinksByEntity(entityId);
@@ -534,6 +604,9 @@ class TrellisKernel {
534
604
  deleteLinks: links
535
605
  });
536
606
  }
607
+ /**
608
+ * List entities by type, with optional attribute filters.
609
+ */
537
610
  listEntities(type, filters) {
538
611
  let entityIds;
539
612
  if (type) {
@@ -556,32 +629,56 @@ class TrellisKernel {
556
629
  }
557
630
  return Array.from(entityIds).map((id) => this.getEntity(id)).filter(Boolean);
558
631
  }
632
+ /**
633
+ * Add a link between two entities.
634
+ */
559
635
  async addLink(sourceId, attribute, targetId) {
560
636
  return this.mutate("addLinks", {
561
637
  links: [{ e1: sourceId, a: attribute, e2: targetId }]
562
638
  });
563
639
  }
640
+ /**
641
+ * Remove a link between two entities.
642
+ */
564
643
  async removeLink(sourceId, attribute, targetId) {
565
644
  return this.mutate("deleteLinks", {
566
645
  deleteLinks: [{ e1: sourceId, a: attribute, e2: targetId }]
567
646
  });
568
647
  }
648
+ /**
649
+ * Add a fact to an entity.
650
+ */
569
651
  async addFact(entityId, attribute, value) {
570
652
  return this.mutate("addFacts", {
571
653
  facts: [{ e: entityId, a: attribute, v: value }]
572
654
  });
573
655
  }
656
+ /**
657
+ * Remove a fact from an entity.
658
+ */
574
659
  async removeFact(entityId, attribute, value) {
575
660
  return this.mutate("deleteFacts", {
576
661
  deleteFacts: [{ e: entityId, a: attribute, v: value }]
577
662
  });
578
663
  }
664
+ // -------------------------------------------------------------------------
665
+ // Ontology CRUD
666
+ // -------------------------------------------------------------------------
667
+ /**
668
+ * Get an ontology schema by ID.
669
+ */
579
670
  getOntology(id) {
580
671
  return this.ontologies.get(id);
581
672
  }
673
+ /**
674
+ * List all ontologies.
675
+ */
582
676
  listOntologies() {
583
677
  return Array.from(this.ontologies.values());
584
678
  }
679
+ /**
680
+ * Create a new ontology schema.
681
+ */
585
682
  createOntology(schema) {
586
683
  const tier = schema.tier ?? "user";
587
684
  if (tier === "core") {
@@ -598,6 +695,9 @@ class TrellisKernel {
598
695
  };
599
696
  this.store.addFacts([fact]);
600
697
  }
698
+ /**
699
+ * Update an existing ontology schema.
700
+ */
601
701
  updateOntology(id, updates) {
602
702
  const existing = this.ontologies.get(id);
603
703
  if (!existing) {
@@ -622,6 +722,9 @@ class TrellisKernel {
622
722
  this.store.deleteFacts(deleteFacts);
623
723
  this.store.addFacts(addFacts);
624
724
  }
725
+ /**
726
+ * Delete an ontology schema.
727
+ */
625
728
  deleteOntology(id) {
626
729
  const existing = this.ontologies.get(id);
627
730
  if (!existing) {
@@ -635,6 +738,13 @@ class TrellisKernel {
635
738
  const facts = this.store.getFactsByEntity(id);
636
739
  this.store.deleteFacts(facts);
637
740
  }
741
+ // -------------------------------------------------------------------------
742
+ // Workspace
743
+ // -------------------------------------------------------------------------
744
+ /**
745
+ * Boot the kernel with a workspace configuration.
746
+ * Loads ontologies, projections, and seed data.
747
+ */
638
748
  bootWorkspace(config) {
639
749
  this.workspaceConfig = config;
640
750
  if (config.workspace.ontologies) {
@@ -676,6 +786,9 @@ class TrellisKernel {
676
786
  }
677
787
  this.boot();
678
788
  }
789
+ /**
790
+ * Export the current workspace configuration.
791
+ */
679
792
  exportWorkspace() {
680
793
  const ontologies = {};
681
794
  for (const [id, schema] of this.ontologies) {
@@ -710,7 +823,7 @@ class TrellisKernel {
710
823
  workspace: {
711
824
  name: this.workspaceConfig?.workspace.name,
712
825
  description: this.workspaceConfig?.workspace.description,
713
- ontologies: Object.keys(ontologies).length > 0 ? ontologies : undefined,
826
+ ontologies: Object.keys(ontologies).length > 0 ? ontologies : void 0,
714
827
  graph: { nodes, edges },
715
828
  projections: this.workspaceConfig?.workspace.projections,
716
829
  routes: this.workspaceConfig?.workspace.routes,
@@ -718,27 +831,51 @@ class TrellisKernel {
718
831
  }
719
832
  };
720
833
  }
834
+ // -------------------------------------------------------------------------
835
+ // TQL Compatibility Aliases
836
+ // -------------------------------------------------------------------------
837
+ /**
838
+ * Create a node (alias for createEntity with schema validation).
839
+ */
721
840
  async createNode(id, data, type, _ctx) {
722
841
  return this.createEntity(id, type, data);
723
842
  }
843
+ /**
844
+ * Update a node (alias for updateEntity with schema validation).
845
+ */
724
846
  async updateNode(id, data, type, _ctx) {
725
847
  return this.updateEntity(id, data);
726
848
  }
849
+ /**
850
+ * Delete a node (alias for deleteEntity).
851
+ */
727
852
  async deleteNode(id, _ctx) {
728
853
  return this.deleteEntity(id);
729
854
  }
855
+ /**
856
+ * Link two nodes (alias for addLink).
857
+ */
730
858
  async link(e1, a, e2, _ctx) {
731
859
  return this.addLink(e1, a, e2);
732
860
  }
861
+ /**
862
+ * Unlink two nodes (alias for removeLink).
863
+ */
733
864
  async unlink(e1, a, e2, _ctx) {
734
865
  return this.removeLink(e1, a, e2);
735
866
  }
867
+ // -------------------------------------------------------------------------
868
+ // Middleware
869
+ // -------------------------------------------------------------------------
736
870
  addMiddleware(mw) {
737
871
  this.middleware.push(mw);
738
872
  }
739
873
  removeMiddleware(name) {
740
874
  this.middleware = this.middleware.filter((m) => m.name !== name);
741
875
  }
876
+ // -------------------------------------------------------------------------
877
+ // Internal
878
+ // -------------------------------------------------------------------------
742
879
  async _runMiddleware(op, ctx) {
743
880
  const chain = [...this.middleware];
744
881
  let idx = 0;
@@ -766,6 +903,8 @@ class TrellisKernel {
766
903
  this.store.addLinks(op.links);
767
904
  }
768
905
  }
769
- }
906
+ };
770
907
 
771
- export { TrellisKernel };
908
+ export {
909
+ TrellisKernel
910
+ };