Recover the WorkBuddy 5.8.3 快捷键 page from REA evidence (keyboard-shortcuts-DOrivHwf.css + tokens): 49 recovered module rules, scoped light/dark tokens, the 24-row 命令/按键绑定/操作 sheet (panel 638x620, header 39, scroll 638x533, rows 41/45/44, keycaps 22) and the recording/ESC-cancel interaction. Wire the panel into SettingsDialog and keep only real bindings honest: 14 of 24 rows are marked supported, the remaining rows stay visually 1:1 but are labelled 尚未接入 and cannot pretend to save custom keys. Add Ctrl+K search focus, Ctrl+B / Ctrl+Shift+B left/right sidebar toggles, Ctrl+N new conversation (App -> Sidebar path) and Esc-to-stop while generating; fix the sidebar search focus race introduced by conditional mounting. Verify with scripts/verify-shortcuts-settings.cjs: 32 assertions covering geometry, row/key order, search filtering, recording/cancel, supported ids, dark theme surfaces and the four new global shortcuts in a real main window. All existing regressions stay green.
87 lines
4.5 KiB
JavaScript
87 lines
4.5 KiB
JavaScript
// Recover only already-retained REA CSS; never access the installed application here.
|
|
// Source: REA evidence ev_5f3148eb51ea4a6e5b6f2ffea5f6e3dfb94e4009ecf2d16173fa676ce7c51b4b
|
|
// (WorkBuddy 5.8.3 设置 → 快捷键), keyboard-shortcuts-DOrivHwf.css.
|
|
import fs from 'node:fs/promises'
|
|
import { createHash } from 'node:crypto'
|
|
import postcss from 'postcss'
|
|
|
|
const sha = value => createHash('sha256').update(value).digest('hex')
|
|
const evidenceId = 'ev_5f3148eb51ea4a6e5b6f2ffea5f6e3dfb94e4009ecf2d16173fa676ce7c51b4b'
|
|
const evidence = JSON.parse(await fs.readFile(`.tmp/rea-css-evidence/${evidenceId}.json`, 'utf8'))
|
|
if (evidence.evidence_id !== evidenceId) throw new Error('REA identity mismatch')
|
|
|
|
const module = evidence.normalized_result.styles.items.find(item => /keyboard-shortcuts-DOrivHwf\.css$/.test(item.file_path))
|
|
if (!module) throw new Error('Keyboard shortcuts module CSS is absent from the evidence')
|
|
const moduleCss = module.source.artifact.text
|
|
const moduleSha = sha(moduleCss)
|
|
if (moduleSha !== 'd2c570c8d65db87c1cb9df06b59e6aa191b772330857376b85fd923aed580ae8') throw new Error('Keyboard shortcuts module CSS changed')
|
|
|
|
const tokens = await fs.readFile('.tmp/rea-css-recovered/tokens-Df-i-zsO.css', 'utf8')
|
|
const tokensSha = sha(tokens)
|
|
if (tokensSha !== '13f2bf82c96e5167a7d7098e36950c6c22c475b3337dbb8bb29ad2fe79cde696') throw new Error('Tokens CSS changed')
|
|
|
|
const lightTokens = new Map()
|
|
const darkTokens = new Map()
|
|
for (const rule of postcss.parse(tokens).nodes) {
|
|
if (rule.type !== 'rule') continue
|
|
const selectors = rule.selectors ?? []
|
|
const dark = selectors.some(selector => selector.includes('[data-theme=dark]'))
|
|
const light = selectors.some(selector => selector.trim() === ':root')
|
|
if (!dark && !light) continue
|
|
for (const node of rule.nodes ?? []) {
|
|
if (node.type !== 'decl' || !node.prop.startsWith('--')) continue
|
|
if (dark) darkTokens.set(node.prop, node.value)
|
|
if (light) lightTokens.set(node.prop, node.value)
|
|
}
|
|
}
|
|
|
|
const relatedSelector = /\.(?:keyboard-shortcuts-panel|shortcut-item)(?:[\w-]*)?(?![\w-])/i
|
|
const darkScope = /^\s*(?:\[data-theme=["']?dark["']?\]|body\[data-vscode-theme-name=["']IDE Night["']\]|body\.vscode-dark|\.vscode-dark|body\.dark|\.dark)(?=\s|$)/i
|
|
function project(node) {
|
|
if (node.type === 'rule') {
|
|
const selectors = []
|
|
for (const selector of node.selectors) {
|
|
if (!relatedSelector.test(selector)) continue
|
|
const mapped = selector.replace(darkScope, '[data-theme=dark]')
|
|
if (!selectors.includes(mapped)) selectors.push(mapped)
|
|
}
|
|
return selectors.length ? node.clone({ selector: selectors.join(',') }) : null
|
|
}
|
|
if (node.type === 'atrule' && node.nodes) {
|
|
if (node.name === 'keyframes' && /recording-cursor-blink/.test(node.params)) return node.clone()
|
|
const nodes = node.nodes.map(project).filter(Boolean)
|
|
return nodes.length ? node.clone({ nodes }) : null
|
|
}
|
|
return null
|
|
}
|
|
|
|
const root = postcss.root({ nodes: postcss.parse(moduleCss).nodes.map(project).filter(Boolean) })
|
|
const referenced = new Set()
|
|
const collect = text => {
|
|
for (const match of text.matchAll(/var\(\s*(--[\w-]+)/g)) referenced.add(match[1])
|
|
}
|
|
collect(root.toString())
|
|
for (let depth = 0; depth < 8; depth++) {
|
|
const before = referenced.size
|
|
for (const name of [...referenced]) {
|
|
for (const value of [lightTokens.get(name), darkTokens.get(name)]) {
|
|
if (typeof value === 'string') collect(value)
|
|
}
|
|
}
|
|
if (referenced.size === before) break
|
|
}
|
|
|
|
const missingLight = [...referenced].filter(name => !lightTokens.has(name))
|
|
if (missingLight.length) throw new Error(`Tokens missing from light root scope: ${missingLight.join(', ')}`)
|
|
const pick = map => new Map([...referenced].map(name => [name, map.get(name) ?? lightTokens.get(name)]))
|
|
const scope = (selector, map) => `${selector}{${[...map].map(([property, value]) => `${property}:${value}`).join(';')}}`
|
|
const scopedTokens = `${scope('.keyboard-shortcuts-panel', pick(lightTokens))}\n${scope(':root[data-theme=dark] .keyboard-shortcuts-panel', pick(darkTokens))}\n`
|
|
const css = `/* REA ${evidenceId}; keyboard-shortcuts-DOrivHwf.css sha256=${moduleSha}; tokens sha256=${tokensSha}. */\n${root.toString()}\n${scopedTokens}`
|
|
await fs.writeFile('src/renderer/src/components/source-shortcuts-panel-recovered.css', css)
|
|
|
|
const rules = []
|
|
root.walkRules(rule => rules.push(rule.selector))
|
|
console.log(`Recovered ${rules.length} shortcuts rules (${Buffer.byteLength(css)} bytes); scoped ${pick(lightTokens).size} light / ${pick(darkTokens).size} dark tokens`)
|
|
console.log(rules.slice(0, 12).join('\n'))
|
|
if (rules.length < 20) throw new Error('Unexpectedly few shortcuts rules')
|