@travisennis/acai 0.0.1 → 0.0.3
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 +3 -4
- package/dist/commands/health-command.d.ts +2 -0
- package/dist/commands/health-command.js +59 -0
- package/dist/commands/manager.js +2 -0
- package/dist/commands/paste-command.d.ts +1 -1
- package/dist/commands/paste-command.js +155 -11
- package/dist/commands/reset-command.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/models/openrouter-provider.d.ts +4 -1
- package/dist/models/openrouter-provider.js +46 -4
- package/dist/models/providers.d.ts +1 -1
- package/dist/prompts/manager.d.ts +1 -0
- package/dist/prompts/manager.js +10 -0
- package/dist/prompts.js +8 -6
- package/dist/repl.js +49 -26
- package/dist/terminal/formatting.d.ts +16 -5
- package/dist/terminal/formatting.js +40 -6
- package/dist/terminal/index.d.ts +1 -1
- package/dist/terminal/index.js +54 -14
- package/dist/terminal/markdown.js +0 -1
- package/dist/terminal/supports-color.d.ts +16 -0
- package/dist/terminal/supports-color.js +121 -0
- package/dist/terminal/supports-hyperlinks.d.ts +7 -0
- package/dist/terminal/supports-hyperlinks.js +98 -0
- package/dist/tools/bash.js +95 -117
- package/dist/tools/code-interpreter.js +11 -1
- package/dist/tools/command-validation.d.ts +7 -3
- package/dist/tools/command-validation.js +67 -23
- package/dist/tools/delete-file.d.ts +4 -1
- package/dist/tools/delete-file.js +47 -3
- package/dist/tools/git-utils.d.ts +6 -0
- package/dist/tools/git-utils.js +89 -12
- package/dist/tools/grep.d.ts +20 -0
- package/dist/tools/grep.js +128 -40
- package/dist/tools/index.d.ts +2 -18
- package/dist/tools/index.js +4 -18
- package/package.json +30 -20
- package/.acai/acai.json +0 -9
- package/.acai/prompts/add-openrouter-model.md +0 -13
- package/.acai/prompts/project-status.md +0 -4
- package/.acai/prompts/update-architecture-document.md +0 -9
- package/.acai/rules/learned-rules.md +0 -9
- package/.ai/docs/available-tools.txt +0 -3
- package/.ai/docs/cognitive_complexity_refactoring_progress.md +0 -65
- package/.ai/docs/deleted_tools.md +0 -168
- package/.ai/docs/deleted_tools_88ced9ef.md +0 -56
- package/.ai/docs/image-pasting.md +0 -46
- package/.ai/docs/initialize-app.md +0 -117
- package/.ai/docs/issue-4-plan.md +0 -44
- package/.ai/docs/marked-renderer-debug.md +0 -15
- package/.ai/docs/marked-renderer-refactor-plan.md +0 -64
- package/.ai/docs/memory-use-cases.md +0 -55
- package/.ai/docs/prompt-consistency.md +0 -31
- package/.ai/docs/refactoring-tools.md +0 -98
- package/.ai/docs/system-prompt-update.md +0 -174
- package/.ai/docs/system_prompt.txt +0 -210
- package/.ai/docs/tasks.md +0 -49
- package/.ai/plan.md +0 -131
- package/.ai/prompt.md +0 -1
- package/.ai/scripts/fetch_models.js +0 -27
- package/.ai/scripts/generateSystemPrompt.ts +0 -15
- package/.ai/scripts/list-tools.mjs +0 -4
- package/.ai/scripts/p5_geometric_shapes.js +0 -149
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -3
- package/.husky/pre-push +0 -1
- package/.ignore +0 -4
- package/AGENTS.md +0 -25
- package/ARCHITECTURE.md +0 -304
- package/TODO.md +0 -2
- package/biome.json +0 -61
- package/commitlint.config.js +0 -3
- package/dist/source/cli.d.ts +0 -19
- package/dist/source/cli.js +0 -116
- package/dist/source/commands/application-log-command.d.ts +0 -2
- package/dist/source/commands/application-log-command.js +0 -43
- package/dist/source/commands/clear-command.d.ts +0 -2
- package/dist/source/commands/clear-command.js +0 -12
- package/dist/source/commands/compact-command.d.ts +0 -2
- package/dist/source/commands/compact-command.js +0 -51
- package/dist/source/commands/copy-command.d.ts +0 -2
- package/dist/source/commands/copy-command.js +0 -51
- package/dist/source/commands/edit-command.d.ts +0 -2
- package/dist/source/commands/edit-command.js +0 -53
- package/dist/source/commands/edit-prompt-command.d.ts +0 -2
- package/dist/source/commands/edit-prompt-command.js +0 -25
- package/dist/source/commands/exit-command.d.ts +0 -2
- package/dist/source/commands/exit-command.js +0 -14
- package/dist/source/commands/files-command.d.ts +0 -2
- package/dist/source/commands/files-command.js +0 -63
- package/dist/source/commands/generate-rules-command.d.ts +0 -2
- package/dist/source/commands/generate-rules-command.js +0 -61
- package/dist/source/commands/help-command.d.ts +0 -2
- package/dist/source/commands/help-command.js +0 -19
- package/dist/source/commands/init-command.d.ts +0 -2
- package/dist/source/commands/init-command.js +0 -40
- package/dist/source/commands/last-log-command.d.ts +0 -2
- package/dist/source/commands/last-log-command.js +0 -76
- package/dist/source/commands/manager.d.ts +0 -22
- package/dist/source/commands/manager.js +0 -123
- package/dist/source/commands/model-command.d.ts +0 -2
- package/dist/source/commands/model-command.js +0 -84
- package/dist/source/commands/paste-command.d.ts +0 -2
- package/dist/source/commands/paste-command.js +0 -40
- package/dist/source/commands/prompt-command.d.ts +0 -2
- package/dist/source/commands/prompt-command.js +0 -111
- package/dist/source/commands/reset-command.d.ts +0 -2
- package/dist/source/commands/reset-command.js +0 -16
- package/dist/source/commands/rules-command.d.ts +0 -2
- package/dist/source/commands/rules-command.js +0 -68
- package/dist/source/commands/save-command.d.ts +0 -2
- package/dist/source/commands/save-command.js +0 -14
- package/dist/source/commands/types.d.ts +0 -26
- package/dist/source/commands/types.js +0 -1
- package/dist/source/commands/usage-command.d.ts +0 -2
- package/dist/source/commands/usage-command.js +0 -21
- package/dist/source/config.d.ts +0 -60
- package/dist/source/config.js +0 -193
- package/dist/source/conversation-analyzer.d.ts +0 -10
- package/dist/source/conversation-analyzer.js +0 -88
- package/dist/source/dedent.d.ts +0 -3
- package/dist/source/dedent.js +0 -38
- package/dist/source/formatting.d.ts +0 -17
- package/dist/source/formatting.js +0 -103
- package/dist/source/index.d.ts +0 -18
- package/dist/source/index.js +0 -213
- package/dist/source/logger.d.ts +0 -2
- package/dist/source/logger.js +0 -24
- package/dist/source/mentions.d.ts +0 -9
- package/dist/source/mentions.js +0 -182
- package/dist/source/messages.d.ts +0 -69
- package/dist/source/messages.js +0 -261
- package/dist/source/middleware/audit-message.d.ts +0 -5
- package/dist/source/middleware/audit-message.js +0 -95
- package/dist/source/middleware/index.d.ts +0 -2
- package/dist/source/middleware/index.js +0 -2
- package/dist/source/middleware/rate-limit.d.ts +0 -4
- package/dist/source/middleware/rate-limit.js +0 -17
- package/dist/source/models/ai-config.d.ts +0 -12
- package/dist/source/models/ai-config.js +0 -87
- package/dist/source/models/anthropic-provider.d.ts +0 -25
- package/dist/source/models/anthropic-provider.js +0 -184
- package/dist/source/models/deepseek-provider.d.ts +0 -20
- package/dist/source/models/deepseek-provider.js +0 -42
- package/dist/source/models/google-provider.d.ts +0 -19
- package/dist/source/models/google-provider.js +0 -56
- package/dist/source/models/manager.d.ts +0 -15
- package/dist/source/models/manager.js +0 -48
- package/dist/source/models/openai-provider.d.ts +0 -22
- package/dist/source/models/openai-provider.js +0 -70
- package/dist/source/models/openrouter-provider.d.ts +0 -36
- package/dist/source/models/openrouter-provider.js +0 -276
- package/dist/source/models/providers.d.ts +0 -33
- package/dist/source/models/providers.js +0 -116
- package/dist/source/models/xai-provider.d.ts +0 -20
- package/dist/source/models/xai-provider.js +0 -47
- package/dist/source/parsing.d.ts +0 -2
- package/dist/source/parsing.js +0 -18
- package/dist/source/prompts/manager.d.ts +0 -19
- package/dist/source/prompts/manager.js +0 -71
- package/dist/source/prompts.d.ts +0 -4
- package/dist/source/prompts.js +0 -158
- package/dist/source/repl-prompt.d.ts +0 -14
- package/dist/source/repl-prompt.js +0 -147
- package/dist/source/repl.d.ts +0 -27
- package/dist/source/repl.js +0 -431
- package/dist/source/terminal/formatting.d.ts +0 -37
- package/dist/source/terminal/formatting.js +0 -106
- package/dist/source/terminal/index.d.ts +0 -94
- package/dist/source/terminal/index.js +0 -420
- package/dist/source/terminal/markdown-utils.d.ts +0 -2
- package/dist/source/terminal/markdown-utils.js +0 -81
- package/dist/source/terminal/markdown.d.ts +0 -1
- package/dist/source/terminal/markdown.js +0 -111
- package/dist/source/terminal/types.d.ts +0 -71
- package/dist/source/terminal/types.js +0 -1
- package/dist/source/terminal-output.d.ts +0 -8
- package/dist/source/terminal-output.js +0 -213
- package/dist/source/terminal-output.test.d.ts +0 -8
- package/dist/source/terminal-output.test.js +0 -213
- package/dist/source/token-tracker.d.ts +0 -14
- package/dist/source/token-tracker.js +0 -53
- package/dist/source/token-utils.d.ts +0 -7
- package/dist/source/token-utils.js +0 -13
- package/dist/source/tools/agent.d.ts +0 -17
- package/dist/source/tools/agent.js +0 -87
- package/dist/source/tools/bash.d.ts +0 -19
- package/dist/source/tools/bash.js +0 -294
- package/dist/source/tools/code-interpreter.d.ts +0 -12
- package/dist/source/tools/code-interpreter.js +0 -131
- package/dist/source/tools/command-validation.d.ts +0 -8
- package/dist/source/tools/command-validation.js +0 -69
- package/dist/source/tools/delete-file.d.ts +0 -12
- package/dist/source/tools/delete-file.js +0 -56
- package/dist/source/tools/directory-tree.d.ts +0 -12
- package/dist/source/tools/directory-tree.js +0 -38
- package/dist/source/tools/edit-file.d.ts +0 -19
- package/dist/source/tools/edit-file.js +0 -107
- package/dist/source/tools/filesystem-utils.d.ts +0 -22
- package/dist/source/tools/filesystem-utils.js +0 -191
- package/dist/source/tools/git-utils.d.ts +0 -14
- package/dist/source/tools/git-utils.js +0 -64
- package/dist/source/tools/grep.d.ts +0 -17
- package/dist/source/tools/grep.js +0 -138
- package/dist/source/tools/index.d.ts +0 -161
- package/dist/source/tools/index.js +0 -209
- package/dist/source/tools/memory-read.d.ts +0 -13
- package/dist/source/tools/memory-read.js +0 -135
- package/dist/source/tools/memory-write.d.ts +0 -12
- package/dist/source/tools/memory-write.js +0 -83
- package/dist/source/tools/move-file.d.ts +0 -13
- package/dist/source/tools/move-file.js +0 -44
- package/dist/source/tools/read-file.d.ts +0 -17
- package/dist/source/tools/read-file.js +0 -86
- package/dist/source/tools/read-multiple-files.d.ts +0 -14
- package/dist/source/tools/read-multiple-files.js +0 -55
- package/dist/source/tools/save-file.d.ts +0 -17
- package/dist/source/tools/save-file.js +0 -98
- package/dist/source/tools/think.d.ts +0 -11
- package/dist/source/tools/think.js +0 -45
- package/dist/source/tools/types.d.ts +0 -29
- package/dist/source/tools/types.js +0 -14
- package/dist/source/tools/web-fetch.d.ts +0 -47
- package/dist/source/tools/web-fetch.js +0 -246
- package/dist/source/tools/web-search.d.ts +0 -13
- package/dist/source/tools/web-search.js +0 -80
- package/dist/source/utils/process.d.ts +0 -36
- package/dist/source/utils/process.js +0 -75
- package/dist/source/version.d.ts +0 -1
- package/dist/source/version.js +0 -21
- package/dist/terminal-output.d.ts +0 -8
- package/dist/terminal-output.js +0 -213
- package/dist/tools/memory-read.d.ts +0 -13
- package/dist/tools/memory-read.js +0 -135
- package/dist/tools/memory-write.d.ts +0 -12
- package/dist/tools/memory-write.js +0 -83
- package/knip.json +0 -5
- package/source/cli.ts +0 -172
- package/source/commands/application-log-command.ts +0 -53
- package/source/commands/clear-command.ts +0 -14
- package/source/commands/compact-command.ts +0 -64
- package/source/commands/copy-command.ts +0 -55
- package/source/commands/edit-command.ts +0 -63
- package/source/commands/edit-prompt-command.ts +0 -31
- package/source/commands/exit-command.ts +0 -18
- package/source/commands/files-command.ts +0 -85
- package/source/commands/generate-rules-command.ts +0 -82
- package/source/commands/help-command.ts +0 -27
- package/source/commands/init-command.ts +0 -48
- package/source/commands/last-log-command.ts +0 -88
- package/source/commands/manager.ts +0 -151
- package/source/commands/model-command.ts +0 -123
- package/source/commands/paste-command.ts +0 -62
- package/source/commands/prompt-command.ts +0 -150
- package/source/commands/reset-command.ts +0 -22
- package/source/commands/rules-command.ts +0 -76
- package/source/commands/save-command.ts +0 -20
- package/source/commands/types.ts +0 -28
- package/source/commands/usage-command.ts +0 -26
- package/source/config.ts +0 -223
- package/source/conversation-analyzer.ts +0 -115
- package/source/dedent.ts +0 -53
- package/source/formatting.ts +0 -132
- package/source/index.ts +0 -240
- package/source/logger.ts +0 -29
- package/source/mentions.ts +0 -227
- package/source/messages.ts +0 -360
- package/source/middleware/audit-message.ts +0 -133
- package/source/middleware/index.ts +0 -2
- package/source/middleware/rate-limit.ts +0 -24
- package/source/models/ai-config.ts +0 -109
- package/source/models/anthropic-provider.ts +0 -199
- package/source/models/deepseek-provider.ts +0 -53
- package/source/models/google-provider.ts +0 -68
- package/source/models/manager.ts +0 -84
- package/source/models/openai-provider.ts +0 -81
- package/source/models/openrouter-provider.ts +0 -288
- package/source/models/providers.ts +0 -197
- package/source/models/xai-provider.ts +0 -59
- package/source/parsing.ts +0 -20
- package/source/prompts/manager.ts +0 -90
- package/source/prompts.ts +0 -172
- package/source/repl-prompt.ts +0 -196
- package/source/repl.ts +0 -572
- package/source/terminal/formatting.ts +0 -121
- package/source/terminal/index.ts +0 -518
- package/source/terminal/markdown-utils.ts +0 -89
- package/source/terminal/markdown.ts +0 -155
- package/source/terminal/types.ts +0 -84
- package/source/terminal-output.test.ts +0 -266
- package/source/token-tracker.ts +0 -78
- package/source/token-utils.ts +0 -17
- package/source/tools/agent.ts +0 -107
- package/source/tools/bash.ts +0 -367
- package/source/tools/code-interpreter.ts +0 -172
- package/source/tools/command-validation.ts +0 -81
- package/source/tools/delete-file.ts +0 -71
- package/source/tools/directory-tree.ts +0 -54
- package/source/tools/edit-file.ts +0 -155
- package/source/tools/filesystem-utils.ts +0 -265
- package/source/tools/git-utils.ts +0 -70
- package/source/tools/grep.ts +0 -184
- package/source/tools/index.ts +0 -278
- package/source/tools/memory-read.ts +0 -174
- package/source/tools/memory-write.ts +0 -105
- package/source/tools/move-file.ts +0 -59
- package/source/tools/read-file.ts +0 -129
- package/source/tools/read-multiple-files.ts +0 -80
- package/source/tools/save-file.ts +0 -147
- package/source/tools/think.ts +0 -51
- package/source/tools/types.ts +0 -58
- package/source/tools/web-fetch.ts +0 -327
- package/source/tools/web-search.ts +0 -101
- package/source/utils/process.ts +0 -121
- package/source/version.ts +0 -21
- package/test/commands/copy-command.test.ts +0 -69
- package/test/config.test.ts +0 -200
- package/test/terminal/markdown-utils.test.ts +0 -124
- package/test/tools/bash-tool.test.ts +0 -58
- package/test/tools/code-interpreter.test.ts +0 -91
- package/test/tools/command-validation.test.ts +0 -48
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -30
package/dist/source/index.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { text } from "node:stream/consumers";
|
|
2
|
-
import { parseArgs } from "node:util";
|
|
3
|
-
import { select } from "@inquirer/prompts";
|
|
4
|
-
import { asyncTry } from "@travisennis/stdlib/try";
|
|
5
|
-
import { isDefined } from "@travisennis/stdlib/typeguards";
|
|
6
|
-
import { Cli } from "./cli.js";
|
|
7
|
-
import { CommandManager } from "./commands/manager.js";
|
|
8
|
-
import { config } from "./config.js";
|
|
9
|
-
import { logger } from "./logger.js";
|
|
10
|
-
import { MessageHistory } from "./messages.js";
|
|
11
|
-
import { ModelManager } from "./models/manager.js";
|
|
12
|
-
import { isSupportedModel } from "./models/providers.js";
|
|
13
|
-
import { PromptManager } from "./prompts/manager.js";
|
|
14
|
-
import { Repl } from "./repl.js";
|
|
15
|
-
import { initTerminal } from "./terminal/index.js";
|
|
16
|
-
import { TokenTracker } from "./token-tracker.js";
|
|
17
|
-
import { TokenCounter } from "./token-utils.js";
|
|
18
|
-
import { getPackageVersion } from "./version.js";
|
|
19
|
-
const helpText = `
|
|
20
|
-
Usage
|
|
21
|
-
$ acai <input>
|
|
22
|
-
|
|
23
|
-
Options
|
|
24
|
-
--model, -m Sets the model to use
|
|
25
|
-
--prompt, -p Sets the prompt
|
|
26
|
-
--oneshot, -o Run once and exit
|
|
27
|
-
--continue Load the most recent conversation
|
|
28
|
-
--resume Select a recent conversation to resume
|
|
29
|
-
--autoAcceptAll Accept all commands and edits without prompting
|
|
30
|
-
--help, -h Show help
|
|
31
|
-
--version, -v Show version
|
|
32
|
-
|
|
33
|
-
Examples
|
|
34
|
-
$ acai --model anthopric:sonnet
|
|
35
|
-
$ acai -p "initial prompt"
|
|
36
|
-
$ acai -p "one-shot prompt" -o
|
|
37
|
-
`;
|
|
38
|
-
const parsed = parseArgs({
|
|
39
|
-
options: {
|
|
40
|
-
model: { type: "string", short: "m" },
|
|
41
|
-
prompt: { type: "string", short: "p" },
|
|
42
|
-
oneshot: { type: "boolean", short: "o", default: false },
|
|
43
|
-
continue: { type: "boolean", default: false },
|
|
44
|
-
resume: { type: "boolean", default: false },
|
|
45
|
-
autoAcceptAll: { type: "boolean", default: false },
|
|
46
|
-
help: { type: "boolean", short: "h" },
|
|
47
|
-
version: { type: "boolean", short: "v" },
|
|
48
|
-
},
|
|
49
|
-
allowPositionals: true,
|
|
50
|
-
});
|
|
51
|
-
const flags = parsed.values;
|
|
52
|
-
const input = parsed.positionals;
|
|
53
|
-
/**
|
|
54
|
-
* Global error handler function.
|
|
55
|
-
* @param {Error} error - The error to be handled.
|
|
56
|
-
* @throws {Error} Rethrows the error after logging it.
|
|
57
|
-
*/
|
|
58
|
-
export function handleError(error) {
|
|
59
|
-
logger.error({ error: error }, error.message);
|
|
60
|
-
}
|
|
61
|
-
async function main() {
|
|
62
|
-
const appConfig = await config.ensureAppConfig("acai");
|
|
63
|
-
if (flags.version === true) {
|
|
64
|
-
console.info(getPackageVersion());
|
|
65
|
-
process.exit(0);
|
|
66
|
-
}
|
|
67
|
-
if (flags.help === true) {
|
|
68
|
-
console.info(helpText);
|
|
69
|
-
process.exit(0);
|
|
70
|
-
}
|
|
71
|
-
const appDir = config.app;
|
|
72
|
-
const messageHistoryDir = await appDir.ensurePath("message-history");
|
|
73
|
-
// --- Argument Validation ---
|
|
74
|
-
if (flags.continue === true && flags.resume === true) {
|
|
75
|
-
console.error("Cannot use --continue and --resume flags together.");
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
const hasContinueOrResume = flags.continue === true || flags.resume === true;
|
|
79
|
-
if (hasContinueOrResume && flags.oneshot === true) {
|
|
80
|
-
console.error("Cannot use --continue or --resume with --oneshot.");
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
// --- Determine Initial Prompt (potential conflict) ---
|
|
84
|
-
const positionalPrompt = input.at(0);
|
|
85
|
-
let stdInPrompt;
|
|
86
|
-
// Check if there's data available on stdin
|
|
87
|
-
if (!process.stdin.isTTY) {
|
|
88
|
-
try {
|
|
89
|
-
// Non-TTY stdin means data is being piped in
|
|
90
|
-
stdInPrompt = await text(process.stdin);
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.error(`Error reading stdin: ${error.message}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const initialPromptInput = typeof flags.prompt === "string" && flags.prompt.length > 0
|
|
97
|
-
? flags.prompt
|
|
98
|
-
: positionalPrompt && positionalPrompt.length > 0
|
|
99
|
-
? positionalPrompt
|
|
100
|
-
: undefined;
|
|
101
|
-
if (hasContinueOrResume && isDefined(initialPromptInput)) {
|
|
102
|
-
console.error("Cannot use --continue or --resume with an initial prompt.");
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
const terminal = initTerminal();
|
|
106
|
-
terminal.setTitle(`acai: ${process.cwd()}`);
|
|
107
|
-
const chosenModel = isSupportedModel(flags.model)
|
|
108
|
-
? flags.model
|
|
109
|
-
: "openrouter:sonnet4";
|
|
110
|
-
const modelManager = new ModelManager({
|
|
111
|
-
stateDir: await appDir.ensurePath("audit"),
|
|
112
|
-
});
|
|
113
|
-
modelManager.setModel("repl", chosenModel);
|
|
114
|
-
modelManager.setModel("cli", chosenModel);
|
|
115
|
-
modelManager.setModel("title-conversation", "openrouter:gemini-flash25");
|
|
116
|
-
modelManager.setModel("conversation-summarizer", "openrouter:gemini-flash25");
|
|
117
|
-
modelManager.setModel("tool-repair", "openai:gpt-4.1");
|
|
118
|
-
modelManager.setModel("conversation-analyzer", "openrouter:gemini-flash25");
|
|
119
|
-
modelManager.setModel("init-project", chosenModel);
|
|
120
|
-
modelManager.setModel("task-agent", "openrouter:gemini-flash25");
|
|
121
|
-
const tokenTracker = new TokenTracker();
|
|
122
|
-
const tokenCounter = new TokenCounter();
|
|
123
|
-
const messageHistory = new MessageHistory({
|
|
124
|
-
stateDir: messageHistoryDir,
|
|
125
|
-
modelManager,
|
|
126
|
-
tokenTracker,
|
|
127
|
-
});
|
|
128
|
-
messageHistory.on("update-title", (title) => terminal.setTitle(title));
|
|
129
|
-
if (flags.continue === true) {
|
|
130
|
-
const histories = await MessageHistory.load(messageHistoryDir, 1);
|
|
131
|
-
const latestHistory = histories.at(0);
|
|
132
|
-
if (latestHistory) {
|
|
133
|
-
messageHistory.restore(latestHistory);
|
|
134
|
-
console.info(`Resuming conversation: ${latestHistory.title}`);
|
|
135
|
-
// Set terminal title after restoring
|
|
136
|
-
terminal.setTitle(latestHistory.title || `acai: ${process.cwd()}`);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
logger.info("No previous conversation found to continue.");
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else if (flags.resume === true) {
|
|
143
|
-
const histories = await MessageHistory.load(messageHistoryDir, 10);
|
|
144
|
-
if (histories.length > 0) {
|
|
145
|
-
const choice = await select({
|
|
146
|
-
message: "Select a conversation to resume:",
|
|
147
|
-
choices: histories.map((h, index) => ({
|
|
148
|
-
name: `${index + 1}: ${h.title} (${h.updatedAt.toLocaleString()})`,
|
|
149
|
-
value: index,
|
|
150
|
-
description: `${h.messages.length} messages`,
|
|
151
|
-
})),
|
|
152
|
-
});
|
|
153
|
-
const selectedHistory = histories.at(choice);
|
|
154
|
-
if (selectedHistory) {
|
|
155
|
-
messageHistory.restore(selectedHistory);
|
|
156
|
-
logger.info(`Resuming conversation: ${selectedHistory.title}`);
|
|
157
|
-
// Set terminal title after restoring
|
|
158
|
-
terminal.setTitle(selectedHistory.title || `acai: ${process.cwd()}`);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
// This case should theoretically not happen if choice is valid
|
|
162
|
-
logger.error("Selected history index out of bounds.");
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
logger.info("No previous conversations found to resume.");
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
// --- Setup Prompt Manager (only if not continuing/resuming) ---
|
|
170
|
-
const promptManager = new PromptManager(tokenCounter);
|
|
171
|
-
if (!hasContinueOrResume && isDefined(initialPromptInput)) {
|
|
172
|
-
promptManager.set(initialPromptInput);
|
|
173
|
-
}
|
|
174
|
-
if (stdInPrompt) {
|
|
175
|
-
promptManager.addContext(stdInPrompt);
|
|
176
|
-
}
|
|
177
|
-
const toolEvents = new Map();
|
|
178
|
-
const commands = new CommandManager({
|
|
179
|
-
promptManager,
|
|
180
|
-
modelManager,
|
|
181
|
-
terminal,
|
|
182
|
-
messageHistory,
|
|
183
|
-
tokenTracker,
|
|
184
|
-
config,
|
|
185
|
-
tokenCounter,
|
|
186
|
-
toolEvents,
|
|
187
|
-
});
|
|
188
|
-
if (flags.oneshot === true) {
|
|
189
|
-
const cliProcess = new Cli({
|
|
190
|
-
promptManager,
|
|
191
|
-
config: appConfig,
|
|
192
|
-
messageHistory,
|
|
193
|
-
modelManager,
|
|
194
|
-
tokenTracker,
|
|
195
|
-
tokenCounter,
|
|
196
|
-
});
|
|
197
|
-
return (await asyncTry(cliProcess.run())).recover(handleError);
|
|
198
|
-
}
|
|
199
|
-
const repl = new Repl({
|
|
200
|
-
promptManager,
|
|
201
|
-
terminal,
|
|
202
|
-
config: appConfig,
|
|
203
|
-
messageHistory,
|
|
204
|
-
modelManager,
|
|
205
|
-
tokenTracker,
|
|
206
|
-
commands,
|
|
207
|
-
tokenCounter,
|
|
208
|
-
toolEvents,
|
|
209
|
-
autoAcceptAll: flags.autoAcceptAll === true,
|
|
210
|
-
});
|
|
211
|
-
return (await asyncTry(repl.run())).recover(handleError);
|
|
212
|
-
}
|
|
213
|
-
main();
|
package/dist/source/logger.d.ts
DELETED
package/dist/source/logger.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import pino from "pino";
|
|
3
|
-
import { config } from "./config.js";
|
|
4
|
-
const transport = pino.transport({
|
|
5
|
-
target: "pino-roll",
|
|
6
|
-
options: {
|
|
7
|
-
file: join(config.app.ensurePathSync("logs"), "acai.log"),
|
|
8
|
-
size: "10m",
|
|
9
|
-
symlink: true,
|
|
10
|
-
limit: {
|
|
11
|
-
count: 3,
|
|
12
|
-
},
|
|
13
|
-
mkdir: true,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
export const logger = pino({
|
|
17
|
-
level: process.env["LOG_LEVEL"] ?? "debug",
|
|
18
|
-
formatters: {
|
|
19
|
-
level: (label) => {
|
|
20
|
-
return { level: label.toUpperCase() };
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
timestamp: pino.stdTimeFunctions.isoTime,
|
|
24
|
-
}, transport);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ModelMetadata } from "./models/providers.ts";
|
|
2
|
-
import type { ContextItem } from "./prompts/manager.ts";
|
|
3
|
-
export declare function processPrompt(message: string, { baseDir, model }: {
|
|
4
|
-
baseDir: string;
|
|
5
|
-
model: ModelMetadata;
|
|
6
|
-
}): Promise<{
|
|
7
|
-
message: string;
|
|
8
|
-
context: ContextItem[];
|
|
9
|
-
}>;
|
package/dist/source/mentions.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { isString } from "@travisennis/stdlib/typeguards";
|
|
4
|
-
import { formatFile, formatUrl } from "./formatting.js";
|
|
5
|
-
import { readUrl } from "./tools/web-fetch.js";
|
|
6
|
-
import { executeCommand } from "./utils/process.js";
|
|
7
|
-
// Helper function to recursively read all files in a directory
|
|
8
|
-
async function readDirectoryRecursive(dirPath, format) {
|
|
9
|
-
const allContents = [];
|
|
10
|
-
async function readDir(currentPath, relativePath = "") {
|
|
11
|
-
const entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
12
|
-
for (const entry of entries) {
|
|
13
|
-
const fullPath = path.join(currentPath, entry.name);
|
|
14
|
-
const relativeFilePath = path.join(relativePath, entry.name);
|
|
15
|
-
if (entry.isDirectory()) {
|
|
16
|
-
await readDir(fullPath, relativeFilePath);
|
|
17
|
-
}
|
|
18
|
-
else if (entry.isFile()) {
|
|
19
|
-
try {
|
|
20
|
-
const fileContents = await fs.readFile(fullPath, "utf8");
|
|
21
|
-
allContents.push(formatFile(relativeFilePath, fileContents, format));
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
allContents.push(`Error reading file ${relativeFilePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
await readDir(dirPath);
|
|
30
|
-
if (allContents.length === 0) {
|
|
31
|
-
return `Directory ${path.basename(dirPath)} is empty or contains no readable files.`;
|
|
32
|
-
}
|
|
33
|
-
return allContents.join("\n\n");
|
|
34
|
-
}
|
|
35
|
-
// Returns the formatted string or an error message string
|
|
36
|
-
async function processFileCommand(context) {
|
|
37
|
-
const { baseDir, match } = context;
|
|
38
|
-
const filePath = match.trim();
|
|
39
|
-
const format = context.model.promptFormat;
|
|
40
|
-
try {
|
|
41
|
-
// Resolve paths to absolute to prevent traversal issues
|
|
42
|
-
const resolvedBaseDir = path.resolve(baseDir);
|
|
43
|
-
const resolvedFilePath = path.resolve(resolvedBaseDir, filePath);
|
|
44
|
-
// Security Check: Ensure the resolved path is still within the base directory
|
|
45
|
-
if (!resolvedFilePath.startsWith(resolvedBaseDir + path.sep)) {
|
|
46
|
-
return `Error: Access denied. Attempted to read file outside the allowed directory: ${filePath}`;
|
|
47
|
-
}
|
|
48
|
-
// Check if path exists
|
|
49
|
-
const stats = await fs.stat(resolvedFilePath);
|
|
50
|
-
// If it's a directory, read all files recursively
|
|
51
|
-
if (stats.isDirectory()) {
|
|
52
|
-
return await readDirectoryRecursive(resolvedFilePath, format);
|
|
53
|
-
}
|
|
54
|
-
// If it's a file, process as before
|
|
55
|
-
if (stats.isFile()) {
|
|
56
|
-
const fileContents = await fs.readFile(resolvedFilePath, "utf8");
|
|
57
|
-
return formatFile(filePath, fileContents, format);
|
|
58
|
-
}
|
|
59
|
-
return `Error: ${filePath} is neither a regular file nor directory.`;
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
// Handle both ENOENT (file not found) and permission errors
|
|
63
|
-
if (error && typeof error === "object" && "code" in error) {
|
|
64
|
-
if (error.code === "ENOENT") {
|
|
65
|
-
return `Error: File or directory not found: ${filePath}\nPlease check that the path is correct and exists.`;
|
|
66
|
-
}
|
|
67
|
-
if (error.code === "EACCES") {
|
|
68
|
-
return `Error: Permission denied accessing: ${filePath}`;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (error instanceof Error) {
|
|
72
|
-
return `Error accessing ${filePath}: ${error.message}`;
|
|
73
|
-
}
|
|
74
|
-
// Fallback for unknown error types
|
|
75
|
-
return `Error accessing ${filePath}: An unknown error occurred.`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async function processShellCommand(command) {
|
|
79
|
-
try {
|
|
80
|
-
const { stdout, stderr, code } = await executeCommand(command, {
|
|
81
|
-
shell: true,
|
|
82
|
-
});
|
|
83
|
-
if (code === 0) {
|
|
84
|
-
return stdout;
|
|
85
|
-
}
|
|
86
|
-
return `Error executing command: ${command}\n${stderr}`;
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
if (error instanceof Error) {
|
|
90
|
-
return `Error executing command ${command}: ${error.message}`;
|
|
91
|
-
}
|
|
92
|
-
return `Error executing command ${command}: An unknown error occurred.`;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// Returns the formatted string or an error message string
|
|
96
|
-
async function processUrlCommand(context) {
|
|
97
|
-
const { match } = context;
|
|
98
|
-
const urlPath = match;
|
|
99
|
-
try {
|
|
100
|
-
return Object.assign(await readUrl(urlPath), { source: urlPath });
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
if (error instanceof Error) {
|
|
104
|
-
return {
|
|
105
|
-
contentType: "text/plain",
|
|
106
|
-
data: `Url: ${urlPath} Status: Error fetching URL: ${error.message}`,
|
|
107
|
-
source: urlPath,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
// Fallback for unknown error types
|
|
111
|
-
return {
|
|
112
|
-
contentType: "text/plain",
|
|
113
|
-
data: `Url: ${urlPath} Status: Error fetching URL: An unknown error occurred.`,
|
|
114
|
-
source: urlPath,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export async function processPrompt(message, { baseDir, model }) {
|
|
119
|
-
const fileRegex = /@([^\s@]+(?:\.[\w\d]+))/g;
|
|
120
|
-
const urlRegex = /@(https?:\/\/[^\s]+)/g;
|
|
121
|
-
const shellRegex = /!`([^`]+)`/g;
|
|
122
|
-
// Collect all matches for files and urls
|
|
123
|
-
const fileMatches = Array.from(message.matchAll(fileRegex));
|
|
124
|
-
const urlMatches = Array.from(message.matchAll(urlRegex));
|
|
125
|
-
const shellMatches = Array.from(message.matchAll(shellRegex));
|
|
126
|
-
const mentionProcessingPromises = [];
|
|
127
|
-
// Process file references - collect promises
|
|
128
|
-
for (const match of fileMatches) {
|
|
129
|
-
const firstMatch = match[1];
|
|
130
|
-
if (firstMatch) {
|
|
131
|
-
const context = {
|
|
132
|
-
model,
|
|
133
|
-
baseDir,
|
|
134
|
-
match: firstMatch,
|
|
135
|
-
};
|
|
136
|
-
mentionProcessingPromises.push(processFileCommand(context));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
// Process url references - collect promises
|
|
140
|
-
for (const match of urlMatches) {
|
|
141
|
-
const firstMatch = match[1];
|
|
142
|
-
if (firstMatch) {
|
|
143
|
-
const context = {
|
|
144
|
-
model,
|
|
145
|
-
baseDir, // baseDir is not used by processUrlCommand but kept for consistency
|
|
146
|
-
match: firstMatch,
|
|
147
|
-
};
|
|
148
|
-
mentionProcessingPromises.push(processUrlCommand(context));
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
let processedMessage = message;
|
|
152
|
-
// Process shell commands
|
|
153
|
-
for (const match of shellMatches) {
|
|
154
|
-
const command = match[1];
|
|
155
|
-
if (command) {
|
|
156
|
-
const output = await processShellCommand(command);
|
|
157
|
-
processedMessage = processedMessage.replace(match[0], output);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// Wait for all mentions to be processed
|
|
161
|
-
const mentionResults = await Promise.all(mentionProcessingPromises);
|
|
162
|
-
const context = [];
|
|
163
|
-
for (const mention of mentionResults) {
|
|
164
|
-
if (isString(mention)) {
|
|
165
|
-
context.push(mention);
|
|
166
|
-
}
|
|
167
|
-
else if (mention.data.startsWith("data")) {
|
|
168
|
-
context.push({
|
|
169
|
-
type: "image",
|
|
170
|
-
mediaType: mention.contentType,
|
|
171
|
-
image: mention.data,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
context.push(formatUrl(mention.source, mention.data.trim(), model.promptFormat));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return {
|
|
179
|
-
message: processedMessage,
|
|
180
|
-
context,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import EventEmitter from "node:events";
|
|
2
|
-
import { type AssistantModelMessage, type ImagePart, // Added ImagePart
|
|
3
|
-
type ModelMessage, type ToolModelMessage, type UserModelMessage } from "ai";
|
|
4
|
-
import type { ModelManager } from "./models/manager.ts";
|
|
5
|
-
import type { TokenTracker } from "./token-tracker.ts";
|
|
6
|
-
export type UserMessageContentItem = string | ImagePart;
|
|
7
|
-
export declare function createUserMessage(contentItems: UserMessageContentItem[], prompt?: string): UserModelMessage;
|
|
8
|
-
export declare function createAssistantMessage(content: string): AssistantModelMessage;
|
|
9
|
-
/**
|
|
10
|
-
A message that was generated during the generation process.
|
|
11
|
-
It can be either an assistant message or a tool message.
|
|
12
|
-
*/
|
|
13
|
-
type ResponseMessage = AssistantModelMessage | ToolModelMessage;
|
|
14
|
-
export type SavedMessageHistory = {
|
|
15
|
-
title: string;
|
|
16
|
-
createdAt: Date;
|
|
17
|
-
updatedAt: Date;
|
|
18
|
-
messages: ModelMessage[];
|
|
19
|
-
};
|
|
20
|
-
interface MessageHistoryEvents {
|
|
21
|
-
"update-title": [string];
|
|
22
|
-
"clear-history": [];
|
|
23
|
-
}
|
|
24
|
-
export declare class MessageHistory extends EventEmitter<MessageHistoryEvents> {
|
|
25
|
-
private history;
|
|
26
|
-
private title;
|
|
27
|
-
private createdAt;
|
|
28
|
-
private updatedAt;
|
|
29
|
-
private stateDir;
|
|
30
|
-
private modelManager;
|
|
31
|
-
private tokenTracker;
|
|
32
|
-
constructor({ stateDir, modelManager, tokenTracker, }: {
|
|
33
|
-
stateDir: string;
|
|
34
|
-
modelManager: ModelManager;
|
|
35
|
-
tokenTracker: TokenTracker;
|
|
36
|
-
});
|
|
37
|
-
private validMessage;
|
|
38
|
-
get(): ModelMessage[];
|
|
39
|
-
clear(): void;
|
|
40
|
-
appendUserMessage(msg: string): void;
|
|
41
|
-
appendUserMessage(msg: UserModelMessage): void;
|
|
42
|
-
appendAssistantMessage(msg: string): void;
|
|
43
|
-
appendAssistantMessage(msg: AssistantModelMessage): void;
|
|
44
|
-
appendResponseMessages(responseMessages: ResponseMessage[]): void;
|
|
45
|
-
isEmpty(): boolean;
|
|
46
|
-
save(): Promise<void>;
|
|
47
|
-
private generateTitle;
|
|
48
|
-
getFirstUserMessage(): UserModelMessage | undefined;
|
|
49
|
-
static load(stateDir: string, count?: number): Promise<SavedMessageHistory[]>;
|
|
50
|
-
restore(savedHistory: SavedMessageHistory): void;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Normalizes an array of messages for API consumption by:
|
|
54
|
-
* 1. Filtering out progress-type messages
|
|
55
|
-
* 2. Processing user and assistant messages
|
|
56
|
-
* 3. Handling tool results by either:
|
|
57
|
-
* - Adding them as new messages if they're the first tool result
|
|
58
|
-
* - Adding them as new messages if the previous message wasn't a tool result
|
|
59
|
-
* - Merging them with the previous message if it was also a tool result
|
|
60
|
-
*
|
|
61
|
-
* This consolidation of sequential tool results into a single message
|
|
62
|
-
* ensures proper formatting for API consumption while maintaining the
|
|
63
|
-
* logical flow of the conversation.
|
|
64
|
-
*
|
|
65
|
-
* @param messages - Array of messages to normalize
|
|
66
|
-
* @returns Normalized array of user and assistant messages ready for API
|
|
67
|
-
*/
|
|
68
|
-
export declare function normalizeMessagesForApi(messages: ModelMessage[]): ModelMessage[];
|
|
69
|
-
export {};
|