@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/lib/client.js
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@jiyr0119/dsh-service-console",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
module.exports;
|
|
6
|
+
//#region \0rolldown/runtime.js
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
//#endregion
|
|
28
|
+
let react = require("react");
|
|
29
|
+
react = __toESM(react, 1);
|
|
30
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
//#region \0dsh-css:/Users/jonathan/workspaceforme/dsh-service-console/src/client/service-console.module.css.mjs
|
|
32
|
+
const css = ".citwcW_panel{z-index:9999;background:var(--dsw-alias-bg-overlay,#262626);width:540px;max-height:min(640px,100dvh - 110px);color:var(--dsw-alias-label-primary,#eee);border:1px solid var(--dsw-alias-border-l1,#444);pointer-events:auto;border-radius:10px;padding:12px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;position:fixed;top:72px;right:20px;overflow:auto;box-shadow:0 8px 32px #00000059}.citwcW_header{flex-wrap:wrap;align-items:center;gap:6px;margin-bottom:6px;display:flex}.citwcW_row{border-bottom:1px solid var(--dsw-alias-border-l1,#333);padding:8px 0}.citwcW_rowMain{flex-wrap:wrap;align-items:center;gap:6px;display:flex}.citwcW_name{font-weight:600}.citwcW_muted{color:var(--dsw-alias-label-secondary,#999)}.citwcW_ok{color:var(--dsw-alias-state-success-primary,#4ade80)}.citwcW_err{color:var(--dsw-alias-state-error-primary,#f87171)}.citwcW_warn{color:var(--dsw-alias-state-warn-primary,#fbbf24)}.citwcW_btn{cursor:pointer;border:1px solid var(--dsw-alias-border-l1,#555);background:var(--dsw-alias-bg-layer-1,#333);color:var(--dsw-alias-label-primary,#eee);border-radius:4px;margin-left:6px;padding:1px 6px;font-family:inherit;font-size:11px;text-decoration:none}.citwcW_badge{border:1px solid;border-radius:4px;padding:0 5px;font-size:10px}.citwcW_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);border-radius:4px;padding:2px 6px;font-family:inherit;font-size:11px}.citwcW_search{box-sizing:border-box;width:100%;margin-bottom:6px}.citwcW_spacer{flex:1}.citwcW_configBox{background:var(--dsw-alias-bg-layer-1,#333);border-radius:6px;margin-bottom:8px;padding:8px}.citwcW_configRow{align-items:center;gap:6px;margin-top:4px;display:flex}.citwcW_confirmRow{margin-top:4px}.citwcW_detailBox{background:var(--dsw-alias-bg-layer-1,#333);border-radius:6px;margin-top:4px;padding:6px}.citwcW_entry{border:1px solid var(--dsw-alias-border-l2);min-width:111px;height:32px;color:var(--dsw-alias-label-primary);font-family:var(--dsw-font-family);cursor:pointer;background:0 0;border-radius:18px;justify-content:center;align-items:center;gap:4px;padding:6px 12px;font-size:13px;font-weight:400;line-height:20px;display:inline-flex}.citwcW_entry:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}.citwcW_entryLabel,.citwcW_entryIcon{white-space:nowrap;flex:none}";
|
|
33
|
+
const tagId = "@jiyr0119/dsh-service-console/service-console.module.css";
|
|
34
|
+
if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
|
|
35
|
+
const tag = document.createElement("style");
|
|
36
|
+
tag.dataset.plugin = "@jiyr0119/dsh-service-console";
|
|
37
|
+
tag.dataset.pluginCss = tagId;
|
|
38
|
+
tag.textContent = css;
|
|
39
|
+
document.head.appendChild(tag);
|
|
40
|
+
}
|
|
41
|
+
var service_console_module_css_default = {
|
|
42
|
+
"spacer": "citwcW_spacer",
|
|
43
|
+
"err": "citwcW_err",
|
|
44
|
+
"rowMain": "citwcW_rowMain",
|
|
45
|
+
"entry": "citwcW_entry",
|
|
46
|
+
"entryIcon": "citwcW_entryIcon",
|
|
47
|
+
"row": "citwcW_row",
|
|
48
|
+
"entryLabel": "citwcW_entryLabel",
|
|
49
|
+
"detailBox": "citwcW_detailBox",
|
|
50
|
+
"name": "citwcW_name",
|
|
51
|
+
"warn": "citwcW_warn",
|
|
52
|
+
"configBox": "citwcW_configBox",
|
|
53
|
+
"input": "citwcW_input",
|
|
54
|
+
"panel": "citwcW_panel",
|
|
55
|
+
"ok": "citwcW_ok",
|
|
56
|
+
"btn": "citwcW_btn",
|
|
57
|
+
"header": "citwcW_header",
|
|
58
|
+
"confirmRow": "citwcW_confirmRow",
|
|
59
|
+
"muted": "citwcW_muted",
|
|
60
|
+
"configRow": "citwcW_configRow",
|
|
61
|
+
"badge": "citwcW_badge",
|
|
62
|
+
"search": "citwcW_search"
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/client/ServiceConsole.tsx
|
|
66
|
+
let timerCtx = null;
|
|
67
|
+
function bindTimer(t) {
|
|
68
|
+
timerCtx = t;
|
|
69
|
+
}
|
|
70
|
+
async function api(path, payload) {
|
|
71
|
+
const response = await fetch("/dsh-sc/api/" + path, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { "content-type": "application/json" },
|
|
74
|
+
body: JSON.stringify(payload)
|
|
75
|
+
});
|
|
76
|
+
const text = await response.text().catch(() => "");
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(text || "{}");
|
|
79
|
+
} catch {
|
|
80
|
+
throw new Error("bad JSON response HTTP " + response.status);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const store = {
|
|
84
|
+
open: false,
|
|
85
|
+
listeners: /* @__PURE__ */ new Set()
|
|
86
|
+
};
|
|
87
|
+
function subscribe(fn) {
|
|
88
|
+
store.listeners.add(fn);
|
|
89
|
+
return () => store.listeners.delete(fn);
|
|
90
|
+
}
|
|
91
|
+
function setOpen(v) {
|
|
92
|
+
store.open = v;
|
|
93
|
+
store.listeners.forEach((l) => l(v));
|
|
94
|
+
}
|
|
95
|
+
const OWNERSHIP = {
|
|
96
|
+
"conversation-confirmed": {
|
|
97
|
+
zh: "本次对话",
|
|
98
|
+
en: "This chat",
|
|
99
|
+
color: "var(--dsw-alias-state-success-primary, #4ade80)"
|
|
100
|
+
},
|
|
101
|
+
"workspace-inferred": {
|
|
102
|
+
zh: "工作区推断",
|
|
103
|
+
en: "Workspace",
|
|
104
|
+
color: "var(--dsw-alias-state-warn-primary, #fbbf24)"
|
|
105
|
+
},
|
|
106
|
+
"other-local": {
|
|
107
|
+
zh: "本机其他",
|
|
108
|
+
en: "Other local",
|
|
109
|
+
color: "var(--dsw-alias-label-secondary, #94a3b8)"
|
|
110
|
+
},
|
|
111
|
+
unknown: {
|
|
112
|
+
zh: "未知",
|
|
113
|
+
en: "Unknown",
|
|
114
|
+
color: "var(--dsw-alias-state-error-primary, #f87171)"
|
|
115
|
+
},
|
|
116
|
+
protected: {
|
|
117
|
+
zh: "受保护",
|
|
118
|
+
en: "Protected",
|
|
119
|
+
color: "var(--dsw-alias-state-error-primary, #f87171)"
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const ERROR_LABEL = {
|
|
123
|
+
PERMISSION_DENIED: ["没有权限读取或控制该服务", "No permission"],
|
|
124
|
+
TARGET_GONE: ["该服务已结束", "Service gone"],
|
|
125
|
+
PID_REUSED: ["进程身份已变化,已取消操作", "PID reused"],
|
|
126
|
+
UNKNOWN_OWNERSHIP: ["无法确认来源,不允许控制", "Unknown ownership"],
|
|
127
|
+
PROTECTED_PROCESS: ["受保护进程,不能操作", "Protected process"],
|
|
128
|
+
GRACEFUL_TIMEOUT: ["未在等待时间内退出", "Graceful timeout"],
|
|
129
|
+
RESTART_UNSAFE: ["缺少安全启动信息,不能重启", "Cannot restart safely"],
|
|
130
|
+
PORT_CONFLICT: ["端口仍被占用", "Port conflict"],
|
|
131
|
+
START_TIMEOUT: ["未在预期时间开始监听", "Start timeout"]
|
|
132
|
+
};
|
|
133
|
+
const TEXTS = {
|
|
134
|
+
zh: {
|
|
135
|
+
title: "Service Console",
|
|
136
|
+
search: "搜索服务/端口/路径…",
|
|
137
|
+
scopeConv: "本次对话",
|
|
138
|
+
scopeWs: "工作区",
|
|
139
|
+
scopeMachine: "本机",
|
|
140
|
+
auto: "5s",
|
|
141
|
+
config: "配置",
|
|
142
|
+
close: "关闭",
|
|
143
|
+
noSvc: "未发现服务",
|
|
144
|
+
stop: "停止",
|
|
145
|
+
restart: "重启",
|
|
146
|
+
detail: "详情",
|
|
147
|
+
confirmStop: "确认停止?",
|
|
148
|
+
confirmRestart: "确认重启?",
|
|
149
|
+
confirmTxt: "确认对 {name} (pid {pid}) 执行{action}?",
|
|
150
|
+
ok: "确认",
|
|
151
|
+
cancel: "取消",
|
|
152
|
+
stopped: "已停止",
|
|
153
|
+
restarted: "已重启",
|
|
154
|
+
evidence: "归属证据",
|
|
155
|
+
refreshInterval: "自动刷新间隔(ms)",
|
|
156
|
+
gracefulTimeout: "优雅超时(ms)",
|
|
157
|
+
forceKill: "允许强制终止"
|
|
158
|
+
},
|
|
159
|
+
en: {
|
|
160
|
+
title: "Service Console",
|
|
161
|
+
search: "Search services/ports/paths…",
|
|
162
|
+
scopeConv: "This chat",
|
|
163
|
+
scopeWs: "Workspace",
|
|
164
|
+
scopeMachine: "This Mac",
|
|
165
|
+
auto: "5s",
|
|
166
|
+
config: "Config",
|
|
167
|
+
close: "Close",
|
|
168
|
+
noSvc: "no services found",
|
|
169
|
+
stop: "Stop",
|
|
170
|
+
restart: "Restart",
|
|
171
|
+
detail: "Detail",
|
|
172
|
+
confirmStop: "Confirm stop?",
|
|
173
|
+
confirmRestart: "Confirm restart?",
|
|
174
|
+
confirmTxt: "Run {action} on {name} (pid {pid})?",
|
|
175
|
+
ok: "OK",
|
|
176
|
+
cancel: "Cancel",
|
|
177
|
+
stopped: "Stopped",
|
|
178
|
+
restarted: "Restarted",
|
|
179
|
+
evidence: "Ownership evidence",
|
|
180
|
+
refreshInterval: "Refresh interval (ms)",
|
|
181
|
+
gracefulTimeout: "Graceful timeout (ms)",
|
|
182
|
+
forceKill: "Allow force kill"
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
function ServiceConsoleEntry() {
|
|
186
|
+
const [open, setLocal] = react.useState(store.open);
|
|
187
|
+
react.useEffect(() => subscribe(setLocal), []);
|
|
188
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
189
|
+
className: service_console_module_css_default.entry,
|
|
190
|
+
onClick: () => setOpen(!store.open),
|
|
191
|
+
title: "Service Console",
|
|
192
|
+
"aria-label": "Service Console",
|
|
193
|
+
children: [
|
|
194
|
+
open ? "✕" : null,
|
|
195
|
+
!open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
196
|
+
className: service_console_module_css_default.entryLabel,
|
|
197
|
+
children: "Services"
|
|
198
|
+
}) : null,
|
|
199
|
+
!open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
200
|
+
className: service_console_module_css_default.entryIcon,
|
|
201
|
+
children: "🖥"
|
|
202
|
+
}) : null
|
|
203
|
+
]
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function ServiceConsolePanel() {
|
|
207
|
+
const [open, setLocal] = react.useState(store.open);
|
|
208
|
+
const [lang, setLang] = react.useState("zh");
|
|
209
|
+
const [scope, setScope] = react.useState("workspace");
|
|
210
|
+
const [query, setQuery] = react.useState("");
|
|
211
|
+
const [showConfig, setShowConfig] = react.useState(false);
|
|
212
|
+
const [configData, setConfigData] = react.useState(null);
|
|
213
|
+
const [view, setView] = react.useState({
|
|
214
|
+
phase: "idle",
|
|
215
|
+
at: null,
|
|
216
|
+
data: null,
|
|
217
|
+
err: null
|
|
218
|
+
});
|
|
219
|
+
const [confirming, setConfirming] = react.useState(null);
|
|
220
|
+
const [opResult, setOpResult] = react.useState(null);
|
|
221
|
+
const [expanded, setExpanded] = react.useState(null);
|
|
222
|
+
const [autoRefresh, setAutoRefresh] = react.useState(true);
|
|
223
|
+
const timeoutRef = react.useRef(null);
|
|
224
|
+
const intervalRef = react.useRef(null);
|
|
225
|
+
react.useEffect(() => subscribe(setLocal), []);
|
|
226
|
+
react.useEffect(() => () => {
|
|
227
|
+
timeoutRef.current?.();
|
|
228
|
+
intervalRef.current?.();
|
|
229
|
+
}, []);
|
|
230
|
+
const T = TEXTS[lang];
|
|
231
|
+
const scan = react.useCallback(() => {
|
|
232
|
+
const at = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
233
|
+
setView((v) => ({
|
|
234
|
+
phase: "scanning",
|
|
235
|
+
at,
|
|
236
|
+
data: v.data,
|
|
237
|
+
err: null
|
|
238
|
+
}));
|
|
239
|
+
timeoutRef.current?.();
|
|
240
|
+
timeoutRef.current = timerCtx?.timeout(() => {
|
|
241
|
+
setView((v) => v.phase === "scanning" ? {
|
|
242
|
+
phase: "timeout",
|
|
243
|
+
at,
|
|
244
|
+
data: v.data,
|
|
245
|
+
err: "timeout"
|
|
246
|
+
} : v);
|
|
247
|
+
}, 8e3) ?? null;
|
|
248
|
+
api("services/scan", {}).then((res) => {
|
|
249
|
+
timeoutRef.current?.();
|
|
250
|
+
timeoutRef.current = null;
|
|
251
|
+
setView({
|
|
252
|
+
phase: "done",
|
|
253
|
+
at,
|
|
254
|
+
data: res?.data ?? null,
|
|
255
|
+
err: null
|
|
256
|
+
});
|
|
257
|
+
}).catch((e) => {
|
|
258
|
+
timeoutRef.current?.();
|
|
259
|
+
timeoutRef.current = null;
|
|
260
|
+
setView({
|
|
261
|
+
phase: "error",
|
|
262
|
+
at,
|
|
263
|
+
data: null,
|
|
264
|
+
err: String(e?.message || e)
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
}, []);
|
|
268
|
+
const loadConfig = react.useCallback(() => {
|
|
269
|
+
api("config", {}).then((res) => setConfigData(res?.data?.config ?? null)).catch(() => setConfigData(null));
|
|
270
|
+
}, []);
|
|
271
|
+
react.useEffect(() => {
|
|
272
|
+
if (open && view.phase === "idle") scan();
|
|
273
|
+
if (open && autoRefresh) {
|
|
274
|
+
intervalRef.current = timerCtx?.interval(() => scan(), 5e3) ?? null;
|
|
275
|
+
return () => {
|
|
276
|
+
intervalRef.current?.();
|
|
277
|
+
intervalRef.current = null;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}, [
|
|
281
|
+
open,
|
|
282
|
+
autoRefresh,
|
|
283
|
+
scan,
|
|
284
|
+
view.phase
|
|
285
|
+
]);
|
|
286
|
+
if (!open) return null;
|
|
287
|
+
const runAction = (svc, action) => {
|
|
288
|
+
setConfirming({
|
|
289
|
+
id: svc.id,
|
|
290
|
+
action
|
|
291
|
+
});
|
|
292
|
+
setOpResult(null);
|
|
293
|
+
};
|
|
294
|
+
const confirmAction = (svc, action) => {
|
|
295
|
+
setConfirming(null);
|
|
296
|
+
api("services/" + action, { serviceId: svc.id }).then((res) => {
|
|
297
|
+
if (res?.ok) setOpResult({
|
|
298
|
+
id: svc.id,
|
|
299
|
+
ok: true,
|
|
300
|
+
text: action === "stop" ? T.stopped : T.restarted
|
|
301
|
+
});
|
|
302
|
+
else {
|
|
303
|
+
const code = res?.error?.code ?? "";
|
|
304
|
+
const msg = res?.error?.message ?? "";
|
|
305
|
+
setOpResult({
|
|
306
|
+
id: svc.id,
|
|
307
|
+
ok: false,
|
|
308
|
+
text: ERROR_LABEL[code] ? ERROR_LABEL[code][lang === "zh" ? 0 : 1] : msg || "ERR"
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
scan();
|
|
312
|
+
}).catch(() => setOpResult({
|
|
313
|
+
id: svc.id,
|
|
314
|
+
ok: false,
|
|
315
|
+
text: "RPC error"
|
|
316
|
+
}));
|
|
317
|
+
};
|
|
318
|
+
const setConfig = (patch) => {
|
|
319
|
+
api("config", {
|
|
320
|
+
action: "update",
|
|
321
|
+
patch
|
|
322
|
+
}).then((res) => {
|
|
323
|
+
if (res?.data) setConfigData(res.data.config);
|
|
324
|
+
}).catch(() => void 0);
|
|
325
|
+
};
|
|
326
|
+
let rows = view.data?.services ?? [];
|
|
327
|
+
if (scope === "conversation") rows = rows.filter((s) => s.ownership === "conversation-confirmed");
|
|
328
|
+
else if (scope === "workspace") rows = rows.filter((s) => s.ownership === "conversation-confirmed" || s.ownership === "workspace-inferred");
|
|
329
|
+
if (query) {
|
|
330
|
+
const q = String(query).toLowerCase();
|
|
331
|
+
rows = rows.filter((s) => 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));
|
|
332
|
+
}
|
|
333
|
+
const status = view.phase === "scanning" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
334
|
+
className: service_console_module_css_default.warn,
|
|
335
|
+
children: ["⏳ ", view.at]
|
|
336
|
+
}) : view.phase === "done" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
337
|
+
className: service_console_module_css_default.ok,
|
|
338
|
+
children: [
|
|
339
|
+
"✅ ",
|
|
340
|
+
view.at,
|
|
341
|
+
" · ",
|
|
342
|
+
String(view.data?.count ?? 0),
|
|
343
|
+
" · ledger=",
|
|
344
|
+
String(view.data?.ledgerCount ?? 0)
|
|
345
|
+
]
|
|
346
|
+
}) : view.phase === "error" || view.phase === "timeout" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
347
|
+
className: service_console_module_css_default.err,
|
|
348
|
+
children: ["⛔ ", view.err]
|
|
349
|
+
}) : null;
|
|
350
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
351
|
+
className: service_console_module_css_default.panel,
|
|
352
|
+
children: [
|
|
353
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
354
|
+
className: service_console_module_css_default.header,
|
|
355
|
+
children: [
|
|
356
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: T.title }),
|
|
357
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
358
|
+
className: service_console_module_css_default.input,
|
|
359
|
+
value: scope,
|
|
360
|
+
onChange: (e) => setScope(e.target.value),
|
|
361
|
+
children: [
|
|
362
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
363
|
+
value: "conversation",
|
|
364
|
+
children: T.scopeConv
|
|
365
|
+
}),
|
|
366
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
367
|
+
value: "workspace",
|
|
368
|
+
children: T.scopeWs
|
|
369
|
+
}),
|
|
370
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
371
|
+
value: "machine",
|
|
372
|
+
children: T.scopeMachine
|
|
373
|
+
})
|
|
374
|
+
]
|
|
375
|
+
}),
|
|
376
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
377
|
+
className: service_console_module_css_default.btn,
|
|
378
|
+
onClick: () => setLang(lang === "zh" ? "en" : "zh"),
|
|
379
|
+
children: lang === "zh" ? "EN" : "中"
|
|
380
|
+
}),
|
|
381
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
382
|
+
className: service_console_module_css_default.btn,
|
|
383
|
+
onClick: () => {
|
|
384
|
+
setShowConfig(!showConfig);
|
|
385
|
+
if (!showConfig) loadConfig();
|
|
386
|
+
},
|
|
387
|
+
children: T.config
|
|
388
|
+
}),
|
|
389
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: service_console_module_css_default.spacer }),
|
|
390
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
391
|
+
className: service_console_module_css_default.muted,
|
|
392
|
+
children: [
|
|
393
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
394
|
+
type: "checkbox",
|
|
395
|
+
checked: autoRefresh,
|
|
396
|
+
onChange: (e) => setAutoRefresh(e.target.checked)
|
|
397
|
+
}),
|
|
398
|
+
" ",
|
|
399
|
+
T.auto
|
|
400
|
+
]
|
|
401
|
+
}),
|
|
402
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
403
|
+
className: service_console_module_css_default.btn,
|
|
404
|
+
onClick: scan,
|
|
405
|
+
children: "↻"
|
|
406
|
+
}),
|
|
407
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
408
|
+
className: service_console_module_css_default.btn,
|
|
409
|
+
onClick: () => setOpen(false),
|
|
410
|
+
children: T.close
|
|
411
|
+
})
|
|
412
|
+
]
|
|
413
|
+
}),
|
|
414
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
415
|
+
className: `${service_console_module_css_default.input} ${service_console_module_css_default.search}`,
|
|
416
|
+
placeholder: T.search,
|
|
417
|
+
value: query,
|
|
418
|
+
onChange: (e) => setQuery(e.target.value)
|
|
419
|
+
}),
|
|
420
|
+
showConfig && configData ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
421
|
+
className: service_console_module_css_default.configBox,
|
|
422
|
+
children: [
|
|
423
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
424
|
+
className: service_console_module_css_default.configRow,
|
|
425
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
426
|
+
className: service_console_module_css_default.muted,
|
|
427
|
+
children: T.refreshInterval
|
|
428
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
429
|
+
className: service_console_module_css_default.input,
|
|
430
|
+
type: "number",
|
|
431
|
+
defaultValue: configData.refreshInterval,
|
|
432
|
+
onBlur: (e) => setConfig({ refreshInterval: parseInt(e.target.value, 10) })
|
|
433
|
+
})]
|
|
434
|
+
}),
|
|
435
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
436
|
+
className: service_console_module_css_default.configRow,
|
|
437
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
438
|
+
className: service_console_module_css_default.muted,
|
|
439
|
+
children: T.gracefulTimeout
|
|
440
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
441
|
+
className: service_console_module_css_default.input,
|
|
442
|
+
type: "number",
|
|
443
|
+
defaultValue: configData.gracefulTimeout,
|
|
444
|
+
onBlur: (e) => setConfig({ gracefulTimeout: parseInt(e.target.value, 10) })
|
|
445
|
+
})]
|
|
446
|
+
}),
|
|
447
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
448
|
+
className: service_console_module_css_default.configRow,
|
|
449
|
+
children: [
|
|
450
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
451
|
+
type: "checkbox",
|
|
452
|
+
checked: !!configData.forceKill,
|
|
453
|
+
onChange: (e) => setConfig({ forceKill: e.target.checked })
|
|
454
|
+
}),
|
|
455
|
+
" ",
|
|
456
|
+
T.forceKill
|
|
457
|
+
]
|
|
458
|
+
})
|
|
459
|
+
]
|
|
460
|
+
}) : null,
|
|
461
|
+
status,
|
|
462
|
+
(view.data?.partialWarnings ?? []).map((w, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
463
|
+
className: service_console_module_css_default.warn,
|
|
464
|
+
children: ["⚠ ", w]
|
|
465
|
+
}, `w${i}`)),
|
|
466
|
+
rows.length === 0 && view.phase === "done" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
467
|
+
className: service_console_module_css_default.muted,
|
|
468
|
+
children: T.noSvc
|
|
469
|
+
}) : rows.map((svc) => {
|
|
470
|
+
const badge = OWNERSHIP[svc.ownership] ?? OWNERSHIP.unknown;
|
|
471
|
+
const ports = svc.listeners.map((l) => String(l.port)).join(", ");
|
|
472
|
+
const url = svc.listeners.map((l) => l.url).filter(Boolean)[0] ?? null;
|
|
473
|
+
const canControl = svc.ownership === "conversation-confirmed" || svc.ownership === "workspace-inferred" || svc.ownership === "other-local";
|
|
474
|
+
const isConfirming = confirming?.id === svc.id;
|
|
475
|
+
const result = opResult?.id === svc.id ? opResult : null;
|
|
476
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
477
|
+
className: service_console_module_css_default.row,
|
|
478
|
+
children: [
|
|
479
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
480
|
+
className: service_console_module_css_default.rowMain,
|
|
481
|
+
children: [
|
|
482
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
483
|
+
className: service_console_module_css_default.ok,
|
|
484
|
+
children: "●"
|
|
485
|
+
}),
|
|
486
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
487
|
+
className: service_console_module_css_default.name,
|
|
488
|
+
children: svc.name
|
|
489
|
+
}),
|
|
490
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
491
|
+
className: service_console_module_css_default.muted,
|
|
492
|
+
children: [
|
|
493
|
+
":",
|
|
494
|
+
ports,
|
|
495
|
+
" · pid ",
|
|
496
|
+
String(svc.pid)
|
|
497
|
+
]
|
|
498
|
+
}),
|
|
499
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
500
|
+
className: service_console_module_css_default.badge,
|
|
501
|
+
style: { color: badge.color },
|
|
502
|
+
children: lang === "zh" ? badge.zh : badge.en
|
|
503
|
+
}),
|
|
504
|
+
svc.restartable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
505
|
+
className: service_console_module_css_default.badge,
|
|
506
|
+
style: { color: "var(--dsw-alias-state-success-primary, #4ade80)" },
|
|
507
|
+
children: "↻"
|
|
508
|
+
}) : null,
|
|
509
|
+
url ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
510
|
+
className: service_console_module_css_default.btn,
|
|
511
|
+
href: url,
|
|
512
|
+
target: "_blank",
|
|
513
|
+
rel: "noreferrer",
|
|
514
|
+
children: "🔗"
|
|
515
|
+
}) : null,
|
|
516
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: service_console_module_css_default.spacer }),
|
|
517
|
+
canControl ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
518
|
+
className: service_console_module_css_default.btn,
|
|
519
|
+
onClick: () => runAction(svc, "stop"),
|
|
520
|
+
children: isConfirming && confirming.action === "stop" ? T.confirmStop : T.stop
|
|
521
|
+
}) : null,
|
|
522
|
+
svc.restartable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
523
|
+
className: service_console_module_css_default.btn,
|
|
524
|
+
onClick: () => runAction(svc, "restart"),
|
|
525
|
+
children: isConfirming && confirming.action === "restart" ? T.confirmRestart : T.restart
|
|
526
|
+
}) : null,
|
|
527
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
528
|
+
className: service_console_module_css_default.btn,
|
|
529
|
+
onClick: () => setExpanded(expanded === svc.id ? null : svc.id),
|
|
530
|
+
children: expanded === svc.id ? "▾" : T.detail
|
|
531
|
+
})
|
|
532
|
+
]
|
|
533
|
+
}),
|
|
534
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
535
|
+
className: service_console_module_css_default.muted,
|
|
536
|
+
children: (svc.commandSummary ? svc.commandSummary.slice(0, 100) : "(?)") + (svc.commandSummary && svc.commandSummary.length > 100 ? "…" : "")
|
|
537
|
+
}),
|
|
538
|
+
svc.cwd ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
539
|
+
className: service_console_module_css_default.muted,
|
|
540
|
+
children: svc.cwd
|
|
541
|
+
}) : null,
|
|
542
|
+
result ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
543
|
+
className: result.ok ? service_console_module_css_default.ok : service_console_module_css_default.err,
|
|
544
|
+
children: [result.ok ? "✅ " : "⛔ ", result.text]
|
|
545
|
+
}) : null,
|
|
546
|
+
isConfirming ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
547
|
+
className: service_console_module_css_default.confirmRow,
|
|
548
|
+
children: [
|
|
549
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
550
|
+
className: service_console_module_css_default.muted,
|
|
551
|
+
children: [T.confirmTxt.replace("{name}", svc.name).replace("{pid}", String(svc.pid)).replace("{action}", confirming.action === "stop" ? T.stop : T.restart), " "]
|
|
552
|
+
}),
|
|
553
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
554
|
+
className: service_console_module_css_default.btn,
|
|
555
|
+
style: { color: "var(--dsw-alias-state-error-primary, #f87171)" },
|
|
556
|
+
onClick: () => confirmAction(svc, confirming.action),
|
|
557
|
+
children: T.ok
|
|
558
|
+
}),
|
|
559
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
560
|
+
className: service_console_module_css_default.btn,
|
|
561
|
+
onClick: () => setConfirming(null),
|
|
562
|
+
children: T.cancel
|
|
563
|
+
})
|
|
564
|
+
]
|
|
565
|
+
}) : null,
|
|
566
|
+
expanded === svc.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
567
|
+
className: service_console_module_css_default.detailBox,
|
|
568
|
+
children: [
|
|
569
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
570
|
+
className: service_console_module_css_default.muted,
|
|
571
|
+
children: ["id: ", svc.id]
|
|
572
|
+
}),
|
|
573
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
574
|
+
className: service_console_module_css_default.muted,
|
|
575
|
+
children: [
|
|
576
|
+
"pgid: ",
|
|
577
|
+
String(svc.processGroupId ?? "-"),
|
|
578
|
+
" · ppid: ",
|
|
579
|
+
String(svc.parentPid ?? "-"),
|
|
580
|
+
" · startedAt: ",
|
|
581
|
+
String(svc.startedAt ?? "-")
|
|
582
|
+
]
|
|
583
|
+
}),
|
|
584
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
585
|
+
className: service_console_module_css_default.muted,
|
|
586
|
+
children: [T.evidence, ":"]
|
|
587
|
+
}),
|
|
588
|
+
svc.ownershipEvidence.map((ev, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
589
|
+
className: service_console_module_css_default.muted,
|
|
590
|
+
children: [" · ", ev]
|
|
591
|
+
}, i))
|
|
592
|
+
]
|
|
593
|
+
}) : null
|
|
594
|
+
]
|
|
595
|
+
}, svc.id);
|
|
596
|
+
})
|
|
597
|
+
]
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
601
|
+
module.exports = {
|
|
602
|
+
inject: ["slots", "timer"],
|
|
603
|
+
apply(ctx) {
|
|
604
|
+
bindTimer(ctx.timer);
|
|
605
|
+
const slots = ctx.get("slots");
|
|
606
|
+
if (slots === void 0) return;
|
|
607
|
+
slots.inject("conversation.session.header.utilities", () => slots.register({
|
|
608
|
+
name: "conversation.session.header.utilities",
|
|
609
|
+
id: "sc-entry"
|
|
610
|
+
}, () => react.createElement(ServiceConsoleEntry)));
|
|
611
|
+
slots.inject("shell.overlay", () => slots.register({
|
|
612
|
+
name: "shell.overlay",
|
|
613
|
+
id: "sc-panel"
|
|
614
|
+
}, () => react.createElement(ServiceConsolePanel)));
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
return module.exports;
|
|
618
|
+
}
|
|
619
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
//#region src/host/config.ts
|
|
5
|
+
const DEFAULT_CONFIG = {
|
|
6
|
+
refreshInterval: 5e3,
|
|
7
|
+
defaultScope: "workspace",
|
|
8
|
+
gracefulTimeout: 3e3,
|
|
9
|
+
showUnknown: true,
|
|
10
|
+
forceKill: false,
|
|
11
|
+
autoCleanup: false
|
|
12
|
+
};
|
|
13
|
+
const CONFIG_LIMITS = {
|
|
14
|
+
refreshInterval: [2e3, 3e4],
|
|
15
|
+
gracefulTimeout: [1e3, 15e3]
|
|
16
|
+
};
|
|
17
|
+
function configFilePath() {
|
|
18
|
+
return join(homedir(), ".dsh", "plugins", "dsh-service-console", "config.json");
|
|
19
|
+
}
|
|
20
|
+
function loadConfigFromFile() {
|
|
21
|
+
try {
|
|
22
|
+
const file = configFilePath();
|
|
23
|
+
if (!existsSync(file)) return { ...DEFAULT_CONFIG };
|
|
24
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
25
|
+
return {
|
|
26
|
+
...DEFAULT_CONFIG,
|
|
27
|
+
...parsed
|
|
28
|
+
};
|
|
29
|
+
} catch {
|
|
30
|
+
return { ...DEFAULT_CONFIG };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function saveConfigToFile(config) {
|
|
34
|
+
try {
|
|
35
|
+
const file = configFilePath();
|
|
36
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
37
|
+
writeFileSync(file, JSON.stringify(config, null, 2), "utf8");
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
40
|
+
function validateConfigPatch(patch) {
|
|
41
|
+
const next = {};
|
|
42
|
+
for (const key of Object.keys(patch)) {
|
|
43
|
+
if (!(key in DEFAULT_CONFIG)) return {
|
|
44
|
+
ok: false,
|
|
45
|
+
message: "unknown config key: " + key
|
|
46
|
+
};
|
|
47
|
+
const v = patch[key];
|
|
48
|
+
if (typeof v === "boolean") {
|
|
49
|
+
next[key] = v;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (typeof v === "number" && CONFIG_LIMITS[key]) {
|
|
53
|
+
if (v < CONFIG_LIMITS[key][0] || v > CONFIG_LIMITS[key][1]) return {
|
|
54
|
+
ok: false,
|
|
55
|
+
message: "config out of range: " + key
|
|
56
|
+
};
|
|
57
|
+
next[key] = v;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (key === "defaultScope" && (v === "conversation" || v === "workspace" || v === "machine")) {
|
|
61
|
+
next.defaultScope = v;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
ok: false,
|
|
66
|
+
message: "invalid value for: " + key
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
ok: true,
|
|
71
|
+
next
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { CONFIG_LIMITS, DEFAULT_CONFIG, loadConfigFromFile, saveConfigToFile, validateConfigPatch };
|