@travisennis/acai 0.0.12 → 0.0.13

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 (237) hide show
  1. package/README.md +3 -2
  2. package/dist/agent/index.d.ts.map +1 -1
  3. package/dist/agent/index.js +2 -5
  4. package/dist/commands/history/types.d.ts +3 -2
  5. package/dist/commands/history/types.d.ts.map +1 -1
  6. package/dist/commands/init-project/utils.d.ts +0 -1
  7. package/dist/commands/init-project/utils.d.ts.map +1 -1
  8. package/dist/commands/init-project/utils.js +1 -1
  9. package/dist/commands/manager.d.ts.map +1 -1
  10. package/dist/commands/manager.js +0 -18
  11. package/dist/commands/share/html-renderer.d.ts.map +1 -1
  12. package/dist/commands/share/html-renderer.js +54 -48
  13. package/dist/commands/tools/index.js +39 -38
  14. package/dist/config/index.d.ts +0 -2
  15. package/dist/config/index.d.ts.map +1 -1
  16. package/dist/config/index.js +2 -6
  17. package/dist/index.d.ts +14 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +94 -76
  20. package/dist/models/manager.d.ts +1 -10
  21. package/dist/models/manager.d.ts.map +1 -1
  22. package/dist/models/manager.js +2 -2
  23. package/dist/models/opencode-go-provider.d.ts +4 -4
  24. package/dist/models/opencode-go-provider.d.ts.map +1 -1
  25. package/dist/models/opencode-go-provider.js +29 -35
  26. package/dist/models/providers.d.ts +1 -1
  27. package/dist/models/providers.d.ts.map +1 -1
  28. package/dist/prompts/system-prompt.d.ts +0 -2
  29. package/dist/prompts/system-prompt.d.ts.map +1 -1
  30. package/dist/prompts/system-prompt.js +6 -10
  31. package/dist/repl/index.d.ts +27 -11
  32. package/dist/repl/index.d.ts.map +1 -1
  33. package/dist/repl/index.js +238 -254
  34. package/dist/skills/index.d.ts +12 -2
  35. package/dist/skills/index.d.ts.map +1 -1
  36. package/dist/skills/index.js +123 -73
  37. package/dist/terminal/control.d.ts +1 -21
  38. package/dist/terminal/control.d.ts.map +1 -1
  39. package/dist/terminal/control.js +1 -32
  40. package/dist/terminal/formatting.d.ts +0 -33
  41. package/dist/terminal/formatting.d.ts.map +1 -1
  42. package/dist/terminal/formatting.js +0 -91
  43. package/dist/terminal/highlight/theme.d.ts +0 -37
  44. package/dist/terminal/highlight/theme.d.ts.map +1 -1
  45. package/dist/terminal/highlight/theme.js +1 -79
  46. package/dist/terminal/keys.d.ts +0 -97
  47. package/dist/terminal/keys.d.ts.map +1 -1
  48. package/dist/terminal/keys.js +0 -194
  49. package/dist/terminal/select-prompt.d.ts.map +1 -1
  50. package/dist/terminal/select-prompt.js +65 -51
  51. package/dist/terminal/style.d.ts +1 -1
  52. package/dist/terminal/style.d.ts.map +1 -1
  53. package/dist/terminal/supports-color.d.ts.map +1 -1
  54. package/dist/terminal/supports-color.js +38 -20
  55. package/dist/terminal/supports-hyperlinks.d.ts +3 -0
  56. package/dist/terminal/supports-hyperlinks.d.ts.map +1 -1
  57. package/dist/terminal/supports-hyperlinks.js +72 -31
  58. package/dist/terminal/table/layout-manager.d.ts +0 -20
  59. package/dist/terminal/table/layout-manager.d.ts.map +1 -1
  60. package/dist/terminal/table/layout-manager.js +68 -44
  61. package/dist/terminal/table/utils.d.ts +0 -1
  62. package/dist/terminal/table/utils.d.ts.map +1 -1
  63. package/dist/terminal/table/utils.js +2 -4
  64. package/dist/tools/apply-patch.d.ts +5 -3
  65. package/dist/tools/apply-patch.d.ts.map +1 -1
  66. package/dist/tools/apply-patch.js +154 -123
  67. package/dist/tools/bash.d.ts.map +1 -1
  68. package/dist/tools/bash.js +11 -8
  69. package/dist/tools/dynamic-tool-loader.d.ts +6 -1
  70. package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
  71. package/dist/tools/dynamic-tool-loader.js +154 -135
  72. package/dist/tools/index.d.ts +3 -133
  73. package/dist/tools/index.d.ts.map +1 -1
  74. package/dist/tools/index.js +0 -20
  75. package/dist/tools/read-file.d.ts.map +1 -1
  76. package/dist/tools/read-file.js +32 -13
  77. package/dist/tools/skill.d.ts.map +1 -1
  78. package/dist/tools/skill.js +20 -13
  79. package/dist/tools/web-fetch.d.ts +2 -6
  80. package/dist/tools/web-fetch.d.ts.map +1 -1
  81. package/dist/tools/web-fetch.js +59 -36
  82. package/dist/tools/web-search.d.ts +0 -4
  83. package/dist/tools/web-search.d.ts.map +1 -1
  84. package/dist/tools/web-search.js +40 -32
  85. package/dist/tui/autocomplete/utils.d.ts +0 -15
  86. package/dist/tui/autocomplete/utils.d.ts.map +1 -1
  87. package/dist/tui/autocomplete/utils.js +0 -85
  88. package/dist/tui/autocomplete.d.ts +1 -1
  89. package/dist/tui/autocomplete.d.ts.map +1 -1
  90. package/dist/tui/autocomplete.js +1 -1
  91. package/dist/tui/components/editor.d.ts +12 -0
  92. package/dist/tui/components/editor.d.ts.map +1 -1
  93. package/dist/tui/components/editor.js +181 -195
  94. package/dist/tui/components/input.d.ts +4 -0
  95. package/dist/tui/components/input.d.ts.map +1 -1
  96. package/dist/tui/components/input.js +33 -31
  97. package/dist/tui/components/markdown.d.ts +30 -0
  98. package/dist/tui/components/markdown.d.ts.map +1 -1
  99. package/dist/tui/components/markdown.js +274 -242
  100. package/dist/tui/components/modal.d.ts.map +1 -1
  101. package/dist/tui/components/modal.js +11 -11
  102. package/dist/tui/components/select-list.d.ts +5 -0
  103. package/dist/tui/components/select-list.d.ts.map +1 -1
  104. package/dist/tui/components/select-list.js +69 -98
  105. package/dist/tui/components/table.d.ts +6 -0
  106. package/dist/tui/components/table.d.ts.map +1 -1
  107. package/dist/tui/components/table.js +61 -52
  108. package/dist/tui/index.d.ts +1 -8
  109. package/dist/tui/index.d.ts.map +1 -1
  110. package/dist/tui/index.js +0 -8
  111. package/dist/tui/tui.d.ts +9 -0
  112. package/dist/tui/tui.d.ts.map +1 -1
  113. package/dist/tui/tui.js +78 -48
  114. package/dist/tui/utils.d.ts +7 -0
  115. package/dist/tui/utils.d.ts.map +1 -1
  116. package/dist/tui/utils.js +117 -53
  117. package/dist/utils/bash.d.ts.map +1 -1
  118. package/dist/utils/bash.js +121 -104
  119. package/dist/utils/command-protection.d.ts +3 -2
  120. package/dist/utils/command-protection.d.ts.map +1 -1
  121. package/dist/utils/command-protection.js +42 -33
  122. package/dist/utils/filesystem/operations.d.ts +0 -15
  123. package/dist/utils/filesystem/operations.d.ts.map +1 -1
  124. package/dist/utils/filesystem/operations.js +1 -38
  125. package/dist/utils/filesystem/security.d.ts.map +1 -1
  126. package/dist/utils/filesystem/security.js +22 -15
  127. package/dist/utils/filetype-detection.d.ts +0 -1
  128. package/dist/utils/filetype-detection.d.ts.map +1 -1
  129. package/dist/utils/filetype-detection.js +0 -12
  130. package/dist/utils/formatting.d.ts +0 -30
  131. package/dist/utils/formatting.d.ts.map +1 -1
  132. package/dist/utils/formatting.js +0 -44
  133. package/dist/utils/git.d.ts +4 -6
  134. package/dist/utils/git.d.ts.map +1 -1
  135. package/dist/utils/git.js +36 -46
  136. package/dist/utils/ignore.d.ts +1 -1
  137. package/dist/utils/ignore.d.ts.map +1 -1
  138. package/dist/utils/ignore.js +1 -1
  139. package/dist/utils/process.d.ts.map +1 -1
  140. package/dist/utils/process.js +77 -79
  141. package/dist/utils/yaml.d.ts +0 -1
  142. package/dist/utils/yaml.d.ts.map +1 -1
  143. package/dist/utils/yaml.js +80 -89
  144. package/dist/utils/zod.d.ts +0 -3
  145. package/dist/utils/zod.d.ts.map +1 -1
  146. package/dist/utils/zod.js +0 -7
  147. package/package.json +25 -24
  148. package/dist/agent/sub-agent.d.ts +0 -23
  149. package/dist/agent/sub-agent.d.ts.map +0 -1
  150. package/dist/agent/sub-agent.js +0 -109
  151. package/dist/commands/add-directory/index.d.ts +0 -3
  152. package/dist/commands/add-directory/index.d.ts.map +0 -1
  153. package/dist/commands/add-directory/index.js +0 -50
  154. package/dist/commands/add-directory/utils.d.ts +0 -3
  155. package/dist/commands/add-directory/utils.d.ts.map +0 -1
  156. package/dist/commands/add-directory/utils.js +0 -15
  157. package/dist/commands/clear/index.d.ts +0 -3
  158. package/dist/commands/clear/index.d.ts.map +0 -1
  159. package/dist/commands/clear/index.js +0 -13
  160. package/dist/commands/generate-rules/index.d.ts +0 -3
  161. package/dist/commands/generate-rules/index.d.ts.map +0 -1
  162. package/dist/commands/generate-rules/index.js +0 -206
  163. package/dist/commands/generate-rules/service.d.ts +0 -22
  164. package/dist/commands/generate-rules/service.d.ts.map +0 -1
  165. package/dist/commands/generate-rules/service.js +0 -103
  166. package/dist/commands/generate-rules/utils.d.ts +0 -5
  167. package/dist/commands/generate-rules/utils.d.ts.map +0 -1
  168. package/dist/commands/generate-rules/utils.js +0 -25
  169. package/dist/commands/handoff/index.d.ts +0 -3
  170. package/dist/commands/handoff/index.d.ts.map +0 -1
  171. package/dist/commands/handoff/index.js +0 -97
  172. package/dist/commands/handoff/utils.d.ts +0 -4
  173. package/dist/commands/handoff/utils.d.ts.map +0 -1
  174. package/dist/commands/handoff/utils.js +0 -123
  175. package/dist/commands/list-directories/index.d.ts +0 -3
  176. package/dist/commands/list-directories/index.d.ts.map +0 -1
  177. package/dist/commands/list-directories/index.js +0 -35
  178. package/dist/commands/pickup/index.d.ts +0 -3
  179. package/dist/commands/pickup/index.d.ts.map +0 -1
  180. package/dist/commands/pickup/index.js +0 -141
  181. package/dist/commands/pickup/types.d.ts +0 -6
  182. package/dist/commands/pickup/types.d.ts.map +0 -1
  183. package/dist/commands/pickup/types.js +0 -1
  184. package/dist/commands/pickup/utils.d.ts +0 -7
  185. package/dist/commands/pickup/utils.d.ts.map +0 -1
  186. package/dist/commands/pickup/utils.js +0 -56
  187. package/dist/commands/remove-directory/index.d.ts +0 -3
  188. package/dist/commands/remove-directory/index.d.ts.map +0 -1
  189. package/dist/commands/remove-directory/index.js +0 -55
  190. package/dist/commands/review/index.d.ts +0 -3
  191. package/dist/commands/review/index.d.ts.map +0 -1
  192. package/dist/commands/review/index.js +0 -12
  193. package/dist/commands/review/review-panel.d.ts +0 -3
  194. package/dist/commands/review/review-panel.d.ts.map +0 -1
  195. package/dist/commands/review/review-panel.js +0 -186
  196. package/dist/commands/review/utils.d.ts +0 -18
  197. package/dist/commands/review/utils.d.ts.map +0 -1
  198. package/dist/commands/review/utils.js +0 -146
  199. package/dist/commands/shell/index.d.ts +0 -3
  200. package/dist/commands/shell/index.d.ts.map +0 -1
  201. package/dist/commands/shell/index.js +0 -96
  202. package/dist/subagents/index.d.ts +0 -16
  203. package/dist/subagents/index.d.ts.map +0 -1
  204. package/dist/subagents/index.js +0 -231
  205. package/dist/terminal/index.d.ts +0 -9
  206. package/dist/terminal/index.d.ts.map +0 -1
  207. package/dist/terminal/index.js +0 -8
  208. package/dist/tools/agent.d.ts +0 -27
  209. package/dist/tools/agent.d.ts.map +0 -1
  210. package/dist/tools/agent.js +0 -81
  211. package/dist/tools/directory-tree.d.ts +0 -28
  212. package/dist/tools/directory-tree.d.ts.map +0 -1
  213. package/dist/tools/directory-tree.js +0 -154
  214. package/dist/tools/glob.d.ts +0 -35
  215. package/dist/tools/glob.d.ts.map +0 -1
  216. package/dist/tools/glob.js +0 -167
  217. package/dist/tools/grep.d.ts +0 -100
  218. package/dist/tools/grep.d.ts.map +0 -1
  219. package/dist/tools/grep.js +0 -608
  220. package/dist/tools/ls.d.ts +0 -26
  221. package/dist/tools/ls.d.ts.map +0 -1
  222. package/dist/tools/ls.js +0 -83
  223. package/dist/tui/components/header.d.ts +0 -21
  224. package/dist/tui/components/header.d.ts.map +0 -1
  225. package/dist/tui/components/header.js +0 -63
  226. package/dist/utils/bash/parse.d.ts +0 -19
  227. package/dist/utils/bash/parse.d.ts.map +0 -1
  228. package/dist/utils/bash/parse.js +0 -223
  229. package/dist/utils/bash/quote.d.ts +0 -6
  230. package/dist/utils/bash/quote.d.ts.map +0 -1
  231. package/dist/utils/bash/quote.js +0 -23
  232. package/dist/utils/generators.d.ts +0 -3
  233. package/dist/utils/generators.d.ts.map +0 -1
  234. package/dist/utils/generators.js +0 -25
  235. package/dist/utils/glob.d.ts +0 -52
  236. package/dist/utils/glob.d.ts.map +0 -1
  237. package/dist/utils/glob.js +0 -376
