@aigne/doc-smith 0.8.11-beta.5 → 0.8.11-beta.7
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/.aigne/doc-smith/config.yaml +3 -1
- package/.aigne/doc-smith/output/structure-plan.json +2 -2
- package/.aigne/doc-smith/preferences.yml +28 -20
- package/.aigne/doc-smith/upload-cache.yaml +702 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +22 -2
- package/README.md +2 -2
- package/agents/clear/choose-contents.mjs +2 -2
- package/agents/clear/clear-document-structure.mjs +8 -8
- package/agents/clear/index.yaml +1 -1
- package/agents/evaluate/document-structure.yaml +1 -1
- package/agents/generate/check-document-structure.yaml +3 -3
- package/agents/generate/check-need-generate-structure.mjs +8 -8
- package/agents/generate/document-structure-tools/add-document.mjs +38 -13
- package/agents/generate/document-structure-tools/delete-document.mjs +37 -14
- package/agents/generate/document-structure-tools/move-document.mjs +46 -19
- package/agents/generate/document-structure-tools/update-document.mjs +39 -12
- package/agents/generate/generate-structure.yaml +1 -1
- package/agents/generate/update-document-structure.yaml +3 -9
- package/agents/generate/user-review-document-structure.mjs +15 -14
- package/agents/translate/translate-document.yaml +1 -9
- package/agents/update/batch-generate-document.yaml +1 -1
- package/agents/update/check-document.mjs +2 -2
- package/agents/update/check-update-is-single.mjs +2 -1
- package/agents/update/document-tools/update-document-content.mjs +24 -14
- package/agents/update/fs-tools/glob.mjs +184 -0
- package/agents/update/fs-tools/grep.mjs +317 -0
- package/agents/update/fs-tools/read-file.mjs +307 -0
- package/agents/update/generate-document.yaml +4 -7
- package/agents/update/update-document-detail.yaml +6 -10
- package/agents/update/user-review-document.mjs +13 -13
- package/agents/utils/check-feedback-refiner.mjs +1 -1
- package/agents/utils/choose-docs.mjs +1 -1
- package/agents/utils/load-document-all-content.mjs +3 -3
- package/agents/utils/load-sources.mjs +1 -1
- package/agents/utils/save-docs.mjs +7 -28
- package/aigne.yaml +2 -2
- package/assets/screenshots/doc-complete-setup.png +0 -0
- package/assets/screenshots/doc-generate-docs.png +0 -0
- package/assets/screenshots/doc-generate.png +0 -0
- package/assets/screenshots/doc-generated-successfully.png +0 -0
- package/assets/screenshots/doc-publish.png +0 -0
- package/assets/screenshots/doc-regenerate.png +0 -0
- package/assets/screenshots/doc-translate-langs.png +0 -0
- package/assets/screenshots/doc-translate.png +0 -0
- package/assets/screenshots/doc-update.png +0 -0
- package/docs/_sidebar.md +1 -1
- package/docs/advanced-how-it-works.ja.md +31 -31
- package/docs/advanced-how-it-works.md +10 -10
- package/docs/advanced-how-it-works.zh-TW.md +24 -24
- package/docs/advanced-how-it-works.zh.md +20 -20
- package/docs/advanced-quality-assurance.ja.md +57 -61
- package/docs/advanced-quality-assurance.md +57 -61
- package/docs/advanced-quality-assurance.zh-TW.md +57 -61
- package/docs/advanced-quality-assurance.zh.md +57 -61
- package/docs/advanced.ja.md +8 -4
- package/docs/advanced.md +7 -3
- package/docs/advanced.zh-TW.md +9 -5
- package/docs/advanced.zh.md +9 -5
- package/docs/changelog.ja.md +206 -29
- package/docs/changelog.md +177 -0
- package/docs/changelog.zh-TW.md +229 -52
- package/docs/changelog.zh.md +204 -27
- package/docs/cli-reference.ja.md +181 -80
- package/docs/cli-reference.md +168 -67
- package/docs/cli-reference.zh-TW.md +177 -76
- package/docs/cli-reference.zh.md +172 -71
- package/docs/configuration-interactive-setup.ja.md +45 -42
- package/docs/configuration-interactive-setup.md +9 -6
- package/docs/configuration-interactive-setup.zh-TW.md +26 -23
- package/docs/configuration-interactive-setup.zh.md +25 -22
- package/docs/configuration-language-support.ja.md +33 -63
- package/docs/configuration-language-support.md +32 -62
- package/docs/configuration-language-support.zh-TW.md +35 -65
- package/docs/configuration-language-support.zh.md +32 -62
- package/docs/configuration-llm-setup.ja.md +25 -23
- package/docs/configuration-llm-setup.md +20 -18
- package/docs/configuration-llm-setup.zh-TW.md +21 -19
- package/docs/configuration-llm-setup.zh.md +20 -18
- package/docs/configuration-preferences.ja.md +67 -52
- package/docs/configuration-preferences.md +55 -40
- package/docs/configuration-preferences.zh-TW.md +69 -54
- package/docs/configuration-preferences.zh.md +68 -53
- package/docs/configuration.ja.md +98 -58
- package/docs/configuration.md +42 -2
- package/docs/configuration.zh-TW.md +86 -46
- package/docs/configuration.zh.md +76 -36
- package/docs/features-generate-documentation.ja.md +49 -55
- package/docs/features-generate-documentation.md +49 -55
- package/docs/features-generate-documentation.zh-TW.md +54 -60
- package/docs/features-generate-documentation.zh.md +48 -54
- package/docs/features-publish-your-docs.ja.md +68 -45
- package/docs/features-publish-your-docs.md +65 -42
- package/docs/features-publish-your-docs.zh-TW.md +74 -51
- package/docs/features-publish-your-docs.zh.md +67 -44
- package/docs/features-translate-documentation.ja.md +46 -35
- package/docs/features-translate-documentation.md +39 -28
- package/docs/features-translate-documentation.zh-TW.md +45 -34
- package/docs/features-translate-documentation.zh.md +39 -28
- package/docs/features-update-and-refine.ja.md +75 -71
- package/docs/features-update-and-refine.md +67 -63
- package/docs/features-update-and-refine.zh-TW.md +72 -67
- package/docs/features-update-and-refine.zh.md +71 -67
- package/docs/features.ja.md +29 -19
- package/docs/features.md +25 -15
- package/docs/features.zh-TW.md +28 -18
- package/docs/features.zh.md +31 -21
- package/docs/getting-started.ja.md +43 -46
- package/docs/getting-started.md +36 -39
- package/docs/getting-started.zh-TW.md +41 -44
- package/docs/getting-started.zh.md +39 -42
- package/docs/overview.ja.md +63 -11
- package/docs/overview.md +62 -10
- package/docs/overview.zh-TW.md +67 -15
- package/docs/overview.zh.md +62 -10
- package/docs-mcp/analyze-docs-relevance.yaml +6 -6
- package/docs-mcp/docs-search.yaml +1 -1
- package/media.md +9 -9
- package/package.json +2 -2
- package/prompts/common/document-structure/conflict-resolution-guidance.md +3 -3
- package/prompts/common/document-structure/document-structure-rules.md +2 -2
- package/prompts/detail/custom/custom-components.md +304 -188
- package/prompts/detail/document-rules.md +5 -5
- package/prompts/detail/generate-document.md +21 -8
- package/prompts/detail/update-document.md +8 -12
- package/prompts/evaluate/document-structure.md +6 -6
- package/prompts/structure/check-document-structure.md +10 -10
- package/prompts/structure/document-rules.md +2 -2
- package/prompts/structure/generate-structure-system.md +3 -3
- package/prompts/structure/structure-example.md +1 -1
- package/prompts/structure/structure-getting-started.md +1 -1
- package/prompts/structure/update-document-structure.md +18 -14
- package/prompts/utils/feedback-refiner.md +3 -3
- package/tests/agents/clear/choose-contents.test.mjs +1 -1
- package/tests/agents/clear/clear-document-structure.test.mjs +36 -30
- package/tests/agents/evaluate/generate-report.test.mjs +1 -1
- package/tests/agents/generate/check-need-generate-structure.test.mjs +1 -1
- package/tests/agents/generate/document-structure-tools/add-document.test.mjs +2 -2
- package/tests/agents/generate/document-structure-tools/delete-document.test.mjs +4 -4
- package/tests/agents/generate/document-structure-tools/move-document.test.mjs +12 -12
- package/tests/agents/generate/document-structure-tools/update-document.test.mjs +3 -3
- package/tests/agents/generate/user-review-document-structure.test.mjs +36 -13
- package/tests/agents/update/check-document.test.mjs +1 -1
- package/tests/agents/update/document-tools/update-document-content.test.mjs +115 -112
- package/tests/agents/update/fs-tools/glob.test.mjs +438 -0
- package/tests/agents/update/fs-tools/grep.test.mjs +279 -0
- package/tests/agents/update/fs-tools/read-file.test.mjs +553 -0
- package/tests/agents/update/user-review-document.test.mjs +48 -27
- package/tests/agents/utils/format-document-structure.test.mjs +5 -5
- package/tests/agents/utils/load-sources.test.mjs +4 -4
- package/tests/agents/utils/save-docs.test.mjs +1 -1
- package/tests/utils/conflict-detector.test.mjs +1 -1
- package/tests/utils/docs-finder-utils.test.mjs +8 -8
- package/types/document-schema.mjs +5 -6
- package/types/document-structure-schema.mjs +25 -13
- package/utils/conflict-detector.mjs +1 -1
- package/utils/constants/index.mjs +4 -4
- package/utils/docs-finder-utils.mjs +11 -11
- package/utils/markdown-checker.mjs +1 -1
|
@@ -48,13 +48,13 @@ function formatDocumentStructure(structure) {
|
|
|
48
48
|
|
|
49
49
|
function printDocumentStructure(structure) {
|
|
50
50
|
console.log(`\n ${"-".repeat(50)}`);
|
|
51
|
-
console.log(" Current
|
|
51
|
+
console.log(" Current Documentation Structure");
|
|
52
52
|
console.log(` ${"-".repeat(50)}`);
|
|
53
53
|
|
|
54
54
|
const { rootNodes, printNode } = formatDocumentStructure(structure);
|
|
55
55
|
|
|
56
56
|
if (rootNodes.length === 0) {
|
|
57
|
-
console.log(" No
|
|
57
|
+
console.log(" No documentation structure found.");
|
|
58
58
|
} else {
|
|
59
59
|
rootNodes.forEach((node) => {
|
|
60
60
|
printNode(node);
|
|
@@ -64,19 +64,19 @@ function printDocumentStructure(structure) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export default async function userReviewDocumentStructure({ documentStructure, ...rest }, options) {
|
|
67
|
-
// Check if
|
|
67
|
+
// Check if documentation structure exists
|
|
68
68
|
if (!documentStructure || !Array.isArray(documentStructure) || documentStructure.length === 0) {
|
|
69
|
-
console.log("No
|
|
69
|
+
console.log("No documentation structure was generated to review.");
|
|
70
70
|
return { documentStructure };
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
// Print current
|
|
73
|
+
// Print current documentation structure in a user-friendly format
|
|
74
74
|
printDocumentStructure(documentStructure);
|
|
75
75
|
|
|
76
|
-
// Ask user if they want to review the
|
|
76
|
+
// Ask user if they want to review the documentation structure
|
|
77
77
|
const needReview = await options.prompts.select({
|
|
78
78
|
message:
|
|
79
|
-
"Would you like to optimize the
|
|
79
|
+
"Would you like to optimize the documentation structure?\n You can edit titles, reorganize sections.",
|
|
80
80
|
choices: [
|
|
81
81
|
{
|
|
82
82
|
name: "Looks good - proceed with current structure",
|
|
@@ -97,6 +97,9 @@ export default async function userReviewDocumentStructure({ documentStructure, .
|
|
|
97
97
|
|
|
98
98
|
const MAX_ITERATIONS = 100;
|
|
99
99
|
let iterationCount = 0;
|
|
100
|
+
|
|
101
|
+
// share current structure with updateDocumentStructure agent
|
|
102
|
+
options.context.userContext.currentStructure = currentStructure;
|
|
100
103
|
while (iterationCount < MAX_ITERATIONS) {
|
|
101
104
|
iterationCount++;
|
|
102
105
|
|
|
@@ -117,7 +120,7 @@ export default async function userReviewDocumentStructure({ documentStructure, .
|
|
|
117
120
|
const refineAgent = options.context.agents["updateDocumentStructure"];
|
|
118
121
|
if (!refineAgent) {
|
|
119
122
|
console.log(
|
|
120
|
-
"Unable to process your feedback - the
|
|
123
|
+
"Unable to process your feedback - the documentation structure update feature is unavailable.",
|
|
121
124
|
);
|
|
122
125
|
console.log("Please try again later or contact support if this continues.");
|
|
123
126
|
break;
|
|
@@ -132,16 +135,14 @@ export default async function userReviewDocumentStructure({ documentStructure, .
|
|
|
132
135
|
|
|
133
136
|
try {
|
|
134
137
|
// Call refineDocumentStructure agent with feedback
|
|
135
|
-
|
|
138
|
+
await options.context.invoke(refineAgent, {
|
|
136
139
|
...rest,
|
|
137
140
|
feedback: feedback.trim(),
|
|
138
141
|
documentStructure: currentStructure,
|
|
139
142
|
userPreferences,
|
|
140
143
|
});
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
currentStructure = result.documentStructure;
|
|
144
|
-
}
|
|
145
|
+
currentStructure = options.context.userContext.currentStructure;
|
|
145
146
|
|
|
146
147
|
// Check if feedback should be saved as user preference
|
|
147
148
|
const feedbackRefinerAgent = options.context.agents["checkFeedbackRefiner"];
|
|
@@ -157,7 +158,7 @@ export default async function userReviewDocumentStructure({ documentStructure, .
|
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
// Print current
|
|
161
|
+
// Print current documentation structure in a user-friendly format
|
|
161
162
|
printDocumentStructure(currentStructure);
|
|
162
163
|
} catch (error) {
|
|
163
164
|
console.error("Error processing your feedback:");
|
|
@@ -172,4 +173,4 @@ export default async function userReviewDocumentStructure({ documentStructure, .
|
|
|
172
173
|
return { documentStructure: currentStructure };
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
userReviewDocumentStructure.taskTitle = "User review and modify
|
|
176
|
+
userReviewDocumentStructure.taskTitle = "User review and modify documentation structure";
|
|
@@ -21,12 +21,4 @@ input_schema:
|
|
|
21
21
|
required:
|
|
22
22
|
- language
|
|
23
23
|
- content
|
|
24
|
-
|
|
25
|
-
type: object
|
|
26
|
-
properties:
|
|
27
|
-
translation:
|
|
28
|
-
type: string
|
|
29
|
-
description: Translated text
|
|
30
|
-
language:
|
|
31
|
-
type: string
|
|
32
|
-
description: Language code of the translation
|
|
24
|
+
output_key: translation
|
|
@@ -8,7 +8,7 @@ input_schema:
|
|
|
8
8
|
properties:
|
|
9
9
|
datasources:
|
|
10
10
|
type: string
|
|
11
|
-
description: Context for
|
|
11
|
+
description: Context for documentation structure generation, used to assist generate documentation structure
|
|
12
12
|
documentExecutionStructure: ../schema/document-execution-structure.yaml
|
|
13
13
|
modifiedFiles:
|
|
14
14
|
type: array
|
|
@@ -36,10 +36,10 @@ export default async function checkDocument(
|
|
|
36
36
|
detailGenerated = false;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// Check if sourceIds have changed by comparing with original
|
|
39
|
+
// Check if sourceIds have changed by comparing with original documentation structure
|
|
40
40
|
let sourceIdsChanged = false;
|
|
41
41
|
if (originalDocumentStructure && sourceIds) {
|
|
42
|
-
// Find the original node in the
|
|
42
|
+
// Find the original node in the documentation structure
|
|
43
43
|
const originalNode = originalDocumentStructure.find((node) => node.path === path);
|
|
44
44
|
|
|
45
45
|
if (originalNode?.sourceIds) {
|
|
@@ -10,7 +10,8 @@ export default async function checkUpdateIsSingle({ selectedDocs, ...rest }, opt
|
|
|
10
10
|
let targetAgent;
|
|
11
11
|
let agentName;
|
|
12
12
|
|
|
13
|
-
if (selectedDocs.length === 1) {
|
|
13
|
+
if (selectedDocs.length === 1 && !rest.reset) {
|
|
14
|
+
// Single doc update without reset
|
|
14
15
|
agentName = "updateSingleDocument";
|
|
15
16
|
targetAgent = options.context.agents["updateSingleDocument"];
|
|
16
17
|
} else {
|
|
@@ -5,18 +5,24 @@ import {
|
|
|
5
5
|
validateUpdateDocumentContentInput,
|
|
6
6
|
} from "../../../types/document-schema.mjs";
|
|
7
7
|
|
|
8
|
-
export default async function updateDocumentContent(input) {
|
|
8
|
+
export default async function updateDocumentContent(input, options) {
|
|
9
|
+
// Get originalContent from shared context, fallback to input
|
|
10
|
+
let originalContent = options?.context?.userContext?.currentContent;
|
|
11
|
+
|
|
12
|
+
if (!originalContent) {
|
|
13
|
+
originalContent = input.originalContent;
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
// Validate input using Zod schema
|
|
10
17
|
const validation = validateUpdateDocumentContentInput(input);
|
|
11
18
|
if (!validation.success) {
|
|
12
19
|
return {
|
|
13
20
|
success: false,
|
|
14
|
-
error: validation.error,
|
|
15
|
-
message: "Invalid input parameters",
|
|
21
|
+
error: { message: validation.error },
|
|
16
22
|
};
|
|
17
23
|
}
|
|
18
24
|
|
|
19
|
-
const {
|
|
25
|
+
const { diffPatch } = validation.data;
|
|
20
26
|
|
|
21
27
|
try {
|
|
22
28
|
// Parse and validate diff patch
|
|
@@ -24,8 +30,7 @@ export default async function updateDocumentContent(input) {
|
|
|
24
30
|
if (!parsedDiff.success) {
|
|
25
31
|
return {
|
|
26
32
|
success: false,
|
|
27
|
-
error: parsedDiff.error,
|
|
28
|
-
message: "Invalid diff format: No valid hunks found or parsing failed",
|
|
33
|
+
error: { message: parsedDiff.error },
|
|
29
34
|
};
|
|
30
35
|
}
|
|
31
36
|
|
|
@@ -34,8 +39,7 @@ export default async function updateDocumentContent(input) {
|
|
|
34
39
|
if (!fixedDiff.success) {
|
|
35
40
|
return {
|
|
36
41
|
success: false,
|
|
37
|
-
error: fixedDiff.error,
|
|
38
|
-
message: "Cannot fix diff line number issues",
|
|
42
|
+
error: { message: fixedDiff.error },
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
45
|
|
|
@@ -48,21 +52,27 @@ export default async function updateDocumentContent(input) {
|
|
|
48
52
|
if (result === false) {
|
|
49
53
|
return {
|
|
50
54
|
success: false,
|
|
51
|
-
error: "Failed to apply patch",
|
|
52
|
-
message: "Diff patch could not be applied",
|
|
55
|
+
error: { message: "Failed to apply patch" },
|
|
53
56
|
};
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
// Update shared context with new content if options is provided
|
|
60
|
+
if (options?.context?.userContext) {
|
|
61
|
+
options.context.userContext.currentContent = result;
|
|
62
|
+
}
|
|
63
|
+
|
|
56
64
|
return {
|
|
57
65
|
success: true,
|
|
58
|
-
updatedContent:
|
|
59
|
-
|
|
66
|
+
updatedContent: `<page_content>
|
|
67
|
+
${result}
|
|
68
|
+
</page_content>`,
|
|
69
|
+
message:
|
|
70
|
+
"Document content updated successfully.\nCheck if updatedContent meets user feedback, if so, just return 'success'.",
|
|
60
71
|
};
|
|
61
72
|
} catch (error) {
|
|
62
73
|
return {
|
|
63
74
|
success: false,
|
|
64
|
-
error: error.message,
|
|
65
|
-
message: "Failed to update document content",
|
|
75
|
+
error: { message: error.message },
|
|
66
76
|
};
|
|
67
77
|
}
|
|
68
78
|
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import fsPromises from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sorts files by modification time (newest first), then alphabetically
|
|
7
|
+
*/
|
|
8
|
+
function sortFilesByModTime(files, basePath) {
|
|
9
|
+
return files
|
|
10
|
+
.map((file) => {
|
|
11
|
+
const fullPath = path.isAbsolute(file) ? file : path.resolve(basePath, file);
|
|
12
|
+
try {
|
|
13
|
+
const stats = fs.statSync(fullPath);
|
|
14
|
+
return {
|
|
15
|
+
path: file,
|
|
16
|
+
fullPath,
|
|
17
|
+
mtime: stats.mtimeMs || 0,
|
|
18
|
+
};
|
|
19
|
+
} catch {
|
|
20
|
+
return {
|
|
21
|
+
path: file,
|
|
22
|
+
fullPath,
|
|
23
|
+
mtime: 0,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
.sort((a, b) => {
|
|
28
|
+
// Sort by modification time (newest first), then alphabetically
|
|
29
|
+
if (b.mtime !== a.mtime) {
|
|
30
|
+
return b.mtime - a.mtime;
|
|
31
|
+
}
|
|
32
|
+
return a.path.localeCompare(b.path);
|
|
33
|
+
})
|
|
34
|
+
.map((item) => item.path);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Filters out common ignore patterns
|
|
39
|
+
*/
|
|
40
|
+
function shouldIgnoreFile(filePath) {
|
|
41
|
+
const ignorePatterns = [
|
|
42
|
+
"node_modules",
|
|
43
|
+
".git",
|
|
44
|
+
".DS_Store",
|
|
45
|
+
".vscode",
|
|
46
|
+
".idea",
|
|
47
|
+
"dist",
|
|
48
|
+
"build",
|
|
49
|
+
"*.log",
|
|
50
|
+
"coverage",
|
|
51
|
+
".nyc_output",
|
|
52
|
+
".cache",
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
56
|
+
|
|
57
|
+
return ignorePatterns.some((pattern) => {
|
|
58
|
+
if (pattern.includes("*")) {
|
|
59
|
+
// Simple wildcard matching for patterns like "*.log"
|
|
60
|
+
const regex = new RegExp(pattern.replace(/\*/g, ".*"));
|
|
61
|
+
return regex.test(path.basename(normalizedPath));
|
|
62
|
+
} else {
|
|
63
|
+
// Directory or file name matching
|
|
64
|
+
return (
|
|
65
|
+
normalizedPath.includes(`/${pattern}/`) ||
|
|
66
|
+
normalizedPath.endsWith(`/${pattern}`) ||
|
|
67
|
+
normalizedPath.startsWith(`${pattern}/`) ||
|
|
68
|
+
normalizedPath === pattern
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default async function glob({
|
|
75
|
+
pattern,
|
|
76
|
+
case_sensitive = false,
|
|
77
|
+
respect_git_ignore = true,
|
|
78
|
+
limit = 100,
|
|
79
|
+
}) {
|
|
80
|
+
let result = [];
|
|
81
|
+
let error = null;
|
|
82
|
+
const searchDir = process.cwd();
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
// Validate required parameters
|
|
86
|
+
if (!pattern || typeof pattern !== "string" || pattern.trim() === "") {
|
|
87
|
+
throw new Error("Pattern parameter is required and cannot be empty");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Use Node.js built-in glob
|
|
91
|
+
const globOptions = {
|
|
92
|
+
cwd: searchDir,
|
|
93
|
+
nodir: true, // Only return files, not directories
|
|
94
|
+
dot: true, // Include hidden files
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Note: Node.js fs.glob doesn't support case_sensitive option directly
|
|
98
|
+
// We'll handle case sensitivity in post-processing if needed
|
|
99
|
+
const iter = fsPromises.glob(pattern, globOptions);
|
|
100
|
+
const files = [];
|
|
101
|
+
|
|
102
|
+
for await (const file of iter) {
|
|
103
|
+
if (files.length >= limit) break;
|
|
104
|
+
|
|
105
|
+
// Apply ignore filters
|
|
106
|
+
if (shouldIgnoreFile(file)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Handle case sensitivity if needed
|
|
111
|
+
if (case_sensitive === false) {
|
|
112
|
+
// Node.js glob is case-sensitive by default on most systems
|
|
113
|
+
// For case-insensitive matching, we rely on the pattern itself
|
|
114
|
+
// or the filesystem behavior
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
files.push(file);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Sort files by modification time (newest first)
|
|
121
|
+
const sortedFiles = sortFilesByModTime(files, searchDir);
|
|
122
|
+
|
|
123
|
+
// Build result message
|
|
124
|
+
let message;
|
|
125
|
+
if (sortedFiles.length === 0) {
|
|
126
|
+
message = `No files found matching pattern "${pattern}"`;
|
|
127
|
+
} else {
|
|
128
|
+
const fileCount = sortedFiles.length;
|
|
129
|
+
const truncated = files.length >= limit;
|
|
130
|
+
message = `Found ${fileCount}${truncated ? "+" : ""} file(s) matching "${pattern}"`;
|
|
131
|
+
message += ", sorted by modification time (newest first):";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
result = {
|
|
135
|
+
files: sortedFiles,
|
|
136
|
+
count: sortedFiles.length,
|
|
137
|
+
message,
|
|
138
|
+
truncated: files.length >= limit,
|
|
139
|
+
};
|
|
140
|
+
} catch (err) {
|
|
141
|
+
error = err;
|
|
142
|
+
result = {
|
|
143
|
+
files: [],
|
|
144
|
+
count: 0,
|
|
145
|
+
message: `Error during glob search: ${err.message}`,
|
|
146
|
+
truncated: false,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
command: "glob",
|
|
152
|
+
arguments: {
|
|
153
|
+
pattern,
|
|
154
|
+
case_sensitive,
|
|
155
|
+
respect_git_ignore,
|
|
156
|
+
limit,
|
|
157
|
+
},
|
|
158
|
+
result,
|
|
159
|
+
error: error && { message: error.message },
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
glob.input_schema = {
|
|
164
|
+
type: "object",
|
|
165
|
+
properties: {
|
|
166
|
+
pattern: {
|
|
167
|
+
type: "string",
|
|
168
|
+
description: 'The glob pattern to match files against (e.g., "**/*.js", "src/**/*.ts")',
|
|
169
|
+
},
|
|
170
|
+
case_sensitive: {
|
|
171
|
+
type: "boolean",
|
|
172
|
+
description: "Optional: Whether the search should be case-sensitive (defaults to false)",
|
|
173
|
+
},
|
|
174
|
+
respect_git_ignore: {
|
|
175
|
+
type: "boolean",
|
|
176
|
+
description: "Optional: Whether to respect .gitignore patterns (defaults to true)",
|
|
177
|
+
},
|
|
178
|
+
limit: {
|
|
179
|
+
type: "number",
|
|
180
|
+
description: "Optional: Maximum number of files to return (defaults to 100)",
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
required: ["pattern"],
|
|
184
|
+
};
|