@jiyr0119/dsh-service-console 0.1.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/LICENSE +21 -0
- package/README.md +49 -0
- package/README.zh.md +49 -0
- package/cordis.patch.yml +5 -0
- package/docs/awesome-submission.yml +76 -0
- package/docs/client-acceptance-checklist.md +44 -0
- package/docs/release-checklist.md +47 -0
- package/dsh.plugin.json +16 -0
- package/dynamic/client.js +202 -0
- package/dynamic/host.js +334 -0
- package/lib/client.js +619 -0
- package/lib/host/config.js +75 -0
- package/lib/host/ledger.js +33 -0
- package/lib/host/lifecycle.js +59 -0
- package/lib/host/ownership.js +36 -0
- package/lib/host/process-inspector.js +177 -0
- package/lib/host/redaction.js +27 -0
- package/lib/host/service-registry.js +75 -0
- package/lib/index.js +168 -0
- package/lib/types/client/ServiceConsole.d.ts +9 -0
- package/lib/types/client/index.d.ts +11 -0
- package/lib/types/host/config.d.ts +12 -0
- package/lib/types/host/ledger.d.ts +15 -0
- package/lib/types/host/lifecycle.d.ts +17 -0
- package/lib/types/host/ownership.d.ts +12 -0
- package/lib/types/host/process-inspector.d.ts +51 -0
- package/lib/types/host/redaction.d.ts +1 -0
- package/lib/types/host/service-registry.d.ts +3 -0
- package/lib/types/host/types.d.ts +87 -0
- package/lib/types/index.d.ts +17 -0
- package/manifest.json +24 -0
- package/package.json +100 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-service-console contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# DSH Service Console
|
|
2
|
+
|
|
3
|
+
> A local development service console for DSH: discover listening ports, identify services related to the current conversation or workspace, and safely inspect, stop, or restart them.
|
|
4
|
+
|
|
5
|
+
**DSH 本地开发服务控制台:发现监听端口,识别与当前对话或工作区相关的服务,并安全地查看、停止和重启。**
|
|
6
|
+
|
|
7
|
+
Single-purpose plugin for the DeepSeek Harness web UI. When the model (or you) starts a local dev server (`npm run dev`, Vite, Next.js, Uvicorn, Express, Rust, …), Service Console shows it in one place: which ports it listens on, which command and working directory started it, whether it belongs to this conversation or workspace, and whether it is safe to stop or restart.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Discovery** — scans listening TCP ports and correlates PID, PPID, command, working directory, process group and start time (macOS/Linux).
|
|
12
|
+
- **Ownership & risk** — five-level attribution: `This chat` (matched against the session launch ledger), `Workspace`, `Other local`, `Unknown`, `Protected`.
|
|
13
|
+
- **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.
|
|
14
|
+
- **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.
|
|
15
|
+
- **Scopes, search, config, i18n** — conversation / workspace / machine scopes, keyword filtering, refresh interval / graceful timeout / force-kill settings, zh/en.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
Native package (recommended):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
dsh plugin --profile web add -w @jiyr0119/dsh-service-console@latest
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then refresh the DSH web UI — a `🖥 SC` entry appears in the conversation header and opens the console panel.
|
|
26
|
+
|
|
27
|
+
> 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.
|
|
28
|
+
|
|
29
|
+
Alternative — dynamic paste (zero-build, process-local): paste `dynamic/host.js` + `dynamic/client.js` via the dynamic Cordis plugin flow.
|
|
30
|
+
|
|
31
|
+
## Permissions & safety
|
|
32
|
+
|
|
33
|
+
- The client never sends raw PIDs or shell commands; it targets a service ID and the Host re-validates PID / start time / fingerprint before acting.
|
|
34
|
+
- Graceful termination first (SIGTERM to the process group); SIGKILL only when explicitly enabled and confirmed.
|
|
35
|
+
- Sensitive tokens/passwords in command summaries are redacted.
|
|
36
|
+
- This plugin is **not** a general process manager: system-critical, high-privilege, unknown and protected processes are read-only.
|
|
37
|
+
|
|
38
|
+
## Development
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pnpm install
|
|
42
|
+
npm run typecheck
|
|
43
|
+
npm run build
|
|
44
|
+
npm test # unit + integration tests (node --test)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# DSH Service Console
|
|
2
|
+
|
|
3
|
+
> A local development service console for DSH: discover listening ports, identify services related to the current conversation or workspace, and safely inspect, stop, or restart them.
|
|
4
|
+
>
|
|
5
|
+
> **DSH 本地开发服务控制台:发现监听端口,识别与当前对话或工作区相关的服务,并安全地查看、停止和重启。**
|
|
6
|
+
|
|
7
|
+
面向 DeepSeek Harness Web UI 的单职责插件。当模型(或你)启动本地开发服务(`npm run dev`、Vite、Next.js、Uvicorn、Express、Rust 等)时,Service Console 在一个地方把它们展示出来:监听了哪些端口、由什么命令和目录启动、是否属于当前对话或工作区、能否安全停止或重启。
|
|
8
|
+
|
|
9
|
+
## 功能
|
|
10
|
+
|
|
11
|
+
- **服务发现** — 扫描监听 TCP 端口,关联 PID、PPID、命令、工作目录、进程组与启动时间(macOS/Linux)。
|
|
12
|
+
- **归属与风险** — 五级归属:`本次对话`(与会话启动台账匹配)、`工作区`、`本机其他`、`未知`、`受保护`。
|
|
13
|
+
- **受控操作** — 对进程组优雅停止;对保存了安全启动命令的服务重启。每个动作均二次确认,并在操作前重新校验快照。
|
|
14
|
+
- **安全防护** — 任何信号前校验 PID 复用 / fingerprint;未知与受保护服务只读;强制终止默认关闭;无隐式自动清理;命令输出脱敏。
|
|
15
|
+
- **范围 / 搜索 / 配置 / 国际化** — 本次对话 / 工作区 / 本机三种范围、关键字过滤、刷新间隔 / 优雅超时 / 强制终止设置、中英文。
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
原生安装(推荐):
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
dsh plugin --profile web add -w @jiyr0119/dsh-service-console@latest
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
安装后刷新 DSH Web UI——会话头部出现 `🖥 SC` 入口,点击打开控制台面板。
|
|
26
|
+
|
|
27
|
+
> 注意:插件被 dsh-market/awesome 收录 ≠ 浏览器自动出现 UI。本包同时提供 Host 路由与浏览器 bundle,`dsh plugin add` 后面板即可用。支持 macOS / Linux;Windows 暂不支持。
|
|
28
|
+
|
|
29
|
+
备用方式——动态粘贴(零构建、进程级):通过动态 Cordis 插件流程粘贴 `dynamic/host.js` + `dynamic/client.js`。
|
|
30
|
+
|
|
31
|
+
## 权限与安全
|
|
32
|
+
|
|
33
|
+
- Client 不直接传任意 PID 或 Shell 命令,只以 service ID 为目标,Host 在操作前重新校验 PID / 启动时间 / fingerprint。
|
|
34
|
+
- 优先优雅终止(SIGTERM 到进程组);SIGKILL 仅在显式开启并确认后使用。
|
|
35
|
+
- 命令摘要中的敏感 token/密码会脱敏。
|
|
36
|
+
- 本插件**不是**通用进程管理器:系统关键、高权限、未知和受保护进程一律只读。
|
|
37
|
+
|
|
38
|
+
## 开发
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pnpm install
|
|
42
|
+
npm run typecheck
|
|
43
|
+
npm run build
|
|
44
|
+
npm test # 单元 + 集成测试(node --test)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 许可证
|
|
48
|
+
|
|
49
|
+
MIT
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# awesome-dsh-plugin 提交材料(T3-5 草案)
|
|
2
|
+
|
|
3
|
+
> canonical 上游:`awesome-dsh-plugin/awesome-dsh-plugin`(勿用 `omdsh-dev` fork;提交当天用
|
|
4
|
+
> `gh api repos/awesome-dsh-plugin/awesome-dsh-plugin --jq '.parent'` 与 `git ls-tree -r upstream/main scripts/` 复查生成流程)。
|
|
5
|
+
> 流程:先双语 issue → 修改 YAML 数据源 → `node scripts/generate-readme.mjs`(勿手改 README)→ `--check` → `awesome-lint` → `build-site` → 双语 PR。
|
|
6
|
+
|
|
7
|
+
## 1. 门槛自查(提交前复核贡献指南)
|
|
8
|
+
|
|
9
|
+
- [x] `package.json` 声明 `dsh.bundle.patch` → `./cordis.patch.yml`(已声明)
|
|
10
|
+
- [x] 真实可用代码 + 活跃维护(T1/T2 已完成,测试 9 项全绿)
|
|
11
|
+
- [x] 添加 `dsh-plugin` GitHub topic(T3-4 执行时配置)
|
|
12
|
+
- [ ] repo 年龄 ≥ 1 天、commits ≥ 10(创建后自然满足,提交当天复核)
|
|
13
|
+
- [x] 描述只讲事实,无营销词
|
|
14
|
+
|
|
15
|
+
## 2. 数据源 YAML 草案
|
|
16
|
+
|
|
17
|
+
粘贴到 awesome 仓库 `data/plugins/Jiyr0119__dsh-service-console.yml`(字段名以当期 schema 为准):
|
|
18
|
+
|
|
19
|
+
```yaml
|
|
20
|
+
url: https://github.com/Jiyr0119/dsh-service-console
|
|
21
|
+
name: Jiyr0119/dsh-service-console
|
|
22
|
+
category: ui
|
|
23
|
+
description:
|
|
24
|
+
en: 'Local development service console for DSH: discovers listening ports, shows service ownership, and safely inspects, stops, or restarts services related to a conversation or workspace.'
|
|
25
|
+
zh: 'DSH 本地开发服务控制台:发现监听端口,展示服务归属,并安全地查看、停止或重启与对话或工作区相关的服务。'
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- 描述以句号结尾;含 `: `(英文冒号+空格)必须加引号;避免裸 `[file: ...]` 触发 awesome-lint 引用规则。
|
|
29
|
+
|
|
30
|
+
## 3. 截图(data/screenshots.json,key = 仓库 URL)
|
|
31
|
+
|
|
32
|
+
待 T1-18 浏览器验证时截取并上传 `assets/screenshots/`(GitHub raw URL 引用):
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
"https://github.com/Jiyr0119/dsh-service-console": [
|
|
36
|
+
"https://raw.githubusercontent.com/Jiyr0119/dsh-service-console/main/assets/screenshots/panel.png",
|
|
37
|
+
"https://raw.githubusercontent.com/Jiyr0119/dsh-service-console/main/assets/screenshots/ownership.png",
|
|
38
|
+
"https://raw.githubusercontent.com/Jiyr0119/dsh-service-console/main/assets/screenshots/stop-confirm.png"
|
|
39
|
+
]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
建议截图内容:服务列表面板 / 归属徽标与详情证据 / 停止确认框。
|
|
43
|
+
|
|
44
|
+
## 4. 执行步骤(T3-4 仓库就绪后)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# 1) 双语 issue
|
|
48
|
+
gh issue create --repo awesome-dsh-plugin/awesome-dsh-plugin --title "Add DSH Service Console / 新增 DSH 服务控制台" --body-file issue.md
|
|
49
|
+
|
|
50
|
+
# 2) 从 canonical 建分支
|
|
51
|
+
gh repo clone Jiyr0119/awesome-dsh-plugin && cd awesome-dsh-plugin
|
|
52
|
+
git remote add upstream https://github.com/awesome-dsh-plugin/awesome-dsh-plugin.git
|
|
53
|
+
git fetch upstream main
|
|
54
|
+
git checkout -b feat/add-dsh-service-console upstream/main
|
|
55
|
+
|
|
56
|
+
# 3) 改 YAML + 截图 → 生成/校验
|
|
57
|
+
npm ci
|
|
58
|
+
node scripts/generate-readme.mjs
|
|
59
|
+
node scripts/generate-readme.mjs --check
|
|
60
|
+
npx awesome-lint
|
|
61
|
+
node scripts/build-site.mjs
|
|
62
|
+
|
|
63
|
+
# 4) 提交数据源 + 生成的 README → 双语 PR
|
|
64
|
+
git add data/plugins README.md README.zh.md
|
|
65
|
+
git commit -m "Add DSH Service Console"
|
|
66
|
+
git push origin feat/add-dsh-service-console
|
|
67
|
+
gh pr create --repo awesome-dsh-plugin/awesome-dsh-plugin --base main --head Jiyr0119:feat/add-dsh-service-console --title "Add DSH Service Console / 新增 DSH 服务控制台" --body-file pr.md
|
|
68
|
+
|
|
69
|
+
# 5) 查重 + CI
|
|
70
|
+
gh search prs --repo awesome-dsh-plugin/awesome-dsh-plugin "Jiyr0119"
|
|
71
|
+
gh pr view <num> --repo awesome-dsh-plugin/awesome-dsh-plugin --json statusCheckRollup,mergeStateStatus
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 5. 差异化定位
|
|
75
|
+
|
|
76
|
+
对比 `DSH-better-sidebar` 等全家桶:本插件是 **standalone / single-purpose / zero-config / one-command** 的本地开发服务控制台,只做"服务发现 + 归属 + 安全控制"一件事。
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Client 验收清单(T3-1)· 执行记录
|
|
2
|
+
|
|
3
|
+
> 运行环境:DSH Web 原生包(lib/index.js + lib/client.js,preflight 已过,真实 web profile 挂载待确认)
|
|
4
|
+
> 动态对照:scdev-2/pkg-18(M1 面板,浏览器可见验证)
|
|
5
|
+
> 状态:⬜ 待执行(浏览器人工/自动化走查后勾选)
|
|
6
|
+
|
|
7
|
+
## 状态与错误展示
|
|
8
|
+
|
|
9
|
+
- [ ] 空态:无监听服务时显示"未发现服务"
|
|
10
|
+
- [ ] 扫描中:显示 `⏳` 状态与发起时间
|
|
11
|
+
- [ ] 部分失败:`⚠ partialWarnings` 逐条展示
|
|
12
|
+
- [ ] 权限不足:降级为只读,不显示 Stop
|
|
13
|
+
- [ ] 服务退出后:列表刷新后消失(TARGET_GONE 语义)
|
|
14
|
+
|
|
15
|
+
## 交互正确性
|
|
16
|
+
|
|
17
|
+
- [ ] 范围切换(本次对话/工作区/本机)不混淆归属
|
|
18
|
+
- [ ] 搜索按名称/端口/命令/路径过滤正确
|
|
19
|
+
- [ ] Detail 展开显示 serviceId、pgid、ppid、startedAt、归属证据
|
|
20
|
+
- [ ] 停止:两次点击(Stop → 确认),成功后显示"已停止"且服务消失
|
|
21
|
+
- [ ] 重启:仅可重启服务显示 Restart,成功后新 PID 重新监听
|
|
22
|
+
- [ ] 错误码本地化:PID_REUSED / GRACEFUL_TIMEOUT / RESTART_UNSAFE 等显示可读文案
|
|
23
|
+
- [ ] URL 打开:HTTP 服务 🔗 链接可打开
|
|
24
|
+
- [ ] 配置面板:刷新间隔/优雅超时/强制终止修改生效并持久化(重启后保留)
|
|
25
|
+
- [ ] 5s 自动轮询开关生效;面板关闭后无残留请求
|
|
26
|
+
|
|
27
|
+
## 主题 / i18n / a11y
|
|
28
|
+
|
|
29
|
+
- [ ] 深浅主题(`--dsw-alias-*`)均正常
|
|
30
|
+
- [ ] 中/EN 切换:全部用户可见文案跟随
|
|
31
|
+
- [ ] 键盘可操作(Tab 聚焦、Enter 触发)
|
|
32
|
+
- [ ] 窄窗口下不遮挡 composer
|
|
33
|
+
- [ ] reduced motion 无异常
|
|
34
|
+
|
|
35
|
+
## 动态版对照(scdev-2/pkg-18)
|
|
36
|
+
|
|
37
|
+
- [ ] header 入口 🖥 SC 可见,面板打开
|
|
38
|
+
- [ ] 本次对话启动的 dev 服务显示"本次对话"归属 + 可重启
|
|
39
|
+
- [ ] Stop/Restart 命令链路生效(bash 等价命令已验证)
|
|
40
|
+
|
|
41
|
+
## 备注
|
|
42
|
+
|
|
43
|
+
- 动态版端到端(T1-18)依赖本清单第 2 节浏览器走查。
|
|
44
|
+
- 原生版真实 web profile 挂载(T2-7 后半)后,需在原生环境重跑本清单。
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# npm 发布 checklist(T3-3)
|
|
2
|
+
|
|
3
|
+
> 2FA 的 OTP 为 30 秒一次性验证码,必须在发布那一刻输入,不能当作可异步转交事项。
|
|
4
|
+
> 版本同步四处:`package.json` / `dsh.plugin.json` / `manifest.json` / `CHANGELOG.md`。
|
|
5
|
+
|
|
6
|
+
## 发布前验证(缺一不可)
|
|
7
|
+
|
|
8
|
+
- [x] `npm run typecheck`
|
|
9
|
+
- [x] `npm run build`(Host ESM + Client `__ModuleLoader__` bundle)
|
|
10
|
+
- [x] `npm test`(单元 7 + 集成 2)
|
|
11
|
+
- [x] `npm pack --dry-run`:tarball 含 `lib/`、`dsh.plugin.json`、`cordis.patch.yml`、`manifest.json`、`dynamic/`、`README*`、`LICENSE`
|
|
12
|
+
- [x] preflight 组合解析(临时 profile add + dump-config,已清理)
|
|
13
|
+
- [ ] 真实 DSH Web profile 挂载验证(T2-7 后半:header 入口、面板、`/dsh-sc/api/*`、硬刷新)
|
|
14
|
+
|
|
15
|
+
## 发布步骤
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 1) 版本 bump(四处同步)
|
|
19
|
+
npm version patch -m "chore: v0.1.1"
|
|
20
|
+
# 手动同步 dsh.plugin.json / manifest.json / CHANGELOG.md 的版本号
|
|
21
|
+
|
|
22
|
+
# 2) 构建 + 发布
|
|
23
|
+
npm run build
|
|
24
|
+
npm publish # 需要 OTP(2FA)
|
|
25
|
+
|
|
26
|
+
# 3) Git
|
|
27
|
+
git add .
|
|
28
|
+
git commit -m "feat: ..."
|
|
29
|
+
git push
|
|
30
|
+
git tag v0.1.1 && git push origin v0.1.1
|
|
31
|
+
|
|
32
|
+
# 4) GitHub Release
|
|
33
|
+
gh release create v0.1.1 --title "v0.1.1" --notes "..."
|
|
34
|
+
|
|
35
|
+
# 5) 冒烟:临时 profile 安装新版本
|
|
36
|
+
dsh plugin --profile smoke add -w "@jiyr0119/dsh-service-console@latest"
|
|
37
|
+
dsh --profile smoke --dump-config >/dev/null && echo OK
|
|
38
|
+
rm -rf "$HOME/.dsh/profiles/smoke"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## keywords(可检索事实描述)
|
|
42
|
+
|
|
43
|
+
`deepseek-harness` · `cordis` · `dsh-plugin` · `local-dev-server` · `port-manager`
|
|
44
|
+
|
|
45
|
+
## 发布顺序(完整)
|
|
46
|
+
|
|
47
|
+
功能完成 → typecheck/build/pack → preflight + 真实 Web 验证 → 版本与 CHANGELOG 同步 → commit/tag/push → npm publish → GitHub Release → 干净安装冒烟 → awesome issue/PR(T3-5)。
|
package/dsh.plugin.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "dsh-external/dsh-service-console",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"description": "本地开发服务控制台:发现监听端口,识别服务归属,安全查看/停止/重启。Local development service console for DSH.",
|
|
6
|
+
"engines": {
|
|
7
|
+
"dsh": ">=0.0.1"
|
|
8
|
+
},
|
|
9
|
+
"contributes": {
|
|
10
|
+
"tools": [],
|
|
11
|
+
"skills": []
|
|
12
|
+
},
|
|
13
|
+
"client": {
|
|
14
|
+
"main": "./lib/client.js"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// dsh-service-console · M1 动态原型 Client(v3 = pkg-18 增强版:范围/搜索/配置/i18n)
|
|
2
|
+
// 覆盖任务:T1-9 入口 · T1-10 Overlay+轮询 · T1-11 列表/详情 · T1-12 范围/搜索/筛选
|
|
3
|
+
// T1-13 停止 UI · T1-14 重启 UI · T1-15 URL 打开 · T1-16 配置面板 · T1-17 i18n
|
|
4
|
+
// 说明:纯 JavaScript + React.createElement(无 JSX)。定时器必须用 timer 服务(inject: ['timer'] + ctx.timeout/ctx.interval)。
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
inject: ['timer'],
|
|
8
|
+
apply(ctx) {
|
|
9
|
+
const slots = ctx.get('slots')
|
|
10
|
+
if (slots === undefined) return
|
|
11
|
+
|
|
12
|
+
const store = { open: false, listeners: new Set() }
|
|
13
|
+
function subscribe(fn) { store.listeners.add(fn); return () => store.listeners.delete(fn) }
|
|
14
|
+
function setOpen(v) { store.open = v; store.listeners.forEach((l) => l(v)) }
|
|
15
|
+
|
|
16
|
+
const TEXTS = {
|
|
17
|
+
zh: {
|
|
18
|
+
title: 'Service Console', scopeConv: '本次对话', scopeWs: '工作区', scopeMachine: '本机',
|
|
19
|
+
search: '搜索服务/端口/路径…', auto: '5s', config: '配置', close: '关闭',
|
|
20
|
+
noSvc: '未发现服务', stop: '停止', restart: '重启', detail: '详情',
|
|
21
|
+
confirmStop: '确认停止?', confirmRestart: '确认重启?', confirmTxt: '确认对 {name} (pid {pid}) 执行{action}?',
|
|
22
|
+
ok: '确认', cancel: '取消', stopped: '已停止', restarted: '已重启',
|
|
23
|
+
evidence: '归属证据', refreshInterval: '自动刷新间隔(ms)', gracefulTimeout: '优雅超时(ms)', forceKill: '允许强制终止',
|
|
24
|
+
},
|
|
25
|
+
en: {
|
|
26
|
+
title: 'Service Console', scopeConv: 'This chat', scopeWs: 'Workspace', scopeMachine: 'This Mac',
|
|
27
|
+
search: 'Search services/ports/paths…', auto: '5s', config: 'Config', close: 'Close',
|
|
28
|
+
noSvc: 'no services found', stop: 'Stop', restart: 'Restart', detail: 'Detail',
|
|
29
|
+
confirmStop: 'Confirm stop?', confirmRestart: 'Confirm restart?', confirmTxt: 'Run {action} on {name} (pid {pid})?',
|
|
30
|
+
ok: 'OK', cancel: 'Cancel', stopped: 'Stopped', restarted: 'Restarted',
|
|
31
|
+
evidence: 'Ownership evidence', refreshInterval: 'Refresh interval (ms)', gracefulTimeout: 'Graceful timeout (ms)', forceKill: 'Allow force kill',
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
const OWNERSHIP = {
|
|
35
|
+
'conversation-confirmed': { zh: '本次对话', en: 'This chat', color: 'var(--dsw-alias-state-success-primary, #4ade80)' },
|
|
36
|
+
'workspace-inferred': { zh: '工作区推断', en: 'Workspace', color: 'var(--dsw-alias-state-warn-primary, #fbbf24)' },
|
|
37
|
+
'other-local': { zh: '本机其他', en: 'Other local', color: 'var(--dsw-alias-label-secondary, #94a3b8)' },
|
|
38
|
+
'unknown': { zh: '未知', en: 'Unknown', color: 'var(--dsw-alias-state-error-primary, #f87171)' },
|
|
39
|
+
'protected': { zh: '受保护', en: 'Protected', color: 'var(--dsw-alias-state-error-primary, #f87171)' },
|
|
40
|
+
}
|
|
41
|
+
const ERROR_LABEL = {
|
|
42
|
+
PERMISSION_DENIED: ['没有权限读取或控制该服务', 'No permission'], TARGET_GONE: ['该服务已结束', 'Service gone'],
|
|
43
|
+
PID_REUSED: ['进程身份已变化,已取消操作', 'PID reused'], UNKNOWN_OWNERSHIP: ['无法确认来源,不允许控制', 'Unknown ownership'],
|
|
44
|
+
PROTECTED_PROCESS: ['受保护进程,不能操作', 'Protected process'], GRACEFUL_TIMEOUT: ['未在等待时间内退出', 'Graceful timeout'],
|
|
45
|
+
RESTART_UNSAFE: ['缺少安全启动信息,不能重启', 'Cannot restart safely'], PORT_CONFLICT: ['端口仍被占用', 'Port conflict'],
|
|
46
|
+
START_TIMEOUT: ['未在预期时间开始监听', 'Start timeout'],
|
|
47
|
+
}
|
|
48
|
+
const STYLE = {
|
|
49
|
+
panel: { position: 'fixed', top: 72, right: 20, zIndex: 9999, width: 540, maxHeight: 'min(640px, calc(100dvh - 110px))', overflow: 'auto', background: 'var(--dsw-alias-bg-overlay, #262626)', color: 'var(--dsw-alias-label-primary, #eee)', border: '1px solid var(--dsw-alias-border-l1, #444)', borderRadius: 10, padding: 12, boxShadow: '0 8px 32px rgba(0,0,0,.35)', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: 12, pointerEvents: 'auto' },
|
|
50
|
+
row: { padding: '8px 0', borderBottom: '1px solid var(--dsw-alias-border-l1, #333)' },
|
|
51
|
+
muted: { color: 'var(--dsw-alias-label-secondary, #999)' }, ok: { color: 'var(--dsw-alias-state-success-primary, #4ade80)' },
|
|
52
|
+
err: { color: 'var(--dsw-alias-state-error-primary, #f87171)' }, warn: { color: 'var(--dsw-alias-state-warn-primary, #fbbf24)' },
|
|
53
|
+
btn: { cursor: 'pointer', fontSize: 11, marginLeft: 6, padding: '1px 6px', borderRadius: 4, border: '1px solid var(--dsw-alias-border-l1, #555)', background: 'var(--dsw-alias-bg-layer-1, #333)', color: 'var(--dsw-alias-label-primary, #eee)' },
|
|
54
|
+
badge: { borderRadius: 4, padding: '0 5px', fontSize: 10, border: '1px solid currentColor' },
|
|
55
|
+
input: { background: 'var(--dsw-alias-bg-layer-1, #333)', color: 'var(--dsw-alias-label-primary, #eee)', border: '1px solid var(--dsw-alias-border-l1, #555)', borderRadius: 4, padding: '2px 6px', fontSize: 11 },
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function Entry() {
|
|
59
|
+
const [open, setLocal] = React.useState(store.open)
|
|
60
|
+
React.useEffect(() => subscribe(setLocal), [])
|
|
61
|
+
return React.createElement('button', { onClick: () => setOpen(!store.open), title: 'Service Console', style: { background: 'var(--dsw-alias-bg-layer-1, #333)', color: 'var(--dsw-alias-label-primary, #eee)', border: '1px solid var(--dsw-alias-border-l1, #555)', borderRadius: 6, padding: '2px 8px', fontSize: 12, cursor: 'pointer' } }, open ? '✕' : '🖥 SC')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function Panel() {
|
|
65
|
+
const [open, setLocal] = React.useState(store.open)
|
|
66
|
+
const [lang, setLang] = React.useState('zh')
|
|
67
|
+
const [scope, setScope] = React.useState('workspace')
|
|
68
|
+
const [query, setQuery] = React.useState('')
|
|
69
|
+
const [showConfig, setShowConfig] = React.useState(false)
|
|
70
|
+
const [configData, setConfigData] = React.useState(null)
|
|
71
|
+
const [view, setView] = React.useState({ phase: 'idle', at: null, data: null, err: null })
|
|
72
|
+
const [confirming, setConfirming] = React.useState(null)
|
|
73
|
+
const [opResult, setOpResult] = React.useState(null)
|
|
74
|
+
const [expanded, setExpanded] = React.useState(null)
|
|
75
|
+
const [autoRefresh, setAutoRefresh] = React.useState(true)
|
|
76
|
+
const timeoutRef = React.useRef(null)
|
|
77
|
+
const intervalRef = React.useRef(null)
|
|
78
|
+
React.useEffect(() => subscribe(setLocal), [])
|
|
79
|
+
React.useEffect(() => () => { if (timeoutRef.current) timeoutRef.current(); if (intervalRef.current) intervalRef.current() }, [])
|
|
80
|
+
|
|
81
|
+
const T = TEXTS[lang]
|
|
82
|
+
const scan = () => {
|
|
83
|
+
const at = new Date().toLocaleTimeString()
|
|
84
|
+
setView((v) => ({ phase: 'scanning', at, data: v.data, err: null }))
|
|
85
|
+
if (timeoutRef.current) timeoutRef.current()
|
|
86
|
+
timeoutRef.current = ctx.timeout(() => { setView((v) => (v.phase === 'scanning' ? { phase: 'timeout', at, data: v.data, err: 'timeout' } : v)) }, 8000)
|
|
87
|
+
host.call('scan', {}).then((res) => { if (timeoutRef.current) { timeoutRef.current(); timeoutRef.current = null } setView({ phase: 'done', at, data: res && res.data ? res.data : res, err: null }) })
|
|
88
|
+
.catch((e) => { if (timeoutRef.current) { timeoutRef.current(); timeoutRef.current = null } setView({ phase: 'error', at, data: null, err: String((e && e.message) || e) }) })
|
|
89
|
+
}
|
|
90
|
+
const loadConfig = () => {
|
|
91
|
+
host.call('config', {}).then((res) => setConfigData(res && res.data ? res.data.config : null)).catch(() => {})
|
|
92
|
+
}
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
if (open && view.phase === 'idle') scan()
|
|
95
|
+
if (open && autoRefresh) { intervalRef.current = ctx.interval(() => scan(), 5000); return () => { if (intervalRef.current) intervalRef.current(); intervalRef.current = null } }
|
|
96
|
+
}, [open, autoRefresh])
|
|
97
|
+
if (!open) return null
|
|
98
|
+
|
|
99
|
+
const runAction = (svc, action) => { setConfirming({ id: svc.id, action }); setOpResult(null) }
|
|
100
|
+
const confirmAction = (svc, action) => {
|
|
101
|
+
setConfirming(null)
|
|
102
|
+
host.call(action, { serviceId: svc.id })
|
|
103
|
+
.then((res) => {
|
|
104
|
+
if (res && res.ok) setOpResult({ id: svc.id, ok: true, text: action === 'stop' ? T.stopped : T.restarted })
|
|
105
|
+
else setOpResult({ id: svc.id, ok: false, text: (res && res.error && (ERROR_LABEL[res.error.code] ? ERROR_LABEL[res.error.code][lang === 'zh' ? 0 : 1] : res.error.message)) || 'ERR' })
|
|
106
|
+
scan()
|
|
107
|
+
})
|
|
108
|
+
.catch((e) => setOpResult({ id: svc.id, ok: false, text: 'RPC error' }))
|
|
109
|
+
}
|
|
110
|
+
const setConfig = (patch) => {
|
|
111
|
+
host.call('config', { action: 'update', patch }).then((res) => { if (res && res.data) setConfigData(res.data.config) })
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let rows = (view.data && view.data.services) || []
|
|
115
|
+
if (scope === 'conversation') rows = rows.filter((s) => s.ownership === 'conversation-confirmed')
|
|
116
|
+
else if (scope === 'workspace') rows = rows.filter((s) => s.ownership === 'conversation-confirmed' || s.ownership === 'workspace-inferred')
|
|
117
|
+
if (query) {
|
|
118
|
+
const q = String(query).toLowerCase()
|
|
119
|
+
rows = rows.filter((s) => String(s.name).toLowerCase().indexOf(q) >= 0 || String(s.pid).indexOf(q) >= 0 || (s.commandSummary || '').toLowerCase().indexOf(q) >= 0 || (s.cwd || '').toLowerCase().indexOf(q) >= 0 || (s.listeners || []).some((l) => String(l.port).indexOf(q) >= 0))
|
|
120
|
+
}
|
|
121
|
+
const status =
|
|
122
|
+
view.phase === 'scanning' ? React.createElement('div', { style: STYLE.warn }, '⏳ ' + view.at)
|
|
123
|
+
: view.phase === 'done' ? React.createElement('div', { style: STYLE.ok }, '✅ ' + view.at + ' · ' + String(view.data.count) + ' · ledger=' + String(view.data.ledgerCount))
|
|
124
|
+
: view.phase === 'error' || view.phase === 'timeout' ? React.createElement('div', { style: STYLE.err }, '⛔ ' + view.err)
|
|
125
|
+
: null
|
|
126
|
+
|
|
127
|
+
return React.createElement('div', { style: STYLE.panel },
|
|
128
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6, flexWrap: 'wrap' } },
|
|
129
|
+
React.createElement('strong', null, T.title),
|
|
130
|
+
React.createElement('select', { value: scope, onChange: (e) => setScope(e.target.value), style: STYLE.input },
|
|
131
|
+
React.createElement('option', { value: 'conversation' }, T.scopeConv),
|
|
132
|
+
React.createElement('option', { value: 'workspace' }, T.scopeWs),
|
|
133
|
+
React.createElement('option', { value: 'machine' }, T.scopeMachine)
|
|
134
|
+
),
|
|
135
|
+
React.createElement('button', { onClick: () => setLang(lang === 'zh' ? 'en' : 'zh'), style: STYLE.btn }, lang === 'zh' ? 'EN' : '中'),
|
|
136
|
+
React.createElement('button', { onClick: () => { setShowConfig(!showConfig); if (!showConfig) loadConfig() }, style: STYLE.btn }, T.config),
|
|
137
|
+
React.createElement('span', { style: { flex: 1 } }),
|
|
138
|
+
React.createElement('label', { style: STYLE.muted }, React.createElement('input', { type: 'checkbox', checked: autoRefresh, onChange: (e) => setAutoRefresh(e.target.checked) }), T.auto),
|
|
139
|
+
React.createElement('button', { onClick: scan, style: STYLE.btn }, '↻'),
|
|
140
|
+
React.createElement('button', { onClick: () => setOpen(false), style: STYLE.btn }, T.close)
|
|
141
|
+
),
|
|
142
|
+
React.createElement('input', { placeholder: T.search, value: query, onChange: (e) => setQuery(e.target.value), style: Object.assign({}, STYLE.input, { width: '100%', marginBottom: 6 }) }),
|
|
143
|
+
showConfig && configData
|
|
144
|
+
? React.createElement('div', { style: { background: 'var(--dsw-alias-bg-layer-1, #333)', borderRadius: 6, padding: 8, marginBottom: 8 } },
|
|
145
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
|
|
146
|
+
React.createElement('span', { style: STYLE.muted }, T.refreshInterval),
|
|
147
|
+
React.createElement('input', { type: 'number', defaultValue: configData.refreshInterval, onBlur: (e) => setConfig({ refreshInterval: parseInt(e.target.value, 10) }), style: Object.assign({}, STYLE.input, { width: 80 }) })
|
|
148
|
+
),
|
|
149
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 4 } },
|
|
150
|
+
React.createElement('span', { style: STYLE.muted }, T.gracefulTimeout),
|
|
151
|
+
React.createElement('input', { type: 'number', defaultValue: configData.gracefulTimeout, onBlur: (e) => setConfig({ gracefulTimeout: parseInt(e.target.value, 10) }), style: Object.assign({}, STYLE.input, { width: 80 }) })
|
|
152
|
+
),
|
|
153
|
+
React.createElement('label', { style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 4 } },
|
|
154
|
+
React.createElement('input', { type: 'checkbox', checked: !!configData.forceKill, onChange: (e) => setConfig({ forceKill: e.target.checked }) }), T.forceKill
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
: null,
|
|
158
|
+
status,
|
|
159
|
+
rows.length === 0 && view.phase === 'done' ? React.createElement('div', { style: STYLE.muted }, T.noSvc)
|
|
160
|
+
: rows.map((svc) => {
|
|
161
|
+
const badge = OWNERSHIP[svc.ownership] || OWNERSHIP.unknown
|
|
162
|
+
const ports = (svc.listeners || []).map((l) => String(l.port)).join(', ')
|
|
163
|
+
const url = (svc.listeners || []).map((l) => l.url).filter(Boolean)[0]
|
|
164
|
+
const canControl = svc.ownership === 'conversation-confirmed' || svc.ownership === 'workspace-inferred' || svc.ownership === 'other-local'
|
|
165
|
+
const isConfirming = confirming && confirming.id === svc.id
|
|
166
|
+
const result = opResult && opResult.id === svc.id ? opResult : null
|
|
167
|
+
return React.createElement('div', { key: svc.id, style: STYLE.row },
|
|
168
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } },
|
|
169
|
+
React.createElement('span', { style: STYLE.ok }, '●'),
|
|
170
|
+
React.createElement('span', { style: { fontWeight: 600 } }, String(svc.name)),
|
|
171
|
+
React.createElement('span', { style: STYLE.muted }, ':' + ports + ' · pid ' + String(svc.pid)),
|
|
172
|
+
React.createElement('span', { style: Object.assign({}, STYLE.badge, { color: badge.color }) }, badge[lang] || badge.zh),
|
|
173
|
+
svc.restartable ? React.createElement('span', { style: Object.assign({}, STYLE.badge, { color: STYLE.ok.color }) }, '↻') : null,
|
|
174
|
+
url ? React.createElement('a', { href: url, target: '_blank', rel: 'noreferrer', style: Object.assign({}, STYLE.btn, { textDecoration: 'none' }) }, '🔗') : null,
|
|
175
|
+
React.createElement('span', { style: { flex: 1 } }),
|
|
176
|
+
canControl ? React.createElement('button', { style: STYLE.btn, onClick: () => runAction(svc, 'stop') }, isConfirming && confirming.action === 'stop' ? T.confirmStop : T.stop) : null,
|
|
177
|
+
svc.restartable ? React.createElement('button', { style: STYLE.btn, onClick: () => runAction(svc, 'restart') }, isConfirming && confirming.action === 'restart' ? T.confirmRestart : T.restart) : null,
|
|
178
|
+
React.createElement('button', { style: STYLE.btn, onClick: () => setExpanded(expanded === svc.id ? null : svc.id) }, expanded === svc.id ? '▾' : T.detail)
|
|
179
|
+
),
|
|
180
|
+
React.createElement('div', { style: STYLE.muted }, (svc.commandSummary ? String(svc.commandSummary).slice(0, 100) : '(?)') + (svc.commandSummary && svc.commandSummary.length > 100 ? '…' : '')),
|
|
181
|
+
svc.cwd ? React.createElement('div', { style: STYLE.muted }, svc.cwd) : null,
|
|
182
|
+
result ? React.createElement('div', { style: result.ok ? STYLE.ok : STYLE.err }, (result.ok ? '✅ ' : '⛔ ') + result.text) : null,
|
|
183
|
+
isConfirming ? React.createElement('div', { style: { marginTop: 4 } },
|
|
184
|
+
React.createElement('span', { style: STYLE.muted }, T.confirmTxt.replace('{name}', svc.name).replace('{pid}', String(svc.pid)).replace('{action}', confirming.action === 'stop' ? T.stop : T.restart) + ' '),
|
|
185
|
+
React.createElement('button', { style: Object.assign({}, STYLE.btn, { color: STYLE.err.color }), onClick: () => confirmAction(svc, confirming.action) }, T.ok),
|
|
186
|
+
React.createElement('button', { style: STYLE.btn, onClick: () => setConfirming(null) }, T.cancel)
|
|
187
|
+
) : null,
|
|
188
|
+
expanded === svc.id ? React.createElement('div', { style: { marginTop: 4, background: 'var(--dsw-alias-bg-layer-1, #333)', padding: 6, borderRadius: 6 } },
|
|
189
|
+
React.createElement('div', { style: STYLE.muted }, 'id: ' + svc.id),
|
|
190
|
+
React.createElement('div', { style: STYLE.muted }, 'pgid: ' + String(svc.processGroupId) + ' · ppid: ' + String(svc.parentPid) + ' · startedAt: ' + String(svc.startedAt)),
|
|
191
|
+
React.createElement('div', { style: STYLE.muted }, T.evidence + ':'),
|
|
192
|
+
(svc.ownershipEvidence || []).map((ev, i) => React.createElement('div', { key: i, style: STYLE.muted }, ' · ' + ev))
|
|
193
|
+
) : null
|
|
194
|
+
)
|
|
195
|
+
})
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
slots.inject('conversation.session.header.utilities', () => slots.register({ name: 'conversation.session.header.utilities', id: 'sc-dev-entry' }, () => React.createElement(Entry)))
|
|
200
|
+
slots.inject('shell.overlay', () => slots.register({ name: 'shell.overlay', id: 'sc-dev-panel' }, () => React.createElement(Panel)))
|
|
201
|
+
},
|
|
202
|
+
}
|