fwdloop 0.6.0 → 0.8.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 +221 -64
- package/package.json +5 -5
- package/src/ask.js +260 -6
- package/src/authoring.js +313 -0
- package/src/books.js +209 -2
- package/src/catalogue.json +1 -1
- package/src/declaration.js +16 -2
- package/src/docx.js +33 -4
- package/src/drafter.js +324 -0
- package/src/flow.js +247 -2
- package/src/index.js +9 -3
- package/src/input-facts.js +45 -0
- package/src/model-step.js +151 -12
- package/src/panel/data.js +1589 -0
- package/src/panel/index.html +2377 -0
- package/src/panel/server.js +268 -0
- package/src/primitives.js +146 -42
- package/src/provider.js +61 -43
- package/src/runner.js +393 -54
- package/src/send.js +20 -1
- package/src/sign-confirm.js +27 -0
- package/src/signed-text.js +19 -5
- package/src/types.js +19 -0
- package/types/ask.d.ts +77 -0
- package/types/authoring.d.ts +132 -0
- package/types/books.d.ts +70 -2
- package/types/declaration.d.ts +7 -1
- package/types/docx.d.ts +8 -0
- package/types/drafter.d.ts +164 -0
- package/types/flow.d.ts +135 -0
- package/types/index.d.ts +5 -3
- package/types/input-facts.d.ts +14 -0
- package/types/panel/data.d.ts +433 -0
- package/types/panel/server.d.ts +45 -0
- package/types/primitives.d.ts +33 -0
- package/types/provider.d.ts +14 -1
- package/types/runner.d.ts +66 -5
- package/types/sign-confirm.d.ts +18 -0
- package/types/signed-text.d.ts +14 -0
- package/types/types.d.ts +45 -0
package/bin/fwdloop
CHANGED
|
@@ -15,21 +15,27 @@
|
|
|
15
15
|
// from poc/, and poc/ is not part of the published package.
|
|
16
16
|
|
|
17
17
|
import { parseArgs } from 'node:util';
|
|
18
|
-
import {
|
|
19
|
-
existsSync, mkdirSync, readFileSync, readdirSync,
|
|
20
|
-
} from 'node:fs';
|
|
18
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
21
19
|
import { extname, join, resolve } from 'node:path';
|
|
22
20
|
import { pathToFileURL } from 'node:url';
|
|
23
21
|
import { randomUUID } from 'node:crypto';
|
|
24
22
|
|
|
25
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
readFlow, checkFlowName, resolveRunDir, listFlowNames, listRunIds, readFileInside,
|
|
25
|
+
} from '../src/flow.js';
|
|
26
26
|
import { loadCatalogue } from '../src/catalogue.js';
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
runFlow, resumeRun, makeParkingAskStep, readAsk,
|
|
29
|
+
} from '../src/runner.js';
|
|
28
30
|
import { makeLiveModelStep } from '../src/model-step.js';
|
|
29
31
|
import { sendViaPrimitive } from '../src/send.js';
|
|
30
32
|
import { resolvePrimitives } from '../src/primitives.js';
|
|
31
33
|
import { checkKeyPreflight } from '../src/provider.js';
|
|
32
|
-
import { answerAsk } from '../src/ask.js';
|
|
34
|
+
import { answerAsk, readAskEvidence } from '../src/ask.js';
|
|
35
|
+
import { panelMain } from '../src/panel/server.js';
|
|
36
|
+
import { isInteractive, confirmTypedName, NEEDS_TTY } from '../src/sign-confirm.js';
|
|
37
|
+
import { draftToDir, signDraft, SIGN_LINE, costText } from '../src/authoring.js';
|
|
38
|
+
import { userInfo } from 'node:os';
|
|
33
39
|
|
|
34
40
|
// The baseline model (project rule, CLAUDE.md/AGENT_RULES: "deepseek-flash
|
|
35
41
|
// ... Never Claude for fwdloop's own runs") — the ONE provider slot this CLI
|
|
@@ -42,6 +48,21 @@ function fail(message) {
|
|
|
42
48
|
process.exit(1);
|
|
43
49
|
}
|
|
44
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The ONE place a human-typed `--root` becomes a path (hamr ruling
|
|
53
|
+
* 2026-09-29): resolved to its real path once, at command start. Nothing
|
|
54
|
+
* inside the root is ever followed; that stays under bareguard's symlink
|
|
55
|
+
* refusal.
|
|
56
|
+
*/
|
|
57
|
+
function resolveRoot(cmd, given) {
|
|
58
|
+
try {
|
|
59
|
+
return realpathSync(resolve(given));
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (err.code === 'ENOENT') fail(`${cmd}: --root "${given}" does not exist`);
|
|
62
|
+
fail(`${cmd}: --root "${given}" cannot be resolved: ${err.code ?? err.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
45
66
|
function today() {
|
|
46
67
|
return new Date().toISOString().slice(0, 10);
|
|
47
68
|
}
|
|
@@ -88,25 +109,23 @@ function parseSourceFlags(list) {
|
|
|
88
109
|
return out;
|
|
89
110
|
}
|
|
90
111
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
112
|
+
// F48 round 3 (docs/logs/FINDINGS.md): this CLI must never build a run path
|
|
113
|
+
// by hand — every flow/runId it walks goes through `listFlowNames`/
|
|
114
|
+
// `listRunIds`/`resolveRunDir` (`src/flow.js`, the same checked builders
|
|
115
|
+
// `src/panel/data.js` already uses), and every `ask.json` it reads goes
|
|
116
|
+
// through `readAsk` (`src/runner.js`, itself routed through
|
|
117
|
+
// `readFileInside`) — never a private `join()` + raw `readFileSync`. Closes
|
|
118
|
+
// the CLI-side half of F48: a symlinked flow/run/ask.json (or a hand-placed
|
|
119
|
+
// directory whose name would fail `checkFlowName`/`checkRunId`) is skipped
|
|
120
|
+
// here exactly as it already is by the panel, instead of being followed.
|
|
96
121
|
function findRunDirByAskId(root, askId) {
|
|
97
|
-
for (const flow of
|
|
98
|
-
const
|
|
99
|
-
for (const runId of
|
|
100
|
-
const
|
|
101
|
-
if (!
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
ask = JSON.parse(readFileSync(askPath, 'utf8'));
|
|
105
|
-
} catch {
|
|
106
|
-
// eslint-disable-next-line no-continue
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (ask.askId === askId) return join(runsDir, runId);
|
|
122
|
+
for (const flow of listFlowNames(root)) {
|
|
123
|
+
const flowDir = join(root, flow);
|
|
124
|
+
for (const runId of listRunIds(flowDir)) {
|
|
125
|
+
const resolved = resolveRunDir(flowDir, runId);
|
|
126
|
+
if (!resolved.ok) continue; // eslint-disable-line no-continue
|
|
127
|
+
const ask = readAsk(resolved.runDir);
|
|
128
|
+
if (ask && ask.askId === askId) return resolved.runDir;
|
|
110
129
|
}
|
|
111
130
|
}
|
|
112
131
|
return null;
|
|
@@ -160,7 +179,7 @@ async function cmdRun(rest) {
|
|
|
160
179
|
if (!flowName) fail('run: a flow name is required — fwdloop run <flow> --root <dir> --source <role>=<path> ...');
|
|
161
180
|
if (!values.root) fail('run: --root <dir> is required');
|
|
162
181
|
|
|
163
|
-
const root =
|
|
182
|
+
const root = resolveRoot('run', values.root);
|
|
164
183
|
const nameCheck = checkFlowName(flowName);
|
|
165
184
|
if (!nameCheck.ok) fail(nameCheck.red);
|
|
166
185
|
|
|
@@ -196,7 +215,9 @@ async function cmdRun(rest) {
|
|
|
196
215
|
}
|
|
197
216
|
|
|
198
217
|
const runId = values['run-id'] ?? `run-${Date.now().toString(36)}-${randomUUID().slice(0, 8)}`;
|
|
199
|
-
const
|
|
218
|
+
const runIdCheck = resolveRunDir(join(root, flowName), runId);
|
|
219
|
+
if (!runIdCheck.ok) fail(runIdCheck.red);
|
|
220
|
+
const { runDir } = runIdCheck;
|
|
200
221
|
if (existsSync(runDir)) fail(`run: run dir "${runDir}" already exists — use a new --run-id`);
|
|
201
222
|
|
|
202
223
|
// The key preflight (item A: "refuses at $0 BEFORE any book write") runs
|
|
@@ -212,12 +233,16 @@ async function cmdRun(rest) {
|
|
|
212
233
|
|
|
213
234
|
// Predict the frozen input paths `runFlow`'s own `freezeInputs` will use
|
|
214
235
|
// (deterministic: `<runDir>/inputs/<id><ext>`) so the primitives map can
|
|
215
|
-
// be built once, before `runFlow` itself freezes anything.
|
|
216
|
-
|
|
236
|
+
// be built once, before `runFlow` itself freezes anything. Pure path
|
|
237
|
+
// arithmetic — `resolvePrimitives` only needs the STRINGS, never the
|
|
238
|
+
// directory to actually exist yet — so nothing under `runDir` is created
|
|
239
|
+
// here. `runFlow` itself now carries the F46 unwired-verb preflight
|
|
240
|
+
// refusal (moved to `src/runner.js` so any caller — this CLI, M4's web
|
|
241
|
+
// panel — gets it for free); it also owns the ONLY `mkdirSync`/
|
|
242
|
+
// `freezeInputs` for this run dir, so a refusal leaves nothing behind.
|
|
217
243
|
const predictedInputs = sources.map((s) => ({ id: s.id, frozen: join(runDir, 'inputs', `${s.id}${extname(s.path)}`) }));
|
|
218
244
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
219
245
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, { runDir, inputs: predictedInputs });
|
|
220
|
-
for (const red of primitiveReds) process.stderr.write(`run: ${red}\n`);
|
|
221
246
|
|
|
222
247
|
const result = await runFlow({
|
|
223
248
|
root,
|
|
@@ -229,6 +254,7 @@ async function cmdRun(rest) {
|
|
|
229
254
|
askStep: makeParkingAskStep(),
|
|
230
255
|
sendStep: sendViaPrimitive,
|
|
231
256
|
primitives,
|
|
257
|
+
primitiveReds,
|
|
232
258
|
businessDate: today(),
|
|
233
259
|
});
|
|
234
260
|
|
|
@@ -244,19 +270,25 @@ function cmdInbox(rest) {
|
|
|
244
270
|
args: rest,
|
|
245
271
|
options: { root: { type: 'string' } },
|
|
246
272
|
});
|
|
247
|
-
const root =
|
|
248
|
-
if (!existsSync(root)) fail(`inbox: root "${root}" does not exist`);
|
|
273
|
+
const root = resolveRoot('inbox', values.root ?? '.');
|
|
249
274
|
|
|
250
275
|
const rows = [];
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
276
|
+
// F48 round 3: flow/run identity is walked via `listFlowNames`/
|
|
277
|
+
// `listRunIds`/`resolveRunDir` (never a private `join()`), and `ask.json`
|
|
278
|
+
// is read via `readFileInside` (both `src/flow.js`) — a symlinked
|
|
279
|
+
// ask.json, or a symlinked run/flow dir, is treated as "missing" here,
|
|
280
|
+
// never followed.
|
|
281
|
+
for (const flow of listFlowNames(root)) {
|
|
282
|
+
const flowDir = join(root, flow);
|
|
283
|
+
for (const runId of listRunIds(flowDir)) {
|
|
284
|
+
const resolved = resolveRunDir(flowDir, runId);
|
|
285
|
+
if (!resolved.ok) continue; // eslint-disable-line no-continue
|
|
286
|
+
const runDir = resolved.runDir;
|
|
287
|
+
const askRead = readFileInside(runDir, 'ask.json');
|
|
288
|
+
if (!askRead.ok) continue; // eslint-disable-line no-continue -- missing (or refused) ask.json: nothing to show
|
|
257
289
|
let ask;
|
|
258
290
|
try {
|
|
259
|
-
ask = JSON.parse(
|
|
291
|
+
ask = JSON.parse(askRead.text);
|
|
260
292
|
} catch (err) {
|
|
261
293
|
// A malformed/unparseable ask.json must never crash inbox — show it
|
|
262
294
|
// naming the run as unreadable and move on to the next one.
|
|
@@ -276,8 +308,10 @@ function cmdInbox(rest) {
|
|
|
276
308
|
// Signed item 6: expiry is checked whenever anyone touches the run —
|
|
277
309
|
// for `inbox` that means SHOWING an expired ask, never cancelling it
|
|
278
310
|
// (cancelling happens only at answer/resume, which re-verify anyway).
|
|
279
|
-
|
|
280
|
-
|
|
311
|
+
// Consumed-marker check also goes through `readFileInside` — a
|
|
312
|
+
// symlinked consumed marker is treated as "not consumed" (still shown
|
|
313
|
+
// as open/expired), never as proof the ask was answered.
|
|
314
|
+
if (readFileInside(runDir, `answer.${ask.askId}.consumed.json`).ok) continue; // eslint-disable-line no-continue -- this specific ask is already answered
|
|
281
315
|
// A present-but-unparseable expiresAt (Date.parse -> NaN) must never
|
|
282
316
|
// read as "not expired" — `Date.now() > NaN` is false, so the naive
|
|
283
317
|
// compare below would show this as [open] with a "NaNs left"
|
|
@@ -323,11 +357,6 @@ function cmdInbox(rest) {
|
|
|
323
357
|
// is how a human actually sees what they'd be accepting. Never writes.
|
|
324
358
|
// ---------------------------------------------------------------------------
|
|
325
359
|
|
|
326
|
-
function artifactText(artifact) {
|
|
327
|
-
if (artifact && typeof artifact === 'object' && typeof artifact.text === 'string') return artifact.text;
|
|
328
|
-
return JSON.stringify(artifact, null, 2);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
360
|
function cmdShow(rest) {
|
|
332
361
|
const { values, positionals } = parseArgs({
|
|
333
362
|
args: rest,
|
|
@@ -337,14 +366,22 @@ function cmdShow(rest) {
|
|
|
337
366
|
const [askId] = positionals;
|
|
338
367
|
if (!askId) fail('show: an askId is required — fwdloop show <askId> --root <dir>');
|
|
339
368
|
|
|
340
|
-
const root =
|
|
341
|
-
if (!existsSync(root)) fail(`show: root "${root}" does not exist`);
|
|
369
|
+
const root = resolveRoot('show', values.root ?? '.');
|
|
342
370
|
const runDir = findRunDirByAskId(root, askId);
|
|
343
371
|
if (!runDir) fail(`show: no open ask found for askId "${askId}" under ${root}`);
|
|
344
372
|
|
|
373
|
+
// F48 round 3: routed through `readFileInside` (`src/flow.js`) — a
|
|
374
|
+
// symlinked ask.json is refused by name here, never read through.
|
|
375
|
+
const askRead = readFileInside(runDir, 'ask.json');
|
|
376
|
+
if (!askRead.ok) {
|
|
377
|
+
fail(askRead.missing
|
|
378
|
+
? `show: no ask.json for askId "${askId}"`
|
|
379
|
+
: `show: ask.json for askId "${askId}" — ${askRead.red}`);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
345
382
|
let ask;
|
|
346
383
|
try {
|
|
347
|
-
ask = JSON.parse(
|
|
384
|
+
ask = JSON.parse(askRead.text);
|
|
348
385
|
} catch (err) {
|
|
349
386
|
fail(`show: ask.json for askId "${askId}" is not valid JSON — ${err.message}`);
|
|
350
387
|
return;
|
|
@@ -353,16 +390,16 @@ function cmdShow(rest) {
|
|
|
353
390
|
process.stdout.write(`question: ${ask.question}\n`);
|
|
354
391
|
process.stdout.write(`expiresAt: ${ask.expiresAt}\n`);
|
|
355
392
|
|
|
356
|
-
const
|
|
357
|
-
if (!
|
|
358
|
-
process.stdout.write(
|
|
393
|
+
const { draft, unjudged, why } = readAskEvidence(ask);
|
|
394
|
+
if (!draft) {
|
|
395
|
+
process.stdout.write(`\n(no evidence recorded on this ask — ${why})\n`);
|
|
359
396
|
return;
|
|
360
397
|
}
|
|
361
398
|
process.stdout.write('\n--- artifact under review ---\n');
|
|
362
|
-
process.stdout.write(`${
|
|
363
|
-
for (const item of
|
|
364
|
-
process.stdout.write(`\n--- unjudged: ${item.step
|
|
365
|
-
process.stdout.write(`${
|
|
399
|
+
process.stdout.write(`${draft.text}\n`);
|
|
400
|
+
for (const item of unjudged) {
|
|
401
|
+
process.stdout.write(`\n--- unjudged: ${item.step} ---\n`);
|
|
402
|
+
process.stdout.write(`${item.text}\n`);
|
|
366
403
|
}
|
|
367
404
|
}
|
|
368
405
|
|
|
@@ -380,8 +417,7 @@ function cmdAnswer(rest) {
|
|
|
380
417
|
if (!askId) fail('answer: an askId is required — fwdloop answer <askId> accept|reject "<reason>"|rerun "<reason>"');
|
|
381
418
|
if (!decision) fail(`answer: a decision (accept|reject|rerun) is required for askId "${askId}"`);
|
|
382
419
|
|
|
383
|
-
const root =
|
|
384
|
-
if (!existsSync(root)) fail(`answer: root "${root}" does not exist`);
|
|
420
|
+
const root = resolveRoot('answer', values.root ?? '.');
|
|
385
421
|
const runDir = findRunDirByAskId(root, askId);
|
|
386
422
|
if (!runDir) fail(`answer: no open ask found for askId "${askId}" under ${root}`);
|
|
387
423
|
|
|
@@ -411,7 +447,7 @@ async function cmdResume(rest) {
|
|
|
411
447
|
if (!values.flow) fail('resume: --flow <name> is required');
|
|
412
448
|
if (!values.root) fail('resume: --root <dir> is required');
|
|
413
449
|
|
|
414
|
-
const root =
|
|
450
|
+
const root = resolveRoot('resume', values.root);
|
|
415
451
|
const flowName = values.flow;
|
|
416
452
|
|
|
417
453
|
const loaded = loadCatalogue();
|
|
@@ -422,7 +458,9 @@ async function cmdResume(rest) {
|
|
|
422
458
|
if (!read.ok) fail(`flow "${flowName}": ${read.reds.join('; ')}`);
|
|
423
459
|
const { declaration } = read;
|
|
424
460
|
|
|
425
|
-
const
|
|
461
|
+
const runIdCheck = resolveRunDir(join(root, flowName), runId);
|
|
462
|
+
if (!runIdCheck.ok) fail(runIdCheck.red);
|
|
463
|
+
const { runDir } = runIdCheck;
|
|
426
464
|
if (!existsSync(runDir)) fail(`resume: no run dir for runId "${runId}" under flow "${flowName}"`);
|
|
427
465
|
|
|
428
466
|
const spendPath = join(runDir, 'spend.jsonl');
|
|
@@ -437,13 +475,27 @@ async function cmdResume(rest) {
|
|
|
437
475
|
// Resume never re-freezes inputs — the run's own `inputs.json` (written at
|
|
438
476
|
// park by `freezeInputs`) is the one source of the already-frozen paths a
|
|
439
477
|
// sandboxed primitive may read.
|
|
440
|
-
|
|
441
|
-
|
|
478
|
+
// F48 round 3: routed through `readFileInside` (`src/flow.js`) — a
|
|
479
|
+
// symlinked `inputs.json` is treated as "no manifest" (empty array) rather
|
|
480
|
+
// than followed, which would otherwise let an outside file's content name
|
|
481
|
+
// arbitrary "frozen" paths for the sandboxed read/grep/readDocx/
|
|
482
|
+
// addressCells tools built just below.
|
|
483
|
+
const inputsManifestRead = readFileInside(runDir, 'inputs.json');
|
|
484
|
+
let inputsManifest = [];
|
|
485
|
+
if (inputsManifestRead.ok) {
|
|
486
|
+
try {
|
|
487
|
+
inputsManifest = JSON.parse(inputsManifestRead.text);
|
|
488
|
+
} catch (err) {
|
|
489
|
+
fail(`resume: inputs.json for run "${runId}" is not valid JSON — ${err.message}`);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
442
493
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
494
|
+
// F46's unwired-verb preflight refusal now lives in `resumeRun` itself
|
|
495
|
+
// (`src/runner.js`) — this CLI no longer keeps a second copy of the check.
|
|
443
496
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
444
497
|
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })),
|
|
445
498
|
});
|
|
446
|
-
for (const red of primitiveReds) process.stderr.write(`resume: ${red}\n`);
|
|
447
499
|
|
|
448
500
|
const result = await resumeRun({
|
|
449
501
|
root,
|
|
@@ -453,24 +505,129 @@ async function cmdResume(rest) {
|
|
|
453
505
|
modelStep,
|
|
454
506
|
sendStep: sendViaPrimitive,
|
|
455
507
|
primitives,
|
|
508
|
+
primitiveReds,
|
|
456
509
|
businessDate: today(),
|
|
457
510
|
});
|
|
458
511
|
|
|
459
512
|
reportRunResult(result, { rootArg: values.root });
|
|
460
513
|
}
|
|
461
514
|
|
|
515
|
+
// ---------------------------------------------------------------------------
|
|
516
|
+
// panel — M4a piece 2 (docs/wiki/the-module-ladder.md, "M4a — read-only
|
|
517
|
+
// panel — SIGNED"): `fwdloop panel [--port 4800] [--root <dir>]`. Read-only,
|
|
518
|
+
// GET/HEAD only, bound to 127.0.0.1 only (src/panel/server.js). Never picks
|
|
519
|
+
// a different port on collision — a taken port is a loud, non-zero-exit
|
|
520
|
+
// failure.
|
|
521
|
+
// ---------------------------------------------------------------------------
|
|
522
|
+
|
|
523
|
+
async function cmdPanel(rest) {
|
|
524
|
+
const { values } = parseArgs({
|
|
525
|
+
args: rest,
|
|
526
|
+
options: {
|
|
527
|
+
port: { type: 'string' },
|
|
528
|
+
root: { type: 'string' },
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
const root = resolveRoot('panel', values.root ?? '.');
|
|
532
|
+
|
|
533
|
+
const argv = ['--root', root];
|
|
534
|
+
if (values.port) argv.push('--port', values.port);
|
|
535
|
+
|
|
536
|
+
const code = await panelMain(argv, {
|
|
537
|
+
out: (s) => process.stdout.write(`${s}\n`),
|
|
538
|
+
err: (s) => process.stderr.write(`fwdloop: ${s}\n`),
|
|
539
|
+
});
|
|
540
|
+
process.exitCode = code;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// ---------------------------------------------------------------------------
|
|
544
|
+
// draft / sign — M6a (docs/wiki/the-module-ladder.md, "M6a — authoring
|
|
545
|
+
// backend", scope items 4-5). `draft` is the one paid step and never writes a
|
|
546
|
+
// flow; `sign` is the human step ($0) and the only path that writes one.
|
|
547
|
+
// Test-only escape hatch for draft, same two-gate shape as resolveModelStep:
|
|
548
|
+
// NODE_ENV=test AND FWDLOOP_TEST_DRAFT_PROVIDER (a module whose default export
|
|
549
|
+
// returns { provider, rates, modelId }).
|
|
550
|
+
// ---------------------------------------------------------------------------
|
|
551
|
+
|
|
552
|
+
async function cmdDraft(rest) {
|
|
553
|
+
const { values, positionals } = parseArgs({
|
|
554
|
+
args: rest,
|
|
555
|
+
options: {
|
|
556
|
+
out: { type: 'string' }, root: { type: 'string' }, name: { type: 'string' }, budget: { type: 'string' },
|
|
557
|
+
},
|
|
558
|
+
allowPositionals: true,
|
|
559
|
+
});
|
|
560
|
+
const proseFile = positionals[0];
|
|
561
|
+
if (!proseFile) fail('draft: a prose file is required — fwdloop draft <prose.txt> --out <draftDir> --root <flowsDir> --name <flow> [--budget <usd>]');
|
|
562
|
+
for (const req of ['out', 'root', 'name']) if (!values[req]) fail(`draft: --${req} is required`);
|
|
563
|
+
|
|
564
|
+
let injected = {};
|
|
565
|
+
if (process.env.NODE_ENV === 'test' && process.env.FWDLOOP_TEST_DRAFT_PROVIDER) {
|
|
566
|
+
const mod = await import(pathToFileURL(resolve(process.env.FWDLOOP_TEST_DRAFT_PROVIDER)).href);
|
|
567
|
+
injected = await mod.default();
|
|
568
|
+
}
|
|
569
|
+
const result = await draftToDir({
|
|
570
|
+
proseFile: resolve(proseFile),
|
|
571
|
+
dir: resolve(values.out),
|
|
572
|
+
root: resolve(values.root),
|
|
573
|
+
name: values.name,
|
|
574
|
+
budgetUsd: values.budget === undefined ? undefined : Number(values.budget),
|
|
575
|
+
...injected,
|
|
576
|
+
});
|
|
577
|
+
const cost = result.costUsd === null ? 'UNKNOWN' : costText(Number(result.costUsd), result.spendComplete);
|
|
578
|
+
if (!result.wrote) {
|
|
579
|
+
process.stderr.write(`fwdloop: draft refused at $0 — ${result.reds.join('; ')}\n`);
|
|
580
|
+
process.exitCode = 1;
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
process.stdout.write(`draft dir: ${resolve(values.out)} cost: ${cost}\n`);
|
|
584
|
+
if (!result.ok) {
|
|
585
|
+
process.stderr.write(`fwdloop: draft RED (${result.stop ?? 'scrub'}) — ${result.reds.join('; ')}\n`);
|
|
586
|
+
process.exitCode = 1;
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
process.stdout.write(`${SIGN_LINE(resolve(values.out), result.hash)}\n`);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
async function cmdSign(rest) {
|
|
593
|
+
const { values, positionals } = parseArgs({
|
|
594
|
+
args: rest,
|
|
595
|
+
options: { approve: { type: 'string' }, 'signed-by': { type: 'string' } },
|
|
596
|
+
allowPositionals: true,
|
|
597
|
+
});
|
|
598
|
+
const dir = positionals[0];
|
|
599
|
+
if (!dir) fail('sign: a draft dir is required — fwdloop sign <dir> --approve <hash>');
|
|
600
|
+
// Amendment 2: a person at a keyboard. TTY check first (cheapest), then the typed flow name; only then
|
|
601
|
+
// signDraft's own $0 checks (hash, wired, goals, TTL, sources, send, leak). signDraft writes only on success.
|
|
602
|
+
if (!isInteractive()) fail(`sign refused — ${NEEDS_TTY}`);
|
|
603
|
+
let flowName;
|
|
604
|
+
const tj = readFileInside(resolve(dir), 'target.json');
|
|
605
|
+
try { flowName = tj.ok ? JSON.parse(tj.text).name : undefined; } catch { flowName = undefined; }
|
|
606
|
+
if (typeof flowName !== 'string' || flowName === '') fail('sign refused — the draft has no readable target.json name');
|
|
607
|
+
const typed = await confirmTypedName({ name: flowName });
|
|
608
|
+
if (!typed.ok) fail(`sign refused — ${typed.red}`);
|
|
609
|
+
const result = signDraft({
|
|
610
|
+
dir: resolve(dir), approve: values.approve, signedBy: values['signed-by'] ?? userInfo().username,
|
|
611
|
+
});
|
|
612
|
+
if (!result.ok) fail(`sign refused — ${result.reds.join('; ')}`);
|
|
613
|
+
process.stdout.write(`signed: ${result.flowDir} (by ${result.signature.signedBy})\n`);
|
|
614
|
+
}
|
|
615
|
+
|
|
462
616
|
// ---------------------------------------------------------------------------
|
|
463
617
|
|
|
464
618
|
async function main() {
|
|
465
619
|
const [verb, ...rest] = process.argv.slice(2);
|
|
466
|
-
if (!verb) fail('usage: fwdloop run|inbox|show|answer|resume ...');
|
|
620
|
+
if (!verb) fail('usage: fwdloop draft|sign|run|inbox|show|answer|resume|panel ...');
|
|
467
621
|
|
|
622
|
+
if (verb === 'draft') return cmdDraft(rest);
|
|
623
|
+
if (verb === 'sign') return cmdSign(rest);
|
|
468
624
|
if (verb === 'run') return cmdRun(rest);
|
|
469
625
|
if (verb === 'inbox') return cmdInbox(rest);
|
|
470
626
|
if (verb === 'show') return cmdShow(rest);
|
|
471
627
|
if (verb === 'answer') return cmdAnswer(rest);
|
|
472
628
|
if (verb === 'resume') return cmdResume(rest);
|
|
473
|
-
|
|
629
|
+
if (verb === 'panel') return cmdPanel(rest);
|
|
630
|
+
fail(`unknown verb "${verb}" — expected draft | sign | run | inbox | show | answer | resume | panel`);
|
|
474
631
|
return undefined;
|
|
475
632
|
}
|
|
476
633
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"NOTICE"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"bare-agent": "^0.
|
|
53
|
-
"bareguard": "^0.
|
|
52
|
+
"bare-agent": "^0.49.0",
|
|
53
|
+
"bareguard": "^0.19.2",
|
|
54
54
|
"litectx": "^0.32.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"
|
|
58
|
-
"
|
|
57
|
+
"@types/node": "^22.20.4",
|
|
58
|
+
"typescript": "^5.9.3"
|
|
59
59
|
}
|
|
60
60
|
}
|