@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
package/dist/repl-new.js
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { PromptError, processPrompt } from "./mentions.js";
|
|
2
|
+
import { getProjectStatusLine } from "./repl/project-status-line.js";
|
|
3
|
+
import { AssistantMessageComponent } from "./tui/components/assistant-message.js";
|
|
4
|
+
import { FooterComponent } from "./tui/components/footer.js";
|
|
5
|
+
import { PromptStatusComponent } from "./tui/components/prompt-status.js";
|
|
6
|
+
import { ThinkingBlockComponent } from "./tui/components/thinking-block.js";
|
|
7
|
+
import { ToolExecutionComponent } from "./tui/components/tool-execution.js";
|
|
8
|
+
import { Welcome } from "./tui/components/welcome.js";
|
|
9
|
+
import { CombinedAutocompleteProvider, Container, Editor, Loader, ProcessTerminal, Spacer, TUI, UserMessageComponent, } from "./tui/index.js";
|
|
10
|
+
export class NewRepl {
|
|
11
|
+
options;
|
|
12
|
+
tui;
|
|
13
|
+
welcome;
|
|
14
|
+
editor;
|
|
15
|
+
chatContainer;
|
|
16
|
+
statusContainer;
|
|
17
|
+
promptStatus;
|
|
18
|
+
footer;
|
|
19
|
+
editorContainer; // Container to swap between editor and selector
|
|
20
|
+
isInitialized;
|
|
21
|
+
onInputCallback;
|
|
22
|
+
loadingAnimation = null;
|
|
23
|
+
onInterruptCallback;
|
|
24
|
+
lastSigintTime = 0;
|
|
25
|
+
pendingTools;
|
|
26
|
+
// Streaming message tracking
|
|
27
|
+
streamingComponent = null;
|
|
28
|
+
// thinking block tracking
|
|
29
|
+
thinkingBlockComponent = null;
|
|
30
|
+
constructor(options) {
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.tui = new TUI(new ProcessTerminal());
|
|
33
|
+
this.welcome = new Welcome();
|
|
34
|
+
this.editor = new Editor();
|
|
35
|
+
this.chatContainer = new Container();
|
|
36
|
+
this.statusContainer = new Container();
|
|
37
|
+
this.editorContainer = new Container(); // Container to hold editor or selector
|
|
38
|
+
this.footer = new FooterComponent(options.agent.state);
|
|
39
|
+
this.promptStatus = new PromptStatusComponent(options.modelManager, {
|
|
40
|
+
projectStatus: "",
|
|
41
|
+
currentContextWindow: 0,
|
|
42
|
+
contextWindow: options.modelManager.getModelMetadata("repl").contextWindow,
|
|
43
|
+
});
|
|
44
|
+
this.editorContainer.addChild(this.editor); // Start with editor
|
|
45
|
+
this.editor.onRenderRequested = () => this.tui.requestRender();
|
|
46
|
+
this.isInitialized = false;
|
|
47
|
+
this.pendingTools = new Map();
|
|
48
|
+
}
|
|
49
|
+
async init() {
|
|
50
|
+
if (this.isInitialized) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// Setup autocomplete for file paths and slash commands
|
|
54
|
+
const autocompleteProvider = new CombinedAutocompleteProvider([...(await this.options.commands.getCompletions())], this.options.workspace.allowedDirs);
|
|
55
|
+
this.editor.setAutocompleteProvider(autocompleteProvider);
|
|
56
|
+
const { promptManager, terminal, modelManager, messageHistory, commands, promptHistory, } = this.options;
|
|
57
|
+
const modelConfig = modelManager.getModelMetadata("repl");
|
|
58
|
+
this.promptStatus.setState({
|
|
59
|
+
projectStatus: await getProjectStatusLine(),
|
|
60
|
+
currentContextWindow: 0,
|
|
61
|
+
contextWindow: modelConfig.contextWindow,
|
|
62
|
+
});
|
|
63
|
+
this.tui.addChild(this.welcome);
|
|
64
|
+
this.tui.addChild(this.chatContainer);
|
|
65
|
+
this.tui.addChild(this.statusContainer);
|
|
66
|
+
this.tui.addChild(new Spacer(1));
|
|
67
|
+
this.tui.addChild(this.footer);
|
|
68
|
+
this.tui.addChild(this.editorContainer); // Use container that can hold editor or selector
|
|
69
|
+
this.tui.addChild(this.promptStatus);
|
|
70
|
+
this.tui.setFocus(this.editor);
|
|
71
|
+
// Set up custom key handlers on the editor
|
|
72
|
+
this.editor.onEscape = () => {
|
|
73
|
+
// Intercept Escape key when processing
|
|
74
|
+
if (this.loadingAnimation && this.onInterruptCallback) {
|
|
75
|
+
this.onInterruptCallback();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
this.editor.onCtrlC = () => {
|
|
79
|
+
this.handleCtrlC();
|
|
80
|
+
};
|
|
81
|
+
// Create editor for input
|
|
82
|
+
this.editor.onSubmit = async (text) => {
|
|
83
|
+
if (text.trim()) {
|
|
84
|
+
// see if the text contains a command
|
|
85
|
+
const commandResult = await commands.handle2({ userInput: text }, {
|
|
86
|
+
tui: this.tui,
|
|
87
|
+
container: this.chatContainer,
|
|
88
|
+
inputContainer: this.editorContainer,
|
|
89
|
+
editor: this.editor,
|
|
90
|
+
});
|
|
91
|
+
if (commandResult.break) {
|
|
92
|
+
this.stop();
|
|
93
|
+
process.exit(0);
|
|
94
|
+
}
|
|
95
|
+
if (commandResult.continue) {
|
|
96
|
+
this.editor.setText("");
|
|
97
|
+
this.tui.requestRender();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!promptManager.isPending()) {
|
|
101
|
+
try {
|
|
102
|
+
const processedPrompt = await processPrompt(text, {
|
|
103
|
+
baseDir: process.cwd(),
|
|
104
|
+
model: modelConfig,
|
|
105
|
+
});
|
|
106
|
+
for (const context of processedPrompt.context) {
|
|
107
|
+
promptManager.addContext(context);
|
|
108
|
+
}
|
|
109
|
+
promptManager.set(processedPrompt.message);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (error instanceof PromptError) {
|
|
113
|
+
terminal.error(`Prompt processing failed: ${error.message}`);
|
|
114
|
+
if (error.cause &&
|
|
115
|
+
typeof error.cause === "object" &&
|
|
116
|
+
"command" in error.cause &&
|
|
117
|
+
typeof error.cause.command === "string") {
|
|
118
|
+
terminal.error(`Command: ${error.cause.command}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
throw error; // Re-throw other errors
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
promptHistory.push(promptManager.get());
|
|
126
|
+
}
|
|
127
|
+
// flag to see if the user prompt has added context
|
|
128
|
+
const hasAddedContext = promptManager.hasContext();
|
|
129
|
+
if (hasAddedContext) {
|
|
130
|
+
const contextTokenCount = promptManager.getContextTokenCount();
|
|
131
|
+
terminal.info(`Context will be added to prompt. (${contextTokenCount} tokens)`);
|
|
132
|
+
terminal.lineBreak();
|
|
133
|
+
}
|
|
134
|
+
const userPrompt = promptManager.get();
|
|
135
|
+
const userMsg = promptManager.getUserMessage();
|
|
136
|
+
messageHistory.appendUserMessage(userMsg);
|
|
137
|
+
if (this.onInputCallback) {
|
|
138
|
+
this.onInputCallback(userPrompt);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
// Start
|
|
143
|
+
this.tui.start();
|
|
144
|
+
this.isInitialized = true;
|
|
145
|
+
}
|
|
146
|
+
async handle(event, state) {
|
|
147
|
+
if (!this.isInitialized) {
|
|
148
|
+
await this.init();
|
|
149
|
+
}
|
|
150
|
+
// Update footer with current stats
|
|
151
|
+
this.footer.updateState(state);
|
|
152
|
+
this.promptStatus.setState({
|
|
153
|
+
projectStatus: await getProjectStatusLine(),
|
|
154
|
+
currentContextWindow: state.usage.totalTokens,
|
|
155
|
+
contextWindow: this.options.modelManager.getModelMetadata("repl").contextWindow,
|
|
156
|
+
});
|
|
157
|
+
const eventType = event.type;
|
|
158
|
+
switch (eventType) {
|
|
159
|
+
case "agent-start":
|
|
160
|
+
// Show loading animation
|
|
161
|
+
this.editor.disableSubmit = true;
|
|
162
|
+
// Stop old loader before clearing
|
|
163
|
+
if (this.loadingAnimation) {
|
|
164
|
+
this.loadingAnimation.stop();
|
|
165
|
+
}
|
|
166
|
+
this.statusContainer.clear();
|
|
167
|
+
this.loadingAnimation = new Loader(this.tui, "Working... (esc to interrupt)");
|
|
168
|
+
this.statusContainer.addChild(this.loadingAnimation);
|
|
169
|
+
this.tui.requestRender();
|
|
170
|
+
break;
|
|
171
|
+
case "step-start":
|
|
172
|
+
this.tui.requestRender();
|
|
173
|
+
break;
|
|
174
|
+
case "step-stop":
|
|
175
|
+
this.pendingTools.clear();
|
|
176
|
+
this.tui.requestRender();
|
|
177
|
+
break;
|
|
178
|
+
case "message-start":
|
|
179
|
+
if (event.role === "assistant") {
|
|
180
|
+
// Create assistant component for streaming
|
|
181
|
+
const assistantMessageComponent = new AssistantMessageComponent();
|
|
182
|
+
this.streamingComponent = assistantMessageComponent;
|
|
183
|
+
this.chatContainer.addChild(assistantMessageComponent);
|
|
184
|
+
this.streamingComponent.updateContent(event);
|
|
185
|
+
this.tui.requestRender();
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case "message":
|
|
189
|
+
if (event.role === "user") {
|
|
190
|
+
// Show user message immediately and clear editor
|
|
191
|
+
this.addMessageToChat(event);
|
|
192
|
+
this.editor.setText("");
|
|
193
|
+
this.tui.requestRender();
|
|
194
|
+
}
|
|
195
|
+
else if (event.role === "assistant") {
|
|
196
|
+
// Update streaming component
|
|
197
|
+
if (this.streamingComponent && event.role === "assistant") {
|
|
198
|
+
this.streamingComponent.updateContent(event);
|
|
199
|
+
this.tui.requestRender();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
case "message-end":
|
|
204
|
+
if (this.streamingComponent && event.role === "assistant") {
|
|
205
|
+
this.streamingComponent.updateContent(event);
|
|
206
|
+
this.streamingComponent = null;
|
|
207
|
+
}
|
|
208
|
+
this.tui.requestRender();
|
|
209
|
+
break;
|
|
210
|
+
case "tool-call-start": {
|
|
211
|
+
// Create tool component for new tool call
|
|
212
|
+
const component = this.pendingTools.get(event.toolCallId);
|
|
213
|
+
if (component) {
|
|
214
|
+
component.update(event);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const newComponent = new ToolExecutionComponent(event);
|
|
218
|
+
this.pendingTools.set(event.toolCallId, newComponent);
|
|
219
|
+
this.chatContainer.addChild(newComponent);
|
|
220
|
+
}
|
|
221
|
+
this.tui.requestRender();
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "tool-call-end": {
|
|
225
|
+
// Update the existing tool component with the result
|
|
226
|
+
const component = this.pendingTools.get(event.toolCallId);
|
|
227
|
+
if (component) {
|
|
228
|
+
component.update(event);
|
|
229
|
+
this.pendingTools.delete(event.toolCallId);
|
|
230
|
+
this.tui.requestRender();
|
|
231
|
+
}
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case "tool-call-update": {
|
|
235
|
+
// Update the existing tool component with the result
|
|
236
|
+
const component = this.pendingTools.get(event.toolCallId);
|
|
237
|
+
if (component) {
|
|
238
|
+
component.update(event);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
// Defensive: create component if update arrives before start
|
|
242
|
+
const newComponent = new ToolExecutionComponent(event);
|
|
243
|
+
this.pendingTools.set(event.toolCallId, newComponent);
|
|
244
|
+
this.chatContainer.addChild(newComponent);
|
|
245
|
+
}
|
|
246
|
+
this.tui.requestRender();
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
case "tool-call-error": {
|
|
250
|
+
// Update the existing tool component with the result
|
|
251
|
+
const component = this.pendingTools.get(event.toolCallId);
|
|
252
|
+
if (component) {
|
|
253
|
+
component.update(event);
|
|
254
|
+
this.pendingTools.delete(event.toolCallId);
|
|
255
|
+
this.tui.requestRender();
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
case "agent-stop":
|
|
260
|
+
// Stop loading animation
|
|
261
|
+
if (this.loadingAnimation) {
|
|
262
|
+
this.loadingAnimation.stop();
|
|
263
|
+
this.loadingAnimation = null;
|
|
264
|
+
this.statusContainer.clear();
|
|
265
|
+
}
|
|
266
|
+
// Clear streaming component reference
|
|
267
|
+
if (this.streamingComponent) {
|
|
268
|
+
this.streamingComponent = null;
|
|
269
|
+
}
|
|
270
|
+
this.pendingTools.clear();
|
|
271
|
+
this.editor.disableSubmit = false;
|
|
272
|
+
this.tui.requestRender();
|
|
273
|
+
break;
|
|
274
|
+
case "agent-error":
|
|
275
|
+
// Stop loading animation
|
|
276
|
+
if (this.loadingAnimation) {
|
|
277
|
+
this.loadingAnimation.stop();
|
|
278
|
+
this.loadingAnimation = null;
|
|
279
|
+
this.statusContainer.clear();
|
|
280
|
+
}
|
|
281
|
+
// Clear streaming component reference
|
|
282
|
+
if (this.streamingComponent) {
|
|
283
|
+
this.streamingComponent = null;
|
|
284
|
+
}
|
|
285
|
+
this.pendingTools.clear();
|
|
286
|
+
this.editor.disableSubmit = false;
|
|
287
|
+
this.tui.requestRender();
|
|
288
|
+
break;
|
|
289
|
+
case "thinking-start": {
|
|
290
|
+
const component = new ThinkingBlockComponent();
|
|
291
|
+
this.thinkingBlockComponent = component;
|
|
292
|
+
this.chatContainer.addChild(component);
|
|
293
|
+
this.thinkingBlockComponent.updateContent(event);
|
|
294
|
+
this.tui.requestRender();
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case "thinking":
|
|
298
|
+
if (this.thinkingBlockComponent) {
|
|
299
|
+
this.thinkingBlockComponent.updateContent(event);
|
|
300
|
+
}
|
|
301
|
+
this.tui.requestRender();
|
|
302
|
+
break;
|
|
303
|
+
case "thinking-end":
|
|
304
|
+
if (this.thinkingBlockComponent) {
|
|
305
|
+
this.thinkingBlockComponent.updateContent(event);
|
|
306
|
+
this.thinkingBlockComponent = null;
|
|
307
|
+
}
|
|
308
|
+
this.tui.requestRender();
|
|
309
|
+
break;
|
|
310
|
+
default:
|
|
311
|
+
eventType;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
addMessageToChat(message) {
|
|
315
|
+
if (message.role === "user") {
|
|
316
|
+
// Extract text content from content blocks
|
|
317
|
+
const textContent = message.content;
|
|
318
|
+
if (textContent) {
|
|
319
|
+
const userComponent = new UserMessageComponent(textContent);
|
|
320
|
+
this.chatContainer.addChild(userComponent);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async getUserInput() {
|
|
325
|
+
return new Promise((resolve) => {
|
|
326
|
+
this.onInputCallback = (text) => {
|
|
327
|
+
this.onInputCallback = undefined;
|
|
328
|
+
resolve(text);
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
clearEditor() {
|
|
333
|
+
this.editor.setText("");
|
|
334
|
+
this.tui.requestRender();
|
|
335
|
+
}
|
|
336
|
+
setInterruptCallback(callback) {
|
|
337
|
+
this.onInterruptCallback = callback;
|
|
338
|
+
}
|
|
339
|
+
async rerender() {
|
|
340
|
+
this.footer.updateState(this.options.agent.state);
|
|
341
|
+
this.promptStatus.setState({
|
|
342
|
+
projectStatus: await getProjectStatusLine(),
|
|
343
|
+
currentContextWindow: this.options.agent.state.usage.totalTokens,
|
|
344
|
+
contextWindow: this.options.modelManager.getModelMetadata("repl").contextWindow,
|
|
345
|
+
});
|
|
346
|
+
this.tui.requestRender();
|
|
347
|
+
}
|
|
348
|
+
handleCtrlC() {
|
|
349
|
+
// Handle Ctrl+C double-press logic
|
|
350
|
+
const now = Date.now();
|
|
351
|
+
const timeSinceLastCtrlC = now - this.lastSigintTime;
|
|
352
|
+
if (timeSinceLastCtrlC < 500) {
|
|
353
|
+
// Second Ctrl+C within 500ms - exit
|
|
354
|
+
this.options.messageHistory.save();
|
|
355
|
+
this.stop();
|
|
356
|
+
process.exit(0);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
// First Ctrl+C - clear the editor
|
|
360
|
+
this.clearEditor();
|
|
361
|
+
this.lastSigintTime = now;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
stop() {
|
|
365
|
+
if (this.loadingAnimation) {
|
|
366
|
+
this.loadingAnimation.stop();
|
|
367
|
+
this.loadingAnimation = null;
|
|
368
|
+
}
|
|
369
|
+
if (this.isInitialized) {
|
|
370
|
+
this.tui.stop();
|
|
371
|
+
this.isInitialized = false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
package/dist/repl.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { CommandManager } from "./commands/manager.ts";
|
|
2
|
+
import type { WorkspaceContext } from "./index.ts";
|
|
2
3
|
import type { MessageHistory } from "./messages.ts";
|
|
3
|
-
import type { ModelManager } from "./models/manager.
|
|
4
|
+
import type { ModelManager } from "./models/manager.ts";
|
|
4
5
|
import type { PromptManager } from "./prompts/manager.ts";
|
|
5
6
|
import type { Terminal } from "./terminal/index.ts";
|
|
6
7
|
import type { TokenCounter } from "./tokens/counter.ts";
|
|
7
8
|
import type { TokenTracker } from "./tokens/tracker.ts";
|
|
8
|
-
import type { ToolExecutor } from "./tool-executor.ts";
|
|
9
|
-
import type { Message } from "./tools/types.ts";
|
|
10
9
|
interface ReplOptions {
|
|
11
10
|
messageHistory: MessageHistory;
|
|
12
11
|
promptManager: PromptManager;
|
|
@@ -16,10 +15,9 @@ interface ReplOptions {
|
|
|
16
15
|
commands: CommandManager;
|
|
17
16
|
config: Record<PropertyKey, unknown>;
|
|
18
17
|
tokenCounter: TokenCounter;
|
|
19
|
-
toolEvents: Map<string, Message[]>;
|
|
20
18
|
showLastMessage: boolean;
|
|
21
|
-
toolExecutor?: ToolExecutor;
|
|
22
19
|
promptHistory: string[];
|
|
20
|
+
workspace: WorkspaceContext;
|
|
23
21
|
}
|
|
24
22
|
export declare class Repl {
|
|
25
23
|
private options;
|
package/dist/repl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../source/repl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"repl.d.ts","sourceRoot":"","sources":["../source/repl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAM1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGxD,UAAU,WAAW;IACnB,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACrC,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,qBAAa,IAAI;IACf,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,eAAe,CAAU;gBAErB,OAAO,EAAE,WAAW;IAK1B,GAAG;CA0PV"}
|