@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.
@@ -1,16 +1,19 @@
1
1
  /**
2
- * dsh-service-console — 面板组件(原生包 v2)
2
+ * dsh-service-console — 控制台内容组件(rc.5 右侧栏 tab 版)
3
3
  *
4
- * 架构对齐 dsh-service-console 的 rc.5 契约:
5
- * - i18n: 组件通过 slot 注册项的 `locale:` 选项拿到框架合成的 `t` seat
6
- * (`PropsLocale`,按 namespace 联合类型化;语言切换由渲染器按 locale revision
7
- * 重渲染 outlet,不再需要模块级 bind + 手动订阅)
8
- * - API: 通过 fetch 直连 webServer JSON 路由(不走 host.call / LLM)
9
- * - UI: 抽屉式面板 + Tab 栏(服务 / 设置),对标 workspace-explorer 视觉风格
4
+ * 结构(M1 迁移后):
5
+ * - `ServiceConsoleTab`:tab 内容体(工具条 + 服务列表 + 详情 + Toast)。
6
+ * 面板的边框/拖拽/停靠/焦点/关闭由右侧栏拥有,这里只画内容。
7
+ * - `ServiceConsoleEntry`:header 入口按钮,点击由侧栏打开 tab。
8
+ * - `ServiceConsoleSettings` / `ServiceConsoleIcon`:全局设置页与其导航图标。
9
+ *
10
+ * i18n:组件从 slot 注册项的 `locale:` 拿到框架合成的 `t`(按 namespace 类型化),
11
+ * 语言切换由渲染器按 locale revision 重渲染,不需要手动订阅。
12
+ * API:fetch 直连 webServer JSON 路由(不走 host.call / LLM)。
10
13
  */
11
14
  import * as React from 'react';
12
15
  import type { Translate } from './i18n';
13
- /** rc.5 框架注入的 namespace 翻译函数(slot 注册项声明 `locale:` 后出现在 props 上) */
16
+ /** rc.5 框架注入的 namespace 翻译函数(注册项声明 `locale:` 后出现在 props 上) */
14
17
  export type ConsoleT = Translate;
