@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
|
@@ -24,7 +24,7 @@ import * as StdError from "../StdError.ts";
|
|
|
24
24
|
* @category models
|
|
25
25
|
* @since 1.0.0
|
|
26
26
|
*/
|
|
27
|
-
export declare const ExecErrorCode: Schema.Literals<readonly ["timeout", "spawn_error", "capture_overflow"]>;
|
|
27
|
+
export declare const ExecErrorCode: Schema.Literals<readonly ["timeout", "spawn_error", "arguments_too_long", "capture_overflow"]>;
|
|
28
28
|
/**
|
|
29
29
|
* Failure codes a buffered execution can report.
|
|
30
30
|
*
|
|
@@ -33,7 +33,7 @@ export declare const ExecErrorCode: Schema.Literals<readonly ["timeout", "spawn_
|
|
|
33
33
|
*/
|
|
34
34
|
export type ExecErrorCode = typeof ExecErrorCode.Type;
|
|
35
35
|
declare const ExecError_base: Schema.Class<ExecError, Schema.TaggedStruct<"@smthrs/std/ExecError", {
|
|
36
|
-
readonly code: Schema.Literals<readonly ["timeout", "spawn_error", "capture_overflow"]>;
|
|
36
|
+
readonly code: Schema.Literals<readonly ["timeout", "spawn_error", "arguments_too_long", "capture_overflow"]>;
|
|
37
37
|
readonly message: Schema.String;
|
|
38
38
|
/** The limit a `timeout` ran past, in milliseconds. */
|
|
39
39
|
readonly limitMillis: Schema.optional<Schema.Number>;
|
|
@@ -42,8 +42,10 @@ declare const ExecError_base: Schema.Class<ExecError, Schema.TaggedStruct<"@smth
|
|
|
42
42
|
* A command that never produced an exit code.
|
|
43
43
|
*
|
|
44
44
|
* A non-zero exit is a successful {@link ExecResult}, not a failure; this
|
|
45
|
-
* error is reserved for a command that could not start
|
|
46
|
-
*
|
|
45
|
+
* error is reserved for a command that could not start (`arguments_too_long`
|
|
46
|
+
* when the operating system refused it for the size of its arguments) or was
|
|
47
|
+
* cut off by its timeout, or whose captured output exceeded a refusing capture
|
|
48
|
+
* bound.
|
|
47
49
|
*
|
|
48
50
|
* @category errors
|
|
49
51
|
* @since 1.0.0
|
|
@@ -60,9 +62,9 @@ export interface ExecResult {
|
|
|
60
62
|
readonly stdout: string;
|
|
61
63
|
readonly stderr: string;
|
|
62
64
|
readonly exitCode: number;
|
|
63
|
-
/** UTF-8 bytes
|
|
65
|
+
/** UTF-8 bytes of stdout dropped to stay inside the capture bound; see `overflow`. */
|
|
64
66
|
readonly stdoutDroppedBytes: number;
|
|
65
|
-
/** UTF-8 bytes
|
|
67
|
+
/** UTF-8 bytes of stderr dropped to stay inside the capture bound; see `overflow`. */
|
|
66
68
|
readonly stderrDroppedBytes: number;
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
@@ -90,17 +92,24 @@ export interface ExecOptions {
|
|
|
90
92
|
*/
|
|
91
93
|
readonly stdin?: string | undefined;
|
|
92
94
|
/**
|
|
93
|
-
* Bytes retained per captured stream. A stream that prints more keeps
|
|
94
|
-
*
|
|
95
|
-
* bounded amount of memory rather than the whole of what it
|
|
95
|
+
* Bytes retained per captured stream. A stream that prints more keeps what
|
|
96
|
+
* `overflow` names and reports what it dropped, so a command printing
|
|
97
|
+
* gigabytes costs a bounded amount of memory rather than the whole of what it
|
|
98
|
+
* printed.
|
|
96
99
|
*
|
|
97
100
|
* Absent means unbounded, which is what a caller wants when it needs every
|
|
98
101
|
* byte a tool produced (`rg --files`, `git worktree list`).
|
|
99
102
|
*/
|
|
100
103
|
readonly maxCaptureBytes?: number | undefined;
|
|
101
|
-
/**
|
|
102
|
-
|
|
104
|
+
/**
|
|
105
|
+
* What a stream past the bound keeps. `tail`, the default, keeps its last
|
|
106
|
+
* bytes. `ends` keeps its first and last halves and puts one line naming the
|
|
107
|
+
* dropped bytes where the middle was. `refuse` fails if either stream exceeds
|
|
108
|
+
* the bound.
|
|
109
|
+
*/
|
|
110
|
+
readonly overflow?: Overflow | undefined;
|
|
103
111
|
}
|
|
112
|
+
type Overflow = "tail" | "ends" | "refuse";
|
|
104
113
|
/**
|
|
105
114
|
* Runs a command line through the platform shell and buffers its output.
|
|
106
115
|
*
|
|
@@ -118,7 +127,9 @@ export declare const exec: (command: string, options?: ExecOptions) => Effect.Ef
|
|
|
118
127
|
*
|
|
119
128
|
* A timeout keeps its own code, because "the command never finished" and "the
|
|
120
129
|
* command never started" are different things to a caller deciding whether to
|
|
121
|
-
* retry.
|
|
130
|
+
* retry. Arguments the operating system refused for their size are the
|
|
131
|
+
* caller's own input, which a shell flow publishes, so they read as
|
|
132
|
+
* `invalid_input`. Every other way of producing no exit code is a host failure.
|
|
122
133
|
*
|
|
123
134
|
* @category errors
|
|
124
135
|
* @since 1.0.0
|
|
@@ -128,8 +139,9 @@ export declare const toStdErrorCode: (error: ExecError) => StdError.Code;
|
|
|
128
139
|
* The model-facing failure one execution error becomes.
|
|
129
140
|
*
|
|
130
141
|
* A timeout names the command, which is what the caller asked for and all a
|
|
131
|
-
* timeout has to say.
|
|
132
|
-
*
|
|
142
|
+
* timeout has to say. Arguments too long to start carry the reason and the
|
|
143
|
+
* fix, and nothing of the command. Any other failure carries the message the
|
|
144
|
+
* execution produced, which already names the command.
|
|
133
145
|
*
|
|
134
146
|
* @category errors
|
|
135
147
|
* @since 1.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Exec.d.ts","sourceRoot":"","sources":["../../../src/internal/Exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,mBAAmB,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"Exec.d.ts","sourceRoot":"","sources":["../../../src/internal/Exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,mBAAmB,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAG1C;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,gGAAwF,CAAA;AAElH;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA;;;;IAiBnD,uDAAuD;;;AAfzD;;;;;;;;;;;GAWG;AACH,qBAAa,SAAU,SAAQ,cAK7B;CAAG;AAEL;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,sFAAsF;IACtF,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAA;IACnC,sFAAsF;IACtF,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAA;CACpC;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAA;IAC3D,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IACjD;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC;;;;;;;;OAQG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7C;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;CACzC;AAED,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;AA2O1C;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI,GACf,SAAS,MAAM,EACf,UAAS,WAAgB,KACxB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,mBAAmB,CAAC,mBAAmB,CAazE,CAAA;AAEN;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,KAAG,QAAQ,CAAC,IACsD,CAAA;AAEjH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,OAAO,SAAS,KAAG,QAAQ,CAAC,QASpE,CAAA"}
|
|
@@ -42,7 +42,8 @@ var ChildProcess = __toESM(require("effect/process/ChildProcess"), 1);
|
|
|
42
42
|
var Schema = __toESM(require("effect/Schema"), 1);
|
|
43
43
|
var Stream = __toESM(require("effect/Stream"), 1);
|
|
44
44
|
var StdError = __toESM(require("../StdError.js"), 1);
|
|
45
|
-
|
|
45
|
+
var import_Text = require("./Text.js");
|
|
46
|
+
const ExecErrorCode = Schema.Literals(["timeout", "spawn_error", "arguments_too_long", "capture_overflow"]);
|
|
46
47
|
class ExecError extends Schema.TaggedError()("@smthrs/std/ExecError", {
|
|
47
48
|
code: ExecErrorCode,
|
|
48
49
|
message: Schema.String,
|
|
@@ -51,44 +52,85 @@ class ExecError extends Schema.TaggedError()("@smthrs/std/ExecError", {
|
|
|
51
52
|
}) {
|
|
52
53
|
}
|
|
53
54
|
const decoder = new TextDecoder("utf-8");
|
|
54
|
-
const
|
|
55
|
-
|
|
55
|
+
const emptyTail = () => ({ chunks: [], bytes: 0, dropped: 0 });
|
|
56
|
+
const isContinuation = (byte) => (byte & 192) === 128;
|
|
57
|
+
const join = (chunks, size) => {
|
|
58
|
+
const bytes = new Uint8Array(size);
|
|
56
59
|
let offset = 0;
|
|
57
|
-
for (const chunk of
|
|
60
|
+
for (const chunk of chunks) {
|
|
58
61
|
bytes.set(chunk, offset);
|
|
59
62
|
offset += chunk.byteLength;
|
|
60
63
|
}
|
|
64
|
+
return bytes;
|
|
65
|
+
};
|
|
66
|
+
const keepTail = (state, chunk, maxBytes) => {
|
|
67
|
+
if (chunk.byteLength === 0) return;
|
|
68
|
+
state.chunks.push(chunk);
|
|
69
|
+
state.bytes += chunk.byteLength;
|
|
70
|
+
while (state.bytes > maxBytes && state.chunks.length > 0) {
|
|
71
|
+
const excess = state.bytes - maxBytes;
|
|
72
|
+
const first = state.chunks[0];
|
|
73
|
+
if (first.byteLength <= excess) {
|
|
74
|
+
state.chunks.shift();
|
|
75
|
+
state.bytes -= first.byteLength;
|
|
76
|
+
state.dropped += first.byteLength;
|
|
77
|
+
} else {
|
|
78
|
+
state.chunks[0] = first.subarray(excess);
|
|
79
|
+
state.bytes -= excess;
|
|
80
|
+
state.dropped += excess;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const decodeTail = (state) => {
|
|
85
|
+
const bytes = join(state.chunks, state.bytes);
|
|
61
86
|
if (state.dropped === 0) return { text: decoder.decode(bytes), droppedBytes: 0 };
|
|
62
87
|
let start = 0;
|
|
63
|
-
while (start < bytes.byteLength && start < 3 && (bytes[start]
|
|
88
|
+
while (start < bytes.byteLength && start < 3 && isContinuation(bytes[start])) start++;
|
|
64
89
|
return { text: decoder.decode(bytes.subarray(start)), droppedBytes: state.dropped + start };
|
|
65
90
|
};
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
state.dropped += first.byteLength;
|
|
80
|
-
} else {
|
|
81
|
-
state.chunks[0] = first.subarray(excess);
|
|
82
|
-
state.bytes -= excess;
|
|
83
|
-
state.dropped += excess;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return state;
|
|
91
|
+
const wholeLength = (bytes) => {
|
|
92
|
+
for (let back = 1; back <= Math.min(3, bytes.byteLength); back++) {
|
|
93
|
+
const byte = bytes[bytes.byteLength - back];
|
|
94
|
+
if (isContinuation(byte)) continue;
|
|
95
|
+
const width = byte >= 240 ? 4 : byte >= 224 ? 3 : byte >= 192 ? 2 : 1;
|
|
96
|
+
return width > back ? bytes.byteLength - back : bytes.byteLength;
|
|
97
|
+
}
|
|
98
|
+
return bytes.byteLength;
|
|
99
|
+
};
|
|
100
|
+
const decodeEnds = (state) => {
|
|
101
|
+
if (state.tail.dropped === 0) {
|
|
102
|
+
const whole = join([...state.head, ...state.tail.chunks], state.headBytes + state.tail.bytes);
|
|
103
|
+
return { text: decoder.decode(whole), droppedBytes: 0 };
|
|
87
104
|
}
|
|
88
|
-
|
|
105
|
+
const head = join(state.head, state.headBytes);
|
|
106
|
+
const kept = wholeLength(head);
|
|
107
|
+
const tail = decodeTail(state.tail);
|
|
108
|
+
const droppedBytes = head.byteLength - kept + tail.droppedBytes;
|
|
109
|
+
return { text: (0, import_Text.elideMiddle)(decoder.decode(head.subarray(0, kept)), droppedBytes, tail.text), droppedBytes };
|
|
110
|
+
};
|
|
111
|
+
const boundedTail = (stream, maxBytes, overflow) => Stream.runFold(stream, emptyTail, (state, chunk) => {
|
|
112
|
+
keepTail(state, chunk, maxBytes);
|
|
113
|
+
return state;
|
|
114
|
+
}).pipe(Effect.map(
|
|
89
115
|
(state) => overflow === "refuse" && state.dropped > 0 ? { text: "", droppedBytes: state.dropped } : decodeTail(state)
|
|
90
116
|
));
|
|
91
|
-
const
|
|
117
|
+
const boundedEnds = (stream, maxBytes) => {
|
|
118
|
+
const headBytes = Math.floor(maxBytes / 2);
|
|
119
|
+
return Stream.runFold(stream, () => ({ head: [], headBytes: 0, tail: emptyTail() }), (state, chunk) => {
|
|
120
|
+
const taken = Math.min(headBytes - state.headBytes, chunk.byteLength);
|
|
121
|
+
if (taken > 0) {
|
|
122
|
+
state.head.push(chunk.subarray(0, taken));
|
|
123
|
+
state.headBytes += taken;
|
|
124
|
+
}
|
|
125
|
+
keepTail(state.tail, chunk.subarray(taken), maxBytes - headBytes);
|
|
126
|
+
return state;
|
|
127
|
+
}).pipe(Effect.map(decodeEnds));
|
|
128
|
+
};
|
|
129
|
+
const capture = (stream, maxBytes, overflow) => maxBytes === void 0 ? Effect.map(Stream.mkString(Stream.decodeText(stream)), (text) => ({ text, droppedBytes: 0 })) : overflow === "ends" ? boundedEnds(stream, maxBytes) : boundedTail(stream, maxBytes, overflow);
|
|
130
|
+
const argumentsTooLong = (error) => error.cause?.code === "E2BIG" ? new ExecError({
|
|
131
|
+
code: "arguments_too_long",
|
|
132
|
+
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."
|
|
133
|
+
}) : void 0;
|
|
92
134
|
const unbounded = (command, options) => Effect.gen(function* () {
|
|
93
135
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
94
136
|
const settings = {
|
|
@@ -133,7 +175,7 @@ const unbounded = (command, options) => Effect.gen(function* () {
|
|
|
133
175
|
}).pipe(
|
|
134
176
|
Effect.scoped,
|
|
135
177
|
Effect.mapError(
|
|
136
|
-
(error) => error instanceof ExecError ? error : new ExecError({
|
|
178
|
+
(error) => error instanceof ExecError ? error : argumentsTooLong(error) ?? new ExecError({
|
|
137
179
|
code: "spawn_error",
|
|
138
180
|
message: `exec: ${command}: ${error.message}`
|
|
139
181
|
})
|
|
@@ -149,10 +191,10 @@ const exec = (command, options = {}) => options.timeoutMs === void 0 ? unbounded
|
|
|
149
191
|
})
|
|
150
192
|
)
|
|
151
193
|
});
|
|
152
|
-
const toStdErrorCode = (error) => error.code === "timeout" ? "timeout" : "command_failed";
|
|
194
|
+
const toStdErrorCode = (error) => error.code === "timeout" ? "timeout" : error.code === "arguments_too_long" ? "invalid_input" : "command_failed";
|
|
153
195
|
const toStdError = (command, error) => new StdError.StdError({
|
|
154
196
|
code: toStdErrorCode(error),
|
|
155
|
-
message: error.code === "timeout" ? `Command timed out: ${command}` : `Command failed to start: ${error.message}`,
|
|
197
|
+
message: error.code === "timeout" ? `Command timed out: ${command}` : error.code === "arguments_too_long" ? error.message : `Command failed to start: ${error.message}`,
|
|
156
198
|
...error.limitMillis === void 0 ? {} : { limitMillis: error.limitMillis }
|
|
157
199
|
});
|
|
158
200
|
//# sourceMappingURL=Exec.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/internal/Exec.ts"],
|
|
4
|
-
"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 * \u2014 including the one a `timeoutMs` interrupts \u2014 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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,8BAAyC;AACzC,0BAAqC;AACrC,aAAwB;AACxB,mBAA8B;AAC9B,aAAwB;AACxB,aAAwB;AACxB,eAA0B;
|
|
4
|
+
"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 * \u2014 including the one a `timeoutMs` interrupts \u2014 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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,8BAAyC;AACzC,0BAAqC;AACrC,aAAwB;AACxB,mBAA8B;AAC9B,aAAwB;AACxB,aAAwB;AACxB,eAA0B;AAC1B,kBAA4B;AASrB,MAAM,gBAA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,YAAY,QAAQ,iBAAiB,KAAK,KAAK,IAAI,UAAU;AAAA,MAC5E,MAAM;AAAA,MACN,SAAS,SAAS,OAAO,KAAK,MAAM,OAAO;AAAA,IAC7C,CAAC;AAAA,EACH;AACF;AAYK,MAAM,OAAO,CAClB,SACA,UAAuB,CAAC,MAExB,QAAQ,cAAc,SAClB,UAAU,SAAS,OAAO,IAC1B,OAAO,cAAc,UAAU,SAAS,OAAO,GAAG;AAAA,EAClD,UAAU,QAAQ;AAAA,EAClB,QAAQ,MACN,OAAO;AAAA,IACL,IAAI,UAAU;AAAA,MACZ,MAAM;AAAA,MACN,SAAS,WAAW,OAAO,eAAe,QAAQ,SAAS;AAAA,MAC3D,aAAa,QAAQ;AAAA,IACvB,CAAC;AAAA,EACH;AACJ,CAAC;AAeE,MAAM,iBAAiB,CAAC,UAC7B,MAAM,SAAS,YAAY,YAAY,MAAM,SAAS,uBAAuB,kBAAkB;AAa1F,MAAM,aAAa,CAAC,SAAiB,UAC1C,IAAI,SAAS,SAAS;AAAA,EACpB,MAAM,eAAe,KAAK;AAAA,EAC1B,SAAS,MAAM,SAAS,YACpB,sBAAsB,OAAO,KAC7B,MAAM,SAAS,uBACf,MAAM,UACN,4BAA4B,MAAM,OAAO;AAAA,EAC7C,GAAI,MAAM,gBAAgB,SAAY,CAAC,IAAI,EAAE,aAAa,MAAM,YAAY;AAC9E,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -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,OAAO,CAAA;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAKD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,MAAM,EACZ,UAAU,MAAM,EAChB,SAAS;IAAE,QAAQ,C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S,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAKD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACxB,MAAM,MAAM,EACZ,UAAU,MAAM,EAChB,SAAS;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,KAC1C,UAwBF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,EAAE,cAAc,MAAM,EAAE,KAAK,MAAM,KAAG,MAG1D,CAAA;AAErB;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,aAAa,CAAC,MAAM,CAI9D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK,GAChB,MAAM,MAAM,EACZ,SAAS;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAC3D,IAWF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,MACL,CAAA"}
|
|
@@ -24,6 +24,7 @@ __export(Text_exports, {
|
|
|
24
24
|
MAX_LINE_CHARS: () => MAX_LINE_CHARS,
|
|
25
25
|
MAX_OUTPUT_BYTES: () => MAX_OUTPUT_BYTES,
|
|
26
26
|
MAX_SHELL_OUTPUT_BYTES: () => MAX_SHELL_OUTPUT_BYTES,
|
|
27
|
+
elideMiddle: () => elideMiddle,
|
|
27
28
|
notice: () => notice,
|
|
28
29
|
slice: () => slice,
|
|
29
30
|
sourceLines: () => sourceLines,
|
|
@@ -61,6 +62,8 @@ const truncateBytes = (text, maxBytes, options) => {
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
};
|
|
65
|
+
const elideMiddle = (start, droppedBytes, end) => `${start}${start === "" || start.endsWith("\n") ? "" : "\n"}[${droppedBytes} ${droppedBytes === 1 ? "byte" : "bytes"} omitted]
|
|
66
|
+
${end}`;
|
|
64
67
|
const sourceLines = (text) => {
|
|
65
68
|
const lines = text.length === 0 ? [] : text.split("\n");
|
|
66
69
|
if (text.endsWith("\n")) lines.pop();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/internal/Text.ts"],
|
|
4
|
-
"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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,MAAM,qBAAqB;AAQ3B,MAAM,cAAc;AAQpB,MAAM,mBAAmB;AAQzB,MAAM,iBAAiB;AAQvB,MAAM,mBAAmB;AAQzB,MAAM,yBAAyB;AA4BtC,MAAM,UAAU,IAAI,YAAY;AAChC,MAAM,eAAe,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC;AAYtD,MAAM,gBAAgB,CAC3B,MACA,UACA,YACe;AACf,QAAM,QAAQ,QAAQ,OAAO,IAAI;AACjC,MAAI,MAAM,cAAc,UAAU;AAChC,WAAO,EAAE,MAAM,WAAW,OAAO,WAAW,MAAM,YAAY,cAAc,EAAE;AAAA,EAChF;AACA,MAAI,QAAQ,QAAQ,SAAS,SAAS,IAAI,MAAM,aAAa;AAC7D,MAAI,MAAM,QAAQ,SAAS,SAAS,WAAW,MAAM;AAGrD,SAAO,MAAM;AACX,QAAI;AACF,YAAM,UAAU,aAAa,OAAO,MAAM,SAAS,OAAO,GAAG,CAAC;AAC9D,YAAM,YAAY,MAAM;AACxB,aAAO;AAAA,QACL,MAAM;AAAA,QACN,WAAW;AAAA,QACX;AAAA,QACA,cAAc,MAAM,aAAa;AAAA,MACnC;AAAA,IACF,QAAQ;AACN,UAAI,QAAQ,SAAS,OAAQ;AAAA,UACxB;AAAA,IACP;AAAA,EACF;AACF;
|
|
4
|
+
"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 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MAAM,IAAI;AACtD,MAAI,KAAK,SAAS,IAAI,EAAG,OAAM,IAAI;AACnC,SAAO;AACT;AAQO,MAAM,QAAQ,CACnB,MACA,YACS;AACT,QAAM,QAAQ,YAAY,IAAI;AAC9B,QAAM,aAAa,MAAM;AACzB,QAAM,YAAY,KAAK,IAAI,GAAG,QAAQ,MAAM;AAC5C,QAAM,UAAU,KAAK,IAAI,YAAY,YAAY,KAAK,IAAI,GAAG,QAAQ,KAAK,IAAI,CAAC;AAC/E,SAAO;AAAA,IACL,OAAO,MAAM,MAAM,YAAY,GAAG,OAAO;AAAA,IACzC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQO,MAAM,SAAS,CAAC,MAAc,OAAe,UAClD,WAAW,KAAK,OAAO,KAAK,IAAI,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Bash.d.ts
CHANGED
|
@@ -133,6 +133,16 @@ export declare const Output: Schema.Struct<{
|
|
|
133
133
|
* @since 1.0.0
|
|
134
134
|
*/
|
|
135
135
|
export type Output = typeof Output.Type;
|
|
136
|
+
/**
|
|
137
|
+
* The text of a stream cut to its start and end: the start, one line naming
|
|
138
|
+
* the bytes omitted between them, and the end. A host that captures output
|
|
139
|
+
* itself, such as a terminal behind {@link inTerminal}, cuts with this so every
|
|
140
|
+
* {@link Output} reads the same.
|
|
141
|
+
*
|
|
142
|
+
* @category rendering
|
|
143
|
+
* @since 1.0.0-rc.5
|
|
144
|
+
*/
|
|
145
|
+
export declare const elideMiddle: (start: string, droppedBytes: number, end: string) => string;
|
|
136
146
|
/**
|
|
137
147
|
* Static conservative effect envelope for the bash flow.
|
|
138
148
|
*
|
package/dist/esm/Bash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bash.d.ts","sourceRoot":"","sources":["../../src/Bash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,KAAK,mBAAmB,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,GAAG,QAAQ,CAAC,QAAuB,CAAA;AAEvF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,EAC1B,SAAS,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qDAapE,CAAA;AAEJ;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,EAAE,WAAW,MAAM,GAAG,SAAS,KAAG,QAAQ,CAAC,QAMxF,CAAA;AAEJ;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,MAAM,GAAI,UAAU,MAAM,MAErC,OAAO,KAAK,KACX,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC,mBAAmB,GAAG,IAAI,CAAC,IAAI,CACO,CAAA"}
|
package/dist/esm/Bash.js
CHANGED
|
@@ -25,7 +25,7 @@ import { capability, envelope } from "./internal/Declaration.js";
|
|
|
25
25
|
import * as Diagnostics from "./internal/Diagnostics.js";
|
|
26
26
|
import { outsideEnvelope } from "./internal/EnvelopePrecheck.js";
|
|
27
27
|
import * as Exec from "./internal/Exec.js";
|
|
28
|
-
import {
|
|
28
|
+
import { elideMiddle as elide, MAX_SHELL_OUTPUT_BYTES } from "./internal/Text.js";
|
|
29
29
|
import * as Probe from "./Probe.js";
|
|
30
30
|
import * as StdError from "./StdError.js";
|
|
31
31
|
import * as TreeFingerprint from "./TreeFingerprint.js";
|
|
@@ -151,10 +151,10 @@ export const Input = Schema.Union([
|
|
|
151
151
|
export const Output = Schema.Struct({
|
|
152
152
|
exitCode: Schema.Number.annotate({ description: "Command exit code, including non-zero codes" }),
|
|
153
153
|
stdout: Schema.String.annotate({
|
|
154
|
-
description: "Captured stdout;
|
|
154
|
+
description: "Captured stdout; when stdoutTruncated is true, only its start and end, with one line naming the bytes omitted between them"
|
|
155
155
|
}),
|
|
156
156
|
stderr: Schema.String.annotate({
|
|
157
|
-
description: "Captured stderr;
|
|
157
|
+
description: "Captured stderr; when stderrTruncated is true, only its start and end, with one line naming the bytes omitted between them"
|
|
158
158
|
}),
|
|
159
159
|
stdoutTruncated: Schema.Boolean.annotate({
|
|
160
160
|
description: "Whether stdout exceeded the capture limit, leaving stdout a fragment that must not be written to a file"
|
|
@@ -162,8 +162,8 @@ export const Output = Schema.Struct({
|
|
|
162
162
|
stderrTruncated: Schema.Boolean.annotate({
|
|
163
163
|
description: "Whether stderr exceeded the capture limit, leaving stderr a fragment that must not be written to a file"
|
|
164
164
|
}),
|
|
165
|
-
stdoutDroppedBytes: Schema.Number.annotate({ description: "UTF-8 bytes omitted from the
|
|
166
|
-
stderrDroppedBytes: Schema.Number.annotate({ description: "UTF-8 bytes omitted from the
|
|
165
|
+
stdoutDroppedBytes: Schema.Number.annotate({ description: "UTF-8 bytes omitted from the middle of stdout" }),
|
|
166
|
+
stderrDroppedBytes: Schema.Number.annotate({ description: "UTF-8 bytes omitted from the middle of stderr" }),
|
|
167
167
|
invalidProbe: Schema.optional(Probe.InvalidProbe.annotate({
|
|
168
168
|
description: "Reserved for a confirmed launch failure; an exit code alone does not establish one"
|
|
169
169
|
})),
|
|
@@ -171,6 +171,16 @@ export const Output = Schema.Struct({
|
|
|
171
171
|
description: "Present for a containerised command whose working directory was measured before and after it: true when the tree changed, false when it held still. Absent when the tree was not measured, which is never read as unchanged."
|
|
172
172
|
}))
|
|
173
173
|
});
|
|
174
|
+
/**
|
|
175
|
+
* The text of a stream cut to its start and end: the start, one line naming
|
|
176
|
+
* the bytes omitted between them, and the end. A host that captures output
|
|
177
|
+
* itself, such as a terminal behind {@link inTerminal}, cuts with this so every
|
|
178
|
+
* {@link Output} reads the same.
|
|
179
|
+
*
|
|
180
|
+
* @category rendering
|
|
181
|
+
* @since 1.0.0-rc.5
|
|
182
|
+
*/
|
|
183
|
+
export const elideMiddle = elide;
|
|
174
184
|
/**
|
|
175
185
|
* Static conservative effect envelope for the bash flow.
|
|
176
186
|
*
|
|
@@ -424,6 +434,7 @@ export const run = Effect.fn("Bash.run")(function* (input) {
|
|
|
424
434
|
...(spawned.env === undefined ? {} : { env: spawned.env }),
|
|
425
435
|
timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
426
436
|
maxCaptureBytes: MAX_SHELL_OUTPUT_BYTES,
|
|
437
|
+
overflow: "ends",
|
|
427
438
|
...(spawned.args === undefined ? {} : { args: spawned.args }),
|
|
428
439
|
...(spawned.stdin === undefined ? {} : { stdin: spawned.stdin })
|
|
429
440
|
}).pipe(Effect.mapError((error) => Exec.toStdError(spawned.quoted, error)));
|
|
@@ -432,18 +443,16 @@ export const run = Effect.fn("Bash.run")(function* (input) {
|
|
|
432
443
|
// open; a container's files are not the ones it was sent.
|
|
433
444
|
if (!contained)
|
|
434
445
|
yield* Diagnostics.refresh;
|
|
435
|
-
const stdout = truncateBytes(result.stdout, MAX_SHELL_OUTPUT_BYTES, { keep: "tail" });
|
|
436
|
-
const stderr = truncateBytes(result.stderr, MAX_SHELL_OUTPUT_BYTES, { keep: "tail" });
|
|
437
446
|
// Exit codes alone cannot establish whether the shell refused to launch a
|
|
438
447
|
// command or a launched runner chose that status after executing tests.
|
|
439
448
|
return {
|
|
440
449
|
exitCode: result.exitCode,
|
|
441
|
-
stdout: stdout
|
|
442
|
-
stderr: stderr
|
|
443
|
-
stdoutTruncated: result.stdoutDroppedBytes > 0
|
|
444
|
-
stderrTruncated: result.stderrDroppedBytes > 0
|
|
445
|
-
stdoutDroppedBytes: result.stdoutDroppedBytes
|
|
446
|
-
stderrDroppedBytes: result.stderrDroppedBytes
|
|
450
|
+
stdout: result.stdout,
|
|
451
|
+
stderr: result.stderr,
|
|
452
|
+
stdoutTruncated: result.stdoutDroppedBytes > 0,
|
|
453
|
+
stderrTruncated: result.stderrDroppedBytes > 0,
|
|
454
|
+
stdoutDroppedBytes: result.stdoutDroppedBytes,
|
|
455
|
+
stderrDroppedBytes: result.stderrDroppedBytes,
|
|
447
456
|
...(mutated === undefined ? {} : { mutated })
|
|
448
457
|
};
|
|
449
458
|
});
|