bareloop 0.57.0 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/bareloop.context.md +11 -8
- package/package.json +1 -1
- package/src/authorflow.js +50 -62
- package/src/authorjob.js +100 -30
- package/src/authorreadout.js +88 -0
- package/src/authorrun.js +63 -24
- package/src/authorscout.js +9 -1
- package/src/blockasks.js +11 -16
- package/src/checkblock.js +227 -31
- package/src/checkpick.js +0 -5
- package/src/declaredclose.js +38 -6
- package/src/draftspend.js +20 -4
- package/src/fencepointcall.js +76 -0
- package/src/guarddescriptions.js +14 -0
- package/src/kinds.js +5 -1
- package/src/pagemap.js +7 -29
- package/src/panel/authorroutes.js +6 -1
- package/src/panel/authorsession.js +108 -32
- package/src/panel/index.html +38 -13
- package/src/panel/jobplan.js +49 -16
- package/src/panel/server.js +66 -6
- package/src/planrun.js +2 -0
- package/src/promptregisters.js +5 -0
- package/src/questionbox.js +32 -20
- package/src/reviewdoor.js +1 -1
- package/src/rowresults.js +69 -0
- package/src/rubricstep.js +110 -22
- package/src/stagewords.js +24 -0
- package/types/authorflow.d.ts +42 -79
- package/types/authorjob.d.ts +3 -2
- package/types/authorreadout.d.ts +44 -0
- package/types/authorrun.d.ts +20 -0
- package/types/blockasks.d.ts +5 -10
- package/types/checkblock.d.ts +115 -11
- package/types/checkpick.d.ts +0 -3
- package/types/declaredclose.d.ts +3 -1
- package/types/draftspend.d.ts +16 -2
- package/types/fencepointcall.d.ts +68 -0
- package/types/guarddescriptions.d.ts +7 -0
- package/types/kinds.d.ts +1 -0
- package/types/pagemap.d.ts +2 -5
- package/types/panel/authorsession.d.ts +3 -2
- package/types/panel/jobplan.d.ts +13 -1
- package/types/panel/server.d.ts +41 -16
- package/types/questionbox.d.ts +20 -6
- package/types/rowresults.d.ts +23 -0
- package/types/rubricstep.d.ts +34 -7
- package/types/stagewords.d.ts +11 -0
package/src/draftspend.js
CHANGED
|
@@ -182,16 +182,32 @@ export function sessionDirForRow(row, opts = {}) {
|
|
|
182
182
|
return null;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
/**
|
|
186
|
+
* What an answered look question DECIDED, in one spelling for every view (the draft readout and the Audit drafting table): agreed / you wrote / dropped.
|
|
187
|
+
* `null` for any other answer, and for an old log row with no `words` (those keep the question-and-answer form).
|
|
188
|
+
* @param {{choice?: string, words?: string}} h
|
|
189
|
+
* @returns {string|null}
|
|
190
|
+
*/
|
|
191
|
+
export function decidedWords(h) {
|
|
192
|
+
if (h.choice === 'agree' && typeof h.words === 'string') return `agreed \u2014 ${h.words}`;
|
|
193
|
+
if (h.choice === 'rule' && typeof h.words === 'string') return `you wrote \u2014 ${h.words}`;
|
|
194
|
+
if (h.choice === 'drop') return 'dropped \u2014 Not checked';
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
185
198
|
/**
|
|
186
199
|
* PRD v1.106 Part 5 Q1: one answered question as the two lines the Audit's drafting table shows under its step. ONE place owns the words.
|
|
187
|
-
* @param {{question: string, answer: string, source?: string, line?: number, at?: string}} h
|
|
188
|
-
* @returns {{question: string, answer: string, source: string, line?: number, at?: string, askedText: string, saidText: string}}
|
|
200
|
+
* @param {{question: string, answer: string, source?: string, line?: number, at?: string, choice?: string, words?: string}} h
|
|
201
|
+
* @returns {{question: string, answer: string, source: string, line?: number, at?: string, choice?: string, words?: string, askedText: string, saidText: string}}
|
|
189
202
|
*/
|
|
190
203
|
export function humanRowWords(h) {
|
|
204
|
+
const decided = decidedWords(h);
|
|
191
205
|
return {
|
|
192
206
|
question: h.question, answer: h.answer, source: typeof h.source === 'string' ? h.source : 'confirm',
|
|
193
207
|
...(Number.isInteger(h.line) ? { line: h.line } : {}), ...(h.at ? { at: h.at } : {}),
|
|
194
|
-
|
|
208
|
+
...(typeof h.choice === 'string' ? { choice: h.choice } : {}), ...(typeof h.words === 'string' ? { words: h.words } : {}),
|
|
209
|
+
// a rule the answer replaced is shown by what was decided, never by the question that quotes its old words
|
|
210
|
+
askedText: decided ?? `you were asked: ${h.question}`, saidText: decided === null ? `you said: ${h.answer}` : '',
|
|
195
211
|
};
|
|
196
212
|
}
|
|
197
213
|
|
|
@@ -228,7 +244,7 @@ export function readDraftSteps(dir) {
|
|
|
228
244
|
x.status = 'running';
|
|
229
245
|
x.endedAt = null;
|
|
230
246
|
} else if (ev.kind === 'human' && byNo.has(ev.no) && typeof ev.question === 'string' && typeof ev.answer === 'string') {
|
|
231
|
-
byNo.get(ev.no).humans.push(humanRowWords({ question: ev.question, answer: ev.answer, source: ev.source, ...(Number.isInteger(ev.line) ? { line: ev.line } : {}), at: ev.at }));
|
|
247
|
+
byNo.get(ev.no).humans.push(humanRowWords({ question: ev.question, answer: ev.answer, source: ev.source, ...(typeof ev.choice === 'string' ? { choice: ev.choice } : {}), ...(typeof ev.words === 'string' ? { words: ev.words } : {}), ...(Number.isInteger(ev.line) ? { line: ev.line } : {}), at: ev.at }));
|
|
232
248
|
} else if (ev.kind === 'call') {
|
|
233
249
|
const c = { label: String(ev.label), model: typeof ev.model === 'string' ? ev.model : null, costUsd: typeof ev.costUsd === 'number' ? ev.costUsd : null, unpricedRounds: Number(ev.unpricedRounds) || 0, at: String(ev.at) };
|
|
234
250
|
byNo.get(ev.no)?.calls.push(c);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// THE REPO JOB'S POINTING CALL (hamr 2026-11-15: "same as rubric"). A rubric job's `~` rules take the AI's pointing through row edits that code then judges; a repo job does the same. BEFORE the asks, ONE small call
|
|
2
|
+
// shows the AI each `~` rule's own words and the repo paths outside the write scope; it answers in the row-edit shape `{"edits": [...]}` with the one op `fence` {line, rule, path}. The edits go through
|
|
3
|
+
// `CheckBlock.applyDelta` like every rubric edit; code proves each (the path is on the listing, the rule's own words name it, it lies outside the write scope). The AI points; code decides.
|
|
4
|
+
// A rule nobody pointed at, or whose point fails the proof, is asked about like any rule code cannot settle. A failed call never stops the draft: its rules go to the questions.
|
|
5
|
+
import { askStructured, makeCostBook } from './authorflow.js';
|
|
6
|
+
import { lineRules } from './rubricstep.js';
|
|
7
|
+
|
|
8
|
+
/** the label of the call, as the drafting book and the draft log see it */
|
|
9
|
+
export const FENCE_POINT_LABEL = 'fence-point';
|
|
10
|
+
export const FENCE_POINT_TOOL = 'submit_edits';
|
|
11
|
+
/** at most this many outside paths are shown to the call */
|
|
12
|
+
export const FENCE_POINT_MAX_PATHS = 300;
|
|
13
|
+
|
|
14
|
+
/** the call's own system text (model-facing; a prompt register: src/promptregisters.js) */
|
|
15
|
+
export const FENCE_POINT_SYSTEM = `You read the "~" rules of a job and point at the files a rule asks to leave as they are, by sending EDITS to a list of checks that code keeps. Code checks every edit you send against the rule's own words and the file list; an edit it cannot prove is dropped.
|
|
16
|
+
Call ${FENCE_POINT_TOOL} once with an "edits" list, or with an empty list.
|
|
17
|
+
The one edit: {"op":"fence","line":N,"rule":n,"path":"<a path copied from the list of paths>"} - the rule asks that this file or folder stay as it is. The path is one of the listed paths, or a folder that holds some of them, and the rule's own words name it.
|
|
18
|
+
Send an edit only for a rule whose own words say a listed file or folder stays as it is. A rule that says anything else gets no edit. An empty list is a good answer.`;
|
|
19
|
+
|
|
20
|
+
export const FENCE_POINT_SCHEMA = Object.freeze({
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
edits: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
items: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
op: { enum: ['fence'] },
|
|
29
|
+
line: { type: 'integer', minimum: 1, description: 'the job line number' },
|
|
30
|
+
rule: { type: 'integer', minimum: 1, description: 'the number of the ~ rule on that line' },
|
|
31
|
+
path: { type: 'string', minLength: 1, description: 'a path from the list that the rule asks to leave as it is' },
|
|
32
|
+
},
|
|
33
|
+
required: ['op', 'line', 'rule', 'path'],
|
|
34
|
+
additionalProperties: false,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ['edits'],
|
|
39
|
+
additionalProperties: false,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const channel = () => ({
|
|
43
|
+
name: FENCE_POINT_TOOL,
|
|
44
|
+
instruction: `Your reply did not deliver exactly one ${FENCE_POINT_TOOL} call. Call ${FENCE_POINT_TOOL} exactly once. Do not write the answer as text.`,
|
|
45
|
+
textPath: 'edits',
|
|
46
|
+
tool: (/** @type {{calls: any[]}} */ box) => ({
|
|
47
|
+
name: FENCE_POINT_TOOL,
|
|
48
|
+
description: 'Deliver the fence edits (or an empty list). Call this exactly once.',
|
|
49
|
+
parameters: FENCE_POINT_SCHEMA,
|
|
50
|
+
execute: async (/** @type {any} */ args) => { box.calls.push(args); return 'received'; },
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/** @param {{n: number, rules?: string[], rule?: string}[]} jobLines @param {string[]} outside the repo paths outside the write scope @param {string[]|null} writeScope @returns {string} */
|
|
55
|
+
export function fencePointUserText(jobLines, outside, writeScope) {
|
|
56
|
+
const out = ["THE RULES (the person's own words)"];
|
|
57
|
+
for (const l of jobLines) lineRules(l).forEach((r, i) => out.push(`line ${l.n} rule ${i + 1}: ${r}`));
|
|
58
|
+
out.push('', `PATHS OUTSIDE THE WRITE SCOPE${Array.isArray(writeScope) && writeScope.length ? ` (${writeScope.join(', ')})` : ''}:`, ...outside.slice(0, FENCE_POINT_MAX_PATHS).map((p) => `- ${p}`));
|
|
59
|
+
return out.join('\n');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The one paid call; its spend is booked like the look's. An unusable answer is NOT a guessed list: it yields no edits and says why (the rules then go to the questions).
|
|
64
|
+
* @param {{jobLines: any[], outside: string[], writeScope?: string[]|null, generate: Function, ceilingUsd?: number|null, onCall?: (c: any) => void, priorCalls?: any[], priorRaws?: any[]}} o
|
|
65
|
+
* @returns {Promise<{edits: any[], reason: string|null, calls: any[], raws: any[]}>}
|
|
66
|
+
*/
|
|
67
|
+
export async function runFencePoint({ jobLines, outside, writeScope = null, generate, ceilingUsd = null, onCall = () => {}, priorCalls = [], priorRaws = [] }) {
|
|
68
|
+
const book = makeCostBook({ ceilingUsd, onCall });
|
|
69
|
+
book.absorb(priorCalls, priorRaws);
|
|
70
|
+
const before = book.report().calls.length;
|
|
71
|
+
const beforeRaws = book.raws().length;
|
|
72
|
+
const r = await askStructured({ messages: [{ role: 'user', content: fencePointUserText(jobLines, outside, writeScope) }], generate, mode: 'tool', retries: 1, label: FENCE_POINT_LABEL, book, channel: channel() });
|
|
73
|
+
const edits = r.artifact && Array.isArray(r.artifact.edits) ? r.artifact.edits : [];
|
|
74
|
+
const reason = r.artifact ? null : (r.budget ? 'the spend ceiling was reached' : (r.providerError ?? r.red?.detail ?? 'the answer could not be read'));
|
|
75
|
+
return { edits, reason, calls: book.report().calls.slice(before), raws: book.raws().slice(beforeRaws) };
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The plain-English line of each mandatory guard, ONE owner (a leaf module: the confirm turn, the signed card and the one check list's `$` guard rows all read it).
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PLAIN-ENGLISH lines for the guards `classGuards` can compose, keyed by guard NAME — frozen beside CONFIRM_MENU (`src/authorflow.js`) because both are constants the confirm turn shows a person
|
|
5
|
+
* verbatim. One entry per guard that exists in `MECHANICAL_GUARDS` (`src/authoring.js`); `confirmProtections` throws if a guard `classGuards` hands back has no line here, so a battery that grows a
|
|
6
|
+
* guard fails loudly instead of showing a blank description.
|
|
7
|
+
* @type {Record<string, string>}
|
|
8
|
+
*/
|
|
9
|
+
export const GUARD_DESCRIPTIONS = Object.freeze({
|
|
10
|
+
'changed-from-seed': 'the run must actually change at least one file in scope — a close that reports done '
|
|
11
|
+
+ 'without touching anything is refused',
|
|
12
|
+
'no-suppressions': 'the run may not silence a checker instead of fixing what it flags (things like @ts-ignore, '
|
|
13
|
+
+ 'eslint-disable, or # type: ignore) — none of those may appear in the diff',
|
|
14
|
+
});
|
package/src/kinds.js
CHANGED
|
@@ -67,6 +67,7 @@ import { join, sep, dirname } from 'node:path';
|
|
|
67
67
|
import { globToPrefix, isNonEmptyString } from './validate.js';
|
|
68
68
|
import { CLOSE_ENV_DENY } from './ralph.js';
|
|
69
69
|
import { gradeStep, stepFileRel, STEP_MAX_BYTES, citedLabels, sha256Of } from './rubricstep.js';
|
|
70
|
+
import { rowResultsOf } from './rowresults.js';
|
|
70
71
|
|
|
71
72
|
/** the close's two judgment exits — a stage's verdict, in the shape the
|
|
72
73
|
* hand-written closes already spoke (exit code is truth) */
|
|
@@ -228,6 +229,7 @@ export function mechanicalStages(stages) {
|
|
|
228
229
|
* gapCap?: number, maxBuffer?: number, seedTrees?: SeedTrees,
|
|
229
230
|
* humanRuling?: {decision: string, text?: string|null}|null,
|
|
230
231
|
* onRubricEvidence?: (e: {step: number, evidence: any[], evidenceTotal?: number}) => void,
|
|
232
|
+
* list?: any[]|null,
|
|
231
233
|
* onStage?: (row: {stage: string|null, kind: string|null, verdict: string, durationMs: number}) => void}} Ctx
|
|
232
234
|
* The arbiter's half of a stage run. Every field here is operator/runner
|
|
233
235
|
* territory: a declaration parameterises kinds, never the contracts.
|
|
@@ -1506,12 +1508,14 @@ async function runRubricStep(stage, ctx) {
|
|
|
1506
1508
|
if (notRegular) gap.push(`${stage.name}: line ${step}: ${stepFileRel(step)} is not a regular file`);
|
|
1507
1509
|
for (const l of graded.gapLines) gap.push(`${stage.name}: ${l}`);
|
|
1508
1510
|
const red = graded.verdict === 'red' || notRegular;
|
|
1511
|
+
// each row of the line gets its own result (Addendum 2026-11-14 (c) piece 4), when the signed list is at hand: a REPORT of which row each gap belongs to, read by no verdict, governor or money path
|
|
1512
|
+
const per = Array.isArray(ctx.list) ? rowResultsOf(ctx.list, p, notRegular ? { ...graded, rawGaps: [{ id: 'happened', check: 'happened', kind: 'wrong-type' }], detail: { ...graded.detail, why: 'not-object' } } : graded) : null;
|
|
1509
1513
|
return result(stage, {
|
|
1510
1514
|
verdict: red ? 'red' : 'green',
|
|
1511
1515
|
exitCode: red ? EXIT_RED : EXIT_GREEN,
|
|
1512
1516
|
gapLines: gap.render(),
|
|
1513
1517
|
// the trend number (`trendValueOf`, src/declaredclose.js, reads `detail.redCount` for a stage with no measurement)
|
|
1514
|
-
detail: { ...graded.detail, ...(notRegular ? { redCount: 1 } : {}) },
|
|
1518
|
+
detail: { ...graded.detail, ...(notRegular ? { redCount: 1 } : {}), ...(per ? { rows: per.rows, unclaimed: per.unclaimed } : {}) },
|
|
1515
1519
|
});
|
|
1516
1520
|
}
|
|
1517
1521
|
|
package/src/pagemap.js
CHANGED
|
@@ -199,50 +199,28 @@ export async function runPageMap({
|
|
|
199
199
|
export const DROP_IT = 'drop it';
|
|
200
200
|
/** @param {unknown} text @returns {boolean} */
|
|
201
201
|
export const isDropIt = (text) => String(text ?? '').trim().replace(/\.$/, '').toLowerCase() === DROP_IT;
|
|
202
|
-
/** the answers that accept the code's reading of a rule
|
|
202
|
+
/** the answers that accept the code's reading of a rule (the Result tab's "(you confirmed)" reads an old typed one) */
|
|
203
203
|
const AGREE_WORDS = ['agree', 'yes'];
|
|
204
204
|
/** @param {unknown} text @returns {boolean} */
|
|
205
205
|
export const isAgree = (text) => AGREE_WORDS.includes(String(text ?? '').trim().replace(/[.!]$/, '').toLowerCase());
|
|
206
|
-
/**
|
|
207
|
-
* F240: an answer that opens with an agree word IMMEDIATELY followed by a comma or a colon (spaces allowed only after it) and more text
|
|
208
|
-
* ("yes, check it as ...", "agree: the outbound flight") is the person's own reading with a courtesy word in front: the word and the
|
|
209
|
-
* comma/colon go, the rest stays word for word. No hyphen or dash of any kind and no bare space counts, so "yes-no questions only",
|
|
210
|
-
* "agree-ment on price", "yes - departs", "yes departs" and "yesterday, ..." are kept whole. A bare "yes"/"agree" (isAgree) and a text that
|
|
211
|
-
* only contains the word later are returned untouched.
|
|
212
|
-
* @param {string} text @returns {string}
|
|
213
|
-
*/
|
|
214
|
-
export const stripAgreeLead = (text) => {
|
|
215
|
-
const m = String(text ?? '').match(new RegExp(`^(?:${AGREE_WORDS.join('|')})[,:]\\s*(\\S[\\s\\S]*)$`, 'i'));
|
|
216
|
-
return m ? m[1].trim() : String(text ?? '');
|
|
217
|
-
};
|
|
218
|
-
|
|
219
206
|
/** @typedef {{line: number, rule: number, source: 'look', question: string, ask: 'reading'|'cant-check'|'check'|'no-check', ruleText: string, reading?: string}} LookAsk
|
|
220
207
|
* `reading` = the plain words an `agree` writes as a `~` rule (a reading ask only) */
|
|
221
208
|
|
|
222
209
|
/** the words of a reading ask: the ONE spelling, and {@link readingOfQuestion} reads it back (the Result tab's "(you confirmed)") */
|
|
223
210
|
const READING_HEAD = ' I read it as: ';
|
|
224
211
|
const READING_ASKED = '. Agree?';
|
|
225
|
-
/**
|
|
226
|
-
const
|
|
227
|
-
const READING_TAIL = `${READING_ASKED}${READING_ANSWER}`;
|
|
228
|
-
/** @param {number} n @returns {string} the rest of a reading ask after its answer words */
|
|
229
|
-
const readingRest = (n) => `, or type your own reading (your answer replaces that ~ rule on line ${n}).`;
|
|
230
|
-
/** @param {number} n @returns {string} the answer words a reading ask ends with (said once, here, and cut in the panel) */
|
|
231
|
-
export const readingTail = (n) => `${READING_ANSWER}${readingRest(n)}`;
|
|
232
|
-
/** @param {number} n @returns {string} the answer words a can't-check ask ends with (said once, here, and cut in the panel) */
|
|
233
|
-
export const cantCheckTail = (n) => ` Answer "${DROP_IT}", or type how to check it (your answer replaces that ~ rule on line ${n}).`;
|
|
234
|
-
/** @param {number} n @param {string} rule @param {string} reading @returns {string} */
|
|
235
|
-
export const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_TAIL}${readingRest(n)}`;
|
|
212
|
+
/** @param {number} n @param {string} rule @param {string} reading @returns {string} a reading ask: the question only (hamr 2026-11-15: buttons only, so no answer words; a rule is changed by Revise) */
|
|
213
|
+
export const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_ASKED}`;
|
|
236
214
|
/** @param {unknown} q a recorded question @returns {string|null} the reading a reading ask proposed, or null when it was another kind of question */
|
|
237
215
|
export function readingOfQuestion(q) {
|
|
238
216
|
const s = String(q ?? '');
|
|
239
217
|
const a = s.indexOf(READING_HEAD);
|
|
240
|
-
const b = s.indexOf(
|
|
218
|
+
const b = s.indexOf(READING_ASKED, a + 1);
|
|
241
219
|
return a >= 0 && b > a ? s.slice(a + READING_HEAD.length, b) : null;
|
|
242
220
|
}
|
|
243
221
|
|
|
244
222
|
/** @param {number} n @param {string} rule @returns {string} the can't-check ask of a rule the page cannot check */
|
|
245
|
-
export const cantCheckQuestion = (n, rule) => `Your line ${n} says "${rule}". I can't check this
|
|
223
|
+
export const cantCheckQuestion = (n, rule, where = ' on the page') => `Your line ${n} says "${rule}". I can't check this${where}. Drop it?`;
|
|
246
224
|
|
|
247
225
|
/**
|
|
248
226
|
* PRD v1.107 Part 5b ("the look reads, code asks"): the early asks CODE forces before any paid drafting, from the look's own result. Every `~` rule is
|
|
@@ -304,7 +282,7 @@ const ruleBounds = (r) => (r.op === 'between' ? [r.lo, r.hi] : [r.value]);
|
|
|
304
282
|
* its reading as the suggestion (no extra paid call). A secret in a rule is masked.
|
|
305
283
|
* @param {LookAsk[]} asks @returns {string}
|
|
306
284
|
*/
|
|
307
|
-
export function tooManyAsksText(asks) {
|
|
308
|
-
const list = asks.map((a) => `line ${a.line} "${a.ruleText}" → ${a.
|
|
285
|
+
export function tooManyAsksText(asks, where = ' on the page') {
|
|
286
|
+
const list = asks.map((a) => `line ${a.line} "${a.ruleText}" → ${a.reading ?? `I can't check this${where}`}`).join('; ');
|
|
309
287
|
return redactSecrets(`Your job has ${asks.length} rules I can't check or had to guess. Please rewrite it so each one says what to look for. My readings: ${list}.`);
|
|
310
288
|
}
|
|
@@ -475,6 +475,11 @@ export function createAuthorRoutes(opts) {
|
|
|
475
475
|
}
|
|
476
476
|
if (sub === 'row-edit') {
|
|
477
477
|
// hamr 2026-11-13 (N-2): the confirm card's Drop / Add. $0 and instant: a row edit through the live check block, never a model call
|
|
478
|
+
// the FINAL repo card's Drop (hamr 2026-11-15): the signing gates run again, so the answer comes when they have
|
|
479
|
+
if (session.state.phase === 'prepared' && body?.op === 'drop') {
|
|
480
|
+
session.dropStage(body?.key).then((r) => send(r.ok ? 200 : 400, { ...r, state: session.state }), () => send(500, { ok: false, error: 'could not drop that check' }));
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
478
483
|
const r = session.rowEdit(body?.op, body?.key);
|
|
479
484
|
send(r.ok ? 200 : 400, { ...r, state: session.state });
|
|
480
485
|
return true;
|
|
@@ -536,7 +541,7 @@ export function signRun(session, claimedHash, o) {
|
|
|
536
541
|
if (session.state.finalPlan) {
|
|
537
542
|
try {
|
|
538
543
|
const spec = JSON.parse(readFileSync(session.state.resolvedSpecPath, 'utf8'));
|
|
539
|
-
const m = planMatchesClose(session.state.finalPlan.checkItems, spec.closeDecl);
|
|
544
|
+
const m = planMatchesClose(session.state.finalPlan.checkItems, spec.closeDecl, spec.jobLines ?? null);
|
|
540
545
|
if (!m.ok) return { ok: false, error: m.error };
|
|
541
546
|
// B2: a close that carries the one check list must agree with it: every built row points at a check the close runs, and every check has a row
|
|
542
547
|
const lm = listMatchesClose(spec.closeDecl);
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
import { resolveJobJudge } from '../judged.js';
|
|
50
50
|
import { assertThinkingMode, thinkingPlanFor, thinkingRowText, thinkingCallOptions } from '../thinking.js';
|
|
51
51
|
import { RUBRIC_LANG } from '../authoring.js';
|
|
52
|
-
import { rubricGoal, cardOfClose, signedFactNames } from '../rubricstep.js';
|
|
52
|
+
import { rubricGoal, cardOfClose, signedFactNames, carriesOneList, stageNameOfKey } from '../rubricstep.js';
|
|
53
53
|
import { redactSecrets } from '../validate.js';
|
|
54
54
|
import { FLOW_TYPES, flowTypeOf, oldJobWords } from '../job.js';
|
|
55
55
|
import { mcpPickFor, signFlow } from '../mcppick.js';
|
|
@@ -58,23 +58,24 @@ import { newestUnrunTicket } from '../ticketnext.js';
|
|
|
58
58
|
import { readTicket } from '../ticket.js';
|
|
59
59
|
import { readRunList } from '../runlist.js';
|
|
60
60
|
import { fetchPageText } from '../pagefetch.js';
|
|
61
|
-
import { isDropIt, isAgree, stripAgreeLead } from '../pagemap.js';
|
|
62
61
|
import { plainWords, SUGGEST_SYSTEM } from '../checkpick.js';
|
|
63
62
|
import { LEDGER_SYSTEM } from '../checklist.js';
|
|
63
|
+
import { FENCE_POINT_SYSTEM } from '../fencepointcall.js';
|
|
64
64
|
import { ROW_EDIT_SYSTEM } from '../rowedit.js';
|
|
65
|
+
import { choiceEntries } from '../checkblock.js';
|
|
65
66
|
import { readRecordFile, readRowChoices, writeRecordPart, RECORD_FILE, KEPT_WORDS } from '../pickrecord.js';
|
|
66
67
|
import { MAX_REVISES, draftLabelOf, nextRevisesUsed, sessionsRootOf, writeRevisesUsed } from '../revises.js';
|
|
67
68
|
import { runDestPoint, destQuestionText, yesNoOf } from '../destpoint.js';
|
|
68
69
|
import { runNoteAsk } from '../noteask.js';
|
|
69
70
|
import { tallyCalls } from '../text.js';
|
|
70
|
-
import { appendDraftLog, readDraftLedger } from '../draftspend.js';
|
|
71
|
-
import { signingStopText, draftStopText, redsRecord, declarationRecord, tryRefusedText } from '../authorreadout.js';
|
|
71
|
+
import { appendDraftLog, readDraftLedger, readDraftSteps } from '../draftspend.js';
|
|
72
|
+
import { signingStopText, draftStopText, redsRecord, declarationRecord, tryRefusedText, buildReadout, readoutHeadIndexes } from '../authorreadout.js';
|
|
72
73
|
import { runNpmCi, NPM_CI_LOCKS } from '../npminstall.js';
|
|
73
74
|
import {
|
|
74
75
|
parseJobBlock, parseInputs, renderJobLines, signedJobLines, jobBoxText, REPO_RUBRIC_WORDS,
|
|
75
76
|
} from '../jobblock.js';
|
|
76
77
|
import { planFromConfirm } from './jobplan.js';
|
|
77
|
-
import { boxFor, offersOf, panelQuestionText, refuseChoice, resolveChoice } from '../questionbox.js';
|
|
78
|
+
import { boxFor, offersOf, panelQuestionText, answerEffectWords, refuseChoice, resolveChoice, CHOICE_SAYS } from '../questionbox.js';
|
|
78
79
|
import { isTicketTrigger } from '../trigger.js';
|
|
79
80
|
import { ticketLookOf } from '../ticketschedule.js';
|
|
80
81
|
|
|
@@ -171,7 +172,7 @@ const SOURCE_CHECK_CODES = new Set([
|
|
|
171
172
|
]);
|
|
172
173
|
|
|
173
174
|
/** the line under the plan bubble, in plain words (the bubble itself is drawn by the page's one `renderJobPlan`) */
|
|
174
|
-
export const PLAN_FOOTER = '
|
|
175
|
+
export const PLAN_FOOTER = 'Draft the plan to see its checks, or Revise to edit the boxes.';
|
|
175
176
|
|
|
176
177
|
/**
|
|
177
178
|
* The confirm turn's plan as a chat message (P7): a STRUCTURED `{role:'bot', kind:'plan', plan}` the page draws with the
|
|
@@ -493,7 +494,7 @@ export function validateJobCard(card, opts = {}) {
|
|
|
493
494
|
* `signPrepare()` are the only ways in.
|
|
494
495
|
* @param {any} card the validated job card (see {@link validateJobCard})
|
|
495
496
|
* @param {{env?: Record<string,string|undefined>, sessionsRoot?: string, home?: string, timeoutMs?: number,
|
|
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
|
+
* scout?: any, generate?: Function, pickGenerate?: Function|null, ledgerGenerate?: Function|null, fenceGenerate?: Function|null, noteFn?: Function|null, editGenerate?: Function|null, carryFrom?: string, carryKind?: string, confirmGenerate?: Function, authorFn?: Function,
|
|
497
498
|
* prepareSigningFn?: Function, npmCiFn?: Function, lookFn?: Function|null, destFn?: Function|null, newestUnrunTicket?: typeof newestUnrunTicket, readTicketFn?: typeof readTicket, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>, draftThinking?: "on"|"off", reuse?: {spec: any, workflowKey: string}, schedule?: import('../trigger.js').Trigger|null, flow?: {flowType: 'plain'|'mcp'|'tickets', pick: {server: string, tools: string[]}|null}}} [deps] `scout`..`prepareSigningFn` are
|
|
498
499
|
* TEST SEAMS ONLY — see the note just above where each is read, below. `reuse` (Reuse workflow) is NOT a seam: the
|
|
499
500
|
* caller (`/api/author/start`) sets it only when the server's own same-job rule held.
|
|
@@ -667,7 +668,9 @@ export function createSession(card, deps = {}) {
|
|
|
667
668
|
const running = state.steps.findLastIndex((/** @type {any} */ x) => x.status === 'running');
|
|
668
669
|
appendDraftLog(outDir, {
|
|
669
670
|
kind: 'human', no: running === -1 ? Math.max(0, state.steps.length - 1) : running, source: typeof step.source === 'string' ? step.source : 'confirm',
|
|
670
|
-
question: redactSecrets(step.question), answer: said, ...(answeredChoice === null ? {} : { choice: answeredChoice }),
|
|
671
|
+
question: redactSecrets(step.question), answer: said, ...(answeredChoice === null ? {} : { choice: answeredChoice }),
|
|
672
|
+
// what was decided, for the readout (it never prints a question that quotes the rule's old words): the agreed reading, or the person's own correction
|
|
673
|
+
...(answeredChoice === 'agree' && typeof step.agreeWords === 'string' ? { words: redactSecrets(step.agreeWords) } : answeredChoice === 'rule' ? { words: said } : {}), ...(Number.isInteger(step.line) ? { line: step.line } : {}), at: new Date().toISOString(),
|
|
671
674
|
});
|
|
672
675
|
}
|
|
673
676
|
resolveFn0(value);
|
|
@@ -682,7 +685,7 @@ export function createSession(card, deps = {}) {
|
|
|
682
685
|
else if (step.kind === 'menu') {
|
|
683
686
|
sayPlan(step.plan ?? {});
|
|
684
687
|
} 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))}`);
|
|
688
|
+
else if (step.kind === 'answer') sayOpen(`A question the plan raised (${step.index} of ${step.total})${Number.isInteger(step.line) ? `, about job line ${step.line}` : ''}: ${panelQuestionText(/** @type {any} */ (step))}${answerEffectWords(/** @type {any} */ (step)) === null ? '' : ` ${answerEffectWords(/** @type {any} */ (step))}`}`);
|
|
686
689
|
else if (step.kind === 'goal') say('bot', 'Type the goal sentence yourself.');
|
|
687
690
|
});
|
|
688
691
|
|
|
@@ -716,6 +719,7 @@ export function createSession(card, deps = {}) {
|
|
|
716
719
|
// the one check list of a rubric job: each row once when it is built and once at the end, and each try's refusals (kind `ledger` / `ledger-try`)
|
|
717
720
|
if (name === 'note-answered') appendDraftLog(outDir, { kind: 'note-ask', no: Math.max(0, state.steps.length - 1), state: data.state, answers: data.answers, ...(data.reason ? { reason: redactSecrets(String(data.reason)) } : {}), at: new Date().toISOString() });
|
|
718
721
|
if (name === 'ledger-built' && Array.isArray(data.rows)) for (const r of data.rows) appendDraftLog(outDir, { phase: 'built', ...r, kind: 'ledger', no: Math.max(0, state.steps.length - 1), at: new Date().toISOString() });
|
|
722
|
+
if (name === 'fence-point-done') appendDraftLog(outDir, { kind: 'fence-point', no: Math.max(0, state.steps.length - 1), edits: redactSecrets(JSON.stringify(data.edits ?? [])), results: redactSecrets(JSON.stringify(data.results ?? [])), reason: data.reason == null ? null : redactSecrets(String(data.reason)), at: new Date().toISOString() });
|
|
719
723
|
if (name === 'draft-ledger-try') appendDraftLog(outDir, { kind: 'ledger-try', no: Math.max(0, state.steps.length - 1), label: data.label, kept: data.kept, refused: data.refused, at: new Date().toISOString() });
|
|
720
724
|
if (name === 'draft-ledger' && Array.isArray(data.rows)) for (const r of data.rows) appendDraftLog(outDir, { phase: 'final', ...r, kind: 'ledger', no: Math.max(0, state.steps.length - 1), at: new Date().toISOString() });
|
|
721
725
|
if (name === 'draft-retention' && Array.isArray(data.lines)) appendDraftLog(outDir, { kind: 'retention', no: Math.max(0, state.steps.length - 1), lines: data.lines, at: new Date().toISOString() });
|
|
@@ -1147,6 +1151,8 @@ export function createSession(card, deps = {}) {
|
|
|
1147
1151
|
// R10 (fwd am16): the check-suggestion call's own model boundary (SUGGEST_SYSTEM, the drafter's thinking); a test that replaces the model boundary never reaches it unless it brings `deps.pickGenerate`
|
|
1148
1152
|
const pickGenerate = deps.pickGenerate !== undefined ? deps.pickGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: SUGGEST_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1149
1153
|
// the one check list's call has its own model boundary (LEDGER_SYSTEM, the drafter's thinking); like the others, a test that replaces the model boundary never reaches it unless it brings `deps.ledgerGenerate`
|
|
1154
|
+
// the repo job's pointing call: its own model boundary (FENCE_POINT_SYSTEM), the drafter's thinking (off); a test that replaces the model boundary never reaches it unless it brings `deps.fenceGenerate`
|
|
1155
|
+
const fenceGenerate = deps.fenceGenerate !== undefined ? deps.fenceGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: FENCE_POINT_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1150
1156
|
const ledgerGenerate = deps.ledgerGenerate !== undefined ? deps.ledgerGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: LEDGER_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
1151
1157
|
// the row-edit turn (the drafter's reply of a rubric job, src/rowedit.js) has its own model boundary; a test that replaces `generate` need not bring one
|
|
1152
1158
|
const editGenerate = deps.editGenerate !== undefined ? deps.editGenerate : (deps.generate ? null : noCallAfterAbandon(makeLoopGenerate(provider, { system: ROW_EDIT_SYSTEM, rates: draftPrice?.rates ?? null, draftThinking })));
|
|
@@ -1213,15 +1219,18 @@ export function createSession(card, deps = {}) {
|
|
|
1213
1219
|
const left = [];
|
|
1214
1220
|
/** R10: the picks the person made (fwd am16): the check agreed to, or their own words with no check @type {{line: number, rule: number, check: Record<string, any>|null, added?: string, own?: boolean}[]} */
|
|
1215
1221
|
const picks = [];
|
|
1216
|
-
/** the choices the check block applies (src/blockasks.js) @type {{key: string, choice: string, text
|
|
1222
|
+
/** the choices the check block applies (src/blockasks.js) @type {{key: string, choice: string, text?: string}[]} */
|
|
1217
1223
|
const choices = [];
|
|
1218
1224
|
for (let k = 0; k < total; k += 1) {
|
|
1219
1225
|
const q = o.questions[k];
|
|
1220
1226
|
let text = '';
|
|
1221
|
-
/** the button the person used for this question (src/questionbox.js)
|
|
1227
|
+
/** the button the person used for this question (src/questionbox.js); null only for the drafter's own typed question: a typed choice decides, never the words */
|
|
1222
1228
|
let via = null;
|
|
1223
1229
|
for (;;) {
|
|
1224
|
-
|
|
1230
|
+
// a try-3 question (the drafter's own) says what its answer does: it REPLACES the rule it names, or ADDS a new one (Addendum 2026-11-14 (c) piece 5); a look question has its own words
|
|
1231
|
+
const asked = q.source === 'look' ? null : jobLines.find((l) => l.n === q.line);
|
|
1232
|
+
const replaces = asked && Number.isInteger(q.rule) ? asked.rules[/** @type {number} */ (q.rule) - 1] : undefined;
|
|
1233
|
+
const a = await ask({ kind: 'answer', source: typeof q.source === 'string' ? q.source : 'try-3', index: k + 1, total, question: q.question, line: q.line, ...(q.source === 'look' ? { ask: q.ask, rule: q.rule, offers: offersOf(q), agreeWords: q.ask === 'check' && q.check ? plainWords(/** @type {any} */ (q.check)) : typeof q.reading === 'string' ? q.reading : undefined } : {}), ...(typeof replaces === 'string' ? { replaces } : {}), ...(q.source !== 'look' && /** @type {any} */ (q).new === true ? { adds: true } : {}) });
|
|
1225
1234
|
if (a === null) return null;
|
|
1226
1235
|
via = takeChoice();
|
|
1227
1236
|
// one `~` line is one line: the person's own words, newlines folded to spaces, nothing else touched
|
|
@@ -1229,23 +1238,15 @@ export function createSession(card, deps = {}) {
|
|
|
1229
1238
|
if (text) break;
|
|
1230
1239
|
say('bot', 'An answer is needed here — there is no skip. Type it in the box below and press Send.');
|
|
1231
1240
|
}
|
|
1232
|
-
//
|
|
1233
|
-
// rule
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
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));
|
|
1241
|
+
// a code-forced look question about a `~` rule is answered by a BUTTON (hamr 2026-11-15; `send` refuses words with no choice): `agree` writes the code's reading (a reading ask) or the proposed check (a check ask)
|
|
1242
|
+
// as the rule, `drop` leaves the rule Not checked. Only a READING question also takes the person's own correction (`rule`, the box's words), which REPLACES the asked rule. The choice decides, never the words.
|
|
1243
|
+
const agrees = via === 'agree';
|
|
1244
|
+
const dropsIt = via === 'drop';
|
|
1245
|
+
const corrects = via === 'rule' && q.source === 'look' && q.ask === 'reading';
|
|
1240
1246
|
if (q.source === 'look' && q.ask === 'reading' && typeof q.reading === 'string' && agrees) text = q.reading;
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
const
|
|
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)
|
|
1248
|
-
const isPick = q.source === 'look' && (q.ask === 'check' || q.ask === 'no-check') && Number.isInteger(q.rule);
|
|
1247
|
+
if (q.source === 'look' && typeof (/** @type {any} */ (q)).key === 'string' && (agrees || dropsIt || corrects)) choices.push({ key: /** @type {any} */ (q).key, choice: dropsIt ? 'drop' : corrects ? 'rule' : 'agree', ...(corrects ? { text } : {}) });
|
|
1248
|
+
// R10 (fwd am16): a check-pick ask. `agree` REPLACES the asked rule with the proposal's plain words and picks the check; "drop it" leaves the rule Not checked
|
|
1249
|
+
const isPick = q.source === 'look' && q.ask === 'check' && Number.isInteger(q.rule);
|
|
1249
1250
|
if (isPick && dropsIt) { left.push({ line: q.line, rule: /** @type {number} */ (q.rule) }); appendDraftLog(outDir, { kind: 'check-pick', no: Math.max(0, state.steps.length - 1), line: q.line, rule: q.rule, ruleText: redactSecrets(String(q.ruleText ?? '')), proposed: q.reading ?? null, how: 'drop it', at: new Date().toISOString() }); continue; }
|
|
1250
1251
|
if (isPick) {
|
|
1251
1252
|
const agreed = q.ask === 'check' && q.check && agrees;
|
|
@@ -1256,8 +1257,14 @@ export function createSession(card, deps = {}) {
|
|
|
1256
1257
|
}
|
|
1257
1258
|
// one rule in, one rule out (hamr 2026-11-14): an answer about a rule of the check list REPLACES that rule, and the list is the one owner (the caller rebuilds the job text from it: `onJobLines`).
|
|
1258
1259
|
// Only an answer that is not about a list row (a model's own try-3 question) is still added word for word as a new `~` rule on its line.
|
|
1260
|
+
// A try-3 question (the drafter's own) names the rule it is about (the answer REPLACES it, one in one out) or says `new` (the answer is added); the draft log counts each under its own kind
|
|
1259
1261
|
const line = jobLines.find((l) => l.n === q.line);
|
|
1260
|
-
if (q.source !== 'look' && line) {
|
|
1262
|
+
if (q.source !== 'look' && line) {
|
|
1263
|
+
const old = Number.isInteger(q.rule) ? line.rules[/** @type {number} */ (q.rule) - 1] : undefined;
|
|
1264
|
+
if (typeof old === 'string') line.rules[/** @type {number} */ (q.rule) - 1] = text; else line.rules.push(text);
|
|
1265
|
+
line.rule = line.rules.join('; ');
|
|
1266
|
+
appendDraftLog(outDir, { kind: 'try3-question', no: Math.max(0, state.steps.length - 1), line: q.line, ...(typeof old === 'string' ? { rule: q.rule, ruleText: redactSecrets(old) } : { new: true }), how: typeof old === 'string' ? 'replaced' : 'added', question: redactSecrets(q.question), answer: redactSecrets(text), at: new Date().toISOString() });
|
|
1267
|
+
}
|
|
1261
1268
|
}
|
|
1262
1269
|
const said = left.length === total ? 'Noted: those stay Not checked. Drafting.' : 'Your answers are in on those job lines. Drafting again.';
|
|
1263
1270
|
// a check-list ask (every question carries a list key): the list has not yet replaced the asked rules, so the message waits for the rebuilt lines (`onJobLines`) and is drawn from them
|
|
@@ -1286,7 +1293,7 @@ export function createSession(card, deps = {}) {
|
|
|
1286
1293
|
rates: draftPrice?.rates ?? null,
|
|
1287
1294
|
draftThinking,
|
|
1288
1295
|
onPhase, onCall,
|
|
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,
|
|
1296
|
+
ask, answerQuestions, confirmGenerate, isRepo: !RUBRIC_FILES, langResult, pickGenerate, ledgerGenerate, fenceGenerate, noteFn, onJobLines: (/** @type {any[]} */ lines) => { const p = pendingSay; pendingSay = null; syncJobLines(lines, p ? p.say : null, p ? p.confirmed : null); }, editGenerate, carriedPicks, carriedChoices,
|
|
1290
1297
|
onChoices: (/** @type {any[]} */ rec) => { try { writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: rec }); } catch { /* a convenience: a disk fault only means the next draft starts without them */ } },
|
|
1291
1298
|
// R10: this draft's record (the picks it kept and the ones just answered) goes to its own folder for the next draft to carry; each kept pick is logged as such
|
|
1292
1299
|
onPicks: (/** @type {{entries: any[], kept: {line: number, rule: number, entry: any}[]}} */ o) => {
|
|
@@ -1325,7 +1332,8 @@ export function createSession(card, deps = {}) {
|
|
|
1325
1332
|
// piece 8: the card's Flow type and MCP pick are signed by CODE, after the draft (the agent cannot carry them: `assembleSpec` refuses a draft that does). A plain card adds nothing.
|
|
1326
1333
|
const spec = signFlow(assembleSpec(draft, { ...authored, verdictType: /** @type {string} */ (authored.verdictType) }), deps.flow?.flowType ?? 'plain', deps.flow?.pick ?? null, authored.authoring?.ticketFilter);
|
|
1327
1334
|
// PART 1a (run mv5bk400): the card AFTER drafting is built from the signed close itself (cardOfClose), never from what the confirm turn planned.
|
|
1328
|
-
|
|
1335
|
+
// a repo job that signs the one list gets the same card: its rows, never what the confirm turn planned (Addendum 2026-11-15 (d))
|
|
1336
|
+
if (RUBRIC_FILES || carriesOneList(spec.closeDecl)) {
|
|
1329
1337
|
const rec = cardOfClose({ closeDecl: spec.closeDecl, jobLines, ledger: readDraftLedger(outDir) });
|
|
1330
1338
|
// the checks this draft ended with, each marked who added it (`agent` or `you`): the Audit's Draft group shows them (a log line, not a second record of the plan)
|
|
1331
1339
|
appendDraftLog(outDir, { kind: 'draft-checks', no: Math.max(0, state.steps.length - 1), checks: rec.checkItems.filter((/** @type {any} */ c) => c.by === 'agent' || c.by === 'you').map((/** @type {any} */ c) => ({ line: c.fromLine[0], text: redactSecrets(String(c.text)), by: c.by })), at: new Date().toISOString() });
|
|
@@ -1336,18 +1344,36 @@ export function createSession(card, deps = {}) {
|
|
|
1336
1344
|
state.finalPlan = { goal: String(draft.goal ?? ''), checkItems: rec.checkItems, picked, notChecked: rec.notChecked, notCheckedBy: rec.notCheckedBy, protections: authored.confirmed?.protections ?? [], signedFacts: signedFactNames(spec.closeDecl), ...(spec.ticketFilter ? { ticketFilter: spec.ticketFilter } : {}) };
|
|
1337
1345
|
}
|
|
1338
1346
|
await finish(spec, authored.seedRef, authored.hasBuiltCheck ?? null);
|
|
1347
|
+
if (state.phase === 'prepared') finalCtx = { spec, seedRef: authored.seedRef, tree: prep.tree, repo: !RUBRIC_FILES };
|
|
1339
1348
|
if (state.finalPlan && state.phase === 'prepared') {
|
|
1340
1349
|
// The confirm turn's plan bubble (and a try-3 "answers are in" one) is the DRAFTER's wording of the checks, written before
|
|
1341
1350
|
// any close existed. Once the close is signed-ready its card is the only plan the person sees: the earlier ones are
|
|
1342
1351
|
// dropped, so drafter prose can never sit above (and be read instead of) the code's sentences (run mv5e1ktb).
|
|
1343
1352
|
state.messages = state.messages.filter((/** @type {any} */ m) => m.kind !== 'plan');
|
|
1344
1353
|
state.messages.push({
|
|
1345
|
-
...
|
|
1354
|
+
...finalPlanMessage(),
|
|
1346
1355
|
text: 'These are the checks the signed close will run, and what it will not check. Sign & run to accept them, or Revise to edit the boxes and draft again.',
|
|
1347
1356
|
});
|
|
1348
1357
|
}
|
|
1349
1358
|
}
|
|
1350
1359
|
|
|
1360
|
+
/** the signed-ready card as a chat message; a repo job's agent rows can be Dropped on it (the person shapes the spec they sign: `dropStage`) */
|
|
1361
|
+
const finalPlanMessage = () => ({ ...finalPlanCard(), readout: draftReadout() });
|
|
1362
|
+
/** the draft readout of the signed-ready plan (hamr 2026-11-15): text + head indexes, display only, built from the signed spec in `finalCtx`, the draft log and this session's own figures; one function, so Drop never carries a stale or a second one */
|
|
1363
|
+
const draftReadout = () => {
|
|
1364
|
+
const steps = readDraftSteps(outDir);
|
|
1365
|
+
const text = buildReadout({
|
|
1366
|
+
spec: finalCtx?.spec, name: String(finalCtx?.spec?.job ?? card.jobName), modelId: String(card.model), rounds: steps.reduce((n, x) => n + x.calls.length, 0),
|
|
1367
|
+
costUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete, specHash: state.specHash, source: cardSource(card), destination: String(card.destination ?? ''),
|
|
1368
|
+
humans: steps.flatMap((x) => x.humans), ledger: readDraftLedger(outDir),
|
|
1369
|
+
});
|
|
1370
|
+
return { text, heads: readoutHeadIndexes(text) };
|
|
1371
|
+
};
|
|
1372
|
+
const finalPlanCard = () => planMessage({ checkItems: state.finalPlan.checkItems, checks: state.finalPlan.checkItems.map((/** @type {any} */ c) => c.text), notChecked: state.finalPlan.notChecked, notCheckedBy: state.finalPlan.notCheckedBy, protections: state.finalPlan.protections, signedFacts: state.finalPlan.signedFacts, picked: state.finalPlan.picked, ticketFilter: state.finalPlan.ticketFilter, questions: [], ...(finalCtx?.repo ? { editable: true } : {}) }, jobLines);
|
|
1373
|
+
/** @type {{spec: any, seedRef: string|null, tree: string, repo: boolean}|null} the spec the final card shows and the seed it was gated against */
|
|
1374
|
+
let finalCtx = null;
|
|
1375
|
+
let dropping = false;
|
|
1376
|
+
|
|
1351
1377
|
// fire-and-forget — the caller (src/panel/server.js) never awaits this; it
|
|
1352
1378
|
// polls `state` instead. A crash anywhere in `run()` is caught here so it
|
|
1353
1379
|
// can never take the panel server process down with it.
|
|
@@ -1363,6 +1389,8 @@ export function createSession(card, deps = {}) {
|
|
|
1363
1389
|
if (!state.pendingAsk) return { ok: false, error: 'nothing is being asked right now' };
|
|
1364
1390
|
if (state.pendingAsk.kind === 'menu') return { ok: false, error: 'use Sign & run for a plan, never Send — the chat can never sign or pick a plan action' };
|
|
1365
1391
|
if (state.pendingAsk.kind === 'install-needed') return { ok: false, error: 'install the packages, then click Check again — nothing to send here' };
|
|
1392
|
+
// a check question (a look's reading, a proposed check) is answered by its button only (hamr 2026-11-15): typed words with no choice are refused and the question stays open
|
|
1393
|
+
if (choice === undefined && state.pendingAsk.kind === 'answer' && state.pendingAsk.source === 'look') return { ok: false, refused: 'bad-choice', error: CHOICE_SAYS.bad };
|
|
1366
1394
|
if (choice !== undefined) {
|
|
1367
1395
|
// hamr 2026-11-12 (fwd am29/am31): the question box posts a typed choice. A refusal leaves the question open: nothing said, nothing logged, nothing resolved.
|
|
1368
1396
|
const no = refuseChoice(state.pendingAsk, choice);
|
|
@@ -1424,6 +1452,54 @@ export function createSession(card, deps = {}) {
|
|
|
1424
1452
|
appendDraftLog(outDir, { kind: 'row-edit', no: Math.max(0, state.steps.length - 1), op, key: redactSecrets(String(key)), at: new Date().toISOString() });
|
|
1425
1453
|
return { ok: true };
|
|
1426
1454
|
},
|
|
1455
|
+
/**
|
|
1456
|
+
* Drop on a repo `! [agent]` stage row of the FINAL card (hamr 2026-11-15, spec 2 pick b): the person shaping the spec they are about to sign. The stage and its list row leave a COPY of the spec; the $0 signing gates (the validator and the seed read)
|
|
1457
|
+
* run again on it and the hash is recomputed before the card is drawn again. A gate that refuses (a line left with no check, no work stage red at the seed) refuses the Drop in plain words and nothing changes. Add: a repo has no Suggested rows, so there is none.
|
|
1458
|
+
* @param {unknown} key @returns {Promise<{ok: true}|{ok: false, error: string, refused: string}>}
|
|
1459
|
+
*/
|
|
1460
|
+
dropStage: async (key) => {
|
|
1461
|
+
if (state.phase !== 'prepared' || finalCtx === null || !state.finalPlan || !finalCtx.repo || dropping) return { ok: false, refused: 'no-plan', error: 'no plan is waiting where checks can be dropped right now' };
|
|
1462
|
+
const name = stageNameOfKey(key);
|
|
1463
|
+
const rowOk = name !== '' && Array.isArray(finalCtx.spec.closeDecl?.list) && finalCtx.spec.closeDecl.list.some((/** @type {any} */ r) => r && r.key === key && r.kind === 'stage' && r.state === 'built');
|
|
1464
|
+
if (!rowOk) return { ok: false, refused: 'bad-row', error: 'only a check the agent added can be dropped' };
|
|
1465
|
+
dropping = true;
|
|
1466
|
+
try {
|
|
1467
|
+
const droppedLine = Number(finalCtx.spec.closeDecl.list.find((/** @type {any} */ r) => r && r.key === key)?.line ?? 1);
|
|
1468
|
+
const spec = structuredClone(finalCtx.spec);
|
|
1469
|
+
spec.closeDecl.stages = spec.closeDecl.stages.filter((/** @type {any} */ st) => st.name !== name);
|
|
1470
|
+
spec.closeDecl.list = spec.closeDecl.list.filter((/** @type {any} */ r) => r.key !== key);
|
|
1471
|
+
const jv = validateJob(spec, { shellCapUsd: spec.budgetUsd });
|
|
1472
|
+
const signing = jv.ok ? await prepareSigningFn({ spec, workdir: finalCtx.tree, seedRef: finalCtx.seedRef, timeoutMs, shellCapUsd: spec.budgetUsd }) : null;
|
|
1473
|
+
if (signing === null || !signing.ok) {
|
|
1474
|
+
// the plain-words owners (src/authorreadout.js): a validator red is told in its own plain sentence (`tryRefusedText`, the words the draft's own refusals use), a signing red as the signing stop tells it
|
|
1475
|
+
/** @type {any} */
|
|
1476
|
+
const uncovered = signing === null ? jv.reds.find((/** @type {any} */ r) => r.code === 'job-line-uncovered' && Number.isInteger(r.line)) : undefined;
|
|
1477
|
+
const why = uncovered
|
|
1478
|
+
? `Dropping that check would leave line ${uncovered.line} with no check, so it stays. Use Revise to change the job instead.`
|
|
1479
|
+
: signing === null
|
|
1480
|
+
? tryRefusedText({ reds: jv.reds.map((/** @type {any} */ r) => ({ ...r, detail: String(r.detail ?? '') })) })
|
|
1481
|
+
: signingStopText({ reds: signing.reds ?? [], refusal: signing.refusal, noCheck: false, spend: { knownUsd: state.draftSpentUsd, spendComplete: state.draftSpendComplete } });
|
|
1482
|
+
return { ok: false, refused: 'gates', error: uncovered ? why : `Dropping that check is refused: ${why}` };
|
|
1483
|
+
}
|
|
1484
|
+
writeFileSync(join(outDir, 'resolved-spec.json'), `${JSON.stringify(spec, null, 2)}\n`);
|
|
1485
|
+
writeFileSync(join(outDir, 'signing.json'), `${JSON.stringify(signing, null, 2)}\n`);
|
|
1486
|
+
state.specHash = signing.specHash;
|
|
1487
|
+
finalCtx = { ...finalCtx, spec };
|
|
1488
|
+
const rec = cardOfClose({ closeDecl: spec.closeDecl, jobLines, ledger: readDraftLedger(outDir) });
|
|
1489
|
+
state.finalPlan = { ...state.finalPlan, checkItems: rec.checkItems, notChecked: rec.notChecked, notCheckedBy: rec.notCheckedBy };
|
|
1490
|
+
const at = state.messages.findLastIndex((/** @type {any} */ m) => m.kind === 'plan');
|
|
1491
|
+
const msg = { ...finalPlanMessage(), text: 'These are the checks the signed close will run, and what it will not check. Sign & run to accept them, or Revise to edit the boxes and draft again.' };
|
|
1492
|
+
if (at === -1) state.messages.push(msg); else state.messages[at] = msg;
|
|
1493
|
+
appendDraftLog(outDir, { kind: 'row-edit', no: Math.max(0, state.steps.length - 1), op: 'drop', key: redactSecrets(String(key)), at: new Date().toISOString() });
|
|
1494
|
+
// the same record a rubric Drop writes (the check block's own `choiceEntries`): a Revise keeps this Drop, code still judging it (never the last check on a line)
|
|
1495
|
+
try {
|
|
1496
|
+
const entry = choiceEntries(jobLines.map((/** @type {any} */ l) => ({ n: l.n, text: l.text })), [{ line: droppedLine, key: String(key), choice: 'drop' }]);
|
|
1497
|
+
const had = readRowChoices(join(outDir, RECORD_FILE)) ?? [];
|
|
1498
|
+
writeRecordPart(join(outDir, RECORD_FILE), { rowChoices: [...had.filter((/** @type {any} */ c) => !entry.some((e) => e.lineWords === c.lineWords && e.occurrence === c.occurrence && e.tail === c.tail)), ...entry] });
|
|
1499
|
+
} catch { /* a convenience: a disk fault only means the next draft starts without it */ }
|
|
1500
|
+
return { ok: true };
|
|
1501
|
+
} finally { dropping = false; }
|
|
1502
|
+
},
|
|
1427
1503
|
/** click 1 — the confirm pick. Never signs on its own. */
|
|
1428
1504
|
signPrepare: () => {
|
|
1429
1505
|
if (!state.pendingAsk || state.pendingAsk.kind !== 'menu') return { ok: false, error: 'no plan is waiting for a decision right now' };
|