dsh-context-compression-improved 0.7.0-beta.1 → 0.7.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.github/workflows/ci.yml +39 -39
  2. package/CHANGELOG.ja.md +217 -220
  3. package/CHANGELOG.ko.md +211 -214
  4. package/CHANGELOG.md +392 -376
  5. package/CHANGELOG.zh.md +196 -199
  6. package/README.md +97 -97
  7. package/README.zh.md +86 -86
  8. package/package.json +18 -17
  9. package/packages/selector/dsh.plugin.json +1 -1
  10. package/packages/selector/lib/client.js +733 -0
  11. package/packages/selector/lib/style.css +46 -46
  12. package/packages/selector/src/client/decode.ts +53 -53
  13. package/packages/selector/src/client/index.ts +30 -0
  14. package/packages/selector/src/client/locales/de.ts +98 -0
  15. package/packages/selector/src/client/locales/es.ts +98 -0
  16. package/packages/selector/src/client/locales/fr.ts +98 -0
  17. package/packages/selector/src/client/locales/it.ts +98 -0
  18. package/packages/selector/src/client/locales/ja.ts +98 -0
  19. package/packages/selector/src/client/locales/ko.ts +98 -0
  20. package/packages/selector/src/client/locales/ru.ts +98 -0
  21. package/packages/selector/src/deepseek-v4-tokenizer.ts +205 -205
  22. package/packages/selector/src/preset-overlay.ts +629 -629
  23. package/packages/selector/src/profiles.ts +414 -414
  24. package/packages/selector/src/pruner/content.ts +198 -198
  25. package/packages/selector/src/pruner/state.ts +57 -57
  26. package/packages/selector/src/pruner.ts +2665 -2665
  27. package/packages/selector/src/runtime/audit.ts +303 -303
  28. package/packages/selector/src/runtime/config.ts +731 -731
  29. package/packages/selector/src/runtime/reducers.ts +1674 -1674
  30. package/packages/selector/src/runtime/summary-command.ts +133 -133
  31. package/packages/selector/src/runtime/tokenpilot/advisor-prompt.ts +233 -233
  32. package/packages/selector/src/runtime/tokenpilot/advisor-state.ts +204 -204
  33. package/packages/selector/src/runtime/tokenpilot/intent-fold.ts +53 -53
  34. package/packages/selector/src/runtime/tokenpilot/intent-gate.ts +65 -65
  35. package/packages/selector/src/runtime/tokenpilot/intent-input-mask.ts +125 -125
  36. package/packages/selector/src/runtime/tokenpilot/intent-range.ts +37 -37
  37. package/packages/selector/src/runtime/tokenpilot/locator.ts +128 -128
  38. package/packages/selector/src/runtime/tokenpilot/sidechannel.ts +306 -306
  39. package/packages/selector/src/runtime/types.ts +358 -358
  40. package/packages/selector/tests/built/client-artifact.spec.ts +61 -61
  41. package/packages/selector/tests/helpers/legacy-settings/index.ts +15 -15
  42. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.d.ts +41 -41
  43. package/packages/selector/tests/helpers/legacy-settings/legacy/provider.js +647 -647
  44. package/packages/selector/tests/helpers/legacy-settings/legacy/redact.js +78 -78
  45. package/packages/selector/tests/helpers/legacy-settings/legacy/util-values.js +234 -234
  46. package/packages/selector/tests/host-preset-overlay.host.spec.ts +203 -203
  47. package/packages/selector/tests/runtime/auto-compact-config.spec.ts +523 -523
  48. package/packages/selector/tests/runtime/deepseek-v4-tokenizer.spec.ts +122 -122
  49. package/packages/selector/tests/runtime/intent-gate.spec.ts +62 -62
  50. package/packages/selector/tests/runtime/intent-summary.spec.ts +156 -156
  51. package/packages/selector/tests/runtime/summary-command.spec.ts +154 -154
  52. package/scripts/packed-components-smoke.mjs +734 -734
  53. package/tests/TEST_INVENTORY.md +41 -41
  54. package/tsconfig.tests.json +17 -17
  55. package/vitest.config.ts +57 -57
