@ai-zen/cli 1.0.0-alpha.9 → 1.0.0
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/CHANGELOG.md +1334 -275
- package/LICENSE +21 -0
- package/README.md +136 -31
- package/README.zh.md +136 -31
- package/dist/agent-creator.d.ts +11 -0
- package/dist/agent-creator.d.ts.map +1 -1
- package/dist/agent-creator.js +50 -20
- package/dist/agent-creator.js.map +1 -1
- package/dist/agent-switch.d.ts +61 -0
- package/dist/agent-switch.d.ts.map +1 -0
- package/dist/agent-switch.js +83 -0
- package/dist/agent-switch.js.map +1 -0
- package/dist/agents-store.d.ts +6 -1
- package/dist/agents-store.d.ts.map +1 -1
- package/dist/agents-store.js +46 -4
- package/dist/agents-store.js.map +1 -1
- package/dist/auto-migrate-confirm.d.ts +43 -0
- package/dist/auto-migrate-confirm.d.ts.map +1 -0
- package/dist/auto-migrate-confirm.js +47 -0
- package/dist/auto-migrate-confirm.js.map +1 -0
- package/dist/clipboard.d.ts +68 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +177 -0
- package/dist/clipboard.js.map +1 -0
- package/dist/config-editor.d.ts +42 -5
- package/dist/config-editor.d.ts.map +1 -1
- package/dist/config-editor.js +80 -27
- package/dist/config-editor.js.map +1 -1
- package/dist/config.d.ts +76 -17
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +143 -39
- package/dist/config.js.map +1 -1
- package/dist/conversation-commands/registry.d.ts +127 -4
- package/dist/conversation-commands/registry.d.ts.map +1 -1
- package/dist/conversation-commands/registry.js +93 -14
- package/dist/conversation-commands/registry.js.map +1 -1
- package/dist/conversation-persist-plugin.d.ts +0 -1
- package/dist/conversation-persist-plugin.d.ts.map +1 -1
- package/dist/conversation-persist-plugin.js +7 -16
- package/dist/conversation-persist-plugin.js.map +1 -1
- package/dist/conversation-repository.d.ts +79 -18
- package/dist/conversation-repository.d.ts.map +1 -1
- package/dist/conversation-repository.js +96 -30
- package/dist/conversation-repository.js.map +1 -1
- package/dist/cwd-tracker-plugin.d.ts.map +1 -1
- package/dist/cwd-tracker-plugin.js +22 -7
- package/dist/cwd-tracker-plugin.js.map +1 -1
- package/dist/format-time.d.ts +17 -6
- package/dist/format-time.d.ts.map +1 -1
- package/dist/format-time.js +32 -14
- package/dist/format-time.js.map +1 -1
- package/dist/handoff-service.d.ts +19 -0
- package/dist/handoff-service.d.ts.map +1 -0
- package/dist/handoff-service.js +85 -0
- package/dist/handoff-service.js.map +1 -0
- package/dist/hook.d.ts.map +1 -1
- package/dist/hook.js +69 -15
- package/dist/hook.js.map +1 -1
- package/dist/i18n/en-wizard.d.ts +8 -0
- package/dist/i18n/en-wizard.d.ts.map +1 -0
- package/dist/i18n/en-wizard.js +303 -0
- package/dist/i18n/en-wizard.js.map +1 -0
- package/dist/i18n/en.d.ts +7 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +245 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/index.d.ts +57 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +109 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/preferences.d.ts +37 -0
- package/dist/i18n/preferences.d.ts.map +1 -0
- package/dist/i18n/preferences.js +73 -0
- package/dist/i18n/preferences.js.map +1 -0
- package/dist/i18n/zh-wizard.d.ts +11 -0
- package/dist/i18n/zh-wizard.d.ts.map +1 -0
- package/dist/i18n/zh-wizard.js +306 -0
- package/dist/i18n/zh-wizard.js.map +1 -0
- package/dist/i18n/zh.d.ts +10 -0
- package/dist/i18n/zh.d.ts.map +1 -0
- package/dist/i18n/zh.js +249 -0
- package/dist/i18n/zh.js.map +1 -0
- package/dist/index.js +52 -23
- package/dist/index.js.map +1 -1
- package/dist/mcp-command.d.ts +32 -0
- package/dist/mcp-command.d.ts.map +1 -0
- package/dist/mcp-command.js +37 -0
- package/dist/mcp-command.js.map +1 -0
- package/dist/mode.d.ts +31 -4
- package/dist/mode.d.ts.map +1 -1
- package/dist/mode.js +42 -7
- package/dist/mode.js.map +1 -1
- package/dist/model-switch.d.ts +58 -0
- package/dist/model-switch.d.ts.map +1 -0
- package/dist/model-switch.js +62 -0
- package/dist/model-switch.js.map +1 -0
- package/dist/reasoning-effort.d.ts +96 -0
- package/dist/reasoning-effort.d.ts.map +1 -0
- package/dist/reasoning-effort.js +164 -0
- package/dist/reasoning-effort.js.map +1 -0
- package/dist/reasoning-presets.d.ts +34 -0
- package/dist/reasoning-presets.d.ts.map +1 -0
- package/dist/reasoning-presets.js +85 -0
- package/dist/reasoning-presets.js.map +1 -0
- package/dist/sdk-log.d.ts +84 -0
- package/dist/sdk-log.d.ts.map +1 -0
- package/dist/sdk-log.js +167 -0
- package/dist/sdk-log.js.map +1 -0
- package/dist/session-pointer.d.ts.map +1 -1
- package/dist/session-pointer.js +10 -4
- package/dist/session-pointer.js.map +1 -1
- package/dist/stdio-runner.d.ts.map +1 -1
- package/dist/stdio-runner.js +32 -30
- package/dist/stdio-runner.js.map +1 -1
- package/dist/sub-agent-guard-plugin.d.ts +10 -7
- package/dist/sub-agent-guard-plugin.d.ts.map +1 -1
- package/dist/sub-agent-guard-plugin.js +12 -9
- package/dist/sub-agent-guard-plugin.js.map +1 -1
- package/dist/tui/chat-history.d.ts +29 -0
- package/dist/tui/chat-history.d.ts.map +1 -0
- package/dist/tui/chat-history.js +55 -0
- package/dist/tui/chat-history.js.map +1 -0
- package/dist/tui/chat-session.d.ts +144 -13
- package/dist/tui/chat-session.d.ts.map +1 -1
- package/dist/tui/chat-session.js +312 -73
- package/dist/tui/chat-session.js.map +1 -1
- package/dist/tui/components.d.ts +109 -6
- package/dist/tui/components.d.ts.map +1 -1
- package/dist/tui/components.js +177 -12
- package/dist/tui/components.js.map +1 -1
- package/dist/tui/config-wizard/detail.d.ts +18 -10
- package/dist/tui/config-wizard/detail.d.ts.map +1 -1
- package/dist/tui/config-wizard/detail.js +53 -46
- package/dist/tui/config-wizard/detail.js.map +1 -1
- package/dist/tui/config-wizard/engine.d.ts +2 -2
- package/dist/tui/config-wizard/engine.d.ts.map +1 -1
- package/dist/tui/config-wizard/engine.js +48 -26
- package/dist/tui/config-wizard/engine.js.map +1 -1
- package/dist/tui/config-wizard/fields.d.ts +3 -1
- package/dist/tui/config-wizard/fields.d.ts.map +1 -1
- package/dist/tui/config-wizard/fields.js +202 -167
- package/dist/tui/config-wizard/fields.js.map +1 -1
- package/dist/tui/config-wizard/frame.js +1 -1
- package/dist/tui/config-wizard/kv-editor.d.ts.map +1 -1
- package/dist/tui/config-wizard/kv-editor.js +13 -5
- package/dist/tui/config-wizard/kv-editor.js.map +1 -1
- package/dist/tui/config-wizard/list.d.ts +3 -1
- package/dist/tui/config-wizard/list.d.ts.map +1 -1
- package/dist/tui/config-wizard/list.js +4 -4
- package/dist/tui/config-wizard/list.js.map +1 -1
- package/dist/tui/config-wizard/mcp-helpers.d.ts.map +1 -1
- package/dist/tui/config-wizard/mcp-helpers.js +4 -3
- package/dist/tui/config-wizard/mcp-helpers.js.map +1 -1
- package/dist/tui/config-wizard/menu.d.ts.map +1 -1
- package/dist/tui/config-wizard/menu.js +33 -21
- package/dist/tui/config-wizard/menu.js.map +1 -1
- package/dist/tui/config-wizard/prompt-editor.d.ts +8 -1
- package/dist/tui/config-wizard/prompt-editor.d.ts.map +1 -1
- package/dist/tui/config-wizard/prompt-editor.js +11 -7
- package/dist/tui/config-wizard/prompt-editor.js.map +1 -1
- package/dist/tui/config-wizard/prompt.d.ts.map +1 -1
- package/dist/tui/config-wizard/prompt.js +8 -7
- package/dist/tui/config-wizard/prompt.js.map +1 -1
- package/dist/tui/config-wizard/step-agents.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-agents.js +50 -29
- package/dist/tui/config-wizard/step-agents.js.map +1 -1
- package/dist/tui/config-wizard/step-defaults.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-defaults.js +77 -27
- package/dist/tui/config-wizard/step-defaults.js.map +1 -1
- package/dist/tui/config-wizard/step-endpoints.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-endpoints.js +27 -14
- package/dist/tui/config-wizard/step-endpoints.js.map +1 -1
- package/dist/tui/config-wizard/step-mcp.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-mcp.js +29 -25
- package/dist/tui/config-wizard/step-mcp.js.map +1 -1
- package/dist/tui/config-wizard/step-models.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-models.js +98 -43
- package/dist/tui/config-wizard/step-models.js.map +1 -1
- package/dist/tui/config-wizard/step-new-endpoint.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-new-endpoint.js +16 -12
- package/dist/tui/config-wizard/step-new-endpoint.js.map +1 -1
- package/dist/tui/config-wizard/step-simple.d.ts.map +1 -1
- package/dist/tui/config-wizard/step-simple.js +18 -17
- package/dist/tui/config-wizard/step-simple.js.map +1 -1
- package/dist/tui/config-wizard/types.d.ts +31 -3
- package/dist/tui/config-wizard/types.d.ts.map +1 -1
- package/dist/tui/config-wizard/types.js.map +1 -1
- package/dist/tui/file-index.d.ts +38 -0
- package/dist/tui/file-index.d.ts.map +1 -0
- package/dist/tui/file-index.js +117 -0
- package/dist/tui/file-index.js.map +1 -0
- package/dist/tui/index.d.ts +17 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +105 -49
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/input-editing.d.ts +52 -0
- package/dist/tui/input-editing.d.ts.map +1 -0
- package/dist/tui/input-editing.js +91 -0
- package/dist/tui/input-editing.js.map +1 -0
- package/dist/tui/key-debug.d.ts +62 -0
- package/dist/tui/key-debug.d.ts.map +1 -0
- package/dist/tui/key-debug.js +92 -0
- package/dist/tui/key-debug.js.map +1 -0
- package/dist/tui/mention.d.ts +47 -0
- package/dist/tui/mention.d.ts.map +1 -0
- package/dist/tui/mention.js +152 -0
- package/dist/tui/mention.js.map +1 -0
- package/dist/tui/mouse.d.ts +55 -0
- package/dist/tui/mouse.d.ts.map +1 -0
- package/dist/tui/mouse.js +74 -0
- package/dist/tui/mouse.js.map +1 -0
- package/dist/tui/phase.d.ts +64 -0
- package/dist/tui/phase.d.ts.map +1 -0
- package/dist/tui/phase.js +112 -0
- package/dist/tui/phase.js.map +1 -0
- package/dist/tui/screens/agent-tabs.d.ts +53 -0
- package/dist/tui/screens/agent-tabs.d.ts.map +1 -0
- package/dist/tui/screens/agent-tabs.js +81 -0
- package/dist/tui/screens/agent-tabs.js.map +1 -0
- package/dist/tui/screens/chat-commands.d.ts +78 -1
- package/dist/tui/screens/chat-commands.d.ts.map +1 -1
- package/dist/tui/screens/chat-commands.js +688 -157
- package/dist/tui/screens/chat-commands.js.map +1 -1
- package/dist/tui/screens/chat.d.ts +57 -1
- package/dist/tui/screens/chat.d.ts.map +1 -1
- package/dist/tui/screens/chat.js +708 -261
- package/dist/tui/screens/chat.js.map +1 -1
- package/dist/tui/screens/common-keys.d.ts +36 -0
- package/dist/tui/screens/common-keys.d.ts.map +1 -0
- package/dist/tui/screens/common-keys.js +67 -0
- package/dist/tui/screens/common-keys.js.map +1 -0
- package/dist/tui/screens/frame-buffer.d.ts.map +1 -1
- package/dist/tui/screens/frame-buffer.js.map +1 -1
- package/dist/tui/screens/handoff-choice.d.ts +37 -0
- package/dist/tui/screens/handoff-choice.d.ts.map +1 -0
- package/dist/tui/screens/handoff-choice.js +42 -0
- package/dist/tui/screens/handoff-choice.js.map +1 -0
- package/dist/tui/screens/index.d.ts +7 -5
- package/dist/tui/screens/index.d.ts.map +1 -1
- package/dist/tui/screens/index.js +6 -5
- package/dist/tui/screens/index.js.map +1 -1
- package/dist/tui/screens/input-row.d.ts +64 -0
- package/dist/tui/screens/input-row.d.ts.map +1 -0
- package/dist/tui/screens/input-row.js +67 -0
- package/dist/tui/screens/input-row.js.map +1 -0
- package/dist/tui/screens/input.d.ts +77 -1
- package/dist/tui/screens/input.d.ts.map +1 -1
- package/dist/tui/screens/input.js +125 -8
- package/dist/tui/screens/input.js.map +1 -1
- package/dist/tui/screens/layout.d.ts +49 -0
- package/dist/tui/screens/layout.d.ts.map +1 -1
- package/dist/tui/screens/layout.js +45 -7
- package/dist/tui/screens/layout.js.map +1 -1
- package/dist/tui/screens/lines.d.ts +7 -0
- package/dist/tui/screens/lines.d.ts.map +1 -1
- package/dist/tui/screens/lines.js +6 -6
- package/dist/tui/screens/lines.js.map +1 -1
- package/dist/tui/screens/messages-view.d.ts +20 -1
- package/dist/tui/screens/messages-view.d.ts.map +1 -1
- package/dist/tui/screens/messages-view.js +55 -8
- package/dist/tui/screens/messages-view.js.map +1 -1
- package/dist/tui/screens/notice-bar.d.ts +5 -0
- package/dist/tui/screens/notice-bar.d.ts.map +1 -0
- package/dist/tui/screens/notice-bar.js +21 -0
- package/dist/tui/screens/notice-bar.js.map +1 -0
- package/dist/tui/screens/notice.d.ts +44 -10
- package/dist/tui/screens/notice.d.ts.map +1 -1
- package/dist/tui/screens/notice.js +75 -15
- package/dist/tui/screens/notice.js.map +1 -1
- package/dist/tui/screens/overlays.d.ts.map +1 -1
- package/dist/tui/screens/overlays.js +4 -3
- package/dist/tui/screens/overlays.js.map +1 -1
- package/dist/tui/screens/render.d.ts +1 -1
- package/dist/tui/screens/render.d.ts.map +1 -1
- package/dist/tui/screens/render.js +18 -11
- package/dist/tui/screens/render.js.map +1 -1
- package/dist/tui/screens/use-chat-viewport.d.ts +22 -0
- package/dist/tui/screens/use-chat-viewport.d.ts.map +1 -0
- package/dist/tui/screens/use-chat-viewport.js +50 -0
- package/dist/tui/screens/use-chat-viewport.js.map +1 -0
- package/dist/tui/screens/use-input-editing.d.ts +69 -0
- package/dist/tui/screens/use-input-editing.d.ts.map +1 -0
- package/dist/tui/screens/use-input-editing.js +220 -0
- package/dist/tui/screens/use-input-editing.js.map +1 -0
- package/dist/tui/screens/use-overlays.d.ts +25 -0
- package/dist/tui/screens/use-overlays.d.ts.map +1 -0
- package/dist/tui/screens/use-overlays.js +32 -0
- package/dist/tui/screens/use-overlays.js.map +1 -0
- package/dist/tui/screens/use-wizard-host.d.ts +46 -0
- package/dist/tui/screens/use-wizard-host.d.ts.map +1 -0
- package/dist/tui/screens/use-wizard-host.js +123 -0
- package/dist/tui/screens/use-wizard-host.js.map +1 -0
- package/dist/tui/screens/welcome.d.ts +12 -0
- package/dist/tui/screens/welcome.d.ts.map +1 -0
- package/dist/tui/screens/welcome.js +36 -0
- package/dist/tui/screens/welcome.js.map +1 -0
- package/dist/tui/status-segments.d.ts +37 -0
- package/dist/tui/status-segments.d.ts.map +1 -0
- package/dist/tui/status-segments.js +166 -0
- package/dist/tui/status-segments.js.map +1 -0
- package/dist/tui/text.d.ts +22 -7
- package/dist/tui/text.d.ts.map +1 -1
- package/dist/tui/text.js +110 -39
- package/dist/tui/text.js.map +1 -1
- package/dist/tui/theme.d.ts +2 -0
- package/dist/tui/theme.d.ts.map +1 -1
- package/dist/tui/theme.js +2 -0
- package/dist/tui/theme.js.map +1 -1
- package/dist/tui/token-rate.d.ts +83 -0
- package/dist/tui/token-rate.d.ts.map +1 -0
- package/dist/tui/token-rate.js +195 -0
- package/dist/tui/token-rate.js.map +1 -0
- package/dist/types.d.ts +7 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/user-content.d.ts +41 -0
- package/dist/user-content.d.ts.map +1 -0
- package/dist/user-content.js +37 -0
- package/dist/user-content.js.map +1 -0
- package/dist/version-compare.d.ts +37 -0
- package/dist/version-compare.d.ts.map +1 -0
- package/dist/version-compare.js +105 -0
- package/dist/version-compare.js.map +1 -0
- package/dist/version.js.map +1 -1
- package/package.json +7 -5
- package/dist/auto-migrate-confirm-plugin.d.ts +0 -58
- package/dist/auto-migrate-confirm-plugin.d.ts.map +0 -1
- package/dist/auto-migrate-confirm-plugin.js +0 -61
- package/dist/auto-migrate-confirm-plugin.js.map +0 -1
- package/dist/migration-service.d.ts +0 -15
- package/dist/migration-service.d.ts.map +0 -1
- package/dist/migration-service.js +0 -66
- package/dist/migration-service.js.map +0 -1
- package/dist/tui/screens/splash.d.ts +0 -5
- package/dist/tui/screens/splash.d.ts.map +0 -1
- package/dist/tui/screens/splash.js +0 -51
- package/dist/tui/screens/splash.js.map +0 -1
package/dist/tui/screens/chat.js
CHANGED
|
@@ -2,24 +2,55 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
// 对话屏幕 —— 以 SDK 的 `agent.messages` 为唯一数据源渲染(无自定义中间模型)
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { Box, Text, useApp, useCursor, useInput, useWindowSize } from "ink";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { disableMouseTracking } from "../mouse.js";
|
|
7
|
+
import { setSdkNoticeSink } from "../../sdk-log.js";
|
|
8
|
+
import { keyDebug } from "../key-debug.js";
|
|
9
|
+
import { phaseLabel } from "../phase.js";
|
|
5
10
|
import { AgentNS } from "@ai-zen/agents-core";
|
|
6
11
|
import { theme } from "../theme.js";
|
|
7
|
-
import { Spinner, StatusBar,
|
|
8
|
-
import { layoutInput, usableFrameRows
|
|
12
|
+
import { Spinner, StatusBar, statusBarRows, BottomMenu, PastedImagesBar } from "../components.js";
|
|
13
|
+
import { graphemes, layoutInput, usableFrameRows } from "../text.js";
|
|
9
14
|
import { ChatSession } from "../chat-session.js";
|
|
10
|
-
import { matchCommandHints } from "../../conversation-commands/registry.js";
|
|
11
|
-
import { readConfig, readMcpConfig, saveConfig, writeMcpConfig } from "../../config.js";
|
|
15
|
+
import { commandBlocksInput, matchCommandHints, parseCommandInput, } from "../../conversation-commands/registry.js";
|
|
16
|
+
import { readConfig, readMcpConfig, readReasoningPresets, saveConfig, writeMcpConfig } from "../../config.js";
|
|
12
17
|
import { readAgentStore } from "../../agents-store.js";
|
|
13
|
-
import { resolveCredential } from "../../config-editor.js";
|
|
14
18
|
import { ConfigWizard } from "../config-wizard/index.js";
|
|
15
|
-
import { computeInputCursorPosition,
|
|
16
|
-
import { computeChatLayout } from "./layout.js";
|
|
19
|
+
import { computeInputCursorPosition, inputWindow } from "./input.js";
|
|
20
|
+
import { AGENT_TABS_LINES, computeChatLayout } from "./layout.js";
|
|
17
21
|
import { FrameBuffer } from "./frame-buffer.js";
|
|
18
22
|
import { LineView } from "./render.js";
|
|
19
23
|
import { messageToLines, transcriptLines } from "./messages-view.js";
|
|
24
|
+
import { welcomeLines } from "./welcome.js";
|
|
20
25
|
import { PickerOverlay, Confirm } from "./overlays.js";
|
|
26
|
+
import { CursorInputRow } from "./input-row.js";
|
|
27
|
+
import { chooseHandoffMode } from "./handoff-choice.js";
|
|
21
28
|
import { runCommand } from "./chat-commands.js";
|
|
29
|
+
import { describeEffortView } from "../../reasoning-effort.js";
|
|
30
|
+
import { t } from "../../i18n/index.js";
|
|
22
31
|
import { NoticeChannel, noticeLines } from "./notice.js";
|
|
32
|
+
import { NoticeBar } from "./notice-bar.js";
|
|
33
|
+
import { AgentTabs } from "./agent-tabs.js";
|
|
34
|
+
import { useChatViewport } from "./use-chat-viewport.js";
|
|
35
|
+
import { useChatOverlays } from "./use-overlays.js";
|
|
36
|
+
import { useWizardHost } from "./use-wizard-host.js";
|
|
37
|
+
import { useInputEditing } from "./use-input-editing.js";
|
|
38
|
+
import { extractMention, mentionInsertText, rankPaths } from "../mention.js";
|
|
39
|
+
import { userDrafts } from "../chat-history.js";
|
|
40
|
+
import { listProjectPaths } from "../file-index.js";
|
|
41
|
+
import { MAX_CLIPBOARD_TEXT_BYTES, readClipboardImage, readClipboardText } from "../../clipboard.js";
|
|
42
|
+
import { handleCtrlDExit, handleScrollKey } from "./common-keys.js";
|
|
43
|
+
/**
|
|
44
|
+
* 单条消息最多附几张粘贴图片。
|
|
45
|
+
*
|
|
46
|
+
* 顶在 4 张:一张手机截图内联后 base64 常在 1~3MB,再多一次请求就是几十 MB,
|
|
47
|
+
* 既扫 token 也容易撞端点的请求体上限。
|
|
48
|
+
*/
|
|
49
|
+
export const MAX_PASTED_IMAGES = 4;
|
|
50
|
+
/** 字节数 → 一位小数的 MB(提示文案用) */
|
|
51
|
+
export function formatMegabytes(bytes) {
|
|
52
|
+
return (bytes / 1024 / 1024).toFixed(1);
|
|
53
|
+
}
|
|
23
54
|
/**
|
|
24
55
|
* 计算回车时应提交的文本。
|
|
25
56
|
*
|
|
@@ -35,41 +66,98 @@ export function resolveSubmitText(input, hints, menuIndex) {
|
|
|
35
66
|
const picked = hints[index]?.names[0];
|
|
36
67
|
return picked ? `/${picked}` : input;
|
|
37
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* 忙碌期那一行 spinner 的文案。
|
|
71
|
+
*
|
|
72
|
+
* 生成中由 SDK 的阶段驱动(`phaseLabel`);但 `/update`、`/migrate` 这类
|
|
73
|
+
* **阻塞输入的命令**执行时根本没有生成轮次,`phase` 是 `null`,`phaseLabel(null)`
|
|
74
|
+
* 会兜底成「处理中…」——与实际动作毫无关系。命令期间改显命令名,
|
|
75
|
+
* 至少能看出「在跑哪条命令」,具体进度由命令自己 push 通知(查版本 / 开始安装 …)。
|
|
76
|
+
*/
|
|
77
|
+
export function busySpinnerLabel(phase, command) {
|
|
78
|
+
if (phase)
|
|
79
|
+
return phaseLabel(phase);
|
|
80
|
+
return command ? t("cmd.running", { name: command }) : phaseLabel(null);
|
|
81
|
+
}
|
|
38
82
|
export function Chat(props) {
|
|
83
|
+
const deps = {
|
|
84
|
+
readConfig,
|
|
85
|
+
readReasoningPresets,
|
|
86
|
+
readAgentStore,
|
|
87
|
+
createSession: ChatSession.create,
|
|
88
|
+
listProjectPaths,
|
|
89
|
+
readClipboardImage,
|
|
90
|
+
readClipboardText,
|
|
91
|
+
wizardReaders: {
|
|
92
|
+
readConfig,
|
|
93
|
+
readMcpConfig,
|
|
94
|
+
readReasoningPresets,
|
|
95
|
+
readAgentStore,
|
|
96
|
+
},
|
|
97
|
+
saveConfig,
|
|
98
|
+
writeMcpConfig,
|
|
99
|
+
...props.deps,
|
|
100
|
+
};
|
|
39
101
|
const { exit, suspendTerminal } = useApp();
|
|
40
102
|
const { setCursorPosition } = useCursor();
|
|
41
103
|
const { columns, rows } = useWindowSize();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const [cursor, setCursor] = useState(Array.from(props.initialInput ?? "").length);
|
|
45
|
-
const [menuIndex, setMenuIndex] = useState(0);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
setMenuIndex(0);
|
|
48
|
-
}, [input]);
|
|
49
|
-
const [confirmState, setConfirmState] = useState(null);
|
|
50
|
-
const [pickerState, setPickerState] = useState(null);
|
|
51
|
-
/** 配置向导:非 null 时整屏接管(凭据设置 / 配置中心) */
|
|
52
|
-
const [wizardStep, setWizardStep] = useState(null);
|
|
53
|
-
const [wizardConfig, setWizardConfig] = useState(null);
|
|
54
|
-
const [wizardAgents, setWizardAgents] = useState([]);
|
|
55
|
-
const [wizardMcp, setWizardMcp] = useState(null);
|
|
56
|
-
const [wizardAgentStore, setWizardAgentStore] = useState(null);
|
|
57
|
-
const currentEndpointRef = useRef(null);
|
|
58
|
-
const [history, setHistory] = useState([]);
|
|
59
|
-
const historyIndex = useRef(-1);
|
|
104
|
+
/** 覆盖层(确认框 / 选择器):弹窗与 resolve 生命周期见 use-overlays.ts */
|
|
105
|
+
const { confirmState, pickerState, setConfirmState, setPickerState, resolveConfirm, resolvePicker } = useChatOverlays();
|
|
60
106
|
const sessionRef = useRef(null);
|
|
61
107
|
const [bootError, setBootError] = useState(null);
|
|
62
108
|
const [ready, setReady] = useState(false);
|
|
63
|
-
/**
|
|
64
|
-
const
|
|
65
|
-
/** 最近一次布局,供键盘回调读取总行数 / 视口高度(应用内翻页) */
|
|
66
|
-
const layoutRef = useRef(null);
|
|
109
|
+
/** 视口:滚动状态与翻页 / 按行 / 滚轮换算(唯一入口见 use-chat-viewport.ts) */
|
|
110
|
+
const { viewTop, layoutRef, scrollByPage, scrollByLine, scrollByWheel, scrollToBottom } = useChatViewport();
|
|
67
111
|
/** 本轮是否在生成中(spinner / 输入禁用) */
|
|
68
112
|
const [busy, setBusy] = useState(false);
|
|
113
|
+
/** 正在执行的**阻塞型命令**名(`blocksInput: true` 的 `/update` / `/migrate` …),见 `busySpinnerLabel` */
|
|
114
|
+
const [busyCommand, setBusyCommand] = useState(null);
|
|
115
|
+
/** 生成速率快照(token/s):生成中为实时值,结束后保留本轮平均 */
|
|
116
|
+
const [rate, setRate] = useState(null);
|
|
117
|
+
/**
|
|
118
|
+
* 当前模型 id —— **从会话(即 Agent 定义)读**,不作为 prop 传入。
|
|
119
|
+
*
|
|
120
|
+
* 模型的唯一真相源是 `AgentDefinition.modelId`:所以状态栏、凭据检查、思考状态
|
|
121
|
+
* 与 SDK 实发请求用的永远是同一个值,不会出现「显示 A、实发 B」。
|
|
122
|
+
*/
|
|
123
|
+
const [modelId, setModelId] = useState("");
|
|
124
|
+
/**
|
|
125
|
+
* 思考强度展示文案(关 / 低 / 中 / 高 / 最高 / 开 / —)。
|
|
126
|
+
*
|
|
127
|
+
* 真相在配置里(模型的 `defaultParams`),这里只镜像一份供状态栏用:
|
|
128
|
+
* `/think` 写入后由命令层回调刷新,切模型(会话重建)时靠 `modelId` 变化重读。
|
|
129
|
+
*/
|
|
130
|
+
const [effortView, setEffortView] = useState(null);
|
|
131
|
+
/**
|
|
132
|
+
* 语言切换计数(`/lang`):`t()` 是模块级函数,语言变了已渲染的文案不会自更新,
|
|
133
|
+
* 递增这个计数只为逼 React 重跑一遍渲染函数。
|
|
134
|
+
*/
|
|
135
|
+
const [localeTick, bumpLocale] = useState(0);
|
|
136
|
+
/**
|
|
137
|
+
* IME 光标位置:由光标所在行**渲染后实测**而来(渲染器给的帧内坐标)。
|
|
138
|
+
* 带上 key —— 只有「产生它的那个输入状态」与当前一致时才能用,否则就是上一帧的陈旧值。
|
|
139
|
+
*/
|
|
140
|
+
const [imePosition, setImePosition] = useState(null);
|
|
69
141
|
/** 乐观回显:提交后、真实 user 消息落进 messages 之前,先显示用户提问 */
|
|
70
142
|
const [pendingUser, setPendingUser] = useState(null);
|
|
143
|
+
/**
|
|
144
|
+
* 待发送的粘贴图片(`Ctrl+V` 累积)。
|
|
145
|
+
*
|
|
146
|
+
* 存 base64 而不是落盘:SDK 的 `fileToContentSection()` 正好接受 `{ base64, mime }`,
|
|
147
|
+
* 于是粘贴全程不碰磁盘 —— 也就不会在 `$TMPDIR` 里留下一堆无人清理的 png。
|
|
148
|
+
*/
|
|
149
|
+
const [pastedImages, setPastedImages] = useState([]);
|
|
71
150
|
/** 转录显示起点(/clear 清屏用:隐藏此索引之前的消息,但不改上下文) */
|
|
72
151
|
const [transcriptFrom, setTranscriptFrom] = useState(0);
|
|
152
|
+
/**
|
|
153
|
+
* 当前查看的 Agent 视图:`"main"` 或某个子 Agent 的视图 id。
|
|
154
|
+
*
|
|
155
|
+
* 只影响**消息列表的数据源**(主 Agent 的 `messages` / 子 Agent 自己的 `messages`),
|
|
156
|
+
* 不改上下文、不影响发送目标:发出的消息永远属于主 Agent。
|
|
157
|
+
*/
|
|
158
|
+
const [activeAgentId, setActiveAgentId] = useState("main");
|
|
159
|
+
/** Ctrl+D 双击退出计时 */
|
|
160
|
+
const ctrlDAtRef = useRef(0);
|
|
73
161
|
/**
|
|
74
162
|
* 通知通道:notice / error 走独立栏位,绝不进对话转录(messages)。
|
|
75
163
|
*/
|
|
@@ -77,8 +165,53 @@ export function Chat(props) {
|
|
|
77
165
|
if (noticeChannelRef.current == null)
|
|
78
166
|
noticeChannelRef.current = new NoticeChannel();
|
|
79
167
|
const noticeChannel = noticeChannelRef.current;
|
|
80
|
-
|
|
81
|
-
|
|
168
|
+
/**
|
|
169
|
+
* 通知队列(最近的在最后)。通道内部保留最近 `MAX_NOTICE_HISTORY` 条,
|
|
170
|
+
* 这里只做镜像:单槽 state 会让「同一批摘要 / 分阶段进度」只剩最后一条。
|
|
171
|
+
*/
|
|
172
|
+
const [notices, setNotices] = useState(noticeChannel.notices);
|
|
173
|
+
useEffect(() => noticeChannel.subscribe(setNotices), [noticeChannel]);
|
|
174
|
+
/**
|
|
175
|
+
* SDK 的 warn / error 直接进通知栏 —— **通用通道**,不为某个功能单独接线。
|
|
176
|
+
*
|
|
177
|
+
* 以前 SDK 日志被整体接管到文件里(不然 `console.log` 会撕坏 Ink 的帧),代价是
|
|
178
|
+
* 「SDK 说了什么」用户在界面上一个字都看不见,只能事后翻 sdk.log —— 排查成本极高
|
|
179
|
+
* (连「工具文件把进程杀了」这种事都只能靠猜)。这里注册一个 sink 把 warn/error
|
|
180
|
+
* 引过来:以后 SDK 任何模块只要打日志,界面上自动就有,不必为新特性再传一个回调。
|
|
181
|
+
*
|
|
182
|
+
* 晚绑定、启动期缓冲、去重、封顶都在 `sdk-log.ts` 里做,这里只做接线。
|
|
183
|
+
*/
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
setSdkNoticeSink((level, message) => noticeChannel.push(message, level));
|
|
186
|
+
return () => setSdkNoticeSink(null);
|
|
187
|
+
}, [noticeChannel]);
|
|
188
|
+
/**
|
|
189
|
+
* 配置向导宿主(凭据 / 配置中心):整屏接管与「关闭后让改动生效」见
|
|
190
|
+
* use-wizard-host.ts。这里只提供出口:通知走通知通道、重启 / 重载走会话。
|
|
191
|
+
*/
|
|
192
|
+
const { wizardStep, wizardConfig, wizardPresets, wizardAgents, wizardMcp, wizardAgentStore, openWizard, openKeyEditor, closeWizard, } = useWizardHost({
|
|
193
|
+
modelId,
|
|
194
|
+
notify: (text, tone) => noticeChannel.push(text, tone),
|
|
195
|
+
hasSession: () => sessionRef.current != null,
|
|
196
|
+
restart: () => exit({ restart: true, messages: props.messages }),
|
|
197
|
+
reloadSession: () => {
|
|
198
|
+
void sessionRef.current
|
|
199
|
+
?.reload()
|
|
200
|
+
.then(() => noticeChannel.push(t("notice.reloaded")))
|
|
201
|
+
.catch((error) => noticeChannel.push(t("chat.sessionReloadFailed", { error: error?.message ?? error }), "error"));
|
|
202
|
+
},
|
|
203
|
+
// 向导读快照 / 落盘也走注入:集成测试不该碰真实配置目录
|
|
204
|
+
readers: deps.wizardReaders,
|
|
205
|
+
});
|
|
206
|
+
/**
|
|
207
|
+
* 重挂载附带的系统提示(如 `/model` 的切换结果)。
|
|
208
|
+
*
|
|
209
|
+
* 用 ref 而非 props 直读:本值只在首次挂载消费一次,若写进 create 的依赖数组,
|
|
210
|
+
* 会把「展示一条提示」误变成「重建会话」。
|
|
211
|
+
*/
|
|
212
|
+
const initialNoticeRef = useRef(props.initialNotice);
|
|
213
|
+
/** 钩子带来的首条消息:只在会话建好后发一次,重挂载不再重发 */
|
|
214
|
+
const initialPromptRef = useRef(props.initialPrompt);
|
|
82
215
|
/**
|
|
83
216
|
* 渲染信号 + 合帧:SDK 内容变更 → FrameBuffer 合帧 → setTick 触发重渲染。
|
|
84
217
|
* 转录内容始终从 `agent.messages` 现取,tick 只负责「告诉 React 该重画了」。
|
|
@@ -88,6 +221,30 @@ export function Chat(props) {
|
|
|
88
221
|
if (frameBufferRef.current == null) {
|
|
89
222
|
frameBufferRef.current = new FrameBuffer(() => setTick((t) => t + 1));
|
|
90
223
|
}
|
|
224
|
+
// 思考强度展示:从当前模型的 defaultParams 派生;`/think` 写入后由命令层回调刷新,
|
|
225
|
+
// 切模型(会话重建)时靠 modelId 变化重读。
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
if (!modelId)
|
|
228
|
+
return;
|
|
229
|
+
let alive = true;
|
|
230
|
+
// 档位存在 Agent 定义上(`modelParams`),可选档位在策略表里(`reasoningPreset` 指向),两者都要读
|
|
231
|
+
Promise.all([deps.readConfig(), deps.readAgentStore(), deps.readReasoningPresets()])
|
|
232
|
+
.then(([config, store, presets]) => {
|
|
233
|
+
const model = config.models?.find((item) => item.id === modelId);
|
|
234
|
+
const agentId = props.agentId ?? "default";
|
|
235
|
+
const definition = store.agents.find((item) => item.id === agentId) ?? null;
|
|
236
|
+
if (alive)
|
|
237
|
+
setEffortView(describeEffortView(model, presets, definition));
|
|
238
|
+
})
|
|
239
|
+
.catch(() => {
|
|
240
|
+
if (alive)
|
|
241
|
+
setEffortView(null);
|
|
242
|
+
});
|
|
243
|
+
return () => {
|
|
244
|
+
alive = false;
|
|
245
|
+
};
|
|
246
|
+
// localeTick:切语言后档位文案要重算(它缓存的是已本地化的字符串,不是档位名)
|
|
247
|
+
}, [modelId, props.agentId, localeTick]);
|
|
91
248
|
// 创建会话
|
|
92
249
|
useEffect(() => {
|
|
93
250
|
let disposed = false;
|
|
@@ -102,13 +259,13 @@ export function Chat(props) {
|
|
|
102
259
|
noticeChannel.push(text, tone);
|
|
103
260
|
},
|
|
104
261
|
};
|
|
105
|
-
|
|
106
|
-
modelId: props.modelId,
|
|
262
|
+
deps.createSession({
|
|
107
263
|
agentId: props.agentId,
|
|
108
264
|
messages: props.messages,
|
|
109
265
|
conversationId: props.conversationId,
|
|
110
266
|
conversationName: props.conversationName,
|
|
111
|
-
|
|
267
|
+
// 自动迁移:与手动 /migrate、/handoff 共用同一套「交接方式三选一」选择器
|
|
268
|
+
requestMode: (info) => chooseHandoffMode(setPickerState, t("handoff.pickTitle", { used: info.promptTokens, limit: info.handoffTokens })),
|
|
112
269
|
}, notifier)
|
|
113
270
|
.then((session) => {
|
|
114
271
|
if (disposed) {
|
|
@@ -116,7 +273,21 @@ export function Chat(props) {
|
|
|
116
273
|
return;
|
|
117
274
|
}
|
|
118
275
|
sessionRef.current = session;
|
|
276
|
+
setModelId(session.modelId);
|
|
119
277
|
setReady(true);
|
|
278
|
+
// 重挂载附带的提示只需展示一次(消费后置空,避免再次触发)
|
|
279
|
+
if (initialNoticeRef.current) {
|
|
280
|
+
noticeChannel.push(initialNoticeRef.current);
|
|
281
|
+
initialNoticeRef.current = undefined;
|
|
282
|
+
}
|
|
283
|
+
// shell 钩子:会话就绪后立即把原命令当**用户消息**发出去(不经命令解析)
|
|
284
|
+
if (initialPromptRef.current) {
|
|
285
|
+
const prompt = initialPromptRef.current;
|
|
286
|
+
initialPromptRef.current = undefined;
|
|
287
|
+
setTick((t) => t + 1);
|
|
288
|
+
void runSubmit(prompt, { asMessage: true });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
120
291
|
setTick((t) => t + 1);
|
|
121
292
|
})
|
|
122
293
|
.catch((error) => setBootError(error?.message ?? String(error)));
|
|
@@ -126,169 +297,175 @@ export function Chat(props) {
|
|
|
126
297
|
sessionRef.current?.dispose();
|
|
127
298
|
};
|
|
128
299
|
}, [
|
|
129
|
-
props.modelId,
|
|
130
300
|
props.agentId,
|
|
131
301
|
props.messages,
|
|
132
302
|
props.conversationId,
|
|
133
303
|
props.conversationName,
|
|
134
304
|
]);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
305
|
+
// 速率采样:Spinner 的重渲染只影响它自己,不会带着状态栏一起刷,所以生成中要自己定时读快照。
|
|
306
|
+
// 生成结束(busy → false)时再读一次,拿本轮平均速率并留在状态栏上。
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
const read = () => setRate(sessionRef.current?.rateSample ?? null);
|
|
309
|
+
read();
|
|
310
|
+
if (!busy)
|
|
311
|
+
return;
|
|
312
|
+
const timer = setInterval(read, 250);
|
|
313
|
+
return () => clearInterval(timer);
|
|
314
|
+
}, [busy]);
|
|
315
|
+
/** 清屏但保留上下文:把显示起点推到当前消息末尾 */
|
|
316
|
+
const clearTranscript = () => {
|
|
317
|
+
setTranscriptFrom(sessionRef.current?.messages.length ?? 0);
|
|
318
|
+
noticeChannel.clear();
|
|
140
319
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
320
|
+
/**
|
|
321
|
+
* 输入编辑(文本 / 光标 / 历史 / kill ring / undo / stash):
|
|
322
|
+
* 全部语义在 use-input-editing.ts,这里只把通知出口接上。
|
|
323
|
+
*/
|
|
324
|
+
const { input, cursor, setInputText, insertAtCursor, replaceRange, deleteBeforeCursor, deleteAfterCursor, deleteWordBeforeCursor, deleteWordAfterCursor, deleteToStartOfLine, deleteToEndOfLine, deletePrevWhitespace, yank, undoEdit, toggleStash, moveCursor, moveCursorToLineStart, moveCursorToLineEnd, moveCursorUpRow, moveCursorDownRow, moveCursorByWord, historyPrev, historyNext, clearDraft, } = useInputEditing({
|
|
325
|
+
initialText: props.initialInput,
|
|
326
|
+
notify: (text, tone) => noticeChannel.push(text, tone),
|
|
327
|
+
// 历史来自 messages(唯一真相源):自带图片,`↑` 回到带图消息时附件也一并回来
|
|
328
|
+
historySource: () => userDrafts(sessionRef.current?.messages ?? []),
|
|
329
|
+
restoreImages: (images) => setPastedImages(images),
|
|
330
|
+
});
|
|
331
|
+
/** 斜杠候选菜单的高亮索引;输入一变就回到第一个候选 */
|
|
332
|
+
const [menuIndex, setMenuIndex] = useState(0);
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
setMenuIndex(0);
|
|
335
|
+
}, [input]);
|
|
336
|
+
/** 项目文件索引(`@` 补全的候选源);null = 还没扫过 */
|
|
337
|
+
const [fileIndex, setFileIndex] = useState(null);
|
|
338
|
+
/** 用户按 Esc 主动关掉了 `@` 菜单:输入 / 光标一变就重新允许弹出 */
|
|
339
|
+
const [mentionOff, setMentionOff] = useState(false);
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
setMentionOff(false);
|
|
342
|
+
}, [input, cursor]);
|
|
343
|
+
// 命令候选人
|
|
344
|
+
const slash = input.startsWith("/") && !input.includes("\n") && !input.includes(" ");
|
|
345
|
+
const hints = slash ? matchCommandHints(input.slice(1)) : [];
|
|
346
|
+
/**
|
|
347
|
+
* `@` 文件补全的上下文:光标是否停在一个 `@token` 里(判据见 `mention.ts`)。
|
|
348
|
+
*
|
|
349
|
+
* 与斜杠命令**互斥**:`/` 开头就是在写命令,此时不弹文件菜单。
|
|
350
|
+
*/
|
|
351
|
+
const mention = slash || mentionOff ? null : extractMention(input, cursor);
|
|
352
|
+
const fileMatches = mention && fileIndex ? rankPaths(mention.query, fileIndex) : [];
|
|
353
|
+
/** 索引还没就绪:菜单先占一行「扫描中…」,否则敲下 `@` 后一片空白像没反应 */
|
|
354
|
+
const scanningFiles = mention != null && fileIndex == null;
|
|
355
|
+
/** 当前菜单条数(两种菜单互斥,非零的那个说了算) */
|
|
356
|
+
const menuCount = slash ? hints.length : fileMatches.length;
|
|
357
|
+
/**
|
|
358
|
+
* 菜单**想吃**的行数:候选条数 + 「扫描中…」占位。
|
|
359
|
+
*
|
|
360
|
+
* 实际能拿多少由布局决定(`computeChatLayout` 按输入框上方的剩余空间放行,
|
|
361
|
+
* 不设固定上限)—— 这里交上去的是「想要多少」,渲染与 IME 光标一律读回
|
|
362
|
+
* `layout.hintRows`,三处同源。
|
|
363
|
+
*/
|
|
364
|
+
const menuWant = slash ? hints.length : fileMatches.length + (scanningFiles ? 1 : 0);
|
|
365
|
+
/** 菜单条目:斜杠命令带说明,`@` 路径目录带尾斜杠(提示「选中后继续下钻」) */
|
|
366
|
+
const menuItems = slash
|
|
367
|
+
? hints.map((hint) => ({ key: hint.names[0], label: hint.label, hint: hint.description }))
|
|
368
|
+
: fileMatches.map((entry) => ({
|
|
369
|
+
key: entry.path,
|
|
370
|
+
label: entry.dir ? `${entry.path}/` : entry.path,
|
|
371
|
+
}));
|
|
372
|
+
/** 每次「重新唤起 `@`」都问一次索引:`listProjectPaths` 内部有 15s 缓存,未过期时几乎零成本,
|
|
373
|
+
* 过期则顺手重扫 —— 于是会话里新建的文件不会因为「只扫过一次」而永远看不到。 */
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
if (mention == null)
|
|
376
|
+
return;
|
|
377
|
+
let alive = true;
|
|
378
|
+
void deps.listProjectPaths(process.cwd())
|
|
379
|
+
.then((paths) => {
|
|
380
|
+
if (alive)
|
|
381
|
+
setFileIndex(paths);
|
|
382
|
+
})
|
|
383
|
+
.catch(() => {
|
|
384
|
+
if (alive)
|
|
385
|
+
setFileIndex([]);
|
|
145
386
|
});
|
|
387
|
+
return () => {
|
|
388
|
+
alive = false;
|
|
389
|
+
};
|
|
390
|
+
// 只在「从无菜单到有菜单」时触发:同一 token 内每敲一个键都重扫毫无意义
|
|
391
|
+
}, [mention == null]);
|
|
392
|
+
/**
|
|
393
|
+
* 把 `@` 菜单里高亮的那条补进草稿。
|
|
394
|
+
*
|
|
395
|
+
* 落字走 `replaceRange`:替换的是**整个 token**(`@src/tu` 这种半截路径、或光标停在
|
|
396
|
+
* 中间时右半边残留),并且会记一条撤销快照 —— 补错了 `Ctrl+_` 能退回。
|
|
397
|
+
* 目录带尾斜杠,补完菜单会重新过滤出该目录下的内容,于是可以一路钻下去。
|
|
398
|
+
*/
|
|
399
|
+
const completeMentionSelection = () => {
|
|
400
|
+
if (!mention || fileMatches.length === 0)
|
|
401
|
+
return;
|
|
402
|
+
const entry = fileMatches[Math.max(0, Math.min(menuIndex, fileMatches.length - 1))];
|
|
403
|
+
if (!entry)
|
|
404
|
+
return;
|
|
405
|
+
replaceRange(mention.start, mention.end, mentionInsertText(entry.path, entry.dir));
|
|
146
406
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
/** `/key`:直达「当前模型所用端点」的 API Key 编辑步骤 */
|
|
164
|
-
const openKeyEditor = async () => {
|
|
165
|
-
try {
|
|
166
|
-
const config = await readConfig();
|
|
167
|
-
const credential = resolveCredential(config, props.modelId);
|
|
168
|
-
if (!credential) {
|
|
169
|
-
noticeChannel.push(`模型 ${props.modelId} 未绑定可用端点,请用 /config 检查配置`, "error");
|
|
407
|
+
/**
|
|
408
|
+
* `Ctrl+V`:**先问剪贴板要图片,没有图片就退回粘贴文本**。
|
|
409
|
+
*
|
|
410
|
+
* 顺序不能反 —— 文本一旦先粘进去,再发现「其实剪贴板里是图片」就晚了(草稿里已经
|
|
411
|
+
* 多了一坨东西)。所以永远是「图片优先、文本兑底」,这也就是用户按 Ctrl+V 的默认期待。
|
|
412
|
+
*
|
|
413
|
+
* 异步不阻塞输入:`readClipboardImage()` 要 spawn 一个子进程(几十 ms),期间用户
|
|
414
|
+
* 还能继续打字;回到结果时只做一次 setState / 插字。
|
|
415
|
+
*/
|
|
416
|
+
const pasteClipboard = async () => {
|
|
417
|
+
const result = await deps.readClipboardImage();
|
|
418
|
+
if (result.kind === "image") {
|
|
419
|
+
if (pastedImages.length >= MAX_PASTED_IMAGES) {
|
|
420
|
+
noticeChannel.push(t("notice.imageLimit", { n: MAX_PASTED_IMAGES }), "error");
|
|
170
421
|
return;
|
|
171
422
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
noticeChannel.push(`读取配置失败:${error?.message ?? error}`, "error");
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
/** 向导关闭:渲染变更摘要;若改到当前端点则重建会话(消息保留) */
|
|
181
|
-
const closeWizard = (result) => {
|
|
182
|
-
setWizardStep(null);
|
|
183
|
-
setWizardConfig(null);
|
|
184
|
-
setWizardMcp(null);
|
|
185
|
-
setWizardAgentStore(null);
|
|
186
|
-
for (const line of result.summary)
|
|
187
|
-
noticeChannel.push(`配置已更新:${line}`);
|
|
188
|
-
if (!result.dirty)
|
|
189
|
-
return;
|
|
190
|
-
if (!sessionRef.current) {
|
|
191
|
-
exit({ restart: true, messages: props.messages });
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
const endpointChanged = !!currentEndpointRef.current && result.changedEndpointIds.includes(currentEndpointRef.current);
|
|
195
|
-
if (endpointChanged || result.mcpChanged || result.agentsChanged) {
|
|
196
|
-
sessionRef.current
|
|
197
|
-
.reload()
|
|
198
|
-
.then(() => noticeChannel.push("已按新配置重建会话(消息与上下文保留)"))
|
|
199
|
-
.catch((error) => noticeChannel.push(`重建会话失败:${error?.message ?? error}`, "error"));
|
|
423
|
+
setPastedImages((list) => [...list, result.image]);
|
|
424
|
+
noticeChannel.push(t("notice.imagePasted", { n: pastedImages.length + 1 }));
|
|
425
|
+
return;
|
|
200
426
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const scrollTo = (nextTop) => {
|
|
204
|
-
const L = layoutRef.current;
|
|
205
|
-
if (!L)
|
|
206
|
-
return;
|
|
207
|
-
const maxTop = Math.max(0, L.totalLines - L.budget);
|
|
208
|
-
const clamped = Math.max(0, Math.min(maxTop, nextTop));
|
|
209
|
-
setViewTop(clamped >= maxTop ? null : clamped);
|
|
210
|
-
};
|
|
211
|
-
const scrollByPage = (dir) => {
|
|
212
|
-
const L = layoutRef.current;
|
|
213
|
-
if (!L)
|
|
427
|
+
if (result.kind === "too-large") {
|
|
428
|
+
noticeChannel.push(t("notice.imageTooLarge", { size: formatMegabytes(result.bytes) }), "error");
|
|
214
429
|
return;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
430
|
+
}
|
|
431
|
+
// 没有图片 → 当成普通粘贴:把剪贴板文本插到光标处
|
|
432
|
+
const pasted = await deps.readClipboardText();
|
|
433
|
+
if (pasted.kind === "unavailable") {
|
|
434
|
+
noticeChannel.push(t("notice.clipboardUnavailable"), "error");
|
|
220
435
|
return;
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
setNotice(null);
|
|
228
|
-
};
|
|
229
|
-
// ---- 输入编辑(光标感知)----
|
|
230
|
-
const setInputText = (text) => {
|
|
231
|
-
setInput(text);
|
|
232
|
-
setCursor(Array.from(text).length);
|
|
233
|
-
};
|
|
234
|
-
const insertAtCursor = (text) => {
|
|
235
|
-
const chars = Array.from(input);
|
|
236
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
237
|
-
setInput(chars.slice(0, cp).join("") + text + chars.slice(cp).join(""));
|
|
238
|
-
setCursor(cp + Array.from(text).length);
|
|
239
|
-
};
|
|
240
|
-
const deleteBeforeCursor = () => {
|
|
241
|
-
const chars = Array.from(input);
|
|
242
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
243
|
-
if (cp === 0)
|
|
436
|
+
}
|
|
437
|
+
if (pasted.kind === "too-large") {
|
|
438
|
+
noticeChannel.push(t("notice.textTooLarge", {
|
|
439
|
+
size: Math.round(pasted.bytes / 1024),
|
|
440
|
+
limit: MAX_CLIPBOARD_TEXT_BYTES / 1024,
|
|
441
|
+
}), "error");
|
|
244
442
|
return;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const deleteAfterCursor = () => {
|
|
249
|
-
const chars = Array.from(input);
|
|
250
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
251
|
-
if (cp >= chars.length)
|
|
443
|
+
}
|
|
444
|
+
if (pasted.text.length === 0) {
|
|
445
|
+
noticeChannel.push(t("notice.clipboardEmpty"));
|
|
252
446
|
return;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const len = Array.from(input).length;
|
|
257
|
-
setCursor((c) => Math.max(0, Math.min(len, c + delta)));
|
|
258
|
-
};
|
|
259
|
-
const moveCursorToLineStart = () => {
|
|
260
|
-
const chars = Array.from(input);
|
|
261
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
262
|
-
let i = cp;
|
|
263
|
-
while (i > 0 && chars[i - 1] !== "\n")
|
|
264
|
-
i -= 1;
|
|
265
|
-
setCursor(i);
|
|
266
|
-
};
|
|
267
|
-
const moveCursorToLineEnd = () => {
|
|
268
|
-
const chars = Array.from(input);
|
|
269
|
-
const cp = Math.max(0, Math.min(cursor, chars.length));
|
|
270
|
-
let i = cp;
|
|
271
|
-
while (i < chars.length && chars[i] !== "\n")
|
|
272
|
-
i += 1;
|
|
273
|
-
setCursor(i);
|
|
447
|
+
}
|
|
448
|
+
// 去掉末尾单个换行:剪贴板文本几乎总带一个尾换行,粘完光标原地跳行很莫妙
|
|
449
|
+
insertAtCursor(pasted.text.replace(/\n$/, ""));
|
|
274
450
|
};
|
|
275
|
-
|
|
276
|
-
const slash = input.startsWith("/") && !input.includes("\n") && !input.includes(" ");
|
|
277
|
-
const hints = slash ? matchCommandHints(input.slice(1)) : [];
|
|
278
|
-
const runSubmit = async (text) => {
|
|
451
|
+
const runSubmit = async (text, options = {}) => {
|
|
279
452
|
const trimmed = text.trim();
|
|
280
453
|
if (!trimmed || !sessionRef.current || busy)
|
|
281
454
|
return;
|
|
282
|
-
|
|
283
|
-
historyIndex.current = -1;
|
|
455
|
+
clearDraft();
|
|
284
456
|
scrollToBottom();
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
457
|
+
// 发出去的消息永远属于主 Agent:停在子 Agent 视图上会让用户看不到自己的提问
|
|
458
|
+
setActiveAgentId("main");
|
|
459
|
+
noticeChannel.clear();
|
|
460
|
+
// 斜杠命令:命令名怎么解析、哪些命令会调用模型(要拦输入框),都来自命令元数据
|
|
461
|
+
const command = options.asMessage ? null : parseCommandInput(trimmed);
|
|
462
|
+
if (command) {
|
|
463
|
+
const name = command.name;
|
|
464
|
+
const blocksInput = commandBlocksInput(name);
|
|
465
|
+
if (blocksInput) {
|
|
291
466
|
setBusy(true);
|
|
467
|
+
setBusyCommand(name);
|
|
468
|
+
}
|
|
292
469
|
try {
|
|
293
470
|
await runCommand(name, trimmed, {
|
|
294
471
|
session: sessionRef.current,
|
|
@@ -300,23 +477,30 @@ export function Chat(props) {
|
|
|
300
477
|
openWizard,
|
|
301
478
|
openKeyEditor,
|
|
302
479
|
doExit,
|
|
480
|
+
restartProcess,
|
|
303
481
|
setPickerState,
|
|
304
482
|
setConfirmState,
|
|
305
483
|
setInputText,
|
|
484
|
+
setEffortView,
|
|
485
|
+
refreshLocale: () => bumpLocale((n) => n + 1),
|
|
306
486
|
});
|
|
307
487
|
}
|
|
308
488
|
finally {
|
|
309
|
-
if (blocksInput)
|
|
489
|
+
if (blocksInput) {
|
|
310
490
|
setBusy(false);
|
|
491
|
+
setBusyCommand(null);
|
|
492
|
+
}
|
|
311
493
|
}
|
|
312
494
|
return;
|
|
313
495
|
}
|
|
314
|
-
setHistory((h) => [...h, trimmed]);
|
|
315
496
|
const base = sessionRef.current.messages.filter((m) => m.role === AgentNS.Role.User).length;
|
|
316
|
-
|
|
497
|
+
// 先取快照再清空:`send` 要用同一个数组,而输入区要立刻回到「没有附件」的状态
|
|
498
|
+
const images = pastedImages;
|
|
499
|
+
setPastedImages([]);
|
|
500
|
+
setPendingUser({ text: trimmed, base, images });
|
|
317
501
|
setBusy(true);
|
|
318
502
|
try {
|
|
319
|
-
await sessionRef.current.send(trimmed);
|
|
503
|
+
await sessionRef.current.send(trimmed, images);
|
|
320
504
|
}
|
|
321
505
|
finally {
|
|
322
506
|
setBusy(false);
|
|
@@ -326,8 +510,68 @@ export function Chat(props) {
|
|
|
326
510
|
const doExit = () => {
|
|
327
511
|
exit("done");
|
|
328
512
|
};
|
|
513
|
+
/**
|
|
514
|
+
* 真·重启进程(`/update` 装完新版本后调用)。
|
|
515
|
+
*
|
|
516
|
+
* 不能复用 `exit({ restart: true })`:那条路只是 `continue` 回 `mount(<Chat/>)`,
|
|
517
|
+
* 同一个进程、内存里还是旧模块图——对「磁盘上的代码变了」这种升级等于没装。
|
|
518
|
+
* 这里退到 shell 的视角:**spawn 一个新的自己**(新进程重新加载新 dist),
|
|
519
|
+
* 父进程在挂起态里等子进程退出,然后跟着退出。
|
|
520
|
+
*
|
|
521
|
+
* 三个必须注意的细节:
|
|
522
|
+
*
|
|
523
|
+
* 1. **在挂起态里退出**。`suspendTerminal` 的 `beginSuspend()` 会 `pauseInput()`
|
|
524
|
+
* (raw 模式关闭),而 `endSuspend()` 会 `resumeInput()` 把它重新打开。若等
|
|
525
|
+
* `suspendTerminal` 返回后再 `process.exit`,终端就停在 raw 模式,回到 shell
|
|
526
|
+
* 后按键全是乱码。所以子进程一结束就**就地**退出。
|
|
527
|
+
* 2. **先关鼠标上报**。`mount()` 按 Ink 实例开关它,而本实例此刻只是「挂起」并未
|
|
528
|
+
* 退出 —— 不关的话,子进程若异常死亡,终端会一直把滚轮写成转义序列。
|
|
529
|
+
* 3. **不转发 `process.argv.slice(2)`**。`ai --tui --new "..."` 那套是 shell 兜底
|
|
530
|
+
* 钩子的一次性载荷,重启时重放会把同一条提示词再发一遍。新进程按常规启动即
|
|
531
|
+
* 续接上一轮会话(重启前已落盘)。
|
|
532
|
+
*/
|
|
533
|
+
const restartProcess = () => suspendTerminal(() => new Promise((resolve) => {
|
|
534
|
+
const entry = process.argv[1];
|
|
535
|
+
if (!entry) {
|
|
536
|
+
// 拿不到入口脚本(理论上不会发生):不重启,退回 TUI,由调用方收尾
|
|
537
|
+
resolve();
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
disableMouseTracking();
|
|
541
|
+
const child = spawn(process.execPath, [entry], { stdio: "inherit" });
|
|
542
|
+
child.on("error", () => process.exit(1));
|
|
543
|
+
child.on("exit", (code) => process.exit(code ?? 0));
|
|
544
|
+
}));
|
|
545
|
+
/** 本次会话已出现的子 Agent(渲染期现取;`sessionRef` 在首次渲染时为 null) */
|
|
546
|
+
const subAgentViews = sessionRef.current?.subAgents ?? [];
|
|
547
|
+
/**
|
|
548
|
+
* Agent 栏目切换(← / →):在「主 Agent + 各子 Agent」之间循环。
|
|
549
|
+
*
|
|
550
|
+
* 键位分流见下方两个 `useInput`:输入框**为空**或**生成中**(输入框已被 Spinner 顶替)
|
|
551
|
+
* 时,左右键本来就无事可做,正好用来切换;输入框**有内容**时左右键仍然是移光标——
|
|
552
|
+
* 不能为了切栏目把文本编辑的左右移动废掉。
|
|
553
|
+
*/
|
|
554
|
+
const switchAgentView = (dir) => {
|
|
555
|
+
const ids = ["main", ...subAgentViews.map((item) => item.id)];
|
|
556
|
+
// 旧 id 已失效(会话重建)时 indexOf 为 -1,归一后从主 Agent 起步
|
|
557
|
+
const current = Math.max(0, ids.indexOf(activeAgentId));
|
|
558
|
+
setActiveAgentId(ids[(current + dir + ids.length) % ids.length]);
|
|
559
|
+
scrollToBottom();
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* 两个 `useInput`(空闲 / 忙碌)共用的键位上下文 —— 判定逻辑在 common-keys.ts。
|
|
563
|
+
* 放这里而不是各自内联,是为了让「什么时候能滚、Ctrl+D 怎么退」只有一份定义。
|
|
564
|
+
*/
|
|
565
|
+
const scrollKeys = { scrollByWheel, scrollByPage, scrollByLine };
|
|
566
|
+
const ctrlDExit = {
|
|
567
|
+
lastAt: ctrlDAtRef,
|
|
568
|
+
notify: () => noticeChannel.push(t("notice.pressCtrlDAgain")),
|
|
569
|
+
exit: doExit,
|
|
570
|
+
};
|
|
329
571
|
// 输入处理
|
|
330
572
|
useInput((char, key) => {
|
|
573
|
+
// 按键诊断(AIZ_DEBUG_KEYS=1):必须在任何 return 之前记录,否则被吞掉的键不会留痕
|
|
574
|
+
keyDebug(char, key);
|
|
331
575
|
if (bootError) {
|
|
332
576
|
if (char === "k" || char === "K") {
|
|
333
577
|
void openWizard({ kind: "menu" });
|
|
@@ -337,52 +581,129 @@ export function Chat(props) {
|
|
|
337
581
|
exit("done");
|
|
338
582
|
return;
|
|
339
583
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (key.pageUp) {
|
|
343
|
-
scrollByPage(-1);
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
if (key.pageDown) {
|
|
347
|
-
scrollByPage(1);
|
|
584
|
+
// 回看历史类按键(滚轮 / PgUp/PgDn / ⌘[ ⌘] / ⌘; ⌘' / Alt+V)与忙碌态共用
|
|
585
|
+
if (handleScrollKey(char, key, scrollKeys))
|
|
348
586
|
return;
|
|
349
|
-
}
|
|
350
587
|
if (key.return && (key.ctrl || key.meta || key.shift)) {
|
|
351
588
|
insertAtCursor("\n");
|
|
352
589
|
return;
|
|
353
590
|
}
|
|
354
591
|
if (char === "c" && key.ctrl) {
|
|
592
|
+
// Claude Code:生成中中断;空闲时有草稿就先清空,已空则退出
|
|
355
593
|
if (busy)
|
|
356
594
|
sessionRef.current?.abort();
|
|
595
|
+
else if (input.length > 0) {
|
|
596
|
+
setInputText("");
|
|
597
|
+
noticeChannel.push(t("notice.inputCleared"));
|
|
598
|
+
}
|
|
357
599
|
else
|
|
358
600
|
void doExit();
|
|
359
601
|
return;
|
|
360
602
|
}
|
|
361
|
-
if (char === "d" && key.ctrl) {
|
|
362
|
-
|
|
603
|
+
if (char === "d" && key.ctrl && input.length > 0) {
|
|
604
|
+
// Claude Code:有草稿时删光标后一个字符(空闲态独有)
|
|
605
|
+
deleteAfterCursor();
|
|
363
606
|
return;
|
|
364
607
|
}
|
|
608
|
+
if (handleCtrlDExit(char, key, ctrlDExit))
|
|
609
|
+
return;
|
|
365
610
|
if (char === "l" && key.ctrl) {
|
|
366
611
|
clearTranscript();
|
|
367
612
|
return;
|
|
368
613
|
}
|
|
614
|
+
// ---- kill / yank / undo / stash(照抄 Claude Code / readline)----
|
|
369
615
|
if (char === "u" && key.ctrl) {
|
|
370
|
-
|
|
616
|
+
// 删到行首。macOS 上 ⌘⌫ 会被终端映射成 Ctrl+U,故不能做成「清空全部」
|
|
617
|
+
deleteToStartOfLine();
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (char === "k" && key.ctrl) {
|
|
621
|
+
deleteToEndOfLine();
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (char === "w" && key.ctrl) {
|
|
625
|
+
// 删到前一空白(标点不切分:`src/utils/foo.ts` 一次删完)
|
|
626
|
+
deletePrevWhitespace();
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
if (char === "y" && key.ctrl) {
|
|
630
|
+
yank(false);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (char === "y" && key.meta) {
|
|
634
|
+
yank(true);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
// Ctrl+_ / Ctrl+Shift+-:撤销上一次输入编辑
|
|
638
|
+
if ((char === "_" && key.ctrl) || (char === "-" && key.ctrl && key.shift)) {
|
|
639
|
+
undoEdit();
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
if (char === "s" && key.ctrl) {
|
|
643
|
+
toggleStash();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if ((char === "v" && key.ctrl) || (key.super && (char === "v" || char === "V"))) {
|
|
647
|
+
// 剪贴板里有图片就附在消息上(发送时转成内容块),没有就退回粘贴文本
|
|
648
|
+
void pasteClipboard();
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
// readline 的行首 / 行尾(macOS 上部分终端把 ⌘← / ⌘→ 发成 ^A / ^E)
|
|
652
|
+
if (char === "a" && key.ctrl) {
|
|
653
|
+
moveCursorToLineStart();
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
if (char === "e" && key.ctrl) {
|
|
657
|
+
moveCursorToLineEnd();
|
|
371
658
|
return;
|
|
372
659
|
}
|
|
373
660
|
if (char === "j" && key.ctrl) {
|
|
374
661
|
insertAtCursor("\n");
|
|
375
662
|
return;
|
|
376
663
|
}
|
|
377
|
-
|
|
378
|
-
|
|
664
|
+
// Ctrl+P / Ctrl+N:历史上下(Claude Code 语义;换行改用 Ctrl+J / Alt+Enter)
|
|
665
|
+
if ((char === "p" && key.ctrl) || (char === "n" && key.ctrl)) {
|
|
666
|
+
const up = char === "p";
|
|
667
|
+
if (menuCount > 0) {
|
|
668
|
+
// 同上:视觉「上」(Ctrl+P)是 +1
|
|
669
|
+
setMenuIndex((i) => (up ? (i + 1) % menuCount : (i - 1 + menuCount) % menuCount));
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if (up)
|
|
673
|
+
historyPrev();
|
|
674
|
+
else
|
|
675
|
+
historyNext();
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
// 按词删除:Alt+Backspace / Ctrl+Backspace 删前一个词;Alt+D / Ctrl+Delete 删后一个词。
|
|
679
|
+
// 必须在下面「单字符 Backspace/Delete」之前判定,否则带修饰键的删除只掉一个字符。
|
|
680
|
+
if (key.backspace && (key.ctrl || key.meta || key.super)) {
|
|
681
|
+
deleteWordBeforeCursor();
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (key.delete && (key.ctrl || key.meta || key.super)) {
|
|
685
|
+
deleteWordAfterCursor();
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (char === "d" && key.meta) {
|
|
689
|
+
deleteWordAfterCursor();
|
|
379
690
|
return;
|
|
380
691
|
}
|
|
381
692
|
if (key.return) {
|
|
693
|
+
// `@` 菜单开着时回车 = 补全(不发送):让「选完继续接着写」成为默认动作,
|
|
694
|
+
// 否则选完就得再敲一个空格才能换行/继续,很容易误发半截消息。
|
|
695
|
+
if (mention && fileMatches.length > 0) {
|
|
696
|
+
completeMentionSelection();
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
382
699
|
void runSubmit(resolveSubmitText(input, hints, menuIndex));
|
|
383
700
|
return;
|
|
384
701
|
}
|
|
385
|
-
if (key.tab &&
|
|
702
|
+
if (key.tab && menuCount > 0) {
|
|
703
|
+
if (mention) {
|
|
704
|
+
completeMentionSelection();
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
386
707
|
setInputText(`/${hints[menuIndex]?.names[0] ?? ""} `);
|
|
387
708
|
return;
|
|
388
709
|
}
|
|
@@ -391,42 +712,53 @@ export function Chat(props) {
|
|
|
391
712
|
scrollByLine(key.upArrow ? -1 : 1);
|
|
392
713
|
return;
|
|
393
714
|
}
|
|
394
|
-
if (
|
|
395
|
-
|
|
715
|
+
if (menuCount > 0) {
|
|
716
|
+
// 底部锚定菜单里**下标大 = 视觉靠上**(`items[0]` 贴着输入框,越往后越往上),
|
|
717
|
+
// 所以视觉「上」是 +1、视觉「下」是 −1;取模环绕:到顶溢出回到底部、到底溢出回到顶部。
|
|
718
|
+
// 写反了方向就与视觉相反 —— 只有 ≥ 3 条候选时才能从测试里看出来。
|
|
719
|
+
setMenuIndex((i) => key.upArrow ? (i + 1) % menuCount : (i - 1 + menuCount) % menuCount);
|
|
396
720
|
return;
|
|
397
721
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
setInputText(history[idx]);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
722
|
+
// 多行输入:先按**视觉行**走光标(含软折行,宽度与渲染一致),走到首/末行才翻历史
|
|
723
|
+
const wrapWidth = Math.max(4, (columns ?? 80) - 4);
|
|
724
|
+
if (key.upArrow ? moveCursorUpRow(wrapWidth) : moveCursorDownRow(wrapWidth))
|
|
725
|
+
return;
|
|
726
|
+
if (key.upArrow)
|
|
727
|
+
historyPrev();
|
|
728
|
+
else
|
|
729
|
+
historyNext();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
// Agent 栏目:输入框为空时光标停在 0,←/→ 本无作用 → 拿来切换主 / 子 Agent
|
|
733
|
+
if ((key.leftArrow || key.rightArrow) && input.length === 0 && subAgentViews.length > 0) {
|
|
734
|
+
switchAgentView(key.leftArrow ? -1 : 1);
|
|
414
735
|
return;
|
|
415
736
|
}
|
|
416
737
|
if (key.leftArrow) {
|
|
417
|
-
if (key.ctrl || key.meta)
|
|
418
|
-
|
|
738
|
+
if (key.ctrl || key.meta || key.super)
|
|
739
|
+
moveCursorByWord(-1);
|
|
419
740
|
else
|
|
420
741
|
moveCursor(-1);
|
|
421
742
|
return;
|
|
422
743
|
}
|
|
423
744
|
if (key.rightArrow) {
|
|
424
|
-
if (key.ctrl || key.meta)
|
|
425
|
-
|
|
745
|
+
if (key.ctrl || key.meta || key.super)
|
|
746
|
+
moveCursorByWord(1);
|
|
426
747
|
else
|
|
427
748
|
moveCursor(1);
|
|
428
749
|
return;
|
|
429
750
|
}
|
|
751
|
+
// 跨词移动的「兜底键」:macOS 上 Option+←/→ 往往发的是 ESC b / ESC f
|
|
752
|
+
// (readline 的 backward-word / forward-word),并不带 leftArrow 标记;
|
|
753
|
+
// 而 Ctrl+←/→ 常被系统「Mission Control → 左右切换空间」截走,应用根本收不到。
|
|
754
|
+
if (char === "b" && key.meta) {
|
|
755
|
+
moveCursorByWord(-1);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
if (char === "f" && key.meta) {
|
|
759
|
+
moveCursorByWord(1);
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
430
762
|
if (key.home) {
|
|
431
763
|
moveCursorToLineStart();
|
|
432
764
|
return;
|
|
@@ -436,8 +768,25 @@ export function Chat(props) {
|
|
|
436
768
|
return;
|
|
437
769
|
}
|
|
438
770
|
if (key.escape) {
|
|
439
|
-
|
|
440
|
-
|
|
771
|
+
// `@` 菜单开着时,Esc 只关菜单:清草稿太粗暴(`@` 打一半按 Esc 会连正文一起没)
|
|
772
|
+
if (mention && menuWant > 0) {
|
|
773
|
+
setMentionOff(true);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
// 有附件时先清附件(草稿保留)——误粘一张图后总得有个退路,
|
|
777
|
+
// 而又不能为了这个把 ESC 变成「清空一切」的随机键
|
|
778
|
+
if (!busy && pastedImages.length > 0) {
|
|
779
|
+
setPastedImages([]);
|
|
780
|
+
noticeChannel.push(t("notice.imagesCleared"));
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
// Claude Code:生成中 Esc = 中断本轮;否则清空草稿并回到底部
|
|
784
|
+
if (busy)
|
|
785
|
+
sessionRef.current?.abort();
|
|
786
|
+
else {
|
|
787
|
+
setInputText("");
|
|
788
|
+
scrollToBottom();
|
|
789
|
+
}
|
|
441
790
|
return;
|
|
442
791
|
}
|
|
443
792
|
if (key.backspace) {
|
|
@@ -448,7 +797,7 @@ export function Chat(props) {
|
|
|
448
797
|
deleteAfterCursor();
|
|
449
798
|
return;
|
|
450
799
|
}
|
|
451
|
-
if (char && !key.ctrl && !key.meta) {
|
|
800
|
+
if (char && !key.ctrl && !key.meta && !key.super) {
|
|
452
801
|
insertAtCursor(char);
|
|
453
802
|
}
|
|
454
803
|
},
|
|
@@ -458,98 +807,196 @@ export function Chat(props) {
|
|
|
458
807
|
{ isActive: !busy && !confirmState && !pickerState && !wizardStep });
|
|
459
808
|
// 忙碌期(生成 / 迁移中)专用:输入框不可编辑,仅保留「中止(Ctrl+C) / 退出(Ctrl+D) / 回看滚动」。
|
|
460
809
|
useInput((char, key) => {
|
|
461
|
-
|
|
810
|
+
keyDebug(char, key);
|
|
811
|
+
// 忙碌期只剩「中止 / 退出 / 回看」,滚轮同样生效(生成时正是最想往回看的时机)
|
|
812
|
+
if (handleScrollKey(char, key, scrollKeys))
|
|
462
813
|
return;
|
|
463
814
|
if (char === "c" && key.ctrl) {
|
|
464
815
|
sessionRef.current?.abort();
|
|
465
816
|
return;
|
|
466
817
|
}
|
|
467
|
-
if (
|
|
468
|
-
|
|
818
|
+
if (key.escape) {
|
|
819
|
+
// 忙碌期 Esc 也充当「中断」(与 Claude Code 一致)
|
|
820
|
+
sessionRef.current?.abort();
|
|
469
821
|
return;
|
|
470
822
|
}
|
|
471
|
-
if (key
|
|
472
|
-
|
|
823
|
+
if (handleCtrlDExit(char, key, ctrlDExit))
|
|
824
|
+
return;
|
|
825
|
+
if ((key.upArrow || key.downArrow) && (key.shift || key.meta || key.super)) {
|
|
826
|
+
scrollByLine(key.upArrow ? -1 : 1);
|
|
473
827
|
return;
|
|
474
828
|
}
|
|
475
|
-
|
|
476
|
-
|
|
829
|
+
// Agent 栏目:生成中输入框已失活,←/→ 空闲 → 直接切换(此时最想看子 Agent 在干什么)
|
|
830
|
+
if ((key.leftArrow || key.rightArrow) && subAgentViews.length > 0) {
|
|
831
|
+
switchAgentView(key.leftArrow ? -1 : 1);
|
|
477
832
|
return;
|
|
478
833
|
}
|
|
479
|
-
if (
|
|
480
|
-
|
|
834
|
+
if (char === "v" && key.super) {
|
|
835
|
+
scrollByPage(-1);
|
|
481
836
|
return;
|
|
482
837
|
}
|
|
483
838
|
}, { isActive: busy && !confirmState && !pickerState && !wizardStep });
|
|
484
839
|
// 配置向导:整屏接管(凭据设置 / 配置中心),关闭后回到对话屏
|
|
485
840
|
if (wizardStep && wizardConfig) {
|
|
486
|
-
return (_jsx(ConfigWizard, { config: wizardConfig, initialStep: wizardStep, closeOnSave: wizardStep.kind !== "menu", agents: wizardAgents, mcp: wizardMcp ?? undefined, agentStore: wizardAgentStore ?? undefined, onSave: saveConfig, onSaveMcp: async (scope, cfg) => {
|
|
487
|
-
await writeMcpConfig(cfg, scope);
|
|
841
|
+
return (_jsx(ConfigWizard, { config: wizardConfig, reasoningPresets: wizardPresets, initialStep: wizardStep, closeOnSave: wizardStep.kind !== "menu", agents: wizardAgents, mcp: wizardMcp ?? undefined, agentStore: wizardAgentStore ?? undefined, onSave: deps.saveConfig, onSaveMcp: async (scope, cfg) => {
|
|
842
|
+
await deps.writeMcpConfig(cfg, scope);
|
|
488
843
|
}, onClose: closeWizard }));
|
|
489
844
|
}
|
|
490
845
|
if (bootError) {
|
|
491
846
|
setCursorPosition(undefined);
|
|
492
|
-
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [
|
|
847
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [_jsx(Text, { color: theme.error, wrap: "truncate", children: t("chat.bootFailed", { error: bootError }) }), _jsx(Text, { color: theme.dim, wrap: "truncate", children: t("chat.bootHint") })] }));
|
|
493
848
|
}
|
|
494
849
|
const session = sessionRef.current;
|
|
495
850
|
const lastTokens = session?.lastUsage?.total_tokens;
|
|
496
851
|
const totalTokens = session?.totalUsage.total_tokens;
|
|
497
852
|
const cols = columns ?? 80;
|
|
498
853
|
const messages = session?.messages ?? [];
|
|
854
|
+
const subAgents = session?.subAgents ?? [];
|
|
855
|
+
/** 当前查看的子 Agent;不在列表里(会话重建后 id 失效)时回落到主 Agent */
|
|
856
|
+
const activeSub = subAgents.find((item) => item.id === activeAgentId) ?? null;
|
|
499
857
|
const userCount = messages.filter((m) => m.role === AgentNS.Role.User).length;
|
|
500
|
-
|
|
501
|
-
const
|
|
858
|
+
// 乐观回显只属于主 Agent 的视图(子 Agent 不会收到用户直接发的消息)
|
|
859
|
+
const showPending = !activeSub && pendingUser != null && userCount <= pendingUser.base;
|
|
860
|
+
// 子 Agent 视图读它**自己**的 messages(从第 0 条起,不受主会话 /clear 的显示起点影响)
|
|
861
|
+
const transcript = transcriptLines(activeSub ? activeSub.agent.messages : messages.slice(transcriptFrom), cols);
|
|
862
|
+
/**
|
|
863
|
+
* 空对话:对话区顶部展示品牌区(logo + 标语 + 版本)。
|
|
864
|
+
*
|
|
865
|
+
* 判据里必须带 `showPending` —— 用户刚敲下第一条消息、乐观回显已经上屏,
|
|
866
|
+
* 这时欢迎块要立刻让位,不能等消息真正落地。
|
|
867
|
+
*/
|
|
868
|
+
const showWelcome = !activeSub && !showPending && messages.length === 0;
|
|
869
|
+
if (showWelcome)
|
|
870
|
+
transcript.unshift(...welcomeLines({ columns: cols }));
|
|
502
871
|
if (showPending) {
|
|
503
|
-
|
|
872
|
+
// 带粘贴图片的消息:乐观回显要与实际发送的结构一致(文本段 + 图片占位块),
|
|
873
|
+
// 否则图片那几条会在真实消息落地前「消失」一下。
|
|
874
|
+
const images = pendingUser.images ?? [];
|
|
875
|
+
transcript.push(...messageToLines({
|
|
876
|
+
id: "__pending_user",
|
|
877
|
+
role: AgentNS.Role.User,
|
|
878
|
+
content: images.length > 0
|
|
879
|
+
? [
|
|
880
|
+
{ type: "text", text: pendingUser.text },
|
|
881
|
+
...images.map(() => ({ type: "image_url", image_url: { url: "" } })),
|
|
882
|
+
]
|
|
883
|
+
: pendingUser.text,
|
|
884
|
+
}, cols));
|
|
504
885
|
}
|
|
505
|
-
const noticeTextLines =
|
|
886
|
+
const noticeTextLines = noticeLines(notices, cols);
|
|
887
|
+
/** Agent 栏目条目:无子 Agent 时整条栏目不存在(不占高度、也不接管左右键) */
|
|
888
|
+
const agentTabs = subAgents.length > 0
|
|
889
|
+
? [
|
|
890
|
+
{ id: "main", label: t("agentTabs.main") },
|
|
891
|
+
...subAgents.map((item) => ({
|
|
892
|
+
id: item.id,
|
|
893
|
+
label: t("agentTabs.sub", { n: item.index }),
|
|
894
|
+
status: item.status,
|
|
895
|
+
})),
|
|
896
|
+
]
|
|
897
|
+
: [];
|
|
898
|
+
const activeTabId = activeSub ? activeSub.id : "main";
|
|
899
|
+
const agentTabLines = agentTabs.length > 0 ? AGENT_TABS_LINES : 0;
|
|
900
|
+
// 状态栏:先按当前状态算出「折行后实际几行」,交给布局预留高度(否则窄屏下一旦提示折行,
|
|
901
|
+
// 整帧就会高出一行,把输入框顶出屏幕)。这里用 `viewTop` 状态判断滚动,而不是
|
|
902
|
+
// `layout.scrolled` —— 后者要等布局算完才有,会与行数测量形成循环。
|
|
903
|
+
const statusProps = {
|
|
904
|
+
model: modelId,
|
|
905
|
+
agent: props.agentId ?? "default",
|
|
906
|
+
effort: effortView?.text ?? null,
|
|
907
|
+
effortDimmed: effortView?.dimmed ?? false,
|
|
908
|
+
lastTokens,
|
|
909
|
+
totalTokens,
|
|
910
|
+
busy,
|
|
911
|
+
hint: !ready
|
|
912
|
+
? t("input.hint.initializing")
|
|
913
|
+
: viewTop != null
|
|
914
|
+
? t("input.hint.scrolling")
|
|
915
|
+
: t("input.hint.ready"),
|
|
916
|
+
rate,
|
|
917
|
+
columns: cols,
|
|
918
|
+
};
|
|
919
|
+
const statusRows = statusBarRows(statusProps, cols);
|
|
920
|
+
/** 附件提示行:有粘贴图片时占 1 行(与 `computeChatLayout` 的 `attachmentLines` 同一个判据) */
|
|
921
|
+
const attachmentLines = pastedImages.length > 0 ? 1 : 0;
|
|
506
922
|
const layout = computeChatLayout({
|
|
507
923
|
columns: cols,
|
|
508
924
|
rows: usableFrameRows(rows ?? 24),
|
|
509
925
|
transcript,
|
|
510
926
|
input,
|
|
511
927
|
busy,
|
|
512
|
-
hintCount:
|
|
928
|
+
hintCount: menuWant,
|
|
513
929
|
noticeCount: noticeTextLines.length,
|
|
930
|
+
attachmentLines,
|
|
931
|
+
agentTabLines,
|
|
514
932
|
overlay: confirmState ? "confirm" : pickerState ? "picker" : "none",
|
|
515
933
|
pickerItems: pickerState?.items.length ?? 0,
|
|
516
934
|
viewTop,
|
|
935
|
+
statusBarLines: statusRows.length,
|
|
936
|
+
// 空对话的品牌块落在对话区垂直中部(贴顶太空、贴底太挤)
|
|
937
|
+
anchor: showWelcome ? "center" : undefined,
|
|
517
938
|
});
|
|
518
939
|
layoutRef.current = layout;
|
|
519
940
|
const isPlaceholder = input.length === 0;
|
|
520
|
-
const inputLayout = layoutInput(isPlaceholder ? "
|
|
941
|
+
const inputLayout = layoutInput(isPlaceholder ? t("input.placeholder") : input, isPlaceholder ? 0 : cursor, Math.max(4, cols - 4));
|
|
521
942
|
const bodyLines = inputLayout.lines;
|
|
522
|
-
|
|
943
|
+
/**
|
|
944
|
+
* 输入区可见窗口:最多 `INPUT_MAX_ROWS` 行,且**跟随光标**(与 `computeChatLayout`
|
|
945
|
+
* 的 `inputHeight` 同源)。`cursorRowIndex` 是**窗口内**的行号 —— 渲染用哪一行、
|
|
946
|
+
* 硬件光标 y 都基于它;用全文本的行号会让 IME 候选框跑到屏外。
|
|
947
|
+
*/
|
|
948
|
+
const inputWin = inputWindow(bodyLines.length, inputLayout.cursorRow);
|
|
949
|
+
const shownLines = bodyLines.slice(inputWin.from, inputWin.to);
|
|
950
|
+
// 光标所在行的三段拆分(与 `CursorInputRow` 的渲染一一对应)
|
|
951
|
+
const cursorRowIndex = inputLayout.cursorRow - inputWin.from;
|
|
952
|
+
const cursorRowChars = graphemes(shownLines[cursorRowIndex] ?? "");
|
|
953
|
+
const cursorColInRow = Math.min(inputLayout.cursorCol, cursorRowChars.length);
|
|
954
|
+
const cursorBefore = cursorRowChars.slice(0, cursorColInRow).join("");
|
|
955
|
+
const cursorAt = cursorRowChars[cursorColInRow] ?? " ";
|
|
956
|
+
const cursorAfter = cursorRowChars.slice(cursorColInRow + 1).join("");
|
|
957
|
+
/** 实测结果的身份标记:输入段落一改,上一帧的实测值就作废 */
|
|
958
|
+
const cursorKey = `${cursorRowIndex}\u0000${cursorBefore}\u0000${cursorAt}\u0000${cursorAfter}`;
|
|
959
|
+
/** 渲染后实测(值不变则不会重渲染);闭包捕获当帧的 key,保证标的是「这一帧」的结果 */
|
|
960
|
+
const onCursorMeasure = (position) => {
|
|
961
|
+
setImePosition((prev) => prev && prev.position.x === position.x && prev.position.y === position.y
|
|
962
|
+
? prev
|
|
963
|
+
: { key: cursorKey, position });
|
|
964
|
+
};
|
|
965
|
+
// 把终端硬件光标移到编辑光标处,让 IME(输入法)候选框正确定位:
|
|
966
|
+
// 首选「渲染器实测」(宽字符 / emoji 的宽度由 Ink 自己算,不会偏);
|
|
967
|
+
// 首次渲染还没量到时,退回手算值顶一帧(下一帧即被实测值纠正)。
|
|
523
968
|
if (!busy && !confirmState && !pickerState) {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
969
|
+
const measured = imePosition && imePosition.key === cursorKey ? imePosition.position : null;
|
|
970
|
+
setCursorPosition(measured ??
|
|
971
|
+
computeInputCursorPosition({
|
|
972
|
+
transcriptLines: layout.lines.length,
|
|
973
|
+
// Agent 栏目与通知栏都夹在对话区与输入行之间:漏算会让硬件光标整体偏上
|
|
974
|
+
agentTabCount: agentTabLines,
|
|
975
|
+
noticeCount: noticeTextLines.length,
|
|
976
|
+
attachmentCount: attachmentLines,
|
|
977
|
+
hintCount: layout.hintRows,
|
|
978
|
+
cursorRow: cursorRowIndex,
|
|
979
|
+
cursorCol: inputLayout.cursorCol,
|
|
980
|
+
lineText: bodyLines[inputLayout.cursorRow] ?? "",
|
|
981
|
+
placeholder: isPlaceholder,
|
|
982
|
+
}));
|
|
532
983
|
}
|
|
533
984
|
else {
|
|
534
985
|
setCursorPosition(undefined);
|
|
535
986
|
}
|
|
536
|
-
return (_jsxs(Box, { flexDirection: "column", width: cols, children: [layout.lines.map((line) => (_jsx(LineView, { line: line }, line.key))), confirmState ? (_jsx(Confirm, { question: confirmState.question, onAnswer: resolveConfirm })) : pickerState ? (_jsx(PickerOverlay, { title: pickerState.title, items: pickerState.items, columns: cols, onPick: resolvePicker })) : (_jsxs(Box, { flexDirection: "column", children: [
|
|
537
|
-
const prompt = i === 0 ? (_jsx(Text, { color: theme.brand[0], bold: true, children: "❯ " })) : (_jsx(Text, { children: " " }));
|
|
987
|
+
return (_jsxs(Box, { flexDirection: "column", width: cols, children: [layout.lines.map((line) => (_jsx(LineView, { line: line }, line.key))), confirmState ? (_jsx(Confirm, { question: confirmState.question, onAnswer: resolveConfirm })) : pickerState ? (_jsx(PickerOverlay, { title: pickerState.title, items: pickerState.items, columns: cols, onPick: resolvePicker })) : (_jsxs(Box, { flexDirection: "column", children: [agentTabs.length > 0 ? _jsx(AgentTabs, { tabs: agentTabs, activeId: activeTabId }) : null, _jsx(NoticeBar, { lines: noticeTextLines }), attachmentLines > 0 ? _jsx(PastedImagesBar, { count: pastedImages.length }) : null, menuWant > 0 ? (_jsx(BottomMenu, { items: menuItems, selected: menuIndex, maxRows: layout.hintRows, columns: cols, topLine: scanningFiles ? t("mention.scanning") : undefined })) : null, _jsx(Box, { paddingX: 1, children: _jsx(Text, { color: theme.border, wrap: "truncate", children: "─".repeat(Math.max(1, cols - 2)) }) }), _jsx(Box, { flexDirection: "column", paddingX: 1, children: busy ? (_jsx(Spinner, { label: busySpinnerLabel(sessionRef.current?.phase ?? null, busyCommand) })) : (shownLines.map((line, i) => {
|
|
988
|
+
const prompt = i === 0 && inputWin.from === 0 ? (_jsx(Text, { color: theme.brand[0], bold: true, children: "❯ " })) : (_jsx(Text, { children: " " }));
|
|
538
989
|
if (isPlaceholder) {
|
|
539
|
-
|
|
990
|
+
// 占位态不画「假光标」(那个行尾的 ▏):硬件光标这时就停在提示语开头
|
|
991
|
+
// (x = 前缀宽),终端自己会把它显示出来;再画一个方块等于屏幕上两个光标,
|
|
992
|
+
// 而且位置还在提示语末尾,反而误导。
|
|
993
|
+
return (_jsxs(Text, { wrap: "truncate", children: [prompt, _jsx(Text, { color: theme.faint, children: line })] }, i));
|
|
540
994
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const at = rowChars[inputLayout.cursorCol];
|
|
545
|
-
const after = rowChars.slice(inputLayout.cursorCol + 1).join("");
|
|
546
|
-
return (_jsxs(Text, { wrap: "truncate", children: [prompt, _jsx(Text, { children: before }), _jsx(Text, { inverse: true, color: theme.brand[0], children: at ?? " " }), _jsx(Text, { children: after })] }, i));
|
|
995
|
+
// 光标行:把光标字符包成独立节点,渲染后由渲染器给出真实坐标(IME 定位)
|
|
996
|
+
if (i === cursorRowIndex) {
|
|
997
|
+
return (_jsx(CursorInputRow, { firstLine: i === 0, before: cursorBefore, at: cursorAt, after: cursorAfter, onMeasure: onCursorMeasure }, i));
|
|
547
998
|
}
|
|
548
999
|
return (_jsxs(Text, { wrap: "truncate", children: [prompt, _jsx(Text, { children: line })] }, i));
|
|
549
|
-
})) })] })), _jsx(StatusBar, {
|
|
550
|
-
? "初始化中…"
|
|
551
|
-
: layout.scrolled
|
|
552
|
-
? "↕ 滚动中 · PgUp/PgDn 翻页 · 发送回到底部"
|
|
553
|
-
: "Enter 发送 · Ctrl+N 换行 · / 命令 · PgUp 看历史" })] }));
|
|
1000
|
+
})) })] })), _jsx(StatusBar, { ...statusProps })] }));
|
|
554
1001
|
}
|
|
555
1002
|
//# sourceMappingURL=chat.js.map
|