@stellar_ai/mcp_fossil_scm 0.2.0 → 0.2.2
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 +35 -32
- package/dist/capabilities.js +30 -22
- package/dist/cli.js +11 -11
- package/dist/config.js +1 -1
- package/dist/core/gitignore.js +7 -4
- package/dist/index.js +1 -1
- package/dist/prompts.js +28 -30
- package/dist/tools/admin.js +103 -56
- package/dist/tools/utils.js +237 -0
- package/dist/tools/version-control.js +100 -240
- package/docs/README.md +6 -5
- package/docs/admin.md +60 -46
- package/docs/chat.md +1 -1
- package/docs/forum.md +1 -1
- package/docs/prompts.md +4 -4
- package/docs/tickets.md +1 -1
- package/docs/utils.md +262 -0
- package/docs/vcs.md +68 -241
- package/docs/wiki.md +1 -1
- package/package.json +5 -3
package/dist/tools/admin.js
CHANGED
|
@@ -7,7 +7,7 @@ import { clean, workspaceParam, flag, pushOption } from './common.js';
|
|
|
7
7
|
const repoPathParam = z
|
|
8
8
|
.string()
|
|
9
9
|
.min(1)
|
|
10
|
-
.describe('Repository database file.
|
|
10
|
+
.describe('Repository database file, e.g. `repos/app.fossil`. Absolute paths are used verbatim; relative paths resolve against the workspace. Include the `.fossil` name.');
|
|
11
11
|
const revealSecretsParam = z
|
|
12
12
|
.boolean()
|
|
13
13
|
.default(false)
|
|
@@ -72,6 +72,7 @@ export function registerAdminTools(server) {
|
|
|
72
72
|
.optional()
|
|
73
73
|
.describe('Repository file to copy settings from (--template).'),
|
|
74
74
|
project_desc: z.string().min(1).optional().describe('Project description stored in the repository (--project-desc).'),
|
|
75
|
+
sha1: flag('Use SHA1 instead of SHA3-256 for artifact names (--sha1).'),
|
|
75
76
|
date_override: z
|
|
76
77
|
.string()
|
|
77
78
|
.min(1)
|
|
@@ -80,7 +81,7 @@ export function registerAdminTools(server) {
|
|
|
80
81
|
reveal_secrets: revealSecretsParam,
|
|
81
82
|
workspace: workspaceParam,
|
|
82
83
|
}),
|
|
83
|
-
}, async ({ repository, project_name, admin_user, template, project_desc, date_override, reveal_secrets, workspace }) => {
|
|
84
|
+
}, async ({ repository, project_name, admin_user, template, project_desc, sha1, date_override, reveal_secrets, workspace }) => {
|
|
84
85
|
const workspaceDir = resolveWorkspace(workspace);
|
|
85
86
|
const repoPath = resolveRepoPath(repository, workspaceDir);
|
|
86
87
|
const finalProjectName = clean(project_name) ?? (path.basename(workspaceDir) || 'project');
|
|
@@ -90,6 +91,8 @@ export function registerAdminTools(server) {
|
|
|
90
91
|
pushOption(args, '-A', admin_user);
|
|
91
92
|
pushOption(args, '--template', template);
|
|
92
93
|
pushOption(args, '--project-desc', project_desc);
|
|
94
|
+
if (sha1)
|
|
95
|
+
args.push('--sha1');
|
|
93
96
|
pushOption(args, '--date-override', date_override);
|
|
94
97
|
const init = await runFossil(args, { workspace: workspaceDir });
|
|
95
98
|
const rendered = renderOutcome(init, {
|
|
@@ -114,9 +117,15 @@ export function registerAdminTools(server) {
|
|
|
114
117
|
.min(1)
|
|
115
118
|
.optional()
|
|
116
119
|
.describe('Check-out directory passed as --workdir DIR (relative paths resolve against the workspace).'),
|
|
120
|
+
repodir: z
|
|
121
|
+
.string()
|
|
122
|
+
.min(1)
|
|
123
|
+
.optional()
|
|
124
|
+
.describe('Directory that holds the clone when `repository` is a URI (--repodir DIR).'),
|
|
125
|
+
verbose: flag('Print the clone progress when `repository` is a URI (--verbose).'),
|
|
117
126
|
workspace: workspaceParam,
|
|
118
127
|
}),
|
|
119
|
-
}, async ({ repository, force, keep, nested, empty, no_sync, set_mtime, force_missing, workdir, workspace }) => {
|
|
128
|
+
}, async ({ repository, force, keep, nested, empty, no_sync, set_mtime, force_missing, workdir, repodir, verbose, workspace }) => {
|
|
120
129
|
const workspaceDir = resolveWorkspace(workspace);
|
|
121
130
|
const repoPath = resolveRepoPath(repository, workspaceDir);
|
|
122
131
|
const args = ['open', repoPath];
|
|
@@ -134,6 +143,9 @@ export function registerAdminTools(server) {
|
|
|
134
143
|
args.push('--setmtime');
|
|
135
144
|
if (force_missing)
|
|
136
145
|
args.push('--force-missing');
|
|
146
|
+
if (verbose)
|
|
147
|
+
args.push('--verbose');
|
|
148
|
+
pushOption(args, '--repodir', repodir);
|
|
137
149
|
const requestedWorkdir = clean(workdir);
|
|
138
150
|
const checkoutDir = requestedWorkdir ? path.resolve(workspaceDir, requestedWorkdir) : workspaceDir;
|
|
139
151
|
if (requestedWorkdir)
|
|
@@ -173,11 +185,19 @@ export function registerAdminTools(server) {
|
|
|
173
185
|
target_file: z
|
|
174
186
|
.string()
|
|
175
187
|
.min(1)
|
|
176
|
-
.describe('Destination .fossil
|
|
188
|
+
.describe('Destination repository database file, e.g. `repos/app.fossil` (relative paths resolve against the workspace). Missing parent folders are created.'),
|
|
177
189
|
http_proxy: z.string().min(1).optional().describe('HTTP proxy URL passed as --proxy.'),
|
|
178
190
|
httpauth: z.string().min(1).optional().describe('HTTP Basic credentials "user:pass" (-B).'),
|
|
179
191
|
ssl_identity: z.string().min(1).optional().describe('SSL client certificate file (--ssl-identity).'),
|
|
180
192
|
ssh_command: z.string().min(1).optional().describe('Command used as the ssh client (-c).'),
|
|
193
|
+
transport_command: z
|
|
194
|
+
.string()
|
|
195
|
+
.min(1)
|
|
196
|
+
.optional()
|
|
197
|
+
.describe('External command that moves messages to the server and back (--transport-command).'),
|
|
198
|
+
no_compress: flag('Omit the extra delta compression step (--nocompress).'),
|
|
199
|
+
no_open: flag('Clone only, leaving no check-out (--no-open).'),
|
|
200
|
+
save_http_password: flag('Remember the HTTP password instead of asking for it (--save-http-password).'),
|
|
181
201
|
workdir: z.string().min(1).optional().describe('Also open a check-out in this directory (--workdir).'),
|
|
182
202
|
nested: flag('Clone a repository inside an already opened check-out (--nested).'),
|
|
183
203
|
once: flag('Use the URI once and forget it (--once).'),
|
|
@@ -188,7 +208,7 @@ export function registerAdminTools(server) {
|
|
|
188
208
|
reveal_secrets: revealSecretsParam,
|
|
189
209
|
workspace: workspaceParam,
|
|
190
210
|
}),
|
|
191
|
-
}, async ({ repository_uri, target_file, http_proxy, httpauth, ssl_identity, ssh_command, workdir, nested, once, private: privateBranches, admin_user, unversioned, verbose, reveal_secrets, workspace, }) => {
|
|
211
|
+
}, async ({ repository_uri, target_file, http_proxy, httpauth, ssl_identity, ssh_command, transport_command, no_compress, no_open, save_http_password, workdir, nested, once, private: privateBranches, admin_user, unversioned, verbose, reveal_secrets, workspace, }) => {
|
|
192
212
|
const workspaceDir = resolveWorkspace(workspace);
|
|
193
213
|
const targetFile = path.resolve(workspaceDir, target_file);
|
|
194
214
|
await mkdir(path.dirname(targetFile), { recursive: true });
|
|
@@ -197,7 +217,14 @@ export function registerAdminTools(server) {
|
|
|
197
217
|
pushOption(args, '--httpauth', httpauth);
|
|
198
218
|
pushOption(args, '--ssl-identity', ssl_identity);
|
|
199
219
|
pushOption(args, '--ssh-command', ssh_command);
|
|
220
|
+
pushOption(args, '--transport-command', transport_command);
|
|
200
221
|
pushOption(args, '--workdir', workdir);
|
|
222
|
+
if (no_compress)
|
|
223
|
+
args.push('--nocompress');
|
|
224
|
+
if (no_open)
|
|
225
|
+
args.push('--no-open');
|
|
226
|
+
if (save_http_password)
|
|
227
|
+
args.push('--save-http-password');
|
|
201
228
|
pushOption(args, '--admin-user', admin_user);
|
|
202
229
|
if (nested)
|
|
203
230
|
args.push('--nested');
|
|
@@ -379,6 +406,16 @@ export function registerAdminTools(server) {
|
|
|
379
406
|
proxy: z.string().min(1).optional().describe('HTTP proxy URL (--proxy).'),
|
|
380
407
|
httpauth: z.string().min(1).optional().describe('Credentials for the simple HTTP auth protocol, as USER:PASS (--httpauth).'),
|
|
381
408
|
ssl_identity: z.string().min(1).optional().describe('Client SSL identity file when the remote asks for one (--ssl-identity).'),
|
|
409
|
+
transport_command: z
|
|
410
|
+
.string()
|
|
411
|
+
.min(1)
|
|
412
|
+
.optional()
|
|
413
|
+
.describe('External command that moves messages to the server and back (--transport-command).'),
|
|
414
|
+
no_http_compression: flag('Send HTTP traffic uncompressed (--no-http-compression).'),
|
|
415
|
+
ipv4: flag('Use IPv4 for the connection (--ipv4).'),
|
|
416
|
+
repository: repoPathParam
|
|
417
|
+
.optional()
|
|
418
|
+
.describe('Repository database file to work on (-R), e.g. `repos/app.fossil`; omit to use the repository of the check-out.'),
|
|
382
419
|
reveal_secrets: revealSecretsParam,
|
|
383
420
|
workspace: workspaceParam,
|
|
384
421
|
};
|
|
@@ -400,6 +437,12 @@ export function registerAdminTools(server) {
|
|
|
400
437
|
pushOption(args, '--proxy', options.proxy);
|
|
401
438
|
pushOption(args, '--httpauth', options.httpauth);
|
|
402
439
|
pushOption(args, '--ssl-identity', options.ssl_identity);
|
|
440
|
+
pushOption(args, '--transport-command', options.transport_command);
|
|
441
|
+
pushOption(args, '-R', options.repository);
|
|
442
|
+
if (options.no_http_compression)
|
|
443
|
+
args.push('--no-http-compression');
|
|
444
|
+
if (options.ipv4)
|
|
445
|
+
args.push('--ipv4');
|
|
403
446
|
return args;
|
|
404
447
|
};
|
|
405
448
|
server.registerTool('fossil_push', {
|
|
@@ -452,13 +495,67 @@ export function registerAdminTools(server) {
|
|
|
452
495
|
const rendered = renderOutcome(outcome);
|
|
453
496
|
return input.reveal_secrets ? rendered : withoutSecrets(rendered);
|
|
454
497
|
});
|
|
498
|
+
server.registerTool('fossil_config', {
|
|
499
|
+
title: 'Project configuration',
|
|
500
|
+
description: 'Export, import, merge, pull, push or reset the configuration areas (ticket, user, skin, …) that live in the repository database.',
|
|
501
|
+
inputSchema: z.object({
|
|
502
|
+
action: z.enum(['export', 'import', 'merge', 'pull', 'push', 'reset']).describe('Configuration method.'),
|
|
503
|
+
area: z
|
|
504
|
+
.enum(['all', 'email', 'interwiki', 'project', 'shun', 'skin', 'ticket', 'user', 'alias', 'subscriber'])
|
|
505
|
+
.optional()
|
|
506
|
+
.describe('Configuration area; required by export, pull, push and reset.'),
|
|
507
|
+
file: z.string().min(1).optional().describe('File to read or write; required by export, import and merge.'),
|
|
508
|
+
url: z.string().min(1).optional().describe('Remote repository for pull/push; the default remote when omitted.'),
|
|
509
|
+
repository: repoPathParam
|
|
510
|
+
.optional()
|
|
511
|
+
.describe('Repository database file to configure (-R), e.g. `repos/app.fossil`; omit to use the repository of the check-out.'),
|
|
512
|
+
overwrite: flag('Replace local settings with the ones received from the remote (--overwrite).'),
|
|
513
|
+
workspace: workspaceParam,
|
|
514
|
+
}),
|
|
515
|
+
annotations: { openWorldHint: true },
|
|
516
|
+
}, async (input) => {
|
|
517
|
+
const needsArea = ['export', 'pull', 'push', 'reset'].includes(input.action);
|
|
518
|
+
const needsFile = ['export', 'import', 'merge'].includes(input.action);
|
|
519
|
+
if (needsArea && !input.area) {
|
|
520
|
+
return {
|
|
521
|
+
isError: true,
|
|
522
|
+
content: [{ type: 'text', text: `ERROR: \`${input.action}\` requires \`area\`.` }],
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
if (needsFile && !input.file) {
|
|
526
|
+
return {
|
|
527
|
+
isError: true,
|
|
528
|
+
content: [{ type: 'text', text: `ERROR: \`${input.action}\` requires \`file\`.` }],
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
const args = ['config', input.action];
|
|
532
|
+
if (input.action === 'export') {
|
|
533
|
+
args.push(input.area, input.file);
|
|
534
|
+
}
|
|
535
|
+
else if (input.action === 'import' || input.action === 'merge') {
|
|
536
|
+
args.push(input.file);
|
|
537
|
+
}
|
|
538
|
+
else if (input.action === 'reset') {
|
|
539
|
+
args.push(input.area);
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
args.push(input.area);
|
|
543
|
+
if (input.url)
|
|
544
|
+
args.push(input.url);
|
|
545
|
+
if (input.overwrite)
|
|
546
|
+
args.push('--overwrite');
|
|
547
|
+
}
|
|
548
|
+
pushOption(args, '-R', input.repository);
|
|
549
|
+
const timeoutMs = input.action === 'pull' || input.action === 'push' ? NETWORK_TIMEOUT_MS : undefined;
|
|
550
|
+
return renderOutcome(await runFossil(args, { workspace: input.workspace, timeoutMs }));
|
|
551
|
+
});
|
|
455
552
|
server.registerTool('fossil_rebuild', {
|
|
456
553
|
title: 'Rebuild repository',
|
|
457
554
|
description: 'Reconstruct the repository database from its core records, e.g. after changing the fossil schema. WARNING: destructive. It rewrites the repository database; obtain user confirmation first.',
|
|
458
555
|
inputSchema: z.object({
|
|
459
556
|
repository: repoPathParam
|
|
460
557
|
.optional()
|
|
461
|
-
.describe('Repository database file
|
|
558
|
+
.describe('Repository database file, e.g. `repos/app.fossil`; omit to rebuild the repository of the open check-out.'),
|
|
462
559
|
ifneeded: flag('Rebuild only when the schema version would change (--ifneeded).'),
|
|
463
560
|
compress: flag('Shrink the database while rebuilding (--compress).'),
|
|
464
561
|
compress_only: flag('Only run the compression step (--compress-only).'),
|
|
@@ -513,54 +610,4 @@ export function registerAdminTools(server) {
|
|
|
513
610
|
args.push(input.repository);
|
|
514
611
|
return renderOutcome(await runFossil(args, { workspace: input.workspace }));
|
|
515
612
|
});
|
|
516
|
-
server.registerTool('fossil_config', {
|
|
517
|
-
title: 'Project configuration',
|
|
518
|
-
description: 'Export, import, merge, pull, push or reset the configuration areas (ticket, user, skin, …) that live in the repository database.',
|
|
519
|
-
inputSchema: z.object({
|
|
520
|
-
action: z.enum(['export', 'import', 'merge', 'pull', 'push', 'reset']).describe('Configuration method.'),
|
|
521
|
-
area: z
|
|
522
|
-
.enum(['all', 'email', 'interwiki', 'project', 'shun', 'skin', 'ticket', 'user', 'alias', 'subscriber'])
|
|
523
|
-
.optional()
|
|
524
|
-
.describe('Configuration area; required by export, pull, push and reset.'),
|
|
525
|
-
file: z.string().min(1).optional().describe('File to read or write; required by export, import and merge.'),
|
|
526
|
-
url: z.string().min(1).optional().describe('Remote repository for pull/push; the default remote when omitted.'),
|
|
527
|
-
overwrite: flag('Replace local settings with the ones received from the remote (--overwrite).'),
|
|
528
|
-
workspace: workspaceParam,
|
|
529
|
-
}),
|
|
530
|
-
annotations: { openWorldHint: true },
|
|
531
|
-
}, async (input) => {
|
|
532
|
-
const needsArea = ['export', 'pull', 'push', 'reset'].includes(input.action);
|
|
533
|
-
const needsFile = ['export', 'import', 'merge'].includes(input.action);
|
|
534
|
-
if (needsArea && !input.area) {
|
|
535
|
-
return {
|
|
536
|
-
isError: true,
|
|
537
|
-
content: [{ type: 'text', text: `ERROR: \`${input.action}\` requires \`area\`.` }],
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
if (needsFile && !input.file) {
|
|
541
|
-
return {
|
|
542
|
-
isError: true,
|
|
543
|
-
content: [{ type: 'text', text: `ERROR: \`${input.action}\` requires \`file\`.` }],
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
const args = ['config', input.action];
|
|
547
|
-
if (input.action === 'export') {
|
|
548
|
-
args.push(input.area, input.file);
|
|
549
|
-
}
|
|
550
|
-
else if (input.action === 'import' || input.action === 'merge') {
|
|
551
|
-
args.push(input.file);
|
|
552
|
-
}
|
|
553
|
-
else if (input.action === 'reset') {
|
|
554
|
-
args.push(input.area);
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
args.push(input.area);
|
|
558
|
-
if (input.url)
|
|
559
|
-
args.push(input.url);
|
|
560
|
-
if (input.overwrite)
|
|
561
|
-
args.push('--overwrite');
|
|
562
|
-
}
|
|
563
|
-
const timeoutMs = input.action === 'pull' || input.action === 'push' ? NETWORK_TIMEOUT_MS : undefined;
|
|
564
|
-
return renderOutcome(await runFossil(args, { workspace: input.workspace, timeoutMs }));
|
|
565
|
-
});
|
|
566
613
|
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { renderOutcome, resolveWorkspace, runFossil, truncateOutput } from '../core/fossil.js';
|
|
5
|
+
import { convertGitignore, renderGlobFile } from '../core/gitignore.js';
|
|
6
|
+
import { runSql } from '../core/sql.js';
|
|
7
|
+
import { flag, pushOption, workspaceParam } from './common.js';
|
|
8
|
+
const repoOptionParam = z
|
|
9
|
+
.string()
|
|
10
|
+
.min(1)
|
|
11
|
+
.optional()
|
|
12
|
+
.describe('Repository database file to read instead of the open check-out, e.g. `repos/app.fossil` (-R). Absolute paths are used verbatim; relative paths resolve against the workspace.');
|
|
13
|
+
/** Utility tools: raw file/artifact/SQL access and ignore-rule conversion. */
|
|
14
|
+
export function registerUtilsTools(server) {
|
|
15
|
+
server.registerTool('fossil_cat', {
|
|
16
|
+
title: 'Cat file revision',
|
|
17
|
+
description: 'Print the content of a file at a given revision.',
|
|
18
|
+
inputSchema: z.object({
|
|
19
|
+
file: z.string().min(1).describe('File path/name inside the repository.'),
|
|
20
|
+
revision: z.string().min(1).optional().describe('Check-in or revision (-r). Defaults to the checked-out version.'),
|
|
21
|
+
repository: repoOptionParam,
|
|
22
|
+
workspace: workspaceParam,
|
|
23
|
+
}),
|
|
24
|
+
annotations: { readOnlyHint: true },
|
|
25
|
+
}, async ({ file, revision, repository, workspace }) => {
|
|
26
|
+
const args = ['cat', file];
|
|
27
|
+
pushOption(args, '-R', repository);
|
|
28
|
+
pushOption(args, '-r', revision);
|
|
29
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
30
|
+
});
|
|
31
|
+
server.registerTool('fossil_grep', {
|
|
32
|
+
title: 'Grep history',
|
|
33
|
+
description: 'Match a POSIX extended regular expression over every historical version of the named files, ' +
|
|
34
|
+
'starting at the newest version of each file.',
|
|
35
|
+
inputSchema: z.object({
|
|
36
|
+
pattern: z.string().min(1).describe('POSIX extended regular expression.'),
|
|
37
|
+
files: z.array(z.string().min(1)).min(1).describe('Files to search, newest version first.'),
|
|
38
|
+
ignore_case: flag('Case-insensitive match (-i).'),
|
|
39
|
+
count: flag('Print the number of matching files only (-c).'),
|
|
40
|
+
files_with_matches: flag('Print one artifact hash per matching file instead of the lines (-l).'),
|
|
41
|
+
once: flag('Stop at the first match (--once).'),
|
|
42
|
+
invert_match: flag('Show only files without a match (-v).'),
|
|
43
|
+
no_messages: flag('Suppress messages about unreadable files (-s).'),
|
|
44
|
+
verbose: flag('Report each file as it is analysed (--verbose).'),
|
|
45
|
+
workspace: workspaceParam,
|
|
46
|
+
}),
|
|
47
|
+
annotations: { readOnlyHint: true },
|
|
48
|
+
}, async ({ pattern, files, ignore_case, count, files_with_matches, once, invert_match, no_messages, verbose, workspace, }) => {
|
|
49
|
+
const args = ['grep'];
|
|
50
|
+
if (ignore_case)
|
|
51
|
+
args.push('-i');
|
|
52
|
+
if (count)
|
|
53
|
+
args.push('-c');
|
|
54
|
+
if (files_with_matches)
|
|
55
|
+
args.push('-l');
|
|
56
|
+
if (once)
|
|
57
|
+
args.push('--once');
|
|
58
|
+
if (invert_match)
|
|
59
|
+
args.push('-v');
|
|
60
|
+
if (no_messages)
|
|
61
|
+
args.push('-s');
|
|
62
|
+
if (verbose)
|
|
63
|
+
args.push('--verbose');
|
|
64
|
+
args.push(pattern, ...files);
|
|
65
|
+
return renderOutcome(await runFossil(args, { workspace }), { emptyText: 'No matches.' });
|
|
66
|
+
});
|
|
67
|
+
server.registerTool('fossil_whatis', {
|
|
68
|
+
title: 'What is',
|
|
69
|
+
description: 'Resolve a name (tag, branch, hash prefix, or with file: the content hash) to its artifact hash and role.',
|
|
70
|
+
inputSchema: z.object({
|
|
71
|
+
name: z.string().min(1).describe('Symbol to resolve: tag, branch, hash prefix or filename.'),
|
|
72
|
+
file: flag('Treat name as a file whose content hash is looked up (-f).'),
|
|
73
|
+
type: z.enum(['ci', 't', 'w', 'g', 'e']).optional().describe('Only match this artifact type (--type).'),
|
|
74
|
+
verbose: flag('Include the internal record id (-v).'),
|
|
75
|
+
workspace: workspaceParam,
|
|
76
|
+
}),
|
|
77
|
+
annotations: { readOnlyHint: true },
|
|
78
|
+
}, async ({ name, file, type, verbose, workspace }) => {
|
|
79
|
+
const args = ['whatis'];
|
|
80
|
+
if (file)
|
|
81
|
+
args.push('-f');
|
|
82
|
+
pushOption(args, '--type', type);
|
|
83
|
+
if (verbose)
|
|
84
|
+
args.push('-v');
|
|
85
|
+
args.push(name);
|
|
86
|
+
return renderOutcome(await runFossil(args, { workspace }));
|
|
87
|
+
});
|
|
88
|
+
server.registerTool('fossil_ignore_from_gitignore', {
|
|
89
|
+
title: 'Ignore glob from .gitignore',
|
|
90
|
+
description: 'Convert a .gitignore file into the ignore-glob patterns Fossil matches against check-out paths, ' +
|
|
91
|
+
'and optionally write them to .fossil-settings/ignore-glob.',
|
|
92
|
+
inputSchema: z.object({
|
|
93
|
+
source: z.string().min(1).default('.gitignore').describe('File to convert, relative to the workspace.'),
|
|
94
|
+
write: flag('Write the patterns to .fossil-settings/ignore-glob.'),
|
|
95
|
+
overwrite: flag('Replace an existing .fossil-settings/ignore-glob.'),
|
|
96
|
+
workspace: workspaceParam,
|
|
97
|
+
}),
|
|
98
|
+
}, async ({ source, write, overwrite, workspace }) => {
|
|
99
|
+
const root = resolveWorkspace(workspace);
|
|
100
|
+
const sourcePath = path.resolve(root, source);
|
|
101
|
+
const relative = path.relative(root, sourcePath);
|
|
102
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
103
|
+
return {
|
|
104
|
+
content: [{ type: 'text', text: `ERROR: \`source\` must stay inside the workspace (${root}).` }],
|
|
105
|
+
isError: true,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
let content;
|
|
109
|
+
try {
|
|
110
|
+
content = await readFile(sourcePath, 'utf8');
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const code = error.code ?? 'unknown error';
|
|
114
|
+
return {
|
|
115
|
+
content: [{ type: 'text', text: `ERROR: cannot read ${relative}: ${code}.` }],
|
|
116
|
+
isError: true,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const directory = path.dirname(relative);
|
|
120
|
+
const conversion = convertGitignore(content, { prefix: directory === '.' ? '' : directory });
|
|
121
|
+
const lines = [
|
|
122
|
+
`Converted ${conversion.lineCount} rules from ${relative} into ${conversion.patterns.length} ignore-glob patterns.`,
|
|
123
|
+
'',
|
|
124
|
+
...conversion.patterns,
|
|
125
|
+
];
|
|
126
|
+
if (conversion.warnings.length > 0) {
|
|
127
|
+
lines.push('', ...conversion.warnings.map((warning) => `NOTE: ${warning}.`));
|
|
128
|
+
}
|
|
129
|
+
if (!write)
|
|
130
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
131
|
+
const settingsDir = path.join(root, '.fossil-settings');
|
|
132
|
+
const target = path.join(settingsDir, 'ignore-glob');
|
|
133
|
+
const exists = await stat(target).then(() => true, () => false);
|
|
134
|
+
if (exists && !overwrite) {
|
|
135
|
+
return {
|
|
136
|
+
content: [
|
|
137
|
+
{
|
|
138
|
+
type: 'text',
|
|
139
|
+
text: 'ERROR: .fossil-settings/ignore-glob already exists; pass `overwrite: true` to replace it.',
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
isError: true,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
await mkdir(settingsDir, { recursive: true });
|
|
146
|
+
await writeFile(target, renderGlobFile(conversion), 'utf8');
|
|
147
|
+
lines.splice(1, 0, 'Wrote .fossil-settings/ignore-glob.');
|
|
148
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
149
|
+
});
|
|
150
|
+
server.registerTool('fossil_search', {
|
|
151
|
+
title: 'Search timeline',
|
|
152
|
+
description: 'Search check-in and other timeline comments for every given word and print the best matches.',
|
|
153
|
+
inputSchema: z.object({
|
|
154
|
+
pattern: z.string().min(1).describe('Words to look for; all of them must match.'),
|
|
155
|
+
all: flag('Print every match instead of only the best scoring ones (--all).'),
|
|
156
|
+
limit: z.number().int().min(1).optional().describe('Maximum number of matches (-n).'),
|
|
157
|
+
width: z.number().int().min(0).optional().describe('Output width in columns; 0 means no wrapping (-W).'),
|
|
158
|
+
workspace: workspaceParam,
|
|
159
|
+
}),
|
|
160
|
+
annotations: { readOnlyHint: true },
|
|
161
|
+
}, async ({ pattern, all, limit, width, workspace }) => {
|
|
162
|
+
const args = ['search'];
|
|
163
|
+
if (all)
|
|
164
|
+
args.push('-a');
|
|
165
|
+
if (limit !== undefined)
|
|
166
|
+
args.push('-n', String(limit));
|
|
167
|
+
if (width !== undefined)
|
|
168
|
+
args.push('-W', String(width));
|
|
169
|
+
args.push(pattern);
|
|
170
|
+
const outcome = await runFossil(args, { workspace });
|
|
171
|
+
// fossil reports an empty result set as "+++ no more data (0) +++".
|
|
172
|
+
if (outcome.ok && /^\+{3} no more data \(0\) \+{3}$/.test(outcome.stdout.trim())) {
|
|
173
|
+
return { content: [{ type: 'text', text: 'No matches.' }] };
|
|
174
|
+
}
|
|
175
|
+
return renderOutcome(outcome, { emptyText: 'No matches.' });
|
|
176
|
+
});
|
|
177
|
+
server.registerTool('fossil_artifact', {
|
|
178
|
+
title: 'Artifact content',
|
|
179
|
+
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.',
|
|
180
|
+
inputSchema: z.object({
|
|
181
|
+
artifact: z.string().min(1).describe('Artifact hash, or a unique prefix of it.'),
|
|
182
|
+
repository: repoOptionParam,
|
|
183
|
+
workspace: workspaceParam,
|
|
184
|
+
}),
|
|
185
|
+
annotations: { readOnlyHint: true },
|
|
186
|
+
}, async ({ artifact, repository, workspace }) => renderOutcome(await runFossil(repository ? ['artifact', '-R', repository, artifact] : ['artifact', artifact], { workspace })));
|
|
187
|
+
server.registerTool('fossil_sql', {
|
|
188
|
+
title: 'SQL query',
|
|
189
|
+
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`.',
|
|
190
|
+
inputSchema: z.object({
|
|
191
|
+
query: z.string().min(1).describe('SQL statement, e.g. "SELECT name FROM blob LIMIT 5".'),
|
|
192
|
+
repository: repoOptionParam.describe('Repository database file, e.g. `repos/app.fossil`, to query instead of the one of the check-out (-R).'),
|
|
193
|
+
database: z
|
|
194
|
+
.string()
|
|
195
|
+
.min(1)
|
|
196
|
+
.optional()
|
|
197
|
+
.describe('Standalone SQLite file to query in place of a repository (--no-repository), e.g. a chat archive.'),
|
|
198
|
+
workspace: workspaceParam,
|
|
199
|
+
}),
|
|
200
|
+
annotations: { readOnlyHint: true },
|
|
201
|
+
}, async ({ query, repository, database, workspace }) => {
|
|
202
|
+
const trimmed = query.trim().replace(/;+\s*$/, '');
|
|
203
|
+
if (!/^(select|with|pragma|explain)\b/i.test(trimmed)) {
|
|
204
|
+
return {
|
|
205
|
+
isError: true,
|
|
206
|
+
content: [
|
|
207
|
+
{
|
|
208
|
+
type: 'text',
|
|
209
|
+
text: 'ERROR: the query must start with SELECT, WITH, PRAGMA or EXPLAIN.',
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const result = await runSql(trimmed, { workspace, readonly: true, repository, database });
|
|
215
|
+
if (!result.ok)
|
|
216
|
+
return { isError: true, content: [{ type: 'text', text: result.error }] };
|
|
217
|
+
if (result.rows.length === 0)
|
|
218
|
+
return { content: [{ type: 'text', text: 'No rows.' }] };
|
|
219
|
+
const columns = Object.keys(result.rows[0] ?? {});
|
|
220
|
+
const cell = (value) => {
|
|
221
|
+
if (value === null || value === undefined)
|
|
222
|
+
return 'NULL';
|
|
223
|
+
if (typeof value === 'object')
|
|
224
|
+
return JSON.stringify(value);
|
|
225
|
+
return String(value);
|
|
226
|
+
};
|
|
227
|
+
const lines = [columns.join('\t'), ...result.rows.map((row) => columns.map((column) => cell(row[column])).join('\t'))];
|
|
228
|
+
return {
|
|
229
|
+
content: [
|
|
230
|
+
{
|
|
231
|
+
type: 'text',
|
|
232
|
+
text: truncateOutput(`${lines.join('\n')}\n\n${result.rows.length} row(s).`),
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
}
|