bareloop 0.55.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.
- package/CHANGELOG.md +82 -0
- package/README.md +3 -3
- package/bareloop.context.md +69 -209
- package/package.json +2 -2
- package/src/authorflow.js +164 -340
- package/src/authoring.js +7 -127
- package/src/authorjob.js +139 -472
- package/src/authorreadout.js +24 -368
- package/src/authorrun.js +21 -215
- package/src/behaviour.js +14 -0
- package/src/blockasks.js +43 -0
- package/src/bundlerun.js +4 -1
- package/src/checkblock.js +798 -0
- package/src/checklist.js +128 -0
- package/src/checkpick.js +39 -312
- package/src/checkwords.js +3 -1
- package/src/cli.js +3 -3
- package/src/declaredclose.js +38 -108
- package/src/destpoint.js +4 -2
- package/src/draftspend.js +46 -0
- package/src/facts.js +8 -1
- package/src/index.js +3 -43
- package/src/interviewrun.js +13 -8
- package/src/job.js +20 -1
- package/src/jobblock.js +11 -46
- package/src/judged.js +13 -1229
- package/src/kinds.js +5 -347
- package/src/noteask.js +124 -0
- package/src/pagedry.js +27 -5
- package/src/pagemap.js +15 -3
- package/src/pagerules.js +18 -3
- package/src/panel/authorroutes.js +24 -6
- package/src/panel/authorsession.js +222 -177
- package/src/panel/importrun.js +0 -1
- package/src/panel/index.html +198 -26
- package/src/panel/jobplan.js +87 -33
- package/src/panel/server.js +74 -68
- package/src/panel/status.js +3 -0
- package/src/pickrecord.js +34 -55
- package/src/placerule.js +355 -0
- package/src/planrun.js +2 -48
- package/src/promptregisters.js +13 -17
- package/src/providerrows.js +0 -36
- package/src/providers.js +4 -25
- package/src/questionbox.js +104 -0
- package/src/rowedit.js +115 -0
- package/src/rubricstep.js +234 -127
- package/src/run.js +11 -16
- package/src/userrun.js +60 -112
- package/types/authorflow.d.ts +41 -197
- package/types/authoring.d.ts +1 -14
- package/types/authorjob.d.ts +35 -59
- package/types/authorreadout.d.ts +10 -88
- package/types/behaviour.d.ts +12 -0
- package/types/blockasks.d.ts +36 -0
- package/types/checkblock.d.ts +376 -0
- package/types/checklist.d.ts +134 -0
- package/types/checkpick.d.ts +8 -140
- package/types/cli.d.ts +1 -3
- package/types/declaredclose.d.ts +7 -33
- package/types/destpoint.d.ts +2 -0
- package/types/draftspend.d.ts +21 -0
- package/types/index.d.ts +2 -4
- package/types/job.d.ts +8 -0
- package/types/jobblock.d.ts +8 -38
- package/types/judged.d.ts +7 -357
- package/types/kinds.d.ts +3 -104
- package/types/noteask.d.ts +76 -0
- package/types/pagedry.d.ts +13 -0
- package/types/pagemap.d.ts +4 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/authorsession.d.ts +47 -5
- package/types/panel/jobgrid.d.ts +8 -8
- package/types/panel/jobplan.d.ts +48 -10
- package/types/panel/server.d.ts +27 -18
- package/types/panel/status.d.ts +5 -0
- package/types/pickrecord.d.ts +20 -13
- package/types/placerule.d.ts +194 -0
- package/types/planrun.d.ts +1 -22
- package/types/providerrows.d.ts +0 -31
- package/types/providers.d.ts +3 -19
- package/types/questionbox.d.ts +87 -0
- package/types/rowedit.d.ts +32 -0
- package/types/rubricstep.d.ts +100 -48
- package/types/run.d.ts +9 -19
- package/types/userrun.d.ts +0 -1
- package/src/calibrate.js +0 -702
- package/src/cardauthor.js +0 -502
- package/src/fitcheck.js +0 -166
- package/types/calibrate.d.ts +0 -201
- package/types/cardauthor.d.ts +0 -358
- package/types/fitcheck.d.ts +0 -113
|
@@ -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,
|
|
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,34 +41,40 @@ import {
|
|
|
42
41
|
import { prepareSigning } from '../authorjob.js';
|
|
43
42
|
import { checkCloseByteSignature } from '../close-integrity.js';
|
|
44
43
|
import {
|
|
45
|
-
questionsFor, requiredAnswersFor, makeLoopGenerate,
|
|
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
|
|
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,
|
|
52
|
+
import { rubricGoal, cardOfClose, signedFactNames } 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';
|
|
57
|
+
import { newestUnrunTicket } from '../ticketnext.js';
|
|
58
|
+
import { readTicket } from '../ticket.js';
|
|
59
|
+
import { readRunList } from '../runlist.js';
|
|
60
|
+
import { fetchPageText } from '../pagefetch.js';
|
|
59
61
|
import { isDropIt, isAgree, stripAgreeLead } from '../pagemap.js';
|
|
60
|
-
import { plainWords, SUGGEST_SYSTEM
|
|
61
|
-
import {
|
|
62
|
+
import { plainWords, SUGGEST_SYSTEM } from '../checkpick.js';
|
|
63
|
+
import { LEDGER_SYSTEM } from '../checklist.js';
|
|
64
|
+
import { ROW_EDIT_SYSTEM } from '../rowedit.js';
|
|
65
|
+
import { readRecordFile, readRowChoices, writeRecordPart, RECORD_FILE, KEPT_WORDS } from '../pickrecord.js';
|
|
62
66
|
import { MAX_REVISES, draftLabelOf, nextRevisesUsed, sessionsRootOf, writeRevisesUsed } from '../revises.js';
|
|
63
|
-
import { FIT_ABSENT_NOTE } from '../fitcheck.js';
|
|
64
67
|
import { runDestPoint, destQuestionText, yesNoOf } from '../destpoint.js';
|
|
68
|
+
import { runNoteAsk } from '../noteask.js';
|
|
65
69
|
import { tallyCalls } from '../text.js';
|
|
66
|
-
import { appendDraftLog } from '../draftspend.js';
|
|
67
|
-
import {
|
|
70
|
+
import { appendDraftLog, readDraftLedger } from '../draftspend.js';
|
|
71
|
+
import { signingStopText, draftStopText, redsRecord, declarationRecord, tryRefusedText } from '../authorreadout.js';
|
|
68
72
|
import { runNpmCi, NPM_CI_LOCKS } from '../npminstall.js';
|
|
69
73
|
import {
|
|
70
|
-
parseJobBlock, parseInputs,
|
|
74
|
+
parseJobBlock, parseInputs, renderJobLines, signedJobLines, jobBoxText, REPO_RUBRIC_WORDS,
|
|
71
75
|
} from '../jobblock.js';
|
|
72
76
|
import { planFromConfirm } from './jobplan.js';
|
|
77
|
+
import { boxFor, offersOf, panelQuestionText, refuseChoice, resolveChoice } from '../questionbox.js';
|
|
73
78
|
import { isTicketTrigger } from '../trigger.js';
|
|
74
79
|
import { ticketLookOf } from '../ticketschedule.js';
|
|
75
80
|
|
|
@@ -92,7 +97,6 @@ export const STEP_LABELS = Object.freeze({
|
|
|
92
97
|
listing: 'listing files',
|
|
93
98
|
confirm: 'confirming plan',
|
|
94
99
|
draft: 'drafting',
|
|
95
|
-
calibrate: 'calibrating',
|
|
96
100
|
gates: 'checking signing gates',
|
|
97
101
|
hash: 'generating hash',
|
|
98
102
|
signed: 'signed hash',
|
|
@@ -128,17 +132,11 @@ export const PHASE_STEP = Object.freeze({
|
|
|
128
132
|
'scout-done': 'scout',
|
|
129
133
|
look: 'look',
|
|
130
134
|
'look-done': 'look',
|
|
131
|
-
// F243: the fit check's one call is counted in the look's line, like the look
|
|
132
|
-
'fit-check': 'look',
|
|
133
|
-
'fit-check-done': 'look',
|
|
134
135
|
confirm: 'confirm',
|
|
135
136
|
'confirm-turn-done': 'confirm',
|
|
136
137
|
listing: 'listing',
|
|
137
138
|
'listing-done': 'listing',
|
|
138
139
|
author: 'draft',
|
|
139
|
-
rubric: 'calibrate',
|
|
140
|
-
'rubric-done': 'calibrate',
|
|
141
|
-
'rubric-scrubbed': 'calibrate',
|
|
142
140
|
});
|
|
143
141
|
|
|
144
142
|
export { thinkingRowText };
|
|
@@ -179,7 +177,7 @@ export const PLAN_FOOTER = 'Sign & run to confirm this plan, or Revise to edit t
|
|
|
179
177
|
* The confirm turn's plan as a chat message (P7): a STRUCTURED `{role:'bot', kind:'plan', plan}` the page draws with the
|
|
180
178
|
* same renderer the Job tab uses — each numbered job line, its `~` rule, its drafted checks folded; the AI's own "not
|
|
181
179
|
* checked"; the always-on guards. `questions` (what the plan still asks) ride inside the plan. One owner of the shape.
|
|
182
|
-
* @param {{goal?: string, checks?: string[], checkItems?: {text: string, fromLine: number[]|null}[], notChecked?: string[], questions?: string[], protections?: string[], signedFacts?: string[], ticketFilter?: any, picked?: {line: number, text: string}[]}} p the confirm turn's plan
|
|
180
|
+
* @param {{goal?: string, checks?: string[], checkItems?: {text: string, fromLine: number[]|null, by?: 'agent'|'you'|'default'|null, key?: string}[], notChecked?: string[], notCheckedBy?: Record<string, 'you'|'agent'|'default'>, suggested?: {key: string, line: number, text: string}[], editable?: boolean, questions?: string[], protections?: string[], signedFacts?: string[], ticketFilter?: any, picked?: {line: number, text: string}[]}} p the confirm turn's plan
|
|
183
181
|
* @param {{n: number, text: string, rule: string}[]|null} jobLines
|
|
184
182
|
* @returns {{role: 'bot', kind: 'plan', text: string, plan: ReturnType<typeof planFromConfirm> & {goal: string, questions: string[]}}}
|
|
185
183
|
*/
|
|
@@ -235,6 +233,31 @@ export function nextFreeJobName(origin, runJobs, opts = {}) {
|
|
|
235
233
|
/** the form's fields, in card order — what `card.json` stores, verbatim (P5 item 3) */
|
|
236
234
|
export const CARD_FIELDS = Object.freeze(['jobName', 'checkType', 'provider', 'model', 'thinking', 'jobText', 'inputs', 'destination', 'capUsd', 'maxWallMs', 'flowType', 'mcp', 'ticket', 'schedule']);
|
|
237
235
|
|
|
236
|
+
/**
|
|
237
|
+
* 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
|
|
238
|
+
* Destination check and Reuse (`buildReuseSpec`) all read THIS, never a copy.
|
|
239
|
+
* @param {any} card
|
|
240
|
+
* @param {{rubric?: boolean, flowType?: 'plain'|'mcp'|'tickets'}} [o]
|
|
241
|
+
* @returns {{ok: true, inputs: import('../jobblock.js').JobInput[]}|{ok: false, error: string}}
|
|
242
|
+
*/
|
|
243
|
+
export function cardInputs(card, o = {}) {
|
|
244
|
+
const ip = parseInputs(card?.inputs);
|
|
245
|
+
if (!ip.ok) return ip;
|
|
246
|
+
return { ok: true, inputs: ticketRubricInputs(ip.inputs, { rubric: o.rubric ?? card?.checkType === 'rubric', flowType: o.flowType ?? flowOfCard(card).flowType }) };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 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
|
|
251
|
+
* 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.
|
|
252
|
+
* @param {import('../jobblock.js').JobInput[]} inputs @param {{rubric: boolean, flowType: 'plain'|'mcp'|'tickets'}} o
|
|
253
|
+
* @returns {import('../jobblock.js').JobInput[]}
|
|
254
|
+
*/
|
|
255
|
+
export function ticketRubricInputs(inputs, { rubric, flowType }) {
|
|
256
|
+
if (!rubric || flowType !== 'tickets') return inputs;
|
|
257
|
+
const line = inputs.find((i) => parseTicketList(i.value).ok);
|
|
258
|
+
return line ? [{ ...line, n: 1 }] : inputs;
|
|
259
|
+
}
|
|
260
|
+
|
|
238
261
|
/**
|
|
239
262
|
* The repo a card names: Inputs line 1 (P7 — the Source box is gone; the first input IS the repo). `''` when the Inputs
|
|
240
263
|
* box does not parse (the card validator refuses that before anything uses this).
|
|
@@ -242,7 +265,7 @@ export const CARD_FIELDS = Object.freeze(['jobName', 'checkType', 'provider', 'm
|
|
|
242
265
|
* @returns {string}
|
|
243
266
|
*/
|
|
244
267
|
export function cardSource(card) {
|
|
245
|
-
const p =
|
|
268
|
+
const p = cardInputs(card);
|
|
246
269
|
return p.ok ? p.inputs[0].value : '';
|
|
247
270
|
}
|
|
248
271
|
|
|
@@ -261,7 +284,7 @@ export function cardFields(card) {
|
|
|
261
284
|
/**
|
|
262
285
|
* 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
|
|
263
286
|
* 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,
|
|
264
|
-
* `~` rules
|
|
287
|
+
* `~` rules), the check type and the thinking tick. The RUN boxes (Inputs, Destination, Model, $ cap, Time cap)
|
|
265
288
|
* never decide it. A green origin with no job box changed reuses the signed plan verbatim (no drafting); anything else drafts.
|
|
266
289
|
*/
|
|
267
290
|
export const JOB_BOXES = Object.freeze(['jobText', 'checkType', 'thinking', 'flowType', 'mcp']);
|
|
@@ -347,7 +370,7 @@ export function buildReuseSpec(originSpec, card, rows) {
|
|
|
347
370
|
// 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
|
|
348
371
|
// 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).
|
|
349
372
|
if (!isAbsoluteDestination(String(card.destination ?? '').trim())) spec.writeScope = String(card.destination ?? '').split(/[,\n]/).map((x) => x.trim()).filter(Boolean);
|
|
350
|
-
const ip =
|
|
373
|
+
const ip = cardInputs(card, { rubric: spec.verdictType === 'soft-green', flowType: flowTypeOf(spec) });
|
|
351
374
|
if (ip.ok) spec.inputs = ip.inputs; else delete spec.inputs;
|
|
352
375
|
spec.budgetUsd = card.capUsd;
|
|
353
376
|
if (typeof card.maxWallMs === 'number' && Number.isFinite(card.maxWallMs) && card.maxWallMs > 0) spec.maxWallMs = card.maxWallMs;
|
|
@@ -403,7 +426,7 @@ export const DESTINATION_HINT = 'Type the folder that holds the files the job sh
|
|
|
403
426
|
* @returns {string|null} the plain refusal, or null when the Destination is fine
|
|
404
427
|
*/
|
|
405
428
|
export function startDestinationProblem(card) {
|
|
406
|
-
const ip =
|
|
429
|
+
const ip = cardInputs(card);
|
|
407
430
|
const source = ip.ok ? (ip.inputs[0]?.value ?? '') : '';
|
|
408
431
|
const destination = typeof card?.destination === 'string' ? card.destination : '';
|
|
409
432
|
const isRepoLike = looksLikeRepoSource(source);
|
|
@@ -452,13 +475,10 @@ export function validateJobCard(card, opts = {}) {
|
|
|
452
475
|
if (card.thinking !== undefined && typeof card.thinking !== 'boolean') return { ok: false, error: 'Thinking on must be on or off' };
|
|
453
476
|
const jb = parseJobBlock(card.jobText);
|
|
454
477
|
if (!jb.ok) return { ok: false, error: jb.error };
|
|
455
|
-
const ib =
|
|
478
|
+
const ib = cardInputs(card);
|
|
456
479
|
if (!ib.ok) return { ok: false, error: ib.error };
|
|
457
|
-
//
|
|
458
|
-
|
|
459
|
-
const rubricFiles = checkType === 'rubric' && looksLikeRubricInput(ib.inputs[0].value);
|
|
460
|
-
const misfit = jobBlockFitsCheck(jb.lines, checkType === 'rubric', { judged: !rubricFiles });
|
|
461
|
-
if (misfit) return { ok: false, error: misfit };
|
|
480
|
+
// 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).
|
|
481
|
+
if (checkType === 'rubric' && flowOfCard(card).flowType !== 'tickets' && looksLikeRepoSource(ib.inputs[0].value)) return { ok: false, error: REPO_RUBRIC_WORDS };
|
|
462
482
|
if (typeof destination !== 'string' || destination.trim() === '') return { ok: false, error: 'Destination is required' };
|
|
463
483
|
if (typeof capUsd !== 'number' || !Number.isFinite(capUsd) || capUsd <= 0) {
|
|
464
484
|
return { ok: false, error: '$ cap is required and must be a positive number' };
|
|
@@ -473,8 +493,8 @@ export function validateJobCard(card, opts = {}) {
|
|
|
473
493
|
* `signPrepare()` are the only ways in.
|
|
474
494
|
* @param {any} card the validated job card (see {@link validateJobCard})
|
|
475
495
|
* @param {{env?: Record<string,string|undefined>, sessionsRoot?: string, home?: string, timeoutMs?: number,
|
|
476
|
-
* scout?: any, generate?: Function, pickGenerate?: Function|null, carryFrom?: string, carryKind?: string, confirmGenerate?: Function, authorFn?: Function,
|
|
477
|
-
* prepareSigningFn?: Function, npmCiFn?: Function, lookFn?: Function|null,
|
|
496
|
+
* scout?: any, generate?: Function, pickGenerate?: Function|null, ledgerGenerate?: Function|null, noteFn?: Function|null, editGenerate?: Function|null, carryFrom?: string, carryKind?: string, confirmGenerate?: Function, authorFn?: Function,
|
|
497
|
+
* 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
|
|
478
498
|
* TEST SEAMS ONLY — see the note just above where each is read, below. `reuse` (Reuse workflow) is NOT a seam: the
|
|
479
499
|
* caller (`/api/author/start`) sets it only when the server's own same-job rule held.
|
|
480
500
|
* @returns {any} the session object
|
|
@@ -488,7 +508,7 @@ export function createSession(card, deps = {}) {
|
|
|
488
508
|
// block before a session exists; a reuse card's job text is the origin's and is not drafted from.
|
|
489
509
|
const jobParsed = parseJobBlock(card.jobText);
|
|
490
510
|
const jobLines = jobParsed.ok ? jobParsed.lines : [];
|
|
491
|
-
const inputsParsed =
|
|
511
|
+
const inputsParsed = cardInputs(card, { flowType: deps.flow?.flowType ?? 'plain' });
|
|
492
512
|
const INPUTS = inputsParsed.ok ? inputsParsed.inputs : [];
|
|
493
513
|
/** the repo — Inputs line 1 */
|
|
494
514
|
const SOURCE = INPUTS[0]?.value ?? '';
|
|
@@ -511,6 +531,10 @@ export function createSession(card, deps = {}) {
|
|
|
511
531
|
// R10 (fwd am17/am18/am20): the picks record of the earlier session this draft follows (a Revise, or a Start over), read from that session's own folder. The id is a session id
|
|
512
532
|
// (never a path); no record, or an unreadable one, is no record: every rule is asked.
|
|
513
533
|
const carriedPicks = typeof deps.carryFrom === 'string' && /^s[a-z0-9]+$/.test(deps.carryFrom) ? readRecordFile(join(sessionsRoot, deps.carryFrom, RECORD_FILE)) : null;
|
|
534
|
+
// hamr 2026-11-13 (N-2): the Drop/Add choices of that same earlier draft ride in the same record file
|
|
535
|
+
const carriedChoices = typeof deps.carryFrom === 'string' && /^s[a-z0-9]+$/.test(deps.carryFrom) ? readRowChoices(join(sessionsRoot, deps.carryFrom, RECORD_FILE)) : null;
|
|
536
|
+
/** the confirm card's Drop/Add door for the plan now waiting (set by `ask`, cleared when it is answered): a row edit through the live check block, $0, no model call @type {((op: 'drop'|'add', key: string) => any)|null} */
|
|
537
|
+
let planEdit = null;
|
|
514
538
|
|
|
515
539
|
// fwd M4e am14 item 3: the revises this draft has used (src/revises.js); the page reads `revisesLeft` to word its button
|
|
516
540
|
const revisesUsed = nextRevisesUsed(sessionsRoot, deps.carryFrom, deps.carryKind);
|
|
@@ -575,7 +599,7 @@ export function createSession(card, deps = {}) {
|
|
|
575
599
|
};
|
|
576
600
|
|
|
577
601
|
/** a rubric job on local files words its copy/read steps for files (set once the card is known) */
|
|
578
|
-
let fileJob = card.checkType === 'rubric' && looksLikeRubricInput(
|
|
602
|
+
let fileJob = card.checkType === 'rubric' && looksLikeRubricInput(INPUTS[0]?.value ?? '');
|
|
579
603
|
/** @param {string} id @param {string} [detail] (absent = keep what the step has) start (or restart) a step; whatever step was running is finished */
|
|
580
604
|
const stepStart = (id, detail) => {
|
|
581
605
|
const labels = fileJob ? { ...STEP_LABELS, ...FILE_JOB_STEP_LABELS } : STEP_LABELS;
|
|
@@ -603,6 +627,13 @@ export function createSession(card, deps = {}) {
|
|
|
603
627
|
|
|
604
628
|
/** @param {'bot'|'you'|'system'} role @param {string} text */
|
|
605
629
|
const say = (role, text) => { state.messages.push({ role, text }); };
|
|
630
|
+
/** the bot message of the question now open: the panel's question box shows it, so the thread holds it back (`askOpen`) until the question is answered @type {{role: string, text: string, askOpen?: boolean}|null} */
|
|
631
|
+
let openMsg = null;
|
|
632
|
+
const sayOpen = (/** @type {string} */ text) => { openMsg = { role: 'bot', text, askOpen: true }; state.messages.push(openMsg); };
|
|
633
|
+
const closeOpenMsg = () => { if (openMsg) { delete openMsg.askOpen; openMsg = null; } };
|
|
634
|
+
/** the button the person used to answer the question just resolved (`agree`, `drop`, `rule`, ...), or null when they typed words (the CLI, an old page); read once, right after the `await ask(...)` @type {string|null} */
|
|
635
|
+
let answeredChoice = null;
|
|
636
|
+
const takeChoice = () => { const c = answeredChoice; answeredChoice = null; return c; };
|
|
606
637
|
/** a structured message (the plan bubble): the page draws it, the thread keeps it as data */
|
|
607
638
|
/** the checks the person has agreed so far (their plain words, `kept from last draft` on a carried one): the plan bubble draws each once, as a `[you picked]` row @type {{line: number, text: string}[]} */
|
|
608
639
|
const pickedSoFar = [];
|
|
@@ -636,45 +667,39 @@ export function createSession(card, deps = {}) {
|
|
|
636
667
|
const running = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
|
|
637
668
|
appendDraftLog(outDir, {
|
|
638
669
|
kind: 'human', no: running === -1 ? Math.max(0, state.steps.length - 1) : running, source: typeof step.source === 'string' ? step.source : 'confirm',
|
|
639
|
-
question: redactSecrets(step.question), answer: said, ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
|
|
670
|
+
question: redactSecrets(step.question), answer: said, ...(answeredChoice === null ? {} : { choice: answeredChoice }), ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
|
|
640
671
|
});
|
|
641
672
|
}
|
|
642
673
|
resolveFn0(value);
|
|
643
674
|
};
|
|
644
|
-
|
|
675
|
+
const box = boxFor(step);
|
|
676
|
+
// the plan's Drop/Add door is a function: it never rides in `state` (that is JSON)
|
|
677
|
+
const { edit: stepEdit, ...stepPure } = step;
|
|
678
|
+
planEdit = typeof stepEdit === 'function' ? stepEdit : null;
|
|
679
|
+
state.pendingAsk = box === null ? stepPure : { ...stepPure, box };
|
|
645
680
|
resolvePending = resolveFn;
|
|
646
681
|
if (step.kind === 'language') say('bot', `${step.field?.prompt ?? 'Which language is this job about?'} (${(step.candidates ?? []).join(', ')})`);
|
|
647
682
|
else if (step.kind === 'menu') {
|
|
648
683
|
sayPlan(step.plan ?? {});
|
|
649
|
-
} else if (step.kind === 'answer' && (step.source === '
|
|
650
|
-
else if (step.kind === 'answer')
|
|
684
|
+
} else if (step.kind === 'answer' && (step.source === 'dest-point')) sayOpen(panelQuestionText(/** @type {any} */ (step)));
|
|
685
|
+
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))}`);
|
|
651
686
|
else if (step.kind === 'goal') say('bot', 'Type the goal sentence yourself.');
|
|
652
687
|
});
|
|
653
688
|
|
|
654
|
-
/** @param {string|null} value @returns {boolean} */
|
|
655
|
-
const answer = (value) => {
|
|
689
|
+
/** @param {string|null} value @param {string|null} [choice] the button used, when the answer came from the question box @returns {boolean} */
|
|
690
|
+
const answer = (value, choice = null) => {
|
|
656
691
|
if (!resolvePending) return false;
|
|
657
692
|
const r = resolvePending;
|
|
658
693
|
resolvePending = null;
|
|
659
694
|
state.pendingAsk = null;
|
|
695
|
+
planEdit = null;
|
|
696
|
+
closeOpenMsg();
|
|
697
|
+
answeredChoice = choice;
|
|
660
698
|
r(value);
|
|
661
699
|
return true;
|
|
662
700
|
};
|
|
663
701
|
|
|
664
702
|
let lastTryRefused = false;
|
|
665
|
-
// 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
|
|
666
|
-
// (a seam of its own - onPhase never posts a chat message)
|
|
667
|
-
const onFit = (/** @type {any} */ data) => {
|
|
668
|
-
const running = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
|
|
669
|
-
appendDraftLog(outDir, {
|
|
670
|
-
kind: 'fit-check', no: running === -1 ? Math.max(0, state.steps.length - 1) : running, state: String(data.state ?? 'absent'),
|
|
671
|
-
asks: (Array.isArray(data.asks) ? data.asks : []).map((/** @type {any} */ a) => ({
|
|
672
|
-
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' } : {}),
|
|
673
|
-
})),
|
|
674
|
-
notFound: (Array.isArray(data.notFound) ? data.notFound : []).map((/** @type {any} */ x) => ({ line: x.line, ask: redactSecrets(String(x.ask)) })), at: new Date().toISOString(),
|
|
675
|
-
});
|
|
676
|
-
if (data.state === 'absent') say('bot', FIT_ABSENT_NOTE);
|
|
677
|
-
};
|
|
678
703
|
const onPhase = (name, data = {}) => {
|
|
679
704
|
// COLLAPSED INTO THE PROGRESS INDICATOR ONLY (build item 3) — this used
|
|
680
705
|
// to also `say('system', `… ${name}`)`, one jargon chat bubble per
|
|
@@ -688,6 +713,11 @@ export function createSession(card, deps = {}) {
|
|
|
688
713
|
// WHY a try was refused: the drafting log keeps it beside the call that made it (it used to say only "retry 3 of 3"), and the
|
|
689
714
|
// progress line shows it briefly, in code's words
|
|
690
715
|
// PRD v1.131 tick 7: the retention counts of a rubric draft, one line when it ends (counts only, no words)
|
|
716
|
+
// 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`)
|
|
717
|
+
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() });
|
|
718
|
+
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() });
|
|
719
|
+
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() });
|
|
720
|
+
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() });
|
|
691
721
|
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() });
|
|
692
722
|
if (name === 'author-try-failed') {
|
|
693
723
|
lastTryRefused = true;
|
|
@@ -826,6 +856,9 @@ export function createSession(card, deps = {}) {
|
|
|
826
856
|
const keyProblem = apiKeyProblem(apiKey);
|
|
827
857
|
if (keyProblem) { refuse(`${draftKeyName} ${keyProblem}. Stopped — nothing spent.`); return; }
|
|
828
858
|
|
|
859
|
+
// 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.
|
|
860
|
+
const oldJob = deps.reuse ? oldJobWords(deps.reuse.spec) : null;
|
|
861
|
+
if (oldJob !== null) { refuse(`${oldJob} Nothing spent.`); return; }
|
|
829
862
|
const verdictType = card.checkType === 'rubric' ? 'soft-green' : 'green';
|
|
830
863
|
const into = join(outDir, 'source-seed');
|
|
831
864
|
const isRepoLike = looksLikeRepoSource(SOURCE);
|
|
@@ -858,7 +891,20 @@ export function createSession(card, deps = {}) {
|
|
|
858
891
|
/** @type {any} */
|
|
859
892
|
let prep;
|
|
860
893
|
if (RUBRIC_FILES) {
|
|
861
|
-
|
|
894
|
+
// 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
|
|
895
|
+
// (the product's own lookup, `newestUnrunTicket`) and reads it (`readTicket`): there is no ticket-number box. Run start re-reads the same list row.
|
|
896
|
+
const ticketFlow = deps.flow?.flowType === 'tickets' && deps.flow.pick ? deps.flow.pick : null;
|
|
897
|
+
/** @param {string} url @returns {Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>} */
|
|
898
|
+
const readNewestTicket = async (url) => {
|
|
899
|
+
const rows = (() => { try { return readRunList({ home: configHome }).rows; } catch { return []; } })();
|
|
900
|
+
const picked = await (deps.newestUnrunTicket ?? newestUnrunTicket)({ job: card.jobName, rows, inputs: INPUTS, mcp: /** @type {{server: string, tools: string[]}} */ (ticketFlow) });
|
|
901
|
+
if (!picked.ok) return { ok: false, error: picked.say.replace(/\s*Nothing spent\.$/, '') };
|
|
902
|
+
const t = await (deps.readTicketFn ?? readTicket)({ mcp: /** @type {{server: string, tools: string[]}} */ (ticketFlow), listUrl: url, number: picked.number });
|
|
903
|
+
return t.ok ? { ok: true, text: t.ticket.text, url } : { ok: false, error: t.error };
|
|
904
|
+
};
|
|
905
|
+
const pageFetch = deps.fetchUrl ?? fetchPageText;
|
|
906
|
+
const draftFetch = ticketFlow ? (/** @type {string} */ url) => (parseTicketList(url).ok ? readNewestTicket(url) : pageFetch(url)) : deps.fetchUrl;
|
|
907
|
+
const proved = await proveRubricInputs({ inputs: INPUTS, into, destination: card.destination, ...(draftFetch ? { fetchUrl: draftFetch } : {}) });
|
|
862
908
|
prep = proved.ok ? proved.prep : { stop: proved.error, code: proved.code };
|
|
863
909
|
// what each header-only page read came back with (already secret-masked at capture), so the next live failure shows it
|
|
864
910
|
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() });
|
|
@@ -949,7 +995,7 @@ export function createSession(card, deps = {}) {
|
|
|
949
995
|
* the seed themselves.
|
|
950
996
|
* @param {any} spec @param {string|null} seedRef
|
|
951
997
|
*/
|
|
952
|
-
const finish = async (spec, seedRef) => {
|
|
998
|
+
const finish = async (spec, seedRef, hasBuiltCheck = /** @type {boolean|null} */ (null)) => {
|
|
953
999
|
if (abandoned) return;
|
|
954
1000
|
// R7 (piece 9): a schedule picked on the card is part of the job the person signs, so the FIRST run's hash already covers it. By hand adds nothing (the key stays absent).
|
|
955
1001
|
if (deps.schedule) {
|
|
@@ -991,54 +1037,21 @@ export function createSession(card, deps = {}) {
|
|
|
991
1037
|
return;
|
|
992
1038
|
}
|
|
993
1039
|
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
const
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
let judgePrice = null;
|
|
1001
|
-
if (judge) {
|
|
1002
|
-
const judgeRow = judgeRowFor(keyCfg, judge, modelChoice.provider, keyCfg.find((r) => r.envName === modelChoice.envName) ?? null);
|
|
1003
|
-
try {
|
|
1004
|
-
judgePrice = judgeRatesFor(judge, modelChoice.provider, modelChoice.baseUrl, draftPrice, keyCfg);
|
|
1005
|
-
} catch (e) {
|
|
1006
|
-
if (!(e instanceof ConfigError)) throw e;
|
|
1007
|
-
refuse(`${e.message} — refusing before gate 4 spends anything`);
|
|
1008
|
-
return;
|
|
1009
|
-
}
|
|
1010
|
-
const judgeKeyValue = env.JUDGE_API_KEY ?? (judge.provider === modelChoice.provider ? apiKey : keyValueOf(env, judgeRow?.envName));
|
|
1011
|
-
const judgeKeyProblem = judgeKeyValue ? apiKeyProblem(judgeKeyValue) : null;
|
|
1012
|
-
if (!judgeKeyValue || judgeKeyProblem) {
|
|
1013
|
-
refuse(`the judge key is not usable (${judgeKeyProblem ?? 'not set'}) — refusing before gate 4 spends anything`);
|
|
1014
|
-
return;
|
|
1015
|
-
}
|
|
1016
|
-
judgeProvider = buildRunnerProviders({
|
|
1017
|
-
providerName: modelChoice.provider, apiKey, model: MODEL, baseUrl: modelChoice.baseUrl, legacyMaxTokens: modelChoice.legacyMaxTokens,
|
|
1018
|
-
judgeApiKey: judgeKeyValue, judgeModel: judge.model, judgeProviderName: judge.provider,
|
|
1019
|
-
judgeBaseUrl: judge.provider === modelChoice.provider ? modelChoice.baseUrl : (judgeRow?.baseUrl.trim() || undefined),
|
|
1020
|
-
judgeLegacyMaxTokens: judge.provider === modelChoice.provider ? modelChoice.legacyMaxTokens : (judgeRow?.legacyMaxTokens ?? false),
|
|
1021
|
-
}).judgeProvider;
|
|
1040
|
+
// the end check: a rubric close with no real check never reaches the signing gates (R10, hamr 2026-11-10)
|
|
1041
|
+
// the check block says it (block.hasBuiltCheck(), carried out of drafting): a rubric run needs at least one built check
|
|
1042
|
+
const noCheck = hasBuiltCheck === false ? signingStopText({ reds: [], noCheck: true, spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete } }) : null;
|
|
1043
|
+
if (noCheck) {
|
|
1044
|
+
refuse(noCheck);
|
|
1045
|
+
return;
|
|
1022
1046
|
}
|
|
1047
|
+
state.phase = 'signing-gates';
|
|
1048
|
+
stepStart('gates', 'gates 1–3 cost $0');
|
|
1023
1049
|
const signing = await prepareSigningFn({
|
|
1024
1050
|
spec, workdir: prep.tree, seedRef: seedRef, timeoutMs,
|
|
1025
|
-
shellCapUsd: spec.budgetUsd,
|
|
1026
|
-
judgeLoop: judgeProvider ? (o) => defaultJudgeLoop({ provider: judgeProvider, system: o.system, rates: judgePrice?.rates ?? null, thinking: spec.thinking === true }) : null,
|
|
1027
|
-
judgeModel: judge?.model ?? null,
|
|
1028
|
-
onJudgeCost: (c) => onCall({ label: `${c.label}:${c.id}`, costUsd: c.costUsd, unpricedRounds: c.unpricedRounds }),
|
|
1051
|
+
shellCapUsd: spec.budgetUsd,
|
|
1029
1052
|
});
|
|
1030
1053
|
const signingFile = join(outDir, 'signing.json');
|
|
1031
1054
|
writeFileSync(signingFile, `${JSON.stringify(signing, null, 2)}\n`);
|
|
1032
|
-
// The `calibrating` line is the rubric phase the person watched; its ✓ was set long before the gate graded
|
|
1033
|
-
// anything. Once the gate has a result, the line says THAT, on its own line (hamr, 2026-10-09).
|
|
1034
|
-
const calSum = calibrationSummary(signing.gates?.calibration);
|
|
1035
|
-
const calStep = latestStep(state.steps, 'calibrate');
|
|
1036
|
-
if (calSum && calStep) {
|
|
1037
|
-
calStep.status = calSum.ok ? 'done' : 'failed';
|
|
1038
|
-
calStep.detail = calSum.note;
|
|
1039
|
-
logSteps();
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
1055
|
if (!signing.ok) {
|
|
1043
1056
|
// plain words for the person (src/authorreadout.js, the one owner the CLI prints too); the full reds go into
|
|
1044
1057
|
// the drafting log on the failed step, so the cause survives the session
|
|
@@ -1048,7 +1061,7 @@ export function createSession(card, deps = {}) {
|
|
|
1048
1061
|
reds: redsRecord(signing.reds ?? [], { signing: true }), at: new Date().toISOString(),
|
|
1049
1062
|
});
|
|
1050
1063
|
refuse(signingStopText({
|
|
1051
|
-
reds: signing.reds ?? [], refusal: signing.refusal,
|
|
1064
|
+
reds: signing.reds ?? [], refusal: signing.refusal, noCheck: hasBuiltCheck === false,
|
|
1052
1065
|
spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete },
|
|
1053
1066
|
}));
|
|
1054
1067
|
return;
|
|
@@ -1114,19 +1127,13 @@ export function createSession(card, deps = {}) {
|
|
|
1114
1127
|
|
|
1115
1128
|
/** @type {Record<string, string>} */
|
|
1116
1129
|
const answers = { 1: renderJobLines(jobLines) };
|
|
1117
|
-
if (verdictType === 'soft-green') answers[SOFTGREEN_JUDGE_EXAMPLES_KEY] = renderExamples(jobLines);
|
|
1118
|
-
// a rubric job on files holds no judged part in this build, so the PASS/FAIL examples are not required of it
|
|
1119
1130
|
const required = RUBRIC_FILES ? [1] : requiredAnswersFor(verdictType);
|
|
1120
1131
|
for (const n of required) {
|
|
1121
1132
|
if (!answers[n]) { refuse(`the ${verdictType} check type needs ${required.length} answers and one is missing (key ${n})`); return; }
|
|
1122
1133
|
}
|
|
1123
1134
|
|
|
1124
|
-
const draftJudge = (() => {
|
|
1125
|
-
try { return resolveJobJudge(draft, modelChoice.provider, resolveWorkerModel); } catch { return { provider: modelChoice.provider, model: modelChoice.name }; }
|
|
1126
|
-
})();
|
|
1127
1135
|
const { provider } = buildRunnerProviders({
|
|
1128
1136
|
providerName: modelChoice.provider, apiKey, model: MODEL, baseUrl: modelChoice.baseUrl, legacyMaxTokens: modelChoice.legacyMaxTokens,
|
|
1129
|
-
judgeApiKey: apiKey, judgeModel: MODEL, judgeProviderName: modelChoice.provider, judgeBaseUrl: modelChoice.baseUrl,
|
|
1130
1137
|
});
|
|
1131
1138
|
// TEST SEAMS (see the constructor's own note): a test overrides
|
|
1132
1139
|
// `generate`/`confirmGenerate` directly (bypassing this real, constructed
|
|
@@ -1136,9 +1143,13 @@ export function createSession(card, deps = {}) {
|
|
|
1136
1143
|
// no NEW model call starts after an abandon; a call already in flight books its usage via onCall and is discarded
|
|
1137
1144
|
const noCallAfterAbandon = (fn) => (...a) => { if (abandoned) throw new Error('abandoned — no new model call'); return fn(...a); };
|
|
1138
1145
|
const generate = noCallAfterAbandon(deps.generate ?? makeLoopGenerate(provider, { rates: draftPrice?.rates ?? null, draftThinking }));
|
|
1139
|
-
const confirmGenerate = noCallAfterAbandon(deps.confirmGenerate ?? makeLoopGenerate(provider, { system:
|
|
1146
|
+
const confirmGenerate = noCallAfterAbandon(deps.confirmGenerate ?? makeLoopGenerate(provider, { system: confirmSystemFor(RUBRIC_FILES ? RUBRIC_LANG : ''), rates: draftPrice?.rates ?? null, draftThinking }));
|
|
1140
1147
|
// 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`
|
|
1141
1148
|
const pickGenerate = deps.pickGenerate !== undefined ? deps.pickGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: SUGGEST_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1149
|
+
// 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`
|
|
1150
|
+
const ledgerGenerate = deps.ledgerGenerate !== undefined ? deps.ledgerGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: LEDGER_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1151
|
+
// 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
|
|
1152
|
+
const editGenerate = deps.editGenerate !== undefined ? deps.editGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: ROW_EDIT_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1142
1153
|
|
|
1143
1154
|
// R7b (3), hamr's option A: the drafting AI POINTS when a job line's file to change lies outside Destination; code checks the claim (src/destpoint.js) and asks ONE typed
|
|
1144
1155
|
// yes/no question through the same `ask` as the fit check's "go on". "yes" sets the fence (below) AND this session's card Destination (the page re-fills its box from it);
|
|
@@ -1156,19 +1167,23 @@ export function createSession(card, deps = {}) {
|
|
|
1156
1167
|
if (pointed.state === 'point' && pointed.point) {
|
|
1157
1168
|
const question = destQuestionText(pointed.point, card.destination);
|
|
1158
1169
|
let said = null;
|
|
1170
|
+
let typedDest = '';
|
|
1159
1171
|
while (said === null) {
|
|
1160
|
-
const a = await ask({ kind: 'answer', source: 'dest-point', index: 1, total: 1, question, line: pointed.point.line });
|
|
1172
|
+
const a = await ask({ kind: 'answer', source: 'dest-point', index: 1, total: 1, question, line: pointed.point.line, folder: pointed.point.folder, current: card.destination });
|
|
1161
1173
|
if (a === null) return;
|
|
1174
|
+
// a typed Destination (the question box's own words, already checked at $0 by `send`) is taken as typed; buttons and old words say yes or no
|
|
1175
|
+
if (takeChoice() === 'path') { said = 'typed'; typedDest = String(a).trim(); break; }
|
|
1162
1176
|
said = yesNoOf(a);
|
|
1163
1177
|
if (said === null) say('bot', 'Type yes or no.');
|
|
1164
1178
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1179
|
+
const newDest = said === 'typed' ? typedDest : pointed.point.folder;
|
|
1180
|
+
appendDraftLog(outDir, { kind: 'dest-answer', no: Math.max(0, state.steps.length - 1), answer: said, from: redactSecrets(card.destination), to: redactSecrets(newDest), at: new Date().toISOString() });
|
|
1181
|
+
if (said === 'yes' || said === 'typed') {
|
|
1182
|
+
card = { ...card, destination: newDest };
|
|
1183
|
+
writeScope = said === 'typed' ? newDest.split(/[,\n]/).map((x) => x.trim()).filter(Boolean) : [newDest];
|
|
1169
1184
|
draft.writeScope = writeScope;
|
|
1170
|
-
state.card = { ...state.card, destination:
|
|
1171
|
-
say('bot', `Destination is now ${
|
|
1185
|
+
state.card = { ...state.card, destination: newDest };
|
|
1186
|
+
say('bot', `Destination is now ${newDest}. Drafting.`);
|
|
1172
1187
|
} else say('bot', 'Destination stays as it is. Drafting.');
|
|
1173
1188
|
}
|
|
1174
1189
|
}
|
|
@@ -1178,6 +1193,19 @@ export function createSession(card, deps = {}) {
|
|
|
1178
1193
|
// ask path as every other (the chat box + Send); the answer is REQUIRED (a blank one asks again, there is no skip) and is
|
|
1179
1194
|
// added WORD FOR WORD as a `~` rule on the job line it names — never rewritten. The lines are mutated in place, so the
|
|
1180
1195
|
// signed `jobLines`, the answers text and the plan card all read the same words.
|
|
1196
|
+
/** 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) */
|
|
1197
|
+
const syncJobLines = (/** @type {any[]} */ lines, /** @type {string|null} */ say = null, /** @type {any} */ confirmed = null) => {
|
|
1198
|
+
// 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
|
|
1199
|
+
if (lines !== jobLines) jobLines.splice(0, jobLines.length, ...lines);
|
|
1200
|
+
draft.jobLines = signedJobLines(lines);
|
|
1201
|
+
// 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
|
|
1202
|
+
state.card = { ...state.card, jobText: jobBoxText(lines) };
|
|
1203
|
+
card = { ...card, jobText: state.card.jobText };
|
|
1204
|
+
answers[1] = renderJobLines(lines);
|
|
1205
|
+
if (say !== null) state.messages.push({ ...planMessage({ ...(confirmed ?? {}), ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, lines), text: say });
|
|
1206
|
+
};
|
|
1207
|
+
/** the answers message of a check-list ask, drawn once the list has rebuilt the lines @type {{say: string, confirmed: any}|null} */
|
|
1208
|
+
let pendingSay = null;
|
|
1181
1209
|
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) => {
|
|
1182
1210
|
if (o.dropped.length) appendDraftLog(outDir, { kind: 'questions-dropped', no: Math.max(0, state.steps.length - 1), dropped: o.dropped, at: new Date().toISOString() });
|
|
1183
1211
|
const total = o.questions.length;
|
|
@@ -1185,12 +1213,17 @@ export function createSession(card, deps = {}) {
|
|
|
1185
1213
|
const left = [];
|
|
1186
1214
|
/** 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}[]} */
|
|
1187
1215
|
const picks = [];
|
|
1216
|
+
/** the choices the check block applies (src/blockasks.js) @type {{key: string, choice: string, text: string}[]} */
|
|
1217
|
+
const choices = [];
|
|
1188
1218
|
for (let k = 0; k < total; k += 1) {
|
|
1189
1219
|
const q = o.questions[k];
|
|
1190
1220
|
let text = '';
|
|
1221
|
+
/** 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 */
|
|
1222
|
+
let via = null;
|
|
1191
1223
|
for (;;) {
|
|
1192
|
-
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 });
|
|
1224
|
+
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) } : {}) });
|
|
1193
1225
|
if (a === null) return null;
|
|
1226
|
+
via = takeChoice();
|
|
1194
1227
|
// one `~` line is one line: the person's own words, newlines folded to spaces, nothing else touched
|
|
1195
1228
|
text = String(a).replace(/\s*\n\s*/g, ' ').trim();
|
|
1196
1229
|
if (text) break;
|
|
@@ -1200,43 +1233,44 @@ export function createSession(card, deps = {}) {
|
|
|
1200
1233
|
// 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
|
|
1201
1234
|
// bound is now the person's own words); anything else typed is the person's own rule, word for word.
|
|
1202
1235
|
// F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
|
|
1203
|
-
|
|
1204
|
-
if (q.source === 'look' &&
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1236
|
+
// 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"
|
|
1237
|
+
if (q.source === 'look' && via === null) text = stripAgreeLead(text);
|
|
1238
|
+
const agrees = via === 'agree' || (via === null && isAgree(text));
|
|
1239
|
+
const dropsIt = via === 'drop' || (via === null && isDropIt(text));
|
|
1240
|
+
if (q.source === 'look' && q.ask === 'reading' && typeof q.reading === 'string' && agrees) text = q.reading;
|
|
1241
|
+
// 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
|
|
1242
|
+
const canAgree = q.source === 'look' && ((q.ask === 'reading' && typeof q.reading === 'string') || (q.ask === 'check' && q.check !== undefined && q.check !== null));
|
|
1243
|
+
const canDrop = q.source === 'look' && (q.ask === 'cant-check' || q.ask === 'no-check' || q.ask === 'check') && Number.isInteger(q.rule);
|
|
1244
|
+
if (typeof (/** @type {any} */ (q)).key === 'string') choices.push({ key: /** @type {any} */ (q).key, choice: canDrop && dropsIt ? 'drop' : canAgree && agrees ? 'agree' : 'rule', text });
|
|
1245
|
+
if (q.source === 'look' && q.ask === 'cant-check' && Number.isInteger(q.rule) && dropsIt) { left.push({ line: q.line, rule: /** @type {number} */ (q.rule) }); continue; }
|
|
1246
|
+
// 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; anything else
|
|
1247
|
+
// is the person's own words, which replace the asked rule word for word (no check unless the words are the check: they judge it at Accept)
|
|
1208
1248
|
const isPick = q.source === 'look' && (q.ask === 'check' || q.ask === 'no-check') && Number.isInteger(q.rule);
|
|
1209
|
-
|
|
1210
|
-
const pair = isPick && Number.isInteger(/** @type {any} */ (q).pairRule) ? /** @type {number} */ (/** @type {any} */ (q).pairRule) : null;
|
|
1211
|
-
if (isPick && isDropIt(text)) { 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; }
|
|
1249
|
+
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; }
|
|
1212
1250
|
if (isPick) {
|
|
1213
|
-
const agreed = q.ask === 'check' && q.check &&
|
|
1251
|
+
const agreed = q.ask === 'check' && q.check && agrees;
|
|
1214
1252
|
if (agreed) text = plainWords(/** @type {any} */ (q.check));
|
|
1215
1253
|
if (agreed) pickedSoFar.push({ line: q.line, text: plainWords(/** @type {any} */ (q.check)) });
|
|
1216
|
-
picks.push({ line: q.line, rule:
|
|
1254
|
+
picks.push({ line: q.line, rule: /** @type {number} */ (q.rule), check: agreed ? /** @type {any} */ (q.check) : null, ...(agreed ? {} : { own: true }) });
|
|
1217
1255
|
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() });
|
|
1218
1256
|
}
|
|
1257
|
+
// 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`).
|
|
1258
|
+
// 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.
|
|
1219
1259
|
const line = jobLines.find((l) => l.n === q.line);
|
|
1220
|
-
if (
|
|
1221
|
-
else if (line) { line.rule = line.rule ? `${line.rule}; ${text}` : text; line.rules.push(text); }
|
|
1260
|
+
if (q.source !== 'look' && line) { line.rule = line.rule ? `${line.rule}; ${text}` : text; line.rules.push(text); }
|
|
1222
1261
|
}
|
|
1223
|
-
|
|
1224
|
-
//
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
return { jobLines, answers, left, picks };
|
|
1262
|
+
const said = left.length === total ? 'Noted: those stay Not checked. Drafting.' : 'Your answers are in on those job lines. Drafting again.';
|
|
1263
|
+
// 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
|
|
1264
|
+
if (o.questions.every((q) => typeof (/** @type {any} */ (q)).key === 'string')) pendingSay = { say: said, confirmed: o.confirmed };
|
|
1265
|
+
else syncJobLines(jobLines, said, o.confirmed);
|
|
1266
|
+
return { jobLines, answers, left, picks, choices };
|
|
1229
1267
|
};
|
|
1230
1268
|
|
|
1231
|
-
//
|
|
1232
|
-
const
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
if (String(a).trim()) return String(a);
|
|
1237
|
-
say('bot', 'An answer is needed here — there is no skip. Type it in the box below and press Send.');
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1269
|
+
// 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`
|
|
1270
|
+
const noteFn = deps.noteFn !== undefined ? deps.noteFn : (deps.generate ? null : (/** @type {any} */ o) => runNoteAsk({
|
|
1271
|
+
...o, provider, ...(draftPrice?.rates ? { rates: draftPrice.rates } : {}),
|
|
1272
|
+
...(Object.keys(thinkingCallOptions(provider, draftThinking)).length ? { callOptions: thinkingCallOptions(provider, draftThinking) } : {}),
|
|
1273
|
+
}));
|
|
1240
1274
|
|
|
1241
1275
|
state.phase = 'drafting';
|
|
1242
1276
|
// no early "drafting" line: the real author phase (PHASE_STEP) starts it, carrying draftDetail (see onPhase)
|
|
@@ -1244,7 +1278,6 @@ export function createSession(card, deps = {}) {
|
|
|
1244
1278
|
// the internal resolved tier model string (MODEL) or the raw provider
|
|
1245
1279
|
// name — the same id the Model field's own dropdown showed.
|
|
1246
1280
|
const authored = await authorCloseForJob({
|
|
1247
|
-
judgeModel: draftJudge.model,
|
|
1248
1281
|
answers, verdictType, repoPath: prep.tree, lang: LANG,
|
|
1249
1282
|
questions: questionsFor(verdictType),
|
|
1250
1283
|
jobLines, inputs: INPUTS,
|
|
@@ -1253,10 +1286,11 @@ export function createSession(card, deps = {}) {
|
|
|
1253
1286
|
rates: draftPrice?.rates ?? null,
|
|
1254
1287
|
draftThinking,
|
|
1255
1288
|
onPhase, onCall,
|
|
1256
|
-
ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, carriedPicks,
|
|
1289
|
+
ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, ledgerGenerate, noteFn, onJobLines: (/** @type {any[]} */ lines) => { const p = pendingSay; pendingSay = null; syncJobLines(lines, p ? p.say : null, p ? p.confirmed : null); }, editGenerate, carriedPicks, carriedChoices,
|
|
1290
|
+
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 */ } },
|
|
1257
1291
|
// 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
|
|
1258
1292
|
onPicks: (/** @type {{entries: any[], kept: {line: number, rule: number, entry: any}[]}} */ o) => {
|
|
1259
|
-
try {
|
|
1293
|
+
try { writeRecordPart(join(outDir, RECORD_FILE), { picks: o.entries }); } catch { /* the record is a convenience: a disk fault only means the next draft asks again */ }
|
|
1260
1294
|
for (const k of o.kept) {
|
|
1261
1295
|
if (k.entry.check) pickedSoFar.push({ line: k.line, text: `${plainWords(/** @type {any} */ (k.entry.check))} \u00B7 ${KEPT_WORDS}` });
|
|
1262
1296
|
appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: k.line, rule: k.rule, ruleText: redactSecrets(String(k.entry.ruleText ?? '')), how: KEPT_WORDS, ...(k.entry.check ? { picked: k.entry.check } : {}), ...(k.entry.left ? { left: true } : {}), ...(k.entry.own ? { own: true } : {}), at: new Date().toISOString() });
|
|
@@ -1265,31 +1299,11 @@ export function createSession(card, deps = {}) {
|
|
|
1265
1299
|
...(deps.scout ? { scout: deps.scout } : {}),
|
|
1266
1300
|
// PART 1c: a test that replaces the model boundary (`generate`) must not reach the real paid look; `deps.lookFn` brings its own
|
|
1267
1301
|
...(deps.lookFn !== undefined ? { lookFn: deps.lookFn } : (deps.generate ? { lookFn: null } : {})),
|
|
1268
|
-
// 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
|
|
1269
|
-
fitAsk, onFit,
|
|
1270
|
-
...(deps.fitFn !== undefined ? { fitFn: deps.fitFn } : (deps.generate ? { fitFn: null } : {})),
|
|
1271
1302
|
...(authorFnOverride ? { authorFn: authorFnOverride } : {}),
|
|
1272
1303
|
// R5 (piece 2): a Tickets job's drafter is told about the ticket filter and may propose one (the person signs it)
|
|
1273
1304
|
...(deps.flow?.flowType === 'tickets' ? { authorOpts: { ticket: true } } : {}),
|
|
1274
1305
|
});
|
|
1275
1306
|
|
|
1276
|
-
if (!authored.ok && PLAIN_PROPOSAL_STOPS.includes(String(authored.stop))) {
|
|
1277
|
-
// a refused rubric proposal: the person gets the reason in plain words (src/authorreadout.js, the one owner the
|
|
1278
|
-
// CLI prints too), and the full reds go into the drafting log on the failed step so the cause survives the session
|
|
1279
|
-
const cases = authored.judged?.signed?.cases ?? authored.judged?.proposal?.proposal?.cases ?? null;
|
|
1280
|
-
const reds = authored.reds ?? [];
|
|
1281
|
-
const runningNo = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
|
|
1282
|
-
appendDraftLog(outDir, {
|
|
1283
|
-
kind: 'step-reds', no: runningNo === -1 ? state.steps.length - 1 : runningNo, stop: authored.stop,
|
|
1284
|
-
reds: redsRecord(reds, { cases }), at: new Date().toISOString(),
|
|
1285
|
-
});
|
|
1286
|
-
refuse(proposalStopText({
|
|
1287
|
-
stop: String(authored.stop), reds, cases,
|
|
1288
|
-
spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete },
|
|
1289
|
-
source: authored.judged?.source === 'signer' ? 'signer' : 'proposal',
|
|
1290
|
-
}));
|
|
1291
|
-
return;
|
|
1292
|
-
}
|
|
1293
1307
|
if (!authored.ok) {
|
|
1294
1308
|
// ITEM 6 (P7): every drafting stop says WHY in plain words (the reds travel into the drafting log beside it) — the bare
|
|
1295
1309
|
// "Stopped: provider-red" of live session smv2bzdqmp0f8 carried a code and no reason.
|
|
@@ -1310,28 +1324,25 @@ export function createSession(card, deps = {}) {
|
|
|
1310
1324
|
else if (authored.confirmed?.goal) draft.goal = redactSecrets(String(authored.confirmed.goal));
|
|
1311
1325
|
// 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.
|
|
1312
1326
|
const spec = signFlow(assembleSpec(draft, { ...authored, verdictType: /** @type {string} */ (authored.verdictType) }), deps.flow?.flowType ?? 'plain', deps.flow?.pick ?? null, authored.authoring?.ticketFilter);
|
|
1313
|
-
// PART 1a (run mv5bk400): the
|
|
1314
|
-
// "lists 3 releases" in its notes, so the card promised a check the close never ran. The card AFTER drafting is now built
|
|
1315
|
-
// from the close itself, and every confirmed check no part carries out is moved to Not checked, in code, before signing.
|
|
1327
|
+
// PART 1a (run mv5bk400): the card AFTER drafting is built from the signed close itself (cardOfClose), never from what the confirm turn planned.
|
|
1316
1328
|
if (RUBRIC_FILES) {
|
|
1317
|
-
const rec =
|
|
1318
|
-
confirmed: authored.confirmed?.checkItems ?? [], notChecked: authored.confirmed?.notChecked ?? [], closeDecl: spec.closeDecl, jobLines,
|
|
1319
|
-
});
|
|
1329
|
+
const rec = cardOfClose({ closeDecl: spec.closeDecl, jobLines, ledger: readDraftLedger(outDir) });
|
|
1320
1330
|
// 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)
|
|
1321
1331
|
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() });
|
|
1332
|
+
// F-b (hamr 2026-11-13): a suggestion code could not build is not on the card; it is one plain sentence in the Audit's draft lines
|
|
1333
|
+
appendDraftLog(outDir, { kind: 'draft-notbuilt', no: Math.max(0, state.steps.length - 1), rows: (Array.isArray(authored.notBuilt) ? authored.notBuilt : []).map((/** @type {any} */ x) => ({ line: x.line, text: redactSecrets(String(x.text)) })), at: new Date().toISOString() });
|
|
1322
1334
|
// R10: the checks the person picked, for the plan card's "You picked" rows (the check rows and the Not checked rows come from the signed close itself)
|
|
1323
|
-
const
|
|
1324
|
-
|
|
1325
|
-
state.finalPlan = { goal: String(draft.goal ?? ''), checkItems: rec.checkItems, picked, notChecked: rec.notChecked, protections: authored.confirmed?.protections ?? [], moved: rec.moved, signedFacts: signedFactNames(spec.closeDecl), ...(spec.ticketFilter ? { ticketFilter: spec.ticketFilter } : {}) };
|
|
1335
|
+
const picked = Array.isArray(authored.picked) ? authored.picked : [];
|
|
1336
|
+
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 } : {}) };
|
|
1326
1337
|
}
|
|
1327
|
-
await finish(spec, authored.seedRef);
|
|
1338
|
+
await finish(spec, authored.seedRef, authored.hasBuiltCheck ?? null);
|
|
1328
1339
|
if (state.finalPlan && state.phase === 'prepared') {
|
|
1329
1340
|
// The confirm turn's plan bubble (and a try-3 "answers are in" one) is the DRAFTER's wording of the checks, written before
|
|
1330
1341
|
// any close existed. Once the close is signed-ready its card is the only plan the person sees: the earlier ones are
|
|
1331
1342
|
// dropped, so drafter prose can never sit above (and be read instead of) the code's sentences (run mv5e1ktb).
|
|
1332
1343
|
state.messages = state.messages.filter((/** @type {any} */ m) => m.kind !== 'plan');
|
|
1333
1344
|
state.messages.push({
|
|
1334
|
-
...planMessage({ checkItems: state.finalPlan.checkItems, checks: state.finalPlan.checkItems.map((/** @type {any} */ c) => c.text), notChecked: state.finalPlan.notChecked, protections: state.finalPlan.protections, signedFacts: state.finalPlan.signedFacts, picked: state.finalPlan.picked, ticketFilter: state.finalPlan.ticketFilter, questions: [] }, jobLines),
|
|
1345
|
+
...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),
|
|
1335
1346
|
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.',
|
|
1336
1347
|
});
|
|
1337
1348
|
}
|
|
@@ -1347,11 +1358,26 @@ export function createSession(card, deps = {}) {
|
|
|
1347
1358
|
return {
|
|
1348
1359
|
id,
|
|
1349
1360
|
state,
|
|
1350
|
-
/** @param {string} text */
|
|
1351
|
-
send: (text) => {
|
|
1361
|
+
/** @param {string} text @param {unknown} [choice] the button used in the question box (`agree`, `drop`, `rule`); absent = the words reading (the CLI's way, old pages) */
|
|
1362
|
+
send: (text, choice) => {
|
|
1352
1363
|
if (!state.pendingAsk) return { ok: false, error: 'nothing is being asked right now' };
|
|
1353
1364
|
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' };
|
|
1354
1365
|
if (state.pendingAsk.kind === 'install-needed') return { ok: false, error: 'install the packages, then click Check again — nothing to send here' };
|
|
1366
|
+
if (choice !== undefined) {
|
|
1367
|
+
// 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.
|
|
1368
|
+
const no = refuseChoice(state.pendingAsk, choice);
|
|
1369
|
+
if (no !== null) return { ok: false, refused: 'bad-choice', error: no };
|
|
1370
|
+
const r = resolveChoice(choice, text);
|
|
1371
|
+
if ('error' in r) return { ok: false, refused: 'blank-answer', error: r.error };
|
|
1372
|
+
// a typed Destination goes through the SAME $0 check the card's Destination does, before it is taken; a refusal keeps the question open with that check's own words
|
|
1373
|
+
if (choice === 'path') {
|
|
1374
|
+
const problem = startDestinationProblem({ inputs: card.inputs, destination: r.value, checkType: card.checkType });
|
|
1375
|
+
if (problem !== null) return { ok: false, refused: 'bad-destination', error: problem };
|
|
1376
|
+
}
|
|
1377
|
+
say('you', r.shown);
|
|
1378
|
+
answer(r.value, /** @type {string} */ (choice));
|
|
1379
|
+
return { ok: true };
|
|
1380
|
+
}
|
|
1355
1381
|
say('you', text);
|
|
1356
1382
|
answer(text);
|
|
1357
1383
|
return { ok: true };
|
|
@@ -1366,6 +1392,7 @@ export function createSession(card, deps = {}) {
|
|
|
1366
1392
|
dropWorktree();
|
|
1367
1393
|
state.error = 'Abandoned by you — money already spent stays booked.';
|
|
1368
1394
|
state.pendingAsk = null;
|
|
1395
|
+
closeOpenMsg();
|
|
1369
1396
|
if (resolvePending) { const r = resolvePending; resolvePending = null; r(null); }
|
|
1370
1397
|
if (resolveDepsCheck) { const r = resolveDepsCheck; resolveDepsCheck = null; r(); }
|
|
1371
1398
|
return { ok: true };
|
|
@@ -1379,6 +1406,24 @@ export function createSession(card, deps = {}) {
|
|
|
1379
1406
|
r();
|
|
1380
1407
|
return { ok: true };
|
|
1381
1408
|
},
|
|
1409
|
+
/**
|
|
1410
|
+
* Drop or Add on the confirm card (hamr 2026-11-13, N-2): an instant row edit through the live check block. $0: no model call, no new draft. The block reconciles the whole list; a refusal is plain
|
|
1411
|
+
* words and changes nothing. On success the plan bubble is drawn again from the rows and the person's choices are kept for a Revise.
|
|
1412
|
+
* @param {unknown} op @param {unknown} key @returns {{ok: true}|{ok: false, error: string, refused?: string}}
|
|
1413
|
+
*/
|
|
1414
|
+
rowEdit: (op, key) => {
|
|
1415
|
+
if (!state.pendingAsk || state.pendingAsk.kind !== 'menu' || planEdit === null) return { ok: false, refused: 'no-plan', error: 'no plan is waiting where checks can be dropped or added right now' };
|
|
1416
|
+
if (op !== 'drop' && op !== 'add') return { ok: false, refused: 'bad-choice', error: 'not one of the choices' };
|
|
1417
|
+
const r = planEdit(op, String(key ?? ''));
|
|
1418
|
+
if (!r.ok) return { ok: false, refused: 'bad-row', error: String(r.why) };
|
|
1419
|
+
const at = state.messages.findLastIndex((/** @type {any} */ m) => m.kind === 'plan');
|
|
1420
|
+
const msg = planMessage({ ...r.plan, ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, jobLines);
|
|
1421
|
+
if (at === -1) state.messages.push(msg); else state.messages[at] = msg;
|
|
1422
|
+
state.pendingAsk = { ...state.pendingAsk, plan: r.plan };
|
|
1423
|
+
if (Array.isArray(r.choices)) { try { writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: r.choices }); } catch { /* a convenience */ } }
|
|
1424
|
+
appendDraftLog(outDir, { kind: 'row-edit', no: Math.max(0, state.steps.length - 1), op, key: redactSecrets(String(key)), at: new Date().toISOString() });
|
|
1425
|
+
return { ok: true };
|
|
1426
|
+
},
|
|
1382
1427
|
/** click 1 — the confirm pick. Never signs on its own. */
|
|
1383
1428
|
signPrepare: () => {
|
|
1384
1429
|
if (!state.pendingAsk || state.pendingAsk.kind !== 'menu') return { ok: false, error: 'no plan is waiting for a decision right now' };
|