@travisennis/acai 0.0.3 → 0.0.5
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 +225 -6
- package/dist/api/exa/index.d.ts +177 -0
- package/dist/api/exa/index.d.ts.map +1 -0
- package/dist/api/exa/index.js +439 -0
- package/dist/cli.d.ts +3 -2
- package/dist/cli.d.ts.map +1 -0
- package/dist/commands/application-log-command.d.ts +1 -0
- package/dist/commands/application-log-command.d.ts.map +1 -0
- package/dist/commands/application-log-command.js +5 -3
- package/dist/commands/clear-command.d.ts +1 -0
- package/dist/commands/clear-command.d.ts.map +1 -0
- package/dist/commands/clear-command.js +2 -3
- package/dist/commands/compact-command.d.ts +1 -0
- package/dist/commands/compact-command.d.ts.map +1 -0
- package/dist/commands/compact-command.js +1 -1
- package/dist/commands/copy-command.d.ts +1 -0
- package/dist/commands/copy-command.d.ts.map +1 -0
- package/dist/commands/copy-command.js +3 -2
- package/dist/commands/edit-command.d.ts +1 -0
- package/dist/commands/edit-command.d.ts.map +1 -0
- package/dist/commands/edit-command.js +7 -5
- package/dist/commands/edit-prompt-command.d.ts +2 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -0
- package/dist/commands/edit-prompt-command.js +15 -7
- package/dist/commands/exit-command.d.ts +13 -2
- package/dist/commands/exit-command.d.ts.map +1 -0
- package/dist/commands/exit-command.js +14 -2
- package/dist/commands/files-command.d.ts +1 -0
- package/dist/commands/files-command.d.ts.map +1 -0
- package/dist/commands/files-command.js +9 -8
- package/dist/commands/generate-rules-command.d.ts +1 -0
- package/dist/commands/generate-rules-command.d.ts.map +1 -0
- package/dist/commands/generate-rules-command.js +4 -3
- package/dist/commands/health-command.d.ts +3 -1
- package/dist/commands/health-command.d.ts.map +1 -0
- package/dist/commands/health-command.js +42 -5
- package/dist/commands/help-command.d.ts +1 -0
- package/dist/commands/help-command.d.ts.map +1 -0
- package/dist/commands/help-command.js +2 -3
- package/dist/commands/init-command.d.ts +1 -0
- package/dist/commands/init-command.d.ts.map +1 -0
- package/dist/commands/init-command.js +1 -2
- package/dist/commands/last-log-command.d.ts +1 -0
- package/dist/commands/last-log-command.d.ts.map +1 -0
- package/dist/commands/last-log-command.js +12 -17
- package/dist/commands/list-tools-command.d.ts +3 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -0
- package/dist/commands/list-tools-command.js +61 -0
- package/dist/commands/manager.d.ts +7 -2
- package/dist/commands/manager.d.ts.map +1 -0
- package/dist/commands/manager.js +43 -6
- package/dist/commands/model-command.d.ts +1 -0
- package/dist/commands/model-command.d.ts.map +1 -0
- package/dist/commands/model-command.js +5 -5
- package/dist/commands/paste-command.d.ts +1 -0
- package/dist/commands/paste-command.d.ts.map +1 -0
- package/dist/commands/paste-command.js +6 -5
- package/dist/commands/prompt-command.d.ts +2 -1
- package/dist/commands/prompt-command.d.ts.map +1 -0
- package/dist/commands/prompt-command.js +62 -8
- package/dist/commands/reset-command.d.ts +1 -0
- package/dist/commands/reset-command.d.ts.map +1 -0
- package/dist/commands/reset-command.js +1 -1
- package/dist/commands/rules-command.d.ts +1 -0
- package/dist/commands/rules-command.d.ts.map +1 -0
- package/dist/commands/rules-command.js +5 -3
- package/dist/commands/save-command.d.ts +1 -0
- package/dist/commands/save-command.d.ts.map +1 -0
- package/dist/commands/save-command.js +1 -1
- package/dist/commands/shell-command.d.ts +3 -0
- package/dist/commands/shell-command.d.ts.map +1 -0
- package/dist/commands/shell-command.js +60 -0
- package/dist/commands/types.d.ts +9 -6
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/usage-command.d.ts +1 -0
- package/dist/commands/usage-command.d.ts.map +1 -0
- package/dist/commands/usage-command.js +2 -3
- package/dist/config.d.ts +22 -34
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +61 -15
- package/dist/conversation-analyzer.d.ts +2 -1
- package/dist/conversation-analyzer.d.ts.map +1 -0
- package/dist/dedent.d.ts +1 -0
- package/dist/dedent.d.ts.map +1 -0
- package/dist/execution/index.d.ts +112 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +432 -0
- package/dist/formatting.d.ts +2 -13
- package/dist/formatting.d.ts.map +1 -0
- package/dist/formatting.js +5 -64
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -4
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/mentions.d.ts +4 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +42 -10
- package/dist/messages.d.ts +8 -20
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +33 -53
- package/dist/middleware/audit-message.d.ts +1 -0
- package/dist/middleware/audit-message.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/rate-limit.d.ts +1 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/models/ai-config.d.ts +1 -0
- package/dist/models/ai-config.d.ts.map +1 -0
- package/dist/models/anthropic-provider.d.ts +1 -0
- package/dist/models/anthropic-provider.d.ts.map +1 -0
- package/dist/models/deepseek-provider.d.ts +1 -0
- package/dist/models/deepseek-provider.d.ts.map +1 -0
- package/dist/models/google-provider.d.ts +1 -0
- package/dist/models/google-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.d.ts +20 -0
- package/dist/models/groq-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.js +31 -0
- package/dist/models/manager.d.ts +1 -0
- package/dist/models/manager.d.ts.map +1 -0
- package/dist/models/openai-provider.d.ts +2 -1
- package/dist/models/openai-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.d.ts +31 -22
- package/dist/models/openrouter-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.js +115 -1
- package/dist/models/providers.d.ts +4 -5
- package/dist/models/providers.d.ts.map +1 -0
- package/dist/models/providers.js +7 -3
- package/dist/models/xai-provider.d.ts +1 -0
- package/dist/models/xai-provider.d.ts.map +1 -0
- package/dist/parsing.d.ts +2 -1
- package/dist/parsing.d.ts.map +1 -0
- package/dist/prompts/manager.d.ts +14 -2
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts.d.ts +1 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +17 -11
- package/dist/repl/display-tool-messages.d.ts +4 -0
- package/dist/repl/display-tool-messages.d.ts.map +1 -0
- package/dist/repl/display-tool-messages.js +55 -0
- package/dist/repl/display-tool-use.d.ts +14 -0
- package/dist/repl/display-tool-use.d.ts.map +1 -0
- package/dist/repl/display-tool-use.js +63 -0
- package/dist/repl/get-prompt-header.d.ts +8 -0
- package/dist/repl/get-prompt-header.d.ts.map +1 -0
- package/dist/repl/get-prompt-header.js +38 -0
- package/dist/repl/tool-call-repair.d.ts +4 -0
- package/dist/repl/tool-call-repair.d.ts.map +1 -0
- package/dist/repl/tool-call-repair.js +50 -0
- package/dist/repl-prompt.d.ts +1 -0
- package/dist/repl-prompt.d.ts.map +1 -0
- package/dist/repl.d.ts +8 -4
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +108 -252
- package/dist/terminal/ansi-styles.d.ts +77 -0
- package/dist/terminal/ansi-styles.d.ts.map +1 -0
- package/dist/terminal/ansi-styles.js +215 -0
- package/dist/terminal/checkbox-prompt.d.ts +36 -0
- package/dist/terminal/checkbox-prompt.d.ts.map +1 -0
- package/dist/terminal/checkbox-prompt.js +362 -0
- package/dist/terminal/default-theme.d.ts +6 -0
- package/dist/terminal/default-theme.d.ts.map +1 -0
- package/dist/terminal/default-theme.js +182 -0
- package/dist/terminal/east-asian-width.d.ts +8 -0
- package/dist/terminal/east-asian-width.d.ts.map +1 -0
- package/dist/terminal/east-asian-width.js +409 -0
- package/dist/terminal/editor-prompt.d.ts +10 -0
- package/dist/terminal/editor-prompt.d.ts.map +1 -0
- package/dist/terminal/editor-prompt.js +61 -0
- package/dist/terminal/errors.d.ts +19 -0
- package/dist/terminal/errors.d.ts.map +1 -0
- package/dist/terminal/errors.js +37 -0
- package/dist/terminal/formatting.d.ts +1 -11
- package/dist/terminal/formatting.d.ts.map +1 -0
- package/dist/terminal/formatting.js +4 -20
- package/dist/terminal/highlight/index.d.ts +53 -0
- package/dist/terminal/highlight/index.d.ts.map +1 -0
- package/dist/terminal/highlight/index.js +90 -0
- package/dist/terminal/highlight/theme.d.ts +233 -0
- package/dist/terminal/highlight/theme.d.ts.map +1 -0
- package/dist/terminal/highlight/theme.js +83 -0
- package/dist/terminal/index.d.ts +16 -9
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +42 -126
- package/dist/terminal/input-prompt.d.ts +16 -0
- package/dist/terminal/input-prompt.d.ts.map +1 -0
- package/dist/terminal/input-prompt.js +181 -0
- package/dist/terminal/markdown-utils.d.ts +1 -0
- package/dist/terminal/markdown-utils.d.ts.map +1 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.d.ts.map +1 -0
- package/dist/terminal/markdown.js +17 -12
- package/dist/terminal/search-prompt.d.ts +20 -0
- package/dist/terminal/search-prompt.d.ts.map +1 -0
- package/dist/terminal/search-prompt.js +279 -0
- package/dist/terminal/select-prompt.d.ts +26 -0
- package/dist/terminal/select-prompt.d.ts.map +1 -0
- package/dist/terminal/select-prompt.js +298 -0
- package/dist/terminal/string-width.d.ts +7 -0
- package/dist/terminal/string-width.d.ts.map +1 -0
- package/dist/terminal/string-width.js +61 -0
- package/dist/terminal/strip-ansi.d.ts +2 -0
- package/dist/terminal/strip-ansi.d.ts.map +1 -0
- package/dist/terminal/strip-ansi.js +20 -0
- package/dist/terminal/style.d.ts +191 -0
- package/dist/terminal/style.d.ts.map +1 -0
- package/dist/terminal/style.js +259 -0
- package/dist/terminal/supports-color.d.ts +1 -0
- package/dist/terminal/supports-color.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.d.ts +1 -3
- package/dist/terminal/supports-hyperlinks.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.js +1 -1
- package/dist/terminal/types.d.ts +1 -37
- package/dist/terminal/types.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.d.ts +8 -0
- package/dist/terminal/wrap-ansi.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.js +190 -0
- package/dist/{token-utils.d.ts → tokens/counter.d.ts} +1 -0
- package/dist/tokens/counter.d.ts.map +1 -0
- package/dist/{token-utils.js → tokens/counter.js} +1 -1
- package/dist/tokens/manage-output.d.ts +34 -0
- package/dist/tokens/manage-output.d.ts.map +1 -0
- package/dist/tokens/manage-output.js +44 -0
- package/dist/{token-tracker.d.ts → tokens/tracker.d.ts} +1 -0
- package/dist/tokens/tracker.d.ts.map +1 -0
- package/dist/tool-executor.d.ts +28 -0
- package/dist/tool-executor.d.ts.map +1 -0
- package/dist/tool-executor.js +74 -0
- package/dist/tools/agent.d.ts +3 -2
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +7 -4
- package/dist/tools/bash-utils.d.ts +7 -0
- package/dist/tools/bash-utils.d.ts.map +1 -0
- package/dist/tools/bash-utils.js +212 -0
- package/dist/tools/bash.d.ts +9 -7
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +95 -212
- package/dist/tools/code-interpreter.d.ts +1 -0
- package/dist/tools/code-interpreter.d.ts.map +1 -0
- package/dist/tools/code-interpreter.js +33 -8
- package/dist/tools/delete-file.d.ts +5 -3
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +47 -33
- package/dist/tools/directory-tree.d.ts +10 -1
- package/dist/tools/directory-tree.d.ts.map +1 -0
- package/dist/tools/directory-tree.js +91 -8
- package/dist/tools/dynamic-tool-loader.d.ts +12 -0
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-loader.js +280 -0
- package/dist/tools/dynamic-tool-parser.d.ts +20 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-parser.js +21 -0
- package/dist/tools/edit-file.d.ts +10 -2
- package/dist/tools/edit-file.d.ts.map +1 -0
- package/dist/tools/edit-file.js +117 -40
- package/dist/tools/file-editing-utils.d.ts +2 -0
- package/dist/tools/file-editing-utils.d.ts.map +1 -0
- package/dist/tools/file-editing-utils.js +135 -0
- package/dist/tools/filesystem-utils.d.ts +6 -21
- package/dist/tools/filesystem-utils.d.ts.map +1 -0
- package/dist/tools/filesystem-utils.js +96 -148
- package/dist/tools/git-utils.d.ts +1 -0
- package/dist/tools/git-utils.d.ts.map +1 -0
- package/dist/tools/grep.d.ts +5 -3
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +67 -27
- package/dist/tools/index.d.ts +10 -14
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +33 -22
- package/dist/tools/move-file.d.ts +1 -0
- package/dist/tools/move-file.d.ts.map +1 -0
- package/dist/tools/move-file.js +12 -5
- package/dist/tools/read-file.d.ts +2 -1
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +13 -6
- package/dist/tools/read-multiple-files.d.ts +2 -1
- package/dist/tools/read-multiple-files.d.ts.map +1 -0
- package/dist/tools/read-multiple-files.js +90 -9
- package/dist/tools/save-file.d.ts +5 -3
- package/dist/tools/save-file.d.ts.map +1 -0
- package/dist/tools/save-file.js +64 -36
- package/dist/tools/think.d.ts +1 -0
- package/dist/tools/think.d.ts.map +1 -0
- package/dist/tools/think.js +5 -1
- package/dist/tools/types.d.ts +14 -1
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/web-fetch.d.ts +4 -2
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +2 -2
- package/dist/tools/web-search.d.ts +2 -1
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +46 -11
- package/dist/utils/filesystem.d.ts +23 -0
- package/dist/utils/filesystem.d.ts.map +1 -0
- package/dist/utils/filesystem.js +140 -0
- package/dist/utils/filetype-detection.d.ts +3 -0
- package/dist/utils/filetype-detection.d.ts.map +1 -0
- package/dist/utils/filetype-detection.js +112 -0
- package/dist/utils/glob.d.ts +52 -0
- package/dist/utils/glob.d.ts.map +1 -0
- package/dist/utils/glob.js +376 -0
- package/dist/utils/ignore.d.ts +104 -0
- package/dist/utils/ignore.d.ts.map +1 -0
- package/dist/utils/ignore.js +649 -0
- package/dist/utils/process.d.ts +10 -1
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +104 -5
- package/dist/utils/zod-utils.d.ts +4 -0
- package/dist/utils/zod-utils.d.ts.map +1 -0
- package/dist/utils/zod-utils.js +7 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +32 -30
- package/dist/tools/command-validation.d.ts +0 -12
- package/dist/tools/command-validation.js +0 -113
- /package/dist/{token-tracker.js → tokens/tracker.js} +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { ansiStyles } from "./ansi-styles.js";
|
|
2
|
+
import stringWidth from "./string-width.js";
|
|
3
|
+
import stripAnsi from "./strip-ansi.js";
|
|
4
|
+
const ESCAPES = new Set(["\\u001B", "\\u009B"]);
|
|
5
|
+
const END_CODE = 39;
|
|
6
|
+
const ANSI_ESCAPE_BELL = "\\u0007";
|
|
7
|
+
const ANSI_CSI = "[";
|
|
8
|
+
const ANSI_OSC = "]";
|
|
9
|
+
const ANSI_SGR_TERMINATOR = "m";
|
|
10
|
+
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
|
|
11
|
+
const wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
|
|
12
|
+
const wrapAnsiHyperlink = (url) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
|
|
13
|
+
// Calculate the length of words split on ' ', ignoring
|
|
14
|
+
// the extra characters added by ansi escape codes
|
|
15
|
+
const wordLengths = (string) => string.split(" ").map((character) => stringWidth(character));
|
|
16
|
+
// Wrap a long word across multiple rows
|
|
17
|
+
// Ansi escape codes do not count towards length
|
|
18
|
+
const wrapWord = (rows, word, columns) => {
|
|
19
|
+
const characters = [...word];
|
|
20
|
+
let isInsideEscape = false;
|
|
21
|
+
let isInsideLinkEscape = false;
|
|
22
|
+
let visible = stringWidth(stripAnsi(rows.at(-1) ?? ""));
|
|
23
|
+
for (const [index, character] of characters.entries()) {
|
|
24
|
+
const characterLength = stringWidth(character);
|
|
25
|
+
if (visible + characterLength <= columns) {
|
|
26
|
+
rows[rows.length - 1] += character;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
rows.push(character);
|
|
30
|
+
visible = 0;
|
|
31
|
+
}
|
|
32
|
+
if (ESCAPES.has(character)) {
|
|
33
|
+
isInsideEscape = true;
|
|
34
|
+
const ansiEscapeLinkCandidate = characters
|
|
35
|
+
.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length)
|
|
36
|
+
.join("");
|
|
37
|
+
isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
|
|
38
|
+
}
|
|
39
|
+
if (isInsideEscape) {
|
|
40
|
+
if (isInsideLinkEscape) {
|
|
41
|
+
if (character === ANSI_ESCAPE_BELL) {
|
|
42
|
+
isInsideEscape = false;
|
|
43
|
+
isInsideLinkEscape = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (character === ANSI_SGR_TERMINATOR) {
|
|
47
|
+
isInsideEscape = false;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
visible += characterLength;
|
|
52
|
+
if (visible === columns && index < characters.length - 1) {
|
|
53
|
+
rows.push("");
|
|
54
|
+
visible = 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// It's possible that the last row we copy over is only
|
|
58
|
+
// ansi escape characters, handle this edge-case
|
|
59
|
+
const lastRow = rows.at(-1);
|
|
60
|
+
if (!visible && lastRow && lastRow.length > 0 && rows.length > 1) {
|
|
61
|
+
const poppedRow = rows.pop();
|
|
62
|
+
if (poppedRow) {
|
|
63
|
+
rows[rows.length - 1] += poppedRow;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// Trims spaces from a string ignoring invisible sequences
|
|
68
|
+
const stringVisibleTrimSpacesRight = (string) => {
|
|
69
|
+
const words = string.split(" ");
|
|
70
|
+
let last = words.length;
|
|
71
|
+
while (last > 0) {
|
|
72
|
+
if (stringWidth(words[last - 1]) > 0) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
last--;
|
|
76
|
+
}
|
|
77
|
+
if (last === words.length) {
|
|
78
|
+
return string;
|
|
79
|
+
}
|
|
80
|
+
return words.slice(0, last).join(" ") + words.slice(last).join("");
|
|
81
|
+
};
|
|
82
|
+
// The wrap-ansi module can be invoked in either 'hard' or 'soft' wrap mode.
|
|
83
|
+
//
|
|
84
|
+
// 'hard' will never allow a string to take up more than columns characters.
|
|
85
|
+
//
|
|
86
|
+
// 'soft' allows long words to expand past the column length.
|
|
87
|
+
const exec = (string, columns, options = {}) => {
|
|
88
|
+
if (options.trim !== false && string.trim() === "") {
|
|
89
|
+
return "";
|
|
90
|
+
}
|
|
91
|
+
let returnValue = "";
|
|
92
|
+
let escapeCode;
|
|
93
|
+
let escapeUrl;
|
|
94
|
+
const lengths = wordLengths(string);
|
|
95
|
+
let rows = [""];
|
|
96
|
+
for (const [index, word] of string.split(" ").entries()) {
|
|
97
|
+
if (options.trim !== false) {
|
|
98
|
+
rows[rows.length - 1] = rows.at(-1)?.trimStart() ?? "";
|
|
99
|
+
}
|
|
100
|
+
let rowLength = stringWidth(rows.at(-1) ?? "");
|
|
101
|
+
if (index !== 0) {
|
|
102
|
+
if (rowLength >= columns &&
|
|
103
|
+
(options.wordWrap === false || options.trim === false)) {
|
|
104
|
+
// If we start with a new word but the current row length equals the length of the columns, add a new row
|
|
105
|
+
rows.push("");
|
|
106
|
+
rowLength = 0;
|
|
107
|
+
}
|
|
108
|
+
if (rowLength > 0 || options.trim === false) {
|
|
109
|
+
rows[rows.length - 1] += " ";
|
|
110
|
+
rowLength++;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// In 'hard' wrap mode, the length of a line is never allowed to extend past 'columns'
|
|
114
|
+
if (options.hard && lengths[index] > columns) {
|
|
115
|
+
const remainingColumns = columns - rowLength;
|
|
116
|
+
const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
|
|
117
|
+
const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
|
|
118
|
+
if (breaksStartingNextLine < breaksStartingThisLine) {
|
|
119
|
+
rows.push("");
|
|
120
|
+
}
|
|
121
|
+
wrapWord(rows, word, columns);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (rowLength + lengths[index] > columns &&
|
|
125
|
+
rowLength > 0 &&
|
|
126
|
+
lengths[index] > 0) {
|
|
127
|
+
if (options.wordWrap === false && rowLength < columns) {
|
|
128
|
+
wrapWord(rows, word, columns);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
rows.push("");
|
|
132
|
+
}
|
|
133
|
+
if (rowLength + lengths[index] > columns && options.wordWrap === false) {
|
|
134
|
+
wrapWord(rows, word, columns);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
rows[rows.length - 1] += word;
|
|
138
|
+
}
|
|
139
|
+
if (options.trim !== false) {
|
|
140
|
+
rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
|
|
141
|
+
}
|
|
142
|
+
const preString = rows.join("\n");
|
|
143
|
+
const pre = [...preString];
|
|
144
|
+
// We need to keep a separate index as `String#slice()` works on Unicode code units, while `pre` is an array of codepoints.
|
|
145
|
+
let preStringIndex = 0;
|
|
146
|
+
for (const [index, character] of pre.entries()) {
|
|
147
|
+
returnValue += character;
|
|
148
|
+
if (ESCAPES.has(character)) {
|
|
149
|
+
const match = new RegExp(`(?:\\\\${ANSI_CSI}(?<code>\\d+)m|\\\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`).exec(preString.slice(preStringIndex));
|
|
150
|
+
if (match?.groups) {
|
|
151
|
+
const { groups } = match;
|
|
152
|
+
if (groups["code"] !== undefined) {
|
|
153
|
+
const code = Number.parseFloat(groups["code"]);
|
|
154
|
+
escapeCode = code === END_CODE ? undefined : code;
|
|
155
|
+
}
|
|
156
|
+
else if (groups["uri"] !== undefined) {
|
|
157
|
+
escapeUrl = groups["uri"].length === 0 ? undefined : groups["uri"];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const code = ansiStyles["codes"].get(Number(escapeCode));
|
|
162
|
+
if (pre[index + 1] === "\n") {
|
|
163
|
+
if (escapeUrl) {
|
|
164
|
+
returnValue += wrapAnsiHyperlink("");
|
|
165
|
+
}
|
|
166
|
+
if (escapeCode && code) {
|
|
167
|
+
returnValue += wrapAnsiCode(code);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (character === "\n") {
|
|
171
|
+
if (escapeCode && code) {
|
|
172
|
+
returnValue += wrapAnsiCode(escapeCode);
|
|
173
|
+
}
|
|
174
|
+
if (escapeUrl) {
|
|
175
|
+
returnValue += wrapAnsiHyperlink(escapeUrl);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
preStringIndex += character.length;
|
|
179
|
+
}
|
|
180
|
+
return returnValue;
|
|
181
|
+
};
|
|
182
|
+
// For each newline, invoke the method separately
|
|
183
|
+
export default function wrapAnsi(string, columns, options) {
|
|
184
|
+
return String(string)
|
|
185
|
+
.normalize()
|
|
186
|
+
.replaceAll("\r\n", "\n")
|
|
187
|
+
.split("\n")
|
|
188
|
+
.map((line) => exec(line, columns, options))
|
|
189
|
+
.join("\n");
|
|
190
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../../source/tokens/counter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAElE,qBAAa,YAAY;IACvB,OAAO,CAAC,gBAAgB,CAAwC;gBAEpD,KAAK,GAAE,aAAmC;IAItD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI5B,IAAI;CAGL"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TokenCounter } from "./counter.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Interface for options when managing output
|
|
4
|
+
*/
|
|
5
|
+
interface ManageOutputOptions {
|
|
6
|
+
tokenCounter: TokenCounter;
|
|
7
|
+
threshold?: number;
|
|
8
|
+
truncate?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface for the result of managing output
|
|
12
|
+
*/
|
|
13
|
+
interface TruncatedOutput {
|
|
14
|
+
content: string;
|
|
15
|
+
tokenCount: number;
|
|
16
|
+
truncated: true;
|
|
17
|
+
warning: string;
|
|
18
|
+
}
|
|
19
|
+
interface Output {
|
|
20
|
+
content: string;
|
|
21
|
+
tokenCount: number;
|
|
22
|
+
truncated: false;
|
|
23
|
+
warning?: string;
|
|
24
|
+
}
|
|
25
|
+
type ManagedOutput = Output | TruncatedOutput;
|
|
26
|
+
/**
|
|
27
|
+
* Manages output by counting tokens and optionally truncating if over threshold.
|
|
28
|
+
* @param input - The input string to manage
|
|
29
|
+
* @param options - Configuration for management
|
|
30
|
+
* @returns Managed output details
|
|
31
|
+
*/
|
|
32
|
+
export declare function manageOutput(input: string, options: ManageOutputOptions): ManagedOutput;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=manage-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manage-output.d.ts","sourceRoot":"","sources":["../../source/tokens/manage-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;GAEG;AACH,UAAU,mBAAmB;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,aAAa,GAAG,MAAM,GAAG,eAAe,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,mBAAmB,GAC3B,aAAa,CA2Cf"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages output by counting tokens and optionally truncating if over threshold.
|
|
3
|
+
* @param input - The input string to manage
|
|
4
|
+
* @param options - Configuration for management
|
|
5
|
+
* @returns Managed output details
|
|
6
|
+
*/
|
|
7
|
+
export function manageOutput(input, options) {
|
|
8
|
+
const { threshold = 8000, truncate = true } = options;
|
|
9
|
+
if (!input) {
|
|
10
|
+
return { content: input, tokenCount: 0, truncated: false };
|
|
11
|
+
}
|
|
12
|
+
let tokenCount;
|
|
13
|
+
try {
|
|
14
|
+
tokenCount = options.tokenCounter.count(input);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.warn(`Token counting failed: ${error}. Using fallback.`);
|
|
18
|
+
// Fallback: Rough estimate (4 chars ~1 token)
|
|
19
|
+
tokenCount = Math.ceil(input.length / 4);
|
|
20
|
+
}
|
|
21
|
+
if (tokenCount <= threshold) {
|
|
22
|
+
return { content: input, tokenCount, truncated: false };
|
|
23
|
+
}
|
|
24
|
+
const _exceededBy = tokenCount - threshold;
|
|
25
|
+
let truncatedContent = input;
|
|
26
|
+
let truncated = false;
|
|
27
|
+
if (truncate) {
|
|
28
|
+
// Simple truncation: Cut to approx threshold tokens, add ellipsis
|
|
29
|
+
// For better UX, could be smarter (e.g., by lines for grep, preserve JSON)
|
|
30
|
+
// But keep general for now
|
|
31
|
+
const targetLength = threshold * 4; // Rough char estimate
|
|
32
|
+
truncatedContent = `${input.slice(0, targetLength)}\n\n[Output truncated at ~${threshold} tokens (${_exceededBy} tokens omitted)]`;
|
|
33
|
+
truncated = true;
|
|
34
|
+
}
|
|
35
|
+
const warning = truncated
|
|
36
|
+
? `Warning: Output exceeds token threshold (${threshold}). Tokens: ${tokenCount}. ${truncate ? "Truncated." : "Full output returned—consider summarizing."}`
|
|
37
|
+
: undefined;
|
|
38
|
+
return {
|
|
39
|
+
content: truncatedContent,
|
|
40
|
+
tokenCount,
|
|
41
|
+
truncated,
|
|
42
|
+
warning,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../source/tokens/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAC;AAO7C,UAAU,kBAAkB;IAC1B,KAAK,EAAE,CAAC,kBAAkB,CAAC,CAAC;CAC7B;AAED,qBAAa,YAAa,SAAQ,YAAY,CAAC,kBAAkB,CAAC;IAChE,OAAO,CAAC,MAAM,CAAoB;IAElC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,SAAS;IAQ9D,aAAa,IAAI,kBAAkB;IAcnC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB;IAoB9C,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAY3C,YAAY;CAOb"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface AskContext {
|
|
2
|
+
toolName: string;
|
|
3
|
+
toolCallId: string;
|
|
4
|
+
message: string;
|
|
5
|
+
choices: {
|
|
6
|
+
accept: string;
|
|
7
|
+
acceptAll: string;
|
|
8
|
+
reject: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export type AskResponse = {
|
|
12
|
+
result: "accept" | "accept-all";
|
|
13
|
+
reason?: string;
|
|
14
|
+
} | {
|
|
15
|
+
result: "reject";
|
|
16
|
+
reason: string;
|
|
17
|
+
};
|
|
18
|
+
export declare class ToolExecutor {
|
|
19
|
+
private autoAcceptAll;
|
|
20
|
+
private autoAcceptMap;
|
|
21
|
+
constructor(autoAcceptAll: boolean);
|
|
22
|
+
autoAccept(toolName: string): boolean;
|
|
23
|
+
ask(ctx: AskContext, { abortSignal }: {
|
|
24
|
+
abortSignal?: AbortSignal;
|
|
25
|
+
}): Promise<AskResponse>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=tool-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-executor.d.ts","sourceRoot":"","sources":["../source/tool-executor.ts"],"names":[],"mappings":"AAIA,UAAU,UAAU;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,MAAM,EAAE,QAAQ,GAAG,YAAY,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,aAAa,CAA8B;gBAEvC,aAAa,EAAE,OAAO;IAIlC,UAAU,CAAC,QAAQ,EAAE,MAAM;IAIrB,GAAG,CACP,GAAG,EAAE,UAAU,EACf,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE,GAC7C,OAAO,CAAC,WAAW,CAAC;CAgExB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { input } from "./terminal/input-prompt.js";
|
|
2
|
+
import { select } from "./terminal/select-prompt.js";
|
|
3
|
+
import style from "./terminal/style.js";
|
|
4
|
+
export class ToolExecutor {
|
|
5
|
+
autoAcceptAll;
|
|
6
|
+
autoAcceptMap = new Map();
|
|
7
|
+
constructor(autoAcceptAll) {
|
|
8
|
+
this.autoAcceptAll = autoAcceptAll;
|
|
9
|
+
}
|
|
10
|
+
autoAccept(toolName) {
|
|
11
|
+
return !!this.autoAcceptMap.get(toolName);
|
|
12
|
+
}
|
|
13
|
+
async ask(ctx, { abortSignal }) {
|
|
14
|
+
if (this.autoAcceptAll) {
|
|
15
|
+
return {
|
|
16
|
+
result: "accept-all",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (this.autoAcceptMap.has(ctx.toolName)) {
|
|
20
|
+
if (this.autoAcceptMap.get(ctx.toolName) === true) {
|
|
21
|
+
return {
|
|
22
|
+
result: "accept-all",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let userChoice;
|
|
27
|
+
try {
|
|
28
|
+
userChoice = await select({
|
|
29
|
+
message: `${style.blue.bold("●")} ${ctx.message}`,
|
|
30
|
+
choices: [
|
|
31
|
+
{ name: ctx.choices.accept, value: "accept" },
|
|
32
|
+
{
|
|
33
|
+
name: ctx.choices.acceptAll,
|
|
34
|
+
value: "accept-all",
|
|
35
|
+
},
|
|
36
|
+
{ name: ctx.choices.reject, value: "reject" },
|
|
37
|
+
],
|
|
38
|
+
initial: 0,
|
|
39
|
+
signal: abortSignal,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
if (e.name === "AbortError") {
|
|
44
|
+
throw new Error("Operation aborted during user input");
|
|
45
|
+
}
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
if (userChoice === "reject") {
|
|
49
|
+
let reason;
|
|
50
|
+
try {
|
|
51
|
+
reason = await input({
|
|
52
|
+
message: `${style.yellowBright.bold("●")} Feedback`,
|
|
53
|
+
signal: abortSignal,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (e.name === "AbortError") {
|
|
58
|
+
throw new Error("Operation aborted during user input");
|
|
59
|
+
}
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
result: userChoice,
|
|
64
|
+
reason,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (userChoice === "accept-all") {
|
|
68
|
+
this.autoAcceptMap.set(ctx.toolName, true);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
result: userChoice,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/tools/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ModelManager } from "../models/manager.ts";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { TokenCounter } from "../tokens/counter.ts";
|
|
3
|
+
import type { TokenTracker } from "../tokens/tracker.ts";
|
|
4
4
|
import type { SendData } from "./types.ts";
|
|
5
5
|
export declare const AgentTool: {
|
|
6
6
|
name: "agent";
|
|
@@ -15,3 +15,4 @@ export declare const createAgentTools: (options: {
|
|
|
15
15
|
prompt: string;
|
|
16
16
|
}, string>;
|
|
17
17
|
};
|
|
18
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../source/tools/agent.ts"],"names":[],"mappings":"AAGA,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,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,SAAS;;CAErB,CAAC;AA+BF,eAAO,MAAM,gBAAgB,GAAI,SAAS;IACxC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CACjC;;;;CAyDA,CAAC"}
|
package/dist/tools/agent.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { generateText, stepCountIs, tool } from "ai";
|
|
2
|
-
import chalk from "chalk";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
import { AiConfig } from "../models/ai-config.js";
|
|
4
|
+
import style from "../terminal/style.js";
|
|
5
5
|
import { BashTool } from "./bash.js";
|
|
6
|
-
import { DirectoryTreeTool } from "./directory-tree.
|
|
6
|
+
// import { DirectoryTreeTool } from "./directory-tree.ts";
|
|
7
7
|
import { GrepTool } from "./grep.js";
|
|
8
8
|
import { initCliTools } from "./index.js";
|
|
9
9
|
import { ReadFileTool } from "./read-file.js";
|
|
@@ -16,7 +16,7 @@ const TOOLS = [
|
|
|
16
16
|
BashTool.name,
|
|
17
17
|
ReadFileTool.name,
|
|
18
18
|
ReadMultipleFilesTool.name,
|
|
19
|
-
DirectoryTreeTool.name,
|
|
19
|
+
// DirectoryTreeTool.name,
|
|
20
20
|
];
|
|
21
21
|
function getToolDescription() {
|
|
22
22
|
const toolNames = TOOLS.join(", ");
|
|
@@ -42,10 +42,13 @@ export const createAgentTools = (options) => {
|
|
|
42
42
|
description: getToolDescription(),
|
|
43
43
|
inputSchema: inputSchema,
|
|
44
44
|
execute: async ({ prompt }, { abortSignal, toolCallId }) => {
|
|
45
|
+
if (abortSignal?.aborted) {
|
|
46
|
+
throw new Error("Agent execution aborted");
|
|
47
|
+
}
|
|
45
48
|
sendData?.({
|
|
46
49
|
event: "tool-init",
|
|
47
50
|
id: toolCallId,
|
|
48
|
-
data: `Initializing agent with prompt: ${
|
|
51
|
+
data: `Initializing agent with prompt: ${style.cyan(prompt)}`,
|
|
49
52
|
});
|
|
50
53
|
try {
|
|
51
54
|
const modelConfig = modelManager.getModelMetadata("task-agent");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function validatePaths(command: string, baseDir: string, cwd: string): {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
error?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const resolveCwd: (cwdInput: string | null | undefined, workingDir: string) => string;
|
|
6
|
+
export declare const isMutatingCommand: (rawCommand: string) => boolean;
|
|
7
|
+
//# sourceMappingURL=bash-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash-utils.d.ts","sourceRoot":"","sources":["../../source/tools/bash-utils.ts"],"names":[],"mappings":"AAKA,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAiEtC;AAED,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,YAAY,MAAM,KACjB,MAiDF,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,KAAG,OAmHtD,CAAC"}
|