dsh-fleetseek 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -8
- package/docs/README.md +1 -1
- package/docs/user/README.md +2 -1
- package/docs/user/fetch-takeover.md +64 -0
- package/docs/user/getting-started.md +7 -7
- package/docs/user/troubleshooting.md +14 -14
- package/docs/user/upgrade.md +15 -5
- package/package.json +10 -2
- package/src/backends/bing.js +10 -5
- package/src/backends/exa.js +5 -3
- package/src/client-entry.js +1086 -120
- package/src/client.js +2 -2
- package/src/config.js +281 -17
- package/src/constants.js +149 -1
- package/src/fetch/chain.js +522 -0
- package/src/fetch/official-leg.js +53 -0
- package/src/fetch/provider.js +245 -0
- package/src/fetch/ssrf.js +181 -0
- package/src/host-log.js +132 -0
- package/src/index.js +163 -24
- package/src/official.js +1 -1
- package/src/search.js +648 -69
- package/src/settings/catalog.js +18 -5
- package/src/transport.js +84 -6
package/src/client.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
//
|
|
9
9
|
// 呈现层边界:本模块只产出面板数据与插槽挂载描述;DOM/主题/控件由宿主设置区渲染。
|
|
10
10
|
// 面板-宿主投影依赖(宿主是否接受插件自定义 Config 的 describe()/volatileForm/schema.toJSON()
|
|
11
|
-
//
|
|
11
|
+
// 投影路径)属实机核对项,见交付报告「面板-宿主投影依赖假设」;数据层不臆造呈现。
|
|
12
12
|
//
|
|
13
13
|
// 零 npm 依赖;运行时零 import test/(常量本地镜像见 src/settings/catalog.js 头注同步义务)。
|
|
14
14
|
|
|
@@ -30,7 +30,7 @@ export function createSettingsPanel(deps) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* 把面板挂载为宿主设置区的「千帆 FleetSeek」区域(SET-001/DSH-001)。
|
|
34
34
|
* 幂等:同一 panel 重复挂载不会双注册;返回的 cleanup 注销区域(卸载语义 DSH-001)。
|
|
35
35
|
*
|
|
36
36
|
* descriptor 为最小自描述形状:{ id, title, panel }。真实宿主 settings.section 的
|
package/src/config.js
CHANGED
|
@@ -13,23 +13,41 @@
|
|
|
13
13
|
import {
|
|
14
14
|
CONFIG_CODES,
|
|
15
15
|
DEFAULT_TIMEOUT_MS,
|
|
16
|
+
FETCH_CONFIG_KEYS,
|
|
17
|
+
FETCH_CODES,
|
|
18
|
+
FETCH_TOOL_TYPES,
|
|
16
19
|
KEY_ENV_BY_TYPE,
|
|
17
20
|
KEYLESS_TYPES,
|
|
18
21
|
LEGACY_YAML_SUPPLIERS,
|
|
22
|
+
POOL_MAX,
|
|
23
|
+
PROXY_PINS,
|
|
24
|
+
PROXY_PIN_VALUES,
|
|
19
25
|
TOOL_TYPES,
|
|
20
26
|
TRUSTED_ENV_KEYS,
|
|
27
|
+
isLegitGlobalProxyRef,
|
|
28
|
+
isSecretClosureKey,
|
|
29
|
+
WEB_CODES,
|
|
21
30
|
supplierOfToolType,
|
|
31
|
+
stripSecretClosure,
|
|
22
32
|
} from "./constants.js";
|
|
23
33
|
|
|
24
34
|
// WP1 导出增量:常量面(值以主线 constants.js 为单一事实源)。
|
|
35
|
+
// #87 增量:fetch 面常量族再导出(FETCH_TOOL_TYPES / FETCH_CONFIG_KEYS / FETCH_CODES / WEB_CODES)。
|
|
25
36
|
export {
|
|
26
37
|
TOOL_TYPES,
|
|
27
38
|
KEY_ENV_BY_TYPE,
|
|
28
39
|
KEYLESS_TYPES,
|
|
40
|
+
POOL_MAX,
|
|
29
41
|
TRUSTED_ENV_KEYS,
|
|
30
42
|
LEGACY_YAML_SUPPLIERS,
|
|
31
43
|
CONFIG_CODES,
|
|
32
44
|
DEFAULT_TIMEOUT_MS,
|
|
45
|
+
PROXY_PINS,
|
|
46
|
+
PROXY_PIN_VALUES,
|
|
47
|
+
FETCH_TOOL_TYPES,
|
|
48
|
+
FETCH_CONFIG_KEYS,
|
|
49
|
+
FETCH_CODES,
|
|
50
|
+
WEB_CODES,
|
|
33
51
|
};
|
|
34
52
|
|
|
35
53
|
/** 配置类错误:携带 CONFIG_CODES 之一的 code,message 不含任何凭据。 */
|
|
@@ -42,25 +60,77 @@ export class ConfigError extends Error {
|
|
|
42
60
|
}
|
|
43
61
|
|
|
44
62
|
const SECRET_FIELD = /^(apikey|api_key|key|secret|token|password|auth|authorization)$/i;
|
|
45
|
-
|
|
63
|
+
// §7 合同①键集并集(Refs #88 #86):#86 credentialRefs 族 + #88 proxyPin 族并列;任一面板保存不得清他包字段。
|
|
64
|
+
// P2b(sol-87 同源钉):未知字段透传谓词 = `HANDLED_ENTRY_FIELDS 含 k || SECRET_FIELD.test(k)`,与 client-entry.js 孪生面同一判据源——改本处字段集/正则须同步孪生面(search+fetch entry 未知字段透传零漂移)。
|
|
65
|
+
const POSIX_CREDENTIAL_REF = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
66
|
+
const HANDLED_ENTRY_FIELDS = new Set(["id", "type", "name", "enabled", "credentialRef", "credentialRefs", "proxy", "proxyPin"]);
|
|
67
|
+
// sol-87b 案2/批3③(lead 裁决):fetch 条目字段集(孪生 client-entry.js 同形;改一处须同步另一处)——
|
|
68
|
+
// HANDLED = fetch 条目接纳字段(D-FT1 冻结分离:不含搜索条目的池/pin);
|
|
69
|
+
// SIBLING = 搜索条目专用(proxyPin/credentialRefs)——两闸显式拒(不得整键丢弃静默吞)。
|
|
70
|
+
const FETCH_ENTRY_HANDLED_FIELDS = new Set(["id", "type", "name", "enabled", "credentialRef", "proxy"]);
|
|
71
|
+
const FETCH_ENTRY_SIBLING_FIELDS = new Set(["proxyPin", "credentialRefs"]);
|
|
46
72
|
|
|
47
|
-
|
|
48
|
-
|
|
73
|
+
/**
|
|
74
|
+
* POOL-001/003/010(#86)凭据池双闸读侧:credentialRefs 形态裁决(写闸镜像在 client-entry
|
|
75
|
+
* contract.normalizeEntry,文案与检查序必须逐字一致——两闸双向全等由 pool-oracle-gates 钉)。
|
|
76
|
+
* 检查序:互斥 → bing 免 key → 数组 → 上限 → 元素 → trim 去重。
|
|
77
|
+
* @returns {string[]|undefined} trim 后原序引用;空/缺省返回 undefined(省略该键)。
|
|
78
|
+
*/
|
|
79
|
+
function normalizeCredentialRefs(rawRefs, { where, type, hasCredentialRef }) {
|
|
80
|
+
if (rawRefs === undefined) return undefined;
|
|
81
|
+
const isArray = Array.isArray(rawRefs);
|
|
82
|
+
if (hasCredentialRef && isArray && rawRefs.length > 0) {
|
|
83
|
+
throw invalid(`${where}.credentialRef 与 credentialRefs 互斥(两字段不得共存,请保留其一)`, "credentialRefs");
|
|
84
|
+
}
|
|
85
|
+
if (type === "bing" && isArray && rawRefs.length > 0) {
|
|
86
|
+
throw invalid(`${where} bing 类型免 key,不得配置 credentialRefs`, "credentialRefs");
|
|
87
|
+
}
|
|
88
|
+
if (!isArray) {
|
|
89
|
+
throw invalid(`${where}.credentialRefs 必须是数组(0–${POOL_MAX} 个凭据引用名)`, "credentialRefs");
|
|
90
|
+
}
|
|
91
|
+
if (rawRefs.length > POOL_MAX) {
|
|
92
|
+
throw invalid(`${where}.credentialRefs 超出池上限:实际 ${rawRefs.length} 个,上限 ${POOL_MAX} 个`, "credentialRefs");
|
|
93
|
+
}
|
|
94
|
+
const refs = [];
|
|
95
|
+
for (let j = 0; j < rawRefs.length; j += 1) {
|
|
96
|
+
const el = rawRefs[j];
|
|
97
|
+
if (typeof el !== "string" || el.trim() === "") {
|
|
98
|
+
throw invalid(`${where}.credentialRefs[${j}] 必须是非空白字符串(凭据引用名)`, "credentialRefs");
|
|
99
|
+
}
|
|
100
|
+
refs.push(el.trim());
|
|
101
|
+
}
|
|
102
|
+
for (let j = 0; j < refs.length; j += 1) {
|
|
103
|
+
for (let k = 0; k < j; k += 1) {
|
|
104
|
+
if (refs[j] === refs[k]) {
|
|
105
|
+
throw invalid(`${where}.credentialRefs[${j}] 与池内其他元素 trim 后重复(池内引用重复)`, "credentialRefs");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return refs.length > 0 ? refs : undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// sol 第三轮(Refs #88):新契约字段族违规的结构化标记(写闸分叉判据)——fieldFamily 为
|
|
113
|
+
// "credentialRefs" | "proxyEscalation" | "globalProxy" | "proxyPin" 之一;legacy 违规不带该属性。
|
|
114
|
+
// 分叉按结构化标记而非文案关键词(反例钉:合法条目 id="proxyPin" 撞 legacy 重复 id 文案不得误分叉)。
|
|
115
|
+
function invalid(message, family) {
|
|
116
|
+
const e = new ConfigError(CONFIG_CODES.INVALID, message);
|
|
117
|
+
if (family !== undefined) e.fieldFamily = family;
|
|
118
|
+
return e;
|
|
49
119
|
}
|
|
50
120
|
|
|
51
121
|
function isPlainObject(v) {
|
|
52
122
|
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
53
123
|
}
|
|
54
124
|
|
|
55
|
-
function assertHttpUrl(text, where) {
|
|
125
|
+
function assertHttpUrl(text, where, family) {
|
|
56
126
|
let u;
|
|
57
127
|
try {
|
|
58
128
|
u = new URL(text);
|
|
59
129
|
} catch {
|
|
60
|
-
throw invalid(`${where} 必须是绝对 HTTP(S) URL
|
|
130
|
+
throw invalid(`${where} 必须是绝对 HTTP(S) URL`, family);
|
|
61
131
|
}
|
|
62
132
|
if (u.protocol !== "http:" && u.protocol !== "https:") {
|
|
63
|
-
throw invalid(`${where} 必须是 HTTP(S) URL
|
|
133
|
+
throw invalid(`${where} 必须是 HTTP(S) URL`, family);
|
|
64
134
|
}
|
|
65
135
|
}
|
|
66
136
|
|
|
@@ -68,22 +138,24 @@ function assertHttpUrl(text, where) {
|
|
|
68
138
|
* CFG-001:proxy 为 string(HTTP(S) 代理 URL)| { pac } | 省略/空白=直连。
|
|
69
139
|
* WP1 导出面:where 为条目位置前缀(如 "entries[0]",内部调用传入);缺省时文案以 "proxy" 开头。
|
|
70
140
|
*/
|
|
71
|
-
|
|
141
|
+
/** CFG-001 代理三形态校验。family(可选):违规打字段族标(sol-87b 批2②:fetch 条目
|
|
142
|
+
* 传入 "fetch" → validate 分叉走新契约 throw 形;搜索面不传,行为零变化)。 */
|
|
143
|
+
export function normalizeProxy(raw, where, family) {
|
|
72
144
|
const w = where ? `${where}.proxy` : "proxy";
|
|
73
145
|
if (raw === undefined || raw === null) return undefined;
|
|
74
146
|
if (typeof raw === "string") {
|
|
75
147
|
const s = raw.trim();
|
|
76
148
|
if (s === "") return undefined;
|
|
77
|
-
assertHttpUrl(s, w);
|
|
149
|
+
assertHttpUrl(s, w, family);
|
|
78
150
|
return s;
|
|
79
151
|
}
|
|
80
152
|
if (isPlainObject(raw) && Object.keys(raw).length === 1 && typeof raw.pac === "string") {
|
|
81
153
|
const pac = raw.pac.trim();
|
|
82
|
-
if (pac === "") throw invalid(`${w}.pac
|
|
83
|
-
assertHttpUrl(pac, `${w}.pac
|
|
154
|
+
if (pac === "") throw invalid(`${w}.pac 不得为空白`, family);
|
|
155
|
+
assertHttpUrl(pac, `${w}.pac`, family);
|
|
84
156
|
return { pac };
|
|
85
157
|
}
|
|
86
|
-
throw invalid(`${w} 形态非法(须为代理 URL 字符串或 { pac }
|
|
158
|
+
throw invalid(`${w} 形态非法(须为代理 URL 字符串或 { pac })`, family);
|
|
87
159
|
}
|
|
88
160
|
|
|
89
161
|
function normalizeEntry(raw, index) {
|
|
@@ -106,20 +178,123 @@ function normalizeEntry(raw, index) {
|
|
|
106
178
|
}
|
|
107
179
|
out.credentialRef = raw.credentialRef.trim();
|
|
108
180
|
}
|
|
181
|
+
// POOL-001/003/010:credentialRefs 池形态(旧形态 credentialRef 单引用行为零变化;
|
|
182
|
+
// 合法空数组等同省略——旧形态条目不得被注入 credentialRefs 键)。
|
|
183
|
+
const refs = normalizeCredentialRefs(raw.credentialRefs, {
|
|
184
|
+
where,
|
|
185
|
+
type: raw.type,
|
|
186
|
+
hasCredentialRef: out.credentialRef !== undefined,
|
|
187
|
+
});
|
|
188
|
+
if (refs !== undefined) out.credentialRefs = refs;
|
|
109
189
|
const proxy = normalizeProxy(raw.proxy, where);
|
|
110
190
|
if (proxy !== undefined) out.proxy = proxy;
|
|
111
191
|
|
|
192
|
+
let proxyPin = PROXY_PINS.INHERIT;
|
|
193
|
+
if (raw.proxyPin !== undefined) {
|
|
194
|
+
if (typeof raw.proxyPin !== "string" || !PROXY_PIN_VALUES.includes(raw.proxyPin)) {
|
|
195
|
+
throw invalid(`${where}.proxyPin 必须是 "inherit" | "directOnly" | "proxyOnly"`, "proxyPin");
|
|
196
|
+
}
|
|
197
|
+
proxyPin = raw.proxyPin;
|
|
198
|
+
}
|
|
199
|
+
// #120 PX-006 双态演化 + #142 修订注②:开=inherit/省略(输出省略该键)、关=directOnly;proxyOnly
|
|
200
|
+
// 退役为读兼容存量值(不再由 UI 写入)。组合裁决:directOnly + 自有 proxy(固定字符串形与 PAC 对象形
|
|
201
|
+
// 同域,#142 推翻「PAC 拒绝任何显式钉值」)合法化(关态=仅走自有路径);proxyOnly + 自有 proxy
|
|
202
|
+
// 维持互斥(强制全局与自有矛盾格,含 PAC)。
|
|
203
|
+
if (proxy !== undefined && proxyPin !== PROXY_PINS.INHERIT) {
|
|
204
|
+
const legal = proxyPin === PROXY_PINS.DIRECT_ONLY;
|
|
205
|
+
if (!legal) {
|
|
206
|
+
throw invalid(
|
|
207
|
+
`${where}.proxyPin 与条目自有 proxy 互斥(自有代理条目(含 PAC 形)仅允许 inherit 或 directOnly;proxyOnly 强制全局与自有代理矛盾)`,
|
|
208
|
+
"proxyPin",
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// PX-006 验收4:默认值不实体化——显式 "inherit" 与省略归一化输出同构(均省略键)。
|
|
213
|
+
if (proxyPin !== PROXY_PINS.INHERIT) out.proxyPin = proxyPin;
|
|
214
|
+
|
|
112
215
|
// 其余参数只保留原始标量;对象与明文 key 字段一律丢弃(CFG-003:明文 key 不落盘)。
|
|
216
|
+
// §7 合同②(Refs #88 #86):保留面跳过判定用统一闭集(legacy 八名族 ∪ globalProxy 族,合法引用豁免)——
|
|
217
|
+
// 条目级 globalProxyUrl 等未知标量明文不再经 normalized 透传(readConfig→writeConfig round-trip 零留存)。
|
|
218
|
+
// P2b 同源谓词(见 HANDLED_ENTRY_FIELDS 定义处注释):与 client-entry 孪生面同一判据源。
|
|
113
219
|
for (const [k, v] of Object.entries(raw)) {
|
|
114
|
-
if (HANDLED_ENTRY_FIELDS.has(k) ||
|
|
220
|
+
if (HANDLED_ENTRY_FIELDS.has(k) || (isSecretClosureKey(k) && !isLegitGlobalProxyRef(k, v))) continue;
|
|
115
221
|
if (["string", "number", "boolean"].includes(typeof v)) out[k] = v;
|
|
116
222
|
}
|
|
117
223
|
return out;
|
|
118
224
|
}
|
|
119
225
|
|
|
226
|
+
function normalizeGlobalProxyRef(raw) {
|
|
227
|
+
if (raw === undefined || raw === "") return undefined;
|
|
228
|
+
if (typeof raw !== "string") {
|
|
229
|
+
throw invalid("globalProxy 只允许保存凭据引用名(禁止非字符串或 null),请改由设置面板保存全局代理地址", "globalProxy");
|
|
230
|
+
}
|
|
231
|
+
const s = raw.trim();
|
|
232
|
+
if (s === "") {
|
|
233
|
+
throw invalid("globalProxy 不得为空白字符串(未配置请省略,或在设置面板保存)", "globalProxy");
|
|
234
|
+
}
|
|
235
|
+
if (s.includes("://") || s.includes("@")) {
|
|
236
|
+
throw invalid("globalProxy 只允许保存凭据引用名(禁止明文代理 URL),请改由设置面板保存全局代理地址", "globalProxy");
|
|
237
|
+
}
|
|
238
|
+
if (!POSIX_CREDENTIAL_REF.test(s)) {
|
|
239
|
+
throw invalid("globalProxy 只允许保存 POSIX 凭据引用名(禁止明文地址或非法字符),请改由设置面板保存全局代理地址", "globalProxy");
|
|
240
|
+
}
|
|
241
|
+
return s;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* #87 FT-009 fetch 条目规范化(读闸/写闸共用)。
|
|
246
|
+
* 读闸 credentialRef 可缺省(执行期按 FB-001 跳过);写闸的 keyless 拒绝在 writeConfig 预检
|
|
247
|
+
* (FT-009#2:免 key 形态不得落盘,文案含 key/凭据)。proxy 复用 CFG-001 三形态
|
|
248
|
+
* (sol-87b 批2②:fetch 面传入 family="fetch",违规走 validate 新契约 throw 形)。
|
|
249
|
+
* 未知字段面(sol-87b 案2/批3③ lead 裁决):兄弟族键(proxyPin/credentialRefs = 搜索条目
|
|
250
|
+
* 专用)显式拒;其余未知字段整键丢弃(两闸同形,不建第三形态);合法引用豁免族不受影响。
|
|
251
|
+
*/
|
|
252
|
+
function normalizeFetchEntry(raw, index) {
|
|
253
|
+
const where = `fetchEntries[${index}]`;
|
|
254
|
+
if (!isPlainObject(raw)) throw invalid(`${where} 必须是对象`, "fetch");
|
|
255
|
+
if (typeof raw.id !== "string" || raw.id.trim() === "") throw invalid(`${where}.id 必须是非空字符串`, "fetch");
|
|
256
|
+
if (typeof raw.type !== "string" || !FETCH_TOOL_TYPES.includes(raw.type)) {
|
|
257
|
+
throw invalid(`${where}.type 不是已知 fetch 类型(首期仅 ${FETCH_TOOL_TYPES.join(" / ")})`, "fetch");
|
|
258
|
+
}
|
|
259
|
+
const name = raw.name === undefined ? raw.type : raw.name;
|
|
260
|
+
if (typeof name !== "string") throw invalid(`${where}.name 必须是字符串`, "fetch");
|
|
261
|
+
const enabled = raw.enabled === undefined ? true : raw.enabled;
|
|
262
|
+
if (typeof enabled !== "boolean") throw invalid(`${where}.enabled 必须是布尔值`, "fetch");
|
|
263
|
+
|
|
264
|
+
const out = { id: raw.id.trim(), type: raw.type, name, enabled };
|
|
265
|
+
|
|
266
|
+
if (raw.credentialRef !== undefined && raw.credentialRef !== null && raw.credentialRef !== "") {
|
|
267
|
+
if (typeof raw.credentialRef !== "string" || raw.credentialRef.trim() === "") {
|
|
268
|
+
throw invalid(`${where}.credentialRef 非法`, "fetch");
|
|
269
|
+
}
|
|
270
|
+
out.credentialRef = raw.credentialRef.trim();
|
|
271
|
+
}
|
|
272
|
+
const proxy = normalizeProxy(raw.proxy, where, "fetch");
|
|
273
|
+
if (proxy !== undefined) out.proxy = proxy;
|
|
274
|
+
// sol-87b 批3③(lead 裁决):兄弟族键(搜索条目专用,D-FT1 冻结分离——fetch 条目不收
|
|
275
|
+
// pin/pool,④ 非缺陷仅显式化)显式拒——安全意图字段永不静默吞(不得整键丢弃)。
|
|
276
|
+
for (const k of FETCH_ENTRY_SIBLING_FIELDS) {
|
|
277
|
+
if (Object.hasOwn(raw, k)) {
|
|
278
|
+
throw invalid(`${where}.${k} 是搜索条目专用字段,fetch 条目不接受(D-FT1:fetch 条目不收 pin/pool 键)`, "fetch");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// sol-87b 案2(lead 裁决):未知字段整键丢弃(scalar/对象/数组均不透传,两闸同形,不建第三
|
|
282
|
+
// 形态);合法引用豁免族不受影响(唯一合法形态 = 精确键 globalProxy 持 POSIX 凭据引用名——
|
|
283
|
+
// 引用是数据非明文,round-trip 零留存);明文 key 字段读闸静默丢弃(CFG-003 同源),
|
|
284
|
+
// 写闸预检先行拒绝(FT-007#2)。
|
|
285
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
286
|
+
if (FETCH_ENTRY_HANDLED_FIELDS.has(k)) continue;
|
|
287
|
+
if (isSecretClosureKey(k) && isLegitGlobalProxyRef(k, v)) out[k] = v;
|
|
288
|
+
}
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
|
|
120
292
|
/**
|
|
121
293
|
* 校验并规范化已保存形状(CFG-004)。非法输入抛 ConfigError(CONFIG_INVALID)。
|
|
122
|
-
* 缺省:entries=[]、useOfficialDeepSeekSearch=true(SET-005)、timeoutMs=25000(FB-003
|
|
294
|
+
* 缺省:entries=[]、useOfficialDeepSeekSearch=true(SET-005)、timeoutMs=25000(FB-003)、
|
|
295
|
+
* proxyEscalation 省略(PX-001 #120:省略=默认开,输出不实体化)、globalProxy 省略;
|
|
296
|
+
* #87:fetch 三键校验恒执行(非法即 CONFIG_INVALID,FT-007#1b),输出条件化——输入未携带的键
|
|
297
|
+
* 不进输出(CFG-004 落盘=输出 ∩ FT-007#3 未触碰零新键);缺键默认由消费面承担(FT-003#1)。
|
|
123
298
|
*/
|
|
124
299
|
export function normalizeConfig(raw) {
|
|
125
300
|
if (raw === undefined || raw === null) raw = {};
|
|
@@ -142,7 +317,44 @@ export function normalizeConfig(raw) {
|
|
|
142
317
|
throw invalid("timeoutMs 必须是正整数毫秒");
|
|
143
318
|
}
|
|
144
319
|
|
|
145
|
-
|
|
320
|
+
// #120 PX-001(二轮):默认翻转——省略=默认开且输出省略该键(默认值不落盘不实体化);
|
|
321
|
+
// 显式布尔原样保留(kill-switch 意图可审计);类型判定不变(非布尔含 null 仍 CONFIG_INVALID)。
|
|
322
|
+
let proxyEscalation;
|
|
323
|
+
if (raw.proxyEscalation !== undefined) {
|
|
324
|
+
if (typeof raw.proxyEscalation !== "boolean") {
|
|
325
|
+
throw invalid("proxyEscalation 必须是布尔值", "proxyEscalation");
|
|
326
|
+
}
|
|
327
|
+
proxyEscalation = raw.proxyEscalation;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const globalProxy = normalizeGlobalProxyRef(raw.globalProxy);
|
|
331
|
+
// #120 PX-001 验收2/3:组合拒绝废止——「显式 true+无引用」合法化(PX-009 矩阵第 5 行=PX-002a 零改道);
|
|
332
|
+
// 「无键+无引用」a 态静默合法(能力未置备)。
|
|
333
|
+
|
|
334
|
+
// #87 fetch 面三键(FT-003#1 缺省即默认;FT-002#3/FT-007#1b 非法形态 CONFIG_INVALID)。
|
|
335
|
+
const fetchTakeover = raw.fetchTakeover === undefined ? false : raw.fetchTakeover;
|
|
336
|
+
if (typeof fetchTakeover !== "boolean") throw invalid("fetchTakeover 必须是布尔值", "fetch");
|
|
337
|
+
const rawFetchEntries = raw.fetchEntries === undefined ? [] : raw.fetchEntries;
|
|
338
|
+
if (!Array.isArray(rawFetchEntries)) throw invalid("fetchEntries 必须是数组", "fetch");
|
|
339
|
+
const fetchEntries = rawFetchEntries.map((e, i) => normalizeFetchEntry(e, i));
|
|
340
|
+
const seenFetch = new Set();
|
|
341
|
+
for (const e of fetchEntries) {
|
|
342
|
+
if (seenFetch.has(e.id)) throw invalid(`fetchEntries 中 id 重复:${e.id}`, "fetch");
|
|
343
|
+
seenFetch.add(e.id);
|
|
344
|
+
}
|
|
345
|
+
const fetchOfficialFallback = raw.fetchOfficialFallback === undefined ? true : raw.fetchOfficialFallback;
|
|
346
|
+
if (typeof fetchOfficialFallback !== "boolean") throw invalid("fetchOfficialFallback 必须是布尔值", "fetch");
|
|
347
|
+
const out = {
|
|
348
|
+
entries,
|
|
349
|
+
useOfficialDeepSeekSearch: useOfficial,
|
|
350
|
+
timeoutMs,
|
|
351
|
+
};
|
|
352
|
+
if (proxyEscalation !== undefined) out.proxyEscalation = proxyEscalation;
|
|
353
|
+
if (globalProxy !== undefined) out.globalProxy = globalProxy;
|
|
354
|
+
if (Object.hasOwn(raw, "fetchTakeover")) out.fetchTakeover = fetchTakeover;
|
|
355
|
+
if (Object.hasOwn(raw, "fetchEntries")) out.fetchEntries = fetchEntries;
|
|
356
|
+
if (Object.hasOwn(raw, "fetchOfficialFallback")) out.fetchOfficialFallback = fetchOfficialFallback;
|
|
357
|
+
return out;
|
|
146
358
|
}
|
|
147
359
|
|
|
148
360
|
function deepFreeze(value) {
|
|
@@ -163,21 +375,73 @@ export function readConfig(settings) {
|
|
|
163
375
|
}
|
|
164
376
|
|
|
165
377
|
/** 本插件在 override 层自有的顶层配置键(normalizeConfig 输出键集);写入时整体替换,其余键(未知/他插件)保留。 */
|
|
166
|
-
const OWN_CONFIG_KEYS = [
|
|
378
|
+
export const OWN_CONFIG_KEYS = Object.freeze([
|
|
379
|
+
"entries",
|
|
380
|
+
"useOfficialDeepSeekSearch",
|
|
381
|
+
"timeoutMs",
|
|
382
|
+
"proxyEscalation",
|
|
383
|
+
"globalProxy",
|
|
384
|
+
]);
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* #87 FT-007#2/FT-009#2 写闸预检(新契约字段族=预检抛错,lead 裁决 PR #104;
|
|
388
|
+
* 同 #88 PX 修订注所立分叉规则——legacy 字段违规仍走 normalizeConfig 返回 CONFIG_INVALID)。
|
|
389
|
+
* 在 editor.edit 之前执行:拒绝时磁盘零变化。文案不含任何 key 值(CFG-003)。
|
|
390
|
+
*/
|
|
391
|
+
export function checkFetchWriteGate(input) {
|
|
392
|
+
if (input === undefined || input === null || typeof input !== "object" || Array.isArray(input)) return;
|
|
393
|
+
const rawFetch = input.fetchEntries;
|
|
394
|
+
if (rawFetch === undefined) return;
|
|
395
|
+
if (!Array.isArray(rawFetch)) return; // 形状错误归 normalizeConfig 判
|
|
396
|
+
rawFetch.forEach((e, i) => {
|
|
397
|
+
if (e === null || typeof e !== "object" || Array.isArray(e)) return; // 形状错误归 normalizeConfig 判
|
|
398
|
+
for (const k of Object.keys(e)) {
|
|
399
|
+
if (SECRET_FIELD.test(k)) {
|
|
400
|
+
throw invalid(
|
|
401
|
+
`fetch 条目 fetchEntries[${i}] 含明文 key 字段:key 必须经 credentialRef 引用(write-only),不得明文落盘`,
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const ref = typeof e.credentialRef === "string" ? e.credentialRef.trim() : "";
|
|
406
|
+
if (ref === "") {
|
|
407
|
+
const label = typeof e.id === "string" && e.id.trim() !== "" ? e.id.trim() : `fetchEntries[${i}]`;
|
|
408
|
+
throw invalid(`fetch 条目「${label}」必须配置 key:credentialRef 需为非空凭据引用(免 key 形态不得落盘)`);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
167
412
|
|
|
168
413
|
/**
|
|
169
414
|
* 校验后经 configEditor 写入(CFG-004)。非法输入在写入前即抛错;
|
|
170
415
|
* 宿主保存失败抛 ConfigError(CONFIG_SAVE_FAILED),已生效快照不变。
|
|
171
416
|
* editor.edit 第二参为变异函数 (raw, inherited) => newRawLayer,返回新 raw 整体对象落该行 override 层。
|
|
172
417
|
* 注意:SAVE_FAILED 错误不附宿主 cause(宿主报错可能回显被拒负载,含明文 key,CFG-003)。
|
|
418
|
+
* #87:fetch 三键懒持久化(FT-003#4/FT-007#3)——输入未触碰 fetch 面时不落三新键、保留既有盘值;
|
|
419
|
+
* 触碰则以规范化值覆写(secret 已剥)。
|
|
173
420
|
*/
|
|
174
421
|
export async function writeConfig(settings, next) {
|
|
175
|
-
const
|
|
422
|
+
const input = structuredClone(next ?? {});
|
|
423
|
+
checkFetchWriteGate(input);
|
|
424
|
+
const normalized = normalizeConfig(input);
|
|
176
425
|
try {
|
|
177
426
|
await settings.editor.edit(settings.entry, (raw) => {
|
|
178
427
|
const merged = { ...(raw ?? {}) };
|
|
179
428
|
for (const k of OWN_CONFIG_KEYS) delete merged[k];
|
|
180
|
-
|
|
429
|
+
// #88 第二批② + 二次整改 P0-A(Refs #88):清理必须作用于**最终待写结构**(含 normalized 面)——
|
|
430
|
+
// normalizeEntry 只跳 legacy SECRET_FIELD,条目未知标量(globalProxyUrl 等)会经 normalized.entries
|
|
431
|
+
// 透传写回(readConfig→writeConfig round-trip 保留明文);故对 merged∪normalized 的最终文档整体
|
|
432
|
+
// 递归剥离闭集(合法顶层 globalProxy 引用形态豁免),再对清理后最终有效态过读闸(违规即抛、
|
|
433
|
+
// 宿主拒绝、已生效配置不变)。PX-009 的降级保留故事只对非 secret 未知键成立。
|
|
434
|
+
// #87:输入未携带的 fetch 键不写回(FT-007#3 未触碰零新键落盘)。
|
|
435
|
+
// #87(sol-87b 批2① lead 裁决):输入省略 ≠ 删除——输入未携带的 fetch 键 = 沿用既有盘值
|
|
436
|
+
// (CFG-004「未携带键条件化省略是输出面语义,不是删除指令」;对齐 #88 globalProxy 键的
|
|
437
|
+
// 合并面先例)。normalize 输出条件化(未携带键不进输出)与合并面解耦:finalDoc =
|
|
438
|
+
// merged∪normalized,输入未触碰 fetch 面 → normalized 无三键 → merged 的盘值天然留存;
|
|
439
|
+
// FT-007#3 未触碰零新键落盘仍成立(盘上无既有值且输入未携带 → 不产生新键);
|
|
440
|
+
// 输入显式携带值 → 以规范化值覆写。键级删除不经 writeConfig(宿主 editor raw 层面)。
|
|
441
|
+
const finalDoc = { ...merged, ...structuredClone(normalized) };
|
|
442
|
+
const cleaned = stripSecretClosure(finalDoc);
|
|
443
|
+
normalizeConfig(structuredClone(cleaned));
|
|
444
|
+
return cleaned;
|
|
181
445
|
});
|
|
182
446
|
} catch {
|
|
183
447
|
throw new ConfigError(CONFIG_CODES.SAVE_FAILED, "保存搜索配置失败,已生效配置保持不变");
|
package/src/constants.js
CHANGED
|
@@ -59,6 +59,14 @@ export const ENTRY_CODES = Object.freeze({
|
|
|
59
59
|
CONTENT_POLICY: "ENTRY_CONTENT_POLICY",
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* #87 fetch 面条目级码(不入 ENTRY_CODES:FB-005 钉搜索链条目级分类恰八类,P1-3 深比对同值面)。
|
|
64
|
+
* 条目级预供应商闸拒绝(字面段/dns 命中;loopback 族允许官方腿兜底,其余不兜底)。
|
|
65
|
+
*/
|
|
66
|
+
export const FETCH_ENTRY_CODES = Object.freeze({
|
|
67
|
+
BLOCKED_URL: "ENTRY_BLOCKED_URL",
|
|
68
|
+
});
|
|
69
|
+
|
|
62
70
|
/** FB-001 跳过诊断标记(非失败分类)。 */
|
|
63
71
|
export const SKIPPED_NO_KEY = "SKIPPED_NO_KEY";
|
|
64
72
|
|
|
@@ -83,8 +91,42 @@ export const CONFIG_CODES = Object.freeze({
|
|
|
83
91
|
ROW_UNAVAILABLE: "CONFIG_ROW_UNAVAILABLE",
|
|
84
92
|
});
|
|
85
93
|
|
|
94
|
+
// ─── fetch 接管面(#87,FT-001..FT-009)──────────────────────────────────────────────
|
|
95
|
+
// 常量三镜同步:本文件(运行时)↔ test/helpers/contract.js(oracle 镜像)↔ src/client-entry.js(浏览器镜像)。
|
|
96
|
+
|
|
97
|
+
/** FT-009 首期 fetch 类型(OQ-O8 命名由 oracle 骨架锁定:FETCH_TOOL_TYPES)。 */
|
|
98
|
+
export const FETCH_TOOL_TYPES = Object.freeze(["tavily-extract"]);
|
|
99
|
+
|
|
100
|
+
/** CFG-002 fetch 面:类型 → 凭据环境变量(与 tavily 搜索共用 TAVILY_API_KEY,已在 TRUSTED_ENV_KEYS 白名单内)。 */
|
|
101
|
+
export const FETCH_KEY_ENV_BY_TYPE = Object.freeze({ "tavily-extract": "TAVILY_API_KEY" });
|
|
102
|
+
|
|
103
|
+
/** FT-003 三键:缺省即默认(normalizeConfig 内存补齐;writeConfig 懒持久化,仅输入触碰 fetch 面才落盘)。 */
|
|
104
|
+
export const FETCH_CONFIG_KEYS = Object.freeze(["fetchTakeover", "fetchEntries", "fetchOfficialFallback"]);
|
|
105
|
+
|
|
106
|
+
/** FT-002#4/FT-004 面终码(OQ-O5;「全部条目禁用」按 FB-004 口径复用 CHAIN_CODES.NOT_CONFIGURED,不另设码)。 */
|
|
107
|
+
export const FETCH_CODES = Object.freeze({
|
|
108
|
+
NO_ENTRIES: "FETCH_NO_ENTRIES", // fetchEntries 为空(开关开但无任何条目)
|
|
109
|
+
KEY_MISSING: "FETCH_KEY_MISSING", // 存在启用条目但全链无可解析 key
|
|
110
|
+
CONFIG: "FETCH_CONFIG", // 执行期发现 fetch 面形状非法
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/** 宿主 WebError 终码族(PR #104 gate2 分族;先例 = dsh-web / dsh-web-fetch-http policy 实证)。 */
|
|
114
|
+
export const WEB_CODES = Object.freeze({
|
|
115
|
+
INVALID_URL: "WEB_INVALID_URL", // 形态错误族:空 host / parse 失败 / 超长 >2048
|
|
116
|
+
BLOCKED_URL: "WEB_BLOCKED_URL", // 策略拒绝族:非 http(s) scheme / SSRF 段 / 内嵌凭据
|
|
117
|
+
FETCH_TIMEOUT: "WEB_FETCH_TIMEOUT", // 总预算超时唯一码(OQ-O4 裁决 = 宿主先例码)
|
|
118
|
+
ABORTED: "WEB_ABORTED", // 宿主取消
|
|
119
|
+
PROVIDER_ERROR: "WEB_PROVIDER_ERROR", // 官方腿网络/协议失败(asar provider.ts 实证码)
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/** 宿主首 URL 预闸(dsh-web-fetch-http policy 实证 WEB_FETCH_MAX_URL_LENGTH)。 */
|
|
123
|
+
export const FETCH_URL_MAX_LENGTH = 2048;
|
|
124
|
+
|
|
125
|
+
/** 宿主官方 WEB_FETCH_MAX_BODY_CHARS 实证值:正文字符上限(截断,truncated 置位)。 */
|
|
126
|
+
export const FETCH_MAX_BODY_CHARS = 100_000;
|
|
127
|
+
|
|
86
128
|
/**
|
|
87
|
-
* 响应体字节上限(PAC
|
|
129
|
+
* 响应体字节上限(PAC 下载、六家供应商正文与 fetch 面提取商响应的跨模块单源;BING-002 先例同值 2MiB)。
|
|
88
130
|
* 超限即 reader.cancel 早停,不读满全量(见下方 readBoundedText)。修改须同步 test/body-size-cap.test.js 的 MAX_EXPECTED。
|
|
89
131
|
*/
|
|
90
132
|
export const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
@@ -92,6 +134,22 @@ export const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
|
92
134
|
/** FB-003 默认总预算(毫秒)。 */
|
|
93
135
|
export const DEFAULT_TIMEOUT_MS = 25000;
|
|
94
136
|
|
|
137
|
+
/**
|
|
138
|
+
* POOL-001/003(#86 多 key 池轮替):单条目凭据池(credentialRefs)上限(lead 审阅批准)。
|
|
139
|
+
* 镜像同步义务:src/settings/catalog.js、src/client-entry.js 内联镜像、test/helpers/contract.js。
|
|
140
|
+
*/
|
|
141
|
+
export const POOL_MAX = 8;
|
|
142
|
+
|
|
143
|
+
/** PX-006 条目级 proxyPin 三态枚举(与 test/helpers/contract.js、src/settings/catalog.js 同步)。 */
|
|
144
|
+
export const PROXY_PINS = Object.freeze({
|
|
145
|
+
INHERIT: "inherit",
|
|
146
|
+
DIRECT_ONLY: "directOnly",
|
|
147
|
+
PROXY_ONLY: "proxyOnly",
|
|
148
|
+
});
|
|
149
|
+
export const PROXY_PIN_VALUES = Object.freeze(Object.values(PROXY_PINS));
|
|
150
|
+
/** PX-001 默认全局代理凭据引用名(POSIX 标识符)。 */
|
|
151
|
+
export const DEFAULT_GLOBAL_PROXY_REF = "search_chain_global_proxy";
|
|
152
|
+
|
|
95
153
|
/** 传输层释放语义码(src/transport.js fetch() 的 closed 分支)。 */
|
|
96
154
|
export const TRANSPORT_CODES = Object.freeze({
|
|
97
155
|
RELEASED: "TRANSPORT_RELEASED",
|
|
@@ -112,6 +170,30 @@ export function carriesPassthroughCode(err) {
|
|
|
112
170
|
return typeof err?.code === "string" && PASSTHROUGH_CODE_VALUES.has(err.code);
|
|
113
171
|
}
|
|
114
172
|
|
|
173
|
+
// #120 P1-1(sol 终评 · PR #126):相位归属标记——PX-004「仅建连相位可改道」在真实网络面
|
|
174
|
+
// fail-closed:无「可证请求未写出」证据的 fetch 拒绝/正文读取失败,一律标记 post-connect
|
|
175
|
+
// (不可改道)。带显式码的合成台架/后端建连族错误保持无标记=沿用既有可改道码契约。
|
|
176
|
+
// 触发收敛面 src/search.js;标记来源=transport.mapFetchError、exa/bing 正文读取处、
|
|
177
|
+
// createProductionFetch 卸载拒绝处。Symbol.for:跨模块单例(零新增运行时 import 环)。
|
|
178
|
+
export const POST_CONNECT_PHASE = Symbol.for("dsh-fleetseek.postConnectPhase");
|
|
179
|
+
|
|
180
|
+
/** 标记错误为「建连相位之后/不可证相位」——失败归因不变,仅剥夺改道资格。 */
|
|
181
|
+
export function markPostConnectPhase(err) {
|
|
182
|
+
if (err && typeof err === "object") {
|
|
183
|
+
try {
|
|
184
|
+
Object.defineProperty(err, POST_CONNECT_PHASE, { value: true, configurable: true });
|
|
185
|
+
} catch {
|
|
186
|
+
/* 冻结对象无法标记:上层按「拿不准=不升级」的 fail-closed 判定由标记缺失方默认放行,
|
|
187
|
+
本仓库受控抛错面不存在冻结错误对象;出现即为程序违约,交由既有测试面暴露。 */
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return err;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function isPostConnectPhase(err) {
|
|
194
|
+
return Boolean(err) && typeof err === "object" && err[POST_CONNECT_PHASE] === true;
|
|
195
|
+
}
|
|
196
|
+
|
|
115
197
|
// ─── 响应体有界读取(PAC 与六家正文共用;BING-002 先例)────────────────────────────────────
|
|
116
198
|
// 流式主路超限即 reader.cancel 早停(tooLarge),退化路只能读后判长。超限不是异常:调用方据 tooLarge 归类。
|
|
117
199
|
// 放在 constants.js 而非独立模块:staging 测试只复制 backends/<name>.js 与 constants.js(见 classifier-*.test.js)。
|
|
@@ -166,3 +248,69 @@ export function bodyTooLargeMessage(limit) {
|
|
|
166
248
|
function utf8ByteLength(text) {
|
|
167
249
|
return new TextEncoder().encode(text).byteLength;
|
|
168
250
|
}
|
|
251
|
+
|
|
252
|
+
// ─────────────── 统一 secret 字段名闭集(读写闸/清理/保留面共享;Refs #88 #86;§7 合并合同②单源) ───────────────
|
|
253
|
+
// 递归清零依据:按字段名闭集匹配,不做值形态扫描(不按 URL/凭据形状猜值,避免误伤用户数据;
|
|
254
|
+
// 边界如实记录于 docs/specs/draft/config-write-gate.md PX 修订注)。
|
|
255
|
+
// 注册单元(单一事实源 = 本闭集,writeConfig / normalizeEntry 保留面 / finalizeOps / client-entry
|
|
256
|
+
// 两镜像 stripSecrets 全部引用同一判定):
|
|
257
|
+
// ① legacy secret 八名族(#86 stripSecrets 注册点,CFG-W-003,POOL 侧确认「闭集无需新增字段名」);
|
|
258
|
+
// ② globalProxy 字段名族(#88 全局代理明文;唯一豁免 = 精确键 globalProxy 持 POSIX 引用名)。
|
|
259
|
+
// #87 fetch key 明文族(§7-①):fetchEntries 条目的 apiKey/api_key/key/secret/token/password/auth/authorization 字段与 legacy 八名族正则完全同形——注册为单位①的同名单元,无需追加正则;client-entry 两镜像 isSecretClosureKey 同步判定(零 import 约束下的镜像义务)。
|
|
260
|
+
const SECRET_KEY_LEGACY = /^(apikey|api_key|key|secret|token|password|auth|authorization)$/i;
|
|
261
|
+
const GLOBAL_PROXY_KEY = /^globalproxy/i;
|
|
262
|
+
const POSIX_CREDENTIAL_REF = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
263
|
+
|
|
264
|
+
export const SECRET_KEY_CLOSURE = Object.freeze([SECRET_KEY_LEGACY, GLOBAL_PROXY_KEY]);
|
|
265
|
+
|
|
266
|
+
export function isSecretClosureKey(key) {
|
|
267
|
+
return SECRET_KEY_CLOSURE.some((re) => re.test(String(key)));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** 合法形态豁免:唯一合法键 globalProxy(精确名)持 POSIX 凭据引用名(引用存放合法、明文不合法)。
|
|
271
|
+
* 导出:闭集豁免语义是共享 helper 契约面(#86/#87 注册同名单元时同口径引用)。 */
|
|
272
|
+
export function isLegitGlobalProxyRef(key, value) {
|
|
273
|
+
return (
|
|
274
|
+
String(key).toLowerCase() === "globalproxy" &&
|
|
275
|
+
typeof value === "string" &&
|
|
276
|
+
value.trim() !== "" &&
|
|
277
|
+
POSIX_CREDENTIAL_REF.test(value.trim())
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* 递归收集 user 层(任意深度、任意位置)命中 secret 闭集的字段路径。
|
|
283
|
+
* 路径段:对象键原样、数组下标字符串化(与 ops path 形态一致)。
|
|
284
|
+
* 数组元素本身不作键匹配(下标不是字段名);仅递归进入嵌套对象/数组。
|
|
285
|
+
*/
|
|
286
|
+
export function secretClosurePaths(value, path = [], out = []) {
|
|
287
|
+
if (value === null || typeof value !== "object") return out;
|
|
288
|
+
if (Array.isArray(value)) {
|
|
289
|
+
for (let i = 0; i < value.length; i++) secretClosurePaths(value[i], [...path, String(i)], out);
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
for (const [k, v] of Object.entries(value)) {
|
|
293
|
+
const p = [...path, k];
|
|
294
|
+
if (isSecretClosureKey(k) && !isLegitGlobalProxyRef(k, v)) {
|
|
295
|
+
// 第六批(Refs #88):命中即将删除的父键→只输出父路径、不扫后代——父+子双 unset 会让
|
|
296
|
+
// apply 在子条上重建已删父键(extra/password 清不掉;globalProxy={password:…} 先删后建 {}
|
|
297
|
+
// 致终检抛错堵死保存)。与 stripSecretClosure 同口径,保证 ops 应用结果与剥离结果相等。
|
|
298
|
+
out.push(p);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (v !== null && typeof v === "object") secretClosurePaths(v, p, out);
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** 递归剥离 secret 闭集命中字段(任意深度),返回新结构(writeConfig 保留面;Refs #88 第二批②)。 */
|
|
307
|
+
export function stripSecretClosure(value) {
|
|
308
|
+
if (value === null || typeof value !== "object") return value;
|
|
309
|
+
if (Array.isArray(value)) return value.map((v) => stripSecretClosure(v));
|
|
310
|
+
const out = {};
|
|
311
|
+
for (const [k, v] of Object.entries(value)) {
|
|
312
|
+
if (isSecretClosureKey(k) && !isLegitGlobalProxyRef(k, v)) continue;
|
|
313
|
+
out[k] = stripSecretClosure(v);
|
|
314
|
+
}
|
|
315
|
+
return out;
|
|
316
|
+
}
|