@uncarved/jade 0.1.3 → 0.2.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/bin/jade.js +5 -27
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -30
- package/dist/index.js +11 -30
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +159 -1362
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +2 -0
- package/dist/update.js +6 -3
- package/dist/update.js.map +1 -1
- package/package.json +10 -8
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -100
- package/{src/plugins → plugins/approval}/review.ts +62 -16
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +48 -38
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +73 -38
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +2 -2
- package/{src/tools → plugins/fs}/fs.ts +19 -42
- package/{src/tools → plugins/fs}/grep.ts +1 -1
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/{src/ui → plugins/fs}/renderers.ts +25 -70
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +79 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +198 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +16 -119
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +31 -20
- package/{src → plugins/shell}/sys.ts +2 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/{src/ui → plugins/tui}/render.ts +8 -2
- package/{src/ui → plugins/tui}/screen.ts +8 -3
- package/{src/ui → plugins/tui}/transcript.ts +74 -99
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/{src/tools → plugins/web}/web.ts +58 -26
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
- package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +51 -33
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
- package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
- package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +69 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +167 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +18 -81
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
- package/{dist → plugins-dist/shell}/sys.js +2 -43
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +586 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/{dist/ui → plugins-dist/tui}/render.js +7 -3
- package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
- package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/{dist/tools → plugins-dist/web}/web.js +50 -24
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -30
- package/src/install.ts +355 -0
- package/src/main.ts +155 -1387
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -262
- package/LICENSE +0 -21
- package/README.md +0 -204
- package/dist/commands.d.ts +0 -50
- package/dist/commands.js +0 -126
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -141
- package/dist/distro.js +0 -462
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -294
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -25
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -71
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -47
- package/dist/plugins/core.js +0 -229
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/host.d.ts +0 -52
- package/dist/plugins/host.js +0 -115
- package/dist/plugins/host.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -410
- package/dist/plugins/loader.js +0 -407
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -98
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -43
- package/dist/plugins/prompts.js +0 -284
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -16
- package/dist/plugins/repeats.js +0 -151
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -18
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/plugins/sessions.d.ts +0 -7
- package/dist/plugins/sessions.js +0 -110
- package/dist/plugins/sessions.js.map +0 -1
- package/dist/provider.d.ts +0 -165
- package/dist/provider.js.map +0 -1
- package/dist/session-lifecycle.d.ts +0 -61
- package/dist/session-lifecycle.js +0 -167
- package/dist/session-lifecycle.js.map +0 -1
- package/dist/session-scope.d.ts +0 -53
- package/dist/session-scope.js +0 -116
- package/dist/session-scope.js.map +0 -1
- package/dist/sessions.d.ts +0 -28
- package/dist/sessions.js +0 -73
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -51
- package/dist/sys.js.map +0 -1
- package/dist/tools/ask.d.ts +0 -11
- package/dist/tools/ask.js +0 -62
- package/dist/tools/ask.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -39
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -39
- package/dist/tools/task.js +0 -117
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -53
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -447
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -41
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -22
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -14
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/renderers.d.ts +0 -8
- package/dist/ui/renderers.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -118
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -46
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -47
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -144
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -577
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -278
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -34
- package/src/plugins/core.ts +0 -257
- package/src/plugins/host.ts +0 -146
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -742
- package/src/plugins/prompts.ts +0 -327
- package/src/plugins/repeats.ts +0 -157
- package/src/plugins/sessions.ts +0 -109
- package/src/session-lifecycle.ts +0 -194
- package/src/session-scope.ts +0 -135
- package/src/sessions.ts +0 -78
- package/src/tools/ask.ts +0 -72
- package/src/tools/task.ts +0 -149
- package/src/ui/configure.ts +0 -471
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
- /package/{src/ui → plugins/tui}/markdown.ts +0 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
// 终端界面(Ink):全屏(备用屏幕缓冲区)分三块——顶部标题(版本、模型、目录),中间是对话,
|
|
3
2
|
// 自己滚动(滚轮、PgUp/PgDn),底部固定显示运行状态、排队的消息、输入框(或对话框)和状态栏。
|
|
4
3
|
// 运行中也能输入:提交的内容由宿主决定立即执行还是排队。
|
|
4
|
+
//
|
|
5
|
+
// 不用 JSX:插件以 .ts 源码加载,Node 的类型剥离不处理 .tsx,所以组件用 createElement(h)写。
|
|
5
6
|
import { writeSync } from "node:fs";
|
|
6
7
|
import { Box, render, Text, useBoxMetrics, useCursor, useInput, usePaste, useWindowSize, } from "ink";
|
|
7
|
-
import { createContext, useContext, useEffect, useReducer, useRef, useState, useSyncExternalStore, } from "react";
|
|
8
|
+
import { createContext, createElement as h, useContext, useEffect, useReducer, useRef, useState, useSyncExternalStore, } from "react";
|
|
8
9
|
import stringWidth from "string-width";
|
|
9
10
|
import wrapAnsi from "wrap-ansi";
|
|
10
|
-
import { mentionAt, mentionText, rankPaths } from "
|
|
11
|
+
import { mentionAt, mentionText, rankPaths } from "./mentions.js";
|
|
11
12
|
import { charWidth, edit, empty, layout, moveRow, offsetAt } from "./editor.js";
|
|
12
13
|
import { expandTabs, markdownStream } from "./markdown.js";
|
|
13
14
|
import { dim, } from "./screen.js";
|
|
@@ -242,7 +243,7 @@ class Store {
|
|
|
242
243
|
this.#wrapped = [];
|
|
243
244
|
this.#owners = [];
|
|
244
245
|
this.#named.clear();
|
|
245
|
-
this.update({ version: this.state.version + 1, live: undefined, progress: [], scroll: 0 }, true);
|
|
246
|
+
this.update({ version: this.state.version + 1, live: undefined, progress: [], scroll: 0, hint: undefined }, true);
|
|
246
247
|
}
|
|
247
248
|
/** 展开或收起最后一个可折叠的项(Ctrl+O);start、view 同 toggle */
|
|
248
249
|
toggleLatest(start, view) {
|
|
@@ -359,7 +360,16 @@ export function tuiScreen(opts) {
|
|
|
359
360
|
// 切到备用屏幕后光标还停在原来的位置(不少终端不会自动归位),Ink 从那里往下画第一帧会让屏幕滚动,
|
|
360
361
|
// 之后每帧只重写变化的行,整个界面就错位了。所以先自己切过去、清屏、把光标移到左上角
|
|
361
362
|
stdout.write("\x1b[?1049h\x1b[2J\x1b[H");
|
|
362
|
-
const
|
|
363
|
+
const commands = opts.commands;
|
|
364
|
+
const instance = render(h(App, {
|
|
365
|
+
store,
|
|
366
|
+
copy: (text) => void stdout.write(osc52(text)),
|
|
367
|
+
version: opts.version,
|
|
368
|
+
commands: typeof commands === "function" ? commands : () => commands,
|
|
369
|
+
handlers: opts.handlers,
|
|
370
|
+
history: opts.history ?? [],
|
|
371
|
+
draft,
|
|
372
|
+
}), {
|
|
363
373
|
exitOnCtrlC: false,
|
|
364
374
|
alternateScreen: true,
|
|
365
375
|
// 全屏每帧只重写变化的行
|
|
@@ -461,6 +471,7 @@ export function tuiScreen(opts) {
|
|
|
461
471
|
const value = text.replace(/\r\n?/g, "\n");
|
|
462
472
|
draft.current?.apply(() => ({ value, cursor: value.length }));
|
|
463
473
|
},
|
|
474
|
+
hint: (text) => store.update({ hint: text ? text.replace(/\r\n?/g, "\n") : undefined }),
|
|
464
475
|
},
|
|
465
476
|
select: (title, choices, o) => {
|
|
466
477
|
if (longBusy())
|
|
@@ -651,10 +662,16 @@ function App({ store, copy, version, commands, handlers, history, draft, }) {
|
|
|
651
662
|
copiedTimer.current = setTimeout(() => setCopied(undefined), COPIED_MS);
|
|
652
663
|
};
|
|
653
664
|
// Ink 增量渲染只用相对光标移动,第一帧起点一旦偏了(启动时终端尺寸还没稳定、窗口缩放、别的输出插进来),
|
|
654
|
-
//
|
|
665
|
+
// 之后每帧都会画错行。尺寸变化后和按 Ctrl+L 时让一帧比终端高,Ink 会清屏从左上角整帧重画(包在同步输出里),下一帧再恢复。
|
|
666
|
+
// 启动时不重画:第一帧之前已经清屏、光标在左上角;这两次清屏在不支持同步输出的终端上(Windows 上常见)看得出闪一下
|
|
655
667
|
const [redraws, setRedraws] = useState(0);
|
|
656
668
|
const [repaint, setRepaint] = useState(false);
|
|
669
|
+
const mounted = useRef(false);
|
|
657
670
|
useEffect(() => {
|
|
671
|
+
if (!mounted.current) {
|
|
672
|
+
mounted.current = true;
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
658
675
|
const t = setTimeout(() => setRepaint(true), 100);
|
|
659
676
|
return () => clearTimeout(t);
|
|
660
677
|
}, [columns, rows, redraws]);
|
|
@@ -726,10 +743,44 @@ function App({ store, copy, version, commands, handlers, history, draft, }) {
|
|
|
726
743
|
// 总高度要比终端少一行,否则 Ink 认为输出占满了屏幕,每帧清屏重画。
|
|
727
744
|
// 重画那一帧上下各垫一行空白:终端把顶上那行滚出去后,看到的和平时逐行一样,所以不会闪。
|
|
728
745
|
// 只做纵向裁剪:每行都已按宽度折好或截断,横向裁剪会让 Ink 每帧对每一行再切一遍 ANSI 字符串
|
|
729
|
-
return (
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
746
|
+
return h(SelectionContext.Provider, { value: selectionApi }, h(Box, {
|
|
747
|
+
flexDirection: "column",
|
|
748
|
+
width: columns,
|
|
749
|
+
height: repaint ? rows + 1 : Math.max(1, rows - 1),
|
|
750
|
+
paddingY: repaint ? 1 : 0,
|
|
751
|
+
overflowY: "hidden",
|
|
752
|
+
},
|
|
753
|
+
// 垫的空白放在外层:里面这层在重画那一帧和平时一样高,对话区的 top(相对父节点)不变,点击换算的行号不会差一行
|
|
754
|
+
h(Box, { flexDirection: "column", flexGrow: 1, overflowY: "hidden" }, h(Header, { status: state.status, version, compact: rows < COMPACT_ROWS }), h(Box, {
|
|
755
|
+
ref,
|
|
756
|
+
flexDirection: "column",
|
|
757
|
+
flexGrow: 1,
|
|
758
|
+
flexShrink: 1,
|
|
759
|
+
flexBasis: 0,
|
|
760
|
+
overflowY: "hidden",
|
|
761
|
+
paddingX: 1,
|
|
762
|
+
}, shown.map((l, i) => {
|
|
763
|
+
const cols = selection && selectedCols(selection, start + i);
|
|
764
|
+
return h(Text, { key: i, wrap: "truncate-end" }, cols ? highlight(l || " ", ...cols) : l || " ");
|
|
765
|
+
}), scrolled
|
|
766
|
+
? h(Text, { dimColor: true, wrap: "truncate-end" }, `── ↓ ${scroll} more lines · wheel / PgDn to scroll · ctrl+end to jump to the bottom ──`)
|
|
767
|
+
: null), h(Box, { flexDirection: "column", flexShrink: 0 }, state.busy && !dialog ? h(Spinner, { label: state.busy.label, since: state.busy.since }) : null, state.queued.map((q, i) => h(Text, { key: i, dimColor: true, wrap: "truncate-end" }, " ↳ queued: ", q.replace(/\s+/g, " "))), dialog
|
|
768
|
+
? dialog.kind === "select"
|
|
769
|
+
? h(SelectDialog, { key: dialogKey(dialog), dialog })
|
|
770
|
+
: h(InputDialog, { key: dialogKey(dialog), dialog })
|
|
771
|
+
: null, h(Prompt, {
|
|
772
|
+
commands,
|
|
773
|
+
handlers,
|
|
774
|
+
history,
|
|
775
|
+
bridge: draft,
|
|
776
|
+
hint: state.hint,
|
|
777
|
+
onHintDone: () => store.update({ hint: undefined }),
|
|
778
|
+
busy: Boolean(state.busy),
|
|
779
|
+
queued: state.queued.length > 0,
|
|
780
|
+
active: !dialog,
|
|
781
|
+
onSubmit: () => store.scrollBy(-max, max),
|
|
782
|
+
flash: copied,
|
|
783
|
+
}), h(StatusBar, { status: state.status, width: Math.max(10, columns - 2) })))));
|
|
733
784
|
}
|
|
734
785
|
const JADE = "#00a86b";
|
|
735
786
|
const SHINE = "#b6f2d4";
|
|
@@ -738,13 +789,21 @@ const SHINE = "#b6f2d4";
|
|
|
738
789
|
* 每个字符上下两个像素;眼睛是玉上挖空的两格,左上角一点高光让它看起来像玉
|
|
739
790
|
*/
|
|
740
791
|
function Bot() {
|
|
741
|
-
return (
|
|
792
|
+
return h(Box, { flexDirection: "column", flexShrink: 0, marginRight: 2 }, h(Text, { color: JADE }, " ▄", h(Text, { color: SHINE, backgroundColor: JADE }, "▄"), "████▄"), h(Text, { color: JADE }, "██ ███ ██"), h(Text, { color: JADE }, "▀███████▀"));
|
|
742
793
|
}
|
|
743
794
|
function Header({ status, version, compact, }) {
|
|
744
795
|
const { columns } = useScreenSize();
|
|
796
|
+
// 模型 · 目录 (分支)
|
|
797
|
+
const where = [
|
|
798
|
+
h(Text, { key: "model", color: "cyan" }, status.model),
|
|
799
|
+
h(Text, { key: "sep", dimColor: true }, " · "),
|
|
800
|
+
h(Text, { key: "cwd" }, status.cwd),
|
|
801
|
+
status.branch ? h(Text, { key: "branch", color: "magenta" }, ` (${status.branch})`) : null,
|
|
802
|
+
];
|
|
803
|
+
const name = h(Text, { key: "name", color: "cyan", bold: true }, "jade");
|
|
745
804
|
if (compact)
|
|
746
|
-
return (
|
|
747
|
-
return (
|
|
805
|
+
return h(Box, { flexShrink: 0, paddingX: 1 }, h(Text, { wrap: "truncate-end" }, name, h(Text, { key: "dot", dimColor: true }, " · "), ...where));
|
|
806
|
+
return h(Box, { flexShrink: 0, borderStyle: "round", borderColor: "cyan", paddingX: 1 }, columns >= 50 ? h(Bot) : null, h(Box, { flexDirection: "column", flexGrow: 1, flexShrink: 1 }, h(Text, { wrap: "truncate-end" }, name, h(Text, { dimColor: true }, ` v${version}`), status.session ? h(Text, { dimColor: true }, ` · session ${status.session}`) : null), h(Text, { wrap: "truncate-end" }, ...where), h(Text, { dimColor: true, wrap: "truncate-end" }, "/help for commands · @ to attach files")));
|
|
748
807
|
}
|
|
749
808
|
const dialogIds = new WeakMap();
|
|
750
809
|
let dialogCounter = 0;
|
|
@@ -758,7 +817,7 @@ const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "
|
|
|
758
817
|
function Spinner({ label, since }) {
|
|
759
818
|
const now = Date.now();
|
|
760
819
|
const seconds = Math.floor((now - since) / 1000);
|
|
761
|
-
return (
|
|
820
|
+
return h(Box, { marginTop: 1 }, h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, `${FRAMES[Math.floor(now / 100) % FRAMES.length]} `), h(Text, null, `${label}… `), h(Text, { dimColor: true }, `(${seconds}s · esc to interrupt)`)));
|
|
762
821
|
}
|
|
763
822
|
/** 在 width 列里放下尽量多的内容(保持原来的顺序) */
|
|
764
823
|
export function fitSegments(segments, width) {
|
|
@@ -846,12 +905,12 @@ function StatusBar({ status, width }) {
|
|
|
846
905
|
},
|
|
847
906
|
];
|
|
848
907
|
const shown = fitSegments(segments, width);
|
|
849
|
-
return (
|
|
908
|
+
return h(Box, { paddingX: 1 }, h(Text, { wrap: "truncate-end" }, shown.map((s, i) => h(Text, { key: i }, i ? h(Text, { dimColor: true }, " · ") : null, h(Text, { color: s.color, dimColor: s.dim }, s.text)))));
|
|
850
909
|
}
|
|
851
910
|
/** 一行提示:按宽度选第一个放得下的写法,都放不下时用最后一个并截断 */
|
|
852
911
|
function Hint({ variants, width }) {
|
|
853
912
|
const text = variants.find((v) => stringWidth(v) <= width) ?? variants.at(-1);
|
|
854
|
-
return (
|
|
913
|
+
return h(Text, { dimColor: true, wrap: "truncate-end" }, text);
|
|
855
914
|
}
|
|
856
915
|
const tokens = (n) => n >= 1_000_000
|
|
857
916
|
? `${(n / 1_000_000).toFixed(n >= 10_000_000 ? 0 : 1)}M`
|
|
@@ -890,6 +949,10 @@ function editKey(s, input, key) {
|
|
|
890
949
|
return edit.del(s);
|
|
891
950
|
if (key.ctrl && input === "w")
|
|
892
951
|
return edit.deleteWord(s);
|
|
952
|
+
if (key.meta && !key.ctrl && input === "f")
|
|
953
|
+
return edit.wordRight(s);
|
|
954
|
+
if (key.meta && !key.ctrl && input === "b")
|
|
955
|
+
return edit.wordLeft(s);
|
|
893
956
|
if (key.ctrl && input === "u")
|
|
894
957
|
return edit.killBefore(s);
|
|
895
958
|
if (key.ctrl && input === "k")
|
|
@@ -948,11 +1011,9 @@ function EditableText({ state, width, prefix, mask, placeholder, active, maxRows
|
|
|
948
1011
|
if (now.x !== at.x || now.y !== at.y)
|
|
949
1012
|
recheck();
|
|
950
1013
|
});
|
|
951
|
-
return (
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
? "↑".padEnd(prefix.length)
|
|
955
|
-
: " ".repeat(prefix.length) }), r] }, first + i))))] }));
|
|
1014
|
+
return h(Box, { ref, flexDirection: "column" }, active ? h(CursorAt, { position }) : null, state.value === "" && placeholder
|
|
1015
|
+
? h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, prefix), h(Text, { dimColor: true }, placeholder))
|
|
1016
|
+
: rows.map((r, i) => h(Text, { key: first + i, wrap: "truncate-end" }, h(Text, { color: "cyan" }, first + i === 0 ? prefix : i === 0 ? "↑".padEnd(prefix.length) : " ".repeat(prefix.length)), r)));
|
|
956
1017
|
}
|
|
957
1018
|
/**
|
|
958
1019
|
* 终端光标只有一个,每个 useCursor 每次提交都会设一遍。没有焦点的输入框(弹出输入框时下面的主输入框)
|
|
@@ -973,7 +1034,7 @@ function origin(node) {
|
|
|
973
1034
|
}
|
|
974
1035
|
return { x, y };
|
|
975
1036
|
}
|
|
976
|
-
function Prompt({ commands, handlers, history: initial, bridge, busy, active, onSubmit, flash, }) {
|
|
1037
|
+
function Prompt({ commands, handlers, history: initial, bridge, hint, onHintDone, busy, queued, active, onSubmit, flash, }) {
|
|
977
1038
|
const selection = useContext(SelectionContext);
|
|
978
1039
|
const [current, setState] = useLive(empty);
|
|
979
1040
|
const [getSelected, setSelected] = useLive(0);
|
|
@@ -999,7 +1060,7 @@ function Prompt({ commands, handlers, history: initial, bridge, busy, active, on
|
|
|
999
1060
|
// Ctrl+R 搜索历史:结果新的在前,index 是选中的那条
|
|
1000
1061
|
const [getSearch, setSearch] = useLive(undefined);
|
|
1001
1062
|
const usageOf = (c) => `/${c.name}${c.args ? ` ${c.args}` : ""}`;
|
|
1002
|
-
const column = Math.max(...commands.map((c) => usageOf(c).length)) + 2;
|
|
1063
|
+
const column = Math.max(...commands().map((c) => usageOf(c).length)) + 2;
|
|
1003
1064
|
/** 由最新的输入算出补全菜单和搜索结果;渲染和按键处理都用它 */
|
|
1004
1065
|
const derive = () => {
|
|
1005
1066
|
const state = current();
|
|
@@ -1011,7 +1072,7 @@ function Prompt({ commands, handlers, history: initial, bridge, busy, active, on
|
|
|
1011
1072
|
history.current[history.current.length - 1 - browsing.current];
|
|
1012
1073
|
const naming = !recalled && state.value.startsWith("/") && !/\s/.test(state.value);
|
|
1013
1074
|
const matches = naming
|
|
1014
|
-
? commands.filter((c) => `/${c.name}`.startsWith(state.value))
|
|
1075
|
+
? commands().filter((c) => `/${c.name}`.startsWith(state.value))
|
|
1015
1076
|
: [];
|
|
1016
1077
|
const pick = matches[Math.min(selected, matches.length - 1)];
|
|
1017
1078
|
// @ 引用:光标处正在输入的路径和补全候选
|
|
@@ -1067,7 +1128,12 @@ function Prompt({ commands, handlers, history: initial, bridge, busy, active, on
|
|
|
1067
1128
|
const first = around(hit, results.length, menuRows);
|
|
1068
1129
|
const firstMatch = around(Math.max(0, matches.indexOf(pick)), matches.length, menuRows);
|
|
1069
1130
|
const firstFound = around(Math.max(0, found.indexOf(file)), found.length, menuRows);
|
|
1131
|
+
/** 提示只在空闲、输入框为空、没有在搜索历史时显示,也只有这时能接受 */
|
|
1132
|
+
const hinting = () => hint !== undefined && !busy && current().value === "" && !getSearch();
|
|
1070
1133
|
const set = (s) => {
|
|
1134
|
+
// 用户开始打字(或者插件改了输入框):提示作废
|
|
1135
|
+
if (s.value && hint !== undefined)
|
|
1136
|
+
onHintDone();
|
|
1071
1137
|
setState(s);
|
|
1072
1138
|
setSelected(0);
|
|
1073
1139
|
setNotice(undefined);
|
|
@@ -1222,6 +1288,12 @@ function Prompt({ commands, handlers, history: initial, bridge, busy, active, on
|
|
|
1222
1288
|
return complete(file);
|
|
1223
1289
|
return submit(state.value.trim());
|
|
1224
1290
|
}
|
|
1291
|
+
// Tab 或 →:把提示变成输入框里的文字,接着可以改
|
|
1292
|
+
if (((key.tab && !key.shift) || key.rightArrow) && hinting()) {
|
|
1293
|
+
onHintDone();
|
|
1294
|
+
browsing.current = -1;
|
|
1295
|
+
return set({ value: hint, cursor: hint.length });
|
|
1296
|
+
}
|
|
1225
1297
|
if (key.tab && key.shift)
|
|
1226
1298
|
return handlers.cycleMode?.();
|
|
1227
1299
|
if (key.tab) {
|
|
@@ -1243,6 +1315,11 @@ function Prompt({ commands, handlers, history: initial, bridge, busy, active, on
|
|
|
1243
1315
|
const up = moveRow(state, textWidth, -1);
|
|
1244
1316
|
if (up)
|
|
1245
1317
|
return setState(up);
|
|
1318
|
+
// 先取回排队的消息,取完了再翻历史
|
|
1319
|
+
if (handlers.unqueue?.()) {
|
|
1320
|
+
browsing.current = -1;
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
1246
1323
|
if (browsing.current + 1 < history.current.length) {
|
|
1247
1324
|
if (browsing.current === -1)
|
|
1248
1325
|
draft.current = state.value;
|
|
@@ -1269,31 +1346,75 @@ function Prompt({ commands, handlers, history: initial, bridge, busy, active, on
|
|
|
1269
1346
|
set(next);
|
|
1270
1347
|
}, { isActive: active });
|
|
1271
1348
|
// 对话框打开时隐藏但不卸载,输入到一半的内容和历史都保留
|
|
1272
|
-
return (
|
|
1349
|
+
return h(Box, { flexDirection: "column", marginTop: 1, display: active ? "flex" : "none" }, h(Box, { borderStyle: "round", borderColor: busy ? "gray" : "cyan", paddingX: 1 }, search
|
|
1350
|
+
? h(EditableText, {
|
|
1351
|
+
state: { value: search.query, cursor: search.query.length },
|
|
1352
|
+
width: Math.max(10, columns - 5),
|
|
1353
|
+
prefix: "search history› ",
|
|
1354
|
+
placeholder: "type to filter",
|
|
1355
|
+
active,
|
|
1356
|
+
maxRows: inputRows,
|
|
1357
|
+
})
|
|
1358
|
+
: h(EditableText, {
|
|
1359
|
+
state,
|
|
1360
|
+
width: Math.max(10, columns - 5),
|
|
1361
|
+
prefix: "› ",
|
|
1362
|
+
placeholder: hinting()
|
|
1363
|
+
? hintLine(hint)
|
|
1364
|
+
: queued
|
|
1365
|
+
? "↑ to edit queued messages · esc to interrupt"
|
|
1366
|
+
: busy
|
|
1273
1367
|
? "Type to queue a message · esc to interrupt"
|
|
1274
1368
|
: columns >= 70
|
|
1275
1369
|
? "Message jade · / commands · @ files · ↑ or ctrl+r for history"
|
|
1276
|
-
: "Message jade · / commands · @ files",
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1370
|
+
: "Message jade · / commands · @ files",
|
|
1371
|
+
active,
|
|
1372
|
+
maxRows: inputRows,
|
|
1373
|
+
place,
|
|
1374
|
+
})), search
|
|
1375
|
+
? h(Box, { flexDirection: "column", paddingX: 2 }, results.length
|
|
1376
|
+
? results.slice(first, first + menuRows).map((item, i) => {
|
|
1377
|
+
const on = first + i === hit;
|
|
1378
|
+
return h(Text, { key: first + i, wrap: "truncate-end", color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", item.replace(/\s*\n\s*/g, " ⏎ "));
|
|
1379
|
+
})
|
|
1380
|
+
: h(Text, { dimColor: true }, " no match"), h(Hint, {
|
|
1381
|
+
width: hintWidth,
|
|
1382
|
+
variants: [" ↑↓ or ctrl+r select · enter/tab put in the input · esc cancel", " ↑↓ select · enter use · esc cancel"],
|
|
1383
|
+
}))
|
|
1384
|
+
: matches.length
|
|
1385
|
+
? h(Box, { flexDirection: "column", paddingX: 2 }, matches.slice(firstMatch, firstMatch + menuRows).map((c) => {
|
|
1386
|
+
const on = c === pick;
|
|
1387
|
+
return h(Text, { key: c.name, wrap: "truncate-end" }, h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", usageOf(c).padEnd(column)), h(Text, { dimColor: true }, c.about));
|
|
1388
|
+
}), h(Hint, {
|
|
1389
|
+
width: hintWidth,
|
|
1390
|
+
variants: [
|
|
1391
|
+
` ↑↓ select · enter run · tab complete${matches.length > menuRows ? ` · ${matches.length} commands` : ""}`,
|
|
1392
|
+
" ↑↓ · enter run · tab complete",
|
|
1393
|
+
],
|
|
1394
|
+
}))
|
|
1395
|
+
: found.length
|
|
1396
|
+
? h(Box, { flexDirection: "column", paddingX: 2 }, found.slice(firstFound, firstFound + menuRows).map((p) => {
|
|
1397
|
+
const on = p === file;
|
|
1398
|
+
return h(Text, { key: p, wrap: "truncate-middle", color: on ? "cyan" : p.endsWith("/") ? "blue" : undefined, bold: on }, on ? "❯ " : " ", p);
|
|
1399
|
+
}), h(Hint, {
|
|
1400
|
+
width: hintWidth,
|
|
1401
|
+
variants: [
|
|
1402
|
+
" ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
|
|
1403
|
+
" ↑↓ select · enter/tab insert the path",
|
|
1404
|
+
" ↑↓ · enter insert",
|
|
1405
|
+
],
|
|
1406
|
+
}))
|
|
1407
|
+
: notice
|
|
1408
|
+
? h(Text, { color: "yellow" }, ` ${notice}`)
|
|
1409
|
+
: null,
|
|
1410
|
+
// 压在输入框上边框的右边,不占行,出现和消失时下面的内容不跳
|
|
1411
|
+
flash ? h(Box, { position: "absolute", top: 0, right: 2 }, h(Text, { color: "green" }, ` ${flash} `)) : null);
|
|
1296
1412
|
}
|
|
1413
|
+
/** 提示在输入框里只显示第一行,后面还有时加 … */
|
|
1414
|
+
const hintLine = (hint) => {
|
|
1415
|
+
const [first, ...rest] = hint.split("\n");
|
|
1416
|
+
return `${first}${rest.length ? " …" : ""}`;
|
|
1417
|
+
};
|
|
1297
1418
|
/** @ 补全最多显示几项 */
|
|
1298
1419
|
const MENTION_ROWS = 8;
|
|
1299
1420
|
/** 长列表只显示 size 项时,为了让第 selected 项在中间附近,从第几项开始显示 */
|
|
@@ -1375,12 +1496,17 @@ function SelectDialog({ dialog, }) {
|
|
|
1375
1496
|
});
|
|
1376
1497
|
// 选项多时只显示选中项附近的一段
|
|
1377
1498
|
const start = around(selected, n, visible);
|
|
1378
|
-
return (
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1499
|
+
return h(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 }, h(Text, { bold: true, wrap: "truncate-end" }, dialog.title), body.map((l, i) => h(Text, { key: i, wrap: "truncate-end" }, l || " ")), filtering
|
|
1500
|
+
? h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, "filter› "), query ? h(Text, null, query) : h(Text, { dimColor: true }, `type to filter ${dialog.choices.length} items`))
|
|
1501
|
+
: null, h(Box, { flexDirection: "column", marginTop: filtering ? 0 : 1 }, start > 0 ? h(Text, { dimColor: true }, ` ↑ ${start} more`) : null, n === 0 ? h(Text, { dimColor: true }, " no match") : null, items.slice(start, start + visible).map(({ c, i }, j) => {
|
|
1502
|
+
const on = start + j === selected;
|
|
1503
|
+
return h(Text, { key: i, wrap: "truncate-end" }, h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", filtering ? "" : `${i + 1}. `, c.label), c.hint ? h(Text, { dimColor: true }, ` ${c.hint}`) : null);
|
|
1504
|
+
}), start + visible < n ? h(Text, { dimColor: true }, ` ↓ ${n - start - visible} more`) : null), h(Hint, {
|
|
1505
|
+
width: Math.max(10, columns - 4),
|
|
1506
|
+
variants: filtering
|
|
1507
|
+
? ["↑↓ select · type to filter · enter confirm · esc clear/cancel", "↑↓ · enter · esc"]
|
|
1508
|
+
: ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"],
|
|
1509
|
+
}));
|
|
1384
1510
|
}
|
|
1385
1511
|
function InputDialog({ dialog, }) {
|
|
1386
1512
|
const selection = useContext(SelectionContext);
|
|
@@ -1404,6 +1530,12 @@ function InputDialog({ dialog, }) {
|
|
|
1404
1530
|
if (next)
|
|
1405
1531
|
setState(next);
|
|
1406
1532
|
});
|
|
1407
|
-
return (
|
|
1533
|
+
return h(Box, { flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 }, h(Text, { bold: true }, dialog.title), h(EditableText, {
|
|
1534
|
+
state,
|
|
1535
|
+
width: Math.max(10, columns - 6),
|
|
1536
|
+
prefix: "› ",
|
|
1537
|
+
mask: dialog.mask,
|
|
1538
|
+
placeholder: dialog.placeholder,
|
|
1539
|
+
active: true,
|
|
1540
|
+
}), h(Text, { dimColor: true }, "enter confirm · esc cancel"));
|
|
1408
1541
|
}
|
|
1409
|
-
//# sourceMappingURL=tui.js.map
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
// 文件快照:write_file / edit_file
|
|
1
|
+
// 文件快照:write_file / edit_file / multi_edit 执行前保存原内容,/undo 用它恢复。从旧 jade 的 tools/checkpoint.ts 移植。
|
|
2
2
|
//
|
|
3
|
-
// 快照放在 <dir>/<sessionId>/<toolUseId>.json
|
|
4
|
-
//
|
|
3
|
+
// 快照放在 <dir>/<sessionId>/<toolUseId>.json,不进日志:文件可能很大,而撤销是用户的操作,不影响插件决策。
|
|
4
|
+
// 哪些修改已经撤销记在同一个目录的 undone.json 里(命令拿不到会话日志),恢复会话后仍然有效。
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
|
-
import {
|
|
6
|
+
import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
/** derived 中保存已撤销的 toolUseId 的键 */
|
|
9
|
-
export const UNDO_KEY = "jade/undo";
|
|
10
8
|
export const sha256 = (s) => createHash("sha256").update(s).digest("hex");
|
|
11
9
|
export class Checkpoints {
|
|
12
10
|
#dir;
|
|
13
|
-
/** 会话 → 文件 → markSeen 记下的 sha256;第一次用到时从 seen.jsonl 读入 */
|
|
14
|
-
#seen = new Map();
|
|
15
11
|
constructor(dir) {
|
|
16
12
|
this.#dir = dir;
|
|
17
13
|
}
|
|
@@ -33,7 +29,7 @@ export class Checkpoints {
|
|
|
33
29
|
}
|
|
34
30
|
const out = [];
|
|
35
31
|
for (const n of names) {
|
|
36
|
-
if (!n.endsWith(".json"))
|
|
32
|
+
if (!n.endsWith(".json") || n === UNDONE)
|
|
37
33
|
continue;
|
|
38
34
|
try {
|
|
39
35
|
out.push(JSON.parse(await readFile(path.join(dir, n), "utf8")));
|
|
@@ -44,53 +40,23 @@ export class Checkpoints {
|
|
|
44
40
|
}
|
|
45
41
|
return out.sort((a, b) => b.at - a.at);
|
|
46
42
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
* 这里的是给恢复的会话用的:之前的进程里读过、写过的文件,内容没变就不用再读一遍。
|
|
50
|
-
* 追加到每个会话一个的 seen.jsonl,后面的记录覆盖前面的;内容没变的重复读取不再写
|
|
51
|
-
*/
|
|
52
|
-
async markSeen(sessionId, file, hash) {
|
|
53
|
-
const seen = await this.#seenOf(sessionId);
|
|
54
|
-
if (seen.get(file) === hash)
|
|
55
|
-
return;
|
|
56
|
-
seen.set(file, hash);
|
|
57
|
-
const dir = path.join(this.#dir, safe(sessionId));
|
|
58
|
-
await mkdir(dir, { recursive: true });
|
|
59
|
-
await appendFile(path.join(dir, "seen.jsonl"), JSON.stringify({ path: file, hash }) + "\n");
|
|
60
|
-
}
|
|
61
|
-
/** markSeen 记下的 sha256;没有记录返回 undefined */
|
|
62
|
-
async seenHash(sessionId, file) {
|
|
63
|
-
const hash = (await this.#seenOf(sessionId)).get(file);
|
|
64
|
-
if (hash !== undefined)
|
|
65
|
-
return hash;
|
|
66
|
-
// 旧版本每个文件一个 seen/<sha256(path)>.json
|
|
43
|
+
/** 已经撤销的修改(toolUseId) */
|
|
44
|
+
async undone(sessionId) {
|
|
67
45
|
try {
|
|
68
|
-
const
|
|
69
|
-
return
|
|
46
|
+
const ids = JSON.parse(await readFile(path.join(this.#dir, safe(sessionId), UNDONE), "utf8"));
|
|
47
|
+
return new Set(Array.isArray(ids) ? ids.filter((x) => typeof x === "string") : []);
|
|
70
48
|
}
|
|
71
49
|
catch {
|
|
72
|
-
return
|
|
50
|
+
return new Set();
|
|
73
51
|
}
|
|
74
52
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const rec = JSON.parse(line);
|
|
83
|
-
map.set(rec.path, rec.hash);
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
// 空行或写到一半的一行
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return map;
|
|
90
|
-
}, () => new Map());
|
|
91
|
-
this.#seen.set(sessionId, seen);
|
|
92
|
-
}
|
|
93
|
-
return seen;
|
|
53
|
+
async markUndone(sessionId, ids) {
|
|
54
|
+
const all = await this.undone(sessionId);
|
|
55
|
+
for (const id of ids)
|
|
56
|
+
all.add(id);
|
|
57
|
+
const dir = path.join(this.#dir, safe(sessionId));
|
|
58
|
+
await mkdir(dir, { recursive: true });
|
|
59
|
+
await writeFile(path.join(dir, UNDONE), JSON.stringify([...all]));
|
|
94
60
|
}
|
|
95
61
|
/** 文件现在的内容是否还是这次写入的结果 */
|
|
96
62
|
async unchangedSince(cp) {
|
|
@@ -111,9 +77,10 @@ export class Checkpoints {
|
|
|
111
77
|
}
|
|
112
78
|
}
|
|
113
79
|
}
|
|
80
|
+
const UNDONE = "undone.json";
|
|
114
81
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
82
|
+
* 最近一轮还有没撤销的修改的快照(最新的在前)。一轮从一条用户自己写的消息开始;
|
|
83
|
+
* 只有工具结果、或者只有插件、宿主加的说明(例如自动续写的提示)的消息不算新的一轮。没有可撤销的返回空数组
|
|
117
84
|
*/
|
|
118
85
|
export function lastTurnChanges(messages, checkpoints, undone) {
|
|
119
86
|
const pending = checkpoints.filter((c) => !undone.has(c.toolUseId));
|
|
@@ -128,7 +95,7 @@ export function lastTurnChanges(messages, checkpoints, undone) {
|
|
|
128
95
|
ids.add(b.id);
|
|
129
96
|
continue;
|
|
130
97
|
}
|
|
131
|
-
const startsTurn = m.content.some((b) => b.kind !== "tool_result" && b.origin.by
|
|
98
|
+
const startsTurn = m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user");
|
|
132
99
|
if (!startsTurn)
|
|
133
100
|
continue;
|
|
134
101
|
const hits = pending.filter((c) => ids.has(c.toolUseId));
|
|
@@ -141,4 +108,3 @@ export function lastTurnChanges(messages, checkpoints, undone) {
|
|
|
141
108
|
}
|
|
142
109
|
/** 会话和工具调用的 id 用作文件名 */
|
|
143
110
|
const safe = (id) => id.replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
144
|
-
//# sourceMappingURL=checkpoint.js.map
|