dsh-tool-manager 1.2.12 → 1.3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.3.0] - 2026-11-20
9
+
10
+ ### Added
11
+
12
+ - 新增「复制配置」:在工具目录面板「手动分组」旁,可把当前 Preset 的全部按需组和已关闭工具清单复制到一个或多个其他 Preset。目标配置整份覆盖;复制时按目标实际拥有的工具裁剪组员,整组无可用工具则跳过并在结果中提示;复制只写入页面草稿,点击「保存」后生效。该功能回应 issue #5 的跨 Preset 复用诉求,采用显式复制而非新增 `global` 策略桶,`tool-manager.json` 结构与运行时策略解析保持不变。
13
+ - 新增「重置配置」:清空当前 Preset 的全部按需组和已关闭工具,恢复为所有工具常开、未分组;只修改页面草稿,点击「保存」后生效。
14
+
15
+ ### Fixed
16
+
17
+ - 修复「折叠工具后,按族名注册的 `tool:*` 提示词段仍然留在系统提示词里」(issue #4)。`dsh-tool-jobs` 的 `tool:jobs`、`dsh-tool-goal` 的 `tool:goal`、`dsh-tool-session-query` 的 `tool:session-query`、`dsh-tool-terminal` 的 `tool:pty`、`dsh-terminal-panel` 的 `tool:pty-panel`、`dsh-tool-schedule` 的 `tool:schedule` 都以能力族而不是单个工具命名,而旧实现把 `tool:` 后面的整段当成工具名,于是 `owners=["jobs"]` 永远匹配不到任何隐藏工具,模型仍会读到「可以调用 `job_output` / `session_search` / `create_goal`」的指令,真正调用却被 guard 拒绝。现在包装 `systemPrompt.section()` 与 `tools.register()`,按**注册该段落的 plugin entry / fiber** 收集它注册的工具,作为该段落的工具族;族内全部被隐藏或折叠时删除段落,任一可见则保留。DSH 的默认 `preset-standard` 属于 web-app bundle,可能在 profile bundle 应用前就完成注册,也可能由 `DefaultPresetMount` 在本插件启动后才组合出来;因此启动时先从仍存活的 Cordis fiber registry 恢复历史注册,并在每次提示词组装发现 `systemPrompt` / `tools` 层的名字集合变化时按当前层再懒恢复一次:读取每个 plugin entry 的 callback 及其委托模块函数中的 section / `defineTool` 声明,再按 `fiber.getEffects()` 记录的 section/register 顺序精确配对,解决「明明是新启动的会话,`tool:jobs` / `tool:goal` 段落仍然存在」的启动顺序问题。该恢复不读取 section 正文、不做词干/前后缀/标签猜测,也不维护任何「包名 → 工具列表」的硬编码表;`tool:pty-panel` 这类 section 与工具分属不同 helper 的插件按模块函数声明配对。无法从声明恢复时保持旧行为(不误删)。issue #3 的「子代理 baseline 被上游 `restrict()` 裁空、按 Preset 策略判定折叠」路径保持不变。
18
+
19
+ ## [1.2.13] - 2026-11-10
20
+
21
+ ### Fixed
22
+
23
+ - 修复「按需组的开放状态读不出来」的问题:恢复逻辑只按 provider 形状读取 `tool/result`(`message.content` 里的 `tool-result` 块),而 DSH 落盘的是它自己的工具消息(`toolCallId` / `isError` 在 message 上,`content` 是 text/image 块)。于是原生 `tool_list` 调用在真实会话里一条都匹配不上,`restoredExposureNames()` 始终返回空——不只是 fork,重启 DSH 并恢复同一 Session 后组也照样隐藏。现在两种形状都读,错误结果(`isError`)仍然不算开放。
24
+ - 修复「`tool_list` 打开的按需组在 fork 出来的子会话里重新隐藏」的问题。此前恢复开放状态时跳过 `inheritedEventCount` 之前的 fork 前缀,于是子会话的历史里明明有一条成功的 `tool_list` 结果(写着这些工具「在本会话内可用」),工具却不在该步的工具集合里,模型调用还会被 guard 拒绝。现在恢复会读完整份 Session 日志,fork 子会话沿用 fork 点之前已开放的组;fork 点之后父 Session 新打开的组不在子会话日志里,仍保持隐藏,全新会话没有前缀,行为不变。
25
+
8
26
  ## [1.2.12] - 2026-11-06
9
27
 
10
28
  ### Fixed
package/DESIGN.md CHANGED
@@ -56,17 +56,24 @@ mcp__<serverName>__<rawToolName>
56
56
 
57
57
  提示词里不只有工具声明:`@deepseek-ai/dsh-mcp-resources` 会注册 `mcp-resource-servers` 段(列出资源服务器名,并让模型用三个共享资源工具),`@deepseek-ai/dsh-mcp-client` 会为每个服务器注册 `mcp:<server>` 段(服务器自带 instructions)。这些段落只在对应工具可用时才有意义;工具全部收进未打开的按需组或被关闭后,段落会诱导模型调用已经不存在的工具。
58
58
 
59
- DSH 的 section 注册只有 `name` / `order` / `text` / `interpolate`,没有“本段介绍哪些工具”的元数据,因此按命名约定归属(`src/runtime.ts` 的 `sectionToolOwners()`):
59
+ DSH 的 section 注册只有 `name` / `order` / `text` / `interpolate`,没有“本段介绍哪些工具”的元数据;`ToolDefinition` 也没有 owner/source 字段。因此归属从**注册身份**读取(`src/prompt-affinity.ts`):Cordis 的服务方法按调用方 context 绑定(`this.ctx` 就是调用方),包装 `SystemPrompt.prototype.section()` 与 `ToolsService.prototype.register()` 就能记下「这个段落由哪个插件 fiber 注册」「这个工具由哪个插件 fiber 注册」。官方工具包(`dsh-tool-jobs`、`dsh-tool-goal`、`dsh-tool-session-query`、`dsh-tool-terminal`、`dsh-terminal-panel`、`dsh-tool-schedule`)都在同一个 plugin entry(含它委托的模块函数)里注册 section 和工具,因此「同一 entry 声明并注册的工具」就是该段落的精确工具族,**不维护任何包名→工具名表**。
60
60
 
61
- - `tool:<name>`:DSH 为单个工具生成的说明段;
62
- - `mcp:<server>`:该服务器注册的全部 `mcp__<server>__*` 工具;
63
- - `mcp-resource-servers`:`list_mcp_resources` / `list_mcp_resource_templates` / `read_mcp_resource` 三个共享工具。
61
+ 但 DSH 的默认 `preset-standard`(以及 web-app 层的其他 preset 定义)属于 web-app bundle:它可能在 profile bundle 里的 `dsh-tool-manager` 应用之前就已经把 section 和工具注册完,也可能由 `DefaultPresetMount` 在插件启动之后才组合出来,启动时 `systemPrompt.layers` / `tools.layers` 还可能是空的。此时不能把「层里暂时没有」当成「段落不存在」。因此 `src/prompt-affinity.ts` 从**仍然存活的 Cordis fiber registry** 恢复注册:每个 fiber 保留 plugin callback,`fiber.getEffects()` 记录该 fiber 调用 `systemPrompt.section()` / `tools.register()` 的精确顺序;解析 callback(以及 callback 委托的模块函数)里的 `name: "tool:..."` 声明和 `defineTool({ name: "..." })` 声明,按相同顺序配对,就得到每个 section 的真实工具集合。启动时先恢复一次;之后每次提示词组装调用 `lookup()` 时若发现 `systemPrompt` / `tools` 层的名字集合变化(例如默认 Preset 刚挂载),会按当前层再懒恢复一次。整个过程不读 section 的 `text`,不做词干、前后缀或标签猜测;找不到声明时保持旧行为,绝不猜测。
64
62
 
65
- 只有「该族全部工具都被隐藏」时才删除段落;族内还有任一工具可见就保留(例如只关闭一个 MCP 工具时,服务器说明仍然有效)。不属于任何工具族的段落、以及族内没有注册任何工具的段落一律保留,避免误删 persona、计划策略这类正文。
63
+ 归属按以下顺序解析:
66
64
 
67
- 归属与判据都不依赖 baseline 是否包含该工具(issue #3):`denyNames()` 只能拒绝**已存在**的名字,因为 `restrict()` 会拒绝未知工具;而子代理在 tool-manager install 之前就被 `childCtx.tools.restrict(toolFilter)` 裁过一次工具面,baseline 里可能一个成员都没有。因此段落判定额外读 **Preset 策略本身**——`disabled` 命中,或命中某个**未 open** 的组 patterns,就视为折叠,即使该工具不在 baseline。这样「折叠工具 = 折叠其说明段」按声明生效,与委派层裁了多少工具无关。
65
+ - `tool:<工具名>`:`<工具名>` 本身是真实工具(baseline 或策略字面名)时,只覆盖该工具;
66
+ - `tool:<族名>`:`<工具名>` 不是真实工具时,取「注册该 section 的 plugin entry 所声明并注册的全部工具」;该 entry 在观察器安装前或安装后才挂载时,都从 fiber 的 callback/effect 顺序和模块函数声明恢复,不读取 section 文字;
67
+ - `mcp:<server>`:该服务器注册的全部 `mcp__<server>__*` 工具(命名约定不变);
68
+ - `mcp-resource-servers`:`list_mcp_resources` / `list_mcp_resource_templates` / `read_mcp_resource` 三个共享工具(`dsh-mcp-resources` 的 section 和工具分属不同 child fiber,注册归属不适用,保留常量)。
68
69
 
69
- 族的成员从两处取并集:baseline 里实际继承到的名字 + 策略里写明的字面名(`disabled` 与不含 `*` 的 patterns)。若族在 baseline 与策略里都没有具体成员(只被通配符覆盖,例如 `mcp__playwright__*`),则只有当某个未 open 的组的 pattern 以 `mcp__<server>__` 开头时才删除该服务器的 instructions 段。
70
+ 只有「该族全部工具都被隐藏」时才删除段落;族内还有任一工具可见就保留(例如只关闭一个 MCP 工具时,服务器说明仍然有效)。不属于任何工具族的段落一律保留,避免误删 persona、计划策略这类正文。
71
+
72
+ 族名家族的成员不按 baseline 过滤(issue #3):`denyNames()` 只能拒绝**已存在**的名字,因为 `restrict()` 会拒绝未知工具;而子代理在 tool-manager install 之前就被 `childCtx.tools.restrict(toolFilter)` 裁过一次工具面,baseline 里可能一个成员都没有。因此段落判定额外读 **Preset 策略本身**——`disabled` 命中,或命中某个**未 open** 的组 patterns,就视为折叠,即使该工具不在 baseline。这样「折叠工具 = 折叠其说明段」按声明生效,与委派层裁了多少工具无关。
73
+
74
+ 归属只认该 section 所属 plugin entry 自己声明并注册的工具,不把正文里提到的其他插件工具算进来。例如 `tool:pty-panel` 的正文可能提到 `terminal_open`/`terminal_close`,但它们属于 `dsh-tool-terminal`,不会改变 `tool:pty-panel` 归 `dsh-terminal-panel` 的 `user_terminal_*` 工具这一事实;`user_terminal_*` 全隐藏时段落照常删除,避免用正文猜测把失效说明留下。
75
+
76
+ 若某 `tool:<族名>` 的 callback/模块声明无法恢复(例如插件动态拼接 section 名或工具名),该段回退到旧行为(按 label 自身判定),不会误删。恢复只会记录同一 plugin entry 的显式声明;任何成员可见都会保留,因此最坏情况是多留一段,不会删掉仍有效的说明。包装器只观察、不改写调用语义,且按原型各装一次;观察结果放在 `globalThis`(与 §2.6 的跨重载内存同一原则),插件重载不丢。
70
77
 
71
78
  ### 2.3 每个模型 step 都重新组装工具目录
72
79
 
@@ -82,7 +89,8 @@ Agent loop 在 `preStep()` 中**先** `systemPrompt.assemble()`,**再**跑 `ag
82
89
  - **静态 preset 规则**可以放在 standing scope;
83
90
  - **按会话临时曝光状态**必须应用在 Agent 自己的 scope;
84
91
  - `tool_list` 注册在 host 全局层(否则 PTC 生成 SDK 看不到),每个 live Agent 只维护该会话的打开状态,避免同 Preset 会话互相解锁;
85
- - Agent 安装时从该 Session 的持久事件日志恢复成功的 `tool_list` 调用,因此重启 DSH 并恢复同一 Session 后仍保持开放。原生调用通过成功配对的 `tool/call` + `tool/result` 恢复,PTC 调用通过成功的 `tool/ptc-dispatch` 恢复;fork 时跳过 `inheritedEventCount` 前缀,避免把父 Session 的临时开放状态带入子 Session。
92
+ - Agent 安装时从该 Session 的持久事件日志恢复成功的 `tool_list` 调用,因此重启 DSH 并恢复同一 Session 后仍保持开放。原生调用通过成功配对的 `tool/call` + `tool/result` 恢复,PTC 调用通过成功的 `tool/ptc-dispatch` 恢复。
93
+ - fork 子会话的日志包含被重放的父 Session 前缀(`inheritedEventCount` 之前),恢复时整份日志都读:子会话继承的是同一段对话,前缀里的 `tool_list` 结果已经告诉模型这些工具「在本会话内可用」,再隐藏就与模型读到的历史矛盾。fork 点之后父 Session 新打开的组不在子会话日志里,因此不会带入;全新会话没有前缀,仍从默认隐藏开始。
86
94
 
87
95
  ### 2.5 Preset inventory 已有只读基础,但没有写 API
88
96
 
@@ -234,7 +242,9 @@ DSH 内置文件/Web 等工具 guidance 会通过 `ctx.tools.get(name, scope)`
234
242
  - 同源 HTTP endpoint 提供 snapshot/save;
235
243
  - 保存携带文件存储 revision,拒绝 stale write,并以临时文件原子替换;
236
244
  - WebUI 不直接编辑 `agent.cordis.yml`,因此绝不会损坏 shipped preset;
237
- - 设置页支持搜索、常开/按需/关闭筛选、组内筛选勾选、以及 orphan disable 清理。
245
+ - 设置页支持搜索、常开/按需/关闭筛选、组内筛选勾选、以及 orphan disable 清理;
246
+ - 设置页支持把当前 Preset 的整份策略(全部按需组 + 关闭清单)复制到多个其他 Preset:目标配置整份覆盖,按目标实际工具裁剪组员、跳过空组,只修改页面草稿,保存时仍走同一份 `/save` 校验;不引入全局策略桶,也不改变 `tool-manager.json` 的 `presets` 结构;
247
+ - 设置页支持一键重置当前 Preset 的整份策略:清空全部按需组和关闭清单,恢复为所有工具常开、未分组;同样只修改页面草稿,保存后生效。
238
248
 
239
249
  生产版仍可:
240
250
 
@@ -287,7 +297,7 @@ DSH 内置文件/Web 等工具 guidance 会通过 `ctx.tools.get(name, scope)`
287
297
  1. 监听 `tools/change`,MCP 动态 tools/list 或插件 HMR 后刷新每个 Agent baseline;
288
298
  2. 设置页提示并一键清除 orphan disable;旧配置中的空组在草稿中标记为无效,必须补选工具或删除后才能保存;
289
299
  3. `tool_list` 支持 `query`,大组只返回 preview + 截断列表;
290
- 4. 打开后的组在当前会话一直可用,重启恢复同一 Session 时从成功的原生/PTC 工具事件重建;fork 不继承父 Session 的开放状态;策略更新不取消正在执行的工具;
300
+ 4. 打开后的组在当前会话一直可用,重启恢复同一 Session 时从成功的原生/PTC 工具事件重建;fork 沿用 fork 点之前的开放状态,fork 点之后父 Session 新打开的组不带入;策略更新不取消正在执行的工具;
291
301
  5. 自动命名和自动分组在执行前显示确认框,并允许配置 5–600 秒请求超时(默认 60/120 秒);Host 校验范围,超时及供应商中止会返回明确错误。
292
302
 
293
303
  仍待:
package/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  > DSH `0.2.2` 修改了提示词组装接口,插件相应改为过滤每一步的工具集合:无论工具由 Preset、MCP 还是插件按 Agent 自身作用域注册,被关闭或被按需组收起时都不会出现在模型的工具列表中,也无法被调用。
25
25
 
26
- 只介绍这些工具的提示词段落也会一起消失:`tool:<名称>` 单工具说明、MCP 服务器自带说明(`mcp:<服务器>`),以及 `mcp-resource-servers` 资源提示。判断以工具族为单位——族内还有任一工具可用时段落保留,全部隐藏时才删除。折叠按 Preset 策略判定,因此在委派子代理这类工具面已被上游裁剪的会话里同样生效。
26
+ 只介绍这些工具的提示词段落也会一起消失:`tool:<名称>` 单工具说明、按族名注册的 `tool:<族名>`(如 `tool:jobs`、`tool:goal`、`tool:session-query`、`tool:pty`、`tool:schedule`)、MCP 服务器自带说明(`mcp:<服务器>`),以及 `mcp-resource-servers` 资源提示。判断以工具族为单位——族内还有任一工具可用时段落保留,全部隐藏时才删除;族名段落按「注册该段落的 plugin entry 所声明并注册的工具」归属,默认 Preset 早于本插件挂载时从存活 Cordis fiber 的 callback/effect 顺序和模块函数声明精确恢复;若默认 Preset 在本插件启动后才挂载,则在下一次提示词组装发现 layer 变化时按当前层懒恢复。不读 section 正文、不维护固定工具名单。折叠按 Preset 策略判定,因此在委派子代理这类工具面已被上游裁剪的会话里同样生效。
27
27
 
28
28
  不同 Agent Preset 可以使用不同的工具配置。
29
29
 
@@ -39,6 +39,12 @@
39
39
 
40
40
  分组支持手动选择工具,也可以使用当前默认模型自动生成分组、名称和描述。调用模型前可以预览、编辑或重置提示词。
41
41
 
42
+ ### 跨 Preset 复制配置
43
+
44
+ 在工具目录面板点击「复制配置」,可以勾选一个或多个其他 Agent Preset,把当前 Preset 的全部按需组与已关闭工具清单复制过去。目标已有配置会被整份覆盖;复制会按目标实际拥有的工具裁剪组员,整组都没有可用工具时自动跳过并提示。复制只写入页面草稿,仍需点击「保存」才会生效。
45
+
46
+ 同一排的「重置配置」会清空当前 Preset 的全部按需组和已关闭工具,把它恢复为所有工具常开、未分组的状态;重置同样只修改页面草稿,点击「保存」后生效。
47
+
42
48
  ### 像 Skill 一样按需加载
43
49
 
44
50
  放进按需组的工具默认不会全部出现在模型上下文中。
@@ -59,7 +65,7 @@
59
65
  - 每个按需组必须至少包含一个当前可用且未关闭的工具,空组不能保存,也不会进入模型目录;
60
66
  - 一个工具只能属于一个按需组;已分组或已关闭的工具不能再加入其他组;
61
67
  - 开放后在当前会话中持续可用;重启 DSH 并恢复同一会话时,会根据该会话中成功的 `tool_list` 调用恢复开放状态;
62
- - 不会影响其他会话;新建会话或从当前会话 fork 出来的子会话仍从默认隐藏状态开始;
68
+ - 不会影响其他会话:新建会话仍从默认隐藏状态开始;从当前会话 fork 出来的子会话沿用 fork 点之前已开放的组(这段共享历史里本来就有成功的 `tool_list` 调用),fork 点之后父会话新打开的组不会带入;
63
69
  - 工具仍以原来的名称和参数运行;
64
70
  - 明确关闭的工具不会被按需组重新启用。
65
71
 
@@ -138,7 +144,7 @@ dsh plugin --profile desktop remove dsh-tool-manager
138
144
 
139
145
  在页面顶部选择需要配置的 Agent Preset。
140
146
 
141
- 每个 Preset 的工具策略相互独立。
147
+ 每个 Preset 的工具策略相互独立。配置好后,可以在工具目录面板使用「复制配置」把当前 Preset 的整份策略复制到其他 Preset。
142
148
 
143
149
  ### 2. 开启或关闭工具
144
150
 
@@ -168,7 +174,19 @@ dsh plugin --profile desktop remove dsh-tool-manager
168
174
 
169
175
  执行前可以预览并编辑提示词;默认提示词会随工具勾选实时更新,自定义后也可以一键重置。自动生成的结果会先显示预览。确认后只会加入页面草稿,不会立即写入配置。
170
176
 
171
- ### 5. 保存修改
177
+ ### 5. 重置或复制到其他 Preset
178
+
179
+ 点击「重置配置」并确认,可以清空当前 Preset 的全部按需组和已关闭工具,恢复为所有工具常开、未分组。重置只修改页面草稿,仍需点击「保存」。
180
+
181
+ 点击「复制配置」,弹出窗口会列出其他可用的 Agent Preset:
182
+
183
+ 1. 勾选要接收配置的目标 Preset;
184
+ 2. 查看每个目标的复制预览(会复制多少个组和关闭项、会跳过哪些缺少工具的组);
185
+ 3. 点击「复制到 N 个 Preset」。
186
+
187
+ 目标 Preset 的现有分组和关闭项会被整份覆盖。复制只修改当前页面草稿,完成后仍需点击「保存」才会写入配置。
188
+
189
+ ### 6. 保存修改
172
190
 
173
191
  工具开关或分组发生变化后,页面会显示“有未保存的修改”。
174
192
 
package/dist/client.js CHANGED
@@ -36,7 +36,7 @@ window.__ModuleLoader__.load({
36
36
  ".tm_modal_body{padding:0 16px 12px;display:flex;flex-direction:column;gap:10px;min-height:0;flex:1 1 auto;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;scrollbar-gutter:stable}",
37
37
  ".tm_modal_foot{padding:12px 16px 16px;display:flex;justify-content:flex-end;gap:8px;border-top:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.18));flex:0 0 auto}.tm_confirm_card{width:min(460px,100%)}.tm_timeout_field{display:flex;align-items:center;gap:8px}.tm_timeout_field .tm_input{max-width:120px;flex:0 0 120px}.tm_preview_body{padding-right:10px}.tm_preview_panel{flex:0 0 auto;overflow:visible}.tm_preview_meta{min-width:0;flex:1}.tm_preview_desc{margin-top:4px;white-space:normal;overflow-wrap:anywhere;word-break:break-word;color:var(--dsw-alias-label-secondary,#9097a4);font-size:12px;line-height:1.55}",
38
38
  ".tm_picker{min-height:180px;max-height:min(46vh,420px);overflow:auto;border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.18));border-radius:8px;background:var(--dsw-alias-bg-layer-1,rgba(128,128,128,.06))}",
39
- ".tm_pick{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.1))}.tm_pick:last-child{border-bottom:0}",
39
+ ".tm_pick{display:flex;gap:8px;align-items:flex-start;padding:8px 10px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.1))}.tm_pick:last-child{border-bottom:0}.tm_copy_meta{font-size:11px;color:var(--dsw-alias-label-secondary,#9097a4);line-height:1.45;margin-top:3px;overflow-wrap:anywhere}",
40
40
  ".tm_banner{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);z-index:10001;display:flex;align-items:flex-start;gap:14px;width:min(720px,calc(100vw - 32px));padding:12px 14px;border:1px solid #b45309;border-radius:12px;background:color-mix(in srgb,#f59e0b 18%,var(--dsw-alias-bg-base,#17191d));box-shadow:0 16px 48px rgba(0,0,0,.42);font-size:12px;line-height:1.55;color:var(--dsw-alias-label-primary,#e7e9ed)}",
41
41
  ".tm_banner_body{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px}.tm_banner_line{overflow-wrap:anywhere}",
42
42
  ].join("");
@@ -93,6 +93,45 @@ window.__ModuleLoader__.load({
93
93
  })),
94
94
  };
95
95
  }
96
+ /**
97
+ * Project one Preset's whole policy onto another Preset.
98
+ *
99
+ * The target is meant to be overwritten, so its current groups and
100
+ * disabled names are ignored. Copy only what the target can actually
101
+ * expose: group membership is limited to tools present in both
102
+ * Presets, and a group whose members all disappear is skipped instead
103
+ * of becoming an invalid empty group. Old wildcard patterns are
104
+ * expanded to exact names, matching what the group editor shows.
105
+ */
106
+ function copyPresetPolicy(sourcePreset, targetPreset) {
107
+ const sourceTools = sourcePreset.tools || [];
108
+ const sourcePolicy = sourcePreset.policy || { disabled: [], groups: [] };
109
+ const targetNames = new Set((targetPreset.tools || []).map((tool) => tool.name));
110
+ const sourceNames = new Set(sourceTools.map((tool) => tool.name));
111
+ const disabled = (sourcePolicy.disabled || [])
112
+ .filter((name) => sourceNames.has(name) && targetNames.has(name));
113
+ const claimed = new Set(disabled);
114
+ const groups = [];
115
+ const skippedGroups = [];
116
+ for (const group of sourcePolicy.groups || []) {
117
+ const members = [];
118
+ for (const tool of matchingTools(sourceTools, group.patterns || [])) {
119
+ if (!targetNames.has(tool.name) || claimed.has(tool.name)) continue;
120
+ claimed.add(tool.name);
121
+ members.push(tool.name);
122
+ }
123
+ if (members.length === 0) {
124
+ skippedGroups.push(group.name || "未命名分组");
125
+ continue;
126
+ }
127
+ groups.push({
128
+ name: group.name,
129
+ ...(group.description ? { description: group.description } : {}),
130
+ patterns: members,
131
+ });
132
+ }
133
+ return { disabled, groups, skippedGroups };
134
+ }
96
135
  function settingsPayload(value) {
97
136
  const settings = { presets: {} };
98
137
  for (const item of value && value.presets || []) settings.presets[item.id] = policyPayload(item.policy);
@@ -259,6 +298,7 @@ window.__ModuleLoader__.load({
259
298
  const [autoGrouping, setAutoGrouping] = react.useState(false);
260
299
  const [autoGroupError, setAutoGroupError] = react.useState("");
261
300
  const [autoPreview, setAutoPreview] = react.useState(null);
301
+ const [copyDialog, setCopyDialog] = react.useState(null);
262
302
  const [expanded, setExpanded] = react.useState({});
263
303
  const [aiConfirm, setAiConfirm] = react.useState(null);
264
304
  const [suggestionTimeoutSeconds, setSuggestionTimeoutSeconds] = react.useState("60");
@@ -269,7 +309,7 @@ window.__ModuleLoader__.load({
269
309
  setBusy(true); setError("");
270
310
  return api("/snapshot").then((value) => {
271
311
  const next = withGroupKeys(value);
272
- setSnapshot(value); setDraft(next); setModal(null); setAutoPreview(null); setAutoGroupError("");
312
+ setSnapshot(value); setDraft(next); setModal(null); setAutoPreview(null); setCopyDialog(null); setAutoGroupError("");
273
313
  setActive((current) => current && value.presets.some((p) => p.id === current) ? current : (value.presets[0] && value.presets[0].id) || "");
274
314
  }).catch((e) => {
275
315
  // The Host swaps the preset registry instance when its node
@@ -294,17 +334,18 @@ window.__ModuleLoader__.load({
294
334
  return () => window.removeEventListener("beforeunload", onBeforeUnload);
295
335
  }, [dirty]);
296
336
  react.useEffect(() => {
297
- if (!modal && !aiConfirm && !autoPreview) return undefined;
337
+ if (!modal && !aiConfirm && !autoPreview && !copyDialog) return undefined;
298
338
  function onKeyDown(event) {
299
339
  if (event.key === "Escape") {
300
340
  if (aiConfirm) setAiConfirm(null);
301
341
  else if (autoPreview) setAutoPreview(null);
342
+ else if (copyDialog) setCopyDialog(null);
302
343
  else if (modal) setModal(null);
303
344
  }
304
345
  }
305
346
  window.addEventListener("keydown", onKeyDown);
306
347
  return () => window.removeEventListener("keydown", onKeyDown);
307
- }, [modal, aiConfirm, autoPreview]);
348
+ }, [modal, aiConfirm, autoPreview, copyDialog]);
308
349
 
309
350
  if (!draft) return h("div", { className: "tm_root" }, error ? h("div", { className: "tm_error" }, error) : h("div", { className: "tm_muted" }, "正在读取工具目录…"));
310
351
  const preset = draft.presets.find((item) => item.id === active) || draft.presets[0];
@@ -341,6 +382,82 @@ window.__ModuleLoader__.load({
341
382
  });
342
383
  }
343
384
 
385
+ function resetPresetConfig() {
386
+ if (!hasPresetConfig) return;
387
+ if (!window.confirm("确定重置当前 Preset 的配置吗?这会清空它的全部按需组和已关闭工具;只修改页面草稿,保存后生效。")) return;
388
+ mutatePreset((target) => {
389
+ target.policy = { disabled: [], groups: [] };
390
+ });
391
+ setQuery("");
392
+ setFilter("all");
393
+ setExpanded({});
394
+ setMessage("已重置当前 Preset 的配置(草稿);点击保存后生效。");
395
+ }
396
+
397
+ function openCopyDialog() {
398
+ if (!hasPresetConfig || copyTargetCount === 0) return;
399
+ setCopyDialog({ sourceId: preset.id, selected: [] });
400
+ }
401
+
402
+ function toggleCopyTarget(id) {
403
+ setCopyDialog((current) => {
404
+ if (!current) return current;
405
+ const selected = new Set(current.selected || []);
406
+ if (selected.has(id)) selected.delete(id); else selected.add(id);
407
+ return { ...current, selected: [...selected] };
408
+ });
409
+ }
410
+
411
+ function selectAllCopyTargets(ids) {
412
+ setCopyDialog((current) => current ? { ...current, selected: [...ids] } : current);
413
+ }
414
+
415
+ function clearCopyTargets() {
416
+ setCopyDialog((current) => current ? { ...current, selected: [] } : current);
417
+ }
418
+
419
+ function confirmCopy() {
420
+ if (!copyDialog) return;
421
+ const source = draft.presets.find((item) => item.id === copyDialog.sourceId);
422
+ if (!source) { setCopyDialog(null); return; }
423
+ const selected = new Set(copyDialog.selected || []);
424
+ const plans = [];
425
+ for (const target of draft.presets) {
426
+ if (target.id === source.id || !selected.has(target.id) || target.broken) continue;
427
+ const copied = copyPresetPolicy(source, target);
428
+ const before = JSON.stringify(policyPayload(target.policy));
429
+ const after = JSON.stringify(policyPayload({ disabled: copied.disabled, groups: copied.groups }));
430
+ plans.push({ targetId: target.id, label: target.name || target.id, copied, changed: before !== after });
431
+ }
432
+ if (!plans.length) { setCopyDialog(null); return; }
433
+ setDraft((current) => {
434
+ const next = clone(current);
435
+ for (const plan of plans) {
436
+ const target = next.presets.find((item) => item.id === plan.targetId);
437
+ if (!target) continue;
438
+ target.policy = {
439
+ disabled: [...plan.copied.disabled],
440
+ groups: plan.copied.groups.map((group) => ({ ...group, _key: newKey() })),
441
+ };
442
+ }
443
+ return next;
444
+ });
445
+ const changed = plans.filter((plan) => plan.changed);
446
+ const unchanged = plans.length - changed.length;
447
+ const skipped = plans.flatMap((plan) => plan.copied.skippedGroups.map((name) => plan.label + ":" + name));
448
+ const parts = [];
449
+ if (changed.length) {
450
+ parts.push("已将「" + (source.name || source.id) + "」的配置复制到 "
451
+ + changed.map((plan) => "「" + plan.label + "」").join("、") + "(草稿),请检查后保存。");
452
+ } else {
453
+ parts.push("所选 Preset 的配置已与当前 Preset 一致,没有产生修改。");
454
+ }
455
+ if (unchanged) parts.push(unchanged + " 个 Preset 无变化。");
456
+ if (skipped.length) parts.push("跳过 " + skipped.length + " 个无可用工具的分组:" + skipped.join(";"));
457
+ setMessage(parts.join(" "));
458
+ setCopyDialog(null);
459
+ }
460
+
344
461
  function openEdit(group) {
345
462
  const members = matchingTools(preset.tools, group.patterns || []).map((tool) => tool.name);
346
463
  setModal({
@@ -568,7 +685,7 @@ window.__ModuleLoader__.load({
568
685
  api("/save", { method: "POST", body: JSON.stringify({ expectedRevision: snapshot.revision, settings }) })
569
686
  .then((value) => {
570
687
  const next = withGroupKeys(value);
571
- setSnapshot(value); setDraft(next); setModal(null);
688
+ setSnapshot(value); setDraft(next); setModal(null); setCopyDialog(null);
572
689
  setMessage("已保存;运行中 Agent 将从下一个模型步骤应用新策略。");
573
690
  })
574
691
  .catch((e) => setError(String(e.message || e)))
@@ -579,6 +696,10 @@ window.__ModuleLoader__.load({
579
696
  const grouped = groupedNames(preset);
580
697
  const autoGroupCandidates = (preset.tools || []).filter((tool) => !disabled.has(tool.name) && !grouped.has(tool.name));
581
698
  const stats = catalogStats(preset);
699
+ const presetPolicy = preset.policy || { disabled: [], groups: [] };
700
+ const hasPresetConfig = !preset.broken
701
+ && ((presetPolicy.groups || []).length > 0 || (presetPolicy.disabled || []).length > 0);
702
+ const copyTargetCount = draft.presets.filter((item) => item.id !== preset.id && !item.broken).length;
582
703
  const needle = query.trim().toLowerCase();
583
704
  const groups = preset.policy.groups || [];
584
705
  const visibleGroups = groups.filter((group) => {
@@ -616,6 +737,15 @@ window.__ModuleLoader__.load({
616
737
  const aiVisibleSelected = aiVisibleCandidates.filter((tool) => aiSelected.has(tool.name)).map((tool) => tool.name);
617
738
  const aiPromptTrimmed = String(aiConfirm && aiConfirm.prompt || "").trim();
618
739
  const aiCanConfirm = aiPromptTrimmed.length > 0 && (!aiIsAutoGroup || aiSelected.size > 0);
740
+ const copySource = copyDialog ? draft.presets.find((item) => item.id === copyDialog.sourceId) : null;
741
+ const copyPreviewRows = copySource
742
+ ? draft.presets
743
+ .filter((item) => item.id !== copySource.id)
744
+ .map((target) => ({ target, preview: copyPresetPolicy(copySource, target) }))
745
+ : [];
746
+ const copySelectableIds = copyPreviewRows.filter((row) => !row.target.broken).map((row) => row.target.id);
747
+ const copySelected = new Set(copyDialog ? copyDialog.selected || [] : []);
748
+ const copySelectedCount = copySelectableIds.filter((id) => copySelected.has(id)).length;
619
749
 
620
750
  function updateAutoGroupSelection(nextSelectedNames) {
621
751
  const nextSelected = [...new Set(nextSelectedNames)];
@@ -907,6 +1037,77 @@ window.__ModuleLoader__.load({
907
1037
  document.body,
908
1038
  ) : null;
909
1039
 
1040
+ const copyDialogNode = copyDialog && copySource && typeof document !== "undefined" ? reactDom.createPortal(
1041
+ h("div", { className: "tm_modal", role: "dialog", "aria-modal": "true", "aria-label": "复制当前 Preset 配置" },
1042
+ h("div", { className: "tm_modal_mask", onMouseDown: () => setCopyDialog(null) }),
1043
+ h("div", { className: "tm_modal_card" },
1044
+ h("div", { className: "tm_modal_head" },
1045
+ h("div", null,
1046
+ h("h3", null, "复制当前 Preset 配置"),
1047
+ h("div", { className: "tm_muted" }, "将当前 Preset 的全部按需组和已关闭工具复制到勾选的 Preset;只改页面草稿,保存后生效。"),
1048
+ ),
1049
+ h("button", { className: "tm_btn", onClick: () => setCopyDialog(null) }, "关闭"),
1050
+ ),
1051
+ h("div", { className: "tm_modal_body" },
1052
+ h("div", { className: "tm_notice" },
1053
+ "源 Preset「" + (copySource.name || copySource.id) + "」:"
1054
+ + (copySource.policy.groups || []).length + " 个按需组、"
1055
+ + (copySource.policy.disabled || []).length + " 个已关闭工具。"
1056
+ + "勾选的目标 Preset 现有分组和关闭项将被整份覆盖。",
1057
+ ),
1058
+ h("div", { className: "tm_row" },
1059
+ h("button", {
1060
+ className: "tm_btn",
1061
+ disabled: copySelectableIds.length === 0,
1062
+ onClick: () => selectAllCopyTargets(copySelectableIds),
1063
+ }, "全选可复制项"),
1064
+ h("button", { className: "tm_btn", disabled: copySelectedCount === 0, onClick: clearCopyTargets }, "清空"),
1065
+ h("span", { className: "tm_muted" }, "已选 " + copySelectedCount + " / " + copySelectableIds.length + " 个 Preset"),
1066
+ ),
1067
+ copyPreviewRows.length
1068
+ ? h("div", { className: "tm_picker" }, copyPreviewRows.map(({ target, preview }) => {
1069
+ const currentGroups = (target.policy.groups || []).length;
1070
+ const currentDisabled = (target.policy.disabled || []).length;
1071
+ const meta = target.broken
1072
+ ? "工具目录读取失败,暂不能复制"
1073
+ : "现有 " + currentGroups + " 个组 / " + currentDisabled + " 个关闭项 → 将复制 "
1074
+ + preview.groups.length + " 个组 / " + preview.disabled.length + " 个关闭项"
1075
+ + (preview.skippedGroups.length
1076
+ ? ";跳过 " + preview.skippedGroups.length + " 个组:" + preview.skippedGroups.join("、")
1077
+ : "")
1078
+ + ((target.tools || []).length === 0 ? ";目标没有可见工具,复制后配置为空" : "");
1079
+ return h("label", { className: "tm_pick", key: target.id },
1080
+ h("input", {
1081
+ type: "checkbox",
1082
+ checked: copySelected.has(target.id) && !target.broken,
1083
+ disabled: !!target.broken,
1084
+ onChange: () => toggleCopyTarget(target.id),
1085
+ }),
1086
+ h("span", null,
1087
+ h("div", { className: "tm_tool_name" },
1088
+ target.name ? target.name + " · " + target.id : target.id,
1089
+ target.broken ? h("span", { className: "tm_badge off" }, "不可用") : null,
1090
+ ),
1091
+ h("div", { className: "tm_copy_meta", title: meta }, meta),
1092
+ ),
1093
+ );
1094
+ }))
1095
+ : h("div", { className: "tm_muted" }, "没有其他可复制的 Preset。"),
1096
+ h("div", { className: "tm_muted" }, "提示:分组按目标 Preset 实际拥有的工具裁剪;整组都没有可用工具时会自动跳过。"),
1097
+ ),
1098
+ h("div", { className: "tm_modal_foot" },
1099
+ h("button", { className: "tm_btn", onClick: () => setCopyDialog(null) }, "取消"),
1100
+ h("button", {
1101
+ className: "tm_btn primary",
1102
+ disabled: copySelectedCount === 0,
1103
+ onClick: confirmCopy,
1104
+ }, "复制到 " + copySelectedCount + " 个 Preset"),
1105
+ ),
1106
+ ),
1107
+ ),
1108
+ document.body,
1109
+ ) : null;
1110
+
910
1111
  const empty = listedGroups.length === 0 && visibleTools.length === 0;
911
1112
 
912
1113
  return h("div", { className: "tm_root" },
@@ -930,7 +1131,7 @@ window.__ModuleLoader__.load({
930
1131
  className: "tm_preset_select",
931
1132
  value: preset.id,
932
1133
  disabled: autoGrouping,
933
- onChange: (event) => { setActive(event.target.value); setQuery(""); setFilter("all"); setModal(null); setAutoPreview(null); setAutoGroupError(""); setExpanded({}); },
1134
+ onChange: (event) => { setActive(event.target.value); setQuery(""); setFilter("all"); setModal(null); setAutoPreview(null); setCopyDialog(null); setAutoGroupError(""); setExpanded({}); },
934
1135
  }, draft.presets.map((item) => h("option", { key: item.id, value: item.id }, (item.name || item.id) + " · " + (item.tools || []).length + " 个工具" + (item.isDefault ? " · 默认" : "") + (item.trust === "user" ? " · 用户" : "")))),
935
1136
  ),
936
1137
  ),
@@ -946,6 +1147,22 @@ window.__ModuleLoader__.load({
946
1147
  h("div", { className: "tm_row" },
947
1148
  h("button", { className: "tm_btn", onClick: startAutoGroup, disabled: autoGrouping || autoGroupCandidates.length === 0, title: autoGroupCandidates.length ? "用默认模型对未分组且未关闭的工具进行聚类" : "没有可自动分组的工具" }, autoGrouping ? "自动分组中…" : "自动分组"),
948
1149
  h("button", { className: "tm_btn", onClick: openCreate, disabled: autoGrouping }, "手动分组"),
1150
+ h("button", {
1151
+ className: "tm_btn",
1152
+ onClick: resetPresetConfig,
1153
+ disabled: autoGrouping || busy || !draft.writable || !hasPresetConfig,
1154
+ title: hasPresetConfig
1155
+ ? "清空当前 Preset 的全部按需组和已关闭工具"
1156
+ : "当前 Preset 没有可重置的配置",
1157
+ }, "重置配置"),
1158
+ h("button", {
1159
+ className: "tm_btn",
1160
+ onClick: openCopyDialog,
1161
+ disabled: autoGrouping || busy || !draft.writable || !hasPresetConfig || copyTargetCount === 0,
1162
+ title: hasPresetConfig
1163
+ ? "把当前 Preset 的分组和已关闭工具复制到其他 Preset"
1164
+ : "当前 Preset 没有可复制的分组或已关闭工具",
1165
+ }, "复制配置"),
949
1166
  ),
950
1167
  ),
951
1168
  h("div", { className: "tm_stats" },
@@ -974,6 +1191,7 @@ window.__ModuleLoader__.load({
974
1191
  dialog,
975
1192
  aiConfirmDialog,
976
1193
  previewDialog,
1194
+ copyDialogNode,
977
1195
  );
978
1196
  }
979
1197
 
@@ -995,6 +1213,9 @@ window.__ModuleLoader__.load({
995
1213
 
996
1214
  exports.apply = apply;
997
1215
  exports.inject = inject;
1216
+ // Pure policy projection, exported for unit tests. DSH only consumes
1217
+ // apply/inject, so this does not widen the client plugin contract.
1218
+ exports.copyPresetPolicy = copyPresetPolicy;
998
1219
  return module.exports;
999
1220
  },
1000
1221
  });
@@ -2,9 +2,13 @@ import type { AgentSessionLike } from "./dsh.js";
2
2
  /**
3
3
  * Rebuild the on-demand groups successfully opened in one Session.
4
4
  *
5
- * The tool call/result log is the durable source of truth. This intentionally
6
- * excludes a fork's inherited prefix so temporary capability choices do not
7
- * leak from the parent Session into a new child Session.
5
+ * The tool call/result log is the durable source of truth, and a fork's
6
+ * inherited prefix counts: the child continues the same transcript, whose
7
+ * `tool_list` result already told the model those tools are available for the
8
+ * rest of the session. Hiding them again would contradict the history the
9
+ * model reads, so a fork starts from the groups its shared prefix opened.
10
+ * Groups the parent opened after the fork point are not in the child's log and
11
+ * stay closed, as does every group on a Session that never opened one.
8
12
  */
9
13
  export declare function restoredExposureNames(session: AgentSessionLike | undefined): Set<string>;
10
14
  //# sourceMappingURL=exposure-history.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exposure-history.d.ts","sourceRoot":"","sources":["../src/exposure-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,UAAU,CAAC;AAGnE;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,GAAG,CAAC,MAAM,CAAC,CAsBb"}
1
+ {"version":3,"file":"exposure-history.d.ts","sourceRoot":"","sources":["../src/exposure-history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,UAAU,CAAC;AAGnE;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,GAAG,CAAC,MAAM,CAAC,CAqBb"}
@@ -2,17 +2,20 @@ import { DISCOVERY_TOOL_NAME } from "./types.js";
2
2
  /**
3
3
  * Rebuild the on-demand groups successfully opened in one Session.
4
4
  *
5
- * The tool call/result log is the durable source of truth. This intentionally
6
- * excludes a fork's inherited prefix so temporary capability choices do not
7
- * leak from the parent Session into a new child Session.
5
+ * The tool call/result log is the durable source of truth, and a fork's
6
+ * inherited prefix counts: the child continues the same transcript, whose
7
+ * `tool_list` result already told the model those tools are available for the
8
+ * rest of the session. Hiding them again would contradict the history the
9
+ * model reads, so a fork starts from the groups its shared prefix opened.
10
+ * Groups the parent opened after the fork point are not in the child's log and
11
+ * stay closed, as does every group on a Session that never opened one.
8
12
  */
9
13
  export function restoredExposureNames(session) {
10
14
  const restored = new Set();
11
15
  if (!session)
12
16
  return restored;
13
17
  const pending = new Map();
14
- const start = validBoundary(session.inheritedEventCount, session.seq);
15
- for (let seq = start; seq < session.seq; seq += 1) {
18
+ for (let seq = 0; seq < session.seq; seq += 1) {
16
19
  const event = session.eventAt(seq);
17
20
  if (!event)
18
21
  continue;
@@ -39,20 +42,41 @@ function rememberNativeCall(event, pending) {
39
42
  pending.set(data.callId, group);
40
43
  }
41
44
  function settleNativeCall(event, pending, restored) {
42
- const data = asRecord(event.data);
43
- const message = asRecord(data?.message);
44
- const content = Array.isArray(message?.content) ? message.content : [];
45
- const result = content.map(asRecord).find((block) => block?.type === "tool-result");
46
- const callId = result?.toolCallId;
47
- if (typeof callId !== "string")
45
+ const settled = settledCall(asRecord(asRecord(event.data)?.message));
46
+ if (settled === undefined)
48
47
  return;
49
- const group = pending.get(callId);
48
+ const group = pending.get(settled.callId);
50
49
  if (group === undefined)
51
50
  return;
52
- pending.delete(callId);
53
- if (result?.isError !== true)
51
+ pending.delete(settled.callId);
52
+ if (!settled.isError)
54
53
  restored.add(group);
55
54
  }
55
+ /**
56
+ * The call identity and error flag of one `tool/result` message.
57
+ *
58
+ * DSH stores its own tool message — `toolCallId` and `isError` on the message,
59
+ * text/image blocks in `content` — while a provider-shaped message carries an
60
+ * Anthropic-style `tool-result` block inside `content`. Read both, so restore
61
+ * never depends on which one the Host wrote.
62
+ */
63
+ function settledCall(message) {
64
+ if (!message)
65
+ return undefined;
66
+ const source = asRecord(message.source);
67
+ const direct = nonEmpty(message.toolCallId) ?? nonEmpty(source?.callId);
68
+ if (direct !== undefined)
69
+ return { callId: direct, isError: message.isError === true };
70
+ const content = Array.isArray(message.content) ? message.content : [];
71
+ const block = content.map(asRecord).find((item) => item?.type === "tool-result");
72
+ const blockId = nonEmpty(block?.toolCallId);
73
+ if (blockId === undefined)
74
+ return undefined;
75
+ return { callId: blockId, isError: block?.isError === true };
76
+ }
77
+ function nonEmpty(value) {
78
+ return typeof value === "string" && value !== "" ? value : undefined;
79
+ }
56
80
  function restorePtcDispatch(event, restored) {
57
81
  const data = asRecord(event.data);
58
82
  if (data?.name !== DISCOVERY_TOOL_NAME || data.isError === true)
@@ -77,11 +101,6 @@ function groupFromArguments(value) {
77
101
  const trimmed = group.trim();
78
102
  return trimmed || undefined;
79
103
  }
80
- function validBoundary(value, end) {
81
- if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0)
82
- return 0;
83
- return Math.min(value, end);
84
- }
85
104
  function asRecord(value) {
86
105
  if (value === null || typeof value !== "object" || Array.isArray(value))
87
106
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"exposure-history.js","sourceRoot":"","sources":["../src/exposure-history.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAqC;IAErC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,IAAI,CAAC,OAAO;QAAE,OAAO,QAAQ,CAAC;IAE9B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IACtE,KAAK,IAAI,GAAG,GAAG,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,KAAK;YAAE,SAAS;QACrB,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAC/B,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACnC,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACjC,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC3C,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACvC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,kBAAkB,CACzB,KAAuB,EACvB,OAA4B;IAE5B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