@jiyr0119/dsh-service-console 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/README.zh.md +6 -4
- package/docs/local-debugging.md +1 -1
- package/docs/rc5-upgrade-review.zh.md +182 -0
- package/docs/release-checklist.md +15 -12
- package/icon.svg +8 -0
- package/lib/client/dictionaries.js +159 -0
- package/lib/client/i18n.js +45 -47
- package/lib/client.js +200 -145
- package/lib/host/config.js +1 -2
- package/lib/host/ledger.js +2 -3
- package/lib/host/lifecycle.js +2 -3
- package/lib/host/ownership.js +8 -4
- package/lib/host/process-inspector.js +1 -2
- package/lib/host/protection.js +1 -2
- package/lib/host/redaction.js +1 -2
- package/lib/host/service-registry.js +4 -5
- package/lib/host/service-tool.js +28 -4
- package/lib/index.js +54 -11
- package/lib/types/client/ServiceConsole.d.ts +24 -12
- package/lib/types/client/dictionaries.d.ts +2 -0
- package/lib/types/client/i18n.d.ts +42 -20
- package/lib/types/host/ledger.d.ts +7 -0
- package/lib/types/host/ownership.d.ts +9 -1
- package/lib/types/host/service-registry.d.ts +2 -1
- package/lib/types/host/service-tool.d.ts +7 -2
- package/lib/types/index.d.ts +18 -2
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +24 -30
- package/dsh.plugin.json +0 -16
- package/dynamic/client.js +0 -193
- package/dynamic/host.js +0 -337
- package/manifest.json +0 -24
package/README.md
CHANGED
|
@@ -20,13 +20,15 @@ Single-purpose plugin for the DeepSeek Harness web UI. When the model (or you) s
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
22
|
- **Discovery** — scans listening TCP ports and correlates PID, PPID, command, working directory, process group and start time (macOS/Linux).
|
|
23
|
-
- **Ownership & risk** — five-level attribution: `This chat` (matched against the session launch ledger), `Workspace`, `Other local`, `Unknown`, `Protected`.
|
|
23
|
+
- **Ownership & risk** — five-level attribution: `This chat` (matched against the session launch ledger and narrowed to the calling session), `Workspace`, `Other local`, `Unknown`, `Protected`.
|
|
24
24
|
- **Control** — graceful stop to the process group, restart with a safe saved launch command. Every action is confirmed twice and re-validated against the current snapshot.
|
|
25
25
|
- **Safeguards** — PID-reuse / fingerprint checks before any signal; unknown and protected services are read-only; force-kill is off by default; no implicit auto-cleanup; command output is redacted.
|
|
26
26
|
- **All local services** — every listening service on this machine is visible; ownership is shown as a safety signal rather than a hidden category filter.
|
|
27
|
-
- **Search, config, i18n** — keyword filtering, graceful timeout / force-kill settings, and
|
|
28
|
-
- **
|
|
27
|
+
- **Search, config, i18n** — keyword filtering, graceful timeout / force-kill settings, auto-refresh interval, and Chinese/English labels following DSH's active locale through the platform `t` seat.
|
|
28
|
+
- **Scanning** — opening the console fetches a snapshot; the refresh button rescans on demand, and an optional interval (off / 2 / 5 / 10 / 30 s) keeps the list live while the panel is open.
|
|
29
29
|
- **DSH-native inspector** — an expanded service record card presents process identity, ports, command, working directory and ownership evidence in the Web UI's token-based visual language.
|
|
30
|
+
- **Chat card + model tool** — a read-only `service_list` model tool with a bounded presentation payload, plus a settings page with its own navigation icon.
|
|
31
|
+
- **Remote-safe** — stop / restart / config writes refuse non-loopback callers, so exposing the Web UI on a network interface never exposes a process killer.
|
|
30
32
|
|
|
31
33
|
## Install
|
|
32
34
|
|
|
@@ -40,7 +42,7 @@ Then refresh the DSH web UI — a `🖥 SC` entry appears in the conversation he
|
|
|
40
42
|
|
|
41
43
|
> Note: a plugin being listed in dsh-market/awesome does not mean its UI auto-appears — this package ships both Host routes and a browser bundle, so after `dsh plugin add` the panel is present. Works on macOS / Linux; Windows is not supported yet.
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
Requires DSH `>=0.2.2-rc.5 <0.3.0` (declared as `engines.dsh`) and Node.js `>=24.9.0`.
|
|
44
46
|
|
|
45
47
|
## UI preview
|
|
46
48
|
|
package/README.zh.md
CHANGED
|
@@ -22,13 +22,15 @@
|
|
|
22
22
|
## 功能
|
|
23
23
|
|
|
24
24
|
- **服务发现** — 扫描监听 TCP 端口,关联 PID、PPID、命令、工作目录、进程组与启动时间(macOS/Linux)。
|
|
25
|
-
- **归属与风险** —
|
|
25
|
+
- **归属与风险** — 五级归属:`本次对话`(与会话启动台账匹配,并按调用方会话收窄)、`工作区`、`本机其他`、`未知`、`受保护`。
|
|
26
26
|
- **受控操作** — 对进程组优雅停止;对保存了安全启动命令的服务重启。每个动作均二次确认,并在操作前重新校验快照。
|
|
27
27
|
- **安全防护** — 任何信号前校验 PID 复用 / fingerprint;未知与受保护服务只读;强制终止默认关闭;无隐式自动清理;命令输出脱敏。
|
|
28
28
|
- **全量本机服务** — 展示本机全部监听服务;归属只作为安全提示,不再隐藏端口分类,用户可自行选择要查看或停止的服务。
|
|
29
|
-
- **搜索 / 配置 / 国际化** — 支持关键字过滤、优雅超时 /
|
|
30
|
-
-
|
|
29
|
+
- **搜索 / 配置 / 国际化** — 支持关键字过滤、优雅超时 / 强制终止、自动刷新间隔;中英文文案通过平台 `t` seat 跟随 DSH 当前语言。
|
|
30
|
+
- **扫描** — 打开控制台时获取快照;刷新按钮按需重扫,可选的自动刷新间隔(关闭 / 2 / 5 / 10 / 30 秒)在面板打开期间保持列表最新。
|
|
31
31
|
- **DSH 原生检查卡片** — 展开详情采用 DSH Web token 化视觉风格,展示进程身份、端口、命令、工作目录和归属证据。
|
|
32
|
+
- **聊天卡片 + 模型工具** — 只读 `service_list` 模型工具(呈现载荷有界),以及带独立导航图标的设置页。
|
|
33
|
+
- **远程安全** — 停止 / 重启 / 配置写入拒绝非回环来源:把 Web UI 暴露到网络接口也不会变成远程进程杀手。
|
|
32
34
|
|
|
33
35
|
## 安装
|
|
34
36
|
|
|
@@ -42,7 +44,7 @@ dsh plugin --profile web add -w @jiyr0119/dsh-service-console@latest
|
|
|
42
44
|
|
|
43
45
|
> 注意:插件被 dsh-market/awesome 收录 ≠ 浏览器自动出现 UI。本包同时提供 Host 路由与浏览器 bundle,`dsh plugin add` 后面板即可用。支持 macOS / Linux;Windows 暂不支持。
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
要求 DSH `>=0.2.2-rc.5 <0.3.0`(见 `engines.dsh`)与 Node.js `>=24.9.0`。
|
|
46
48
|
|
|
47
49
|
## 界面预览
|
|
48
50
|
|
package/docs/local-debugging.md
CHANGED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# DSH 0.2.2-rc.5 兼容性审计与功能跟进建议
|
|
2
|
+
|
|
3
|
+
审计对象:`@jiyr0119/dsh-service-console` 0.7.2(当前工作树)
|
|
4
|
+
审计基准:本机安装的 DSH **0.2.2-rc.5**(`DeepSeek Harness.app/.../dsh/package.json`,Cordis `@deepseek-ai/cordis@4.1.0`)
|
|
5
|
+
审计日期:2026-11-28
|
|
6
|
+
方法:安装版 rc.5 的 340 个 `@deepseek-ai/*` 包源码 + `docs/upgrade-guide/**`(v0.2.0-rc.2 → v0.2.2-rc.4 共 143 条)+ 从 npm `next` tag 取的 5 个未随包发布的客户端包 tarball;插件侧逐文件与 `lib/` 产物对照;另在 `/tmp` 副本里用 rc.5 依赖做了 typecheck / build / test 实测。
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 0. 结论
|
|
11
|
+
|
|
12
|
+
**没有硬性破坏(0 BREAKS)。** 插件调用的 9 个 rc.5 面(3 个 slot、`webServer.register`、`defineTool`、timer、`Toast`、`__ModuleLoader__.load`、`locale.bind/subscribe`、`workspaceRegistry.list`)全部仍在且形状兼容。把 devDeps 换成 rc.5 后:`typecheck` 0 错、`build` 0 错、`test` 38/39(唯一失败项与基线逐字相同,是依赖真实 `lsof` 的环境用例,非 rc.5 引起)。
|
|
13
|
+
|
|
14
|
+
但有 **10 项需要适配**,其中 **2 项是真 bug(且从 0.2.0-rc.2 起就一直是坏的)**,1 项是安全缺口,其余是类型/打包债。
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 1. 必须修的(P0)
|
|
19
|
+
|
|
20
|
+
### P0-1 会话启动台账读错字段 → 「本次对话」归属与「重启」能力全废
|
|
21
|
+
|
|
22
|
+
- `src/host/ledger.ts:11,25` 读 `exec.args`;rc.5 的 `ToolExecution` 只有 **`arguments`**(`dsh-tools/src/contracts.ts:186`)。
|
|
23
|
+
- 已验证该字段从 **0.2.0-rc.2 起就叫 `arguments`**(`dsh-tools@0.2.0-rc.2` 的 `lib/types/index.d.ts:227` 同样是 `readonly arguments: unknown`),所以这不是 rc.5 回归,而是 v0.6.0 升级时漏掉的既有 bug。
|
|
24
|
+
- 后果链:台账恒空 → `classifyOwnership` 永不返回 `conversation-confirmed` → `restartable` 恒 false → 面板「重启」按钮不出现、`restartService` 永远走 `RESTART_UNSAFE`(`src/host/lifecycle.ts:54-56`);「本次对话」范围也恒为空。
|
|
25
|
+
- 单测没抓到,是因为 `test/*.test.mjs` 自己构造的假 exec 对象也用 `args`,自洽。
|
|
26
|
+
- 修法:`const args = (exec as { arguments?: Record<string, unknown> }).arguments ?? {}`(`exec.agent.id` 在 rc.5 仍有效,`dsh-agent/src/types.ts:16-19`)。
|
|
27
|
+
|
|
28
|
+
### P0-2 面板定位测的是一个 `display: contents` 元素 → 恒在 `top: 8px`
|
|
29
|
+
|
|
30
|
+
- `src/client/ServiceConsole.tsx:107-112` 用 `[data-slot="conversation.session.header"]` 的 `getBoundingClientRect().bottom`。
|
|
31
|
+
- rc.5 每个 slot 渲染点都是 `<Anchor data-slot={key} style={{display:'contents'}}>`(`dsh-client-ui-renderer/src/client/scoped-slots.tsx:1319,1348`);`display:contents` 没有盒子,`getBoundingClientRect()` 全 0 → `top = 0 + 8 = 8`。
|
|
32
|
+
- 同样是 rc.2 就存在(repo 里 rc.2 的 renderer 产物也是 `display: "contents"`),即既有视觉缺陷:面板压住会话 header。
|
|
33
|
+
- 修法:量真实盒子(`anchor.firstElementChild` 或 `anchor.closest('header')`,兜底 48),或直接换 rc.5 的 `useAnchoredMaxHeight()`(`@deepseek-ai/dsh-client-ui-primitives` 导出)。
|
|
34
|
+
|
|
35
|
+
### P0-3 macOS 桌面拖拽区域:浮层需要 `data-window-drag-exclude`
|
|
36
|
+
|
|
37
|
+
- rc.5 起,macOS Desktop 只在 `data-window-drag` 行/`data-window-drag-controls` 作用域内自动 `no-drag`;覆盖到拖拽行的自定义浮层必须自己声明排除区(`docs/upgrade-guide/v0.2.2-rc.1/window-drag-regions/guide.md`)。
|
|
38
|
+
- 会话 header 就是拖拽行(`dsh-client-ui-conversation/src/client/skeleton/ConversationHeader.tsx:18` → `data-window-drag`),而 P0-2 让面板正好压在它上面。
|
|
39
|
+
- 修法:给 `.popup`(可见交互盒,不是 click-through 的 `.layer`)加 `data-window-drag-exclude`。修完 P0-2 后这条仍建议保留作防御。
|
|
40
|
+
|
|
41
|
+
### P0-4 兼容性门禁形同虚设:`engines.dsh` 写在没人读的文件里
|
|
42
|
+
|
|
43
|
+
- `package.json` 里**没有** `engines`;`>=0.2.0-rc.2` 只写在 `dsh.plugin.json:6-8`。
|
|
44
|
+
- rc.5 的兼容性检查只读插件自己的 `package.json`(`docs/upgrade-guide/v0.2.1-alpha.3/plugin-engines-dsh/guide.md`;`dsh-app-boot/src/plugin-compatibility.ts:56-60`),而全树 grep 证明 `dsh.plugin.json` **0 处被引用**。
|
|
45
|
+
- 现状:任何 DSH 版本都能装上,包括未来不兼容的版本。
|
|
46
|
+
- 修法:`package.json` 加 `"engines": { "dsh": ">=0.2.2-rc.5 <0.3.0" }`(或至少 `>=0.2.0-rc.2` 保持现状语义)。
|
|
47
|
+
|
|
48
|
+
### P0-5 变更类路由没有 loopback 校验(安全)
|
|
49
|
+
|
|
50
|
+
- `src/index.ts:147-174` 的 `services/stop`、`services/restart`、`config` 无调用方来源校验。
|
|
51
|
+
- rc.5 的 `dsh-host-webserver` 允许绑非 loopback 地址(容器/Pod 场景,`dsh-host-webserver/README.md:39-45`),此时同网段任何客户端都能停本机进程。
|
|
52
|
+
- 修法:在共用 route wrapper 里按 peer socket 地址 + `ctx.webServer.host` 拒绝非 loopback(含 `::ffff:127.0.0.1`),错误码如 `FORBIDDEN_REMOTE`;桌面/本机行为不变。
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 2. 需要适配的(P1,类型与打包债)
|
|
57
|
+
|
|
58
|
+
| # | 问题 | 证据 | 修法 |
|
|
59
|
+
|---|---|---|---|
|
|
60
|
+
| A7 | devDeps 仍钉 `^0.2.0-rc.2`、cordis `~4.0.4`;rc.5 各包 peer 要求 `~4.1.0` | `package.json:60-102` | 全部升 `0.2.2-rc.5`、`@deepseek-ai/cordis@~4.1.0`(npm 上在 `next` dist-tag) |
|
|
61
|
+
| A7b | 唯一的 `@deepseek-ai` **运行时** import(`@deepseek-ai/dsh-tools`,`src/host/service-tool.ts:5` → `lib/host/service-tool.js:1`)只写在 devDependencies | 同上 | 提升到 `peerDependencies`(rc.5 要求「peer + dev 双写」) |
|
|
62
|
+
| A6 | `import type { Context } from 'cordis'` + `declare module 'cordis'` 指向 rc.5 不发布的裸 `cordis` | `src/index.ts:2,12-21` | 改 `@deepseek-ai/cordis`;`timer` 无需自声明(`@deepseek-ai/cordis-plugin-timer` 已 merge) |
|
|
63
|
+
| A4 | 词典用 3 参 `locale.register(ns, code, dict)`,绕过 rc.5 的类型化对象式 | `src/client/i18n.ts:35-50` | 改 `locale.register('dsh-service-console', { zh: ZH_DICT, en: EN_DICT })`;`/already has locale/` 幂等兜底保留 |
|
|
64
|
+
| A2 | 没有 Plugin Manager 显示元数据:无 `locale/*.json` 的 `meta.title/description/detail`、无 `./icon` 导出 | `package.json:8-19,35-47` | 加 `locale/{en,zh}.json` + `icon.svg` + `exports["./locale/*.json"]`/`["./icon"]` + `files` 同步 |
|
|
65
|
+
| A3 | `dsh.client.inject` 漏了两个 slot 的 owner 包 | `package.json:52-59` vs `src/client/index.tsx:70,85,95` | 补 `dsh-client-ui-layout`(`shell.overlay`)、`dsh-client-ui-settings`(`settings.section`)、`dsh-client-ui-renderer` |
|
|
66
|
+
| A9 | `dsh.plugin.json`、`manifest.json`、`dynamic/`、`package.json.dsh.plugin.*` 在 rc.5 全树 **0 引用**,却仍随包发布 | 全树 grep | 删除(保留 `dsh.bundle` + `dsh.client`);`files` 相应精简 |
|
|
67
|
+
| A10 | `tsdown.config.ts:23-29` 的 `PLATFORM_MODULES` 比 rc.5 种子少 `zod`、`@tanstack/react-virtual` | rc.5 shell bundle 的 `qJ()` | 补齐。当前不炸(插件不 import 它们),但将来静默内联不会有任何告警 |
|
|
68
|
+
|
|
69
|
+
另:CI/开发环境 Node 22 通过属于**假绿**——rc.5 要求 Node ≥ 24.9(`docs/upgrade-guide/v0.2.1-rc.2/node-24/guide.md`)。建议 `@types/node` 升 `^24.9.0`,CI 用 24。
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 3. 值得跟着新版本加的(按 价值/成本 排序)
|
|
74
|
+
|
|
75
|
+
rc.5 把过去只能手搓的东西做成了平台能力,本插件正好是重灾区:
|
|
76
|
+
|
|
77
|
+
### A1 · 用 `locale:` 注册选项 + 框架合成的 `t` seat(高价值 / S)
|
|
78
|
+
`ctx.slots.register({ name, id, order, label, locale: 'dsh-service-console' }, Component)` 会给组件注入 namespace 类型化的 `t`(`@deepseek-ai/dsh-client-ui-slots` 的 `BaseOptions.locale` / `PropsLocale`;渲染器 `scoped-slots.tsx:604-612` 在缺 locale 面时**大声抛错**而不是回退原始键)。
|
|
79
|
+
可删掉:`ServiceConsole.tsx:19-30` 的模块级 `tr`/`timerCtx`/`localeSubscribe` 三件套、`:258-263` 的 `setLangTick` 重渲染 hack、`i18n.ts:66-99` 的 `bindTranslator`(含手写 `{param}` 插值)、`index.tsx:47-50` 的 `labelT`/`labelFn`。0.7.1/0.7.2 两个版本围绕 i18n 打的补丁,本质都是在 rc.5 已经原生解决的问题上做自定义实现。
|
|
80
|
+
|
|
81
|
+
### A2 · Plugin Manager 元数据 + 详情页 + 图标(高 / S)
|
|
82
|
+
现在插件在「插件」页显示为包名 + 通用占位图。补 `locale/*.json` 的 `meta`、`./icon`、可选 `meta.detail`(单图 Markdown)即可获得与官方插件一致的行/详情页。
|
|
83
|
+
|
|
84
|
+
### A6 · 注册 `settings.section.icon`(中 / S)
|
|
85
|
+
一个 root 级 list slot,按 section id 对齐,props `{ size, active }`。设置页导航就能显示监视器图标而不是默认字形;`ServiceConsole.tsx:536-540` 的 SVG 直接复用。
|
|
86
|
+
|
|
87
|
+
### A3 · 让「本次对话」归属真正按会话判定(高 / S–M)
|
|
88
|
+
现状只用 `cwd` 前缀 + 10 分钟窗口猜(`src/host/ownership.ts:12,26-31`),**从未比较台账里的 `sessionKey`**——同一工作区里另一个会话十分钟前起的服务会被标成「本次对话」。
|
|
89
|
+
rc.5 给了两条正路:tool 侧 `exec.agent.id` 就是 `SessionId`;client 侧 session 作用域 slot 天然带 `sessionId` 标准 prop。改法:台账命中且 `sessionKey` 匹配才算 `conversation-confirmed`,不匹配降级 `workspace-inferred`,无 session id 的旧调用方保留现启发式。
|
|
90
|
+
|
|
91
|
+
### A5 · 用右侧栏 tab 取代 `shell.overlay` 抽屉(高 / L,结构性)
|
|
92
|
+
`ctx.sidebarRightTabs.register(...)` + `sidebar.right.pane.tab` / `.tab.title` / `sidebar.right.tab.guide.entry`,`ctx.sidebarRight.openTab(kind)` 打开(rc.5 终端插件就是这条路的现成范例)。
|
|
93
|
+
一次删掉:`measurePopup()`(P0-2 的根源,也是插件指南明确禁止的「读别的插件 DOM 估位置」)、模块级 open store、抽屉动画与 document 级 Escape、面板里重复的「设置」tab。换来可拖宽/可停靠/按会话记忆/键盘可达。
|
|
94
|
+
代价:console 变成 session 作用域(今天 header 入口本来也只在会话里存在);「设置」页保持全局。
|
|
95
|
+
|
|
96
|
+
### A4 · 把 `service_list` 渲染成真正的聊天卡片(高 / M)
|
|
97
|
+
rc.5 的 `tool.call.toolview`(keyed by 工具名)+ `output.presentationMeta` / `presentCall` / `presentResult`(`dsh-tools/src/schema.ts:492-545`,`dsh-tool-bash` 与 `dsh-tool-fs-search` 是现成范例)。
|
|
98
|
+
现在只有一段 `output.render` 纯文本(`src/host/service-tool.ts:99-107`)。改成:`presentationMeta` 带**有界**的结构化摘要,客户端一行一个服务(归属 Tag、端口、URL、受保护标记),行内提供「打开 URL」「停止/重启」(复用面板同一套二次确认 + `PROTECTED_PROCESS` 拒绝)、「打开控制台」。注意 meta 会随会话日志持久化,必须限长;toolview 抛错会让整行空白,需要纯文本兜底。
|
|
99
|
+
|
|
100
|
+
### A8 · composer 上方常驻状态 pill(中 / S–M)
|
|
101
|
+
`conversation.composer.dock`(rc.5 的 `ActivityPill`/`UsagePill` 同款)。只在「本会话有归属服务」时出现,显示 `2 services · :3000, :5173`,点开即用。不新增轮询,复用现有扫描。
|
|
102
|
+
|
|
103
|
+
### A9/A10 · 小件安全与可达性(中 / S)
|
|
104
|
+
- loopback 守卫见 P0-5;
|
|
105
|
+
- `ctx.shortcuts.register(...)` 注册「打开服务控制台」命令(可被用户改键,自动出现在快捷键参考里)。
|
|
106
|
+
|
|
107
|
+
### A12 · `timeoutMs` + 可取消扫描(中 / M)
|
|
108
|
+
现在 `execFileSync` 跑 `lsof`/`ps`(`src/host/process-inspector.ts:22-39`),无法响应取消;面板 8s 超时到了命令还在跑。改成 promisified `execFile` + `AbortSignal`,再给 `service_list` 声明 `timeoutMs`(声明即承诺转发 `exec.signal`,必须真做到)。
|
|
109
|
+
|
|
110
|
+
### A13 · 补齐 rc.5 的 8 种语言(中 / M)
|
|
111
|
+
rc.5 内置 `zh, en, ja, es, fr, de, ru, pt`;现在只有 zh/en,其余回落英文。144 个 key × 6 语言,可分批。
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 4. 明确不建议做
|
|
116
|
+
|
|
117
|
+
| 能力 | 原因 |
|
|
118
|
+
|---|---|
|
|
119
|
+
| `deferLoading: true` | 一期工具里没有先例,providers 行为未验证;`service_list` 很便宜 |
|
|
120
|
+
| `tools.register(def, { when })` 门控 | 只读本地扫描在任何会话都安全,加了只有 step 开销 |
|
|
121
|
+
| 迁移到 API Gateway / Typert Remote | 认证类型化确实更好,但要生成 invocation descriptor + Remote 类 + client contribution,L 成本换单机单用户场景;P0-5 已覆盖安全价值 |
|
|
122
|
+
| `useSessionAccess` / `useRemoteAccess` | 它回答的是「能否调用某个 **Remote** 端点」,本插件没有 Remote 命名空间 |
|
|
123
|
+
| 把台账改成 session projection | 更 DSH-native 且 fork/重启友好,但 M–L;A3 已解决用户可见问题 |
|
|
124
|
+
| 用 `ctx.jobs` 跑 stop/restart | jobs 属于 agent,结算会往对话里塞通知;UI 触发的重启不是 agent 任务 |
|
|
125
|
+
| 直接依赖 `dsh-client-ui-dockkit` | 包自己声明是内部引擎、「任意版本可能变更」;用 `ctx.sidebarRight` |
|
|
126
|
+
| 占用 `root` / `main` / `shell.bottom` | 单占位 seat,会遮住内置 UI;`shell.overlay`(或右侧栏)才是正确形状 |
|
|
127
|
+
| terminal 在服务目录里开 shell | 公开 API 的 `TerminalCreateRequest` 没有 `cwd`;改用「复制命令/目录」 |
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 5. 建议落地顺序
|
|
132
|
+
|
|
133
|
+
1. **A7 / A7b / A6 / A10**(依赖与类型基线)→ 一次性 typecheck 全绿;这是后面所有改动的前提。
|
|
134
|
+
2. **P0-1**(`exec.arguments`)→ 补一条用真实 `ToolExecution` 形状的回归用例,锁住这次漏测。
|
|
135
|
+
3. **P0-4 + A9**(`engines.dsh` + 删死文件)→ 让兼容性可声明,发布物变干净。
|
|
136
|
+
4. **A2 + A6**(Plugin Manager 元数据、设置页图标)→ 小、独立、立刻可见。
|
|
137
|
+
5. **P0-2 + P0-3**(面板定位 + 拖拽排除区)→ 视觉/交互修复。
|
|
138
|
+
6. **A1**(`locale:` + `t` seat)→ 删掉最大一块 client 垫片。
|
|
139
|
+
7. **P0-5 + A9(loopback)**(安全)。
|
|
140
|
+
8. **A3**(会话准确归属)→ 先 tool 侧,UI 侧可等 A5。
|
|
141
|
+
9. **A4**(toolview 卡片)、**A5**(右侧栏 tab,连带删 `measurePopup`/全局 store/重复 settings tab)、**A8**(pill)。
|
|
142
|
+
10. **A12 / A13** 独立,随时落。
|
|
143
|
+
|
|
144
|
+
验收:`dsh plugin --profile <p> add ./` 后确认 —— 插件页显示本地化标题/描述/图标;header 入口 + 面板 + 设置页在中英文下文案正确;macOS 桌面上面板不再压住 header 且拖拽区正常;`/dsh-sc/api/services/scan` 在 rc.5 webServer 上正常应答;模型能看到 `service_list` 且 `output.schema` 通过校验;用 `bash` 起一个 dev server 后「本次对话」归属与「重启」按钮**真的出现**(这一条是 P0-1 的关键验收,此前从未真正跑通)。
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 6. 验证边界(不夸大)
|
|
149
|
+
|
|
150
|
+
- rc.5 的 **UI 结论**来自类型与源码契约,不是截图/真机渲染:本会话没有浏览器控制权,面板、pill、toolview 的视觉与键盘流程仍需在 rc.5 Web GUI 里实测。
|
|
151
|
+
- 5 个不随包发布的客户端包(`dsh-client-ui-slots`/`-primitives`/`-store`/`-dockkit`/`dsh-client-web`)取自 npm `next` dist-tag 的 `0.2.2-rc.5` tarball;rc.5 的模块表种子取自安装版 desktop 的 `dsh-web-frontend` bundle(11 项,与插件 9 项对比后确认只差 `zod`、`@tanstack/react-virtual`)。
|
|
152
|
+
- `typecheck`/`build`/`test` 是在 `/tmp` 副本上跑的真实结果(真实仓库未被改动;`git status` 干净)。
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 7. 实施状态(0.8.0)
|
|
157
|
+
|
|
158
|
+
按 §5 的建议顺序落地,`typecheck` 0 错 / `build` 0 错 / `test` **50/50**(rc.5 依赖 + Node 24.22.3):
|
|
159
|
+
|
|
160
|
+
| 阶段 | 项 | 状态 | 落地位置 |
|
|
161
|
+
|---|---|---|---|
|
|
162
|
+
| 1 | A7 依赖与类型基线(rc.5 + cordis 4.1.0 + `@types/node` 24 + CI Node 24) | ✅ | `package.json`、`pnpm-lock.yaml`、`.github/workflows/publish.yml` |
|
|
163
|
+
| 1 | A7b `@deepseek-ai/dsh-tools` peer 化 | ✅ | `package.json` `peerDependencies` |
|
|
164
|
+
| 1 | A6 `cordis` → `@deepseek-ai/cordis` 模块身份 | ✅ | `src/index.ts` |
|
|
165
|
+
| 1 | A10 `PLATFORM_MODULES` 补 `zod` / `@tanstack/react-virtual` | ✅ | `tsdown.config.ts` |
|
|
166
|
+
| 2 | P0-1 `exec.arguments`(+ 真实 `ToolExecution` 形状与端到端回归) | ✅ | `src/host/ledger.ts`、`test/host-more.test.mjs` |
|
|
167
|
+
| 3 | P0-4 `engines.dsh` 入 `package.json` | ✅ | `package.json` |
|
|
168
|
+
| 3 | A9 删除 `dsh.plugin.json` / `manifest.json` / `dynamic/` / `dsh.plugin` | ✅ | 仓库根;README、release-checklist 同步 |
|
|
169
|
+
| 4 | A2 Plugin Manager 元数据(`locale/*.json` meta、`icon.svg`、exports/files) | ✅ | `locale/`、`icon.svg`、`package.json` |
|
|
170
|
+
| 4 | A6 `settings.section.icon` | ✅ | `src/client/index.tsx`、`ServiceConsole.tsx` |
|
|
171
|
+
| 5 | P0-2 面板定位(量真实盒子)+ P0-3 `data-window-drag-exclude` | ✅ | `src/client/ServiceConsole.tsx` |
|
|
172
|
+
| 6 | A1 slot `locale:` + 合成 `t` seat(删 `bindLocale`/`tr`/`setLangTick`/订阅) | ✅ | `src/client/index.tsx`、`ServiceConsole.tsx`、`i18n.ts` |
|
|
173
|
+
| 7 | P0-5 变更路由 loopback 守卫(`FORBIDDEN_REMOTE`) | ✅ | `src/index.ts`、`dictionaries.ts`、`test/hot-reload.test.mjs` |
|
|
174
|
+
| 8 | A3 会话准确归属(`sessionKey` 收窄 + `exec.agent.id` + 面板 `sessionId`) | ✅ | `ownership.ts`、`service-registry.ts`、`service-tool.ts`、`index.ts`、客户端 |
|
|
175
|
+
| 9 | A4 `service_list` 呈现层(`presentCall`/`presentResult`/`presentationMeta`) | ✅(宿主半) | `src/host/service-tool.ts` |
|
|
176
|
+
| 9 | A4 客户端 `tool.call.toolview` 自定义卡片 | ⏳ 待做(需真实 GUI 验证) | — |
|
|
177
|
+
| 9 | A5 右侧栏 tab 迁移 | ⏳ 待做(结构性重写,需视觉验收) | — |
|
|
178
|
+
| 9 | A8 composer dock 常驻 pill | ⏳ 待做 | — |
|
|
179
|
+
| 10 | A12 可取消扫描 + `timeoutMs` | ⏳ 待做 | — |
|
|
180
|
+
| 10 | A13 8 语言词典 | ⏳ 待做 | — |
|
|
181
|
+
|
|
182
|
+
未做项统一原因:它们改变可见 UI/交互或需要真机运行时验证,而本次会话没有浏览器控制权——按「先落地可类型化、可单测验证的部分」处理,其余留作下一轮(每项在 §3 都有完整实现要点)。
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
# npm 发布 checklist(T3-3)
|
|
2
2
|
|
|
3
3
|
> 2FA 的 OTP 为 30 秒一次性验证码,必须在发布那一刻输入,不能当作可异步转交事项。
|
|
4
|
-
>
|
|
4
|
+
> 版本同步两处:`package.json` / `CHANGELOG.md`。
|
|
5
|
+
> (0.8.0 起 `dsh.plugin.json` / `manifest.json` 已删除——DSH 0.2.2-rc.5 只读 `package.json`,
|
|
6
|
+
> 见 `docs/rc5-upgrade-review.zh.md` §A9。兼容性范围改由 `package.json` 的 `engines.dsh` 声明。)
|
|
5
7
|
|
|
6
8
|
## 发布前验证(缺一不可)
|
|
7
9
|
|
|
8
|
-
- [x]
|
|
9
|
-
- [x] `
|
|
10
|
-
- [x] `
|
|
11
|
-
- [x] `
|
|
10
|
+
- [x] Node.js ≥ 24.9(DSH 0.2.2-rc.5 的运行时下限;CI 用 Node 24)
|
|
11
|
+
- [x] `pnpm run typecheck`
|
|
12
|
+
- [x] `pnpm run build`(Host ESM + Client `__ModuleLoader__` bundle)
|
|
13
|
+
- [x] `pnpm test`
|
|
14
|
+
- [x] `npm pack --dry-run`:tarball 含 `lib/`、`cordis.patch.yml`、`locale/*.json`、`icon.svg`、`docs/`、`README*`、`LICENSE`
|
|
12
15
|
- [x] preflight 组合解析(临时 profile add + dump-config,已清理)
|
|
13
|
-
- [ ] 真实 DSH Web profile 挂载验证(
|
|
16
|
+
- [ ] 真实 DSH Web profile 挂载验证(header 入口、面板、`/dsh-sc/api/*`、硬刷新)
|
|
14
17
|
|
|
15
18
|
## 发布步骤
|
|
16
19
|
|
|
17
20
|
```bash
|
|
18
|
-
# 1) 版本 bump
|
|
19
|
-
npm version patch -m "chore: v0.
|
|
20
|
-
# 手动同步
|
|
21
|
+
# 1) 版本 bump(两处同步)
|
|
22
|
+
npm version patch -m "chore: v0.8.0"
|
|
23
|
+
# 手动同步 CHANGELOG.md 的版本号
|
|
21
24
|
|
|
22
25
|
# 2) 构建 + 发布
|
|
23
|
-
|
|
26
|
+
pnpm run build
|
|
24
27
|
npm publish # 需要 OTP(2FA)
|
|
25
28
|
|
|
26
29
|
# 3) Git
|
|
27
30
|
git add .
|
|
28
31
|
git commit -m "feat: ..."
|
|
29
32
|
git push
|
|
30
|
-
git tag v0.
|
|
33
|
+
git tag v0.8.0 && git push origin v0.8.0
|
|
31
34
|
|
|
32
35
|
# 4) GitHub Release
|
|
33
|
-
gh release create v0.
|
|
36
|
+
gh release create v0.8.0 --title "v0.8.0" --notes "..."
|
|
34
37
|
|
|
35
38
|
# 5) 冒烟:临时 profile 安装新版本
|
|
36
39
|
dsh plugin --profile smoke add -w "@jiyr0119/dsh-service-console@latest"
|
package/icon.svg
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" fill="none">
|
|
2
|
+
<!-- Local service console: a monitor with a terminal prompt row and a live status dot. -->
|
|
3
|
+
<rect x="4.25" y="8.25" width="27.5" height="18.5" rx="3.25" stroke="#C6CBD4" stroke-width="1.9" />
|
|
4
|
+
<path d="M10.5 15.25 L14 18 L10.5 20.75" stroke="#C6CBD4" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" />
|
|
5
|
+
<path d="M17.5 20.75 H24" stroke="#C6CBD4" stroke-width="1.9" stroke-linecap="round" />
|
|
6
|
+
<path d="M13.5 30.25 H22.5" stroke="#C6CBD4" stroke-width="1.9" stroke-linecap="round" />
|
|
7
|
+
<circle cx="29.25" cy="9.25" r="3.5" fill="#3FBF7F" stroke="#1B1D21" stroke-width="1.5" />
|
|
8
|
+
</svg>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// src/client/dictionaries.ts
|
|
2
|
+
/**
|
|
3
|
+
* dsh-service-console — i18n 词典(对齐 DSH locale.register 机制)
|
|
4
|
+
* 与 dsh-workspace-explorer 共享设计语言:flat key → template string with {vars}
|
|
5
|
+
*
|
|
6
|
+
* 类型化:ZH_DICT 的键集是词典权威(ConsoleKey);EN_DICT 必须同键集
|
|
7
|
+
* (satisfies Record<ConsoleKey, string> —— 缺键/多键都是编译错误)。
|
|
8
|
+
*/
|
|
9
|
+
const ZH_DICT = {
|
|
10
|
+
"plugin.name": "服务控制台",
|
|
11
|
+
"panel.title": "Service Console",
|
|
12
|
+
"panel.subtitle": "本机监听服务",
|
|
13
|
+
"entry.label": "服务",
|
|
14
|
+
"entry.tip": "服务控制台",
|
|
15
|
+
"search.ph": "搜索服务、端口或路径…",
|
|
16
|
+
"status.scanning": "正在扫描…",
|
|
17
|
+
"status.done": "{n} 项服务",
|
|
18
|
+
"status.lastScan": "最近扫描",
|
|
19
|
+
"status.error": "扫描失败",
|
|
20
|
+
"svc.noSvc": "未发现服务",
|
|
21
|
+
"svc.ports": "端口",
|
|
22
|
+
"svc.pid": "pid",
|
|
23
|
+
"svc.command": "命令",
|
|
24
|
+
"svc.cwd": "工作目录",
|
|
25
|
+
"action.stop": "停止",
|
|
26
|
+
"action.restart": "重启",
|
|
27
|
+
"action.detail": "详情",
|
|
28
|
+
"action.confirm": "确认",
|
|
29
|
+
"action.cancel": "取消",
|
|
30
|
+
"action.pending": "处理中…",
|
|
31
|
+
"confirm.stop": "确认停止?",
|
|
32
|
+
"confirm.restart": "确认重启?",
|
|
33
|
+
"confirm.txt": "确认对 {name} (pid {pid}) 执行 {action}?",
|
|
34
|
+
"result.stopped": "已停止",
|
|
35
|
+
"result.restarted": "已重启",
|
|
36
|
+
"result.error": "操作失败",
|
|
37
|
+
"own.conversation": "本次对话",
|
|
38
|
+
"own.workspace": "工作区推断",
|
|
39
|
+
"own.other": "本机其他",
|
|
40
|
+
"own.unknown": "未知",
|
|
41
|
+
"own.protected": "受保护",
|
|
42
|
+
"scope.conversation": "本次对话",
|
|
43
|
+
"scope.workspace": "当前工作区",
|
|
44
|
+
"scope.machine": "本机",
|
|
45
|
+
"scope.machineWarn": "本机范围可能影响其他项目的服务",
|
|
46
|
+
"detail.title": "详情",
|
|
47
|
+
"detail.serviceRecord": "SERVICE RECORD",
|
|
48
|
+
"detail.serviceId": "SERVICE ID",
|
|
49
|
+
"detail.process": "PROCESS",
|
|
50
|
+
"detail.parent": "PARENT",
|
|
51
|
+
"detail.started": "STARTED",
|
|
52
|
+
"detail.evidence": "归属证据",
|
|
53
|
+
"err.PERMISSION_DENIED": "没有权限读取或控制该服务",
|
|
54
|
+
"err.TARGET_GONE": "该服务已结束",
|
|
55
|
+
"err.PID_REUSED": "进程身份已变化,已取消操作",
|
|
56
|
+
"err.UNKNOWN_OWNERSHIP": "无法确认来源,不允许控制",
|
|
57
|
+
"err.PROTECTED_PROCESS": "受保护进程,不能操作",
|
|
58
|
+
"err.GRACEFUL_TIMEOUT": "未在等待时间内退出",
|
|
59
|
+
"err.RESTART_UNSAFE": "缺少安全启动信息,不能重启",
|
|
60
|
+
"err.PORT_CONFLICT": "端口仍被占用",
|
|
61
|
+
"err.START_TIMEOUT": "未在预期时间开始监听",
|
|
62
|
+
"err.FORBIDDEN_REMOTE": "非本机来源:只读(防止远程停本机进程)",
|
|
63
|
+
"tab.services": "服务",
|
|
64
|
+
"tab.settings": "设置",
|
|
65
|
+
"settings.title": "面板设置",
|
|
66
|
+
"settings.general": "通用",
|
|
67
|
+
"settings.refreshInterval": "自动刷新间隔",
|
|
68
|
+
"settings.refresh.desc": "面板打开时定期自动重新扫描",
|
|
69
|
+
"settings.refreshOff": "关闭",
|
|
70
|
+
"settings.refreshN": "{n} 秒",
|
|
71
|
+
"settings.defaultScope": "默认范围",
|
|
72
|
+
"settings.showUnknown": "显示未知服务",
|
|
73
|
+
"settings.showUnknown.desc": "关闭后隐藏归属未知的服务",
|
|
74
|
+
"settings.gracefulTimeout": "优雅超时 (ms)",
|
|
75
|
+
"settings.forceKill": "允许强制终止",
|
|
76
|
+
"settings.forceKill.desc": "优雅超时后发送 SIGKILL",
|
|
77
|
+
"settings.restore": "恢复默认",
|
|
78
|
+
"settings.note": "配置持久保存在 ~/.dsh/plugins/dsh-service-console/config.json。",
|
|
79
|
+
"settings.nav": "Service Console",
|
|
80
|
+
"star.developer": "开发者",
|
|
81
|
+
"star.ask": "⭐ 顺手留颗 Star,作者能高兴一整天",
|
|
82
|
+
"star.cta": "行,给你一颗 Star"
|
|
83
|
+
};
|
|
84
|
+
const EN_DICT = {
|
|
85
|
+
"plugin.name": "Service Console",
|
|
86
|
+
"panel.title": "Service Console",
|
|
87
|
+
"panel.subtitle": "Listening services on this machine",
|
|
88
|
+
"entry.label": "Services",
|
|
89
|
+
"entry.tip": "Service Console",
|
|
90
|
+
"search.ph": "Search services, ports, or paths…",
|
|
91
|
+
"status.scanning": "Scanning…",
|
|
92
|
+
"status.done": "{n} services",
|
|
93
|
+
"status.lastScan": "Last scan",
|
|
94
|
+
"status.error": "Scan failed",
|
|
95
|
+
"svc.noSvc": "no services found",
|
|
96
|
+
"svc.ports": "Ports",
|
|
97
|
+
"svc.pid": "pid",
|
|
98
|
+
"svc.command": "Command",
|
|
99
|
+
"svc.cwd": "Working dir",
|
|
100
|
+
"action.stop": "Stop",
|
|
101
|
+
"action.restart": "Restart",
|
|
102
|
+
"action.detail": "Detail",
|
|
103
|
+
"action.confirm": "OK",
|
|
104
|
+
"action.cancel": "Cancel",
|
|
105
|
+
"action.pending": "Working…",
|
|
106
|
+
"confirm.stop": "Confirm stop?",
|
|
107
|
+
"confirm.restart": "Confirm restart?",
|
|
108
|
+
"confirm.txt": "Run {action} on {name} (pid {pid})?",
|
|
109
|
+
"result.stopped": "Stopped",
|
|
110
|
+
"result.restarted": "Restarted",
|
|
111
|
+
"result.error": "Action failed",
|
|
112
|
+
"own.conversation": "This chat",
|
|
113
|
+
"own.workspace": "Workspace",
|
|
114
|
+
"own.other": "Other local",
|
|
115
|
+
"own.unknown": "Unknown",
|
|
116
|
+
"own.protected": "Protected",
|
|
117
|
+
"scope.conversation": "This chat",
|
|
118
|
+
"scope.workspace": "Workspace",
|
|
119
|
+
"scope.machine": "This machine",
|
|
120
|
+
"scope.machineWarn": "Machine scope may affect services of other projects",
|
|
121
|
+
"detail.title": "Detail",
|
|
122
|
+
"detail.serviceRecord": "SERVICE RECORD",
|
|
123
|
+
"detail.serviceId": "SERVICE ID",
|
|
124
|
+
"detail.process": "PROCESS",
|
|
125
|
+
"detail.parent": "PARENT",
|
|
126
|
+
"detail.started": "STARTED",
|
|
127
|
+
"detail.evidence": "Ownership evidence",
|
|
128
|
+
"err.PERMISSION_DENIED": "No permission",
|
|
129
|
+
"err.TARGET_GONE": "Service gone",
|
|
130
|
+
"err.PID_REUSED": "PID reused",
|
|
131
|
+
"err.UNKNOWN_OWNERSHIP": "Unknown ownership",
|
|
132
|
+
"err.PROTECTED_PROCESS": "Protected process",
|
|
133
|
+
"err.GRACEFUL_TIMEOUT": "Graceful timeout",
|
|
134
|
+
"err.RESTART_UNSAFE": "Cannot restart safely",
|
|
135
|
+
"err.PORT_CONFLICT": "Port conflict",
|
|
136
|
+
"err.START_TIMEOUT": "Start timeout",
|
|
137
|
+
"err.FORBIDDEN_REMOTE": "Not a local caller — read-only",
|
|
138
|
+
"tab.services": "Services",
|
|
139
|
+
"tab.settings": "Settings",
|
|
140
|
+
"settings.title": "Panel settings",
|
|
141
|
+
"settings.general": "General",
|
|
142
|
+
"settings.refreshInterval": "Auto-refresh interval",
|
|
143
|
+
"settings.refresh.desc": "Re-scan automatically while the panel is open",
|
|
144
|
+
"settings.refreshOff": "Off",
|
|
145
|
+
"settings.refreshN": "{n}s",
|
|
146
|
+
"settings.defaultScope": "Default scope",
|
|
147
|
+
"settings.showUnknown": "Show unknown services",
|
|
148
|
+
"settings.showUnknown.desc": "Hide services with unknown ownership when off",
|
|
149
|
+
"settings.gracefulTimeout": "Graceful timeout (ms)",
|
|
150
|
+
"settings.forceKill": "Allow force kill",
|
|
151
|
+
"settings.forceKill.desc": "Send SIGKILL after graceful timeout",
|
|
152
|
+
"settings.restore": "Reset to defaults",
|
|
153
|
+
"settings.note": "Saved to ~/.dsh/plugins/dsh-service-console/config.json — persists across restarts.",
|
|
154
|
+
"settings.nav": "Service Console",
|
|
155
|
+
"star.developer": "Developer",
|
|
156
|
+
"star.ask": "⭐ Drop a Star if it helped — it makes the author's day",
|
|
157
|
+
"star.cta": "★ Give a Star"
|
|
158
|
+
};
|
|
159
|
+
export { EN_DICT, ZH_DICT };
|
package/lib/client/i18n.js
CHANGED
|
@@ -1,59 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
// src/client/i18n.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* 幂等注册词典:单次对象式注册;已由先前装载注册(`already has locale`)视为
|
|
4
|
+
* 成功,其余错误留一条告警而不是静默吞成「UI 回显原始键」。
|
|
5
5
|
*/
|
|
6
6
|
function registerDictionaries(locale, ns, dicts) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const off = locale.register(ns, code, dict);
|
|
13
|
-
if (typeof off === "function") offs.push(off);
|
|
14
|
-
} catch {}
|
|
7
|
+
try {
|
|
8
|
+
locale.register(ns, dicts);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
11
|
+
if (!/already has locale/.test(message)) console.warn("[dsh-service-console] locale.register(" + ns + ") failed:", message);
|
|
15
12
|
}
|
|
16
|
-
return () => {
|
|
17
|
-
for (const off of offs) try {
|
|
18
|
-
off();
|
|
19
|
-
} catch {}
|
|
20
|
-
};
|
|
21
13
|
}
|
|
22
14
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
15
|
+
* 绑定翻译函数:rc.5 的 bound 原生支持 `{param}` 插值;这里仍保留兜底替换,
|
|
16
|
+
* 以便旧版/桩实现忽略 params 时标签不出现裸占位符。
|
|
25
17
|
*/
|
|
26
18
|
function bindTranslator(locale, ns) {
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
let bound;
|
|
20
|
+
try {
|
|
21
|
+
bound = locale.bind(ns);
|
|
22
|
+
} catch {
|
|
23
|
+
return ((key) => key);
|
|
24
|
+
}
|
|
25
|
+
return ((key, params) => {
|
|
26
|
+
let s;
|
|
29
27
|
try {
|
|
30
|
-
|
|
28
|
+
s = bound(key, params);
|
|
31
29
|
} catch {
|
|
32
|
-
|
|
30
|
+
s = key;
|
|
33
31
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
32
|
+
if (typeof s !== "string" || s === "") s = key;
|
|
33
|
+
if (params && s.includes("{")) for (const k of Object.keys(params)) s = s.split("{" + k + "}").join(String(params[k]));
|
|
34
|
+
return s;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 反应式 i18n 挂载:等 locale 服务真正可用(provider fiber 就绪)后注册词典,
|
|
39
|
+
* 并把绑定好的翻译函数交给调用方(用于 slot 注册项的 `label` thunk——它在每次
|
|
40
|
+
* 投影时被重新读取,因此语言切换无需重新注册)。
|
|
41
|
+
*/
|
|
42
|
+
function attachLocale(ctx, ns, dicts, onReady) {
|
|
43
|
+
ctx.inject(["locale"], (sub) => {
|
|
44
|
+
const locale = sub.get("locale");
|
|
45
|
+
if (locale === void 0) return;
|
|
46
|
+
registerDictionaries(locale, ns, dicts);
|
|
47
|
+
onReady(bindTranslator(locale, ns));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** 动态错误码 → 词典键(`err.<CODE>`);未收录的码回退 fallback */
|
|
51
|
+
function errorText(t, code, fallback) {
|
|
52
|
+
if (!code) return fallback;
|
|
53
|
+
const key = "err." + code;
|
|
54
|
+
const s = t(key);
|
|
55
|
+
return s === key ? fallback : s;
|
|
57
56
|
}
|
|
58
|
-
|
|
59
|
-
export { bindTranslator, registerDictionaries };
|
|
57
|
+
export { attachLocale, bindTranslator, errorText, registerDictionaries };
|