@@ -1,78 +1,78 @@
1
- /* Vendored verbatim from @deepseek-ai/<pkg> — third-party code, exempt from this repo's lint rules. */
2
- /**
3
- * Structural secret redaction for settings values. `role('secret')` fields are
4
- * removed from a value before it crosses a wire boundary; a sidecar records
5
- * each schema-declared secret position and whether it currently holds a value,
6
- * so a configuration surface can render a write-only input without ever
7
- * receiving the secret itself.
8
- * @module @deepseek-ai/dsh-settings/redact
9
- */
10
- /** Whether a value is a plain data object the walker may recurse into. */
11
- function isRecord(value) {
12
- return typeof value === 'object' && value !== null && !Array.isArray(value);
13
- }
14
- function walk(node, value, path, secrets) {
15
- if (node === undefined)
16
- return value;
17
- if (node.meta?.role === 'secret') {
18
- secrets.push({ path, set: value !== undefined });
19
- return undefined;
20
- }
21
- switch (node.type) {
22
- case 'object': {
23
- const properties = node.dict ?? {};
24
- const source = isRecord(value) ? value : undefined;
25
- const rebuilt = {};
26
- if (source !== undefined) {
27
- for (const [key, entry] of Object.entries(source)) {
28
- if (key in properties)
29
- continue;
30
- rebuilt[key] = entry;
31
- }
32
- }
33
- for (const [key, child] of Object.entries(properties)) {
34
- const stripped = walk(child, source?.[key], [...path, key], secrets);
35
- if (stripped !== undefined)
36
- rebuilt[key] = stripped;
37
- }
38
- return source === undefined && Object.keys(rebuilt).length === 0 ? value : rebuilt;
39
- }
40
- case 'dict': {
41
- if (!isRecord(value))
42
- return value;
43
- const rebuilt = {};
44
- for (const [key, entry] of Object.entries(value)) {
45
- const stripped = walk(node.inner, entry, [...path, key], secrets);
46
- if (stripped !== undefined)
47
- rebuilt[key] = stripped;
48
- }
49
- return rebuilt;
50
- }
51
- case 'array': {
52
- if (!Array.isArray(value))
53
- return value;
54
- return value.map((entry, index) => walk(node.inner, entry, [...path, String(index)], secrets));
55
- }
56
- default:
57
- // TODO(settings-wire-redaction): Fail closed instead — a secret reachable
58
- // only through a union, intersection, or transform is returned verbatim
59
- // here, with nothing recording that it was missed.
60
- return value;
61
- }
62
- }
63
- /**
64
- * Remove every `role('secret')` field a schema declares from a value. The
65
- * walker follows `object`, `dict`, and `array` containers; a secret must be
66
- * declared directly on a field reachable through those containers (a secret
67
- * buried inside a union branch or transform is not reachable and must not be
68
- * modeled that way). The input is never mutated.
69
- * @param schema - live schemastery schema describing the value.
70
- * @param value - the value to strip; `undefined` yields an empty record with
71
- * object-property secret slots still enumerated.
72
- * @returns the stripped detached value and the ordered secret positions.
73
- */
74
- export function redactSecrets(schema, value) {
75
- const secrets = [];
76
- const stripped = walk(schema, value, [], secrets);
77
- return { value: stripped, secrets };
78
- }
1
+ /* Vendored verbatim from @deepseek-ai/<pkg> — third-party code, exempt from this repo's lint rules. */
2
+ /**
3
+ * Structural secret redaction for settings values. `role('secret')` fields are
4
+ * removed from a value before it crosses a wire boundary; a sidecar records
5
+ * each schema-declared secret position and whether it currently holds a value,
6
+ * so a configuration surface can render a write-only input without ever
7
+ * receiving the secret itself.
8
+ * @module @deepseek-ai/dsh-settings/redact
9
+ */
10
+ /** Whether a value is a plain data object the walker may recurse into. */
11
+ function isRecord(value) {
12
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
13
+ }
14
+ function walk(node, value, path, secrets) {
15
+ if (node === undefined)
16
+ return value;
17
+ if (node.meta?.role === 'secret') {
18
+ secrets.push({ path, set: value !== undefined });
19
+ return undefined;
20
+ }
21
+ switch (node.type) {
22
+ case 'object': {
23
+ const properties = node.dict ?? {};
24
+ const source = isRecord(value) ? value : undefined;
25
+ const rebuilt = {};
26
+ if (source !== undefined) {
27
+ for (const [key, entry] of Object.entries(source)) {
28
+ if (key in properties)
29
+ continue;
30
+ rebuilt[key] = entry;
31
+ }
32
+ }
33
+ for (const [key, child] of Object.entries(properties)) {
34
+ const stripped = walk(child, source?.[key], [...path, key], secrets);
35
+ if (stripped !== undefined)
36
+ rebuilt[key] = stripped;
37
+ }
38
+ return source === undefined && Object.keys(rebuilt).length === 0 ? value : rebuilt;
39
+ }
40
+ case 'dict': {
41
+ if (!isRecord(value))
42
+ return value;
43
+ const rebuilt = {};
44
+ for (const [key, entry] of Object.entries(value)) {
45
+ const stripped = walk(node.inner, entry, [...path, key], secrets);
46
+ if (stripped !== undefined)
47
+ rebuilt[key] = stripped;
48
+ }
49
+ return rebuilt;
50
+ }
51
+ case 'array': {
52
+ if (!Array.isArray(value))
53
+ return value;
54
+ return value.map((entry, index) => walk(node.inner, entry, [...path, String(index)], secrets));
55
+ }
56
+ default:
57
+ // TODO(settings-wire-redaction): Fail closed instead — a secret reachable
58
+ // only through a union, intersection, or transform is returned verbatim
59
+ // here, with nothing recording that it was missed.
60
+ return value;
61
+ }
62
+ }
63
+ /**
64
+ * Remove every `role('secret')` field a schema declares from a value. The
65
+ * walker follows `object`, `dict`, and `array` containers; a secret must be
66
+ * declared directly on a field reachable through those containers (a secret
67
+ * buried inside a union branch or transform is not reachable and must not be
68
+ * modeled that way). The input is never mutated.
69
+ * @param schema - live schemastery schema describing the value.
70
+ * @param value - the value to strip; `undefined` yields an empty record with
71
+ * object-property secret slots still enumerated.
72
+ * @returns the stripped detached value and the ordered secret positions.
73
+ */
74
+ export function redactSecrets(schema, value) {
75
+ const secrets = [];
76
+ const stripped = walk(schema, value, [], secrets);
77
+ return { value: stripped, secrets };
78
+ }
@@ -1,234 +1,234 @@
1
- /* Vendored verbatim from @deepseek-ai/<pkg> — third-party code, exempt from this repo's lint rules. */
2
- /* eslint-disable */
3
- //#region lib/types/index.js
4
- /** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
5
- /**
6
- * Mark an unreachable closed-union branch.
7
- * @param value - impossible value; an unhandled typed variant fails at the call site.
8
- * @param context - optional switch-site label included in the failure message.
9
- * @returns never; a runtime value that escaped its type always throws.
10
- */
11
- function assertNever(value, context) {
12
- const rendered = JSON.stringify(value) ?? String(value);
13
- throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
14
- }
15
- /** Whether a realm-owned intrinsic prototype is backed by its native constructor. */
16
- function hasIntrinsicConstructor(prototype, name) {
17
- const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
18
- if (typeof constructor !== "function") return false;
19
- try {
20
- return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`;
21
- } catch {
22
- return false;
23
- }
24
- }
25
- /** Whether a candidate is one realm's intrinsic `Object.prototype`. */
26
- function isIntrinsicObjectPrototype(value) {
27
- return Object.getPrototypeOf(value) === null && hasIntrinsicConstructor(value, "Object");
28
- }
29
- /** Whether an array uses one realm's intrinsic `Array.prototype`, not a subclass or forged prototype. */
30
- function hasPlainArrayPrototype(value) {
31
- const prototype = Object.getPrototypeOf(value);
32
- if (!Array.isArray(prototype) || !hasIntrinsicConstructor(prototype, "Array")) return false;
33
- const objectPrototype = Object.getPrototypeOf(prototype);
34
- return typeof objectPrototype === "object" && objectPrototype !== null && isIntrinsicObjectPrototype(objectPrototype);
35
- }
36
- /** Whether an object is a plain or null-prototype record from any JavaScript realm. */
37
- function hasPlainObjectPrototype(value) {
38
- const prototype = Object.getPrototypeOf(value);
39
- return prototype === null || typeof prototype === "object" && isIntrinsicObjectPrototype(prototype);
40
- }
41
- /** Return every JSON-visible object key, or reject own data JSON would discard. */
42
- function enumerableStringKeys(value) {
43
- const keys = Reflect.ownKeys(value);
44
- if (keys.some((key) => typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key))) return void 0;
45
- return keys;
46
- }
47
- /** Validate lossless JSON iteratively, optionally materializing a detached snapshot. */
48
- function walkJsonValue(value, detach) {
49
- const ancestors = /* @__PURE__ */ new Set();
50
- let root;
51
- const assign = (destination, item) => {
52
- if (destination === void 0) return;
53
- if (destination.kind === "root") root = item;
54
- else if (destination.kind === "array") destination.target[destination.index] = item;
55
- else Object.defineProperty(destination.target, destination.key, {
56
- value: item,
57
- enumerable: true,
58
- configurable: true,
59
- writable: true
60
- });
61
- };
62
- const tasks = [{
63
- kind: "visit",
64
- value,
65
- ...detach ? { destination: { kind: "root" } } : {}
66
- }];
67
- for (let task = tasks.pop(); task !== void 0; task = tasks.pop()) {
68
- if (task.kind === "leave") {
69
- ancestors.delete(task.source);
70
- continue;
71
- }
72
- if (task.kind === "array-item") {
73
- if (!Object.prototype.hasOwnProperty.call(task.source, task.index)) return void 0;
74
- tasks.push({
75
- kind: "visit",
76
- value: task.source[task.index],
77
- ...task.target === void 0 ? {} : { destination: {
78
- kind: "array",
79
- target: task.target,
80
- index: task.index
81
- } }
82
- });
83
- continue;
84
- }
85
- if (task.kind === "object-property") {
86
- tasks.push({
87
- kind: "visit",
88
- value: task.source[task.key],
89
- ...task.target === void 0 ? {} : { destination: {
90
- kind: "object",
91
- target: task.target,
92
- key: task.key
93
- } }
94
- });
95
- continue;
96
- }
97
- const current = task.value;
98
- if (current === null) {
99
- assign(task.destination, null);
100
- continue;
101
- }
102
- if (typeof current === "boolean" || typeof current === "string") {
103
- assign(task.destination, current);
104
- continue;
105
- }
106
- if (typeof current === "number") {
107
- if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
108
- assign(task.destination, current);
109
- continue;
110
- }
111
- if (typeof current !== "object") return void 0;
112
- if (ancestors.has(current)) return void 0;
113
- if (Array.isArray(current)) {
114
- if (!hasPlainArrayPrototype(current)) return void 0;
115
- const length = current.length;
116
- if (Reflect.ownKeys(current).length !== length + 1) return void 0;
117
- const target = detach ? [] : void 0;
118
- if (target !== void 0) assign(task.destination, target);
119
- ancestors.add(current);
120
- tasks.push({
121
- kind: "leave",
122
- source: current
123
- });
124
- for (let index = length - 1; index >= 0; index--) tasks.push({
125
- kind: "array-item",
126
- source: current,
127
- index,
128
- ...target === void 0 ? {} : { target }
129
- });
130
- continue;
131
- }
132
- if (!hasPlainObjectPrototype(current)) return void 0;
133
- const keys = enumerableStringKeys(current);
134
- if (keys === void 0) return void 0;
135
- const target = detach ? {} : void 0;
136
- if (target !== void 0) assign(task.destination, target);
137
- ancestors.add(current);
138
- tasks.push({
139
- kind: "leave",
140
- source: current
141
- });
142
- for (let index = keys.length - 1; index >= 0; index--) {
143
- const key = keys[index];
144
- /* v8 ignore next -- the loop is bounded by the captured key count. */
145
- if (key === void 0) return void 0;
146
- tasks.push({
147
- kind: "object-property",
148
- source: current,
149
- key,
150
- ...target === void 0 ? {} : { target }
151
- });
152
- }
153
- }
154
- return detach ? root : true;
155
- }
156
- /**
157
- * Validate and detach lossless JSON in one read per property.
158
- * @param value - candidate value to validate and detach.
159
- * @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
160
- */
161
- function snapshotJsonValue(value) {
162
- return walkJsonValue(value, true);
163
- }
164
- /**
165
- * Test the same lossless JSON rules as {@link snapshotJsonValue} without detaching the value.
166
- * @param value - candidate value to test.
167
- * @returns whether the value survives a JSON round trip without loss.
168
- */
169
- function isJsonValue(value) {
170
- return walkJsonValue(value, false) === true;
171
- }
172
- /**
173
- * Compare JSON-compatible values structurally.
174
- * @param a - one JSON-compatible value.
175
- * @param b - the other JSON-compatible value.
176
- * @returns whether both values contain the same JSON data.
177
- */
178
- function deepEqualJson(a, b) {
179
- if (a === b) return true;
180
- if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
181
- if (Array.isArray(a) || Array.isArray(b)) {
182
- if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
183
- return a.every((entry, index) => deepEqualJson(entry, b[index]));
184
- }
185
- const left = a;
186
- const right = b;
187
- const keys = Object.keys(left);
188
- if (keys.length !== Object.keys(right).length) return false;
189
- return keys.every((key) => key in right && deepEqualJson(left[key], right[key]));
190
- }
191
- /**
192
- * Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
193
- * @param value - value to freeze.
194
- * @returns the same value after every reachable enumerable child is frozen.
195
- */
196
- function deepFreeze(value) {
197
- const seen = /* @__PURE__ */ new WeakSet();
198
- const pending = [{
199
- kind: "visit",
200
- node: value
201
- }];
202
- while (pending.length > 0) {
203
- const task = pending.pop();
204
- /* v8 ignore next -- the loop condition guarantees one pending task. */
205
- if (task === void 0) continue;
206
- if (task.kind === "property") {
207
- pending.push({
208
- kind: "visit",
209
- node: task.source[task.key]
210
- });
211
- continue;
212
- }
213
- const node = task.node;
214
- if (node === null || typeof node !== "object") continue;
215
- if (node instanceof AbortSignal) continue;
216
- if (seen.has(node)) continue;
217
- seen.add(node);
218
- Object.freeze(node);
219
- const keys = Object.keys(node);
220
- for (let index = keys.length - 1; index >= 0; index--) {
221
- const key = keys[index];
222
- /* v8 ignore next -- the loop is bounded by the captured key count. */
223
- if (key === void 0) continue;
224
- pending.push({
225
- kind: "property",
226
- source: node,
227
- key
228
- });
229
- }
230
- }
231
- return value;
232
- }
233
- //#endregion
234
- export { assertNever, deepEqualJson, deepFreeze, isJsonValue, snapshotJsonValue };
1
+ /* Vendored verbatim from @deepseek-ai/<pkg> — third-party code, exempt from this repo's lint rules. */
2
+ /* eslint-disable */
3
+ //#region lib/types/index.js
4
+ /** Duplicate-install-safe JSON and immutable-value helpers. @module @deepseek-ai/dsh-util-values */
5
+ /**
6
+ * Mark an unreachable closed-union branch.
7
+ * @param value - impossible value; an unhandled typed variant fails at the call site.
8
+ * @param context - optional switch-site label included in the failure message.
9
+ * @returns never; a runtime value that escaped its type always throws.
10
+ */
11
+ function assertNever(value, context) {
12
+ const rendered = JSON.stringify(value) ?? String(value);
13
+ throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
14
+ }
15
+ /** Whether a realm-owned intrinsic prototype is backed by its native constructor. */
16
+ function hasIntrinsicConstructor(prototype, name) {
17
+ const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
18
+ if (typeof constructor !== "function") return false;
19
+ try {
20
+ return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+ /** Whether a candidate is one realm's intrinsic `Object.prototype`. */
26
+ function isIntrinsicObjectPrototype(value) {
27
+ return Object.getPrototypeOf(value) === null && hasIntrinsicConstructor(value, "Object");
28
+ }
29
+ /** Whether an array uses one realm's intrinsic `Array.prototype`, not a subclass or forged prototype. */
30
+ function hasPlainArrayPrototype(value) {
31
+ const prototype = Object.getPrototypeOf(value);
32
+ if (!Array.isArray(prototype) || !hasIntrinsicConstructor(prototype, "Array")) return false;
33
+ const objectPrototype = Object.getPrototypeOf(prototype);
34
+ return typeof objectPrototype === "object" && objectPrototype !== null && isIntrinsicObjectPrototype(objectPrototype);
35
+ }
36
+ /** Whether an object is a plain or null-prototype record from any JavaScript realm. */
37
+ function hasPlainObjectPrototype(value) {
38
+ const prototype = Object.getPrototypeOf(value);
39
+ return prototype === null || typeof prototype === "object" && isIntrinsicObjectPrototype(prototype);
40
+ }
41
+ /** Return every JSON-visible object key, or reject own data JSON would discard. */
42
+ function enumerableStringKeys(value) {
43
+ const keys = Reflect.ownKeys(value);
44
+ if (keys.some((key) => typeof key !== "string" || !Object.prototype.propertyIsEnumerable.call(value, key))) return void 0;
45
+ return keys;
46
+ }
47
+ /** Validate lossless JSON iteratively, optionally materializing a detached snapshot. */
48
+ function walkJsonValue(value, detach) {
49
+ const ancestors = /* @__PURE__ */ new Set();
50
+ let root;
51
+ const assign = (destination, item) => {
52
+ if (destination === void 0) return;
53
+ if (destination.kind === "root") root = item;
54
+ else if (destination.kind === "array") destination.target[destination.index] = item;
55
+ else Object.defineProperty(destination.target, destination.key, {
56
+ value: item,
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true
60
+ });
61
+ };
62
+ const tasks = [{
63
+ kind: "visit",
64
+ value,
65
+ ...detach ? { destination: { kind: "root" } } : {}
66
+ }];
67
+ for (let task = tasks.pop(); task !== void 0; task = tasks.pop()) {
68
+ if (task.kind === "leave") {
69
+ ancestors.delete(task.source);
70
+ continue;
71
+ }
72
+ if (task.kind === "array-item") {
73
+ if (!Object.prototype.hasOwnProperty.call(task.source, task.index)) return void 0;
74
+ tasks.push({
75
+ kind: "visit",
76
+ value: task.source[task.index],
77
+ ...task.target === void 0 ? {} : { destination: {
78
+ kind: "array",
79
+ target: task.target,
80
+ index: task.index
81
+ } }
82
+ });
83
+ continue;
84
+ }
85
+ if (task.kind === "object-property") {
86
+ tasks.push({
87
+ kind: "visit",
88
+ value: task.source[task.key],
89
+ ...task.target === void 0 ? {} : { destination: {
90
+ kind: "object",
91
+ target: task.target,
92
+ key: task.key
93
+ } }
94
+ });
95
+ continue;
96
+ }
97
+ const current = task.value;
98
+ if (current === null) {
99
+ assign(task.destination, null);
100
+ continue;
101
+ }
102
+ if (typeof current === "boolean" || typeof current === "string") {
103
+ assign(task.destination, current);
104
+ continue;
105
+ }
106
+ if (typeof current === "number") {
107
+ if (!Number.isFinite(current) || Object.is(current, -0)) return void 0;
108
+ assign(task.destination, current);
109
+ continue;
110
+ }
111
+ if (typeof current !== "object") return void 0;
112
+ if (ancestors.has(current)) return void 0;
113
+ if (Array.isArray(current)) {
114
+ if (!hasPlainArrayPrototype(current)) return void 0;
115
+ const length = current.length;
116
+ if (Reflect.ownKeys(current).length !== length + 1) return void 0;
117
+ const target = detach ? [] : void 0;
118
+ if (target !== void 0) assign(task.destination, target);
119
+ ancestors.add(current);
120
+ tasks.push({
121
+ kind: "leave",
122
+ source: current
123
+ });
124
+ for (let index = length - 1; index >= 0; index--) tasks.push({
125
+ kind: "array-item",
126
+ source: current,
127
+ index,
128
+ ...target === void 0 ? {} : { target }
129
+ });
130
+ continue;
131
+ }
132
+ if (!hasPlainObjectPrototype(current)) return void 0;
133
+ const keys = enumerableStringKeys(current);
134
+ if (keys === void 0) return void 0;
135
+ const target = detach ? {} : void 0;
136
+ if (target !== void 0) assign(task.destination, target);
137
+ ancestors.add(current);
138
+ tasks.push({
139
+ kind: "leave",
140
+ source: current
141
+ });
142
+ for (let index = keys.length - 1; index >= 0; index--) {
143
+ const key = keys[index];
144
+ /* v8 ignore next -- the loop is bounded by the captured key count. */
145
+ if (key === void 0) return void 0;
146
+ tasks.push({
147
+ kind: "object-property",
148
+ source: current,
149
+ key,
150
+ ...target === void 0 ? {} : { target }
151
+ });
152
+ }
153
+ }
154
+ return detach ? root : true;
155
+ }
156
+ /**
157
+ * Validate and detach lossless JSON in one read per property.
158
+ * @param value - candidate value to validate and detach.
159
+ * @returns the detached snapshot, or `undefined` when the value is not losslessly JSON-serializable.
160
+ */
161
+ function snapshotJsonValue(value) {
162
+ return walkJsonValue(value, true);
163
+ }
164
+ /**
165
+ * Test the same lossless JSON rules as {@link snapshotJsonValue} without detaching the value.
166
+ * @param value - candidate value to test.
167
+ * @returns whether the value survives a JSON round trip without loss.
168
+ */
169
+ function isJsonValue(value) {
170
+ return walkJsonValue(value, false) === true;
171
+ }
172
+ /**
173
+ * Compare JSON-compatible values structurally.
174
+ * @param a - one JSON-compatible value.
175
+ * @param b - the other JSON-compatible value.
176
+ * @returns whether both values contain the same JSON data.
177
+ */
178
+ function deepEqualJson(a, b) {
179
+ if (a === b) return true;
180
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
181
+ if (Array.isArray(a) || Array.isArray(b)) {
182
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
183
+ return a.every((entry, index) => deepEqualJson(entry, b[index]));
184
+ }
185
+ const left = a;
186
+ const right = b;
187
+ const keys = Object.keys(left);
188
+ if (keys.length !== Object.keys(right).length) return false;
189
+ return keys.every((key) => key in right && deepEqualJson(left[key], right[key]));
190
+ }
191
+ /**
192
+ * Deep-freeze an object graph in place while leaving live AbortSignal objects mutable.
193
+ * @param value - value to freeze.
194
+ * @returns the same value after every reachable enumerable child is frozen.
195
+ */
196
+ function deepFreeze(value) {
197
+ const seen = /* @__PURE__ */ new WeakSet();
198
+ const pending = [{
199
+ kind: "visit",
200
+ node: value
201
+ }];
202
+ while (pending.length > 0) {
203
+ const task = pending.pop();
204
+ /* v8 ignore next -- the loop condition guarantees one pending task. */
205
+ if (task === void 0) continue;
206
+ if (task.kind === "property") {
207
+ pending.push({
208
+ kind: "visit",
209
+ node: task.source[task.key]
210
+ });
211
+ continue;
212
+ }
213
+ const node = task.node;
214
+ if (node === null || typeof node !== "object") continue;
215
+ if (node instanceof AbortSignal) continue;
216
+ if (seen.has(node)) continue;
217
+ seen.add(node);
218
+ Object.freeze(node);
219
+ const keys = Object.keys(node);
220
+ for (let index = keys.length - 1; index >= 0; index--) {
221
+ const key = keys[index];
222
+ /* v8 ignore next -- the loop is bounded by the captured key count. */
223
+ if (key === void 0) continue;
224
+ pending.push({
225
+ kind: "property",
226
+ source: node,
227
+ key
228
+ });
229
+ }
230
+ }
231
+ return value;
232
+ }
233
+ //#endregion
234
+ export { assertNever, deepEqualJson, deepFreeze, isJsonValue, snapshotJsonValue };