@stellar_ai/mcp_fossil_scm 0.1.2 → 0.1.3

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,7 +1,17 @@
1
+ import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
1
3
  import { z } from 'zod';
2
- import { renderOutcome, renderSections, runFossil } from '../core/fossil.js';
3
- import { clean, cwdParam, filesParam, flag, pushOption } from './common.js';
4
+ import { renderOutcome, renderSections, resolveWorkspace, runFossil, truncateOutput } from '../core/fossil.js';
5
+ import { convertGitignore, renderGlobFile } from '../core/gitignore.js';
6
+ import { runSql } from '../core/sql.js';
7
+ import { clean, workspaceParam, filesParam, flag, pushOption } from './common.js';
4
8
  /** Version-control tools: status, diff, history, commit, branch and workspace state. */
9
+ /** Join glob patterns into one fossil GLOBLIST argument, quoting patterns that hold a comma. */
10
+ function globList(patterns) {
11
+ return patterns
12
+ .map((pattern) => (pattern.includes(',') ? `"${pattern}"` : pattern))
13
+ .join(',');
14
+ }
5
15
  export function registerVersionControlTools(server) {
6
16
  server.registerTool('fossil_status', {
7
17
  title: 'Status',
@@ -11,10 +21,10 @@ export function registerVersionControlTools(server) {
11
21
  dotfiles: flag('Include dot-files in the untracked (extra) list.'),
12
22
  brief: flag('Use -b to print a single status keyword.'),
13
23
  ignore: z.string().min(1).optional().describe('Comma-separated glob patterns of extra files to ignore.'),
14
- cwd: cwdParam,
24
+ workspace: workspaceParam,
15
25
  }),
16
26
  annotations: { readOnlyHint: true },
17
- }, async ({ dotfiles, brief, ignore, cwd }) => {
27
+ }, async ({ dotfiles, brief, ignore, workspace }) => {
18
28
  const statusArgs = ['status'];
19
29
  if (brief)
20
30
  statusArgs.push('-b');
@@ -23,8 +33,8 @@ export function registerVersionControlTools(server) {
23
33
  extraArgs.push('--dotfiles');
24
34
  pushOption(extraArgs, '--ignore', ignore);
25
35
  const [status, extra] = await Promise.all([
26
- runFossil(statusArgs, { cwd }),
27
- runFossil(extraArgs, { cwd }),
36
+ runFossil(statusArgs, { workspace }),
37
+ runFossil(extraArgs, { workspace }),
28
38
  ]);
29
39
  return renderSections([
30
40
  { title: 'STATUS', outcome: status },
@@ -39,63 +49,109 @@ export function registerVersionControlTools(server) {
39
49
  to_version: z.string().min(1).optional().describe('Ending check-in/revision (--to).'),
40
50
  files: filesParam.describe('Optional list of files to diff.'),
41
51
  branch: z.string().min(1).optional().describe('Diff across a branch (--branch).'),
52
+ checkin: z.string().min(1).optional().describe('Diff all changes introduced by this check-in (-ci).'),
42
53
  brief: flag('Only list the changed file names (--brief).'),
54
+ stat: flag('Show only the number of added and deleted lines (--numstat).'),
55
+ context: z.number().int().min(0).max(100).optional().describe('Lines of context around each change (-c).'),
56
+ side_by_side: flag('Print a side-by-side diff (-y).'),
57
+ verbose: flag('Print the complete text of added or deleted files (-v).'),
58
+ undo: flag('Diff against the undo buffer (--undo).'),
43
59
  ignore_whitespace: flag('Ignore whitespace-only changes (-w).'),
44
- cwd: cwdParam,
60
+ workspace: workspaceParam,
45
61
  }),
46
62
  annotations: { readOnlyHint: true },
47
- }, async ({ from_version, to_version, files, branch, brief, ignore_whitespace, cwd }) => {
63
+ }, async ({ from_version, to_version, files, branch, checkin, brief, stat, context: contextLines, side_by_side, verbose, undo, ignore_whitespace, workspace, }) => {
48
64
  const args = ['diff'];
49
65
  pushOption(args, '--from', from_version);
50
66
  pushOption(args, '--to', to_version);
51
67
  pushOption(args, '--branch', branch);
68
+ pushOption(args, '-ci', checkin);
52
69
  if (brief)
53
70
  args.push('--brief');
71
+ if (stat)
72
+ args.push('--numstat');
73
+ if (contextLines !== undefined)
74
+ args.push('-c', String(contextLines));
75
+ if (side_by_side)
76
+ args.push('-y');
77
+ if (verbose)
78
+ args.push('-v');
79
+ if (undo)
80
+ args.push('--undo');
54
81
  if (ignore_whitespace)
55
82
  args.push('-w');
56
83
  if (files?.length)
57
84
  args.push(...files);
58
- return renderOutcome(await runFossil(args, { cwd }), { emptyText: 'No differences found.' });
85
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No differences found.' });
59
86
  });
60
87
  server.registerTool('fossil_cat', {
61
88
  title: 'Cat file revision',
62
- description: 'Print the content of a file at a given revision without touching the workspace.',
89
+ description: 'Print the content of a file at a given revision.',
63
90
  inputSchema: z.object({
64
91
  file: z.string().min(1).describe('File path/name inside the repository.'),
65
92
  revision: z.string().min(1).optional().describe('Check-in or revision (-r). Defaults to the checked-out version.'),
66
- cwd: cwdParam,
93
+ workspace: workspaceParam,
67
94
  }),
68
95
  annotations: { readOnlyHint: true },
69
- }, async ({ file, revision, cwd }) => {
96
+ }, async ({ file, revision, workspace }) => {
70
97
  const args = ['cat', file];
71
98
  pushOption(args, '-r', revision);
72
- return renderOutcome(await runFossil(args, { cwd }));
99
+ return renderOutcome(await runFossil(args, { workspace }));
73
100
  });
74
101
  server.registerTool('fossil_finfo', {
75
102
  title: 'File history',
76
- description: 'Show the revision history (finfo) of a single file.',
103
+ description: 'Show the change history of one file, or switch to the artifact facts, status line or file content view.',
77
104
  inputSchema: z.object({
78
105
  file: z.string().min(1).describe('File to inspect.'),
79
- limit: z.number().int().min(1).max(1000).default(20).describe('Number of events to show.'),
80
- cwd: cwdParam,
106
+ mode: z
107
+ .enum(['log', 'id', 'status', 'print'])
108
+ .default('log')
109
+ .describe('log: revisions with comments; id: artifact facts; status: one-line status; print: file content.'),
110
+ brief: flag('One line per revision, in log mode (-b).'),
111
+ limit: z.number().int().min(1).max(1000).default(20).describe('Number of revisions to show, in log mode (-n).'),
112
+ offset: z.number().int().min(0).optional().describe('Revisions to skip, in log mode (--offset).'),
113
+ revision: z.string().min(1).optional().describe('Revision the id and print modes describe (-r).'),
114
+ verbose: flag('In id mode, show every check-in that uses the file (-v).'),
115
+ workspace: workspaceParam,
81
116
  }),
82
117
  annotations: { readOnlyHint: true },
83
- }, async ({ file, limit, cwd }) => renderOutcome(await runFossil(['finfo', '-n', String(limit ?? 20), file], { cwd })));
118
+ }, async ({ file, mode, brief, limit, offset, revision, verbose, workspace }) => {
119
+ const args = ['finfo'];
120
+ if (mode === 'id')
121
+ args.push('-i');
122
+ else if (mode === 'status')
123
+ args.push('-s');
124
+ else if (mode === 'print')
125
+ args.push('-p');
126
+ if (mode === 'log') {
127
+ if (brief)
128
+ args.push('-b');
129
+ if (limit !== undefined)
130
+ args.push('-n', String(limit));
131
+ if (offset !== undefined)
132
+ args.push('--offset', String(offset));
133
+ }
134
+ pushOption(args, '-r', revision);
135
+ if (verbose)
136
+ args.push('-v');
137
+ args.push(file);
138
+ return renderOutcome(await runFossil(args, { workspace }));
139
+ });
84
140
  server.registerTool('fossil_revert', {
85
141
  title: 'Revert changes',
86
142
  description: 'Revert uncommitted local changes. Destructive: the workspace is restored from the repository.',
87
143
  inputSchema: z.object({
88
144
  files: filesParam.describe('Files to revert. Omit to revert the whole check-out.'),
89
145
  revision: z.string().min(1).optional().describe('Revision to revert to (-r).'),
90
- cwd: cwdParam,
146
+ workspace: workspaceParam,
91
147
  }),
92
148
  annotations: { destructiveHint: true },
93
- }, async ({ files, revision, cwd }) => {
149
+ }, async ({ files, revision, workspace }) => {
94
150
  const args = ['revert'];
95
151
  pushOption(args, '-r', revision);
96
152
  if (files?.length)
97
153
  args.push(...files);
98
- return renderOutcome(await runFossil(args, { cwd }));
154
+ return renderOutcome(await runFossil(args, { workspace }));
99
155
  });
