From d68840202ed73fd6a7a0245f6e1b445976ca2069 Mon Sep 17 00:00:00 2001 From: newbie Date: Wed, 25 Nov 2026 12:37:37 +0800 Subject: [PATCH] refactor(ui)!: rename settings-ui bundle to dsh-brain-ui with export alias --- README.md | 3 +- cordis.patch.yml | 4 +-- lib/entries/settings-ui.js | 34 +++++----------------- lib/entries/ui.js | 43 +++++++++++++++++++++++++++ lib/index.js | 4 +-- lib/kernel.js | 4 +-- package.json | 3 +- src/entries/settings-ui.ts | 43 ++++----------------------- src/entries/ui.ts | 59 ++++++++++++++++++++++++++++++++++++++ src/index.ts | 6 ++-- src/kernel.ts | 6 ++-- verify-plugin-entry.mjs | 10 ++++--- 12 files changed, 136 insertions(+), 83 deletions(-) create mode 100644 lib/entries/ui.js create mode 100644 src/entries/ui.ts diff --git a/README.md b/README.md index 85455e0..afc33b2 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ | `dsh-brain-memory` | 五个 `memory_*` 工具注册。 | | `dsh-brain-skills` | 技能管理页、`skill_list` 工具、技能市场、来源树。 | | `dsh-brain-mcp` | MCP 管理页开关(页签与宿主桥接能力声明;MCP 连接本身由宿主 `dsh-mcp-connector` 管理,本插件不做 MCP 云同步)。 | -| `dsh-brain-settings-ui` | 配置页与状态/能力/配置路由。 | +| `dsh-brain-ui` | 左侧栏 Brain 总面板与 better-sidebar 项目记忆页签;配置页与状态/能力/配置路由。 | - 停掉 `dsh-brain-cloudsync` 后活动上报与技能同步停止,但记忆读写工具 仍可用(它们实时访问云端)。停掉 `dsh-brain-memory` 才会移除记忆工具。 @@ -47,6 +47,7 @@ 重复实例;设置持久化在 `$DSH_HOME/dsh-brain.json`(侧车文件为权威, 插件行的 config 只作首次种子)。 - 根导出 `.` 仍是兼容组合器:老的单行 profile 升级后行为不变。 +- 0.11.0 起第五个子插件行 id 从 `dsh-brain-settings-ui` 改为 `dsh-brain-ui`(package exports 保留 `./settings-ui` 别名指向同一入口)。若 profile 里还留有旧 id 的禁用/配置行,请到「设置 → 插件」对 `dsh-brain-ui` 重新设置;插件不会自动改写宿主配置文件。 ## 安装 diff --git a/cordis.patch.yml b/cordis.patch.yml index d15222c..b44667e 100644 --- a/cordis.patch.yml +++ b/cordis.patch.yml @@ -32,5 +32,5 @@ name: dsh-brain/skills - id: dsh-brain-mcp name: dsh-brain/mcp - - id: dsh-brain-settings-ui - name: dsh-brain/settings-ui + - id: dsh-brain-ui + name: dsh-brain/ui diff --git a/lib/entries/settings-ui.js b/lib/entries/settings-ui.js index 4c6d156..528138d 100644 --- a/lib/entries/settings-ui.js +++ b/lib/entries/settings-ui.js @@ -1,27 +1,7 @@ -import { brainKernel, VERSION } from "../kernel.js"; -import { createCoreRoutes, legacyAliases } from "../routes.js"; -import { createSettingsUiRoutes } from "../settings-ui/routes.js"; -export const name = 'dsh-brain-settings-ui'; -/** Services required before `apply` runs. */ -export const inject = ['webServer']; -/** Register the sub-plugin with the host. */ -export function apply(ctx, config) { - const logger = ctx.logger('dsh-brain'); - const kernel = brainKernel(config, logger); - kernel.activate('settings-ui'); - kernel.logEvent('boot.entry', { bundle: 'settings-ui' }); - ctx.effect(() => () => kernel.deactivate('settings-ui'), 'dsh-brain-settings-ui: activation'); - const webServer = ctx.webServer; - if (webServer === undefined) { - logger.warn('webServer service unavailable; the configuration page stays disabled'); - return; - } - const routes = [ - ...createSettingsUiRoutes({ version: VERSION, store: kernel.store }), - ...createCoreRoutes(kernel.routeDeps()), - ]; - routes.push(...legacyAliases(routes)); - for (const route of routes) { - ctx.effect(() => webServer.register(route), `dsh-brain-settings-ui: route ${route.path}`); - } -} +/** + * Backward-compatible entry alias: the bundle was renamed from + * dsh-brain-settings-ui to dsh-brain-ui. The package exports map points the + * old './settings-ui' subpath at lib/entries/ui.js; this physical module is a + * second safety net for profiles that resolve the old file path directly. + */ +export * from "./ui.js"; diff --git a/lib/entries/ui.js b/lib/entries/ui.js new file mode 100644 index 0000000..154efcf --- /dev/null +++ b/lib/entries/ui.js @@ -0,0 +1,43 @@ +import { brainKernel, VERSION } from "../kernel.js"; +import { createCoreRoutes, legacyAliases } from "../routes.js"; +import { createSettingsUiRoutes } from "../settings-ui/routes.js"; +export const name = 'dsh-brain-ui'; +/** Services required before `apply` runs. */ +export const inject = ['webServer']; +/** The pre-rename row id; only used to point a stale profile at the new row. */ +const LEGACY_BUNDLE_ID = 'dsh-brain-settings-ui'; +function profileMentionsLegacyId(ctx) { + try { + const face = ctx; + return [face.config, face.settings].some((value) => value !== undefined && JSON.stringify(value).includes(LEGACY_BUNDLE_ID)); + } + catch { + return false; + } +} +/** Register the sub-plugin with the host. */ +export function apply(ctx, config) { + const logger = ctx.logger('dsh-brain'); + const kernel = brainKernel(config, logger); + kernel.activate('ui'); + kernel.logEvent('boot.entry', { bundle: 'ui' }); + ctx.effect(() => () => kernel.deactivate('ui'), 'dsh-brain-ui: activation'); + // We never rewrite host files: if the old row is visible in the live config + // face, tell the user which row to re-toggle after the rename. + if (profileMentionsLegacyId(ctx)) { + logger.info('detected the old plugin id ' + LEGACY_BUNDLE_ID + '; re-apply the plugin toggle under dsh-brain-ui in Settings → Plugins'); + } + const webServer = ctx.webServer; + if (webServer === undefined) { + logger.warn('webServer service unavailable; the configuration page stays disabled'); + return; + } + const routes = [ + ...createSettingsUiRoutes({ version: VERSION, store: kernel.store }), + ...createCoreRoutes(kernel.routeDeps()), + ]; + routes.push(...legacyAliases(routes)); + for (const route of routes) { + ctx.effect(() => webServer.register(route), `dsh-brain-ui: route ${route.path}`); + } +} diff --git a/lib/index.js b/lib/index.js index ac713fa..59456fe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,7 +2,7 @@ import * as cloudsync from "./entries/cloudsync.js"; import * as memory from "./entries/memory.js"; import * as skills from "./entries/skills.js"; import * as mcp from "./entries/mcp.js"; -import * as settingsUi from "./entries/settings-ui.js"; +import * as ui from "./entries/ui.js"; /** Package name; also the client bundle id. */ export const name = 'dsh-brain'; /** Services required before `apply` runs. */ @@ -13,5 +13,5 @@ export function apply(ctx, config) { memory.apply(ctx, config); skills.apply(ctx, config); mcp.apply(ctx, config); - settingsUi.apply(ctx, config); + ui.apply(ctx, config); } diff --git a/lib/kernel.js b/lib/kernel.js index 294c4ae..832ac03 100644 --- a/lib/kernel.js +++ b/lib/kernel.js @@ -2,7 +2,7 @@ * Shared kernel for the dsh-brain sub-plugins. * * The five bundle entries (dsh-brain/cloudsync, dsh-brain/memory, - * dsh-brain/skills, dsh-brain/mcp, dsh-brain/settings-ui) and the compat + * dsh-brain/skills, dsh-brain/mcp, dsh-brain/ui) and the compat * root entry all load from the same package inside the same host process, * so this module's export resolves to a single instance: whichever entry * applies first builds the services, the rest reuse them. @@ -316,7 +316,7 @@ export class BrainKernel { memory: this.isActive('memory'), skills: this.isActive('skills'), mcp: this.isActive('mcp'), - 'settings-ui': this.isActive('settings-ui'), + ui: this.isActive('ui'), }, }; } diff --git a/package.json b/package.json index a87a2ff..65488be 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "./memory": "./lib/entries/memory.js", "./skills": "./lib/entries/skills.js", "./mcp": "./lib/entries/mcp.js", - "./settings-ui": "./lib/entries/settings-ui.js", + "./ui": "./lib/entries/ui.js", + "./settings-ui": "./lib/entries/ui.js", "./cordis.patch.yml": "./cordis.patch.yml", "./package.json": "./package.json", "./mnemon-provider": "./lib/mnemon/index.js", diff --git a/src/entries/settings-ui.ts b/src/entries/settings-ui.ts index 89d977f..6dd1d00 100644 --- a/src/entries/settings-ui.ts +++ b/src/entries/settings-ui.ts @@ -1,40 +1,7 @@ /** - * Settings-UI sub-plugin entry — the configuration page and core routes. - * - * Owns the standalone HTML page, the status / capabilities / config / - * migrate routes, and their legacy /cloud-memory aliases. The capability - * report is assembled from the kernel's active-bundle view, so the page - * reflects which sibling sub-plugins are currently enabled. + * Backward-compatible entry alias: the bundle was renamed from + * dsh-brain-settings-ui to dsh-brain-ui. The package exports map points the + * old './settings-ui' subpath at lib/entries/ui.js; this physical module is a + * second safety net for profiles that resolve the old file path directly. */ -import type { CloudMemoryContext } from '../context-types.ts' -import { brainKernel, VERSION } from '../kernel.ts' -import { createCoreRoutes, legacyAliases } from '../routes.ts' -import { createSettingsUiRoutes } from '../settings-ui/routes.ts' - -export const name = 'dsh-brain-settings-ui' - -/** Services required before `apply` runs. */ -export const inject = ['webServer'] - -/** Register the sub-plugin with the host. */ -export function apply(ctx: CloudMemoryContext, config: unknown): void { - const logger = ctx.logger('dsh-brain') - const kernel = brainKernel(config, logger) - kernel.activate('settings-ui') - kernel.logEvent('boot.entry', { bundle: 'settings-ui' }) - ctx.effect(() => () => kernel.deactivate('settings-ui'), 'dsh-brain-settings-ui: activation') - - const webServer = ctx.webServer - if (webServer === undefined) { - logger.warn('webServer service unavailable; the configuration page stays disabled') - return - } - const routes = [ - ...createSettingsUiRoutes({ version: VERSION, store: kernel.store }), - ...createCoreRoutes(kernel.routeDeps()), - ] - routes.push(...legacyAliases(routes)) - for (const route of routes) { - ctx.effect(() => webServer.register(route), `dsh-brain-settings-ui: route ${route.path}`) - } -} +export * from './ui.ts' diff --git a/src/entries/ui.ts b/src/entries/ui.ts new file mode 100644 index 0000000..12763b3 --- /dev/null +++ b/src/entries/ui.ts @@ -0,0 +1,59 @@ +/** + * UI sub-plugin entry — the configuration page, core routes and the panel host. + * + * Owns the standalone HTML page, the status / capabilities / config / + * migrate routes, and their legacy /cloud-memory aliases. The capability + * report is assembled from the kernel's active-bundle view, so the page + * reflects which sibling sub-plugins are currently enabled. The client half + * of this bundle adds the left-rail Brain panel and the better-sidebar tab. + */ +import type { CloudMemoryContext } from '../context-types.ts' +import { brainKernel, VERSION } from '../kernel.ts' +import { createCoreRoutes, legacyAliases } from '../routes.ts' +import { createSettingsUiRoutes } from '../settings-ui/routes.ts' + +export const name = 'dsh-brain-ui' + +/** Services required before `apply` runs. */ +export const inject = ['webServer'] + +/** The pre-rename row id; only used to point a stale profile at the new row. */ +const LEGACY_BUNDLE_ID = 'dsh-brain-settings-ui' + +function profileMentionsLegacyId(ctx: CloudMemoryContext): boolean { + try { + const face = (ctx as unknown as { config?: unknown; settings?: unknown }) + return [face.config, face.settings].some((value) => value !== undefined && JSON.stringify(value).includes(LEGACY_BUNDLE_ID)) + } catch { + return false + } +} + +/** Register the sub-plugin with the host. */ +export function apply(ctx: CloudMemoryContext, config: unknown): void { + const logger = ctx.logger('dsh-brain') + const kernel = brainKernel(config, logger) + kernel.activate('ui') + kernel.logEvent('boot.entry', { bundle: 'ui' }) + ctx.effect(() => () => kernel.deactivate('ui'), 'dsh-brain-ui: activation') + + // We never rewrite host files: if the old row is visible in the live config + // face, tell the user which row to re-toggle after the rename. + if (profileMentionsLegacyId(ctx)) { + logger.info('detected the old plugin id ' + LEGACY_BUNDLE_ID + '; re-apply the plugin toggle under dsh-brain-ui in Settings → Plugins') + } + + const webServer = ctx.webServer + if (webServer === undefined) { + logger.warn('webServer service unavailable; the configuration page stays disabled') + return + } + const routes = [ + ...createSettingsUiRoutes({ version: VERSION, store: kernel.store }), + ...createCoreRoutes(kernel.routeDeps()), + ] + routes.push(...legacyAliases(routes)) + for (const route of routes) { + ctx.effect(() => webServer.register(route), `dsh-brain-ui: route ${route.path}`) + } +} diff --git a/src/index.ts b/src/index.ts index 4eb5abe..4a25ca9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ * Plugin entry — compat root. * * The package now ships five toggleable sub-plugin rows (see - * cordis.patch.yml): cloud-sync, memory, skills, mcp, and settings-ui. + * cordis.patch.yml): cloud-sync, memory, skills, mcp, and ui. * This root entry remains for older single-row profiles: it applies all * five entries against the same context, so the route and tool tables it * registers are identical to the pre-split build, including the legacy @@ -16,7 +16,7 @@ import * as cloudsync from './entries/cloudsync.ts' import * as memory from './entries/memory.ts' import * as skills from './entries/skills.ts' import * as mcp from './entries/mcp.ts' -import * as settingsUi from './entries/settings-ui.ts' +import * as ui from './entries/ui.ts' /** Package name; also the client bundle id. */ export const name = 'dsh-brain' @@ -30,5 +30,5 @@ export function apply(ctx: CloudMemoryContext, config: unknown): void { memory.apply(ctx, config) skills.apply(ctx, config) mcp.apply(ctx, config) - settingsUi.apply(ctx, config) + ui.apply(ctx, config) } diff --git a/src/kernel.ts b/src/kernel.ts index 691865a..5cf42cb 100644 --- a/src/kernel.ts +++ b/src/kernel.ts @@ -2,7 +2,7 @@ * Shared kernel for the dsh-brain sub-plugins. * * The five bundle entries (dsh-brain/cloudsync, dsh-brain/memory, - * dsh-brain/skills, dsh-brain/mcp, dsh-brain/settings-ui) and the compat + * dsh-brain/skills, dsh-brain/mcp, dsh-brain/ui) and the compat * root entry all load from the same package inside the same host process, * so this module's export resolves to a single instance: whichever entry * applies first builds the services, the rest reuse them. @@ -47,7 +47,7 @@ export interface KernelLogger { } /** The bundles a sub-plugin entry can activate. */ -export type BrainBundle = 'cloudsync' | 'memory' | 'skills' | 'mcp' | 'settings-ui' +export type BrainBundle = 'cloudsync' | 'memory' | 'skills' | 'mcp' | 'ui' /** The shared service set behind every dsh-brain sub-plugin entry. */ @@ -348,7 +348,7 @@ export class BrainKernel { memory: this.isActive('memory'), skills: this.isActive('skills'), mcp: this.isActive('mcp'), - 'settings-ui': this.isActive('settings-ui'), + ui: this.isActive('ui'), }, } } diff --git a/verify-plugin-entry.mjs b/verify-plugin-entry.mjs index 3872598..8740280 100644 --- a/verify-plugin-entry.mjs +++ b/verify-plugin-entry.mjs @@ -67,7 +67,8 @@ const cloudsyncEntry = await import('./lib/entries/cloudsync.js') const memoryEntry = await import('./lib/entries/memory.js') const skillsEntry = await import('./lib/entries/skills.js') const mcpEntry = await import('./lib/entries/mcp.js') -const settingsUiEntry = await import('./lib/entries/settings-ui.js') +const uiEntry = await import('./lib/entries/ui.js') +const legacySettingsUiEntry = await import('./lib/entries/settings-ui.js') const { buildStatusPayload } = await import('./lib/routes.js') const root = await import('./lib/index.js') @@ -77,9 +78,9 @@ const SEED = { baseUrl: 'https://your-memory-host/api/longmemory', clientId: 'sm resetBrainKernel() let ui = fakeCtx() -settingsUiEntry.apply(ui.ctx, SEED) +uiEntry.apply(ui.ctx, SEED) const uiPaths = ui.routes.map((route) => `${route.kind}:${route.path}`) -check('settings-ui entry applies and registers the page + core routes', [ +check('ui entry applies and registers the page + core routes', [ 'exact:/dsh-brain', 'exact:/dsh-brain/status', 'exact:/dsh-brain/capabilities', @@ -91,7 +92,8 @@ check('settings-ui entry applies and registers the page + core routes', [ 'exact:/cloud-memory/config', 'prefix:/cloud-memory/migrate', ].every((item) => uiPaths.includes(item)), uiPaths.join(' | ')) -check('settings-ui entry registers no tools', ui.tools.length === 0, `${ui.tools.length} tools`) +check('ui entry registers no tools', ui.tools.length === 0, `${ui.tools.length} tools`) +check('legacy ./settings-ui subpath still resolves to the ui entry', typeof legacySettingsUiEntry.apply === 'function' && legacySettingsUiEntry.name === 'dsh-brain-ui', String(legacySettingsUiEntry.name)) const mcpCtx = fakeCtx() mcpEntry.apply(mcpCtx.ctx, SEED)