A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Check that the client takes colors, radii and springs from the shared ones
Fei2411950a6cf3d1d9
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex eb3388e7..c867daa9 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -161,6 +161,7 @@ For a change to the Bot browser, check it in DSH Desktop. On Linux, the scripts- Keep a change to one subject.- Do not edit `client.js` by hand. Change `src/client/`, run `npm run build` and commit both.+- In `src/client/`, take colors from the `--bt-*` variables, corner radii from the steps 4, 6, 8, 10, 12, 16, 18, 20, 22, 999px and 50%, and springs from `motion.js`. A unit test checks this. The places written before the test are listed in `test/style-debt.json`; that list only gets shorter. When you remove one, run `node scripts/style-debt.mjs --write` to update it.- Follow the style of the code around your change. Write a comment only when the reason for the code is not clear from the code itself.- Write commit messages in English. Use a short subject in the imperative mood ("Keep group replies visible") and explain the reason in the body.- The author of a commit is the person who made the change. When an AI tool helped, do not add it as an author or with a `Co-authored-by` line; turn that setting off in the tool.diff --git a/CONTRIBUTING.zh.md b/CONTRIBUTING.zh.mdindex 7cb25169..8f34d0bd 100644--- a/CONTRIBUTING.zh.md+++ b/CONTRIBUTING.zh.md@@ -161,6 +161,7 @@ dev/bench.sh dev 3081 8771 reset # 模拟模型 + DSH Web;数据在 ../.dsh- 一个改动只做一件事。- 不要手改 `client.js`。改 `src/client/`,运行 `npm run build`,两者一起提交。+- 在 `src/client/` 里,颜色用 `--bt-*` 变量,圆角只用 4、6、8、10、12、16、18、20、22、999px 和 50% 这几档,弹簧用 `motion.js` 里的。有单元测试检查这三项。测试之前就写成的地方列在 `test/style-debt.json` 里,这份清单只减不增。改掉一处后,运行 `node scripts/style-debt.mjs --write` 更新清单。- 跟随改动周围代码的风格。只有当代码本身看不出原因时才写注释。- 提交说明用英文。标题简短,用祈使句(如 "Keep group replies visible"),在正文里写原因。- 提交的作者是做出改动的人。用 AI 工具辅助时,不要把它加为作者,也不要加 `Co-authored-by` 行;在工具里关掉这个设置。diff --git a/ds-bot/scripts/style-debt.mjs b/ds-bot/scripts/style-debt.mjsnew file mode 100644index 00000000..57fe27f3--- /dev/null+++ b/ds-bot/scripts/style-debt.mjs@@ -0,0 +1,102 @@+// Finds the colors, corner radii and springs in src/client that skip the shared ones.+// test/style-debt.json lists the ones written before the check; the test fails when a+// file gets one more, and when one is gone but still listed.+//+// node scripts/style-debt.mjs prints what it finds now+// node scripts/style-debt.mjs --write lowers test/style-debt.json to what is left+//+// --write only lowers counts. A new entry is added by hand, so it shows in review.+import { readdirSync, readFileSync, writeFileSync } from 'node:fs'+import { join, resolve } from 'node:path'+import { fileURLToPath } from 'node:url'++const PLUGIN = resolve(import.meta.dirname, '..')+const CLIENT = join(PLUGIN, 'src', 'client')+export const DEBT = join(PLUGIN, 'test', 'style-debt.json')++// The theme colors, the Bot colors and the generated characters.+const PALETTES = new Set(['themes.js', 'inks.js', 'characters.js'])+export const RADII = ['0', '4px', '6px', '8px', '10px', '12px', '16px', '18px', '20px', '22px', '999px', '50%', 'inherit']++const COLOR = /#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})\b|\b(?:rgba?|hsla?)\([^)]*\)/gi+const RADIUS = /border(?:-[a-z]+)*-radius\s*:\s*((?:\$\{[^}]*\}|[^;{}`'"])+)|border\w*Radius\s*:\s*['"]?((?:\$\{[^}]*\}|[^,}'"])+)/g+const SPRING = /\bspringEasing\([^)]*\)|\blinear\([^)]*\)/g++// The gradient(…) that holds `index`, or ''.+function gradientAround(line, index) {+ const start = line.lastIndexOf('gradient(', index)+ if (start < 0) return ''+ let depth = 0+ for (let at = start; at < line.length; at += 1) {+ if (line[at] === '(') depth += 1+ else if (line[at] === ')' && --depth === 0) return at > index ? line.slice(start, at + 1) : ''+ }+ return ''+}++// A literal color that is not a hard-coded one: the value of a variable, or black used+// for its alpha (shadows, scrims, and masks, whose ramps run to transparent).+function exempt(value, line, index) {+ const before = line.slice(0, index)+ if (/--[\w-]+['"]?\s*:[^;{}]*$/.test(before) || value.startsWith('rgba(0,0,0,')) return true+ if (!/^#000(?:000)?$/.test(value)) return false+ return /<mask\b(?!.*<\/mask>)/.test(before) || gradientAround(line, index).includes('transparent')+}++const plain = value => value.toLowerCase().replace(/\s+/g, '')++// A step is one corner of a border-radius value; a bare number in a React style is px.+const steps = value => value.replace(/!important/g, '').replace(/\([^)]*\)/g, group => group.replace(/\s+/g, '')).trim().split(/\s*\/\s*|\s+/)+ .map(step => (/^\d*\.?\d+$/.test(step) && step !== '0' ? `${step}px` : step))++export const checks = {+ colors: (file, line) => (PALETTES.has(file) ? [] : [...line.matchAll(COLOR)]+ .map(({ 0: value, index }) => ({ value: plain(value), index }))+ .filter(({ value, index }) => !exempt(value, line, index))+ .map(({ value }) => value)),+ radii: (file, line) => [...line.matchAll(RADIUS)]+ .flatMap(match => steps(match[1] ?? match[2]))+ .filter(step => !RADII.includes(step) && !step.startsWith('var(')),+ springs: (file, line) => (file === 'motion.js' ? [] : [...line.matchAll(SPRING)].map(({ 0: call }) => call.replace(/\s+/g, ''))),+}++// Comments are not styles. A trailing comment follows a space, which a URL's `://` lacks.+const code = text => text.split(/\r?\n/)+ .map(line => (/^\s*(\/\/|\/\*|\*\/|\*\s|\*$)/.test(line) ? '' : line.replace(/\s\/\/\s.*$/, '')))++export function findStyles(dir = CLIENT) {+ const found = Object.fromEntries(Object.keys(checks).map(kind => [kind, {}]))+ for (const file of readdirSync(dir, { recursive: true }).filter(name => name.endsWith('.js')).map(name => name.replaceAll('\\', '/'))) {+ for (const line of code(readFileSync(join(dir, file), 'utf8'))) {+ for (const [kind, check] of Object.entries(checks)) {+ for (const value of check(file, line)) {+ const counts = (found[kind][file] ??= {})+ counts[value] = (counts[value] ?? 0) + 1+ }+ }+ }+ }+ return found+}++export const readDebt = () => JSON.parse(readFileSync(DEBT, 'utf8'))++// Each listed entry keeps the smaller of its listed and its found count.+export function lowered(debt, found) {+ return Object.fromEntries(Object.entries(debt).map(([kind, files]) => [kind, Object.fromEntries(Object.entries(files)+ .map(([file, values]) => [file, Object.fromEntries(Object.entries(values)+ .map(([value, count]) => [value, Math.min(count, found[kind]?.[file]?.[value] ?? 0)])+ .filter(([, count]) => count > 0))])+ .filter(([, values]) => Object.keys(values).length > 0))]))+}++const sorted = item => (typeof item === 'object'+ ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([key, value]) => [key, sorted(value)]))+ : item)+const format = debt => `${JSON.stringify(sorted(debt), null, 2)}\n`++if (process.argv[1] === fileURLToPath(import.meta.url)) {+ const found = findStyles()+ if (process.argv.includes('--write')) writeFileSync(DEBT, format(lowered(readDebt(), found)))+ else process.stdout.write(format(found))+}diff --git a/ds-bot/test/style-debt.json b/ds-bot/test/style-debt.jsonnew file mode 100644index 00000000..97a04ef7--- /dev/null+++ b/ds-bot/test/style-debt.json@@ -0,0 +1,108 @@+{+ "colors": {+ "about.js": {+ "#e3a008": 2+ },+ "bot-browsers.js": {+ "#fff": 1+ },+ "bot-settings.js": {+ "#fff": 1+ },+ "browser-pane.js": {+ "#4d6bfe": 3,+ "#fff": 1+ },+ "feedback.js": {+ "#141414": 1,+ "#e02135": 3,+ "#e3a008": 1,+ "#fff": 2+ },+ "mark.js": {+ "#fff": 1+ },+ "member-status.js": {+ "#b7791f": 2,+ "#e3a008": 1,+ "#f0b84a": 2+ },+ "secret-card.js": {+ "#16a34a": 1,+ "#22a06b": 1,+ "#b25e09": 1,+ "#f59e0b": 1,+ "rgba(20,20,20,.08)": 1+ },+ "settings.js": {+ "#4d6bfe": 1+ },+ "sidebar.js": {+ "#4d6bfe": 2,+ "#e5484d": 1,+ "#fff": 1,+ "rgba(127,127,127,.14)": 1+ },+ "styles.js": {+ "#00c972": 1,+ "#1cc3b0": 1,+ "#2a92fe": 1,+ "#777": 2,+ "#a97efe": 1,+ "#e02135": 1,+ "#e5484d": 1,+ "#ff3e51": 4,+ "#ff5eb1": 1,+ "#ffaf38": 1,+ "#fff": 10,+ "rgba(20,20,20,.035)": 1,+ "rgba(20,20,20,.04)": 1,+ "rgba(20,20,20,.05)": 1,+ "rgba(20,20,20,.5)": 1,+ "rgba(228,228,228,.04)": 2,+ "rgba(255,62,81,.35)": 1,+ "rgba(255,62,81,0)": 1+ },+ "usage-page.js": {+ "#fff": 2+ }+ },+ "radii": {+ "browser-pane.js": {+ "2px": 1,+ "3px": 2,+ "5px": 1,+ "7px": 1,+ "9px": 3+ },+ "member-status.js": {+ "13px": 1+ },+ "secret-card.js": {+ "5px": 1+ },+ "sidebar.js": {+ "14px": 1+ },+ "styles.js": {+ "1px": 1,+ "9999px": 2+ },+ "usage-page.js": {+ "14px": 5,+ "30%": 1,+ "3px": 1,+ "5px": 1,+ "9px": 1+ }+ },+ "springs": {+ "browser-pane.js": {+ "springEasing(144,19.7)": 1,+ "springEasing(576,39.4)": 1+ },+ "sidebar.js": {+ "springEasing(1000,63)": 1+ }+ }+}diff --git a/ds-bot/test/style-debt.test.js b/ds-bot/test/style-debt.test.jsnew file mode 100644index 00000000..e0f49e62--- /dev/null+++ b/ds-bot/test/style-debt.test.js@@ -0,0 +1,57 @@+import assert from 'node:assert/strict'+import { test } from 'node:test'+import { RADII, checks, findStyles, lowered, readDebt } from '../scripts/style-debt.mjs'++const found = findStyles()+const debt = readDebt()++// One line per file and value whose count differs from test/style-debt.json.+function drift(kind) {+ const lines = []+ for (const file of new Set([...Object.keys(found[kind]), ...Object.keys(debt[kind] ?? {})])) {+ const now = found[kind][file] ?? {}+ const was = debt[kind]?.[file] ?? {}+ for (const value of new Set([...Object.keys(now), ...Object.keys(was)])) {+ const more = (now[value] ?? 0) - (was[value] ?? 0)+ if (more > 0) lines.push(`src/client/${file}: ${value}, ${more} new`)+ if (more < 0) lines.push(`src/client/${file}: ${value}, ${-more} gone; run node scripts/style-debt.mjs --write`)+ }+ }+ return lines+}++function check(kind, advice) {+ const lines = drift(kind)+ assert.equal(lines.length, 0, `${lines.join('\n')}\n${advice}`)+}++test('colors come from the --bt-* variables', () => {+ check('colors', 'Use a --bt-* variable. A new color becomes a variable first, in themes.js or in the base sheet of styles.js.')+})++test('corner radii stay on the steps', () => {+ check('radii', `Round corners with one of ${RADII.join(' ')}, or with a variable.`)+})++test('springs come from motion.js', () => {+ check('springs', 'Use a spring that motion.js exports, or add the new one there.')+})++test('the checks catch what they look for and pass what they allow', () => {+ assert.deepEqual(checks.colors('x.js', '.a{color:#12AB56;background:rgba(1, 2, 3, .5);box-shadow:0 1px 2px rgba(0,0,0,.1)}'), ['#12ab56', 'rgba(1,2,3,.5)'])+ assert.deepEqual(checks.colors('x.js', 'body{--bt-x:#fff}.m{mask-image:linear-gradient(to top,transparent,#000 calc(100% - 8px))}'), [])+ assert.deepEqual(checks.colors('x.js', '<mask id="m"><g stroke="#000"/></mask><g fill="#000"/>'), ['#000'])+ assert.deepEqual(checks.colors('x.js', '.a{background:linear-gradient(#000,#fff)}'), ['#000', '#fff'])+ assert.deepEqual(checks.colors('themes.js', "const ink = '#123456'"), [])+ assert.deepEqual(checks.radii('x.js', '.a{border-radius:12px 9px;border-top-left-radius:5px!important}'), ['9px', '5px'])+ assert.deepEqual(checks.radii('x.js', "h('i', { style: { borderRadius: 999 } }), h('b', { style: { borderRadius: 7 } })"), ['7px'])+ assert.deepEqual(checks.radii('x.js', '.a{border-radius:var(--r, 3px) 50%}'), [])+ assert.deepEqual(checks.springs('x.js', 'const GLIDE = springEasing(1000, 63)'), ['springEasing(1000,63)'])+ assert.deepEqual(checks.springs('motion.js', 'export const SPRING = springEasing(400, 31.2)'), [])+})++test('--write only lowers the list', () => {+ const listed = { colors: { 'a.js': { '#111': 2, '#222': 1 }, 'b.js': { '#333': 1 } }, radii: {}, springs: {} }+ const now = { colors: { 'a.js': { '#111': 1, '#444': 3 }, 'c.js': { '#555': 1 } }, radii: { 'a.js': { '9px': 1 } }, springs: {} }+ assert.deepEqual(lowered(listed, now), { colors: { 'a.js': { '#111': 1 } }, radii: {}, springs: {} })+})