bareloop 0.10.0 → 0.12.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.
@@ -0,0 +1,81 @@
1
+ /** the door's own record, off the run's spine — the LAST one, because a run that
2
+ * ends at a door writes exactly one and a reader that guesses which is which is a
3
+ * reader that will one day answer the wrong question.
4
+ * @param {any[]} events the run's spine, parsed
5
+ * @returns {any|null} */
6
+ export function doorRecordOf(events: any[]): any | null;
7
+ /**
8
+ * IS THE DOOR STILL OPEN? The same 60-day TTL a hitl checkpoint keeps
9
+ * (`PAUSE_TTL_MS`) and deliberately the same NUMBER — the door replaced `cancel`
10
+ * precisely because an unanswered door and an unresumed pause are one state, and
11
+ * two TTLs for one state is how they come to disagree.
12
+ *
13
+ * An UNREADABLE stamp refuses too: unknown is not young (F6). Reading the age is
14
+ * not the same as deciding on it, so this states both the answer and the arithmetic.
15
+ * @param {any} door the door record
16
+ * @param {{now?: () => number, ttlMs?: number}} [opts]
17
+ * @returns {{ok: boolean, ageMs: number|null, ttlMs: number, detail: string}}
18
+ */
19
+ export function doorAgeGate(door: any, { now, ttlMs }?: {
20
+ now?: () => number;
21
+ ttlMs?: number;
22
+ }): {
23
+ ok: boolean;
24
+ ageMs: number | null;
25
+ ttlMs: number;
26
+ detail: string;
27
+ };
28
+ /**
29
+ * Answer a run's review door.
30
+ *
31
+ * Never throws and never conjures: a malformed decision, a run that opened no
32
+ * door, an expired one, a tree that moved and a registry that is not there all
33
+ * come back as named reds. The loop's verdict is untouched on every path — this
34
+ * function has no way to write one.
35
+ *
36
+ * @param {object} opts
37
+ * @param {any} opts.job the SIGNED spec the run was judged by (its close is what an accept re-proves)
38
+ * @param {string} opts.workdir the patient, as it stands NOW
39
+ * @param {any[]} opts.events the run's own spine, parsed
40
+ * @param {string} opts.decision one of the three doors
41
+ * @param {string|null} [opts.text] the rerun's words — the gap, and refused when empty
42
+ * @param {number} [opts.closeTimeoutMs] the per-stage bound for the accept's re-run
43
+ * @param {string|null} [opts.registryDir] the workflow registry, when the runner keeps one
44
+ * @param {string|null} [opts.name] the workflow this run wrote its row against
45
+ * @param {string|null} [opts.runid] the RUN's id, exactly as the bridge row records it
46
+ * @param {string|null} [opts.at] when the person answered
47
+ * @param {() => number} [opts.now] the clock, injected for the TTL
48
+ * @param {number} [opts.ttlMs]
49
+ * @param {((type: string, data: any) => any)|null} [opts.emit] the run's spine, to record the disposition on
50
+ * @returns {Promise<{ok: boolean, decision: string|null, next: string|null, released: boolean,
51
+ * doorRecorded: boolean, reds: any[], mechanical: any, door: any, text: string|null,
52
+ * options: string[], ttlMs: number, note: string|null}>}
53
+ */
54
+ export function answerReviewDoor({ job, workdir, events, decision, text, closeTimeoutMs, registryDir, name, runid, at, now, ttlMs, emit, }: {
55
+ job: any;
56
+ workdir: string;
57
+ events: any[];
58
+ decision: string;
59
+ text?: string | null | undefined;
60
+ closeTimeoutMs?: number | undefined;
61
+ registryDir?: string | null | undefined;
62
+ name?: string | null | undefined;
63
+ runid?: string | null | undefined;
64
+ at?: string | null | undefined;
65
+ now?: (() => number) | undefined;
66
+ ttlMs?: number | undefined;
67
+ emit?: ((type: string, data: any) => any) | null | undefined;
68
+ }): Promise<{
69
+ ok: boolean;
70
+ decision: string | null;
71
+ next: string | null;
72
+ released: boolean;
73
+ doorRecorded: boolean;
74
+ reds: any[];
75
+ mechanical: any;
76
+ door: any;
77
+ text: string | null;
78
+ options: string[];
79
+ ttlMs: number;
80
+ note: string | null;
81
+ }>;
package/types/run.d.ts CHANGED
@@ -34,6 +34,13 @@
34
34
  * metered claude-json text provider for the toolless drafter); ignored on every Loop-driven provider
