trellis 3.2.2 → 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 (210) 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 +9 -9
  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-H6JB3PZ3.js → chunk-5KSGGKET.js} +1 -1
  20. package/dist/{chunk-J2TXUFCZ.js → chunk-6RWGFC3N.js} +134 -20
  21. package/dist/{chunk-QB5ISE47.js → chunk-7WVOPXJV.js} +3 -3
  22. package/dist/chunk-CMSFD6OV.js +11801 -0
  23. package/dist/{chunk-RSWUFTO2.js → chunk-CPUYCCLT.js} +2 -2
  24. package/dist/{chunk-4HYPLFJD.js → chunk-FA5TFVA5.js} +1 -1
  25. package/dist/{chunk-4XIVMVHC.js → chunk-G3XIHPSQ.js} +1 -1
  26. package/dist/{chunk-JHHEXEDM.js → chunk-GCQF75T4.js} +3 -3
  27. package/dist/{chunk-FKQO5A3H.js → chunk-GHG4H3AS.js} +2 -2
  28. package/dist/{chunk-GLM4HGN4.js → chunk-GRWQPKYK.js} +1 -1
  29. package/dist/{chunk-PZ4XYZ4J.js → chunk-GXA73CNC.js} +33 -8
  30. package/dist/{chunk-6GEZ6DN5.js → chunk-H6VTC5SS.js} +3 -3
  31. package/dist/{chunk-S3XLFZ27.js → chunk-IHHSOBJS.js} +1 -1
  32. package/dist/chunk-IJNC25UD.js +2243 -0
  33. package/dist/{chunk-VDAKEOML.js → chunk-J6OUIION.js} +1 -1
  34. package/dist/chunk-JAVAYMMS.js +6 -0
  35. package/dist/{chunk-S6GBJ2ZB.js → chunk-JCQQFLO5.js} +1 -1
  36. package/dist/{chunk-FWRS4CSC.js → chunk-KQG6ZYXP.js} +3 -3
  37. package/dist/chunk-KXAISKZT.js +119 -0
  38. package/dist/chunk-N3R74ZSR.js +7949 -0
  39. package/dist/{chunk-GU374KWZ.js → chunk-NLFRRGX6.js} +3 -3
  40. package/dist/{chunk-XMQ7G77X.js → chunk-OB4CMMX6.js} +1 -1
  41. package/dist/chunk-OKNASCZY.js +182 -0
  42. package/dist/chunk-ONOPPX5E.js +394 -0
  43. package/dist/chunk-QMSU2RAH.js +98 -0
  44. package/dist/{chunk-TCKXSOBP.js → chunk-RARKFVWU.js} +8 -1
  45. package/dist/{chunk-2W3MHTMG.js → chunk-SJWVDS5M.js} +835 -127
  46. package/dist/{chunk-SPSPV5BC.js → chunk-SZ3VAB5P.js} +159 -2
  47. package/dist/chunk-V2ASD6RQ.js +147 -0
  48. package/dist/{chunk-KQ4A2D2P.js → chunk-V4YCJDYL.js} +58 -38
  49. package/dist/{chunk-LNUIGRDZ.js → chunk-VWKLKLYB.js} +1 -1
  50. package/dist/chunk-W5PADCDF.js +1856 -0
  51. package/dist/{chunk-MLC5BUYO.js → chunk-WMERMSWI.js} +1 -1
  52. package/dist/{chunk-IZX2PLIB.js → chunk-WXAURJUD.js} +835 -127
  53. package/dist/chunk-YC5I32PS.js +147 -0
  54. package/dist/{chunk-VBYUTRXX.js → chunk-YKVB4LUQ.js} +3 -3
  55. package/dist/{chunk-7ZFRVCUE.js → chunk-YPT6XMS4.js} +48 -64
  56. package/dist/cli/deploy-cli.d.ts.map +1 -1
  57. package/dist/{deploy-cli-C35HTITO.js → cli/deploy-cli.js} +45 -6
  58. package/dist/cli/gateway-deploy-cli.d.ts +19 -0
  59. package/dist/cli/gateway-deploy-cli.d.ts.map +1 -0
  60. package/dist/cli/index.d.ts.map +1 -1
  61. package/dist/cli/index.js +1363 -884
  62. package/dist/cli/lane.d.ts.map +1 -1
  63. package/dist/cli/protocol.d.ts +6 -0
  64. package/dist/cli/protocol.d.ts.map +1 -0
  65. package/dist/client/index.browser.js +2 -2
  66. package/dist/client/index.js +11 -11
  67. package/dist/client/sdk.browser.d.ts +28 -1
  68. package/dist/client/sdk.browser.d.ts.map +1 -1
  69. package/dist/client/sdk.browser.js +2 -2
  70. package/dist/client/sdk.js +2 -2
  71. package/dist/cms/index.js +1 -1
  72. package/dist/config-KMY6RRK3.js +19 -0
  73. package/dist/core/index.js +17 -17
  74. package/dist/core/kernel/boot-middleware.d.ts +1 -1
  75. package/dist/core/kernel/boot-middleware.d.ts.map +1 -1
  76. package/dist/core/kernel/schema-middleware.d.ts +2 -1
  77. package/dist/core/kernel/schema-middleware.d.ts.map +1 -1
  78. package/dist/core/kernel/trellis-kernel.d.ts +10 -10
  79. package/dist/core/kernel/trellis-kernel.d.ts.map +1 -1
  80. package/dist/core/persist/factory.js +2 -2
  81. package/dist/core/persist/sqljs-backend.js +2 -2
  82. package/dist/db/index.js +32 -27
  83. package/dist/decisions/index.js +4 -4
  84. package/dist/embeddings/index.js +2 -2
  85. package/dist/engine.d.ts +24 -6
  86. package/dist/engine.d.ts.map +1 -1
  87. package/dist/gateway-deploy-cli-4TU4V3QI.js +312 -0
  88. package/dist/gateway-deploy-cli-A4ISTDHJ.js +298 -0
  89. package/dist/gateway-deploy-cli-D3XTKJQJ.js +312 -0
  90. package/dist/gateway-deploy-cli-ECV3OQCN.js +305 -0
  91. package/dist/gateway-deploy-cli-JUHKVIJE.js +296 -0
  92. package/dist/gateway-deploy-cli-NSDW2JLT.js +310 -0
  93. package/dist/gateway-serve-CM5EAZ52.js +113 -0
  94. package/dist/import-AJLYHFIA.js +10 -0
  95. package/dist/index.js +11 -11
  96. package/dist/launch-explorer-FVX6ZABW.js +95 -0
  97. package/dist/links/index.js +2 -2
  98. package/dist/mcp/bridge.d.ts +45 -0
  99. package/dist/mcp/bridge.d.ts.map +1 -0
  100. package/dist/mcp/discovery.d.ts +15 -0
  101. package/dist/mcp/discovery.d.ts.map +1 -0
  102. package/dist/mcp/gateway-config.d.ts +20 -0
  103. package/dist/mcp/gateway-config.d.ts.map +1 -0
  104. package/dist/mcp/gateway-serve.d.ts +19 -0
  105. package/dist/mcp/gateway-serve.d.ts.map +1 -0
  106. package/dist/mcp/gateway-serve.js +119 -0
  107. package/dist/mcp/graph-summary.d.ts +47 -0
  108. package/dist/mcp/graph-summary.d.ts.map +1 -0
  109. package/dist/mcp/room-audit.d.ts +14 -0
  110. package/dist/mcp/room-audit.d.ts.map +1 -0
  111. package/dist/mcp/room-helpers.d.ts +43 -0
  112. package/dist/mcp/room-helpers.d.ts.map +1 -0
  113. package/dist/mcp/room-registry.d.ts +32 -0
  114. package/dist/mcp/room-registry.d.ts.map +1 -0
  115. package/dist/mcp/room.d.ts +28 -0
  116. package/dist/mcp/room.d.ts.map +1 -0
  117. package/dist/plugins/agent-memory/index.js +1 -1
  118. package/dist/plugins/idea-garden/index.js +1 -1
  119. package/dist/plugins/plan-approval/index.js +1 -1
  120. package/dist/plugins/proactive-watcher/index.js +1 -1
  121. package/dist/protocol/envelope.d.ts +30 -0
  122. package/dist/protocol/envelope.d.ts.map +1 -0
  123. package/dist/protocol/index.d.ts +3 -0
  124. package/dist/protocol/index.d.ts.map +1 -0
  125. package/dist/protocol/whereami.d.ts +33 -0
  126. package/dist/protocol/whereami.d.ts.map +1 -0
  127. package/dist/query-KHDDIR5G.js +31 -0
  128. package/dist/react/index.js +3 -3
  129. package/dist/react/realtime.js +1 -1
  130. package/dist/react/schema-hooks.js +6 -6
  131. package/dist/realtime/index.js +3 -3
  132. package/dist/realtime/relay-server.d.ts.map +1 -1
  133. package/dist/realtime/room.d.ts.map +1 -1
  134. package/dist/realtime.bundle.js +2 -0
  135. package/dist/relay-server-BT6DCJ7F.js +12 -0
  136. package/dist/relay-server-MPQVGNQU.js +12 -0
  137. package/dist/relay-server-PAPW2EWC.js +12 -0
  138. package/dist/remote-manager-6ERQUBSL.js +224 -0
  139. package/dist/remote-manager-G665WWYY.js +224 -0
  140. package/dist/remote-manager-HJTEZ4OF.js +224 -0
  141. package/dist/remote-manager-NYP2Y5UR.js +224 -0
  142. package/dist/remote-manager-WGLCAMMC.js +224 -0
  143. package/dist/scaffold/write.d.ts.map +1 -1
  144. package/dist/schema/index.js +1 -1
  145. package/dist/server/cors.d.ts +13 -0
  146. package/dist/server/cors.d.ts.map +1 -0
  147. package/dist/server/deploy-gateway.d.ts +27 -0
  148. package/dist/server/deploy-gateway.d.ts.map +1 -0
  149. package/dist/server/deploy.d.ts +1 -1
  150. package/dist/server/deploy.d.ts.map +1 -1
  151. package/dist/server/deploy.js +10 -0
  152. package/dist/server/discovery-mcp-gateway.d.ts +13 -0
  153. package/dist/server/discovery-mcp-gateway.d.ts.map +1 -0
  154. package/dist/server/index.js +44 -37
  155. package/dist/server/mcp-gateway.d.ts +27 -0
  156. package/dist/server/mcp-gateway.d.ts.map +1 -0
  157. package/dist/server/mcp-oauth-metadata.d.ts +31 -0
  158. package/dist/server/mcp-oauth-metadata.d.ts.map +1 -0
  159. package/dist/server/node-adapter.d.ts +7 -0
  160. package/dist/server/node-adapter.d.ts.map +1 -1
  161. package/dist/server/node-adapter.js +2 -2
  162. package/dist/server/realtime.d.ts.map +1 -1
  163. package/dist/server/server.d.ts +8 -0
  164. package/dist/server/server.d.ts.map +1 -1
  165. package/dist/server/streamable-mcp-gateway.d.ts +12 -0
  166. package/dist/server/streamable-mcp-gateway.d.ts.map +1 -0
  167. package/dist/server/usage-meter.d.ts +11 -0
  168. package/dist/server/usage-meter.d.ts.map +1 -1
  169. package/dist/server-4VEZHXXS.js +23 -0
  170. package/dist/{server-ZVWGLLRF.js → server-556BMK4C.js} +1 -1
  171. package/dist/server-FQT2VYRE.js +23 -0
  172. package/dist/server-HGZE4ECC.js +23 -0
  173. package/dist/server-J4JKEAMH.js +23 -0
  174. package/dist/server-LXPM5TFR.js +23 -0
  175. package/dist/{server-MB3OPSPI.js → server-POB4NEUX.js} +2 -2
  176. package/dist/server-VJKAPGPG.js +23 -0
  177. package/dist/server-YHS3XIIG.js +23 -0
  178. package/dist/server-ZHTPWPXS.js +23 -0
  179. package/dist/sprites-NC6D7YZS.js +27 -0
  180. package/dist/svelte/index.js +3 -3
  181. package/dist/svelte/schema-hooks.js +4 -4
  182. package/dist/sync/index.js +4 -4
  183. package/dist/tenancy-2SZTP4UD.js +16 -0
  184. package/dist/tenancy-7MTSESMJ.js +16 -0
  185. package/dist/tenancy-U4E7ZEAG.js +16 -0
  186. package/dist/vcs/decompose.d.ts.map +1 -1
  187. package/dist/vcs/index.js +5 -5
  188. package/dist/vcs/lane-disk-materialize.d.ts +11 -0
  189. package/dist/vcs/lane-disk-materialize.d.ts.map +1 -0
  190. package/dist/vcs/lane-worktree.d.ts +21 -0
  191. package/dist/vcs/lane-worktree.d.ts.map +1 -0
  192. package/dist/vcs/store.d.ts +28 -0
  193. package/dist/vcs/store.d.ts.map +1 -0
  194. package/dist/vcs/types.d.ts +5 -0
  195. package/dist/vcs/types.d.ts.map +1 -1
  196. package/dist/vm-config-YZRJ3KUB.js +21 -0
  197. package/dist/vue/index.js +3 -3
  198. package/dist/vue/schema-hooks.js +4 -4
  199. package/package.json +4 -3
  200. package/dist/chunk-FF36CQHZ.js +0 -61
  201. package/dist/chunk-GFZCJ4EH.js +0 -108
  202. package/dist/chunk-KIJITUZB.js +0 -419
  203. package/dist/chunk-SGMDTWJJ.js +0 -149
  204. package/dist/chunk-UQISRW6T.js +0 -203
  205. package/dist/db/trellis.css +0 -1
  206. package/dist/deploy-LQ7GUGJ5.js +0 -9
  207. package/dist/deploy-YNVG5E4E.js +0 -9
  208. package/dist/deploy-cli-24BCHAXY.js +0 -67
  209. package/dist/sprites-RU3E4XQN.js +0 -15
  210. package/dist/tenancy-NBLLGCNJ.js +0 -14
