dsh-fleetseek 0.2.0 → 0.3.3

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.

Potentially problematic release.


This version of dsh-fleetseek might be problematic. Click here for more details.

@@ -26,7 +26,7 @@
26
26
  const PROVIDER_ID = "search-chain";
27
27
  const SEARCH_NS = "search-chain"; // settings namespace(行 id 同值)
28
28
  const SECTION_SLOT = "settings.section";
29
- const SECTION_TITLE = "网页搜索链";
29
+ const SECTION_TITLE = "千帆 FleetSeek";
30
30
 
31
31
  /** 区域排序:live [L2] 既有 occupants 之后。 */
32
32
  const SECTION_ORDER = 30;
@@ -43,14 +43,102 @@ const TOOL_TYPES = [
43
43
  "deepseek-agentic-search",
44
44
  ];
45
45
  const DEFAULT_TIMEOUT_MS = 25000;
46
+ // #86 POOL-001/003:单条目凭据池(credentialRefs)上限(单一事实源 src/constants.js POOL_MAX;
47
+ // 本文件为客户端内联镜像——client-entry 不 import src/,同步义务见 config-write-gate.md 修订注)。
48
+ const POOL_MAX = 8;
46
49
  const SECRET_FIELD = /^(apikey|api_key|key|secret|token|password|auth|authorization)$/i;
