@jiyr0119/dsh-service-console 0.7.2 → 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 +3 -2
- package/lib/client/i18n.js +37 -71
- package/lib/client.js +188 -162
- 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 +35 -40
- 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/lib/host/ownership.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
// src/host/ownership.ts
|
|
2
2
|
const SYSTEM_CWD_RE = /^(\/usr\/|\/System\/|\/Library\/|\/bin\/|\/sbin\/|\/private\/)/;
|
|
3
3
|
const LEDGER_WINDOW_MS = 6e5;
|
|
4
|
-
function classifyOwnership(proc, ledgers, workspaces) {
|
|
4
|
+
function classifyOwnership(proc, ledgers, workspaces, context = {}) {
|
|
5
5
|
const cwd = proc.cwd;
|
|
6
6
|
proc.command;
|
|
7
7
|
const evidence = [];
|
|
8
8
|
let ownership = "unknown";
|
|
9
9
|
let confidence = "unknown";
|
|
10
10
|
let ledgerEntry = null;
|
|
11
|
-
if (cwd && ledgers.length > 0)
|
|
11
|
+
if (cwd && ledgers.length > 0) {
|
|
12
|
+
const candidate = ledgers.find((l) => l.cwd && cwd.indexOf(l.cwd) === 0 && proc.startedAt !== null && Math.abs(proc.startedAt - l.at) < LEDGER_WINDOW_MS) ?? null;
|
|
13
|
+
const sessionId = context.sessionId ?? null;
|
|
14
|
+
if (candidate !== null && sessionId !== null && candidate.sessionKey !== null && candidate.sessionKey !== sessionId) evidence.push("launch ledger entry belongs to another session: " + String(candidate.sessionKey).slice(0, 16));
|
|
15
|
+
else ledgerEntry = candidate;
|
|
16
|
+
}
|
|
12
17
|
if (ledgerEntry) {
|
|
13
18
|
ownership = "conversation-confirmed";
|
|
14
19
|
confidence = "confirmed";
|
|
@@ -32,5 +37,4 @@ function classifyOwnership(proc, ledgers, workspaces) {
|
|
|
32
37
|
ledgerEntry
|
|
33
38
|
};
|
|
34
39
|
}
|
|
35
|
-
//#endregion
|
|
36
40
|
export { classifyOwnership };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
|
-
|
|
2
|
+
// src/host/process-inspector.ts
|
|
3
3
|
const MONTHS = {
|
|
4
4
|
Jan: 1,
|
|
5
5
|
Feb: 2,
|
|
@@ -174,5 +174,4 @@ async function scanRaw(commandRunner = runCommand) {
|
|
|
174
174
|
partialWarnings
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
//#endregion
|
|
178
177
|
export { parseAddress, parseListenRows, parseLstart, parsePsRows, runCommand, scanRaw, shellQuote };
|
package/lib/host/protection.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/host/protection.ts
|
|
2
2
|
const CRITICAL_NAMES = /* @__PURE__ */ new Set([
|
|
3
3
|
"launchd",
|
|
4
4
|
"kernel_task",
|
|
@@ -37,5 +37,4 @@ function classifyProtection(proc, guard = {}) {
|
|
|
37
37
|
evidence: unique
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
//#endregion
|
|
41
40
|
export { classifyProtection };
|
package/lib/host/redaction.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/host/redaction.ts
|
|
2
2
|
const REDACT_RULES = [
|
|
3
3
|
{
|
|
4
4
|
re: /(--(?:token|password|passwd|secret|key|api[-_]?key|client[-_]?secret|cookie|session))\s*[=:]\s*(\S+)/gi,
|
|
@@ -23,5 +23,4 @@ function redact(command) {
|
|
|
23
23
|
for (const rule of REDACT_RULES) out = out.replace(rule.re, (match, p1, p2, p3) => rule.replace(match, p1, p2, p3));
|
|
24
24
|
return out;
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { redact };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { redact } from "./redaction.js";
|
|
2
1
|
import { runCommand, scanRaw } from "./process-inspector.js";
|
|
2
|
+
import { redact } from "./redaction.js";
|
|
3
3
|
import { classifyOwnership } from "./ownership.js";
|
|
4
4
|
import { classifyProtection } from "./protection.js";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
|
-
|
|
6
|
+
// src/host/service-registry.ts
|
|
7
7
|
function sha256Hex(input) {
|
|
8
8
|
return createHash("sha256").update(input).digest("hex");
|
|
9
9
|
}
|
|
10
10
|
function isLocalhost(host) {
|
|
11
11
|
return host === "127.0.0.1" || host === "::1" || host === "localhost";
|
|
12
12
|
}
|
|
13
|
-
async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, guard = {}) {
|
|
13
|
+
async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, guard = {}, context = {}) {
|
|
14
14
|
const raw = await scanRaw(commandRunner);
|
|
15
15
|
const byPid = /* @__PURE__ */ new Map();
|
|
16
16
|
for (const l of raw.listeners) {
|
|
@@ -40,7 +40,7 @@ async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, gu
|
|
|
40
40
|
cwd,
|
|
41
41
|
command,
|
|
42
42
|
startedAt
|
|
43
|
-
}, ledgers, workspaces);
|
|
43
|
+
}, ledgers, workspaces, context);
|
|
44
44
|
const listenersFinal = listeners.map((l) => ({
|
|
45
45
|
...l,
|
|
46
46
|
url: isLocalhost(l.host) ? "http://localhost:" + l.port : null
|
|
@@ -80,5 +80,4 @@ async function buildSnapshot(ledgers, workspaces, commandRunner = runCommand, gu
|
|
|
80
80
|
ledgerCount: ledgers.length
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
//#endregion
|
|
84
83
|
export { buildSnapshot };
|
package/lib/host/service-tool.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2
|
-
|
|
2
|
+
// src/host/service-tool.ts
|
|
3
3
|
/** 与 host/types.ts 的 Ownership 联合一致(运行时无从推导,双写靠测试对齐) */
|
|
4
4
|
const OWNERSHIP_LEVELS = [
|
|
5
5
|
"conversation-confirmed",
|
|
@@ -111,6 +111,18 @@ function buildServiceTool(deps) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
},
|
|
114
|
+
presentationMeta: (_args, value) => ({
|
|
115
|
+
scannedAt: value.scannedAt,
|
|
116
|
+
total: value.total,
|
|
117
|
+
count: value.count,
|
|
118
|
+
services: value.services.slice(0, 20).map((s) => ({
|
|
119
|
+
id: s.id,
|
|
120
|
+
name: s.name.slice(0, 80),
|
|
121
|
+
ports: s.ports,
|
|
122
|
+
ownership: s.ownership,
|
|
123
|
+
protected: s.protected
|
|
124
|
+
}))
|
|
125
|
+
}),
|
|
114
126
|
render: (_args, value) => {
|
|
115
127
|
const lines = value.services.map((s) => {
|
|
116
128
|
const tag = s.protected ? "[protected] " : "";
|
|
@@ -124,8 +136,21 @@ function buildServiceTool(deps) {
|
|
|
124
136
|
}
|
|
125
137
|
},
|
|
126
138
|
isConcurrencySafe: () => true,
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
presentCall: () => ({
|
|
140
|
+
card: "generic",
|
|
141
|
+
title: "List local services",
|
|
142
|
+
kind: "execute"
|
|
143
|
+
}),
|
|
144
|
+
presentResult: (_args, result) => {
|
|
145
|
+
const first = result.content.flatMap((item) => item.type === "text" ? [item.text] : []).join("\n").split("\n")[0] ?? "";
|
|
146
|
+
return {
|
|
147
|
+
card: "generic",
|
|
148
|
+
...first === "" ? {} : { title: first.slice(0, 120) }
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
async execute(args, exec) {
|
|
152
|
+
const sessionId = exec?.agent?.id ?? null;
|
|
153
|
+
const snap = await deps.snapshot(sessionId);
|
|
129
154
|
let rows = snap.services;
|
|
130
155
|
if (args.ownership !== void 0) rows = rows.filter((s) => s.ownership === args.ownership);
|
|
131
156
|
if (args.query) {
|
|
@@ -154,5 +179,4 @@ function buildServiceTool(deps) {
|
|
|
154
179
|
}
|
|
155
180
|
});
|
|
156
181
|
}
|
|
157
|
-
//#endregion
|
|
158
182
|
export { buildServiceTool };
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { buildSnapshot } from "./host/service-registry.js";
|
|
|
3
3
|
import { restartService, stopService } from "./host/lifecycle.js";
|
|
4
4
|
import { buildServiceTool } from "./host/service-tool.js";
|
|
5
5
|
import { loadConfigFromFile, saveConfigToFile, validateConfigPatch } from "./host/config.js";
|
|
6
|
-
|
|
6
|
+
// src/index.ts
|
|
7
7
|
async function readJsonBody(req) {
|
|
8
8
|
try {
|
|
9
9
|
let body = "";
|
|
@@ -21,6 +21,24 @@ function sendJson(res, status, payload) {
|
|
|
21
21
|
r.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
22
22
|
r.end(JSON.stringify(payload));
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 调用方是否来自本机回环。
|
|
26
|
+
*
|
|
27
|
+
* rc.5 的 `dsh-host-webserver` 允许绑非 loopback 地址(容器 / Pod 场景),
|
|
28
|
+
* 此时同网段的任何客户端都能请求这些路由。停止/重启进程是**本机**操作,
|
|
29
|
+
* 变更类路由必须只接受回环来源,否则暴露 Web UI 就等于开放一个远程杀进程入口。
|
|
30
|
+
*
|
|
31
|
+
* 只信任 peer socket 地址(不读 `x-forwarded-for` 之类可伪造的请求头);
|
|
32
|
+
* 无法判定来源(例如同进程直调、Unix socket)时按本机处理,保持既有行为。
|
|
33
|
+
*/
|
|
34
|
+
function isLoopbackCaller(remoteAddress) {
|
|
35
|
+
if (!remoteAddress) return true;
|
|
36
|
+
const addr = remoteAddress.trim().toLowerCase();
|
|
37
|
+
const v4 = addr.startsWith("::ffff:") ? addr.slice(7) : addr;
|
|
38
|
+
if (v4 === "::1" || v4 === "localhost") return true;
|
|
39
|
+
if (v4 === "127.0.0.1") return true;
|
|
40
|
+
return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v4);
|
|
41
|
+
}
|
|
24
42
|
var src_default = {
|
|
25
43
|
inject: ["timer", "webServer"],
|
|
26
44
|
apply(ctx) {
|
|
@@ -69,21 +87,27 @@ var src_default = {
|
|
|
69
87
|
} catch {}
|
|
70
88
|
return guard;
|
|
71
89
|
}
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
/** 快照(可带调用方会话 id → 「本次对话」归属按 sessionKey 收窄) */
|
|
91
|
+
function snapshot(sessionId) {
|
|
92
|
+
return buildSnapshot(ledger.list, workspaces(), void 0, protectionGuard(), { sessionId: sessionId ?? null });
|
|
93
|
+
}
|
|
94
|
+
/** 请求体里的会话 id(可缺省:HTTP/旧客户端保持启发式归属) */
|
|
95
|
+
function sessionIdOf(args) {
|
|
96
|
+
const v = args?.sessionId;
|
|
97
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
74
98
|
}
|
|
75
99
|
const routes = [
|
|
76
100
|
{
|
|
77
101
|
path: "/dsh-sc/api/services/scan",
|
|
78
|
-
handler: async () => ({
|
|
102
|
+
handler: async (args) => ({
|
|
79
103
|
ok: true,
|
|
80
|
-
data: await snapshot()
|
|
104
|
+
data: await snapshot(sessionIdOf(args))
|
|
81
105
|
})
|
|
82
106
|
},
|
|
83
107
|
{
|
|
84
108
|
path: "/dsh-sc/api/services/detail",
|
|
85
109
|
handler: async (args) => {
|
|
86
|
-
const svc = (await snapshot()).services.find((x) => x.id === String(args.serviceId ?? ""));
|
|
110
|
+
const svc = (await snapshot(sessionIdOf(args))).services.find((x) => x.id === String(args.serviceId ?? ""));
|
|
87
111
|
if (!svc) return {
|
|
88
112
|
ok: false,
|
|
89
113
|
error: {
|
|
@@ -102,16 +126,25 @@ var src_default = {
|
|
|
102
126
|
},
|
|
103
127
|
{
|
|
104
128
|
path: "/dsh-sc/api/services/stop",
|
|
129
|
+
mutating: true,
|
|
105
130
|
handler: async (args) => stopService(deps, String(args.serviceId ?? ""), String(args.mode ?? "graceful"))
|
|
106
131
|
},
|
|
107
132
|
{
|
|
108
133
|
path: "/dsh-sc/api/services/restart",
|
|
134
|
+
mutating: true,
|
|
109
135
|
handler: async (args) => restartService(deps, String(args.serviceId ?? ""))
|
|
110
136
|
},
|
|
111
137
|
{
|
|
112
138
|
path: "/dsh-sc/api/config",
|
|
113
|
-
handler: async (args) => {
|
|
139
|
+
handler: async (args, info) => {
|
|
114
140
|
const a = args || {};
|
|
141
|
+
if (a.action === "update" && !info.loopback) return {
|
|
142
|
+
ok: false,
|
|
143
|
+
error: {
|
|
144
|
+
code: "FORBIDDEN_REMOTE",
|
|
145
|
+
message: "non-loopback caller"
|
|
146
|
+
}
|
|
147
|
+
};
|
|
115
148
|
if (a.action === "update" && a.patch && typeof a.patch === "object") {
|
|
116
149
|
const v = validateConfigPatch(a.patch);
|
|
117
150
|
if (!v.ok) return {
|
|
@@ -151,6 +184,17 @@ var src_default = {
|
|
|
151
184
|
kind: "exact",
|
|
152
185
|
path: route.path,
|
|
153
186
|
handler: async (req, res) => {
|
|
187
|
+
const info = { loopback: isLoopbackCaller(req?.socket?.remoteAddress) };
|
|
188
|
+
if (route.mutating === true && !info.loopback) {
|
|
189
|
+
sendJson(res, 403, {
|
|
190
|
+
ok: false,
|
|
191
|
+
error: {
|
|
192
|
+
code: "FORBIDDEN_REMOTE",
|
|
193
|
+
message: "non-loopback caller"
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
154
198
|
const body = await readJsonBody(req);
|
|
155
199
|
if (body === null) {
|
|
156
200
|
sendJson(res, 400, {
|
|
@@ -163,7 +207,7 @@ var src_default = {
|
|
|
163
207
|
return;
|
|
164
208
|
}
|
|
165
209
|
try {
|
|
166
|
-
const result = await route.handler(body);
|
|
210
|
+
const result = await route.handler(body, info);
|
|
167
211
|
sendJson(res, result.ok ? 200 : 400, result);
|
|
168
212
|
} catch (e) {
|
|
169
213
|
sendJson(res, 500, {
|
|
@@ -184,7 +228,7 @@ var src_default = {
|
|
|
184
228
|
const tools = ctx.get("tools");
|
|
185
229
|
if (tools) ctx.effect(() => {
|
|
186
230
|
try {
|
|
187
|
-
const off = tools.register(buildServiceTool({ snapshot }));
|
|
231
|
+
const off = tools.register(buildServiceTool({ snapshot: (sessionId) => snapshot(sessionId) }));
|
|
188
232
|
if (process.env.DSH_SC_DEBUG === "1") console.log(`[dsh-sc] service_list registered: ${String(Boolean(tools.get("service_list")))}`);
|
|
189
233
|
return off;
|
|
190
234
|
} catch (e) {
|
|
@@ -195,5 +239,4 @@ var src_default = {
|
|
|
195
239
|
else if (process.env.DSH_SC_DEBUG === "1") console.log("[dsh-sc] tools service absent — service_list not registered");
|
|
196
240
|
}
|
|
197
241
|
};
|
|
198
|
-
|
|
199
|
-
export { src_default as default };
|
|
242
|
+
export { src_default as default, isLoopbackCaller };
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-service-console — 面板组件(原生包 v2)
|
|
3
3
|
*
|
|
4
|
-
* 架构对齐 dsh-
|
|
5
|
-
* - i18n:
|
|
4
|
+
* 架构对齐 dsh-service-console 的 rc.5 契约:
|
|
5
|
+
* - i18n: 组件通过 slot 注册项的 `locale:` 选项拿到框架合成的 `t` seat
|
|
6
|
+
* (`PropsLocale`,按 namespace 联合类型化;语言切换由渲染器按 locale revision
|
|
7
|
+
* 重渲染 outlet,不再需要模块级 bind + 手动订阅)
|
|
6
8
|
* - API: 通过 fetch 直连 webServer JSON 路由(不走 host.call / LLM)
|
|
7
9
|
* - UI: 抽屉式面板 + Tab 栏(服务 / 设置),对标 workspace-explorer 视觉风格
|
|
8
10
|
*/
|
|
9
11
|
import * as React from 'react';
|
|
10
|
-
import type {
|
|
12
|
+
import type { Translate } from './i18n';
|
|
13
|
+
/** rc.5 框架注入的 namespace 翻译函数(slot 注册项声明 `locale:` 后出现在 props 上) */
|
|
14
|
+
export type ConsoleT = Translate;
|
|
11
15
|
interface TimerLike {
|
|
12
16
|
timeout(callback: () => void, delay: number): () => void;
|
|
13
17
|
}
|
|
14
|
-
/** 类型化翻译函数:key 为词典键(拼写错误=编译错误),params 替换 {vars}(locale 运行时完成) */
|
|
15
|
-
type Translate = (key: ConsoleKey, params?: Record<string, unknown>) => string;
|
|
16
18
|
export declare function bindTimer(t: TimerLike): void;
|
|
17
|
-
export declare function bindLocale(locale: {
|
|
18
|
-
t: Translate;
|
|
19
|
-
subscribe(fn: () => void): () => void;
|
|
20
|
-
}): void;
|
|
21
19
|
type ServiceScope = 'conversation' | 'workspace' | 'machine';
|
|
22
20
|
interface ConfigData {
|
|
23
21
|
refreshInterval: number;
|
|
@@ -26,10 +24,24 @@ interface ConfigData {
|
|
|
26
24
|
showUnknown: boolean;
|
|
27
25
|
forceKill: boolean;
|
|
28
26
|
}
|
|
29
|
-
export declare function ServiceConsoleEntry(
|
|
27
|
+
export declare function ServiceConsoleEntry({ t, sessionId }: {
|
|
28
|
+
t: ConsoleT;
|
|
29
|
+
sessionId?: string | null;
|
|
30
|
+
}): React.ReactElement;
|
|
31
|
+
export interface SettingsSectionIconProps {
|
|
32
|
+
/** 请求的正方形边长(px)。 */
|
|
33
|
+
size: number;
|
|
34
|
+
/** 该 section 当前是否被选中。 */
|
|
35
|
+
active: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function ServiceConsoleIcon({ size }: SettingsSectionIconProps): React.ReactElement;
|
|
30
38
|
export interface SettingsProps {
|
|
31
39
|
onSaved?: (config: ConfigData) => void;
|
|
32
40
|
}
|
|
33
|
-
export declare function ServiceConsoleSettings({ onSaved }: SettingsProps
|
|
34
|
-
|
|
41
|
+
export declare function ServiceConsoleSettings({ t, onSaved }: SettingsProps & {
|
|
42
|
+
t: ConsoleT;
|
|
43
|
+
}): React.ReactElement;
|
|
44
|
+
export declare function ServiceConsolePanel({ t }: {
|
|
45
|
+
t: ConsoleT;
|
|
46
|
+
}): React.ReactElement | null;
|
|
35
47
|
export {};
|
|
@@ -58,6 +58,7 @@ export declare const ZH_DICT: {
|
|
|
58
58
|
'err.RESTART_UNSAFE': string;
|
|
59
59
|
'err.PORT_CONFLICT': string;
|
|
60
60
|
'err.START_TIMEOUT': string;
|
|
61
|
+
'err.FORBIDDEN_REMOTE': string;
|
|
61
62
|
'tab.services': string;
|
|
62
63
|
'tab.settings': string;
|
|
63
64
|
'settings.title': string;
|
|
@@ -134,6 +135,7 @@ export declare const EN_DICT: {
|
|
|
134
135
|
'err.RESTART_UNSAFE': string;
|
|
135
136
|
'err.PORT_CONFLICT': string;
|
|
136
137
|
'err.START_TIMEOUT': string;
|
|
138
|
+
'err.FORBIDDEN_REMOTE': string;
|
|
137
139
|
'tab.services': string;
|
|
138
140
|
'tab.settings': string;
|
|
139
141
|
'settings.title': string;
|
|
@@ -1,57 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* i18n
|
|
2
|
+
* i18n 注册/绑定(0.8.0:对齐 DSH 0.2.2-rc.5 的 locale 契约)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* rc.5 的 `ctx.locale.register(ns, { zh, en, … })` 是**类型化对象式**重载:一次注册
|
|
5
|
+
* 全部语种,词典键按 `LocaleNamespaceMap` 的 namespace 联合校验(缺键/多键/拼写错误
|
|
6
|
+
* 都是编译错误)。3 参逐语种式是给「不在 merge 表里的 namespace」用的降级路径,
|
|
7
|
+
* 用它会绕过类型校验,因此不再使用。
|
|
8
|
+
*
|
|
9
|
+
* 两个真实事故口(0.7.1/0.7.2 已修,这里保留对应机制):
|
|
10
|
+
* 1. 桌面竞态:`dsh-client-locale` 的 apply 要先 `await __DSH_LOCALE__.read()`
|
|
11
|
+
* (Electron IPC)才 `ctx.provide('locale')`;本插件 apply 先跑,一次性
|
|
12
|
+
* `ctx.get('locale')` 取到 undefined 即整体跳过 i18n,UI 永久回显原始键。
|
|
13
|
+
* 2. 热更新双装载:dshmarket 更新会把插件装载两次,第二次 `register` 抛
|
|
14
|
+
* `already has locale`;旧实例卸载时不得撤走词典。
|
|
15
|
+
*
|
|
16
|
+
* 对策:`ctx.inject(['locale'], …)` 等 provider fiber 就绪后进入;词典注册幂等且
|
|
17
|
+
* 有意不随实例卸载撤销。组件文案改由 rc.5 框架合成的 `t` seat 提供
|
|
18
|
+
* (slot 注册项的 `locale:` 选项),本模块只保留 `label` thunk 需要的绑定。
|
|
8
19
|
*/
|
|
9
|
-
import type {
|
|
10
|
-
/** 平台 locale 服务的最小兼容面(
|
|
20
|
+
import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots';
|
|
21
|
+
/** 平台 locale 服务的最小兼容面(rc.5:对象式注册 + namespace 绑定) */
|
|
11
22
|
export interface LocaleCompat {
|
|
12
|
-
register(ns: string,
|
|
23
|
+
register(ns: string, dicts: Record<string, Record<string, string>>): unknown;
|
|
13
24
|
bind(ns: string): (key: string, params?: Record<string, unknown>) => string;
|
|
14
|
-
subscribe(fn: () => void): (() => void) | void;
|
|
15
|
-
}
|
|
16
|
-
export type Translate = (key: ConsoleKey, params?: Record<string, unknown>) => string;
|
|
17
|
-
export interface BoundLocale {
|
|
18
|
-
t: Translate;
|
|
19
|
-
subscribe: (fn: () => void) => () => void;
|
|
20
25
|
}
|
|
26
|
+
/** 词典键域翻译函数(namespace 联合 + 公共词表兜底) */
|
|
27
|
+
export type Translate = TranslateNS<'dsh-service-console'>;
|
|
28
|
+
/** 语言 id → 词典 */
|
|
29
|
+
export type DictionaryMap = Record<string, Record<string, string>>;
|
|
21
30
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
31
|
+
* 幂等注册词典:单次对象式注册;已由先前装载注册(`already has locale`)视为
|
|
32
|
+
* 成功,其余错误留一条告警而不是静默吞成「UI 回显原始键」。
|
|
24
33
|
*/
|
|
25
|
-
export declare function registerDictionaries(locale: LocaleCompat, ns: string, dicts:
|
|
34
|
+
export declare function registerDictionaries(locale: LocaleCompat, ns: string, dicts: DictionaryMap): void;
|
|
26
35
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
36
|
+
* 绑定翻译函数:rc.5 的 bound 原生支持 `{param}` 插值;这里仍保留兜底替换,
|
|
37
|
+
* 以便旧版/桩实现忽略 params 时标签不出现裸占位符。
|
|
29
38
|
*/
|
|
30
|
-
export declare function bindTranslator(locale: LocaleCompat, ns: string):
|
|
39
|
+
export declare function bindTranslator(locale: LocaleCompat, ns: string): Translate;
|
|
31
40
|
/** 宿主上下文最小面:本模块只用到 get / inject(真实 ctx 来自 @deepseek-ai/cordis) */
|
|
32
41
|
export interface PluginContextCompat {
|
|
33
42
|
get(name: string, strict?: boolean): unknown;
|
|
34
43
|
inject(deps: string[], callback: (ctx: PluginContextCompat) => void): unknown;
|
|
35
44
|
}
|
|
36
45
|
/**
|
|
37
|
-
* 反应式 i18n
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* 退回 `entry.label` 等原始键:
|
|
41
|
-
*
|
|
42
|
-
* 1. 服务晚到(桌面竞态):桌面客户端 `globalThis.__DSH_LOCALE__` 存在时,
|
|
43
|
-
* dsh-client-locale 的 apply 要先 `await bridge.read()`(Electron IPC)才
|
|
44
|
-
* `ctx.provide('locale')`;本插件 apply 先跑,get 取到 undefined 即整体
|
|
45
|
-
* 跳过 i18n。浏览器开发环境无 bridge、provide 同步完成,所以“本地验证
|
|
46
|
-
* 通过、用户下载后失效”。另外 cordis 的 get(strict) 在 provider fiber
|
|
47
|
-
* 尚未落定(state != 2)时同样返回 undefined。
|
|
48
|
-
* 2. 热更新双装载的 dispose 顺序:dshmarket 更新会把插件装载两次,第二次
|
|
49
|
-
* register 抛 already has locale 被跳过;随后旧实例卸载时若把词典 disposer
|
|
50
|
-
* 掉,词典即被撤走,留下没有词典的新实例回显原始键。
|
|
51
|
-
*
|
|
52
|
-
* 对策:`ctx.inject(['locale'], …)` 按平台注入等待语义在服务真正可用
|
|
53
|
-
* (provider fiber 就绪)后才进入;provider 重启/热更新重载都会重新进入
|
|
54
|
-
* 回调并重绑;词典注册保持幂等,且有意不在实例卸载时撤销(见上第 2 条),
|
|
55
|
-
* 注册本身只增不减,对双装载安全。
|
|
46
|
+
* 反应式 i18n 挂载:等 locale 服务真正可用(provider fiber 就绪)后注册词典,
|
|
47
|
+
* 并把绑定好的翻译函数交给调用方(用于 slot 注册项的 `label` thunk——它在每次
|
|
48
|
+
* 投影时被重新读取,因此语言切换无需重新注册)。
|
|
56
49
|
*/
|
|
57
|
-
export declare function attachLocale(ctx: PluginContextCompat, ns: string, dicts:
|
|
50
|
+
export declare function attachLocale(ctx: PluginContextCompat, ns: string, dicts: DictionaryMap, onReady: (t: Translate) => void): void;
|
|
51
|
+
/** 动态错误码 → 词典键(`err.<CODE>`);未收录的码回退 fallback */
|
|
52
|
+
export declare function errorText(t: Translate, code: string, fallback: string): string;
|
|
@@ -2,6 +2,13 @@ import type { LedgerEntry } from './types';
|
|
|
2
2
|
export declare const DEV_COMMAND_RE: RegExp;
|
|
3
3
|
export interface ToolExecLike {
|
|
4
4
|
name?: string;
|
|
5
|
+
/**
|
|
6
|
+
* DSH ≥ 0.2.0:`ToolExecution.arguments`(executor 已解析、lossless JSON 快照的参数)。
|
|
7
|
+
* 0.1.x 曾叫 `args`,0.2.0-rc.2 起改名为 `arguments`——读错字段会让台账恒空
|
|
8
|
+
* (「本次对话」归属与「重启」能力静默失效),因此两个名字都读,优先新名。
|
|
9
|
+
*/
|
|
10
|
+
arguments?: Record<string, unknown>;
|
|
11
|
+
/** @deprecated DSH 0.1.x 字段名,仅为跨版本兼容保留 */
|
|
5
12
|
args?: Record<string, unknown>;
|
|
6
13
|
agent?: {
|
|
7
14
|
id?: string;
|
|
@@ -5,8 +5,16 @@ export interface OwnershipResult {
|
|
|
5
5
|
evidence: string[];
|
|
6
6
|
ledgerEntry: LedgerEntry | null;
|
|
7
7
|
}
|
|
8
|
+
/** 归属判定的会话上下文(缺省时保持 0.7.x 的启发式行为) */
|
|
9
|
+
export interface OwnershipContext {
|
|
10
|
+
/**
|
|
11
|
+
* 当前会话 id。提供时,只有 `sessionKey` 相等的台账条目才能确认「本次对话」;
|
|
12
|
+
* 同一工作区里**另一个会话**起的服务最多降级为「工作区推断」。
|
|
13
|
+
*/
|
|
14
|
+
sessionId?: string | null;
|
|
15
|
+
}
|
|
8
16
|
export declare function classifyOwnership(proc: {
|
|
9
17
|
cwd: string | null;
|
|
10
18
|
command: string | null;
|
|
11
19
|
startedAt: number | null;
|
|
12
|
-
}, ledgers: LedgerEntry[], workspaces: WorkspaceLike[]): OwnershipResult;
|
|
20
|
+
}, ledgers: LedgerEntry[], workspaces: WorkspaceLike[], context?: OwnershipContext): OwnershipResult;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LedgerEntry, Snapshot, WorkspaceLike } from './types';
|
|
2
2
|
import { type CommandRunner } from './process-inspector';
|
|
3
|
+
import { type OwnershipContext } from './ownership';
|
|
3
4
|
import { type ProtectionGuard } from './protection';
|
|
4
|
-
export declare function buildSnapshot(ledgers: LedgerEntry[], workspaces: WorkspaceLike[], commandRunner?: CommandRunner, guard?: ProtectionGuard): Promise<Snapshot>;
|
|
5
|
+
export declare function buildSnapshot(ledgers: LedgerEntry[], workspaces: WorkspaceLike[], commandRunner?: CommandRunner, guard?: ProtectionGuard, context?: OwnershipContext): Promise<Snapshot>;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Snapshot } from './types';
|
|
2
2
|
export interface ServiceToolDeps {
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 与 API scan 路由同源的快照函数(含受保护判定 guard)。
|
|
5
|
+
* @param sessionId 调用方会话 id(`exec.agent.id`,rc.5 起就是 `SessionId`);
|
|
6
|
+
* 提供时「本次对话」归属按台账 sessionKey 收窄,避免同工作区另一会话的
|
|
7
|
+
* 启动记录被误判成本次对话。
|
|
8
|
+
*/
|
|
9
|
+
snapshot(sessionId?: string | null): Promise<Snapshot>;
|
|
5
10
|
}
|
|
6
11
|
export declare function buildServiceTool(deps: ServiceToolDeps): import("@deepseek-ai/dsh-tools").ToolDefinition;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Context } from 'cordis';
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
2
|
import type { WebServer } from '@deepseek-ai/dsh-host-webserver';
|
|
3
|
-
declare module 'cordis' {
|
|
3
|
+
declare module '@deepseek-ai/cordis' {
|
|
4
4
|
interface Context {
|
|
5
5
|
timer: {
|
|
6
6
|
timeout(callback: () => void, delay: number): () => void;
|
|
@@ -10,6 +10,22 @@ declare module 'cordis' {
|
|
|
10
10
|
webServer: WebServer;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
/** 一次请求的来源信息(handler 的第二个参数) */
|
|
14
|
+
export interface RequestInfo {
|
|
15
|
+
/** 调用方是否来自本机回环;变更类操作只允许 true。 */
|
|
16
|
+
loopback: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 调用方是否来自本机回环。
|
|
20
|
+
*
|
|
21
|
+
* rc.5 的 `dsh-host-webserver` 允许绑非 loopback 地址(容器 / Pod 场景),
|
|
22
|
+
* 此时同网段的任何客户端都能请求这些路由。停止/重启进程是**本机**操作,
|
|
23
|
+
* 变更类路由必须只接受回环来源,否则暴露 Web UI 就等于开放一个远程杀进程入口。
|
|
24
|
+
*
|
|
25
|
+
* 只信任 peer socket 地址(不读 `x-forwarded-for` 之类可伪造的请求头);
|
|
26
|
+
* 无法判定来源(例如同进程直调、Unix socket)时按本机处理,保持既有行为。
|
|
27
|
+
*/
|
|
28
|
+
export declare function isLoopbackCaller(remoteAddress: string | undefined | null): boolean;
|
|
13
29
|
declare const _default: {
|
|
14
30
|
inject: string[];
|
|
15
31
|
apply(ctx: Context): void;
|
package/locale/en.json
ADDED