fwdloop 0.25.1 → 0.26.1
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 +8 -1
- package/bin/fwdloop +21 -22
- package/package.json +2 -2
- package/src/config.js +23 -2
- package/src/launcher.js +79 -12
- package/src/pagefetch.js +3 -3
- package/src/panel/authortrigger.js +4 -0
- package/src/panel/index.html +20 -8
- package/src/prompts.js +1 -1
- package/src/provider.js +2 -2
- package/src/registry.js +3 -0
- package/src/runner.js +4 -2
- package/types/config.d.ts +9 -0
- package/types/launcher.d.ts +46 -7
- package/types/pagefetch.d.ts +1 -1
- package/types/registry.d.ts +1 -0
package/README.md
CHANGED
|
@@ -28,6 +28,13 @@ 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
|
+
## See it
|
|
32
|
+
|
|
33
|
+
A real past run: a job that reads a public flights page, lists 3 Madrid→Rome flights, asks a
|
|
34
|
+
human to check them, then writes the result out. Shown across the panel's Job, Run, Ask, Audit and Result tabs.
|
|
35
|
+
|
|
36
|
+
<img src="https://raw.githubusercontent.com/hamr0/fwdloop/main/docs/media/walkthrough.gif" alt="fwdloop panel walkthrough: Job, Run, Ask, Audit, Result" width="100%">
|
|
37
|
+
|
|
31
38
|
## Where it comes from
|
|
32
39
|
|
|
33
40
|
fwdloop carries forward what the bare suite learned about agentic automation: how to author
|
|
@@ -60,7 +67,7 @@ standalone.
|
|
|
60
67
|
|
|
61
68
|
## Status
|
|
62
69
|
|
|
63
|
-
Work in progress.
|
|
70
|
+
Work in progress, on npm as `fwdloop` (`npm install -g fwdloop`); expect changes between versions. `fwdloop` with no arguments opens a menu to start the panel; the menu also checks for a newer fwdloop on `6 update` (online only when pressed). All jobs live in `~/.config/fwdloop/flows`, next to the settings; `--root <folder>` points a command somewhere else.
|
|
64
71
|
|
|
65
72
|
The in-run `impact` tool needs ripgrep (`rg`) on PATH; without it the tool is refused with a message, never a wrong answer.
|
|
66
73
|
|
package/bin/fwdloop
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
} from '../src/provider.js';
|
|
41
41
|
import { readModelRecord, readRunModel, LEARNINGS_FILE } from '../src/flowmodel.js';
|
|
42
42
|
import { readRunInputs } from '../src/runfile.js';
|
|
43
|
-
import { configDoorHome } from '../src/config.js';
|
|
43
|
+
import { configDoorHome, defaultFlowsRoot } from '../src/config.js';
|
|
44
44
|
import {
|
|
45
45
|
claimHold, settleHold, nameRunDir, monthlyRefusalText, ConfigError,
|
|
46
46
|
} from '../src/monthly.js';
|
|
@@ -145,10 +145,13 @@ function fail(message) {
|
|
|
145
145
|
*/
|
|
146
146
|
function resolveRoot(cmd, given) {
|
|
147
147
|
try {
|
|
148
|
-
|
|
148
|
+
// M4b am7: no `--root` = the ONE default (`defaultFlowsRoot`: <config home>/flows), never the current folder
|
|
149
|
+
return realpathSync(given === undefined ? defaultFlowsRoot() : resolve(given));
|
|
149
150
|
} catch (err) {
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
// No --root given: name the default jobs folder (the failing path from the error), never the word "undefined".
|
|
152
|
+
const what = given === undefined ? `the jobs folder "${err.path ?? '~/.config/fwdloop/flows'}"` : `--root "${given}"`;
|
|
153
|
+
if (err.code === 'ENOENT') fail(`${cmd}: ${what} does not exist`);
|
|
154
|
+
fail(`${cmd}: ${what} cannot be resolved: ${err.code ?? err.message}`);
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
|
|
@@ -326,7 +329,6 @@ async function cmdRun(rest) {
|
|
|
326
329
|
|
|
327
330
|
const flowName = positionals[0];
|
|
328
331
|
if (!flowName) fail('run: a flow name is required — fwdloop run <flow> --root <dir> --source <role>=<path> ...');
|
|
329
|
-
if (!values.root) fail('run: --root <dir> is required');
|
|
330
332
|
|
|
331
333
|
const root = resolveRoot('run', values.root);
|
|
332
334
|
const nameCheck = checkFlowName(flowName);
|
|
@@ -444,7 +446,7 @@ async function cmdRun(rest) {
|
|
|
444
446
|
});
|
|
445
447
|
|
|
446
448
|
for (const d of rerunDirs(result, join(root, flowName))) hold.addRunDir(d);
|
|
447
|
-
reportRunResult(result, { rootArg: values.root });
|
|
449
|
+
reportRunResult(result, { rootArg: values.root ?? root });
|
|
448
450
|
}
|
|
449
451
|
|
|
450
452
|
// ---------------------------------------------------------------------------
|
|
@@ -456,7 +458,7 @@ function cmdInbox(rest) {
|
|
|
456
458
|
args: rest,
|
|
457
459
|
options: { root: { type: 'string' } },
|
|
458
460
|
});
|
|
459
|
-
const root = resolveRoot('inbox', values.root
|
|
461
|
+
const root = resolveRoot('inbox', values.root);
|
|
460
462
|
|
|
461
463
|
const rows = [];
|
|
462
464
|
// F48 round 3: flow/run identity is walked via `listFlowNames`/
|
|
@@ -552,7 +554,7 @@ function cmdShow(rest) {
|
|
|
552
554
|
const [askId] = positionals;
|
|
553
555
|
if (!askId) fail('show: an askId is required — fwdloop show <askId> --root <dir>');
|
|
554
556
|
|
|
555
|
-
const root = resolveRoot('show', values.root
|
|
557
|
+
const root = resolveRoot('show', values.root);
|
|
556
558
|
const runDir = findRunDirByAskId(root, askId);
|
|
557
559
|
if (!runDir) fail(`show: no open ask found for askId "${askId}" under ${root}`);
|
|
558
560
|
|
|
@@ -609,7 +611,7 @@ function cmdAnswer(rest) {
|
|
|
609
611
|
if (!askId) fail('answer: an askId is required — fwdloop answer <askId> accept|redo "<reason>"|rerun "<reason>"');
|
|
610
612
|
if (!decision) fail(`answer: a decision (accept|redo|rerun) is required for askId "${askId}"`);
|
|
611
613
|
|
|
612
|
-
const root = resolveRoot('answer', values.root
|
|
614
|
+
const root = resolveRoot('answer', values.root);
|
|
613
615
|
const runDir = findRunDirByAskId(root, askId);
|
|
614
616
|
if (!runDir) fail(`answer: no open ask found for askId "${askId}" under ${root}`);
|
|
615
617
|
|
|
@@ -639,7 +641,6 @@ async function cmdResume(rest) {
|
|
|
639
641
|
const runId = positionals[0];
|
|
640
642
|
if (!runId) fail('resume: a runId is required — fwdloop resume <runId> --flow <name> --root <dir>');
|
|
641
643
|
if (!values.flow) fail('resume: --flow <name> is required');
|
|
642
|
-
if (!values.root) fail('resume: --root <dir> is required');
|
|
643
644
|
|
|
644
645
|
const root = resolveRoot('resume', values.root);
|
|
645
646
|
const flowName = values.flow;
|
|
@@ -716,7 +717,7 @@ async function cmdResume(rest) {
|
|
|
716
717
|
});
|
|
717
718
|
|
|
718
719
|
for (const d of rerunDirs(result, join(root, flowName))) hold.addRunDir(d);
|
|
719
|
-
reportRunResult(result, { rootArg: values.root });
|
|
720
|
+
reportRunResult(result, { rootArg: values.root ?? root });
|
|
720
721
|
}
|
|
721
722
|
|
|
722
723
|
// ---------------------------------------------------------------------------
|
|
@@ -739,7 +740,6 @@ async function cmdContinue(rest) {
|
|
|
739
740
|
const runId = positionals[0];
|
|
740
741
|
if (!runId) fail('continue: a runId is required — fwdloop continue <runId> --flow <name> --root <dir>');
|
|
741
742
|
if (!values.flow) fail('continue: --flow <name> is required');
|
|
742
|
-
if (!values.root) fail('continue: --root <dir> is required');
|
|
743
743
|
|
|
744
744
|
const root = resolveRoot('continue', values.root);
|
|
745
745
|
const flowName = values.flow;
|
|
@@ -802,7 +802,7 @@ async function cmdContinue(rest) {
|
|
|
802
802
|
});
|
|
803
803
|
|
|
804
804
|
for (const d of rerunDirs(result, join(root, flowName))) hold.addRunDir(d);
|
|
805
|
-
reportRunResult(result, { rootArg: values.root });
|
|
805
|
+
reportRunResult(result, { rootArg: values.root ?? root });
|
|
806
806
|
}
|
|
807
807
|
|
|
808
808
|
// ---------------------------------------------------------------------------
|
|
@@ -823,7 +823,7 @@ async function cmdPanel(rest) {
|
|
|
823
823
|
root: { type: 'string' },
|
|
824
824
|
},
|
|
825
825
|
});
|
|
826
|
-
const root = resolveRoot('panel', values.root
|
|
826
|
+
const root = resolveRoot('panel', values.root);
|
|
827
827
|
|
|
828
828
|
const argv = ['--root', root];
|
|
829
829
|
if (values.port) argv.push('--port', values.port);
|
|
@@ -863,7 +863,7 @@ async function cmdDraft(rest) {
|
|
|
863
863
|
const { env } = keysLoad;
|
|
864
864
|
const proseFile = positionals[0];
|
|
865
865
|
if (!proseFile) fail('draft: a prose file is required — fwdloop draft <prose.txt> --out <draftDir> --root <flowsDir> --name <flow>');
|
|
866
|
-
for (const req of ['out', '
|
|
866
|
+
for (const req of ['out', 'name']) if (!values[req]) fail(`draft: --${req} is required`);
|
|
867
867
|
|
|
868
868
|
const leftRules = [];
|
|
869
869
|
for (const pair of values.left === undefined ? [] : values.left.split(',')) {
|
|
@@ -926,7 +926,7 @@ async function cmdDraft(rest) {
|
|
|
926
926
|
proseFile: resolve(proseFile),
|
|
927
927
|
proseRead,
|
|
928
928
|
dir: resolve(values.out),
|
|
929
|
-
root: resolve(values.root),
|
|
929
|
+
root: values.root === undefined ? defaultFlowsRoot() : resolve(values.root),
|
|
930
930
|
name: values.name,
|
|
931
931
|
noQuestions: values['no-questions'] === true,
|
|
932
932
|
...(leftRules.length ? { leftRules } : {}),
|
|
@@ -996,7 +996,6 @@ function cmdLearn(rest) {
|
|
|
996
996
|
const [sub, ...args] = rest;
|
|
997
997
|
if (sub !== 'seed') fail('learn: expected "seed" — fwdloop learn seed --root <flows folder>');
|
|
998
998
|
const { values } = parseArgs({ args, options: { root: { type: 'string' } } });
|
|
999
|
-
if (!values.root) fail('learn seed: --root <flows folder> is required');
|
|
1000
999
|
const root = resolveRoot('learn seed', values.root);
|
|
1001
1000
|
const r = seedLedger({ root });
|
|
1002
1001
|
if (r.skippedNoDoor) fail('learn seed: a test process has no config home (set FWDLOOP_CONFIG_HOME)');
|
|
@@ -1009,12 +1008,12 @@ function cmdLearn(rest) {
|
|
|
1009
1008
|
// ---------------------------------------------------------------------------
|
|
1010
1009
|
|
|
1011
1010
|
/**
|
|
1012
|
-
* M4b am4/am5 (the launcher): a bare `fwdloop` shows the menu; `start | stop | restart | status | install` are its
|
|
1013
|
-
* `--root <flows folder>` (default
|
|
1011
|
+
* M4b am4/am5 (the launcher): a bare `fwdloop` shows the menu; `start | stop | restart | status | install | update` are its six choices as verbs. All logic is src/launcher.js.
|
|
1012
|
+
* `--root <flows folder>` (default <config home>/flows, M4b am7) is the folder the runs line reads and `start` hands the panel; the config home is the real ~/.config/fwdloop.
|
|
1014
1013
|
*/
|
|
1015
1014
|
async function cmdLauncher(cmd, rest) {
|
|
1016
1015
|
const at = rest.indexOf('--root');
|
|
1017
|
-
const given = at === -1 ?
|
|
1016
|
+
const given = at === -1 ? undefined : rest[at + 1];
|
|
1018
1017
|
if (at !== -1 && (given === undefined || given.startsWith('--'))) fail(`${cmd}: --root needs a folder`);
|
|
1019
1018
|
const args = at === -1 ? rest : rest.filter((_, i) => i !== at && i !== at + 1);
|
|
1020
1019
|
process.exitCode = await launcherMain(cmd, args, { root: resolveRoot(cmd, given) });
|
|
@@ -1034,8 +1033,8 @@ async function main() {
|
|
|
1034
1033
|
if (verb === 'continue') return cmdContinue(rest);
|
|
1035
1034
|
if (verb === 'panel') return cmdPanel(rest);
|
|
1036
1035
|
if (verb === 'learn') return cmdLearn(rest);
|
|
1037
|
-
if (verb === 'start' || verb === 'stop' || verb === 'restart' || verb === 'status' || verb === 'install') return cmdLauncher(verb, rest);
|
|
1038
|
-
fail(`unknown verb "${verb}" — expected draft | sign | run | inbox | show | answer | resume | continue | panel | learn | start | stop | restart | status | install (or none, for the menu)`);
|
|
1036
|
+
if (verb === 'start' || verb === 'stop' || verb === 'restart' || verb === 'status' || verb === 'install' || verb === 'update') return cmdLauncher(verb, rest);
|
|
1037
|
+
fail(`unknown verb "${verb}" — expected draft | sign | run | inbox | show | answer | resume | continue | panel | learn | start | stop | restart | status | install | update (or none, for the menu)`);
|
|
1039
1038
|
return undefined;
|
|
1040
1039
|
}
|
|
1041
1040
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
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.52.0",
|
|
53
|
-
"barebrowse": "^0.
|
|
53
|
+
"barebrowse": "^0.24.1",
|
|
54
54
|
"bareguard": "^0.26.0",
|
|
55
55
|
"litectx": "^0.32.0"
|
|
56
56
|
},
|
package/src/config.js
CHANGED
|
@@ -37,6 +37,26 @@ export function configHome(home) {
|
|
|
37
37
|
return home ?? join(homedir(), '.config', 'fwdloop');
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* M4b am7: the ONE decider of the default jobs folder, `<config home>/flows`, used by every verb given no `--root` (the current
|
|
42
|
+
* folder is never the default). Made 0700 if missing (chmod only when this call made it, so umask cannot loosen it and an
|
|
43
|
+
* existing folder is never touched). Under a test process with no explicit home and no `FWDLOOP_CONFIG_HOME` it THROWS rather
|
|
44
|
+
* than make a folder under the real ~/.config/fwdloop (the same door as `configDoorHome`).
|
|
45
|
+
* @param {string} [home] test seam; production never passes it
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
export function defaultFlowsRoot(home) {
|
|
49
|
+
let base = home;
|
|
50
|
+
if (base === undefined) {
|
|
51
|
+
const door = configDoorHome();
|
|
52
|
+
if (door.skip) throw new Error('a test process has no config home for the default jobs folder (set FWDLOOP_CONFIG_HOME or pass --root)');
|
|
53
|
+
base = door.home;
|
|
54
|
+
}
|
|
55
|
+
const root = join(configHome(base), 'flows');
|
|
56
|
+
if (mkdirSync(root, { recursive: true, mode: 0o700 }) !== undefined) chmodSync(root, 0o700);
|
|
57
|
+
return root;
|
|
58
|
+
}
|
|
59
|
+
|
|
40
60
|
/**
|
|
41
61
|
* @param {string} [home]
|
|
42
62
|
* @returns {string} `<home>/config.json`
|
|
@@ -105,8 +125,9 @@ export function providerFieldProblem(field, v) {
|
|
|
105
125
|
return null;
|
|
106
126
|
}
|
|
107
127
|
|
|
108
|
-
/** A Base URL as stored: trailing slashes dropped.
|
|
109
|
-
|
|
128
|
+
/** A Base URL as stored: trailing slashes dropped. The lookbehind starts the match only at the start of a run of slashes, so a long run is linear.
|
|
129
|
+
* // borrowed-from: bareloop src/config.js@v0.48.0 (ed3a110) */
|
|
130
|
+
export const cleanBaseUrl = (v) => v.replace(/(?<!\/)\/+$/, '');
|
|
110
131
|
|
|
111
132
|
const isPrice = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0;
|
|
112
133
|
|
package/src/launcher.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
// `readOwnVersion`; `start` spawns through src/panel/spawn.js `spawnDetached` (detached = its own session, log opened 0600 and appended) with `--root <flows folder>`;
|
|
5
5
|
// install creates the keys file with `createKeysFile`; the silent-port words are M4b am5 item 3's (bareloop 6d10023, unreleased); `launcherMain` is the entry bin/fwdloop calls
|
|
6
6
|
// (bareloop's runLauncher in cli.js). M4b am4 + am5.
|
|
7
|
+
// M4b am8 (built from the signed text): `6 update` / `fwdloop update` - the only online touch in this file, and only when pressed: node's own fetch of
|
|
8
|
+
// registry.npmjs.org/fwdloop/latest (`.version`, 5 s), a plain X.Y.Z compare, a y/n, then `npm install -g fwdloop@latest` (no shell, npm's output shown, a 5-minute
|
|
9
|
+
// deadline that kills only its own child; the number is the builder's, not signed). Piped input (no terminal) never asks and never installs.
|
|
7
10
|
//
|
|
8
11
|
// M4b am4/am5 (bareloop PANEL-BUILD.md addendum 2026-10-24, L) - the `fwdloop` launcher: the bare-`fwdloop` menu and `fwdloop start | stop | restart | status | install`.
|
|
9
12
|
//
|
|
@@ -17,14 +20,16 @@ import {
|
|
|
17
20
|
existsSync, statSync, mkdirSync, chmodSync,
|
|
18
21
|
} from 'node:fs';
|
|
19
22
|
import { createServer } from 'node:net';
|
|
23
|
+
import { spawn as realSpawn } from 'node:child_process';
|
|
20
24
|
import { openAsker } from './prompts.js';
|
|
21
25
|
import { dirname, join } from 'node:path';
|
|
22
26
|
import { fileURLToPath } from 'node:url';
|
|
23
|
-
import { readConfig, updateConfig, configPath, ConfigError } from './config.js';
|
|
27
|
+
import { readConfig, updateConfig, configPath, defaultFlowsRoot, ConfigError } from './config.js';
|
|
24
28
|
import { keysHome, keysFilePath, createKeysFile } from './keysfile.js';
|
|
25
29
|
import { openInOs } from './opener.js';
|
|
26
30
|
import { PLAIN, makePaint } from './tty-colour.js';
|
|
27
31
|
import { readOwnVersion } from './version.js';
|
|
32
|
+
import { REGISTRY_URL } from './registry.js';
|
|
28
33
|
import { spawnDetached } from './panel/spawn.js';
|
|
29
34
|
import { runsListForCount, panelUrl } from './panel/server.js';
|
|
30
35
|
|
|
@@ -39,6 +44,11 @@ const SILENT_PORT_WAIT_MS = 10_000;
|
|
|
39
44
|
const POLL_MS = 100;
|
|
40
45
|
const MIN_NODE_MAJOR = 22;
|
|
41
46
|
const RULE_WIDTH = 56;
|
|
47
|
+
const REGISTRY_TIMEOUT_MS = 5000;
|
|
48
|
+
/** not in the signed text: how long `npm install -g` may run before its own child is killed */
|
|
49
|
+
const NPM_DEADLINE_MS = 300_000;
|
|
50
|
+
const NPM_ARGS = ['install', '-g', 'fwdloop@latest'];
|
|
51
|
+
const UPDATE_LATER = 'Not updated. To update later: npm install -g fwdloop@latest';
|
|
42
52
|
|
|
43
53
|
/**
|
|
44
54
|
* @typedef {object} Panel one answered probe
|
|
@@ -49,7 +59,7 @@ const RULE_WIDTH = 56;
|
|
|
49
59
|
/**
|
|
50
60
|
* @typedef {object} LauncherDeps every OS touch, injectable (a test passes all of them)
|
|
51
61
|
* @property {string} [home] the fwdloop config home (`~/.config/fwdloop`, src/config.js `configHome`); undefined = the real one
|
|
52
|
-
* @property {string} [root] the flows folder the runs line reads and `start` hands the panel (`--root`); default
|
|
62
|
+
* @property {string} [root] the flows folder the runs line reads and `start` hands the panel (`--root`); default `<config home>/flows` (`defaultFlowsRoot`)
|
|
53
63
|
* @property {number} [portStart] @property {number} [portCount]
|
|
54
64
|
* @property {number[]} [ports] an explicit port list (tests); wins over portStart/portCount
|
|
55
65
|
* @property {number} [timeoutMs] probe timeout per port
|
|
@@ -57,6 +67,9 @@ const RULE_WIDTH = 56;
|
|
|
57
67
|
* @property {number} [silentWaitMs] how long start keeps asking a taken, silent port (default 10 s)
|
|
58
68
|
* @property {string} [nodeVersion] default process.versions.node
|
|
59
69
|
* @property {typeof fetch} [fetchImpl]
|
|
70
|
+
* @property {typeof fetch} [registryFetch] the registry read of `update` (default global fetch); tests never go online
|
|
71
|
+
* @property {(args: string[]) => Promise<number>} [spawnNpm] runs npm with these args, resolves its exit code (non-zero = failed, deadline included); default {@link runNpm}
|
|
72
|
+
* @property {boolean} [isTTY] stdin is a terminal (launcherMain sets it); false/absent = `update` never asks and never installs
|
|
60
73
|
* @property {(a: {bin: string, argv: string[], env: Record<string, string|undefined>, logPath: string}) => any} [spawnFn] default src/panel/spawn.js `spawnDetached`
|
|
61
74
|
* @property {(pid: number, sig: string|number) => void} [kill] default process.kill
|
|
62
75
|
* @property {((target: string) => Promise<boolean>)} [open] default the shared OS opener
|
|
@@ -195,7 +208,7 @@ export async function buildHeader(d) {
|
|
|
195
208
|
const first = `${P.boldCyan('fwdloop')} ${P.grey(version)}${sep}${state}${sep}${where}`;
|
|
196
209
|
let second;
|
|
197
210
|
try {
|
|
198
|
-
const c = countRuns(runsListForCount({ root: d.root ??
|
|
211
|
+
const c = countRuns(runsListForCount({ root: d.root ?? defaultFlowsRoot(d.home), ...(typeof d.now === 'number' ? { now: () => /** @type {number} */ (d.now) } : {}) }));
|
|
199
212
|
second = `${P.grey('runs:')} ${c.running > 0 ? P.green(`${c.running} running`) : P.grey(`${c.running} running`)}${sep}`
|
|
200
213
|
+ `${c.needYou > 0 ? P.yellow(`${c.needYou} need you`) : P.grey(`${c.needYou} need you`)}${sep}${c.total} in all`;
|
|
201
214
|
} catch {
|
|
@@ -244,7 +257,7 @@ function bindFree(port) {
|
|
|
244
257
|
}
|
|
245
258
|
|
|
246
259
|
/**
|
|
247
|
-
* `fwdloop install` — creates only what is missing, never reads a key value.
|
|
260
|
+
* `fwdloop install` (menu 5) — creates only what is missing, never reads a key value.
|
|
248
261
|
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
|
|
249
262
|
* @returns {Promise<number>}
|
|
250
263
|
*/
|
|
@@ -279,12 +292,64 @@ export async function installCmd(io, d, shown) {
|
|
|
279
292
|
return 1;
|
|
280
293
|
}
|
|
281
294
|
}
|
|
282
|
-
if (made.length === 0) { io.out('Already
|
|
295
|
+
if (made.length === 0) { io.out('Already set up. This does not update fwdloop. Pick 6 update for that.'); return 0; }
|
|
283
296
|
io.out('Installed. Created:');
|
|
284
297
|
for (const m of made) io.out(` ${m}`);
|
|
285
298
|
return 0;
|
|
286
299
|
}
|
|
287
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Run `npm install -g fwdloop@latest`: no shell, npm's output on the terminal, killed by its own child handle at the deadline.
|
|
303
|
+
* @param {string[]} args @param {{spawnImpl?: typeof realSpawn, deadlineMs?: number}} [o]
|
|
304
|
+
* @returns {Promise<number>} npm's exit code; 1 when it could not start, was killed by a signal, or hit the deadline
|
|
305
|
+
*/
|
|
306
|
+
export function runNpm(args, o = {}) {
|
|
307
|
+
const spawnImpl = o.spawnImpl ?? realSpawn;
|
|
308
|
+
return new Promise((resolve) => {
|
|
309
|
+
let child;
|
|
310
|
+
try { child = spawnImpl('npm', args, { shell: false, stdio: 'inherit' }); } catch { resolve(1); return; }
|
|
311
|
+
let done = false;
|
|
312
|
+
const end = (/** @type {number} */ code) => { if (done) return; done = true; clearTimeout(timer); resolve(code); };
|
|
313
|
+
const timer = setTimeout(() => { try { child.kill('SIGTERM'); } catch { /* already gone */ } end(1); }, o.deadlineMs ?? NPM_DEADLINE_MS);
|
|
314
|
+
child.once('error', () => end(1));
|
|
315
|
+
child.once('close', (/** @type {number|null} */ code) => end(code === 0 ? 0 : 1));
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** @param {string} v @returns {number[]|null} X.Y.Z as numbers, nothing else counts */
|
|
320
|
+
const semverOf = (v) => { const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v); return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null; };
|
|
321
|
+
/** @param {number[]} a @param {number[]} b @returns {boolean} a is newer than b */
|
|
322
|
+
const isNewer = (a, b) => { for (let i = 0; i < 3; i += 1) if (a[i] !== b[i]) return a[i] > b[i]; return false; };
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* `fwdloop update` (menu 6, M4b am8) - the one online press. Exit 0: newest / updated / not updated; 1: could not reach npm, update failed.
|
|
326
|
+
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
|
|
327
|
+
* @returns {Promise<number>}
|
|
328
|
+
*/
|
|
329
|
+
export async function updateCmd(io, d, shown) {
|
|
330
|
+
await headerOnce(io, d, shown);
|
|
331
|
+
const mine = d.version ?? readOwnVersion() ?? 'unknown';
|
|
332
|
+
/** @type {string|null} */
|
|
333
|
+
let latest = null;
|
|
334
|
+
try {
|
|
335
|
+
const res = await (d.registryFetch ?? fetch)(REGISTRY_URL, { signal: AbortSignal.timeout(REGISTRY_TIMEOUT_MS) });
|
|
336
|
+
if (res.ok) { const v = /** @type {any} */ (await res.json())?.version; if (typeof v === 'string' && semverOf(v)) latest = v; }
|
|
337
|
+
} catch { /* offline, timeout or bad JSON: the same answer */ }
|
|
338
|
+
if (latest === null) { fail(io, d, 'Could not reach npm to check. Try again later.'); return 1; }
|
|
339
|
+
const a = /** @type {number[]} */ (semverOf(latest));
|
|
340
|
+
const b = semverOf(mine) ?? [0, 0, 0];
|
|
341
|
+
if (!isNewer(a, b)) { io.out(`You have the newest fwdloop (${mine}).`); return 0; }
|
|
342
|
+
io.out(`fwdloop ${latest} is out. You have ${mine}.`);
|
|
343
|
+
if (!d.isTTY || !d.ask) { io.out(UPDATE_LATER); return 0; }
|
|
344
|
+
let answer = (await d.ask('Update now? (y/n) ')).trim().toLowerCase();
|
|
345
|
+
if (answer === '') answer = (await d.ask('Update now? (y/n) ')).trim().toLowerCase();
|
|
346
|
+
if (answer !== 'y' && answer !== 'yes') { io.out(UPDATE_LATER); return 0; }
|
|
347
|
+
const code = await (d.spawnNpm ?? runNpm)(NPM_ARGS);
|
|
348
|
+
if (code !== 0) { fail(io, d, 'The update did not finish. Run it yourself: npm install -g fwdloop@latest'); return 1; }
|
|
349
|
+
io.out(`Updated to ${latest}. Then pick 3 restart.`);
|
|
350
|
+
return 0;
|
|
351
|
+
}
|
|
352
|
+
|
|
288
353
|
/**
|
|
289
354
|
* `fwdloop status` — the header, then one line per panel (or `Panel not running.`). Exit 0 running, 3 not running; 0 when the menu ran it.
|
|
290
355
|
* @param {{out: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown] header the menu already printed
|
|
@@ -387,7 +452,7 @@ export async function startCmd(io, d, shown) {
|
|
|
387
452
|
try { mkdirSync(dir, { recursive: true, mode: 0o700 }); } catch { /* the log open below reports it */ }
|
|
388
453
|
const logFile = join(dir, 'panel.log');
|
|
389
454
|
const bin = d.fwdloopBin ?? join(HERE, '..', 'bin', 'fwdloop');
|
|
390
|
-
const argv = ['panel', '--port', String(chosen), '--root', d.root ??
|
|
455
|
+
const argv = ['panel', '--port', String(chosen), '--root', d.root ?? defaultFlowsRoot(d.home)];
|
|
391
456
|
const spawnFn = d.spawnFn ?? spawnDetached;
|
|
392
457
|
try {
|
|
393
458
|
const child = spawnFn({ bin, argv, env: d.env ?? process.env, logPath: logFile });
|
|
@@ -497,7 +562,7 @@ export async function restartCmd(args, io, d, shown) {
|
|
|
497
562
|
}
|
|
498
563
|
|
|
499
564
|
/**
|
|
500
|
-
* The bare `fwdloop` menu: header, the
|
|
565
|
+
* The bare `fwdloop` menu: header, the six choices, one question. Runs the chosen command and returns its exit code.
|
|
501
566
|
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d
|
|
502
567
|
* @returns {Promise<number>}
|
|
503
568
|
*/
|
|
@@ -508,7 +573,7 @@ export async function menuCmd(io, d) {
|
|
|
508
573
|
const P = d.paint ?? PLAIN;
|
|
509
574
|
if (!P.on) io.out('');
|
|
510
575
|
const n = (/** @type {string} */ k) => P.boldCyan(k);
|
|
511
|
-
const items = `${n('1')} start ${n('2')} stop ${n('3')} restart ${n('4')} status ${n('5')} install ${n('q')} quit`;
|
|
576
|
+
const items = `${n('1')} start ${n('2')} stop ${n('3')} restart ${n('4')} status ${n('5')} install ${n('6')} update ${n('q')} quit`;
|
|
512
577
|
io.out(P.on ? ` ${items}` : items);
|
|
513
578
|
const choice = ask ? (await ask(`${P.cyan('>')} `)).trim().toLowerCase() : 'q';
|
|
514
579
|
// the header is already on screen: the chosen command reuses it instead of printing it a second time
|
|
@@ -517,15 +582,16 @@ export async function menuCmd(io, d) {
|
|
|
517
582
|
if (choice === '3' || choice === 'restart') return restartCmd([], io, d, h);
|
|
518
583
|
if (choice === '4' || choice === 'status') return statusCmd(io, d, h);
|
|
519
584
|
if (choice === '5' || choice === 'install') return installCmd(io, d, h);
|
|
585
|
+
if (choice === '6' || choice === 'update') return updateCmd(io, d, h);
|
|
520
586
|
if (choice === '' || choice === 'q' || choice === 'quit') return 0;
|
|
521
|
-
fail(io, d, `unknown choice ${JSON.stringify(choice)} — one of: 1, 2, 3, 4, 5, q`);
|
|
587
|
+
fail(io, d, `unknown choice ${JSON.stringify(choice)} — one of: 1, 2, 3, 4, 5, 6, q`);
|
|
522
588
|
return 1;
|
|
523
589
|
}
|
|
524
590
|
|
|
525
591
|
/**
|
|
526
|
-
* The launcher doors: the bare `fwdloop` menu and `start | stop | restart | status | install` (bin/fwdloop calls this; bareloop's runLauncher in src/cli.js). All logic is above;
|
|
592
|
+
* The launcher doors: the bare `fwdloop` menu and `start | stop | restart | status | install | update` (bin/fwdloop calls this; bareloop's runLauncher in src/cli.js). All logic is above;
|
|
527
593
|
* this only supplies the line reader and the colour. `deps.launcher` is the test seam for every OS touch (ports, spawn, kill, opener, clock).
|
|
528
|
-
* @param {'menu'|'start'|'stop'|'restart'|'status'|'install'} cmd @param {string[]} rest
|
|
594
|
+
* @param {'menu'|'start'|'stop'|'restart'|'status'|'install'|'update'} cmd @param {string[]} rest
|
|
529
595
|
* @param {{ stdin?: any, stdout?: any, stderr?: any, home?: string, root?: string, processEnv?: Record<string, string|undefined>, launcher?: LauncherDeps & {version?: string} }} deps
|
|
530
596
|
* @returns {Promise<number>}
|
|
531
597
|
*/
|
|
@@ -537,7 +603,7 @@ export async function launcherMain(cmd, rest, deps) {
|
|
|
537
603
|
const { ask, close } = openAsker({ stdin: deps.stdin, stdout });
|
|
538
604
|
const rawEnv = deps.processEnv ?? process.env;
|
|
539
605
|
const d = {
|
|
540
|
-
home: deps.home, root: deps.root, ask, paint: makePaint(stdout, rawEnv), paintErr: makePaint(stderr, rawEnv), ...(deps.launcher ?? {}),
|
|
606
|
+
home: deps.home, root: deps.root, ask, isTTY: Boolean((deps.stdin ?? process.stdin).isTTY), paint: makePaint(stdout, rawEnv), paintErr: makePaint(stderr, rawEnv), ...(deps.launcher ?? {}),
|
|
541
607
|
};
|
|
542
608
|
try {
|
|
543
609
|
if (cmd === 'start') return await startCmd(io, d);
|
|
@@ -545,6 +611,7 @@ export async function launcherMain(cmd, rest, deps) {
|
|
|
545
611
|
if (cmd === 'restart') return await restartCmd(rest, io, d);
|
|
546
612
|
if (cmd === 'status') return await statusCmd(io, d);
|
|
547
613
|
if (cmd === 'install') return await installCmd(io, d);
|
|
614
|
+
if (cmd === 'update') return await updateCmd(io, d);
|
|
548
615
|
return await menuCmd(io, d);
|
|
549
616
|
} finally {
|
|
550
617
|
close();
|
package/src/pagefetch.js
CHANGED
|
@@ -90,8 +90,8 @@ export function pageContentChars(text) {
|
|
|
90
90
|
* snapshot: (o?: {mode?: string}) => Promise<string>, close: () => Promise<void>}} FetchPage the part of barebrowse's page handle the fetch uses
|
|
91
91
|
*/
|
|
92
92
|
|
|
93
|
-
/** the oldest barebrowse
|
|
94
|
-
export const MIN_BAREBROWSE = [0,
|
|
93
|
+
/** the oldest barebrowse we accept: 0.21.0 honours CONNECT_OPTIONS (incognito, blockPrivateNetwork; an older one would drop both guards without a word); 0.24.1 tethers Chromium to its launcher, so a killed run or an Abandoned draft leaves no browser behind */
|
|
94
|
+
export const MIN_BAREBROWSE = [0, 24, 1];
|
|
95
95
|
|
|
96
96
|
/** @param {string} v @returns {boolean} true when `v` (x.y.z) is at least MIN_BAREBROWSE */
|
|
97
97
|
export function barebrowseNewEnough(v) {
|
|
@@ -108,7 +108,7 @@ async function loadConnect() {
|
|
|
108
108
|
try {
|
|
109
109
|
const mod = /** @type {any} */ (await import('barebrowse'));
|
|
110
110
|
const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.resolve('barebrowse'))), '..', 'package.json'), 'utf8'));
|
|
111
|
-
if (!barebrowseNewEnough(pkg.version)) return { ok: /** @type {const} */ (false), error: `the page reader (barebrowse ${pkg.version}) is too old: a web page needs 0.
|
|
111
|
+
if (!barebrowseNewEnough(pkg.version)) return { ok: /** @type {const} */ (false), error: `the page reader (barebrowse ${pkg.version}) is too old: a web page needs 0.24.1 or newer, which keeps the browser private, off the local network, and closed when the run ends` };
|
|
112
112
|
return { ok: /** @type {const} */ (true), connect: /** @type {(opts: Record<string, any>) => Promise<FetchPage>} */ (mod.connect) };
|
|
113
113
|
} catch (e) { return { ok: /** @type {const} */ (false), error: `the page reader (barebrowse) could not be loaded: ${/** @type {Error} */ (e).message}` }; }
|
|
114
114
|
}
|
|
@@ -25,6 +25,7 @@ import { destinationRefusal, checkInputRows, runInputRows } from './authorcard.j
|
|
|
25
25
|
import { endRow, readHistory } from '../books.js';
|
|
26
26
|
import { appendRow } from '../jsonl-append.js';
|
|
27
27
|
import { loadCatalogue } from '../catalogue.js';
|
|
28
|
+
import { canFlowRun, willNotRunSay } from '../canrun.js';
|
|
28
29
|
import {
|
|
29
30
|
FLOW_FILES, checkFlowName, listFlowNames, listRunIds, planForReuse, readFileInside, readFlow, readRunJobCopy, resolveRunDir,
|
|
30
31
|
} from '../flow.js';
|
|
@@ -398,6 +399,9 @@ export function createTriggerDoor(opts) {
|
|
|
398
399
|
read = /** @type {any} */ (kept);
|
|
399
400
|
planRun = planRec.run;
|
|
400
401
|
}
|
|
402
|
+
// the Run door's own `canFlowRun` (a retired check form, an unwired verb), on the plan this fire runs, in the Run door's own sentence: refused at $0, nothing started
|
|
403
|
+
const can = canFlowRun(read);
|
|
404
|
+
if (!can.ok) return done({ outcome: 'refused', why: willNotRunSay(flow, String(can.red)) });
|
|
401
405
|
const claim = monthlyClaim(read.arbiter.capUsd); // the same check the Run door decides on
|
|
402
406
|
if (claim && 'problem' in claim) return done({ outcome: 'refused', why: `${claim.problem}. Nothing spent.` });
|
|
403
407
|
if (claim && !claim.ok) return done({ outcome: 'monthly-exhausted', leftUsd: claim.room.leftUsd, needUsd: claim.room.needUsd, atLeast: claim.room.atLeast === true });
|
package/src/panel/index.html
CHANGED
|
@@ -5224,7 +5224,7 @@
|
|
|
5224
5224
|
askWait: askWaitEl.value.trim(),
|
|
5225
5225
|
provider: modelPick().provider,
|
|
5226
5226
|
model: modelPick().model,
|
|
5227
|
-
thinking: thinkingEl.checked && !
|
|
5227
|
+
thinking: thinkingEl.checked && !thinkingNone,
|
|
5228
5228
|
...(reuseOf !== null ? {reuseOf: reuseOf} : {})
|
|
5229
5229
|
};
|
|
5230
5230
|
}
|
|
@@ -5377,6 +5377,7 @@
|
|
|
5377
5377
|
runFlowSel.classList.toggle("locked", on);
|
|
5378
5378
|
rwPickedEl.classList.toggle("locked", on);
|
|
5379
5379
|
card.querySelectorAll('input[name="jf-mode"]').forEach(function(r){ r.disabled = on || sessionLive; });
|
|
5380
|
+
paintModelLock();
|
|
5380
5381
|
}
|
|
5381
5382
|
// top-right: Abandon while a draft is live and unsigned, else Clear
|
|
5382
5383
|
function clearButtonFor(live, hasId){
|
|
@@ -5683,6 +5684,16 @@
|
|
|
5683
5684
|
var modelEl = byId("jf-model");
|
|
5684
5685
|
var thinkingEl = byId("jf-thinking");
|
|
5685
5686
|
var modelLines = [];
|
|
5687
|
+
var modelNone = true; // no model to pick (none ticked, or the list could not be read): the menu stays shut
|
|
5688
|
+
var thinkingNone = true; // Thinking cannot change for the picked line (thinkingBoxState): the box stays shut
|
|
5689
|
+
// M6 item 7: the card is locked as a whole, so the Model menu and the Thinking box lock with it. THE one writer of both `disabled`s:
|
|
5690
|
+
// shut when the card is locked OR for their own reason above; the other sites only set the reason and call this.
|
|
5691
|
+
function paintModelLock(){
|
|
5692
|
+
if(!modelEl || !thinkingEl) return; // syncCardLock can run before these two are looked up
|
|
5693
|
+
var on = cardLocked();
|
|
5694
|
+
modelEl.disabled = on || modelNone; modelEl.classList.toggle("locked", on);
|
|
5695
|
+
thinkingEl.disabled = on || thinkingNone; thinkingEl.classList.toggle("locked", on);
|
|
5696
|
+
}
|
|
5686
5697
|
function modelPick(){
|
|
5687
5698
|
var l = modelLines[Number(modelEl.value)];
|
|
5688
5699
|
return l ? {provider: l.slot, model: l.model} : {provider: "", model: ""};
|
|
@@ -5696,7 +5707,8 @@
|
|
|
5696
5707
|
}
|
|
5697
5708
|
function paintThinking(){
|
|
5698
5709
|
var st = thinkingBoxState(modelLines[Number(modelEl.value)], thinkingEl.checked);
|
|
5699
|
-
|
|
5710
|
+
thinkingNone = st.disabled; thinkingEl.checked = st.checked;
|
|
5711
|
+
paintModelLock();
|
|
5700
5712
|
byId("jf-thinking-note").textContent = st.note;
|
|
5701
5713
|
drafterModel = modelPick().model;
|
|
5702
5714
|
}
|
|
@@ -5716,7 +5728,7 @@
|
|
|
5716
5728
|
}
|
|
5717
5729
|
runPickEl.addEventListener("change", function(){ runPicked = runPickChoice(); });
|
|
5718
5730
|
function syncRunPick(){
|
|
5719
|
-
runPickEl.innerHTML = modelEl.innerHTML; runPickEl.disabled =
|
|
5731
|
+
runPickEl.innerHTML = modelEl.innerHTML; runPickEl.disabled = modelNone;
|
|
5720
5732
|
for(var i = 0; i < modelLines.length; i += 1){ if(modelLines[i].slot === runPicked.provider && modelLines[i].model === runPicked.model){ runPickEl.value = String(i); break; } }
|
|
5721
5733
|
}
|
|
5722
5734
|
// `tries` counts the reads that failed in a row (a click passes an Event, which is not a number: that is a fresh read).
|
|
@@ -5725,7 +5737,7 @@
|
|
|
5725
5737
|
var failed = typeof tries === "number" ? tries : 0;
|
|
5726
5738
|
function unread(){
|
|
5727
5739
|
if(modelLines.length > 0) return; // a menu that was filled keeps what it had
|
|
5728
|
-
modelEl.innerHTML = "";
|
|
5740
|
+
modelEl.innerHTML = ""; modelNone = true; paintModelLock();
|
|
5729
5741
|
var o = document.createElement("option"); o.value = "";
|
|
5730
5742
|
o.textContent = failed < 5 ? "Could not read your models. Trying again\u2026" : "Could not read your models. Reload the page.";
|
|
5731
5743
|
modelEl.appendChild(o);
|
|
@@ -5739,12 +5751,12 @@
|
|
|
5739
5751
|
modelEl.innerHTML = "";
|
|
5740
5752
|
if(modelLines.length === 0){
|
|
5741
5753
|
var none = document.createElement("option"); none.value = ""; none.textContent = j.say || "Tick a model in Settings > Providers."; modelEl.appendChild(none);
|
|
5742
|
-
|
|
5754
|
+
modelNone = true;
|
|
5743
5755
|
} else {
|
|
5744
|
-
|
|
5756
|
+
modelNone = false;
|
|
5745
5757
|
modelLines.forEach(function(l, i){ var o = document.createElement("option"); o.value = String(i); o.textContent = l.label; modelEl.appendChild(o); });
|
|
5746
5758
|
}
|
|
5747
|
-
setModelPick(was.provider, was.model);
|
|
5759
|
+
setModelPick(was.provider, was.model); // (paints the lock through paintThinking)
|
|
5748
5760
|
syncRunPick();
|
|
5749
5761
|
}).catch(function(){ failed += 1; unread(); });
|
|
5750
5762
|
}
|
|
@@ -6235,7 +6247,7 @@
|
|
|
6235
6247
|
openNewCard();
|
|
6236
6248
|
setMode("new");
|
|
6237
6249
|
setVal("jf-name", c.flowName); setVal("jf-job", c.job); setVal("jf-cap-money", c.capUsd);
|
|
6238
|
-
setModelPick(c.provider || "", c.model || ""); thinkingEl.checked = c.thinking === true && !
|
|
6250
|
+
setModelPick(c.provider || "", c.model || ""); thinkingEl.checked = c.thinking === true && !thinkingNone;
|
|
6239
6251
|
refreshCapNote();
|
|
6240
6252
|
setVal("jf-dest-folder", typeof c.destination === "string" ? c.destination : ""); setVal("jf-inputs", typeof c.inputs === "string" ? c.inputs : ""); setVal("jf-ask-wait", c.askWait || "1h");
|
|
6241
6253
|
sessionId = d.draftId;
|
package/src/prompts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// borrowed-from: bareloop src/prompts.js@
|
|
1
|
+
// borrowed-from: bareloop src/prompts.js@v0.48.0 (openAsker only; askRequired and the menu changes are not copied)
|
|
2
2
|
// The CLI's one line-asker. Every prompt in the launcher reads through this, so a closed stdin behaves the same everywhere.
|
|
3
3
|
|
|
4
4
|
import { createInterface } from 'node:readline';
|
package/src/provider.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { dirname, basename } from 'node:path';
|
|
22
22
|
import { readFileInside } from './flow.js';
|
|
23
23
|
import { appendRow } from './jsonl-append.js';
|
|
24
|
-
import { readConfig, configDoorHome } from './config.js';
|
|
24
|
+
import { readConfig, configDoorHome, cleanBaseUrl } from './config.js';
|
|
25
25
|
import { isKeyName } from './keysfile.js';
|
|
26
26
|
import { OpenAI, Anthropic, Gemini } from 'bare-agent/providers';
|
|
27
27
|
|
|
@@ -81,7 +81,7 @@ export function resolveSlot(slotName, { config = {} } = {}) {
|
|
|
81
81
|
// F11: some providers ignore `max_completion_tokens`; only the legacy `max_tokens` key bounds their output. A per-row tick in Settings.
|
|
82
82
|
legacyMaxTokens: saved.legacyMaxTokens === true && shape === 'openai-api',
|
|
83
83
|
shape,
|
|
84
|
-
baseUrl: typeof saved.baseUrl === 'string' ? saved.baseUrl
|
|
84
|
+
baseUrl: typeof saved.baseUrl === 'string' ? cleanBaseUrl(saved.baseUrl) : '',
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
|
package/src/registry.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// M4b am8: the one address `fwdloop update` asks, and only when the human presses update. Kept out of src/launcher.js, whose test (launcher-header.test.js)
|
|
2
|
+
// pins "no address but panelUrl" for the PANEL's address.
|
|
3
|
+
export const REGISTRY_URL = 'https://registry.npmjs.org/fwdloop/latest';
|
package/src/runner.js
CHANGED
|
@@ -979,7 +979,7 @@ export async function runStepRalph({
|
|
|
979
979
|
const usd = sumKnownUsd(attemptFloorUsd, result.costUsd);
|
|
980
980
|
const ranCalls = (turns ?? 0) > 0 || attemptFloorUsd !== null;
|
|
981
981
|
return stopped(stopWords(ranCalls ? attempt : attempt - 1, turns ?? 0), rowOf({
|
|
982
|
-
step, attempt: ranCalls ? attempt : null, verdict: 'stopped', gap: null, usd, spendComplete:
|
|
982
|
+
step, attempt: ranCalls ? attempt : null, verdict: 'stopped', gap: null, usd, spendComplete: typeof result.costUsd === 'number', wallMs, model: result.model, modelMatch: result.modelMatch, strike: false, at: now(), tokens: result.tokens ?? null, tools: result.tools ?? null, ungranted: result.ungranted, refused: result.refused, thinking: result.thinking,
|
|
983
983
|
}));
|
|
984
984
|
}
|
|
985
985
|
|
|
@@ -1008,9 +1008,11 @@ export async function runStepRalph({
|
|
|
1008
1008
|
const strike = seenGaps.has(normalised);
|
|
1009
1009
|
seenGaps.add(normalised);
|
|
1010
1010
|
if (strike) strikes += 1;
|
|
1011
|
+
// A floor from a faulted first call plus a retry whose own cost is unknown is "at least" the floor, never complete: complete needs THIS call's cost known
|
|
1012
|
+
// (no floor and an unknown cost is usd null, also incomplete - the "no provider ever built" case).
|
|
1011
1013
|
const usd = sumKnownUsd(attemptFloorUsd, result?.costUsd);
|
|
1012
1014
|
recordAudit(rowOf({
|
|
1013
|
-
step, attempt, verdict: 'red', gap: red, usd, spendComplete:
|
|
1015
|
+
step, attempt, verdict: 'red', gap: red, usd, spendComplete: typeof result?.costUsd === 'number', wallMs, model: result?.model, modelMatch: result?.modelMatch, strike, at: now(), tokens: result?.tokens ?? null, tools: result?.tools ?? null, ungranted: result?.ungranted, refused: result?.refused, thinking: result?.thinking,
|
|
1014
1016
|
}), red);
|
|
1015
1017
|
if (n === maxN) return { ok: false, outcome: 'attempt-fallback', red: `attempt-fallback: step "${step.goal}" — ${red}` };
|
|
1016
1018
|
if (strikes >= STRIKE_LIMIT) return { ok: false, outcome: 'struck-out', red: `struck-out: step "${step.goal}" — ${red}` };
|
package/types/config.d.ts
CHANGED
|
@@ -5,6 +5,15 @@
|
|
|
5
5
|
* @returns {string}
|
|
6
6
|
*/
|
|
7
7
|
export function configHome(home?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* M4b am7: the ONE decider of the default jobs folder, `<config home>/flows`, used by every verb given no `--root` (the current
|
|
10
|
+
* folder is never the default). Made 0700 if missing (chmod only when this call made it, so umask cannot loosen it and an
|
|
11
|
+
* existing folder is never touched). Under a test process with no explicit home and no `FWDLOOP_CONFIG_HOME` it THROWS rather
|
|
12
|
+
* than make a folder under the real ~/.config/fwdloop (the same door as `configDoorHome`).
|
|
13
|
+
* @param {string} [home] test seam; production never passes it
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
export function defaultFlowsRoot(home?: string): string;
|
|
8
17
|
/**
|
|
9
18
|
* @param {string} [home]
|
|
10
19
|
* @returns {string} `<home>/config.json`
|
package/types/launcher.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* @typedef {object} LauncherDeps every OS touch, injectable (a test passes all of them)
|
|
8
8
|
* @property {string} [home] the fwdloop config home (`~/.config/fwdloop`, src/config.js `configHome`); undefined = the real one
|
|
9
|
-
* @property {string} [root] the flows folder the runs line reads and `start` hands the panel (`--root`); default
|
|
9
|
+
* @property {string} [root] the flows folder the runs line reads and `start` hands the panel (`--root`); default `<config home>/flows` (`defaultFlowsRoot`)
|
|
10
10
|
* @property {number} [portStart] @property {number} [portCount]
|
|
11
11
|
* @property {number[]} [ports] an explicit port list (tests); wins over portStart/portCount
|
|
12
12
|
* @property {number} [timeoutMs] probe timeout per port
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* @property {number} [silentWaitMs] how long start keeps asking a taken, silent port (default 10 s)
|
|
15
15
|
* @property {string} [nodeVersion] default process.versions.node
|
|
16
16
|
* @property {typeof fetch} [fetchImpl]
|
|
17
|
+
* @property {typeof fetch} [registryFetch] the registry read of `update` (default global fetch); tests never go online
|
|
18
|
+
* @property {(args: string[]) => Promise<number>} [spawnNpm] runs npm with these args, resolves its exit code (non-zero = failed, deadline included); default {@link runNpm}
|
|
19
|
+
* @property {boolean} [isTTY] stdin is a terminal (launcherMain sets it); false/absent = `update` never asks and never installs
|
|
17
20
|
* @property {(a: {bin: string, argv: string[], env: Record<string, string|undefined>, logPath: string}) => any} [spawnFn] default src/panel/spawn.js `spawnDetached`
|
|
18
21
|
* @property {(pid: number, sig: string|number) => void} [kill] default process.kill
|
|
19
22
|
* @property {((target: string) => Promise<boolean>)} [open] default the shared OS opener
|
|
@@ -103,7 +106,7 @@ export function headerLines(d: LauncherDeps & {
|
|
|
103
106
|
version?: string;
|
|
104
107
|
}): Promise<string[]>;
|
|
105
108
|
/**
|
|
106
|
-
* `fwdloop install` — creates only what is missing, never reads a key value.
|
|
109
|
+
* `fwdloop install` (menu 5) — creates only what is missing, never reads a key value.
|
|
107
110
|
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
|
|
108
111
|
* @returns {Promise<number>}
|
|
109
112
|
*/
|
|
@@ -116,6 +119,29 @@ export function installCmd(io: {
|
|
|
116
119
|
lines: string[];
|
|
117
120
|
panels: Panel[];
|
|
118
121
|
}): Promise<number>;
|
|
122
|
+
/**
|
|
123
|
+
* Run `npm install -g fwdloop@latest`: no shell, npm's output on the terminal, killed by its own child handle at the deadline.
|
|
124
|
+
* @param {string[]} args @param {{spawnImpl?: typeof realSpawn, deadlineMs?: number}} [o]
|
|
125
|
+
* @returns {Promise<number>} npm's exit code; 1 when it could not start, was killed by a signal, or hit the deadline
|
|
126
|
+
*/
|
|
127
|
+
export function runNpm(args: string[], o?: {
|
|
128
|
+
spawnImpl?: typeof realSpawn;
|
|
129
|
+
deadlineMs?: number;
|
|
130
|
+
}): Promise<number>;
|
|
131
|
+
/**
|
|
132
|
+
* `fwdloop update` (menu 6, M4b am8) - the one online press. Exit 0: newest / updated / not updated; 1: could not reach npm, update failed.
|
|
133
|
+
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
|
|
134
|
+
* @returns {Promise<number>}
|
|
135
|
+
*/
|
|
136
|
+
export function updateCmd(io: {
|
|
137
|
+
out: (s: string) => void;
|
|
138
|
+
err: (s: string) => void;
|
|
139
|
+
}, d: LauncherDeps & {
|
|
140
|
+
version?: string;
|
|
141
|
+
}, shown?: {
|
|
142
|
+
lines: string[];
|
|
143
|
+
panels: Panel[];
|
|
144
|
+
}): Promise<number>;
|
|
119
145
|
/**
|
|
120
146
|
* `fwdloop status` — the header, then one line per panel (or `Panel not running.`). Exit 0 running, 3 not running; 0 when the menu ran it.
|
|
121
147
|
* @param {{out: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown] header the menu already printed
|
|
@@ -177,7 +203,7 @@ export function restartCmd(args: string[], io: {
|
|
|
177
203
|
panels: Panel[];
|
|
178
204
|
}): Promise<number>;
|
|
179
205
|
/**
|
|
180
|
-
* The bare `fwdloop` menu: header, the
|
|
206
|
+
* The bare `fwdloop` menu: header, the six choices, one question. Runs the chosen command and returns its exit code.
|
|
181
207
|
* @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d
|
|
182
208
|
* @returns {Promise<number>}
|
|
183
209
|
*/
|
|
@@ -188,13 +214,13 @@ export function menuCmd(io: {
|
|
|
188
214
|
version?: string;
|
|
189
215
|
}): Promise<number>;
|
|
190
216
|
/**
|
|
191
|
-
* The launcher doors: the bare `fwdloop` menu and `start | stop | restart | status | install` (bin/fwdloop calls this; bareloop's runLauncher in src/cli.js). All logic is above;
|
|
217
|
+
* The launcher doors: the bare `fwdloop` menu and `start | stop | restart | status | install | update` (bin/fwdloop calls this; bareloop's runLauncher in src/cli.js). All logic is above;
|
|
192
218
|
* this only supplies the line reader and the colour. `deps.launcher` is the test seam for every OS touch (ports, spawn, kill, opener, clock).
|
|
193
|
-
* @param {'menu'|'start'|'stop'|'restart'|'status'|'install'} cmd @param {string[]} rest
|
|
219
|
+
* @param {'menu'|'start'|'stop'|'restart'|'status'|'install'|'update'} cmd @param {string[]} rest
|
|
194
220
|
* @param {{ stdin?: any, stdout?: any, stderr?: any, home?: string, root?: string, processEnv?: Record<string, string|undefined>, launcher?: LauncherDeps & {version?: string} }} deps
|
|
195
221
|
* @returns {Promise<number>}
|
|
196
222
|
*/
|
|
197
|
-
export function launcherMain(cmd: "menu" | "start" | "stop" | "restart" | "status" | "install", rest: string[], deps: {
|
|
223
|
+
export function launcherMain(cmd: "menu" | "start" | "stop" | "restart" | "status" | "install" | "update", rest: string[], deps: {
|
|
198
224
|
stdin?: any;
|
|
199
225
|
stdout?: any;
|
|
200
226
|
stderr?: any;
|
|
@@ -232,7 +258,7 @@ export type LauncherDeps = {
|
|
|
232
258
|
*/
|
|
233
259
|
home?: string | undefined;
|
|
234
260
|
/**
|
|
235
|
-
* the flows folder the runs line reads and `start` hands the panel (`--root`); default
|
|
261
|
+
* the flows folder the runs line reads and `start` hands the panel (`--root`); default `<config home>/flows` (`defaultFlowsRoot`)
|
|
236
262
|
*/
|
|
237
263
|
root?: string | undefined;
|
|
238
264
|
portStart?: number | undefined;
|
|
@@ -258,6 +284,18 @@ export type LauncherDeps = {
|
|
|
258
284
|
*/
|
|
259
285
|
nodeVersion?: string | undefined;
|
|
260
286
|
fetchImpl?: typeof fetch | undefined;
|
|
287
|
+
/**
|
|
288
|
+
* the registry read of `update` (default global fetch); tests never go online
|
|
289
|
+
*/
|
|
290
|
+
registryFetch?: typeof fetch | undefined;
|
|
291
|
+
/**
|
|
292
|
+
* runs npm with these args, resolves its exit code (non-zero = failed, deadline included); default {@link runNpm}
|
|
293
|
+
*/
|
|
294
|
+
spawnNpm?: ((args: string[]) => Promise<number>) | undefined;
|
|
295
|
+
/**
|
|
296
|
+
* stdin is a terminal (launcherMain sets it); false/absent = `update` never asks and never installs
|
|
297
|
+
*/
|
|
298
|
+
isTTY?: boolean | undefined;
|
|
261
299
|
/**
|
|
262
300
|
* default src/panel/spawn.js `spawnDetached`
|
|
263
301
|
*/
|
|
@@ -305,3 +343,4 @@ export type LauncherDeps = {
|
|
|
305
343
|
*/
|
|
306
344
|
env?: Record<string, string | undefined> | undefined;
|
|
307
345
|
};
|
|
346
|
+
import { spawn as realSpawn } from 'node:child_process';
|
package/types/pagefetch.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export const PAGE_FETCH_TIMEOUT_MS: 90000;
|
|
|
68
68
|
* @typedef {{goto: (url: string, timeout?: number) => Promise<void>, waitForNetworkIdle: (o?: {idle?: number, timeout?: number}) => Promise<void>,
|
|
69
69
|
* snapshot: (o?: {mode?: string}) => Promise<string>, close: () => Promise<void>}} FetchPage the part of barebrowse's page handle the fetch uses
|
|
70
70
|
*/
|
|
71
|
-
/** the oldest barebrowse
|
|
71
|
+
/** the oldest barebrowse we accept: 0.21.0 honours CONNECT_OPTIONS (incognito, blockPrivateNetwork; an older one would drop both guards without a word); 0.24.1 tethers Chromium to its launcher, so a killed run or an Abandoned draft leaves no browser behind */
|
|
72
72
|
export const MIN_BAREBROWSE: number[];
|
|
73
73
|
/**
|
|
74
74
|
* the part of barebrowse's page handle the fetch uses
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const REGISTRY_URL: "https://registry.npmjs.org/fwdloop/latest";
|