@@ -1,154 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { z } from "zod";
4
- import style from "../terminal/style.js";
5
- import { toDisplayPath } from "../utils/filesystem/path-display.js";
6
- import { joinWorkingDir, validatePath } from "../utils/filesystem/security.js";
7
- import ignore from "../utils/ignore.js";
8
- import { convertNullString } from "../utils/zod.js";
9
- const DEFAULT_ITEM_LIMIT = 500;
10
- const DEFAULT_DEPTH_LIMIT = 10;
11
- export const DirectoryTreeTool = {
12
- name: "DirectoryTree",
13
- };
14
- const inputSchema = z.object({
15
- path: z.string().describe("The path"),
16
- maxResults: z
17
- .preprocess((val) => convertNullString(val), z.coerce.number().nullable())
18
- .default(null)
19
- .describe(`Maximum number of items (files + directories) to return. Set to 0 for no limit. (default: ${DEFAULT_ITEM_LIMIT})`),
20
- maxDepth: z
21
- .preprocess((val) => convertNullString(val), z.coerce.number().nullable())
22
- .default(null)
23
- .describe(`Maximum recursion depth. Set to 0 for no limit. (default: ${DEFAULT_DEPTH_LIMIT})`),
24
- });
25
- export const createDirectoryTreeTool = async (options) => {
26
- const { primaryDir, allowedDirs } = options.workspace;
27
- const allowedDirectory = allowedDirs ?? [primaryDir];
28
- return {
29
- toolDef: {
30
- description: "Show directory structure as a recursive tree. Use this to explore nested directories and understand the overall project structure. For a simple flat list of a single directory, use LS instead.",
31
- inputSchema,
32
- },
33
- display({ path, maxDepth, maxResults }) {
34
- const displayPath = toDisplayPath(path);
35
- let display = `${style.cyan(displayPath)}`;
36
- if (maxDepth || maxResults) {
37
- const parts = [];
38
- if (maxDepth)
39
- parts.push(`depth: ${maxDepth}`);
40
- if (maxResults)
41
- parts.push(`max: ${maxResults}`);
42
- display += ` (${parts.join(", ")})`;
43
- }
44
- return display;
45
- },
46
- async execute({ path, maxResults, maxDepth }, { abortSignal }) {
47
- if (abortSignal?.aborted) {
48
- throw new Error("Directory tree listing aborted");
49
- }
50
- const validPath = await validatePath(joinWorkingDir(path, primaryDir), allowedDirectory, { abortSignal });
51
- if (abortSignal?.aborted) {
52
- throw new Error("Directory tree listing aborted before tree generation");
53
- }
54
- const treeResult = await directoryTree(validPath, {
55
- maxResults: maxResults ?? DEFAULT_ITEM_LIMIT,
56
- maxDepth: maxDepth ?? DEFAULT_DEPTH_LIMIT,
57
- });
58
- return treeResult.tree;
59
- },
60
- };
61
- };
62
- /**
63
- * Generates the indentation string for a given level in the directory tree.
64
- * @param level - The current level in the directory tree.
65
- * @param isLast - Indicates if the current item is the last in its parent directory.
66
- * @returns The indentation string for the current level.
67
- */
68
- function getIndent(level, isLast) {
69
- const indent = "│ ".repeat(Math.max(level - 1, 0));
70
- return level === 0 ? "" : `${indent}${isLast ? "└── " : "├── "}`;
71
- }
72
- /**
73
- * Recursively generates a string representation of a directory tree.
74
- * @param dirPath - The path of the directory to generate the tree for.
75
- * @param ig - The ignore instance for filtering files.
76
- * @param level - The current level in the directory tree (default: 0).
77
- * @param options - Options for limiting results.
78
- * @returns A Promise that resolves to a string representation of the directory tree with counts.
79
- * @throws Will log an error if there's an issue reading the directory.
80
- */
81
- async function generateDirectoryTree(dirPath, ig, level = 0, options = {}) {
82
- const name = path.basename(dirPath);
83
- let output = `${getIndent(level, false)}${name}\n`;
84
- let fileCount = 0;
85
- let directoryCount = 1; // Count the current directory
86
- let totalCount = 1; // Count the current directory
87
- let isTruncated = false;
88
- // Check maxDepth limit - when maxDepth is reached, we should indicate truncation
89
- if (options.maxDepth !== null &&
90
- options.maxDepth !== undefined &&
91
- options.maxDepth > 0 &&
92
- level >= options.maxDepth) {
93
- // When maxDepth is reached, return with truncation flag set
94
- return {
95
- tree: output,
96
- fileCount: 0,
97
- directoryCount: 1, // Count the current directory
98
- totalCount: 1, // Count the current directory
99
- isTruncated: true, // Set truncation flag when depth limit is reached
100
- };
101
- }
102
- const items = await fs.readdir(dirPath);
103
- const filteredItems = ig.filter(items);
104
- for (let i = 0; i < filteredItems.length; i++) {
105
- // Check maxResults limit BEFORE processing each item to ensure strict adherence to limits
106
- if (options.maxResults !== null &&
107
- options.maxResults !== undefined &&
108
- options.maxResults > 0 &&
109
- totalCount >= options.maxResults) {
110
- isTruncated = true;
111
- break;
112
- }
113
- const item = filteredItems[i] ?? "";
114
- const itemPath = path.join(dirPath, item);
115
- const isLast = i === filteredItems.length - 1;
116
- const stats = await fs.stat(itemPath);
117
- if (stats.isDirectory()) {
118
- const subTreeResult = await generateDirectoryTree(itemPath, ig, level + 1, options);
119
- output += subTreeResult.tree;
120
- fileCount += subTreeResult.fileCount;
121
- directoryCount += subTreeResult.directoryCount;
122
- totalCount += subTreeResult.totalCount;
123
- // Propagate truncation from subtree results
124
- if (subTreeResult.isTruncated) {
125
- isTruncated = true;
126
- }
127
- }
128
- else {
129
- output += `${getIndent(level + 1, isLast)}${item}\n`;
130
- fileCount += 1;
131
- totalCount += 1;
132
- }
133
- }
134
- return { tree: output, fileCount, directoryCount, totalCount, isTruncated };
135
- }
136
- async function directoryTree(dirPath, options = {}) {
137
- let ig;
138
- try {
139
- const ignoreFile = await fs.readFile(path.join(process.cwd(), ".gitignore"));
140
- ig = ignore().add(ignoreFile.toString()).add(".git");
141
- }
142
- catch (_error) {
143
- // If .gitignore doesn't exist, create basic ignore with just .git
144
- ig = ignore().add(".git");
145
- }
146
- const result = await generateDirectoryTree(dirPath, ig, 0, options);
147
- return {
148
- tree: result.tree.trim(),
149
- fileCount: result.fileCount,
150
- directoryCount: result.directoryCount,
151
- totalCount: result.totalCount,
152
- isTruncated: result.isTruncated,
153
- };
154
- }
@@ -1,35 +0,0 @@
1
- import { z } from "zod";
2
- import type { ToolExecutionOptions } from "./types.ts";
3
- export declare const GlobTool: {
4
- name: "Glob";
5
- };
6
- export declare const inputSchema: z.ZodObject<{
7
- patterns: z.ZodDefault<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
8
- path: z.ZodDefault<z.ZodPreprocess<z.ZodString>>;
9
- gitignore: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
10
- recursive: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
11
- expandDirectories: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
12
- ignoreFiles: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>>;
13
- cwd: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedString<unknown>>>>;
14
- maxResults: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedNumber<unknown>>>>;
15
- }, z.core.$strip>;
16
- type GlobInputSchema = z.infer<typeof inputSchema>;
17
- export declare const createGlobTool: () => {
18
- toolDef: {
19
- description: string;
20
- inputSchema: z.ZodObject<{
21
- patterns: z.ZodDefault<z.ZodPreprocess<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>;
22
- path: z.ZodDefault<z.ZodPreprocess<z.ZodString>>;
23
- gitignore: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
24
- recursive: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
25
- expandDirectories: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
26
- ignoreFiles: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>>>;
27
- cwd: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedString<unknown>>>>;
28
- maxResults: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedNumber<unknown>>>>;
29
- }, z.core.$strip>;
30
- };
31
- display({ patterns, path }: GlobInputSchema): string;
32
- execute({ patterns, path, gitignore, recursive, expandDirectories, ignoreFiles, cwd, maxResults, }: GlobInputSchema, { abortSignal }: ToolExecutionOptions): Promise<string>;
33
- };
34
- export {};
35
- //# sourceMappingURL=glob.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../source/tools/glob.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA6EvD,eAAO,MAAM,QAAQ;;CAEpB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;iBAkFtB,CAAC;AAEH,KAAK,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEnD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;gCAMK,eAAe;wGAmBtC,eAAe,mBACD,oBAAoB,GACpC,OAAO,CAAC,MAAM,CAAC;CAuCrB,CAAC"}
@@ -1,167 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as nodePath from "node:path";
3
- import { z } from "zod";
4
- import style from "../terminal/style.js";
5
- import { toDisplayPath } from "../utils/filesystem/path-display.js";
6
- import { glob } from "../utils/glob.js";
7
- import { convertNullString } from "../utils/zod.js";
8
- const DEFAULT_MAX_RESULTS = 100;
9
- const MAX_STAT_FILES = 1000;
10
- async function getFileWithStats(filePath, effectivePath) {
11
- const fullPath = nodePath.join(effectivePath, filePath);
12
- try {
13
- const stats = await fs.promises.stat(fullPath);
14
- return {
15
- path: filePath,
16
- mtime: stats.mtime.getTime(),
17
- };
18
- }
19
- catch {
20
- return {
21
- path: filePath,
22
- mtime: 0,
23
- };
24
- }
25
- }
26
- function sortFilesByMtime(files) {
27
- return files
28
- .sort((a, b) => {
29
- if (b.mtime !== a.mtime) {
30
- return b.mtime - a.mtime;
31
- }
32
- return a.path.localeCompare(b.path);
33
- })
34
- .map((file) => file.path);
35
- }
36
- function formatResult(sortedFiles) {
37
- return sortedFiles.length > 0
38
- ? sortedFiles.join("\n")
39
- : "No files found matching the specified patterns.";
40
- }
41
- function normalizePatternArray(patterns) {
42
- return Array.isArray(patterns) ? patterns : [patterns];
43
- }
44
- function buildGlobOptions(effectivePath, gitignore, recursive, expandDirectories, ignoreFiles, cwd) {
45
- return {
46
- cwd: cwd || effectivePath,
47
- ...(gitignore !== null && { gitignore }),
48
- ...(recursive !== null && { recursive }),
49
- ...(expandDirectories !== null && { expandDirectories }),
50
- ...(ignoreFiles !== null && { ignoreFiles }),
51
- };
52
- }
53
- function limitResults(sortedFiles, effectiveMaxResults) {
54
- if (effectiveMaxResults > 0 && sortedFiles.length > effectiveMaxResults) {
55
- return sortedFiles.slice(0, effectiveMaxResults);
56
- }
57
- return sortedFiles;
58
- }
59
- export const GlobTool = {
60
- name: "Glob",
61
- };
62
- export const inputSchema = z.object({
63
- patterns: z
64
- .preprocess((val) => {
65
- if (val === null || val === undefined) {
66
- return "**/*";
67
- }
68
- if (typeof val === "string") {
69
- const trimmed = val.trim();
70
- if (trimmed.startsWith("[")) {
71
- try {
72
- const parsed = JSON.parse(trimmed);
73
- if (Array.isArray(parsed)) {
74
- return parsed;
75
- }
76
- }
77
- catch {
78
- // Not valid JSON, treat as a plain glob string
79
- }
80
- }
81
- }
82
- return val;
83
- }, z.union([z.string(), z.array(z.string())]))
84
- .default("**/*")
85
- .describe("Glob patterns to search for (e.g., '*.ts', '**/*.test.ts', 'src/**/*.js')"),
86
- path: z
87
- .preprocess((val) => (val === null || val === undefined ? process.cwd() : val), z.string())
88
- .default(process.cwd())
89
- .describe("Base directory to search in"),
90
- gitignore: z
91
- .preprocess((val) => convertNullString(val), z.coerce.boolean().nullable())
92
- .default(null)
93
- .describe("Respect ignore patterns in .gitignore files. (default: true)"),
94
- recursive: z
95
- .preprocess((val) => convertNullString(val), z.coerce.boolean().nullable())
96
- .default(null)
97
- .describe("Search recursively. (default: true)"),
98
- expandDirectories: z
99
- .preprocess((val) => convertNullString(val), z.coerce.boolean().nullable())
100
- .default(null)
101
- .describe("Automatically expand directories to files. (default: true)"),
102
- ignoreFiles: z
103
- .preprocess((val) => {
104
- const converted = convertNullString(val);
105
- if (converted === null) {
106
- return null;
107
- }
108
- if (typeof converted === "string") {
109
- const trimmed = converted.trim();
110
- if (trimmed.startsWith("[")) {
111
- try {
112
- const parsed = JSON.parse(trimmed);
113
- if (Array.isArray(parsed)) {
114
- return parsed;
115
- }
116
- }
117
- catch {
118
- // Not valid JSON, treat as a plain string
119
- }
120
- }
121
- }
122
- return converted;
123
- }, z.union([z.string(), z.array(z.string())]).nullable())
124
- .default(null)
125
- .describe("Glob patterns to look for ignore files (e.g., '.gitignore'). Pass null to use default behavior."),
126
- cwd: z
127
- .preprocess((val) => convertNullString(val), z.coerce.string().nullable())
128
- .default(null)
129
- .describe("Current working directory override. (default: process.cwd())"),
130
- maxResults: z
131
- .preprocess((val) => convertNullString(val), z.coerce.number().nullable())
132
- .default(null)
133
- .describe("Maximum number of files to return. Set to 0 for no limit. (Default: 100)"),
134
- });
135
- export const createGlobTool = () => {
136
- return {
137
- toolDef: {
138
- description: "Find files by name pattern (e.g., *.ts).",
139
- inputSchema,
140
- },
141
- display({ patterns, path }) {
142
- const patternArray = Array.isArray(patterns) ? patterns : [patterns];
143
- const patternStr = patternArray.length === 1
144
- ? patternArray[0]
145
- : JSON.stringify(patternArray);
146
- const displayPath = toDisplayPath(path);
147
- return `${style.cyan(patternStr)} in ${style.cyan(displayPath)}`;
148
- },
149
- async execute({ patterns, path, gitignore, recursive, expandDirectories, ignoreFiles, cwd, maxResults, }, { abortSignal }) {
150
- if (abortSignal?.aborted) {
151
- throw new Error("Glob search aborted");
152
- }
153
- const effectivePath = typeof path === "string" && path.trim() !== "" ? path : process.cwd();
154
- const patternArray = normalizePatternArray(patterns);
155
- const effectiveMaxResults = maxResults ?? DEFAULT_MAX_RESULTS;
156
- const globOptions = buildGlobOptions(effectivePath, gitignore ?? null, recursive ?? null, expandDirectories ?? null, ignoreFiles ?? null, cwd ?? null);
157
- const matchingFiles = await glob(patternArray, globOptions);
158
- const filesToStat = matchingFiles.length > MAX_STAT_FILES
159
- ? matchingFiles.slice(0, MAX_STAT_FILES)
160
- : matchingFiles;
161
- const filesWithStats = await Promise.all(filesToStat.map((filePath) => getFileWithStats(filePath, effectivePath)));
162
- const sortedFiles = sortFilesByMtime(filesWithStats);
163
- const result = limitResults(sortedFiles, effectiveMaxResults);
164
- return formatResult(result);
165
- },
166
- };
167
- };
@@ -1,100 +0,0 @@
1
- import { z } from "zod";
2
- import type { ToolExecutionOptions } from "./types.ts";
3
- export declare const GrepTool: {
4
- name: "Grep";
5
- };
6
- declare const inputSchema: z.ZodObject<{
7
- pattern: z.ZodString;
8
- path: z.ZodString;
9
- recursive: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
10
- ignoreCase: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
11
- filePattern: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedString<unknown>>>>;
12
- contextLines: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedNumber<unknown>>>>;
13
- searchIgnored: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
14
- literal: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
15
- maxResults: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedNumber<unknown>>>>;
16
- }, z.core.$strip>;
17
- type GrepInputSchema = z.infer<typeof inputSchema>;
18
- export declare const createGrepTool: () => {
19
- toolDef: {
20
- description: string;
21
- inputSchema: z.ZodObject<{
22
- pattern: z.ZodString;
23
- path: z.ZodString;
24
- recursive: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
25
- ignoreCase: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
26
- filePattern: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedString<unknown>>>>;
27
- contextLines: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedNumber<unknown>>>>;
28
- searchIgnored: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
29
- literal: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedBoolean<unknown>>>>;
30
- maxResults: z.ZodDefault<z.ZodPreprocess<z.ZodNullable<z.ZodCoercedNumber<unknown>>>>;
31
- }, z.core.$strip>;
32
- };
33
- display({ pattern, path, filePattern, recursive, ignoreCase, contextLines, }: GrepInputSchema): string;
34
- execute({ pattern, path, recursive, ignoreCase, filePattern, contextLines, searchIgnored, literal, maxResults, }: GrepInputSchema, { abortSignal }: ToolExecutionOptions): Promise<string>;
35
- };
36
- interface GrepOptions {
37
- recursive?: boolean | null;
38
- ignoreCase?: boolean | null;
39
- filePattern?: string | null;
40
- contextLines?: number | null;
41
- searchIgnored?: boolean | null;
42
- literal?: boolean | null;
43
- maxResults?: number | null;
44
- likelyUnbalanced?: boolean;
45
- }
46
- export declare function likelyUnbalancedRegex(pattern: string): boolean;
47
- /**
48
- * Build grep command args array directly
49
- *
50
- * @param pattern - The regex pattern to search for
51
- * @param path - The path to search in
52
- * @param options - Additional options for the grep command
53
- * @returns The args array for the grep command
54
- */
55
- export declare function buildGrepArgs(pattern: string, path: string, options?: GrepOptions): string[];
56
- export interface ParsedMatch {
57
- file?: string;
58
- line: number;
59
- content: string;
60
- isMatch: boolean;
61
- isContext?: boolean;
62
- lineNumber?: number;
63
- absolutePath?: string;
64
- submatches?: Array<{
65
- start: number;
66
- end: number;
67
- text: string;
68
- }>;
69
- }
70
- interface GrepResult {
71
- rawOutput: string;
72
- parsedMatches: ParsedMatch[];
73
- matchCount: number;
74
- displayedCount?: number;
75
- contextCount: number;
76
- hasMatches: boolean;
77
- isTruncated?: boolean;
78
- }
79
- /**
80
- * Parse ripgrep JSON output and extract structured match information
81
- */
82
- export declare function parseRipgrepJsonOutput(content: string): ParsedMatch[];
83
- /**
84
- * Count actual matches (excluding context lines)
85
- */
86
- export declare function countActualMatches(parsed: ParsedMatch[]): number;
87
- /**
88
- * Count context lines
89
- */
90
- export declare function countContextLines(parsed: ParsedMatch[]): number;
91
- /**
92
- * Truncate matches to a maximum number of results, preserving context lines for kept matches
93
- */
94
- export declare function truncateMatches(matches: ParsedMatch[], maxResults: number | null | undefined): {
95
- truncated: ParsedMatch[];
96
- isTruncated: boolean;
97
- };
98
- export declare function grepFilesStructured(pattern: string, path: string, options?: GrepOptions, abortSignal?: AbortSignal | null): Promise<GrepResult>;
99
- export {};
100
- //# sourceMappingURL=grep.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../source/tools/grep.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAKvD,eAAO,MAAM,QAAQ;;CAEpB,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;iBA2Cf,CAAC;AAEH,KAAK,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEnD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;kFAapB,eAAe;sHAoCb,eAAe,mBACD,oBAAoB,GACpC,OAAO,CAAC,MAAM,CAAC;CAkErB,CAAC;AAEF,UAAU,WAAW;IACnB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAuMD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CA8B9D;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,GACxB,MAAM,EAAE,CAgEV;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,KAAK,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;CACJ;AAED,UAAU,UAAU;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,EAAE,CAqDrE;AA8BD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAEhE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAE/D;AAyBD;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,WAAW,EAAE,EACtB,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACpC;IAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAAC,WAAW,EAAE,OAAO,CAAA;CAAE,CAoDpD;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,EACzB,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,GAC/B,OAAO,CAAC,UAAU,CAAC,CAgGrB"}