fwdloop 0.26.0 → 0.26.2

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 CHANGED
@@ -67,7 +67,7 @@ standalone.
67
67
 
68
68
  ## Status
69
69
 
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. All jobs live in `~/.config/fwdloop/flows`, next to the settings; `--root <folder>` points a command somewhere else.
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.
71
71
 
72
72
  The in-run `impact` tool needs ripgrep (`rg`) on PATH; without it the tool is refused with a message, never a wrong answer.
73
73
 
package/bin/fwdloop CHANGED
@@ -1008,7 +1008,7 @@ function cmdLearn(rest) {
1008
1008
  // ---------------------------------------------------------------------------
1009
1009
 
1010
1010
  /**
1011
- * 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.
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
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.
1013
1013
  */
1014
1014
  async function cmdLauncher(cmd, rest) {
@@ -1033,8 +1033,8 @@ async function main() {
1033
1033
  if (verb === 'continue') return cmdContinue(rest);
1034
1034
  if (verb === 'panel') return cmdPanel(rest);
1035
1035
  if (verb === 'learn') return cmdLearn(rest);
1036
- if (verb === 'start' || verb === 'stop' || verb === 'restart' || verb === 'status' || verb === 'install') 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 (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)`);
1038
1038
  return undefined;
1039
1039
  }
1040
1040
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwdloop",
3
- "version": "0.26.0",
3
+ "version": "0.26.2",
4
4
  "description": "Describe a job as steps and guardrails; an agent builds the workflow, pauses for humans where you said, checks every step happened, and reruns it under budgets it cannot touch.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -49,8 +49,8 @@
49
49
  "NOTICE"
50
50
  ],
51
51
  "dependencies": {
52
- "bare-agent": "^0.52.0",
53
- "barebrowse": "^0.24.1",
52
+ "bare-agent": "^0.54.1",
53
+ "barebrowse": "^0.26.0",
54
54
  "bareguard": "^0.26.0",
55
55
  "litectx": "^0.32.0"
56
56
  },
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/am9 (built from the signed text; am9: the typed `fwdloop update` ends "Then run fwdloop restart.", the menu keeps "pick 3 restart"): `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,6 +20,7 @@ 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';
@@ -25,6 +29,7 @@ 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
@@ -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
@@ -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,65 @@ export async function installCmd(io, d, shown) {
279
292
  return 1;
280
293
  }
281
294
  }
282
- if (made.length === 0) { io.out('Already installed, nothing to do.'); return 0; }
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
+ // am9: the menu says pick 3; the typed sub-command has no menu (`shown` is the menu's header, as statusCmd uses it)
350
+ io.out(shown ? `Updated to ${latest}. Then pick 3 restart.` : `Updated to ${latest}. Then run fwdloop restart.`);
351
+ return 0;
352
+ }
353
+
288
354
  /**
289
355
  * `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
356
  * @param {{out: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d @param {{lines: string[], panels: Panel[]}} [shown] header the menu already printed
@@ -497,7 +563,7 @@ export async function restartCmd(args, io, d, shown) {
497
563
  }
498
564
 
499
565
  /**
500
- * The bare `fwdloop` menu: header, the five choices, one question. Runs the chosen command and returns its exit code.
566
+ * The bare `fwdloop` menu: header, the six choices, one question. Runs the chosen command and returns its exit code.
501
567
  * @param {{out: (s: string) => void, err: (s: string) => void}} io @param {LauncherDeps & {version?: string}} d
502
568
  * @returns {Promise<number>}
503
569
  */
@@ -508,7 +574,7 @@ export async function menuCmd(io, d) {
508
574
  const P = d.paint ?? PLAIN;
509
575
  if (!P.on) io.out('');
510
576
  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`;
577
+ const items = `${n('1')} start ${n('2')} stop ${n('3')} restart ${n('4')} status ${n('5')} install ${n('6')} update ${n('q')} quit`;
512
578
  io.out(P.on ? ` ${items}` : items);
513
579
  const choice = ask ? (await ask(`${P.cyan('>')} `)).trim().toLowerCase() : 'q';
514
580
  // the header is already on screen: the chosen command reuses it instead of printing it a second time
@@ -517,15 +583,16 @@ export async function menuCmd(io, d) {
517
583
  if (choice === '3' || choice === 'restart') return restartCmd([], io, d, h);
518
584
  if (choice === '4' || choice === 'status') return statusCmd(io, d, h);
519
585
  if (choice === '5' || choice === 'install') return installCmd(io, d, h);
586
+ if (choice === '6' || choice === 'update') return updateCmd(io, d, h);
520
587
  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`);
588
+ fail(io, d, `unknown choice ${JSON.stringify(choice)} — one of: 1, 2, 3, 4, 5, 6, q`);
522
589
  return 1;
523
590
  }
524
591
 
