fwdloop 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/package.json +2 -2
  2. package/src/added-end.js +60 -0
  3. package/src/authoring.js +14 -8
  4. package/src/checked.js +11 -9
  5. package/src/checkpick.js +67 -6
  6. package/src/checkwords.js +5 -0
  7. package/src/citedcheck.js +14 -0
  8. package/src/closers.js +32 -2
  9. package/src/declaration.js +49 -2
  10. package/src/draft-steps.js +3 -3
  11. package/src/drafter.js +41 -9
  12. package/src/jobkey.js +3 -1
  13. package/src/model-step.js +14 -8
  14. package/src/pageask.js +36 -5
  15. package/src/panel/author.js +17 -6
  16. package/src/panel/authorcard.js +12 -8
  17. package/src/panel/data.js +5 -3
  18. package/src/panel/index.html +42 -10
  19. package/src/panel/result.js +2 -1
  20. package/src/plain-checks.js +15 -3
  21. package/src/provider.js +1 -1
  22. package/src/repairs.js +38 -0
  23. package/src/runner.js +47 -10
  24. package/src/setup.js +11 -5
  25. package/src/sheetblock.js +2 -1
  26. package/src/sheetfind.js +3 -1
  27. package/src/ticket-draft.js +2 -2
  28. package/src/ticket-labels.js +2 -2
  29. package/src/try-checks.js +13 -3
  30. package/src/whole-job.js +71 -0
  31. package/types/added-end.d.ts +62 -0
  32. package/types/authoring.d.ts +2 -1
  33. package/types/checkpick.d.ts +35 -0
  34. package/types/checkwords.d.ts +4 -0
  35. package/types/citedcheck.d.ts +6 -0
  36. package/types/closers.d.ts +4 -2
  37. package/types/declaration.d.ts +3 -0
  38. package/types/drafter.d.ts +16 -0
  39. package/types/model-step.d.ts +18 -3
  40. package/types/pageask.d.ts +12 -2
  41. package/types/panel/data.d.ts +1 -1
  42. package/types/panel/jobgrid.d.ts +1 -1
  43. package/types/plain-checks.d.ts +9 -1
  44. package/types/repairs.d.ts +13 -0
  45. package/types/sheetfind.d.ts +1 -0
  46. package/types/try-checks.d.ts +1 -7
  47. package/types/whole-job.d.ts +70 -0
package/src/drafter.js CHANGED
@@ -19,6 +19,7 @@ import { Loop, HaltError } from 'bare-agent';
19
19
  import { capTooSmallText, usdText } from './draftspend.js';
20
20
  import { parseSignedText, unsignedAskTtls } from './signed-text.js';
21
21
  import { validateDeclaration, checkGuardrailSums, checkSendLineGuardrail } from './declaration.js';
22
+ import { readEveryStep } from './whole-job.js';
22
23
  import { loadCatalogue } from './catalogue.js';
23
24
  import { findMcpPlanRed } from './canrun.js';
24
25
  import { WIRED_VERBS, wiredMenu } from './primitives.js';
@@ -30,12 +31,14 @@ import { lookAtPage, pageInfoLines } from './pagelook.js';
30
31
  import { lookAtSheet, sheetPrompt } from './sheetlook.js';
31
32
  import { leftRuleLine, dropRows, dropLine, dropSentence, pickNoteLine } from './pagedropwords.js';
32
33
  import {
33
- scopedRules, rowsFromAnswer, checkAsks, settleRules, applyPicks, SUGGEST_SYSTEM, SUGGEST_TOOL, SUGGEST_SCHEMA, suggestUserText,
34
+ offerRules, rowsFromAnswer, checkAsks, settleRules, applyPicks, retentionOf, SUGGEST_SYSTEM, SUGGEST_TOOL, SUGGEST_SCHEMA, suggestUserText,
34
35
  } from './checkpick.js';
35
36
  import { matchRecord, entriesFromAnswers, sameWords, KEPT_WORDS } from './pickrecord.js';
36
37
  import { MAP_SYSTEM, mapPrompt } from './pagemap.js';
37
38
  import { askableFromLook, tooManyAsksText, MAX_LOOK_ASKS } from './pageask.js';
38
39
  import { lineRules } from './pagebits.js';
40
+ import { isCountGuardrail } from './declaration.js';
41
+ import { repairDeclaration } from './repairs.js';
39
42
  import path from 'node:path';
40
43
  import { isCellsPath } from './closers.js';
41
44
  import { parseCsv, sheetTable } from './csv.js';
@@ -291,11 +294,29 @@ function cleanNotChecked(raw) {
291
294
  return Array.isArray(raw) ? raw.filter((x) => typeof x === 'string' && x.trim() !== '').map((x) => x.trim()) : [];
292
295
  }
293
296
 
