@uncarved/jade 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -150
- package/bin/jade.js +14 -25
- 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 +160 -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 +311 -0
- package/plugins/approval/plugin.json +22 -0
- package/{src/plugins → plugins/approval}/policy.ts +45 -104
- 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 +80 -39
- 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 +89 -46
- package/{src/tools → plugins/fs}/grep.ts +36 -8
- package/plugins/fs/index.ts +37 -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 +99 -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 +213 -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 +160 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +111 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +258 -0
- package/plugins/prompts/results.ts +63 -0
- package/plugins/prompts/sys.ts +84 -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 +168 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +343 -0
- package/plugins/todo/index.ts +93 -0
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +619 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +153 -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 +79 -100
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
- package/plugins/tui/vendor.ts +16 -0
- package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
- package/plugins/undo/index.ts +143 -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 +64 -31
- package/plugins-dist/approval/index.js +287 -0
- package/plugins-dist/approval/plugin.json +28 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
- 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 +58 -34
- 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 +82 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
- package/plugins-dist/fs/index.js +39 -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 +87 -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 +181 -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 +172 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +85 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +231 -0
- package/plugins-dist/prompts/results.js +60 -0
- package/plugins-dist/prompts/sys.js +58 -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 +152 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +284 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +609 -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 +153 -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 +79 -99
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
- package/plugins-dist/tui/vendor.js +13822 -0
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
- package/plugins-dist/undo/index.js +143 -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 +56 -29
- 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 +156 -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/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/tools/todo.ts +0 -67
- 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,8 +1,11 @@
|
|
|
1
1
|
// 终端界面(Ink):全屏(备用屏幕缓冲区)分三块——顶部标题(版本、模型、目录),中间是对话,
|
|
2
2
|
// 自己滚动(滚轮、PgUp/PgDn),底部固定显示运行状态、排队的消息、输入框(或对话框)和状态栏。
|
|
3
3
|
// 运行中也能输入:提交的内容由宿主决定立即执行还是排队。
|
|
4
|
+
//
|
|
5
|
+
// 不用 JSX:插件以 .ts 源码加载,Node 的类型剥离不处理 .tsx,所以组件用 createElement(h)写。
|
|
4
6
|
|
|
5
7
|
import { writeSync } from "node:fs";
|
|
8
|
+
import type { DOMElement, Key } from "ink";
|
|
6
9
|
import {
|
|
7
10
|
Box,
|
|
8
11
|
render,
|
|
@@ -12,21 +15,18 @@ import {
|
|
|
12
15
|
useInput,
|
|
13
16
|
usePaste,
|
|
14
17
|
useWindowSize,
|
|
15
|
-
type DOMElement,
|
|
16
|
-
type Key,
|
|
17
|
-
} from "ink";
|
|
18
|
-
import {
|
|
19
18
|
createContext,
|
|
19
|
+
createElement as h,
|
|
20
20
|
useContext,
|
|
21
21
|
useEffect,
|
|
22
22
|
useReducer,
|
|
23
23
|
useRef,
|
|
24
24
|
useState,
|
|
25
25
|
useSyncExternalStore,
|
|
26
|
-
} from "
|
|
26
|
+
} from "./vendor.ts";
|
|
27
27
|
import stringWidth from "string-width";
|
|
28
28
|
import wrapAnsi from "wrap-ansi";
|
|
29
|
-
import { mentionAt, mentionText, rankPaths } from "
|
|
29
|
+
import { mentionAt, mentionText, rankPaths } from "./mentions.ts";
|
|
30
30
|
import { charWidth, edit, empty, layout, moveRow, offsetAt, type EditState } from "./editor.ts";
|
|
31
31
|
import { expandTabs, markdownStream, type MdLine } from "./markdown.ts";
|
|
32
32
|
import {
|
|
@@ -52,6 +52,8 @@ export interface TuiHandlers {
|
|
|
52
52
|
submit(text: string): void;
|
|
53
53
|
/** 运行中按 Esc 或 Ctrl+C */
|
|
54
54
|
interrupt(): void;
|
|
55
|
+
/** 输入框第一行按 ↑:把排队的消息放回输入框;没有排队的消息时返回 false,↑ 照常翻历史 */
|
|
56
|
+
unqueue?(): boolean;
|
|
55
57
|
/** 空闲时连按两次 Ctrl+C */
|
|
56
58
|
exit(): void;
|
|
57
59
|
/** 输入 @ 时补全用的路径(目录以 / 结尾);每次开始输入一个新的 @ 引用时取一次 */
|
|
@@ -104,6 +106,8 @@ interface UiState {
|
|
|
104
106
|
queued: string[];
|
|
105
107
|
dialogs: Dialog[];
|
|
106
108
|
status: StatusInfo;
|
|
109
|
+
/** 插件设置的灰色提示(ctx.input.hint):输入框为空时显示,Tab 或 → 接受 */
|
|
110
|
+
hint?: string;
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
/** 对话最多保留这么多行(折行前),超出时丢掉最早的一段 */
|
|
@@ -352,7 +356,7 @@ class Store {
|
|
|
352
356
|
this.#owners = [];
|
|
353
357
|
this.#named.clear();
|
|
354
358
|
this.update(
|
|
355
|
-
{ version: this.state.version + 1, live: undefined, progress: [], scroll: 0 },
|
|
359
|
+
{ version: this.state.version + 1, live: undefined, progress: [], scroll: 0, hint: undefined },
|
|
356
360
|
true,
|
|
357
361
|
);
|
|
358
362
|
}
|
|
@@ -375,7 +379,8 @@ export interface TuiOptions {
|
|
|
375
379
|
status: StatusInfo;
|
|
376
380
|
/** 标题里显示的版本号 */
|
|
377
381
|
version: string;
|
|
378
|
-
|
|
382
|
+
/** 斜杠命令菜单的内容;命令随会话的插件增减时传函数,每次显示菜单时取最新的 */
|
|
383
|
+
commands: CommandInfo[] | (() => CommandInfo[]);
|
|
379
384
|
handlers: TuiHandlers;
|
|
380
385
|
/** 之前提交过的输入(旧的在前),↑/↓ 和 Ctrl+R 用 */
|
|
381
386
|
history?: string[];
|
|
@@ -468,7 +473,7 @@ export function tuiScreen(opts: TuiOptions): Screen {
|
|
|
468
473
|
};
|
|
469
474
|
|
|
470
475
|
/** signal 中止时关掉对话框,返回 undefined */
|
|
471
|
-
const ask = <T
|
|
476
|
+
const ask = <T>(dialog: Dialog, signal?: AbortSignal) =>
|
|
472
477
|
new Promise<T>((resolve) => {
|
|
473
478
|
if (signal?.aborted) return resolve(undefined as T);
|
|
474
479
|
const close = () => d.resolve(undefined);
|
|
@@ -490,16 +495,17 @@ export function tuiScreen(opts: TuiOptions): Screen {
|
|
|
490
495
|
// 切到备用屏幕后光标还停在原来的位置(不少终端不会自动归位),Ink 从那里往下画第一帧会让屏幕滚动,
|
|
491
496
|
// 之后每帧只重写变化的行,整个界面就错位了。所以先自己切过去、清屏、把光标移到左上角
|
|
492
497
|
stdout.write("\x1b[?1049h\x1b[2J\x1b[H");
|
|
498
|
+
const commands = opts.commands;
|
|
493
499
|
const instance = render(
|
|
494
|
-
|
|
495
|
-
store
|
|
496
|
-
copy
|
|
497
|
-
version
|
|
498
|
-
commands
|
|
499
|
-
handlers
|
|
500
|
-
history
|
|
501
|
-
draft
|
|
502
|
-
|
|
500
|
+
h(App, {
|
|
501
|
+
store,
|
|
502
|
+
copy: (text: string) => void stdout.write(osc52(text)),
|
|
503
|
+
version: opts.version,
|
|
504
|
+
commands: typeof commands === "function" ? commands : () => commands,
|
|
505
|
+
handlers: opts.handlers,
|
|
506
|
+
history: opts.history ?? [],
|
|
507
|
+
draft,
|
|
508
|
+
}),
|
|
503
509
|
{
|
|
504
510
|
exitOnCtrlC: false,
|
|
505
511
|
alternateScreen: true,
|
|
@@ -603,8 +609,9 @@ export function tuiScreen(opts: TuiOptions): Screen {
|
|
|
603
609
|
const value = text.replace(/\r\n?/g, "\n");
|
|
604
610
|
draft.current?.apply(() => ({ value, cursor: value.length }));
|
|
605
611
|
},
|
|
612
|
+
hint: (text) => store.update({ hint: text ? text.replace(/\r\n?/g, "\n") : undefined }),
|
|
606
613
|
},
|
|
607
|
-
select: <T
|
|
614
|
+
select: <T>(title: string, choices: Choice<T>[], o?: { body?: string; signal?: AbortSignal }) => {
|
|
608
615
|
if (longBusy()) notify(title);
|
|
609
616
|
return ask<T | undefined>(
|
|
610
617
|
{
|
|
@@ -773,7 +780,7 @@ function App({
|
|
|
773
780
|
/** 把选中的文字放进剪贴板 */
|
|
774
781
|
copy(text: string): void;
|
|
775
782
|
version: string;
|
|
776
|
-
commands: CommandInfo[];
|
|
783
|
+
commands: () => CommandInfo[];
|
|
777
784
|
handlers: TuiHandlers;
|
|
778
785
|
history: string[];
|
|
779
786
|
draft: DraftBridge;
|
|
@@ -845,10 +852,16 @@ function App({
|
|
|
845
852
|
};
|
|
846
853
|
|
|
847
854
|
// Ink 增量渲染只用相对光标移动,第一帧起点一旦偏了(启动时终端尺寸还没稳定、窗口缩放、别的输出插进来),
|
|
848
|
-
//
|
|
855
|
+
// 之后每帧都会画错行。尺寸变化后和按 Ctrl+L 时让一帧比终端高,Ink 会清屏从左上角整帧重画(包在同步输出里),下一帧再恢复。
|
|
856
|
+
// 启动时不重画:第一帧之前已经清屏、光标在左上角;这两次清屏在不支持同步输出的终端上(Windows 上常见)看得出闪一下
|
|
849
857
|
const [redraws, setRedraws] = useState(0);
|
|
850
858
|
const [repaint, setRepaint] = useState(false);
|
|
859
|
+
const mounted = useRef(false);
|
|
851
860
|
useEffect(() => {
|
|
861
|
+
if (!mounted.current) {
|
|
862
|
+
mounted.current = true;
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
852
865
|
const t = setTimeout(() => setRepaint(true), 100);
|
|
853
866
|
return () => clearTimeout(t);
|
|
854
867
|
}, [columns, rows, redraws]);
|
|
@@ -904,77 +917,75 @@ function App({
|
|
|
904
917
|
// 总高度要比终端少一行,否则 Ink 认为输出占满了屏幕,每帧清屏重画。
|
|
905
918
|
// 重画那一帧上下各垫一行空白:终端把顶上那行滚出去后,看到的和平时逐行一样,所以不会闪。
|
|
906
919
|
// 只做纵向裁剪:每行都已按宽度折好或截断,横向裁剪会让 Ink 每帧对每一行再切一遍 ANSI 字符串
|
|
907
|
-
return (
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
<
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
920
|
+
return h(
|
|
921
|
+
SelectionContext.Provider,
|
|
922
|
+
{ value: selectionApi },
|
|
923
|
+
h(
|
|
924
|
+
Box,
|
|
925
|
+
{
|
|
926
|
+
flexDirection: "column",
|
|
927
|
+
width: columns,
|
|
928
|
+
height: repaint ? rows + 1 : Math.max(1, rows - 1),
|
|
929
|
+
paddingY: repaint ? 1 : 0,
|
|
930
|
+
overflowY: "hidden",
|
|
931
|
+
},
|
|
932
|
+
// 垫的空白放在外层:里面这层在重画那一帧和平时一样高,对话区的 top(相对父节点)不变,点击换算的行号不会差一行
|
|
933
|
+
h(
|
|
934
|
+
Box,
|
|
935
|
+
{ flexDirection: "column", flexGrow: 1, overflowY: "hidden" },
|
|
936
|
+
h(Header, { status: state.status, version, compact: rows < COMPACT_ROWS }),
|
|
937
|
+
h(
|
|
938
|
+
Box,
|
|
939
|
+
{
|
|
940
|
+
ref,
|
|
941
|
+
flexDirection: "column",
|
|
942
|
+
flexGrow: 1,
|
|
943
|
+
flexShrink: 1,
|
|
944
|
+
flexBasis: 0,
|
|
945
|
+
overflowY: "hidden",
|
|
946
|
+
paddingX: 1,
|
|
947
|
+
},
|
|
948
|
+
shown.map((l, i) => {
|
|
933
949
|
const cols = selection && selectedCols(selection, start + i);
|
|
934
|
-
return (
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
{
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
{
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
<StatusBar status={state.status} width={Math.max(10, columns - 2)} />
|
|
974
|
-
</Box>
|
|
975
|
-
</Box>
|
|
976
|
-
</Box>
|
|
977
|
-
</SelectionContext.Provider>
|
|
950
|
+
return h(Text, { key: i, wrap: "truncate-end" }, cols ? highlight(l || " ", ...cols) : l || " ");
|
|
951
|
+
}),
|
|
952
|
+
scrolled
|
|
953
|
+
? h(
|
|
954
|
+
Text,
|
|
955
|
+
{ dimColor: true, wrap: "truncate-end" },
|
|
956
|
+
`── ↓ ${scroll} more lines · wheel / PgDn to scroll · ctrl+end to jump to the bottom ──`,
|
|
957
|
+
)
|
|
958
|
+
: null,
|
|
959
|
+
),
|
|
960
|
+
h(
|
|
961
|
+
Box,
|
|
962
|
+
{ flexDirection: "column", flexShrink: 0 },
|
|
963
|
+
state.busy && !dialog ? h(Spinner, { label: state.busy.label, since: state.busy.since }) : null,
|
|
964
|
+
state.queued.map((q, i) =>
|
|
965
|
+
h(Text, { key: i, dimColor: true, wrap: "truncate-end" }, " ↳ queued: ", q.replace(/\s+/g, " ")),
|
|
966
|
+
),
|
|
967
|
+
dialog
|
|
968
|
+
? dialog.kind === "select"
|
|
969
|
+
? h(SelectDialog, { key: dialogKey(dialog), dialog })
|
|
970
|
+
: h(InputDialog, { key: dialogKey(dialog), dialog })
|
|
971
|
+
: null,
|
|
972
|
+
h(Prompt, {
|
|
973
|
+
commands,
|
|
974
|
+
handlers,
|
|
975
|
+
history,
|
|
976
|
+
bridge: draft,
|
|
977
|
+
hint: state.hint,
|
|
978
|
+
onHintDone: () => store.update({ hint: undefined }),
|
|
979
|
+
busy: Boolean(state.busy),
|
|
980
|
+
queued: state.queued.length > 0,
|
|
981
|
+
active: !dialog,
|
|
982
|
+
onSubmit: () => store.scrollBy(-max, max),
|
|
983
|
+
flash: copied,
|
|
984
|
+
}),
|
|
985
|
+
h(StatusBar, { status: state.status, width: Math.max(10, columns - 2) }),
|
|
986
|
+
),
|
|
987
|
+
),
|
|
988
|
+
),
|
|
978
989
|
);
|
|
979
990
|
}
|
|
980
991
|
|
|
@@ -986,18 +997,12 @@ const SHINE = "#b6f2d4";
|
|
|
986
997
|
* 每个字符上下两个像素;眼睛是玉上挖空的两格,左上角一点高光让它看起来像玉
|
|
987
998
|
*/
|
|
988
999
|
function Bot() {
|
|
989
|
-
return (
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
</Text>
|
|
996
|
-
{"████▄"}
|
|
997
|
-
</Text>
|
|
998
|
-
<Text color={JADE}>██ ███ ██</Text>
|
|
999
|
-
<Text color={JADE}>▀███████▀</Text>
|
|
1000
|
-
</Box>
|
|
1000
|
+
return h(
|
|
1001
|
+
Box,
|
|
1002
|
+
{ flexDirection: "column", flexShrink: 0, marginRight: 2 },
|
|
1003
|
+
h(Text, { color: JADE }, " ▄", h(Text, { color: SHINE, backgroundColor: JADE }, "▄"), "████▄"),
|
|
1004
|
+
h(Text, { color: JADE }, "██ ███ ██"),
|
|
1005
|
+
h(Text, { color: JADE }, "▀███████▀"),
|
|
1001
1006
|
);
|
|
1002
1007
|
}
|
|
1003
1008
|
|
|
@@ -1012,49 +1017,37 @@ function Header({
|
|
|
1012
1017
|
compact: boolean;
|
|
1013
1018
|
}) {
|
|
1014
1019
|
const { columns } = useScreenSize();
|
|
1020
|
+
// 模型 · 目录 (分支)
|
|
1021
|
+
const where = [
|
|
1022
|
+
h(Text, { key: "model", color: "cyan" }, status.model),
|
|
1023
|
+
h(Text, { key: "sep", dimColor: true }, " · "),
|
|
1024
|
+
h(Text, { key: "cwd" }, status.cwd),
|
|
1025
|
+
status.branch ? h(Text, { key: "branch", color: "magenta" }, ` (${status.branch})`) : null,
|
|
1026
|
+
];
|
|
1027
|
+
const name = h(Text, { key: "name", color: "cyan", bold: true }, "jade");
|
|
1015
1028
|
if (compact)
|
|
1016
|
-
return (
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
jade
|
|
1021
|
-
</Text>
|
|
1022
|
-
<Text dimColor> · </Text>
|
|
1023
|
-
<Text color="cyan">{status.model}</Text>
|
|
1024
|
-
<Text dimColor> · </Text>
|
|
1025
|
-
<Text>{status.cwd}</Text>
|
|
1026
|
-
{status.branch ? (
|
|
1027
|
-
<Text color="magenta"> ({status.branch})</Text>
|
|
1028
|
-
) : null}
|
|
1029
|
-
</Text>
|
|
1030
|
-
</Box>
|
|
1029
|
+
return h(
|
|
1030
|
+
Box,
|
|
1031
|
+
{ flexShrink: 0, paddingX: 1 },
|
|
1032
|
+
h(Text, { wrap: "truncate-end" }, name, h(Text, { key: "dot", dimColor: true }, " · "), ...where),
|
|
1031
1033
|
);
|
|
1032
|
-
return (
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
{status.branch ? (
|
|
1050
|
-
<Text color="magenta"> ({status.branch})</Text>
|
|
1051
|
-
) : null}
|
|
1052
|
-
</Text>
|
|
1053
|
-
<Text dimColor wrap="truncate-end">
|
|
1054
|
-
/help for commands · @ to attach files
|
|
1055
|
-
</Text>
|
|
1056
|
-
</Box>
|
|
1057
|
-
</Box>
|
|
1034
|
+
return h(
|
|
1035
|
+
Box,
|
|
1036
|
+
{ flexShrink: 0, borderStyle: "round", borderColor: "cyan", paddingX: 1 },
|
|
1037
|
+
columns >= 50 ? h(Bot) : null,
|
|
1038
|
+
h(
|
|
1039
|
+
Box,
|
|
1040
|
+
{ flexDirection: "column", flexGrow: 1, flexShrink: 1 },
|
|
1041
|
+
h(
|
|
1042
|
+
Text,
|
|
1043
|
+
{ wrap: "truncate-end" },
|
|
1044
|
+
name,
|
|
1045
|
+
h(Text, { dimColor: true }, ` v${version}`),
|
|
1046
|
+
status.session ? h(Text, { dimColor: true }, ` · session ${status.session}`) : null,
|
|
1047
|
+
),
|
|
1048
|
+
h(Text, { wrap: "truncate-end" }, ...where),
|
|
1049
|
+
h(Text, { dimColor: true, wrap: "truncate-end" }, "/help for commands · @ to attach files"),
|
|
1050
|
+
),
|
|
1058
1051
|
);
|
|
1059
1052
|
}
|
|
1060
1053
|
|
|
@@ -1071,14 +1064,16 @@ const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "
|
|
|
1071
1064
|
function Spinner({ label, since }: { label: string; since: number }) {
|
|
1072
1065
|
const now = Date.now();
|
|
1073
1066
|
const seconds = Math.floor((now - since) / 1000);
|
|
1074
|
-
return (
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1067
|
+
return h(
|
|
1068
|
+
Box,
|
|
1069
|
+
{ marginTop: 1 },
|
|
1070
|
+
h(
|
|
1071
|
+
Text,
|
|
1072
|
+
{ wrap: "truncate-end" },
|
|
1073
|
+
h(Text, { color: "cyan" }, `${FRAMES[Math.floor(now / 100) % FRAMES.length]} `),
|
|
1074
|
+
h(Text, null, `${label}… `),
|
|
1075
|
+
h(Text, { dimColor: true }, `(${seconds}s · esc to interrupt)`),
|
|
1076
|
+
),
|
|
1082
1077
|
);
|
|
1083
1078
|
}
|
|
1084
1079
|
|
|
@@ -1181,19 +1176,16 @@ function StatusBar({ status, width }: { status: StatusInfo; width: number }) {
|
|
|
1181
1176
|
},
|
|
1182
1177
|
];
|
|
1183
1178
|
const shown = fitSegments(segments, width);
|
|
1184
|
-
return (
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
))}
|
|
1195
|
-
</Text>
|
|
1196
|
-
</Box>
|
|
1179
|
+
return h(
|
|
1180
|
+
Box,
|
|
1181
|
+
{ paddingX: 1 },
|
|
1182
|
+
h(
|
|
1183
|
+
Text,
|
|
1184
|
+
{ wrap: "truncate-end" },
|
|
1185
|
+
shown.map((s, i) =>
|
|
1186
|
+
h(Text, { key: i }, i ? h(Text, { dimColor: true }, " · ") : null, h(Text, { color: s.color, dimColor: s.dim }, s.text)),
|
|
1187
|
+
),
|
|
1188
|
+
),
|
|
1197
1189
|
);
|
|
1198
1190
|
}
|
|
1199
1191
|
|
|
@@ -1201,11 +1193,7 @@ function StatusBar({ status, width }: { status: StatusInfo; width: number }) {
|
|
|
1201
1193
|
function Hint({ variants, width }: { variants: string[]; width: number }) {
|
|
1202
1194
|
const text =
|
|
1203
1195
|
variants.find((v) => stringWidth(v) <= width) ?? variants.at(-1)!;
|
|
1204
|
-
return (
|
|
1205
|
-
<Text dimColor wrap="truncate-end">
|
|
1206
|
-
{text}
|
|
1207
|
-
</Text>
|
|
1208
|
-
);
|
|
1196
|
+
return h(Text, { dimColor: true, wrap: "truncate-end" }, text);
|
|
1209
1197
|
}
|
|
1210
1198
|
|
|
1211
1199
|
const tokens = (n: number) =>
|
|
@@ -1241,6 +1229,8 @@ function editKey(s: EditState, input: string, key: Key): EditState | undefined {
|
|
|
1241
1229
|
if (key.backspace) return key.meta ? edit.deleteWord(s) : edit.backspace(s);
|
|
1242
1230
|
if (key.delete || (key.ctrl && input === "d")) return edit.del(s);
|
|
1243
1231
|
if (key.ctrl && input === "w") return edit.deleteWord(s);
|
|
1232
|
+
if (key.meta && !key.ctrl && input === "f") return edit.wordRight(s);
|
|
1233
|
+
if (key.meta && !key.ctrl && input === "b") return edit.wordLeft(s);
|
|
1244
1234
|
if (key.ctrl && input === "u") return edit.killBefore(s);
|
|
1245
1235
|
if (key.ctrl && input === "k") return edit.killAfter(s);
|
|
1246
1236
|
if (
|
|
@@ -1325,29 +1315,24 @@ function EditableText({
|
|
|
1325
1315
|
if (now.x !== at.x || now.y !== at.y) recheck();
|
|
1326
1316
|
});
|
|
1327
1317
|
|
|
1328
|
-
return (
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
{
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
{r}
|
|
1347
|
-
</Text>
|
|
1348
|
-
))
|
|
1349
|
-
)}
|
|
1350
|
-
</Box>
|
|
1318
|
+
return h(
|
|
1319
|
+
Box,
|
|
1320
|
+
{ ref, flexDirection: "column" },
|
|
1321
|
+
active ? h(CursorAt, { position }) : null,
|
|
1322
|
+
state.value === "" && placeholder
|
|
1323
|
+
? h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, prefix), h(Text, { dimColor: true }, placeholder))
|
|
1324
|
+
: rows.map((r, i) =>
|
|
1325
|
+
h(
|
|
1326
|
+
Text,
|
|
1327
|
+
{ key: first + i, wrap: "truncate-end" },
|
|
1328
|
+
h(
|
|
1329
|
+
Text,
|
|
1330
|
+
{ color: "cyan" },
|
|
1331
|
+
first + i === 0 ? prefix : i === 0 ? "↑".padEnd(prefix.length) : " ".repeat(prefix.length),
|
|
1332
|
+
),
|
|
1333
|
+
r,
|
|
1334
|
+
),
|
|
1335
|
+
),
|
|
1351
1336
|
);
|
|
1352
1337
|
}
|
|
1353
1338
|
|
|
@@ -1377,17 +1362,27 @@ function Prompt({
|
|
|
1377
1362
|
handlers,
|
|
1378
1363
|
history: initial,
|
|
1379
1364
|
bridge,
|
|
1365
|
+
hint,
|
|
1366
|
+
onHintDone,
|
|
1380
1367
|
busy,
|
|
1368
|
+
queued,
|
|
1381
1369
|
active,
|
|
1382
1370
|
onSubmit,
|
|
1383
1371
|
flash,
|
|
1384
1372
|
}: {
|
|
1385
|
-
|
|
1373
|
+
/** 当前的命令(随会话的插件增减),每次算菜单时取 */
|
|
1374
|
+
commands: () => CommandInfo[];
|
|
1386
1375
|
handlers: TuiHandlers;
|
|
1387
1376
|
history: string[];
|
|
1388
1377
|
/** 让 tuiScreen 的 draft 读写输入框 */
|
|
1389
1378
|
bridge: DraftBridge;
|
|
1379
|
+
/** 插件设置的灰色提示 */
|
|
1380
|
+
hint?: string;
|
|
1381
|
+
/** 提示被接受了,或者用户开始打字了:去掉它 */
|
|
1382
|
+
onHintDone(): void;
|
|
1390
1383
|
busy: boolean;
|
|
1384
|
+
/** 有排队等待发送的消息 */
|
|
1385
|
+
queued: boolean;
|
|
1391
1386
|
active: boolean;
|
|
1392
1387
|
/** 提交后对话区回到底部 */
|
|
1393
1388
|
onSubmit(): void;
|
|
@@ -1424,7 +1419,7 @@ function Prompt({
|
|
|
1424
1419
|
>(undefined);
|
|
1425
1420
|
|
|
1426
1421
|
const usageOf = (c: CommandInfo) => `/${c.name}${c.args ? ` ${c.args}` : ""}`;
|
|
1427
|
-
const column = Math.max(...commands.map((c) => usageOf(c).length)) + 2;
|
|
1422
|
+
const column = Math.max(...commands().map((c) => usageOf(c).length)) + 2;
|
|
1428
1423
|
|
|
1429
1424
|
/** 由最新的输入算出补全菜单和搜索结果;渲染和按键处理都用它 */
|
|
1430
1425
|
const derive = () => {
|
|
@@ -1439,7 +1434,7 @@ function Prompt({
|
|
|
1439
1434
|
const naming =
|
|
1440
1435
|
!recalled && state.value.startsWith("/") && !/\s/.test(state.value);
|
|
1441
1436
|
const matches = naming
|
|
1442
|
-
? commands.filter((c) => `/${c.name}`.startsWith(state.value))
|
|
1437
|
+
? commands().filter((c) => `/${c.name}`.startsWith(state.value))
|
|
1443
1438
|
: [];
|
|
1444
1439
|
const pick = matches[Math.min(selected, matches.length - 1)];
|
|
1445
1440
|
// @ 引用:光标处正在输入的路径和补全候选
|
|
@@ -1501,7 +1496,11 @@ function Prompt({
|
|
|
1501
1496
|
const firstMatch = around(Math.max(0, matches.indexOf(pick!)), matches.length, menuRows);
|
|
1502
1497
|
const firstFound = around(Math.max(0, found.indexOf(file!)), found.length, menuRows);
|
|
1503
1498
|
|
|
1499
|
+
/** 提示只在空闲、输入框为空、没有在搜索历史时显示,也只有这时能接受 */
|
|
1500
|
+
const hinting = () => hint !== undefined && !busy && current().value === "" && !getSearch();
|
|
1504
1501
|
const set = (s: EditState) => {
|
|
1502
|
+
// 用户开始打字(或者插件改了输入框):提示作废
|
|
1503
|
+
if (s.value && hint !== undefined) onHintDone();
|
|
1505
1504
|
setState(s);
|
|
1506
1505
|
setSelected(0);
|
|
1507
1506
|
setNotice(undefined);
|
|
@@ -1651,6 +1650,12 @@ function Prompt({
|
|
|
1651
1650
|
if (file) return complete(file);
|
|
1652
1651
|
return submit(state.value.trim());
|
|
1653
1652
|
}
|
|
1653
|
+
// Tab 或 →:把提示变成输入框里的文字,接着可以改
|
|
1654
|
+
if (((key.tab && !key.shift) || key.rightArrow) && hinting()) {
|
|
1655
|
+
onHintDone();
|
|
1656
|
+
browsing.current = -1;
|
|
1657
|
+
return set({ value: hint!, cursor: hint!.length });
|
|
1658
|
+
}
|
|
1654
1659
|
if (key.tab && key.shift) return handlers.cycleMode?.();
|
|
1655
1660
|
if (key.tab) {
|
|
1656
1661
|
const { pick, file } = derive();
|
|
@@ -1668,6 +1673,11 @@ function Prompt({
|
|
|
1668
1673
|
// 按折行后的屏幕行移动:一大段没有换行的文字也能上下走,到了第一行才翻历史
|
|
1669
1674
|
const up = moveRow(state, textWidth, -1);
|
|
1670
1675
|
if (up) return setState(up);
|
|
1676
|
+
// 先取回排队的消息,取完了再翻历史
|
|
1677
|
+
if (handlers.unqueue?.()) {
|
|
1678
|
+
browsing.current = -1;
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1671
1681
|
if (browsing.current + 1 < history.current.length) {
|
|
1672
1682
|
if (browsing.current === -1) draft.current = state.value;
|
|
1673
1683
|
recall(browsing.current + 1);
|
|
@@ -1691,132 +1701,116 @@ function Prompt({
|
|
|
1691
1701
|
);
|
|
1692
1702
|
|
|
1693
1703
|
// 对话框打开时隐藏但不卸载,输入到一半的内容和历史都保留
|
|
1694
|
-
return (
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1704
|
+
return h(
|
|
1705
|
+
Box,
|
|
1706
|
+
{ flexDirection: "column", marginTop: 1, display: active ? "flex" : "none" },
|
|
1707
|
+
h(
|
|
1708
|
+
Box,
|
|
1709
|
+
{ borderStyle: "round", borderColor: busy ? "gray" : "cyan", paddingX: 1 },
|
|
1710
|
+
search
|
|
1711
|
+
? h(EditableText, {
|
|
1712
|
+
state: { value: search.query, cursor: search.query.length },
|
|
1713
|
+
width: Math.max(10, columns - 5),
|
|
1714
|
+
prefix: "search history› ",
|
|
1715
|
+
placeholder: "type to filter",
|
|
1716
|
+
active,
|
|
1717
|
+
maxRows: inputRows,
|
|
1718
|
+
})
|
|
1719
|
+
: h(EditableText, {
|
|
1720
|
+
state,
|
|
1721
|
+
width: Math.max(10, columns - 5),
|
|
1722
|
+
prefix: "› ",
|
|
1723
|
+
placeholder: hinting()
|
|
1724
|
+
? hintLine(hint!)
|
|
1725
|
+
: queued
|
|
1726
|
+
? "↑ to edit queued messages · esc to interrupt"
|
|
1727
|
+
: busy
|
|
1728
|
+
? "Type to queue a message · esc to interrupt"
|
|
1729
|
+
: columns >= 70
|
|
1730
|
+
? "Message jade · / commands · @ files · ↑ or ctrl+r for history"
|
|
1731
|
+
: "Message jade · / commands · @ files",
|
|
1732
|
+
active,
|
|
1733
|
+
maxRows: inputRows,
|
|
1734
|
+
place,
|
|
1735
|
+
}),
|
|
1736
|
+
),
|
|
1737
|
+
search
|
|
1738
|
+
? h(
|
|
1739
|
+
Box,
|
|
1740
|
+
{ flexDirection: "column", paddingX: 2 },
|
|
1741
|
+
results.length
|
|
1742
|
+
? results.slice(first, first + menuRows).map((item, i) => {
|
|
1743
|
+
const on = first + i === hit;
|
|
1744
|
+
return h(
|
|
1745
|
+
Text,
|
|
1746
|
+
{ key: first + i, wrap: "truncate-end", color: on ? "cyan" : undefined, bold: on },
|
|
1747
|
+
on ? "❯ " : " ",
|
|
1748
|
+
item.replace(/\s*\n\s*/g, " ⏎ "),
|
|
1749
|
+
);
|
|
1750
|
+
})
|
|
1751
|
+
: h(Text, { dimColor: true }, " no match"),
|
|
1752
|
+
h(Hint, {
|
|
1753
|
+
width: hintWidth,
|
|
1754
|
+
variants: [" ↑↓ or ctrl+r select · enter/tab put in the input · esc cancel", " ↑↓ select · enter use · esc cancel"],
|
|
1755
|
+
}),
|
|
1756
|
+
)
|
|
1757
|
+
: matches.length
|
|
1758
|
+
? h(
|
|
1759
|
+
Box,
|
|
1760
|
+
{ flexDirection: "column", paddingX: 2 },
|
|
1761
|
+
matches.slice(firstMatch, firstMatch + menuRows).map((c) => {
|
|
1762
|
+
const on = c === pick;
|
|
1763
|
+
return h(
|
|
1764
|
+
Text,
|
|
1765
|
+
{ key: c.name, wrap: "truncate-end" },
|
|
1766
|
+
h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", usageOf(c).padEnd(column)),
|
|
1767
|
+
h(Text, { dimColor: true }, c.about),
|
|
1747
1768
|
);
|
|
1748
|
-
})
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
{found.slice(firstFound, firstFound + menuRows).map((p) => {
|
|
1785
|
-
const on = p === file;
|
|
1786
|
-
return (
|
|
1787
|
-
<Text
|
|
1788
|
-
key={p}
|
|
1789
|
-
wrap="truncate-middle"
|
|
1790
|
-
color={on ? "cyan" : p.endsWith("/") ? "blue" : undefined}
|
|
1791
|
-
bold={on}
|
|
1792
|
-
>
|
|
1793
|
-
{on ? "❯ " : " "}
|
|
1794
|
-
{p}
|
|
1795
|
-
</Text>
|
|
1796
|
-
);
|
|
1797
|
-
})}
|
|
1798
|
-
<Hint
|
|
1799
|
-
width={hintWidth}
|
|
1800
|
-
variants={[
|
|
1801
|
-
" ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
|
|
1802
|
-
" ↑↓ select · enter/tab insert the path",
|
|
1803
|
-
" ↑↓ · enter insert",
|
|
1804
|
-
]}
|
|
1805
|
-
/>
|
|
1806
|
-
</Box>
|
|
1807
|
-
) : notice ? (
|
|
1808
|
-
<Text color="yellow"> {notice}</Text>
|
|
1809
|
-
) : null}
|
|
1810
|
-
{/* 压在输入框上边框的右边,不占行,出现和消失时下面的内容不跳 */}
|
|
1811
|
-
{flash ? (
|
|
1812
|
-
<Box position="absolute" top={0} right={2}>
|
|
1813
|
-
<Text color="green"> {flash} </Text>
|
|
1814
|
-
</Box>
|
|
1815
|
-
) : null}
|
|
1816
|
-
</Box>
|
|
1769
|
+
}),
|
|
1770
|
+
h(Hint, {
|
|
1771
|
+
width: hintWidth,
|
|
1772
|
+
variants: [
|
|
1773
|
+
` ↑↓ select · enter run · tab complete${matches.length > menuRows ? ` · ${matches.length} commands` : ""}`,
|
|
1774
|
+
" ↑↓ · enter run · tab complete",
|
|
1775
|
+
],
|
|
1776
|
+
}),
|
|
1777
|
+
)
|
|
1778
|
+
: found.length
|
|
1779
|
+
? h(
|
|
1780
|
+
Box,
|
|
1781
|
+
{ flexDirection: "column", paddingX: 2 },
|
|
1782
|
+
found.slice(firstFound, firstFound + menuRows).map((p) => {
|
|
1783
|
+
const on = p === file;
|
|
1784
|
+
return h(
|
|
1785
|
+
Text,
|
|
1786
|
+
{ key: p, wrap: "truncate-middle", color: on ? "cyan" : p.endsWith("/") ? "blue" : undefined, bold: on },
|
|
1787
|
+
on ? "❯ " : " ",
|
|
1788
|
+
p,
|
|
1789
|
+
);
|
|
1790
|
+
}),
|
|
1791
|
+
h(Hint, {
|
|
1792
|
+
width: hintWidth,
|
|
1793
|
+
variants: [
|
|
1794
|
+
" ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
|
|
1795
|
+
" ↑↓ select · enter/tab insert the path",
|
|
1796
|
+
" ↑↓ · enter insert",
|
|
1797
|
+
],
|
|
1798
|
+
}),
|
|
1799
|
+
)
|
|
1800
|
+
: notice
|
|
1801
|
+
? h(Text, { color: "yellow" }, ` ${notice}`)
|
|
1802
|
+
: null,
|
|
1803
|
+
// 压在输入框上边框的右边,不占行,出现和消失时下面的内容不跳
|
|
1804
|
+
flash ? h(Box, { position: "absolute", top: 0, right: 2 }, h(Text, { color: "green" }, ` ${flash} `)) : null,
|
|
1817
1805
|
);
|
|
1818
1806
|
}
|
|
1819
1807
|
|
|
1808
|
+
/** 提示在输入框里只显示第一行,后面还有时加 … */
|
|
1809
|
+
const hintLine = (hint: string) => {
|
|
1810
|
+
const [first, ...rest] = hint.split("\n");
|
|
1811
|
+
return `${first}${rest.length ? " …" : ""}`;
|
|
1812
|
+
};
|
|
1813
|
+
|
|
1820
1814
|
/** @ 补全最多显示几项 */
|
|
1821
1815
|
const MENTION_ROWS = 8;
|
|
1822
1816
|
|
|
@@ -1901,61 +1895,41 @@ function SelectDialog({
|
|
|
1901
1895
|
});
|
|
1902
1896
|
// 选项多时只显示选中项附近的一段
|
|
1903
1897
|
const start = around(selected, n, visible);
|
|
1904
|
-
return (
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
)
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
{filtering ? "" : `${i + 1}. `}
|
|
1940
|
-
{c.label}
|
|
1941
|
-
</Text>
|
|
1942
|
-
{c.hint ? <Text dimColor> {c.hint}</Text> : null}
|
|
1943
|
-
</Text>
|
|
1944
|
-
);
|
|
1945
|
-
})}
|
|
1946
|
-
{start + visible < n ? (
|
|
1947
|
-
<Text dimColor> ↓ {n - start - visible} more</Text>
|
|
1948
|
-
) : null}
|
|
1949
|
-
</Box>
|
|
1950
|
-
<Hint
|
|
1951
|
-
width={Math.max(10, columns - 4)}
|
|
1952
|
-
variants={
|
|
1953
|
-
filtering
|
|
1954
|
-
? ["↑↓ select · type to filter · enter confirm · esc clear/cancel", "↑↓ · enter · esc"]
|
|
1955
|
-
: ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"]
|
|
1956
|
-
}
|
|
1957
|
-
/>
|
|
1958
|
-
</Box>
|
|
1898
|
+
return h(
|
|
1899
|
+
Box,
|
|
1900
|
+
{ flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 },
|
|
1901
|
+
h(Text, { bold: true, wrap: "truncate-end" }, dialog.title),
|
|
1902
|
+
body.map((l, i) => h(Text, { key: i, wrap: "truncate-end" }, l || " ")),
|
|
1903
|
+
filtering
|
|
1904
|
+
? h(
|
|
1905
|
+
Text,
|
|
1906
|
+
{ wrap: "truncate-end" },
|
|
1907
|
+
h(Text, { color: "cyan" }, "filter› "),
|
|
1908
|
+
query ? h(Text, null, query) : h(Text, { dimColor: true }, `type to filter ${dialog.choices.length} items`),
|
|
1909
|
+
)
|
|
1910
|
+
: null,
|
|
1911
|
+
h(
|
|
1912
|
+
Box,
|
|
1913
|
+
{ flexDirection: "column", marginTop: filtering ? 0 : 1 },
|
|
1914
|
+
start > 0 ? h(Text, { dimColor: true }, ` ↑ ${start} more`) : null,
|
|
1915
|
+
n === 0 ? h(Text, { dimColor: true }, " no match") : null,
|
|
1916
|
+
items.slice(start, start + visible).map(({ c, i }, j) => {
|
|
1917
|
+
const on = start + j === selected;
|
|
1918
|
+
return h(
|
|
1919
|
+
Text,
|
|
1920
|
+
{ key: i, wrap: "truncate-end" },
|
|
1921
|
+
h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", filtering ? "" : `${i + 1}. `, c.label),
|
|
1922
|
+
c.hint ? h(Text, { dimColor: true }, ` ${c.hint}`) : null,
|
|
1923
|
+
);
|
|
1924
|
+
}),
|
|
1925
|
+
start + visible < n ? h(Text, { dimColor: true }, ` ↓ ${n - start - visible} more`) : null,
|
|
1926
|
+
),
|
|
1927
|
+
h(Hint, {
|
|
1928
|
+
width: Math.max(10, columns - 4),
|
|
1929
|
+
variants: filtering
|
|
1930
|
+
? ["↑↓ select · type to filter · enter confirm · esc clear/cancel", "↑↓ · enter · esc"]
|
|
1931
|
+
: ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"],
|
|
1932
|
+
}),
|
|
1959
1933
|
);
|
|
1960
1934
|
}
|
|
1961
1935
|
|
|
@@ -1984,24 +1958,18 @@ function InputDialog({
|
|
|
1984
1958
|
const next = editKey(state, input, key);
|
|
1985
1959
|
if (next) setState(next);
|
|
1986
1960
|
});
|
|
1987
|
-
return (
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
mask={dialog.mask}
|
|
2001
|
-
placeholder={dialog.placeholder}
|
|
2002
|
-
active
|
|
2003
|
-
/>
|
|
2004
|
-
<Text dimColor>enter confirm · esc cancel</Text>
|
|
2005
|
-
</Box>
|
|
1961
|
+
return h(
|
|
1962
|
+
Box,
|
|
1963
|
+
{ flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 },
|
|
1964
|
+
h(Text, { bold: true }, dialog.title),
|
|
1965
|
+
h(EditableText, {
|
|
1966
|
+
state,
|
|
1967
|
+
width: Math.max(10, columns - 6),
|
|
1968
|
+
prefix: "› ",
|
|
1969
|
+
mask: dialog.mask,
|
|
1970
|
+
placeholder: dialog.placeholder,
|
|
1971
|
+
active: true,
|
|
1972
|
+
}),
|
|
1973
|
+
h(Text, { dimColor: true }, "enter confirm · esc cancel"),
|
|
2006
1974
|
);
|
|
2007
1975
|
}
|