fwdloop 0.24.0 → 0.25.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 +33 -26
- package/package.json +1 -1
- package/src/cited-record.js +3 -22
- package/src/cited-source.js +5 -6
- package/src/diary.js +21 -17
- package/src/flowmodel.js +6 -37
- package/src/keysfile.js +1 -1
- package/src/launcher.js +552 -0
- package/src/learnstore.js +6 -4
- package/src/line-checks.js +55 -0
- package/src/opener.js +33 -0
- package/src/panel/author.js +2 -0
- package/src/panel/authorflows.js +9 -9
- package/src/panel/authorresume.js +4 -3
- package/src/panel/data.js +3 -2
- package/src/panel/index.html +22 -8
- package/src/panel/result.js +7 -12
- package/src/panel/server.js +53 -5
- package/src/panel/settings.js +4 -18
- package/src/panel/spawn.js +0 -9
- package/src/prompts.js +33 -0
- package/src/runfile.js +60 -0
- package/src/runner.js +18 -17
- package/src/sheet-record.js +15 -35
- package/src/sheetblock.js +3 -3
- package/src/sheetrun.js +6 -6
- package/src/summary-words.js +13 -5
- package/src/tty-colour.js +29 -0
- package/types/cited-record.d.ts +0 -2
- package/types/diary.d.ts +2 -5
- package/types/flowmodel.d.ts +2 -21
- package/types/keysfile.d.ts +7 -0
- package/types/launcher.d.ts +307 -0
- package/types/learnstore.d.ts +1 -1
- package/types/line-checks.d.ts +26 -0
- package/types/opener.d.ts +12 -0
- package/types/panel/author.d.ts +2 -0
- package/types/panel/result.d.ts +1 -3
- package/types/panel/server.d.ts +24 -3
- package/types/panel/settings.d.ts +2 -2
- package/types/panel/spawn.d.ts +0 -6
- package/types/prompts.d.ts +14 -0
- package/types/runfile.d.ts +48 -0
- package/types/runner.d.ts +3 -3
- package/types/sheet-record.d.ts +0 -2
- package/types/sheetblock.d.ts +2 -2
- package/types/sheetrun.d.ts +1 -1
- package/types/summary-words.d.ts +2 -1
- package/types/tty-colour.d.ts +33 -0
package/bin/fwdloop
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
checkKeyPreflight, resolveUsableModel, pickTicked, readPriceConfig, ceilingCostUsd,
|
|
40
40
|
} from '../src/provider.js';
|
|
41
41
|
import { readModelRecord, readRunModel, LEARNINGS_FILE } from '../src/flowmodel.js';
|
|
42
|
+
import { readRunInputs } from '../src/runfile.js';
|
|
42
43
|
import { configDoorHome } from '../src/config.js';
|
|
43
44
|
import {
|
|
44
45
|
claimHold, settleHold, nameRunDir, monthlyRefusalText, ConfigError,
|
|
@@ -48,6 +49,7 @@ import {
|
|
|
48
49
|
answerAsk, readAskEvidence, normalizeDecision, stripControl, withReopen,
|
|
49
50
|
} from '../src/ask.js';
|
|
50
51
|
import { panelMain } from '../src/panel/server.js';
|
|
52
|
+
import { launcherMain } from '../src/launcher.js';
|
|
51
53
|
import { isInteractive, confirmTypedName, NEEDS_TTY } from '../src/sign-confirm.js';
|
|
52
54
|
import { draftToDir, draftKeyRefusal, signDraft, SIGN_LINE, costText, questionsRefusal } from '../src/authoring.js';
|
|
53
55
|
import { userInfo } from 'node:os';
|
|
@@ -677,24 +679,20 @@ async function cmdResume(rest) {
|
|
|
677
679
|
what: 'resume', flow: flowName, runId, runDir, holdUsd: Math.max(0, arbiter.capUsd - priorSpent), spentAtHold: priorSpent,
|
|
678
680
|
});
|
|
679
681
|
|
|
680
|
-
// Resume never re-freezes inputs — the run's own `
|
|
681
|
-
//
|
|
682
|
+
// Resume never re-freezes inputs — the run's own `run.json` (its `inputs`,
|
|
683
|
+
// written at start by `runFlow`) is the one source of the already-frozen paths a
|
|
682
684
|
// sandboxed primitive may read.
|
|
683
|
-
// F48 round 3: routed through `readFileInside` (`src/flow.js
|
|
684
|
-
// symlinked `
|
|
685
|
-
// than followed, which would otherwise let an outside file's
|
|
686
|
-
// arbitrary "frozen" paths for the sandboxed read/grep/readDocx/
|
|
685
|
+
// F48 round 3: routed through `readFileInside` (`src/flow.js`, inside
|
|
686
|
+
// `readRunInputs`) — a symlinked `run.json` is treated as "no manifest" (empty
|
|
687
|
+
// array) rather than followed, which would otherwise let an outside file's
|
|
688
|
+
// content name arbitrary "frozen" paths for the sandboxed read/grep/readDocx/
|
|
687
689
|
// addressCells tools built just below.
|
|
688
|
-
const
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
inputsManifest = JSON.parse(inputsManifestRead.text);
|
|
693
|
-
} catch (err) {
|
|
694
|
-
fail(`resume: inputs.json for run "${runId}" is not valid JSON — ${err.message}`);
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
690
|
+
const inputsRead = readRunInputs(runDir);
|
|
691
|
+
if (!inputsRead.ok && inputsRead.code === 'invalid') {
|
|
692
|
+
fail(`resume: run "${runId}": ${inputsRead.red}`);
|
|
693
|
+
return;
|
|
697
694
|
}
|
|
695
|
+
const inputsManifest = inputsRead.ok ? inputsRead.entries : [];
|
|
698
696
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
699
697
|
// F46's unwired-verb preflight refusal now lives in `resumeRun` itself
|
|
700
698
|
// (`src/runner.js`) — this CLI no longer keeps a second copy of the check.
|
|
@@ -779,16 +777,12 @@ async function cmdContinue(rest) {
|
|
|
779
777
|
what: 'resume', flow: flowName, runId, runDir, holdUsd: Math.max(0, applied.arbiter.capUsd - spentSoFar.total), spentAtHold: spentSoFar.total,
|
|
780
778
|
});
|
|
781
779
|
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
inputsManifest = JSON.parse(inputsManifestRead.text);
|
|
787
|
-
} catch (err) {
|
|
788
|
-
fail(`continue: inputs.json for run "${runId}" is not valid JSON — ${err.message}`);
|
|
789
|
-
return;
|
|
790
|
-
}
|
|
780
|
+
const inputsRead = readRunInputs(runDir);
|
|
781
|
+
if (!inputsRead.ok && inputsRead.code === 'invalid') {
|
|
782
|
+
fail(`continue: run "${runId}": ${inputsRead.red}`);
|
|
783
|
+
return;
|
|
791
784
|
}
|
|
785
|
+
const inputsManifest = inputsRead.ok ? inputsRead.entries : [];
|
|
792
786
|
const allVerbs = [...new Set(declaration.steps.flatMap((s) => s.primitives ?? []))];
|
|
793
787
|
const { tools: primitives, reds: primitiveReds } = resolvePrimitives(catalogue, allVerbs, {
|
|
794
788
|
runDir, inputs: inputsManifest.map((m) => ({ id: m.id, frozen: m.frozen })),
|
|
@@ -1014,9 +1008,21 @@ function cmdLearn(rest) {
|
|
|
1014
1008
|
|
|
1015
1009
|
// ---------------------------------------------------------------------------
|
|
1016
1010
|
|
|
1011
|
+
/**
|
|
1012
|
+
* M4b am4/am5 (the launcher): a bare `fwdloop` shows the menu; `start | stop | restart | status | install` are its five choices as verbs. All logic is src/launcher.js.
|
|
1013
|
+
* `--root <flows folder>` (default '.', like `fwdloop panel`) is the folder the runs line reads and `start` hands the panel; the config home is the real ~/.config/fwdloop.
|
|
1014
|
+
*/
|
|
1015
|
+
async function cmdLauncher(cmd, rest) {
|
|
1016
|
+
const at = rest.indexOf('--root');
|
|
1017
|
+
const given = at === -1 ? '.' : rest[at + 1];
|
|
1018
|
+
if (at !== -1 && (given === undefined || given.startsWith('--'))) fail(`${cmd}: --root needs a folder`);
|
|
1019
|
+
const args = at === -1 ? rest : rest.filter((_, i) => i !== at && i !== at + 1);
|
|
1020
|
+
process.exitCode = await launcherMain(cmd, args, { root: resolveRoot(cmd, given) });
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1017
1023
|
async function main() {
|
|
1018
1024
|
const [verb, ...rest] = process.argv.slice(2);
|
|
1019
|
-
if (!verb)
|
|
1025
|
+
if (!verb || verb === '--root') return cmdLauncher('menu', verb ? [verb, ...rest] : []);
|
|
1020
1026
|
|
|
1021
1027
|
if (verb === 'draft') return cmdDraft(rest);
|
|
1022
1028
|
if (verb === 'sign') return cmdSign(rest);
|
|
@@ -1028,7 +1034,8 @@ async function main() {
|
|
|
1028
1034
|
if (verb === 'continue') return cmdContinue(rest);
|
|
1029
1035
|
if (verb === 'panel') return cmdPanel(rest);
|
|
1030
1036
|
if (verb === 'learn') return cmdLearn(rest);
|
|
1031
|
-
|
|
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)`);
|
|
1032
1039
|
return undefined;
|
|
1033
1040
|
}
|
|
1034
1041
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fwdloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/cited-record.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// borrowed-from: bareloop src/panel/server.js@2959217 (proofOf, moneyAsRead, resultCell - the row a Result tab shows, read off bareguard's evidence)
|
|
2
|
-
// M10 piece 4: the
|
|
2
|
+
// M10 piece 4 / M8b item 3: the writer of the `cited` section of `<run>/line-checks.json` (the file's one writer is `writeLineSection`, src/line-checks.js), the record the Result tab's reader (`readCitedChecks`, src/panel/result.js) takes. One line per
|
|
3
3
|
// job line, written the moment that line's cited check has run, from the check's own answer: nothing here decides a verdict.
|
|
4
4
|
//
|
|
5
5
|
// Shape (the reader's, copied from bareloop): { lines: [ { n, source, passed, facts: [{name, kind: 'phrase'|'value', sentence}],
|
|
@@ -7,15 +7,10 @@
|
|
|
7
7
|
// Extra keys the reader ignores and the separate checker (scripts/check-cited-run.mjs) reads: per line `check` {sha256 of the frozen text, the signed facts,
|
|
8
8
|
// the count} and per row `values`.
|
|
9
9
|
// Throws away: bareguard's evidence beyond the marks of the claim's own spans; nothing: a red line keeps its judged rows (am9); only a stopped check has none.
|
|
10
|
-
import {
|
|
11
|
-
import { join } from 'node:path';
|
|
12
|
-
import { readFileInside } from './flow.js';
|
|
10
|
+
import { writeLineSection } from './line-checks.js';
|
|
13
11
|
import { moneyAs } from './pageask.js';
|
|
14
12
|
import { factSentence, countSentence, CITED_ID } from './citedcheck.js';
|
|
15
13
|
|
|
16
|
-
/** the record's name in the run's own folder; the Result tab's reader takes it from here */
|
|
17
|
-
export const CITED_CHECKS_FILE = 'cited-checks.json';
|
|
18
|
-
|
|
19
14
|
const isRec = (/** @type {unknown} */ v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
20
15
|
|
|
21
16
|
/**
|
|
@@ -120,19 +115,5 @@ export function citedLineOf({
|
|
|
120
115
|
* @param {string} runDir @param {Record<string, any>} line @returns {void}
|
|
121
116
|
*/
|
|
122
117
|
export function writeCitedLine(runDir, line) {
|
|
123
|
-
|
|
124
|
-
/** @type {Record<string, any>[]} */
|
|
125
|
-
let lines = [];
|
|
126
|
-
const had = readFileInside(runDir, CITED_CHECKS_FILE);
|
|
127
|
-
if (had.ok) {
|
|
128
|
-
try {
|
|
129
|
-
const rec = JSON.parse(had.text);
|
|
130
|
-
if (rec && Array.isArray(rec.lines)) lines = rec.lines.filter((/** @type {any} */ l) => isRec(l) && l.n !== line.n);
|
|
131
|
-
} catch { lines = []; }
|
|
132
|
-
}
|
|
133
|
-
lines.push(line);
|
|
134
|
-
lines.sort((a, b) => a.n - b.n);
|
|
135
|
-
const tmp = `${file}.tmp`;
|
|
136
|
-
writeFileSync(tmp, `${JSON.stringify({ lines }, null, 2)}\n`);
|
|
137
|
-
renameSync(tmp, file);
|
|
118
|
+
writeLineSection(runDir, 'cited', (had) => [...had.filter((/** @type {any} */ l) => isRec(l) && l.n !== line.n), line].sort((a, b) => a.n - b.n));
|
|
138
119
|
}
|
package/src/cited-source.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// M10 piece 4: the text a cited check reads - THE RUN'S OWN frozen copy of a web page or a text/markdown doc (`<run>/inputs/<file>`, written at run start by
|
|
2
|
-
// `freezeInputs`), checked against the sha256 `
|
|
2
|
+
// `freezeInputs`), checked against the sha256 `run.json` (its `inputs`) recorded when it was frozen. The drafting copy lives in the draft folder and is never read here.
|
|
3
3
|
// Same three outcomes as the CSV reader (`readInputCells`): not a text input of this run, a refusal that names why, or the text.
|
|
4
4
|
// A .docx input (M10 piece 5, item 2 "a quote in a doc") is served as its paragraph text (src/docx.js says what that throws away), its sha256 taken over the file's BYTES from the same
|
|
5
5
|
// read the text comes from. Throws away: nothing for a page or a text file. A .csv input is not served here (it is read as cells).
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { createHash } from 'node:crypto';
|
|
9
9
|
import { basename } from 'node:path';
|
|
10
10
|
import { readFileInside, resolveInside } from './flow.js';
|
|
11
|
+
import { readRunInputs } from './runfile.js';
|
|
11
12
|
import { readDocxSource } from './docx.js';
|
|
12
13
|
|
|
13
14
|
/** the frozen files served as text: a saved page (.txt) or a text/markdown document. Any other kind (a spreadsheet, a .docx, a binary) is never served as text. */
|
|
@@ -20,11 +21,9 @@ const TEXT_EXTS = Object.freeze(['.txt', '.md', '.markdown']);
|
|
|
20
21
|
* @returns {{ok: true, text: string, sha256: string, frozen: string}|{ok: false, red: string, code: 'no-manifest'|'not-an-input'|'not-text'|'unreadable'}}
|
|
21
22
|
*/
|
|
22
23
|
export function readRunSource(runDir, role, { docx = false } = {}) {
|
|
23
|
-
const manifest =
|
|
24
|
-
if (!manifest.ok) return { ok: false, code: manifest.missing ? 'no-manifest' : 'unreadable', red: manifest.missing ? `input "${role}": this run has no frozen inputs` : `input "${role}": ${manifest.red}` };
|
|
25
|
-
|
|
26
|
-
try { entries = JSON.parse(manifest.text); } catch (err) { return { ok: false, code: 'unreadable', red: `input "${role}": inputs.json is not valid JSON — ${err.message}` }; }
|
|
27
|
-
const entry = Array.isArray(entries) ? entries.find((e) => e?.id === role) : undefined;
|
|
24
|
+
const manifest = readRunInputs(runDir);
|
|
25
|
+
if (!manifest.ok) return { ok: false, code: manifest.code === 'missing' ? 'no-manifest' : 'unreadable', red: manifest.code === 'missing' ? `input "${role}": this run has no frozen inputs` : `input "${role}": ${manifest.red}` };
|
|
26
|
+
const entry = manifest.entries.find((e) => e?.id === role);
|
|
28
27
|
if (!entry || typeof entry.frozen !== 'string' || typeof entry.sha256 !== 'string') return { ok: false, code: 'not-an-input', red: `input "${role}": this run froze no input with that name` };
|
|
29
28
|
const lower = entry.frozen.toLowerCase();
|
|
30
29
|
if (docx && lower.endsWith('.docx')) return readRunDocx(runDir, role, entry);
|
package/src/diary.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// M4d am29 item 1-3: the run's
|
|
2
|
-
// (src/planrun.js: `new Gate({ audit: { path } })`, the path denied to the worker with `fs.deny`).
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// checks
|
|
1
|
+
// M4d am29 item 1-3 / M8b item 2: the run's one add-only step diary, `diary.jsonl`, in the run's own folder, the way bareloop keeps its gate audit sidecar
|
|
2
|
+
// (src/planrun.js: `new Gate({ audit: { path } })`, the path denied to the worker with `fs.deny`). Every row carries `kind`, in the order the rows were written:
|
|
3
|
+
// kind 'call' one row per MODEL CALL: step, try, round, cost, tokens, time, stop reason, thinking asked and status
|
|
4
|
+
// kind 'tool' one row per TOOL CALL: step, try, round, tool, path, the guard's decision (allow / deny + rule / no check)
|
|
5
|
+
// kind 'checks' one row per TRY that ran checks: each check numbered, ✓/✗, its result, where it comes from, and the output it judged
|
|
6
6
|
// Never saved: what the model said, what was in any file (a tool row names a path, never its content). Every string is scrubbed with the
|
|
7
|
-
// ONE secret inventory (`redactSecrets`, src/redact.js) before the row is written. The model can never read
|
|
8
|
-
// bareguard Gate denies
|
|
7
|
+
// ONE secret inventory (`redactSecrets`, src/redact.js) before the row is written. The model can never read this file: the step's
|
|
8
|
+
// bareguard Gate denies it (src/primitives.js) and a grep over the run folder drops its hits.
|
|
9
9
|
// Rounds count from 1 in EACH STEP (they keep counting across that step's tries); `nextRound` reads the count off the diary.
|
|
10
10
|
//
|
|
11
11
|
// borrowed-from: bareloop src/planrun.js@fd78723 (the gate audit sidecar + fs.deny of its path; the per-round rows emitted from the onLlmResult wrapper)
|
|
@@ -14,10 +14,12 @@ import { appendRow } from './jsonl-append.js';
|
|
|
14
14
|
import { readLines } from './books.js';
|
|
15
15
|
import { redactSecrets } from './redact.js';
|
|
16
16
|
|
|
17
|
-
export const
|
|
17
|
+
export const DIARY_FILE = 'diary.jsonl';
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
export const diaryPaths = (runDir) =>
|
|
19
|
+
/** The diary's absolute path for a run, for the model's deny list (a list, as the deny lists take one). @param {string} runDir @returns {string[]} */
|
|
20
|
+
export const diaryPaths = (runDir) => [join(runDir, DIARY_FILE)];
|
|
21
|
+
|
|
22
|
+
/** @typedef {'call'|'tool'|'checks'} DiaryKind */
|
|
21
23
|
|
|
22
24
|
/** A copy of a JSON value with every string scrubbed. @param {any} v @returns {any} */
|
|
23
25
|
function scrub(v) {
|
|
@@ -27,22 +29,24 @@ function scrub(v) {
|
|
|
27
29
|
return v;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
/** The ONE writer of a diary row. @param {string} runDir @param {
|
|
31
|
-
function write(runDir, kind, row) { appendRow(join(runDir,
|
|
32
|
+
/** The ONE writer of a diary row. @param {string} runDir @param {DiaryKind} kind @param {Record<string, any>} row */
|
|
33
|
+
function write(runDir, kind, row) { appendRow(join(runDir, DIARY_FILE), scrub({ kind, ...row })); }
|
|
32
34
|
|
|
33
35
|
/** @param {string} runDir @param {{step:string|null, try:number|null, round:number, at:string, model:string|null, costUsd:number|null, tokens:{in:number,out:number,cache:number}|null, ms:number|null, stopReason:string|null, thinking:{asked:string|null,status:string|null}}} row */
|
|
34
|
-
export const appendCall = (runDir, row) => write(runDir, '
|
|
36
|
+
export const appendCall = (runDir, row) => write(runDir, 'call', row);
|
|
35
37
|
/** @param {string} runDir @param {{step:string|null, try:number|null, round:number, at:string, tool:string, path:string|null, decision:'allow'|'deny'|'no check', rule:string|null}} row */
|
|
36
|
-
export const appendTool = (runDir, row) => write(runDir, '
|
|
38
|
+
export const appendTool = (runDir, row) => write(runDir, 'tool', row);
|
|
37
39
|
/** @param {string} runDir @param {{step:string|null, try:number, at:string, lastRound:number, checks:Array<{n:number, text:string, ok:boolean, result:string|null, source:string}>, output:{file:string, bytes:number, sha256:string}|null}} row */
|
|
38
40
|
export const appendChecks = (runDir, row) => write(runDir, 'checks', row);
|
|
39
41
|
|
|
42
|
+
/** The rows of one kind, in the order they were written; a torn or unparseable line is skipped (the writer's fresh-line rule is its other half). @param {string} runDir @param {DiaryKind} kind @returns {any[]} */
|
|
43
|
+
const readKind = (runDir, kind) => readLines(runDir, DIARY_FILE).filter((r) => r.kind === kind);
|
|
40
44
|
/** @param {string} runDir @returns {any[]} */
|
|
41
|
-
export const readCalls = (runDir) =>
|
|
45
|
+
export const readCalls = (runDir) => readKind(runDir, 'call');
|
|
42
46
|
/** @param {string} runDir @returns {any[]} */
|
|
43
|
-
export const readTools = (runDir) =>
|
|
47
|
+
export const readTools = (runDir) => readKind(runDir, 'tool');
|
|
44
48
|
/** @param {string} runDir @returns {any[]} */
|
|
45
|
-
export const readChecks = (runDir) =>
|
|
49
|
+
export const readChecks = (runDir) => readKind(runDir, 'checks');
|
|
46
50
|
|
|
47
51
|
/** The round number of this step's next model call: one more than the highest round it has in the diary, so it counts on across tries and across resumes.
|
|
48
52
|
* Read off the file each time (the diary is the one record), never a copy held in memory. @param {string} runDir @param {string|null} step */
|
package/src/flowmodel.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { writeFileSync, renameSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { readFileInside } from './flow.js';
|
|
8
|
+
import { readRunRecord, readRunThinking } from './runfile.js';
|
|
8
9
|
import { isKeyName } from './provider.js';
|
|
9
10
|
|
|
10
11
|
export const MODEL_FILE = 'model.json';
|
|
@@ -35,11 +36,8 @@ function writeOnce(file, obj) {
|
|
|
35
36
|
writeFileSync(file, `${JSON.stringify(obj, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
/** M4d am25: the file in a run's folder that keeps the box as the run started with it (outside `job/`, which holds the three signed files only). */
|
|
39
|
-
export const RUN_THINKING_FILE = 'thinking.json';
|
|
40
|
-
|
|
41
39
|
/**
|
|
42
|
-
* M4d am25: the ONE reader of the job's "Thinking on" box for a run. A run reads its OWN record (`<run>/
|
|
40
|
+
* M4d am25: the ONE reader of the job's "Thinking on" box for a run. A run reads its OWN record (`thinking` in `<run>/run.json`, written once when the run
|
|
43
41
|
* started) when it has one; otherwise the flow folder's `model.json`. No record, an unreadable one, or one without `thinking` is box OFF: a job
|
|
44
42
|
* signed before am25 stored nothing, and it must not start thinking on every try.
|
|
45
43
|
* @param {string} flowDir @param {string|null} runDir @returns {boolean}
|
|
@@ -49,42 +47,13 @@ export function readJobThinking(flowDir, runDir) {
|
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
/**
|
|
52
|
-
* M4d
|
|
53
|
-
* An unreadable record is box off, as `readJobThinking` has always read it. @param {string|null} runDir @returns {boolean|null}
|
|
54
|
-
*/
|
|
55
|
-
export function readRunThinking(runDir) {
|
|
56
|
-
const own = typeof runDir === 'string' ? readFileInside(runDir, RUN_THINKING_FILE) : null;
|
|
57
|
-
if (!own?.ok) return null;
|
|
58
|
-
try { return JSON.parse(own.text)?.thinking === true; } catch { return false; }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* M4d am25: a run keeps the box as the job had it when the run started (write-once, so an Edit of the job never changes a run already going).
|
|
63
|
-
* Written for every fresh run, ticked or not. @param {string} flowDir @param {string} runDir
|
|
64
|
-
*/
|
|
65
|
-
export function writeRunThinking(flowDir, runDir) {
|
|
66
|
-
writeOnce(join(runDir, RUN_THINKING_FILE), { thinking: readModelRecord(flowDir)?.thinking === true });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** M4d am33: the file in a run's folder that records the model the run STARTED on (write-once; every continue path keeps it). */
|
|
70
|
-
export const RUN_MODEL_FILE = 'run-model.json';
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* M4d am33: the ONE reader of the model a run started on, or null (a run from before the record, or an unusable one: the caller then keeps today's pick).
|
|
50
|
+
* M4d am33: the ONE reader of the model a run started on (`model` in `<run>/run.json`), or null (a run from before the record, or an unusable one: the caller then keeps today's pick).
|
|
74
51
|
* @param {string|null} runDir @returns {{ slot: string, model: string }|null}
|
|
75
52
|
*/
|
|
76
53
|
export function readRunModel(runDir) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const j = JSON.parse(r.text);
|
|
81
|
-
return isKeyName(j?.slot) && typeof j?.model === 'string' && j.model !== '' ? { slot: j.slot, model: j.model } : null;
|
|
82
|
-
} catch { return null; }
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** M4d am33: the ONE writer, called once when a fresh run starts (`runFlow`); never over an existing record. @param {string} runDir @param {{ slot: string, model: string }} pick */
|
|
86
|
-
export function writeRunModel(runDir, { slot, model }) {
|
|
87
|
-
writeOnce(join(runDir, RUN_MODEL_FILE), { slot, model });
|
|
54
|
+
const got = readRunRecord(runDir);
|
|
55
|
+
const m = got.ok ? got.rec.model : null;
|
|
56
|
+
return isKeyName(m?.slot) && typeof m?.model === 'string' && m.model !== '' ? { slot: m.slot, model: m.model } : null;
|
|
88
57
|
}
|
|
89
58
|
|
|
90
59
|
/**
|
package/src/keysfile.js
CHANGED
|
@@ -99,7 +99,7 @@ export function parseKeysText(text) {
|
|
|
99
99
|
* @param {string} [home]
|
|
100
100
|
* @returns {boolean} true if it was created
|
|
101
101
|
*/
|
|
102
|
-
function createKeysFile(home) {
|
|
102
|
+
export function createKeysFile(home) {
|
|
103
103
|
mkdirSync(keysHome(home), { recursive: true, mode: 0o700 });
|
|
104
104
|
const body = '# fwdloop keys — type NAME=value by hand; this file is never shown or written by fwdloop.\n'
|
|
105
105
|
+ '# One line per provider key, e.g. MY_PROVIDER_API_KEY=... ; each key becomes a row in Settings > Providers.\n';
|