@jiyr0119/dsh-service-console 0.8.0 → 0.10.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 +1 -1
- package/README.zh.md +1 -1
- package/lib/client/dictionaries.js +24 -0
- package/lib/client/i18n.js +1 -8
- package/lib/client/service-list-view.js +186 -0
- package/lib/client.js +1211 -616
- package/lib/host/config-schema.js +45 -0
- package/lib/host/config.js +80 -27
- package/lib/host/ledger-projection.js +223 -0
- package/lib/host/ownership.js +2 -1
- package/lib/host/process-inspector.js +174 -49
- package/lib/host/service-registry.js +5 -4
- package/lib/host/service-tool.js +18 -2
- package/lib/host/snapshot-cache.js +59 -0
- package/lib/index.js +157 -24
- package/lib/types/client/ServiceConsole.d.ts +20 -12
- package/lib/types/client/ServiceDockPill.d.ts +29 -0
- package/lib/types/client/ServiceListCard.d.ts +17 -0
- package/lib/types/client/api.d.ts +19 -0
- package/lib/types/client/dictionaries.d.ts +24 -0
- package/lib/types/client/i18n.d.ts +0 -2
- package/lib/types/client/index.d.ts +21 -10
- package/lib/types/client/service-list-view.d.ts +92 -0
- package/lib/types/host/config-schema.d.ts +52 -0
- package/lib/types/host/config.d.ts +27 -2
- package/lib/types/host/ledger-projection.d.ts +98 -0
- package/lib/types/host/process-inspector.d.ts +51 -2
- package/lib/types/host/service-registry.d.ts +1 -1
- package/lib/types/host/service-tool.d.ts +1 -1
- package/lib/types/host/snapshot-cache.d.ts +39 -0
- package/lib/types/host/types.d.ts +9 -0
- package/lib/types/index.d.ts +26 -1
- package/package.json +18 -7
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ Native package (recommended):
|
|
|
38
38
|
dsh plugin --profile web add -w @jiyr0119/dsh-service-console@latest
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
Then refresh the DSH web UI — a
|
|
41
|
+
Then refresh the DSH web UI — a `Services` entry appears in the conversation header and opens the console as a **right-Sidebar tab** (dock, float, resize, and per-session layout are the sidebar's).
|
|
42
42
|
|
|
43
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.
|
|
44
44
|
|
package/README.zh.md
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
dsh plugin --profile web add -w @jiyr0119/dsh-service-console@latest
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
安装后刷新 DSH Web UI——会话头部出现
|
|
43
|
+
安装后刷新 DSH Web UI——会话头部出现 `服务` 入口,点击把控制台作为**右侧栏 tab** 打开(停靠、浮动、拖宽、按会话记忆布局都由侧栏拥有)。
|
|
44
44
|
|
|
45
45
|
> 注意:插件被 dsh-market/awesome 收录 ≠ 浏览器自动出现 UI。本包同时提供 Host 路由与浏览器 bundle,`dsh plugin add` 后面板即可用。支持 macOS / Linux;Windows 暂不支持。
|
|
46
46
|
|
|
@@ -18,6 +18,12 @@ const ZH_DICT = {
|
|
|
18
18
|
"status.lastScan": "最近扫描",
|
|
19
19
|
"status.error": "扫描失败",
|
|
20
20
|
"svc.noSvc": "未发现服务",
|
|
21
|
+
"card.summary": "{count}/{total} 项服务",
|
|
22
|
+
"card.more": "还有 {n} 项…",
|
|
23
|
+
"card.confirm": "确认对 {name} 执行{action}?",
|
|
24
|
+
"svc.restartable": "可重启",
|
|
25
|
+
"dock.pill": "{n} 个会话服务",
|
|
26
|
+
"dock.open": "打开服务控制台",
|
|
21
27
|
"svc.ports": "端口",
|
|
22
28
|
"svc.pid": "pid",
|
|
23
29
|
"svc.command": "命令",
|
|
@@ -25,6 +31,7 @@ const ZH_DICT = {
|
|
|
25
31
|
"action.stop": "停止",
|
|
26
32
|
"action.restart": "重启",
|
|
27
33
|
"action.detail": "详情",
|
|
34
|
+
"action.open": "打开",
|
|
28
35
|
"action.confirm": "确认",
|
|
29
36
|
"action.cancel": "取消",
|
|
30
37
|
"action.pending": "处理中…",
|
|
@@ -39,6 +46,7 @@ const ZH_DICT = {
|
|
|
39
46
|
"own.other": "本机其他",
|
|
40
47
|
"own.unknown": "未知",
|
|
41
48
|
"own.protected": "受保护",
|
|
49
|
+
"scope.filter": "服务范围",
|
|
42
50
|
"scope.conversation": "本次对话",
|
|
43
51
|
"scope.workspace": "当前工作区",
|
|
44
52
|
"scope.machine": "本机",
|
|
@@ -60,6 +68,10 @@ const ZH_DICT = {
|
|
|
60
68
|
"err.PORT_CONFLICT": "端口仍被占用",
|
|
61
69
|
"err.START_TIMEOUT": "未在预期时间开始监听",
|
|
62
70
|
"err.FORBIDDEN_REMOTE": "非本机来源:只读(防止远程停本机进程)",
|
|
71
|
+
"err.SCAN_FAILED": "扫描失败:无法读取本机监听端口",
|
|
72
|
+
"err.BAD_REQUEST": "请求参数不合法",
|
|
73
|
+
"err.INTERNAL": "内部错误",
|
|
74
|
+
"err.SCAN_TIMEOUT": "扫描超时:系统命令未在时限内返回",
|
|
63
75
|
"tab.services": "服务",
|
|
64
76
|
"tab.settings": "设置",
|
|
65
77
|
"settings.title": "面板设置",
|
|
@@ -93,6 +105,12 @@ const EN_DICT = {
|
|
|
93
105
|
"status.lastScan": "Last scan",
|
|
94
106
|
"status.error": "Scan failed",
|
|
95
107
|
"svc.noSvc": "no services found",
|
|
108
|
+
"card.summary": "{count}/{total} services",
|
|
109
|
+
"card.more": "{n} more…",
|
|
110
|
+
"card.confirm": "Run {action} on {name}?",
|
|
111
|
+
"svc.restartable": "restartable",
|
|
112
|
+
"dock.pill": "{n} dev service(s)",
|
|
113
|
+
"dock.open": "Open the service console",
|
|
96
114
|
"svc.ports": "Ports",
|
|
97
115
|
"svc.pid": "pid",
|
|
98
116
|
"svc.command": "Command",
|
|
@@ -100,6 +118,7 @@ const EN_DICT = {
|
|
|
100
118
|
"action.stop": "Stop",
|
|
101
119
|
"action.restart": "Restart",
|
|
102
120
|
"action.detail": "Detail",
|
|
121
|
+
"action.open": "Open",
|
|
103
122
|
"action.confirm": "OK",
|
|
104
123
|
"action.cancel": "Cancel",
|
|
105
124
|
"action.pending": "Working…",
|
|
@@ -114,6 +133,7 @@ const EN_DICT = {
|
|
|
114
133
|
"own.other": "Other local",
|
|
115
134
|
"own.unknown": "Unknown",
|
|
116
135
|
"own.protected": "Protected",
|
|
136
|
+
"scope.filter": "Service scope",
|
|
117
137
|
"scope.conversation": "This chat",
|
|
118
138
|
"scope.workspace": "Workspace",
|
|
119
139
|
"scope.machine": "This machine",
|
|
@@ -135,6 +155,10 @@ const EN_DICT = {
|
|
|
135
155
|
"err.PORT_CONFLICT": "Port conflict",
|
|
136
156
|
"err.START_TIMEOUT": "Start timeout",
|
|
137
157
|
"err.FORBIDDEN_REMOTE": "Not a local caller — read-only",
|
|
158
|
+
"err.SCAN_FAILED": "Scan failed: cannot read local listeners",
|
|
159
|
+
"err.BAD_REQUEST": "Invalid request",
|
|
160
|
+
"err.INTERNAL": "Internal error",
|
|
161
|
+
"err.SCAN_TIMEOUT": "Scan timed out",
|
|
138
162
|
"tab.services": "Services",
|
|
139
163
|
"tab.settings": "Settings",
|
|
140
164
|
"settings.title": "Panel settings",
|
package/lib/client/i18n.js
CHANGED
|
@@ -47,11 +47,4 @@ function attachLocale(ctx, ns, dicts, onReady) {
|
|
|
47
47
|
onReady(bindTranslator(locale, ns));
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
|
|
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;
|
|
56
|
-
}
|
|
57
|
-
export { attachLocale, bindTranslator, errorText, registerDictionaries };
|
|
50
|
+
export { attachLocale, bindTranslator, registerDictionaries };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// src/client/service-list-view.ts
|
|
2
|
+
/** 卡片最多展示多少行(meta 由宿主限长,这里再兜一次,防止回放旧数据) */
|
|
3
|
+
const MAX_CARD_ROWS = 20;
|
|
4
|
+
/** 与 host/types.ts 的 Ownership 联合一致(运行时无从推导,靠单测对齐) */
|
|
5
|
+
const OWNERSHIP_LEVELS = [
|
|
6
|
+
"conversation-confirmed",
|
|
7
|
+
"workspace-inferred",
|
|
8
|
+
"other-local",
|
|
9
|
+
"unknown",
|
|
10
|
+
"protected"
|
|
11
|
+
];
|
|
12
|
+
/** 归属 → 主题色(两处 UI 共用,避免各写一份) */
|
|
13
|
+
const OWNERSHIP_COLOR = {
|
|
14
|
+
"conversation-confirmed": "var(--dsw-alias-state-success-primary, #4ade80)",
|
|
15
|
+
"workspace-inferred": "var(--dsw-alias-state-warn-primary, #fbbf24)",
|
|
16
|
+
"other-local": "var(--dsw-alias-label-secondary, #94a3b8)",
|
|
17
|
+
unknown: "var(--dsw-alias-state-error-primary, #f87171)",
|
|
18
|
+
protected: "var(--dsw-alias-state-error-primary, #f87171)"
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 归属徽标的 tone:统一 `neutral`。
|
|
22
|
+
*
|
|
23
|
+
* 平台 Tag 的语义色(success/warning/danger)在浅色主题下实测对比度不足
|
|
24
|
+
* (success 2.09:1 / warning 1.96:1 / danger 3.80:1,均低于 AA 4.5:1),
|
|
25
|
+
* 而 `neutral` 为 5.36:1。归属的细粒度语义由前面的彩色圆点承担(装饰性)。
|
|
26
|
+
*/
|
|
27
|
+
const OWNERSHIP_TONE = {
|
|
28
|
+
"conversation-confirmed": "neutral",
|
|
29
|
+
"workspace-inferred": "neutral",
|
|
30
|
+
"other-local": "neutral",
|
|
31
|
+
unknown: "neutral",
|
|
32
|
+
protected: "neutral"
|
|
33
|
+
};
|
|
34
|
+
/** 归属 → 词典键 */
|
|
35
|
+
const OWNERSHIP_KEY = {
|
|
36
|
+
"conversation-confirmed": "own.conversation",
|
|
37
|
+
"workspace-inferred": "own.workspace",
|
|
38
|
+
"other-local": "own.other",
|
|
39
|
+
unknown: "own.unknown",
|
|
40
|
+
protected: "own.protected"
|
|
41
|
+
};
|
|
42
|
+
/** API 字符串 → 归属级别(未知值降级 unknown,不炸 UI) */
|
|
43
|
+
function ownershipLevel(value) {
|
|
44
|
+
return OWNERSHIP_LEVELS.includes(value) ? value : "unknown";
|
|
45
|
+
}
|
|
46
|
+
function asRecord(value) {
|
|
47
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
48
|
+
}
|
|
49
|
+
function finiteNumber(value) {
|
|
50
|
+
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
51
|
+
}
|
|
52
|
+
function ownershipOf(value) {
|
|
53
|
+
return typeof value === "string" && OWNERSHIP_LEVELS.includes(value) ? value : "unknown";
|
|
54
|
+
}
|
|
55
|
+
/** 允许打开的主机名:只认本机回环(meta 可被篡改,不能让卡片变成钓鱼链接) */
|
|
56
|
+
const LOOPBACK_HOSTS = /* @__PURE__ */ new Set([
|
|
57
|
+
"localhost",
|
|
58
|
+
"127.0.0.1",
|
|
59
|
+
"::1",
|
|
60
|
+
"[::1]"
|
|
61
|
+
]);
|
|
62
|
+
/**
|
|
63
|
+
* 只接受 http(s) + 回环主机;其余(含 `javascript:`、`data:`、外部域名)一律 null。
|
|
64
|
+
* @param value meta 里的 url 字段(unknown)
|
|
65
|
+
*/
|
|
66
|
+
function safeServiceUrl(value) {
|
|
67
|
+
if (typeof value !== "string" || value === "" || value.length > 2048) return null;
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
parsed = new URL(value);
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
|
|
75
|
+
return LOOPBACK_HOSTS.has(parsed.hostname.toLowerCase()) ? value : null;
|
|
76
|
+
}
|
|
77
|
+
/** 单行投影:缺 id 的行直接丢弃(没有稳定 key 无法渲染,也无法操作) */
|
|
78
|
+
function projectRow(value) {
|
|
79
|
+
const raw = asRecord(value);
|
|
80
|
+
if (raw === null) return null;
|
|
81
|
+
const id = typeof raw.id === "string" ? raw.id : "";
|
|
82
|
+
if (id === "") return null;
|
|
83
|
+
const name = typeof raw.name === "string" && raw.name !== "" ? raw.name : id;
|
|
84
|
+
const url = safeServiceUrl(raw.url);
|
|
85
|
+
return {
|
|
86
|
+
id,
|
|
87
|
+
name: name.slice(0, 200),
|
|
88
|
+
ports: typeof raw.ports === "string" ? raw.ports.slice(0, 200) : "",
|
|
89
|
+
ownership: ownershipOf(raw.ownership),
|
|
90
|
+
protected: raw.protected === true,
|
|
91
|
+
restartable: raw.restartable === true,
|
|
92
|
+
url
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* `presentationMeta` → 卡片视图模型。
|
|
97
|
+
* @param meta 持久化的 meta(`unknown`:旧会话可能没有,或形状已变)
|
|
98
|
+
* @returns 可渲染模型;`null` 表示「没有可用 meta」,调用方应回退到纯文本内容
|
|
99
|
+
*/
|
|
100
|
+
function projectServiceListMeta(meta) {
|
|
101
|
+
const raw = asRecord(meta);
|
|
102
|
+
if (raw === null) return null;
|
|
103
|
+
const services = Object.hasOwn(raw, "services") && Array.isArray(raw.services) ? raw.services : null;
|
|
104
|
+
if (services === null) return null;
|
|
105
|
+
const rows = [];
|
|
106
|
+
for (const entry of services) {
|
|
107
|
+
if (rows.length >= 20) break;
|
|
108
|
+
const row = projectRow(entry);
|
|
109
|
+
if (row !== null) rows.push(row);
|
|
110
|
+
}
|
|
111
|
+
const total = finiteNumber(raw.total) ?? rows.length;
|
|
112
|
+
const count = finiteNumber(raw.count) ?? rows.length;
|
|
113
|
+
return {
|
|
114
|
+
scannedAt: finiteNumber(raw.scannedAt),
|
|
115
|
+
total: Math.max(total, rows.length),
|
|
116
|
+
count: Math.max(count, rows.length),
|
|
117
|
+
rows,
|
|
118
|
+
truncated: Math.max(Math.max(count, rows.length) - rows.length, 0)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** 端口去重后的一行摘要片段(最多 6 个,避免撑爆行宽);语言无关 */
|
|
122
|
+
function serviceListPorts(model) {
|
|
123
|
+
const ports = [];
|
|
124
|
+
for (const row of model.rows) {
|
|
125
|
+
for (const port of row.ports.split(",")) {
|
|
126
|
+
const p = port.trim();
|
|
127
|
+
if (p !== "" && !ports.includes(p)) ports.push(p);
|
|
128
|
+
if (ports.length >= 6) break;
|
|
129
|
+
}
|
|
130
|
+
if (ports.length >= 6) break;
|
|
131
|
+
}
|
|
132
|
+
return ports.length > 0 ? ":" + ports.join(" :") : "";
|
|
133
|
+
}
|
|
134
|
+
/** 行是否可执行生命周期操作(与面板同一判定:受保护目标只读) */
|
|
135
|
+
function canControlService(row) {
|
|
136
|
+
return !row.protected;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 从一次扫描快照里挑出「属于本会话」的服务。
|
|
140
|
+
* 归属判定在宿主完成(scan 带 sessionId 时按台账 sessionKey 收窄),
|
|
141
|
+
* 这里只做防御式读取:坏行丢弃,未知归属不计数。
|
|
142
|
+
* @param services 扫描接口的 `data.services`(不可信:可能缺失/坏形状)
|
|
143
|
+
*/
|
|
144
|
+
function selectSessionServices(services) {
|
|
145
|
+
if (!Array.isArray(services)) return [];
|
|
146
|
+
const rows = [];
|
|
147
|
+
for (const entry of services) {
|
|
148
|
+
const raw = asRecord(entry);
|
|
149
|
+
if (raw === null) continue;
|
|
150
|
+
const id = typeof raw.id === "string" ? raw.id : "";
|
|
151
|
+
if (id === "") continue;
|
|
152
|
+
if (!Object.hasOwn(raw, "ownership") || raw.ownership !== "conversation-confirmed") continue;
|
|
153
|
+
const ports = (Array.isArray(raw.listeners) ? raw.listeners : []).map((l) => {
|
|
154
|
+
const rec = asRecord(l);
|
|
155
|
+
return rec !== null && typeof rec.port === "number" && Number.isFinite(rec.port) ? String(rec.port) : "";
|
|
156
|
+
}).filter((p) => p !== "").join(", ");
|
|
157
|
+
rows.push({
|
|
158
|
+
id,
|
|
159
|
+
name: typeof raw.name === "string" && raw.name !== "" ? raw.name.slice(0, 200) : id,
|
|
160
|
+
ownership: "conversation-confirmed",
|
|
161
|
+
protected: raw.protected === true,
|
|
162
|
+
ports
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return rows;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 本会话服务摘要;`count === 0` 时 pill 不渲染。
|
|
169
|
+
* @param services `selectSessionServices` 的结果
|
|
170
|
+
*/
|
|
171
|
+
function summarizeSessionServices(services) {
|
|
172
|
+
const ports = [];
|
|
173
|
+
for (const row of services) {
|
|
174
|
+
for (const port of row.ports.split(",")) {
|
|
175
|
+
const p = port.trim();
|
|
176
|
+
if (p !== "" && !ports.includes(p)) ports.push(p);
|
|
177
|
+
if (ports.length >= 4) break;
|
|
178
|
+
}
|
|
179
|
+
if (ports.length >= 4) break;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
count: services.length,
|
|
183
|
+
ports: ports.length > 0 ? ":" + ports.join(" :") : ""
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
export { MAX_CARD_ROWS, OWNERSHIP_COLOR, OWNERSHIP_KEY, OWNERSHIP_TONE, canControlService, ownershipLevel, projectServiceListMeta, safeServiceUrl, selectSessionServices, serviceListPorts, summarizeSessionServices };
|