fwdloop 0.23.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.
Files changed (71) hide show
  1. package/bin/fwdloop +62 -32
  2. package/package.json +1 -1
  3. package/src/ask.js +15 -1
  4. package/src/attemptdiff.js +118 -0
  5. package/src/audit-fold.js +2 -0
  6. package/src/authoring.js +32 -2
  7. package/src/cited-record.js +3 -22
  8. package/src/cited-source.js +5 -6
  9. package/src/citedwords.js +36 -2
  10. package/src/config.js +5 -1
  11. package/src/diary.js +21 -17
  12. package/src/drafter.js +6 -2
  13. package/src/flowmodel.js +52 -28
  14. package/src/keysfile.js +1 -1
  15. package/src/launcher.js +552 -0
  16. package/src/learn.js +952 -0
  17. package/src/learnstore.js +348 -0
  18. package/src/line-checks.js +55 -0
  19. package/src/model-step.js +2 -0
  20. package/src/opener.js +33 -0
  21. package/src/pagedry.js +3 -4
  22. package/src/pagefetch.js +9 -2
  23. package/src/pagerules.js +28 -5
  24. package/src/panel/author.js +2 -0
  25. package/src/panel/authorflows.js +9 -9
  26. package/src/panel/authorresume.js +4 -3
  27. package/src/panel/data.js +63 -14
  28. package/src/panel/index.html +162 -16
  29. package/src/panel/result.js +7 -12
  30. package/src/panel/server.js +53 -5
  31. package/src/panel/settings.js +4 -18
  32. package/src/panel/spawn.js +0 -9
  33. package/src/prompts.js +33 -0
  34. package/src/redact.js +6 -6
  35. package/src/runfile.js +60 -0
  36. package/src/runner.js +144 -33
  37. package/src/sheet-record.js +15 -35
  38. package/src/sheetblock.js +3 -3
  39. package/src/sheetrun.js +6 -6
  40. package/src/summary-words.js +13 -5
  41. package/src/thinking.js +11 -0
  42. package/src/tty-colour.js +29 -0
  43. package/types/ask.d.ts +7 -2
  44. package/types/attemptdiff.d.ts +38 -0
  45. package/types/cited-record.d.ts +0 -2
  46. package/types/citedwords.d.ts +14 -0
  47. package/types/diary.d.ts +2 -5
  48. package/types/drafter.d.ts +6 -1
  49. package/types/flowmodel.d.ts +37 -20
  50. package/types/keysfile.d.ts +7 -0
  51. package/types/launcher.d.ts +307 -0
  52. package/types/learn.d.ts +576 -0
  53. package/types/learnstore.d.ts +168 -0
  54. package/types/line-checks.d.ts +26 -0
  55. package/types/opener.d.ts +12 -0
  56. package/types/pagerules.d.ts +7 -0
  57. package/types/panel/author.d.ts +2 -0
  58. package/types/panel/data.d.ts +2 -1
  59. package/types/panel/result.d.ts +2 -4
  60. package/types/panel/server.d.ts +24 -3
  61. package/types/panel/settings.d.ts +2 -2
  62. package/types/panel/spawn.d.ts +0 -6
  63. package/types/prompts.d.ts +14 -0
  64. package/types/runfile.d.ts +48 -0
  65. package/types/runner.d.ts +14 -5
  66. package/types/sheet-record.d.ts +0 -2
  67. package/types/sheetblock.d.ts +2 -2
  68. package/types/sheetrun.d.ts +1 -1
  69. package/types/summary-words.d.ts +2 -1
  70. package/types/thinking.d.ts +11 -0
  71. package/types/tty-colour.d.ts +33 -0
