bareloop 0.52.0 → 0.53.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 +19 -0
- package/bareloop.context.md +22 -13
- package/package.json +1 -1
- package/src/carrynote.js +38 -12
- package/src/carrystore.js +74 -30
- package/src/config.js +3 -5
- package/src/job.js +16 -4
- package/src/pagedropwords.js +5 -2
- package/src/panel/schedules.js +2 -2
- package/src/planrun.js +53 -42
- package/src/readshim.js +98 -3
- package/src/run.js +2 -5
- package/src/seednote.js +28 -0
- package/src/userrun.js +0 -3
- package/types/carrynote.d.ts +19 -2
- package/types/carrystore.d.ts +5 -9
- package/types/config.d.ts +2 -2
- package/types/planrun.d.ts +3 -6
- package/types/readshim.d.ts +54 -18
- package/types/run.d.ts +1 -5
- package/types/seednote.d.ts +18 -0
- package/src/handoff.js +0 -100
- package/types/handoff.d.ts +0 -39
package/types/readshim.d.ts
CHANGED
|
@@ -26,8 +26,31 @@ export function readShimArm(flag?: boolean | "cap" | "diff" | undefined): ReadSh
|
|
|
26
26
|
* @returns {string}
|
|
27
27
|
*/
|
|
28
28
|
export function readShimStrategy(arm: ReadShimArm): string;
|
|
29
|
-
/**
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The map text for one file, from the index's chunks. Pure. A chunk that CONTAINS another named chunk is left out (a class
|
|
31
|
+
* chunk would hand the whole class to `ctx_get`); the rest are listed by start line as `symbol start-end` in the index's own
|
|
32
|
+
* 0-based inclusive line space, the one `ctx_get` takes. Cut to READ_MAP_CAP characters with a `+N more` line.
|
|
33
|
+
* @param {{rel: string, lines: number, chunks: {symbol?: string|null, startLine: number, endLine: number}[]}} o
|
|
34
|
+
* @returns {{text: string, symbols: number}|null} null when the file has no named part
|
|
35
|
+
*/
|
|
36
|
+
export function buildReadMap({ rel, lines, chunks }: {
|
|
37
|
+
rel: string;
|
|
38
|
+
lines: number;
|
|
39
|
+
chunks: {
|
|
40
|
+
symbol?: string | null;
|
|
41
|
+
startLine: number;
|
|
42
|
+
endLine: number;
|
|
43
|
+
}[];
|
|
44
|
+
}): {
|
|
45
|
+
text: string;
|
|
46
|
+
symbols: number;
|
|
47
|
+
} | null;
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {{root: string, hasGet: boolean, getNode: (rel: string) => any, refresh?: (() => Promise<unknown>)|null, emit: (type: string, data: object) => void}} ReadMapOpts
|
|
50
|
+
* `root`: the job root (paths are made relative to it); `hasGet`: this worker holds `ctx_get` (a map hands out handles only that tool opens);
|
|
51
|
+
* `getNode`: the LiteCtx index's node for a path (its `chunks`); `refresh`: re-index first so the ranges are true to the file as it now is;
|
|
52
|
+
* `emit`: the spine channel, for the report-only `read-map` / `read-map-skip` records (counts and a reason, never text).
|
|
53
|
+
*/
|
|
31
54
|
/**
|
|
32
55
|
* Create the shim: one delivery ledger, and the two seams that speak for it.
|
|
33
56
|
*
|
|
@@ -36,7 +59,7 @@ export function readShimStrategy(arm: ReadShimArm): string;
|
|
|
36
59
|
* reference to the ledger — see its own note. Both live in one object because
|
|
37
60
|
* they are one worker's shim: the read seam and the retrieval seam the cap
|
|
38
61
|
* steers a capped worker towards.
|
|
39
|
-
* @param {{cap?: number, arm?: ReadShimArm, onCount?: ((kind: 'pointered'|'capped', bytesWithheld: number) => void)|null}} [opts]
|
|
62
|
+
* @param {{cap?: number, arm?: ReadShimArm, onCount?: ((kind: 'pointered'|'capped', bytesWithheld: number) => void)|null, readMap?: ReadMapOpts|null}} [opts]
|
|
40
63
|
* `cap`: delivery bound in bytes (the shipped value is `READ_SHIM_CAP`; the option
|
|
41
64
|
* exists so the native path can pin the two bounds to one number rather than two
|
|
42
65
|
* constants drifting apart). `arm`: which levers are live (`readShimArm`). Defaults to
|
|
@@ -47,20 +70,15 @@ export function readShimStrategy(arm: ReadShimArm): string;
|
|
|
47
70
|
* for a diff response (L2 is its own lever, uncounted here) or a first read under the
|
|
48
71
|
* cap (nothing was withheld).
|
|
49
72
|
*/
|
|
50
|
-
export function createReadShim({ cap, arm, onCount }?: {
|
|
73
|
+
export function createReadShim({ cap, arm, onCount, readMap }?: {
|
|
51
74
|
cap?: number;
|
|
52
75
|
arm?: ReadShimArm;
|
|
53
76
|
onCount?: ((kind: "pointered" | "capped", bytesWithheld: number) => void) | null;
|
|
77
|
+
readMap?: ReadMapOpts | null;
|
|
54
78
|
}): {
|
|
55
79
|
arm: ReadShimArm;
|
|
56
80
|
cap: number;
|
|
57
|
-
wrapRead: (tool:
|
|
58
|
-
name: string;
|
|
59
|
-
execute: (args: any) => Promise<any>;
|
|
60
|
-
}) => {
|
|
61
|
-
name: string;
|
|
62
|
-
execute: (args: any) => Promise<any>;
|
|
63
|
-
};
|
|
81
|
+
wrapRead: (tool: any) => any;
|
|
64
82
|
serveStale: ({ file, path, startLine, endLine, detail }: StaleReq) => StaleServe | null;
|
|
65
83
|
summary: () => {
|
|
66
84
|
pointered: number;
|
|
@@ -109,6 +127,31 @@ export const READ_SHIM_STRATEGY: "\nREAD LIMIT: a shell_read of a file over 24KB
|
|
|
109
127
|
* of A1 into A2. The delivery itself carries `diffNotice`'s framing inline; this
|
|
110
128
|
* line exists so the first diff is not a surprise. */
|
|
111
129
|
export const READ_SHIM_DIFF_STRATEGY: "\nRE-READS: if you shell_read a file you have already been shown in full and it has changed since, the result is a unified DIFF against the copy you already hold \u2014 not the file itself. It is labelled as one. Lines starting '-' were removed, '+' were added, ' ' are unchanged context; apply it to the copy you have and you hold the current file.";
|
|
130
|
+
/** @typedef {{file: string, path: string, startLine: number, endLine: number, detail: string}} StaleReq */
|
|
131
|
+
/** @typedef {{text: string, outcome: 'stale-served'|'stale-absent'|'stale-past-eof'}} StaleServe */
|
|
132
|
+
/** a file this long (in lines) or longer gets a map on its first read in an ask */
|
|
133
|
+
export const READ_MAP_MIN_LINES: 200;
|
|
134
|
+
/** the map's size bound, in characters (header, parts, `+N more` line and footer together) */
|
|
135
|
+
export const READ_MAP_CAP: 4000;
|
|
136
|
+
/**
|
|
137
|
+
* `root`: the job root (paths are made relative to it); `hasGet`: this worker holds `ctx_get` (a map hands out handles only that tool opens);
|
|
138
|
+
* `getNode`: the LiteCtx index's node for a path (its `chunks`); `refresh`: re-index first so the ranges are true to the file as it now is;
|
|
139
|
+
* `emit`: the spine channel, for the report-only `read-map` / `read-map-skip` records (counts and a reason, never text).
|
|
140
|
+
*/
|
|
141
|
+
export type ReadMapOpts = {
|
|
142
|
+
root: string;
|
|
143
|
+
hasGet: boolean;
|
|
144
|
+
getNode: (rel: string) => any;
|
|
145
|
+
refresh?: (() => Promise<unknown>) | null;
|
|
146
|
+
emit: (type: string, data: object) => void;
|
|
147
|
+
};
|
|
148
|
+
export type ReadShimArm = {
|
|
149
|
+
on: boolean;
|
|
150
|
+
cap: boolean;
|
|
151
|
+
pointer: boolean;
|
|
152
|
+
diff: boolean;
|
|
153
|
+
g1: boolean;
|
|
154
|
+
};
|
|
112
155
|
export type StaleReq = {
|
|
113
156
|
file: string;
|
|
114
157
|
path: string;
|
|
@@ -120,10 +163,3 @@ export type StaleServe = {
|
|
|
120
163
|
text: string;
|
|
121
164
|
outcome: "stale-served" | "stale-absent" | "stale-past-eof";
|
|
122
165
|
};
|
|
123
|
-
export type ReadShimArm = {
|
|
124
|
-
on: boolean;
|
|
125
|
-
cap: boolean;
|
|
126
|
-
pointer: boolean;
|
|
127
|
-
diff: boolean;
|
|
128
|
-
g1: boolean;
|
|
129
|
-
};
|
package/types/run.d.ts
CHANGED
|
@@ -200,9 +200,6 @@
|
|
|
200
200
|
* round-boundary seam (where the money cap binds) and ends the leg `stopped`. `null` = no stop surface.
|
|
201
201
|
* @param {{text: string, ids: string[]}|null} [opts.learnHints=null] cross-run learnings for the PLANNER only (the draft and the
|
|
202
202
|
* first replan); forwarded verbatim to the plan flow, which records what it handed over as a `learnings` spine record.
|
|
203
|
-
* @param {boolean} [opts.carryNote=false] THE CARRY NOTE (src/carrynote.js): hand each step/fix worker a facts-only note of what earlier
|
|
204
|
-
* workers of this run looked at, searched and changed. The caller reads the one switch (`carryNote` in config.json, src/carrystore.js
|
|
205
|
-
* `carryNoteOn`) once; the library default is off, exactly like `learnHints`. Forwarded verbatim to the plan flow.
|
|
206
203
|
* @returns {Promise<string>} outcome: 'green' | 'already-green' | 'escalated' |
|
|
207
204
|
* 'unapproved-spec' | 'job-red' | 'smoke-red' | 'plan-red' | 'check-red' |
|
|
208
205
|
* 'close-red' | 'close-unsupported' | 'recipe-stale' | 'branch-red' | 'pricing-red' | 'provider-red' |
|
|
@@ -217,7 +214,7 @@
|
|
|
217
214
|
* deliberately NOT in the resumable/checkpoint set (`src/reuse.js`) — an
|
|
218
215
|
* unknown in-flight state is not a known-safe resume point.
|
|
219
216
|
*/
|
|
220
|
-
export function runJob(rawSpec: object | string, { approvals, workdir, provider, nativeProvider, providerFor, judgeProvider, judgeModel, rates, judgeRates, emit, capRuns, strikeLimit, shellCapUsd, closeTimeoutMs, closeDir, layerRoot, readShim, scout, bridge, draftSpentUsd, draftSpendComplete, priorSpentUsd, priorSpendComplete, priorWallMs, resumeSeed, resumeGrades, resumeReplans, resumeBranch, humanRuling, heldRuling, reviewDoor, doorRerun, resumable, stopFile, learnHints
|
|
217
|
+
export function runJob(rawSpec: object | string, { approvals, workdir, provider, nativeProvider, providerFor, judgeProvider, judgeModel, rates, judgeRates, emit, capRuns, strikeLimit, shellCapUsd, closeTimeoutMs, closeDir, layerRoot, readShim, scout, bridge, draftSpentUsd, draftSpendComplete, priorSpentUsd, priorSpendComplete, priorWallMs, resumeSeed, resumeGrades, resumeReplans, resumeBranch, humanRuling, heldRuling, reviewDoor, doorRerun, resumable, stopFile, learnHints }: {
|
|
221
218
|
approvals: unknown;
|
|
222
219
|
workdir: string;
|
|
223
220
|
provider: any;
|
|
@@ -284,7 +281,6 @@ export function runJob(rawSpec: object | string, { approvals, workdir, provider,
|
|
|
284
281
|
text: string;
|
|
285
282
|
ids: string[];
|
|
286
283
|
} | null | undefined;
|
|
287
|
-
carryNote?: boolean | undefined;
|
|
288
284
|
}): Promise<string>;
|
|
289
285
|
/** @typedef {{code: string, path: string, detail?: string}} Red */
|
|
290
286
|
/**
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{stage: string|null|undefined, kind: string|null|undefined, gap: string|null|undefined}[]} reds one entry per preflight verdict
|
|
3
|
+
* that was RED at seed (stage = the stage that rendered it, kind = that stage's declared kind, gap = the verdict's gap text)
|
|
4
|
+
* @param {(s: string) => string} scrub the run's secret mask
|
|
5
|
+
* @returns {{ text: string, body: string, stages: string[] }|null} null when no qualifying stage was red (nothing to say)
|
|
6
|
+
*/
|
|
7
|
+
export function buildSeedNote(reds: {
|
|
8
|
+
stage: string | null | undefined;
|
|
9
|
+
kind: string | null | undefined;
|
|
10
|
+
gap: string | null | undefined;
|
|
11
|
+
}[], scrub: (s: string) => string): {
|
|
12
|
+
text: string;
|
|
13
|
+
body: string;
|
|
14
|
+
stages: string[];
|
|
15
|
+
} | null;
|
|
16
|
+
export const SEED_NOTE_HEADING: "At start, the job's own check said:";
|
|
17
|
+
/** the one stage kind whose text qualifies */
|
|
18
|
+
export const SEED_NOTE_KIND: "count-not-worse";
|
package/src/handoff.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
// The handoff note (F253): a map of the files earlier workers in THIS run read, appended to the next step/fix
|
|
2
|
-
// worker's first prompt. Code-written only, never a model; names files, never carries their content.
|
|
3
|
-
// The switch is the signed spec's `handoffNote` (absent = on, only `false` turns it off; see src/job.js).
|
|
4
|
-
import { readFileSync, statSync } from 'node:fs';
|
|
5
|
-
import { isAbsolute, relative, resolve } from 'node:path';
|
|
6
|
-
import { isArbiterBook } from './kinds.js';
|
|
7
|
-
|
|
8
|
-
/** The one cap on a note, in characters. */
|
|
9
|
-
export const HANDOFF_CAP = 8000;
|
|
10
|
-
export const HANDOFF_HEADING = '== Files earlier workers in this run read (a map only; contents are not included; line ranges as ctx_recall prints them) ==';
|
|
11
|
-
/** Per-entry symbol-map cap, so one huge file cannot eat the whole note. */
|
|
12
|
-
const ENTRY_MAP_CAP = 500;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Is this repo-relative path off limits to a note: outside the job root, an arbiter book (the one list,
|
|
16
|
-
* `isArbiterBook`: .smoke — spine, attempt-diff, bridges — .litectx, the gate audit), or inside `.git` / `.bareloop`.
|
|
17
|
-
* @param {string} rel
|
|
18
|
-
*/
|
|
19
|
-
export function isHandoffExcluded(rel) {
|
|
20
|
-
if (rel === '' || rel === '..' || rel.startsWith('../') || isAbsolute(rel)) return true;
|
|
21
|
-
if (isArbiterBook(rel) !== null) return true;
|
|
22
|
-
return rel.split('/').some((seg) => seg === '.git' || seg === '.bareloop');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Wrap the worker's read-class tools (the real names come from the caller: shell_read, ctx_get) so a call that
|
|
27
|
-
* reached `execute` (the gate already allowed it) and returned a file's text is reported to `onRead`.
|
|
28
|
-
* Wraps in place: tool objects are fresh per worker.
|
|
29
|
-
* @param {{name: string, execute: Function}[]} tools
|
|
30
|
-
* @param {string[]} names
|
|
31
|
-
* @param {(absPath: string) => void} onRead
|
|
32
|
-
* @param {string} workdir
|
|
33
|
-
*/
|
|
34
|
-
export function trackReads(tools, names, onRead, workdir) {
|
|
35
|
-
for (const t of tools) {
|
|
36
|
-
if (!names.includes(t.name)) continue;
|
|
37
|
-
const inner = t.execute;
|
|
38
|
-
t.execute = async (/** @type {any} */ args) => {
|
|
39
|
-
const r = await inner(args);
|
|
40
|
-
if (typeof r === 'string' && typeof args?.path === 'string' && !/^ctx_get failed/.test(r)) {
|
|
41
|
-
const abs = isAbsolute(args.path) ? args.path : resolve(workdir, args.path);
|
|
42
|
-
try { if (statSync(abs).isFile()) onRead(abs); } catch { /* not a file: nothing was read */ }
|
|
43
|
-
}
|
|
44
|
-
return r;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Run-level store of the paths earlier workers read. Newest read last; a re-read moves a path to newest.
|
|
51
|
-
* In memory only: a resumed leg starts empty (the first ask of a resumed leg gets no note, later asks do).
|
|
52
|
-
* @param {{workdir: string}} o
|
|
53
|
-
*/
|
|
54
|
-
export function createHandoffStore({ workdir }) {
|
|
55
|
-
/** @type {Set<string>} insertion order = oldest first */
|
|
56
|
-
const paths = new Set();
|
|
57
|
-
/** @param {Iterable<string>} absPaths */
|
|
58
|
-
const absorb = (absPaths) => {
|
|
59
|
-
for (const a of absPaths) {
|
|
60
|
-
const rel = relative(workdir, a).split('\\').join('/');
|
|
61
|
-
if (isHandoffExcluded(rel)) continue;
|
|
62
|
-
paths.delete(rel);
|
|
63
|
-
paths.add(rel);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* @param {{getNode?: (rel: string) => any}} [o] `getNode`: the LiteCtx index's node for a path (its `chunks`)
|
|
68
|
-
* @returns {{text: string, paths: number}} text '' when nothing was read; else heading + body, length <= HANDOFF_CAP
|
|
69
|
-
*/
|
|
70
|
-
const render = ({ getNode = () => null } = {}) => {
|
|
71
|
-
if (paths.size === 0) return { text: '', paths: 0 };
|
|
72
|
-
const lineCount = (/** @type {string} */ rel) => { try { return readFileSync(resolve(workdir, rel), 'utf8').split('\n').length; } catch { return null; } };
|
|
73
|
-
const entries = [...paths].map((rel) => {
|
|
74
|
-
const n = lineCount(rel);
|
|
75
|
-
let node = null;
|
|
76
|
-
try { node = getNode(rel); } catch { node = null; }
|
|
77
|
-
// Fresh index only: a node whose last chunk ends past the file's current end is stale — fall back to the count.
|
|
78
|
-
const named = (node?.chunks ?? []).filter((/** @type {any} */ c) => c.symbol);
|
|
79
|
-
const fresh = n !== null && named.every((/** @type {any} */ c) => c.endLine <= n);
|
|
80
|
-
let map = '';
|
|
81
|
-
let more = 0;
|
|
82
|
-
for (let i = 0; fresh && i < named.length; i++) {
|
|
83
|
-
const c = named[i];
|
|
84
|
-
const piece = `${c.symbol} ${c.startLine}-${c.endLine}`;
|
|
85
|
-
if ((map ? map.length + 2 : 0) + piece.length > ENTRY_MAP_CAP) { more = named.length - i; break; }
|
|
86
|
-
map += (map ? ', ' : '') + piece;
|
|
87
|
-
}
|
|
88
|
-
return `- ${rel}${n === null ? '' : ` (${n} lines)`}${map ? `: ${map}` : ''}${more ? `, +${more} more` : ''}`;
|
|
89
|
-
});
|
|
90
|
-
const wrap = (/** @type {string[]} */ es, /** @type {number} */ dropped) => `${HANDOFF_HEADING}\n${dropped ? `[trimmed: ${dropped} older path(s)]\n` : ''}${es.join('\n')}`;
|
|
91
|
-
let dropped = 0;
|
|
92
|
-
let out = wrap(entries, 0);
|
|
93
|
-
while (out.length > HANDOFF_CAP && dropped < entries.length) {
|
|
94
|
-
dropped++;
|
|
95
|
-
out = wrap(entries.slice(dropped), dropped);
|
|
96
|
-
}
|
|
97
|
-
return { text: out, paths: entries.length - dropped };
|
|
98
|
-
};
|
|
99
|
-
return { absorb, render, size: () => paths.size };
|
|
100
|
-
}
|
package/types/handoff.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Is this repo-relative path off limits to a note: outside the job root, an arbiter book (the one list,
|
|
3
|
-
* `isArbiterBook`: .smoke — spine, attempt-diff, bridges — .litectx, the gate audit), or inside `.git` / `.bareloop`.
|
|
4
|
-
* @param {string} rel
|
|
5
|
-
*/
|
|
6
|
-
export function isHandoffExcluded(rel: string): boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Wrap the worker's read-class tools (the real names come from the caller: shell_read, ctx_get) so a call that
|
|
9
|
-
* reached `execute` (the gate already allowed it) and returned a file's text is reported to `onRead`.
|
|
10
|
-
* Wraps in place: tool objects are fresh per worker.
|
|
11
|
-
* @param {{name: string, execute: Function}[]} tools
|
|
12
|
-
* @param {string[]} names
|
|
13
|
-
* @param {(absPath: string) => void} onRead
|
|
14
|
-
* @param {string} workdir
|
|
15
|
-
*/
|
|
16
|
-
export function trackReads(tools: {
|
|
17
|
-
name: string;
|
|
18
|
-
execute: Function;
|
|
19
|
-
}[], names: string[], onRead: (absPath: string) => void, workdir: string): void;
|
|
20
|
-
/**
|
|
21
|
-
* Run-level store of the paths earlier workers read. Newest read last; a re-read moves a path to newest.
|
|
22
|
-
* In memory only: a resumed leg starts empty (the first ask of a resumed leg gets no note, later asks do).
|
|
23
|
-
* @param {{workdir: string}} o
|
|
24
|
-
*/
|
|
25
|
-
export function createHandoffStore({ workdir }: {
|
|
26
|
-
workdir: string;
|
|
27
|
-
}): {
|
|
28
|
-
absorb: (absPaths: Iterable<string>) => void;
|
|
29
|
-
render: ({ getNode }?: {
|
|
30
|
-
getNode?: (rel: string) => any;
|
|
31
|
-
}) => {
|
|
32
|
-
text: string;
|
|
33
|
-
paths: number;
|
|
34
|
-
};
|
|
35
|
-
size: () => number;
|
|
36
|
-
};
|
|
37
|
-
/** The one cap on a note, in characters. */
|
|
38
|
-
export const HANDOFF_CAP: 8000;
|
|
39
|
-
export const HANDOFF_HEADING: "== Files earlier workers in this run read (a map only; contents are not included; line ranges as ctx_recall prints them) ==";
|