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.
Files changed (93) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +3 -3
  3. package/bareloop.context.md +75 -214
  4. package/package.json +2 -2
  5. package/src/authorflow.js +71 -136
  6. package/src/authoring.js +5 -124
  7. package/src/authorjob.js +125 -417
  8. package/src/authorreadout.js +105 -355
  9. package/src/authorrun.js +70 -234
  10. package/src/authorscout.js +9 -1
  11. package/src/blockasks.js +12 -17
  12. package/src/bundlerun.js +4 -1
  13. package/src/checkblock.js +297 -75
  14. package/src/checklist.js +1 -1
  15. package/src/checkpick.js +9 -5
  16. package/src/cli.js +3 -3
  17. package/src/declaredclose.js +45 -112
  18. package/src/destpoint.js +1 -1
  19. package/src/draftspend.js +20 -4
  20. package/src/fencepointcall.js +76 -0
  21. package/src/guarddescriptions.js +14 -0
  22. package/src/index.js +3 -43
  23. package/src/interviewrun.js +13 -8
  24. package/src/job.js +20 -1
  25. package/src/jobblock.js +11 -46
  26. package/src/judged.js +13 -1229
  27. package/src/kinds.js +10 -348
  28. package/src/noteask.js +124 -0
  29. package/src/pagedry.js +27 -5
  30. package/src/pagemap.js +7 -29
  31. package/src/pagerules.js +18 -3
  32. package/src/panel/authorroutes.js +15 -4
  33. package/src/panel/authorsession.js +201 -167
  34. package/src/panel/importrun.js +0 -1
  35. package/src/panel/index.html +43 -18
  36. package/src/panel/jobplan.js +54 -19
  37. package/src/panel/server.js +90 -69
  38. package/src/panel/status.js +3 -0
  39. package/src/pickrecord.js +15 -54
  40. package/src/planrun.js +4 -48
  41. package/src/promptregisters.js +7 -17
  42. package/src/providerrows.js +0 -36
  43. package/src/providers.js +4 -25
  44. package/src/questionbox.js +34 -30
  45. package/src/reviewdoor.js +1 -1
  46. package/src/rowresults.js +69 -0
  47. package/src/rubricstep.js +136 -28
  48. package/src/run.js +2 -15
  49. package/src/stagewords.js +24 -0
  50. package/src/userrun.js +14 -111
  51. package/types/authorflow.d.ts +51 -137
  52. package/types/authoring.d.ts +1 -14
  53. package/types/authorjob.d.ts +14 -55
  54. package/types/authorreadout.d.ts +52 -80
  55. package/types/authorrun.d.ts +20 -0
  56. package/types/blockasks.d.ts +5 -11
  57. package/types/checkblock.d.ts +147 -28
  58. package/types/checklist.d.ts +2 -2
  59. package/types/checkpick.d.ts +5 -3
  60. package/types/cli.d.ts +1 -3
  61. package/types/declaredclose.d.ts +5 -33
  62. package/types/draftspend.d.ts +16 -2
  63. package/types/fencepointcall.d.ts +68 -0
  64. package/types/guarddescriptions.d.ts +7 -0
  65. package/types/index.d.ts +2 -4
  66. package/types/job.d.ts +8 -0
  67. package/types/jobblock.d.ts +8 -38
  68. package/types/judged.d.ts +7 -357
  69. package/types/kinds.d.ts +4 -104
  70. package/types/noteask.d.ts +76 -0
  71. package/types/pagedry.d.ts +13 -0
  72. package/types/pagemap.d.ts +2 -5
  73. package/types/pagerules.d.ts +7 -0
  74. package/types/panel/authorsession.d.ts +37 -5
  75. package/types/panel/jobplan.d.ts +15 -3
  76. package/types/panel/server.d.ts +46 -13
  77. package/types/panel/status.d.ts +5 -0
  78. package/types/pickrecord.d.ts +8 -13
  79. package/types/planrun.d.ts +1 -22
  80. package/types/providerrows.d.ts +0 -31
  81. package/types/providers.d.ts +3 -19
  82. package/types/questionbox.d.ts +20 -6
  83. package/types/rowresults.d.ts +23 -0
  84. package/types/rubricstep.d.ts +43 -7
  85. package/types/run.d.ts +1 -20
  86. package/types/stagewords.d.ts +11 -0
  87. package/types/userrun.d.ts +0 -1
  88. package/src/calibrate.js +0 -702
  89. package/src/cardauthor.js +0 -502
  90. package/src/fitcheck.js +0 -168
  91. package/types/calibrate.d.ts +0 -201
  92. package/types/cardauthor.d.ts +0 -358
  93. package/types/fitcheck.d.ts +0 -119
@@ -20,8 +20,7 @@
20
20
  // `src/panel/server.js`'s POST routes). Nothing here changes what a step
21
21
  // means or what an answer does — only where the answer comes from.
22
22
 
23
- import { judgePick, judgeRatesFor, judgeRowFor, keyValueOf, modelChoiceFor, ratesOfLine, rowsForHome } from '../providerrows.js';
24
- import { ConfigError } from '../config.js';
23
+ import { judgePick, keyValueOf, modelChoiceFor, ratesOfLine, rowsForHome } from '../providerrows.js';
25
24
  import {
26
25
  mkdirSync, existsSync, writeFileSync, readdirSync,
27
26
  } from 'node:fs';