525
592
  /**
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;
593
+ * 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
594
  * 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
595
+ * @param {'menu'|'start'|'stop'|'restart'|'status'|'install'|'update'} cmd @param {string[]} rest
529
596
  * @param {{ stdin?: any, stdout?: any, stderr?: any, home?: string, root?: string, processEnv?: Record<string, string|undefined>, launcher?: LauncherDeps & {version?: string} }} deps
530
597
  * @returns {Promise<number>}
531
598
  */
@@ -537,7 +604,7 @@ export async function launcherMain(cmd, rest, deps) {
537
604
  const { ask, close } = openAsker({ stdin: deps.stdin, stdout });
538
605
  const rawEnv = deps.processEnv ?? process.env;
539
606
  const d = {
540
- home: deps.home, root: deps.root, ask, paint: makePaint(stdout, rawEnv), paintErr: makePaint(stderr, rawEnv), ...(deps.launcher ?? {}),
607
+ 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
608
  };
542
609
  try {
543
610
  if (cmd === 'start') return await startCmd(io, d);
@@ -545,6 +612,7 @@ export async function launcherMain(cmd, rest, deps) {
545
612
  if (cmd === 'restart') return await restartCmd(rest, io, d);
546
613
  if (cmd === 'status') return await statusCmd(io, d);
547
614
  if (cmd === 'install') return await installCmd(io, d);
615
+ if (cmd === 'update') return await updateCmd(io, d);
548
616
  return await menuCmd(io, d);
549
617
  } finally {
550
618
  close();
package/src/pageask.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // borrowed-from: bareloop src/pagemap.js@0a34846 (DROP_IT, isDropIt, isAgree, readingQuestion, readingOfQuestion, askableFromLook, ruleBounds, tooManyAsksText)
2
2
  // borrowed-from: bareloop src/facts.js@0a34846 (ruleWords, sayBound, moneyAs)
3
+ // borrowed-from: bareloop src/pagemap.js@v0.49.0 (d51a367) (stripAgreeLead, F240; adapted: literal regex, src/ bans new RegExp)
3
4
  // M10 piece 3 (docs/wiki/the-module-ladder.md "M10", item 4, am1, am2, am5): the early asks CODE forces before any paid drafting, from the page look's own
4
5
  // result. The model never decides whether to ask: this file reads a kept fact's own keys (line, forRule, name, shape, unit, currency, reading) and the job
5
6
  // lines, and nothing else (test/m10-pageask.test.js greps for it). The question words are bareloop's, verbatim (am5 item 1); the answer words are
@@ -25,6 +26,20 @@ const AGREE_WORDS = ['agree', 'yes'];
25
26
  /** @param {unknown} text @returns {boolean} */
26
27
  export const isAgree = (text) => AGREE_WORDS.includes(String(text ?? '').trim().replace(/[.!]$/, '').toLowerCase());
27
28
 
29
+ /**
30
+ * F240: an answer that opens with an agree word IMMEDIATELY followed by a comma or a colon (spaces allowed only after it) and more text
31
+ * ("yes, check it as ...", "agree: the outbound flight") is the person's own reading with a courtesy word in front: the word and the
32
+ * comma/colon go, the rest stays word for word. No hyphen or dash of any kind and no bare space counts, so "yes-no questions only",
33
+ * "agree-ment on price", "yes - departs", "yes departs" and "yesterday, ..." are kept whole. A bare "yes"/"agree" (isAgree), a bare "yes,"
34
+ * and a text that only contains the word later are returned untouched.
35
+ * @param {string} text @returns {string}
36
+ */
37
+ export const stripAgreeLead = (text) => {
38
+ // a literal that spells out AGREE_WORDS (src/ bans dynamic RegExp, the ReDoS guard); the two must stay in step
39
+ const m = String(text ?? '').match(/^(?:agree|yes)[,:]\s*(\S[\s\S]*)$/i);
40
+ return m ? m[1].trim() : String(text ?? '');
41
+ };
42
+
28
43
  /** @typedef {{line: number, rule: number, source: 'look', question: string, ask: 'reading'|'cant-check', ruleText: string, reading?: string}} LookAsk
29
44
  * `reading` = the plain words an `agree` writes as a `~` rule (a reading ask only) */
30
45
 
@@ -128,8 +143,9 @@ export function tooManyAsksText(asks) {
128
143
  * @returns {{rule: string|null, left: boolean}} `rule` = the words written as a new `~` rule (null when the rule is left Not checked)
129
144
  */
130
145
  export function ruleOfAnswer(q, typed) {
131
- const text = String(typed ?? '').replace(/\s*\n\s*/g, ' ').trim();
132
- if (q.source !== 'look') return { rule: text, left: false };
146
+ const typedText = String(typed ?? '').replace(/\s*\n\s*/g, ' ').trim();
147
+ if (q.source !== 'look') return { rule: typedText, left: false };
148
+ const text = stripAgreeLead(typedText); // F240: "yes, check it as ..." is the person's own words minus the leading "yes,"
133
149
  if (q.ask === 'reading' && typeof q.proposal === 'string' && isAgree(text)) return { rule: q.proposal, left: false };
134
150
  if (q.ask === 'cant-check' && isDropIt(text)) return { rule: null, left: true };
135
151
  return { rule: text, left: false };
package/src/pagefetch.js CHANGED
@@ -86,12 +86,12 @@ export function pageContentChars(text) {
86
86
  }
87
87
 
88
88
  /**
89
- * @typedef {{goto: (url: string, timeout?: number) => Promise<void>, waitForNetworkIdle: (o?: {idle?: number, timeout?: number}) => Promise<void>,
89
+ * @typedef {{goto: (url: string, timeout?: number) => Promise<{url: string, status: number}>, waitForNetworkIdle: (o?: {idle?: number, timeout?: number}) => Promise<void>,
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 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];
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; 0.26.0 makes goto() resolve to {url, status}, the HTTP status an error page is refused on (M10 am13) */
94
+ export const MIN_BAREBROWSE = [0, 26, 0];
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.24.1 or newer, which keeps the browser private, off the local network, and closed when the run ends` };
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.26.0 or newer, which keeps the browser private, off the local network, closed when the run ends, and says whether the page loaded` };
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
  }
@@ -143,13 +143,18 @@ export async function fetchPageText(url, { connect, timeoutMs = PAGE_FETCH_TIMEO
143
143
  const text = await Promise.race([
144
144
  (async () => {
145
145
  const p = await page;
146
- await p.goto(u.href, GOTO_TIMEOUT_MS);
146
+ const nav = await p.goto(u.href, GOTO_TIMEOUT_MS);
147
+ // M10 am13: the status is goto's typed result, never read from the page text; decided before any reading
148
+ const st = nav && typeof nav === 'object' ? /** @type {any} */ (nav).status : undefined;
149
+ if (typeof st !== 'number' || !Number.isFinite(st) || st <= 0) return { refused: `${u.href} did not say whether it loaded (no HTTP status), so it is not read` };
150
+ if (st < 200 || st > 299) return { refused: `${u.href} came back as an error page (HTTP ${st}), so there is nothing to read` };
147
151
  // bounded: a page that never goes quiet (polling, streaming) is read as it stands (bareloop); the size and chrome floors below then decide
148
152
  try { await p.waitForNetworkIdle({ idle: idleMs, timeout: idleTimeoutMs }); } catch { /* read what is there */ }
149
153
  return p.snapshot({ ...SNAPSHOT_OPTIONS });
150
154
  })(),
151
155
  new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(`no answer inside ${Math.round(timeoutMs / 1000)} seconds`)), timeoutMs); }),
152
156
  ]);
157
+ if (text && typeof text === 'object' && 'refused' in text) return { ok: false, error: String(text.refused) };
153
158
  if (typeof text !== 'string') return { ok: false, error: `${u.href} did not come back as text` };
154
159
  if (/\[BOT CHALLENGE DETECTED\]/.test(text)) return { ok: false, error: `${u.href} asked for a human check (a bot challenge), so the page could not be read` };
155
160
  const size = text.trim().length;
@@ -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';
@@ -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 five choices, one question. Runs the chosen command and returns its exit code.
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;
@@ -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';
@@ -61,6 +61,7 @@ export const MAX_LOOK_ASKS: 3;
61
61
  export const DROP_IT: "drop it";
62
62
  export function isDropIt(text: unknown): boolean;
63
63
  export function isAgree(text: unknown): boolean;
64
+ export function stripAgreeLead(text: string): string;
64
65
  /**
65
66
  * `reading` = the plain words an `agree` writes as a `~` rule (a reading ask only)
66
67
  */
@@ -65,16 +65,19 @@ export const MIN_CONTENT_CHARS: 100;
65
65
  /** our own deadline around one whole fetch (a hung browser leaves no trace; this is the only thing that fires on the absence of an answer) */
66
66
  export const PAGE_FETCH_TIMEOUT_MS: 90000;
67
67
  /**
68
- * @typedef {{goto: (url: string, timeout?: number) => Promise<void>, waitForNetworkIdle: (o?: {idle?: number, timeout?: number}) => Promise<void>,
68
+ * @typedef {{goto: (url: string, timeout?: number) => Promise<{url: string, status: number}>, 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 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 */
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; 0.26.0 makes goto() resolve to {url, status}, the HTTP status an error page is refused on (M10 am13) */
72
72
  export const MIN_BAREBROWSE: number[];
73
73
  /**
74
74
  * the part of barebrowse's page handle the fetch uses
75
75
  */
76
76
  export type FetchPage = {
77
- goto: (url: string, timeout?: number) => Promise<void>;
77
+ goto: (url: string, timeout?: number) => Promise<{
78
+ url: string;
79
+ status: number;
80
+ }>;
78
81
  waitForNetworkIdle: (o?: {
79
82
  idle?: number;
80
83
  timeout?: number;
@@ -0,0 +1 @@
1
+ export const REGISTRY_URL: "https://registry.npmjs.org/fwdloop/latest";