@plune-ai/cairn 0.6.0 → 0.8.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/README.md +3 -1
- package/dist/agent/finalize.d.ts +4 -0
- package/dist/agent/finalize.d.ts.map +1 -1
- package/dist/agent/finalize.js +8 -1
- package/dist/agent/finalize.js.map +1 -1
- package/dist/agent/graph.d.ts +9 -0
- package/dist/agent/graph.d.ts.map +1 -1
- package/dist/agent/graph.js +9 -1
- package/dist/agent/graph.js.map +1 -1
- package/dist/agent/index.d.ts +9 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +93 -34
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/repair-loop.d.ts +17 -1
- package/dist/agent/repair-loop.d.ts.map +1 -1
- package/dist/agent/repair-loop.js +88 -5
- package/dist/agent/repair-loop.js.map +1 -1
- package/dist/agent/summary.d.ts +3 -0
- package/dist/agent/summary.d.ts.map +1 -1
- package/dist/agent/summary.js +5 -0
- package/dist/agent/summary.js.map +1 -1
- package/dist/api/cases.d.ts +4 -0
- package/dist/api/cases.d.ts.map +1 -1
- package/dist/api/cases.js.map +1 -1
- package/dist/artifacts/contract.d.ts +62 -0
- package/dist/artifacts/contract.d.ts.map +1 -0
- package/dist/artifacts/contract.js +58 -0
- package/dist/artifacts/contract.js.map +1 -0
- package/dist/artifacts/report.d.ts +9 -0
- package/dist/artifacts/report.d.ts.map +1 -1
- package/dist/artifacts/report.js +26 -0
- package/dist/artifacts/report.js.map +1 -1
- package/dist/artifacts/testcase-md.d.ts +2 -0
- package/dist/artifacts/testcase-md.d.ts.map +1 -1
- package/dist/artifacts/testcase-md.js +8 -1
- package/dist/artifacts/testcase-md.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +35 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +101 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.d.ts +10 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +2 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/core/config.d.ts +7 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +4 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/modalities/api.d.ts.map +1 -1
- package/dist/core/modalities/api.js +10 -1
- package/dist/core/modalities/api.js.map +1 -1
- package/dist/core/modalities/explore.d.ts.map +1 -1
- package/dist/core/modalities/explore.js +7 -1
- package/dist/core/modalities/explore.js.map +1 -1
- package/dist/decider/capabilities.d.ts +15 -0
- package/dist/decider/capabilities.d.ts.map +1 -0
- package/dist/decider/capabilities.js +87 -0
- package/dist/decider/capabilities.js.map +1 -0
- package/dist/decider/client-http.d.ts +27 -0
- package/dist/decider/client-http.d.ts.map +1 -0
- package/dist/decider/client-http.js +134 -0
- package/dist/decider/client-http.js.map +1 -0
- package/dist/decider/guarded.d.ts +18 -0
- package/dist/decider/guarded.d.ts.map +1 -0
- package/dist/decider/guarded.js +48 -0
- package/dist/decider/guarded.js.map +1 -0
- package/dist/decider/index.d.ts +61 -0
- package/dist/decider/index.d.ts.map +1 -0
- package/dist/decider/index.js +191 -0
- package/dist/decider/index.js.map +1 -0
- package/dist/decider/redact.d.ts +6 -0
- package/dist/decider/redact.d.ts.map +1 -0
- package/dist/decider/redact.js +265 -0
- package/dist/decider/redact.js.map +1 -0
- package/dist/decider/types.d.ts +139 -0
- package/dist/decider/types.d.ts.map +1 -0
- package/dist/decider/types.js +21 -0
- package/dist/decider/types.js.map +1 -0
- package/dist/decider/uses/coverage.d.ts +37 -0
- package/dist/decider/uses/coverage.d.ts.map +1 -0
- package/dist/decider/uses/coverage.js +63 -0
- package/dist/decider/uses/coverage.js.map +1 -0
- package/dist/decider/uses/locator-heal.d.ts +69 -0
- package/dist/decider/uses/locator-heal.d.ts.map +1 -0
- package/dist/decider/uses/locator-heal.js +216 -0
- package/dist/decider/uses/locator-heal.js.map +1 -0
- package/dist/decider/uses/repair-triage.d.ts +40 -0
- package/dist/decider/uses/repair-triage.d.ts.map +1 -0
- package/dist/decider/uses/repair-triage.js +94 -0
- package/dist/decider/uses/repair-triage.js.map +1 -0
- package/dist/design/critique.d.ts.map +1 -1
- package/dist/design/critique.js +3 -0
- package/dist/design/critique.js.map +1 -1
- package/dist/design/index.d.ts.map +1 -1
- package/dist/design/index.js +4 -0
- package/dist/design/index.js.map +1 -1
- package/dist/design/schema.d.ts +3 -0
- package/dist/design/schema.d.ts.map +1 -1
- package/dist/design/schema.js.map +1 -1
- package/dist/eval/gap-cases.d.ts.map +1 -1
- package/dist/eval/gap-cases.js +2 -0
- package/dist/eval/gap-cases.js.map +1 -1
- package/dist/eval/judge.d.ts +12 -0
- package/dist/eval/judge.d.ts.map +1 -1
- package/dist/eval/judge.js +51 -0
- package/dist/eval/judge.js.map +1 -1
- package/dist/flow/crawl.d.ts +5 -0
- package/dist/flow/crawl.d.ts.map +1 -1
- package/dist/flow/crawl.js +0 -0
- package/dist/flow/crawl.js.map +1 -1
- package/dist/llm/cost.d.ts +2 -1
- package/dist/llm/cost.d.ts.map +1 -1
- package/dist/llm/cost.js +3 -2
- package/dist/llm/cost.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +2 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +8 -7
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +9 -2
- package/dist/mcp/tools.js.map +1 -1
- package/dist/telemetry/index.d.ts +23 -0
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +44 -1
- package/dist/telemetry/index.js.map +1 -1
- package/dist/tui/screens/summary-screen.d.ts.map +1 -1
- package/dist/tui/screens/summary-screen.js +10 -1
- package/dist/tui/screens/summary-screen.js.map +1 -1
- package/dist/validate/runner.d.ts.map +1 -1
- package/dist/validate/runner.js +19 -1
- package/dist/validate/runner.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Values that must never reach a decider (spec §3.7). Cairn never PUTS knowledge, storageState, screenshots
|
|
3
|
+
* or env into a state — but a designed case can ECHO a credential it read in a knowledge file ("type
|
|
4
|
+
* Sup3rS3cret! into Password"), and a test error can echo a typed value. So every state and every question
|
|
5
|
+
* is scrubbed of the values that look like secrets in this run's knowledge and environment.
|
|
6
|
+
*
|
|
7
|
+
* BEST-EFFORT, weighed by what a wrong guess costs: a missed secret leaves the machine; a word scrubbed by
|
|
8
|
+
* mistake damages every input it appears in. So a secret word anywhere on a line only POINTS at values, and
|
|
9
|
+
* of those only credential-shaped ones are taken (`Qwerty123!`, `sk_live_…`, `admin@test`) — never a plain word
|
|
10
|
+
* like `required` or `name` — unless a label whose head word names the secret says the value IS one
|
|
11
|
+
* (`Password: qwerty`). A credential-shaped secret is scrubbed wherever it appears (`Qwerty123!x` included); a
|
|
12
|
+
* plain one only as a whole token, so it can never eat into a longer word.
|
|
13
|
+
*/
|
|
14
|
+
// A secret word, anywhere on a line, as a whole word.
|
|
15
|
+
const SECRET_WORD = /(?<![\p{L}\p{N}])(?:pass(?:words?|wd|phrase|code)?|pwd|secrets?|tokens?|(?:api)?keys?|otp|pin|пін|пин|credentials?|creds|парол\p{L}*|токен\p{L}*|секрет\p{L}*|ключ\p{L}*|креденшел\p{L}*|облікові\s+дані|учетные\s+данные)(?![\p{L}\p{N}])/iu;
|
|
16
|
+
// A label whose HEAD word is a secret word names the secret itself. English puts the head last ("Admin
|
|
17
|
+
// password", "Stripe key", "PIN code"); Ukrainian/Russian first or last, in the nominative ("Пароль
|
|
18
|
+
// адміністратора", "Тестовий пароль", "ПІН-код") — "Password rules" and "Правила пароля" only talk about one.
|
|
19
|
+
const EN_SECRET_HEAD = /(?:^|[^\p{L}\p{N}])(?:pass(?:words?|wd|phrase|code)?|pwd|secrets?|tokens?|keys?|(?:otp|pin)(?:[\s-]?code)?|credentials?|creds)$/iu;
|
|
20
|
+
const SLAVIC_HEAD = "(?:парол[ьіи]|токен[иы]?|секрет[иы]?|ключ[іи]?|креденшел[иі]|облікові\\s+дані|учетные\\s+данные|(?:otp|pin|пін|пин)(?:-?код)?)";
|
|
21
|
+
const SLAVIC_SECRET_HEAD = new RegExp(`^${SLAVIC_HEAD}(?![\\p{L}\\p{N}])|(?<![\\p{L}\\p{N}])${SLAVIC_HEAD}$`, "iu");
|
|
22
|
+
/**
|
|
23
|
+
* "Forgot password", "Change password", "Змінити пароль" name a feature or a link; "Empty password", "Wrong
|
|
24
|
+
* password", "Порожній пароль" a test condition (`Empty password: "Password is required"` quotes a message) —
|
|
25
|
+
* none of them the secret.
|
|
26
|
+
*/
|
|
27
|
+
const ACTION_HEAD = /(?:^|[^\p{L}\p{N}])(?:forgot(?:ten)?|reset|change|recover|restore|update|show|hide|toggle|remember|manage|edit|empty|blank|wrong|invalid|incorrect|short|weak|missing|забули|змінити|скинути|відновити|показати|сховати|приховати|порожн\p{L}*|невірн\p{L}*|неправильн\p{L}*|коротк\p{L}*|слаб\p{L}*|изменить|сменить|поменять|сбросить|восстановить|забыли|показать|скрыть|пуст\p{L}*|неверн\p{L}*)(?:\s+(?:your|the|my|свій|ваш|свой))?\s+\S+$/iu;
|
|
28
|
+
/** Env names that end in a secret word (`DB_PASS`, `GITHUB_TOKEN`, `STRIPE_KEY`) or carry SECRET / PASSWORD
|
|
29
|
+
* anywhere (`SECRET_KEY_BASE`) — not `TOKEN_TTL`, not a public key. */
|
|
30
|
+
const SECRET_ENV = /(?:^|_)(?:PASS(?:WORDS?|WD|PHRASE|CODE)?|PWD|SECRETS?|TOKENS?|KEYS?|OTP|PIN|CREDENTIALS?|CREDS)$|SECRET|PASSWORD/i;
|
|
31
|
+
/** …of which a password variable counts whatever its value looks like (`DB_PASSWORD=postgres`). */
|
|
32
|
+
const PASSWORD_ENV = /(?:^|_)(?:PASS(?:WORDS?|WD|PHRASE|CODE)?|PWD)$/i;
|
|
33
|
+
const PUBLIC_ENV = /(?:^|_)(?:PUBLIC|PUBLISHABLE)_KEYS?$/i;
|
|
34
|
+
/** Never a secret: flags, and the words a field list puts after "Password:". */
|
|
35
|
+
const TRIVIAL = /^(?:true|false|yes|no|on|off|null|none|undefined|empty|blank|enabled|disabled|required|optional|hidden|visible|masked|mandatory|обов['’]язков\p{L}*|необов['’]язков\p{L}*|порожн\p{L}*|пуст\p{L}*|немає|нема)$/iu;
|
|
36
|
+
/** Drops trailing characters of a class — a loop, not a `[…]+$` pattern, which rescans a long run from every position. */
|
|
37
|
+
const trimEnd = (s, cls) => {
|
|
38
|
+
let end = s.length;
|
|
39
|
+
while (end > 0 && cls.test(s[end - 1]))
|
|
40
|
+
end -= 1;
|
|
41
|
+
return s.slice(0, end);
|
|
42
|
+
};
|
|
43
|
+
/** Markdown, quotes and punctuation around a label or a value: `**Password:**`, `` `sk-…` ``, `«…»`, `(admin)`. */
|
|
44
|
+
const strip = (s) => trimEnd(s.trim().replace(/^[\s*_`"'([«“„‘]+/u, ""), /[\s*_`"')\].,;:»”’]/u);
|
|
45
|
+
/** A value written in quotes is meant literally (single quotes excluded: they are apostrophes too). */
|
|
46
|
+
const QUOTED = /[`"«“„]([^`"«»“”„\n]{4,})[`"»”“]/gu;
|
|
47
|
+
/** …and a value that STARTS with a quote is that quote, spaces and all: `Password: "correct horse battery"`. */
|
|
48
|
+
const QUOTED_VALUE = /^[`"«“„]([^`"«»“”„\n]{4,})[`"»”“]/u;
|
|
49
|
+
/** A column that describes a field or records a result rather than holding its value: `| Field | Type |`,
|
|
50
|
+
* `| Поле | Роль |`, `| Status |`, `| Min |` — from a word start, so `Information` is not `format`, and a bound as a
|
|
51
|
+
* whole word (`Minimum`, `Мінімальне значення`), so `Maxim` stays a name. */
|
|
52
|
+
const SPEC_COLUMN = /(?<![\p{L}\p{N}])(?:type|role|kind|format|rule|validat|constraint|selector|locator|element|widget|controls?(?!\p{L})|descri|note|comment|behavio|expect|status|result|actual|length|тип|роль|формат|правил|валідац|валидац|опис|примітк|примечан|очікуван|ожидаем|селектор|локатор|елемент|элемент|статус|результат|фактичн|довжин|длин|(?:(?:min|max)(?:imum|imal)?|мін(?:імум|імальн\p{L}*)?|мин(?:имум|имальн\p{L}*)?|макс(?:имум|имальн\p{L}*)?)(?!\p{L}))/iu;
|
|
53
|
+
/** A type word describes a field and is never a secret: `| Password | textbox |`, `Password: password` — a password
|
|
54
|
+
* `password` protects nothing, and taking it would cut the word out of every state. */
|
|
55
|
+
const SPEC_WORD = /^(?:password|text|textbox|textarea|string|email|e-mail|number|numeric|integer|int|boolean|bool|checkbox|radio|input|field|button|select|combobox|date|datetime|tel|url|search|пароль|текст|рядок|строка|число)$/iu;
|
|
56
|
+
/** A first header cell that makes every column an instance: `| | Staging | Production |`, `| Role | Admin | Viewer |`. */
|
|
57
|
+
const MATRIX_HEAD = /(?<![\p{L}\p{N}])(?:environment|env(?!\p{L})|account|role|user|середовищ|оточенн|окружени|акаунт|роль|користувач)/iu;
|
|
58
|
+
/** …as do columns that all name an environment: `| Parameter | Staging | Production |`, `| QA1 | QA2 |`,
|
|
59
|
+
* `| Staging EU | Prod (US) |`. */
|
|
60
|
+
const ENV_NAME = /^(?:staging|stage|stg|prod|production|dev|development|qa|test|testing|uat|local|demo|sandbox|pre-?prod|beta|integration|live|тест|прод|дев|стейдж\p{L}*)(?:[\s_-]*(?:\d+|[a-z]{2}|\([^)]*\)?))?$/iu;
|
|
61
|
+
/** Outside a matrix, a column named for the value holds it — the header's last word, and not a default, invalid or
|
|
62
|
+
* old value: `| Field | Required | Value |`, `| Test data |`, `| Тестове значення |`; not `| Data source |`. */
|
|
63
|
+
const VALUE_COLUMN = /(?<![\p{L}\p{N}])(?<!(?:default|invalid|wrong|old|initial|(?:невалідн|неправильн|невірн|некоректн|стар|початков|невалидн|неверн|некорректн|начальн)\p{L}*)\s+)(?:values?|examples?|data|значення|значение|приклад|пример|дані|данные)$/iu;
|
|
64
|
+
/** A key–value table's layout, read once from its header: which columns describe the field, whether every other
|
|
65
|
+
* column holds a value (a matrix), and the column named for the value. */
|
|
66
|
+
const tableLayout = (header) => {
|
|
67
|
+
const spec = header.map((h) => SPEC_COLUMN.test(h));
|
|
68
|
+
const values = header.flatMap((h, i) => (i > 0 && !spec[i] ? [i] : []));
|
|
69
|
+
const matrix = !header[0] || MATRIX_HEAD.test(header[0]) || values.every((i) => ENV_NAME.test(strip(header[i])));
|
|
70
|
+
return { spec, matrix, named: values.find((i) => VALUE_COLUMN.test(strip(header[i]))) };
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Shaped like a credential rather than a word: letters mixed with digits (not "6-digit"), or a symbol other
|
|
74
|
+
* than a word's own hyphen, apostrophe or dot, or a closing "?"/"!" (not "e-mail", "one-time", "password?");
|
|
75
|
+
* all digits (a PIN) only when asked.
|
|
76
|
+
*/
|
|
77
|
+
function credentialShaped(t, digitsOnly = false) {
|
|
78
|
+
if (t.length < 4 || TRIVIAL.test(t))
|
|
79
|
+
return false;
|
|
80
|
+
if (/^\p{N}+$/u.test(t))
|
|
81
|
+
return digitsOnly;
|
|
82
|
+
if (/\p{L}/u.test(t) && /\p{N}/u.test(t))
|
|
83
|
+
return !/^\p{N}+[-‑–]\p{L}+$/u.test(t);
|
|
84
|
+
return /[^\p{L}\p{N}\-‑–'’ʼ.]/u.test(trimEnd(t, /[?!]/u));
|
|
85
|
+
}
|
|
86
|
+
/** Parenthesised commentary out: "Password (admin)", "(the admin's)". `[^()]` keeps an unclosed "(" run linear. */
|
|
87
|
+
const dropParens = (s) => s.replace(/\([^()]*\)/g, " ");
|
|
88
|
+
function secretHead(rawLabel) {
|
|
89
|
+
const label = strip(dropParens(rawLabel)).replace(/\s+(?:for|of)\s.*$/i, ""); // "… for the admin"
|
|
90
|
+
const m = EN_SECRET_HEAD.exec(label) ?? SLAVIC_SECRET_HEAD.exec(label);
|
|
91
|
+
if (!m)
|
|
92
|
+
return undefined;
|
|
93
|
+
const w = m[0].toLowerCase();
|
|
94
|
+
const head = /phrase/.test(w)
|
|
95
|
+
? "passphrase"
|
|
96
|
+
: /otp|pin|пін|пин|код|code/.test(w)
|
|
97
|
+
? "code"
|
|
98
|
+
: /pass|pwd|парол/.test(w)
|
|
99
|
+
? "password"
|
|
100
|
+
: /cred|креденшел|дані|данные/.test(w)
|
|
101
|
+
? "credentials"
|
|
102
|
+
: "other";
|
|
103
|
+
// "Forgot password: /forgot-password", "Empty password: "…"" — but "Reset PIN: 4711" is still a code (digits only)
|
|
104
|
+
return head !== "code" && ACTION_HEAD.test(label) ? undefined : head;
|
|
105
|
+
}
|
|
106
|
+
/** What a value under a secret head adds, whatever the rest of the line says. */
|
|
107
|
+
function headValues(head, value) {
|
|
108
|
+
const quoted = QUOTED_VALUE.exec(value.trim())?.[1];
|
|
109
|
+
const v = quoted ?? strip(dropParens(value));
|
|
110
|
+
if (head !== "passphrase" && /^\/|:\/\//.test(v))
|
|
111
|
+
return []; // a path or a URL names a page, not a secret
|
|
112
|
+
const first = strip(v.split(/[\s,;]+/)[0] ?? "");
|
|
113
|
+
const pair = v.split("/").map((p) => p.trim()); // "login / password"
|
|
114
|
+
switch (head) {
|
|
115
|
+
case "passphrase":
|
|
116
|
+
return [v]; // spaces are part of it
|
|
117
|
+
case "password":
|
|
118
|
+
case "credentials":
|
|
119
|
+
if (pair.length === 2)
|
|
120
|
+
return [strip(pair[1])]; // "Email / password: qa@acme.test / qwerty"
|
|
121
|
+
if (head === "credentials")
|
|
122
|
+
return [];
|
|
123
|
+
return quoted !== undefined || !/\s/.test(v) ? [v] : []; // a weak password is still one — but "required, 8-64 characters" is prose
|
|
124
|
+
case "code":
|
|
125
|
+
return credentialShaped(first, true) ? [first] : []; // "PIN: 4711, same for all" — not "6-digit code…"
|
|
126
|
+
case "other":
|
|
127
|
+
// "Key: abcd-1234", "API key = `sk-live-abcdef`" — not "Sort key: name", nor `Sort key: "name"`
|
|
128
|
+
if (quoted !== undefined && !/\s/.test(v) && /[-_]/.test(v))
|
|
129
|
+
return [v];
|
|
130
|
+
return credentialShaped(first) ? [first] : [];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** `label: value`, `label = value` or `label — value` / `label - value`; bullets and quotes tolerated. */
|
|
134
|
+
const LINE = /^\s*(?:>\s*)?(?:[-*+]\s+|\d+[.)]\s+)?(.{1,60}?)(?:\s*[:=:]|\s+[—–]|\s+-(?=\s))\s*(.+)$/u;
|
|
135
|
+
/**
|
|
136
|
+
* A login written next to its credential with no label at all: "Test account: qa@acme.test / Qwerty123!". The
|
|
137
|
+
* lookbehind starts a match only at a token's first character — without it a long run of word characters is
|
|
138
|
+
* rescanned from every position.
|
|
139
|
+
*/
|
|
140
|
+
const LOGIN_PAIR = /(?<![\p{L}\p{N}._%+-])[\p{L}\p{N}._%+-]+@[\p{L}\p{N}.-]+\s*\/\s*(\S+)/gu;
|
|
141
|
+
/**
|
|
142
|
+
* "Login: admin / Password: qwerty", "User: qa@acme.test, Password: qwerty", "Admin - Password: qwerty" — one label
|
|
143
|
+
* per segment; a dash only splits before another "label:".
|
|
144
|
+
*/
|
|
145
|
+
const SEGMENT = /(?:[,;]|\s[/|—–-])\s+(?=[^,;:]{1,40}[:=:])/;
|
|
146
|
+
export function secretValues(knowledgeText, env) {
|
|
147
|
+
const out = new Set();
|
|
148
|
+
const add = (v) => {
|
|
149
|
+
const s = strip(v);
|
|
150
|
+
if (s.length >= 4 && !TRIVIAL.test(s) && !SPEC_WORD.test(s))
|
|
151
|
+
out.add(s);
|
|
152
|
+
};
|
|
153
|
+
// A Markdown table: the row above its |---| rule is the header; a header cell naming a secret marks a column.
|
|
154
|
+
let above = [];
|
|
155
|
+
let table; // undefined until the rule: a row above it may be the header
|
|
156
|
+
let columns = [];
|
|
157
|
+
for (const line of knowledgeText.split(/\r?\n/)) {
|
|
158
|
+
for (const p of line.matchAll(LOGIN_PAIR)) {
|
|
159
|
+
const v = strip(p[1] ?? "");
|
|
160
|
+
// Not a second login ("viewer@… / editor@…"), not a phone number ("qa@… / +380 44 …").
|
|
161
|
+
if (!v.includes("@") && !/^\+?[\d()-]+$/.test(v) && credentialShaped(v))
|
|
162
|
+
add(v);
|
|
163
|
+
}
|
|
164
|
+
if (/^\s*\|/.test(line)) {
|
|
165
|
+
const cells = line.split("|").slice(1, -1).map((c) => c.trim());
|
|
166
|
+
if (cells.length > 0 && cells.every((c) => /^:?-+:?$/.test(c))) {
|
|
167
|
+
columns = above.flatMap((c, at) => (SECRET_WORD.test(c) ? [{ at, head: secretHead(c) }] : []));
|
|
168
|
+
table = tableLayout(above);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
above = cells;
|
|
172
|
+
for (const { at, head } of columns) {
|
|
173
|
+
const cell = cells[at] ?? ""; // | admin | admin@acme.test | Adm1n!2024 |
|
|
174
|
+
for (const v of head ? headValues(head, cell) : [])
|
|
175
|
+
add(v);
|
|
176
|
+
for (const t of cell.split(/[\s,;/]+/))
|
|
177
|
+
if (credentialShaped(strip(t)))
|
|
178
|
+
add(t);
|
|
179
|
+
}
|
|
180
|
+
// A key–value row — | Password | qwerty | — holds one value: in the column named for it (| Value |, | Test data |),
|
|
181
|
+
// else in the first that neither describes the field (| Type |, | Status |) nor holds a flag (| yes |, | ✓ |) or
|
|
182
|
+
// nothing. The columns past it hold results or translations (| error |, | Passwort |); a matrix holds one per column.
|
|
183
|
+
const rowHead = table && cells[0] ? secretHead(cells[0]) : undefined;
|
|
184
|
+
if (table && rowHead) {
|
|
185
|
+
const { spec, matrix, named } = table;
|
|
186
|
+
const values = cells.flatMap((_, i) => (i > 0 && !spec[i] ? [i] : []));
|
|
187
|
+
const holds = (i) => {
|
|
188
|
+
const s = strip(cells[i] ?? "");
|
|
189
|
+
return s.length >= 4 && !TRIVIAL.test(s);
|
|
190
|
+
};
|
|
191
|
+
const at = matrix ? values : [named ?? values.find(holds)];
|
|
192
|
+
for (const i of at)
|
|
193
|
+
if (i !== undefined)
|
|
194
|
+
for (const v of headValues(rowHead, cells[i] ?? ""))
|
|
195
|
+
add(v);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
above = [];
|
|
200
|
+
table = undefined;
|
|
201
|
+
columns = [];
|
|
202
|
+
}
|
|
203
|
+
const at = line.search(SECRET_WORD);
|
|
204
|
+
if (at < 0)
|
|
205
|
+
continue;
|
|
206
|
+
// Everything after the secret word may hold it — "(password: Adm1n!2024)" included.
|
|
207
|
+
const after = line.slice(at);
|
|
208
|
+
for (const t of after.split(/[\s,;|/:]+/))
|
|
209
|
+
if (credentialShaped(strip(t)))
|
|
210
|
+
add(t);
|
|
211
|
+
// A Markdown heading is a title, not "label: value" — "## Passwords - staging" names a section.
|
|
212
|
+
for (const seg of /^\s*#/.test(line) ? [] : line.split(SEGMENT)) {
|
|
213
|
+
const m = LINE.exec(seg);
|
|
214
|
+
const head = m?.[1] && m[2] ? secretHead(m[1]) : undefined;
|
|
215
|
+
if (head)
|
|
216
|
+
for (const v of headValues(head, m[2]))
|
|
217
|
+
add(v);
|
|
218
|
+
}
|
|
219
|
+
// Any other quote on the line counts only when it looks like a credential — "Forgot password?" does not.
|
|
220
|
+
for (const q of after.matchAll(QUOTED)) {
|
|
221
|
+
const v = q[1] ?? "";
|
|
222
|
+
if (v.split(/\s+/).some((w) => credentialShaped(strip(w))))
|
|
223
|
+
add(v);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const [k, v] of Object.entries(env)) {
|
|
227
|
+
// PWD is the working directory, not a password.
|
|
228
|
+
if (!v || k === "PWD" || !SECRET_ENV.test(k) || PUBLIC_ENV.test(k))
|
|
229
|
+
continue;
|
|
230
|
+
const t = v.trim();
|
|
231
|
+
// An env value is not prose: API_TOKEN=Welcome! is the token, closing "!" and all — VITE_STORAGE_KEY=user is not.
|
|
232
|
+
if (PASSWORD_ENV.test(k) || credentialShaped(t, true) || /[?!]$/.test(t))
|
|
233
|
+
add(v);
|
|
234
|
+
}
|
|
235
|
+
return [...out].sort((a, b) => b.length - a.length); // longest first: a secret containing another is scrubbed whole
|
|
236
|
+
}
|
|
237
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
238
|
+
export function redact(text, secrets) {
|
|
239
|
+
let out = text;
|
|
240
|
+
for (const s of secrets) {
|
|
241
|
+
// A credential-shaped secret anywhere — a negative case's "Qwerty123!x" still carries it; a plain word or a
|
|
242
|
+
// PIN only as a whole token, so a scrubbed "qwerty" never eats into "qwertyuiop", nor "4711" into "14711".
|
|
243
|
+
out = credentialShaped(s)
|
|
244
|
+
? out.split(s).join("‹redacted›")
|
|
245
|
+
: out.replace(new RegExp(`(?<![\\p{L}\\p{N}])${escapeRe(s)}(?![\\p{L}\\p{N}])`, "gu"), "‹redacted›");
|
|
246
|
+
}
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
/** The question's texts are scrubbed too; its option LABELS are the answer contract and stay as they are. */
|
|
250
|
+
export function redactQuestion(q, secrets) {
|
|
251
|
+
const r = (t) => redact(t, secrets);
|
|
252
|
+
switch (q.type) {
|
|
253
|
+
case "noul":
|
|
254
|
+
return { ...q, instructions: r(q.instructions), criteria: { true: r(q.criteria.true), false: r(q.criteria.false) } };
|
|
255
|
+
case "choice":
|
|
256
|
+
return {
|
|
257
|
+
...q,
|
|
258
|
+
instructions: r(q.instructions),
|
|
259
|
+
options: Object.fromEntries(Object.entries(q.options).map(([k, d]) => [k, d === null ? null : r(d)])),
|
|
260
|
+
};
|
|
261
|
+
case "score":
|
|
262
|
+
return { ...q, instructions: r(q.instructions), levels: q.levels.map(r) };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../../src/decider/redact.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,sDAAsD;AACtD,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,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACtG,CAAC;QACJ,KAAK,OAAO;YACV,OAAO,EAAE,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { CostReport } from "../llm/cost.js";
|
|
2
|
+
/**
|
|
3
|
+
* The decision layer's contract (ADR-0022). A System One model — TypeSafe Jev, Convai Laya, or any
|
|
4
|
+
* server speaking Jev's `POST /v1/systemone` — answers typed questions about a state; it never writes
|
|
5
|
+
* text. These are Cairn's own types: the wire format differs on purpose, and `client-http.ts` is the
|
|
6
|
+
* only place that knows it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DECIDER_PROVIDERS: readonly ["jev", "laya", "compat"];
|
|
9
|
+
export type DeciderProvider = (typeof DECIDER_PROVIDERS)[number];
|
|
10
|
+
/** Use points `DECIDER_USES` accepts — nothing else (a typo must not look enabled). */
|
|
11
|
+
export declare const DECIDER_USES: readonly ["repair-triage", "coverage", "locator-heal"];
|
|
12
|
+
export type DeciderUse = (typeof DECIDER_USES)[number];
|
|
13
|
+
export type Question = {
|
|
14
|
+
type: "noul";
|
|
15
|
+
instructions: string;
|
|
16
|
+
/**
|
|
17
|
+
* What a yes and a no mean. Required: measured on laya 0.3.11, a bare yes/no is answered against
|
|
18
|
+
* the text, and these descriptions are what laya's two-option form is asked with (client-http.ts).
|
|
19
|
+
*/
|
|
20
|
+
criteria: {
|
|
21
|
+
true: string;
|
|
22
|
+
false: string;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
type: "choice";
|
|
26
|
+
instructions: string;
|
|
27
|
+
/** label → when it applies (null = the label speaks for itself). The answer is one of these labels. */
|
|
28
|
+
options: Record<string, string | null>;
|
|
29
|
+
} | {
|
|
30
|
+
type: "score";
|
|
31
|
+
instructions: string;
|
|
32
|
+
/** Ordered level descriptions; the answer's value is a position between 0 and levels.length − 1. */
|
|
33
|
+
levels: string[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* `confidence` describes the SHAPE of the answer's distribution, not the chance it is right, and each
|
|
37
|
+
* provider computes it differently — thresholds are calibrated per use and per provider (spec §8.4, §9.5).
|
|
38
|
+
*/
|
|
39
|
+
export type Answer = {
|
|
40
|
+
type: "noul";
|
|
41
|
+
value: boolean;
|
|
42
|
+
p: number;
|
|
43
|
+
confidence: number;
|
|
44
|
+
} | {
|
|
45
|
+
type: "choice";
|
|
46
|
+
value: string;
|
|
47
|
+
dist: Record<string, number>;
|
|
48
|
+
confidence: number;
|
|
49
|
+
} | {
|
|
50
|
+
type: "score";
|
|
51
|
+
value: number;
|
|
52
|
+
dist: number[];
|
|
53
|
+
confidence: number;
|
|
54
|
+
};
|
|
55
|
+
export interface DeciderCaps {
|
|
56
|
+
/** State + its longest question, in characters: each question is encoded together with the state. */
|
|
57
|
+
maxInputChars: number;
|
|
58
|
+
/** One question's own text (instructions + options): laya cuts that part of its input separately. */
|
|
59
|
+
maxQuestionChars: number;
|
|
60
|
+
/** One option as laya renders it (`label: description`, a criterion, a level): laya cuts each at 48 tokens. */
|
|
61
|
+
maxOptionChars: number;
|
|
62
|
+
maxOptions: number;
|
|
63
|
+
maxQuestionsPerCall: number;
|
|
64
|
+
/** USD per 1M tokens; undefined → unknown, the cost line shows n/a. */
|
|
65
|
+
price?: {
|
|
66
|
+
inputPer1M: number;
|
|
67
|
+
outputPer1M: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Parsed `DECIDER*` configuration (config/index.ts). Absent from AppConfig unless a provider is chosen. */
|
|
71
|
+
export interface DeciderConfig {
|
|
72
|
+
provider: DeciderProvider;
|
|
73
|
+
baseUrl: string;
|
|
74
|
+
model: string;
|
|
75
|
+
/** jev: TYPESAFE_API_KEY · laya: LAYA_API_KEY · compat: DECIDER_API_KEY — never another provider's key. */
|
|
76
|
+
apiKey?: string;
|
|
77
|
+
uses: DeciderUse[];
|
|
78
|
+
minConfidence: number;
|
|
79
|
+
timeoutMs: number;
|
|
80
|
+
maxCalls: number;
|
|
81
|
+
/** DECIDER_SHADOW / --decider-shadow: ask, record next to the current path's decision, act on nothing. */
|
|
82
|
+
shadow: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** One shadow-mode observation (spec §7): what the current path did and what the decider would have done. */
|
|
85
|
+
export interface ShadowEntry {
|
|
86
|
+
use: DeciderUse;
|
|
87
|
+
/** What the decider was shown (the state, or a compact description of it). */
|
|
88
|
+
input: unknown;
|
|
89
|
+
/** What the current path decided. */
|
|
90
|
+
current: unknown;
|
|
91
|
+
/** What the decider would have decided, or `{ unavailable: reason }`. */
|
|
92
|
+
decider: unknown;
|
|
93
|
+
confidence?: number;
|
|
94
|
+
latencyMs: number;
|
|
95
|
+
/** 1/0 when the current path makes a comparable decision; absent otherwise (repair-triage: spec §9.3). */
|
|
96
|
+
agreement?: 0 | 1;
|
|
97
|
+
}
|
|
98
|
+
export interface ShadowLog {
|
|
99
|
+
readonly entries: readonly ShadowEntry[];
|
|
100
|
+
record(e: ShadowEntry): void;
|
|
101
|
+
}
|
|
102
|
+
/** What a run tells about its decider: calls made, and every fallback with its reason. */
|
|
103
|
+
export interface DeciderSummary {
|
|
104
|
+
provider: DeciderProvider;
|
|
105
|
+
model: string;
|
|
106
|
+
calls: number;
|
|
107
|
+
fallbacks: {
|
|
108
|
+
use: DeciderUse;
|
|
109
|
+
reason: string;
|
|
110
|
+
}[];
|
|
111
|
+
/** Shadow mode only: its private ledger. An active decider prices into the run's own cost report. */
|
|
112
|
+
cost?: CostReport;
|
|
113
|
+
}
|
|
114
|
+
export interface Decider {
|
|
115
|
+
readonly provider: DeciderProvider;
|
|
116
|
+
readonly model: string;
|
|
117
|
+
readonly caps: DeciderCaps;
|
|
118
|
+
readonly uses: ReadonlySet<DeciderUse>;
|
|
119
|
+
readonly minConfidence: number;
|
|
120
|
+
/** The questions are independent: they share `state` and never see each other's answers. */
|
|
121
|
+
decide<K extends string>(use: DeciderUse, state: string, questions: Record<K, Question>): Promise<Record<K, Answer>>;
|
|
122
|
+
/**
|
|
123
|
+
* The run's secrets scrubbed out of a text, exactly as `decide` scrubs a state. A use point that cuts its state to
|
|
124
|
+
* fit a cap scrubs FIRST: a secret cut in half no longer matches, and half a secret is still one.
|
|
125
|
+
*/
|
|
126
|
+
readonly scrub: (text: string) => string;
|
|
127
|
+
/** Present only in shadow mode: use points record here and act on nothing. */
|
|
128
|
+
readonly shadow?: ShadowLog;
|
|
129
|
+
summary(): DeciderSummary;
|
|
130
|
+
}
|
|
131
|
+
/** Any failure or limit. The call site catches it and takes the path it would have taken without a decider. */
|
|
132
|
+
export declare class DeciderUnavailable extends Error {
|
|
133
|
+
/** HTTP status when the server answered with an error — lets the guard retry 429/5xx once. */
|
|
134
|
+
readonly status?: number | undefined;
|
|
135
|
+
constructor(message: string,
|
|
136
|
+
/** HTTP status when the server answered with an error — lets the guard retry 429/5xx once. */
|
|
137
|
+
status?: number | undefined);
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/decider/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,oCAAqC,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,uFAAuF;AAC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AAA;KAAE,EAAE,CAAC;IACjD,qGAAqG;IACrG,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACvC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,4FAA4F;IAC5F,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACrH;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B,OAAO,IAAI,cAAc,CAAC;CAC3B;AAED,+GAA+G;AAC/G,qBAAa,kBAAmB,SAAQ,KAAK;IAGzC,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;gBAFxB,OAAO,EAAE,MAAM;IACf,8FAA8F;IACrF,MAAM,CAAC,EAAE,MAAM,YAAA;CAK3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The decision layer's contract (ADR-0022). A System One model — TypeSafe Jev, Convai Laya, or any
|
|
3
|
+
* server speaking Jev's `POST /v1/systemone` — answers typed questions about a state; it never writes
|
|
4
|
+
* text. These are Cairn's own types: the wire format differs on purpose, and `client-http.ts` is the
|
|
5
|
+
* only place that knows it.
|
|
6
|
+
*/
|
|
7
|
+
export const DECIDER_PROVIDERS = ["jev", "laya", "compat"];
|
|
8
|
+
/** Use points `DECIDER_USES` accepts — nothing else (a typo must not look enabled). */
|
|
9
|
+
export const DECIDER_USES = ["repair-triage", "coverage", "locator-heal"];
|
|
10
|
+
/** Any failure or limit. The call site catches it and takes the path it would have taken without a decider. */
|
|
11
|
+
export class DeciderUnavailable extends Error {
|
|
12
|
+
status;
|
|
13
|
+
constructor(message,
|
|
14
|
+
/** HTTP status when the server answered with an error — lets the guard retry 429/5xx once. */
|
|
15
|
+
status) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.name = "DeciderUnavailable";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/decider/types.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAGpE,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,eAAe,EAAE,UAAU,EAAE,cAAc,CAAU,CAAC;AA+GnF,+GAA+G;AAC/G,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAIhC;IAHX,YACE,OAAe;IACf,8FAA8F;IACrF,MAAe;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,WAAM,GAAN,MAAM,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { TestCase } from "../../design/index.js";
|
|
2
|
+
import type { Decider } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* coverage (spec §6.2, ADR-0022): the checklist × case matrix as yes/no judgments. An item is covered when
|
|
5
|
+
* some case confidently says yes. Anything short of a confident verdict on every item is `undecided`, and
|
|
6
|
+
* the LLM judge decides exactly as it does without a decider.
|
|
7
|
+
*/
|
|
8
|
+
export type DeciderCoverage = {
|
|
9
|
+
value: number;
|
|
10
|
+
comment: string;
|
|
11
|
+
perItem: {
|
|
12
|
+
item: string;
|
|
13
|
+
covered: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
asked: CoverageAnswer[];
|
|
16
|
+
} | {
|
|
17
|
+
undecided: string;
|
|
18
|
+
asked: CoverageAnswer[];
|
|
19
|
+
};
|
|
20
|
+
/** One asked (case, item) pair as answered — the pilot tunes the threshold on these (spec §9.5). */
|
|
21
|
+
export interface CoverageAnswer {
|
|
22
|
+
case: number;
|
|
23
|
+
item: number;
|
|
24
|
+
yes: boolean;
|
|
25
|
+
confidence: number;
|
|
26
|
+
}
|
|
27
|
+
/** The case as the decider sees it. Not clipped: an over-long case is refused by the caps — a fallback, not a guess. */
|
|
28
|
+
export declare function caseState(tc: TestCase): string;
|
|
29
|
+
/**
|
|
30
|
+
* One call per case, one `noul` per still-open item (chunked by the provider's questions-per-call cap).
|
|
31
|
+
* Cases are asked one after another: a covered item is not asked again, the first unavailable call ends the
|
|
32
|
+
* pass (so a hanging server costs one timeout), and a single-worker local server is never flooded.
|
|
33
|
+
*/
|
|
34
|
+
export declare function deciderChecklistCoverage(items: {
|
|
35
|
+
text: string;
|
|
36
|
+
}[], cases: TestCase[], decider: Decider): Promise<DeciderCoverage>;
|
|
37
|
+
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../../../src/decider/uses/coverage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,aAAa,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC;IAAC,KAAK,EAAE,cAAc,EAAE,CAAA;CAAE,GAC1G;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC;AAEnD,oGAAoG;AACpG,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACpB;AAOD,wHAAwH;AACxH,wBAAgB,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAQ9C;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EACzB,KAAK,EAAE,QAAQ,EAAE,EACjB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,eAAe,CAAC,CAuC1B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const CRITERIA = {
|
|
2
|
+
true: "Its steps or expected result exercise this checklist item",
|
|
3
|
+
false: "It does not exercise this checklist item",
|
|
4
|
+
};
|
|
5
|
+
/** The case as the decider sees it. Not clipped: an over-long case is refused by the caps — a fallback, not a guess. */
|
|
6
|
+
export function caseState(tc) {
|
|
7
|
+
return [
|
|
8
|
+
`Test case: ${tc.title}`,
|
|
9
|
+
...(tc.preconditions.length ? [`Preconditions: ${tc.preconditions.join("; ")}`] : []),
|
|
10
|
+
"Steps:",
|
|
11
|
+
...tc.steps.map((s, i) => `${i + 1}. ${s}`),
|
|
12
|
+
`Expected result: ${tc.expected}`,
|
|
13
|
+
].join("\n");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* One call per case, one `noul` per still-open item (chunked by the provider's questions-per-call cap).
|
|
17
|
+
* Cases are asked one after another: a covered item is not asked again, the first unavailable call ends the
|
|
18
|
+
* pass (so a hanging server costs one timeout), and a single-worker local server is never flooded.
|
|
19
|
+
*/
|
|
20
|
+
export async function deciderChecklistCoverage(items, cases, decider) {
|
|
21
|
+
const covered = new Set();
|
|
22
|
+
const unsure = new Set();
|
|
23
|
+
const asked = [];
|
|
24
|
+
for (const [c, tc] of cases.entries()) {
|
|
25
|
+
// Shadow mode asks the whole matrix: a pilot replaying a stricter threshold needs the answers pruning skips.
|
|
26
|
+
const open = items.map((_, i) => i).filter((i) => decider.shadow || !covered.has(i));
|
|
27
|
+
for (let at = 0; at < open.length; at += decider.caps.maxQuestionsPerCall) {
|
|
28
|
+
const chunk = open.slice(at, at + decider.caps.maxQuestionsPerCall);
|
|
29
|
+
const questions = Object.fromEntries(chunk.map((i) => [
|
|
30
|
+
`i${i}`,
|
|
31
|
+
{ type: "noul", instructions: `Does this test case exercise the checklist item "${items[i].text}"?`, criteria: CRITERIA },
|
|
32
|
+
]));
|
|
33
|
+
let answers;
|
|
34
|
+
try {
|
|
35
|
+
answers = await decider.decide("coverage", caseState(tc), questions);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return { undecided: `unavailable: ${e instanceof Error ? e.message : String(e)}`, asked };
|
|
39
|
+
}
|
|
40
|
+
for (const i of chunk) {
|
|
41
|
+
const a = answers[`i${i}`];
|
|
42
|
+
if (a?.type !== "noul")
|
|
43
|
+
return { undecided: "an answer that is not a yes/no", asked };
|
|
44
|
+
asked.push({ case: c, item: i, yes: a.value, confidence: a.confidence });
|
|
45
|
+
if (a.confidence < decider.minConfidence)
|
|
46
|
+
unsure.add(i);
|
|
47
|
+
else if (a.value)
|
|
48
|
+
covered.add(i);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const doubtful = items.filter((_, i) => !covered.has(i) && unsure.has(i)).map((it) => it.text);
|
|
53
|
+
if (doubtful.length > 0)
|
|
54
|
+
return { undecided: `unsure about: ${doubtful.join("; ")}`, asked };
|
|
55
|
+
const uncovered = items.filter((_, i) => !covered.has(i)).map((it) => it.text);
|
|
56
|
+
return {
|
|
57
|
+
value: items.length ? covered.size / items.length : 0,
|
|
58
|
+
comment: uncovered.length > 0 ? `uncovered: ${uncovered.join("; ")}` : "full coverage",
|
|
59
|
+
perItem: items.map((it, i) => ({ item: it.text, covered: covered.has(i) })),
|
|
60
|
+
asked,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.js","sourceRoot":"","sources":["../../../src/decider/uses/coverage.ts"],"names":[],"mappings":"AAoBA,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,2DAA2D;IACjE,KAAK,EAAE,0CAA0C;CAClD,CAAC;AAEF,wHAAwH;AACxH,MAAM,UAAU,SAAS,CAAC,EAAY;IACpC,OAAO;QACL,cAAc,EAAE,CAAC,KAAK,EAAE;QACxB,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACrF,QAAQ;QACR,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,oBAAoB,EAAE,CAAC,QAAQ,EAAE;KAClC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,KAAyB,EACzB,KAAiB,EACjB,OAAgB;IAEhB,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,MAAM,KAAK,GAAqB,EAAE,CA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