fwdloop 0.34.0 → 0.35.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 +14 -0
- package/bin/fwdloop +4 -0
- package/package.json +1 -1
- package/src/action-line.js +100 -0
- package/src/action-stop.js +44 -0
- package/src/ask.js +9 -2
- package/src/authoring.js +24 -11
- package/src/checkblock.js +7 -2
- package/src/checked.js +7 -2
- package/src/checklist.js +0 -2
- package/src/declaration.js +11 -28
- package/src/drafter.js +132 -81
- package/src/jobkey.js +2 -3
- package/src/pageask.js +19 -1
- package/src/pagemap.js +8 -2
- package/src/panel/author.js +62 -35
- package/src/panel/authorcard.js +2 -9
- package/src/panel/data.js +5 -1
- package/src/panel/index.html +59 -36
- package/src/runner.js +87 -41
- package/src/runvalues.js +9 -1
- package/src/setup.js +2 -0
- package/src/sheetbuild.js +4 -7
- package/src/sheetlook.js +1 -1
- package/src/signed-text.js +1 -5
- package/src/whole-job.js +27 -11
- package/types/action-line.d.ts +71 -0
- package/types/action-stop.d.ts +36 -0
- package/types/ask.d.ts +3 -2
- package/types/authoring.d.ts +5 -2
- package/types/checkblock.d.ts +1 -0
- package/types/checked.d.ts +2 -0
- package/types/checklist.d.ts +0 -2
- package/types/drafter.d.ts +9 -2
- package/types/pageask.d.ts +12 -1
- package/types/panel/author.d.ts +1 -1
- package/types/panel/data.d.ts +1 -1
- package/types/panel/jobgrid.d.ts +1 -1
- package/types/sheetbuild.d.ts +1 -3
- package/types/whole-job.d.ts +3 -3
- package/src/added-end.js +0 -60
- package/types/added-end.d.ts +0 -62
package/README.md
CHANGED
|
@@ -28,6 +28,20 @@ change.
|
|
|
28
28
|
It is built mainly for that shape of work: gather, decide, pause, hand off, continue. Not a
|
|
29
29
|
general agent. Not a chat bot. A workflow that a person can read, approve, rerun, and edit.
|
|
30
30
|
|
|
31
|
+
## The machine that makes machines
|
|
32
|
+
|
|
33
|
+
Like a CNC machine, fwdloop builds the thing that does the work, then lets a gauge it can't touch decide if the work is good, and stops for you where you said. Trust needs four things. Miss one and trust is zero. fwdloop has all four.
|
|
34
|
+
|
|
35
|
+
**Intent.** You write the job as plain numbered lines, and `~` rules under each say what success means. Every rule gets a check or a written reason why not. You sign before a dollar is spent.
|
|
36
|
+
|
|
37
|
+
**Guide rails, not just guardrails.** Guardrails stop the agent going off the road: a money cap per run, a monthly limit, a time limit on every Ask, and a send destination you signed that it can't move. Nothing leaves the machine without that signed destination and your accept in the same run. Guide rails keep it on the road: each new try hears what earlier tries in the run did; lessons from past runs go to the drafter and to retries; a rule it can't settle comes back as a question with buttons (Agree, Drop it, or your own words), not a guess.
|
|
38
|
+
|
|
39
|
+
**Verification.** The check sits outside the agent's loop: code decides, built on bareguard. Anything code can't check is listed as Not checked, and you judge it at the Ask. A red step goes back with the real gap to be fixed, up to four tries a step; the same miss twice stops it.
|
|
40
|
+
|
|
41
|
+
**Evidence.** Every try, its cost and its check result is recorded, and the books balance to the cent. You can read it all in the Audit tab, including exactly what each try was told. Page facts are quoted from a saved copy of the page.
|
|
42
|
+
|
|
43
|
+
The one difference from a lights-out machine: a person stands at the gate. The run parks at your Ask, spending nothing, and only after your accept does it act on the world.
|
|
44
|
+
|
|
31
45
|
## See it
|
|
32
46
|
|
|
33
47
|
A real past run: a job that reads a public flights page, lists 3 Madrid→Rome flights, asks a
|
package/bin/fwdloop
CHANGED
|
@@ -895,9 +895,12 @@ async function cmdDraft(rest) {
|
|
|
895
895
|
model: { type: 'string' }, provider: { type: 'string' }, thinking: { type: 'boolean' },
|
|
896
896
|
// M13 piece 4: the job's flow type (plain | mcp | tickets) and its MCP server, from the card; the tools come from that server's newest OK `check tools` (never a started server)
|
|
897
897
|
'flow-type': { type: 'string' }, mcp: { type: 'string' },
|
|
898
|
+
// M13 am11: what the prose's send line is: check (the card's tentative send: the AI says if the last line is the action), known (the person agreed or typed the last line) . Absent: the prose file is the truth.
|
|
899
|
+
action: { type: 'string' },
|
|
898
900
|
},
|
|
899
901
|
allowPositionals: true,
|
|
900
902
|
});
|
|
903
|
+
if (values.action !== undefined && !['check', 'known'].includes(values.action)) fail(`draft: --action takes check or known, got "${values.action}"`);
|
|
901
904
|
const flowType = values['flow-type'] ?? 'plain';
|
|
902
905
|
if (!['plain', 'mcp', 'tickets'].includes(flowType)) fail(`draft: --flow-type takes plain, mcp or tickets, got "${flowType}"`);
|
|
903
906
|
if (flowType === 'plain' && values.mcp !== undefined) fail('draft: --mcp goes with --flow-type mcp or tickets');
|
|
@@ -1000,6 +1003,7 @@ async function cmdDraft(rest) {
|
|
|
1000
1003
|
root: values.root === undefined ? defaultFlowsRoot() : resolve(values.root),
|
|
1001
1004
|
name: values.name,
|
|
1002
1005
|
noQuestions: values['no-questions'] === true,
|
|
1006
|
+
...(values.action === undefined ? {} : { actionMode: values.action }),
|
|
1003
1007
|
...(leftRules.length ? { leftRules } : {}),
|
|
1004
1008
|
...(columnAnswers.length ? { columnAnswers } : {}),
|
|
1005
1009
|
...(checkPicks === undefined ? {} : { checkPicks }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.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",
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// M13 am11 rules 1 and 2: the job's last line is the action. ONE module for the two AI questions (prompts verbatim from poc/f204-action-ai/prompts.mjs, F204),
|
|
2
|
+
// the checks code makes on each answer, and the one function that takes the tentative send out of a prose file.
|
|
3
|
+
// The AI answers one question ("is there a last step that writes or sends everything that came before it?"); code checks the answer is the LAST line and not an Ask.
|
|
4
|
+
// The AI suggests one line when there is none; code keeps one plain line or nothing. The AI never writes a destination: the send target is typed data in the signed arbiter.
|
|
5
|
+
// Throws away: whatever else the answer carried (only `action.line` / `text` are read). Third outcomes: a line that is not the last, an Ask, a non-integer, text with a
|
|
6
|
+
// newline or empty -> "no action" / "no suggestion" (never a guess).
|
|
7
|
+
|
|
8
|
+
export const RECOGNISE_TOOL = 'record_action';
|
|
9
|
+
export const SUGGEST_TOOL = 'suggest_action';
|
|
10
|
+
export const MAX_SUGGESTION_CHARS = 300;
|
|
11
|
+
|
|
12
|
+
export const RECOGNISE_SYSTEM = `A person wrote a numbered list of steps for a job. The finished result goes to the Destination named below the list.
|
|
13
|
+
|
|
14
|
+
Is there a last step that writes or sends everything that came before it? Answer with that step's number, or null if there is none.
|
|
15
|
+
|
|
16
|
+
A step that only reads, makes, lists, checks or asks something is not one. The step does not have to name the Destination: the Destination is only where the result goes.
|
|
17
|
+
|
|
18
|
+
Answer by calling the tool ${RECOGNISE_TOOL} exactly once, with the field "action" holding one required field: line (the step's number, or null).`;
|
|
19
|
+
|
|
20
|
+
export const SUGGEST_SYSTEM = `A person wrote a numbered list of steps for a job. The finished result goes to the Destination named below the list. The list has no last step that writes or sends everything that came before it.
|
|
21
|
+
|
|
22
|
+
Your one task: suggest ONE last step that writes or sends everything that came before it to the Destination.
|
|
23
|
+
|
|
24
|
+
Rules:
|
|
25
|
+
- Write the step as one short plain sentence, in the person's voice, like their other steps. It must say that the result is written or sent to the Destination.
|
|
26
|
+
- Do not repeat or change any existing step. Do not write a step that asks the person a question.
|
|
27
|
+
|
|
28
|
+
Answer by calling the tool ${SUGGEST_TOOL} exactly once. The one required field is text (the new step).`;
|
|
29
|
+
|
|
30
|
+
export const RECOGNISE_SCHEMA = {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
action: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
line: { type: ['integer', 'null'], description: 'Number of the last step that writes or sends everything that came before it, or null if there is none.' },
|
|
37
|
+
},
|
|
38
|
+
required: ['line'],
|
|
39
|
+
additionalProperties: false,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
required: ['action'],
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const SUGGEST_SCHEMA = {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
text: { type: 'string', description: 'The one new last step, one short plain sentence.' },
|
|
50
|
+
},
|
|
51
|
+
required: ['text'],
|
|
52
|
+
additionalProperties: false,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The job as the model sees it (F204's listing): `n. text`, ` gN: rule` per `; ` part, then the Destination.
|
|
57
|
+
* @param {{n: number, text: string, guardrail?: string}[]} lines `parseSignedText`'s lines @param {Set<number>} askLines @param {string} destination
|
|
58
|
+
*/
|
|
59
|
+
export function jobListing(lines, askLines, destination) {
|
|
60
|
+
const out = ['The job:'];
|
|
61
|
+
for (const l of lines) {
|
|
62
|
+
out.push(`${l.n}. ${askLines.has(l.n) ? `Ask: ${l.text}` : l.text}`);
|
|
63
|
+
const rules = typeof l.guardrail === 'string' && l.guardrail !== '' ? l.guardrail.split('; ') : [];
|
|
64
|
+
rules.forEach((g, i) => out.push(` g${i + 1}: ${g}`));
|
|
65
|
+
}
|
|
66
|
+
out.push('', `Destination: folder ${destination}`);
|
|
67
|
+
return out.join('\n');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Code's check of the recognise answer: the action is the LAST line (and not an Ask) or there is none.
|
|
72
|
+
* @param {any} args the tool call's arguments @param {number} lastLine @param {boolean} lastIsAsk
|
|
73
|
+
* @returns {boolean} true = the last line is the action
|
|
74
|
+
*/
|
|
75
|
+
export function recognisedIsLast(args, lastLine, lastIsAsk) {
|
|
76
|
+
const line = args && typeof args === 'object' ? args.action?.line : undefined;
|
|
77
|
+
return Number.isInteger(line) && line === lastLine && !lastIsAsk;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Code's check of the suggestion: one plain line, not empty, not long, no control characters. Anything else is no suggestion.
|
|
82
|
+
* @param {any} args @returns {string|null}
|
|
83
|
+
*/
|
|
84
|
+
export function cleanSuggestion(args) {
|
|
85
|
+
const t = args && typeof args === 'object' && typeof args.text === 'string' ? args.text.trim() : '';
|
|
86
|
+
// eslint-disable-next-line no-control-regex
|
|
87
|
+
if (t === '' || t.length > MAX_SUGGESTION_CHARS || /[\x00-\x1F\x7F]/.test(t)) return null;
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The asked question's words (signed, M13 am11 rule 2). @param {string} line */
|
|
92
|
+
export const suggestionQuestion = (line) => `Your job has no last step that writes it out. I suggest: "${line}". `;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The prose file without its (tentative) send line: the one writer of "this job has no write". Only the arbiter's `send at line <n> to ...` line is removed.
|
|
96
|
+
* @param {string} proseText
|
|
97
|
+
*/
|
|
98
|
+
export function withoutSend(proseText) {
|
|
99
|
+
return proseText.split('\n').filter((l) => !/^guardrail: send at line \d+ to /.test(l)).join('\n');
|
|
100
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// M13 am11 rule 3 / am11a: before the action (the job's last line, a signed send) writes or sends, what goes out is compared by sha256 with what the person
|
|
2
|
+
// accepted at their last Ask IN THIS RUN. ONE function decides (`decideAction`), the words and the wait live here once.
|
|
3
|
+
// Throws away: nothing. Third outcomes: an accept with no recorded sha (null / '') reads as "nothing accepted"; an unreadable outgoing sha reads as unseen.
|
|
4
|
+
import { sha256Hex, serializeArtifact } from './ask.js';
|
|
5
|
+
|
|
6
|
+
export const ACTION_STOP_KIND = 'action-stop';
|
|
7
|
+
export const STOP_CHANGED = 'This changed since you accepted it.';
|
|
8
|
+
export const STOP_UNSEEN = 'You have not seen this yet.';
|
|
9
|
+
/** am11a 1: the card's Ask wait is 1h unless the person changes it; this is the default when nothing else is signed. */
|
|
10
|
+
export const DEFAULT_ACTION_WAIT_MS = 3_600_000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {{ acceptedSha: string|null|undefined, outgoing: Record<string, any> }} a `acceptedSha` = the sha256 recorded at the last Ask accepted this run; `outgoing` = the artifact about to go out
|
|
14
|
+
* @returns {{ go: true, outgoingSha: string } | { go: false, question: string, outgoingSha: string }}
|
|
15
|
+
*/
|
|
16
|
+
export function decideAction({ acceptedSha, outgoing }) {
|
|
17
|
+
const outgoingSha = sha256Hex(serializeArtifact(outgoing));
|
|
18
|
+
if (typeof acceptedSha !== 'string' || acceptedSha === '') return { go: false, question: STOP_UNSEEN, outgoingSha };
|
|
19
|
+
return acceptedSha === outgoingSha ? { go: true, outgoingSha } : { go: false, question: STOP_CHANGED, outgoingSha };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The accept to compare against: the sha of the LAST Ask (by step order) before step `i` that was accepted in this run, or null when there is none.
|
|
24
|
+
* @param {{ emits?: string }[]} steps @param {number} i @param {Map<string, string|null>} acceptedAskEmitsThisRun
|
|
25
|
+
*/
|
|
26
|
+
export function lastAcceptedSha(steps, i, acceptedAskEmitsThisRun) {
|
|
27
|
+
for (let k = i - 1; k >= 0; k -= 1) {
|
|
28
|
+
const e = steps[k].emits;
|
|
29
|
+
if (typeof e === 'string' && acceptedAskEmitsThisRun.has(e)) return acceptedAskEmitsThisRun.get(e) ?? null;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* am11a 1/2: the wait of the stop. The LAST Ask's own wait when the job has an Ask before the action; else the card's Ask wait kept in the run's signed values (`arbiter.actionWaitMs`), else 1h.
|
|
36
|
+
* @param {{ fromLine: number }[]} steps @param {number} i @param {Map<number, {ttlMs: number}>} askLines @param {number|undefined} actionWaitMs
|
|
37
|
+
*/
|
|
38
|
+
export function stopWaitMs(steps, i, askLines, actionWaitMs) {
|
|
39
|
+
for (let k = i - 1; k >= 0; k -= 1) {
|
|
40
|
+
const ask = askLines.get(steps[k].fromLine);
|
|
41
|
+
if (ask) return ask.ttlMs;
|
|
42
|
+
}
|
|
43
|
+
return Number.isFinite(actionWaitMs) && /** @type {number} */ (actionWaitMs) > 0 ? /** @type {number} */ (actionWaitMs) : DEFAULT_ACTION_WAIT_MS;
|
|
44
|
+
}
|
package/src/ask.js
CHANGED
|
@@ -509,6 +509,11 @@ export function answerAsk({
|
|
|
509
509
|
return { ok: false, red: `answerAsk: askId "${askId}" is unknown for run ${runDir}` };
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
+
// M13 am11: the stop before the action takes Accept only; "Not now" is the Stop (the run ends stopped, nothing written)
|
|
513
|
+
if (ask.kind === 'action-stop' && decision !== 'accept') {
|
|
514
|
+
return { ok: false, red: `answerAsk: askId "${askId}" is the stop before the action and takes Accept only (Not now is Stop)` };
|
|
515
|
+
}
|
|
516
|
+
|
|
512
517
|
const nowIso = now();
|
|
513
518
|
// A present-but-unparseable expiresAt (Date.parse -> NaN) must never read
|
|
514
519
|
// as "not expired" — `NaN > x`/`x > NaN` are both false, so the comparison
|
|
@@ -619,11 +624,11 @@ export function answerAsk({
|
|
|
619
624
|
* Written once with the rest of the record; an existing archive is never
|
|
620
625
|
* rewritten to add it (the `wx` create refuses).
|
|
621
626
|
*
|
|
622
|
-
* @param {{ runDir: string, askId: string, question: string, askedAt: string, expiresAt: string, evidence: unknown, emits?: string }} opts
|
|
627
|
+
* @param {{ runDir: string, askId: string, question: string, askedAt: string, expiresAt: string, evidence: unknown, emits?: string, kind?: string }} opts
|
|
623
628
|
* @returns {{ ok: true } | { ok: false, red: string }}
|
|
624
629
|
*/
|
|
625
630
|
export function writeAskArchive({
|
|
626
|
-
runDir, askId, question, askedAt, expiresAt, evidence, emits,
|
|
631
|
+
runDir, askId, question, askedAt, expiresAt, evidence, emits, kind,
|
|
627
632
|
}) {
|
|
628
633
|
if (typeof runDir !== 'string' || runDir.length === 0) {
|
|
629
634
|
return { ok: false, red: 'writeAskArchive: "runDir" must be a non-empty string' };
|
|
@@ -638,6 +643,7 @@ export function writeAskArchive({
|
|
|
638
643
|
askId, question, askedAt, expiresAt, evidence,
|
|
639
644
|
};
|
|
640
645
|
if (typeof emits === 'string' && emits.length > 0) payload.emits = emits;
|
|
646
|
+
if (typeof kind === 'string' && kind.length > 0) payload.kind = kind; // M13 am11: the stop before the action is an ask record with this one added field
|
|
641
647
|
try {
|
|
642
648
|
writeFileSync(archivePath, JSON.stringify(payload, null, 2), { flag: 'wx' });
|
|
643
649
|
} catch (err) {
|
|
@@ -785,6 +791,7 @@ export function listArchivedAsks(runDir) {
|
|
|
785
791
|
evidence: readAskEvidence(ask),
|
|
786
792
|
answer,
|
|
787
793
|
...(typeof ask.emits === 'string' ? { emits: ask.emits } : {}),
|
|
794
|
+
...(typeof ask.kind === 'string' ? { kind: ask.kind } : {}), // M13 am11: the stop before the action
|
|
788
795
|
});
|
|
789
796
|
}
|
|
790
797
|
|
package/src/authoring.js
CHANGED
|
@@ -22,7 +22,6 @@ import path from 'node:path';
|
|
|
22
22
|
import { draft } from './drafter.js';
|
|
23
23
|
import { parseSignedText, unsignedAskTtls } from './signed-text.js';
|
|
24
24
|
import { validateDeclaration, flowTypeOf } from './declaration.js';
|
|
25
|
-
import { addedLinesOf } from './added-end.js';
|
|
26
25
|
import { factRows, factSentence, countSentence } from './citedcheck.js';
|
|
27
26
|
import { plainWords, labelled, tagged } from './checkwords.js';
|
|
28
27
|
import { listLinesOf, partByOf, factByOf, countByOf } from './checklistsign.js';
|
|
@@ -44,6 +43,7 @@ import { sessionPriorSpend, writeDraftSpend } from './draftspend.js';
|
|
|
44
43
|
import { writeSetup } from './setup.js';
|
|
45
44
|
import { RECORD_FILE } from './pickrecord.js';
|
|
46
45
|
import { mcpPickHere } from './mcp-pick.js';
|
|
46
|
+
import { hitlWords } from './checked.js';
|
|
47
47
|
|
|
48
48
|
export const SPEC_HASH_FILE = 'spec.hash';
|
|
49
49
|
/** The one folder under the flows root where the panel keeps its draft folders (M4e). Starts with a dot, so it is never a flow name. */
|
|
@@ -181,11 +181,15 @@ const READOUT_HEADS = {
|
|
|
181
181
|
refused: 'REFUSED LINES',
|
|
182
182
|
jobLines: 'JOB LINES',
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
// borrowed-from: bareloop src/authorreadout.js@v0.58.0
|
|
185
|
+
/** The readout's top line prefix: ONE owner for the text `buildReadout` writes and the bold `readoutHeadIndexes` finds. */
|
|
186
|
+
export const READOUT_HEADER_PREFIX = 'DRAFT READOUT — NOT SIGNED — flow ';
|
|
187
|
+
|
|
188
|
+
/** Zero-based indexes of the header and heading lines in a readout's text (split on "\n"): the panel renders those bold. */
|
|
185
189
|
export function readoutHeadIndexes(text) {
|
|
186
190
|
const heads = new Set(Object.values(READOUT_HEADS));
|
|
187
191
|
const idx = [];
|
|
188
|
-
String(text).split('\n').forEach((l, i) => { if (heads.has(l)) idx.push(i); });
|
|
192
|
+
String(text).split('\n').forEach((l, i) => { if (heads.has(l) || l.startsWith(READOUT_HEADER_PREFIX)) idx.push(i); });
|
|
189
193
|
return idx;
|
|
190
194
|
}
|
|
191
195
|
|
|
@@ -194,7 +198,7 @@ export function buildReadout({
|
|
|
194
198
|
declaration, arbiter, lines, name, modelId, costUsd, rounds, spendComplete, root,
|
|
195
199
|
}) {
|
|
196
200
|
const out = [];
|
|
197
|
-
out.push(
|
|
201
|
+
out.push(`${READOUT_HEADER_PREFIX}"${name}"`, '');
|
|
198
202
|
out.push(`Drafted by: ${modelId ?? '?'} in ${rounds} round(s), cost ${usd(costUsd, spendComplete)}`);
|
|
199
203
|
if (typeof root === 'string') out.push(`Flows root: ${root} (the flow is written to <flows root>/${name} when you sign)`);
|
|
200
204
|
out.push(`Cap per run (signed by you in the prose): $${arbiter.capUsd}`, '');
|
|
@@ -220,11 +224,14 @@ export function buildReadout({
|
|
|
220
224
|
out.push('', READOUT_HEADS.steps);
|
|
221
225
|
const sheetBlocks = sheetLineBlocks({ declaration, lines });
|
|
222
226
|
const onList = listLinesOf(declaration);
|
|
223
|
-
|
|
227
|
+
// display only: a hitl step that is not an Ask line prints the card's words (src/checked.js hitlWords); an Ask line (pure stop) keeps `hitl`
|
|
228
|
+
const askLineNos = (arbiter.asks ?? []).map((a) => a.line);
|
|
229
|
+
const lastAskIdx = declaration.steps.reduce((m, st, i) => (askLineNos.includes(st.fromLine) ? i : m), -1);
|
|
230
|
+
const checkText = (st, i) => (st.close?.class === 'hitl' && !askLineNos.includes(st.fromLine) ? hitlWords(askLineNos.length > 0, lastAskIdx !== -1 && i > lastAskIdx) : st.close?.class);
|
|
224
231
|
declaration.steps.forEach((st, i) => {
|
|
225
|
-
out.push(` ${i + 1}. (line ${st.fromLine}) ${st.goal}
|
|
232
|
+
out.push(` ${i + 1}. (line ${st.fromLine}) ${st.goal}`);
|
|
226
233
|
out.push(` grants: ${st.primitives?.length ? st.primitives.join(', ') : 'none (pure stop)'}`
|
|
227
|
-
+ ` | reads: ${st.reads?.length ? st.reads.join(', ') : '-'} | emits: ${st.emits} | check: ${st
|
|
234
|
+
+ ` | reads: ${st.reads?.length ? st.reads.join(', ') : '-'} | emits: ${st.emits} | check: ${checkText(st, i)}`);
|
|
228
235
|
if (Array.isArray(st.mcpTools) && st.mcpTools.length) out.push(` tools: ${st.mcpTools.join(', ')}`);
|
|
229
236
|
// M10 am7 item 1: the facts a cited step checks its quotes against, signed with the readout (typed fields, never model prose)
|
|
230
237
|
// M16: a list line's checks carry the tag of the row that built each (`[you]`, `[agent]`, `[default]`); any other line keeps today's words
|
|
@@ -339,6 +346,8 @@ export function writePlanFiles(dir, files, opts = {}) {
|
|
|
339
346
|
export async function draftToDir({
|
|
340
347
|
proseFile, dir, root, name, slot, model, draftThinking = /** @type {'on'|'off'} */ ('off'), keyNames, env = process.env, provider, rates, modelId, noQuestions = false, onResult, fetchPage, leftRules, columnAnswers, carriedColumns, checkPicks, carriedPicks, carriedChoices, carriedSheetDropped, proseRead,
|
|
341
348
|
flowType = /** @type {'plain'|'mcp'|'tickets'} */ ('plain'), mcpServer = /** @type {string|undefined} */ (undefined), mcpPick = /** @type {any} */ (undefined), mcpServers = /** @type {string[]|undefined} */ (undefined),
|
|
349
|
+
// M13 am11: what the card's tentative send line is (see draft()); null = the prose file is the truth
|
|
350
|
+
actionMode = /** @type {null|'check'|'known'} */ (null),
|
|
342
351
|
}) {
|
|
343
352
|
const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
|
|
344
353
|
const nameCheck = checkFlowName(name);
|
|
@@ -423,7 +432,7 @@ export async function draftToDir({
|
|
|
423
432
|
let pickRecord = null; // M10 am17: handed by draft() as it learns it; the last one handed is this draft's (written below, the one writer)
|
|
424
433
|
const result = await draft({
|
|
425
434
|
proseText: prose.text, slot, model, provider, rates, modelId, env, onBook, priorSpend, offerQuestions: !noQuestions, draftThinking, draftDir: path.join(dir, PAGES_DIR), fetchPage, learnHints, ...(leftRules === undefined ? {} : { leftRules }), ...(columnAnswers === undefined ? {} : { columnAnswers }), ...(carriedColumns === undefined ? {} : { carriedColumns }), onColumns: (rec) => { columnRecord = rec; }, ...(checkPicks === undefined ? {} : { checkPicks }), ...(carriedPicks === undefined ? {} : { carriedPicks }), ...(carriedChoices === undefined ? {} : { carriedChoices, onChoices: (rec) => { rowChoices = rec; } }), ...(carriedSheetDropped === undefined ? {} : { carriedSheetDropped }), onSheetDropped: (rec) => { sheetDropped = rec; }, onPickRecord: (r) => { pickRecord = r; },
|
|
426
|
-
flowType, mcp, ...(mcpServers === undefined ? {} : { mcpServers }),
|
|
435
|
+
flowType, mcp, ...(mcpServers === undefined ? {} : { mcpServers }), actionMode,
|
|
427
436
|
});
|
|
428
437
|
if (result.stop === 'pre-flight') {
|
|
429
438
|
try { rmdirSync(dir); } catch { /* the claimed dir is still empty; leave it rather than mask the refusal */ }
|
|
@@ -441,12 +450,14 @@ export async function draftToDir({
|
|
|
441
450
|
const paidFail = (red) => ({
|
|
442
451
|
ok: false, wrote: true, dir, reds: [red], costUsd: result.costUsd, spendComplete: result.spendComplete, stop: 'write', rounds: result.rounds, calls: result.calls, leaks: 0,
|
|
443
452
|
});
|
|
444
|
-
|
|
453
|
+
// M13 am11: the prose as the drafter kept it (its tentative send line stays or is taken out); every file below is made from this one text
|
|
454
|
+
const proseOut = typeof result.proseText === 'string' ? result.proseText : prose.text;
|
|
455
|
+
const parsed = parseSignedText(proseOut); // the drafter already proved it parses
|
|
445
456
|
if (!parsed.ok) return paidFail(`parse: ${parsed.reds.join('; ')}`);
|
|
446
457
|
const dj = (o) => `${JSON.stringify(o, null, 2)}\n`;
|
|
447
458
|
/** @type {Record<string, string>} */
|
|
448
459
|
const files = {};
|
|
449
|
-
files['prose.txt'] =
|
|
460
|
+
files['prose.txt'] = proseOut; // verbatim (M13 am11: as the drafter kept it)
|
|
450
461
|
const targetText = dj({ root, name });
|
|
451
462
|
files['target.json'] = targetText;
|
|
452
463
|
// M4d am6 item 6: the pick is remembered beside the draft (written below as model.json, outside the signed files) so the signed job runs with it.
|
|
@@ -464,6 +475,8 @@ export async function draftToDir({
|
|
|
464
475
|
revisions: result.revisions, thinking: result.thinking, inputs: result.inputs, log: result.log,
|
|
465
476
|
// M16 P4: what the plan card shows of the list (rows with tags and reasons, the suggestions), drawn by the page; Drop and Add rebuild it
|
|
466
477
|
...(result.checkCard ? { checkCard: result.checkCard } : {}),
|
|
478
|
+
// M13 am11: the job's action (the last line the AI named, or the person agreed or typed), or null: the plan card's row `› line <n> writes everything before it`
|
|
479
|
+
action: result.action ?? null,
|
|
467
480
|
}), secrets);
|
|
468
481
|
let hash = null;
|
|
469
482
|
if (result.ok) {
|
|
@@ -476,7 +489,7 @@ export async function draftToDir({
|
|
|
476
489
|
files['input-facts.json'] = inputFactsText;
|
|
477
490
|
files['readout.txt'] = readoutText;
|
|
478
491
|
const h = specHash({
|
|
479
|
-
proseText:
|
|
492
|
+
proseText: proseOut, declarationText, inputFactsText, readoutText, targetText,
|
|
480
493
|
});
|
|
481
494
|
if (!h.ok) return paidFail(`hash: ${h.red}`);
|
|
482
495
|
hash = h.hash; // spec.hash is written only after a clean sweep, below
|
package/src/checkblock.js
CHANGED
|
@@ -76,6 +76,8 @@ export const REASON = Object.freeze({
|
|
|
76
76
|
manyInputs: 'the job has more than one input and code cannot pick which one the claims quote',
|
|
77
77
|
oneSidedTime: 'a time limit the AI proposes must be a range, so you judge it at Accept.',
|
|
78
78
|
countNeedsFact: 'a result count needs a fact to count; this line has none',
|
|
79
|
+
// borrowed-from: bareloop src/checkblock.js@v0.58.0
|
|
80
|
+
countNeedsSuggested: 'a result count needs a fact to count; add the suggested fact on this line to count its results',
|
|
79
81
|
lookNoWords: "the page does not hold the words of the look's fact for this rule",
|
|
80
82
|
afterLast: 'no more tries: Start over (rows are never changed by the AI after the last try)',
|
|
81
83
|
noPick: 'No check was picked for it, so you judge it at Accept.',
|
|
@@ -243,7 +245,9 @@ export class CheckBlock {
|
|
|
243
245
|
const said = this.said(r.line);
|
|
244
246
|
if (r.kind === 'count') return [r.min, r.max].filter((x) => Number.isInteger(x)).some((n) => numberIn(said, n));
|
|
245
247
|
// a 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
|
|
246
|
-
|
|
248
|
+
// borrowed-from: bareloop src/checkblock.js@v0.58.0
|
|
249
|
+
// A phrase or place is job-derived 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")
|
|
250
|
+
return (r.words ?? []).some((/** @type {string} */ w) => inText(said, w)) || (r.kind === 'fact' && r.shape !== 'phrase' && r.shape !== 'place' && typeof r.name === 'string' && inText(said, r.name));
|
|
247
251
|
}
|
|
248
252
|
|
|
249
253
|
/** a `!` count row is built unless a `~` rule on its line already names the number */
|
|
@@ -445,7 +449,8 @@ export class CheckBlock {
|
|
|
445
449
|
r.grown = words.length ? words : undefined;
|
|
446
450
|
}
|
|
447
451
|
lineParts.push({ ...part, facts: facts.flatMap((f) => grownOf(f) ?? [f]) }); lineRows.push([...factRows.map((f) => f.r.key), ...(countRow ? [countRow.key] : [])]); factLines.add(l.n); if (countRow) { countRow.state = 'built'; countRow.reason = null; } }
|
|
448
|
-
|
|
452
|
+
// borrowed-from: bareloop src/checkblock.js@v0.58.0
|
|
453
|
+
} else if (countRow) { countRow.state = 'not-checked'; countRow.reason = this.rowsOn(l.n).some((x) => x.held && (x.kind === 'fact' || x.kind === 'phrase')) ? REASON.countNeedsSuggested : REASON.countNeedsFact; }
|
|
449
454
|
for (const { p, key } of pickParts) { lineParts.push(p); lineRows.push([key]); }
|
|
450
455
|
this.buildDefaults(l, lineParts, lineRows, factLines);
|
|
451
456
|
}
|
package/src/checked.js
CHANGED
|
@@ -25,6 +25,12 @@ import { splitReadNotes, signedFactNames } from './pagedropwords.js';
|
|
|
25
25
|
|
|
26
26
|
const list = (xs) => xs.join(', ');
|
|
27
27
|
|
|
28
|
+
/** The words for a step with no machine check of its content: the ONE owner (the card and the draft readout both call it). @param {boolean} hasAsk the job has a signed ask @param {boolean} afterLastAsk the step comes after the last ask */
|
|
29
|
+
export function hitlWords(hasAsk, afterLastAsk) {
|
|
30
|
+
if (afterLastAsk) return 'No machine check of the content; you check it after you accept.';
|
|
31
|
+
return hasAsk ? 'No machine check of the content: you check it at the ask.' : 'No machine check of the content; the machine checks only that the step happened.';
|
|
32
|
+
}
|
|
33
|
+
|
|
28
34
|
/**
|
|
29
35
|
* One entry per step, in plan order: the plain sentences for what its typed close checks.
|
|
30
36
|
* M10b piece 4: with `lines` (the signed job lines) a step that reads a sheet also carries `sheet`, its line's block (src/sheetblock.js `sheetLineBlocks`: guardrails,
|
|
@@ -69,8 +75,7 @@ export function checkedLines(declaration, { hasAsk = true, askLines, lines, csvR
|
|
|
69
75
|
// M10 am16: each check the person picked, in the words it was picked in (src/checkwords.js, the one place)
|
|
70
76
|
if (!listed && Array.isArray(shape.picked)) for (const c of shape.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptOf(st.fromLine, c)}`, 'picked'));
|
|
71
77
|
} else {
|
|
72
|
-
|
|
73
|
-
else out.push(hasAsk ? 'No machine check of the content: you check it at the ask.' : 'No machine check of the content; the machine checks only that the step happened.');
|
|
78
|
+
out.push(hitlWords(hasAsk, lastAsk !== -1 && i > lastAsk));
|
|
74
79
|
}
|
|
75
80
|
// M10 am22 (1)(4): the checks the person picked for a fact line, beside its fact rows
|
|
76
81
|
if (!listed && cls === 'green' && Array.isArray(st.close.picked)) for (const c of st.close.picked) out.push(labelled(`You picked: ${plainWords(c)}.${keptOf(st.fromLine, c)}`, 'picked'));
|
package/src/checklist.js
CHANGED
|
@@ -12,8 +12,6 @@ import { lineRules } from './pagebits.js';
|
|
|
12
12
|
export const MAX_BANG = 3;
|
|
13
13
|
/** the reason a check on a version or a date goes under Not checked: it is true only for the input as it is today */
|
|
14
14
|
export const WEEK_ONLY_WORDS = 'It names a version or a date from the input, true only for the input as it is today, so you judge it at Accept.';
|
|
15
|
-
/** the label of the list call, as the drafting book and the draft log see it */
|
|
16
|
-
export const LEDGER_LABEL = 'ledger-suggest';
|
|
17
15
|
export const LEDGER_TOOL = 'suggest_extra_checks';
|
|
18
16
|
/** how much of each input the call is shown */
|
|
19
17
|
const SHOWN_CHARS = 8000;
|
package/src/declaration.js
CHANGED
|
@@ -1208,33 +1208,14 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1208
1208
|
reds.push(`declaration: send at line ${n} (steps[${sendIdx}]) is not granted a catalogue primitive of class "write"`);
|
|
1209
1209
|
}
|
|
1210
1210
|
|
|
1211
|
-
//
|
|
1212
|
-
//
|
|
1213
|
-
//
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
const earlierAskLines = askLines.filter((a) => {
|
|
1220
|
-
const askIdx = stepInfo.findIndex((st) => st.fromLine === a);
|
|
1221
|
-
return askIdx !== -1 && askIdx < sendIdx;
|
|
1222
|
-
});
|
|
1223
|
-
if (earlierAskLines.length === 0) {
|
|
1224
|
-
reds.push(`declaration: send at line ${n} (steps[${sendIdx}]) has no signed ask at an earlier line to read from`);
|
|
1225
|
-
} else {
|
|
1226
|
-
const earlierAskEmits = earlierAskLines
|
|
1227
|
-
.map((a) => stepInfo.find((st) => st.fromLine === a))
|
|
1228
|
-
.filter((st) => st !== undefined)
|
|
1229
|
-
.map((st) => st.emits);
|
|
1230
|
-
const readAskEmits = earlierAskEmits.filter((emits) => emits !== null && sendStep.reads.includes(emits));
|
|
1231
|
-
if (readAskEmits.length === 0) {
|
|
1232
|
-
reds.push(`declaration: send at line ${n} (steps[${sendIdx}]) does not read the emits of any earlier signed `
|
|
1233
|
-
+ `ask step (asks at lines ${earlierAskLines.join(', ')})`);
|
|
1234
|
-
} else if (readAskEmits.length >= 2) {
|
|
1235
|
-
reds.push(`declaration: send at line ${n} (steps[${sendIdx}]) reads the emits of more than one earlier signed `
|
|
1236
|
-
+ `ask step (${readAskEmits.join(', ')}) — exactly 1 required`);
|
|
1237
|
-
}
|
|
1211
|
+
// M13 am11: the action ships everything that came before it: it reads the output of the step right before it (by step order, the order the
|
|
1212
|
+
// runner folds over). An Ask there is the artifact accepted at it; any other step's output is checked at run time against the last accept (or the run stops once).
|
|
1213
|
+
// No Ask is needed before the action. (Was: the send must read exactly one earlier signed ask.)
|
|
1214
|
+
const before = sendIdx > 0 ? stepInfo[sendIdx - 1] : null;
|
|
1215
|
+
if (before === null || before.emits === null) {
|
|
1216
|
+
reds.push(`declaration: send at line ${n} (steps[${sendIdx}]) has no step before it to write out`);
|
|
1217
|
+
} else if (!sendStep.reads.includes(before.emits)) {
|
|
1218
|
+
reds.push(`declaration: send at line ${n} (steps[${sendIdx}]) must read the output of the step before it ("${before.emits}"), got [${sendStep.reads.join(', ')}]`);
|
|
1238
1219
|
}
|
|
1239
1220
|
}
|
|
1240
1221
|
|
|
@@ -1246,7 +1227,9 @@ export function validateDeclaration(declaration, context = {}) {
|
|
|
1246
1227
|
// STEP ORDER (a step's position in `declaration.steps`, not its line
|
|
1247
1228
|
// number) since that is the order the runner actually folds over. No
|
|
1248
1229
|
// anchor to check against when there is no signed ask at all.
|
|
1249
|
-
|
|
1230
|
+
// M13 am11: with an action (a signed send) a step after the last Ask is allowed: what goes out is compared with the last accept at run time and the run stops once if it changed
|
|
1231
|
+
// (src/runner.js). A job with no action keeps this rule unchanged.
|
|
1232
|
+
if (askLines.length > 0 && sendLines.length === 0) {
|
|
1250
1233
|
const lastAskLine = Math.max(...askLines);
|
|
1251
1234
|
const lastAskStepIdx = stepInfo.findIndex((st) => st.fromLine === lastAskLine);
|
|
1252
1235
|
if (lastAskStepIdx !== -1) {
|