47
- const HANDLED_ENTRY_FIELDS = ["id", "type", "name", "enabled", "credentialRef", "proxy"];
50
+ // PX-001/006/012(Refs #88):与 src/constants.js / src/config.js 同形镜像(常量镜像义务)。
51
+ const PROXY_PINS = Object.freeze({ INHERIT: "inherit", DIRECT_ONLY: "directOnly", PROXY_ONLY: "proxyOnly" });
52
+ const PROXY_PIN_VALUES = Object.freeze(Object.values(PROXY_PINS));
53
+ const POSIX_CREDENTIAL_REF = /^[A-Za-z_][A-Za-z0-9_]*$/;
54
+ // PX-001:全局代理明文字段族(top/entry 任意层出现即按 CFG-W-003 同规则清零并入清理闭集)。
55
+ const GLOBAL_PROXY_FIELD = /^globalproxy/i;
56
+ // PX-001(Refs #88):全局代理默认凭据引用名(镜像 src/constants.js,自包含文件不得 import)——
57
+ // 仅作唯一名**前缀**(可识别出身);不再作为任何写入值(二次整改 P0-B)。
58
+ const DEFAULT_GLOBAL_PROXY_REF = "search_chain_global_proxy";
59
+ // #88 第四批 P0 + 二次整改 P0-B(Refs #88):每一次新 secret(**含首存**)恒生成真唯一 ref
60
+ // (crypto.randomUUID 去连字符 32hex,POSIX 合法;无 crypto 环境降级 时间戳+随机+序号,碰撞概率可忽略)。
61
+ // 首存不再写默认名:双面板并发首存会在默认名上撞名(A 生效后 B 覆盖、mutate 冲突 → 半成品改路由重现)。
62
+ // mutate 失败不静默改活路由:ref 随 mutate 原子切换,失败只留孤儿新 ref(文档化),绝不读旧 secret 回滚。
63
+ let gpRefSeq = 0;
64
+ function makeUniqueGlobalProxyRef() {
65
+ let hex = "";
66
+ try { hex = String(crypto.randomUUID()).replace(/-/g, ""); } catch { hex = ""; }
67
+ if (!/^[a-f0-9]{32}$/.test(hex)) hex = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 10)}${(++gpRefSeq).toString(36)}`;
68
+ return `${DEFAULT_GLOBAL_PROXY_REF}_${hex}`;
69
+ }
70
+ // PX-012(Refs #88):编辑器钉死单选选项(值/文案/data-role)。
71
+ // #120 PX-012:三态「继承/仅直连/仅代理」控件与字样整体退役(双态开关 + 问号 tooltip)。
72
+ // proxyOnly 仅存读兼容(进不出);「继承」字样零呈现。帮助四要素(#142 起 hover/focus 呈现)=触发面/仅一次/关闭=仅当前路径/前提=全局代理已配置。
73
+ // #120 PX-012 四要素(sol 终评非阻塞①补全):自有代理优先(建连成功后业务失败绝不改道,
74
+ // 与 P1-1 相位收敛一致)/建连失败按开关重试一次/置备前提=全局代理已配置/逐事件可见。
75
+ const RETRY_HELP_TEXT = "条目自有代理(含 PAC)或直连优先;仅建连失败(查询尚未发给供应商)时,按本开关自动经全局代理重试一次;"
76
+ + "建连成功后的供应商侧业务失败绝不改道;全局代理需已配置,未配置不改道;"
77
+ + "每一次改道在结果与诊断可见;关闭=仅当前路径。";
78
+ // #145 修订注二②(Refs #145):PX-013 常驻披露全文迁入全局代理标题 tooltip——文本逐字保留,仅载体换层。
79
+ const GLOBAL_PROXY_HELP_TEXT = "全局代理重试默认开启:条目自有代理(含 PAC)或直连优先;仅建连失败(查询尚未发给供应商)时按条目「自动全局代理」开关自动经全局代理重试一次,建连成功后的供应商侧业务失败绝不改道;改道以全局代理地址已配置为前提——未配置不改道、失败原因会明示;每一次改道在结果首行与诊断中可见。条目可在编辑器单独关闭。";
80
+ // §7 合同①键集并集(Refs #88 #86):#86 credentialRefs 族 + #88 proxyPin 族并列;任一面板保存不得清他包字段。
81
+ // P2b(sol-87 同源钉):未知字段透传谓词 = `HANDLED_ENTRY_FIELDS 含 k || SECRET_FIELD.test(k)`,
82
+ // 与 src/config.js 孪生面(L54 常量 + L126 过滤)同一判据源——改本处字段集/正则须同步 config 面
83
+ // (零 import 约束下镜像单表达式;search entry L133 与 fetch entry L167 两闸共用本谓词、零漂移)。
84
+ const HANDLED_ENTRY_FIELDS = ["id", "type", "name", "enabled", "credentialRef", "credentialRefs", "proxy", "proxyPin"];
85
+ // sol-87b 案2/批3③(lead 裁决):fetch 条目字段集(镜像 src/config.js 同形;改一处须同步另一处)——
86
+ // HANDLED = fetch 条目接纳字段(D-FT1:不含搜索条目的池/pin);
87
+ // SIBLING = 搜索条目专用(proxyPin/credentialRefs)——两闸显式拒(不得整键丢弃静默吞)。
88
+ const FETCH_ENTRY_HANDLED_FIELDS = ["id", "type", "name", "enabled", "credentialRef", "proxy"];
89
+ const FETCH_ENTRY_SIBLING_FIELDS = ["proxyPin", "credentialRefs"];
48
90
  /** 表单管理的条目子字段(合并时覆盖;其余字段保留既有值)。 */
49
- const MANAGED_ENTRY_KEYS = ["id", "type", "name", "enabled", "credentialRef"];
91
+ const MANAGED_ENTRY_KEYS = ["id", "type", "name", "enabled", "credentialRef", "credentialRefs", "proxyPin"];
50
92
  /** 表单管理的顶层键:保存时恒产出 set(即便值未变)。 */
51
93
  const MANAGED_TOP_KEYS = ["useOfficialDeepSeekSearch", "timeoutMs"];
94
+ // #87(Refs #87):fetch 面常量镜像(与 src/constants.js 同值;同步义务见 transport.js 头注口径)。
95
+ const FETCH_TOOL_TYPES = ["tavily-extract"];
96
+ /** fetch 面三键(本面板不管理其草稿值;toOps 不得对其 unset,防搜索面保存清掉 fetch 配置)。 */
97
+ const FETCH_CONFIG_KEYS = ["fetchTakeover", "fetchEntries", "fetchOfficialFallback"];
98
+ // §7 合同③(Refs #87):全局代理面板三键(懒持久化)——搜索面板草稿不含它们,
99
+ // toOps 不得对其 unset,防搜索面保存清掉已保存的全局代理配置(与 fetch 三键对称)。
100
+ // OSB-004(Refs #152):allowUnsandboxedPac 同族并入——本面板全局区块单键管理、懒持久,搜索草稿不含。
101
+ const GLOBAL_PROXY_KEYS = ["globalProxy", "proxyEscalation", "allowUnsandboxedPac"];
102
+ /** OSB-004 有效值读面:user 层显式键优先(懒持久语义),否则 base;缺省 = false(默认拒)。
103
+ * 自足判形(模块级先于 isPlainObject 定义点使用,零 TDZ 依赖)。 */
104
+ const effAllowUnsandboxedPac = (proj) => {
105
+ const plain = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
106
+ const u = plain(proj && proj.user) ? proj.user : {};
107
+ const b = plain(proj && proj.base) ? proj.base : {};
108
+ return (Object.hasOwn(u, "allowUnsandboxedPac") ? u.allowUnsandboxedPac : b.allowUnsandboxedPac) === true;
109
+ };
110
+ /** OSB-004 徽标平台旗标(仅披露面,裁决权在宿主探测):客户端 navigator 形似 darwin 则不显徽标;
111
+ * navigator 缺席(测试 harness/远程浏览器)保守读作非 darwin——多显徽标不缺显。 */
112
+ const clientPlatformLooksDarwin = () => {
113
+ try {
114
+ const n = typeof navigator !== "undefined" ? navigator : null;
115
+ const p = (n && ((n.userAgentData && n.userAgentData.platform) || n.platform)) || "";
116
+ return /mac|iphone|ipad/i.test(String(p));
117
+ } catch {
118
+ return false;
119
+ }
120
+ };
121
+ /** OSB-004(Refs #152)+ #156:「信任所有 PAC」? 悬浮 tooltip 全文(NAM-003 纪律;常驻段落退役入气泡)。 */
122
+ const PAC_UNSANDBOXED_HELP_TEXT =
123
+ "默认关闭:无 OS 级隔离的环境(Linux/Windows,或 macOS 系统沙箱不可用)下,远程 PAC 脚本不下载、不求值," +
124
+ "相关条目显式失败并给出路(直连/固定代理)。开启 = 知情接受远程 PAC 仅受进程内防线约束" +
125
+ "(密封求值、24 MiB 内存上限、2 秒超时),无 OS 级硬边界;此时 PAC 条目卡片常显徽标。" +
126
+ "macOS 系统沙箱可用时始终走沙箱、本开关不参与。语义见规格 OSB-004。";
52
127
 
53
- const sectionLabel = () => SECTION_TITLE;
128
+ // #118(用户反馈):sidebar 条目位窄空间品牌分语言——中文「千帆」/其余「FleetSeek」;
129
+ // 面板内标题位仍用组合名 SECTION_TITLE(O-2 决议有效,本行只影响 settings.section label)。
130
+ // 语言源 = 宿主语言面 ctx.locale(@deepseek-ai/dsh-client-locale:getSnapshot().active 为
131
+ // 已解析偏好;不造第二套语言状态)。语言面缺席(旧装载面/测试 harness)退化组合名——
132
+ // 与既有钉「label=千帆 FleetSeek」的无 locale 语义一致。
133
+ const BRAND_ZH = "千帆";
134
+ const BRAND_OTHER = "FleetSeek";
135
+ const sectionLabel = (ctx) => {
136
+ const face = ctx && ctx.locale;
137
+ if (!face || typeof face.getSnapshot !== "function") return SECTION_TITLE;
138
+ const snapshot = face.getSnapshot() || {};
139
+ const active = String(snapshot.active == null ? "" : snapshot.active).toLowerCase();
140
+ return active.startsWith("zh") ? BRAND_ZH : BRAND_OTHER;
141
+ };
54
142
 
55
143
  /** 已挂载的 ctx.slots 幂等键;卸载 cleanup 清除。 */
56
144
  const mounted = new WeakMap();
@@ -71,38 +159,79 @@ globalThis.window?.__ModuleLoader__?.load({
71
159
  // 与 src/config.js 同形裁决:validate ≡ normalizeConfig(对比钉在测试内)。不依赖 DOM/fetch/react。
72
160
 
73
161
  const isPlainObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
74
- const invalid = (message) => {
162
+ // sol 第三轮(Refs #88):新契约字段族违规的结构化标记(写闸分叉判据)——镜像 src/config.js
163
+ // ConfigError.fieldFamily;legacy 违规不带该属性。分叉按结构化标记而非文案关键词
164
+ // (反例钉:合法条目 id="proxyPin" 撞 legacy 重复 id 文案不得误分叉)。
165
+ const invalid = (message, family) => {
75
166
  const e = new Error(message);
76
167
  e.code = "CONFIG_INVALID";
168
+ if (family !== undefined) e.fieldFamily = family;
77
169
  return e;
78
170
  };
79
171
 
80
- function assertHttpUrl(text, where) {
172
+ function assertHttpUrl(text, where, family) {
81
173
  let u;
82
174
  try {
83
175
  u = new URL(text);
84
176
  } catch {
85
- throw invalid(`${where} 必须是绝对 HTTP(S) URL`);
177
+ throw invalid(`${where} 必须是绝对 HTTP(S) URL`, family);
86
178
  }
87
- if (u.protocol !== "http:" && u.protocol !== "https:") throw invalid(`${where} 必须是 HTTP(S) URL`);
179
+ if (u.protocol !== "http:" && u.protocol !== "https:") throw invalid(`${where} 必须是 HTTP(S) URL`, family);
88
180
  }
89
181
 
90
- function normalizeProxy(raw, where) {
182
+ /** 镜像 src/config.js normalizeProxy。family(可选):违规打字段族标(sol-87b 批2②:
183
+ * fetch 条目传 "fetch" → validate 分叉走新契约 throw 形)。 */
184
+ function normalizeProxy(raw, where, family) {
91
185
  const w = where ? `${where}.proxy` : "proxy";
92
186
  if (raw === undefined || raw === null) return undefined;
93
187
  if (typeof raw === "string") {
94
188
  const s = raw.trim();
95
189
  if (s === "") return undefined;
96
- assertHttpUrl(s, w);
190
+ assertHttpUrl(s, w, family);
97
191
  return s;
98
192
  }
99
193
  if (isPlainObject(raw) && Object.keys(raw).length === 1 && typeof raw.pac === "string") {
100
194
  const pac = raw.pac.trim();
101
- if (pac === "") throw invalid(`${w}.pac 不得为空白`);
102
- assertHttpUrl(pac, `${w}.pac`);
195
+ if (pac === "") throw invalid(`${w}.pac 不得为空白`, family);
196
+ assertHttpUrl(pac, `${w}.pac`, family);
103
197
  return { pac };
104
198
  }
105
- throw invalid(`${w} 形态非法(须为代理 URL 字符串或 { pac })`);
199
+ throw invalid(`${w} 形态非法(须为代理 URL 字符串或 { pac })`, family);
200
+ }
201
+
202
+ // POOL-001/003/010(#86)凭据池双闸写侧:与 src/config.js normalizeCredentialRefs 逐字同形
203
+ // (文案与检查序一致;两闸双向全等由 pool-oracle-gates 钉)。
204
+ function normalizeCredentialRefs(rawRefs, { where, type, hasCredentialRef }) {
205
+ if (rawRefs === undefined) return undefined;
206
+ const isArray = Array.isArray(rawRefs);
207
+ if (hasCredentialRef && isArray && rawRefs.length > 0) {
208
+ throw invalid(`${where}.credentialRef 与 credentialRefs 互斥(两字段不得共存,请保留其一)`, "credentialRefs");
209
+ }
210
+ if (type === "bing" && isArray && rawRefs.length > 0) {
211
+ throw invalid(`${where} bing 类型免 key,不得配置 credentialRefs`, "credentialRefs");
212
+ }
213
+ if (!isArray) {
214
+ throw invalid(`${where}.credentialRefs 必须是数组(0–${POOL_MAX} 个凭据引用名)`, "credentialRefs");
215
+ }
216
+ if (rawRefs.length > POOL_MAX) {
217
+ throw invalid(`${where}.credentialRefs 超出池上限:实际 ${rawRefs.length} 个,上限 ${POOL_MAX} 个`, "credentialRefs");
218
+ }
219
+ const refs = [];
220
+ for (let j = 0; j < rawRefs.length; j += 1) {
221
+ const el = rawRefs[j];
222
+ if (typeof el !== "string" || el.trim() === "") {
223
+ throw invalid(`${where}.credentialRefs[${j}] 必须是非空白字符串(凭据引用名)`, "credentialRefs");
224
+ }
225
+ refs.push(el.trim());
226
+ }
227
+ for (let j = 0; j < refs.length; j += 1) {
228
+ for (let k = 0; k < j; k += 1) {
229
+ if (refs[j] === refs[k]) {
230
+ throw invalid(`${where}.credentialRefs[${j}] 与池内其他元素 trim 后重复(池内引用重复)`, "credentialRefs");
231
+ }
232
+ }
233
+ }
234
+ return refs.length > 0 ? refs : undefined;
106
235
  }
107
236
 
108
237
  function normalizeEntry(raw, index) {
@@ -123,15 +252,86 @@ globalThis.window?.__ModuleLoader__?.load({
123
252
  }
124
253
  out.credentialRef = raw.credentialRef.trim();
125
254
  }
255
+ // POOL-001/003/010:credentialRefs 池形态(旧形态单引用零变化;合法空数组省略该键)。
256
+ const refs = normalizeCredentialRefs(raw.credentialRefs, {
257
+ where,
258
+ type: raw.type,
259
+ hasCredentialRef: out.credentialRef !== undefined,
260
+ });
261
+ if (refs !== undefined) out.credentialRefs = refs;
126
262
  const proxy = normalizeProxy(raw.proxy, where);
127
263
  if (proxy !== undefined) out.proxy = proxy;
264
+ // PX-012(Refs #88)+ #120 PX-006 双态演化(与读闸 src/config.js 同形镜像,CFG-W-001 等价钉):
265
+ // 开=inherit/省略(输出省略键)、关=directOnly;proxyOnly 读兼容存量值。directOnly+自有 proxy
266
+ // (固定形与 PAC 形同域,#142)合法化;proxyOnly+自有 proxy 维持互斥(含 PAC)。
267
+ let proxyPin = PROXY_PINS.INHERIT;
268
+ if (raw.proxyPin !== undefined) {
269
+ if (typeof raw.proxyPin !== "string" || !PROXY_PIN_VALUES.includes(raw.proxyPin)) {
270
+ throw invalid(`${where}.proxyPin 必须是 "inherit" | "directOnly" | "proxyOnly"`, "proxyPin");
271
+ }
272
+ proxyPin = raw.proxyPin;
273
+ }
274
+ if (proxy !== undefined && proxyPin !== PROXY_PINS.INHERIT) {
275
+ const legal = proxyPin === PROXY_PINS.DIRECT_ONLY;
276
+ if (!legal) {
277
+ throw invalid(
278
+ `${where}.proxyPin 与条目自有 proxy 互斥(自有代理条目(含 PAC 形)仅允许 inherit 或 directOnly;proxyOnly 强制全局与自有代理矛盾)`,
279
+ "proxyPin",
280
+ );
281
+ }
282
+ }
283
+ if (proxyPin !== PROXY_PINS.INHERIT) out.proxyPin = proxyPin;
284
+ // sol 第三轮(Refs #88):保留面跳过判定并入统一闭集(legacy 八名族 ∪ globalProxy 族,合法引用豁免)——
285
+ // 与读闸 src/config.js normalizeEntry 同判据(两闸 deepEqual 反例钉:条目级 globalProxyUrl 等
286
+ // globalProxy 族名明文标量写闸不得透传,读闸丢弃)。
128
287
  for (const [k, v] of Object.entries(raw)) {
129
- if (HANDLED_ENTRY_FIELDS.includes(k) || SECRET_FIELD.test(k)) continue;
288
+ if (HANDLED_ENTRY_FIELDS.includes(k) || (isSecretClosureKey(k) && !isLegitGlobalProxyRefValue(k, v))) continue;
130
289
  if (["string", "number", "boolean"].includes(typeof v)) out[k] = v;
131
290
  }
132
291
  return out;
133
292
  }
134
293
 
294
+ /** #87 FT-009 fetch 条目规范化(与 src/config.js normalizeFetchEntry 同形;fieldFamily="fetch" 标记供
295
+ * validate 分叉)。未知字段面(sol-87b 案2/批3③ lead 裁决):兄弟族键(搜索条目专用)显式拒;
296
+ * 其余未知字段整键丢弃(两闸同形,不建第三形态);合法引用豁免族不受影响。 */
297
+ function normalizeFetchEntry(raw, index) {
298
+ const where = `fetchEntries[${index}]`;
299
+ const fail = (message) => { throw invalid(message, "fetch"); };
300
+ if (!isPlainObject(raw)) fail(`${where} 必须是对象`);
301
+ if (typeof raw.id !== "string" || raw.id.trim() === "") fail(`${where}.id 必须是非空字符串`);
302
+ if (typeof raw.type !== "string" || !FETCH_TOOL_TYPES.includes(raw.type)) {
303
+ fail(`${where}.type 不是已知 fetch 类型(首期仅 ${FETCH_TOOL_TYPES.join(" / ")})`);
304
+ }
305
+ const name = raw.name === undefined ? raw.type : raw.name;
306
+ if (typeof name !== "string") fail(`${where}.name 必须是字符串`);
307
+ const enabled = raw.enabled === undefined ? true : raw.enabled;
308
+ if (typeof enabled !== "boolean") fail(`${where}.enabled 必须是布尔值`);
309
+ const out = { id: raw.id.trim(), type: raw.type, name, enabled };
310
+ if (raw.credentialRef !== undefined && raw.credentialRef !== null && raw.credentialRef !== "") {
311
+ if (typeof raw.credentialRef !== "string" || raw.credentialRef.trim() === "") {
312
+ fail(`${where}.credentialRef 非法`);
313
+ }
314
+ out.credentialRef = raw.credentialRef.trim();
315
+ }
316
+ const proxy = normalizeProxy(raw.proxy, where, "fetch");
317
+ if (proxy !== undefined) out.proxy = proxy;
318
+ // sol-87b 批3③(lead 裁决):兄弟族键(搜索条目专用,D-FT1 冻结分离——fetch 条目不收
319
+ // pin/pool,非缺陷仅显式化)显式拒——安全意图字段永不静默吞(不得整键丢弃)。
320
+ for (const k of FETCH_ENTRY_SIBLING_FIELDS) {
321
+ if (Object.hasOwn(raw, k)) {
322
+ fail(`${where}.${k} 是搜索条目专用字段,fetch 条目不接受(D-FT1:fetch 条目不收 pin/pool 键)`);
323
+ }
324
+ }
325
+ // sol-87b 案2(lead 裁决):未知字段整键丢弃(scalar/对象/数组均不透传,与读闸同形,
326
+ // 不建第三形态);合法引用豁免族不受影响(唯一合法形态 = 精确键 globalProxy 持 POSIX
327
+ // 凭据引用名——引用是数据非明文,round-trip 零留存)。
328
+ for (const [k, v] of Object.entries(raw)) {
329
+ if (FETCH_ENTRY_HANDLED_FIELDS.includes(k)) continue;
330
+ if (isSecretClosureKey(k) && isLegitGlobalProxyRefValue(k, v)) out[k] = v;
331
+ }
332
+ return out;
333
+ }
334
+
135
335
  function normalizeConfig(raw) {
136
336
  if (raw === undefined || raw === null) raw = {};
137
337
  if (!isPlainObject(raw)) throw invalid("配置必须是对象");
@@ -147,19 +347,100 @@ globalThis.window?.__ModuleLoader__?.load({
147
347
  if (typeof useOfficial !== "boolean") throw invalid("useOfficialDeepSeekSearch 必须是布尔值");
148
348
  const timeoutMs = raw.timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : raw.timeoutMs;
149
349
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) throw invalid("timeoutMs 必须是正整数毫秒");
150
- return { entries, useOfficialDeepSeekSearch: useOfficial, timeoutMs };
350
+
351
+ // PX-001/002(Refs #88)+ #120 二轮(与 src/config.js 读闸同形,两闸等价钉 CFG-W-001):
352
+ // 省略=默认开且输出省略键(默认值不实体化);显式布尔原样保留;组合拒绝废止(PX-001 验收2/3)。
353
+ let proxyEscalation;
354
+ if (raw.proxyEscalation !== undefined) {
355
+ if (typeof raw.proxyEscalation !== "boolean") {
356
+ throw invalid("proxyEscalation 必须是布尔值", "proxyEscalation");
357
+ }
358
+ proxyEscalation = raw.proxyEscalation;
359
+ }
360
+ const globalProxy = normalizeGlobalProxyRef(raw.globalProxy);
361
+ // #87(Refs #87):fetch 面三键默认补齐(与 src/config.js 同形——两闸等价钉要求输出键集一致)。
362
+ const fetchTakeover = raw.fetchTakeover === undefined ? false : raw.fetchTakeover;
363
+ if (typeof fetchTakeover !== "boolean") throw invalid("fetchTakeover 必须是布尔值", "fetch");
364
+ const rawFetchEntries = raw.fetchEntries === undefined ? [] : raw.fetchEntries;
365
+ if (!Array.isArray(rawFetchEntries)) throw invalid("fetchEntries 必须是数组", "fetch");
366
+ const fetchEntries = rawFetchEntries.map((e, i) => normalizeFetchEntry(e, i));
367
+ const seenFetch = new Set();
368
+ for (const e of fetchEntries) {
369
+ if (seenFetch.has(e.id)) throw invalid(`fetchEntries 中 id 重复:${e.id}`, "fetch");
370
+ seenFetch.add(e.id);
371
+ }
372
+ const fetchOfficialFallback = raw.fetchOfficialFallback === undefined ? true : raw.fetchOfficialFallback;
373
+ if (typeof fetchOfficialFallback !== "boolean") throw invalid("fetchOfficialFallback 必须是布尔值", "fetch");
374
+ // OSB-004(Refs #152):与 src/config.js 同形镜像(两闸等价钉)——非布尔拒绝、显式布尔才进输出。
375
+ if (raw.allowUnsandboxedPac !== undefined && typeof raw.allowUnsandboxedPac !== "boolean") {
376
+ throw invalid("allowUnsandboxedPac 必须是布尔值", "allowUnsandboxedPac");
377
+ }
378
+ // #87 条件输出(与 src/config.js 同形——两闸等价钉要求输出键集一致):输入未携带的 fetch 键
379
+ // 不进输出(CFG-004 落盘=输出 ∩ FT-007#3 未触碰零新键);缺键默认由消费面承担(FT-003#1)。
380
+ const out = {
381
+ entries,
382
+ useOfficialDeepSeekSearch: useOfficial,
383
+ timeoutMs,
384
+ };
385
+ if (proxyEscalation !== undefined) out.proxyEscalation = proxyEscalation;
386
+ if (globalProxy !== undefined) out.globalProxy = globalProxy;
387
+ if (Object.hasOwn(raw, "fetchTakeover")) out.fetchTakeover = fetchTakeover;
388
+ if (Object.hasOwn(raw, "fetchEntries")) out.fetchEntries = fetchEntries;
389
+ if (Object.hasOwn(raw, "fetchOfficialFallback")) out.fetchOfficialFallback = fetchOfficialFallback;
390
+ if (Object.hasOwn(raw, "allowUnsandboxedPac")) out.allowUnsandboxedPac = raw.allowUnsandboxedPac;
391
+ return out;
151
392
  }
152
393
 
394
+ /** PX-006(Refs #88):globalProxy 只存凭据引用名,永不存明文 URL(与读闸同文)。 */
395
+ function normalizeGlobalProxyRef(raw) {
396
+ if (raw === undefined || raw === "") return undefined;
397
+ if (typeof raw !== "string") {
398
+ throw invalid("globalProxy 只允许保存凭据引用名(禁止非字符串或 null),请改由设置面板保存全局代理地址", "globalProxy");
399
+ }
400
+ const s = raw.trim();
401
+ if (s === "") {
402
+ throw invalid("globalProxy 不得为空白字符串(未配置请省略,或在设置面板保存)", "globalProxy");
403
+ }
404
+ if (s.includes("://") || s.includes("@")) {
405
+ throw invalid("globalProxy 只允许保存凭据引用名(禁止明文代理 URL),请改由设置面板保存全局代理地址", "globalProxy");
406
+ }
407
+ if (!POSIX_CREDENTIAL_REF.test(s)) {
408
+ throw invalid("globalProxy 只允许保存 POSIX 凭据引用名(禁止明文地址或非法字符),请改由设置面板保存全局代理地址", "globalProxy");
409
+ }
410
+ return s;
411
+ }
412
+
413
+
414
+ // §7 合同③(Refs #88 #86):写闸分叉字段族——#86 credentialRefs 池族与 #88 全局代理族
415
+ // (proxyEscalation / globalProxy / entries[i].proxyPin)并入**同一分叉函数**,不得出现两套 validate 行为。
416
+
153
417
  function validate(raw) {
418
+ let normalized;
154
419
  try {
155
- return { ok: true, config: normalizeConfig(raw) };
420
+ normalized = normalizeConfig(raw);
156
421
  } catch (e) {
422
+ // #86/#88/#87 统一分叉规则(§7 合同②③,以 #86 包装为底):新契约字段族违规 = 预检抛错,
423
+ // 写闸预检面(preCheck/commit 预检)直接 catch 呈现;legacy 字段违规维持返回形态 { ok:false, code, issues }。
424
+ // 抛错文案逐字来自读闸(normalizeCredentialRefs / normalizeConfig 全局代理族)——双向等价由
425
+ // pool-oracle-gates / px-oracle-gates 两闸钉。
426
+ // sol 第三轮(Refs #88):分叉判据 = 结构化标记 e.fieldFamily(invalid(message, family) 打标,
427
+ // 镜像 src/config.js ConfigError.fieldFamily)——禁用文案关键词 includes(反例:合法条目
428
+ // id="proxyPin" 使 legacy 重复 id 文案撞族名而误分叉)。
429
+ // #87 fetch 字段族(fetchTakeover/fetchEntries/fetchOfficialFallback)违规同走该分叉(invalid(..., "fetch") 打标 fieldFamily="fetch")。
430
+ if (e && typeof e.fieldFamily === "string") throw e;
157
431
  return {
158
432
  ok: false,
159
433
  code: "CONFIG_INVALID",
160
434
  issues: [{ message: String((e && e.message) || "配置未通过校验") }],
161
435
  };
162
436
  }
437
+ // #86 Oracle 钉(POOL-001 两闸双向逐字段一致):成功直接返回归一化配置(≡ 读闸 normalizeConfig 输出)。
438
+ // #86/#88 合并注(PR #105 交付记录同步):本函数成功形态相对 v0.2.0 有 BREAKING 变更——
439
+ // 成功 = 直返归一化配置对象(v0.2.0 为 { ok:true, config } 包装),池字段族违规 = throw,
440
+ // legacy 违规 = { ok:false, code, issues }。全部包装点(try/catch 转 legacy/可见错误面):
441
+ // ① 载入路径 effective 预检(load)② commitReorder 预检 ③ submitEditor preCheck(外层 catch 呈现)
442
+ // ④ editorBlock 渲染门(try/catch 转 issues)。#88 合并 client-entry.js 时以此四处为协调锚点。
443
+ return normalized;
163
444
  }
164
445
 
165
446
  function mergeEntry(prior, formEntry) {
@@ -210,17 +491,78 @@ globalThis.window?.__ModuleLoader__?.load({
210
491
  return ka.every((k) => Object.prototype.hasOwnProperty.call(b, k) && deepEq(a[k], b[k]));
211
492
  }
212
493
 
213
- /** 递归剥离明文字段(SECRET_FIELD 键):ops 的 set 值绝不携带既有/表单的明文 key(P2-1)。 */
494
+ // PX-001(Refs #88):全局代理明文判形——字段族名 + 值含 "://" 或 "@"(引用名恒为 POSIX,不含二者)。
495
+ const isGlobalProxyPlaintext = (v) => typeof v === "string" && (v.includes("://") || v.includes("@"));
496
+
497
+ // §7 合同②统一闭集(Refs #88 #86,单一事实源 src/constants.js SECRET_KEY_CLOSURE;本文件为零 import
498
+ // 内联镜像):注册单元 ① legacy secret 八名族(#86 stripSecrets 注册点,CFG-W-003;POOL 侧确认闭集无需
499
+ // 新增字段名——credentialRefs 只存引用名、明文凭据永入 credentials 服务不进配置)② globalProxy 字段名族
500
+ // (#88 全局代理明文)。递归按字段名匹配、数组按元素递归,不做值形态扫描(避免误伤用户数据,边界记录于
501
+ // config-write-gate.md 修订注);扩展点:#87 fetch key 明文族以追加正则注册同名单元。
502
+ const isSecretClosureKey = (k) => SECRET_FIELD.test(k) || GLOBAL_PROXY_FIELD.test(k);
503
+ /** 合法形态豁免:唯一合法键 globalProxy(精确名)持 POSIX 凭据引用名(引用存放合法、明文不合法)。 */
504
+ const isLegitGlobalProxyRefValue = (k, v) =>
505
+ String(k).toLowerCase() === "globalproxy" &&
506
+ typeof v === "string" &&
507
+ v.trim() !== "" &&
508
+ POSIX_CREDENTIAL_REF.test(v.trim());
509
+
510
+ /** 递归收集命中 secret 闭集的字段路径(任意深度、任意位置;数组下标字符串化与 ops path 同形)。
511
+ * 第六批(Refs #88):命中即将删除的父键→只输出父路径、不扫后代——父+子双 unset 会让 apply
512
+ * 在子条上重建已删父键(extra/password 清不掉;globalProxy={password:…} 先删后建 {} 致终检抛错堵死保存)。
513
+ * 与 stripSecretClosure 同口径(命中即整子树跳过),保证 ops 应用结果与剥离结果完全相等。 */
514
+ function secretClosurePaths(value, path, out) {
515
+ if (value === null || typeof value !== "object") return out;
516
+ if (Array.isArray(value)) {
517
+ for (let i = 0; i < value.length; i++) secretClosurePaths(value[i], [...path, String(i)], out);
518
+ return out;
519
+ }
520
+ for (const [k, v] of Object.entries(value)) {
521
+ const p = [...path, k];
522
+ if (isSecretClosureKey(k) && !isLegitGlobalProxyRefValue(k, v)) {
523
+ out.push(p);
524
+ continue;
525
+ }
526
+ if (v !== null && typeof v === "object") secretClosurePaths(v, p, out);
527
+ }
528
+ return out;
529
+ }
530
+
531
+ /** 统一清理闭集 → unset ops(第一批 P0:legacy secret 族 + globalProxy 族一次跑全;第三批④:对最终候选层调用,删除流索引正确)。 */
532
+ function secretClosureCleanupOps(userLayer) {
533
+ return secretClosurePaths(isPlainObject(userLayer) ? userLayer : {}, [], []).map((path) => ({ op: "unset", path }));
534
+ }
535
+
536
+ /** 递归剥离明文字段(secret 闭集):ops 的 set 值绝不携带既有/表单的闭集命中 key(P2-1 + #88 第二批①);
537
+ * globalProxy 键的合法引用形态豁免(refs-only 契约)。 */
214
538
  function stripSecrets(v) {
215
539
  if (Array.isArray(v)) return v.map(stripSecrets);
216
540
  if (v !== null && typeof v === "object") {
217
541
  const out = {};
218
- for (const [k, child] of Object.entries(v)) if (!SECRET_FIELD.test(k)) out[k] = stripSecrets(child);
542
+ for (const [k, child] of Object.entries(v)) {
543
+ if (isSecretClosureKey(k) && !isLegitGlobalProxyRefValue(k, child)) continue;
544
+ out[k] = stripSecrets(child);
545
+ }
219
546
  return out;
220
547
  }
221
548
  return v;
222
549
  }
223
550
 
551
+ /** 读闸等价预检的 scrub:base+user 合并目标中的全局代理明文不得让预检误抛(清零由清理 ops 承载)。 */
552
+ function scrubGlobalProxyPlaintext(obj) {
553
+ if (!isPlainObject(obj)) return obj;
554
+ const out = {};
555
+ for (const [k, v] of Object.entries(obj)) {
556
+ if (k === "entries") {
557
+ out.entries = Array.isArray(v) ? v.map((e) => (isPlainObject(e) ? scrubGlobalProxyPlaintext(e) : e)) : v;
558
+ continue;
559
+ }
560
+ if (GLOBAL_PROXY_FIELD.test(k) && isGlobalProxyPlaintext(v)) continue;
561
+ out[k] = v;
562
+ }
563
+ return out;
564
+ }
565
+
224
566
  /** 路径补丁 reducer(与 settings 宿主 mutate 语义同形:数值段=数组下标;unset 数组段=splice)。 */
225
567
  function applyOne(state, op) {
226
568
  const segs = op.path.map((s) => (/^\d+$/.test(s) ? Number(s) : s));
@@ -254,7 +596,12 @@ globalThis.window?.__ModuleLoader__?.load({
254
596
  };
255
597
  const nxt = isPlainObject(next) ? next : {};
256
598
  for (const key of Object.keys(state)) {
257
- if (key !== "entries" && !(key in nxt)) emit({ op: "unset", path: [key] });
599
+ // §7 合同③(Refs #87):三方对称——fetch 三键归 fetch 面、全局代理三键归全局代理面板
600
+ //(均懒持久化),搜索面板草稿不含它们——不得 unset,否则搜索面保存会清掉
601
+ // 已保存的 fetch/全局代理配置(CFG-W-003 同族数据保护)。
602
+ if (key !== "entries" && !(key in nxt) && !FETCH_CONFIG_KEYS.includes(key) && !GLOBAL_PROXY_KEYS.includes(key)) {
603
+ emit({ op: "unset", path: [key] });
604
+ }
258
605
  }
259
606
  for (const key of Object.keys(nxt)) {
260
607
  if (key === "entries") continue;
@@ -327,18 +674,10 @@ globalThis.window?.__ModuleLoader__?.load({
327
674
  return true;
328
675
  }
329
676
 
330
- /** 为 user.entries[*] 上残留的明文密钥字段产出 unset 补丁(CFG-W-003)。 */
331
- function secretCleanupOps(userLayer, skipIndex = -1) {
332
- const entries = isPlainObject(userLayer) && Array.isArray(userLayer.entries) ? userLayer.entries : [];
333
- const ops = [];
334
- for (let i = 0; i < entries.length; i++) {
335
- if (i === skipIndex || !isPlainObject(entries[i])) continue;
336
- for (const k of Object.keys(entries[i])) {
337
- if (SECRET_FIELD.test(k)) ops.push({ op: "unset", path: ["entries", String(i), k] });
338
- }
339
- }
340
- return ops;
341
- }
677
+ // §7 合同①(Refs #87):fetchEntries 明文密钥清理已由 #88 单源闭集 secretClosureCleanupOps 承担
678
+ // (secretClosurePaths 递归整层 userLayer,含 fetchEntries;判据 = isSecretClosureKey 统一闭集)。
679
+ // 原 sol-87 P0-4 本地复刻清单(secretCleanupOps,判据 SECRET_FIELD)已删——fetch key 明文族
680
+ // 与 legacy 八名族同名单元(constants.js SECRET_KEY_CLOSURE 单源),无新增正则、无本地清单。
342
681
 
343
682
  /** 二轮修复:权威快照乐观更新——把本轮成功 ops 应用到 user 层克隆(与宿主 mutate 同形;随后读回仍为权威)。 */
344
683
  function applyOpsToLayer(layer, ops) {
@@ -382,6 +721,16 @@ globalThis.window?.__ModuleLoader__?.load({
382
721
  if (!cache || !proj || typeof proj.revision !== "number" || cache.size === 0) return null;
383
722
  let entries = draft.entries;
384
723
  const keys = {};
724
+ const poolKeys = {}; // #86 POOL-009 + sol P0:槽位缓冲复原(entryId → 带身份槽位数组,只写不回显)
725
+ const credDirty = {}; // sol P1:显式触碰/增删标志复原(删槽/清空意图不靠明文非空反推)
726
+ // 槽位记录归一:对象 {value, keptRef} 原样(身份保留);旧形态字符串值 → 无身份新槽
727
+ // (历史缓存降级语义:留空=丢弃、填入=新 ref,不做身份臆测)。
728
+ const normSlots = (raw) => {
729
+ if (!Array.isArray(raw) || raw.length === 0) return undefined;
730
+ return raw.map((s) => (isPlainObject(s)
731
+ ? { value: typeof s.value === "string" ? s.value : "", keptRef: typeof s.keptRef === "string" && s.keptRef !== "" ? s.keptRef : null }
732
+ : { value: typeof s === "string" ? s : "", keptRef: null }));
733
+ };
385
734
  let editingId = null;
386
735
  const conflicts = [];
387
736
  for (const [id, rec] of cache) {
@@ -395,8 +744,12 @@ globalThis.window?.__ModuleLoader__?.load({
395
744
  const existing = entries.find((e) => e.id === id);
396
745
  if (rec.mode === "create") {
397
746
  if (existing) { conflicts.push({ text: `新条目「${label}」:当前设置已存在同 id 条目,按版本冲突处理`, kind: "version" }); continue; }
398
- entries = [...entries, { id, type: rec.type, name: (rec.fields && rec.fields.name) ?? "", enabled: true, credentialRef: (rec.fields && rec.fields.credentialRef) ?? "" }];
747
+ // #88 第三批②:新建草稿的 proxyPin 一并复原。
748
+ entries = [...entries, { id, type: rec.type, name: (rec.fields && rec.fields.name) ?? "", enabled: true, credentialRef: (rec.fields && rec.fields.credentialRef) ?? "", proxyPin: (rec.fields && rec.fields.proxyPin) || PROXY_PINS.INHERIT }];
399
749
  keys[id] = rec.key ?? "";
750
+ const createdSlots = normSlots(rec.poolKeys) ?? [{ value: rec.key ?? "", keptRef: null }];
751
+ poolKeys[id] = createdSlots;
752
+ if (rec.credDirty) credDirty[id] = true;
400
753
  if (!editingId) editingId = id;
401
754
  continue;
402
755
  }
@@ -405,10 +758,21 @@ globalThis.window?.__ModuleLoader__?.load({
405
758
  cache.delete(id);
406
759
  continue;
407
760
  }
761
+ // #88 第三批②(Refs #88):proxyPin 随条目草稿缓存全量复原(重开/重挂回填,不静默丢)。
408
762
  entries = entries.map((e) => (e.id === id
409
- ? { ...e, name: (rec.fields && rec.fields.name) ?? e.name, credentialRef: (rec.fields && rec.fields.credentialRef) ?? (e.credentialRef ?? "") }
763
+ ? (() => {
764
+ const out = { ...e, name: (rec.fields && rec.fields.name) ?? e.name, credentialRef: (rec.fields && rec.fields.credentialRef) ?? (e.credentialRef ?? "") };
765
+ // #86 POOL-008②:池条目草稿复原 credentialRefs(重挂后保存不得丢失池形态)。
766
+ if (rec.fields && Array.isArray(rec.fields.credentialRefs)) out.credentialRefs = rec.fields.credentialRefs.slice();
767
+ // §7 合同④(Refs #88 #86):池槽位形态与条目 pin 同帧复原——两能力字段互不覆盖。
768
+ out.proxyPin = (rec.fields && rec.fields.proxyPin) || e.proxyPin || PROXY_PINS.INHERIT;
769
+ return out;
770
+ })()
410
771
  : e));
411
772
  if (rec.key) keys[id] = rec.key;
773
+ const editedSlots = normSlots(rec.poolKeys) ?? (rec.key ? [{ value: rec.key, keptRef: null }] : undefined);
774
+ if (editedSlots) poolKeys[id] = editedSlots;
775
+ if (rec.credDirty) credDirty[id] = true;
412
776
  if (!editingId) editingId = id;
413
777
  if (typeof rec.baseRevision !== "number" || rec.baseRevision !== proj.revision) {
414
778
  conflicts.push({ text: `条目「${label}」:起草后设置版本已变化;提交即按最新版本写入,或点击取消丢弃草稿`, kind: "version" });
@@ -418,6 +782,8 @@ globalThis.window?.__ModuleLoader__?.load({
418
782
  return {
419
783
  draft: { ...draft, entries, timeoutText: globalRec ? globalRec.timeoutText : draft.timeoutText },
420
784
  keys,
785
+ poolKeys,
786
+ credDirty,
421
787
  editingId,
422
788
  conflicts,
423
789
  };
@@ -435,6 +801,9 @@ globalThis.window?.__ModuleLoader__?.load({
435
801
  reorderFocusTarget,
436
802
  // 四轮修复(B-007/009/019 污染源):新建/编辑提交名称门(纯函数面,测试直测)。
437
803
  entryNameGate,
804
+ // sol P0/P1:凭据形态纯函数面(槽位稳定身份映射 + 显式触碰):重挂复原→提交链直测
805
+ // (组件内「卸载→重挂」不可达,SET-008 复原提交语义按此面单测,同 draftCacheApply 先例)。
806
+ credFormOf,
438
807
  });
439
808
 
440
809
  // ───────────────────────────── 组件 ─────────────────────────────
@@ -479,6 +848,15 @@ globalThis.window?.__ModuleLoader__?.load({
479
848
  };
480
849
  }
481
850
 
851
+ // #86 POOL-008②/008④:离散提交(开关/重排/移除)的落盘行整形——
852
+ // 草稿默认占位 credentialRef:"" 不得复活成持久行键(POOL-008②「共存零落盘」);
853
+ // credentialRefs 盘上形态原样携带(含损坏形态——写闸预检按盘上形态整单裁决,草稿层不得规整/丢弃)。
854
+ function persistCleanRow(e) {
855
+ const row = stripSecrets(isPlainObject(e) ? { ...e } : e);
856
+ if (row.credentialRef === "") delete row.credentialRef;
857
+ return row;
858
+ }
859
+
482
860
  function draftFrom(config) {
483
861
  const entries = Array.isArray(config.entries) ? config.entries.filter(isPlainObject) : [];
484
862
  return {
@@ -490,21 +868,28 @@ globalThis.window?.__ModuleLoader__?.load({
490
868
  }
491
869
  // proxy is a supported structured field; strip secret-shaped nested keys defensively.
492
870
  if (Object.prototype.hasOwnProperty.call(e, "proxy")) passthrough.proxy = stripSecrets(e.proxy);
493
- return {
871
+ const row = {
494
872
  ...passthrough,
495
873
  id: String(e.id),
496
874
  type: typeof e.type === "string" ? e.type : TOOL_TYPES[0],
497
875
  name: typeof e.name === "string" ? e.name : "",
498
876
  enabled: e.enabled !== false,
499
877
  credentialRef: typeof e.credentialRef === "string" ? e.credentialRef : "",
878
+ // PX-012(Refs #88):钉死态回读(缺省 inherit)。
879
+ proxyPin: typeof e.proxyPin === "string" && PROXY_PIN_VALUES.includes(e.proxyPin) ? e.proxyPin : PROXY_PINS.INHERIT,
500
880
  };
881
+ // #86 POOL-001/008④:credentialRefs 盘上形态显式进草稿(不经标量透传——数组会被丢,损坏形态即漏过写闸)。
882
+ if (e.credentialRefs !== undefined) row.credentialRefs = e.credentialRefs;
883
+ return row;
501
884
  }),
502
885
  useOfficial: config.useOfficialDeepSeekSearch !== false,
503
886
  timeoutText: config.timeoutMs === undefined ? "" : String(config.timeoutMs),
887
+ // PX-011/#120(Refs #88):全局代理重试开关态与全局代理引用名(引用名非机密,可回读呈现;明文永不回显)。
888
+ globalProxyRef: typeof config.globalProxy === "string" ? config.globalProxy : "",
504
889
  };
505
890
  }
506
891
 
507
- const EMPTY_DRAFT = Object.freeze({ entries: [], useOfficial: true, timeoutText: "" });
892
+ const EMPTY_DRAFT = Object.freeze({ entries: [], useOfficial: true, timeoutText: "", globalProxyRef: "" });
508
893
  const IDLE = Object.freeze({ kind: "idle", text: "", issues: [] });
509
894
 
510
895
  /** settings.section 完整设置面板(第二参)。所有配置读写均经同源 Remote API。 */
@@ -561,6 +946,8 @@ globalThis.window?.__ModuleLoader__?.load({
561
946
  .sc-card-name { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); overflow-wrap: anywhere; }
562
947
  .sc-card-name-placeholder { color: var(--dsw-alias-label-secondary, inherit); }
563
948
  .sc-type-badge { flex: none; padding: 1px 6px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-xs); font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); white-space: nowrap; }
949
+ /* #116 巡检:钉死徽标原为零规则裸文本,与 type 徽标族群并排时黏连且简陋——沿用 .sc-type-badge 同一档数值(不发明新数值)。 */
950
+ .sc-pin-badge { flex: none; padding: 1px 6px; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-xs); font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); white-space: nowrap; }
564
951
  .sc-type-duplicate { display: none; }
565
952
  /* R2:徽标纯点——.sc-status wrapper 废止;语义(role=img/aria-label/title/data-state)落在点自身。 */
566
953
  .sc-status-dot { box-sizing: border-box; display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; corner-shape: round; }
@@ -674,7 +1061,7 @@ globalThis.window?.__ModuleLoader__?.load({
674
1061
  .sc-card:hover .sc-drag-handle:disabled, .sc-drag-handle:disabled:focus-visible { opacity: .4; }
675
1062
  .sc-drag-handle:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
676
1063
  }
677
- .sc-switch { position: relative; display: inline-flex; align-items: center; gap: 8px; color: var(--dsw-alias-label-secondary); cursor: pointer; white-space: nowrap; }
1064
+ .sc-switch, .sc-pin-retry-switch { position: relative; display: inline-flex; align-items: center; gap: 8px; color: var(--dsw-alias-label-secondary); cursor: pointer; white-space: nowrap; }
678
1065
  .sc-switch:has(.sc-switch-input:disabled) { cursor: default; }
679
1066
  .sc-switch-label { font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-secondary); }
680
1067
  .sc-switch-input:disabled ~ .sc-switch-label { opacity: .5; }
@@ -776,6 +1163,8 @@ globalThis.window?.__ModuleLoader__?.load({
776
1163
  /* V5-2:原 .sc-picker/.sc-picker-item/-title/-billing 规则随 picker 控件废止整体移除(SPC-025 目标面废止)。 */
777
1164
  .sc-editor-title { margin: 0; font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }
778
1165
  .sc-editor-actions, .sc-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
1166
+ /* #110:编辑器(flex column)内启用开关按内容收敛——label 包裹区不随 align stretch 铺满整行。 */
1167
+ .sc-editor .sc-switch, .sc-editor .sc-pin-retry-switch { align-self: flex-start; }
779
1168
  .sc-field { display: flex; flex-direction: column; gap: 6px; margin-block: 0; }
780
1169
  .sc-field-label { display: inline-flex; align-items: center; gap: 10px; font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); }
781
1170
  .sc-error { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-error-primary); }
@@ -795,6 +1184,17 @@ globalThis.window?.__ModuleLoader__?.load({
795
1184
  .sc-input::placeholder { color: var(--dsw-alias-label-dimmed); }
796
1185
  .sc-input:focus { outline: none; border-color: var(--dsw-alias-state-business-primary); }
797
1186
  select.sc-input { max-width: 240px; cursor: pointer; }
1187
+ /* #116(用户实机反馈:键位槽区黏连):.sc-key-slots/.sc-key-slot-row/.sc-key-slot-status 此前零规则
1188
+ ——槽位字段间无间距、行内输入(width:100%)把状态标与移除钮挤到下行且无间隙。版式全部复用既有档:
1189
+ 行间 10px(.sc-card-row 同值,介于列表 8 与卡片 12 之间)、行内 8px(.sc-proxy-input-row 同档,
1190
+ 输入伸展/动作钮按内容收敛同该模式)、状态标 12/18 + state-success token(.sc-status-node 同族)。
1191
+ 纯版式:零行为语义、零新增文案、零 DOM 结构改动。 */
1192
+ .sc-key-slots { display: flex; flex-direction: column; gap: 10px; }
1193
+ .sc-key-slots > .sc-button { align-self: flex-start; }
1194
+ .sc-key-slot-row { display: flex; align-items: center; gap: 8px; }
1195
+ .sc-key-slot-row .sc-input { flex: 1 1 auto; min-width: 0; }
1196
+ .sc-key-slot-row .sc-button { flex: none; }
1197
+ .sc-key-slot-status { flex: none; font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-success-primary); white-space: nowrap; }
798
1198
  .sc-select-input {
799
1199
  appearance: none;
800
1200
  padding-right: 32px;
@@ -806,16 +1206,21 @@ globalThis.window?.__ModuleLoader__?.load({
806
1206
  background-size: 12px 12px;
807
1207
  }
808
1208
  .sc-billing-hint { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
809
- /* V5-7(Issue #58):编辑器高级区(<details> 原生折叠,无 display/visibility 隐藏机制;复用既有字号档 12/18)。
1209
+ /* V5-7(Issue #58)+ #145 修订注二③(Refs #145):编辑器高级区=常开普通容器(details/summary 折叠退役;复用既有字号档 12/18)。
810
1210
  说明行专用 .sc-proxy-hint(不复用 .sc-billing-hint——V5-6 判据钉「编辑路径零 sc-billing-hint 节点」,
811
1211
  换类即零迁移;视觉同档 12/18 tertiary)。 */
812
1212
  .sc-advanced { margin: 0; }
813
- .sc-advanced summary { font-size: 12px; line-height: 18px; font-weight: 500; color: var(--dsw-alias-label-secondary); cursor: pointer; }
814
1213
  .sc-advanced > .sc-field { margin-top: 8px; }
815
1214
  .sc-proxy-input-row { display: flex; align-items: center; gap: 8px; }
816
1215
  .sc-proxy-input-row .sc-input { flex: 1 1 auto; min-width: 0; }
817
1216
  .sc-proxy-input-row .sc-button-secondary { flex: none; }
818
1217
  .sc-proxy-hint { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
1218
+ /* #116 巡检:出网路径钉死单选组零规则——标签/选项/提示行距为 0、三选项横排无间隙且单选钮与文字相贴。
1219
+ 补节奏:行内列距 6px(.sc-field 同档)、选项间 16px(横)/4px(换行行距)、钮与文字 6px;
1220
+ 选项文字 12/18 次级色沿用字段标签字阶。纯版式,零行为零文案。 */
1221
+ /* #145 修订注二④:重试行并排=开关→标题→tooltip(列改行);.sc-pin-options 承载层注销(零选择器残留)。 */
1222
+ .sc-pin-row { display: flex; flex-direction: row; align-items: center; gap: 8px; }
1223
+ .sc-pin-option { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); cursor: pointer; }
819
1224
  .sc-status-node { margin: 0; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
820
1225
  .sc-status-node[data-state="saved"] { color: var(--dsw-alias-state-success-primary); }
821
1226
  .sc-status-node[data-state="error"] { color: var(--dsw-alias-state-error-primary); }
@@ -825,6 +1230,23 @@ globalThis.window?.__ModuleLoader__?.load({
825
1230
  .sc-timeout-row { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
826
1231
  .sc-timeout-label { font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-primary); }
827
1232
  .sc-timeout-row .sc-input { width: 240px; max-width: 100%; }
1233
+ /* #116 巡检(全局代理区块):重试区块零规则——开关长文案 nowrap 横向溢出、地址输入(width:100%)
1234
+ 把保存钮与状态行挤作一团。列布局 gap 8 沿用超时行同款;地址行沿用 .sc-proxy-input-row 模式
1235
+ (输入伸展、保存钮按内容收敛、状态行 flex-basis:100% 独占一行、12/18 沿用状态字档)。纯版式。 */
1236
+ .sc-escalation-row { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
1237
+ .sc-escalation-switch { max-width: 100%; white-space: normal; }
1238
+ .sc-escalation-proxy { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; width: 100%; }
1239
+ .sc-escalation-proxy .sc-input { flex: 1 1 240px; min-width: 0; }
1240
+ .sc-escalation-proxy .sc-button { flex: none; }
1241
+ .sc-escalation-status { margin: 0; flex-basis: 100%; font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
1242
+ .sc-escalation-title { display: flex; align-items: center; gap: 8px; }
1243
+ .sc-pin-retry-switch { max-width: 100%; white-space: normal; }
1244
+ .sc-retry-help { flex: none; width: 18px; height: 18px; padding: 0; border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-full, 50%); background: none; color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 16px; cursor: help; }
1245
+ /* #145 修订注二①/②(Refs #145):悬浮 tooltip——absolute 挂 .sc-tip-anchor,展开/收起零布局位移
1246
+ (消除内联披露致按钮跳动,用户复验直令);pointer-events:none 防悬浮窗抢焦点/hover 抖动。 */
1247
+ .sc-tip-anchor { position: relative; display: inline-flex; }
1248
+ .sc-tip-bubble { position: absolute; left: 0; top: calc(100% + 6px); z-index: 30; box-sizing: border-box; width: max-content; max-width: 340px; padding: 8px 10px; border: 0.5px solid var(--dsw-alias-settings-card-stroke); border-radius: var(--dsw-radius-l, 12px); background: var(--dsw-alias-settings-card-fill); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); font-size: 12px; line-height: 18px; font-weight: 400; color: var(--dsw-alias-label-secondary); white-space: normal; text-align: left; pointer-events: none; }
1249
+ /* #142:编辑器启用行退役——其专属样式规则随之注销(零选择器残留,钉在 139④ 翻钉测试)。 */
828
1250
  @media (max-width: 720px) {
829
1251
  .sc-card { padding: 18px 16px; }
830
1252
  .sc-card-row { align-items: flex-start; flex-direction: column; }
@@ -856,6 +1278,54 @@ globalThis.window?.__ModuleLoader__?.load({
856
1278
  return `SEARCH_CHAIN_CREDENTIAL_${safeId}_${Date.now().toString(36)}_${++credentialRefSeq}`;
857
1279
  }
858
1280
 
1281
+ /**
1282
+ * #86 POOL-002③/POOL-009:编辑器凭据目标形态裁决(纯函数,渲染门与提交共用同一判据):
1283
+ * 返回 { kind:"single", ref }(legacy 单引用)| { kind:"pool", refs }(池数组)| null(无凭据字段)。
1284
+ * - credentialRef 输入相对持久值被改动 且 key 区未触碰 → single(新值)(v0.2.0:ref 输入=显式 legacy 形态);
1285
+ * - key 区未触碰 且 有存量引用 → pool(existingRefs):legacy 单引用 = 1 元池惰性迁移(POOL-002③,
1286
+ * 同提交附带旧键 unset);池条目 = 池原样(零 diff);
1287
+ * - key 区触碰 → 按槽位录入序(sol P0 稳定身份):非空槽位 = 新 ref(同值槽位共享同一 ref,
1288
+ * POOL-009⑤ 去重语义,重复 ref 由写闸 preCheck 拒;新值顶替该槽位身份);空槽位 = 保留槽位
1289
+ * 自带身份 keptRef(原引用),无身份(新槽)= 丢弃该槽——不再按删除后的新下标回绑存量序;
1290
+ * 持久池条目恒 pool 形态(删槽后单留存仍为 1 元池,POOL-009②);legacy/新建:
1291
+ * 1 引用 = single(v0.2.0 单 key 形态不变)、≥2 = pool、0 = 无字段。
1292
+ * @param {object} entry 草稿行(credentialRef 输入现值)
1293
+ * @param {object|null} persisted 持久行(引用存量真值源;新建=null)
1294
+ * @param {Array<string|{value:string, keptRef:string|null}>} slotVals 槽位缓冲(只写;对象带身份)
1295
+ * @param {boolean} keyTouched key 区是否被触碰(显式标志:输入/增槽/删槽/SET-008 复原 credDirty)
1296
+ * @param {(value: string, ord: number) => string} newRefOf 新值→ref 生成器(提交=受控唯一;渲染门=占位符)
1297
+ */
1298
+ function credFormOf(entry, persisted, slotVals, keyTouched, newRefOf) {
1299
+ if (!entry || !KEYED_TYPES.includes(entry.type)) return null;
1300
+ const persistedRef = persisted && typeof persisted.credentialRef === "string" ? persisted.credentialRef : "";
1301
+ const persistedRefs = persisted && Array.isArray(persisted.credentialRefs) ? persisted.credentialRefs.filter((r) => typeof r === "string" && r !== "") : [];
1302
+ const persistedIsPool = persistedRefs.length > 0;
1303
+ const refTouched = (typeof entry.credentialRef === "string" ? entry.credentialRef : "") !== persistedRef;
1304
+ if (refTouched && !keyTouched) return { kind: "single", ref: (entry.credentialRef ?? "").trim() };
1305
+ const existingRefs = persistedIsPool ? persistedRefs : (persistedRef ? [persistedRef] : []);
1306
+ if (!keyTouched) return existingRefs.length > 0 ? { kind: "pool", refs: existingRefs } : null;
1307
+ const refs = [];
1308
+ const valueRef = new Map();
1309
+ (Array.isArray(slotVals) ? slotVals : []).forEach((raw) => {
1310
+ // sol P0:按稳定身份映射——空槽位保留槽位自带的 keptRef(原引用),不再按删除后的
1311
+ // 新下标回绑 existingRefs[i](旧 bug:池 [A,B,C] 删头保存掉的是 C 而非 A)。
1312
+ const s = isPlainObject(raw) ? raw : null;
1313
+ const v = (s ? (typeof s.value === "string" ? s.value : "") : (typeof raw === "string" ? raw : "")).trim();
1314
+ if (v === "") {
1315
+ const kept = s && typeof s.keptRef === "string" ? s.keptRef.trim() : "";
1316
+ if (kept !== "") refs.push(kept); // 空槽位=保留原引用身份;无身份(新槽)=丢弃该槽
1317
+ return;
1318
+ }
1319
+ let r = valueRef.get(v);
1320
+ if (r === undefined) { r = newRefOf(v, refs.length); valueRef.set(v, r); }
1321
+ refs.push(r); // 非空值=新受控 ref(同值槽位共享;新值顶替该槽位身份)
1322
+ });
1323
+ if (persistedIsPool) return refs.length > 0 ? { kind: "pool", refs } : null;
1324
+ if (refs.length === 1) return { kind: "single", ref: refs[0] };
1325
+ if (refs.length >= 2) return { kind: "pool", refs };
1326
+ return null;
1327
+ }
1328
+
859
1329
  function SettingsPanel(_props) {
860
1330
  if (!React) return null;
861
1331
  // 组件工厂的轻量测试/预览适配:完整 DSH React 提供 hooks;仅 createElement 的宿主探针显示静态标题与添加入口。
@@ -874,8 +1344,20 @@ globalThis.window?.__ModuleLoader__?.load({
874
1344
  base: {},
875
1345
  user: {},
876
1346
  revision: undefined,
877
- draft: { entries: [], useOfficial: true, timeoutText: String(DEFAULT_TIMEOUT_MS) },
1347
+ draft: { entries: [], useOfficial: true, timeoutText: String(DEFAULT_TIMEOUT_MS), globalProxyRef: "" },
878
1348
  keys: {},
1349
+ // #86 POOL-009:池槽位 key 缓冲(entryId → 槽位值数组)——仅在编辑 keyed 条目且触碰
1350
+ // key 区(输入/增槽/删槽)后建档;成功提交/显式取消清除。只写不回显(CFG-002 同政策)。
1351
+ poolKeys: {},
1352
+ // #86 POOL-002③/POOL-009:凭据区触碰标记(entryId → true)——区分「key 未触碰(惰性迁移
1353
+ // 1 元池)」与「触碰后留空(保留旧形态)」;SET-008 复原出非空 key 缓冲时同样置位。
1354
+ credTouched: {},
1355
+ // PX-011(Refs #88):全局代理地址输入明文缓冲——只写不回显;成功保存即清(重开输入框为空)。
1356
+ globalProxyText: "",
1357
+ // PX-011:全局代理重试区块内错误槽(role=alert;与节级成功提示互斥)。
1358
+ escalationError: null,
1359
+ // OSB-004(Refs #152):无隔离远程 PAC 放行态(每次读回自 base∪user 重导出;缺省 false)。
1360
+ pacUnlocked: false,
879
1361
  // V5-7(Issue #58):代理输入明文缓冲(entryId → 文本),与 keys 同生命周期——
880
1362
  // 仅用户触碰输入后建档(键存在=已触碰);成功提交/显式取消清除。
881
1363
  // 只写不回显:渲染 value 只读本缓冲;条目已持久 proxy 绝不写入任何 DOM。
@@ -887,6 +1369,14 @@ globalThis.window?.__ModuleLoader__?.load({
887
1369
  savedNotice: null,
888
1370
  sectionError: null,
889
1371
  editorError: null,
1372
+ // #139(Refs #139):retry-help 问号内联说明的编辑器局部草稿态(true=展开)。
1373
+ // 不持久、零配置键;editingId 的任一变化(切条目/收起/取消/提交成功/移除/新建)即重置 false,
1374
+ // 面板卸载随组件态自然销毁——重开编辑器恒收起初态。
1375
+ editorHelpOpen: false,
1376
+ // #145 修订注二②:全局代理标题 tooltip 悬浮态(hover/focus 呈现,零持久零配置键,随组件态销毁)。
1377
+ globalHelpOpen: false,
1378
+ // #156(Refs #156):「信任所有 PAC」? 气泡独立状态位(与编辑器/全局代理气泡互不串台)。
1379
+ pacHelpOpen: false,
890
1380
  // 三轮修复(B-012):重排回焦意图——被移动条目 id;渲染提交后 effect 据此回焦(焦点跟随条目)。
891
1381
  pendingHandleFocus: null,
892
1382
  });
@@ -940,7 +1430,7 @@ globalThis.window?.__ModuleLoader__?.load({
940
1430
  if (draft.entries.some((e) => e.id === m.editingId)) {
941
1431
  return {
942
1432
  ...draft,
943
- entries: draft.entries.map((e) => (e.id === m.editingId ? { ...e, name: prev.name, credentialRef: prev.credentialRef, enabled: prev.enabled } : e)),
1433
+ entries: draft.entries.map((e) => (e.id === m.editingId ? { ...e, name: prev.name, credentialRef: prev.credentialRef, enabled: prev.enabled, proxyPin: prev.proxyPin } : e)),
944
1434
  };
945
1435
  }
946
1436
  // v3 用户反馈(V3-1 无占位行):v2「未提交新建重追加尾部」分支废止——在编新建条目(不在新投影中)
@@ -956,7 +1446,7 @@ globalThis.window?.__ModuleLoader__?.load({
956
1446
  const cacheBaseRevision = (m) => (typeof latestRef.current.revision === "number"
957
1447
  ? latestRef.current.revision
958
1448
  : (typeof m.revision === "number" ? m.revision : undefined));
959
- const syncEntryCache = (m, id, entry, keyVal) => {
1449
+ const syncEntryCache = (m, id, entry, keyVal, poolSlots, credDirty) => {
960
1450
  if (!entry) return;
961
1451
  const rec = draftCache.get(id) || {
962
1452
  mode: entryIsPersisted(m, entry) ? "edit" : "create",
@@ -965,8 +1455,15 @@ globalThis.window?.__ModuleLoader__?.load({
965
1455
  key: "",
966
1456
  baseRevision: cacheBaseRevision(m),
967
1457
  };
968
- rec.fields = { name: entry.name, credentialRef: entry.credentialRef ?? "" };
1458
+ rec.type = entry.type; // §7 合同④(Refs #88 #86):缓存记录厂商随草稿同口径更新(新建重放不得用旧厂商)
1459
+ // #86 POOL-008② + #88 第三批②(§7 合同④,Refs #88 #86):条目草稿记录同帧保留池形态(credentialRefs)
1460
+ // 与条目 pin(proxyPin)——重挂复原两能力字段互不丢;legacy 条目 fields 形态不变(proxyPin 恒默认 inherit)。
1461
+ rec.fields = { name: entry.name, credentialRef: entry.credentialRef ?? "", proxyPin: entry.proxyPin ?? PROXY_PINS.INHERIT };
1462
+ if (Array.isArray(entry.credentialRefs) && entry.credentialRefs.length > 0) rec.fields.credentialRefs = entry.credentialRefs.slice();
969
1463
  rec.key = keyVal ?? "";
1464
+ if (Array.isArray(poolSlots) && poolSlots.length > 0) rec.poolKeys = poolSlots.slice();
1465
+ // sol P1:显式触碰/增删标志随缓存存——复原提交的删槽/清空意图不依赖明文是否非空反推。
1466
+ if (credDirty) rec.credDirty = true;
970
1467
  draftCache.set(id, rec);
971
1468
  };
972
1469
  const syncGlobalCache = (m, timeoutText) => {
@@ -989,13 +1486,35 @@ globalThis.window?.__ModuleLoader__?.load({
989
1486
  return;
990
1487
  }
991
1488
  const effective = { ...proj.base, ...proj.user };
992
- const check = validate(effective);
993
- const normalized = check.ok ? check.config : effective;
1489
+ // #86 分叉规则(§7 合同③包装点①,Refs #88 #86):新契约字段族(credentialRefs / proxyEscalation /
1490
+ // globalProxy / proxyPin)违规 validate 抛错——读回面就地转 legacy 返回形态(面板可见校验告警,
1491
+ // 渲染链不得被拒绝对象击穿);legacy 违规本就是返回形态。成功直返归一化配置。
1492
+ // (PX-012#4 读路径不崩溃语义由本 try/catch 承载——与 #86 包装同形,单一锚点。)
1493
+ let check;
1494
+ try {
1495
+ check = validate(effective);
1496
+ } catch (e) {
1497
+ check = { ok: false, code: "CONFIG_INVALID", issues: [{ message: String((e && e.message) || "配置未通过校验") }] };
1498
+ }
1499
+ const normalized = check && check.ok === false ? effective : check;
994
1500
  // 二轮修复:权威快照同 tick 写入(先于 setModel)——任何 await 本 done 链尾的路径,读 latestRef 必为最新已读回视图。
995
1501
  latestRef.current = { user: proj.user, base: proj.base, revision: proj.revision };
996
1502
  setModel((m) => {
997
1503
  let draft = draftFrom(normalized);
998
1504
  let nextKeys = m.keys;
1505
+ let nextPoolKeys = m.poolKeys;
1506
+ let nextCredTouched = m.credTouched;
1507
+ // #86 POOL-009:SET-008 槽位缓冲复原——复原出非空槽位值即视为凭据区已触碰
1508
+ // (否则重放保存会误走「未触碰=惰性迁移」分支,丢弃复原的 key 意图)。
1509
+ const mergeOverlayBuffers = (overlay) => {
1510
+ const poolKeys = { ...m.poolKeys };
1511
+ const credTouched = { ...m.credTouched };
1512
+ for (const [id, slots] of Object.entries(overlay.poolKeys || {})) poolKeys[id] = slots;
1513
+ // sol P1:触碰复原只认显式标志(rec.credDirty)——删槽后全空保存不得被「明文为空」
1514
+ // 反推成未触碰(否则删槽意图在重挂后静默丢失,保存零 mutate)。
1515
+ for (const id of Object.keys(overlay.credDirty || {})) credTouched[id] = true;
1516
+ return { poolKeys, credTouched };
1517
+ };
999
1518
  let editingId = keepStatus ? m.editingId : null;
1000
1519
  let sectionError;
1001
1520
  if (keepStatus) {
@@ -1015,6 +1534,9 @@ globalThis.window?.__ModuleLoader__?.load({
1015
1534
  if (overlay) {
1016
1535
  draft = overlay.draft;
1017
1536
  nextKeys = { ...m.keys, ...overlay.keys };
1537
+ const merged = mergeOverlayBuffers(overlay);
1538
+ nextPoolKeys = merged.poolKeys;
1539
+ nextCredTouched = merged.credTouched;
1018
1540
  draft = overlayEditingDraft(m, draft);
1019
1541
  if (draftCache.has(DRAFT_CACHE_GLOBAL_KEY)) draft = { ...draft, timeoutText: m.draft.timeoutText };
1020
1542
  sectionError = overlay.conflicts.length > 0
@@ -1028,13 +1550,19 @@ globalThis.window?.__ModuleLoader__?.load({
1028
1550
  }
1029
1551
  } else {
1030
1552
  // 初始挂载:SET-008 重挂校验(版本一致→回填+自动重开;冲突/外部删除→顶部告警,保留草稿,不静默丢弃/重放)。
1553
+ // #86 分叉规则:仅 legacy 返回形态 { ok:false } 走校验告警分支(成功直返归一化对象)。
1031
1554
  sectionError = typeof proj.revision !== "number"
1032
1555
  ? { text: "宿主投影缺少 revision,禁止保存(请重新打开设置)", issues: [] }
1033
- : check.ok ? null : { text: "当前配置未通过校验,请修正后保存", issues: check.issues.map((i) => i.message) };
1556
+ : check && check.ok === false
1557
+ ? { text: "当前配置未通过校验,请修正后保存", issues: check.issues.map((i) => i.message) }
1558
+ : null;
1034
1559
  const overlay = draftCacheApply(draftCache, proj, draft);
1035
1560
  if (overlay) {
1036
1561
  draft = overlay.draft;
1037
1562
  nextKeys = { ...m.keys, ...overlay.keys };
1563
+ const merged = mergeOverlayBuffers(overlay);
1564
+ nextPoolKeys = merged.poolKeys;
1565
+ nextCredTouched = merged.credTouched;
1038
1566
  editingId = overlay.editingId;
1039
1567
  if (overlay.conflicts.length > 0) {
1040
1568
  sectionError = { text: "设置已被外部变更:未提交草稿已保留(未静默丢弃、未自动重放)", issues: overlay.conflicts.map((c) => c.text) };
@@ -1051,8 +1579,11 @@ globalThis.window?.__ModuleLoader__?.load({
1051
1579
  base: proj.base,
1052
1580
  user: proj.user,
1053
1581
  revision: proj.revision,
1582
+ pacUnlocked: effAllowUnsandboxedPac(proj),
1054
1583
  draft,
1055
1584
  keys: nextKeys,
1585
+ poolKeys: nextPoolKeys,
1586
+ credTouched: nextCredTouched,
1056
1587
  editingId,
1057
1588
  savedNotice: keepStatus ? m.savedNotice : null,
1058
1589
  sectionError,
@@ -1143,6 +1674,31 @@ globalThis.window?.__ModuleLoader__?.load({
1143
1674
  // 二轮修复(单写者):提交整体在 commitChain 队列内执行——(a) 先 await 全部在途读回落进 latestRef;
1144
1675
  // (b) ops 从权威快照起算(buildOps(snap),snap=最新持久投影);(c) expectedRevision 取同一 snap(乐观锁);
1145
1676
  // (d) 成功后乐观更新 latestRef 并 await load(true) 读回——队列内下一次提交必然从本轮之后的最新投影起算。
1677
+ // ─────────────── #88 首批 P0 统一 ops builder(Refs #88,sol-review 同根因修) ───────────────
1678
+ // 所有保存动作(离散/编辑器/全局代理重试区块)收敛同一终态语义:
1679
+ // (1) baseOps = 意图 diff(含删除/重排等结构变更);
1680
+ // (2) 终层清理:对应用 baseOps 后的候选层跑 secret 闭集(legacy secret 族 + globalProxy 族,递归、按字段名)——
1681
+ // 合法 set 已在候选层(引用值不命中闭集),后位 unset 永不会覆盖前位合法 op;
1682
+ // 结构变更后在最终候选层上生成清理路径(第三批④:删除行不再按删除前下标清错行);
1683
+ // (3) 终态预检:对 ops 应用后的实际终态 validate(抛错形态转返回形);
1684
+ // (4) 调用方预检通过后才写凭据/mutate(第四批 P0 次序)。
1685
+ const finalizeOps = (snap, baseOps) => {
1686
+ const candidateUser = applyOpsToLayer(snap.user, baseOps);
1687
+ const cleanup = secretClosureCleanupOps(candidateUser);
1688
+ const ops = cleanup.length > 0 ? [...baseOps, ...cleanup] : baseOps;
1689
+ const finalUser = cleanup.length > 0 ? applyOpsToLayer(candidateUser, cleanup) : candidateUser;
1690
+ let check;
1691
+ try {
1692
+ const res = validate({ ...(isPlainObject(snap.base) ? snap.base : {}), ...finalUser });
1693
+ // §7 合同③(Refs #88 #86):#86 包装契约——成功直返归一化配置(无 .ok 字段)、legacy 违规返回形、
1694
+ // 新族违规抛错。本抽象对调用方恒定输出 { ok, issues }:成功 → { ok:true },其余两形态原样透传。
1695
+ check = res && res.ok === false ? res : { ok: true };
1696
+ } catch (err) {
1697
+ check = { ok: false, issues: [{ message: String((err && err.message) || err) }] };
1698
+ }
1699
+ return { ops, check };
1700
+ };
1701
+
1146
1702
  const commitDiscrete = (buildOps, successText, onGateReject) => {
1147
1703
  const m0 = model;
1148
1704
  if (lockRef.current || m0.phase !== "ready" || typeof m0.revision !== "number") return Promise.resolve(false);
@@ -1166,20 +1722,22 @@ globalThis.window?.__ModuleLoader__?.load({
1166
1722
  return false;
1167
1723
  }
1168
1724
  if (!ops || ops.length === 0) return true; // 意图未变化:无需写
1169
- // CFG-W-001 / CFG-W-002:所有离散写入在发出 mutate 前均须通过读闸等价预检。
1170
- const nextUser = applyOpsToLayer(snap.user, ops);
1171
- const nextEffective = { ...(isPlainObject(snap.base) ? snap.base : {}), ...nextUser };
1172
- const check = validate(nextEffective);
1173
- if (!check.ok) {
1725
+ // #88 首批 P0(Refs #88):统一 ops builder——终层清理闭集(统一闭集两族,§7 合同②)+ 终态预检。
1726
+ // CFG-W-001 / CFG-W-002 + #86 分叉规则(§7 合同③包装点②,Refs #88 #86):终态预检锚点收进 finalizeOps
1727
+ // 内部(try/catch:新契约字段族违规抛错 → 转返回形呈现;legacy 违规本就是返回形态)——
1728
+ // 离散/编辑器/全局代理重试区块三条保存路径共用同一预检面,不得各自复制。
1729
+ const fin = finalizeOps(snap, ops);
1730
+ if (!fin.check.ok) {
1174
1731
  if (!alive.current) return false;
1175
1732
  if (onGateReject) onGateReject(snap);
1176
1733
  setModel((m) => ({
1177
1734
  ...m,
1178
1735
  savedNotice: null,
1179
- sectionError: { text: "无法保存:配置未通过校验", issues: check.issues.map((i) => i.message) },
1736
+ sectionError: { text: "无法保存:配置未通过校验", issues: fin.check.issues.map((i) => i.message) },
1180
1737
  }));
1181
1738
  return false;
1182
1739
  }
1740
+ ops = fin.ops;
1183
1741
  if (lockRef.current) return false; // 队列排空后复核在途标志(排队期间可能已有新操作先行)
1184
1742
  setModel((m) => ({ ...m, busy: true, savedNotice: null, sectionError: null }));
1185
1743
  let response;
@@ -1212,13 +1770,67 @@ globalThis.window?.__ModuleLoader__?.load({
1212
1770
  if (lockRef.current) return;
1213
1771
  const entry = model.draft.entries.find((e) => e.id === id);
1214
1772
  setModel((m) => ({ ...m, editorError: null, draft: { ...m.draft, entries: m.draft.entries.map((e) => (e.id === id ? { ...e, [field]: value } : e)) } }));
1215
- if (entry) syncEntryCache(model, id, { ...entry, [field]: value }, typeof model.keys[id] === "string" ? model.keys[id] : "");
1773
+ if (entry) {
1774
+ // #86 POOL-009:非 key 字段变更同样同步槽位缓冲(SET-008 记录不丢 key 草稿)。
1775
+ const nextEntry = { ...entry, [field]: value };
1776
+ const slots = poolSlotsOf(nextEntry);
1777
+ const keyVal = slots.map((s) => (s && typeof s.value === "string" ? s.value : "")).find((v) => v.trim() !== "") ?? "";
1778
+ syncEntryCache(model, id, nextEntry, keyVal, slots);
1779
+ }
1780
+ };
1781
+ // #86 POOL-009 + sol P0(稳定身份):槽位 = { value: 只写明文, keptRef: 既有引用身份 | null }。
1782
+ // keptRef 把槽位与持久引用绑定:删槽=连身份一起删、保存按身份映射 ref 序列(不再按删除后
1783
+ // 的新下标重绑);新槽/新建条目 keptRef=null(留空=丢弃、填入=新受控 ref)。
1784
+ // 默认数——keyed 类型 = 持久池规模(≥1,逐引用带身份),无池时 1(legacy 单槽带 credentialRef
1785
+ // 身份;新建条目=null);免 key 类型(bing)= 0 槽(POOL-010① 面板面)。
1786
+ const defaultPoolSlots = (entry) => {
1787
+ if (!entry || !KEYED_TYPES.includes(entry.type)) return [];
1788
+ const refs = Array.isArray(entry.credentialRefs) ? entry.credentialRefs.filter((r) => typeof r === "string" && r !== "") : [];
1789
+ if (refs.length > 0) return refs.slice(0, POOL_MAX).map((ref) => ({ value: "", keptRef: ref }));
1790
+ const legacyRef = typeof entry.credentialRef === "string" && entry.credentialRef !== "" ? entry.credentialRef : null;
1791
+ return [{ value: "", keptRef: legacyRef }];
1216
1792
  };
1217
- const updateKey = (id, value) => {
1793
+ const poolSlotsOf = (entry) => {
1794
+ if (!entry) return [];
1795
+ const rec = model.poolKeys[entry.id];
1796
+ return Array.isArray(rec) && rec.length > 0 && isPlainObject(rec[0]) ? rec : defaultPoolSlots(entry);
1797
+ };
1798
+ // SET-008 同步:key 记录保留首非空槽位值(legacy 兼容面);poolKeys 存带身份槽位;
1799
+ // credDirty=显式触碰/增删标志(sol P1:复原提交须保留删槽语义,不得从明文是否非空反推)。
1800
+ const syncPoolCache = (entry, id, slots, credDirty) => {
1801
+ const keyVal = slots.map((s) => (s && typeof s.value === "string" ? s.value : "")).find((v) => v.trim() !== "") ?? "";
1802
+ syncEntryCache(model, id, entry, keyVal, slots, credDirty);
1803
+ };
1804
+ const updatePoolKey = (id, idx, value) => {
1805
+ if (lockRef.current) return;
1806
+ const entry = model.draft.entries.find((e) => e.id === id);
1807
+ if (!entry) return;
1808
+ const cur = poolSlotsOf(entry);
1809
+ if (!Number.isInteger(idx) || idx < 0 || idx >= cur.length) return;
1810
+ const next = cur.slice();
1811
+ next[idx] = { ...next[idx], value: typeof value === "string" ? value : "" }; // 身份不动,只写值
1812
+ setModel((m) => ({ ...m, editorError: null, poolKeys: { ...m.poolKeys, [id]: next }, credTouched: { ...m.credTouched, [id]: true } }));
1813
+ syncPoolCache(entry, id, next, true);
1814
+ };
1815
+ const addPoolSlot = (id) => {
1218
1816
  if (lockRef.current) return;
1219
1817
  const entry = model.draft.entries.find((e) => e.id === id);
1220
- setModel((m) => ({ ...m, editorError: null, keys: { ...m.keys, [id]: value } }));
1221
- if (entry) syncEntryCache(model, id, entry, value);
1818
+ if (!entry) return;
1819
+ const cur = poolSlotsOf(entry);
1820
+ if (cur.length >= POOL_MAX) return; // POOL-009⑤b:8 槽为上限(按钮同判据禁用)
1821
+ const next = [...cur, { value: "", keptRef: null }]; // 新槽无身份:留空=丢弃、填入=新 ref
1822
+ setModel((m) => ({ ...m, editorError: null, poolKeys: { ...m.poolKeys, [id]: next }, credTouched: { ...m.credTouched, [id]: true } }));
1823
+ syncPoolCache(entry, id, next, true);
1824
+ };
1825
+ const removePoolSlot = (id, idx) => {
1826
+ if (lockRef.current) return;
1827
+ const entry = model.draft.entries.find((e) => e.id === id);
1828
+ if (!entry) return;
1829
+ const cur = poolSlotsOf(entry);
1830
+ if (cur.length <= 1 || !Number.isInteger(idx)) return; // keyed 条目恒保留至少 1 槽
1831
+ const next = cur.filter((_, i) => i !== idx); // sol P0:身份随槽位删除,剩余槽位身份不重绑
1832
+ setModel((m) => ({ ...m, editorError: null, poolKeys: { ...m.poolKeys, [id]: next }, credTouched: { ...m.credTouched, [id]: true } }));
1833
+ syncPoolCache(entry, id, next, true);
1222
1834
  };
1223
1835
  // V5-7(Issue #58):代理输入变更——只更新明文缓冲并清除该编辑器错误态。
1224
1836
  // 缓冲不进 SET-008 草稿缓存(缓存记录 shape 不变);后台读回/切换条目不清缓冲(与 keys 同)。
@@ -1248,7 +1860,7 @@ globalThis.window?.__ModuleLoader__?.load({
1248
1860
  setModel((m) => ({ ...m, sectionError: null, savedNotice: null, draft: { ...m.draft, useOfficial: target } }));
1249
1861
  commitDiscrete((m) => (effectiveOfficialOf(m) === target
1250
1862
  ? []
1251
- : [{ op: "set", path: ["useOfficialDeepSeekSearch"], value: target }, ...secretCleanupOps(m.user)]), null); // v3 用户反馈(V3-3):开关免提示——开关状态呈现即反馈(落盘语义不变)
1863
+ : [{ op: "set", path: ["useOfficialDeepSeekSearch"], value: target }]), null); // v3 用户反馈(V3-3):开关免提示——开关状态呈现即反馈(落盘语义不变;清理闭集由 finalizeOps 终层统一附加,#88 首批 P0)
1252
1864
  };
1253
1865
 
1254
1866
  // 超时输入:失焦/回车 且 值有变化且合法 才提交(仅 timeoutMs 键);成功后清 __global__ 草稿记录(SET-008)。
@@ -1272,10 +1884,189 @@ globalThis.window?.__ModuleLoader__?.load({
1272
1884
  // 新值落 user 层单键 override(与 official 开关同形,不连带具化条目列表)。
1273
1885
  const run = commitDiscrete((snap) => (effectiveTimeoutMsOf(snap) === parsed
1274
1886
  ? []
1275
- : [{ op: "set", path: ["timeoutMs"], value: parsed }, ...secretCleanupOps(snap.user)]), "已保存设置。");
1887
+ : [{ op: "set", path: ["timeoutMs"], value: parsed }]), "已保存设置。"); // 清理闭集由 finalizeOps 终层统一附加(#88 首批 P0)
1276
1888
  run.then((ok) => { if (ok) draftCache.delete(DRAFT_CACHE_GLOBAL_KEY); }, () => {});
1277
1889
  };
1278
1890
 
1891
+ // ─────────────── PX-011/PX-002(Refs #88):全局代理重试区块 ───────────────
1892
+ // 开关为草稿字段(onChange 不落盘——避免非法态零 mutate 或孤儿凭据写入);区块内「保存」按钮为唯一保存路径:
1893
+ // 语法门(SET-004 违规零出站)→ 写闸预检(CFG-W-004,先于凭据写)→ credentials/set(仅录入新址时,先写凭据)→ settings/mutate。
1894
+ // 全局代理明文只写不回显:输入缓冲不进配置、任何 DOM 值永不含已存地址;状态面只呈脱敏 scheme://host:port。
1895
+ const globalProxyRedacted = React.useRef({}); // 引用名 → 脱敏目标(会话内记忆,不落盘不读回)
1896
+ // #142(PX-011 修订注③):总闸开关 UI 退役——updateEscalation 随之退役;面板对 proxyEscalation
1897
+ // 零写(保存 ops 恒零该键),存量显式 false 为隐藏兼容读面、仍全局生效。
1898
+ const updateGlobalProxyText = (ev) => {
1899
+ if (lockRef.current) return;
1900
+ setModel((m) => ({ ...m, escalationError: null, sectionError: null, globalProxyText: String(ev.target?.value ?? "") }));
1901
+ };
1902
+ const commitEscalation = () => {
1903
+ const m0 = model;
1904
+ if (lockRef.current || m0.phase !== "ready" || typeof m0.revision !== "number") return Promise.resolve(false);
1905
+ return enqueueCommit(async () => {
1906
+ const fail = (message) => {
1907
+ setModel((m) => ({ ...m, busy: false, escalationError: { text: message }, savedNotice: null, sectionError: null }));
1908
+ return false;
1909
+ };
1910
+ // #88 第五批⑥(Refs #88):统一错误边界——宿主拒绝消息可能回显本次 URL 明文(含认证)——
1911
+ // 呈现前把本次 URL(完整形)替换为脱敏形、页内既有 key 值全脱敏;另对任意 http(s) URL 剥 userinfo(不留 path/query)。
1912
+ // text/target/maskedTarget/safeMsg 声明于 try 之外:catch 面(凭据/宿主 RPC 抛异常)必须可达 safeMsg,
1913
+ // 否则 try 内块级 const 在 catch 中 ReferenceError 被提交链吞掉,busy 恒置位、错误永不呈现。
1914
+ const text = String(model.globalProxyText ?? "").trim();
1915
+ let target = null;
1916
+ let maskedTarget = "";
1917
+ const safeMsg = (msg) => {
1918
+ let out = String((msg && msg.message) || msg || "");
1919
+ // sol 收敛轮案3(lead 裁决·兜底遮蔽补全):第一步先对本次完整原始 text 整体遮蔽——
1920
+ // userinfo 含引号等原始字符时(new URL 接受并编码,是合法 URL)token 正则会劈断,残段泄
1921
+ // path/query/凭据片段;字面 split/join(完整原值 → maskedTarget;原值未解析成功 → [redacted URL])
1922
+ // 不依赖正则语义,完整形先整段落定。第二步才通用 token 归一 + fail-closed(覆盖非本次原值回显)。
1923
+ if (text !== "") {
1924
+ out = out.split(text).join(maskedTarget !== "" ? maskedTarget : "[redacted URL]");
1925
+ }
1926
+ // #88 第五批⑥ + 二次整改 P1-③ + sol 第三批(Refs #88):统一错误边界——识别消息内**所有**
1927
+ // HTTP(S) URL token(scheme 大小写不敏感 /i:大写 scheme 合法,new URL 接受并归一小写),
1928
+ // 解析后仅留 protocol//host:userinfo/path/query/fragment 一律剥除。
1929
+ // fail-closed(sol 第三批 lead 裁决):疑似 URL token(已匹配 http(s):// 前缀)解析失败
1930
+ // 必须替换 [redacted URL]——绝不返回原文(token 可能承载认证明文);不匹配该前缀的普通文本
1931
+ // 不动,可操作原因面不受损。解析前剥离常见尾部标点()/】}>.,;:!?)再回贴——相邻收尾标点
1932
+ // 不入解析核、但保留于输出(原文可读性不损);核剥空即按 fail-closed 处置。
1933
+ out = out.replace(/https?:\/\/[^\s"'<>]+/gi, (token) => {
1934
+ const m = token.match(/^(.*?)([\)\)】\]}>.,;:!?]*)$/);
1935
+ const core = m[1];
1936
+ const trail = m[2];
1937
+ if (core === "") return "[redacted URL]" + trail;
1938
+ try {
1939
+ const u = new URL(core);
1940
+ return (u.protocol === "http:" || u.protocol === "https:" ? `${u.protocol}//${u.host}` : "[redacted URL]") + trail;
1941
+ } catch {
1942
+ return "[redacted URL]" + trail;
1943
+ }
1944
+ });
1945
+ for (const secret of Object.values(model.keys)) {
1946
+ if (typeof secret === "string" && secret.trim()) out = out.split(secret.trim()).join("[redacted]");
1947
+ }
1948
+ return out;
1949
+ };
1950
+ try {
1951
+ if (!alive.current) return false;
1952
+ await drainReads();
1953
+ if (!alive.current) return false;
1954
+ const snap = latestRef.current;
1955
+ if (!snap || typeof snap.revision !== "number") return fail("宿主投影缺少 revision,禁止保存(请重新打开设置)");
1956
+ const eff = { ...(isPlainObject(snap.base) ? snap.base : {}), ...(isPlainObject(snap.user) ? snap.user : {}) };
1957
+ if (text !== "") {
1958
+ try { target = new URL(text); } catch { return fail("全局代理地址须为绝对 HTTP(S) URL(如 http://host:port)"); }
1959
+ if (target.protocol !== "http:" && target.protocol !== "https:") return fail("全局代理地址须为 HTTP(S) URL");
1960
+ maskedTarget = `${target.protocol}//${target.host}`;
1961
+ }
1962
+ const prevRef = typeof eff.globalProxy === "string" && eff.globalProxy !== "" ? eff.globalProxy : undefined;
1963
+ // #88 第四批 P0 + 二次整改 P0-B(Refs #88):新地址(含首存)恒生成真唯一 ref(UUID hex,见
1964
+ // makeUniqueGlobalProxyRef)——凭据成功而 mutate 冲突/拒绝时,配置层旧 ref/value/活路由全部不变
1965
+ // (ref 随 mutate 原子切换),失败只留孤儿新 ref(宿主凭据服务可清理),绝不读旧 secret 回滚。
1966
+ const nextRef = text !== "" ? makeUniqueGlobalProxyRef() : prevRef;
1967
+ // 统一 ops builder(#88 首批 P0):baseOps 意图 diff → 终层清理闭集(两族)→ 实际终态预检——
1968
+ // 构造/清理/终态 validate 全部先于 credentials/set(第四批 P0 次序;CFG-W-004 先于凭据写预检)。
1969
+ const baseOps = [];
1970
+ // #142(PX-011 修订注③):本区块对 proxyEscalation 零写——ops 恒零该键(既不实体化 true
1971
+ // 也不抹除 false);存量显式 false 保留为隐藏兼容读面,仍全局生效。
1972
+ if (nextRef !== undefined && nextRef !== prevRef) baseOps.push({ op: "set", path: ["globalProxy"], value: nextRef });
1973
+ const fin = finalizeOps(snap, baseOps);
1974
+ if (!fin.check.ok) return fail(`无法保存:${fin.check.issues.map((i) => i.message).join(";")}`);
1975
+ const ops = fin.ops;
1976
+ setModel((m) => ({ ...m, busy: true, savedNotice: null, sectionError: null, escalationError: null }));
1977
+ const persist = async () => {
1978
+ if (ops.length === 0) return true;
1979
+ const response = await rpc("mutate", { ns: SEARCH_NS, ops, expectedRevision: snap.revision });
1980
+ const result = unwrap(response);
1981
+ if (!alive.current) return false;
1982
+ if (!result.ok) return fail(safeMsg(`保存失败:${result.message || "宿主拒绝该请求"}`));
1983
+ try { latestRef.current = { ...snap, user: applyOpsToLayer(snap.user, ops) }; } catch { /* 失败由读回纠正 */ }
1984
+ return true;
1985
+ };
1986
+ if (text !== "") {
1987
+ // 新地址:凭据服务先写(只写不读,只写新 ref),随后 mutate 原子切 ref(次序断言:credentials/set 先于 settings/mutate)。
1988
+ const credResponse = await credentialRpc("set", { ref: nextRef, value: text });
1989
+ const credResult = unwrap(credResponse);
1990
+ if (!alive.current) return false;
1991
+ if (!credResult.ok) return fail(safeMsg(`无法保存:${credResult.message || "凭据服务拒绝写入"}`));
1992
+ const ok = await persist();
1993
+ if (!ok) return false;
1994
+ globalProxyRedacted.current[nextRef] = maskedTarget;
1995
+ setModel((m) => ({ ...m, busy: false, savedNotice: { text: "已保存设置。" }, globalProxyText: "", draft: { ...m.draft, globalProxyRef: nextRef } }));
1996
+ selfCommitPending = true;
1997
+ await load(true); // 单写者:读回必须在队列内下一提交构建 ops 前落定
1998
+ return true;
1999
+ }
2000
+ const ok = await persist();
2001
+ if (!ok) return false;
2002
+ if (ops.length > 0) {
2003
+ setModel((m) => ({ ...m, busy: false, savedNotice: { text: "已保存设置。" } }));
2004
+ selfCommitPending = true;
2005
+ await load(true);
2006
+ } else {
2007
+ setModel((m) => ({ ...m, busy: false, savedNotice: null }));
2008
+ }
2009
+ return true;
2010
+ } catch (err) {
2011
+ if (!alive.current) return false;
2012
+ const message = safeMsg(String((err && err.message) || err || "配置未通过校验"));
2013
+ return fail(`保存失败:${message}`);
2014
+ }
2015
+ });
2016
+ };
2017
+ // OSB-004(Refs #152):全局区块双态开关——拨动即单键落盘(globalProxy 凭据族零触碰;
2018
+ // finalizeOps 终态校验与乐观位回滚复用 escalation 同款骨架:drainReads→snap→mutate→读回)。
2019
+ const commitPacUnsandboxed = (next) => {
2020
+ const m0 = model;
2021
+ if (lockRef.current || m0.phase !== "ready" || typeof m0.revision !== "number") return Promise.resolve(false);
2022
+ const value = next === true;
2023
+ return enqueueCommit(async () => {
2024
+ const fail = (message) => {
2025
+ setModel((m) => ({ ...m, busy: false, pacUnlocked: !value, escalationError: { text: message }, savedNotice: null, sectionError: null }));
2026
+ return false;
2027
+ };
2028
+ try {
2029
+ if (!alive.current) return false;
2030
+ await drainReads();
2031
+ if (!alive.current) return false;
2032
+ const snap = latestRef.current;
2033
+ if (!snap || typeof snap.revision !== "number") return fail("宿主投影缺少 revision,禁止保存(请重新打开设置)");
2034
+ const baseOps = [{ op: "set", path: ["allowUnsandboxedPac"], value }];
2035
+ const fin = finalizeOps(snap, baseOps);
2036
+ if (!fin.check.ok) return fail(`无法保存:${fin.check.issues.map((i) => i.message).join(";")}`);
2037
+ const ops = fin.ops;
2038
+ setModel((m) => ({ ...m, busy: true, pacUnlocked: value, savedNotice: null, sectionError: null, escalationError: null }));
2039
+ if (ops.length === 0) {
2040
+ setModel((m) => ({ ...m, busy: false, savedNotice: null }));
2041
+ return true;
2042
+ }
2043
+ const response = await rpc("mutate", { ns: SEARCH_NS, ops, expectedRevision: snap.revision });
2044
+ const result = unwrap(response);
2045
+ if (!alive.current) return false;
2046
+ if (!result.ok) return fail(`保存失败:${result.message || "宿主拒绝该请求"}`);
2047
+ try { latestRef.current = { ...snap, user: applyOpsToLayer(snap.user, ops) }; } catch { /* 失败由读回纠正 */ }
2048
+ setModel((m) => ({ ...m, busy: false, savedNotice: { text: "已保存设置。" } }));
2049
+ selfCommitPending = true;
2050
+ await load(true);
2051
+ return true;
2052
+ } catch (err) {
2053
+ if (!alive.current) return false;
2054
+ return fail(`保存失败:${String((err && err.message) || err || "配置未通过校验")}`);
2055
+ }
2056
+ });
2057
+ };
2058
+ // PX-012(Refs #88):编辑器钉死三态变更(草稿字段;提交经条目级保存落盘)。
2059
+ const updateEditorPin = (id, value) => {
2060
+ if (lockRef.current) return;
2061
+ const entry = model.draft.entries.find((e) => e.id === id);
2062
+ setModel((m) => ({ ...m, editorError: null, draft: { ...m.draft, entries: m.draft.entries.map((e) => (e.id === id ? { ...e, proxyPin: value } : e)) } }));
2063
+ // #88 第三批②(Refs #88):钉死变更同步进 SET-008 缓存(成功提交/显式取消时随条目记录清除)。
2064
+ if (entry) syncEntryCache(model, id, { ...entry, proxyPin: value }, (model.keys && model.keys[id]) ?? "");
2065
+ };
2066
+ const hasOwnProxyValue = (p) => (typeof p === "string" ? p.trim() !== "" : Boolean(p && typeof p === "object"));
2067
+ // #142:isPacProxyForm 退役——PAC 与其他路由形态同域,编辑器/写闸零形态特判(原 #120 验收4
2068
+ // 「PAC 自治零 proxyPin」判据随用户复验裁决废止)。
2069
+
1279
2070
  // 卡片启用开关:onChange 即离散提交(仅自身 enabled 键;未提交的新条目无持久化变更)。
