bareloop 0.56.0 → 0.57.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +3 -3
  3. package/bareloop.context.md +65 -207
  4. package/package.json +2 -2
  5. package/src/authorflow.js +25 -78
  6. package/src/authoring.js +5 -124
  7. package/src/authorjob.js +33 -395
  8. package/src/authorreadout.js +17 -355
  9. package/src/authorrun.js +8 -211
  10. package/src/blockasks.js +2 -2
  11. package/src/bundlerun.js +4 -1
  12. package/src/checkblock.js +76 -50
  13. package/src/checklist.js +1 -1
  14. package/src/checkpick.js +10 -1
  15. package/src/cli.js +3 -3
  16. package/src/declaredclose.js +11 -110
  17. package/src/destpoint.js +1 -1
  18. package/src/index.js +3 -43
  19. package/src/interviewrun.js +13 -8
  20. package/src/job.js +20 -1
  21. package/src/jobblock.js +11 -46
  22. package/src/judged.js +13 -1229
  23. package/src/kinds.js +5 -347
  24. package/src/noteask.js +124 -0
  25. package/src/pagedry.js +27 -5
  26. package/src/pagemap.js +2 -2
  27. package/src/pagerules.js +18 -3
  28. package/src/panel/authorroutes.js +9 -3
  29. package/src/panel/authorsession.js +99 -141
  30. package/src/panel/importrun.js +0 -1
  31. package/src/panel/index.html +6 -6
  32. package/src/panel/jobplan.js +7 -5
  33. package/src/panel/server.js +25 -64
  34. package/src/panel/status.js +3 -0
  35. package/src/pickrecord.js +15 -54
  36. package/src/planrun.js +2 -48
  37. package/src/promptregisters.js +2 -17
  38. package/src/providerrows.js +0 -36
  39. package/src/providers.js +4 -25
  40. package/src/questionbox.js +4 -12
  41. package/src/rubricstep.js +26 -6
  42. package/src/run.js +2 -15
  43. package/src/userrun.js +14 -111
  44. package/types/authorflow.d.ts +9 -58
  45. package/types/authoring.d.ts +1 -14
  46. package/types/authorjob.d.ts +13 -55
  47. package/types/authorreadout.d.ts +8 -80
  48. package/types/blockasks.d.ts +1 -2
  49. package/types/checkblock.d.ts +32 -17
  50. package/types/checklist.d.ts +2 -2
  51. package/types/checkpick.d.ts +5 -0
  52. package/types/cli.d.ts +1 -3
  53. package/types/declaredclose.d.ts +3 -33
  54. package/types/index.d.ts +2 -4
  55. package/types/job.d.ts +8 -0
  56. package/types/jobblock.d.ts +8 -38
  57. package/types/judged.d.ts +7 -357
  58. package/types/kinds.d.ts +3 -104
  59. package/types/noteask.d.ts +76 -0
  60. package/types/pagedry.d.ts +13 -0
  61. package/types/pagerules.d.ts +7 -0
  62. package/types/panel/authorsession.d.ts +35 -4
  63. package/types/panel/jobplan.d.ts +3 -3
  64. package/types/panel/server.d.ts +13 -5
  65. package/types/panel/status.d.ts +5 -0
  66. package/types/pickrecord.d.ts +8 -13
  67. package/types/planrun.d.ts +1 -22
  68. package/types/providerrows.d.ts +0 -31
  69. package/types/providers.d.ts +3 -19
  70. package/types/rubricstep.d.ts +9 -0
  71. package/types/run.d.ts +1 -20
  72. package/types/userrun.d.ts +0 -1
  73. package/src/calibrate.js +0 -702
  74. package/src/cardauthor.js +0 -502
  75. package/src/fitcheck.js +0 -168
  76. package/types/calibrate.d.ts +0 -201
  77. package/types/cardauthor.d.ts +0 -358
  78. package/types/fitcheck.d.ts +0 -119
