@jiyr0119/dsh-service-console 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { execFileSync } from "node:child_process";
2
- //#region src/host/process-inspector.ts
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 };
@@ -1,4 +1,4 @@
1
- //#region src/host/protection.ts
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 };
@@ -1,4 +1,4 @@
1
- //#region src/host/redaction.ts
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
- //#region src/host/service-registry.ts
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 };
@@ -1,5 +1,5 @@
1
1
  import { defineTool } from "@deepseek-ai/dsh-tools";
2
- //#region src/host/service-tool.ts
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
- async execute(args) {
128
- const snap = await deps.snapshot();
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
- //#region src/index.ts
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
- function snapshot() {
73
- return buildSnapshot(ledger.list, workspaces(), void 0, protectionGuard());
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
- //#endregion
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-workspace-explorer:
5
- * - i18n: 通过 locale.bind(NS) 获取翻译函数(而非硬编码 TEXTS)
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 { ConsoleKey } from './dictionaries';
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(): React.ReactElement;
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): React.ReactElement;
34
- export declare function ServiceConsolePanel(): React.ReactElement | null;
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,30 +1,52 @@
1
1
  /**
2
- * i18n 注册/绑定(热挂载与双装载幂等,0.7.1)
2
+ * i18n 注册/绑定(0.8.0:对齐 DSH 0.2.2-rc.5 的 locale 契约)
3
3
  *
4
- * 桌面 dshmarket 热更新会把插件装载两次:第二次 locale.register 抛
5
- * "already has locale",webServer.register 抛 "duplicate exact route"。
6
- * 0.5–0.7.0 的初始化在异常后直接放弃绑定,导致 UI 退回原始键。
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 { ConsoleKey } from './dictionaries';
10
- /** 平台 locale 服务的最小兼容面(3 参式注册,各版本通用;对象式为 0.2.0+ 专属) */
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, locale: string, dict: Record<string, string>): (() => void) | unknown;
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
- * 幂等注册词典:逐语种注册;单条失败(如 already has locale)跳过,
23
- * 不影响其余语种与后续绑定。返回 disposer(整体可安全清理)。
31
+ * 幂等注册词典:单次对象式注册;已由先前装载注册(`already has locale`)视为
32
+ * 成功,其余错误留一条告警而不是静默吞成「UI 回显原始键」。
24
33
  */
25
- export declare function registerDictionaries(locale: LocaleCompat, ns: string, dicts: ReadonlyArray<readonly [string, Record<string, string>]>): () => void;
34
+ export declare function registerDictionaries(locale: LocaleCompat, ns: string, dicts: DictionaryMap): void;
35
+ /**
36
+ * 绑定翻译函数:rc.5 的 bound 原生支持 `{param}` 插值;这里仍保留兜底替换,
37
+ * 以便旧版/桩实现忽略 params 时标签不出现裸占位符。
38
+ */
39
+ export declare function bindTranslator(locale: LocaleCompat, ns: string): Translate;
40
+ /** 宿主上下文最小面:本模块只用到 get / inject(真实 ctx 来自 @deepseek-ai/cordis) */
41
+ export interface PluginContextCompat {
42
+ get(name: string, strict?: boolean): unknown;
43
+ inject(deps: string[], callback: (ctx: PluginContextCompat) => void): unknown;
44
+ }
26
45
  /**
27
- * 绑定翻译函数:稳定外层 + 每次取最新 bound(旧版 bind 可能缓存语种)。
28
- * 变量插值手工兜底(旧版 bound 可能不支持 params)。
46
+ * 反应式 i18n 挂载:等 locale 服务真正可用(provider fiber 就绪)后注册词典,
47
+ * 并把绑定好的翻译函数交给调用方(用于 slot 注册项的 `label` thunk——它在每次
48
+ * 投影时被重新读取,因此语言切换无需重新注册)。
29
49
  */
30
- export declare function bindTranslator(locale: LocaleCompat, ns: string): BoundLocale;
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
- /** 与 API scan 路由同源的快照函数(含受保护判定 guard) */
4
- snapshot(): Promise<Snapshot>;
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;
@@ -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
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Service console",
4
+ "description": "Discovers listening TCP ports on this machine, attributes each service to a conversation, workspace, or the machine, and safely stops or restarts local dev servers."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "服务控制台",
4
+ "description": "发现本机监听的 TCP 端口,识别每个服务归属的对话、工作区或本机,并安全地停止或重启本地开发服务。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jiyr0119/dsh-service-console",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "DeepSeek Harness 本地开发服务控制台(原生插件):发现监听端口,识别服务归属,安全查看/停止/重启。Local development service console for DSH.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,18 +32,21 @@
32
32
  "local-dev-server",
33
33
  "port-manager"
