fwdloop 0.37.0 → 0.39.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 +5 -19
- package/bin/fwdloop +51 -29
- package/package.json +1 -1
- package/src/ask.js +70 -148
- package/src/audit-fold.js +5 -4
- package/src/auditchecks.js +6 -4
- package/src/authoring.js +36 -64
- package/src/blockasks.js +2 -1
- package/src/blockassemble.js +7 -9
- package/src/blockdraft.js +2 -2
- package/src/blockpick.js +5 -5
- package/src/books.js +217 -12
- package/src/checkblock.js +25 -55
- package/src/checked.js +2 -3
- package/src/checklistsign.js +26 -5
- package/src/checklook.js +3 -1
- package/src/checkpick.js +5 -76
- 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 +22 -55
- package/src/diary.js +23 -1
- package/src/draft-steps.js +11 -1
- package/src/drafter.js +28 -23
- 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 +86 -0
- package/src/isrec.js +2 -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 +2 -3
- package/src/liveness.js +3 -0
- package/src/mcp-use.js +8 -9
- package/src/memo.js +13 -16
- package/src/minrule.js +16 -0
- package/src/model-step.js +3 -3
- 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 +121 -78
- 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 +125 -168
- package/src/panel/index.html +154 -63
- 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/planrebuild.js +19 -19
- package/src/primitives.js +1 -1
- package/src/provider.js +1 -1
- package/src/reasons.js +25 -0
- package/src/report.js +2 -1
- 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/sheet-record.js +1 -2
- package/src/sheetblock.js +3 -4
- package/src/sheetbuild.js +5 -5
- package/src/sheetchecks.js +1 -2
- package/src/sheetclaims.js +1 -2
- package/src/sheetoffer.js +1 -1
- package/src/sheetrun.js +5 -7
- package/src/summary-words.js +2 -1
- package/src/thinking.js +5 -2
- package/src/ticketrows.js +8 -30
- 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 +8 -42
- package/types/blockassemble.d.ts +0 -1
- package/types/blockpick.d.ts +1 -1
- package/types/books.d.ts +256 -4
- package/types/checkblock.d.ts +2 -25
- 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 +3 -2
- 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 +58 -0
- package/types/isrec.d.ts +1 -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/minrule.d.ts +6 -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 +36 -11
- 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/sheetclaims.d.ts +0 -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/README.md
CHANGED
|
@@ -57,27 +57,13 @@ last word, and how to make cost and outcome honest. It borrows those solved prob
|
|
|
57
57
|
primitives directly, as a sibling of the suite, and adds the part that was missing: the
|
|
58
58
|
pauses, the checks, and the people.
|
|
59
59
|
|
|
60
|
-
##
|
|
60
|
+
## bare suite
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
- **Hands** · [barebrowse](https://github.com/hamr0/barebrowse) · [baremobile](https://github.com/hamr0/baremobile) · [beeperbox](https://github.com/hamr0/beeperbox)
|
|
63
|
+
- **Rails** · [bareagent](https://github.com/hamr0/bareagent) · [bareguard](https://github.com/hamr0/bareguard) · [barebox](https://github.com/hamr0/barebox) · [litectx](https://github.com/hamr0/litectx)
|
|
64
|
+
- **Apps** · **fwdloop** · [bareloop](https://github.com/hamr0/bareloop)
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
- **[bareagent](https://npmjs.com/package/bare-agent)** — the think→act→observe loop. *Goal in → coordinated actions out.*
|
|
68
|
-
- **[bareguard](https://npmjs.com/package/bareguard)** — the single gate every action passes through. *Action in → allow / deny / ask-a-human out.*
|
|
69
|
-
- **[litectx](https://npmjs.com/package/litectx)** — memory and context engineering (write · select · compress · isolate). *Query in → ranked context out.*
|
|
70
|
-
|
|
71
|
-
**Optional reach** — give the agent hands.
|
|
72
|
-
|
|
73
|
-
- **[barebrowse](https://npmjs.com/package/barebrowse)** — a real browser for agents.
|
|
74
|
-
- **[baremobile](https://npmjs.com/package/baremobile)** — Android + iOS device control.
|
|
75
|
-
- **[beeperbox](https://github.com/hamr0/beeperbox)** — 50+ messaging networks via one MCP server.
|
|
76
|
-
|
|
77
|
-
**Siblings** — workflows on top of the rails.
|
|
78
|
-
|
|
79
|
-
- **[bareloop](https://github.com/hamr0/bareloop)** — workflows that earn their own design, for repeated, verifiable jobs. Closed loop.
|
|
80
|
-
- **fwdloop** — workflows with people in them. Open loop.
|
|
66
|
+
Built from [bareagent](https://github.com/hamr0/bareagent), [barebrowse](https://github.com/hamr0/barebrowse), [bareguard](https://github.com/hamr0/bareguard) and [litectx](https://github.com/hamr0/litectx). → [The whole suite](https://github.com/hamr0)
|
|
81
67
|
|
|
82
68
|
## Status
|
|
83
69
|
|
package/bin/fwdloop
CHANGED
|
@@ -22,13 +22,13 @@ import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
|
22
22
|
import { draftHoldUsd } from '../src/draftspend.js';
|
|
23
23
|
import { pathToFileURL } from 'node:url';
|
|
24
24
|
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
} from '../src/flow.js';
|
|
25
|
+
import { readPlan, readRunPlan, checkFlowName, resolveRunDir, listFlowNames, listRunIds, claimRunId } from '../src/flow.js';
|
|
26
|
+
import { readFileInside } from '../src/inside.js';
|
|
28
27
|
import { loadCatalogue } from '../src/catalogue.js';
|
|
29
28
|
import {
|
|
30
|
-
runFlow, resumeRun, continueRun, auditSpend, makeParkingAskStep, readAsk,
|
|
29
|
+
runFlow, resumeRun, continueRun, auditSpend, makeParkingAskStep, readAsk,
|
|
31
30
|
} from '../src/runner.js';
|
|
31
|
+
import { readRunState, consumedAnswerName } from '../src/books.js';
|
|
32
32
|
import { applyRunValues, pickRunValues, dropUnstartedValues, runModelOf } from '../src/runvalues.js';
|
|
33
33
|
import { TRIGGER_RECORD_FILE } from '../src/trigger-line.js';
|
|
34
34
|
import { makeLiveModelStep } from '../src/model-step.js';
|
|
@@ -39,24 +39,25 @@ import {
|
|
|
39
39
|
checkKeyPreflight, resolveUsableModel, pickTicked, readPriceConfig, ceilingCostUsd,
|
|
40
40
|
} from '../src/provider.js';
|
|
41
41
|
import { readModelRecord, readRunModel, LEARNINGS_FILE } from '../src/flowmodel.js';
|
|
42
|
-
import { readRunInputs } from '../src/runfile.js';
|
|
42
|
+
import { readRunInputs, INPUTS_DIR } from '../src/runfile.js';
|
|
43
43
|
import { configDoorHome, defaultFlowsRoot } from '../src/config.js';
|
|
44
44
|
import {
|
|
45
45
|
claimHold, settleHold, nameRunDir, monthlyRefusalText, ConfigError,
|
|
46
46
|
} from '../src/monthly.js';
|
|
47
47
|
import { keysForDoor } from '../src/keysfile.js';
|
|
48
48
|
import {
|
|
49
|
-
answerAsk, readAskEvidence, normalizeDecision, stripControl, withReopen,
|
|
49
|
+
answerAsk, readAskEvidence, normalizeDecision, stripControl, withReopen, readAskFile,
|
|
50
50
|
} from '../src/ask.js';
|
|
51
51
|
import { panelMain } from '../src/panel/server.js';
|
|
52
52
|
import { launcherMain } from '../src/launcher.js';
|
|
53
53
|
import { isInteractive, confirmTypedName, NEEDS_TTY } from '../src/sign-confirm.js';
|
|
54
|
-
import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal } from '../src/authoring.js';
|
|
54
|
+
import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal, readTargetName } from '../src/authoring.js';
|
|
55
|
+
import { minRuleRefusal } from '../src/minrule.js';
|
|
55
56
|
import { readRecordFile, readRowChoices, readSheetDropped, readShapeDropped, readColumns } from '../src/pickrecord.js';
|
|
56
57
|
import { userInfo } from 'node:os';
|
|
57
58
|
import { pageAddressesOf, pageAddressRefusal } from '../src/pagefetch.js';
|
|
58
59
|
import { ticketListsOf, isTicketNumber, TICKET_NUMBER_WORDS } from '../src/ticket-shape.js';
|
|
59
|
-
import { flowTypeOf } from '../src/declaration.js';
|
|
60
|
+
import { flowTypeOf, isFlowType } from '../src/declaration.js';
|
|
60
61
|
import { LOOK_TOOL } from '../src/ticket-draft.js';
|
|
61
62
|
import { newestUnrunTicket } from '../src/ticket-next.js';
|
|
62
63
|
|
|
@@ -110,9 +111,15 @@ function takeMonthlyHold({ what, flow, runId, runDir, holdUsd, spentAtHold = 0 }
|
|
|
110
111
|
});
|
|
111
112
|
} catch (err) {
|
|
112
113
|
if (!(err instanceof ConfigError)) throw err;
|
|
113
|
-
|
|
114
|
+
const words = `${err.message} — refusing to start rather than guess the monthly limit. Nothing spent.`;
|
|
115
|
+
if (what === 'draft') refuseDraft('capUsd', words, words);
|
|
116
|
+
fail(words);
|
|
117
|
+
}
|
|
118
|
+
if (!claim.ok) {
|
|
119
|
+
const words = monthlyRefusalText(claim.room);
|
|
120
|
+
if (what === 'draft') refuseDraft('capUsd', words, words);
|
|
121
|
+
fail(words);
|
|
114
122
|
}
|
|
115
|
-
if (!claim.ok) fail(monthlyRefusalText(claim.room));
|
|
116
123
|
let settled = false;
|
|
117
124
|
const settle = (why) => {
|
|
118
125
|
if (settled || claim.holdId === null) return;
|
|
@@ -142,6 +149,14 @@ function fail(message) {
|
|
|
142
149
|
process.exit(1);
|
|
143
150
|
}
|
|
144
151
|
|
|
152
|
+
// F262: the ONE writer of a draft refusal's typed record. `box` is named by the refusing check's own call site (job | capUsd | model | inputs | null), never read from words.
|
|
153
|
+
// The human line is printed first, unchanged; the record is the last line of the log, one JSON line (so words with a newline stay one line).
|
|
154
|
+
function refuseDraft(box, words, printed = `draft refused at $0 — ${words}`) {
|
|
155
|
+
process.stderr.write(`fwdloop: ${printed}\n`);
|
|
156
|
+
process.stderr.write(`fwdloop: refusal-record ${JSON.stringify({ box, words })}\n`);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
|
|
145
160
|
/**
|
|
146
161
|
* The ONE place a human-typed `--root` becomes a path (hamr ruling
|
|
147
162
|
* 2026-09-29): resolved to its real path once, at command start. Nothing
|
|
@@ -457,7 +472,7 @@ async function cmdRun(rest) {
|
|
|
457
472
|
// refusal (moved to `src/runner.js` so any caller — this CLI, M4's web
|
|
458
473
|
// panel — gets it for free); it also owns the ONLY `mkdirSync`/
|
|
459
474
|
// `freezeInputs` for this run dir, so a refusal leaves nothing behind.
|
|
460
|
-
const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir,
|
|
475
|
+
const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir, INPUTS_DIR, `${s.id}${extname(s.path)}`) }));
|
|
461
476
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
462
477
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, { runDir, inputs: predictedInputs, mcp: stepMcp(declaration) });
|
|
463
478
|
|
|
@@ -504,11 +519,12 @@ function cmdInbox(rest) {
|
|
|
504
519
|
const resolved = resolveRunDir(flowDir, runId);
|
|
505
520
|
if (!resolved.ok) continue; // eslint-disable-line no-continue
|
|
506
521
|
const runDir = resolved.runDir;
|
|
507
|
-
const askRead =
|
|
522
|
+
const askRead = readAskFile(runDir);
|
|
508
523
|
if (!askRead.ok) continue; // eslint-disable-line no-continue -- missing (or refused) ask.json: nothing to show
|
|
509
524
|
let ask;
|
|
510
525
|
try {
|
|
511
|
-
|
|
526
|
+
if (askRead.parseError !== null) throw new Error(askRead.parseError);
|
|
527
|
+
ask = withReopen(runDir, askRead.value); // the effective deadline (a reopened ask's new one)
|
|
512
528
|
} catch (err) {
|
|
513
529
|
// A malformed/unparseable ask.json must never crash inbox — show it
|
|
514
530
|
// naming the run as unreadable and move on to the next one.
|
|
@@ -531,7 +547,7 @@ function cmdInbox(rest) {
|
|
|
531
547
|
// Consumed-marker check also goes through `readFileInside` — a
|
|
532
548
|
// symlinked consumed marker is treated as "not consumed" (still shown
|
|
533
549
|
// as open/expired), never as proof the ask was answered.
|
|
534
|
-
if (readFileInside(runDir,
|
|
550
|
+
if (readFileInside(runDir, consumedAnswerName(ask.askId)).ok) continue; // eslint-disable-line no-continue -- this specific ask is already answered
|
|
535
551
|
// A present-but-unparseable expiresAt (Date.parse -> NaN) must never
|
|
536
552
|
// read as "not expired" — `Date.now() > NaN` is false, so the naive
|
|
537
553
|
// compare below would show this as [open] with a "NaNs left"
|
|
@@ -592,7 +608,7 @@ function cmdShow(rest) {
|
|
|
592
608
|
|
|
593
609
|
// F48 round 3: routed through `readFileInside` (`src/flow.js`) — a
|
|
594
610
|
// symlinked ask.json is refused by name here, never read through.
|
|
595
|
-
const askRead =
|
|
611
|
+
const askRead = readAskFile(runDir);
|
|
596
612
|
if (!askRead.ok) {
|
|
597
613
|
fail(askRead.missing
|
|
598
614
|
? `show: no ask.json for askId "${askId}"`
|
|
@@ -601,7 +617,8 @@ function cmdShow(rest) {
|
|
|
601
617
|
}
|
|
602
618
|
let ask;
|
|
603
619
|
try {
|
|
604
|
-
|
|
620
|
+
if (askRead.parseError !== null) throw new Error(askRead.parseError);
|
|
621
|
+
ask = withReopen(runDir, askRead.value); // the effective deadline (a reopened ask's new one)
|
|
605
622
|
} catch (err) {
|
|
606
623
|
fail(`show: ask.json for askId "${askId}" is not valid JSON — ${err.message}`);
|
|
607
624
|
return;
|
|
@@ -902,7 +919,7 @@ async function cmdDraft(rest) {
|
|
|
902
919
|
});
|
|
903
920
|
if (values.action !== undefined && !['check', 'known'].includes(values.action)) fail(`draft: --action takes check or known, got "${values.action}"`);
|
|
904
921
|
const flowType = values['flow-type'] ?? 'plain';
|
|
905
|
-
if (!
|
|
922
|
+
if (!isFlowType(flowType)) fail(`draft: --flow-type takes plain, mcp or tickets, got "${flowType}"`);
|
|
906
923
|
if (flowType === 'plain' && values.mcp !== undefined) fail('draft: --mcp goes with --flow-type mcp or tickets');
|
|
907
924
|
if (flowType !== 'plain' && !values.mcp) fail(`draft: --flow-type ${flowType} needs --mcp <server>`);
|
|
908
925
|
const keysLoad = keyedLoad();
|
|
@@ -959,15 +976,16 @@ async function cmdDraft(rest) {
|
|
|
959
976
|
if (configDoorHome().skip) fail(NO_CONFIG_HOME_REFUSAL);
|
|
960
977
|
try {
|
|
961
978
|
const p = pickTicked(readPriceConfig(), values);
|
|
962
|
-
if (!p.ok)
|
|
979
|
+
if (!p.ok) refuseDraft('model', p.say);
|
|
963
980
|
pick = { slot: p.slot, model: p.model };
|
|
964
981
|
} catch (err) {
|
|
965
982
|
if (!(err instanceof ConfigError)) throw err;
|
|
966
|
-
|
|
983
|
+
const words = `${err.message} — refusing to draft rather than guess the price. Nothing spent.`;
|
|
984
|
+
refuseDraft('model', words, words);
|
|
967
985
|
}
|
|
968
986
|
// The key preflight (draftToDir repeats it).
|
|
969
987
|
const refusal = draftKeyRefusal(pick.slot, env);
|
|
970
|
-
if (refusal !== null)
|
|
988
|
+
if (refusal !== null) refuseDraft('model', refusal);
|
|
971
989
|
} else if (values.model !== undefined) pick = { slot: values.provider, model: values.model };
|
|
972
990
|
// M4d piece 3: the monthly check — one ceiling round, priced from the
|
|
973
991
|
// picked model's own Settings prices (an injected test provider carries its own rates). A model that is not
|
|
@@ -978,13 +996,14 @@ async function cmdDraft(rest) {
|
|
|
978
996
|
if (!rates) {
|
|
979
997
|
if (configDoorHome().skip) fail(NO_CONFIG_HOME_REFUSAL);
|
|
980
998
|
const usable = resolveUsableModel(pick.slot, { config: readPriceConfig(), model: pick.model });
|
|
981
|
-
if (!usable.ok)
|
|
999
|
+
if (!usable.ok) refuseDraft('model', usable.say);
|
|
982
1000
|
rates = usable.rates;
|
|
983
1001
|
}
|
|
984
1002
|
ceiling = ceilingCostUsd(rates);
|
|
985
1003
|
} catch (err) {
|
|
986
1004
|
if (!(err instanceof ConfigError)) throw err;
|
|
987
|
-
|
|
1005
|
+
const words = `${err.message} — refusing to draft rather than guess the price. Nothing spent.`;
|
|
1006
|
+
refuseDraft('model', words, words);
|
|
988
1007
|
}
|
|
989
1008
|
// M4d am19 item 1: the hold is what is left of the cap (cap minus this job's drafting so far), the most the draft may spend, not one round
|
|
990
1009
|
// the ONE read of the prose file goes through the safe gateway (a symlink or an outside path is refused); draftToDir is handed this read
|
|
@@ -993,12 +1012,19 @@ async function cmdDraft(rest) {
|
|
|
993
1012
|
const proseRead = gate.ok
|
|
994
1013
|
? (gate.text.trim() === '' ? { ok: false, red: `prose: "${proseAbs}" is empty` } : gate)
|
|
995
1014
|
: { ok: false, red: gate.missing ? `prose: cannot read "${proseAbs}": ENOENT` : `prose: ${gate.red}` };
|
|
1015
|
+
// M19 am13: a job with no `~` rule of the person's is refused here, at $0, before the hold, the draft folder or any provider call (the panel's Start drafting spawns this command and shows these words)
|
|
1016
|
+
if (proseRead.ok) {
|
|
1017
|
+
const noRule = minRuleRefusal(proseRead.text);
|
|
1018
|
+
if (noRule !== null) refuseDraft('job', noRule);
|
|
1019
|
+
}
|
|
996
1020
|
const hold = takeMonthlyHold({
|
|
997
1021
|
what: 'draft', flow: values.name, runId: null, runDir: resolve(values.out), holdUsd: draftHoldUsd(proseRead.ok ? proseRead.text : '', resolve(values.out), ceiling),
|
|
998
1022
|
});
|
|
999
1023
|
const result = await draftToDir({
|
|
1000
1024
|
// M4d am32: the hold is given back when the draft's result is written, not when this process exits (the exit hook stays as the backstop)
|
|
1001
1025
|
onResult: ({ ok }) => hold.settle(ok ? 'ended or parked' : 'ended (red)'),
|
|
1026
|
+
// M20 am1 item 5: the step lines go to the log like `refusal-record` does (the panel reads child.log)
|
|
1027
|
+
onStepLine: (kind, rec) => process.stderr.write(`fwdloop: ${kind} ${JSON.stringify(rec)}\n`),
|
|
1002
1028
|
proseFile: resolve(proseFile),
|
|
1003
1029
|
proseRead,
|
|
1004
1030
|
dir: resolve(values.out),
|
|
@@ -1024,9 +1050,7 @@ async function cmdDraft(rest) {
|
|
|
1024
1050
|
});
|
|
1025
1051
|
const cost = result.costUsd === null ? 'UNKNOWN' : costText(Number(result.costUsd), result.spendComplete);
|
|
1026
1052
|
if (!result.wrote) {
|
|
1027
|
-
|
|
1028
|
-
process.exitCode = 1;
|
|
1029
|
-
return;
|
|
1053
|
+
refuseDraft(result.box ?? null, result.reds.join('; '));
|
|
1030
1054
|
}
|
|
1031
1055
|
process.stdout.write(`draft dir: ${resolve(values.out)} cost: ${cost}\n`);
|
|
1032
1056
|
// M10 piece 3: a draft that stopped to ask what the page look raised is not red: it waits for the person's answers (the panel takes them)
|
|
@@ -1058,10 +1082,8 @@ async function cmdSign(rest) {
|
|
|
1058
1082
|
// Amendment 2: a person at a keyboard. TTY check first (cheapest), then the typed flow name; only then
|
|
1059
1083
|
// signDraft's own $0 checks (hash, wired, goals, TTL, sources, send, leak). signDraft writes only on success.
|
|
1060
1084
|
if (!isInteractive()) fail(`sign refused — ${NEEDS_TTY}`);
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
try { flowName = tj.ok ? JSON.parse(tj.text).name : undefined; } catch { flowName = undefined; }
|
|
1064
|
-
if (typeof flowName !== 'string' || flowName === '') fail('sign refused — the draft has no readable target.json name');
|
|
1085
|
+
const flowName = readTargetName(resolve(dir));
|
|
1086
|
+
if (flowName === null) fail('sign refused — the draft has no readable target.json name');
|
|
1065
1087
|
const typed = await confirmTypedName({ name: flowName });
|
|
1066
1088
|
if (!typed.ok) fail(`sign refused — ${typed.red}`);
|
|
1067
1089
|
const result = signDraft({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/ask.js
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// polls for `answer.json` (`{ decision: accept|redo|rerun, reason?,
|
|
5
|
-
// answeredAt }`). Consumed exactly once (renamed away on read); a stale
|
|
6
|
-
// answer — `answeredAt` older than THIS ask's `askedAt` — is quarantined
|
|
7
|
-
// (renamed to `answer.stale.<n>.json`, audited `stale-answer-ignored`) and
|
|
8
|
-
// never applied; a timeout returns `{ decision: 'timeout' }`, which
|
|
9
|
-
// `src/runner.js` must treat as a halt (a pause spends nothing).
|
|
10
|
-
//
|
|
11
|
-
// borrowed-from: fwdloop poc/m0/runner.mjs@76a3607 (`checkpointAsk`'s file
|
|
12
|
-
// protocol: `ask.json` out / poll `answer.json`, and the "ASK OPEN" stderr
|
|
13
|
-
// line so a human watching knows a run is waiting on them) and
|
|
14
|
-
// fwdloop poc/m0/answer.mjs@76a3607 (the answer file's own shape). Rewritten
|
|
15
|
-
// off bare-agent's `Checkpoint` (M0's dependency) onto a plain poll loop —
|
|
16
|
-
// M2's signed scope (item 6) calls for "M0's file checkpoint, in-process",
|
|
17
|
-
// not a second Checkpoint instance layered on top of the same file protocol.
|
|
1
|
+
// The ask's files and rules: the answer door (`answerAsk`), the reopen record, the archive of asked questions, the
|
|
2
|
+
// one evidence reader, and the one decision table. (M2 piece 2's in-process file-checkpoint step was removed by M20 am3
|
|
3
|
+
// item 5: the runner parks an ask and the Resume path reads the answer.)
|
|
18
4
|
|
|
19
5
|
import {
|
|
20
|
-
existsSync, linkSync, mkdirSync,
|
|
6
|
+
existsSync, linkSync, mkdirSync, unlinkSync, writeFileSync,
|
|
21
7
|
} from 'node:fs';
|
|
22
8
|
import { join } from 'node:path';
|
|
23
|
-
import { createHash
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
24
10
|
|
|
25
|
-
import { appendAudit } from './books.js';
|
|
26
|
-
import { readFileInside, resolveInside, readdirInside } from './
|
|
11
|
+
import { appendAudit, consumedAnswerName, readSavedAnswer } from './books.js';
|
|
12
|
+
import { readFileInside, resolveInside, readdirInside } from './inside.js';
|
|
27
13
|
|
|
28
14
|
/**
|
|
29
15
|
* M4c amendment 3: the ONE rule for "was this answer saved in time" — the
|
|
@@ -66,6 +52,11 @@ export function stripControl(text) {
|
|
|
66
52
|
return String(text).replace(/[\x00-\x08\x0B-\x1F\x7F-\x9F]/g, '');
|
|
67
53
|
}
|
|
68
54
|
|
|
55
|
+
/** M20 am8a: the decisions that need a reason, as a list (the panel hands it to the page, which asks it instead of spelling them) */
|
|
56
|
+
export const REASON_DECISIONS = Object.freeze(['redo', 'rerun']);
|
|
57
|
+
/** M20 am8: the one question "does this decision need a reason" (a redo or a rerun; an accept does not): the answer door and the runner's re-check of a saved answer ask it @param {unknown} decision @returns {boolean} */
|
|
58
|
+
export const needsReason = (decision) => REASON_DECISIONS.includes(/** @type {string} */ (decision));
|
|
59
|
+
|
|
69
60
|
/** The one decision -> status table, used by `listArchivedAsks` here and by the panel's legacy-ask rows.
|
|
70
61
|
* Look it up with `normalizeDecision(decision)`. */
|
|
71
62
|
export const DECISION_STATUS = { accept: 'accepted', redo: 'redo', rerun: 'reran' };
|
|
@@ -77,96 +68,6 @@ export function decisionStatus(decision) {
|
|
|
77
68
|
return typeof word === 'string' && Object.hasOwn(DECISION_STATUS, word) ? DECISION_STATUS[word] : undefined;
|
|
78
69
|
}
|
|
79
70
|
|
|
80
|
-
function sleep(ms) {
|
|
81
|
-
return new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function safeStamp(iso) {
|
|
85
|
-
return String(iso).replace(/[^0-9A-Za-z]/g, '-');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @param {{ timeoutMs?: number, pollMs?: number, clock?: () => string, writeLine?: (line:string) => void }} [opts]
|
|
90
|
-
* @returns {(opts:{question:string, evidence:unknown, runDir:string, ttlMs?: number}) => Promise<{decision:string, reason?:string}>}
|
|
91
|
-
*/
|
|
92
|
-
export function makeFileAskStep({
|
|
93
|
-
timeoutMs = 120_000,
|
|
94
|
-
pollMs = 500,
|
|
95
|
-
clock = () => new Date().toISOString(),
|
|
96
|
-
writeLine = (line) => { process.stderr.write(`${line}\n`); },
|
|
97
|
-
} = {}) {
|
|
98
|
-
let attemptCounter = 0;
|
|
99
|
-
|
|
100
|
-
return async function fileAskStep({
|
|
101
|
-
question, evidence, runDir, ttlMs,
|
|
102
|
-
}) {
|
|
103
|
-
attemptCounter += 1;
|
|
104
|
-
const attempt = attemptCounter;
|
|
105
|
-
|
|
106
|
-
// M3 scope item 1 (fixes F43): a signed `ttlMs` threaded in by the
|
|
107
|
-
// runner always governs — this constructor's own `timeoutMs` is only
|
|
108
|
-
// ever the fallback for a DIRECT call that carries no signed ttl (e.g.
|
|
109
|
-
// this module's own unit tests). No code default overrides a signed
|
|
110
|
-
// value.
|
|
111
|
-
const effectiveTimeoutMs = typeof ttlMs === 'number' ? ttlMs : timeoutMs;
|
|
112
|
-
|
|
113
|
-
mkdirSync(runDir, { recursive: true });
|
|
114
|
-
const askPath = join(runDir, 'ask.json');
|
|
115
|
-
const answerPath = join(runDir, 'answer.json');
|
|
116
|
-
const askedAt = clock();
|
|
117
|
-
const askId = randomUUID();
|
|
118
|
-
const expiresAt = new Date(Date.parse(askedAt) + effectiveTimeoutMs).toISOString();
|
|
119
|
-
|
|
120
|
-
writeFileSync(askPath, JSON.stringify({
|
|
121
|
-
askId, question, evidence, askedAt, expiresAt, attempt,
|
|
122
|
-
}, null, 2));
|
|
123
|
-
writeLine(`ASK OPEN (expires in ${Math.round(effectiveTimeoutMs / 1000)}s): ${question} — answer by writing ${answerPath}`);
|
|
124
|
-
|
|
125
|
-
const deadline = Date.now() + effectiveTimeoutMs;
|
|
126
|
-
let staleCount = 0;
|
|
127
|
-
|
|
128
|
-
for (;;) {
|
|
129
|
-
// F48 round 3: `answer.json` is checked with `resolveInside`
|
|
130
|
-
// (`src/flow.js`) before it is ever read — a symlinked answer file (or
|
|
131
|
-
// a symlinked run-dir ancestor) is treated exactly like "no answer
|
|
132
|
-
// yet" (kept polling), never read through to an outside file's
|
|
133
|
-
// content standing in for the human's real decision.
|
|
134
|
-
const answerResolved = resolveInside(runDir, 'answer.json');
|
|
135
|
-
if (answerResolved.ok) {
|
|
136
|
-
let raw = null;
|
|
137
|
-
try { raw = readFileSync(answerPath, 'utf8'); } catch { raw = null; }
|
|
138
|
-
let parsed = null;
|
|
139
|
-
if (raw !== null) { try { parsed = JSON.parse(raw); } catch { parsed = null; } }
|
|
140
|
-
|
|
141
|
-
if (parsed) {
|
|
142
|
-
const { answeredAt } = parsed;
|
|
143
|
-
const isStale = typeof answeredAt === 'string' && typeof askedAt === 'string' && answeredAt < askedAt;
|
|
144
|
-
if (isStale) {
|
|
145
|
-
staleCount += 1;
|
|
146
|
-
let staleName = join(runDir, `answer.stale.${staleCount}.json`);
|
|
147
|
-
while (existsSync(staleName)) { staleCount += 1; staleName = join(runDir, `answer.stale.${staleCount}.json`); }
|
|
148
|
-
renameSync(answerPath, staleName);
|
|
149
|
-
appendAudit(runDir, {
|
|
150
|
-
step: 'ask', attempt, class: null, verdict: 'stale-answer-ignored', gap: `answeredAt ${answeredAt} predates this ask's askedAt ${askedAt}`, usd: 0, spendComplete: true, wallMs: 0, model: null, modelMatch: null, strike: false, at: clock(), tokens: null, tools: null, refused: [],
|
|
151
|
-
});
|
|
152
|
-
// Keep polling — a stale file quarantined does not mean THIS
|
|
153
|
-
// ask has been answered.
|
|
154
|
-
} else {
|
|
155
|
-
renameSync(answerPath, join(runDir, `answer.${safeStamp(askedAt)}.consumed.json`));
|
|
156
|
-
return { decision: normalizeDecision(parsed.decision), reason: parsed.reason, artifactSha256: parsed.artifactSha256 };
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (Date.now() >= deadline) {
|
|
162
|
-
return { decision: 'timeout' };
|
|
163
|
-
}
|
|
164
|
-
// eslint-disable-next-line no-await-in-loop
|
|
165
|
-
await sleep(pollMs);
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
71
|
// ---------------------------------------------------------------------------
|
|
171
72
|
// F47 fix (docs/logs/FINDINGS.md F47, M4a ladder item 1): the ONE shared
|
|
172
73
|
// reader for ask.json's `evidence` field, across every real shape on disk —
|
|
@@ -311,15 +212,14 @@ export function sha256Hex(serialised) {
|
|
|
311
212
|
* M4c-fix amendment 1 (a): why a saved `answer.json` is not a usable answer for the open ask `openAskId`, or `null`
|
|
312
213
|
* when it is usable. The resume refuses each of these by name before it consumes the file, so without a way aside
|
|
313
214
|
* the file would block every new answer (`answerAsk`'s exclusive create).
|
|
314
|
-
* @param {
|
|
215
|
+
* @param {Extract<ReturnType<typeof readSavedAnswer>, {ok: true}>} saved `readSavedAnswer`'s result (the one reader of the file) @param {string} openAskId
|
|
315
216
|
* @returns {string|null}
|
|
316
217
|
*/
|
|
317
|
-
export function brokenAnswerWhy(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
if (
|
|
322
|
-
if (Number.isNaN(Date.parse(typeof a.answeredAt === 'string' ? a.answeredAt : ''))) return 'it carries no readable saved time';
|
|
218
|
+
export function brokenAnswerWhy(saved, openAskId) {
|
|
219
|
+
if (saved.parseError !== null) return 'it is not valid JSON';
|
|
220
|
+
if (!saved.isObject) return 'it is not a JSON object';
|
|
221
|
+
if (saved.value.askId !== openAskId) return `it names another ask ("${saved.value.askId}")`;
|
|
222
|
+
if (saved.broken) return 'it carries no readable saved time';
|
|
323
223
|
return null;
|
|
324
224
|
}
|
|
325
225
|
|
|
@@ -380,6 +280,20 @@ export function effectiveExpiresAt(runDir, askId, original) {
|
|
|
380
280
|
return best ? best.expiresAt : original;
|
|
381
281
|
}
|
|
382
282
|
|
|
283
|
+
/**
|
|
284
|
+
* M20 am3e item 15: the ONE reader of a run's `ask.json`, as found, through the safe gateway: `{ok: false, missing, red}` when the gateway gives nothing (missing, a symlink,
|
|
285
|
+
* outside the folder), else `{ok: true, value, parseError}`: `value` is the parsed JSON as it is (any shape), `parseError` the parser's message when the text is not JSON
|
|
286
|
+
* (`value` is then undefined). It applies nothing: each caller keeps its own refusal words and its own `withReopen` step (`readAsk` in src/runner.js is this plus
|
|
287
|
+
* `withReopen`, null on any trouble).
|
|
288
|
+
* @param {string} runDir
|
|
289
|
+
* @returns {{ok: false, missing: boolean, red?: string}|{ok: true, value: any, parseError: string|null}}
|
|
290
|
+
*/
|
|
291
|
+
export function readAskFile(runDir) {
|
|
292
|
+
const r = readFileInside(runDir, 'ask.json');
|
|
293
|
+
if (!r.ok) return r;
|
|
294
|
+
try { return { ok: true, value: JSON.parse(r.text), parseError: null }; } catch (err) { return { ok: true, value: undefined, parseError: /** @type {any} */ (err).message }; }
|
|
295
|
+
}
|
|
296
|
+
|
|
383
297
|
/**
|
|
384
298
|
* An `ask.json`-shaped object as every reader should see it: `expiresAt` is the effective deadline, and `waitMs`
|
|
385
299
|
* is the signed wait the ask was parked with (its own `expiresAt` minus `askedAt`, written from the signed ttl),
|
|
@@ -414,22 +328,21 @@ export function reopenAsk({
|
|
|
414
328
|
if (typeof runDir !== 'string' || runDir.length === 0) return { ok: false, red: 'reopenAsk: "runDir" must be a non-empty string' };
|
|
415
329
|
if (typeof askId !== 'string' || askId.length === 0) return { ok: false, red: 'reopenAsk: "askId" must be a non-empty string' };
|
|
416
330
|
if (typeof by !== 'string' || by.length === 0) return { ok: false, red: 'reopenAsk: "by" must name who reopened it' };
|
|
417
|
-
const askRead =
|
|
331
|
+
const askRead = readAskFile(runDir);
|
|
418
332
|
if (!askRead.ok) return { ok: false, red: `reopenAsk: no open ask for run ${runDir}` };
|
|
419
|
-
|
|
420
|
-
|
|
333
|
+
if (askRead.parseError !== null) return { ok: false, red: `reopenAsk: ask.json for run ${runDir} is not valid JSON — ${askRead.parseError}` };
|
|
334
|
+
const raw = askRead.value;
|
|
421
335
|
if (raw === null || typeof raw !== 'object' || raw.askId !== askId) return { ok: false, red: `reopenAsk: askId "${askId}" is unknown for run ${runDir}` };
|
|
422
336
|
const ask = withReopen(runDir, raw);
|
|
423
337
|
if (Number.isNaN(Date.parse(ask.expiresAt))) return { ok: false, red: `reopenAsk: askId "${askId}" has an unparseable expiresAt — refusing` };
|
|
424
338
|
if (ask.waitMs === null) return { ok: false, red: `reopenAsk: askId "${askId}" carries no readable wait (askedAt/expiresAt) to repeat — refusing` };
|
|
425
|
-
if (existsSync(join(runDir,
|
|
339
|
+
if (existsSync(join(runDir, consumedAnswerName(askId)))) return { ok: false, red: `reopenAsk: askId "${askId}" already answered for run ${runDir}` };
|
|
426
340
|
if (Date.parse(nowIso) <= Date.parse(ask.expiresAt)) return { ok: false, red: `reopenAsk: askId "${askId}" has not expired (it runs until ${ask.expiresAt})` };
|
|
427
|
-
const saved =
|
|
341
|
+
const saved = readSavedAnswer(runDir);
|
|
428
342
|
let timing = null;
|
|
429
343
|
if (saved.ok) {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
timing = a !== null && typeof a === 'object' && a.askId === askId ? answerTiming(a.answeredAt, ask.expiresAt) : 'unreadable';
|
|
344
|
+
// a broken answer, or one for another ask, is set aside below
|
|
345
|
+
timing = !saved.broken && saved.askId === askId ? answerTiming(saved.answeredAt, ask.expiresAt) : 'unreadable';
|
|
433
346
|
if (timing === 'on-time') return { ok: false, red: `reopenAsk: askId "${askId}" has an answer saved in time — resume it, it is not expired` };
|
|
434
347
|
}
|
|
435
348
|
// Amendment 3 (b): the stale answer is moved aside FIRST. If that fails nothing is written (no record, no audit
|
|
@@ -492,19 +405,17 @@ export function answerAsk({
|
|
|
492
405
|
// F48 round 3: routed through `readFileInside` — a symlinked `ask.json`
|
|
493
406
|
// (or a symlinked run-dir ancestor) reads as "no open ask", never as some
|
|
494
407
|
// outside file's content.
|
|
495
|
-
const askRead =
|
|
408
|
+
const askRead = readAskFile(runDir);
|
|
496
409
|
if (!askRead.ok) {
|
|
497
410
|
if (askRead.missing) {
|
|
498
411
|
return { ok: false, red: `answerAsk: no open ask for run ${runDir}` };
|
|
499
412
|
}
|
|
500
413
|
return { ok: false, red: `answerAsk: ask.json for run ${runDir} — ${askRead.red}` };
|
|
501
414
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
ask = JSON.parse(askRead.text);
|
|
505
|
-
} catch (err) {
|
|
506
|
-
return { ok: false, red: `answerAsk: ask.json for run ${runDir} is not valid JSON — ${err.message}` };
|
|
415
|
+
if (askRead.parseError !== null) {
|
|
416
|
+
return { ok: false, red: `answerAsk: ask.json for run ${runDir} is not valid JSON — ${askRead.parseError}` };
|
|
507
417
|
}
|
|
418
|
+
const ask = askRead.value;
|
|
508
419
|
if (ask.askId !== askId) {
|
|
509
420
|
return { ok: false, red: `answerAsk: askId "${askId}" is unknown for run ${runDir}` };
|
|
510
421
|
}
|
|
@@ -532,12 +443,12 @@ export function answerAsk({
|
|
|
532
443
|
// A consumed marker survives long after the run has moved on (or ended) —
|
|
533
444
|
// it must still refuse a second answer naming the SAME askId, never only
|
|
534
445
|
// while answer.json happens to still be sitting there.
|
|
535
|
-
if (existsSync(join(runDir,
|
|
446
|
+
if (existsSync(join(runDir, consumedAnswerName(askId)))) {
|
|
536
447
|
return { ok: false, red: `answerAsk: askId "${askId}" already answered for run ${runDir}` };
|
|
537
448
|
}
|
|
538
449
|
|
|
539
450
|
const trimmedReason = typeof reason === 'string' ? reason.trim() : '';
|
|
540
|
-
if ((decision
|
|
451
|
+
if (needsReason(decision) && trimmedReason.length === 0) {
|
|
541
452
|
return { ok: false, red: `answerAsk: askId "${askId}" needs a non-blank reason to ${decision}` };
|
|
542
453
|
}
|
|
543
454
|
|
|
@@ -566,9 +477,9 @@ export function answerAsk({
|
|
|
566
477
|
// M4c-fix amendment 1 (a): a saved answer that is broken (not JSON, not an object, names another ask, no readable
|
|
567
478
|
// time) would block this write for good — it is moved aside as a record first (never deleted). Only a broken one.
|
|
568
479
|
let setAside = null;
|
|
569
|
-
const savedRead =
|
|
480
|
+
const savedRead = readSavedAnswer(runDir);
|
|
570
481
|
if (savedRead.ok) {
|
|
571
|
-
const why = brokenAnswerWhy(savedRead
|
|
482
|
+
const why = brokenAnswerWhy(savedRead, askId);
|
|
572
483
|
if (why !== null) {
|
|
573
484
|
const moved = setAsideAnswer(runDir, askId, 'broken');
|
|
574
485
|
if (!moved.ok) return { ok: false, red: `answerAsk: askId "${askId}" — a broken saved answer (${why}) is in the way — ${moved.red}` };
|
|
@@ -655,6 +566,18 @@ export function writeAskArchive({
|
|
|
655
566
|
return { ok: true };
|
|
656
567
|
}
|
|
657
568
|
|
|
569
|
+
/**
|
|
570
|
+
* The one parse of an archived ask, `asks/<entry>` (entry = `<askId>.json`), through the safe gateway. `unreadable` keeps the gateway's own result in `read`
|
|
571
|
+
* (missing, a symlink, outside the folder); `invalid` is text that is not JSON, with the parser's message. The callers decide what a failure means.
|
|
572
|
+
* @param {string} runDir @param {string} entry
|
|
573
|
+
* @returns {{ok: true, ask: any}|{ok: false, code: 'unreadable', read: any}|{ok: false, code: 'invalid', message: string}}
|
|
574
|
+
*/
|
|
575
|
+
function readArchivedAsk(runDir, entry) {
|
|
576
|
+
const read = readFileInside(runDir, join('asks', entry));
|
|
577
|
+
if (!read.ok) return { ok: false, code: 'unreadable', read };
|
|
578
|
+
try { return { ok: true, ask: JSON.parse(read.text) }; } catch (err) { return { ok: false, code: 'invalid', message: err.message }; }
|
|
579
|
+
}
|
|
580
|
+
|
|
658
581
|
/**
|
|
659
582
|
* M4b amendment 2: for each archived ask that carries `emits`, joins it BY
|
|
660
583
|
* askId to its consumed answer and returns the recorded `artifactSha256` of
|
|
@@ -674,12 +597,11 @@ export function readAcceptedHashesByEmits(runDir) {
|
|
|
674
597
|
for (const entry of readdirInside(runDir, 'asks').sort()) {
|
|
675
598
|
if (!entry.endsWith('.json')) continue; // eslint-disable-line no-continue
|
|
676
599
|
const askId = entry.slice(0, -'.json'.length);
|
|
677
|
-
const
|
|
678
|
-
if (!
|
|
679
|
-
|
|
680
|
-
try { emits = JSON.parse(archiveRead.text)?.emits; } catch { continue; } // eslint-disable-line no-continue
|
|
600
|
+
const archived = readArchivedAsk(runDir, entry);
|
|
601
|
+
if (!archived.ok) continue; // eslint-disable-line no-continue
|
|
602
|
+
const emits = archived.ask?.emits;
|
|
681
603
|
if (typeof emits !== 'string' || emits.length === 0) continue; // eslint-disable-line no-continue
|
|
682
|
-
const markerRead = readFileInside(runDir,
|
|
604
|
+
const markerRead = readFileInside(runDir, consumedAnswerName(askId));
|
|
683
605
|
if (!markerRead.ok) continue; // eslint-disable-line no-continue
|
|
684
606
|
let marker;
|
|
685
607
|
try { marker = JSON.parse(markerRead.text); } catch { continue; } // eslint-disable-line no-continue
|
|
@@ -730,9 +652,10 @@ export function listArchivedAsks(runDir) {
|
|
|
730
652
|
if (!entry.endsWith('.json')) continue; // eslint-disable-line no-continue
|
|
731
653
|
const askId = entry.slice(0, -'.json'.length);
|
|
732
654
|
const archivePath = join(runDir, 'asks', entry);
|
|
733
|
-
const
|
|
655
|
+
const archived = readArchivedAsk(runDir, entry);
|
|
734
656
|
let ask;
|
|
735
|
-
if (!
|
|
657
|
+
if (!archived.ok && archived.code === 'unreadable') {
|
|
658
|
+
const archiveRead = archived.read;
|
|
736
659
|
asks.push({
|
|
737
660
|
askId, question: undefined, askedAt: undefined, expiresAt: undefined,
|
|
738
661
|
evidence: {
|
|
@@ -746,18 +669,17 @@ export function listArchivedAsks(runDir) {
|
|
|
746
669
|
});
|
|
747
670
|
continue; // eslint-disable-line no-continue
|
|
748
671
|
}
|
|
749
|
-
|
|
750
|
-
ask = JSON.parse(archiveRead.text);
|
|
751
|
-
} catch (err) {
|
|
672
|
+
if (!archived.ok) {
|
|
752
673
|
asks.push({
|
|
753
674
|
askId, question: undefined, askedAt: undefined, expiresAt: undefined,
|
|
754
|
-
evidence: { draft: null, unjudged: [], why: `${archivePath} is not valid JSON — ${
|
|
675
|
+
evidence: { draft: null, unjudged: [], why: `${archivePath} is not valid JSON — ${archived.message}` },
|
|
755
676
|
answer: { status: 'open' },
|
|
756
677
|
});
|
|
757
678
|
continue; // eslint-disable-line no-continue
|
|
758
679
|
}
|
|
680
|
+
ask = archived.ask;
|
|
759
681
|
|
|
760
|
-
const consumedRelPath =
|
|
682
|
+
const consumedRelPath = consumedAnswerName(askId);
|
|
761
683
|
const consumedRead = readFileInside(runDir, consumedRelPath);
|
|
762
684
|
let answer = { status: 'open' };
|
|
763
685
|
if (consumedRead.ok) {
|
package/src/audit-fold.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// M4d am29 items 4-8: the Audit step fold, the Run summary's two lines and the step card's one line, all derived HERE from the run's files on disk
|
|
2
2
|
// (audit.jsonl's try rows + the three diaries in src/diary.js). Nothing here calls a model ($0 replay), and the page only draws what this returns,
|
|
3
3
|
// so the Audit rows, the summary and the cards can only agree. A run from before am29 has no diaries: no fold, `—` on the new lines, nothing made up.
|
|
4
|
-
import { readCalls, readTools, readChecks } from './diary.js';
|
|
4
|
+
import { readCalls, readTools, readChecks, newestChecksOf } from './diary.js';
|
|
5
|
+
import { isStopNote, isHumanNo } from './books.js';
|
|
5
6
|
|
|
6
7
|
/** A Stop's notes are not tries: the asked/not-honoured rows, and a `stopped` row that cut no try (no attempt number). @param {any} r */
|
|
7
8
|
export function isTryRow(r) {
|
|
8
|
-
return r.verdict
|
|
9
|
+
return !isStopNote(r.verdict) && !(r.verdict === 'stopped' && !Number.isInteger(r.attempt));
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
/** @param {string} runDir */
|
|
@@ -95,7 +96,7 @@ export function deriveFold(group, d, info = {}) {
|
|
|
95
96
|
tries.push(open);
|
|
96
97
|
}
|
|
97
98
|
open.answer = humanWords(r);
|
|
98
|
-
open.mark = r.verdict === 'green' ? '✓' : (r.verdict
|
|
99
|
+
open.mark = r.verdict === 'green' ? '✓' : (isHumanNo(r.verdict) ? '✗' : '·');
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
for (const r of group.rows) {
|
|
@@ -138,7 +139,7 @@ export function deriveFold(group, d, info = {}) {
|
|
|
138
139
|
const tally = {};
|
|
139
140
|
for (const t of tools) tally[t.tool] = (tally[t.tool] ?? 0) + 1;
|
|
140
141
|
const tallyWords = Object.entries(tally).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([k, v]) => `${k} ${v}`).join(', ');
|
|
141
|
-
const lastChecks = checkRows
|
|
142
|
+
const lastChecks = newestChecksOf(checkRows, step)?.checks ?? null;
|
|
142
143
|
const answered = human ? group.rows.filter((r) => r.verdict !== 'paused' && isTryRow(r) && humanWords(r) !== null) : [];
|
|
143
144
|
const lastAnswerRow = answered.length ? answered[answered.length - 1] : null;
|
|
144
145
|
return {
|