@j0hanz/filesystem-mcp 1.19.0 → 2.0.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 +333 -838
- package/dist/cli-help.d.ts +3 -0
- package/dist/cli-help.d.ts.map +1 -0
- package/dist/cli-help.js +169 -0
- package/dist/cli-help.js.map +1 -0
- package/dist/cli.d.ts +28 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +168 -123
- package/dist/cli.js.map +1 -0
- package/dist/core/concurrency.d.ts +70 -0
- package/dist/core/concurrency.d.ts.map +1 -0
- package/dist/core/concurrency.js +173 -0
- package/dist/core/concurrency.js.map +1 -0
- package/dist/core/config.d.ts +19 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +11 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/cursor.d.ts +23 -0
- package/dist/core/cursor.d.ts.map +1 -0
- package/dist/core/cursor.js +62 -0
- package/dist/core/cursor.js.map +1 -0
- package/dist/core/errors.d.ts +96 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +356 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/file-uri.d.ts +24 -0
- package/dist/core/file-uri.d.ts.map +1 -0
- package/dist/core/file-uri.js +52 -0
- package/dist/core/file-uri.js.map +1 -0
- package/dist/core/fmt.d.ts +38 -0
- package/dist/core/fmt.d.ts.map +1 -0
- package/dist/core/fmt.js +109 -0
- package/dist/core/fmt.js.map +1 -0
- package/dist/core/fs.d.ts +108 -0
- package/dist/core/fs.d.ts.map +1 -0
- package/dist/core/fs.js +243 -0
- package/dist/core/fs.js.map +1 -0
- package/dist/core/glob.d.ts +41 -0
- package/dist/core/glob.d.ts.map +1 -0
- package/dist/core/glob.js +399 -0
- package/dist/core/glob.js.map +1 -0
- package/dist/core/input-required.d.ts +147 -0
- package/dist/core/input-required.d.ts.map +1 -0
- package/dist/core/input-required.js +261 -0
- package/dist/core/input-required.js.map +1 -0
- package/dist/core/mime.d.ts +15 -0
- package/dist/core/mime.d.ts.map +1 -0
- package/dist/core/mime.js +188 -0
- package/dist/core/mime.js.map +1 -0
- package/dist/core/observability.d.ts +10 -0
- package/dist/core/observability.d.ts.map +1 -0
- package/dist/core/observability.js +76 -0
- package/dist/core/observability.js.map +1 -0
- package/dist/core/page-store.d.ts +41 -0
- package/dist/core/page-store.d.ts.map +1 -0
- package/dist/core/page-store.js +74 -0
- package/dist/core/page-store.js.map +1 -0
- package/dist/core/path-completer.d.ts +10 -0
- package/dist/core/path-completer.d.ts.map +1 -0
- package/dist/core/path-completer.js +227 -0
- package/dist/core/path-completer.js.map +1 -0
- package/dist/core/path-discovery.d.ts +8 -0
- package/dist/core/path-discovery.d.ts.map +1 -0
- package/dist/core/path-discovery.js +105 -0
- package/dist/core/path-discovery.js.map +1 -0
- package/dist/core/path-utils.d.ts +9 -0
- package/dist/core/path-utils.d.ts.map +1 -0
- package/dist/core/path-utils.js +121 -0
- package/dist/core/path-utils.js.map +1 -0
- package/dist/core/path.d.ts +148 -0
- package/dist/core/path.d.ts.map +1 -0
- package/dist/core/path.js +674 -0
- package/dist/core/path.js.map +1 -0
- package/dist/core/primitives.d.ts +23 -0
- package/dist/core/primitives.d.ts.map +1 -0
- package/dist/core/primitives.js +54 -0
- package/dist/core/primitives.js.map +1 -0
- package/dist/core/read.d.ts +74 -0
- package/dist/core/read.d.ts.map +1 -0
- package/dist/core/read.js +562 -0
- package/dist/core/read.js.map +1 -0
- package/dist/core/schema.d.ts +139 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +345 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/search.d.ts +100 -0
- package/dist/core/search.d.ts.map +1 -0
- package/dist/core/search.js +248 -0
- package/dist/core/search.js.map +1 -0
- package/dist/core/sensitive.d.ts +6 -0
- package/dist/core/sensitive.d.ts.map +1 -0
- package/dist/core/sensitive.js +142 -0
- package/dist/core/sensitive.js.map +1 -0
- package/dist/core/store.d.ts +57 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/store.js +162 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/util.d.ts +26 -0
- package/dist/core/util.d.ts.map +1 -0
- package/dist/core/util.js +66 -0
- package/dist/core/util.js.map +1 -0
- package/dist/core/watcher-registry.d.ts +68 -0
- package/dist/core/watcher-registry.d.ts.map +1 -0
- package/dist/core/watcher-registry.js +312 -0
- package/dist/core/watcher-registry.js.map +1 -0
- package/dist/http-policy.d.ts +121 -0
- package/dist/http-policy.d.ts.map +1 -0
- package/dist/http-policy.js +340 -0
- package/dist/http-policy.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -41
- package/dist/index.js.map +1 -0
- package/dist/instructions.d.ts +12 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/instructions.js +71 -0
- package/dist/instructions.js.map +1 -0
- package/dist/prompts.d.ts +8 -6
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +74 -168
- package/dist/prompts.js.map +1 -0
- package/dist/resources.d.ts +73 -9
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +392 -163
- package/dist/resources.js.map +1 -0
- package/dist/server.d.ts +62 -1
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +139 -1
- package/dist/server.js.map +1 -0
- package/dist/tools/batch.d.ts +89 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +157 -0
- package/dist/tools/batch.js.map +1 -0
- package/dist/tools/create.d.ts +2 -0
- package/dist/tools/create.d.ts.map +1 -0
- package/dist/tools/create.js +142 -0
- package/dist/tools/create.js.map +1 -0
- package/dist/tools/define.d.ts +110 -0
- package/dist/tools/define.d.ts.map +1 -0
- package/dist/tools/define.js +394 -0
- package/dist/tools/define.js.map +1 -0
- package/dist/tools/delete-file.d.ts +2 -4
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +330 -87
- package/dist/tools/delete-file.js.map +1 -0
- package/dist/tools/diff.d.ts +2 -0
- package/dist/tools/diff.d.ts.map +1 -0
- package/dist/tools/diff.js +94 -0
- package/dist/tools/diff.js.map +1 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +442 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list.d.ts +2 -0
- package/dist/tools/list.d.ts.map +1 -0
- package/dist/tools/list.js +291 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/move.d.ts +2 -0
- package/dist/tools/move.d.ts.map +1 -0
- package/dist/tools/move.js +321 -0
- package/dist/tools/move.js.map +1 -0
- package/dist/tools/patch.d.ts +2 -0
- package/dist/tools/patch.d.ts.map +1 -0
- package/dist/tools/patch.js +155 -0
- package/dist/tools/patch.js.map +1 -0
- package/dist/tools/progress.d.ts +52 -0
- package/dist/tools/progress.d.ts.map +1 -0
- package/dist/tools/progress.js +172 -0
- package/dist/tools/progress.js.map +1 -0
- package/dist/tools/read.d.ts +2 -4
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +398 -152
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/replace-in-files.d.ts +2 -4
- package/dist/tools/replace-in-files.d.ts.map +1 -0
- package/dist/tools/replace-in-files.js +435 -264
- package/dist/tools/replace-in-files.js.map +1 -0
- package/dist/tools/roots.d.ts +2 -4
- package/dist/tools/roots.d.ts.map +1 -0
- package/dist/tools/roots.js +29 -52
- package/dist/tools/roots.js.map +1 -0
- package/dist/tools/search-content.d.ts +2 -4
- package/dist/tools/search-content.d.ts.map +1 -0
- package/dist/tools/search-content.js +262 -228
- package/dist/tools/search-content.js.map +1 -0
- package/dist/tools/search-files.d.ts +2 -4
- package/dist/tools/search-files.d.ts.map +1 -0
- package/dist/tools/search-files.js +162 -161
- package/dist/tools/search-files.js.map +1 -0
- package/dist/tools/stat.d.ts +2 -4
- package/dist/tools/stat.d.ts.map +1 -0
- package/dist/tools/stat.js +202 -62
- package/dist/tools/stat.js.map +1 -0
- package/dist/transport/http.d.ts +5 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +276 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/shared.d.ts +45 -0
- package/dist/transport/shared.d.ts.map +1 -0
- package/dist/transport/shared.js +65 -0
- package/dist/transport/shared.js.map +1 -0
- package/dist/transport/stdio.d.ts +32 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +279 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/transport.d.ts +5 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +4 -0
- package/dist/transport.js.map +1 -0
- package/package.json +37 -46
- package/dist/assets/logo.svg +0 -35
- package/dist/completions.d.ts +0 -2
- package/dist/completions.js +0 -572
- package/dist/config.d.ts +0 -119
- package/dist/config.js +0 -31
- package/dist/lib/abort.d.ts +0 -7
- package/dist/lib/abort.js +0 -81
- package/dist/lib/constants.d.ts +0 -42
- package/dist/lib/constants.js +0 -313
- package/dist/lib/errors.d.ts +0 -28
- package/dist/lib/errors.js +0 -301
- package/dist/lib/file-operations/core.d.ts +0 -53
- package/dist/lib/file-operations/core.js +0 -144
- package/dist/lib/file-operations/metadata.d.ts +0 -77
- package/dist/lib/file-operations/metadata.js +0 -878
- package/dist/lib/file-operations/search.d.ts +0 -46
- package/dist/lib/file-operations/search.js +0 -1194
- package/dist/lib/file-operations/traversal.d.ts +0 -40
- package/dist/lib/file-operations/traversal.js +0 -310
- package/dist/lib/fs-helpers.d.ts +0 -46
- package/dist/lib/fs-helpers.js +0 -606
- package/dist/lib/globs.d.ts +0 -2
- package/dist/lib/globs.js +0 -19
- package/dist/lib/logger.d.ts +0 -27
- package/dist/lib/logger.js +0 -91
- package/dist/lib/observability.d.ts +0 -33
- package/dist/lib/observability.js +0 -373
- package/dist/lib/paths.d.ts +0 -35
- package/dist/lib/paths.js +0 -634
- package/dist/lib/resource-store.d.ts +0 -28
- package/dist/lib/resource-store.js +0 -195
- package/dist/lib/utils.d.ts +0 -7
- package/dist/lib/utils.js +0 -37
- package/dist/lib/zod-codecs.d.ts +0 -2
- package/dist/lib/zod-codecs.js +0 -18
- package/dist/pkg-info.d.ts +0 -7
- package/dist/pkg-info.js +0 -9
- package/dist/resources/generated-instructions.d.ts +0 -1
- package/dist/resources/generated-instructions.js +0 -105
- package/dist/resources/tool-catalog.d.ts +0 -2
- package/dist/resources/tool-catalog.js +0 -78
- package/dist/resources/tool-info.d.ts +0 -9
- package/dist/resources/tool-info.js +0 -206
- package/dist/resources/workflows.d.ts +0 -1
- package/dist/resources/workflows.js +0 -72
- package/dist/schemas.d.ts +0 -505
- package/dist/schemas.js +0 -676
- package/dist/server/bootstrap.d.ts +0 -6
- package/dist/server/bootstrap.js +0 -563
- package/dist/server/event-store.d.ts +0 -18
- package/dist/server/event-store.js +0 -71
- package/dist/server/roots-manager.d.ts +0 -28
- package/dist/server/roots-manager.js +0 -227
- package/dist/server/task-store.d.ts +0 -10
- package/dist/server/task-store.js +0 -91
- package/dist/tools/apply-patch.d.ts +0 -4
- package/dist/tools/apply-patch.js +0 -235
- package/dist/tools/calculate-hash.d.ts +0 -4
- package/dist/tools/calculate-hash.js +0 -187
- package/dist/tools/contract.d.ts +0 -50
- package/dist/tools/contract.js +0 -1
- package/dist/tools/create-directory.d.ts +0 -4
- package/dist/tools/create-directory.js +0 -68
- package/dist/tools/diff-files.d.ts +0 -4
- package/dist/tools/diff-files.js +0 -136
- package/dist/tools/edit-file.d.ts +0 -4
- package/dist/tools/edit-file.js +0 -256
- package/dist/tools/icons.d.ts +0 -15
- package/dist/tools/icons.js +0 -24
- package/dist/tools/list-directory.d.ts +0 -4
- package/dist/tools/list-directory.js +0 -218
- package/dist/tools/move-file.d.ts +0 -4
- package/dist/tools/move-file.js +0 -178
- package/dist/tools/read-multiple.d.ts +0 -4
- package/dist/tools/read-multiple.js +0 -207
- package/dist/tools/shared.d.ts +0 -172
- package/dist/tools/shared.js +0 -599
- package/dist/tools/stat-many.d.ts +0 -4
- package/dist/tools/stat-many.js +0 -104
- package/dist/tools/task-support.d.ts +0 -29
- package/dist/tools/task-support.js +0 -472
- package/dist/tools/tree.d.ts +0 -4
- package/dist/tools/tree.js +0 -102
- package/dist/tools/write-file.d.ts +0 -4
- package/dist/tools/write-file.js +0 -60
- package/dist/tools.d.ts +0 -5
- package/dist/tools.js +0 -54
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { DEFAULT_SEARCH_CONTENT_RESULTS, MAX_SEARCH_RESULTS, MAX_TEXT_FILE_SIZE, } from '../lib/constants.js';
|
|
3
|
-
import { ALL_TOOLS } from '../tools.js';
|
|
4
|
-
function getTaskSupportLabel(taskSupport) {
|
|
5
|
-
switch (taskSupport) {
|
|
6
|
-
case 'optional':
|
|
7
|
-
return '[Task: Optional]';
|
|
8
|
-
case 'required':
|
|
9
|
-
return '[Task: Required]';
|
|
10
|
-
default:
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function toEntry(contract) {
|
|
15
|
-
const annotations = [];
|
|
16
|
-
if (contract.annotations?.destructiveHint)
|
|
17
|
-
annotations.push('[Destructive]');
|
|
18
|
-
if (contract.annotations?.idempotentHint)
|
|
19
|
-
annotations.push('[Idempotent]');
|
|
20
|
-
if (contract.annotations?.readOnlyHint)
|
|
21
|
-
annotations.push('[Read-Only]');
|
|
22
|
-
const taskLabel = getTaskSupportLabel(contract.taskSupport);
|
|
23
|
-
if (taskLabel)
|
|
24
|
-
annotations.push(taskLabel);
|
|
25
|
-
return {
|
|
26
|
-
name: contract.name,
|
|
27
|
-
title: contract.title,
|
|
28
|
-
description: contract.description,
|
|
29
|
-
...(annotations.length > 0 ? { annotations } : {}),
|
|
30
|
-
...(contract.nuances && contract.nuances.length > 0
|
|
31
|
-
? { nuances: contract.nuances }
|
|
32
|
-
: {}),
|
|
33
|
-
...(contract.gotchas && contract.gotchas.length > 0
|
|
34
|
-
? { gotchas: contract.gotchas }
|
|
35
|
-
: {}),
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const ENTRIES = Object.fromEntries(ALL_TOOLS.map((contract) => [contract.name, toEntry(contract)]));
|
|
39
|
-
const CONTRACTS_BY_NAME = new Map(ALL_TOOLS.map((contract) => [contract.name, contract]));
|
|
40
|
-
export function getToolContracts() {
|
|
41
|
-
return ALL_TOOLS;
|
|
42
|
-
}
|
|
43
|
-
export function getSortedToolContracts() {
|
|
44
|
-
return [...ALL_TOOLS].sort((left, right) => left.name.localeCompare(right.name));
|
|
45
|
-
}
|
|
46
|
-
export function pickAvailableToolNames(names) {
|
|
47
|
-
return names.filter((name) => CONTRACTS_BY_NAME.has(name));
|
|
48
|
-
}
|
|
49
|
-
export function formatToolNameList(names) {
|
|
50
|
-
return names.map((name) => `\`${name}\``).join(', ');
|
|
51
|
-
}
|
|
52
|
-
export function getTaskCapableToolNames() {
|
|
53
|
-
return getSortedToolContracts()
|
|
54
|
-
.filter((contract) => contract.taskSupport === 'optional' ||
|
|
55
|
-
contract.taskSupport === 'required')
|
|
56
|
-
.map((contract) => contract.name);
|
|
57
|
-
}
|
|
58
|
-
export function buildCoreContextPack() {
|
|
59
|
-
const rows = getSortedToolContracts().map((contract) => {
|
|
60
|
-
const e = ENTRIES[contract.name];
|
|
61
|
-
if (!e)
|
|
62
|
-
return '';
|
|
63
|
-
const annotations = e.annotations ? ` ${e.annotations.join(' ')}` : '';
|
|
64
|
-
return `| \`${e.name}\` | ${e.description}${annotations} |`;
|
|
65
|
-
});
|
|
66
|
-
return `## Tool Summary\n\n| Tool | Purpose |\n|------|---------|\n${rows.join('\n')}`;
|
|
67
|
-
}
|
|
68
|
-
export function getSharedConstraints() {
|
|
69
|
-
return [
|
|
70
|
-
'Operate within allowed roots only (negotiated at startup via CLI).',
|
|
71
|
-
'Sensitive file paths (e.g. .env, *.pem, *id_rsa*) are denied by default.',
|
|
72
|
-
`Enforced limits: max file size ${Math.floor(MAX_TEXT_FILE_SIZE / 1024 / 1024)} MB, file search cap ${MAX_SEARCH_RESULTS} results, content search cap ${DEFAULT_SEARCH_CONTENT_RESULTS} matches.`,
|
|
73
|
-
'When a response includes `resourceUri`, call `resources/read` immediately — cached results expire on server restart.',
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
function formatTaskSupportLabel(taskSupport) {
|
|
77
|
-
switch (taskSupport) {
|
|
78
|
-
case 'optional':
|
|
79
|
-
return 'optional';
|
|
80
|
-
case 'required':
|
|
81
|
-
return 'required';
|
|
82
|
-
default:
|
|
83
|
-
return 'forbidden';
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function toJsonSchemaObject(schema, io = 'output') {
|
|
87
|
-
return z.toJSONSchema(schema, { io });
|
|
88
|
-
}
|
|
89
|
-
function summarizeArrayType(schema) {
|
|
90
|
-
if (Array.isArray(schema.prefixItems) && schema.prefixItems.length > 0) {
|
|
91
|
-
const itemTypes = schema.prefixItems.map(summarizeSchemaType).join(', ');
|
|
92
|
-
return `tuple<${itemTypes}>`;
|
|
93
|
-
}
|
|
94
|
-
const itemType = schema.items ? summarizeSchemaType(schema.items) : 'unknown';
|
|
95
|
-
return `array<${itemType}>`;
|
|
96
|
-
}
|
|
97
|
-
function summarizeSchemaType(schema) {
|
|
98
|
-
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
99
|
-
return `enum(${schema.enum.map((value) => JSON.stringify(value)).join(', ')})`;
|
|
100
|
-
}
|
|
101
|
-
if (schema.const !== undefined) {
|
|
102
|
-
return `const(${JSON.stringify(schema.const)})`;
|
|
103
|
-
}
|
|
104
|
-
if (Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
|
|
105
|
-
return schema.anyOf.map(summarizeSchemaType).join(' | ');
|
|
106
|
-
}
|
|
107
|
-
if (Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {
|
|
108
|
-
return schema.oneOf.map(summarizeSchemaType).join(' | ');
|
|
109
|
-
}
|
|
110
|
-
if (schema.type === 'array') {
|
|
111
|
-
return summarizeArrayType(schema);
|
|
112
|
-
}
|
|
113
|
-
if (schema.type === 'object' && schema.additionalProperties === false) {
|
|
114
|
-
return 'object (strict)';
|
|
115
|
-
}
|
|
116
|
-
if (typeof schema.type === 'string' && schema.type.length > 0) {
|
|
117
|
-
return schema.type;
|
|
118
|
-
}
|
|
119
|
-
return 'unknown';
|
|
120
|
-
}
|
|
121
|
-
function formatFieldLabel(label) {
|
|
122
|
-
return label
|
|
123
|
-
.split('_')
|
|
124
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
125
|
-
.join(' ');
|
|
126
|
-
}
|
|
127
|
-
function buildSchemaFieldLines(label, schema) {
|
|
128
|
-
const heading = `**${formatFieldLabel(label)}:**`;
|
|
129
|
-
if (!schema) {
|
|
130
|
-
return [heading, '- none'];
|
|
131
|
-
}
|
|
132
|
-
const io = label === 'input_fields' ? 'input' : 'output';
|
|
133
|
-
const jsonSchema = toJsonSchemaObject(schema, io);
|
|
134
|
-
const properties = jsonSchema.properties ?? {};
|
|
135
|
-
const required = new Set(jsonSchema.required ?? []);
|
|
136
|
-
const fieldNames = Object.keys(properties);
|
|
137
|
-
const lines = [heading];
|
|
138
|
-
if (typeof jsonSchema.description === 'string' &&
|
|
139
|
-
jsonSchema.description.length > 0) {
|
|
140
|
-
lines.push(`- Schema constraints: ${jsonSchema.description}`);
|
|
141
|
-
}
|
|
142
|
-
if (jsonSchema.additionalProperties === false) {
|
|
143
|
-
lines.push('- Unknown fields are rejected (`additionalProperties: false`).');
|
|
144
|
-
}
|
|
145
|
-
if (fieldNames.length === 0) {
|
|
146
|
-
lines.push('- object with no fields');
|
|
147
|
-
return lines;
|
|
148
|
-
}
|
|
149
|
-
lines.push(...fieldNames.map((fieldName) => {
|
|
150
|
-
const fieldSchema = properties[fieldName] ?? {};
|
|
151
|
-
const type = summarizeSchemaType(fieldSchema);
|
|
152
|
-
const requiredLabel = required.has(fieldName) ? 'required' : 'optional';
|
|
153
|
-
const description = typeof fieldSchema.description === 'string' &&
|
|
154
|
-
fieldSchema.description.length > 0
|
|
155
|
-
? fieldSchema.description
|
|
156
|
-
: 'No description.';
|
|
157
|
-
return `- ${fieldName} (${type}, ${requiredLabel}): ${description}`;
|
|
158
|
-
}));
|
|
159
|
-
return lines;
|
|
160
|
-
}
|
|
161
|
-
export function buildToolInfo(name) {
|
|
162
|
-
const contract = CONTRACTS_BY_NAME.get(name);
|
|
163
|
-
const entry = ENTRIES[name];
|
|
164
|
-
if (!entry || !contract)
|
|
165
|
-
return undefined;
|
|
166
|
-
const annotationLines = [];
|
|
167
|
-
if (contract.annotations?.readOnlyHint)
|
|
168
|
-
annotationLines.push('- readOnlyHint: true');
|
|
169
|
-
if (contract.annotations?.idempotentHint)
|
|
170
|
-
annotationLines.push('- idempotentHint: true');
|
|
171
|
-
if (contract.annotations?.destructiveHint)
|
|
172
|
-
annotationLines.push('- destructiveHint: true');
|
|
173
|
-
if (contract.annotations?.openWorldHint)
|
|
174
|
-
annotationLines.push('- openWorldHint: true');
|
|
175
|
-
const lines = [
|
|
176
|
-
`---`,
|
|
177
|
-
`# ${entry.name}`,
|
|
178
|
-
'',
|
|
179
|
-
`**Title:** ${entry.title}`,
|
|
180
|
-
`**Description:** ${entry.description}`,
|
|
181
|
-
'',
|
|
182
|
-
'**Execution:**',
|
|
183
|
-
`- taskSupport: ${formatTaskSupportLabel(contract.taskSupport)}`,
|
|
184
|
-
'',
|
|
185
|
-
...buildSchemaFieldLines('input_fields', contract.inputSchema),
|
|
186
|
-
'',
|
|
187
|
-
...buildSchemaFieldLines('output_fields', contract.outputSchema),
|
|
188
|
-
];
|
|
189
|
-
if (annotationLines.length > 0) {
|
|
190
|
-
lines.push('', '**Behavior:**', ...annotationLines);
|
|
191
|
-
}
|
|
192
|
-
if (entry.nuances && entry.nuances.length > 0) {
|
|
193
|
-
lines.push('', '**Usage Notes:**');
|
|
194
|
-
for (const nuance of entry.nuances) {
|
|
195
|
-
lines.push(`- ${nuance}`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (entry.gotchas && entry.gotchas.length > 0) {
|
|
199
|
-
lines.push('', '**Warnings:**');
|
|
200
|
-
for (const gotcha of entry.gotchas) {
|
|
201
|
-
lines.push(`- ${gotcha}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
lines.push('---');
|
|
205
|
-
return lines.join('\n');
|
|
206
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function buildWorkflowGuide(): string;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { formatToolNameList, pickAvailableToolNames } from './tool-info.js';
|
|
2
|
-
export function buildWorkflowGuide() {
|
|
3
|
-
const exploreTools = formatToolNameList(pickAvailableToolNames([
|
|
4
|
-
'roots',
|
|
5
|
-
'ls',
|
|
6
|
-
'tree',
|
|
7
|
-
'stat',
|
|
8
|
-
'stat_many',
|
|
9
|
-
'read',
|
|
10
|
-
'read_many',
|
|
11
|
-
]));
|
|
12
|
-
const searchTools = formatToolNameList(pickAvailableToolNames(['find', 'grep', 'read']));
|
|
13
|
-
const editTools = formatToolNameList(pickAvailableToolNames([
|
|
14
|
-
'edit',
|
|
15
|
-
'write',
|
|
16
|
-
'search_and_replace',
|
|
17
|
-
'mv',
|
|
18
|
-
'rm',
|
|
19
|
-
'mkdir',
|
|
20
|
-
]));
|
|
21
|
-
return `## Workflows
|
|
22
|
-
|
|
23
|
-
### A: Explore — Discover directory layout or file content
|
|
24
|
-
|
|
25
|
-
**Tools:** ${exploreTools}
|
|
26
|
-
|
|
27
|
-
1. Start with \`roots\` to identify allowed directories.
|
|
28
|
-
2. Use \`ls\` or \`tree\` to map structure, then \`stat\` or \`read\` for details.
|
|
29
|
-
|
|
30
|
-
> Resolve paths before acting. Never assume a path exists.
|
|
31
|
-
|
|
32
|
-
### B: Search — Find files by name or content
|
|
33
|
-
|
|
34
|
-
**Tools:** ${searchTools}
|
|
35
|
-
|
|
36
|
-
1. Use \`find\` for file name/glob matching.
|
|
37
|
-
2. Use \`grep\` for content search (supports regex).
|
|
38
|
-
3. Use \`read\` to inspect matched files.
|
|
39
|
-
|
|
40
|
-
> Use \`grep\` for content, \`find\` for filenames. Do not conflate them.
|
|
41
|
-
|
|
42
|
-
### C: Edit — Modify files or directory layout
|
|
43
|
-
|
|
44
|
-
**Tools:** ${editTools}
|
|
45
|
-
|
|
46
|
-
1. Use \`edit\` for targeted single-file changes (exact text match → replace).
|
|
47
|
-
2. Use \`search_and_replace\` for bulk changes across multiple files.
|
|
48
|
-
3. Use \`mv\`, \`rm\`, \`mkdir\` for structural changes.
|
|
49
|
-
|
|
50
|
-
> Confirm destructive operations (\`write\`, \`mv\`, \`rm\`, bulk replace) before executing.
|
|
51
|
-
|
|
52
|
-
### D: Patch — Generate and apply unified diffs
|
|
53
|
-
|
|
54
|
-
1. Generate: \`diff_files(original, modified)\`.
|
|
55
|
-
2. Validate: \`apply_patch(patch, dryRun: true)\`.
|
|
56
|
-
3. Apply: \`apply_patch(patch)\`.
|
|
57
|
-
|
|
58
|
-
> Multi-file patches: set \`path\` to the base directory. Results are reported per file.
|
|
59
|
-
|
|
60
|
-
### E: Task Mode — Deferred execution with polling
|
|
61
|
-
|
|
62
|
-
Use task mode for long-running operations when durable polling or cancellation is needed.
|
|
63
|
-
Only tools with \`execution.taskSupport: "optional"\` or \`"required"\` support this.
|
|
64
|
-
|
|
65
|
-
1. Send \`tools/call\` with \`task: {}\` in the request to create a task.
|
|
66
|
-
2. Poll \`tasks/get({ taskId })\` until status reaches \`completed\`, \`failed\`, or \`cancelled\`.
|
|
67
|
-
3. Retrieve the final result via \`tasks/result({ taskId })\`.
|
|
68
|
-
4. Cancel with \`tasks/cancel({ taskId })\` if no longer needed.
|
|
69
|
-
|
|
70
|
-
> Do not send \`task\` metadata to tools with \`taskSupport: "forbidden"\` (the default).
|
|
71
|
-
`;
|
|
72
|
-
}
|