100
156
  server.registerTool('fossil_stash', {
101
157
  title: 'Stash',
@@ -107,9 +163,9 @@ export function registerVersionControlTools(server) {
107
163
  .describe('Stash sub-command.'),
108
164
  comment: z.string().optional().describe('Comment used by save/snapshot (-m).'),
109
165
  stash_id: z.string().min(1).optional().describe('Stash id used by pop/apply/drop/diff.'),
110
- cwd: cwdParam,
166
+ workspace: workspaceParam,
111
167
  }),
112
- }, async ({ action, comment, stash_id, cwd }) => {
168
+ }, async ({ action, comment, stash_id, workspace }) => {
113
169
  const args = ['stash', action ?? 'ls'];
114
170
  if ((action === 'save' || action === 'snapshot') && comment !== undefined) {
115
171
  args.push('-m', comment);
@@ -119,7 +175,7 @@ export function registerVersionControlTools(server) {
119
175
  if (stashId)
120
176
  args.push(stashId);
121
177
  }
122
- return renderOutcome(await runFossil(args, { cwd }), { emptyText: 'No stashed changes.' });
178
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No stashed changes.' });
123
179
  });
124
180
  server.registerTool('fossil_tag', {
125
181
  title: 'Tags',
@@ -132,10 +188,10 @@ export function registerVersionControlTools(server) {
132
188
  .min(1)
133
189
  .optional()
134
190
  .describe('Target check-in (required for add; defaults to tip for cancel).'),
135
- cwd: cwdParam,
191
+ workspace: workspaceParam,
136
192
  }),
137
193
  annotations: { idempotentHint: true },
138
- }, async ({ action, tag_name, checkin, cwd }) => {
194
+ }, async ({ action, tag_name, checkin, workspace }) => {
139
195
  const name = clean(tag_name);
140
196
  const target = clean(checkin);
141
197
  if (action === 'add' && (!name || !target)) {
@@ -154,7 +210,7 @@ export function registerVersionControlTools(server) {
154
210
  if (name)
155
211
  args.push(name, target ?? 'tip');
156
212
  }
157
- return renderOutcome(await runFossil(args, { cwd }), { emptyText: 'No tags.' });
213
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No tags.' });
158
214
  });
159
215
  server.registerTool('fossil_addremove', {
160
216
  title: 'Add/remove scan',
@@ -164,10 +220,13 @@ export function registerVersionControlTools(server) {
164
220
  ignore: z.string().min(1).optional().describe('Comma-separated glob patterns to ignore (--ignore).'),
165
221
  clean: z.string().min(1).optional().describe('Comma-separated glob patterns of clean files to ignore (--clean).'),
166
222
  reset: flag('Reset the ADDED/DELETED state of the check-out instead (--reset).'),
167
- cwd: cwdParam,
223
+ dry_run: flag('Show what would be staged without changing anything (-n/--dry-run).'),
224
+ workspace: workspaceParam,
168
225
  }),
169
- }, async ({ dotfiles, ignore, clean: cleanGlob, reset, cwd }) => {
226
+ }, async ({ dotfiles, ignore, clean: cleanGlob, reset, dry_run, workspace }) => {
170
227
  const args = ['addremove'];
228
+ if (dry_run)
229
+ args.push('-n');
171
230
  if (reset) {
172
231
  args.push('--reset');
173
232
  }
@@ -177,50 +236,81 @@ export function registerVersionControlTools(server) {
177
236
  pushOption(args, '--ignore', ignore);
178
237
  pushOption(args, '--clean', cleanGlob);
179
238
  }
180
- return renderOutcome(await runFossil(args, { cwd }));
239
+ return renderOutcome(await runFossil(args, { workspace }));
181
240
  });
182
241
  server.registerTool('fossil_commit', {
183
242
  title: 'Commit',
184
243
  description: 'Create a check-in from the staged/current changes. Answers the interactive "commit anyhow" prompt with ' +
185
- "'a' (all) automatically, so binary-file confirmations never block the server.",
244
+ "'a' (all) automatically.",
186
245
  inputSchema: z.object({
187
246
  message: z.string().min(1).describe('Commit message.'),
188
247
  files: filesParam.describe('Files to commit. Omit to commit everything that changed.'),
189
248
  branch: z.string().min(1).optional().describe('Place the new check-in on this branch (--branch).'),
190
- no_warnings: flag('Omit content warnings (--no-warnings), on by default.'),
249
+ no_warnings: flag('Omit content warnings (--no-warnings).'),
191
250
  allow_empty: flag('Allow a check-in with no file changes (--allow-empty).'),
192
251
  user_override: z.string().min(1).optional().describe('Record this login as the author (--user-override).'),
193
- cwd: cwdParam,
252
+ tags: z.array(z.string().min(1)).optional().describe('Tags to attach to the new check-in (--tag).'),
253
+ close: flag('Close the branch being committed (--close).'),
254
+ bgcolor: z.string().min(1).optional().describe('Background colour for this one check-in (--bgcolor).'),
255
+ mtime: z.string().min(1).optional().describe('Check-in timestamp, e.g. "2026-11-17 12:00:00" (--mtime).'),
256
+ workspace: workspaceParam,
194
257
  }),
195
- }, async ({ message, files, branch, no_warnings, allow_empty, user_override, cwd }) => {
258
+ }, async ({ message, files, branch, no_warnings, allow_empty, user_override, tags, close, bgcolor, mtime, workspace }) => {
196
259
  const args = ['commit', '-m', message];
197
260
  pushOption(args, '--branch', branch);
198
261
  if (no_warnings)
199
262
  args.push('--no-warnings');
200
263
  if (allow_empty)
201
264
  args.push('--allow-empty');
265
+ if (close)
266
+ args.push('--close');
267
+ pushOption(args, '--bgcolor', bgcolor);
268
+ pushOption(args, '--mtime', mtime);
269
+ for (const tag of tags ?? [])
270
+ args.push('--tag', tag);
202
271
  pushOption(args, '--user-override', user_override);
203
272
  if (files?.length)
204
273
  args.push(...files);
205
- return renderOutcome(await runFossil(args, { cwd, input: 'a\n' }));
274
+ return renderOutcome(await runFossil(args, { workspace, input: 'a\n' }));
206
275
  });
