fwdloop 0.28.0 → 0.30.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 (74) hide show
  1. package/README.md +1 -1
  2. package/bin/fwdloop +27 -5
  3. package/package.json +3 -3
  4. package/src/added-end.js +60 -0
  5. package/src/ask.js +1 -1
  6. package/src/audit-fold.js +9 -1
  7. package/src/authoring.js +18 -7
  8. package/src/checked.js +14 -9
  9. package/src/checkpick.js +318 -0
  10. package/src/checkwords.js +29 -0
  11. package/src/citedcheck.js +14 -0
  12. package/src/closers.js +40 -3
  13. package/src/declaration.js +102 -5
  14. package/src/draft-steps.js +3 -3
  15. package/src/drafter.js +151 -38
  16. package/src/jobkey.js +3 -1
  17. package/src/learn.js +1 -1
  18. package/src/learnstore.js +6 -6
  19. package/src/memo.js +120 -0
  20. package/src/model-step.js +103 -25
  21. package/src/pageask.js +12 -6
  22. package/src/pagedropwords.js +9 -0
  23. package/src/panel/author.js +33 -10
  24. package/src/panel/authorcard.js +59 -6
  25. package/src/panel/data.js +16 -10
  26. package/src/panel/index.html +151 -59
  27. package/src/panel/result.js +28 -7
  28. package/src/panel/server.js +2 -1
  29. package/src/pickrecord.js +146 -0
  30. package/src/plain-checks.js +16 -3
  31. package/src/provider.js +4 -1
  32. package/src/repairs.js +38 -0
  33. package/src/runfile.js +4 -2
  34. package/src/runner.js +129 -40
  35. package/src/send.js +71 -4
  36. package/src/setup.js +13 -1
  37. package/src/sheetblock.js +2 -1
  38. package/src/ticket-draft.js +2 -2
  39. package/src/ticket-labels.js +2 -2
  40. package/src/try-checks.js +13 -3
  41. package/src/whole-job.js +71 -0
  42. package/types/added-end.d.ts +62 -0
  43. package/types/ask.d.ts +2 -1
  44. package/types/audit-fold.d.ts +13 -2
  45. package/types/authoring.d.ts +6 -2
  46. package/types/checked.d.ts +7 -2
  47. package/types/checkpick.d.ts +183 -0
  48. package/types/checkwords.d.ts +18 -0
  49. package/types/citedcheck.d.ts +6 -0
  50. package/types/closers.d.ts +6 -3
  51. package/types/declaration.d.ts +12 -0
  52. package/types/drafter.d.ts +28 -25
  53. package/types/learn.d.ts +1 -0
  54. package/types/learnstore.d.ts +2 -3
  55. package/types/memo.d.ts +15 -0
  56. package/types/model-step.d.ts +23 -3
  57. package/types/pageask.d.ts +9 -2
  58. package/types/pagedropwords.d.ts +1 -0
  59. package/types/panel/author.d.ts +1 -1
  60. package/types/panel/authorcard.d.ts +41 -0
  61. package/types/panel/data.d.ts +1 -1
  62. package/types/panel/jobgrid.d.ts +1 -1
  63. package/types/panel/result.d.ts +9 -3
  64. package/types/pickrecord.d.ts +88 -0
  65. package/types/plain-checks.d.ts +9 -1
  66. package/types/repairs.d.ts +13 -0
  67. package/types/runfile.d.ts +7 -2
  68. package/types/runner.d.ts +16 -5
  69. package/types/send.d.ts +10 -2
  70. package/types/setup.d.ts +1 -56
  71. package/types/try-checks.d.ts +1 -7
  72. package/types/whole-job.d.ts +70 -0
  73. package/src/attemptdiff.js +0 -118
  74. package/types/attemptdiff.d.ts +0 -38
package/src/try-checks.js CHANGED
@@ -3,6 +3,7 @@
3
3
  // checks. A check that did not run (the done check halts before the others) is not listed. A hitl close has no mechanical check, so it adds none.
4
4
  import { createHash } from 'node:crypto';
5
5
  import { serializeArtifact } from './ask.js';
6
+ import { labelled } from './checkwords.js';
6
7
 
7
8
  export const EVERY_STEP = 'every step';
8
9
 
