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
@@ -0,0 +1,394 @@
1
+ import {
2
+ TrellisVcsEngine,
3
+ init_engine
4
+ } from "./chunk-L5N5PR2S.js";
5
+ import {
6
+ IdbOpLog
7
+ } from "./chunk-MPXUVGT3.js";
8
+ import {
9
+ JsonOpLog,
10
+ init_op_log
11
+ } from "./chunk-VBYUTRXX.js";
12
+ import {
13
+ PartyKitRoomTransport,
14
+ TrellisVcsSyncPeer
15
+ } from "./chunk-RSWUFTO2.js";
16
+ import {
17
+ Signal
18
+ } from "./chunk-UBGUDMUV.js";
19
+
20
+ // src/client/vcs-client.ts
21
+ init_engine();
22
+ init_op_log();
23
+ var DEFAULT_SYNC_STATUS = {
24
+ connected: false,
25
+ pending: 0,
26
+ synced: false,
27
+ lastSyncAt: null,
28
+ lastError: null
29
+ };
30
+ var MemoryOpLog = class {
31
+ ops = [];
32
+ hashes = /* @__PURE__ */ new Set();
33
+ load() {
34
+ }
35
+ append(op) {
36
+ if (this.hashes.has(op.hash)) return;
37
+ this.ops.push(op);
38
+ this.hashes.add(op.hash);
39
+ }
40
+ readAll() {
41
+ return [...this.ops];
42
+ }
43
+ getLastOp() {
44
+ return this.ops[this.ops.length - 1];
45
+ }
46
+ count() {
47
+ return this.ops.length;
48
+ }
49
+ };
50
+ var TrellisClient = class _TrellisClient {
51
+ _engine;
52
+ _syncPeer;
53
+ _peerId = "";
54
+ _opLog;
55
+ _roomId = "room";
56
+ _pushDebounceMs = 200;
57
+ _snapshotMaxOps = 500;
58
+ _pushTimer;
59
+ _closed = false;
60
+ /** Raw causal log. Updated on every local or remote op. */
61
+ _ops = new Signal([]);
62
+ /** Sync connection state. */
63
+ _syncStatus = new Signal({ ...DEFAULT_SYNC_STATUS });
64
+ _opHandlers = [];
65
+ _topicSubs = /* @__PURE__ */ new Map();
66
+ constructor() {
67
+ }
68
+ /** Factory — opens the repo, loads ops, and optionally connects to sync. */
69
+ static async open(opts) {
70
+ const client = new _TrellisClient();
71
+ client._peerId = opts.agentId ?? `client:${crypto.randomUUID()}`;
72
+ client._opLog = client._createOpLog(opts);
73
+ if ("load" in client._opLog && typeof client._opLog.load === "function") {
74
+ const maybePromise = client._opLog.load();
75
+ if (maybePromise instanceof Promise) await maybePromise;
76
+ }
77
+ client._engine = new TrellisVcsEngine({
78
+ rootPath: opts.repo,
79
+ agentId: client._peerId,
80
+ opLog: client._opLog
81
+ });
82
+ client._engine.open();
83
+ client._refreshState();
84
+ if (opts.sync) {
85
+ client._roomId = opts.sync.roomId ?? "room";
86
+ client._pushDebounceMs = opts.sync.pushDebounceMs ?? 200;
87
+ client._snapshotMaxOps = opts.sync.snapshotMaxOps ?? 500;
88
+ const transport = client._createTransport(opts.sync, client);
89
+ client._syncPeer = new TrellisVcsSyncPeer({
90
+ peerId: client._peerId,
91
+ engine: client._engine,
92
+ transport,
93
+ onIntegrate: () => {
94
+ client._refreshState();
95
+ client._setSyncStatus({ synced: true, lastError: null });
96
+ }
97
+ });
98
+ if (opts.sync.connectOnOpen !== false) {
99
+ try {
100
+ await client._connectAndCatchUp();
101
+ } catch {
102
+ }
103
+ }
104
+ }
105
+ return client;
106
+ }
107
+ // -------------------------------------------------------------------------
108
+ // Public API
109
+ // -------------------------------------------------------------------------
110
+ /** Subscribe to reactive topics. Callback receives current value immediately. */
111
+ subscribe(topic, callback) {
112
+ if (!this._topicSubs.has(topic)) {
113
+ this._topicSubs.set(topic, /* @__PURE__ */ new Set());
114
+ }
115
+ const subs = this._topicSubs.get(topic);
116
+ subs.add(callback);
117
+ const current = this._getTopicValue(topic);
118
+ if (current !== void 0) {
119
+ try {
120
+ callback(current);
121
+ } catch {
122
+ }
123
+ }
124
+ return () => {
125
+ subs.delete(callback);
126
+ };
127
+ }
128
+ /** Listen for raw op events (local or remote). */
129
+ on(event, handler) {
130
+ this._opHandlers.push(handler);
131
+ return () => {
132
+ const idx = this._opHandlers.indexOf(handler);
133
+ if (idx >= 0) this._opHandlers.splice(idx, 1);
134
+ };
135
+ }
136
+ /** Create an issue and emit reactive updates. */
137
+ async createIssue(title, opts) {
138
+ const createOpts = { ...opts };
139
+ if (opts?.lane) {
140
+ createOpts.laneId = opts.lane;
141
+ }
142
+ const op = await this._engine.createIssue(title, createOpts);
143
+ this._refreshState();
144
+ this._schedulePush();
145
+ return op;
146
+ }
147
+ /** Force a push/pull sync with the room. */
148
+ async sync() {
149
+ if (!this._syncPeer) {
150
+ throw new Error(
151
+ "No sync configured. Pass sync.url to TrellisClient.open() to enable multiplayer sync."
152
+ );
153
+ }
154
+ await this._connectAndCatchUp();
155
+ }
156
+ /** Close (complete) an issue. */
157
+ async closeIssue(id, opts) {
158
+ const result = await this._engine.closeIssue(id, opts);
159
+ if (result.op) {
160
+ this._refreshState();
161
+ this._schedulePush();
162
+ }
163
+ return result.op ?? null;
164
+ }
165
+ /** Reopen a closed issue. */
166
+ async reopenIssue(id) {
167
+ const op = await this._engine.reopenIssue(id);
168
+ this._refreshState();
169
+ this._schedulePush();
170
+ return op;
171
+ }
172
+ /** Read current ops without subscribing. */
173
+ getOps() {
174
+ return this._engine.getOps();
175
+ }
176
+ /** Read current issues without subscribing. */
177
+ listIssues() {
178
+ return this._engine.listIssues();
179
+ }
180
+ /** Clean up resources. */
181
+ close() {
182
+ if (this._closed) return;
183
+ this._closed = true;
184
+ if (this._pushTimer !== void 0) {
185
+ clearTimeout(this._pushTimer);
186
+ this._pushTimer = void 0;
187
+ }
188
+ this._syncPeer?.close();
189
+ if ("close" in this._opLog && typeof this._opLog.close === "function") {
190
+ void this._opLog.close();
191
+ }
192
+ this._engine.stop();
193
+ this._setSyncStatus({ connected: false });
194
+ }
195
+ // -------------------------------------------------------------------------
196
+ // Reactive accessors (for framework adapters)
197
+ // -------------------------------------------------------------------------
198
+ /** Signal exposing the full causal op log. */
199
+ get opsSignal() {
200
+ return this._ops;
201
+ }
202
+ /** Signal exposing sync connection status. */
203
+ get syncStatusSignal() {
204
+ return this._syncStatus;
205
+ }
206
+ /** Underlying VCS engine (for advanced sync wiring and queries). */
207
+ get engine() {
208
+ return this._engine;
209
+ }
210
+ // -------------------------------------------------------------------------
211
+ // Private
212
+ // -------------------------------------------------------------------------
213
+ _createTransport(sync, client) {
214
+ if (sync.transport) return sync.transport;
215
+ if (!sync.url) {
216
+ throw new Error(
217
+ "sync.transport or sync.url is required when sync is configured."
218
+ );
219
+ }
220
+ return new PartyKitRoomTransport({
221
+ peerId: this._peerId,
222
+ roomUrl: sync.url,
223
+ auth: sync.auth,
224
+ roomId: sync.roomId,
225
+ reconnect: sync.reconnect !== false,
226
+ onReconnect: () => client._onTransportReconnect(),
227
+ onDisconnect: () => client._setSyncStatus({ connected: false })
228
+ });
229
+ }
230
+ _createOpLog(opts) {
231
+ switch (opts.persist) {
232
+ case "indexeddb":
233
+ return new IdbOpLog({ dbName: opts.repo });
234
+ case "memory":
235
+ return new MemoryOpLog();
236
+ case "opfs":
237
+ throw new Error(
238
+ 'OPFS persistence not yet implemented. Use "indexeddb" or "memory".'
239
+ );
240
+ default:
241
+ if (typeof globalThis !== "undefined" && "indexedDB" in globalThis) {
242
+ return new IdbOpLog({ dbName: opts.repo });
243
+ }
244
+ return new JsonOpLog(`${opts.repo}/.trellis/ops.json`);
245
+ }
246
+ }
247
+ async _connectTransport() {
248
+ const transport = this._syncPeer?.getTransport();
249
+ if (transport && "connect" in transport && typeof transport.connect === "function") {
250
+ await transport.connect();
251
+ this._setSyncStatus({ connected: true, lastError: null });
252
+ } else if (transport) {
253
+ this._setSyncStatus({ connected: true, lastError: null });
254
+ }
255
+ }
256
+ async _connectAndCatchUp() {
257
+ if (!this._syncPeer) return;
258
+ this._setSyncStatus({
259
+ pending: this._syncStatus.value.pending + 1,
260
+ synced: false
261
+ });
262
+ try {
263
+ await this._connectTransport();
264
+ await this._requestSnapshot();
265
+ const result = await this._syncPeer.syncWith(this._roomId);
266
+ this._setSyncStatus({
267
+ connected: true,
268
+ synced: result.rejected === 0,
269
+ lastSyncAt: (/* @__PURE__ */ new Date()).toISOString(),
270
+ lastError: result.rejected > 0 ? `${result.rejected} op(s) rejected during sync` : null
271
+ });
272
+ } catch (err) {
273
+ const message = err instanceof Error ? err.message : String(err);
274
+ this._setSyncStatus({
275
+ connected: false,
276
+ synced: false,
277
+ lastError: message
278
+ });
279
+ throw err;
280
+ } finally {
281
+ this._setSyncStatus({
282
+ pending: Math.max(0, this._syncStatus.value.pending - 1)
283
+ });
284
+ }
285
+ }
286
+ async _onTransportReconnect() {
287
+ if (this._closed || !this._syncPeer) return;
288
+ try {
289
+ await this._connectAndCatchUp();
290
+ } catch {
291
+ }
292
+ }
293
+ async _requestSnapshot() {
294
+ if (!this._syncPeer || this._snapshotMaxOps <= 0) return;
295
+ await this._syncPeer.requestSnapshot(this._roomId, this._snapshotMaxOps);
296
+ await new Promise((resolve) => {
297
+ queueMicrotask(() => resolve());
298
+ });
299
+ }
300
+ _schedulePush() {
301
+ if (!this._syncPeer || this._pushDebounceMs <= 0 || this._closed) return;
302
+ if (this._pushTimer !== void 0) {
303
+ clearTimeout(this._pushTimer);
304
+ }
305
+ this._pushTimer = setTimeout(() => {
306
+ this._pushTimer = void 0;
307
+ void this._pushToRoom();
308
+ }, this._pushDebounceMs);
309
+ }
310
+ async _pushToRoom() {
311
+ if (!this._syncPeer || this._closed) return;
312
+ this._setSyncStatus({
313
+ pending: this._syncStatus.value.pending + 1,
314
+ synced: false
315
+ });
316
+ try {
317
+ await this._connectTransport();
318
+ const result = await this._syncPeer.pushTo(this._roomId);
319
+ this._setSyncStatus({
320
+ connected: true,
321
+ synced: result.remoteRejected.length === 0,
322
+ lastSyncAt: (/* @__PURE__ */ new Date()).toISOString(),
323
+ lastError: result.remoteRejected.length > 0 ? `${result.remoteRejected.length} op(s) rejected by room` : null
324
+ });
325
+ } catch (err) {
326
+ const message = err instanceof Error ? err.message : String(err);
327
+ this._setSyncStatus({
328
+ connected: false,
329
+ synced: false,
330
+ lastError: message
331
+ });
332
+ } finally {
333
+ this._setSyncStatus({
334
+ pending: Math.max(0, this._syncStatus.value.pending - 1)
335
+ });
336
+ }
337
+ }
338
+ _refreshState() {
339
+ const ops = this._engine.getOps();
340
+ const previousHashes = new Set(this._ops.value.map((o) => o.hash));
341
+ this._ops.value = ops;
342
+ for (const op of ops) {
343
+ if (!previousHashes.has(op.hash)) {
344
+ this._emitOp(op);
345
+ }
346
+ }
347
+ this._broadcastTopic("ops", ops);
348
+ this._broadcastTopic("issues", this._engine.listIssues());
349
+ this._broadcastTopic("milestones", this._engine.listMilestones());
350
+ this._broadcastTopic("branches", this._engine.listBranches());
351
+ }
352
+ _emitOp(op) {
353
+ for (const h of this._opHandlers) {
354
+ try {
355
+ h(op);
356
+ } catch {
357
+ }
358
+ }
359
+ }
360
+ _broadcastTopic(topic, data) {
361
+ const subs = this._topicSubs.get(topic);
362
+ if (!subs) return;
363
+ for (const fn of subs) {
364
+ try {
365
+ fn(data);
366
+ } catch {
367
+ }
368
+ }
369
+ }
370
+ _getTopicValue(topic) {
371
+ switch (topic) {
372
+ case "ops":
373
+ return this._ops.value;
374
+ case "syncStatus":
375
+ return this._syncStatus.value;
376
+ case "issues":
377
+ return this._engine.listIssues();
378
+ case "milestones":
379
+ return this._engine.listMilestones();
380
+ case "branches":
381
+ return this._engine.listBranches();
382
+ default:
383
+ return void 0;
384
+ }
385
+ }
386
+ _setSyncStatus(partial) {
387
+ this._syncStatus.value = { ...this._syncStatus.value, ...partial };
388
+ this._broadcastTopic("syncStatus", this._syncStatus.value);
389
+ }
390
+ };
391
+
392
+ export {
393
+ TrellisClient
394
+ };
@@ -0,0 +1,211 @@
1
+ import {
2
+ SPRITE_ENSURE_BUN_SH,
3
+ assertSpriteCli,
4
+ ensureSprite,
5
+ ensureSpritePublicAccess,
6
+ resolveSpritePublicUrl,
7
+ runSpriteCopy,
8
+ runSpriteExec
9
+ } from "./chunk-CAG4FULI.js";
10
+ import {
11
+ updateConfig
12
+ } from "./chunk-JA7AIHRK.js";
13
+ import {
14
+ __require
15
+ } from "./chunk-KFQGP6VL.js";
16
+
17
+ // src/server/deploy.ts
18
+ import { existsSync, writeFileSync, mkdirSync } from "fs";
19
+ import { join, resolve } from "path";
20
+
21
+ // src/server/deploy-meta.ts
22
+ var DEPLOY_NAME_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
23
+ var MIN_LEN = 3;
24
+ var MAX_LEN = 32;
25
+ var DeployNameError = class extends Error {
26
+ constructor(message) {
27
+ super(message);
28
+ this.name = "DeployNameError";
29
+ }
30
+ };
31
+ function normalizeDeployName(name) {
32
+ return name.trim().toLowerCase();
33
+ }
34
+ function validateDeployName(name) {
35
+ const normalized = normalizeDeployName(name);
36
+ if (!normalized) {
37
+ throw new DeployNameError("Deploy name is required.");
38
+ }
39
+ if (normalized.length < MIN_LEN || normalized.length > MAX_LEN) {
40
+ throw new DeployNameError(
41
+ `Deploy name must be ${MIN_LEN}\u2013${MAX_LEN} characters (got ${normalized.length}).`
42
+ );
43
+ }
44
+ if (normalized.includes("--")) {
45
+ throw new DeployNameError(
46
+ "Deploy name cannot contain consecutive hyphens."
47
+ );
48
+ }
49
+ if (!DEPLOY_NAME_RE.test(normalized)) {
50
+ throw new DeployNameError(
51
+ "Deploy name must start with a letter and use only lowercase letters, numbers, and single hyphens (e.g. my-app)."
52
+ );
53
+ }
54
+ return normalized;
55
+ }
56
+ function buildDeployUrl(name) {
57
+ const slug = validateDeployName(name);
58
+ return `https://${slug}.sprites.app`;
59
+ }
60
+ var SPRITE_PUBLIC_HTTP_PORT = 8080;
61
+
62
+ // src/server/deploy.ts
63
+ async function deploy(opts) {
64
+ const { configDir = ".", onProgress = () => {
65
+ } } = opts;
66
+ const listenPort = opts.port ?? SPRITE_PUBLIC_HTTP_PORT;
67
+ const name = validateDeployName(opts.name);
68
+ const apiKey = opts.apiKey ?? generateSecret("spk_");
69
+ const jwtSecret = opts.jwtSecret ?? generateSecret("jws_");
70
+ if (opts.stub) {
71
+ const url2 = buildDeployUrl(name);
72
+ onProgress("Stub deploy \u2014 skipping Sprites provisioning");
73
+ onProgress("Writing .trellis-db.json...");
74
+ writeRemoteDeployConfig({ name, url: url2, apiKey, configDir });
75
+ return { url: url2, name, apiKey };
76
+ }
77
+ onProgress("Checking Sprites CLI...");
78
+ await assertSpriteCli();
79
+ onProgress("Writing server entrypoint...");
80
+ const tmpDir = resolve(configDir, ".trellis-deploy");
81
+ if (!existsSync(tmpDir)) mkdirSync(tmpDir, { recursive: true });
82
+ const entrypoint = join(tmpDir, "server-entry.ts");
83
+ writeFileSync(
84
+ entrypoint,
85
+ generateServerEntrypoint({ port: listenPort, apiKey, jwtSecret })
86
+ );
87
+ onProgress("Bundling server with Bun...");
88
+ const bundlePath = join(tmpDir, "server.js");
89
+ await runBun([
90
+ "build",
91
+ entrypoint,
92
+ "--outfile",
93
+ bundlePath,
94
+ "--target",
95
+ "bun",
96
+ "--format",
97
+ "esm"
98
+ ]);
99
+ onProgress(`Ensuring Sprite: ${name}...`);
100
+ await ensureSprite(name);
101
+ onProgress("Configuring public URL...");
102
+ await ensureSpritePublicAccess(name);
103
+ const url = await resolveSpritePublicUrl(name);
104
+ onProgress(`Uploading to Sprite: ${name}...`);
105
+ await runSpriteExec(name, "mkdir -p /home/sprite/trellis-db");
106
+ await runSpriteCopy(bundlePath, name, "/home/sprite/trellis-db/server.js");
107
+ onProgress("Ensuring Bun is installed...");
108
+ const bunPath = await runSpriteExec(name, SPRITE_ENSURE_BUN_SH);
109
+ if (!bunPath.includes("bun")) {
110
+ throw new Error(`Bun install failed on sprite ${name}: ${bunPath || "(no output)"}`);
111
+ }
112
+ onProgress("Starting server...");
113
+ await runSpriteExec(
114
+ name,
115
+ 'pkill -f "/home/sprite/trellis-db/server.js" 2>/dev/null || true'
116
+ ).catch(() => {
117
+ });
118
+ const bun = bunPath.trim().split("\n").pop().trim();
119
+ await runSpriteExec(
120
+ name,
121
+ `cd /home/sprite/trellis-db && (nohup ${bun} run server.js >> server.log 2>&1 </dev/null &); exit 0`
122
+ );
123
+ onProgress("Waiting for health check...");
124
+ await waitForDeployHealth(url, 6e4);
125
+ onProgress("Writing .trellis-db.json...");
126
+ writeRemoteDeployConfig({ name, url, apiKey, configDir });
127
+ return { url, name, apiKey };
128
+ }
129
+ function writeRemoteDeployConfig(opts) {
130
+ updateConfig(
131
+ {
132
+ mode: "remote",
133
+ url: opts.url,
134
+ apiKey: opts.apiKey,
135
+ spriteName: opts.name,
136
+ deployedAt: (/* @__PURE__ */ new Date()).toISOString()
137
+ },
138
+ opts.configDir
139
+ );
140
+ }
141
+ async function waitForDeployHealth(url, timeoutMs) {
142
+ const deadline = Date.now() + timeoutMs;
143
+ const healthUrl = `${url.replace(/\/$/, "")}/health`;
144
+ let lastStatus = 0;
145
+ while (Date.now() < deadline) {
146
+ try {
147
+ const res = await fetch(healthUrl);
148
+ lastStatus = res.status;
149
+ if (res.ok) return;
150
+ } catch {
151
+ }
152
+ await new Promise((r) => setTimeout(r, 2e3));
153
+ }
154
+ throw new Error(
155
+ `Deploy health check timed out (${healthUrl}${lastStatus ? `, last status ${lastStatus}` : ""})`
156
+ );
157
+ }
158
+ function generateSecret(prefix) {
159
+ const bytes = new Uint8Array(24);
160
+ crypto.getRandomValues(bytes);
161
+ const b64 = btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
162
+ return `${prefix}${b64}`;
163
+ }
164
+ async function runBun(args) {
165
+ const { execFile } = __require("child_process");
166
+ const { promisify } = __require("util");
167
+ const execFileAsync = promisify(execFile);
168
+ try {
169
+ await execFileAsync("bun", args);
170
+ } catch (err) {
171
+ throw new Error(
172
+ `bun ${args[0]} failed (exit ${err.code ?? "?"}): ${err.stderr ?? err.message}`
173
+ );
174
+ }
175
+ }
176
+ function generateServerEntrypoint(opts) {
177
+ return `
178
+ import { TenantPool, startServer } from 'trellis/server';
179
+ import { readConfig, defaultLocalConfig, writeConfig } from 'trellis/client';
180
+ import { join } from 'path';
181
+ import { existsSync } from 'fs';
182
+
183
+ const dbPath = '/home/sprite/trellis-db/data';
184
+ const configDir = '/home/sprite/trellis-db';
185
+
186
+ writeConfig(defaultLocalConfig(dbPath, {
187
+ apiKey: '${opts.apiKey}',
188
+ jwtSecret: '${opts.jwtSecret}',
189
+ port: ${opts.port},
190
+ }), configDir);
191
+
192
+ const config = readConfig(configDir)!;
193
+ // Sprites VMs lack better-sqlite3 native bindings \u2014 use WASM sql.js backend.
194
+ const pool = new TenantPool(dbPath, { backend: { backend: 'sqljs' } });
195
+ await pool.preload();
196
+
197
+ const server = startServer({ port: ${opts.port}, config, pool });
198
+
199
+ console.log('Trellis DB running on port ${opts.port}');
200
+ console.log(\`Listening on port ${opts.port}\`);
201
+ `;
202
+ }
203
+
204
+ export {
205
+ DeployNameError,
206
+ normalizeDeployName,
207
+ validateDeployName,
208
+ buildDeployUrl,
209
+ SPRITE_PUBLIC_HTTP_PORT,
210
+ deploy
211
+ };