bareloop 0.55.0 → 0.57.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/CHANGELOG.md +82 -0
- package/README.md +3 -3
- package/bareloop.context.md +69 -209
- package/package.json +2 -2
- package/src/authorflow.js +164 -340
- package/src/authoring.js +7 -127
- package/src/authorjob.js +139 -472
- package/src/authorreadout.js +24 -368
- package/src/authorrun.js +21 -215
- package/src/behaviour.js +14 -0
- package/src/blockasks.js +43 -0
- package/src/bundlerun.js +4 -1
- package/src/checkblock.js +798 -0
- package/src/checklist.js +128 -0
- package/src/checkpick.js +39 -312
- package/src/checkwords.js +3 -1
- package/src/cli.js +3 -3
- package/src/declaredclose.js +38 -108
- package/src/destpoint.js +4 -2
- package/src/draftspend.js +46 -0
- package/src/facts.js +8 -1
- package/src/index.js +3 -43
- package/src/interviewrun.js +13 -8
- package/src/job.js +20 -1
- package/src/jobblock.js +11 -46
- package/src/judged.js +13 -1229
- package/src/kinds.js +5 -347
- package/src/noteask.js +124 -0
- package/src/pagedry.js +27 -5
- package/src/pagemap.js +15 -3
- package/src/pagerules.js +18 -3
- package/src/panel/authorroutes.js +24 -6
- package/src/panel/authorsession.js +222 -177
- package/src/panel/importrun.js +0 -1
- package/src/panel/index.html +198 -26
- package/src/panel/jobplan.js +87 -33
- package/src/panel/server.js +74 -68
- package/src/panel/status.js +3 -0
- package/src/pickrecord.js +34 -55
- package/src/placerule.js +355 -0
- package/src/planrun.js +2 -48
- package/src/promptregisters.js +13 -17
- package/src/providerrows.js +0 -36
- package/src/providers.js +4 -25
- package/src/questionbox.js +104 -0
- package/src/rowedit.js +115 -0
- package/src/rubricstep.js +234 -127
- package/src/run.js +11 -16
- package/src/userrun.js +60 -112
- package/types/authorflow.d.ts +41 -197
- package/types/authoring.d.ts +1 -14
- package/types/authorjob.d.ts +35 -59
- package/types/authorreadout.d.ts +10 -88
- package/types/behaviour.d.ts +12 -0
- package/types/blockasks.d.ts +36 -0
- package/types/checkblock.d.ts +376 -0
- package/types/checklist.d.ts +134 -0
- package/types/checkpick.d.ts +8 -140
- package/types/cli.d.ts +1 -3
- package/types/declaredclose.d.ts +7 -33
- package/types/destpoint.d.ts +2 -0
- package/types/draftspend.d.ts +21 -0
- package/types/index.d.ts +2 -4
- package/types/job.d.ts +8 -0
- package/types/jobblock.d.ts +8 -38
- package/types/judged.d.ts +7 -357
- package/types/kinds.d.ts +3 -104
- package/types/noteask.d.ts +76 -0
- package/types/pagedry.d.ts +13 -0
- package/types/pagemap.d.ts +4 -0
- package/types/pagerules.d.ts +7 -0
- package/types/panel/authorsession.d.ts +47 -5
- package/types/panel/jobgrid.d.ts +8 -8
- package/types/panel/jobplan.d.ts +48 -10
- package/types/panel/server.d.ts +27 -18
- package/types/panel/status.d.ts +5 -0
- package/types/pickrecord.d.ts +20 -13
- package/types/placerule.d.ts +194 -0
- package/types/planrun.d.ts +1 -22
- package/types/providerrows.d.ts +0 -31
- package/types/providers.d.ts +3 -19
- package/types/questionbox.d.ts +87 -0
- package/types/rowedit.d.ts +32 -0
- package/types/rubricstep.d.ts +100 -48
- package/types/run.d.ts +9 -19
- package/types/userrun.d.ts +0 -1
- package/src/calibrate.js +0 -702
- package/src/cardauthor.js +0 -502
- package/src/fitcheck.js +0 -166
- package/types/calibrate.d.ts +0 -201
- package/types/cardauthor.d.ts +0 -358
- package/types/fitcheck.d.ts +0 -113
package/src/kinds.js
CHANGED
|
@@ -66,8 +66,6 @@ import { tmpdir } from 'node:os';
|
|
|
66
66
|
import { join, sep, dirname } from 'node:path';
|
|
67
67
|
import { globToPrefix, isNonEmptyString } from './validate.js';
|
|
68
68
|
import { CLOSE_ENV_DENY } from './ralph.js';
|
|
69
|
-
import { runLocate, decide, validateCard, LOCATE_AXES, LOCATE_LABEL } from './judged.js';
|
|
70
|
-
import { rateSourceFields } from './text.js';
|
|
71
69
|
import { gradeStep, stepFileRel, STEP_MAX_BYTES, citedLabels, sha256Of } from './rubricstep.js';
|
|
72
70
|
|
|
73
71
|
/** the close's two judgment exits — a stage's verdict, in the shape the
|
|
@@ -139,82 +137,12 @@ export const SIGNS = Object.freeze([1, -1]);
|
|
|
139
137
|
* own live half by the suite, both directions: a kind the catalogue offers and
|
|
140
138
|
* this executor cannot run is a close that stops at runtime, and a kind this
|
|
141
139
|
* executor runs that the catalogue never names is a capability nothing can
|
|
142
|
-
* reach.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
* The judged stage's ladder: ONE attempt plus ONE retry, and no more.
|
|
147
|
-
*
|
|
148
|
-
* The POC measured a malformed emission roughly 1 in 6, which is exactly the
|
|
149
|
-
* shape a single retry buys down and a longer ladder buys nothing more of — each
|
|
150
|
-
* further attempt is another paid call against the same unchanged artifact and
|
|
151
|
-
* the same unchanged prompt. It is a CEILING the arbiter owns, never a knob a
|
|
152
|
-
* declaration can widen: a stage that could re-ask a model forever is a stage
|
|
153
|
-
* that can spend a budget without ever rendering a verdict.
|
|
154
|
-
*
|
|
155
|
-
* A `pricing-red` is never retried at all (see `runJudgedFloor`): a retry of an
|
|
156
|
-
* unpriced call only buys more spend nobody can see (F6).
|
|
157
|
-
*/
|
|
158
|
-
export const JUDGE_ATTEMPTS = 2;
|
|
159
|
-
/**
|
|
160
|
-
* The ceiling on how many artifacts ONE judged stage may buy a judgement of —
|
|
161
|
-
* the sibling of `MAX_TERMS` and `MAX_STAGES`, and here for the same reason: a
|
|
162
|
-
* runaway list is a bill, not a red. Enforced by the catalogue's validator
|
|
163
|
-
* before any token, so a declaration that names more is refused at the gate
|
|
164
|
-
* rather than discovered at the invoice.
|
|
165
|
-
*/
|
|
166
|
-
export const MAX_JUDGED_PATHS = 8;
|
|
167
|
-
/** RULING 8 — the stages the seed-verdict read (D12) must NOT run. A judged
|
|
168
|
-
* number at seed is unstable and a person at seed is an interview, not a
|
|
169
|
-
* measurement; their bar comes from calibration (soft-green) or from the person
|
|
170
|
-
* themselves (hitl), never from the seed. The skip is RECORDED by name rather
|
|
171
|
-
* than taken in silence (F59: absent is not empty), so `seedRead` still returns
|
|
140
|
+
* reach. */
|
|
141
|
+
export const LIVE_KINDS = Object.freeze(['command-exit', 'count-not-worse', 'pattern-absent-in-diff', 'files-changed', 'human-confirms', 'rubric-step']);
|
|
142
|
+
/** RULING 8 — the stages the seed-verdict read (D12) must NOT run: a person at seed is an interview, not a measurement; their bar comes from the person
|
|
143
|
+
* themselves (hitl), never from the seed. The skip is RECORDED by name rather than taken in silence (F59: absent is not empty), so `seedRead` still returns
|
|
172
144
|
* one row per declared stage. */
|
|
173
|
-
|
|
174
|
-
* the authoring pipeline, the card, the catalogue and the close each key a
|
|
175
|
-
* decision on it, and five literals is how they come to disagree. */
|
|
176
|
-
export const JUDGED_FLOOR_KIND = 'judged-floor';
|
|
177
|
-
export const SEED_EXEMPT_KINDS = Object.freeze([JUDGED_FLOOR_KIND, 'human-confirms']);
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* The judged stages of a close declaration, and whether it has any — the ONE
|
|
181
|
-
* spelling of "does this close ask a model to render anything?".
|
|
182
|
-
*
|
|
183
|
-
* The comment above `JUDGED_FLOOR_KIND` says five literals is how the readers
|
|
184
|
-
* come to disagree, and by PRD item 31.4 there were SIX open-coded
|
|
185
|
-
* `stages.filter(s => s.kind === JUDGED_FLOOR_KIND)` across the tree
|
|
186
|
-
* (`src/authorjob.js` twice, `src/cardauthor.js`, `src/declaredclose.js`,
|
|
187
|
-
* `scripts/run-author.mjs`, `scripts/author-readout.mjs`). 31.4 needed a
|
|
188
|
-
* seventh, in the runner, to decide whether a judge KEY is demanded — and a
|
|
189
|
-
* seventh spelling deciding a REFUSAL is the drift `scripts/run-u.mjs`'s own
|
|
190
|
-
* judge-provider comment warns about ("a second reading of the declaration
|
|
191
|
-
* that can drift from the one the runner actually executes"). So there is one
|
|
192
|
-
* reading now, and every caller shares it.
|
|
193
|
-
*
|
|
194
|
-
* Defensive on shape ON PURPOSE: callers pass raw specs read off disk and
|
|
195
|
-
* half-built drafts, not validated declarations. An absent/!object `closeDecl`
|
|
196
|
-
* or `stages` is "no judged stages", never a throw — the close VALIDATOR is
|
|
197
|
-
* what rejects a malformed declaration, and this predicate answering a
|
|
198
|
-
* question about one is not the place to re-litigate it.
|
|
199
|
-
* @param {any} closeDecl a close declaration (or anything, including undefined)
|
|
200
|
-
* @returns {any[]} the judged-floor stages, in declaration order
|
|
201
|
-
*/
|
|
202
|
-
export function judgedStages(closeDecl) {
|
|
203
|
-
const stages = closeDecl && typeof closeDecl === 'object' ? closeDecl.stages : undefined;
|
|
204
|
-
if (!Array.isArray(stages)) return [];
|
|
205
|
-
return stages.filter((s) => s !== null && typeof s === 'object' && s.kind === JUDGED_FLOOR_KIND);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Does this close declaration judge — i.e. will a judge model be CALLED?
|
|
210
|
-
* The question `scripts/run-u.mjs` asks before demanding a judge key (PRD item
|
|
211
|
-
* 31.4): a job that never judges must run on its own provider's key alone.
|
|
212
|
-
* @param {any} closeDecl
|
|
213
|
-
* @returns {boolean}
|
|
214
|
-
*/
|
|
215
|
-
export function closeJudges(closeDecl) {
|
|
216
|
-
return judgedStages(closeDecl).length > 0;
|
|
217
|
-
}
|
|
145
|
+
export const SEED_EXEMPT_KINDS = Object.freeze(['human-confirms']);
|
|
218
146
|
/** the one kind a PERSON renders — named once, because the runner keys three
|
|
219
147
|
* decisions on it (is there a door to answer, which stage paused, whose ruling
|
|
220
148
|
* this is) and three literals is how they come to disagree */
|
|
@@ -299,38 +227,12 @@ export function mechanicalStages(stages) {
|
|
|
299
227
|
* timeoutMsDefault?: number, baselineMode?: 'auto'|'worktree',
|
|
300
228
|
* gapCap?: number, maxBuffer?: number, seedTrees?: SeedTrees,
|
|
301
229
|
* humanRuling?: {decision: string, text?: string|null}|null,
|
|
302
|
-
* judgeLoop?: (o: {system: string}) => any,
|
|
303
|
-
* judgeModel?: string,
|
|
304
|
-
* onJudgeCost?: (c: {stage: string|null, kind: string|null, path: string, attempt: number,
|
|
305
|
-
* label: string, model: string, costUsd: number|null, unpricedRounds: number}) => void,
|
|
306
|
-
* callBounds?: () => {timeoutMs?: number, deadlineMs?: number},
|
|
307
230
|
* onRubricEvidence?: (e: {step: number, evidence: any[], evidenceTotal?: number}) => void,
|
|
308
231
|
* onStage?: (row: {stage: string|null, kind: string|null, verdict: string, durationMs: number}) => void}} Ctx
|
|
309
232
|
* The arbiter's half of a stage run. Every field here is operator/runner
|
|
310
233
|
* territory: a declaration parameterises kinds, never the contracts.
|
|
311
234
|
* `humanRuling` is the SIGNER's answer at a hitl pause, carried in from the
|
|
312
235
|
* runner — never authored, never defaulted, and absent on every ordinary run.
|
|
313
|
-
* `judgeLoop` is the PAID seam the judged stage runs its locate call through, and
|
|
314
|
-
* it is operator territory for the same reason the worker's provider is: this
|
|
315
|
-
* module owns no provider and never picks one. Absent is not a fall-back to some
|
|
316
|
-
* other model — the stage stops as a wiring gap, the same answer `runPlan` gives a
|
|
317
|
-
* native job with no native factory.
|
|
318
|
-
* `judgeModel` is the seam's other half (PRD item 32.1): WHICH model that loop
|
|
319
|
-
* drives, resolved by the runner (`resolveJudge`, src/judged.js — the spec's signed
|
|
320
|
-
* `judge` override, else the job's own worker model) rather than pinned in this
|
|
321
|
-
* library. It is required whenever `judgeLoop` is, and for the same reason: a
|
|
322
|
-
* verdict whose grader cannot be named is a floor nobody can attribute, and the
|
|
323
|
-
* signed calibration record has nothing to compare against. The two travel
|
|
324
|
-
* together or the stage stops.
|
|
325
|
-
* `onJudgeCost` is the METER, and it is the only reason a judged stage can be
|
|
326
|
-
* funded honestly: this executor cannot reach the run's ledger, so every locate
|
|
327
|
-
* call's cost is reported OUT through it, once per call, on every route including
|
|
328
|
-
* the red ones — a paid call that leaves no meter record is F12 in a judge's coat.
|
|
329
|
-
* `callBounds` is F152/PRD 30.4's per-call TIME bound, read fresh before every
|
|
330
|
-
* locate attempt — the same derivation the run's own worker rounds carry
|
|
331
|
-
* (`callBounds()`, src/planrun.js). Absent is the honest unbounded default:
|
|
332
|
-
* an adopter or test that wires no clock through behaves exactly as before
|
|
333
|
-
* this field existed.
|
|
334
236
|
* `onStage` is a REPORTING seam and nothing else: the seed read spawns a real
|
|
335
237
|
* toolchain per stage (a suite is the slow one) and a whole read is one opaque
|
|
336
238
|
* await, so the shell gets told as each stage lands. It decides nothing, it is
|
|
@@ -1790,249 +1692,6 @@ async function runHumanConfirms(stage, ctx) {
|
|
|
1790
1692
|
{}, STOP_FAULTS.CRASHED);
|
|
1791
1693
|
}
|
|
1792
1694
|
|
|
1793
|
-
/**
|
|
1794
|
-
* THE JUDGED FLOOR (softgreen module 2) — the one kind that BUYS its measurement.
|
|
1795
|
-
*
|
|
1796
|
-
* It is `src/judged.js`'s two halves wired into the close, and the split is the
|
|
1797
|
-
* whole safety argument: LOCATE is a pinned, toolless model asked for facts with
|
|
1798
|
-
* addresses over the AUTHORITATIVE artifact, and DECIDE is a pure arbiter-owned
|
|
1799
|
-
* function with no model in it. The judge never renders a verdict; this runner
|
|
1800
|
-
* renders it, from an owned rulebook, over quotes the artifact must contain.
|
|
1801
|
-
*
|
|
1802
|
-
* FOUR ROUTES OUT, and which is which is the load-bearing part:
|
|
1803
|
-
*
|
|
1804
|
-
* - GREEN / RED come from `decide()` alone. A red is CONTENT — facts in hand,
|
|
1805
|
-
* and a card item those facts do not satisfy (or cannot be sure about, since
|
|
1806
|
-
* unsure is red). That is evidence about the tree.
|
|
1807
|
-
* - AN INSTRUMENT STOP is everything else: a card this arbiter cannot read, an
|
|
1808
|
-
* artifact that will not open, no judge seam wired, and — after the ladder —
|
|
1809
|
-
* a judge whose emission never parsed or whose call never came back.
|
|
1810
|
-
* Contract (a) names "unreadable or unparseable required output" as a stop in
|
|
1811
|
-
* so many words, and the reason is the casualty rule: our judge producing
|
|
1812
|
-
* garbage says nothing whatsoever about the worker, and grading a tree red on
|
|
1813
|
-
* it would be manufactured evidence (F45).
|
|
1814
|
-
* - A `pricing-red` locate is that same stop with the retry REFUSED: an
|
|
1815
|
-
* unpriced call cannot be summed, and buying a second one only adds more
|
|
1816
|
-
* spend nobody can see (F6).
|
|
1817
|
-
*
|
|
1818
|
-
* The gap is ITEMIZED (ruling 7, F38/F39): named card items, per-file, with the
|
|
1819
|
-
* function names and the instrument's own quotes — never one paragraph. It rides
|
|
1820
|
-
* the same `Gap` bound as every other kind, so the trim is announced.
|
|
1821
|
-
*
|
|
1822
|
-
* EVERY path is judged, not just up to the first red, for the same reason
|
|
1823
|
-
* `decide()` grades every item: calibration reads itemized reds, and a stage that
|
|
1824
|
-
* short-circuits reports the first thing it found rather than what is true.
|
|
1825
|
-
* `firstRed` still names the deciding item in DECLARED order, so the verdict's
|
|
1826
|
-
* reason is stable against whatever order a model emitted anything in.
|
|
1827
|
-
*
|
|
1828
|
-
* NOT WIRED, AND NAMED RATHER THAN SILENTLY SKIPPED — `judgeToAnnotation` →
|
|
1829
|
-
* `gate.annotate` (the slice-2 obligation list, item 4). Two independent reasons,
|
|
1830
|
-
* either of which alone would defer it:
|
|
1831
|
-
* (1) THE ADAPTER TAKES A VERDICT. bare-agent's `judgeToAnnotation` maps a
|
|
1832
|
-
* `judge()` verdict (`{verdict, where:{field, stated, returned}}`) onto the
|
|
1833
|
-
* annotation shape, and this pipe deliberately never buys a verdict from a
|
|
1834
|
-
* model — LOCATE returns facts, and the verdict is `decide()`'s. Feeding it
|
|
1835
|
-
* a synthesised verdict would annotate the gate with a judgement no judge
|
|
1836
|
-
* made, which is the one thing the locate-not-verdict split exists to stop.
|
|
1837
|
-
* (2) THERE IS NO GATE HERE. A Gate is built per WORKER step (`mkWorker`,
|
|
1838
|
-
* src/planrun.js) and is gone by the time the close runs; the close is
|
|
1839
|
-
* deliberately outside every worker's fence. Annotating "the arbiter's own
|
|
1840
|
-
* gate" needs a run-scoped gate that does not exist today, and inventing
|
|
1841
|
-
* one to carry an annotation would be plumbing built for its own sake.
|
|
1842
|
-
* The facts themselves are NOT lost meanwhile: every per-path reading (verdict,
|
|
1843
|
-
* itemized reds, the ladder, the scrubbed raw) rides `detail.perPath`.
|
|
1844
|
-
* @param {any} stage @param {Ctx} ctx @returns {Promise<StageResult>}
|
|
1845
|
-
*/
|
|
1846
|
-
async function runJudgedFloor(stage, ctx) {
|
|
1847
|
-
const p = stage.params;
|
|
1848
|
-
// 1. the CARD, through the one spelling (`validateCard`). A card this arbiter
|
|
1849
|
-
// cannot read is a broken close, never a red about the tree — and it is
|
|
1850
|
-
// checked before the seam and before the artifact, because it costs nothing.
|
|
1851
|
-
const cv = validateCard(p?.card);
|
|
1852
|
-
if (!cv.ok) {
|
|
1853
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}" carries a rubric card this arbiter cannot read: ${cv.reds.join('; ')}`,
|
|
1854
|
-
{}, STOP_FAULTS.CRASHED);
|
|
1855
|
-
}
|
|
1856
|
-
const paths = Array.isArray(p?.paths) ? p.paths.filter(isNonEmptyString) : [];
|
|
1857
|
-
if (paths.length === 0) {
|
|
1858
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}" names no artifact to judge — a judged stage with no `
|
|
1859
|
-
+ 'paths judges nothing, and nothing is not a pass', {}, STOP_FAULTS.CRASHED);
|
|
1860
|
-
}
|
|
1861
|
-
if (paths.length > MAX_JUDGED_PATHS) {
|
|
1862
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}" names ${paths.length} artifacts, over the ceiling of `
|
|
1863
|
-
+ `${MAX_JUDGED_PATHS} — a judged stage buys one call per artifact, and a runaway list is a bill`, {}, STOP_FAULTS.CRASHED);
|
|
1864
|
-
}
|
|
1865
|
-
// 1b. THE TIER THE SIGNED SET WAS GRADED BY, against the tier this run would buy.
|
|
1866
|
-
// the judge model has always SAID a bump forces a full recalibration; this is the
|
|
1867
|
-
// detector, because a rule with no wired detector is prose (F45). The stamp comes
|
|
1868
|
-
// off the SIGNED calibration (`calibration.judgeModel`, carried across by
|
|
1869
|
-
// `declaredStages`), so a mismatch means exactly one thing: the pin moved under a
|
|
1870
|
-
// signature, and the floor standing behind this stage was certified by a model
|
|
1871
|
-
// nobody is about to call. That is a FAILED wiring gap and not a crash — the same
|
|
1872
|
-
// fault, and for the same reason, as the absent seam below: nothing is broken,
|
|
1873
|
-
// something was never re-done. It stops rather than degrading in either direction,
|
|
1874
|
-
// because grading on the new tier would mint a verdict against an uncalibrated
|
|
1875
|
-
// floor and grading on the old one is not on offer (the pin is a constant).
|
|
1876
|
-
// AN ABSENT STAMP IS NOT CHECKED HERE, deliberately and for the reason the SET's
|
|
1877
|
-
// own presence is not checked in `validateCloseDecl`: a spec that judges cannot
|
|
1878
|
-
// reach a run without a calibration (the signing gate, module 5) or without a
|
|
1879
|
-
// model on it (`validateCloseDecl`), so the runtime question is only ever WHICH
|
|
1880
|
-
// model — and a stage descriptor handed straight to `runStage` by an adopter or a
|
|
1881
|
-
// test is not a signed spec making a claim about a tier.
|
|
1882
|
-
//
|
|
1883
|
-
// PRD item 32.1: WHICH model grades is no longer this module's constant — it is
|
|
1884
|
-
// `ctx.judgeModel`, the identity the run resolved and wired (`resolveJudge`,
|
|
1885
|
-
// src/judged.js: the spec's signed `judge` override, else the job's own worker
|
|
1886
|
-
// model). The IDENTITY is checked before the seam and before the stamp, because
|
|
1887
|
-
// an unwired identity makes both of the messages below unwritable: neither
|
|
1888
|
-
// "would grade with X" nor "the judge is X" can be said by a stage that cannot
|
|
1889
|
-
// name X. There is deliberately NO library-pinned fall-back here — a run that
|
|
1890
|
-
// cannot say which model grades has not wired a judge, and grading under an
|
|
1891
|
-
// identity nobody chose is exactly the silent-ignore class this repo refuses
|
|
1892
|
-
// everywhere else.
|
|
1893
|
-
if (!isNonEmptyString(ctx.judgeModel)) {
|
|
1894
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}" is a judged stage and this run wired no judge IDENTITY `
|
|
1895
|
-
+ '(ctx.judgeModel) — an adopter wiring gap, never a silent fall-back to a library pin. A verdict whose grader '
|
|
1896
|
-
+ 'cannot be named is a floor nobody can attribute, and the calibration record has nothing to compare against',
|
|
1897
|
-
{}, STOP_FAULTS.FAILED);
|
|
1898
|
-
}
|
|
1899
|
-
const judgeModel = /** @type {string} */ (ctx.judgeModel);
|
|
1900
|
-
if (isNonEmptyString(stage.calibrationJudgeModel) && stage.calibrationJudgeModel !== judgeModel) {
|
|
1901
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}" would grade with ${judgeModel}, and the calibration `
|
|
1902
|
-
+ `set signed with this close was graded by ${stage.calibrationJudgeModel} — the judge moved under the `
|
|
1903
|
-
+ 'signature. A floor is worth exactly the judge that certified it, so this stops rather than grading against a '
|
|
1904
|
-
+ 'floor nobody calibrated: re-sign the spec with the new judge and re-run the calibration gate (recalibrate)',
|
|
1905
|
-
{ signedJudgeModel: stage.calibrationJudgeModel, judgeModel }, STOP_FAULTS.FAILED);
|
|
1906
|
-
}
|
|
1907
|
-
if (typeof ctx.judgeLoop !== 'function') {
|
|
1908
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}" is a judged stage and this run wired no judge seam `
|
|
1909
|
-
+ `(ctx.judgeLoop) — an adopter wiring gap, never a silent fall-back: the judge is ${judgeModel} and a `
|
|
1910
|
-
+ 'stage that quietly graded on whatever model was lying around would be a floor nobody calibrated',
|
|
1911
|
-
{}, STOP_FAULTS.FAILED);
|
|
1912
|
-
}
|
|
1913
|
-
const loopFactory = /** @type {(o: {system: string}) => any} */ (ctx.judgeLoop);
|
|
1914
|
-
|
|
1915
|
-
const gap = new Gap(ctx.gapKeep, ctx.gapCap);
|
|
1916
|
-
/** @type {any[]} */
|
|
1917
|
-
const perPath = [];
|
|
1918
|
-
/** @type {{path: string, rule: string, text: string, reds: any[]}[]} */
|
|
1919
|
-
const redItems = [];
|
|
1920
|
-
/** the reds that name NO card item: `decide()`'s unsure routes (no usable facts,
|
|
1921
|
-
* an empty function list). They are the fail-safe itself, so the verdict is read
|
|
1922
|
-
* off the per-path verdicts and NEVER off `redItems` — a red with nothing itemized
|
|
1923
|
-
* under it is exactly the shape that would otherwise fall through to green. */
|
|
1924
|
-
/** @type {{path: string, reason: string}[]} */
|
|
1925
|
-
const unsure = [];
|
|
1926
|
-
let redFiles = 0;
|
|
1927
|
-
|
|
1928
|
-
for (const rel of paths) {
|
|
1929
|
-
let artifactText;
|
|
1930
|
-
try {
|
|
1931
|
-
artifactText = await readFile(join(ctx.workdir, rel), 'utf8');
|
|
1932
|
-
} catch (e) {
|
|
1933
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}" could not read the artifact it judges (${rel}): `
|
|
1934
|
-
+ `${String(/** @type {any} */ (e)?.message ?? e)}`, { path: rel }, STOP_FAULTS.CRASHED);
|
|
1935
|
-
}
|
|
1936
|
-
if (artifactText.trim() === '') {
|
|
1937
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}"'s artifact ${rel} is empty — an empty artifact `
|
|
1938
|
-
+ 'yields no facts, and no facts is unknown, never a pass', { path: rel }, STOP_FAULTS.CRASHED);
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
/** @type {any} */
|
|
1942
|
-
let last = null;
|
|
1943
|
-
/** @type {any[]} */
|
|
1944
|
-
const tries = [];
|
|
1945
|
-
for (let attempt = 1; attempt <= JUDGE_ATTEMPTS; attempt += 1) {
|
|
1946
|
-
last = await runLocate({
|
|
1947
|
-
artifactText,
|
|
1948
|
-
card: p.card,
|
|
1949
|
-
loopFactory,
|
|
1950
|
-
attempt,
|
|
1951
|
-
// F152/PRD 30.4 — read fresh per attempt, the same way `planrun.js`'s own
|
|
1952
|
-
// worker rounds re-read `callBounds()` at every call site rather than
|
|
1953
|
-
// once: the remaining time shrinks between attempts. Absent (no clock
|
|
1954
|
-
// wired through) is `{}`, the honest unbounded default `runLocate` itself
|
|
1955
|
-
// already carries.
|
|
1956
|
-
callBounds: typeof ctx.callBounds === 'function' ? ctx.callBounds() : {},
|
|
1957
|
-
onCost: (c) => {
|
|
1958
|
-
if (typeof ctx.onJudgeCost !== 'function') return;
|
|
1959
|
-
ctx.onJudgeCost({
|
|
1960
|
-
stage: stage?.name ?? null, kind: stage?.kind ?? null, path: rel, attempt,
|
|
1961
|
-
label: LOCATE_LABEL, model: judgeModel, costUsd: c.costUsd, unpricedRounds: c.unpricedRounds,
|
|
1962
|
-
...rateSourceFields(c),
|
|
1963
|
-
});
|
|
1964
|
-
},
|
|
1965
|
-
});
|
|
1966
|
-
tries.push({ attempt, ok: last.ok, axis: last.red?.axis ?? null, costUsd: last.costUsd, truncated: last.truncated, parseError: last.parseError });
|
|
1967
|
-
if (last.ok) break;
|
|
1968
|
-
// the ONE non-retryable axis, and it outranks the ladder: a retry of an
|
|
1969
|
-
// unpriced call buys more spend nobody can see (F6).
|
|
1970
|
-
if (last.red.axis === LOCATE_AXES.PRICING) break;
|
|
1971
|
-
}
|
|
1972
|
-
if (!last.ok) {
|
|
1973
|
-
return stopped(stage, ctx, `INSTRUMENT: stage "${stage.name}"'s judge returned no usable facts for ${rel} after `
|
|
1974
|
-
+ `${tries.length} attempt(s) [${last.red.axis}]: ${last.red.detail}`,
|
|
1975
|
-
{ path: rel, axis: last.red.axis, attempts: tries }, STOP_FAULTS.CRASHED);
|
|
1976
|
-
}
|
|
1977
|
-
|
|
1978
|
-
const d = decide(last.facts, p.card, { artifactText });
|
|
1979
|
-
perPath.push({ path: rel, verdict: d.verdict, firstRed: d.firstRed, attempts: tries, raw: last.raw, items: d.items });
|
|
1980
|
-
if (d.verdict === 'red') {
|
|
1981
|
-
redFiles += 1;
|
|
1982
|
-
for (const it of d.items) if (!it.ok) redItems.push({ path: rel, rule: it.rule, text: it.text, reds: it.reds });
|
|
1983
|
-
if (!d.items.some((it) => !it.ok)) unsure.push({ path: rel, reason: String(d.reason ?? 'unsure, and unsure is red') });
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
|
|
1987
|
-
// WHAT failed, as a set of plain keys — one per failing function (a red that names no function
|
|
1988
|
-
// keeps its item key), plus each unsure entry. Its SIZE is the ONE red count: the gap headline
|
|
1989
|
-
// prints it, `trendValueOf` reads it, and `readGrade` scrapes the same number back (F192 e).
|
|
1990
|
-
const redSet = [
|
|
1991
|
-
...redItems.flatMap((it) => (it.reds.length ? it.reds.map((r) => `${it.path}|${it.rule}|${r.fn}`) : [`${it.path}|${it.rule}`])),
|
|
1992
|
-
...unsure.map((u) => `${u.path}|unsure|${u.reason}`),
|
|
1993
|
-
];
|
|
1994
|
-
const redCount = new Set(redSet).size;
|
|
1995
|
-
const red = redFiles > 0;
|
|
1996
|
-
if (red) {
|
|
1997
|
-
// FIRST-RED-WINS in the CARD's own signed order, across every artifact: the
|
|
1998
|
-
// card is the arbiter's order, and the file loop's order is the declaration's.
|
|
1999
|
-
const order = p.card.items.map((/** @type {any} */ it) => it.rule);
|
|
2000
|
-
const firstRed = order.find((/** @type {string} */ r) => redItems.some((x) => x.rule === r))
|
|
2001
|
-
?? (redItems[0]?.rule ?? 'unsure');
|
|
2002
|
-
gap.push(`${stage.name}: the judged floor is not met — ${redCount} red(s) across ${redFiles} of `
|
|
2003
|
-
+ `${paths.length} artifact(s); first red: ${firstRed}`);
|
|
2004
|
-
for (const u of unsure) gap.push(` ${u.path}: ${u.reason}`);
|
|
2005
|
-
for (const it of redItems) {
|
|
2006
|
-
gap.push(` [${it.rule}] ${it.text}`);
|
|
2007
|
-
// the file, the function and the quote are all things the INSTRUMENT itself
|
|
2008
|
-
// reported (contract (b) bars naming a culprit it did not) — and a red with
|
|
2009
|
-
// no address is the semantic genre F38 measured as inert
|
|
2010
|
-
for (const r of it.reds) {
|
|
2011
|
-
gap.push(` ${it.path}: ${r.fn} — ${r.why}`);
|
|
2012
|
-
if (r.quote) gap.push(` > ${String(r.quote).split('\n')[0].trim().slice(0, 200)}`);
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
}
|
|
2016
|
-
return result(stage, {
|
|
2017
|
-
verdict: red ? 'red' : 'green',
|
|
2018
|
-
exitCode: red ? EXIT_RED : EXIT_GREEN,
|
|
2019
|
-
gapLines: gap.render(),
|
|
2020
|
-
detail: {
|
|
2021
|
-
model: judgeModel,
|
|
2022
|
-
card: p.card.items.map((/** @type {any} */ it) => it.rule),
|
|
2023
|
-
paths,
|
|
2024
|
-
perPath,
|
|
2025
|
-
redItems: redItems.length,
|
|
2026
|
-
unsure,
|
|
2027
|
-
redFiles,
|
|
2028
|
-
// the distinct red COUNT (the headline's number and the trend value) and the set it counts;
|
|
2029
|
-
// the set also lets the trend reader compare two numberless judged reds (run mv13ery3)
|
|
2030
|
-
redCount,
|
|
2031
|
-
redSet,
|
|
2032
|
-
},
|
|
2033
|
-
});
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
1695
|
/** @type {Record<string, (stage: any, ctx: Ctx) => Promise<StageResult>>} */
|
|
2037
1696
|
const RUNNERS = {
|
|
2038
1697
|
'command-exit': runCommandExit,
|
|
@@ -2040,7 +1699,6 @@ const RUNNERS = {
|
|
|
2040
1699
|
'pattern-absent-in-diff': runPatternAbsentInDiff,
|
|
2041
1700
|
'files-changed': runFilesChanged,
|
|
2042
1701
|
'human-confirms': runHumanConfirms,
|
|
2043
|
-
'judged-floor': runJudgedFloor,
|
|
2044
1702
|
'rubric-step': runRubricStep,
|
|
2045
1703
|
};
|
|
2046
1704
|
|
package/src/noteask.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Build 2026-11-14 (b), live run mwgjlezb: a rubric line whose `~` rule maps to a fact is facts-only, so "Write a one-sentence triage note ..." produced results and no note.
|
|
2
|
+
// ONE typed call per job, ONLY when a line is facts-only: the AI answers yes/no per line, "does the line also ask for written words beyond the facts found?"; CODE decides what it means
|
|
3
|
+
// (src/checkblock.js buildNote). The AI sees the numbered line text only (no `~` rules). Wording and reply shape are the POC's (.claude/scratch/poc-note-question, 12/12), the call/book/retry
|
|
4
|
+
// pattern is src/destpoint.js's `runDestPoint`. A call that does not finish is `failed` for every asked line (the card says so); never a guess.
|
|
5
|
+
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { priceOf, scrubRaw, tallyCalls, capStop, callCasualty } from './text.js';
|
|
8
|
+
import { redactSecrets } from './validate.js';
|
|
9
|
+
import { isTransportFailure } from './transport.js';
|
|
10
|
+
import { isRateLimited, rateLimitWaitMs } from './ratelimit.js';
|
|
11
|
+
import { isOutputCutOff } from './authorflow.js';
|
|
12
|
+
import { AUTHOR_CALL_TIMEOUT_MS, AUTHOR_SCOUT_MAX_TOKENS } from './authorscout.js';
|
|
13
|
+
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
const { Loop } = require('bare-agent');
|
|
16
|
+
|
|
17
|
+
/** the label of the one paid call, as the drafting book sees it */
|
|
18
|
+
export const NOTE_CALL_LABEL = 'note-ask';
|
|
19
|
+
|
|
20
|
+
export const NOTE_SYSTEM = 'You read the numbered lines of a job. You answer only about what each line says; you never invent words.';
|
|
21
|
+
|
|
22
|
+
/** What the AI is told: the numbered job lines (text only), the one question, the reply shape and a legal example. @param {{n: number, text: string}[]} lines @returns {string} */
|
|
23
|
+
export function notePrompt(lines) {
|
|
24
|
+
return `THE JOB:\n${lines.map((l) => `LINE ${l.n}: ${l.text}`).join('\n')}\n\n`
|
|
25
|
+
+ 'For EACH line answer ONE question: does the line also ask for written words (a note, a sentence, a paragraph, a summary) beyond the facts found on the page (items, numbers, dates, quoted words)? '
|
|
26
|
+
+ 'A line that only asks to list, find or give items with their fields is "no". '
|
|
27
|
+
+ 'Reply with JSON only, no prose, no code fence: {"lines":[{"line":<line number>,"writtenWords":"yes"|"no"}]}, one entry per line. '
|
|
28
|
+
+ 'Example: for "LINE 1: List the 3 newest posts with title and date" and "LINE 2: Write a two-sentence recap of the newest post" the reply is {"lines":[{"line":1,"writtenWords":"no"},{"line":2,"writtenWords":"yes"}]}.';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Code reads the reply: every asked line answered exactly yes or no, else malformed (no repair). An answer for a line not asked is malformed too.
|
|
33
|
+
* @param {unknown} text @param {{n: number}[]} lines @returns {Map<number, 'yes'|'no'>|null}
|
|
34
|
+
*/
|
|
35
|
+
export function decideNote(text, lines) {
|
|
36
|
+
/** @type {any} */
|
|
37
|
+
let j;
|
|
38
|
+
try { j = JSON.parse(String(text ?? '').trim()); } catch { return null; }
|
|
39
|
+
if (j === null || typeof j !== 'object' || !Array.isArray(j.lines)) return null;
|
|
40
|
+
/** @type {Map<number, 'yes'|'no'>} */
|
|
41
|
+
const out = new Map();
|
|
42
|
+
for (const e of j.lines) {
|
|
43
|
+
if (e === null || typeof e !== 'object' || !Number.isInteger(e.line) || (e.writtenWords !== 'yes' && e.writtenWords !== 'no') || !lines.some((l) => l.n === e.line)) return null;
|
|
44
|
+
out.set(e.line, e.writtenWords);
|
|
45
|
+
}
|
|
46
|
+
return lines.every((l) => out.has(l.n)) ? out : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const defaultLoop = (/** @type {any} */ { system, onLlmResult, provider, rates }) =>
|
|
50
|
+
new Loop({ provider, system, onLlmResult, ...(rates ? { rates } : {}) });
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Run the call: one call, one retry on a malformed reply, a transport failure or a 429. Never throws on a call casualty; every failure is `failed` (the lines stay facts-only).
|
|
54
|
+
* @param {{lines: {n: number, text: string}[], provider?: any, maxTokens?: number, ceilingUsd?: number|null, callTimeoutMs?: number,
|
|
55
|
+
* onCall?: (call: {label: string, costUsd: number|null, unpricedRounds: number, thinkingStatus?: string, raw?: string}) => void,
|
|
56
|
+
* createLoop?: Function, rates?: {in: number, out: number}|null, callOptions?: Record<string, any>, sleep?: (ms: number) => Promise<void>}} o
|
|
57
|
+
* @returns {Promise<{state: 'answered'|'failed', answers: Map<number, 'yes'|'no'>, reason: string|null, calls: {label: string, costUsd: number|null, unpricedRounds: number}[]}>}
|
|
58
|
+
*/
|
|
59
|
+
export async function runNoteAsk({
|
|
60
|
+
lines, provider = null, maxTokens = AUTHOR_SCOUT_MAX_TOKENS, ceilingUsd = null, callTimeoutMs = AUTHOR_CALL_TIMEOUT_MS,
|
|
61
|
+
onCall = () => {}, createLoop = defaultLoop, rates = null, callOptions = {}, sleep = (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
62
|
+
}) {
|
|
63
|
+
const callTimeout = Number.isFinite(Number(callTimeoutMs)) && Number(callTimeoutMs) > 0 ? Math.min(Math.trunc(Number(callTimeoutMs)), AUTHOR_CALL_TIMEOUT_MS) : AUTHOR_CALL_TIMEOUT_MS;
|
|
64
|
+
const priced = rates ? { rates } : {};
|
|
65
|
+
/** @type {{label: string, costUsd: number|null, unpricedRounds: number}[]} */
|
|
66
|
+
const calls = [];
|
|
67
|
+
let attempts = 0;
|
|
68
|
+
const record = (/** @type {any} */ r) => {
|
|
69
|
+
const call = { label: NOTE_CALL_LABEL, ...priceOf(r) };
|
|
70
|
+
calls.push(call);
|
|
71
|
+
const raw = scrubRaw({ label: NOTE_CALL_LABEL, attempt: attempts, text: r?.text });
|
|
72
|
+
onCall({ ...call, raw: raw.text, ...(r?.thinkingStatus === undefined ? {} : { thinkingStatus: r.thinkingStatus }) });
|
|
73
|
+
};
|
|
74
|
+
const failed = (/** @type {string} */ reason) => ({ state: /** @type {'failed'} */ ('failed'), answers: /** @type {Map<number, 'yes'|'no'>} */ (new Map()), reason, calls });
|
|
75
|
+
const content = notePrompt(lines);
|
|
76
|
+
let malformed = 0;
|
|
77
|
+
let transportRetried = false;
|
|
78
|
+
let rateRetried = false;
|
|
79
|
+
for (;;) {
|
|
80
|
+
if (capStop({ ceilingUsd, ...tallyCalls(calls) })) return failed('the note question was not asked: the spend ceiling was reached');
|
|
81
|
+
attempts += 1;
|
|
82
|
+
const loop = createLoop({ system: NOTE_SYSTEM, onLlmResult: undefined, provider, ...priced });
|
|
83
|
+
/** @type {any} */
|
|
84
|
+
let r;
|
|
85
|
+
try {
|
|
86
|
+
r = await loop.run([{ role: 'user', content }], [], { cacheMessages: true, maxTokens, timeoutMs: callTimeout, ...callOptions });
|
|
87
|
+
} catch (e) {
|
|
88
|
+
if (isRateLimited(e) && !rateRetried) {
|
|
89
|
+
const wait = rateLimitWaitMs(e);
|
|
90
|
+
if (wait !== null) { rateRetried = true; await sleep(wait); continue; }
|
|
91
|
+
}
|
|
92
|
+
const casualty = callCasualty(e) ?? (isTransportFailure(e) ? String(/** @type {any} */ (e)?.message ?? e) : null);
|
|
93
|
+
if (casualty === null) throw e;
|
|
94
|
+
record({ error: casualty });
|
|
95
|
+
if (!transportRetried) { transportRetried = true; continue; }
|
|
96
|
+
return failed(`the note question call failed: ${redactSecrets(casualty)}`);
|
|
97
|
+
}
|
|
98
|
+
record(r);
|
|
99
|
+
if (isOutputCutOff(r)) return failed('the note question answer was cut off');
|
|
100
|
+
if (r?.error) return failed(`the note question call failed: ${redactSecrets(String(r.error))}`);
|
|
101
|
+
const d = decideNote(r?.text, lines);
|
|
102
|
+
if (d) return { state: 'answered', answers: d, reason: null, calls };
|
|
103
|
+
malformed += 1;
|
|
104
|
+
if (malformed >= 2) return failed('the note question answer was not readable twice');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The drafting step: when the block has a facts-only line (and a `noteFn`), make the ONE call, then let code decide through `block.setNotes`. No facts-only line, or no `noteFn`: no call, nothing changes.
|
|
110
|
+
* A failed call leaves the lines facts-only, each with its Not checked row. Returns the calls made (for the drafting book).
|
|
111
|
+
* @param {{block: import('./checkblock.js').CheckBlock, jobLines: {n: number, text: string}[], noteFn: Function|null, ceilingUsd?: number|null, onCall?: Function, onPhase?: (name: string, data: any) => void}} o
|
|
112
|
+
* @returns {Promise<{label: string, costUsd: number|null, unpricedRounds: number}[]>}
|
|
113
|
+
*/
|
|
114
|
+
export async function askNotes({ block, jobLines, noteFn, ceilingUsd = null, onCall = () => {}, onPhase = () => {} }) {
|
|
115
|
+
if (typeof noteFn !== 'function') return [];
|
|
116
|
+
const only = block.factOnlyLines();
|
|
117
|
+
if (only.length === 0) return [];
|
|
118
|
+
onPhase('note-ask', { lines: only.length });
|
|
119
|
+
const nr = await noteFn({ lines: jobLines.filter((l) => only.includes(l.n)).map((l) => ({ n: l.n, text: l.text })), ceilingUsd, onCall });
|
|
120
|
+
const answers = only.map((n) => ({ line: n, answer: /** @type {'yes'|'no'|'failed'} */ (nr.state === 'answered' ? (nr.answers.get(n) ?? 'failed') : 'failed') }));
|
|
121
|
+
block.setNotes(answers);
|
|
122
|
+
onPhase('note-answered', { state: nr.state, answers, reason: nr.reason ?? null });
|
|
123
|
+
return nr.calls ?? [];
|
|
124
|
+
}
|
package/src/pagedry.js
CHANGED
|
@@ -114,6 +114,30 @@ export async function dryReadMoney(text, facts) {
|
|
|
114
114
|
return { facts: kept, dropped, reads, results };
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* The page's RESULT LINES: the lines the given money facts read (`moneyResultLines`), each quote once. Empty when no money fact reads a line (the result lines are then unknown).
|
|
119
|
+
* The one owner of "what is a result row" for phrase facts, shared by the dry read below and by the check list's `!` rows (`phraseInNoResult`).
|
|
120
|
+
* @param {string} text @param {KeptFact[]} facts @returns {string[]}
|
|
121
|
+
*/
|
|
122
|
+
export function resultQuotes(text, facts) {
|
|
123
|
+
/** @type {Set<string>} */
|
|
124
|
+
const quotes = new Set();
|
|
125
|
+
for (const k of facts) if (k.shape === 'money') for (const r of moneyResultLines(text, k)) quotes.add(r.quote);
|
|
126
|
+
return [...quotes];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Is this phrase in the page but in NONE of its result lines (the `phrase-no-result` case)? Sync, for a `!` row the check list is about to build.
|
|
131
|
+
* True only when result lines exist and no line holds the words (case and spacing aside, a plain substring: it never refuses a phrase the run's presence check could pass).
|
|
132
|
+
* With no result line known nothing is guessed (false).
|
|
133
|
+
* @param {string} text @param {KeptFact[]} moneyFacts the line's money facts @param {string} words @returns {boolean}
|
|
134
|
+
*/
|
|
135
|
+
export function phraseInNoResult(text, moneyFacts, words) {
|
|
136
|
+
const rows = resultQuotes(text, moneyFacts);
|
|
137
|
+
const w = words.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
138
|
+
return rows.length > 0 && w !== '' && !rows.some((q) => q.replace(/\s+/g, ' ').toLowerCase().includes(w));
|
|
139
|
+
}
|
|
140
|
+
|
|
117
141
|
/**
|
|
118
142
|
* The same "can it read" for PHRASE facts (hamr ruled 3a, run m10-walk-flights-3: "Rome" was on the page only in "Track prices from Madrid to
|
|
119
143
|
* Rome" switches, in none of the 18 result lines, so no result could ever say it). A kept phrase fact is read against the page's RESULT LINES =
|
|
@@ -125,9 +149,7 @@ export async function dryReadMoney(text, facts) {
|
|
|
125
149
|
*/
|
|
126
150
|
export async function dryReadPhrases(text, facts) {
|
|
127
151
|
const sha = createHash('sha256').update(text).digest('hex');
|
|
128
|
-
|
|
129
|
-
const quotes = new Map();
|
|
130
|
-
for (const k of facts) if (k.shape === 'money') for (const r of moneyResultLines(text, k)) quotes.set(r.quote, true);
|
|
152
|
+
const quotes = resultQuotes(text, facts);
|
|
131
153
|
/** @type {KeptFact[]} */
|
|
132
154
|
const kept = [];
|
|
133
155
|
/** @type {Dropped[]} */
|
|
@@ -135,10 +157,10 @@ export async function dryReadPhrases(text, facts) {
|
|
|
135
157
|
/** @type {Record<string, number>} */
|
|
136
158
|
const reads = {};
|
|
137
159
|
for (const k of facts) {
|
|
138
|
-
if (k.shape !== 'phrase' || quotes.
|
|
160
|
+
if (k.shape !== 'phrase' || quotes.length === 0 || !k.words.length) { kept.push(k); continue; }
|
|
139
161
|
const fact = { name: k.name, shape: 'phrase', phrase: k.words[0] };
|
|
140
162
|
let n = 0;
|
|
141
|
-
for (const quote of quotes
|
|
163
|
+
for (const quote of quotes) {
|
|
142
164
|
const params = { step: 1, parts: [{ text: 'dry read', class: 'fact', source: SOURCE, covers: [1], facts: [fact] }] };
|
|
143
165
|
const g = await gradeStep({ params, bytes: JSON.stringify({ results: [{ quote, values: {} }] }), outputBytes: null, inputs: { [SOURCE]: text } }, { [SOURCE]: sha });
|
|
144
166
|
if (g.verdict === 'green') n += 1;
|
package/src/pagemap.js
CHANGED
|
@@ -221,9 +221,18 @@ export const stripAgreeLead = (text) => {
|
|
|
221
221
|
|
|
222
222
|
/** the words of a reading ask: the ONE spelling, and {@link readingOfQuestion} reads it back (the Result tab's "(you confirmed)") */
|
|
223
223
|
const READING_HEAD = ' I read it as: ';
|
|
224
|
-
const
|
|
224
|
+
const READING_ASKED = '. Agree?';
|
|
225
|
+
/** the part of a reading ask that tells the CLI's typed words (the panel's question box shows the question without it: src/questionbox.js) */
|
|
226
|
+
const READING_ANSWER = ' Answer "agree"';
|
|
227
|
+
const READING_TAIL = `${READING_ASKED}${READING_ANSWER}`;
|
|
228
|
+
/** @param {number} n @returns {string} the rest of a reading ask after its answer words */
|
|
229
|
+
const readingRest = (n) => `, or type your own reading (your answer replaces that ~ rule on line ${n}).`;
|
|
230
|
+
/** @param {number} n @returns {string} the answer words a reading ask ends with (said once, here, and cut in the panel) */
|
|
231
|
+
export const readingTail = (n) => `${READING_ANSWER}${readingRest(n)}`;
|
|
232
|
+
/** @param {number} n @returns {string} the answer words a can't-check ask ends with (said once, here, and cut in the panel) */
|
|
233
|
+
export const cantCheckTail = (n) => ` Answer "${DROP_IT}", or type how to check it (your answer replaces that ~ rule on line ${n}).`;
|
|
225
234
|
/** @param {number} n @param {string} rule @param {string} reading @returns {string} */
|
|
226
|
-
const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_TAIL}
|
|
235
|
+
export const readingQuestion = (n, rule, reading) => `Your line ${n} says "${rule}".${READING_HEAD}${reading}${READING_TAIL}${readingRest(n)}`;
|
|
227
236
|
/** @param {unknown} q a recorded question @returns {string|null} the reading a reading ask proposed, or null when it was another kind of question */
|
|
228
237
|
export function readingOfQuestion(q) {
|
|
229
238
|
const s = String(q ?? '');
|
|
@@ -232,6 +241,9 @@ export function readingOfQuestion(q) {
|
|
|
232
241
|
return a >= 0 && b > a ? s.slice(a + READING_HEAD.length, b) : null;
|
|
233
242
|
}
|
|
234
243
|
|
|
244
|
+
/** @param {number} n @param {string} rule @returns {string} the can't-check ask of a rule the page cannot check */
|
|
245
|
+
export const cantCheckQuestion = (n, rule) => `Your line ${n} says "${rule}". I can't check this on the page. Drop it?${cantCheckTail(n)}`;
|
|
246
|
+
|
|
235
247
|
/**
|
|
236
248
|
* PRD v1.107 Part 5b ("the look reads, code asks"): the early asks CODE forces before any paid drafting, from the look's own result. Every `~` rule is
|
|
237
249
|
* one of three kinds:
|
|
@@ -277,7 +289,7 @@ export function askableFromLook(look, jobLines) {
|
|
|
277
289
|
seen.add(key);
|
|
278
290
|
cants.push({
|
|
279
291
|
line: l.n, rule: n, source: 'look', ask: 'cant-check', ruleText: rule,
|
|
280
|
-
question:
|
|
292
|
+
question: cantCheckQuestion(l.n, rule),
|
|
281
293
|
});
|
|
282
294
|
});
|
|
283
295
|
}
|
package/src/pagerules.js
CHANGED
|
@@ -237,6 +237,18 @@ function pageDecimal(lines, signs) {
|
|
|
237
237
|
/** the shapes that read a value after a label */
|
|
238
238
|
const VALUE_SHAPES = ['money', 'time', 'number', 'date'];
|
|
239
239
|
|
|
240
|
+
/**
|
|
241
|
+
* The ONE owner of a label's separator: the label as the page writes it. The run's checker reads a value right after the signed label, so a page that
|
|
242
|
+
* writes "Departure time: 10:24 AM." can only be read by the label "Departure time:". When EVERY place the page holds the label has a colon right after
|
|
243
|
+
* it, the label is signed with that colon; one bare place leaves it as the look gave it. A plain count of the page's own text, no pattern.
|
|
244
|
+
* @param {string} text the frozen page text @param {string} label a label as normLabel leaves it @returns {string}
|
|
245
|
+
*/
|
|
246
|
+
export function withColon(text, label) {
|
|
247
|
+
if (label.endsWith(':')) return label;
|
|
248
|
+
const n = countExact(text, label);
|
|
249
|
+
return n >= 1 && countExact(text, `${label}:`) === n ? `${label}:` : label;
|
|
250
|
+
}
|
|
251
|
+
|
|
240
252
|
/** the full month names of each language a date may be signed in (bareguard 0.27 reads these and short forms; one full name on the page proves the language is the page's) */
|
|
241
253
|
const MONTHS_FULL = /** @type {Record<string, string[]>} */ ({
|
|
242
254
|
en: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'],
|
|
@@ -353,9 +365,12 @@ export function applyPageRules(text, mapping, jobLines) {
|
|
|
353
365
|
const asListed = [];
|
|
354
366
|
/** U1: labels the page writes after the number */
|
|
355
367
|
const moved = [];
|
|
356
|
-
for (const
|
|
357
|
-
const
|
|
358
|
-
if (!
|
|
368
|
+
for (const w00 of words) {
|
|
369
|
+
const base = normLabel(w00);
|
|
370
|
+
if (!base) continue;
|
|
371
|
+
// a label the page always writes with a colon right after it ("Departure time: 10:24 AM.") is signed as the page writes it (run mwgsl7zx)
|
|
372
|
+
const w = withColon(text, base);
|
|
373
|
+
const w0 = w === base ? w00 : w;
|
|
359
374
|
if (countExact(text, w) < 1) { asListed.push(w0); drop(f, w0, 'not-on-page'); continue; }
|
|
360
375
|
if (amount) {
|
|
361
376
|
const { B, A } = beforeAfter(lines, w);
|