bareloop 0.52.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/bareloop.context.md +29 -16
- 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/carrynote.js +38 -12
- package/src/carrystore.js +78 -31
- package/src/config.js +3 -5
- package/src/declaredclose.js +1 -1
- package/src/job.js +16 -4
- package/src/kinds.js +4 -2
- package/src/pagedropwords.js +5 -2
- package/src/panel/handed.js +92 -0
- package/src/panel/index.html +225 -120
- package/src/panel/jobplan.js +6 -1
- package/src/panel/schedules.js +2 -2
- package/src/panel/server.js +25 -8
- package/src/plan.js +38 -1
- package/src/planrun.js +245 -80
- package/src/ralph.js +2 -0
- package/src/readshim.js +98 -3
- package/src/run.js +2 -5
- package/src/seednote.js +28 -0
- package/src/tools.js +65 -6
- package/src/userrun.js +0 -3
- package/types/authorflow.d.ts +54 -1
- package/types/carrynote.d.ts +19 -2
- package/types/carrystore.d.ts +5 -9
- package/types/config.d.ts +2 -2
- 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 +47 -7
- package/types/readshim.d.ts +54 -18
- package/types/run.d.ts +1 -5
- package/types/seednote.d.ts +18 -0
- package/types/tools.d.ts +25 -3
- package/src/handoff.js +0 -100
- package/types/handoff.d.ts +0 -39
package/types/planrun.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export function closeGapBlock(gap: string | null | undefined): string;
|
|
|
103
103
|
* and announces the trim with the repo's ONE marker rather than a second spelling
|
|
104
104
|
* of "this text was cut" (F90.2).
|
|
105
105
|
*
|
|
106
|
-
* @param {{iteration?: number|string|undefined, cause: string, reason: string|null}|null|undefined} bounded
|
|
106
|
+
* @param {{iteration?: number|string|undefined, cause: string, reason: string|null, bad?: BadCallFacts|null}|null|undefined} bounded
|
|
107
107
|
* the previous attempt's bound state, or nullish when it was not bounded
|
|
108
108
|
* @param {number} rounds the step's round bound, as quoted by the frozen sentence
|
|
109
109
|
* @returns {string|null} the note, or null when there is nothing to say
|
|
@@ -112,6 +112,7 @@ export function boundedNote(bounded: {
|
|
|
112
112
|
iteration?: number | string | undefined;
|
|
113
113
|
cause: string;
|
|
114
114
|
reason: string | null;
|
|
115
|
+
bad?: BadCallFacts | null;
|
|
115
116
|
} | null | undefined, rounds: number): string | null;
|
|
116
117
|
/**
|
|
117
118
|
* The plan-drafting prompt: a schema DESCRIPTION built from the live validator
|
|
@@ -151,6 +152,7 @@ export function boundedNote(bounded: {
|
|
|
151
152
|
* byte-identically to the pre-shim prompt.
|
|
152
153
|
* @param {string|null} [hints] the cross-run learnings block (src/learn.js `renderHints`), verbatim; null/empty
|
|
153
154
|
* renders byte-identically to the prompt without it. Only ever passed for the draft and the first replan.
|
|
155
|
+
* @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
156
|
*/
|
|
155
157
|
export function planPrompt(job: any, scoutBlob: string, reds: any[] | null, maxStepRounds: number, failure: string | null, scopes: string[] | undefined, materials?: {
|
|
156
158
|
balanceUsd?: number | null;
|
|
@@ -159,7 +161,7 @@ export function planPrompt(job: any, scoutBlob: string, reds: any[] | null, maxS
|
|
|
159
161
|
}, startingDraft?: object | null, checkFacts?: {
|
|
160
162
|
seedRed?: string[];
|
|
161
163
|
priorChecks?: string[];
|
|
162
|
-
}, doorNote?: string | null, readShim?: boolean | "cap" | "diff", hints?: string | null): string;
|
|
164
|
+
}, doorNote?: string | null, readShim?: boolean | "cap" | "diff", hints?: string | null, seedNote?: string | null): string;
|
|
163
165
|
/**
|
|
164
166
|
* Execute a validateJob-GREEN plan-shape job (goal/verdictType/close).
|
|
165
167
|
* Called by runJob after the approval gate, validation, and the smoke — this
|
|
@@ -408,15 +410,12 @@ export function planPrompt(job: any, scoutBlob: string, reds: any[] | null, maxS
|
|
|
408
410
|
* run start from the ledger as it stood). Handed to the PLANNER only: the first draft and the FIRST replan. No worker ever
|
|
409
411
|
* receives it, and a later replan gets nothing. Each injection is recorded on the spine as a `learnings` record (the exact
|
|
410
412
|
* text) so the Audit can show it and the byte check can compare it with a fresh render. `null` = no hints (the default).
|
|
411
|
-
* @param {boolean} [opts.carryNote=false] THE CARRY NOTE (src/carrynote.js): the step/fix worker is handed a facts-only note of what earlier
|
|
412
|
-
* workers of this run looked at, searched and changed, after the handoff note. The caller reads the switch once; `false` builds no store
|
|
413
|
-
* and leaves the worker prompt byte-identical. One `carry-note` spine record (counts only) per note handed.
|
|
414
413
|
* @returns {Promise<string>} 'green' | 'already-green' | 'escalated' | 'plan-red' |
|
|
415
414
|
* 'check-red' | 'close-red' | 'close-unsupported' | 'recipe-stale' | 'pricing-red' |
|
|
416
415
|
* 'branch-red' | 'cap-halt' | 'wall-halt' | 'stopped' | 'provider-red' | 'interpreter-red' |
|
|
417
416
|
* 'step-stalled' | 'hitl-pause' | 'hitl-decision-red' | `step-red:<id>`
|
|
418
417
|
*/
|
|
419
|
-
export function runPlan(job: any, { workdir, provider, nativeProvider, providerFor, judgeProvider, judgeModel, rates, judgeRates, emit, remainingUsd, isUnpriced, spendComplete, capRuns, strikeLimit, closeTimeoutMs, closeDir, maxStepRounds, layerRoot, readShim, scout, scoutRounds, bridge, now, priorWallMs, resumeSeed, resumeGrades, resumeReplans, resumeBranch, humanRuling, heldRuling, priorSpentUsd, reviewDoor, doorRerun, resumable, stopFile, learnHints
|
|
418
|
+
export function runPlan(job: any, { workdir, provider, nativeProvider, providerFor, judgeProvider, judgeModel, rates, judgeRates, emit, remainingUsd, isUnpriced, spendComplete, capRuns, strikeLimit, closeTimeoutMs, closeDir, maxStepRounds, layerRoot, readShim, scout, scoutRounds, bridge, now, priorWallMs, resumeSeed, resumeGrades, resumeReplans, resumeBranch, humanRuling, heldRuling, priorSpentUsd, reviewDoor, doorRerun, resumable, stopFile, learnHints }: {
|
|
420
419
|
workdir: string;
|
|
421
420
|
provider: any;
|
|
422
421
|
nativeProvider?: ((o: {
|
|
@@ -484,7 +483,6 @@ export function runPlan(job: any, { workdir, provider, nativeProvider, providerF
|
|
|
484
483
|
text: string;
|
|
485
484
|
ids: string[];
|
|
486
485
|
} | null | undefined;
|
|
487
|
-
carryNote?: boolean | undefined;
|
|
488
486
|
}): Promise<string>;
|
|
489
487
|
export { rateSourceFields };
|
|
490
488
|
/**
|
|
@@ -535,12 +533,54 @@ export const FORBIDDEN_WRITE_SEGMENT_PATTERN: RegExp;
|
|
|
535
533
|
* shipped path routinely rides through.
|
|
536
534
|
*/
|
|
537
535
|
export const BOUND_REASON_MAX: 200;
|
|
536
|
+
/** the one message a text-only worker ending is continued with (once per ask, no toolChoice) */
|
|
537
|
+
export const TEXT_ONLY_NUDGE: "You ended without writing any file. Make the change now with your write or edit tool; do not reply in text.";
|
|
538
|
+
/** the stored text-only ending is capped here (report-only record, masked first) */
|
|
539
|
+
export const TEXT_ONLY_MAX: 2000;
|
|
538
540
|
/** the recorded reason for a step attempt whose round was cut at the output cap (F122 2A b) */
|
|
539
541
|
export const TRUNCATED_REASON: "output cut at the token limit (max_tokens)";
|
|
540
542
|
/** the plain sentence for a replan answer cut off at its length limit (hamr 2026-10-16, run mv9gm796) */
|
|
541
543
|
export const REPLAN_CUT_WORDS: "The replan answer was cut off at its length limit, so no new plan came back.";
|
|
544
|
+
/**
|
|
545
|
+
* @typedef {{ kind: string, tool: string|null, param?: string, expected?: string, got?: string, argBytes?: number, parsed?: boolean, hasAppend: boolean, round: number|null }} BadCallFact
|
|
546
|
+
* @typedef {{ calls: BadCallFact[], cutOff: {outputTokens: number|null, reasoningTokens: number|null, maxTokensRequested: number|null}|null }} BadCallFacts
|
|
547
|
+
* bare-agent's STRUCTURED `badCalls`/`cutOff` for one attempt (BA-29); the only input of the two note sentences below
|
|
548
|
+
*/
|
|
549
|
+
/** a cut call at least this many bytes long is the reason the round hit the cap: the note teaches `append` (a bareloop choice, not bare-agent's) */
|
|
550
|
+
export const CUT_LARGE_ARG_BYTES: 8000;
|
|
551
|
+
/** a cut round whose reasoning tokens are more than this share of its output tokens was spent thinking, not writing */
|
|
552
|
+
export const CUT_REASONING_SHARE: 0.5;
|
|
542
553
|
export type CategorizedError = Error & {
|
|
543
554
|
category?: string;
|
|
544
555
|
lib?: string;
|
|
556
|
+
badCall?: {
|
|
557
|
+
kind: string;
|
|
558
|
+
tool: string | null;
|
|
559
|
+
param?: string;
|
|
560
|
+
expected?: string;
|
|
561
|
+
got?: string;
|
|
562
|
+
};
|
|
563
|
+
};
|
|
564
|
+
export type BadCallFact = {
|
|
565
|
+
kind: string;
|
|
566
|
+
tool: string | null;
|
|
567
|
+
param?: string;
|
|
568
|
+
expected?: string;
|
|
569
|
+
got?: string;
|
|
570
|
+
argBytes?: number;
|
|
571
|
+
parsed?: boolean;
|
|
572
|
+
hasAppend: boolean;
|
|
573
|
+
round: number | null;
|
|
574
|
+
};
|
|
575
|
+
/**
|
|
576
|
+
* bare-agent's STRUCTURED `badCalls`/`cutOff` for one attempt (BA-29); the only input of the two note sentences below
|
|
577
|
+
*/
|
|
578
|
+
export type BadCallFacts = {
|
|
579
|
+
calls: BadCallFact[];
|
|
580
|
+
cutOff: {
|
|
581
|
+
outputTokens: number | null;
|
|
582
|
+
reasoningTokens: number | null;
|
|
583
|
+
maxTokensRequested: number | null;
|
|
584
|
+
} | null;
|
|
545
585
|
};
|
|
546
586
|
import { rateSourceFields } from './text.js';
|
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/types/tools.d.ts
CHANGED
|
@@ -224,6 +224,26 @@ export function createCtxTools(lc: any, workdir: string, emit: (type: string, da
|
|
|
224
224
|
};
|
|
225
225
|
execute: (args: any) => Promise<string>;
|
|
226
226
|
})[];
|
|
227
|
+
/**
|
|
228
|
+
* The REAL path of `p`, for a path that may not exist yet: realpath the deepest existing
|
|
229
|
+
* ancestor and append the rest. bare-agent's guard hands its predicate the LEXICAL absolute
|
|
230
|
+
* path (it stays lexical by its own ruling), so a symlinked parent directory would otherwise
|
|
231
|
+
* read as "not tracked" and fail the guard open (F276 gap a).
|
|
232
|
+
* @param {string} p an absolute path
|
|
233
|
+
* @returns {Promise<string>}
|
|
234
|
+
*/
|
|
235
|
+
export function realPathOrAncestor(p: string): Promise<string>;
|
|
236
|
+
/**
|
|
237
|
+
* BA-30's `guardPath`: true only for a path tracked at the seed. Both sides are compared in
|
|
238
|
+
* the REAL form: the set is `realpath(workdir)` + each seed-listed name (a tracked path cannot
|
|
239
|
+
* lie beyond a symlink, git refuses it, so the join is already real), the candidate goes through
|
|
240
|
+
* `realPathOrAncestor`. Files the worker creates later are not in the set, so the guard is off
|
|
241
|
+
* for them (a rubric step file's own rewrite is not a gutting).
|
|
242
|
+
* @param {string} workdir the WORKER tree (panel worktree or hidden-git copy), never the source repo
|
|
243
|
+
* @param {string[]} files the seed listing (`seedListing().files`, repo-relative)
|
|
244
|
+
* @returns {Promise<(absPath: string) => Promise<boolean>>}
|
|
245
|
+
*/
|
|
246
|
+
export function trackedAtSeedGuard(workdir: string, files: string[]): Promise<(absPath: string) => Promise<boolean>>;
|
|
227
247
|
export const PERSONA_TOOLS: string;
|
|
228
248
|
export const RETRIEVAL_STRATEGY: string;
|
|
229
249
|
export const EDIT_STRATEGY: string;
|
|
@@ -255,14 +275,13 @@ export function toolAction(name: string, args: any, workdir?: string): {
|
|
|
255
275
|
path: string;
|
|
256
276
|
args: {
|
|
257
277
|
bytes: number;
|
|
258
|
-
|
|
278
|
+
valueType: string;
|
|
259
279
|
};
|
|
260
280
|
} | {
|
|
261
281
|
type: string;
|
|
262
282
|
path: string;
|
|
263
283
|
args: {
|
|
264
284
|
tool: string;
|
|
265
|
-
bytes?: undefined;
|
|
266
285
|
};
|
|
267
286
|
} | {
|
|
268
287
|
type: string;
|
|
@@ -271,7 +290,10 @@ export function toolAction(name: string, args: any, workdir?: string): {
|
|
|
271
290
|
};
|
|
272
291
|
export function gatedShellOptions(gate: {
|
|
273
292
|
allows: (action: any) => Promise<boolean>;
|
|
274
|
-
}, workdir: string): {
|
|
293
|
+
}, workdir: string, guardPath?: (absPath: string) => boolean | Promise<boolean>): {
|
|
294
|
+
shrinkGuard?: {
|
|
295
|
+
guardPath: (absPath: string) => boolean | Promise<boolean>;
|
|
296
|
+
} | undefined;
|
|
275
297
|
noFollowSymlinks: boolean;
|
|
276
298
|
canRead: (p: string, { tool }: {
|
|
277
299
|
tool: string;
|
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) ==";
|