bareloop 0.53.0 → 0.54.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 +26 -0
- package/bareloop.context.md +9 -5
- package/package.json +2 -2
- package/src/authorflow.js +33 -3
- package/src/authoring.js +30 -2
- package/src/authorjob.js +4 -0
- package/src/carrystore.js +4 -1
- package/src/declaredclose.js +1 -1
- package/src/kinds.js +4 -2
- package/src/panel/handed.js +92 -0
- package/src/panel/index.html +225 -120
- package/src/panel/jobplan.js +6 -1
- package/src/panel/server.js +25 -8
- package/src/plan.js +38 -1
- package/src/planrun.js +192 -38
- package/src/ralph.js +2 -0
- package/src/tools.js +65 -6
- package/types/authorflow.d.ts +54 -1
- package/types/panel/handed.d.ts +38 -0
- package/types/panel/jobplan.d.ts +2 -1
- package/types/plan.d.ts +19 -1
- package/types/planrun.d.ts +44 -1
- package/types/tools.d.ts +25 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,32 @@ All notable changes to bareloop are documented here. Format:
|
|
|
5
5
|
[SemVer](https://semver.org/spec/v2.0.0.html). Pre-1.0: **minor** = a ladder rung or
|
|
6
6
|
feature lands, **patch** = docs, fixes, scaffolding.
|
|
7
7
|
|
|
8
|
+
## [0.54.0] - 2026-11-03
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **A worker that ends a try in text without writing is nudged once (F282).** When a writeable step's (or the fix loop's) ask finishes with text and the gate audit holds no allowed write or edit for it, the same conversation is continued once with one fixed message (`TEXT_ONLY_NUDGE`: "You ended without writing any file. Make the change now with your write or edit tool; do not reply in text."). The nudge round is inside the same try, metered like every other round, and honours the money cap, the wall clock, Stop and the round limit; read-only steps are never nudged and nothing is forced (no `toolChoice`). A new spine record `worker-text-only` stores the worker's last text (secret-masked, up to 2,000 characters, `truncated`) with `nudged` and `nudgeWrote`; the Audit marks a nudged try "nudged" in its grid header. Test-proven only; not seen live.
|
|
13
|
+
- **An always-on guard can cover a job line (F281).** A drafted close may list `guardLines: [{guard, lines}]` beside its stages, so a job line the mandatory guards fully do (for example "fix the cause in src/, no suppression comments") needs no duplicate stage and no refusal; the validator checks the link names a real guard and real lines, the drafter is told the guards exist and shown a legal example, and the plan card shows "check - always-on: <guard>" under the line. Specs without the field are unchanged.
|
|
14
|
+
- **The Audit shows the memo and the learnings where they were passed (F274).** The `carry-note` spine record now carries the memo text itself (secret-masked, up to 12,000 characters per ask), and the Audit tab shows it as a closed fold "Memory this worker got" under the part and try that received it; the learnings the planner got show as a fold on the drafting/plan part and the first replan part. The bottom "What the planner was told" box is gone (no text shown twice). Runs from before this change read "not saved (older run)". Matched by recorded phase, iteration and spine order, never by timestamp.
|
|
15
|
+
- **bare-agent `^0.59.0` bad-call handling (BA-29; F265, F266, F267).** The worker Loop turns on `checkArgs` (an object where a string was declared is refused before the tool runs, with the corrected hint). A new spine record `worker-bad-calls` names each bad call from bare-agent's structured `badCalls`/`cutOff` (kind, tool, param, expected, got, size, `hasAppend`, round); `worker-malformed-tool-call` is no longer lost on a round cut at the output cap. The next attempt's note says what was cut or refused (write in parts with `append`, decide sooner when reasoning dominates, send JSON as text). Test-proven only; not seen live.
|
|
16
|
+
- **`pairEditGrant` (F271, B2 safety net).** A plan step granting `write` without `edit` is paired with `edit` by code at the draft, replan and resume sites, only when the signed ceiling offers `edit` and never for a rubric step-file step. Internal (not exported). Test-proven, including the three live gutting plans as a fixture; not seen live.
|
|
17
|
+
|
|
18
|
+
- **BA-30 `shrinkGuard` on every worker (F272, F276).** A whole-file `write` that would cut a file tracked at the seed to under half its size (and at least 2 KB) is refused with the file unchanged, and the worker is told to use `edit`, `append:true` or `content:''`. "Tracked at seed" is the files at HEAD at the start of the leg, read from the worker tree for every job (command, declared or rubric close), compared in real-path form (a symlinked parent or root cannot launder a path); a file the worker creates later is not guarded; a resumed leg counts what earlier legs committed as tracked. The authoring scout has no write tool and takes no guard.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **`seedListing` reads `git ls-tree -z`** so file names with non-ASCII bytes list as themselves, not C-quoted (F276).
|
|
23
|
+
- **Planner and persona wording (F271, B).** `EXIT_EXAMPLE` now teaches the read-only look-around step shape (tools read, grep with an `artifact-written` exit on an existing file); the two persona lines say "the file-changing tool you were given" instead of "the write tool", a tool a look-around step does not hold. Drafter-only POC (prereg `docs/logs/PLANWORDING-PREREG.md`): a leaning, 7 drafts per arm.
|
|
24
|
+
- **Gate audit write/edit rows record `valueType` and UTF-8 `bytes`** (F267): an object content no longer reads as 15 bytes and non-ASCII text is no longer under-counted.
|
|
25
|
+
- **Plain panel words for a stuck refused-argument loop**: the Ended block names what the model did instead of "(code: interpreter-red)"; the terminal outcome is unchanged (the escalation record gains `badCall`).
|
|
26
|
+
- **Panel caption looks, carried from fwdloop (hamr's request).** Chat job card field captions are accent pills (no left bar); the `[n]` numbers are gone from both tab rows; field captions elsewhere (global label, Settings money labels) are 12px bold accent, with checkbox/radio labels unchanged; the Runs tab section captions are colour bars with a count pill (Needs you amber, Running now teal, Scheduled blue, Jobs grey) and a divider between Jobs cards; the Run tab ENDED/NEXT/SCHEDULE labels and the Summary and Map captions are accent bold. Not carried (no such element here): the Ask door/evidence headings, the Result grid headings (the Result tab uses boxes). Look only; checked by screenshot at desktop width, not at phone width.
|
|
27
|
+
- **Run summary row labels are blue bold (hamr, 2026-11-03).** The `model:`, `steps:`, `why:`, `close:`, `tools:`, `calls:`, `checks:` and `cache:` labels in the Run tab SUMMARY box wear the accent colour and bold, like ENDED / NEXT / SCHEDULE; values unchanged. Scoped to the Run summary; the Import box keeps its faint labels. Look only.
|
|
28
|
+
- **Chat New job card pills say what is required (hamr, 2026-11-03; fwdloop 0ae68fb pattern).** A small grey `required` sits inside the caption pill of Job name, The job, Inputs, Destination and Cap $ — the five fields `validateJobCard` refuses when empty; Model, Check type and Time cap carry none. Look only.
|
|
29
|
+
- **Audit tab caption words are blue (hamr, 2026-11-03; fwdloop e637bb8).** In the Audit / logs tab the table header cells (check grid, Flat table, drafting, door and rounds tables), the `errors` and `rounds per try` captions, the `try N` labels in the errors list and the row labels of the schedule and learnings tables wear the accent colour (bold where they were not already). Scoped to `#audit-body`; values, the `[ +N more lines ]` buttons and the red/green marks are unchanged. Look only.
|
|
30
|
+
- **Runs tab search block is a light card (hamr, 2026-11-03; fwdloop V1).** The dashed line above search is gone; the "search also finds Scheduled" note (accent bold, SEARCH caption) and the search box sit together on one tinted card with rounded corners, the box has a 1px accent border and a focus ring. CSS only. Checked by screenshot at 1280 and 390 widths (no horizontal scroll), light and dark.
|
|
31
|
+
- **Audit grid shows what a worker was told as a `told in this run` row, like fwdloop (hamr, 2026-11-03; fwdloop 1574dcb).** In a step's or the fix loop's check grid, a row under the header has one `[ N lines ]` button per try that was handed the carry memo and a dash for a try that was not; a click opens the exact saved text under `errors` (8 lines, then `[ +N more lines ]`), a second click closes it. This replaces the per-try "Memory this worker got" folds in grids. A run with no saved memo text (older run) draws no row. The learnings stay a fold on the planner part (the planner, not a step try, is what gets them), so there is no `told from earlier runs` row. A try outside a grid (single-attempt step, the fix loop's cut-off try) keeps the old fold.
|
|
32
|
+
- bare-agent pin `^0.55.0` to `^0.59.0` (clean-install peers checked: bareguard 0.27.0 deduped).
|
|
33
|
+
|
|
8
34
|
## [0.53.0] - 2026-11-02
|
|
9
35
|
|
|
10
36
|
### Added
|
package/bareloop.context.md
CHANGED
|
@@ -182,7 +182,7 @@ the step plan at run time (gated by `validatePlan`); the human signs only:
|
|
|
182
182
|
| `jobLines`, `inputs` | optional (P7). `jobLines: [{ n, text, rule, rules? }]` — the person's own numbered job lines, `rule` = their `~` lines joined with `'; '` (`''` when none), `rules` = the same `~` lines as an array BESIDE `rule` (present only when the line has any; must join back to `rule` exactly; the Reuse card prefers it so an example's own `; ` is not cut; an older spec lacking it renders by splitting `rule`); `inputs: [{ n, label, value }]` — line 1 the repo (absolute path), lines 2+ tracked files inside it. Exact fields, numbered 1..n in order | what the Job tab and Reuse show back exactly as typed (the signed `goal` stays the model's confirm sentence, which the worker reads). **A spec without them keeps its `jobSpecHash`** (never rewritten); only NEW jobs carry them, so a new job's `workflowKey` differs from an old one's. `inputs` is OPEN on a reuse (`REUSE_OPEN_SPEC_FIELDS`), so `workflowKey` ignores it; `jobSpecHash` covers it. Parsed by `parseJobBlock` / `parseInputs` (`src/jobblock.js`, one owner for the panel and the CLI) |
|
|
183
183
|
| `verdictType` | `green` \| `soft-green` | declared radio, never inferred (`VERDICT_TYPES`, frozen). **AUTHORING offers both (`MENU_CLASSES`).** `soft-green` has its judged floor (`judged-floor`, signed rubric card + calibration gate) and is the forward path for a job needing judgement, paired with the end-of-run review door. Every `request-red` (e.g. for a locked TOOL verb, not a verdict class) also carries `lib` — the territory the demand lands against, stamped at the emit site (`verdictType` → `bareloop`, a locked tool verb → `bare-agent`): the ledger keys and its `suggestedAsk` seed on it, so a bareloop-catalogue refusal never files as an upstream ask |
|
|
184
184
|
| `close` | **an ORDERED LIST of named stages** `[{ name, cmd, expect, judged?, gapKeep?, offer?, needs?, direction? }, ...]` (PRD v1.28), or a close object (table below) | the destination, the only thing hand-authored; the check menu DERIVES from it (below). The plan flow executes a staged close directly and adapts a bare `predicate` object into a one-stage list; an object close names no command to run, so the plan flow refuses one at runtime as `close-unsupported`. The modern route to a judged or human-decided close is a staged `closeDecl` (`judged-floor` / `human-confirms` stage kinds), not this object form |
|
|
185
|
-
| `closeDecl` | **the AUTHORED close** `{ genre: "TYPES", lang: "js"\|"python", stages: [{ name, kind, params, fromLine? }], notes?, refused? }` | the ALTERNATIVE to `close`, and the point of the close-authoring rung: the user answers an interview and an LLM composes a DECLARATION over kinds whose implementations we own — never a script, never a shell fragment, never a new kind. **`close` and `closeDecl` are alternatives**: declaring both reds `close-duplicated` (two closes are two arbiters). It is HARD-class by construction (`CLASS_BY_CLOSE.declared`), so a locked verdict on one reds `close-hierarchy` as well as `request-red`. The declaration is validated by `validateCloseDecl`; the TREE-GROUNDED half of that gate (the path rule, and the scoped-job derivation that arms the F84 one-population law) is DEFERRED at spec-validation time — a job spec is validated with no repository in hand — and the runner re-runs it GROUNDED against the real seed before any stage and before any token. **Job-line coverage (P7, `checkJobLines` in `validateDeclaration`, $0, fed back through the revise loop):** with `jobLines` handed in, every stage the drafter writes carries `fromLine: [N, ...]` — a non-empty, duplicate-free ARRAY of real job lines, so one check (e.g. the one judged stage) may serve several lines, the mandatory guards carry none, and every numbered line has at least one stage OR a `{line, reason}` in `closeDecl.refused` — a note in `notes` does NOT cover a line (`job-line-uncovered`). `validateCloseDecl`/`validateJob` run it when the spec carries `jobLines`. It stores the counting RULE and never a number (D12): there is no seed field, and `baseline: "seed"` is measured at each run's own HEAD |
|
|
185
|
+
| `closeDecl` | **the AUTHORED close** `{ genre: "TYPES", lang: "js"\|"python", stages: [{ name, kind, params, fromLine? }], notes?, refused?, guardLines? }` | the ALTERNATIVE to `close`, and the point of the close-authoring rung: the user answers an interview and an LLM composes a DECLARATION over kinds whose implementations we own — never a script, never a shell fragment, never a new kind. **`close` and `closeDecl` are alternatives**: declaring both reds `close-duplicated` (two closes are two arbiters). It is HARD-class by construction (`CLASS_BY_CLOSE.declared`), so a locked verdict on one reds `close-hierarchy` as well as `request-red`. The declaration is validated by `validateCloseDecl`; the TREE-GROUNDED half of that gate (the path rule, and the scoped-job derivation that arms the F84 one-population law) is DEFERRED at spec-validation time — a job spec is validated with no repository in hand — and the runner re-runs it GROUNDED against the real seed before any stage and before any token. **Job-line coverage (P7, `checkJobLines` in `validateDeclaration`, $0, fed back through the revise loop):** with `jobLines` handed in, every stage the drafter writes carries `fromLine: [N, ...]` — a non-empty, duplicate-free ARRAY of real job lines, so one check (e.g. the one judged stage) may serve several lines, the mandatory guards carry none, and every numbered line has at least one stage OR a `{line, reason}` in `closeDecl.refused` — a note in `notes` does NOT cover a line (`job-line-uncovered`). `validateCloseDecl`/`validateJob` run it when the spec carries `jobLines`. **`guardLines` (F281):** an optional `[{guard, lines: [N, ...]}]` beside `stages` names the job lines a MANDATORY guard already does (a line fully covered by the always-on checks, e.g. "fix the cause in src/" with "no suppression comments"); the guard stage itself stays the genre's own object and still carries no `fromLine`. A listed line counts as covered (no stage, no `refused` entry needed); `guard` must name a mandatory guard of this close, `lines` must be real job lines, a guard is listed once with a duplicate-free non-empty `lines`, else a `$0` `invalid-value` red fed back through the revise loop. It is kept in the signed `closeDecl` (names and numbers only), and the plan card shows `check - always-on: <guard>` under a covered line. Old specs without it behave as before. It stores the counting RULE and never a number (D12): there is no seed field, and `baseline: "seed"` is measured at each run's own HEAD |
|
|
186
186
|
| `checks` | **RETIRED** (PRD v1.28/v1.32) | hand-authored checks are gone, not merely discouraged: declaring `checks` reds `checks-derived` by name. The check menu is DERIVED from the close's own stages instead — see **Staged close** below. The hazard this removes is measured, not theoretical: job #5's three hand-written checks were re-implementations of three stages the close already ran, and a hand-carved copy can drift LENIENT (the worker passes the operator's ruler and fails the real inspection) |
|
|
187
187
|
| `tools` | optional unique subset of `TOOL_MENU` (14 verbs, below) | the CEILING every plan step's grant must fit inside (omitting it means the full menu — and the hash is taken over that RESOLVED form, so a `TOOL_MENU` widening flips an omitted-`tools` spec's hash and forces a re-sign; see `jobSpecHash`, MED-1); `run` is `LOCKED_TOOLS` and reds `request-red` — locked-but-listed, and the red IS the admission evidence the ledger tallies (a typo stays `invalid-value`). A ceiling of write-class and store-class verbs ONLY reds `invalid-value`: the scout surveys read-only, so it would be handed an empty menu and survey blind |
|
|
188
188
|
|
|
@@ -193,7 +193,7 @@ ships with the grant (`COMPONENT_STRATEGIES` — capability without strategy is
|
|
|
193
193
|
|
|
194
194
|
| component | verbs | class |
|
|
195
195
|
|---|---|---|
|
|
196
|
-
| write | `write` · `edit` | tree writes, judged by the signed `writeScope` fence — `edit` (BA-13) is the anchored exact-once replace and goes through that SAME fence, not a weaker one |
|
|
196
|
+
| write | `write` · `edit` | tree writes, judged by the signed `writeScope` fence — `edit` (BA-13) is the anchored exact-once replace and goes through that SAME fence, not a weaker one **A plan step that grants `write` without `edit` is paired with `edit` by code (F271, `pairEditGrant`, `src/plan.js`):** applied to the validated plan at the draft, replan and resume sites, only when the signed ceiling (`tools`; absent = the full menu) offers `edit`, and never to a rubric step-file step (every declared path under `output/steps/`). The agent never asks for it and the ceiling is never passed, so it cannot widen its own menu; `edit` is judged by the same `writeScope` fence as `write`. `plan-accepted` and `step-start` record the paired grant. `pairEditGrant` is internal (not exported from `src/index.js`); `validatePlan` is unchanged. Test-proven; not yet seen live. **A whole-file `write` that would cut a file tracked at the seed to under half its size (2 KB or more) is refused, file unchanged (BA-30 `shrinkGuard`, F272):** "tracked at seed" is HEAD at the start of the leg (a resumed leg counts what earlier legs committed), compared in real-path form; files the worker creates later, `append:true` and `content:''` are not guarded. Test-proven; not yet seen live. |
|
|
197
197
|
| select | `read` · `grep` · `recall` · `get` · `impact` · `related` · `recent` | read-only; every one is judged as a `read` action by that same fence, so the deny list applies through every door. A walking `grep` is judged per path too (F259): the worker's and the authoring scout's shell tools are built with `gatedShellOptions` (`src/tools.js`: bare-agent `canRead` = the gate's own `allows()`, plus `noFollowSymlinks`), so a root grep skips the arbiter's books instead of reading them |
|
|
198
198
|
| compress | `compress` · `peek` | read-only (a signature tier; a stash's head/tail) |
|
|
199
199
|
| isolate | `stash` · `remember` · `forget` | STORE writes (the `.litectx` store, never the tree) — their own gate action types, so a store park can never be counted as a tree write by the F32 `workerWrites` instrument. **Not read-capable** |
|
|
@@ -652,7 +652,11 @@ are asked after two failed drafts, about a job line.
|
|
|
652
652
|
|
|
653
653
|
**First-read map (EXPERIMENTAL, default off; docs/logs/MAP-PREREG.md).** With `readMap: true` the read shim answers the FIRST `shell_read` of a file in an ask with a map, not the file: header `<path> (<N> lines) — map, not the file:`, one line per named chunk of the LiteCtx index as `symbol start-end` (0-based inclusive, the space `ctx_get` takes; a chunk that contains another named chunk is left out), and a footer saying how to open a part with `ctx_get` or read again for the whole file. Capped at 4,000 characters with a `+N more` line. Only files of 200+ lines that are not test files (`test/`, `tests/`, `__tests__/` segment or `*.test.*`/`*.spec.*` name). The map delivers nothing, so the shim never marks the file delivered; the second read of the same path in the same ask (a new ask resets) is today's read, paged as before. No map, today's read plus a report-only `read-map-skip` record, when: the worker's step lacks `ctx_get` (`no-ctx_get`), the read shim is off (`shim-off`), the file has no index node (`no-index`) or no named chunk (`no-named-chunks`), or the index is older than the file (`stale-index`). The index is built at run start when the switch is on. Off is byte-identical to a build without it.
|
|
654
654
|
|
|
655
|
-
**Carry note (hamr 2026-10-30, M1, F258).** The one note (the former separate handoff note is folded in, 2026-10-31), written by code from the run's own record and appended to the first prompt of every step and fix ask that has something to say (never the scout or the drafter; the first step ask of a run has something to say only when the seed note found a start failure, which rides in as the `at start` entry). It carries facts only, never file content and never a worker's own words, and secrets are masked by the one secret-shape inventory. Under the fixed heading `== What earlier workers in this run did (facts from the record, written by code) ==`: how the last try ended (the bound, if any, then its check result: "Its check failed.", "Its check passed.", "Check not run.") and what it changed; where earlier workers looked (path, line count, times read, line ranges, and ` · functions: <name> <a>-<b>, ...` from the LiteCtx index's named chunks, kept only while the index is fresh for that file, refreshed before each note; 500 characters per file; listings, manifests, docs and config reads are counted in one line, not shown; a file read 3 or more times in a try that ended red with no change carries ` · looked here, no fix made`); searches and what they matched; the edits made in the run (per file, changed-line count and diff hunks, taken from the working tree against the run's start commit, never from the spine); earlier tries folded to one line each, then `Earlier failures (folded):` (each earlier failed check's whole text, masked, indented 4 spaces under `- step "x" try 1 · N similar:`; the last try's failure is left out only when that try failed, since its retry prompt carries it; a failure from a try that was later passed stays). Repeats fold by the learnings Jaccard rule or a shared 6-character prefix. Capped at 12,000 characters (`CAP`, src/carrynote.js), cut in this order: the function ranges on every file line first, then file lines (edited files last), search lines, earlier tries, earlier failures (oldest group first, whole group), then diff hunks one edit at a time, oldest edit first (to 12 lines, then to none), the newest edit's hunk last. The state lives in `<workdir>/.smoke/carry/state.json` (an arbiter book the worker's `fs.deny` covers) and a resumed leg loads it. Each note given is one report-only spine record `{type:'carry-note', phase, iteration, chars, capped, sections:{reads,searches,edits,earlier,failures}}` (counts
|
|
655
|
+
**Carry note (hamr 2026-10-30, M1, F258).** The one note (the former separate handoff note is folded in, 2026-10-31), written by code from the run's own record and appended to the first prompt of every step and fix ask that has something to say (never the scout or the drafter; the first step ask of a run has something to say only when the seed note found a start failure, which rides in as the `at start` entry). It carries facts only, never file content and never a worker's own words, and secrets are masked by the one secret-shape inventory. Under the fixed heading `== What earlier workers in this run did (facts from the record, written by code) ==`: how the last try ended (the bound, if any, then its check result: "Its check failed.", "Its check passed.", "Check not run.") and what it changed; where earlier workers looked (path, line count, times read, line ranges, and ` · functions: <name> <a>-<b>, ...` from the LiteCtx index's named chunks, kept only while the index is fresh for that file, refreshed before each note; 500 characters per file; listings, manifests, docs and config reads are counted in one line, not shown; a file read 3 or more times in a try that ended red with no change carries ` · looked here, no fix made`); searches and what they matched; the edits made in the run (per file, changed-line count and diff hunks, taken from the working tree against the run's start commit, never from the spine); earlier tries folded to one line each, then `Earlier failures (folded):` (each earlier failed check's whole text, masked, indented 4 spaces under `- step "x" try 1 · N similar:`; the last try's failure is left out only when that try failed, since its retry prompt carries it; a failure from a try that was later passed stays). Repeats fold by the learnings Jaccard rule or a shared 6-character prefix. Capped at 12,000 characters (`CAP`, src/carrynote.js), cut in this order: the function ranges on every file line first, then file lines (edited files last), search lines, earlier tries, earlier failures (oldest group first, whole group), then diff hunks one edit at a time, oldest edit first (to 12 lines, then to none), the newest edit's hunk last. The state lives in `<workdir>/.smoke/carry/state.json` (an arbiter book the worker's `fs.deny` covers) and a resumed leg loads it. Each note given is one report-only spine record `{type:'carry-note', phase, iteration, chars, capped, sections:{reads,searches,edits,earlier,failures}, text}` (the counts plus the note text itself, secret-masked; the Audit shows `text` under the part and try that received it). Always on, no switch (hamr 2026-11-01): the `carryNote` key in `config.json` is retired (ignored on read, dropped on any config write), a job spec's `handoffNote` is accepted and hashed but has no effect, and `runJob`/`runPlan` take no `carryNote` option; every run builds the store, writes its state and emits its records.
|
|
656
|
+
|
|
657
|
+
**Bad tool calls (bare-agent 0.59, BA-29; F265-F267).** The worker Loop runs with `checkArgs`: a wrong-typed or missing top-level tool argument is refused BEFORE the tool runs, with `<param> must be a <type>, got <type>` (an object where a string was declared adds "to send JSON, encode it as one string") or `<param> is required`; the refusal counts toward bare-agent's identical-error stop. Spine records: `worker-bad-calls {phase, iteration, calls:[{kind: arg-type|arg-missing|cut-off|malformed-json, tool, param?, expected?, got?, argBytes?, parsed?, hasAppend, round}], cutOff?:{outputTokens, reasoningTokens, maxTokensRequested}}` (structured fields only, no arguments and no prose), and `worker-malformed-tool-call` now also fires on a round cut at the output cap. The next attempt's note adds one sentence built from those fields: write in parts with `append:true` for a large cut write (at least 8,000 bytes, `CUT_LARGE_ARG_BYTES`), decide sooner when reasoning tokens are over half of the cut round's output, send JSON as text for an object/array where a string was declared; a cut with nothing known keeps the plain cut-off sentence. A stuck loop of refused arguments is still the terminal `interpreter-red`, but its escalation record carries `badCall {kind, tool, param, expected?, got?}` and the panel's Ended block says what the model did in words. The gate audit's write/edit rows carry `args: {bytes, valueType}`: `bytes` is the UTF-8 byte length (a non-string is measured as the JSON it was sent as), `valueType` the JSON type (`string`, `object`, `array`, `undefined`, ...); before this, an object content read as 15 and bytes were UTF-16 units. Test-proven; not yet seen live.
|
|
658
|
+
|
|
659
|
+
**Text-only ending nudge (F282).** When a writeable step's (or the fix loop's) ask finishes (`end_turn`) with text and the REAL gate audit holds no allowed write or edit for it, the same conversation is continued ONCE with one code-written message (`TEXT_ONLY_NUDGE`, "You ended without writing any file. Make the change now with your write or edit tool; do not reply in text."), same tools, no `toolChoice`, same try and no strike change. It is metered by the same per-round seam and skipped when the attempt is already bounded, the run was stopped, the wall is up or the round limit is reached; read-only steps are never nudged. Spine records: `worker-nudge {phase, iteration, round}` when the nudge is sent, and `worker-text-only {phase, iteration, nudged, nudgeWrote, text, truncated}` once per text-only ending (the last text, secret-masked, cut at 2,000 characters; `truncated` says so); the Audit marks a nudged try. Test-proven; not yet seen live.
|
|
656
660
|
|
|
657
661
|
**Thinking on (per job; hamr 2026-10-11).** The New job card has a "Thinking on" tick under Model, unticked by default, saved in the SIGNED job as the optional
|
|
658
662
|
boolean `thinking` (absent = off; an old spec and any unticked job keep the hash they would have had; a ticked job's `jobSpecHash` and `workflowKey` differ). It
|
|
@@ -1948,7 +1952,7 @@ hand them to the one `Loop` that drives worker, scout and planner rounds; the ru
|
|
|
1948
1952
|
them once. No price on the row = no `rates` key anywhere = the guesstimate above, byte-identical to
|
|
1949
1953
|
before. bareloop keeps no price list of its own, ever.
|
|
1950
1954
|
|
|
1951
|
-
**The provenance is on the record, per round (`rateSource`).** The pinned bare-agent (`^0.
|
|
1955
|
+
**The provenance is on the record, per round (`rateSource`).** The pinned bare-agent (`^0.59.0`)
|
|
1952
1956
|
carries it on every metering payload, and bareloop forwards it VERBATIM (`rateSourceFields`,
|
|
1953
1957
|
`src/planrun.js`): every API `worker-round` (worker, scout, planner, fix loop) carries it beside
|
|
1954
1958
|
`pricing` today — `'caller'` when a customer price is on the key's row, else `'tier'`/`'default'`
|
|
@@ -2765,7 +2769,7 @@ Report-only, counts and a reason, never text, no cost fields, not rounds (spend
|
|
|
2765
2769
|
|
|
2766
2770
|
#### `carry-note` — a carry note handed to a worker ask (`src/carrystore.js`, `src/planrun.js`)
|
|
2767
2771
|
|
|
2768
|
-
One report-only spine record per carry note given: `{type:'carry-note', phase, iteration, chars, capped, sections}`. `phase` is `step:<id>` or `fix`; `chars` is the
|
|
2772
|
+
One report-only spine record per carry note given: `{type:'carry-note', phase, iteration, chars, capped, sections, text}`. `phase` is `step:<id>` or `fix`; `chars` is the length of `text` (at most 12,000); `capped` is true when the cap cut anything; `sections` is `{reads, searches, edits, earlier, failures}`, the COUNT of entries shown in each part; `text` is the exact note handed to the worker (F274, 2026-11-02), run through the one secret mask (`render` masks the whole text, diff hunks included; the emit masks again, idempotent), so `chars` is the masked length. Size cost: up to 12,000 characters per ask on the spine. Records from before 2026-11-02 have no `text`; the Audit reads them as "not saved (older run)". Written right before the ask runs, only for an ask that receives a note; no cost fields, no verdict. Absent only for an ask that has no note to give; there is no switch (the carry memo is always on). The prose rules are under "Carry note".
|
|
2769
2773
|
|
|
2770
2774
|
### `replayRun(spineEvents, auditEvents?, { runId? })` / `formatReplay(summary)` / `summarizeForAllLine(summary)` / `formatAllLines(entries)` — `src/replay.js`
|
|
2771
2775
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bareloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "Workflows that earn their own design, with receipts — agent-authored workflows for repeated, long, verifiable jobs that improve across runs under an un-gameable gate.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"check:lockfile": "node scripts/check-lockfile.mjs"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"bare-agent": "^0.
|
|
30
|
+
"bare-agent": "^0.59.0",
|
|
31
31
|
"barebrowse": "^0.25.0",
|
|
32
32
|
"bareguard": "^0.27.0",
|
|
33
33
|
"litectx": "^0.32.0"
|
package/src/authorflow.js
CHANGED
|
@@ -149,6 +149,9 @@ export function linesNamedByReds(reds, declaration, lineNums) {
|
|
|
149
149
|
if (st && Array.isArray(stages[Number(st[1])]?.fromLine)) {
|
|
150
150
|
for (const n of stages[Number(st[1])].fromLine) if (Number.isInteger(n)) found.add(n);
|
|
151
151
|
}
|
|
152
|
+
const gl = /^guardLines\[(\d+)\]/.exec(String(red?.path ?? ''));
|
|
153
|
+
const guardLines = Array.isArray(declaration?.guardLines) ? declaration.guardLines : [];
|
|
154
|
+
if (gl && Array.isArray(guardLines[Number(gl[1])]?.lines)) for (const n of guardLines[Number(gl[1])].lines) if (Number.isInteger(n)) found.add(n);
|
|
152
155
|
const rf = /^refused\[(\d+)\]/.exec(String(red?.path ?? ''));
|
|
153
156
|
if (rf && Number.isInteger(refused[Number(rf[1])]?.line)) found.add(refused[Number(rf[1])].line);
|
|
154
157
|
}
|
|
@@ -1000,6 +1003,19 @@ export function declarationSchema(catalogue = KIND_CATALOGUE, { verdictType = nu
|
|
|
1000
1003
|
},
|
|
1001
1004
|
description: 'job lines (or single ~ rules of a line) you could not turn into a check, each with a reason in the person\'s words — a note does not cover a line or a rule',
|
|
1002
1005
|
},
|
|
1006
|
+
guardLines: {
|
|
1007
|
+
type: 'array',
|
|
1008
|
+
items: {
|
|
1009
|
+
type: 'object',
|
|
1010
|
+
properties: {
|
|
1011
|
+
guard: { type: 'string', minLength: 1, description: 'the name of a mandatory guard stage' },
|
|
1012
|
+
lines: { type: 'array', minItems: 1, uniqueItems: true, items: { type: 'integer', minimum: 1 }, description: 'the number(s) of the job line(s) that guard already checks' },
|
|
1013
|
+
},
|
|
1014
|
+
required: ['guard', 'lines'],
|
|
1015
|
+
additionalProperties: false,
|
|
1016
|
+
},
|
|
1017
|
+
description: 'optional: which job lines the always-on guards already cover (a line whose every ask a mandatory guard checks needs no stage of its own)',
|
|
1018
|
+
},
|
|
1003
1019
|
...(questions ? {
|
|
1004
1020
|
questions: {
|
|
1005
1021
|
type: 'array',
|
|
@@ -1246,14 +1262,28 @@ export function confirmedBlock(confirmed, { numbered = false } = {}) {
|
|
|
1246
1262
|
* names the ONE numbered job line it serves, or the line is refused with a reason; the mandatory guards serve no line.
|
|
1247
1263
|
* The $0 validator (validateDeclaration, `jobLines`) enforces it and the revise loop feeds a miss back.
|
|
1248
1264
|
* @param {number} count how many numbered job lines the person wrote
|
|
1265
|
+
* @param {string[]} [guardNames] the mandatory guards' names; present = the block also tells how a line they already cover is covered
|
|
1249
1266
|
*/
|
|
1250
|
-
export function jobLineTagBlock(count) {
|
|
1267
|
+
export function jobLineTagBlock(count, guardNames = []) {
|
|
1251
1268
|
return 'EVERY STAGE SERVES ONE JOB LINE\n\n'
|
|
1252
1269
|
+ `The person's job has ${count} numbered line${count === 1 ? '' : 's'} (the interview above). Tag every stage YOU write `
|
|
1253
1270
|
+ 'with "fromLine": [N, ...] — the number(s) of the job line(s) that stage checks (one stage may serve several lines, e.g. a judged stage that reads lines 1-3). A job line that no kind in the catalogue '
|
|
1254
1271
|
+ 'can check is not left out silently: list it in "refused" as {"line": N, "reason": "..."}, with a reason in plain '
|
|
1255
1272
|
+ 'words the person can read. Every numbered line needs at least one stage or one refusal — a note in "notes" does '
|
|
1256
|
-
+ 'NOT cover a line. The mandatory guards serve no job line and carry NO "fromLine".'
|
|
1273
|
+
+ 'NOT cover a line. The mandatory guards serve no job line and carry NO "fromLine".'
|
|
1274
|
+
+ (guardNames.length
|
|
1275
|
+
? '\n\nA job line whose every ask the always-on checks (the mandatory guards) already do needs no stage of its own and no refusal: '
|
|
1276
|
+
+ 'name the guard(s) that do it in "guardLines", beside "stages" — for example {"guardLines": [{"guard": "' + guardNames[0] + '", "lines": [N]}]}. '
|
|
1277
|
+
+ 'Never write a second stage that repeats a guard, and keep "refused" for a line nothing can check.'
|
|
1278
|
+
+ '\n\nTHE ALWAYS-ON CHECKS ALREADY EXIST in this close, in plain words: ' + guardNames.map((n) => n + ' (' + (GUARD_DESCRIPTIONS[n] ?? n) + ')').join('; ')
|
|
1279
|
+
+ '; and the write fence (changes stay inside the write scope). They are already among the guard stages you were given — keep those exactly as given, and NEVER declare any of them again as a stage of your own — '
|
|
1280
|
+
+ 'no second files-changed or scope stage, and no stage that adds scope or params to the suppression guard. A job line they already cover '
|
|
1281
|
+
+ '(for example "Fix the cause in the source code under src/" with the rule "no suppression comments") is linked to them with "guardLines", '
|
|
1282
|
+
+ 'not given a stage and not refused. Legal example for a two-line job whose line 1 is a test run and whose line 2 is covered by the guards: '
|
|
1283
|
+
+ '{"stages": [{"name": "suite-green", "kind": "command-exit", "fromLine": [1], "params": {"cmd": "npm", "args": ["test"], "expectExit": 0}}], '
|
|
1284
|
+
+ '"guardLines": [{"guard": "' + guardNames[0] + '", "lines": [2]}' + (guardNames[1] ? ', {"guard": "' + guardNames[1] + '", "lines": [2]}' : '') + ']} — '
|
|
1285
|
+
+ 'line 2 has no stage of its own and is not refused.'
|
|
1286
|
+
: '');
|
|
1257
1287
|
}
|
|
1258
1288
|
|
|
1259
1289
|
/**
|
|
@@ -1375,7 +1405,7 @@ measure anything.`;
|
|
|
1375
1405
|
`WHAT THE PERSON DECLARED "DONE" TO MEAN — their answer, not yours\n\n${statement}`,
|
|
1376
1406
|
`THE INTERVIEW — the person's own words\n\n${interview}`
|
|
1377
1407
|
+ (inputs && inputs.length ? `\n\n${renderInputs(inputs)}` : ''),
|
|
1378
|
-
...(jobLines && jobLines.length ? [jobLineTagBlock(jobLines.length)] : []),
|
|
1408
|
+
...(jobLines && jobLines.length ? [jobLineTagBlock(jobLines.length, guards.map((g) => g.name))] : []),
|
|
1379
1409
|
// Q2 IS GONE (PRD item 33 M3 piece 3) — what it used to carry (which files
|
|
1380
1410
|
// change, which are read-only) is proven against the machine now, not typed,
|
|
1381
1411
|
// and this is where that proof reaches the composer instead of vanishing.
|
package/src/authoring.js
CHANGED
|
@@ -1537,7 +1537,7 @@ export function validateDeclaration(declaration, opts = {}) {
|
|
|
1537
1537
|
/**
|
|
1538
1538
|
* P7 rules 1-3 of the job block, at $0, in the gate that can still revise: every `fromLine` is a non-empty, duplicate-free array of real job line numbers (one check may serve several lines);
|
|
1539
1539
|
* every numbered job line has at least one stage OR a refusal reason in `refused` (a note in `notes` does NOT cover a
|
|
1540
|
-
* line);
|
|
1540
|
+
* line); a mandatory guard carries no `fromLine` (its object stays the genre's own) and names the lines it already covers in the separate `guardLines`. The SHAPE of `fromLine` / `refused` is checked
|
|
1541
1541
|
* whenever they appear; the coverage half runs only when the person's `jobLines` were handed in.
|
|
1542
1542
|
* @param {{declaration: any, stages: any[], jobLines: {n: number}[]|null|undefined,
|
|
1543
1543
|
* guards: {name: string}[], red: (c: string, p: string, d: string, e?: object) => void}} o
|
|
@@ -1554,7 +1554,7 @@ function checkJobLines({ declaration, stages, jobLines, guards, red }) {
|
|
|
1554
1554
|
const guard = isNonEmptyString(s.name) && guardNames.has(s.name);
|
|
1555
1555
|
if (Object.hasOwn(s, 'fromLine')) {
|
|
1556
1556
|
if (guard) {
|
|
1557
|
-
red('invalid-value', at, `stage "${label}" is a mandatory guard and
|
|
1557
|
+
red('invalid-value', at, `stage "${label}" is a mandatory guard and carries no fromLine — to say it covers a job line, list it in "guardLines" as {"guard": "${label}", "lines": [N]}`);
|
|
1558
1558
|
} else if (!Array.isArray(s.fromLine) || s.fromLine.length === 0 || !s.fromLine.every((/** @type {any} */ x) => Number.isInteger(x) && x >= 1)) {
|
|
1559
1559
|
red('invalid-value', at, `stage "${label}" has fromLine ${JSON.stringify(s.fromLine)} — a non-empty array of job line numbers, e.g. [1] or [1, 3]`);
|
|
1560
1560
|
} else if (new Set(s.fromLine).size !== s.fromLine.length) {
|
|
@@ -1567,6 +1567,34 @@ function checkJobLines({ declaration, stages, jobLines, guards, red }) {
|
|
|
1567
1567
|
+ 'only a mandatory guard carries none');
|
|
1568
1568
|
}
|
|
1569
1569
|
});
|
|
1570
|
+
// a mandatory guard says which job lines its always-on check already covers, beside the stage (the guard's own object stays
|
|
1571
|
+
// byte-identical to the genre's): `guardLines: [{guard, lines: [N, ...]}]`. It counts as coverage for those lines, nothing more.
|
|
1572
|
+
if (declaration.guardLines !== undefined) {
|
|
1573
|
+
if (!Array.isArray(declaration.guardLines)) {
|
|
1574
|
+
red('invalid-value', 'guardLines', 'an array of {guard, lines} — which job lines each always-on guard already covers, e.g. [{"guard": "<a mandatory guard name>", "lines": [2]}]');
|
|
1575
|
+
} else {
|
|
1576
|
+
/** @type {Set<string>} */
|
|
1577
|
+
const seenGuards = new Set();
|
|
1578
|
+
declaration.guardLines.forEach((/** @type {any} */ g, /** @type {number} */ j) => {
|
|
1579
|
+
const at = `guardLines[${j}]`;
|
|
1580
|
+
if (!isObj(g) || !isNonEmptyString(g.guard) || !Array.isArray(g.lines) || g.lines.length === 0
|
|
1581
|
+
|| !g.lines.every((/** @type {any} */ x) => Number.isInteger(x) && x >= 1)) {
|
|
1582
|
+
red('invalid-value', at, '{guard, lines}: the name of a mandatory guard and a non-empty array of job line numbers, e.g. {"guard": "<a mandatory guard name>", "lines": [2]}');
|
|
1583
|
+
} else if (!guardNames.has(g.guard)) {
|
|
1584
|
+
red('invalid-value', `${at}.guard`, `"${g.guard}" is not a mandatory guard${guardNames.size ? ` — the always-on guards are ${[...guardNames].join(', ')}` : ''}`);
|
|
1585
|
+
} else if (seenGuards.has(g.guard)) {
|
|
1586
|
+
red('invalid-value', `${at}.guard`, `guard "${g.guard}" is listed twice in guardLines — give it one entry with all its lines`);
|
|
1587
|
+
} else if (new Set(g.lines).size !== g.lines.length) {
|
|
1588
|
+
red('invalid-value', `${at}.lines`, `guard "${g.guard}" lists a job line twice in ${JSON.stringify(g.lines)}`);
|
|
1589
|
+
} else if (known !== null && g.lines.some((/** @type {number} */ x) => !known.includes(x))) {
|
|
1590
|
+
red('invalid-value', `${at}.lines`, `guard "${g.guard}" has lines ${JSON.stringify(g.lines)}, but the job has lines ${known.join(', ')} only`);
|
|
1591
|
+
} else {
|
|
1592
|
+
seenGuards.add(g.guard);
|
|
1593
|
+
for (const x of g.lines) served.add(x);
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1570
1598
|
/** @type {Set<number>} */
|
|
1571
1599
|
const refused = new Set();
|
|
1572
1600
|
if (declaration.refused !== undefined) {
|
package/src/authorjob.js
CHANGED
|
@@ -867,6 +867,10 @@ export async function authorCloseForJob({
|
|
|
867
867
|
...(authored.declaration.refused?.length
|
|
868
868
|
? { refused: authored.declaration.refused.map((/** @type {any} */ r) => ({ line: r.line, ...(Number.isInteger(r.rule) ? { rule: r.rule } : {}), reason: redactSecrets(String(r.reason)) })) }
|
|
869
869
|
: {}),
|
|
870
|
+
// the lines the always-on guards cover (names and numbers only, nothing free-text)
|
|
871
|
+
...(authored.declaration.guardLines?.length
|
|
872
|
+
? { guardLines: authored.declaration.guardLines.map((/** @type {any} */ g) => ({ guard: g.guard, lines: [...g.lines] })) }
|
|
873
|
+
: {}),
|
|
870
874
|
};
|
|
871
875
|
|
|
872
876
|
// ── THE TWO SIGNED ARTIFACTS (softgreen module 4, wired here by module 5) ──
|
package/src/carrystore.js
CHANGED
|
@@ -226,7 +226,10 @@ export function createCarryStore({ workdir, emit, strikeLimit, resume = false })
|
|
|
226
226
|
const hasAny = notes.events.length || edits.length || notes.earlier.length || notes.failures.length || notes.lastTry;
|
|
227
227
|
if (!hasAny) { save(); return ''; }
|
|
228
228
|
const r = render(/** @type {any} */ (notes));
|
|
229
|
-
|
|
229
|
+
// counts plus the note text itself (F274, so the Audit can show it where it was handed). `render` masked the whole text with the one
|
|
230
|
+
// inventory; the second pass here is idempotent. `chars` = the length of this saved (masked) text.
|
|
231
|
+
const saved = redactSecrets(r.text);
|
|
232
|
+
emit('carry-note', { phase, iteration, chars: saved.length, capped: r.capped, sections: r.sections, text: saved });
|
|
230
233
|
save();
|
|
231
234
|
return r.text;
|
|
232
235
|
};
|
package/src/declaredclose.js
CHANGED
|
@@ -102,7 +102,7 @@ export const DECLARED_GENRES = Object.freeze([TYPES_GENRE.name, TEXT_GENRE]);
|
|
|
102
102
|
* constrained to the names the genre OWNS, so it can never become an environment
|
|
103
103
|
* channel of its own.
|
|
104
104
|
*/
|
|
105
|
-
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'genreEnv', 'calibration']);
|
|
105
|
+
export const CLOSE_DECL_FIELDS = Object.freeze(['genre', 'lang', 'stages', 'notes', 'refused', 'guardLines', 'genreEnv', 'calibration']);
|
|
106
106
|
|
|
107
107
|
/** what a stored calibration set carries, ENUMERATED: the frozen cases and the judge
|
|
108
108
|
* tier that graded them. Both are inside the spec, so `jobSpecHash` covers both — which
|
package/src/kinds.js
CHANGED
|
@@ -541,11 +541,13 @@ export async function seedAtHead(workdir) {
|
|
|
541
541
|
* @returns {Promise<{stop: string, files: null}|{stop: null, files: string[]}>}
|
|
542
542
|
*/
|
|
543
543
|
export async function seedListing(workdir, seedRef) {
|
|
544
|
-
|
|
544
|
+
// `-z`: NUL-separated, names raw. Without it git C-quotes any name with a non-ASCII byte
|
|
545
|
+
// (`"caf\303\251.js"`), so a listing entry would never equal the path on disk (F276 gap c).
|
|
546
|
+
const r = await git(workdir, ['ls-tree', '-r', '-z', '--name-only', seedRef]);
|
|
545
547
|
if (!r.ok) {
|
|
546
548
|
return { stop: `INSTRUMENT: git ls-tree -r ${seedRef} failed in ${workdir}: ${String(r.err).trim()}`, files: null };
|
|
547
549
|
}
|
|
548
|
-
return { stop: null, files: r.out.split('\
|
|
550
|
+
return { stop: null, files: r.out.split('\0').filter(Boolean) };
|
|
549
551
|
}
|
|
550
552
|
|
|
551
553
|
// ── contract (c): the changed-set primitive ──────────────────────────────────
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Where the memory and the learnings were passed on (ITEM33-BUILD addendum 2026-11-02): the Audit shows the carry memo under the
|
|
2
|
+
// worker try that received it, and the learnings text under the planner part that received it. READ-ONLY and pure: the spine's own
|
|
3
|
+
// `carry-note` / `learnings` records, matched by their RECORDED phase and iteration (never by a timestamp window).
|
|
4
|
+
import { parseHintBlock, hintsErrorLine } from '../learn.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One carry-note record as the Audit shows it: `{text, chars, capped}`, or `{missing:true, chars, capped}` for a record from before the
|
|
8
|
+
* text was saved (older run).
|
|
9
|
+
* @param {any} rec @returns {{text: string, chars: number, capped: boolean}|{missing: true, chars: number, capped: boolean}}
|
|
10
|
+
*/
|
|
11
|
+
function memoOf(rec) {
|
|
12
|
+
const chars = typeof rec.chars === 'number' ? rec.chars : 0;
|
|
13
|
+
const capped = rec.capped === true;
|
|
14
|
+
return typeof rec.text === 'string' ? { text: rec.text, chars, capped } : { missing: true, chars, capped };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The carry-note record that belongs to one try. Match = the recorded phase (`step:<id>` is the part's own label, `fix` the fix part),
|
|
19
|
+
* the recorded iteration equal to the try's, and the record's spine order (`seq`) inside the try's own window. The window is needed
|
|
20
|
+
* because a step re-entered after a replan restarts at iteration 1; a try with no iteration (a whole-part fallback) takes the first
|
|
21
|
+
* record of its phase in its window.
|
|
22
|
+
* @param {any[]} recs the run's carry-note records @param {string} phase @param {any} a a try: {iteration?, startSeq, endSeq}
|
|
23
|
+
*/
|
|
24
|
+
function recFor(recs, phase, a) {
|
|
25
|
+
const lo = typeof a.startSeq === 'number' ? a.startSeq : -Infinity;
|
|
26
|
+
const hi = typeof a.endSeq === 'number' ? a.endSeq : Infinity;
|
|
27
|
+
const hit = recs.filter((r) => r.phase === phase && typeof r.seq === 'number' && r.seq > lo && r.seq <= hi
|
|
28
|
+
&& (typeof a.iteration !== 'number' || r.iteration === a.iteration));
|
|
29
|
+
return hit[0] ?? null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Every step part's and fix part's tries (and a cut-off try) gain `memo`: the carry-note record handed to that try, or null; a try whose text-only ending was nudged (spine `worker-text-only`, `nudged: true`) also gains `nudged: true`.
|
|
34
|
+
* Parts and tries are copied, never mutated. An outer-close try (no model call) never has one.
|
|
35
|
+
* @param {any[]|null|undefined} parts @param {any[]} records the run's spine records
|
|
36
|
+
*/
|
|
37
|
+
export function attachMemos(parts, records) {
|
|
38
|
+
if (!Array.isArray(parts)) return parts;
|
|
39
|
+
const recs = records.filter((r) => r?.type === 'carry-note');
|
|
40
|
+
const nudges = records.filter((r) => r?.type === 'worker-text-only' && r.nudged === true);
|
|
41
|
+
if (recs.length === 0 && nudges.length === 0) return parts.map((p) => (p.kind === 'step' || p.kind === 'fix' ? { ...p, attempts: (p.attempts ?? []).map((a) => ({ ...a, memo: null })) } : p));
|
|
42
|
+
return parts.map((p) => {
|
|
43
|
+
if (p.kind !== 'step' && p.kind !== 'fix') return p;
|
|
44
|
+
const phase = p.kind === 'fix' ? 'fix' : `step:${p.label}`;
|
|
45
|
+
const one = (/** @type {any} */ a) => {
|
|
46
|
+
if (a.source === 'outer-close') return { ...a, memo: null };
|
|
47
|
+
const r = recFor(recs, phase, a);
|
|
48
|
+
return { ...a, memo: r ? memoOf(r) : null, ...(recFor(nudges, phase, a) ? { nudged: true } : {}) };
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
...p,
|
|
52
|
+
attempts: (p.attempts ?? []).map(one),
|
|
53
|
+
...(p.cutOffTry ? { cutOffTry: one(p.cutOffTry) } : {}),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The learnings the planner was handed, by injection: `draft` and `replan` (the first replan), each `{phase, text, chars, ids, hints}` or
|
|
60
|
+
* null, plus `error` (the plain line when the learnings file could not be read, else null).
|
|
61
|
+
* @param {any[]} records
|
|
62
|
+
*/
|
|
63
|
+
export function learningsHanded(records) {
|
|
64
|
+
const pick = (/** @type {string} */ phase) => {
|
|
65
|
+
const e = records.find((r) => r?.type === 'learnings' && r.phase === phase && typeof r.text === 'string');
|
|
66
|
+
return e ? { phase, text: e.text, chars: e.text.length, ids: Array.isArray(e.ids) ? e.ids : [], hints: parseHintBlock(e.text) } : null;
|
|
67
|
+
};
|
|
68
|
+
const er = records.find((r) => r?.type === 'learnings' && typeof r.hintsError === 'string');
|
|
69
|
+
return { draft: pick('draft'), replan: pick('replan'), error: er ? hintsErrorLine(String(er.hintsError)) : null };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Put the learnings on the parts that received them: the draft block (and the error line) on the drafting part, else the `plan` part;
|
|
74
|
+
* the first-replan block on the first `replan` part. `drafting` is the drafting part or null. Copies, never mutates.
|
|
75
|
+
* @param {any[]|null|undefined} parts the spine's own parts @param {any|null} drafting @param {ReturnType<typeof learningsHanded>} l
|
|
76
|
+
* @returns {{parts: any[]|null|undefined, drafting: any|null}}
|
|
77
|
+
*/
|
|
78
|
+
export function attachLearnings(parts, drafting, l) {
|
|
79
|
+
const draftExtra = { ...(l.draft ? { learnings: l.draft } : {}), ...(l.error ? { learningsError: l.error } : {}) };
|
|
80
|
+
const hasDraft = Object.keys(draftExtra).length > 0;
|
|
81
|
+
const toDrafting = hasDraft && drafting ? { ...drafting, ...draftExtra } : drafting;
|
|
82
|
+
if (!Array.isArray(parts)) return { parts, drafting: toDrafting };
|
|
83
|
+
let draftDone = !hasDraft || !!drafting;
|
|
84
|
+
let replanDone = !l.replan;
|
|
85
|
+
const out = parts.map((p) => {
|
|
86
|
+
if (!draftDone && p.kind === 'plan') { draftDone = true; return { ...p, ...draftExtra }; }
|
|
87
|
+
if (!replanDone && p.kind === 'replan') { replanDone = true; return { ...p, learnings: l.replan }; }
|
|
88
|
+
return p;
|
|
89
|
+
});
|
|
90
|
+
if (!draftDone && out.length > 0) out[0] = { ...out[0], ...draftExtra }; // no drafting or plan part: the first part, never lost
|
|
91
|
+
return { parts: out, drafting: toDrafting };
|
|
92
|
+
}
|