trellis 3.2.3 → 3.2.4

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 (194) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +4 -0
  3. package/dist/better-sqlite-backend-CDYOAJDF.js +209 -0
  4. package/dist/boot-middleware-LBJX4N2S.js +9 -0
  5. package/dist/boot-middleware-PATBLD52.js +9 -0
  6. package/dist/bridge-G5DPW6TY.js +2361 -0
  7. package/dist/bridge-JSSPQPRH.js +2389 -0
  8. package/dist/bridge-LNXE4HAW.js +2389 -0
  9. package/dist/bridge-OAAXJWSA.js +2389 -0
  10. package/dist/bridge-SFS63RHC.js +2367 -0
  11. package/dist/bridge-U5TOUBVM.js +2389 -0
  12. package/dist/browser/index.js +12 -12
  13. package/dist/{chunk-KSU2GW22.js → chunk-276W52FK.js} +8 -0
  14. package/dist/{chunk-KFQGP6VL.js → chunk-2ESYSVXG.js} +15 -0
  15. package/dist/{chunk-L5N5PR2S.js → chunk-2WW2X2BR.js} +313 -77
  16. package/dist/chunk-3XCOAP6G.js +48 -0
  17. package/dist/chunk-53PDCTJ3.js +1856 -0
  18. package/dist/{chunk-N6MYZT4O.js → chunk-547FZFKO.js} +1 -1
  19. package/dist/{chunk-7DUMWO5L.js → chunk-7WVOPXJV.js} +3 -3
  20. package/dist/chunk-CMSFD6OV.js +11801 -0
  21. package/dist/{chunk-RSWUFTO2.js → chunk-CPUYCCLT.js} +2 -2
  22. package/dist/{chunk-4HYPLFJD.js → chunk-FA5TFVA5.js} +1 -1
  23. package/dist/{chunk-4XIVMVHC.js → chunk-G3XIHPSQ.js} +1 -1
  24. package/dist/{chunk-JHHEXEDM.js → chunk-GCQF75T4.js} +3 -3
  25. package/dist/{chunk-FKQO5A3H.js → chunk-GHG4H3AS.js} +2 -2
  26. package/dist/{chunk-GLM4HGN4.js → chunk-GRWQPKYK.js} +1 -1
  27. package/dist/{chunk-PZ4XYZ4J.js → chunk-GXA73CNC.js} +33 -8
  28. package/dist/{chunk-6GEZ6DN5.js → chunk-H6VTC5SS.js} +3 -3
  29. package/dist/{chunk-S3XLFZ27.js → chunk-IHHSOBJS.js} +1 -1
  30. package/dist/chunk-IJNC25UD.js +2243 -0
  31. package/dist/{chunk-VDAKEOML.js → chunk-J6OUIION.js} +1 -1
  32. package/dist/chunk-JAVAYMMS.js +6 -0
  33. package/dist/{chunk-S6GBJ2ZB.js → chunk-JCQQFLO5.js} +1 -1
  34. package/dist/{chunk-FWRS4CSC.js → chunk-KQG6ZYXP.js} +3 -3
  35. package/dist/chunk-KXAISKZT.js +119 -0
  36. package/dist/chunk-N3R74ZSR.js +7949 -0
  37. package/dist/{chunk-GU374KWZ.js → chunk-NLFRRGX6.js} +3 -3
  38. package/dist/{chunk-XMQ7G77X.js → chunk-OB4CMMX6.js} +1 -1
  39. package/dist/chunk-OKNASCZY.js +182 -0
  40. package/dist/chunk-ONOPPX5E.js +394 -0
  41. package/dist/chunk-QMSU2RAH.js +98 -0
  42. package/dist/{chunk-TCKXSOBP.js → chunk-RARKFVWU.js} +8 -1
  43. package/dist/{chunk-2AACZRII.js → chunk-SJWVDS5M.js} +751 -162
  44. package/dist/{chunk-SPSPV5BC.js → chunk-SZ3VAB5P.js} +159 -2
  45. package/dist/chunk-V2ASD6RQ.js +147 -0
  46. package/dist/{chunk-KQ4A2D2P.js → chunk-V4YCJDYL.js} +58 -38
  47. package/dist/{chunk-LNUIGRDZ.js → chunk-VWKLKLYB.js} +1 -1
  48. package/dist/chunk-W5PADCDF.js +1856 -0
  49. package/dist/{chunk-MLC5BUYO.js → chunk-WMERMSWI.js} +1 -1
  50. package/dist/chunk-WXAURJUD.js +1948 -0
  51. package/dist/chunk-YC5I32PS.js +147 -0
  52. package/dist/{chunk-VBYUTRXX.js → chunk-YKVB4LUQ.js} +3 -3
  53. package/dist/{chunk-NWSW5YNS.js → chunk-YPT6XMS4.js} +20 -50
  54. package/dist/cli/deploy-cli.d.ts.map +1 -1
  55. package/dist/cli/deploy-cli.js +43 -4
  56. package/dist/cli/gateway-deploy-cli.d.ts +19 -0
  57. package/dist/cli/gateway-deploy-cli.d.ts.map +1 -0
  58. package/dist/cli/index.d.ts.map +1 -1
  59. package/dist/cli/index.js +1360 -881
  60. package/dist/cli/lane.d.ts.map +1 -1
  61. package/dist/cli/protocol.d.ts +6 -0
  62. package/dist/cli/protocol.d.ts.map +1 -0
  63. package/dist/client/index.browser.js +2 -2
  64. package/dist/client/index.js +11 -11
  65. package/dist/client/sdk.browser.js +1 -1
  66. package/dist/client/sdk.js +2 -2
  67. package/dist/cms/index.js +1 -1
  68. package/dist/config-KMY6RRK3.js +19 -0
  69. package/dist/core/index.js +13 -13
  70. package/dist/core/kernel/boot-middleware.d.ts +1 -1
  71. package/dist/core/kernel/boot-middleware.d.ts.map +1 -1
  72. package/dist/core/kernel/schema-middleware.d.ts +2 -1
  73. package/dist/core/kernel/schema-middleware.d.ts.map +1 -1
  74. package/dist/core/kernel/trellis-kernel.d.ts +10 -10
  75. package/dist/core/kernel/trellis-kernel.d.ts.map +1 -1
  76. package/dist/core/persist/factory.js +2 -2
  77. package/dist/core/persist/sqljs-backend.js +2 -2
  78. package/dist/db/index.js +30 -25
  79. package/dist/decisions/index.js +4 -4
  80. package/dist/embeddings/index.js +2 -2
  81. package/dist/engine.d.ts +24 -6
  82. package/dist/engine.d.ts.map +1 -1
  83. package/dist/gateway-deploy-cli-4TU4V3QI.js +312 -0
  84. package/dist/gateway-deploy-cli-A4ISTDHJ.js +298 -0
  85. package/dist/gateway-deploy-cli-D3XTKJQJ.js +312 -0
  86. package/dist/gateway-deploy-cli-ECV3OQCN.js +305 -0
  87. package/dist/gateway-deploy-cli-JUHKVIJE.js +296 -0
  88. package/dist/gateway-deploy-cli-NSDW2JLT.js +310 -0
  89. package/dist/gateway-serve-CM5EAZ52.js +113 -0
  90. package/dist/import-AJLYHFIA.js +10 -0
  91. package/dist/index.js +11 -11
  92. package/dist/launch-explorer-FVX6ZABW.js +95 -0
  93. package/dist/links/index.js +2 -2
  94. package/dist/mcp/bridge.d.ts +45 -0
  95. package/dist/mcp/bridge.d.ts.map +1 -0
  96. package/dist/mcp/discovery.d.ts +15 -0
  97. package/dist/mcp/discovery.d.ts.map +1 -0
  98. package/dist/mcp/gateway-config.d.ts +20 -0
  99. package/dist/mcp/gateway-config.d.ts.map +1 -0
  100. package/dist/mcp/gateway-serve.d.ts +19 -0
  101. package/dist/mcp/gateway-serve.d.ts.map +1 -0
  102. package/dist/mcp/gateway-serve.js +119 -0
  103. package/dist/mcp/graph-summary.d.ts +47 -0
  104. package/dist/mcp/graph-summary.d.ts.map +1 -0
  105. package/dist/mcp/room-audit.d.ts +14 -0
  106. package/dist/mcp/room-audit.d.ts.map +1 -0
  107. package/dist/mcp/room-helpers.d.ts +43 -0
  108. package/dist/mcp/room-helpers.d.ts.map +1 -0
  109. package/dist/mcp/room-registry.d.ts +32 -0
  110. package/dist/mcp/room-registry.d.ts.map +1 -0
  111. package/dist/mcp/room.d.ts +28 -0
  112. package/dist/mcp/room.d.ts.map +1 -0
  113. package/dist/plugins/agent-memory/index.js +1 -1
  114. package/dist/plugins/idea-garden/index.js +1 -1
  115. package/dist/plugins/plan-approval/index.js +1 -1
  116. package/dist/plugins/proactive-watcher/index.js +1 -1
  117. package/dist/protocol/envelope.d.ts +30 -0
  118. package/dist/protocol/envelope.d.ts.map +1 -0
  119. package/dist/protocol/index.d.ts +3 -0
  120. package/dist/protocol/index.d.ts.map +1 -0
  121. package/dist/protocol/whereami.d.ts +33 -0
  122. package/dist/protocol/whereami.d.ts.map +1 -0
  123. package/dist/query-KHDDIR5G.js +31 -0
  124. package/dist/react/index.js +1 -1
  125. package/dist/react/realtime.js +1 -1
  126. package/dist/react/schema-hooks.js +5 -5
  127. package/dist/realtime/index.js +3 -3
  128. package/dist/realtime/relay-server.d.ts.map +1 -1
  129. package/dist/realtime/room.d.ts.map +1 -1
  130. package/dist/realtime.bundle.js +2 -0
  131. package/dist/relay-server-BT6DCJ7F.js +12 -0
  132. package/dist/relay-server-MPQVGNQU.js +12 -0
  133. package/dist/relay-server-PAPW2EWC.js +12 -0
  134. package/dist/remote-manager-6ERQUBSL.js +224 -0
  135. package/dist/remote-manager-G665WWYY.js +224 -0
  136. package/dist/remote-manager-HJTEZ4OF.js +224 -0
  137. package/dist/remote-manager-NYP2Y5UR.js +224 -0
  138. package/dist/remote-manager-WGLCAMMC.js +224 -0
  139. package/dist/scaffold/write.d.ts.map +1 -1
  140. package/dist/schema/index.js +1 -1
  141. package/dist/server/cors.d.ts.map +1 -1
  142. package/dist/server/deploy-gateway.d.ts +27 -0
  143. package/dist/server/deploy-gateway.d.ts.map +1 -0
  144. package/dist/server/deploy.d.ts.map +1 -1
  145. package/dist/server/deploy.js +3 -2
  146. package/dist/server/discovery-mcp-gateway.d.ts +13 -0
  147. package/dist/server/discovery-mcp-gateway.d.ts.map +1 -0
  148. package/dist/server/index.js +38 -31
  149. package/dist/server/mcp-gateway.d.ts +27 -0
  150. package/dist/server/mcp-gateway.d.ts.map +1 -0
  151. package/dist/server/mcp-oauth-metadata.d.ts +31 -0
  152. package/dist/server/mcp-oauth-metadata.d.ts.map +1 -0
  153. package/dist/server/node-adapter.d.ts +7 -0
  154. package/dist/server/node-adapter.d.ts.map +1 -1
  155. package/dist/server/node-adapter.js +2 -2
  156. package/dist/server/realtime.d.ts.map +1 -1
  157. package/dist/server/server.d.ts +8 -0
  158. package/dist/server/server.d.ts.map +1 -1
  159. package/dist/server/streamable-mcp-gateway.d.ts +12 -0
  160. package/dist/server/streamable-mcp-gateway.d.ts.map +1 -0
  161. package/dist/server/usage-meter.d.ts +11 -0
  162. package/dist/server/usage-meter.d.ts.map +1 -1
  163. package/dist/server-4VEZHXXS.js +23 -0
  164. package/dist/{server-OGVWNDNK.js → server-556BMK4C.js} +1 -1
  165. package/dist/server-FQT2VYRE.js +23 -0
  166. package/dist/server-HGZE4ECC.js +23 -0
  167. package/dist/server-J4JKEAMH.js +23 -0
  168. package/dist/server-LXPM5TFR.js +23 -0
  169. package/dist/server-POB4NEUX.js +18 -0
  170. package/dist/server-VJKAPGPG.js +23 -0
  171. package/dist/server-YHS3XIIG.js +23 -0
  172. package/dist/server-ZHTPWPXS.js +23 -0
  173. package/dist/sprites-NC6D7YZS.js +27 -0
  174. package/dist/svelte/index.js +3 -3
  175. package/dist/svelte/schema-hooks.js +4 -4
  176. package/dist/sync/index.js +4 -4
  177. package/dist/tenancy-2SZTP4UD.js +16 -0
  178. package/dist/tenancy-7MTSESMJ.js +16 -0
  179. package/dist/tenancy-U4E7ZEAG.js +16 -0
  180. package/dist/vcs/decompose.d.ts.map +1 -1
  181. package/dist/vcs/index.js +5 -5
  182. package/dist/vcs/lane-disk-materialize.d.ts +11 -0
  183. package/dist/vcs/lane-disk-materialize.d.ts.map +1 -0
  184. package/dist/vcs/lane-worktree.d.ts +21 -0
  185. package/dist/vcs/lane-worktree.d.ts.map +1 -0
  186. package/dist/vcs/store.d.ts +28 -0
  187. package/dist/vcs/store.d.ts.map +1 -0
  188. package/dist/vcs/types.d.ts +5 -0
  189. package/dist/vcs/types.d.ts.map +1 -1
  190. package/dist/vm-config-YZRJ3KUB.js +21 -0
  191. package/dist/vue/index.js +3 -3
  192. package/dist/vue/schema-hooks.js +4 -4
  193. package/package.json +4 -3
  194. package/dist/chunk-GFZCJ4EH.js +0 -108
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  decisionEntityId,
3
3
  init_types
