@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.
- package/README.md +136 -123
- package/dist/capabilities.js +6 -6
- package/dist/cli.js +38 -33
- package/dist/config.js +7 -24
- package/dist/core/fossil.js +65 -77
- package/dist/core/gitignore.js +136 -0
- package/dist/core/sql.js +3 -1
- package/dist/index.js +6 -3
- package/dist/prompts.js +167 -0
- package/dist/server.js +5 -3
- package/dist/tools/admin.js +489 -82
- package/dist/tools/chat.js +16 -16
- package/dist/tools/common.js +4 -3
- package/dist/tools/forum.js +21 -18
- package/dist/tools/tickets.js +32 -10
- package/dist/tools/version-control.js +1261 -102
- package/dist/tools/wiki.js +17 -17
- package/docs/README.md +31 -0
- package/docs/admin.md +666 -0
- package/docs/chat.md +152 -0
- package/docs/forum.md +146 -0
- package/docs/prompts.md +39 -0
- package/docs/tickets.md +179 -0
- package/docs/vcs.md +1182 -0
- package/docs/wiki.md +140 -0
- package/package.json +9 -6
|
@@ -1,30 +1,93 @@
|
|
|
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 {
|
|
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',
|
|
8
18
|
description: 'Show the change set of the check-out (modified/added/deleted files) plus the list of untracked files. ' +
|
|
9
19
|
'Both queries run in parallel.',
|
|
10
20
|
inputSchema: z.object({
|
|
11
|
-
dotfiles: flag('Include dot-files in the untracked (
|
|
12
|
-
brief: flag('
|
|
13
|
-
ignore: z.string().min(1).optional().describe('Comma-separated glob patterns of extra files to ignore.'),
|
|
14
|
-
|
|
21
|
+
dotfiles: flag('Include dot-files in the change and untracked lists (--dotfiles).'),
|
|
22
|
+
brief: flag('List only the changed file names (fossil changes).'),
|
|
23
|
+
ignore: z.string().min(1).optional().describe('Comma-separated glob patterns of extra files to ignore (--ignore).'),
|
|
24
|
+
select: z
|
|
25
|
+
.array(z.enum([
|
|
26
|
+
'edited',
|
|
27
|
+
'updated',
|
|
28
|
+
'changed',
|
|
29
|
+
'missing',
|
|
30
|
+
'added',
|
|
31
|
+
'deleted',
|
|
32
|
+
'renamed',
|
|
33
|
+
'conflict',
|
|
34
|
+
'meta',
|
|
35
|
+
'unchanged',
|
|
36
|
+
'all',
|
|
37
|
+
'differ',
|
|
38
|
+
'extra',
|
|
39
|
+
]))
|
|
40
|
+
.optional()
|
|
41
|
+
.describe('Report only these change groups, e.g. ["changed", "extra"] (--edited, --added, --all, --differ, …). ' +
|
|
42
|
+
'Omit to report the default change set plus untracked files.'),
|
|
43
|
+
classify: flag('Start each line with the change type; changes mode only (--classify).'),
|
|
44
|
+
hash: flag('Verify file status by hashing instead of size and mtime (--hash).'),
|
|
45
|
+
header: flag('Print the repository name above a non-empty report; changes mode only (--header).'),
|
|
46
|
+
verbose: flag('Print "(none)" when the report is empty; changes mode only (-v).'),
|
|
47
|
+
abs_paths: flag('Print absolute pathnames (--abs-paths).'),
|
|
48
|
+
rel_paths: flag('Print pathnames relative to the current directory (--rel-paths).'),
|
|
49
|
+
workspace: workspaceParam,
|
|
15
50
|
}),
|
|
16
51
|
annotations: { readOnlyHint: true },
|
|
17
|
-
}, async ({ dotfiles, brief, ignore,
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
52
|
+
}, async ({ dotfiles, brief, ignore, select, classify, hash, header, verbose, abs_paths, rel_paths, workspace, }) => {
|
|
53
|
+
const command = brief ? 'changes' : 'status';
|
|
54
|
+
const args = [command];
|
|
55
|
+
if (dotfiles)
|
|
56
|
+
args.push('--dotfiles');
|
|
57
|
+
pushOption(args, '--ignore', ignore);
|
|
58
|
+
for (const group of select ?? [])
|
|
59
|
+
args.push(`--${group}`);
|
|
60
|
+
if (command === 'changes') {
|
|
61
|
+
if (classify)
|
|
62
|
+
args.push('--classify');
|
|
63
|
+
if (header)
|
|
64
|
+
args.push('--header');
|
|
65
|
+
if (verbose)
|
|
66
|
+
args.push('-v');
|
|
67
|
+
}
|
|
68
|
+
if (hash)
|
|
69
|
+
args.push('--hash');
|
|
70
|
+
if (abs_paths)
|
|
71
|
+
args.push('--abs-paths');
|
|
72
|
+
if (rel_paths)
|
|
73
|
+
args.push('--rel-paths');
|
|
74
|
+
const includesExtra = (select ?? []).some((group) => group === 'extra' || group === 'differ');
|
|
75
|
+
if (select?.length && includesExtra) {
|
|
76
|
+
return renderSections([{ title: 'STATUS', outcome: await runFossil(args, { workspace }) }]);
|
|
77
|
+
}
|
|
21
78
|
const extraArgs = ['extra'];
|
|
22
79
|
if (dotfiles)
|
|
23
80
|
extraArgs.push('--dotfiles');
|
|
24
81
|
pushOption(extraArgs, '--ignore', ignore);
|
|
82
|
+
if (hash)
|
|
83
|
+
extraArgs.push('--hash');
|
|
84
|
+
if (abs_paths)
|
|
85
|
+
extraArgs.push('--abs-paths');
|
|
86
|
+
if (rel_paths)
|
|
87
|
+
extraArgs.push('--rel-paths');
|
|
25
88
|
const [status, extra] = await Promise.all([
|
|
26
|
-
runFossil(
|
|
27
|
-
runFossil(extraArgs, {
|
|
89
|
+
runFossil(args, { workspace }),
|
|
90
|
+
runFossil(extraArgs, { workspace }),
|
|
28
91
|
]);
|
|
29
92
|
return renderSections([
|
|
30
93
|
{ title: 'STATUS', outcome: status },
|
|
@@ -39,63 +102,131 @@ export function registerVersionControlTools(server) {
|
|
|
39
102
|
to_version: z.string().min(1).optional().describe('Ending check-in/revision (--to).'),
|
|
40
103
|
files: filesParam.describe('Optional list of files to diff.'),
|
|
41
104
|
branch: z.string().min(1).optional().describe('Diff across a branch (--branch).'),
|
|
105
|
+
checkin: z.string().min(1).optional().describe('Diff all changes introduced by this check-in (-ci).'),
|
|
42
106
|
brief: flag('Only list the changed file names (--brief).'),
|
|
107
|
+
stat: flag('Show only the number of added and deleted lines (--numstat).'),
|
|
108
|
+
context: z.number().int().min(0).max(100).optional().describe('Lines of context around each change (-c).'),
|
|
109
|
+
side_by_side: flag('Print a side-by-side diff (-y).'),
|
|
110
|
+
verbose: flag('Print the complete text of added or deleted files (-v).'),
|
|
111
|
+
undo: flag('Diff against the undo buffer (--undo).'),
|
|
43
112
|
ignore_whitespace: flag('Ignore whitespace-only changes (-w).'),
|
|
44
|
-
|
|
113
|
+
ignore_trailing_space: flag('Ignore changes to end-of-line whitespace (-Z).'),
|
|
114
|
+
internal: flag('Use the internal diff logic (-i).'),
|
|
115
|
+
unified: flag('Print a unified diff (--unified).'),
|
|
116
|
+
versions_header: flag('Show the compared versions in the diff header (-h).'),
|
|
117
|
+
json: flag('Print the diff as JSON (--json).'),
|
|
118
|
+
width: z.number().int().min(20).optional().describe('Width of side-by-side lines (-W).'),
|
|
119
|
+
workspace: workspaceParam,
|
|
45
120
|
}),
|
|
46
121
|
annotations: { readOnlyHint: true },
|
|
47
|
-
}, async ({ from_version, to_version, files, branch, brief, ignore_whitespace,
|
|
122
|
+
}, async ({ from_version, to_version, files, branch, checkin, brief, stat, context: contextLines, side_by_side, verbose, undo, ignore_whitespace, ignore_trailing_space, internal, unified, versions_header, json, width, workspace, }) => {
|
|
48
123
|
const args = ['diff'];
|
|
49
124
|
pushOption(args, '--from', from_version);
|
|
50
125
|
pushOption(args, '--to', to_version);
|
|
51
126
|
pushOption(args, '--branch', branch);
|
|
127
|
+
pushOption(args, '-ci', checkin);
|
|
52
128
|
if (brief)
|
|
53
129
|
args.push('--brief');
|
|
130
|
+
if (stat)
|
|
131
|
+
args.push('--numstat');
|
|
132
|
+
if (contextLines !== undefined)
|
|
133
|
+
args.push('-c', String(contextLines));
|
|
134
|
+
if (side_by_side)
|
|
135
|
+
args.push('-y');
|
|
136
|
+
if (verbose)
|
|
137
|
+
args.push('-v');
|
|
138
|
+
if (undo)
|
|
139
|
+
args.push('--undo');
|
|
54
140
|
if (ignore_whitespace)
|
|
55
141
|
args.push('-w');
|
|
142
|
+
if (ignore_trailing_space)
|
|
143
|
+
args.push('-Z');
|
|
144
|
+
if (internal)
|
|
145
|
+
args.push('-i');
|
|
146
|
+
if (unified)
|
|
147
|
+
args.push('--unified');
|
|
148
|
+
if (versions_header)
|
|
149
|
+
args.push('-h');
|
|
150
|
+
if (json)
|
|
151
|
+
args.push('--json');
|
|
152
|
+
if (width !== undefined)
|
|
153
|
+
args.push('-W', String(width));
|
|
56
154
|
if (files?.length)
|
|
57
155
|
args.push(...files);
|
|
58
|
-
return renderOutcome(await runFossil(args, {
|
|
156
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No differences found.' });
|
|
59
157
|
});
|
|
60
158
|
server.registerTool('fossil_cat', {
|
|
61
159
|
title: 'Cat file revision',
|
|
62
|
-
description: 'Print the content of a file at a given revision
|
|
160
|
+
description: 'Print the content of a file at a given revision.',
|
|
63
161
|
inputSchema: z.object({
|
|
64
162
|
file: z.string().min(1).describe('File path/name inside the repository.'),
|
|
65
163
|
revision: z.string().min(1).optional().describe('Check-in or revision (-r). Defaults to the checked-out version.'),
|
|
66
|
-
|
|
164
|
+
workspace: workspaceParam,
|
|
67
165
|
}),
|
|
68
166
|
annotations: { readOnlyHint: true },
|
|
69
|
-
}, async ({ file, revision,
|
|
167
|
+
}, async ({ file, revision, workspace }) => {
|
|
70
168
|
const args = ['cat', file];
|
|
71
169
|
pushOption(args, '-r', revision);
|
|
72
|
-
return renderOutcome(await runFossil(args, {
|
|
170
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
73
171
|
});
|
|
74
172
|
server.registerTool('fossil_finfo', {
|
|
75
173
|
title: 'File history',
|
|
76
|
-
description: 'Show the
|
|
174
|
+
description: 'Show the change history of one file, or switch to the artifact facts, status line or file content view.',
|
|
77
175
|
inputSchema: z.object({
|
|
78
176
|
file: z.string().min(1).describe('File to inspect.'),
|
|
79
|
-
|
|
80
|
-
|
|
177
|
+
mode: z
|
|
178
|
+
.enum(['log', 'id', 'status', 'print'])
|
|
179
|
+
.default('log')
|
|
180
|
+
.describe('log: revisions with comments; id: artifact facts; status: one-line status; print: file content.'),
|
|
181
|
+
brief: flag('One line per revision, in log mode (-b).'),
|
|
182
|
+
limit: z.number().int().min(1).max(1000).default(20).describe('Number of revisions to show, in log mode (-n).'),
|
|
183
|
+
offset: z.number().int().min(0).optional().describe('Revisions to skip, in log mode (--offset).'),
|
|
184
|
+
revision: z.string().min(1).optional().describe('Revision the id and print modes describe (-r).'),
|
|
185
|
+
verbose: flag('In id mode, show every check-in that uses the file (-v).'),
|
|
186
|
+
workspace: workspaceParam,
|
|
81
187
|
}),
|
|
82
188
|
annotations: { readOnlyHint: true },
|
|
83
|
-
}, async ({ file,
|
|
189
|
+
}, async ({ file, mode, brief, limit, offset, revision, verbose, workspace }) => {
|
|
190
|
+
const args = ['finfo'];
|
|
191
|
+
if (mode === 'id') {
|
|
192
|
+
args.push('-i');
|
|
193
|
+
pushOption(args, '-r', revision);
|
|
194
|
+
if (verbose)
|
|
195
|
+
args.push('-v');
|
|
196
|
+
}
|
|
197
|
+
else if (mode === 'status') {
|
|
198
|
+
args.push('-s');
|
|
199
|
+
}
|
|
200
|
+
else if (mode === 'print') {
|
|
201
|
+
args.push('-p');
|
|
202
|
+
pushOption(args, '-r', revision);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
if (brief)
|
|
206
|
+
args.push('-b');
|
|
207
|
+
if (limit !== undefined)
|
|
208
|
+
args.push('-n', String(limit));
|
|
209
|
+
if (offset !== undefined)
|
|
210
|
+
args.push('--offset', String(offset));
|
|
211
|
+
}
|
|
212
|
+
args.push(file);
|
|
213
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
214
|
+
});
|
|
84
215
|
server.registerTool('fossil_revert', {
|
|
85
216
|
title: 'Revert changes',
|
|
86
217
|
description: 'Revert uncommitted local changes. Destructive: the workspace is restored from the repository.',
|
|
87
218
|
inputSchema: z.object({
|
|
88
219
|
files: filesParam.describe('Files to revert. Omit to revert the whole check-out.'),
|
|
89
220
|
revision: z.string().min(1).optional().describe('Revision to revert to (-r).'),
|
|
90
|
-
|
|
221
|
+
workspace: workspaceParam,
|
|
91
222
|
}),
|
|
92
223
|
annotations: { destructiveHint: true },
|
|
93
|
-
}, async ({ files, revision,
|
|
224
|
+
}, async ({ files, revision, workspace }) => {
|
|
94
225
|
const args = ['revert'];
|
|
95
226
|
pushOption(args, '-r', revision);
|
|
96
227
|
if (files?.length)
|
|
97
228
|
args.push(...files);
|
|
98
|
-
return renderOutcome(await runFossil(args, {
|
|
229
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
99
230
|
});
|
|
100
231
|
server.registerTool('fossil_stash', {
|
|
101
232
|
title: 'Stash',
|
|
@@ -107,9 +238,9 @@ export function registerVersionControlTools(server) {
|
|
|
107
238
|
.describe('Stash sub-command.'),
|
|
108
239
|
comment: z.string().optional().describe('Comment used by save/snapshot (-m).'),
|
|
109
240
|
stash_id: z.string().min(1).optional().describe('Stash id used by pop/apply/drop/diff.'),
|
|
110
|
-
|
|
241
|
+
workspace: workspaceParam,
|
|
111
242
|
}),
|
|
112
|
-
}, async ({ action, comment, stash_id,
|
|
243
|
+
}, async ({ action, comment, stash_id, workspace }) => {
|
|
113
244
|
const args = ['stash', action ?? 'ls'];
|
|
114
245
|
if ((action === 'save' || action === 'snapshot') && comment !== undefined) {
|
|
115
246
|
args.push('-m', comment);
|
|
@@ -119,42 +250,95 @@ export function registerVersionControlTools(server) {
|
|
|
119
250
|
if (stashId)
|
|
120
251
|
args.push(stashId);
|
|
121
252
|
}
|
|
122
|
-
return renderOutcome(await runFossil(args, {
|
|
253
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No stashed changes.' });
|
|
123
254
|
});
|
|
124
255
|
server.registerTool('fossil_tag', {
|
|
125
256
|
title: 'Tags',
|
|
126
|
-
description: 'List, add or cancel Fossil tags (symbolic labels attached to check-ins).',
|
|
257
|
+
description: 'List, find, add or cancel Fossil tags (symbolic labels attached to check-ins and other artifacts).',
|
|
127
258
|
inputSchema: z.object({
|
|
128
|
-
action: z.enum(['ls', 'add', 'cancel']).default('ls').describe('Tag sub-command.'),
|
|
129
|
-
tag_name: z.string().min(1).optional().describe('Tag name (required for add/cancel).'),
|
|
259
|
+
action: z.enum(['ls', 'find', 'add', 'cancel']).default('ls').describe('Tag sub-command.'),
|
|
260
|
+
tag_name: z.string().min(1).optional().describe('Tag name (required for find/add/cancel).'),
|
|
130
261
|
checkin: z
|
|
131
262
|
.string()
|
|
132
263
|
.min(1)
|
|
133
264
|
.optional()
|
|
134
|
-
.describe('Target check-in (required for add; defaults to tip for cancel).'),
|
|
135
|
-
|
|
265
|
+
.describe('Target check-in or artifact (required for add; defaults to tip for cancel, optional for list).'),
|
|
266
|
+
raw: flag('Use the raw tag name instead of a branch name (--raw).'),
|
|
267
|
+
propagate: flag('Propagate the tag to all descendants of the artifact; used with `add` (--propagate).'),
|
|
268
|
+
date_override: z
|
|
269
|
+
.string()
|
|
270
|
+
.min(1)
|
|
271
|
+
.optional()
|
|
272
|
+
.describe('Tag timestamp to store, e.g. "2026-11-17 12:00:00"; used with `add`/`cancel` (--date-override).'),
|
|
273
|
+
user_override: z
|
|
274
|
+
.string()
|
|
275
|
+
.min(1)
|
|
276
|
+
.optional()
|
|
277
|
+
.describe('Login to record as the tag author; used with `add`/`cancel` (--user-override).'),
|
|
278
|
+
dry_run: flag('Print the control artifact without writing it; used with `add`/`cancel` (-n).'),
|
|
279
|
+
type: z
|
|
280
|
+
.enum(['ci', 'w', 'e', 'f', 't'])
|
|
281
|
+
.optional()
|
|
282
|
+
.describe('Artifact type to match; used with `find` (-t).'),
|
|
283
|
+
limit: z.number().int().min(1).optional().describe('Maximum number of results; used with `find` (-n).'),
|
|
284
|
+
tagtype: z
|
|
285
|
+
.enum(['propagated', 'singleton', 'cancel'])
|
|
286
|
+
.optional()
|
|
287
|
+
.describe('List only tags of this type; used with `ls` (--tagtype).'),
|
|
288
|
+
inverse: flag('Invert the `tagtype` filter; used with `ls` (-v).'),
|
|
289
|
+
prefix: z.string().min(1).optional().describe('List only tags with this prefix; used with `ls` (--prefix).'),
|
|
290
|
+
workspace: workspaceParam,
|
|
136
291
|
}),
|
|
137
292
|
annotations: { idempotentHint: true },
|
|
138
|
-
}, async ({ action, tag_name, checkin,
|
|
293
|
+
}, async ({ action, tag_name, checkin, raw, propagate, date_override, user_override, dry_run, type, limit, tagtype, inverse, prefix, workspace, }) => {
|
|
139
294
|
const name = clean(tag_name);
|
|
140
295
|
const target = clean(checkin);
|
|
141
|
-
|
|
296
|
+
const subcommand = action ?? 'ls';
|
|
297
|
+
if (subcommand === 'add' && (!name || !target)) {
|
|
142
298
|
return { content: [{ type: 'text', text: "ERROR: 'tag_name' and 'checkin' are required for action 'add'." }], isError: true };
|
|
143
299
|
}
|
|
144
|
-
if (
|
|
145
|
-
return {
|
|
300
|
+
if ((subcommand === 'cancel' || subcommand === 'find') && !name) {
|
|
301
|
+
return {
|
|
302
|
+
content: [{ type: 'text', text: `ERROR: 'tag_name' is required for action '${subcommand}'.` }],
|
|
303
|
+
isError: true,
|
|
304
|
+
};
|
|
146
305
|
}
|
|
147
|
-
const args = ['tag',
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
306
|
+
const args = ['tag', subcommand];
|
|
307
|
+
if (subcommand === 'ls') {
|
|
308
|
+
if (raw)
|
|
309
|
+
args.push('--raw');
|
|
310
|
+
pushOption(args, '--tagtype', tagtype);
|
|
311
|
+
if (inverse)
|
|
312
|
+
args.push('-v');
|
|
313
|
+
pushOption(args, '--prefix', prefix);
|
|
314
|
+
if (target)
|
|
315
|
+
args.push(target);
|
|
152
316
|
}
|
|
153
|
-
else if (
|
|
317
|
+
else if (subcommand === 'find') {
|
|
318
|
+
if (raw)
|
|
319
|
+
args.push('--raw');
|
|
320
|
+
pushOption(args, '-t', type);
|
|
321
|
+
if (limit !== undefined)
|
|
322
|
+
args.push('-n', String(limit));
|
|
154
323
|
if (name)
|
|
324
|
+
args.push(name);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
if (raw)
|
|
328
|
+
args.push('--raw');
|
|
329
|
+
if (subcommand === 'add' && propagate)
|
|
330
|
+
args.push('--propagate');
|
|
331
|
+
pushOption(args, '--date-override', date_override);
|
|
332
|
+
pushOption(args, '--user-override', user_override);
|
|
333
|
+
if (dry_run)
|
|
334
|
+
args.push('-n');
|
|
335
|
+
// `fossil tag cancel` always needs an artifact id; 'tip' is the sane default.
|
|
336
|
+
if (subcommand === 'add' && name && target)
|
|
337
|
+
args.push(name, target);
|
|
338
|
+
else if (subcommand === 'cancel' && name)
|
|
155
339
|
args.push(name, target ?? 'tip');
|
|
156
340
|
}
|
|
157
|
-
return renderOutcome(await runFossil(args, {
|
|
341
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No tags.' });
|
|
158
342
|
});
|
|
159
343
|
server.registerTool('fossil_addremove', {
|
|
160
344
|
title: 'Add/remove scan',
|
|
@@ -164,63 +348,124 @@ export function registerVersionControlTools(server) {
|
|
|
164
348
|
ignore: z.string().min(1).optional().describe('Comma-separated glob patterns to ignore (--ignore).'),
|
|
165
349
|
clean: z.string().min(1).optional().describe('Comma-separated glob patterns of clean files to ignore (--clean).'),
|
|
166
350
|
reset: flag('Reset the ADDED/DELETED state of the check-out instead (--reset).'),
|
|
167
|
-
|
|
351
|
+
dry_run: flag('Show what would be staged without changing anything (-n/--dry-run).'),
|
|
352
|
+
case_sensitive: z
|
|
353
|
+
.boolean()
|
|
354
|
+
.optional()
|
|
355
|
+
.describe('Override the case-sensitive setting (--case-sensitive).'),
|
|
356
|
+
verbose: flag('Report each file while resetting, with reset: true (-v).'),
|
|
357
|
+
workspace: workspaceParam,
|
|
168
358
|
}),
|
|
169
|
-
}, async ({ dotfiles, ignore, clean: cleanGlob, reset,
|
|
359
|
+
}, async ({ dotfiles, ignore, clean: cleanGlob, reset, dry_run, case_sensitive, verbose, workspace }) => {
|
|
170
360
|
const args = ['addremove'];
|
|
361
|
+
if (dry_run)
|
|
362
|
+
args.push('-n');
|
|
171
363
|
if (reset) {
|
|
172
364
|
args.push('--reset');
|
|
365
|
+
if (verbose)
|
|
366
|
+
args.push('-v');
|
|
173
367
|
}
|
|
174
368
|
else {
|
|
175
369
|
if (dotfiles)
|
|
176
370
|
args.push('--dotfiles');
|
|
371
|
+
if (case_sensitive !== undefined)
|
|
372
|
+
args.push('--case-sensitive', case_sensitive ? '1' : '0');
|
|
177
373
|
pushOption(args, '--ignore', ignore);
|
|
178
374
|
pushOption(args, '--clean', cleanGlob);
|
|
179
375
|
}
|
|
180
|
-
return renderOutcome(await runFossil(args, {
|
|
376
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
181
377
|
});
|
|
182
378
|
server.registerTool('fossil_commit', {
|
|
183
379
|
title: 'Commit',
|
|
184
|
-
description: 'Create a check-in from the staged/current changes. Answers the interactive "commit anyhow"
|
|
185
|
-
|
|
380
|
+
description: 'Create a check-in from the staged/current changes. Answers the interactive "continue" and "commit anyhow" ' +
|
|
381
|
+
'prompts automatically.',
|
|
186
382
|
inputSchema: z.object({
|
|
187
383
|
message: z.string().min(1).describe('Commit message.'),
|
|
188
384
|
files: filesParam.describe('Files to commit. Omit to commit everything that changed.'),
|
|
189
385
|
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)
|
|
386
|
+
no_warnings: flag('Omit content warnings (--no-warnings).'),
|
|
191
387
|
allow_empty: flag('Allow a check-in with no file changes (--allow-empty).'),
|
|
192
388
|
user_override: z.string().min(1).optional().describe('Record this login as the author (--user-override).'),
|
|
193
|
-
|
|
389
|
+
tags: z.array(z.string().min(1)).optional().describe('Tags to attach to the new check-in (--tag).'),
|
|
390
|
+
close: flag('Close the branch being committed (--close).'),
|
|
391
|
+
bgcolor: z.string().min(1).optional().describe('Background colour for this one check-in (--bgcolor).'),
|
|
392
|
+
date_override: z
|
|
393
|
+
.string()
|
|
394
|
+
.min(1)
|
|
395
|
+
.optional()
|
|
396
|
+
.describe('Check-in timestamp to store instead of now, e.g. "2026-11-17 12:00:00" (--date-override).'),
|
|
397
|
+
workspace: workspaceParam,
|
|
194
398
|
}),
|
|
195
|
-
}, async ({ message, files, branch, no_warnings, allow_empty, user_override,
|
|
399
|
+
}, async ({ message, files, branch, no_warnings, allow_empty, user_override, tags, close, bgcolor, date_override, workspace }) => {
|
|
196
400
|
const args = ['commit', '-m', message];
|
|
197
401
|
pushOption(args, '--branch', branch);
|
|
198
402
|
if (no_warnings)
|
|
199
403
|
args.push('--no-warnings');
|
|
200
404
|
if (allow_empty)
|
|
201
405
|
args.push('--allow-empty');
|
|
406
|
+
if (close)
|
|
407
|
+
args.push('--close');
|
|
408
|
+
pushOption(args, '--bgcolor', bgcolor);
|
|
409
|
+
pushOption(args, '--date-override', date_override);
|
|
410
|
+
for (const tag of tags ?? [])
|
|
411
|
+
args.push('--tag', tag);
|
|
202
412
|
pushOption(args, '--user-override', user_override);
|
|
203
413
|
if (files?.length)
|
|
204
414
|
args.push(...files);
|
|
205
|
-
|
|
415
|
+
// Fossil asks "continue (y/N)?" for unknown file arguments and
|
|
416
|
+
// "Commit anyhow (a=all/y/N)?" for warned files. "y" then "a" answers
|
|
417
|
+
// both, and a single prompt just consumes the first line.
|
|
418
|
+
return renderOutcome(await runFossil(args, { workspace, input: 'y\na\n' }));
|
|
206
419
|
});
|
|
207
420
|
server.registerTool('fossil_add', {
|
|
208
421
|
title: 'Add files',
|
|
209
422
|
description: 'Start tracking one or more files or directories.',
|
|
210
423
|
inputSchema: z.object({
|
|
211
|
-
files: z
|
|
424
|
+
files: z
|
|
425
|
+
.array(z.string().min(1))
|
|
426
|
+
.optional()
|
|
427
|
+
.describe('Files or directories to add. Required unless reset is true.'),
|
|
212
428
|
dotfiles: flag('Recurse into dot-files/directories (--dotfiles).'),
|
|
213
429
|
force: z.boolean().default(true).describe('Add even when a file matches ignore-glob, without prompting (-f).'),
|
|
214
|
-
|
|
430
|
+
reset: flag('Reset the ADDED state instead of adding files (--reset).'),
|
|
431
|
+
ignore: z.string().min(1).optional().describe('Ignore unmanaged files matching these globs (--ignore).'),
|
|
432
|
+
clean: z.string().min(1).optional().describe('Also ignore files matching these globs (--clean).'),
|
|
433
|
+
case_sensitive: z
|
|
434
|
+
.boolean()
|
|
435
|
+
.optional()
|
|
436
|
+
.describe('Override the case-sensitive setting (--case-sensitive).'),
|
|
437
|
+
allow_reserved: flag('Add file names that Windows reserves, such as `CON` or `NUL` (--allow-reserved).'),
|
|
438
|
+
verbose: flag('Report each file while resetting, with reset: true (-v).'),
|
|
439
|
+
workspace: workspaceParam,
|
|
215
440
|
}),
|
|
216
|
-
}, async ({ files, dotfiles, force,
|
|
441
|
+
}, async ({ files, dotfiles, force, reset, ignore, clean: cleanGlob, case_sensitive, allow_reserved, verbose, workspace }) => {
|
|
217
442
|
const args = ['add'];
|
|
443
|
+
if (reset) {
|
|
444
|
+
args.push('--reset');
|
|
445
|
+
if (verbose)
|
|
446
|
+
args.push('-v');
|
|
447
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
448
|
+
}
|
|
449
|
+
if (!files?.length) {
|
|
450
|
+
return {
|
|
451
|
+
isError: true,
|
|
452
|
+
content: [
|
|
453
|
+
{ type: 'text', text: 'ERROR: `files` is required unless `reset` is true.' },
|
|
454
|
+
],
|
|
455
|
+
};
|
|
456
|
+
}
|
|
218
457
|
if (dotfiles)
|
|
219
458
|
args.push('--dotfiles');
|
|
220
459
|
if (force !== false)
|
|
221
460
|
args.push('-f');
|
|
461
|
+
if (case_sensitive !== undefined)
|
|
462
|
+
args.push('--case-sensitive', case_sensitive ? '1' : '0');
|
|
463
|
+
if (allow_reserved)
|
|
464
|
+
args.push('--allow-reserved');
|
|
465
|
+
pushOption(args, '--ignore', ignore);
|
|
466
|
+
pushOption(args, '--clean', cleanGlob);
|
|
222
467
|
args.push(...files);
|
|
223
|
-
return renderOutcome(await runFossil(args, {
|
|
468
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
224
469
|
});
|
|
225
470
|
server.registerTool('fossil_rm', {
|
|
226
471
|
title: 'Remove files',
|
|
@@ -228,18 +473,41 @@ export function registerVersionControlTools(server) {
|
|
|
228
473
|
inputSchema: z.object({
|
|
229
474
|
files: z.array(z.string().min(1)).min(1).describe('Files or directories to remove.'),
|
|
230
475
|
force: flag('Also delete from disk (--hard).'),
|
|
231
|
-
keep: flag('Keep files on disk (--soft)
|
|
232
|
-
|
|
476
|
+
keep: flag('Keep files on disk (--soft); takes precedence over `force`.'),
|
|
477
|
+
dry_run: flag('Show what would be removed without changing anything (-n).'),
|
|
478
|
+
reset: flag('Reset the DELETED state instead of removing files (--reset).'),
|
|
479
|
+
verbose: flag('Report each file when resetting (--verbose); used with `reset`.'),
|
|
480
|
+
case_sensitive: z
|
|
481
|
+
.boolean()
|
|
482
|
+
.optional()
|
|
483
|
+
.describe('Override the case-sensitive setting (--case-sensitive).'),
|
|
484
|
+
workspace: workspaceParam,
|
|
233
485
|
}),
|
|
234
486
|
annotations: { destructiveHint: true },
|
|
235
|
-
}, async ({ files, force, keep,
|
|
487
|
+
}, async ({ files, force, keep, dry_run, reset, verbose, case_sensitive, workspace }) => {
|
|
236
488
|
const args = ['rm'];
|
|
237
|
-
if (
|
|
238
|
-
args.push('--
|
|
239
|
-
|
|
489
|
+
if (reset) {
|
|
490
|
+
args.push('--reset');
|
|
491
|
+
if (verbose)
|
|
492
|
+
args.push('--verbose');
|
|
493
|
+
if (dry_run)
|
|
494
|
+
args.push('-n');
|
|
495
|
+
}
|
|
496
|
+
else if (keep) {
|
|
240
497
|
args.push('--soft');
|
|
498
|
+
if (dry_run)
|
|
499
|
+
args.push('-n');
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
if (force)
|
|
503
|
+
args.push('--hard');
|
|
504
|
+
if (dry_run)
|
|
505
|
+
args.push('-n');
|
|
506
|
+
}
|
|
507
|
+
if (case_sensitive !== undefined)
|
|
508
|
+
args.push('--case-sensitive', case_sensitive ? '1' : '0');
|
|
241
509
|
args.push(...files);
|
|
242
|
-
return renderOutcome(await runFossil(args, {
|
|
510
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
243
511
|
});
|
|
244
512
|
server.registerTool('fossil_mv', {
|
|
245
513
|
title: 'Move/rename',
|
|
@@ -252,14 +520,17 @@ export function registerVersionControlTools(server) {
|
|
|
252
520
|
.boolean()
|
|
253
521
|
.optional()
|
|
254
522
|
.describe('Explicitly set the case-sensitive behaviour (--case-sensitive 1/0).'),
|
|
255
|
-
|
|
523
|
+
dry_run: flag('Print the RENAME event without changing anything (-n).'),
|
|
524
|
+
workspace: workspaceParam,
|
|
256
525
|
}),
|
|
257
|
-
}, async ({ old_name, new_name, hard, case_sensitive,
|
|
526
|
+
}, async ({ old_name, new_name, hard, case_sensitive, dry_run, workspace }) => {
|
|
258
527
|
const args = ['mv', hard !== false ? '--hard' : '--soft'];
|
|
259
528
|
if (case_sensitive !== undefined)
|
|
260
529
|
args.push('--case-sensitive', case_sensitive ? '1' : '0');
|
|
530
|
+
if (dry_run)
|
|
531
|
+
args.push('-n');
|
|
261
532
|
args.push(old_name, new_name);
|
|
262
|
-
return renderOutcome(await runFossil(args, {
|
|
533
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
263
534
|
});
|
|
264
535
|
server.registerTool('fossil_extras', {
|
|
265
536
|
title: 'List extras',
|
|
@@ -267,29 +538,72 @@ export function registerVersionControlTools(server) {
|
|
|
267
538
|
inputSchema: z.object({
|
|
268
539
|
dotfiles: flag('Include dot-files (--dotfiles).'),
|
|
269
540
|
ignore: z.string().min(1).optional().describe('Comma-separated glob patterns to ignore.'),
|
|
270
|
-
|
|
541
|
+
abs_paths: flag('Print absolute path names (--abs-paths).'),
|
|
542
|
+
rel_paths: flag('Print paths relative to the current directory (--rel-paths).'),
|
|
543
|
+
header: flag('Prefix the list with the repository name (--header).'),
|
|
544
|
+
case_sensitive: z
|
|
545
|
+
.boolean()
|
|
546
|
+
.optional()
|
|
547
|
+
.describe('Override the case-sensitive setting (--case-sensitive 1|0).'),
|
|
548
|
+
workspace: workspaceParam,
|
|
271
549
|
}),
|
|
272
550
|
annotations: { readOnlyHint: true },
|
|
273
|
-
}, async ({ dotfiles, ignore,
|
|
551
|
+
}, async ({ dotfiles, ignore, abs_paths, rel_paths, header, case_sensitive, workspace }) => {
|
|
274
552
|
const args = ['extras'];
|
|
275
553
|
if (dotfiles)
|
|
276
554
|
args.push('--dotfiles');
|
|
277
555
|
pushOption(args, '--ignore', ignore);
|
|
278
|
-
|
|
556
|
+
if (abs_paths)
|
|
557
|
+
args.push('--abs-paths');
|
|
558
|
+
if (rel_paths)
|
|
559
|
+
args.push('--rel-paths');
|
|
560
|
+
if (header)
|
|
561
|
+
args.push('--header');
|
|
562
|
+
if (case_sensitive !== undefined)
|
|
563
|
+
args.push('--case-sensitive', case_sensitive ? '1' : '0');
|
|
564
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No untracked files.' });
|
|
279
565
|
});
|
|
280
566
|
server.registerTool('fossil_clean', {
|
|
281
567
|
title: 'Clean untracked files',
|
|
282
568
|
description: 'Delete untracked files from the workspace. Destructive: preview with dry_run first. ' +
|
|
283
569
|
'Without flags it runs non-interactively (--no-prompt).',
|
|
284
570
|
inputSchema: z.object({
|
|
285
|
-
all_files: flag('
|
|
571
|
+
all_files: flag('Delete every unmanaged file without confirmation (-f).'),
|
|
286
572
|
dry_run: flag('Only list what would be deleted (-n).'),
|
|
287
|
-
|
|
573
|
+
dotfiles: flag('Include files and directories whose name starts with a dot (--dotfiles).'),
|
|
574
|
+
ignore: z.string().min(1).optional().describe('Keep unmanaged files matching these globs (--ignore).'),
|
|
575
|
+
clean: z.string().min(1).optional().describe('Delete matching files without prompting (--clean).'),
|
|
576
|
+
verily: flag('Remove everything that is not managed, including dot-files and ignored files, without the undo buffer (-x).'),
|
|
577
|
+
temp: flag('Remove only Fossil-generated temporary files (--temp).'),
|
|
578
|
+
dirs_only: flag('Remove empty directories only, no files (--dirsonly).'),
|
|
579
|
+
empty_dirs: flag('Remove empty directories after deleting files (--emptydirs).'),
|
|
580
|
+
verbose: flag('Report each file as it is removed (-v).'),
|
|
581
|
+
workspace: workspaceParam,
|
|
288
582
|
}),
|
|
289
583
|
annotations: { destructiveHint: true },
|
|
290
|
-
}, async ({ all_files, dry_run,
|
|
291
|
-
const args = ['clean'
|
|
292
|
-
|
|
584
|
+
}, async ({ all_files, dry_run, dotfiles, ignore, clean: cleanGlob, verily, temp, dirs_only, empty_dirs, verbose, workspace }) => {
|
|
585
|
+
const args = ['clean'];
|
|
586
|
+
if (dry_run)
|
|
587
|
+
args.push('-n');
|
|
588
|
+
else if (all_files)
|
|
589
|
+
args.push('-f');
|
|
590
|
+
else if (!verily)
|
|
591
|
+
args.push('--no-prompt');
|
|
592
|
+
if (dotfiles)
|
|
593
|
+
args.push('--dotfiles');
|
|
594
|
+
pushOption(args, '--ignore', ignore);
|
|
595
|
+
pushOption(args, '--clean', cleanGlob);
|
|
596
|
+
if (verily)
|
|
597
|
+
args.push('-x');
|
|
598
|
+
if (temp)
|
|
599
|
+
args.push('--temp');
|
|
600
|
+
if (dirs_only)
|
|
601
|
+
args.push('--dirsonly');
|
|
602
|
+
if (empty_dirs)
|
|
603
|
+
args.push('--emptydirs');
|
|
604
|
+
if (verbose)
|
|
605
|
+
args.push('-v');
|
|
606
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'Nothing to clean.' });
|
|
293
607
|
});
|
|
294
608
|
server.registerTool('fossil_timeline', {
|
|
295
609
|
title: 'Timeline',
|
|
@@ -301,52 +615,143 @@ export function registerVersionControlTools(server) {
|
|
|
301
615
|
.string()
|
|
302
616
|
.min(1)
|
|
303
617
|
.optional()
|
|
304
|
-
.describe("Event type
|
|
305
|
-
|
|
618
|
+
.describe("Event type (-t), e.g. 'ci' for check-ins, 't' for tickets, 'w' for wiki."),
|
|
619
|
+
branch: z.string().min(1).optional().describe('Only events on this branch (-b).'),
|
|
620
|
+
current_branch: flag('Only events on the current branch (-c).'),
|
|
621
|
+
when: z
|
|
622
|
+
.enum(['before', 'after', 'descendants', 'children', 'ancestors', 'parents'])
|
|
623
|
+
.optional()
|
|
624
|
+
.describe('Timeline direction relative to `checkin`.'),
|
|
625
|
+
checkin: z.string().min(1).optional().describe('Check-in hash or date the `when` keyword applies to.'),
|
|
626
|
+
format: z
|
|
627
|
+
.string()
|
|
628
|
+
.min(1)
|
|
629
|
+
.optional()
|
|
630
|
+
.describe("Entry format (-F), e.g. 'oneline' or '%h %d %c'."),
|
|
631
|
+
verbose: flag('List the files changed by each check-in (-v).'),
|
|
632
|
+
offset: z.number().int().min(0).optional().describe('Skip this many entries before reporting (--offset).'),
|
|
633
|
+
width: z.number().int().min(20).optional().describe('Width of the output lines (-W).'),
|
|
634
|
+
workspace: workspaceParam,
|
|
306
635
|
}),
|
|
307
636
|
annotations: { readOnlyHint: true },
|
|
308
|
-
}, async ({ limit, path: targetPath, type_filter,
|
|
637
|
+
}, async ({ limit, path: targetPath, type_filter, branch, current_branch, when, checkin, format, verbose, offset, width, workspace, }) => {
|
|
309
638
|
const args = ['timeline', '-n', String(limit ?? 20)];
|
|
310
639
|
pushOption(args, '-p', targetPath);
|
|
311
640
|
pushOption(args, '-t', type_filter);
|
|
312
|
-
|
|
641
|
+
pushOption(args, '-b', branch);
|
|
642
|
+
if (current_branch)
|
|
643
|
+
args.push('-c');
|
|
644
|
+
if (when)
|
|
645
|
+
args.push(when);
|
|
646
|
+
if (checkin)
|
|
647
|
+
args.push(checkin);
|
|
648
|
+
pushOption(args, '-F', format);
|
|
649
|
+
if (verbose)
|
|
650
|
+
args.push('-v');
|
|
651
|
+
if (offset !== undefined)
|
|
652
|
+
args.push('--offset', String(offset));
|
|
653
|
+
if (width !== undefined)
|
|
654
|
+
args.push('-W', String(width));
|
|
655
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No events.' });
|
|
313
656
|
});
|
|
314
657
|
server.registerTool('fossil_info', {
|
|
315
658
|
title: 'Info',
|
|
316
659
|
description: 'Repository/check-out metadata, or details about a specific file, check-in or branch.',
|
|
317
660
|
inputSchema: z.object({
|
|
318
661
|
target: z.string().optional().describe('File name, check-in hash or branch. Omit for general repository info.'),
|
|
319
|
-
|
|
662
|
+
verbose: flag('Show extra details, such as the SQLite version and repository size (-v).'),
|
|
663
|
+
workspace: workspaceParam,
|
|
320
664
|
}),
|
|
321
665
|
annotations: { readOnlyHint: true },
|
|
322
|
-
}, async ({ target,
|
|
666
|
+
}, async ({ target, verbose, workspace }) => {
|
|
323
667
|
const targetValue = clean(target);
|
|
324
668
|
const args = targetValue ? ['info', targetValue] : ['info'];
|
|
325
|
-
|
|
669
|
+
if (verbose)
|
|
670
|
+
args.push('-v');
|
|
671
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
326
672
|
});
|
|
327
673
|
server.registerTool('fossil_branch', {
|
|
328
674
|
title: 'Branches',
|
|
329
|
-
description: 'List
|
|
675
|
+
description: 'List, inspect, create, close, reopen, hide or unhide branches.',
|
|
330
676
|
inputSchema: z.object({
|
|
331
|
-
action: z
|
|
332
|
-
|
|
677
|
+
action: z
|
|
678
|
+
.enum(['ls', 'new', 'info', 'current', 'close', 'reopen', 'hide', 'unhide'])
|
|
679
|
+
.default('ls')
|
|
680
|
+
.describe("Branch sub-command: 'ls' lists branches, 'new' creates one, 'info'/'current' report"),
|
|
681
|
+
branch_name: z
|
|
682
|
+
.string()
|
|
683
|
+
.min(1)
|
|
684
|
+
.optional()
|
|
685
|
+
.describe("Branch to act on (required for 'new', 'info', 'close', 'reopen', 'hide' and 'unhide')."),
|
|
333
686
|
basis: z
|
|
334
687
|
.string()
|
|
335
688
|
.min(1)
|
|
336
689
|
.optional()
|
|
337
690
|
.describe("Starting point for the new branch (check-in or branch). Defaults to 'current'."),
|
|
338
|
-
|
|
691
|
+
all: flag('List all branches, including closed ones (-a).'),
|
|
692
|
+
closed: flag('List only closed branches (-c).'),
|
|
693
|
+
private_branches: flag('List only private branches (-p).'),
|
|
694
|
+
reverse: flag('Reverse the sort order (-r).'),
|
|
695
|
+
time_order: flag('Show recently changed branches first (-t).'),
|
|
696
|
+
dry_run: flag('Print the control artifact without committing it; used with close/reopen/hide/unhide (-n).'),
|
|
697
|
+
verbose: flag('Report more detail; used with close/reopen (-v).'),
|
|
698
|
+
date_override: z
|
|
699
|
+
.string()
|
|
700
|
+
.min(1)
|
|
701
|
+
.optional()
|
|
702
|
+
.describe('Timestamp to store instead of now (--date-override).'),
|
|
703
|
+
user_override: z
|
|
704
|
+
.string()
|
|
705
|
+
.min(1)
|
|
706
|
+
.optional()
|
|
707
|
+
.describe('Login to record as the author (--user-override).'),
|
|
708
|
+
bgcolor: z.string().min(1).optional().describe('Background colour for the new branch (--bgcolor).'),
|
|
709
|
+
private_branch: flag('Keep the new branch local; used with `new` (--private).'),
|
|
710
|
+
workspace: workspaceParam,
|
|
339
711
|
}),
|
|
340
|
-
}, async ({ action, branch_name, basis,
|
|
712
|
+
}, async ({ action, branch_name, basis, all, closed, private_branches, reverse, time_order, dry_run, verbose, date_override, user_override, bgcolor, private_branch, workspace, }) => {
|
|
341
713
|
const name = clean(branch_name);
|
|
342
|
-
|
|
343
|
-
|
|
714
|
+
const subcommand = action ?? 'ls';
|
|
715
|
+
if (['new', 'info', 'close', 'reopen', 'hide', 'unhide'].includes(subcommand) && !name) {
|
|
716
|
+
return {
|
|
717
|
+
content: [{ type: 'text', text: `ERROR: 'branch_name' is required for action '${subcommand}'.` }],
|
|
718
|
+
isError: true,
|
|
719
|
+
};
|
|
344
720
|
}
|
|
345
|
-
const args = ['branch',
|
|
346
|
-
|
|
347
|
-
|
|
721
|
+
const args = ['branch', subcommand];
|
|
722
|
+
if (subcommand === 'ls') {
|
|
723
|
+
if (all)
|
|
724
|
+
args.push('-a');
|
|
725
|
+
if (closed)
|
|
726
|
+
args.push('-c');
|
|
727
|
+
if (private_branches)
|
|
728
|
+
args.push('-p');
|
|
729
|
+
if (reverse)
|
|
730
|
+
args.push('-r');
|
|
731
|
+
if (time_order)
|
|
732
|
+
args.push('-t');
|
|
733
|
+
}
|
|
734
|
+
else if (subcommand === 'new' && name) {
|
|
735
|
+
// Fossil requires an explicit basis, 'current' means the checked-out branch.
|
|
348
736
|
args.push(name, clean(basis) ?? 'current');
|
|
349
|
-
|
|
737
|
+
if (private_branch)
|
|
738
|
+
args.push('--private');
|
|
739
|
+
pushOption(args, '--bgcolor', bgcolor);
|
|
740
|
+
}
|
|
741
|
+
else if (name) {
|
|
742
|
+
args.push(name);
|
|
743
|
+
if (['close', 'reopen', 'hide', 'unhide'].includes(subcommand)) {
|
|
744
|
+
if (dry_run)
|
|
745
|
+
args.push('-n');
|
|
746
|
+
if (verbose)
|
|
747
|
+
args.push('-v');
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (subcommand !== 'ls' && subcommand !== 'current') {
|
|
751
|
+
pushOption(args, '--date-override', date_override);
|
|
752
|
+
pushOption(args, '--user-override', user_override);
|
|
753
|
+
}
|
|
754
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
350
755
|
});
|
|
351
756
|
server.registerTool('fossil_merge', {
|
|
352
757
|
title: 'Merge',
|
|
@@ -354,17 +759,37 @@ export function registerVersionControlTools(server) {
|
|
|
354
759
|
inputSchema: z.object({
|
|
355
760
|
branch_or_version: z.string().min(1).describe('Branch name or check-in hash to merge.'),
|
|
356
761
|
integrate: flag('Close the source branch after merging (--integrate).'),
|
|
762
|
+
cherrypick: flag('Merge only the changes of this single check-in (--cherrypick).'),
|
|
763
|
+
backout: flag('Remove the changes of this single check-in (--backout).'),
|
|
357
764
|
dry_run: flag('Simulate the merge without touching files (-n).'),
|
|
358
|
-
|
|
765
|
+
baseline: z.string().min(1).optional().describe('Use this version as the merge pivot (--baseline).'),
|
|
766
|
+
binary: z.string().min(1).optional().describe('Skip parallel changes of files matching this glob (--binary).'),
|
|
767
|
+
force: flag('Force the merge even if it would be a no-op (-f).'),
|
|
768
|
+
force_missing: flag('Merge even when content of one side is missing (--force-missing).'),
|
|
769
|
+
keep_merge_files: flag('Keep the temporary merge files on conflict (-K).'),
|
|
770
|
+
verbose: flag('Report each file as it is merged (-v).'),
|
|
771
|
+
workspace: workspaceParam,
|
|
359
772
|
}),
|
|
360
|
-
}, async ({ branch_or_version, integrate, dry_run,
|
|
773
|
+
}, async ({ branch_or_version, integrate, cherrypick, backout, dry_run, baseline, binary, force, keep_merge_files, verbose, workspace, }) => {
|
|
361
774
|
const args = ['merge'];
|
|
362
775
|
if (dry_run)
|
|
363
776
|
args.push('-n');
|
|
364
777
|
if (integrate)
|
|
365
778
|
args.push('--integrate');
|
|
779
|
+
if (cherrypick)
|
|
780
|
+
args.push('--cherrypick');
|
|
781
|
+
if (backout)
|
|
782
|
+
args.push('--backout');
|
|
783
|
+
pushOption(args, '--baseline', baseline);
|
|
784
|
+
pushOption(args, '--binary', binary);
|
|
785
|
+
if (force)
|
|
786
|
+
args.push('-f');
|
|
787
|
+
if (keep_merge_files)
|
|
788
|
+
args.push('-K');
|
|
789
|
+
if (verbose)
|
|
790
|
+
args.push('-v');
|
|
366
791
|
args.push(branch_or_version);
|
|
367
|
-
return renderOutcome(await runFossil(args, {
|
|
792
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
368
793
|
});
|
|
369
794
|
server.registerTool('fossil_update', {
|
|
370
795
|
title: 'Update check-out',
|
|
@@ -372,23 +797,757 @@ export function registerVersionControlTools(server) {
|
|
|
372
797
|
'Overrides local workspace state - obtain user confirmation first.',
|
|
373
798
|
inputSchema: z.object({
|
|
374
799
|
target: z.string().optional().describe('Version or branch to update to. Omit to update the current branch.'),
|
|
375
|
-
|
|
800
|
+
latest: flag('Update to the latest version instead of a named one (--latest).'),
|
|
801
|
+
dry_run: flag('Show what would change without touching the workspace (-n).'),
|
|
802
|
+
no_sync: flag('Skip the automatic sync before updating (--nosync).'),
|
|
803
|
+
set_mtime: flag('Stamp every file with its last-check-in time (--setmtime).'),
|
|
804
|
+
keep_merge_files: flag('Keep the temporary merge files (-K).'),
|
|
805
|
+
force_missing: flag('Update even when content of one side is missing (--force-missing).'),
|
|
806
|
+
verbose: flag('Report the state of every file (-v).'),
|
|
807
|
+
workspace: workspaceParam,
|
|
376
808
|
}),
|
|
377
809
|
annotations: { destructiveHint: true },
|
|
378
|
-
}, async ({ target,
|
|
810
|
+
}, async ({ target, latest, dry_run, no_sync, set_mtime, keep_merge_files, force_missing, verbose, workspace }) => {
|
|
379
811
|
const args = ['update'];
|
|
812
|
+
if (latest)
|
|
813
|
+
args.push('--latest');
|
|
814
|
+
if (dry_run)
|
|
815
|
+
args.push('-n');
|
|
816
|
+
if (no_sync)
|
|
817
|
+
args.push('--nosync');
|
|
818
|
+
if (set_mtime)
|
|
819
|
+
args.push('--setmtime');
|
|
820
|
+
if (keep_merge_files)
|
|
821
|
+
args.push('-K');
|
|
822
|
+
if (force_missing)
|
|
823
|
+
args.push('--force-missing');
|
|
824
|
+
if (verbose)
|
|
825
|
+
args.push('-v');
|
|
380
826
|
const targetValue = clean(target);
|
|
381
827
|
if (targetValue)
|
|
382
828
|
args.push(targetValue);
|
|
383
|
-
return renderOutcome(await runFossil(args, {
|
|
829
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
384
830
|
});
|
|
385
831
|
server.registerTool('fossil_undo', {
|
|
386
832
|
title: 'Undo',
|
|
387
833
|
description: 'WARNING: destructive. Undo the last update/revert/merge in the workspace. Preview with dry_run (-n) first.',
|
|
388
834
|
inputSchema: z.object({
|
|
389
835
|
dry_run: flag('Simulate the undo (-n) without modifying files.'),
|
|
390
|
-
|
|
836
|
+
workspace: workspaceParam,
|
|
837
|
+
}),
|
|
838
|
+
annotations: { destructiveHint: true },
|
|
839
|
+
}, async ({ dry_run, workspace }) => renderOutcome(await runFossil(dry_run ? ['undo', '-n'] : ['undo'], { workspace })));
|
|
840
|
+
server.registerTool('fossil_changes', {
|
|
841
|
+
title: 'Changes',
|
|
842
|
+
description: 'Report the change status of files in the check-out, optionally restricted to one or more change types ' +
|
|
843
|
+
'(edited, updated, added, deleted, renamed, conflict, meta) and/or to explicit paths.',
|
|
844
|
+
inputSchema: z.object({
|
|
845
|
+
files: filesParam,
|
|
846
|
+
edited: flag('Only edited, merged and conflicted files (--edited).'),
|
|
847
|
+
updated: flag('Only files updated by merge/integrate (--updated).'),
|
|
848
|
+
added: flag('Only added files (--added).'),
|
|
849
|
+
deleted: flag('Only deleted files (--deleted).'),
|
|
850
|
+
renamed: flag('Only renamed files (--renamed).'),
|
|
851
|
+
conflict: flag('Only files with merge conflicts (--conflict).'),
|
|
852
|
+
meta: flag('Only files with metadata changes (--meta).'),
|
|
853
|
+
changed: flag('Edited and updated files together (--changed).'),
|
|
854
|
+
missing: flag('Only missing files (--missing).'),
|
|
855
|
+
unchanged: flag('Only unchanged files (--unchanged).'),
|
|
856
|
+
extra: flag('Only unmanaged files (--extra).'),
|
|
857
|
+
differ: flag('All differences against the check-out, including unmanaged files (--differ).'),
|
|
858
|
+
all: flag('Every managed file, i.e. all change types (--all).'),
|
|
859
|
+
classify: flag('Start each line with the change type (--classify).'),
|
|
860
|
+
no_merge: flag('Hide merge contributors (--no-merge).'),
|
|
861
|
+
hash: flag('Verify file status by hashing instead of size and mtime (--hash).'),
|
|
862
|
+
header: flag('Print the repository name above a non-empty report (--header).'),
|
|
863
|
+
verbose: flag('Print "(none)" when the report is empty (-v).'),
|
|
864
|
+
dotfiles: flag('Include unmanaged files whose name starts with a dot (--dotfiles).'),
|
|
865
|
+
absolute_paths: flag('Print absolute pathnames (--abs-paths).'),
|
|
866
|
+
relative_paths: flag('Print pathnames relative to the current directory (--rel-paths).'),
|
|
867
|
+
workspace: workspaceParam,
|
|
868
|
+
}),
|
|
869
|
+
annotations: { readOnlyHint: true },
|
|
870
|
+
}, async ({ files, edited, updated, added, deleted, renamed, conflict, meta, changed, missing, unchanged, extra, differ, all, classify, no_merge, hash, header, verbose, dotfiles, absolute_paths, relative_paths, workspace, }) => {
|
|
871
|
+
const args = ['changes'];
|
|
872
|
+
const filters = [
|
|
873
|
+
[edited, '--edited'],
|
|
874
|
+
[updated, '--updated'],
|
|
875
|
+
[added, '--added'],
|
|
876
|
+
[deleted, '--deleted'],
|
|
877
|
+
[renamed, '--renamed'],
|
|
878
|
+
[conflict, '--conflict'],
|
|
879
|
+
[meta, '--meta'],
|
|
880
|
+
[changed, '--changed'],
|
|
881
|
+
[missing, '--missing'],
|
|
882
|
+
[unchanged, '--unchanged'],
|
|
883
|
+
[extra, '--extra'],
|
|
884
|
+
[differ, '--differ'],
|
|
885
|
+
[all, '--all'],
|
|
886
|
+
];
|
|
887
|
+
for (const [enabled, option] of filters)
|
|
888
|
+
if (enabled)
|
|
889
|
+
args.push(option);
|
|
890
|
+
if (classify)
|
|
891
|
+
args.push('--classify');
|
|
892
|
+
if (no_merge)
|
|
893
|
+
args.push('--no-merge');
|
|
894
|
+
if (hash)
|
|
895
|
+
args.push('--hash');
|
|
896
|
+
if (header)
|
|
897
|
+
args.push('--header');
|
|
898
|
+
if (verbose)
|
|
899
|
+
args.push('-v');
|
|
900
|
+
if (dotfiles)
|
|
901
|
+
args.push('--dotfiles');
|
|
902
|
+
if (absolute_paths)
|
|
903
|
+
args.push('--abs-paths');
|
|
904
|
+
if (relative_paths)
|
|
905
|
+
args.push('--rel-paths');
|
|
906
|
+
if (files?.length)
|
|
907
|
+
args.push(...files);
|
|
908
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No changes.' });
|
|
909
|
+
});
|
|
910
|
+
server.registerTool('fossil_annotate', {
|
|
911
|
+
title: 'Annotate',
|
|
912
|
+
description: 'Show a file line by line with the check-in that last changed each line' +
|
|
913
|
+
' (annotate: line numbers, blame/praise: author names).',
|
|
914
|
+
inputSchema: z.object({
|
|
915
|
+
file: z.string().min(1).describe('File to annotate, relative to the check-out.'),
|
|
916
|
+
command: z
|
|
917
|
+
.enum(['blame', 'annotate', 'praise'])
|
|
918
|
+
.default('blame')
|
|
919
|
+
.describe('blame/praise print the author, annotate prints line numbers only.'),
|
|
920
|
+
revision: z.string().min(1).optional().describe('Check-in containing the file version to annotate (-r).'),
|
|
921
|
+
origin: z.string().min(1).optional().describe('Future check-in to annotate towards (-o); e.g. trunk.'),
|
|
922
|
+
limit: z.string().min(1).optional().describe('Version limit: a count, a duration like "2s", or "none" (-n).'),
|
|
923
|
+
filevers: flag('Show file versions instead of check-in versions (--filevers).'),
|
|
924
|
+
log: flag('List every version analysed (-l).'),
|
|
925
|
+
ignore_all_space: flag('Ignore all whitespace when matching lines (-w).'),
|
|
926
|
+
ignore_trailing_space: flag('Ignore trailing whitespace (-Z).'),
|
|
927
|
+
workspace: workspaceParam,
|
|
928
|
+
}),
|
|
929
|
+
annotations: { readOnlyHint: true },
|
|
930
|
+
}, async ({ file, command, revision, origin, limit, filevers, log, ignore_all_space, ignore_trailing_space, workspace, }) => {
|
|
931
|
+
const args = [command];
|
|
932
|
+
pushOption(args, '-r', revision);
|
|
933
|
+
pushOption(args, '-o', origin);
|
|
934
|
+
pushOption(args, '-n', limit);
|
|
935
|
+
if (filevers)
|
|
936
|
+
args.push('--filevers');
|
|
937
|
+
if (log)
|
|
938
|
+
args.push('-l');
|
|
939
|
+
if (ignore_all_space)
|
|
940
|
+
args.push('-w');
|
|
941
|
+
if (ignore_trailing_space)
|
|
942
|
+
args.push('-Z');
|
|
943
|
+
args.push(file);
|
|
944
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
945
|
+
});
|
|
946
|
+
server.registerTool('fossil_grep', {
|
|
947
|
+
title: 'Grep history',
|
|
948
|
+
description: 'Match a POSIX extended regular expression over every historical version of the named files, ' +
|
|
949
|
+
'starting at the newest version of each file.',
|
|
950
|
+
inputSchema: z.object({
|
|
951
|
+
pattern: z.string().min(1).describe('POSIX extended regular expression.'),
|
|
952
|
+
files: z.array(z.string().min(1)).min(1).describe('Files to search, newest version first.'),
|
|
953
|
+
ignore_case: flag('Case-insensitive match (-i).'),
|
|
954
|
+
count: flag('Print the number of matching files only (-c).'),
|
|
955
|
+
files_with_matches: flag('Print one artifact hash per matching file instead of the lines (-l).'),
|
|
956
|
+
once: flag('Stop at the first match (--once).'),
|
|
957
|
+
invert_match: flag('Show only files without a match (-v).'),
|
|
958
|
+
no_messages: flag('Suppress messages about unreadable files (-s).'),
|
|
959
|
+
verbose: flag('Report each file as it is analysed (--verbose).'),
|
|
960
|
+
workspace: workspaceParam,
|
|
961
|
+
}),
|
|
962
|
+
annotations: { readOnlyHint: true },
|
|
963
|
+
}, async ({ pattern, files, ignore_case, count, files_with_matches, once, invert_match, no_messages, verbose, workspace, }) => {
|
|
964
|
+
const args = ['grep'];
|
|
965
|
+
if (ignore_case)
|
|
966
|
+
args.push('-i');
|
|
967
|
+
if (count)
|
|
968
|
+
args.push('-c');
|
|
969
|
+
if (files_with_matches)
|
|
970
|
+
args.push('-l');
|
|
971
|
+
if (once)
|
|
972
|
+
args.push('--once');
|
|
973
|
+
if (invert_match)
|
|
974
|
+
args.push('-v');
|
|
975
|
+
if (no_messages)
|
|
976
|
+
args.push('-s');
|
|
977
|
+
if (verbose)
|
|
978
|
+
args.push('--verbose');
|
|
979
|
+
args.push(pattern, ...files);
|
|
980
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No matches.' });
|
|
981
|
+
});
|
|
982
|
+
server.registerTool('fossil_whatis', {
|
|
983
|
+
title: 'What is',
|
|
984
|
+
description: 'Resolve a name (tag, branch, hash prefix, or with file: the content hash) to its artifact hash and role.',
|
|
985
|
+
inputSchema: z.object({
|
|
986
|
+
name: z.string().min(1).describe('Symbol to resolve: tag, branch, hash prefix or filename.'),
|
|
987
|
+
file: flag('Treat name as a file whose content hash is looked up (-f).'),
|
|
988
|
+
type: z.enum(['ci', 't', 'w', 'g', 'e']).optional().describe('Only match this artifact type (--type).'),
|
|
989
|
+
verbose: flag('Include the internal record id (-v).'),
|
|
990
|
+
workspace: workspaceParam,
|
|
991
|
+
}),
|
|
992
|
+
annotations: { readOnlyHint: true },
|
|
993
|
+
}, async ({ name, file, type, verbose, workspace }) => {
|
|
994
|
+
const args = ['whatis'];
|
|
995
|
+
if (file)
|
|
996
|
+
args.push('-f');
|
|
997
|
+
pushOption(args, '--type', type);
|
|
998
|
+
if (verbose)
|
|
999
|
+
args.push('-v');
|
|
1000
|
+
args.push(name);
|
|
1001
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1002
|
+
});
|
|
1003
|
+
server.registerTool('fossil_merge_base', {
|
|
1004
|
+
title: 'Merge base',
|
|
1005
|
+
description: 'Find the common ancestor check-in of two or more versions, as a hypothetical merge would.',
|
|
1006
|
+
inputSchema: z.object({
|
|
1007
|
+
versions: z.array(z.string().min(1)).min(2).describe('Two or more versions; the first is the primary.'),
|
|
1008
|
+
ignore_merges: flag('Ignore merge arcs when looking for name pivots (--ignore-merges).'),
|
|
1009
|
+
workspace: workspaceParam,
|
|
1010
|
+
}),
|
|
1011
|
+
annotations: { readOnlyHint: true },
|
|
1012
|
+
}, async ({ versions, ignore_merges, workspace }) => {
|
|
1013
|
+
const args = ['merge-base'];
|
|
1014
|
+
if (ignore_merges)
|
|
1015
|
+
args.push('--ignore-merges');
|
|
1016
|
+
args.push(...versions);
|
|
1017
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1018
|
+
});
|
|
1019
|
+
server.registerTool('fossil_leaves', {
|
|
1020
|
+
title: 'Leaves',
|
|
1021
|
+
description: 'List the leaf check-ins of every branch, i.e. heads that have no children.',
|
|
1022
|
+
inputSchema: z.object({
|
|
1023
|
+
all: flag('Include closed leaves as well (-a).'),
|
|
1024
|
+
closed: flag('Only closed leaves (-c).'),
|
|
1025
|
+
multiple: flag('Only branches with more than one leaf (-m).'),
|
|
1026
|
+
by_branch: flag('Order the output by branch name (--bybranch).'),
|
|
1027
|
+
width: z.number().int().nonnegative().optional().describe('Output width in columns (-W); 0 means one line per entry.'),
|
|
1028
|
+
workspace: workspaceParam,
|
|
1029
|
+
}),
|
|
1030
|
+
annotations: { readOnlyHint: true },
|
|
1031
|
+
}, async ({ all, closed, multiple, by_branch, width, workspace }) => {
|
|
1032
|
+
const args = ['leaves'];
|
|
1033
|
+
if (all)
|
|
1034
|
+
args.push('-a');
|
|
1035
|
+
if (closed)
|
|
1036
|
+
args.push('-c');
|
|
1037
|
+
if (multiple)
|
|
1038
|
+
args.push('-m');
|
|
1039
|
+
if (by_branch)
|
|
1040
|
+
args.push('--bybranch');
|
|
1041
|
+
if (width !== undefined)
|
|
1042
|
+
args.push('-W', String(width));
|
|
1043
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1044
|
+
});
|
|
1045
|
+
server.registerTool('fossil_descendants', {
|
|
1046
|
+
title: 'Descendants',
|
|
1047
|
+
description: 'List every leaf descendant of a check-in (default: the check-out version).',
|
|
1048
|
+
inputSchema: z.object({
|
|
1049
|
+
checkin: z.string().min(1).optional().describe('Check-in to start from. Omit for the check-out version.'),
|
|
1050
|
+
width: z.number().int().nonnegative().optional().describe('Output width in columns (-W); 0 means one line per entry.'),
|
|
1051
|
+
workspace: workspaceParam,
|
|
1052
|
+
}),
|
|
1053
|
+
annotations: { readOnlyHint: true },
|
|
1054
|
+
}, async ({ checkin, width, workspace }) => {
|
|
1055
|
+
const args = ['descendants'];
|
|
1056
|
+
const target = clean(checkin);
|
|
1057
|
+
if (target)
|
|
1058
|
+
args.push(target);
|
|
1059
|
+
if (width !== undefined)
|
|
1060
|
+
args.push('-W', String(width));
|
|
1061
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1062
|
+
});
|
|
1063
|
+
server.registerTool('fossil_unpublished', {
|
|
1064
|
+
title: 'Unpublished',
|
|
1065
|
+
description: 'List unpublished check-ins (private artifacts that a push will not send).',
|
|
1066
|
+
inputSchema: z.object({
|
|
1067
|
+
all: flag('Include every unpublished artifact, not only check-ins (--all).'),
|
|
1068
|
+
workspace: workspaceParam,
|
|
1069
|
+
}),
|
|
1070
|
+
annotations: { readOnlyHint: true },
|
|
1071
|
+
}, async ({ all, workspace }) => renderOutcome(await runFossil(all ? ['unpublished', '--all'] : ['unpublished'], { workspace }), {
|
|
1072
|
+
emptyText: 'No unpublished artifacts.',
|
|
1073
|
+
}));
|
|
1074
|
+
server.registerTool('fossil_ignore_from_gitignore', {
|
|
1075
|
+
title: 'Ignore glob from .gitignore',
|
|
1076
|
+
description: 'Convert a .gitignore file into the ignore-glob patterns Fossil matches against check-out paths, ' +
|
|
1077
|
+
'and optionally write them to .fossil-settings/ignore-glob.',
|
|
1078
|
+
inputSchema: z.object({
|
|
1079
|
+
source: z.string().min(1).default('.gitignore').describe('File to convert, relative to the workspace.'),
|
|
1080
|
+
write: flag('Write the patterns to .fossil-settings/ignore-glob.'),
|
|
1081
|
+
overwrite: flag('Replace an existing .fossil-settings/ignore-glob.'),
|
|
1082
|
+
workspace: workspaceParam,
|
|
1083
|
+
}),
|
|
1084
|
+
}, async ({ source, write, overwrite, workspace }) => {
|
|
1085
|
+
const root = resolveWorkspace(workspace);
|
|
1086
|
+
const sourcePath = path.resolve(root, source);
|
|
1087
|
+
const relative = path.relative(root, sourcePath);
|
|
1088
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
1089
|
+
return {
|
|
1090
|
+
content: [{ type: 'text', text: `ERROR: \`source\` must stay inside the workspace (${root}).` }],
|
|
1091
|
+
isError: true,
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
let content;
|
|
1095
|
+
try {
|
|
1096
|
+
content = await readFile(sourcePath, 'utf8');
|
|
1097
|
+
}
|
|
1098
|
+
catch (error) {
|
|
1099
|
+
const code = error.code ?? 'unknown error';
|
|
1100
|
+
return {
|
|
1101
|
+
content: [{ type: 'text', text: `ERROR: cannot read ${relative}: ${code}.` }],
|
|
1102
|
+
isError: true,
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
const directory = path.dirname(relative);
|
|
1106
|
+
const conversion = convertGitignore(content, { prefix: directory === '.' ? '' : directory });
|
|
1107
|
+
const lines = [
|
|
1108
|
+
`Converted ${conversion.lineCount} rules from ${relative} into ${conversion.patterns.length} ignore-glob patterns.`,
|
|
1109
|
+
'',
|
|
1110
|
+
...conversion.patterns,
|
|
1111
|
+
];
|
|
1112
|
+
if (conversion.warnings.length > 0) {
|
|
1113
|
+
lines.push('', ...conversion.warnings.map((warning) => `NOTE: ${warning}.`));
|
|
1114
|
+
}
|
|
1115
|
+
if (!write)
|
|
1116
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
1117
|
+
const settingsDir = path.join(root, '.fossil-settings');
|
|
1118
|
+
const target = path.join(settingsDir, 'ignore-glob');
|
|
1119
|
+
const exists = await stat(target).then(() => true, () => false);
|
|
1120
|
+
if (exists && !overwrite) {
|
|
1121
|
+
return {
|
|
1122
|
+
content: [
|
|
1123
|
+
{
|
|
1124
|
+
type: 'text',
|
|
1125
|
+
text: 'ERROR: .fossil-settings/ignore-glob already exists; pass `overwrite: true` to replace it.',
|
|
1126
|
+
},
|
|
1127
|
+
],
|
|
1128
|
+
isError: true,
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
await mkdir(settingsDir, { recursive: true });
|
|
1132
|
+
await writeFile(target, renderGlobFile(conversion), 'utf8');
|
|
1133
|
+
lines.splice(1, 0, 'Wrote .fossil-settings/ignore-glob.');
|
|
1134
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
1135
|
+
});
|
|
1136
|
+
server.registerTool('fossil_ls', {
|
|
1137
|
+
title: 'List files',
|
|
1138
|
+
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.',
|
|
1139
|
+
inputSchema: z.object({
|
|
1140
|
+
paths: filesParam,
|
|
1141
|
+
revision: z.string().min(1).optional().describe('Check-in to list (-r) instead of the check-out contents.'),
|
|
1142
|
+
age: flag('Show when each file was committed (--age).'),
|
|
1143
|
+
verbose: flag('Show extra information, including change status (--verbose).'),
|
|
1144
|
+
time_order: flag('Sort by time instead of name (-t).'),
|
|
1145
|
+
hash: flag('Verify file status by hashing instead of size and mtime (--hash); adds --verbose.'),
|
|
1146
|
+
workspace: workspaceParam,
|
|
1147
|
+
}),
|
|
1148
|
+
annotations: { readOnlyHint: true },
|
|
1149
|
+
}, async ({ paths, revision, age, verbose, time_order, hash, workspace }) => {
|
|
1150
|
+
const args = ['ls'];
|
|
1151
|
+
pushOption(args, '-r', revision);
|
|
1152
|
+
if (age)
|
|
1153
|
+
args.push('--age');
|
|
1154
|
+
if (verbose || hash)
|
|
1155
|
+
args.push('-v');
|
|
1156
|
+
if (time_order)
|
|
1157
|
+
args.push('-t');
|
|
1158
|
+
if (hash)
|
|
1159
|
+
args.push('--hash');
|
|
1160
|
+
if (paths && paths.length > 0)
|
|
1161
|
+
args.push(...paths);
|
|
1162
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1163
|
+
});
|
|
1164
|
+
server.registerTool('fossil_search', {
|
|
1165
|
+
title: 'Search timeline',
|
|
1166
|
+
description: 'Search check-in and other timeline comments for every given word and print the best matches.',
|
|
1167
|
+
inputSchema: z.object({
|
|
1168
|
+
pattern: z.string().min(1).describe('Words to look for; all of them must match.'),
|
|
1169
|
+
all: flag('Print every match instead of only the best scoring ones (--all).'),
|
|
1170
|
+
limit: z.number().int().min(1).optional().describe('Maximum number of matches (-n).'),
|
|
1171
|
+
width: z.number().int().min(0).optional().describe('Output width in columns; 0 means no wrapping (-W).'),
|
|
1172
|
+
workspace: workspaceParam,
|
|
1173
|
+
}),
|
|
1174
|
+
annotations: { readOnlyHint: true },
|
|
1175
|
+
}, async ({ pattern, all, limit, width, workspace }) => {
|
|
1176
|
+
const args = ['search'];
|
|
1177
|
+
if (all)
|
|
1178
|
+
args.push('-a');
|
|
1179
|
+
if (limit !== undefined)
|
|
1180
|
+
args.push('-n', String(limit));
|
|
1181
|
+
if (width !== undefined)
|
|
1182
|
+
args.push('-W', String(width));
|
|
1183
|
+
args.push(pattern);
|
|
1184
|
+
const outcome = await runFossil(args, { workspace });
|
|
1185
|
+
// fossil reports an empty result set as "+++ no more data (0) +++".
|
|
1186
|
+
if (outcome.ok && /^\+{3} no more data \(0\) \+{3}$/.test(outcome.stdout.trim())) {
|
|
1187
|
+
return { content: [{ type: 'text', text: 'No matches.' }] };
|
|
1188
|
+
}
|
|
1189
|
+
return renderOutcome(outcome, { emptyText: 'No matches.' });
|
|
1190
|
+
});
|
|
1191
|
+
server.registerTool('fossil_artifact', {
|
|
1192
|
+
title: 'Artifact content',
|
|
1193
|
+
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.',
|
|
1194
|
+
inputSchema: z.object({
|
|
1195
|
+
artifact: z.string().min(1).describe('Artifact hash, or a unique prefix of it.'),
|
|
1196
|
+
workspace: workspaceParam,
|
|
1197
|
+
}),
|
|
1198
|
+
annotations: { readOnlyHint: true },
|
|
1199
|
+
}, async ({ artifact, workspace }) => renderOutcome(await runFossil(['artifact', artifact], { workspace })));
|
|
1200
|
+
server.registerTool('fossil_describe', {
|
|
1201
|
+
title: 'Describe version',
|
|
1202
|
+
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.',
|
|
1203
|
+
inputSchema: z.object({
|
|
1204
|
+
version: z.string().min(1).optional().describe('Version to describe; defaults to the checked-out version.'),
|
|
1205
|
+
digits: z.number().int().min(4).max(40).optional().describe('Hex digits of the hash to show (--digits).'),
|
|
1206
|
+
dirty: flag('Also show whether there are uncommitted changes (--dirty).'),
|
|
1207
|
+
long: flag('Always show tag, count and hash, even when they collapse (--long).'),
|
|
1208
|
+
match: z.string().min(1).optional().describe('Only consider non-propagating tags matching this glob (--match).'),
|
|
1209
|
+
workspace: workspaceParam,
|
|
1210
|
+
}),
|
|
1211
|
+
annotations: { readOnlyHint: true },
|
|
1212
|
+
}, async ({ version, digits, dirty, long, match, workspace }) => {
|
|
1213
|
+
const args = ['describe'];
|
|
1214
|
+
if (version)
|
|
1215
|
+
args.push(version);
|
|
1216
|
+
if (digits !== undefined)
|
|
1217
|
+
args.push('--digits', String(digits));
|
|
1218
|
+
if (dirty)
|
|
1219
|
+
args.push('--dirty');
|
|
1220
|
+
if (long)
|
|
1221
|
+
args.push('--long');
|
|
1222
|
+
if (match)
|
|
1223
|
+
args.push('--match', match);
|
|
1224
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1225
|
+
});
|
|
1226
|
+
server.registerTool('fossil_archive', {
|
|
1227
|
+
title: 'Archive check-in',
|
|
1228
|
+
description: 'Generate a tarball or ZIP archive of a check-in, or list the files the archive would contain.',
|
|
1229
|
+
inputSchema: z.object({
|
|
1230
|
+
format: z.enum(['tarball', 'zip']).default('tarball').describe('Archive format.'),
|
|
1231
|
+
version: z.string().min(1).default('tip').describe('Check-in to archive.'),
|
|
1232
|
+
output: z
|
|
1233
|
+
.string()
|
|
1234
|
+
.min(1)
|
|
1235
|
+
.optional()
|
|
1236
|
+
.describe('Archive path, relative to the workspace. Omit to list the files instead.'),
|
|
1237
|
+
name: z.string().min(1).optional().describe('Top-level directory name inside the archive (--name).'),
|
|
1238
|
+
exclude: z.array(z.string().min(1)).optional().describe('Glob patterns to leave out (-X).'),
|
|
1239
|
+
include: z.array(z.string().min(1)).optional().describe('Glob patterns to keep (--include).'),
|
|
1240
|
+
workspace: workspaceParam,
|
|
1241
|
+
}),
|
|
1242
|
+
annotations: {},
|
|
1243
|
+
}, async ({ format, version, output, name, exclude, include, workspace }) => {
|
|
1244
|
+
const args = [format, version, output ?? '/dev/null'];
|
|
1245
|
+
if (!output)
|
|
1246
|
+
args.push('-l');
|
|
1247
|
+
pushOption(args, '--name', name);
|
|
1248
|
+
if (exclude && exclude.length > 0)
|
|
1249
|
+
args.push('-X', globList(exclude));
|
|
1250
|
+
if (include && include.length > 0)
|
|
1251
|
+
args.push('--include', globList(include));
|
|
1252
|
+
const outcome = await runFossil(args, { workspace });
|
|
1253
|
+
if (outcome.ok && output) {
|
|
1254
|
+
return renderOutcome({ ...outcome, stdout: `Wrote ${output} from ${version}.` });
|
|
1255
|
+
}
|
|
1256
|
+
return renderOutcome(outcome, { emptyText: 'The archive would be empty.' });
|
|
1257
|
+
});
|
|
1258
|
+
server.registerTool('fossil_unversioned', {
|
|
1259
|
+
title: 'Unversioned files',
|
|
1260
|
+
description: 'List, print, add, remove or timestamp the unversioned files the repository keeps without history, ' +
|
|
1261
|
+
'and sync or revert them against a remote.',
|
|
1262
|
+
inputSchema: z.object({
|
|
1263
|
+
action: z
|
|
1264
|
+
.enum(['list', 'cat', 'add', 'remove', 'touch', 'sync', 'revert'])
|
|
1265
|
+
.default('list')
|
|
1266
|
+
.describe('list: show them; cat: print content; add/remove: change the set; touch: update timestamps; ' +
|
|
1267
|
+
'sync/revert: exchange them with a remote.'),
|
|
1268
|
+
files: filesParam.describe('Files the action applies to.'),
|
|
1269
|
+
glob: z
|
|
1270
|
+
.string()
|
|
1271
|
+
.min(1)
|
|
1272
|
+
.optional()
|
|
1273
|
+
.describe('Match names by this glob, in `list` and `remove` (--glob).'),
|
|
1274
|
+
like: z
|
|
1275
|
+
.string()
|
|
1276
|
+
.min(1)
|
|
1277
|
+
.optional()
|
|
1278
|
+
.describe('Match names like this pattern, in `list` and `remove` (--like).'),
|
|
1279
|
+
url: z.string().min(1).optional().describe('Remote URL for `sync` and `revert`; defaults to the configured remote.'),
|
|
1280
|
+
mtime: z
|
|
1281
|
+
.string()
|
|
1282
|
+
.min(1)
|
|
1283
|
+
.optional()
|
|
1284
|
+
.describe('Timestamp to store instead of now, for add/remove/touch (--mtime).'),
|
|
1285
|
+
verbose: flag('Report extra diagnostics; used with `sync` and `revert` (-v).'),
|
|
1286
|
+
dry_run: flag('Show what would happen without changing anything; used with `sync` and `revert` (-n).'),
|
|
1287
|
+
workspace: workspaceParam,
|
|
1288
|
+
}),
|
|
1289
|
+
annotations: {},
|
|
1290
|
+
}, async ({ action, files, glob, like, url, mtime, verbose, dry_run, workspace }) => {
|
|
1291
|
+
const args = ['unversioned', action];
|
|
1292
|
+
if (action === 'list' || action === 'remove') {
|
|
1293
|
+
pushOption(args, '--glob', glob);
|
|
1294
|
+
pushOption(args, '--like', like);
|
|
1295
|
+
}
|
|
1296
|
+
pushOption(args, '--mtime', mtime);
|
|
1297
|
+
if (action === 'sync' || action === 'revert') {
|
|
1298
|
+
if (verbose)
|
|
1299
|
+
args.push('-v');
|
|
1300
|
+
if (dry_run)
|
|
1301
|
+
args.push('-n');
|
|
1302
|
+
if (url)
|
|
1303
|
+
args.push(url);
|
|
1304
|
+
}
|
|
1305
|
+
if (files && files.length > 0)
|
|
1306
|
+
args.push(...files);
|
|
1307
|
+
const needsFiles = ['cat', 'add', 'touch'].includes(action);
|
|
1308
|
+
if (needsFiles && !(files && files.length > 0)) {
|
|
1309
|
+
return {
|
|
1310
|
+
isError: true,
|
|
1311
|
+
content: [{ type: 'text', text: `ERROR: action '${action}' needs \`files\`.` }],
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No unversioned files.' });
|
|
1315
|
+
});
|
|
1316
|
+
server.registerTool('fossil_touch', {
|
|
1317
|
+
title: 'Touch files',
|
|
1318
|
+
description: "Update file timestamps so that Fossil's size and mtime based change detection sees the files again.",
|
|
1319
|
+
inputSchema: z.object({
|
|
1320
|
+
files: filesParam.describe('Files or glob patterns to touch. Omit to touch every managed file.'),
|
|
1321
|
+
mode: z
|
|
1322
|
+
.enum(['now', 'checkin', 'checkout'])
|
|
1323
|
+
.default('now')
|
|
1324
|
+
.describe('now: current time; checkin: last check-in that modified each file; checkout: the checked-out version.'),
|
|
1325
|
+
glob: z
|
|
1326
|
+
.string()
|
|
1327
|
+
.min(1)
|
|
1328
|
+
.optional()
|
|
1329
|
+
.describe('Comma-separated glob patterns, evaluated from the top of the source tree (-g).'),
|
|
1330
|
+
glob_file: z
|
|
1331
|
+
.string()
|
|
1332
|
+
.min(1)
|
|
1333
|
+
.optional()
|
|
1334
|
+
.describe('Fossil glob-list file to read patterns from (-G).'),
|
|
1335
|
+
verbose: flag('Report the globs and each file touched (-v).'),
|
|
1336
|
+
dry_run: flag('List the files that need touching without touching them (-n).'),
|
|
1337
|
+
quiet: flag('Suppress warnings about skipped unmanaged or out-of-tree files (-q).'),
|
|
1338
|
+
workspace: workspaceParam,
|
|
1339
|
+
}),
|
|
1340
|
+
annotations: {},
|
|
1341
|
+
}, async ({ files, mode, glob, glob_file, verbose, dry_run, quiet, workspace }) => {
|
|
1342
|
+
const args = ['touch'];
|
|
1343
|
+
if (mode === 'checkin')
|
|
1344
|
+
args.push('-c');
|
|
1345
|
+
else if (mode === 'checkout')
|
|
1346
|
+
args.push('-C');
|
|
1347
|
+
pushOption(args, '-g', glob);
|
|
1348
|
+
pushOption(args, '-G', glob_file);
|
|
1349
|
+
if (verbose)
|
|
1350
|
+
args.push('-v');
|
|
1351
|
+
if (dry_run)
|
|
1352
|
+
args.push('-n');
|
|
1353
|
+
if (quiet)
|
|
1354
|
+
args.push('-q');
|
|
1355
|
+
if (files && files.length > 0)
|
|
1356
|
+
args.push(...files);
|
|
1357
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1358
|
+
});
|
|
1359
|
+
server.registerTool('fossil_amend', {
|
|
1360
|
+
title: 'Amend check-in',
|
|
1361
|
+
description: 'Change the comment, author, date, tags, branch or visibility of an existing check-in.',
|
|
1362
|
+
inputSchema: z.object({
|
|
1363
|
+
checkin: z.string().min(1).describe('Check-in to amend, such as tip or a hash.'),
|
|
1364
|
+
comment: z.string().min(1).optional().describe('Replacement comment (-m).'),
|
|
1365
|
+
message_file: z
|
|
1366
|
+
.string()
|
|
1367
|
+
.min(1)
|
|
1368
|
+
.optional()
|
|
1369
|
+
.describe('File to read the replacement comment from, in the workspace (-M).'),
|
|
1370
|
+
author: z.string().min(1).optional().describe('Replacement author (--author).'),
|
|
1371
|
+
date: z.string().min(1).optional().describe('Replacement check-in time, or now (--date).'),
|
|
1372
|
+
bgcolor: z.string().min(1).optional().describe('Background colour for this check-in (--bgcolor).'),
|
|
1373
|
+
branchcolor: flag('Apply the colour to the whole branch (--branchcolor).'),
|
|
1374
|
+
date_override: z
|
|
1375
|
+
.string()
|
|
1376
|
+
.min(1)
|
|
1377
|
+
.optional()
|
|
1378
|
+
.describe('Change time of the control artifact (--date-override).'),
|
|
1379
|
+
user_override: z.string().min(1).optional().describe('Login recorded on the control artifact (--user-override).'),
|
|
1380
|
+
tag: z.array(z.string().min(1)).optional().describe('Tags to add (--tag, repeatable).'),
|
|
1381
|
+
cancel: z.array(z.string().min(1)).optional().describe('Tags to remove (--cancel, repeatable).'),
|
|
1382
|
+
branch: z.string().min(1).optional().describe('Start a branch at this check-in (--branch).'),
|
|
1383
|
+
hide: flag('Hide the branch starting at this check-in (--hide).'),
|
|
1384
|
+
close: flag('Mark this leaf as closed (--close).'),
|
|
1385
|
+
dry_run: flag('Print the control artifact without changing anything (-n).'),
|
|
1386
|
+
workspace: workspaceParam,
|
|
1387
|
+
}),
|
|
1388
|
+
annotations: { destructiveHint: true },
|
|
1389
|
+
}, async ({ checkin, comment, message_file, author, date, bgcolor, branchcolor, date_override, user_override, tag, cancel, branch, hide, close, dry_run, workspace, }) => {
|
|
1390
|
+
const args = ['amend', checkin];
|
|
1391
|
+
if (dry_run)
|
|
1392
|
+
args.push('-n');
|
|
1393
|
+
pushOption(args, '-m', comment);
|
|
1394
|
+
pushOption(args, '-M', message_file);
|
|
1395
|
+
pushOption(args, '--author', author);
|
|
1396
|
+
pushOption(args, '--date', date);
|
|
1397
|
+
pushOption(args, '--bgcolor', bgcolor);
|
|
1398
|
+
if (branchcolor && bgcolor)
|
|
1399
|
+
args.push('--branchcolor', bgcolor);
|
|
1400
|
+
pushOption(args, '--date-override', date_override);
|
|
1401
|
+
pushOption(args, '--user-override', user_override);
|
|
1402
|
+
for (const value of tag ?? [])
|
|
1403
|
+
args.push('--tag', value);
|
|
1404
|
+
for (const value of cancel ?? [])
|
|
1405
|
+
args.push('--cancel', value);
|
|
1406
|
+
pushOption(args, '--branch', branch);
|
|
1407
|
+
if (hide)
|
|
1408
|
+
args.push('--hide');
|
|
1409
|
+
if (close)
|
|
1410
|
+
args.push('--close');
|
|
1411
|
+
const changed = comment ||
|
|
1412
|
+
message_file ||
|
|
1413
|
+
author ||
|
|
1414
|
+
date ||
|
|
1415
|
+
bgcolor ||
|
|
1416
|
+
date_override ||
|
|
1417
|
+
user_override ||
|
|
1418
|
+
branch ||
|
|
1419
|
+
hide ||
|
|
1420
|
+
close ||
|
|
1421
|
+
(tag?.length ?? 0) > 0 ||
|
|
1422
|
+
(cancel?.length ?? 0) > 0;
|
|
1423
|
+
if (!changed) {
|
|
1424
|
+
return {
|
|
1425
|
+
isError: true,
|
|
1426
|
+
content: [
|
|
1427
|
+
{
|
|
1428
|
+
type: 'text',
|
|
1429
|
+
text: 'ERROR: pass at least one of `comment`, `message_file`, `author`, `date`, `tag`, `cancel`, `branch`, `hide` or `close`.',
|
|
1430
|
+
},
|
|
1431
|
+
],
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1435
|
+
});
|
|
1436
|
+
server.registerTool('fossil_patch', {
|
|
1437
|
+
title: 'Binary patch',
|
|
1438
|
+
description: 'Create a binary patch from uncommitted changes, show it as a diff, or apply it to the check-out.',
|
|
1439
|
+
inputSchema: z.object({
|
|
1440
|
+
action: z.enum(['create', 'apply', 'diff']).default('create').describe('create, apply or show the patch.'),
|
|
1441
|
+
file: z.string().min(1).describe('Patch file path; relative paths resolve against the workspace.'),
|
|
1442
|
+
force: flag('Overwrite an existing patch, or apply over unsaved changes (-f).'),
|
|
1443
|
+
dry_run: flag('Print what `apply` would do without doing it (-n).'),
|
|
1444
|
+
verbose: flag('Explain what `apply` does (-v).'),
|
|
1445
|
+
workspace: workspaceParam,
|
|
391
1446
|
}),
|
|
392
1447
|
annotations: { destructiveHint: true },
|
|
393
|
-
}, async ({
|
|
1448
|
+
}, async ({ action, file, force, dry_run, verbose, workspace }) => {
|
|
1449
|
+
const args = ['patch', action];
|
|
1450
|
+
if (force)
|
|
1451
|
+
args.push('-f');
|
|
1452
|
+
if (action === 'apply') {
|
|
1453
|
+
if (dry_run)
|
|
1454
|
+
args.push('-n');
|
|
1455
|
+
if (verbose)
|
|
1456
|
+
args.push('-v');
|
|
1457
|
+
}
|
|
1458
|
+
args.push(file);
|
|
1459
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1460
|
+
});
|
|
1461
|
+
server.registerTool('fossil_bisect', {
|
|
1462
|
+
title: 'Bisect',
|
|
1463
|
+
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.',
|
|
1464
|
+
inputSchema: z.object({
|
|
1465
|
+
action: z
|
|
1466
|
+
.enum(['good', 'bad', 'skip', 'next', 'log', 'chart', 'options', 'reset', 'run'])
|
|
1467
|
+
.describe('Bisect subcommand.'),
|
|
1468
|
+
version: z.string().min(1).optional().describe('Version to mark (good/bad/skip); omit for the current check-out.'),
|
|
1469
|
+
command: z
|
|
1470
|
+
.string()
|
|
1471
|
+
.min(1)
|
|
1472
|
+
.optional()
|
|
1473
|
+
.describe('Command that decides good (exit 0), skip (125) or bad (anything else); required by `run`.'),
|
|
1474
|
+
interactive: flag('Ask for the decision after each step instead of using the exit code (--interactive).'),
|
|
1475
|
+
option: z.string().min(1).optional().describe('Bisect option name for `options`.'),
|
|
1476
|
+
value: z.string().min(1).optional().describe('New value for `option`.'),
|
|
1477
|
+
workspace: workspaceParam,
|
|
1478
|
+
}),
|
|
1479
|
+
annotations: { idempotentHint: false },
|
|
1480
|
+
}, async ({ action, version, command, interactive, option, value, workspace }) => {
|
|
1481
|
+
if (action === 'run' && !command) {
|
|
1482
|
+
return {
|
|
1483
|
+
isError: true,
|
|
1484
|
+
content: [{ type: 'text', text: 'ERROR: `run` requires `command`.' }],
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
const args = ['bisect', action];
|
|
1488
|
+
if (action === 'run') {
|
|
1489
|
+
if (interactive)
|
|
1490
|
+
args.push('-i');
|
|
1491
|
+
args.push(command);
|
|
1492
|
+
}
|
|
1493
|
+
else if (action === 'options') {
|
|
1494
|
+
if (option)
|
|
1495
|
+
args.push(option);
|
|
1496
|
+
if (option && value)
|
|
1497
|
+
args.push(value);
|
|
1498
|
+
}
|
|
1499
|
+
else if (version) {
|
|
1500
|
+
args.push(version);
|
|
1501
|
+
}
|
|
1502
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
1503
|
+
});
|
|
1504
|
+
server.registerTool('fossil_sql', {
|
|
1505
|
+
title: 'SQL query',
|
|
1506
|
+
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`.',
|
|
1507
|
+
inputSchema: z.object({
|
|
1508
|
+
query: z.string().min(1).describe('SQL statement, e.g. "SELECT name FROM blob LIMIT 5".'),
|
|
1509
|
+
repository: z
|
|
1510
|
+
.string()
|
|
1511
|
+
.min(1)
|
|
1512
|
+
.optional()
|
|
1513
|
+
.describe('Repository database to query instead of the one of the check-out (-R).'),
|
|
1514
|
+
workspace: workspaceParam,
|
|
1515
|
+
}),
|
|
1516
|
+
annotations: { readOnlyHint: true },
|
|
1517
|
+
}, async ({ query, repository, workspace }) => {
|
|
1518
|
+
const trimmed = query.trim().replace(/;+\s*$/, '');
|
|
1519
|
+
if (!/^(select|with|pragma|explain)\b/i.test(trimmed)) {
|
|
1520
|
+
return {
|
|
1521
|
+
isError: true,
|
|
1522
|
+
content: [
|
|
1523
|
+
{
|
|
1524
|
+
type: 'text',
|
|
1525
|
+
text: 'ERROR: the query must start with SELECT, WITH, PRAGMA or EXPLAIN.',
|
|
1526
|
+
},
|
|
1527
|
+
],
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
const result = await runSql(trimmed, { workspace, readonly: true, repository });
|
|
1531
|
+
if (!result.ok)
|
|
1532
|
+
return { isError: true, content: [{ type: 'text', text: result.error }] };
|
|
1533
|
+
if (result.rows.length === 0)
|
|
1534
|
+
return { content: [{ type: 'text', text: 'No rows.' }] };
|
|
1535
|
+
const columns = Object.keys(result.rows[0] ?? {});
|
|
1536
|
+
const cell = (value) => {
|
|
1537
|
+
if (value === null || value === undefined)
|
|
1538
|
+
return 'NULL';
|
|
1539
|
+
if (typeof value === 'object')
|
|
1540
|
+
return JSON.stringify(value);
|
|
1541
|
+
return String(value);
|
|
1542
|
+
};
|
|
1543
|
+
const lines = [columns.join('\t'), ...result.rows.map((row) => columns.map((column) => cell(row[column])).join('\t'))];
|
|
1544
|
+
return {
|
|
1545
|
+
content: [
|
|
1546
|
+
{
|
|
1547
|
+
type: 'text',
|
|
1548
|
+
text: truncateOutput(`${lines.join('\n')}\n\n${result.rows.length} row(s).`),
|
|
1549
|
+
},
|
|
1550
|
+
],
|
|
1551
|
+
};
|
|
1552
|
+
});
|
|
394
1553
|
}
|