fwdloop 0.38.0 → 0.40.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/README.md +6 -9
- package/bin/fwdloop +21 -19
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +6 -5
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +32 -60
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +15 -3
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +42 -16
- package/src/books.js +237 -12
- package/src/checkblock.js +24 -44
- package/src/checklistsign.js +25 -3
- package/src/checklook.js +3 -1
- package/src/checkpick.js +6 -77
- package/src/cited-source.js +4 -4
- package/src/citedcheck.js +6 -11
- package/src/citedwords.js +9 -8
- package/src/closers.js +9 -6
- package/src/declaration.js +14 -49
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +18 -12
- package/src/draftfiles.js +127 -0
- package/src/draftspend.js +165 -17
- package/src/flow.js +42 -87
- package/src/flowmodel.js +1 -1
- package/src/index.js +3 -2
- package/src/inside.js +106 -0
- package/src/jsonl-append.js +33 -1
- package/src/learn.js +1 -1
- package/src/learnstore.js +20 -22
- package/src/line-checks.js +1 -1
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/model-step.js +2 -2
- package/src/page-words.js +8 -0
- package/src/pageask.js +8 -3
- package/src/pagebits.js +8 -1
- package/src/pagedropwords.js +1 -1
- package/src/pagerules.js +6 -3
- package/src/panel/author.js +99 -75
- package/src/panel/authorcard.js +21 -8
- package/src/panel/authorflows.js +3 -3
- package/src/panel/authorresume.js +3 -3
- package/src/panel/authorstart.js +15 -16
- package/src/panel/authortrigger.js +43 -70
- package/src/panel/data.js +186 -188
- package/src/panel/index.html +139 -115
- package/src/panel/jobgrid.js +3 -7
- package/src/panel/result.js +7 -10
- package/src/panel/resume.js +4 -3
- package/src/panel/scheduler.js +9 -9
- package/src/panel/server.js +8 -4
- package/src/panel/spawn.js +22 -11
- package/src/panel/tickets.js +2 -2
- package/src/pickrecord.js +51 -31
- package/src/placerule.js +3 -4
- package/src/plain-checks.js +1 -1
- package/src/planrebuild.js +19 -19
- package/src/primitives.js +1 -1
- package/src/provider.js +1 -1
- package/src/reasons.js +25 -0
- package/src/runfile.js +26 -2
- package/src/runner.js +57 -105
- package/src/runvalues.js +47 -24
- package/src/schedule-choices.js +41 -0
- package/src/schedule-shape.js +39 -0
- package/src/schedule.js +9 -8
- package/src/setup.js +20 -36
- package/src/shaperows.js +2 -2
- package/src/sheetblock.js +2 -2
- package/src/sheetbuild.js +5 -5
- package/src/sheetrun.js +4 -5
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +7 -28
- package/src/trigger-clock.js +9 -23
- package/src/trigger-files.js +30 -22
- package/src/trigger-tickets.js +15 -14
- package/src/try-checks.js +2 -1
- package/src/types.js +2 -0
- package/types/ask.d.ts +25 -20
- package/types/authoring.d.ts +7 -42
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +380 -4
- package/types/checkblock.d.ts +1 -23
- package/types/checklist.d.ts +3 -3
- package/types/checklistsign.d.ts +7 -0
- package/types/checkpick.d.ts +0 -21
- package/types/citedwords.d.ts +7 -4
- package/types/closers.d.ts +1 -0
- package/types/declaration.d.ts +4 -14
- package/types/diary.d.ts +14 -1
- package/types/draft-steps.d.ts +7 -0
- package/types/drafter.d.ts +1 -1
- package/types/draftfiles.d.ts +89 -0
- package/types/draftspend.d.ts +74 -0
- package/types/flow.d.ts +32 -54
- package/types/index.d.ts +3 -3
- package/types/inside.d.ts +71 -0
- package/types/jsonl-append.d.ts +20 -0
- package/types/learnstore.d.ts +0 -2
- package/types/liveness.d.ts +1 -0
- package/types/page-words.d.ts +6 -0
- package/types/pageask.d.ts +2 -0
- package/types/pagebits.d.ts +3 -0
- package/types/pagerules.d.ts +1 -0
- package/types/panel/author.d.ts +7 -3
- package/types/panel/authorcard.d.ts +0 -6
- package/types/panel/authorflows.d.ts +4 -4
- package/types/panel/authortrigger.d.ts +16 -2
- package/types/panel/data.d.ts +50 -16
- package/types/panel/spawn.d.ts +18 -2
- package/types/pickrecord.d.ts +29 -0
- package/types/reasons.d.ts +23 -0
- package/types/runfile.d.ts +14 -0
- package/types/runner.d.ts +6 -38
- package/types/runvalues.d.ts +17 -2
- package/types/schedule-choices.d.ts +9 -0
- package/types/schedule-shape.d.ts +15 -0
- package/types/sheetbuild.d.ts +1 -1
- package/types/thinking.d.ts +1 -0
- package/types/ticketrows.d.ts +0 -9
- package/types/trigger-clock.d.ts +3 -2
- package/types/trigger-files.d.ts +15 -4
- package/types/types.d.ts +8 -0
package/src/books.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import { mkdirSync } from 'node:fs';
|
|
22
22
|
import { dirname, join } from 'node:path';
|
|
23
23
|
|
|
24
|
-
import { readFileInside, readdirInside } from './
|
|
24
|
+
import { readFileInside, readdirInside } from './inside.js';
|
|
25
25
|
import { appendRow } from './jsonl-append.js';
|
|
26
26
|
import { TRIGGER_RECORD_FILE } from './trigger-line.js';
|
|
27
27
|
|
|
@@ -30,6 +30,15 @@ function appendLine(filePath, row) {
|
|
|
30
30
|
appendRow(filePath, row);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* M20 am3 item 5: the ONE place the consumed-answer file name is spelled: `answer.<askId>.consumed.json`, what the resume
|
|
35
|
+
* renames `answer.json` to (F44). `askIdOfConsumedName` is its inverse (null for any other name, `answer.stale.<n>.json` included).
|
|
36
|
+
* @param {string} askId
|
|
37
|
+
*/
|
|
38
|
+
export const consumedAnswerName = (askId) => `answer.${askId}.consumed.json`;
|
|
39
|
+
/** @param {string} name @returns {string|null} */
|
|
40
|
+
export const askIdOfConsumedName = (name) => /^answer\.(.+)\.consumed\.json$/.exec(name)?.[1] ?? null;
|
|
41
|
+
|
|
33
42
|
/**
|
|
34
43
|
* M4c piece 1: the ONE writer of a run dir's `pids.jsonl` — append-only, never
|
|
35
44
|
* rewritten, not a book the arbiter reads. One row per process that works on
|
|
@@ -50,6 +59,39 @@ export function readPidRows(runDir) {
|
|
|
50
59
|
return readLines(runDir, 'pids.jsonl');
|
|
51
60
|
}
|
|
52
61
|
|
|
62
|
+
/**
|
|
63
|
+
* M20 am3b item 1: the ONE reader of a run's saved answer, `answer.json` (what `answerAsk` writes; the resume consumes it by renaming it away). Through the safe
|
|
64
|
+
* gateway (a symlink or a file outside the folder is refused). It parses nothing else's words: each caller keeps its own refusal sentence and reads these fields.
|
|
65
|
+
* `broken` = no JSON object, no `askId`, or no readable `answeredAt`: the file is not a usable answer for any ask. `value` is the parsed JSON as it is (any shape),
|
|
66
|
+
* `parseError` the parser's message when the text is not JSON, `isObject` says `value` is a plain JSON object. `decision` is the file's own word, not normalised.
|
|
67
|
+
* @param {string} runDir
|
|
68
|
+
* @returns {{ok: false, missing: boolean, red: string}
|
|
69
|
+
* | {ok: true, value: any, parseError: string|null, isObject: boolean, askId: string|null, decision: string|null, answeredAt: string|null, broken: boolean}}
|
|
70
|
+
*/
|
|
71
|
+
export function readSavedAnswer(runDir) {
|
|
72
|
+
const r = readFileInside(runDir, 'answer.json');
|
|
73
|
+
if (!r.ok) return r.missing ? { ok: false, missing: true, red: 'answer.json is missing' } : { ok: false, missing: false, red: r.red };
|
|
74
|
+
const text = r.text;
|
|
75
|
+
let value;
|
|
76
|
+
try { value = JSON.parse(text); } catch (err) {
|
|
77
|
+
return { ok: true, value: undefined, parseError: err.message, isObject: false, askId: null, decision: null, answeredAt: null, broken: true };
|
|
78
|
+
}
|
|
79
|
+
const isObject = value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
80
|
+
const askId = isObject && typeof value.askId === 'string' && value.askId.length > 0 ? value.askId : null;
|
|
81
|
+
const answeredAt = isObject && typeof value.answeredAt === 'string' ? value.answeredAt : null;
|
|
82
|
+
return {
|
|
83
|
+
ok: true, value, parseError: null, isObject, askId,
|
|
84
|
+
decision: isObject && typeof value.decision === 'string' ? value.decision : null,
|
|
85
|
+
answeredAt,
|
|
86
|
+
broken: !isObject || askId === null || Number.isNaN(Date.parse(answeredAt ?? '')),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Has a process started on this run? (the run wrote its first pid row; a run with none is still starting, or never started) @param {string} runDir */
|
|
91
|
+
export function processStarted(runDir) {
|
|
92
|
+
return readPidRows(runDir).length > 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
53
95
|
/**
|
|
54
96
|
* Raw read-back of one JSONL book, one writer's own sibling reader (M4a
|
|
55
97
|
* piece 2, docs/wiki/the-module-ladder.md M4a scope item 2: "one reader per
|
|
@@ -274,11 +316,33 @@ export function auditRowAt(row) {
|
|
|
274
316
|
* Read back every row `appendAudit` has written for one run, in file order
|
|
275
317
|
* (append order — never re-sorted). `[]` when the file doesn't exist yet
|
|
276
318
|
* (a run that hasn't made an attempt), never a thrown error.
|
|
319
|
+
* `{ strict: true }` is the one named mode for the money sum: `{ok:true, rows}` or `{ok:false, red}` on a torn line.
|
|
277
320
|
* @param {string} runDir
|
|
278
|
-
* @
|
|
321
|
+
* @param {{strict?: boolean}} [opts]
|
|
322
|
+
* @returns {any}
|
|
279
323
|
*/
|
|
280
|
-
export function readAudit(runDir) {
|
|
281
|
-
return readLines(runDir, 'audit.jsonl');
|
|
324
|
+
export function readAudit(runDir, { strict = false } = {}) {
|
|
325
|
+
if (!strict) return readLines(runDir, 'audit.jsonl');
|
|
326
|
+
// strict mode (M20 am3 item 11): the money sum must balance, so a torn line is a red, never skipped; a missing or refused file is no rows
|
|
327
|
+
const result = readFileInside(runDir, 'audit.jsonl');
|
|
328
|
+
if (!result.ok) return { ok: true, rows: [] };
|
|
329
|
+
const rows = [];
|
|
330
|
+
for (const line of result.text.split('\n')) {
|
|
331
|
+
if (line.trim().length === 0) continue;
|
|
332
|
+
try { rows.push(JSON.parse(line)); } catch (err) { return { ok: false, red: `audit.jsonl line is not valid JSON — ${err.message}` }; }
|
|
333
|
+
}
|
|
334
|
+
return { ok: true, rows };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The one reader of a run's `trigger.json` (why it started): an object, or `null` (a hand run, a missing, refused or unreadable file, a non-object).
|
|
339
|
+
* @param {string} runDir
|
|
340
|
+
* @returns {Record<string, any>|null}
|
|
341
|
+
*/
|
|
342
|
+
export function readTriggerRecord(runDir) {
|
|
343
|
+
const f = readFileInside(runDir, TRIGGER_RECORD_FILE);
|
|
344
|
+
if (!f.ok) return null;
|
|
345
|
+
try { const j = JSON.parse(f.text); return j && typeof j === 'object' ? j : null; } catch { return null; }
|
|
282
346
|
}
|
|
283
347
|
|
|
284
348
|
/**
|
|
@@ -291,10 +355,8 @@ export function readAudit(runDir) {
|
|
|
291
355
|
export function appendHistory(flowDir, row) {
|
|
292
356
|
checkCostField(row, 'spentUsd', 'appendHistory');
|
|
293
357
|
// M9 (am2 item 1): a run a trigger started says so in its history row, read from the record the start wrote into the run's own folder
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
if (rec !== null && rec.ok) { try { trigger = JSON.parse(rec.text); } catch { trigger = undefined; } }
|
|
297
|
-
appendLine(join(flowDir, 'history.jsonl'), trigger === undefined ? row : { ...row, trigger });
|
|
358
|
+
const trigger = typeof row.runId === 'string' && row.trigger === undefined ? readTriggerRecord(join(flowDir, 'runs', row.runId)) : null;
|
|
359
|
+
appendLine(join(flowDir, 'history.jsonl'), trigger === null ? row : { ...row, trigger });
|
|
298
360
|
}
|
|
299
361
|
|
|
300
362
|
/**
|
|
@@ -308,8 +370,112 @@ export function readHistory(flowDir) {
|
|
|
308
370
|
return readLines(flowDir, 'history.jsonl');
|
|
309
371
|
}
|
|
310
372
|
|
|
311
|
-
|
|
312
|
-
|
|
373
|
+
export const HALT_FILE = 'halt.json';
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* M20 am1 item 1: the ONE table of endings. Every history outcome and every audit verdict fwd writes is a key; the flags say what it
|
|
377
|
+
* means, and every reader asks a helper below (never its own list of words):
|
|
378
|
+
* good the run or try passed resumable `halt.json` is left, the run can be continued
|
|
379
|
+
* notFailed not a failure of the job (complete, a stop, a cap halt, a rerun, an expired ask, a skipped ticket)
|
|
380
|
+
* noise the instrument failed, not the work (learnings set the run aside)
|
|
381
|
+
* blocked a verdict that stopped a step, the Run tab's "blocked" line
|
|
382
|
+
* open the Audit's `·` mark: waiting / a human note, not yet resolved either way
|
|
383
|
+
* waiting a step whose last row is this is parked stopNote a Stop's own note row, never a try
|
|
384
|
+
* humanNo the human's own no (the ask fold's `✗`) redTry a try that said the output was wrong
|
|
385
|
+
* tryVerdict a step's try with a verdict on its output spendFloor a halt whose spend can be a floor
|
|
386
|
+
* draftRow a verdict a drafting row of the Audit can carry (anything else reads not-done)
|
|
387
|
+
* notRunEnd not an end of a run (a pause, a failed stop, a skipped ticket): learnings wait
|
|
388
|
+
* word the Runs list's bold word for it (`null` = none: a run the human ended with rerun)
|
|
389
|
+
* audit M20 am9: what an Audit row of this verdict shows: `sign` (`null` = none), `word` and the try `mark` it gives its try. The run's `word` and the Audit's
|
|
390
|
+
* differ (ask-expired reads "expired" on the run, "expired waiting for you" on the row), so they are two columns; read it through `auditSignWord`
|
|
391
|
+
* runOnly an ending of a run only, never a verdict of an Audit row (no `audit` column); `auditSignWord` treats it like a word the table does not hold: failed, ✗
|
|
392
|
+
* Outcome (history.jsonl) and verdict (audit.jsonl) are not split: one word means one thing on either book.
|
|
393
|
+
* Not here, by design: the scheduler's own words (busy, monthly-exhausted, refused fire), the closers' verdicts (done, crash,
|
|
394
|
+
* unparseable), and the Run tab's ending sentences (src/summary-words.js stays their one owner).
|
|
395
|
+
*/
|
|
396
|
+
export const ENDINGS = Object.freeze({
|
|
397
|
+
complete: { good: true, notFailed: true, word: 'passed', runOnly: true },
|
|
398
|
+
skipped: { notFailed: true, notRunEnd: true, word: 'skipped', runOnly: true },
|
|
399
|
+
stopped: { resumable: true, notFailed: true, open: true, humanNo: true, word: 'stopped', audit: { sign: null, word: 'stopped by you', mark: '·' } },
|
|
400
|
+
'cap-halt': { resumable: true, notFailed: true, blocked: true, spendFloor: true, word: 'capped', audit: { sign: '■', word: 'capped — money cap', mark: '■' } },
|
|
401
|
+
rerun: { notFailed: true, word: null, runOnly: true },
|
|
402
|
+
'ask-expired': { notFailed: true, blocked: true, open: true, word: 'expired', audit: { sign: null, word: 'expired waiting for you', mark: '·' } },
|
|
403
|
+
'ask-timeout': { blocked: true, open: true, word: 'failed', audit: { sign: null, word: 'expired waiting for you', mark: '·' } },
|
|
404
|
+
refused: { blocked: true, open: true, waiting: true, word: 'failed', audit: { sign: null, word: 'refused — no reason given', mark: '·' } },
|
|
405
|
+
red: { blocked: true, humanNo: true, redTry: true, tryVerdict: true, draftRow: true, word: 'failed', audit: { sign: '✗', word: 'failed', mark: '✗' } },
|
|
406
|
+
'not-done': { blocked: true, redTry: true, tryVerdict: true, word: 'failed', audit: { sign: '✗', word: 'not done', mark: '✗' } },
|
|
407
|
+
'provider-red': { blocked: true, noise: true, spendFloor: true, word: 'failed', audit: { sign: '✗', word: 'failed', mark: '✗' } },
|
|
408
|
+
'pricing-red': { blocked: true, spendFloor: true, word: 'failed', audit: { sign: '✗', word: 'failed', mark: '✗' } },
|
|
409
|
+
'close-casualty': { blocked: true, noise: true, word: 'failed', audit: { sign: '✗', word: 'failed', mark: '✗' } },
|
|
410
|
+
'preflight-red': { word: 'failed', runOnly: true },
|
|
411
|
+
'struck-out': { word: 'failed', runOnly: true },
|
|
412
|
+
'attempt-fallback': { word: 'failed', runOnly: true },
|
|
413
|
+
'redo-halt': { word: 'failed', runOnly: true },
|
|
414
|
+
'stop-failed': { notRunEnd: true, word: 'failed', runOnly: true },
|
|
415
|
+
green: { good: true, tryVerdict: true, draftRow: true, audit: { sign: '✓', word: 'passed', mark: '✓' } },
|
|
416
|
+
hitl: { good: true, tryVerdict: true, audit: { sign: '✓', word: 'human check', mark: '✓' } },
|
|
417
|
+
softgreen: { tryVerdict: true, audit: { sign: '✗', word: 'failed', mark: '✗' } }, // fwd writes no such verdict today; the learnings read audits shaped like bareloop's, so it stays a try
|
|
418
|
+
paused: { open: true, waiting: true, notRunEnd: true, audit: { sign: null, word: 'paused for you', mark: '·' } },
|
|
419
|
+
'ask-reopened': { open: true, audit: { sign: null, word: 'reopened by you', mark: '·' } },
|
|
420
|
+
'lock-removed': { open: true, audit: { sign: null, word: 'old lock removed by you', mark: '·' } },
|
|
421
|
+
'stop-asked': { open: true, stopNote: true, audit: { sign: null, word: 'stop asked by you', mark: '·' } },
|
|
422
|
+
'stop-not-honoured': { open: true, stopNote: true, audit: { sign: null, word: 'stop not honoured', mark: '·' } },
|
|
423
|
+
'stale-answer-ignored': { audit: { sign: '✗', word: 'failed', mark: '✗' } },
|
|
424
|
+
'answer-after-run': { audit: { sign: '✗', word: 'failed', mark: '✗' } },
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
/** @param {unknown} word @param {string} flag */
|
|
428
|
+
const endingHas = (word, flag) => typeof word === 'string' && Object.hasOwn(ENDINGS, word) && /** @type {any} */ (ENDINGS)[word][flag] === true;
|
|
429
|
+
export const isGoodEnding = (/** @type {unknown} */ w) => endingHas(w, 'good');
|
|
430
|
+
/** a history outcome that is a failure of the job; a word the table does not know counts as one */
|
|
431
|
+
export const isFailedEnding = (/** @type {unknown} */ w) => !endingHas(w, 'notFailed');
|
|
432
|
+
export const isNoiseEnding = (/** @type {unknown} */ w) => endingHas(w, 'noise');
|
|
433
|
+
export const isBlockedEnding = (/** @type {unknown} */ w) => endingHas(w, 'blocked');
|
|
434
|
+
export const isOpenEnding = (/** @type {unknown} */ w) => endingHas(w, 'open');
|
|
435
|
+
export const isWaitingEnding = (/** @type {unknown} */ w) => endingHas(w, 'waiting');
|
|
436
|
+
export const isStopNote = (/** @type {unknown} */ w) => endingHas(w, 'stopNote');
|
|
437
|
+
export const isHumanNo = (/** @type {unknown} */ w) => endingHas(w, 'humanNo');
|
|
438
|
+
export const isRedTry = (/** @type {unknown} */ w) => endingHas(w, 'redTry');
|
|
439
|
+
/**
|
|
440
|
+
* M20 am3g item 22: the ONE rule for why a run is red: the log's own `red` when it is a non-empty string, else the LAST red audit row as `<step>: <gap>` (a step can fail,
|
|
441
|
+
* redo and fail again differently; the most recent stop is where the run sits now), else null. The Run tab and the Result tab ask it and keep their own guards and words.
|
|
442
|
+
* @param {any} logJson the run's log.json (or null) @param {any[]} auditRows @returns {string|null}
|
|
443
|
+
*/
|
|
444
|
+
export function redWhyOf(logJson, auditRows) {
|
|
445
|
+
if (typeof logJson?.red === 'string' && logJson.red.length > 0) return logJson.red;
|
|
446
|
+
const row = auditRows.findLast((r) => isRedTry(r.verdict));
|
|
447
|
+
return row ? `${row.step}: ${row.gap}` : null;
|
|
448
|
+
}
|
|
449
|
+
export const isTryVerdict = (/** @type {unknown} */ w) => endingHas(w, 'tryVerdict');
|
|
450
|
+
export const isSpendFloorEnding = (/** @type {unknown} */ w) => endingHas(w, 'spendFloor');
|
|
451
|
+
export const isDraftRowVerdict = (/** @type {unknown} */ w) => endingHas(w, 'draftRow');
|
|
452
|
+
export const isNotRunEnd = (/** @type {unknown} */ w) => endingHas(w, 'notRunEnd');
|
|
453
|
+
/** The outcomes a run can be continued from (M4e amendment 4 item 4): the runner leaves `halt.json` for them. */
|
|
454
|
+
export const isResumableEnding = (/** @type {unknown} */ w) => endingHas(w, 'resumable');
|
|
455
|
+
/** the Runs list's bold word for an ending (`null` for none) @param {string} w @returns {string|null} */
|
|
456
|
+
export function endingWord(w) {
|
|
457
|
+
return Object.hasOwn(ENDINGS, w) ? /** @type {any} */ (ENDINGS)[w].word ?? null : null;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* M20 am9b: was this Audit row written by the Ask's answer path (the person's own paused, accept, redo, rerun, refused rows)? The runner gives that path's rows, and no other, `unjudgedCount` (F281: 41 hitl+red rows, 0 mismatches).
|
|
462
|
+
* @param {any} row
|
|
463
|
+
*/
|
|
464
|
+
export const isAskRow = (row) => row !== null && typeof row === 'object' && Object.hasOwn(row, 'unjudgedCount');
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* M20 am9 / am9b: the ONE owner of an Audit row's sign, word and try mark. `closeClass`, `gap` and `human` (the row is the Ask's own, `isAskRow`) are its inputs: a `red` on a
|
|
468
|
+
* `hitl` step that the person wrote is their redo, no sign, "redo by you: <gap>" (mark ✗); the same red written by a model is a plain red, failed ✗. A verdict that is not a string reads "unknown" ✗; a verdict with no `audit` column (a run-only ending, or a word the table
|
|
469
|
+
* does not hold) reads failed ✗, as the page always drew it.
|
|
470
|
+
* @param {unknown} verdict @param {string|null|undefined} [closeClass] @param {string|null|undefined} [gap] @param {boolean} [human]
|
|
471
|
+
* @returns {{sign: '✓'|'✗'|'■'|null, word: string, mark: '✓'|'✗'|'·'|'■'}}
|
|
472
|
+
*/
|
|
473
|
+
export function auditSignWord(verdict, closeClass, gap, human = false) {
|
|
474
|
+
if (closeClass === 'hitl' && verdict === 'red' && human) return { sign: null, word: `redo by you${gap ? `: ${gap}` : ''}`, mark: '✗' };
|
|
475
|
+
if (typeof verdict !== 'string') return { sign: '✗', word: 'unknown', mark: '✗' };
|
|
476
|
+
const col = Object.hasOwn(ENDINGS, verdict) ? /** @type {any} */ (ENDINGS)[verdict].audit : undefined;
|
|
477
|
+
return col ?? { sign: '✗', word: 'failed', mark: '✗' };
|
|
478
|
+
}
|
|
313
479
|
|
|
314
480
|
/**
|
|
315
481
|
* The ONE rule for "how did this run end": the LAST history row of the run (a run that was stopped or cap-halted and
|
|
@@ -323,8 +489,67 @@ export const HALT_OUTCOMES = Object.freeze(['cap-halt', 'stopped']);
|
|
|
323
489
|
export function endRow(historyRows, runDir, runId) {
|
|
324
490
|
let last = null;
|
|
325
491
|
for (const r of historyRows) if (r && r.runId === runId) last = r;
|
|
326
|
-
if (last === null || !
|
|
492
|
+
if (last === null || !isResumableEnding(last.outcome)) return last;
|
|
327
493
|
const names = readdirInside(runDir, '.');
|
|
328
|
-
const continuing = !names.includes('halt.json') &&
|
|
494
|
+
const continuing = !names.includes('halt.json') && haltConsumedCount(runDir) > 0;
|
|
329
495
|
return continuing ? null : last;
|
|
330
496
|
}
|
|
497
|
+
|
|
498
|
+
/** The one place `halt.<n>.consumed.json` is named: how many a run holds, and the name the next continue renames halt.json to. @param {string} runDir */
|
|
499
|
+
export function haltConsumedCount(runDir) {
|
|
500
|
+
return readdirInside(runDir, '.').filter((n) => /^halt\.\d+\.consumed\.json$/.test(n)).length;
|
|
501
|
+
}
|
|
502
|
+
/** @param {string} runDir */
|
|
503
|
+
export function nextHaltConsumedName(runDir) {
|
|
504
|
+
return `halt.${haltConsumedCount(runDir) + 1}.consumed.json`;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** The one reader of halt.json (the run is waiting = the file EXISTS, parse or not: see {@link haltFileExists}): `{ok:true, halt}`, `{ok:false, missing:true}` (not resumable), or `{ok:false, red}`. @param {string} runDir */
|
|
508
|
+
export function readHaltRecord(runDir) {
|
|
509
|
+
const r = readFileInside(runDir, HALT_FILE);
|
|
510
|
+
if (!r.ok) return r.missing ? { ok: false, missing: true } : { ok: false, red: `halt.json — ${r.red}` };
|
|
511
|
+
try { return { ok: true, halt: JSON.parse(r.text) }; } catch (err) { return { ok: false, red: `halt.json is not valid JSON — ${err.message}` }; }
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* `writeLog`'s own sibling reader (M4a piece 2, docs/wiki/the-module-
|
|
516
|
+
* ladder.md M4a scope item 2: "one reader per book") — `null` when the run
|
|
517
|
+
* hasn't reached an exit path yet (still running, or parked before any
|
|
518
|
+
* halt/complete), or the file is present but not valid JSON (a torn write),
|
|
519
|
+
* never a thrown error.
|
|
520
|
+
* @param {string} runDir
|
|
521
|
+
* @returns {any|null}
|
|
522
|
+
*/
|
|
523
|
+
export function readLog(runDir) {
|
|
524
|
+
const result = readFileInside(runDir, 'log.json');
|
|
525
|
+
if (!result.ok) return null;
|
|
526
|
+
try { return JSON.parse(result.text); } catch { return null; }
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* `state.json`'s own sibling reader (same rule as {@link readLog}) — `null`
|
|
531
|
+
* when the run has never parked, or the file is present but not valid JSON. `{ strict: true }` (Resume) returns
|
|
532
|
+
* `{ok:true, state}`, `{ok:false, missing:true}` or `{ok:false, red}` instead.
|
|
533
|
+
* @param {string} runDir
|
|
534
|
+
* @param {{strict?: boolean}} [opts]
|
|
535
|
+
* @returns {any}
|
|
536
|
+
*/
|
|
537
|
+
export function readRunState(runDir, { strict = false } = {}) {
|
|
538
|
+
const result = readFileInside(runDir, 'state.json');
|
|
539
|
+
if (strict) {
|
|
540
|
+
// strict mode (M20 am3 item 11, Resume): missing, refused and torn stay three different words
|
|
541
|
+
if (!result.ok) return result.missing ? { ok: false, missing: true } : { ok: false, red: result.red };
|
|
542
|
+
try { return { ok: true, state: JSON.parse(result.text) }; } catch (err) { return { ok: false, red: `is not valid JSON — ${err.message}` }; }
|
|
543
|
+
}
|
|
544
|
+
if (!result.ok) return null;
|
|
545
|
+
try { return JSON.parse(result.text); } catch { return null; }
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* "Is this run waiting to be resumed?" as the panel's start watcher has always read it: a `halt.json` that EXISTS means
|
|
550
|
+
* waiting, even when it does not parse (unlike {@link readHaltRecord}, where a torn file is a red). One name for that rule.
|
|
551
|
+
* @param {string} runDir
|
|
552
|
+
*/
|
|
553
|
+
export function haltFileExists(runDir) {
|
|
554
|
+
return readFileInside(runDir, HALT_FILE).ok;
|
|
555
|
+
}
|
package/src/checkblock.js
CHANGED
|
@@ -15,15 +15,16 @@
|
|
|
15
15
|
// counts built into rubric-step parts; a repo job (`repo` option) holds `~` rule rows the write fence keeps (or that the person answers about), `!` rows for the drafter's catalogue work stages, and the same `$` rows.
|
|
16
16
|
// The same rows store, the same asks, the same Drop/carry, the same signedRows and closeView serve both.
|
|
17
17
|
import { globToPrefix } from './globprefix.js';
|
|
18
|
-
import { countExact, countPhrase } from './pagebits.js';
|
|
18
|
+
import { countExact, countPhrase, isAmountShape, isPhraseShape, isLegalCount } from './pagebits.js';
|
|
19
19
|
import { checkFactWords, keptSetOf } from './factwords.js';
|
|
20
20
|
import { isCountable, keepOrDrop, countCheck, obviousCheck, partOfPick, plainWords } from './blockpick.js';
|
|
21
21
|
import { dropRows, dropSentence } from './pagedropwords.js';
|
|
22
22
|
import { phraseInNoResult, asSeenOf } from './pagedry.js';
|
|
23
23
|
import { boundInWords, rubricStepShapeReds, stageKeyOf, guardKeyOf, FENCE_KEY, defaultCitedText, defaultNoteText, readLimit, holdsManyBounds, NEGATING_RE, WHY_OTHER_CURRENCY } from './rubricstep.js';
|
|
24
|
-
import { validReading } from './pagerules.js';
|
|
24
|
+
import { validReading, canReadLimit } from './pagerules.js';
|
|
25
25
|
import { weekOnly, weekTokens, WEEK_ONLY_WORDS, MAX_BANG } from './checklist.js';
|
|
26
26
|
import { fitPlacePhrase } from './placerule.js';
|
|
27
|
+
import { isRowChoice } from './pickrecord.js';
|
|
27
28
|
import { ruleWords } from './pageask.js';
|
|
28
29
|
import { SIGNED_ROW_FIELDS } from './declaredclose.js';
|
|
29
30
|
import { factSentence, countSentence, factsOfLook } from './citedcheck.js';
|
|
@@ -33,6 +34,7 @@ import { sheetCheckName, sheetPlainText, coversWords } from './sheetblock.js';
|
|
|
33
34
|
import { sheetCheckBody, sheetRowKey } from './sheetrows.js';
|
|
34
35
|
import { shapeRowKey, shapeDefaultKey, shapeFieldText, buildShapePart, itemCountOf } from './shaperows.js';
|
|
35
36
|
import { fieldSpec } from './shapebuild.js';
|
|
37
|
+
import { REASON } from './reasons.js';
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* A row. `kind`: rule, fact, phrase, count, cited, numbers, floor. `by`: you (`~`), agent (`!`), default (`$`). A `~` row may carry `links` (the look's facts tied to it),
|
|
@@ -44,6 +46,8 @@ import { fieldSpec } from './shapebuild.js';
|
|
|
44
46
|
|
|
45
47
|
/** the four row edits an AI reply may hold */
|
|
46
48
|
export const EDIT_OPS = Object.freeze(['add', 'reading', 'pick', 'not-checkable', 'fence']);
|
|
49
|
+
/** M20 am8: the one question "is this check row's kind a fact or a phrase" (a page-word row, not a count) @param {unknown} kind @returns {boolean} */
|
|
50
|
+
export const isFactKind = (kind) => kind === 'fact' || kind === 'phrase';
|
|
47
51
|
|
|
48
52
|
const norm = (/** @type {unknown} */ t) => String(t ?? '').toLowerCase().replace(/\s+/g, ' ').trim();
|
|
49
53
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -76,30 +80,6 @@ const numberIn = (text, n) => {
|
|
|
76
80
|
};
|
|
77
81
|
const wordSet = (/** @type {unknown} */ t) => new Set(norm(t).match(/[\p{L}\p{N}]+/gu) ?? []);
|
|
78
82
|
|
|
79
|
-
/** the plain reasons code gives, in one place (the card, the Job tab and the Audit read them from the row) */
|
|
80
|
-
export const REASON = Object.freeze({
|
|
81
|
-
left: 'You chose to leave it Not checked, so you judge it at Accept.',
|
|
82
|
-
nothingOnPage: 'Your own words are on the line; the machine has no check for them, so you judge it at Accept.',
|
|
83
|
-
noRule: 'No rule can check this, so you judge it at Accept.',
|
|
84
|
-
waitingPick: 'waiting for your answer on the proposed check',
|
|
85
|
-
waitingReading: 'waiting for your answer on the reading',
|
|
86
|
-
onePerLine: 'this line finds facts, so it has no text to quote',
|
|
87
|
-
manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
|
|
88
|
-
oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
|
|
89
|
-
countNeedsFact: 'a result count needs a fact to count; this line has none',
|
|
90
|
-
countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
|
|
91
|
-
lookNoWords: "the page does not hold the words of the look's fact for this rule",
|
|
92
|
-
afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
|
|
93
|
-
noPick: 'No check was picked for it, so you judge it at Accept.',
|
|
94
|
-
itemCountByRule: 'your rule on this line sets the item count',
|
|
95
|
-
negated: 'it says what is not needed, so there is nothing to check',
|
|
96
|
-
dropped: 'You dropped it.',
|
|
97
|
-
suggested: 'Suggested: not in your job, so it is not checked unless you add it.',
|
|
98
|
-
sheetLine: 'this line reads a sheet and its rules are checked by the sheet checks, so a row edit about it is not used',
|
|
99
|
-
sheetFacts: 'this line reads a sheet, so it is checked by its sheet checks and not by page facts',
|
|
100
|
-
columnRule: "this rule only names a column; the agent's checks on this line use it",
|
|
101
|
-
});
|
|
102
|
-
|
|
103
83
|
/** the card's rows: which rows show, and their key, line, tag, state and reason. NO words: the words of a row are the plan reader's (src/checkrows.js `planCard`), one writer (M19 am6 item 4). @param {Row[]} rows */
|
|
104
84
|
export function renderCard(rows) {
|
|
105
85
|
// fwd keeps: the card draws no floor row (and there is no prose row) today
|
|
@@ -260,7 +240,7 @@ export class CheckBlock {
|
|
|
260
240
|
*/
|
|
261
241
|
shapeCandidates() {
|
|
262
242
|
if (this.repo !== null) return [];
|
|
263
|
-
return this.rows.filter((r) => r.kind === 'rule' && !r.left && (!r.can?.ok || r.truthRefused) && !r.can?.ask && !this.isSheetLine(r.line) && !NEGATING_RE.test(String(r.text))).map((r) => ({ line: r.line, rule: Number(r.rule) }));
|
|
243
|
+
return this.rows.filter((r) => r.kind === 'rule' && !r.left && (!r.can?.ok || r.truthRefused) && !r.can?.ask && !r.can?.final && !this.isSheetLine(r.line) && !NEGATING_RE.test(String(r.text))).map((r) => ({ line: r.line, rule: Number(r.rule) }));
|
|
264
244
|
}
|
|
265
245
|
|
|
266
246
|
/**
|
|
@@ -407,7 +387,7 @@ export class CheckBlock {
|
|
|
407
387
|
match() {
|
|
408
388
|
// live draft 3 (hamr 2026-11-13: "anything not in your original job that code can check goes to Suggested"): a `!` fact whose page words are longer than what the job says ("Boston Logan International
|
|
409
389
|
// Airport" for the job's "Boston") says the JOB's word; the row is then job-derived (inJob below, the one owner) and its phrase check uses that word
|
|
410
|
-
if (this.split) for (const r of this.rows) if (this.isBang(r) && (r.kind
|
|
390
|
+
if (this.split) for (const r of this.rows) if (this.isBang(r) && isFactKind(r.kind)) this.takeJobWord(r);
|
|
411
391
|
for (const r of this.rows) {
|
|
412
392
|
r.can = null;
|
|
413
393
|
if (r.kind === 'floor') continue;
|
|
@@ -415,7 +395,7 @@ export class CheckBlock {
|
|
|
415
395
|
else if (r.lookWhy && r.kind === 'fact' && !r.words.length) r.can = { ok: false, why: r.lookWhy };
|
|
416
396
|
else if (r.kind === 'stage') r.can = r.refusal ? { ok: false, why: r.said } : { ok: true, how: 'stage' };
|
|
417
397
|
else if (r.kind === 'rule') this.matchRule(r);
|
|
418
|
-
else if (r.kind
|
|
398
|
+
else if (isFactKind(r.kind)) this.matchBang(r);
|
|
419
399
|
else if (r.kind === 'count') this.matchCount(r);
|
|
420
400
|
else if (r.kind === 'sheet') r.can = { ok: true, how: 'sheet' };
|
|
421
401
|
}
|
|
@@ -466,7 +446,7 @@ export class CheckBlock {
|
|
|
466
446
|
if (r.kind === 'count') return [r.min, r.max].filter((x) => Number.isInteger(x)).some((n) => numberIn(said, n));
|
|
467
447
|
// a money, time, number or date fact the person asked for BY NAME ("the release heading") is in the job too: the look's page words rarely echo the job's own words. A phrase or place is job-derived
|
|
468
448
|
// only when its own words are in the person's text: a name the AI gave it is no proof (hamr 2026-11-15, live run mwi76vh8: "friendly" for "Select flight")
|
|
469
|
-
return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && r.shape
|
|
449
|
+
return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && !isPhraseShape(r.shape) && typeof r.name === 'string' && inText(said, r.name));
|
|
470
450
|
}
|
|
471
451
|
|
|
472
452
|
/**
|
|
@@ -495,7 +475,8 @@ export class CheckBlock {
|
|
|
495
475
|
matchRule(r) {
|
|
496
476
|
this.matchTruthRule(r);
|
|
497
477
|
// a truth check code picked but REFUSED when it built the line (live mwnbs3np: 4 results, a title said once) is no check: the rule is still Not checked, so it may take its shape field (hamr: shape for what code could not check)
|
|
498
|
-
|
|
478
|
+
// `final`: the page itself says this rule cannot be checked (an amount in another currency than the page's prices): the AI's own answer is not a way round it, the person reads the reason
|
|
479
|
+
if (r.can?.ask || r.can?.final || (r.can?.ok && !r.truthRefused)) return;
|
|
499
480
|
const sh = this.takesShape(r);
|
|
500
481
|
if (sh === null) return;
|
|
501
482
|
r.can = this.shapeDrops.rules.has(`${r.line}:${r.rule}`) ? { ok: false, why: REASON.dropped } : { ok: true, how: 'shape', name: sh.name };
|
|
@@ -509,7 +490,7 @@ export class CheckBlock {
|
|
|
509
490
|
if (isCountable(r.text)) { this.matchCountRule(r); return; }
|
|
510
491
|
// F-a (hamr 2026-11-13): a rule that carries a negation ("nonstop is not mandatory") says what is NOT needed; its words can never give a phrase bound ("must say"). The one negation reader is NEGATING_RE.
|
|
511
492
|
const negated = NEGATING_RE.test(r.text);
|
|
512
|
-
const isPhrase = (/** @type {any} */ l) => l.shape
|
|
493
|
+
const isPhrase = (/** @type {any} */ l) => isPhraseShape(l.shape);
|
|
513
494
|
if (negated && (r.links ?? []).length && (r.links ?? []).every(isPhrase)) { r.can = { ok: false, why: REASON.negated }; return; }
|
|
514
495
|
const links = (r.links ?? []).filter((/** @type {any} */ l) => !(negated && isPhrase(l)) && l.words.some((/** @type {string} */ w) => proved(this.textOf(l.source), w)));
|
|
515
496
|
const said = this.said(r.line);
|
|
@@ -518,7 +499,7 @@ export class CheckBlock {
|
|
|
518
499
|
for (const l of links) {
|
|
519
500
|
let reading = l.reading;
|
|
520
501
|
let ownWords = false;
|
|
521
|
-
if (l.shape
|
|
502
|
+
if (canReadLimit(l.shape)) {
|
|
522
503
|
// the person's words win (hamr 2026-11-13): code's reading of the `~` words beats the look's and the AI's; theirs is used only when code cannot read the words
|
|
523
504
|
const rd = this.wordsReading(l, r.text);
|
|
524
505
|
// fwdloop run walk-m16-flights run-1: "under $150" on a euro fact fell back to the look's reading and checked 150 euros; a bound in another currency than the page fact is never replaced by the look's or the AI's reading
|
|
@@ -551,7 +532,7 @@ export class CheckBlock {
|
|
|
551
532
|
r.can = { ok: true, how: 'fact', link: l, reading: undefined };
|
|
552
533
|
return;
|
|
553
534
|
}
|
|
554
|
-
if (otherCurrency) { r.can = { ok: false, why: `the amount in your rule is in another currency than the page's prices, so it is not checked.` }; return; }
|
|
535
|
+
if (otherCurrency) { r.can = { ok: false, final: true, why: `the amount in your rule is in another currency than the page's prices, so it is not checked.` }; return; }
|
|
555
536
|
if (r.links?.length && !links.length) { r.can = { ok: false, why: REASON.lookNoWords }; return; }
|
|
556
537
|
if (r.origin === 'typed' || r.cantAsked) { r.can = { ok: false, why: r.aiReason ?? r.lookWhy ?? REASON.noPick }; return; }
|
|
557
538
|
if (r.links?.length) { r.can = { ok: false, why: r.aiReason ?? `the look tied a fact to this rule but gave no limit, and ${ownWhy ? `in your words ${ownWhy}` : 'your own words give none code can read'}, so you judge it at Accept.` }; return; }
|
|
@@ -728,7 +709,7 @@ export class CheckBlock {
|
|
|
728
709
|
return k ? factsOfLook(k) : null;
|
|
729
710
|
};
|
|
730
711
|
lineParts.push({ ...part, facts: facts.flatMap((f) => grownOf(f) ?? [f]) }); lineRows.push([...factRows.map((f) => f.r.key), ...(countRow ? [countRow.key] : [])]); foundFact = true; if (countRow) { countRow.state = 'built'; countRow.reason = null; } }
|
|
731
|
-
} else if (countRow) { countRow.state = 'not-checked'; countRow.reason = this.rowsOn(l.n).some((x) => x.held && (x.kind
|
|
712
|
+
} else if (countRow) { countRow.state = 'not-checked'; countRow.reason = this.rowsOn(l.n).some((x) => x.held && isFactKind(x.kind)) ? REASON.countNeedsSuggested : REASON.countNeedsFact; }
|
|
732
713
|
// facts+shape: the shape part follows the fact part (the same `results` list); its fields are the rules no truth check could take
|
|
733
714
|
if (shapeRows.length > 0) this.buildShapePartOf(l, shapeRows, lineParts, lineRows);
|
|
734
715
|
for (const { p, key } of pickParts) { lineParts.push(p); lineRows.push([key]); }
|
|
@@ -794,7 +775,7 @@ export class CheckBlock {
|
|
|
794
775
|
const mk = (/** @type {string} */ name, /** @type {any} */ extra) => ({ name: cleanName(name), ...extra });
|
|
795
776
|
const kindFields = (/** @type {any} */ f, /** @type {string} */ anchor, /** @type {any} */ extra) => mk(f.name, {
|
|
796
777
|
shape: f.shape, anchor, ...(f.unit ? { unit: f.unit } : {}), ...(f.currency ? { currency: f.currency } : {}),
|
|
797
|
-
...(f.decimal && (f.shape
|
|
778
|
+
...(f.decimal && isAmountShape(f.shape) ? { decimal: f.decimal } : {}), ...(f.lang && f.shape === 'date' ? { lang: f.lang } : {}), ...extra,
|
|
798
779
|
});
|
|
799
780
|
/** @type {any[]} */ let fs;
|
|
800
781
|
if (r.kind === 'rule') {
|
|
@@ -1136,7 +1117,7 @@ export class CheckBlock {
|
|
|
1136
1117
|
|
|
1137
1118
|
editAdd(/** @type {any} */ e) {
|
|
1138
1119
|
if (e.kind === 'count') return this.addCount(e);
|
|
1139
|
-
if (e.kind
|
|
1120
|
+
if (!isFactKind(e.kind)) return { refusedBecause: 'an add is a fact, a phrase or a count' };
|
|
1140
1121
|
// an input the job does not have is refused alone (it would otherwise reach the draft gate as a red on code's own plan and stop the whole draft)
|
|
1141
1122
|
if (e.source !== undefined && e.source !== null && !this.labels.includes(e.source)) return { refusedBecause: `"${String(e.source).slice(0, 60)}" is not one of the inputs` };
|
|
1142
1123
|
// a job with more than one input never guesses which one an add quotes (code fills a missing source only when there is exactly one)
|
|
@@ -1165,13 +1146,12 @@ export class CheckBlock {
|
|
|
1165
1146
|
const rs = wordSet(rr.text);
|
|
1166
1147
|
if (wset.size && [...wset].every((w) => rs.has(w))) return `already on the list: a ~ rule says it (line ${line} rule ${rr.rule})`;
|
|
1167
1148
|
}
|
|
1168
|
-
if (this.rows.some((r) => (r.kind
|
|
1149
|
+
if (this.rows.some((r) => isFactKind(r.kind) && r.line === line && (norm(r.name) === norm(name) || norm(r.words?.[0]) === norm(words[0])))) return 'already on the list';
|
|
1169
1150
|
return null;
|
|
1170
1151
|
}
|
|
1171
1152
|
|
|
1172
1153
|
addCount(/** @type {any} */ e) {
|
|
1173
|
-
|
|
1174
|
-
if (![e.min, e.max].some(Number.isInteger) || [e.min, e.max].some((x) => x !== undefined && !ok(x)) || (Number.isInteger(e.min) && Number.isInteger(e.max) && e.min > e.max)) return { refusedBecause: 'no legal number given' };
|
|
1154
|
+
if (!isLegalCount({ min: e.min, max: e.max })) return { refusedBecause: 'no legal number given' };
|
|
1175
1155
|
if (this.rowsOn(e.line, 'count').length) return { refusedBecause: 'already on the list: this line has a result count' };
|
|
1176
1156
|
const row = this.addRow({ key: `L${e.line}.count.${e.min ?? ''}-${e.max ?? ''}`, line: e.line, kind: 'count', by: 'agent', from: 'agent', min: e.min, max: e.max });
|
|
1177
1157
|
return { accepted: true, landedKey: row.key };
|
|
@@ -1184,7 +1164,7 @@ export class CheckBlock {
|
|
|
1184
1164
|
|
|
1185
1165
|
/** the one owner of "what do the person's own words say": code's reading of a `~` rule for a money/time fact, or undefined when it cannot read it */
|
|
1186
1166
|
wordsReading(/** @type {any} */ l, /** @type {string} */ text) {
|
|
1187
|
-
if (l.shape
|
|
1167
|
+
if (!canReadLimit(l.shape)) return undefined;
|
|
1188
1168
|
const own = readLimit(l.shape, text, l);
|
|
1189
1169
|
const rd = 'reading' in own ? own.reading : undefined;
|
|
1190
1170
|
return rd && validReading(l.shape, rd) && (rd.op === 'between' ? [rd.lo, rd.hi] : [rd.value]).every((b) => boundInWords(b, text)) ? rd : undefined;
|
|
@@ -1334,7 +1314,7 @@ export class CheckBlock {
|
|
|
1334
1314
|
}
|
|
1335
1315
|
if (r.by === 'you') return { ok: false, why: 'that check comes from a rule you wrote; edit the job to change it' };
|
|
1336
1316
|
if (r.by !== 'agent' || !this.droppable(r)) return { ok: false, why: 'that check is code\'s own and stays' };
|
|
1337
|
-
if (choice
|
|
1317
|
+
if (!isRowChoice(choice)) return { ok: false, why: 'not one of the choices' };
|
|
1338
1318
|
if (r.kind === 'stage') {
|
|
1339
1319
|
// a repo work stage: Drop takes it out of the close (never the last check on its line), Add puts it back
|
|
1340
1320
|
if (choice === 'drop' && r.state !== 'built') return { ok: false, why: 'only a check that is on the card can be dropped' };
|
|
@@ -1355,7 +1335,7 @@ export class CheckBlock {
|
|
|
1355
1335
|
|
|
1356
1336
|
/** the person's Drop/Add choices, tied to the line's words (not its number) and the row's own name, so a Revise keeps them @returns {{lineWords: string, occurrence: number, tail: string, choice: string}[]} */
|
|
1357
1337
|
choicesRecord() {
|
|
1358
|
-
return choiceEntries(this.lines, this.rows.filter((r) => r.kind !== 'sheet' && r.kind !== 'shape' && (r.choice
|
|
1338
|
+
return choiceEntries(this.lines, this.rows.filter((r) => r.kind !== 'sheet' && r.kind !== 'shape' && isRowChoice(r.choice)).map((r) => ({ line: r.line, key: r.key, choice: String(r.choice) })));
|
|
1359
1339
|
}
|
|
1360
1340
|
|
|
1361
1341
|
/** a Revise keeps the last draft's Drop/Add choices on the rows that are still there (same line words, same row); code still judges every one @param {{lineWords: string, occurrence: number, tail: string, choice: string}[]} rec */
|
|
@@ -1363,7 +1343,7 @@ export class CheckBlock {
|
|
|
1363
1343
|
const seen = new Map();
|
|
1364
1344
|
const lines = this.lines.map((l) => { const w = norm(l.text); const o = seen.get(w) ?? 0; seen.set(w, o + 1); return { n: l.n, w, o }; });
|
|
1365
1345
|
for (const c of Array.isArray(rec) ? rec : []) {
|
|
1366
|
-
if (!c || (c.choice
|
|
1346
|
+
if (!c || !isRowChoice(c.choice)) continue;
|
|
1367
1347
|
const line = lines.find((l) => l.w === c.lineWords && l.o === c.occurrence);
|
|
1368
1348
|
const r = line ? this.rows.find((x) => x.line === line.n && this.droppable(x) && x.key.replace(/^L\d+\./, '') === c.tail) : undefined;
|
|
1369
1349
|
if (r) { r.choice = c.choice; r.keptFromLast = true; }
|
package/src/checklistsign.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Equivalent of bareloop src/rubricstep.js@v0.56.0 (3383cce) `listMatchesClose`, read over fwdloop's close fields instead of a rubric-step stage: the checks of one line, in the order the check block
|
|
3
3
|
// builds them, are [close.cited (the fact part)], [close.itemShape (the shape part, M19 S5)], then each entry of close.picked / close.shape.picked, then close.numbersFrom (the numbers tie). A signed row points at one of them by `part: {line, part: <index>}`.
|
|
4
4
|
import { isRec } from './isrec.js';
|
|
5
|
+
import { tagOf } from './checkwords.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* The checks of one step's close in the block's part order. M16 am4: with `withSheet` (a plan whose list has sheet rows) each `close.sheet` check is a part too, after the others.
|
|
@@ -77,17 +78,38 @@ const builtOn = (declaration, line) => (isRec(declaration) && Array.isArray(decl
|
|
|
77
78
|
*/
|
|
78
79
|
export function partByOf(declaration, line, idx) {
|
|
79
80
|
const r = builtOn(declaration, line).find((x) => isRec(x.part) && x.part.part === idx);
|
|
80
|
-
return r && (r.by
|
|
81
|
+
return r && tagOf(r.by) !== '' ? r.by : null;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
/** who made the fact named `name` of a list line's quote check (the row that built it), else null @param {any} declaration @param {number} line @param {string} name @returns {'you'|'agent'|'default'|null} */
|
|
84
85
|
export function factByOf(declaration, line, name) {
|
|
85
86
|
const r = builtOn(declaration, line).find((x) => Array.isArray(x.facts) && x.facts.includes(name));
|
|
86
|
-
return r && (r.by
|
|
87
|
+
return r && tagOf(r.by) !== '' ? r.by : null;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/** who made the result count of a list line's quote check, else null @param {any} declaration @param {number} line @returns {'you'|'agent'|'default'|null} */
|
|
90
91
|
export function countByOf(declaration, line) {
|
|
91
92
|
const r = builtOn(declaration, line).find((x) => x.kind === 'count');
|
|
92
|
-
return r && (r.by
|
|
93
|
+
return r && tagOf(r.by) !== '' ? r.by : null;
|
|
93
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The proof of a plan whose list has ticket rows (a plan with none is not examined): a built ticket row needs the declaration's field, and a field the declaration holds needs a built row for it.
|
|
98
|
+
* @param {any} declaration @returns {string[]}
|
|
99
|
+
*/
|
|
100
|
+
export function ticketListReds(declaration) {
|
|
101
|
+
const list = isRec(declaration) && Array.isArray(declaration.checkList) ? declaration.checkList.filter((/** @type {any} */ r) => isRec(r) && r.kind === 'ticket') : [];
|
|
102
|
+
if (list.length === 0) return [];
|
|
103
|
+
/** @type {string[]} */
|
|
104
|
+
const reds = [];
|
|
105
|
+
for (const f of TICKET_FIELDS) {
|
|
106
|
+
const built = list.some((/** @type {any} */ r) => r.field === f && r.state === 'built');
|
|
107
|
+
const has = Object.hasOwn(declaration, f);
|
|
108
|
+
if (built && !has) reds.push(`declaration: checkList: a row says "${f}" is its check, but the plan has no "${f}". Nothing was signed - draft again.`);
|
|
109
|
+
if (has && !built) reds.push(`declaration: "${f}" is not the check of any rule on the list. Nothing was signed - draft again.`);
|
|
110
|
+
}
|
|
111
|
+
return reds;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** @type {readonly ('ticketFilter'|'ticketWatch')[]} */
|
|
115
|
+
export const TICKET_FIELDS = Object.freeze(['ticketFilter', 'ticketWatch']);
|
package/src/checklook.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// The card (src/cardlist.js), the Audit (src/auditchecks.js), the draft readout (src/authoring.js) and the page all take their kind word and their Not-checked split from these.
|
|
4
4
|
// What this throws away: a Not checked item's own quotes round a whole rule and the reason "you judge it at Accept" (the group title says it).
|
|
5
5
|
|
|
6
|
+
import { tagOf } from './checkwords.js';
|
|
7
|
+
|
|
6
8
|
/** the group titles and the tail of the Not checked one (section 3.7, copied unchanged) */
|
|
7
9
|
export const LOOK = Object.freeze({
|
|
8
10
|
checked: 'CHECKED', notChecked: 'NOT CHECKED', notCheckedTail: 'you judge these at Accept', suggested: 'SUGGESTED · add if you want it', everyLine: 'Every line',
|
|
@@ -40,6 +42,6 @@ export function ncRowsOf(items, by = {}) {
|
|
|
40
42
|
const m = /^line (\d+): ([\s\S]*)$/.exec(raw);
|
|
41
43
|
const body = (m ? m[2] : raw).replace(/^not checked · /, '');
|
|
42
44
|
const tag = by[raw];
|
|
43
|
-
return { line: m ? Number(m[1]) : 0, ...splitNotChecked(body), ...(tag
|
|
45
|
+
return { line: m ? Number(m[1]) : 0, ...splitNotChecked(body), ...(tagOf(tag) !== '' ? { by: /** @type {'you'|'agent'|'default'} */ (tag) } : {}) };
|
|
44
46
|
});
|
|
45
47
|
}
|