@sunshaobei/dsh-mcp-manager 0.0.0-stage → 0.4.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.
Files changed (144) hide show
  1. package/LICENSE +1 -0
  2. package/README.en.md +476 -0
  3. package/README.md +379 -2
  4. package/cordis.patch.yml +9 -0
  5. package/lib/THIRD-PARTY-LICENSES +43 -0
  6. package/lib/client/core/api.d.ts +42 -0
  7. package/lib/client/core/constants.d.ts +58 -0
  8. package/lib/client/core/current-session.d.ts +39 -0
  9. package/lib/client/core/dom.d.ts +19 -0
  10. package/lib/client/core/i18n.d.ts +12 -0
  11. package/lib/client/core/session.d.ts +27 -0
  12. package/lib/client/core/state.d.ts +120 -0
  13. package/lib/client/float/float.d.ts +126 -0
  14. package/lib/client/float/panel.d.ts +29 -0
  15. package/lib/client/float/quick-add.d.ts +38 -0
  16. package/lib/client/float/servers.d.ts +54 -0
  17. package/lib/client/index.d.ts +26 -0
  18. package/lib/client/locales.d.ts +123 -0
  19. package/lib/client/settings/settings-card.d.ts +47 -0
  20. package/lib/client.js +2568 -0
  21. package/lib/index.d.ts +86 -0
  22. package/lib/index.js +10035 -0
  23. package/lib/server/api/deps.d.ts +36 -0
  24. package/lib/server/api/impl/health/type.d.ts +12 -0
  25. package/lib/server/api/impl/service/index.d.ts +28 -0
  26. package/lib/server/api/interface.d.ts +27 -0
  27. package/lib/server/api/routes-controllers.d.ts +61 -0
  28. package/lib/server/api/routes-helpers.d.ts +8 -0
  29. package/lib/server/api/routes.d.ts +58 -0
  30. package/lib/server/catalog/deps.d.ts +51 -0
  31. package/lib/server/catalog/impl/cache-view/index.d.ts +48 -0
  32. package/lib/server/catalog/impl/digest/index.d.ts +19 -0
  33. package/lib/server/catalog/impl/directory/index.d.ts +168 -0
  34. package/lib/server/catalog/impl/entries/index.d.ts +129 -0
  35. package/lib/server/catalog/impl/entries/type.d.ts +19 -0
  36. package/lib/server/catalog/impl/history/index.d.ts +36 -0
  37. package/lib/server/catalog/impl/injection/index.d.ts +45 -0
  38. package/lib/server/catalog/impl/search/type.d.ts +59 -0
  39. package/lib/server/catalog/impl/service/index.d.ts +25 -0
  40. package/lib/server/catalog/interface.d.ts +45 -0
  41. package/lib/server/catalog/search.d.ts +108 -0
  42. package/lib/server/config/config-schema.d.ts +85 -0
  43. package/lib/server/config/impl/env/index.d.ts +24 -0
  44. package/lib/server/config/impl/env/policy.d.ts +54 -0
  45. package/lib/server/config/impl/model/type.d.ts +39 -0
  46. package/lib/server/config/impl/ui/type.d.ts +20 -0
  47. package/lib/server/config/import.d.ts +20 -0
  48. package/lib/server/config/interface.d.ts +15 -0
  49. package/lib/server/config/normalize.d.ts +24 -0
  50. package/lib/server/config/sources-sync.d.ts +32 -0
  51. package/lib/server/config/sources.d.ts +50 -0
  52. package/lib/server/connection/interface.d.ts +86 -0
  53. package/lib/server/connection/orchestrator/deps.d.ts +93 -0
  54. package/lib/server/connection/orchestrator/impl/service/index.d.ts +27 -0
  55. package/lib/server/connection/orchestrator/interface.d.ts +25 -0
  56. package/lib/server/connection/orchestrator/manager.d.ts +484 -0
  57. package/lib/server/connection/orchestrator/tool-names.d.ts +14 -0
  58. package/lib/server/connection/runtime/deps.d.ts +141 -0
  59. package/lib/server/connection/runtime/impl/middleware/type.d.ts +45 -0
  60. package/lib/server/connection/runtime/impl/service/index.d.ts +28 -0
  61. package/lib/server/connection/runtime/interface.d.ts +29 -0
  62. package/lib/server/connection/runtime/limits.d.ts +19 -0
  63. package/lib/server/connection/runtime/middleware.d.ts +194 -0
  64. package/lib/server/erasure/impl/guard/index.d.ts +35 -0
  65. package/lib/server/erasure/interface.d.ts +31 -0
  66. package/lib/server/inject/deps.d.ts +54 -0
  67. package/lib/server/inject/impl/call-timeout/index.d.ts +1 -0
  68. package/lib/server/inject/impl/image-admission/index.d.ts +81 -0
  69. package/lib/server/inject/impl/service/index.d.ts +25 -0
  70. package/lib/server/inject/interface.d.ts +27 -0
  71. package/lib/server/inject/middleware-register.d.ts +114 -0
  72. package/lib/server/pipeline/deps.d.ts +27 -0
  73. package/lib/server/pipeline/impl/args/index.d.ts +26 -0
  74. package/lib/server/pipeline/impl/authorize/index.d.ts +43 -0
  75. package/lib/server/pipeline/impl/msg/index.d.ts +8 -0
  76. package/lib/server/pipeline/impl/project/index.d.ts +43 -0
  77. package/lib/server/pipeline/impl/redact/index.d.ts +13 -0
  78. package/lib/server/pipeline/impl/service/index.d.ts +25 -0
  79. package/lib/server/pipeline/impl/timeout/index.d.ts +8 -0
  80. package/lib/server/pipeline/interface.d.ts +32 -0
  81. package/lib/server/servers/dispatch/deps.d.ts +100 -0
  82. package/lib/server/servers/dispatch/impl/call/index.d.ts +49 -0
  83. package/lib/server/servers/dispatch/impl/redact/index.d.ts +13 -0
  84. package/lib/server/servers/dispatch/interface.d.ts +18 -0
  85. package/lib/server/servers/lifecycle/deps.d.ts +62 -0
  86. package/lib/server/servers/lifecycle/impl/ledger/index.d.ts +52 -0
  87. package/lib/server/servers/lifecycle/impl/logs/index.d.ts +48 -0
  88. package/lib/server/servers/lifecycle/impl/mount/index.d.ts +83 -0
  89. package/lib/server/servers/lifecycle/impl/service/index.d.ts +26 -0
  90. package/lib/server/servers/lifecycle/impl/state/index.d.ts +35 -0
  91. package/lib/server/servers/lifecycle/impl/timeout/index.d.ts +39 -0
  92. package/lib/server/servers/lifecycle/interface.d.ts +56 -0
  93. package/lib/server/shared/compose.d.ts +38 -0
  94. package/lib/server/shared/constants.d.ts +62 -0
  95. package/lib/server/shared/file-io.d.ts +8 -0
  96. package/lib/server/shared/host-faces.d.ts +206 -0
  97. package/lib/server/shared/interface.d.ts +14 -0
  98. package/lib/server/shared/paths.d.ts +66 -0
  99. package/lib/server/shared/tool-names.d.ts +11 -0
  100. package/lib/server/stats/impl/collector.d.ts +68 -0
  101. package/lib/server/stats/impl/type.d.ts +41 -0
  102. package/lib/server/stats/interface.d.ts +13 -0
  103. package/lib/server/store/impl/middleware-state.d.ts +45 -0
  104. package/lib/server/store/impl/store.d.ts +43 -0
  105. package/lib/server/store/interface.d.ts +9 -0
  106. package/lib/server/upgrade/deps.d.ts +25 -0
  107. package/lib/server/upgrade/impl/chain/index.d.ts +2 -0
  108. package/lib/server/upgrade/impl/service/index.d.ts +9 -0
  109. package/lib/server/upgrade/impl/steps/index.d.ts +19 -0
  110. package/lib/server/upgrade/impl/steps/project-layout.d.ts +24 -0
  111. package/lib/server/upgrade/impl/steps/storage-layout.d.ts +17 -0
  112. package/lib/server/upgrade/impl/version/index.d.ts +7 -0
  113. package/lib/server/upgrade/interface.d.ts +21 -0
  114. package/lib/server/visibility/impl/mask/index.d.ts +7 -0
  115. package/lib/server/visibility/interface.d.ts +46 -0
  116. package/lib/server/workspace/impl/full-name/index.d.ts +24 -0
  117. package/lib/server/workspace/impl/root-resolution/index.d.ts +18 -0
  118. package/lib/server/workspace/impl/scope/index.d.ts +14 -0
  119. package/lib/server/workspace/impl/server-id/index.d.ts +17 -0
  120. package/lib/server/workspace/interface.d.ts +22 -0
  121. package/lib/shared/constants.d.ts +22 -0
  122. package/lib/shared/dto.d.ts +62 -0
  123. package/lib/shared/frames.d.ts +19 -0
  124. package/lib/shared/interface.d.ts +22 -0
  125. package/lib/shared/placement-math.d.ts +81 -0
  126. package/lib/shared/routes.d.ts +43 -0
  127. package/lib/shared/service.d.ts +85 -0
  128. package/lib/shared/status.d.ts +23 -0
  129. package/lib/vendor/shared/README.md +147 -0
  130. package/lib/vendor/shared/client/ensure-style.d.ts +23 -0
  131. package/lib/vendor/shared/client/i18n.d.ts +30 -0
  132. package/lib/vendor/shared/client/ui/index.d.ts +214 -0
  133. package/lib/vendor/shared/dsh-home.d.ts +26 -0
  134. package/lib/vendor/shared/host-utils.d.ts +82 -0
  135. package/lib/vendor/shared/loopback.d.ts +12 -0
  136. package/lib/vendor/shared/package.json +12 -0
  137. package/lib/vendor/shared/paths.d.ts +35 -0
  138. package/lib/vendor/shared/settings-namespace.d.ts +82 -0
  139. package/lib/vendor/shared/sse-hub.d.ts +75 -0
  140. package/lib/vendor/shared/upgrade-chain.d.ts +140 -0
  141. package/lib/vendor/shared/upgrade-tick.d.ts +17 -0
  142. package/locale/en.json +6 -0
  143. package/locale/zh.json +6 -0
  144. package/package.json +171 -4
