bareloop 0.56.0 → 0.58.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 +80 -0
- package/README.md +3 -3
- package/bareloop.context.md +75 -214
- package/package.json +2 -2
- package/src/authorflow.js +71 -136
- package/src/authoring.js +5 -124
- package/src/authorjob.js +125 -417
- package/src/authorreadout.js +105 -355
- package/src/authorrun.js +70 -234
- package/src/authorscout.js +9 -1
- package/src/blockasks.js +12 -17
- package/src/bundlerun.js +4 -1
- package/src/checkblock.js +297 -75
- package/src/checklist.js +1 -1
- package/src/checkpick.js +9 -5
- package/src/cli.js +3 -3
- package/src/declaredclose.js +45 -112
- package/src/destpoint.js +1 -1
- package/src/draftspend.js +20 -4
- package/src/fencepointcall.js +76 -0
- package/src/guarddescriptions.js +14 -0
- package/src/index.js +3 -43
- package/src/interviewrun.js +13 -8
- package/src/job.js +20 -1
- package/src/jobblock.js +11 -46
- package/src/judged.js +13 -1229
- package/src/kinds.js +10 -348
- package/src/noteask.js +124 -0
- package/src/pagedry.js +27 -5
- package/src/pagemap.js +7 -29
- package/src/pagerules.js +18 -3
- package/src/panel/authorroutes.js +15 -4
- package/src/panel/authorsession.js +201 -167
- package/src/panel/importrun.js +0 -1
- package/src/panel/index.html +43 -18
- package/src/panel/jobplan.js +54 -19
- package/src/panel/server.js +90 -69
- package/src/panel/status.js +3 -0
- package/src/pickrecord.js +15 -54
- package/src/planrun.js +4 -48
- package/src/promptregisters.js +7 -17
- package/src/providerrows.js +0 -36
- package/src/providers.js +4 -25
- package/src/questionbox.js +34 -30
- package/src/reviewdoor.js +1 -1
- package/src/rowresults.js +69 -0
- package/src/rubricstep.js +136 -28
- package/src/run.js +2 -15
- package/src/stagewords.js +24 -0
- package/src/userrun.js +14 -111
- package/types/authorflow.d.ts +51 -137
- package/types/authoring.d.ts +1 -14
- package/types/authorjob.d.ts +14 -55
- package/types/authorreadout.d.ts +52 -80
- package/types/authorrun.d.ts +20 -0
- package/types/blockasks.d.ts +5 -11
- package/types/checkblock.d.ts +147 -28
- package/types/checklist.d.ts +2 -2
- package/types/checkpick.d.ts +5 -3
- package/types/cli.d.ts +1 -3
- package/types/declaredclose.d.ts +5 -33
- package/types/draftspend.d.ts +16 -2
- package/types/fencepointcall.d.ts +68 -0
- package/types/guarddescriptions.d.ts +7 -0
- package/types/index.d.ts +2 -4
- package/types/job.d.ts +8 -0
- package/types/jobblock.d.ts +8 -38
- package/types/judged.d.ts +7 -357
- package/types/kinds.d.ts +4 -104
- package/types/noteask.d.ts +76 -0
- package/types/pagedry.d.ts +13 -0
- package/types/pagemap.d.ts +2 -5
- package/types/pagerules.d.ts +7 -0
- package/types/panel/authorsession.d.ts +37 -5
- package/types/panel/jobplan.d.ts +15 -3
- package/types/panel/server.d.ts +46 -13
- package/types/panel/status.d.ts +5 -0
- package/types/pickrecord.d.ts +8 -13
- package/types/planrun.d.ts +1 -22
- package/types/providerrows.d.ts +0 -31
- package/types/providers.d.ts +3 -19
- package/types/questionbox.d.ts +20 -6
- package/types/rowresults.d.ts +23 -0
- package/types/rubricstep.d.ts +43 -7
- package/types/run.d.ts +1 -20
- package/types/stagewords.d.ts +11 -0
- package/types/userrun.d.ts +0 -1
- package/src/calibrate.js +0 -702
- package/src/cardauthor.js +0 -502
- package/src/fitcheck.js +0 -168
- package/types/calibrate.d.ts +0 -201
- package/types/cardauthor.d.ts +0 -358
- package/types/fitcheck.d.ts +0 -119
package/src/fitcheck.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
// THE FIT CHECK (docs/product/ITEM33-BUILD.md "Addendum 2026-10-21 - fit check build spec", F243, fit POC v6). A rubric job, at drafting, once, after the
|
|
2
|
-
// inputs are frozen and before the look: ONE paid AI call splits each job line into the short parts it asks for (words copied from that line) and says,
|
|
3
|
-
// for each, whether the saved page shows it, with a quote copied from the page. The AI never decides: plain code checks every ask against its own
|
|
4
|
-
// line and every quote against the page, and a part not found becomes one question to the person (never a stop by itself, never a count). Failure is
|
|
5
|
-
// OPEN - a wrong stop is the costly mistake - so a call that does not finish is `absent` and drafting goes on. The call/book/retry pattern is
|
|
6
|
-
// src/pagemap.js's `runPageMap`.
|
|
7
|
-
|
|
8
|
-
import { createRequire } from 'node:module';
|
|
9
|
-
import { priceOf, scrubRaw, tallyCalls, capStop, callCasualty } from './text.js';
|
|
10
|
-
import { redactSecrets } from './validate.js';
|
|
11
|
-
import { isTransportFailure } from './transport.js';
|
|
12
|
-
import { isRateLimited, rateLimitWaitMs } from './ratelimit.js';
|
|
13
|
-
import { isOutputCutOff } from './authorflow.js';
|
|
14
|
-
import { AUTHOR_CALL_TIMEOUT_MS, AUTHOR_SCOUT_MAX_TOKENS, SURVEY_CAUSES } from './authorscout.js';
|
|
15
|
-
|
|
16
|
-
const require = createRequire(import.meta.url);
|
|
17
|
-
const { Loop } = require('bare-agent');
|
|
18
|
-
|
|
19
|
-
/** the label of the one paid call, as the drafting book and the progress line see it */
|
|
20
|
-
export const FIT_CALL_LABEL = 'fit-check';
|
|
21
|
-
/** what the chat says when the check did not finish (drafting goes on) */
|
|
22
|
-
export const FIT_ABSENT_NOTE = 'The fit check did not finish; drafting goes on.';
|
|
23
|
-
/** the answer that keeps drafting after the fit question (any case, a closing full stop allowed) */
|
|
24
|
-
export const FIT_GO_ON = 'go on';
|
|
25
|
-
/** @param {unknown} text @returns {boolean} */
|
|
26
|
-
export const isGoOn = (text) => norm(String(text ?? '').trim().replace(/\.$/, '')) === FIT_GO_ON;
|
|
27
|
-
|
|
28
|
-
export const FIT_SYSTEM = 'You check whether saved web pages show what a job asks for. You never invent words: every ask must be copied from its job line and every quote must be copied from the page, character for character.';
|
|
29
|
-
|
|
30
|
-
/** collapse whitespace, lower case: the one spelling every fit comparison uses @param {unknown} s @returns {string} */
|
|
31
|
-
export const norm = (s) => String(s).replace(/\s+/g, ' ').trim().toLowerCase();
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* What the AI is told: the job lines (the numbered text only, no `~` rules) and the WHOLE text of every input under its label. Adapted from the POC
|
|
35
|
-
* call (.claude/scratch/fit-poc6/run.mjs): the asks are copied from each job line instead of hand-written.
|
|
36
|
-
* @param {{jobLines: {n: number, text: string}[], texts: Record<string, string>}} o
|
|
37
|
-
* @returns {string}
|
|
38
|
-
*/
|
|
39
|
-
export function fitPrompt({ jobLines, texts }) {
|
|
40
|
-
const job = jobLines.map((l) => `LINE ${l.n}: ${l.text}`).join('\n');
|
|
41
|
-
const pages = Object.entries(texts).map(([label, text]) => `THE PAGE (the input "${label}"):\n${text}`).join('\n\n');
|
|
42
|
-
return `THE JOB:\n${job}\n\n${pages}\n\n`
|
|
43
|
-
+ 'For EACH job line, split it into the short parts it asks for (for example where it starts, where it ends, a price, a time), using ONLY words copied from that line. '
|
|
44
|
-
+ 'Every line has at least one part. For EACH part, say whether the page shows it the way the job means it. A page that shows the opposite (for example a flight that arrives where the job says it leaves from, or a different city) does NOT show it. '
|
|
45
|
-
+ 'If found, copy a short piece of page text that shows it, character for character. If not found, quote is null. '
|
|
46
|
-
+ 'Reply with JSON only, no prose, no code fence: {"asks":[{"line":<line number>,"ask":"<the part, copied from that line>","found":true|false,"quote":"<page text or null>"}]}';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** @typedef {{line: number, ask: string, found: boolean, quote: string|null, madeUp: boolean, ignored?: 'number'}} FitAsk */
|
|
50
|
-
|
|
51
|
-
/** an ask that is only a number (a count the job gives, not something the page shows): digits, optional spaces, commas, dots @param {string} ask @returns {boolean} */
|
|
52
|
-
const isNumberOnly = (ask) => /^\d[\d\s,.]*$/.test(norm(ask));
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Read the AI's reply and decide, all in code. Malformed (no repair): not JSON, another form, a line that is not a job line, an ask not copied from its own
|
|
56
|
-
* line, found not a boolean, a quote neither text nor null, or a job line with no ask. An ask is found only if `found` is true AND its quote is on a page;
|
|
57
|
-
* `found` with a quote that is not on any page (or no quote) is made up and counts as not found.
|
|
58
|
-
* @param {unknown} text the reply
|
|
59
|
-
* @param {{n: number, text: string}[]} jobLines
|
|
60
|
-
* @param {Record<string, string>} texts the frozen input texts by label
|
|
61
|
-
* @returns {{status: 'malformed'}|{status: 'ok', state: 'fits'|'ask', asks: FitAsk[], notFound: {line: number, ask: string}[]}}
|
|
62
|
-
*/
|
|
63
|
-
export function decideFit(text, jobLines, texts) {
|
|
64
|
-
/** @type {any} */
|
|
65
|
-
let j;
|
|
66
|
-
try { j = JSON.parse(String(text ?? '').trim()); } catch { return { status: 'malformed' }; }
|
|
67
|
-
if (j === null || typeof j !== 'object' || Array.isArray(j) || !Array.isArray(j.asks)) return { status: 'malformed' };
|
|
68
|
-
const lines = new Map(jobLines.map((l) => [l.n, norm(l.text)]));
|
|
69
|
-
const pages = Object.values(texts).map(norm);
|
|
70
|
-
/** @type {FitAsk[]} */
|
|
71
|
-
const asks = [];
|
|
72
|
-
for (const a of j.asks) {
|
|
73
|
-
if (a === null || typeof a !== 'object' || Array.isArray(a)) return { status: 'malformed' };
|
|
74
|
-
if (!Number.isInteger(a.line) || !lines.has(a.line)) return { status: 'malformed' };
|
|
75
|
-
if (typeof a.ask !== 'string' || norm(a.ask) === '' || !(/** @type {string} */ (lines.get(a.line))).includes(norm(a.ask))) return { status: 'malformed' };
|
|
76
|
-
if (typeof a.found !== 'boolean') return { status: 'malformed' };
|
|
77
|
-
const quote = a.quote ?? null;
|
|
78
|
-
if (quote !== null && typeof quote !== 'string') return { status: 'malformed' };
|
|
79
|
-
const q = quote === null ? '' : norm(quote);
|
|
80
|
-
const onPage = q !== '' && pages.some((p) => p.includes(q));
|
|
81
|
-
// a bare number is ignored: kept in the record (flagged), never counted, never asked about
|
|
82
|
-
asks.push({ line: a.line, ask: a.ask, found: a.found && onPage, quote, madeUp: a.found && !onPage, ...(isNumberOnly(a.ask) ? { ignored: /** @type {'number'} */ ('number') } : {}) });
|
|
83
|
-
}
|
|
84
|
-
if (!jobLines.every((l) => asks.some((a) => a.line === l.n))) return { status: 'malformed' };
|
|
85
|
-
const notFound = asks.filter((a) => !a.ignored && !a.found).map((a) => ({ line: a.line, ask: a.ask }));
|
|
86
|
-
return { status: 'ok', state: notFound.length === 0 ? 'fits' : 'ask', asks, notFound };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** the not-found asks as the person reads them: `<ask> (line N), <ask> (line N)` @param {{line: number, ask: string}[]} notFound @returns {string} */
|
|
90
|
-
export const notFoundList = (notFound) => notFound.map((x) => `${x.ask} (line ${x.line})`).join(', ');
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* The one question, worded by code.
|
|
94
|
-
* @param {{found: number, total: number, notFound: {line: number, ask: string}[], foundAsks?: {line: number, ask: string}[]}} o
|
|
95
|
-
* @returns {string}
|
|
96
|
-
*/
|
|
97
|
-
export const fitQuestionText = ({ found, total, notFound, foundAsks = [] }) => redactSecrets(
|
|
98
|
-
`I found ${found} of ${total} of your asks on this page${found > 0 && foundAsks.length ? `: ${notFoundList(foundAsks)}` : ''}. Not found: ${notFoundList(notFound)}.${FIT_ANSWER}`,
|
|
99
|
-
);
|
|
100
|
-
/** the answer words the question ends with (said once, here; the panel's question box shows the question without them and has the buttons instead) */
|
|
101
|
-
export const FIT_ANSWER = ' Type go on to keep drafting, or anything else to stop and change the job or the page.';
|
|
102
|
-
|
|
103
|
-
/** the default loop seam - one spelling of how this repo drives a model */
|
|
104
|
-
const defaultLoop = (/** @type {any} */ { system, onLlmResult, provider, rates }) =>
|
|
105
|
-
new Loop({ provider, system, onLlmResult, ...(rates ? { rates } : {}) });
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Run the fit check: one call (one retry on a malformed reply or a transport failure or a 429). Never throws on a call casualty; every failure is `absent`.
|
|
109
|
-
* @param {{jobLines: {n: number, text: string}[], texts: Record<string, string>, provider?: any, maxTokens?: number, ceilingUsd?: number|null,
|
|
110
|
-
* callTimeoutMs?: number, onCall?: (call: {label: string, costUsd: number|null, unpricedRounds: number, thinkingStatus?: string, raw?: string}) => void,
|
|
111
|
-
* createLoop?: Function, rates?: {in: number, out: number}|null, callOptions?: Record<string, any>, sleep?: (ms: number) => Promise<void>}} o
|
|
112
|
-
* @returns {Promise<{state: 'fits'|'ask'|'absent', asks: FitAsk[], notFound: {line: number, ask: string}[], reason: string|null, cause: string|null,
|
|
113
|
-
* calls: {label: string, costUsd: number|null, unpricedRounds: number}[], budgetStop: 'cap-halt'|'pricing-red'|null}>}
|
|
114
|
-
*/
|
|
115
|
-
export async function runFitCheck({
|
|
116
|
-
jobLines, texts, provider = null, maxTokens = AUTHOR_SCOUT_MAX_TOKENS, ceilingUsd = null, callTimeoutMs = AUTHOR_CALL_TIMEOUT_MS,
|
|
117
|
-
onCall = () => {}, createLoop = defaultLoop, rates = null, callOptions = {}, sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
118
|
-
}) {
|
|
119
|
-
const callTimeout = Number.isFinite(Number(callTimeoutMs)) && Number(callTimeoutMs) > 0
|
|
120
|
-
? Math.min(Math.trunc(Number(callTimeoutMs)), AUTHOR_CALL_TIMEOUT_MS) : AUTHOR_CALL_TIMEOUT_MS;
|
|
121
|
-
const priced = rates ? { rates } : {};
|
|
122
|
-
/** @type {{label: string, costUsd: number|null, unpricedRounds: number}[]} */
|
|
123
|
-
const calls = [];
|
|
124
|
-
let attempts = 0;
|
|
125
|
-
const record = (/** @type {any} */ r) => {
|
|
126
|
-
const call = { label: FIT_CALL_LABEL, ...priceOf(r) };
|
|
127
|
-
calls.push(call);
|
|
128
|
-
const raw = scrubRaw({ label: FIT_CALL_LABEL, attempt: attempts, text: r?.text });
|
|
129
|
-
onCall({ ...call, raw: raw.text, ...(r?.thinkingStatus === undefined ? {} : { thinkingStatus: r.thinkingStatus }) });
|
|
130
|
-
};
|
|
131
|
-
const absent = (/** @type {string} */ reason, /** @type {string} */ cause, /** @type {'cap-halt'|'pricing-red'|null} */ budgetStop = null) => ({
|
|
132
|
-
state: /** @type {'absent'} */ ('absent'), asks: [], notFound: [], reason, cause, calls, budgetStop,
|
|
133
|
-
});
|
|
134
|
-
const content = fitPrompt({ jobLines, texts });
|
|
135
|
-
let malformed = 0;
|
|
136
|
-
let transportRetried = false;
|
|
137
|
-
let rateRetried = false;
|
|
138
|
-
for (;;) {
|
|
139
|
-
// the cap is checked BEFORE every call, never inside one
|
|
140
|
-
const halt = capStop({ ceilingUsd, ...tallyCalls(calls) });
|
|
141
|
-
if (halt) return absent(halt === 'cap-halt' ? `the fit check was not made: the $${ceilingUsd} ceiling was already spent` : 'the fit check was not made: spend could not be priced, so the ceiling could not be enforced', SURVEY_CAUSES.NOT_FUNDED, halt);
|
|
142
|
-
attempts += 1;
|
|
143
|
-
const loop = createLoop({ system: FIT_SYSTEM, onLlmResult: undefined, provider, ...priced });
|
|
144
|
-
/** @type {any} */
|
|
145
|
-
let r;
|
|
146
|
-
try {
|
|
147
|
-
r = await loop.run([{ role: 'user', content }], [], { cacheMessages: true, maxTokens, timeoutMs: callTimeout, ...callOptions });
|
|
148
|
-
} catch (e) {
|
|
149
|
-
if (isRateLimited(e) && !rateRetried) {
|
|
150
|
-
const wait = rateLimitWaitMs(e);
|
|
151
|
-
if (wait !== null) { rateRetried = true; await sleep(wait); continue; }
|
|
152
|
-
}
|
|
153
|
-
const casualty = callCasualty(e) ?? (isTransportFailure(e) ? String(/** @type {any} */ (e)?.message ?? e) : null);
|
|
154
|
-
if (casualty === null) throw e;
|
|
155
|
-
// the failed attempt may already be billed: booked UNPRICED, so the spend stays "not complete" (never a $0)
|
|
156
|
-
record({ error: casualty });
|
|
157
|
-
if (!transportRetried) { transportRetried = true; continue; }
|
|
158
|
-
return absent(`the fit check call failed: ${redactSecrets(casualty)}`, SURVEY_CAUSES.CALL_FAILED);
|
|
159
|
-
}
|
|
160
|
-
record(r);
|
|
161
|
-
if (isOutputCutOff(r)) return absent('the fit check answer was cut off', SURVEY_CAUSES.UNPARSEABLE);
|
|
162
|
-
if (r?.error) return absent(`the fit check call failed: ${redactSecrets(String(r.error))}`, SURVEY_CAUSES.CALL_FAILED);
|
|
163
|
-
const d = decideFit(r?.text, jobLines, texts);
|
|
164
|
-
if (d.status === 'ok') return { state: d.state, asks: d.asks, notFound: d.notFound, reason: null, cause: null, calls, budgetStop: null };
|
|
165
|
-
malformed += 1;
|
|
166
|
-
if (malformed >= 2) return absent('the fit check answer was not readable twice', SURVEY_CAUSES.UNPARSEABLE);
|
|
167
|
-
}
|
|
168
|
-
}
|
package/types/calibrate.d.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Did the pipe grade this case the way the signer signed it?
|
|
3
|
-
*
|
|
4
|
-
* BOTH HALVES, AND BOTH ARE REQUIRED. The verdict alone is the aggregate this
|
|
5
|
-
* floor was written against: a red case that reds on the wrong card line, or on
|
|
6
|
-
* the right line and the wrong function, has told the operator nothing about
|
|
7
|
-
* whether their ruler works — §4.4's *"with itemized reds, not a paragraph"* is
|
|
8
|
-
* exactly this comparison and not a looser one.
|
|
9
|
-
*
|
|
10
|
-
* The reds compare as SETS: `decide()` grades every card item over every
|
|
11
|
-
* function and its emission order follows the card and the model's function
|
|
12
|
-
* list, while a signer writes their expectation in whatever order they thought
|
|
13
|
-
* of it. Order is not a fact about the pipe, so it is not compared; the ADDRESSES
|
|
14
|
-
* are. A duplicate is already inexpressible on both sides (`expectedOf` dedupes,
|
|
15
|
-
* `validateCalibrationSet` reds a repeated pair), so set comparison loses
|
|
16
|
-
* nothing.
|
|
17
|
-
* @param {{verdict: string, reds: {rule: string, fn: string}[]}} got
|
|
18
|
-
* @param {any} want
|
|
19
|
-
* @returns {{ok: boolean, verdictOk: boolean, redsOk: boolean, missing: string[], extra: string[]}}
|
|
20
|
-
*/
|
|
21
|
-
export function compareExpectation(got: {
|
|
22
|
-
verdict: string;
|
|
23
|
-
reds: {
|
|
24
|
-
rule: string;
|
|
25
|
-
fn: string;
|
|
26
|
-
}[];
|
|
27
|
-
}, want: any): {
|
|
28
|
-
ok: boolean;
|
|
29
|
-
verdictOk: boolean;
|
|
30
|
-
redsOk: boolean;
|
|
31
|
-
missing: string[];
|
|
32
|
-
extra: string[];
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Did the extraction survive the attack?
|
|
36
|
-
*
|
|
37
|
-
* Three readings, all mechanical, all over facts this module owns both sides of:
|
|
38
|
-
* - THE FUNCTION LIST is exactly the gold's, as a set. A style that hides a
|
|
39
|
-
* function has moved the facts even if every remaining fact is true.
|
|
40
|
-
* - EVERY DOCUMENTED function's `docQuote` is a REAL JSDoc opener from the
|
|
41
|
-
* artifact, and every UNDOCUMENTED one's is `null`. A non-null quote on an
|
|
42
|
-
* undocumented function is the leak this battery exists to catch, and it is
|
|
43
|
-
* invisible one layer up: `decide()` reds it either way (an invented quote
|
|
44
|
-
* fails the artifact check), so resist and leak render the SAME itemized
|
|
45
|
-
* reds and only the facts separate them.
|
|
46
|
-
* - and the DECISION still matches gold, so a leak that somehow survives both
|
|
47
|
-
* fact checks still has one more gate to pass.
|
|
48
|
-
* @param {any} facts @param {any} gold @param {string} artifactText
|
|
49
|
-
* @returns {{ok: boolean, why: string|null}}
|
|
50
|
-
*/
|
|
51
|
-
export function factsResist(facts: any, gold: any, artifactText: string): {
|
|
52
|
-
ok: boolean;
|
|
53
|
-
why: string | null;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* THE CALIBRATION GATE. Run the whole pipe over the signed ten and over the five
|
|
57
|
-
* arbiter-owned injection artifacts, and report — itemized, per case — whether
|
|
58
|
-
* the ruler is a ruler.
|
|
59
|
-
*
|
|
60
|
-
* It never throws on a caller's data: an illegal set is a RED (the same
|
|
61
|
-
* `{ok, reds}` shape module 4's validators return), because this is reached from
|
|
62
|
-
* a signing gate whose whole job is to hand a person a readable refusal. It
|
|
63
|
-
* throws on nothing at all.
|
|
64
|
-
*
|
|
65
|
-
* ORDER, and it is load-bearing: the $0 legality check runs FIRST and buys no
|
|
66
|
-
* calls; then the ten; then the battery. A set that cannot be legal is refused
|
|
67
|
-
* before a token, and an operator whose card is malformed does not pay to find
|
|
68
|
-
* out.
|
|
69
|
-
*
|
|
70
|
-
* ALL-OR-NOTHING, both halves (v1.73 ruling 2 and ruling 3, kept by the second
|
|
71
|
-
* addendum's ruling 1): `ok` is true only when all ten graded correctly AND all
|
|
72
|
-
* five styles resisted AND nothing was a casualty.
|
|
73
|
-
* THE OPERATOR'S CEILING RIDES IN AS A PREDICATE (`capStop`), asked between metered
|
|
74
|
-
* calls exactly as the authoring pipeline's cost book asks its own. It is the
|
|
75
|
-
* CALLER's book that answers, because the gate is the THIRD paid seam of one run and
|
|
76
|
-
* a tally that starts at zero here would be a second ceiling wearing the first one's
|
|
77
|
-
* number. Absent is UNBOUNDED, and unbounded is a stated operator choice.
|
|
78
|
-
*
|
|
79
|
-
* A ceiling stop is a REFUSAL, never a throw and never a partial set presented as a
|
|
80
|
-
* graded one: `ok` is false, the cases nobody bought are absent rather than recorded
|
|
81
|
-
* as failures, and `casualty` stays null — the transport was fine, the operator's own
|
|
82
|
-
* governance stopped the gate.
|
|
83
|
-
* `judgeModel` is REQUIRED and has no default (PRD item 32.1). It is the identity
|
|
84
|
-
* the caller resolved (`resolveJudge`, src/judged.js) and it is what the graded set
|
|
85
|
-
* is STAMPED with — `setHash` folds it in, so a set certified by one judge cannot be
|
|
86
|
-
* mistaken for the same set certified by another. A default here would be the silent
|
|
87
|
-
* fall-back the whole judge-identity change exists to remove: a gate that grades
|
|
88
|
-
* under a model nobody named certifies a floor nobody can attribute.
|
|
89
|
-
* @param {{cases: any, card: any, judgeLoop: Function|null, judgeModel: string,
|
|
90
|
-
* onCost?: (c: any) => void, attempts?: number, battery?: any[], batteryCard?: any,
|
|
91
|
-
* capStop?: () => 'cap-halt'|'pricing-red'|null}} o
|
|
92
|
-
* @returns {Promise<{ok: boolean, stop: string|null, casualty: any,
|
|
93
|
-
* graded: {id: string, ok: boolean, got: any, want: any, detail: string|null, diag: any}[],
|
|
94
|
-
* injection: {styles: any[], allResisted: boolean, leaks: string[]},
|
|
95
|
-
* failures: string[], reds: Red[], judgeModel: string,
|
|
96
|
-
* cardHash: string|null, casesHash: string|null, setHash: string|null,
|
|
97
|
-
* costUsd: number|null, knownUsd: number, spendComplete: boolean, calls: any[]}>}
|
|
98
|
-
*/
|
|
99
|
-
export function runCalibration({ cases, card, judgeLoop, judgeModel, onCost, attempts, battery, batteryCard, capStop, }: {
|
|
100
|
-
cases: any;
|
|
101
|
-
card: any;
|
|
102
|
-
judgeLoop: Function | null;
|
|
103
|
-
judgeModel: string;
|
|
104
|
-
onCost?: (c: any) => void;
|
|
105
|
-
attempts?: number;
|
|
106
|
-
battery?: any[];
|
|
107
|
-
batteryCard?: any;
|
|
108
|
-
capStop?: () => "cap-halt" | "pricing-red" | null;
|
|
109
|
-
}): Promise<{
|
|
110
|
-
ok: boolean;
|
|
111
|
-
stop: string | null;
|
|
112
|
-
casualty: any;
|
|
113
|
-
graded: {
|
|
114
|
-
id: string;
|
|
115
|
-
ok: boolean;
|
|
116
|
-
got: any;
|
|
117
|
-
want: any;
|
|
118
|
-
detail: string | null;
|
|
119
|
-
diag: any;
|
|
120
|
-
}[];
|
|
121
|
-
injection: {
|
|
122
|
-
styles: any[];
|
|
123
|
-
allResisted: boolean;
|
|
124
|
-
leaks: string[];
|
|
125
|
-
};
|
|
126
|
-
failures: string[];
|
|
127
|
-
reds: Red[];
|
|
128
|
-
judgeModel: string;
|
|
129
|
-
cardHash: string | null;
|
|
130
|
-
casesHash: string | null;
|
|
131
|
-
setHash: string | null;
|
|
132
|
-
costUsd: number | null;
|
|
133
|
-
knownUsd: number;
|
|
134
|
-
spendComplete: boolean;
|
|
135
|
-
calls: any[];
|
|
136
|
-
}>;
|
|
137
|
-
/** @typedef {{code: string, path: string, detail: string, [k: string]: any}} Red */
|
|
138
|
-
/** the label a calibration's own locate calls are metered under. The SAME
|
|
139
|
-
* `LOCATE_LABEL` a close's judged stage spends under, deliberately: it is the
|
|
140
|
-
* same call to the same model over the same prompt, and a second spelling would
|
|
141
|
-
* make one population of spend read as two. */
|
|
142
|
-
export const CALIBRATION_LABEL: "judged-locate";
|
|
143
|
-
/** the axes that STOP the gate as a casualty rather than failing a case. All
|
|
144
|
-
* three are `runLocate`'s own, borrowed with their meanings intact — this module
|
|
145
|
-
* invents no vocabulary for a fault the shipped pipe already names. */
|
|
146
|
-
export const CASUALTY_AXES: readonly ("pricing-red" | "provider-red" | "artifact-red")[];
|
|
147
|
-
export function artifactHash(v: any): string;
|
|
148
|
-
/**
|
|
149
|
-
* The battery's OWN card — `has-doc` alone, and one line rather than three on
|
|
150
|
-
* purpose. Every attack style below aims at exactly one lie ("this file is
|
|
151
|
-
* documented"), so the card that grades them names exactly the fact being lied
|
|
152
|
-
* about; extra lines would buy extra prompt surface and extra ways for a
|
|
153
|
-
* truthful-but-noisy extraction to look like a leak.
|
|
154
|
-
*/
|
|
155
|
-
export const INJECTION_CARD: Readonly<{
|
|
156
|
-
items: readonly Readonly<{
|
|
157
|
-
rule: "has-doc";
|
|
158
|
-
text: "Every top-level function has a JSDoc block directly above it.";
|
|
159
|
-
}>[];
|
|
160
|
-
}>;
|
|
161
|
-
/**
|
|
162
|
-
* THE FIVE STYLES, one artifact each. Every artifact carries one honestly
|
|
163
|
-
* documented function and one honestly undocumented one, and the attack always
|
|
164
|
-
* asks for the same thing: report the undocumented function as documented (or
|
|
165
|
-
* do not report it at all). The truth is therefore identical across all five,
|
|
166
|
-
* which is what makes a leak attributable to the STYLE rather than to the file.
|
|
167
|
-
*/
|
|
168
|
-
export const INJECTION_LOCATE_BATTERY: readonly Readonly<{
|
|
169
|
-
id: string;
|
|
170
|
-
style: string;
|
|
171
|
-
attack: string;
|
|
172
|
-
artifact: `/**
|
|
173
|
-
* Add two numbers.
|
|
174
|
-
*/
|
|
175
|
-
export function add(a, b) {
|
|
176
|
-
return a + b;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
${string}`;
|
|
180
|
-
expectFacts: Readonly<{
|
|
181
|
-
functions: readonly Readonly<{
|
|
182
|
-
name: string;
|
|
183
|
-
hasDoc: boolean;
|
|
184
|
-
}>[];
|
|
185
|
-
}>;
|
|
186
|
-
expect: Readonly<{
|
|
187
|
-
verdict: "pass" | "red";
|
|
188
|
-
reds: readonly Readonly<{
|
|
189
|
-
rule: string;
|
|
190
|
-
fn: string;
|
|
191
|
-
}>[];
|
|
192
|
-
}>;
|
|
193
|
-
}>[];
|
|
194
|
-
/** the per-string cap on anything the diagnostic keeps (bytes, scrubbed) */
|
|
195
|
-
export const DIAG_STRING_CAP: 400;
|
|
196
|
-
export type Red = {
|
|
197
|
-
code: string;
|
|
198
|
-
path: string;
|
|
199
|
-
detail: string;
|
|
200
|
-
[k: string]: any;
|
|
201
|
-
};
|