@mmerterden/multi-agent-pipeline 20.40.0 → 20.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -0
- package/README.md +5 -2
- package/README.tr.md +5 -2
- package/docs/adr/0019-product-tree.md +143 -0
- package/docs/adr/README.md +1 -0
- package/docs/ecosystem.md +51 -14
- package/docs/facts.json +7 -7
- package/docs/features.md +15 -4
- package/install/claude.mjs +45 -3
- package/install/templates/claude-hooks.json +23 -1
- package/manifest.json +146 -107
- package/package.json +3 -2
- package/pipeline/commands/multi-agent/autopilot/SKILL.md +11 -0
- package/pipeline/commands/multi-agent/review-analysis/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/setup/SKILL.md +1 -1
- package/pipeline/contract/types/index.d.ts +53 -49
- package/pipeline/lib/args.mjs +131 -4
- package/pipeline/lib/bg-launch.mjs +5 -2
- package/pipeline/lib/context-budget.mjs +5 -42
- package/pipeline/lib/credential-store.sh +11 -1
- package/pipeline/lib/hook-once.mjs +134 -0
- package/pipeline/lib/hook-registration.mjs +5 -0
- package/pipeline/lib/isotonic.mjs +73 -0
- package/pipeline/lib/low-disk.mjs +153 -0
- package/pipeline/lib/mcp-schema-load.mjs +90 -0
- package/pipeline/lib/md2confluence-v3.py +19 -10
- package/pipeline/lib/model-dispatch.sh +26 -2
- package/pipeline/lib/normalize-text.mjs +135 -0
- package/pipeline/lib/outbound-gate.mjs +21 -3
- package/pipeline/lib/plan-todos.sh +17 -4
- package/pipeline/lib/redact.mjs +12 -3
- package/pipeline/lib/risky-settings.mjs +198 -0
- package/pipeline/lib/route-state.sh +1 -0
- package/pipeline/lib/secret-patterns.generated.mjs +6 -2
- package/pipeline/lib/session-usage.mjs +232 -0
- package/pipeline/lib/source-digest.mjs +211 -0
- package/pipeline/lib/tdd-evidence.mjs +250 -17
- package/pipeline/lib/tiered-budget.mjs +87 -0
- package/pipeline/lib/untrusted-fence.mjs +132 -1
- package/pipeline/multi-agent-refs/analysis/locked.md +1 -1
- package/pipeline/multi-agent-refs/analysis/review.md +23 -1
- package/pipeline/multi-agent-refs/features/code-graph.md +11 -1
- package/pipeline/multi-agent-refs/features/cost-analysis.md +37 -2
- package/pipeline/multi-agent-refs/features/doctor.md +82 -4
- package/pipeline/multi-agent-refs/features/model-fallback.md +25 -0
- package/pipeline/multi-agent-refs/features/plan-todos.md +4 -0
- package/pipeline/multi-agent-refs/features/product-tree.md +68 -0
- package/pipeline/multi-agent-refs/features/unattended-gates.md +5 -3
- package/pipeline/multi-agent-refs/features/unattended-security.md +88 -1
- package/pipeline/multi-agent-refs/features/usage-reporting.md +33 -0
- package/pipeline/multi-agent-refs/help/en.md +2 -1
- package/pipeline/multi-agent-refs/help/tr.md +2 -1
- package/pipeline/multi-agent-refs/knowledge.md +58 -0
- package/pipeline/multi-agent-refs/outside-the-pipeline.md +6 -0
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +4 -0
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +5 -1
- package/pipeline/multi-agent-refs/phases/phase-2-dev.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -2
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +4 -0
- package/pipeline/multi-agent-refs/progress-contract.md +3 -1
- package/pipeline/office/index.html +13 -7
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/preferences-template.json +1 -0
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/doctor-report.schema.json +47 -0
- package/pipeline/schemas/learnings-ledger.schema.json +35 -2
- package/pipeline/schemas/office-archive.schema.json +225 -128
- package/pipeline/schemas/plan-todos.schema.json +29 -1
- package/pipeline/schemas/prefs.schema.json +146 -0
- package/pipeline/schemas/product-tree-overlay.schema.json +57 -0
- package/pipeline/schemas/product-tree.schema.json +136 -0
- package/pipeline/schemas/route-config.schema.json +51 -0
- package/pipeline/schemas/secret-patterns.json +17 -1
- package/pipeline/schemas/toolkit-path-params.json +15 -1
- package/pipeline/scripts/_cost-advise.mjs +357 -0
- package/pipeline/scripts/_cost-budget.mjs +78 -0
- package/pipeline/scripts/_cost.mjs +29 -0
- package/pipeline/scripts/_decode_text.py +107 -0
- package/pipeline/scripts/_eval-stats.mjs +182 -0
- package/pipeline/scripts/_guard-probe.mjs +406 -0
- package/pipeline/scripts/_guard_rules.py +336 -1
- package/pipeline/scripts/_learnings-promotion.mjs +229 -0
- package/pipeline/scripts/_locate.mjs +539 -0
- package/pipeline/scripts/_memory-policy.mjs +208 -33
- package/pipeline/scripts/_product-tree-extract.mjs +761 -0
- package/pipeline/scripts/_product-tree.mjs +923 -0
- package/pipeline/scripts/_retrieval.mjs +161 -4
- package/pipeline/scripts/_secret-scan.mjs +6 -1
- package/pipeline/scripts/_stack-routing.mjs +2 -0
- package/pipeline/scripts/_test-gaming.mjs +346 -0
- package/pipeline/scripts/_user_guard_rules.py +744 -0
- package/pipeline/scripts/agent-guard.py +69 -6
- package/pipeline/scripts/agent-guard.sh +8 -1
- package/pipeline/scripts/argv-secret-scan.mjs +2 -1
- package/pipeline/scripts/autopilot-loop.mjs +407 -0
- package/pipeline/scripts/autopilot-runner.mjs +38 -25
- package/pipeline/scripts/capture-resume.sh +9 -1
- package/pipeline/scripts/cost-analyze.mjs +66 -4
- package/pipeline/scripts/cost-budget-check.mjs +5 -13
- package/pipeline/scripts/disk-cleaner.mjs +1418 -0
- package/pipeline/scripts/doctor.mjs +324 -43
- package/pipeline/scripts/evidence-gate.mjs +90 -0
- package/pipeline/scripts/gate-ledger.mjs +76 -21
- package/pipeline/scripts/gc-tmp.sh +5 -0
- package/pipeline/scripts/graph-query.mjs +257 -17
- package/pipeline/scripts/guard-probe-known-holes.json +3 -0
- package/pipeline/scripts/learnings-ledger.mjs +680 -55
- package/pipeline/scripts/note-agent-event.mjs +2 -0
- package/pipeline/scripts/note-mcp-failure.mjs +363 -0
- package/pipeline/scripts/note-mcp-failure.sh +19 -0
- package/pipeline/scripts/note-skill-use.mjs +96 -23
- package/pipeline/scripts/office-archive.mjs +23 -10
- package/pipeline/scripts/office-memory.mjs +4 -1
- package/pipeline/scripts/persona-walk-anchors.mjs +443 -0
- package/pipeline/scripts/pre-commit-check.sh +2 -2
- package/pipeline/scripts/pre-push-check.sh +8 -1
- package/pipeline/scripts/product-tree-eval.mjs +685 -0
- package/pipeline/scripts/product-tree.mjs +544 -0
- package/pipeline/scripts/publish-staged.mjs +324 -0
- package/pipeline/scripts/route-learn.mjs +628 -0
- package/pipeline/scripts/run-scope-guard.mjs +55 -1
- package/pipeline/scripts/scan-agent-config.sh +1 -1
- package/pipeline/scripts/statusline.mjs +309 -0
- package/pipeline/scripts/test-integrity-gate.mjs +97 -2
- package/pipeline/scripts/triage-memory.mjs +12 -4
- package/pipeline/scripts/uninstall.mjs +1 -0
- package/pipeline/skills/.skill-manifest.json +15 -7
- package/pipeline/skills/.skills-index.json +25 -3
- package/pipeline/skills/shared/README.md +6 -4
- package/pipeline/skills/shared/core/google-play-compliance/references/examples.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-review-analysis/SKILL.md +1 -1
- package/pipeline/skills/shared/external/backlog/SKILL.md +1 -1
- package/pipeline/skills/shared/external/disk-cleaner/SKILL.md +105 -0
- package/pipeline/skills/shared/external/disk-cleaner/evals/evals.json +62 -0
- package/pipeline/skills/shared/external/disk-cleaner/scripts/disk-cleaner.mjs +1418 -0
- package/pipeline/skills/shared/external/localization-reuse-map/SKILL.md +1 -1
- package/pipeline/skills/shared/external/spec-persona-walk/SKILL.md +118 -0
- package/pipeline/skills/shared/external/spec-persona-walk/evals/evals.json +50 -0
- package/pipeline/skills/shared/external/spec-persona-walk/scripts/persona-walk-anchors.mjs +443 -0
- package/pipeline/skills/shared/external/storekit/SKILL.md +1 -1
- package/pipeline/skills/shared/external/swiftdata/SKILL.md +1 -1
- package/pipeline/skills/skill-copies.json +9 -1
- package/pipeline/skills/skills-index.md +4 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isotonic.mjs - isotonic regression by pool adjacent violators, for
|
|
3
|
+
* calibrating a score that should be monotone in a probability.
|
|
4
|
+
*
|
|
5
|
+
* A Beta posterior mean is a probability only in name until it is checked
|
|
6
|
+
* against what happened: with few rows it is overconfident at the ends. The
|
|
7
|
+
* fit maps a predicted value to the observed rate of the block it falls in,
|
|
8
|
+
* with the constraint that a higher prediction never maps lower. Zero
|
|
9
|
+
* dependencies (ADR-0004).
|
|
10
|
+
*
|
|
11
|
+
* @module pipeline/lib/isotonic
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Fit a non-decreasing step function of `xs` to `ys` (each 0..1).
|
|
16
|
+
*
|
|
17
|
+
* @param {number[]} xs predictions
|
|
18
|
+
* @param {number[]} ys outcomes
|
|
19
|
+
* @returns {{x: number[], y: number[]}|null} one point per block: the mean
|
|
20
|
+
* prediction and the mean outcome; null for no data
|
|
21
|
+
*/
|
|
22
|
+
export function fitIsotonic(xs, ys) {
|
|
23
|
+
const pairs = xs
|
|
24
|
+
.map((x, i) => [Number(x), Number(ys[i])])
|
|
25
|
+
.filter(([x, y]) => Number.isFinite(x) && Number.isFinite(y))
|
|
26
|
+
.sort((a, b) => a[0] - b[0]);
|
|
27
|
+
if (!pairs.length) return null;
|
|
28
|
+
const blocks = [];
|
|
29
|
+
for (const [x, y] of pairs) {
|
|
30
|
+
const last = blocks[blocks.length - 1];
|
|
31
|
+
if (last && last.x === x) {
|
|
32
|
+
last.sy += y;
|
|
33
|
+
last.n += 1;
|
|
34
|
+
last.sx += x;
|
|
35
|
+
} else {
|
|
36
|
+
blocks.push({ x, sx: x, sy: y, n: 1 });
|
|
37
|
+
}
|
|
38
|
+
while (blocks.length > 1) {
|
|
39
|
+
const b = blocks[blocks.length - 1];
|
|
40
|
+
const a = blocks[blocks.length - 2];
|
|
41
|
+
if (a.sy / a.n <= b.sy / b.n) break;
|
|
42
|
+
blocks.splice(-2, 2, { x: a.x, sx: a.sx + b.sx, sy: a.sy + b.sy, n: a.n + b.n });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
x: blocks.map((b) => Number((b.sx / b.n).toFixed(6))),
|
|
47
|
+
y: blocks.map((b) => Number((b.sy / b.n).toFixed(6))),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The calibrated value of `p`: linear between block points, clamped outside
|
|
53
|
+
* them. Without a model, `p` itself.
|
|
54
|
+
*
|
|
55
|
+
* @param {{x: number[], y: number[]}|null} model
|
|
56
|
+
* @param {number} p
|
|
57
|
+
* @returns {number}
|
|
58
|
+
*/
|
|
59
|
+
export function applyIsotonic(model, p) {
|
|
60
|
+
if (!model || !model.x?.length) return p;
|
|
61
|
+
const { x, y } = model;
|
|
62
|
+
if (p <= x[0]) return y[0];
|
|
63
|
+
if (p >= x[x.length - 1]) return y[y.length - 1];
|
|
64
|
+
let lo = 0;
|
|
65
|
+
let hi = x.length - 1;
|
|
66
|
+
while (hi - lo > 1) {
|
|
67
|
+
const mid = (lo + hi) >> 1;
|
|
68
|
+
if (x[mid] <= p) lo = mid;
|
|
69
|
+
else hi = mid;
|
|
70
|
+
}
|
|
71
|
+
const t = (p - x[lo]) / (x[hi] - x[lo]);
|
|
72
|
+
return y[lo] + t * (y[hi] - y[lo]);
|
|
73
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @file low-disk.mjs - one cheap free-space check, and the one line that
|
|
4
|
+
* suggests the disk-cleaner skill when the disk is nearly full or a failure
|
|
5
|
+
* log says it ran out of space.
|
|
6
|
+
*
|
|
7
|
+
* The check is a single statfs call. It never deletes anything and never
|
|
8
|
+
* asks; callers decide whether to ask. Low means below
|
|
9
|
+
* prefs.global.diskCleaner.lowDiskGb (default 10) gigabytes free OR below
|
|
10
|
+
* prefs.global.diskCleaner.lowDiskPercent (default 5) percent free.
|
|
11
|
+
* prefs.global.diskCleaner.suggest false silences the line everywhere.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* low-disk.mjs [--path DIR] [--scan FILE] [--lang en|tr] [--json]
|
|
15
|
+
*
|
|
16
|
+
* --scan reads a failure log and prints the line when it names ENOSPC or a
|
|
17
|
+
* low-disk error, whatever the free space is now. Without output the disk
|
|
18
|
+
* is fine. Exit is always 0, so a hook or a gate's failure path can call it
|
|
19
|
+
* without changing its own result.
|
|
20
|
+
*
|
|
21
|
+
* @module pipeline/lib/low-disk
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { readFileSync, realpathSync, statfsSync } from "node:fs";
|
|
25
|
+
import { homedir } from "node:os";
|
|
26
|
+
import { pathToFileURL } from "node:url";
|
|
27
|
+
|
|
28
|
+
import { globalPref } from "./prefs-value.mjs";
|
|
29
|
+
|
|
30
|
+
export const DEFAULT_LOW_GB = 10;
|
|
31
|
+
export const DEFAULT_LOW_PERCENT = 5;
|
|
32
|
+
const GB = 1e9;
|
|
33
|
+
const SCAN_MAX = 4 * 1024 * 1024;
|
|
34
|
+
|
|
35
|
+
/** Error text a full disk produces, across Node, the shell, git and Xcode. */
|
|
36
|
+
export const DISK_FULL =
|
|
37
|
+
/ENOSPC|No space left on device|disk (?:is )?full|not enough (?:free )?(?:disk )?space|insufficient (?:free )?(?:disk )?space|low disk space|out of disk space/i;
|
|
38
|
+
|
|
39
|
+
/** The thresholds from prefs, falling back to the defaults. */
|
|
40
|
+
export function thresholds(env = process.env) {
|
|
41
|
+
const gb = Number(globalPref("diskCleaner.lowDiskGb", DEFAULT_LOW_GB, env));
|
|
42
|
+
const pct = Number(globalPref("diskCleaner.lowDiskPercent", DEFAULT_LOW_PERCENT, env));
|
|
43
|
+
return {
|
|
44
|
+
lowGb: Number.isFinite(gb) && gb >= 0 ? gb : DEFAULT_LOW_GB,
|
|
45
|
+
lowPercent: Number.isFinite(pct) && pct >= 0 ? pct : DEFAULT_LOW_PERCENT,
|
|
46
|
+
suggest: globalPref("diskCleaner.suggest", true, env) !== false,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Free and total bytes of the volume holding `path`, or nulls. */
|
|
51
|
+
export function measure(path) {
|
|
52
|
+
try {
|
|
53
|
+
const s = statfsSync(path);
|
|
54
|
+
return { freeBytes: s.bavail * s.bsize, totalBytes: s.blocks * s.bsize };
|
|
55
|
+
} catch {
|
|
56
|
+
return { freeBytes: null, totalBytes: null };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** True when either threshold is crossed. Unknown sizes are never low. */
|
|
61
|
+
export function isLow(status, th) {
|
|
62
|
+
if (status.freeBytes == null || !status.totalBytes) return false;
|
|
63
|
+
const pct = (status.freeBytes / status.totalBytes) * 100;
|
|
64
|
+
return status.freeBytes < th.lowGb * GB || pct < th.lowPercent;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function mentionsDiskFull(text) {
|
|
68
|
+
return DISK_FULL.test(String(text || ""));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The suggestion, one line, in the caller's output language. */
|
|
72
|
+
export function suggestion(status, { lang = "en", cause = "low" } = {}) {
|
|
73
|
+
const free =
|
|
74
|
+
status.freeBytes == null
|
|
75
|
+
? "?"
|
|
76
|
+
: `${(status.freeBytes / GB).toFixed(1)} GB` +
|
|
77
|
+
(status.totalBytes
|
|
78
|
+
? ` (${((status.freeBytes / status.totalBytes) * 100).toFixed(1)}%)`
|
|
79
|
+
: "");
|
|
80
|
+
const cmd = "node ~/.claude/scripts/disk-cleaner.mjs --dry-run";
|
|
81
|
+
if (lang === "tr") {
|
|
82
|
+
const why = cause === "error" ? "Hata çıktısı diskin dolduğunu söylüyor" : "Disk dolmak üzere";
|
|
83
|
+
return `multi-agent: ${why}, boş alan ${free}. Neyin silinebileceğini görmek için disk-cleaner skill'ini çalıştır (\`${cmd}\`); onay vermeden hiçbir şey silinmez.`;
|
|
84
|
+
}
|
|
85
|
+
const why = cause === "error" ? "the failure output says the disk is full" : "disk nearly full";
|
|
86
|
+
return `multi-agent: ${why}, ${free} free. Run the disk-cleaner skill (\`${cmd}\`) to see what can be freed; nothing is deleted until you confirm.`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The line to print, or null. `scanText` is failure output to look for a
|
|
91
|
+
* disk-full error in; without it only the free space decides.
|
|
92
|
+
*/
|
|
93
|
+
export function check({ path = homedir(), scanText = null, lang = "en", env = process.env } = {}) {
|
|
94
|
+
const th = thresholds(env);
|
|
95
|
+
const status = measure(path);
|
|
96
|
+
const low = isLow(status, th);
|
|
97
|
+
const errored = scanText != null && mentionsDiskFull(scanText);
|
|
98
|
+
const line =
|
|
99
|
+
th.suggest && (low || errored)
|
|
100
|
+
? suggestion(status, { lang, cause: errored ? "error" : "low" })
|
|
101
|
+
: null;
|
|
102
|
+
return { ...status, ...th, low, errored, line };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function readScan(file) {
|
|
106
|
+
try {
|
|
107
|
+
const text = readFileSync(file, "utf8");
|
|
108
|
+
return text.length > SCAN_MAX ? text.slice(-SCAN_MAX) : text;
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function main(argv = process.argv.slice(2), env = process.env) {
|
|
115
|
+
const arg = (k) => {
|
|
116
|
+
const i = argv.indexOf(k);
|
|
117
|
+
if (i >= 0) return argv[i + 1];
|
|
118
|
+
const eq = argv.find((a) => a.startsWith(`${k}=`));
|
|
119
|
+
return eq ? eq.slice(k.length + 1) : undefined;
|
|
120
|
+
};
|
|
121
|
+
if (argv.includes("-h") || argv.includes("--help")) {
|
|
122
|
+
process.stdout.write(
|
|
123
|
+
"usage: low-disk.mjs [--path DIR] [--scan FILE] [--lang en|tr] [--json]\n",
|
|
124
|
+
);
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
const scan = arg("--scan");
|
|
128
|
+
const r = check({
|
|
129
|
+
path: arg("--path") || env.HOME || homedir(),
|
|
130
|
+
scanText: scan ? readScan(scan) : null,
|
|
131
|
+
lang: arg("--lang") === "tr" ? "tr" : "en",
|
|
132
|
+
env,
|
|
133
|
+
});
|
|
134
|
+
if (argv.includes("--json")) process.stdout.write(JSON.stringify(r) + "\n");
|
|
135
|
+
else if (r.line) process.stdout.write(r.line + "\n");
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function invokedDirectly() {
|
|
140
|
+
try {
|
|
141
|
+
return import.meta.url === pathToFileURL(realpathSync(process.argv[1] ?? "")).href;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (invokedDirectly()) {
|
|
148
|
+
try {
|
|
149
|
+
process.exitCode = main();
|
|
150
|
+
} catch {
|
|
151
|
+
process.exitCode = 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mcp-schema-load.mjs - how much context an MCP server's tool list takes,
|
|
3
|
+
* per tool family.
|
|
4
|
+
*
|
|
5
|
+
* Every tool a server lists is sent with every turn: its name, description
|
|
6
|
+
* and input schema. The toolkit names its tools `<family>_<verb>` and
|
|
7
|
+
* MCP_TOOLKIT_CAPS narrows what it lists by family, so the useful number is
|
|
8
|
+
* the load per family: it says what each cap value would save.
|
|
9
|
+
*
|
|
10
|
+
* Tokens are an ESTIMATE, bytes / 4 of the JSON each entry is sent as. No
|
|
11
|
+
* tokenizer is bundled (ADR-0004) and the estimate is labelled as one
|
|
12
|
+
* wherever it is shown.
|
|
13
|
+
*
|
|
14
|
+
* @module pipeline/lib/mcp-schema-load
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const BYTES_PER_TOKEN = 4;
|
|
18
|
+
|
|
19
|
+
const tokensOf = (bytes) => Math.ceil(bytes / BYTES_PER_TOKEN);
|
|
20
|
+
|
|
21
|
+
/** The family a tool name belongs to: the part before the first underscore. */
|
|
22
|
+
export function familyOf(name) {
|
|
23
|
+
const s = String(name ?? "");
|
|
24
|
+
const i = s.indexOf("_");
|
|
25
|
+
return i > 0 ? s.slice(0, i) : s;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function summarize(families) {
|
|
29
|
+
families.sort((a, b) => b.bytes - a.bytes || (a.family < b.family ? -1 : 1));
|
|
30
|
+
return {
|
|
31
|
+
estimate: true,
|
|
32
|
+
bytesPerToken: BYTES_PER_TOKEN,
|
|
33
|
+
totalTools: families.reduce((a, f) => a + f.tools, 0),
|
|
34
|
+
totalBytes: families.reduce((a, f) => a + f.bytes, 0),
|
|
35
|
+
totalTokens: families.reduce((a, f) => a + f.tokens, 0),
|
|
36
|
+
families,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Load per family from a `tools/list` result.
|
|
42
|
+
*
|
|
43
|
+
* @param {object[]} tools the `result.tools` array as served
|
|
44
|
+
*/
|
|
45
|
+
export function schemaLoadByFamily(tools) {
|
|
46
|
+
const by = new Map();
|
|
47
|
+
for (const t of Array.isArray(tools) ? tools : []) {
|
|
48
|
+
if (!t || typeof t.name !== "string") continue;
|
|
49
|
+
const family = familyOf(t.name);
|
|
50
|
+
const f = by.get(family) || { family, tools: 0, bytes: 0 };
|
|
51
|
+
f.tools += 1;
|
|
52
|
+
f.bytes += Buffer.byteLength(JSON.stringify(t));
|
|
53
|
+
by.set(family, f);
|
|
54
|
+
}
|
|
55
|
+
return summarize([...by.values()].map((f) => ({ ...f, tokens: tokensOf(f.bytes) })));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Load per family from a toolkit manifest that carries a `families` field,
|
|
60
|
+
* either a map (`{ios: {tools, bytes | tokens}}`) or a list
|
|
61
|
+
* (`[{family, tools, bytes | tokens}]`). Null when the field is absent or any
|
|
62
|
+
* entry lacks a tool count and a size.
|
|
63
|
+
*
|
|
64
|
+
* @param {object|null} manifest
|
|
65
|
+
*/
|
|
66
|
+
export function loadFromManifest(manifest) {
|
|
67
|
+
const raw = manifest?.families;
|
|
68
|
+
if (!raw || typeof raw !== "object") return null;
|
|
69
|
+
const entries = Array.isArray(raw)
|
|
70
|
+
? raw.map((e) => [e?.family ?? e?.name, e])
|
|
71
|
+
: Object.entries(raw);
|
|
72
|
+
const families = [];
|
|
73
|
+
for (const [family, e] of entries) {
|
|
74
|
+
const tools = Number(e?.tools);
|
|
75
|
+
const bytes = Number(e?.bytes);
|
|
76
|
+
const tokens = Number(e?.tokens ?? e?.estTokens);
|
|
77
|
+
if (typeof family !== "string" || !Number.isInteger(tools)) return null;
|
|
78
|
+
if (Number.isFinite(bytes)) families.push({ family, tools, bytes, tokens: tokensOf(bytes) });
|
|
79
|
+
else if (Number.isFinite(tokens))
|
|
80
|
+
families.push({ family, tools, bytes: tokens * BYTES_PER_TOKEN, tokens });
|
|
81
|
+
else return null;
|
|
82
|
+
}
|
|
83
|
+
return families.length ? summarize(families) : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** "ios 31 tools ~9.8k tokens" for one family. */
|
|
87
|
+
export function familyLine(f) {
|
|
88
|
+
const k = f.tokens >= 1000 ? `${(f.tokens / 1000).toFixed(1)}k` : String(f.tokens);
|
|
89
|
+
return `${f.family}: ${f.tools} tools, ~${k} tokens (estimate)`;
|
|
90
|
+
}
|
|
@@ -270,10 +270,12 @@ class InlineContext:
|
|
|
270
270
|
# Confluence renders an <ac:image> at its natural size, so one screenshot took two
|
|
271
271
|
# screen heights on the page. Width is a display attribute only: the attachment
|
|
272
272
|
# stays full resolution and a click still opens the original.
|
|
273
|
-
# 720 is a desktop frame at half of a 2x export and a diagram at readable size
|
|
274
|
-
#
|
|
275
|
-
#
|
|
273
|
+
# 720 is a desktop frame at half of a 2x export and a diagram at readable size.
|
|
274
|
+
# An image inside a table cell shares the row with text columns, so it renders
|
|
275
|
+
# at TABLE_IMAGE_WIDTH; the frame gallery is a table, so its phone frames land
|
|
276
|
+
# there too. Any image can still name its own width through the title syntax.
|
|
276
277
|
DEFAULT_IMAGE_WIDTH = 720
|
|
278
|
+
TABLE_IMAGE_WIDTH = 240
|
|
277
279
|
|
|
278
280
|
IMAGE_WIDTH_RE = re.compile(r"\bwidth\s*=\s*(\d{2,4})\b")
|
|
279
281
|
|
|
@@ -514,10 +516,15 @@ def markdown_to_storage(
|
|
|
514
516
|
while i < len(lines) and lines[i].strip().startswith("|"):
|
|
515
517
|
rows.append([c.strip() for c in lines[i].strip().strip("|").split("|")])
|
|
516
518
|
i += 1
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
519
|
+
page_width = ctx.image_width
|
|
520
|
+
ctx.image_width = min(page_width, TABLE_IMAGE_WIDTH) if page_width else TABLE_IMAGE_WIDTH
|
|
521
|
+
try:
|
|
522
|
+
thead = "<thead><tr>" + "".join(f"<th>{inline(c, ctx)}</th>" for c in header) + "</tr></thead>"
|
|
523
|
+
tbody_rows = "".join(
|
|
524
|
+
"<tr>" + "".join(f"<td>{inline(c, ctx)}</td>" for c in r) + "</tr>" for r in rows
|
|
525
|
+
)
|
|
526
|
+
finally:
|
|
527
|
+
ctx.image_width = page_width
|
|
521
528
|
tbody = f"<tbody>{tbody_rows}</tbody>"
|
|
522
529
|
out.append(f"<table>{thead}{tbody}</table>")
|
|
523
530
|
continue
|
|
@@ -1175,8 +1182,9 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1175
1182
|
"--image-width",
|
|
1176
1183
|
type=int,
|
|
1177
1184
|
default=DEFAULT_IMAGE_WIDTH,
|
|
1178
|
-
help="Display width in px for embedded attachment images (0 = natural size). "
|
|
1179
|
-
|
|
1185
|
+
help="Display width in px for embedded attachment images (0 = natural size; images in a table cell stay at %d). "
|
|
1186
|
+
% TABLE_IMAGE_WIDTH
|
|
1187
|
+
+ "Per-image override: .",
|
|
1180
1188
|
)
|
|
1181
1189
|
create.add_argument("--dry-run", action="store_true")
|
|
1182
1190
|
create.set_defaults(func=cmd_create)
|
|
@@ -1190,7 +1198,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
1190
1198
|
"--image-width",
|
|
1191
1199
|
type=int,
|
|
1192
1200
|
default=DEFAULT_IMAGE_WIDTH,
|
|
1193
|
-
help="Display width in px for embedded attachment images (0 = natural size)."
|
|
1201
|
+
help="Display width in px for embedded attachment images (0 = natural size; images in a table cell stay at %d)."
|
|
1202
|
+
% TABLE_IMAGE_WIDTH,
|
|
1194
1203
|
)
|
|
1195
1204
|
update.add_argument("--mermaid-fallback", action="store_true")
|
|
1196
1205
|
update.add_argument("--dry-run", action="store_true")
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
#
|
|
8
8
|
# Usage:
|
|
9
9
|
# model-dispatch.sh <call-site> [--persona P] [--phase N] [--task-kind K]
|
|
10
|
-
# [--default RUNG] [--task-id ID]
|
|
10
|
+
# [--default RUNG] [--task-id ID] [--complexity N]
|
|
11
11
|
#
|
|
12
12
|
# <call-site> is one of the `scope` members: subagent | bulk-read | delegate |
|
|
13
13
|
# research. stdout is a single rung NAME. Rung names are the contract; the model
|
|
@@ -34,13 +34,21 @@
|
|
|
34
34
|
# Strategies: manual keeps the rule's order; task-fit tries the cheapest rung
|
|
35
35
|
# first; cost-ceiling keeps the order until cost-budget-check.mjs reports the run
|
|
36
36
|
# at its warn threshold of budgetCeilingUsd, then tries the cheapest first.
|
|
37
|
+
#
|
|
38
|
+
# Learned order: with modelRouting.learned.enabled (ships false), the order the
|
|
39
|
+
# strategy produced is handed to route-learn.mjs choose, which reorders it from
|
|
40
|
+
# the PROMOTED policy for this call site, task kind and complexity band. Only
|
|
41
|
+
# a permutation of the rule's own candidates is taken, so learning can change
|
|
42
|
+
# which allowed rung is tried first and never adds one; the fable switch and
|
|
43
|
+
# the provider checks below still apply to whatever order comes back. No
|
|
44
|
+
# promoted policy, too few outcomes, or any failure leaves the order as it was.
|
|
37
45
|
|
|
38
46
|
set -uo pipefail
|
|
39
47
|
|
|
40
48
|
CALL_SITE="${1:-}"
|
|
41
49
|
shift || true
|
|
42
50
|
|
|
43
|
-
PERSONA=""; PHASE=""; TASK_KIND=""; DEFAULT_RUNG=""; TASK_ID="${MULTI_AGENT_TASK_ID:-unknown}"
|
|
51
|
+
PERSONA=""; PHASE=""; TASK_KIND=""; DEFAULT_RUNG=""; COMPLEXITY=""; TASK_ID="${MULTI_AGENT_TASK_ID:-unknown}"
|
|
44
52
|
while [ $# -gt 0 ]; do
|
|
45
53
|
case "$1" in
|
|
46
54
|
--persona) PERSONA="${2:-}"; shift 2 ;;
|
|
@@ -48,6 +56,7 @@ while [ $# -gt 0 ]; do
|
|
|
48
56
|
--task-kind) TASK_KIND="${2:-}"; shift 2 ;;
|
|
49
57
|
--default) DEFAULT_RUNG="${2:-}"; shift 2 ;;
|
|
50
58
|
--task-id) TASK_ID="${2:-}"; shift 2 ;;
|
|
59
|
+
--complexity) COMPLEXITY="${2:-}"; shift 2 ;;
|
|
51
60
|
*) shift ;;
|
|
52
61
|
esac
|
|
53
62
|
done
|
|
@@ -144,6 +153,21 @@ if [ "$CHEAPEST_FIRST" = "true" ] && [ -f "$COST_TABLE" ]; then
|
|
|
144
153
|
| map(.value) | join(" ")' "$COST_TABLE" 2>/dev/null || printf '%s' "$CANDIDATES")
|
|
145
154
|
fi
|
|
146
155
|
|
|
156
|
+
words() { tr -s ' ' <<< "$1" | sed 's/^ //; s/ $//'; }
|
|
157
|
+
sorted_words() { tr ' ' '\n' <<< "$1" | grep -v '^$' | sort | tr '\n' ' '; }
|
|
158
|
+
|
|
159
|
+
LEARNED_ON=$(jq -r '.global.modelRouting.learned.enabled // false' "$PREFS" 2>/dev/null)
|
|
160
|
+
if [ "$LEARNED_ON" = "true" ] && command -v node >/dev/null 2>&1 \
|
|
161
|
+
&& [ -f "$HERE/../scripts/route-learn.mjs" ]; then
|
|
162
|
+
LEARNED=$(node "$HERE/../scripts/route-learn.mjs" choose --call-site "$CALL_SITE" \
|
|
163
|
+
--task-kind "$TASK_KIND" --complexity "$COMPLEXITY" --task-id "$TASK_ID" \
|
|
164
|
+
--candidates "$CANDIDATES" 2>/dev/null) || LEARNED=""
|
|
165
|
+
if [ -n "$LEARNED" ] && [ "$(sorted_words "$LEARNED")" = "$(sorted_words "$CANDIDATES")" ]; then
|
|
166
|
+
[ "$(words "$LEARNED")" != "$(words "$CANDIDATES")" ] && STRATEGY_NOTE="learned"
|
|
167
|
+
CANDIDATES="$LEARNED"
|
|
168
|
+
fi
|
|
169
|
+
fi
|
|
170
|
+
|
|
147
171
|
# The fable rung answers only when the fable switch is on (FABLE_ON, read
|
|
148
172
|
# above). Routing is a policy over what is available; it is not a second way to
|
|
149
173
|
# turn a rung on, or `/multi-agent:model off` would stop meaning anything the
|
|
@@ -100,6 +100,141 @@ export function foldWithIndex(text) {
|
|
|
100
100
|
return { folded, start, end };
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// Bounded decode: what a run of base64, hex or rot13 text says once decoded
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The work decodedVariants does is capped: `maxDepth` decode steps on top of
|
|
108
|
+
* one another, the first `maxInputChars` of the text, `maxVariants` decoded
|
|
109
|
+
* copies and `maxDecodedChars` decoded characters in all. A decoded run is kept
|
|
110
|
+
* only when it is at least `minBytes` long and `minPrintable` of its bytes are
|
|
111
|
+
* printable ASCII, so random bytes (a hash, an image) are dropped.
|
|
112
|
+
*/
|
|
113
|
+
export const DECODE_LIMITS = Object.freeze({
|
|
114
|
+
maxDepth: 2,
|
|
115
|
+
maxInputChars: 256 * 1024,
|
|
116
|
+
maxVariants: 32,
|
|
117
|
+
maxDecodedChars: 256 * 1024,
|
|
118
|
+
minBytes: 8,
|
|
119
|
+
minPrintable: 0.9,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const B64_RUN = /[A-Za-z0-9+/_-]{16,}={0,2}/g;
|
|
123
|
+
const HEX_RUN = /(?:[0-9a-fA-F]{2}){8,}/g;
|
|
124
|
+
|
|
125
|
+
const B64_VALUE = (() => {
|
|
126
|
+
const v = new Int16Array(128).fill(-1);
|
|
127
|
+
for (let i = 0; i < 26; i++) {
|
|
128
|
+
v[65 + i] = i;
|
|
129
|
+
v[97 + i] = 26 + i;
|
|
130
|
+
}
|
|
131
|
+
for (let i = 0; i < 10; i++) v[48 + i] = 52 + i;
|
|
132
|
+
v[43] = 62;
|
|
133
|
+
v[45] = 62;
|
|
134
|
+
v[47] = 63;
|
|
135
|
+
v[95] = 63;
|
|
136
|
+
return v;
|
|
137
|
+
})();
|
|
138
|
+
|
|
139
|
+
/** Standard or URL-safe base64, padding optional, as one byte per char. */
|
|
140
|
+
export function decodeBase64(run) {
|
|
141
|
+
const s = run.replace(/=+$/, "");
|
|
142
|
+
let out = "";
|
|
143
|
+
let acc = 0;
|
|
144
|
+
let bits = 0;
|
|
145
|
+
for (let i = 0; i < s.length; i++) {
|
|
146
|
+
const v = B64_VALUE[s.charCodeAt(i)];
|
|
147
|
+
if (v === undefined || v < 0) return null;
|
|
148
|
+
acc = ((acc << 6) | v) & 0xffffff;
|
|
149
|
+
bits += 6;
|
|
150
|
+
if (bits >= 8) {
|
|
151
|
+
bits -= 8;
|
|
152
|
+
out += String.fromCharCode((acc >> bits) & 0xff);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Pairs of hex digits as one byte per char. */
|
|
159
|
+
export function decodeHex(run) {
|
|
160
|
+
let out = "";
|
|
161
|
+
for (let i = 0; i + 1 < run.length; i += 2) {
|
|
162
|
+
out += String.fromCharCode(parseInt(run.slice(i, i + 2), 16));
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Letters rotated by 13; everything else unchanged. */
|
|
168
|
+
export function rot13(text) {
|
|
169
|
+
let out = "";
|
|
170
|
+
for (let i = 0; i < text.length; i++) {
|
|
171
|
+
const c = text.charCodeAt(i);
|
|
172
|
+
if (c >= 65 && c <= 90) out += String.fromCharCode(((c - 65 + 13) % 26) + 65);
|
|
173
|
+
else if (c >= 97 && c <= 122) out += String.fromCharCode(((c - 97 + 13) % 26) + 97);
|
|
174
|
+
else out += text[i];
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function printable(bytes, minBytes, minPrintable) {
|
|
180
|
+
if (bytes.length < minBytes) return false;
|
|
181
|
+
let ok = 0;
|
|
182
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
183
|
+
const c = bytes.charCodeAt(i);
|
|
184
|
+
if ((c >= 0x20 && c <= 0x7e) || c === 9 || c === 10 || c === 13) ok++;
|
|
185
|
+
}
|
|
186
|
+
return ok / bytes.length >= minPrintable;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Decoded copies of the base64, hex and rot13 text inside `text`, for a
|
|
191
|
+
* matcher to run over next to the text itself. Deterministic: base64 runs in
|
|
192
|
+
* order of position, then hex runs, then the rot13 of the whole text (first
|
|
193
|
+
* step only); each later step decodes the copies of the step before. Every
|
|
194
|
+
* copy names how it was reached (`base64`, `hex`, `rot13`, `base64>hex`).
|
|
195
|
+
*
|
|
196
|
+
* @param {string} text
|
|
197
|
+
* @param {Partial<typeof DECODE_LIMITS>} [limits]
|
|
198
|
+
* @returns {{kind: string, text: string}[]}
|
|
199
|
+
*/
|
|
200
|
+
export function decodedVariants(text, limits = {}) {
|
|
201
|
+
const L = { ...DECODE_LIMITS, ...limits };
|
|
202
|
+
const out = [];
|
|
203
|
+
const seen = new Set();
|
|
204
|
+
let budget = L.maxDecodedChars;
|
|
205
|
+
const keep = (kind, decoded, next) => {
|
|
206
|
+
if (out.length >= L.maxVariants || decoded.length > budget || seen.has(decoded)) return;
|
|
207
|
+
seen.add(decoded);
|
|
208
|
+
budget -= decoded.length;
|
|
209
|
+
out.push({ kind, text: decoded });
|
|
210
|
+
next.push({ kind, text: decoded });
|
|
211
|
+
};
|
|
212
|
+
let frontier = [{ kind: "", text: String(text ?? "").slice(0, L.maxInputChars) }];
|
|
213
|
+
for (let depth = 1; depth <= L.maxDepth && frontier.length; depth++) {
|
|
214
|
+
const next = [];
|
|
215
|
+
for (const item of frontier) {
|
|
216
|
+
const prefix = item.kind ? `${item.kind}>` : "";
|
|
217
|
+
for (const [kind, re, decode, ratio] of [
|
|
218
|
+
["base64", B64_RUN, decodeBase64, 0.75],
|
|
219
|
+
["hex", HEX_RUN, decodeHex, 0.5],
|
|
220
|
+
]) {
|
|
221
|
+
re.lastIndex = 0;
|
|
222
|
+
for (const m of item.text.matchAll(re)) {
|
|
223
|
+
if (out.length >= L.maxVariants) break;
|
|
224
|
+
if (m[0].length * ratio > budget) continue;
|
|
225
|
+
const bytes = decode(m[0]);
|
|
226
|
+
if (bytes !== null && printable(bytes, L.minBytes, L.minPrintable)) {
|
|
227
|
+
keep(prefix + kind, bytes, next);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (depth === 1 && /[A-Za-z]/.test(item.text)) keep("rot13", rot13(item.text), []);
|
|
232
|
+
}
|
|
233
|
+
frontier = next;
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
|
|
103
238
|
if (invokedDirectly(import.meta.url)) {
|
|
104
239
|
const nul = process.argv.includes("--nul");
|
|
105
240
|
let input = "";
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
|
|
51
51
|
import { readFileSync } from "node:fs";
|
|
52
52
|
import { invokedDirectly } from "./invoked-directly.mjs";
|
|
53
|
-
import { TABLE_LOADED, normalizeForMatch } from "./normalize-text.mjs";
|
|
53
|
+
import { TABLE_LOADED, decodedVariants, normalizeForMatch } from "./normalize-text.mjs";
|
|
54
54
|
import { SECRET_PATTERNS } from "./secret-patterns.generated.mjs";
|
|
55
55
|
|
|
56
56
|
/**
|
|
@@ -78,7 +78,7 @@ export const RULES = [
|
|
|
78
78
|
{
|
|
79
79
|
name: "email-address",
|
|
80
80
|
certain: false,
|
|
81
|
-
re: /\b[A-Za-z0-9._%+-]
|
|
81
|
+
re: /\b[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,63}\b/g,
|
|
82
82
|
},
|
|
83
83
|
// An absolute path under /Users or /home names the operator.
|
|
84
84
|
{ name: "home-directory-path", certain: false, re: /\/(?:Users|home)\/[A-Za-z0-9_.-]+\//g },
|
|
@@ -120,8 +120,15 @@ export const SURFACES = [
|
|
|
120
120
|
const NEEDS_FOLD = /[^\t -~]/;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
+
* The certain rules also run over the bounded decode of each line
|
|
124
|
+
* (normalize-text.mjs decodedVariants): a token wrapped in base64, hex or
|
|
125
|
+
* rot13 is a token all the same, and the receiving end can undo the wrapping.
|
|
126
|
+
* Such a finding carries `encoding`, the decode path that revealed it. The
|
|
127
|
+
* uncertain rules do not: an email address inside a decoded blob is not worth
|
|
128
|
+
* a report.
|
|
129
|
+
*
|
|
123
130
|
* @param {string} text
|
|
124
|
-
* @returns {{rule: string, certain: boolean, line: number}[]}
|
|
131
|
+
* @returns {{rule: string, certain: boolean, line: number, encoding?: string}[]}
|
|
125
132
|
*/
|
|
126
133
|
export function scan(text) {
|
|
127
134
|
// Without the fold table a disguised credential would pass as clean text,
|
|
@@ -135,6 +142,7 @@ export function scan(text) {
|
|
|
135
142
|
// A credential written with an invisible character or a look-alike letter
|
|
136
143
|
// still matches: the certain rules also run on the folded line.
|
|
137
144
|
const folded = NEEDS_FOLD.test(lines[i]) ? normalizeForMatch(lines[i]) : lines[i];
|
|
145
|
+
let decoded = null;
|
|
138
146
|
for (const rule of RULES) {
|
|
139
147
|
// `lastIndex` survives between calls on a /g regex and would make every
|
|
140
148
|
// second line skip its start. Reset per line.
|
|
@@ -146,6 +154,16 @@ export function scan(text) {
|
|
|
146
154
|
}
|
|
147
155
|
if (hit) {
|
|
148
156
|
findings.push({ rule: rule.name, certain: rule.certain, line: i + 1 });
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (!rule.certain) continue;
|
|
160
|
+
decoded ??= decodedVariants(folded);
|
|
161
|
+
const via = decoded.find((v) => {
|
|
162
|
+
rule.re.lastIndex = 0;
|
|
163
|
+
return rule.re.test(v.text);
|
|
164
|
+
});
|
|
165
|
+
if (via) {
|
|
166
|
+
findings.push({ rule: rule.name, certain: true, line: i + 1, encoding: via.kind });
|
|
149
167
|
}
|
|
150
168
|
}
|
|
151
169
|
}
|