bareloop 0.49.0 → 0.51.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/src/rubricstep.js CHANGED
@@ -3,7 +3,7 @@ import { readFile, lstat } from 'node:fs/promises';
3
3
  import { join, dirname } from 'node:path';
4
4
  import { createRubric, checkStep, renderGaps, numbersInQuote } from 'bareguard';
5
5
  import { dropRows, dropLine } from './pagedropwords.js';
6
- import { factPartOf, factShapeReds, factDecides, factClaims, factRows, plainFactItem, factBrief } from './facts.js';
6
+ import { factPartOf, factShapeReds, factDecides, factClaims, factRows, plainFactItem, factBrief, writtenSpans } from './facts.js';
7
7
 
8
8
  // PART 1a (docs/product/ITEM33-BUILD.md, "Addendum 2026-10-12"): the rubric job on LOCAL FILES — what one job line leaves
9
9
  // behind and how it is told to the worker.
@@ -340,9 +340,10 @@ export function parseStepFile(bytes) {
340
340
  * @param {Record<string, any>} obj
341
341
  * @param {string[]} [countLabels] labels whose claim COUNT a minClaims/maxClaims part reads
342
342
  * @param {any} [factPart] the step's `fact` part: its `results` become claims (text built by code) under `cites:<source>`
343
+ * @param {(Record<number, string>|undefined)[]} [asWritten] per result, the value spans a page-form fact's claim text is written with (see factClaims)
343
344
  * @returns {Record<string, any>}
344
345
  */
345
- export function flattenStep(obj, countLabels = [], factPart = null) {
346
+ export function flattenStep(obj, countLabels = [], factPart = null, asWritten = []) {
346
347
  /** @type {Record<string, any>} */
347
348
  const fields = {};
348
349
  // the number of claims listed under each label a claim-count check names (0 when the label is absent): counted HERE, by
@@ -352,7 +353,7 @@ export function flattenStep(obj, countLabels = [], factPart = null) {
352
353
  fields[`claims:${label}`] = Array.isArray(list) ? list.length : 0;
353
354
  }
354
355
  if (factPart) {
355
- const claims = factClaims(factPart, obj.results);
356
+ const claims = factClaims(factPart, obj.results, asWritten);
356
357
  fields[`claims:${factPart.source}`] = claims.length;
357
358
  fields[`cites:${factPart.source}`] = claims;
358
359
  }
@@ -430,9 +431,18 @@ export async function gradeStep({ params, bytes, outputBytes, inputs, factQuotes
430
431
  }
431
432
  const parsed = parseStepFile(bytes);
432
433
  const countLabels = [...new Set(params.parts.filter((/** @type {any} */ x) => x.class === 'countable' && (x.check === 'minClaims' || x.check === 'maxClaims')).map((/** @type {any} */ x) => String(x.source)))];
433
- const r = await checkStep(rubric, String(params.step), parsed.obj === null ? null : flattenStep(parsed.obj, countLabels, factPartOf(params)), {
434
+ const factPart = factPartOf(params);
435
+ const check = (/** @type {(Record<number, string>|undefined)[]} */ asWritten = []) => checkStep(rubric, String(params.step), parsed.obj === null ? null : flattenStep(parsed.obj, countLabels, factPart, asWritten), {
434
436
  inputs, ...(outputBytes === null ? {} : { outputBytes }),
435
437
  });
438
+ let r = await check();
439
+ // a fact that signs a page form (`lang` / `decimal`) has a canonical value but its claim text must spell it as the quote does: bareguard's own
440
+ // evidence of where it read the value in each quote gives the spelling, and the same file is checked once more with the text written so. Both
441
+ // passes are the one bareguard reader; the verdict, gap and counts below come from the last.
442
+ if (factPart && Array.isArray(factPart.facts) && factPart.facts.some((/** @type {any} */ f) => isRec(f) && (f.lang !== undefined || f.decimal !== undefined))) {
443
+ const written = writtenSpans(factPart, r.full.evidence);
444
+ if (written.some(Boolean)) r = await check(written);
445
+ }
436
446
  // PART 1b: a prose step's numbers are tied to the checked facts of earlier lines (bareguard's `numbersInQuote`: token match on the
437
447
  // numbers, not a canonical compare — a documented limit). Words are free; a number that no checked quote holds is a red.
438
448
  /** @type {string[]} */
@@ -502,6 +512,26 @@ function wordRange(part) {
502
512
  return null;
503
513
  }
504
514
 
515
+ /**
516
+ * bareguard refuses a money unit list whose entries are equal once `**`, `__` and extra spaces are removed, naming the path
517
+ * `...checks[K].decides[N].unit`. K indexes buildStepSpec's checks (id `p<part>-facts`), N the fact within that part.
518
+ * @param {{step: number, parts: any[]}} p @param {unknown} path @returns {{name: string, a: string, b: string}|null} the fact and the two twin units, or null when the path is not that
519
+ */
520
+ function dupUnitWords(p, path) {
521
+ const m = typeof path === 'string' ? /\.checks\[(\d+)\]\.decides\[(\d+)\]\.unit$/.exec(path) : null;
522
+ if (!m) return null;
523
+ const id = buildStepSpec(p, {}).checkpoints[String(p.step)].checks[Number(m[1])]?.id;
524
+ const pm = typeof id === 'string' ? /^p(\d+)-facts$/.exec(id) : null;
525
+ const fact = pm ? p.parts[Number(pm[1]) - 1]?.facts?.[Number(m[2])] : null;
526
+ if (!fact || !Array.isArray(fact.unit)) return null;
527
+ const key = (/** @type {string} */ u) => u.split('**').join('').split('__').join('').replace(/\s+/g, ' ').trim();
528
+ for (let i = 0; i < fact.unit.length; i += 1) {
529
+ const j = fact.unit.findIndex((/** @type {string} */ u, /** @type {number} */ k) => k > i && key(u) === key(fact.unit[i]));
530
+ if (j > i) return { name: String(fact.name), a: fact.unit[i], b: fact.unit[j] };
531
+ }
532
+ return null;
533
+ }
534
+
505
535
  /**
506
536
  * R11 — the drafting-time rules for the `rubric-step` stages of a declaration, each a red in the person's plain words that
507
537
  * names the job line and ends "Nothing spent." where nothing was. Pure; never throws. Judged parts are RED in this build
@@ -591,7 +621,8 @@ export function checkRubricParts(stages, { inputLabels = null, red }) {
591
621
  // bareguard is the judge of whether a fact list is SIGNABLE (anchors, units, bounds): ask it at drafting, at $0, so a list
592
622
  // it would refuse at run time is a red the drafter can fix now
593
623
  try { createRubric(buildStepSpec(/** @type {{step: number, parts: any[]}} */ (p), Object.fromEntries(citedLabels(p).map((l) => [l, '0'.repeat(64)])))); } catch (e) {
594
- red('rubric-fact-invalid', `${at}.params.parts`, `line ${line}: the facts cannot be signed: ${/** @type {Error} */ (e).message}`, { line: step, stage: label });
624
+ const twins = dupUnitWords(/** @type {{step: number, parts: any[]}} */ (p), /** @type {{path?: unknown}} */ (e).path);
625
+ red('rubric-fact-invalid', `${at}.params.parts`, twins ? `line ${line}: the fact '${twins.name}' lists the same unit twice ('${twins.a}' and '${twins.b}' are the same once marks and spaces are removed). Keep one. Nothing spent.` : `line ${line}: the facts cannot be signed: ${/** @type {Error} */ (e).message}`, { line: step, stage: label });
595
626
  }
596
627
  }
597
628
  for (let a = 0; a < ranges.length; a += 1) {
package/src/source.js CHANGED
@@ -1250,8 +1250,8 @@ export function isRubricFilesManifest(manifest) {
1250
1250
  * so run start can fetch it again); a `search:` line is a named refusal (a later build); so is a relative path, a missing file, a folder, a file over
1251
1251
  * {@link RUBRIC_INPUT_MAX_BYTES}, and text that is not valid UTF-8. Every refusal is plain words naming the line and
1252
1252
  * ends "Nothing spent." — nothing here touches a model.
1253
- * @param {{inputs: {n: number, label: string, value: string}[], into: string, destination?: string, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>}} o `fetchUrl` - how a web address is read (default barebrowse via `fetchPageText`; a test injects a stub, never the network)
1254
- * @returns {Promise<{ok: true, prep: {stop: null, into: string, tree: string, manifestPath: string, manifest: Record<string, any>}}|{ok: false, error: string, code: string}>}
1253
+ * @param {{inputs: {n: number, label: string, value: string}[], into: string, destination?: string, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string, attempts?: {chars: number, ms: number, head: string}[]}>}} o `fetchUrl` - how a web address is read (default barebrowse via `fetchPageText`; a test injects a stub, never the network)
1254
+ * @returns {Promise<{ok: true, prep: {stop: null, into: string, tree: string, manifestPath: string, manifest: Record<string, any>}}|{ok: false, error: string, code: string, attempts?: {chars: number, ms: number, head: string}[]}>}
1255
1255
  */
1256
1256
  export async function proveRubricInputs({ inputs, into, destination, fetchUrl = (u) => fetchPageText(u) }) {
1257
1257
  /** @param {string} code @param {number} n @param {string} msg @returns {{ok: false, error: string, code: string}} */
@@ -1273,7 +1273,7 @@ export async function proveRubricInputs({ inputs, into, destination, fetchUrl =
1273
1273
  labels.add(label.toLowerCase());
1274
1274
  if (isWebUrl(value)) {
1275
1275
  const got = await fetchUrl(value.trim());
1276
- if (!got.ok) return bad('input-url-unreadable', n, `${got.error.replace(/(?<![.\s])[.\s]+$/, '')}.`);
1276
+ if (!got.ok) return { ...bad('input-url-unreadable', n, `${got.error.replace(/(?<![.\s])[.\s]+$/, '')}.`), ...(got.attempts?.length ? { attempts: got.attempts } : {}) };
1277
1277
  const pageBuf = Buffer.from(got.text, 'utf8');
1278
1278
  const leak = secretPatternNames(got.text);
1279
1279
  if (leak.length) return bad('input-url-secret', n, `the page at ${got.url} carries a known secret shape (${leak.join(', ')}) - refused, secrets never enter a job.`);
package/src/stagewords.js CHANGED
@@ -38,8 +38,13 @@ export function cmdKey(params) {
38
38
  * - `pattern-absent-in-diff` is always the `no-suppressions` guard: "no
39
39
  * casts or silencers added?"
40
40
  * - `rubric-step` (Part 1a) is one job line's output file: "line N — does its output pass the line's checks?"
41
- * - `command-exit` is the genre's `suite-green` stage (the only shipped use
42
- * of this kind): "does the test suite pass?"
41
+ * - `command-exit` quotes its OWN signed command verbatim:
42
+ * `does "<cmd> <args joined by space>" exit clean?` (e.g. `does "npm test"
43
+ * exit clean?`, `does "npx tsc --noEmit --strict" exit clean?`). It used
44
+ * to read "does the test suite pass?" for every command, so F256's run
45
+ * mvtatlxw showed two different commands (the real suite and a whole-repo
46
+ * `tsc --strict`) reading the same question. A missing or non-string
47
+ * `cmd` returns `null` (the caller falls back to the stage name).
43
48
  * - `count-not-worse` splits three ways on its own declared
44
49
  * `direction`/`baseline` (never the runtime number — see
45
50
  * {@link stageKindMetaFromSpec}'s own doc for why the baseline KIND must
@@ -87,7 +92,11 @@ export function stageQuestionText({
87
92
  }) {
88
93
  if (kind === 'files-changed') return 'did it change any file?';
89
94
  if (kind === 'pattern-absent-in-diff') return 'no casts or silencers added?';
90
- if (kind === 'command-exit') return 'does the test suite pass?';
95
+ if (kind === 'command-exit') {
96
+ if (!params || typeof params.cmd !== 'string' || params.cmd.length === 0) return null;
97
+ const args = Array.isArray(params.args) ? params.args.filter((a) => typeof a === 'string') : [];
98
+ return `does "${[params.cmd, ...args].join(' ')}" exit clean?`;
99
+ }
91
100
  // Part 1a: one rubric-step stage = one job line's output file
92
101
  if (kind === 'rubric-step') return params && Number.isInteger(params.step) ? `line ${params.step} — does its output pass the line's checks?` : null;
93
102
  if (kind !== 'count-not-worse' || !params || typeof params !== 'object') return null;
@@ -1764,6 +1764,14 @@ export const PARAM_SCHEMAS: Readonly<{
1764
1764
  type: string;
1765
1765
  description: string;
1766
1766
  };
1767
+ lang: {
1768
+ enum: string[];
1769
+ description: string;
1770
+ };
1771
+ decimal: {
1772
+ enum: string[];
1773
+ description: string;
1774
+ };
1767
1775
  };
1768
1776
  required: string[];
1769
1777
  additionalProperties: boolean;
package/types/facts.d.ts CHANGED
@@ -16,13 +16,26 @@ export function factDecides(part: any): Record<string, any>[];
16
16
  * from the values the worker gave (the worker writes no claim text): `name: value; name: value`. A phrase fact contributes its
17
17
  * own signed words. A result that is not an object, or has no string quote, still becomes a claim — an empty one — so
18
18
  * bareguard reds it by name rather than the result vanishing.
19
- * @param {any} part @param {unknown} results @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
19
+ *
20
+ * A fact that signs a page form (`lang` or `decimal`) carries a CANONICAL value ("2026-10-26", "1057.65": bareguard's typed binding, `values.d<j>`),
21
+ * but bareguard's number scan compares the claim TEXT with the quote's own digits, so the text must spell the value the way the quote does
22
+ * ("26 October 2026", "1.057,65"). That spelling is `asWritten[result][fact index]`: the value span bareguard itself reported for that quote
23
+ * ({@link writtenSpans}); a fact with no span there reads the value the worker gave.
24
+ * @param {any} part @param {unknown} results @param {(Record<number, string>|undefined)[]} [asWritten]
25
+ * @returns {{claim: string, quote: string, values?: Record<string, string>}[]}
20
26
  */
21
- export function factClaims(part: any, results: unknown): {
27
+ export function factClaims(part: any, results: unknown, asWritten?: (Record<number, string> | undefined)[]): {
22
28
  claim: string;
23
29
  quote: string;
24
30
  values?: Record<string, string>;
25
31
  }[];
32
+ /**
33
+ * Where bareguard read each page-form fact's value inside each quote, as the quote spells it: from `checkStep`'s `full.evidence` (one entry per
34
+ * claim: `text` = the normalized quote the decides ran on, `spans` = where each decide read its anchor, value and unit/currency). Only a fact that
35
+ * signs `lang` or `decimal` is looked up; the span is the decide's `value` span (the one equal to the claim's own value when bareguard flags it).
36
+ * @param {any} part @param {any[]|undefined} evidence @returns {(Record<number, string>|undefined)[]} per claim index
37
+ */
38
+ export function writtenSpans(part: any, evidence: any[] | undefined): (Record<number, string> | undefined)[];
26
39
  /**
27
40
  * One amount of a money fact in the fact's OWN signed forms, never a hardcoded sign: `symbolFirst` puts the currency sign before the amount
28
41
  * ("$144") when the fact has one, else the unit after it ("144 US dollars"); not `symbolFirst` (a rule's bound) prefers the unit.
@@ -75,6 +88,18 @@ export const FACT_SHAPES: readonly string[];
75
88
  export const FACT_OPS: readonly string[];
76
89
  /** bareguard signs at most this many decides on one `cited` check */
77
90
  export const MAX_FACTS: 10;
91
+ /** the languages whose month names bareguard 0.27 reads on a `date` fact (its `lang`), each with the name a person reads; absent `lang` = ISO YYYY-MM-DD only */
92
+ export const FACT_LANGS: Readonly<{
93
+ en: "English";
94
+ de: "German";
95
+ fr: "French";
96
+ es: "Spanish";
97
+ it: "Italian";
98
+ pt: "Portuguese";
99
+ nl: "Dutch";
100
+ }>;
101
+ /** the decimal marks a number or money fact may sign (bareguard 0.27 `decimal`); absent = "." */
102
+ export const FACT_DECIMALS: readonly string[];
78
103
  /** every field a part of class `fact` may carry (the shared ones are checked by rubricStepShapeReds) */
79
104
  export const FACT_PART_FIELDS: readonly string[];
80
105
  /** the limits bareguard 0.24 puts on a money fact's lists (ruling #65), enforced here first so the red is ours and plain */
@@ -13,7 +13,7 @@ export function countPhrase(source: string, words: string): number;
13
13
  * What the page-word map (src/pagemap.js) KEPT and DROPPED for one input: the sets the second proof reads. A look from the old search-and-read
14
14
  * path has no `dropped` list, so it gives null and the label is proved against the code-made list as before.
15
15
  * @param {{facts?: any[], dropped?: (import('./pagerules.js').Dropped & {source?: string})[]}|null|undefined} look @param {string} source
16
- * @returns {{labels: Set<string>, units: Set<string>, currencies: Set<string>, words: Set<string>, dropped: Map<string, import('./pagerules.js').Dropped>}|null}
16
+ * @returns {{labels: Set<string>, units: Set<string>, currencies: Set<string>, words: Set<string>, dropped: Map<string, import('./pagerules.js').Dropped>, forms: {labels: Set<string>, lang?: string, decimal?: string}[]}|null}
17
17
  */
18
18
  export function keptSetOf(look: {
19
19
  facts?: any[];
@@ -26,6 +26,11 @@ export function keptSetOf(look: {
26
26
  currencies: Set<string>;
27
27
  words: Set<string>;
28
28
  dropped: Map<string, import("./pagerules.js").Dropped>;
29
+ forms: {
30
+ labels: Set<string>;
31
+ lang?: string;
32
+ decimal?: string;
33
+ }[];
29
34
  } | null;
30
35
  /**
31
36
  * The reds for ONE fact part against its frozen source text.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Is this repo-relative path off limits to a note: outside the job root, an arbiter book (the one list,
3
+ * `isArbiterBook`: .smoke — spine, attempt-diff, bridges — .litectx, the gate audit), or inside `.git` / `.bareloop`.
4
+ * @param {string} rel
5
+ */
6
+ export function isHandoffExcluded(rel: string): boolean;
7
+ /**
8
+ * Wrap the worker's read-class tools (the real names come from the caller: shell_read, ctx_get) so a call that
9
+ * reached `execute` (the gate already allowed it) and returned a file's text is reported to `onRead`.
10
+ * Wraps in place: tool objects are fresh per worker.
11
+ * @param {{name: string, execute: Function}[]} tools
12
+ * @param {string[]} names
13
+ * @param {(absPath: string) => void} onRead
14
+ * @param {string} workdir
15
+ */
16
+ export function trackReads(tools: {
17
+ name: string;
18
+ execute: Function;
19
+ }[], names: string[], onRead: (absPath: string) => void, workdir: string): void;
20
+ /**
21
+ * Run-level store of the paths earlier workers read. Newest read last; a re-read moves a path to newest.
22
+ * In memory only: a resumed leg starts empty (the first ask of a resumed leg gets no note, later asks do).
23
+ * @param {{workdir: string}} o
24
+ */
25
+ export function createHandoffStore({ workdir }: {
26
+ workdir: string;
27
+ }): {
28
+ absorb: (absPaths: Iterable<string>) => void;
29
+ render: ({ getNode }?: {
30
+ getNode?: (rel: string) => any;
31
+ }) => {
32
+ text: string;
33
+ paths: number;
34
+ };
35
+ size: () => number;
36
+ };
37
+ /** The one cap on a note, in characters. */
38
+ export const HANDOFF_CAP: 8000;
39
+ export const HANDOFF_HEADING: "== Files earlier workers in this run read (a map only; contents are not included; line ranges as ctx_recall prints them) ==";
@@ -211,6 +211,8 @@ export type LookFact = {
211
211
  labels?: string[];
212
212
  unit?: string[];
213
213
  currency?: string[];
214
+ lang?: string;
215
+ decimal?: string;
214
216
  };
215
217
  export type LookNotFound = {
216
218
  line: number;
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * The result lines of a kept money fact: with a label, every page line where a kept label is followed by a number (one sign between allowed);
3
- * with no label (U1 moved it to a unit, e.g. "€533 total"), every line where a number is followed by a kept unit.
3
+ * with no label (U1 moved it to a unit, e.g. "€533 total", or a sign alone, e.g. "48,49€"), every line where a number sits right before a kept
4
+ * unit or sign, or right after a kept sign. A fact that signs `decimal: ","` is read in that form: groups of three joined by "." or a space, a comma
5
+ * before the decimals. The value is always the CANONICAL amount ("1057.65"): the typed value a claim carries, never the page's spelling.
6
+ * A LOOSE finder (it only collects): whether the run's checker can read the line is `gradeStep`'s to say.
4
7
  * @param {string} text @param {KeptFact} k @returns {{quote: string, value: string}[]}
5
8
  */
6
9
  export function moneyResultLines(text: string, k: KeptFact): {
@@ -12,18 +12,25 @@ export function pageContentChars(text: string): number;
12
12
  * @typedef {{goto: (url: string, timeout?: number) => Promise<void>, waitForNetworkIdle: (o?: {idle?: number, timeout?: number}) => Promise<void>,
13
13
  * snapshot: (o?: {mode?: string}) => Promise<string>, close: () => Promise<void>}} FetchPage the part of barebrowse's page handle the fetch uses
14
14
  */
15
+ /** @typedef {{chars: number, ms: number, head: string}} AttemptRecord what a header-only attempt saw: content characters, elapsed ms, the first characters of the content (secret-masked) */
15
16
  /**
16
17
  * Fetch one page's text. `connect` is injected (a test never reaches the network); the default is barebrowse's own `connect`.
18
+ * The whole fetch (own browser, own page, closed each time) is tried up to FETCH_ATTEMPTS times, but ONLY when an attempt ends header-only (the page
19
+ * loaded its menus and not its content) or times out (our deadline, or the page load's own timeout). A bot challenge, a refused or private address, any
20
+ * other load error, a near-empty page and a non-text answer are final on the first attempt.
17
21
  * @param {string} url
18
- * @param {{connect?: (opts: Record<string, any>) => Promise<FetchPage>, timeoutMs?: number, idleMs?: number, idleTimeoutMs?: number, closeWaitMs?: number}} [o]
19
- * @returns {Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>} `error` is plain words, without a spend line
22
+ * @param {{connect?: (opts: Record<string, any>) => Promise<FetchPage>, timeoutMs?: number, idleMs?: number, idleTimeoutMs?: number, closeWaitMs?: number, retryWaitMs?: number, settleMs?: number, settleIntervalMs?: number}} [o] `retryWaitMs` - the pause between attempts (a test passes 0); `settleMs`/`settleIntervalMs` - the in-attempt re-read budget and pace for a header-only page
23
+ * @returns {Promise<{ok: true, text: string, url: string}|{ok: false, error: string, attempts?: AttemptRecord[]}>} `error` is plain words, without a spend line
20
24
  */
21
- export function fetchPageText(url: string, { connect, timeoutMs, idleMs, idleTimeoutMs, closeWaitMs }?: {
25
+ export function fetchPageText(url: string, { connect, timeoutMs, idleMs, idleTimeoutMs, closeWaitMs, retryWaitMs, settleMs, settleIntervalMs }?: {
22
26
  connect?: (opts: Record<string, any>) => Promise<FetchPage>;
23
27
  timeoutMs?: number;
24
28
  idleMs?: number;
25
29
  idleTimeoutMs?: number;
26
30
  closeWaitMs?: number;
31
+ retryWaitMs?: number;
32
+ settleMs?: number;
33
+ settleIntervalMs?: number;
27
34
  }): Promise<{
28
35
  ok: true;
29
36
  text: string;
@@ -31,6 +38,7 @@ export function fetchPageText(url: string, { connect, timeoutMs, idleMs, idleTim
31
38
  } | {
32
39
  ok: false;
33
40
  error: string;
41
+ attempts?: AttemptRecord[];
34
42
  }>;
35
43
  /** the session options (incognito: no auth ever enters; blockPrivateNetwork: SSRF guard); ONE frozen object so a test can pin them */
36
44
  export const CONNECT_OPTIONS: Readonly<{
@@ -53,7 +61,18 @@ export const MIN_PAGE_CHARS: 200;
53
61
  /** the page text left after the site's own header, menus and footer are taken out must hold at least this many characters, or the page is
54
62
  * "only site chrome" (L2: a 719-character fetch of Google's header and sign-in passed the 200-character floor) */
55
63
  export const MIN_CONTENT_CHARS: 100;
56
- /** 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) */
64
+ /** how many times one fetch is tried when it comes back header-only or times out (a real Dell page was header-only on one try and whole on the next) */
65
+ export const FETCH_ATTEMPTS: 3;
66
+ /** the pause between attempts (ms) */
67
+ export const RETRY_WAIT_MS: 3000;
68
+ /** a header-only snapshot is re-taken (same open page) every this many ms until content shows up (live: Dell de-de gave header-only 3 times in ~5 s
69
+ * each, while its content arrived ~18-35 s after load; a fast refetch hits the same unsettled page) */
70
+ export const SETTLE_INTERVAL_MS: 2000;
71
+ /** the most one attempt keeps re-reading a header-only page (ms) before it counts as header-only; the per-attempt deadline below still bounds the whole attempt */
72
+ export const SETTLE_BUDGET_MS: 20000;
73
+ /** how many characters of a header-only page's content (after the snapshot header) the failure record keeps */
74
+ export const HEAD_KEEP_CHARS: 300;
75
+ /** our own deadline around ONE attempt (a fetch that retries can take up to FETCH_ATTEMPTS of these, plus the pauses); a hung browser leaves no trace, this is the only thing that fires on the absence of an answer */
57
76
  export const PAGE_FETCH_TIMEOUT_MS: 90000;
58
77
  /**
59
78
  * the part of barebrowse's page handle the fetch uses
@@ -69,3 +88,11 @@ export type FetchPage = {
69
88
  }) => Promise<string>;
70
89
  close: () => Promise<void>;
71
90
  };
91
+ /**
92
+ * what a header-only attempt saw: content characters, elapsed ms, the first characters of the content (secret-masked)
93
+ */
94
+ export type AttemptRecord = {
95
+ chars: number;
96
+ ms: number;
97
+ head: string;
98
+ };
@@ -25,6 +25,12 @@ export function validReading(shape: unknown, r: unknown): boolean;
25
25
  * @param {string} s @returns {string|undefined}
26
26
  */
27
27
  export function numberAtEnd(s: string): string | undefined;
28
+ /**
29
+ * {@link numberAtEnd} for a comma-decimal page: the number written at the very end of `s` (only whitespace after it), as the page writes it
30
+ * ("1.057,65", "1 089", "48,49"). Only the last 24 characters are read (no price is longer), so a long run of digits cannot cost more than that.
31
+ * @param {string} s @returns {string|undefined}
32
+ */
33
+ export function numberAtEndComma(s: string): string | undefined;
28
34
  /**
29
35
  * Apply the rules to the AI's map over one saved page. Returns the kept facts and, for everything a rule removed, one `dropped` entry.
30
36
  * The order of the rules is the POC's (apply-v3.mjs): found-on-page, then the rules that read the page. A place is read as a phrase.
@@ -41,6 +47,8 @@ export function applyPageRules(text: string, mapping: PageMap, jobLines: {
41
47
  dropped: Dropped[];
42
48
  };
43
49
  export function linesOf(text: string): string[];
50
+ /** a number as a page writes it where the decimal mark is a comma: groups of three joined by "." or a space (or none), then an optional comma and decimals */
51
+ export const NUM_COMMA: "\\d{1,3}(?:[. ]\\d{3})+(?:,\\d+)?|\\d+(?:,\\d+)?";
44
52
  /**
45
53
  * what a `~` rule means as a limit (PRD v1.107 Part 5b): the same shape as a signed fact rule
46
54
  */
@@ -61,6 +69,8 @@ export type MapFact = {
61
69
  currency?: string[];
62
70
  unit?: string[];
63
71
  reading?: Reading;
72
+ lang?: string;
73
+ decimal?: string;
64
74
  };
65
75
  export type PageMap = {
66
76
  facts: MapFact[];
@@ -78,9 +88,11 @@ export type KeptFact = {
78
88
  currency?: string[];
79
89
  forRule?: number;
80
90
  reading?: Reading;
91
+ lang?: string;
92
+ decimal?: string;
81
93
  };
82
94
  /**
83
- * `other` = what the drop is compared to: the first label (R1), the primary form (R1L), the fact it would have repeated (S1), the phrase it looked for (phrase-no-result)
95
+ * `other` = what the drop is compared to: the first label (R1), the primary form (R1L), the box a sign listed twice was kept in (sign-twice: unit or currency), the fact it would have repeated (S1), the phrase it looked for (phrase-no-result)
84
96
  */
85
97
  export type Dropped = {
86
98
  line: number;
package/types/plan.d.ts CHANGED
@@ -123,6 +123,10 @@ export const EXIT_TYPES: readonly string[];
123
123
  /** decision 8: AND-only conjunction, bounded — no OR (a weak arm would
124
124
  * launder the exit), no NOT */
125
125
  export const MAX_EXITS_PER_STEP: 2;
126
+ /** a legal-example sentence for the exit menu — shown in the planner prompt and
127
+ * appended to the missing-required exit red, so a redraft sees a legal shape,
128
+ * not only the rule (F254: `exit` is required on EVERY step) */
129
+ export const EXIT_EXAMPLE: "Legal exit examples: a step with no check uses [{\"type\":\"artifact-written\",\"path\":\"<its target>\"},{\"type\":\"tree-changed\",\"scope\":\"<an offered scope>\"}]; a step with a check uses [{\"type\":\"tree-changed\",\"scope\":\"<an offered scope>\"},{\"type\":\"check-passes\",\"name\":\"<a check name>\"}].";
126
130
  /** plan size bound — per-step rounds bound the spend, but an unbounded step
127
131
  * COUNT is still an unbounded claim on the wallet; same 8 as loop.maxIterations */
128
132
  export const MAX_PLAN_STEPS: 8;
@@ -67,6 +67,7 @@ export function createReadShim({ cap, arm, onCount }?: {
67
67
  capped: number;
68
68
  bytesWithheld: number;
69
69
  };
70
+ reset: () => void;
70
71
  };
71
72
  /**
72
73
  * The one-tool spelling, kept for every caller written before the shim became an
@@ -107,9 +107,10 @@ export function parseStepFile(bytes: string | null): {
107
107
  * @param {Record<string, any>} obj
108
108
  * @param {string[]} [countLabels] labels whose claim COUNT a minClaims/maxClaims part reads
109
109
  * @param {any} [factPart] the step's `fact` part: its `results` become claims (text built by code) under `cites:<source>`
110
+ * @param {(Record<number, string>|undefined)[]} [asWritten] per result, the value spans a page-form fact's claim text is written with (see factClaims)
110
111
  * @returns {Record<string, any>}
111
112
  */
112
- export function flattenStep(obj: Record<string, any>, countLabels?: string[], factPart?: any): Record<string, any>;
113
+ export function flattenStep(obj: Record<string, any>, countLabels?: string[], factPart?: any, asWritten?: (Record<number, string> | undefined)[]): Record<string, any>;
113
114
  /**
114
115
  * One bareguard gap as a sentence the worker can act on. The numbers and names are bareguard's own measurements and the
115
116
  * person's signed limits, never anything this module infers; a gap this table does not know falls back to bareguard's own
package/types/source.d.ts CHANGED
@@ -347,8 +347,8 @@ export function isRubricFilesManifest(manifest: Record<string, any> | null | und
347
347
  * so run start can fetch it again); a `search:` line is a named refusal (a later build); so is a relative path, a missing file, a folder, a file over
348
348
  * {@link RUBRIC_INPUT_MAX_BYTES}, and text that is not valid UTF-8. Every refusal is plain words naming the line and
349
349
  * ends "Nothing spent." — nothing here touches a model.
350
- * @param {{inputs: {n: number, label: string, value: string}[], into: string, destination?: string, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string}>}} o `fetchUrl` - how a web address is read (default barebrowse via `fetchPageText`; a test injects a stub, never the network)
351
- * @returns {Promise<{ok: true, prep: {stop: null, into: string, tree: string, manifestPath: string, manifest: Record<string, any>}}|{ok: false, error: string, code: string}>}
350
+ * @param {{inputs: {n: number, label: string, value: string}[], into: string, destination?: string, fetchUrl?: (url: string) => Promise<{ok: true, text: string, url: string}|{ok: false, error: string, attempts?: {chars: number, ms: number, head: string}[]}>}} o `fetchUrl` - how a web address is read (default barebrowse via `fetchPageText`; a test injects a stub, never the network)
351
+ * @returns {Promise<{ok: true, prep: {stop: null, into: string, tree: string, manifestPath: string, manifest: Record<string, any>}}|{ok: false, error: string, code: string, attempts?: {chars: number, ms: number, head: string}[]}>}
352
352
  */
353
353
  export function proveRubricInputs({ inputs, into, destination, fetchUrl }: {
354
354
  inputs: {
@@ -365,6 +365,11 @@ export function proveRubricInputs({ inputs, into, destination, fetchUrl }: {
365
365
  } | {
366
366
  ok: false;
367
367
  error: string;
368
+ attempts?: {
369
+ chars: number;
370
+ ms: number;
371
+ head: string;
372
+ }[];
368
373
  }>;
369
374
  }): Promise<{
370
375
  ok: true;
@@ -379,6 +384,11 @@ export function proveRubricInputs({ inputs, into, destination, fetchUrl }: {
379
384
  ok: false;
380
385
  error: string;
381
386
  code: string;
387
+ attempts?: {
388
+ chars: number;
389
+ ms: number;
390
+ head: string;
391
+ }[];
382
392
  }>;
383
393
  /**
384
394
  * Is this Inputs value a path to an existing regular FILE on this machine (not a repo folder, not a web address, not a
@@ -26,8 +26,13 @@ export function cmdKey(params: any): string | null;
26
26
  * - `pattern-absent-in-diff` is always the `no-suppressions` guard: "no
27
27
  * casts or silencers added?"
28
28
  * - `rubric-step` (Part 1a) is one job line's output file: "line N — does its output pass the line's checks?"
29
- * - `command-exit` is the genre's `suite-green` stage (the only shipped use
30
- * of this kind): "does the test suite pass?"
29
+ * - `command-exit` quotes its OWN signed command verbatim:
30
+ * `does "<cmd> <args joined by space>" exit clean?` (e.g. `does "npm test"
31
+ * exit clean?`, `does "npx tsc --noEmit --strict" exit clean?`). It used
32
+ * to read "does the test suite pass?" for every command, so F256's run
33
+ * mvtatlxw showed two different commands (the real suite and a whole-repo
34
+ * `tsc --strict`) reading the same question. A missing or non-string
35
+ * `cmd` returns `null` (the caller falls back to the stage name).
31
36
  * - `count-not-worse` splits three ways on its own declared
32
37
  * `direction`/`baseline` (never the runtime number — see
33
38
  * {@link stageKindMetaFromSpec}'s own doc for why the baseline KIND must