@travisennis/acai 0.0.6 → 0.0.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/README.md +186 -17
- package/bin/acai-wrapper.js +26 -0
- package/dist/agent/index.d.ts +15 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +202 -174
- package/dist/api/exa/index.js +1 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +40 -7
- package/dist/commands/add-directory-command.d.ts +1 -1
- package/dist/commands/add-directory-command.d.ts.map +1 -1
- package/dist/commands/add-directory-command.js +1 -32
- package/dist/commands/application-log-command.d.ts +1 -1
- package/dist/commands/application-log-command.d.ts.map +1 -1
- package/dist/commands/application-log-command.js +2 -38
- package/dist/commands/clear-command.d.ts +1 -1
- package/dist/commands/clear-command.d.ts.map +1 -1
- package/dist/commands/clear-command.js +1 -5
- package/dist/commands/compact-command.d.ts.map +1 -1
- package/dist/commands/compact-command.js +0 -9
- package/dist/commands/context-command.d.ts +1 -1
- package/dist/commands/context-command.d.ts.map +1 -1
- package/dist/commands/context-command.js +13 -72
- package/dist/commands/copy-command.d.ts.map +1 -1
- package/dist/commands/copy-command.js +0 -19
- package/dist/commands/edit-command.d.ts +1 -1
- package/dist/commands/edit-command.d.ts.map +1 -1
- package/dist/commands/edit-command.js +3 -49
- package/dist/commands/edit-prompt-command.d.ts +1 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -1
- package/dist/commands/edit-prompt-command.js +1 -26
- package/dist/commands/exit-command.d.ts +1 -4
- package/dist/commands/exit-command.d.ts.map +1 -1
- package/dist/commands/exit-command.js +2 -18
- package/dist/commands/files-command.d.ts +1 -1
- package/dist/commands/files-command.d.ts.map +1 -1
- package/dist/commands/files-command.js +1 -54
- package/dist/commands/generate-rules-command.d.ts +1 -1
- package/dist/commands/generate-rules-command.d.ts.map +1 -1
- package/dist/commands/generate-rules-command.js +18 -60
- package/dist/commands/handoff-command.d.ts.map +1 -1
- package/dist/commands/handoff-command.js +0 -11
- package/dist/commands/health-command.d.ts +1 -1
- package/dist/commands/health-command.d.ts.map +1 -1
- package/dist/commands/health-command.js +8 -103
- package/dist/commands/help-command.d.ts +1 -1
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +6 -14
- package/dist/commands/history-command.d.ts +1 -1
- package/dist/commands/history-command.d.ts.map +1 -1
- package/dist/commands/history-command.js +30 -106
- package/dist/commands/init-command.d.ts +1 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/init-command.js +4 -23
- package/dist/commands/last-log-command.d.ts +1 -1
- package/dist/commands/last-log-command.d.ts.map +1 -1
- package/dist/commands/last-log-command.js +1 -28
- package/dist/commands/list-directories-command.d.ts +1 -1
- package/dist/commands/list-directories-command.d.ts.map +1 -1
- package/dist/commands/list-directories-command.js +1 -14
- package/dist/commands/list-tools-command.d.ts.map +1 -1
- package/dist/commands/list-tools-command.js +55 -78
- package/dist/commands/manager.d.ts +1 -8
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +7 -42
- package/dist/commands/model-command.d.ts +0 -22
- package/dist/commands/model-command.d.ts.map +1 -1
- package/dist/commands/model-command.js +5 -126
- package/dist/commands/paste-command.d.ts +1 -1
- package/dist/commands/paste-command.d.ts.map +1 -1
- package/dist/commands/paste-command.js +1 -79
- package/dist/commands/pickup-command.d.ts.map +1 -1
- package/dist/commands/pickup-command.js +3 -55
- package/dist/commands/prompt-command.d.ts +19 -1
- package/dist/commands/prompt-command.d.ts.map +1 -1
- package/dist/commands/prompt-command.js +172 -194
- package/dist/commands/remove-directory-command.d.ts +1 -1
- package/dist/commands/remove-directory-command.d.ts.map +1 -1
- package/dist/commands/remove-directory-command.js +1 -33
- package/dist/commands/reset-command.d.ts +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/reset-command.js +3 -11
- package/dist/commands/rules-command.d.ts +1 -1
- package/dist/commands/rules-command.d.ts.map +1 -1
- package/dist/commands/rules-command.js +1 -63
- package/dist/commands/save-command.d.ts +1 -1
- package/dist/commands/save-command.d.ts.map +1 -1
- package/dist/commands/save-command.js +1 -8
- package/dist/commands/shell-command.d.ts.map +1 -1
- package/dist/commands/shell-command.js +1 -48
- package/dist/commands/types.d.ts +0 -3
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/usage-command.d.ts +1 -1
- package/dist/commands/usage-command.d.ts.map +1 -1
- package/dist/commands/usage-command.js +5 -16
- package/dist/config.d.ts +17 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +86 -53
- package/dist/execution/index.d.ts +17 -2
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +62 -20
- package/dist/formatting.d.ts +19 -0
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +54 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +212 -153
- package/dist/messages.d.ts +3 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +67 -3
- package/dist/models/anthropic-provider.d.ts.map +1 -1
- package/dist/models/anthropic-provider.js +0 -7
- package/dist/models/deepseek-provider.d.ts.map +1 -1
- package/dist/models/deepseek-provider.js +0 -2
- package/dist/models/google-provider.d.ts.map +1 -1
- package/dist/models/google-provider.js +0 -3
- package/dist/models/groq-provider.d.ts.map +1 -1
- package/dist/models/groq-provider.js +0 -1
- package/dist/models/openai-provider.d.ts.map +1 -1
- package/dist/models/openai-provider.js +0 -4
- package/dist/models/openrouter-provider.d.ts +10 -9
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +82 -88
- package/dist/models/providers.d.ts +4 -14
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/models/providers.js +1 -57
- package/dist/models/xai-provider.d.ts.map +1 -1
- package/dist/models/xai-provider.js +0 -2
- package/dist/prompts.d.ts +9 -4
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +427 -99
- package/dist/repl/project-status-line.d.ts +1 -0
- package/dist/repl/project-status-line.d.ts.map +1 -1
- package/dist/repl/project-status-line.js +57 -27
- package/dist/repl-new.d.ts +0 -2
- package/dist/repl-new.d.ts.map +1 -1
- package/dist/repl-new.js +34 -54
- package/dist/skills.d.ts +20 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +192 -0
- package/dist/terminal/control.d.ts +55 -0
- package/dist/terminal/control.d.ts.map +1 -0
- package/dist/terminal/control.js +109 -0
- package/dist/terminal/default-theme.d.ts +1 -1
- package/dist/terminal/default-theme.d.ts.map +1 -1
- package/dist/terminal/default-theme.js +24 -28
- package/dist/terminal/formatting.d.ts +23 -25
- package/dist/terminal/formatting.d.ts.map +1 -1
- package/dist/terminal/formatting.js +35 -52
- package/dist/terminal/highlight/index.d.ts.map +1 -1
- package/dist/terminal/highlight/index.js +3 -6
- package/dist/terminal/highlight/theme.d.ts.map +1 -1
- package/dist/terminal/highlight/theme.js +2 -6
- package/dist/terminal/index.d.ts +2 -101
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/index.js +2 -464
- package/dist/terminal/markdown.js +7 -5
- package/dist/terminal/strip-ansi.js +4 -4
- package/dist/terminal/table/cell.d.ts +114 -0
- package/dist/terminal/table/cell.d.ts.map +1 -0
- package/dist/terminal/table/cell.js +407 -0
- package/dist/terminal/table/debug.d.ts +15 -0
- package/dist/terminal/table/debug.d.ts.map +1 -0
- package/dist/terminal/table/debug.js +32 -0
- package/dist/terminal/table/index.d.ts +3 -0
- package/dist/terminal/table/index.d.ts.map +1 -0
- package/dist/terminal/table/index.js +2 -0
- package/dist/terminal/table/layout-manager.d.ts +27 -0
- package/dist/terminal/table/layout-manager.d.ts.map +1 -0
- package/dist/terminal/table/layout-manager.js +257 -0
- package/dist/terminal/table/table.d.ts +9 -0
- package/dist/terminal/table/table.d.ts.map +1 -0
- package/dist/terminal/table/table.js +97 -0
- package/dist/terminal/table/utils.d.ts +63 -0
- package/dist/terminal/table/utils.d.ts.map +1 -0
- package/dist/terminal/table/utils.js +326 -0
- package/dist/tokens/threshold.d.ts +6 -21
- package/dist/tokens/threshold.d.ts.map +1 -1
- package/dist/tokens/threshold.js +13 -31
- package/dist/tools/advanced-edit-file.d.ts.map +1 -1
- package/dist/tools/advanced-edit-file.js +5 -1
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/agent.js +19 -5
- package/dist/tools/bash.d.ts +3 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +204 -42
- package/dist/tools/batch.d.ts +34 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +174 -0
- package/dist/tools/code-interpreter.d.ts.map +1 -1
- package/dist/tools/code-interpreter.js +25 -9
- package/dist/tools/delete-file.d.ts.map +1 -1
- package/dist/tools/delete-file.js +9 -2
- package/dist/tools/directory-tree.d.ts +0 -6
- package/dist/tools/directory-tree.d.ts.map +1 -1
- package/dist/tools/directory-tree.js +29 -18
- package/dist/tools/dynamic-tool-loader.d.ts +0 -4
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +2 -2
- package/dist/tools/edit-file.d.ts.map +1 -1
- package/dist/tools/edit-file.js +16 -3
- package/dist/tools/glob.d.ts.map +1 -1
- package/dist/tools/glob.js +24 -13
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +40 -25
- package/dist/tools/index.d.ts +17 -3
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +43 -1
- package/dist/tools/llm-edit-fixer.d.ts +0 -1
- package/dist/tools/llm-edit-fixer.d.ts.map +1 -1
- package/dist/tools/llm-edit-fixer.js +14 -28
- package/dist/tools/move-file.d.ts.map +1 -1
- package/dist/tools/move-file.js +8 -1
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +32 -23
- package/dist/tools/read-multiple-files.d.ts.map +1 -1
- package/dist/tools/read-multiple-files.js +102 -45
- package/dist/tools/save-file.d.ts +4 -4
- package/dist/tools/save-file.d.ts.map +1 -1
- package/dist/tools/save-file.js +20 -2
- package/dist/tools/think.d.ts.map +1 -1
- package/dist/tools/think.js +7 -1
- package/dist/tools/types.d.ts +5 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +1 -1
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +24 -9
- package/dist/tui/components/assistant-message.js +1 -1
- package/dist/tui/components/box.d.ts +20 -0
- package/dist/tui/components/box.d.ts.map +1 -0
- package/dist/tui/components/box.js +81 -0
- package/dist/tui/components/editor.d.ts +60 -5
- package/dist/tui/components/editor.d.ts.map +1 -1
- package/dist/tui/components/editor.js +577 -115
- package/dist/tui/components/footer.d.ts +0 -12
- package/dist/tui/components/footer.d.ts.map +1 -1
- package/dist/tui/components/footer.js +19 -7
- package/dist/tui/components/header.d.ts +21 -0
- package/dist/tui/components/header.d.ts.map +1 -0
- package/dist/tui/components/header.js +63 -0
- package/dist/tui/components/loader.d.ts +5 -1
- package/dist/tui/components/loader.d.ts.map +1 -1
- package/dist/tui/components/loader.js +2 -2
- package/dist/tui/components/markdown.d.ts +26 -23
- package/dist/tui/components/markdown.d.ts.map +1 -1
- package/dist/tui/components/markdown.js +107 -54
- package/dist/tui/components/modal.d.ts +0 -11
- package/dist/tui/components/modal.d.ts.map +1 -1
- package/dist/tui/components/modal.js +0 -29
- package/dist/tui/components/progress-bar.d.ts +19 -0
- package/dist/tui/components/progress-bar.d.ts.map +1 -0
- package/dist/tui/components/progress-bar.js +78 -0
- package/dist/tui/components/prompt-status.d.ts +2 -1
- package/dist/tui/components/prompt-status.d.ts.map +1 -1
- package/dist/tui/components/prompt-status.js +7 -2
- package/dist/tui/components/select-list.d.ts +27 -1
- package/dist/tui/components/select-list.d.ts.map +1 -1
- package/dist/tui/components/select-list.js +93 -29
- package/dist/tui/components/spacer.d.ts +1 -1
- package/dist/tui/components/spacer.d.ts.map +1 -1
- package/dist/tui/components/spacer.js +2 -2
- package/dist/tui/components/table.d.ts +27 -0
- package/dist/tui/components/table.d.ts.map +1 -0
- package/dist/tui/components/table.js +125 -0
- package/dist/tui/components/thinking-block.d.ts.map +1 -1
- package/dist/tui/components/thinking-block.js +4 -1
- package/dist/tui/components/tool-execution.d.ts +8 -4
- package/dist/tui/components/tool-execution.d.ts.map +1 -1
- package/dist/tui/components/tool-execution.js +88 -80
- package/dist/tui/components/user-message.d.ts.map +1 -1
- package/dist/tui/components/user-message.js +6 -4
- package/dist/tui/index.d.ts +9 -5
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +5 -1
- package/dist/tui/terminal.d.ts +2 -1
- package/dist/tui/terminal.d.ts.map +1 -1
- package/dist/tui/terminal.js +28 -38
- package/dist/tui/tui.d.ts +2 -0
- package/dist/tui/tui.d.ts.map +1 -1
- package/dist/tui/tui.js +53 -33
- package/dist/tui/utils.d.ts +5 -0
- package/dist/tui/utils.d.ts.map +1 -1
- package/dist/tui/utils.js +81 -1
- package/dist/{tools/bash-utils.d.ts → utils/bash.d.ts} +3 -3
- package/dist/utils/bash.d.ts.map +1 -0
- package/dist/{tools/bash-utils.js → utils/bash.js} +22 -11
- package/dist/utils/{filesystem.d.ts → filesystem/operations.d.ts} +1 -1
- package/dist/utils/filesystem/operations.d.ts.map +1 -0
- package/dist/{tools/filesystem-utils.d.ts → utils/filesystem/security.d.ts} +3 -2
- package/dist/utils/filesystem/security.d.ts.map +1 -0
- package/dist/{tools/filesystem-utils.js → utils/filesystem/security.js} +62 -4
- package/dist/utils/funcs.d.ts +6 -0
- package/dist/utils/funcs.d.ts.map +1 -0
- package/dist/utils/funcs.js +6 -0
- package/dist/{tools/git-utils.d.ts → utils/git.d.ts} +1 -1
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/{tools/git-utils.js → utils/git.js} +0 -6
- package/dist/utils/glob.js +1 -1
- package/dist/utils/{zod-utils.d.ts → zod.d.ts} +1 -1
- package/dist/utils/zod.d.ts.map +1 -0
- package/package.json +17 -17
- package/dist/agent/manual-loop.d.ts +0 -41
- package/dist/agent/manual-loop.d.ts.map +0 -1
- package/dist/agent/manual-loop.js +0 -278
- package/dist/repl/display-tool-messages.d.ts +0 -4
- package/dist/repl/display-tool-messages.d.ts.map +0 -1
- package/dist/repl/display-tool-messages.js +0 -58
- package/dist/repl/display-tool-use.d.ts +0 -14
- package/dist/repl/display-tool-use.d.ts.map +0 -1
- package/dist/repl/display-tool-use.js +0 -63
- package/dist/repl/get-prompt-header.d.ts +0 -8
- package/dist/repl/get-prompt-header.d.ts.map +0 -1
- package/dist/repl/get-prompt-header.js +0 -9
- package/dist/repl/prompt.d.ts +0 -21
- package/dist/repl/prompt.d.ts.map +0 -1
- package/dist/repl/prompt.js +0 -244
- package/dist/repl.d.ts +0 -29
- package/dist/repl.d.ts.map +0 -1
- package/dist/repl.js +0 -218
- package/dist/terminal/checkbox-prompt.d.ts +0 -36
- package/dist/terminal/checkbox-prompt.d.ts.map +0 -1
- package/dist/terminal/checkbox-prompt.js +0 -368
- package/dist/terminal/editor-prompt.d.ts +0 -10
- package/dist/terminal/editor-prompt.d.ts.map +0 -1
- package/dist/terminal/editor-prompt.js +0 -61
- package/dist/terminal/errors.d.ts +0 -19
- package/dist/terminal/errors.d.ts.map +0 -1
- package/dist/terminal/errors.js +0 -37
- package/dist/terminal/input-prompt.d.ts +0 -17
- package/dist/terminal/input-prompt.d.ts.map +0 -1
- package/dist/terminal/input-prompt.js +0 -181
- package/dist/terminal/search-prompt.d.ts +0 -20
- package/dist/terminal/search-prompt.d.ts.map +0 -1
- package/dist/terminal/search-prompt.js +0 -280
- package/dist/terminal/types.d.ts +0 -35
- package/dist/terminal/types.d.ts.map +0 -1
- package/dist/terminal/types.js +0 -1
- package/dist/tools/bash-utils.d.ts.map +0 -1
- package/dist/tools/filesystem-utils.d.ts.map +0 -1
- package/dist/tools/git-utils.d.ts.map +0 -1
- package/dist/utils/filesystem.d.ts.map +0 -1
- package/dist/utils/zod-utils.d.ts.map +0 -1
- /package/dist/utils/{filesystem.js → filesystem/operations.js} +0 -0
- /package/dist/utils/{zod-utils.js → zod.js} +0 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import stringWidth from "../string-width.js";
|
|
2
|
+
function codeRegex(capture) {
|
|
3
|
+
return capture
|
|
4
|
+
? // biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape sequences for terminal formatting
|
|
5
|
+
/\u001b\[((?:\d*;){0,5}\d*)m/g
|
|
6
|
+
: // biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape sequences for terminal formatting
|
|
7
|
+
/\u001b\[(?:\d*;){0,5}\d*m/g;
|
|
8
|
+
}
|
|
9
|
+
export function strlen(str) {
|
|
10
|
+
const code = codeRegex(false);
|
|
11
|
+
const stripped = `${str}`.replace(code, "");
|
|
12
|
+
const split = stripped.split("\n");
|
|
13
|
+
return split.reduce((memo, s) => {
|
|
14
|
+
return stringWidth(s) > memo ? stringWidth(s) : memo;
|
|
15
|
+
}, 0);
|
|
16
|
+
}
|
|
17
|
+
export function repeat(str, times) {
|
|
18
|
+
return Array(times + 1).join(str);
|
|
19
|
+
}
|
|
20
|
+
export function pad(str, len, padChar, dir) {
|
|
21
|
+
const length = strlen(str);
|
|
22
|
+
let result = str;
|
|
23
|
+
if (len + 1 >= length) {
|
|
24
|
+
const padlen = len - length;
|
|
25
|
+
switch (dir) {
|
|
26
|
+
case "right": {
|
|
27
|
+
result = repeat(padChar, padlen) + result;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case "center": {
|
|
31
|
+
const right = Math.ceil(padlen / 2);
|
|
32
|
+
const left = padlen - right;
|
|
33
|
+
result = repeat(padChar, left) + result + repeat(padChar, right);
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
default: {
|
|
37
|
+
result = result + repeat(padChar, padlen);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
const codeCache = {};
|
|
45
|
+
function addToCodeCache(name, on, off) {
|
|
46
|
+
const onCode = `\u001b[${on}m`;
|
|
47
|
+
const offCode = `\u001b[${off}m`;
|
|
48
|
+
codeCache[onCode] = { set: name, to: true };
|
|
49
|
+
codeCache[offCode] = { set: name, to: false };
|
|
50
|
+
codeCache[name] = { on: onCode, off: offCode };
|
|
51
|
+
}
|
|
52
|
+
// https://github.com/Marak/colors.js/blob/master/lib/styles.js
|
|
53
|
+
addToCodeCache("bold", "1", "22");
|
|
54
|
+
addToCodeCache("italics", "3", "23");
|
|
55
|
+
addToCodeCache("underline", "4", "24");
|
|
56
|
+
addToCodeCache("inverse", "7", "27");
|
|
57
|
+
addToCodeCache("strikethrough", "9", "29");
|
|
58
|
+
function updateState(state, controlChars) {
|
|
59
|
+
const controlCode = controlChars[1]
|
|
60
|
+
? Number.parseInt(controlChars[1].split(";")[0], 10)
|
|
61
|
+
: 0;
|
|
62
|
+
if ((controlCode >= 30 && controlCode <= 39) ||
|
|
63
|
+
(controlCode >= 90 && controlCode <= 97)) {
|
|
64
|
+
state.lastForegroundAdded = controlChars[0];
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if ((controlCode >= 40 && controlCode <= 49) ||
|
|
68
|
+
(controlCode >= 100 && controlCode <= 107)) {
|
|
69
|
+
state.lastBackgroundAdded = controlChars[0];
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (controlCode === 0) {
|
|
73
|
+
for (const i in state) {
|
|
74
|
+
/* istanbul ignore else */
|
|
75
|
+
if (Object.hasOwn(state, i)) {
|
|
76
|
+
delete state[i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const info = codeCache[controlChars[0]];
|
|
82
|
+
if (info) {
|
|
83
|
+
state[info.set] = info.to;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function readState(line) {
|
|
87
|
+
const code = codeRegex(true);
|
|
88
|
+
let controlChars = code.exec(line);
|
|
89
|
+
const state = {};
|
|
90
|
+
while (controlChars !== null) {
|
|
91
|
+
updateState(state, controlChars);
|
|
92
|
+
controlChars = code.exec(line);
|
|
93
|
+
}
|
|
94
|
+
return state;
|
|
95
|
+
}
|
|
96
|
+
function unwindState(state, ret) {
|
|
97
|
+
const lastBackgroundAdded = state.lastBackgroundAdded;
|
|
98
|
+
const lastForegroundAdded = state.lastForegroundAdded;
|
|
99
|
+
delete state.lastBackgroundAdded;
|
|
100
|
+
delete state.lastForegroundAdded;
|
|
101
|
+
let result = ret;
|
|
102
|
+
Object.keys(state).forEach((key) => {
|
|
103
|
+
if (state[key]) {
|
|
104
|
+
const cacheEntry = codeCache[key];
|
|
105
|
+
result += cacheEntry.off;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (lastBackgroundAdded && lastBackgroundAdded !== "\u001b[49m") {
|
|
109
|
+
result += "\u001b[49m";
|
|
110
|
+
}
|
|
111
|
+
if (lastForegroundAdded && lastForegroundAdded !== "\u001b[39m") {
|
|
112
|
+
result += "\u001b[39m";
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
function rewindState(state, ret) {
|
|
117
|
+
const lastBackgroundAdded = state.lastBackgroundAdded;
|
|
118
|
+
const lastForegroundAdded = state.lastForegroundAdded;
|
|
119
|
+
delete state.lastBackgroundAdded;
|
|
120
|
+
delete state.lastForegroundAdded;
|
|
121
|
+
let result = ret;
|
|
122
|
+
Object.keys(state).forEach((key) => {
|
|
123
|
+
if (state[key]) {
|
|
124
|
+
const cacheEntry = codeCache[key];
|
|
125
|
+
result = cacheEntry.on + result;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (lastBackgroundAdded && lastBackgroundAdded !== "\u001b[49m") {
|
|
129
|
+
result = lastBackgroundAdded + result;
|
|
130
|
+
}
|
|
131
|
+
if (lastForegroundAdded && lastForegroundAdded !== "\u001b[39m") {
|
|
132
|
+
result = lastForegroundAdded + result;
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
function truncateWidth(str, desiredLength) {
|
|
137
|
+
if (str.length === strlen(str)) {
|
|
138
|
+
return str.substr(0, desiredLength);
|
|
139
|
+
}
|
|
140
|
+
let result = str;
|
|
141
|
+
while (strlen(result) > desiredLength) {
|
|
142
|
+
result = result.slice(0, -1);
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
function truncateWidthWithAnsi(str, desiredLength) {
|
|
147
|
+
const code = codeRegex(true);
|
|
148
|
+
const split = str.split(codeRegex(false));
|
|
149
|
+
let splitIndex = 0;
|
|
150
|
+
let retLen = 0;
|
|
151
|
+
let ret = "";
|
|
152
|
+
let myArray;
|
|
153
|
+
const state = {};
|
|
154
|
+
while (retLen < desiredLength) {
|
|
155
|
+
myArray = code.exec(str);
|
|
156
|
+
let toAdd = split[splitIndex];
|
|
157
|
+
splitIndex++;
|
|
158
|
+
if (retLen + strlen(toAdd) > desiredLength) {
|
|
159
|
+
toAdd = truncateWidth(toAdd, desiredLength - retLen);
|
|
160
|
+
}
|
|
161
|
+
ret += toAdd;
|
|
162
|
+
retLen += strlen(toAdd);
|
|
163
|
+
if (retLen < desiredLength) {
|
|
164
|
+
if (!myArray) {
|
|
165
|
+
break;
|
|
166
|
+
} // full-width chars may cause a whitespace which cannot be filled
|
|
167
|
+
ret += myArray[0];
|
|
168
|
+
updateState(state, myArray);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return unwindState(state, ret);
|
|
172
|
+
}
|
|
173
|
+
export function truncate(str, desiredLength, truncateChar) {
|
|
174
|
+
const finalTruncateChar = truncateChar || "…";
|
|
175
|
+
const lengthOfStr = strlen(str);
|
|
176
|
+
if (lengthOfStr <= desiredLength) {
|
|
177
|
+
return str;
|
|
178
|
+
}
|
|
179
|
+
const finalDesiredLength = desiredLength - strlen(finalTruncateChar);
|
|
180
|
+
let ret = truncateWidthWithAnsi(str, finalDesiredLength);
|
|
181
|
+
ret += finalTruncateChar;
|
|
182
|
+
const hrefTag = "\x1B]8;;\x07";
|
|
183
|
+
if (str.includes(hrefTag) && !ret.includes(hrefTag)) {
|
|
184
|
+
ret += hrefTag;
|
|
185
|
+
}
|
|
186
|
+
return ret;
|
|
187
|
+
}
|
|
188
|
+
export function defaultOptions() {
|
|
189
|
+
return {
|
|
190
|
+
chars: {
|
|
191
|
+
top: "─",
|
|
192
|
+
topMid: "┬",
|
|
193
|
+
topLeft: "┌",
|
|
194
|
+
topRight: "┐",
|
|
195
|
+
bottom: "─",
|
|
196
|
+
bottomMid: "┴",
|
|
197
|
+
bottomLeft: "└",
|
|
198
|
+
bottomRight: "┘",
|
|
199
|
+
left: "│",
|
|
200
|
+
leftMid: "├",
|
|
201
|
+
mid: "─",
|
|
202
|
+
midMid: "┼",
|
|
203
|
+
right: "│",
|
|
204
|
+
rightMid: "┤",
|
|
205
|
+
middle: "│",
|
|
206
|
+
},
|
|
207
|
+
truncate: "…",
|
|
208
|
+
colWidths: [],
|
|
209
|
+
rowHeights: [],
|
|
210
|
+
colAligns: [],
|
|
211
|
+
rowAligns: [],
|
|
212
|
+
style: {
|
|
213
|
+
"padding-left": 1,
|
|
214
|
+
"padding-right": 1,
|
|
215
|
+
head: ["red"],
|
|
216
|
+
border: ["grey"],
|
|
217
|
+
compact: false,
|
|
218
|
+
},
|
|
219
|
+
head: [],
|
|
220
|
+
wordWrap: false,
|
|
221
|
+
wrapOnWordBoundary: true,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export function mergeOptions(options, defaults) {
|
|
225
|
+
const finalOptions = options || {};
|
|
226
|
+
const finalDefaults = defaults || defaultOptions();
|
|
227
|
+
const ret = Object.assign({}, finalDefaults, finalOptions);
|
|
228
|
+
ret.chars = Object.assign({}, finalDefaults.chars, finalOptions.chars);
|
|
229
|
+
ret.style = Object.assign({}, finalDefaults.style, finalOptions.style);
|
|
230
|
+
return ret;
|
|
231
|
+
}
|
|
232
|
+
// Wrap on word boundary
|
|
233
|
+
function wordWrap(maxLength, input) {
|
|
234
|
+
const lines = [];
|
|
235
|
+
const split = input.split(/(\s+)/g);
|
|
236
|
+
const line = [];
|
|
237
|
+
let lineLength = 0;
|
|
238
|
+
let whitespace = "";
|
|
239
|
+
for (let i = 0; i < split.length; i += 2) {
|
|
240
|
+
const word = split[i];
|
|
241
|
+
let newLength = lineLength + strlen(word);
|
|
242
|
+
if (lineLength > 0 && whitespace) {
|
|
243
|
+
newLength += whitespace.length;
|
|
244
|
+
}
|
|
245
|
+
if (newLength > maxLength) {
|
|
246
|
+
if (lineLength !== 0) {
|
|
247
|
+
lines.push(line.join(""));
|
|
248
|
+
}
|
|
249
|
+
line.length = 0;
|
|
250
|
+
line.push(word);
|
|
251
|
+
lineLength = strlen(word);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
line.push(whitespace || "", word);
|
|
255
|
+
lineLength = newLength;
|
|
256
|
+
}
|
|
257
|
+
whitespace = split[i + 1];
|
|
258
|
+
}
|
|
259
|
+
if (lineLength) {
|
|
260
|
+
lines.push(line.join(""));
|
|
261
|
+
}
|
|
262
|
+
return lines;
|
|
263
|
+
}
|
|
264
|
+
// Wrap text (ignoring word boundaries)
|
|
265
|
+
function textWrap(maxLength, input) {
|
|
266
|
+
const lines = [];
|
|
267
|
+
let line = "";
|
|
268
|
+
function pushLine(str, ws) {
|
|
269
|
+
if (line.length && ws)
|
|
270
|
+
line += ws;
|
|
271
|
+
line += str;
|
|
272
|
+
while (line.length > maxLength) {
|
|
273
|
+
lines.push(line.slice(0, maxLength));
|
|
274
|
+
line = line.slice(maxLength);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const split = input.split(/(\s+)/g);
|
|
278
|
+
for (let i = 0; i < split.length; i += 2) {
|
|
279
|
+
pushLine(split[i], i ? split[i - 1] : "");
|
|
280
|
+
}
|
|
281
|
+
if (line.length)
|
|
282
|
+
lines.push(line);
|
|
283
|
+
return lines;
|
|
284
|
+
}
|
|
285
|
+
export function multiLineWordWrap(maxLength, input, wrapOnWordBoundary = true) {
|
|
286
|
+
const output = [];
|
|
287
|
+
const lines = input.split("\n");
|
|
288
|
+
const handler = wrapOnWordBoundary ? wordWrap : textWrap;
|
|
289
|
+
for (let i = 0; i < lines.length; i++) {
|
|
290
|
+
output.push(...handler(maxLength, lines[i]));
|
|
291
|
+
}
|
|
292
|
+
return output;
|
|
293
|
+
}
|
|
294
|
+
export function colorizeLines(input) {
|
|
295
|
+
let state = {};
|
|
296
|
+
const output = [];
|
|
297
|
+
for (let i = 0; i < input.length; i++) {
|
|
298
|
+
const line = rewindState(state, input[i]);
|
|
299
|
+
state = readState(line);
|
|
300
|
+
const temp = Object.assign({}, state);
|
|
301
|
+
output.push(unwindState(temp, line));
|
|
302
|
+
}
|
|
303
|
+
return output;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Credit: Matheus Sampaio https://github.com/matheussampaio
|
|
307
|
+
*/
|
|
308
|
+
export function hyperlink(url, text) {
|
|
309
|
+
const Osc = "\u001B]";
|
|
310
|
+
const Bel = "\u0007";
|
|
311
|
+
const Sep = ";";
|
|
312
|
+
return [
|
|
313
|
+
Osc,
|
|
314
|
+
"8",
|
|
315
|
+
Sep,
|
|
316
|
+
Sep,
|
|
317
|
+
url || text,
|
|
318
|
+
Bel,
|
|
319
|
+
text,
|
|
320
|
+
Osc,
|
|
321
|
+
"8",
|
|
322
|
+
Sep,
|
|
323
|
+
Sep,
|
|
324
|
+
Bel,
|
|
325
|
+
].join("");
|
|
326
|
+
}
|
|
@@ -1,35 +1,20 @@
|
|
|
1
1
|
import type { TokenCounter } from "./counter.ts";
|
|
2
2
|
export declare function clearTokenCache(): void;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
interface TokenLimitResult {
|
|
7
|
-
content: string;
|
|
8
|
-
tokenCount: number;
|
|
9
|
-
truncated: boolean;
|
|
3
|
+
export declare class TokenLimitExceededError extends Error {
|
|
4
|
+
constructor(toolName: string, tokenCount: number, maxTokens: number, guidance?: string);
|
|
10
5
|
}
|
|
11
6
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param toolName - Name of the tool (e.g., "ReadFile", "Bash")
|
|
14
|
-
* @param tokenCount - Actual token count of content
|
|
15
|
-
* @param maxTokens - Maximum allowed tokens
|
|
16
|
-
* @param additionalGuidance - Optional specific guidance for this tool
|
|
17
|
-
* @returns TokenLimitResult with message and metadata
|
|
18
|
-
*/
|
|
19
|
-
export declare function createTokenLimitResult(toolName: string, tokenCount: number, additionalGuidance?: string): TokenLimitResult;
|
|
20
|
-
/**
|
|
21
|
-
* Check if content should be truncated and return appropriate result
|
|
7
|
+
* Check if content exceeds token limit
|
|
22
8
|
* @param content - The content to check
|
|
23
9
|
* @param tokenCounter - Token counter instance
|
|
24
10
|
* @param toolName - Name of the tool for messages
|
|
25
11
|
* @param additionalGuidance - Optional tool-specific guidance
|
|
26
12
|
* @param encoding - Optional encoding type for non-text file handling
|
|
27
|
-
* @returns
|
|
13
|
+
* @returns Content with token count if under limit
|
|
14
|
+
* @throws TokenLimitExceededError if content exceeds token limit
|
|
28
15
|
*/
|
|
29
16
|
export declare function manageTokenLimit<T extends string>(content: T, tokenCounter: TokenCounter, toolName: string, additionalGuidance?: string, encoding?: string): Promise<{
|
|
30
|
-
content: T
|
|
17
|
+
content: T;
|
|
31
18
|
tokenCount: number;
|
|
32
|
-
truncated: boolean;
|
|
33
19
|
}>;
|
|
34
|
-
export {};
|
|
35
20
|
//# sourceMappingURL=threshold.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threshold.d.ts","sourceRoot":"","sources":["../../source/tokens/threshold.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQjD,wBAAgB,eAAe,SAG9B;AAyBD
|
|
1
|
+
{"version":3,"file":"threshold.d.ts","sourceRoot":"","sources":["../../source/tokens/threshold.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQjD,wBAAgB,eAAe,SAG9B;AAyBD,qBAAa,uBAAwB,SAAQ,KAAK;gBAE9C,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE,MAAM;CASpB;AAED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EACrD,OAAO,EAAE,CAAC,EACV,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM,EAChB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,OAAO,EAAE,CAAC,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CA2B7C"}
|
package/dist/tokens/threshold.js
CHANGED
|
@@ -17,7 +17,7 @@ async function getMaxTokens() {
|
|
|
17
17
|
return maxTokensCache;
|
|
18
18
|
}
|
|
19
19
|
try {
|
|
20
|
-
const projectConfig = await config.
|
|
20
|
+
const projectConfig = await config.getConfig();
|
|
21
21
|
maxTokensCache = projectConfig.tools.maxTokens;
|
|
22
22
|
cacheExpiry = now + CACHE_DURATION;
|
|
23
23
|
return maxTokensCache;
|
|
@@ -29,39 +29,26 @@ async function getMaxTokens() {
|
|
|
29
29
|
return maxTokensCache;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param additionalGuidance - Optional specific guidance for this tool
|
|
38
|
-
* @returns TokenLimitResult with message and metadata
|
|
39
|
-
*/
|
|
40
|
-
export function createTokenLimitResult(toolName, tokenCount, additionalGuidance) {
|
|
41
|
-
const truncated = true;
|
|
42
|
-
const baseMessage = `${toolName}: Content (${tokenCount} tokens) exceeds maximum allowed tokens`;
|
|
43
|
-
const guidance = additionalGuidance ??
|
|
44
|
-
"Please adjust your parameters to reduce content size";
|
|
45
|
-
const content = `${baseMessage}. ${guidance}`;
|
|
46
|
-
return {
|
|
47
|
-
content,
|
|
48
|
-
tokenCount,
|
|
49
|
-
truncated,
|
|
50
|
-
};
|
|
32
|
+
export class TokenLimitExceededError extends Error {
|
|
33
|
+
constructor(toolName, tokenCount, maxTokens, guidance) {
|
|
34
|
+
super(`${toolName}: Content (${tokenCount} tokens) exceeds maximum allowed tokens (${maxTokens}). ${guidance || "Please adjust parameters to reduce content size."}`);
|
|
35
|
+
this.name = "TokenLimitExceededError";
|
|
36
|
+
}
|
|
51
37
|
}
|
|
52
38
|
/**
|
|
53
|
-
* Check if content
|
|
39
|
+
* Check if content exceeds token limit
|
|
54
40
|
* @param content - The content to check
|
|
55
41
|
* @param tokenCounter - Token counter instance
|
|
56
42
|
* @param toolName - Name of the tool for messages
|
|
57
43
|
* @param additionalGuidance - Optional tool-specific guidance
|
|
58
44
|
* @param encoding - Optional encoding type for non-text file handling
|
|
59
|
-
* @returns
|
|
45
|
+
* @returns Content with token count if under limit
|
|
46
|
+
* @throws TokenLimitExceededError if content exceeds token limit
|
|
60
47
|
*/
|
|
61
48
|
export async function manageTokenLimit(content, tokenCounter, toolName, additionalGuidance, encoding) {
|
|
62
49
|
// For non-text files, return content directly without token management
|
|
63
50
|
if (encoding && !encoding.startsWith("utf")) {
|
|
64
|
-
return { content, tokenCount: 0
|
|
51
|
+
return { content, tokenCount: 0 };
|
|
65
52
|
}
|
|
66
53
|
let tokenCount = 0;
|
|
67
54
|
try {
|
|
@@ -70,16 +57,11 @@ export async function manageTokenLimit(content, tokenCounter, toolName, addition
|
|
|
70
57
|
catch (tokenError) {
|
|
71
58
|
console.info("Error calculating token count:", tokenError);
|
|
72
59
|
// Return content if token counting fails
|
|
73
|
-
return { content, tokenCount: 0
|
|
60
|
+
return { content, tokenCount: 0 };
|
|
74
61
|
}
|
|
75
62
|
const maxTokens = await getMaxTokens();
|
|
76
63
|
if (tokenCount <= maxTokens) {
|
|
77
|
-
return { content, tokenCount
|
|
64
|
+
return { content, tokenCount };
|
|
78
65
|
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
content: limitResult.content,
|
|
82
|
-
tokenCount,
|
|
83
|
-
truncated: true,
|
|
84
|
-
};
|
|
66
|
+
throw new TokenLimitExceededError(toolName, tokenCount, maxTokens, additionalGuidance);
|
|
85
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced-edit-file.d.ts","sourceRoot":"","sources":["../../source/tools/advanced-edit-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"advanced-edit-file.d.ts","sourceRoot":"","sources":["../../source/tools/advanced-edit-file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,oBAAoB;;CAEhC,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;iBAuCf,CAAC;AAEH,KAAK,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAE/D,UAAU,aAAa;IACrB,IAAI,EAAE,SAAS,GAAG,eAAe,GAAG,cAAc,GAAG,QAAQ,CAAC;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,0BAA0B,GAAU,8BAG9C;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;;;;;;;;;;;;;;;;;;;;;;;;;;6EAiBQ,2BAA2B,+BACD,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;EAoDhC,CAAC;AA2MF,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,KAAK,EAC/B,UAAU,EAAE,aAAa,EAAE,EAC3B,UAAU,CAAC,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,MAAM,EACvB,MAAM,UAAQ,EACd,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,MAAM,CAAC,CAyEjB"}
|
|
@@ -2,8 +2,9 @@ import { execSync } from "node:child_process";
|
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { createTwoFilesPatch } from "diff";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import { config } from "../config.js";
|
|
5
6
|
import style from "../terminal/style.js";
|
|
6
|
-
import { joinWorkingDir, validatePath } from "
|
|
7
|
+
import { joinWorkingDir, validateFileNotReadOnly, validatePath, } from "../utils/filesystem/security.js";
|
|
7
8
|
export const AdvancedEditFileTool = {
|
|
8
9
|
name: "advancedEditFile",
|
|
9
10
|
};
|
|
@@ -59,6 +60,9 @@ export const createAdvancedEditFileTool = async ({ workingDir, allowedDirs, }) =
|
|
|
59
60
|
data: `${style.cyan(path)} (mode: ${mode})`,
|
|
60
61
|
};
|
|
61
62
|
const validPath = await validatePath(joinWorkingDir(path, workingDir), allowedDirectory, { abortSignal });
|
|
63
|
+
// Check if file is read-only
|
|
64
|
+
const projectConfig = await config.getConfig();
|
|
65
|
+
validateFileNotReadOnly(validPath, projectConfig, workingDir);
|
|
62
66
|
const result = await applyAdvancedFileEdits(validPath, mode, operations, astPattern, astReplacement, dryRun, abortSignal);
|
|
63
67
|
yield {
|
|
64
68
|
name: AdvancedEditFileTool.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../source/tools/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAOzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,SAAS;;CAErB,CAAC;AAiCF,QAAA,MAAM,WAAW;;iBAEf,CAAC;AAEH,eAAO,MAAM,gBAAgB,GAAI,SAAS;IACxC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,gBAAgB,CAAC;CAC7B;;;;;;;0BASe,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,+BACV,eAAe,KAC3C,cAAc,CAAC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../source/tools/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAOzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,SAAS;;CAErB,CAAC;AAiCF,QAAA,MAAM,WAAW;;iBAEf,CAAC;AAEH,eAAO,MAAM,gBAAgB,GAAI,SAAS;IACxC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,gBAAgB,CAAC;CAC7B;;;;;;;0BASe,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,+BACV,eAAe,KAC3C,cAAc,CAAC,UAAU,CAAC;CA+E9B,CAAC"}
|
package/dist/tools/agent.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { generateText, stepCountIs } from "ai";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { AiConfig } from "../models/ai-config.js";
|
|
4
|
-
import style from "../terminal/style.js";
|
|
5
4
|
import { DirectoryTreeTool } from "./directory-tree.js";
|
|
6
5
|
import { GlobTool } from "./glob.js";
|
|
7
6
|
import { GrepTool } from "./grep.js";
|
|
@@ -55,13 +54,19 @@ export const createAgentTools = (options) => {
|
|
|
55
54
|
name: AgentTool.name,
|
|
56
55
|
event: "tool-init",
|
|
57
56
|
id: toolCallId,
|
|
58
|
-
data:
|
|
57
|
+
data: "Invoking agent...",
|
|
58
|
+
};
|
|
59
|
+
yield {
|
|
60
|
+
name: AgentTool.name,
|
|
61
|
+
event: "tool-update",
|
|
62
|
+
id: toolCallId,
|
|
63
|
+
data: `## Prompt:\n\n${prompt}`,
|
|
59
64
|
};
|
|
60
65
|
try {
|
|
61
66
|
const modelConfig = modelManager.getModelMetadata("task-agent");
|
|
62
67
|
const aiConfig = new AiConfig({
|
|
63
68
|
modelMetadata: modelConfig,
|
|
64
|
-
prompt
|
|
69
|
+
prompt,
|
|
65
70
|
});
|
|
66
71
|
const { text, usage } = await generateText({
|
|
67
72
|
model: modelManager.getModel("task-agent"),
|
|
@@ -72,17 +77,26 @@ export const createAgentTools = (options) => {
|
|
|
72
77
|
topP: aiConfig.topP(),
|
|
73
78
|
stopWhen: stepCountIs(30),
|
|
74
79
|
providerOptions: aiConfig.providerOptions(),
|
|
75
|
-
tools: (await initCliTools({
|
|
80
|
+
tools: (await initCliTools({
|
|
81
|
+
tokenCounter,
|
|
82
|
+
workspace: options.workspace,
|
|
83
|
+
})).toolDefs,
|
|
76
84
|
abortSignal: abortSignal,
|
|
77
85
|
// biome-ignore lint/style/useNamingConvention: third-party code
|
|
78
86
|
experimental_activeTools: [...TOOLS],
|
|
79
87
|
});
|
|
80
88
|
tokenTracker.trackUsage("task-agent", usage);
|
|
89
|
+
yield {
|
|
90
|
+
name: AgentTool.name,
|
|
91
|
+
event: "tool-update",
|
|
92
|
+
id: toolCallId,
|
|
93
|
+
data: `## Response:\n\n${text}`,
|
|
94
|
+
};
|
|
81
95
|
yield {
|
|
82
96
|
name: AgentTool.name,
|
|
83
97
|
event: "tool-completion",
|
|
84
98
|
id: toolCallId,
|
|
85
|
-
data: `Finished
|
|
99
|
+
data: `Finished (${usage.totalTokens} tokens)`,
|
|
86
100
|
};
|
|
87
101
|
yield text;
|
|
88
102
|
}
|
package/dist/tools/bash.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare const inputSchema: z.ZodObject<{
|
|
|
9
9
|
command: z.ZodString;
|
|
10
10
|
cwd: z.ZodNullable<z.ZodString>;
|
|
11
11
|
timeout: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
12
|
+
background: z.ZodOptional<z.ZodBoolean>;
|
|
12
13
|
}, z.core.$strip>;
|
|
13
14
|
type BashInputSchema = z.infer<typeof inputSchema>;
|
|
14
15
|
export declare const createBashTool: ({ baseDir, allowedDirs, tokenCounter, }: {
|
|
@@ -22,9 +23,10 @@ export declare const createBashTool: ({ baseDir, allowedDirs, tokenCounter, }: {
|
|
|
22
23
|
command: z.ZodString;
|
|
23
24
|
cwd: z.ZodNullable<z.ZodString>;
|
|
24
25
|
timeout: z.ZodNullable<z.ZodCoercedNumber<unknown>>;
|
|
26
|
+
background: z.ZodOptional<z.ZodBoolean>;
|
|
25
27
|
}, z.core.$strip>;
|
|
26
28
|
};
|
|
27
|
-
execute({ command, cwd, timeout }: BashInputSchema, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
29
|
+
execute({ command, cwd, timeout, background }: BashInputSchema, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
28
30
|
}>;
|
|
29
31
|
export {};
|
|
30
32
|
//# sourceMappingURL=bash.d.ts.map
|
package/dist/tools/bash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../source/tools/bash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../source/tools/bash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAMzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,QAAQ;;CAEpB,CAAC;AAYF,QAAA,MAAM,WAAW;;;;;iBAoBf,CAAC;AAEH,KAAK,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEnD,eAAO,MAAM,cAAc,GAAU,yCAIlC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;;;;mDAS4C,eAAe,+BACzB,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;EAqJhC,CAAC"}
|