4
- } from "./chunk-N6MYZT4O.js";
4
+ } from "./chunk-547FZFKO.js";
5
5
  import {
6
6
  createVcsOp,
7
7
  init_ops
8
- } from "./chunk-GLM4HGN4.js";
8
+ } from "./chunk-GRWQPKYK.js";
9
9
  import {
10
10
  __esm
11
- } from "./chunk-KFQGP6VL.js";
11
+ } from "./chunk-2ESYSVXG.js";
12
12
 
13
13
  // src/decisions/hooks.ts
14
14
  function matchesPattern(pattern, toolName) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __require
3
- } from "./chunk-KFQGP6VL.js";
3
+ } from "./chunk-2ESYSVXG.js";
4
4
 
5
5
  // src/core/persist/sqlite-backend.ts
6
6
  var _DatabaseCtor = null;
@@ -0,0 +1,182 @@
1
+ import {
2
+ inferProjectContext,
3
+ init_infer,
4
+ init_profile,
5
+ init_write,
6
+ loadProfile
7
+ } from "./chunk-N3R74ZSR.js";
8
+
9
+ // src/scaffold/seed.ts
10
+ init_profile();
11
+ init_infer();
12
+ import { existsSync, writeFileSync } from "fs";
13
+ import { join } from "path";
14
+ async function seedContext(opts) {
15
+ const { rootPath, ide = "none", force = false } = opts;
16
+ const filesUpdated = [];
17
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
18
+ const profile = loadProfile();
19
+ const context = await inferProjectContext(rootPath);
20
+ const agentsDir = join(rootPath, ".trellis", "agents");
21
+ if (existsSync(agentsDir)) {
22
+ const agentsMdPath = join(agentsDir, "AGENTS.md");
23
+ if (existsSync(agentsMdPath) || force) {
24
+ const content = renderSeedAgentsMd(profile, context, timestamp);
25
+ writeFileSync(agentsMdPath, content, "utf-8");
26
+ filesUpdated.push(".trellis/agents/AGENTS.md");
27
+ }
28
+ const agentContextPath = join(agentsDir, "agent-context.json");
29
+ if (existsSync(agentContextPath) || force) {
30
+ const config = {
31
+ domain: context.domain,
32
+ ecosystem: context.ecosystem,
33
+ tools: [],
34
+ ontologies: [],
35
+ generatedAt: timestamp,
36
+ confidence: context.confidence,
37
+ lastSeed: timestamp
38
+ };
39
+ writeFileSync(agentContextPath, JSON.stringify(config, null, 2), "utf-8");
40
+ filesUpdated.push(".trellis/agents/agent-context.json");
41
+ }
42
+ }
43
+ switch (ide) {
44
+ case "cursor": {
45
+ const cursorRulesPath = join(rootPath, ".cursor", "rules.md");
46
+ if (existsSync(cursorRulesPath) || force) {
47
+ const content = renderSeedIdeRules(
48
+ profile,
49
+ context,
50
+ "cursor",
51
+ timestamp
52
+ );
53
+ writeFileSync(cursorRulesPath, content, "utf-8");
54
+ filesUpdated.push(".cursor/rules.md");
55
+ }
56
+ break;
57
+ }
58
+ case "devin": {
59
+ const devinRulesPath = join(rootPath, ".devin", "rules.md");
60
+ if (existsSync(devinRulesPath) || force) {
61
+ const content = renderSeedIdeRules(
62
+ profile,
63
+ context,
64
+ "devin",
65
+ timestamp
66
+ );
67
+ writeFileSync(devinRulesPath, content, "utf-8");
68
+ filesUpdated.push(".devin/rules.md");
69
+ }
70
+ break;
71
+ }
72
+ case "claude": {
73
+ const claudeSettingsPath = join(rootPath, ".claude", "settings.md");
74
+ if (existsSync(claudeSettingsPath) || force) {
75
+ const content = renderSeedIdeRules(
76
+ profile,
77
+ context,
78
+ "claude",
79
+ timestamp
80
+ );
81
+ writeFileSync(claudeSettingsPath, content, "utf-8");
82
+ filesUpdated.push(".claude/settings.md");
83
+ }
84
+ break;
85
+ }
86
+ case "none":
87
+ break;
88
+ }
89
+ return {
90
+ success: true,
91
+ filesUpdated,
92
+ timestamp
93
+ };
94
+ }
95
+ function renderSeedAgentsMd(profile, context, timestamp) {
96
+ const userName = profile?.name ?? "the user";
97
+ const userBio = profile?.bio ?? "(not provided)";
98
+ const userSkills = profile?.skills?.length ? profile.skills.join(", ") : "(not specified)";
99
+ return `# Trellis Agent Context
100
+
101
+ > This file was seeded by \`trellis seed\` on ${timestamp}
102
+ > Inference confidence: **${context.confidence}**
103
+
104
+ ---
105
+
106
+ ## About the User
107
+
108
+ | Field | Value |
109
+ |-------|-------|
110
+ | **Name** | ${userName} |
111
+ | **Bio** | ${userBio} |
112
+ | **Skills** | ${userSkills} |
113
+
114
+ ---
115
+
116
+ ## About This Project
117
+
118
+ | Field | Value |
119
+ |-------|-------|
120
+ | **Name** | ${context.name ?? "(unnamed)"} |
121
+ | **Domain** | ${context.domain ?? "(not determined)"} |
122
+ | **Description** | ${context.description ?? "(no description found)"} |
123
+ | **Ecosystem** | ${context.ecosystem ?? "unknown"} |
124
+ | **File count** | ~${context.fileCount} |
125
+
126
+ ---
127
+
128
+ ## Agent Instructions
129
+
130
+ You are operating in a Trellis-tracked repository. Follow these guidelines:
131
+
132
+ 1. **Read \`agent-context.json\`** in this directory for registered tools, ontologies, and domain settings.
133
+ 2. **Check \`skills/\`** for domain-specific operating instructions relevant to this project.
134
+ 3. **Check \`workflows/\`** for repeatable task procedures.
135
+ 4. **Run \`trellis seed\`** to refresh this context file when the project evolves.
136
+
137
+ ---
138
+
139
+ ## Quick Reference
140
+
141
+ \`\`\`bash
142
+ trellis status # Current repo state
143
+ trellis log # Causal operation history
144
+ trellis seed # Refresh this context
145
+ trellis milestone # Create narrative checkpoints
146
+ \`\`\`
147
+ `;
148
+ }
149
+ function renderSeedIdeRules(profile, context, ide, timestamp) {
150
+ const ideName = ide.charAt(0).toUpperCase() + ide.slice(1);
151
+ const projectName = context.name ?? "this project";
152
+ return `# ${ideName} Rules for ${projectName}
153
+
154
+ > Generated by \`trellis seed\` on ${timestamp}
155
+
156
+ ## Project Context
157
+ - **Domain**: ${context.domain ?? "(not determined)"}
158
+ - **Ecosystem**: ${context.ecosystem ?? "unknown"}
159
+ - **File count**: ~${context.fileCount}
160
+ - **Confidence**: ${context.confidence}
161
+
162
+ ## Agent Instructions
163
+ You are working in a Trellis-tracked repository. See \`.trellis/agents/AGENTS.md\` for full context.
164
+
165
+ ## Commands
166
+ - \`trellis status\` \u2014 Check repo state
167
+ - \`trellis seed\` \u2014 Refresh this context file
168
+ - \`trellis log\` \u2014 View causal history
169
+
170
+ ---
171
+ *Auto-generated by Trellis. Run \`trellis seed\` to refresh context.*
172
+ `;
173
+ }
174
+
175
+ // src/scaffold/index.ts
176
+ init_infer();
177
+ init_profile();
178
+ init_write();
179
+
180
+ export {
181
+ seedContext
182
+ };
@@ -0,0 +1,394 @@
1
+ import {
2
+ TrellisVcsEngine,
3
+ init_engine
4
+ } from "./chunk-N3R74ZSR.js";
5
+ import {
6
+ IdbOpLog
7
+ } from "./chunk-MPXUVGT3.js";
8
+ import {
9
+ JsonOpLog,
10
+ init_op_log
11
+ } from "./chunk-IJNC25UD.js";
12
+ import {
13
+ PartyKitRoomTransport,
14
+ TrellisVcsSyncPeer
15
+ } from "./chunk-CPUYCCLT.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,98 @@
1
+ import {
2
+ decompose,
3
+ init_blob_store,
4
+ init_branch,
5
+ init_checkpoint,
6
+ init_decompose,
7
+ init_diff,
8
+ init_issue,
9
+ init_lane,
10
+ init_merge,
11
+ init_milestone,
12
+ init_op_log
13
+ } from "./chunk-YKVB4LUQ.js";
14
+ import {
15
+ init_types
16
+ } from "./chunk-547FZFKO.js";
17
+ import {
18
+ init_ops,
19
+ isVcsOp
20
+ } from "./chunk-GRWQPKYK.js";
21
+
22
+ // src/vcs/index.ts
23
+ init_types();
24
+ init_ops();
25
+ init_decompose();
26
+
27
+ // src/vcs/vcs-middleware.ts
28
+ init_decompose();
29
+ init_ops();
30
+ var VcsMiddleware = class {
31
+ name = "vcs";
32
+ async handleOp(op, ctx, next) {
33
+ if (!isVcsOp(op)) {
34
+ return next(op, ctx);
35
+ }
36
+ const vcsOp = op;
37
+ const decomposed = decompose(vcsOp);
38
+ if (decomposed.deleteFacts.length > 0) {
39
+ await next(
40
+ {
41
+ ...op,
42
+ kind: "deleteFacts",
43
+ facts: decomposed.deleteFacts,
44
+ links: void 0
45
+ },
46
+ ctx
47
+ );
48
+ }
49
+ if (decomposed.deleteLinks.length > 0) {
50
+ await next(
51
+ {
52
+ ...op,
53
+ kind: "deleteLinks",
54
+ facts: void 0,
55
+ links: decomposed.deleteLinks
56
+ },
57
+ ctx
58
+ );
59
+ }
60
+ if (decomposed.addFacts.length > 0) {
61
+ await next(
62
+ {
63
+ ...op,
64
+ kind: "addFacts",
65
+ facts: decomposed.addFacts,
66
+ links: void 0
67
+ },
68
+ ctx
69
+ );
70
+ }
71
+ if (decomposed.addLinks.length > 0) {
72
+ await next(
73
+ {
74
+ ...op,
75
+ kind: "addLinks",
76
+ facts: void 0,
77
+ links: decomposed.addLinks
78
+ },
79
+ ctx
80
+ );
81
+ }
82
+ }
83
+ };
84
+
85
+ // src/vcs/index.ts
86
+ init_blob_store();
87
+ init_branch();
88
+ init_milestone();
89
+ init_checkpoint();
90
+ init_diff();
91
+ init_merge();
92
+ init_issue();
93
+ init_op_log();
94
+ init_lane();
95
+
96
+ export {
97
+ VcsMiddleware
98
+ };