@@ -44,6 +45,14 @@ export function outputRecord(step, artifact) {
44
45
  * @param {any} step @param {any} artifact @param {{verdict: string, red?: string|null, checks?: Array<{text:string, ok:boolean, result:string|null}>}} closed
45
46
  */
46
47
  export function closeRecords(step, artifact, closed) {
48
+ const rows = factRecords(step, artifact, closed);
49
+ // M10 am22 (1): the picks on a fact line are rows after the fact rows, each judged on the answer's text
50
+ const picks = Array.isArray(/** @type {any} */ (closed).pickChecks) ? /** @type {any} */ (closed).pickChecks : [];
51
+ return [...rows, ...picks.map((/** @type {any} */ c, i) => ({ n: rows.length + 3 + i, text: labelled(c.text, 'picked'), ok: c.ok, result: c.result, source: lineSource(step) }))];
52
+ }
53
+
54
+ /** @param {any} step @param {any} artifact @param {any} closed */
55
+ function factRecords(step, artifact, closed) {
47
56
  const source = lineSource(step);
48
57
  if (closed.verdict === 'unparseable' || closed.verdict === 'crash') {
49
58
  return [{
@@ -53,13 +62,13 @@ export function closeRecords(step, artifact, closed) {
53
62
  if (step?.close?.class === 'green' && Array.isArray(step?.close?.sheet) && Array.isArray(closed.checks)) {
54
63
  // M10b piece 2: each signed sheet check is its own row, worded by `sheetCheckSentence`, judged by bareguard
55
64
  return closed.checks.map((c, i) => ({
56
- n: 3 + i, text: c.text, ok: c.ok, result: c.result, source,
65
+ n: 3 + i, text: labelled(c.text, 'agent'), ok: c.ok, result: c.result, source,
57
66
  }));
58
67
  }
59
68
  if (step?.close?.class === 'green' && step?.close?.cited) {
60
69
  const n = Array.isArray(artifact?.results) ? artifact.results.length : 0;
61
70
  return [{
62
- n: 3, text: 'every result is quoted from the saved copy and passes its rules', ok: closed.verdict === 'green', result: `${n} result${n === 1 ? '' : 's'}`, source,
71
+ n: 3, text: labelled('every result is quoted from the saved copy and passes its rules', 'agent'), ok: Array.isArray(/** @type {any} */ (closed).pickChecks) && closed.cited?.check ? closed.cited.check.verdict === 'green' : closed.verdict === 'green', result: `${n} result${n === 1 ? '' : 's'}`, source,
63
72
  }];
64
73
  }
65
74
  if (step?.close?.class === 'green') {
@@ -68,7 +77,8 @@ export function closeRecords(step, artifact, closed) {
68
77
  n: 3, text: 'every cited field matches its source', ok: closed.verdict === 'green', result: `${n} field${n === 1 ? '' : 's'}`, source,
69
78
  }];
70
79
  }
80
+ // M10 am22 (4): a softgreen check is the person's when it is one of their picks, the drafter's otherwise; the one-key row is code's own and carries no label
71
81
  return (closed.checks ?? []).map((c, i) => ({
72
- n: 3 + i, text: c.text, ok: c.ok, result: c.result, source,
82
+ n: 3 + i, text: /** @type {any} */ (c).id === 'keys' ? c.text : labelled(c.text, /^pick\d+$/.test(String(/** @type {any} */ (c).id)) ? 'picked' : 'agent'), ok: c.ok, result: c.result, source,
73
83
  }));
74
84
  }
@@ -0,0 +1,71 @@
1
+ // M13 am9: the file holds the whole job. ONE writer of the whole-job text (`wholeJobText`), ONE finder of the Ask that shows it (`wholeJobAskIndex`).
2
+ // The last Ask before the added `write it out` shows every step's result in job order, built by code from each step's saved output (never picked by the AI):
3
+ // a work step is one section `## Line <n>: <line words>` + `renderSentMd(<its saved output>)` (the M15 form, unchanged); an Ask before it is one line
4
+ // `Line <n>: you accepted this at the Ask.`; the last Ask itself and the send line are not sections. The accepted artifact is `{text}`, so the send ships it unchanged.
5
+ // Throws away: nothing of a step's saved output beyond what `renderSentMd` already drops. Third outcomes: a work step with no readable saved output refuses, naming the step.
6
+ import { renderSentMd } from './send.js';
7
+ import { addedLinesOf } from './added-end.js';
8
+
9
+ /**
10
+ * The index of the Ask that shows the whole job: the Ask the added send reads, only when the plan has the am8 added `write it out`. A job signed before am8
11
+ * (its send line is the person's own words) finds -1 and keeps today's behaviour exactly.
12
+ * @param {{ steps: { fromLine: number, goal: string, emits?: string, reads?: string[] }[], askLines: Map<number, any>, sendLines: Map<number, any> }} p
13
+ * @returns {number} -1 = none
14
+ */
15
+ export function wholeJobAskIndex({ steps, askLines, sendLines }) {
16
+ if (sendLines.size !== 1) return -1;
17
+ const send = [...sendLines.values()][0];
18
+ const lines = steps.map((s) => ({ n: s.fromLine, text: s.goal }));
19
+ if (!addedLinesOf(lines, { sends: [...sendLines.values()], asks: [...askLines.values()] }).has(send.line)) return -1;
20
+ const sendStep = steps.find((s) => s.fromLine === send.line);
21
+ const askIds = (sendStep?.reads ?? []).filter((id) => steps.some((s) => s.emits === id && askLines.has(s.fromLine)));
22
+ if (askIds.length !== 1) return -1;
23
+ return steps.findIndex((s) => s.emits === askIds[0]);
24
+ }
25
+
26
+ /**
27
+ * @param {{ steps: { fromLine: number, goal: string, emits?: string }[], askLines: Map<number, any>, lastAskIndex: number,
28
+ * readResult: (id: string) => ({ ok: true, value: any } | { ok: false, missing: true } | { ok: false, missing: false, red: string }) }} p
29
+ * @returns {{ ok: true, value: { text: string } } | { ok: false, red: string }}
30
+ */
31
+ export function wholeJobText({ steps, askLines, lastAskIndex, readResult }) {
32
+ /** @type {string[]} */
33
+ const parts = [];
34
+ for (let i = 0; i < lastAskIndex; i += 1) {
35
+ const s = steps[i];
36
+ if (askLines.has(s.fromLine)) {
37
+ parts.push(`Line ${s.fromLine}: you accepted this at the Ask.`);
38
+ continue;
39
+ }
40
+ const r = readResult(/** @type {string} */ (s.emits));
41
+ if (!r.ok) {
42
+ return {
43
+ ok: false,
44
+ red: r.missing
45
+ ? `ask: the saved output "${s.emits}" of step "${s.goal}" is missing — refusing to show the whole job`
46
+ : `ask: the saved output "${s.emits}" of step "${s.goal}" — ${r.red}`,
47
+ };
48
+ }
49
+ parts.push(`## Line ${s.fromLine}: ${s.goal}\n${renderSentMd(r.value)}`);
50
+ }
51
+ return { ok: true, value: { text: parts.join('\n\n') } };
52
+ }
53
+
54
+ /**
55
+ * M13 am9 item 4: the plan shows the last Ask as reading every step. Code sets the Ask's `reads` to every work step's emits before it (the nearest one first, so a
56
+ * redo still re-runs the step just before the Ask; the rest in job order). Only a plan with the am8 added end; any other plan comes back as it was.
57
+ * @template {{ fromLine: number, goal: string, emits?: string, reads?: string[], primitives?: string[] }} S
58
+ * @param {S[]} steps @param {{ asks?: { line: number }[], sends?: { line: number }[] }} arbiter
59
+ * @returns {S[]}
60
+ */
61
+ export function readEveryStep(steps, arbiter) {
62
+ if (!Array.isArray(steps) || !steps.every((s) => s && typeof s === 'object')) return steps;
63
+ const askLines = new Map((arbiter?.asks ?? []).map((a) => [a.line, a]));
64
+ const sendLines = new Map((arbiter?.sends ?? []).map((x) => [x.line, x]));
65
+ const idx = wholeJobAskIndex({ steps, askLines, sendLines });
66
+ if (idx < 1) return steps;
67
+ const work = steps.slice(0, idx).filter((s) => !askLines.has(s.fromLine) && typeof s.emits === 'string').map((s) => /** @type {string} */ (s.emits));
68
+ if (work.length === 0) return steps;
69
+ const reads = [work[work.length - 1], ...work.slice(0, -1)];
70
+ return steps.map((s, i) => (i === idx ? { ...s, reads } : s));
71
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @param {{ n: number, text: string, ask: null | { wait: string|null, question: string }, guardrails: string[] }[]} steps `parseJobBox` steps
3
+ * @param {string} destination the card's Destination ('' = none)
4
+ * @returns {{ steps: { n: number, text: string, ask: null | { wait: string|null, question: string }, guardrails: string[] }[], added: number[] }} the steps with the end added, and the numbers of the added lines
5
+ */
6
+ export function addEnd(steps: {
7
+ n: number;
8
+ text: string;
9
+ ask: null | {
10
+ wait: string | null;
11
+ question: string;
12
+ };
13
+ guardrails: string[];
14
+ }[], destination: string): {
15
+ steps: {
16
+ n: number;
17
+ text: string;
18
+ ask: null | {
19
+ wait: string | null;
20
+ question: string;
21
+ };
22
+ guardrails: string[];
23
+ }[];
24
+ added: number[];
25
+ };
26
+ /**
27
+ * The added lines of a plan, found again from its signed lines and arbiter: the send line when it reads `write it out`, and the Ask just before it
28
+ * when that reads `check the result with me`. A job signed before M13 am8 (its send line is the person's own words) finds none.
29
+ * @param {{ n: number, text: string }[]} lines @param {{ sends?: { line: number }[], asks?: { line: number }[] }} arbiter
30
+ * @returns {Set<number>}
31
+ */
32
+ export function addedLinesOf(lines: {
33
+ n: number;
34
+ text: string;
35
+ }[], arbiter: {
36
+ sends?: {
37
+ line: number;
38
+ }[];
39
+ asks?: {
40
+ line: number;
41
+ }[];
42
+ }): Set<number>;
43
+ /**
44
+ * The lines a person typed, found again from a signed job: the signed lines without the send line (the last line when it is the send; today's `write it out`, or
45
+ * the person's own words in a job signed before am8) and without an added Ask before it. ONE reader for the Edit card (`cardFromSigned`) and the job identity (`jobKeyOfSigned`).
46
+ * @template {{ n: number, text: string }} L
47
+ * @param {L[]} lines @param {{ sends?: { line: number }[], asks?: { line: number }[] }} arbiter
48
+ * @returns {L[]}
49
+ */
50
+ export function typedLinesOf<L extends {
51
+ n: number;
52
+ text: string;
53
+ }>(lines: L[], arbiter: {
54
+ sends?: {
55
+ line: number;
56
+ }[];
57
+ asks?: {
58
+ line: number;
59
+ }[];
60
+ }): L[];
61
+ export const ADDED_ASK_QUESTION: "check the result with me";
62
+ export const ADDED_WRITE: "write it out";
package/types/ask.d.ts CHANGED
@@ -227,7 +227,7 @@ export function readAcceptedHashesByEmits(runDir: string): {
227
227
  /**
228
228
  * @param {string} runDir
229
229
  * @returns {{ archived: true, asks: Array<{ askId: string, question?: string, askedAt?: string, expiresAt?: string,
230
- * evidence: ReturnType<typeof readAskEvidence>,
230
+ * evidence: ReturnType<typeof readAskEvidence>, emits?: string,
231
231
  * answer: { status: string, reason?: string, answeredAt?: string, why?: string } }> } | { archived: false, why: string }}
232
232
  */
233
233
  export function listArchivedAsks(runDir: string): {
@@ -238,6 +238,7 @@ export function listArchivedAsks(runDir: string): {
238
238
  askedAt?: string;
239
239
  expiresAt?: string;
240
240
  evidence: ReturnType<typeof readAskEvidence>;
241
+ emits?: string;
241
242
  answer: {
242
243
  status: string;
243
244
  reason?: string;
@@ -13,7 +13,7 @@ export function humanWords(r: any): string | null;
13
13
  * The fold of one step, or `null` for a step with nothing new to show (an old run, or a step that is neither a model step with records nor an ask).
14
14
  * @param {{rows:any[], tryMarks:string[], closeClass:string|null}} group `deriveAuditGroups`' group for the step
15
15
  * @param {ReturnType<typeof loadDiaries>} d
16
- * @param {{about?: string|null}} [info] `about`: the file an ask is about
16
+ * @param {{about?: string|null, rerun?: {words: string}|null}} [info] `about`: the file an ask is about; `rerun`: this run's reason for starting (run.json), given for its first step only
17
17
  */
18
18
  export function deriveFold(group: {
19
19
  rows: any[];
@@ -21,11 +21,21 @@ export function deriveFold(group: {
21
21
  closeClass: string | null;
22
22
  }, d: ReturnType<typeof loadDiaries>, info?: {
23
23
  about?: string | null;
24
+ rerun?: {
25
+ words: string;
26
+ } | null;
24
27
  }): {
25
28
  who: string;
26
29
  tally: string | null;
27
30
  tries: any[];
28
- rows: any[];
31
+ rows: {
32
+ round: null;
33
+ try: any;
34
+ action: string;
35
+ path: string | null;
36
+ decision: string;
37
+ at: any;
38
+ }[];
29
39
  counts: {
30
40
  rounds: number;
31
41
  tools: number;
@@ -52,3 +62,4 @@ export function summaryLines(d: ReturnType<typeof loadDiaries>): {
52
62
  calls: string;
53
63
  checks: string;
54
64
  };
65
+ export function rerunWords(words: string): string;
@@ -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}[], 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, 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: {
@@ -38,6 +38,8 @@ export function readQuestions(planDir: string): {
38
38
  ruleNo?: number;
39
39
  ruleText?: string;
40
40
  proposal?: string | null;
41
+ check?: Record<string, any>;
42
+ pairRule?: number;
41
43
  }[];
42
44
  open: {
43
45
  k: number;
@@ -95,7 +97,7 @@ export function draftKeyRefusal(slot: string, env: Record<string, string | undef
95
97
  * Test seam: `provider`/`rates`/`modelId` are injected; without them a live provider is built.
96
98
  * `onResult({ ok })` (M4d am32): called once, after the spend is booked and just before the result files are written (the CLI gives its monthly hold back there).
97
99
  */
98
- export function draftToDir({ proseFile, dir, root, name, slot, model, draftThinking, keyNames, env, provider, rates, modelId, noQuestions, onResult, fetchPage, leftRules, proseRead, flowType, mcpServer, mcpPick, mcpServers, }: {
100
+ export function draftToDir({ proseFile, dir, root, name, slot, model, draftThinking, keyNames, env, provider, rates, modelId, noQuestions, onResult, fetchPage, leftRules, checkPicks, carriedPicks, proseRead, flowType, mcpServer, mcpPick, mcpServers, }: {
99
101
  proseFile: any;
100
102
  dir: any;
101
103
  root: any;
@@ -112,6 +114,8 @@ export function draftToDir({ proseFile, dir, root, name, slot, model, draftThink
112
114
  onResult: any;
113
115
  fetchPage: any;
114
116
  leftRules: any;
117
+ checkPicks: any;
118
+ carriedPicks: any;
115
119
  proseRead: any;
116
120
  flowType?: "mcp" | "plain" | "tickets" | undefined;
117
121
  mcpServer?: string | undefined;
@@ -2,17 +2,22 @@
2
2
  * One entry per step, in plan order: the plain sentences for what its typed close checks.
3
3
  * M10b piece 4: with `lines` (the signed job lines) a step that reads a sheet also carries `sheet`, its line's block (src/sheetblock.js `sheetLineBlocks`: guardrails,
4
4
  * Checked with `covers`, Not checked), and its sentences are only the lead sentence; the surfaces draw the block. Without `lines` the older one-row-per-check sentences.
5
- * @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[], lines?: any[], csvRoles?: string[] }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
5
+ * @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[], lines?: any[], csvRoles?: string[], keptChecks?: {line: number, check: any}[], keptWords?: string }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
6
6
  * askLines = the job lines of the signed asks, which also lets a step after the LAST ask read "you check it after you accept" (am41 item 2, am42: the ONE place for these words)
7
7
  * @returns {{ step: number, line: number|null, goal: string, class: string, sentences: string[], sheet?: ReturnType<typeof sheetLineBlocks>[number] }[]}
8
8
  */
9
9
  export function checkedLines(declaration: {
10
10
  steps?: any[];
11
- }, { hasAsk, askLines, lines, csvRoles }?: {
11
+ }, { hasAsk, askLines, lines, csvRoles, keptChecks, keptWords }?: {
12
12
  hasAsk?: boolean;
13
13
  askLines?: number[];
14
14
  lines?: any[];
15
15
  csvRoles?: string[];
16
+ keptChecks?: {
17
+ line: number;
18
+ check: any;
19
+ }[];
20
+ keptWords?: string;
16
21
  }): {
17
22
  step: number;
18
23
  line: number | null;
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Every guardrail rule on a step line (not a signed ask or send line) that this call settles, in line order. `rule` is the rule's number on its line (the one
3
+ * number `leftRules`, `ruleNo` and the answers use); a repeated text on a line is one rule here, asked once.
4
+ * @param {{n: number, guardrail?: string}[]} lines `parseSignedText`'s lines @param {{asks?: {line: number}[], sends?: {line: number}[], sources?: any[]}} arbiter
5
+ * @returns {{line: number, rule: number, text: string}[]}
6
+ */
7
+ export function scopedRules(lines: {
8
+ n: number;
9
+ guardrail?: string;
10
+ }[], arbiter: {
11
+ asks?: {
12
+ line: number;
13
+ }[];
14
+ sends?: {
15
+ line: number;
16
+ }[];
17
+ sources?: any[];
18
+ }): {
19
+ line: number;
20
+ rule: number;
21
+ text: string;
22
+ }[];
23
+ /**
24
+ * Keep a suggestion only if its rule is on bareguard's list, it carries only that rule's own fields, every number in it is a number the guardrail names and
25
+ * every word in it is a word of the guardrail. Anything else is dropped, with the reason. `none` is a drop with the reason `none`.
26
+ * @param {string} guardrail @param {any} sug the model's entry for this guardrail
27
+ * @returns {{kept: true, check: Record<string, any>}|{kept: false, why: string}}
28
+ */
29
+ export function keepOrDrop(guardrail: string, sug: any): {
30
+ kept: true;
31
+ check: Record<string, any>;
32
+ } | {
33
+ kept: false;
34
+ why: string;
35
+ };
36
+ /**
37
+ * The user message: the job's lines, and under a line only the guardrails this call settles, numbered by their rule number on the line.
38
+ * @param {{n: number, text: string}[]} lines @param {{line: number, rule: number, text: string}[]} scoped @returns {string}
39
+ */
40
+ export function suggestUserText(lines: {
41
+ n: number;
42
+ text: string;
43
+ }[], scoped: {
44
+ line: number;
45
+ rule: number;
46
+ text: string;
47
+ }[]): string;
48
+ /**
49
+ * What the call's answer comes to, one row per scoped guardrail: the check kept (or null) and why it was dropped. A guardrail the answer never mentions is
50
+ * dropped as `no entry`; an entry for a guardrail that was not sent is ignored.
51
+ * @param {{line: number, rule: number, text: string}[]} scoped @param {any} args the tool call's arguments
52
+ * @returns {{line: number, rule: number, text: string, check: Record<string, any>|null, why: string|null}[]}
53
+ */
54
+ export function rowsFromAnswer(scoped: {
55
+ line: number;
56
+ rule: number;
57
+ text: string;
58
+ }[], args: any): {
59
+ line: number;
60
+ rule: number;
61
+ text: string;
62
+ check: Record<string, any> | null;
63
+ why: string | null;
64
+ }[];
65
+ /**
66
+ * The check CODE proposes for a count rule when the call yields none: a bullets / list-items / points count -> listItems N, a lines count -> maxLines N, ONE word number ->
67
+ * minWords N when the rule says "at least / minimum / more than", else maxWords N. A section count names no sections, so none is built; a rule naming two different counts is
68
+ * not built either; a rule with several word numbers or a range is not guessed. The result passes `keepOrDrop`, so every number is one the rule names.
69
+ * @param {string} text @returns {Record<string, any>|null}
70
+ */
71
+ export function countCheck(text: string): Record<string, any> | null;
72
+ /**
73
+ * 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
74
+ * Not checked?` when nothing was kept. A proposal is not counted toward am1's cap; a can't-check ask is (am16 (5)).
75
+ * @param {ReturnType<typeof rowsFromAnswer>} rows
76
+ * @returns {{pairRule?: number, line: number, rule: number, source: 'look', ask: 'check'|'no-check', ruleText: string, question: string, reading?: string, check?: Record<string, any>, counted: boolean}[]}
77
+ */
78
+ export function checkAsks(rows: ReturnType<typeof rowsFromAnswer>): {
79
+ pairRule?: number;
80
+ line: number;
81
+ rule: number;
82
+ source: "look";
83
+ ask: "check" | "no-check";
84
+ ruleText: string;
85
+ question: string;
86
+ reading?: string;
87
+ check?: Record<string, any>;
88
+ counted: boolean;
89
+ }[];
90
+ /**
91
+ * @typedef {{line: number, rule: number, check: Record<string, any>|null, added?: string, own?: boolean}} Pick
92
+ * `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
93
+ */
94
+ /**
95
+ * Settle every scoped rule against the person's answers: a rule with a picked check is checked; the `~` line an agree wrote is covered by that pick; every other
96
+ * rule is Not checked, with the reason (`person-left` = they chose it, `own-words` = they gave their own words, `no-pick` = nothing was picked).
97
+ * @param {ReturnType<typeof scopedRules>} rules @param {Pick[]} picks @param {{line: number, rule: number}[]} left
98
+ * @returns {{checks: Map<number, Record<string, any>[]>, notes: {line: number, rule: number, text: string, reason: 'person-left'|'own-words'|'no-pick'}[]}}
99
+ */
100
+ export function settleRules(rules: ReturnType<typeof scopedRules>, picks: Pick[], left: {
101
+ line: number;
102
+ rule: number;
103
+ }[]): {
104
+ checks: Map<number, Record<string, any>[]>;
105
+ notes: {
106
+ line: number;
107
+ rule: number;
108
+ text: string;
109
+ reason: "person-left" | "own-words" | "no-pick";
110
+ }[];
111
+ };
112
+ /**
113
+ * Overwrite the drafter's check on every step of a line this call settles (a green step, which another signed part settles, is left alone): a line with picked checks
114
+ * is softgreen and carries exactly those checks; a line with none is hitl. Whatever `close.shape` the drafter wrote is gone. Pure: returns a new declaration.
115
+ * @param {any} declaration @param {ReturnType<typeof scopedRules>} rules @param {ReturnType<typeof settleRules>} settled
116
+ * @param {(note: {line: number, reason: 'person-left'|'own-words'|'no-pick'}) => string} sentence the one table's words for a reason
117
+ */
118
+ export function applyPicks(declaration: any, rules: ReturnType<typeof scopedRules>, settled: ReturnType<typeof settleRules>, sentence: (note: {
119
+ line: number;
120
+ reason: "person-left" | "own-words" | "no-pick";
121
+ }) => string): any;
122
+ /**
123
+ * M10 am27 (4) RETENTION record of one draft (record only, counts, no words). Per job line: `aiParts` = the cited facts the drafter wrote on that line (a `cited` close counts once per
124
+ * fact, at least 1), `kept` = how many are still in the final declaration, `dropped` = what code removed, `picks` = the line has the person's picks; `classAsked` / `classFinal`
125
+ * = the line's close class as the drafter sent it and as it ended. Pure.
126
+ * @param {any} drafted the declaration as the drafter sent it @param {any} final the declaration the draft ended with @param {any[]|null|undefined} jobLines @param {Iterable<number>} [pickLines]
127
+ * @returns {{line: number, aiParts: number, kept: number, dropped: number, picks: boolean, classAsked: string|null, classFinal: string|null}[]}
128
+ */
129
+ export function retentionOf(drafted: any, final: any, jobLines: any[] | null | undefined, pickLines?: Iterable<number>): {
130
+ line: number;
131
+ aiParts: number;
132
+ kept: number;
133
+ dropped: number;
134
+ picks: boolean;
135
+ classAsked: string | null;
136
+ classFinal: string | null;
137
+ }[];
138
+ /** the one tool the suggestion call is forced to use */
139
+ export const SUGGEST_TOOL: "suggest_checks";
140
+ export function hasRoutingInput(sources: any[] | undefined): boolean;
141
+ export function codeScope(sources: any[] | undefined, g: string): "in" | "out";
142
+ export function offerRules(lines: {
143
+ n: number;
144
+ guardrail?: string;
145
+ }[], arbiter: any, facts: {
146
+ line: number;
147
+ forRule?: number;
148
+ }[]): {
149
+ line: number;
150
+ rule: number;
151
+ text: string;
152
+ }[];
153
+ export const SUGGEST_SYSTEM: string;
154
+ /** the forced tool's parameter schema: one `anyOf` variant per offered rule, plus `none` */
155
+ export const SUGGEST_SCHEMA: Readonly<{
156
+ type: "object";
157
+ properties: {
158
+ checks: {
159
+ type: string;
160
+ description: string;
161
+ items: {
162
+ anyOf: any[];
163
+ };
164
+ };
165
+ };
166
+ required: string[];
167
+ additionalProperties: false;
168
+ }>;
169
+ /** the can't-check ask, as the signed words say it */
170
+ export const CANT_CHECK_WORDS: "I can't check this. Your own words, or Not checked?";
171
+ /**
172
+ * `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
+ export type Pick = {
175
+ line: number;
176
+ rule: number;
177
+ check: Record<string, any> | null;
178
+ added?: string;
179
+ own?: boolean;
180
+ };
181
+ import { plainWords } from './checkwords.js';
182
+ import { OFFERED } from './checkwords.js';
183
+ export { plainWords, OFFERED };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The check in plain words, one fixed phrase per rule: the ask, the `~` line an agree writes, the plan card and the Audit all read this one function.
3
+ * @param {{rule: string, value?: number, size?: number, wordsPerSection?: number, names?: string[], phrases?: string[]}} c @returns {string}
4
+ */
5
+ export function plainWords(c: {
6
+ rule: string;
7
+ value?: number;
8
+ size?: number;
9
+ wordsPerSection?: number;
10
+ names?: string[];
11
+ phrases?: string[];
12
+ }): string;
13
+ /** the rules of bareguard's list a person may pick here (text rules only: the ones a plain answer can be judged by) */
14
+ export const OFFERED: readonly string[];
15
+ /** M10 am22 (4): who added a check, the ONE place these two words live. The plan card, the Job tab and the Audit trail write them after the check's words. */
16
+ export const LABEL_AGENT: "[agent]";
17
+ export const LABEL_PICKED: "[you picked]";
18
+ export function labelled(text: string, by: "agent" | "picked"): string;
@@ -57,6 +57,12 @@ export function citedBrief(part: any): {
57
57
  eachResultHolds: string[];
58
58
  howMany: string | null;
59
59
  };
60
+ /**
61
+ * M10 am28: what a page-quoting step is told about the picks (am22) on its line, one plain line per pick, the values and what counts, never a verdict and never
62
+ * another guardrail. A list item is what bareguard's listItems counts: its own line starting with "1." or "- " followed by a space and its text.
63
+ * @param {any[]} picked @returns {string[]}
64
+ */
65
+ export function toldPicks(picked: any[]): string[];
60
66
  /**
61
67
  * Every plan-card row a fact part carries: its facts, then its count (bareloop's factRows).
62
68
  * @param {any} part @returns {string[]}
@@ -52,12 +52,13 @@ export function buildSoftgreenRubric(shape: Record<string, any>): ReturnType<typ
52
52
  * A gap it has no sentence for is still a red, worded generically, never dropped.
53
53
  *
54
54
  * @param {any[]} gaps
55
- * @param {{ linesPerInvoice?: number, mustCarry?: string[] }} shape
55
+ * @param {{ linesPerInvoice?: number, mustCarry?: string[], picked?: any[] }} shape
56
56
  * @returns {{ red: string, reds: string[] }}
57
57
  */
58
58
  export function renderSoftgreenGaps(gaps: any[], shape: {
59
59
  linesPerInvoice?: number;
60
60
  mustCarry?: string[];
61
+ picked?: any[];
61
62
  }): {
62
63
  red: string;
63
64
  reds: string[];
@@ -70,7 +71,7 @@ export function renderSoftgreenGaps(gaps: any[], shape: {
70
71
  * Async because bareguard's `checkStep` is.
71
72
  *
72
73
  * @param {any} artifact
73
- * @param {{ maxWords?: number, sections?: string[], wordsPerSection?: number, linesPerInvoice?: number, mustCarry?: string[] }} shape
74
+ * @param {{ maxWords?: number, sections?: string[], wordsPerSection?: number, linesPerInvoice?: number, mustCarry?: string[], picked?: any[] }} shape
74
75
  * @returns {Promise<CloseVerdict>}
75
76
  */
76
77
  export function closeSoftgreen(artifact: any, shape: {
@@ -79,11 +80,12 @@ export function closeSoftgreen(artifact: any, shape: {
79
80
  wordsPerSection?: number;
80
81
  linesPerInvoice?: number;
81
82
  mustCarry?: string[];
83
+ picked?: any[];
82
84
  }): Promise<CloseVerdict>;
83
85
  /**
84
86
  * The one dispatcher — `close by declared class` (M2 scope item 4).
85
87
  *
86
- * @param {{ close?: { class?: string, shape?: Record<string, any>, cited?: any, columns?: {source: string, column: string}[], sheet?: any[] } }} step
88
+ * @param {{ close?: { class?: string, shape?: Record<string, any>, picked?: any[], cited?: any, columns?: {source: string, column: string}[], sheet?: any[] } }} step
87
89
  * @param {unknown} artifact
88
90
  * @param {{ reads: Record<string, any>, businessDate: string, source?: {ok: true, text: string, sha256: string}|{ok: false, red: string}|null, sheet?: any }} ctx
89
91
  * `source` (M10 piece 4) = the run's own frozen copy a cited step reads, from `readRunSource`; only a step whose close carries `cited` reads it
@@ -94,6 +96,7 @@ export function closeByClass(step: {
94
96
  close?: {
95
97
  class?: string;
96
98
  shape?: Record<string, any>;
99
+ picked?: any[];
97
100
  cited?: any;
98
101
  columns?: {
99
102
  source: string;
@@ -29,10 +29,21 @@ export function checkShapes(declaration: any): {
29
29
  * there is none. Code does not decide which one is the limit: the AI picks `maxWords` and the validator checks the pick is one of these
30
30
  * (M4e amendments 28 + 29). A "<n> words each" / "<n> words per section" is the per-section size (amendment 15), never listed here. */
31
31
  export function guardrailWordNumbers(guardrail: any): number[];
32
+ /** M10 amendment 14 item 2: every standalone number in a guardrail's own text (digits not joined to letters: "P1" and "250ish" are not one; "1,000" and "2.5" are one number each). */
33
+ export function guardrailStandaloneNumbers(guardrail: any): number[];
34
+ /** M10 amendment 14 item 1: the send line (a signed send) is where the accepted result is written out and no AI runs, so a guardrail under it is refused at $0, naming the line.
35
+ * Pure; the card (src/panel/authorcard.js checkCard) and the drafter's pre-flight both call it. @param {any[]} lines `parseSignedText`'s lines @param {{sends?: {line: number}[]}} arbiter */
36
+ export function checkSendLineGuardrail(lines: any[], arbiter: {
37
+ sends?: {
38
+ line: number;
39
+ }[];
40
+ }): string[];
32
41
  /** M4e amendment 15 item 1: the "<n> words each" / "<n> words per section" size in a guardrail ("about 250 words each", "250ish each" -> 250), or null. */
33
42
  export function guardrailWordsPerSection(guardrail: any): number | null;
34
43
  /** M4e amendment 7 item 1: the first "<N> sections" in a guardrail (N digits, or the words one..ten), or null. */
35
44
  export function guardrailSectionCount(guardrail: any): any;
45
+ /** M10 amendment 23: the first "<N> bullets / list items / items / lines / points" in a guardrail (N digits, or the words one..ten; not a price like "$5 per item"), or null. */
46
+ export function guardrailItemCount(guardrail: any): any;
36
47
  /** M4e amendment 15 item 2: for each line whose guardrail gives a size for each section, a section count AND a word number,
37
48
  * size x count more than the LARGEST word number (no possible pick fits) is a red naming the line and the numbers. $0; run before any model
38
49
  * call, when there is no AI pick yet (amendment 29). After the draft the AI's `maxWords` is checked in checkShapeFitsJobLine. */
@@ -102,6 +113,7 @@ export const FLOW_TYPES: readonly string[];
102
113
  export const SHAPE_KEYS: readonly string[];
103
114
  /** Shape keys only the MACHINE sets (M4e amendment 15): read from the line's guardrail, never offered to the drafter's model. */
104
115
  export const MACHINE_SHAPE_KEYS: readonly string[];
116
+ export function isCountGuardrail(guardrail: any): boolean;
105
117
  export type Arbiter = import("./types.js").Arbiter;
106
118
  export type SignedLine = import("./types.js").SignedLine;
107
119
  export type CatalogueEntry = import("./types.js").CatalogueEntry;