fwdloop 0.30.0 → 0.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwdloop",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/authoring.js CHANGED
@@ -91,7 +91,7 @@ export function specHash({
91
91
  * answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
92
92
  * @param {string} planDir
93
93
  * A question the page look raised (M10 piece 3) also carries `source: 'look'`, `ask` ('reading' | 'cant-check'), `ruleNo`, `ruleText` and `proposal`; an answer file carries `at`.
94
- * @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number}[], open: {k:number, line:number, question:string, answer:null}[] }}
94
+ * @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, choice?:'agree'|'drop'|'rule', source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number}[], open: {k:number, line:number, question:string, answer:null}[] }}
95
95
  */
96
96
  export function readQuestions(planDir) {
97
97
  const none = { questions: [], open: [] };
@@ -107,15 +107,17 @@ export function readQuestions(planDir) {
107
107
  let at;
108
108
  /** @type {string|null|undefined} the `~` rule the answer added (null = it left the rule Not checked), as the answer file recorded it */
109
109
  let rule;
110
+ /** @type {'agree'|'drop'|'rule'|undefined} M10 am29: which one the answer used (`agree`, `drop` or `rule`), when the file records it */
111
+ let choice;
110
112
  if (a.ok) {
111
113
  try {
112
114
  const j = JSON.parse(a.text);
113
115
  const t = j?.answer;
114
- if (typeof t === 'string' && t.trim() !== '') { answer = t; if (typeof j.at === 'string') at = j.at; if (j.rule === null || typeof j.rule === 'string') rule = j.rule; }
116
+ if (typeof t === 'string' && t.trim() !== '') { answer = t; if (typeof j.at === 'string') at = j.at; if (j.rule === null || typeof j.rule === 'string') rule = j.rule; if (j.choice === 'agree' || j.choice === 'drop' || j.choice === 'rule') choice = j.choice; }
115
117
  } catch { /* unreadable = unanswered */ }
116
118
  }
117
119
  return {
118
- k, line: q.line, question: String(q.question), answer, ...(at === undefined ? {} : { at }), ...(rule === undefined ? {} : { rule }),
120
+ k, line: q.line, question: String(q.question), answer, ...(at === undefined ? {} : { at }), ...(rule === undefined ? {} : { rule }), ...(choice === undefined ? {} : { choice }),
119
121
  ...(q.source === 'look' ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: typeof q.proposal === 'string' ? q.proposal : null, ...(q.check && typeof q.check === 'object' ? { check: q.check } : {}), ...(Number.isInteger(q.pairRule) ? { pairRule: q.pairRule } : {}) } : {}),
120
122
  };
121
123
  });
package/src/checkpick.js CHANGED
@@ -205,7 +205,7 @@ export function countCheck(text) {
205
205
  /** the can't-check ask, as the signed words say it */
206
206
  export const CANT_CHECK_WORDS = "I can't check this. Your own words, or Not checked?";
207
207
  /** how every answer is told, once (am2 item 2's words) */
208
- const HOW_TO_ANSWER = (/** @type {number} */ line, /** @type {boolean} */ agree) => `${agree ? 'Answer "agree" to use it, or type your own words' : 'Type your own words'} (your answer is added as a new ~ rule on line ${line}), or answer "drop it" to leave it Not checked.`;
208
+ export const HOW_TO_ANSWER = (/** @type {number} */ line, /** @type {boolean} */ agree) => `${agree ? 'Answer "agree" to use it, or type your own words' : 'Type your own words'} (your answer is added as a new ~ rule on line ${line}), or answer "drop it" to leave it Not checked.`;
209
209
 
210
210
  /**
211
211
  * The asks for the rows: `Line n, guardrail "<…>": I propose <check in plain words>.` for a kept check, `Line n, guardrail "<…>": I can't check this. Your own words, or
package/src/drafter.js CHANGED
@@ -22,6 +22,7 @@ import { validateDeclaration, checkGuardrailSums, checkSendLineGuardrail } from
22
22
  import { readEveryStep } from './whole-job.js';
23
23
  import { loadCatalogue } from './catalogue.js';
24
24
  import { findMcpPlanRed } from './canrun.js';
25
+ import { tableChecksFailingOnInput } from './sheetrun.js';
25
26
  import { WIRED_VERBS, wiredMenu } from './primitives.js';
26
27
  import { ticketSourcesOf, ticketFactsLines, mcpFactsLines, ticketSchemaParts, ticketReds, userMcpServers } from './ticket-draft.js';
27
28
  import { readInputFacts } from './input-facts.js';
@@ -50,6 +51,7 @@ import {
50
51
  import { LIVE_PROVIDER_OPTIONS } from './model-step.js';
51
52
  import { ConfigError } from './config.js';
52
53
  import { thinkingSay, worstThinkingStatus } from './thinking.js';
54
+ import { repairTrailingBraces } from './jsonbrace.js';
53
55
 
54
56
  export const MAX_STRUCTURE_RETRIES = 2;
55
57
  export const MAX_REVISIONS = 2;
@@ -851,15 +853,9 @@ export async function draft({
851
853
  break;
852
854
  }
853
855
 
854
- if (!isPlainObject(captured)) {
855
- const malformed = provider?.lastMalformedToolCall ?? null;
856
- const why = result?.stopReason === 'max_tokens' ? 'truncated: the round hit the output cap with no completed tool call'
857
- : malformed ? `the tool call's arguments were not valid JSON (${malformed.error})`
858
- : 'no usable tool call (text instead of the tool)';
856
+ // M4d am39: a structure failure is handled by one function, so a brace repair that the validator then refuses takes the very same path.
857
+ const structureFailure = (/** @type {string} */ why) => {
859
858
  entry.outcome = `structure: ${why}`;
860
- // the raw answer is kept (log.json): the unparseable arguments as sent, else the model's text
861
- if (typeof malformed?.rawArguments === 'string') entry.rawArguments = malformed.rawArguments;
862
- else if (typeof result?.text === 'string' && result.text !== '') entry.rawText = result.text;
863
859
  log.push(entry);
864
860
  lastReds = [why];
865
861
  // M4d am3 A3: a round cut off at the output cap before tries 1 and 2 are spent is a FAILED TRY, advancing the same counter a
@@ -873,15 +869,36 @@ export async function draft({
873
869
  failedLines = lineNums;
874
870
  userText += `\n\n${QUESTIONS_PROMPT}`;
875
871
  }
876
- continue;
872
+ return 'continue';
877
873
  }
878
- if (structureRetries >= MAX_STRUCTURE_RETRIES) { stop = 'structure'; break; }
874
+ if (structureRetries >= MAX_STRUCTURE_RETRIES) { stop = 'structure'; return 'break'; }
879
875
  structureRetries += 1;
880
876
  nextKind = 'structure-retry';
881
877
  userText = `Your last reply was not a usable tool call (${why}). Call ${TOOL} now with a complete, valid JSON declaration.`;
882
878
  if (validatorReds.length) userText += `\n\nThe last declaration you emitted was still refused by the validator; keep fixing these too:\n${validatorReds.map((r) => `- ${r}`).join('\n')}`;
883
879
  if (askOpen) userText += `\n\n${QUESTIONS_PROMPT}`;
884
- continue;
880
+ return 'continue';
881
+ };
882
+ /** @type {string | null} the structure reason, kept while a brace-repaired answer waits for the validator */
883
+ let braceWhy = null;
884
+ if (!isPlainObject(captured)) {
885
+ const malformed = provider?.lastMalformedToolCall ?? null;
886
+ const why = result?.stopReason === 'max_tokens' ? 'truncated: the round hit the output cap with no completed tool call'
887
+ : malformed ? `the tool call's arguments were not valid JSON (${malformed.error})`
888
+ : 'no usable tool call (text instead of the tool)';
889
+ // the raw answer is kept (log.json): the unparseable arguments as sent, else the model's text
890
+ if (typeof malformed?.rawArguments === 'string') entry.rawArguments = malformed.rawArguments;
891
+ else if (typeof result?.text === 'string' && result.text !== '') entry.rawText = result.text;
892
+ // M4d am39: only a malformed-JSON round (never a cut-off, never text) whose answer is a complete object plus trailing `}` is repaired
893
+ const fixed = malformed && result?.stopReason !== 'max_tokens' ? repairTrailingBraces(malformed.rawArguments) : null;
894
+ if (!fixed) {
895
+ const next = structureFailure(why);
896
+ if (next === 'break') break;
897
+ continue;
898
+ }
899
+ captured = fixed.value;
900
+ braceWhy = why;
901
+ entry.braceRepair = { dropped: fixed.dropped, used: true };
885
902
  }