207
276
  server.registerTool('fossil_add', {
208
277
  title: 'Add files',
209
278
  description: 'Start tracking one or more files or directories.',
210
279
  inputSchema: z.object({
211
- files: z.array(z.string().min(1)).min(1).describe('Files or directories to add.'),
280
+ files: z
281
+ .array(z.string().min(1))
282
+ .optional()
283
+ .describe('Files or directories to add. Required unless reset is true.'),
212
284
  dotfiles: flag('Recurse into dot-files/directories (--dotfiles).'),
213
285
  force: z.boolean().default(true).describe('Add even when a file matches ignore-glob, without prompting (-f).'),
214
- cwd: cwdParam,
286
+ reset: flag('Reset the ADDED state instead of adding files (--reset).'),
287
+ ignore: z.string().min(1).optional().describe('Ignore unmanaged files matching these globs (--ignore).'),
288
+ verbose: flag('Report each file while resetting, with reset: true (-v).'),
289
+ workspace: workspaceParam,
215
290
  }),
216
- }, async ({ files, dotfiles, force, cwd }) => {
291
+ }, async ({ files, dotfiles, force, reset, ignore, verbose, workspace }) => {
217
292
  const args = ['add'];
293
+ if (reset) {
294
+ args.push('--reset');
295
+ if (verbose)
296
+ args.push('-v');
297
+ return renderOutcome(await runFossil(args, { workspace }));
298
+ }
299
+ if (!files?.length) {
300
+ return {
301
+ isError: true,
302
+ content: [
303
+ { type: 'text', text: 'ERROR: `files` is required unless `reset` is true.' },
304
+ ],
305
+ };
306
+ }
218
307
  if (dotfiles)
219
308
  args.push('--dotfiles');
220
309
  if (force !== false)
221
310
  args.push('-f');
311
+ pushOption(args, '--ignore', ignore);
222
312
  args.push(...files);
223
- return renderOutcome(await runFossil(args, { cwd }));
313
+ return renderOutcome(await runFossil(args, { workspace }));
224
314
  });
225
315
  server.registerTool('fossil_rm', {
226
316
  title: 'Remove files',
@@ -229,17 +319,26 @@ export function registerVersionControlTools(server) {
229
319
  files: z.array(z.string().min(1)).min(1).describe('Files or directories to remove.'),
230
320
  force: flag('Also delete from disk (--hard).'),
231
321
  keep: flag('Keep files on disk (--soft).'),
232
- cwd: cwdParam,
322
+ dry_run: flag('Show what would be removed without changing anything (-n).'),
323
+ reset: flag('Reset the DELETED state instead of removing files (--reset).'),
324
+ verbose: flag('Report each file when resetting (--verbose).'),
325
+ workspace: workspaceParam,
233
326
  }),
234
327
  annotations: { destructiveHint: true },
235
- }, async ({ files, force, keep, cwd }) => {
328
+ }, async ({ files, force, keep, dry_run, reset, verbose, workspace }) => {
236
329
  const args = ['rm'];
237
330
  if (force)
238
331
  args.push('--hard');
239
332
  if (keep)
240
333
  args.push('--soft');
334
+ if (reset)
335
+ args.push('--reset');
336
+ if (verbose)
337
+ args.push('--verbose');
338
+ if (dry_run)
339
+ args.push('-n');
241
340
  args.push(...files);
242
- return renderOutcome(await runFossil(args, { cwd }));
341
+ return renderOutcome(await runFossil(args, { workspace }));
243
342
  });
244
343
  server.registerTool('fossil_mv', {
245
344
  title: 'Move/rename',
@@ -252,14 +351,14 @@ export function registerVersionControlTools(server) {
252
351
  .boolean()
253
352
  .optional()
254
353
  .describe('Explicitly set the case-sensitive behaviour (--case-sensitive 1/0).'),
255
- cwd: cwdParam,
354
+ workspace: workspaceParam,
256
355
  }),
257
- }, async ({ old_name, new_name, hard, case_sensitive, cwd }) => {
356
+ }, async ({ old_name, new_name, hard, case_sensitive, workspace }) => {
258
357
  const args = ['mv', hard !== false ? '--hard' : '--soft'];
259
358
  if (case_sensitive !== undefined)
260
359
  args.push('--case-sensitive', case_sensitive ? '1' : '0');
261
360
  args.push(old_name, new_name);
262
- return renderOutcome(await runFossil(args, { cwd }));
361
+ return renderOutcome(await runFossil(args, { workspace }));
263
362
  });
264
363
  server.registerTool('fossil_extras', {
265
364
  title: 'List extras',
@@ -267,15 +366,30 @@ export function registerVersionControlTools(server) {
267
366
  inputSchema: z.object({
268
367
  dotfiles: flag('Include dot-files (--dotfiles).'),
269
368
  ignore: z.string().min(1).optional().describe('Comma-separated glob patterns to ignore.'),
270
- cwd: cwdParam,
369
+ abs_paths: flag('Print absolute path names (--abs-paths).'),
370
+ rel_paths: flag('Print paths relative to the current directory (--rel-paths).'),
371
+ header: flag('Prefix the list with the repository name (--header).'),
372
+ case_sensitive: z
373
+ .boolean()
374
+ .optional()
375
+ .describe('Override the case-sensitive setting (--case-sensitive 1|0).'),
376
+ workspace: workspaceParam,
271
377
  }),
272
378
  annotations: { readOnlyHint: true },
273
- }, async ({ dotfiles, ignore, cwd }) => {
379
+ }, async ({ dotfiles, ignore, abs_paths, rel_paths, header, case_sensitive, workspace }) => {
274
380
  const args = ['extras'];
275
381
  if (dotfiles)
276
382
  args.push('--dotfiles');
277
383
  pushOption(args, '--ignore', ignore);
278
- return renderOutcome(await runFossil(args, { cwd }), { emptyText: 'No untracked files.' });
384
+ if (abs_paths)
385
+ args.push('--abs-paths');
386
+ if (rel_paths)
387
+ args.push('--rel-paths');
388
+ if (header)
389
+ args.push('--header');
390
+ if (case_sensitive !== undefined)
391
+ args.push('--case-sensitive', case_sensitive ? '1' : '0');
392
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No untracked files.' });
279
393
  });
280
394
  server.registerTool('fossil_clean', {
281
395
  title: 'Clean untracked files',
@@ -284,12 +398,12 @@ export function registerVersionControlTools(server) {
284
398
  inputSchema: z.object({
285
399
  all_files: flag('Force deletion without confirmation (-f).'),
286
400
  dry_run: flag('Only list what would be deleted (-n).'),
287
- cwd: cwdParam,
401
+ workspace: workspaceParam,
288
402
  }),
289
403
  annotations: { destructiveHint: true },
290
- }, async ({ all_files, dry_run, cwd }) => {
404
+ }, async ({ all_files, dry_run, workspace }) => {
291
405
  const args = ['clean', dry_run ? '-n' : all_files ? '-f' : '--no-prompt'];
292
- return renderOutcome(await runFossil(args, { cwd }), { emptyText: 'Nothing to clean.' });
406
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'Nothing to clean.' });
293
407
  });
