fwdloop 0.13.0 → 0.15.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/bin/fwdloop +25 -12
- package/package.json +2 -2
- package/src/authoring.js +73 -39
- package/src/canrun.js +71 -1
- package/src/catalogue.json +2 -2
- package/src/checked.js +54 -0
- package/src/closers.js +112 -91
- package/src/declaration.js +115 -11
- package/src/drafter.js +139 -39
- package/src/flow.js +220 -5
- package/src/keysfile.js +4 -2
- package/src/model-step.js +1 -1
- package/src/monthly.js +139 -17
- package/src/panel/author.js +226 -64
- package/src/panel/authorcard.js +99 -4
- package/src/panel/authorflows.js +51 -10
- package/src/panel/authorresume.js +2 -2
- package/src/panel/authorstart.js +18 -10
- package/src/panel/data.js +147 -81
- package/src/panel/index.html +497 -338
- package/src/panel/server.js +5 -2
- package/src/panel/settings.js +1 -1
- package/src/runner.js +105 -48
- package/src/setup.js +21 -14
- package/src/signed-diff.js +71 -0
- package/types/authoring.d.ts +52 -14
- package/types/canrun.d.ts +33 -1
- package/types/checked.d.ts +25 -0
- package/types/closers.d.ts +47 -28
- package/types/declaration.d.ts +16 -2
- package/types/drafter.d.ts +146 -11
- package/types/flow.d.ts +42 -2
- package/types/model-step.d.ts +1 -6
- package/types/monthly.d.ts +25 -1
- package/types/panel/author.d.ts +55 -40
- package/types/panel/authorcard.d.ts +54 -0
- package/types/panel/authorflows.d.ts +39 -0
- package/types/panel/authorstart.d.ts +1 -0
- package/types/panel/data.d.ts +11 -56
- package/types/runner.d.ts +11 -3
- package/types/setup.d.ts +6 -12
- package/types/signed-diff.d.ts +10 -0
package/bin/fwdloop
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
} from '../src/provider.js';
|
|
38
38
|
import { configDoorHome } from '../src/config.js';
|
|
39
39
|
import {
|
|
40
|
-
claimHold, settleHold, monthlyRefusalText, ConfigError,
|
|
40
|
+
claimHold, settleHold, nameRunDir, monthlyRefusalText, ConfigError,
|
|
41
41
|
} from '../src/monthly.js';
|
|
42
42
|
import { keysForDoor } from '../src/keysfile.js';
|
|
43
43
|
import {
|
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
} from '../src/ask.js';
|
|
46
46
|
import { panelMain } from '../src/panel/server.js';
|
|
47
47
|
import { isInteractive, confirmTypedName, NEEDS_TTY } from '../src/sign-confirm.js';
|
|
48
|
-
import { draftToDir, signDraft, SIGN_LINE, costText } from '../src/authoring.js';
|
|
48
|
+
import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal } from '../src/authoring.js';
|
|
49
49
|
import { userInfo } from 'node:os';
|
|
50
50
|
|
|
51
51
|
// The baseline model (project rule, CLAUDE.md/AGENT_RULES: "deepseek-flash
|
|
@@ -73,7 +73,7 @@ function keyedEnv() {
|
|
|
73
73
|
* that does not fit refuses at $0 with the one refusal text. A hold that fits is given back when this
|
|
74
74
|
* process ends or parks (the `exit` hook runs on every exit path; a SIGKILL leaves it for the next check,
|
|
75
75
|
* which settles it as "process gone").
|
|
76
|
-
* @returns {{ addRunDir: (d: string) => void }}
|
|
76
|
+
* @returns {{ addRunDir: (d: string) => void, nameRunDir: (d: string) => void }}
|
|
77
77
|
*/
|
|
78
78
|
function takeMonthlyHold({ what, flow, runId, runDir, holdUsd, spentAtHold = 0 }) {
|
|
79
79
|
const door = configDoorHome();
|
|
@@ -86,7 +86,7 @@ function takeMonthlyHold({ what, flow, runId, runDir, holdUsd, spentAtHold = 0 }
|
|
|
86
86
|
if (!(process.env.NODE_ENV === 'test' && process.env[hook])) {
|
|
87
87
|
fail('NODE_ENV=test is set without FWDLOOP_CONFIG_HOME, so the keys file, prices and monthly limit would be skipped. Nothing spent. Unset NODE_ENV, or set FWDLOOP_CONFIG_HOME.');
|
|
88
88
|
}
|
|
89
|
-
return { addRunDir: () => {} };
|
|
89
|
+
return { addRunDir: () => {}, nameRunDir: () => {} };
|
|
90
90
|
}
|
|
91
91
|
let claim;
|
|
92
92
|
try {
|
|
@@ -103,13 +103,17 @@ function takeMonthlyHold({ what, flow, runId, runDir, holdUsd, spentAtHold = 0 }
|
|
|
103
103
|
holdId: claim.holdId, why: process.exitCode ? 'ended (red)' : 'ended or parked', home, alsoRunDirs: also,
|
|
104
104
|
}));
|
|
105
105
|
}
|
|
106
|
-
return {
|
|
106
|
+
return {
|
|
107
|
+
addRunDir: (d) => also.push(d),
|
|
108
|
+
// C2: a rerun's new run dir is named in the money record the moment it starts.
|
|
109
|
+
nameRunDir: (d) => { also.push(d); nameRunDir({ holdId: claim.holdId, runDir: d, home }); },
|
|
110
|
+
};
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
/** The new runs a `rerun` chain started in this process — their spend belongs to this hold's month too. */
|
|
110
114
|
function rerunDirs(result, flowDir) {
|
|
111
115
|
const dirs = [];
|
|
112
|
-
for (let r = result; r && r.outcome === 'rerun'; r = r.newRun) dirs.push(join(flowDir, r.newRunId));
|
|
116
|
+
for (let r = result; r && r.outcome === 'rerun'; r = r.newRun) dirs.push(join(flowDir, 'runs', r.newRunId));
|
|
113
117
|
return dirs;
|
|
114
118
|
}
|
|
115
119
|
|
|
@@ -619,6 +623,7 @@ async function cmdResume(rest) {
|
|
|
619
623
|
primitives,
|
|
620
624
|
primitiveReds,
|
|
621
625
|
businessDate: today(),
|
|
626
|
+
onRerunStart: (d) => hold.nameRunDir(d),
|
|
622
627
|
});
|
|
623
628
|
|
|
624
629
|
for (const d of rerunDirs(result, join(root, flowName))) hold.addRunDir(d);
|
|
@@ -754,13 +759,15 @@ async function cmdDraft(rest) {
|
|
|
754
759
|
const { values, positionals } = parseArgs({
|
|
755
760
|
args: rest,
|
|
756
761
|
options: {
|
|
757
|
-
out: { type: 'string' }, root: { type: 'string' }, name: { type: 'string' }, budget: { type: 'string' },
|
|
762
|
+
out: { type: 'string' }, root: { type: 'string' }, name: { type: 'string' }, budget: { type: 'string' },
|
|
763
|
+
// M4e amendment 24 item 4: the redraft after the human's answers never asks (the panel passes this; a plain draft may ask on try 3)
|
|
764
|
+
'no-questions': { type: 'boolean' },
|
|
758
765
|
},
|
|
759
766
|
allowPositionals: true,
|
|
760
767
|
});
|
|
761
768
|
const env = keyedEnv();
|
|
762
769
|
const proseFile = positionals[0];
|
|
763
|
-
if (!proseFile) fail('draft: a prose file is required — fwdloop draft <prose.txt> --out <draftDir> --root <flowsDir> --name <flow> [--budget <usd>]
|
|
770
|
+
if (!proseFile) fail('draft: a prose file is required — fwdloop draft <prose.txt> --out <draftDir> --root <flowsDir> --name <flow> [--budget <usd>]');
|
|
764
771
|
for (const req of ['out', 'root', 'name']) if (!values[req]) fail(`draft: --${req} is required`);
|
|
765
772
|
|
|
766
773
|
let injected = {};
|
|
@@ -770,8 +777,8 @@ async function cmdDraft(rest) {
|
|
|
770
777
|
}
|
|
771
778
|
// The key preflight comes first (draftToDir repeats it), so an unset key keeps its own message ahead of the NODE_ENV refusal.
|
|
772
779
|
if (injected.provider == null) {
|
|
773
|
-
const
|
|
774
|
-
if (
|
|
780
|
+
const refusal = draftKeyRefusal(MODEL_SLOT, env);
|
|
781
|
+
if (refusal !== null) fail(`draft refused at $0 — ${refusal}`);
|
|
775
782
|
}
|
|
776
783
|
// M4d piece 3: the monthly check — a draft has no signed cap, so it holds one ceiling round, priced by the
|
|
777
784
|
// ONE price lookup (an injected test provider carries its own rates).
|
|
@@ -794,8 +801,7 @@ async function cmdDraft(rest) {
|
|
|
794
801
|
root: resolve(values.root),
|
|
795
802
|
name: values.name,
|
|
796
803
|
budgetUsd: values.budget === undefined ? undefined : Number(values.budget),
|
|
797
|
-
|
|
798
|
-
noteFile: values.note === undefined ? undefined : resolve(values.note),
|
|
804
|
+
noQuestions: values['no-questions'] === true,
|
|
799
805
|
env,
|
|
800
806
|
...injected,
|
|
801
807
|
});
|
|
@@ -811,6 +817,10 @@ async function cmdDraft(rest) {
|
|
|
811
817
|
process.exitCode = 1;
|
|
812
818
|
return;
|
|
813
819
|
}
|
|
820
|
+
if (result.questions > 0) {
|
|
821
|
+
process.stdout.write('DRAFTED — NOT SIGNABLE YET: the plan raised a question. Answer it in the panel (fwdloop panel); the panel drafts again with your answers.\n');
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
814
824
|
process.stdout.write(`${SIGN_LINE(resolve(values.out), result.hash)}\n`);
|
|
815
825
|
}
|
|
816
826
|
|
|
@@ -823,6 +833,9 @@ async function cmdSign(rest) {
|
|
|
823
833
|
const env = keyedEnv(); // sign takes no key, but its leak sweep must know the file's keys too
|
|
824
834
|
const dir = positionals[0];
|
|
825
835
|
if (!dir) fail('sign: a draft dir is required — fwdloop sign <dir> --approve <hash>');
|
|
836
|
+
// M4e amendments 24/25: a plan with a question is not signed from here — the answers are taken in the panel. One check, also run again inside signDraft.
|
|
837
|
+
const openQuestion = questionsRefusal(resolve(dir));
|
|
838
|
+
if (openQuestion !== null) fail(`sign refused — ${openQuestion}`);
|
|
826
839
|
// Amendment 2: a person at a keyboard. TTY check first (cheapest), then the typed flow name; only then
|
|
827
840
|
// signDraft's own $0 checks (hash, wired, goals, TTL, sources, send, leak). signDraft writes only on success.
|
|
828
841
|
if (!isInteractive()) fail(`sign refused — ${NEEDS_TTY}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"bare-agent": "^0.49.0",
|
|
53
|
-
"bareguard": "^0.
|
|
53
|
+
"bareguard": "^0.21.2",
|
|
54
54
|
"litectx": "^0.32.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
package/src/authoring.js
CHANGED
|
@@ -37,6 +37,11 @@ export const SPEC_HASH_FILE = 'spec.hash';
|
|
|
37
37
|
export const PANEL_DRAFTS_DIR = '.drafts';
|
|
38
38
|
/** Written when the end sweep finds a key in the draft dir; sign refuses a dir that has it. */
|
|
39
39
|
export const LEAK_MARKER_FILE = 'scrub-leak.red';
|
|
40
|
+
/** M4e amendments 24/25: the drafter's questions (written once by `fwdloop draft`), each human answer (`answer-<k>.json`, written once by the panel),
|
|
41
|
+
* and the drafter's own "not checked" reading (information only; never in the readout, so never in the hash). */
|
|
42
|
+
export const QUESTIONS_FILE = 'questions.json';
|
|
43
|
+
export const NOT_CHECKED_FILE = 'not-checked.json';
|
|
44
|
+
export const ANSWER_FILE = (k) => `answer-${k}.json`;
|
|
40
45
|
export const SIGN_LINE = (dir, hash) => `DRAFTED — NOT SIGNED. To sign: fwdloop sign ${dir} --approve ${hash}`;
|
|
41
46
|
|
|
42
47
|
const sha = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
@@ -65,6 +70,40 @@ export function specHash({
|
|
|
65
70
|
return { ok: true, hash: sha(Buffer.from(framed, 'utf8')) };
|
|
66
71
|
}
|
|
67
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The questions a plan folder raised and the answers on disk, READ from its files — the ONE reader (the panel's phase reader, the sign
|
|
75
|
+
* checks and the page all use it). `questions` = [{ k, line, question, answer|null }], `open` = those with no answer. A blank or unreadable
|
|
76
|
+
* answer file counts as no answer. No questions file = `{ questions: [], open: [] }`.
|
|
77
|
+
* @param {string} planDir
|
|
78
|
+
* @returns {{ questions: {k:number, line:number, question:string, answer:string|null}[], open: {k:number, line:number, question:string, answer:null}[] }}
|
|
79
|
+
*/
|
|
80
|
+
export function readQuestions(planDir) {
|
|
81
|
+
const none = { questions: [], open: [] };
|
|
82
|
+
const f = readFileInside(planDir, QUESTIONS_FILE);
|
|
83
|
+
if (!f.ok) return none;
|
|
84
|
+
let list;
|
|
85
|
+
try { list = JSON.parse(f.text)?.questions; } catch { return none; }
|
|
86
|
+
if (!Array.isArray(list)) return none;
|
|
87
|
+
const questions = list.map((q, i) => {
|
|
88
|
+
const k = i + 1;
|
|
89
|
+
const a = readFileInside(planDir, ANSWER_FILE(k));
|
|
90
|
+
let answer = null;
|
|
91
|
+
if (a.ok) { try { const t = JSON.parse(a.text)?.answer; if (typeof t === 'string' && t.trim() !== '') answer = t; } catch { /* unreadable = unanswered */ } }
|
|
92
|
+
return { k, line: q.line, question: String(q.question), answer };
|
|
93
|
+
});
|
|
94
|
+
return { questions, open: /** @type {any} */ (questions.filter((q) => q.answer === null)) };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const OPEN_QUESTION_SAY = 'A question the plan raised is still open. Answer it in the panel (fwdloop panel), then sign the plan it drafts after your answers. Nothing was signed.';
|
|
98
|
+
export const ANSWERED_QUESTION_SAY = 'This plan raised questions, and your answers went into a newer plan. Sign the newest plan, not this one. Nothing was signed.';
|
|
99
|
+
|
|
100
|
+
/** The ONE check that a plan folder with questions is not signable (CLI sign, the page's sign route and signDraft all call it). null = fine. @param {string} planDir */
|
|
101
|
+
export function questionsRefusal(planDir) {
|
|
102
|
+
const q = readQuestions(planDir);
|
|
103
|
+
if (q.questions.length === 0) return null;
|
|
104
|
+
return q.open.length > 0 ? OPEN_QUESTION_SAY : ANSWERED_QUESTION_SAY;
|
|
105
|
+
}
|
|
106
|
+
|
|
68
107
|
/** Literal (never RegExp) key scrub; a secret under 8 chars is skipped so it can't blank ordinary text. */
|
|
69
108
|
export function scrub(text, secrets) {
|
|
70
109
|
let out = text;
|
|
@@ -72,15 +111,6 @@ export function scrub(text, secrets) {
|
|
|
72
111
|
return out;
|
|
73
112
|
}
|
|
74
113
|
|
|
75
|
-
/**
|
|
76
|
-
* Does `text` carry any provider key VALUE in `env` (every slot, 8+ chars, literal)? The one test for a human's free text
|
|
77
|
-
* (the revise note) — the same literal rule `scrub` and `sweepForSecrets` use.
|
|
78
|
-
* @param {string} text @param {Record<string, string|undefined>} env
|
|
79
|
-
*/
|
|
80
|
-
export function textHasKey(text, env) {
|
|
81
|
-
return Object.values(PROVIDER_SLOTS).some((p) => { const k = env[p.envVar]; return typeof k === 'string' && k.length >= 8 && text.includes(k); });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
114
|
/** Count files directly inside `dir` that contain a secret literally. */
|
|
85
115
|
export function sweepForSecrets(dir, secrets) {
|
|
86
116
|
const live = secrets.filter((s) => typeof s === 'string' && s.length >= 8);
|
|
@@ -146,6 +176,13 @@ export function buildReadout({
|
|
|
146
176
|
out.push(` ${i + 1}. (line ${st.fromLine}) ${st.goal}`);
|
|
147
177
|
out.push(` grants: ${st.primitives?.length ? st.primitives.join(', ') : 'none (pure stop)'}`
|
|
148
178
|
+ ` | reads: ${st.reads?.length ? st.reads.join(', ') : '-'} | emits: ${st.emits} | check: ${st.close?.class}`);
|
|
179
|
+
// M4e amendment 14 item 5: the check's sections in its order (+ word limit); fixed text from typed fields, never model prose.
|
|
180
|
+
const shape = st.close?.shape;
|
|
181
|
+
if (Array.isArray(shape?.sections) && shape.sections.length > 0) {
|
|
182
|
+
const per = Number.isInteger(shape.wordsPerSection) ? ` · about ${shape.wordsPerSection} words each` : '';
|
|
183
|
+
const lim = Number.isInteger(shape.maxWords) ? ` · under ${shape.maxWords} words` : '';
|
|
184
|
+
out.push(` sections: ${shape.sections.join(' · ')}${per}${lim}`);
|
|
185
|
+
}
|
|
149
186
|
});
|
|
150
187
|
out.push('', READOUT_HEADS.asks);
|
|
151
188
|
for (const a of arbiter.asks) out.push(` line ${a.line}: "${a.question}" (ttl ${fmtTtl(a.ttlMs)})`);
|
|
@@ -188,6 +225,17 @@ export function readProseFile(file) {
|
|
|
188
225
|
return { ok: true, text };
|
|
189
226
|
}
|
|
190
227
|
|
|
228
|
+
/**
|
|
229
|
+
* The ONE check of a draft's API key, at $0 before any ledger write (C3, amendment 16): `bin/fwdloop draft` and `draftToDir` both call
|
|
230
|
+
* it, so both refuse with the same sentence. null = the key is fine; else the sentence (never the key's value).
|
|
231
|
+
* @param {string} slot @param {Record<string,string|undefined>} env
|
|
232
|
+
* @returns {string|null}
|
|
233
|
+
*/
|
|
234
|
+
export function draftKeyRefusal(slot, env) {
|
|
235
|
+
const key = checkKeyPreflight(slot, env);
|
|
236
|
+
return key.ok ? null : String(key.message);
|
|
237
|
+
}
|
|
238
|
+
|
|
191
239
|
/**
|
|
192
240
|
* Draft into `dir`. $0 refusals (return {ok:false, wrote:false}, nothing on disk): bad key,
|
|
193
241
|
* unreadable/blank prose, prose that contains the key, missing inputs / bad signed text, dir
|
|
@@ -198,7 +246,7 @@ export function readProseFile(file) {
|
|
|
198
246
|
* Test seam: `provider`/`rates`/`modelId` are injected; without them a live provider is built.
|
|
199
247
|
*/
|
|
200
248
|
export async function draftToDir({
|
|
201
|
-
proseFile, dir, root, name, slot = 'deepseek', model, budgetUsd = DRAFT_BUDGET_USD, env = process.env, provider, rates, modelId,
|
|
249
|
+
proseFile, dir, root, name, slot = 'deepseek', model, budgetUsd = DRAFT_BUDGET_USD, env = process.env, provider, rates, modelId, noQuestions = false,
|
|
202
250
|
}) {
|
|
203
251
|
const refuse = (reds) => ({ ok: false, wrote: false, reds, costUsd: 0 });
|
|
204
252
|
const nameCheck = checkFlowName(name);
|
|
@@ -221,33 +269,11 @@ export async function draftToDir({
|
|
|
221
269
|
const injected = provider != null;
|
|
222
270
|
const secretVar = PROVIDER_SLOTS[slot]?.envVar;
|
|
223
271
|
if (!injected) {
|
|
224
|
-
const
|
|
225
|
-
if (
|
|
272
|
+
const refusal = draftKeyRefusal(slot, env);
|
|
273
|
+
if (refusal !== null) return refuse([refusal]);
|
|
226
274
|
}
|
|
227
275
|
const secrets = secretVar && env[secretVar] ? [env[secretVar]] : [];
|
|
228
276
|
if (secrets.some((s) => s.length >= 8 && prose.text.includes(s))) return refuse(['prose: contains an API key value — refused']);
|
|
229
|
-
// M4e amendment 3 item 3: a revise starts from the current green plan's dir plus the human's note, and nothing else. All $0, before the dir is claimed.
|
|
230
|
-
/** @type {{ plan: any, note: string }|undefined} */
|
|
231
|
-
let revise;
|
|
232
|
-
if ((reviseFrom === undefined) !== (noteFile === undefined)) return refuse(['draft: --revise-from and --note go together']);
|
|
233
|
-
if (reviseFrom !== undefined && noteFile !== undefined) {
|
|
234
|
-
const prev = {};
|
|
235
|
-
for (const f of ['prose.txt', 'declaration.json', SPEC_HASH_FILE]) {
|
|
236
|
-
const r = readFileInside(reviseFrom, f);
|
|
237
|
-
if (!r.ok) return refuse([`revise: "${reviseFrom}" is not a green draft — ${f} ${r.missing ? 'is missing' : `is refused (${r.red})`}`]);
|
|
238
|
-
prev[f] = r.text;
|
|
239
|
-
}
|
|
240
|
-
// the card's fields come only from the card: a revise carries the SAME prose, byte for byte, as the plan it revises
|
|
241
|
-
if (prev['prose.txt'] !== prose.text) return refuse(['revise: the prose differs from the plan being revised — a revise never changes the card']);
|
|
242
|
-
const noteRead = readFileInside(path.dirname(noteFile), path.basename(noteFile));
|
|
243
|
-
if (!noteRead.ok) return refuse([`revise: cannot read the note "${noteFile}": ${noteRead.missing ? 'missing' : noteRead.red}`]);
|
|
244
|
-
const note = noteRead.text;
|
|
245
|
-
if (note.trim() === '') return refuse(['revise: the note is empty']);
|
|
246
|
-
if (textHasKey(note, env)) return refuse(['note: contains an API key value — refused']);
|
|
247
|
-
let plan;
|
|
248
|
-
try { plan = JSON.parse(prev['declaration.json']); } catch { return refuse(['revise: the plan being revised is not valid JSON']); }
|
|
249
|
-
revise = { plan, note };
|
|
250
|
-
}
|
|
251
277
|
// Red messages can echo what a provider's error body echoed (a key): scrubbed like every file, before anything prints them.
|
|
252
278
|
const cleanReds = (reds) => (reds ?? []).map((r) => scrub(String(r), secrets));
|
|
253
279
|
// Claim the dir BEFORE the paid round (exclusive mkdir: a race or an existing path refuses at $0).
|
|
@@ -279,7 +305,7 @@ export async function draftToDir({
|
|
|
279
305
|
}
|
|
280
306
|
};
|
|
281
307
|
const result = await draft({
|
|
282
|
-
proseText: prose.text, slot, model, budgetUsd, provider, rates, modelId, env, onBook,
|
|
308
|
+
proseText: prose.text, slot, model, budgetUsd, provider, rates, modelId, env, onBook, offerQuestions: !noQuestions,
|
|
283
309
|
});
|
|
284
310
|
if (result.stop === 'pre-flight') {
|
|
285
311
|
try { rmdirSync(dir); } catch { /* the claimed dir is still empty; leave it rather than mask the refusal */ }
|
|
@@ -297,7 +323,10 @@ export async function draftToDir({
|
|
|
297
323
|
files['prose.txt'] = prose.text; // verbatim
|
|
298
324
|
const targetText = dj({ root, name });
|
|
299
325
|
files['target.json'] = targetText;
|
|
300
|
-
|
|
326
|
+
// Amendments 24/25: the questions and the drafter's own "not checked" reading are written BEFORE log.json/spec.hash (the panel reads those
|
|
327
|
+
// two as "the draft finished"), as their own files: never in the readout, so never in the hash.
|
|
328
|
+
if (result.questions?.length) files[QUESTIONS_FILE] = scrub(dj({ questions: result.questions }), secrets);
|
|
329
|
+
files[NOT_CHECKED_FILE] = scrub(dj({ notChecked: result.notChecked ?? [] }), secrets);
|
|
301
330
|
files['log.json'] = scrub(dj({
|
|
302
331
|
ok: result.ok, stop: result.stop, reds: result.reds, rounds: result.rounds, calls: result.calls, costUsd: result.costUsd, spendComplete: result.spendComplete,
|
|
303
332
|
modelId: result.modelId, modelReturned: result.modelReturned, structureRetries: result.structureRetries,
|
|
@@ -354,7 +383,7 @@ export async function draftToDir({
|
|
|
354
383
|
return paidFail(`write failed after the paid round (${e.code ?? e.message}); the draft dir is incomplete and never signable`);
|
|
355
384
|
}
|
|
356
385
|
return {
|
|
357
|
-
ok: result.ok, wrote: true, dir, hash, reds: cleanReds(result.reds), costUsd: result.costUsd, spendComplete: result.spendComplete, stop: result.stop, rounds: result.rounds, calls: result.calls, leaks: 0,
|
|
386
|
+
ok: result.ok, wrote: true, dir, hash, questions: result.questions?.length ?? 0, reds: cleanReds(result.reds), costUsd: result.costUsd, spendComplete: result.spendComplete, stop: result.stop, rounds: result.rounds, calls: result.calls, leaks: 0,
|
|
358
387
|
};
|
|
359
388
|
}
|
|
360
389
|
|
|
@@ -362,12 +391,17 @@ export async function draftToDir({
|
|
|
362
391
|
* The human step, $0. Every refusal returns reds and writes NO flow.
|
|
363
392
|
* `signedBy` must come from the human's own invocation (the CLI's --signed-by/username).
|
|
364
393
|
* `sessionDir` (the panel's draft folder: card, notes, every change) widens the setup record; the CLI has none, so its record is the one plan folder.
|
|
394
|
+
* M6: `replaces: {flowHash}` (a draft opened from an existing signed job, carrying that job's signature hash) makes this sign REPLACE that job
|
|
395
|
+
* (`writeFlow` checks the hash is still the job's); without it a taken name is refused as ever.
|
|
396
|
+
* @param {{dir: any, approve?: any, signedBy: any, signedAt?: string, env?: Record<string, string|undefined>, sessionDir?: string, replaces?: {flowHash: string}}} a
|
|
365
397
|
*/
|
|
366
398
|
export function signDraft({
|
|
367
|
-
dir, approve, signedBy, signedAt = new Date().toISOString(), env = process.env, sessionDir,
|
|
399
|
+
dir, approve, signedBy, signedAt = new Date().toISOString(), env = process.env, sessionDir, replaces,
|
|
368
400
|
}) {
|
|
369
401
|
const refuse = (...reds) => ({ ok: false, reds });
|
|
370
402
|
if (readFileInside(dir, LEAK_MARKER_FILE).ok) return refuse(`sign: "${dir}" carries a key-leak marker (${LEAK_MARKER_FILE}) — never signed`);
|
|
403
|
+
const openQuestion = questionsRefusal(dir);
|
|
404
|
+
if (openQuestion !== null) return refuse(`sign: ${openQuestion}`);
|
|
371
405
|
// Sign is $0 and takes no key, so it can only sweep for keys present in ITS env (any provider slot's).
|
|
372
406
|
// With none set the sweep is skipped: the marker above and the missing spec.hash are then the guard.
|
|
373
407
|
const keys = Object.values(PROVIDER_SLOTS).map((p) => env[p.envVar]).filter(Boolean);
|
|
@@ -417,7 +451,7 @@ export function signDraft({
|
|
|
417
451
|
if (reds.length) return { ok: false, reds };
|
|
418
452
|
|
|
419
453
|
const written = writeFlow({
|
|
420
|
-
root: target.root, name: target.name, proseText: parts['prose.txt'], declaration, signedBy, signedAt, catalogue: cat.primitives,
|
|
454
|
+
root: target.root, name: target.name, proseText: parts['prose.txt'], declaration, signedBy, signedAt, catalogue: cat.primitives, replaces,
|
|
421
455
|
});
|
|
422
456
|
if (!written.ok) return { ok: false, reds: written.reds };
|
|
423
457
|
// M4e amendment 6 item 4: the draft's record goes into the flow folder once, outside the three signed files. The flow IS signed by now, so a
|
package/src/canrun.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// preflight refusal says the same words. A flow the run would refuse at preflight (a signature that does not check out; a step granting a
|
|
3
3
|
// verb with no wired implementation) is not offered. Reads only; writes nothing. `WIRED_VERBS` stays the one list (src/primitives.js).
|
|
4
4
|
import { WIRED_VERBS } from './primitives.js';
|
|
5
|
+
import { buildSoftgreenRubric } from './closers.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* The first step granting a verb that has no wired implementation, or null. (A verb absent from the catalogue entirely is caught earlier,
|
|
@@ -23,14 +24,83 @@ export function unwiredRed(found) {
|
|
|
23
24
|
return `preflight: step "${found.step.emits}" (line ${found.step.fromLine}) grants verb "${found.verb}", which has no wired implementation`;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/** bareguard refuses a signed name or phrase past this many characters (rubric MAX_SIGNED_LEN). */
|
|
28
|
+
const MAX_ENTRY_CHARS = 1000;
|
|
29
|
+
const SIGN_AGAIN = 'and sign the job again';
|
|
30
|
+
const clipText = (t, n = 40) => (t.length > n ? `${t.slice(0, n)}...` : t);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* M4e amendment 23: the ONE function that turns "this step's check cannot be built" into a plain sentence. It reads the shape, never
|
|
34
|
+
* bareguard's wording, so no `spec.` path or `checks[` index can reach a human. The steps are numbered by the job line they came from
|
|
35
|
+
* ("line 3" elsewhere), so "step 3" is job line 3. What it throws away: the raw reason (kept apart as `detail`) and any second problem
|
|
36
|
+
* in the same shape (the first one found is the one said). A shape it cannot classify gets the generic sentence.
|
|
37
|
+
* @param {number|undefined} n the step's job line
|
|
38
|
+
* @param {Record<string, any>} shape
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function unbuildableSay(n, shape) {
|
|
42
|
+
const head = `This flow will not run: step ${n}'s`;
|
|
43
|
+
const lists = [['sections', 'section name', 'section list'], ['mustCarry', 'required phrase', 'required-phrase list']];
|
|
44
|
+
for (const [key, one, whole] of lists) {
|
|
45
|
+
const list = shape[key];
|
|
46
|
+
if (!Array.isArray(list)) continue;
|
|
47
|
+
if (list.length === 0) return `${head} ${whole} is empty. Name at least one, or remove the list, ${SIGN_AGAIN}.`;
|
|
48
|
+
for (const entry of list) {
|
|
49
|
+
if (typeof entry !== 'string') continue;
|
|
50
|
+
if (entry.trim() === '') return `${head} ${one} is blank. Fill it in or remove it, ${SIGN_AGAIN}.`;
|
|
51
|
+
if (entry.length > MAX_ENTRY_CHARS) return `${head} ${one} "${clipText(entry)}" is ${entry.length} characters, and the most one may be is ${MAX_ENTRY_CHARS}. Shorten it ${SIGN_AGAIN}.`;
|
|
52
|
+
if (key === 'sections' && entry.trim().endsWith(':')) return `${head} ${one} "${entry}" ends in ':'. Remove the ':' ${SIGN_AGAIN}.`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const noSections = !Array.isArray(shape.sections) || shape.sections.length === 0;
|
|
56
|
+
if (shape.wordsPerSection !== undefined && noSections) return `${head} check sets a size for each section but names no sections. Name the sections or remove the size, ${SIGN_AGAIN}.`;
|
|
57
|
+
if ((shape.linesPerInvoice === undefined) !== (shape.mustCarry === undefined)) {
|
|
58
|
+
const have = shape.linesPerInvoice === undefined ? 'the words each invoice must carry' : 'the lines in each invoice';
|
|
59
|
+
return `${head} invoice check has ${have} but not the other half. Add the missing half or remove this one, ${SIGN_AGAIN}.`;
|
|
60
|
+
}
|
|
61
|
+
return `This flow will not run: step ${n}'s check cannot be built. Draft the job again.`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* M4e amendment 19 4: the first softgreen step whose check bareguard cannot build (a flow signed before amendment 18 may hold one), or null.
|
|
66
|
+
* Built with the same `buildSoftgreenRubric` the close uses, so a step that passes here never crashes at its close for want of a check.
|
|
67
|
+
* `why` is bareguard's raw reason, for the record only (amendment 23); `say` is the plain sentence.
|
|
68
|
+
* @param {Record<string, any>} declaration `readFlow`'s declaration
|
|
69
|
+
* @returns {{step: {emits: string, fromLine: number}, why: string, say: string}|null}
|
|
70
|
+
*/
|
|
71
|
+
export function findUnbuildableCheckStep(declaration) {
|
|
72
|
+
for (const step of declaration.steps) {
|
|
73
|
+
if (step.close?.class !== 'softgreen') continue;
|
|
74
|
+
try {
|
|
75
|
+
buildSoftgreenRubric(step.close.shape ?? {});
|
|
76
|
+
} catch (err) {
|
|
77
|
+
return { step, why: String(err.message).replace(/^invalid rubric: /, ''), say: unbuildableSay(step.fromLine, step.close.shape ?? {}) };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The preflight refusal sentence for a check that cannot be built: plain words, never bareguard's (that is `found.why`). @param {{say: string}} found */
|
|
84
|
+
export function unbuildableRed(found) {
|
|
85
|
+
return found.say;
|
|
86
|
+
}
|
|
87
|
+
|
|
26
88
|
/**
|
|
27
89
|
* Can this flow run? `read` is `readFlow`'s result (a failed read — signature, tampering, missing files — is a refusal with its own reds).
|
|
28
90
|
* @param {any} read
|
|
29
|
-
* @returns {{ok: true} | {ok: false, red: string}}
|
|
91
|
+
* @returns {{ok: true} | {ok: false, red: string, detail?: string}} `detail` is the raw reason, for the record, never the sentence
|
|
30
92
|
*/
|
|
31
93
|
export function canFlowRun(read) {
|
|
32
94
|
if (!read || read.ok !== true) return { ok: false, red: String(read?.reds?.[0] ?? 'the flow does not read') };
|
|
33
95
|
const unwired = findUnwiredVerbStep(read.declaration);
|
|
34
96
|
if (unwired) return { ok: false, red: unwiredRed(unwired) };
|
|
97
|
+
const unbuildable = findUnbuildableCheckStep(read.declaration);
|
|
98
|
+
if (unbuildable) return { ok: false, red: unbuildableRed(unbuildable), detail: unbuildable.why };
|
|
35
99
|
return { ok: true };
|
|
36
100
|
}
|
|
101
|
+
|
|
102
|
+
/** The one sentence for a signed flow that will not run: the panel's run door (the POST /api/author/run 409) and Run again say the same words. The Signed list no longer shows a refused flow. @param {string} flow @param {string} red */
|
|
103
|
+
export function willNotRunSay(flow, red) {
|
|
104
|
+
if (red.startsWith('This flow will not run:')) return red; // amendment 23: already a whole sentence
|
|
105
|
+
return `"${flow}" will not run: ${red}`;
|
|
106
|
+
}
|
package/src/catalogue.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 1,
|
|
3
3
|
"primitives": [
|
|
4
4
|
{
|
|
5
|
-
"verb": "write", "component": "write", "package": "bare-agent/tools", "symbol": "createShellTools", "tool": "shell_write", "class": "write", "skill": "core", "desc": "Create or overwrite a file with given contents."
|
|
5
|
+
"verb": "write", "component": "write", "package": "bare-agent/tools", "symbol": "createShellTools", "tool": "shell_write", "class": "write", "skill": "core", "desc": "Create or overwrite a file with given contents. Never granted to a step whose check reads its reply (softgreen)."
|
|
6
6
|
},
|
|
7
7
|
{
|
|
8
|
-
"verb": "edit", "component": "write", "package": "bare-agent/tools", "symbol": "createShellTools", "tool": "shell_edit", "class": "write", "skill": "core", "desc": "Change part of an existing file in place."
|
|
8
|
+
"verb": "edit", "component": "write", "package": "bare-agent/tools", "symbol": "createShellTools", "tool": "shell_edit", "class": "write", "skill": "core", "desc": "Change part of an existing file in place. Never granted to a step whose check reads its reply (softgreen)."
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"verb": "read", "component": "select", "package": "bare-agent/tools", "symbol": "createShellTools", "tool": "shell_read", "class": "read", "skill": "core", "desc": "Read a file's text."
|
package/src/checked.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// M4e amendments 24 item 6, 25: "Checked" and "Not checked" at sign.
|
|
2
|
+
//
|
|
3
|
+
// CHECKED is built here, by code, from the plan's TYPED closes (`close.class` and `close.shape`) — never from model text. It says only what a
|
|
4
|
+
// typed check really does (src/closers.js): `green` recomputes a cited figure; `softgreen` runs the declared shape (headings in order, word
|
|
5
|
+
// ceilings, lines per invoice and the fields each block carries); `hitl` has no content check — a human reads it at the ask. A shape key that is
|
|
6
|
+
// not in SHAPE_KEYS has no sentence, so a key the closers do not run can never be listed as checked.
|
|
7
|
+
//
|
|
8
|
+
// NOT CHECKED is the drafter's own reading (a list of short phrases it wrote in the same call). It is information only: shown with its label,
|
|
9
|
+
// never signed, never in the readout, never in the spec hash. What this throws away: anything the drafter did not list; the list is not complete.
|
|
10
|
+
|
|
11
|
+
/** The label that always sits with the "Not checked" list (am41 item 3: the ONE place these words live; the Job tab and the Chat card read it off their payloads). */
|
|
12
|
+
export const NOT_CHECKED_LABEL = "not checked (the AI's own reading)";
|
|
13
|
+
|
|
14
|
+
const list = (xs) => xs.join(', ');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* One entry per step, in plan order: the plain sentences for what its typed close checks.
|
|
18
|
+
* @param {{ steps?: any[] }} declaration @param {{ hasAsk?: boolean, askLines?: number[] }} [opts] hasAsk = the job has a signed ask line (so "you check it at the ask" is true);
|
|
19
|
+
* askLines = the job lines of the signed asks, which also lets a step after the LAST ask read "you check it after you accept" (am41 item 2, am42: the ONE place for these words)
|
|
20
|
+
* @returns {{ step: number, line: number|null, goal: string, class: string, sentences: string[] }[]}
|
|
21
|
+
*/
|
|
22
|
+
export function checkedLines(declaration, { hasAsk = true, askLines } = {}) {
|
|
23
|
+
const steps = Array.isArray(declaration?.steps) ? declaration.steps : [];
|
|
24
|
+
if (Array.isArray(askLines)) hasAsk = askLines.length > 0;
|
|
25
|
+
const lastAsk = Array.isArray(askLines) ? steps.reduce((m, st, i) => (askLines.includes(st?.fromLine) ? i : m), -1) : -1;
|
|
26
|
+
return steps.map((st, i) => {
|
|
27
|
+
const cls = st?.close?.class;
|
|
28
|
+
const shape = st?.close?.shape && typeof st.close.shape === 'object' ? st.close.shape : {};
|
|
29
|
+
/** @type {string[]} */
|
|
30
|
+
const out = [];
|
|
31
|
+
if (cls === 'green') {
|
|
32
|
+
out.push('Every figure must cite its source cell, or a formula over cells, and the machine recomputes it and compares it with its source.');
|
|
33
|
+
} else if (cls === 'softgreen') {
|
|
34
|
+
out.push('The reply is checked as plain text only.');
|
|
35
|
+
if (Number.isInteger(shape.maxWords)) out.push(`The whole output is under ${shape.maxWords} words.`);
|
|
36
|
+
if (Array.isArray(shape.sections) && shape.sections.length > 0) out.push(`These section headings are there, in this order: ${list(shape.sections)}.`);
|
|
37
|
+
if (Number.isInteger(shape.wordsPerSection) && Array.isArray(shape.sections) && shape.sections.length > 0) out.push(`Each of those sections is about ${shape.wordsPerSection} words.`);
|
|
38
|
+
if (Number.isInteger(shape.linesPerInvoice)) out.push(`The output comes in blocks of ${shape.linesPerInvoice} lines.`);
|
|
39
|
+
if (Array.isArray(shape.mustCarry) && shape.mustCarry.length > 0) out.push(`Every block carries: ${list(shape.mustCarry)}.`);
|
|
40
|
+
} else {
|
|
41
|
+
if (lastAsk !== -1 && i > lastAsk) out.push('No machine check of the content; you check it after you accept.');
|
|
42
|
+
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.');
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
step: i + 1, line: Number.isInteger(st?.fromLine) ? st.fromLine : null, goal: typeof st?.goal === 'string' ? st.goal : '', class: String(cls), sentences: out,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The "Not checked" block the page shows: always the label, then the drafter's items (an empty list says the drafter listed nothing). @param {unknown} items */
|
|
51
|
+
export function notCheckedBlock(items) {
|
|
52
|
+
const clean = Array.isArray(items) ? items.filter((x) => typeof x === 'string' && x.trim() !== '').map((x) => x.trim()) : [];
|
|
53
|
+
return { label: NOT_CHECKED_LABEL, items: clean };
|
|
54
|
+
}
|