35
35
  * @param {(type: string, data?: object) => object} opts.emit spine emitter
36
36
  * @param {(tier: string) => any} [opts.providerFor] P: per-step model-tier provider factory (forwarded to the plan flow)
37
+ * @param {any} [opts.judgeProvider] SOFTGREEN — the provider a JUDGED close stage runs its
38
+ * locate call through, wired by the operator and PINNED to `JUDGE_MODEL` (src/judged.js:
39
+ * the only tier with established injection resistance upstream). Forwarded to the plan
40
+ * flow. It is its own seam and not `provider`/`providerFor`, because the judge tier is
41
+ * never a step knob and never agent-selectable; absent, a judged stage instrument-stops as
42
+ * a wiring gap rather than grading on whatever binding happened to be at hand. Its spend
43
+ * lands on this ledger as `judge-round` (see `ACCOUNTED_ROUND_TYPES`).
37
44
  * @param {number} [opts.capRuns] shell-owned iteration cap for the plan flow's
38
45
  * CLOSE-FIX loop (a plan STEP runs under the strike ladder instead)
39
46
  * @param {number} [opts.strikeLimit] shell-owned strike ceiling for a plan step's ladder
@@ -97,12 +104,31 @@
97
104
  * a manufactured-fixation probe). `true` is the ON/experimental arm; the
98
105
  * default is the OFF arm. (Shell-owned seam, same doctrine as the provider
99
106
  * binding.)
