fwdloop 0.26.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fwdloop",
3
- "version": "0.26.1",
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,7 +4,7 @@
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
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
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
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.
10
10
  //
@@ -346,7 +346,8 @@ export async function updateCmd(io, d, shown) {
346
346
  if (answer !== 'y' && answer !== 'yes') { io.out(UPDATE_LATER); return 0; }
347
347
  const code = await (d.spawnNpm ?? runNpm)(NPM_ARGS);
348
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.`);
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.`);
350
351
  return 0;
351
352
  }
352
353
 
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;
@@ -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;