fwdloop 0.22.0 → 0.23.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 +2 -2
- package/src/ask.js +20 -4
- package/src/authoring.js +4 -0
- package/src/canrun.js +5 -0
- package/src/checked.js +14 -3
- package/src/citedcheck.js +16 -1
- package/src/closers.js +13 -223
- package/src/csv.js +69 -12
- package/src/declaration.js +64 -6
- package/src/drafter.js +37 -15
- package/src/model-step.js +13 -21
- package/src/panel/author.js +2 -1
- package/src/panel/authorcard.js +9 -2
- package/src/panel/data.js +20 -5
- package/src/panel/index.html +43 -1
- package/src/panel/result.js +6 -0
- package/src/runner.js +24 -7
- package/src/sheet-record.js +57 -0
- package/src/sheetblock.js +170 -0
- package/src/sheetchecks.js +206 -0
- package/src/sheetclaims.js +78 -0
- package/src/sheetoffer.js +125 -0
- package/src/sheetrun.js +105 -0
- package/src/try-checks.js +6 -0
- package/src/types.js +1 -9
- package/types/ask.d.ts +2 -1
- package/types/checked.d.ts +9 -3
- package/types/closers.d.ts +6 -31
- package/types/csv.d.ts +25 -4
- package/types/declaration.d.ts +6 -1
- package/types/drafter.d.ts +22 -8
- package/types/model-step.d.ts +19 -30
- package/types/panel/authorcard.d.ts +2 -1
- package/types/runner.d.ts +8 -4
- package/types/sheet-record.d.ts +24 -0
- package/types/sheetblock.d.ts +116 -0
- package/types/sheetchecks.d.ts +70 -0
- package/types/sheetclaims.d.ts +26 -0
- package/types/sheetoffer.d.ts +25 -0
- package/types/sheetrun.d.ts +35 -0
- package/types/types.d.ts +16 -11
package/src/declaration.js
CHANGED
|
@@ -39,6 +39,9 @@
|
|
|
39
39
|
import { buildSoftgreenRubric, isCellsPath } from './closers.js';
|
|
40
40
|
import { factPartReds } from './citedcheck.js';
|
|
41
41
|
import { numberRuleReds, countReds, citedWordReds } from './citedwords.js';
|
|
42
|
+
import { SHEET_RULES, MAX_SHEET_CHECKS, sheetCheckColumns, sheetCheckReds, sheetCheckWordReds, sheetNoClaimReds, sheetCoversReds } from './sheetchecks.js';
|
|
43
|
+
import { lineRules } from './pagebits.js';
|
|
44
|
+
import { isColumnChoiceRule } from './sheetoffer.js';
|
|
42
45
|
|
|
43
46
|
/** @typedef {import('./types.js').Arbiter} Arbiter */
|
|
44
47
|
/** @typedef {import('./types.js').SignedLine} SignedLine */
|
|
@@ -68,6 +71,7 @@ export const DECLARATION_FIELDS = Object.freeze([
|
|
|
68
71
|
'shape',
|
|
69
72
|
'cited',
|
|
70
73
|
'columns',
|
|
74
|
+
'sheet',
|
|
71
75
|
]);
|
|
72
76
|
|
|
73
77
|
const VALID_CLASSES = Object.freeze(['green', 'softgreen', 'hitl']);
|
|
@@ -80,7 +84,7 @@ const ARBITER_KEYS = Object.freeze(['cap', 'ask', 'ttl', 'send', 'source', 'trig
|
|
|
80
84
|
|
|
81
85
|
const TOP_LEVEL_ALLOWED = Object.freeze(['steps', 'guardrailClasses', 'unjudgeable', 'refused', 'inputFacts']);
|
|
82
86
|
const STEP_ALLOWED = Object.freeze(['goal', 'primitives', 'reads', 'emits', 'fromLine', 'close', 'picks']);
|
|
83
|
-
const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns']);
|
|
87
|
+
const CLOSE_ALLOWED = Object.freeze(['class', 'shape', 'cited', 'columns', 'sheet']);
|
|
84
88
|
|
|
85
89
|
/** @returns {value is Record<string, any>} */
|
|
86
90
|
function isPlainObject(value) {
|
|
@@ -435,10 +439,10 @@ function checkCitedKey(step, label, c, reds) {
|
|
|
435
439
|
}
|
|
436
440
|
|
|
437
441
|
/**
|
|
438
|
-
* M10 am8 item 2: `close.columns` is the column
|
|
442
|
+
* M10 am8 item 2: `close.columns` is the column choice of a green step that reads a sheet: `[{source, column}]`, written by the drafter and checked by code (the old cell-cite check that enforced it at run time retired in M10b piece 5; a job signed with it still reads). Its SHAPE is
|
|
439
443
|
* checked in every mode; with `sheetWords` (draft time) every column is proved to be a real column of its sheet and a column the sheet look kept for this step's
|
|
440
|
-
* line must be in the list.
|
|
441
|
-
* @param {any} step @param {string} label @param {{cellsRoles: string[], reads: string[]|null, effectiveClass: string, sheetWords?: {headers: Record<string, string[]>, facts: any[]}}} c @param {string[]} reds
|
|
444
|
+
* line must be in the list. M10b am3: a step with `close.sheet` is exempt from the list; an AGREED column must instead be used by one of its checks.
|
|
445
|
+
* @param {any} step @param {string} label @param {{cellsRoles: string[], reads: string[]|null, effectiveClass: string, lines?: SignedLine[], sheetWords?: {headers: Record<string, string[]>, facts: any[]}}} c @param {string[]} reds
|
|
442
446
|
*/
|
|
443
447
|
function checkColumnsKey(step, label, c, reds) {
|
|
444
448
|
const at = `declaration: ${label}.close.columns`;
|
|
@@ -463,12 +467,57 @@ function checkColumnsKey(step, label, c, reds) {
|
|
|
463
467
|
const header = sw.headers?.[e.source];
|
|
464
468
|
if (Array.isArray(header) && !header.includes(e.column)) reds.push(`declaration: line ${step.fromLine}: '${e.column}' is not a real column of "${e.source}" (its columns: ${header.map((h) => `'${h}'`).join(', ')}). Copy a column name exactly.`);
|
|
465
469
|
}
|
|
470
|
+
const sheet = Array.isArray(step.close.sheet) ? step.close.sheet : null;
|
|
471
|
+
const covLine = (c.lines ?? []).find((l) => l.n === step.fromLine);
|
|
466
472
|
for (const f of sw.facts ?? []) {
|
|
467
473
|
if (f.line !== step.fromLine || f.shape !== 'column') continue;
|
|
474
|
+
if (sheet !== null) {
|
|
475
|
+
// M10b am3: with sheet checks a job word that matches a header does nothing by itself; only a column the person AGREED to (a column ask wrote
|
|
476
|
+
// "use the column 'X' for 'Y'" on the line) must be used by at least one of this line's checks
|
|
477
|
+
const agreed = f.agreed === true || lineRules(covLine).some((r) => isColumnChoiceRule(r) && r.startsWith(`use the column '${f.column}' for '`));
|
|
478
|
+
if (agreed && !sheet.some((chk) => chk?.table === f.source && sheetCheckColumns(chk).includes(f.column))) reds.push(`declaration: line ${step.fromLine}: a check must use the column '${f.column}' of "${f.source}" - the column you agreed to for this line.`);
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
468
481
|
if (!list.some((e) => e.source === f.source && e.column === f.column)) reds.push(`declaration: line ${step.fromLine}: the check must name the column '${f.column}' of "${f.source}" in close.columns - the code kept it for this line${f.agreed ? ' (the column you agreed to)' : ''}, and every cell must come from it.`);
|
|
469
482
|
}
|
|
470
483
|
}
|
|
471
484
|
|
|
485
|
+
/**
|
|
486
|
+
* M10b piece 1: `close.sheet` is the signed bareguard checks of a green step that reads a CSV sheet: a list of bareguard `cells` / `table` check objects
|
|
487
|
+
* (src/sheetchecks.js), each naming the step's sheet input in `table`. The drafter will offer them (piece 3); fwdloop stores them as data. Its SHAPE is checked in
|
|
488
|
+
* every mode (a signed flow is read the same way). With `sheetWords.tables` (the drafting copy's table of each sheet, draft time) every column is proved an exact
|
|
489
|
+
* header of its sheet and bareguard's own sign-time test (`createRubric` over the sheet's `tableSha`) must accept the list; each red names the job line.
|
|
490
|
+
* @param {any} step @param {string} label @param {{cellsRoles: string[], reads: string[]|null, effectiveClass: string, lines?: SignedLine[], fitJobLine?: boolean, sheetWords?: {tables?: Record<string, {header: string[], rows: any[]}>}}} c @param {string[]} reds
|
|
491
|
+
* M10b piece 3: with `fitJobLine` a number or a date in a check must be in the person's own words on the job line (src/sheetchecks.js `sheetCheckWordReds`), and a list of
|
|
492
|
+
* only `table` checks (nothing for the step to answer) is refused; each red names the line.
|
|
493
|
+
*/
|
|
494
|
+
function checkSheetKey(step, label, c, reds) {
|
|
495
|
+
const at = `declaration: ${label}.close.sheet`;
|
|
496
|
+
const list = step.close.sheet;
|
|
497
|
+
if (step.close.class !== 'green' || c.effectiveClass !== 'green') reds.push(`${at} is for a green step only (its sheet is checked by bareguard); this step's check is "${step.close.class ?? c.effectiveClass}"`);
|
|
498
|
+
if (!Array.isArray(list) || list.length === 0 || list.length > MAX_SHEET_CHECKS) { reds.push(`${at} must be a list of 1 to ${MAX_SHEET_CHECKS} bareguard checks`); return; }
|
|
499
|
+
let shapeOk = true;
|
|
500
|
+
for (const [j, e] of list.entries()) {
|
|
501
|
+
if (!isPlainObject(e)) { reds.push(`${at}[${j}] must be a check object`); shapeOk = false; continue; }
|
|
502
|
+
scanForArbiterKeys(e, `${at}[${j}]`, reds);
|
|
503
|
+
if (!SHEET_RULES.includes(e.rule)) { reds.push(`${at}[${j}].rule must be one of ${SHEET_RULES.join(', ')}`); shapeOk = false; }
|
|
504
|
+
if (typeof e.table !== 'string' || !c.cellsRoles.includes(e.table)) { reds.push(`${at}[${j}].table ${JSON.stringify(e.table)} is not a signed spreadsheet input`); shapeOk = false; }
|
|
505
|
+
else if (c.reads !== null && !c.reads.includes(e.table)) { reds.push(`${at}[${j}].table "${e.table}" is not in ${label}.reads - the step must read the sheet its checks come from`); shapeOk = false; }
|
|
506
|
+
}
|
|
507
|
+
if (shapeOk && Number.isInteger(step.fromLine)) {
|
|
508
|
+
const covLine = (c.lines ?? []).find((l) => l.n === step.fromLine);
|
|
509
|
+
if (covLine) for (const r of sheetCoversReds(list, { n: covLine.n, ...(covLine.guardrail ? { rule: covLine.guardrail } : {}) })) reds.push(r);
|
|
510
|
+
}
|
|
511
|
+
if (shapeOk && c.fitJobLine === true && Number.isInteger(step.fromLine)) {
|
|
512
|
+
const jobLine = (c.lines ?? []).find((l) => l.n === step.fromLine);
|
|
513
|
+
if (jobLine) for (const r of sheetCheckWordReds(list, { n: jobLine.n, text: jobLine.text, ...(jobLine.guardrail ? { rule: jobLine.guardrail } : {}) })) reds.push(r);
|
|
514
|
+
for (const r of sheetNoClaimReds(list, step.fromLine)) reds.push(r);
|
|
515
|
+
}
|
|
516
|
+
const tables = c.sheetWords?.tables;
|
|
517
|
+
if (!shapeOk || !tables || !Number.isInteger(step.fromLine)) return;
|
|
518
|
+
for (const r of sheetCheckReds(list, step.fromLine, tables)) reds.push(r);
|
|
519
|
+
}
|
|
520
|
+
|
|
472
521
|
/**
|
|
473
522
|
* Validate a drafter declaration against the M1 closed schema. `arbiter`
|
|
474
523
|
* and `lines` are `parseSignedText`'s output; `catalogue` is a plain array
|
|
@@ -488,7 +537,8 @@ function checkColumnsKey(step, label, c, reds) {
|
|
|
488
537
|
* `pageWords.docs` (M10 piece 5): the roles that are documents (.docx / .md / .txt): their words are proved on their text alone, with no page-word map.
|
|
489
538
|
* `sheetWords` (optional; M10 am8 item 2): `{headers: {role: header names}, facts: the columns the sheet look kept}`. With `fitJobLine`, every column a step's `close.columns` names
|
|
490
539
|
* is proved a real column of its sheet, and a column the code kept for the step's line (an agreed one included) must be in it.
|
|
491
|
-
*
|
|
540
|
+
* `sheetWords.tables` (optional; M10b piece 1): `{role: bareguard table}` of the drafting copy. With it, every `close.sheet` check passes bareguard's sign-time test at $0.
|
|
541
|
+
* @param {{ arbiter?: unknown, lines?: unknown, catalogue?: unknown, wired?: Set<string>, verbatimGoals?: boolean, fitJobLine?: boolean, pageWords?: {texts: Record<string, string>, look: any, docs?: string[]}, sheetWords?: {headers: Record<string, string[]>, facts: any[], tables?: Record<string, {header: string[], rows: any[]}>} }} [context]
|
|
492
542
|
* @returns {ValidateDeclarationResult}
|
|
493
543
|
*/
|
|
494
544
|
export function validateDeclaration(declaration, context = {}) {
|
|
@@ -768,7 +818,8 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
768
818
|
}
|
|
769
819
|
}
|
|
770
820
|
if (step.close.cited !== undefined) checkCitedKey(step, label, { sourceRoles, reads, effectiveClass, lines: safeLines, fitJobLine, pageWords }, reds);
|
|
771
|
-
if (step.close.
|
|
821
|
+
if (step.close.sheet !== undefined) checkSheetKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, fitJobLine, sheetWords }, reds);
|
|
822
|
+
if (step.close.columns !== undefined || (fitJobLine === true && sheetWords)) checkColumnsKey(step, label, { cellsRoles, reads, effectiveClass, lines: safeLines, sheetWords }, reds);
|
|
772
823
|
}
|
|
773
824
|
}
|
|
774
825
|
|
|
@@ -788,6 +839,13 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
788
839
|
reds.push(`declaration: Line ${n}'s check needs cells, but ${reading}. Line ${n} must read ${want}.`);
|
|
789
840
|
}
|
|
790
841
|
|
|
842
|
+
// M10b piece 5 (item 8): the old cell cite retires for CSV. A green step that reads a spreadsheet answers in bareguard's claim boxes (`close.sheet`);
|
|
843
|
+
// one with neither `close.sheet` nor `close.cited` would be the old cite close, which a new plan no longer offers. Signed flows keep running (fitJobLine only).
|
|
844
|
+
if (fitJobLine === true && effectiveClass === 'green' && reads !== null && reads.some((r) => cellsRoles.includes(r))
|
|
845
|
+
&& !isPlainObject(step.close?.cited) && !Array.isArray(step.close?.sheet)) {
|
|
846
|
+
reds.push(`declaration: Line ${fromLine}'s check cannot cite cells any more. Line ${fromLine} must carry close.sheet: bareguard's checks of ${reads.filter((r) => cellsRoles.includes(r)).join(' or ')}.`);
|
|
847
|
+
}
|
|
848
|
+
|
|
791
849
|
// M4d amendment 9: an ask step shows you something: its FIRST read must be the output of an earlier step. A read is not a
|
|
792
850
|
// grant (the ask stays a pure stop); the check is for the plan checker only (fitJobLine), so signed flows still run.
|
|
793
851
|
if (fitJobLine === true && reads !== null && fromLine !== null && askLines.includes(fromLine)
|
package/src/drafter.js
CHANGED
|
@@ -32,7 +32,9 @@ import { askableFromLook, tooManyAsksText, MAX_LOOK_ASKS } from './pageask.js';
|
|
|
32
32
|
import { lineRules } from './pagebits.js';
|
|
33
33
|
import path from 'node:path';
|
|
34
34
|
import { isCellsPath } from './closers.js';
|
|
35
|
-
import { parseCsv } from './csv.js';
|
|
35
|
+
import { parseCsv, sheetTable } from './csv.js';
|
|
36
|
+
import { sheetChecksProp, sheetOfferRules } from './sheetoffer.js';
|
|
37
|
+
import { uncoveredRules } from './sheetblock.js';
|
|
36
38
|
import {
|
|
37
39
|
makeProvider, ModelRefusal, sumMeterings, ceilingCostUsd, priceRecord,
|
|
38
40
|
} from './provider.js';
|
|
@@ -56,12 +58,12 @@ const docRolesOf = (sources) => (sources ?? []).filter((s) => s.kind === 'file'
|
|
|
56
58
|
/** the document inputs a quote can come from (M10 piece 5, item 2) */
|
|
57
59
|
const DOC_EXTS = Object.freeze(['.docx', '.md', '.txt']);
|
|
58
60
|
|
|
59
|
-
/** M10 am8 item 2: the column lock of a green step that
|
|
61
|
+
/** M10 am8 item 2: the column lock of a green step that reads a CSV input (`close.columns`): the exact header(s) its values come from. */
|
|
60
62
|
const COLUMNS_PROP = Object.freeze({
|
|
61
63
|
type: 'array',
|
|
62
64
|
minItems: 1,
|
|
63
65
|
maxItems: 10,
|
|
64
|
-
description: "only on a green step that
|
|
66
|
+
description: "only on a green step that reads a CSV input: the exact column names (the sheet's header) its values come from. Omit on any other step",
|
|
65
67
|
items: {
|
|
66
68
|
type: 'object',
|
|
67
69
|
properties: {
|
|
@@ -124,8 +126,13 @@ const SHAPE_PROPS = Object.freeze({
|
|
|
124
126
|
mustCarry: { type: 'array', minItems: 1, items: { type: 'string', minLength: 1 }, description: 'named fields every line must carry' },
|
|
125
127
|
});
|
|
126
128
|
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The forced tool's parameter schema. `menu` = wiredMenu(). `sheets` (M10b piece 3, optional) = the drafting copy's table of each CSV input role: with it a step may carry
|
|
131
|
+
* `close.sheet`, and every column a check names is an enum of that sheet's exact header (src/sheetoffer.js); without it (no CSV input) no sheet property exists.
|
|
132
|
+
* @param {any[]} menu @param {{sheets?: Record<string, {header: string[]}>}} [o]
|
|
133
|
+
*/
|
|
134
|
+
export function buildDeclarationSchema(menu, { sheets } = {}) {
|
|
135
|
+
const sheetProp = sheets ? sheetChecksProp(sheets) : null;
|
|
129
136
|
const shapeProps = {};
|
|
130
137
|
for (const key of SHAPE_KEYS) {
|
|
131
138
|
if (!SHAPE_PROPS[key]) throw new Error(`schema: SHAPE_KEYS gained "${key}" — add its type to SHAPE_PROPS`);
|
|
@@ -165,6 +172,7 @@ export function buildDeclarationSchema(menu) {
|
|
|
165
172
|
},
|
|
166
173
|
cited: CITED_PROP,
|
|
167
174
|
columns: COLUMNS_PROP,
|
|
175
|
+
...(sheetProp ? { sheet: sheetProp } : {}),
|
|
168
176
|
},
|
|
169
177
|
required: ['class'],
|
|
170
178
|
additionalProperties: false,
|
|
@@ -208,7 +216,7 @@ export const MAX_QUESTIONS = 2;
|
|
|
208
216
|
|
|
209
217
|
/** What fwdloop's typed checks can really check (bareloop F174: give the model the real list, or "Not checked" is invented). */
|
|
210
218
|
export const CHECKABLE = Object.freeze([
|
|
211
|
-
'green: a figure
|
|
219
|
+
'green: a sheet figure is recomputed by bareguard from the saved sheet',
|
|
212
220
|
'softgreen: the output carries named section headings (sections), in order',
|
|
213
221
|
`softgreen: a word ceiling for the whole output (maxWords; ${WHOLE_OUTPUT_CEILING_RULE}) and per section (wordsPerSection)`,
|
|
214
222
|
'softgreen: a line count per invoice (linesPerInvoice) and fields every line must carry (mustCarry)',
|
|
@@ -231,8 +239,9 @@ export const QUESTIONS_PROMPT = [
|
|
|
231
239
|
].join('\n');
|
|
232
240
|
|
|
233
241
|
/** The declaration schema plus the optional `notChecked` (every try) and, on try 3 only, `questions`. Neither is in `required`. */
|
|
234
|
-
|
|
235
|
-
|
|
242
|
+
/** @param {any[]} menu @param {{questions?: boolean, sheets?: Record<string, {header: string[]}>|undefined}} [o] */
|
|
243
|
+
export function buildRoundSchema(menu, { questions = false, sheets = undefined } = {}) {
|
|
244
|
+
const s = buildDeclarationSchema(menu, { sheets });
|
|
236
245
|
const extra = { notChecked: { type: 'array', items: { type: 'string' }, description: 'what the job asks for that no typed check verifies' } };
|
|
237
246
|
if (questions) {
|
|
238
247
|
extra.questions = {
|
|
@@ -305,10 +314,11 @@ function greenReadRule(sources) {
|
|
|
305
314
|
const pageRoles = (sources ?? []).filter((s) => s.kind === 'page').map((s) => s.role);
|
|
306
315
|
// M10 piece 5 (item 2): a quote in a doc - a .docx / .md / .txt input is quoted the way a page is
|
|
307
316
|
const docRoles = docRolesOf(sources);
|
|
308
|
-
const rule = '- A step whose line has a "green" guardrail must list the CSV input\'s role in its reads (for example reads: ["aging"]), because only an input with cells can be
|
|
317
|
+
const rule = '- A step whose line has a "green" guardrail must list the CSV input\'s role in its reads (for example reads: ["aging"]), because only an input with cells can be checked against its sheet; a text output of an earlier step has no cells. A green step that reads only other steps is refused.';
|
|
309
318
|
const out = [csvRoles.length
|
|
310
|
-
? `${rule} CSV inputs in this job: ${csvRoles.join(', ')}. close.columns = [{source, column}] names the exact column(s) of the CSV header that the step's
|
|
311
|
-
: `${rule} This job signs no CSV input, so a guardrail that needs
|
|
319
|
+
? `${rule} CSV inputs in this job: ${csvRoles.join(', ')}. close.columns = [{source, column}] names the exact column(s) of the CSV header that the step's values come from. Where the Inputs list says a line "is column 'X'", that line's step must name that column. A step that has close.sheet is not held to close.columns by a word that merely matches a header (such as a bucket name); but when a line carries a rule "use the column 'X' for ...", at least one of that line's close.sheet checks must use that column. Leave close.columns out when the line names no column.`
|
|
320
|
+
: `${rule} This job signs no CSV input, so a guardrail that needs a sheet check cannot be classed green here: class it "hitl"${pageRoles.length ? ' (unless it is about a web page, below)' : ''}.`];
|
|
321
|
+
if (csvRoles.length) out.push(...sheetOfferRules(csvRoles)); // M10b piece 3: close.sheet and every rule the validator enforces on it
|
|
312
322
|
if (pageRoles.length || docRoles.length) {
|
|
313
323
|
out.push(
|
|
314
324
|
`- ${[pageRoles.length ? `Web page inputs in this job: ${pageRoles.join(', ')}.` : '', docRoles.length ? `Document inputs in this job: ${docRoles.join(', ')}.` : ''].filter(Boolean).join(' ')} A step whose line asks for things found in one of them, and whose guardrail is about them, is "green" and checks quotes: it lists that input's role in its reads and carries close.cited = {source, facts, count}. close.cited is for a green step only.`,
|
|
@@ -339,6 +349,14 @@ function whenToUse(menu) {
|
|
|
339
349
|
return Object.entries(WHEN_TO_USE).filter(([verb]) => on.has(verb)).map(([, line]) => line);
|
|
340
350
|
}
|
|
341
351
|
|
|
352
|
+
/** M10b piece 3: with a CSV input, the guardrail rules of each line by number (the numbers `covers` names), in the order the validator counts them. Otherwise nothing. */
|
|
353
|
+
function sheetRuleNumbers(lines, arbiter) {
|
|
354
|
+
const csvRoles = (arbiter.sources ?? []).filter((s) => s.kind === 'file' && isCellsPath(s.path));
|
|
355
|
+
if (csvRoles.length === 0) return [];
|
|
356
|
+
const rows = lines.map((l) => ({ n: l.n, rules: lineRules(l.guardrail ? { rule: l.guardrail } : {}) })).filter((x) => x.rules.length > 0);
|
|
357
|
+
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(' ')}`)];
|
|
358
|
+
}
|
|
359
|
+
|
|
342
360
|
export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }) {
|
|
343
361
|
const askLines = arbiter.asks.map((a) => a.line);
|
|
344
362
|
const sendLines = arbiter.sends.map((s) => s.line);
|
|
@@ -352,7 +370,7 @@ export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }) {
|
|
|
352
370
|
'Rules:',
|
|
353
371
|
'- Steps share one artifact space. Each step: primitives (verbs it needs, [] if none), reads (artifact ids emitted by an EARLIER step, or the role of a CSV input listed under Inputs), emits (ONE new unique artifact id), fromLine (the ONE job line it serves), close. The machine fills each step\'s goal with that signed line, verbatim — you never write a goal.',
|
|
354
372
|
'- Every numbered job line must be served by a step (fromLine = that line) or listed in "refused" with a reason.',
|
|
355
|
-
'- guardrailClasses: for each job line that HAS a guardrail, classify its wording once: "green" (every figure must
|
|
373
|
+
'- guardrailClasses: for each job line that HAS a guardrail, classify its wording once: "green" (every figure must be checkable against its source: a sheet figure by the bareguard checks of the sheet), "softgreen" (the human declared a SHAPE the output must take), "hitl" (an ask/accept/review gate, or anything you are not sure of). When unsure, "hitl".',
|
|
356
374
|
'- close.class MUST equal the class of the guardrail on that step\'s fromLine (guardrailClasses[fromLine]); a line with no guardrail is "hitl". A step cannot claim a class its own line does not earn.',
|
|
357
375
|
...greenReadRule(arbiter.sources),
|
|
358
376
|
'- close.shape only on a softgreen step; it is the human\'s declared shape in structured form.',
|
|
@@ -368,6 +386,7 @@ export function buildSystemPrompt({ menu, lines, arbiter, factsInfo }) {
|
|
|
368
386
|
'',
|
|
369
387
|
'The numbered job lines:',
|
|
370
388
|
jobLinesText(lines, arbiter.asks),
|
|
389
|
+
...sheetRuleNumbers(lines, arbiter),
|
|
371
390
|
].join('\n');
|
|
372
391
|
}
|
|
373
392
|
|
|
@@ -638,6 +657,8 @@ export async function draft({
|
|
|
638
657
|
const factsInfo = pageInfo.length ? [...facts.info.filter((l) => !pageSources.some((s) => l.startsWith(`- ${s.role}: a web page`))), ...pageInfo] : facts.info;
|
|
639
658
|
|
|
640
659
|
// `notChecked` is offered on every try (information, not asking); `questions` only on try 3 (below).
|
|
660
|
+
// M10b piece 3: the drafting copy's table of each CSV input - the header the drafter may pick from, the table bareguard's sign-time test runs over
|
|
661
|
+
const sheetTables = Object.keys(facts.sheets ?? {}).length ? Object.fromEntries(Object.entries(facts.sheets).map(([role, t]) => [role, sheetTable(parseCsv(t))])) : undefined;
|
|
641
662
|
const baseSystem = buildSystemPrompt({ menu, lines, arbiter, factsInfo });
|
|
642
663
|
const system = `${baseSystem}\n\n${NOTCHECKED_PROMPT}`;
|
|
643
664
|
let structureRetries = 0;
|
|
@@ -664,7 +685,7 @@ export async function draft({
|
|
|
664
685
|
// Amendment 25: a lock is a mechanism. Only try 3 of 3, and only when tries 1 and 2 BOTH failed validation (`revisions` counts the
|
|
665
686
|
// validator's refusals fed back), gets the `questions` property; the redraft after an answer passes offerQuestions:false and never does.
|
|
666
687
|
const askOpen = offerQuestions && revisions === MAX_REVISIONS;
|
|
667
|
-
const schema = buildRoundSchema(menu, { questions: askOpen });
|
|
688
|
+
const schema = buildRoundSchema(menu, { questions: askOpen, sheets: sheetTables });
|
|
668
689
|
const tool = {
|
|
669
690
|
name: TOOL,
|
|
670
691
|
description: 'Emit the flow declaration over the granted primitives, or refuse lines you cannot serve.',
|
|
@@ -754,15 +775,16 @@ export async function draft({
|
|
|
754
775
|
return { ...st, close: { ...st.close, shape: per === null ? shape : { ...shape, wordsPerSection: per } } };
|
|
755
776
|
});
|
|
756
777
|
}
|
|
778
|
+
// 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
|
|
757
779
|
const verdict = validateDeclaration(declaration, {
|
|
758
780
|
arbiter, lines, catalogue: validationCatalogue, wired: WIRED_VERBS, verbatimGoals: true, fitJobLine: true,
|
|
759
781
|
// M10 am7 item 1: the words of every cited fact are proved on the drafting copy of the page, against what the page-word map kept
|
|
760
|
-
sheetWords:
|
|
782
|
+
sheetWords: sheetTables ? { headers: Object.fromEntries(Object.entries(sheetTables).map(([role, t]) => [role, t.header])), facts: sheetFacts.filter((f) => f.shape === 'column'), tables: sheetTables } : undefined,
|
|
761
783
|
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) },
|
|
762
784
|
});
|
|
763
785
|
lastDecl = declaration;
|
|
764
786
|
const asked = askOpen ? normalizeQuestions(rawQuestions, failedLines) : { kept: [], dropped: [] };
|
|
765
|
-
extras = { questions: asked.kept, droppedQuestions: asked.dropped, notChecked: [...pageNotChecked, ...cleanNotChecked(rawNotChecked)
|
|
787
|
+
extras = { questions: asked.kept, droppedQuestions: asked.dropped, notChecked: [...new Set([...pageNotChecked, ...cleanNotChecked(rawNotChecked), ...uncoveredRules(declaration, jobLines, Object.keys(facts.sheets ?? {}))])] };
|
|
766
788
|
if (asked.dropped.length) entry.droppedQuestions = asked.dropped;
|
|
767
789
|
if (verdict.ok) {
|
|
768
790
|
entry.outcome = 'valid';
|
package/src/model-step.js
CHANGED
|
@@ -31,7 +31,7 @@ import { appendCall, appendTool, nextRound } from './diary.js';
|
|
|
31
31
|
import { ConfigError } from './config.js';
|
|
32
32
|
import { worstThinkingStatus } from './thinking.js';
|
|
33
33
|
import { citedBrief } from './citedcheck.js';
|
|
34
|
-
import {
|
|
34
|
+
import { sheetAnswerProps, sheetBrief } from './sheetclaims.js';
|
|
35
35
|
|
|
36
36
|
import {
|
|
37
37
|
makeProvider, ModelRefusal, sumMeterings, appendSpendRow, classifyModelId, priceRecord,
|
|
@@ -93,22 +93,6 @@ const DONE_PROPS = Object.freeze({
|
|
|
93
93
|
},
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
const GREEN_SCHEMA = Object.freeze({
|
|
97
|
-
type: 'object',
|
|
98
|
-
properties: {
|
|
99
|
-
fields: {
|
|
100
|
-
type: 'object',
|
|
101
|
-
additionalProperties: {
|
|
102
|
-
type: 'object',
|
|
103
|
-
properties: { value: {}, cite: { type: 'string', description: `Where the value comes from: ${citeForms()}.` } },
|
|
104
|
-
required: ['value', 'cite'],
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
...DONE_PROPS,
|
|
108
|
-
},
|
|
109
|
-
required: ['fields', 'done'],
|
|
110
|
-
});
|
|
111
|
-
|
|
112
96
|
const SOFTGREEN_SCHEMA = Object.freeze({
|
|
113
97
|
type: 'object',
|
|
114
98
|
properties: {
|
|
@@ -159,9 +143,15 @@ const CITED_SCHEMA = Object.freeze({
|
|
|
159
143
|
* only (plus, for a green step that quotes a saved page, the form of its answer).
|
|
160
144
|
* `stepClass` is `'green' | 'softgreen' | 'hitl' | null | undefined`; `cited` is true for that green step.
|
|
161
145
|
*/
|
|
162
|
-
|
|
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) {
|
|
148
|
+
if (stepClass === 'green' && Array.isArray(sheet)) {
|
|
149
|
+
// M10b piece 2: a step that reads a sheet answers in one typed box per claim (bareguard's shapes), never a cite
|
|
150
|
+
const { properties, required } = sheetAnswerProps(sheet);
|
|
151
|
+
return { type: 'object', properties: { ...properties, ...DONE_PROPS }, required: [...required, 'done'], additionalProperties: false };
|
|
152
|
+
}
|
|
163
153
|
if (stepClass === 'green' && cited) return CITED_SCHEMA;
|
|
164
|
-
if (stepClass === 'green')
|
|
154
|
+
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');
|
|
165
155
|
if (stepClass === 'softgreen') return SOFTGREEN_SCHEMA;
|
|
166
156
|
return HITL_SCHEMA;
|
|
167
157
|
}
|
|
@@ -311,7 +301,7 @@ function stoppedResult(cumulative, modelId, modelMatch) {
|
|
|
311
301
|
* @param {{in:number,out:number}} [opts.rates]
|
|
312
302
|
* @param {string} [opts.modelId]
|
|
313
303
|
* @param {Record<string,string|undefined>} [opts.env] - the merged shell+keys-file env the key is read from (default process.env).
|
|
314
|
-
* @returns {(executorContext:object, grantedTools:Record<string,any>, stepMeta?:{class?:string, attempt?:number, step?:string|null, cited?:any, thinkingMode?:'on'|'off'}, seam?:{stopRequested?:() => boolean}) => Promise<any>}
|
|
304
|
+
* @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>}
|
|
315
305
|
*/
|
|
316
306
|
export function makeLiveModelStep({
|
|
317
307
|
slot, model, spendPath, provider: injectedProvider, rates: injectedRates, modelId: injectedModelId, env,
|
|
@@ -352,7 +342,7 @@ export function makeLiveModelStep({
|
|
|
352
342
|
const runDir = dirname(spendPath);
|
|
353
343
|
const diaryStep = stepMeta.step ?? null;
|
|
354
344
|
const diaryTry = typeof stepMeta.attempt === 'number' ? stepMeta.attempt : null;
|
|
355
|
-
const toolSchema = buildEmitArtifactSchema(stepMeta.class, stepMeta.class === 'green' && Boolean(stepMeta.cited));
|
|
345
|
+
const toolSchema = buildEmitArtifactSchema(stepMeta.class, stepMeta.class === 'green' && Boolean(stepMeta.cited), stepMeta.class === 'green' && Array.isArray(stepMeta.sheet) ? stepMeta.sheet : null);
|
|
356
346
|
const thinkingMode = stepMeta.thinkingMode === 'on' || stepMeta.thinkingMode === 'off' ? stepMeta.thinkingMode : null;
|
|
357
347
|
const systemPrompt = 'You are executing one step of a signed, human-authored automation. '
|
|
358
348
|
+ 'Call emit_artifact exactly once with this step\'s result. Ground every value in the '
|
|
@@ -363,6 +353,8 @@ export function makeLiveModelStep({
|
|
|
363
353
|
gap: executorContext.gap,
|
|
364
354
|
// M10 am7 item 3: a step that quotes a saved page is told the form of its answer and what each result must hold
|
|
365
355
|
...(stepMeta.class === 'green' && stepMeta.cited ? { quoting: citedBrief(stepMeta.cited) } : {}),
|
|
356
|
+
// M10b piece 2: a step that reads a sheet is told the shape of each claim box (bareguard's worked example), never the check
|
|
357
|
+
...(stepMeta.class === 'green' && Array.isArray(stepMeta.sheet) ? { answering: sheetBrief(stepMeta.sheet) } : {}),
|
|
366
358
|
});
|
|
367
359
|
const messages = [
|
|
368
360
|
{ role: 'system', content: systemPrompt },
|
package/src/panel/author.js
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
appendAnswersToJob, capFloorFor, capFloorOf, capFloorUsd, cardFields, checkCard, checkInputRows, parseInputLines, parseJobBox,
|
|
50
50
|
} from './authorcard.js';
|
|
51
51
|
import { checkedLines, notCheckedView } from '../checked.js';
|
|
52
|
+
import { csvRolesOf } from '../sheetblock.js';
|
|
52
53
|
import {
|
|
53
54
|
readPriceConfig, resolveSlot, resolveUsableModel, tickedLines,
|
|
54
55
|
} from '../provider.js';
|
|
@@ -296,7 +297,7 @@ export function createAuthor(opts) {
|
|
|
296
297
|
const decl = readJson(dir, `${rel}/declaration.json`);
|
|
297
298
|
const prose = readFileInside(dir, `${rel}/prose.txt`);
|
|
298
299
|
const parsed = prose.ok ? parseSignedText(prose.text) : null;
|
|
299
|
-
const opts = parsed?.ok === true ? { askLines: parsed.arbiter.asks.map((x) => x.line) } : { hasAsk: true };
|
|
300
|
+
const opts = parsed?.ok === true ? { askLines: parsed.arbiter.asks.map((x) => x.line), lines: parsed.lines, csvRoles: csvRolesOf(parsed.arbiter) } : { hasAsk: true };
|
|
300
301
|
return { checked: checkedLines(decl, opts), notChecked: notCheckedView(readJson(dir, `${rel}/${NOT_CHECKED_FILE}`)?.notChecked, decl) };
|
|
301
302
|
}
|
|
302
303
|
|
package/src/panel/authorcard.js
CHANGED
|
@@ -88,7 +88,8 @@ export function parseJobBox(text) {
|
|
|
88
88
|
* M4e amendment 24 item 3: the submitted job box with each answer added WORD FOR WORD as a `~` line under the job line it is about, after
|
|
89
89
|
* that line's own `~` lines (several answers for one line keep their order). The job box's own lines are untouched; the card -> prose path
|
|
90
90
|
* (`cardToProse`) then writes the answer as that line's guardrail, so it reaches the signed text and the hash. Pure. An answer for a line
|
|
91
|
-
* the box does not have is NOT added (the caller sees the count).
|
|
91
|
+
* the box does not have is NOT added (the caller sees the count). An answer equal (exact string, after trim) to a `~` rule already on that line is not added
|
|
92
|
+
* again, and still counts: it is taken, the line already says it.
|
|
92
93
|
* @param {string} job @param {{ line: number, answer: string }[]} answers
|
|
93
94
|
* @returns {{ job: string, added: number }}
|
|
94
95
|
*/
|
|
@@ -96,12 +97,15 @@ export function appendAnswersToJob(job, answers) {
|
|
|
96
97
|
const raw = String(job).split('\n');
|
|
97
98
|
/** @type {Map<number, number>} the index of the last non-empty box line that belongs to each step (its own line or a `~` under it) */
|
|
98
99
|
const lastOf = new Map();
|
|
100
|
+
/** @type {Map<number, Set<string>>} the `~` rules each step already has */
|
|
101
|
+
const have = new Map();
|
|
99
102
|
let step = 0;
|
|
100
103
|
raw.forEach((l, i) => {
|
|
101
104
|
const t = l.trim();
|
|
102
105
|
if (t === '') return;
|
|
103
106
|
if (!t.startsWith('~')) step += 1;
|
|
104
107
|
if (step > 0) lastOf.set(step, i);
|
|
108
|
+
if (step > 0 && t.startsWith('~')) have.set(step, (have.get(step) ?? new Set()).add(t.slice(1).trim()));
|
|
105
109
|
});
|
|
106
110
|
/** @type {Map<number, string[]>} */
|
|
107
111
|
const after = new Map();
|
|
@@ -109,8 +113,11 @@ export function appendAnswersToJob(job, answers) {
|
|
|
109
113
|
for (const a of answers) {
|
|
110
114
|
if (!lastOf.has(a.line)) continue;
|
|
111
115
|
const at = /** @type {number} */ (lastOf.get(a.line));
|
|
112
|
-
after.set(at, [...(after.get(at) ?? []), `~ ${a.answer}`]);
|
|
113
116
|
added += 1;
|
|
117
|
+
const rules = have.get(a.line) ?? new Set();
|
|
118
|
+
if (rules.has(a.answer.trim())) continue;
|
|
119
|
+
have.set(a.line, rules.add(a.answer.trim()));
|
|
120
|
+
after.set(at, [...(after.get(at) ?? []), `~ ${a.answer}`]);
|
|
114
121
|
}
|
|
115
122
|
const out = [];
|
|
116
123
|
raw.forEach((l, i) => { out.push(l); for (const g of after.get(i) ?? []) out.push(g); });
|
package/src/panel/data.js
CHANGED
|
@@ -39,6 +39,8 @@ import { readSpendRows } from '../provider.js';
|
|
|
39
39
|
import { applyRunValues, parseWaitMs, pickRunValues, VALUES_FILE_RE } from '../runvalues.js';
|
|
40
40
|
import { readSetup } from '../setup.js';
|
|
41
41
|
import { checkedLines, notCheckedView, NOT_CHECKED_LABEL } from '../checked.js';
|
|
42
|
+
import { csvRolesOf, askSheetCard } from '../sheetblock.js';
|
|
43
|
+
import { readSheetChecks } from '../sheet-record.js';
|
|
42
44
|
import {
|
|
43
45
|
NO_COPY_SAY, catchUpWords, endedLineWords, endedWords, needsLeftWords, nextInWords, nextTimeWords, scheduleAuditWords, scheduleBlockWords, scheduleFieldWords, scheduledNextFor, scheduledWords, startedWords,
|
|
44
46
|
} from '../summary-words.js';
|
|
@@ -2024,8 +2026,8 @@ export function getRunAudit({
|
|
|
2024
2026
|
* M6: a sign row that names another signing than the job being shown (`flowHash`) is not this job's record: `recorded:false`, never the new job's words.
|
|
2025
2027
|
* @param {any} declaration @param {Array<{line:number, ttlMs?:number}>} asks @param {string} flowDir @param {string|null} [flowHash] the signature hash of the job being shown
|
|
2026
2028
|
*/
|
|
2027
|
-
function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
|
|
2028
|
-
const lines = checkedLines(declaration, { askLines: asks.map((x) => x.line) });
|
|
2029
|
+
function buildJobPlan(declaration, asks, flowDir, flowHash = null, jobLines = /** @type {any[]|undefined} */ (undefined), csvRoles = /** @type {string[]} */ ([])) {
|
|
2030
|
+
const lines = checkedLines(declaration, { askLines: asks.map((x) => x.line), lines: jobLines, csvRoles });
|
|
2029
2031
|
const declSteps = Array.isArray(declaration?.steps) ? declaration.steps : [];
|
|
2030
2032
|
const steps = declSteps.map((st, i) => {
|
|
2031
2033
|
const ak = asks.find((x) => x.line === st.fromLine);
|
|
@@ -2037,6 +2039,7 @@ function buildJobPlan(declaration, asks, flowDir, flowHash = null) {
|
|
|
2037
2039
|
mayDo: Array.isArray(st.primitives) ? st.primitives : [],
|
|
2038
2040
|
check: lines[i].sentences,
|
|
2039
2041
|
checkClass: lines[i].class,
|
|
2042
|
+
sheet: lines[i].sheet ?? null,
|
|
2040
2043
|
ask: !!ak,
|
|
2041
2044
|
waitMs: ak && typeof ak.ttlMs === 'number' ? ak.ttlMs : null,
|
|
2042
2045
|
};
|
|
@@ -2146,7 +2149,7 @@ export function getRunJob({
|
|
|
2146
2149
|
guardrails: flowRead.lines
|
|
2147
2150
|
.filter((l) => typeof l.guardrail === 'string' && l.guardrail.length > 0)
|
|
2148
2151
|
.map((l) => ({ line: l.n, guardrail: l.guardrail })),
|
|
2149
|
-
plan: buildJobPlan(flowRead.declaration, asks, run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null),
|
|
2152
|
+
plan: buildJobPlan(flowRead.declaration, asks, run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null, flowRead.lines, csvRolesOf(a)),
|
|
2150
2153
|
signature: (sig && typeof sig.signedBy === 'string' && typeof sig.signedAt === 'string' && typeof sig.flow === 'string')
|
|
2151
2154
|
? { signedBy: sig.signedBy, signedAt: sig.signedAt, hash: sig.flow }
|
|
2152
2155
|
: null,
|
|
@@ -2199,7 +2202,7 @@ export function getRunResult({
|
|
|
2199
2202
|
if (!got) return null;
|
|
2200
2203
|
const { run, ctx } = got;
|
|
2201
2204
|
const sig = ctx.flowRead.signature;
|
|
2202
|
-
const plan = buildJobPlan(ctx.flowRead.declaration, ctx.arbiter.asks ?? [], run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null);
|
|
2205
|
+
const plan = buildJobPlan(ctx.flowRead.declaration, ctx.arbiter.asks ?? [], run.flowDir, typeof sig?.flow === 'string' ? sig.flow : null, ctx.flowRead.lines, csvRolesOf(ctx.arbiter));
|
|
2203
2206
|
return buildResult({
|
|
2204
2207
|
flow, runId, runDir: run.runDir, root, flowRead: ctx.flowRead, arbiter: ctx.arbiter, historyRow: ctx.historyRow, auditRows: ctx.auditRows, logJson: ctx.logJson, notChecked: plan.notChecked.items, readNotes: plan.notChecked.readNotes,
|
|
2205
2208
|
setupRows: (() => { const st = readSetup(run.flowDir); return st.present ? st.rows : []; })(),
|
|
@@ -2337,6 +2340,7 @@ function flattenEvidence(evidence) {
|
|
|
2337
2340
|
draft: evidence.draft ? evidence.draft.text : null,
|
|
2338
2341
|
unjudged: evidence.unjudged,
|
|
2339
2342
|
why: evidence.why,
|
|
2343
|
+
...(evidence.claims ? { claims: evidence.claims } : {}),
|
|
2340
2344
|
};
|
|
2341
2345
|
}
|
|
2342
2346
|
|
|
@@ -2686,7 +2690,18 @@ export function getRunAsks({
|
|
|
2686
2690
|
}
|
|
2687
2691
|
}
|
|
2688
2692
|
const openAskJson = hasHistoryRow ? null : readAsk(run.runDir);
|
|
2689
|
-
|
|
2693
|
+
// M10b am4: an ask whose evidence is a sheet step's claim boxes carries that step's block and answer (the Result tab's block), and loses the "unrecognised shape" line
|
|
2694
|
+
const sheetRecord = ordered.some((a) => a.evidence?.claims) ? readSheetChecks(run.runDir) : null;
|
|
2695
|
+
const sheetArbiter = flowRead.ok ? flowRead.arbiter : null;
|
|
2696
|
+
const withSheet = (/** @type {any} */ ask) => {
|
|
2697
|
+
const { claims, ...ev } = ask.evidence ?? {};
|
|
2698
|
+
if (!claims) return ask;
|
|
2699
|
+
const card = flowRead.ok ? askSheetCard({ claims, declaration: flowRead.declaration, lines: flowRead.lines, csvRoles: csvRolesOf(sheetArbiter), record: sheetRecord }) : null;
|
|
2700
|
+
if (card === null) return { ...ask, evidence: ev };
|
|
2701
|
+
const { why: _gone, ...rest } = ev;
|
|
2702
|
+
return { ...ask, evidence: { ...rest, sheet: card } };
|
|
2703
|
+
};
|
|
2704
|
+
const asks = ordered.map(withSheet).map((ask, i) => ({
|
|
2690
2705
|
...ask,
|
|
2691
2706
|
...deriveAskOpenFields(ask, hasHistoryRow, resume),
|
|
2692
2707
|
reopen: reopenOffer(ask, openAskJson, resume, readSavedAnswer(run.runDir)?.askId === ask.askId),
|
package/src/panel/index.html
CHANGED
|
@@ -2413,6 +2413,37 @@
|
|
|
2413
2413
|
var note = file && file.judged && file.note ? '<div class="hint" data-testid="result-judged-note">' + escapeXml(file.note) + '</div>' : "";
|
|
2414
2414
|
return note + (file && file.judged && file.words ? '<div class="rs-warn" data-testid="result-file-words">' + escapeXml(file.words) + '</div>' : "");
|
|
2415
2415
|
}
|
|
2416
|
+
// M10b am2: what a job line that reads a sheet shows, drawn from the server's ONE block ({guardrails, checked: [{text, ...}], notChecked: [..] | "none"}): its
|
|
2417
|
+
// guardrails, "Checked:" with one line per sheet check (name, plain words, covers), then "Not checked:" with the guardrails no check covers, or "none".
|
|
2418
|
+
// Pure: the Chat plan card and the Job tab step rows both draw these strings; the server wrote every one of them.
|
|
2419
|
+
function sheetBlockLines(sheet){
|
|
2420
|
+
if(!sheet) return [];
|
|
2421
|
+
var out = [];
|
|
2422
|
+
if((sheet.guardrails || []).length){
|
|
2423
|
+
out.push("Guardrails:");
|
|
2424
|
+
sheet.guardrails.forEach(function(g){ out.push("- " + g); });
|
|
2425
|
+
}
|
|
2426
|
+
out.push("Checked:");
|
|
2427
|
+
(sheet.checked || []).forEach(function(c){ out.push("- " + c.text); });
|
|
2428
|
+
if(sheet.notChecked === "none" || !(sheet.notChecked || []).length) out.push("Not checked: none");
|
|
2429
|
+
else { out.push("Not checked:"); sheet.notChecked.forEach(function(g){ out.push("- " + g); }); }
|
|
2430
|
+
return out;
|
|
2431
|
+
}
|
|
2432
|
+
// the Result tab's drawing of the same block, after the run: each check carries \u2713 or \u2717 and what was found (the server's `found`), then its plain words and
|
|
2433
|
+
// covers; "Not checked" again. A check with no verdict (the run never reached it) draws with no mark. Every string is escaped.
|
|
2434
|
+
function resultSheetBlock(sheet){
|
|
2435
|
+
if(!sheet) return "";
|
|
2436
|
+
var rows = (sheet.checked || []).map(function(c){
|
|
2437
|
+
var mark = c.ok === true ? '<span class="rs-ok">\u2713</span> ' : (c.ok === false ? '<span class="rs-bad">\u2717</span> ' : "");
|
|
2438
|
+
var more = [c.words, c.coversWords].filter(function(x){ return x; }).join(" \u00b7 ");
|
|
2439
|
+
return '<div data-testid="result-sheet-check">' + mark + escapeXml(typeof c.found === "string" ? c.found : c.name) +
|
|
2440
|
+
(more ? ' <span class="hint">' + escapeXml(more) + '</span>' : "") + '</div>';
|
|
2441
|
+
}).join("");
|
|
2442
|
+
var nc = sheet.notChecked === "none" || !(sheet.notChecked || []).length ? "none" : null;
|
|
2443
|
+
return resultField("Checked", '<div class="ro-value" data-testid="result-sheet-checked">' + rows + '</div>') +
|
|
2444
|
+
resultField("Not checked", nc !== null ? '<div class="ro-value" data-testid="result-sheet-notchecked">none</div>' :
|
|
2445
|
+
'<div class="ro-value" data-testid="result-sheet-notchecked"><ul style="margin:0;padding-left:18px">' + sheet.notChecked.map(function(t){ return '<li>' + escapeXml(t) + '</li>'; }).join("") + '</ul></div>');
|
|
2446
|
+
}
|
|
2416
2447
|
function resultField(label, inner){
|
|
2417
2448
|
return '<div class="field"><label>' + escapeXml(label) + '</label>' + inner + '</div>';
|
|
2418
2449
|
}
|
|
@@ -2497,7 +2528,7 @@
|
|
|
2497
2528
|
function resultLineCard(line, own, note){
|
|
2498
2529
|
return '<div class="job-card" data-testid="result-line"><h4>Line ' + escapeXml(String(line.n)) + '</h4>' + resultLineBox(line) +
|
|
2499
2530
|
(own ? resultPageLink(line.page, note, "result-page-line") : "") +
|
|
2500
|
-
(line.kind === "facts" ? resultFactsLine(line) : resultTextLine(line)) + resultChecksList(line) +
|
|
2531
|
+
(line.kind === "facts" ? resultFactsLine(line) : resultTextLine(line)) + (line.sheet ? resultSheetBlock(line.sheet) : resultChecksList(line)) +
|
|
2501
2532
|
resultNotChecked("Not checked", line.notChecked, "result-line-notchecked") + '</div>';
|
|
2502
2533
|
}
|
|
2503
2534
|
function renderResult(){
|
|
@@ -3505,6 +3536,8 @@
|
|
|
3505
3536
|
// M10 am11: each check sentence is its own row
|
|
3506
3537
|
if(st.ask || !(st.check || []).length) fold.appendChild(textDiv("plan-row", "check: " + (st.ask ? "ASK · waits " + plainWait(st.waitMs) : "")));
|
|
3507
3538
|
else st.check.forEach(function(s){ fold.appendChild(textDiv("plan-row", "check: " + s)); });
|
|
3539
|
+
// M10b am2: a step that reads a sheet shows its line's block under the check sentence
|
|
3540
|
+
sheetBlockLines(st.sheet).forEach(function(t){ fold.appendChild(textDiv("plan-row", t)); });
|
|
3508
3541
|
return fold;
|
|
3509
3542
|
}
|
|
3510
3543
|
// The tail: any step that came from no listed line, then the folded Not-checked summary (its label comes from the payload, src/checked.js; always shown).
|
|
@@ -4392,6 +4425,13 @@
|
|
|
4392
4425
|
// style a footnote/why-text uses.
|
|
4393
4426
|
ev.appendChild(textDiv("evidence-heading", "draft " + ctx.draftNo));
|
|
4394
4427
|
ev.appendChild(draftEl);
|
|
4428
|
+
} else if(evidence.sheet){
|
|
4429
|
+
// M10b am4: a sheet step's ask shows the Result tab's own lines (resultSheetBlock) and the step's answer value by value, where the error line was
|
|
4430
|
+
var sheetBox = document.createElement("div");
|
|
4431
|
+
sheetBox.setAttribute("data-testid", "ask-sheet");
|
|
4432
|
+
sheetBox.innerHTML = resultSheetBlock(evidence.sheet.block) + resultField("Answer", '<div class="ro-value" data-testid="ask-sheet-answers">' +
|
|
4433
|
+
(evidence.sheet.answer || []).map(function(t){ return '<div data-testid="ask-sheet-answer">' + escapeXml(t) + '</div>'; }).join("") + '</div>');
|
|
4434
|
+
ev.appendChild(sheetBox);
|
|
4395
4435
|
} else {
|
|
4396
4436
|
ev.appendChild(textDiv("hint", evidence.why || "no draft on file"));
|
|
4397
4437
|
}
|
|
@@ -4922,6 +4962,8 @@
|
|
|
4922
4962
|
c.sentences.forEach(function(s, i){
|
|
4923
4963
|
checkedLines.push(i === 0 ? (c.line !== null && c.line !== undefined ? "line " + c.line : "step " + c.step) + ": " + s : " " + s);
|
|
4924
4964
|
});
|
|
4965
|
+
// M10b am2: a line that reads a sheet: its guardrails, Checked (name, words, covers), Not checked
|
|
4966
|
+
sheetBlockLines(c.sheet).forEach(function(t){ checkedLines.push(" " + t); });
|
|
4925
4967
|
});
|
|
4926
4968
|
blocks.push({id: "chat-checked", head: "Checked", sub: "built by the machine from the plan's checks", lines: checkedLines});
|
|
4927
4969
|
var nc = state.notChecked || {};
|
package/src/panel/result.js
CHANGED
|
@@ -20,6 +20,8 @@ import { isAgree, readingOfQuestion } from '../pageask.js';
|
|
|
20
20
|
import { lineRules } from '../pagebits.js';
|
|
21
21
|
import { CITED_CHECKS_FILE } from '../cited-record.js';
|
|
22
22
|
import { readChecks } from '../diary.js';
|
|
23
|
+
import { sheetLineBlocks, csvRolesOf } from '../sheetblock.js';
|
|
24
|
+
import { readSheetChecks } from '../sheet-record.js';
|
|
23
25
|
|
|
24
26
|
/** the two sentences for a saved file that is no longer what the run wrote (code-owned, one spelling) */
|
|
25
27
|
export const RESULT_FILE_GONE = 'the saved file is gone';
|
|
@@ -234,12 +236,16 @@ export function buildResult({
|
|
|
234
236
|
const urls = pageUrlsByRole(arbiter);
|
|
235
237
|
// am9: a page job's card is bareloop's (no checks list); every other job lists what each step checked
|
|
236
238
|
const diary = urls.size === 0 ? readChecks(runDir) : [];
|
|
239
|
+
// M10b am2: the block of every job line that reads a sheet (guardrails, Checked with ✓ / ✗ and what was found, Not checked), from the signed job and the run's
|
|
240
|
+
// sheet-checks.json; it is there with no rows found and when the result is written to a doc
|
|
241
|
+
const sheetBlocks = sheetLineBlocks({ declaration, lines: flowRead.lines, csvRoles: csvRolesOf(arbiter), record: readSheetChecks(runDir) });
|
|
237
242
|
const lines = flowRead.lines.filter((l) => !taken.has(l.n)).map((l) => {
|
|
238
243
|
const c = record.find((x) => x.n === l.n) ?? null;
|
|
239
244
|
const out = {
|
|
240
245
|
notChecked: c ? c.notChecked : [], n: l.n, text: l.text, rules: isStr(l.guardrail) && l.guardrail !== '' ? [l.guardrail] : [],
|
|
241
246
|
kind: c ? 'facts' : 'text', passed: c ? c.passed : false, file: null,
|
|
242
247
|
checks: checksOfLine((declaration?.steps ?? []).filter((st) => st.fromLine === l.n), diary),
|
|
248
|
+
sheet: sheetBlocks.find((b) => b.line === l.n) ?? null,
|
|
243
249
|
};
|
|
244
250
|
if (c) {
|
|
245
251
|
out.source = c.source;
|