107
+ * @param {{decision: string, text?: string}|null} [opts.humanRuling] N4 — the SIGNER's
108
+ * answer at a hitl pause (accept | rerun <text> | pause), carried by the leg that
109
+ * RESUMES a paused run and forwarded verbatim to the plan flow. Absent on every
110
+ * ordinary run; never authored and never defaulted (a defaulted answer to "is this
111
+ * done?" is the rubber-stamp the class exists to prevent, 2026-08-12 §4).
112
+ * @param {{decision: string, text?: string|null, receivedAt?: string|null}|null} [opts.heldRuling]
113
+ * F102 — the answer the CHECKPOINT holds (`readResume`'s `restart.pendingDecision`):
114
+ * a decision a person already gave on a leg that stopped before a single round was
115
+ * bought for it. Forwarded verbatim; the plan flow applies it exactly as a fresh one
116
+ * and refuses a leg handed both. It is also what decides whether the TIME fold this
117
+ * run declares is the chain's or this engagement's (F103).
118
+ * @param {boolean|null} [opts.reviewDoor] MODULE 8 — does this run END at the review
119
+ * door (PRD v1.71 §3)? Forwarded verbatim to the plan flow, which owns the class
120
+ * default. It changes what the run RECORDS and never what it returns: the door is a
121
+ * disposition and the loop's verdict is not the door's to touch.
122
+ * @param {{text: string, fromRunid?: string|null, receivedAt?: string|null}|null} [opts.doorRerun]
123
+ * MODULE 8 — this leg IS the fresh engagement a signer commissioned at a previous
124
+ * run's review door, carrying their words. Forwarded verbatim.
100
125
  * @returns {Promise<string>} outcome: 'green' | 'already-green' | 'escalated' |
101
126
  * 'unapproved-spec' | 'job-red' | 'smoke-red' | 'plan-red' | 'check-red' |
102
127
  * 'close-red' | 'close-unsupported' | 'recipe-stale' | 'branch-red' | 'pricing-red' | 'provider-red' |
103
- * 'interpreter-red' | 'cap-halt' | 'wall-halt' | 'step-stalled' | `step-red:<id>`
128
+ * 'interpreter-red' | 'cap-halt' | 'wall-halt' | 'step-stalled' |
129
+ * 'hitl-pause' | 'hitl-decision-red' | `step-red:<id>`
104
130
  */
105
- export function runJob(rawSpec: object | string, { approvals, workdir, provider, nativeProvider, providerFor, emit, capRuns, strikeLimit, shellCapUsd, closeTimeoutMs, layerRoot, bridge, priorSpentUsd, priorSpendComplete, priorWallMs, resumeSeed, resumeGrades, resumeReplans, resumeBranch }: {
131
+ export function runJob(rawSpec: object | string, { approvals, workdir, provider, nativeProvider, providerFor, judgeProvider, emit, capRuns, strikeLimit, shellCapUsd, closeTimeoutMs, layerRoot, bridge, priorSpentUsd, priorSpendComplete, priorWallMs, resumeSeed, resumeGrades, resumeReplans, resumeBranch, humanRuling, heldRuling, reviewDoor, doorRerun }: {
106
132
  approvals: unknown;
107
133
  workdir: string;
108
134
  provider: any;
@@ -114,6 +140,7 @@ export function runJob(rawSpec: object | string, { approvals, workdir, provider,
114
140
  }) => any) | undefined;
115
141
  emit: (type: string, data?: object) => object;
116
142
  providerFor?: ((tier: string) => any) | undefined;
143
+ judgeProvider?: any;
117
144
  capRuns?: number | undefined;
118
145
  strikeLimit?: number | undefined;
119
146
  shellCapUsd?: number | undefined;
@@ -133,7 +160,38 @@ export function runJob(rawSpec: object | string, { approvals, workdir, provider,
133
160
  } | null | undefined;
134
161
  resumeBranch?: string | null | undefined;
135
162
  layerRoot?: boolean | undefined;
163
+ humanRuling?: {
164
+ decision: string;
165
+ text?: string;
166
+ } | null | undefined;
167
+ heldRuling?: {
168
+ decision: string;
169
+ text?: string | null;
170
+ receivedAt?: string | null;
171
+ } | null | undefined;
172
+ reviewDoor?: boolean | null | undefined;
173
+ doorRerun?: {
174
+ text: string;
175
+ fromRunid?: string | null;
176
+ receivedAt?: string | null;
177
+ } | null | undefined;
136
178
  }): Promise<string>;
179
+ /** @typedef {{code: string, path: string, detail?: string}} Red */
180
+ /**
181
+ * THE ROUND RECORDS THE ONE LEDGER SUMS — as data, because two of them now exist
182
+ * and a hand-spelled condition per record is how a paid call comes to be free.
183
+ *
184
+ * `worker-round` is the attempt's own spend, metered per ROUND rather than per
185
+ * attempt-return (F12: a halted attempt's spend was invisible by 300×).
186
+ * `judge-round` is the CLOSE's, and it is the first spend a close has ever had:
187
+ * the judged floor (softgreen) buys a pinned locate call per artifact, and the
188
+ * budget-identity rule is that a budget funds the attempt PLUS its close. Both
189
+ * carry the honest `costUsd` — a null lands as `unpriced` and halts, never as $0.
190
+ *
191
+ * What is deliberately NOT here: `worker-result` / `worker-plan`, which are
192
+ * attempt TOTALS of the same rounds and would double-count.
193
+ */
194
+ export const ACCOUNTED_ROUND_TYPES: readonly string[];
137
195
  export type Red = {
138
196
  code: string;
139
197
  path: string;