bareloop 0.53.0 → 0.54.1
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 +34 -0
- package/bareloop.context.md +17 -11
- 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/bridges.js +4 -3
- package/src/carrystore.js +5 -2
- package/src/declaredclose.js +1 -1
- package/src/kinds.js +4 -2
- package/src/launcher.js +7 -4
- package/src/learn.js +6 -4
- 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 +43 -8
- package/src/panel/status.js +3 -1
- package/src/plan.js +38 -1
- package/src/planrun.js +192 -38
- package/src/ralph.js +2 -0
- package/src/replay.js +6 -0
- package/src/reuse.js +3 -3
- package/src/tools.js +65 -6
- package/src/u-readout.js +2 -2
- package/src/userrun.js +1 -1
- package/types/authorflow.d.ts +54 -1
- package/types/bridges.d.ts +4 -3
- package/types/launcher.d.ts +5 -0
- 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/replay.d.ts +3 -0
- package/types/reuse.d.ts +2 -2
- package/types/tools.d.ts +25 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,40 @@ 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.1] - 2026-11-04
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **The review door's held line no longer says a rubric green earns no learning credit.** A rubric run's lessons count at run end (PRD v1.112); only reuse/bridge credit waits for Accept, so `src/u-readout.js` now says "NO reuse credit until you accept it", and `bareloop.context.md` says the same in its two places. The same wording is fixed where Accept's release is described elsewhere: the door's Accept line (`src/u-readout.js`), the run-u HELD line (`src/userrun.js`), the `bridges.js`/`reuse.js` door comments, and the tests pinning them. Also, the learn-ledger climb test's failure message no longer quotes a time figure.
|
|
13
|
+
- **The step a money or time cap escalated reads capped, not failed.** A run that ended capped left its last step's card at `failed` because that step's own `step-end` says `escalated` and carries no stop reason (real spines msi0w2i5 and msx87qqs: the cap's escalation lands just before the step-end). `src/panel/server.js` now gives the run's LAST step part the cap word where the run's verdict is known, and only when that step's own escalation was the cap: a wall-halt reads time cap, a money cap-halt reads money cap (the replay part now carries its `tripped` escalation, with `ladder` when its strike limit ended it). A step its own strike limit escalated stays failed even if the run then ended on the cap (the ladder's stop is also category `cap-halt`, real spine u-mshcpdg4), and so does an earlier escalated step.
|
|
14
|
+
- **`climb` and `foldCards` no longer compare card pairs already in one family.** Same families, levels and groups (checked identical against the old code on 4,000 random ledgers for `climb`, and on 4,300 random and real-shaped card sets for `foldCards`); 2,000 same-lesson rows take about 60 ms instead of about 400 ms, which removes the load flake in `tests/learn-ledger.test.js`. `tests/launcher-stop-deadline.test.js` now uses a fake clock through a new optional `clock` dep of the launcher (default `performance.now`, no change for real callers), so load can no longer flip it.
|
|
15
|
+
|
|
16
|
+
## [0.54.0] - 2026-11-03
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- **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.
|
|
21
|
+
- **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.
|
|
22
|
+
- **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.
|
|
23
|
+
- **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.
|
|
24
|
+
- **`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.
|
|
25
|
+
|
|
26
|
+
- **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.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- **`seedListing` reads `git ls-tree -z`** so file names with non-ASCII bytes list as themselves, not C-quoted (F276).
|
|
31
|
+
- **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.
|
|
32
|
+
- **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.
|
|
33
|
+
- **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`).
|
|
34
|
+
- **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.
|
|
35
|
+
- **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.
|
|
36
|
+
- **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.
|
|
37
|
+
- **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.
|
|
38
|
+
- **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.
|
|
39
|
+
- **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.
|
|
40
|
+
- bare-agent pin `^0.55.0` to `^0.59.0` (clean-install peers checked: bareguard 0.27.0 deduped).
|
|
41
|
+
|
|
8
42
|
## [0.53.0] - 2026-11-02
|
|
9
43
|
|
|
10
44
|
### Added
|
package/bareloop.context.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> facts with quotes from the real artifact, an arbiter-owned `decide()` renders pass/fail from
|
|
6
6
|
> a signed rubric card, and *unsure* is a red, never a pass — bought by a signed calibration
|
|
7
7
|
> gate (ten graded truths, five resisted lies, floor 10/10, itemized reds). A soft-green pass
|
|
8
|
-
> mints its bridge row QUARANTINED: no
|
|
8
|
+
> mints its bridge row QUARANTINED: no reuse credit until an `accept` releases it, forward
|
|
9
9
|
> only; a rerun records a disposition and its outcome is a NEW run's own row, born held
|
|
10
10
|
> again. Every run ends at the signer's **review door** — `accept` / `rerun` / `pause` — which
|
|
11
11
|
> records a disposition and **never changes the loop's own verdict** (`runPlan` still returns
|
|
@@ -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
|
|
@@ -1899,7 +1903,7 @@ Loop path is untouched.
|
|
|
1899
1903
|
**Resume-to-cap (close-first):** the job's close runs FIRST, before any tokens
|
|
1900
1904
|
(`close-precheck` on the spine, output scrubbed at capture like every close). Already-green
|
|
1901
1905
|
is a DISTINCT zero-token outcome, never plain `green`: nothing was done, so it mints no
|
|
1902
|
-
|
|
1906
|
+
reuse credit and runs no on-green retention. A close that cannot RUN is a `broken-close`
|
|
1903
1907
|
escalation before any provider call. So the resume story is: a `cap-halt` or `wall-halt`
|
|
1904
1908
|
stop IS the checkpoint (the workdir + the close), the human raises `budgetUsd` or
|
|
1905
1909
|
`maxWallMs` (a new spec hash — re-sign), and the rerun picks up where the budget died,
|
|
@@ -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'`
|
|
@@ -2142,7 +2146,7 @@ a named `reason`: no `registryDir` (`no-registry` — the registry is operator-s
|
|
|
2142
2146
|
conjured), `outcome !== 'green'` (`green-predates-run` for already-green — accept confirms a
|
|
2143
2147
|
verdict, it never mints one — else `not-green`), and no executed `plan` (`no-plan-executed`,
|
|
2144
2148
|
R1). Every green class mints (hamr's ruling 2026-08-30): a `soft-green` row is born HELD —
|
|
2145
|
-
its
|
|
2149
|
+
its reuse credit is quarantined until a signer accepts at the door — and a `green`-class
|
|
2146
2150
|
row is born RELEASED, because a machine's own close proved it and there was never a credit
|
|
2147
2151
|
to quarantine; `quarantinesCredit(verdictType)` in `greenParts` is the one predicate, read
|
|
2148
2152
|
off the record's own `verdictType`, never a flag. `door-accept` on a released row records
|
|
@@ -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
|
|
|
@@ -2880,7 +2884,9 @@ shares the same seq counter, so it is an exact ordering where two same-milliseco
|
|
|
2880
2884
|
are not), never pooled across every occurrence sharing the id. `rounds` counts real
|
|
2881
2885
|
`worker-round` records (`phase === 'step:<id>'`), never the declared cap; `toolCalls` is the one
|
|
2882
2886
|
thing still windowed by `ts` (the gate-audit carries no `step` or shared `seq`). `tripped` is the
|
|
2883
|
-
last `escalation` whose `seq` falls inside the occurrence's window — `{category, detail}
|
|
2887
|
+
last `escalation` whose `seq` falls inside the occurrence's window — `{category, detail}` (plus `ladder: true`
|
|
2888
|
+
when the escalation is the step ladder's own strike-limit stop, which is also category `cap-halt` but carries
|
|
2889
|
+
`spend.strikes`; a money cap's escalation does not), with
|
|
2884
2890
|
`detail` falling back to `decision` when the escalation site carries no `detail` at all (a
|
|
2885
2891
|
ladder-exhaustion `cap-halt`, `src/ralph.js`, is the measured example — without the fallback the
|
|
2886
2892
|
tripped line would print a bare category and hide the real reason).
|
|
@@ -3674,7 +3680,7 @@ key you want first (the panel picks the row by the Model menu).
|
|
|
3674
3680
|
stopped runs are `no ending recorded` and `you pressed Stop` (each `— resume` when Resume is offered).
|
|
3675
3681
|
Every PART of a run detail (`parts[]`) also carries its own `status` `{key, sign, word}` from the same table
|
|
3676
3682
|
(`partStatusFor`, `src/panel/status.js`): drafting, a green outcome and a part with no verdict and no cut-off → passed; a red
|
|
3677
|
-
outcome → its run-outcome word; a part its leg's halt cut off → capped (money cap / time cap — also a leg that ended `escalated` on a money-halt or wall-halt, and the open step of a single-leg run that ended on a cap), stopped (you stopped it),
|
|
3683
|
+
outcome → its run-outcome word; a part its leg's halt cut off → capped (money cap / time cap — also a leg that ended `escalated` on a money-halt or wall-halt, and the open step of a single-leg run that ended on a cap; and the LAST step part of a run that ended capped when that step's OWN escalation was the cap — its `step-end` reads `escalated` with no stop reason, so `cappedLastStep` in `src/panel/server.js` gives it the cap word, a `wall-halt` escalation reading time cap and a `cap-halt` that is not the ladder's reading money cap; a step its own strike limit escalated, and any earlier escalated step, stays failed), stopped (you stopped it),
|
|
3678
3684
|
died, else failed. A run that DIED (no `job-end`, runner gone) leaves its last part in flight: when that part has no outcome
|
|
3679
3685
|
and no cut-off, the server marks it `died` (`[?] died`), never the "happened, so passed" default — replay alone cannot tell
|
|
3680
3686
|
died from still running, so `getRunDetail` decides it from the same `death` verdict as the run's status. A live run's open
|
|
@@ -4482,7 +4488,7 @@ A **Rubric** job whose first Input is the full path of a FILE (not a repo folder
|
|
|
4482
4488
|
- **Panel topbar.** `bareloop · v<version> · automate a job, verified`: the version is bareloop's own package.json, read once when the panel starts and templated into the page when it is served (`__BARELOOP_PANEL_VERSION__`), so it is the version the process runs, not what package.json says now. Right of the host line and left of Settings sits the online dot (`#online-dot`): the Runs list read (the 10 s poll, no new endpoint or timer) paints green `online` on any HTTP reply, even an error status or a 200 whose body will not parse, and red `offline` only when the read fails with no HTTP status (the panel process is gone); a page render error after a good read never paints it offline.
|
|
4483
4489
|
- **After drafting, the code-worded card is the only plan on screen (run mv5e1ktb).** The confirm turn's plan bubble is the drafter's own prose (written before any close existed) and used to stay in the thread above the code-worded card; when the rubric card is ready the earlier `kind:'plan'` messages are dropped. `partSentence` now reads "1 line" / "1 word" for a count of one.
|
|
4484
4490
|
- **Each `~` guardrail is its own row on the plan card.** `planFromSpec` / `planFromConfirm` lines carry `rules: string[]` (the line's own `rules`, else the joined `rule` split on "; "); `renderJobPlan` draws one `~ rule` row per rule under its numbered line, in the plan card and the Job tab alike (one renderer). Gutter numbers stay on job lines only.
|
|
4485
|
-
- **The review door's held line is true for a no-judge close.** Credit is held by VERDICT CLASS (`quarantinesCredit`: soft-green), whether or not a judge ran; the door now says "this is a rubric (soft-green) job, so its green earns NO reuse
|
|
4491
|
+
- **The review door's held line is true for a no-judge close.** Credit is held by VERDICT CLASS (`quarantinesCredit`: soft-green), whether or not a judge ran; the door now says "this is a rubric (soft-green) job, so its green earns NO reuse credit until you accept it, whether or not a judge ran". Wording only; `bridges.js`/`reuse.js`/the Reuse refusal still say "rendered by the judged floor".
|
|
4486
4492
|
- **A refused drafting try records why.** `authorClose` emits `onPhase('author-try-failed', { call, i, of, reds | reason, declaration? })` for a try refused by validation (the scrubbed reds), by a vacuous or stopped seed read (a `reason`), or by an all-cut-off reply; the panel writes `{kind:'try-refused', no, call, reason, reds?, declaration?}` to `draft-log.jsonl` (`tryRefusedText`, `src/authorreadout.js`, the code's own red details) and shows `<call>: refused — <reason>` on the drafting step's detail line. The CLI prints it via `phaseLine`. The refused declaration itself rides beside it (`declaration`, secrets masked; `declarationText` + `declarationCut` when over 60000 characters), so a failed draft can be read and replayed at $0 (`declarationRecord`).
|
|
4487
4493
|
|
|
4488
4494
|
### Required facts — a line that finds, lists or looks something up (Part 1b, `src/facts.js`, `docs/product/ITEM33-BUILD.md` "Addendum 2026-10-13" and "Part 1c", PRD item 33 RF1–RF22)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bareloop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.1",
|
|
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/bridges.js
CHANGED
|
@@ -50,7 +50,8 @@ export const BRIDGE_SCHEMA = 'bridge-v1';
|
|
|
50
50
|
* SOFTGREEN MODULE 6 — the verdict classes whose greens are minted QUARANTINED.
|
|
51
51
|
*
|
|
52
52
|
* The standing ruling (PRD v1.53, given a mechanism by v1.71 §3): *softgreen
|
|
53
|
-
* passes are quarantined from learning credit until the judged floor is proven
|
|
53
|
+
* passes are quarantined from learning credit until the judged floor is proven*
|
|
54
|
+
* (learning credit = reuse/bridge credit),
|
|
54
55
|
* and **the signer's `accept` at the review door is what releases it**.
|
|
55
56
|
*
|
|
56
57
|
* `soft-green` and NOT `hitl`: the hold is about the young JUDGE, not about every
|
|
@@ -65,7 +66,7 @@ export const QUARANTINED_VERDICTS = Object.freeze(['soft-green']);
|
|
|
65
66
|
* spelling, because three literals is how a hold silently becomes a breakage. */
|
|
66
67
|
export const QUARANTINED_CODE = 'quarantined';
|
|
67
68
|
|
|
68
|
-
/** does a green under this verdict class earn its
|
|
69
|
+
/** does a green under this verdict class earn its reuse credit at the close, or
|
|
69
70
|
* does it wait for a person? Absent/unknown means green's behaviour, byte for byte
|
|
70
71
|
* — the pre-softgreen path is the default and stays untouched.
|
|
71
72
|
* @param {unknown} verdictType @returns {boolean} */
|
|
@@ -525,7 +526,7 @@ export function reuseEligibility(bridge) {
|
|
|
525
526
|
/**
|
|
526
527
|
* THE REVIEW DOOR, written down (PRD v1.71 §3). The person read the finished run
|
|
527
528
|
* and said one of three things; this records that on the run's own row, and — for
|
|
528
|
-
* `accept` on a HELD green — releases the
|
|
529
|
+
* `accept` on a HELD green — releases the reuse credit that green has been
|
|
529
530
|
* carrying unspent.
|
|
530
531
|
*
|
|
531
532
|
* Three properties, and each is a ruling rather than a convenience:
|
package/src/carrystore.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The carry note's store (M1, F258): the run-level record behind src/carrynote.js. It captures the worker's read-class tool
|
|
2
2
|
// calls AT THE SOURCE (the worker's tool objects, result SUMMARIES only, never file
|
|
3
|
-
|
|
3
|
+
// content), reads the run's edits from the WORKING TREE (git diff against the run's start commit, never the spine), renders
|
|
4
4
|
// the note and persists its state under `<workdir>/.smoke/carry/state.json` (an arbiter book: the worker's fs.deny covers
|
|
5
5
|
// `.smoke`, so it cannot read it; the gate audit, spine and bridges live there too). There is no switch: the memo is
|
|
6
6
|
// always on (hamr 2026-11-01).
|
|
@@ -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 ──────────────────────────────────
|
package/src/launcher.js
CHANGED
|
@@ -60,6 +60,7 @@ const RULE_WIDTH = 56;
|
|
|
60
60
|
* @property {((target: string) => Promise<boolean>)} [open] default the shared OS opener
|
|
61
61
|
* @property {(port: number) => Promise<boolean>} [portFree] default: try to bind 127.0.0.1:port
|
|
62
62
|
* @property {(ms: number) => Promise<void>} [sleep]
|
|
63
|
+
* @property {() => number} [clock] monotonic ms clock for stop's wait-until-gone deadlines (default performance.now); tests pass a fake one so load cannot move a deadline
|
|
63
64
|
* @property {(question: string) => Promise<string>} [ask] the y/N and menu reader
|
|
64
65
|
* @property {string} [bareloopBin] default bin/bareloop.mjs of this package
|
|
65
66
|
* @property {import('./tty-colour.js').Paint} [paint] colour for stdout lines (default none); {@link makePaint} decides TTY / NO_COLOR / TERM
|
|
@@ -369,8 +370,9 @@ async function waitFor(d, port, gone) {
|
|
|
369
370
|
const sleep = sleepOf(d);
|
|
370
371
|
const deadline = d.deadlineMs ?? WAIT_DEADLINE_MS;
|
|
371
372
|
// real clock time (CLOCK_MONOTONIC): a probe can take up to its whole timeout, so counting POLL_MS a turn would overshoot the deadline many times over
|
|
372
|
-
const
|
|
373
|
-
|
|
373
|
+
const clock = d.clock ?? (() => performance.now());
|
|
374
|
+
const t0 = clock();
|
|
375
|
+
while (clock() - t0 <= deadline) {
|
|
374
376
|
const found = await probePanels({ ports: [port], timeoutMs: d.timeoutMs, fetchImpl: d.fetchImpl });
|
|
375
377
|
if (gone ? found.length === 0 : found.length > 0) return true;
|
|
376
378
|
await sleep(POLL_MS);
|
|
@@ -501,7 +503,8 @@ export async function stopCmd(args, io, d, shown) {
|
|
|
501
503
|
}
|
|
502
504
|
}
|
|
503
505
|
// the pid being gone is the truth (signal 0: ESRCH = gone, EPERM = alive); the port going quiet is checked after, for those that went
|
|
504
|
-
const
|
|
506
|
+
const clock = d.clock ?? (() => performance.now());
|
|
507
|
+
const t0 = clock();
|
|
505
508
|
const limit = d.deadlineMs ?? WAIT_DEADLINE_MS;
|
|
506
509
|
const sleep = sleepOf(d);
|
|
507
510
|
let pending = panels.slice();
|
|
@@ -509,7 +512,7 @@ export async function stopCmd(args, io, d, shown) {
|
|
|
509
512
|
pending = pending.filter((p) => {
|
|
510
513
|
try { kill(p.pid, 0); return true; } catch (e) { return /** @type {any} */ (e)?.code !== 'ESRCH'; }
|
|
511
514
|
});
|
|
512
|
-
if (pending.length === 0 ||
|
|
515
|
+
if (pending.length === 0 || clock() - t0 > limit) break;
|
|
513
516
|
await sleep(POLL_MS);
|
|
514
517
|
}
|
|
515
518
|
if (pending.length > 0) {
|
package/src/learn.js
CHANGED
|
@@ -526,10 +526,11 @@ export function foldCards(cards) {
|
|
|
526
526
|
const n = cards.length;
|
|
527
527
|
const par = cards.map((_, i) => i);
|
|
528
528
|
const find = (/** @type {number} */ x) => { let r = x; while (par[r] !== r) r = par[r]; par[x] = r; return r; };
|
|
529
|
-
|
|
529
|
+
// a pair already in one family cannot change the families, so its (Jaccard) test is skipped: one big family stays near-linear
|
|
530
|
+
for (let i = 0; i < n; i += 1) for (let j = i + 1; j < n; j += 1) if (find(i) !== find(j) && cardsMatch(cards[i], cards[j]).match) par[find(i)] = find(j);
|
|
530
531
|
/** @type {Map<number, number[]>} */
|
|
531
532
|
const comps = new Map();
|
|
532
|
-
for (let i = 0; i < n; i += 1) { const r = find(i); comps.
|
|
533
|
+
for (let i = 0; i < n; i += 1) { const r = find(i); const f = comps.get(r); if (f) f.push(i); else comps.set(r, [i]); }
|
|
533
534
|
/** @type {Card[][]} */
|
|
534
535
|
const groups = [];
|
|
535
536
|
for (const m of comps.values()) {
|
|
@@ -697,10 +698,11 @@ export function climb(rows) {
|
|
|
697
698
|
const n = rows.length;
|
|
698
699
|
const par = rows.map((_, i) => i);
|
|
699
700
|
const find = (/** @type {number} */ x) => { let r = x; while (par[r] !== r) r = par[r]; par[x] = r; return r; };
|
|
700
|
-
|
|
701
|
+
// a pair already in one family cannot change the families, so its (Jaccard) test is skipped: one big family stays near-linear
|
|
702
|
+
for (let i = 0; i < n; i += 1) for (let j = i + 1; j < n; j += 1) if (find(i) !== find(j) && cardsMatch(rows[i].sample, rows[j].sample, { sameJob: false }).match) par[find(i)] = find(j);
|
|
701
703
|
/** @type {Map<number, number[]>} */
|
|
702
704
|
const fam = new Map();
|
|
703
|
-
for (let i = 0; i < n; i += 1) { const r = find(i); fam.
|
|
705
|
+
for (let i = 0; i < n; i += 1) { const r = find(i); const f = fam.get(r); if (f) f.push(i); else fam.set(r, [i]); }
|
|
704
706
|
/** @type {Row[]} */
|
|
705
707
|
const out = rows.map((r) => ({ ...r, level: 'workflow' }));
|
|
706
708
|
for (const idx of fam.values()) {
|
|
@@ -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
|
+
}
|