886
903
 
887
904
  // `notChecked` was offered on every try, so it is information and never reaches the validator. `questions` is stripped only where it was
@@ -923,8 +940,18 @@ export async function draft({
923
940
  pageWords: { texts: { ...(facts.docs ?? {}), ...Object.fromEntries(Object.entries(pages).map(([role, pg]) => [role, pg.text])) }, look: pageSources.length ? { facts: look.facts, dropped: look.dropped } : null, docs: docRolesOf(arbiter.sources) },
924
941
  });
925
942
  // M13 piece 4 (F105 rewritten): a generic MCP job whose steps call none of its tools is fed back like any validator red (the run would refuse it at $0, by the same sentence)
943
+ // M4d am39: a brace-repaired answer the validator finds an unknown key in is not used; the round is a structure failure, as today
944
+ if (braceWhy !== null && !verdict1.ok && verdict1.reds.some((r) => /unknown key/.test(r))) {
945
+ entry.braceRepair = { ...entry.braceRepair, used: false };
946
+ delete entry.retention;
947
+ const next = structureFailure(braceWhy);
948
+ if (next === 'break') break;
949
+ continue;
950
+ }
926
951
  const planRed = verdict1.ok ? findMcpPlanRed(declaration) : null;
927
- const verdict = planRed ? { ok: false, reds: [planRed] } : verdict1;
952
+ // M10b am5: a `table` check that already fails on the sheet this draft was made with is a red ($0: bareguard's checkStep on the draft-time table, no model call)
953
+ const tableReds = verdict1.ok && sheetTables ? await tableChecksFailingOnInput(declaration, sheetTables) : [];
954
+ const verdict = planRed ? { ok: false, reds: [planRed] } : tableReds.length ? { ok: false, reds: tableReds } : verdict1;
928
955
  lastDecl = declaration;
929
956
  const asked = askOpen ? normalizeQuestions(rawQuestions, failedLines) : { kept: [], dropped: [] };
930
957
  extras = { questions: asked.kept, droppedQuestions: asked.dropped, notChecked: [...new Set([...pageNotChecked, ...cleanNotChecked(rawNotChecked), ...uncoveredRules(declaration, jobLines, Object.keys(facts.sheets ?? {}))])] };
@@ -0,0 +1,21 @@
1
+ // borrowed-from: poc/f183-brace/repair.mjs (the repair rule, M4d am39)
2
+ // A drafting answer that is a complete JSON object followed ONLY by `}` characters and whitespace: drop exactly those
3
+ // trailing characters and parse the rest. Anything else (trailing `]`, text, `}x`, a truncated object, two objects,
4
+ // an array root) returns null. The caller calls this only for a round whose reason is malformed JSON.
5
+ /**
6
+ * @param {unknown} raw
7
+ * @returns {{ value: Record<string, any>, dropped: string } | null}
8
+ */
9
+ export function repairTrailingBraces(raw) {
10
+ if (typeof raw !== 'string') return null;
11
+ let cut = raw.trimEnd();
12
+ if (!cut.endsWith('}')) return null;
13
+ for (;;) {
14
+ cut = cut.slice(0, -1).trimEnd();
15
+ if (!cut.endsWith('}')) return null;
16
+ let value;
17
+ try { value = JSON.parse(cut); } catch { continue; }
18
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) return null;
19
+ return { value, dropped: raw.slice(cut.length) };
20
+ }
21
+ }
package/src/pageask.js CHANGED
@@ -16,6 +16,8 @@ import { redactSecrets } from './redact.js';
16
16
  import { lineRules, boundInWords, wordsSaidOn } from './pagebits.js';
17
17
  import { validReading } from './pagerules.js';
18
18
  import { isCountGuardrail } from './declaration.js';
19
+ import { HOW_TO_ANSWER } from './checkpick.js';
20
+ import { columnTail } from './sheetfind.js';
19
21
 
20
22
  /** the most asks before drafting; more than this is a job to rewrite, not a questionnaire (am1) */
21
23
  export const MAX_LOOK_ASKS = 3;
@@ -70,9 +72,16 @@ export function ruleWords(f) {
70
72
 
71
73
  /** the words of a reading ask: the ONE spelling, and {@link readingOfQuestion} reads it back (the Result tab's "(you confirmed)") */
72
74
  const READING_HEAD = ' I read it as: ';
73
- const READING_TAIL = '. Agree? Answer "agree"';
75
+ const READING_ASKED = '. Agree?';
76
+ /** the part of a reading ask that tells the CLI's typed words (M10 am29: the panel shows the question without it) */
77
+ const READING_ANSWER = ' Answer "agree"';
78
+ const READING_TAIL = `${READING_ASKED}${READING_ANSWER}`;
79
+ /** @param {number} n @returns {string} the rest of a reading ask after its answer words */
80
+ const readingRest = (n) => `, or type your own reading (your answer is added as a new ~ rule on line ${n}).`;
81
+ /** @param {number} n @returns {string} the answer words a can't-check ask ends with (said once, here, and cut in the panel) */
82
+ const cantCheckTail = (n) => ` Answer "${DROP_IT}", or type how to check it (your answer is added as a new ~ rule on line ${n}).`;
74
83
  /** @param {number} n @param {string} rule @param {string} reading @returns {string} */
75
- const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_TAIL}, or type your own reading (your answer is added as a new ~ rule on line ${n}).`;
84
+ const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_TAIL}${readingRest(n)}`;
76
85
  /** @param {unknown} q a recorded question @returns {string|null} the reading a reading ask proposed, or null when it was another kind of question */
