bareloop 0.51.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 +34 -0
- package/README.md +12 -0
- package/bareloop.context.md +29 -12
- package/package.json +2 -2
- package/src/authorscout.js +2 -2
- package/src/carrynote.js +288 -0
- package/src/carrystore.js +264 -0
- package/src/config.js +2 -1
- package/src/job.js +16 -4
- package/src/pagedropwords.js +5 -2
- package/src/panel/index.html +289 -181
- package/src/panel/schedules.js +2 -2
- package/src/panel/server.js +47 -3
- package/src/planrun.js +59 -32
- package/src/readshim.js +98 -3
- package/src/replay.js +28 -3
- package/src/seednote.js +28 -0
- package/src/tools.js +17 -0
- package/types/carrynote.d.ts +151 -0
- package/types/carrystore.d.ts +65 -0
- package/types/config.d.ts +1 -1
- package/types/planrun.d.ts +2 -1
- package/types/readshim.d.ts +54 -18
- package/types/replay.d.ts +1 -0
- package/types/seednote.d.ts +18 -0
- package/types/tools.d.ts +8 -0
- package/src/handoff.js +0 -100
- package/types/handoff.d.ts +0 -39
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is this repo-relative path off limits to the memo: 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 isCarryExcluded(rel: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* One record per tool call (no content, no worker words).
|
|
9
|
+
* @typedef {object} Ev
|
|
10
|
+
* @property {number} ask
|
|
11
|
+
* @property {'read'|'get'|'grep'|'recall'} tool
|
|
12
|
+
* @property {string} [path]
|
|
13
|
+
* @property {number|null} [lines]
|
|
14
|
+
* @property {boolean} [dir]
|
|
15
|
+
* @property {boolean} [linesStale]
|
|
16
|
+
* @property {[number,number]|null} [range]
|
|
17
|
+
* @property {string} [pattern]
|
|
18
|
+
* @property {string} [scope]
|
|
19
|
+
* @property {number} [matches]
|
|
20
|
+
* @property {string[]} [firstMatches]
|
|
21
|
+
* @property {string} [query]
|
|
22
|
+
* @property {string[]} [hitPaths]
|
|
23
|
+
* @property {string[]} [hitRanges]
|
|
24
|
+
* @property {boolean} [noFix] the try that made this call ended with no change and a red check
|
|
25
|
+
*/
|
|
26
|
+
/** token set, same tokenisation as src/learn.js flaggedTokens: lowercase [a-z0-9_]{2,} */
|
|
27
|
+
export function tokens(s: any): any[];
|
|
28
|
+
/**
|
|
29
|
+
* Files that are neither source nor test: manifests, lockfiles, docs, config. Dropped from "where looked" unless edited.
|
|
30
|
+
* @param {string} p repo-relative path
|
|
31
|
+
*/
|
|
32
|
+
export function isNonSource(p: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Fold rule for two search keys (added beside Jaccard): same string prefix of >= PREFIX_MIN chars, or one
|
|
35
|
+
* contains the other (shorter side >= CONTAINS_MIN chars so "a" cannot swallow everything). Case-insensitive.
|
|
36
|
+
* @param {string|undefined} a @param {string|undefined} b
|
|
37
|
+
*/
|
|
38
|
+
export function similarName(a: string | undefined, b: string | undefined): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Group items (newest first). An item joins the first group whose representative (the newest member) matches:
|
|
41
|
+
* Jaccard >= JACCARD_MIN on key tokens (the learnings rule), or `near(rep, item)`.
|
|
42
|
+
* @template T @param {T[]} items @param {(x:T)=>string} keyOf @param {(a:T,b:T)=>boolean} [near]
|
|
43
|
+
* @returns {{rep:T, members:T[]}[]}
|
|
44
|
+
*/
|
|
45
|
+
export function fold<T>(items: T[], keyOf: (x: T) => string, near?: (a: T, b: T) => boolean): {
|
|
46
|
+
rep: T;
|
|
47
|
+
members: T[];
|
|
48
|
+
}[];
|
|
49
|
+
/** merge overlapping / adjacent [a,b] line ranges, ascending; returns 'a-b' strings */
|
|
50
|
+
export function mergeRanges(rs: any): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Render the carry note. PURE.
|
|
53
|
+
* @param {{lastTry?: {step:string|null, kind:'step'|'fix', n:number|string|undefined, of?:number, ended:string, changed:string[]}|null,
|
|
54
|
+
* lastCheck?: string|null, events: Ev[], edits?: {path:string, lines:number, hunks:string[]}[],
|
|
55
|
+
* earlier?: string[], failures?: {label:string, text:string}[], lastAsk?: number,
|
|
56
|
+
* fnRanges?: Record<string, string>}} notes `fnRanges`: path to its function line ranges (`a 1-5, b 7-9`), made by the store from the index
|
|
57
|
+
* @param {number} [cap]
|
|
58
|
+
*/
|
|
59
|
+
export function render(notes: {
|
|
60
|
+
lastTry?: {
|
|
61
|
+
step: string | null;
|
|
62
|
+
kind: "step" | "fix";
|
|
63
|
+
n: number | string | undefined;
|
|
64
|
+
of?: number;
|
|
65
|
+
ended: string;
|
|
66
|
+
changed: string[];
|
|
67
|
+
} | null;
|
|
68
|
+
lastCheck?: string | null;
|
|
69
|
+
events: Ev[];
|
|
70
|
+
edits?: {
|
|
71
|
+
path: string;
|
|
72
|
+
lines: number;
|
|
73
|
+
hunks: string[];
|
|
74
|
+
}[];
|
|
75
|
+
earlier?: string[];
|
|
76
|
+
failures?: {
|
|
77
|
+
label: string;
|
|
78
|
+
text: string;
|
|
79
|
+
}[];
|
|
80
|
+
lastAsk?: number;
|
|
81
|
+
fnRanges?: Record<string, string>;
|
|
82
|
+
}, cap?: number): {
|
|
83
|
+
text: string;
|
|
84
|
+
capped: boolean;
|
|
85
|
+
rawChars: number;
|
|
86
|
+
rawEntries: number;
|
|
87
|
+
foldedEntries: number;
|
|
88
|
+
named: Set<any>;
|
|
89
|
+
summarized: Set<string>;
|
|
90
|
+
sections: {
|
|
91
|
+
reads: number;
|
|
92
|
+
searches: number;
|
|
93
|
+
edits: number;
|
|
94
|
+
earlier: number;
|
|
95
|
+
failures: number;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export const CAP: 12000;
|
|
99
|
+
export const HUNK_LINES: 40;
|
|
100
|
+
export const HUNK_SHOW: 12;
|
|
101
|
+
export const GAP_LINES: 8;
|
|
102
|
+
export const GAP_CHARS: 600;
|
|
103
|
+
export const MATCH_SHOW: 3;
|
|
104
|
+
export const PREFIX_MIN: 6;
|
|
105
|
+
export const CONTAINS_MIN: 4;
|
|
106
|
+
export const HEADING: "== What earlier workers in this run did (facts from the record, written by code) ==";
|
|
107
|
+
export const NO_FIX_MIN_READS: 3;
|
|
108
|
+
export const NO_FIX: " \u00B7 looked here, no fix made";
|
|
109
|
+
/**
|
|
110
|
+
* One record per tool call (no content, no worker words).
|
|
111
|
+
*/
|
|
112
|
+
export type Ev = {
|
|
113
|
+
ask: number;
|
|
114
|
+
tool: "read" | "get" | "grep" | "recall";
|
|
115
|
+
path?: string | undefined;
|
|
116
|
+
lines?: number | null | undefined;
|
|
117
|
+
dir?: boolean | undefined;
|
|
118
|
+
linesStale?: boolean | undefined;
|
|
119
|
+
range?: [number, number] | null | undefined;
|
|
120
|
+
pattern?: string | undefined;
|
|
121
|
+
scope?: string | undefined;
|
|
122
|
+
matches?: number | undefined;
|
|
123
|
+
firstMatches?: string[] | undefined;
|
|
124
|
+
query?: string | undefined;
|
|
125
|
+
hitPaths?: string[] | undefined;
|
|
126
|
+
hitRanges?: string[] | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* the try that made this call ended with no change and a red check
|
|
129
|
+
*/
|
|
130
|
+
noFix?: boolean | undefined;
|
|
131
|
+
};
|
|
132
|
+
export type Entry = {
|
|
133
|
+
text: string;
|
|
134
|
+
keys: string[];
|
|
135
|
+
/**
|
|
136
|
+
* 0 = last try's own fact, 1 = edited file, 2 = the rest
|
|
137
|
+
*/
|
|
138
|
+
tier: 0 | 1 | 2;
|
|
139
|
+
/**
|
|
140
|
+
* times read / searched
|
|
141
|
+
*/
|
|
142
|
+
count: number;
|
|
143
|
+
/**
|
|
144
|
+
* index of the newest call
|
|
145
|
+
*/
|
|
146
|
+
recency: number;
|
|
147
|
+
/**
|
|
148
|
+
* the file's function line ranges (` · functions: a 1-5, b 7-9`), the FIRST thing the cap drops
|
|
149
|
+
*/
|
|
150
|
+
fn?: string | undefined;
|
|
151
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run's edits from the working tree against the start commit: tracked (git diff) plus untracked (no diff exists).
|
|
3
|
+
* Arbiter books / .git / .bareloop are excluded. Never throws; [] on any git failure.
|
|
4
|
+
* @param {string} workdir @param {string|null} base
|
|
5
|
+
* @returns {Promise<{path: string, lines: number, hunks: string[]}[]>}
|
|
6
|
+
*/
|
|
7
|
+
export function workingEdits(workdir: string, base: string | null): Promise<{
|
|
8
|
+
path: string;
|
|
9
|
+
lines: number;
|
|
10
|
+
hunks: string[];
|
|
11
|
+
}[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Order edits oldest to newest by when they last changed: a file's recency is the latest settled ask whose `changed`
|
|
14
|
+
* list names it; a file in no `changed` list is oldest. Ties keep their incoming (alphabetical) order. PURE.
|
|
15
|
+
* @param {{path: string}[]} edits @param {{changed?: string[]}[]} settled asks settled so far, oldest first
|
|
16
|
+
*/
|
|
17
|
+
export function orderEditsByRecency(edits: {
|
|
18
|
+
path: string;
|
|
19
|
+
}[], settled: {
|
|
20
|
+
changed?: string[];
|
|
21
|
+
}[]): {
|
|
22
|
+
path: string;
|
|
23
|
+
}[];
|
|
24
|
+
/**
|
|
25
|
+
* Run-level store. Asks are sequential, so "the current ask" is one counter.
|
|
26
|
+
* @param {{workdir: string, emit: (type: string, rec: any) => void, strikeLimit?: number, resume?: boolean}} o
|
|
27
|
+
*/
|
|
28
|
+
export function createCarryStore({ workdir, emit, strikeLimit, resume }: {
|
|
29
|
+
workdir: string;
|
|
30
|
+
emit: (type: string, rec: any) => void;
|
|
31
|
+
strikeLimit?: number;
|
|
32
|
+
resume?: boolean;
|
|
33
|
+
}): {
|
|
34
|
+
wrapTools: (tools: {
|
|
35
|
+
name: string;
|
|
36
|
+
execute: Function;
|
|
37
|
+
}[]) => void;
|
|
38
|
+
beginAsk: ({ phase, iteration, prompt, getNode }: {
|
|
39
|
+
phase: string;
|
|
40
|
+
iteration: number | string | undefined;
|
|
41
|
+
prompt: string;
|
|
42
|
+
getNode?: (rel: string) => any;
|
|
43
|
+
}) => Promise<string>;
|
|
44
|
+
setStartFailure: (text: string) => void;
|
|
45
|
+
endAsk: ({ bounded, iteration, rounds }: {
|
|
46
|
+
bounded?: {
|
|
47
|
+
iteration: any;
|
|
48
|
+
cause: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
iteration: any;
|
|
51
|
+
rounds: number;
|
|
52
|
+
}) => void;
|
|
53
|
+
settleAsk: (result: "green" | "red" | "unknown", text?: string) => void;
|
|
54
|
+
setBase: (b: string | null | undefined) => void;
|
|
55
|
+
loaded: () => boolean;
|
|
56
|
+
_state: () => {
|
|
57
|
+
n: number;
|
|
58
|
+
events: any[];
|
|
59
|
+
asks: any[];
|
|
60
|
+
base: string | null;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export const CARRY_DIR: "carry";
|
|
64
|
+
/** the retry marker the next prompt of a retried step / fix try carries; kept as a pinned fact about the prompts, no longer read to decide an outcome */
|
|
65
|
+
export const RED_MARKER: RegExp;
|
package/types/config.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function modelsProblem(list: unknown): string | null;
|
|
|
39
39
|
* Patch fields understood: `monthlyLimitUsd` (finite > 0), `learningHints` (true | false), `keys.<ENV>.{shape,baseUrl,legacyMaxTokens}`,
|
|
40
40
|
* `models.<ENV>` (a list judged by {@link modelsProblem}). The first write of a row's `models` list
|
|
41
41
|
* removes that row's older `name` / `priceInPerM` / `priceOutPerM` in the SAME write (never two
|
|
42
|
-
* sources);
|
|
42
|
+
* sources); the retired top-level `anthropicBalanceNote` and `carryNote` (the carry memo is always on, 2026-11-01) are dropped on any write. Any other field is
|
|
43
43
|
* kept, but the whole document is swept for secret-shaped strings first.
|
|
44
44
|
* @param {Record<string, any>} patch
|
|
45
45
|
* @param {{ home?: string }} [opts]
|
package/types/planrun.d.ts
CHANGED
|
@@ -151,6 +151,7 @@ export function boundedNote(bounded: {
|
|
|
151
151
|
* byte-identically to the pre-shim prompt.
|
|
152
152
|
* @param {string|null} [hints] the cross-run learnings block (src/learn.js `renderHints`), verbatim; null/empty
|
|
153
153
|
* renders byte-identically to the prompt without it. Only ever passed for the draft and the first replan.
|
|
154
|
+
* @param {string|null} [seedNote] the seed note (src/seednote.js), verbatim, after the hints; null/empty renders byte-identically to the prompt without it. First draft only.
|
|
154
155
|
*/
|
|
155
156
|
export function planPrompt(job: any, scoutBlob: string, reds: any[] | null, maxStepRounds: number, failure: string | null, scopes: string[] | undefined, materials?: {
|
|
156
157
|
balanceUsd?: number | null;
|
|
@@ -159,7 +160,7 @@ export function planPrompt(job: any, scoutBlob: string, reds: any[] | null, maxS
|
|
|
159
160
|
}, startingDraft?: object | null, checkFacts?: {
|
|
160
161
|
seedRed?: string[];
|
|
161
162
|
priorChecks?: string[];
|
|
162
|
-
}, doorNote?: string | null, readShim?: boolean | "cap" | "diff", hints?: string | null): string;
|
|
163
|
+
}, doorNote?: string | null, readShim?: boolean | "cap" | "diff", hints?: string | null, seedNote?: string | null): string;
|
|
163
164
|
/**
|
|
164
165
|
* Execute a validateJob-GREEN plan-shape job (goal/verdictType/close).
|
|
165
166
|
* Called by runJob after the approval gate, validation, and the smoke — this
|
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/replay.d.ts
CHANGED
|
@@ -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/types/tools.d.ts
CHANGED
|
@@ -269,6 +269,14 @@ export function toolAction(name: string, args: any, workdir?: string): {
|
|
|
269
269
|
args: any;
|
|
270
270
|
path?: undefined;
|
|
271
271
|
};
|
|
272
|
+
export function gatedShellOptions(gate: {
|
|
273
|
+
allows: (action: any) => Promise<boolean>;
|
|
274
|
+
}, workdir: string): {
|
|
275
|
+
noFollowSymlinks: boolean;
|
|
276
|
+
canRead: (p: string, { tool }: {
|
|
277
|
+
tool: string;
|
|
278
|
+
}) => Promise<boolean>;
|
|
279
|
+
};
|
|
272
280
|
/**
|
|
273
281
|
* litectx recall hit — body present only with `{body: true}`
|
|
274
282
|
*/
|
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) ==";
|