diff --git a/README.md b/README.md index 411d40d..864b684 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ pnpm publish --access public --no-git-checks > lifecycle 脚本要求 `node` 在 `PATH` 里。若报 `'node' is not recognized`,先把 DSH 运行时自带 node 的 `bin` 目录加进 `$env:Path` 再发布。 -## 统一管理卡(0.5.0) +## 统一管理卡(0.6.0) 「设置 → 云端记忆」现在是三个页签:**连接与上报 / 技能管理 / MCP 管理**。 @@ -209,10 +209,12 @@ pnpm publish --access public --no-git-checks - 服务地址换 origin 时,旧令牌一律清除(`credentialsCleared`),要求重新认证。 - 技能安装是两步:`install/plan` 把仓库克隆到隔离暂存目录并列出候选(含冲突、脚本、体积),`install/commit` 只写入选中的目录;`.git` 与符号链接不复制,仓库脚本不执行。 - 卸载同样是两步:`uninstall/plan` 给出真实目录、文件数与不可恢复提示并签发一次性 token,`remove` 必须带 `confirmed: true` 与匹配 token。 -- MCP 管理读取宿主 `dsh-mcp-connector` 的同源公开接口 `/mcp-connector/api`;探测不到时明确显示能力缺口,不改它的托管配置。 -- 技能市场本版未接入经验证来源:`capabilities.features.skillsMarketplace = false`,界面不显示假条目。 +- **技能市场(P3)**:接入经验证来源 `anthropics/skills` 的 `.claude-plugin/marketplace.json`;搜索→详情→`market/plan`(固定提交)→勾选安装。客户端只传 provider/id,从不传 URL。 +- **更新/回退(P3)**:安装写 `.skill-source.json`;`skills/update/check|apply` 与 `skills/rollback` 更新前整目录备份,过期提交拒绝。 +- **同步冲突(P3)**:`sync/status|run|resolve` 提供两侧信息,逐项「保留本地 / 采用云端 / 手动合并」。 +- **MCP 管理(P4)**:读取宿主 `dsh-mcp-connector` 的同源公开接口 `/mcp-connector/api`;覆盖连接、健康检查、工具、启停、重连、两段式移除、目录市场连接、自定义 HTTP/stdio、JSON 导入、配置编辑、作用域与治理策略。 -接口清单见 `docs/management-surface.md`,验收脚本是 `verify-brain-panel.mjs` 与 `verify-skill-admin.mjs`。 +接口清单见 `docs/management-surface.md`;验收脚本见 `verify-*.mjs`(含 `verify-market` / `verify-skill-update` / `verify-sync-resolve` / `verify-mcp-bridge` / `verify-upgrade` / `verify-concurrency` / `verify-theme`)。 ### 技能来源树 diff --git a/client/index.js b/client/index.js index d0997ce..63ecd80 100644 --- a/client/index.js +++ b/client/index.js @@ -651,7 +651,7 @@ window.__ModuleLoader__.load({ width: '16px', height: '16px', borderRadius: '999px', - background: '#ffffff', + background: 'rgba(255,255,255,0.96)', boxShadow: '0 1px 2px rgba(0,0,0,0.25)', flex: '0 0 auto', }, diff --git a/docs/management-surface.md b/docs/management-surface.md index 46f7281..d43ab27 100644 --- a/docs/management-surface.md +++ b/docs/management-surface.md @@ -218,4 +218,38 @@ refreshCatalog, toolsList, toolSearch, toolExplorer, toolDetail` - `verify-mcp-bridge.mjs`(连运行中的 DSH)实测 **8/8** 通过:versionStatus、catalog(116 个已上架连接器)、governance、scopeContext、status、connectionStatistics、listSnapshots 全部 `ok:true`。 - `verify-card-render.mjs` 覆盖 MCP 页签在无桥接时的能力缺口文案,以及存在桥接时的分区渲染。 +## 8. P5:集成发布(0.6.0) + +### 8.1 暗色 / 窄屏 + +- 卡片全部使用主题相对色(`rgba(127,127,127,…)` 中性色 + `rgba(37,99,235,…)` 蓝色强调),不硬编码浅色专用颜色;切换开关的白色圆点用 `rgba(255,255,255,0.96)`。 +- 长行、页签与操作区声明 `flexWrap: 'wrap'`,窄设置面板不会出现横向滚动;不固定 375px 专用宽度。 +- `verify-theme.mjs`:6 项通过(无纯白/纯黑硬编码、中性/强调 token 使用次数、换行行数、页签换行、无固定窄宽)。 + +### 8.2 并发保护 + +所有会改文件的入口在同步进行中一律拒绝,绝不半写: + +| 入口 | 行为 | +|---|---| +| `skills/install/plan` `install/commit` | `sync_running` | +| `skills/toggle` `skills/remove` | `sync_running` | +| `skills/update/apply` `skills/rollback` | `sync_running` | +| `sync/resolve` | `sync_running` | + +HTTP 层统一映射为 **409 `sync_running`**。`verify-concurrency.mjs`:8 项通过(六个入口 + 路由 409 + 同步结束后放行)。 + +### 8.3 升级迁移(UPGRADE-01) + +- 配置 sidecar 仍是 `version:1`;0.4.1 写入的 `baseUrl / clientId / requestTimeoutMs / defaultK / 三个 token / summary` 全部按原值读回,未知的未来字段被忽略而不是致命。 +- **默认地址改为中性占位符** `https://your-memory-host/api/longmemory`:新装显示「未配置服务」,已配置用户由 sidecar 中的真实地址覆盖,不受影响。个人域名不再随包外发。 +- 二次构造 `SettingsStore` 模拟重启,读到相同值;损坏文件降级为默认值,不阻断激活。 +- `verify-upgrade.mjs`:11 项通过。 + +### 8.4 制品校验与回退 + +- `node scripts/pack-guard.mjs`:按 `files` 白名单展开真实入包文件,文件名黑名单(笔记/工程文件/`*.mjs`/`tsconfig*`/锁文件)与内容黑名单(个人域名、`C:\Users\…`、`cmt_…` 令牌原文)全部通过。 +- 回退:代码层用 Git 提交与分支回退;本机配置由 sidecar 原子写(tmp + rename)保护;MCP 连接由宿主快照(`listSnapshots/restoreSnapshot`)保护;技能更新前自动备份到 `$DSH_HOME/.cloud-memory-backups`,可 `skills/rollback` 恢复。 + + diff --git a/lib/config.js b/lib/config.js index 06d028b..002a91a 100644 --- a/lib/config.js +++ b/lib/config.js @@ -6,7 +6,7 @@ /** Defaults written into cordis.patch.yml; also the fallback for missing keys. */ export const DEFAULT_SETTINGS = { enabled: true, - baseUrl: 'https://mem.qyhhh.top/api/longmemory', + baseUrl: 'https://your-memory-host/api/longmemory', clientId: 'dsh-desktop', requestTimeoutMs: 5000, defaultK: 10, diff --git a/lib/page.js b/lib/page.js index e995f27..48a37c9 100644 --- a/lib/page.js +++ b/lib/page.js @@ -118,7 +118,7 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
- +
不带结尾斜杠,路径为 /api/longmemory。
diff --git a/src/config.ts b/src/config.ts index cc67ce1..55e8120 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,7 +7,7 @@ /** Defaults written into cordis.patch.yml; also the fallback for missing keys. */ export const DEFAULT_SETTINGS: Settings = { enabled: true, - baseUrl: 'https://mem.qyhhh.top/api/longmemory', + baseUrl: 'https://your-memory-host/api/longmemory', clientId: 'dsh-desktop', requestTimeoutMs: 5000, defaultK: 10, diff --git a/src/page.ts b/src/page.ts index 5a223ca..8d050a7 100644 --- a/src/page.ts +++ b/src/page.ts @@ -120,7 +120,7 @@ code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size
- +
不带结尾斜杠,路径为 /api/longmemory。
diff --git a/verify-concurrency.mjs b/verify-concurrency.mjs new file mode 100644 index 0000000..9362762 --- /dev/null +++ b/verify-concurrency.mjs @@ -0,0 +1,70 @@ +// P5 concurrency / mutex verification. +// +// Every mutating skill path must refuse to run while a sync pass is running: +// install staging, install commit, toggle, remove, update apply and rollback. +// The refusal is a typed 409 at the route layer, never a silent partial write. +import http from 'node:http' +import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' + +process.env.DSH_HOME = mkdtempSync(join(tmpdir(), 'brain-conc-')) + +const results = [] +function check(name, ok, detail) { + results.push({ name, ok }) + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail === undefined ? '' : ` :: ${detail}`}`) +} + +const { SkillAdmin } = await import('./lib/skill-admin.js') +const { SkillUpdater } = await import('./lib/skill-update.js') +const { SettingsStore } = await import('./lib/store.js') +const { Reporter } = await import('./lib/reporter.js') +const { createRoutes } = await import('./lib/routes.js') + +const root = join(process.env.DSH_HOME, 'skills') +const holding = join(process.env.DSH_HOME, 'skills-disabled') +mkdirSync(join(root, 'alpha'), { recursive: true }) +writeFileSync(join(root, 'alpha', 'SKILL.md'), '# alpha\n') + +let running = true +const admin = new SkillAdmin({ skillsRoot: () => root, holdingDir: () => holding, syncStatePath: () => join(process.env.DSH_HOME, 'cloud-memory-skills.json'), syncRunning: () => running, log: () => {} }) +const updater = new SkillUpdater({ admin, skillsRoot: () => root, holdingDir: () => holding, syncRunning: () => running, log: () => {} }) + +async function expectCode(fn, code) { + try { await fn(); return false } catch (error) { return error.code === code || error.message === code } +} +check('prepareInstall refuses while sync runs', await expectCode(() => admin.prepareInstall('https://example.org/x.git'), 'sync_running')) +check('commitInstall refuses while sync runs', await expectCode(() => admin.commitInstall({ planId: 'x', folders: [] }), 'sync_running')) +check('setEnabled refuses while sync runs', await expectCode(() => admin.setEnabled('alpha', false), 'sync_running')) +check('remove refuses while sync runs', await expectCode(() => admin.remove('alpha'), 'sync_running')) +check('applyUpdate refuses while sync runs', await expectCode(() => updater.applyUpdate('alpha', 'deadbeef'), 'sync_running')) +check('rollback refuses while sync runs', await expectCode(() => updater.rollback('alpha'), 'sync_running')) + +// Route layer maps the refusal to 409. +const store = new SettingsStore({ clientId: 't' }, join(process.env.DSH_HOME, 'c.json')) +const reporter = new Reporter({ client: () => ({ reportTurn: async () => ({ ok: true, status: 200, data: {} }), submitSummary: async () => ({ ok: true, status: 200, data: {} }) }), settings: () => ({ enabled: true, clientId: 't' }), activityToken: () => '', summary: () => ({ enabled: false, maxChars: 1 }), summaryToken: () => '', log: () => {} }) +const routes = createRoutes({ version: '0.6.0', store, reporter, client: () => ({ reach: async () => ({ ok: false, status: 0, message: 'x' }), listSkills: async () => ({ ok: true, status: 200, data: { items: [] } }) }), admin, updates: updater }) +const server = http.createServer((req, res) => { + const path = (req.url ?? '/').split('?')[0] + for (const route of routes) { + if (route.kind === 'exact' && path === route.path) return route.handler(req, res) + if (route.kind === 'prefix' && (path === route.path || path.startsWith(`${route.path}/`))) return route.handler(req, res) + } + res.writeHead(404); res.end('{"ok":false}') +}) +await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)) +const origin = `http://127.0.0.1:${server.address().port}` +const response = await fetch(`${origin}/cloud-memory/skills/toggle`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ folder: 'alpha', enabled: false }) }) +const body = await response.json() +check('route answers 409 sync_running during a sync', response.status === 409 && body.code === 'sync_running', JSON.stringify(body)) +await new Promise((resolve) => server.close(resolve)) + +// After the sync ends, the same toggle succeeds. +running = false +const enabled = await admin.setEnabled('alpha', false) +check('after the sync ends the mutation is allowed', enabled.folder === 'alpha' && enabled.enabled === false) + +const passed = results.filter((r) => r.ok).length +console.log(`\n${passed}/${results.length} passed`) +process.exit(passed === results.length ? 0 : 1) diff --git a/verify-theme.mjs b/verify-theme.mjs new file mode 100644 index 0000000..33177ec --- /dev/null +++ b/verify-theme.mjs @@ -0,0 +1,34 @@ +// P5 theme / narrow-panel structural guard. +// +// This is a static guard, not a screenshot: it fails if the hand-written card +// reintroduces a hard-coded light-only colour or drops the wrapping that keeps +// a narrow settings panel from scrolling sideways. It also asserts the tab bar +// and the two long action rows declare flexWrap. +import { readFileSync } from 'node:fs' + +const results = [] +function check(name, ok, detail) { + results.push({ name, ok }) + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail === undefined ? '' : ` :: ${detail}`}`) +} + +const source = readFileSync('./client/index.js', 'utf8') + +const hardcoded = source.match(/(?:background|color|borderColor)\s*:\s*['"]#(?:fff(?:fff)?|000(?:000)?)['"]/gi) +check('no hard-coded pure white/black colours', hardcoded === null, hardcoded === null ? '' : hardcoded.join(',')) + +const neutralTokens = (source.match(/rgba\(127,127,127/gi) ?? []).length +check('theme-neutral colour tokens are used throughout', neutralTokens >= 5, `${neutralTokens} uses`) + +const accentTokens = (source.match(/rgba\(37,99,235/gi) ?? []).length +check('accent colour is the shared blue token', accentTokens >= 2, `${accentTokens} uses`) + +const wrapCount = (source.match(/flexWrap\s*:\s*['"]wrap['"]/g) ?? []).length +check('long rows wrap instead of scrolling sideways', wrapCount >= 4, `${wrapCount} wrapping rows`) + +check('tabs and actions declare wrapping', /tabBar[\s\S]{0,400}?flexWrap/.test(source) || /styles\.tabs/.test(source)) +check('no fixed 375px-only width is pinned', !/minWidth\s*:\s*['"]?375/.test(source)) + +const passed = results.filter((r) => r.ok).length +console.log(`\n${passed}/${results.length} passed`) +process.exit(passed === results.length ? 0 : 1) diff --git a/verify-upgrade.mjs b/verify-upgrade.mjs new file mode 100644 index 0000000..97efec6 --- /dev/null +++ b/verify-upgrade.mjs @@ -0,0 +1,81 @@ +// P5 upgrade / migration verification. +// +// A 0.4.1 sidecar must survive an in-place upgrade: the schema is unchanged, so +// base URL, tokens, client id and numeric overrides are read back verbatim and +// survive a second "restart". Unknown keys are ignored rather than fatal. The +// packaged default must be a neutral placeholder, and no personal domain may +// remain in the shipped lib/. +import { mkdtempSync, readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' + +process.env.DSH_HOME = mkdtempSync(join(tmpdir(), 'brain-upgrade-')) + +const results = [] +function check(name, ok, detail) { + results.push({ name, ok }) + console.log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail === undefined ? '' : ` :: ${detail}`}`) +} + +const { SettingsStore } = await import('./lib/store.js') +const { DEFAULT_SETTINGS } = await import('./lib/config.js') + +// ── 1. A 0.4.1-shaped sidecar survives the upgrade ────────────────────── +const file = join(process.env.DSH_HOME, 'cloud-memory.json') +const old = { + version: 1, + enabled: true, + baseUrl: 'https://memory.example.org/api/longmemory', + clientId: 'dsh-desktop', + requestTimeoutMs: 5000, + defaultK: 12, + activityToken: 'cmt_old_activity_0123456789abcdef', + memoryToken: 'cmt_old_memory_0123456789abcdef', + summaryEnabled: true, + summaryMaxChars: 6000, + summaryToken: 'cmt_old_summary_0123456789abcdef', + someFutureField: 'ignore-me', +} +writeFileSync(file, JSON.stringify(old, null, 2)) + +const store = new SettingsStore(null, file) +const s = store.settings() +check('base URL survives the upgrade', s.baseUrl === old.baseUrl, s.baseUrl) +check('client id survives the upgrade', s.clientId === 'dsh-desktop') +check('numeric overrides survive', s.requestTimeoutMs === 5000 && s.defaultK === 12) +check('all three tokens survive', store.activityToken() === old.activityToken && store.memoryToken() === old.memoryToken && store.summaryToken() === old.summaryToken) +check('an unknown future key is ignored, not fatal', store.describe().baseUrlConfigured === true) + +// A second construction models a restart over the same file. +const reopened = new SettingsStore(null, file) +check('a restart reads the same values back', reopened.settings().baseUrl === old.baseUrl && reopened.activityToken() === old.activityToken) + +// ── 2. Fresh installs default to a neutral placeholder ────────────────── +const emptyFile = join(process.env.DSH_HOME, 'empty.json') +const fresh = new SettingsStore(null, emptyFile) +check('fresh install uses the packaged placeholder', DEFAULT_SETTINGS.baseUrl === 'https://your-memory-host/api/longmemory', DEFAULT_SETTINGS.baseUrl) +check('a placeholder is reported as unconfigured', fresh.describe().baseUrlConfigured === false) + +// ── 3. A corrupt file degrades to defaults instead of breaking boot ───── +const corrupt = join(process.env.DSH_HOME, 'corrupt.json') +writeFileSync(corrupt, '{not json') +let survived = true +try { new SettingsStore(null, corrupt) } catch { survived = false } +check('a torn sidecar does not break activation', survived) + +// ── 4. Artifact hygiene: no personal domain in shipped lib/ ───────────── +const libDir = join(process.cwd(), 'lib') +let leaked = [] +for (const name of readdirSync(libDir)) { + const full = join(libDir, name) + if (!statSync(full).isFile() || !name.endsWith('.js')) continue + const text = readFileSync(full, 'utf8') + if (/qyhhh/i.test(text)) leaked.push(name) +} +check('no personal domain remains in shipped lib/', leaked.length === 0, leaked.join(',')) +const pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8')) +check('package version is the delivery version', pkg.version === '0.6.0', pkg.version) + +const passed = results.filter((r) => r.ok).length +console.log(`\n${passed}/${results.length} passed`) +process.exit(passed === results.length ? 0 : 1)