1280
2071
  // 五轮修复(codex 复审 P2·继承条目的离散动作不落盘):以有效持久列表起算——继承条目(base 层、
1281
2072
  // user 层无同 id 行)的开关同样落盘:把有效列表(含变更行)整单具化进 user 层(数组整段遮蔽语义
@@ -1289,7 +2080,7 @@ globalThis.window?.__ModuleLoader__?.load({
1289
2080
  const idx = list.findIndex((e) => isPlainObject(e) && sameEntryId(e.id, entryId)); // #55:entryId 为草稿(trim)形态,持久行可能带首尾空白
1290
2081
  if (idx < 0) return []; // 未提交新条目无持久化变更
1291
2082
  if ((list[idx].enabled !== false) === target) return []; // 意图未变化:无需写(对照有效值)
1292
- const cleanList = list.map((e) => stripSecrets(isPlainObject(e) && sameEntryId(e.id, entryId) ? { ...e, enabled: target } : e));
2083
+ const cleanList = list.map((e) => persistCleanRow(isPlainObject(e) && sameEntryId(e.id, entryId) ? { ...e, enabled: target } : e));
1293
2084
  return toOps({ entries: cleanList }, { entries: userEntriesOf(m) });
1294
2085
  }, null); // v3 用户反馈(V3-3):开关免提示——开关状态呈现即反馈(落盘语义不变)
