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/authorjob.js
CHANGED
|
@@ -99,16 +99,13 @@
|
|
|
99
99
|
// in the stored declaration (forward-compat point 3), and the suite pins it.
|
|
100
100
|
|
|
101
101
|
import { jobSpecHash, validateJob } from './job.js';
|
|
102
|
-
import { seedAtHead, seedListing, seedRead as runSeedRead, makeSeedTrees
|
|
102
|
+
import { seedAtHead, seedListing, seedRead as runSeedRead, makeSeedTrees } from './kinds.js';
|
|
103
103
|
import { inputLabelsOf, readFrozenInputs, lineRules, cardOfClose } from './rubricstep.js';
|
|
104
104
|
import { proverOf } from './factwords.js';
|
|
105
105
|
// SOFTGREEN modules 4 and 5 — the compile the interview's Q6/Q7 answers land in,
|
|
106
106
|
// and the gate that decides whether the ruler they describe is a ruler.
|
|
107
|
-
import { proposeJudgedArtifacts, signJudgedArtifacts, foldJudgedArtifacts } from './cardauthor.js';
|
|
108
|
-
import { runCalibration } from './calibrate.js';
|
|
109
|
-
import { CALIBRATION_SIZE } from './judged.js';
|
|
110
107
|
import {
|
|
111
|
-
GENRE_LANGUAGES, RUBRIC_LANG, DECLARABLE_LANGUAGES, genreForLang, LOCKED_KINDS, TYPES_GENRE, VERDICT_CLASSES, LOCKED_CLASSES, LIVE_CLASSES,
|
|
108
|
+
GENRE_LANGUAGES, RUBRIC_LANG, classGuards, DECLARABLE_LANGUAGES, genreForLang, LOCKED_KINDS, TYPES_GENRE, VERDICT_CLASSES, LOCKED_CLASSES, LIVE_CLASSES,
|
|
112
109
|
UNLISTED_CLASSES, MENU_CLASSES,
|
|
113
110
|
} from './authoring.js';
|
|
114
111
|
import {
|
|
@@ -116,16 +113,18 @@ import {
|
|
|
116
113
|
runConfirmTurn, LANGUAGE_PICK_FIELD, MAX_QUESTIONS,
|
|
117
114
|
} from './authorflow.js';
|
|
118
115
|
import { thinkingCallOptions, assertThinkingMode } from './thinking.js';
|
|
119
|
-
import { runFitCheck, fitQuestionText, notFoundList, isGoOn } from './fitcheck.js';
|
|
120
116
|
import { pageContentChars } from './pagefetch.js';
|
|
121
117
|
import { runAuthorScout, buildSeedListing, SCOUT_ATTEMPTS } from './authorscout.js';
|
|
122
118
|
import { runPageMap, tooManyAsksText } from './pagemap.js';
|
|
123
|
-
import { CheckBlock } from './checkblock.js';
|
|
119
|
+
import { CheckBlock, REASON } from './checkblock.js';
|
|
124
120
|
import { questionsOfBlock, applyChoices } from './blockasks.js';
|
|
125
|
-
import {
|
|
121
|
+
import { askNotes } from './noteask.js';
|
|
122
|
+
import { renderJobLines } from './jobblock.js';
|
|
123
|
+
import { scopedRules, codeScope, plainWords, obviousCheck } from './checkpick.js';
|
|
126
124
|
import { matchRecord, entriesFromAnswers, KEPT_WORDS } from './pickrecord.js';
|
|
127
125
|
import { runCheckSuggest } from './checksuggest.js';
|
|
128
126
|
import { runLedgerSuggest, ledgerRecord } from './checklist.js';
|
|
127
|
+
import { runFencePoint } from './fencepointcall.js';
|
|
129
128
|
import {
|
|
130
129
|
DECLARED_GAP_PREFIX, DECLARED_GENRES, guardNames, isDeclaredClose, validateCloseDecl,
|
|
131
130
|
} from './declaredclose.js';
|
|
@@ -429,25 +428,23 @@ function composerRefusal(reds) {
|
|
|
429
428
|
* one-genre-at-a-time law is untouched.
|
|
430
429
|
*
|
|
431
430
|
* @param {{answers: Record<string|number, any>, repoPath?: string|null, lang: string,
|
|
432
|
-
* jobLines?: {n: number, text: string}[]|null, inputs?: {n: number, label: string, value: string}[]|null,
|
|
431
|
+
* jobLines?: {n: number, text: string, rule?: string, rules?: string[]}[]|null, inputs?: {n: number, label: string, value: string}[]|null,
|
|
433
432
|
* verdictType?: string|null,
|
|
434
433
|
* questions?: Record<string|number, string>|null, generate?: Function, provider?: any,
|
|
435
|
-
* seedRef?: string|null, scout?: any, listing?: any, ceilingUsd?: number|null,
|
|
434
|
+
* seedRef?: string|null, scout?: any, listing?: any, ceilingUsd?: number|null,
|
|
436
435
|
* rates?: {in: number, out: number}|null, draftThinking?: 'on'|'off',
|
|
437
436
|
* onPhase?: (phase: string, data?: any) => void,
|
|
438
437
|
* onCall?: (call: {label: string, costUsd: number|null, unpricedRounds: number, thinkingStatus?: string}) => void,
|
|
439
|
-
* seedFn?: Function, scoutFn?: Function, listingFn?: Function, lookFn?: Function|null,
|
|
440
|
-
* fitAsk?: ((question: string) => Promise<string|null>)|null, onFit?: (fit: {state: string, asks: any[], notFound: any[]}) => void,
|
|
438
|
+
* seedFn?: Function, scoutFn?: Function, listingFn?: Function, lookFn?: Function|null,
|
|
441
439
|
* authorFn?: Function, authorOpts?: object, writeScope?: string[]|null,
|
|
442
|
-
* signerFix?: Function|any, proposeFn?: Function, compileOpts?: object,
|
|
443
440
|
* ask?: ((step: {kind: string, [k: string]: any}) => Promise<string|null>)|null,
|
|
444
441
|
* answerQuestions?: ((o: {questions: {line: number, question: string, rule?: number, source?: string, ask?: string, reading?: string, key?: string}[], dropped: {reason: string, raw: any}[], confirmed: any}) =>
|
|
445
442
|
* Promise<{jobLines: {n: number, text: string, rule?: string}[], answers: Record<string|number, any>, left?: {line: number, rule: number}[], picks?: any[], choices?: {key: string, choice: string, text?: string}[]}|null>)|null,
|
|
446
|
-
* pickGenerate?: Function|null, ledgerGenerate?: Function|null, editGenerate?: Function|null, carriedPicks?: any[]|null, carriedChoices?: any[]|null, onChoices?: (rec: any[]) => void, onPicks?: (o: {entries: any[], kept: {line: number, rule: number, entry: any}[]}) => void,
|
|
443
|
+
* pickGenerate?: Function|null, ledgerGenerate?: Function|null, fenceGenerate?: Function|null, noteFn?: Function|null, onJobLines?: ((jobLines: any[]) => void)|null, editGenerate?: Function|null, carriedPicks?: any[]|null, carriedChoices?: any[]|null, onChoices?: (rec: any[]) => void, onPicks?: (o: {entries: any[], kept: {line: number, rule: number, entry: any}[]}) => void,
|
|
447
444
|
* confirmGenerate?: Function|null, isRepo?: boolean,
|
|
448
445
|
* langResult?: {kind: string, candidates?: string[], [k: string]: any}|null}} o
|
|
449
446
|
* @returns {Promise<{ok: boolean, refusal: Refusal|null, verdictType: string|null,
|
|
450
|
-
* closeDecl: any, seedRef: string|null, authoring: any,
|
|
447
|
+
* closeDecl: any, seedRef: string|null, authoring: any, reds: Red[],
|
|
451
448
|
* stop: string|null, cost: any, interview: any, confirmed: any, picked?: {line: number, text: string}[], hasBuiltCheck?: boolean, notBuilt?: {line: number, text: string}[]}>}
|
|
452
449
|
*/
|
|
453
450
|
export async function authorCloseForJob({
|
|
@@ -466,11 +463,6 @@ export async function authorCloseForJob({
|
|
|
466
463
|
// `writeScope`, and this is what carries it into the composer prompt
|
|
467
464
|
// (`authorPrompt`'s `writeScopeBlock`) instead of letting it vanish.
|
|
468
465
|
writeScope = null,
|
|
469
|
-
// THE JUDGE IDENTITY (PRD item 32.1), required only on the path that actually
|
|
470
|
-
// composes a judged stage — the stored calibration set carries the judge that
|
|
471
|
-
// certified it, and there is no library pin to fall back to. Absent on a purely
|
|
472
|
-
// mechanical close is correct and costs nothing: that close never judges.
|
|
473
|
-
judgeModel = null,
|
|
474
466
|
// THE PROGRESS SEAMS. This composition is the pipeline's long silence — a real
|
|
475
467
|
// survey, a real declaration ladder, and a real toolchain per close stage — and
|
|
476
468
|
// it emitted nothing until it returned, so an operator watching a live run
|
|
@@ -482,9 +474,6 @@ export async function authorCloseForJob({
|
|
|
482
474
|
// PART 1c / IDEA A CORE - the look at a rubric job's inputs: the default is the page-word map (src/pagemap.js `runPageMap`, one paid AI
|
|
483
475
|
// call per page input, its words kept by code). `null` is an explicit "no look" (a test seam, like a caller-supplied `scout`).
|
|
484
476
|
lookFn = runPageMap,
|
|
485
|
-
// THE FIT CHECK (F243): one paid call BEFORE the look, rubric jobs only. It runs only when the caller supplies the answer seam `fitAsk` (the panel);
|
|
486
|
-
// `fitFn` null is an explicit "no check" (a test seam). With no `fitAsk` (the CLI door) it never runs.
|
|
487
|
-
fitFn = runFitCheck, fitAsk = null, onFit = () => {},
|
|
488
477
|
authorFn = authorClose, authorOpts = {},
|
|
489
478
|
// R10 (fwd am16): the model boundary of the check-suggestion call (a `makeLoopGenerate` bound to SUGGEST_SYSTEM). ABSENT = no pick path: nothing is suggested or asked and the
|
|
490
479
|
// drafted declaration is validated as it always was (a test seam, like `lookFn: null`).
|
|
@@ -492,17 +481,18 @@ export async function authorCloseForJob({
|
|
|
492
481
|
// the model boundary of the list call (a `makeLoopGenerate` bound to LEDGER_SYSTEM), rubric jobs only. ABSENT = the list is built from the look and the defaults with no suggestion call
|
|
493
482
|
// (a test seam, like `pickGenerate`); the CLI and the panel always bring it.
|
|
494
483
|
ledgerGenerate = null,
|
|
484
|
+
// the repo job's pointing call (src/fencepointcall.js): ONE small call BEFORE the asks that points a `~` rule at a file the write fence keeps; code proves it. ABSENT = no pointing: every unproven rule is asked
|
|
485
|
+
fenceGenerate = null,
|
|
486
|
+
// 2026-11-14 (b): the note question (src/noteask.js), asked ONLY when a rubric line is facts-only; ABSENT = never asked (every older caller and test)
|
|
487
|
+
noteFn = null,
|
|
488
|
+
// one rule in, one rule out: called with the job lines rebuilt from the check list after an answer (the seam that shows the job text updates itself); ABSENT = nothing shows it
|
|
489
|
+
onJobLines = null,
|
|
495
490
|
// the row-edit turn's own model boundary (src/rowedit.js ROW_EDIT_SYSTEM); a test that replaces `generate` need not bring one
|
|
496
491
|
editGenerate = null,
|
|
497
492
|
// R10 (fwd am17/am18): the picks record of the draft this one follows (`readRecordFile`), and the seam that receives this draft's record + the picks it kept. ABSENT = every rule is asked.
|
|
498
493
|
carriedPicks = null, onPicks = () => {},
|
|
499
494
|
// hamr 2026-11-13 (N-2): the Drop/Add choices of the draft this one follows (the picks record file's `rowChoices`); a Revise keeps them, code still judges every one
|
|
500
495
|
carriedChoices = null, onChoices = () => {},
|
|
501
|
-
// SOFTGREEN modules 4+5. `signerFix` is the D5 seam: a function (or a value)
|
|
502
|
-
// carrying the SIGNER's corrected artifacts back. Absent means the proposal is
|
|
503
|
-
// signed as proposed, and `signJudgedArtifacts` records which of the two
|
|
504
|
-
// happened rather than leaving a reader to guess.
|
|
505
|
-
signerFix = null, proposeFn = proposeJudgedArtifacts, compileOpts = {},
|
|
506
496
|
// PRD item 33 M3 piece 4 — the confirm turn. ALL FOUR default to nothing so
|
|
507
497
|
// every existing caller runs byte-identical: `ask` absent means no confirm
|
|
508
498
|
// turn runs at all, exactly as before this piece existed.
|
|
@@ -532,7 +522,7 @@ export async function authorCloseForJob({
|
|
|
532
522
|
/** @type {any} */
|
|
533
523
|
const base = {
|
|
534
524
|
ok: false, refusal: null, verdictType: null, closeDecl: null, seedRef: null,
|
|
535
|
-
authoring: null,
|
|
525
|
+
authoring: null, reds: [], stop: null, cost: null, interview: null,
|
|
536
526
|
confirmed: null,
|
|
537
527
|
};
|
|
538
528
|
|
|
@@ -640,26 +630,6 @@ export async function authorCloseForJob({
|
|
|
640
630
|
// nothing to check a rule against. Plain words, before any model call.
|
|
641
631
|
survey = { state: 'ABSENT', reason: 'your input holds nothing to read (it is empty, or only the site\'s own header and menus) - nothing was asked and nothing was spent', cause: 'call-failed', budgetStop: null, calls: [], raws: [], facts: null };
|
|
642
632
|
} else if (frozen !== null && lookFn) {
|
|
643
|
-
if (fitAsk && fitFn) {
|
|
644
|
-
// F243: a page that does not show what the job asks for stops here, before the look spends. Failure is OPEN: an `absent` check
|
|
645
|
-
// (cut, unreadable twice, call failed, cap) asks nothing and drafting goes on; the answer is NOT a `~` rule and changes nothing in the job.
|
|
646
|
-
onPhase('fit-check', {});
|
|
647
|
-
const fitCallOptions = thinkingCallOptions(provider, draftThinking);
|
|
648
|
-
const fit = await fitFn({
|
|
649
|
-
jobLines, texts: frozen.texts, provider, ceilingUsd, onCall, ...(rates ? { rates } : {}),
|
|
650
|
-
...(Object.keys(fitCallOptions).length ? { callOptions: fitCallOptions } : {}),
|
|
651
|
-
});
|
|
652
|
-
onPhase('fit-check-done', { state: fit.state });
|
|
653
|
-
onFit({ state: fit.state, asks: fit.asks, notFound: fit.notFound });
|
|
654
|
-
if (fit.state === 'ask') {
|
|
655
|
-
const foundAsks = fit.asks.filter((/** @type {any} */ a) => !a.ignored && a.found).map((/** @type {any} */ a) => ({ line: a.line, ask: a.ask }));
|
|
656
|
-
const answer = await fitAsk(fitQuestionText({ found: foundAsks.length, foundAsks, total: fit.asks.filter((/** @type {any} */ a) => !a.ignored).length, notFound: fit.notFound }));
|
|
657
|
-
if (answer === null) return { ...base, interview, verdictType: picked, seedRef: seed, reds: [], stop: 'confirm-abandoned', cost: null };
|
|
658
|
-
if (!isGoOn(answer)) {
|
|
659
|
-
return { ...base, interview, verdictType: picked, seedRef: seed, reds: [{ code: 'fit-stopped', path: 'jobLines', detail: notFoundList(fit.notFound) }], stop: 'fit-stopped', cost: null };
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
633
|
onPhase('look', {});
|
|
664
634
|
const lookCallOptions = thinkingCallOptions(provider, draftThinking);
|
|
665
635
|
survey = await lookFn({
|
|
@@ -692,10 +662,45 @@ export async function authorCloseForJob({
|
|
|
692
662
|
onPhase('scout-done', { state: survey?.state ?? null, facts: Object.keys(survey?.facts ?? {}).length });
|
|
693
663
|
}
|
|
694
664
|
|
|
665
|
+
/**
|
|
666
|
+
* The code-forced ask rounds of the check block, ONE flow for every job (hamr 2026-11-15): the rows code cannot settle are asked (cap 3 counted), the person's choice goes back through the block, and the job text is rebuilt
|
|
667
|
+
* from the list. Only a rule with something to Agree to is asked (a look's reading, a proposed count check); a rule no check can prove is Not checked at once, never asked (option A, hamr 2026-11-15). Returns `{stop}` (a finished return) or `{answered}`.
|
|
668
|
+
* @param {import('./checkblock.js').CheckBlock} blk @param {NonNullable<typeof answerQuestions>} answerFn the seam that asks the person @returns {Promise<{stop: any}|{answered: {picks: any[], left: any[]}}>}
|
|
669
|
+
*/
|
|
670
|
+
const askRounds = async (blk, answerFn) => {
|
|
671
|
+
/** what the person answered, across the rounds: the picks and the rules they left, for the record this draft hands on @type {{picks: any[], left: any[]}} */
|
|
672
|
+
const answered = { picks: [], left: [] };
|
|
673
|
+
for (let round = 0; round < 3 && blk.open.length > 0; round += 1) {
|
|
674
|
+
const asks = questionsOfBlock(blk);
|
|
675
|
+
const counted = asks.filter((a) => a.counted);
|
|
676
|
+
if (counted.length > MAX_QUESTIONS) {
|
|
677
|
+
return { stop: { ...base, interview, verdictType: picked, seedRef: seed, reds: [{ code: 'look-asks-too-many', path: 'jobLines', detail: tooManyAsksText(asks, blk.repo !== null ? '' : undefined) }], stop: 'look-asks-too-many', cost: null } };
|
|
678
|
+
}
|
|
679
|
+
// the asks go to the person whole (key, check, reading, counted, pairRule): normalizeQuestions keeps only a model's question fields and would drop the proposal an Agree button needs
|
|
680
|
+
const shown = asks.map((a) => ({ ...a, question: redactSecrets(a.question) }));
|
|
681
|
+
if (shown.length === 0) break;
|
|
682
|
+
onPhase(shown.every((a) => a.ask === 'check') ? 'check-ask' : 'look-ask', { questions: shown.length });
|
|
683
|
+
const updated = await answerFn({ questions: shown, dropped: [], confirmed: null });
|
|
684
|
+
if (updated === null) return { stop: { ...base, interview, verdictType: picked, seedRef: seed, reds: [], stop: 'confirm-abandoned', cost: null } };
|
|
685
|
+
jobLines = updated.jobLines;
|
|
686
|
+
interview.answers = updated.answers;
|
|
687
|
+
answered.picks.push(...(Array.isArray(updated.picks) ? updated.picks : []));
|
|
688
|
+
answered.left.push(...(Array.isArray(updated.left) ? updated.left : []));
|
|
689
|
+
const refused = applyChoices(blk, Array.isArray(updated.choices) ? updated.choices : []);
|
|
690
|
+
// one rule in, one rule out (hamr 2026-11-14): the list replaced each answered rule, so the job text is rebuilt FROM the list (its one owner) and handed back to the seam that shows it
|
|
691
|
+
const rebuilt = blk.jobLinesView(jobLines);
|
|
692
|
+
jobLines = rebuilt;
|
|
693
|
+
interview.answers = { ...interview.answers, 1: renderJobLines(rebuilt) };
|
|
694
|
+
if (typeof onJobLines === 'function') onJobLines(rebuilt);
|
|
695
|
+
if (refused.length === 0) break;
|
|
696
|
+
}
|
|
697
|
+
return { answered };
|
|
698
|
+
};
|
|
699
|
+
|
|
695
700
|
// THE CHECK BLOCK of a rubric job (src/checkblock.js; hamr 2026-11-12: "one flow one place ai suggestes ! code adds $ and code decides what worked/doable"). It is made once here, after the look:
|
|
696
701
|
// the person's `~` rules and `$` defaults, then the look's facts (a fact tied to a `~` rule is a link on that row), then the last draft's picks Revise keeps (am17/am18/am21). The AI's two
|
|
697
702
|
// helpers (the pick call for count rules, the call for extra `!` checks) send ROW EDITS through the SAME door as the drafter's reply (`applyDelta`). Code then asks (cap 3) about what it
|
|
698
|
-
// cannot settle and applies the person's CHOICE (agree | drop
|
|
703
|
+
// cannot settle and applies the person's CHOICE (agree | drop, buttons only) with `applyAnswer`. Every check comes from the rows; no other store holds one.
|
|
699
704
|
/** @type {import('./checkblock.js').CheckBlock|null} */
|
|
700
705
|
let block = null;
|
|
701
706
|
/** the picks the person made (kept and answered) this draft, as the picks record carries them */
|
|
@@ -705,17 +710,15 @@ export async function authorCloseForJob({
|
|
|
705
710
|
const look = survey.facts?.look && typeof survey.facts.look === 'object' ? survey.facts.look : null;
|
|
706
711
|
block = new CheckBlock({ texts: ledgerTexts, labels: (Array.isArray(inputs) ? inputs : []).map((i) => i.label), asks: Boolean(answerQuestions), split: true, countScope: (t) => Boolean(pickGenerate) && codeScope(inputs, t) === 'in' });
|
|
707
712
|
block.fromJob(jobLines);
|
|
713
|
+
block.setGuards(classGuards({ verdictType: picked, lang }).map((g) => g.name), Array.isArray(writeScope) && writeScope.length ? writeScope : ['output/']);
|
|
708
714
|
block.addLook(Array.isArray(look?.facts) ? look.facts : [], Array.isArray(look?.dropped) ? look.dropped : []);
|
|
709
715
|
/** the rules a count pick settles, as the record knows them (a scoped rule is a counting `~` rule code scopes in) */
|
|
710
716
|
const scoped = answerQuestions ? scopedRules(jobLines, { inputs, look }) : [];
|
|
711
717
|
const matched = matchRecord(Array.isArray(carriedPicks) ? carriedPicks : [], jobLines, scoped);
|
|
718
|
+
// a rule whose words already are its check is settled by the block as written (no ask, no suggestion call)
|
|
719
|
+
matched.askRules = matched.askRules.filter((r) => !obviousCheck(r.text));
|
|
712
720
|
carried = { kept: matched.kept };
|
|
713
|
-
block.carry({ picks: matched.picks, left: matched.left }
|
|
714
|
-
// a rule the record folded into another ask (a broken pair's partner) is neither asked nor given the old check: Not checked, in the pick path's own words
|
|
715
|
-
for (const r of scoped) {
|
|
716
|
-
const row = block.ruleRows(r.line).find((x) => x.rule === r.rule);
|
|
717
|
-
if (row && !matched.askRules.some((a) => a.line === r.line && a.rule === r.rule) && !row.pick && !row.cantAsked && !row.left && !row.parent) row.folded = true;
|
|
718
|
-
}
|
|
721
|
+
block.carry({ picks: matched.picks, left: matched.left });
|
|
719
722
|
block.reconcile();
|
|
720
723
|
// the pick call: one suggestion per counting rule the record did not keep; each kept suggestion is a `pick` edit
|
|
721
724
|
if (answerQuestions && pickGenerate && matched.askRules.length > 0) {
|
|
@@ -742,6 +745,8 @@ export async function authorCloseForJob({
|
|
|
742
745
|
block.applyDelta({ label: 'pre:ledger-suggest', pre: true, edits: adds });
|
|
743
746
|
block.reconcile();
|
|
744
747
|
}
|
|
748
|
+
// the note question: ONE call, only when a line is facts-only. The AI says yes/no per line; code decides (block.setNotes -> a `$` note row and a countable text part). A failed call leaves the line facts-only with a Not checked row.
|
|
749
|
+
survey.calls = [...(survey.calls ?? []), ...(await askNotes({ block, jobLines, noteFn, ceilingUsd, onCall, onPhase }))];
|
|
745
750
|
// a Revise keeps the last draft's Drop/Add choices (the suggestions exist now); code still judges every one when the list is reconciled
|
|
746
751
|
if (Array.isArray(carriedChoices)) { block.carryChoices(carriedChoices); onChoices(block.choicesRecord()); }
|
|
747
752
|
block.reconcile();
|
|
@@ -749,37 +754,30 @@ export async function authorCloseForJob({
|
|
|
749
754
|
// the code-forced asks (PRD v1.106 Part 5 Q3 T2, v1.107 Part 5b, R10): a reading code proposes, a rule the page cannot check, a check proposed for a counting rule. More than
|
|
750
755
|
// MAX_QUESTIONS counted asks is a job to rewrite, not a questionnaire: nothing is asked and the stop lists every ask.
|
|
751
756
|
if (answerQuestions) {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
const asks = questionsOfBlock(block, pickGenerate ? scoped : []);
|
|
756
|
-
const counted = asks.filter((a) => a.counted);
|
|
757
|
-
if (counted.length > MAX_QUESTIONS) {
|
|
758
|
-
return { ...base, interview, verdictType: picked, seedRef: seed, reds: [{ code: 'look-asks-too-many', path: 'jobLines', detail: tooManyAsksText(asks) }], stop: 'look-asks-too-many', cost: null };
|
|
759
|
-
}
|
|
760
|
-
// the asks go to the person whole (key, check, reading, counted, pairRule): normalizeQuestions keeps only a model's question fields and would drop the proposal an Agree button needs
|
|
761
|
-
const shown = asks.map((a) => ({ ...a, question: redactSecrets(a.question) }));
|
|
762
|
-
if (shown.length === 0) break;
|
|
763
|
-
onPhase(shown.every((a) => a.ask === 'check' || a.ask === 'no-check') ? 'check-ask' : 'look-ask', { questions: shown.length });
|
|
764
|
-
const updated = await answerQuestions({ questions: shown, dropped: [], confirmed: null });
|
|
765
|
-
if (updated === null) return { ...base, interview, verdictType: picked, seedRef: seed, reds: [], stop: 'confirm-abandoned', cost: null };
|
|
766
|
-
jobLines = updated.jobLines;
|
|
767
|
-
interview.answers = updated.answers;
|
|
768
|
-
answered.picks.push(...(Array.isArray(updated.picks) ? updated.picks : []));
|
|
769
|
-
answered.left.push(...(Array.isArray(updated.left) ? updated.left : []));
|
|
770
|
-
const refused = applyChoices(block, Array.isArray(updated.choices) ? updated.choices : []);
|
|
771
|
-
if (refused.length === 0) break;
|
|
772
|
-
}
|
|
757
|
+
const ar = await askRounds(block, answerQuestions);
|
|
758
|
+
if ('stop' in ar) return ar.stop;
|
|
759
|
+
const answered = ar.answered;
|
|
773
760
|
// the record this draft hands on, written whether or not anything was asked (a draft that kept every pick still carries them forward): the picks it kept, as they were, and the picks just answered, keyed by words
|
|
774
761
|
if (scoped.length > 0) {
|
|
762
|
+
// the record keeps the FINAL words of each rule (an answer replaced the rule it was asked about), numbered on this card
|
|
763
|
+
const finalRules = jobLines.flatMap((l) => (l.rules ?? []).map((t, i) => ({ line: l.n, rule: i + 1, text: t })));
|
|
775
764
|
onPicks({
|
|
776
|
-
entries: [...carried.kept.map((k) => k.entry), ...entriesFromAnswers(jobLines,
|
|
765
|
+
entries: [...carried.kept.map((k) => k.entry), ...entriesFromAnswers(jobLines, finalRules, answered.picks, answered.left.filter((l) => scoped.some((r) => r.line === l.line && r.rule === l.rule)))],
|
|
777
766
|
kept: carried.kept.map((k) => ({ line: k.line, rule: k.rule, entry: k.entry })),
|
|
778
767
|
});
|
|
779
768
|
}
|
|
780
769
|
} else block.reconcile();
|
|
781
770
|
}
|
|
782
771
|
|
|
772
|
+
// A repo job runs through the SAME check block (hamr 2026-11-15: "same flow as rubric, no exceptions; only the TYPE of checks varies"): its `$` rows are known now (the confirm card draws them); its `~` rule rows
|
|
773
|
+
// are made once the repo listing is read, and its `!` work-stage rows once the draft stands.
|
|
774
|
+
/** @type {import('./checkblock.js').CheckBlock|null} */
|
|
775
|
+
let repoBlock = null;
|
|
776
|
+
if (block === null && isRepo && lang !== RUBRIC_LANG && Array.isArray(jobLines) && jobLines.length > 0) {
|
|
777
|
+
repoBlock = new CheckBlock({ texts: {}, labels: [], asks: Boolean(answerQuestions), repo: { files: null, writeScope: Array.isArray(writeScope) && writeScope.length ? [...writeScope] : null } });
|
|
778
|
+
repoBlock.setGuards(classGuards({ verdictType: picked, lang }).map((g) => g.name), Array.isArray(writeScope) && writeScope.length ? writeScope : null);
|
|
779
|
+
}
|
|
780
|
+
|
|
783
781
|
// ── THE CONFIRM TURN'S PAID HALF (PRD item 33 M3 piece 4) ──────────────────
|
|
784
782
|
// Slotted between the scout and the listing: it reuses the scout's own
|
|
785
783
|
// survey (ruling 4 — never a second read of the source) and needs nothing
|
|
@@ -829,6 +827,11 @@ export async function authorCloseForJob({
|
|
|
829
827
|
const cardOf = () => cardOfClose({ closeDecl: block.closeView(), jobLines, ledger: block.rows.map((r) => ({ key: r.key, words: r.kind === 'rule' ? [r.text ?? ''] : (r.words ?? []) })) });
|
|
830
828
|
return { card: cardOf(), cardOf, block };
|
|
831
829
|
})() : {}),
|
|
830
|
+
// a repo job's card is its rows too (Addendum 2026-11-15 (d)): the `$ [default]` guards and the write fence, known before drafting, read from the same block; the `~` rules and the `!` stages get their rows later
|
|
831
|
+
...(repoBlock ? (() => {
|
|
832
|
+
const closeDecl = repoBlock.closeView();
|
|
833
|
+
return { card: { ...cardOfClose({ closeDecl, jobLines }), closeDecl } };
|
|
834
|
+
})() : {}),
|
|
832
835
|
});
|
|
833
836
|
// DISTINCT from `runConfirmTurn`'s own per-round 'confirm-done' (fired once
|
|
834
837
|
// per round when a plan arrives) — this is the WRAPPER's own line, once,
|
|
@@ -865,6 +868,29 @@ export async function authorCloseForJob({
|
|
|
865
868
|
onPhase('listing-done', { files: seeds?.files?.length ?? null, stop: seeds?.stop ?? null });
|
|
866
869
|
}
|
|
867
870
|
|
|
871
|
+
// a repo job's `~` rule rows (a rule is kept only when code finds a repo path in the person's own words that the write fence keeps; every other rule is asked about, as a rubric rule is), once the listing is read
|
|
872
|
+
if (repoBlock !== null && seeds != null && seeds.stop == null && Array.isArray(seeds.files)) {
|
|
873
|
+
repoBlock.setGuards(classGuards({ verdictType: picked, lang }).map((g) => g.name), Array.isArray(writeScope) && writeScope.length ? writeScope : null);
|
|
874
|
+
repoBlock.setListing(seeds.files);
|
|
875
|
+
repoBlock.fromJob(jobLines ?? []);
|
|
876
|
+
repoBlock.reconcile();
|
|
877
|
+
// point -> code proves -> asks -> draft (the rubric's order): the AI points a rule at a listing path, row edits judge it alone; only when the job has `~` rules and the listing has paths outside the fence
|
|
878
|
+
// the folders holding outside files are listed too (`test/`), so a rule that names a folder can be pointed at it
|
|
879
|
+
const outside = [...repoBlock.outsideFolders().map((d) => `${d}/`), ...repoBlock.outsideScope()];
|
|
880
|
+
if (fenceGenerate && outside.length > 0 && repoBlock.rows.some((r) => r.kind === 'rule')) {
|
|
881
|
+
onPhase('fence-point', {});
|
|
882
|
+
const fp = await runFencePoint({ jobLines: jobLines ?? [], outside, writeScope, generate: fenceGenerate, ceilingUsd, onCall, priorCalls: survey?.calls ?? [], priorRaws: survey?.raws ?? [] });
|
|
883
|
+
if (survey != null) { survey.calls = [...(survey.calls ?? []), ...fp.calls]; survey.raws = [...(survey.raws ?? []), ...fp.raws]; }
|
|
884
|
+
const rec = repoBlock.applyDelta({ label: 'pre:fence-point', pre: true, edits: fp.edits });
|
|
885
|
+
repoBlock.reconcile();
|
|
886
|
+
onPhase('fence-point-done', { edits: fp.edits, results: rec.edits.map((/** @type {any} */ e) => ({ op: e.op, line: e.line, rule: e.rule, path: e.path, accepted: e.accepted === true, ...(e.accepted === true ? {} : { refusedBecause: String(e.refusedBecause) }) })), sent: fp.edits.length, kept: rec.edits.filter((/** @type {any} */ e) => e.accepted === true).length, reason: fp.reason, refused: rec.edits.filter((/** @type {any} */ e) => e.accepted !== true).map((/** @type {any} */ e) => String(e.refusedBecause)) });
|
|
887
|
+
}
|
|
888
|
+
if (answerQuestions) {
|
|
889
|
+
const ar = await askRounds(repoBlock, answerQuestions);
|
|
890
|
+
if ('stop' in ar) return ar.stop;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
|
|
868
894
|
// The declaration ladder. The REVISION CAP is deliberately not quoted here:
|
|
869
895
|
// the tighten-only clamp lives in `authorClose` (and `authorOpts` may lower
|
|
870
896
|
// it), so a number spelled at this call site could disagree with the one the
|
|
@@ -968,90 +994,21 @@ export async function authorCloseForJob({
|
|
|
968
994
|
: {}),
|
|
969
995
|
};
|
|
970
996
|
|
|
971
|
-
//
|
|
972
|
-
//
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
if (closeJudges(closeDecl)) {
|
|
987
|
-
// ONE CEILING, ALL THREE PAID SEAMS. The declaration loop's own calls are
|
|
988
|
-
// ABSORBED before the compile is asked for, so the ceiling folds in prior
|
|
989
|
-
// spend and re-invoking a seam cannot silently widen it. `absorb` deliberately
|
|
990
|
-
// does not re-fire `onCall`, so nothing is reported twice.
|
|
991
|
-
const book = makeCostBook({ ceilingUsd, onCall });
|
|
992
|
-
book.absorb(authored.cost?.calls ?? []);
|
|
993
|
-
onPhase('rubric', { size: CALIBRATION_SIZE });
|
|
994
|
-
const proposed = await proposeFn({
|
|
995
|
-
answers: stageAnswers,
|
|
996
|
-
questions: questions ?? questionsFor(picked),
|
|
997
|
-
generate,
|
|
998
|
-
book,
|
|
999
|
-
...compileOpts,
|
|
1000
|
-
});
|
|
1001
|
-
onPhase('rubric-done', { ok: proposed.ok, stop: proposed.stop, attempts: proposed.attempts });
|
|
1002
|
-
if (!proposed.ok) {
|
|
1003
|
-
return {
|
|
1004
|
-
...base,
|
|
1005
|
-
verdictType: picked, seedRef: seed, authoring: authored, judged: { proposal: proposed, signed: null },
|
|
1006
|
-
reds: proposed.reds, stop: proposed.stop, cost: book.report(), interview,
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
// THE D5 MOMENT. `signerFix` is the seam a UI (or an operator's own editor)
|
|
1011
|
-
// hands the fixed artifacts back through; ABSENT is a legal answer and it is
|
|
1012
|
-
// recorded as one — `source: 'proposal'` says *nobody changed this*, which is
|
|
1013
|
-
// a different fact from *a person read it and changed nothing*.
|
|
1014
|
-
const fix = typeof signerFix === 'function' ? await signerFix(proposed.proposal) : signerFix;
|
|
1015
|
-
const signed = signJudgedArtifacts({ proposal: proposed.proposal, fix });
|
|
1016
|
-
judged = { proposal: proposed, signed, scrubbed: signed.scrubbed, source: signed.source };
|
|
1017
|
-
if (!signed.ok) {
|
|
1018
|
-
return {
|
|
1019
|
-
...base,
|
|
1020
|
-
verdictType: picked, seedRef: seed, authoring: authored, judged,
|
|
1021
|
-
reds: signed.reds, stop: 'rubric-invalid', cost: book.report(), interview,
|
|
1022
|
-
};
|
|
1023
|
-
}
|
|
1024
|
-
// THE SCRUB, ANNOUNCED. A signer signs a hash over the STORED bytes, so bytes
|
|
1025
|
-
// the ONE inventory masked on the way in are said out loud rather than left
|
|
1026
|
-
// for them to notice — by PATH only, because echoing the matched string would
|
|
1027
|
-
// be the same leak one hop on.
|
|
1028
|
-
if (signed.scrubbed.length) onPhase('rubric-scrubbed', { paths: signed.scrubbed.map((s) => s.path) });
|
|
1029
|
-
// `cases` is an array on every ok path — `validateCalibrationSet` reds a
|
|
1030
|
-
// non-array before anything can be `ok` — and the narrowing is stated rather
|
|
1031
|
-
// than defaulted: `?? []` here would fold an EMPTY signed set into a close,
|
|
1032
|
-
// which is the one direction that must never be reachable.
|
|
1033
|
-
if (typeof judgeModel !== 'string' || judgeModel.trim() === '') {
|
|
1034
|
-
throw new Error('[authorjob] authorCloseForJob composed a JUDGED close and was given no judgeModel (PRD item '
|
|
1035
|
-
+ '32.1). The stored calibration set carries the judge that certified it, and a set stamped with a model '
|
|
1036
|
-
+ 'nobody named is exactly the unattributable floor that field exists to prevent.');
|
|
1037
|
-
}
|
|
1038
|
-
closeDecl = foldJudgedArtifacts(closeDecl, {
|
|
1039
|
-
card: signed.card, cases: /** @type {any[]} */ (signed.cases), judgeModel,
|
|
1040
|
-
});
|
|
1041
|
-
return {
|
|
1042
|
-
ok: true,
|
|
1043
|
-
refusal: null,
|
|
1044
|
-
verdictType: picked,
|
|
1045
|
-
closeDecl,
|
|
1046
|
-
seedRef: seed,
|
|
1047
|
-
authoring: authored,
|
|
1048
|
-
judged,
|
|
1049
|
-
reds: authored.reds,
|
|
1050
|
-
stop: authored.stop,
|
|
1051
|
-
cost: book.report(),
|
|
1052
|
-
interview,
|
|
1053
|
-
confirmed,
|
|
1054
|
-
};
|
|
997
|
+
// A repo job signs its list through the same block (hamr 2026-11-15): its `~` rule rows (kept by the fence or Not checked with a REASON), the drafter's work stages as `!` rows, the `$` guards and the fence.
|
|
998
|
+
// `refused` is built from the rows in code, as a rubric job's is: the drafter's line-level refusals, then each `~` rule row no check carries.
|
|
999
|
+
if (repoBlock !== null && closeDecl.list === undefined && !closeDecl.stages.some((/** @type {any} */ s) => s && s.kind === 'rubric-step')) {
|
|
1000
|
+
const guardNames = classGuards({ verdictType: picked, lang }).map((g) => g.name);
|
|
1001
|
+
repoBlock.setGuards(guardNames, Array.isArray(writeScope) && writeScope.length ? writeScope : null);
|
|
1002
|
+
repoBlock.asks = false; // nobody is asked after the draft stands: a rule not settled now is Not checked
|
|
1003
|
+
repoBlock.syncJob(jobLines ?? []);
|
|
1004
|
+
repoBlock.addStages(closeDecl.stages, { guardNames, refused: closeDecl.refused ?? [], guardLines: closeDecl.guardLines ?? [] });
|
|
1005
|
+
if (Array.isArray(carriedChoices)) { repoBlock.carryChoices(carriedChoices); onChoices(repoBlock.choicesRecord()); }
|
|
1006
|
+
const view = repoBlock.closeView();
|
|
1007
|
+
const lineRefusals = repoBlock.rows.filter((r) => r.kind === 'stage' && r.refusal === true).map((r) => ({ line: r.line, reason: REASON.noRule }));
|
|
1008
|
+
const ruleRefusals = repoBlock.rows.filter((r) => r.kind === 'rule' && r.state !== 'built').map((r) => ({ line: r.line, rule: r.rule, reason: String(r.reason ?? 'not checked') }));
|
|
1009
|
+
closeDecl.stages = view.stages;
|
|
1010
|
+
closeDecl.list = view.list;
|
|
1011
|
+
if (lineRefusals.length || ruleRefusals.length) closeDecl.refused = [...lineRefusals, ...ruleRefusals]; else delete closeDecl.refused;
|
|
1055
1012
|
}
|
|
1056
1013
|
|
|
1057
1014
|
return {
|
|
@@ -1061,7 +1018,6 @@ export async function authorCloseForJob({
|
|
|
1061
1018
|
closeDecl,
|
|
1062
1019
|
seedRef: seed,
|
|
1063
1020
|
authoring: authored,
|
|
1064
|
-
judged,
|
|
1065
1021
|
// the checks the person picked, for the plan card's "You picked" rows (read from the block's rows)
|
|
1066
1022
|
...(block ? { hasBuiltCheck: block.hasBuiltCheck() } : {}),
|
|
1067
1023
|
// the suggestions code could not build, one plain sentence each: the Audit's draft lines, never the card (hamr 2026-11-13, F-b)
|
|
@@ -1211,184 +1167,6 @@ const scrubRed = (r) => /** @type {any} */ (Object.fromEntries(
|
|
|
1211
1167
|
Object.entries(r).map(([k, v]) => [k, typeof v === 'string' ? redactSecrets(v) : v]),
|
|
1212
1168
|
));
|
|
1213
1169
|
|
|
1214
|
-
/**
|
|
1215
|
-
* THE one spelling of "a passed calibration gate stands in for the seed red": the
|
|
1216
|
-
* close carries a judged stage AND the gate ran and passed. A failed or missing
|
|
1217
|
-
* calibration never satisfies it, and a close with no judged stage never reaches it.
|
|
1218
|
-
* @param {any[]} judged `judgedStages(closeDecl)` @param {any} calibration `gates.calibration`
|
|
1219
|
-
* @returns {boolean}
|
|
1220
|
-
*/
|
|
1221
|
-
export function seedProofIsCalibration(judged, calibration) {
|
|
1222
|
-
return judged.length > 0 && calibration?.ok === true;
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
/**
|
|
1226
|
-
* GATE 4 — the calibration gate, and the only gate here that spends money.
|
|
1227
|
-
*
|
|
1228
|
-
* It answers ONE question: has this close's own ruler been shown to grade the
|
|
1229
|
-
* signer's own ten correctly, itemized, and to resist all five attack styles?
|
|
1230
|
-
* Anything else it learns — a missing set, an unwired judge, a dead call — is
|
|
1231
|
-
* reported under its own name and refuses, because every one of them leaves the
|
|
1232
|
-
* question unanswered and an unanswered calibration is not a passed one.
|
|
1233
|
-
*
|
|
1234
|
-
* THE CASUALTY SPLIT is the same one the judged stage runs (F45, contract (a)): a
|
|
1235
|
-
* provider failure, an unpriced call or an unparseable emission after the ladder
|
|
1236
|
-
* says NOTHING about the set. It refuses the signature — an ungraded ruler is
|
|
1237
|
-
* still ungraded — but it refuses under the TRANSPORT's name, so the operator is
|
|
1238
|
-
* sent to the socket or the meter and never to their own rubric.
|
|
1239
|
-
* AND IT MEETS THE ONE CEILING. This is the run's THIRD paid seam — the largest of
|
|
1240
|
-
* them, at up to `CALIBRATION_SIZE` locate calls plus a five-artifact battery, each
|
|
1241
|
-
* under its own retry ladder — and it used to run with no bound at all while the
|
|
1242
|
-
* scout and the declaration loop were both stopped by the operator's own number.
|
|
1243
|
-
* That is the advertised budget and the enforced budget being two different numbers.
|
|
1244
|
-
* The book is built HERE and PRIOR SPEND IS ABSORBED into it, so the ceiling folds in
|
|
1245
|
-
* what the earlier seams already spent and re-invoking a seam cannot silently widen
|
|
1246
|
-
* it; the gate reads it between calls and stops as a refusal that names money.
|
|
1247
|
-
* `judgeModel` is the RESOLVED judge identity (PRD item 32.1), required and with no
|
|
1248
|
-
* default: it is stamped onto the graded set and onto the calibration-missing record
|
|
1249
|
-
* alike, so both say which judge the close would have been certified by.
|
|
1250
|
-
* @param {{spec: any, judgedStages: any[], judgeLoop: Function|null, judgeModel: string,
|
|
1251
|
-
* onJudgeCost: ((c: any) => void)|null, calibrateFn: Function,
|
|
1252
|
-
* ceilingUsd: number|null, priorCalls: any[]}} o
|
|
1253
|
-
* @returns {Promise<{ok: boolean, record: any, reds: Red[], refusal: Refusal|null}>}
|
|
1254
|
-
*/
|
|
1255
|
-
async function calibrationGate({ spec, judgedStages, judgeLoop, judgeModel, onJudgeCost, calibrateFn, ceilingUsd, priorCalls }) {
|
|
1256
|
-
const cases = spec.closeDecl?.calibration?.cases ?? null;
|
|
1257
|
-
// ONE card, and it is the SIGNED one — the card the calibration is graded
|
|
1258
|
-
// against must be the card the close will RUN, or the gate certifies a ruler
|
|
1259
|
-
// nobody is going to use. `validateCloseDecl` has already refused a second
|
|
1260
|
-
// judged stage (AT_MOST_ONCE_KINDS), so there is exactly one here.
|
|
1261
|
-
const card = judgedStages[0]?.params?.card ?? null;
|
|
1262
|
-
|
|
1263
|
-
if (cases === null || cases === undefined) {
|
|
1264
|
-
const detail = `This close judges with a rubric card, and no calibration set is stored with it. The judged floor `
|
|
1265
|
-
+ `is only a floor once the whole pipe has graded ${CALIBRATION_SIZE} signed cases correctly — until then the `
|
|
1266
|
-
+ 'ruler is unmeasured, and an unmeasured ruler cannot be signed.';
|
|
1267
|
-
return {
|
|
1268
|
-
ok: false,
|
|
1269
|
-
record: { ok: false, stop: 'calibration-missing', judgeModel, required: CALIBRATION_SIZE },
|
|
1270
|
-
reds: [{ code: 'calibration-missing', path: 'closeDecl.calibration.cases', detail }],
|
|
1271
|
-
refusal: refuse({
|
|
1272
|
-
kind: 'decision-ready',
|
|
1273
|
-
verb: null,
|
|
1274
|
-
path: 'closeDecl.calibration',
|
|
1275
|
-
detail,
|
|
1276
|
-
options: [
|
|
1277
|
-
`author the calibration set from the interview's own Q7 answer (${CALIBRATION_SIZE} cases, mixed polarity) and re-sign`,
|
|
1278
|
-
'drop the judged stage and describe a job whose done is machine-checkable',
|
|
1279
|
-
'abandon the job',
|
|
1280
|
-
],
|
|
1281
|
-
}),
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
// ONE CEILING, ALL THE PAID SEAMS (`authorCloseForJob` says the same words over
|
|
1286
|
-
// the compile). The book absorbs what the run has already spent, so what the gate
|
|
1287
|
-
// reads is the REMAINING balance and never a fresh allowance; `absorb` deliberately
|
|
1288
|
-
// does not re-fire a reporter, so nothing is counted twice downstream.
|
|
1289
|
-
const book = makeCostBook({ ceilingUsd });
|
|
1290
|
-
book.absorb(Array.isArray(priorCalls) ? priorCalls : []);
|
|
1291
|
-
const cal = await calibrateFn({
|
|
1292
|
-
cases,
|
|
1293
|
-
card,
|
|
1294
|
-
judgeLoop,
|
|
1295
|
-
judgeModel,
|
|
1296
|
-
// the gate's own calls join the same tally the ceiling is read against — a
|
|
1297
|
-
// ceiling that cannot see the spend it bounds is F45's blind detector in a
|
|
1298
|
-
// money coat. The caller's reporter fires with the call's whole record, after.
|
|
1299
|
-
onCost: (/** @type {any} */ c) => {
|
|
1300
|
-
book.absorb([{ label: c?.label ?? 'calibrate', costUsd: c?.costUsd ?? null, unpricedRounds: c?.unpricedRounds ?? 0 }]);
|
|
1301
|
-
if (typeof onJudgeCost === 'function') onJudgeCost(c);
|
|
1302
|
-
},
|
|
1303
|
-
capStop: () => book.capStop(),
|
|
1304
|
-
});
|
|
1305
|
-
|
|
1306
|
-
/** what the signing evidence KEEPS about this gate. The per-case artifacts are
|
|
1307
|
-
* deliberately not in it — they are already in the signed spec, and a second
|
|
1308
|
-
* copy in the evidence file is a second thing to keep in step. Each graded row's
|
|
1309
|
-
* `diag` (F192) keeps the judge's own facts and the decision's reds — scrubbed
|
|
1310
|
-
* and bounded quotes, never an artifact body — so a refusal reads from its own
|
|
1311
|
-
* record. What IS kept is
|
|
1312
|
-
* WHICH BYTES were certified (`cardHash`/`casesHash`/`setHash`) and BY WHICH
|
|
1313
|
-
* MODEL (`judgeModel`), which is what makes a judge-model bump detectable at
|
|
1314
|
-
* all. */
|
|
1315
|
-
const record = {
|
|
1316
|
-
ok: cal.ok,
|
|
1317
|
-
stop: cal.stop,
|
|
1318
|
-
judgeModel: cal.judgeModel,
|
|
1319
|
-
cardHash: cal.cardHash,
|
|
1320
|
-
casesHash: cal.casesHash,
|
|
1321
|
-
setHash: cal.setHash,
|
|
1322
|
-
graded: cal.graded,
|
|
1323
|
-
failures: cal.failures,
|
|
1324
|
-
injection: cal.injection,
|
|
1325
|
-
casualty: cal.casualty,
|
|
1326
|
-
costUsd: cal.costUsd,
|
|
1327
|
-
knownUsd: cal.knownUsd,
|
|
1328
|
-
spendComplete: cal.spendComplete,
|
|
1329
|
-
calls: cal.calls?.length ?? 0,
|
|
1330
|
-
};
|
|
1331
|
-
if (cal.ok) return { ok: true, record, reds: [], refusal: null };
|
|
1332
|
-
|
|
1333
|
-
const reds = cal.reds.map(scrubRed);
|
|
1334
|
-
const casualty = cal.casualty !== null && cal.casualty !== undefined;
|
|
1335
|
-
/** the OPERATOR's own governance stop, and it is neither a casualty nor a reading
|
|
1336
|
-
* of the close: the ceiling ran out mid-question, and what was graded before it
|
|
1337
|
-
* did says nothing either way about the rest of the set. */
|
|
1338
|
-
const budget = cal.stop === 'cap-halt' || cal.stop === 'pricing-red';
|
|
1339
|
-
const detail = budget
|
|
1340
|
-
? (cal.stop === 'cap-halt'
|
|
1341
|
-
? `The calibration gate ran out of CEILING before it could finish: ${cal.graded.length} of `
|
|
1342
|
-
+ `${Array.isArray(cases) ? cases.length : 0} case(s) were graded and the next call was never made. A `
|
|
1343
|
-
+ 'part-graded set is an ungraded ruler, so nothing is signable — and nothing here says the ruler is wrong.'
|
|
1344
|
-
: 'The calibration gate stopped on an UNPRICED call: with the run\'s total unknown the ceiling cannot be read '
|
|
1345
|
-
+ 'against it, and unpriced is never free (F6). Nothing here says anything about the set.')
|
|
1346
|
-
: casualty
|
|
1347
|
-
? `The calibration gate could not be RUN: the judge produced no usable facts for ${cal.casualty.kind} `
|
|
1348
|
-
+ `"${cal.casualty.at}" [${cal.casualty.axis}]. A broken judge is a casualty and never a verdict, so this says `
|
|
1349
|
-
+ 'nothing about the set — but an ungraded ruler is still an ungraded ruler, and it cannot be signed.'
|
|
1350
|
-
: cal.stop === 'no-judge'
|
|
1351
|
-
? `This close carries a judged stage and no judge seam was wired, so the ${CALIBRATION_SIZE}-case gate never ran. `
|
|
1352
|
-
+ 'An absent seam is a wiring gap, never a fall-back: a gate that grades nothing would certify every close.'
|
|
1353
|
-
: cal.stop === 'invalid-set'
|
|
1354
|
-
? 'The stored rubric card and calibration set do not compose into something gradeable, so the gate refused '
|
|
1355
|
-
+ 'before spending anything.'
|
|
1356
|
-
: `The whole pipe did not grade this close's own calibration set correctly: `
|
|
1357
|
-
+ `${cal.failures.length} of ${Array.isArray(cases) ? cases.length : 0} case(s) graded wrong`
|
|
1358
|
-
+ `${cal.injection.leaks.length ? ` and ${cal.injection.leaks.length} injection style(s) leaked` : ''}. `
|
|
1359
|
-
+ `The floor is ${CALIBRATION_SIZE}/${CALIBRATION_SIZE} with itemized reds and all styles resisting `
|
|
1360
|
-
+ '(hamr, 2026-08-18) — the fix for a miss is a new card line or a corrected case, and a re-sign.';
|
|
1361
|
-
|
|
1362
|
-
return {
|
|
1363
|
-
ok: false,
|
|
1364
|
-
record,
|
|
1365
|
-
reds,
|
|
1366
|
-
refusal: refuse({
|
|
1367
|
-
kind: 'decision-ready',
|
|
1368
|
-
verb: null,
|
|
1369
|
-
path: 'closeDecl.calibration',
|
|
1370
|
-
detail,
|
|
1371
|
-
options: budget
|
|
1372
|
-
? [
|
|
1373
|
-
'raise the authoring ceiling and re-run the gate — the $0 gates above are already passed',
|
|
1374
|
-
'run the gate unbounded (omit the ceiling) — that is a stated operator choice, never a default',
|
|
1375
|
-
'abandon the job',
|
|
1376
|
-
]
|
|
1377
|
-
: casualty || cal.stop === 'no-judge'
|
|
1378
|
-
? [
|
|
1379
|
-
'wire a judge provider pinned to the judged tier and re-run the gate',
|
|
1380
|
-
'wait out the provider and re-run — nothing about the close was judged here',
|
|
1381
|
-
'abandon the job',
|
|
1382
|
-
]
|
|
1383
|
-
: [
|
|
1384
|
-
'correct the card line or the case the pipe graded differently, and re-sign',
|
|
1385
|
-
'read the itemized rows above: a case the pipe reds for the WRONG reason is the card talking, not the judge',
|
|
1386
|
-
'abandon the job',
|
|
1387
|
-
],
|
|
1388
|
-
}),
|
|
1389
|
-
};
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
1170
|
/**
|
|
1393
1171
|
* D9, in code: *nothing JUDGES the close; three mechanical gates plus a
|
|
1394
1172
|
* signature.* No LLM validates another LLM's close, here or anywhere.
|
|
@@ -1402,23 +1180,7 @@ async function calibrationGate({ spec, judgedStages, judgeLoop, judgeModel, onJu
|
|
|
1402
1180
|
* A close with NO work stage red at seed has nothing to do and is refused
|
|
1403
1181
|
* decision-ready — gate-2 round 2's arm B died exactly there, on a mypy that
|
|
1404
1182
|
* scanned nothing and therefore read clean.
|
|
1405
|
-
*
|
|
1406
|
-
* `judged-floor` stage ONLY. The whole judged pipe runs over the signed ten
|
|
1407
|
-
* and the five arbiter-owned injection artifacts, and anything short of
|
|
1408
|
-
* 10/10 with itemized reds and 5/5 resisted is an unsignable close. It is
|
|
1409
|
-
* the ONE gate here that spends money, so it runs LAST — every free refusal
|
|
1410
|
-
* has already had its chance, and nobody pays to discover a broken
|
|
1411
|
-
* declaration.
|
|
1412
|
-
*
|
|
1413
|
-
* D9.3 AND THE JUDGED CLOSE (2026-08-18 second addendum, ruling 3; hamr: *"fix it now,
|
|
1414
|
-
* we are delivering softgreen, isn't that the whole point?"*; widened 2026-10-09 to mixed
|
|
1415
|
-
* closes, hamr: *"a rubric job should check if judge can judge (calibration) and judge
|
|
1416
|
-
* rules can apply properly to pass ... we can't close everything upfront"*). Gate 3
|
|
1417
|
-
* protects against a close that cannot fail. A judged stage SKIPS the seed read by ruling
|
|
1418
|
-
* 8, so it can never show red there. For ANY close carrying a judged stage (pure or
|
|
1419
|
-
* mixed with mechanical stages), a PASSED calibration gate plays the seed-red role
|
|
1420
|
-
* (`seedProofIsCalibration`). A close with NO judged stage is UNCHANGED: some work stage
|
|
1421
|
-
* must be red at the seed. A failed or missing calibration never satisfies it.
|
|
1183
|
+
* (There was a fourth, paid gate, the calibration gate of the old judge; it is gone with the old judge, 2026-11-14.)
|
|
1422
1184
|
*
|
|
1423
1185
|
* Gates 2 and 3 share ONE execution, and that is stated rather than hidden: at
|
|
1424
1186
|
* job creation the tree IS the seed, so "does every stage run against the real
|
|
@@ -1431,35 +1193,18 @@ async function calibrationGate({ spec, judgedStages, judgeLoop, judgeModel, onJu
|
|
|
1431
1193
|
* comes back is the resolved spec, its hash, and the evidence to sign against.
|
|
1432
1194
|
*
|
|
1433
1195
|
* @param {{spec: any, workdir: string, seedRef?: string|null, shellCapUsd?: number,
|
|
1434
|
-
* timeoutMs?: number, seedFn?: Function, listingFn?: Function, seedReadFn?: Function
|
|
1435
|
-
* judgeLoop?: Function|null, judgeModel?: string|null, onJudgeCost?: ((c: any) => void)|null,
|
|
1436
|
-
* calibrateFn?: Function, ceilingUsd?: number|null, priorCalls?: any[]}} o
|
|
1196
|
+
* timeoutMs?: number, seedFn?: Function, listingFn?: Function, seedReadFn?: Function}} o
|
|
1437
1197
|
* @returns {Promise<{ok: boolean, specHash: string|null, seedRef: string|null,
|
|
1438
1198
|
* gates: any, work: any[], guards: any[], stops: any[], reds: Red[], refusal: Refusal|null}>}
|
|
1439
1199
|
*/
|
|
1440
1200
|
export async function prepareSigning({
|
|
1441
1201
|
spec, workdir, seedRef = null, shellCapUsd, timeoutMs,
|
|
1442
1202
|
seedFn = seedAtHead, listingFn = seedListing, seedReadFn = runSeedRead,
|
|
1443
|
-
// THE PAID SEAM, and it is the operator's to wire — this module owns no
|
|
1444
|
-
// provider and picks none (the same contract `authorCloseForJob` keeps for the
|
|
1445
|
-
// drafting model). Absent is never a fall-back: a judged close whose gate could
|
|
1446
|
-
// not run is refused, not waved through. `judgeModel` is the seam's other half
|
|
1447
|
-
// (PRD item 32.1) — WHICH model that loop drives, resolved by the caller
|
|
1448
|
-
// (`resolveJudge`, src/judged.js). The two travel together: a gate that grades
|
|
1449
|
-
// without recording its judge certifies a floor nobody can attribute.
|
|
1450
|
-
judgeLoop = null, judgeModel = null, onJudgeCost = null, calibrateFn = runCalibration,
|
|
1451
|
-
// THE OPERATOR'S CEILING, and the spend it has already met. `null`/absent is
|
|
1452
|
-
// UNBOUNDED and is a stated choice, never a default invented here (the same
|
|
1453
|
-
// contract `authorCloseForJob` keeps). `priorCalls` is what the earlier paid
|
|
1454
|
-
// seams of this run already cost — a `makeCostBook().report().calls` list — and
|
|
1455
|
-
// it is ABSORBED so the gate reads the remaining balance rather than opening a
|
|
1456
|
-
// fresh allowance under the same number.
|
|
1457
|
-
ceilingUsd = null, priorCalls = [],
|
|
1458
1203
|
}) {
|
|
1459
1204
|
/** @type {any} */
|
|
1460
1205
|
const base = {
|
|
1461
1206
|
ok: false, specHash: null, seedRef: null, work: [], guards: [], stops: [], reds: [], refusal: null,
|
|
1462
|
-
gates: { declaration: null, precheck: null, seedVerdict: null
|
|
1207
|
+
gates: { declaration: null, precheck: null, seedVerdict: null },
|
|
1463
1208
|
};
|
|
1464
1209
|
|
|
1465
1210
|
// ── gate 1a: the spec itself. A declared close that is not on a plan-shape
|
|
@@ -1514,7 +1259,7 @@ export async function prepareSigning({
|
|
|
1514
1259
|
}
|
|
1515
1260
|
// the class rides from the SPEC (PRD v1.57 §2) — gate 1a already refused a spec
|
|
1516
1261
|
// whose class is unknown or locked, so this is the class D5's battery hangs off
|
|
1517
|
-
const dv = validateCloseDecl(spec.closeDecl, { at: 'closeDecl', listing: listed.files, verdictType: spec.verdictType,
|
|
1262
|
+
const dv = validateCloseDecl(spec.closeDecl, { at: 'closeDecl', listing: listed.files, verdictType: spec.verdictType, jobLines: Array.isArray(spec.jobLines) ? spec.jobLines : null, inputLabels: inputLabelsOf(spec.inputs) });
|
|
1518
1263
|
// the grounded gate's reds quote BOTH untrusted sources — the declaration, and
|
|
1519
1264
|
// the seed listing itself (the listing rule names what really sits beside an
|
|
1520
1265
|
// invented path). The listing half is a channel gate 1a structurally cannot
|
|
@@ -1562,7 +1307,7 @@ export async function prepareSigning({
|
|
|
1562
1307
|
};
|
|
1563
1308
|
if (stops.length) {
|
|
1564
1309
|
// M2: a rubric job's readout never uses the code-job wording ("install, build and test commands")
|
|
1565
|
-
const rubricJob = (Array.isArray(spec.closeDecl?.stages) ? spec.closeDecl.stages : []).some((/** @type {any} */ st) => st &&
|
|
1310
|
+
const rubricJob = (Array.isArray(spec.closeDecl?.stages) ? spec.closeDecl.stages : []).some((/** @type {any} */ st) => st && st.kind === 'rubric-step');
|
|
1566
1311
|
const reds = stops.map((s) => ({
|
|
1567
1312
|
code: 'broken-close',
|
|
1568
1313
|
...(rubricJob ? { rubricJob: true } : {}),
|
|
@@ -1598,49 +1343,12 @@ export async function prepareSigning({
|
|
|
1598
1343
|
workRed: workRed.map((r) => r.stage),
|
|
1599
1344
|
};
|
|
1600
1345
|
|
|
1601
|
-
// ── gate 4: THE CALIBRATION GATE (softgreen module 5). The ONLY paid gate, and
|
|
1602
|
-
// it runs LAST for exactly that reason: every $0 refusal above has already had
|
|
1603
|
-
// its chance, so a broken declaration or a stage that cannot run is found for
|
|
1604
|
-
// free. MANDATORY for any close carrying a judged-floor stage — module 4's
|
|
1605
|
-
// validator checks a stored set for LEGALITY only and deliberately allows a
|
|
1606
|
-
// judged stage with no set at all, because making it mandatory is a signing
|
|
1607
|
-
// decision and this is the signing gate.
|
|
1608
|
-
const judged = judgedStages(spec.closeDecl);
|
|
1609
|
-
if (judged.length) {
|
|
1610
|
-
if (judgeLoop !== null && (typeof judgeModel !== 'string' || judgeModel.trim() === '')) {
|
|
1611
|
-
throw new Error('[authorjob] prepareSigning was wired a judgeLoop with no judgeModel (PRD item 32.1). The two '
|
|
1612
|
-
+ 'halves of the judge seam travel together: the graded set is stamped with the judge that certified it, and '
|
|
1613
|
-
+ 'there is no library pin to fall back to.');
|
|
1614
|
-
}
|
|
1615
|
-
const cal = await calibrationGate({
|
|
1616
|
-
spec, judgedStages: judged, judgeLoop, judgeModel: /** @type {string} */ (judgeModel),
|
|
1617
|
-
onJudgeCost, calibrateFn, ceilingUsd, priorCalls,
|
|
1618
|
-
});
|
|
1619
|
-
base.gates.calibration = cal.record;
|
|
1620
|
-
if (!cal.ok) return { ...base, work, guards, reds: cal.reds, refusal: cal.refusal };
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
1346
|
// D9.3 — nothing red at seed means nothing to do. Round 2's arm B read GREEN
|
|
1624
1347
|
// with value 0 because mypy died on an unrelated broken fixture and scanned
|
|
1625
1348
|
// nothing: an instrument scanning nothing reads clean, which is F6's shape at
|
|
1626
1349
|
// the close-authoring layer, and this gate is what refuses it BEFORE a
|
|
1627
1350
|
// signature rather than after a paid run.
|
|
1628
|
-
|
|
1629
|
-
// THE JUDGED ROUTE (ruling 3, widened 2026-10-09 by hamr: "a rubric job should
|
|
1630
|
-
// check if judge can judge (calibration) and judge rules can apply properly to
|
|
1631
|
-
// pass ... we can't close everything upfront"). A close carrying ANY judged stage
|
|
1632
|
-
// has a work-bearing stage that ruling 8 exempts from the seed read, so the seed
|
|
1633
|
-
// cannot show it red — not because it measures nothing, but because it is not
|
|
1634
|
-
// measured there. Its proof of failability is the calibration gate, which has
|
|
1635
|
-
// just run and passed (a failed one returned above), and which contains signed
|
|
1636
|
-
// cases the pipe must RED as well as ones it must pass. That holds for a PURE
|
|
1637
|
-
// judged close and a MIXED one alike; a close with NO judged stage takes the
|
|
1638
|
-
// original path unchanged (some work stage must be red at the seed).
|
|
1639
|
-
if (workRed.length === 0 && seedProofIsCalibration(judged, base.gates.calibration)) {
|
|
1640
|
-
// said out loud in the record: this close passed gate 3 on a DIFFERENT proof,
|
|
1641
|
-
// and a reader must never have to infer which one from an empty workRed list
|
|
1642
|
-
base.gates.seedVerdict.satisfiedBy = 'calibration';
|
|
1643
|
-
} else if (!workRed.length) {
|
|
1351
|
+
if (!workRed.length) {
|
|
1644
1352
|
return {
|
|
1645
1353
|
...base,
|
|
1646
1354
|
work,
|