294
408
  server.registerTool('fossil_timeline', {
295
409
  title: 'Timeline',
@@ -301,28 +415,51 @@ export function registerVersionControlTools(server) {
301
415
  .string()
302
416
  .min(1)
303
417
  .optional()
304
- .describe("Event type or branch filter (-t), e.g. 'ci' for check-ins or a branch name."),
305
- cwd: cwdParam,
418
+ .describe("Event type (-t), e.g. 'ci' for check-ins, 't' for tickets, 'w' for wiki."),
419
+ branch: z.string().min(1).optional().describe('Only events on this branch (-b).'),
420
+ current_branch: flag('Only events on the current branch (-c).'),
421
+ when: z
422
+ .enum(['before', 'after', 'descendants', 'children', 'ancestors', 'parents'])
423
+ .optional()
424
+ .describe('Timeline direction relative to `checkin`.'),
425
+ checkin: z.string().min(1).optional().describe('Check-in hash or date the `when` keyword applies to.'),
426
+ format: z
427
+ .string()
428
+ .min(1)
429
+ .optional()
430
+ .describe("Entry format (-F), e.g. 'oneline' or '%h %d %c'."),
431
+ verbose: flag('List the files changed by each check-in (-v).'),
432
+ workspace: workspaceParam,
306
433
  }),
307
434
  annotations: { readOnlyHint: true },
308
- }, async ({ limit, path: targetPath, type_filter, cwd }) => {
435
+ }, async ({ limit, path: targetPath, type_filter, branch, current_branch, when, checkin, format, verbose, workspace }) => {
309
436
  const args = ['timeline', '-n', String(limit ?? 20)];
310
437
  pushOption(args, '-p', targetPath);
311
438
  pushOption(args, '-t', type_filter);
312
- return renderOutcome(await runFossil(args, { cwd }), { emptyText: 'No events.' });
439
+ pushOption(args, '-b', branch);
440
+ if (current_branch)
441
+ args.push('-c');
442
+ if (when)
443
+ args.push(when);
444
+ if (checkin)
445
+ args.push(checkin);
446
+ pushOption(args, '-F', format);
447
+ if (verbose)
448
+ args.push('-v');
449
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No events.' });
313
450
  });
314
451
  server.registerTool('fossil_info', {
315
452
  title: 'Info',
316
453
  description: 'Repository/check-out metadata, or details about a specific file, check-in or branch.',
317
454
  inputSchema: z.object({
318
455
  target: z.string().optional().describe('File name, check-in hash or branch. Omit for general repository info.'),
319
- cwd: cwdParam,
456
+ workspace: workspaceParam,
320
457
  }),
321
458
  annotations: { readOnlyHint: true },
322
- }, async ({ target, cwd }) => {
459
+ }, async ({ target, workspace }) => {
323
460
  const targetValue = clean(target);
324
461
  const args = targetValue ? ['info', targetValue] : ['info'];
325
- return renderOutcome(await runFossil(args, { cwd }));
462
+ return renderOutcome(await runFossil(args, { workspace }));
326
463
  });