1295
2086
  };
@@ -1308,6 +2099,7 @@ globalThis.window?.__ModuleLoader__?.load({
1308
2099
  ...m,
1309
2100
  confirmId: null,
1310
2101
  editingId: m.editingId === entryId ? null : m.editingId,
2102
+ editorHelpOpen: m.editingId === entryId ? false : m.editorHelpOpen, // #139:被移除条目即在编→编辑器关闭,展开态同清;他条目移除不动在编态
1311
2103
  savedNotice: null,
1312
2104
  sectionError: null,
1313
2105
  draft: { ...m.draft, entries: m.draft.entries.filter((e) => e.id !== entryId) },
@@ -1315,12 +2107,14 @@ globalThis.window?.__ModuleLoader__?.load({
1315
2107
  commitDiscrete((m) => {
1316
2108
  const user = userEntriesOf(m);
1317
2109
  const uIdx = user.findIndex((e) => isPlainObject(e) && sameEntryId(e.id, entryId)); // #55:持久行 id 可能带首尾空白
1318
- if (uIdx >= 0) return [...secretCleanupOps(m.user, uIdx), { op: "unset", path: ["entries", String(uIdx)] }];
2110
+ // #88 第三批④(Refs #88):清理闭集不再在 builder 内按删除前下标生成(数组位移后清错行/宿主拒删风险)——
2111
+ // 只产出结构 unset;余条目的清理由 finalizeOps 对删除后的最终候选层统一生成。
2112
+ if (uIdx >= 0) return [{ op: "unset", path: ["entries", String(uIdx)] }];
1319
2113
  const list = effectiveEntriesOf(m);
1320
2114
  const idx = list.findIndex((e) => isPlainObject(e) && sameEntryId(e.id, entryId)); // #55
1321
2115
  if (idx < 0) return [];
1322
2116
  const hasUserEntries = isPlainObject(m && m.user) && Array.isArray(m.user.entries);
1323
- const remaining = list.filter((e) => !(isPlainObject(e) && sameEntryId(e.id, entryId))).map(stripSecrets);
2117
+ const remaining = list.filter((e) => !(isPlainObject(e) && sameEntryId(e.id, entryId))).map(persistCleanRow);
1324
2118
  return toOps({ entries: remaining }, hasUserEntries ? { entries: user } : {});
1325
2119
  }, "已保存设置。", (snap) => {
1326
2120
  const restored = draftFrom({ entries: effectiveEntriesOf(snap) }).entries;
@@ -1346,8 +2140,8 @@ globalThis.window?.__ModuleLoader__?.load({
1346
2140
  commitDiscrete((m) => {
1347
2141
  const user = userEntriesOf(m);
1348
2142
  const list = effectiveEntriesOf(m);
1349
- const cleanList = list.map(stripSecrets);
1350
- // 先跑读闸等价校验(捕捉重复 id / null 字段 / 非对象项),防止在非法配置上静默吞错返回 []。
2143
+ const cleanList = list.map(persistCleanRow);
2144
+ // 先跑读闸等价校验(捕捉重复 id / null 字段 / 非对象项、#86 损坏池形态),防止在非法配置上静默吞错返回 []。
1351
2145
  normalizeConfig({ entries: cleanList });
1352
2146
  const present = new Set(cleanList.map((e) => normEntryId(e.id))); // #55:持久行 id 可能带首尾空白,草稿 id 为 trim 形态
1353
2147
  const targetIds = ids.filter((id) => present.has(normEntryId(id)));
@@ -1382,7 +2176,7 @@ globalThis.window?.__ModuleLoader__?.load({
1382
2176
  const pending = model.draft.entries.find((e) => !entryIsPersisted(model, e));
1383
2177
  if (pending) {
1384
2178
  restoreFocus.current = trigger ?? null;
1385
- setModel((m) => ({ ...m, editingId: pending.id, editorError: null }));
2179
+ setModel((m) => ({ ...m, editingId: pending.id, editorError: null, editorHelpOpen: false }));
1386
2180
  return;
1387
2181
  }
1388
2182
  const [type, label] = CATALOG_UI[0];
@@ -1393,6 +2187,7 @@ globalThis.window?.__ModuleLoader__?.load({
1393
2187
  ...m,
1394
2188
  editingId: id,
1395
2189
  editorError: null,
2190
+ editorHelpOpen: false, // #139:新建=在编条目变化,展开态重置初态
1396
2191
  draft: { ...m.draft, entries: [...m.draft.entries, { id, type, name: label, enabled: true, credentialRef: "" }] },
1397
2192
  }));
1398
2193
  // SET-008:新建草稿入缓存(稳定临时 id 为键;未提交即卸载,重挂须能复原)。
@@ -1414,17 +2209,18 @@ globalThis.window?.__ModuleLoader__?.load({
1414
2209
  const oldRow = CATALOG_UI.find((x) => x[0] === entry.type);
1415
2210
  const oldLabel = oldRow ? oldRow[1] : entry.type;
1416
2211
  const name = entry.name === oldLabel ? newLabel : entry.name;
1417
- const keyVal = typeof model.keys[id] === "string" ? model.keys[id] : "";
2212
+ // #86 POOL-009:厂商切换时槽位缓冲同保(缓存记录 key 面取首非空槽位值,legacy 兼容)。
2213
+ const curSlots = Array.isArray(model.poolKeys[id]) && model.poolKeys[id].length > 0 ? model.poolKeys[id] : [];
2214
+ const keyVal = curSlots.map((s) => (s && typeof s.value === "string" ? s.value : "")).find((v) => v.trim() !== "") ?? (typeof model.keys[id] === "string" ? model.keys[id] : "");
1418
2215
  setModel((m) => ({
1419
2216
  ...m,
1420
2217
  editorError: null,
1421
2218
  draft: { ...m.draft, entries: m.draft.entries.map((e) => (e.id === id ? { ...e, type, name } : e)) },
1422
2219
  }));
1423
- const rec = draftCache.get(id) || { mode: "create", type, fields: {}, key: "", baseRevision: typeof latestRef.current.revision === "number" ? latestRef.current.revision : undefined };
1424
- rec.type = type;
1425
- rec.fields = { name, credentialRef: entry.credentialRef ?? "" };
1426
- rec.key = keyVal;
1427
- draftCache.set(id, rec);
2220
+ // #88 二次整改 P1-② + #86 POOL-009(§7 合同④,Refs #88 #86):字段集重建走 syncEntryCache 同一口径
2221
+ // (name+credentialRef+credentialRefs+proxyPin,整替 rec.fields 不得丢 pin);厂商切换不清槽位缓冲
2222
+ // (与 keys 同生命周期)——槽位数组入参,两能力字段互不吞。
2223
+ syncEntryCache(model, id, { ...entry, type, name }, keyVal, model.poolKeys[id]);
1428
2224
  };
1429
2225
 
1430
2226
  // 二轮修复:同时查权威快照——创建提交成功但读回未落定时闭包 user 缺该条目,误判 create 会使重挂校验误报版本冲突。
@@ -1442,23 +2238,43 @@ globalThis.window?.__ModuleLoader__?.load({
1442
2238
  // V5-7(Issue #58):proxyIntent(见 proxyIntentOf)——null=未触碰(proxy 原样保留);
1443
2239
  // {proxy}=覆盖写入;{removeProxy}=删除该字段。与 editorCredInputs 凭据逻辑正交(keyless 条目同样适用)。
1444
2240
  // CFG-W-003:对返回条目统一剥离 SECRET_FIELD,由 toOps 对未移动条目自动产出字段级 unset 清理残留明文。
1445
- const candidateEntriesFor = (m, entry, credRef, proxyIntent) => {
2241
+ // #86 POOL-002③/POOL-009:credForm(见 credFormOf)= null | {kind:"single",ref} | {kind:"pool",refs}。
2242
+ // 形态互斥落盘:single → 只写 credentialRef(目标行 credentialRefs 键删除,同一提交 toOps 产出 unset);
2243
+ // pool → 只写 credentialRefs(credentialRef 键删除 = 惰性迁移旧键移除,POOL-002③);null → 两键皆删。
2244
+ const candidateEntriesFor = (m, entry, credForm, proxyIntent) => {
1446
2245
  const list = effectiveEntriesOf(m);
1447
2246
  const matched = list.find((e) => isPlainObject(e) && sameEntryId(e.id, entry.id)); // #55:持久行 id 可能带首尾空白
1448
2247
  // #55:命中持久行时 patch.id 取原持久行 raw id——trim 后草稿 id 不得改写原持久 id(写回最小字段级 diff)。
1449
2248
  const patch = { id: matched ? matched.id : entry.id, type: entry.type, name: entry.name, enabled: entry.enabled };
1450
- if (credRef) patch.credentialRef = credRef;
2249
+ if (credForm && credForm.kind === "single" && typeof credForm.ref === "string" && credForm.ref !== "") patch.credentialRef = credForm.ref;
2250
+ if (credForm && credForm.kind === "pool" && Array.isArray(credForm.refs) && credForm.refs.length > 0) patch.credentialRefs = credForm.refs.slice();
1451
2251
  if (proxyIntent && proxyIntent.proxy !== undefined) patch.proxy = proxyIntent.proxy;
2252
+ // #120 PX-006/PX-012 双态落盘(三态显式 inherit 键废止)+ #142 修订注②:开=inherit=默认值不落盘
2253
+ // ——存量显式值拨回开时显式退钉(键 unset);关=directOnly 落盘(自有代理两种形态——固定 proxy 与
2254
+ // PAC——同域合法);proxyOnly 存量读兼容原样保留(新写停用)。#142 推翻「PAC 保存恒零 proxyPin
2255
+ // 产出」:PAC 条目与其余形态同写域(directOnly 合法写、拨回开显式 unset)。
2256
+ const patchRetryDraft = entry.proxyPin ?? PROXY_PINS.INHERIT;
2257
+ if (patchRetryDraft !== PROXY_PINS.INHERIT) patch.proxyPin = entry.proxyPin;
2258
+ const patchUnpin = patchRetryDraft === PROXY_PINS.INHERIT;
2259
+ const dropCredentialKeys = (out) => {
2260
+ const keepRef = !!(credForm && credForm.kind === "single" && out.credentialRef);
2261
+ const keepPool = !!(credForm && credForm.kind === "pool" && out.credentialRefs);
2262
+ if (!keepRef) delete out.credentialRef;
2263
+ if (!keepPool) delete out.credentialRefs;
2264
+ };
1452
2265
  if (matched) {
1453
2266
  return list.map((e) => {
1454
2267
  if (!isPlainObject(e) || !sameEntryId(e.id, entry.id)) return stripSecrets(e);
1455
2268
  const out = stripSecrets({ ...e, ...patch });
1456
- if (!credRef) delete out.credentialRef;
2269
+ dropCredentialKeys(out);
1457
2270
  if (proxyIntent && proxyIntent.removeProxy) delete out.proxy; // 触碰并清空 = 删除字段(未触碰不动)
2271
+ if (patchUnpin) delete out.proxyPin; // 拨回开=退钉:显式移除存量键(默认值不落盘)
1458
2272
  return out;
1459
2273
  });
1460
2274
  }
1461
- return [...list.map((e) => stripSecrets(e)), stripSecrets({ ...patch })];
2275
+ const created = stripSecrets({ ...patch });
2276
+ dropCredentialKeys(created);
2277
+ return [...list.map((e) => stripSecrets(e)), created];
1462
2278
  };
1463
2279
 
1464
2280
  // 条目级提交(新建=创建 / 编辑=更新):先凭据后配置;成功=该条目整体生效并关闭编辑器;
@@ -1470,21 +2286,18 @@ globalThis.window?.__ModuleLoader__?.load({
1470
2286
  // 存在漂移(stale 快照竞态)则拒发(B-007/009:旧代码以陈旧 user 列表为底,toOps 把他条目当「我的差异」LWW 覆盖)。
1471
2287
  // 免 key 厂商(如 bing)隐藏凭据字段但仍保留 V5-2 缓存值以便切回 keyed 厂商时回填;
1472
2288
  // 校验与提交路径须按当前厂商决定是否采信缓存的 credentialRef 与明文 key。
1473
- const editorCredInputs = (entry, rawKey) => {
1474
- const isKeyed = KEYED_TYPES.includes(entry.type);
1475
- const keyVal = (typeof rawKey === "string" ? rawKey : "").trim();
1476
- const writesKey = isKeyed && keyVal !== "";
1477
- const credRef = isKeyed ? (entry.credentialRef ?? "").trim() : "";
1478
- return { keyVal, writesKey, credRef };
1479
- };
1480
-
1481
2289
  const submitEditor = () => {
1482
2290
  const entry = model.draft.entries.find((e) => e.id === model.editingId);
1483
2291
  if (!entry || lockRef.current) return;
1484
2292
  if (model.phase !== "ready" || typeof model.revision !== "number") return;
1485
2293
  const boundId = entry.id; // 编辑器绑定:本次提交只允许触及该 id 一行
1486
- const { keyVal, writesKey, credRef: initialCredRef } = editorCredInputs(entry, model.keys[boundId]);
1487
- let credRef = initialCredRef;
2294
+ // #86 POOL-009:槽位值(只写缓冲)与触碰标记——渲染门(editorBlock)与本提交共用同一判据面。
2295
+ const slotVals = Array.isArray(model.poolKeys[boundId]) && model.poolKeys[boundId].length > 0
2296
+ ? model.poolKeys[boundId]
2297
+ : (typeof model.keys[boundId] === "string" && model.keys[boundId] !== "" ? [model.keys[boundId]] : []);
2298
+ // sol P1:触碰判定只认显式标志 credTouched(输入/增槽/删槽/SET-008 复原置位),
2299
+ // 不从明文是否非空反推——删槽后全空仍须按「已触碰」重放删除意图。
2300
+ const keyTouched = Boolean(model.credTouched?.[boundId]);
1488
2301
  // V5-7(Issue #58):代理三态意图(未触碰=原样保留/清空=删除/非空=写入);非法形态由下方
1489
2302
  // validate(normalizeProxy 权威)拦截,错误文案经 catch 落到既有保存错误面。
1490
2303
  const proxyIntent = proxyIntentOf(boundId);
@@ -1497,8 +2310,10 @@ globalThis.window?.__ModuleLoader__?.load({
1497
2310
  return;
1498
2311
  }
1499
2312
  // 代码级阻断(与实时 editorBlock 同判据;真实 DOM 中禁用钮不可点,此守卫兜底测试侧直接触发):
1500
- // 超语法 ref 且本次不带新 key → 零出站(R-1 / P2-3 留空变体)。
1501
- if (!writesKey && credRef && !POSIX_REF.test(credRef)) {
2313
+ // 超语法 ref 且 key 区未触碰(ref 输入生效)→ 零出站(R-1 / P2-3 留空变体)。
2314
+ // 免 key 类型(bing)ref 输入不进渲染面 → 缓存 ref 不阻塞(v5 切厂商面,与 v0.2.0 同语义)。
2315
+ const refInput = KEYED_TYPES.includes(entry.type) ? (entry.credentialRef ?? "").trim() : "";
2316
+ if (!keyTouched && refInput && !POSIX_REF.test(refInput)) {
1502
2317
  setModel((m) => ({ ...m, editorError: { text: "凭据引用格式无效:仅允许以字母或下划线开头,后续使用字母、数字或下划线。", issues: [] } }));
1503
2318
  return;
1504
2319
  }
@@ -1510,25 +2325,46 @@ globalThis.window?.__ModuleLoader__?.load({
1510
2325
  if (!alive.current) return;
1511
2326
  const snap = latestRef.current;
1512
2327
  if (!snap || typeof snap.revision !== "number") throw new Error("宿主投影缺少 revision,禁止保存(请重新打开设置)");
2328
+ // #86 POOL-009/lead P0⑤:终态裁决与写闸预检先于任何 credentials/set——
2329
+ // 每个新 key 生成全新受控唯一 ref(绝不复用/覆盖在效引用,P0④);同值槽位共享同一新 ref
2330
+ // (POOL-009⑤ 去重 → 重复 ref 由下方 validate 终态预检拒,零凭据写入、零 mutate)。
2331
+ const persistedEntry = effectiveEntriesOf(snap).find((e) => isPlainObject(e) && sameEntryId(e.id, boundId)) ?? null;
2332
+ const newRefs = new Map(); // 新值 → 受控唯一 ref
2333
+ const credForm = credFormOf(entry, persistedEntry, slotVals, keyTouched, (v) => {
2334
+ let r = newRefs.get(v);
2335
+ if (!r) { r = credentialRefFor(boundId); newRefs.set(v, r); }
2336
+ return r;
2337
+ });
1513
2338
  // CFG-W-004:先于 credentials/set 执行写闸预检与绑定守卫,避免配置校验失败时留下孤儿凭据写入。
1514
- const preCandidate = candidateEntriesFor(snap, entry, writesKey ? "SEARCH_CHAIN_CREDENTIAL_REF" : credRef, proxyIntent);
2339
+ // #86 分叉规则:池字段族违规 validate 直接抛错(本 try 的 catch 面呈现,零凭据写入);
2340
+ // legacy 违规返回 { ok:false } 走既有文案分支。
2341
+ const preCandidate = candidateEntriesFor(snap, entry, credForm, proxyIntent);
1515
2342
  const baseObj = isPlainObject(snap.base) ? snap.base : {};
1516
2343
  const userObj = isPlainObject(snap.user) ? snap.user : {};
1517
- const preCheck = validate({ ...baseObj, ...{ ...userObj, entries: preCandidate } });
1518
- if (!preCheck.ok) throw new Error(`校验未通过:${preCheck.issues.map((i) => i.message).join(";")}`);
2344
+ // CFG-W-004 + #86 分叉规则(§7 合同③包装点③,Refs #88 #86):先于 credentials/set 执行写闸预检与绑定守卫。
2345
+ // 抛错形态(新契约字段族)由外层 catch 转编辑器错误呈现(零凭据写入);legacy 违规返回形 → 显式 throw 同面。
2346
+ // PX-001(Refs #88):user 层既有全局代理明文不令预检误抛(清零由清理 ops 承载,与 CFG-W-003 同规则)。
2347
+ const preCheck = validate(scrubGlobalProxyPlaintext({ ...baseObj, ...{ ...userObj, entries: preCandidate } }));
2348
+ if (preCheck && preCheck.ok === false) throw new Error(`校验未通过:${preCheck.issues.map((i) => i.message).join(";")}`);
1519
2349
  if (!singleEntryDiff({ entries: effectiveEntriesOf(snap) }, preCandidate, boundId)) {
1520
2350
  throw new Error("提交目标与编辑器绑定条目不一致(持久快照漂移),本次写入已拒绝;请重新保存");
1521
2351
  }
1522
- if (writesKey) {
1523
- // 新引用总是 POSIX 合法(受控生成);先写凭据,成功后才允许携带新 ref 落盘。
1524
- const newRef = credentialRefFor(boundId);
1525
- credRef = newRef;
1526
- const credResponse = await credentialRpc("set", { ref: newRef, value: keyVal });
2352
+ // #88 首批 P0 + 二次整改 P1-④(§7 合同④,Refs #88 #86):统一 ops builder——终层清理闭集
2353
+ // (统一闭集两族)+ 实际终态预检(finalizeOps 内部 validate try/catch)。终态裁决先于任何
2354
+ // credentials/set:新形态 ref 已在 preCandidate(credFormOf 生成),ops 应用后终态即凭据写后终态——
2355
+ // 失败路径零凭据写(不留孤儿 key)、零 mutate。
2356
+ const candidate = preCandidate;
2357
+ const baseOps = toOps({ entries: candidate }, { entries: userEntriesOf(snap) });
2358
+ const preFin = baseOps.length > 0 ? finalizeOps(snap, baseOps) : null;
2359
+ if (preFin && !preFin.check.ok) throw new Error(`校验未通过:${preFin.check.issues.map((i) => i.message).join(";")}`);
2360
+ // #86 POOL-009:终态校验通过后才写凭据;全部新 ref set 成功才允许 mutate(任一拒绝 → 抛错,
2361
+ // 旧池值/旧路由在磁盘上零变化——失败面断言锚点;新 ref 未入效 = 无孤儿在用引用)。
2362
+ for (const [value, ref] of newRefs) {
2363
+ const credResponse = await credentialRpc("set", { ref, value });
1527
2364
  const credResult = unwrap(credResponse);
1528
2365
  if (!credResult.ok) throw new Error(credResult.message || "凭据服务拒绝写入");
1529
2366
  }
1530
- const candidate = writesKey ? candidateEntriesFor(snap, entry, credRef, proxyIntent) : preCandidate;
1531
- const ops = toOps({ entries: candidate }, { entries: userEntriesOf(snap) });
2367
+ const ops = preFin ? preFin.ops : [];
1532
2368
  if (ops.length > 0) {
1533
2369
  const response = await rpc("mutate", { ns: SEARCH_NS, ops, expectedRevision: snap.revision });
1534
2370
  const result = unwrap(response);
@@ -1541,15 +2377,21 @@ globalThis.window?.__ModuleLoader__?.load({
1541
2377
  setModel((m) => {
1542
2378
  const keys = { ...m.keys };
1543
2379
  delete keys[boundId];
2380
+ const poolKeys = { ...m.poolKeys };
2381
+ delete poolKeys[boundId]; // #86:成功提交清槽位明文缓冲(重开只写不回显)
2382
+ const credTouched = { ...m.credTouched };
2383
+ delete credTouched[boundId];
1544
2384
  const proxyTexts = { ...m.proxyTexts };
1545
2385
  delete proxyTexts[boundId]; // V5-7:成功提交清代理明文缓冲(重开回到「未触碰 + 已配置态」)
1546
- return { ...m, editorBusy: false, editingId: null, keys, proxyTexts, editorError: null, savedNotice: { text: `已保存 ${name}。` } };
2386
+ return { ...m, editorBusy: false, editingId: null, editorHelpOpen: false, keys, poolKeys, credTouched, proxyTexts, editorError: null, savedNotice: { text: `已保存 ${name}。` } };
1547
2387
  });
1548
2388
  await load(true); // 单写者:读回必须在队列内下一提交构建 ops 前落定
1549
2389
  } catch (err) {
1550
2390
  if (!alive.current) return;
2391
+ // #86:错误文案脱敏面含全部槽位明文(不只单 key 缓冲);失败不触碰任何已持久路由/池值。
1551
2392
  let message = String((err && err.message) || err || "保存失败");
1552
- for (const secret of Object.values(model.keys)) {
2393
+ const secrets = [...Object.values(model.keys), ...Object.values(model.poolKeys || {}).flat().map((s) => (s && typeof s.value === "string" ? s.value : ""))];
2394
+ for (const secret of secrets) {
1553
2395
  if (typeof secret === "string" && secret.trim()) message = message.replaceAll(secret.trim(), "[redacted]");
1554
2396
  }
1555
2397
  setModel((m) => ({ ...m, editorBusy: false, editorError: { text: `保存失败:${message}`, issues: [] } }));
@@ -1566,10 +2408,14 @@ globalThis.window?.__ModuleLoader__?.load({
1566
2408
  const trigger = restoreFocus.current;
1567
2409
  setModel((m) => {
1568
2410
  const keys = { ...m.keys };
2411
+ const poolKeys = { ...m.poolKeys };
2412
+ const credTouched = { ...m.credTouched };
1569
2413
  const proxyTexts = { ...m.proxyTexts };
1570
2414
  let entries = m.draft.entries;
1571
2415
  if (entry) {
1572
2416
  delete keys[entry.id];
2417
+ delete poolKeys[entry.id]; // #86:取消 ≡ 丢弃——槽位明文缓冲同清
2418
+ delete credTouched[entry.id];
1573
2419
  delete proxyTexts[entry.id]; // V5-7:取消 ≡ 丢弃——代理明文缓冲同清(与 key 缓冲同语义)
1574
2420
  if (entryIsPersisted(m, entry)) {
1575
2421
  // 五轮修复(codex 复审 P1/P2 配套):持久值取有效行——继承条目的取消恢复到 base 值;
@@ -1580,13 +2426,16 @@ globalThis.window?.__ModuleLoader__?.load({
1580
2426
  ...e,
1581
2427
  name: persisted ? (persisted.name ?? "") : e.name,
1582
2428
  credentialRef: persisted && typeof persisted.credentialRef === "string" ? persisted.credentialRef : "",
2429
+ // #88 二次整改 P1-①(Refs #88):钉死态随取消恢复 persisted(持久行无该字段 = 默认 inherit)——
2430
+ // 否则取消后的草稿 pin 会被稍后任何保存路径原样落盘(取消意图静默写穿)。
2431
+ proxyPin: persisted ? (persisted.proxyPin ?? PROXY_PINS.INHERIT) : e.proxyPin,
1583
2432
  }
1584
2433
  : e));
1585
2434
  } else {
1586
2435
  entries = entries.filter((e) => e.id !== entry.id); // 新条目:移出草稿即清草稿
1587
2436
  }
1588
2437
  }
1589
- return { ...m, editingId: null, keys, proxyTexts, editorError: null, draft: { ...m.draft, entries } };
2438
+ return { ...m, editingId: null, editorHelpOpen: false, keys, poolKeys, credTouched, proxyTexts, editorError: null, draft: { ...m.draft, entries } };
1590
2439
  });
1591
2440
  restoreFocus.current = null;
1592
2441
  if (trigger && typeof trigger.focus === "function") Promise.resolve().then(() => trigger.focus());
@@ -1599,11 +2448,12 @@ globalThis.window?.__ModuleLoader__?.load({
1599
2448
  const openEditorFor = (entryId, trigger) => {
1600
2449
  if (lockRef.current) return;
1601
2450
  restoreFocus.current = trigger ?? null;
2451
+ // #139(Refs #139):问号内联说明为编辑器局部草稿态——开/收/切条目一律重置收起(零写入语义零动)。
1602
2452
  if (model.editingId === entryId) {
1603
- setModel((m) => ({ ...m, editingId: null, editorError: null }));
2453
+ setModel((m) => ({ ...m, editingId: null, editorError: null, editorHelpOpen: false }));
1604
2454
  return;
1605
2455
  }
1606
- setModel((m) => ({ ...m, editingId: entryId, editorError: null }));
2456
+ setModel((m) => ({ ...m, editingId: entryId, editorError: null, editorHelpOpen: false }));
1607
2457
  };
1608
2458
  const onDialogKeyDown = (ev) => {
1609
2459
  if (ev.key === "Escape") {
@@ -1639,12 +2489,15 @@ globalThis.window?.__ModuleLoader__?.load({
1639
2489
  }
1640
2490
  };
1641
2491
 
2492
+ // #86 POOL-009:池条目(credentialRefs 非空)与单引用等效「已就绪」;卡片另以可见
2493
+ // 「N 把」标注池规模(仅池条目渲染该节点,legacy 卡片结构零变化)。
2494
+ const credPoolSize = (e) => (Array.isArray(e.credentialRefs) ? e.credentialRefs.filter((r) => typeof r === "string" && r !== "").length : 0);
1642
2495
  const entryStatusText = (e) => {
1643
2496
  if (!e.enabled) return "已关闭";
1644
- if (KEYED_TYPES.includes(e.type) && !e.credentialRef) return "缺少凭据引用";
2497
+ if (KEYED_TYPES.includes(e.type) && !e.credentialRef && credPoolSize(e) === 0) return "缺少凭据引用";
1645
2498
  return "已就绪";
1646
2499
  };
1647
- const entryStatusState = (e) => (!e.enabled ? "disabled" : KEYED_TYPES.includes(e.type) && !e.credentialRef ? "missing" : "ready");
2500
+ const entryStatusState = (e) => (!e.enabled ? "disabled" : KEYED_TYPES.includes(e.type) && !e.credentialRef && credPoolSize(e) === 0 ? "missing" : "ready");
1648
2501
  const dragList = (node) => node?.closest?.(".sc-card-list") ?? null;
1649
2502
  const clearDragMarks = (node) => {
1650
2503
  const list = dragList(node);
@@ -1727,15 +2580,30 @@ globalThis.window?.__ModuleLoader__?.load({
1727
2580
  // 上方 role=alert 报错(SPC-023「新建=完整校验」/SPC-030),不必等提交才暴露。
1728
2581
  const nameProblem = entryNameGate(editorEntry.name);
1729
2582
  if (nameProblem) return { text: nameProblem, issues: [] };
1730
- const { writesKey, credRef } = editorCredInputs(editorEntry, model.keys[editorEntry.id]);
1731
- if (!writesKey && credRef && !POSIX_REF.test(credRef)) {
2583
+ // #86 POOL-009:凭据门与提交共用 credFormOf 判据(渲染门新 ref 用占位符,零副作用);
2584
+ // 同值槽位占位符去重后呈重复 ref → validate 池违规禁提交(POOL-009⑤ 实时面)。
2585
+ const rSlotVals = poolSlotsOf(editorEntry);
2586
+ // sol P1:与提交同判据——触碰只认显式标志,不从明文非空反推(删槽后全空仍禁不得按未触碰放行)。
2587
+ const rKeyTouched = Boolean(model.credTouched?.[editorEntry.id]);
2588
+ // 免 key 类型(bing)ref 输入不进渲染面 → 缓存 ref 不阻塞(v5 切厂商面,与 v0.2.0 同语义)。
2589
+ const rRefInput = KEYED_TYPES.includes(editorEntry.type) ? (editorEntry.credentialRef ?? "").trim() : "";
2590
+ if (!rKeyTouched && rRefInput && !POSIX_REF.test(rRefInput)) {
1732
2591
  return { text: "凭据引用格式无效:仅允许以字母或下划线开头,后续使用字母、数字或下划线。", issues: [] };
1733
2592
  }
1734
2593
  // V5-7(Issue #58):触碰后的代理值同样进实时校验门(与名称门/凭据门同判据)——
1735
2594
  // normalizeProxy 文案经 issues 原样呈现,非法值期间提交钮禁用(提交时兜底同判据)。
1736
2595
  const proxyIntent = proxyIntentOf(editorEntry.id);
1737
- const check = validate({ ...model.base, ...{ ...model.user, entries: candidateEntriesFor(model, editorEntry, writesKey ? "SEARCH_CHAIN_CREDENTIAL_REF" : credRef, proxyIntent) } });
1738
- if (!check.ok) return { text: "无法提交:配置校验未通过", issues: check.issues.map((i) => i.message) };
2596
+ const rForm = credFormOf(editorEntry, effectiveEntriesOf(model).find((e) => isPlainObject(e) && sameEntryId(e.id, editorEntry.id)) ?? null, rSlotVals, rKeyTouched, (v, ord) => `SEARCH_CHAIN_CREDENTIAL_REF_${ord}`);
2597
+ // #86 分叉规则 + PX-012#4(§7 合同③包装点④,Refs #88 #86):新契约字段族违规 validate 抛错
2598
+ // 渲染期不得外逃——就地转 issues 呈现;legacy 违规本就是返回形态。
2599
+ // PX-001(Refs #88):user 层既有全局代理明文不令实时门误抛(与提交 preCheck 同判据;清零由清理 ops 承载)。
2600
+ let check;
2601
+ try {
2602
+ check = validate(scrubGlobalProxyPlaintext({ ...model.base, ...{ ...model.user, entries: candidateEntriesFor(model, editorEntry, rForm, proxyIntent) } }));
2603
+ } catch (e) {
2604
+ return { text: "无法提交:配置校验未通过", issues: [String((e && e.message) || "配置未通过校验")] };
2605
+ }
2606
+ if (check && check.ok === false) return { text: "无法提交:配置校验未通过", issues: check.issues.map((i) => i.message) };
1739
2607
  return null;
1740
2608
  })();
1741
2609
  const editorProblem = model.editorError || editorBlock;
@@ -1743,6 +2611,22 @@ globalThis.window?.__ModuleLoader__?.load({
1743
2611
  // v3 用户反馈(V3-1 文案统一):提交钮编辑/新建一律「取消|保存」,busy「保存中…」——
1744
2612
  // 废止「创建工具/创建中…」(任何编辑器动作标签中不得出现)。
1745
2613
  const submitLabel = model.editorBusy ? "保存中…" : "保存";
2614
+ // PX-012(Refs #88):自有代理在场判定(输入中意图优先于草稿/持久值)→ 钉死控件禁用;钉死当前值(缺省 inherit)。
2615
+ const editorPinOwnProxy = editorEntry ? (() => {
2616
+ const intent = proxyIntentOf(editorEntry.id);
2617
+ if (intent && intent.proxy !== undefined) return hasOwnProxyValue(intent.proxy);
2618
+ if (intent && intent.removeProxy) return false;
2619
+ return hasOwnProxyValue(editorEntry.proxy);
2620
+ })() : false;
2621
+ const editorPinValue = editorEntry && typeof editorEntry.proxyPin === "string" && PROXY_PIN_VALUES.includes(editorEntry.proxyPin)
2622
+ ? editorEntry.proxyPin
2623
+ : PROXY_PINS.INHERIT;
2624
+ // #120 PX-012 + #142 修订注②:双态开关呈现——开=inherit 或 legacy proxyOnly(读兼容呈开);
2625
+ // 关=directOnly。PAC 与其他路由形态同域可用(推翻一轮「PAC 禁用+自治注记」)。
2626
+ const editorRetryOn = editorPinValue !== PROXY_PINS.DIRECT_ONLY;
2627
+ // #139(Refs #139):问号内联说明展开态(编辑器局部草稿态,见 model 注释)——button 与
2628
+ // disclosure 同源读取;ESC 不做(用户裁定),button 原生 Enter/Space 即键盘可达。
2629
+ const editorHelpOpen = model.editorHelpOpen === true;
1746
2630
  const editor = editorEntry ? React.createElement("div", {
1747
2631
  role: "dialog", "aria-modal": "true", "aria-labelledby": "sc-editor-title",
1748
2632
  "data-role": "editor", onKeyDown: onDialogKeyDown, className: "sc-dialog sc-editor",
@@ -1766,16 +2650,52 @@ globalThis.window?.__ModuleLoader__?.load({
1766
2650
  value: editorEntry.credentialRef ?? "", placeholder: "例如 TAVILY_API_KEY",
1767
2651
  onChange: (ev) => updateEditorField(editorEntry.id, "credentialRef", ev.target.value),
1768
2652
  })) : null,
1769
- KEYED_TYPES.includes(editorEntry.type) ? React.createElement("label", { className: "sc-field" }, React.createElement("span", { className: "sc-field-label" }, "API key(仅写入,不会回显)"), React.createElement("input", {
1770
- className: "sc-input", type: "password", autoComplete: "new-password", "data-role": "field", "data-field": "key", "data-entry-id": editorEntry.id, disabled: locked,
1771
- value: model.keys[editorEntry.id] ?? "", placeholder: "输入新 key;留空则保留现有凭据",
1772
- onChange: (ev) => updateKey(editorEntry.id, ev.target.value),
1773
- })) : null,
2653
+ // #86 POOL-009/POOL-010:keyed 类型 = 槽位组(每槽一个 data-field="key" 只写输入 + 槽位移除钮)
2654
+ // + 「新增一把 key」(data-role="key-add",8 槽上限同判据禁用);免 key 类型(bing)零 key 节点。
2655
+ // 槽位值只写不回显(CFG-002 同政策):重开/渲染值恒来自只写缓冲,存量引用名不进任何槽位 value。
2656
+ KEYED_TYPES.includes(editorEntry.type) ? (() => {
2657
+ const slots = poolSlotsOf(editorEntry);
2658
+ return React.createElement("div", { className: "sc-key-slots" },
2659
+ slots.map((s, i) => {
2660
+ // sol P0/P2:逐槽状态——已存槽(带引用身份 keptRef)显示「已保存(只写)」状态标
2661
+ // 且 placeholder 提示留空保留;新槽(无身份)placeholder 提示留空丢弃。值恒只写不回显。
2662
+ const sv = isPlainObject(s) ? (typeof s.value === "string" ? s.value : "") : (typeof s === "string" ? s : "");
2663
+ const kept = !!(isPlainObject(s) && typeof s.keptRef === "string" && s.keptRef !== "");
2664
+ return React.createElement("label", { className: "sc-field", key: `key-slot-${i}` },
2665
+ React.createElement("span", { className: "sc-field-label" }, i === 0 ? "API key(仅写入,不会回显)" : `第 ${i + 1} 把 key(仅写入,不会回显)`),
2666
+ React.createElement("div", { className: "sc-key-slot-row" },
2667
+ React.createElement("input", {
2668
+ className: "sc-input", type: "password", autoComplete: "new-password",
2669
+ "data-role": "field", "data-field": "key", "data-slot": String(i), "data-entry-id": editorEntry.id, disabled: locked,
2670
+ value: sv,
2671
+ placeholder: kept ? "已有槽:留空保留" : "新槽:留空丢弃",
2672
+ onChange: (ev) => updatePoolKey(editorEntry.id, i, ev.target.value),
2673
+ }),
2674
+ kept ? React.createElement("span", {
2675
+ className: "sc-key-slot-status", "data-role": "key-slot-status", "data-state": "saved",
2676
+ "data-entry-id": editorEntry.id, "data-slot": String(i),
2677
+ }, "已保存(只写)") : null,
2678
+ slots.length > 1 ? React.createElement("button", {
2679
+ className: "sc-button sc-button-secondary", type: "button",
2680
+ "data-role": "key-remove", "data-entry-id": editorEntry.id, "data-slot": String(i),
2681
+ disabled: locked || model.busy || model.editorBusy,
2682
+ onClick: () => removePoolSlot(editorEntry.id, i),
2683
+ }, "移除") : null,
2684
+ ),
2685
+ );
2686
+ }),
2687
+ React.createElement("button", {
2688
+ className: "sc-button sc-button-secondary", type: "button",
2689
+ "data-role": "key-add", "data-entry-id": editorEntry.id,
2690
+ disabled: locked || model.busy || model.editorBusy || slots.length >= POOL_MAX,
2691
+ onClick: () => addPoolSlot(editorEntry.id),
2692
+ }, `新增一把 key(${slots.length}/${POOL_MAX})`),
2693
+ );
2694
+ })() : null,
1774
2695
  // V5-7(Issue #58):高级区——条目级网络代理三态输入(新建/编辑两条路径同一形态,折叠 details)。
1775
2696
  // 只写不回显(CFG-002 类 key 政策):value 恒为明文缓冲(未触碰=空串),已配置时 placeholder 提示
1776
2697
  // 已配置态;既有 proxy 值(含 user:pass 认证参数)绝不写入任何 DOM 文本/属性。
1777
- React.createElement("details", { className: "sc-advanced", "data-role": "proxy-advanced" },
1778
- React.createElement("summary", null, "网络代理(高级)"),
2698
+ React.createElement("div", { className: "sc-advanced", "data-role": "proxy-advanced" },
1779
2699
  React.createElement("div", { className: "sc-field" },
1780
2700
  React.createElement("label", { className: "sc-field-label", htmlFor: "sc-proxy-input" }, "代理"),
1781
2701
  React.createElement("div", { className: "sc-proxy-input-row" },
@@ -1804,6 +2724,51 @@ globalThis.window?.__ModuleLoader__?.load({
1804
2724
  : "留空=直连;填 http(s)://host:port;PAC 填 pac:http(s)://…") + remotePacWarn,
1805
2725
  ),
1806
2726
  ),
2727
+ // #120 PX-012 + #142 修订注①(用户复验裁决 Refs #142):条目级「自动全局代理」双态开关
2728
+ // (新建默认开=省略);自有代理(含 PAC)与直连条目同域可用。问号帮助三代表演进:title-only
2729
+ // (#120)→ 点击展开(#139)→ 悬停/聚焦展开(#142 用户裁定 hover 非 click)——
2730
+ // mouseenter/focus 展开、mouseleave/blur 收起;button 不再携 aria-expanded/aria-controls
2731
+ // (按需 disclosure 非受控折叠态);aria-label=RETRY_HELP_TEXT 全句。
2732
+ // #148(round-3,用户复验实见):原生 title 悬浮窗与自定义 tooltip 重叠——title 退役,全文唯一
2733
+ // 呈现承载=悬浮气泡+aria-label(无障碍名不变);读屏与键盘面零损失。
2734
+ // 判定/默认/写语义零变化。
2735
+ React.createElement("div", { className: "sc-pin-row" },
2736
+ React.createElement("label", { className: "sc-pin-retry-switch" },
2737
+ React.createElement("input", {
2738
+ className: "sc-switch-input", type: "checkbox", role: "switch", "aria-checked": editorRetryOn,
2739
+ "aria-label": `自动全局代理 ${editorEntry.name || editorEntry.type}`,
2740
+ "data-role": "retry-toggle", "data-entry-id": editorEntry.id,
2741
+ checked: editorRetryOn, disabled: locked || model.busy || model.editorBusy,
2742
+ onChange: (ev) => updateEditorPin(editorEntry.id, ev.target.checked ? PROXY_PINS.INHERIT : PROXY_PINS.DIRECT_ONLY),
2743
+ }),
2744
+ React.createElement("span", { className: "sc-switch-track", "aria-hidden": "true" }),
2745
+ ),
2746
+ React.createElement("span", { className: "sc-field-label" }, "自动全局代理"),
2747
+ React.createElement("span", { className: "sc-tip-anchor" },
2748
+ React.createElement("button", {
2749
+ className: "sc-retry-help", type: "button",
2750
+ "data-role": "retry-help", "data-entry-id": editorEntry.id,
2751
+ "aria-label": RETRY_HELP_TEXT, tabIndex: 0,
2752
+ "aria-describedby": model.editorHelpOpen ? "sc-retry-help-disclosure" : undefined,
2753
+ // #142:hover/focus 展开、mouseleave/blur 收起(键盘经 focus 同达);零 click 语义。
2754
+ // #145 修订注二①:载体=悬浮 tooltip(.sc-tip-bubble,absolute 零布局位移),触发面零动。
2755
+ onMouseEnter: () => setModel((m) => ({ ...m, editorHelpOpen: true })),
2756
+ onMouseLeave: () => setModel((m) => ({ ...m, editorHelpOpen: false })),
2757
+ onFocus: () => setModel((m) => ({ ...m, editorHelpOpen: true })),
2758
+ onBlur: () => setModel((m) => ({ ...m, editorHelpOpen: false })),
2759
+ }, "?"),
2760
+ model.editorHelpOpen ? React.createElement("span", {
2761
+ className: "sc-tip-bubble", role: "tooltip",
2762
+ "data-role": "retry-help-disclosure", id: "sc-retry-help-disclosure",
2763
+ }, RETRY_HELP_TEXT) : null,
2764
+ ),
2765
+ ),
2766
+ // #142(PX-012/SPC-011/SPC-017 修订注,用户复验裁决):编辑器「启用本条目」开关行退役——
2767
+ // 与卡片行启用开关重复,enabled 唯一写面=卡片行开关(离散提交路径唯一化,SPC-011/017 承载
2768
+ // 收敛卡片行域)。#110 由本行承担的「编辑器提交窗 disabled 开关档」(A-025:
2769
+ // .sc-switch-input:disabled + .sc-switch-track)职责迁移到上方「自动全局代理」开关——窗内
2770
+ // disabled=locked,同 CSS 族零新增规则。patch 恒透传 enabled:卡片行 enabledToggleChange
2771
+ // 仍为唯一写者,零新增写语义。
1807
2772
  editorProblem ? React.createElement("p", {
1808
2773
  className: "sc-status-node", "data-role": "save-error", "data-state": "error", role: "alert",
1809
2774
  }, editorProblem.text, ...(editorProblem.issues ?? []).map((issue, i) => React.createElement("span", { key: `issue-${i}`, style: secondaryTextStyle }, ` ${issue}`))) : null,
@@ -1863,6 +2828,18 @@ globalThis.window?.__ModuleLoader__?.load({
1863
2828
  }, "⠿"),
1864
2829
  React.createElement("span", { "data-role": "card-name", "data-entry-id": entry.id, className: entry.name ? "sc-card-name" : "sc-card-name sc-card-name-placeholder" }, displayName),
1865
2830
  React.createElement("span", { "data-role": "card-type", "data-entry-id": entry.id, className: duplicateTypeLabel ? "sc-type-duplicate" : "sc-type-badge" }, displayType),
2831
+ // #86 POOL-009①:卡片凭据状态含池规模「N 把」(仅池条目渲染;legacy 卡片零结构变化)。
2832
+ // §7 合同④(Refs #88 #86):池规模徽标与钉死徽标同排共存——池条目也可被钉死,两徽标互不吞。
2833
+ credPoolSize(entry) > 0 ? React.createElement("span", { "data-role": "card-pool-size", "data-entry-id": entry.id, className: "sc-type-badge" }, `${credPoolSize(entry)} 把`) : null,
2834
+ // #120 PX-012 要求5:双态徽标——关=「不全局重试」、legacy proxyOnly 读兼容=「经全局代理」;默认态(开/省略)零徽标。
2835
+ (entry.proxyPin === PROXY_PINS.DIRECT_ONLY || entry.proxyPin === PROXY_PINS.PROXY_ONLY)
2836
+ ? React.createElement("span", { className: "sc-pin-badge", "data-role": "pin-badge", "data-entry-id": entry.id }, entry.proxyPin === PROXY_PINS.DIRECT_ONLY ? "不全局重试" : "经全局代理")
2837
+ : null,
2838
+ // OSB-004(Refs #152):放行态 × 条目远程 PAC × 客户端平台形似非 darwin → 常显徽标
2839
+ // (子序:既有徽标之后、状态点之前,oracle A-061 兼容);裁决权在宿主探测,本徽标纯披露。
2840
+ model.pacUnlocked && !clientPlatformLooksDarwin() && entry.proxy && typeof entry.proxy === "object" && entry.proxy.pac
2841
+ ? React.createElement("span", { className: "sc-pin-badge", "data-role": "pac-unsandboxed-badge", "data-entry-id": entry.id }, "无 OS 隔离 · 经用户确认运行")
2842
+ : null,
1866
2843
  // R2:徽标纯点——data-role/data-state/role=img/aria-label/title 全部落在点自身;空文本、无 aria-live、无 wrapper。
1867
2844
  React.createElement("span", {
1868
2845
  className: "sc-status-dot", "data-role": "card-status", "data-entry-id": entry.id,
@@ -1905,6 +2882,10 @@ globalThis.window?.__ModuleLoader__?.load({
1905
2882
  const sectionErrorNode = model.sectionError ? React.createElement("p", {
1906
2883
  className: "sc-status-node", "data-role": "save-error", "data-state": "error", role: "alert",
1907
2884
  }, model.sectionError.text, ...(model.sectionError.issues ?? []).map((issue, i) => React.createElement("span", { key: `issue-${i}`, style: secondaryTextStyle }, ` ${issue}`))) : null;
2885
+ // PX-011(Refs #88):全局代理状态面——只写不回读;仅会话内记忆的脱敏目标(scheme://host:port,无 userinfo)。
2886
+ const gpRef = typeof model.draft.globalProxyRef === "string" ? model.draft.globalProxyRef : "";
2887
+ const gpRedacted = gpRef ? globalProxyRedacted.current[gpRef] : undefined;
2888
+ const gpStatusText = gpRef ? (gpRedacted ? `已配置:${gpRedacted}` : "已配置") : "未配置";
1908
2889
  // V5-2/V5-3:旧「点添加 → sc-picker 选厂商」独立步骤废止(picker 控件整体移除)。
1909
2890
  // 「新增表单打开」由「当前编辑器条目为未持久(幽灵)条目」派生(editorIsCreate,非独立标志):
1910
2891
  // 幽灵编辑器渲染于添加块入口原位,期间添加按钮不渲染(互斥);表单关闭(取消/Escape/保存成功)
@@ -1979,7 +2960,7 @@ globalThis.window?.__ModuleLoader__?.load({
1979
2960
  React.createElement("span", { className: "sc-switch-track", "aria-hidden": "true" }),
1980
2961
  React.createElement("span", { className: "sc-switch-label" }, "DeepSeek 官方 API 使用官方搜索"),
1981
2962
  ),
1982
- React.createElement("p", { className: "sc-official-hint", "data-role": "official-hint" }, "仅对 DeepSeek 官方 API 会话生效;关闭后相关会话改用下方工具链。官方搜索不另按次收费,模型用量仍按 token 计费。")),
2963
+ React.createElement("p", { className: "sc-official-hint", "data-role": "official-hint" }, "仅对 DeepSeek 官方 API 会话生效;关闭后相关会话改用下方搜索工具。官方搜索不另按次收费,模型用量仍按 token 计费。")),
1983
2964
  // SET-006:超时输入(B-017)——失焦/回车 且 值变化且合法 才落盘(仅 timeoutMs 键)。
1984
2965
  React.createElement("div", { className: "sc-timeout-row", "data-role": "timeout" },
1985
2966
  React.createElement("label", { className: "sc-timeout-label", htmlFor: "sc-timeout-input" }, "回退超时(毫秒)"),
@@ -1998,6 +2979,83 @@ globalThis.window?.__ModuleLoader__?.load({
1998
2979
  }),
1999
2980
  React.createElement("p", { className: "sc-official-hint" }, "单次搜索的共享总预算;按剩余时间与剩余启用工具数均分给各次尝试,单条超时或失败后在剩余总预算内回退到下一个工具。"),
2000
2981
  ),
2982
+ // PX-011(Refs #88)+ #142 修订注③(用户复验裁决):全局代理区块=地址输入(只写不回显)+
2983
+ // 「保存」唯一路径(语法门→写闸预检→凭据先写→mutate)+ 状态面(仅脱敏 scheme://host:port)+
2984
+ // PX-013 常驻披露文本。总闸开关退役:面板对 proxyEscalation 零写;存量显式 false 为隐藏兼容
2985
+ // 读面、仍全局生效(PR 记录在册风险)。面板对代理零连通性探测。
2986
+ React.createElement("div", { className: "sc-escalation-row" },
2987
+ // #120 PX-013 + #142 + #145 修订注二②:区块首行=「全局代理」标题+「?」;披露全文逐字迁入
2988
+ // 悬浮 tooltip(hover/focus 呈现,零布局位移),列位内长文取消;其余零动。
2989
+ React.createElement("div", { className: "sc-escalation-title" },
2990
+ React.createElement("span", { className: "sc-field-label" }, "全局代理"),
2991
+ React.createElement("span", { className: "sc-tip-anchor" },
2992
+ React.createElement("button", {
2993
+ className: "sc-retry-help", type: "button", "data-role": "global-proxy-help", tabIndex: 0,
2994
+ "aria-label": GLOBAL_PROXY_HELP_TEXT,
2995
+ "aria-describedby": model.globalHelpOpen ? "sc-global-proxy-disclosure" : undefined,
2996
+ onMouseEnter: () => setModel((m) => ({ ...m, globalHelpOpen: true })),
2997
+ onMouseLeave: () => setModel((m) => ({ ...m, globalHelpOpen: false })),
2998
+ onFocus: () => setModel((m) => ({ ...m, globalHelpOpen: true })),
2999
+ onBlur: () => setModel((m) => ({ ...m, globalHelpOpen: false })),
3000
+ }, "?"),
3001
+ model.globalHelpOpen ? React.createElement("span", {
3002
+ className: "sc-tip-bubble", role: "tooltip",
3003
+ "data-role": "escalation-disclosure", id: "sc-global-proxy-disclosure",
3004
+ }, GLOBAL_PROXY_HELP_TEXT) : null,
3005
+ ),
3006
+ ),
3007
+ React.createElement("div", { className: "sc-escalation-proxy" },
3008
+ React.createElement("input", {
3009
+ className: "sc-input", type: "text", inputMode: "url", autoComplete: "off", spellCheck: false,
3010
+ "data-role": "global-proxy-input", disabled: locked,
3011
+ "aria-label": "全局代理地址(只写不回显)",
3012
+ placeholder: "全局代理地址(http(s)://host:port,凭据只写不回显)",
3013
+ value: model.globalProxyText ?? "",
3014
+ onChange: updateGlobalProxyText,
3015
+ }),
3016
+ React.createElement("button", {
3017
+ className: "sc-button sc-button-secondary", type: "button", "data-role": "escalation-save",
3018
+ disabled: locked, onClick: commitEscalation,
3019
+ }, "保存"),
3020
+ React.createElement("p", { className: "sc-escalation-status", "data-role": "global-proxy-status", role: "status" },
3021
+ gpRef ? gpStatusText : "未配置(保存全局代理地址后,失败的条目才会自动经全局代理重试)"),
3022
+ ),
3023
+ model.escalationError ? React.createElement("p", {
3024
+ className: "sc-status-node", "data-role": "save-error", "data-state": "error", role: "alert",
3025
+ }, model.escalationError.text) : null,
3026
+ // OSB-004(Refs #152)+ #156(Refs #156)+ #161 修复(Refs #161):行结构复刻 #145 重试行原版
3027
+ // 三段式 `.sc-pin-row`(开关·短标签·?,gap 节奏同款),气泡内联右缘锚定(left:auto/right:0,
3028
+ // 向左展开不越设置列;.sc-tip-bubble 视觉规则原样,零新增 CSS)。
3029
+ React.createElement("div", { className: "sc-pin-row" },
3030
+ React.createElement("label", { className: "sc-pin-retry-switch" },
3031
+ React.createElement("input", {
3032
+ className: "sc-switch-input", type: "checkbox", role: "switch", "aria-checked": model.pacUnlocked,
3033
+ "aria-label": "信任所有 PAC:无 OS 级隔离时也求值远程 PAC 脚本", "data-role": "pac-unsandboxed-toggle", disabled: locked,
3034
+ checked: model.pacUnlocked,
3035
+ onChange: (ev) => commitPacUnsandboxed(ev.target.checked),
3036
+ }),
3037
+ React.createElement("span", { className: "sc-switch-track", "aria-hidden": "true" }),
3038
+ ),
3039
+ React.createElement("span", { className: "sc-field-label" }, "信任所有 PAC"),
3040
+ React.createElement("span", { className: "sc-tip-anchor" },
3041
+ React.createElement("button", {
3042
+ className: "sc-retry-help", type: "button", "data-role": "pac-help", tabIndex: 0,
3043
+ "aria-label": PAC_UNSANDBOXED_HELP_TEXT,
3044
+ "aria-describedby": model.pacHelpOpen ? "sc-pac-unsandboxed-disclosure" : undefined,
3045
+ onMouseEnter: () => setModel((m) => ({ ...m, pacHelpOpen: true })),
3046
+ onMouseLeave: () => setModel((m) => ({ ...m, pacHelpOpen: false })),
3047
+ onFocus: () => setModel((m) => ({ ...m, pacHelpOpen: true })),
3048
+ onBlur: () => setModel((m) => ({ ...m, pacHelpOpen: false })),
3049
+ }, "?"),
3050
+ model.pacHelpOpen ? React.createElement("span", {
3051
+ className: "sc-tip-bubble", role: "tooltip",
3052
+ // #161:? 位于行右半,气泡右缘锚定向左展开(内联覆盖 left,类与其余规则零动)。
3053
+ style: { left: "auto", right: 0 },
3054
+ "data-role": "pac-unsandboxed-help", id: "sc-pac-unsandboxed-disclosure",
3055
+ }, PAC_UNSANDBOXED_HELP_TEXT) : null,
3056
+ ),
3057
+ ),
3058
+ ),
2001
3059
  // v3 用户反馈(V3-1 无占位行):空状态判据=已持久条目视图(有效列表)——新建编辑器开启期间
2002
3060
  // 草稿含幽灵行,但持久视图仍空 → 空状态与新建编辑器同屏呈现(列表恒等于持久视图)。
2003
3061
  effectiveEntriesOf(model).length === 0 ? React.createElement("p", { "data-role": "empty-state", style: secondaryTextStyle }, "还没有配置搜索工具,点击下方「添加搜索工具」添加第一条。") : null,
@@ -2024,14 +3082,19 @@ globalThis.window?.__ModuleLoader__?.load({
2024
3082
 
2025
3083
 
2026
3084
  return {
2027
- inject: ["slots"],
3085
+ inject: ["slots", "locale"], // #118:locale 为宿主语言面(live 服务目录在列,README 例证 inject ['locale'])
2028
3086
  /**
2029
- * 挂载「网页搜索链」设置区(SET-001)——配置入口唯一。
3087
+ * 挂载「千帆 FleetSeek」设置区(SET-001)——配置入口唯一。
3088
+ * sidebar 导航行品牌分语言(#118):label 经 ctx.locale 取当前语言。
2030
3089
  * @param {{
2031
3090
  * slots: {
2032
3091
  * inject(slot: string, factory: () => (() => void)): () => void,
2033
3092
  * register(registration: object, Component: (props: object) => unknown): () => void,
2034
3093
  * },
3094
+ * locale?: {
3095
+ * getSnapshot(): { active: string },
3096
+ * subscribe(fn: () => void): () => void,
3097
+ * },
2035
3098
  * effect(fn: () => (() => void)): void,
2036
3099
  * }} ctx
2037
3100
  */
@@ -2040,12 +3103,29 @@ globalThis.window?.__ModuleLoader__?.load({
2040
3103
  if (mounted.has(key)) return; // 幂等:重复 apply 不双 inject
2041
3104
  mounted.set(key, true);
2042
3105
 
2043
- const offSection = ctx.slots.inject(SECTION_SLOT, () =>
3106
+ // #118 契约(ui-settings contract/slots.ts 原文):label 是 registrant-local 显示文本,
3107
+ // 「the registrant re-registers with fresh text on locale change, so the shell never
3108
+ // subscribes locale state; the ledger bump doubles as the shell's re-render trigger」
3109
+ // ——语言切换时注销+重注册制造 ledger bump;label 同时保持函数形读当前值,双通道幂等。
3110
+ const registerSection = () =>
2044
3111
  ctx.slots.register(
2045
- { name: SECTION_SLOT, id: PROVIDER_ID, order: SECTION_ORDER, label: sectionLabel },
3112
+ { name: SECTION_SLOT, id: PROVIDER_ID, order: SECTION_ORDER, label: () => sectionLabel(ctx) },
2046
3113
  SettingsPanel,
2047
- ),
2048
- );
3114
+ );
3115
+ const offSection = ctx.slots.inject(SECTION_SLOT, () => {
3116
+ let offRegister = registerSection();
3117
+ const offLocale =
3118
+ ctx.locale && typeof ctx.locale.subscribe === "function"
3119
+ ? ctx.locale.subscribe(() => {
3120
+ offRegister();
3121
+ offRegister = registerSection();
3122
+ })
3123
+ : null;
3124
+ return () => {
3125
+ if (offLocale) offLocale();
3126
+ offRegister();
3127
+ };
3128
+ });
2049
3129
 
2050
3130
  // 卸载语义(DSH-001):撤销懒挂载并清除幂等键;重复调用无副作用。
2051
3131
  ctx.effect(() => () => {