297
+ // M10 am27 (1): at draft time a count guardrail is hidden from the AI (the page look and the drafter); code keeps the ORIGINAL rule numbers and text.
298
+ const shownRules = (/** @type {string} */ guardrail) => lineRules({ rule: guardrail }).filter((r) => !isCountGuardrail(r)).join('; ');
299
+
300
+ /**
301
+ * The job lines as the page look may see them (no count rule), and `toOriginal`, which takes a look fact's / dropped entry's visible rule number back to the guardrail's own number.
302
+ * @param {{n: number, text: string, rule?: string}[]} jobLines
303
+ */
304
+ export function hideCounts(jobLines) {
305
+ const seenLines = jobLines.map((l) => { const kept = lineRules(l).filter((r) => !isCountGuardrail(r)); return { n: l.n, text: l.text, ...(kept.length ? { rule: kept.join('; ') } : {}) }; });
306
+ const ruleMap = (/** @type {number} */ line, /** @type {number|undefined} */ vis) => {
307
+ if (vis === undefined) return undefined;
308
+ const orig = lineRules(jobLines.find((x) => x.n === line)).map((r, i) => ({ r, no: i + 1 })).filter((x) => !isCountGuardrail(x.r));
309
+ return orig[vis - 1]?.no ?? vis;
310
+ };
311
+ const toOriginal = (/** @type {any} */ f) => (f.forRule !== undefined ? { ...f, forRule: ruleMap(f.line, f.forRule) } : f.rule !== undefined ? { ...f, rule: ruleMap(f.line, f.rule) } : f);
312
+ return { seenLines, toOriginal };
313
+ }
314
+
294
315
  function jobLinesText(lines, asks) {
295
316
  const askLines = new Set(asks.map((a) => a.line));
296
317
  return lines
297
318
  .map((l) => `${l.n}. ${l.text}${askLines.has(l.n) ? ' [SIGNED ASK — a human stop]' : ''}`
298
- + `${l.guardrail ? ` [guardrail: ${l.guardrail}]` : ' [no guardrail]'}`)
319
+ + `${l.guardrail && shownRules(l.guardrail) ? ` [guardrail: ${shownRules(l.guardrail)}]` : ' [no guardrail]'}`)
299
320
  .join('\n');
300
321
  }
301
322
 
@@ -348,8 +369,8 @@ function whenToUse(menu) {
348
369
  function sheetRuleNumbers(lines, arbiter) {
349
370
  const csvRoles = (arbiter.sources ?? []).filter((s) => s.kind === 'file' && isCellsPath(s.path));
350
371
  if (csvRoles.length === 0) return [];
351
- const rows = lines.map((l) => ({ n: l.n, rules: lineRules(l.guardrail ? { rule: l.guardrail } : {}) })).filter((x) => x.rules.length > 0);
352
- return rows.length === 0 ? [] : ['', 'The guardrail rules by number (what "covers" counts):', ...rows.map((x) => `- line ${x.n}: ${x.rules.map((r, i) => `${i + 1}) ${r}`).join(' ')}`)];
372
+ const rows = lines.map((l) => ({ n: l.n, rules: lineRules(l.guardrail ? { rule: l.guardrail } : {}).map((r, i) => ({ r, no: i + 1 })).filter((x) => !isCountGuardrail(x.r)) })).filter((x) => x.rules.length > 0);
373
+ return rows.length === 0 ? [] : ['', 'The guardrail rules by number (what "covers" counts):', ...rows.map((x) => `- line ${x.n}: ${x.rules.map((q) => `${q.no}) ${q.r}`).join(' ')}`)];
353
374
  }
354
375
 
