@stellar_ai/mcp_fossil_scm 0.1.1 → 0.1.3

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