15
18
  interface TimerLike {
16
19
  timeout(callback: () => void, delay: number): () => void;
@@ -24,9 +27,9 @@ interface ConfigData {
24
27
  showUnknown: boolean;
25
28
  forceKill: boolean;
26
29
  }
27
- export declare function ServiceConsoleEntry({ t, sessionId }: {
30
+ export declare function ServiceConsoleEntry({ t, openConsole }: {
28
31
  t: ConsoleT;
29
- sessionId?: string | null;
32
+ openConsole: () => void;
30
33
  }): React.ReactElement;
31
34
  export interface SettingsSectionIconProps {
32
35
  /** 请求的正方形边长(px)。 */
@@ -41,7 +44,12 @@ export interface SettingsProps {
41
44
  export declare function ServiceConsoleSettings({ t, onSaved }: SettingsProps & {
42
45
  t: ConsoleT;
43
46
  }): React.ReactElement;
44
- export declare function ServiceConsolePanel({ t }: {
47
+ export interface ConsoleTabProps {
45
48
  t: ConsoleT;
46
- }): React.ReactElement | null;
49
+ /** 调用方会话 id(注入自框架的 session 作用域 inject face) */
50
+ sessionId: string;
51
+ /** tab 是否可见(侧栏折叠 / 后台会话时为 false)——不可见时停止扫描与轮询 */
52
+ visible: boolean;
53
+ }
54
+ export declare function ServiceConsoleTab({ t, sessionId, visible }: ConsoleTabProps): React.ReactElement;
47
55
  export {};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * composer 常驻 pill(`conversation.composer.dock`)
3
+ *
4
+ * 只在**本会话**有归属服务(`conversation-confirmed`)时出现:
5
+ * `2 services · :5173 :3000` → 点击打开控制台 tab。
6
+ *
7
+ * 设计取舍:
8
+ * - 数据来自与面板同一个 `/dsh-sc/api/services/scan`(带 sessionId → 宿主按台账
9
+ * `sessionKey` 收窄归属),选择/摘要全部走纯函数(`service-list-view.ts`,有单测)。
10
+ * - 轮询**慢且可停**:20s 一次、页面隐藏时跳过、卸载即清;不为一个环境提示
11
+ * 引入高频 `lsof`。
12
+ * - 无归属服务时不渲染任何 DOM(不占位、不抢焦点)。
13
+ */
14
+ import * as React from 'react';
15
+ import type { ConsoleT } from './ServiceConsole';
16
+ /** 轮询间隔:环境提示够用,且不让 lsof 跑得太勤 */
17
+ export declare const POLL_INTERVAL_MS = 30000;
18
+ interface TimerLike {
19
+ interval(callback: () => void, delay: number): () => void;
20
+ }
21
+ /** 注入平台 timer(与面板共用 `bindTimer` 的同一份服务,但这里需要 interval) */
22
+ export declare function bindDockTimer(t: TimerLike): void;
23
+ export interface ServiceDockPillProps {
24
+ t: ConsoleT;
25
+ /** 会话作用域 inject face 注入 */
26
+ sessionId: string;
27
+ }
28
+ export declare function ServiceDockPill({ t, sessionId }: ServiceDockPillProps): React.ReactElement | null;
29
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * service_list 的聊天卡片(`tool.call.toolview`,keyed by wire tool name)
3
+ *
4
+ * 数据来自工具 `output.presentationMeta`(随会话日志持久化 → 视为不可信),
5
+ * 投影成视图模型由纯函数 `projectServiceListMeta` 完成;任何坏形状都回退成
6
+ * 纯文本行,**绝不抛错**——toolview 抛错会让该 key 粘性空白。
7
+ *
8
+ * 交互约束(与面板同一语义,不新增策略):
9
+ * - 受保护目标只读;「重启」还要求 meta 里的 `restartable`(无安全启动记录不提供);
10
+ * - 停止/重启二次确认 + 在途去重;错误码走词典;
11
+ * - 卡片是一次调用的**快照**,不轮询;折叠状态由平台的 `useDisclosure` 拥有。
12
+ */
13
+ import * as React from 'react';
14
+ import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
15
+ import type { ToolCallViewProps } from '@deepseek-ai/dsh-client-ui-tool/client';
16
+ export type ServiceListCardProps = ToolCallViewProps & PropsLocale<'dsh-service-console'>;
17
+ export declare function ServiceListCard(props: ServiceListCardProps): React.ReactElement;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Host API 客户端(fetch 直连 webServer JSON 路由,不经过 LLM)
3
+ *
4
+ * 面板 tab 与聊天卡片共用同一份调用约定:统一信封 `{ ok, data | error }`。
5
+ */
6
+ export interface Envelope<T> {
7
+ ok: boolean;
8
+ data?: T;
9
+ error?: {
10
+ code?: string;
11
+ message?: string;
12
+ };
13
+ }
14
+ /**
15
+ * 调用一条 `/dsh-sc/api/*` 路由。
16
+ * @param path 路由尾段(例如 `services/scan`)
17
+ * @param payload JSON 请求体
18
+ */
19
+ export declare function api<T>(path: string, payload: Record<string, unknown>): Promise<T>;
@@ -17,6 +17,12 @@ export declare const ZH_DICT: {
17
17
  'status.lastScan': string;
18
18
  'status.error': string;
19
19
  'svc.noSvc': string;
20
+ 'card.summary': string;
21
+ 'card.more': string;
22
+ 'card.confirm': string;
23
+ 'svc.restartable': string;
24
+ 'dock.pill': string;
25
+ 'dock.open': string;
20
26
  'svc.ports': string;
21
27
  'svc.pid': string;
22
28
  'svc.command': string;
@@ -24,6 +30,7 @@ export declare const ZH_DICT: {
24
30
  'action.stop': string;
25
31
  'action.restart': string;
26
32
  'action.detail': string;
33
+ 'action.open': string;
27
34
  'action.confirm': string;
28
35
  'action.cancel': string;
29
36
  'action.pending': string;
@@ -38,6 +45,7 @@ export declare const ZH_DICT: {
38
45
  'own.other': string;
39
46
  'own.unknown': string;
40
47
  'own.protected': string;
48
+ 'scope.filter': string;
41
49
  'scope.conversation': string;
42
50
  'scope.workspace': string;
43
51
  'scope.machine': string;
@@ -59,6 +67,10 @@ export declare const ZH_DICT: {
59
67
  'err.PORT_CONFLICT': string;
60
68
  'err.START_TIMEOUT': string;
61
69
  'err.FORBIDDEN_REMOTE': string;
70
+ 'err.SCAN_FAILED': string;
71
+ 'err.BAD_REQUEST': string;
72
+ 'err.INTERNAL': string;
73
+ 'err.SCAN_TIMEOUT': string;
62
74
  'tab.services': string;
63
75
  'tab.settings': string;
64
76
  'settings.title': string;
@@ -94,6 +106,12 @@ export declare const EN_DICT: {
94
106
  'status.lastScan': string;
95
107
  'status.error': string;
96
108
  'svc.noSvc': string;
109
+ 'card.summary': string;
110
+ 'card.more': string;
111
+ 'card.confirm': string;
112
+ 'svc.restartable': string;
113
+ 'dock.pill': string;
114
+ 'dock.open': string;
97
115
  'svc.ports': string;
98
116
  'svc.pid': string;
99
117
  'svc.command': string;
@@ -101,6 +119,7 @@ export declare const EN_DICT: {
101
119
  'action.stop': string;
102
120
  'action.restart': string;
103
121
  'action.detail': string;
122
+ 'action.open': string;
104
123
  'action.confirm': string;
105
124
  'action.cancel': string;
106
125
  'action.pending': string;
@@ -115,6 +134,7 @@ export declare const EN_DICT: {
115
134
  'own.other': string;
116
135
  'own.unknown': string;
117
136
  'own.protected': string;
137
+ 'scope.filter': string;
118
138
  'scope.conversation': string;
119
139
  'scope.workspace': string;
120
140
  'scope.machine': string;
@@ -136,6 +156,10 @@ export declare const EN_DICT: {
136
156
  'err.PORT_CONFLICT': string;
137
157
  'err.START_TIMEOUT': string;
138
158
  'err.FORBIDDEN_REMOTE': string;
159
+ 'err.SCAN_FAILED': string;
160
+ 'err.BAD_REQUEST': string;
161
+ 'err.INTERNAL': string;
162
+ 'err.SCAN_TIMEOUT': string;
139
163
  'tab.services': string;
140
164
  'tab.settings': string;
141
165
  'settings.title': string;
@@ -48,5 +48,3 @@ export interface PluginContextCompat {
48
48
  * 投影时被重新读取,因此语言切换无需重新注册)。
49
49
  */
50
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;
@@ -1,14 +1,14 @@
1
1
  /**
2
- * dsh-service-console — Client 入口(原生包 v2)
2
+ * dsh-service-console — Client 入口(rc.5 右侧栏页面型 tab)
3
3
  *
4
- * 架构对齐 dsh-workspace-explorer:
5
- * - 通过 locale.register + locale.bind 实现国际化(词典键编译期校验)
6
- * - 通过 webServer JSON 路由调用 Host(fetch 直连,不走 host.call / LLM)
7
- * - 注册 DSH 设置壳的 settings.section 页
8
- * - 注册 shell.overlay 抽屉面板 + header 入口按钮
9
- *
10
- * 类型化(P0-5):ctx 来自 @deepseek-ai/cordis,ctx.slots / ctx.locale /
11
- * SlotMap 键均由平台类型包增广;平台包仅 type-only 导入,构建时擦除。
4
+ * 架构(M1 迁移后):
5
+ * - 控制台是**右侧栏的一个页面型 tab**:静态类型注册(stage one)+
6
+ * `sidebar.right.pane.tab` / `.title` 的 keyed 注册(stage two)。
7
+ * 面板的边框、拖拽、停靠、焦点、持久化、关闭全部由侧栏拥有——插件只剩内容。
8
+ * - i18n 走 slot 注册项的 `locale:` 选项(框架合成的 `t` seat),
9
+ * 不再需要模块级 bind 与手动订阅。
10
+ * - 设置页仍是全局 `settings.section`(无会话也能改配置)。
11
+ * - API 通过 fetch 直连 webServer JSON 路由(不走 host.call / LLM)。
12
12
  */
13
13
  import type { Context } from '@deepseek-ai/cordis';
14
14
  import { type ConsoleKey } from './dictionaries';
@@ -17,7 +17,18 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
17
17
  'dsh-service-console': ConsoleKey;
18
18
  }
19
19
  }
20
- /** cordis-plugin-timer 未随本包安装类型;客户端只用 timeout 一种能力,结构化声明 */
20
+ /**
21
+ * 页面参数(M10 快捷键 / 第三方入口用得上):
22
+ * 打开已存在的 console tab 时通过 navigation.params 传焦点意图,无需新的打开路径。
23
+ */
24
+ declare module '@deepseek-ai/dsh-client-ui-sidebar-right/client' {
25
+ interface SidebarRightTabParamsMap {
26
+ 'service-console': {
27
+ readonly focus?: 'services' | 'settings';
28
+ } | undefined;
29
+ }
30
+ }
31
+ /** cordis-plugin-timer 的最小结构化面(客户端只用 timeout) */
21
32
  interface TimerLike {
22
33
  timeout(callback: () => void, delay: number): () => void;
23
34
  }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * service_list 的呈现投影(纯函数,无 React / 无 DOM)
3
+ *
4
+ * 模型工具 `service_list` 的 `output.presentationMeta` 会随会话日志**持久化**,
5
+ * 因此这里把它当作**不可信输入**:旧会话(无 meta)、被截断的记录、未来版本新增
6
+ * 字段、手工篡改都可能出现。任何坏形状都必须降级成可见的纯文本行,绝不抛错
7
+ * ——toolview 组件抛错会让该 key 的整行粘性空白(框架放弃该 entry)。
8
+ */
9
+ import type { Ownership } from '../host/types';
10
+ import type { ConsoleKey } from './dictionaries';
11
+ import type { TagTone } from '@deepseek-ai/dsh-client-ui-primitives';
12
+ /** 卡片最多展示多少行(meta 由宿主限长,这里再兜一次,防止回放旧数据) */
13
+ export declare const MAX_CARD_ROWS = 20;
14
+ /** 归属 → 主题色(两处 UI 共用,避免各写一份) */
15
+ export declare const OWNERSHIP_COLOR: Record<Ownership, string>;
16
+ /**
17
+ * 归属徽标的 tone:统一 `neutral`。
18
+ *
19
+ * 平台 Tag 的语义色(success/warning/danger)在浅色主题下实测对比度不足
20
+ * (success 2.09:1 / warning 1.96:1 / danger 3.80:1,均低于 AA 4.5:1),
21
+ * 而 `neutral` 为 5.36:1。归属的细粒度语义由前面的彩色圆点承担(装饰性)。
22
+ */
23
+ export declare const OWNERSHIP_TONE: Record<Ownership, TagTone>;
24
+ /** 归属 → 词典键 */
25
+ export declare const OWNERSHIP_KEY: Record<Ownership, ConsoleKey>;
26
+ /** API 字符串 → 归属级别(未知值降级 unknown,不炸 UI) */
27
+ export declare function ownershipLevel(value: string): Ownership;
28
+ export interface ServiceListRow {
29
+ id: string;
30
+ name: string;
31
+ /** 逗号分隔的端口(与工具输出同形) */
32
+ ports: string;
33
+ ownership: Ownership;
34
+ protected: boolean;
35
+ /** 能否安全重启(meta 缺失时保守为 false:不提供重启入口) */
36
+ restartable: boolean;
37
+ /** 可打开的 localhost URL;非本机监听 / 旧 meta 为 null */
38
+ url: string | null;
39
+ }
40
+ export interface ServiceListViewModel {
41
+ /** 扫描时刻(epoch ms);缺失或非法时为 null */
42
+ scannedAt: number | null;
43
+ /** 过滤前总数 */
44
+ total: number;
45
+ /** 实际返回数 */
46
+ count: number;
47
+ /** 有界行(≤ MAX_CARD_ROWS) */
48
+ rows: ServiceListRow[];
49
+ /** 被截断的行数(count - rows.length,≥0) */
50
+ truncated: number;
51
+ }
52
+ /**
53
+ * 只接受 http(s) + 回环主机;其余(含 `javascript:`、`data:`、外部域名)一律 null。
54
+ * @param value meta 里的 url 字段(unknown)
55
+ */
56
+ export declare function safeServiceUrl(value: unknown): string | null;
57
+ /**
58
+ * `presentationMeta` → 卡片视图模型。
59
+ * @param meta 持久化的 meta(`unknown`:旧会话可能没有,或形状已变)
60
+ * @returns 可渲染模型;`null` 表示「没有可用 meta」,调用方应回退到纯文本内容
61
+ */
62
+ export declare function projectServiceListMeta(meta: unknown): ServiceListViewModel | null;
63
+ /** 端口去重后的一行摘要片段(最多 6 个,避免撑爆行宽);语言无关 */
64
+ export declare function serviceListPorts(model: ServiceListViewModel): string;
65
+ /** 行是否可执行生命周期操作(与面板同一判定:受保护目标只读) */
66
+ export declare function canControlService(row: ServiceListRow): boolean;
67
+ /** 扫描接口返回的服务行(只取 pill 需要的字段) */
68
+ export interface ScanServiceLike {
69
+ id: string;
70
+ name: string;
71
+ ownership: Ownership;
72
+ protected: boolean;
73
+ ports: string;
74
+ }
75
+ export interface SessionPillModel {
76
+ /** 本会话名下的服务数 */
77
+ count: number;
78
+ /** 去重后的端口片段(`:3000 :5173`,最多 4 个) */
79
+ ports: string;
80
+ }
81
+ /**
82
+ * 从一次扫描快照里挑出「属于本会话」的服务。
83
+ * 归属判定在宿主完成(scan 带 sessionId 时按台账 sessionKey 收窄),
84
+ * 这里只做防御式读取:坏行丢弃,未知归属不计数。
85
+ * @param services 扫描接口的 `data.services`(不可信:可能缺失/坏形状)
86
+ */
87
+ export declare function selectSessionServices(services: unknown): ScanServiceLike[];
88
+ /**
89
+ * 本会话服务摘要;`count === 0` 时 pill 不渲染。
90
+ * @param services `selectSessionServices` 的结果
91
+ */
92
+ export declare function summarizeSessionServices(services: readonly ScanServiceLike[]): SessionPillModel;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * 插件配置 schema(rc.5 契约:`Config` 由 Loader 校验组合行里的 `config:`)
3
+ *
4
+ * 与 `config.ts` 的关系:
5
+ * - 本文件是**唯一声明**(默认值 + 取值范围 + 类型),供 `cordis.yml` 的 `config:` 行、
6
+ * Loader 校验、以及运行时对 JSON 覆盖文件的二次校验共用。
7
+ * - `config.ts` 负责「默认值 ← UI 覆盖文件 ← 组合行」的合并与读写。
8
+ *
9
+ * 注意:这里**不使用** `.volatile()`。volatile 字段会进入 rc.5 的 Settings → Plugins
10
+ * 表单(写回 profile patch),而我们面板的设置页写的是插件自己的 JSON 文件——两条写入
11
+ * 路径会互相覆盖。保持单一写入者:面板(JSON),组合行只做部署期覆盖。
12
+ */
13
+ import z from '@deepseek-ai/schemastery';
14
+ /** 自动刷新档位(PRD FR-07:关闭 / 2s / 5s / 10s / 30s) */
15
+ export declare const REFRESH_INTERVAL_CHOICES: readonly number[];
16
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
17
+ /** 自动刷新间隔(毫秒,仅上述离散档位;0 表示关闭) */
18
+ refreshInterval: z<number, number, "defined">;
19
+ /** 面板默认范围 */
20
+ defaultScope: z<"conversation" | "workspace" | "machine", "conversation" | "workspace" | "machine", "defined">;
21
+ /** 优雅停止超时(毫秒) */
22
+ gracefulTimeout: z<number, number, "defined">;
23
+ /** 是否展示归属未知的服务 */
24
+ showUnknown: z<boolean, boolean, "defined">;
25
+ /** 允许 SIGKILL 兜底 */
26
+ forceKill: z<boolean, boolean, "defined">;
27
+ /** 关闭面板时是否自动清理(当前恒为 false,保留字段以兼容旧配置文件) */
28
+ autoCleanup: z<boolean, boolean, "defined">;
29
+ /** 一次扫描请求的预算(毫秒):HTTP deadline 与 service_list 的工具预算共用 */
30
+ scanTimeoutMs: z<number, number, "defined">;
31
+ /** 单条宿主命令的预算(毫秒) */
32
+ commandTimeoutMs: z<number, number, "defined">;
33
+ }>>, Schemastery.ObjectT<NoInfer<{
34
+ /** 自动刷新间隔(毫秒,仅上述离散档位;0 表示关闭) */
35
+ refreshInterval: z<number, number, "defined">;
36
+ /** 面板默认范围 */
37
+ defaultScope: z<"conversation" | "workspace" | "machine", "conversation" | "workspace" | "machine", "defined">;
38
+ /** 优雅停止超时(毫秒) */
39
+ gracefulTimeout: z<number, number, "defined">;
40
+ /** 是否展示归属未知的服务 */
41
+ showUnknown: z<boolean, boolean, "defined">;
42
+ /** 允许 SIGKILL 兜底 */
43
+ forceKill: z<boolean, boolean, "defined">;
44
+ /** 关闭面板时是否自动清理(当前恒为 false,保留字段以兼容旧配置文件) */
45
+ autoCleanup: z<boolean, boolean, "defined">;
46
+ /** 一次扫描请求的预算(毫秒):HTTP deadline 与 service_list 的工具预算共用 */
47
+ scanTimeoutMs: z<number, number, "defined">;
48
+ /** 单条宿主命令的预算(毫秒) */
49
+ commandTimeoutMs: z<number, number, "defined">;
50
+ }>>, "plain">;
51
+ /** 校验后的配置类型 */
52
+ export type PluginConfig = ReturnType<typeof Config>;
@@ -1,9 +1,34 @@
1
+ import { REFRESH_INTERVAL_CHOICES } from './config-schema';
1
2
  import type { Config } from './types';
3
+ export { REFRESH_INTERVAL_CHOICES };
4
+ /** schema 默认值(唯一声明处) */
2
5
  export declare const DEFAULT_CONFIG: Config;
3
- export declare const REFRESH_INTERVAL_CHOICES: readonly number[];
4
6
  export declare const CONFIG_LIMITS: Record<string, [number, number]>;
7
+ /**
8
+ * 读取 UI 覆盖文件,并用同一份 schema 校验/补默认值。
9
+ * @returns 合并后的配置(坏文件退化为默认值,不抛)
10
+ */
5
11
  export declare function loadConfigFromFile(): Config;
6
- export declare function saveConfigToFile(config: Config): void;
12
+ /** 读原始文件(失败返回空对象) */
13
+ export declare function readConfigFile(): Partial<Config>;
14
+ /**
15
+ * schema 校验 + 合并:schema 默认值 ← 组合行(部署基线)← UI 覆盖文件(用户显式选择)。
16
+ *
17
+ * 为什么 UI 覆盖文件优先:rc.5 的 Loader 总是把**补全后的完整** config 传给
18
+ * `apply`,所以「组合行最高」会让文件永远不可达(用户改设置无效)。这里的语义是
19
+ * 「部署行给基线,用户在面板里的显式修改压过它」——面板是该插件唯一的写入者,
20
+ * 不存在两个写入路径互相覆盖的问题(rc.5 的 Settings→Plugins 表单只投影
21
+ * `.volatile()` 字段,本插件未声明 volatile,故不会出现第二个写入者)。
22
+ * @param overrides UI 覆盖文件内容
23
+ * @param rowConfig cordis.yml 组合行里的 `config:`
24
+ */
25
+ export declare function normalizeConfig(overrides?: Partial<Config>, rowConfig?: Partial<Config>): Config;
26
+ /**
27
+ * 持久化 **UI 覆盖补丁**(不是合并后的配置)。
28
+ * 只写用户真正改过的字段:把合并结果写回文件会把部署行的值冻结成用户覆盖,
29
+ * 之后组合行的修改就再也影响不到运行时。
30
+ */
31
+ export declare function saveConfigToFile(overrides: Partial<Config>): void;
7
32
  export declare function validateConfigPatch(patch: Record<string, unknown>): {
8
33
  ok: true;
9
34
  next: Partial<Config>;
@@ -0,0 +1,98 @@
1
+ import { z } from 'zod';
2
+ import type { LedgerEntry } from './types';
3
+ /** 每个会话保留的台账条数上限(旧条目先丢) */
4
+ export declare const MAX_LEDGER_ENTRIES = 200;
5
+ /** 未结算调用(call 已记录、result 还没到)的上限 */
6
+ export declare const MAX_PENDING_CALLS = 32;
7
+ /** 条目保留时长(毫秒):开发服务的归属窗口远小于一天 */
8
+ export declare const LEDGER_TTL_MS: number;
9
+ /** 一次已发起、尚未结算的调用 */
10
+ export interface PendingLaunch {
11
+ /** tool/call 的 callId,或 PTC 的 subCallId */
12
+ id: string;
13
+ at: number;
14
+ command: string;
15
+ cwd: string | null;
16
+ redacted: string;
17
+ }
18
+ /** 台账状态(纯 JSON,projection 的持久化前提) */
19
+ export interface LedgerState {
20
+ /** 会话 id(内核 header),用于归属收窄 */
21
+ sessionKey: string;
22
+ /** 会话创建时的绝对工作目录(bash 未显式给 workdir 时作为 cwd 回退) */
23
+ sessionCwd: string | null;
24
+ entries: LedgerEntry[];
25
+ pending: PendingLaunch[];
26
+ }
27
+ /** 状态 schema:projection 用它在 checkpoint 反序列化时校验(不可信输入) */
28
+ export declare const ledgerStateSchema: z.ZodObject<{
29
+ sessionKey: z.ZodString;
30
+ sessionCwd: z.ZodNullable<z.ZodString>;
31
+ entries: z.ZodArray<z.ZodObject<{
32
+ at: z.ZodNumber;
33
+ command: z.ZodString;
34
+ cwd: z.ZodNullable<z.ZodString>;
35
+ sessionKey: z.ZodNullable<z.ZodString>;
36
+ redacted: z.ZodString;
37
+ }, z.core.$strip>>;
38
+ pending: z.ZodDefault<z.ZodArray<z.ZodObject<{
39
+ id: z.ZodString;
40
+ at: z.ZodNumber;
41
+ command: z.ZodString;
42
+ cwd: z.ZodNullable<z.ZodString>;
43
+ redacted: z.ZodString;
44
+ }, z.core.$strip>>>;
45
+ }, z.core.$strip>;
46
+ /** 折叠需要的事件形状(避免把整个 SessionEvent 联合拖进纯函数) */
47
+ export interface LedgerEventLike {
48
+ readonly type: string;
49
+ readonly time?: number;
50
+ readonly data?: Record<string, unknown>;
51
+ }
52
+ /**
53
+ * 纯 reducer:一条已提交事件 → 新状态(无关事件返回**同一引用**)。
54
+ * @param redact 命令脱敏函数(注入以便单测;生产用 `redaction.redact`)
55
+ */
56
+ export declare function foldLedgerEvent(state: LedgerState, event: LedgerEventLike, redact: (command: string) => string | null | undefined): LedgerState;
57
+ /** 初始状态(`init` 用):空台账 + 会话元数据 */
58
+ export declare function initLedgerState(header: {
59
+ id: string;
60
+ cwd?: string;
61
+ }): LedgerState;
62
+ /**
63
+ * 构造 rc.5 的 `ProjectionDefinition`。
64
+ * @param redact 命令脱敏
65
+ * @returns 可直接交给 `ctx.sessionProjections.register(...)` 的定义
66
+ */
67
+ export declare function createLedgerProjection(redact: (command: string) => string | null | undefined): {
68
+ readonly key: "serviceConsoleLedger";
69
+ readonly stateSchema: z.ZodObject<{
70
+ sessionKey: z.ZodString;
71
+ sessionCwd: z.ZodNullable<z.ZodString>;
72
+ entries: z.ZodArray<z.ZodObject<{
73
+ at: z.ZodNumber;
74
+ command: z.ZodString;
75
+ cwd: z.ZodNullable<z.ZodString>;
76
+ sessionKey: z.ZodNullable<z.ZodString>;
77
+ redacted: z.ZodString;
78
+ }, z.core.$strip>>;
79
+ pending: z.ZodDefault<z.ZodArray<z.ZodObject<{
80
+ id: z.ZodString;
81
+ at: z.ZodNumber;
82
+ command: z.ZodString;
83
+ cwd: z.ZodNullable<z.ZodString>;
84
+ redacted: z.ZodString;
85
+ }, z.core.$strip>>>;
86
+ }, z.core.$strip>;
87
+ readonly stateVersion: 1;
88
+ readonly init: (header: {
89
+ id: string;
90
+ cwd?: string;
91
+ }) => LedgerState;
92
+ readonly apply: (state: LedgerState, event: LedgerEventLike) => LedgerState;
93
+ };
94
+ /**
95
+ * 从投影状态里取条目;形状不对时返回空数组(宁可少归属,也不抛)。
96
+ * @param state `stateOf(session)` 的返回值(unknown:可能来自旧版本 checkpoint)
97
+ */
98
+ export declare function entriesOf(state: unknown, now?: number): LedgerEntry[];
@@ -3,8 +3,47 @@ export interface CommandResult {
3
3
  stderr: string;
4
4
  code: number | null;
5
5
  }
6
- export type CommandRunner = (command: string, timeoutMs?: number) => CommandResult | Promise<CommandResult>;
6
+ export type CommandRunner = (command: string, timeoutMs?: number, signal?: AbortSignal) => CommandResult | Promise<CommandResult>;
7
+ /**
8
+ * 异步命令执行(可取消):`execFile('/bin/sh', ['-c', …])` + `signal`。
9
+ *
10
+ * 扫描链路上的一切命令都必须走这里——`execFileSync` 无法响应取消,
11
+ * 面板的 8s 超时与模型的 `exec.signal` 都只能等进程自己结束。
12
+ * 取消/超时按「已结束但输出不完整」返回(code 125),由上层记为 partial。
13
+ */
14
+ export declare function runCommandAsync(command: string, timeoutMs?: number, signal?: AbortSignal): Promise<CommandResult>;
7
15
  export declare function runCommand(command: string, timeoutMs?: number): CommandResult;
16
+ export interface LsofFieldProcess {
17
+ pid: number;
18
+ /** lsof `c` 字段(命令名,可能被 lsof 截断到 9 字符;优先用 ps 的 command) */
19
+ command: string;
20
+ /** `n` 字段(LISTEN 扫描里是地址;cwd 扫描里不出现,走 cwd 字段) */
21
+ names: string[];
22
+ /** 仅 `-d cwd` 扫描里出现的 `n` 值 */
23
+ cwd: string | null;
24
+ }
25
+ /**
26
+ * 解析 `lsof -F<fields>` 输出(每条记录:p/c/f/n 前缀行)。
27
+ * @param stdout lsof 字段模式输出
28
+ */
29
+ export declare function parseLsofFieldOutput(stdout: string): LsofFieldProcess[];
30
+ export interface PsCombinedRow {
31
+ pid: number;
32
+ ppid: number;
33
+ pgid: number | null;
34
+ user: string | null;
35
+ lstart: string;
36
+ startedAt: number | null;
37
+ command: string;
38
+ }
39
+ /**
40
+ * 解析 `ps -o pid=,ppid=,pgid=,lstart=,command= -p <pids>` 的单次合并输出。
41
+ * lstart 固定占 5 个 token(Www Mmm D HH:MM:SS YYYY),command 是余下全部。
42
+ * @param stdout ps 输出
43
+ */
44
+ export declare function parsePsCombined(stdout: string): PsCombinedRow[];
45
+ /** 地址语法推断协议:`[::1]:80` / `[fe80::1]:80` 视为 tcp6,其余 tcp */
46
+ export declare function protocolOfAddress(address: string): string;
8
47
  export declare function parseLstart(str: string): number | null;
9
48
  export interface ListenRow {
10
49
  command: string;
@@ -36,6 +75,8 @@ export interface RawProcess {
36
75
  name: string | null;
37
76
  pgid: number | null;
38
77
  cwd: string | null;
78
+ /** 进程属主(来自同一次 ps 调用;root 判定用) */
79
+ user: string | null;
39
80
  }
40
81
  export interface RawListener {
41
82
  pid: number;
@@ -49,5 +90,13 @@ export interface RawScan {
49
90
  listeners: RawListener[];
50
91
  procs: Map<number, RawProcess>;
51
92
  partialWarnings: string[];
93
+ /**
94
+ * 监听扫描本身失败时的结构化错误(取消/超时、退出码异常、权限)。
95
+ * 缺省表示扫描成功;上层据此区分「真的没有服务」与「扫不出来」。
96
+ */
97
+ scanError?: {
98
+ code: 'SCAN_TIMEOUT' | 'SCAN_FAILED' | 'PERMISSION_DENIED';
99
+ message: string;
100
+ } | null;
52
101
  }
53
- export declare function scanRaw(commandRunner?: CommandRunner): Promise<RawScan>;
102
+ export declare function scanRaw(commandRunner?: CommandRunner, signal?: AbortSignal, commandTimeoutMs?: number): Promise<RawScan>;
@@ -2,4 +2,4 @@ import type { LedgerEntry, Snapshot, WorkspaceLike } from './types';
2
2
  import { type CommandRunner } from './process-inspector';
3
3
  import { type OwnershipContext } from './ownership';
4
4
  import { type ProtectionGuard } from './protection';
5
- export declare function buildSnapshot(ledgers: LedgerEntry[], workspaces: WorkspaceLike[], commandRunner?: CommandRunner, guard?: ProtectionGuard, context?: OwnershipContext): Promise<Snapshot>;
5
+ export declare function buildSnapshot(ledgers: LedgerEntry[], workspaces: WorkspaceLike[], commandRunner?: CommandRunner, guard?: ProtectionGuard, context?: OwnershipContext, signal?: AbortSignal, commandTimeoutMs?: number): Promise<Snapshot>;
@@ -6,6 +6,6 @@ export interface ServiceToolDeps {
6
6
  * 提供时「本次对话」归属按台账 sessionKey 收窄,避免同工作区另一会话的
7
7
  * 启动记录被误判成本次对话。
8
8
  */
9
- snapshot(sessionId?: string | null): Promise<Snapshot>;
9
+ snapshot(sessionId?: string | null, signal?: AbortSignal): Promise<Snapshot>;
10
10
  }
11
11
  export declare function buildServiceTool(deps: ServiceToolDeps): import("@deepseek-ai/dsh-tools").ToolDefinition;