bareloop 0.55.0 → 0.56.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 +47 -0
- package/bareloop.context.md +4 -2
- package/package.json +2 -2
- package/src/authorflow.js +141 -264
- package/src/authoring.js +2 -3
- package/src/authorjob.js +117 -88
- package/src/authorreadout.js +9 -15
- package/src/authorrun.js +13 -4
- package/src/behaviour.js +14 -0
- package/src/blockasks.js +43 -0
- package/src/checkblock.js +772 -0
- package/src/checklist.js +128 -0
- package/src/checkpick.js +30 -312
- package/src/checkwords.js +3 -1
- package/src/declaredclose.js +30 -1
- package/src/destpoint.js +3 -1
- package/src/draftspend.js +46 -0
- package/src/facts.js +8 -1
- package/src/fitcheck.js +5 -3
- package/src/pagemap.js +15 -3
- package/src/panel/authorroutes.js +15 -3
- package/src/panel/authorsession.js +133 -46
- package/src/panel/index.html +194 -22
- package/src/panel/jobplan.js +85 -33
- package/src/panel/server.js +52 -7
- package/src/pickrecord.js +19 -1
- package/src/placerule.js +355 -0
- package/src/promptregisters.js +11 -0
- package/src/questionbox.js +112 -0
- package/src/rowedit.js +115 -0
- package/src/rubricstep.js +212 -125
- package/src/run.js +10 -2
- package/src/userrun.js +46 -1
- package/types/authorflow.d.ts +32 -139
- package/types/authorjob.d.ts +24 -6
- package/types/authorreadout.d.ts +4 -10
- package/types/behaviour.d.ts +12 -0
- package/types/blockasks.d.ts +37 -0
- package/types/checkblock.d.ts +361 -0
- package/types/checklist.d.ts +134 -0
- package/types/checkpick.d.ts +3 -140
- package/types/declaredclose.d.ts +4 -0
- package/types/destpoint.d.ts +2 -0
- package/types/draftspend.d.ts +21 -0
- package/types/fitcheck.d.ts +7 -1
- package/types/pagemap.d.ts +4 -0
- package/types/panel/authorsession.d.ts +13 -2
- package/types/panel/jobgrid.d.ts +8 -8
- package/types/panel/jobplan.d.ts +48 -10
- package/types/panel/server.d.ts +14 -13
- package/types/pickrecord.d.ts +12 -0
- package/types/placerule.d.ts +194 -0
- package/types/questionbox.d.ts +87 -0
- package/types/rowedit.d.ts +32 -0
- package/types/rubricstep.d.ts +91 -48
- package/types/run.d.ts +10 -1
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
import { prepareSigning } from '../authorjob.js';
|
|
43
43
|
import { checkCloseByteSignature } from '../close-integrity.js';
|
|
44
44
|
import {
|
|
45
|
-
questionsFor, requiredAnswersFor, makeLoopGenerate,
|
|
45
|
+
questionsFor, requiredAnswersFor, makeLoopGenerate, confirmSystemFor, SOFTGREEN_JUDGE_EXAMPLES_KEY,
|
|
46
46
|
} from '../authorflow.js';
|
|
47
47
|
import {
|
|
48
48
|
resolveProvider, buildRunnerProviders, apiKeyProblem,
|
|
@@ -51,25 +51,28 @@ import { resolveJobJudge, defaultJudgeLoop } from '../judged.js';
|
|
|
51
51
|
import { assertThinkingMode, thinkingPlanFor, thinkingRowText, thinkingCallOptions } from '../thinking.js';
|
|
52
52
|
import { closeJudges } from '../kinds.js';
|
|
53
53
|
import { RUBRIC_LANG } from '../authoring.js';
|
|
54
|
-
import { rubricGoal,
|
|
54
|
+
import { rubricGoal, cardOfClose, signedFactNames } from '../rubricstep.js';
|
|
55
55
|
import { redactSecrets } from '../validate.js';
|
|
56
56
|
import { FLOW_TYPES } from '../job.js';
|
|
57
57
|
import { mcpPickFor, signFlow } from '../mcppick.js';
|
|
58
58
|
import { parseTicketList, ticketNumberOf, TICKET_NUMBER_WORDS } from '../ticketshape.js';
|
|
59
59
|
import { isDropIt, isAgree, stripAgreeLead } from '../pagemap.js';
|
|
60
|
-
import { plainWords, SUGGEST_SYSTEM,
|
|
61
|
-
import {
|
|
60
|
+
import { plainWords, SUGGEST_SYSTEM, sameRuleWords } from '../checkpick.js';
|
|
61
|
+
import { LEDGER_SYSTEM } from '../checklist.js';
|
|
62
|
+
import { ROW_EDIT_SYSTEM } from '../rowedit.js';
|
|
63
|
+
import { readRecordFile, readRowChoices, writeRecordPart, RECORD_FILE, KEPT_WORDS } from '../pickrecord.js';
|
|
62
64
|
import { MAX_REVISES, draftLabelOf, nextRevisesUsed, sessionsRootOf, writeRevisesUsed } from '../revises.js';
|
|
63
65
|
import { FIT_ABSENT_NOTE } from '../fitcheck.js';
|
|
64
66
|
import { runDestPoint, destQuestionText, yesNoOf } from '../destpoint.js';
|
|
65
67
|
import { tallyCalls } from '../text.js';
|
|
66
|
-
import { appendDraftLog } from '../draftspend.js';
|
|
68
|
+
import { appendDraftLog, readDraftLedger } from '../draftspend.js';
|
|
67
69
|
import { PLAIN_PROPOSAL_STOPS, proposalStopText, signingStopText, draftStopText, redsRecord, declarationRecord, calibrationSummary, tryRefusedText } from '../authorreadout.js';
|
|
68
70
|
import { runNpmCi, NPM_CI_LOCKS } from '../npminstall.js';
|
|
69
71
|
import {
|
|
70
72
|
parseJobBlock, parseInputs, jobBlockFitsCheck, renderJobLines, renderExamples, signedJobLines, jobBoxText,
|
|
71
73
|
} from '../jobblock.js';
|
|
72
74
|
import { planFromConfirm } from './jobplan.js';
|
|
75
|
+
import { boxFor, offersOf, panelQuestionText, refuseChoice, resolveChoice } from '../questionbox.js';
|
|
73
76
|
import { isTicketTrigger } from '../trigger.js';
|
|
74
77
|
import { ticketLookOf } from '../ticketschedule.js';
|
|
75
78
|
|
|
@@ -179,7 +182,7 @@ export const PLAN_FOOTER = 'Sign & run to confirm this plan, or Revise to edit t
|
|
|
179
182
|
* The confirm turn's plan as a chat message (P7): a STRUCTURED `{role:'bot', kind:'plan', plan}` the page draws with the
|
|
180
183
|
* same renderer the Job tab uses — each numbered job line, its `~` rule, its drafted checks folded; the AI's own "not
|
|
181
184
|
* 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
|
|
185
|
+
* @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
186
|
* @param {{n: number, text: string, rule: string}[]|null} jobLines
|
|
184
187
|
* @returns {{role: 'bot', kind: 'plan', text: string, plan: ReturnType<typeof planFromConfirm> & {goal: string, questions: string[]}}}
|
|
185
188
|
*/
|
|
@@ -473,7 +476,7 @@ export function validateJobCard(card, opts = {}) {
|
|
|
473
476
|
* `signPrepare()` are the only ways in.
|
|
474
477
|
* @param {any} card the validated job card (see {@link validateJobCard})
|
|
475
478
|
* @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,
|
|
479
|
+
* scout?: any, generate?: Function, pickGenerate?: Function|null, ledgerGenerate?: Function|null, editGenerate?: Function|null, carryFrom?: string, carryKind?: string, confirmGenerate?: Function, authorFn?: Function,
|
|
477
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
|
|
478
481
|
* TEST SEAMS ONLY — see the note just above where each is read, below. `reuse` (Reuse workflow) is NOT a seam: the
|
|
479
482
|
* caller (`/api/author/start`) sets it only when the server's own same-job rule held.
|
|
@@ -511,6 +514,10 @@ export function createSession(card, deps = {}) {
|
|
|
511
514
|
// 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
515
|
// (never a path); no record, or an unreadable one, is no record: every rule is asked.
|
|
513
516
|
const carriedPicks = typeof deps.carryFrom === 'string' && /^s[a-z0-9]+$/.test(deps.carryFrom) ? readRecordFile(join(sessionsRoot, deps.carryFrom, RECORD_FILE)) : null;
|
|
517
|
+
// hamr 2026-11-13 (N-2): the Drop/Add choices of that same earlier draft ride in the same record file
|
|
518
|
+
const carriedChoices = typeof deps.carryFrom === 'string' && /^s[a-z0-9]+$/.test(deps.carryFrom) ? readRowChoices(join(sessionsRoot, deps.carryFrom, RECORD_FILE)) : null;
|
|
519
|
+
/** 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} */
|
|
520
|
+
let planEdit = null;
|
|
514
521
|
|
|
515
522
|
// fwd M4e am14 item 3: the revises this draft has used (src/revises.js); the page reads `revisesLeft` to word its button
|
|
516
523
|
const revisesUsed = nextRevisesUsed(sessionsRoot, deps.carryFrom, deps.carryKind);
|
|
@@ -603,6 +610,13 @@ export function createSession(card, deps = {}) {
|
|
|
603
610
|
|
|
604
611
|
/** @param {'bot'|'you'|'system'} role @param {string} text */
|
|
605
612
|
const say = (role, text) => { state.messages.push({ role, text }); };
|
|
613
|
+
/** 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} */
|
|
614
|
+
let openMsg = null;
|
|
615
|
+
const sayOpen = (/** @type {string} */ text) => { openMsg = { role: 'bot', text, askOpen: true }; state.messages.push(openMsg); };
|
|
616
|
+
const closeOpenMsg = () => { if (openMsg) { delete openMsg.askOpen; openMsg = null; } };
|
|
617
|
+
/** 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} */
|
|
618
|
+
let answeredChoice = null;
|
|
619
|
+
const takeChoice = () => { const c = answeredChoice; answeredChoice = null; return c; };
|
|
606
620
|
/** a structured message (the plan bubble): the page draws it, the thread keeps it as data */
|
|
607
621
|
/** 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
622
|
const pickedSoFar = [];
|
|
@@ -636,27 +650,34 @@ export function createSession(card, deps = {}) {
|
|
|
636
650
|
const running = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
|
|
637
651
|
appendDraftLog(outDir, {
|
|
638
652
|
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(),
|
|
653
|
+
question: redactSecrets(step.question), answer: said, ...(answeredChoice === null ? {} : { choice: answeredChoice }), ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
|
|
640
654
|
});
|
|
641
655
|
}
|
|
642
656
|
resolveFn0(value);
|
|
643
657
|
};
|
|
644
|
-
|
|
658
|
+
const box = boxFor(step);
|
|
659
|
+
// the plan's Drop/Add door is a function: it never rides in `state` (that is JSON)
|
|
660
|
+
const { edit: stepEdit, ...stepPure } = step;
|
|
661
|
+
planEdit = typeof stepEdit === 'function' ? stepEdit : null;
|
|
662
|
+
state.pendingAsk = box === null ? stepPure : { ...stepPure, box };
|
|
645
663
|
resolvePending = resolveFn;
|
|
646
664
|
if (step.kind === 'language') say('bot', `${step.field?.prompt ?? 'Which language is this job about?'} (${(step.candidates ?? []).join(', ')})`);
|
|
647
665
|
else if (step.kind === 'menu') {
|
|
648
666
|
sayPlan(step.plan ?? {});
|
|
649
|
-
} else if (step.kind === 'answer' && (step.source === 'fit-check' || step.source === 'dest-point'))
|
|
650
|
-
else if (step.kind === 'answer')
|
|
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))}`);
|
|
651
669
|
else if (step.kind === 'goal') say('bot', 'Type the goal sentence yourself.');
|
|
652
670
|
});
|
|
653
671
|
|
|
654
|
-
/** @param {string|null} value @returns {boolean} */
|
|
655
|
-
const answer = (value) => {
|
|
672
|
+
/** @param {string|null} value @param {string|null} [choice] the button used, when the answer came from the question box @returns {boolean} */
|
|
673
|
+
const answer = (value, choice = null) => {
|
|
656
674
|
if (!resolvePending) return false;
|
|
657
675
|
const r = resolvePending;
|
|
658
676
|
resolvePending = null;
|
|
659
677
|
state.pendingAsk = null;
|
|
678
|
+
planEdit = null;
|
|
679
|
+
closeOpenMsg();
|
|
680
|
+
answeredChoice = choice;
|
|
660
681
|
r(value);
|
|
661
682
|
return true;
|
|
662
683
|
};
|
|
@@ -688,6 +709,10 @@ export function createSession(card, deps = {}) {
|
|
|
688
709
|
// 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
710
|
// progress line shows it briefly, in code's words
|
|
690
711
|
// PRD v1.131 tick 7: the retention counts of a rubric draft, one line when it ends (counts only, no words)
|
|
712
|
+
// 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`)
|
|
713
|
+
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() });
|
|
714
|
+
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
|
+
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
716
|
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
717
|
if (name === 'author-try-failed') {
|
|
693
718
|
lastTryRefused = true;
|
|
@@ -949,7 +974,7 @@ export function createSession(card, deps = {}) {
|
|
|
949
974
|
* the seed themselves.
|
|
950
975
|
* @param {any} spec @param {string|null} seedRef
|
|
951
976
|
*/
|
|
952
|
-
const finish = async (spec, seedRef) => {
|
|
977
|
+
const finish = async (spec, seedRef, hasBuiltCheck = /** @type {boolean|null} */ (null)) => {
|
|
953
978
|
if (abandoned) return;
|
|
954
979
|
// 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
980
|
if (deps.schedule) {
|
|
@@ -991,6 +1016,13 @@ export function createSession(card, deps = {}) {
|
|
|
991
1016
|
return;
|
|
992
1017
|
}
|
|
993
1018
|
|
|
1019
|
+
// the end check: a rubric close with no real check never reaches the signing gates (R10, hamr 2026-11-10)
|
|
1020
|
+
// the check block says it (block.hasBuiltCheck(), carried out of drafting): a rubric run needs at least one built check
|
|
1021
|
+
const noCheck = hasBuiltCheck === false ? signingStopText({ reds: [], noCheck: true, spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete } }) : null;
|
|
1022
|
+
if (noCheck) {
|
|
1023
|
+
refuse(noCheck);
|
|
1024
|
+
return;
|
|
1025
|
+
}
|
|
994
1026
|
state.phase = 'signing-gates';
|
|
995
1027
|
stepStart('gates', 'gates 1–3 cost $0; gate 4 only for a rubric');
|
|
996
1028
|
const judges = closeJudges(spec.closeDecl);
|
|
@@ -1048,7 +1080,7 @@ export function createSession(card, deps = {}) {
|
|
|
1048
1080
|
reds: redsRecord(signing.reds ?? [], { signing: true }), at: new Date().toISOString(),
|
|
1049
1081
|
});
|
|
1050
1082
|
refuse(signingStopText({
|
|
1051
|
-
reds: signing.reds ?? [], refusal: signing.refusal,
|
|
1083
|
+
reds: signing.reds ?? [], refusal: signing.refusal, noCheck: hasBuiltCheck === false,
|
|
1052
1084
|
spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete },
|
|
1053
1085
|
}));
|
|
1054
1086
|
return;
|
|
@@ -1136,9 +1168,13 @@ export function createSession(card, deps = {}) {
|
|
|
1136
1168
|
// no NEW model call starts after an abandon; a call already in flight books its usage via onCall and is discarded
|
|
1137
1169
|
const noCallAfterAbandon = (fn) => (...a) => { if (abandoned) throw new Error('abandoned — no new model call'); return fn(...a); };
|
|
1138
1170
|
const generate = noCallAfterAbandon(deps.generate ?? makeLoopGenerate(provider, { rates: draftPrice?.rates ?? null, draftThinking }));
|
|
1139
|
-
const confirmGenerate = noCallAfterAbandon(deps.confirmGenerate ?? makeLoopGenerate(provider, { system:
|
|
1171
|
+
const confirmGenerate = noCallAfterAbandon(deps.confirmGenerate ?? makeLoopGenerate(provider, { system: confirmSystemFor(RUBRIC_FILES ? RUBRIC_LANG : ''), rates: draftPrice?.rates ?? null, draftThinking }));
|
|
1140
1172
|
// 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
1173
|
const pickGenerate = deps.pickGenerate !== undefined ? deps.pickGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: SUGGEST_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1174
|
+
// 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`
|
|
1175
|
+
const ledgerGenerate = deps.ledgerGenerate !== undefined ? deps.ledgerGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: LEDGER_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1176
|
+
// 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
|
+
const editGenerate = deps.editGenerate !== undefined ? deps.editGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: ROW_EDIT_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1142
1178
|
|
|
1143
1179
|
// 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
1180
|
// 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 +1192,23 @@ export function createSession(card, deps = {}) {
|
|
|
1156
1192
|
if (pointed.state === 'point' && pointed.point) {
|
|
1157
1193
|
const question = destQuestionText(pointed.point, card.destination);
|
|
1158
1194
|
let said = null;
|
|
1195
|
+
let typedDest = '';
|
|
1159
1196
|
while (said === null) {
|
|
1160
|
-
const a = await ask({ kind: 'answer', source: 'dest-point', index: 1, total: 1, question, line: pointed.point.line });
|
|
1197
|
+
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
1198
|
if (a === null) return;
|
|
1199
|
+
// 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
|
|
1200
|
+
if (takeChoice() === 'path') { said = 'typed'; typedDest = String(a).trim(); break; }
|
|
1162
1201
|
said = yesNoOf(a);
|
|
1163
1202
|
if (said === null) say('bot', 'Type yes or no.');
|
|
1164
1203
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1204
|
+
const newDest = said === 'typed' ? typedDest : pointed.point.folder;
|
|
1205
|
+
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() });
|
|
1206
|
+
if (said === 'yes' || said === 'typed') {
|
|
1207
|
+
card = { ...card, destination: newDest };
|
|
1208
|
+
writeScope = said === 'typed' ? newDest.split(/[,\n]/).map((x) => x.trim()).filter(Boolean) : [newDest];
|
|
1169
1209
|
draft.writeScope = writeScope;
|
|
1170
|
-
state.card = { ...state.card, destination:
|
|
1171
|
-
say('bot', `Destination is now ${
|
|
1210
|
+
state.card = { ...state.card, destination: newDest };
|
|
1211
|
+
say('bot', `Destination is now ${newDest}. Drafting.`);
|
|
1172
1212
|
} else say('bot', 'Destination stays as it is. Drafting.');
|
|
1173
1213
|
}
|
|
1174
1214
|
}
|
|
@@ -1185,12 +1225,17 @@ export function createSession(card, deps = {}) {
|
|
|
1185
1225
|
const left = [];
|
|
1186
1226
|
/** 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
1227
|
const picks = [];
|
|
1228
|
+
/** the choices the check block applies (src/blockasks.js) @type {{key: string, choice: string, text: string}[]} */
|
|
1229
|
+
const choices = [];
|
|
1188
1230
|
for (let k = 0; k < total; k += 1) {
|
|
1189
1231
|
const q = o.questions[k];
|
|
1190
1232
|
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 */
|
|
1234
|
+
let via = null;
|
|
1191
1235
|
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 });
|
|
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) } : {}) });
|
|
1193
1237
|
if (a === null) return null;
|
|
1238
|
+
via = takeChoice();
|
|
1194
1239
|
// one `~` line is one line: the person's own words, newlines folded to spaces, nothing else touched
|
|
1195
1240
|
text = String(a).replace(/\s*\n\s*/g, ' ').trim();
|
|
1196
1241
|
if (text) break;
|
|
@@ -1200,32 +1245,42 @@ export function createSession(card, deps = {}) {
|
|
|
1200
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
|
|
1201
1246
|
// bound is now the person's own words); anything else typed is the person's own rule, word for word.
|
|
1202
1247
|
// F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
|
|
1203
|
-
|
|
1204
|
-
if (q.source === 'look' &&
|
|
1205
|
-
|
|
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));
|
|
1252
|
+
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; }
|
|
1206
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
|
|
1207
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;
|
|
1208
1261
|
const isPick = q.source === 'look' && (q.ask === 'check' || q.ask === 'no-check') && Number.isInteger(q.rule);
|
|
1209
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
|
|
1210
1263
|
const pair = isPick && Number.isInteger(/** @type {any} */ (q).pairRule) ? /** @type {number} */ (/** @type {any} */ (q).pairRule) : null;
|
|
1211
|
-
if (isPick &&
|
|
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; }
|
|
1212
1265
|
if (isPick) {
|
|
1213
|
-
const agreed = q.ask === 'check' && q.check &&
|
|
1266
|
+
const agreed = q.ask === 'check' && q.check && agrees;
|
|
1214
1267
|
if (agreed) text = plainWords(/** @type {any} */ (q.check));
|
|
1268
|
+
agreedPick = agreed === true;
|
|
1215
1269
|
if (agreed) pickedSoFar.push({ line: q.line, text: plainWords(/** @type {any} */ (q.check)) });
|
|
1216
1270
|
picks.push({ line: q.line, rule: pair ?? /** @type {number} */ (q.rule), check: agreed ? /** @type {any} */ (q.check) : null, added: text, ...(agreed ? {} : { own: true }) });
|
|
1217
1271
|
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
1272
|
}
|
|
1219
1273
|
const line = jobLines.find((l) => l.n === q.line);
|
|
1220
1274
|
if (line && pair !== null) { line.rules[/** @type {number} */ (q.rule) - 1] = text; line.rule = line.rules.join('; '); }
|
|
1221
|
-
|
|
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); }
|
|
1222
1277
|
}
|
|
1223
1278
|
draft.jobLines = signedJobLines(jobLines);
|
|
1224
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
|
|
1225
1280
|
state.card = { ...state.card, jobText: jobBoxText(jobLines) };
|
|
1226
1281
|
answers[1] = renderJobLines(jobLines);
|
|
1227
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.' });
|
|
1228
|
-
return { jobLines, answers, left, picks };
|
|
1283
|
+
return { jobLines, answers, left, picks, choices };
|
|
1229
1284
|
};
|
|
1230
1285
|
|
|
1231
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)
|
|
@@ -1253,10 +1308,11 @@ export function createSession(card, deps = {}) {
|
|
|
1253
1308
|
rates: draftPrice?.rates ?? null,
|
|
1254
1309
|
draftThinking,
|
|
1255
1310
|
onPhase, onCall,
|
|
1256
|
-
ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, carriedPicks,
|
|
1311
|
+
ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, ledgerGenerate, editGenerate, carriedPicks, carriedChoices,
|
|
1312
|
+
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
1313
|
// 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
1314
|
onPicks: (/** @type {{entries: any[], kept: {line: number, rule: number, entry: any}[]}} */ o) => {
|
|
1259
|
-
try {
|
|
1315
|
+
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
1316
|
for (const k of o.kept) {
|
|
1261
1317
|
if (k.entry.check) pickedSoFar.push({ line: k.line, text: `${plainWords(/** @type {any} */ (k.entry.check))} \u00B7 ${KEPT_WORDS}` });
|
|
1262
1318
|
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() });
|
|
@@ -1310,28 +1366,25 @@ export function createSession(card, deps = {}) {
|
|
|
1310
1366
|
else if (authored.confirmed?.goal) draft.goal = redactSecrets(String(authored.confirmed.goal));
|
|
1311
1367
|
// 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
1368
|
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.
|
|
1369
|
+
// PART 1a (run mv5bk400): the card AFTER drafting is built from the signed close itself (cardOfClose), never from what the confirm turn planned.
|
|
1316
1370
|
if (RUBRIC_FILES) {
|
|
1317
|
-
const rec =
|
|
1318
|
-
confirmed: authored.confirmed?.checkItems ?? [], notChecked: authored.confirmed?.notChecked ?? [], closeDecl: spec.closeDecl, jobLines,
|
|
1319
|
-
});
|
|
1371
|
+
const rec = cardOfClose({ closeDecl: spec.closeDecl, jobLines, ledger: readDraftLedger(outDir) });
|
|
1320
1372
|
// 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
1373
|
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() });
|
|
1374
|
+
// 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
|
|
1375
|
+
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
1376
|
// 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 } : {}) };
|
|
1377
|
+
const picked = Array.isArray(authored.picked) ? authored.picked : [];
|
|
1378
|
+
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
1379
|
}
|
|
1327
|
-
await finish(spec, authored.seedRef);
|
|
1380
|
+
await finish(spec, authored.seedRef, authored.hasBuiltCheck ?? null);
|
|
1328
1381
|
if (state.finalPlan && state.phase === 'prepared') {
|
|
1329
1382
|
// 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
1383
|
// any close existed. Once the close is signed-ready its card is the only plan the person sees: the earlier ones are
|
|
1331
1384
|
// dropped, so drafter prose can never sit above (and be read instead of) the code's sentences (run mv5e1ktb).
|
|
1332
1385
|
state.messages = state.messages.filter((/** @type {any} */ m) => m.kind !== 'plan');
|
|
1333
1386
|
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),
|
|
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),
|
|
1335
1388
|
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
1389
|
});
|
|
1337
1390
|
}
|
|
@@ -1347,11 +1400,26 @@ export function createSession(card, deps = {}) {
|
|
|
1347
1400
|
return {
|
|
1348
1401
|
id,
|
|
1349
1402
|
state,
|
|
1350
|
-
/** @param {string} text */
|
|
1351
|
-
send: (text) => {
|
|
1403
|
+
/** @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) */
|
|
1404
|
+
send: (text, choice) => {
|
|
1352
1405
|
if (!state.pendingAsk) return { ok: false, error: 'nothing is being asked right now' };
|
|
1353
1406
|
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
1407
|
if (state.pendingAsk.kind === 'install-needed') return { ok: false, error: 'install the packages, then click Check again — nothing to send here' };
|
|
1408
|
+
if (choice !== undefined) {
|
|
1409
|
+
// 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
|
+
const no = refuseChoice(state.pendingAsk, choice);
|
|
1411
|
+
if (no !== null) return { ok: false, refused: 'bad-choice', error: no };
|
|
1412
|
+
const r = resolveChoice(choice, text);
|
|
1413
|
+
if ('error' in r) return { ok: false, refused: 'blank-answer', error: r.error };
|
|
1414
|
+
// 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
|
|
1415
|
+
if (choice === 'path') {
|
|
1416
|
+
const problem = startDestinationProblem({ inputs: card.inputs, destination: r.value, checkType: card.checkType });
|
|
1417
|
+
if (problem !== null) return { ok: false, refused: 'bad-destination', error: problem };
|
|
1418
|
+
}
|
|
1419
|
+
say('you', r.shown);
|
|
1420
|
+
answer(r.value, /** @type {string} */ (choice));
|
|
1421
|
+
return { ok: true };
|
|
1422
|
+
}
|
|
1355
1423
|
say('you', text);
|
|
1356
1424
|
answer(text);
|
|
1357
1425
|
return { ok: true };
|
|
@@ -1366,6 +1434,7 @@ export function createSession(card, deps = {}) {
|
|
|
1366
1434
|
dropWorktree();
|
|
1367
1435
|
state.error = 'Abandoned by you — money already spent stays booked.';
|
|
1368
1436
|
state.pendingAsk = null;
|
|
1437
|
+
closeOpenMsg();
|
|
1369
1438
|
if (resolvePending) { const r = resolvePending; resolvePending = null; r(null); }
|
|
1370
1439
|
if (resolveDepsCheck) { const r = resolveDepsCheck; resolveDepsCheck = null; r(); }
|
|
1371
1440
|
return { ok: true };
|
|
@@ -1379,6 +1448,24 @@ export function createSession(card, deps = {}) {
|
|
|
1379
1448
|
r();
|
|
1380
1449
|
return { ok: true };
|
|
1381
1450
|
},
|
|
1451
|
+
/**
|
|
1452
|
+
* 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
|
|
1453
|
+
* 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.
|
|
1454
|
+
* @param {unknown} op @param {unknown} key @returns {{ok: true}|{ok: false, error: string, refused?: string}}
|
|
1455
|
+
*/
|
|
1456
|
+
rowEdit: (op, key) => {
|
|
1457
|
+
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' };
|
|
1458
|
+
if (op !== 'drop' && op !== 'add') return { ok: false, refused: 'bad-choice', error: 'not one of the choices' };
|
|
1459
|
+
const r = planEdit(op, String(key ?? ''));
|
|
1460
|
+
if (!r.ok) return { ok: false, refused: 'bad-row', error: String(r.why) };
|
|
1461
|
+
const at = state.messages.findLastIndex((/** @type {any} */ m) => m.kind === 'plan');
|
|
1462
|
+
const msg = planMessage({ ...r.plan, ...(pickedSoFar.length ? { picked: [...pickedSoFar] } : {}) }, jobLines);
|
|
1463
|
+
if (at === -1) state.messages.push(msg); else state.messages[at] = msg;
|
|
1464
|
+
state.pendingAsk = { ...state.pendingAsk, plan: r.plan };
|
|
1465
|
+
if (Array.isArray(r.choices)) { try { writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: r.choices }); } catch { /* a convenience */ } }
|
|
1466
|
+
appendDraftLog(outDir, { kind: 'row-edit', no: Math.max(0, state.steps.length - 1), op, key: redactSecrets(String(key)), at: new Date().toISOString() });
|
|
1467
|
+
return { ok: true };
|
|
1468
|
+
},
|
|
1382
1469
|
/** click 1 — the confirm pick. Never signs on its own. */
|
|
1383
1470
|
signPrepare: () => {
|
|
1384
1471
|
if (!state.pendingAsk || state.pendingAsk.kind !== 'menu') return { ok: false, error: 'no plan is waiting for a decision right now' };
|