farseer-cli 1.0.9 → 1.0.10

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 (81) hide show
  1. package/dist/commands/app.js +344 -316
  2. package/dist/commands/apps.js +83 -103
  3. package/dist/commands/checkout.js +156 -134
  4. package/dist/commands/config.js +126 -124
  5. package/dist/commands/diff.js +194 -169
  6. package/dist/commands/dimensions.js +122 -137
  7. package/dist/commands/files.js +77 -88
  8. package/dist/commands/install.js +77 -74
  9. package/dist/commands/list.js +74 -89
  10. package/dist/commands/login.js +101 -126
  11. package/dist/commands/logout.js +42 -57
  12. package/dist/commands/mcp-server.js +24 -39
  13. package/dist/commands/model.js +176 -184
  14. package/dist/commands/pull.js +276 -248
  15. package/dist/commands/push.js +222 -200
  16. package/dist/commands/run.js +322 -274
  17. package/dist/commands/status.js +170 -147
  18. package/dist/commands/variables.js +192 -168
  19. package/dist/commands/whoami.js +45 -61
  20. package/dist/index.js +115 -117
  21. package/dist/mcp/index.js +17 -33
  22. package/dist/mcp/prompts/workflows.js +146 -191
  23. package/dist/mcp/resources/documentation.js +149 -158
  24. package/dist/mcp/server.js +34 -50
  25. package/dist/mcp/tools/appTools.js +278 -307
  26. package/dist/mcp/tools/authTools.js +123 -130
  27. package/dist/mcp/tools/dataTools.js +271 -275
  28. package/dist/mcp/tools/modelTools.js +233 -265
  29. package/dist/mcp/tools/runTools.js +205 -199
  30. package/dist/mcp/tools/syncTools.js +315 -341
  31. package/dist/mcp/utils/helpers.js +124 -117
  32. package/dist/services/appSyncService.js +438 -379
  33. package/dist/services/configService.js +144 -154
  34. package/dist/services/farseerApi.js +401 -401
  35. package/dist/services/farseerFactory.js +274 -208
  36. package/dist/services/farseerService.js +488 -455
  37. package/dist/services/syncService.js +732 -657
  38. package/dist/utils/constants.js +20 -45
  39. package/dist/utils/helpers.js +366 -333
  40. package/dist/utils/logger.js +43 -74
  41. package/package.json +8 -1
  42. package/dist/commands/app.js.map +0 -7
  43. package/dist/commands/apps.js.map +0 -7
  44. package/dist/commands/checkout.js.map +0 -7
  45. package/dist/commands/config.js.map +0 -7
  46. package/dist/commands/diff.js.map +0 -7
  47. package/dist/commands/dimensions.js.map +0 -7
  48. package/dist/commands/files.js.map +0 -7
  49. package/dist/commands/install.js.map +0 -7
  50. package/dist/commands/list.js.map +0 -7
  51. package/dist/commands/login.js.map +0 -7
  52. package/dist/commands/logout.js.map +0 -7
  53. package/dist/commands/mcp-server.js.map +0 -7
  54. package/dist/commands/model.js.map +0 -7
  55. package/dist/commands/pull.js.map +0 -7
  56. package/dist/commands/push.js.map +0 -7
  57. package/dist/commands/run.js.map +0 -7
  58. package/dist/commands/status.js.map +0 -7
  59. package/dist/commands/variables.js.map +0 -7
  60. package/dist/commands/whoami.js.map +0 -7
  61. package/dist/index.js.map +0 -7
  62. package/dist/mcp/index.js.map +0 -7
  63. package/dist/mcp/prompts/workflows.js.map +0 -7
  64. package/dist/mcp/resources/documentation.js.map +0 -7
  65. package/dist/mcp/server.js.map +0 -7
  66. package/dist/mcp/tools/appTools.js.map +0 -7
  67. package/dist/mcp/tools/authTools.js.map +0 -7
  68. package/dist/mcp/tools/dataTools.js.map +0 -7
  69. package/dist/mcp/tools/modelTools.js.map +0 -7
  70. package/dist/mcp/tools/runTools.js.map +0 -7
  71. package/dist/mcp/tools/syncTools.js.map +0 -7
  72. package/dist/mcp/utils/helpers.js.map +0 -7
  73. package/dist/services/appSyncService.js.map +0 -7
  74. package/dist/services/configService.js.map +0 -7
  75. package/dist/services/farseerApi.js.map +0 -7
  76. package/dist/services/farseerFactory.js.map +0 -7
  77. package/dist/services/farseerService.js.map +0 -7
  78. package/dist/services/syncService.js.map +0 -7
  79. package/dist/utils/constants.js.map +0 -7
  80. package/dist/utils/helpers.js.map +0 -7
  81. package/dist/utils/logger.js.map +0 -7