package/src/cardauthor.js DELETED
@@ -1,502 +0,0 @@
1
- // THE TWO SIGNED ARTIFACTS — softgreen module 4 (design record
2
- // docs/logs/2026-08-17-softgreen-review-door-design.md §4.3 and §4.4,
3
- // plus the 2026-08-18 threshold addendum).
4
- //
5
- // Module 1 built the judged floor's core, module 2 wired the stage into a close,
6
- // module 3 opened the class and asked the extra question. Nothing compiled its
7
- // answer. This module does exactly that and nothing more:
8
- //
9
- // Judge Examples → THE RUBRIC CARD (§4.3) — the person's own pass/fail
10
- // lines, as ENUMERATED items over the arbiter's own
11
- // rulebook, compiled from the "why" half of their answer.
12
- // → THE CALIBRATION SET (§4.4) — TEN cases, frozen, that the
13
- // whole pipe must grade before the close is signable.
14
- //
15
- // PRD item 33 M3 piece 3 (2026-09-13): the old Q6 ("what separates a pass from
16
- // a fail?") and Q7 ("give one you'd pass and one you'd fail, and say why")
17
- // merged into ONE form field, Judge Examples — Q7's wording, verbatim
18
- // (`SOFTGREEN_JUDGE_EXAMPLES_KEY`/`JUDGE_EXAMPLES_QUESTION`, `authorflow.js`).
19
- // Q6 is not lost: the "why" lines of a real pass/fail pair are what this
20
- // module already compiled a card FROM, and asking the differentiator twice —
21
- // once in the abstract, once against a real example — was the double-ask.
22
- //
23
- // ── THE D5 PATH, AND WHY IT IS THIS ONE ─────────────────────────────────────
24
- //
25
- // Both artifacts are SHOWN AND FIXED: an LLM proposes the extractable rewrite of
26
- // what the person said, the SIGNER fixes it, and THE FIXED VERSION IS WHAT IS
27
- // STORED — enumerated inside the spec hash, so a card line or a case is a re-sign
28
- // exactly like every other spec edit. Asking the person to write the rubric
29
- // themselves is the SWE tax this product refuses; letting the model's draft ride
30
- // unsigned is the arbiter authored by a model. The signer in the middle is the
31
- // whole design.
32
- //
33
- // ── WHAT THIS MODULE DOES NOT DO ────────────────────────────────────────────
34
- //
35
- // * IT DOES NOT GRADE. The calibration GATE — running LOCATE and `decide()`
36
- // over the ten and refusing a signature on anything short of 10/10 with
37
- // itemized reds, alongside the upstream INJECTION_BATTERY — is module 5. What
38
- // is built here is what that gate reads.
39
- // * IT STORES NO INJECTION CASES. The battery is upstream's and it is module
40
- // 5's to run; a copy of it stored here would be a second inventory of
41
- // somebody else's evidence.
42
- // * IT PICKS NO NUMBER. `CALIBRATION_SIZE` is hamr's own ruling, verbatim
43
- // (*"go build 10, we could double later"*). It is operator territory and a
44
- // size change is a spec-level threshold change — the standing
45
- // no-agent-threshold-picking rule binds here exactly as everywhere else.
46
- // * IT ADMITS NO DOC-GENRE ARTIFACT. A case is code-genre text, because the
47
- // catalogue is code-genre only.
48
- //
49
- // ── THE CASE SHAPE, AND WHY EACH FIELD EXISTS ───────────────────────────────
50
- //
51
- // { id, artifact, expect: { verdict: "pass"|"red", reds: [{ rule, fn }] } }
52
- //
53
- // `artifact` REAL TEXT — a file excerpt from the patient or a realistic
54
- // snippet the signer edits. It is what LOCATE will be pointed at,
55
- // so it is the artifact and never a description of one.
56
- // `verdict` what `decide()` must render. Two values, both reachable.
57
- // `reds` the ITEMIZED expectation, and the floor is itemized reds rather
58
- // than verdict-match: a pipe that reds the right case for the wrong
59
- // reason has not been calibrated, it has been lucky. `rule` selects
60
- // from the CARD's own lines (a case cannot expect a red from a line
61
- // the card never named — §4.3's ceiling, made mechanical), and `fn`
62
- // names the function the red lands on, which is the address
63
- // `decide()` itself reports.
64
- //
65
- // WHAT IS DELIBERATELY NOT STORED: the red's `why` and its `quote`. Both are the
66
- // judge's own prose about a specific emission, and a signer cannot predict either
67
- // — pinning them would fail an honest pipe on wording. `expectedOf` is the one
68
- // spelling of that reduction, so the shape the signer stores and the shape the
69
- // pipe produces are one shape read twice (module 5 compares them mechanically).
70
-
71
- import {
72
- JUDGE_RULE_IDS, JUDGE_RULES, CALIBRATION_SIZE, CASE_VERDICTS, validateJudgedArtifacts,
73
- } from './judged.js';
74
- import { askStructured, makeCostBook, SOFTGREEN_JUDGE_EXAMPLES_KEY, JUDGE_EXAMPLES_QUESTION } from './authorflow.js';
75
- import { judgedStages } from './kinds.js';
76
- import { isObj, redactSecrets } from './validate.js';
77
-
78
- /** @typedef {{code: string, path: string, detail: string, [k: string]: any}} Red */
79
-
80
- // ── THE NUMBERS, ALL OPERATOR-SET ───────────────────────────────────────────
81
- //
82
- // `CALIBRATION_SIZE` and `CASE_VERDICTS` are imported from `src/judged.js`, never
83
- // re-spelled: what a legal set IS belongs to the arbiter beside the rulebook, and
84
- // a second copy of the size here is a second threshold to keep in step.
85
-
86
- /** the output channel for the compile. It takes no action; it carries the answer. */
87
- export const PROPOSAL_TOOL_NAME = 'propose_rubric';
88
- /** what the tool returns. The loop stops on delivery, so the model never reads it. */
89
- export const PROPOSAL_ACK = 'proposal received';
90
- /** the label the compile call is metered and persisted under — one spelling */
91
- export const PROPOSAL_LABEL = 'judged-compile';
92
- /** a malformed EMISSION is a transport fault, bounded on its own axis — the same
93
- * ceiling `authorClose` declares for the declaration channel */
94
- export const MAX_PROPOSAL_RETRIES = 2;
95
-
96
- // ── 1. THE SCHEMA — the closed sets, handed over ────────────────────────────
97
-
98
- /**
99
- * The proposal's shape, and therefore the whole shape the compiler can express.
100
- *
101
- * `rule` is an ENUM off the judge's own rulebook in BOTH places it appears — the
102
- * card's lines and a case's expected reds — because wherever only a closed set
103
- * can satisfy a field, the illegal value is made INEXPRESSIBLE rather than
104
- * rejected after the fact (the `check-passes(name)` model). The SIZE is pinned by
105
- * `minItems`/`maxItems` from the one constant, so nine and eleven are both
106
- * unsayable rather than argued about afterwards.
107
- *
108
- * `artifact` and `text` are the only free strings, and neither decides anything:
109
- * one is the code the judge will read, the other is the signer's own words.
110
- */
111
- export function proposalSchema() {
112
- const ruleEnum = { enum: [...JUDGE_RULE_IDS], description: 'which owned rule this line asserts' };
113
- return {
114
- type: 'object',
115
- properties: {
116
- card: {
117
- type: 'object',
118
- description: 'the rubric, as enumerated items: one line per thing the person actually looks for, in the '
119
- + 'order they look for them.',
120
- properties: {
121
- items: {
122
- type: 'array',
123
- minItems: 1,
124
- items: {
125
- type: 'object',
126
- properties: {
127
- rule: ruleEnum,
128
- text: { type: 'string', minLength: 1, description: 'what this line means, in the person\'s own words' },
129
- },
130
- required: ['rule', 'text'],
131
- additionalProperties: false,
132
- },
133
- },
134
- },
135
- required: ['items'],
136
- additionalProperties: false,
137
- },
138
- cases: {
139
- type: 'array',
140
- minItems: CALIBRATION_SIZE,
141
- maxItems: CALIBRATION_SIZE,
142
- description: `exactly ${CALIBRATION_SIZE} calibration cases, and at least one of each verdict — a set that `
143
- + 'cannot fail one way proves nothing',
144
- items: {
145
- type: 'object',
146
- properties: {
147
- id: { type: 'string', minLength: 1, description: 'a unique lowercase-hyphenated slug' },
148
- artifact: {
149
- type: 'string',
150
- minLength: 1,
151
- description: 'the REAL source text this case is about — what the judge will actually read, never a '
152
- + 'description of it',
153
- },
154
- expect: {
155
- type: 'object',
156
- properties: {
157
- verdict: { enum: [...CASE_VERDICTS] },
158
- reds: {
159
- type: 'array',
160
- description: 'the itemized expectation: empty for a pass, and one entry per card line the artifact '
161
- + 'violates for a red',
162
- items: {
163
- type: 'object',
164
- properties: {
165
- rule: ruleEnum,
166
- fn: { type: 'string', minLength: 1, description: 'the function the red lands on' },
167
- },
168
- required: ['rule', 'fn'],
169
- additionalProperties: false,
170
- },
171
- },
172
- },
173
- required: ['verdict', 'reds'],
174
- additionalProperties: false,
175
- },
176
- },
177
- required: ['id', 'artifact', 'expect'],
178
- additionalProperties: false,
179
- },
180
- },
181
- },
182
- required: ['card', 'cases'],
183
- additionalProperties: false,
184
- };
185
- }
186
-
187
- /**
188
- * The output channel. It records and acknowledges; it takes no action, which is
189
- * why handing it to a toolless compile call does not reopen D3.
190
- * @param {{calls: any[]}} box
191
- */
192
- export function proposalTool(box) {
193
- return {
194
- name: PROPOSAL_TOOL_NAME,
195
- description: `Deliver the rubric card and the ${CALIBRATION_SIZE} calibration cases. Call this exactly once.`,
196
- parameters: proposalSchema(),
197
- execute: async (/** @type {any} */ args) => { box.calls.push(args); return PROPOSAL_ACK; },
198
- };
199
- }
200
-
201
- // ── 2. THE PROMPT ───────────────────────────────────────────────────────────
202
-
203
- /**
204
- * The system prompt a caller BINDS ITS SEAM WITH — this module owns no provider
205
- * and picks none, exactly as `authorClose` does not: the compile call arrives as
206
- * `generate`, and a caller wires it with `makeLoopGenerate(provider, {system:
207
- * COMPILE_SYSTEM})`, whose own `maxTokens` default (F30) is what holds ten
208
- * artifacts. Exported rather than inlined so the one register this call is made
209
- * in is not re-spelled at every integration.
210
- */
211
- export const COMPILE_SYSTEM = 'You compile a person\'s own words into a rubric a deterministic arbiter can run. You '
212
- + 'never decide whether anything passes, you never write code that runs, and you never invent a rule: the rulebook '
213
- + 'is fixed and you select from it.';
214
-
215
- /**
216
- * The compile prompt. The Judge Examples answer travels VERBATIM — it is the
217
- * whole input, and paraphrasing a lay answer is how a rubric stops being the
218
- * person's. PRD item 33 M3 piece 3: this used to be two answers (Q6+Q7);
219
- * `SOFTGREEN_JUDGE_EXAMPLES_KEY` is the ONE key both the interview and this
220
- * compile now read, so a future renumbering of the form moves both readers
221
- * together rather than drifting.
222
- *
223
- * The rulebook is rendered from `JUDGE_RULES` itself rather than restated, for
224
- * the reason the catalogue block is rendered from the catalogue: the prompt and
225
- * the gate must describe one set of facts.
226
- * @param {{answers: Record<string|number, any>, questions?: Record<string|number, string>}} o
227
- */
228
- export function cardCasesPrompt({ answers, questions = {} }) {
229
- const qKey = SOFTGREEN_JUDGE_EXAMPLES_KEY;
230
- const q = questions[qKey] ?? JUDGE_EXAMPLES_QUESTION;
231
- const rules = JUDGE_RULE_IDS.map((id) => `- ${id}\n what it can check: ${JUDGE_RULES[id].means}\n the facts it reads: ${JUDGE_RULES[id].ask.trim().split('\n')[0].trim()}`);
232
-
233
- return `You are compiling ONE person's answers into the two artifacts a judged close is signed with.
234
-
235
- They are not a software engineer. They described what they look for in their own words, and your whole job is to
236
- express that over the rulebook below — never to add a standard they did not state, and never to drop one they did.
237
-
238
- THEIR ANSWER — verbatim, and the only input you have
239
-
240
- Q${qKey}. ${q}
241
- A${qKey}. ${answers?.[qKey] ?? '(no answer given)'}
242
-
243
- Each example is kept with the number of the job line the person wrote it under. Never attach an example to a different
244
- line than the one it names (run mv1j01sl guessed which example belonged to which part of the goal).
245
-
246
- ---
247
-
248
- THE RULEBOOK — the only rules that exist. You SELECT from it; a rule that is not here cannot be asked for.
249
-
250
- ${rules.join('\n')}
251
-
252
- ---
253
-
254
- THE CARD
255
-
256
- One item per thing they actually look for, in the order they look for them. \`rule\` is selected from the rulebook;
257
- \`text\` is what that line means IN THEIR WORDS. The judge only ever checks lines this card names, so a standard you
258
- leave out is a standard nobody checks — and a standard they never stated is one you must not add.
259
-
260
- THE CALIBRATION SET
261
-
262
- Exactly ${CALIBRATION_SIZE} cases. Each one is REAL SOURCE TEXT — a small, realistic file the judge could be pointed
263
- at — plus what the arbiter must decide about it.
264
-
265
- - \`artifact\` is the code itself, never a description of it.
266
- - \`expect.verdict\` is "pass" when the artifact satisfies every card line, "red" when it violates any.
267
- - \`expect.reds\` is EMPTY for a pass, and for a red it names one entry per violation: the card \`rule\` it breaks
268
- and the \`fn\` (function name) it breaks it on.
269
-
270
- AT LEAST ONE PASS AND AT LEAST ONE RED. A set that can only fail one way measures nothing.
271
- Every rule you name in a case must be a rule your card carries.
272
- A case may expect a red only where the rule's "what it can check" line says it can raise one on that artifact: a
273
- function with any doc block above it never breaks has-doc, and "the doc only restates the function name" is a
274
- says-what red, never a has-doc one.
275
-
276
- HOW TO ANSWER
277
-
278
- Call the ${PROPOSAL_TOOL_NAME} tool exactly once, with the card and the ${CALIBRATION_SIZE} cases as its arguments.
279
- Do not write them as text.`;
280
- }
281
-
282
- // ── 3. THE COMPILE CHANNEL ──────────────────────────────────────────────────
283
-
284
- /** the compile's own channel, over the SHARED bounded ladder (`askStructured`) */
285
- const proposalChannel = () => ({
286
- name: PROPOSAL_TOOL_NAME,
287
- instruction: `Your reply did not deliver exactly one proposal through the ${PROPOSAL_TOOL_NAME} tool. `
288
- + `Call ${PROPOSAL_TOOL_NAME} exactly once, with the card and the ${CALIBRATION_SIZE} cases as its arguments. `
289
- + 'Do not write them as text.',
290
- textPath: 'proposal',
291
- tool: (/** @type {{calls: any[]}} */ box) => proposalTool(box),
292
- });
293
-
294
- // ── 4. SHOWN AND FIXED ──────────────────────────────────────────────────────
295
-
296
- /** every free string in the two artifacts, scrubbed at INGEST — an answer, a
297
- * proposed snippet and a signer's edit all become a SIGNED artefact that outlives
298
- * the run, and a file that captures a key captures it forever. The ONE shared
299
- * inventory, never a second one.
300
- *
301
- * AND IT ANNOUNCES. A scrub that silently rewrites bytes leaves a signer reading
302
- * one artifact on screen and signing another on disk — the same failure
303
- * `applyGenreEnv` refuses by returning its `dropped` list rather than quietly
304
- * deleting a model-authored env var. Every altered value is reported by PATH (the
305
- * path only: echoing the matched secret into the announcement would be the same
306
- * leak, one hop on), so the caller can say *this was masked* out loud.
307
- * @param {any} v @param {string} at @param {{path: string}[]} altered */
308
- function scrubDeep(v, at, altered) {
309
- if (typeof v === 'string') {
310
- const masked = redactSecrets(v);
311
- // `redactSecrets` returns a non-matching string byte-identical, so this
312
- // compares equal on every honest value and costs the clean path nothing
313
- if (masked !== v) altered.push({ path: at });
314
- return masked;
315
- }
316
- if (Array.isArray(v)) return v.map((x, i) => scrubDeep(x, `${at}[${i}]`, altered));
317
- if (isObj(v)) return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, scrubDeep(x, at ? `${at}.${k}` : k, altered)]));
318
- return v;
319
- }
320
-
321
- /**
322
- * THE D5 MOMENT. The proposal is SHOWN; the signer's `fix` is what is STORED.
323
- *
324
- * The fix replaces the proposal WHOLE rather than merging into it. A merge would
325
- * mean a signer who deleted a card line got it back, and "the signer signs the
326
- * whole hash" is not a rule that survives a field-wise reconciliation. Handing
327
- * back no fix is a legal answer — signing the proposal as proposed — and it says
328
- * so (`source`), because *a person read this and changed nothing* and *nobody has
329
- * looked* are two different facts.
330
- *
331
- * THE GATE RUNS OVER WHAT WILL BE STORED, never over the proposal: a signer can
332
- * fix a legal proposal into an illegal one, and the artifact that reaches the
333
- * hash is the one that must be legal.
334
- *
335
- * `scrubbed` is the INGEST SCRUB'S OWN ANNOUNCEMENT — the paths whose bytes the
336
- * secret inventory masked on the way in. Empty on every honest artifact, and
337
- * never silent when it is not: a signer signs a hash over the STORED bytes, so
338
- * "what you typed is not what was stored" is a fact they are owed rather than one
339
- * the redactor keeps.
340
- * @param {{proposal: any, fix?: any}} o
341
- * @returns {{ok: boolean, reds: Red[], card: any, cases: any[]|null, source: 'signer'|'proposal',
342
- * scrubbed: {path: string}[]}}
343
- */
344
- export function signJudgedArtifacts({ proposal, fix = null }) {
345
- const source = /** @type {'signer'|'proposal'} */ (fix === null || fix === undefined ? 'proposal' : 'signer');
346
- const chosen = source === 'signer' ? fix : proposal;
347
- if (!isObj(chosen)) {
348
- return {
349
- ok: false,
350
- reds: [{ code: 'invalid-value', path: 'proposal', detail: 'the signed artifacts are an object {card, cases}' }],
351
- card: null,
352
- cases: null,
353
- source,
354
- scrubbed: [],
355
- };
356
- }
357
- // A COPY, scrubbed. The caller keeps its proposal (the run's own audit of what
358
- // the model said); what is stored can never be reached back through it.
359
- /** @type {{path: string}[]} */
360
- const scrubbed = [];
361
- const card = scrubDeep(structuredClone(/** @type {any} */ (chosen).card ?? null), 'card', scrubbed);
362
- const cases = scrubDeep(structuredClone(/** @type {any} */ (chosen).cases ?? null), 'cases', scrubbed);
363
- const v = validateJudgedArtifacts({ card, cases });
364
- return { ok: v.ok, reds: v.reds, card, cases: Array.isArray(cases) ? cases : null, source, scrubbed };
365
- }
366
-
367
- // ── 5. THE FOLD — enumerated into the signed spec ───────────────────────────
368
-
369
- /**
370
- * Fold the two signed artifacts into the close declaration, ENUMERATED.
371
- *
372
- * WHERE EACH LANDS, and both are inside the spec so `jobSpecHash` covers them by
373
- * construction (the hash is over the whole resolved spec):
374
- * - THE CARD replaces the judged stage's own `params.card`. ONE card, and it is
375
- * the SIGNED one: the composer's draft is a draft, and two cards in one close
376
- * is the drift a single storage site exists to prevent. The stage is where it
377
- * already lives, which is what `validateCard`, the M2 runner and the locate
378
- * prompt all read.
379
- * - THE CASES land beside the stages as `calibration.cases` — a close-level
380
- * artifact, because the set calibrates the RULER and not one stage's params,
381
- * and because module 5's gate reads it before any stage runs.
382
- * - THE JUDGE MODEL lands beside them as `calibration.judgeModel`. Since PRD item
383
- * 32.1 that is the RESOLVED judge identity the caller hands in (`resolveJudge`,
384
- * src/judged.js — the spec's signed `judge` override, else the job's own worker
385
- * model), not a library pin. A calibration set is only worth the judge that
386
- * graded it, so the set has to carry which judge certified it or nothing
387
- * downstream can tell a signed floor from a moved one. Storing it HERE, inside
388
- * the spec, is what makes a judge change flip `jobSpecHash`: the signature dies,
389
- * the signer re-signs, and a re-sign is a re-run of the calibration gate. It is
390
- * REQUIRED, with no default — a set stamped with a model nobody named is exactly
391
- * the unattributable floor this field exists to prevent (F45).
392
- *
393
- * A card with NOWHERE TO LAND THROWS. It is a caller's own broken input — a
394
- * signed rubric folded into a close with no judged ruler — and there is no safe
395
- * direction to degrade toward: storing it would sign a rubric nothing reads.
396
- *
397
- * The input is never mutated: a closeDecl is a signed artefact and rewriting a
398
- * caller's copy in place is how two readers come to disagree about what was
399
- * signed.
400
- * @param {any} closeDecl @param {{card: any, cases: any[], judgeModel: string}} o
401
- * @returns {any} a new closeDecl
402
- */
403
- export function foldJudgedArtifacts(closeDecl, { card, cases, judgeModel }) {
404
- if (typeof judgeModel !== 'string' || judgeModel.trim() === '') {
405
- throw new Error('[cardauthor] foldJudgedArtifacts needs the resolved judgeModel (PRD item 32.1): the stored set '
406
- + 'carries the judge that certified it, and there is no library pin to fall back to.');
407
- }
408
- const out = structuredClone(closeDecl);
409
- // `judgedStages` filters `out`'s OWN stage objects, so the card assignment
410
- // below mutates the clone in place — the reason this reads `out`, not the
411
- // caller's `closeDecl`.
412
- const judged = judgedStages(out);
413
- if (judged.length !== 1) {
414
- throw new Error(`[cardauthor] the signed card folds into the close's ONE judged-floor stage, and this close has `
415
- + `${judged.length} — a rubric with nowhere to land is signed evidence nothing reads, and a second judged stage `
416
- + 'is a second bar for one verdict');
417
- }
418
- judged[0].params = { ...(isObj(judged[0].params) ? judged[0].params : {}), card: structuredClone(card) };
419
- out.calibration = { cases: structuredClone(cases), judgeModel };
420
- return out;
421
- }
422
-
423
- // ── 6. THE PAID SEAM ────────────────────────────────────────────────────────
424
-
425
- /**
426
- * ONE compile call: the person's Judge Examples answer in, a proposal out.
427
- *
428
- * It buys ONE artifact through ONE channel, and the malformed-emission ladder is
429
- * the SHARED one (`askStructured`) rather than a second copy — a second ladder is
430
- * a second place for the cap, the reject block and the re-ask to drift.
431
- *
432
- * WHAT IS AND IS NOT RETRIED, and the split is the standing one: a reply that
433
- * carries no proposal is a TRANSPORT fault and is retried under the bound; a
434
- * proposal that PARSED and then broke the ruling is not — the model answered
435
- * perfectly clearly and re-asking buys another call to be told the same thing.
436
- * The proposal is returned as it was said, never repaired: no JSON repair, ever.
437
- *
438
- * The book is the CALLER's, so one ceiling governs the survey, the declaration
439
- * ladder and this compile — the advertised ceiling and the enforced ceiling are
440
- * the same ceiling.
441
- * @param {{answers: Record<string|number, any>, questions?: Record<string|number, string>,
442
- * generate: Function, book?: ReturnType<typeof makeCostBook>,
443
- * structuredMode?: 'tool'|'text', structureRetries?: number}} o
444
- * @returns {Promise<{ok: boolean, proposal: any, reds: Red[], stop: string|null,
445
- * attempts: number, raw: string, cost: any, raws: any[]}>}
446
- */
447
- export async function proposeJudgedArtifacts({
448
- answers, questions = {}, generate,
449
- book = makeCostBook({}),
450
- structuredMode = 'tool',
451
- structureRetries = MAX_PROPOSAL_RETRIES,
452
- }) {
453
- // TIGHTEN-ONLY, floor 0, exactly as `authorClose` clamps its own two axes: a
454
- // caller may buy fewer malformed-emission retries, never more than the ceiling
455
- // this module declares and the suite pins.
456
- const retries = Math.max(0, Math.min(Math.trunc(Number(structureRetries)) || 0, MAX_PROPOSAL_RETRIES));
457
- const prompt = cardCasesPrompt({ answers, questions });
458
- const ask = await askStructured({
459
- messages: [{ role: 'user', content: prompt }],
460
- generate,
461
- mode: structuredMode,
462
- retries,
463
- label: PROPOSAL_LABEL,
464
- book,
465
- channel: proposalChannel(),
466
- });
467
-
468
- const base = {
469
- proposal: ask.artifact ?? null, attempts: ask.attempts, raw: ask.raw,
470
- cost: book.report(), raws: book.raws(),
471
- };
472
- if (ask.budget) {
473
- return {
474
- ...base,
475
- ok: false,
476
- stop: ask.budget,
477
- reds: [{
478
- code: ask.budget,
479
- path: 'budgetUsd',
480
- detail: `the authoring ceiling bound before the rubric compile: $${book.ceilingUsd} is spent, and the call was `
481
- + 'never made. The stop IS the checkpoint — raise the ceiling and re-run, or read what is here and stop',
482
- }],
483
- };
484
- }
485
- if (ask.providerError) {
486
- // a casualty, never evidence about the model — and the transport's own prose
487
- // is scrubbed on the way into a red the caller keeps
488
- return {
489
- ...base,
490
- ok: false,
491
- stop: 'provider-red',
492
- reds: [{ code: 'provider-red', path: PROPOSAL_LABEL, detail: redactSecrets(String(ask.providerError)) }],
493
- };
494
- }
495
- if (!ask.artifact) {
496
- return { ...base, ok: false, stop: 'artifact-red', reds: [/** @type {Red} */ (ask.red)] };
497
- }
498
-
499
- const v = validateJudgedArtifacts({ card: ask.artifact.card, cases: ask.artifact.cases });
500
- if (!v.ok) return { ...base, ok: false, stop: 'proposal-invalid', reds: v.reds };
501
- return { ...base, ok: true, stop: null, reds: [] };
502
- }