@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,183 @@
|
|
|
1
|
+
import { systemPrompt } from "../prompts.js";
|
|
2
|
+
import { initCliTools } from "../tools/index.js";
|
|
3
|
+
import { prepareTools } from "../tools/utils.js";
|
|
4
|
+
import { Container, Modal, ModalTable, ModalText } from "../tui/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* Count tokens from message history
|
|
7
|
+
*/
|
|
8
|
+
function countMessageTokens(messages, counter) {
|
|
9
|
+
if (messages.length === 0) {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
// Serialize messages to JSON for token counting
|
|
13
|
+
const serializedMessages = JSON.stringify(messages);
|
|
14
|
+
return counter.count(serializedMessages);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Format numbers for display (e.g., 1.2k, 5.1m)
|
|
18
|
+
*/
|
|
19
|
+
function formatNum(n) {
|
|
20
|
+
if (n < 1000)
|
|
21
|
+
return `${n}`;
|
|
22
|
+
if (n < 1_000_000)
|
|
23
|
+
return `${(n / 1000).toFixed(1)}k`;
|
|
24
|
+
return `${(n / 1_000_000).toFixed(1)}m`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Calculate percentage for display
|
|
28
|
+
*/
|
|
29
|
+
function pct(n, d) {
|
|
30
|
+
if (d <= 0)
|
|
31
|
+
return "0.0%";
|
|
32
|
+
return `${((n / d) * 100).toFixed(1)}%`;
|
|
33
|
+
}
|
|
34
|
+
export function contextCommand({ terminal, tokenCounter, modelManager, messageHistory, workspace, }) {
|
|
35
|
+
return {
|
|
36
|
+
command: "/context",
|
|
37
|
+
description: "Show context window usage breakdown",
|
|
38
|
+
getSubCommands: () => Promise.resolve(["--details", "--json"]),
|
|
39
|
+
async execute(args) {
|
|
40
|
+
const meta = modelManager.getModelMetadata("repl");
|
|
41
|
+
const window = meta.contextWindow;
|
|
42
|
+
// 1) System prompt
|
|
43
|
+
const sys = await systemPrompt({
|
|
44
|
+
supportsToolCalling: meta.supportsToolCalling,
|
|
45
|
+
includeRules: true,
|
|
46
|
+
});
|
|
47
|
+
const systemPromptTokens = tokenCounter.count(sys);
|
|
48
|
+
// 2) Tools (MVP approximation)
|
|
49
|
+
let toolsTokens = 0;
|
|
50
|
+
try {
|
|
51
|
+
const tools = await initCliTools({ tokenCounter, workspace });
|
|
52
|
+
const toolDefs = tools.toolDefs;
|
|
53
|
+
const toolNames = JSON.stringify(prepareTools(toolDefs));
|
|
54
|
+
toolsTokens = tokenCounter.count(toolNames);
|
|
55
|
+
// v2: replace with exact serialized definitions
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error(error);
|
|
59
|
+
toolsTokens = 0;
|
|
60
|
+
}
|
|
61
|
+
// 3) Messages
|
|
62
|
+
const messagesTokens = countMessageTokens(messageHistory.get(), tokenCounter);
|
|
63
|
+
// 4) Totals
|
|
64
|
+
const used = systemPromptTokens + toolsTokens + messagesTokens;
|
|
65
|
+
const free = Math.max(0, window - used);
|
|
66
|
+
const breakdown = {
|
|
67
|
+
systemPrompt: systemPromptTokens,
|
|
68
|
+
tools: toolsTokens,
|
|
69
|
+
messages: messagesTokens,
|
|
70
|
+
totalUsed: used,
|
|
71
|
+
window,
|
|
72
|
+
free,
|
|
73
|
+
};
|
|
74
|
+
// Output
|
|
75
|
+
terminal.header("Context Usage");
|
|
76
|
+
terminal.table([
|
|
77
|
+
[
|
|
78
|
+
"System prompt",
|
|
79
|
+
formatNum(breakdown.systemPrompt),
|
|
80
|
+
pct(breakdown.systemPrompt, window),
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
"System tools",
|
|
84
|
+
formatNum(breakdown.tools),
|
|
85
|
+
pct(breakdown.tools, window),
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"Messages",
|
|
89
|
+
formatNum(breakdown.messages),
|
|
90
|
+
pct(breakdown.messages, window),
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
"Free space",
|
|
94
|
+
formatNum(breakdown.free),
|
|
95
|
+
pct(breakdown.free, window),
|
|
96
|
+
],
|
|
97
|
+
], { header: ["Section", "Tokens", "Percent"], colWidths: [40, 30, 30] });
|
|
98
|
+
terminal.lineBreak();
|
|
99
|
+
terminal.displayProgressBar(used, window);
|
|
100
|
+
if (args.includes("--json")) {
|
|
101
|
+
terminal.lineBreak();
|
|
102
|
+
terminal.display(JSON.stringify(breakdown, null, 2));
|
|
103
|
+
}
|
|
104
|
+
return "continue";
|
|
105
|
+
},
|
|
106
|
+
async handle(args, { tui, editor }) {
|
|
107
|
+
const meta = modelManager.getModelMetadata("repl");
|
|
108
|
+
const window = meta.contextWindow;
|
|
109
|
+
// 1) System prompt
|
|
110
|
+
const sys = await systemPrompt({
|
|
111
|
+
supportsToolCalling: meta.supportsToolCalling,
|
|
112
|
+
includeRules: true,
|
|
113
|
+
});
|
|
114
|
+
const systemPromptTokens = tokenCounter.count(sys);
|
|
115
|
+
// 2) Tools (MVP approximation)
|
|
116
|
+
let toolsTokens = 0;
|
|
117
|
+
try {
|
|
118
|
+
const tools = await initCliTools({ tokenCounter, workspace });
|
|
119
|
+
const toolDefs = tools.toolDefs;
|
|
120
|
+
const toolNames = JSON.stringify(prepareTools(toolDefs));
|
|
121
|
+
toolsTokens = tokenCounter.count(toolNames);
|
|
122
|
+
// v2: replace with exact serialized definitions
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.error(error);
|
|
126
|
+
toolsTokens = 0;
|
|
127
|
+
}
|
|
128
|
+
// 3) Messages
|
|
129
|
+
const messagesTokens = countMessageTokens(messageHistory.get(), tokenCounter);
|
|
130
|
+
// 4) Totals
|
|
131
|
+
const used = systemPromptTokens + toolsTokens + messagesTokens;
|
|
132
|
+
const free = Math.max(0, window - used);
|
|
133
|
+
const breakdown = {
|
|
134
|
+
systemPrompt: systemPromptTokens,
|
|
135
|
+
tools: toolsTokens,
|
|
136
|
+
messages: messagesTokens,
|
|
137
|
+
totalUsed: used,
|
|
138
|
+
window,
|
|
139
|
+
free,
|
|
140
|
+
};
|
|
141
|
+
// Build modal content
|
|
142
|
+
const modalContent = new Container();
|
|
143
|
+
// Context usage table
|
|
144
|
+
const tableData = [
|
|
145
|
+
[
|
|
146
|
+
"System prompt",
|
|
147
|
+
formatNum(breakdown.systemPrompt),
|
|
148
|
+
pct(breakdown.systemPrompt, window),
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
"System tools",
|
|
152
|
+
formatNum(breakdown.tools),
|
|
153
|
+
pct(breakdown.tools, window),
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"Messages",
|
|
157
|
+
formatNum(breakdown.messages),
|
|
158
|
+
pct(breakdown.messages, window),
|
|
159
|
+
],
|
|
160
|
+
["Free space", formatNum(breakdown.free), pct(breakdown.free, window)],
|
|
161
|
+
];
|
|
162
|
+
modalContent.addChild(new ModalText("Context Usage", 0, 1));
|
|
163
|
+
modalContent.addChild(new ModalTable(tableData, ["Section", "Tokens", "Percent"]));
|
|
164
|
+
// Progress bar
|
|
165
|
+
const progressBar = `[${"#".repeat(Math.floor((used / window) * 20))}${"-".repeat(20 - Math.floor((used / window) * 20))}] ${pct(used, window)}`;
|
|
166
|
+
modalContent.addChild(new ModalText("", 0, 1)); // Spacer
|
|
167
|
+
modalContent.addChild(new ModalText(progressBar, 0, 1));
|
|
168
|
+
if (args.includes("--json")) {
|
|
169
|
+
modalContent.addChild(new ModalText("", 0, 1)); // Spacer
|
|
170
|
+
modalContent.addChild(new ModalText("JSON Output:", 0, 1));
|
|
171
|
+
modalContent.addChild(new ModalText(JSON.stringify(breakdown, null, 2), 0, 1));
|
|
172
|
+
}
|
|
173
|
+
// Create and show modal
|
|
174
|
+
const modal = new Modal("Context Window Usage", modalContent, true, () => {
|
|
175
|
+
// Modal closed callback
|
|
176
|
+
editor.setText("");
|
|
177
|
+
tui.requestRender();
|
|
178
|
+
});
|
|
179
|
+
tui.showModal(modal);
|
|
180
|
+
return "continue";
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copy-command.d.ts","sourceRoot":"","sources":["../../source/commands/copy-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"copy-command.d.ts","sourceRoot":"","sources":["../../source/commands/copy-command.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAyB9D,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAsEhE"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Clipboard from "@crosscopy/clipboard";
|
|
2
|
+
import style from "../terminal/style.js";
|
|
3
|
+
import { Spacer, Text } from "../tui/index.js";
|
|
2
4
|
function extractLastAssistantText(messages) {
|
|
3
5
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
4
6
|
const msg = messages[i];
|
|
@@ -48,5 +50,31 @@ export function copyCommand(options) {
|
|
|
48
50
|
return "continue";
|
|
49
51
|
}
|
|
50
52
|
},
|
|
53
|
+
async handle(_args, { tui, container, editor, }) {
|
|
54
|
+
const { messageHistory } = options;
|
|
55
|
+
const history = messageHistory.get();
|
|
56
|
+
container.addChild(new Spacer(1));
|
|
57
|
+
const lastText = extractLastAssistantText(history);
|
|
58
|
+
if (!lastText) {
|
|
59
|
+
container.addChild(new Text(style.dim("No assistant response to copy."), 0, 1));
|
|
60
|
+
tui.requestRender();
|
|
61
|
+
editor.setText("");
|
|
62
|
+
return "continue";
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
await Clipboard.setText(lastText);
|
|
66
|
+
container.addChild(new Text(style.dim("Copied last response to clipboard."), 0, 1));
|
|
67
|
+
tui.requestRender();
|
|
68
|
+
editor.setText("");
|
|
69
|
+
return "continue";
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
73
|
+
container.addChild(new Text(style.dim(`Could not copy to clipboard: ${message}`), 0, 1));
|
|
74
|
+
tui.requestRender();
|
|
75
|
+
editor.setText("");
|
|
76
|
+
return "continue";
|
|
77
|
+
}
|
|
78
|
+
},
|
|
51
79
|
};
|
|
52
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit-command.d.ts","sourceRoot":"","sources":["../../source/commands/edit-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"edit-command.d.ts","sourceRoot":"","sources":["../../source/commands/edit-command.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,WAAW,GAAI,cAAc,cAAc,KAAG,WAoH1D,CAAC"}
|
|
@@ -2,6 +2,8 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { extname, resolve } from "node:path";
|
|
3
3
|
import { editor } from "../terminal/editor-prompt.js";
|
|
4
4
|
import { search } from "../terminal/search-prompt.js";
|
|
5
|
+
import style from "../terminal/style.js";
|
|
6
|
+
import { Text } from "../tui/index.js";
|
|
5
7
|
import { glob } from "../utils/glob.js";
|
|
6
8
|
export const editCommand = ({ terminal }) => {
|
|
7
9
|
return {
|
|
@@ -51,5 +53,36 @@ export const editCommand = ({ terminal }) => {
|
|
|
51
53
|
}
|
|
52
54
|
return "continue";
|
|
53
55
|
},
|
|
56
|
+
async handle(args, { tui, container, editor, }) {
|
|
57
|
+
let fileToEdit;
|
|
58
|
+
if (args.length > 0) {
|
|
59
|
+
// File path provided as argument
|
|
60
|
+
const filePath = args.join(" "); // Handle file paths with spaces
|
|
61
|
+
const resolvedPath = resolve(filePath);
|
|
62
|
+
if (!existsSync(resolvedPath)) {
|
|
63
|
+
container.addChild(new Text(style.red(`File not found: ${filePath}`), 0, 1));
|
|
64
|
+
tui.requestRender();
|
|
65
|
+
editor.setText("");
|
|
66
|
+
return "continue";
|
|
67
|
+
}
|
|
68
|
+
fileToEdit = filePath;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// No file path provided, show message for TUI
|
|
72
|
+
container.addChild(new Text(style.red("File path required for /edit in TUI mode"), 0, 1));
|
|
73
|
+
container.addChild(new Text(style.dim("Usage: /edit <file-path>"), 2, 0));
|
|
74
|
+
tui.requestRender();
|
|
75
|
+
editor.setText("");
|
|
76
|
+
return "continue";
|
|
77
|
+
}
|
|
78
|
+
const content = readFileSync(fileToEdit, { encoding: "utf8" });
|
|
79
|
+
// For TUI mode, we can't use the editor prompt, so we'll just show file info
|
|
80
|
+
container.addChild(new Text(`Editing file: ${style.blue(fileToEdit)}`, 0, 1));
|
|
81
|
+
container.addChild(new Text(`Content length: ${content.length} characters`, 2, 0));
|
|
82
|
+
container.addChild(new Text(style.dim("Note: Full file editing not available in TUI mode"), 3, 0));
|
|
83
|
+
tui.requestRender();
|
|
84
|
+
editor.setText("");
|
|
85
|
+
return "continue";
|
|
86
|
+
},
|
|
54
87
|
};
|
|
55
88
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit-prompt-command.d.ts","sourceRoot":"","sources":["../../source/commands/edit-prompt-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"edit-prompt-command.d.ts","sourceRoot":"","sources":["../../source/commands/edit-prompt-command.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,iBAAiB,GAAI,6CAI/B,cAAc,KAAG,WAkFnB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { syncTry } from "@travisennis/stdlib/try";
|
|
2
2
|
import { editor } from "../terminal/editor-prompt.js";
|
|
3
|
+
import style from "../terminal/style.js";
|
|
4
|
+
import { Text } from "../tui/index.js";
|
|
3
5
|
export const editPromptCommand = ({ terminal, promptManager, promptHistory, }) => {
|
|
4
6
|
return {
|
|
5
7
|
command: "/edit-prompt",
|
|
@@ -29,5 +31,31 @@ export const editPromptCommand = ({ terminal, promptManager, promptHistory, }) =
|
|
|
29
31
|
}
|
|
30
32
|
return "use";
|
|
31
33
|
},
|
|
34
|
+
async handle(args, { tui, container, editor, }) {
|
|
35
|
+
try {
|
|
36
|
+
const prompt = syncTry(() => promptManager.get());
|
|
37
|
+
const initialContent = args.length > 0 ? args.join(" ") : prompt.unwrapOr("");
|
|
38
|
+
// For TUI mode, we can't use the editor prompt, so we'll just set the prompt
|
|
39
|
+
if (initialContent.trim().length === 0) {
|
|
40
|
+
container.addChild(new Text(style.red("Prompt cannot be empty"), 0, 1));
|
|
41
|
+
tui.requestRender();
|
|
42
|
+
editor.setText("");
|
|
43
|
+
return "continue";
|
|
44
|
+
}
|
|
45
|
+
promptManager.set(initialContent);
|
|
46
|
+
// Add the edited prompt to history
|
|
47
|
+
promptHistory.push(initialContent);
|
|
48
|
+
container.addChild(new Text(`Prompt set to: ${style.blue(initialContent)}`, 0, 1));
|
|
49
|
+
tui.requestRender();
|
|
50
|
+
editor.setText("");
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
container.addChild(new Text(style.red(`Error editing prompt: ${error.message}`), 1, 0));
|
|
54
|
+
tui.requestRender();
|
|
55
|
+
editor.setText("");
|
|
56
|
+
return "continue";
|
|
57
|
+
}
|
|
58
|
+
return "use";
|
|
59
|
+
},
|
|
32
60
|
};
|
|
33
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exit-command.d.ts","sourceRoot":"","sources":["../../source/commands/exit-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exit-command.d.ts","sourceRoot":"","sources":["../../source/commands/exit-command.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE;QACd,OAAO,EAAE,MAAM,OAAO,CAAC;QACvB,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;KAC3B,CAAC;IACF,QAAQ,EAAE;QACR,KAAK,EAAE,MAAM,IAAI,CAAC;KACnB,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,eAAO,MAAM,WAAW,GAAI,wCAIzB,kBAAkB,KAAG,WAkDvB,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { logger } from "../logger.js";
|
|
3
|
+
import { Text } from "../tui/index.js";
|
|
2
4
|
import { clearDirectory } from "../utils/filesystem.js";
|
|
3
5
|
export const exitCommand = ({ messageHistory, terminal, baseDir, }) => {
|
|
4
6
|
return {
|
|
@@ -22,5 +24,23 @@ export const exitCommand = ({ messageHistory, terminal, baseDir, }) => {
|
|
|
22
24
|
}
|
|
23
25
|
return "break";
|
|
24
26
|
},
|
|
27
|
+
async handle(_args, { tui, container, editor, }) {
|
|
28
|
+
if (!messageHistory.isEmpty()) {
|
|
29
|
+
await messageHistory.save();
|
|
30
|
+
}
|
|
31
|
+
// Clear the .tmp directory on exit
|
|
32
|
+
try {
|
|
33
|
+
const tmpDirPath = path.join(baseDir ?? process.cwd(), ".tmp");
|
|
34
|
+
await clearDirectory(tmpDirPath);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// Log error but don't block exit
|
|
38
|
+
logger.error(error, "Failed to clear .tmp directory:");
|
|
39
|
+
}
|
|
40
|
+
container.addChild(new Text("Exiting...", 0, 1));
|
|
41
|
+
tui.requestRender();
|
|
42
|
+
editor.setText("");
|
|
43
|
+
return "break";
|
|
44
|
+
},
|
|
25
45
|
};
|
|
26
46
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files-command.d.ts","sourceRoot":"","sources":["../../source/commands/files-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"files-command.d.ts","sourceRoot":"","sources":["../../source/commands/files-command.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,YAAY,GAAI,4CAI1B,cAAc,KAAG,WA8KnB,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { formatFile } from "../formatting.js";
|
|
3
3
|
import { checkbox } from "../terminal/checkbox-prompt.js";
|
|
4
|
+
import style from "../terminal/style.js";
|
|
4
5
|
import { TokenCounter } from "../tokens/counter.js";
|
|
6
|
+
import { Text } from "../tui/index.js";
|
|
5
7
|
import { glob } from "../utils/glob.js";
|
|
6
8
|
export const filesCommand = ({ terminal, promptManager, modelManager, }) => {
|
|
7
9
|
return {
|
|
@@ -60,5 +62,60 @@ export const filesCommand = ({ terminal, promptManager, modelManager, }) => {
|
|
|
60
62
|
return "continue";
|
|
61
63
|
}
|
|
62
64
|
},
|
|
65
|
+
async handle(args, { tui, container, editor, }) {
|
|
66
|
+
try {
|
|
67
|
+
let workingFiles = [];
|
|
68
|
+
if (!args || args.length === 0) {
|
|
69
|
+
// Get all files in the current directory
|
|
70
|
+
const foundFiles = await glob("**/*", { gitignore: true });
|
|
71
|
+
// For TUI mode, we'll just use the first few files
|
|
72
|
+
workingFiles = foundFiles.slice(0, 5);
|
|
73
|
+
if (workingFiles.length === 0) {
|
|
74
|
+
container.addChild(new Text(style.yellow("No files found"), 0, 1));
|
|
75
|
+
tui.requestRender();
|
|
76
|
+
editor.setText("");
|
|
77
|
+
return "continue";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const patternList = args.filter(Boolean);
|
|
82
|
+
const foundFiles = await glob(patternList, { gitignore: true });
|
|
83
|
+
if (foundFiles.length === 0) {
|
|
84
|
+
container.addChild(new Text(style.yellow("No files found matching the pattern(s)"), 1, 0));
|
|
85
|
+
tui.requestRender();
|
|
86
|
+
editor.setText("");
|
|
87
|
+
return "continue";
|
|
88
|
+
}
|
|
89
|
+
// Process the selected files
|
|
90
|
+
workingFiles = foundFiles;
|
|
91
|
+
}
|
|
92
|
+
// Read the content of the files and format them for the next prompt
|
|
93
|
+
const format = modelManager.getModelMetadata("repl").promptFormat;
|
|
94
|
+
let tokenCount = 0;
|
|
95
|
+
const tokenCounter = new TokenCounter();
|
|
96
|
+
await Promise.all(workingFiles.map(async (filePath) => {
|
|
97
|
+
try {
|
|
98
|
+
const content = await readFile(filePath, "utf-8");
|
|
99
|
+
const formattedFile = formatFile(filePath, content, format);
|
|
100
|
+
tokenCount += tokenCounter.count(formattedFile);
|
|
101
|
+
promptManager.addContext(formattedFile);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
container.addChild(new Text(style.red(`Error reading file ${filePath}: ${error.message}`), 1, 0));
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
tokenCounter.free();
|
|
108
|
+
container.addChild(new Text(style.green(`File contents will be added to your next prompt (${workingFiles.length} files, ${tokenCount} tokens)`), 1, 0));
|
|
109
|
+
tui.requestRender();
|
|
110
|
+
editor.setText("");
|
|
111
|
+
return "continue";
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
container.addChild(new Text(style.red(`Error processing file patterns: ${error.message}`), 1, 0));
|
|
115
|
+
tui.requestRender();
|
|
116
|
+
editor.setText("");
|
|
117
|
+
return "continue";
|
|
118
|
+
}
|
|
119
|
+
},
|
|
63
120
|
};
|
|
64
121
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-rules-command.d.ts","sourceRoot":"","sources":["../../source/commands/generate-rules-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-rules-command.d.ts","sourceRoot":"","sources":["../../source/commands/generate-rules-command.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAuC9D,eAAO,MAAM,oBAAoB,GAAI,mEAMlC,cAAc,KAAG,WA6JnB,CAAC"}
|