@@ -1,62 +1,57 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var syncTools_exports = {};
19
- __export(syncTools_exports, {
20
- registerSyncTools: () => registerSyncTools
21
- });
22
- module.exports = __toCommonJS(syncTools_exports);
23
- var import_zod = require("zod");
24
- var import_diff = require("diff");
25
- var import_syncService = require("../../services/syncService");
26
- var import_appSyncService = require("../../services/appSyncService");
27
- var import_farseerFactory = require("../../services/farseerFactory");
28
- var import_helpers = require("../utils/helpers");
1
+ "use strict";
2
+ /**
3
+ * File Synchronization Tools
4
+ *
5
+ * Tools for syncing files between local repository and Farseer instance.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.registerSyncTools = registerSyncTools;
9
+ const zod_1 = require("zod");
10
+ const diff_1 = require("diff");
11
+ const syncService_1 = require("../../services/syncService");
12
+ const appSyncService_1 = require("../../services/appSyncService");
13
+ const farseerFactory_1 = require("../../services/farseerFactory");
14
+ const helpers_1 = require("../utils/helpers");
15
+ // Define schemas outside of tool registration to avoid deep type instantiation
29
16
  const pullSchema = {
30
- organisation: import_zod.z.string().optional().describe('Farseer organisation (subdomain, e.g. "salvus-2"). If omitted, uses checked-out org or saved mapping.'),
31
- tenant: import_zod.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
32
- all: import_zod.z.boolean().optional().describe("Download all files, not just scripts (.ts, .js)"),
33
- force: import_zod.z.boolean().optional().describe("Force pull, overwriting local changes on conflicts")
17
+ organisation: zod_1.z
18
+ .string()
19
+ .optional()
20
+ .describe('Farseer organisation (subdomain, e.g. "salvus-2"). If omitted, uses checked-out org or saved mapping.'),
21
+ tenant: zod_1.z.string().optional().describe('Tenant ID (e.g. "salvus-prodaja"). Uses checked-out tenant if omitted.'),
22
+ all: zod_1.z.boolean().optional().describe('Download all files, not just scripts (.ts, .js)'),
23
+ force: zod_1.z.boolean().optional().describe('Force pull, overwriting local changes on conflicts'),
34
24
  };
35
25
  const pushSchema = {
36
- organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
37
- tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
38
- force: import_zod.z.boolean().optional().describe("Skip remote changes check (may overwrite remote changes)")
26
+ organisation: zod_1.z
27
+ .string()
28
+ .optional()
29
+ .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
30
+ tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
31
+ force: zod_1.z.boolean().optional().describe('Skip remote changes check (may overwrite remote changes)'),
39
32
  };
40
33
  const statusSchema = {
41
- organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping."),
42
- tenant: import_zod.z.string().optional().describe("Tenant ID. Uses checked-out tenant if omitted."),
43
- all: import_zod.z.boolean().optional().describe("Show all files, not just scripts")
34
+ organisation: zod_1.z
35
+ .string()
36
+ .optional()
37
+ .describe('Farseer organisation (subdomain). If omitted, uses checked-out org or saved mapping.'),
38
+ tenant: zod_1.z.string().optional().describe('Tenant ID. Uses checked-out tenant if omitted.'),
39
+ all: zod_1.z.boolean().optional().describe('Show all files, not just scripts'),
44
40
  };
45
41
  const diffSchema = {
46
- organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain)."),
47
- tenant: import_zod.z.string().optional().describe("Tenant ID"),
48
- file: import_zod.z.string().optional().describe("Specific file path to diff. If omitted, shows all differences."),
49
- showRemote: import_zod.z.boolean().optional().describe("Show only the remote content instead of diff")
42
+ organisation: zod_1.z.string().optional().describe('Farseer organisation (subdomain).'),
43
+ tenant: zod_1.z.string().optional().describe('Tenant ID'),
44
+ file: zod_1.z.string().optional().describe('Specific file path to diff. If omitted, shows all differences.'),
45
+ showRemote: zod_1.z.boolean().optional().describe('Show only the remote content instead of diff'),
50
46
  };
51
47
  const listFilesSchema = {
52
- organisation: import_zod.z.string().optional().describe("Farseer organisation (subdomain)."),
53
- tenant: import_zod.z.string().optional().describe("Tenant ID"),
54
- all: import_zod.z.boolean().optional().describe("Show all files, not just scripts")
48
+ organisation: zod_1.z.string().optional().describe('Farseer organisation (subdomain).'),
49
+ tenant: zod_1.z.string().optional().describe('Tenant ID'),
50
+ all: zod_1.z.boolean().optional().describe('Show all files, not just scripts'),
55
51
  };
56
52
  function registerSyncTools(server) {
57
- server.tool(
58
- "farseer_pull",
59
- `Pull (download) files and app configurations from a Farseer instance to the local repository.
53
+ // farseer_pull - Download files from remote
54
+ server.tool('farseer_pull', `Pull (download) files and app configurations from a Farseer instance to the local repository.
60
55
 
61
56
  What gets pulled:
62
57
  - TypeScript/JavaScript scripts from Files/ folder (searched recursively)
@@ -72,66 +67,65 @@ Organisation and tenant:
72
67
  - Organisation = subdomain (e.g. "salvus-2" for salvus-2.farseer.io)
73
68
  - Tenant = workspace ID (e.g. "salvus-prodaja")
74
69
  - Often they are the same. Only specify organisation when it differs from tenant.
75
- - If checked out, both are resolved automatically.`,
76
- pullSchema,
77
- async (params) => {
78
- const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
79
- if (!resolved) {
80
- return (0, import_helpers.tenantRequiredResponse)();
81
- }
82
- const { organisation, tenant } = resolved;
83
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
84
- if (!clientResult) {
85
- return (0, import_helpers.authRequiredResponse)(tenant);
86
- }
87
- try {
88
- const syncService = new import_syncService.SyncService(tenant, clientResult.client);
89
- const fileResult = await syncService.pull({ all: params.all, force: params.force });
90
- let appResult = null;
91
- if (clientResult.authType === "jwt") {
92
- const appSyncService = new import_appSyncService.AppSyncService(tenant, clientResult.client);
93
- appResult = await appSyncService.pull();
70
+ - If checked out, both are resolved automatically.`, pullSchema, async (params) => {
71
+ const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
72
+ if (!resolved) {
73
+ return (0, helpers_1.tenantRequiredResponse)();
74
+ }
75
+ const { organisation, tenant } = resolved;
76
+ const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
77
+ if (!clientResult) {
78
+ return (0, helpers_1.authRequiredResponse)(tenant);
94
79
  }
95
- const response = {
96
- tenant,
97
- organisation,
98
- files: {
99
- downloaded: fileResult.downloaded,
100
- deleted: fileResult.deleted,
101
- unchanged: fileResult.unchanged.length
102
- },
103
- apps: appResult ? {
104
- created: appResult.created,
105
- updated: appResult.updated,
106
- deleted: appResult.deleted,
107
- unchanged: appResult.unchanged.length
108
- } : { note: "App sync requires browser login (JWT)" },
109
- message: `Pulled ${fileResult.downloaded.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ""}`
110
- };
111
- if (fileResult.conflicts.length > 0) {
112
- response.conflicts = fileResult.conflicts.map((c) => ({
113
- file: c.filePath,
114
- type: c.type,
115
- description: c.description
116
- }));
117
- response.message = `Pulled ${fileResult.downloaded.length} files but ${fileResult.conflicts.length} conflict(s) need resolution`;
118
- response.hint = "Use force=true to overwrite local changes, or resolve conflicts via CLI: farseer pull <tenant>";
80
+ try {
81
+ // Pull files (use tenant for folder path)
82
+ const syncService = new syncService_1.SyncService(tenant, clientResult.client);
83
+ const fileResult = await syncService.pull({ all: params.all, force: params.force });
84
+ // Pull apps (only with JWT auth)
85
+ let appResult = null;
86
+ if (clientResult.authType === 'jwt') {
87
+ const appSyncService = new appSyncService_1.AppSyncService(tenant, clientResult.client);
88
+ appResult = await appSyncService.pull();
89
+ }
90
+ const response = {
91
+ tenant,
92
+ organisation,
93
+ files: {
94
+ downloaded: fileResult.downloaded,
95
+ deleted: fileResult.deleted,
96
+ unchanged: fileResult.unchanged.length,
97
+ },
98
+ apps: appResult
99
+ ? {
100
+ created: appResult.created,
101
+ updated: appResult.updated,
102
+ deleted: appResult.deleted,
103
+ unchanged: appResult.unchanged.length,
104
+ }
105
+ : { note: 'App sync requires browser login (JWT)' },
106
+ message: `Pulled ${fileResult.downloaded.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ''}`,
107
+ };
108
+ if (fileResult.conflicts.length > 0) {
109
+ response.conflicts = fileResult.conflicts.map((c) => ({
110
+ file: c.filePath,
111
+ type: c.type,
112
+ description: c.description,
113
+ }));
114
+ response.message = `Pulled ${fileResult.downloaded.length} files but ${fileResult.conflicts.length} conflict(s) need resolution`;
115
+ response.hint =
116
+ 'Use force=true to overwrite local changes, or resolve conflicts via CLI: farseer pull <tenant>';
117
+ }
118
+ if (fileResult.conflictFilesWritten.length > 0) {
119
+ response.conflictFilesWritten = fileResult.conflictFilesWritten;
120
+ }
121
+ return (0, helpers_1.successResponse)(response);
119
122
  }
120
- if (fileResult.conflictFilesWritten.length > 0) {
121
- response.conflictFilesWritten = fileResult.conflictFilesWritten;
123
+ catch (error) {
124
+ return (0, helpers_1.errorResponse)(`Pull failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
122
125
  }
123
- return (0, import_helpers.successResponse)(response);
124
- } catch (error) {
125
- return (0, import_helpers.errorResponse)(
126
- `Pull failed: ${error instanceof Error ? error.message : "Unknown error"}`,
127
- "NETWORK_ERROR"
128
- );
129
- }
130
- }
131
- );
132
- server.tool(
133
- "farseer_push",
134
- `Push (upload) local file and app changes to a Farseer instance.
126
+ });
127
+ // farseer_push - Upload files to remote
128
+ server.tool('farseer_push', `Push (upload) local file and app changes to a Farseer instance.
135
129
 
136
130
  What gets pushed:
137
131
  - New/modified scripts from farseer-apps/<tenant>/files/
@@ -142,71 +136,62 @@ Important:
142
136
  - Checks for unpulled remote changes first to prevent conflicts
143
137
  - Use force=true to skip this check (may overwrite remote changes)
144
138
 
145
- If no tenant is specified, uses the currently checked-out tenant.`,
146
- pushSchema,
147
- async (params) => {
148
- const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
149
- if (!resolved) {
150
- return (0, import_helpers.tenantRequiredResponse)();
151
- }
152
- const { organisation, tenant } = resolved;
153
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
154
- if (!clientResult) {
155
- return (0, import_helpers.authRequiredResponse)(tenant);
156
- }
157
- try {
158
- const syncService = new import_syncService.SyncService(tenant, clientResult.client);
159
- if (!params.force) {
160
- const hasRemoteChanges = await syncService.checkRemoteChanges();
161
- if (hasRemoteChanges) {
162
- return (0, import_helpers.errorResponse)(
163
- "Remote has unpulled changes. Pull first or use force=true to overwrite.",
164
- "VALIDATION_ERROR"
165
- );
166
- }
139
+ If no tenant is specified, uses the currently checked-out tenant.`, pushSchema, async (params) => {
140
+ const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
141
+ if (!resolved) {
142
+ return (0, helpers_1.tenantRequiredResponse)();
167
143
  }
168
- const fileResult = await syncService.push({ force: params.force });
169
- if (fileResult.conflicts.length > 0) {
170
- return (0, import_helpers.errorResponse)(
171
- `Push blocked by ${fileResult.conflicts.length} conflict(s):
172
- ${fileResult.conflicts.map((c) => ` - ${c.filePath}: ${c.description}`).join("\n")}
173
-
174
- Pull first or use force=true.`,
175
- "VALIDATION_ERROR"
176
- );
144
+ const { organisation, tenant } = resolved;
145
+ const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
146
+ if (!clientResult) {
147
+ return (0, helpers_1.authRequiredResponse)(tenant);
177
148
  }
178
- let appResult = null;
179
- if (clientResult.authType === "jwt") {
180
- const appSyncService = new import_appSyncService.AppSyncService(tenant, clientResult.client);
181
- appResult = await appSyncService.push();
149
+ try {
150
+ const syncService = new syncService_1.SyncService(tenant, clientResult.client);
151
+ // Check for remote changes unless force is true
152
+ if (!params.force) {
153
+ const hasRemoteChanges = await syncService.checkRemoteChanges();
154
+ if (hasRemoteChanges) {
155
+ return (0, helpers_1.errorResponse)('Remote has unpulled changes. Pull first or use force=true to overwrite.', 'VALIDATION_ERROR');
156
+ }
157
+ }
158
+ // Push files
159
+ const fileResult = await syncService.push({ force: params.force });
160
+ // Check for conflicts
161
+ if (fileResult.conflicts.length > 0) {
162
+ return (0, helpers_1.errorResponse)(`Push blocked by ${fileResult.conflicts.length} conflict(s):\n${fileResult.conflicts.map((c) => ` - ${c.filePath}: ${c.description}`).join('\n')}\n\nPull first or use force=true.`, 'VALIDATION_ERROR');
163
+ }
164
+ // Push apps (only with JWT auth)
165
+ let appResult = null;
166
+ if (clientResult.authType === 'jwt') {
167
+ const appSyncService = new appSyncService_1.AppSyncService(tenant, clientResult.client);
168
+ appResult = await appSyncService.push();
169
+ }
170
+ return (0, helpers_1.successResponse)({
171
+ tenant,
172
+ organisation,
173
+ files: {
174
+ uploaded: fileResult.uploaded,
175
+ updated: fileResult.updated,
176
+ deleted: fileResult.deleted,
177
+ unchanged: fileResult.unchanged.length,
178
+ },
179
+ apps: appResult
180
+ ? {
181
+ created: appResult.created,
182
+ updated: appResult.updated,
183
+ unchanged: appResult.unchanged.length,
184
+ }
185
+ : { note: 'App sync requires browser login (JWT)' },
186
+ summary: `Pushed ${fileResult.uploaded.length + fileResult.updated.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ''}`,
187
+ });
182
188
  }
183
- return (0, import_helpers.successResponse)({
184
- tenant,
185
- organisation,
186
- files: {
187
- uploaded: fileResult.uploaded,
188
- updated: fileResult.updated,
189
- deleted: fileResult.deleted,
190
- unchanged: fileResult.unchanged.length
191
- },
192
- apps: appResult ? {
193
- created: appResult.created,
194
- updated: appResult.updated,
195
- unchanged: appResult.unchanged.length
196
- } : { note: "App sync requires browser login (JWT)" },
197
- summary: `Pushed ${fileResult.uploaded.length + fileResult.updated.length} files${appResult ? ` and ${appResult.created.length + appResult.updated.length} apps` : ""}`
198
- });
199
- } catch (error) {
200
- return (0, import_helpers.errorResponse)(
201
- `Push failed: ${error instanceof Error ? error.message : "Unknown error"}`,
202
- "NETWORK_ERROR"
203
- );
204
- }
205
- }
206
- );
207
- server.tool(
208
- "farseer_status",
209
- `Check the synchronization status between local files and the remote Farseer instance.
189
+ catch (error) {
190
+ return (0, helpers_1.errorResponse)(`Push failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
191
+ }
192
+ });
193
+ // farseer_status - Check sync status
194
+ server.tool('farseer_status', `Check the synchronization status between local files and the remote Farseer instance.
210
195
 
211
196
  Shows which files are:
212
197
  - Modified locally (changed since last sync)
@@ -217,61 +202,66 @@ Shows which files are:
217
202
 
218
203
  Also shows app sync status if using JWT authentication.
219
204
 
220
- If no tenant is specified, uses the currently checked-out tenant.`,
221
- statusSchema,
222
- async (params) => {
223
- const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
224
- if (!resolved) {
225
- return (0, import_helpers.tenantRequiredResponse)();
226
- }
227
- const { organisation, tenant } = resolved;
228
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
229
- if (!clientResult) {
230
- return (0, import_helpers.authRequiredResponse)(tenant);
231
- }
232
- try {
233
- const syncService = new import_syncService.SyncService(tenant, clientResult.client);
234
- const fileStatus = await syncService.getStatus({ all: params.all });
235
- let appStatus = null;
236
- if (clientResult.authType === "jwt") {
237
- const appSyncService = new import_appSyncService.AppSyncService(tenant, clientResult.client);
238
- appStatus = await appSyncService.getStatus();
205
+ If no tenant is specified, uses the currently checked-out tenant.`, statusSchema, async (params) => {
206
+ const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
207
+ if (!resolved) {
208
+ return (0, helpers_1.tenantRequiredResponse)();
209
+ }
210
+ const { organisation, tenant } = resolved;
211
+ const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
212
+ if (!clientResult) {
213
+ return (0, helpers_1.authRequiredResponse)(tenant);
214
+ }
215
+ try {
216
+ const syncService = new syncService_1.SyncService(tenant, clientResult.client);
217
+ const fileStatus = await syncService.getStatus({ all: params.all });
218
+ // Get app status (only with JWT auth)
219
+ let appStatus = null;
220
+ if (clientResult.authType === 'jwt') {
221
+ const appSyncService = new appSyncService_1.AppSyncService(tenant, clientResult.client);
222
+ appStatus = await appSyncService.getStatus();
223
+ }
224
+ const hasChanges = fileStatus.modifiedLocally.length > 0 ||
225
+ fileStatus.modifiedRemotely.length > 0 ||
226
+ fileStatus.onlyLocal.length > 0 ||
227
+ fileStatus.onlyRemote.length > 0 ||
228
+ (fileStatus.conflicts && fileStatus.conflicts.length > 0);
229
+ return (0, helpers_1.successResponse)({
230
+ tenant,
231
+ organisation,
232
+ files: {
233
+ modifiedLocally: fileStatus.modifiedLocally,
234
+ modifiedRemotely: fileStatus.modifiedRemotely,
235
+ onlyLocal: fileStatus.onlyLocal,
236
+ onlyRemote: fileStatus.onlyRemote,
237
+ inSync: fileStatus.inSync.length,
238
+ conflicts: fileStatus.conflicts?.map((c) => ({
239
+ file: c.filePath,
240
+ type: c.type,
241
+ description: c.description,
242
+ })) ?? [],
243
+ },
244
+ apps: appStatus
245
+ ? {
246
+ newLocal: appStatus.newLocal,
247
+ newRemote: appStatus.newRemote,
248
+ modified: appStatus.modified,
249
+ synced: appStatus.synced.length,
250
+ }
251
+ : { note: 'App sync requires browser login (JWT)' },
252
+ summary: fileStatus.conflicts?.length
253
+ ? `${fileStatus.conflicts.length} conflict(s) detected`
254
+ : hasChanges
255
+ ? 'Changes detected'
256
+ : 'Everything is in sync',
257
+ });
239
258
  }
240
- const hasChanges = fileStatus.modifiedLocally.length > 0 || fileStatus.modifiedRemotely.length > 0 || fileStatus.onlyLocal.length > 0 || fileStatus.onlyRemote.length > 0 || fileStatus.conflicts && fileStatus.conflicts.length > 0;
241
- return (0, import_helpers.successResponse)({
242
- tenant,
243
- organisation,
244
- files: {
245
- modifiedLocally: fileStatus.modifiedLocally,
246
- modifiedRemotely: fileStatus.modifiedRemotely,
247
- onlyLocal: fileStatus.onlyLocal,
248
- onlyRemote: fileStatus.onlyRemote,
249
- inSync: fileStatus.inSync.length,
250
- conflicts: fileStatus.conflicts?.map((c) => ({
251
- file: c.filePath,
252
- type: c.type,
253
- description: c.description
254
- })) ?? []
255
- },
256
- apps: appStatus ? {
257
- newLocal: appStatus.newLocal,
258
- newRemote: appStatus.newRemote,
259
- modified: appStatus.modified,
260
- synced: appStatus.synced.length
261
- } : { note: "App sync requires browser login (JWT)" },
262
- summary: fileStatus.conflicts?.length ? `${fileStatus.conflicts.length} conflict(s) detected` : hasChanges ? "Changes detected" : "Everything is in sync"
263
- });
264
- } catch (error) {
265
- return (0, import_helpers.errorResponse)(
266
- `Status check failed: ${error instanceof Error ? error.message : "Unknown error"}`,
267
- "NETWORK_ERROR"
268
- );
269
- }
270
- }
271
- );
272
- server.tool(
273
- "farseer_diff",
274
- `Show the differences between local and remote versions of files.
259
+ catch (error) {
260
+ return (0, helpers_1.errorResponse)(`Status check failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
261
+ }
262
+ });
263
+ // farseer_diff - Show file differences
264
+ server.tool('farseer_diff', `Show the differences between local and remote versions of files.
275
265
 
276
266
  Can show:
277
267
  - Unified diff format (default)
@@ -279,131 +269,115 @@ Can show:
279
269
 
280
270
  Useful for reviewing changes before pull or push.
281
271
 
282
- If no file is specified, shows diffs for all changed files.`,
283
- diffSchema,
284
- async (params) => {
285
- const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
286
- if (!resolved) {
287
- return (0, import_helpers.tenantRequiredResponse)();
288
- }
289
- const { organisation, tenant } = resolved;
290
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
291
- if (!clientResult) {
292
- return (0, import_helpers.authRequiredResponse)(tenant);
293
- }
294
- try {
295
- const syncService = new import_syncService.SyncService(tenant, clientResult.client);
296
- if (params.file) {
297
- const { localContent, remoteContent } = await syncService.getFileDiff(params.file);
298
- if (params.showRemote) {
299
- return (0, import_helpers.successResponse)({
300
- file: params.file,
301
- remoteContent: remoteContent || "(file does not exist on remote)"
302
- });
303
- }
304
- const diff = (0, import_diff.createPatch)(
305
- params.file,
306
- remoteContent || "",
307
- localContent || "",
308
- "remote",
309
- "local"
310
- );
311
- return (0, import_helpers.successResponse)({
312
- file: params.file,
313
- localExists: localContent !== null,
314
- remoteExists: remoteContent !== null,
315
- diff
316
- });
317
- } else {
318
- const status = await syncService.getStatus();
319
- const changedFiles = [
320
- ...status.modifiedLocally,
321
- ...status.modifiedRemotely,
322
- ...status.onlyLocal,
323
- ...status.onlyRemote
324
- ];
325
- const diffs = [];
326
- for (const f of changedFiles.slice(0, 10)) {
327
- const { localContent, remoteContent } = await syncService.getFileDiff(f);
328
- const diff = (0, import_diff.createPatch)(f, remoteContent || "", localContent || "", "remote", "local");
329
- diffs.push({
330
- file: f,
331
- localExists: localContent !== null,
332
- remoteExists: remoteContent !== null,
333
- diff
334
- });
335
- }
336
- return (0, import_helpers.successResponse)({
337
- totalChangedFiles: changedFiles.length,
338
- diffs,
339
- note: changedFiles.length > 10 ? `Showing first 10 of ${changedFiles.length} changed files` : void 0
340
- });
272
+ If no file is specified, shows diffs for all changed files.`, diffSchema, async (params) => {
273
+ const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
274
+ if (!resolved) {
275
+ return (0, helpers_1.tenantRequiredResponse)();
276
+ }
277
+ const { organisation, tenant } = resolved;
278
+ const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
279
+ if (!clientResult) {
280
+ return (0, helpers_1.authRequiredResponse)(tenant);
281
+ }
282
+ try {
283
+ const syncService = new syncService_1.SyncService(tenant, clientResult.client);
284
+ if (params.file) {
285
+ // Single file diff
286
+ const { localContent, remoteContent } = await syncService.getFileDiff(params.file);
287
+ if (params.showRemote) {
288
+ return (0, helpers_1.successResponse)({
289
+ file: params.file,
290
+ remoteContent: remoteContent || '(file does not exist on remote)',
291
+ });
292
+ }
293
+ const diff = (0, diff_1.createPatch)(params.file, remoteContent || '', localContent || '', 'remote', 'local');
294
+ return (0, helpers_1.successResponse)({
295
+ file: params.file,
296
+ localExists: localContent !== null,
297
+ remoteExists: remoteContent !== null,
298
+ diff,
299
+ });
300
+ }
301
+ else {
302
+ // All changed files
303
+ const status = await syncService.getStatus();
304
+ const changedFiles = [
305
+ ...status.modifiedLocally,
306
+ ...status.modifiedRemotely,
307
+ ...status.onlyLocal,
308
+ ...status.onlyRemote,
309
+ ];
310
+ const diffs = [];
311
+ for (const f of changedFiles.slice(0, 10)) {
312
+ // Limit to 10 files
313
+ const { localContent, remoteContent } = await syncService.getFileDiff(f);
314
+ const diff = (0, diff_1.createPatch)(f, remoteContent || '', localContent || '', 'remote', 'local');
315
+ diffs.push({
316
+ file: f,
317
+ localExists: localContent !== null,
318
+ remoteExists: remoteContent !== null,
319
+ diff,
320
+ });
321
+ }
322
+ return (0, helpers_1.successResponse)({
323
+ totalChangedFiles: changedFiles.length,
324
+ diffs,
325
+ note: changedFiles.length > 10
326
+ ? `Showing first 10 of ${changedFiles.length} changed files`
327
+ : undefined,
328
+ });
329
+ }
341
330
  }
342
- } catch (error) {
343
- return (0, import_helpers.errorResponse)(
344
- `Diff failed: ${error instanceof Error ? error.message : "Unknown error"}`,
345
- "NETWORK_ERROR"
346
- );
347
- }
348
- }
349
- );
350
- server.tool(
351
- "farseer_list_files",
352
- `List all files stored on the remote Farseer instance in the Files/ folder.
331
+ catch (error) {
332
+ return (0, helpers_1.errorResponse)(`Diff failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
333
+ }
334
+ });
335
+ // farseer_list_files - List remote files
336
+ server.tool('farseer_list_files', `List all files stored on the remote Farseer instance in the Files/ folder.
353
337
 
354
338
  By default shows only script files (.ts, .js, .mjs, .cjs).
355
339
  Use all=true to show all files including images, data files, etc.
356
340
 
357
- Returns file paths relative to the Files/ folder.`,
358
- listFilesSchema,
359
- async (params) => {
360
- const resolved = (0, import_helpers.resolveOrgAndTenant)(params);
361
- if (!resolved) {
362
- return (0, import_helpers.tenantRequiredResponse)();
363
- }
364
- const { organisation, tenant } = resolved;
365
- const clientResult = await (0, import_farseerFactory.getFarseerClientWithFallback)(organisation, tenant);
366
- if (!clientResult) {
367
- return (0, import_helpers.authRequiredResponse)(tenant);
368
- }
369
- try {
370
- let files = await clientResult.client.listFiles();
371
- if (!params.all) {
372
- const scriptExtensions = [".ts", ".js", ".mjs", ".cjs"];
373
- files = files.filter(
374
- (f) => scriptExtensions.some((ext) => f.name.toLowerCase().endsWith(ext))
375
- );
341
+ Returns file paths relative to the Files/ folder.`, listFilesSchema, async (params) => {
342
+ const resolved = (0, helpers_1.resolveOrgAndTenant)(params);
343
+ if (!resolved) {
344
+ return (0, helpers_1.tenantRequiredResponse)();
345
+ }
346
+ const { organisation, tenant } = resolved;
347
+ const clientResult = await (0, farseerFactory_1.getFarseerClientWithFallback)(organisation, tenant);
348
+ if (!clientResult) {
349
+ return (0, helpers_1.authRequiredResponse)(tenant);
350
+ }
351
+ try {
352
+ let files = await clientResult.client.listFiles();
353
+ // Filter to scripts unless --all
354
+ if (!params.all) {
355
+ const scriptExtensions = ['.ts', '.js', '.mjs', '.cjs'];
356
+ files = files.filter((f) => scriptExtensions.some((ext) => f.name.toLowerCase().endsWith(ext)));
357
+ }
358
+ // Group by directory
359
+ const byDirectory = {};
360
+ for (const file of files) {
361
+ const dir = file.path.includes('/') ? file.path.split('/').slice(0, -1).join('/') : '.';
362
+ if (!byDirectory[dir]) {
363
+ byDirectory[dir] = [];
364
+ }
365
+ byDirectory[dir].push(file.name);
366
+ }
367
+ return (0, helpers_1.successResponse)({
368
+ tenant,
369
+ organisation,
370
+ totalFiles: files.length,
371
+ files: files.map((f) => ({
372
+ name: f.name,
373
+ path: f.path,
374
+ reference: f.reference,
375
+ })),
376
+ byDirectory,
377
+ });
376
378
  }
377
- const byDirectory = {};
378
- for (const file of files) {
379
- const dir = file.path.includes("/") ? file.path.split("/").slice(0, -1).join("/") : ".";
380
- if (!byDirectory[dir]) {
381
- byDirectory[dir] = [];
382
- }
383
- byDirectory[dir].push(file.name);
379
+ catch (error) {
380
+ return (0, helpers_1.errorResponse)(`List files failed: ${error instanceof Error ? error.message : 'Unknown error'}`, 'NETWORK_ERROR');
384
381
  }
385
- return (0, import_helpers.successResponse)({
386
- tenant,
387
- organisation,
388
- totalFiles: files.length,
389
- files: files.map((f) => ({
390
- name: f.name,
391
- path: f.path,
392
- reference: f.reference
393
- })),
394
- byDirectory
395
- });
396
- } catch (error) {
397
- return (0, import_helpers.errorResponse)(
398
- `List files failed: ${error instanceof Error ? error.message : "Unknown error"}`,
399
- "NETWORK_ERROR"
400
- );
401
- }
402
- }
403
- );
382
+ });
404
383
  }
405
- // Annotate the CommonJS export names for ESM import in node:
406
- 0 && (module.exports = {
407
- registerSyncTools
408
- });
409
- //# sourceMappingURL=syncTools.js.map