@travisennis/acai 0.0.5 → 0.0.6
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 +4 -2
- package/dist/agent/index.d.ts +119 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +406 -0
- package/dist/agent/manual-loop.d.ts +41 -0
- package/dist/agent/manual-loop.d.ts.map +1 -0
- package/dist/agent/manual-loop.js +278 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +27 -33
- package/dist/commands/add-directory-command.d.ts +3 -0
- package/dist/commands/add-directory-command.d.ts.map +1 -0
- package/dist/commands/add-directory-command.js +85 -0
- package/dist/commands/application-log-command.d.ts.map +1 -1
- package/dist/commands/application-log-command.js +34 -0
- package/dist/commands/clear-command.d.ts.map +1 -1
- package/dist/commands/clear-command.js +8 -0
- package/dist/commands/compact-command.d.ts.map +1 -1
- package/dist/commands/compact-command.js +15 -2
- package/dist/commands/context-command.d.ts +3 -0
- package/dist/commands/context-command.d.ts.map +1 -0
- package/dist/commands/context-command.js +183 -0
- package/dist/commands/copy-command.d.ts.map +1 -1
- package/dist/commands/copy-command.js +28 -0
- package/dist/commands/edit-command.d.ts.map +1 -1
- package/dist/commands/edit-command.js +33 -0
- package/dist/commands/edit-prompt-command.d.ts.map +1 -1
- package/dist/commands/edit-prompt-command.js +28 -0
- package/dist/commands/exit-command.d.ts.map +1 -1
- package/dist/commands/exit-command.js +20 -0
- package/dist/commands/files-command.d.ts.map +1 -1
- package/dist/commands/files-command.js +57 -0
- package/dist/commands/generate-rules-command.d.ts.map +1 -1
- package/dist/commands/generate-rules-command.js +311 -1
- package/dist/commands/handoff-command.d.ts +3 -0
- package/dist/commands/handoff-command.d.ts.map +1 -0
- package/dist/commands/handoff-command.js +202 -0
- package/dist/commands/health-command.d.ts.map +1 -1
- package/dist/commands/health-command.js +119 -2
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +28 -0
- package/dist/commands/history-command.d.ts +3 -0
- package/dist/commands/history-command.d.ts.map +1 -0
- package/dist/commands/history-command.js +534 -0
- 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 +55 -18
- package/dist/commands/last-log-command.d.ts.map +1 -1
- package/dist/commands/last-log-command.js +27 -0
- package/dist/commands/list-directories-command.d.ts +3 -0
- package/dist/commands/list-directories-command.d.ts.map +1 -0
- package/dist/commands/list-directories-command.js +48 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -1
- package/dist/commands/list-tools-command.js +66 -3
- package/dist/commands/manager.d.ts +15 -3
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +86 -26
- package/dist/commands/model-command.d.ts +22 -0
- package/dist/commands/model-command.d.ts.map +1 -1
- package/dist/commands/model-command.js +256 -0
- package/dist/commands/paste-command.d.ts.map +1 -1
- package/dist/commands/paste-command.js +92 -0
- package/dist/commands/pickup-command.d.ts +3 -0
- package/dist/commands/pickup-command.d.ts.map +1 -0
- package/dist/commands/pickup-command.js +161 -0
- package/dist/commands/prompt-command.d.ts +1 -1
- package/dist/commands/prompt-command.d.ts.map +1 -1
- package/dist/commands/prompt-command.js +117 -2
- package/dist/commands/remove-directory-command.d.ts +3 -0
- package/dist/commands/remove-directory-command.d.ts.map +1 -0
- package/dist/commands/remove-directory-command.js +87 -0
- 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 +13 -2
- package/dist/commands/rules-command.d.ts.map +1 -1
- package/dist/commands/rules-command.js +65 -0
- package/dist/commands/save-command.d.ts.map +1 -1
- package/dist/commands/save-command.js +12 -0
- package/dist/commands/shell-command.d.ts.map +1 -1
- package/dist/commands/shell-command.js +68 -0
- package/dist/commands/types.d.ts +9 -4
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/usage-command.d.ts.map +1 -1
- package/dist/commands/usage-command.js +22 -0
- package/dist/config.d.ts +6 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -29
- package/dist/formatting.d.ts +108 -0
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +147 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +140 -38
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +47 -18
- package/dist/mentions.d.ts +2 -1
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +16 -1
- package/dist/messages.d.ts +8 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +56 -19
- package/dist/middleware/cache.d.ts +3 -0
- package/dist/middleware/cache.d.ts.map +1 -0
- package/dist/middleware/cache.js +53 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +1 -0
- package/dist/models/ai-config.d.ts +4 -2
- package/dist/models/ai-config.d.ts.map +1 -1
- package/dist/models/ai-config.js +12 -2
- package/dist/models/anthropic-provider.d.ts.map +1 -1
- package/dist/models/anthropic-provider.js +3 -60
- package/dist/models/manager.d.ts +2 -1
- package/dist/models/manager.d.ts.map +1 -1
- package/dist/models/manager.js +26 -2
- package/dist/models/openrouter-provider.d.ts +7 -14
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +114 -169
- package/dist/models/providers.d.ts +1 -1
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/prompts.d.ts +1 -0
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +53 -4
- package/dist/repl/display-tool-messages.d.ts +1 -1
- package/dist/repl/display-tool-messages.d.ts.map +1 -1
- package/dist/repl/display-tool-messages.js +47 -44
- package/dist/repl/get-prompt-header.d.ts.map +1 -1
- package/dist/repl/get-prompt-header.js +1 -30
- package/dist/repl/project-status-line.d.ts +2 -0
- package/dist/repl/project-status-line.d.ts.map +1 -0
- package/dist/repl/project-status-line.js +31 -0
- package/dist/repl/prompt.d.ts +21 -0
- package/dist/repl/prompt.d.ts.map +1 -0
- package/dist/{repl-prompt.js → repl/prompt.js} +119 -22
- package/dist/repl/tool-call-repair.d.ts.map +1 -1
- package/dist/repl/tool-call-repair.js +8 -4
- package/dist/repl-new.d.ts +53 -0
- package/dist/repl-new.d.ts.map +1 -0
- package/dist/repl-new.js +374 -0
- package/dist/repl.d.ts +3 -5
- package/dist/repl.d.ts.map +1 -1
- package/dist/repl.js +74 -166
- package/dist/terminal/checkbox-prompt.d.ts.map +1 -1
- package/dist/terminal/checkbox-prompt.js +10 -4
- package/dist/terminal/index.d.ts +7 -0
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/index.js +94 -0
- package/dist/terminal/input-prompt.d.ts +2 -1
- package/dist/terminal/input-prompt.d.ts.map +1 -1
- package/dist/terminal/markdown.js +3 -0
- package/dist/terminal/search-prompt.d.ts.map +1 -1
- package/dist/terminal/search-prompt.js +11 -10
- package/dist/terminal/select-prompt.d.ts +2 -2
- package/dist/terminal/select-prompt.d.ts.map +1 -1
- package/dist/terminal/select-prompt.js +47 -39
- package/dist/tokens/threshold.d.ts +35 -0
- package/dist/tokens/threshold.d.ts.map +1 -0
- package/dist/tokens/threshold.js +85 -0
- package/dist/tools/advanced-edit-file.d.ts +69 -0
- package/dist/tools/advanced-edit-file.d.ts.map +1 -0
- package/dist/tools/advanced-edit-file.js +281 -0
- package/dist/tools/agent.d.ts +16 -5
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/agent.js +71 -58
- package/dist/tools/bash-utils.d.ts +1 -1
- package/dist/tools/bash-utils.d.ts.map +1 -1
- package/dist/tools/bash-utils.js +14 -6
- package/dist/tools/bash.d.ts +21 -12
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +88 -135
- package/dist/tools/code-interpreter.d.ts +21 -9
- package/dist/tools/code-interpreter.d.ts.map +1 -1
- package/dist/tools/code-interpreter.js +138 -137
- package/dist/tools/delete-file.d.ts +17 -10
- package/dist/tools/delete-file.d.ts.map +1 -1
- package/dist/tools/delete-file.js +51 -95
- package/dist/tools/directory-tree.d.ts +17 -6
- package/dist/tools/directory-tree.d.ts.map +1 -1
- package/dist/tools/directory-tree.js +47 -49
- package/dist/tools/dynamic-tool-loader.d.ts +18 -8
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +121 -129
- package/dist/tools/dynamic-tool-parser.d.ts +1 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-parser.js +1 -0
- package/dist/tools/edit-file.d.ts +35 -15
- package/dist/tools/edit-file.d.ts.map +1 -1
- package/dist/tools/edit-file.js +112 -112
- package/dist/tools/filesystem-utils.d.ts +2 -1
- package/dist/tools/filesystem-utils.d.ts.map +1 -1
- package/dist/tools/filesystem-utils.js +31 -17
- package/dist/tools/glob.d.ts +36 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +143 -0
- package/dist/tools/grep.d.ts +73 -12
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +413 -168
- package/dist/tools/index.d.ts +204 -124
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +242 -135
- package/dist/tools/llm-edit-fixer.d.ts +25 -0
- package/dist/tools/llm-edit-fixer.d.ts.map +1 -0
- package/dist/tools/llm-edit-fixer.js +150 -0
- package/dist/tools/move-file.d.ts +19 -7
- package/dist/tools/move-file.d.ts.map +1 -1
- package/dist/tools/move-file.js +40 -33
- package/dist/tools/read-file.d.ts +47 -9
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +74 -69
- package/dist/tools/read-multiple-files.d.ts +17 -6
- package/dist/tools/read-multiple-files.d.ts.map +1 -1
- package/dist/tools/read-multiple-files.js +76 -73
- package/dist/tools/save-file.d.ts +45 -12
- package/dist/tools/save-file.d.ts.map +1 -1
- package/dist/tools/save-file.js +58 -101
- package/dist/tools/think.d.ts +15 -7
- package/dist/tools/think.d.ts.map +1 -1
- package/dist/tools/think.js +30 -22
- package/dist/tools/types.d.ts +4 -10
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js +9 -0
- package/dist/tools/utils.d.ts +14 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +16 -0
- package/dist/tools/web-fetch.d.ts +11 -4
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +39 -38
- package/dist/tools/web-search.d.ts +15 -6
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +50 -32
- package/dist/tui/autocomplete.d.ts +44 -0
- package/dist/tui/autocomplete.d.ts.map +1 -0
- package/dist/tui/autocomplete.js +466 -0
- package/dist/tui/components/assistant-message.d.ts +18 -0
- package/dist/tui/components/assistant-message.d.ts.map +1 -0
- package/dist/tui/components/assistant-message.js +29 -0
- package/dist/tui/components/editor.d.ts +51 -0
- package/dist/tui/components/editor.d.ts.map +1 -0
- package/dist/tui/components/editor.js +758 -0
- package/dist/tui/components/footer.d.ts +24 -0
- package/dist/tui/components/footer.d.ts.map +1 -0
- package/dist/tui/components/footer.js +197 -0
- package/dist/tui/components/input.d.ts +14 -0
- package/dist/tui/components/input.d.ts.map +1 -0
- package/dist/tui/components/input.js +122 -0
- package/dist/tui/components/loader.d.ts +19 -0
- package/dist/tui/components/loader.d.ts.map +1 -0
- package/dist/tui/components/loader.js +45 -0
- package/dist/tui/components/markdown.d.ts +103 -0
- package/dist/tui/components/markdown.d.ts.map +1 -0
- package/dist/tui/components/markdown.js +533 -0
- package/dist/tui/components/modal.d.ts +40 -0
- package/dist/tui/components/modal.d.ts.map +1 -0
- package/dist/tui/components/modal.js +292 -0
- package/dist/tui/components/prompt-status.d.ts +16 -0
- package/dist/tui/components/prompt-status.d.ts.map +1 -0
- package/dist/tui/components/prompt-status.js +21 -0
- package/dist/tui/components/select-list.d.ts +22 -0
- package/dist/tui/components/select-list.d.ts.map +1 -0
- package/dist/tui/components/select-list.js +143 -0
- package/dist/tui/components/spacer.d.ts +16 -0
- package/dist/tui/components/spacer.d.ts.map +1 -0
- package/dist/tui/components/spacer.js +27 -0
- package/dist/tui/components/text.d.ts +26 -0
- package/dist/tui/components/text.d.ts.map +1 -0
- package/dist/tui/components/text.js +143 -0
- package/dist/tui/components/thinking-block.d.ts +14 -0
- package/dist/tui/components/thinking-block.d.ts.map +1 -0
- package/dist/tui/components/thinking-block.js +30 -0
- package/dist/tui/components/tool-execution.d.ts +17 -0
- package/dist/tui/components/tool-execution.d.ts.map +1 -0
- package/dist/tui/components/tool-execution.js +153 -0
- package/dist/tui/components/user-message.d.ts +9 -0
- package/dist/tui/components/user-message.d.ts.map +1 -0
- package/dist/tui/components/user-message.js +21 -0
- package/dist/tui/components/welcome.d.ts +6 -0
- package/dist/tui/components/welcome.d.ts.map +1 -0
- package/dist/tui/components/welcome.js +30 -0
- package/dist/tui/index.d.ts +14 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +18 -0
- package/dist/tui/terminal.d.ts +37 -0
- package/dist/tui/terminal.d.ts.map +1 -0
- package/dist/tui/terminal.js +104 -0
- package/dist/tui/tui.d.ts +67 -0
- package/dist/tui/tui.d.ts.map +1 -0
- package/dist/tui/tui.js +184 -0
- package/dist/tui/utils.d.ts +19 -0
- package/dist/tui/utils.d.ts.map +1 -0
- package/dist/tui/utils.js +31 -0
- package/dist/utils/generators.d.ts +3 -0
- package/dist/utils/generators.d.ts.map +1 -0
- package/dist/utils/generators.js +25 -0
- package/dist/utils/iterables.d.ts +2 -0
- package/dist/utils/iterables.d.ts.map +1 -0
- package/dist/utils/iterables.js +6 -0
- package/package.json +16 -16
- package/dist/conversation-analyzer.d.ts +0 -11
- package/dist/conversation-analyzer.d.ts.map +0 -1
- package/dist/conversation-analyzer.js +0 -88
- package/dist/repl-prompt.d.ts +0 -15
- package/dist/repl-prompt.d.ts.map +0 -1
- package/dist/tokens/manage-output.d.ts +0 -34
- package/dist/tokens/manage-output.d.ts.map +0 -1
- package/dist/tokens/manage-output.js +0 -44
- package/dist/tool-executor.d.ts +0 -28
- package/dist/tool-executor.d.ts.map +0 -1
- package/dist/tool-executor.js +0 -74
- package/dist/tools/file-editing-utils.d.ts +0 -2
- package/dist/tools/file-editing-utils.d.ts.map +0 -1
- package/dist/tools/file-editing-utils.js +0 -135
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { NoOutputGeneratedError, streamText, } from "ai";
|
|
2
|
+
import { logger } from "../logger.js";
|
|
3
|
+
import { AiConfig } from "../models/ai-config.js";
|
|
4
|
+
import { displayToolMessages } from "../repl/display-tool-messages.js";
|
|
5
|
+
import style from "../terminal/style.js";
|
|
6
|
+
import { isToolMessage } from "../tools/types.js";
|
|
7
|
+
import { isAsyncIterable } from "../utils/iterables.js";
|
|
8
|
+
export async function runManualLoop(opts) {
|
|
9
|
+
const { modelManager, messageHistory, systemPrompt, input, toolDefs, executors, maxIterations = 90, maxRetries = 2, abortSignal, toolCallRepair, } = opts;
|
|
10
|
+
const terminal = opts.terminal;
|
|
11
|
+
const langModel = modelManager.getModel("repl");
|
|
12
|
+
const modelConfig = modelManager.getModelMetadata("repl");
|
|
13
|
+
const aiConfig = new AiConfig({
|
|
14
|
+
modelMetadata: modelConfig,
|
|
15
|
+
prompt: input,
|
|
16
|
+
});
|
|
17
|
+
const loopResult = {
|
|
18
|
+
usage: {
|
|
19
|
+
inputTokens: 0,
|
|
20
|
+
outputTokens: 0,
|
|
21
|
+
totalTokens: 0,
|
|
22
|
+
reasoningTokens: 0,
|
|
23
|
+
cachedInputTokens: 0,
|
|
24
|
+
},
|
|
25
|
+
totalUsage: {
|
|
26
|
+
inputTokens: 0,
|
|
27
|
+
outputTokens: 0,
|
|
28
|
+
totalTokens: 0,
|
|
29
|
+
reasoningTokens: 0,
|
|
30
|
+
cachedInputTokens: 0,
|
|
31
|
+
},
|
|
32
|
+
steps: [],
|
|
33
|
+
};
|
|
34
|
+
let iter = 0;
|
|
35
|
+
let consecutiveErrors = 0;
|
|
36
|
+
while (iter < maxIterations) {
|
|
37
|
+
if (abortSignal?.aborted) {
|
|
38
|
+
logger.warn("The agent loop was aborted by the user.");
|
|
39
|
+
terminal.warn("Operation aborted by user.");
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const result = streamText({
|
|
44
|
+
model: langModel,
|
|
45
|
+
maxOutputTokens: aiConfig.maxOutputTokens(),
|
|
46
|
+
system: systemPrompt,
|
|
47
|
+
messages: messageHistory.get(),
|
|
48
|
+
temperature: aiConfig.temperature(),
|
|
49
|
+
topP: aiConfig.topP(),
|
|
50
|
+
maxRetries: 2,
|
|
51
|
+
providerOptions: aiConfig.providerOptions(),
|
|
52
|
+
tools: toolDefs,
|
|
53
|
+
// biome-ignore lint/style/useNamingConvention: third-party code
|
|
54
|
+
experimental_repairToolCall: toolCallRepair,
|
|
55
|
+
abortSignal,
|
|
56
|
+
});
|
|
57
|
+
let accumulatedText = "";
|
|
58
|
+
let lastType = null;
|
|
59
|
+
for await (const chunk of result.fullStream) {
|
|
60
|
+
if (chunk.type === "reasoning-delta" || chunk.type === "text-delta") {
|
|
61
|
+
if (chunk.type === "reasoning-delta") {
|
|
62
|
+
if (lastType !== "reasoning") {
|
|
63
|
+
terminal.writeln(style.dim("<think>"));
|
|
64
|
+
}
|
|
65
|
+
terminal.write(style.dim(chunk.text));
|
|
66
|
+
lastType = "reasoning";
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
terminal.stopProgress();
|
|
70
|
+
if (lastType === "reasoning") {
|
|
71
|
+
terminal.writeln(style.dim("\n</think>\n"));
|
|
72
|
+
}
|
|
73
|
+
accumulatedText += chunk.text;
|
|
74
|
+
lastType = "text";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// finish off this step
|
|
79
|
+
if (lastType === "reasoning") {
|
|
80
|
+
terminal.write(style.dim("\n</think>\n\n"));
|
|
81
|
+
}
|
|
82
|
+
terminal.stopProgress();
|
|
83
|
+
if (accumulatedText.trim()) {
|
|
84
|
+
terminal.writeln(`${style.blue.bold("● Response:")}`);
|
|
85
|
+
terminal.display(accumulatedText, true);
|
|
86
|
+
terminal.lineBreak();
|
|
87
|
+
}
|
|
88
|
+
accumulatedText = "";
|
|
89
|
+
lastType = null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Get response and tool calls
|
|
93
|
+
const response = await result.response;
|
|
94
|
+
const responseMessages = response.messages;
|
|
95
|
+
messageHistory.appendResponseMessages(responseMessages);
|
|
96
|
+
const toolCalls = await result.toolCalls;
|
|
97
|
+
const thisStepToolCalls = [];
|
|
98
|
+
const thisStepToolResults = [];
|
|
99
|
+
loopResult.steps.push({
|
|
100
|
+
toolCalls: thisStepToolCalls,
|
|
101
|
+
toolResults: thisStepToolResults,
|
|
102
|
+
});
|
|
103
|
+
// If finishReason is not tool-calls, break
|
|
104
|
+
const finishReason = await result.finishReason;
|
|
105
|
+
if (finishReason !== "tool-calls") {
|
|
106
|
+
const lastStepUsage = await result.usage;
|
|
107
|
+
loopResult.usage.inputTokens = lastStepUsage.inputTokens ?? 0;
|
|
108
|
+
loopResult.usage.outputTokens = lastStepUsage.outputTokens ?? 0;
|
|
109
|
+
loopResult.usage.totalTokens = lastStepUsage.totalTokens ?? 0;
|
|
110
|
+
loopResult.usage.cachedInputTokens =
|
|
111
|
+
lastStepUsage.cachedInputTokens ?? 0;
|
|
112
|
+
loopResult.usage.reasoningTokens = lastStepUsage.reasoningTokens ?? 0;
|
|
113
|
+
loopResult.totalUsage.inputTokens += lastStepUsage.inputTokens ?? 0;
|
|
114
|
+
loopResult.totalUsage.outputTokens += lastStepUsage.outputTokens ?? 0;
|
|
115
|
+
loopResult.totalUsage.totalTokens += lastStepUsage.totalTokens ?? 0;
|
|
116
|
+
loopResult.totalUsage.cachedInputTokens +=
|
|
117
|
+
lastStepUsage.cachedInputTokens ?? 0;
|
|
118
|
+
loopResult.totalUsage.reasoningTokens +=
|
|
119
|
+
lastStepUsage.reasoningTokens ?? 0;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
// Execute tools in parallel (order not guaranteed)
|
|
123
|
+
// Check response.messages for already-processed tool results
|
|
124
|
+
const alreadyProcessedToolCallIds = new Set();
|
|
125
|
+
// Look for tool results and tool errors in the response messages
|
|
126
|
+
for (const message of responseMessages) {
|
|
127
|
+
if (message.role === "tool" && Array.isArray(message.content)) {
|
|
128
|
+
for (const content of message.content) {
|
|
129
|
+
if ((content.type === "tool-result" ||
|
|
130
|
+
content.type === "tool-error") &&
|
|
131
|
+
content.toolCallId) {
|
|
132
|
+
alreadyProcessedToolCallIds.add(content.toolCallId);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Filter out tool calls that have already been processed or are invalid
|
|
138
|
+
const validToolCalls = toolCalls.filter((call) => !alreadyProcessedToolCallIds.has(call.toolCallId) &&
|
|
139
|
+
// Also check if the tool call is marked as invalid by the AI SDK
|
|
140
|
+
!call.invalid);
|
|
141
|
+
if (validToolCalls.length === 0) {
|
|
142
|
+
// All tool calls were already processed by the AI SDK
|
|
143
|
+
logger.debug(`All ${toolCalls.length} tool calls were already processed by AI SDK, skipping manual execution`);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (validToolCalls.length < toolCalls.length) {
|
|
147
|
+
logger.debug(`Filtered out ${toolCalls.length - validToolCalls.length} already-processed tool calls, executing ${validToolCalls.length} remaining`);
|
|
148
|
+
}
|
|
149
|
+
// Process all tools concurrently
|
|
150
|
+
const toolMessagesPromise = Promise.allSettled(validToolCalls.map(async (call) => {
|
|
151
|
+
const toolName = call.toolName;
|
|
152
|
+
let resultOutput = "Unknown result.";
|
|
153
|
+
try {
|
|
154
|
+
thisStepToolCalls.push({ toolName });
|
|
155
|
+
thisStepToolResults.push({ toolName });
|
|
156
|
+
const exec = executors.get(toolName);
|
|
157
|
+
if (!exec) {
|
|
158
|
+
resultOutput = `No executor for tool ${toolName}`;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
try {
|
|
162
|
+
const output = await exec(call.input, {
|
|
163
|
+
toolCallId: call.toolCallId,
|
|
164
|
+
messages: messageHistory.get(),
|
|
165
|
+
abortSignal,
|
|
166
|
+
});
|
|
167
|
+
if (isAsyncIterable(output)) {
|
|
168
|
+
const { finalValue } = await consumeToolAsyncIterable(output, terminal);
|
|
169
|
+
resultOutput = formatToolResult(finalValue);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
resultOutput = formatToolResult(output);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch (err) {
|
|
176
|
+
resultOutput = `Tool error: ${err instanceof Error ? err.message : String(err)}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
resultOutput = `Tool error: ${error instanceof Error ? error.message : String(error)}`;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
role: "tool",
|
|
185
|
+
content: [
|
|
186
|
+
{
|
|
187
|
+
type: "tool-result",
|
|
188
|
+
toolName,
|
|
189
|
+
toolCallId: call.toolCallId,
|
|
190
|
+
output: {
|
|
191
|
+
type: "text",
|
|
192
|
+
value: resultOutput,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
};
|
|
197
|
+
}));
|
|
198
|
+
const toolMessages = (await toolMessagesPromise)
|
|
199
|
+
.filter((result) => result.status === "fulfilled")
|
|
200
|
+
.map((result) => result.value);
|
|
201
|
+
messageHistory.appendToolMessages(toolMessages);
|
|
202
|
+
// Calculate usage for the current step/iteration
|
|
203
|
+
const stepUsage = await result.usage;
|
|
204
|
+
loopResult.totalUsage.inputTokens += stepUsage.inputTokens ?? 0;
|
|
205
|
+
loopResult.totalUsage.outputTokens += stepUsage.outputTokens ?? 0;
|
|
206
|
+
loopResult.totalUsage.totalTokens += stepUsage.totalTokens ?? 0;
|
|
207
|
+
loopResult.totalUsage.cachedInputTokens +=
|
|
208
|
+
stepUsage.cachedInputTokens ?? 0;
|
|
209
|
+
loopResult.totalUsage.reasoningTokens += stepUsage.reasoningTokens ?? 0;
|
|
210
|
+
// Consume the rest of the team if necessary
|
|
211
|
+
// await result.consumeStream();
|
|
212
|
+
// continue iterations
|
|
213
|
+
iter += 1;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
consecutiveErrors += 1;
|
|
217
|
+
logger.error(error, // Log the full error object
|
|
218
|
+
`Error on manual agent loop streamText (attempt ${consecutiveErrors}/${maxRetries + 1})`);
|
|
219
|
+
terminal.error("Error in manual agent loop.");
|
|
220
|
+
terminal.error(error.message.length > 100
|
|
221
|
+
? `${error.message.slice(0, 100)}...`
|
|
222
|
+
: error.message);
|
|
223
|
+
if (NoOutputGeneratedError.isInstance(error)) {
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
// Break loop if we exceed max retries
|
|
227
|
+
if (consecutiveErrors > maxRetries) {
|
|
228
|
+
terminal.error(`Exceeded maximum retry attempts (${maxRetries}). Stopping manual loop.`);
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return loopResult;
|
|
234
|
+
}
|
|
235
|
+
export async function consumeToolAsyncIterable(iterable, terminal) {
|
|
236
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
237
|
+
const toolResultValues = [];
|
|
238
|
+
let next = await iterator.next();
|
|
239
|
+
while (!next.done) {
|
|
240
|
+
const value = next.value;
|
|
241
|
+
if (isToolMessage(value)) {
|
|
242
|
+
if (terminal) {
|
|
243
|
+
displayToolMessages(value, terminal);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
toolResultValues.push(value);
|
|
248
|
+
}
|
|
249
|
+
next = await iterator.next();
|
|
250
|
+
}
|
|
251
|
+
const finalValue = next.value ??
|
|
252
|
+
(toolResultValues.length > 0 ? toolResultValues.at(-1) : undefined);
|
|
253
|
+
return { finalValue };
|
|
254
|
+
}
|
|
255
|
+
function formatToolResult(value) {
|
|
256
|
+
if (typeof value === "string") {
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
if (value === undefined) {
|
|
260
|
+
return "";
|
|
261
|
+
}
|
|
262
|
+
if (value === null) {
|
|
263
|
+
return "null";
|
|
264
|
+
}
|
|
265
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
266
|
+
return String(value);
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
const serialized = JSON.stringify(value);
|
|
270
|
+
if (typeof serialized === "string") {
|
|
271
|
+
return serialized;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// noop - fallback below
|
|
276
|
+
}
|
|
277
|
+
return String(value);
|
|
278
|
+
}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WorkspaceContext } from "./index.ts";
|
|
1
2
|
import type { MessageHistory } from "./messages.ts";
|
|
2
3
|
import type { ModelManager } from "./models/manager.js";
|
|
3
4
|
import type { PromptManager } from "./prompts/manager.ts";
|
|
@@ -10,6 +11,7 @@ interface CliOptions {
|
|
|
10
11
|
tokenTracker: TokenTracker;
|
|
11
12
|
config: Record<PropertyKey, unknown>;
|
|
12
13
|
tokenCounter: TokenCounter;
|
|
14
|
+
workspace: WorkspaceContext;
|
|
13
15
|
}
|
|
14
16
|
export declare class Cli {
|
|
15
17
|
private options;
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../source/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../source/cli.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AASxD,UAAU,UAAU;IAClB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACrC,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAWD,qBAAa,GAAG;IACd,OAAO,CAAC,OAAO,CAAa;gBAChB,OAAO,EAAE,UAAU;IAIzB,GAAG;CAkFV"}
|
package/dist/cli.js
CHANGED
|
@@ -2,12 +2,21 @@ import { generateObject, generateText, NoSuchToolError, stepCountIs, } from "ai"
|
|
|
2
2
|
import { logger } from "./logger.js";
|
|
3
3
|
import { AiConfig } from "./models/ai-config.js";
|
|
4
4
|
import { minSystemPrompt } from "./prompts.js";
|
|
5
|
-
import {
|
|
5
|
+
import { BashTool } from "./tools/bash.js";
|
|
6
|
+
import { CodeInterpreterTool } from "./tools/code-interpreter.js";
|
|
6
7
|
import { EditFileTool } from "./tools/edit-file.js";
|
|
8
|
+
import { GlobTool } from "./tools/glob.js";
|
|
9
|
+
import { GrepTool } from "./tools/grep.js";
|
|
7
10
|
import { initCliTools } from "./tools/index.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
import { ReadFileTool } from "./tools/read-file.js";
|
|
12
|
+
const activeTools = [
|
|
13
|
+
EditFileTool.name,
|
|
14
|
+
ReadFileTool.name,
|
|
15
|
+
BashTool.name,
|
|
16
|
+
GrepTool.name,
|
|
17
|
+
GlobTool.name,
|
|
18
|
+
CodeInterpreterTool.name,
|
|
19
|
+
];
|
|
11
20
|
export class Cli {
|
|
12
21
|
options;
|
|
13
22
|
constructor(options) {
|
|
@@ -33,41 +42,25 @@ export class Cli {
|
|
|
33
42
|
modelMetadata: modelConfig,
|
|
34
43
|
prompt: userPrompt,
|
|
35
44
|
});
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
const tools = await initCliTools({
|
|
46
|
+
tokenCounter,
|
|
47
|
+
workspace: this.options.workspace,
|
|
48
|
+
});
|
|
40
49
|
try {
|
|
41
50
|
const result = await generateText({
|
|
42
51
|
model: langModel,
|
|
43
|
-
maxOutputTokens:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
providerOptions: {
|
|
49
|
-
anthropic: { cacheControl: { type: "ephemeral" } },
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
...messageHistory.get(),
|
|
53
|
-
],
|
|
54
|
-
temperature: modelConfig.defaultTemperature,
|
|
52
|
+
maxOutputTokens: aiConfig.maxOutputTokens(),
|
|
53
|
+
system: finalSystemPrompt,
|
|
54
|
+
messages: messageHistory.get(),
|
|
55
|
+
temperature: aiConfig.temperature(),
|
|
56
|
+
topP: aiConfig.topP(),
|
|
55
57
|
stopWhen: stepCountIs(60),
|
|
56
58
|
maxRetries: 2,
|
|
57
|
-
providerOptions: aiConfig.
|
|
58
|
-
tools,
|
|
59
|
-
|
|
60
|
-
experimental_activeTools: [
|
|
61
|
-
EditFileTool.name,
|
|
62
|
-
SaveFileTool.name,
|
|
63
|
-
MoveFileTool.name,
|
|
64
|
-
DeleteFileTool.name,
|
|
65
|
-
ThinkTool.name,
|
|
66
|
-
],
|
|
59
|
+
providerOptions: aiConfig.providerOptions(),
|
|
60
|
+
tools: tools.toolDefs,
|
|
61
|
+
activeTools,
|
|
67
62
|
// biome-ignore lint/style/useNamingConvention: third-party controlled
|
|
68
|
-
experimental_repairToolCall:
|
|
69
|
-
? toolCallRepair(modelManager)
|
|
70
|
-
: undefined,
|
|
63
|
+
experimental_repairToolCall: toolCallRepair(modelManager),
|
|
71
64
|
abortSignal: signal,
|
|
72
65
|
});
|
|
73
66
|
if (result.response.messages.length > 0) {
|
|
@@ -75,6 +68,7 @@ export class Cli {
|
|
|
75
68
|
}
|
|
76
69
|
// this tracks the usage of every step in the call to streamText. it's a cumulative usage.
|
|
77
70
|
tokenTracker.trackUsage("cli", result.usage);
|
|
71
|
+
messageHistory.save();
|
|
78
72
|
process.stdout.end(result.text.endsWith("\n") ? result.text : `${result.text}\n`);
|
|
79
73
|
}
|
|
80
74
|
catch (e) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-directory-command.d.ts","sourceRoot":"","sources":["../../source/commands/add-directory-command.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,mBAAmB,GAAI,0BAGjC,cAAc,KAAG,WAkInB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import style from "../terminal/style.js";
|
|
4
|
+
import { Text } from "../tui/index.js";
|
|
5
|
+
export const addDirectoryCommand = ({ terminal, workspace, }) => {
|
|
6
|
+
return {
|
|
7
|
+
command: "/add-directory",
|
|
8
|
+
description: "Add a directory to the list of allowed working directories",
|
|
9
|
+
getSubCommands: async () => {
|
|
10
|
+
return [];
|
|
11
|
+
},
|
|
12
|
+
execute: async (args) => {
|
|
13
|
+
const directoryPath = args?.[0];
|
|
14
|
+
if (!directoryPath) {
|
|
15
|
+
terminal.error("Usage: /add-directory <path>");
|
|
16
|
+
return "continue";
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
// Resolve and validate the directory
|
|
20
|
+
const resolvedPath = path.resolve(directoryPath);
|
|
21
|
+
const stats = await fs.stat(resolvedPath);
|
|
22
|
+
if (!stats.isDirectory()) {
|
|
23
|
+
terminal.error(`Path is not a directory: ${resolvedPath}`);
|
|
24
|
+
return "continue";
|
|
25
|
+
}
|
|
26
|
+
// Check if directory is already in the list
|
|
27
|
+
if (workspace.allowedDirs.includes(resolvedPath)) {
|
|
28
|
+
terminal.warn(`Directory already in allowed list: ${resolvedPath}`);
|
|
29
|
+
return "continue";
|
|
30
|
+
}
|
|
31
|
+
// Add the directory to the workspace
|
|
32
|
+
workspace.allowedDirs.push(resolvedPath);
|
|
33
|
+
terminal.writeln(`Added directory to allowed list: ${style.blue(resolvedPath)}`);
|
|
34
|
+
terminal.writeln(`Current allowed directories: ${style.blue(workspace.allowedDirs.join(", "))}`);
|
|
35
|
+
return "continue";
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
39
|
+
terminal.error(`Failed to add directory: ${errorMessage}`);
|
|
40
|
+
return "continue";
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
async handle(args, { tui, container, editor, }) {
|
|
44
|
+
const directoryPath = args?.[0];
|
|
45
|
+
if (!directoryPath) {
|
|
46
|
+
container.addChild(new Text(style.red("Usage: /add-directory <path>"), 0, 1));
|
|
47
|
+
tui.requestRender();
|
|
48
|
+
editor.setText("");
|
|
49
|
+
return "continue";
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
// Resolve and validate the directory
|
|
53
|
+
const resolvedPath = path.resolve(directoryPath);
|
|
54
|
+
const stats = await fs.stat(resolvedPath);
|
|
55
|
+
if (!stats.isDirectory()) {
|
|
56
|
+
container.addChild(new Text(style.red(`Path is not a directory: ${resolvedPath}`), 1, 0));
|
|
57
|
+
tui.requestRender();
|
|
58
|
+
editor.setText("");
|
|
59
|
+
return "continue";
|
|
60
|
+
}
|
|
61
|
+
// Check if directory is already in the list
|
|
62
|
+
if (workspace.allowedDirs.includes(resolvedPath)) {
|
|
63
|
+
container.addChild(new Text(style.yellow(`Directory already in allowed list: ${resolvedPath}`), 1, 0));
|
|
64
|
+
tui.requestRender();
|
|
65
|
+
editor.setText("");
|
|
66
|
+
return "continue";
|
|
67
|
+
}
|
|
68
|
+
// Add the directory to the workspace
|
|
69
|
+
workspace.allowedDirs.push(resolvedPath);
|
|
70
|
+
container.addChild(new Text(`Added directory to allowed list: ${style.blue(resolvedPath)}`, 1, 0));
|
|
71
|
+
container.addChild(new Text(`Current allowed directories: ${style.blue(workspace.allowedDirs.join(", "))}`, 2, 0));
|
|
72
|
+
tui.requestRender();
|
|
73
|
+
editor.setText("");
|
|
74
|
+
return "continue";
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
78
|
+
container.addChild(new Text(style.red(`Failed to add directory: ${errorMessage}`), 0, 1));
|
|
79
|
+
tui.requestRender();
|
|
80
|
+
editor.setText("");
|
|
81
|
+
return "continue";
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-log-command.d.ts","sourceRoot":"","sources":["../../source/commands/application-log-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"application-log-command.d.ts","sourceRoot":"","sources":["../../source/commands/application-log-command.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,qBAAqB,GAAI,eAEnC,cAAc,KAAG,WAwHnB,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { config } from "../config.js";
|
|
3
3
|
import { editor } from "../terminal/editor-prompt.js";
|
|
4
|
+
import style from "../terminal/style.js";
|
|
5
|
+
import { Text } from "../tui/index.js";
|
|
4
6
|
export const applicationLogCommand = ({ terminal, }) => {
|
|
5
7
|
return {
|
|
6
8
|
command: "/application-logs",
|
|
@@ -41,5 +43,37 @@ export const applicationLogCommand = ({ terminal, }) => {
|
|
|
41
43
|
return "continue";
|
|
42
44
|
}
|
|
43
45
|
},
|
|
46
|
+
async handle(_args, { tui, container, editor, }) {
|
|
47
|
+
let logFilePath;
|
|
48
|
+
try {
|
|
49
|
+
const projectConfig = await config.readProjectConfig();
|
|
50
|
+
logFilePath = projectConfig.logs?.path;
|
|
51
|
+
if (!logFilePath) {
|
|
52
|
+
container.addChild(new Text(style.red("Application log path is not defined in .acai/acai.json under the 'logs.path' key."), 1, 0));
|
|
53
|
+
tui.requestRender();
|
|
54
|
+
editor.setText("");
|
|
55
|
+
return "continue";
|
|
56
|
+
}
|
|
57
|
+
const content = await readFile(logFilePath, { encoding: "utf8" });
|
|
58
|
+
// For TUI mode, we'll just display a message since we can't use the editor prompt
|
|
59
|
+
container.addChild(new Text(`Viewing application log: ${style.blue(logFilePath)}`, 0, 1));
|
|
60
|
+
container.addChild(new Text(`Content length: ${content.length} characters`, 2, 0));
|
|
61
|
+
container.addChild(new Text(style.dim("Note: Full log viewing not available in TUI mode"), 3, 0));
|
|
62
|
+
tui.requestRender();
|
|
63
|
+
editor.setText("");
|
|
64
|
+
return "continue";
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (logFilePath && error.code === "ENOENT") {
|
|
68
|
+
container.addChild(new Text(style.red(`Application log file not found at: ${logFilePath}`), 1, 0));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
container.addChild(new Text(style.red(`Error reading log file ${logFilePath ?? "specified in config"}: ${error}`), 1, 0));
|
|
72
|
+
}
|
|
73
|
+
tui.requestRender();
|
|
74
|
+
editor.setText("");
|
|
75
|
+
return "continue";
|
|
76
|
+
}
|
|
77
|
+
},
|
|
44
78
|
};
|
|
45
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear-command.d.ts","sourceRoot":"","sources":["../../source/commands/clear-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clear-command.d.ts","sourceRoot":"","sources":["../../source/commands/clear-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,YAAY,GAAI,cAAc,cAAc,KAAG,WAyB3D,CAAC"}
|
|
@@ -7,5 +7,13 @@ export const clearCommand = ({ terminal }) => {
|
|
|
7
7
|
terminal.clear();
|
|
8
8
|
return "continue";
|
|
9
9
|
},
|
|
10
|
+
async handle(_args, { tui, container, editor, }) {
|
|
11
|
+
// In TUI mode, we can't clear the screen like terminal.clear()
|
|
12
|
+
// Instead, we'll just clear the input and show a message
|
|
13
|
+
container.clear();
|
|
14
|
+
tui.requestRender();
|
|
15
|
+
editor.setText("");
|
|
16
|
+
return "continue";
|
|
17
|
+
},
|
|
10
18
|
};
|
|
11
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compact-command.d.ts","sourceRoot":"","sources":["../../source/commands/compact-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compact-command.d.ts","sourceRoot":"","sources":["../../source/commands/compact-command.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,cAAc,GAAI,SAAS,cAAc,KAAG,WAqCxD,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { generateText } from "ai";
|
|
2
2
|
import { createUserMessage } from "../messages.js";
|
|
3
|
+
import style from "../terminal/style.js";
|
|
4
|
+
import { Text } from "../tui/index.js";
|
|
3
5
|
export const compactCommand = (options) => {
|
|
4
6
|
return {
|
|
5
7
|
command: "/compact",
|
|
@@ -14,6 +16,17 @@ export const compactCommand = (options) => {
|
|
|
14
16
|
terminal.info("Message history summarized and reset.");
|
|
15
17
|
return "continue";
|
|
16
18
|
},
|
|
19
|
+
async handle(args, { tui, container, editor, }) {
|
|
20
|
+
const { messageHistory } = options;
|
|
21
|
+
if (!messageHistory.isEmpty()) {
|
|
22
|
+
const additionalInstructions = args.join(" ");
|
|
23
|
+
await summarizeAndReset(options, additionalInstructions);
|
|
24
|
+
}
|
|
25
|
+
container.addChild(new Text(style.green("Message history summarized and reset."), 0, 1));
|
|
26
|
+
tui.requestRender();
|
|
27
|
+
editor.setText("");
|
|
28
|
+
return "continue";
|
|
29
|
+
},
|
|
17
30
|
};
|
|
18
31
|
};
|
|
19
32
|
async function summarizeAndReset({ messageHistory, modelManager, tokenTracker }, additionalInstructions) {
|
|
@@ -45,7 +58,7 @@ Your summary should include the following sections:
|
|
|
45
58
|
messages: messageHistory.get(),
|
|
46
59
|
});
|
|
47
60
|
tokenTracker.trackUsage(app, usage);
|
|
48
|
-
//
|
|
49
|
-
messageHistory.
|
|
61
|
+
//create new session
|
|
62
|
+
messageHistory.create(modelManager.getModel("repl").modelId);
|
|
50
63
|
messageHistory.appendUserMessage(createUserMessage([text]));
|
|
51
64
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-command.d.ts","sourceRoot":"","sources":["../../source/commands/context-command.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4C9D,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,SAAS,GACV,EAAE,cAAc,GAAG,WAAW,CA4L9B"}
|