@stellar_ai/mcp_fossil_scm 0.1.2 → 0.2.0

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.
@@ -1,118 +1,168 @@
1
- import { mkdir, writeFile } from 'node:fs/promises';
1
+ import { access, mkdir } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { z } from 'zod';
4
- import { EDITORCONFIG_CONTENT, NETWORK_TIMEOUT_MS } from '../config.js';
5
- import { applyAutoSettings, combineText, formatFailure, renderOutcome, resolveRepoPaths, resolveWorkspace, runFossil, } from '../core/fossil.js';
6
- import { clean, cwdParam, flag, pushOption } from './common.js';
7
- const dbNameParam = z
4
+ import { NETWORK_TIMEOUT_MS } from '../config.js';
5
+ import { formatFailure, renderOutcome, resolveRepoPath, resolveWorkspace, runFossil, } from '../core/fossil.js';
6
+ import { clean, workspaceParam, flag, pushOption } from './common.js';
7
+ const repoPathParam = z
8
8
  .string()
9
9
  .min(1)
10
- .optional()
11
- .describe("Repository database: a bare name ('notes' or 'notes.fossil'), a path relative to the workspace, or an absolute path. " +
12
- 'Defaults to the auto-derived "<workspace>.fossil" inside the sibling ".fossil_repositories" folder.');
10
+ .describe('Repository database file. Pass an absolute path, or a path relative to the workspace (no `.fossil` suffix is added).');
11
+ const revealSecretsParam = z
12
+ .boolean()
13
+ .default(false)
14
+ .describe('Return secrets verbatim (currently the initial admin password printed by `fossil init`).');
15
+ /** Matches `initial password is "..."` in `fossil init` output. */
16
+ const ADMIN_PASSWORD_PATTERN = /(initial password is ")[^"]*(")/g;
17
+ /** Matches credentials embedded in a URL: `scheme://user:pass@host`. */
18
+ const URL_CREDENTIALS_PATTERN = /([a-z][a-z0-9+.-]*:\/\/)[^/@\s]+@/gi;
19
+ /** Replaces secrets fossil prints with `***`. */
20
+ function redactSecrets(text) {
21
+ return text.replace(ADMIN_PASSWORD_PATTERN, '$1***$2').replace(URL_CREDENTIALS_PATTERN, '$1***@');
22
+ }
23
+ /** Returns the result with every secret redacted. */
24
+ function withoutSecrets(result) {
25
+ return {
26
+ ...result,
27
+ content: result.content.map((item) => ({ ...item, text: redactSecrets(item.text) })),
28
+ };
29
+ }
13
30
  /**
14
- * Creates `.editorconfig` (LF, final newline, trimmed trailing whitespace) when
15
- * missing and stages it. Never throws.
31
+ * True when `dir` or one of its ancestors looks like a Fossil check-out
32
+ * (`.fslckout` or `_FOSSIL_` present). Walking up matches how fossil itself
33
+ * locates the check-out when the command runs in a sub-directory.
16
34
  */
17
- async function ensureEditorConfig(dir) {
18
- const target = path.join(dir, '.editorconfig');
19
- try {
20
- // flag 'wx' fails instead of overwriting an existing file (no TOCTOU check).
21
- await writeFile(target, EDITORCONFIG_CONTENT, { encoding: 'utf8', flag: 'wx' });
22
- }
23
- catch {
24
- // Already present (EEXIST) or not writable (ENOENT/EACCES): nothing to do.
25
- return undefined;
35
+ async function hasCheckout(dir) {
36
+ let current = path.resolve(dir);
37
+ for (;;) {
38
+ for (const name of ['.fslckout', '_FOSSIL_']) {
39
+ try {
40
+ await access(path.join(current, name));
41
+ return true;
42
+ }
43
+ catch {
44
+ // Not this marker; try the next one.
45
+ }
46
+ }
47
+ const parent = path.dirname(current);
48
+ if (parent === current)
49
+ return false;
50
+ current = parent;
26
51
  }
27
- const staged = await runFossil(['add', '.editorconfig'], { cwd: dir });
28
- return staged.ok
29
- ? "Created and added '.editorconfig' to the workspace (LF line endings)."
30
- : `Created '.editorconfig' but could not stage it: ${formatFailure(staged).content[0].text}`;
31
52
  }
32
- function withWarnings(result, warnings) {
33
- if (warnings.length === 0 || result.isError)
53
+ /** Appends a hint/section to a result without changing its error state. */
54
+ function withNote(result, note) {
55
+ if (!note)
34
56
  return result;
35
- const text = combineText([result.content[0]?.text, `WARNINGS:\n${warnings.join('\n')}`]);
36
- return { content: [{ type: 'text', text }] };
57
+ const body = result.content[0]?.text ?? '';
58
+ return { ...result, content: [{ type: 'text', text: `${body}\n\n${note}` }] };
37
59
  }
38
60
  /** Repository administration: init, open, close, clone, settings. */
39
61
  export function registerAdminTools(server) {
40
62
  server.registerTool('fossil_init', {
41
63
  title: 'Initialize repository',
42
- description: 'Create a new Fossil repository database from scratch and auto-configure the recommended settings ' +
43
- "(crlf-glob, dotfiles, ignore-glob, binary-glob). Place the database in the sibling '.fossil_repositories' " +
44
- 'folder unless an explicit db_name path is given.',
64
+ description: 'Create a new Fossil repository database at the given path.',
45
65
  inputSchema: z.object({
46
- db_name: dbNameParam,
66
+ repository: repoPathParam,
47
67
  project_name: z.string().min(1).optional().describe('Project name stored in the repository. Defaults to the workspace folder name.'),
48
- cwd: cwdParam,
68
+ admin_user: z.string().min(1).optional().describe('Login to record as the repository administrator (-A).'),
69
+ template: z
70
+ .string()
71
+ .min(1)
72
+ .optional()
73
+ .describe('Repository file to copy settings from (--template).'),
74
+ project_desc: z.string().min(1).optional().describe('Project description stored in the repository (--project-desc).'),
75
+ date_override: z
76
+ .string()
77
+ .min(1)
78
+ .optional()
79
+ .describe('Timestamp of the initial check-in (--date-override).'),
80
+ reveal_secrets: revealSecretsParam,
81
+ workspace: workspaceParam,
49
82
  }),
50
- }, async ({ db_name, project_name, cwd }) => {
51
- const { workspaceDir, repoDbPath, projectName } = await resolveRepoPaths(db_name, cwd);
52
- const finalProjectName = clean(project_name) ?? projectName;
53
- const init = await runFossil(['init', repoDbPath, '--project-name', finalProjectName], { cwd: workspaceDir });
54
- if (!init.ok)
55
- return formatFailure(init);
56
- const warnings = await applyAutoSettings({ dbPath: repoDbPath, cwd: workspaceDir });
57
- return withWarnings(renderOutcome(init, {
58
- note: `Repository created at '${repoDbPath}' (project '${finalProjectName}') and auto-configured with ` +
59
- "standard settings (crlf-glob='*', dotfiles=1, ignore-glob, binary-glob).",
60
- }), warnings);
83
+ }, async ({ repository, project_name, admin_user, template, project_desc, date_override, reveal_secrets, workspace }) => {
84
+ const workspaceDir = resolveWorkspace(workspace);
85
+ const repoPath = resolveRepoPath(repository, workspaceDir);
86
+ const finalProjectName = clean(project_name) ?? (path.basename(workspaceDir) || 'project');
87
+ // fossil init cannot create the parent folder itself (SQLITE_CANTOPEN).
88
+ await mkdir(path.dirname(repoPath), { recursive: true });
89
+ const args = ['init', repoPath, '--project-name', finalProjectName];
90
+ pushOption(args, '-A', admin_user);
91
+ pushOption(args, '--template', template);
92
+ pushOption(args, '--project-desc', project_desc);
93
+ pushOption(args, '--date-override', date_override);
94
+ const init = await runFossil(args, { workspace: workspaceDir });
95
+ const rendered = renderOutcome(init, {
96
+ note: `Repository created at '${repoPath}' (project '${finalProjectName}').`,
97
+ });
98
+ return reveal_secrets ? rendered : withoutSecrets(rendered);
61
99
  });
62
100
  server.registerTool('fossil_open', {
63
101
  title: 'Open repository',
64
- description: 'Open an existing Fossil repository as a check-out in the workspace, then auto-configure the standard ' +
65
- "settings and create/stage '.editorconfig' when it is missing.",
102
+ description: 'Open an existing Fossil repository as a check-out.',
66
103
  inputSchema: z.object({
67
- db_name: dbNameParam,
104
+ repository: repoPathParam,
68
105
  force: flag('Use -f/--force to open into a directory that is not empty.'),
69
106
  keep: flag('Use -k/--keep to keep existing local files untouched.'),
107
+ nested: flag('Allow opening a repository inside an already opened check-out (--nested).'),
108
+ empty: flag('Create the check-out without files, still connected to the repository (--empty).'),
109
+ no_sync: flag('Skip the automatic sync before opening (--nosync).'),
110
+ set_mtime: flag('Stamp every file with its check-in time (--setmtime).'),
111
+ force_missing: flag('Open even when content of one side is missing (--force-missing).'),
70
112
  workdir: z
71
113
  .string()
72
114
  .min(1)
73
115
  .optional()
74
116
  .describe('Check-out directory passed as --workdir DIR (relative paths resolve against the workspace).'),
75
- cwd: cwdParam,
117
+ workspace: workspaceParam,
76
118
  }),
77
- }, async ({ db_name, force, keep, workdir, cwd }) => {
78
- const { workspaceDir, repoDbPath } = await resolveRepoPaths(db_name, cwd);
79
- const args = ['open', repoDbPath];
119
+ }, async ({ repository, force, keep, nested, empty, no_sync, set_mtime, force_missing, workdir, workspace }) => {
120
+ const workspaceDir = resolveWorkspace(workspace);
121
+ const repoPath = resolveRepoPath(repository, workspaceDir);
122
+ const args = ['open', repoPath];
80
123
  if (force)
81
124
  args.push('-f');
82
125
  if (keep)
83
126
  args.push('-k');
127
+ if (nested)
128
+ args.push('--nested');
129
+ if (empty)
130
+ args.push('--empty');
131
+ if (no_sync)
132
+ args.push('--nosync');
133
+ if (set_mtime)
134
+ args.push('--setmtime');
135
+ if (force_missing)
136
+ args.push('--force-missing');
84
137
  const requestedWorkdir = clean(workdir);
85
138
  const checkoutDir = requestedWorkdir ? path.resolve(workspaceDir, requestedWorkdir) : workspaceDir;
86
139
  if (requestedWorkdir)
87
140
  args.push('--workdir', checkoutDir);
88
- const opened = await runFossil(args, { cwd: workspaceDir });
141
+ const opened = await runFossil(args, { workspace: workspaceDir });
89
142
  if (!opened.ok)
90
143
  return formatFailure(opened);
91
- const warnings = await applyAutoSettings({ cwd: checkoutDir });
92
- const editorconfig = await ensureEditorConfig(checkoutDir);
93
- return withWarnings(renderOutcome(opened, {
94
- note: combineText([
95
- warnings.length === 0
96
- ? `Opened repository '${repoDbPath}' in '${checkoutDir}' with standard settings ` +
97
- "(crlf-glob='*', dotfiles=1, ignore-glob, binary-glob)."
98
- : `Opened repository '${repoDbPath}' in '${checkoutDir}'.`,
99
- editorconfig,
100
- ]),
101
- }), warnings);
144
+ return renderOutcome(opened, { note: `Opened repository '${repoPath}' in '${checkoutDir}'.` });
102
145
  });
103
146
  server.registerTool('fossil_close', {
104
147
  title: 'Close check-out',
105
- description: 'Close the Fossil check-out that is currently open in the workspace (the repository database is kept).',
148
+ description: 'Close the Fossil check-out that is currently open in the workspace.',
106
149
  inputSchema: z.object({
107
150
  force: flag('Use -f/--force to close even with uncommitted changes or a pending stash.'),
108
- cwd: cwdParam,
151
+ workspace: workspaceParam,
109
152
  }),
110
153
  annotations: { destructiveHint: true, idempotentHint: true },
111
- }, async ({ force, cwd }) => {
154
+ }, async ({ force, workspace }) => {
112
155
  const args = ['close'];
113
156
  if (force)
114
157
  args.push('-f');
115
- return renderOutcome(await runFossil(args, { cwd }));
158
+ const rendered = renderOutcome(await runFossil(args, { workspace }));
159
+ if (force || !rendered.isError)
160
+ return rendered;
161
+ const text = rendered.content[0]?.text ?? '';
162
+ const dirty = /unsaved changes|uncommitted|pending stash|local changes/i.test(text);
163
+ return dirty
164
+ ? withNote(rendered, 'HINT: the check-out has uncommitted changes; call this tool again with force: true to close anyway.')
165
+ : rendered;
116
166
  });
117
167
  server.registerTool('fossil_clone', {
118
168
  title: 'Clone repository',
@@ -125,35 +175,392 @@ export function registerAdminTools(server) {
125
175
  .min(1)
126
176
  .describe('Destination .fossil file (relative paths resolve against the workspace). Missing parent folders are created.'),
127
177
  http_proxy: z.string().min(1).optional().describe('HTTP proxy URL passed as --proxy.'),
128
- cwd: cwdParam,
178
+ httpauth: z.string().min(1).optional().describe('HTTP Basic credentials "user:pass" (-B).'),
179
+ ssl_identity: z.string().min(1).optional().describe('SSL client certificate file (--ssl-identity).'),
180
+ ssh_command: z.string().min(1).optional().describe('Command used as the ssh client (-c).'),
181
+ workdir: z.string().min(1).optional().describe('Also open a check-out in this directory (--workdir).'),
182
+ nested: flag('Clone a repository inside an already opened check-out (--nested).'),
183
+ once: flag('Use the URI once and forget it (--once).'),
184
+ private: flag('Also clone private branches (--private).'),
185
+ admin_user: z.string().min(1).optional().describe('Make this user the administrator (-A).'),
186
+ unversioned: flag('Sync unversioned content too (-u).'),
187
+ verbose: flag('Show transfer statistics (-v).'),
188
+ reveal_secrets: revealSecretsParam,
189
+ workspace: workspaceParam,
129
190
  }),
130
- }, async ({ repository_uri, target_file, http_proxy, cwd }) => {
131
- const workspaceDir = resolveWorkspace(cwd);
191
+ }, async ({ repository_uri, target_file, http_proxy, httpauth, ssl_identity, ssh_command, workdir, nested, once, private: privateBranches, admin_user, unversioned, verbose, reveal_secrets, workspace, }) => {
192
+ const workspaceDir = resolveWorkspace(workspace);
132
193
  const targetFile = path.resolve(workspaceDir, target_file);
133
194
  await mkdir(path.dirname(targetFile), { recursive: true });
134
195
  const args = ['clone', repository_uri, targetFile];
135
196
  pushOption(args, '--proxy', http_proxy);
136
- const outcome = await runFossil(args, { cwd: workspaceDir, timeoutMs: NETWORK_TIMEOUT_MS });
137
- return renderOutcome(outcome, { note: `Repository cloned to '${targetFile}'.` });
197
+ pushOption(args, '--httpauth', httpauth);
198
+ pushOption(args, '--ssl-identity', ssl_identity);
199
+ pushOption(args, '--ssh-command', ssh_command);
200
+ pushOption(args, '--workdir', workdir);
201
+ pushOption(args, '--admin-user', admin_user);
202
+ if (nested)
203
+ args.push('--nested');
204
+ if (once)
205
+ args.push('--once');
206
+ if (privateBranches)
207
+ args.push('--private');
208
+ if (unversioned)
209
+ args.push('-u');
210
+ if (verbose)
211
+ args.push('-v');
212
+ const outcome = await runFossil(args, { workspace: workspaceDir, timeoutMs: NETWORK_TIMEOUT_MS });
213
+ const rendered = renderOutcome(outcome, { note: `Repository cloned to '${targetFile}'.` });
214
+ return reveal_secrets ? rendered : withoutSecrets(rendered);
138
215
  });
139
216
  server.registerTool('fossil_settings', {
140
217
  title: 'Read/write settings',
141
- description: 'Read or change Fossil repository settings (crlf-glob, binary-glob, ignore-glob, autosync, ...). ' +
142
- 'Without arguments it lists every setting; with name only it shows that value; with name and value it sets it.',
218
+ description: 'Read or change Fossil settings (crlf-glob, binary-glob, ignore-glob, autosync, ...). ' +
219
+ 'Without arguments it lists every setting; with name only it shows that value; with name and value it sets it; ' +
220
+ 'with unset: true it clears it.',
143
221
  inputSchema: z.object({
144
222
  name: z.string().min(1).optional().describe('Setting name, e.g. "autosync".'),
145
- value: z.string().optional().describe('New value for the setting. Only used together with name.'),
146
- cwd: cwdParam,
223
+ value: z.string().optional().describe('New value for the setting. Requires name.'),
224
+ unset: flag('Clear the setting instead of setting a value (fossil unset). Requires name.'),
225
+ global: flag('Operate on the user-level configuration (~/.config/fossil.db) instead of the repository (--global).'),
226
+ exact: flag('Match the setting name exactly instead of by prefix (--exact).'),
227
+ workspace: workspaceParam,
147
228
  }),
148
229
  annotations: { idempotentHint: true },
149
- }, async ({ name, value, cwd }) => {
150
- const args = ['settings'];
230
+ }, async ({ name, value, unset, global, exact, workspace }) => {
231
+ const workspaceDir = resolveWorkspace(workspace);
151
232
  const settingName = clean(name);
152
- if (settingName) {
153
- args.push(settingName);
154
- if (value !== undefined)
155
- args.push(value);
233
+ if (!settingName && value !== undefined) {
234
+ return {
235
+ content: [
236
+ {
237
+ type: 'text',
238
+ text: 'ERROR: `value` requires `name` (pass name to read it, name + value to write it, neither to list every setting).',
239
+ },
240
+ ],
241
+ isError: true,
242
+ };
243
+ }
244
+ if (unset && !settingName) {
245
+ return {
246
+ content: [{ type: 'text', text: 'ERROR: `unset` requires `name` (name the setting to clear).' }],
247
+ isError: true,
248
+ };
249
+ }
250
+ if (unset && value !== undefined) {
251
+ return {
252
+ content: [
253
+ {
254
+ type: 'text',
255
+ text: 'ERROR: `unset` and `value` are mutually exclusive; pass `unset: true` with `name` to clear a setting.',
256
+ },
257
+ ],
258
+ isError: true,
259
+ };
260
+ }
261
+ const scope = global ? ['--global'] : [];
262
+ const matcher = exact ? ['--exact'] : [];
263
+ let args;
264
+ if (unset) {
265
+ args = ['unset', settingName, ...scope, ...matcher];
266
+ }
267
+ else {
268
+ args = ['settings', ...scope, ...matcher];
269
+ if (settingName) {
270
+ args.push(settingName);
271
+ if (value !== undefined)
272
+ args.push(value);
273
+ }
274
+ }
275
+ const outcome = await runFossil(args, { workspace: workspaceDir });
276
+ const rendered = renderOutcome(outcome);
277
+ if (rendered.isError)
278
+ return rendered;
279
+ if (unset)
280
+ return withNote(rendered, `Setting '${settingName}' cleared${global ? ' in the user-level configuration' : ''}.`);
281
+ const lines = outcome.stdout.split(/\r?\n/).filter((line) => line.trim());
282
+ const notes = [];
283
+ if (settingName && !exact && lines.length > 1) {
284
+ notes.push(`NOTE: '${settingName}' matched ${lines.length} settings (Fossil matches setting names by prefix; pass exact: true to match one).`);
285
+ }
286
+ if (!global && !(await hasCheckout(workspaceDir))) {
287
+ notes.push(`WARNING: no check-out found in '${workspaceDir}' (.fslckout / _FOSSIL_ missing), so this setting came ` +
288
+ 'from the user-level configuration (~/.config/fossil.db), not from a repository.');
289
+ }
290
+ return withNote(rendered, notes.join('\n'));
291
+ });
292
+ server.registerTool('fossil_remote', {
293
+ title: 'Remote URLs',
294
+ description: 'View or change the remote repository URLs used for sync: list the named URLs, show the default, ' +
295
+ 'add or delete a named URL, make one the default, or turn the default off.',
296
+ inputSchema: z.object({
297
+ action: z
298
+ .enum(['list', 'default', 'add', 'delete', 'off', 'set'])
299
+ .default('list')
300
+ .describe('list: all URLs; default: the current default; add/delete: named URLs; set: make name the default; off: forget the default.'),
301
+ name: z.string().min(1).optional().describe('Name of the remote for add/delete, or the URL/prior name to make default with set.'),
302
+ url: z.string().min(1).optional().describe('URL registered by add (a URL or the name of an existing remote).'),
303
+ reveal_secrets: revealSecretsParam,
304
+ workspace: workspaceParam,
305
+ }),
306
+ }, async ({ action, name, url, reveal_secrets, workspace }) => {
307
+ const remoteName = clean(name);
308
+ const remoteUrl = clean(url);
309
+ if (action === 'add' && (!remoteName || !remoteUrl)) {
310
+ return {
311
+ content: [{ type: 'text', text: 'ERROR: `add` requires both `name` and `url` (fossil remote add NAME URL).' }],
312
+ isError: true,
313
+ };
314
+ }
315
+ if (action === 'add' && remoteName === 'default') {
316
+ return {
317
+ content: [
318
+ {
319
+ type: 'text',
320
+ text: 'ERROR: fossil reserves the name `default`; register the URL under another name, then call this tool with `action: "set"` and that name to make it the default.',
321
+ },
322
+ ],
323
+ isError: true,
324
+ };
325
+ }
326
+ if ((action === 'delete' || action === 'set') && !remoteName) {
327
+ return {
328
+ content: [
329
+ { type: 'text', text: `ERROR: \`${action}\` requires \`name\` (the remote name${action === 'set' ? ' or URL' : ''}).` },
330
+ ],
331
+ isError: true,
332
+ };
333
+ }
334
+ const args = ['remote'];
335
+ switch (action) {
336
+ case 'list':
337
+ args.push('list');
338
+ break;
339
+ case 'default':
340
+ break;
341
+ case 'add':
342
+ args.push('add', remoteName, remoteUrl);
343
+ break;
344
+ case 'delete':
345
+ args.push('delete', remoteName);
346
+ break;
347
+ case 'off':
348
+ args.push('off');
349
+ break;
350
+ case 'set':
351
+ args.push(remoteName);
352
+ break;
353
+ }
354
+ const outcome = await runFossil(args, { workspace });
355
+ if (!outcome.ok)
356
+ return renderOutcome(outcome);
357
+ if (action === 'default' && outcome.stdout.trim() === 'off') {
358
+ return { content: [{ type: 'text', text: 'No default remote (off).' }] };
359
+ }
360
+ const emptyText = action === 'list'
361
+ ? 'No remote URLs configured.'
362
+ : action === 'default'
363
+ ? 'No default remote (off).'
364
+ : `Remote \`${action}\` done.`;
365
+ const rendered = renderOutcome(outcome, { emptyText });
366
+ return reveal_secrets ? rendered : withoutSecrets(rendered);
367
+ });
368
+ const networkOptions = {
369
+ url: z
370
+ .string()
371
+ .min(1)
372
+ .optional()
373
+ .describe('Remote URL; omit to reuse the URL fossil recorded from the last clone, push, pull, remote or sync.'),
374
+ all: flag('Use every configured remote (--all).'),
375
+ private: flag('Include private branches (--private).'),
376
+ once: flag('Use the URL for this command only (--once).'),
377
+ verily: flag('Exchange extra information with the remote to be sure nothing is overlooked (--verily).'),
378
+ verbose: flag('Print additional debugging output (--verbose).'),
379
+ proxy: z.string().min(1).optional().describe('HTTP proxy URL (--proxy).'),
380
+ httpauth: z.string().min(1).optional().describe('Credentials for the simple HTTP auth protocol, as USER:PASS (--httpauth).'),
381
+ ssl_identity: z.string().min(1).optional().describe('Client SSL identity file when the remote asks for one (--ssl-identity).'),
382
+ reveal_secrets: revealSecretsParam,
383
+ workspace: workspaceParam,
384
+ };
385
+ const networkArgs = (command, options) => {
386
+ const args = [command];
387
+ const remoteUrl = clean(options.url);
388
+ if (remoteUrl)
389
+ args.push(remoteUrl);
390
+ if (options.all)
391
+ args.push('--all');
392
+ if (options.private)
393
+ args.push('--private');
394
+ if (options.once)
395
+ args.push('--once');
396
+ if (options.verily)
397
+ args.push('--verily');
398
+ if (options.verbose)
399
+ args.push('-v');
400
+ pushOption(args, '--proxy', options.proxy);
401
+ pushOption(args, '--httpauth', options.httpauth);
402
+ pushOption(args, '--ssl-identity', options.ssl_identity);
403
+ return args;
404
+ };
405
+ server.registerTool('fossil_push', {
406
+ title: 'Push',
407
+ description: 'Send the local repository\'s sharable changes (public check-ins plus wiki, ticket and forum edits) ' +
408
+ 'to a remote repository. Uses a longer timeout because pushing is network bound.',
409
+ inputSchema: z.object(networkOptions),
410
+ annotations: { openWorldHint: true },
411
+ }, async (input) => {
412
+ const outcome = await runFossil(networkArgs('push', input), {
413
+ workspace: input.workspace,
414
+ timeoutMs: NETWORK_TIMEOUT_MS,
415
+ });
416
+ const rendered = renderOutcome(outcome);
417
+ return input.reveal_secrets ? rendered : withoutSecrets(rendered);
418
+ });
419
+ server.registerTool('fossil_pull', {
420
+ title: 'Pull',
421
+ description: 'Bring a remote repository\'s sharable changes into the local repository. ' +
422
+ 'Uses a longer timeout because pulling is network bound.',
423
+ inputSchema: z.object({
424
+ ...networkOptions,
425
+ from_parent_project: flag('Ask the remote for content belonging to its parent project (--from-parent-project).'),
426
+ project_code: z.string().min(1).optional().describe('Project code the remote must report (--project-code).'),
427
+ }),
428
+ annotations: { openWorldHint: true },
429
+ }, async (input) => {
430
+ const args = networkArgs('pull', input);
431
+ if (input.from_parent_project)
432
+ args.push('--from-parent-project');
433
+ pushOption(args, '--project-code', input.project_code);
434
+ const outcome = await runFossil(args, { workspace: input.workspace, timeoutMs: NETWORK_TIMEOUT_MS });
435
+ const rendered = renderOutcome(outcome);
436
+ return input.reveal_secrets ? rendered : withoutSecrets(rendered);
437
+ });
438
+ server.registerTool('fossil_sync', {
439
+ title: 'Sync',
440
+ description: 'Exchange sharable changes in both directions with a remote repository. ' +
441
+ 'Uses a longer timeout because syncing is network bound.',
442
+ inputSchema: z.object({
443
+ ...networkOptions,
444
+ unversioned: flag('Include unversioned content (--unversioned).'),
445
+ }),
446
+ annotations: { openWorldHint: true },
447
+ }, async (input) => {
448
+ const args = networkArgs('sync', input);
449
+ if (input.unversioned)
450
+ args.push('-u');
451
+ const outcome = await runFossil(args, { workspace: input.workspace, timeoutMs: NETWORK_TIMEOUT_MS });
452
+ const rendered = renderOutcome(outcome);
453
+ return input.reveal_secrets ? rendered : withoutSecrets(rendered);
454
+ });
455
+ server.registerTool('fossil_rebuild', {
456
+ title: 'Rebuild repository',
457
+ description: 'Reconstruct the repository database from its core records, e.g. after changing the fossil schema. WARNING: destructive. It rewrites the repository database; obtain user confirmation first.',
458
+ inputSchema: z.object({
459
+ repository: repoPathParam
460
+ .optional()
461
+ .describe('Repository database file; omit to rebuild the repository of the open check-out.'),
462
+ ifneeded: flag('Rebuild only when the schema version would change (--ifneeded).'),
463
+ compress: flag('Shrink the database while rebuilding (--compress).'),
464
+ compress_only: flag('Only run the compression step (--compress-only).'),
465
+ vacuum: flag('Run VACUUM afterwards (--vacuum).'),
466
+ stats: flag('Show artifact statistics afterwards (--stats).'),
467
+ analyze: flag('Run ANALYZE afterwards (--analyze).'),
468
+ wal: flag('Switch the database to Write-Ahead-Log journalling (--wal).'),
469
+ force: flag('Finish even when errors are seen (--force).'),
470
+ quiet: flag('Print output only for errors (--quiet).'),
471
+ cluster: flag('Compute clusters for unclustered artifacts (--cluster).'),
472
+ deanalyze: flag('Remove the ANALYZE tables from the database (--deanalyze).'),
473
+ no_verify: flag('Skip verification of changes to the BLOB table (--noverify).'),
474
+ index: flag('Always rebuild the full-text search index (--index).'),
475
+ noindex: flag('Skip the full-text search index (--noindex).'),
476
+ pagesize: z.number().int().min(512).max(65536).optional().describe('Database page size (--pagesize).'),
477
+ workspace: workspaceParam,
478
+ }),
479
+ annotations: { destructiveHint: true },
480
+ }, async (input) => {
481
+ const args = ['rebuild'];
482
+ if (input.ifneeded)
483
+ args.push('--ifneeded');
484
+ if (input.compress)
485
+ args.push('--compress');
486
+ if (input.compress_only)
487
+ args.push('--compress-only');
488
+ if (input.vacuum)
489
+ args.push('--vacuum');
490
+ if (input.stats)
491
+ args.push('--stats');
492
+ if (input.analyze)
493
+ args.push('--analyze');
494
+ if (input.wal)
495
+ args.push('--wal');
496
+ if (input.force)
497
+ args.push('--force');
498
+ if (input.quiet)
499
+ args.push('--quiet');
500
+ if (input.cluster)
501
+ args.push('--cluster');
502
+ if (input.deanalyze)
503
+ args.push('--deanalyze');
504
+ if (input.no_verify)
505
+ args.push('--noverify');
506
+ if (input.index)
507
+ args.push('--index');
508
+ if (input.noindex)
509
+ args.push('--noindex');
510
+ if (input.pagesize)
511
+ args.push('--pagesize', String(input.pagesize));
512
+ if (input.repository)
513
+ args.push(input.repository);
514
+ return renderOutcome(await runFossil(args, { workspace: input.workspace }));
515
+ });
516
+ server.registerTool('fossil_config', {
517
+ title: 'Project configuration',
518
+ description: 'Export, import, merge, pull, push or reset the configuration areas (ticket, user, skin, …) that live in the repository database.',
519
+ inputSchema: z.object({
520
+ action: z.enum(['export', 'import', 'merge', 'pull', 'push', 'reset']).describe('Configuration method.'),
521
+ area: z
522
+ .enum(['all', 'email', 'interwiki', 'project', 'shun', 'skin', 'ticket', 'user', 'alias', 'subscriber'])
523
+ .optional()
524
+ .describe('Configuration area; required by export, pull, push and reset.'),
525
+ file: z.string().min(1).optional().describe('File to read or write; required by export, import and merge.'),
526
+ url: z.string().min(1).optional().describe('Remote repository for pull/push; the default remote when omitted.'),
527
+ overwrite: flag('Replace local settings with the ones received from the remote (--overwrite).'),
528
+ workspace: workspaceParam,
529
+ }),
530
+ annotations: { openWorldHint: true },
531
+ }, async (input) => {
532
+ const needsArea = ['export', 'pull', 'push', 'reset'].includes(input.action);
533
+ const needsFile = ['export', 'import', 'merge'].includes(input.action);
534
+ if (needsArea && !input.area) {
535
+ return {
536
+ isError: true,
537
+ content: [{ type: 'text', text: `ERROR: \`${input.action}\` requires \`area\`.` }],
538
+ };
539
+ }
540
+ if (needsFile && !input.file) {
541
+ return {
542
+ isError: true,
543
+ content: [{ type: 'text', text: `ERROR: \`${input.action}\` requires \`file\`.` }],
544
+ };
545
+ }
546
+ const args = ['config', input.action];
547
+ if (input.action === 'export') {
548
+ args.push(input.area, input.file);
549
+ }
550
+ else if (input.action === 'import' || input.action === 'merge') {
551
+ args.push(input.file);
552
+ }
553
+ else if (input.action === 'reset') {
554
+ args.push(input.area);
555
+ }
556
+ else {
557
+ args.push(input.area);
558
+ if (input.url)
559
+ args.push(input.url);
560
+ if (input.overwrite)
561
+ args.push('--overwrite');
156
562
  }
157
- return renderOutcome(await runFossil(args, { cwd }));
563
+ const timeoutMs = input.action === 'pull' || input.action === 'push' ? NETWORK_TIMEOUT_MS : undefined;
564
+ return renderOutcome(await runFossil(args, { workspace: input.workspace, timeoutMs }));
158
565
  });
159
566
  }