bareloop 0.48.0 → 0.50.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.
@@ -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): {
@@ -33,5 +36,31 @@ export function dryReadPhrases(text: string, facts: KeptFact[]): Promise<{
33
36
  dropped: Dropped[];
34
37
  reads: Record<string, number>;
35
38
  }>;
39
+ /**
40
+ * The candidate lines of a kept time fact: a LOOSE finder (it only collects). Every page line where a kept label word has a clock time anywhere
41
+ * after it; the value is that line's first time after the label. Whether the run's checker can read it is not decided here.
42
+ * @param {string} text @param {KeptFact} k @returns {{quote: string, value: string}[]}
43
+ */
44
+ export function timeCandidateLines(text: string, k: KeptFact): {
45
+ quote: string;
46
+ value: string;
47
+ }[];
48
+ /**
49
+ * The same "can it read" for TIME facts (F236: the label "Departure time" sat on a page that writes "Departure time:", the colon right after it, so
50
+ * no time could ever be read after the label, and the fact was signed anyway). Each candidate line of a kept time fact is graded as an HONEST claim
51
+ * (quote = that line, value = its first time after the label) by the real `gradeStep`, signed like a run would sign it (name, shape, anchor = the
52
+ * primary label; no window, as dryReadMoney leaves the limits out). A fact with no green line is dropped whole as `reads-no-time`.
53
+ * No counts, no pass bar. A time fact with no label word has nothing to anchor a read to (a run could not sign it either), so it passes through untouched.
54
+ * Facts of other shapes pass through untouched. It catches an IMPOSSIBLE label only: a label that reads a WRONG time is kept (left to the person at Accept).
55
+ * @param {string} text the frozen page text @param {KeptFact[]} facts what the money dry read kept
56
+ * @returns {Promise<{facts: KeptFact[], dropped: Dropped[], reads: Record<string, number>, results: Record<string, number>}>}
57
+ * `reads` / `results` = candidate lines the checker read / found, per fact name (for tests and reports; no verdict derives from the numbers)
58
+ */
59
+ export function dryReadTimes(text: string, facts: KeptFact[]): Promise<{
60
+ facts: KeptFact[];
61
+ dropped: Dropped[];
62
+ reads: Record<string, number>;
63
+ results: Record<string, number>;
64
+ }>;
36
65
  export type KeptFact = import("./pagerules.js").KeptFact;
37
66
  export type Dropped = import("./pagerules.js").Dropped;
@@ -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
+ };
@@ -139,6 +139,7 @@ export const MAP_UNREADABLE: "The AI's answer about the page was not readable tw
139
139
  export const DROP_IT: "drop it";
140
140
  export function isDropIt(text: unknown): boolean;
141
141
  export function isAgree(text: unknown): boolean;
142
+ export function stripAgreeLead(text: string): string;
142
143
  /**
143
144
  * `reading` = the plain words an `agree` writes as a `~` rule (a reading ask only)
144
145
  */
@@ -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;
@@ -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