rea
morluto
Reverse engineer anything with agents, from app behavior down to native binaries.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:whitewatercn/dsh-hotkeys-platform
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
正在开发中,还不能使用
DeepSeek Harness(DSH)Web 插件:快捷键设定平台。
把「每个插件各自拦截键盘、各写各的设置」升级为一个注册表服务 ctx.hotkeys:
ctx.hotkeys.registerAction(...) 注册「动作 → 处理器」;/hotkeys 命令提供统一配置。架构与 dsh-better-sidebar 同构:平台 ctx.provide('hotkeys', service),业务动作由消费插件注册(吃狗粮),能力对等。
使用示例:docs/example.md
export const inject = ['hotkeys']
export function apply(ctx: Context): void {
ctx.effect(() =>
ctx.hotkeys.registerAction({
id: 'my-plugin:send-message',
title: () => t('发送'),
description: '发送当前消息',
group: '消息',
scope: 'input',
defaultKey: 'Control+Enter',
handler: (event, h) => {
// 命中后的处理;返回 false 表示「不消费,放行给 DSH 原生行为」。
h.dispatchEnter(h.target ?? event.target)
},
})
)
}
要点:
inject = ['hotkeys'] 让 Cordis 在平台就绪后才激活你的插件(ctx.hotkeys 恒存在);registerAction 返回 disposer,必须包在 ctx.effect(...) 里(HMR-safe);id 建议包前缀(my-plugin:xxx),避免冲突。| 点 | 说明 |
|---|---|
ctx.get('hotkeys') + 判空 |
平台是可选项,读不到就跳过;不要用 inject 之外的 ctx.hotkeys 直接访问 |
ctx.effect 包裹 |
registerAction 返回 disposer,fiber 卸载(HMR/禁用)时自动撤销注册,否则下次激活抛 already registered |
id 用包前缀 |
dsh-better-archive:open-archived,避免与别的插件冲突 |
scope: 'global' |
任意处可触发;若动作只在输入框有意义,改 scope: 'input';提问卡内用 question-card;精确判定用 custom + target(el) |
handler 返回 false |
表示「不消费这次按键,放行给 DSH 原生/后续动作」——例如你想让某键只在特定条件下生效,条件不满足时 return false |
如果某个快捷键动作要触发 host 侧能力(读写文件、执行命令、归档会话等),平台不承载这些逻辑——由你的插件自带 host 路由,handler 里 fetch 即可。例如 better-archive 的「清空全部归档」动作可以这样写:
handler: async () => {
await fetch('/archived/delete-all', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ confirm: true }),
})
}
这正是平台「host 仅可选扩展」的设计:host 半只留一个可选的
hotkeys设置命名空间,业务 host 能力一律由各插件自己的/路由提供。
dsh web(peer 依赖新增需重启),浏览器强刷;Ctrl+Shift+A;Ctrl+Shift+A,应跳转到「已归档」设置页;| 字段 | 说明 |
|---|---|
id |
唯一 id,建议包前缀 |
title |
标题(字符串或 () => string,i18n 友好) |
description |
描述,显示在设置页 |
group |
分组(设置页分区展示) |
defaultKey |
默认组合键,如 'Control+Enter';空串 = 默认不绑 |
scope |
global / input / question-card / command-palette / custom |
target |
scope='custom' 时的精确判定 (el) => boolean |
handler |
(event, ctx) => void | false;返回 false 表示不消费、放行 |
hidden |
设置页隐藏(默认 false) |
order |
排序(升序,默认 100) |
内置 scope:
| scope | 判定 |
|---|---|
global |
任意处 |
input |
可编辑文本区(textarea / input[type=text]) |
question-card |
DeepSeek 提问卡([data-question-key])内 |
command-palette |
命令菜单/下拉打开时 |
custom |
自定义 target(el) 判定 |
Handler 上下文 ctx:target(事件目标)、dispatchEnter(el)(合成裸 Enter,防重入)、insertTextAtCaret(el, text)、hasOpenOverlay()、isEditableTarget(el)。
interface HotkeyService {
registerAction(d: HotkeyActionDescriptor): () => void
getActions(): readonly HotkeyActionDescriptor[]
getBindings(): Readonly<Record<string, string>> // 只存用户改过的
effectiveKey(actionId: string): string | null // 用户绑定 ?? 默认 ?? null(禁用)
setBinding(actionId: string, combo: string): void // combo='' 表示显式禁用
clearBinding(actionId: string): void // 删除绑定,回落 defaultKey
record(actionId: string): Promise<string | null> // 录制
subscribe(listener: () => void): () => void
readonly features: readonly string[] // 'record' | 'subscribe' | 'effectiveKey' | 'clearBinding'
readonly version: string
}
dsh.hotkeys.v1,只存用户显式改过的 { actionId: combo };defaultKey)/ 具体串(用户绑定)/ ''(显式禁用,连默认也关掉);dsh-hotkeys 的 dsh.sendkeys.v1 迁非默认绑定(保留旧键)。dsh plugin --profile web add dsh-hotkeys-platform
# 或本地开发
dsh plugin --profile web add link:<本仓库路径>
重启 dsh web(host 改动需重启;client 改动浏览器强刷)。
Ctrl / ⌘/Win / Alt/⌥ / Shift(多选);Cmd+W、Ctrl+T 录不到但可手工拼)、能精确微调单个修饰键。Esc 取消;15 秒无操作自动取消。/hotkeys 命令/hotkeys。+ 连接,如 Control+Shift+Enter。| 修饰键 | 别名 |
|---|---|
| Ctrl | Ctrl / Control / ⌃ |
| Meta | Meta / Cmd / Command / Win / ⌘ |
| Shift | Shift / ⇧ |
| Alt | Alt / Option / ⌥ |
Space。| 状态 | 含义 |
|---|---|
| 未改过 | 使用动作声明的默认键(defaultKey) |
| 已录制 | 使用你设置的键 |
| 已禁用 | 完全不触发 |
当多个动作绑定了同一个组合键,先注册的动作优先触发;冲突的动作在设置页会红色高亮,请改绑其中一个避免歧义。
pnpm install
pnpm typecheck
pnpm test # vitest 单测(combo / scope / store / dispatcher)
pnpm build # tsc 声明 + tsdown(host ESM + client.js + client-registry.js)
src/
├── index.ts # host half(可选设置命名空间,其余留空)
├── combo.ts # 组合键解析/匹配/描述(纯函数)
├── scope.ts # 内置 scope 判定(纯函数)
├── store.ts # bindings 持久化 + 迁移(纯函数)
├── context-types.ts # HotkeyService 类型 + Context 增补
└── client/
├── index.tsx # apply:ctx.provide + settings.section + /hotkeys 命令
├── service.ts # HotkeyService 实现工厂
├── dispatcher.ts # 全局 keydown 分发(纯决策可测)
├── record.ts # 录制
├── dom-utils.ts # overlay/合成 Enter/toast
└── HotkeysSettingsPanel.tsx # 设置页
MIT
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek、deepseek-harness、deepseek-harness-plugin。