@smthrs/std 1.0.0-rc.6 → 1.0.0-rc.8
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 +4 -0
- package/README.md +39 -37
- package/dist/cjs/Bash.d.ts +10 -0
- package/dist/cjs/Bash.d.ts.map +1 -1
- package/dist/cjs/Bash.js +13 -12
- package/dist/cjs/Bash.js.map +3 -3
- 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/internal/EnvelopePrecheck.d.ts +2 -0
- package/dist/cjs/internal/EnvelopePrecheck.d.ts.map +1 -1
- package/dist/cjs/internal/EnvelopePrecheck.js +217 -34
- package/dist/cjs/internal/EnvelopePrecheck.js.map +3 -3
- package/dist/cjs/internal/Exec.d.ts +26 -14
- package/dist/cjs/internal/Exec.d.ts.map +1 -1
- package/dist/cjs/internal/Exec.js +73 -31
- package/dist/cjs/internal/Exec.js.map +2 -2
- package/dist/cjs/internal/Text.d.ts +11 -0
- package/dist/cjs/internal/Text.d.ts.map +1 -1
- package/dist/cjs/internal/Text.js +3 -0
- package/dist/cjs/internal/Text.js.map +2 -2
- package/dist/esm/Bash.d.ts +10 -0
- package/dist/esm/Bash.d.ts.map +1 -1
- package/dist/esm/Bash.js +22 -13
- package/dist/esm/Bash.js.map +1 -1
- 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/internal/EnvelopePrecheck.d.ts +2 -0
- package/dist/esm/internal/EnvelopePrecheck.d.ts.map +1 -1
- package/dist/esm/internal/EnvelopePrecheck.js +295 -60
- package/dist/esm/internal/EnvelopePrecheck.js.map +1 -1
- package/dist/esm/internal/Exec.d.ts +26 -14
- package/dist/esm/internal/Exec.d.ts.map +1 -1
- package/dist/esm/internal/Exec.js +116 -30
- package/dist/esm/internal/Exec.js.map +1 -1
- package/dist/esm/internal/Text.d.ts +11 -0
- package/dist/esm/internal/Text.d.ts.map +1 -1
- package/dist/esm/internal/Text.js +11 -0
- package/dist/esm/internal/Text.js.map +1 -1
- package/docs/README.md +3 -1
- package/docs/api.md +21 -18
- package/docs/concepts/limits-and-disclosure.md +8 -5
- package/docs/guides/pin-a-checkpoint.md +20 -0
- package/docs/guides/run-a-shell-command.md +16 -6
- package/docs/installation.md +13 -9
- package/docs/quickstart.md +1 -1
- package/docs/reference/flows.md +2 -2
- package/docs/troubleshooting.md +15 -3
- package/package.json +6 -6
- package/src/Bash.ts +25 -13
- package/src/Checkpoints.ts +137 -0
- package/src/internal/EnvelopePrecheck.ts +295 -63
- package/src/internal/Exec.ts +157 -51
- package/src/internal/Text.ts +15 -0
|
@@ -20,6 +20,7 @@ import * as ChildProcess from "effect/process/ChildProcess";
|
|
|
20
20
|
import * as Schema from "effect/Schema";
|
|
21
21
|
import * as Stream from "effect/Stream";
|
|
22
22
|
import * as StdError from "../StdError.js";
|
|
23
|
+
import { elideMiddle } from "./Text.js";
|
|
23
24
|
/**
|
|
24
25
|
* Failure codes a buffered execution can report, matching the codes the
|
|
25
26
|
* removed kernel `Shell` used so handler-level mapping is unchanged.
|
|
@@ -27,13 +28,15 @@ import * as StdError from "../StdError.js";
|
|
|
27
28
|
* @category models
|
|
28
29
|
* @since 1.0.0
|
|
29
30
|
*/
|
|
30
|
-
export const ExecErrorCode = Schema.Literals(["timeout", "spawn_error", "capture_overflow"]);
|
|
31
|
+
export const ExecErrorCode = Schema.Literals(["timeout", "spawn_error", "arguments_too_long", "capture_overflow"]);
|
|
31
32
|
/**
|
|
32
33
|
* A command that never produced an exit code.
|
|
33
34
|
*
|
|
34
35
|
* A non-zero exit is a successful {@link ExecResult}, not a failure; this
|
|
35
|
-
* error is reserved for a command that could not start
|
|
36
|
-
*
|
|
36
|
+
* error is reserved for a command that could not start (`arguments_too_long`
|
|
37
|
+
* when the operating system refused it for the size of its arguments) or was
|
|
38
|
+
* cut off by its timeout, or whose captured output exceeded a refusing capture
|
|
39
|
+
* bound.
|
|
37
40
|
*
|
|
38
41
|
* @category errors
|
|
39
42
|
* @since 1.0.0
|
|
@@ -46,32 +49,22 @@ export class ExecError extends Schema.TaggedError()("@smthrs/std/ExecError", {
|
|
|
46
49
|
}) {
|
|
47
50
|
}
|
|
48
51
|
const decoder = new TextDecoder("utf-8");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* bytes, so at most three leading continuation bytes can precede the first
|
|
55
|
-
* whole character. Skipping them is counted as dropped rather than decoded to a
|
|
56
|
-
* replacement character the process never printed.
|
|
57
|
-
*/
|
|
58
|
-
const decodeTail = (state) => {
|
|
59
|
-
const bytes = new Uint8Array(state.bytes);
|
|
52
|
+
const emptyTail = () => ({ chunks: [], bytes: 0, dropped: 0 });
|
|
53
|
+
/** A UTF-8 continuation byte is `10xxxxxx`; every other byte starts a character. */
|
|
54
|
+
const isContinuation = (byte) => (byte & 0b1100_0000) === 0b1000_0000;
|
|
55
|
+
const join = (chunks, size) => {
|
|
56
|
+
const bytes = new Uint8Array(size);
|
|
60
57
|
let offset = 0;
|
|
61
|
-
for (const chunk of
|
|
58
|
+
for (const chunk of chunks) {
|
|
62
59
|
bytes.set(chunk, offset);
|
|
63
60
|
offset += chunk.byteLength;
|
|
64
61
|
}
|
|
65
|
-
|
|
66
|
-
return { text: decoder.decode(bytes), droppedBytes: 0 };
|
|
67
|
-
let start = 0;
|
|
68
|
-
while (start < bytes.byteLength && start < 3 && (bytes[start] & 0b1100_0000) === 0b1000_0000)
|
|
69
|
-
start++;
|
|
70
|
-
return { text: decoder.decode(bytes.subarray(start)), droppedBytes: state.dropped + start };
|
|
62
|
+
return bytes;
|
|
71
63
|
};
|
|
72
|
-
|
|
64
|
+
/** Appends one chunk and drops from the front whatever no longer fits. */
|
|
65
|
+
const keepTail = (state, chunk, maxBytes) => {
|
|
73
66
|
if (chunk.byteLength === 0)
|
|
74
|
-
return
|
|
67
|
+
return;
|
|
75
68
|
state.chunks.push(chunk);
|
|
76
69
|
state.bytes += chunk.byteLength;
|
|
77
70
|
while (state.bytes > maxBytes && state.chunks.length > 0) {
|
|
@@ -88,13 +81,101 @@ const boundedTail = (stream, maxBytes, overflow) => Stream.runFold(stream, () =>
|
|
|
88
81
|
state.dropped += excess;
|
|
89
82
|
}
|
|
90
83
|
}
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Joins the retained chunks and decodes them, skipping the partial code point a
|
|
87
|
+
* dropped head can leave behind.
|
|
88
|
+
*
|
|
89
|
+
* A code point is at most four bytes, so at most three leading continuation
|
|
90
|
+
* bytes can precede the first whole character. Skipping them is counted as
|
|
91
|
+
* dropped rather than decoded to a replacement character the process never
|
|
92
|
+
* printed.
|
|
93
|
+
*/
|
|
94
|
+
const decodeTail = (state) => {
|
|
95
|
+
const bytes = join(state.chunks, state.bytes);
|
|
96
|
+
if (state.dropped === 0)
|
|
97
|
+
return { text: decoder.decode(bytes), droppedBytes: 0 };
|
|
98
|
+
let start = 0;
|
|
99
|
+
while (start < bytes.byteLength && start < 3 && isContinuation(bytes[start]))
|
|
100
|
+
start++;
|
|
101
|
+
return { text: decoder.decode(bytes.subarray(start)), droppedBytes: state.dropped + start };
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The length of a cut head without the character the cut left unfinished.
|
|
105
|
+
*
|
|
106
|
+
* Its last character starts at the last byte that is not a continuation byte,
|
|
107
|
+
* and that byte says how many bytes the character needs. One that needs more
|
|
108
|
+
* than the head holds is dropped, for the same reason {@link decodeTail} skips
|
|
109
|
+
* a partial code point.
|
|
110
|
+
*/
|
|
111
|
+
const wholeLength = (bytes) => {
|
|
112
|
+
for (let back = 1; back <= Math.min(3, bytes.byteLength); back++) {
|
|
113
|
+
const byte = bytes[bytes.byteLength - back];
|
|
114
|
+
if (isContinuation(byte))
|
|
115
|
+
continue;
|
|
116
|
+
const width = byte >= 0b1111_0000 ? 4 : byte >= 0b1110_0000 ? 3 : byte >= 0b1100_0000 ? 2 : 1;
|
|
117
|
+
return width > back ? bytes.byteLength - back : bytes.byteLength;
|
|
118
|
+
}
|
|
119
|
+
return bytes.byteLength;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Decodes a stream kept by its ends. A stream that fit is decoded whole;
|
|
123
|
+
* otherwise each end is cut on a character boundary and one line naming every
|
|
124
|
+
* byte between them stands where the middle was.
|
|
125
|
+
*/
|
|
126
|
+
const decodeEnds = (state) => {
|
|
127
|
+
if (state.tail.dropped === 0) {
|
|
128
|
+
const whole = join([...state.head, ...state.tail.chunks], state.headBytes + state.tail.bytes);
|
|
129
|
+
return { text: decoder.decode(whole), droppedBytes: 0 };
|
|
130
|
+
}
|
|
131
|
+
const head = join(state.head, state.headBytes);
|
|
132
|
+
const kept = wholeLength(head);
|
|
133
|
+
const tail = decodeTail(state.tail);
|
|
134
|
+
const droppedBytes = head.byteLength - kept + tail.droppedBytes;
|
|
135
|
+
return { text: elideMiddle(decoder.decode(head.subarray(0, kept)), droppedBytes, tail.text), droppedBytes };
|
|
136
|
+
};
|
|
137
|
+
const boundedTail = (stream, maxBytes, overflow) => Stream.runFold(stream, emptyTail, (state, chunk) => {
|
|
138
|
+
keepTail(state, chunk, maxBytes);
|
|
91
139
|
return state;
|
|
92
140
|
}).pipe(Effect.map((state) => overflow === "refuse" && state.dropped > 0
|
|
93
141
|
? { text: "", droppedBytes: state.dropped }
|
|
94
142
|
: decodeTail(state)));
|
|
143
|
+
/**
|
|
144
|
+
* Keeps the first half of the bound and the last half. The head fills first,
|
|
145
|
+
* and every byte after it passes through the tail, which drops from its front:
|
|
146
|
+
* what falls out of the tail is the middle.
|
|
147
|
+
*/
|
|
148
|
+
const boundedEnds = (stream, maxBytes) => {
|
|
149
|
+
const headBytes = Math.floor(maxBytes / 2);
|
|
150
|
+
return Stream.runFold(stream, () => ({ head: [], headBytes: 0, tail: emptyTail() }), (state, chunk) => {
|
|
151
|
+
const taken = Math.min(headBytes - state.headBytes, chunk.byteLength);
|
|
152
|
+
if (taken > 0) {
|
|
153
|
+
state.head.push(chunk.subarray(0, taken));
|
|
154
|
+
state.headBytes += taken;
|
|
155
|
+
}
|
|
156
|
+
keepTail(state.tail, chunk.subarray(taken), maxBytes - headBytes);
|
|
157
|
+
return state;
|
|
158
|
+
}).pipe(Effect.map(decodeEnds));
|
|
159
|
+
};
|
|
95
160
|
const capture = (stream, maxBytes, overflow) => maxBytes === undefined
|
|
96
161
|
? Effect.map(Stream.mkString(Stream.decodeText(stream)), (text) => ({ text, droppedBytes: 0 }))
|
|
97
|
-
:
|
|
162
|
+
: overflow === "ends"
|
|
163
|
+
? boundedEnds(stream, maxBytes)
|
|
164
|
+
: boundedTail(stream, maxBytes, overflow);
|
|
165
|
+
/**
|
|
166
|
+
* A command whose arguments exceed the operating system's limit fails `execve`
|
|
167
|
+
* with `E2BIG` before it starts: one argument over 128 KiB on Linux, all of
|
|
168
|
+
* them over 1 MiB on macOS. A heredoc in a command line, or a file's text
|
|
169
|
+
* passed as an argument, is one such argument. The platform error's own text
|
|
170
|
+
* repeats the whole command line, so this text is written here instead, and a
|
|
171
|
+
* caller may show it as it stands.
|
|
172
|
+
*/
|
|
173
|
+
const argumentsTooLong = (error) => error.cause?.code === "E2BIG"
|
|
174
|
+
? new ExecError({
|
|
175
|
+
code: "arguments_too_long",
|
|
176
|
+
message: "Command not started: its arguments exceed the operating system's size limit (E2BIG). Send long text on standard input or in a file, not in the command line or its arguments."
|
|
177
|
+
})
|
|
178
|
+
: undefined;
|
|
98
179
|
const unbounded = (command, options) => Effect.gen(function* () {
|
|
99
180
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
100
181
|
const settings = {
|
|
@@ -137,7 +218,7 @@ const unbounded = (command, options) => Effect.gen(function* () {
|
|
|
137
218
|
stdoutDroppedBytes: stdout.droppedBytes,
|
|
138
219
|
stderrDroppedBytes: stderr.droppedBytes
|
|
139
220
|
};
|
|
140
|
-
}).pipe(Effect.scoped, Effect.mapError((error) => error instanceof ExecError ? error : new ExecError({
|
|
221
|
+
}).pipe(Effect.scoped, Effect.mapError((error) => error instanceof ExecError ? error : argumentsTooLong(error) ?? new ExecError({
|
|
141
222
|
code: "spawn_error",
|
|
142
223
|
message: `exec: ${command}: ${error.message}`
|
|
143
224
|
})));
|
|
@@ -167,18 +248,21 @@ export const exec = (command, options = {}) => options.timeoutMs === undefined
|
|
|
167
248
|
*
|
|
168
249
|
* A timeout keeps its own code, because "the command never finished" and "the
|
|
169
250
|
* command never started" are different things to a caller deciding whether to
|
|
170
|
-
* retry.
|
|
251
|
+
* retry. Arguments the operating system refused for their size are the
|
|
252
|
+
* caller's own input, which a shell flow publishes, so they read as
|
|
253
|
+
* `invalid_input`. Every other way of producing no exit code is a host failure.
|
|
171
254
|
*
|
|
172
255
|
* @category errors
|
|
173
256
|
* @since 1.0.0
|
|
174
257
|
*/
|
|
175
|
-
export const toStdErrorCode = (error) => error.code === "timeout" ? "timeout" : "command_failed";
|
|
258
|
+
export const toStdErrorCode = (error) => error.code === "timeout" ? "timeout" : error.code === "arguments_too_long" ? "invalid_input" : "command_failed";
|
|
176
259
|
/**
|
|
177
260
|
* The model-facing failure one execution error becomes.
|
|
178
261
|
*
|
|
179
262
|
* A timeout names the command, which is what the caller asked for and all a
|
|
180
|
-
* timeout has to say.
|
|
181
|
-
*
|
|
263
|
+
* timeout has to say. Arguments too long to start carry the reason and the
|
|
264
|
+
* fix, and nothing of the command. Any other failure carries the message the
|
|
265
|
+
* execution produced, which already names the command.
|
|
182
266
|
*
|
|
183
267
|
* @category errors
|
|
184
268
|
* @since 1.0.0
|
|
@@ -187,7 +271,9 @@ export const toStdError = (command, error) => new StdError.StdError({
|
|
|
187
271
|
code: toStdErrorCode(error),
|
|
188
272
|
message: error.code === "timeout"
|
|
189
273
|
? `Command timed out: ${command}`
|
|
190
|
-
:
|
|
274
|
+
: error.code === "arguments_too_long"
|
|
275
|
+
? error.message
|
|
276
|
+
: `Command failed to start: ${error.message}`,
|
|
191
277
|
...(error.limitMillis === undefined ? {} : { limitMillis: error.limitMillis })
|
|
192
278
|
});
|
|
193
279
|
//# sourceMappingURL=Exec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Exec.js","sourceRoot":"","sources":["../../../src/internal/Exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,uBAAuB,MAAM,wCAAwC,CAAA;AACjF,OAAO,KAAK,mBAAmB,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAA;AAC3D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,kBAAkB,CAAC,CAAC,CAAA;AAU5F;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAU,SAAQ,MAAM,CAAC,WAAW,EAAa,CAAC,uBAAuB,EAAE;IACtF,IAAI,EAAE,aAAa;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;CAC5C,CAAC;CAAG;AAmEL,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,CAAC,CAAA;AAExC;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG,CAAC,KAAW,EAAW,EAAE;IAC1C,MAAM,KAAK,GAAG,IAAI,UA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AC/B,CAAC,CAAC,sBAAsB,OAAO,EAAE;QACjC,CAAC,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE;IAC/C,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;CAC/E,CAAC,CAAA","sourcesContent":["/**\n * Buffered shell execution over the permission-aware process spawner.\n *\n * `@smthrs/kernel` used to expose a `Shell` service whose `exec` returned a\n * buffered `{ stdout, stderr, exitCode }`. The kernel replaced it with\n * `ChildProcessSpawner`, Effect's own process boundary, which streams and has\n * no buffered form. This module is the buffered form the shell flows still\n * want, expressed in terms of the spawner so the `proc:spawn` capability check\n * and the command-line resource stay exactly where the kernel put them.\n *\n * Commands run through the platform shell (`shell: true`), matching the old\n * service: the flows take a command *line*, not an argv.\n *\n * @since 1.0.0\n */\n\nimport * as ChildProcessEnvironment from \"@smthrs/kernel/ChildProcessEnvironment\"\nimport * as ChildProcessSpawner from \"@smthrs/kernel/ChildProcessSpawner\"\nimport * as Effect from \"effect/Effect\"\nimport * as ChildProcess from \"effect/process/ChildProcess\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport * as StdError from \"../StdError.ts\"\n\n/**\n * Failure codes a buffered execution can report, matching the codes the\n * removed kernel `Shell` used so handler-level mapping is unchanged.\n *\n * @category models\n * @since 1.0.0\n */\nexport const ExecErrorCode = Schema.Literals([\"timeout\", \"spawn_error\", \"capture_overflow\"])\n\n/**\n * Failure codes a buffered execution can report.\n *\n * @category models\n * @since 1.0.0\n */\nexport type ExecErrorCode = typeof ExecErrorCode.Type\n\n/**\n * A command that never produced an exit code.\n *\n * A non-zero exit is a successful {@link ExecResult}, not a failure; this\n * error is reserved for a command that could not start or was cut off by its\n * timeout, or whose captured output exceeded a refusing capture bound.\n *\n * @category errors\n * @since 1.0.0\n */\nexport class ExecError extends Schema.TaggedError<ExecError>()(\"@smthrs/std/ExecError\", {\n code: ExecErrorCode,\n message: Schema.String,\n /** The limit a `timeout` ran past, in milliseconds. */\n limitMillis: Schema.optional(Schema.Number)\n}) {}\n\n/**\n * The buffered result of one command.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface ExecResult {\n readonly stdout: string\n readonly stderr: string\n readonly exitCode: number\n /** UTF-8 bytes dropped from the head of stdout to stay inside the capture bound. */\n readonly stdoutDroppedBytes: number\n /** UTF-8 bytes dropped from the head of stderr to stay inside the capture bound. */\n readonly stderrDroppedBytes: number\n}\n\n/**\n * Options accepted by {@link exec}.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface ExecOptions {\n readonly cwd?: string | undefined\n readonly env?: Readonly<Record<string, string>> | undefined\n readonly timeoutMs?: number | undefined\n /**\n * The program's arguments. Present means an argv, absent means a command\n * line for the platform shell. An argv is how a payload reaches a program\n * without being quoted into a string: nothing between here and `execve`\n * re-parses it.\n */\n readonly args?: ReadonlyArray<string> | undefined\n /**\n * Text written to the program's standard input, as data. A script delivered\n * this way is never quoted, escaped, or heredoc-terminated, which is the\n * whole point: quoting corruption cost the measured SWE-bench program twelve\n * probe failures and one instance's most expensive frame.\n */\n readonly stdin?: string | undefined\n /**\n * Bytes retained per captured stream. A stream that prints more keeps its\n * tail and reports what it dropped, so a command printing gigabytes costs a\n * bounded amount of memory rather than the whole of what it printed.\n *\n * Absent means unbounded, which is what a caller wants when it needs every\n * byte a tool produced (`rg --files`, `git worktree list`).\n */\n readonly maxCaptureBytes?: number | undefined\n /** Defaults to `tail`; `refuse` fails if either stream exceeds the bound. */\n readonly overflow?: \"tail\" | \"refuse\" | undefined\n}\n\n/** One captured stream: the text kept, and the bytes dropped to keep it bounded. */\ninterface Capture {\n readonly text: string\n readonly droppedBytes: number\n}\n\ninterface Tail {\n chunks: Array<Uint8Array>\n bytes: number\n dropped: number\n}\n\nconst decoder = new TextDecoder(\"utf-8\")\n\n/**\n * Joins the retained chunks and decodes them, skipping the partial code point a\n * dropped head can leave behind.\n *\n * A UTF-8 continuation byte is `10xxxxxx`, and a code point is at most four\n * bytes, so at most three leading continuation bytes can precede the first\n * whole character. Skipping them is counted as dropped rather than decoded to a\n * replacement character the process never printed.\n */\nconst decodeTail = (state: Tail): Capture => {\n const bytes = new Uint8Array(state.bytes)\n let offset = 0\n for (const chunk of state.chunks) {\n bytes.set(chunk, offset)\n offset += chunk.byteLength\n }\n if (state.dropped === 0) return { text: decoder.decode(bytes), droppedBytes: 0 }\n let start = 0\n while (start < bytes.byteLength && start < 3 && (bytes[start]! & 0b1100_0000) === 0b1000_0000) start++\n return { text: decoder.decode(bytes.subarray(start)), droppedBytes: state.dropped + start }\n}\n\nconst boundedTail = <E>(\n stream: Stream.Stream<Uint8Array, E>,\n maxBytes: number,\n overflow: \"tail\" | \"refuse\" | undefined\n): Effect.Effect<Capture, E> =>\n Stream.runFold(\n stream,\n (): Tail => ({ chunks: [], bytes: 0, dropped: 0 }),\n (state, chunk) => {\n if (chunk.byteLength === 0) return state\n state.chunks.push(chunk)\n state.bytes += chunk.byteLength\n while (state.bytes > maxBytes && state.chunks.length > 0) {\n const excess = state.bytes - maxBytes\n const first = state.chunks[0]!\n if (first.byteLength <= excess) {\n state.chunks.shift()\n state.bytes -= first.byteLength\n state.dropped += first.byteLength\n } else {\n state.chunks[0] = first.subarray(excess)\n state.bytes -= excess\n state.dropped += excess\n }\n }\n return state\n }\n ).pipe(Effect.map((state) =>\n overflow === \"refuse\" && state.dropped > 0\n ? { text: \"\", droppedBytes: state.dropped }\n : decodeTail(state)\n ))\n\nconst capture = <E>(\n stream: Stream.Stream<Uint8Array, E>,\n maxBytes: number | undefined,\n overflow: \"tail\" | \"refuse\" | undefined\n): Effect.Effect<Capture, E> =>\n maxBytes === undefined\n ? Effect.map(Stream.mkString(Stream.decodeText(stream)), (text) => ({ text, droppedBytes: 0 }))\n : boundedTail(stream, maxBytes, overflow)\n\nconst unbounded = (\n command: string,\n options: ExecOptions\n): Effect.Effect<ExecResult, ExecError, ChildProcessSpawner.ChildProcessSpawner> =>\n Effect.gen(function*() {\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n const settings: ChildProcess.CommandOptions = {\n ...(options.args === undefined ? { shell: true } : {}),\n ...(options.cwd === undefined ? {} : { cwd: options.cwd }),\n env: ChildProcessEnvironment.make(process.env, options.env),\n extendEnv: false,\n ...(options.stdin === undefined\n ? {}\n : { stdin: Stream.make(new TextEncoder().encode(options.stdin)) })\n }\n const handle = yield* spawner.spawn(\n options.args === undefined\n ? ChildProcess.make(command, settings)\n : ChildProcess.make(command, [...options.args], settings)\n )\n // stdout, stderr, and the exit code have to be consumed concurrently: a\n // command that fills a pipe blocks until the pipe is drained, so waiting\n // for exit first would deadlock on any output larger than the buffer.\n const [stdout, stderr, exitCode] = yield* Effect.all(\n [\n capture(handle.stdout, options.maxCaptureBytes, options.overflow),\n capture(handle.stderr, options.maxCaptureBytes, options.overflow),\n handle.exitCode\n ],\n { concurrency: \"unbounded\" }\n )\n if (options.overflow === \"refuse\") {\n const overflowed = [\n stdout.droppedBytes > 0 ? \"stdout\" : undefined,\n stderr.droppedBytes > 0 ? \"stderr\" : undefined\n ]\n .filter((stream): stream is string => stream !== undefined)\n if (overflowed.length > 0) {\n return yield* Effect.fail(\n new ExecError({\n code: \"capture_overflow\",\n message: `${command} ${\n overflowed.join(\" and \")\n } exceeded the ${options.maxCaptureBytes}-byte capture cap; refusing partial output`\n })\n )\n }\n }\n return {\n stdout: stdout.text,\n stderr: stderr.text,\n exitCode,\n stdoutDroppedBytes: stdout.droppedBytes,\n stderrDroppedBytes: stderr.droppedBytes\n }\n }).pipe(\n Effect.scoped,\n Effect.mapError((error) =>\n error instanceof ExecError ? error : new ExecError({\n code: \"spawn_error\",\n message: `exec: ${command}: ${error.message}`\n })\n )\n )\n\n/**\n * Runs a command line through the platform shell and buffers its output.\n *\n * Cancellation is scope closure: the spawn is scoped, so an interrupted fiber\n * — including the one a `timeoutMs` interrupts — terminates the process rather\n * than leaking it.\n *\n * @category execution\n * @since 1.0.0\n */\nexport const exec = (\n command: string,\n options: ExecOptions = {}\n): Effect.Effect<ExecResult, ExecError, ChildProcessSpawner.ChildProcessSpawner> =>\n options.timeoutMs === undefined\n ? unbounded(command, options)\n : Effect.timeoutOrElse(unbounded(command, options), {\n duration: options.timeoutMs,\n orElse: () =>\n Effect.fail(\n new ExecError({\n code: \"timeout\",\n message: `exec: \\`${command}\\` exceeded ${options.timeoutMs}ms`,\n limitMillis: options.timeoutMs\n })\n )\n })\n\n/**\n * The model-facing failure code a command that never produced an exit code\n * carries.\n *\n * A timeout keeps its own code, because \"the command never finished\" and \"the\n * command never started\" are different things to a caller deciding whether to\n * retry. Every other way of producing no exit code is a host failure.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const toStdErrorCode = (error: ExecError): StdError.Code =>\n error.code === \"timeout\" ? \"timeout\" : \"command_failed\"\n\n/**\n * The model-facing failure one execution error becomes.\n *\n * A timeout names the command, which is what the caller asked for and all a\n * timeout has to say. Any other failure carries the message the execution\n * produced, which already names the command.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const toStdError = (command: string, error: ExecError): StdError.StdError =>\n new StdError.StdError({\n code: toStdErrorCode(error),\n message: error.code === \"timeout\"\n ? `Command timed out: ${command}`\n : `Command failed to start: ${error.message}`,\n ...(error.limitMillis === undefined ? {} : { limitMillis: error.limitMillis })\n })\n"]}
|
|
1
|
+
{"version":3,"file":"Exec.js","sourceRoot":"","sources":["../../../src/internal/Exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,uBAAuB,MAAM,wCAAwC,CAAA;AACjF,OAAO,KAAK,mBAAmB,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,6BAA6B,CAAA;AAC3D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,M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/B,CAAC,CACH;KACJ,CAAC,CAAA;AAEN;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAgB,EAAiB,EAAE,CAChE,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAA;AAEjH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,KAAgB,EAAqB,EAAE,CACjF,IAAI,QAAQ,CAAC,QAAQ,CAAC;IACpB,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC;IAC3B,OAAO,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS;QAC/B,CAAC,CAAC,sBAAsB,OAAO,EAAE;QACjC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,oBAAoB;YACrC,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,4BAA4B,KAAK,CAAC,OAAO,EAAE;IAC/C,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;CAC/E,CAAC,CAAA","sourcesContent":["/**\n * Buffered shell execution over the permission-aware process spawner.\n *\n * `@smthrs/kernel` used to expose a `Shell` service whose `exec` returned a\n * buffered `{ stdout, stderr, exitCode }`. The kernel replaced it with\n * `ChildProcessSpawner`, Effect's own process boundary, which streams and has\n * no buffered form. This module is the buffered form the shell flows still\n * want, expressed in terms of the spawner so the `proc:spawn` capability check\n * and the command-line resource stay exactly where the kernel put them.\n *\n * Commands run through the platform shell (`shell: true`), matching the old\n * service: the flows take a command *line*, not an argv.\n *\n * @since 1.0.0\n */\n\nimport * as ChildProcessEnvironment from \"@smthrs/kernel/ChildProcessEnvironment\"\nimport * as ChildProcessSpawner from \"@smthrs/kernel/ChildProcessSpawner\"\nimport * as Effect from \"effect/Effect\"\nimport * as ChildProcess from \"effect/process/ChildProcess\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport * as StdError from \"../StdError.ts\"\nimport { elideMiddle } from \"./Text.ts\"\n\n/**\n * Failure codes a buffered execution can report, matching the codes the\n * removed kernel `Shell` used so handler-level mapping is unchanged.\n *\n * @category models\n * @since 1.0.0\n */\nexport const ExecErrorCode = Schema.Literals([\"timeout\", \"spawn_error\", \"arguments_too_long\", \"capture_overflow\"])\n\n/**\n * Failure codes a buffered execution can report.\n *\n * @category models\n * @since 1.0.0\n */\nexport type ExecErrorCode = typeof ExecErrorCode.Type\n\n/**\n * A command that never produced an exit code.\n *\n * A non-zero exit is a successful {@link ExecResult}, not a failure; this\n * error is reserved for a command that could not start (`arguments_too_long`\n * when the operating system refused it for the size of its arguments) or was\n * cut off by its timeout, or whose captured output exceeded a refusing capture\n * bound.\n *\n * @category errors\n * @since 1.0.0\n */\nexport class ExecError extends Schema.TaggedError<ExecError>()(\"@smthrs/std/ExecError\", {\n code: ExecErrorCode,\n message: Schema.String,\n /** The limit a `timeout` ran past, in milliseconds. */\n limitMillis: Schema.optional(Schema.Number)\n}) {}\n\n/**\n * The buffered result of one command.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface ExecResult {\n readonly stdout: string\n readonly stderr: string\n readonly exitCode: number\n /** UTF-8 bytes of stdout dropped to stay inside the capture bound; see `overflow`. */\n readonly stdoutDroppedBytes: number\n /** UTF-8 bytes of stderr dropped to stay inside the capture bound; see `overflow`. */\n readonly stderrDroppedBytes: number\n}\n\n/**\n * Options accepted by {@link exec}.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface ExecOptions {\n readonly cwd?: string | undefined\n readonly env?: Readonly<Record<string, string>> | undefined\n readonly timeoutMs?: number | undefined\n /**\n * The program's arguments. Present means an argv, absent means a command\n * line for the platform shell. An argv is how a payload reaches a program\n * without being quoted into a string: nothing between here and `execve`\n * re-parses it.\n */\n readonly args?: ReadonlyArray<string> | undefined\n /**\n * Text written to the program's standard input, as data. A script delivered\n * this way is never quoted, escaped, or heredoc-terminated, which is the\n * whole point: quoting corruption cost the measured SWE-bench program twelve\n * probe failures and one instance's most expensive frame.\n */\n readonly stdin?: string | undefined\n /**\n * Bytes retained per captured stream. A stream that prints more keeps what\n * `overflow` names and reports what it dropped, so a command printing\n * gigabytes costs a bounded amount of memory rather than the whole of what it\n * printed.\n *\n * Absent means unbounded, which is what a caller wants when it needs every\n * byte a tool produced (`rg --files`, `git worktree list`).\n */\n readonly maxCaptureBytes?: number | undefined\n /**\n * What a stream past the bound keeps. `tail`, the default, keeps its last\n * bytes. `ends` keeps its first and last halves and puts one line naming the\n * dropped bytes where the middle was. `refuse` fails if either stream exceeds\n * the bound.\n */\n readonly overflow?: Overflow | undefined\n}\n\ntype Overflow = \"tail\" | \"ends\" | \"refuse\"\n\n/** One captured stream: the text kept, and the bytes dropped to keep it bounded. */\ninterface Capture {\n readonly text: string\n readonly droppedBytes: number\n}\n\ninterface Tail {\n chunks: Array<Uint8Array>\n bytes: number\n dropped: number\n}\n\n/** A stream's first bytes and its last ones: what `overflow: \"ends\"` keeps. */\ninterface Ends {\n readonly head: Array<Uint8Array>\n headBytes: number\n readonly tail: Tail\n}\n\nconst decoder = new TextDecoder(\"utf-8\")\n\nconst emptyTail = (): Tail => ({ chunks: [], bytes: 0, dropped: 0 })\n\n/** A UTF-8 continuation byte is `10xxxxxx`; every other byte starts a character. */\nconst isContinuation = (byte: number): boolean => (byte & 0b1100_0000) === 0b1000_0000\n\nconst join = (chunks: ReadonlyArray<Uint8Array>, size: number): Uint8Array => {\n const bytes = new Uint8Array(size)\n let offset = 0\n for (const chunk of chunks) {\n bytes.set(chunk, offset)\n offset += chunk.byteLength\n }\n return bytes\n}\n\n/** Appends one chunk and drops from the front whatever no longer fits. */\nconst keepTail = (state: Tail, chunk: Uint8Array, maxBytes: number): void => {\n if (chunk.byteLength === 0) return\n state.chunks.push(chunk)\n state.bytes += chunk.byteLength\n while (state.bytes > maxBytes && state.chunks.length > 0) {\n const excess = state.bytes - maxBytes\n const first = state.chunks[0]!\n if (first.byteLength <= excess) {\n state.chunks.shift()\n state.bytes -= first.byteLength\n state.dropped += first.byteLength\n } else {\n state.chunks[0] = first.subarray(excess)\n state.bytes -= excess\n state.dropped += excess\n }\n }\n}\n\n/**\n * Joins the retained chunks and decodes them, skipping the partial code point a\n * dropped head can leave behind.\n *\n * A code point is at most four bytes, so at most three leading continuation\n * bytes can precede the first whole character. Skipping them is counted as\n * dropped rather than decoded to a replacement character the process never\n * printed.\n */\nconst decodeTail = (state: Tail): Capture => {\n const bytes = join(state.chunks, state.bytes)\n if (state.dropped === 0) return { text: decoder.decode(bytes), droppedBytes: 0 }\n let start = 0\n while (start < bytes.byteLength && start < 3 && isContinuation(bytes[start]!)) start++\n return { text: decoder.decode(bytes.subarray(start)), droppedBytes: state.dropped + start }\n}\n\n/**\n * The length of a cut head without the character the cut left unfinished.\n *\n * Its last character starts at the last byte that is not a continuation byte,\n * and that byte says how many bytes the character needs. One that needs more\n * than the head holds is dropped, for the same reason {@link decodeTail} skips\n * a partial code point.\n */\nconst wholeLength = (bytes: Uint8Array): number => {\n for (let back = 1; back <= Math.min(3, bytes.byteLength); back++) {\n const byte = bytes[bytes.byteLength - back]!\n if (isContinuation(byte)) continue\n const width = byte >= 0b1111_0000 ? 4 : byte >= 0b1110_0000 ? 3 : byte >= 0b1100_0000 ? 2 : 1\n return width > back ? bytes.byteLength - back : bytes.byteLength\n }\n return bytes.byteLength\n}\n\n/**\n * Decodes a stream kept by its ends. A stream that fit is decoded whole;\n * otherwise each end is cut on a character boundary and one line naming every\n * byte between them stands where the middle was.\n */\nconst decodeEnds = (state: Ends): Capture => {\n if (state.tail.dropped === 0) {\n const whole = join([...state.head, ...state.tail.chunks], state.headBytes + state.tail.bytes)\n return { text: decoder.decode(whole), droppedBytes: 0 }\n }\n const head = join(state.head, state.headBytes)\n const kept = wholeLength(head)\n const tail = decodeTail(state.tail)\n const droppedBytes = head.byteLength - kept + tail.droppedBytes\n return { text: elideMiddle(decoder.decode(head.subarray(0, kept)), droppedBytes, tail.text), droppedBytes }\n}\n\nconst boundedTail = <E>(\n stream: Stream.Stream<Uint8Array, E>,\n maxBytes: number,\n overflow: Overflow | undefined\n): Effect.Effect<Capture, E> =>\n Stream.runFold(stream, emptyTail, (state, chunk) => {\n keepTail(state, chunk, maxBytes)\n return state\n }).pipe(Effect.map((state) =>\n overflow === \"refuse\" && state.dropped > 0\n ? { text: \"\", droppedBytes: state.dropped }\n : decodeTail(state)\n ))\n\n/**\n * Keeps the first half of the bound and the last half. The head fills first,\n * and every byte after it passes through the tail, which drops from its front:\n * what falls out of the tail is the middle.\n */\nconst boundedEnds = <E>(stream: Stream.Stream<Uint8Array, E>, maxBytes: number): Effect.Effect<Capture, E> => {\n const headBytes = Math.floor(maxBytes / 2)\n return Stream.runFold(stream, (): Ends => ({ head: [], headBytes: 0, tail: emptyTail() }), (state, chunk) => {\n const taken = Math.min(headBytes - state.headBytes, chunk.byteLength)\n if (taken > 0) {\n state.head.push(chunk.subarray(0, taken))\n state.headBytes += taken\n }\n keepTail(state.tail, chunk.subarray(taken), maxBytes - headBytes)\n return state\n }).pipe(Effect.map(decodeEnds))\n}\n\nconst capture = <E>(\n stream: Stream.Stream<Uint8Array, E>,\n maxBytes: number | undefined,\n overflow: Overflow | undefined\n): Effect.Effect<Capture, E> =>\n maxBytes === undefined\n ? Effect.map(Stream.mkString(Stream.decodeText(stream)), (text) => ({ text, droppedBytes: 0 }))\n : overflow === \"ends\"\n ? boundedEnds(stream, maxBytes)\n : boundedTail(stream, maxBytes, overflow)\n\n/**\n * A command whose arguments exceed the operating system's limit fails `execve`\n * with `E2BIG` before it starts: one argument over 128 KiB on Linux, all of\n * them over 1 MiB on macOS. A heredoc in a command line, or a file's text\n * passed as an argument, is one such argument. The platform error's own text\n * repeats the whole command line, so this text is written here instead, and a\n * caller may show it as it stands.\n */\nconst argumentsTooLong = (error: { readonly cause?: unknown }): ExecError | undefined =>\n (error.cause as { readonly code?: unknown } | undefined)?.code === \"E2BIG\"\n ? new ExecError({\n code: \"arguments_too_long\",\n message:\n \"Command not started: its arguments exceed the operating system's size limit (E2BIG). Send long text on standard input or in a file, not in the command line or its arguments.\"\n })\n : undefined\n\nconst unbounded = (\n command: string,\n options: ExecOptions\n): Effect.Effect<ExecResult, ExecError, ChildProcessSpawner.ChildProcessSpawner> =>\n Effect.gen(function*() {\n const spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n const settings: ChildProcess.CommandOptions = {\n ...(options.args === undefined ? { shell: true } : {}),\n ...(options.cwd === undefined ? {} : { cwd: options.cwd }),\n env: ChildProcessEnvironment.make(process.env, options.env),\n extendEnv: false,\n ...(options.stdin === undefined\n ? {}\n : { stdin: Stream.make(new TextEncoder().encode(options.stdin)) })\n }\n const handle = yield* spawner.spawn(\n options.args === undefined\n ? ChildProcess.make(command, settings)\n : ChildProcess.make(command, [...options.args], settings)\n )\n // stdout, stderr, and the exit code have to be consumed concurrently: a\n // command that fills a pipe blocks until the pipe is drained, so waiting\n // for exit first would deadlock on any output larger than the buffer.\n const [stdout, stderr, exitCode] = yield* Effect.all(\n [\n capture(handle.stdout, options.maxCaptureBytes, options.overflow),\n capture(handle.stderr, options.maxCaptureBytes, options.overflow),\n handle.exitCode\n ],\n { concurrency: \"unbounded\" }\n )\n if (options.overflow === \"refuse\") {\n const overflowed = [\n stdout.droppedBytes > 0 ? \"stdout\" : undefined,\n stderr.droppedBytes > 0 ? \"stderr\" : undefined\n ]\n .filter((stream): stream is string => stream !== undefined)\n if (overflowed.length > 0) {\n return yield* Effect.fail(\n new ExecError({\n code: \"capture_overflow\",\n message: `${command} ${\n overflowed.join(\" and \")\n } exceeded the ${options.maxCaptureBytes}-byte capture cap; refusing partial output`\n })\n )\n }\n }\n return {\n stdout: stdout.text,\n stderr: stderr.text,\n exitCode,\n stdoutDroppedBytes: stdout.droppedBytes,\n stderrDroppedBytes: stderr.droppedBytes\n }\n }).pipe(\n Effect.scoped,\n Effect.mapError((error) =>\n error instanceof ExecError ? error : argumentsTooLong(error) ?? new ExecError({\n code: \"spawn_error\",\n message: `exec: ${command}: ${error.message}`\n })\n )\n )\n\n/**\n * Runs a command line through the platform shell and buffers its output.\n *\n * Cancellation is scope closure: the spawn is scoped, so an interrupted fiber\n * — including the one a `timeoutMs` interrupts — terminates the process rather\n * than leaking it.\n *\n * @category execution\n * @since 1.0.0\n */\nexport const exec = (\n command: string,\n options: ExecOptions = {}\n): Effect.Effect<ExecResult, ExecError, ChildProcessSpawner.ChildProcessSpawner> =>\n options.timeoutMs === undefined\n ? unbounded(command, options)\n : Effect.timeoutOrElse(unbounded(command, options), {\n duration: options.timeoutMs,\n orElse: () =>\n Effect.fail(\n new ExecError({\n code: \"timeout\",\n message: `exec: \\`${command}\\` exceeded ${options.timeoutMs}ms`,\n limitMillis: options.timeoutMs\n })\n )\n })\n\n/**\n * The model-facing failure code a command that never produced an exit code\n * carries.\n *\n * A timeout keeps its own code, because \"the command never finished\" and \"the\n * command never started\" are different things to a caller deciding whether to\n * retry. Arguments the operating system refused for their size are the\n * caller's own input, which a shell flow publishes, so they read as\n * `invalid_input`. Every other way of producing no exit code is a host failure.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const toStdErrorCode = (error: ExecError): StdError.Code =>\n error.code === \"timeout\" ? \"timeout\" : error.code === \"arguments_too_long\" ? \"invalid_input\" : \"command_failed\"\n\n/**\n * The model-facing failure one execution error becomes.\n *\n * A timeout names the command, which is what the caller asked for and all a\n * timeout has to say. Arguments too long to start carry the reason and the\n * fix, and nothing of the command. Any other failure carries the message the\n * execution produced, which already names the command.\n *\n * @category errors\n * @since 1.0.0\n */\nexport const toStdError = (command: string, error: ExecError): StdError.StdError =>\n new StdError.StdError({\n code: toStdErrorCode(error),\n message: error.code === \"timeout\"\n ? `Command timed out: ${command}`\n : error.code === \"arguments_too_long\"\n ? error.message\n : `Command failed to start: ${error.message}`,\n ...(error.limitMillis === undefined ? {} : { limitMillis: error.limitMillis })\n })\n"]}
|
|
@@ -85,6 +85,17 @@ export interface Page {
|
|
|
85
85
|
export declare const truncateBytes: (text: string, maxBytes: number, options: {
|
|
86
86
|
readonly keep: "head" | "tail";
|
|
87
87
|
}) => Truncation;
|
|
88
|
+
/**
|
|
89
|
+
* Joins the start and the end of a stream cut in the middle around one line
|
|
90
|
+
* naming the bytes cut between them.
|
|
91
|
+
*
|
|
92
|
+
* The line stands alone, so a start that stops mid-line is ended before it.
|
|
93
|
+
* Only the line's own newlines are added; `droppedBytes` counts printed bytes.
|
|
94
|
+
*
|
|
95
|
+
* @category rendering
|
|
96
|
+
* @since 1.0.0-rc.5
|
|
97
|
+
*/
|
|
98
|
+
export declare const elideMiddle: (start: string, droppedBytes: number, end: string) => string;
|
|
88
99
|
/**
|
|
89
100
|
* Splits on LF without counting a terminal LF as a line.
|
|
90
101
|
* Carriage returns remain part of each line, including the CR in CRLF, so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../../../src/internal/Text.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,OAAQ,CAAA;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,WAAW,OAAQ,CAAA;AAEhC;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,MAAM,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,OAAQ,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAS,CAAA;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,QAAS,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,EAAE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G,MACL,CAAA"}
|
|
@@ -88,6 +88,17 @@ export const truncateBytes = (text, maxBytes, options) => {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Joins the start and the end of a stream cut in the middle around one line
|
|
93
|
+
* naming the bytes cut between them.
|
|
94
|
+
*
|
|
95
|
+
* The line stands alone, so a start that stops mid-line is ended before it.
|
|
96
|
+
* Only the line's own newlines are added; `droppedBytes` counts printed bytes.
|
|
97
|
+
*
|
|
98
|
+
* @category rendering
|
|
99
|
+
* @since 1.0.0-rc.5
|
|
100
|
+
*/
|
|
101
|
+
export const elideMiddle = (start, droppedBytes, end) => `${start}${start === "" || start.endsWith("\n") ? "" : "\n"}[${droppedBytes} ${droppedBytes === 1 ? "byte" : "bytes"} omitted]\n${end}`;
|
|
91
102
|
/**
|
|
92
103
|
* Splits on LF without counting a terminal LF as a line.
|
|
93
104
|
* Carriage returns remain part of each line, including the CR in CRLF, so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../../../src/internal/Text.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAA;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAEtC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAA;AA4B5C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AACjC,MAAM,YAAY,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAA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W,GAAG,CAAC,IAAY,EAAyB,EAAE;IACjE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACvD,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,KAAK,CAAC,GAAG,EAAE,CAAA;IACpC,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,IAAY,EACZ,OAA4D,EACtD,EAAE;IACR,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;IAC/B,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAA;IAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IAChF,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,EAAE,OAAO,CAAC;QAC1C,SAAS;QACT,OAAO;QACP,UAAU;KACX,CAAA;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,KAAa,EAAU,EAAE,CAC3E,WAAW,KAAK,OAAO,KAAK,IAAI,IAAI,yBAAyB,CAAA","sourcesContent":["/**\n * Shared text paging, numbering, and byte-budget helpers.\n *\n * Every limit here is a display budget, not a policy limit: exceeding one is\n * always disclosed to the model rather than silently applied.\n *\n * @since 1.0.0\n */\n\n/**\n * Default number of lines or entries returned by a paged flow.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const DEFAULT_READ_LIMIT = 2_000\n\n/**\n * Maximum number of directory entries or glob paths returned in one call.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_ENTRIES = 1_000\n\n/**\n * Maximum number of grep matches returned in one call.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_GREP_MATCHES = 200\n\n/**\n * Maximum number of Unicode scalar values displayed for a single line.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_LINE_CHARS = 2_000\n\n/**\n * Maximum UTF-8 byte budget for one rendered text payload.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_OUTPUT_BYTES = 60_000\n\n/**\n * Maximum UTF-8 byte budget captured per shell output stream.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_SHELL_OUTPUT_BYTES = 30_000\n\n/**\n * A byte-budgeted rendering of a text value.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Truncation {\n readonly text: string\n readonly truncated: boolean\n readonly keptBytes: number\n readonly droppedBytes: number\n}\n\n/**\n * One page of source lines.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Page {\n readonly lines: ReadonlyArray<string>\n readonly startLine: number\n readonly endLine: number\n readonly totalLines: number\n}\n\nconst encoder = new TextEncoder()\nconst fatalDecoder = new TextDecoder(\"utf-8\", { fatal: true })\n\n/**\n * Trims a string to a UTF-8 byte budget without splitting a code point.\n *\n * `keep: \"head\"` retains the beginning of the value; `keep: \"tail\"` retains\n * the end, which is what shell output needs because the interesting part of an\n * overflowing stream is almost always its last lines.\n *\n * @category rendering\n * @since 1.0.0\n */\nexport const truncateBytes = (\n text: string,\n maxBytes: number,\n options: { readonly keep: \"head\" | \"tail\" }\n): Truncation => {\n const bytes = encoder.encode(text)\n if (bytes.byteLength <= maxBytes) {\n return { text, truncated: false, keptBytes: bytes.byteLength, droppedBytes: 0 }\n }\n let start = options.keep === \"head\" ? 0 : bytes.byteLength - maxBytes\n let end = options.keep === \"head\" ? maxBytes : bytes.byteLength\n // TextEncoder produces valid UTF-8. Moving a cut inward reaches a scalar\n // boundary after at most three continuation bytes, so decoding must succeed.\n while (true) {\n try {\n const decoded = fatalDecoder.decode(bytes.subarray(start, end))\n const keptBytes = end - start\n return {\n text: decoded,\n truncated: true,\n keptBytes,\n droppedBytes: bytes.byteLength - keptBytes\n }\n } catch {\n if (options.keep === \"head\") end--\n else start++\n }\n }\n}\n\n/**\n * Splits on LF without counting a terminal LF as a line.\n * Carriage returns remain part of each line, including the CR in CRLF, so\n * joining a page with LF preserves its bytes except for the final LF.\n *\n * @category parsing\n * @since 1.0.0\n */\nexport const sourceLines = (text: string): ReadonlyArray<string> => {\n const lines = text.length === 0 ? [] : text.split(\"\\n\")\n if (text.endsWith(\"\\n\")) lines.pop()\n return lines\n}\n\n/**\n * Selects a 1-based page of lines from a text value.\n *\n * @category paging\n * @since 1.0.0\n */\nexport const slice = (\n text: string,\n options: { readonly offset: number; readonly limit: number }\n): Page => {\n const lines = sourceLines(text)\n const totalLines = lines.length\n const startLine = Math.max(1, options.offset)\n const endLine = Math.min(totalLines, startLine + Math.max(0, options.limit) - 1)\n return {\n lines: lines.slice(startLine - 1, endLine),\n startLine,\n endLine,\n totalLines\n }\n}\n\n/**\n * Renders the disclosure appended whenever output was capped.\n *\n * @category rendering\n * @since 1.0.0\n */\nexport const notice = (unit: string, shown: number, total: number): string =>\n `Showing ${shown} of ${total} ${unit}; output was truncated.`\n"]}
|
|
1
|
+
{"version":3,"file":"Text.js","sourceRoot":"","sources":["../../../src/internal/Text.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAA;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAA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SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IAChF,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,EAAE,OAAO,CAAC;QAC1C,SAAS;QACT,OAAO;QACP,UAAU;KACX,CAAA;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,KAAa,EAAU,EAAE,CAC3E,WAAW,KAAK,OAAO,KAAK,IAAI,IAAI,yBAAyB,CAAA","sourcesContent":["/**\n * Shared text paging, numbering, and byte-budget helpers.\n *\n * Every limit here is a display budget, not a policy limit: exceeding one is\n * always disclosed to the model rather than silently applied.\n *\n * @since 1.0.0\n */\n\n/**\n * Default number of lines or entries returned by a paged flow.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const DEFAULT_READ_LIMIT = 2_000\n\n/**\n * Maximum number of directory entries or glob paths returned in one call.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_ENTRIES = 1_000\n\n/**\n * Maximum number of grep matches returned in one call.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_GREP_MATCHES = 200\n\n/**\n * Maximum number of Unicode scalar values displayed for a single line.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_LINE_CHARS = 2_000\n\n/**\n * Maximum UTF-8 byte budget for one rendered text payload.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_OUTPUT_BYTES = 60_000\n\n/**\n * Maximum UTF-8 byte budget captured per shell output stream.\n *\n * @category constants\n * @since 1.0.0\n */\nexport const MAX_SHELL_OUTPUT_BYTES = 30_000\n\n/**\n * A byte-budgeted rendering of a text value.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Truncation {\n readonly text: string\n readonly truncated: boolean\n readonly keptBytes: number\n readonly droppedBytes: number\n}\n\n/**\n * One page of source lines.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Page {\n readonly lines: ReadonlyArray<string>\n readonly startLine: number\n readonly endLine: number\n readonly totalLines: number\n}\n\nconst encoder = new TextEncoder()\nconst fatalDecoder = new TextDecoder(\"utf-8\", { fatal: true })\n\n/**\n * Trims a string to a UTF-8 byte budget without splitting a code point.\n *\n * `keep: \"head\"` retains the beginning of the value; `keep: \"tail\"` retains\n * the end, which is what shell output needs because the interesting part of an\n * overflowing stream is almost always its last lines.\n *\n * @category rendering\n * @since 1.0.0\n */\nexport const truncateBytes = (\n text: string,\n maxBytes: number,\n options: { readonly keep: \"head\" | \"tail\" }\n): Truncation => {\n const bytes = encoder.encode(text)\n if (bytes.byteLength <= maxBytes) {\n return { text, truncated: false, keptBytes: bytes.byteLength, droppedBytes: 0 }\n }\n let start = options.keep === \"head\" ? 0 : bytes.byteLength - maxBytes\n let end = options.keep === \"head\" ? maxBytes : bytes.byteLength\n // TextEncoder produces valid UTF-8. Moving a cut inward reaches a scalar\n // boundary after at most three continuation bytes, so decoding must succeed.\n while (true) {\n try {\n const decoded = fatalDecoder.decode(bytes.subarray(start, end))\n const keptBytes = end - start\n return {\n text: decoded,\n truncated: true,\n keptBytes,\n droppedBytes: bytes.byteLength - keptBytes\n }\n } catch {\n if (options.keep === \"head\") end--\n else start++\n }\n }\n}\n\n/**\n * Joins the start and the end of a stream cut in the middle around one line\n * naming the bytes cut between them.\n *\n * The line stands alone, so a start that stops mid-line is ended before it.\n * Only the line's own newlines are added; `droppedBytes` counts printed bytes.\n *\n * @category rendering\n * @since 1.0.0-rc.5\n */\nexport const elideMiddle = (start: string, droppedBytes: number, end: string): string =>\n `${start}${start === \"\" || start.endsWith(\"\\n\") ? \"\" : \"\\n\"}[${droppedBytes} ${\n droppedBytes === 1 ? \"byte\" : \"bytes\"\n } omitted]\\n${end}`\n\n/**\n * Splits on LF without counting a terminal LF as a line.\n * Carriage returns remain part of each line, including the CR in CRLF, so\n * joining a page with LF preserves its bytes except for the final LF.\n *\n * @category parsing\n * @since 1.0.0\n */\nexport const sourceLines = (text: string): ReadonlyArray<string> => {\n const lines = text.length === 0 ? [] : text.split(\"\\n\")\n if (text.endsWith(\"\\n\")) lines.pop()\n return lines\n}\n\n/**\n * Selects a 1-based page of lines from a text value.\n *\n * @category paging\n * @since 1.0.0\n */\nexport const slice = (\n text: string,\n options: { readonly offset: number; readonly limit: number }\n): Page => {\n const lines = sourceLines(text)\n const totalLines = lines.length\n const startLine = Math.max(1, options.offset)\n const endLine = Math.min(totalLines, startLine + Math.max(0, options.limit) - 1)\n return {\n lines: lines.slice(startLine - 1, endLine),\n startLine,\n endLine,\n totalLines\n }\n}\n\n/**\n * Renders the disclosure appended whenever output was capped.\n *\n * @category rendering\n * @since 1.0.0\n */\nexport const notice = (unit: string, shown: number, total: number): string =>\n `Showing ${shown} of ${total} ${unit}; output was truncated.`\n"]}
|
package/docs/README.md
CHANGED
|
@@ -42,7 +42,9 @@ the details that decide whether a model gets its next step right:
|
|
|
42
42
|
|
|
43
43
|
## Install
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
```bash
|
|
46
|
+
npm install @smthrs/std@next effect
|
|
47
|
+
```
|
|
46
48
|
|
|
47
49
|
The handlers
|
|
48
50
|
ask the host for services such as `FileSystem`, `Path`, and
|
package/docs/api.md
CHANGED
|
@@ -60,7 +60,7 @@ Some of them export more than the common nine:
|
|
|
60
60
|
|
|
61
61
|
| Module | Additional exports |
|
|
62
62
|
| -------------- | ------------------------------------------------------------------------------------------- |
|
|
63
|
-
| `Bash` | `DEFAULT_TIMEOUT_MS`
|
|
63
|
+
| `Bash` | `DEFAULT_TIMEOUT_MS`, `elideMiddle(start, droppedBytes, end)` |
|
|
64
64
|
| `Explore` | `make(options: { model?: string })`, and no `run` |
|
|
65
65
|
| `Grep` | `ContextLine`, `Symbol`, `Match` schemas |
|
|
66
66
|
| `Read` | `MAX_READ_FILE_BYTES`, the 64 MiB bound past which `read` refuses a file |
|
|
@@ -307,23 +307,26 @@ How the project under test runs its suite, declared once by the host.
|
|
|
307
307
|
|
|
308
308
|
Pinned trees, and the scratch checkouts a call runs against.
|
|
309
309
|
|
|
310
|
-
| Export | Type
|
|
311
|
-
| ------------------ |
|
|
312
|
-
| `Checkpoints` | interface and `Context.Service` tag
|
|
313
|
-
| `Snapshot` | `Schema.Class`
|
|
314
|
-
| `Materialized` | interface
|
|
315
|
-
| `baseId` | `"base"`
|
|
316
|
-
| `scratchDirectory` | `".flows-checkpoints"`
|
|
317
|
-
| `configSection` | `"flows-checkpoint"`
|
|
318
|
-
| `make` | `(service: Checkpoints) => Checkpoints`
|
|
319
|
-
| `unavailable` | `(id: string) => StdError`
|
|
320
|
-
| `makeNoop` | `() => Checkpoints`
|
|
321
|
-
| `layerNoop` | `Layer<Checkpoints>`
|
|
322
|
-
| `GitOptions` | interface
|
|
323
|
-
| `makeGit` | `(options: GitOptions) => Effect<Checkpoints, never, ChildProcessSpawner>`
|
|
324
|
-
| `layerGit` | `(options: GitOptions) => Layer<Checkpoints, never, ChildProcessSpawner>`
|
|
325
|
-
| `
|
|
326
|
-
| `
|
|
310
|
+
| Export | Type | Meaning |
|
|
311
|
+
| ------------------ | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
312
|
+
| `Checkpoints` | interface and `Context.Service` tag | `{ capture, materialize }`. |
|
|
313
|
+
| `Snapshot` | `Schema.Class` | `{ id, ref }`, identified as `@smthrs/std/Checkpoints/Snapshot`. |
|
|
314
|
+
| `Materialized` | interface | `id`, `host`, `guest`, `root`, `guestRoot`. |
|
|
315
|
+
| `baseId` | `"base"` | The id naming the tree the run opened on. |
|
|
316
|
+
| `scratchDirectory` | `".flows-checkpoints"` | Where a checkpoint is materialized, relative to the root. |
|
|
317
|
+
| `configSection` | `"flows-checkpoint"` | The git-config section minted checkpoints are recorded under. |
|
|
318
|
+
| `make` | `(service: Checkpoints) => Checkpoints` | |
|
|
319
|
+
| `unavailable` | `(id: string) => StdError` | The refusal a host that pins nothing answers with. |
|
|
320
|
+
| `makeNoop` | `() => Checkpoints` | Fails both calls with `unavailable`. |
|
|
321
|
+
| `layerNoop` | `Layer<Checkpoints>` | |
|
|
322
|
+
| `GitOptions` | interface | `root`, `cwd?`, `baseRef?`. |
|
|
323
|
+
| `makeGit` | `(options: GitOptions) => Effect<Checkpoints, never, ChildProcessSpawner>` | |
|
|
324
|
+
| `layerGit` | `(options: GitOptions) => Layer<Checkpoints, never, ChildProcessSpawner>` | |
|
|
325
|
+
| `ContainerOptions` | interface | `container`, `cwd?`. |
|
|
326
|
+
| `makeContainer` | `(options: ContainerOptions) => Effect<Checkpoints, never, ChildProcessSpawner \| Container>` | Runs git inside the container `bash` runs in. |
|
|
327
|
+
| `layerContainer` | `(options: ContainerOptions) => Layer<Checkpoints, never, ChildProcessSpawner \| Container>` | |
|
|
328
|
+
| `Relocation` | tagged union | `Relocated`, `UnsupportedFlow`, `AbsolutePath`, `OutsideTree`. |
|
|
329
|
+
| `relocate` | `(flow: string, input: Json, materialized: Materialized) => Relocation` | Rewrites one call's input onto a checkpoint. |
|
|
327
330
|
|
|
328
331
|
`capture(id)` returns a `Snapshot`. `materialize(id, use)` is scoped: it hands
|
|
329
332
|
the tree to `use` and removes the checkout however that effect ends. Host git
|
|
@@ -84,17 +84,20 @@ caller paging a large directory could see one entry twice and another never.
|
|
|
84
84
|
`stdoutTruncated`, `stderrTruncated`, and `tailTruncated` are not display
|
|
85
85
|
details. A truncated capture is a fragment of what the process printed, and
|
|
86
86
|
[`@smthrs/harness`](/api/harness) reads these flags to refuse a later write of
|
|
87
|
-
those exact bytes: writing a captured
|
|
88
|
-
|
|
87
|
+
those exact bytes: writing a captured fragment over a file replaces the file
|
|
88
|
+
with a piece of a log. Read the flag before writing captured output anywhere, and set
|
|
89
89
|
it in your own handler whenever you cut a capture: a consumer that cannot tell a
|
|
90
90
|
fragment from the whole writes the fragment.
|
|
91
91
|
|
|
92
92
|
`stdoutDroppedBytes`, `stderrDroppedBytes`, and `tailDroppedBytes` count what
|
|
93
93
|
the process actually produced beyond the capture. Capture is bounded where the
|
|
94
94
|
stream is read rather than after it is read, so a command that prints gigabytes
|
|
95
|
-
costs the bound instead of the whole of what it printed. `bash` keeps the
|
|
96
|
-
|
|
97
|
-
`
|
|
95
|
+
costs the bound instead of the whole of what it printed. `bash` keeps the
|
|
96
|
+
first and last 15,000 bytes of each stream and puts one line such as
|
|
97
|
+
`[10025 bytes omitted]` where the middle was, because a search prints its
|
|
98
|
+
matches first and a failing command prints its verdict last. Its dropped-bytes
|
|
99
|
+
count is the size of that middle. `test` keeps the tail; `read`, `fetch`, and
|
|
100
|
+
`http-post` keep the head.
|
|
98
101
|
|
|
99
102
|
Every caller-supplied command (`bash`, `test`, `shell_command`) passes a capture
|
|
100
103
|
bound. The internal `git` plumbing behind `Checkpoints` and `TestRun`'s baseline
|
|
@@ -32,6 +32,26 @@ const store = Checkpoints.layerGit({
|
|
|
32
32
|
`Checkpoints.layerNoop`, whose refusal says to take the reading on the live tree
|
|
33
33
|
instead.
|
|
34
34
|
|
|
35
|
+
## Bind the container store
|
|
36
|
+
|
|
37
|
+
When the repository lives only in a container and `bash` runs there, bind
|
|
38
|
+
`layerContainer` instead. It runs git inside that container through the
|
|
39
|
+
`Container` transport `bash` uses, so `ctx.base` and `ctx.checkpoint()` read the
|
|
40
|
+
container's tree. A git store would look for the repository on the host and
|
|
41
|
+
refuse every call that names a checkpoint.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const store = Checkpoints.layerContainer({
|
|
45
|
+
container: "task", // the container `bash` runs in
|
|
46
|
+
cwd: "/app" // optional; absent is the container's working directory
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`layerContainer` requires a `ChildProcessSpawner` and a `Container`. It records
|
|
51
|
+
and names a checkpoint as the git store does, and checks a tree out at the same
|
|
52
|
+
`<top>/.flows-checkpoints/<id>-<lease>` path inside the container, so a
|
|
53
|
+
relocated `bash` call keeps its subdirectory.
|
|
54
|
+
|
|
35
55
|
## Capture and materialize
|
|
36
56
|
|
|
37
57
|
```ts
|
|
@@ -159,15 +159,25 @@ channel.
|
|
|
159
159
|
| Field | Meaning |
|
|
160
160
|
| ------------------------------------------ | ----------------------------------------------------------- |
|
|
161
161
|
| `exitCode` | The command's exit code. |
|
|
162
|
-
| `stdout`, `stderr` | The captured streams
|
|
162
|
+
| `stdout`, `stderr` | The captured streams; start and end when truncated. |
|
|
163
163
|
| `stdoutTruncated`, `stderrTruncated` | Whether that stream is a fragment. |
|
|
164
|
-
| `stdoutDroppedBytes`, `stderrDroppedBytes` | Bytes omitted from the
|
|
164
|
+
| `stdoutDroppedBytes`, `stderrDroppedBytes` | Bytes omitted from the middle. |
|
|
165
165
|
| `invalidProbe` | Present when the shell refused to start the command at all. |
|
|
166
166
|
|
|
167
|
-
Each stream is bounded at 30,000 bytes
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
Each stream is bounded at 30,000 bytes: its first 15,000 and its last 15,000.
|
|
168
|
+
A search prints its matches first and a failing command prints its verdict
|
|
169
|
+
last, so both survive. One line stands where the middle was:
|
|
170
|
+
|
|
171
|
+
```text
|
|
172
|
+
MARKER-HEAD
|
|
173
|
+
xxxxxxxxxxxx
|
|
174
|
+
[10025 bytes omitted]
|
|
175
|
+
xxxxxxxxxxxx
|
|
176
|
+
MARKER-TAIL
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Never write a truncated stream to a file: it is a fragment, not the content it
|
|
180
|
+
came from. `@smthrs/harness` reads the `Truncated` flags to refuse exactly that.
|
|
171
181
|
|
|
172
182
|
`timeoutMs` defaults to `Bash.DEFAULT_TIMEOUT_MS`, ten minutes.
|
|
173
183
|
|
package/docs/installation.md
CHANGED
|
@@ -7,7 +7,11 @@ sidebar:
|
|
|
7
7
|
|
|
8
8
|
## Install the package
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
```bash
|
|
11
|
+
npm install @smthrs/std@next effect
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The `next` tag carries the 1.0 release candidates.
|
|
11
15
|
|
|
12
16
|
It requires
|
|
13
17
|
Node.js 26.4.0 or later and ships as both ESM and CommonJS with TypeScript
|
|
@@ -92,14 +96,14 @@ Six flows reach the host through a service rather than through a platform layer.
|
|
|
92
96
|
Each one has a refusal layer for a host that cannot serve it, so a flow whose
|
|
93
97
|
service is missing says so instead of succeeding quietly.
|
|
94
98
|
|
|
95
|
-
| Service | Refusal layer | Working layer
|
|
96
|
-
| ---------------- | -------------------------- |
|
|
97
|
-
| `Search` | `Search.layerNoop` | `PortableSearch.layer` or `NativeSearch.layer`
|
|
98
|
-
| `Container` | `Container.layerNoop` | `Container.layerCommand({ program: "docker" })`
|
|
99
|
-
| `TestRunner` | `TestRunner.layerNoop` | `TestRunner.layer(runner)`
|
|
100
|
-
| `Checkpoints` | `Checkpoints.layerNoop` | `Checkpoints.layerGit({ root })`
|
|
101
|
-
| `WebSearch` | `WebSearch.layerNoop` | `ExaWebSearch.layer(credentialId)`
|
|
102
|
-
| `LanguageServer` | `LanguageServer.layerNoop` | `NodeLanguageServer.layer(config)`
|
|
99
|
+
| Service | Refusal layer | Working layer |
|
|
100
|
+
| ---------------- | -------------------------- | ------------------------------------------------------------------------------- |
|
|
101
|
+
| `Search` | `Search.layerNoop` | `PortableSearch.layer` or `NativeSearch.layer` |
|
|
102
|
+
| `Container` | `Container.layerNoop` | `Container.layerCommand({ program: "docker" })` |
|
|
103
|
+
| `TestRunner` | `TestRunner.layerNoop` | `TestRunner.layer(runner)` |
|
|
104
|
+
| `Checkpoints` | `Checkpoints.layerNoop` | `Checkpoints.layerGit({ root })` or `Checkpoints.layerContainer({ container })` |
|
|
105
|
+
| `WebSearch` | `WebSearch.layerNoop` | `ExaWebSearch.layer(credentialId)` |
|
|
106
|
+
| `LanguageServer` | `LanguageServer.layerNoop` | `NodeLanguageServer.layer(config)` |
|
|
103
107
|
|
|
104
108
|
`NativeSearch.layer` drives the `rg` executable, so a host that binds it needs
|
|
105
109
|
ripgrep on the path. `PortableSearch.layer` needs nothing beyond `FileSystem`
|
package/docs/quickstart.md
CHANGED
|
@@ -14,7 +14,7 @@ without an external binary and without an API key.
|
|
|
14
14
|
## Prerequisites
|
|
15
15
|
|
|
16
16
|
- Node.js 26.4.0 or later.
|
|
17
|
-
- A
|
|
17
|
+
- A project with the packages installed: `npm install @smthrs/std@next @effect/platform-node effect`.
|
|
18
18
|
|
|
19
19
|
## Make a tree to search
|
|
20
20
|
|