77
86
  export function readingOfQuestion(q) {
78
87
  const s = String(q ?? '');
@@ -81,6 +90,19 @@ export function readingOfQuestion(q) {
81
90
  return a >= 0 && b > a ? s.slice(a + READING_HEAD.length, b) : null;
82
91
  }
83
92
 
93
+ /**
94
+ * M10 am29: a look question as the PANEL shows it: the code's own answer words (`Answer "agree"…` / `answer "drop it"…`) cut off the end, because the buttons and the box say it.
95
+ * Only the known tails are cut, matched exactly as a suffix (never a pattern over the prose); a question that ends in none of them is returned whole. The stored question is never changed.
96
+ * @param {{question: string, line: number, source?: string}} q @returns {string}
97
+ */
98
+ export function panelQuestionText(q) {
99
+ const text = String(q.question);
100
+ if (q.source !== 'look') return text;
101
+ const tails = [`${READING_ANSWER}${readingRest(q.line)}`, cantCheckTail(q.line), columnTail(q.line), ` ${HOW_TO_ANSWER(q.line, true)}`, ` ${HOW_TO_ANSWER(q.line, false)}`];
102
+ const hit = tails.find((t) => text.endsWith(t));
103
+ return hit === undefined ? text : text.slice(0, text.length - hit.length);
104
+ }
105
+
84
106
  /**
85
107
  * The early asks CODE forces before any paid drafting, from the look's own result. One ask per rule text on a line; readings first, then can't-check
86
108
  * asks, each in line order. The caller applies the cap and the answer gate.
@@ -118,7 +140,7 @@ export function askableFromLook(look, jobLines) {
118
140
  seen.add(key);
119
141
  cants.push({
120
142
  line: l.n, rule: n, source: 'look', ask: 'cant-check', ruleText: rule,
121
- question: `Your line ${l.n} says "${rule}". I can't check this on the page. Drop it? Answer "${DROP_IT}", or type how to check it (your answer is added as a new ~ rule on line ${l.n}).`,
143
+ question: `Your line ${l.n} says "${rule}". I can't check this on the page. Drop it?${cantCheckTail(l.n)}`,
122
144
  });
123
145
  });
124
146
  }
@@ -144,12 +166,18 @@ export function tooManyAsksText(asks) {
144
166
  * person's own words, taken word for word with newlines folded to spaces. A question that is not a look ask is never changed: its answer is its rule.
145
167
  * M10 am16: a shape guardrail's ask (`ask: 'check'` proposes a check, `'no-check'` found none) takes the same words: `agree` takes the proposal (and the check it
146
168
  * carries, `check`), `drop it` leaves the rule Not checked (either kind), anything else is the person's own words (`own`: a `~` rule on the line, no check).
147
- * @param {{source?: string, ask?: string, proposal?: string|null, check?: Record<string, any>}} q @param {unknown} typed
169
+ * @param {{source?: string, ask?: string, proposal?: string|null, check?: Record<string, any>}} q @param {unknown} typed @param {'agree'|'drop'|'rule'} [choice] M10 am29: the button used; absent = today's words reading (CLI, old files)
148
170
  * @returns {{rule: string|null, left: boolean, check?: Record<string, any>, own?: boolean}} `rule` = the words written as a new `~` rule (null when the rule is left Not checked)
149
171
  */
150
- export function ruleOfAnswer(q, typed) {
172
+ export function ruleOfAnswer(q, typed, choice) {
151
173
  const typedText = String(typed ?? '').replace(/\s*\n\s*/g, ' ').trim();
152
174
  if (q.source !== 'look') return { rule: typedText, left: false };
175
+ if (choice !== undefined) { // M10 am29: a typed choice decides, never the words; the box (`rule`) keeps its words whole
176
+ const shapeC = q.ask === 'check' || q.ask === 'no-check';
177
+ if (choice === 'agree' && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check')) return { rule: q.proposal, left: false, ...(q.ask === 'check' && q.check ? { check: q.check } : {}) };
178
+ if (choice === 'drop') return { rule: null, left: true };
179
+ return { rule: typedText, left: false, ...(shapeC ? { own: true } : {}) };
180
+ }
153
181
  const text = stripAgreeLead(typedText); // F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
154
182
  const shape = q.ask === 'check' || q.ask === 'no-check';
155
183
  if ((q.ask === 'reading' || q.ask === 'check') && typeof q.proposal === 'string' && isAgree(text)) return { rule: q.proposal, left: false, ...(q.ask === 'check' && q.check ? { check: q.check } : {}) };
@@ -38,7 +38,7 @@ import { fileURLToPath } from 'node:url';
38
38
  import {
39
39
  ANSWER_FILE, NOT_CHECKED_FILE, OPEN_QUESTION_SAY, PANEL_DRAFTS_DIR, readQuestions, readoutHeadIndexes, scrub, signDraft,
40
40
  } from '../authoring.js';
41
- import { ruleOfAnswer } from '../pageask.js';
41
+ import { ruleOfAnswer, panelQuestionText, DROP_IT } from '../pageask.js';
42
42
  import { checkFlowName, nextRunId, readFileInside, readdirInside } from '../flow.js';
43
43
  import { readModelRecord } from '../flowmodel.js';
44
44
  import { isFwdloopAlive } from '../liveness.js';
@@ -279,7 +279,7 @@ export function createAuthor(opts) {
279
279
  const q = rel === 'draft' ? firstQs : readQuestions(join(dir, rel));
280
280
  if (q.open.length > 0) {
281
281
  const lineText = (line) => parseJobBox(typeof card?.job === 'string' ? card.job : '').steps[line - 1]?.text ?? null;
282
- const questions = q.questions.map((x) => ({ k: x.k, line: x.line, lineText: lineText(x.line), question: scrub(x.question, keys), answered: x.answer !== null, ...(x.source === 'look' ? { source: 'look' } : {}) }));
282
+ const questions = q.questions.map((x) => ({ k: x.k, line: x.line, lineText: lineText(x.line), question: scrub(x.question, keys), answered: x.answer !== null, ...(x.source === 'look' ? { source: 'look', ask: x.ask, proposes: typeof x.proposal === 'string' && (x.ask === 'reading' || x.ask === 'check'), drops: Number.isInteger(x.ruleNo), shown: scrub(panelQuestionText(x), keys) } : {}) }));
283
283
  return { ...shared, stepList: stepListOf(dir, rel, keys, true), phase: 'questions-open', plan: rel, questions, openK: q.open[0].k, total: q.questions.length };
284
284
  }
285
285
  if (q.questions.length > 0) return { ...shared, phase: 'stopped', say: ANSWERS_NOT_DRAFTED_SAY };
@@ -750,7 +750,16 @@ export function createAuthor(opts) {
750
750
  // space (one `~` line is one line) instead of refused. Every other question keeps its own gate (blank, one line).
751
751
  const look = q.source === 'look';
752
752
  // hamr 2026-11-07 (ruling 2A): a leading `~` the person typed is dropped quietly (the job line adds its own); the ONE place, so a tilde-only answer is a blank answer
753
- const answer = typeof b.answer === 'string' ? (look ? b.answer.replace(/\s*\n\s*/g, ' ') : b.answer).trim().replace(/^(?:~\s*)+/, '') : '';
753
+ // M10 am29: the button used rides as a typed `choice`; absent = the words reading (CLI and old pages). agree needs a proposal, drop/agree are look asks only.
754
+ const choice = b.choice;
755
+ // M10 am32 A: every new answer carries its button's choice; an answer with none is refused before anything is written (old answer files are still read by the readers)
756
+ if (choice === undefined) return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'This page is out of date. Reload it and answer again. Nothing was saved.' } };
757
+ {
758
+ const proposes = look && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check');
759
+ if (choice !== 'agree' && choice !== 'drop' && choice !== 'rule') return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That answer is not one of the choices. Nothing was saved.' } };
760
+ if ((choice === 'agree' && !proposes) || (choice === 'drop' && !look)) return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That choice is not offered for this question. Nothing was saved.' } };
761
+ }
762
+ const answer = choice === 'agree' ? 'agree' : choice === 'drop' ? DROP_IT : typeof b.answer === 'string' ? (look ? b.answer.replace(/\s*\n\s*/g, ' ') : b.answer).trim().replace(/^(?:~\s*)+/, '') : '';
754
763
  if (answer === '') return { status: 400, body: { ok: false, refused: 'blank-answer', say: look ? LOOK_BLANK_ANSWER_SAY : BLANK_ANSWER_SAY } };
755
764
  if (!look && /[\r\n]/.test(answer)) return { status: 400, body: { ok: false, refused: 'one-line', say: ONE_LINE_ANSWER_SAY } };
756
765
  if (keys.some((k) => k.length >= 8 && answer.includes(k))) return { status: 400, body: { ok: false, refused: 'key', say: 'This answer contains an API key. Keys go in Settings only. Nothing was saved.' } };
@@ -759,14 +768,17 @@ export function createAuthor(opts) {
759
768
  const answerFile = join(planDir, ANSWER_FILE(v.openK));
760
769
  const at = new Date().toISOString();
761
770
  // what this answer does (ruleOfAnswer, the one place): the `~` rule it adds, or the rule it leaves Not checked
762
- const effect = ruleOfAnswer(q, answer);
771
+ const effect = ruleOfAnswer(q, answer, choice);
772
+ // M10 am30: a rule left Not checked is a `<line>.<rule>` pair, so only a question about one of the person's `~` rules (an integer ruleNo) can be dropped; any other drop is refused here, nothing written, nothing sent to the drafter
773
+ if (effect.left && !Number.isInteger(q.ruleNo)) return { status: 400, body: { ok: false, refused: 'bad-choice', say: 'That question is about the job line, not one of your ~ rules, so there is nothing to drop. Agree, or type your own words. Nothing was saved.' } };
763
774
  // the whole redraft is checked at $0 BEFORE the answer is written, so a refusal leaves the question open and nothing on disk
764
775
  /** @type {any} */
765
776
  let redraft = null;
766
777
  if (last) {
767
778
  const all = full.map((x) => {
768
779
  const typed = x.k === v.openK ? answer : x.answer;
769
- return { line: x.line, question: x.question, answer: typed, ...ruleOfAnswer(x, typed), ruleNo: x.ruleNo, ruleText: x.ruleText, ask: x.ask, ...(x.pairRule === undefined ? {} : { pairRule: x.pairRule }) };
780
+ const ch = x.k === v.openK ? choice : x.choice;
781
+ return { line: x.line, question: x.question, answer: typed, ...ruleOfAnswer(x, typed, ch), ruleNo: x.ruleNo, ruleText: x.ruleText, ask: x.ask, ...(x.pairRule === undefined ? {} : { pairRule: x.pairRule }) };
770
782
  });
771
783
  const adds = all.filter((x) => x.rule !== null);
772
784
  const grown = applyAnswers(typeof v.card.job === 'string' ? v.card.job : '', all);
@@ -784,7 +796,7 @@ export function createAuthor(opts) {
784
796
  try {
785
797
  // the human row of the draft log (am2 item 4): the question, the answer, the line, the time; a look ask also carries what code proposed and the rule the answer added, as their own fields
786
798
  writeFileSync(answerFile, `${JSON.stringify({
787
- k: v.openK, line: q.line, question: q.question, answer, at,
799
+ k: v.openK, line: q.line, question: q.question, answer, ...(choice === undefined ? {} : { choice }), at,
788
800
  ...(look ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: effect.rule } : {}),
789
801
  })}\n`, { mode: 0o600, flag: 'wx' });
790
802
  } catch (e) {
package/src/panel/data.js CHANGED
@@ -42,6 +42,7 @@ import { readSetup } from '../setup.js';
42
42
  import { parseHintBlock } from '../learn.js';
43
43
  import { checkedLines, notCheckedView, NOT_CHECKED_LABEL } from '../checked.js';
44
44
  import { LABEL_PICKED } from '../checkwords.js';
45
+ import { panelQuestionText } from '../pageask.js';
45
46
  import { csvRolesOf, askSheetCard } from '../sheetblock.js';
46
47
  import { readSheetChecks } from '../sheet-record.js';
47
48
  import {
@@ -1941,7 +1942,7 @@ export function getDraftBlock(flowDir, runDir) {
1941
1942
  rows.push(human(r, n, { action: 'card (you)', gap }));
1942
1943
  } else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
1943
1944
  // M10 am2 item 4: a question the page look raised and your answer, under the drafting step, in bareloop's words (`you were asked:` / `you said:`)
1944
- else if (r.kind === 'human') rows.push(human(r, n, { action: `you were asked: ${r.question}`, gap: `you said: ${r.answer}${r.source === 'look' && typeof r.rule === 'string' && r.rule !== '' ? ` ${LABEL_PICKED}` : ''}` }));
1945
+ else if (r.kind === 'human') rows.push(human(r, n, { action: `you were asked: ${panelQuestionText(r)}`, gap: `you said: ${r.answer}${r.source === 'look' && typeof r.rule === 'string' && r.rule !== '' ? ` ${LABEL_PICKED}` : ''}` }));
1945
1946
  else if (r.kind === 'draft') { rows.push(model(r, n, 'draft')); rows.push(...tryRows(r, n)); }
1946
1947
  else if (r.kind === 'change') { rows.push(model(r, n, `change ${r.n}`)); rows.push(...tryRows(r, n)); }
1947
1948
  else if (r.kind === 'startover') { rows.push(model(r, n, 'start over')); rows.push(...tryRows(r, n)); }
@@ -740,6 +740,10 @@
740
740
  .chat-question .q-line{font-size:12px;color:var(--text-faint);margin-top:4px;overflow-wrap:anywhere;}
741
741
  .chat-question .q-text{font-size:13px;margin-top:4px;overflow-wrap:anywhere;white-space:pre-wrap;}
742
742
  .chat-question textarea{display:block;width:100%;max-width:100%;box-sizing:border-box;margin-top:8px;min-height:3.4em;font:inherit;padding:6px 8px;border:1px solid var(--border-strong);border-radius:0;background:var(--bg);color:var(--text);resize:vertical;}
743
+ .chat-question .q-choices{display:flex;flex-wrap:wrap;gap:8px;margin-top:8px;}
744
+ .chat-question .q-choices .btn{flex:1 1 auto;min-width:0;}
745
+ .chat-question .q-or{display:block;font-size:12px;color:var(--text-faint);margin-top:8px;text-transform:none;letter-spacing:normal;font-weight:normal;}
746
+ .chat-question .q-or + textarea{margin-top:4px;}
743
747
  .chat-question .q-err{color:var(--red);}
744
748
  .chat-extras{display:flex;flex-direction:column;gap:10px;margin-bottom:10px;}
745
749
  .chat-extras:empty{display:none;}
@@ -1398,6 +1402,11 @@
1398
1402
  <div class="q-head" id="chat-q-head" data-testid="chat-q-head"></div>
1399
1403
  <div class="q-line" id="chat-q-line" data-testid="chat-q-line"></div>
1400
1404
  <div class="q-text" id="chat-q-text" data-testid="chat-q-text"></div>
1405
+ <div class="q-choices" id="chat-q-choices" data-testid="chat-q-choices" hidden>
1406
+ <button class="btn small" type="button" id="chat-q-agree" data-testid="chat-q-agree" hidden>Agree</button>
1407
+ <button class="btn small" type="button" id="chat-q-drop" data-testid="chat-q-drop" hidden>Drop it</button>
1408
+ </div>
1409
+ <label class="q-or" id="chat-q-or" data-testid="chat-q-or" for="chat-q-answer">Or type a new rule:</label>
1401
1410
  <textarea id="chat-q-answer" data-testid="chat-q-answer" rows="2" autocomplete="off" spellcheck="false" aria-label="Your answer" placeholder="Your answer, on one line"></textarea>
1402
1411
  <div class="hint q-err" id="chat-q-error" data-testid="chat-q-error" role="alert"></div>
1403
1412
  <button class="btn primary wide" type="button" id="chat-q-send" data-testid="chat-q-send">Send</button>
@@ -5533,6 +5542,9 @@
5533
5542
  var qAnswer = document.getElementById("chat-q-answer");
5534
5543
  var qError = document.getElementById("chat-q-error");
5535
5544
  var qSend = document.getElementById("chat-q-send");
5545
+ var qChoices = document.getElementById("chat-q-choices");
5546
+ var qAgree = document.getElementById("chat-q-agree");
5547
+ var qDrop = document.getElementById("chat-q-drop");
5536
5548
  var extrasEl = document.getElementById("chat-extras");
5537
5549
  var newBox = document.getElementById("jf-new");
5538
5550
  var runBox = document.getElementById("jf-run");
@@ -5781,13 +5793,13 @@
5781
5793
  if(!q) return null;
5782
5794
  // M10 am2 item 1 / am5 item 1: a question the page look raised is ONE plain chat message (bareloop's words); the head and line rows stay empty
5783
5795
  if(q.source === "look"){
5784
- return { key: String(state.draftId) + ":" + q.k, k: q.k, head: "", line: "", question: "A question the plan raised (" + q.k + " of " + state.total + "), about job line " + q.line + ": " + q.question };
5796
+ return { key: String(state.draftId) + ":" + q.k, k: q.k, head: "", line: "", question: "A question the plan raised (" + q.k + " of " + state.total + "), about job line " + q.line + ": " + (typeof q.shown === "string" ? q.shown : q.question), agree: q.proposes === true, drop: q.drops === true };
5785
5797
  }
5786
5798
  return {
5787
5799
  key: String(state.draftId) + ":" + q.k, k: q.k,
5788
5800
  head: "A question the plan raised (" + q.k + " of " + state.total + ")",
5789
5801
  line: q.lineText ? "About job line " + q.line + ": " + q.lineText : "About job line " + q.line,
5790
- question: q.question
5802
+ question: q.question, agree: false, drop: false
5791
5803
  };
5792
5804
  }
5793
5805
  // pure: what sits beside a green plan: Your answers (only when the plan was drafted with some), Checked (the machine's sentences from the
@@ -6648,6 +6660,8 @@
6648
6660
  qKey = v.key;
6649
6661
  qHead.textContent = v.head; qLine.textContent = v.line; qText.textContent = v.question;
6650
6662
  qHead.hidden = v.head === ""; qLine.hidden = v.line === ""; // a look question is one plain message: no empty rows
6663
+ // M10 am29: every question has the labelled box; a look question also has Agree (only when it proposes something) and Drop it
6664
+ qAgree.hidden = !v.agree; qDrop.hidden = !v.drop; qChoices.hidden = !(v.agree || v.drop);
6651
6665
  qAnswer.value = ""; qError.textContent = "";
6652
6666
  }
6653
6667
  }
@@ -6843,17 +6857,19 @@
6843
6857
  }
6844
6858
 
6845
6859
  // Send (amendments 24/25): the answer to the question now open. A blank answer is refused by the server in plain words and the question stays open.
6846
- function doAnswer(){
6860
+ // M10 am29: a choice button posts its own choice and nothing else; the box's button posts the box's words as a new rule (choice "rule"), never read as agree or drop it
6861
+ function doAnswer(choice){
6847
6862
  if(qBusy || !sessionId || !lastState || lastState.phase !== "questions-open") return;
6848
- qBusy = true; qSend.disabled = true; qError.textContent = "";
6863
+ qBusy = true; qSend.disabled = true; qAgree.disabled = true; qDrop.disabled = true; qError.textContent = "";
6849
6864
  var id = sessionId;
6850
- authorPost("/api/author/" + id + "/answer", {k: lastState.openK, answer: qAnswer.value}).then(function(r){
6851
- qBusy = false; qSend.disabled = false;
6865
+ var body = choice === "agree" || choice === "drop" ? {k: lastState.openK, choice: choice} : {k: lastState.openK, answer: qAnswer.value, choice: "rule"};
6866
+ authorPost("/api/author/" + id + "/answer", body).then(function(r){
6867
+ qBusy = false; qSend.disabled = false; qAgree.disabled = false; qDrop.disabled = false;
6852
6868
  if(id !== sessionId) return;
6853
6869
  if(!(r.status >= 200 && r.status < 300 && r.body && r.body.ok === true)){ qError.textContent = refusalText(r); return; }
6854
6870
  qAnswer.value = "";
6855
6871
  poll();
6856
- }).catch(function(){ qBusy = false; qSend.disabled = false; qError.textContent = NETWORK_SAY; });
6872
+ }).catch(function(){ qBusy = false; qSend.disabled = false; qAgree.disabled = false; qDrop.disabled = false; qError.textContent = NETWORK_SAY; });
6857
6873
  }
6858
6874
  function doDraft(startedOverFrom){
6859
6875
  clearFieldErrors();
@@ -7098,8 +7114,10 @@
7098
7114
  reviseBtn.addEventListener("click", function(){ if(reviseBtn.disabled) return; if(lastState && lastState.card) fillCardFields(lastState.card); reviseOpen = true; refreshStartEnabled(); fitCardBoxes(); });
7099
7115
  // Start over (amendment 14 item 3): the same draft call as Draft, from the card as it is now; the old draft's files stay (a new draft id, 2 new revises)
7100
7116
  startOverBtn.addEventListener("click", function(){ if(!startOverBtn.disabled) doDraft(sessionId); });
7101
- qSend.addEventListener("click", doAnswer);
7102
- qAnswer.addEventListener("keydown", function(e){ if(e.key === "Enter" && !e.shiftKey){ e.preventDefault(); doAnswer(); } });
7117
+ qSend.addEventListener("click", function(){ doAnswer("rule"); });
7118
+ qAgree.addEventListener("click", function(){ doAnswer("agree"); });
7119
+ qDrop.addEventListener("click", function(){ doAnswer("drop"); });
7120
+ qAnswer.addEventListener("keydown", function(e){ if(e.key === "Enter" && !e.shiftKey){ e.preventDefault(); doAnswer("rule"); } });
7103
7121
  mainBtn.addEventListener("click", function(){
7104
7122
  if(mainBtn.disabled) return;
7105
7123
  if(mainAction === "draft") doDraft(mainStartOver ? sessionId : null);
@@ -144,7 +144,8 @@ export function confirmedFactNames(setupRows, lineN, signedRule, factNames) {
144
144
  const names = new Set();
145
145
  const written = lineRules({ rule: signedRule });
146
146
  for (const h of Array.isArray(setupRows) ? setupRows : []) {
147
- if (h?.kind !== 'human' || h.source !== 'look' || h.line !== lineN || !isAgree(h.answer)) continue; // eslint-disable-line no-continue
147
+ // M10 am29: a row that records its typed choice is read by it (a box answer "agree" is a rule, never a confirmation); the words only when the row has none
148
+ if (h?.kind !== 'human' || h.source !== 'look' || h.line !== lineN || !(typeof h.choice === 'string' ? h.choice === 'agree' : isAgree(h.answer))) continue; // eslint-disable-line no-continue
148
149
  const reading = readingOfQuestion(h.question);
149
150
  if (reading === null || !written.includes(reading)) continue; // eslint-disable-line no-continue
150
151
  for (const name of factNames) if (reading.startsWith(`${name} `)) names.add(name);
package/src/setup.js CHANGED
@@ -61,22 +61,28 @@ function planRow(sessionDir, rel, kind, n) {
61
61
  }
62
62
 
63
63
  /**
64
- * M10 am2 item 4: one row per question the page look raised and the person answered, in the plan folder that raised it (the draft log's human rows, read
65
- * from the answer files). The question, the answer, the line and the time, plus the proposal and the rule the answer added as their own fields (never cut
64
+ * M10 am2 item 4 (and M14 am3: also a question the drafter raised): one row per question the plan asked and the person answered, in the plan folder that
65
+ * raised it (the draft log's human rows, read from the answer files). The question, the answer, the line and the time, plus the proposal and the rule the answer added as their own fields (never cut
66
66
  * out of the question text). A question nobody answered leaves no row.
67
67
  * @param {string} sessionDir @param {string} rel
68
68
  */
69
69
  function humanRows(sessionDir, rel) {
70
- const answered = readQuestions(join(sessionDir, rel)).questions.filter((q) => q.source === 'look' && q.answer !== null).map((q) => ({
70
+ /** @type {any[]} the look rows carry look-only fields (and a recorded choice), the drafter rows do not */
71
+ const answered = readQuestions(join(sessionDir, rel)).questions.filter((q) => q.answer !== null).map((q) => (q.source === 'look' ? {
71
72
  kind: 'human', n: q.k, at: q.at ?? null, source: 'look', ask: q.ask, question: q.question, answer: q.answer, line: q.line,
72
- ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: q.rule ?? null,
73
+ ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: q.rule ?? null, ...(q.choice === undefined ? {} : { choice: q.choice }),
74
+ } : {
75
+ // M14 am3: a question the drafter raised and the person answered is the same row, with no look-only fields (so no picked label)
76
+ kind: 'human', n: q.k, at: q.at ?? null, question: q.question, answer: q.answer, line: q.line,
73
77
  }));
78
+ // a kept row's n counts the answered LOOK rows only, as before M14 am3 (a page-look row never changes)
79
+ const lookAnswered = answered.filter((r) => r.source === 'look').length;
74
80
  // M10 am17 (6): a pick kept from the last draft is the same row, from this plan's picks record (not an answer file), its answer being the words `kept from last draft`
75
81
  const kept = Array.isArray(readJson(join(sessionDir, rel), RECORD_FILE)?.kept) ? readJson(join(sessionDir, rel), RECORD_FILE).kept : [];
76
82
  const keptRows = kept.map((k, i) => {
77
83
  const [ask] = checkAsks([{ line: k.line, rule: k.rule, text: k.ruleText, check: k.check ?? null, why: null }]);
78
84
  return {
79
- kind: 'human', n: answered.length + i + 1, at: null, source: 'look', ask: ask.ask, question: ask.question, answer: KEPT_WORDS, line: k.line,
85
+ kind: 'human', n: lookAnswered + i + 1, at: null, source: 'look', ask: ask.ask, question: ask.question, answer: KEPT_WORDS, line: k.line,
80
86
  ruleNo: k.rule, ruleText: k.ruleText, proposal: ask.reading ?? null, rule: k.added ?? null,
81
87
  };
82
88
  });
package/src/sheetfind.js CHANGED
@@ -47,4 +47,6 @@ export function findColumn(csvText, word) {
47
47
  * `no column 'Price'; 'Amount' has numbers in 40 of 40 rows. Use it? Answer "agree", or type your own words (your answer is added as a new ~ rule on line N).`
48
48
  * @param {string} word @param {FoundAsk} found @param {number} line @returns {string}
49
49
  */
50
- export const columnQuestion = (word, found, line) => `no column '${word}'; '${found.column}' has numbers in ${found.numbers} of ${found.rows} rows. Use it? Answer "agree", or type your own words (your answer is added as a new ~ rule on line ${line}).`;
50
+ export const columnQuestion = (word, found, line) => `no column '${word}'; '${found.column}' has numbers in ${found.numbers} of ${found.rows} rows. Use it?${columnTail(line)}`;
51
+ /** @param {number} line @returns {string} the answer words the column question ends with (M10 am29: the panel cuts exactly this) */
52
+ export const columnTail = (line) => ` Answer "agree", or type your own words (your answer is added as a new ~ rule on line ${line}).`;
package/src/sheetlook.js CHANGED
@@ -104,8 +104,8 @@ export function applySheetWords(text, words, jobLines, label) {
104
104
  if (w.kind !== 'number') { dropped.push({ ...rec, reason: 'no-column' }); continue; }
105
105
  if (found.kind === 'tie') { dropped.push({ ...rec, reason: 'column-tie', other: found.columns.map((c) => `"${c}"`).join(', ') }); continue; }
106
106
  if (found.kind === 'none') { dropped.push({ ...rec, reason: 'no-fit', other: String(found.rows) }); continue; }
107
- // the person already named this column in ANOTHER rule of the line (an answer they gave, or their own words): the word is that column, asked no more
108
- if (rules.some((r, i) => i + 1 !== at.rule && countPhrase(r, found.column) > 0)) { facts.push(fact(found.column)); continue; }
107
+ // the person already named this column in a rule of the line (an answer they gave, or their own words): the word is that column, asked no more
108
+ if (rules.some((r, i) => countPhrase(r, found.column) > 0)) { facts.push(fact(found.column)); continue; }
109
109
  asks.push({
110
110
  line: at.line, rule: at.rule ?? null, source: 'look', ask: 'reading', ruleText, question: columnQuestion(w.word, found, at.line), reading: columnRuleWords(w.word, found.column), word: w.word, column: found.column,
111
111
  });
package/src/sheetoffer.js CHANGED
@@ -111,7 +111,7 @@ export function sheetOfferRules(roles) {
111
111
  `- A green step whose line has a guardrail about values in a CSV input (${roles.join(', ')}) lists that input's role in its reads and carries close.sheet = a list of 1 to ${MAX_SHEET_CHECKS} checks, each a bareguard check object from the ops below, with "table" = the CSV input's role. Write the checks the line's guardrail needs and nothing else; the person signs them. close.sheet is for a green step only.`,
112
112
  '- A column name in a check is picked from the sheet\'s header, spelled exactly; the tool only lets you pick a header name. A check that bareguard refuses (a wrong field for the op, overlapping bands, a missing dateFormats entry) is refused at $0 naming the job line.',
113
113
  '- A number in a where condition (gt, gte, lt, lte, eq, between) must be a number the person wrote on that job line or its guardrail; a date (asOf, and the values of before, after, dateOn, dateBetween) must be a date they wrote there as YYYY-MM-DD. Never make a number or a date up: if the person gave none, leave that condition out.',
114
- '- A "cells" check names "claim", a short name for the answer the step gives; the step is told only the shape of the answer, never the check. A "table" check has no claim and judges the sheet itself. If every check of a step is a table check the step has nothing to answer and the line is refused: pair a table check with at least one cells check.',
114
+ '- A "cells" check names "claim", a short name for the answer the step gives; the step is told only the shape of the answer, never the check. A "table" check has no claim and judges the input sheet itself, so it must already hold on that sheet (one that fails on it is refused); to check what a step gives, use a cells check. If every check of a step is a table check the step has nothing to answer and the line is refused: pair a table check with at least one cells check.',
115
115
  '- "covers" on each check lists the numbers of the line\'s guardrail rules (the ~ parts, counted from 1 in the order shown) that this check really verifies; [] if none. A guardrail rule that no check covers is shown to the person as Not checked, so cover every rule you can with a real check, and never claim a rule a check does not verify. A rule shaped like "use the column \'X\' for \'Y\'" is a column choice, not a rule to cover.',
116
116
  ...sheetOpsBrief(),
117
117
  ];
package/src/sheetrun.js CHANGED
@@ -103,3 +103,30 @@ export async function closeSheet(checks, artifact, sheet) {
103
103
  return /** @type {any} */ ({ verdict: 'crash', red: `sheet close crashed: ${/** @type {any} */ (err).message}` });
104
104
  }
105
105
  }
106
+
107
+ /**
108
+ * M10b am5: the `table` checks of a draft that already fail on the sheet the draft was made with. A table check judges the sheet itself, so bareguard's `checkStep` (the
109
+ * run's own judge, `closeSheet`) can run it before anything is spent: $0, no model call. Only `table` checks run; a cells check judges the step's answer and never runs here.
110
+ * Each check is read by its id, so bareguard's own `happened` check never counts; the answer handed over is non-empty, because an EMPTY one stops bareguard at `happened` before any
111
+ * table check runs (the check would then read as passing).
112
+ * @param {any} declaration the draft @param {Record<string, {header: string[], rows: any[]}>} tables the draft-time table of each CSV input, by role
113
+ * @returns {Promise<string[]>} one red per failing check, in plan order
114
+ */
115
+ export async function tableChecksFailingOnInput(declaration, tables) {
116
+ const reds = [];
117
+ for (const s of Array.isArray(declaration?.steps) ? declaration.steps : []) {
118
+ const list = s?.close?.class === 'green' && Array.isArray(s.close.sheet) ? s.close.sheet : [];
119
+ for (const c of list) {
120
+ if (!isRec(c) || c.rule !== 'table' || typeof c.table !== 'string' || !isRec(tables[c.table])) continue;
121
+ const sha = tableSha(tables[c.table]);
122
+ if (sha === null) continue; // bareguard cannot read the sheet as a table: the draft's own sheet look has said so
123
+ const sheet = { ok: /** @type {const} */ (true), tables: { [c.table]: tables[c.table] }, inputs: [{ name: c.table, sha256: sha }] };
124
+ const v = /** @type {any} */ (await closeSheet([c], { done: true }, sheet));
125
+ const row = Array.isArray(v.checks) ? v.checks.find((/** @type {any} */ r) => r.id === c.id) : undefined;
126
+ if (!row || row.ok) continue;
127
+ const what = String(row.result).startsWith(`${c.id}: `) ? String(row.result).slice(c.id.length + 2) : String(row.result);
128
+ reds.push(`line ${s.fromLine}: the table check "${sheetCheckName(c)}" already fails on the input "${c.table}" (${what}), so this step could never pass. A table check judges the input sheet itself; to check what the step gives, use a cells check.`);
129
+ }
130
+ }
131
+ return reds;
132
+ }
@@ -23,7 +23,7 @@ export function specHash({ proseText, declarationText, inputFactsText, readoutTe
23
23
  * answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
24
24
  * @param {string} planDir
25
25
  * A question the page look raised (M10 piece 3) also carries `source: 'look'`, `ask` ('reading' | 'cant-check'), `ruleNo`, `ruleText` and `proposal`; an answer file carries `at`.
26
- * @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number}[], open: {k:number, line:number, question:string, answer:null}[] }}
26
+ * @returns {{ questions: {k:number, line:number, question:string, answer:string|null, at?:string, rule?:string|null, choice?:'agree'|'drop'|'rule', source?:string, ask?:string, ruleNo?:number, ruleText?:string, proposal?:string|null, check?:Record<string, any>, pairRule?:number}[], open: {k:number, line:number, question:string, answer:null}[] }}
27
27
  */
28
28
  export function readQuestions(planDir: string): {
29
29
  questions: {
@@ -33,6 +33,7 @@ export function readQuestions(planDir: string): {
33
33
  answer: string | null;
34
34
  at?: string;
35
35
  rule?: string | null;
36
+ choice?: "agree" | "drop" | "rule";
36
37
  source?: string;
37
38
  ask?: string;
38
39
  ruleNo?: number;
@@ -168,6 +168,7 @@ export const SUGGEST_SCHEMA: Readonly<{
168
168
  }>;
169
169
  /** the can't-check ask, as the signed words say it */
170
170
  export const CANT_CHECK_WORDS: "I can't check this. Your own words, or Not checked?";
171
+ export function HOW_TO_ANSWER(line: number, agree: boolean): string;
171
172
  /**
172
173
  * `check` = the check the person agreed to (null for their own words); `added` = the `~` rule the answer wrote on the line; `own` = their own words
173
174
  */
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @param {unknown} raw
3
+ * @returns {{ value: Record<string, any>, dropped: string } | null}
4
+ */
5
+ export function repairTrailingBraces(raw: unknown): {
6
+ value: Record<string, any>;
7
+ dropped: string;
8
+ } | null;
@@ -7,6 +7,16 @@ export function moneyAs(f: any, n: string | number, symbolFirst: boolean): strin
7
7
  export function ruleWords(f: any): string;
8
8
  /** @param {unknown} q a recorded question @returns {string|null} the reading a reading ask proposed, or null when it was another kind of question */
9
9
  export function readingOfQuestion(q: unknown): string | null;
10
+ /**
11
+ * M10 am29: a look question as the PANEL shows it: the code's own answer words (`Answer "agree"…` / `answer "drop it"…`) cut off the end, because the buttons and the box say it.
12
+ * Only the known tails are cut, matched exactly as a suffix (never a pattern over the prose); a question that ends in none of them is returned whole. The stored question is never changed.
13
+ * @param {{question: string, line: number, source?: string}} q @returns {string}
14
+ */
15
+ export function panelQuestionText(q: {
16
+ question: string;
17
+ line: number;
18
+ source?: string;
19
+ }): string;
10
20
  /**
11
21
  * The early asks CODE forces before any paid drafting, from the look's own result. One ask per rule text on a line; readings first, then can't-check
12
22
  * asks, each in line order. The caller applies the cap and the answer gate.
@@ -46,7 +56,7 @@ export function tooManyAsksText(asks: {
46
56
  * person's own words, taken word for word with newlines folded to spaces. A question that is not a look ask is never changed: its answer is its rule.
47
57
  * M10 am16: a shape guardrail's ask (`ask: 'check'` proposes a check, `'no-check'` found none) takes the same words: `agree` takes the proposal (and the check it
48
58
  * carries, `check`), `drop it` leaves the rule Not checked (either kind), anything else is the person's own words (`own`: a `~` rule on the line, no check).
49
- * @param {{source?: string, ask?: string, proposal?: string|null, check?: Record<string, any>}} q @param {unknown} typed
59
+ * @param {{source?: string, ask?: string, proposal?: string|null, check?: Record<string, any>}} q @param {unknown} typed @param {'agree'|'drop'|'rule'} [choice] M10 am29: the button used; absent = today's words reading (CLI, old files)
50
60
  * @returns {{rule: string|null, left: boolean, check?: Record<string, any>, own?: boolean}} `rule` = the words written as a new `~` rule (null when the rule is left Not checked)
51
61
  */
52
62
  export function ruleOfAnswer(q: {
@@ -54,7 +64,7 @@ export function ruleOfAnswer(q: {
54
64
  ask?: string;
55
65
  proposal?: string | null;
56
66
  check?: Record<string, any>;
57
- }, typed: unknown): {
67
+ }, typed: unknown, choice?: "agree" | "drop" | "rule"): {
58
68
  rule: string | null;
59
69
  left: boolean;
60
70
  check?: Record<string, any>;
@@ -13,6 +13,7 @@ export function findColumn(csvText: string, word: string): FoundHeader | FoundAs
13
13
  /** a column fits when a plain number fills at least this share of the rows (F71 (b)) */
14
14
  export const FIT_RATIO: 0.9;
15
15
  export function columnQuestion(word: string, found: FoundAsk, line: number): string;
16
+ export function columnTail(line: number): string;
16
17
  /**
17
18
  * the word IS a column (nothing to ask)
18
19
  */
@@ -33,3 +33,15 @@ export function readRunSheets(runDir: string, checks: any[]): {
33
33
  * @returns {Promise<import('./types.js').CloseVerdict>}
34
34
  */
35
35
  export function closeSheet(checks: any[], artifact: unknown, sheet: ReturnType<typeof readRunSheets> | null | undefined): Promise<import("./types.js").CloseVerdict>;
36
+ /**
37
+ * M10b am5: the `table` checks of a draft that already fail on the sheet the draft was made with. A table check judges the sheet itself, so bareguard's `checkStep` (the
38
+ * run's own judge, `closeSheet`) can run it before anything is spent: $0, no model call. Only `table` checks run; a cells check judges the step's answer and never runs here.
39
+ * Each check is read by its id, so bareguard's own `happened` check never counts; the answer handed over is non-empty, because an EMPTY one stops bareguard at `happened` before any
40
+ * table check runs (the check would then read as passing).
41
+ * @param {any} declaration the draft @param {Record<string, {header: string[], rows: any[]}>} tables the draft-time table of each CSV input, by role
42
+ * @returns {Promise<string[]>} one red per failing check, in plan order
43
+ */
44
+ export function tableChecksFailingOnInput(declaration: any, tables: Record<string, {
45
+ header: string[];
46
+ rows: any[];
47
+ }>): Promise<string[]>;