@@ -0,0 +1,224 @@
1
+ import {
2
+ TrellisVcsEngine,
3
+ init_engine
4
+ } from "./chunk-2WW2X2BR.js";
5
+ import "./chunk-NLFRRGX6.js";
6
+ import "./chunk-G3XIHPSQ.js";
7
+ import "./chunk-YKVB4LUQ.js";
8
+ import "./chunk-547FZFKO.js";
9
+ import "./chunk-GRWQPKYK.js";
10
+ import "./chunk-2ESYSVXG.js";
11
+
12
+ // src/federation/remote-manager.ts
13
+ init_engine();
14
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
15
+ import { join, resolve } from "path";
16
+ var RemoteManager = class {
17
+ trellisPath;
18
+ remotesPath;
19
+ constructor(trellisPath) {
20
+ this.trellisPath = trellisPath;
21
+ this.remotesPath = join(trellisPath, "remotes.json");
22
+ }
23
+ /** Load remotes configuration */
24
+ loadRemotes() {
25
+ if (!existsSync(this.remotesPath)) {
26
+ return { remotes: {} };
27
+ }
28
+ try {
29
+ const content = readFileSync(this.remotesPath, "utf8");
30
+ return JSON.parse(content);
31
+ } catch (error) {
32
+ throw new Error(`Failed to load remotes config: ${error}`);
33
+ }
34
+ }
35
+ /** Save remotes configuration */
36
+ saveRemotes(config) {
37
+ try {
38
+ if (!existsSync(this.trellisPath)) {
39
+ mkdirSync(this.trellisPath, { recursive: true });
40
+ }
41
+ writeFileSync(this.remotesPath, JSON.stringify(config, null, 2), "utf8");
42
+ } catch (error) {
43
+ throw new Error(`Failed to save remotes config: ${error}`);
44
+ }
45
+ }
46
+ /** Add a new remote */
47
+ addRemote(name, path) {
48
+ const config = this.loadRemotes();
49
+ if (config.remotes[name]) {
50
+ throw new Error(`Remote '${name}' already exists`);
51
+ }
52
+ const resolvedPath = resolve(path);
53
+ if (!TrellisVcsEngine.isRepo(resolvedPath)) {
54
+ throw new Error(`Not a TrellisVCS repository: ${resolvedPath}`);
55
+ }
56
+ config.remotes[name] = {
57
+ name,
58
+ path: resolvedPath
59
+ };
60
+ this.saveRemotes(config);
61
+ }
62
+ /** Remove a remote */
63
+ removeRemote(name) {
64
+ const config = this.loadRemotes();
65
+ if (!config.remotes[name]) {
66
+ throw new Error(`Remote '${name}' not found`);
67
+ }
68
+ delete config.remotes[name];
69
+ this.saveRemotes(config);
70
+ }
71
+ /** List all remotes */
72
+ listRemotes() {
73
+ const config = this.loadRemotes();
74
+ return Object.values(config.remotes);
75
+ }
76
+ /** Pull new ops from a specific remote */
77
+ async pullRemote(remoteName, localEngine) {
78
+ const startTime = Date.now();
79
+ const config = this.loadRemotes();
80
+ const remote = config.remotes[remoteName];
81
+ if (!remote) {
82
+ throw new Error(`Remote '${remoteName}' not found`);
83
+ }
84
+ const errors = [];
85
+ let newOps = 0;
86
+ let latestOpId = remote.lastOpId || "";
87
+ try {
88
+ const remoteEngine = new TrellisVcsEngine({ rootPath: remote.path });
89
+ remoteEngine.open();
90
+ const remoteOps = remoteEngine.getOps();
91
+ if (remoteOps.length === 0) {
92
+ return {
93
+ remote: remoteName,
94
+ newOps: 0,
95
+ latestOpId: "",
96
+ durationMs: Date.now() - startTime,
97
+ errors: []
98
+ };
99
+ }
100
+ const lastOpHash = remote.lastOpId;
101
+ let startIndex = 0;
102
+ if (lastOpHash) {
103
+ startIndex = remoteOps.findIndex((op) => op.hash === lastOpHash);
104
+ if (startIndex === -1) {
105
+ startIndex = 0;
106
+ errors.push(
107
+ `Last op hash ${lastOpHash} not found in remote, pulling all ops`
108
+ );
109
+ } else {
110
+ startIndex++;
111
+ }
112
+ }
113
+ const opsToPull = remoteOps.slice(startIndex);
114
+ if (opsToPull.length > 0) {
115
+ const prefixedOps = opsToPull.map(
116
+ (op) => this.prefixOpEntities(op, remoteName)
117
+ );
118
+ for (const op of prefixedOps) {
119
+ localEngine.opLog.append(op);
120
+ newOps++;
121
+ }
122
+ latestOpId = remoteOps[remoteOps.length - 1].hash;
123
+ }
124
+ remote.lastOpId = latestOpId;
125
+ remote.pulledAt = (/* @__PURE__ */ new Date()).toISOString();
126
+ this.saveRemotes(config);
127
+ } catch (error) {
128
+ errors.push(`Failed to pull from remote: ${error}`);
129
+ }
130
+ return {
131
+ remote: remoteName,
132
+ newOps,
133
+ latestOpId,
134
+ durationMs: Date.now() - startTime,
135
+ errors
136
+ };
137
+ }
138
+ /** Pull from all configured remotes */
139
+ async pullAll(localEngine) {
140
+ const config = this.loadRemotes();
141
+ const remoteNames = Object.keys(config.remotes);
142
+ if (remoteNames.length === 0) {
143
+ return {
144
+ results: [],
145
+ totalNewOps: 0,
146
+ totalDurationMs: 0
147
+ };
148
+ }
149
+ const startTime = Date.now();
150
+ const results = [];
151
+ let totalNewOps = 0;
152
+ for (const remoteName of remoteNames) {
153
+ try {
154
+ const result = await this.pullRemote(remoteName, localEngine);
155
+ results.push(result);
156
+ totalNewOps += result.newOps;
157
+ } catch (error) {
158
+ results.push({
159
+ remote: remoteName,
160
+ newOps: 0,
161
+ latestOpId: "",
162
+ durationMs: 0,
163
+ errors: [`Failed to pull: ${error}`]
164
+ });
165
+ }
166
+ }
167
+ return {
168
+ results,
169
+ totalNewOps,
170
+ totalDurationMs: Date.now() - startTime
171
+ };
172
+ }
173
+ /** Prefix entity IDs in operations with remote name */
174
+ prefixOpEntities(op, remoteName) {
175
+ const prefixed = { ...op };
176
+ if (op.vcs) {
177
+ const vcs = { ...op.vcs };
178
+ if (vcs.issueId && !vcs.issueId.includes(":")) {
179
+ vcs.issueId = `${remoteName}:${vcs.issueId}`;
180
+ }
181
+ if (vcs.parentIssueId && !vcs.parentIssueId.includes(":")) {
182
+ vcs.parentIssueId = `${remoteName}:${vcs.parentIssueId}`;
183
+ }
184
+ if (vcs.blockedByIssueId && !vcs.blockedByIssueId.includes(":")) {
185
+ vcs.blockedByIssueId = `${remoteName}:${vcs.blockedByIssueId}`;
186
+ }
187
+ if (vcs.decisionId && !vcs.decisionId.includes(":")) {
188
+ vcs.decisionId = `${remoteName}:${vcs.decisionId}`;
189
+ }
190
+ prefixed.vcs = vcs;
191
+ }
192
+ if (op.facts) {
193
+ prefixed.facts = op.facts.map((fact) => {
194
+ if (fact.e === "entity" && fact.a === "id" && typeof fact.v === "string" && !fact.v.includes(":")) {
195
+ return { ...fact, v: `${remoteName}:${fact.v}` };
196
+ }
197
+ if (fact.e === "entity" && fact.a === "from" && typeof fact.v === "string" && !fact.v.includes(":")) {
198
+ return { ...fact, v: `${remoteName}:${fact.v}` };
199
+ }
200
+ if (fact.e === "entity" && fact.a === "to" && typeof fact.v === "string" && !fact.v.includes(":")) {
201
+ return { ...fact, v: `${remoteName}:${fact.v}` };
202
+ }
203
+ return fact;
204
+ });
205
+ }
206
+ if (op.links) {
207
+ prefixed.links = op.links.map((link) => ({
208
+ ...link,
209
+ e1: link.e1.includes(":") ? link.e1 : `${remoteName}:${link.e1}`,
210
+ e2: link.e2.includes(":") ? link.e2 : `${remoteName}:${link.e2}`
211
+ }));
212
+ }
213
+ if (!prefixed.facts) prefixed.facts = [];
214
+ prefixed.facts.push({
215
+ e: "op",
216
+ a: "remote",
217
+ v: remoteName
218
+ });
219
+ return prefixed;
220
+ }
221
+ };
222
+ export {
223
+ RemoteManager
224
+ };
@@ -0,0 +1,224 @@
1
+ import {
2
+ TrellisVcsEngine,
3
+ init_engine
4
+ } from "./chunk-MF2SLV3P.js";
5
+ import "./chunk-NLFRRGX6.js";
6
+ import "./chunk-G3XIHPSQ.js";
7
+ import "./chunk-YKVB4LUQ.js";
8
+ import "./chunk-547FZFKO.js";
9
+ import "./chunk-GRWQPKYK.js";
10
+ import "./chunk-2ESYSVXG.js";
11
+
12
+ // src/federation/remote-manager.ts
13
+ init_engine();
14
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
15
+ import { join, resolve } from "path";
16
+ var RemoteManager = class {
17
+ trellisPath;
18
+ remotesPath;
19
+ constructor(trellisPath) {
20
+ this.trellisPath = trellisPath;
21
+ this.remotesPath = join(trellisPath, "remotes.json");
22
+ }
23
+ /** Load remotes configuration */
24
+ loadRemotes() {
25
+ if (!existsSync(this.remotesPath)) {
26
+ return { remotes: {} };
27
+ }
28
+ try {
29
+ const content = readFileSync(this.remotesPath, "utf8");
30
+ return JSON.parse(content);
31
+ } catch (error) {
32
+ throw new Error(`Failed to load remotes config: ${error}`);
33
+ }
34
+ }
35
+ /** Save remotes configuration */
36
+ saveRemotes(config) {
37
+ try {
38
+ if (!existsSync(this.trellisPath)) {
39
+ mkdirSync(this.trellisPath, { recursive: true });
40
+ }
41
+ writeFileSync(this.remotesPath, JSON.stringify(config, null, 2), "utf8");
42
+ } catch (error) {
43
+ throw new Error(`Failed to save remotes config: ${error}`);
44
+ }
45
+ }
46
+ /** Add a new remote */
47
+ addRemote(name, path) {
48
+ const config = this.loadRemotes();
49
+ if (config.remotes[name]) {
50
+ throw new Error(`Remote '${name}' already exists`);
51
+ }
52
+ const resolvedPath = resolve(path);
53
+ if (!TrellisVcsEngine.isRepo(resolvedPath)) {
54
+ throw new Error(`Not a TrellisVCS repository: ${resolvedPath}`);
55
+ }
56
+ config.remotes[name] = {
57
+ name,
58
+ path: resolvedPath
59
+ };
60
+ this.saveRemotes(config);
61
+ }
62
+ /** Remove a remote */
63
+ removeRemote(name) {
64
+ const config = this.loadRemotes();
65
+ if (!config.remotes[name]) {
66
+ throw new Error(`Remote '${name}' not found`);
67
+ }
68
+ delete config.remotes[name];
69
+ this.saveRemotes(config);
70
+ }
71
+ /** List all remotes */
72
+ listRemotes() {
73
+ const config = this.loadRemotes();
74
+ return Object.values(config.remotes);
75
+ }
76
+ /** Pull new ops from a specific remote */
77
+ async pullRemote(remoteName, localEngine) {
78
+ const startTime = Date.now();
79
+ const config = this.loadRemotes();
80
+ const remote = config.remotes[remoteName];
81
+ if (!remote) {
82
+ throw new Error(`Remote '${remoteName}' not found`);
83
+ }
84
+ const errors = [];
85
+ let newOps = 0;
86
+ let latestOpId = remote.lastOpId || "";
87
+ try {
88
+ const remoteEngine = new TrellisVcsEngine({ rootPath: remote.path });
89
+ remoteEngine.open();
90
+ const remoteOps = remoteEngine.getOps();
91
+ if (remoteOps.length === 0) {
92
+ return {
93
+ remote: remoteName,
94
+ newOps: 0,
95
+ latestOpId: "",
96
+ durationMs: Date.now() - startTime,
97
+ errors: []
98
+ };
99
+ }
100
+ const lastOpHash = remote.lastOpId;
101
+ let startIndex = 0;
102
+ if (lastOpHash) {
103
+ startIndex = remoteOps.findIndex((op) => op.hash === lastOpHash);
104
+ if (startIndex === -1) {
105
+ startIndex = 0;
106
+ errors.push(
107
+ `Last op hash ${lastOpHash} not found in remote, pulling all ops`
108
+ );
109
+ } else {
110
+ startIndex++;
111
+ }
112
+ }
113
+ const opsToPull = remoteOps.slice(startIndex);
114
+ if (opsToPull.length > 0) {
115
+ const prefixedOps = opsToPull.map(
116
+ (op) => this.prefixOpEntities(op, remoteName)
117
+ );
118
+ for (const op of prefixedOps) {
119
+ localEngine.opLog.append(op);
120
+ newOps++;
121
+ }
122
+ latestOpId = remoteOps[remoteOps.length - 1].hash;
123
+ }
124
+ remote.lastOpId = latestOpId;
125
+ remote.pulledAt = (/* @__PURE__ */ new Date()).toISOString();
126
+ this.saveRemotes(config);
127
+ } catch (error) {
128
+ errors.push(`Failed to pull from remote: ${error}`);
129
+ }
130
+ return {
131
+ remote: remoteName,
132
+ newOps,
133
+ latestOpId,
134
+ durationMs: Date.now() - startTime,
135
+ errors
136
+ };
137
+ }
138
+ /** Pull from all configured remotes */
139
+ async pullAll(localEngine) {
140
+ const config = this.loadRemotes();
141
+ const remoteNames = Object.keys(config.remotes);
142
+ if (remoteNames.length === 0) {
143
+ return {
144
+ results: [],
145
+ totalNewOps: 0,
146
+ totalDurationMs: 0
147
+ };
148
+ }
149
+ const startTime = Date.now();
150
+ const results = [];
151
+ let totalNewOps = 0;
152
+ for (const remoteName of remoteNames) {
153
+ try {
154
+ const result = await this.pullRemote(remoteName, localEngine);
155
+ results.push(result);
156
+ totalNewOps += result.newOps;
157
+ } catch (error) {
158
+ results.push({
159
+ remote: remoteName,
160
+ newOps: 0,
161
+ latestOpId: "",
162
+ durationMs: 0,
163
+ errors: [`Failed to pull: ${error}`]
164
+ });
165
+ }
166
+ }
167
+ return {
168
+ results,
169
+ totalNewOps,
170
+ totalDurationMs: Date.now() - startTime
171
+ };
172
+ }
173
+ /** Prefix entity IDs in operations with remote name */
174
+ prefixOpEntities(op, remoteName) {
175
+ const prefixed = { ...op };
176
+ if (op.vcs) {
177
+ const vcs = { ...op.vcs };
178
+ if (vcs.issueId && !vcs.issueId.includes(":")) {
179
+ vcs.issueId = `${remoteName}:${vcs.issueId}`;
180
+ }
181
+ if (vcs.parentIssueId && !vcs.parentIssueId.includes(":")) {
182
+ vcs.parentIssueId = `${remoteName}:${vcs.parentIssueId}`;
183
+ }
184
+ if (vcs.blockedByIssueId && !vcs.blockedByIssueId.includes(":")) {
185
+ vcs.blockedByIssueId = `${remoteName}:${vcs.blockedByIssueId}`;
186
+ }
187
+ if (vcs.decisionId && !vcs.decisionId.includes(":")) {
188
+ vcs.decisionId = `${remoteName}:${vcs.decisionId}`;
189
+ }
190
+ prefixed.vcs = vcs;
191
+ }
192
+ if (op.facts) {
193
+ prefixed.facts = op.facts.map((fact) => {
194
+ if (fact.e === "entity" && fact.a === "id" && typeof fact.v === "string" && !fact.v.includes(":")) {
195
+ return { ...fact, v: `${remoteName}:${fact.v}` };
196
+ }
197
+ if (fact.e === "entity" && fact.a === "from" && typeof fact.v === "string" && !fact.v.includes(":")) {
198
+ return { ...fact, v: `${remoteName}:${fact.v}` };
199
+ }
200
+ if (fact.e === "entity" && fact.a === "to" && typeof fact.v === "string" && !fact.v.includes(":")) {
201
+ return { ...fact, v: `${remoteName}:${fact.v}` };
202
+ }
203
+ return fact;
204
+ });
205
+ }
206
+ if (op.links) {
207
+ prefixed.links = op.links.map((link) => ({
208
+ ...link,
209
+ e1: link.e1.includes(":") ? link.e1 : `${remoteName}:${link.e1}`,
210
+ e2: link.e2.includes(":") ? link.e2 : `${remoteName}:${link.e2}`
211
+ }));
212
+ }
213
+ if (!prefixed.facts) prefixed.facts = [];
214
+ prefixed.facts.push({
215
+ e: "op",
216
+ a: "remote",
217
+ v: remoteName
218
+ });
219
+ return prefixed;
220
+ }
221
+ };
222
+ export {
223
+ RemoteManager
224
+ };
@@ -0,0 +1,224 @@
1
+ import {
2
+ TrellisVcsEngine,
3
+ init_engine
4
+ } from "./chunk-2STT4AEC.js";
5
+ import "./chunk-NLFRRGX6.js";
6
+ import "./chunk-G3XIHPSQ.js";
7
+ import "./chunk-YKVB4LUQ.js";
8
+ import "./chunk-547FZFKO.js";
9
+ import "./chunk-GRWQPKYK.js";
10
+ import "./chunk-2ESYSVXG.js";
11
+
12
+ // src/federation/remote-manager.ts
13
+ init_engine();
14
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
15
+ import { join, resolve } from "path";
16
+ var RemoteManager = class {
17
+ trellisPath;
18
+ remotesPath;
19
+ constructor(trellisPath) {
20
+ this.trellisPath = trellisPath;
21
+ this.remotesPath = join(trellisPath, "remotes.json");
22
+ }
23
+ /** Load remotes configuration */
24
+ loadRemotes() {
25
+ if (!existsSync(this.remotesPath)) {
26
+ return { remotes: {} };
27
+ }
28
+ try {
29
+ const content = readFileSync(this.remotesPath, "utf8");
30
+ return JSON.parse(content);
31
+ } catch (error) {
32
+ throw new Error(`Failed to load remotes config: ${error}`);
33
+ }
34
+ }
35
+ /** Save remotes configuration */
36
+ saveRemotes(config) {
37
+ try {
38
+ if (!existsSync(this.trellisPath)) {
39
+ mkdirSync(this.trellisPath, { recursive: true });
40
+ }
41
+ writeFileSync(this.remotesPath, JSON.stringify(config, null, 2), "utf8");
42
+ } catch (error) {
43
+ throw new Error(`Failed to save remotes config: ${error}`);
44
+ }
45
+ }
46
+ /** Add a new remote */
47
+ addRemote(name, path) {
48
+ const config = this.loadRemotes();
49
+ if (config.remotes[name]) {
50
+ throw new Error(`Remote '${name}' already exists`);
51
+ }
52
+ const resolvedPath = resolve(path);
53
+ if (!TrellisVcsEngine.isRepo(resolvedPath)) {
54
+ throw new Error(`Not a TrellisVCS repository: ${resolvedPath}`);
55
+ }
56
+ config.remotes[name] = {
57
+ name,
58
+ path: resolvedPath
59
+ };
60
+ this.saveRemotes(config);
61
+ }
62
+ /** Remove a remote */
63
+ removeRemote(name) {
64
+ const config = this.loadRemotes();
65
+ if (!config.remotes[name]) {
66
+ throw new Error(`Remote '${name}' not found`);
67
+ }
68
+ delete config.remotes[name];
69
+ this.saveRemotes(config);
70
+ }
71
+ /** List all remotes */
72
+ listRemotes() {
73
+ const config = this.loadRemotes();
74
+ return Object.values(config.remotes);
75
+ }
76
+ /** Pull new ops from a specific remote */
77
+ async pullRemote(remoteName, localEngine) {
78
+ const startTime = Date.now();
79
+ const config = this.loadRemotes();
80
+ const remote = config.remotes[remoteName];
81
+ if (!remote) {
82
+ throw new Error(`Remote '${remoteName}' not found`);
83
+ }
84
+ const errors = [];
85
+ let newOps = 0;
86
+ let latestOpId = remote.lastOpId || "";
87
+ try {
88
+ const remoteEngine = new TrellisVcsEngine({ rootPath: remote.path });
89
+ remoteEngine.open();
90
+ const remoteOps = remoteEngine.getOps();
91
+ if (remoteOps.length === 0) {
92
+ return {
93
+ remote: remoteName,
94
+ newOps: 0,
95
+ latestOpId: "",
96
+ durationMs: Date.now() - startTime,
97
+ errors: []
98
+ };
99
+ }
100
+ const lastOpHash = remote.lastOpId;
101
+ let startIndex = 0;
102
+ if (lastOpHash) {
103
+ startIndex = remoteOps.findIndex((op) => op.hash === lastOpHash);
104
+ if (startIndex === -1) {
105
+ startIndex = 0;
106
+ errors.push(
107
+ `Last op hash ${lastOpHash} not found in remote, pulling all ops`
108
+ );
109
+ } else {
110
+ startIndex++;
111
+ }
112
+ }
113
+ const opsToPull = remoteOps.slice(startIndex);
114
+ if (opsToPull.length > 0) {
115
+ const prefixedOps = opsToPull.map(
116
+ (op) => this.prefixOpEntities(op, remoteName)
117
+ );
118
+ for (const op of prefixedOps) {
119
+ localEngine.opLog.append(op);
120
+ newOps++;
121
+ }
122
+ latestOpId = remoteOps[remoteOps.length - 1].hash;
123
+ }
124
+ remote.lastOpId = latestOpId;
125
+ remote.pulledAt = (/* @__PURE__ */ new Date()).toISOString();
126
+ this.saveRemotes(config);
127
+ } catch (error) {
128
+ errors.push(`Failed to pull from remote: ${error}`);
129
+ }
130
+ return {
131
+ remote: remoteName,
132
+ newOps,
133
+ latestOpId,
134
+ durationMs: Date.now() - startTime,
135
+ errors
136
+ };
137
+ }
138
+ /** Pull from all configured remotes */
139
+ async pullAll(localEngine) {
140
+ const config = this.loadRemotes();
141
+ const remoteNames = Object.keys(config.remotes);
142
+ if (remoteNames.length === 0) {
143
+ return {
144
+ results: [],
145
+ totalNewOps: 0,
146
+ totalDurationMs: 0
147
+ };
148
+ }
149
+ const startTime = Date.now();
150
+ const results = [];
151
+ let totalNewOps = 0;
152
+ for (const remoteName of remoteNames) {
153
+ try {
154
+ const result = await this.pullRemote(remoteName, localEngine);
155
+ results.push(result);
156
+ totalNewOps += result.newOps;
157
+ } catch (error) {
158
+ results.push({
159
+ remote: remoteName,
160
+ newOps: 0,
161
+ latestOpId: "",
162
+ durationMs: 0,
163
+ errors: [`Failed to pull: ${error}`]
164
+ });
165
+ }
166
+ }
167
+ return {
168
+ results,
169
+ totalNewOps,
170
+ totalDurationMs: Date.now() - startTime
171
+ };
172
+ }
173
+ /** Prefix entity IDs in operations with remote name */
174
+ prefixOpEntities(op, remoteName) {
175
+ const prefixed = { ...op };
176
+ if (op.vcs) {
177
+ const vcs = { ...op.vcs };
178
+ if (vcs.issueId && !vcs.issueId.includes(":")) {
179
+ vcs.issueId = `${remoteName}:${vcs.issueId}`;
180
+ }
181
+ if (vcs.parentIssueId && !vcs.parentIssueId.includes(":")) {
182
+ vcs.parentIssueId = `${remoteName}:${vcs.parentIssueId}`;
183
+ }
184
+ if (vcs.blockedByIssueId && !vcs.blockedByIssueId.includes(":")) {
185
+ vcs.blockedByIssueId = `${remoteName}:${vcs.blockedByIssueId}`;
186
+ }
187
+ if (vcs.decisionId && !vcs.decisionId.includes(":")) {
188
+ vcs.decisionId = `${remoteName}:${vcs.decisionId}`;
189
+ }
190
+ prefixed.vcs = vcs;
191
+ }
192
+ if (op.facts) {
193
+ prefixed.facts = op.facts.map((fact) => {
194
+ if (fact.e === "entity" && fact.a === "id" && typeof fact.v === "string" && !fact.v.includes(":")) {
195
+ return { ...fact, v: `${remoteName}:${fact.v}` };
196
+ }
197
+ if (fact.e === "entity" && fact.a === "from" && typeof fact.v === "string" && !fact.v.includes(":")) {
198
+ return { ...fact, v: `${remoteName}:${fact.v}` };
199
+ }
200
+ if (fact.e === "entity" && fact.a === "to" && typeof fact.v === "string" && !fact.v.includes(":")) {
201
+ return { ...fact, v: `${remoteName}:${fact.v}` };
202
+ }
203
+ return fact;
204
+ });
205
+ }
206
+ if (op.links) {
207
+ prefixed.links = op.links.map((link) => ({
208
+ ...link,
209
+ e1: link.e1.includes(":") ? link.e1 : `${remoteName}:${link.e1}`,
210
+ e2: link.e2.includes(":") ? link.e2 : `${remoteName}:${link.e2}`
211
+ }));
212
+ }
213
+ if (!prefixed.facts) prefixed.facts = [];
214
+ prefixed.facts.push({
215
+ e: "op",
216
+ a: "remote",
217
+ v: remoteName
218
+ });
219
+ return prefixed;
220
+ }
221
+ };
222
+ export {
223
+ RemoteManager
224
+ };