34
34
  ],
35
+ "engines": {
36
+ "node": ">=24.9.0",
37
+ "dsh": ">=0.2.2-rc.5 <0.3.0"
38
+ },
35
39
  "files": [
36
40
  "lib",
37
- "dsh.plugin.json",
38
41
  "cordis.patch.yml",
39
- "dynamic",
42
+ "locale",
43
+ "icon.svg",
40
44
  "docs",
41
45
  "assets",
42
46
  "demo",
43
47
  "README.md",
44
48
  "README.zh.md",
45
- "LICENSE",
46
- "manifest.json"
49
+ "LICENSE"
47
50
  ],
48
51
  "dsh": {
49
52
  "bundle": {
@@ -53,21 +56,12 @@
53
56
  "inject": [
54
57
  "@deepseek-ai/dsh-client-locale",
55
58
  "@deepseek-ai/dsh-client-ui-slots",
59
+ "@deepseek-ai/dsh-client-ui-renderer",
60
+ "@deepseek-ai/dsh-client-ui-layout",
61
+ "@deepseek-ai/dsh-client-ui-settings",
56
62
  "@deepseek-ai/dsh-client-ui-conversation"
57
63
  ],
58
64
  "platform": "web"
59
- },
60
- "plugin": {
61
- "id": "dsh-service-console",
62
- "kind": "dynamic-cordis-plugin",
63
- "host": "dynamic/host.js",
64
- "client": "dynamic/client.js",
65
- "hostHandler": "scan",
66
- "clientSlots": [
67
- "conversation.session.header.utilities",
68
- "shell.overlay",
69
- "settings.section"
70
- ]
71
65
  }
72
66
  },
73
67
  "scripts": {
@@ -77,19 +71,18 @@
77
71
  "test": "npm run build && node --test test/*.test.mjs"
78
72
  },
79
73
  "devDependencies": {
80
- "@deepseek-ai/cordis": "~4.0.4",
81
- "@deepseek-ai/dsh-client-locale": "^0.2.0-rc.2",
82
- "@deepseek-ai/dsh-client-ui-conversation": "^0.2.0-rc.2",
83
- "@deepseek-ai/dsh-client-ui-layout": "^0.2.0-rc.2",
84
- "@deepseek-ai/dsh-client-ui-primitives": "^0.2.0-rc.2",
85
- "@deepseek-ai/dsh-client-ui-renderer": "^0.2.0-rc.2",
86
- "@deepseek-ai/dsh-client-ui-settings": "^0.2.0-rc.2",
87
- "@deepseek-ai/dsh-client-ui-slots": "^0.2.0-rc.2",
88
- "@deepseek-ai/dsh-host-webserver": "^0.2.0-rc.2",
89
- "@deepseek-ai/dsh-tools": "^0.2.0-rc.2",
90
- "@types/node": "^22.0.0",
74
+ "@deepseek-ai/cordis": "~4.1.0",
75
+ "@deepseek-ai/dsh-client-locale": "^0.2.2-rc.5",
76
+ "@deepseek-ai/dsh-client-ui-conversation": "^0.2.2-rc.5",
77
+ "@deepseek-ai/dsh-client-ui-layout": "^0.2.2-rc.5",
78
+ "@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.5",
79
+ "@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.5",
80
+ "@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.5",
81
+ "@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.5",
82
+ "@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.5",
83
+ "@deepseek-ai/dsh-tools": "^0.2.2-rc.5",
84
+ "@types/node": "^24.9.0",
91
85
  "@types/react": "^18.3.1",
92
- "cordis": "^4.0.0-rc.7",
93
86
  "lightningcss": "^1.33.0",
94
87
  "react": "^18.2.0",
95
88
  "react-dom": "^18.2.0",
@@ -97,7 +90,8 @@
97
90
  "typescript": "^5.6.0"
98
91
  },
99
92
  "peerDependencies": {
100
- "@deepseek-ai/cordis": "~4.0.4",
93
+ "@deepseek-ai/cordis": "~4.1.0",
94
+ "@deepseek-ai/dsh-tools": "^0.2.2-rc.5",
101
95
  "react": "^18.2.0"
102
96
  }
103
97
  }
package/dsh.plugin.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "id": "dsh-external/dsh-service-console",
3
- "version": "0.7.1",
4
- "main": "./lib/index.js",
5
- "description": "本地开发服务控制台:发现监听端口,识别服务归属,安全查看/停止/重启。Local development service console for DSH.",
6
- "engines": {
7
- "dsh": ">=0.2.0-rc.2"
8
- },
9
- "contributes": {
10
- "tools": [],
11
- "skills": []
12
- },
13
- "client": {
14
- "main": "./lib/client.js"
15
- }
16
- }