355
376
  export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }) {
@@ -541,6 +562,8 @@ export async function draft({
541
562
  const pageExtras = pageSources.length ? { look, pageLooks } : {};
542
563
  let mapCut = null;
543
564
  const jobLines = lines.map((l) => ({ n: l.n, text: l.text, ...(l.guardrail ? { rule: l.guardrail } : {}) }));
565
+ // M10 am27 (1): the page look sees only the non-count rules; `toOriginal` takes a visible rule number back to the original one
566
+ const { seenLines, toOriginal } = hideCounts(jobLines);
544
567
  const pageInfo = [];
545
568
  /** one map call (a page's or a sheet's): its hold, its metering and its book are the drafting round's own (the `kind` names it in the round log) */
546
569
  const makeCallModel = (kind) => async (content, attempt) => {
@@ -572,13 +595,14 @@ export async function draft({
572
595
  for (const s of pageSources) {
573
596
  const pg = pages[s.role];
574
597
  // The hold of the map call is sized from its own prompt (the saved page is in it): one that cannot fit what is left of the cap is refused here, at $0.
575
- const mapCeiling = ceilingCostUsd(rates, mapPrompt({ jobLines, label: s.role, text: pg.text }).length + MAP_SYSTEM.length);
598
+ const mapCeiling = ceilingCostUsd(rates, mapPrompt({ jobLines: seenLines, label: s.role, text: pg.text }).length + MAP_SYSTEM.length);
576
599
  const spentBefore = meterings.reduce((sum, ev) => sum + (ev.costUsd ?? roundCeiling), 0);
577
600
  if (spentBefore + mapCeiling > budgetUsd) {
578
601
  if (meterings.length === 0 && calls === 0) { removeFrozenPages(/** @type {string} */ (draftDir), Object.values(pages).map((q) => q.entry.frozen)); return fail([tooSmall(mapCeiling)]); }
579
602
  }
580
603
  const callModel = makeCallModel('page-map');
581
- const got = await lookAtPage({ label: s.role, text: pg.text, jobLines, callModel });
604
+ const got0 = await lookAtPage({ label: s.role, text: pg.text, jobLines: seenLines, callModel });
605
+ const got = got0.ok ? { ...got0, look: { ...got0.look, facts: got0.look.facts.map(toOriginal), dropped: got0.look.dropped.map(toOriginal) } } : got0;
582
606
  if (!got.ok) {
583
607
  const m = sumMeterings(meterings);
584
608
  return {
@@ -658,7 +682,7 @@ export async function draft({
658
682
  // per guardrail, or none; code keeps what passes keep-or-drop. The call is metered, held and booked as a drafting round (the same `meterings`). The redraft after the answers
659
683
  // (offerQuestions false) makes no call: it settles every rule against the person's picks instead.
660
684
  // a rule a kept page or sheet fact already serves (the look tied it: line + rule number) is settled by that fact and is not asked here
661
- const shapeRules = scopedRules(lines, arbiter).filter((r) => ![...look.facts, ...sheetFacts].some((f) => f.line === r.line && f.forRule === r.rule));
685
+ const shapeRules = offerRules(lines, arbiter, [...look.facts, ...sheetFacts]);
662
686
  // M10 am17/am18: a guardrail whose pick is kept from the last draft skips the suggestion call and the asks; only the rest is suggested and asked. The model never sees a pick.
663
687
  const carried = matchRecord(carriedPicks, lines, shapeRules);
664
688
  const keptView = carried.kept.map((k) => ({ line: k.line, rule: k.rule, ruleText: k.entry.ruleText, check: k.entry.check, added: k.entry.added, left: k.entry.left }));
@@ -873,16 +897,24 @@ export async function draft({
873
897
  if (Array.isArray(declaration.steps)) {
874
898
  declaration.steps = declaration.steps.map((st) => (isPlainObject(st) ? { ...st, goal: goalForLine(st.fromLine, lines) } : st));
875
899
  }
900
+ // M13 am9 item 4: the last Ask before the added `write it out` reads every step; code sets it, whatever the model sent
901
+ if (Array.isArray(declaration.steps)) declaration.steps = readEveryStep(declaration.steps, arbiter);
876
902
  // M10 am16 (4): the drafter writes no check. Whatever `close.shape` it sent (the schema offers none) is dropped here; a check reaches the plan only from the person's picks (applyPicks, next).
903
+ delete declaration.pickedLines; // the record of picked fact lines is code's too (applyPicks)
877
904
  if (Array.isArray(declaration.steps)) {
878
905
  declaration.steps = declaration.steps.map((st) => {
879
- if (!isPlainObject(st) || !isPlainObject(st.close) || st.close.shape === undefined) return st;
880
- const { shape: _drop, ...close } = st.close;
906
+ if (!isPlainObject(st) || !isPlainObject(st.close) || (st.close.shape === undefined && st.close.picked === undefined)) return st;
907
+ // M10 am22 (3): `close.picked` is code's from the person's picks (applyPicks, next); one the drafter sent is dropped here too
908
+ const { shape: _drop, picked: _dropPicked, ...close } = st.close;
881
909
  return { ...st, close };
882
910
  });
883
911
  }
884
912
  // M10 am16 (4): code sets the check of every line it settled, from the picks only; the drafter's own `close.shape` and class for such a line are gone
885
913
  if (settled) Object.assign(declaration, applyPicks(declaration, shapeRules, settled, (n) => dropSentence({ line: n.line, fact: '', reason: n.reason })));
914
+ // M10 am27 (2): the two mechanical plan mistakes (cited page not in reads; unjudgeable note on a green line) are repaired by code and logged on the round
915
+ { const fixed = repairDeclaration(declaration, arbiter); if (fixed.repaired.length) { Object.assign(declaration, fixed.declaration); entry.repaired = fixed.repaired; } }
916
+ // M10 am27 (4): what the drafter wrote vs what the final plan keeps, per job line (record only); drafted = the declaration as sent, before any code change
917
+ entry.retention = retentionOf(captured, declaration, jobLines, [...(settled?.checks.keys() ?? [])]);
886
918
  // M10b piece 4: `covers` (which ~ rules a check verifies) stays on the check and is signed; the validator checks it, the plan card shows it
887
919
  const verdict1 = validateDeclaration(declaration, {
888
920
  arbiter, lines, catalogue: validationCatalogue, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
package/src/jobkey.js CHANGED
@@ -5,6 +5,7 @@
5
5
  // TWO producers, ONE canonical form: the signed flow (parseSignedText's lines + arbiter) and the card's job box (parseJobBox).
6
6
  import { createHash } from 'node:crypto';
7
7
 
8
+ import { typedLinesOf } from './added-end.js';
8
9
  import { joinGuardrails, parseJobBox } from './panel/authorcard.js';
9
10
 
10
11
  /** @param {{ask: boolean, text: string, guardrail: string}[]} steps */
@@ -21,5 +22,6 @@ export function jobKeyOfCard(job) {
21
22
  /** The key of a signed job. @param {{ lines: {n: number, text: string, guardrail: string}[], arbiter: any }} signed `parseSignedText`'s ok result */
22
23
  export function jobKeyOfSigned({ lines, arbiter }) {
23
24
  const asks = new Set((arbiter.asks ?? []).map((a) => a.line));
24
- return keyOf(lines.map((l) => ({ ask: asks.has(l.n), text: String(l.text).trim(), guardrail: String(l.guardrail ?? '').trim() })));
25
+ // M13 am8: the end code adds (and an old job's send line) is not part of the job the person typed
26
+ return keyOf(typedLinesOf(lines, arbiter).map((l) => ({ ask: asks.has(l.n), text: String(l.text).trim(), guardrail: String(l.guardrail ?? '').trim() })));
25
27
  }
package/src/model-step.js CHANGED
@@ -30,7 +30,7 @@ import { GateRefusal } from './primitives.js';
30
30
  import { appendCall, appendTool, nextRound } from './diary.js';
31
31
  import { ConfigError } from './config.js';
32
32
  import { worstThinkingStatus } from './thinking.js';
33
- import { citedBrief } from './citedcheck.js';
33
+ import { citedBrief, toldPicks } from './citedcheck.js';
34
34
  import { sheetAnswerProps, sheetBrief } from './sheetclaims.js';
35
35
 
36
36
  import {
@@ -143,12 +143,16 @@ const CITED_SCHEMA = Object.freeze({
143
143
  * only (plus, for a green step that quotes a saved page, the form of its answer).
144
144
  * `stepClass` is `'green' | 'softgreen' | 'hitl' | null | undefined`; `cited` is true for that green step.
145
145
  */
146
- /** @param {string|null|undefined} stepClass @param {boolean} [cited] @param {any[]|null} [sheet] M10b piece 2: the step's `close.sheet` (its claim boxes become the answer) */
147
- export function buildEmitArtifactSchema(stepClass, cited = false, sheet = null) {
146
+ /** @param {string|null|undefined} stepClass @param {boolean} [cited] @param {any[]|null} [sheet] M10b piece 2: the step's `close.sheet` (its claim boxes become the answer) @param {boolean} [withText] M10 am22: a fact step with the person's picks also answers in `text` (the picks read it) */
147
+ export function buildEmitArtifactSchema(stepClass, cited = false, sheet = null, withText = false) {
148
+ const text = withText ? { text: { type: 'string' } } : {};
148
149
  if (stepClass === 'green' && Array.isArray(sheet)) {
149
150
  // M10b piece 2: a step that reads a sheet answers in one typed box per claim (bareguard's shapes), never a cite
150
151
  const { properties, required } = sheetAnswerProps(sheet);
151
- return { type: 'object', properties: { ...properties, ...DONE_PROPS }, required: [...required, 'done'], additionalProperties: false };
152
+ return { type: 'object', properties: { ...properties, ...text, ...DONE_PROPS }, required: [...required, ...(withText ? ['text'] : []), 'done'], additionalProperties: false };
153
+ }
154
+ if (stepClass === 'green' && cited && withText) {
155
+ return { ...CITED_SCHEMA, properties: { ...CITED_SCHEMA.properties, ...text }, required: ['results', 'text', 'done'] };
152
156
  }
153
157
  if (stepClass === 'green' && cited) return CITED_SCHEMA;
154
158
  if (stepClass === 'green') throw new Error('a green step answers in quotes (close.cited) or in claim boxes (close.sheet); the cell cite retired in M10b piece 5');
@@ -330,7 +334,7 @@ function stoppedResult(cumulative, modelId, modelMatch) {
330
334
  * @param {{in:number,out:number}} [opts.rates]
331
335
  * @param {string} [opts.modelId]
332
336
  * @param {Record<string,string|undefined>} [opts.env] - the merged shell+keys-file env the key is read from (default process.env).
333
- * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, sheet?:any[]|null, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
337
+ * @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, sheet?:any[]|null, withText?:boolean, picked?:any[]|null, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
334
338
  */
335
339
  export function makeLiveModelStep({
336
340
  slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, env,
@@ -371,7 +375,7 @@ export function makeLiveModelStep({
371
375
  const runDir = dirname(spendPath);
372
376
  const diaryStep = stepMeta.step ?? null;
373
377
  const diaryTry = typeof stepMeta.attempt === 'number' ? stepMeta.attempt : null;
374
- const toolSchema = buildEmitArtifactSchema(stepMeta.class, stepMeta.class === 'green' && Boolean(stepMeta.cited), stepMeta.class === 'green' && Array.isArray(stepMeta.sheet) ? stepMeta.sheet : null);
378
+ const toolSchema = buildEmitArtifactSchema(stepMeta.class, stepMeta.class === 'green' && Boolean(stepMeta.cited), stepMeta.class === 'green' && Array.isArray(stepMeta.sheet) ? stepMeta.sheet : null, stepMeta.class === 'green' && stepMeta.withText === true);
375
379
  const thinkingMode = stepMeta.thinkingMode === 'on' || stepMeta.thinkingMode === 'off' ? stepMeta.thinkingMode : null;
376
380
  const systemPrompt = 'You are executing one step of a signed, human-authored automation. '
377
381
  + 'Call emit_artifact exactly once with this step\'s result. Ground every value in the '
@@ -384,10 +388,12 @@ export function makeLiveModelStep({
384
388
  ...(typeof executorContext.hints === 'string' && executorContext.hints !== '' ? { fromEarlierRuns: executorContext.hints } : {}),
385
389
  // M14 item 2: what happened so far in this run (src/memo.js), whole, on every try that has any; absent = nothing has happened yet. Text only, it leans the model, the close alone judges
386
390
  ...(typeof executorContext.memo === 'string' && executorContext.memo !== '' ? { fromThisRun: executorContext.memo } : {}),
387
- // M10 am7 item 3: a step that quotes a saved page is told the form of its answer and what each result must hold
388
- ...(stepMeta.class === 'green' && stepMeta.cited ? { quoting: citedBrief(stepMeta.cited) } : {}),
391
+ // M10 am7 item 3: a step that quotes a saved page is told the form of its answer and what each result must hold; M10 am28: and each pick on its line (values only)
392
+ ...(stepMeta.class === 'green' && stepMeta.cited ? { quoting: { ...citedBrief(stepMeta.cited), ...(Array.isArray(stepMeta.picked) && stepMeta.picked.length > 0 ? { yourTextHas: toldPicks(stepMeta.picked) } : {}) } } : {}),
389
393
  // M10b piece 2: a step that reads a sheet is told the shape of each claim box (bareguard's worked example), never the check
390
394
  ...(stepMeta.class === 'green' && Array.isArray(stepMeta.sheet) ? { answering: sheetBrief(stepMeta.sheet) } : {}),
395
+ // M10 am22: a fact step whose line carries the person's picks also writes the answer the job line asks for, in "text" (their sizes are in the job line)
396
+ ...(stepMeta.class === 'green' && stepMeta.withText === true ? { alsoWrite: 'Also give "text": the written answer the goal asks for, in your own words, grounded in what you found. Never leave it empty.' } : {}),
391
397
  });
392
398
  /** @type {any[]} */
393
399
  let messages = [
package/src/pageask.js CHANGED
@@ -10,10 +10,14 @@
10
10
  // READING: a kept fact carries it with a `reading` (a limit the page cannot hold in words, e.g. "not a red-eye"). Asked only when a bound of the
11
11
  // reading is NOT in the words the person wrote; a bound they wrote themselves is theirs and nothing is asked.
12
12
  // CAN'T CHECK: no kept fact carries it.
13
+ // A COUNT guardrail (declaration.js isCountGuardrail) is none of these: it is asked once, as a pick (M10 am24).
13
14
  // Throws away: a fact's name, words and source (only its reading and the rule it serves are used).
14
15
  import { redactSecrets } from './redact.js';
15
16
  import { lineRules, boundInWords, wordsSaidOn } from './pagebits.js';
16
17
  import { validReading } from './pagerules.js';
18
+ import { isCountGuardrail } from './declaration.js';
19
+ import { HOW_TO_ANSWER } from './checkpick.js';
20
+ import { columnTail } from './sheetfind.js';
17
21
 
18
22
  /** the most asks before drafting; more than this is a job to rewrite, not a questionnaire (am1) */
19
23
  export const MAX_LOOK_ASKS = 3;
@@ -68,9 +72,16 @@ export function ruleWords(f) {
68
72
 
69
73
  /** the words of a reading ask: the ONE spelling, and {@link readingOfQuestion} reads it back (the Result tab's "(you confirmed)") */
70
74
  const READING_HEAD = ' I read it as: ';
71
- 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}).`;
72
83
  /** @param {number} n @param {string} rule @param {string} reading @returns {string} */
73
- 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)}`;
74
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 */
75
86
  export function readingOfQuestion(q) {
76
87
  const s = String(q ?? '');
@@ -79,6 +90,19 @@ export function readingOfQuestion(q) {
79
90
  return a >= 0 && b > a ? s.slice(a + READING_HEAD.length, b) : null;
80
91
  }
81
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
+
82
106
  /**
83
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
84
108
  * asks, each in line order. The caller applies the cap and the answer gate.
@@ -97,6 +121,7 @@ export function askableFromLook(look, jobLines) {
97
121
  for (const l of Array.isArray(jobLines) ? jobLines : []) {
98
122
  lineRules(l).forEach((rule, k) => {
99
123
  const n = k + 1;
124
+ if (isCountGuardrail(rule)) return; // M10 am24: a count guardrail is asked only as a pick (src/checkpick.js), never as a page question; its look facts stay
100
125
  const key = `${l.n}\u0000${rule.trim().toLowerCase()}`;
101
126
  const tied = facts.filter((f) => f.line === l.n && f.forRule === n);
102
127
  if (tied.length > 0) {
@@ -115,7 +140,7 @@ export function askableFromLook(look, jobLines) {
115
140
  seen.add(key);
116
141
  cants.push({
117
142
  line: l.n, rule: n, source: 'look', ask: 'cant-check', ruleText: rule,
118
- 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)}`,
119
144
  });
120
145
  });
121
146
  }
@@ -141,12 +166,18 @@ export function tooManyAsksText(asks) {
141
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.
142
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
143
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).
144
- * @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)
145
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)
146
171
  */
147
- export function ruleOfAnswer(q, typed) {
172
+ export function ruleOfAnswer(q, typed, choice) {
148
173
  const typedText = String(typed ?? '').replace(/\s*\n\s*/g, ' ').trim();
149
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
+ }
150
181
  const text = stripAgreeLead(typedText); // F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
151
182
  const shape = q.ask === 'check' || q.ask === 'no-check';
152
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 };
@@ -749,7 +749,15 @@ export function createAuthor(opts) {
749
749
  // M10 piece 3 (am2): a question the page look raised takes bareloop's answer words. A blank answer gets bareloop's sentence; a newline is folded to a
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
- const answer = typeof b.answer === 'string' ? (look ? b.answer.replace(/\s*\n\s*/g, ' ') : b.answer).trim() : '';
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
+ // 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
+ if (choice !== undefined) {
756
+ const proposes = look && typeof q.proposal === 'string' && (q.ask === 'reading' || q.ask === 'check');
757
+ 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.' } };
758
+ 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.' } };
759
+ }
760
+ 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*)+/, '') : '';
753
761
  if (answer === '') return { status: 400, body: { ok: false, refused: 'blank-answer', say: look ? LOOK_BLANK_ANSWER_SAY : BLANK_ANSWER_SAY } };
754
762
  if (!look && /[\r\n]/.test(answer)) return { status: 400, body: { ok: false, refused: 'one-line', say: ONE_LINE_ANSWER_SAY } };
755
763
  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.' } };
@@ -758,14 +766,17 @@ export function createAuthor(opts) {
758
766
  const answerFile = join(planDir, ANSWER_FILE(v.openK));
759
767
  const at = new Date().toISOString();
760
768
  // what this answer does (ruleOfAnswer, the one place): the `~` rule it adds, or the rule it leaves Not checked
761
- const effect = ruleOfAnswer(q, answer);
769
+ const effect = ruleOfAnswer(q, answer, choice);
770
+ // 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
771
+ 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.' } };
762
772
  // the whole redraft is checked at $0 BEFORE the answer is written, so a refusal leaves the question open and nothing on disk
763
773
  /** @type {any} */
764
774
  let redraft = null;
765
775
  if (last) {
766
776
  const all = full.map((x) => {
767
777
  const typed = x.k === v.openK ? answer : x.answer;
768
- 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 }) };
778
+ const ch = x.k === v.openK ? choice : x.choice;
779
+ 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 }) };
769
780
  });
770
781
  const adds = all.filter((x) => x.rule !== null);
771
782
  const grown = applyAnswers(typeof v.card.job === 'string' ? v.card.job : '', all);
@@ -783,7 +794,7 @@ export function createAuthor(opts) {
783
794
  try {
784
795
  // 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
785
796
  writeFileSync(answerFile, `${JSON.stringify({
786
- k: v.openK, line: q.line, question: q.question, answer, at,
797
+ k: v.openK, line: q.line, question: q.question, answer, ...(choice === undefined ? {} : { choice }), at,
787
798
  ...(look ? { source: 'look', ask: q.ask, ruleNo: q.ruleNo, ruleText: q.ruleText, proposal: q.proposal ?? null, rule: effect.rule } : {}),
788
799
  })}\n`, { mode: 0o600, flag: 'wx' });
789
800
  } catch (e) {
@@ -18,7 +18,7 @@ import { checkFlowName } from '../flow.js';
18
18
  import { isWebUrl } from '../pagefetch.js';
19
19
  import { checkSendDestination } from '../runner.js';
20
20
  import { parseSignedText } from '../signed-text.js';
21
- import { checkSendLineGuardrail } from '../declaration.js';
21
+ import { addEnd, typedLinesOf } from '../added-end.js';
22
22
  import { capTooSmallText } from '../draftspend.js';
23
23
  import { startableMcpServers, mcpConfigFor } from '../mcp-sources.js';
24
24
  import { mcpPickFor } from '../mcp-pick.js';
@@ -257,7 +257,7 @@ export function runInputRows(v) {
257
257
  * @returns {string}
258
258
  */
259
259
  export function cardToProse(card) {
260
- const { steps } = parseJobBox(card.job);
260
+ const { steps } = addEnd(parseJobBox(card.job).steps, card.destination); // M13 am8: the end is added by code
261
261
  const out = [...jobFileLines(steps, card.askWait), '', ARBITER_HEADING];
262
262
  out.push(`guardrail: cap $${capText(Number(card.capUsd))} per run`);
263
263
  if (card.destination !== '') out.push(`guardrail: send at line ${steps.length} to file:${card.destination}`);
@@ -284,14 +284,19 @@ export function cardFromSigned({ lines, arbiter }) {
284
284
  const asks = new Map((arbiter.asks ?? []).map((a) => [a.line, a]));
285
285
  const jobLines = [];
286
286
  let firstWait = null;
287
+ // M13 am8: the end is added by code (`cardToProse`), so the card's job leaves out the send line (the last line when it is the send) and an added Ask before it
288
+ const lastSend = (arbiter.sends ?? []).length === 1 && arbiter.sends[0].line === lines.length ? arbiter.sends[0].line : null;
289
+ const typed = new Set(typedLinesOf(lines, arbiter).map((l) => l.n));
287
290
  for (const l of lines) {
288
291
  const ak = asks.get(l.n);
289
292
  if (ak) {
290
293
  const w = waitText(ak.ttlMs);
291
294
  if (w === null) return no();
292
295
  firstWait ??= w;
293
- jobLines.push(`Ask ${w}: ${l.text}`);
294
- } else jobLines.push(l.text);
296
+ }
297
+ if (!typed.has(l.n)) continue;
298
+ if (ak) jobLines.push(`Ask ${waitText(ak.ttlMs)}: ${l.text}`);
299
+ else jobLines.push(l.text);
295
300
  if (typeof l.guardrail === 'string' && l.guardrail !== '') jobLines.push(`~ ${l.guardrail}`);
296
301
  }
297
302
  const sends = arbiter.sends ?? [];
@@ -306,7 +311,9 @@ export function cardFromSigned({ lines, arbiter }) {
306
311
  const again = parseSignedText(cardToProse(cardFields({ ...card, flowName: 'x' })));
307
312
  // M9 am1: the trigger is not a box on the card, and signing an Edit clears it (By hand again), so it is not part of the fidelity check
308
313
  const norm = (a) => JSON.stringify({ ...a, trigger: null, asks: (a.asks ?? []).map(({ ttlSigned, ...rest }) => rest) });
309
- const sameLines = again.ok && JSON.stringify(again.lines) === JSON.stringify(lines);
314
+ // a send line signed before am8 is the person's own words; the added one reads `write it out`: the words alone may differ there
315
+ const sendText = (/** @type {{n: number, text: string}[]} */ ls) => ls.map((l) => (l.n === lastSend ? { ...l, text: '' } : l));
316
+ const sameLines = again.ok && JSON.stringify(sendText(again.lines)) === JSON.stringify(sendText(lines));
310
317
  if (!sameLines || norm(again.arbiter) !== norm(arbiter)) return no();
311
318
  return { ok: true, card };
312
319
  }
@@ -493,8 +500,5 @@ export function checkCard(card, { root, keys = [], home, runOf }) {
493
500
  }
494
501
  return { ok: false, refusals };
495
502
  }
496
- // M10 am14 item 1: a guardrail on the send line is refused at $0, before drafting, naming the line
497
- for (const r of checkSendLineGuardrail(parsed.lines, parsed.arbiter)) no('job', r);
498
- if (refusals.length > 0) return { ok: false, refusals };
499
503
  return { ok: true, prose };
500
504
  }
package/src/panel/data.js CHANGED
@@ -23,7 +23,7 @@ import {
23
23
  existsSync, realpathSync,
24
24
  } from 'node:fs';
25
25
  import { createHash } from 'node:crypto';
26
- import { plainPlanCheck } from '../plain-checks.js';
26
+ import { plainPlanCheck, pickPlanRed } from '../plain-checks.js';
27
27
  import { compareNatural } from '../natural.js';
28
28
  import { join, sep } from 'node:path';
29
29
 
@@ -41,6 +41,8 @@ import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../r
41
41
  import { readSetup } from '../setup.js';
42
42
  import { parseHintBlock } from '../learn.js';
43
43
  import { checkedLines, notCheckedView, NOT_CHECKED_LABEL } from '../checked.js';
44
+ import { LABEL_PICKED } from '../checkwords.js';
45
+ import { panelQuestionText } from '../pageask.js';
44
46
  import { csvRolesOf, askSheetCard } from '../sheetblock.js';
45
47
  import { readSheetChecks } from '../sheet-record.js';
46
48
  import {
@@ -1911,7 +1913,7 @@ export function getDraftBlock(flowDir, runDir) {
1911
1913
  // The free retry after a broken reply reads `try N again`. A flow signed before am15 recorded no tries: nothing is added.
1912
1914
  const tryRows = (r, n) => (Array.isArray(r.tries) ? r.tries : []).map((t, k) => {
1913
1915
  const reds = Array.isArray(t.reds) ? t.reds.map(String) : [];
1914
- const gap = t.passed ? '' : (reds.length > 0 ? `${plainPlanCheck(reds[0]).reason}${reds.length > 1 ? ` (and ${reds.length - 1} more)` : ''}` : String(t.outcome ?? ''));
1916
+ const gap = t.passed ? '' : (reds.length > 0 ? `${plainPlanCheck(pickPlanRed(reds)).reason}${reds.length > 1 ? ` (and ${reds.length - 1} more)` : ''}` : String(t.outcome ?? ''));
1915
1917
  return {
1916
1918
  attempt: `${n}.${k + 1}`, step: 'drafting', class: null, verdict: t.passed ? 'green' : 'red', gap, at: r.at ?? null, setup: true, blocked: false,
1917
1919
  action: `${t.label} ${t.passed ? '✓' : '✗'}`, tryRow: true, tokensDisplay: { kind: 'no-model' },
@@ -1940,7 +1942,7 @@ export function getDraftBlock(flowDir, runDir) {
1940
1942
  rows.push(human(r, n, { action: 'card (you)', gap }));
1941
1943
  } else if (r.kind === 'note') rows.push(human(r, n, { action: 'note (you)', gap: String(r.text ?? '') }));
1942
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:`)
1943
- else if (r.kind === 'human') rows.push(human(r, n, { action: `you were asked: ${r.question}`, gap: `you said: ${r.answer}` }));
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}` : ''}` }));
1944
1946
  else if (r.kind === 'draft') { rows.push(model(r, n, 'draft')); rows.push(...tryRows(r, n)); }
1945
1947
  else if (r.kind === 'change') { rows.push(model(r, n, `change ${r.n}`)); rows.push(...tryRows(r, n)); }
1946
1948
  else if (r.kind === 'startover') { rows.push(model(r, n, 'start over')); rows.push(...tryRows(r, n)); }
@@ -226,6 +226,7 @@
226
226
  .badge.cyan{color:var(--cyan);}
227
227
 
228
228
  .hint{font-size:11px;color:var(--text-faint);margin-top:4px;}
229
+ .hint.jf-added{margin-top:2px;overflow-wrap:anywhere;}
229
230
  .hint.money-red{color:var(--red);}
230
231
  .btn{padding:8px 14px;min-height:44px;border:1px solid var(--border-strong);background:var(--panel2);color:var(--text);white-space:nowrap;flex:none;position:relative;}
231
232
  .btn::before{content:"[ ";color:var(--text-faint);}
@@ -739,6 +740,10 @@
739
740
  .chat-question .q-line{font-size:12px;color:var(--text-faint);margin-top:4px;overflow-wrap:anywhere;}
740
741
  .chat-question .q-text{font-size:13px;margin-top:4px;overflow-wrap:anywhere;white-space:pre-wrap;}
741
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;}
742
747
  .chat-question .q-err{color:var(--red);}
743
748
  .chat-extras{display:flex;flex-direction:column;gap:10px;margin-bottom:10px;}
744
749
  .chat-extras:empty{display:none;}
@@ -1187,7 +1192,9 @@
1187
1192
  <div class="jf-gut" id="jf-job-gut" data-testid="jf-job-gut" aria-hidden="true"><div class="jf-gut-in"></div></div>
1188
1193
  <textarea class="jf-wrap" id="jf-job" rows="6" data-testid="jf-job" autocomplete="off" spellcheck="false" placeholder="Read my resume&#10;~keep it under 600 words&#10;Ask: check it with me&#10;Write it out"></textarea>
1189
1194
  </div>
1190
- <div class="hint">One step per line. A line starting with <code>~</code> is a guardrail of the step above it. <code>Ask:</code> stops for you; <code>Ask 2h:</code> sets that ask's own wait. The last line writes the result to the Destination.</div>
1195
+ <div class="hint jf-added" id="jf-added-ask" data-testid="jf-added-ask" hidden></div>
1196
+ <div class="hint jf-added" id="jf-added-write" data-testid="jf-added-write" hidden></div>
1197
+ <div class="hint">One step per line. A line starting with <code>~</code> is a guardrail of the step above it. <code>Ask:</code> stops for you; <code>Ask 2h:</code> sets that ask's own wait. fwdloop adds the last check and the write to your Destination.</div>
1191
1198
  <div class="jf-err" id="jf-err-job" data-testid="jf-err-job"></div>
1192
1199
  </div>
1193
1200
  <div class="field">
@@ -1395,6 +1402,11 @@
1395
1402
  <div class="q-head" id="chat-q-head" data-testid="chat-q-head"></div>
1396
1403
  <div class="q-line" id="chat-q-line" data-testid="chat-q-line"></div>
1397
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>
1398
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>
1399
1411
  <div class="hint q-err" id="chat-q-error" data-testid="chat-q-error" role="alert"></div>
1400
1412
  <button class="btn primary wide" type="button" id="chat-q-send" data-testid="chat-q-send">Send</button>
@@ -5530,6 +5542,9 @@
5530
5542
  var qAnswer = document.getElementById("chat-q-answer");
5531
5543
  var qError = document.getElementById("chat-q-error");
5532
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");
5533
5548
  var extrasEl = document.getElementById("chat-extras");
5534
5549
  var newBox = document.getElementById("jf-new");
5535
5550
  var runBox = document.getElementById("jf-run");
@@ -5778,13 +5793,13 @@
5778
5793
  if(!q) return null;
5779
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
5780
5795
  if(q.source === "look"){
5781
- 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 };
5782
5797
  }
5783
5798
  return {
5784
5799
  key: String(state.draftId) + ":" + q.k, k: q.k,
5785
5800
  head: "A question the plan raised (" + q.k + " of " + state.total + ")",
5786
5801
  line: q.lineText ? "About job line " + q.line + ": " + q.lineText : "About job line " + q.line,
5787
- question: q.question
5802
+ question: q.question, agree: false, drop: false
5788
5803
  };
5789
5804
  }
5790
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
@@ -6163,7 +6178,18 @@
6163
6178
  clearBtn.textContent = b.text;
6164
6179
  clearBtn.disabled = b.disabled;
6165
6180
  }
6181
+ // M13 am8: the end code adds, in grey under the Job box (the server's `addEnd` is the one writer; this only shows it): an Ask unless the last step is already one, then the write.
6182
+ function paintAddedEnd(){
6183
+ var steps = jobEl.value.split("\n").map(function(l){ return l.trim(); }).filter(function(l){ return l !== "" && l.charAt(0) !== "~"; });
6184
+ var on = destEl.value.trim() !== "" && steps.length > 0;
6185
+ var needAsk = on && !/^ask[: ]/i.test(steps[steps.length - 1]);
6186
+ var askEl = byId("jf-added-ask"), writeEl = byId("jf-added-write");
6187
+ askEl.hidden = !needAsk; writeEl.hidden = !on;
6188
+ askEl.textContent = "+ Ask " + (askWaitEl.value.trim() || "1h") + ": check the result";
6189
+ writeEl.textContent = "+ Write to Destination";
6190
+ }
6166
6191
  function refreshStartEnabled(){
6192
+ paintAddedEnd();
6167
6193
  paintRequired();
6168
6194
  startOk = startReady();
6169
6195
  syncCardLock();
@@ -6634,6 +6660,8 @@
6634
6660
  qKey = v.key;
6635
6661
  qHead.textContent = v.head; qLine.textContent = v.line; qText.textContent = v.question;
6636
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);
6637
6665
  qAnswer.value = ""; qError.textContent = "";
6638
6666
  }
6639
6667
  }
@@ -6829,17 +6857,19 @@
6829
6857
  }
6830
6858
 
6831
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.
6832
- 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){
6833
6862
  if(qBusy || !sessionId || !lastState || lastState.phase !== "questions-open") return;
6834
- qBusy = true; qSend.disabled = true; qError.textContent = "";
6863
+ qBusy = true; qSend.disabled = true; qAgree.disabled = true; qDrop.disabled = true; qError.textContent = "";
6835
6864
  var id = sessionId;
6836
- authorPost("/api/author/" + id + "/answer", {k: lastState.openK, answer: qAnswer.value}).then(function(r){
6837
- 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;
6838
6868
  if(id !== sessionId) return;
6839
6869
  if(!(r.status >= 200 && r.status < 300 && r.body && r.body.ok === true)){ qError.textContent = refusalText(r); return; }
6840
6870
  qAnswer.value = "";
6841
6871
  poll();
6842
- }).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; });
6843
6873
  }
6844
6874
  function doDraft(startedOverFrom){
6845
6875
  clearFieldErrors();
@@ -7084,8 +7114,10 @@
7084
7114
  reviseBtn.addEventListener("click", function(){ if(reviseBtn.disabled) return; if(lastState && lastState.card) fillCardFields(lastState.card); reviseOpen = true; refreshStartEnabled(); fitCardBoxes(); });
7085
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)
7086
7116
  startOverBtn.addEventListener("click", function(){ if(!startOverBtn.disabled) doDraft(sessionId); });
7087
- qSend.addEventListener("click", doAnswer);
7088
- 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"); } });
7089
7121
  mainBtn.addEventListener("click", function(){
7090
7122
  if(mainBtn.disabled) return;
7091
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);