@whaaaley/crush 0.3.0-next.10 → 0.3.0-next.11
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 +6 -14
- package/SKILL.md +4 -19
- package/dist/crush.tables.d.ts +12 -124
- package/dist/crush.tables.js +7 -22
- package/dist/instrument/instrument.operations.js +1 -1
- package/dist/judge/counters.js +1 -1
- package/dist/judge/edges/api.d.ts +2 -2
- package/dist/judge/edges/api.js +2 -2
- package/dist/judge/edges/hints.reporter.js +2 -2
- package/dist/judge/edges/judge.edges.d.ts +1 -2
- package/dist/judge/edges/judge.edges.js +1 -2
- package/dist/judge/edges/plugin.d.ts +7 -10
- package/dist/judge/edges/plugin.js +34 -55
- package/dist/judge/edges/vitest.d.ts +0 -3
- package/dist/judge/edges/vitest.js +1 -4
- package/dist/judge/hints.d.ts +1 -1
- package/dist/judge/hints.js +0 -3
- package/dist/judge/judge.schema.d.ts +0 -1
- package/dist/judge/judge.schema.js +0 -2
- package/dist/judge/provided.d.ts +2 -10
- package/dist/judge/provided.js +1 -1
- package/dist/judge/refusals.d.ts +2 -2
- package/dist/judge/refusals.js +2 -2
- package/dist/judge/report.test.js +10 -12
- package/dist/judge/runner.js +5 -66
- package/dist/judge/task-meta.d.ts +0 -6
- package/dist/questions/questions.operations.d.ts +2 -5
- package/dist/questions/questions.operations.js +8 -24
- package/dist/questions/questions.schema.d.ts +1 -3
- package/dist/questions/questions.schema.js +2 -2
- package/dist/record/edges/findings.db.d.ts +16 -0
- package/dist/record/edges/findings.db.js +25 -0
- package/dist/record/edges/parts.db.d.ts +1 -1
- package/dist/record/edges/parts.db.js +3 -15
- package/dist/record/edges/record.db.d.ts +1 -1
- package/dist/record/edges/record.db.js +1 -1
- package/dist/record/parts.operations.d.ts +2 -3
- package/dist/record/parts.operations.js +1 -2
- package/migrations/main/20261206102548_drop_explore/migration.sql +17 -0
- package/migrations/main/20261206102548_drop_explore/snapshot.json +3550 -0
- package/package.json +1 -3
- package/references/consumer-setup.md +0 -1
- package/dist/explore/edges/explore.d.ts +0 -53
- package/dist/explore/edges/explore.db.d.ts +0 -27
- package/dist/explore/edges/explore.db.js +0 -57
- package/dist/explore/edges/explore.js +0 -217
- package/dist/explore/edges/random.d.ts +0 -2
- package/dist/explore/edges/random.js +0 -32
- package/dist/explore/explore.operations.d.ts +0 -30
- package/dist/explore/explore.operations.js +0 -117
- package/dist/explore/limits.operations.d.ts +0 -14
- package/dist/explore/limits.operations.js +0 -20
- package/dist/explore/targets.operations.d.ts +0 -36
- package/dist/explore/targets.operations.js +0 -32
- package/dist/explore/utils/draws.d.ts +0 -6
- package/dist/explore/utils/draws.js +0 -2
- package/dist/explore/utils/edits.d.ts +0 -15
- package/dist/explore/utils/edits.js +0 -151
- package/dist/explore/utils/guide.d.ts +0 -23
- package/dist/explore/utils/guide.js +0 -35
- package/dist/explore/utils/keep.d.ts +0 -10
- package/dist/explore/utils/keep.js +0 -61
- package/dist/explore/utils/pools.d.ts +0 -17
- package/dist/explore/utils/pools.js +0 -121
- package/dist/explore/utils/reads.d.ts +0 -19
- package/dist/explore/utils/reads.js +0 -118
- package/dist/explore/utils/twin.d.ts +0 -21
- package/dist/explore/utils/twin.js +0 -55
- package/dist/judge/explore.test.d.ts +0 -1
- package/dist/judge/explore.test.js +0 -101
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { encodeReachKey } from '../graph/symbols/keys.js';
|
|
2
|
-
import { unitFieldsOf } from '../record/record.operations.js';
|
|
3
|
-
import { reachedFrom } from '../graph/symbols/symbols.js';
|
|
4
|
-
// Matches an edges folder, which Explore excludes from search.
|
|
5
|
-
export const edgesPathPattern = /(^|\/)edges\//;
|
|
6
|
-
export const graphOf = ({ nodes, edges }) => ({
|
|
7
|
-
out: new Map([...Map.groupBy(edges, ({ fromKey }) => fromKey)].map(([from, each]) => [from, each.map(({ toKey }) => toKey)])),
|
|
8
|
-
fileOf: new Map(nodes.map(({ key, file }) => [key, file])),
|
|
9
|
-
});
|
|
10
|
-
// The exports and test-declared properties explore may call, by the whole-project graph: none whose calls reach an edges file, and for a related explore only those that sit in a given path or reach one.
|
|
11
|
-
export const explorableOf = ({ keys, out, fileOf, paths }) => {
|
|
12
|
-
return keys.flatMap((key) => {
|
|
13
|
-
const [path, name] = unitFieldsOf(key);
|
|
14
|
-
const files = [...new Set([path, ...[...reachedFrom(out, [encodeReachKey(['export', path, name])])].flatMap((node) => fileOf.get(node) ?? [])])];
|
|
15
|
-
if (files.some((file) => edgesPathPattern.test(file)))
|
|
16
|
-
return [];
|
|
17
|
-
if (paths && !files.some((file) => paths.has(file)))
|
|
18
|
-
return [];
|
|
19
|
-
return [{ key, files }];
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
// Each export explore left out, with why, as the report lists them.
|
|
23
|
-
export const skippedOf = ({ unreplayable, unexplorable, stopped, unsearched }) => [
|
|
24
|
-
...unreplayable.map((key) => `${key}: a call passed an argument the record could not keep`),
|
|
25
|
-
...unexplorable.map((key) => `${key}: its calls reach an edges file, or no path the related explore names`),
|
|
26
|
-
...stopped.map(({ key, reason }) => `${key}: ${reason}`),
|
|
27
|
-
...unsearched.map((key) => `${key}: the cap left it no call`),
|
|
28
|
-
];
|
|
29
|
-
export const unexploredOf = (skipped) => {
|
|
30
|
-
const reasons = skippedOf(skipped);
|
|
31
|
-
return reasons.length ? `explore explored no target:\n${reasons.join('\n')}` : 'explore explored no target: the tests called no export';
|
|
32
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type Pools } from './pools.ts';
|
|
2
|
-
import type { Random } from './draws.ts';
|
|
3
|
-
import { type Path } from './reads.ts';
|
|
4
|
-
type EditsInput = {
|
|
5
|
-
r: Random;
|
|
6
|
-
pools: Pools;
|
|
7
|
-
readPathsOf: (base: object) => Path[];
|
|
8
|
-
kept: () => object[];
|
|
9
|
-
};
|
|
10
|
-
export type Edits = {
|
|
11
|
-
resized: (array: unknown[], key: string, holder?: unknown) => unknown[];
|
|
12
|
-
edit: (base: object) => object;
|
|
13
|
-
};
|
|
14
|
-
export declare const editsOf: ({ r, pools, readPathsOf, kept }: EditsInput) => Edits;
|
|
15
|
-
export {};
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { present } from '../../utils/lookup.js';
|
|
2
|
-
import { holderShapeOf } from './pools.js';
|
|
3
|
-
import { fieldOf, holderKeyOf, isHolder, keysOf, valueAtPath, withAt } from './reads.js';
|
|
4
|
-
// The share of each edit kind, out of their sum: a blind redraw, a redraw aimed at what the run read, a splice from a kept input, and an array resized.
|
|
5
|
-
const weights = { blind: 3, aimed: 6, splice: 2, resize: 1 };
|
|
6
|
-
// The most edits one input takes.
|
|
7
|
-
const stackLimit = 3;
|
|
8
|
-
// Of ten aimed edits, how many redraw every string the run read; the next two redraw each read field by a coin, the rest one read field.
|
|
9
|
-
const aimedStrings = 4;
|
|
10
|
-
export const editsOf = ({ r, pools, readPathsOf, kept }) => {
|
|
11
|
-
const { donorsOf, elementsOf, isTag, isTuple } = pools;
|
|
12
|
-
const redrawn = (holder, at, holderKey) => {
|
|
13
|
-
const current = fieldOf(holder, at);
|
|
14
|
-
return typeof current === 'number' ? pools.drawNumber(at, current) : pools.drawString(at, current, holderKey);
|
|
15
|
-
};
|
|
16
|
-
const redrawAt = (base, path) => {
|
|
17
|
-
const key = present(path.at(-1));
|
|
18
|
-
const holderPath = path.slice(0, -1);
|
|
19
|
-
const holderKey = holderKeyOf(holderPath);
|
|
20
|
-
if (!isTag(holderKey, key))
|
|
21
|
-
return withAt(base, path, 0, (holder, at) => redrawn(holder, at, holderKey));
|
|
22
|
-
// A tag takes a whole object from a matching container in another kept input, an array element's container being the holder of its array.
|
|
23
|
-
let field = holderPath.at(-1);
|
|
24
|
-
let containerPath = holderPath.slice(0, -1);
|
|
25
|
-
while (containerPath.length && Array.isArray(valueAtPath(base, containerPath))) {
|
|
26
|
-
field = containerPath.at(-1);
|
|
27
|
-
containerPath = containerPath.slice(0, -1);
|
|
28
|
-
}
|
|
29
|
-
if (field === undefined)
|
|
30
|
-
return base;
|
|
31
|
-
const donors = donorsOf(valueAtPath(base, containerPath), holderKeyOf(containerPath), field);
|
|
32
|
-
return donors.length ? withAt(base, holderPath, 0, () => r.pick(donors)) : base;
|
|
33
|
-
};
|
|
34
|
-
// Redraws one number or string, reached by a walk that takes a key at random at each object, so a shallow field is drawn as often as a whole subtree.
|
|
35
|
-
const editBlind = (base) => {
|
|
36
|
-
const path = [];
|
|
37
|
-
let at = base;
|
|
38
|
-
while (isHolder(at)) {
|
|
39
|
-
const holder = at;
|
|
40
|
-
const keys = keysOf(holder).filter((key) => fieldOf(holder, key) !== null);
|
|
41
|
-
if (!keys.length)
|
|
42
|
-
return base;
|
|
43
|
-
const key = r.pick(keys);
|
|
44
|
-
path.push(key);
|
|
45
|
-
at = fieldOf(holder, key);
|
|
46
|
-
}
|
|
47
|
-
return typeof at === 'number' || typeof at === 'string' ? redrawAt(base, path) : base;
|
|
48
|
-
};
|
|
49
|
-
// Redraws fields the function under test read: one of them, or each by a coin, as a generator draws every one afresh around one case.
|
|
50
|
-
const editRead = (base) => {
|
|
51
|
-
const paths = readPathsOf(base);
|
|
52
|
-
if (!paths.length)
|
|
53
|
-
return editBlind(base);
|
|
54
|
-
const mode = r.int(1, 10);
|
|
55
|
-
if (mode > aimedStrings + 2)
|
|
56
|
-
return redrawAt(base, r.pick(paths));
|
|
57
|
-
// Strings alone are redrawn most often, since they name one of a few choices where a number is an index that is easily made invalid.
|
|
58
|
-
const isRedrawn = mode <= aimedStrings ? (path) => typeof valueAtPath(base, path) === 'string' && Boolean(r.int(0, 1)) : () => r.int(0, 9) < 3;
|
|
59
|
-
let next = base;
|
|
60
|
-
for (const path of paths) {
|
|
61
|
-
if (isTag(holderKeyOf(path.slice(0, -1)), present(path.at(-1))))
|
|
62
|
-
continue;
|
|
63
|
-
if (isRedrawn(path))
|
|
64
|
-
next = redrawAt(next, path);
|
|
65
|
-
}
|
|
66
|
-
return next;
|
|
67
|
-
};
|
|
68
|
-
// Splices at the same path in another kept input when the containing shapes and labels match.
|
|
69
|
-
const splice = (base) => {
|
|
70
|
-
const path = [];
|
|
71
|
-
let from = base;
|
|
72
|
-
let to = r.pick(kept());
|
|
73
|
-
for (;;) {
|
|
74
|
-
const source = from;
|
|
75
|
-
const donor = to;
|
|
76
|
-
if (holderShapeOf(source) !== holderShapeOf(donor))
|
|
77
|
-
return base;
|
|
78
|
-
const holderKey = holderKeyOf(path);
|
|
79
|
-
const sourceKeys = keysOf(source);
|
|
80
|
-
if (sourceKeys.some((key) => isTag(holderKey, key) && fieldOf(source, key) !== fieldOf(donor, key)))
|
|
81
|
-
return base;
|
|
82
|
-
const keys = sourceKeys.filter((key) => {
|
|
83
|
-
const fromChild = fieldOf(source, key);
|
|
84
|
-
const toChild = fieldOf(donor, key);
|
|
85
|
-
return isHolder(fromChild) && isHolder(toChild) && Array.isArray(fromChild) === Array.isArray(toChild);
|
|
86
|
-
});
|
|
87
|
-
if (!keys.length)
|
|
88
|
-
break;
|
|
89
|
-
const key = r.pick(keys);
|
|
90
|
-
path.push(key);
|
|
91
|
-
from = fieldOf(source, key);
|
|
92
|
-
to = fieldOf(donor, key);
|
|
93
|
-
if (r.int(0, 2) === 0)
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
if (!path.length)
|
|
97
|
-
return base;
|
|
98
|
-
return withAt(base, path, 0, () => to);
|
|
99
|
-
};
|
|
100
|
-
// Lengthens or shortens one array, a new element being a copy of one of its own or of one a kept input holds at the same key.
|
|
101
|
-
const resized = (array, key, holder = { [key]: array }) => {
|
|
102
|
-
const next = array.slice();
|
|
103
|
-
if (array.length && r.int(0, 1)) {
|
|
104
|
-
next.splice(r.int(0, array.length - 1), 1);
|
|
105
|
-
return next;
|
|
106
|
-
}
|
|
107
|
-
const donors = elementsOf(holder, key);
|
|
108
|
-
const item = array.length && (!donors || r.int(0, 1)) ? array[r.int(0, array.length - 1)] : donors && r.pick(donors);
|
|
109
|
-
if (item !== undefined)
|
|
110
|
-
next.splice(r.int(0, array.length), 0, item);
|
|
111
|
-
return next;
|
|
112
|
-
};
|
|
113
|
-
const resize = (base) => {
|
|
114
|
-
// The array is reached by a walk that stops at one by a coin, sparing a list of them all, and walks on through a tuple.
|
|
115
|
-
const path = [];
|
|
116
|
-
let at = base;
|
|
117
|
-
for (;;) {
|
|
118
|
-
const holder = at;
|
|
119
|
-
const keys = keysOf(holder).filter((key) => isHolder(fieldOf(holder, key)));
|
|
120
|
-
if (!keys.length)
|
|
121
|
-
return base;
|
|
122
|
-
const key = r.pick(keys);
|
|
123
|
-
path.push(key);
|
|
124
|
-
at = fieldOf(holder, key);
|
|
125
|
-
if (Array.isArray(at) && !isTuple(path) && r.int(0, 1))
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
return withAt(base, path, 0, (holder, key) => {
|
|
129
|
-
const array = fieldOf(holder, key);
|
|
130
|
-
return Array.isArray(array) ? resized(array, key, holder) : array;
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
const weightSum = weights.blind + weights.aimed + weights.splice + weights.resize;
|
|
134
|
-
const editOnce = (base) => {
|
|
135
|
-
const roll = r.int(1, weightSum);
|
|
136
|
-
if (roll <= weights.blind)
|
|
137
|
-
return editBlind(base);
|
|
138
|
-
if (roll <= weights.blind + weights.aimed)
|
|
139
|
-
return editRead(base);
|
|
140
|
-
if (roll <= weights.blind + weights.aimed + weights.splice)
|
|
141
|
-
return splice(base);
|
|
142
|
-
return resize(base);
|
|
143
|
-
};
|
|
144
|
-
const edit = (base) => {
|
|
145
|
-
let next = editOnce(base);
|
|
146
|
-
for (let more = stackLimit - 1; more > 0 && r.int(0, 1); more--)
|
|
147
|
-
next = editOnce(next);
|
|
148
|
-
return next;
|
|
149
|
-
};
|
|
150
|
-
return { resized, edit };
|
|
151
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type Path, type ReadNode } from './reads.ts';
|
|
2
|
-
export declare const firstSideOf: (reads: ReadNode, first: string, second: string) => ReadNode;
|
|
3
|
-
export declare const bothSidesOf: (reads: ReadNode, first: string, second: string) => ReadNode | undefined;
|
|
4
|
-
export declare const sizeLimitOf: (seeds: readonly object[]) => number;
|
|
5
|
-
export declare const fitsSize: (value: unknown, limit: number) => boolean;
|
|
6
|
-
type Sides = {
|
|
7
|
-
first: string;
|
|
8
|
-
second: string;
|
|
9
|
-
};
|
|
10
|
-
type ReadPathsInput = {
|
|
11
|
-
property: (input: object) => unknown;
|
|
12
|
-
mirrored: (base: object) => object;
|
|
13
|
-
twin: Sides | undefined;
|
|
14
|
-
};
|
|
15
|
-
export declare const readPathsOf: ({ property, mirrored, twin }: ReadPathsInput) => ((base: object) => Path[]);
|
|
16
|
-
type TwinReadsInput = {
|
|
17
|
-
twin: Sides & {
|
|
18
|
-
related: (input: object) => boolean;
|
|
19
|
-
};
|
|
20
|
-
mirrored: (base: object) => object;
|
|
21
|
-
};
|
|
22
|
-
export declare const twinReadsOf: ({ twin, mirrored }: TwinReadsInput) => ((edited: object) => ReadNode | undefined);
|
|
23
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { leafPathsOf, merged, readsOf, sizeOf } from './reads.js';
|
|
2
|
-
// What a run read of a two-run input, with all it read of the second side counted as read of the first, which is the side a kept input holds.
|
|
3
|
-
export const firstSideOf = (reads, first, second) => {
|
|
4
|
-
const children = new Map(reads.children);
|
|
5
|
-
const side = merged(children.get(first), children.get(second));
|
|
6
|
-
children.delete(second);
|
|
7
|
-
if (side)
|
|
8
|
-
children.set(first, side);
|
|
9
|
-
const keys = new Set([...reads.keys].filter((key) => key !== second));
|
|
10
|
-
if (side)
|
|
11
|
-
keys.add(first);
|
|
12
|
-
return { keys, children, proxy: reads.proxy };
|
|
13
|
-
};
|
|
14
|
-
// What a relation read of either side of a two-run input, as one tree, which tells the fields the second side must keep.
|
|
15
|
-
export const bothSidesOf = (reads, first, second) => merged(reads.children.get(first), reads.children.get(second));
|
|
16
|
-
// The largest input the search keeps, twice the size of its largest seed, so kept inputs grow but never without bound.
|
|
17
|
-
export const sizeLimitOf = (seeds) => Math.max(0, ...seeds.map((seed) => 2 * sizeOf(seed)));
|
|
18
|
-
export const fitsSize = (value, limit) => sizeOf(value) <= limit;
|
|
19
|
-
// The fields a run of the property read of each kept base, the ones an edit can change its run through, read once per base and kept.
|
|
20
|
-
export const readPathsOf = ({ property, mirrored, twin }) => {
|
|
21
|
-
const readPaths = new WeakMap();
|
|
22
|
-
return (base) => {
|
|
23
|
-
const known = readPaths.get(base);
|
|
24
|
-
if (known)
|
|
25
|
-
return known;
|
|
26
|
-
const reads = readsOf(mirrored(base), (proxied) => property(proxied));
|
|
27
|
-
const paths = leafPathsOf(base, twin ? firstSideOf(reads, twin.first, twin.second) : reads, [], []);
|
|
28
|
-
readPaths.set(base, paths);
|
|
29
|
-
return paths;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
// What the relation of a two-run input read of either side, for an edited base run mirrored, which the twin plan frees the rest of.
|
|
33
|
-
export const twinReadsOf = ({ twin, mirrored }) => {
|
|
34
|
-
return (edited) => bothSidesOf(readsOf(mirrored(edited), twin.related), twin.first, twin.second);
|
|
35
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Random } from './draws.ts';
|
|
2
|
-
export declare const groupLimit = 8;
|
|
3
|
-
export type KeptInputs = {
|
|
4
|
-
queue: object[];
|
|
5
|
-
groupList: object[][];
|
|
6
|
-
pathOf: (sides: Iterable<string>) => number;
|
|
7
|
-
join: (base: object, path: number, always: boolean) => void;
|
|
8
|
-
keep: (base: object, path: number, counts: ReadonlyMap<string, number>) => boolean;
|
|
9
|
-
};
|
|
10
|
-
export declare const keptInputsOf: (r: Random, onNew: (base: object) => void, sizeLimit: number) => KeptInputs;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { fitsSize } from './guide.js';
|
|
2
|
-
// The most inputs one path's group holds before a new one replaces a member at random.
|
|
3
|
-
export const groupLimit = 8;
|
|
4
|
-
// The highest hit count bucket, past which more passes through a side count as no new side.
|
|
5
|
-
const topBucket = 8;
|
|
6
|
-
// `onNew` is handed each input kept for a new side, as the pools learn it, and `sizeLimit` is the largest input kept, so kept inputs grow but never without bound.
|
|
7
|
-
export const keptInputsOf = (r, onNew, sizeLimit) => {
|
|
8
|
-
const hashes = new Map();
|
|
9
|
-
const seenOf = (key) => {
|
|
10
|
-
const had = hashes.get(key) ?? { bits: 0, hash: r.int(-0x80000000, 0x7fffffff) };
|
|
11
|
-
hashes.set(key, had);
|
|
12
|
-
return had;
|
|
13
|
-
};
|
|
14
|
-
// Which way a run went, as one number over the sides it took, in any order.
|
|
15
|
-
const pathOf = (sides) => {
|
|
16
|
-
let signature = 0;
|
|
17
|
-
for (const key of sides)
|
|
18
|
-
signature ^= seenOf(key).hash;
|
|
19
|
-
return signature;
|
|
20
|
-
};
|
|
21
|
-
const queue = [];
|
|
22
|
-
const groups = new Map();
|
|
23
|
-
const groupList = [];
|
|
24
|
-
const join = (base, path, always) => {
|
|
25
|
-
const group = groups.get(path);
|
|
26
|
-
if (!group) {
|
|
27
|
-
const made = [base];
|
|
28
|
-
groups.set(path, made);
|
|
29
|
-
groupList.push(made);
|
|
30
|
-
}
|
|
31
|
-
else if (always || group.length < groupLimit) {
|
|
32
|
-
group.push(base);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
group[r.int(0, group.length - 1)] = base;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
// Keeps an input by the counts its run left, answering whether it took a side at a bucket no earlier run did.
|
|
39
|
-
const keep = (base, path, counts) => {
|
|
40
|
-
// An input past the limit marks no side seen, so a smaller one taking the same sides is still kept.
|
|
41
|
-
if (!fitsSize(base, sizeLimit))
|
|
42
|
-
return false;
|
|
43
|
-
let isNew = false;
|
|
44
|
-
for (const [key, count] of counts) {
|
|
45
|
-
const had = seenOf(key);
|
|
46
|
-
const bit = 1 << Math.min(topBucket, Math.ceil(Math.log2(count + 1)));
|
|
47
|
-
if (had.bits & bit)
|
|
48
|
-
continue;
|
|
49
|
-
had.bits |= bit;
|
|
50
|
-
isNew = true;
|
|
51
|
-
}
|
|
52
|
-
if (isNew || !groups.has(path))
|
|
53
|
-
join(base, path, false);
|
|
54
|
-
if (isNew) {
|
|
55
|
-
queue.push(base);
|
|
56
|
-
onNew(base);
|
|
57
|
-
}
|
|
58
|
-
return isNew;
|
|
59
|
-
};
|
|
60
|
-
return { queue, groupList, pathOf, join, keep };
|
|
61
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Random } from './draws.ts';
|
|
2
|
-
import { type Path } from './reads.ts';
|
|
3
|
-
export declare const poolLimit = 256;
|
|
4
|
-
export declare const holderShapeOf: (holder: unknown) => string;
|
|
5
|
-
export type Pools = {
|
|
6
|
-
donorsOf: (container: unknown, containerKey: string, key: string) => unknown[];
|
|
7
|
-
elementsOf: (holder: unknown, key: string) => unknown[] | undefined;
|
|
8
|
-
isTag: (holderKey: string, key: string) => boolean;
|
|
9
|
-
learn: (value: unknown, holderKey: string) => void;
|
|
10
|
-
learnInput: (input: object) => void;
|
|
11
|
-
learnLengths: (seed: object) => void;
|
|
12
|
-
isTuple: (path: Path) => boolean;
|
|
13
|
-
forget: () => void;
|
|
14
|
-
drawNumber: (key: string, current: number) => unknown;
|
|
15
|
-
drawString: (key: string, current: unknown, holderKey?: string) => unknown;
|
|
16
|
-
};
|
|
17
|
-
export declare const poolsOf: (r: Random) => Pools;
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { fieldOf, holderKeyOf, isHolder, isIndex, keysOf } from './reads.js';
|
|
2
|
-
import { entryAt } from '../../utils/lookup.js';
|
|
3
|
-
// The most items one pool keeps under one key, a sample once more arrive.
|
|
4
|
-
export const poolLimit = 256;
|
|
5
|
-
// Of nine number draws, how many take a number known under the field's key, one a step from the current value, and the rest a small number.
|
|
6
|
-
const keyedDraws = 3;
|
|
7
|
-
const fieldKeyOf = (holderKey, key) => JSON.stringify([holderKey, key]);
|
|
8
|
-
export const holderShapeOf = (holder) => JSON.stringify(Object.keys(Object(holder)).toSorted());
|
|
9
|
-
export const poolsOf = (r) => {
|
|
10
|
-
const stringsAt = new Map();
|
|
11
|
-
const numbersAt = new Map();
|
|
12
|
-
const donorsAt = new Map();
|
|
13
|
-
const elementsAt = new Map();
|
|
14
|
-
const remember = (pool, key, item) => {
|
|
15
|
-
const known = pool.get(key);
|
|
16
|
-
if (!known)
|
|
17
|
-
pool.set(key, [item]);
|
|
18
|
-
else if (known.length < poolLimit)
|
|
19
|
-
known.push(item);
|
|
20
|
-
else
|
|
21
|
-
known[r.int(0, poolLimit - 1)] = item;
|
|
22
|
-
};
|
|
23
|
-
const shapesAt = new Map();
|
|
24
|
-
const tags = new Set();
|
|
25
|
-
const noteShape = (id, value, holder) => {
|
|
26
|
-
const known = shapesAt.get(id) ?? { byShape: new Map(), exclusive: new Map() };
|
|
27
|
-
shapesAt.set(id, known);
|
|
28
|
-
const shape = holderShapeOf(holder);
|
|
29
|
-
const had = known.byShape.get(shape);
|
|
30
|
-
if (had === undefined) {
|
|
31
|
-
known.byShape.set(shape, value);
|
|
32
|
-
known.exclusive.set(value, (known.exclusive.get(value) ?? 0) + 1);
|
|
33
|
-
}
|
|
34
|
-
else if (had !== null && had !== value) {
|
|
35
|
-
known.byShape.set(shape, null);
|
|
36
|
-
const remaining = entryAt(known.exclusive, had, 'a label with an exclusive shape') - 1;
|
|
37
|
-
if (remaining)
|
|
38
|
-
known.exclusive.set(had, remaining);
|
|
39
|
-
else
|
|
40
|
-
known.exclusive.delete(had);
|
|
41
|
-
}
|
|
42
|
-
if (known.exclusive.size > 1)
|
|
43
|
-
tags.add(id);
|
|
44
|
-
else
|
|
45
|
-
tags.delete(id);
|
|
46
|
-
};
|
|
47
|
-
const isTag = (holderKey, key) => tags.has(fieldKeyOf(holderKey, key));
|
|
48
|
-
const learn = (value, holderKey, parent) => {
|
|
49
|
-
const isArray = Array.isArray(value);
|
|
50
|
-
for (const [key, inner] of Object.entries(Object(value))) {
|
|
51
|
-
if (typeof inner === 'string') {
|
|
52
|
-
const fieldKey = fieldKeyOf(holderKey, key);
|
|
53
|
-
const known = stringsAt.get(fieldKey) ?? [];
|
|
54
|
-
if (!known.includes(inner))
|
|
55
|
-
known.push(inner);
|
|
56
|
-
stringsAt.set(fieldKey, known);
|
|
57
|
-
if (isArray)
|
|
58
|
-
continue;
|
|
59
|
-
noteShape(fieldKey, inner, Object(value));
|
|
60
|
-
if (parent && tags.has(fieldKey))
|
|
61
|
-
remember(donorsAt, fieldKeyOf(holderShapeOf(parent.container), parent.key), { container: parent.container, value });
|
|
62
|
-
}
|
|
63
|
-
else if (typeof inner === 'number') {
|
|
64
|
-
remember(numbersAt, key, inner);
|
|
65
|
-
}
|
|
66
|
-
else if (isHolder(inner)) {
|
|
67
|
-
if (Array.isArray(inner)) {
|
|
68
|
-
const elementKey = fieldKeyOf(holderShapeOf(value), key);
|
|
69
|
-
for (const element of inner)
|
|
70
|
-
if (isHolder(element))
|
|
71
|
-
remember(elementsAt, elementKey, element);
|
|
72
|
-
}
|
|
73
|
-
// An array's elements take the array's own place as their container, so a tagged element is swapped only for one from the same field of a matching holder.
|
|
74
|
-
const container = isArray && parent ? parent : { container: value, key };
|
|
75
|
-
learn(inner, isArray || (holderKey !== '' && isIndex(key)) ? holderKey : key, container);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
// The seeds are learned twice, since which fields are tags is known only once every seed has been seen, so every pool but the strings starts again.
|
|
80
|
-
const forget = () => {
|
|
81
|
-
for (const pool of [donorsAt, elementsAt, numbersAt])
|
|
82
|
-
pool.clear();
|
|
83
|
-
};
|
|
84
|
-
const drawNumber = (key, current) => {
|
|
85
|
-
const roll = r.int(0, 8);
|
|
86
|
-
const known = numbersAt.get(key);
|
|
87
|
-
if (roll < keyedDraws && known)
|
|
88
|
-
return r.pick(known);
|
|
89
|
-
return roll === 8 ? current + r.int(-1, 1) : r.int(-8, 8);
|
|
90
|
-
};
|
|
91
|
-
const drawString = (key, current, holderKey = '') => r.pick(stringsAt.get(fieldKeyOf(holderKey, key)) ?? [current]);
|
|
92
|
-
// An input's own fields sit under the root key, the one `holderKeyOf` gives the empty path, so a tag on its top level is known by the same key edits look it up under.
|
|
93
|
-
const learnInput = (input) => learn(input, holderKeyOf([]));
|
|
94
|
-
// An array is a tuple when the seeds hold it at one length at least twice, counting each element of a list at one place, so `[language, ranked]` entries keep their length.
|
|
95
|
-
const lengthsAt = new Map();
|
|
96
|
-
const placeOf = (path) => JSON.stringify(path.map((key) => (isIndex(key) ? '*' : key)));
|
|
97
|
-
const learnLengths = (value, path = []) => {
|
|
98
|
-
if (Array.isArray(value)) {
|
|
99
|
-
const place = placeOf(path);
|
|
100
|
-
const known = lengthsAt.get(place) ?? { lengths: new Set(), count: 0 };
|
|
101
|
-
known.lengths.add(value.length);
|
|
102
|
-
known.count++;
|
|
103
|
-
lengthsAt.set(place, known);
|
|
104
|
-
}
|
|
105
|
-
for (const [key, inner] of Object.entries(value))
|
|
106
|
-
if (isHolder(inner))
|
|
107
|
-
learnLengths(inner, path.concat(key));
|
|
108
|
-
};
|
|
109
|
-
const isTuple = (path) => {
|
|
110
|
-
const known = lengthsAt.get(placeOf(path));
|
|
111
|
-
return known !== undefined && known.count > 1 && known.lengths.size === 1;
|
|
112
|
-
};
|
|
113
|
-
const elementsOf = (holder, key) => elementsAt.get(fieldKeyOf(holderShapeOf(holder), key));
|
|
114
|
-
const donorsOf = (container, containerKey, key) => {
|
|
115
|
-
const candidates = donorsAt.get(fieldKeyOf(holderShapeOf(container), key)) ?? [];
|
|
116
|
-
// Labels can change as the search learns new shapes, so compare them at draw time.
|
|
117
|
-
const labels = keysOf(container).filter((field) => isTag(containerKey, field));
|
|
118
|
-
return candidates.filter((donor) => labels.every((field) => fieldOf(container, field) === fieldOf(donor.container, field))).map((donor) => donor.value);
|
|
119
|
-
};
|
|
120
|
-
return { donorsOf, elementsOf, isTag, learn, learnInput, learnLengths, isTuple, forget, drawNumber, drawString };
|
|
121
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type Holder = Record<string, unknown> | unknown[];
|
|
2
|
-
export declare const isHolder: (value: unknown) => value is Holder;
|
|
3
|
-
export declare const fieldOf: (holder: unknown, key: string) => unknown;
|
|
4
|
-
export type ReadNode = {
|
|
5
|
-
keys: Set<string>;
|
|
6
|
-
children: Map<string, ReadNode>;
|
|
7
|
-
proxy: unknown;
|
|
8
|
-
};
|
|
9
|
-
export declare const readsOf: (value: object, run: (proxied: object) => unknown) => ReadNode;
|
|
10
|
-
export declare const merged: (a: ReadNode | undefined, b: ReadNode | undefined) => ReadNode | undefined;
|
|
11
|
-
export type Path = string[];
|
|
12
|
-
export declare const leafPathsOf: (value: unknown, node: ReadNode, path: Path, found: Path[]) => Path[];
|
|
13
|
-
export declare const valueAtPath: (value: unknown, path: Path) => unknown;
|
|
14
|
-
export declare const copyOf: (value: unknown) => Holder;
|
|
15
|
-
export declare const withAt: (value: unknown, path: Path, depth: number, change: (holder: unknown, key: string) => unknown) => Holder;
|
|
16
|
-
export declare const isIndex: (key: string) => boolean;
|
|
17
|
-
export declare const holderKeyOf: (path: Path) => string;
|
|
18
|
-
export declare const sizeOf: (value: unknown) => number;
|
|
19
|
-
export declare const keysOf: (value: unknown) => string[];
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// oxlint-disable typescript/no-unsafe-argument, typescript/no-unsafe-assignment, typescript/no-unsafe-return -- this file handles values the code under test makes, passes or throws, which no static type names
|
|
2
|
-
import { itemAt, present } from '../../utils/lookup.js';
|
|
3
|
-
// Only an array or a plain object holds fields an edit walks into; a Set, Map, Date or class instance is one value, so an edit never turns it into a plain object no typed caller could pass.
|
|
4
|
-
export const isHolder = (value) => {
|
|
5
|
-
if (Array.isArray(value))
|
|
6
|
-
return true;
|
|
7
|
-
if (typeof value !== 'object' || value === null)
|
|
8
|
-
return false;
|
|
9
|
-
const prototype = Object.getPrototypeOf(value);
|
|
10
|
-
return prototype === Object.prototype || prototype === null;
|
|
11
|
-
};
|
|
12
|
-
export const fieldOf = (holder, key) => {
|
|
13
|
-
if (!isHolder(holder))
|
|
14
|
-
return undefined;
|
|
15
|
-
const field = Reflect.get(holder, key);
|
|
16
|
-
return field;
|
|
17
|
-
};
|
|
18
|
-
export const readsOf = (value, run) => {
|
|
19
|
-
const wrap = (target) => {
|
|
20
|
-
const node = { keys: new Set(), children: new Map(), proxy: undefined };
|
|
21
|
-
node.proxy = new Proxy(target, {
|
|
22
|
-
get: (object, key) => {
|
|
23
|
-
const inner = Reflect.get(object, key);
|
|
24
|
-
if (typeof key !== 'string')
|
|
25
|
-
return inner;
|
|
26
|
-
node.keys.add(key);
|
|
27
|
-
if (!isHolder(inner))
|
|
28
|
-
return inner;
|
|
29
|
-
let child = node.children.get(key);
|
|
30
|
-
if (!child) {
|
|
31
|
-
child = wrap(inner);
|
|
32
|
-
node.children.set(key, child);
|
|
33
|
-
}
|
|
34
|
-
return child.proxy;
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return node;
|
|
38
|
-
};
|
|
39
|
-
const root = wrap(value);
|
|
40
|
-
run(Object(root.proxy));
|
|
41
|
-
return root;
|
|
42
|
-
};
|
|
43
|
-
// The reads of two runs over one shape, as one tree.
|
|
44
|
-
export const merged = (a, b) => {
|
|
45
|
-
if (!a || !b)
|
|
46
|
-
return a ?? b;
|
|
47
|
-
const node = { keys: new Set([...a.keys, ...b.keys]), children: new Map(), proxy: undefined };
|
|
48
|
-
// A key both trees reached merges once per tree, which gives the same child again.
|
|
49
|
-
for (const key of [...a.children.keys(), ...b.children.keys()])
|
|
50
|
-
node.children.set(key, present(merged(a.children.get(key), b.children.get(key))));
|
|
51
|
-
return node;
|
|
52
|
-
};
|
|
53
|
-
// The path to every number and string a run read.
|
|
54
|
-
export const leafPathsOf = (value, node, path, found) => {
|
|
55
|
-
for (const key of node.keys) {
|
|
56
|
-
const inner = fieldOf(value, key);
|
|
57
|
-
if (typeof inner === 'number' || typeof inner === 'string') {
|
|
58
|
-
if (key !== 'length')
|
|
59
|
-
found.push([...path, key]);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
// A run that read a holder entered it, so only a holder has a child.
|
|
63
|
-
const child = node.children.get(key);
|
|
64
|
-
if (child)
|
|
65
|
-
leafPathsOf(inner, child, [...path, key], found);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return found;
|
|
69
|
-
};
|
|
70
|
-
export const valueAtPath = (value, path) => {
|
|
71
|
-
let at = value;
|
|
72
|
-
for (const key of path)
|
|
73
|
-
at = fieldOf(at, key);
|
|
74
|
-
return at;
|
|
75
|
-
};
|
|
76
|
-
export const copyOf = (value) => (Array.isArray(value) ? value.slice() : { ...Object(value) });
|
|
77
|
-
// A value with the field at a path replaced, copying only the objects along the path.
|
|
78
|
-
export const withAt = (value, path, depth, change) => {
|
|
79
|
-
const key = itemAt(path, depth);
|
|
80
|
-
const copy = copyOf(value);
|
|
81
|
-
Reflect.set(copy, key, depth === path.length - 1 ? change(value, key) : withAt(fieldOf(value, key), path, depth + 1, change));
|
|
82
|
-
return copy;
|
|
83
|
-
};
|
|
84
|
-
export const isIndex = (key) => !Number.isNaN(Number(key));
|
|
85
|
-
// The nearest named holder, with a top-level argument index as the fallback for a positional seed.
|
|
86
|
-
export const holderKeyOf = (path) => {
|
|
87
|
-
let holderKey = path[0] ?? '';
|
|
88
|
-
for (const each of path)
|
|
89
|
-
if (!isIndex(each))
|
|
90
|
-
holderKey = each;
|
|
91
|
-
return holderKey;
|
|
92
|
-
};
|
|
93
|
-
export const sizeOf = (value) => {
|
|
94
|
-
const root = Object(value);
|
|
95
|
-
const stack = [{ value: root, fields: Object.values(root).values() }];
|
|
96
|
-
const ancestors = new Set([root]);
|
|
97
|
-
let size = 1;
|
|
98
|
-
while (stack.length) {
|
|
99
|
-
const frame = itemAt(stack, stack.length - 1);
|
|
100
|
-
const field = frame.fields.next();
|
|
101
|
-
if (field.done) {
|
|
102
|
-
ancestors.delete(frame.value);
|
|
103
|
-
stack.pop();
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
size++;
|
|
107
|
-
const inner = field.value;
|
|
108
|
-
if (!isHolder(inner))
|
|
109
|
-
continue;
|
|
110
|
-
// Only ancestors form a cycle. A shared field still counts at each place it occurs.
|
|
111
|
-
if (ancestors.has(inner))
|
|
112
|
-
return Infinity;
|
|
113
|
-
ancestors.add(inner);
|
|
114
|
-
stack.push({ value: inner, fields: Object.values(inner).values() });
|
|
115
|
-
}
|
|
116
|
-
return size;
|
|
117
|
-
};
|
|
118
|
-
export const keysOf = (value) => Object.keys(Object(value));
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Pools } from './pools.ts';
|
|
2
|
-
import type { Random } from './draws.ts';
|
|
3
|
-
import { type Path, type ReadNode } from './reads.ts';
|
|
4
|
-
export type Plan = {
|
|
5
|
-
numbers: [string, number][];
|
|
6
|
-
strings: string[];
|
|
7
|
-
children: [string, Plan][];
|
|
8
|
-
resizes: string | undefined;
|
|
9
|
-
free: number;
|
|
10
|
-
};
|
|
11
|
-
type TwinInput = {
|
|
12
|
-
r: Random;
|
|
13
|
-
pools: Pools;
|
|
14
|
-
resized: (array: unknown[], key: string, holder?: unknown) => unknown[];
|
|
15
|
-
};
|
|
16
|
-
export type Twin = {
|
|
17
|
-
planOf: (value: unknown, node: ReadNode | undefined, key: string, path: Path) => Plan | undefined;
|
|
18
|
-
vary: (value: unknown, plan: Plan, holderKey?: string, holder?: unknown) => unknown;
|
|
19
|
-
};
|
|
20
|
-
export declare const twinOf: ({ r, pools, resized }: TwinInput) => Twin;
|
|
21
|
-
export {};
|