327
464
  server.registerTool('fossil_branch', {
328
465
  title: 'Branches',
@@ -335,9 +472,9 @@ export function registerVersionControlTools(server) {
335
472
  .min(1)
336
473
  .optional()
337
474
  .describe("Starting point for the new branch (check-in or branch). Defaults to 'current'."),
338
- cwd: cwdParam,
475
+ workspace: workspaceParam,
339
476
  }),
340
- }, async ({ action, branch_name, basis, cwd }) => {
477
+ }, async ({ action, branch_name, basis, workspace }) => {
341
478
  const name = clean(branch_name);
342
479
  if (action === 'new' && !name) {
343
480
  return { content: [{ type: 'text', text: "ERROR: 'branch_name' is required for action 'new'." }], isError: true };
@@ -346,7 +483,7 @@ export function registerVersionControlTools(server) {
346
483
  // Fossil requires an explicit basis, 'current' means the checked-out branch.
347
484
  if (action === 'new' && name)
348
485
  args.push(name, clean(basis) ?? 'current');
349
- return renderOutcome(await runFossil(args, { cwd }));
486
+ return renderOutcome(await runFossil(args, { workspace }));
350
487
  });
351
488
  server.registerTool('fossil_merge', {
352
489
  title: 'Merge',
@@ -354,17 +491,36 @@ export function registerVersionControlTools(server) {
354
491
  inputSchema: z.object({
355
492
  branch_or_version: z.string().min(1).describe('Branch name or check-in hash to merge.'),
356
493
  integrate: flag('Close the source branch after merging (--integrate).'),
494
+ cherrypick: flag('Merge only the changes of this single check-in (--cherrypick).'),
495
+ backout: flag('Remove the changes of this single check-in (--backout).'),
357
496
  dry_run: flag('Simulate the merge without touching files (-n).'),
358
- cwd: cwdParam,
497
+ baseline: z.string().min(1).optional().describe('Use this version as the merge pivot (--baseline).'),
498
+ binary: z.string().min(1).optional().describe('Skip parallel changes of files matching this glob (--binary).'),
499
+ force: flag('Force the merge even if it would be a no-op (-f).'),
500
+ keep_merge_files: flag('Keep the temporary merge files on conflict (-K).'),
501
+ verbose: flag('Report each file as it is merged (-v).'),
502
+ workspace: workspaceParam,
359
503
  }),
360
- }, async ({ branch_or_version, integrate, dry_run, cwd }) => {
504
+ }, async ({ branch_or_version, integrate, cherrypick, backout, dry_run, baseline, binary, force, keep_merge_files, verbose, workspace, }) => {
361
505
  const args = ['merge'];
362
506
  if (dry_run)
363
507
  args.push('-n');
364
508
  if (integrate)
365
509
  args.push('--integrate');
510
+ if (cherrypick)
511
+ args.push('--cherrypick');
512
+ if (backout)
513
+ args.push('--backout');
514
+ pushOption(args, '--baseline', baseline);
515
+ pushOption(args, '--binary', binary);
516
+ if (force)
517
+ args.push('-f');
518
+ if (keep_merge_files)
519
+ args.push('-K');
520
+ if (verbose)
521
+ args.push('-v');
366
522
  args.push(branch_or_version);
367
- return renderOutcome(await runFossil(args, { cwd }));
523
+ return renderOutcome(await runFossil(args, { workspace }));
368
524
  });
369
525
  server.registerTool('fossil_update', {
370
526
  title: 'Update check-out',
@@ -372,23 +528,648 @@ export function registerVersionControlTools(server) {
372
528
  'Overrides local workspace state - obtain user confirmation first.',
373
529
  inputSchema: z.object({
374
530
  target: z.string().optional().describe('Version or branch to update to. Omit to update the current branch.'),
375
- cwd: cwdParam,
531
+ latest: flag('Update to the latest version instead of a named one (--latest).'),
532
+ dry_run: flag('Show what would change without touching the workspace (-n).'),
533
+ no_sync: flag('Skip the automatic sync before updating (--nosync).'),
534
+ set_mtime: flag('Stamp every file with its last-check-in time (--setmtime).'),
535
+ keep_merge_files: flag('Keep the temporary merge files (-K).'),
536
+ verbose: flag('Report the state of every file (-v).'),
537
+ workspace: workspaceParam,
376
538
  }),
377
539
  annotations: { destructiveHint: true },
378
- }, async ({ target, cwd }) => {
540
+ }, async ({ target, latest, dry_run, no_sync, set_mtime, keep_merge_files, verbose, workspace }) => {
379
541
  const args = ['update'];
542
+ if (latest)
543
+ args.push('--latest');
544
+ if (dry_run)
545
+ args.push('-n');
546
+ if (no_sync)
547
+ args.push('--nosync');
548
+ if (set_mtime)
549
+ args.push('--setmtime');
550
+ if (keep_merge_files)
551
+ args.push('-K');
552
+ if (verbose)
553
+ args.push('-v');
380
554
  const targetValue = clean(target);
381
555
  if (targetValue)
382
556
  args.push(targetValue);
383
- return renderOutcome(await runFossil(args, { cwd }));
557
+ return renderOutcome(await runFossil(args, { workspace }));
384
558
  });
385
559
  server.registerTool('fossil_undo', {
386
560
  title: 'Undo',
387
561
  description: 'WARNING: destructive. Undo the last update/revert/merge in the workspace. Preview with dry_run (-n) first.',
388
562
  inputSchema: z.object({
389
563
  dry_run: flag('Simulate the undo (-n) without modifying files.'),
390
- cwd: cwdParam,
564
+ workspace: workspaceParam,
565
+ }),
566
+ annotations: { destructiveHint: true },
567
+ }, async ({ dry_run, workspace }) => renderOutcome(await runFossil(dry_run ? ['undo', '-n'] : ['undo'], { workspace })));
568
+ server.registerTool('fossil_changes', {
569
+ title: 'Changes',
570
+ description: 'Report the change status of files in the check-out, optionally restricted to one or more change types ' +
571
+ '(edited, updated, added, deleted, renamed, conflict, meta) and/or to explicit paths.',
572
+ inputSchema: z.object({
573
+ files: filesParam,
574
+ edited: flag('Only edited, merged and conflicted files (--edited).'),
575
+ updated: flag('Only files updated by merge/integrate (--updated).'),
576
+ added: flag('Only added files (--added).'),
577
+ deleted: flag('Only deleted files (--deleted).'),
578
+ renamed: flag('Only renamed files (--renamed).'),
579
+ conflict: flag('Only files with merge conflicts (--conflict).'),
580
+ meta: flag('Only files with metadata changes (--meta).'),
581
+ classify: flag('Start each line with the change type (--classify).'),
582
+ no_merge: flag('Hide merge contributors (--no-merge).'),
583
+ dotfiles: flag('Include unmanaged files whose name starts with a dot (--dotfiles).'),
584
+ absolute_paths: flag('Print absolute pathnames (--abs-paths).'),
585
+ workspace: workspaceParam,
586
+ }),
587
+ annotations: { readOnlyHint: true },
588
+ }, async ({ files, edited, updated, added, deleted, renamed, conflict, meta, classify, no_merge, dotfiles, absolute_paths, workspace, }) => {
589
+ const args = ['changes'];
590
+ const filters = [
591
+ [edited, '--edited'],
592
+ [updated, '--updated'],
593
+ [added, '--added'],
594
+ [deleted, '--deleted'],
595
+ [renamed, '--renamed'],
596
+ [conflict, '--conflict'],
597
+ [meta, '--meta'],
598
+ ];
599
+ for (const [enabled, option] of filters)
600
+ if (enabled)
601
+ args.push(option);
602
+ if (classify)
603
+ args.push('--classify');
604
+ if (no_merge)
605
+ args.push('--no-merge');
606
+ if (dotfiles)
607
+ args.push('--dotfiles');
608
+ if (absolute_paths)
609
+ args.push('--abs-paths');
610
+ if (files?.length)
611
+ args.push(...files);
612
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No changes.' });
613
+ });
614
+ server.registerTool('fossil_annotate', {
615
+ title: 'Annotate',
616
+ description: 'Show a file line by line with the check-in that last changed each line' +
617
+ ' (annotate: line numbers, blame/praise: author names).',
618
+ inputSchema: z.object({
619
+ file: z.string().min(1).describe('File to annotate, relative to the check-out.'),
620
+ command: z
621
+ .enum(['blame', 'annotate', 'praise'])
622
+ .default('blame')
623
+ .describe('blame/praise print the author, annotate prints line numbers only.'),
624
+ revision: z.string().min(1).optional().describe('Check-in containing the file version to annotate (-r).'),
625
+ origin: z.string().min(1).optional().describe('Future check-in to annotate towards (-o); e.g. trunk.'),
626
+ limit: z.string().min(1).optional().describe('Version limit: a count, a duration like "2s", or "none" (-n).'),
627
+ filevers: flag('Show file versions instead of check-in versions (--filevers).'),
628
+ log: flag('List every version analysed (-l).'),
629
+ ignore_all_space: flag('Ignore all whitespace when matching lines (-w).'),
630
+ ignore_trailing_space: flag('Ignore trailing whitespace (-Z).'),
631
+ workspace: workspaceParam,
632
+ }),
633
+ annotations: { readOnlyHint: true },
634
+ }, async ({ file, command, revision, origin, limit, filevers, log, ignore_all_space, ignore_trailing_space, workspace, }) => {
635
+ const args = [command];
636
+ pushOption(args, '-r', revision);
637
+ pushOption(args, '-o', origin);
638
+ pushOption(args, '-n', limit);
639
+ if (filevers)
640
+ args.push('--filevers');
641
+ if (log)
642
+ args.push('-l');
643
+ if (ignore_all_space)
644
+ args.push('-w');
645
+ if (ignore_trailing_space)
646
+ args.push('-Z');
647
+ args.push(file);
648
+ return renderOutcome(await runFossil(args, { workspace }));
649
+ });
650
+ server.registerTool('fossil_grep', {
651
+ title: 'Grep history',
652
+ description: 'Match a POSIX extended regular expression over every historical version of the named files, ' +
653
+ 'starting at the newest version of each file.',
654
+ inputSchema: z.object({
655
+ pattern: z.string().min(1).describe('POSIX extended regular expression.'),
656
+ files: z.array(z.string().min(1)).min(1).describe('Files to search, newest version first.'),
657
+ ignore_case: flag('Case-insensitive match (-i).'),
658
+ count: flag('Print the number of matching files only (-c).'),
659
+ files_with_matches: flag('Print one artifact hash per matching file instead of the lines (-l).'),
660
+ once: flag('Stop at the first match (--once).'),
661
+ invert_match: flag('Show only files without a match (-v).'),
662
+ no_messages: flag('Suppress messages about unreadable files (-s).'),
663
+ verbose: flag('Report each file as it is analysed (--verbose).'),
664
+ workspace: workspaceParam,
665
+ }),
666
+ annotations: { readOnlyHint: true },
667
+ }, async ({ pattern, files, ignore_case, count, files_with_matches, once, invert_match, no_messages, verbose, workspace, }) => {
668
+ const args = ['grep'];
669
+ if (ignore_case)
670
+ args.push('-i');
671
+ if (count)
672
+ args.push('-c');
673
+ if (files_with_matches)
674
+ args.push('-l');
675
+ if (once)
676
+ args.push('--once');
677
+ if (invert_match)
678
+ args.push('-v');
679
+ if (no_messages)
680
+ args.push('-s');
681
+ if (verbose)
682
+ args.push('--verbose');
683
+ args.push(pattern, ...files);
684
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No matches.' });
685
+ });
686
+ server.registerTool('fossil_whatis', {
687
+ title: 'What is',
688
+ description: 'Resolve a name (tag, branch, hash prefix, or with file: the content hash) to its artifact hash and role.',
689
+ inputSchema: z.object({
690
+ name: z.string().min(1).describe('Symbol to resolve: tag, branch, hash prefix or filename.'),
691
+ file: flag('Treat name as a file whose content hash is looked up (-f).'),
692
+ type: z.enum(['ci', 't', 'w', 'g', 'e']).optional().describe('Only match this artifact type (--type).'),
693
+ verbose: flag('Include the internal record id (-v).'),
694
+ workspace: workspaceParam,
695
+ }),
696
+ annotations: { readOnlyHint: true },
697
+ }, async ({ name, file, type, verbose, workspace }) => {
698
+ const args = ['whatis'];
699
+ if (file)
700
+ args.push('-f');
701
+ pushOption(args, '--type', type);
702
+ if (verbose)
703
+ args.push('-v');
704
+ args.push(name);
705
+ return renderOutcome(await runFossil(args, { workspace }));
706
+ });
707
+ server.registerTool('fossil_merge_base', {
708
+ title: 'Merge base',
709
+ description: 'Find the common ancestor check-in of two or more versions, as a hypothetical merge would.',
710
+ inputSchema: z.object({
711
+ versions: z.array(z.string().min(1)).min(2).describe('Two or more versions; the first is the primary.'),
712
+ ignore_merges: flag('Ignore merge arcs when looking for name pivots (--ignore-merges).'),
713
+ workspace: workspaceParam,
714
+ }),
715
+ annotations: { readOnlyHint: true },
716
+ }, async ({ versions, ignore_merges, workspace }) => {
717
+ const args = ['merge-base'];
718
+ if (ignore_merges)
719
+ args.push('--ignore-merges');
720
+ args.push(...versions);
721
+ return renderOutcome(await runFossil(args, { workspace }));
722
+ });
723
+ server.registerTool('fossil_leaves', {
724
+ title: 'Leaves',
725
+ description: 'List the leaf check-ins of every branch, i.e. heads that have no children.',
726
+ inputSchema: z.object({
727
+ all: flag('Include closed leaves as well (-a).'),
728
+ closed: flag('Only closed leaves (-c).'),
729
+ multiple: flag('Only branches with more than one leaf (-m).'),
730
+ by_branch: flag('Order the output by branch name (--bybranch).'),
731
+ width: z.number().int().nonnegative().optional().describe('Output width in columns (-W); 0 means one line per entry.'),
732
+ workspace: workspaceParam,
733
+ }),
734
+ annotations: { readOnlyHint: true },
735
+ }, async ({ all, closed, multiple, by_branch, width, workspace }) => {
736
+ const args = ['leaves'];
737
+ if (all)
738
+ args.push('-a');
739
+ if (closed)
740
+ args.push('-c');
741
+ if (multiple)
742
+ args.push('-m');
743
+ if (by_branch)
744
+ args.push('--bybranch');
745
+ if (width !== undefined)
746
+ args.push('-W', String(width));
747
+ return renderOutcome(await runFossil(args, { workspace }));
748
+ });
749
+ server.registerTool('fossil_descendants', {
750
+ title: 'Descendants',
751
+ description: 'List every leaf descendant of a check-in (default: the check-out version).',
752
+ inputSchema: z.object({
753
+ checkin: z.string().min(1).optional().describe('Check-in to start from. Omit for the check-out version.'),
754
+ width: z.number().int().nonnegative().optional().describe('Output width in columns (-W); 0 means one line per entry.'),
755
+ workspace: workspaceParam,
756
+ }),
757
+ annotations: { readOnlyHint: true },
758
+ }, async ({ checkin, width, workspace }) => {
759
+ const args = ['descendants'];
760
+ const target = clean(checkin);
761
+ if (target)
762
+ args.push(target);
763
+ if (width !== undefined)
764
+ args.push('-W', String(width));
765
+ return renderOutcome(await runFossil(args, { workspace }));
766
+ });
767
+ server.registerTool('fossil_unpublished', {
768
+ title: 'Unpublished',
769
+ description: 'List unpublished check-ins (private artifacts that a push will not send).',
770
+ inputSchema: z.object({
771
+ all: flag('Include every unpublished artifact, not only check-ins (--all).'),
772
+ workspace: workspaceParam,
773
+ }),
774
+ annotations: { readOnlyHint: true },
775
+ }, async ({ all, workspace }) => renderOutcome(await runFossil(all ? ['unpublished', '--all'] : ['unpublished'], { workspace }), {
776
+ emptyText: 'No unpublished artifacts.',
777
+ }));
778
+ server.registerTool('fossil_ignore_from_gitignore', {
779
+ title: 'Ignore glob from .gitignore',
780
+ description: 'Convert a .gitignore file into the ignore-glob patterns Fossil matches against check-out paths, ' +
781
+ 'and optionally write them to .fossil-settings/ignore-glob.',
782
+ inputSchema: z.object({
783
+ source: z.string().min(1).default('.gitignore').describe('File to convert, relative to the workspace.'),
784
+ write: flag('Write the patterns to .fossil-settings/ignore-glob.'),
785
+ overwrite: flag('Replace an existing .fossil-settings/ignore-glob.'),
786
+ workspace: workspaceParam,
787
+ }),
788
+ }, async ({ source, write, overwrite, workspace }) => {
789
+ const root = resolveWorkspace(workspace);
790
+ const sourcePath = path.resolve(root, source);
791
+ const relative = path.relative(root, sourcePath);
792
+ if (relative.startsWith('..') || path.isAbsolute(relative)) {
793
+ return {
794
+ content: [{ type: 'text', text: `ERROR: \`source\` must stay inside the workspace (${root}).` }],
795
+ isError: true,
796
+ };
797
+ }
798
+ let content;
799
+ try {
800
+ content = await readFile(sourcePath, 'utf8');
801
+ }
802
+ catch (error) {
803
+ const code = error.code ?? 'unknown error';
804
+ return {
805
+ content: [{ type: 'text', text: `ERROR: cannot read ${relative}: ${code}.` }],
806
+ isError: true,
807
+ };
808
+ }
809
+ const directory = path.dirname(relative);
810
+ const conversion = convertGitignore(content, { prefix: directory === '.' ? '' : directory });
811
+ const lines = [
812
+ `Converted ${conversion.lineCount} rules from ${relative} into ${conversion.patterns.length} ignore-glob patterns.`,
813
+ '',
814
+ ...conversion.patterns,
815
+ ];
816
+ if (conversion.warnings.length > 0) {
817
+ lines.push('', ...conversion.warnings.map((warning) => `NOTE: ${warning}.`));
818
+ }
819
+ if (!write)
820
+ return { content: [{ type: 'text', text: lines.join('\n') }] };
821
+ const settingsDir = path.join(root, '.fossil-settings');
822
+ const target = path.join(settingsDir, 'ignore-glob');
823
+ const exists = await stat(target).then(() => true, () => false);
824
+ if (exists && !overwrite) {
825
+ return {
826
+ content: [
827
+ {
828
+ type: 'text',
829
+ text: 'ERROR: .fossil-settings/ignore-glob already exists; pass `overwrite: true` to replace it.',
830
+ },
831
+ ],
832
+ isError: true,
833
+ };
834
+ }
835
+ await mkdir(settingsDir, { recursive: true });
836
+ await writeFile(target, renderGlobFile(conversion), 'utf8');
837
+ lines.splice(1, 0, 'Wrote .fossil-settings/ignore-glob.');
838
+ return { content: [{ type: 'text', text: lines.join('\n') }] };
839
+ });
840
+ server.registerTool('fossil_ls', {
841
+ title: 'List files',
842
+ description: 'List the files of the check-out, or of a given check-in, optionally limited to some paths and enriched with age, status or time ordering.',
843
+ inputSchema: z.object({
844
+ paths: filesParam,
845
+ revision: z.string().min(1).optional().describe('Check-in to list (-r) instead of the check-out contents.'),
846
+ age: flag('Show when each file was committed (--age).'),
847
+ verbose: flag('Show extra information, including change status (--verbose).'),
848
+ time_order: flag('Sort by time instead of name (-t).'),
849
+ hash: flag('Verify file status by hashing instead of size and mtime (--hash).'),
850
+ workspace: workspaceParam,
851
+ }),
852
+ annotations: { readOnlyHint: true },
853
+ }, async ({ paths, revision, age, verbose, time_order, hash, workspace }) => {
854
+ const args = ['ls'];
855
+ pushOption(args, '-r', revision);
856
+ if (age)
857
+ args.push('--age');
858
+ if (verbose)
859
+ args.push('-v');
860
+ if (time_order)
861
+ args.push('-t');
862
+ if (hash)
863
+ args.push('--hash');
864
+ if (paths && paths.length > 0)
865
+ args.push(...paths);
866
+ return renderOutcome(await runFossil(args, { workspace }));
867
+ });
868
+ server.registerTool('fossil_search', {
869
+ title: 'Search timeline',
870
+ description: 'Search check-in and other timeline comments for every given word and print the best matches.',
871
+ inputSchema: z.object({
872
+ pattern: z.string().min(1).describe('Words to look for; all of them must match.'),
873
+ all: flag('Print every match instead of only the best scoring ones (--all).'),
874
+ limit: z.number().int().min(1).optional().describe('Maximum number of matches (-n).'),
875
+ width: z.number().int().min(0).optional().describe('Output width in columns; 0 means no wrapping (-W).'),
876
+ workspace: workspaceParam,
877
+ }),
878
+ annotations: { readOnlyHint: true },
879
+ }, async ({ pattern, all, limit, width, workspace }) => {
880
+ const args = ['search'];
881
+ if (all)
882
+ args.push('-a');
883
+ if (limit !== undefined)
884
+ args.push('-n', String(limit));
885
+ if (width !== undefined)
886
+ args.push('-W', String(width));
887
+ args.push(pattern);
888
+ const outcome = await runFossil(args, { workspace });
889
+ // fossil reports an empty result set as "+++ no more data (0) +++".
890
+ if (outcome.ok && /^\+{3} no more data \(0\) \+{3}$/.test(outcome.stdout.trim())) {
891
+ return { content: [{ type: 'text', text: 'No matches.' }] };
892
+ }
893
+ return renderOutcome(outcome, { emptyText: 'No matches.' });
894
+ });
895
+ server.registerTool('fossil_artifact', {
896
+ title: 'Artifact content',
897
+ description: 'Print the raw content of an artifact by its hash, such as the manifest of a check-in or the blob of a file version.',
898
+ inputSchema: z.object({
899
+ artifact: z.string().min(1).describe('Artifact hash, or a unique prefix of it.'),
900
+ workspace: workspaceParam,
901
+ }),
902
+ annotations: { readOnlyHint: true },
903
+ }, async ({ artifact, workspace }) => renderOutcome(await runFossil(['artifact', artifact], { workspace })));
904
+ server.registerTool('fossil_describe', {
905
+ title: 'Describe version',
906
+ description: 'Describe a version as the closest non-propagating tag, the commit count since it and the short hash, or just the hash when no tag applies.',
907
+ inputSchema: z.object({
908
+ version: z.string().min(1).optional().describe('Version to describe; defaults to the checked-out version.'),
909
+ digits: z.number().int().min(4).max(40).optional().describe('Hex digits of the hash to show (--digits).'),
910
+ dirty: flag('Also show whether there are uncommitted changes (--dirty).'),
911
+ long: flag('Always show tag, count and hash, even when they collapse (--long).'),
912
+ match: z.string().min(1).optional().describe('Only consider non-propagating tags matching this glob (--match).'),
913
+ workspace: workspaceParam,
914
+ }),
915
+ annotations: { readOnlyHint: true },
916
+ }, async ({ version, digits, dirty, long, match, workspace }) => {
917
+ const args = ['describe'];
918
+ if (version)
919
+ args.push(version);
920
+ if (digits !== undefined)
921
+ args.push('--digits', String(digits));
922
+ if (dirty)
923
+ args.push('--dirty');
924
+ if (long)
925
+ args.push('--long');
926
+ if (match)
927
+ args.push('--match', match);
928
+ return renderOutcome(await runFossil(args, { workspace }));
929
+ });
930
+ server.registerTool('fossil_archive', {
931
+ title: 'Archive check-in',
932
+ description: 'Generate a tarball or ZIP archive of a check-in, or list the files the archive would contain.',
933
+ inputSchema: z.object({
934
+ format: z.enum(['tarball', 'zip']).default('tarball').describe('Archive format.'),
935
+ version: z.string().min(1).default('tip').describe('Check-in to archive.'),
936
+ output: z
937
+ .string()
938
+ .min(1)
939
+ .optional()
940
+ .describe('Archive path, relative to the workspace. Omit to list the files instead.'),
941
+ name: z.string().min(1).optional().describe('Top-level directory name inside the archive (--name).'),
942
+ exclude: z.array(z.string().min(1)).optional().describe('Glob patterns to leave out (-X).'),
943
+ include: z.array(z.string().min(1)).optional().describe('Glob patterns to keep (--include).'),
944
+ workspace: workspaceParam,
945
+ }),
946
+ annotations: {},
947
+ }, async ({ format, version, output, name, exclude, include, workspace }) => {
948
+ const args = [format, version, output ?? '/dev/null'];
949
+ if (!output)
950
+ args.push('-l');
951
+ pushOption(args, '--name', name);
952
+ if (exclude && exclude.length > 0)
953
+ args.push('-X', globList(exclude));
954
+ if (include && include.length > 0)
955
+ args.push('--include', globList(include));
956
+ const outcome = await runFossil(args, { workspace });
957
+ if (outcome.ok && output) {
958
+ return renderOutcome({ ...outcome, stdout: `Wrote ${output} from ${version}.` });
959
+ }
960
+ return renderOutcome(outcome, { emptyText: 'The archive would be empty.' });
961
+ });
962
+ server.registerTool('fossil_unversioned', {
963
+ title: 'Unversioned files',
964
+ description: 'List, print, add, remove or timestamp the unversioned files the repository keeps without history.',
965
+ inputSchema: z.object({
966
+ action: z
967
+ .enum(['list', 'cat', 'add', 'remove', 'touch'])
968
+ .default('list')
969
+ .describe('list: show them; cat: print content; add/remove: change the set; touch: update timestamps.'),
970
+ files: filesParam.describe('Files the action applies to.'),
971
+ glob: z.string().min(1).optional().describe('Only match names by this glob (--glob).'),
972
+ like: z.string().min(1).optional().describe('Only match names like this pattern (--like).'),
973
+ workspace: workspaceParam,
974
+ }),
975
+ annotations: {},
976
+ }, async ({ action, files, glob, like, workspace }) => {
977
+ const args = ['unversioned', action];
978
+ pushOption(args, '--glob', glob);
979
+ pushOption(args, '--like', like);
980
+ if (files && files.length > 0)
981
+ args.push(...files);
982
+ const needsFiles = action !== 'list' && !(files && files.length > 0) && !glob && !like;
983
+ if (needsFiles) {
984
+ return {
985
+ isError: true,
986
+ content: [{ type: 'text', text: `ERROR: action '${action}' needs \`files\`, \`glob\` or \`like\`.` }],
987
+ };
988
+ }
989
+ return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No unversioned files.' });
990
+ });
991
+ server.registerTool('fossil_touch', {
992
+ title: 'Touch files',
993
+ description: "Update file timestamps so that Fossil's size and mtime based change detection sees the files again.",
994
+ inputSchema: z.object({
995
+ files: filesParam.describe('Files or glob patterns to touch. Omit to touch every managed file.'),
996
+ mode: z
997
+ .enum(['now', 'checkin', 'checkout'])
998
+ .default('now')
999
+ .describe('now: current time; checkin: last check-in that modified each file; checkout: the checked-out version.'),
1000
+ workspace: workspaceParam,
1001
+ }),
1002
+ annotations: {},
1003
+ }, async ({ files, mode, workspace }) => {
1004
+ const args = ['touch'];
1005
+ if (mode === 'checkin')
1006
+ args.push('-c');
1007
+ else if (mode === 'checkout')
1008
+ args.push('-C');
1009
+ if (files && files.length > 0)
1010
+ args.push(...files);
1011
+ return renderOutcome(await runFossil(args, { workspace }));
1012
+ });
1013
+ server.registerTool('fossil_amend', {
1014
+ title: 'Amend check-in',
1015
+ description: 'Change the comment, author, date, tags, branch or visibility of an existing check-in.',
1016
+ inputSchema: z.object({
1017
+ checkin: z.string().min(1).describe('Check-in to amend, such as tip or a hash.'),
1018
+ comment: z.string().min(1).optional().describe('Replacement comment (-m).'),
1019
+ author: z.string().min(1).optional().describe('Replacement author (--author).'),
1020
+ date: z.string().min(1).optional().describe('Replacement check-in time, or now (--date).'),
1021
+ tag: z.array(z.string().min(1)).optional().describe('Tags to add (--tag, repeatable).'),
1022
+ cancel: z.array(z.string().min(1)).optional().describe('Tags to remove (--cancel, repeatable).'),
1023
+ branch: z.string().min(1).optional().describe('Start a branch at this check-in (--branch).'),
1024
+ hide: flag('Hide the branch starting at this check-in (--hide).'),
1025
+ close: flag('Mark this leaf as closed (--close).'),
1026
+ dry_run: flag('Print the control artifact without changing anything (-n).'),
1027
+ workspace: workspaceParam,
1028
+ }),
1029
+ annotations: { destructiveHint: true },
1030
+ }, async ({ checkin, comment, author, date, tag, cancel, branch, hide, close, dry_run, workspace }) => {
1031
+ const args = ['amend', checkin];
1032
+ if (dry_run)
1033
+ args.push('-n');
1034
+ pushOption(args, '-m', comment);
1035
+ pushOption(args, '--author', author);
1036
+ pushOption(args, '--date', date);
1037
+ for (const value of tag ?? [])
1038
+ args.push('--tag', value);
1039
+ for (const value of cancel ?? [])
1040
+ args.push('--cancel', value);
1041
+ pushOption(args, '--branch', branch);
1042
+ if (hide)
1043
+ args.push('--hide');
1044
+ if (close)
1045
+ args.push('--close');
1046
+ const changed = comment || author || date || branch || hide || close || (tag?.length ?? 0) > 0 || (cancel?.length ?? 0) > 0;
1047
+ if (!changed) {
1048
+ return {
1049
+ isError: true,
1050
+ content: [
1051
+ {
1052
+ type: 'text',
1053
+ text: 'ERROR: pass at least one of `comment`, `author`, `date`, `tag`, `cancel`, `branch`, `hide` or `close`.',
1054
+ },
1055
+ ],
1056
+ };
1057
+ }
1058
+ return renderOutcome(await runFossil(args, { workspace }));
1059
+ });
1060
+ server.registerTool('fossil_patch', {
1061
+ title: 'Binary patch',
1062
+ description: 'Create a binary patch from uncommitted changes, show it as a diff, or apply it to the check-out.',
1063
+ inputSchema: z.object({
1064
+ action: z.enum(['create', 'apply', 'diff']).default('create').describe('create, apply or show the patch.'),
1065
+ file: z.string().min(1).describe('Patch file path; relative paths resolve against the workspace.'),
1066
+ force: flag('Overwrite an existing patch, or apply over unsaved changes (-f).'),
1067
+ dry_run: flag('Print what would happen without doing it (-n).'),
1068
+ verbose: flag('Explain what happens (-v).'),
1069
+ workspace: workspaceParam,
391
1070
  }),
392
1071
  annotations: { destructiveHint: true },
393
- }, async ({ dry_run, cwd }) => renderOutcome(await runFossil(dry_run ? ['undo', '-n'] : ['undo'], { cwd })));
1072
+ }, async ({ action, file, force, dry_run, verbose, workspace }) => {
1073
+ const args = ['patch', action];
1074
+ if (force)
1075
+ args.push('-f');
1076
+ if (dry_run)
1077
+ args.push('-n');
1078
+ if (verbose)
1079
+ args.push('-v');
1080
+ args.push(file);
1081
+ return renderOutcome(await runFossil(args, { workspace }));
1082
+ });
1083
+ server.registerTool('fossil_bisect', {
1084
+ title: 'Bisect',
1085
+ description: 'Search the history for the check-in that introduced or fixed a problem: mark versions good/bad/skip, ask for the next candidate or review the log. WARNING: `run` executes the given command repeatedly; obtain user confirmation first.',
1086
+ inputSchema: z.object({
1087
+ action: z
1088
+ .enum(['good', 'bad', 'skip', 'next', 'log', 'chart', 'options', 'reset', 'run'])
1089
+ .describe('Bisect subcommand.'),
1090
+ version: z.string().min(1).optional().describe('Version to mark (good/bad/skip); omit for the current check-out.'),
1091
+ command: z
1092
+ .string()
1093
+ .min(1)
1094
+ .optional()
1095
+ .describe('Command that decides good (exit 0), skip (125) or bad (anything else); required by `run`.'),
1096
+ interactive: flag('Ask for the decision after each step instead of using the exit code (--interactive).'),
1097
+ option: z.string().min(1).optional().describe('Bisect option name for `options`.'),
1098
+ value: z.string().min(1).optional().describe('New value for `option`.'),
1099
+ workspace: workspaceParam,
1100
+ }),
1101
+ annotations: { idempotentHint: false },
1102
+ }, async ({ action, version, command, interactive, option, value, workspace }) => {
1103
+ if (action === 'run' && !command) {
1104
+ return {
1105
+ isError: true,
1106
+ content: [{ type: 'text', text: 'ERROR: `run` requires `command`.' }],
1107
+ };
1108
+ }
1109
+ const args = ['bisect', action];
1110
+ if (action === 'run') {
1111
+ if (interactive)
1112
+ args.push('-i');
1113
+ args.push(command);
1114
+ }
1115
+ else if (action === 'options') {
1116
+ if (option)
1117
+ args.push(option);
1118
+ if (option && value)
1119
+ args.push(value);
1120
+ }
1121
+ else if (version) {
1122
+ args.push(version);
1123
+ }
1124
+ return renderOutcome(await runFossil(args, { workspace }));
1125
+ });
1126
+ server.registerTool('fossil_sql', {
1127
+ title: 'SQL query',
1128
+ description: 'Run a read-only query against the repository database and return the rows as a table. Pass `limit` inside the SQL, e.g. `SELECT ... LIMIT 20`.',
1129
+ inputSchema: z.object({
1130
+ query: z.string().min(1).describe('SQL statement, e.g. "SELECT name FROM blob LIMIT 5".'),
1131
+ repository: z
1132
+ .string()
1133
+ .min(1)
1134
+ .optional()
1135
+ .describe('Repository database to query instead of the one of the check-out (-R).'),
1136
+ workspace: workspaceParam,
1137
+ }),
1138
+ annotations: { readOnlyHint: true },
1139
+ }, async ({ query, repository, workspace }) => {
1140
+ const trimmed = query.trim().replace(/;+\s*$/, '');
1141
+ if (!/^(select|with|pragma|explain)\b/i.test(trimmed)) {
1142
+ return {
1143
+ isError: true,
1144
+ content: [
1145
+ {
1146
+ type: 'text',
1147
+ text: 'ERROR: the query must start with SELECT, WITH, PRAGMA or EXPLAIN.',
1148
+ },
1149
+ ],
1150
+ };
1151
+ }
1152
+ const result = await runSql(trimmed, { workspace, readonly: true, repository });
1153
+ if (!result.ok)
1154
+ return { isError: true, content: [{ type: 'text', text: result.error }] };
1155
+ if (result.rows.length === 0)
1156
+ return { content: [{ type: 'text', text: 'No rows.' }] };
1157
+ const columns = Object.keys(result.rows[0] ?? {});
1158
+ const cell = (value) => {
1159
+ if (value === null || value === undefined)
1160
+ return 'NULL';
1161
+ if (typeof value === 'object')
1162
+ return JSON.stringify(value);
1163
+ return String(value);
1164
+ };
1165
+ const lines = [columns.join('\t'), ...result.rows.map((row) => columns.map((column) => cell(row[column])).join('\t'))];
1166
+ return {
1167
+ content: [
1168
+ {
1169
+ type: 'text',
1170
+ text: truncateOutput(`${lines.join('\n')}\n\n${result.rows.length} row(s).`),
1171
+ },
1172
+ ],
1173
+ };
1174
+ });
394
1175
  }