@@ -0,0 +1,29 @@
1
+ // borrowed-from: bareloop src/tty-colour.js@v0.47.1 (704d598)
2
+ // Adaptation: none.
3
+ // ONE place for terminal colour (the launcher's header, menu and messages). Colours wrap words and never change them: with colour off
4
+ // every helper returns its text untouched, so plain-text readers (tests, pipes, logs) see the same words.
5
+
6
+ const wrap = (/** @type {string} */ code) => (/** @type {string} */ s) => `\x1b[${code}m${s}\x1b[0m`;
7
+ const id = (/** @type {string} */ s) => s;
8
+
9
+ /**
10
+ * @typedef {object} Paint
11
+ * @property {boolean} on
12
+ * @property {(s: string) => string} grey @property {(s: string) => string} green @property {(s: string) => string} yellow
13
+ * @property {(s: string) => string} red @property {(s: string) => string} cyan @property {(s: string) => string} boldCyan
14
+ */
15
+
16
+ /**
17
+ * Colour is on only for a terminal: the stream says it is a TTY, `NO_COLOR` is empty/unset, and `TERM` is not `dumb`.
18
+ * @param {{isTTY?: boolean}|undefined} stream the output stream (process.stdout)
19
+ * @param {Record<string, string|undefined>} [env]
20
+ * @returns {Paint}
21
+ */
22
+ export function makePaint(stream, env = process.env) {
23
+ const on = Boolean(stream && stream.isTTY) && !(env.NO_COLOR ?? '') && env.TERM !== 'dumb';
24
+ if (!on) return { on, grey: id, green: id, yellow: id, red: id, cyan: id, boldCyan: id };
25
+ return { on, grey: wrap('90'), green: wrap('32'), yellow: wrap('33'), red: wrap('31'), cyan: wrap('36'), boldCyan: wrap('1;36') };
26
+ }
27
+
28
+ /** the no-colour paint, the default when a caller passes none */
29
+ export const PLAIN = makePaint(undefined, {});
package/types/ask.d.ts CHANGED
@@ -51,7 +51,7 @@ export function makeFileAskStep({ timeoutMs, pollMs, clock, writeLine, }?: {
51
51
  * @param {any} ask the parsed ask.json object (or its `evidence` field's
52
52
  * container — pass the whole ask so a missing `evidence` key is itself a
53
53
  * handled case, not the caller's problem).
54
- * @returns {{ draft: {step?: string, text: string} | null, unjudged: Array<{step: string, emits?: string, text: string}>, why?: string, claims?: Record<string, any> }}
54
+ * @returns {{ draft: {step?: string, text: string} | null, unjudged: Array<{step: string, emits?: string, text?: string, cells?: Record<string, unknown>}>, why?: string, claims?: Record<string, any>, results?: Array<{quote: string, values: Record<string, unknown>}> }}
55
55
  */
56
56
  export function readAskEvidence(ask: any): {
57
57
  draft: {
@@ -61,10 +61,15 @@ export function readAskEvidence(ask: any): {
61
61
  unjudged: Array<{
62
62
  step: string;
63
63
  emits?: string;
64
- text: string;
64
+ text?: string;
65
+ cells?: Record<string, unknown>;
65
66
  }>;
66
67
  why?: string;
67
68
  claims?: Record<string, any>;
69
+ results?: Array<{
70
+ quote: string;
71
+ values: Record<string, unknown>;
72
+ }>;
68
73
  };
69
74
  /**
70
75
  * M4b piece 3: the ONE serialisation of an artifact's bytes — what
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Cut `text` to at most `max` bytes at a LINE boundary (never mid-line).
3
+ * @param {string} text @param {number} max
4
+ * @returns {{text: string, truncated: boolean, cutLines: number}}
5
+ */
6
+ export function cutAtLine(text: string, max: number): {
7
+ text: string;
8
+ truncated: boolean;
9
+ cutLines: number;
10
+ };
11
+ /**
12
+ * Begin recording one worker try. Call BEFORE the worker's turn; call `finish()` after
13
+ * (in a `finally`). Never throws.
14
+ * @param {{workdir: string, fence: string[], redact?: (s: string) => string}} o
15
+ * `fence` = the ABSOLUTE write-scope prefixes the gate enforces for this try.
16
+ * @returns {Promise<{finish: () => Promise<null | {files: {path: string, diff: string, truncated: boolean, cutLines: number}[], binary: string[], truncated: boolean, gitError?: string}>}>}
17
+ * `finish()` resolves null when the try changed nothing in scope.
18
+ */
19
+ export function startAttemptDiff({ workdir, fence, redact }: {
20
+ workdir: string;
21
+ fence: string[];
22
+ redact?: (s: string) => string;
23
+ }): Promise<{
24
+ finish: () => Promise<null | {
25
+ files: {
26
+ path: string;
27
+ diff: string;
28
+ truncated: boolean;
29
+ cutLines: number;
30
+ }[];
31
+ binary: string[];
32
+ truncated: boolean;
33
+ gitError?: string;
34
+ }>;
35
+ }>;
36
+ /** per-file and per-event byte caps for the recorded diff text */
37
+ export const ATTEMPT_DIFF_FILE_MAX: 4096;
38
+ export const ATTEMPT_DIFF_EVENT_MAX: 16384;
@@ -17,5 +17,3 @@ export function citedLineOf({ n, part, results, check, confirmed, }: {
17
17
  * @param {string} runDir @param {Record<string, any>} line @returns {void}
18
18
  */
19
19
  export function writeCitedLine(runDir: string, line: Record<string, any>): void;
20
- /** the record's name in the run's own folder; the Result tab's reader takes it from here */
21
- export const CITED_CHECKS_FILE: "cited-checks.json";
@@ -76,6 +76,20 @@ export function placeReds({ part, line, look }: {
76
76
  facts?: any[];
77
77
  } | null | undefined;
78
78
  }): WordRed[];
79
+ /**
80
+ * A limit the page look read from a guardrail ("under $40" -> price under 40, `reading` on a kept fact, src/pagerules.js) must be carried by a fact of the part,
81
+ * with the same kind, op and bound. A plan that leaves it out would pass a result the guardrail forbids ($48 under "under $40"). Only a reading code accepts
82
+ * (validReading) whose bounds are in the person's own words on the line is demanded; a bound that is not said gets its ask (src/pageask.js), never a refusal.
83
+ * @param {{part: any, line: number, jobLine: any, look: {facts?: any[]}|null|undefined}} o @returns {WordRed[]}
84
+ */
85
+ export function boundReds({ part, line, jobLine, look, }: {
86
+ part: any;
87
+ line: number;
88
+ jobLine: any;
89
+ look: {
90
+ facts?: any[];
91
+ } | null | undefined;
92
+ }): WordRed[];
79
93
  /**
80
94
  * Every word red for one cited part, in the order a person fixes them.
81
95
  * @param {{part: any, text: string|undefined, line: number, jobLine: any, look: {facts?: any[], dropped?: any[]}|null|undefined, doc?: boolean}} o @returns {WordRed[]}
package/types/diary.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- export const DIARY_FILES: Readonly<{
2
- calls: "calls.jsonl";
3
- tools: "tools.jsonl";
4
- checks: "checks.jsonl";
5
- }>;
1
+ export const DIARY_FILE: "diary.jsonl";
6
2
  export function diaryPaths(runDir: string): string[];
7
3
  export function appendCall(runDir: string, row: {
8
4
  step: string | null;
@@ -55,3 +51,4 @@ export function readCalls(runDir: string): any[];
55
51
  export function readTools(runDir: string): any[];
56
52
  export function readChecks(runDir: string): any[];
57
53
  export function nextRound(runDir: string, step: string | null): any;
54
+ export type DiaryKind = "call" | "tool" | "checks";
@@ -489,9 +489,10 @@ export function goalForLine(fromLine: any, lines: any): any;
489
489
  * costUsd:number|null, modelReturned:string|null, modelId?:string, price?:object|null, tokens?:object|null, structureRetries:number, revisions:number, stop:string|null, log:object[],
490
490
  * questions?:{line:number, question:string}[], droppedQuestions?:object[], notChecked?:string[], thinking?:{asked:string, status:string|null, say:string|null}, inputs?:{role:string, detail:string}[],
491
491
  * look?:{facts:any[], dropped:any[]}, pageLooks?:{role:string, address:string, sha256:string, bytes:number, frozen:string, attempts:number, mapping:any}[], sheetLooks?:any[]}>}
492
+ * `learnHints` (M8 item 5a): the earlier runs' notes block (src/learnstore.js hintsForRun), appended to the drafter's system prompt; null = nothing.
492
493
  * `look` / `pageLooks` (M10 item 3) are there when the job signs a web page: the kept facts (with their `reading`, the input a later ask reads), every drop, and per page its address, sha256 and the AI's map. Each drop is also a line in `notChecked`.
493
494
  */
494
- export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, priorSpend, skills, makeProviderFn, onBook, offerQuestions, draftThinking, draftDir, fetchPage, leftRules, }: {
495
+ export function draft({ proseText, slot, model, provider: injected, rates: injectedRates, modelId: injectedModelId, env, priorSpend, skills, makeProviderFn, onBook, offerQuestions, draftThinking, draftDir, fetchPage, leftRules, learnHints, }: {
495
496
  proseText: any;
496
497
  slot: any;
497
498
  model: any;
@@ -511,6 +512,10 @@ export function draft({ proseText, slot, model, provider: injected, rates: injec
511
512
  line: number;
512
513
  rule: number;
513
514
  }[] | undefined;
515
+ learnHints?: {
516
+ text: string;
517
+ ids: string[];
518
+ } | null | undefined;
514
519
  }): Promise<{
515
520
  ok: boolean;
516
521
  declaration: object | null;
@@ -17,37 +17,54 @@ export function writeModelRecord(dir: string, { slot, model, thinking }: {
17
17
  thinking?: boolean;
18
18
  }): void;
19
19
  /**
20
- * M4d am25: the ONE reader of the job's "Thinking on" box for a run. A run reads its OWN record (`<run>/thinking.json`, written once when the run
20
+ * 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
21
21
  * 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
22
22
  * signed before am25 stored nothing, and it must not start thinking on every try.
23
23
  * @param {string} flowDir @param {string|null} runDir @returns {boolean}
24
24
  */
25
25
  export function readJobThinking(flowDir: string, runDir: string | null): boolean;
26
26
  /**
27
- * M4d am26: the run's OWN record of the box (`<run>/thinking.json`) and nothing else: `true`/`false`, or `null` when the run has none (a run from before am25).
28
- * An unreadable record is box off, as `readJobThinking` has always read it. @param {string|null} runDir @returns {boolean|null}
29
- */
30
- export function readRunThinking(runDir: string | null): boolean | null;
31
- /**
32
- * 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).
33
- * Written for every fresh run, ticked or not. @param {string} flowDir @param {string} runDir
34
- */
35
- export function writeRunThinking(flowDir: string, runDir: string): void;
36
- /**
37
- * 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).
27
+ * 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).
38
28
  * @param {string|null} runDir @returns {{ slot: string, model: string }|null}
39
29
  */
40
30
  export function readRunModel(runDir: string | null): {
41
31
  slot: string;
42
32
  model: string;
43
33
  } | null;
44
- /** 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 */
45
- export function writeRunModel(runDir: string, { slot, model }: {
46
- slot: string;
47
- model: string;
34
+ /** @param {string} dir @param {{text: string, ids: string[]}} hints */
35
+ export function writeLearningsRecord(dir: string, { text, ids }: {
36
+ text: string;
37
+ ids: string[];
48
38
  }): void;
39
+ /**
40
+ * The drafter's failed ask for the block (or failed record write) rides the same record: nothing handed (`text: ''`, no ids), and `error` (first line, secrets redacted).
41
+ * `readLearningsRecord` reads an empty text as no record, so the Audit box stays hidden and `copyLearningsRecord` copies nothing.
42
+ * @param {string} dir @param {string} error
43
+ */
44
+ export function writeLearningsError(dir: string, error: string): void;
45
+ /**
46
+ * M8 item 6: the Audit box reads the record in the RUN's folder. It reaches the run the way `model.json` does: a draft's record is copied (write-once) into the folder it is signed
47
+ * into (`copyLearningsRecord`: the flow folder at a new job's sign, the new run's folder at a red run's redraft), and the first run that starts from a flow folder TAKES it
48
+ * (`takeLearningsRecord`: a rename, so it moves once and a second run of the same job never shows it). A run that reused its plan has no draft, so it has none.
49
+ * @param {string} fromDir a draft folder @param {string} toDir a flow folder or a run folder @returns {boolean} true when a record was copied
50
+ */
51
+ export function copyLearningsRecord(fromDir: string, toDir: string): boolean;
52
+ /** @param {string} flowDir @param {string} runDir @returns {boolean} true when the flow's record moved into the run (it is no longer in the flow folder) */
53
+ export function takeLearningsRecord(flowDir: string, runDir: string): boolean;
54
+ /**
55
+ * The ONE reader of a run's record. null = no record, or one that is not `{phase, text, ids, chars}` (the box is then hidden, never guessed).
56
+ * @param {string} runDir @returns {{phase: string, text: string, ids: string[], chars: number}|null}
57
+ */
58
+ export function readLearningsRecord(runDir: string): {
59
+ phase: string;
60
+ text: string;
61
+ ids: string[];
62
+ chars: number;
63
+ } | null;
49
64
  export const MODEL_FILE: "model.json";
50
- /** 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). */
51
- export const RUN_THINKING_FILE: "thinking.json";
52
- /** M4d am33: the file in a run's folder that records the model the run STARTED on (write-once; every continue path keeps it). */
53
- export const RUN_MODEL_FILE: "run-model.json";
65
+ /**
66
+ * M8 item 5a: the file that keeps EXACTLY what the drafter was handed from earlier runs (the Audit box of item 6 reads it). Bareloop's
67
+ * `learnings` spine record shape, `{phase, text, ids, chars}`. Write-once (never over an existing record); written with something handed, or by `writeLearningsError` with an empty `text`
68
+ * (a failed ask: nothing handed, why in `error`); a reader treats empty text as no record, so no file or empty text = nothing handed = no box. Borrowed-from: bareloop src/planrun.js@v0.46.0:3092 (emit('learnings', ...)).
69
+ */
70
+ export const LEARNINGS_FILE: "learnings.json";
@@ -25,6 +25,13 @@ export function chmodSentence(home?: string): string;
25
25
  * @returns {Record<string,string>}
26
26
  */
27
27
  export function parseKeysText(text: string): Record<string, string>;
28
+ /**
29
+ * Create the file when — and only when — it does not exist: mode 0600 (`wx`), dir 0700,
30
+ * the known key names as commented lines and nothing else.
31
+ * @param {string} [home]
32
+ * @returns {boolean} true if it was created
33
+ */
34
+ export function createKeysFile(home?: string): boolean;
28
35
  /**
29
36
  * @typedef {object} KeysLoad
30
37
  * @property {boolean} ok false = refused: nothing that needs a key may run
@@ -0,0 +1,307 @@
1
+ /**
2
+ * @typedef {object} Panel one answered probe
3
+ * @property {number} port @property {number} pid @property {string} version @property {number} drafts @property {number} schedules @property {string} [startedAt] ISO, absent on an older panel
4
+ * @property {string} url
5
+ */
6
+ /**
7
+ * @typedef {object} LauncherDeps every OS touch, injectable (a test passes all of them)
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 '.' like `fwdloop panel`
10
+ * @property {number} [portStart] @property {number} [portCount]
11
+ * @property {number[]} [ports] an explicit port list (tests); wins over portStart/portCount
12
+ * @property {number} [timeoutMs] probe timeout per port
13
+ * @property {number} [deadlineMs] start/stop wait deadline
14
+ * @property {number} [silentWaitMs] how long start keeps asking a taken, silent port (default 10 s)
15
+ * @property {string} [nodeVersion] default process.versions.node
16
+ * @property {typeof fetch} [fetchImpl]
17
+ * @property {(a: {bin: string, argv: string[], env: Record<string, string|undefined>, logPath: string}) => any} [spawnFn] default src/panel/spawn.js `spawnDetached`
18
+ * @property {(pid: number, sig: string|number) => void} [kill] default process.kill
19
+ * @property {((target: string) => Promise<boolean>)} [open] default the shared OS opener
20
+ * @property {(port: number) => Promise<boolean>} [portFree] default: try to bind 127.0.0.1:port
21
+ * @property {(ms: number) => Promise<void>} [sleep]
22
+ * @property {(question: string) => Promise<string>} [ask] the y/N and menu reader
23
+ * @property {string} [fwdloopBin] default bin/fwdloop of this package
24
+ * @property {import('./tty-colour.js').Paint} [paint] colour for stdout lines (default none); {@link makePaint} decides TTY / NO_COLOR / TERM
25
+ * @property {import('./tty-colour.js').Paint} [paintErr] colour for stderr lines (default: `paint`)
26
+ * @property {number} [now] ms clock for the run list's 7-day rule (default: real time); tests pass their own
27
+ * @property {Record<string, string|undefined>} [env] raw env handed to the panel child (default process.env)
28
+ */
29
+ /**
30
+ * The run counts, from the panel's own `listRuns` rows - the SAME two reads the page makes (src/panel/index.html: Running now = `live === true`,
31
+ * Needs you = a non-empty `needs`, the tag `needsYouOf` decides, M11 included). A flow with no runs yet (`runId` null) is not a run. A part that is 0 still shows.
32
+ * @param {any[]} rows
33
+ * @returns {{running: number, needYou: number, total: number}}
34
+ */
35
+ export function countRuns(rows: any[]): {
36
+ running: number;
37
+ needYou: number;
38
+ total: number;
39
+ };
40
+ /**
41
+ * "installed ✓" = the folder exists, config.json is there and reads with no problem, `.env` exists with mode 600, node >= 22.
42
+ * Otherwise the FIRST missing thing in plain words.
43
+ * @param {{home?: string, nodeVersion?: string}} o
44
+ * @returns {{ok: boolean, problem: string|null}}
45
+ */
46
+ export function installState(o: {
47
+ home?: string;
48
+ nodeVersion?: string;
49
+ }): {
50
+ ok: boolean;
51
+ problem: string | null;
52
+ };
53
+ /**
54
+ * Ask one port for `/api/whoami`. Never throws. `silent` = no reply inside the timeout (a loaded or stuck process may still be a
55
+ * panel); `other` = something replied (or refused) and it is not a fwdloop whoami.
56
+ * @param {{port: number, timeoutMs?: number, fetchImpl?: typeof fetch}} o
57
+ * @returns {Promise<{state: 'panel', panel: Panel}|{state: 'other'}|{state: 'silent'}>}
58
+ */
59
+ export function probePort(o: {
60
+ port: number;
61
+ timeoutMs?: number;
62
+ fetchImpl?: typeof fetch;
63
+ }): Promise<{
64
+ state: "panel";
65
+ panel: Panel;
66
+ } | {
67
+ state: "other";
68
+ } | {
69
+ state: "silent";
70
+ }>;
71
+ /**
72
+ * Ask 127.0.0.1 across the ports in parallel; a reply with `app === "fwdloop"` is a panel. Never throws.
73
+ * @param {{ports: number[], timeoutMs?: number, fetchImpl?: typeof fetch}} o
74
+ * @returns {Promise<Panel[]>} in port order
75
+ */
76
+ export function probePanels(o: {
77
+ ports: number[];
78
+ timeoutMs?: number;
79
+ fetchImpl?: typeof fetch;
80
+ }): Promise<Panel[]>;
81
+ /**
82
+ * The panel's own date style (src/panel/index.html rlShortDate): local `MM/DD HH:MM`; an unparseable stamp is shown raw, never blank.
83
+ * @param {string} iso
84
+ */
85
+ export function shortDate(iso: string): string;
86
+ /**
87
+ * The header, ONCE per call: the two lines every `fwdloop` command prints first, plus the panels the probe found (the commands
88
+ * reuse them, so nothing is probed twice).
89
+ * @param {LauncherDeps & {version?: string}} d
90
+ * @returns {Promise<{lines: string[], panels: Panel[]}>}
91
+ */
92
+ export function buildHeader(d: LauncherDeps & {
93
+ version?: string;
94
+ }): Promise<{
95
+ lines: string[];
96
+ panels: Panel[];
97
+ }>;
98
+ /**
99
+ * @param {LauncherDeps & {version?: string}} d
100
+ * @returns {Promise<string[]>} the two header lines
101
+ */
102
+ export function headerLines(d: LauncherDeps & {
103
+ version?: string;
104
+ }): Promise<string[]>;
105
+ /**
106
+ * `fwdloop install` — creates only what is missing, never reads a key value.
107
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
108
+ * @returns {Promise<number>}
109
+ */
110
+ export function installCmd(io: {
111
+ out: (s: string) => void;
112
+ err: (s: string) => void;
113
+ }, d: LauncherDeps & {
114
+ version?: string;
115
+ }, shown?: {
116
+ lines: string[];
117
+ panels: Panel[];
118
+ }): Promise<number>;
119
+ /**
120
+ * `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
+ * @param {{out: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown] header the menu already printed
122
+ * @returns {Promise<number>}
123
+ */
124
+ export function statusCmd(io: {
125
+ out: (s: string) => void;
126
+ }, d: LauncherDeps & {
127
+ version?: string;
128
+ }, shown?: {
129
+ lines: string[];
130
+ panels: Panel[];
131
+ }): Promise<number>;
132
+ /**
133
+ * `fwdloop start` — find a running panel first; else start one detached on the first free port 4800..4809, wait until it answers,
134
+ * open the page.
135
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
136
+ * @returns {Promise<number>}
137
+ */
138
+ export function startCmd(io: {
139
+ out: (s: string) => void;
140
+ err: (s: string) => void;
141
+ }, d: LauncherDeps & {
142
+ version?: string;
143
+ }, shown?: {
144
+ lines: string[];
145
+ panels: Panel[];
146
+ }): Promise<number>;
147
+ /**
148
+ * `fwdloop stop [--yes]` — SIGTERM the pid of EVERY panel the probe finds (one panel at a time is the rule; no "which one"), wait until each
149
+ * port stops answering. Drafts are in memory: warn (summed over all found panels) and ask y/N unless `--yes`.
150
+ * @param {string[]} args
151
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
152
+ * @returns {Promise<number>}
153
+ */
154
+ export function stopCmd(args: string[], io: {
155
+ out: (s: string) => void;
156
+ err: (s: string) => void;
157
+ }, d: LauncherDeps & {
158
+ version?: string;
159
+ }, shown?: {
160
+ lines: string[];
161
+ panels: Panel[];
162
+ }): Promise<number>;
163
+ /**
164
+ * `fwdloop restart [--yes]` (M4b am6 item 2) — the existing stop (same open-drafts warning and question; `--yes` skips it), then the existing start, on the port
165
+ * the panel had when it is free. No panel running: it just starts. A declined or failed stop starts nothing.
166
+ * @param {string[]} args
167
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown]
168
+ * @returns {Promise<number>}
169
+ */
170
+ export function restartCmd(args: string[], io: {
171
+ out: (s: string) => void;
172
+ err: (s: string) => void;
173
+ }, d: LauncherDeps & {
174
+ version?: string;
175
+ }, shown?: {
176
+ lines: string[];
177
+ panels: Panel[];
178
+ }): Promise<number>;
179
+ /**
180
+ * The bare `fwdloop` menu: header, the five choices, one question. Runs the chosen command and returns its exit code.
181
+ * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d
182
+ * @returns {Promise<number>}
183
+ */
184
+ export function menuCmd(io: {
185
+ out: (s: string) => void;
186
+ err: (s: string) => void;
187
+ }, d: LauncherDeps & {
188
+ version?: string;
189
+ }): Promise<number>;
190
+ /**
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;
192
+ * 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
194
+ * @param {{ stdin?: any, stdout?: any, stderr?: any, home?: string, root?: string, processEnv?: Record<string, string|undefined>, launcher?: LauncherDeps & {version?: string} }} deps
195
+ * @returns {Promise<number>}
196
+ */
197
+ export function launcherMain(cmd: "menu" | "start" | "stop" | "restart" | "status" | "install", rest: string[], deps: {
198
+ stdin?: any;
199
+ stdout?: any;
200
+ stderr?: any;
201
+ home?: string;
202
+ root?: string;
203
+ processEnv?: Record<string, string | undefined>;
204
+ launcher?: LauncherDeps & {
205
+ version?: string;
206
+ };
207
+ }): Promise<number>;
208
+ /** the first port tried, and how many in a row (4800..4809) */
209
+ export const PORT_START: 4800;
210
+ export const PORT_COUNT: 10;
211
+ /**
212
+ * one answered probe
213
+ */
214
+ export type Panel = {
215
+ port: number;
216
+ pid: number;
217
+ version: string;
218
+ drafts: number;
219
+ schedules: number;
220
+ /**
221
+ * ISO, absent on an older panel
222
+ */
223
+ startedAt?: string | undefined;
224
+ url: string;
225
+ };
226
+ /**
227
+ * every OS touch, injectable (a test passes all of them)
228
+ */
229
+ export type LauncherDeps = {
230
+ /**
231
+ * the fwdloop config home (`~/.config/fwdloop`, src/config.js `configHome`); undefined = the real one
232
+ */
233
+ home?: string | undefined;
234
+ /**
235
+ * the flows folder the runs line reads and `start` hands the panel (`--root`); default '.' like `fwdloop panel`
236
+ */
237
+ root?: string | undefined;
238
+ portStart?: number | undefined;
239
+ portCount?: number | undefined;
240
+ /**
241
+ * an explicit port list (tests); wins over portStart/portCount
242
+ */
243
+ ports?: number[] | undefined;
244
+ /**
245
+ * probe timeout per port
246
+ */
247
+ timeoutMs?: number | undefined;
248
+ /**
249
+ * start/stop wait deadline
250
+ */
251
+ deadlineMs?: number | undefined;
252
+ /**
253
+ * how long start keeps asking a taken, silent port (default 10 s)
254
+ */
255
+ silentWaitMs?: number | undefined;
256
+ /**
257
+ * default process.versions.node
258
+ */
259
+ nodeVersion?: string | undefined;
260
+ fetchImpl?: typeof fetch | undefined;
261
+ /**
262
+ * default src/panel/spawn.js `spawnDetached`
263
+ */
264
+ spawnFn?: ((a: {
265
+ bin: string;
266
+ argv: string[];
267
+ env: Record<string, string | undefined>;
268
+ logPath: string;
269
+ }) => any) | undefined;
270
+ /**
271
+ * default process.kill
272
+ */
273
+ kill?: ((pid: number, sig: string | number) => void) | undefined;
274
+ /**
275
+ * default the shared OS opener
276
+ */
277
+ open?: ((target: string) => Promise<boolean>) | undefined;
278
+ /**
279
+ * default: try to bind 127.0.0.1:port
280
+ */
281
+ portFree?: ((port: number) => Promise<boolean>) | undefined;
282
+ sleep?: ((ms: number) => Promise<void>) | undefined;
283
+ /**
284
+ * the y/N and menu reader
285
+ */
286
+ ask?: ((question: string) => Promise<string>) | undefined;
287
+ /**
288
+ * default bin/fwdloop of this package
289
+ */
290
+ fwdloopBin?: string | undefined;
291
+ /**
292
+ * colour for stdout lines (default none); {@link makePaint} decides TTY / NO_COLOR / TERM
293
+ */
294
+ paint?: import("./tty-colour.js").Paint | undefined;
295
+ /**
296
+ * colour for stderr lines (default: `paint`)
297
+ */
298
+ paintErr?: import("./tty-colour.js").Paint | undefined;
299
+ /**
300
+ * ms clock for the run list's 7-day rule (default: real time); tests pass their own
301
+ */
302
+ now?: number | undefined;
303
+ /**
304
+ * raw env handed to the panel child (default process.env)
305
+ */
306
+ env?: Record<string, string | undefined> | undefined;
307
+ };