openhorse 0.2.19 → 0.2.21
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/dist/agents/coordinator.d.ts.map +1 -1
- package/dist/agents/fork.d.ts.map +1 -1
- package/dist/agents/fork.js +0 -1
- package/dist/agents/fork.js.map +1 -1
- package/dist/agents/worker-pool.d.ts.map +1 -1
- package/dist/agents/worker-pool.js +3 -1
- package/dist/agents/worker-pool.js.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +13 -28
- package/dist/commands/index.js.map +1 -1
- package/dist/core/checkpoint.d.ts.map +1 -1
- package/dist/core/checkpoint.js +3 -0
- package/dist/core/checkpoint.js.map +1 -1
- package/dist/framework/prompt.d.ts.map +1 -1
- package/dist/framework/prompt.js +16 -0
- package/dist/framework/prompt.js.map +1 -1
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +0 -7
- package/dist/framework/query.js.map +1 -1
- package/dist/harness/context-harness.d.ts.map +1 -1
- package/dist/harness/context-harness.js +6 -1
- package/dist/harness/context-harness.js.map +1 -1
- package/dist/harness/ledger.d.ts +1 -0
- package/dist/harness/ledger.d.ts.map +1 -1
- package/dist/harness/ledger.js +8 -0
- package/dist/harness/ledger.js.map +1 -1
- package/dist/harness/safety.d.ts +2 -0
- package/dist/harness/safety.d.ts.map +1 -1
- package/dist/harness/safety.js +27 -3
- package/dist/harness/safety.js.map +1 -1
- package/dist/init.d.ts +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +1 -1
- package/dist/init.js.map +1 -1
- package/dist/ink-ui/components/Markdown.d.ts +1 -1
- package/dist/ink-ui/components/Markdown.d.ts.map +1 -1
- package/dist/ink-ui/components/Markdown.js +1 -1
- package/dist/ink-ui/components/Markdown.js.map +1 -1
- package/dist/ink-ui/runtime/grapheme.d.ts +9 -8
- package/dist/ink-ui/runtime/grapheme.d.ts.map +1 -1
- package/dist/ink-ui/runtime/grapheme.js +14 -60
- package/dist/ink-ui/runtime/grapheme.js.map +1 -1
- package/dist/ink-ui/runtime/input-buffer.d.ts +9 -31
- package/dist/ink-ui/runtime/input-buffer.d.ts.map +1 -1
- package/dist/ink-ui/runtime/input-buffer.js +15 -162
- package/dist/ink-ui/runtime/input-buffer.js.map +1 -1
- package/dist/ink-ui/runtime/native-cursor.js +0 -25
- package/dist/ink-ui/runtime/native-cursor.js.map +1 -1
- package/dist/ink-ui/runtime/prompt-layout.d.ts +9 -29
- package/dist/ink-ui/runtime/prompt-layout.d.ts.map +1 -1
- package/dist/ink-ui/runtime/prompt-layout.js +18 -166
- package/dist/ink-ui/runtime/prompt-layout.js.map +1 -1
- package/dist/ink-ui/runtime/transcript-state.d.ts.map +1 -1
- package/dist/ink-ui/runtime/transcript-state.js +2 -0
- package/dist/ink-ui/runtime/transcript-state.js.map +1 -1
- package/dist/ink-ui/screens/ReplScreen.d.ts.map +1 -1
- package/dist/ink-ui/screens/ReplScreen.js +11 -0
- package/dist/ink-ui/screens/ReplScreen.js.map +1 -1
- package/dist/memory/entrypoint.js +1 -1
- package/dist/memory/entrypoint.js.map +1 -1
- package/dist/memory/storage.js +1 -1
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/store.d.ts +1 -0
- package/dist/memory/store.d.ts.map +1 -1
- package/dist/memory/store.js +9 -0
- package/dist/memory/store.js.map +1 -1
- package/dist/runtime/agent-runtime-controller.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-controller.js +15 -0
- package/dist/runtime/agent-runtime-controller.js.map +1 -1
- package/dist/runtime/agent-runtime-protocol.d.ts +4 -1
- package/dist/runtime/agent-runtime-protocol.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-protocol.js +6 -0
- package/dist/runtime/agent-runtime-protocol.js.map +1 -1
- package/dist/runtime/chat-controller.d.ts +27 -0
- package/dist/runtime/chat-controller.d.ts.map +1 -1
- package/dist/runtime/chat-controller.js +148 -5
- package/dist/runtime/chat-controller.js.map +1 -1
- package/dist/runtime/composer/buffer.d.ts +43 -0
- package/dist/runtime/composer/buffer.d.ts.map +1 -0
- package/dist/runtime/composer/buffer.js +176 -0
- package/dist/runtime/composer/buffer.js.map +1 -0
- package/dist/runtime/composer/grapheme.d.ts +19 -0
- package/dist/runtime/composer/grapheme.d.ts.map +1 -0
- package/dist/runtime/composer/grapheme.js +73 -0
- package/dist/runtime/composer/grapheme.js.map +1 -0
- package/dist/runtime/composer/history.d.ts +39 -0
- package/dist/runtime/composer/history.d.ts.map +1 -0
- package/dist/runtime/composer/history.js +91 -0
- package/dist/runtime/composer/history.js.map +1 -0
- package/dist/runtime/composer/layout.d.ts +40 -0
- package/dist/runtime/composer/layout.d.ts.map +1 -0
- package/dist/runtime/composer/layout.js +174 -0
- package/dist/runtime/composer/layout.js.map +1 -0
- package/dist/runtime/rich-text/ansi-parser.d.ts +31 -0
- package/dist/runtime/rich-text/ansi-parser.d.ts.map +1 -0
- package/dist/runtime/rich-text/ansi-parser.js +272 -0
- package/dist/runtime/rich-text/ansi-parser.js.map +1 -0
- package/dist/runtime/rich-text/layout.d.ts +21 -0
- package/dist/runtime/rich-text/layout.d.ts.map +1 -0
- package/dist/runtime/rich-text/layout.js +327 -0
- package/dist/runtime/rich-text/layout.js.map +1 -0
- package/dist/runtime/rich-text/markdown-parser.d.ts +17 -0
- package/dist/runtime/rich-text/markdown-parser.d.ts.map +1 -0
- package/dist/runtime/rich-text/markdown-parser.js +211 -0
- package/dist/runtime/rich-text/markdown-parser.js.map +1 -0
- package/dist/runtime/rich-text/sanitizer.d.ts +18 -0
- package/dist/runtime/rich-text/sanitizer.d.ts.map +1 -0
- package/dist/runtime/rich-text/sanitizer.js +32 -0
- package/dist/runtime/rich-text/sanitizer.js.map +1 -0
- package/dist/runtime/rich-text/types.d.ts +59 -0
- package/dist/runtime/rich-text/types.d.ts.map +1 -0
- package/dist/runtime/rich-text/types.js +17 -0
- package/dist/runtime/rich-text/types.js.map +1 -0
- package/dist/runtime/subagents/budget.d.ts +118 -0
- package/dist/runtime/subagents/budget.d.ts.map +1 -0
- package/dist/runtime/subagents/budget.js +173 -0
- package/dist/runtime/subagents/budget.js.map +1 -0
- package/dist/runtime/subagents/child-executor-guard.d.ts +60 -0
- package/dist/runtime/subagents/child-executor-guard.d.ts.map +1 -0
- package/dist/runtime/subagents/child-executor-guard.js +219 -0
- package/dist/runtime/subagents/child-executor-guard.js.map +1 -0
- package/dist/runtime/subagents/context-builder.d.ts +34 -0
- package/dist/runtime/subagents/context-builder.d.ts.map +1 -0
- package/dist/runtime/subagents/context-builder.js +99 -0
- package/dist/runtime/subagents/context-builder.js.map +1 -0
- package/dist/runtime/subagents/index.d.ts +21 -0
- package/dist/runtime/subagents/index.d.ts.map +1 -0
- package/dist/runtime/subagents/index.js +62 -0
- package/dist/runtime/subagents/index.js.map +1 -0
- package/dist/runtime/subagents/policy.d.ts +68 -0
- package/dist/runtime/subagents/policy.d.ts.map +1 -0
- package/dist/runtime/subagents/policy.js +230 -0
- package/dist/runtime/subagents/policy.js.map +1 -0
- package/dist/runtime/subagents/presets.d.ts +44 -0
- package/dist/runtime/subagents/presets.d.ts.map +1 -0
- package/dist/runtime/subagents/presets.js +148 -0
- package/dist/runtime/subagents/presets.js.map +1 -0
- package/dist/runtime/subagents/production.d.ts +44 -0
- package/dist/runtime/subagents/production.d.ts.map +1 -0
- package/dist/runtime/subagents/production.js +118 -0
- package/dist/runtime/subagents/production.js.map +1 -0
- package/dist/runtime/subagents/provider-gate.d.ts +99 -0
- package/dist/runtime/subagents/provider-gate.d.ts.map +1 -0
- package/dist/runtime/subagents/provider-gate.js +186 -0
- package/dist/runtime/subagents/provider-gate.js.map +1 -0
- package/dist/runtime/subagents/result-parser.d.ts +40 -0
- package/dist/runtime/subagents/result-parser.d.ts.map +1 -0
- package/dist/runtime/subagents/result-parser.js +226 -0
- package/dist/runtime/subagents/result-parser.js.map +1 -0
- package/dist/runtime/subagents/runner.d.ts +53 -0
- package/dist/runtime/subagents/runner.d.ts.map +1 -0
- package/dist/runtime/subagents/runner.js +172 -0
- package/dist/runtime/subagents/runner.js.map +1 -0
- package/dist/runtime/subagents/runtime-integration.d.ts +73 -0
- package/dist/runtime/subagents/runtime-integration.d.ts.map +1 -0
- package/dist/runtime/subagents/runtime-integration.js +148 -0
- package/dist/runtime/subagents/runtime-integration.js.map +1 -0
- package/dist/runtime/subagents/supervisor.d.ts +79 -0
- package/dist/runtime/subagents/supervisor.d.ts.map +1 -0
- package/dist/runtime/subagents/supervisor.js +301 -0
- package/dist/runtime/subagents/supervisor.js.map +1 -0
- package/dist/runtime/subagents/tool.d.ts +38 -0
- package/dist/runtime/subagents/tool.d.ts.map +1 -0
- package/dist/runtime/subagents/tool.js +171 -0
- package/dist/runtime/subagents/tool.js.map +1 -0
- package/dist/runtime/subagents/types.d.ts +150 -0
- package/dist/runtime/subagents/types.d.ts.map +1 -0
- package/dist/runtime/subagents/types.js +52 -0
- package/dist/runtime/subagents/types.js.map +1 -0
- package/dist/runtime/ui-events.d.ts +5 -0
- package/dist/runtime/ui-events.d.ts.map +1 -1
- package/dist/runtime/ui-events.js.map +1 -1
- package/dist/runtime/ui-view-model.d.ts +35 -1
- package/dist/runtime/ui-view-model.d.ts.map +1 -1
- package/dist/runtime/ui-view-model.js +32 -1
- package/dist/runtime/ui-view-model.js.map +1 -1
- package/dist/sdk/query.d.ts.map +1 -1
- package/dist/sdk/query.js +0 -1
- package/dist/sdk/query.js.map +1 -1
- package/dist/services/auto-fix/autoFixHook.d.ts.map +1 -1
- package/dist/services/auto-fix/autoFixHook.js +3 -2
- package/dist/services/auto-fix/autoFixHook.js.map +1 -1
- package/dist/services/auto-fix/autoFixRunner.d.ts +2 -2
- package/dist/services/auto-fix/autoFixRunner.d.ts.map +1 -1
- package/dist/services/auto-fix/autoFixRunner.js +2 -2
- package/dist/services/auto-fix/autoFixRunner.js.map +1 -1
- package/dist/services/compact/auto-compact.js +3 -3
- package/dist/services/compact/auto-compact.js.map +1 -1
- package/dist/services/compact/summary-generator.d.ts.map +1 -1
- package/dist/services/compact/summary-generator.js +0 -1
- package/dist/services/compact/summary-generator.js.map +1 -1
- package/dist/services/concurrent-sessions.d.ts.map +1 -1
- package/dist/services/concurrent-sessions.js +3 -0
- package/dist/services/concurrent-sessions.js.map +1 -1
- package/dist/services/config.d.ts +11 -4
- package/dist/services/config.d.ts.map +1 -1
- package/dist/services/config.js +45 -4
- package/dist/services/config.js.map +1 -1
- package/dist/services/doctor.d.ts.map +1 -1
- package/dist/services/doctor.js +1 -1
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/global-config.d.ts +23 -1
- package/dist/services/global-config.d.ts.map +1 -1
- package/dist/services/global-config.js +3 -0
- package/dist/services/global-config.js.map +1 -1
- package/dist/services/llm.d.ts.map +1 -1
- package/dist/services/llm.js +9 -1
- package/dist/services/llm.js.map +1 -1
- package/dist/services/mcp/transports.d.ts +2 -0
- package/dist/services/mcp/transports.d.ts.map +1 -1
- package/dist/services/mcp/transports.js +23 -2
- package/dist/services/mcp/transports.js.map +1 -1
- package/dist/services/memory.d.ts.map +1 -1
- package/dist/services/memory.js.map +1 -1
- package/dist/services/model-context.d.ts.map +1 -1
- package/dist/services/model-context.js +7 -1
- package/dist/services/model-context.js.map +1 -1
- package/dist/services/session-memory/sessionMemory.js +1 -1
- package/dist/services/session-memory/sessionMemory.js.map +1 -1
- package/dist/services/session-storage.d.ts +1 -1
- package/dist/services/session-storage.d.ts.map +1 -1
- package/dist/services/session-storage.js +38 -4
- package/dist/services/session-storage.js.map +1 -1
- package/dist/services/task-manager.d.ts +2 -0
- package/dist/services/task-manager.d.ts.map +1 -1
- package/dist/services/task-manager.js +13 -0
- package/dist/services/task-manager.js.map +1 -1
- package/dist/services/usage-state.d.ts.map +1 -1
- package/dist/services/usage-state.js +3 -0
- package/dist/services/usage-state.js.map +1 -1
- package/dist/skills/loader.d.ts +1 -1
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +1 -1
- package/dist/skills/loader.js.map +1 -1
- package/dist/skills/registry.d.ts +1 -1
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +1 -1
- package/dist/skills/registry.js.map +1 -1
- package/dist/terminal-ui/launch.d.ts +18 -3
- package/dist/terminal-ui/launch.d.ts.map +1 -1
- package/dist/terminal-ui/launch.js +21 -4
- package/dist/terminal-ui/launch.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lsp.js.map +1 -1
- package/dist/tools/web.js +3 -3
- package/dist/tools/web.js.map +1 -1
- package/dist/tui-core/frame.d.ts +13 -1
- package/dist/tui-core/frame.d.ts.map +1 -1
- package/dist/tui-core/frame.js +61 -8
- package/dist/tui-core/frame.js.map +1 -1
- package/dist/tui-core/style.d.ts +87 -0
- package/dist/tui-core/style.d.ts.map +1 -0
- package/dist/tui-core/style.js +248 -0
- package/dist/tui-core/style.js.map +1 -0
- package/dist/tui-core/terminal-writer.d.ts.map +1 -1
- package/dist/tui-core/terminal-writer.js +16 -3
- package/dist/tui-core/terminal-writer.js.map +1 -1
- package/dist/tui-ui/inline-surface.d.ts +134 -0
- package/dist/tui-ui/inline-surface.d.ts.map +1 -0
- package/dist/tui-ui/inline-surface.js +364 -0
- package/dist/tui-ui/inline-surface.js.map +1 -0
- package/dist/tui-ui/launch.d.ts.map +1 -1
- package/dist/tui-ui/launch.js +249 -64
- package/dist/tui-ui/launch.js.map +1 -1
- package/dist/tui-ui/layout.js +15 -2
- package/dist/tui-ui/layout.js.map +1 -1
- package/dist/tui-ui/render-scheduler.d.ts +37 -0
- package/dist/tui-ui/render-scheduler.d.ts.map +1 -0
- package/dist/tui-ui/render-scheduler.js +118 -0
- package/dist/tui-ui/render-scheduler.js.map +1 -0
- package/dist/tui-ui/runner.d.ts +12 -0
- package/dist/tui-ui/runner.d.ts.map +1 -1
- package/dist/tui-ui/runner.js +34 -2
- package/dist/tui-ui/runner.js.map +1 -1
- package/dist/tui-ui/state.d.ts +33 -3
- package/dist/tui-ui/state.d.ts.map +1 -1
- package/dist/tui-ui/state.js +138 -25
- package/dist/tui-ui/state.js.map +1 -1
- package/dist/tui-ui/transcript-cache.d.ts +33 -0
- package/dist/tui-ui/transcript-cache.d.ts.map +1 -0
- package/dist/tui-ui/transcript-cache.js +67 -0
- package/dist/tui-ui/transcript-cache.js.map +1 -0
- package/dist/ui/box.d.ts.map +1 -1
- package/dist/ui/box.js +0 -11
- package/dist/ui/box.js.map +1 -1
- package/dist/ui/command-panel.d.ts.map +1 -1
- package/dist/ui/command-panel.js +1 -3
- package/dist/ui/command-panel.js.map +1 -1
- package/dist/ui/file-completion.js +1 -1
- package/dist/ui/file-completion.js.map +1 -1
- package/dist/ui/markdown.d.ts.map +1 -1
- package/dist/ui/markdown.js +1 -2
- package/dist/ui/markdown.js.map +1 -1
- package/dist/ui/multiline-input.d.ts.map +1 -1
- package/dist/ui/multiline-input.js +1 -2
- package/dist/ui/multiline-input.js.map +1 -1
- package/dist/ui/progress.d.ts.map +1 -1
- package/dist/ui/progress.js +0 -3
- package/dist/ui/progress.js.map +1 -1
- package/dist/ui/status-bar.d.ts.map +1 -1
- package/dist/ui/status-bar.js +0 -1
- package/dist/ui/status-bar.js.map +1 -1
- package/dist/ui/stream-markdown.d.ts +3 -0
- package/dist/ui/stream-markdown.d.ts.map +1 -1
- package/dist/ui/stream-markdown.js +0 -6
- package/dist/ui/stream-markdown.js.map +1 -1
- package/dist/ui/tool-preview.d.ts.map +1 -1
- package/dist/ui/tool-preview.js +0 -1
- package/dist/ui/tool-preview.js.map +1 -1
- package/package.json +1 -1
- package/dist/cli-dbg.js +0 -717
- package/dist/cli-debug.d.ts +0 -7
- package/dist/cli-debug.d.ts.map +0 -1
- package/dist/cli-debug.js +0 -717
- package/dist/cli-debug.js.map +0 -1
- package/dist/cli-debug2.d.ts +0 -7
- package/dist/cli-debug2.d.ts.map +0 -1
- package/dist/cli-debug2.js +0 -717
- package/dist/cli-debug2.js.map +0 -1
- package/dist/cli-debug3.d.ts +0 -7
- package/dist/cli-debug3.d.ts.map +0 -1
- package/dist/cli-debug3.js +0 -719
- package/dist/cli-debug3.js.map +0 -1
- package/dist/cli-ink.d.ts +0 -8
- package/dist/cli-ink.d.ts.map +0 -1
- package/dist/cli-ink.js +0 -32
- package/dist/cli-ink.js.map +0 -1
- package/dist/cli-patch.js +0 -716
- package/dist/cli-test.js +0 -726
package/dist/cli-patch.js
DELETED
|
@@ -1,716 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* openhorse - 命令行交互入口
|
|
4
|
-
*
|
|
5
|
-
* 简洁版 REPL,使用 readline + keypress 事件处理
|
|
6
|
-
*/
|
|
7
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
-
};
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
require("dotenv/config");
|
|
12
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
13
|
-
const readline_1 = __importDefault(require("readline"));
|
|
14
|
-
const fs_1 = require("fs");
|
|
15
|
-
const path_1 = require("path");
|
|
16
|
-
const init_1 = require("./init");
|
|
17
|
-
const llm_1 = require("./services/llm");
|
|
18
|
-
const tools_1 = require("./tools");
|
|
19
|
-
const mcp_1 = require("./tools/mcp");
|
|
20
|
-
const config_1 = require("./services/config");
|
|
21
|
-
const config_dir_1 = require("./services/config-dir");
|
|
22
|
-
const global_config_1 = require("./services/global-config");
|
|
23
|
-
const session_storage_1 = require("./services/session-storage");
|
|
24
|
-
const storage_1 = require("./memory/storage");
|
|
25
|
-
const skills_1 = require("./skills");
|
|
26
|
-
const framework_1 = require("./framework");
|
|
27
|
-
const commands_1 = require("./commands");
|
|
28
|
-
const parser_1 = require("./commands/parser");
|
|
29
|
-
const types_1 = require("./commands/types");
|
|
30
|
-
const box_1 = require("./ui/box");
|
|
31
|
-
const command_panel_1 = require("./ui/command-panel");
|
|
32
|
-
const multiline_input_1 = require("./ui/multiline-input");
|
|
33
|
-
const file_completion_1 = require("./ui/file-completion");
|
|
34
|
-
const status_bar_1 = require("./ui/status-bar");
|
|
35
|
-
// Get version from package.json
|
|
36
|
-
const VERSION = (() => {
|
|
37
|
-
try {
|
|
38
|
-
const pkgPath = (0, path_1.join)(__dirname, '..', 'package.json');
|
|
39
|
-
const pkg = JSON.parse((0, fs_1.readFileSync)(pkgPath, 'utf-8'));
|
|
40
|
-
return pkg.version || '0.1.14';
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return '0.1.14';
|
|
44
|
-
}
|
|
45
|
-
})();
|
|
46
|
-
// ============================================================================
|
|
47
|
-
// 颜色常量
|
|
48
|
-
// ============================================================================
|
|
49
|
-
// Force chalk to use full 24-bit color. Must be set BEFORE any chalk.hex/bgHex calls.
|
|
50
|
-
chalk_1.default.level = 3; process.stderr.write("CHALK_LEVEL=" + chalk_1.default.level + "\n");
|
|
51
|
-
const BRAND = chalk_1.default.hex('#FF6B35');
|
|
52
|
-
const ACCENT = chalk_1.default.hex('#00D4AA');
|
|
53
|
-
const DIM = chalk_1.default.dim;
|
|
54
|
-
const ERROR = chalk_1.default.red;
|
|
55
|
-
const WARN = chalk_1.default.yellow;
|
|
56
|
-
const SUCCESS = chalk_1.default.green;
|
|
57
|
-
/** User input background — dark slate fill (like Claude Code) */
|
|
58
|
-
const USER_INPUT_BG = chalk_1.default.bgHex('#1E293B').hex('#E2E8F0');
|
|
59
|
-
const USER_INPUT_ACCENT = chalk_1.default.bgHex('#1E293B').hex('#00D4AA');
|
|
60
|
-
// ============================================================================
|
|
61
|
-
// CLI Help
|
|
62
|
-
// ============================================================================
|
|
63
|
-
function showCliHelp() {
|
|
64
|
-
console.log();
|
|
65
|
-
console.log(BRAND('openhorse') + DIM(` v${VERSION}`));
|
|
66
|
-
console.log(DIM(' Universal Agent Harness Framework'));
|
|
67
|
-
console.log();
|
|
68
|
-
console.log(ACCENT('Usage:'));
|
|
69
|
-
console.log(' openhorse Start interactive REPL');
|
|
70
|
-
console.log(' openhorse --help Show this help message');
|
|
71
|
-
console.log(' openhorse --version Show version');
|
|
72
|
-
console.log();
|
|
73
|
-
console.log(ACCENT('Options:'));
|
|
74
|
-
console.log(' -h, --help Show help');
|
|
75
|
-
console.log(' -v, --version Show version');
|
|
76
|
-
console.log();
|
|
77
|
-
console.log(ACCENT('Interactive Commands:'));
|
|
78
|
-
console.log(' /help Show available slash commands');
|
|
79
|
-
console.log(' /status Show system status');
|
|
80
|
-
console.log(' /model [name] Show or change model');
|
|
81
|
-
console.log(' /chat <msg> Send message to LLM');
|
|
82
|
-
console.log(' /exit Exit the REPL');
|
|
83
|
-
console.log();
|
|
84
|
-
console.log(DIM('Type /help in REPL for full command list.'));
|
|
85
|
-
console.log();
|
|
86
|
-
}
|
|
87
|
-
// ============================================================================
|
|
88
|
-
// 全局状态
|
|
89
|
-
// ============================================================================
|
|
90
|
-
let llm = null;
|
|
91
|
-
let store;
|
|
92
|
-
let currentSession = null;
|
|
93
|
-
let runtime;
|
|
94
|
-
// 输入状态
|
|
95
|
-
let currentInput = '';
|
|
96
|
-
let inputHistory = [];
|
|
97
|
-
let historyIndex = -1;
|
|
98
|
-
let historyMode = 'none';
|
|
99
|
-
let searchQuery = '';
|
|
100
|
-
function parseKey(char, key) {
|
|
101
|
-
if (!key) {
|
|
102
|
-
// 手动解析
|
|
103
|
-
if (char === '\r' || char === '\n')
|
|
104
|
-
return { name: 'enter', ctrl: false, shift: false, meta: false, sequence: char || '' };
|
|
105
|
-
if (char === '\x1b')
|
|
106
|
-
return { name: 'escape', ctrl: false, shift: false, meta: false, sequence: char };
|
|
107
|
-
if (char === '\t')
|
|
108
|
-
return { name: 'tab', ctrl: false, shift: false, meta: false, sequence: char };
|
|
109
|
-
if (char === '\x7f' || char === '\b')
|
|
110
|
-
return { name: 'backspace', ctrl: false, shift: false, meta: false, sequence: char };
|
|
111
|
-
return { name: char || '', ctrl: false, shift: false, meta: false, sequence: char || '' };
|
|
112
|
-
}
|
|
113
|
-
// 统一 "return" 和 "enter"
|
|
114
|
-
if (key.name === 'return') {
|
|
115
|
-
key.name = 'enter';
|
|
116
|
-
}
|
|
117
|
-
// 如果 key.name 为空,使用 char 作为 name
|
|
118
|
-
if (!key.name && char) {
|
|
119
|
-
key.name = char;
|
|
120
|
-
}
|
|
121
|
-
return key;
|
|
122
|
-
}
|
|
123
|
-
function handleKeypress(char, key) {
|
|
124
|
-
const k = parseKey(char, key);
|
|
125
|
-
// 命令面板模式
|
|
126
|
-
if ((0, command_panel_1.isPanelVisible)()) {
|
|
127
|
-
handlePanelKeypress(k, char);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
// 文件补全模式
|
|
131
|
-
if ((0, file_completion_1.isFileCompletionVisible)()) {
|
|
132
|
-
handleFileCompletionKeypress(k, char);
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
// 历史导航模式
|
|
136
|
-
if (historyMode !== 'none') {
|
|
137
|
-
handleHistoryKeypress(k, char);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// 正常输入模式
|
|
141
|
-
handleNormalKeypress(k, char);
|
|
142
|
-
}
|
|
143
|
-
function handlePanelKeypress(k, char) {
|
|
144
|
-
switch (k.name) {
|
|
145
|
-
case 'up':
|
|
146
|
-
(0, command_panel_1.navigatePanel)('up');
|
|
147
|
-
break;
|
|
148
|
-
case 'down':
|
|
149
|
-
(0, command_panel_1.navigatePanel)('down');
|
|
150
|
-
break;
|
|
151
|
-
case 'enter':
|
|
152
|
-
const cmd = (0, command_panel_1.selectCommand)();
|
|
153
|
-
if (cmd) {
|
|
154
|
-
currentInput = cmd;
|
|
155
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
156
|
-
// 直接执行命令
|
|
157
|
-
handleInput(currentInput).catch(err => {
|
|
158
|
-
console.log(ERROR(`Command error: ${err.message || String(err)}`));
|
|
159
|
-
});
|
|
160
|
-
currentInput = '';
|
|
161
|
-
(0, command_panel_1.clearPendingCommand)();
|
|
162
|
-
}
|
|
163
|
-
break;
|
|
164
|
-
case 'escape':
|
|
165
|
-
(0, command_panel_1.hideCommandPanel)();
|
|
166
|
-
currentInput = '';
|
|
167
|
-
(0, command_panel_1.redrawInputWithPrompt)('');
|
|
168
|
-
break;
|
|
169
|
-
case 'backspace':
|
|
170
|
-
currentInput = currentInput.slice(0, -1);
|
|
171
|
-
if (currentInput.length <= 1) {
|
|
172
|
-
(0, command_panel_1.hideCommandPanel)();
|
|
173
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
(0, command_panel_1.updatePanelFilter)(currentInput.slice(1));
|
|
177
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
178
|
-
}
|
|
179
|
-
break;
|
|
180
|
-
default:
|
|
181
|
-
// 添加字符到过滤
|
|
182
|
-
if (char && char.length === 1 && !k.ctrl) {
|
|
183
|
-
currentInput += char;
|
|
184
|
-
(0, command_panel_1.updatePanelFilter)(currentInput.slice(1));
|
|
185
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function handleHistoryKeypress(k, char) {
|
|
190
|
-
if (historyMode === 'search') {
|
|
191
|
-
// 搜索模式:输入搜索词
|
|
192
|
-
switch (k.name) {
|
|
193
|
-
case 'enter':
|
|
194
|
-
if (inputHistory.length > 0 && historyIndex >= 0) {
|
|
195
|
-
currentInput = inputHistory[historyIndex]?.content || '';
|
|
196
|
-
}
|
|
197
|
-
historyMode = 'none';
|
|
198
|
-
searchQuery = '';
|
|
199
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
200
|
-
break;
|
|
201
|
-
case 'escape':
|
|
202
|
-
historyMode = 'none';
|
|
203
|
-
searchQuery = '';
|
|
204
|
-
currentInput = '';
|
|
205
|
-
(0, command_panel_1.redrawInputWithPrompt)('');
|
|
206
|
-
break;
|
|
207
|
-
case 'backspace':
|
|
208
|
-
searchQuery = searchQuery.slice(0, -1);
|
|
209
|
-
updateHistorySearch();
|
|
210
|
-
break;
|
|
211
|
-
default:
|
|
212
|
-
if (char && char.length === 1 && !k.ctrl) {
|
|
213
|
-
searchQuery += char;
|
|
214
|
-
updateHistorySearch();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
// 导航模式
|
|
220
|
-
switch (k.name) {
|
|
221
|
-
case 'up':
|
|
222
|
-
historyIndex = Math.min(inputHistory.length - 1, historyIndex + 1);
|
|
223
|
-
currentInput = inputHistory[historyIndex]?.content || '';
|
|
224
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
225
|
-
break;
|
|
226
|
-
case 'down':
|
|
227
|
-
historyIndex = Math.max(-1, historyIndex - 1);
|
|
228
|
-
if (historyIndex < 0) {
|
|
229
|
-
currentInput = '';
|
|
230
|
-
historyMode = 'none';
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
currentInput = inputHistory[historyIndex]?.content || '';
|
|
234
|
-
}
|
|
235
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
236
|
-
break;
|
|
237
|
-
case 'enter':
|
|
238
|
-
historyMode = 'none';
|
|
239
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
240
|
-
break;
|
|
241
|
-
case 'escape':
|
|
242
|
-
historyMode = 'none';
|
|
243
|
-
currentInput = '';
|
|
244
|
-
historyIndex = -1;
|
|
245
|
-
(0, command_panel_1.redrawInputWithPrompt)('');
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
function handleFileCompletionKeypress(k, char) {
|
|
251
|
-
switch (k.name) {
|
|
252
|
-
case 'up':
|
|
253
|
-
(0, file_completion_1.navigateFiles)('up');
|
|
254
|
-
break;
|
|
255
|
-
case 'down':
|
|
256
|
-
(0, file_completion_1.navigateFiles)('down');
|
|
257
|
-
break;
|
|
258
|
-
case 'tab':
|
|
259
|
-
const completedPath = (0, file_completion_1.completeFile)();
|
|
260
|
-
if (completedPath) {
|
|
261
|
-
currentInput = (0, file_completion_1.getBaseInput)() + '@' + completedPath;
|
|
262
|
-
(0, file_completion_1.hideFileCompletion)();
|
|
263
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
// 目录:继续显示面板,更新 query
|
|
267
|
-
currentInput = (0, file_completion_1.getBaseInput)() + '@' + (0, file_completion_1.getFileQuery)();
|
|
268
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
269
|
-
}
|
|
270
|
-
break;
|
|
271
|
-
case 'enter':
|
|
272
|
-
const selectedPath = (0, file_completion_1.selectFile)();
|
|
273
|
-
if (selectedPath) {
|
|
274
|
-
currentInput = (0, file_completion_1.getBaseInput)() + '@' + selectedPath;
|
|
275
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
276
|
-
}
|
|
277
|
-
break;
|
|
278
|
-
case 'escape':
|
|
279
|
-
(0, file_completion_1.hideFileCompletion)();
|
|
280
|
-
currentInput = (0, file_completion_1.getBaseInput)() + '@' + (0, file_completion_1.getFileQuery)();
|
|
281
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
282
|
-
break;
|
|
283
|
-
case 'backspace':
|
|
284
|
-
const query = (0, file_completion_1.getFileQuery)();
|
|
285
|
-
if (query.length > 0) {
|
|
286
|
-
(0, file_completion_1.updateFileQuery)(query.slice(0, -1));
|
|
287
|
-
currentInput = (0, file_completion_1.getBaseInput)() + '@' + (0, file_completion_1.getFileQuery)();
|
|
288
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
(0, file_completion_1.hideFileCompletion)();
|
|
292
|
-
currentInput = (0, file_completion_1.getBaseInput)();
|
|
293
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
294
|
-
}
|
|
295
|
-
break;
|
|
296
|
-
default:
|
|
297
|
-
// 添加字符到路径查询
|
|
298
|
-
if (char && char.length === 1 && !k.ctrl) {
|
|
299
|
-
const newQuery = (0, file_completion_1.getFileQuery)() + char;
|
|
300
|
-
(0, file_completion_1.updateFileQuery)(newQuery);
|
|
301
|
-
currentInput = (0, file_completion_1.getBaseInput)() + '@' + newQuery;
|
|
302
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
function handleNormalKeypress(k, char) {
|
|
307
|
-
switch (k.name) {
|
|
308
|
-
case 'enter':
|
|
309
|
-
// 多行模式:添加行
|
|
310
|
-
if ((0, multiline_input_1.isMultilineActive)()) {
|
|
311
|
-
if ((0, multiline_input_1.shouldEnterMultiline)(currentInput)) {
|
|
312
|
-
(0, multiline_input_1.addMultilineLine)(currentInput.slice(0, -1));
|
|
313
|
-
currentInput = '';
|
|
314
|
-
process.stdout.write('\r\x1b[2K');
|
|
315
|
-
process.stdout.write((0, multiline_input_1.renderContinuationPrompt)());
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
// 结束多行,发送完整输入
|
|
319
|
-
(0, multiline_input_1.addMultilineLine)(currentInput);
|
|
320
|
-
const fullInput = (0, multiline_input_1.getMultilineInput)();
|
|
321
|
-
(0, multiline_input_1.resetMultiline)();
|
|
322
|
-
if (fullInput.trim()) {
|
|
323
|
-
// 回显多行输入(带半透明背景)
|
|
324
|
-
process.stdout.write('\x1b[2K\r');
|
|
325
|
-
const lines = fullInput.split('\n');
|
|
326
|
-
for (const line of lines) {
|
|
327
|
-
console.log(USER_INPUT_ACCENT('❯ ') + USER_INPUT_BG(' ' + line + ' '));
|
|
328
|
-
}
|
|
329
|
-
// Issue #32 fix: 重置渲染长度,防止后续 redrawInputWithPrompt 清除用户输入
|
|
330
|
-
(0, command_panel_1.resetRenderLength)();
|
|
331
|
-
handleInput(fullInput).catch(err => {
|
|
332
|
-
console.log(ERROR(`Input error: ${err.message || String(err)}`));
|
|
333
|
-
});
|
|
334
|
-
(0, global_config_1.addToInputHistory)(fullInput);
|
|
335
|
-
inputHistory = (0, global_config_1.getInputHistory)();
|
|
336
|
-
}
|
|
337
|
-
currentInput = '';
|
|
338
|
-
(0, command_panel_1.redrawInputWithPrompt)('');
|
|
339
|
-
}
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
// 检查是否进入多行模式
|
|
343
|
-
if ((0, multiline_input_1.shouldEnterMultiline)(currentInput)) {
|
|
344
|
-
(0, multiline_input_1.enterMultiline)(currentInput);
|
|
345
|
-
currentInput = '';
|
|
346
|
-
process.stdout.write('\r\x1b[2K');
|
|
347
|
-
process.stdout.write((0, multiline_input_1.renderContinuationPrompt)());
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
// 正常发送输入
|
|
351
|
-
if (currentInput.trim()) {
|
|
352
|
-
// 先清除输入行的 prompt,然后打印用户输入(保存到终端历史)
|
|
353
|
-
process.stdout.write('\x1b[2K\r'); // 清除当前 prompt 行
|
|
354
|
-
// Echo user input with semi-transparent background fill (Claude Code style)
|
|
355
|
-
const echoLines = currentInput.split('\n');
|
|
356
|
-
for (const echoLine of echoLines) {
|
|
357
|
-
console.log(USER_INPUT_ACCENT('❯ ') + USER_INPUT_BG(' ' + echoLine + ' '));
|
|
358
|
-
}
|
|
359
|
-
// Issue #32 fix: 重置渲染长度,防止后续 redrawInputWithPrompt 清除用户输入行
|
|
360
|
-
// 因为 console.log 打印后光标在新行,redrawInputWithPrompt 会从当前位置向上清除
|
|
361
|
-
(0, command_panel_1.resetRenderLength)();
|
|
362
|
-
handleInput(currentInput);
|
|
363
|
-
(0, global_config_1.addToInputHistory)(currentInput);
|
|
364
|
-
inputHistory = (0, global_config_1.getInputHistory)();
|
|
365
|
-
currentInput = '';
|
|
366
|
-
(0, command_panel_1.redrawInputWithPrompt)('');
|
|
367
|
-
}
|
|
368
|
-
break;
|
|
369
|
-
case 'backspace':
|
|
370
|
-
currentInput = currentInput.slice(0, -1);
|
|
371
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
372
|
-
break;
|
|
373
|
-
case 'up':
|
|
374
|
-
// 进入历史导航
|
|
375
|
-
if (currentInput === '' && inputHistory.length > 0) {
|
|
376
|
-
historyMode = 'navigate';
|
|
377
|
-
historyIndex = 0;
|
|
378
|
-
currentInput = inputHistory[0]?.content || '';
|
|
379
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
380
|
-
}
|
|
381
|
-
break;
|
|
382
|
-
case 'r':
|
|
383
|
-
if (k.ctrl) {
|
|
384
|
-
// Ctrl+R:搜索历史
|
|
385
|
-
historyMode = 'search';
|
|
386
|
-
searchQuery = '';
|
|
387
|
-
showHistorySearchPrompt();
|
|
388
|
-
}
|
|
389
|
-
else if (char) {
|
|
390
|
-
currentInput += char;
|
|
391
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
392
|
-
}
|
|
393
|
-
break;
|
|
394
|
-
case 'c':
|
|
395
|
-
if (k.ctrl) {
|
|
396
|
-
// Ctrl+C:取消多行或退出
|
|
397
|
-
if ((0, multiline_input_1.isMultilineActive)()) {
|
|
398
|
-
(0, multiline_input_1.resetMultiline)();
|
|
399
|
-
currentInput = '';
|
|
400
|
-
(0, command_panel_1.redrawInputWithPrompt)('');
|
|
401
|
-
console.log(DIM('(cancelled)'));
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
handleCtrlC();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
else if (char) {
|
|
408
|
-
currentInput += char;
|
|
409
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
410
|
-
}
|
|
411
|
-
break;
|
|
412
|
-
case 'd':
|
|
413
|
-
if (k.ctrl && currentInput === '') {
|
|
414
|
-
// Ctrl+D:退出(空输入时)
|
|
415
|
-
handleCtrlC();
|
|
416
|
-
}
|
|
417
|
-
else if (char) {
|
|
418
|
-
currentInput += char;
|
|
419
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
420
|
-
}
|
|
421
|
-
break;
|
|
422
|
-
case '/':
|
|
423
|
-
// Issue #30 fix: 只在输入为空时触发命令面板(即 `/` 是第一个字符)
|
|
424
|
-
// 避免在 URL(http://)、路径(src/)、正则等场景误触发
|
|
425
|
-
if (currentInput === '') {
|
|
426
|
-
currentInput = '/';
|
|
427
|
-
(0, command_panel_1.showCommandPanel)('');
|
|
428
|
-
// 命令面板已渲染,光标已在正确位置
|
|
429
|
-
// 重置渲染长度并写入 `/` 符号
|
|
430
|
-
(0, command_panel_1.resetRenderLength)();
|
|
431
|
-
process.stdout.write('/');
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
// 正常添加 `/` 到输入
|
|
435
|
-
currentInput += '/';
|
|
436
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
437
|
-
}
|
|
438
|
-
break;
|
|
439
|
-
case '@':
|
|
440
|
-
// 显示文件补全
|
|
441
|
-
const baseInput = currentInput;
|
|
442
|
-
currentInput += '@';
|
|
443
|
-
(0, file_completion_1.showFileCompletion)('', baseInput);
|
|
444
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
445
|
-
break;
|
|
446
|
-
default:
|
|
447
|
-
// 普通字符
|
|
448
|
-
if (char && char.length === 1 && !k.ctrl && !k.meta) {
|
|
449
|
-
currentInput += char;
|
|
450
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
function updateHistorySearch() {
|
|
455
|
-
if (searchQuery) {
|
|
456
|
-
const allHistory = (0, global_config_1.getInputHistory)();
|
|
457
|
-
const matches = allHistory.filter(h => h.content.toLowerCase().includes(searchQuery.toLowerCase()));
|
|
458
|
-
historyIndex = 0;
|
|
459
|
-
currentInput = matches[0]?.content || '';
|
|
460
|
-
// Don't replace inputHistory — just display filtered results
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
historyIndex = -1;
|
|
464
|
-
currentInput = '';
|
|
465
|
-
}
|
|
466
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput, `[Search: ${searchQuery}]`);
|
|
467
|
-
}
|
|
468
|
-
function showHistorySearchPrompt() {
|
|
469
|
-
process.stdout.write('\r\x1b[2K');
|
|
470
|
-
process.stdout.write(ACCENT('❯ ') + DIM('[Search: ]'));
|
|
471
|
-
}
|
|
472
|
-
async function handleCtrlC() {
|
|
473
|
-
// 保存会话摘要后退出
|
|
474
|
-
if (currentSession) {
|
|
475
|
-
const messages = (0, session_storage_1.readSessionMessages)(currentSession.id);
|
|
476
|
-
if (messages.length > 0) {
|
|
477
|
-
(0, session_storage_1.updateSessionSummary)(currentSession.id, messages);
|
|
478
|
-
}
|
|
479
|
-
(0, session_storage_1.endSession)(currentSession.id);
|
|
480
|
-
}
|
|
481
|
-
// 关闭 stdin raw mode 并退出
|
|
482
|
-
if (process.stdin.isTTY) {
|
|
483
|
-
process.stdin.setRawMode(false);
|
|
484
|
-
}
|
|
485
|
-
process.stdin.pause();
|
|
486
|
-
console.log();
|
|
487
|
-
console.log(DIM('Shutting down...'));
|
|
488
|
-
mcp_1.mcpManager.disconnectAll();
|
|
489
|
-
await runtime.shutdown();
|
|
490
|
-
console.log(SUCCESS('Goodbye! 🐴'));
|
|
491
|
-
process.exit(0);
|
|
492
|
-
}
|
|
493
|
-
// ============================================================================
|
|
494
|
-
// Banner
|
|
495
|
-
// ============================================================================
|
|
496
|
-
function showBanner() {
|
|
497
|
-
const config = store.getSnapshot().config;
|
|
498
|
-
const baseUrl = config.apiBaseUrl || '';
|
|
499
|
-
console.log();
|
|
500
|
-
console.log((0, box_1.renderHeaderBox)({
|
|
501
|
-
provider: baseUrl.includes('anthropic') ? 'Anthropic'
|
|
502
|
-
: baseUrl.includes('openai') ? 'OpenAI'
|
|
503
|
-
: baseUrl.includes('dashscope') ? 'Alibaba Cloud'
|
|
504
|
-
: 'Custom',
|
|
505
|
-
model: config.model,
|
|
506
|
-
endpoint: baseUrl,
|
|
507
|
-
status: llm ? 'ready' : 'loading',
|
|
508
|
-
statusText: llm ? undefined : 'Set OPENHORSE_API_KEY in .env',
|
|
509
|
-
version: VERSION,
|
|
510
|
-
}));
|
|
511
|
-
}
|
|
512
|
-
// ============================================================================
|
|
513
|
-
// 输入处理
|
|
514
|
-
// ============================================================================
|
|
515
|
-
function getPrompt() {
|
|
516
|
-
const mode = store.getSnapshot().permissionMode;
|
|
517
|
-
const modeText = (0, types_1.getModeDisplayText)(mode);
|
|
518
|
-
const modeIndicator = modeText ? `[${modeText}] ` : '';
|
|
519
|
-
return ACCENT('❯ ') + DIM(modeIndicator);
|
|
520
|
-
}
|
|
521
|
-
async function handleInput(input) {
|
|
522
|
-
const text = input.trim();
|
|
523
|
-
if (!text)
|
|
524
|
-
return;
|
|
525
|
-
// 不在这里打印输入,readline 已经显示了
|
|
526
|
-
// 直接交给 executeChat 处理,它有自己的 spinner 和流式输出
|
|
527
|
-
const ctx = {
|
|
528
|
-
cwd: process.cwd(),
|
|
529
|
-
config: store.getSnapshot().config,
|
|
530
|
-
store,
|
|
531
|
-
llm,
|
|
532
|
-
runtime,
|
|
533
|
-
sessionId: currentSession?.id,
|
|
534
|
-
};
|
|
535
|
-
try {
|
|
536
|
-
const parsed = (0, parser_1.parseInput)(text);
|
|
537
|
-
if (parsed.isCommand) {
|
|
538
|
-
const cmd = (0, commands_1.findCommand)(parsed.name);
|
|
539
|
-
if (cmd) {
|
|
540
|
-
const result = await cmd.execute(ctx, parsed.args);
|
|
541
|
-
// executeChat 会被 cmd.execute 调用,如果需要
|
|
542
|
-
if (!result.continueAsChat) {
|
|
543
|
-
// 命令完成后的输出已经在 cmd.execute 中处理
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
console.log();
|
|
548
|
-
console.log(ERROR(`Unknown command: /${parsed.name}`));
|
|
549
|
-
const suggestions = (0, parser_1.buildCommandSuggestions)(parsed.name);
|
|
550
|
-
if (suggestions.length > 0) {
|
|
551
|
-
console.log(DIM(`Did you mean: ${suggestions.map(s => `/${s}`).join(', ')}?`));
|
|
552
|
-
}
|
|
553
|
-
console.log();
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
// 直接 chat - executeChat 有自己的 spinner 和流式输出
|
|
558
|
-
await (0, commands_1.executeChat)(ctx, text);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
catch (err) {
|
|
562
|
-
console.log(ERROR(`Error: ${err.message || String(err)}`));
|
|
563
|
-
}
|
|
564
|
-
// 显示状态栏
|
|
565
|
-
updateStatusBar();
|
|
566
|
-
// 重新显示 prompt
|
|
567
|
-
(0, command_panel_1.redrawInputWithPrompt)(currentInput);
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* 更新状态栏显示
|
|
571
|
-
*/
|
|
572
|
-
function updateStatusBar() {
|
|
573
|
-
const snapshot = store.getSnapshot();
|
|
574
|
-
const usage = snapshot.tokenUsage;
|
|
575
|
-
const costStats = snapshot.costTracker.getSessionStats();
|
|
576
|
-
const mcpStatus = mcp_1.mcpManager.getStatus();
|
|
577
|
-
const stats = {
|
|
578
|
-
model: snapshot.currentModel,
|
|
579
|
-
tokens: usage ? usage.promptTokens + usage.completionTokens : 0,
|
|
580
|
-
promptTokens: usage?.promptTokens || 0,
|
|
581
|
-
completionTokens: usage?.completionTokens || 0,
|
|
582
|
-
cost: costStats.totalCost,
|
|
583
|
-
ctxPercent: Math.round((snapshot.conversationHistory.length / 50) * 100), // 假设 50 条上限
|
|
584
|
-
mcpConnected: mcpStatus.filter(s => s.connected).length,
|
|
585
|
-
mcpTotal: mcpStatus.length,
|
|
586
|
-
};
|
|
587
|
-
// 在 prompt 上一行显示状态栏
|
|
588
|
-
console.log((0, status_bar_1.renderStatusBar)(stats));
|
|
589
|
-
}
|
|
590
|
-
// 接口变量(用于兼容性,主要逻辑通过 keypress 处理)
|
|
591
|
-
let rl = null;
|
|
592
|
-
// ============================================================================
|
|
593
|
-
// 主入口
|
|
594
|
-
// ============================================================================
|
|
595
|
-
async function main() {
|
|
596
|
-
// Parse command line arguments
|
|
597
|
-
const args = process.argv.slice(2);
|
|
598
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
599
|
-
showCliHelp();
|
|
600
|
-
process.exit(0);
|
|
601
|
-
}
|
|
602
|
-
if (args.includes('--version') || args.includes('-v')) {
|
|
603
|
-
console.log(`openhorse v${VERSION}`);
|
|
604
|
-
process.exit(0);
|
|
605
|
-
}
|
|
606
|
-
(0, config_dir_1.ensureConfigDir)();
|
|
607
|
-
(0, global_config_1.recordFirstStartTime)();
|
|
608
|
-
const projectPath = process.cwd();
|
|
609
|
-
const cliConfig = (0, config_1.loadConfig)();
|
|
610
|
-
// Load project memory
|
|
611
|
-
const memories = (0, storage_1.loadAllMemories)(projectPath);
|
|
612
|
-
const memoryContent = memories.length > 0
|
|
613
|
-
? memories.map(m => `## ${m.name} (${m.type})\n${m.content}`).join('\n\n')
|
|
614
|
-
: '';
|
|
615
|
-
// Load skills (builtin + user + project) and render the prompt section
|
|
616
|
-
let skillsContent = '';
|
|
617
|
-
try {
|
|
618
|
-
const registry = (0, skills_1.getSkillsRegistry)();
|
|
619
|
-
skillsContent = registry.generateSystemPromptInjection();
|
|
620
|
-
}
|
|
621
|
-
catch (err) {
|
|
622
|
-
console.error(WARN(`⚠ Skills load error: ${err.message}`));
|
|
623
|
-
}
|
|
624
|
-
store = new framework_1.Store({
|
|
625
|
-
config: cliConfig,
|
|
626
|
-
tools: tools_1.TOOLS,
|
|
627
|
-
currentModel: cliConfig.model,
|
|
628
|
-
memoryContent,
|
|
629
|
-
skillsContent,
|
|
630
|
-
});
|
|
631
|
-
// Mirror tool-state (todos/plan) into Store so the UI can observe it
|
|
632
|
-
(0, framework_1.resetToolState)();
|
|
633
|
-
(0, framework_1.subscribeToolState)((s) => {
|
|
634
|
-
store.setState({
|
|
635
|
-
todos: s.todos,
|
|
636
|
-
planMode: s.planMode,
|
|
637
|
-
currentPlan: s.currentPlan,
|
|
638
|
-
});
|
|
639
|
-
});
|
|
640
|
-
currentSession = (0, session_storage_1.createSession)(projectPath, cliConfig.model);
|
|
641
|
-
(0, global_config_1.incrementSessionCount)();
|
|
642
|
-
if ((0, config_1.isConfigured)(cliConfig)) {
|
|
643
|
-
try {
|
|
644
|
-
llm = new llm_1.LLMService({
|
|
645
|
-
apiKey: cliConfig.apiKey,
|
|
646
|
-
baseUrl: cliConfig.apiBaseUrl,
|
|
647
|
-
model: cliConfig.model,
|
|
648
|
-
fallbackModel: cliConfig.fallbackModel,
|
|
649
|
-
maxTokens: cliConfig.maxTokens,
|
|
650
|
-
temperature: cliConfig.temperature,
|
|
651
|
-
maxRetries: cliConfig.maxRetries,
|
|
652
|
-
retryBaseDelay: cliConfig.retryBaseDelay,
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
catch (err) {
|
|
656
|
-
console.log(WARN(`⚠ LLM initialization warning: ${err.message}`));
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
const config = store.getSnapshot().config;
|
|
660
|
-
runtime = await (0, init_1.init)({
|
|
661
|
-
name: config.name,
|
|
662
|
-
mode: config.mode,
|
|
663
|
-
logLevel: config.logLevel,
|
|
664
|
-
});
|
|
665
|
-
await runtime.start();
|
|
666
|
-
// Auto-connect MCP servers from ~/.openhorse/mcp.json (non-blocking)
|
|
667
|
-
mcp_1.mcpManager.connectAll().catch(err => {
|
|
668
|
-
console.error(WARN(`⚠ MCP startup error: ${err.message}`));
|
|
669
|
-
});
|
|
670
|
-
// Banner
|
|
671
|
-
showBanner();
|
|
672
|
-
// 提示
|
|
673
|
-
console.log(SUCCESS('✔ System initialized'));
|
|
674
|
-
console.log(DIM(' Type /help for commands, /exit to quit'));
|
|
675
|
-
if (!(0, config_1.isConfigured)(cliConfig)) {
|
|
676
|
-
console.log(WARN(' ⚠ LLM not configured — set OPENHORSE_API_KEY'));
|
|
677
|
-
}
|
|
678
|
-
console.log();
|
|
679
|
-
// 加载输入历史
|
|
680
|
-
inputHistory = (0, global_config_1.getInputHistory)();
|
|
681
|
-
// 启用 keypress 事件处理
|
|
682
|
-
// 使用 emitKeypressEvents + setRawMode 实现交互式功能
|
|
683
|
-
readline_1.default.emitKeypressEvents(process.stdin);
|
|
684
|
-
if (process.stdin.isTTY) {
|
|
685
|
-
try {
|
|
686
|
-
process.stdin.setRawMode(true);
|
|
687
|
-
}
|
|
688
|
-
catch (err) {
|
|
689
|
-
console.error(ERROR(`setRawMode failed: ${err.message}`));
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
else {
|
|
693
|
-
console.log(WARN('⚠ stdin is not TTY - interactive features disabled'));
|
|
694
|
-
}
|
|
695
|
-
process.stdin.resume();
|
|
696
|
-
// Force chalk to use full 24-bit color support.
|
|
697
|
-
// chalk.level is evaluated at module load time (before raw mode),
|
|
698
|
-
// so it defaults to 0. Set to 3 after raw mode is enabled.
|
|
699
|
-
chalk_1.default.level = 3;
|
|
700
|
-
// 监听 keypress 事件
|
|
701
|
-
process.stdin.on('keypress', (char, key) => {
|
|
702
|
-
try {
|
|
703
|
-
handleKeypress(char, key);
|
|
704
|
-
}
|
|
705
|
-
catch (err) {
|
|
706
|
-
console.error(ERROR(`Keypress error: ${err.message}`));
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
// 初始 prompt
|
|
710
|
-
(0, command_panel_1.redrawInputWithPrompt)('');
|
|
711
|
-
}
|
|
712
|
-
main().catch(err => {
|
|
713
|
-
console.error(ERROR('[OpenHorse] Fatal error:'), err);
|
|
714
|
-
process.exit(1);
|
|
715
|
-
});
|
|
716
|
-
//# sourceMappingURL=cli.js.map
|