@smthrs/std 1.0.0-rc.7 → 1.0.0-rc.9
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 +14 -0
- package/README.md +40 -36
- package/dist/cjs/Checkpoints.d.ts +37 -0
- package/dist/cjs/Checkpoints.d.ts.map +1 -1
- package/dist/cjs/Checkpoints.js +75 -0
- package/dist/cjs/Checkpoints.js.map +2 -2
- package/dist/cjs/PortableSearch.d.ts +13 -1
- package/dist/cjs/PortableSearch.d.ts.map +1 -1
- package/dist/cjs/PortableSearch.js +8 -1
- package/dist/cjs/PortableSearch.js.map +2 -2
- package/dist/cjs/RemoteSearch.d.ts +54 -0
- package/dist/cjs/RemoteSearch.d.ts.map +1 -0
- package/dist/cjs/RemoteSearch.js +134 -0
- package/dist/cjs/RemoteSearch.js.map +7 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/internal/EnvelopePrecheck.d.ts +2 -0
- package/dist/cjs/internal/EnvelopePrecheck.d.ts.map +1 -1
- package/dist/cjs/internal/EnvelopePrecheck.js +235 -36
- package/dist/cjs/internal/EnvelopePrecheck.js.map +3 -3
- package/dist/cjs/internal/Exec.d.ts +12 -7
- package/dist/cjs/internal/Exec.d.ts.map +1 -1
- package/dist/cjs/internal/Exec.js +8 -4
- package/dist/cjs/internal/Exec.js.map +2 -2
- package/dist/cjs/internal/RemoteTree.d.ts +60 -0
- package/dist/cjs/internal/RemoteTree.d.ts.map +1 -0
- package/dist/cjs/internal/RemoteTree.js +123 -0
- package/dist/cjs/internal/RemoteTree.js.map +7 -0
- package/dist/cjs/internal/Tar.d.ts +23 -0
- package/dist/cjs/internal/Tar.d.ts.map +1 -0
- package/dist/cjs/internal/Tar.js +86 -0
- package/dist/cjs/internal/Tar.js.map +7 -0
- package/dist/esm/Checkpoints.d.ts +37 -0
- package/dist/esm/Checkpoints.d.ts.map +1 -1
- package/dist/esm/Checkpoints.js +85 -0
- package/dist/esm/Checkpoints.js.map +1 -1
- package/dist/esm/PortableSearch.d.ts +13 -1
- package/dist/esm/PortableSearch.d.ts.map +1 -1
- package/dist/esm/PortableSearch.js +16 -0
- package/dist/esm/PortableSearch.js.map +1 -1
- package/dist/esm/RemoteSearch.d.ts +54 -0
- package/dist/esm/RemoteSearch.d.ts.map +1 -0
- package/dist/esm/RemoteSearch.js +162 -0
- package/dist/esm/RemoteSearch.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/EnvelopePrecheck.d.ts +2 -0
- package/dist/esm/internal/EnvelopePrecheck.d.ts.map +1 -1
- package/dist/esm/internal/EnvelopePrecheck.js +321 -62
- package/dist/esm/internal/EnvelopePrecheck.js.map +1 -1
- package/dist/esm/internal/Exec.d.ts +12 -7
- package/dist/esm/internal/Exec.d.ts.map +1 -1
- package/dist/esm/internal/Exec.js +30 -9
- package/dist/esm/internal/Exec.js.map +1 -1
- package/dist/esm/internal/RemoteTree.d.ts +60 -0
- package/dist/esm/internal/RemoteTree.d.ts.map +1 -0
- package/dist/esm/internal/RemoteTree.js +132 -0
- package/dist/esm/internal/RemoteTree.js.map +1 -0
- package/dist/esm/internal/Tar.d.ts +23 -0
- package/dist/esm/internal/Tar.d.ts.map +1 -0
- package/dist/esm/internal/Tar.js +97 -0
- package/dist/esm/internal/Tar.js.map +1 -0
- package/docs/README.md +3 -1
- package/docs/api.md +48 -21
- package/docs/concepts/effects-and-capabilities.md +3 -1
- package/docs/guides/bind-the-standard-flows.md +3 -1
- package/docs/guides/pin-a-checkpoint.md +20 -0
- package/docs/guides/run-a-shell-command.md +4 -1
- package/docs/installation.md +13 -9
- package/docs/quickstart.md +1 -1
- package/docs/troubleshooting.md +20 -0
- package/package.json +16 -6
- package/src/Checkpoints.ts +137 -0
- package/src/PortableSearch.ts +20 -0
- package/src/RemoteSearch.ts +199 -0
- package/src/index.ts +3 -0
- package/src/internal/EnvelopePrecheck.ts +320 -64
- package/src/internal/Exec.ts +32 -8
- package/src/internal/RemoteTree.ts +159 -0
- package/src/internal/Tar.ts +95 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Tar_exports = {};
|
|
20
|
+
__export(Tar_exports, {
|
|
21
|
+
files: () => files
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Tar_exports);
|
|
24
|
+
const decoder = new TextDecoder();
|
|
25
|
+
const text = (bytes) => {
|
|
26
|
+
const end = bytes.indexOf(0);
|
|
27
|
+
return decoder.decode(end === -1 ? bytes : bytes.subarray(0, end));
|
|
28
|
+
};
|
|
29
|
+
const octal = (bytes) => {
|
|
30
|
+
const digits = text(bytes).trim();
|
|
31
|
+
return /^[0-7]+$/.test(digits) ? Number.parseInt(digits, 8) : void 0;
|
|
32
|
+
};
|
|
33
|
+
const checksum = (header) => {
|
|
34
|
+
let sum = 0;
|
|
35
|
+
for (let index = 0; index < 512; index++) sum += index >= 148 && index < 156 ? 32 : header[index];
|
|
36
|
+
return sum;
|
|
37
|
+
};
|
|
38
|
+
const paxPath = (data) => {
|
|
39
|
+
let offset = 0;
|
|
40
|
+
let path;
|
|
41
|
+
while (offset < data.length) {
|
|
42
|
+
const space = data.indexOf(32, offset);
|
|
43
|
+
const length = space === -1 ? Number.NaN : Number(decoder.decode(data.subarray(offset, space)));
|
|
44
|
+
if (!Number.isSafeInteger(length) || length <= space - offset || offset + length > data.length) return path;
|
|
45
|
+
const record = decoder.decode(data.subarray(space + 1, offset + length - 1));
|
|
46
|
+
if (record.startsWith("path=")) path = record.slice("path=".length);
|
|
47
|
+
offset += length;
|
|
48
|
+
}
|
|
49
|
+
return path;
|
|
50
|
+
};
|
|
51
|
+
const files = (stream) => {
|
|
52
|
+
const found = /* @__PURE__ */ new Map();
|
|
53
|
+
let longName;
|
|
54
|
+
let extended;
|
|
55
|
+
let ended = true;
|
|
56
|
+
for (let offset = 0; offset + 512 <= stream.length; ) {
|
|
57
|
+
const header = stream.subarray(offset, offset + 512);
|
|
58
|
+
offset += 512;
|
|
59
|
+
ended = header.every((byte) => byte === 0);
|
|
60
|
+
if (ended) continue;
|
|
61
|
+
const size = octal(header.subarray(124, 136));
|
|
62
|
+
if (size === void 0 || octal(header.subarray(148, 156)) !== checksum(header)) return void 0;
|
|
63
|
+
if (offset + size > stream.length) return void 0;
|
|
64
|
+
const data = stream.subarray(offset, offset + size);
|
|
65
|
+
offset += Math.ceil(size / 512) * 512;
|
|
66
|
+
const type = String.fromCharCode(header[156]);
|
|
67
|
+
if (type === "L") {
|
|
68
|
+
longName = text(data);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (type === "x") {
|
|
72
|
+
extended = paxPath(data) ?? extended;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (type === "K" || type === "g") continue;
|
|
76
|
+
if (type === "0" || type === "\0" || type === "7") {
|
|
77
|
+
const prefix = decoder.decode(header.subarray(257, 263)) === "ustar\0" ? text(header.subarray(345, 500)) : "";
|
|
78
|
+
const short = text(header.subarray(0, 100));
|
|
79
|
+
found.set(extended ?? longName ?? (prefix === "" ? short : `${prefix}/${short}`), data.slice());
|
|
80
|
+
}
|
|
81
|
+
longName = void 0;
|
|
82
|
+
extended = void 0;
|
|
83
|
+
}
|
|
84
|
+
return ended ? found : void 0;
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=Tar.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/Tar.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The regular files of a tar stream.\n *\n * `RemoteSearch` brings a machine's files back with its own `tar`, because\n * every image ships one and it frames each file with its name and size. GNU\n * and BusyBox `tar` write GNU long names, `bsdtar` writes POSIX extended\n * headers, and `xargs` may start `tar` more than once, so the stream can hold\n * several archives one after another. This reads all of them.\n *\n * @since 1.0.0-rc.8\n */\n\nconst decoder = new TextDecoder()\n\n/** Bytes up to the first NUL, as text. */\nconst text = (bytes: Uint8Array): string => {\n const end = bytes.indexOf(0)\n return decoder.decode(end === -1 ? bytes : bytes.subarray(0, end))\n}\n\n/** An octal header field, or `undefined` when it holds anything else. */\nconst octal = (bytes: Uint8Array): number | undefined => {\n const digits = text(bytes).trim()\n return /^[0-7]+$/.test(digits) ? Number.parseInt(digits, 8) : undefined\n}\n\n/** The header's checksum, computed with the checksum field read as spaces. */\nconst checksum = (header: Uint8Array): number => {\n let sum = 0\n for (let index = 0; index < 512; index++) sum += index >= 148 && index < 156 ? 32 : header[index]!\n return sum\n}\n\n/** The `path` record of a POSIX extended header: `<length> <key>=<value>\\n` records. */\nconst paxPath = (data: Uint8Array): string | undefined => {\n let offset = 0\n let path: string | undefined\n while (offset < data.length) {\n const space = data.indexOf(32, offset)\n const length = space === -1 ? Number.NaN : Number(decoder.decode(data.subarray(offset, space)))\n if (!Number.isSafeInteger(length) || length <= space - offset || offset + length > data.length) return path\n const record = decoder.decode(data.subarray(space + 1, offset + length - 1))\n if (record.startsWith(\"path=\")) path = record.slice(\"path=\".length)\n offset += length\n }\n return path\n}\n\n/**\n * Every regular file the stream holds, by member name, or `undefined` when\n * the stream is not whole tar archives: a header whose checksum does not\n * hold, a member cut short, or a last archive with no end. A `tar` that\n * stopped between two members wrote no end, so its missing files are not\n * mistaken for files it could not read.\n *\n * @private\n * @since 1.0.0-rc.8\n */\nexport const files = (stream: Uint8Array): ReadonlyMap<string, Uint8Array> | undefined => {\n const found = new Map<string, Uint8Array>()\n let longName: string | undefined\n let extended: string | undefined\n let ended = true\n for (let offset = 0; offset + 512 <= stream.length;) {\n const header = stream.subarray(offset, offset + 512)\n offset += 512\n // Zero blocks end one archive; `xargs` may have started another.\n ended = header.every((byte) => byte === 0)\n if (ended) continue\n const size = octal(header.subarray(124, 136))\n if (size === undefined || octal(header.subarray(148, 156)) !== checksum(header)) return undefined\n if (offset + size > stream.length) return undefined\n const data = stream.subarray(offset, offset + size)\n offset += Math.ceil(size / 512) * 512\n const type = String.fromCharCode(header[156]!)\n if (type === \"L\") {\n longName = text(data)\n continue\n }\n if (type === \"x\") {\n extended = paxPath(data) ?? extended\n continue\n }\n // A long link name and a global header describe no member of their own.\n if (type === \"K\" || type === \"g\") continue\n if (type === \"0\" || type === \"\\0\" || type === \"7\") {\n const prefix = decoder.decode(header.subarray(257, 263)) === \"ustar\\0\" ? text(header.subarray(345, 500)) : \"\"\n const short = text(header.subarray(0, 100))\n found.set(extended ?? longName ?? (prefix === \"\" ? short : `${prefix}/${short}`), data.slice())\n }\n longName = undefined\n extended = undefined\n }\n return ended ? found : undefined\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,MAAM,UAAU,IAAI,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CAAC,SAAS,SAAS,CAAC;AACzC,QAAI,MAAO;AACX,UAAM,OAAO,MAAM,OAAO,SAAS,KAAK,GAAG,CAAC;AAC5C,QAAI,SAAS,UAAa,MAAM,OAAO,SAAS,KAAK,GAAG,CAAC,MAAM,SAAS,MAAM,EAAG,QAAO;AACxF,QAAI,SAAS,OAAO,OAAO,OAAQ,QAAO;AAC1C,UAAM,OAAO,OAAO,SAAS,QAAQ,SAAS,IAAI;AAClD,cAAU,KAAK,KAAK,OAAO,GAAG,IAAI;AAClC,UAAM,OAAO,OAAO,aAAa,OAAO,GAAG,CAAE;AAC7C,QAAI,SAAS,KAAK;AAChB,iBAAW,KAAK,IAAI;AACpB;AAAA,IACF;AACA,QAAI,SAAS,KAAK;AAChB,iBAAW,QAAQ,IAAI,KAAK;AAC5B;AAAA,IACF;AAEA,QAAI,SAAS,OAAO,SAAS,IAAK;AAClC,QAAI,SAAS,OAAO,SAAS,QAAQ,SAAS,KAAK;AACjD,YAAM,SAAS,QAAQ,OAAO,OAAO,SAAS,KAAK,GAAG,CAAC,MAAM,YAAY,KAAK,OAAO,SAAS,KAAK,GAAG,CAAC,IAAI;AAC3G,YAAM,QAAQ,KAAK,OAAO,SAAS,GAAG,GAAG,CAAC;AAC1C,YAAM,IAAI,YAAY,aAAa,WAAW,KAAK,QAAQ,GAAG,MAAM,IAAI,KAAK,KAAK,KAAK,MAAM,CAAC;AAAA,IAChG;AACA,eAAW;AACX,eAAW;AAAA,EACb;AACA,SAAO,QAAQ,QAAQ;AACzB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
*/
|
|
72
72
|
import { ChildProcessSpawner } from "@smthrs/kernel/ChildProcessSpawner";
|
|
73
73
|
import { Context, Effect, Layer, Schema } from "effect";
|
|
74
|
+
import * as Container from "./Container.ts";
|
|
74
75
|
import * as StdError from "./StdError.ts";
|
|
75
76
|
/**
|
|
76
77
|
* The id naming the tree a run opened on.
|
|
@@ -265,6 +266,42 @@ export declare const makeGit: (options: GitOptions) => Effect.Effect<Checkpoints
|
|
|
265
266
|
* @since 1.0.0
|
|
266
267
|
*/
|
|
267
268
|
export declare const layerGit: (options: GitOptions) => Layer.Layer<Checkpoints, never, ChildProcessSpawner>;
|
|
269
|
+
/**
|
|
270
|
+
* What {@link makeContainer} needs to know about the container it pins in.
|
|
271
|
+
*
|
|
272
|
+
* @category models
|
|
273
|
+
* @since 1.0.0-rc.8
|
|
274
|
+
*/
|
|
275
|
+
export interface ContainerOptions {
|
|
276
|
+
/** The container `bash` runs in. */
|
|
277
|
+
readonly container: string;
|
|
278
|
+
/** A directory of the repository inside it; absent is the container's own working directory. */
|
|
279
|
+
readonly cwd?: string | undefined;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Builds the store for a host whose `bash` runs in one container.
|
|
283
|
+
*
|
|
284
|
+
* The repository is the container's, so every git command runs there, through
|
|
285
|
+
* the same {@link Container.Container} transport `bash` takes. The host store
|
|
286
|
+
* looked in the CLI's own directory instead and refused every `at` in 112 of
|
|
287
|
+
* 123 trials of the 2026-10-14 SWE-bench Pro run. This keeps that store's
|
|
288
|
+
* shape: a checkpoint is a `stash create` commit named in config, and a tree
|
|
289
|
+
* is checked out under the repository for one call, so a relocated `bash`
|
|
290
|
+
* call keeps its subdirectory and still finds what the workspace installs
|
|
291
|
+
* beside it. That git may run what the repository configures, but only inside
|
|
292
|
+
* the container the agent already commands.
|
|
293
|
+
*
|
|
294
|
+
* @category constructors
|
|
295
|
+
* @since 1.0.0-rc.8
|
|
296
|
+
*/
|
|
297
|
+
export declare const makeContainer: (options: ContainerOptions) => Effect.Effect<Checkpoints, never, ChildProcessSpawner | Container.Container>;
|
|
298
|
+
/**
|
|
299
|
+
* Provides {@link makeContainer}.
|
|
300
|
+
*
|
|
301
|
+
* @category layers
|
|
302
|
+
* @since 1.0.0-rc.8
|
|
303
|
+
*/
|
|
304
|
+
export declare const layerContainer: (options: ContainerOptions) => Layer.Layer<Checkpoints, never, ChildProcessSpawner | Container.Container>;
|
|
268
305
|
/**
|
|
269
306
|
* Rewrites one call's input so the call runs against a materialized checkpoint.
|
|
270
307
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkpoints.d.ts","sourceRoot":"","sources":["../../src/Checkpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"Checkpoints.d.ts","sourceRoot":"","sources":["../../src/Checkpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAK3C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAGzC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,MAAM,SAAS,CAAA;AAE5B;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,uBAA0B,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,aAAa,qBAAqB,CAAA;;;;;AAE/C;;;;;;;;GAQG;AACH,qBAAa,QAAS,SAAQ,aAG5B;CAAG;AAEL;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,C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AAM,CAAA;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACtC;AAYD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,GAClB,SAAS,UAAU,KAClB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,EAAE,mBAAmB,CAIpD,CAAA;AAqGJ;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,SAAS,UAAU,KAAG,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,mBAAmB,CACrD,CAAA;AAE7C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,gGAAgG;IAChG,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAClC;AA4CD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,gBAAgB,KACxB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,EAAE,mBAAmB,GAAG,SAAS,CAAC,SAAS,CAgD1E,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,gBAAgB,KACxB,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,mBAAmB,GAAG,SAAS,CAAC,SAAS,CACzB,CAAA;AAEnD;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/esm/Checkpoints.js
CHANGED
|
@@ -71,6 +71,8 @@
|
|
|
71
71
|
*/
|
|
72
72
|
import { ChildProcessSpawner } from "@smthrs/kernel/ChildProcessSpawner";
|
|
73
73
|
import { Context, Effect, Layer, Schema } from "effect";
|
|
74
|
+
import * as Container from "./Container.js";
|
|
75
|
+
import * as Exec from "./internal/Exec.js";
|
|
74
76
|
import { GitWorktree } from "./internal/GitWorktree.js";
|
|
75
77
|
import { withoutTrailingSlash } from "./internal/Paths.js";
|
|
76
78
|
import * as Prune from "./internal/Prune.js";
|
|
@@ -284,6 +286,89 @@ const gitStore = (options, spawner) => {
|
|
|
284
286
|
* @since 1.0.0
|
|
285
287
|
*/
|
|
286
288
|
export const layerGit = (options) => Layer.effect(Checkpoints)(makeGit(options));
|
|
289
|
+
/**
|
|
290
|
+
* `$1` is the id. Records the working tree with `stash create` over a copy of
|
|
291
|
+
* the index, names the commit in config as {@link makeGit} does, and prints it.
|
|
292
|
+
*/
|
|
293
|
+
const pinScript = [
|
|
294
|
+
"set -e",
|
|
295
|
+
"cd \"$(git rev-parse --show-toplevel)\"",
|
|
296
|
+
"copy=$(mktemp -d)",
|
|
297
|
+
"trap 'rm -rf -- \"$copy\"' EXIT",
|
|
298
|
+
"index=$(git rev-parse --git-path index)",
|
|
299
|
+
"if [ -e \"$index\" ]; then cp -p -- \"$index\" \"$copy/index\"; fi",
|
|
300
|
+
"commit=$(GIT_INDEX_FILE=\"$copy/index\" git -c user.name=flows -c user.email=flows@localhost stash create \"flows checkpoint $1\")",
|
|
301
|
+
"[ -n \"$commit\" ] || commit=$(git rev-parse --verify 'HEAD^{commit}')",
|
|
302
|
+
`git config "${configSection}.$1" "$commit"`,
|
|
303
|
+
"printf '%s\\n' \"$commit\""
|
|
304
|
+
].join("\n");
|
|
305
|
+
/**
|
|
306
|
+
* `$1` is the id, `$2` the lease. Checks the tree out at
|
|
307
|
+
* `<top>/.flows-checkpoints/<id>-<lease>` in a repository of its own whose
|
|
308
|
+
* objects are the workspace's, and prints the top and the checkout.
|
|
309
|
+
*/
|
|
310
|
+
const checkoutScript = [
|
|
311
|
+
"set -e",
|
|
312
|
+
"top=$(git rev-parse --show-toplevel)",
|
|
313
|
+
"cd \"$top\"",
|
|
314
|
+
"common=$(cd \"$(git rev-parse --git-common-dir)\" && pwd -P)",
|
|
315
|
+
`if [ "$1" = ${baseId} ]; then`,
|
|
316
|
+
` commit=$(git rev-parse --verify --quiet '${TestRunner.captureBase}^{commit}' || git rev-parse --verify --quiet 'HEAD^{commit}') || { echo "No commit resolves from ${TestRunner.captureBase} or HEAD in $top." >&2; exit 1; }`,
|
|
317
|
+
"else",
|
|
318
|
+
` commit=$(git config --get "${configSection}.$1") || { echo "No checkpoint is stored under $1 in $top. Take the reading on the live tree instead." >&2; exit 1; }`,
|
|
319
|
+
"fi",
|
|
320
|
+
`dir="$top/${scratchDirectory}/$1-$2"`,
|
|
321
|
+
"trap 'rm -rf -- \"$dir\"' EXIT",
|
|
322
|
+
`mkdir -p -- "$top/${scratchDirectory}"`,
|
|
323
|
+
"git init --quiet \"$dir\"",
|
|
324
|
+
"printf '%s/objects\\n' \"$common\" > \"$dir/.git/objects/info/alternates\"",
|
|
325
|
+
"git -C \"$dir\" checkout --quiet --detach \"$commit\"",
|
|
326
|
+
"trap - EXIT",
|
|
327
|
+
"printf '%s\\n%s\\n' \"$top\" \"$dir\""
|
|
328
|
+
].join("\n");
|
|
329
|
+
/**
|
|
330
|
+
* Builds the store for a host whose `bash` runs in one container.
|
|
331
|
+
*
|
|
332
|
+
* The repository is the container's, so every git command runs there, through
|
|
333
|
+
* the same {@link Container.Container} transport `bash` takes. The host store
|
|
334
|
+
* looked in the CLI's own directory instead and refused every `at` in 112 of
|
|
335
|
+
* 123 trials of the 2026-10-14 SWE-bench Pro run. This keeps that store's
|
|
336
|
+
* shape: a checkpoint is a `stash create` commit named in config, and a tree
|
|
337
|
+
* is checked out under the repository for one call, so a relocated `bash`
|
|
338
|
+
* call keeps its subdirectory and still finds what the workspace installs
|
|
339
|
+
* beside it. That git may run what the repository configures, but only inside
|
|
340
|
+
* the container the agent already commands.
|
|
341
|
+
*
|
|
342
|
+
* @category constructors
|
|
343
|
+
* @since 1.0.0-rc.8
|
|
344
|
+
*/
|
|
345
|
+
export const makeContainer = (options) => Effect.gen(function* () {
|
|
346
|
+
const spawner = yield* ChildProcessSpawner;
|
|
347
|
+
const transport = yield* Container.Container;
|
|
348
|
+
const sh = (script, args) => transport.exec({
|
|
349
|
+
container: options.container,
|
|
350
|
+
file: "sh",
|
|
351
|
+
args: ["-c", script, "sh", ...args],
|
|
352
|
+
cwd: options.cwd,
|
|
353
|
+
stdin: false
|
|
354
|
+
}).pipe(Effect.flatMap((plan) => Exec.exec(plan.file, { args: plan.args, env: plan.env }).pipe(Effect.mapError((error) => Exec.toStdError(plan.file, error)))), Effect.flatMap((result) => result.exitCode === 0
|
|
355
|
+
? Effect.succeed(result.stdout.trim().split("\n"))
|
|
356
|
+
: Effect.fail(failed(`git in container ${options.container} failed: ${result.stderr.trim()}`))), Effect.provideService(ChildProcessSpawner, spawner));
|
|
357
|
+
const named = (id) => namable.test(id)
|
|
358
|
+
? Effect.void
|
|
359
|
+
: Effect.fail(failed(`A checkpoint id must match ${namable.source}; ${id} does not.`, "invalid_input"));
|
|
360
|
+
return make({
|
|
361
|
+
capture: (id) => named(id).pipe(Effect.andThen(sh(pinScript, [id])), Effect.map(([commit]) => new Snapshot({ id, ref: commit }))),
|
|
362
|
+
materialize: (id, use) => named(id).pipe(Effect.andThen(Effect.acquireUseRelease(sh(checkoutScript, [id, globalThis.crypto.randomUUID()]), ([root, checkout]) => use({ id, host: checkout, guest: checkout, root: root, guestRoot: root }), ([, checkout]) => sh("rm -rf -- \"$1\"", [checkout]).pipe(Effect.catch((error) => Effect.logWarning("could not remove a scratch checkout").pipe(Effect.annotateLogs({ path: checkout, reason: error.message })))))))
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
/**
|
|
366
|
+
* Provides {@link makeContainer}.
|
|
367
|
+
*
|
|
368
|
+
* @category layers
|
|
369
|
+
* @since 1.0.0-rc.8
|
|
370
|
+
*/
|
|
371
|
+
export const layerContainer = (options) => Layer.effect(Checkpoints)(makeContainer(options));
|
|
287
372
|
/**
|
|
288
373
|
* Rewrites one call's input so the call runs against a materialized checkpoint.
|
|
289
374
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkpoints.js","sourceRoot":"","sources":["../../src/Checkpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAA;AAE5B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,iBAAiB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAA;AAE/C;;;;;;;;GAQG;AACH,MAAM,OAAO,QAAS,SAAQ,MAAM,CAAC,KAAK,CAAW,kCAAkC,CAAC,CAAC;IACvF,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,GAAG,EAAE,MAAM,CAAC,MAAM;CACnB,CAAC;CAAG;AAqDL;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAA8C,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAA;AAEhH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAA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;YACtB,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CACvB,MAAM,CAAC,8BAA8B,OAAO,CAAC,MAAM,KAAK,EAAE,YAAY,EAAE,eAAe,CAAC,CACzF,CAAA;QACH,CAAC;QACD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;QACzC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAK,CAAA;QAC1C,OAAO,KAAK,CAAC,CAAC,WAAW,CAAC,oBAAoB,CAC5C,IAAI,EACJ,GAAG,gBAAgB,IAAI,EAAE,EAAE,EAC3B,MAAM,EACN,CAAC,IAAI,EAAE,EAAE,CACP,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CACtF,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAC/B,CACJ,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;IAEJ,OAAO,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAA;AACvC,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,OAAmB,EAAwD,EAAE,CACpG,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AAC7C;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAA","sourcesContent":["/**\n * Pinned trees, and the scratch checkouts a call runs against.\n *\n * A checkpoint is a **value**: minting one changes nothing about the workspace,\n * and running a call against one leaves the live tree exactly as it stands.\n * That is the whole of what it buys. Before it existed, the only way a run\n * could answer \"did this command fail before my change\" was to undo the change\n * — and the journals price that exactly. On `sympy__sympy-13878` the r95repl\n * lane applied one byte-identical 4,789-character patch **five times**, four of\n * those applications preceded by `git checkout -- sympy/stats/crv_types.py`,\n * because a clean fails-before proof required reverting the very work it was\n * meant to prove.\n *\n * This module is the host half of `@smthrs/harness`'s `ctx.checkpoint()` and\n * `ctx.call(flow, input, { at })`. The harness owns the surface, the identity,\n * the bound and the refusals; nothing in it knows what a tree is. This owns the\n * two host operations that need one:\n *\n * - {@link Checkpoints.capture} records the working tree under an id, and\n * - {@link Checkpoints.materialize} gives that tree back as a directory for the\n * length of one call.\n *\n * ## The git binding, and the container constraint it is shaped by\n *\n * {@link layerGit} records a checkpoint with `git stash create`, then names the\n * commit it prints in this repository's own git config rather than with a ref —\n * see {@link configSection} for why a ref would hand the agent its own edit back\n * as history. `stash create` is the one git command\n * that records the working tree and changes nothing else: it does not move the\n * worktree and does not touch the stash ref. It runs against a shadow\n * `GIT_DIR` over a copy of the workspace index (see `internal/GitWorktree.ts`),\n * so it never writes the repository's index and never runs a program the\n * workspace's `.git` names. That matters more than it sounds. The agent runs `git` in this same\n * workspace and its own `git diff` is the run's evidence, so a capture that\n * staged into the real index would be the harness editing the evidence while\n * recording it. A tree with nothing to record prints nothing, and the\n * checkpoint is then `HEAD` — which is exactly what the tree is.\n *\n * Untracked files are not in the recorded tree, which matches how the rig\n * captures a patch: `capture-patch.sh` drops paths that did not exist when the\n * agent started, so a checkpoint holds what a patch would hold.\n *\n * The materialization is a detached checkout at `<root>/.flows-checkpoints/<id>-<lease>`\n * — **inside** the workspace, which looks wrong and is the only thing that\n * works. A benchmark check runs through `docker exec` inside `/testbed`, and\n * `/testbed` is a bind mount of the live workspace. A scratch checkout anywhere\n * else on the host is simply not visible to the container, so the call would run\n * against a path that does not exist. Placed under the workspace it is visible\n * at the same subpath under the mount, needs no second mount, and needs no\n * change to how the rig starts its container. `TestRun`'s `against: \"base\"`\n * reached the same conclusion first and this reuses its shape;\n * `evals/swebench/run-instance.sh` excludes the directory from patch capture for\n * the same reason it excludes `.flows-test-base`.\n *\n * The checkout is added and removed around **one call**, which is stricter than\n * the frame lifetime the design asks for and much simpler: there is no cache to\n * invalidate, no id to leak, and a checkpoint used by three calls pays three\n * checkouts rather than risking one stale directory. A run that reuses a\n * checkpoint across frames simply re-materializes it, because the ref is what\n * persists.\n *\n * ## What can be pointed at a checkpoint, and what cannot\n *\n * {@link relocate} is the closed answer, and `Relocate.ts` owns it. That half\n * knows the input shapes of `bash`, `read`, `ls`, `grep` and `glob`; this half\n * knows git. They change for different reasons, so they are different modules,\n * and {@link relocate} is re-exported here because the harness reaches the whole\n * feature through this one.\n *\n * @since 1.0.0\n */\n\nimport { ChildProcessSpawner } from \"@smthrs/kernel/ChildProcessSpawner\"\nimport { Context, Effect, Layer, Schema } from \"effect\"\nimport { GitWorktree } from \"./internal/GitWorktree.ts\"\nimport { withoutTrailingSlash } from \"./internal/Paths.ts\"\nimport * as Prune from \"./internal/Prune.ts\"\nimport * as StdError from \"./StdError.ts\"\nimport * as TestRunner from \"./TestRunner.ts\"\n\n/**\n * The id naming the tree a run opened on.\n *\n * It is not minted: the host either recorded one before the agent started or it\n * did not. {@link layerGit} resolves it to {@link TestRunner.captureBase} and\n * then to `HEAD`, which is the same precedence `TestRun` uses for the same\n * question — so a workspace that has one answer for a baseline has one answer\n * for both.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const baseId = \"base\"\n\n/**\n * The directory checkpoints are materialized into, relative to the repository\n * root and therefore also relative to a container's view of it.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const scratchDirectory = Prune.checkpointScratch\n\n/**\n * The git-config section {@link layerGit} records minted checkpoints under.\n *\n * Config and **not a ref**, and that is the whole of the decision. A ref is\n * history: `git log --all` lists it, `git show` prints it, and `git log --all\n * -S` searches it — so a checkpoint named by a ref would hand an agent a commit\n * containing its own edit and let it read that back as if it were upstream\n * work. That exact class cost the measured program real money before the rig\n * moved jj's store out of the workspace (`evals/swebench/run-instance.sh`:\n * django-13346 applied two of its own snapshots as a fake fix), and a ref here\n * would reintroduce it one wave later.\n *\n * The commit object itself is unreferenced. It stays alive for the life of the\n * run — nothing in a run prunes — and a checkout by id works perfectly well,\n * which is measured in `CheckpointsFixture.test.ts`. So the tree is reachable\n * by id and no command that walks refs can reach it:\n * `git log`, `git log --all`, `git log -S` and `git show <ref>` all answer\n * exactly as they did before the capture.\n *\n * One command still sees it, measured rather than argued in\n * `CheckpointsFixture.test.ts`: `git fsck` reports it as a dangling commit,\n * because that is what an unreferenced commit is. A checkout is a standalone\n * repository, not a worktree of this one, so `git log --all` does not list it\n * even while a call runs in it. It is not reachable by a name that looks like project history, and the cell\n * contract's environment section says outright that a dangling commit is this\n * harness holding the agent's own tree — which is the half of the django-13346\n * lesson that a store cannot enforce.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const configSection = \"flows-checkpoint\"\n\n/**\n * One tree this run has pinned.\n *\n * `ref` is the store's own name for it. Nothing above this module interprets\n * it; it travels so the journal says which tree a checkpointed call read.\n *\n * @category models\n * @since 1.0.0\n */\nexport class Snapshot extends Schema.Class<Snapshot>(\"@smthrs/std/Checkpoints/Snapshot\")({\n id: Schema.String,\n ref: Schema.String\n}) {}\n\n/**\n * A tree handed back as a directory, for the length of one call.\n *\n * `host` is where the process running on this machine finds it. `guest` is\n * where a container finds the same directory, which is the same path when no\n * container is in play. They differ exactly as `TestRunner.Runner`'s `cwd` and\n * `root` differ, and for the same reason: one directory, two names.\n *\n * `root` and `guestRoot` are the workspace itself under those same two names.\n * They travel because a call that named a directory *inside* the workspace has\n * to keep it: a check that runs in `tests/` and is pointed at a checkpoint must\n * run in the checkpoint's `tests/`, not at its top. Silently dropping that\n * subpath is how a baseline comes back failing for a reason nobody chose, which\n * is the one failure a checkpoint exists to make impossible.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Materialized {\n readonly id: string\n readonly host: string\n readonly guest: string\n /** The workspace this checkpoint is a tree of, as this machine names it. */\n readonly root: string\n /** The workspace as a container names it; the same as {@link Materialized.root} when none does. */\n readonly guestRoot: string\n}\n\n/**\n * The two host operations a checkpoint needs.\n *\n * @category services\n * @since 1.0.0\n */\nexport interface Checkpoints {\n /** Records the working tree as it stands, under `id`. */\n readonly capture: (id: string) => Effect.Effect<Snapshot, StdError.StdError>\n /**\n * Hands `id` back as a directory for the length of the effect it wraps.\n *\n * Scoped rather than returned, because the directory has to be removed\n * however the call ends — a benchmark run killed at its wall-clock budget\n * would otherwise leave a second checkout of the whole repository in a tree\n * whose diff is the run's answer.\n */\n readonly materialize: <A, E, R>(\n id: string,\n use: (materialized: Materialized) => Effect.Effect<A, E, R>\n ) => Effect.Effect<A, E | StdError.StdError, R>\n}\n\n/**\n * The {@link Checkpoints} service tag.\n *\n * @category services\n * @since 1.0.0\n */\nexport const Checkpoints: Context.Service<Checkpoints, Checkpoints> = Context.Service(\"@smthrs/std/Checkpoints\")\n\n/**\n * Builds a store from its two operations.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const make = (service: Checkpoints): Checkpoints => Checkpoints.of(service)\n\n/**\n * The refusal a host with nowhere to pin a tree answers with.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const unavailable = (id: string): StdError.StdError =>\n new StdError.StdError({\n code: \"provider_unavailable\",\n message: `This host pins no trees, so it holds no checkpoint \"${id}\". Take the reading on the live tree instead.`\n })\n\n/**\n * Builds a store for a host that pins nothing.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const makeNoop = (): Checkpoints =>\n make({\n capture: (id) => Effect.fail(unavailable(id)),\n materialize: (id) => Effect.fail(unavailable(id))\n })\n\n/**\n * Provides {@link makeNoop}.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerNoop: Layer.Layer<Checkpoints> = Layer.succeed(Checkpoints, makeNoop())\n\n/**\n * What {@link layerGit} needs to know about the repository it pins.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface GitOptions {\n /** The host path of the git repository whose trees are pinned. */\n readonly root: string\n /**\n * Where a container sees {@link GitOptions.root}, when one does.\n *\n * Absent means there is no container, and the guest path of a materialized\n * checkpoint is then its host path.\n */\n readonly cwd?: string | undefined\n /**\n * The ref naming the tree the run opened on, for {@link baseId}.\n *\n * Absent takes `TestRunner.captureBase` and then `HEAD`, which is the\n * precedence `TestRun` already uses.\n */\n readonly baseRef?: string | undefined\n}\n\nconst failed = (message: string, code: StdError.Code = \"command_failed\"): StdError.StdError =>\n new StdError.StdError({ code, message })\n\n/**\n * A checkpoint id, restricted to what can safely become a git-config key and a\n * directory name. No dots: a dot would split the config key into another\n * subsection.\n */\nconst namable = /^[A-Za-z0-9][A-Za-z0-9-]*$/\n\n/**\n * Builds the git-backed store.\n *\n * Every git command that records or checks out a tree runs against a shadow\n * `GIT_DIR` the harness owns, never the workspace's `.git`, which the agent\n * can write; see `internal/GitWorktree.ts`. The capture reads a copy of the\n * workspace index, so the agent's own index is untouched: its `git diff` is the\n * run's evidence and must not move because the harness recorded something.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const makeGit = (\n options: GitOptions\n): Effect.Effect<Checkpoints, never, ChildProcessSpawner> =>\n Effect.gen(function*() {\n const spawner = yield* ChildProcessSpawner\n return gitStore(options, spawner)\n })\n\n/**\n * The store itself, with the spawner it runs git through already resolved.\n *\n * Resolving it here rather than threading it through {@link Checkpoints} keeps\n * the service's own requirement empty, which is what lets a browser host bind\n * {@link layerNoop} against the identical interface — the same shape\n * `TestRunner` and `Container` take.\n */\nconst gitStore = (options: GitOptions, spawner: ChildProcessSpawner[\"Service\"]): Checkpoints => {\n const spawn = <A, E>(effect: Effect.Effect<A, E, ChildProcessSpawner>): Effect.Effect<A, E> =>\n Effect.provideService(effect, ChildProcessSpawner, spawner)\n const root = withoutTrailingSlash(options.root)\n const guestRoot = options.cwd === undefined ? root : withoutTrailingSlash(options.cwd)\n const keyOf = (id: string) => `${configSection}.${id}`\n const baseRefs = options.baseRef === undefined ? [TestRunner.captureBase, \"HEAD\"] : [options.baseRef]\n\n /**\n * The commit one id names.\n *\n * `base` is the one id nobody mints, so it is resolved from refs — the same\n * precedence `TestRun` uses. Every other id was recorded by {@link capture}\n * into this repository's config file, which is where a checkpoint is named\n * *without* becoming history. See {@link configSection}.\n */\n const commitOf = (id: string) =>\n Effect.gen(function*() {\n if (id === baseId) return (yield* GitWorktree.resolveCommit(root, baseRefs)).commit\n const repository = yield* GitWorktree.open(root)\n const found = yield* GitWorktree.config(repository, [\"--get\", keyOf(id)])\n const commit = found.stdout.trim()\n if (found.exitCode !== 0 || commit === \"\") {\n return yield* Effect.fail(\n failed(\n `No checkpoint is stored under ${id} in ${root}. Take the reading on the live tree instead.`,\n \"not_found\"\n )\n )\n }\n return commit\n })\n\n const capture = (id: string) =>\n spawn(Effect.gen(function*() {\n if (!namable.test(id)) {\n return yield* Effect.fail(\n failed(`A checkpoint id must match ${namable.source}; ${id} does not.`, \"invalid_input\")\n )\n }\n const repository = yield* GitWorktree.open(root)\n const commit = yield* GitWorktree.withShadow(repository, (shadow) =>\n Effect.gen(function*() {\n const head = (yield* GitWorktree.resolveCommit(root, [\"HEAD\"])).commit\n yield* shadow.adoptIndex\n const pinned = yield* shadow.git([\"update-ref\", \"--no-deref\", \"HEAD\", head])\n if (pinned.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not record the working tree: ${pinned.stderr.trim()}`))\n }\n const recorded = yield* shadow.git([\"stash\", \"create\", `flows checkpoint ${id}`], root)\n if (recorded.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not record the working tree: ${recorded.stderr.trim()}`))\n }\n // Nothing to record means the working tree IS the commit it is on, so\n // that commit is the checkpoint. `stash create` says so by printing\n // nothing, which is not an error and must not be read as one.\n return recorded.stdout.trim() === \"\" ? head : recorded.stdout.trim()\n }))\n const named = yield* GitWorktree.config(repository, [keyOf(id), commit])\n if (named.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not name the checkpoint: ${named.stderr.trim()}`))\n }\n return new Snapshot({ id, ref: commit })\n }))\n\n const materialize = <A, E, R>(\n id: string,\n use: (materialized: Materialized) => Effect.Effect<A, E, R>\n ): Effect.Effect<A, E | StdError.StdError, R> =>\n Effect.gen(function*() {\n if (!namable.test(id)) {\n return yield* Effect.fail(\n failed(`A checkpoint id must match ${namable.source}; ${id} does not.`, \"invalid_input\")\n )\n }\n const commit = yield* spawn(commitOf(id))\n const context = yield* Effect.context<R>()\n return yield* GitWorktree.withDetachedWorktree(\n root,\n `${scratchDirectory}/${id}`,\n commit,\n (host) =>\n use({ id, host, guest: `${guestRoot}${host.slice(root.length)}`, root, guestRoot }).pipe(\n Effect.provideContext(context)\n )\n ).pipe(Effect.provideService(ChildProcessSpawner, spawner))\n })\n\n return make({ capture, materialize })\n}\n\n/**\n * Provides {@link makeGit}.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerGit = (options: GitOptions): Layer.Layer<Checkpoints, never, ChildProcessSpawner> =>\n Layer.effect(Checkpoints)(makeGit(options))\n/**\n * Rewrites one call's input so the call runs against a materialized checkpoint.\n *\n * Re-exported from {@link Relocate}, which owns the table of flows and fields\n * this rewrite is driven by. It is exported here because the harness reaches the\n * whole checkpoint feature through this module.\n *\n * @category conversions\n * @since 1.0.0\n */\nexport { relocate, type Relocation } from \"./Relocate.ts\"\n"]}
|
|
1
|
+
{"version":3,"file":"Checkpoints.js","sourceRoot":"","sources":["../../src/Checkpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AA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,EAAE,QAAQ,CAAC,EAAE,EAAE,CACf,EAAE,CAAC,kBAAkB,EAAE,CAAC,QAAS,CAAC,CAAC,CAAC,IAAI,CACtC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACrB,MAAM,CAAC,UAAU,CAAC,qCAAqC,CAAC,CAAC,IAAI,CAC3D,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAC/D,CACF,CACF,CACJ,CAAC,CAAC;KACN,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAAyB,EACmD,EAAE,CAC9E,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;AAEnD;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAA","sourcesContent":["/**\n * Pinned trees, and the scratch checkouts a call runs against.\n *\n * A checkpoint is a **value**: minting one changes nothing about the workspace,\n * and running a call against one leaves the live tree exactly as it stands.\n * That is the whole of what it buys. Before it existed, the only way a run\n * could answer \"did this command fail before my change\" was to undo the change\n * — and the journals price that exactly. On `sympy__sympy-13878` the r95repl\n * lane applied one byte-identical 4,789-character patch **five times**, four of\n * those applications preceded by `git checkout -- sympy/stats/crv_types.py`,\n * because a clean fails-before proof required reverting the very work it was\n * meant to prove.\n *\n * This module is the host half of `@smthrs/harness`'s `ctx.checkpoint()` and\n * `ctx.call(flow, input, { at })`. The harness owns the surface, the identity,\n * the bound and the refusals; nothing in it knows what a tree is. This owns the\n * two host operations that need one:\n *\n * - {@link Checkpoints.capture} records the working tree under an id, and\n * - {@link Checkpoints.materialize} gives that tree back as a directory for the\n * length of one call.\n *\n * ## The git binding, and the container constraint it is shaped by\n *\n * {@link layerGit} records a checkpoint with `git stash create`, then names the\n * commit it prints in this repository's own git config rather than with a ref —\n * see {@link configSection} for why a ref would hand the agent its own edit back\n * as history. `stash create` is the one git command\n * that records the working tree and changes nothing else: it does not move the\n * worktree and does not touch the stash ref. It runs against a shadow\n * `GIT_DIR` over a copy of the workspace index (see `internal/GitWorktree.ts`),\n * so it never writes the repository's index and never runs a program the\n * workspace's `.git` names. That matters more than it sounds. The agent runs `git` in this same\n * workspace and its own `git diff` is the run's evidence, so a capture that\n * staged into the real index would be the harness editing the evidence while\n * recording it. A tree with nothing to record prints nothing, and the\n * checkpoint is then `HEAD` — which is exactly what the tree is.\n *\n * Untracked files are not in the recorded tree, which matches how the rig\n * captures a patch: `capture-patch.sh` drops paths that did not exist when the\n * agent started, so a checkpoint holds what a patch would hold.\n *\n * The materialization is a detached checkout at `<root>/.flows-checkpoints/<id>-<lease>`\n * — **inside** the workspace, which looks wrong and is the only thing that\n * works. A benchmark check runs through `docker exec` inside `/testbed`, and\n * `/testbed` is a bind mount of the live workspace. A scratch checkout anywhere\n * else on the host is simply not visible to the container, so the call would run\n * against a path that does not exist. Placed under the workspace it is visible\n * at the same subpath under the mount, needs no second mount, and needs no\n * change to how the rig starts its container. `TestRun`'s `against: \"base\"`\n * reached the same conclusion first and this reuses its shape;\n * `evals/swebench/run-instance.sh` excludes the directory from patch capture for\n * the same reason it excludes `.flows-test-base`.\n *\n * The checkout is added and removed around **one call**, which is stricter than\n * the frame lifetime the design asks for and much simpler: there is no cache to\n * invalidate, no id to leak, and a checkpoint used by three calls pays three\n * checkouts rather than risking one stale directory. A run that reuses a\n * checkpoint across frames simply re-materializes it, because the ref is what\n * persists.\n *\n * ## What can be pointed at a checkpoint, and what cannot\n *\n * {@link relocate} is the closed answer, and `Relocate.ts` owns it. That half\n * knows the input shapes of `bash`, `read`, `ls`, `grep` and `glob`; this half\n * knows git. They change for different reasons, so they are different modules,\n * and {@link relocate} is re-exported here because the harness reaches the whole\n * feature through this one.\n *\n * @since 1.0.0\n */\n\nimport { ChildProcessSpawner } from \"@smthrs/kernel/ChildProcessSpawner\"\nimport { Context, Effect, Layer, Schema } from \"effect\"\nimport * as Container from \"./Container.ts\"\nimport * as Exec from \"./internal/Exec.ts\"\nimport { GitWorktree } from \"./internal/GitWorktree.ts\"\nimport { withoutTrailingSlash } from \"./internal/Paths.ts\"\nimport * as Prune from \"./internal/Prune.ts\"\nimport * as StdError from \"./StdError.ts\"\nimport * as TestRunner from \"./TestRunner.ts\"\n\n/**\n * The id naming the tree a run opened on.\n *\n * It is not minted: the host either recorded one before the agent started or it\n * did not. {@link layerGit} resolves it to {@link TestRunner.captureBase} and\n * then to `HEAD`, which is the same precedence `TestRun` uses for the same\n * question — so a workspace that has one answer for a baseline has one answer\n * for both.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const baseId = \"base\"\n\n/**\n * The directory checkpoints are materialized into, relative to the repository\n * root and therefore also relative to a container's view of it.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const scratchDirectory = Prune.checkpointScratch\n\n/**\n * The git-config section {@link layerGit} records minted checkpoints under.\n *\n * Config and **not a ref**, and that is the whole of the decision. A ref is\n * history: `git log --all` lists it, `git show` prints it, and `git log --all\n * -S` searches it — so a checkpoint named by a ref would hand an agent a commit\n * containing its own edit and let it read that back as if it were upstream\n * work. That exact class cost the measured program real money before the rig\n * moved jj's store out of the workspace (`evals/swebench/run-instance.sh`:\n * django-13346 applied two of its own snapshots as a fake fix), and a ref here\n * would reintroduce it one wave later.\n *\n * The commit object itself is unreferenced. It stays alive for the life of the\n * run — nothing in a run prunes — and a checkout by id works perfectly well,\n * which is measured in `CheckpointsFixture.test.ts`. So the tree is reachable\n * by id and no command that walks refs can reach it:\n * `git log`, `git log --all`, `git log -S` and `git show <ref>` all answer\n * exactly as they did before the capture.\n *\n * One command still sees it, measured rather than argued in\n * `CheckpointsFixture.test.ts`: `git fsck` reports it as a dangling commit,\n * because that is what an unreferenced commit is. A checkout is a standalone\n * repository, not a worktree of this one, so `git log --all` does not list it\n * even while a call runs in it. It is not reachable by a name that looks like project history, and the cell\n * contract's environment section says outright that a dangling commit is this\n * harness holding the agent's own tree — which is the half of the django-13346\n * lesson that a store cannot enforce.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const configSection = \"flows-checkpoint\"\n\n/**\n * One tree this run has pinned.\n *\n * `ref` is the store's own name for it. Nothing above this module interprets\n * it; it travels so the journal says which tree a checkpointed call read.\n *\n * @category models\n * @since 1.0.0\n */\nexport class Snapshot extends Schema.Class<Snapshot>(\"@smthrs/std/Checkpoints/Snapshot\")({\n id: Schema.String,\n ref: Schema.String\n}) {}\n\n/**\n * A tree handed back as a directory, for the length of one call.\n *\n * `host` is where the process running on this machine finds it. `guest` is\n * where a container finds the same directory, which is the same path when no\n * container is in play. They differ exactly as `TestRunner.Runner`'s `cwd` and\n * `root` differ, and for the same reason: one directory, two names.\n *\n * `root` and `guestRoot` are the workspace itself under those same two names.\n * They travel because a call that named a directory *inside* the workspace has\n * to keep it: a check that runs in `tests/` and is pointed at a checkpoint must\n * run in the checkpoint's `tests/`, not at its top. Silently dropping that\n * subpath is how a baseline comes back failing for a reason nobody chose, which\n * is the one failure a checkpoint exists to make impossible.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Materialized {\n readonly id: string\n readonly host: string\n readonly guest: string\n /** The workspace this checkpoint is a tree of, as this machine names it. */\n readonly root: string\n /** The workspace as a container names it; the same as {@link Materialized.root} when none does. */\n readonly guestRoot: string\n}\n\n/**\n * The two host operations a checkpoint needs.\n *\n * @category services\n * @since 1.0.0\n */\nexport interface Checkpoints {\n /** Records the working tree as it stands, under `id`. */\n readonly capture: (id: string) => Effect.Effect<Snapshot, StdError.StdError>\n /**\n * Hands `id` back as a directory for the length of the effect it wraps.\n *\n * Scoped rather than returned, because the directory has to be removed\n * however the call ends — a benchmark run killed at its wall-clock budget\n * would otherwise leave a second checkout of the whole repository in a tree\n * whose diff is the run's answer.\n */\n readonly materialize: <A, E, R>(\n id: string,\n use: (materialized: Materialized) => Effect.Effect<A, E, R>\n ) => Effect.Effect<A, E | StdError.StdError, R>\n}\n\n/**\n * The {@link Checkpoints} service tag.\n *\n * @category services\n * @since 1.0.0\n */\nexport const Checkpoints: Context.Service<Checkpoints, Checkpoints> = Context.Service(\"@smthrs/std/Checkpoints\")\n\n/**\n * Builds a store from its two operations.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const make = (service: Checkpoints): Checkpoints => Checkpoints.of(service)\n\n/**\n * The refusal a host with nowhere to pin a tree answers with.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const unavailable = (id: string): StdError.StdError =>\n new StdError.StdError({\n code: \"provider_unavailable\",\n message: `This host pins no trees, so it holds no checkpoint \"${id}\". Take the reading on the live tree instead.`\n })\n\n/**\n * Builds a store for a host that pins nothing.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const makeNoop = (): Checkpoints =>\n make({\n capture: (id) => Effect.fail(unavailable(id)),\n materialize: (id) => Effect.fail(unavailable(id))\n })\n\n/**\n * Provides {@link makeNoop}.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerNoop: Layer.Layer<Checkpoints> = Layer.succeed(Checkpoints, makeNoop())\n\n/**\n * What {@link layerGit} needs to know about the repository it pins.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface GitOptions {\n /** The host path of the git repository whose trees are pinned. */\n readonly root: string\n /**\n * Where a container sees {@link GitOptions.root}, when one does.\n *\n * Absent means there is no container, and the guest path of a materialized\n * checkpoint is then its host path.\n */\n readonly cwd?: string | undefined\n /**\n * The ref naming the tree the run opened on, for {@link baseId}.\n *\n * Absent takes `TestRunner.captureBase` and then `HEAD`, which is the\n * precedence `TestRun` already uses.\n */\n readonly baseRef?: string | undefined\n}\n\nconst failed = (message: string, code: StdError.Code = \"command_failed\"): StdError.StdError =>\n new StdError.StdError({ code, message })\n\n/**\n * A checkpoint id, restricted to what can safely become a git-config key and a\n * directory name. No dots: a dot would split the config key into another\n * subsection.\n */\nconst namable = /^[A-Za-z0-9][A-Za-z0-9-]*$/\n\n/**\n * Builds the git-backed store.\n *\n * Every git command that records or checks out a tree runs against a shadow\n * `GIT_DIR` the harness owns, never the workspace's `.git`, which the agent\n * can write; see `internal/GitWorktree.ts`. The capture reads a copy of the\n * workspace index, so the agent's own index is untouched: its `git diff` is the\n * run's evidence and must not move because the harness recorded something.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const makeGit = (\n options: GitOptions\n): Effect.Effect<Checkpoints, never, ChildProcessSpawner> =>\n Effect.gen(function*() {\n const spawner = yield* ChildProcessSpawner\n return gitStore(options, spawner)\n })\n\n/**\n * The store itself, with the spawner it runs git through already resolved.\n *\n * Resolving it here rather than threading it through {@link Checkpoints} keeps\n * the service's own requirement empty, which is what lets a browser host bind\n * {@link layerNoop} against the identical interface — the same shape\n * `TestRunner` and `Container` take.\n */\nconst gitStore = (options: GitOptions, spawner: ChildProcessSpawner[\"Service\"]): Checkpoints => {\n const spawn = <A, E>(effect: Effect.Effect<A, E, ChildProcessSpawner>): Effect.Effect<A, E> =>\n Effect.provideService(effect, ChildProcessSpawner, spawner)\n const root = withoutTrailingSlash(options.root)\n const guestRoot = options.cwd === undefined ? root : withoutTrailingSlash(options.cwd)\n const keyOf = (id: string) => `${configSection}.${id}`\n const baseRefs = options.baseRef === undefined ? [TestRunner.captureBase, \"HEAD\"] : [options.baseRef]\n\n /**\n * The commit one id names.\n *\n * `base` is the one id nobody mints, so it is resolved from refs — the same\n * precedence `TestRun` uses. Every other id was recorded by {@link capture}\n * into this repository's config file, which is where a checkpoint is named\n * *without* becoming history. See {@link configSection}.\n */\n const commitOf = (id: string) =>\n Effect.gen(function*() {\n if (id === baseId) return (yield* GitWorktree.resolveCommit(root, baseRefs)).commit\n const repository = yield* GitWorktree.open(root)\n const found = yield* GitWorktree.config(repository, [\"--get\", keyOf(id)])\n const commit = found.stdout.trim()\n if (found.exitCode !== 0 || commit === \"\") {\n return yield* Effect.fail(\n failed(\n `No checkpoint is stored under ${id} in ${root}. Take the reading on the live tree instead.`,\n \"not_found\"\n )\n )\n }\n return commit\n })\n\n const capture = (id: string) =>\n spawn(Effect.gen(function*() {\n if (!namable.test(id)) {\n return yield* Effect.fail(\n failed(`A checkpoint id must match ${namable.source}; ${id} does not.`, \"invalid_input\")\n )\n }\n const repository = yield* GitWorktree.open(root)\n const commit = yield* GitWorktree.withShadow(repository, (shadow) =>\n Effect.gen(function*() {\n const head = (yield* GitWorktree.resolveCommit(root, [\"HEAD\"])).commit\n yield* shadow.adoptIndex\n const pinned = yield* shadow.git([\"update-ref\", \"--no-deref\", \"HEAD\", head])\n if (pinned.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not record the working tree: ${pinned.stderr.trim()}`))\n }\n const recorded = yield* shadow.git([\"stash\", \"create\", `flows checkpoint ${id}`], root)\n if (recorded.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not record the working tree: ${recorded.stderr.trim()}`))\n }\n // Nothing to record means the working tree IS the commit it is on, so\n // that commit is the checkpoint. `stash create` says so by printing\n // nothing, which is not an error and must not be read as one.\n return recorded.stdout.trim() === \"\" ? head : recorded.stdout.trim()\n }))\n const named = yield* GitWorktree.config(repository, [keyOf(id), commit])\n if (named.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not name the checkpoint: ${named.stderr.trim()}`))\n }\n return new Snapshot({ id, ref: commit })\n }))\n\n const materialize = <A, E, R>(\n id: string,\n use: (materialized: Materialized) => Effect.Effect<A, E, R>\n ): Effect.Effect<A, E | StdError.StdError, R> =>\n Effect.gen(function*() {\n if (!namable.test(id)) {\n return yield* Effect.fail(\n failed(`A checkpoint id must match ${namable.source}; ${id} does not.`, \"invalid_input\")\n )\n }\n const commit = yield* spawn(commitOf(id))\n const context = yield* Effect.context<R>()\n return yield* GitWorktree.withDetachedWorktree(\n root,\n `${scratchDirectory}/${id}`,\n commit,\n (host) =>\n use({ id, host, guest: `${guestRoot}${host.slice(root.length)}`, root, guestRoot }).pipe(\n Effect.provideContext(context)\n )\n ).pipe(Effect.provideService(ChildProcessSpawner, spawner))\n })\n\n return make({ capture, materialize })\n}\n\n/**\n * Provides {@link makeGit}.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layerGit = (options: GitOptions): Layer.Layer<Checkpoints, never, ChildProcessSpawner> =>\n Layer.effect(Checkpoints)(makeGit(options))\n\n/**\n * What {@link makeContainer} needs to know about the container it pins in.\n *\n * @category models\n * @since 1.0.0-rc.8\n */\nexport interface ContainerOptions {\n /** The container `bash` runs in. */\n readonly container: string\n /** A directory of the repository inside it; absent is the container's own working directory. */\n readonly cwd?: string | undefined\n}\n\n/**\n * `$1` is the id. Records the working tree with `stash create` over a copy of\n * the index, names the commit in config as {@link makeGit} does, and prints it.\n */\nconst pinScript = [\n \"set -e\",\n \"cd \\\"$(git rev-parse --show-toplevel)\\\"\",\n \"copy=$(mktemp -d)\",\n \"trap 'rm -rf -- \\\"$copy\\\"' EXIT\",\n \"index=$(git rev-parse --git-path index)\",\n \"if [ -e \\\"$index\\\" ]; then cp -p -- \\\"$index\\\" \\\"$copy/index\\\"; fi\",\n \"commit=$(GIT_INDEX_FILE=\\\"$copy/index\\\" git -c user.name=flows -c user.email=flows@localhost stash create \\\"flows checkpoint $1\\\")\",\n \"[ -n \\\"$commit\\\" ] || commit=$(git rev-parse --verify 'HEAD^{commit}')\",\n `git config \"${configSection}.$1\" \"$commit\"`,\n \"printf '%s\\\\n' \\\"$commit\\\"\"\n].join(\"\\n\")\n\n/**\n * `$1` is the id, `$2` the lease. Checks the tree out at\n * `<top>/.flows-checkpoints/<id>-<lease>` in a repository of its own whose\n * objects are the workspace's, and prints the top and the checkout.\n */\nconst checkoutScript = [\n \"set -e\",\n \"top=$(git rev-parse --show-toplevel)\",\n \"cd \\\"$top\\\"\",\n \"common=$(cd \\\"$(git rev-parse --git-common-dir)\\\" && pwd -P)\",\n `if [ \"$1\" = ${baseId} ]; then`,\n ` commit=$(git rev-parse --verify --quiet '${TestRunner.captureBase}^{commit}' || git rev-parse --verify --quiet 'HEAD^{commit}') || { echo \"No commit resolves from ${TestRunner.captureBase} or HEAD in $top.\" >&2; exit 1; }`,\n \"else\",\n ` commit=$(git config --get \"${configSection}.$1\") || { echo \"No checkpoint is stored under $1 in $top. Take the reading on the live tree instead.\" >&2; exit 1; }`,\n \"fi\",\n `dir=\"$top/${scratchDirectory}/$1-$2\"`,\n \"trap 'rm -rf -- \\\"$dir\\\"' EXIT\",\n `mkdir -p -- \"$top/${scratchDirectory}\"`,\n \"git init --quiet \\\"$dir\\\"\",\n \"printf '%s/objects\\\\n' \\\"$common\\\" > \\\"$dir/.git/objects/info/alternates\\\"\",\n \"git -C \\\"$dir\\\" checkout --quiet --detach \\\"$commit\\\"\",\n \"trap - EXIT\",\n \"printf '%s\\\\n%s\\\\n' \\\"$top\\\" \\\"$dir\\\"\"\n].join(\"\\n\")\n\n/**\n * Builds the store for a host whose `bash` runs in one container.\n *\n * The repository is the container's, so every git command runs there, through\n * the same {@link Container.Container} transport `bash` takes. The host store\n * looked in the CLI's own directory instead and refused every `at` in 112 of\n * 123 trials of the 2026-10-14 SWE-bench Pro run. This keeps that store's\n * shape: a checkpoint is a `stash create` commit named in config, and a tree\n * is checked out under the repository for one call, so a relocated `bash`\n * call keeps its subdirectory and still finds what the workspace installs\n * beside it. That git may run what the repository configures, but only inside\n * the container the agent already commands.\n *\n * @category constructors\n * @since 1.0.0-rc.8\n */\nexport const makeContainer = (\n options: ContainerOptions\n): Effect.Effect<Checkpoints, never, ChildProcessSpawner | Container.Container> =>\n Effect.gen(function*() {\n const spawner = yield* ChildProcessSpawner\n const transport = yield* Container.Container\n const sh = (script: string, args: ReadonlyArray<string>) =>\n transport.exec({\n container: options.container,\n file: \"sh\",\n args: [\"-c\", script, \"sh\", ...args],\n cwd: options.cwd,\n stdin: false\n }).pipe(\n Effect.flatMap((plan) =>\n Exec.exec(plan.file, { args: plan.args, env: plan.env }).pipe(\n Effect.mapError((error) => Exec.toStdError(plan.file, error))\n )\n ),\n Effect.flatMap((result) =>\n result.exitCode === 0\n ? Effect.succeed(result.stdout.trim().split(\"\\n\"))\n : Effect.fail(failed(`git in container ${options.container} failed: ${result.stderr.trim()}`))\n ),\n Effect.provideService(ChildProcessSpawner, spawner)\n )\n const named = (id: string) =>\n namable.test(id)\n ? Effect.void\n : Effect.fail(failed(`A checkpoint id must match ${namable.source}; ${id} does not.`, \"invalid_input\"))\n return make({\n capture: (id) =>\n named(id).pipe(\n Effect.andThen(sh(pinScript, [id])),\n Effect.map(([commit]) => new Snapshot({ id, ref: commit! }))\n ),\n materialize: (id, use) =>\n named(id).pipe(Effect.andThen(Effect.acquireUseRelease(\n sh(checkoutScript, [id, globalThis.crypto.randomUUID()]),\n ([root, checkout]) => use({ id, host: checkout!, guest: checkout!, root: root!, guestRoot: root! }),\n ([, checkout]) =>\n sh(\"rm -rf -- \\\"$1\\\"\", [checkout!]).pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"could not remove a scratch checkout\").pipe(\n Effect.annotateLogs({ path: checkout, reason: error.message })\n )\n )\n )\n )))\n })\n })\n\n/**\n * Provides {@link makeContainer}.\n *\n * @category layers\n * @since 1.0.0-rc.8\n */\nexport const layerContainer = (\n options: ContainerOptions\n): Layer.Layer<Checkpoints, never, ChildProcessSpawner | Container.Container> =>\n Layer.effect(Checkpoints)(makeContainer(options))\n\n/**\n * Rewrites one call's input so the call runs against a materialized checkpoint.\n *\n * Re-exported from {@link Relocate}, which owns the table of flows and fields\n * this rewrite is driven by. It is exported here because the harness reaches the\n * whole checkpoint feature through this module.\n *\n * @category conversions\n * @since 1.0.0\n */\nexport { relocate, type Relocation } from \"./Relocate.ts\"\n"]}
|
|
@@ -4,9 +4,21 @@
|
|
|
4
4
|
* @since 1.0.0
|
|
5
5
|
*/
|
|
6
6
|
import * as Path from "@smthrs/kernel/Path";
|
|
7
|
-
import { type Context, Layer } from "effect";
|
|
7
|
+
import { type Context, Effect, Layer } from "effect";
|
|
8
8
|
import * as FileSystem from "effect/FileSystem";
|
|
9
9
|
import * as Search from "./Search.ts";
|
|
10
|
+
import * as StdError from "./StdError.ts";
|
|
11
|
+
/**
|
|
12
|
+
* The files this peer's `grep` reads for `input`, in the order it reads
|
|
13
|
+
* them: the walk under `input.root` with its `.gitignore` rules and
|
|
14
|
+
* `input.globs` applied and symbolic links left out, or the root itself when
|
|
15
|
+
* it names one file. A peer that has to bring a tree's bytes to this process
|
|
16
|
+
* before it can search them (`RemoteSearch`) fetches exactly these.
|
|
17
|
+
*
|
|
18
|
+
* @category queries
|
|
19
|
+
* @since 1.0.0-rc.8
|
|
20
|
+
*/
|
|
21
|
+
export declare const searched: (input: Pick<Search.GrepInput, "root" | "hidden" | "noIgnore" | "globs">) => Effect.Effect<ReadonlyArray<string>, StdError.StdError, FileSystem.FileSystem | Path.Path>;
|
|
10
22
|
/**
|
|
11
23
|
* Captures filesystem and path services in the portable peer.
|
|
12
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PortableSearch.d.ts","sourceRoot":"","sources":["../../src/PortableSearch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"PortableSearch.d.ts","sourceRoot":"","sources":["../../src/PortableSearch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAA;AAC5D,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAM/C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAkOzC;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ,GACnB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC,KACtE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAMxF,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,UAAU,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAG,MAAM,CAAC,MAIvF,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAGtF,CAAA"}
|
|
@@ -220,6 +220,22 @@ const glob = (input) => Effect.gen(function* () {
|
|
|
220
220
|
...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })
|
|
221
221
|
};
|
|
222
222
|
});
|
|
223
|
+
/**
|
|
224
|
+
* The files this peer's `grep` reads for `input`, in the order it reads
|
|
225
|
+
* them: the walk under `input.root` with its `.gitignore` rules and
|
|
226
|
+
* `input.globs` applied and symbolic links left out, or the root itself when
|
|
227
|
+
* it names one file. A peer that has to bring a tree's bytes to this process
|
|
228
|
+
* before it can search them (`RemoteSearch`) fetches exactly these.
|
|
229
|
+
*
|
|
230
|
+
* @category queries
|
|
231
|
+
* @since 1.0.0-rc.8
|
|
232
|
+
*/
|
|
233
|
+
export const searched = (input) => Effect.gen(function* () {
|
|
234
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
235
|
+
const path = yield* Path.Path;
|
|
236
|
+
const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore);
|
|
237
|
+
return yield* candidates(fileSystem, path, walked, input.root, input.globs);
|
|
238
|
+
});
|
|
223
239
|
/**
|
|
224
240
|
* Captures filesystem and path services in the portable peer.
|
|
225
241
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|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AAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC,CAAA;IACF,OAAO;QACL,KAAK;QACL,KAAK,EAAE,QAAQ,CAAC,MAAM;QACtB,SAAS,EAAE,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK;QACxC,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtG,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;KAClE,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,QAA4D,EAAiB,EAAE,CAClG,MAAM,CAAC,IAAI,CAAC;IACV,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;IACtD,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;CACvD,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAyE,KAAK,CAAC,MAAM,CACrG,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAqC,EAAE,IAAI,CAAC,CACtE,CAAA","sourcesContent":["/**\n * The in-process implementation of the ripgrep search contract.\n *\n * @since 1.0.0\n */\n\nimport * as Path from \"@smthrs/kernel/Path\"\nimport { type Context, Effect, Layer, Stream } from \"effect\"\nimport * as FileSystem from \"effect/FileSystem\"\nimport * as Grouping from \"./internal/Grouping.ts\"\nimport * as LinearRegex from \"./internal/LinearRegex.ts\"\nimport { escapeRegex } from \"./internal/SearchContract.ts\"\nimport { notice, truncateBytes } from \"./internal/Text.ts\"\nimport * as Walk from \"./internal/Walk.ts\"\nimport * as Search from \"./Search.ts\"\nimport * as Contract from \"./SearchContract.ts\"\nimport * as StdError from \"./StdError.ts\"\n\n/**\n * Narrows a walk to the files a search reports.\n *\n * A root that names one file is that file: `rg` searches a path given on the\n * command line whatever `-g` says, and follows it even when it is a symlink.\n * Everything a walk found is filtered by the globs first and probed for\n * symlinks second, so the probe runs over the far smaller included set.\n */\nconst candidates = (\n fileSystem: FileSystem.FileSystem,\n path: Path.Path,\n walked: Walk.Walked,\n root: string,\n globs: ReadonlyArray<string>\n): Effect.Effect<ReadonlyArray<string>> =>\n Effect.gen(function*() {\n if (walked.explicitFile) return walked.files\n const included = walked.files.filter((file) =>\n Contract.includedByGlobs(globs, Walk.relativeForPattern(path, root, file), path.basename(file))\n )\n const links = yield* Walk.symbolicLinks(fileSystem, included)\n return included.filter((_, index) => links[index] !== true)\n })\n\nconst preview = (line: string): string => {\n let head = \"\"\n let length = 0\n for (const character of line) {\n if (length++ === 500) break\n head += character\n }\n return truncateBytes(head, 500, { keep: \"head\" }).text\n}\n\nconst grep = (\n input: Search.GrepInput\n): Effect.Effect<Search.GrepOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs(input.globs, relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const insensitive = input.ignoreCase || (input.smartCase && !/[A-Z]/.test(input.pattern))\n const regex = LinearRegex.compile(\n input.fixedStrings ? escapeRegex(input.pattern) : input.pattern,\n insensitive\n )\n const shownMatches: Array<Search.GrepMatch> = []\n const shownFiles: Array<string> = []\n let total = 0\n let filesSearched = 0\n let skippedBinary = 0\n\n const included = yield* candidates(fileSystem, path, walked, input.root, input.globs)\n for (const file of included) {\n // Count every admitted file, including unreadable files and binaries.\n filesSearched++\n const remaining = input.filesWithMatches ? 0 : input.limit - shownMatches.length\n const matched: Array<number> = []\n const selected = new Map<number, Search.GrepLine>()\n const recent = new Map<number, Search.GrepLine>()\n let count = 0\n let lineNumber = 0\n let through = 0\n const scanLine = (text: string) =>\n Effect.gen(function*() {\n lineNumber++\n let matches = false\n if (input.maxCount === undefined || count < input.maxCount) {\n const evaluation = regex.test(text)\n let step = evaluation.next()\n while (!step.done) {\n yield* Effect.yieldNow\n step = evaluation.next()\n }\n matches = step.value\n }\n if (matches) count++\n if (remaining <= 0) return\n // The first overflow hit is a boundary: context nearest to it must\n // not migrate to the last retained hit when the limit is applied.\n const retain = matches && matched.length < remaining + 1\n const awaiting = matched.length < remaining + 1\n if (retain || lineNumber <= through || (awaiting && input.beforeContext > 0)) {\n const row: Search.GrepLine = {\n file,\n line: lineNumber,\n text: preview(text),\n kind: retain ? \"match\" : \"context\"\n }\n if (retain) {\n matched.push(lineNumber)\n for (const [number, context] of recent) selected.set(number, context)\n through = lineNumber + input.afterContext\n }\n if (retain || lineNumber <= through) selected.set(lineNumber, row)\n if (awaiting && input.beforeContext > 0) recent.set(lineNumber, row)\n }\n recent.delete(lineNumber - input.beforeContext)\n if (matched.length >= remaining + 1) recent.clear()\n })\n // Split only on LF (stripping a preceding CR), just like sourceLines.\n // Stream.splitLines also treats a standalone CR as a delimiter.\n const decoder = new TextDecoder()\n let fragments: Array<string> = []\n const consume = (chunk: string) =>\n Effect.gen(function*() {\n let from = 0\n let newline = chunk.indexOf(\"\\n\")\n while (newline >= 0) {\n fragments.push(chunk.slice(from, newline))\n const line = fragments.join(\"\")\n fragments = []\n yield* scanLine(line.endsWith(\"\\r\") ? line.slice(0, -1) : line)\n from = newline + 1\n newline = chunk.indexOf(\"\\n\", from)\n }\n if (from < chunk.length) fragments.push(chunk.slice(from))\n })\n const scanned = yield* Effect.gen(function*() {\n let started = false\n // A guarded disk host can safely expose atomic reads while refusing\n // open streaming handles. Retry through that same filesystem service\n // only before any bytes arrive, so a failed partial stream is never\n // combined with a second reading of a file that may have changed.\n yield* fileSystem.stream(file).pipe(\n Stream.catch((error) => started ? Stream.fail(error) : Stream.fromEffect(fileSystem.readFile(file))),\n Stream.runForEach((bytes) => {\n started = true\n if (bytes.includes(0)) {\n return Effect.fail(\n new StdError.StdError({\n code: \"binary_file\",\n message: `Cannot search binary file: ${file}`,\n path: file\n })\n )\n }\n return consume(decoder.decode(bytes, { stream: true }))\n })\n )\n yield* consume(decoder.decode())\n if (fragments.length > 0) yield* scanLine(fragments.join(\"\"))\n return true\n }).pipe(Effect.catch((error) => {\n if (error instanceof StdError.StdError) {\n if (walked.explicitFile) return Effect.fail(error)\n skippedBinary++\n }\n return Effect.succeed(false)\n }))\n if (!scanned || count === 0) continue\n total += input.filesWithMatches ? 1 : count\n if (input.filesWithMatches) {\n if (shownFiles.length < input.limit) shownFiles.push(file)\n continue\n }\n if (matched.length === 0) continue\n const grouped = Grouping.group([...selected.values()].sort((left, right) => left.line - right.line))\n .slice(0, remaining)\n // Source is needed only for returned symbols, and is released before\n // moving to the next file. Overflow files never load symbol source.\n const contents = new Map<string, ReadonlyArray<string>>()\n if (input.symbols) {\n const source = yield* fileSystem.readFileString(file).pipe(Effect.orElseSucceed(() => undefined))\n if (source !== undefined) contents.set(file, Grouping.sourceLines(source))\n }\n shownMatches.push(...Grouping.annotate(grouped, contents))\n }\n\n const truncated = total > input.limit\n const unsatisfiable = total > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: input.globs,\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n matches: shownMatches,\n files: shownFiles,\n filesSearched,\n skippedBinary,\n truncated,\n ...(truncated\n ? { notice: notice(input.filesWithMatches ? \"files\" : \"matches\", input.limit, total) }\n : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\nconst glob = (\n input: Search.GlobInput\n): Effect.Effect<Search.GlobOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs([input.pattern], relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const included = yield* candidates(fileSystem, path, walked, input.root, [input.pattern])\n const matching = [...included].sort()\n const paths = matching.slice(0, input.limit)\n const unsatisfiable = matching.length > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: [input.pattern],\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n paths,\n total: matching.length,\n truncated: matching.length > input.limit,\n ...(matching.length > input.limit ? { notice: notice(\"entries\", paths.length, matching.length) } : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\n/**\n * Captures filesystem and path services in the portable peer.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const make = (services: Context.Context<FileSystem.FileSystem | Path.Path>): Search.Search =>\n Search.make({\n grep: (input) => Effect.provide(grep(input), services),\n glob: (input) => Effect.provide(glob(input), services)\n })\n\n/**\n * Provides the in-process peer.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layer: Layer.Layer<Search.Search, never, FileSystem.FileSystem | Path.Path> = Layer.effect(\n Search.Search,\n Effect.map(Effect.context<FileSystem.FileSystem | Path.Path>(), make)\n)\n"]}
|
|
1
|
+
{"version":3,"file":"PortableSearch.js","sourceRoot":"","sources":["../../src/PortableSearch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,IAAI,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QA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C,EAAE,QAAQ,CAAC;CACvD,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAyE,KAAK,CAAC,MAAM,CACrG,MAAM,CAAC,MAAM,EACb,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAqC,EAAE,IAAI,CAAC,CACtE,CAAA","sourcesContent":["/**\n * The in-process implementation of the ripgrep search contract.\n *\n * @since 1.0.0\n */\n\nimport * as Path from \"@smthrs/kernel/Path\"\nimport { type Context, Effect, Layer, Stream } from \"effect\"\nimport * as FileSystem from \"effect/FileSystem\"\nimport * as Grouping from \"./internal/Grouping.ts\"\nimport * as LinearRegex from \"./internal/LinearRegex.ts\"\nimport { escapeRegex } from \"./internal/SearchContract.ts\"\nimport { notice, truncateBytes } from \"./internal/Text.ts\"\nimport * as Walk from \"./internal/Walk.ts\"\nimport * as Search from \"./Search.ts\"\nimport * as Contract from \"./SearchContract.ts\"\nimport * as StdError from \"./StdError.ts\"\n\n/**\n * Narrows a walk to the files a search reports.\n *\n * A root that names one file is that file: `rg` searches a path given on the\n * command line whatever `-g` says, and follows it even when it is a symlink.\n * Everything a walk found is filtered by the globs first and probed for\n * symlinks second, so the probe runs over the far smaller included set.\n */\nconst candidates = (\n fileSystem: FileSystem.FileSystem,\n path: Path.Path,\n walked: Walk.Walked,\n root: string,\n globs: ReadonlyArray<string>\n): Effect.Effect<ReadonlyArray<string>> =>\n Effect.gen(function*() {\n if (walked.explicitFile) return walked.files\n const included = walked.files.filter((file) =>\n Contract.includedByGlobs(globs, Walk.relativeForPattern(path, root, file), path.basename(file))\n )\n const links = yield* Walk.symbolicLinks(fileSystem, included)\n return included.filter((_, index) => links[index] !== true)\n })\n\nconst preview = (line: string): string => {\n let head = \"\"\n let length = 0\n for (const character of line) {\n if (length++ === 500) break\n head += character\n }\n return truncateBytes(head, 500, { keep: \"head\" }).text\n}\n\nconst grep = (\n input: Search.GrepInput\n): Effect.Effect<Search.GrepOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs(input.globs, relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const insensitive = input.ignoreCase || (input.smartCase && !/[A-Z]/.test(input.pattern))\n const regex = LinearRegex.compile(\n input.fixedStrings ? escapeRegex(input.pattern) : input.pattern,\n insensitive\n )\n const shownMatches: Array<Search.GrepMatch> = []\n const shownFiles: Array<string> = []\n let total = 0\n let filesSearched = 0\n let skippedBinary = 0\n\n const included = yield* candidates(fileSystem, path, walked, input.root, input.globs)\n for (const file of included) {\n // Count every admitted file, including unreadable files and binaries.\n filesSearched++\n const remaining = input.filesWithMatches ? 0 : input.limit - shownMatches.length\n const matched: Array<number> = []\n const selected = new Map<number, Search.GrepLine>()\n const recent = new Map<number, Search.GrepLine>()\n let count = 0\n let lineNumber = 0\n let through = 0\n const scanLine = (text: string) =>\n Effect.gen(function*() {\n lineNumber++\n let matches = false\n if (input.maxCount === undefined || count < input.maxCount) {\n const evaluation = regex.test(text)\n let step = evaluation.next()\n while (!step.done) {\n yield* Effect.yieldNow\n step = evaluation.next()\n }\n matches = step.value\n }\n if (matches) count++\n if (remaining <= 0) return\n // The first overflow hit is a boundary: context nearest to it must\n // not migrate to the last retained hit when the limit is applied.\n const retain = matches && matched.length < remaining + 1\n const awaiting = matched.length < remaining + 1\n if (retain || lineNumber <= through || (awaiting && input.beforeContext > 0)) {\n const row: Search.GrepLine = {\n file,\n line: lineNumber,\n text: preview(text),\n kind: retain ? \"match\" : \"context\"\n }\n if (retain) {\n matched.push(lineNumber)\n for (const [number, context] of recent) selected.set(number, context)\n through = lineNumber + input.afterContext\n }\n if (retain || lineNumber <= through) selected.set(lineNumber, row)\n if (awaiting && input.beforeContext > 0) recent.set(lineNumber, row)\n }\n recent.delete(lineNumber - input.beforeContext)\n if (matched.length >= remaining + 1) recent.clear()\n })\n // Split only on LF (stripping a preceding CR), just like sourceLines.\n // Stream.splitLines also treats a standalone CR as a delimiter.\n const decoder = new TextDecoder()\n let fragments: Array<string> = []\n const consume = (chunk: string) =>\n Effect.gen(function*() {\n let from = 0\n let newline = chunk.indexOf(\"\\n\")\n while (newline >= 0) {\n fragments.push(chunk.slice(from, newline))\n const line = fragments.join(\"\")\n fragments = []\n yield* scanLine(line.endsWith(\"\\r\") ? line.slice(0, -1) : line)\n from = newline + 1\n newline = chunk.indexOf(\"\\n\", from)\n }\n if (from < chunk.length) fragments.push(chunk.slice(from))\n })\n const scanned = yield* Effect.gen(function*() {\n let started = false\n // A guarded disk host can safely expose atomic reads while refusing\n // open streaming handles. Retry through that same filesystem service\n // only before any bytes arrive, so a failed partial stream is never\n // combined with a second reading of a file that may have changed.\n yield* fileSystem.stream(file).pipe(\n Stream.catch((error) => started ? Stream.fail(error) : Stream.fromEffect(fileSystem.readFile(file))),\n Stream.runForEach((bytes) => {\n started = true\n if (bytes.includes(0)) {\n return Effect.fail(\n new StdError.StdError({\n code: \"binary_file\",\n message: `Cannot search binary file: ${file}`,\n path: file\n })\n )\n }\n return consume(decoder.decode(bytes, { stream: true }))\n })\n )\n yield* consume(decoder.decode())\n if (fragments.length > 0) yield* scanLine(fragments.join(\"\"))\n return true\n }).pipe(Effect.catch((error) => {\n if (error instanceof StdError.StdError) {\n if (walked.explicitFile) return Effect.fail(error)\n skippedBinary++\n }\n return Effect.succeed(false)\n }))\n if (!scanned || count === 0) continue\n total += input.filesWithMatches ? 1 : count\n if (input.filesWithMatches) {\n if (shownFiles.length < input.limit) shownFiles.push(file)\n continue\n }\n if (matched.length === 0) continue\n const grouped = Grouping.group([...selected.values()].sort((left, right) => left.line - right.line))\n .slice(0, remaining)\n // Source is needed only for returned symbols, and is released before\n // moving to the next file. Overflow files never load symbol source.\n const contents = new Map<string, ReadonlyArray<string>>()\n if (input.symbols) {\n const source = yield* fileSystem.readFileString(file).pipe(Effect.orElseSucceed(() => undefined))\n if (source !== undefined) contents.set(file, Grouping.sourceLines(source))\n }\n shownMatches.push(...Grouping.annotate(grouped, contents))\n }\n\n const truncated = total > input.limit\n const unsatisfiable = total > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: input.globs,\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n matches: shownMatches,\n files: shownFiles,\n filesSearched,\n skippedBinary,\n truncated,\n ...(truncated\n ? { notice: notice(input.filesWithMatches ? \"files\" : \"matches\", input.limit, total) }\n : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\nconst glob = (\n input: Search.GlobInput\n): Effect.Effect<Search.GlobOutput, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const includedByGlobs = (relative: string, basename: string) =>\n Contract.includedByGlobs([input.pattern], relative, basename)\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore, includedByGlobs)\n const included = yield* candidates(fileSystem, path, walked, input.root, [input.pattern])\n const matching = [...included].sort()\n const paths = matching.slice(0, input.limit)\n const unsatisfiable = matching.length > 0 ? undefined : yield* Contract.unsatisfiableNotice({\n fileSystem,\n path,\n root: input.root,\n globs: [input.pattern],\n hidden: input.hidden,\n noIgnore: input.noIgnore,\n ignored: walked.ignored\n })\n return {\n paths,\n total: matching.length,\n truncated: matching.length > input.limit,\n ...(matching.length > input.limit ? { notice: notice(\"entries\", paths.length, matching.length) } : {}),\n ...(unsatisfiable === undefined ? {} : { notice: unsatisfiable })\n }\n })\n\n/**\n * The files this peer's `grep` reads for `input`, in the order it reads\n * them: the walk under `input.root` with its `.gitignore` rules and\n * `input.globs` applied and symbolic links left out, or the root itself when\n * it names one file. A peer that has to bring a tree's bytes to this process\n * before it can search them (`RemoteSearch`) fetches exactly these.\n *\n * @category queries\n * @since 1.0.0-rc.8\n */\nexport const searched = (\n input: Pick<Search.GrepInput, \"root\" | \"hidden\" | \"noIgnore\" | \"globs\">\n): Effect.Effect<ReadonlyArray<string>, StdError.StdError, FileSystem.FileSystem | Path.Path> =>\n Effect.gen(function*() {\n const fileSystem = yield* FileSystem.FileSystem\n const path = yield* Path.Path\n const walked = yield* Walk.files(fileSystem, path, input.root, input.hidden, input.noIgnore)\n return yield* candidates(fileSystem, path, walked, input.root, input.globs)\n })\n\n/**\n * Captures filesystem and path services in the portable peer.\n *\n * @category constructors\n * @since 1.0.0\n */\nexport const make = (services: Context.Context<FileSystem.FileSystem | Path.Path>): Search.Search =>\n Search.make({\n grep: (input) => Effect.provide(grep(input), services),\n glob: (input) => Effect.provide(glob(input), services)\n })\n\n/**\n * Provides the in-process peer.\n *\n * @category layers\n * @since 1.0.0\n */\nexport const layer: Layer.Layer<Search.Search, never, FileSystem.FileSystem | Path.Path> = Layer.effect(\n Search.Search,\n Effect.map(Effect.context<FileSystem.FileSystem | Path.Path>(), make)\n)\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The search contract for a tree on another machine, in two round trips.
|
|
3
|
+
*
|
|
4
|
+
* `PortableSearch` asks `FileSystem` one question per directory, per entry
|
|
5
|
+
* and per file. On a machine reached through a transport, such as a
|
|
6
|
+
* benchmark's task container behind `docker exec`, every question is a
|
|
7
|
+
* process start, so one `grep` over a 6,000-file repository is some 20,000 of
|
|
8
|
+
* them. This peer asks the machine's own shell twice instead. `find` lists
|
|
9
|
+
* the tree under the root, leaving out the directories every walk skips, and
|
|
10
|
+
* `tar` returns its `.gitignore` files with the listing. The in-process peer
|
|
11
|
+
* then decides which files the search reads, a second `tar` returns exactly
|
|
12
|
+
* those, and `PortableSearch` answers over that copy. Every result, notice,
|
|
13
|
+
* and refusal is therefore the in-process peer's own: this module decides
|
|
14
|
+
* only where the bytes come from.
|
|
15
|
+
*
|
|
16
|
+
* It runs through the machine's own `ChildProcessSpawner`, the one
|
|
17
|
+
* `Sandbox.hostContext` serves beside the machine's `FileSystem`. The machine
|
|
18
|
+
* needs `sh`, `find`, `xargs`, `tar`, `head`, and `base64`; GNU, BusyBox, and
|
|
19
|
+
* BSD userlands all have them. Output crosses as base64, so a transport whose
|
|
20
|
+
* channel carries only text returns it intact. A search reads at most
|
|
21
|
+
* {@link maxBytes} of file content and refuses beyond that, naming the root
|
|
22
|
+
* to narrow.
|
|
23
|
+
*
|
|
24
|
+
* @since 1.0.0-rc.8
|
|
25
|
+
*/
|
|
26
|
+
import type * as ChildProcessSpawner from "@smthrs/kernel/ChildProcessSpawner";
|
|
27
|
+
import * as Path from "@smthrs/kernel/Path";
|
|
28
|
+
import { Context } from "effect";
|
|
29
|
+
import * as Search from "./Search.ts";
|
|
30
|
+
/**
|
|
31
|
+
* The most file content one search brings back from the machine.
|
|
32
|
+
*
|
|
33
|
+
* The copy is held in memory while the in-process peer reads it, so the
|
|
34
|
+
* bound is on this process's memory rather than on the search: a root that
|
|
35
|
+
* holds more is refused with `response_too_large` and a narrower root or
|
|
36
|
+
* globs answer it.
|
|
37
|
+
*
|
|
38
|
+
* @category constants
|
|
39
|
+
* @since 1.0.0-rc.8
|
|
40
|
+
*/
|
|
41
|
+
export declare const maxBytes: number;
|
|
42
|
+
/**
|
|
43
|
+
* Builds the peer over a machine's spawner and its `Path`, which resolves a
|
|
44
|
+
* relative root where the machine's file operations do. `maxBytes` lowers
|
|
45
|
+
* the bound on the file content one search brings back; the default is
|
|
46
|
+
* {@link maxBytes}.
|
|
47
|
+
*
|
|
48
|
+
* @category constructors
|
|
49
|
+
* @since 1.0.0-rc.8
|
|
50
|
+
*/
|
|
51
|
+
export declare const make: (services: Context.Context<ChildProcessSpawner.ChildProcessSpawner | Path.Path>, options?: {
|
|
52
|
+
readonly maxBytes?: number | undefined;
|
|
53
|
+
}) => Search.Search;
|
|
54
|
+
//# sourceMappingURL=RemoteSearch.d.ts.map
|