@@ -0,0 +1,129 @@
1
+ /**
2
+ * dsh-mcp-manager — catalog/impl/entries/index.ts:能力目录条目与渲染(#664 阶段 5)。
3
+ *
4
+ * 自 src/catalog.ts 拆出(目录条目域):条目类型/摘要常量/摘要计算/条目组装/
5
+ * 消息渲染与转义/消息定位读取。digest 与 history 归同域兄弟文件;目录注入决策
6
+ * 归 injection.ts;注入端缓存视图归 cache-view.ts;检索族归 search.ts。
7
+ */
8
+ import type { SupervisorLite } from "../../../connection/interface.js";
9
+ import type { CatalogMessage } from "../injection/index.js";
10
+ import type { ContextFormed } from "@deepseek-ai/dsh-llm";
11
+ import { DEFAULT_ANNOUNCE_CATALOG, DEFAULT_CATALOG_MAX_ENTRIES } from "../../../shared/interface.js";
12
+ /**
13
+ * dsh 0.1.7-rc.2 producer-owned source kind。
14
+ *
15
+ * V4 将生产者身份编码进 kind;本包不再声明或依赖共享 `plugin` 基座,
16
+ * 也不把身份拆到 `plugin` 字段。snapshot 的 form/sections 由官方
17
+ * ContextFormed 约束。
18
+ */
19
+ declare module "@deepseek-ai/dsh-llm" {
20
+ interface MessageSourceMap {
21
+ "plugin:dsh-mcp-manager": {
22
+ kind: "plugin:dsh-mcp-manager";
23
+ } & ContextFormed;
24
+ }
25
+ }
26
+ /** 目录条目。 */
27
+ export interface CatalogEntry {
28
+ name: string;
29
+ text?: string;
30
+ /** 服务器归属(global/project);用于区分调用引导(#228 双轨迁移)。 */
31
+ scope?: string;
32
+ }
33
+ /** supervisor 最小面(manager.supervisors 的条目;物理定义在 connection/interface.ts,此处 re-export)。 */
34
+ export type { SupervisorLite } from "../../../connection/interface.js";
35
+ /** 目录缓存(连接成功时持久化的工具描述摘要)。 */
36
+ export type CatalogCache = Map<string, {
37
+ summary: string;
38
+ }>;
39
+ export { DEFAULT_ANNOUNCE_CATALOG, DEFAULT_CATALOG_MAX_ENTRIES };
40
+ /** 本包 V4 producer-owned source kind;身份编码在 kind,不另设 plugin 字段。 */
41
+ export declare const CATALOG_SOURCE_PLUGIN = "dsh-mcp-manager";
42
+ export declare const CATALOG_SOURCE_KIND = "plugin:dsh-mcp-manager";
43
+ /** 目录快照的段名(snapshot 形态下承载渲染后的目录正文)。 */
44
+ export declare const CATALOG_SECTION_NAME = "mcp-catalog";
45
+ /** 目录摘要总长上限(字符,含前缀与省略号):目录注入 ≤6 条目,防远端工具描述
46
+ * 堆叠稀释上下文;截断先于 escapeCatalogText 转义,防不可信输入注入超长文本。 */
47
+ export declare const CATALOG_SUMMARY_MAX_CHARS = 240;
48
+ /** 目录摘要单句上限(字符):无句读语言 / 超长描述的安全截断点。 */
49
+ export declare const CATALOG_SUMMARY_PER_TOOL_CHARS = 120;
50
+ /** 目录单条服务器描述上限(字符):Level 1 发现层防远端超长说明书(如 context7 500 词)
51
+ * 撑爆会话上下文,符合渐进式披露原则。详细使用说明由 ws_mcp_detail / ws_mcp_search 按需承载。 */
52
+ export declare const CATALOG_ENTRY_MAX_CHARS = 180;
53
+ /**
54
+ * 从工具描述集合计算目录摘要(每工具取首句,按工具名升序 + 精确去重后拼接)。
55
+ *
56
+ * 为什么不再「排序取第一条」(#569):tavily 等服务器的字典序第一条是次要工具
57
+ * (tavily_crawl),会把搜索服务器描述成爬虫、误导模型。改为每工具贡献首句:
58
+ * - 排序(按工具名而非描述)保证工具列表顺序/描述空白抖动时摘要稳定(重连不触发
59
+ * 缓存更新 → digest 不变);
60
+ * - 首句提取(firstSentenceOf)防 "1." 编号 / URL / 缩写误切;多字节按字符截断;
61
+ * - 总长与单句均有上限:目录摘要的用途是让模型判断「该不该调这个服务器」,过长
62
+ * 描述(含远端不可信输入)反而稀释上下文;完整能力清单由 ws_mcp_list /
63
+ * 工具注册表承担,不塞进目录。
64
+ */
65
+ export declare function summarizeToolDescriptions(toolMeta: Map<string, {
66
+ description?: unknown;
67
+ }>): string | undefined;
68
+ /** ① 收集 (工具名, 首句);首句为空的工具不贡献摘要。 */
69
+ export declare function collectToolSentences(toolMeta: Map<string, {
70
+ description?: unknown;
71
+ }>): Array<[string, string]>;
72
+ /** ② 按工具名升序(确定性:顺序抖动只变内容不变名序)→ 精确去重 → 单句截断。 */
73
+ export declare function dedupeToolSentences(collected: Array<[string, string]>): string[];
74
+ /** 单句上限截断(超限留一位给省略号)。 */
75
+ export declare function truncatePerTool(sentence: string): string;
76
+ /** ③ 拼接("; " 分隔),超总长按句整段回退补 "…"(绝不句中切)。 */
77
+ export declare function joinSentencesWithinBudget(sentences: string[], prefix: string): string;
78
+ /**
79
+ * 生成能力目录条目(**数据源不依赖用户配置、不依赖实时连接状态**):
80
+ * ① 服务器自定义 description(用户可选补充,优先)→
81
+ * ② 目录缓存摘要(连接成功时自动持久化的工具描述摘要,磁盘数据,与连接状态解耦)
82
+ * ③ 都没有 → 只显示服务器名。
83
+ * 连接/断开/重连不改变缓存内容 → digest 稳定 → 不触发重复注入。
84
+ * @param supervisors manager.supervisors(name → supervisor)。
85
+ * @param maxEntries 最大条目数。
86
+ * @param cache 目录缓存(manager.catalogCache)。
87
+ * @returns 目录条目。
88
+ */
89
+ export declare function composeCatalogEntries(supervisors: Map<string, SupervisorLite>, maxEntries?: number, cache?: CatalogCache): CatalogEntry[];
90
+ /** 条目描述文本的三级来源:① 用户自写描述(首句,空则整句压空白)→ ② 磁盘缓存摘要
91
+ * → ③ 都没有则 undefined(调用方据此不产出 text 键)。用户描述按单条上限截断。 */
92
+ export declare function entryTextFor(name: string, server: SupervisorLite["server"], cache: CatalogCache | undefined): string | undefined;
93
+ /** 渲染能力目录消息(source 标记供定位替换)。
94
+ *
95
+ * 当前 source 精确为 V4 producer-owned snapshot:
96
+ * `{ kind: "plugin:dsh-mcp-manager", form: "snapshot", sections: [...] }`。
97
+ */
98
+ export declare function renderMcpCatalogMessage(entries: CatalogEntry[]): CatalogMessage;
99
+ /** 转义远程来源文本(防提示注入/标签逃逸;与 skill catalog 的 escapeText 同思路)。
100
+ * 只做安全转义,**不做长度截断**(完整返回描述)。 */
101
+ export declare function escapeCatalogText(value: unknown): string;
102
+ /** 是否为本插件当前 V4 注入的能力目录消息。旧 V0/V2/V3 source 不在业务域兼容。 */
103
+ export declare function isCatalogSource(source: {
104
+ kind?: unknown;
105
+ } | undefined): boolean;
106
+ /** 从消息列表里定位既有的当前 V4 能力目录消息。 */
107
+ export declare function findCatalogMessage(messages: CatalogMessage[]): CatalogMessage | undefined;
108
+ /**
109
+ * 取回一条目录消息所发布的条目:从快照正文的 `<available_mcp_servers>` 块还原
110
+ * 条目(格式化是单射的),使 digest 与 `composeCatalogEntries` 的条目 digest
111
+ * 同口径——否则每次启动都会误判"目录已变"而注入一条修正帧。
112
+ *
113
+ * 坏数据返回 undefined(按"不是本插件的目录"处理):本函数在 step 监听器里被调用,
114
+ * 抛错会让该会话每一轮都失败。
115
+ */
116
+ export declare function resolveCatalogEntries(source: CatalogSourceLike | undefined): CatalogEntry[] | undefined;
117
+ /**
118
+ * 防御性读取当前 V4 source 的条目;旧 `entries` 形态由 maintenance 处理,
119
+ * 不在业务 reader 中兼容。
120
+ */
121
+ export declare function readCatalogEntries(source: CatalogSourceLike | undefined): CatalogEntry[] | undefined;
122
+ /** 当前 V4 source 最小面。 */
123
+ export interface CatalogSourceLike {
124
+ kind?: unknown;
125
+ form?: unknown;
126
+ sections?: unknown;
127
+ }
128
+ /** 渲染"目录更新"消息(历史旧目录无法删除,新消息声明作废——与 tool-skill 同语义)。 */
129
+ export declare function renderMcpCatalogUpdate(entries: CatalogEntry[]): CatalogMessage;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * dsh-mcp-manager — server/catalog/impl/entries/type.ts:目录条目类型落点(#767 W11b2a)。
3
+ *
4
+ * 目录外消费经 catalog/interface.ts 门面转出。
5
+ */
6
+ /** 目录中的单服务器条目。 */
7
+ export interface CatalogServer {
8
+ /** 发现时间戳。 */
9
+ discoveredAt: number;
10
+ /** 工具列表(裸名 → 描述 + schema 摘要)。 */
11
+ tools: Map<string, CatalogTool>;
12
+ /** 发现失败原因(unavailable 段)。 */
13
+ unavailable?: string;
14
+ }
15
+ /** 目录中的单工具。 */
16
+ export interface CatalogTool {
17
+ description: string;
18
+ inputSchema: Record<string, unknown>;
19
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * dsh-mcp-manager — catalog/impl/history/index.ts:会话内目录历史定位(#664 阶段 5)。
3
+ *
4
+ * 自 src/catalog.ts 拆出(history 域):从会话持久化日志倒序找最后一条**可见**
5
+ * 的能力目录消息——目录注入去重的权威来源。新旧两代 source 形态都认(#723)。
6
+ */
7
+ import type { CatalogSourceLike } from "../entries/index.js";
8
+ /** 目录历史查询结果。 */
9
+ export interface CatalogHistoryResult {
10
+ visibleDigest?: string;
11
+ published: boolean;
12
+ }
13
+ /** agent 最小面(session.snapshotEvents() 倒序找目录消息;0.1.2-rc.1 起 events getter 移除)。 */
14
+ export interface CatalogAgent {
15
+ session?: {
16
+ surface?: {
17
+ nodes?: unknown[];
18
+ };
19
+ snapshotEvents?: () => ReadonlyArray<{
20
+ type?: string;
21
+ seq?: unknown;
22
+ data?: {
23
+ source?: CatalogSourceLike;
24
+ };
25
+ }>;
26
+ };
27
+ }
28
+ /**
29
+ * 从会话持久化日志(agent.session.snapshotEvents())倒序找最后一条**可见**的
30
+ * 能力目录消息。**这是去重的权威来源**(与官方 dsh-tool-skill catalogHistory
31
+ * 同构):
32
+ * - decision.messages 只含本轮新消息,历史目录消息不在其中——用它定位会导致每轮重复注入;
33
+ * - 可见性(surface.nodes)过滤:compaction/resume 后旧目录不可见 → visibleDigest 为空 → 重新注入;
34
+ * - 只认 snapshot 形态的目录消息(旧 kind:mcp-catalog 落盘走修复脚本迁移)。
35
+ */
36
+ export declare function catalogHistory(agent: CatalogAgent | undefined): CatalogHistoryResult;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * dsh-mcp-manager — catalog/impl/injection/index.ts:能力目录注入决策(#664 阶段 5)。
3
+ *
4
+ * 自 src/catalog.ts 拆出(injection 域):pre-step 监听器的目录注入决策纯函数,
5
+ * 完全复刻官方 dsh-tool-skill 的 catalog 语义(根治重复注入)。
6
+ */
7
+ import type { CatalogCache, SupervisorLite } from "../entries/index.js";
8
+ import type { CatalogAgent } from "../history/index.js";
9
+ /** 会话消息最小面(pre-step decision.messages / session.snapshotEvents())。 */
10
+ export interface CatalogMessage {
11
+ id?: unknown;
12
+ role?: string;
13
+ content?: Array<{
14
+ type?: string;
15
+ text?: string;
16
+ }>;
17
+ source?: {
18
+ kind?: unknown;
19
+ plugin?: unknown;
20
+ form?: unknown;
21
+ entries?: unknown;
22
+ sections?: unknown;
23
+ };
24
+ }
25
+ /** pre-step 决策最小面。 */
26
+ export interface CatalogDecision {
27
+ kind: string;
28
+ messages: CatalogMessage[];
29
+ }
30
+ /**
31
+ * 目录注入决策(纯函数,pre-step 监听器薄调用,便于单测)。
32
+ * 完全复刻官方 dsh-tool-skill 的 catalog 语义(根治重复注入):
33
+ * 1. 历史(session.snapshotEvents())digest 相同 → 本轮不注入(撤销本轮已注入的)——**去重源是历史而非本轮消息**;
34
+ * 2. 历史 digest 不同 → 注入"更新"消息(声明替换旧目录);
35
+ * 3. 从未发布且无服务器 → 不注入;
36
+ * 4. compaction/resume 后旧目录不可见 → 重新注入(events-based 重建)。
37
+ * @param decision next() 的决策。
38
+ * @param messages 本轮输入消息(签名兼容)。
39
+ * @param supervisors manager.supervisors。
40
+ * @param maxEntries 目录条目上限。
41
+ * @param cache 目录缓存。
42
+ * @param agent pre-step 的 agent(session.snapshotEvents() 来源)。
43
+ * @returns 新决策。
44
+ */
45
+ export declare function resolveCatalogInjection(decision: CatalogDecision, messages: CatalogMessage[], supervisors: Map<string, SupervisorLite>, maxEntries?: number, cache?: CatalogCache, agent?: CatalogAgent): CatalogDecision;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * dsh-mcp-manager — server/catalog/impl/search/type.ts:检索输出类型落点(#767 W11b2a)。
3
+ *
4
+ * 目录外消费经 catalog/interface.ts 门面转出。
5
+ */
6
+ /** ws_mcp_search 单条命中。 */
7
+ export interface SearchHit {
8
+ server: string;
9
+ tool: string;
10
+ description: string;
11
+ inputSchema: Record<string, unknown>;
12
+ score: number;
13
+ matchedTerms: string[];
14
+ fresh: boolean;
15
+ }
16
+ /** ws_mcp_list 的单个工具条目(完整清单只给摘要,防上下文膨胀)。 */
17
+ export interface ListToolEntry {
18
+ tool: string;
19
+ description: string;
20
+ /** 工具级被用户禁用(独立于服务器级 enabled;仅在禁用时置位)。 */
21
+ disabled?: boolean;
22
+ }
23
+ /** ws_mcp_list 的单个服务器条目。 */
24
+ export interface ListServerEntry {
25
+ /** @<root>/<server> 全名。 */
26
+ server: string;
27
+ /** 用户已禁用(工具来自 last-good 目录缓存,明示)。 */
28
+ disabled?: boolean;
29
+ /** 发现失败原因(unavailable 段)。 */
30
+ unavailable?: string;
31
+ tools: ListToolEntry[];
32
+ /** 工具数被 perServerLimit 截断。 */
33
+ toolsTruncated: boolean;
34
+ }
35
+ /** ws_mcp_detail 的单工具详情(完整 inputSchema)。 */
36
+ export interface ToolDetail {
37
+ /** @<root>/<server> 全名。 */
38
+ server: string;
39
+ /** 远端工具裸名(已归一化)。 */
40
+ tool: string;
41
+ description: string;
42
+ inputSchema: Record<string, unknown>;
43
+ /** 目录是否新鲜(TTL 内)。 */
44
+ fresh: boolean;
45
+ /** 用户已禁用。 */
46
+ disabled?: boolean;
47
+ }
48
+ /** ws_mcp_list 输出(多单元合并的完整盘点)。 */
49
+ export interface ListCatalogResult {
50
+ /** 当前工作空间 root;无项目 cwd 时为 "@global"。 */
51
+ workspace: string;
52
+ servers: ListServerEntry[];
53
+ totalServers: number;
54
+ totalTools: number;
55
+ /** 任一服务器截断即为 true。 */
56
+ toolsTruncated: boolean;
57
+ /** 空返回时给模型的明确提示。 */
58
+ message?: string;
59
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * dsh-mcp-manager — catalog/impl/service/index.ts:目录域端口持有者(#767 B2a-wire W4)。
3
+ *
4
+ * 域内实现经 `catalogPorts.get()` 取数,写入只发生在组合根入口顶层的 `installCatalog`
5
+ * (见 `src/index.ts`)。形态照 `server/upgrade/impl/service/` 的 runner:模块级只有一个
6
+ * `const` 实例、状态收进实例字段(I9),装配与复位只经方法(方法内赋值)。
7
+ */
8
+ import type { CatalogDeps } from "../../deps.js";
9
+ /** 目录域端口表:装配一次、域内多处读。 */
10
+ declare class CatalogPorts {
11
+ /** 未装配时保持 undefined——「没装配」与「装配了空实现」必须可区分(I6)。 */
12
+ private deps;
13
+ /** 装配:组合根递入静态模块引用;重复装配是编程错误,当场暴露。 */
14
+ install(deps: CatalogDeps): void;
15
+ /** 卸载:只复位装配标记,本域没有别的活资源要释放。 */
16
+ release(): void;
17
+ /**
18
+ * 域内取数的唯一入口。未装配即抛错而不是回落默认值:默认值会让「组合根漏装」表现成
19
+ * 行为正常但参数不对(目录 TTL 与检索/装箱限额静默换值),症状与本插件毫无字面关联。
20
+ */
21
+ get(): CatalogDeps;
22
+ }
23
+ /** 本域唯一的装配实例:类不外放,外部 new 不出第二份端口表。 */
24
+ export declare const catalogPorts: CatalogPorts;
25
+ export {};
@@ -0,0 +1,45 @@
1
+ /**
2
+ * dsh-mcp-manager — catalog/interface.ts:模型面+目录域唯一对外引用面(D10,#664 阶段 5)。
3
+ *
4
+ * 目录域 = 能力目录条目/渲染(entries)+ digest(digest)+ 会话内历史定位
5
+ * (history)+ 注入决策(injection)+ 注入端缓存视图(cache-view)+ 检索函数族
6
+ * (search),其中 entries/digest/history/injection/cache-view 五块住 impl/<块>/index.ts。
7
+ * 目录外模块**只能**从这里引用(verify-dir-imports 静态强制);工具级禁用裁决
8
+ * (isToolDenied 等,#767 笔 2 后是唯一裁决)归执行管道域的 authorize 块。
9
+ *
10
+ * search 是本域唯一**暂留域根**的块——B2.4 就地重构的刻意偏差,不是漏做:它当时是
11
+ * fileCycles 那条环签名(catalog/interface.ts|catalog/search.ts|connection/interface.ts|
12
+ * connection/runtime/interface.ts|connection/runtime/middleware.ts)的成员,搬进
13
+ * impl/search/ 会让签名变成 catalog/impl/search/index.ts|... → verify-dir-imports 判
14
+ * 「新增未登记证据」且 --write-baseline 拒写(附录 G·G16 同族:证据 id 路径派生)。
15
+ * W4 装上 ConnectionPort 后该环已断(本笔实测叶子模块级 / 文件级值环均归零,基线同笔清理),
16
+ * 搬进 impl/search/ 不再制造证据位移;它改的是模块 id 与目录形态,与 B2b 的原子搬迁同笔。
17
+ */
18
+ import type { CatalogDeps } from "./deps.js";
19
+ /**
20
+ * 装配目录域:把组合根持有的三组端口写入域内注册表(见 impl/service)。组合根在
21
+ * `src/index.ts` 顶层调用,模块求值期即完成——三条 Port 全是静态模块引用,不需要宿主 ctx。
22
+ * 宿主能力(工具注册表读口 / 日志出口 / 落盘路径)都不在端口内:它们是本域声明的**入参契约**,
23
+ * 由 connection 在调用点构造递入(同 CatalogViewHost 的口径,见 deps.ts 头注释)。
24
+ *
25
+ * 为什么不是 `export async function`:注入面对账(verify-dir-imports 的
26
+ * analyzeInjectionFaces)按 `export function installXxx(` 采点,`async` 前缀会让这条对账
27
+ * 静默失明(附录 G·G12)。本域装配是纯同步写标记,签名保持同步形态即可。
28
+ */
29
+ export declare function installCatalog(deps: CatalogDeps): void;
30
+ /** 卸载目录域。只复位装配标记:本域读的是外部递进来的能力,没有活资源要释放。 */
31
+ export declare function releaseCatalog(): void;
32
+ export { DEFAULT_ANNOUNCE_CATALOG, DEFAULT_CATALOG_MAX_ENTRIES, CATALOG_SUMMARY_MAX_CHARS, CATALOG_SUMMARY_PER_TOOL_CHARS, CATALOG_ENTRY_MAX_CHARS, summarizeToolDescriptions, composeCatalogEntries, renderMcpCatalogMessage, renderMcpCatalogUpdate, escapeCatalogText, findCatalogMessage, readCatalogEntries, isCatalogSource, resolveCatalogEntries, CATALOG_SOURCE_PLUGIN, CATALOG_SOURCE_KIND, CATALOG_SECTION_NAME, } from "./impl/entries/index.js";
33
+ export type { CatalogEntry, SupervisorLite, CatalogCache, CatalogSourceLike, } from "./impl/entries/index.js";
34
+ export { digestCatalogEntries } from "./impl/digest/index.js";
35
+ export { catalogHistory } from "./impl/history/index.js";
36
+ export type { CatalogHistoryResult, CatalogAgent } from "./impl/history/index.js";
37
+ export { resolveCatalogInjection } from "./impl/injection/index.js";
38
+ export type { CatalogMessage, CatalogDecision } from "./impl/injection/index.js";
39
+ export { makeCatalogViewFor, catalogCacheFile } from "./impl/cache-view/index.js";
40
+ export type { CatalogViewHost, CatalogViewResolver } from "./impl/cache-view/index.js";
41
+ export { scoreTool, searchCatalog, searchCatalogMulti, listCatalog, findToolDetail, isCatalogFresh, boundCatalogTools, } from "./search.js";
42
+ export { catalogDirectory } from "./impl/directory/index.js";
43
+ export type { SchemaView, RegisteredProjectionInput } from "./impl/directory/index.js";
44
+ export type { CatalogServer, CatalogTool } from "./impl/entries/type.js";
45
+ export type { SearchHit, ListToolEntry, ListServerEntry, ToolDetail, ListCatalogResult, } from "./impl/search/type.js";
@@ -0,0 +1,108 @@
1
+ /**
2
+ * dsh-mcp-manager — catalog/search.ts:能力目录检索函数族(#664 阶段 5)。
3
+ *
4
+ * 自 src/middleware-utils.ts 迁出(catalog 域检索族):打分/单/多单元检索/
5
+ * 完整盘点/单工具详情/新鲜判定/装箱。工具级禁用裁决(isToolDenied 等)与
6
+ * globMatch 归 pipeline(authorize 块)。B10 截断事实
7
+ * 口径随迁保持「恰好命中 limit 不误报」。
8
+ */
9
+ import type { CatalogServer, CatalogTool, ListCatalogResult, ListServerEntry, SearchHit, ToolDetail } from "./interface.js";
10
+ import type { ProjectUnit } from "../connection/interface.js";
11
+ import type { DisabledToolsMap } from "../store/interface.js";
12
+ /** 跨字段打分:query 词命中 server 名 / 工具名 / description / 参数名。
13
+ * 中文(无空格分词):query 连续中文串在原始描述中 substring 匹配即可命中
14
+ * (修复:原实现把连续中文当单个 token,中文召回率接近零)。 */
15
+ export declare function scoreTool(query: string, server: string, toolName: string, tool: CatalogTool): {
16
+ score: number;
17
+ matchedTerms: string[];
18
+ };
19
+ /** 连续中文段命中原始文本即计 2 分(≥2 字才算命中);一个都没命中返回 undefined
20
+ * ——让调用方回落分词打分(中文 query 同时含英文词时两路都试)。 */
21
+ export declare function scoreCjkSegments(segments: string[], haystack: string): {
22
+ score: number;
23
+ matchedTerms: string[];
24
+ } | undefined;
25
+ /** 词元命中原始文本即计 1 分(≥2 字才算命中,单字词元不计)。 */
26
+ export declare function scoreTerms(terms: string[], haystack: string): {
27
+ score: number;
28
+ matchedTerms: string[];
29
+ };
30
+ /** 检索目录:query 为空 → 能力摘要表(每服务器前 N 个工具)。
31
+ * 单 root 实现(searchCatalogMulti 循环调用;兼容既有测试)。
32
+ * truncated:任一服务器存在被 limit 裁掉的结果即 true(B10 截断事实,
33
+ * 供调用方精确标注「是否因 limit 裁掉」——恰好命中 limit 不误报)。 */
34
+ export declare function searchCatalog(units: Map<string, ProjectUnit>, root: string, query: string, limit: number): {
35
+ results: SearchHit[];
36
+ unavailable: Array<{
37
+ server: string;
38
+ reason: string;
39
+ }>;
40
+ truncated: boolean;
41
+ };
42
+ /** 多单元合并检索(项目 root 单元 + @global 单元合并查询)。
43
+ * 与 searchCatalog 同语义,仅数据源扩展为多个 root。
44
+ * 单 root 直接委托 searchCatalog(保持原顺序,不引入跨单元排序变化);
45
+ * 多 root 合并后统一排序并按全局 limit 截断(truncated=合并后曾有超限结果)。 */
46
+ export declare function searchCatalogMulti(units: Map<string, ProjectUnit>, roots: readonly string[], query: string, limit: number): {
47
+ results: SearchHit[];
48
+ unavailable: Array<{
49
+ server: string;
50
+ reason: string;
51
+ }>;
52
+ truncated: boolean;
53
+ };
54
+ /** 工具级禁用标注判定(本 root 段 + @global 段并集命中即禁用;@global 自身不重复继承)。 */
55
+ export declare function isToolDisabledForEntry(disabledTools: DisabledToolsMap | undefined, root: string, serverName: string, toolName: string): boolean;
56
+ /**
57
+ * 完整盘点:列出当前工作空间全部服务器 + 每台完整工具清单(不受关键词/limit
58
+ * 截断服务器,工具数受 perServerLimit 保护)。
59
+ * @param units 连接池单元集合。
60
+ * @param roots 参与盘点的 root 列表(当前项目 root + @global)。
61
+ * @param serverFilter 可选:@<root>/<server> 全名或裸名过滤。
62
+ * @param toolLimit 每服务器工具条数上限(>0;超过置 toolsTruncated)。
63
+ * @param emptyHint 空返回时的 message。
64
+ * @param disabledTools 用户工具级禁用映射(root → server → Set<tool>);
65
+ * 命中条目在工具行标注禁用(供模型感知)。
66
+ * @throws 全名 root 不属于当前 roots → 路由一致性错误(与 ws_mcp_call 口径一致)。
67
+ */
68
+ export declare function listCatalog(units: Map<string, ProjectUnit>, roots: readonly string[], serverFilter: string | undefined, toolLimit: number, emptyHint: string, disabledTools?: DisabledToolsMap): ListCatalogResult;
69
+ /** 每服务器工具条数上限:非有限数或非正回落缺省;正数向下取整(历史口径)。 */
70
+ export declare function safeToolLimit(toolLimit: number): number;
71
+ /** 该 root 是否参与盘点:显式过滤集命中即参与,无过滤集则全参与。 */
72
+ export declare function rootParticipates(root: string, rootSet: Set<string> | undefined): boolean;
73
+ /** 盘点过滤:serverFilter 为空即全收;给定后裸名或 @全名任一命中即收。 */
74
+ export declare function matchesServerFilter(serverName: string, root: string, serverFilter: string | undefined, fullServerName: (root: string, server: string) => string): boolean;
75
+ /** 单台服务器的盘点条目:用户禁用标注 + 目录失败原因,或工具清单(含截断与工具数结算)。 */
76
+ export declare function buildListServerEntry(serverName: string, root: string, catalog: CatalogServer, userDisabled: ReadonlySet<string>, safeLimit: number, disabledTools: DisabledToolsMap | undefined, fullServerName: (root: string, server: string) => string): {
77
+ entry: ListServerEntry;
78
+ truncated: boolean;
79
+ toolCount: number;
80
+ };
81
+ /** 盘点定序比较器:root 出现序优先(不在列表里的排后),同 root 内按裸名升序。 */
82
+ export declare function listOrderComparator(rootIndex: ReadonlyMap<string, number>, parseFullServerName: (full: string) => {
83
+ root: string;
84
+ server: string;
85
+ } | undefined): (a: ListServerEntry, b: ListServerEntry) => number;
86
+ /** 条目排序键两格:root 出现序(不在 roots 列表里的排到末尾)+ root 内裸名。 */
87
+ export declare function listOrderKey(entry: ListServerEntry, rootIndex: ReadonlyMap<string, number>, parseFullServerName: (full: string) => {
88
+ root: string;
89
+ server: string;
90
+ } | undefined): {
91
+ rootOrder: number;
92
+ server: string;
93
+ };
94
+ /**
95
+ * 单工具详情:按 @<root>/<server> + tool 裸名精确命中,返回完整 inputSchema。
96
+ * 错误三分:
97
+ * 1. server 发现失败(catalog.unavailable)→ 附原因;
98
+ * 2. 单元/服务器未发现 → 「server 未连接或未发现」;
99
+ * 3. 工具不存在 → 「tool 不存在」。
100
+ * @param units 连接池单元集合。
101
+ * @param root 目标 root(可为 @global)。
102
+ * @param server @<root>/<server> 全名。
103
+ * @param tool 远端工具裸名(兼容 mcp__ 前缀,复用 normalizeToolName)。
104
+ */
105
+ export declare function findToolDetail(units: Map<string, ProjectUnit>, root: string, server: string, tool: string): ToolDetail;
106
+ /** 目录里没有可用工具时的错误三分:发现失败(附原因)> 用户禁用(附说明)> 未连接。 */
107
+ export declare function toolDetailMissError(catalog: CatalogServer | undefined, server: string, userDisabled: boolean): Error;
108
+ export { boundCatalogTools, isCatalogFresh } from "./impl/directory/index.js";
@@ -0,0 +1,85 @@
1
+ /**
2
+ * dsh-mcp-manager — 插件 Config schema 与配置归一化(纯函数,单一事实源)。
3
+ *
4
+ * 插件自身 Config(cordis 配置注入入口)与浮窗 UI 配置的校验/归一化/默认值;
5
+ * 类型自 types.ts 取(防循环引用),placement-math 提供层级 clamp 与默认层级。
6
+ */
7
+ import z from "schemastery";
8
+ import type { ClientUiConfig } from "../../shared/interface.js";
9
+ import type { UiPlacementConfig } from "./impl/ui/type.js";
10
+ /** 默认浮窗 UI 配置(与升级前一致,无回归;层级基准引用 placement-math 单一事实源,
11
+ * DEFAULT_Z_INDEX_BASE=10 对应 CSS 默认 z-index:10)。 */
12
+ export declare const DEFAULT_UI_CONFIG: UiPlacementConfig;
13
+ /**
14
+ * 归一化浮窗 UI 配置(纯函数,可单测)。
15
+ * 兼容三种形态:新 `Config.ui` 嵌套、旧隐藏命名空间的扁平 `position/offset`、
16
+ * 客户端扁平 `position/offsetX/offsetY/blankY`。非法或缺失 → 安全回退默认,不抛。
17
+ */
18
+ export declare function normalizeUiConfig(raw: unknown): ClientUiConfig;
19
+ /**
20
+ * 把客户端扁平形态({position, offsetX, offsetY, blankY})归一化为写入 `Config.ui`
21
+ * 的嵌套补丁({position, offset:{x,y,blankY}})。走 normalizeUiConfig 的净化为唯一
22
+ * 入口:非法值安全回退默认,负数 clamp 到 0,四舍五入。
23
+ */
24
+ export declare function buildConfigUiPatch(raw: unknown): UiPlacementConfig;
25
+ /** 面板垂直定位纯函数(供 smoke 断言翻转分支;clamp 到视口内,不溢出)。
26
+ * 实现自持于包内 src/shared/placement-math.ts(shared-leaf 叶子约束),此处
27
+ * re-export 保持 index.ts 导出链不变。 */
28
+ export { panelTopForAnchor } from "../../shared/interface.js";
29
+ /**
30
+ * 插件 Config schema(标准 cordis 配置注入入口;含 `ui` 子对象)。
31
+ * 官方 ConfigForm 只开放 ui child;根级运行时字段全部 disabled。
32
+ */
33
+ export declare const Config: z<{
34
+ enabled: boolean;
35
+ announceToAgent: boolean;
36
+ storePath: string;
37
+ announceCatalog: boolean;
38
+ catalogMaxEntries: number;
39
+ debug: {
40
+ callStats: boolean;
41
+ statsFile: string;
42
+ };
43
+ ui: UiPlacementConfig;
44
+ }>;
45
+ /**
46
+ * 默认配置(键集 = schema 中带 .default() 的字段)。从 schema 归一化**空输入**派生,
47
+ * 不手写第二份默认值——默认值只写在上面的 .default(...) 里,改一处即改两处。
48
+ * storePath 无默认值,故键集比 schema 字段数少 1(config-matrix 门禁的 N1/N2 锁这条不变式)。
49
+ */
50
+ export declare const DEFAULT_CONFIG: {
51
+ enabled: boolean;
52
+ announceToAgent: boolean;
53
+ storePath: string;
54
+ announceCatalog: boolean;
55
+ catalogMaxEntries: number;
56
+ debug: {
57
+ callStats: boolean;
58
+ statsFile: string;
59
+ };
60
+ ui: UiPlacementConfig;
61
+ };
62
+ /**
63
+ * 归一化:把外部输入按 schema 校验并补默认值。
64
+ * 与 normalizeUiConfig 分工不同:后者只处理 ui 子面(设置页提交的局部 patch),
65
+ * 本函数给出一份**完整**配置。
66
+ */
67
+ export declare function normalizeConfig(input: unknown): {
68
+ enabled: boolean;
69
+ announceToAgent: boolean;
70
+ storePath: string;
71
+ announceCatalog: boolean;
72
+ catalogMaxEntries: number;
73
+ debug: {
74
+ callStats: boolean;
75
+ statsFile: string;
76
+ };
77
+ ui: UiPlacementConfig;
78
+ };
79
+ /** 只接受布尔值的**顶层**配置键(客户端 UI 按它渲染开关);嵌套的 debug.callStats 不是顶层键。 */
80
+ export declare const BOOLEAN_KEYS: readonly string[];
81
+ /**
82
+ * 非负整数键及其上界:本包**没有产品上界**——catalogMaxEntries 只被要求是正整数,
83
+ * 上界是机器/内存极限而非产品约束,编一个上界等于造假事实。空对象是显式声明而不是遗漏。
84
+ */
85
+ export declare const COUNT_LIMITS: Record<string, number>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * dsh-mcp-manager — server/config/impl/env/index.ts:配置模板预展开与凭据词根(#767 S1-1)。
3
+ *
4
+ * ${ENV} 模板必须在配置交给连接层之前展开:官方 dsh-mcp-client 的 env / headers 只接受
5
+ * 字面量,而落盘配置又必须保持模板形态(展开结果含明文凭据,写盘即泄漏)。展开点归本域,
6
+ * 是因为「哪些字段含模板」是配置面知识;连接域不再持有第二份定义。
7
+ *
8
+ * 凭据词根(SECRET_ENV_NAME)随本块一并迁入:它是 stdio 子进程环境过滤的判据,与
9
+ * ${ENV} 展开同属「配置值出入子进程」这一件事。
10
+ */
11
+ import type { ServerConfig } from "../model/type.js";
12
+ /** 凭据形状的环境变量名(父进程环境不自动透传给 MCP 子进程)。 */
13
+ export declare const SECRET_ENV_NAME: RegExp;
14
+ /** 展开字符串中的 ${ENV_NAME} 引用(未设置 → 空字符串),用于 header/env 值。 */
15
+ export declare function expandEnv(value: unknown): string;
16
+ /** 递归展开对象值中的 ${ENV_NAME} 引用。 */
17
+ export declare function expandEnvObject(input: Record<string, unknown> | undefined): Record<string, string>;
18
+ /**
19
+ * 展开一条服务器配置的 env 与 headers 模板,其余字段原样带上。
20
+ *
21
+ * 恒返回新对象:调用方拿着落盘配置就地改写,会让展开后的明文凭据随下一次 store.save()
22
+ * 落进配置文件——模板落盘、连接时才展开是本插件的凭据面不变量。
23
+ */
24
+ export declare function expandServerEnv(server: ServerConfig): ServerConfig;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * dsh-mcp-manager — server/config/impl/env/policy.ts:环境变量凭据策略门(#770-2 环境净化,B 相)。
3
+ *
4
+ * 两阶段校验中的第二阶段(第一阶段是 normalizeServer 的纯形状校验,不读环境):
5
+ * add / update / import 三个写边界在落盘前调用 assertEnvPolicy,对 env / headers /
6
+ * url / args 做「目标键 + 值 provenance」双审——用户裁决:边界拒绝 + 豁免表,拒绝静默过滤。
7
+ *
8
+ * 为什么不在 normalizeServer 里做:normalize 是纯函数,而本门要读父进程环境快照做展开后
9
+ * 审计(${VAR} 的值 provenance 只有读到快照才知道);纯函数里读环境会让归一结果随调用
10
+ * 时机漂移。形状问题归 normalize,环境策略问题归本门,两门职责不混。
11
+ *
12
+ * 双审口径(fail-closed,命中即抛错,绝不静默丢弃/置空):
13
+ * 1. 目标键审:键名按词精确匹配凭据词表(isSecretEnvName)。子串正则 SECRET_ENV_NAME 只作
14
+ * 候选快筛,确证必须走词表——MONKEY / TURKEY_SIZE / KEYBOARD 这类含 KEY 子串的正当名
15
+ * 在词级无命中,必须放行(误伤回归测试锁死)。
16
+ * 2. 值 provenance 审:值里的 ${VAR} 引用若指向凭据形名(非豁免),而目标键本身非凭据形
17
+ * (如 DEBUG: "${MY_SECRET}"),即秘密被塞进非秘密槽位——子进程会把它当普通数据,
18
+ * 且按名识别的脱敏/投影都认不出它,拦截。引用名是否已 set 不影响判定(unset 时展开
19
+ * 为空串正是「零值消费」陷阱:换个环境就变泄漏,fail-closed 按名拦截)。
20
+ * 3. 活秘密查重:展开后的非空值若与某个凭据形父环境变量的活值逐字相等(如 MY_TOKEN 的
21
+ * 明文字面量与快照里 MY_TOKEN 相同),即把活秘密以明文 baked 进配置文件——轮转即漂移,
22
+ * 且与「模板落盘、连接时展开」的不变量相悖,拦截并指引改用同名模板。
23
+ * 豁免:凭据槽位经凭据引用取值(CONTEXT7_API_KEY: "${CONTEXT7_API_KEY}"、
24
+ * Authorization: "Bearer ${CONTEXT7_API_KEY}")是文档示例的合法形态,展开值等于活
25
+ * 秘密是预期结果,不在此列;空值("",客户端语义=继承父环境)不注册不比对。
26
+ *
27
+ * 报错文案只含键名/变量名与模板,不含任何字面量值:写边界的错误经路由统一错误边界
28
+ * (handleError → redactError)原样进 400 body,而被拒配置尚未落盘、其展开值不在脱敏
29
+ * 快照内——回显字面量即泄漏。模板形态("${MY_SECRET}")无秘密可泄,可以出现。
30
+ */
31
+ /** ${VAR} 引用抽取:字面量必须与 expandEnv 的替换口径逐字一致(门与展开同口径)。 */
32
+ export declare function extractEnvRefs(value: unknown): string[];
33
+ /**
34
+ * 名是否为凭据形(精确判定):豁免表优先 → 子串正则只作候选快筛 → 切词精确确证。
35
+ *
36
+ * 切词规则:大写后按非字母数字切分(下划线/连横线/点/空格都是词界),每词去尾数后查表。
37
+ * 去尾数(TOKEN2 → TOKEN)收的是「带编号的凭据」常见写法;TURKEY2 → TURKEY 照样不命中,
38
+ * 不引入新误伤。MONKEY / TURKEY_SIZE / KEYBOARD / AUTHOR_NAME 在此全灭(子串命中但无整词)。
39
+ */
40
+ export declare function isSecretEnvName(name: unknown): boolean;
41
+ /**
42
+ * 写边界凭据策略门(add / update / import 同门;normalize 保持纯形状校验不调本函数;
43
+ * registerServer 内存态不调本函数,见 manager.registerServer 注释)。
44
+ *
45
+ * @param env 归一化后的 env 表(add/update 传 normalize 产物;import 经 parseClaudeJson →
46
+ * manager.add/update 间接同门,不直调)。
47
+ * @param headers 归一化后的 headers 表。
48
+ * @param snapshot 父环境快照(缺省 process.env;单测注入隔离快照,离线可跑)。
49
+ * @param url 归一化后的 url(只审 userinfo/查询值中的活秘密值 + 引用污染;缺省跳过)。
50
+ * @param args 归一化后的 args(只审秘密 flag 值等于活秘密值 + 引用污染;缺省跳过)。
51
+ * @throws 命中即抛错(fail-closed):文案含哪个键/槽位、为什么被拒、怎么改;不含字面量值
52
+ * (400 body 经 redactError 原样返回,被拒配置不在脱敏快照内,回显即泄漏)。
53
+ */
54
+ export declare function assertEnvPolicy(env: Record<string, unknown> | undefined, headers: Record<string, unknown> | undefined, snapshot?: Record<string, string | undefined>, url?: unknown, args?: unknown): void;