@@ -42,37 +41,41 @@ import {
42
41
  import { prepareSigning } from '../authorjob.js';
43
42
  import { checkCloseByteSignature } from '../close-integrity.js';
44
43
  import {
45
- questionsFor, requiredAnswersFor, makeLoopGenerate, confirmSystemFor, SOFTGREEN_JUDGE_EXAMPLES_KEY,
44
+ questionsFor, requiredAnswersFor, makeLoopGenerate, confirmSystemFor,
46
45
  } from '../authorflow.js';
47
46
  import {
48
47
  resolveProvider, buildRunnerProviders, apiKeyProblem,
49
48
  } from '../providers.js';
50
- import { resolveJobJudge, defaultJudgeLoop } from '../judged.js';
49
+ import { resolveJobJudge } from '../judged.js';
51
50
  import { assertThinkingMode, thinkingPlanFor, thinkingRowText, thinkingCallOptions } from '../thinking.js';
52
- import { closeJudges } from '../kinds.js';
53
51
  import { RUBRIC_LANG } from '../authoring.js';
54
- import { rubricGoal, cardOfClose, signedFactNames } from '../rubricstep.js';
52
+ import { rubricGoal, cardOfClose, signedFactNames, carriesOneList, stageNameOfKey } from '../rubricstep.js';
55
53
  import { redactSecrets } from '../validate.js';
56
- import { FLOW_TYPES } from '../job.js';
54
+ import { FLOW_TYPES, flowTypeOf, oldJobWords } from '../job.js';
57
55
  import { mcpPickFor, signFlow } from '../mcppick.js';
58
56
  import { parseTicketList, ticketNumberOf, TICKET_NUMBER_WORDS } from '../ticketshape.js';
59
- import { isDropIt, isAgree, stripAgreeLead } from '../pagemap.js';
60
- import { plainWords, SUGGEST_SYSTEM, sameRuleWords } from '../checkpick.js';
57
+ import { newestUnrunTicket } from '../ticketnext.js';
58
+ import { readTicket } from '../ticket.js';
59
+ import { readRunList } from '../runlist.js';
60
+ import { fetchPageText } from '../pagefetch.js';
61
+ import { plainWords, SUGGEST_SYSTEM } from '../checkpick.js';
61
62
  import { LEDGER_SYSTEM } from '../checklist.js';
63
+ import { FENCE_POINT_SYSTEM } from '../fencepointcall.js';
62
64
  import { ROW_EDIT_SYSTEM } from '../rowedit.js';
65
+ import { choiceEntries } from '../checkblock.js';
63
66
  import { readRecordFile, readRowChoices, writeRecordPart, RECORD_FILE, KEPT_WORDS } from '../pickrecord.js';
64
67
  import { MAX_REVISES, draftLabelOf, nextRevisesUsed, sessionsRootOf, writeRevisesUsed } from '../revises.js';
65
- import { FIT_ABSENT_NOTE } from '../fitcheck.js';
66
68
  import { runDestPoint, destQuestionText, yesNoOf } from '../destpoint.js';
69
+ import { runNoteAsk } from '../noteask.js';
67
70
  import { tallyCalls } from '../text.js';
68
- import { appendDraftLog, readDraftLedger } from '../draftspend.js';
69
- import { PLAIN_PROPOSAL_STOPS, proposalStopText, signingStopText, draftStopText, redsRecord, declarationRecord, calibrationSummary, tryRefusedText } from '../authorreadout.js';
71
+ import { appendDraftLog, readDraftLedger, readDraftSteps } from '../draftspend.js';
72
+ import { signingStopText, draftStopText, redsRecord, declarationRecord, tryRefusedText, buildReadout, readoutHeadIndexes } from '../authorreadout.js';
70
73
  import { runNpmCi, NPM_CI_LOCKS } from '../npminstall.js';
71
74
  import {
72
- parseJobBlock, parseInputs, jobBlockFitsCheck, renderJobLines, renderExamples, signedJobLines, jobBoxText,
75
+ parseJobBlock, parseInputs, renderJobLines, signedJobLines, jobBoxText, REPO_RUBRIC_WORDS,
73
76
  } from '../jobblock.js';
74
77
  import { planFromConfirm } from './jobplan.js';
75
- import { boxFor, offersOf, panelQuestionText, refuseChoice, resolveChoice } from '../questionbox.js';
78
+ import { boxFor, offersOf, panelQuestionText, answerEffectWords, refuseChoice, resolveChoice, CHOICE_SAYS } from '../questionbox.js';
76
79
  import { isTicketTrigger } from '../trigger.js';
77
80
  import { ticketLookOf } from '../ticketschedule.js';
78
81
 
@@ -95,7 +98,6 @@ export const STEP_LABELS = Object.freeze({
95
98
  listing: 'listing files',
96
99
  confirm: 'confirming plan',
97
100
  draft: 'drafting',
98
- calibrate: 'calibrating',
99
101
  gates: 'checking signing gates',
100
102
  hash: 'generating hash',
101
103
  signed: 'signed hash',
@@ -131,17 +133,11 @@ export const PHASE_STEP = Object.freeze({
131
133
  'scout-done': 'scout',
132
134
  look: 'look',
133
135
  'look-done': 'look',
134
- // F243: the fit check's one call is counted in the look's line, like the look
135
- 'fit-check': 'look',
136
- 'fit-check-done': 'look',
137
136
  confirm: 'confirm',
138
137
  'confirm-turn-done': 'confirm',
139
138
  listing: 'listing',
140
139
  'listing-done': 'listing',
141
140
  author: 'draft',
142
- rubric: 'calibrate',
143
- 'rubric-done': 'calibrate',
144
- 'rubric-scrubbed': 'calibrate',
145
141
  });
146
142
 
147
143
  export { thinkingRowText };
@@ -176,7 +172,7 @@ const SOURCE_CHECK_CODES = new Set([
176
172
  ]);
177
173
 
178
174
  /** the line under the plan bubble, in plain words (the bubble itself is drawn by the page's one `renderJobPlan`) */
179
- export const PLAN_FOOTER = 'Sign & run to confirm this plan, or Revise to edit the boxes and draft again.';
175
+ export const PLAN_FOOTER = 'Draft the plan to see its checks, or Revise to edit the boxes.';
180
176
 
181
177
  /**
182
178
  * The confirm turn's plan as a chat message (P7): a STRUCTURED `{role:'bot', kind:'plan', plan}` the page draws with the
@@ -238,6 +234,31 @@ export function nextFreeJobName(origin, runJobs, opts = {}) {
238
234
  /** the form's fields, in card order — what `card.json` stores, verbatim (P5 item 3) */
239
235
  export const CARD_FIELDS = Object.freeze(['jobName', 'checkType', 'provider', 'model', 'thinking', 'jobText', 'inputs', 'destination', 'capUsd', 'maxWallMs', 'flowType', 'mcp', 'ticket', 'schedule']);
240
236
 
237
+ /**
238
+ * The card's Inputs as the JOB reads them: the one place that decides which lines are inputs (hamr 2026-11-14, piece 5): the fresh card, the session, the
239
+ * Destination check and Reuse (`buildReuseSpec`) all read THIS, never a copy.
240
+ * @param {any} card
241
+ * @param {{rubric?: boolean, flowType?: 'plain'|'mcp'|'tickets'}} [o]
242
+ * @returns {{ok: true, inputs: import('../jobblock.js').JobInput[]}|{ok: false, error: string}}
243
+ */
244
+ export function cardInputs(card, o = {}) {
245
+ const ip = parseInputs(card?.inputs);
246
+ if (!ip.ok) return ip;
247
+ return { ok: true, inputs: ticketRubricInputs(ip.inputs, { rubric: o.rubric ?? card?.checkType === 'rubric', flowType: o.flowType ?? flowOfCard(card).flowType }) };
248
+ }
249
+
250
+ /**
251
+ * The renumbering itself, for a caller that holds parsed lines already (`startSession`): a Tickets + rubric job reads the ticket and nothing else (a repo line is
252
+ * not an input of it), so the ticket line stands alone, numbered 1 (a signed spec's inputs must run 1, 2, 3...). Any other job keeps its lines as typed.
253
+ * @param {import('../jobblock.js').JobInput[]} inputs @param {{rubric: boolean, flowType: 'plain'|'mcp'|'tickets'}} o
254
+ * @returns {import('../jobblock.js').JobInput[]}
255
+ */
256
+ export function ticketRubricInputs(inputs, { rubric, flowType }) {
257
+ if (!rubric || flowType !== 'tickets') return inputs;
258
+ const line = inputs.find((i) => parseTicketList(i.value).ok);
259
+ return line ? [{ ...line, n: 1 }] : inputs;
260
+ }
261
+
241
262
  /**
242
263
  * The repo a card names: Inputs line 1 (P7 — the Source box is gone; the first input IS the repo). `''` when the Inputs
243
264
  * box does not parse (the card validator refuses that before anything uses this).
@@ -245,7 +266,7 @@ export const CARD_FIELDS = Object.freeze(['jobName', 'checkType', 'provider', 'm
245
266
  * @returns {string}
246
267
  */
247
268
  export function cardSource(card) {
248
- const p = parseInputs(card?.inputs);
269
+ const p = cardInputs(card);
249
270
  return p.ok ? p.inputs[0].value : '';
250
271
  }
251
272
 
@@ -264,7 +285,7 @@ export function cardFields(card) {
264
285
  /**
265
286
  * REUSE WORKFLOW, ONE DOOR (RULED 2026-10-15, v1.101; replaces v1.88's five open boxes). Every box on the card is open. What decides
266
287
  * the path is the CARD compared with the origin run's card, never the drafted spec: the JOB boxes are the job text (numbered lines,
267
- * `~` rules, `~ PASS`/`~ FAIL`), the check type and the thinking tick. The RUN boxes (Inputs, Destination, Model, $ cap, Time cap)
288
+ * `~` rules), the check type and the thinking tick. The RUN boxes (Inputs, Destination, Model, $ cap, Time cap)
268
289
  * never decide it. A green origin with no job box changed reuses the signed plan verbatim (no drafting); anything else drafts.
269
290
  */
270
291
  export const JOB_BOXES = Object.freeze(['jobText', 'checkType', 'thinking', 'flowType', 'mcp']);
@@ -350,7 +371,7 @@ export function buildReuseSpec(originSpec, card, rows) {
350
371
  // an ABSOLUTE Destination is a per-run output folder (a plain-files job): it is never part of the signed spec, and the spec's own
351
372
  // fence (inside the run's tree) stays as signed. A repo job's Destination is the fence and is relative (an absolute one is refused).
352
373
  if (!isAbsoluteDestination(String(card.destination ?? '').trim())) spec.writeScope = String(card.destination ?? '').split(/[,\n]/).map((x) => x.trim()).filter(Boolean);
353
- const ip = parseInputs(card.inputs);
374
+ const ip = cardInputs(card, { rubric: spec.verdictType === 'soft-green', flowType: flowTypeOf(spec) });
354
375
  if (ip.ok) spec.inputs = ip.inputs; else delete spec.inputs;
355
376
  spec.budgetUsd = card.capUsd;
356
377
  if (typeof card.maxWallMs === 'number' && Number.isFinite(card.maxWallMs) && card.maxWallMs > 0) spec.maxWallMs = card.maxWallMs;
@@ -406,7 +427,7 @@ export const DESTINATION_HINT = 'Type the folder that holds the files the job sh
406
427
  * @returns {string|null} the plain refusal, or null when the Destination is fine
407
428
  */
408
429
  export function startDestinationProblem(card) {
409
- const ip = parseInputs(card?.inputs);
430
+ const ip = cardInputs(card);
410
431
  const source = ip.ok ? (ip.inputs[0]?.value ?? '') : '';
411
432
  const destination = typeof card?.destination === 'string' ? card.destination : '';
412
433
  const isRepoLike = looksLikeRepoSource(source);
@@ -455,13 +476,10 @@ export function validateJobCard(card, opts = {}) {
455
476
  if (card.thinking !== undefined && typeof card.thinking !== 'boolean') return { ok: false, error: 'Thinking on must be on or off' };
456
477
  const jb = parseJobBlock(card.jobText);
457
478
  if (!jb.ok) return { ok: false, error: jb.error };
458
- const ib = parseInputs(card.inputs);
479
+ const ib = cardInputs(card);
459
480
  if (!ib.ok) return { ok: false, error: ib.error };
460
- // P1=B: PASS/FAIL examples are required of a rubric job only when it holds a judged part. A rubric on the person's own
461
- // local files (first input not a repo) holds none in this build; a rubric on a repo composes the judged floor.
462
- const rubricFiles = checkType === 'rubric' && looksLikeRubricInput(ib.inputs[0].value);
463
- const misfit = jobBlockFitsCheck(jb.lines, checkType === 'rubric', { judged: !rubricFiles });
464
- if (misfit) return { ok: false, error: misfit };
481
+ // hamr 2026-11-14: a repo job is Deterministic. Rubric on a repo is for a Tickets job only (its input is the ticket, below).
482
+ if (checkType === 'rubric' && flowOfCard(card).flowType !== 'tickets' && looksLikeRepoSource(ib.inputs[0].value)) return { ok: false, error: REPO_RUBRIC_WORDS };
465
483
  if (typeof destination !== 'string' || destination.trim() === '') return { ok: false, error: 'Destination is required' };
466
484
  if (typeof capUsd !== 'number' || !Number.isFinite(capUsd) || capUsd <= 0) {
467
485
  return { ok: false, error: '$ cap is required and must be a positive number' };
@@ -476,8 +494,8 @@ export function validateJobCard(card, opts = {}) {
476
494
  * `signPrepare()` are the only ways in.
477
495
  * @param {any} card the validated job card (see {@link validateJobCard})
478
496
  * @param {{env?: Record<string,string|undefined>, sessionsRoot?: string, home?: string, timeoutMs?: number,
479
- * scout?: any, generate?: Function, pickGenerate?: Function|null, ledgerGenerate?: Function|null, editGenerate?: Function|null, carryFrom?: string, carryKind?: string, confirmGenerate?: Function, authorFn?: Function,
480
- * prepareSigningFn?: Function, npmCiFn?: Function, lookFn?: Function|null, fitFn?: Function|null, destFn?: Function|null, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, draftThinking?: "on"|"off", reuse?: {spec: any, workflowKey: string}, schedule?: import('../trigger.js').Trigger|null, flow?: {flowType: 'plain'|'mcp'|'tickets', pick: {server: string, tools: string[]}|null}}} [deps] `scout`..`prepareSigningFn` are
497
+ * scout?: any, generate?: Function, pickGenerate?: Function|null, ledgerGenerate?: Function|null, fenceGenerate?: Function|null, noteFn?: Function|null, editGenerate?: Function|null, carryFrom?: string, carryKind?: string, confirmGenerate?: Function, authorFn?: Function,
498
+ * prepareSigningFn?: Function, npmCiFn?: Function, lookFn?: Function|null, destFn?: Function|null, newestUnrunTicket?: typeof newestUnrunTicket, readTicketFn?: typeof readTicket, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, draftThinking?: "on"|"off", reuse?: {spec: any, workflowKey: string}, schedule?: import('../trigger.js').Trigger|null, flow?: {flowType: 'plain'|'mcp'|'tickets', pick: {server: string, tools: string[]}|null}}} [deps] `scout`..`prepareSigningFn` are
481
499
  * TEST SEAMS ONLY — see the note just above where each is read, below. `reuse` (Reuse workflow) is NOT a seam: the
482
500
  * caller (`/api/author/start`) sets it only when the server's own same-job rule held.
483
501
  * @returns {any} the session object
@@ -491,7 +509,7 @@ export function createSession(card, deps = {}) {
491
509
  // block before a session exists; a reuse card's job text is the origin's and is not drafted from.
492
510
  const jobParsed = parseJobBlock(card.jobText);
493
511
  const jobLines = jobParsed.ok ? jobParsed.lines : [];
494
- const inputsParsed = parseInputs(card.inputs);
512
+ const inputsParsed = cardInputs(card, { flowType: deps.flow?.flowType ?? 'plain' });
495
513
  const INPUTS = inputsParsed.ok ? inputsParsed.inputs : [];
496
514
  /** the repo — Inputs line 1 */
497
515
  const SOURCE = INPUTS[0]?.value ?? '';
@@ -582,7 +600,7 @@ export function createSession(card, deps = {}) {
582
600
  };
583
601
 
584
602
  /** a rubric job on local files words its copy/read steps for files (set once the card is known) */
585
- let fileJob = card.checkType === 'rubric' && looksLikeRubricInput(parseInputs(card.inputs).ok ? (/** @type {any} */ (parseInputs(card.inputs))).inputs[0].value : '');
603
+ let fileJob = card.checkType === 'rubric' && looksLikeRubricInput(INPUTS[0]?.value ?? '');
586
604
  /** @param {string} id @param {string} [detail] (absent = keep what the step has) start (or restart) a step; whatever step was running is finished */
587
605
  const stepStart = (id, detail) => {
588
606
  const labels = fileJob ? { ...STEP_LABELS, ...FILE_JOB_STEP_LABELS } : STEP_LABELS;
@@ -650,7 +668,9 @@ export function createSession(card, deps = {}) {
650
668
  const running = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
651
669
  appendDraftLog(outDir, {
652
670
  kind: 'human', no: running === -1 ? Math.max(0, state.steps.length - 1) : running, source: typeof step.source === 'string' ? step.source : 'confirm',
653
- question: redactSecrets(step.question), answer: said, ...(answeredChoice === null ? {} : { choice: answeredChoice }), ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
671
+ question: redactSecrets(step.question), answer: said, ...(answeredChoice === null ? {} : { choice: answeredChoice }),
672
+ // what was decided, for the readout (it never prints a question that quotes the rule's old words): the agreed reading, or the person's own correction
673
+ ...(answeredChoice === 'agree' && typeof step.agreeWords === 'string' ? { words: redactSecrets(step.agreeWords) } : answeredChoice === 'rule' ? { words: said } : {}), ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
654
674
  });
655
675
  }
656
676
  resolveFn0(value);
@@ -664,8 +684,8 @@ export function createSession(card, deps = {}) {
664
684
  if (step.kind === 'language') say('bot', `${step.field?.prompt ?? 'Which language is this job about?'} (${(step.candidates ?? []).join(', ')})`);
665
685
  else if (step.kind === 'menu') {
666
686
  sayPlan(step.plan ?? {});
667
- } else if (step.kind === 'answer' && (step.source === 'fit-check' || step.source === 'dest-point')) sayOpen(panelQuestionText(/** @type {any} */ (step)));
668
- else if (step.kind === 'answer') sayOpen(`A question the plan raised (${step.index} of ${step.total})${Number.isInteger(step.line) ? `, about job line ${step.line}` : ''}: ${panelQuestionText(/** @type {any} */ (step))}`);
687
+ } else if (step.kind === 'answer' && (step.source === 'dest-point')) sayOpen(panelQuestionText(/** @type {any} */ (step)));
688
+ else if (step.kind === 'answer') sayOpen(`A question the plan raised (${step.index} of ${step.total})${Number.isInteger(step.line) ? `, about job line ${step.line}` : ''}: ${panelQuestionText(/** @type {any} */ (step))}${answerEffectWords(/** @type {any} */ (step)) === null ? '' : ` ${answerEffectWords(/** @type {any} */ (step))}`}`);
669
689
  else if (step.kind === 'goal') say('bot', 'Type the goal sentence yourself.');
670
690
  });
671
691
 
@@ -683,19 +703,6 @@ export function createSession(card, deps = {}) {
683
703
  };
684
704
 
685
705
  let lastTryRefused = false;
686
- // F243: the fit check's result is one drafting-log row (the asks, what was found, what the quote proved); an `absent` check says so in chat
687
- // (a seam of its own - onPhase never posts a chat message)
688
- const onFit = (/** @type {any} */ data) => {
689
- const running = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
690
- appendDraftLog(outDir, {
691
- kind: 'fit-check', no: running === -1 ? Math.max(0, state.steps.length - 1) : running, state: String(data.state ?? 'absent'),
692
- asks: (Array.isArray(data.asks) ? data.asks : []).map((/** @type {any} */ a) => ({
693
- line: a.line, ask: redactSecrets(String(a.ask)), found: a.found === true, quote: typeof a.quote === 'string' ? redactSecrets(a.quote) : null, madeUp: a.madeUp === true, ...(a.ignored === 'number' ? { ignored: 'number' } : {}),
694
- })),
695
- notFound: (Array.isArray(data.notFound) ? data.notFound : []).map((/** @type {any} */ x) => ({ line: x.line, ask: redactSecrets(String(x.ask)) })), at: new Date().toISOString(),
696
- });
697
- if (data.state === 'absent') say('bot', FIT_ABSENT_NOTE);
698
- };
699
706
  const onPhase = (name, data = {}) => {
700
707
  // COLLAPSED INTO THE PROGRESS INDICATOR ONLY (build item 3) — this used
701
708
  // to also `say('system', `… ${name}`)`, one jargon chat bubble per
@@ -710,7 +717,9 @@ export function createSession(card, deps = {}) {
710
717
  // progress line shows it briefly, in code's words
711
718
  // PRD v1.131 tick 7: the retention counts of a rubric draft, one line when it ends (counts only, no words)
712
719
  // the one check list of a rubric job: each row once when it is built and once at the end, and each try's refusals (kind `ledger` / `ledger-try`)
720
+ if (name === 'note-answered') appendDraftLog(outDir, { kind: 'note-ask', no: Math.max(0, state.steps.length - 1), state: data.state, answers: data.answers, ...(data.reason ? { reason: redactSecrets(String(data.reason)) } : {}), at: new Date().toISOString() });
713
721
  if (name === 'ledger-built' && Array.isArray(data.rows)) for (const r of data.rows) appendDraftLog(outDir, { phase: 'built', ...r, kind: 'ledger', no: Math.max(0, state.steps.length - 1), at: new Date().toISOString() });
722
+ if (name === 'fence-point-done') appendDraftLog(outDir, { kind: 'fence-point', no: Math.max(0, state.steps.length - 1), edits: redactSecrets(JSON.stringify(data.edits ?? [])), results: redactSecrets(JSON.stringify(data.results ?? [])), reason: data.reason == null ? null : redactSecrets(String(data.reason)), at: new Date().toISOString() });
714
723
  if (name === 'draft-ledger-try') appendDraftLog(outDir, { kind: 'ledger-try', no: Math.max(0, state.steps.length - 1), label: data.label, kept: data.kept, refused: data.refused, at: new Date().toISOString() });
715
724
  if (name === 'draft-ledger' && Array.isArray(data.rows)) for (const r of data.rows) appendDraftLog(outDir, { phase: 'final', ...r, kind: 'ledger', no: Math.max(0, state.steps.length - 1), at: new Date().toISOString() });
716
725
  if (name === 'draft-retention' && Array.isArray(data.lines)) appendDraftLog(outDir, { kind: 'retention', no: Math.max(0, state.steps.length - 1), lines: data.lines, at: new Date().toISOString() });
@@ -851,6 +860,9 @@ export function createSession(card, deps = {}) {
851
860
  const keyProblem = apiKeyProblem(apiKey);
852
861
  if (keyProblem) { refuse(`${draftKeyName} ${keyProblem}. Stopped — nothing spent.`); return; }
853
862
 
863
+ // hamr 2026-11-14 (piece 6): a job made with PASS/FAIL examples or the old judge is not reused; old runs are not repaired. Before any copy or read.
864
+ const oldJob = deps.reuse ? oldJobWords(deps.reuse.spec) : null;
865
+ if (oldJob !== null) { refuse(`${oldJob} Nothing spent.`); return; }
854
866
  const verdictType = card.checkType === 'rubric' ? 'soft-green' : 'green';
855
867
  const into = join(outDir, 'source-seed');
856
868
  const isRepoLike = looksLikeRepoSource(SOURCE);
@@ -883,7 +895,20 @@ export function createSession(card, deps = {}) {
883
895
  /** @type {any} */
884
896
  let prep;
885
897
  if (RUBRIC_FILES) {
886
- const proved = await proveRubricInputs({ inputs: INPUTS, into, destination: card.destination, ...(deps.fetchUrl ? { fetchUrl: deps.fetchUrl } : {}) });
898
+ // hamr 2026-11-14 (piece 5): a Tickets + rubric job's one input is the ticket. The drafting-time read takes the newest ticket this job has not run
899
+ // (the product's own lookup, `newestUnrunTicket`) and reads it (`readTicket`): there is no ticket-number box. Run start re-reads the same list row.
900
+ const ticketFlow = deps.flow?.flowType === 'tickets' && deps.flow.pick ? deps.flow.pick : null;
901
+ /** @param {string} url @returns {Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>} */
902
+ const readNewestTicket = async (url) => {
903
+ const rows = (() => { try { return readRunList({ home: configHome }).rows; } catch { return []; } })();
904
+ const picked = await (deps.newestUnrunTicket ?? newestUnrunTicket)({ job: card.jobName, rows, inputs: INPUTS, mcp: /** @type {{server: string, tools: string[]}} */ (ticketFlow) });
905
+ if (!picked.ok) return { ok: false, error: picked.say.replace(/\s*Nothing spent\.$/, '') };
906
+ const t = await (deps.readTicketFn ?? readTicket)({ mcp: /** @type {{server: string, tools: string[]}} */ (ticketFlow), listUrl: url, number: picked.number });
907
+ return t.ok ? { ok: true, text: t.ticket.text, url } : { ok: false, error: t.error };
908
+ };
909
+ const pageFetch = deps.fetchUrl ?? fetchPageText;
910
+ const draftFetch = ticketFlow ? (/** @type {string} */ url) => (parseTicketList(url).ok ? readNewestTicket(url) : pageFetch(url)) : deps.fetchUrl;
911
+ const proved = await proveRubricInputs({ inputs: INPUTS, into, destination: card.destination, ...(draftFetch ? { fetchUrl: draftFetch } : {}) });
887
912
  prep = proved.ok ? proved.prep : { stop: proved.error, code: proved.code };
888
913
  // what each header-only page read came back with (already secret-masked at capture), so the next live failure shows it
889
914
  if (!proved.ok && proved.attempts?.length) appendDraftLog(outDir, { kind: 'page-fetch-attempts', no: Math.max(0, state.steps.length - 1), attempts: proved.attempts, at: new Date().toISOString() });
@@ -1024,53 +1049,13 @@ export function createSession(card, deps = {}) {
1024
1049
  return;
1025
1050
  }
1026
1051
  state.phase = 'signing-gates';
1027
- stepStart('gates', 'gates 1–3 cost $0; gate 4 only for a rubric');
1028
- const judges = closeJudges(spec.closeDecl);
1029
- const judge = judges ? resolveJobJudge(spec, modelChoice.provider, resolveWorkerModel) : null;
1030
- let judgeProvider = null;
1031
- /** @type {import('../providerrows.js').PriceResult} */
1032
- let judgePrice = null;
1033
- if (judge) {
1034
- const judgeRow = judgeRowFor(keyCfg, judge, modelChoice.provider, keyCfg.find((r) => r.envName === modelChoice.envName) ?? null);
1035
- try {
1036
- judgePrice = judgeRatesFor(judge, modelChoice.provider, modelChoice.baseUrl, draftPrice, keyCfg);
1037
- } catch (e) {
1038
- if (!(e instanceof ConfigError)) throw e;
1039
- refuse(`${e.message} — refusing before gate 4 spends anything`);
1040
- return;
1041
- }
1042
- const judgeKeyValue = env.JUDGE_API_KEY ?? (judge.provider === modelChoice.provider ? apiKey : keyValueOf(env, judgeRow?.envName));
1043
- const judgeKeyProblem = judgeKeyValue ? apiKeyProblem(judgeKeyValue) : null;
1044
- if (!judgeKeyValue || judgeKeyProblem) {
1045
- refuse(`the judge key is not usable (${judgeKeyProblem ?? 'not set'}) — refusing before gate 4 spends anything`);
1046
- return;
1047
- }
1048
- judgeProvider = buildRunnerProviders({
1049
- providerName: modelChoice.provider, apiKey, model: MODEL, baseUrl: modelChoice.baseUrl, legacyMaxTokens: modelChoice.legacyMaxTokens,
1050
- judgeApiKey: judgeKeyValue, judgeModel: judge.model, judgeProviderName: judge.provider,
1051
- judgeBaseUrl: judge.provider === modelChoice.provider ? modelChoice.baseUrl : (judgeRow?.baseUrl.trim() || undefined),
1052
- judgeLegacyMaxTokens: judge.provider === modelChoice.provider ? modelChoice.legacyMaxTokens : (judgeRow?.legacyMaxTokens ?? false),
1053
- }).judgeProvider;
1054
- }
1052
+ stepStart('gates', 'gates 1–3 cost $0');
1055
1053
  const signing = await prepareSigningFn({
1056
1054
  spec, workdir: prep.tree, seedRef: seedRef, timeoutMs,
1057
- shellCapUsd: spec.budgetUsd, ceilingUsd: card.capUsd, priorCalls: [...metered],
1058
- judgeLoop: judgeProvider ? (o) => defaultJudgeLoop({ provider: judgeProvider, system: o.system, rates: judgePrice?.rates ?? null, thinking: spec.thinking === true }) : null,
1059
- judgeModel: judge?.model ?? null,
1060
- onJudgeCost: (c) => onCall({ label: `${c.label}:${c.id}`, costUsd: c.costUsd, unpricedRounds: c.unpricedRounds }),
1055
+ shellCapUsd: spec.budgetUsd,
1061
1056
  });
1062
1057
  const signingFile = join(outDir, 'signing.json');
1063
1058
  writeFileSync(signingFile, `${JSON.stringify(signing, null, 2)}\n`);
1064
- // The `calibrating` line is the rubric phase the person watched; its ✓ was set long before the gate graded
1065
- // anything. Once the gate has a result, the line says THAT, on its own line (hamr, 2026-10-09).
1066
- const calSum = calibrationSummary(signing.gates?.calibration);
1067
- const calStep = latestStep(state.steps, 'calibrate');
1068
- if (calSum && calStep) {
1069
- calStep.status = calSum.ok ? 'done' : 'failed';
1070
- calStep.detail = calSum.note;
1071
- logSteps();
1072
- }
1073
-
1074
1059
  if (!signing.ok) {
1075
1060
  // plain words for the person (src/authorreadout.js, the one owner the CLI prints too); the full reds go into
1076
1061
  // the drafting log on the failed step, so the cause survives the session
@@ -1146,19 +1131,13 @@ export function createSession(card, deps = {}) {
1146
1131
 
1147
1132
  /** @type {Record<string, string>} */
1148
1133
  const answers = { 1: renderJobLines(jobLines) };
1149
- if (verdictType === 'soft-green') answers[SOFTGREEN_JUDGE_EXAMPLES_KEY] = renderExamples(jobLines);
1150
- // a rubric job on files holds no judged part in this build, so the PASS/FAIL examples are not required of it
1151
1134
  const required = RUBRIC_FILES ? [1] : requiredAnswersFor(verdictType);
1152
1135
  for (const n of required) {
1153
1136
  if (!answers[n]) { refuse(`the ${verdictType} check type needs ${required.length} answers and one is missing (key ${n})`); return; }
1154
1137
  }
1155
1138
 
1156
- const draftJudge = (() => {
1157
- try { return resolveJobJudge(draft, modelChoice.provider, resolveWorkerModel); } catch { return { provider: modelChoice.provider, model: modelChoice.name }; }
1158
- })();
1159
1139
  const { provider } = buildRunnerProviders({
1160
1140
  providerName: modelChoice.provider, apiKey, model: MODEL, baseUrl: modelChoice.baseUrl, legacyMaxTokens: modelChoice.legacyMaxTokens,
1161
- judgeApiKey: apiKey, judgeModel: MODEL, judgeProviderName: modelChoice.provider, judgeBaseUrl: modelChoice.baseUrl,
1162
1141
  });
1163
1142
  // TEST SEAMS (see the constructor's own note): a test overrides
1164
1143
  // `generate`/`confirmGenerate` directly (bypassing this real, constructed
@@ -1172,6 +1151,8 @@ export function createSession(card, deps = {}) {
1172
1151
  // R10 (fwd am16): the check-suggestion call's own model boundary (SUGGEST_SYSTEM, the drafter's thinking); a test that replaces the model boundary never reaches it unless it brings `deps.pickGenerate`
1173
1152
  const pickGenerate = deps.pickGenerate !== undefined ? deps.pickGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: SUGGEST_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
1174
1153
  // the one check list's call has its own model boundary (LEDGER_SYSTEM, the drafter's thinking); like the others, a test that replaces the model boundary never reaches it unless it brings `deps.ledgerGenerate`
1154
+ // the repo job's pointing call: its own model boundary (FENCE_POINT_SYSTEM), the drafter's thinking (off); a test that replaces the model boundary never reaches it unless it brings `deps.fenceGenerate`
1155
+ const fenceGenerate = deps.fenceGenerate !== undefined ? deps.fenceGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: FENCE_POINT_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
1175
1156
  const ledgerGenerate = deps.ledgerGenerate !== undefined ? deps.ledgerGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: LEDGER_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
1176
1157
  // the row-edit turn (the drafter's reply of a rubric job, src/rowedit.js) has its own model boundary; a test that replaces `generate` need not bring one
1177
1158
  const editGenerate = deps.editGenerate !== undefined ? deps.editGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: ROW_EDIT_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
@@ -1218,6 +1199,19 @@ export function createSession(card, deps = {}) {
1218
1199
  // ask path as every other (the chat box + Send); the answer is REQUIRED (a blank one asks again, there is no skip) and is
1219
1200
  // added WORD FOR WORD as a `~` rule on the job line it names — never rewritten. The lines are mutated in place, so the
1220
1201
  // signed `jobLines`, the answers text and the plan card all read the same words.
1202
+ /** the job text as the draft shows and signs it: the signed lines, the card's box, the answers text and one message (the check list's rebuilt lines, or the lines a try-3 answer added) */
1203
+ const syncJobLines = (/** @type {any[]} */ lines, /** @type {string|null} */ say = null, /** @type {any} */ confirmed = null) => {
1204
+ // ONE owner: the session's own lines take the rebuilt ones in place, so the plan cards (`planMessage(..., jobLines)`) and the signed rows read the same words
1205
+ if (lines !== jobLines) jobLines.splice(0, jobLines.length, ...lines);
1206
+ draft.jobLines = signedJobLines(lines);
1207
+ // the card's job box holds the rules as they now are (an answer replaced the rule it was asked about), so a Revise reopens the boxes with them; `card` is what card.json stores
1208
+ state.card = { ...state.card, jobText: jobBoxText(lines) };
1209
+ card = { ...card, jobText: state.card.jobText };
1210
+ answers[1] = renderJobLines(lines);
1211
+ if (say !== null) state.messages.push({ ...planMessage({ ...(confirmed ?? {}), ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, lines), text: say });
1212
+ };
1213
+ /** the answers message of a check-list ask, drawn once the list has rebuilt the lines @type {{say: string, confirmed: any}|null} */
1214
+ let pendingSay = null;
1221
1215
  const answerQuestions = async (/** @type {{questions: {line: number, question: string, rule?: number, source?: string, ask?: string, reading?: string, ruleText?: string, check?: Record<string, any>}[], dropped: {reason: string, raw: any}[], confirmed: any}} */ o) => {
1222
1216
  if (o.dropped.length) appendDraftLog(outDir, { kind: 'questions-dropped', no: Math.max(0, state.steps.length - 1), dropped: o.dropped, at: new Date().toISOString() });
1223
1217
  const total = o.questions.length;
@@ -1225,15 +1219,18 @@ export function createSession(card, deps = {}) {
1225
1219
  const left = [];
1226
1220
  /** R10: the picks the person made (fwd am16): the check agreed to, or their own words with no check @type {{line: number, rule: number, check: Record<string, any>|null, added?: string, own?: boolean}[]} */
1227
1221
  const picks = [];
1228
- /** the choices the check block applies (src/blockasks.js) @type {{key: string, choice: string, text: string}[]} */
1222
+ /** the choices the check block applies (src/blockasks.js) @type {{key: string, choice: string, text?: string}[]} */
1229
1223
  const choices = [];
1230
1224
  for (let k = 0; k < total; k += 1) {
1231
1225
  const q = o.questions[k];
1232
1226
  let text = '';
1233
- /** the button the person used for this question (src/questionbox.js), or null when they typed words (the CLI, an old page): a typed choice decides, never the words */
1227
+ /** the button the person used for this question (src/questionbox.js); null only for the drafter's own typed question: a typed choice decides, never the words */
1234
1228
  let via = null;
1235
1229
  for (;;) {
1236
- const a = await ask({ kind: 'answer', source: typeof q.source === 'string' ? q.source : 'try-3', index: k + 1, total, question: q.question, line: q.line, ...(q.source === 'look' ? { ask: q.ask, rule: q.rule, offers: offersOf(q) } : {}) });
1230
+ // a try-3 question (the drafter's own) says what its answer does: it REPLACES the rule it names, or ADDS a new one (Addendum 2026-11-14 (c) piece 5); a look question has its own words
1231
+ const asked = q.source === 'look' ? null : jobLines.find((l) => l.n === q.line);
1232
+ const replaces = asked && Number.isInteger(q.rule) ? asked.rules[/** @type {number} */ (q.rule) - 1] : undefined;
1233
+ const a = await ask({ kind: 'answer', source: typeof q.source === 'string' ? q.source : 'try-3', index: k + 1, total, question: q.question, line: q.line, ...(q.source === 'look' ? { ask: q.ask, rule: q.rule, offers: offersOf(q), agreeWords: q.ask === 'check' && q.check ? plainWords(/** @type {any} */ (q.check)) : typeof q.reading === 'string' ? q.reading : undefined } : {}), ...(typeof replaces === 'string' ? { replaces } : {}), ...(q.source !== 'look' && /** @type {any} */ (q).new === true ? { adds: true } : {}) });
1237
1234
  if (a === null) return null;
1238
1235
  via = takeChoice();
1239
1236
  // one `~` line is one line: the person's own words, newlines folded to spaces, nothing else touched
@@ -1241,57 +1238,46 @@ export function createSession(card, deps = {}) {
1241
1238
  if (text) break;
1242
1239
  say('bot', 'An answer is needed here — there is no skip. Type it in the box below and press Send.');
1243
1240
  }
1244
- // PRD v1.107 Part 5b: a code-forced look question about a `~` rule. A can't-check ask answered "drop it" adds NO rule; the caller puts that
1245
- // rule on the look's Not checked list. A reading ask answered "agree" adds the code's reading, in plain words, as the `~` rule (so the
1246
- // bound is now the person's own words); anything else typed is the person's own rule, word for word.
1247
- // F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
1248
- // a choice from the question box decides what the answer does; the box's own words (`rule`) are kept whole, even when they read "agree" or "drop it"
1249
- if (q.source === 'look' && via === null) text = stripAgreeLead(text);
1250
- const agrees = via === 'agree' || (via === null && isAgree(text));
1251
- const dropsIt = via === 'drop' || (via === null && isDropIt(text));
1241
+ // a code-forced look question about a `~` rule is answered by a BUTTON (hamr 2026-11-15; `send` refuses words with no choice): `agree` writes the code's reading (a reading ask) or the proposed check (a check ask)
1242
+ // as the rule, `drop` leaves the rule Not checked. Only a READING question also takes the person's own correction (`rule`, the box's words), which REPLACES the asked rule. The choice decides, never the words.
1243
+ const agrees = via === 'agree';
1244
+ const dropsIt = via === 'drop';
1245
+ const corrects = via === 'rule' && q.source === 'look' && q.ask === 'reading';
1252
1246
  if (q.source === 'look' && q.ask === 'reading' && typeof q.reading === 'string' && agrees) text = q.reading;
1253
- // the person's CHOICE, for the check block (the choice decides, never the words): agree only where agree is offered, drop only where drop is
1254
- const canAgree = q.source === 'look' && ((q.ask === 'reading' && typeof q.reading === 'string') || (q.ask === 'check' && q.check !== undefined && q.check !== null));
1255
- const canDrop = q.source === 'look' && (q.ask === 'cant-check' || q.ask === 'no-check' || q.ask === 'check') && Number.isInteger(q.rule);
1256
- if (typeof (/** @type {any} */ (q)).key === 'string') choices.push({ key: /** @type {any} */ (q).key, choice: canDrop && dropsIt ? 'drop' : canAgree && agrees ? 'agree' : 'rule', text });
1257
- if (q.source === 'look' && q.ask === 'cant-check' && Number.isInteger(q.rule) && dropsIt) { left.push({ line: q.line, rule: /** @type {number} */ (q.rule) }); continue; }
1258
- // R10 (fwd am16): a check-pick ask. `agree` writes the proposal's plain words as a new `~` rule and picks the check; "drop it" leaves the rule Not checked; anything else
1259
- // is the person's own words, a `~` rule word for word with no check (Not checked: they judge it at Accept)
1260
- let agreedPick = false;
1261
- const isPick = q.source === 'look' && (q.ask === 'check' || q.ask === 'no-check') && Number.isInteger(q.rule);
1262
- // am21: the ask is about the person's EDITED added `~` line (`pairRule` = the rule it was agreed from): the answer REPLACES that line and the pick is kept under the source's number
1263
- const pair = isPick && Number.isInteger(/** @type {any} */ (q).pairRule) ? /** @type {number} */ (/** @type {any} */ (q).pairRule) : null;
1264
- if (isPick && dropsIt) { left.push({ line: q.line, rule: /** @type {number} */ (q.rule) }); if (pair !== null) left.push({ line: q.line, rule: pair }); appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: q.line, rule: q.rule, ruleText: redactSecrets(String(q.ruleText ?? '')), proposed: q.reading ?? null, how: 'drop it', at: new Date().toISOString() }); continue; }
1247
+ if (q.source === 'look' && typeof (/** @type {any} */ (q)).key === 'string' && (agrees || dropsIt || corrects)) choices.push({ key: /** @type {any} */ (q).key, choice: dropsIt ? 'drop' : corrects ? 'rule' : 'agree', ...(corrects ? { text } : {}) });
1248
+ // R10 (fwd am16): a check-pick ask. `agree` REPLACES the asked rule with the proposal's plain words and picks the check; "drop it" leaves the rule Not checked
1249
+ const isPick = q.source === 'look' && q.ask === 'check' && Number.isInteger(q.rule);
1250
+ if (isPick && dropsIt) { left.push({ line: q.line, rule: /** @type {number} */ (q.rule) }); appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: q.line, rule: q.rule, ruleText: redactSecrets(String(q.ruleText ?? '')), proposed: q.reading ?? null, how: 'drop it', at: new Date().toISOString() }); continue; }
1265
1251
  if (isPick) {
1266
1252
  const agreed = q.ask === 'check' && q.check && agrees;
1267
1253
  if (agreed) text = plainWords(/** @type {any} */ (q.check));
1268
- agreedPick = agreed === true;
1269
1254
  if (agreed) pickedSoFar.push({ line: q.line, text: plainWords(/** @type {any} */ (q.check)) });
1270
- picks.push({ line: q.line, rule: pair ?? /** @type {number} */ (q.rule), check: agreed ? /** @type {any} */ (q.check) : null, added: text, ...(agreed ? {} : { own: true }) });
1255
+ picks.push({ line: q.line, rule: /** @type {number} */ (q.rule), check: agreed ? /** @type {any} */ (q.check) : null, ...(agreed ? {} : { own: true }) });
1271
1256
  appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: q.line, rule: q.rule, ruleText: redactSecrets(String(q.ruleText ?? '')), proposed: q.reading ?? null, how: agreed ? 'agree' : 'own words', ...(agreed ? { picked: q.check } : {}), added: redactSecrets(text), at: new Date().toISOString() });
1272
1257
  }
1258
+ // one rule in, one rule out (hamr 2026-11-14): an answer about a rule of the check list REPLACES that rule, and the list is the one owner (the caller rebuilds the job text from it: `onJobLines`).
1259
+ // Only an answer that is not about a list row (a model's own try-3 question) is still added word for word as a new `~` rule on its line.
1260
+ // A try-3 question (the drafter's own) names the rule it is about (the answer REPLACES it, one in one out) or says `new` (the answer is added); the draft log counts each under its own kind
1273
1261
  const line = jobLines.find((l) => l.n === q.line);
1274
- if (line && pair !== null) { line.rules[/** @type {number} */ (q.rule) - 1] = text; line.rule = line.rules.join('; '); }
1275
- // F318: agreeing to words the line already holds as a ~ rule adds no second line (the pick cites the rule that is there); different words still add one
1276
- else if (line && !(agreedPick && line.rules.some((/** @type {string} */ t) => sameRuleWords(t, text)))) { line.rule = line.rule ? `${line.rule}; ${text}` : text; line.rules.push(text); }
1262
+ if (q.source !== 'look' && line) {
1263
+ const old = Number.isInteger(q.rule) ? line.rules[/** @type {number} */ (q.rule) - 1] : undefined;
1264
+ if (typeof old === 'string') line.rules[/** @type {number} */ (q.rule) - 1] = text; else line.rules.push(text);
1265
+ line.rule = line.rules.join('; ');
1266
+ appendDraftLog(outDir, { kind: 'try3-question', no: Math.max(0, state.steps.length - 1), line: q.line, ...(typeof old === 'string' ? { rule: q.rule, ruleText: redactSecrets(old) } : { new: true }), how: typeof old === 'string' ? 'replaced' : 'added', question: redactSecrets(q.question), answer: redactSecrets(text), at: new Date().toISOString() });
1267
+ }
1277
1268
  }
1278
- draft.jobLines = signedJobLines(jobLines);
1279
- // R10 (fwd am21): the answers are `~` rules on the lines, so the card's job box says so too: a Revise reopens the boxes WITH them, and an edit of an agreed line is seen as an edit
1280
- state.card = { ...state.card, jobText: jobBoxText(jobLines) };
1281
- answers[1] = renderJobLines(jobLines);
1282
- state.messages.push({ ...planMessage({ ...(o.confirmed ?? {}), ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, jobLines), text: left.length === total ? 'Noted: those stay Not checked. Drafting.' : 'Your answers are in as ~ rules on those job lines. Drafting again.' });
1269
+ const said = left.length === total ? 'Noted: those stay Not checked. Drafting.' : 'Your answers are in on those job lines. Drafting again.';
1270
+ // a check-list ask (every question carries a list key): the list has not yet replaced the asked rules, so the message waits for the rebuilt lines (`onJobLines`) and is drawn from them
1271
+ if (o.questions.every((q) => typeof (/** @type {any} */ (q)).key === 'string')) pendingSay = { say: said, confirmed: o.confirmed };
1272
+ else syncJobLines(jobLines, said, o.confirmed);
1283
1273
  return { jobLines, answers, left, picks, choices };
1284
1274
  };
1285
1275
 
1286
- // F243: the fit check's one question, through the same `ask` (the chat box + Send; a blank answer asks again, there is no skip)
1287
- const fitAsk = async (/** @type {string} */ question) => {
1288
- for (;;) {
1289
- const a = await ask({ kind: 'answer', source: 'fit-check', index: 1, total: 1, question });
1290
- if (a === null) return null;
1291
- if (String(a).trim()) return String(a);
1292
- say('bot', 'An answer is needed here — there is no skip. Type it in the box below and press Send.');
1293
- }
1294
- };
1276
+ // 2026-11-14 (b): the note question's own call (src/noteask.js), same provider, model and thinking-off as the destination call; a test that replaces the model boundary never reaches it unless it brings `deps.noteFn`
1277
+ const noteFn = deps.noteFn !== undefined ? deps.noteFn : (deps.generate ? null : (/** @type {any} */ o) => runNoteAsk({
1278
+ ...o, provider, ...(draftPrice?.rates ? { rates: draftPrice.rates } : {}),
1279
+ ...(Object.keys(thinkingCallOptions(provider, draftThinking)).length ? { callOptions: thinkingCallOptions(provider, draftThinking) } : {}),
1280
+ }));
1295
1281
 
1296
1282
  state.phase = 'drafting';
1297
1283
  // no early "drafting" line: the real author phase (PHASE_STEP) starts it, carrying draftDetail (see onPhase)
@@ -1299,7 +1285,6 @@ export function createSession(card, deps = {}) {
1299
1285
  // the internal resolved tier model string (MODEL) or the raw provider
1300
1286
  // name — the same id the Model field's own dropdown showed.
1301
1287
  const authored = await authorCloseForJob({
1302
- judgeModel: draftJudge.model,
1303
1288
  answers, verdictType, repoPath: prep.tree, lang: LANG,
1304
1289
  questions: questionsFor(verdictType),
1305
1290
  jobLines, inputs: INPUTS,
@@ -1308,7 +1293,7 @@ export function createSession(card, deps = {}) {
1308
1293
  rates: draftPrice?.rates ?? null,
1309
1294
  draftThinking,
1310
1295
  onPhase, onCall,
1311
- ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, ledgerGenerate, editGenerate, carriedPicks, carriedChoices,
1296
+ ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, ledgerGenerate, fenceGenerate, noteFn, onJobLines: (/** @type {any[]} */ lines) => { const p = pendingSay; pendingSay = null; syncJobLines(lines, p ? p.say : null, p ? p.confirmed : null); }, editGenerate, carriedPicks, carriedChoices,
1312
1297
  onChoices: (/** @type {any[]} */ rec) => { try { writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: rec }); } catch { /* a convenience: a disk fault only means the next draft starts without them */ } },
1313
1298
  // R10: this draft's record (the picks it kept and the ones just answered) goes to its own folder for the next draft to carry; each kept pick is logged as such
1314
1299
  onPicks: (/** @type {{entries: any[], kept: {line: number, rule: number, entry: any}[]}} */ o) => {
@@ -1321,31 +1306,11 @@ export function createSession(card, deps = {}) {
1321
1306
  ...(deps.scout ? { scout: deps.scout } : {}),
1322
1307
  // PART 1c: a test that replaces the model boundary (`generate`) must not reach the real paid look; `deps.lookFn` brings its own
1323
1308
  ...(deps.lookFn !== undefined ? { lookFn: deps.lookFn } : (deps.generate ? { lookFn: null } : {})),
1324
- // F243: the fit check asks through the ordinary ask path; like the look, a test that replaces the model boundary never reaches the real paid call
1325
- fitAsk, onFit,
1326
- ...(deps.fitFn !== undefined ? { fitFn: deps.fitFn } : (deps.generate ? { fitFn: null } : {})),
1327
1309
  ...(authorFnOverride ? { authorFn: authorFnOverride } : {}),
1328
1310
  // R5 (piece 2): a Tickets job's drafter is told about the ticket filter and may propose one (the person signs it)
1329
1311
  ...(deps.flow?.flowType === 'tickets' ? { authorOpts: { ticket: true } } : {}),
1330
1312
  });
1331
1313
 
1332
- if (!authored.ok && PLAIN_PROPOSAL_STOPS.includes(String(authored.stop))) {
1333
- // a refused rubric proposal: the person gets the reason in plain words (src/authorreadout.js, the one owner the
1334
- // CLI prints too), and the full reds go into the drafting log on the failed step so the cause survives the session
1335
- const cases = authored.judged?.signed?.cases ?? authored.judged?.proposal?.proposal?.cases ?? null;
1336
- const reds = authored.reds ?? [];
1337
- const runningNo = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
1338
- appendDraftLog(outDir, {
1339
- kind: 'step-reds', no: runningNo === -1 ? state.steps.length - 1 : runningNo, stop: authored.stop,
1340
- reds: redsRecord(reds, { cases }), at: new Date().toISOString(),
1341
- });
1342
- refuse(proposalStopText({
1343
- stop: String(authored.stop), reds, cases,
1344
- spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete },
1345
- source: authored.judged?.source === 'signer' ? 'signer' : 'proposal',
1346
- }));
1347
- return;
1348
- }
1349
1314
  if (!authored.ok) {
1350
1315
  // ITEM 6 (P7): every drafting stop says WHY in plain words (the reds travel into the drafting log beside it) — the bare
1351
1316
  // "Stopped: provider-red" of live session smv2bzdqmp0f8 carried a code and no reason.
@@ -1367,7 +1332,8 @@ export function createSession(card, deps = {}) {
1367
1332
  // piece 8: the card's Flow type and MCP pick are signed by CODE, after the draft (the agent cannot carry them: `assembleSpec` refuses a draft that does). A plain card adds nothing.
1368
1333
  const spec = signFlow(assembleSpec(draft, { ...authored, verdictType: /** @type {string} */ (authored.verdictType) }), deps.flow?.flowType ?? 'plain', deps.flow?.pick ?? null, authored.authoring?.ticketFilter);
1369
1334
  // PART 1a (run mv5bk400): the card AFTER drafting is built from the signed close itself (cardOfClose), never from what the confirm turn planned.
1370
- if (RUBRIC_FILES) {
1335
+ // a repo job that signs the one list gets the same card: its rows, never what the confirm turn planned (Addendum 2026-11-15 (d))
1336
+ if (RUBRIC_FILES || carriesOneList(spec.closeDecl)) {
1371
1337
  const rec = cardOfClose({ closeDecl: spec.closeDecl, jobLines, ledger: readDraftLedger(outDir) });
1372
1338
  // the checks this draft ended with, each marked who added it (`agent` or `you`): the Audit's Draft group shows them (a log line, not a second record of the plan)
1373
1339
  appendDraftLog(outDir, { kind: 'draft-checks', no: Math.max(0, state.steps.length - 1), checks: rec.checkItems.filter((/** @type {any} */ c) => c.by === 'agent' || c.by === 'you').map((/** @type {any} */ c) => ({ line: c.fromLine[0], text: redactSecrets(String(c.text)), by: c.by })), at: new Date().toISOString() });
@@ -1378,18 +1344,36 @@ export function createSession(card, deps = {}) {
1378
1344
  state.finalPlan = { goal: String(draft.goal ?? ''), checkItems: rec.checkItems, picked, notChecked: rec.notChecked, notCheckedBy: rec.notCheckedBy, protections: authored.confirmed?.protections ?? [], signedFacts: signedFactNames(spec.closeDecl), ...(spec.ticketFilter ? { ticketFilter: spec.ticketFilter } : {}) };
1379
1345
  }
1380
1346
  await finish(spec, authored.seedRef, authored.hasBuiltCheck ?? null);
1347
+ if (state.phase === 'prepared') finalCtx = { spec, seedRef: authored.seedRef, tree: prep.tree, repo: !RUBRIC_FILES };
1381
1348
  if (state.finalPlan && state.phase === 'prepared') {
1382
1349
  // The confirm turn's plan bubble (and a try-3 "answers are in" one) is the DRAFTER's wording of the checks, written before
1383
1350
  // any close existed. Once the close is signed-ready its card is the only plan the person sees: the earlier ones are
1384
1351
  // dropped, so drafter prose can never sit above (and be read instead of) the code's sentences (run mv5e1ktb).
1385
1352
  state.messages = state.messages.filter((/** @type {any} */ m) => m.kind !== 'plan');
1386
1353
  state.messages.push({
1387
- ...planMessage({ checkItems: state.finalPlan.checkItems, checks: state.finalPlan.checkItems.map((/** @type {any} */ c) => c.text), notChecked: state.finalPlan.notChecked, notCheckedBy: state.finalPlan.notCheckedBy, protections: state.finalPlan.protections, signedFacts: state.finalPlan.signedFacts, picked: state.finalPlan.picked, ticketFilter: state.finalPlan.ticketFilter, questions: [] }, jobLines),
1354
+ ...finalPlanMessage(),
1388
1355
  text: 'These are the checks the signed close will run, and what it will not check. Sign & run to accept them, or Revise to edit the boxes and draft again.',
1389
1356
  });
1390
1357
  }
1391
1358
  }
1392
1359
 
1360
+ /** the signed-ready card as a chat message; a repo job's agent rows can be Dropped on it (the person shapes the spec they sign: `dropStage`) */
1361
+ const finalPlanMessage = () => ({ ...finalPlanCard(), readout: draftReadout() });
1362
+ /** the draft readout of the signed-ready plan (hamr 2026-11-15): text + head indexes, display only, built from the signed spec in `finalCtx`, the draft log and this session's own figures; one function, so Drop never carries a stale or a second one */
1363
+ const draftReadout = () => {
1364
+ const steps = readDraftSteps(outDir);
1365
+ const text = buildReadout({
1366
+ spec: finalCtx?.spec, name: String(finalCtx?.spec?.job ?? card.jobName), modelId: String(card.model), rounds: steps.reduce((n, x) => n + x.calls.length, 0),
1367
+ costUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete, specHash: state.specHash, source: cardSource(card), destination: String(card.destination ?? ''),
1368
+ humans: steps.flatMap((x) => x.humans), ledger: readDraftLedger(outDir),
1369
+ });
1370
+ return { text, heads: readoutHeadIndexes(text) };
1371
+ };
1372
+ const finalPlanCard = () => planMessage({ checkItems: state.finalPlan.checkItems, checks: state.finalPlan.checkItems.map((/** @type {any} */ c) => c.text), notChecked: state.finalPlan.notChecked, notCheckedBy: state.finalPlan.notCheckedBy, protections: state.finalPlan.protections, signedFacts: state.finalPlan.signedFacts, picked: state.finalPlan.picked, ticketFilter: state.finalPlan.ticketFilter, questions: [], ...(finalCtx?.repo ? { editable: true } : {}) }, jobLines);
1373
+ /** @type {{spec: any, seedRef: string|null, tree: string, repo: boolean}|null} the spec the final card shows and the seed it was gated against */
1374
+ let finalCtx = null;
1375
+ let dropping = false;
1376
+
1393
1377
  // fire-and-forget — the caller (src/panel/server.js) never awaits this; it
1394
1378
  // polls `state` instead. A crash anywhere in `run()` is caught here so it
1395
1379
  // can never take the panel server process down with it.
@@ -1405,6 +1389,8 @@ export function createSession(card, deps = {}) {
1405
1389
  if (!state.pendingAsk) return { ok: false, error: 'nothing is being asked right now' };
1406
1390
  if (state.pendingAsk.kind === 'menu') return { ok: false, error: 'use Sign & run for a plan, never Send — the chat can never sign or pick a plan action' };
1407
1391
  if (state.pendingAsk.kind === 'install-needed') return { ok: false, error: 'install the packages, then click Check again — nothing to send here' };
1392
+ // a check question (a look's reading, a proposed check) is answered by its button only (hamr 2026-11-15): typed words with no choice are refused and the question stays open
1393
+ if (choice === undefined && state.pendingAsk.kind === 'answer' && state.pendingAsk.source === 'look') return { ok: false, refused: 'bad-choice', error: CHOICE_SAYS.bad };
1408
1394
  if (choice !== undefined) {
1409
1395
  // hamr 2026-11-12 (fwd am29/am31): the question box posts a typed choice. A refusal leaves the question open: nothing said, nothing logged, nothing resolved.
1410
1396
  const no = refuseChoice(state.pendingAsk, choice);
@@ -1466,6 +1452,54 @@ export function createSession(card, deps = {}) {
1466
1452
  appendDraftLog(outDir, { kind: 'row-edit', no: Math.max(0, state.steps.length - 1), op, key: redactSecrets(String(key)), at: new Date().toISOString() });
1467
1453
  return { ok: true };
1468
1454
  },
1455
+ /**
1456
+ * Drop on a repo `! [agent]` stage row of the FINAL card (hamr 2026-11-15, spec 2 pick b): the person shaping the spec they are about to sign. The stage and its list row leave a COPY of the spec; the $0 signing gates (the validator and the seed read)
1457
+ * run again on it and the hash is recomputed before the card is drawn again. A gate that refuses (a line left with no check, no work stage red at the seed) refuses the Drop in plain words and nothing changes. Add: a repo has no Suggested rows, so there is none.
1458
+ * @param {unknown} key @returns {Promise<{ok: true}|{ok: false, error: string, refused: string}>}
1459
+ */
1460
+ dropStage: async (key) => {
1461
+ if (state.phase !== 'prepared' || finalCtx === null || !state.finalPlan || !finalCtx.repo || dropping) return { ok: false, refused: 'no-plan', error: 'no plan is waiting where checks can be dropped right now' };
1462
+ const name = stageNameOfKey(key);
1463
+ const rowOk = name !== '' && Array.isArray(finalCtx.spec.closeDecl?.list) && finalCtx.spec.closeDecl.list.some((/** @type {any} */ r) => r && r.key === key && r.kind === 'stage' && r.state === 'built');
1464
+ if (!rowOk) return { ok: false, refused: 'bad-row', error: 'only a check the agent added can be dropped' };
1465
+ dropping = true;
1466
+ try {
1467
+ const droppedLine = Number(finalCtx.spec.closeDecl.list.find((/** @type {any} */ r) => r && r.key === key)?.line ?? 1);
1468
+ const spec = structuredClone(finalCtx.spec);
1469
+ spec.closeDecl.stages = spec.closeDecl.stages.filter((/** @type {any} */ st) => st.name !== name);
1470
+ spec.closeDecl.list = spec.closeDecl.list.filter((/** @type {any} */ r) => r.key !== key);
1471
+ const jv = validateJob(spec, { shellCapUsd: spec.budgetUsd });
1472
+ const signing = jv.ok ? await prepareSigningFn({ spec, workdir: finalCtx.tree, seedRef: finalCtx.seedRef, timeoutMs, shellCapUsd: spec.budgetUsd }) : null;
1473
+ if (signing === null || !signing.ok) {
1474
+ // the plain-words owners (src/authorreadout.js): a validator red is told in its own plain sentence (`tryRefusedText`, the words the draft's own refusals use), a signing red as the signing stop tells it
1475
+ /** @type {any} */
1476
+ const uncovered = signing === null ? jv.reds.find((/** @type {any} */ r) => r.code === 'job-line-uncovered' && Number.isInteger(r.line)) : undefined;
1477
+ const why = uncovered
1478
+ ? `Dropping that check would leave line ${uncovered.line} with no check, so it stays. Use Revise to change the job instead.`
1479
+ : signing === null
1480
+ ? tryRefusedText({ reds: jv.reds.map((/** @type {any} */ r) => ({ ...r, detail: String(r.detail ?? '') })) })
1481
+ : signingStopText({ reds: signing.reds ?? [], refusal: signing.refusal, noCheck: false, spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete } });
1482
+ return { ok: false, refused: 'gates', error: uncovered ? why : `Dropping that check is refused: ${why}` };
1483
+ }
1484
+ writeFileSync(join(outDir, 'resolved-spec.json'), `${JSON.stringify(spec, null, 2)}\n`);
1485
+ writeFileSync(join(outDir, 'signing.json'), `${JSON.stringify(signing, null, 2)}\n`);
1486
+ state.specHash = signing.specHash;
1487
+ finalCtx = { ...finalCtx, spec };
1488
+ const rec = cardOfClose({ closeDecl: spec.closeDecl, jobLines, ledger: readDraftLedger(outDir) });
1489
+ state.finalPlan = { ...state.finalPlan, checkItems: rec.checkItems, notChecked: rec.notChecked, notCheckedBy: rec.notCheckedBy };
1490
+ const at = state.messages.findLastIndex((/** @type {any} */ m) => m.kind === 'plan');
1491
+ const msg = { ...finalPlanMessage(), text: 'These are the checks the signed close will run, and what it will not check. Sign & run to accept them, or Revise to edit the boxes and draft again.' };
1492
+ if (at === -1) state.messages.push(msg); else state.messages[at] = msg;
1493
+ appendDraftLog(outDir, { kind: 'row-edit', no: Math.max(0, state.steps.length - 1), op: 'drop', key: redactSecrets(String(key)), at: new Date().toISOString() });
1494
+ // the same record a rubric Drop writes (the check block's own `choiceEntries`): a Revise keeps this Drop, code still judging it (never the last check on a line)
1495
+ try {
1496
+ const entry = choiceEntries(jobLines.map((/** @type {any} */ l) => ({ n: l.n, text: l.text })), [{ line: droppedLine, key: String(key), choice: 'drop' }]);
1497
+ const had = readRowChoices(join(outDir, RECORD_FILE)) ?? [];
1498
+ writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: [...had.filter((/** @type {any} */ c) => !entry.some((e) => e.lineWords === c.lineWords && e.occurrence === c.occurrence && e.tail === c.tail)), ...entry] });
1499
+ } catch { /* a convenience: a disk fault only means the next draft starts without it */ }
1500
+ return { ok: true };
1501
+ } finally { dropping = false; }
1502
+ },
1469
1503
  /** click 1 — the confirm pick. Never signs on its own. */
1470
1504
  signPrepare: () => {
1471
1505
  if (!state.pendingAsk || state.pendingAsk.kind !== 'menu') return { ok: false, error: 'no plan is waiting for a decision right now' };