@smthrs/std 1.0.0-rc.5 → 1.0.0-rc.7
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/README.md +39 -39
- 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/ExaWebSearch.js +1 -1
- package/dist/cjs/ExaWebSearch.js.map +1 -1
- package/dist/cjs/Fetch.d.ts +1 -1
- package/dist/cjs/Fetch.d.ts.map +1 -1
- package/dist/cjs/Fetch.js +1 -1
- package/dist/cjs/Fetch.js.map +2 -2
- package/dist/cjs/HttpPost.d.ts +1 -1
- package/dist/cjs/HttpPost.d.ts.map +1 -1
- package/dist/cjs/HttpPost.js +1 -1
- package/dist/cjs/HttpPost.js.map +2 -2
- package/dist/cjs/Lsp.d.ts +1 -1
- package/dist/cjs/Manifest.d.ts +8 -8
- package/dist/cjs/NodeLanguageServer.js +1 -1
- package/dist/cjs/NodeLanguageServer.js.map +1 -1
- package/dist/cjs/WebFetch.d.ts.map +1 -1
- package/dist/cjs/WebFetch.js +1 -1
- package/dist/cjs/WebFetch.js.map +2 -2
- package/dist/cjs/internal/Exec.d.ts +14 -7
- package/dist/cjs/internal/Exec.d.ts.map +1 -1
- package/dist/cjs/internal/Exec.js +66 -28
- package/dist/cjs/internal/Exec.js.map +2 -2
- package/dist/cjs/internal/Http.d.ts +1 -1
- package/dist/cjs/internal/Http.d.ts.map +1 -1
- package/dist/cjs/internal/Http.js +1 -1
- package/dist/cjs/internal/Http.js.map +2 -2
- package/dist/cjs/internal/HttpNetwork.d.ts +2 -2
- package/dist/cjs/internal/HttpNetwork.d.ts.map +1 -1
- package/dist/cjs/internal/HttpNetwork.js +3 -3
- package/dist/cjs/internal/HttpNetwork.js.map +1 -1
- 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/ExaWebSearch.js +1 -1
- package/dist/esm/ExaWebSearch.js.map +1 -1
- package/dist/esm/Fetch.d.ts +1 -1
- package/dist/esm/Fetch.d.ts.map +1 -1
- package/dist/esm/Fetch.js +1 -1
- package/dist/esm/Fetch.js.map +1 -1
- package/dist/esm/HttpPost.d.ts +1 -1
- package/dist/esm/HttpPost.d.ts.map +1 -1
- package/dist/esm/HttpPost.js +1 -1
- package/dist/esm/HttpPost.js.map +1 -1
- package/dist/esm/Lsp.d.ts +1 -1
- package/dist/esm/Manifest.d.ts +8 -8
- package/dist/esm/NodeLanguageServer.js +1 -1
- package/dist/esm/NodeLanguageServer.js.map +1 -1
- package/dist/esm/WebFetch.d.ts.map +1 -1
- package/dist/esm/WebFetch.js +1 -1
- package/dist/esm/WebFetch.js.map +1 -1
- package/dist/esm/internal/Exec.d.ts +14 -7
- package/dist/esm/internal/Exec.d.ts.map +1 -1
- package/dist/esm/internal/Exec.js +87 -22
- package/dist/esm/internal/Exec.js.map +1 -1
- package/dist/esm/internal/Http.d.ts +1 -1
- package/dist/esm/internal/Http.d.ts.map +1 -1
- package/dist/esm/internal/Http.js +1 -1
- package/dist/esm/internal/Http.js.map +1 -1
- package/dist/esm/internal/HttpNetwork.d.ts +2 -2
- package/dist/esm/internal/HttpNetwork.d.ts.map +1 -1
- package/dist/esm/internal/HttpNetwork.js +3 -3
- package/dist/esm/internal/HttpNetwork.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/api.md +1 -1
- package/docs/concepts/limits-and-disclosure.md +8 -5
- package/docs/guides/run-a-shell-command.md +16 -6
- package/docs/installation.md +1 -1
- package/docs/reference/flows.md +2 -2
- package/docs/troubleshooting.md +3 -3
- package/package.json +10 -10
- package/src/Bash.ts +25 -13
- package/src/ExaWebSearch.ts +1 -1
- package/src/Fetch.ts +1 -1
- package/src/HttpPost.ts +1 -1
- package/src/NodeLanguageServer.ts +1 -1
- package/src/WebFetch.ts +1 -1
- package/src/internal/Exec.ts +126 -44
- package/src/internal/Http.ts +1 -1
- package/src/internal/HttpNetwork.ts +3 -3
- package/src/internal/Text.ts +15 -0
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
import * as ChildProcessEnvironment from "@smthrs/kernel/ChildProcessEnvironment";
|
|
17
17
|
import * as ChildProcessSpawner from "@smthrs/kernel/ChildProcessSpawner";
|
|
18
18
|
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as ChildProcess from "effect/process/ChildProcess";
|
|
19
20
|
import * as Schema from "effect/Schema";
|
|
20
21
|
import * as Stream from "effect/Stream";
|
|
21
|
-
import * as ChildProcess from "effect/unstable/process/ChildProcess";
|
|
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.
|
|
@@ -46,32 +47,22 @@ export class ExecError extends Schema.TaggedError()("@smthrs/std/ExecError", {
|
|
|
46
47
|
}) {
|
|
47
48
|
}
|
|
48
49
|
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);
|
|
50
|
+
const emptyTail = () => ({ chunks: [], bytes: 0, dropped: 0 });
|
|
51
|
+
/** A UTF-8 continuation byte is `10xxxxxx`; every other byte starts a character. */
|
|
52
|
+
const isContinuation = (byte) => (byte & 0b1100_0000) === 0b1000_0000;
|
|
53
|
+
const join = (chunks, size) => {
|
|
54
|
+
const bytes = new Uint8Array(size);
|
|
60
55
|
let offset = 0;
|
|
61
|
-
for (const chunk of
|
|
56
|
+
for (const chunk of chunks) {
|
|
62
57
|
bytes.set(chunk, offset);
|
|
63
58
|
offset += chunk.byteLength;
|
|
64
59
|
}
|
|
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 };
|
|
60
|
+
return bytes;
|
|
71
61
|
};
|
|
72
|
-
|
|
62
|
+
/** Appends one chunk and drops from the front whatever no longer fits. */
|
|
63
|
+
const keepTail = (state, chunk, maxBytes) => {
|
|
73
64
|
if (chunk.byteLength === 0)
|
|
74
|
-
return
|
|
65
|
+
return;
|
|
75
66
|
state.chunks.push(chunk);
|
|
76
67
|
state.bytes += chunk.byteLength;
|
|
77
68
|
while (state.bytes > maxBytes && state.chunks.length > 0) {
|
|
@@ -88,13 +79,87 @@ const boundedTail = (stream, maxBytes, overflow) => Stream.runFold(stream, () =>
|
|
|
88
79
|
state.dropped += excess;
|
|
89
80
|
}
|
|
90
81
|
}
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Joins the retained chunks and decodes them, skipping the partial code point a
|
|
85
|
+
* dropped head can leave behind.
|
|
86
|
+
*
|
|
87
|
+
* A code point is at most four bytes, so at most three leading continuation
|
|
88
|
+
* bytes can precede the first whole character. Skipping them is counted as
|
|
89
|
+
* dropped rather than decoded to a replacement character the process never
|
|
90
|
+
* printed.
|
|
91
|
+
*/
|
|
92
|
+
const decodeTail = (state) => {
|
|
93
|
+
const bytes = join(state.chunks, state.bytes);
|
|
94
|
+
if (state.dropped === 0)
|
|
95
|
+
return { text: decoder.decode(bytes), droppedBytes: 0 };
|
|
96
|
+
let start = 0;
|
|
97
|
+
while (start < bytes.byteLength && start < 3 && isContinuation(bytes[start]))
|
|
98
|
+
start++;
|
|
99
|
+
return { text: decoder.decode(bytes.subarray(start)), droppedBytes: state.dropped + start };
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The length of a cut head without the character the cut left unfinished.
|
|
103
|
+
*
|
|
104
|
+
* Its last character starts at the last byte that is not a continuation byte,
|
|
105
|
+
* and that byte says how many bytes the character needs. One that needs more
|
|
106
|
+
* than the head holds is dropped, for the same reason {@link decodeTail} skips
|
|
107
|
+
* a partial code point.
|
|
108
|
+
*/
|
|
109
|
+
const wholeLength = (bytes) => {
|
|
110
|
+
for (let back = 1; back <= Math.min(3, bytes.byteLength); back++) {
|
|
111
|
+
const byte = bytes[bytes.byteLength - back];
|
|
112
|
+
if (isContinuation(byte))
|
|
113
|
+
continue;
|
|
114
|
+
const width = byte >= 0b1111_0000 ? 4 : byte >= 0b1110_0000 ? 3 : byte >= 0b1100_0000 ? 2 : 1;
|
|
115
|
+
return width > back ? bytes.byteLength - back : bytes.byteLength;
|
|
116
|
+
}
|
|
117
|
+
return bytes.byteLength;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Decodes a stream kept by its ends. A stream that fit is decoded whole;
|
|
121
|
+
* otherwise each end is cut on a character boundary and one line naming every
|
|
122
|
+
* byte between them stands where the middle was.
|
|
123
|
+
*/
|
|
124
|
+
const decodeEnds = (state) => {
|
|
125
|
+
if (state.tail.dropped === 0) {
|
|
126
|
+
const whole = join([...state.head, ...state.tail.chunks], state.headBytes + state.tail.bytes);
|
|
127
|
+
return { text: decoder.decode(whole), droppedBytes: 0 };
|
|
128
|
+
}
|
|
129
|
+
const head = join(state.head, state.headBytes);
|
|
130
|
+
const kept = wholeLength(head);
|
|
131
|
+
const tail = decodeTail(state.tail);
|
|
132
|
+
const droppedBytes = head.byteLength - kept + tail.droppedBytes;
|
|
133
|
+
return { text: elideMiddle(decoder.decode(head.subarray(0, kept)), droppedBytes, tail.text), droppedBytes };
|
|
134
|
+
};
|
|
135
|
+
const boundedTail = (stream, maxBytes, overflow) => Stream.runFold(stream, emptyTail, (state, chunk) => {
|
|
136
|
+
keepTail(state, chunk, maxBytes);
|
|
91
137
|
return state;
|
|
92
138
|
}).pipe(Effect.map((state) => overflow === "refuse" && state.dropped > 0
|
|
93
139
|
? { text: "", droppedBytes: state.dropped }
|
|
94
140
|
: decodeTail(state)));
|
|
141
|
+
/**
|
|
142
|
+
* Keeps the first half of the bound and the last half. The head fills first,
|
|
143
|
+
* and every byte after it passes through the tail, which drops from its front:
|
|
144
|
+
* what falls out of the tail is the middle.
|
|
145
|
+
*/
|
|
146
|
+
const boundedEnds = (stream, maxBytes) => {
|
|
147
|
+
const headBytes = Math.floor(maxBytes / 2);
|
|
148
|
+
return Stream.runFold(stream, () => ({ head: [], headBytes: 0, tail: emptyTail() }), (state, chunk) => {
|
|
149
|
+
const taken = Math.min(headBytes - state.headBytes, chunk.byteLength);
|
|
150
|
+
if (taken > 0) {
|
|
151
|
+
state.head.push(chunk.subarray(0, taken));
|
|
152
|
+
state.headBytes += taken;
|
|
153
|
+
}
|
|
154
|
+
keepTail(state.tail, chunk.subarray(taken), maxBytes - headBytes);
|
|
155
|
+
return state;
|
|
156
|
+
}).pipe(Effect.map(decodeEnds));
|
|
157
|
+
};
|
|
95
158
|
const capture = (stream, maxBytes, overflow) => maxBytes === undefined
|
|
96
159
|
? Effect.map(Stream.mkString(Stream.decodeText(stream)), (text) => ({ text, droppedBytes: 0 }))
|
|
97
|
-
:
|
|
160
|
+
: overflow === "ends"
|
|
161
|
+
? boundedEnds(stream, maxBytes)
|
|
162
|
+
: boundedTail(stream, maxBytes, overflow);
|
|
98
163
|
const unbounded = (command, options) => Effect.gen(function* () {
|
|
99
164
|
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
100
165
|
const settings = {
|
|
@@ -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,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,sCAAsC,CAAA;AACpE,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,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,MAAM,GAAG,CAAC,CAAA;IACd,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjC,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AC,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 Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport * as ChildProcess from \"effect/unstable/process/ChildProcess\"\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,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC;;;;;;GAMG;AACH,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C/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\"\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\", \"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 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\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"]}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import type { GrantStore } from "@smthrs/kernel/GrantStore";
|
|
7
7
|
import * as HttpClient from "@smthrs/kernel/HttpClient";
|
|
8
8
|
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
9
10
|
import * as Schema from "effect/Schema";
|
|
10
11
|
import * as Stream from "effect/Stream";
|
|
11
|
-
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
|
12
12
|
import * as StdError from "../StdError.ts";
|
|
13
13
|
/**
|
|
14
14
|
* Maximum captured response bytes before decoding.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../../src/internal/Http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,UAAU,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../../src/internal/Http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,UAAU,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAK1C;;;;;GAKG;AAC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CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,OAAO;kBAEF,MAAM;uBACD,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS;uBAC5C,MAAM,GAAG,SAAS;sBAEpB,MAAM,KAAK,iBAAiB,CAAC,iBAAiB;;;;;yDA2BjE,CAAA"}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as HttpClient from "@smthrs/kernel/HttpClient";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
8
9
|
import * as Schema from "effect/Schema";
|
|
9
10
|
import * as Stream from "effect/Stream";
|
|
10
|
-
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
|
11
11
|
import * as StdError from "../StdError.js";
|
|
12
12
|
import { guarded, refusal } from "./HttpNetwork.js";
|
|
13
13
|
import { MAX_OUTPUT_BYTES, notice, truncateBytes } from "./Text.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.js","sourceRoot":"","sources":["../../../src/internal/Http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,UAAU,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,iBAAiB,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAA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CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;QAC5D,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAA;IAC3C,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EACnE,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,OAAO,CACd,CAAA;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,GAAG,SAAS,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1E,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,CAAA;AAC9C,CAAC,CAAC,CAAA","sourcesContent":["/**\n * Shared HTTP response limits, error mapping, and request deadlines.\n *\n * @since 1.0.0\n */\n\nimport type { GrantStore } from \"@smthrs/kernel/GrantStore\"\nimport * as HttpClient from \"@smthrs/kernel/HttpClient\"\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport * as HttpClientRequest from \"effect/unstable/http/HttpClientRequest\"\nimport * as StdError from \"../StdError.ts\"\nimport { guarded, refusal } from \"./HttpNetwork.ts\"\nimport { MAX_OUTPUT_BYTES, notice, truncateBytes } from \"./Text.ts\"\nimport { parseHttpUrl } from \"./Url.ts\"\n\n/**\n * Maximum captured response bytes before decoding.\n *\n * @category http\n * @since 1.0.0\n */\nexport const MAX_RESPONSE_BYTES = 5 * 1024 * 1024\n\ninterface BodyState {\n readonly chunks: Array<Uint8Array>\n size: number\n}\n\n/**\n * Reads a response up to the shared byte limit and finalizes the stream on failure.\n *\n * @category http\n * @since 1.0.0\n */\nexport const readBounded = <E, R>(\n stream: Stream.Stream<Uint8Array, E, R>,\n url: string\n): Effect.Effect<Uint8Array, E | StdError.StdError, R> =>\n Stream.runFoldEffect(\n stream,\n (): BodyState => ({ chunks: [], size: 0 }),\n (state, chunk) => {\n const size = state.size + chunk.byteLength\n if (size > MAX_RESPONSE_BYTES) {\n return Effect.fail(\n new StdError.StdError({\n code: \"response_too_large\",\n message: \"Response exceeds the 5 MiB limit\",\n path: url\n })\n )\n }\n state.chunks.push(chunk)\n state.size = size\n return Effect.succeed(state)\n }\n ).pipe(\n Effect.map((state) => {\n const output = new Uint8Array(state.size)\n let offset = 0\n for (const chunk of state.chunks) {\n output.set(chunk, offset)\n offset += chunk.byteLength\n }\n return output\n })\n )\n\n/**\n * Maps transport failures while preserving standard HTTP failure codes.\n *\n * @category http\n * @since 1.0.0\n */\nexport const requestError = (url: string, error: unknown): StdError.StdError =>\n error instanceof StdError.StdError ? error : refusal(error) ?? new StdError.StdError({\n code: \"request_failed\",\n message: `Request failed: ${url}${error instanceof Error ? ` (${error.message})` : \"\"}`\n })\n\n/**\n * Looks up a response header without depending on transport normalization.\n *\n * @category http\n * @since 1.0.0\n */\nexport const header = (headers: Readonly<Record<string, string | undefined>>, name: string): string | undefined => {\n const lower = name.toLowerCase()\n return Object.entries(headers).find(([key]) => key.toLowerCase() === lower)?.[1]\n}\n\n/**\n * Seconds; the runtime caps valid overrides at 120.\n *\n * @category http\n * @since 1.0.0\n */\nexport const Timeout = Schema.Number.check(Schema.isFinite(), Schema.isGreaterThan(0))\n\n/**\n * Bounds the entire request and body read with one timer. Interruption reaches\n * HttpClient.execute and response.stream so Effect aborts the transport and\n * finalizes the body reader before returning the timeout failure.\n * `timeoutError` preserves a tool's own timeout message while sharing the\n * validation, duration cap, and interruption behavior.\n *\n * @category http\n * @since 1.0.0\n */\nexport const withDeadline = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n url: string,\n timeout = 30,\n timeoutError?: (seconds: number) => StdError.StdError\n): Effect.Effect<A, E | StdError.StdError, R> => {\n if (!Schema.is(Timeout)(timeout)) {\n return Effect.fail(\n new StdError.StdError({\n code: \"invalid_input\",\n message: \"Timeout must be a finite number greater than zero seconds\",\n path: url\n })\n )\n }\n const seconds = Math.min(timeout, 120)\n return Effect.timeoutOrElse(effect, {\n duration: seconds * 1_000,\n orElse: () =>\n Effect.fail(\n timeoutError?.(seconds) ?? new StdError.StdError({\n code: \"timeout\",\n message: `Request timed out after ${seconds} seconds`,\n path: url\n })\n )\n })\n}\n\n/**\n * Keeps the head of rendered response text within the shared output budget and\n * discloses the cut.\n *\n * @since 1.0.0\n * @private\n */\nexport const capOutput = (\n text: string\n): { readonly text: string; readonly truncated: boolean; readonly notice?: string } => {\n const rendered = truncateBytes(text, MAX_OUTPUT_BYTES, { keep: \"head\" })\n return {\n text: rendered.text,\n truncated: rendered.truncated,\n ...(rendered.truncated\n ? { notice: notice(\"bytes\", rendered.keptBytes, rendered.keptBytes + rendered.droppedBytes) }\n : {})\n }\n}\n\n/** Shared response contract for the GET and POST tools.\n * @since 1.0.0\n * @private\n */\nexport const Response = Schema.Struct({\n status: Schema.Number.annotate({ description: \"HTTP status code, including error statuses\" }),\n body: Schema.String.annotate({ description: \"Response body as text\" }),\n truncated: Schema.Boolean.annotate({ description: \"Whether the body exceeded the display budget\" }),\n notice: Schema.optional(Schema.String.annotate({ description: \"Truncation disclosure\" }))\n})\n\n/** Validate, execute, and render one bounded HTTP request.\n * @since 1.0.0\n * @private\n */\nexport const execute = Effect.fn(\"Http.execute\")(function*(\n input: {\n readonly url: string\n readonly headers?: Readonly<Record<string, string>> | undefined\n readonly timeout?: number | undefined\n },\n makeRequest: (url: string) => HttpClientRequest.HttpClientRequest\n): Effect.fn.Return<typeof Response.Type, StdError.StdError, HttpClient.HttpClient | GrantStore> {\n const url = parseHttpUrl(input.url)\n if (url === undefined) {\n return yield* Effect.fail(\n new StdError.StdError({\n code: \"invalid_input\",\n message: `URL must use http or https without user information: ${input.url}`,\n path: input.url\n })\n )\n }\n const client = guarded(yield* HttpClient.HttpClient)\n const request = makeRequest(url.toString())\n const { status, bytes } = yield* withDeadline(\n Effect.gen(function*() {\n const response = yield* client.execute(\n input.headers === undefined ? request : HttpClientRequest.setHeaders(request, input.headers)\n )\n const bytes = yield* readBounded(response.stream, input.url)\n return { status: response.status, bytes }\n }).pipe(Effect.mapError((error) => requestError(input.url, error))),\n input.url,\n input.timeout\n )\n const { text, ...disclosure } = capOutput(new TextDecoder().decode(bytes))\n return { status, body: text, ...disclosure }\n})\n"]}
|
|
1
|
+
{"version":3,"file":"Http.js","sourceRoot":"","sources":["../../../src/internal/Http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,UAAU,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAA;AAClE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AAOjD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAuC,EACvC,GAAW,EAC0C,EAAE,CACvD,MAAM,CAAC,aAAa,CAClB,MAAM,EACN,GAAc,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAC1C,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;IACf,MAAM,IAAI,GAAG,KAAK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,OAAO,CACd,CAAA;IACD,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,GAAG,SAAS,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1E,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,UAAU,EAAE,CAAA;AAC9C,CAAC,CAAC,CAAA","sourcesContent":["/**\n * Shared HTTP response limits, error mapping, and request deadlines.\n *\n * @since 1.0.0\n */\n\nimport type { GrantStore } from \"@smthrs/kernel/GrantStore\"\nimport * as HttpClient from \"@smthrs/kernel/HttpClient\"\nimport * as Effect from \"effect/Effect\"\nimport * as HttpClientRequest from \"effect/http/HttpClientRequest\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport * as StdError from \"../StdError.ts\"\nimport { guarded, refusal } from \"./HttpNetwork.ts\"\nimport { MAX_OUTPUT_BYTES, notice, truncateBytes } from \"./Text.ts\"\nimport { parseHttpUrl } from \"./Url.ts\"\n\n/**\n * Maximum captured response bytes before decoding.\n *\n * @category http\n * @since 1.0.0\n */\nexport const MAX_RESPONSE_BYTES = 5 * 1024 * 1024\n\ninterface BodyState {\n readonly chunks: Array<Uint8Array>\n size: number\n}\n\n/**\n * Reads a response up to the shared byte limit and finalizes the stream on failure.\n *\n * @category http\n * @since 1.0.0\n */\nexport const readBounded = <E, R>(\n stream: Stream.Stream<Uint8Array, E, R>,\n url: string\n): Effect.Effect<Uint8Array, E | StdError.StdError, R> =>\n Stream.runFoldEffect(\n stream,\n (): BodyState => ({ chunks: [], size: 0 }),\n (state, chunk) => {\n const size = state.size + chunk.byteLength\n if (size > MAX_RESPONSE_BYTES) {\n return Effect.fail(\n new StdError.StdError({\n code: \"response_too_large\",\n message: \"Response exceeds the 5 MiB limit\",\n path: url\n })\n )\n }\n state.chunks.push(chunk)\n state.size = size\n return Effect.succeed(state)\n }\n ).pipe(\n Effect.map((state) => {\n const output = new Uint8Array(state.size)\n let offset = 0\n for (const chunk of state.chunks) {\n output.set(chunk, offset)\n offset += chunk.byteLength\n }\n return output\n })\n )\n\n/**\n * Maps transport failures while preserving standard HTTP failure codes.\n *\n * @category http\n * @since 1.0.0\n */\nexport const requestError = (url: string, error: unknown): StdError.StdError =>\n error instanceof StdError.StdError ? error : refusal(error) ?? new StdError.StdError({\n code: \"request_failed\",\n message: `Request failed: ${url}${error instanceof Error ? ` (${error.message})` : \"\"}`\n })\n\n/**\n * Looks up a response header without depending on transport normalization.\n *\n * @category http\n * @since 1.0.0\n */\nexport const header = (headers: Readonly<Record<string, string | undefined>>, name: string): string | undefined => {\n const lower = name.toLowerCase()\n return Object.entries(headers).find(([key]) => key.toLowerCase() === lower)?.[1]\n}\n\n/**\n * Seconds; the runtime caps valid overrides at 120.\n *\n * @category http\n * @since 1.0.0\n */\nexport const Timeout = Schema.Number.check(Schema.isFinite(), Schema.isGreaterThan(0))\n\n/**\n * Bounds the entire request and body read with one timer. Interruption reaches\n * HttpClient.execute and response.stream so Effect aborts the transport and\n * finalizes the body reader before returning the timeout failure.\n * `timeoutError` preserves a tool's own timeout message while sharing the\n * validation, duration cap, and interruption behavior.\n *\n * @category http\n * @since 1.0.0\n */\nexport const withDeadline = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n url: string,\n timeout = 30,\n timeoutError?: (seconds: number) => StdError.StdError\n): Effect.Effect<A, E | StdError.StdError, R> => {\n if (!Schema.is(Timeout)(timeout)) {\n return Effect.fail(\n new StdError.StdError({\n code: \"invalid_input\",\n message: \"Timeout must be a finite number greater than zero seconds\",\n path: url\n })\n )\n }\n const seconds = Math.min(timeout, 120)\n return Effect.timeoutOrElse(effect, {\n duration: seconds * 1_000,\n orElse: () =>\n Effect.fail(\n timeoutError?.(seconds) ?? new StdError.StdError({\n code: \"timeout\",\n message: `Request timed out after ${seconds} seconds`,\n path: url\n })\n )\n })\n}\n\n/**\n * Keeps the head of rendered response text within the shared output budget and\n * discloses the cut.\n *\n * @since 1.0.0\n * @private\n */\nexport const capOutput = (\n text: string\n): { readonly text: string; readonly truncated: boolean; readonly notice?: string } => {\n const rendered = truncateBytes(text, MAX_OUTPUT_BYTES, { keep: \"head\" })\n return {\n text: rendered.text,\n truncated: rendered.truncated,\n ...(rendered.truncated\n ? { notice: notice(\"bytes\", rendered.keptBytes, rendered.keptBytes + rendered.droppedBytes) }\n : {})\n }\n}\n\n/** Shared response contract for the GET and POST tools.\n * @since 1.0.0\n * @private\n */\nexport const Response = Schema.Struct({\n status: Schema.Number.annotate({ description: \"HTTP status code, including error statuses\" }),\n body: Schema.String.annotate({ description: \"Response body as text\" }),\n truncated: Schema.Boolean.annotate({ description: \"Whether the body exceeded the display budget\" }),\n notice: Schema.optional(Schema.String.annotate({ description: \"Truncation disclosure\" }))\n})\n\n/** Validate, execute, and render one bounded HTTP request.\n * @since 1.0.0\n * @private\n */\nexport const execute = Effect.fn(\"Http.execute\")(function*(\n input: {\n readonly url: string\n readonly headers?: Readonly<Record<string, string>> | undefined\n readonly timeout?: number | undefined\n },\n makeRequest: (url: string) => HttpClientRequest.HttpClientRequest\n): Effect.fn.Return<typeof Response.Type, StdError.StdError, HttpClient.HttpClient | GrantStore> {\n const url = parseHttpUrl(input.url)\n if (url === undefined) {\n return yield* Effect.fail(\n new StdError.StdError({\n code: \"invalid_input\",\n message: `URL must use http or https without user information: ${input.url}`,\n path: input.url\n })\n )\n }\n const client = guarded(yield* HttpClient.HttpClient)\n const request = makeRequest(url.toString())\n const { status, bytes } = yield* withDeadline(\n Effect.gen(function*() {\n const response = yield* client.execute(\n input.headers === undefined ? request : HttpClientRequest.setHeaders(request, input.headers)\n )\n const bytes = yield* readBounded(response.stream, input.url)\n return { status: response.status, bytes }\n }).pipe(Effect.mapError((error) => requestError(input.url, error))),\n input.url,\n input.timeout\n )\n const { text, ...disclosure } = capOutput(new TextDecoder().decode(bytes))\n return { status, body: text, ...disclosure }\n})\n"]}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { GrantStore } from "@smthrs/kernel/GrantStore";
|
|
7
7
|
import { Context, Effect } from "effect";
|
|
8
|
-
import * as HttpClient from "effect/
|
|
9
|
-
import * as HttpClientError from "effect/
|
|
8
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
9
|
+
import * as HttpClientError from "effect/http/HttpClientError";
|
|
10
10
|
import * as StdError from "../StdError.ts";
|
|
11
11
|
/** Resolver seam: all addresses must be public before an unprivileged request.
|
|
12
12
|
* @since 1.0.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpNetwork.d.ts","sourceRoot":"","sources":["../../../src/internal/HttpNetwork.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAOtD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAEhD,OAAO,KAAK,UAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"HttpNetwork.d.ts","sourceRoot":"","sources":["../../../src/internal/HttpNetwork.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAOtD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAEhD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAG9D,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAG1C;;;GAGG;AACH,eAAO,MAAM,WAAW,+BACX,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAInE,CAAA;AAwEF;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,QAAQ,UAAU,CAAC,UAAU,EAC7B,gBAAa,KACZ,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,EAAE,UAAU,CAuBxE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,KAAG,QAAQ,CAAC,QAAQ,GAAG,SAW5D,CAAA"}
|
|
@@ -7,9 +7,9 @@ import * as Capability from "@smthrs/capability/Capability";
|
|
|
7
7
|
import { GrantStore } from "@smthrs/kernel/GrantStore";
|
|
8
8
|
import { authorizePreflight, Destination, fromHttpClientError, supportsDestinationPinning } from "@smthrs/kernel/HttpClient";
|
|
9
9
|
import { Context, Effect, Option } from "effect";
|
|
10
|
-
import * as FetchHttpClient from "effect/
|
|
11
|
-
import * as HttpClient from "effect/
|
|
12
|
-
import * as HttpClientError from "effect/
|
|
10
|
+
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
11
|
+
import * as HttpClient from "effect/http/HttpClient";
|
|
12
|
+
import * as HttpClientError from "effect/http/HttpClientError";
|
|
13
13
|
import { lookup } from "node:dns/promises";
|
|
14
14
|
import { BlockList, isIP } from "node:net";
|
|
15
15
|
import * as StdError from "../StdError.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpNetwork.js","sourceRoot":"","sources":["../../../src/internal/HttpNetwork.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,UAAU,MAAM,+BAA+B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAChD,OAAO,KAAK,eAAe,MAAM,sCAAsC,CAAA;AACvE,OAAO,KAAK,UAAU,MAAM,iCAAiC,CAAA;AAC7D,OAAO,KAAK,eAAe,MAAM,sCAAsC,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C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AC,OAAO,EAAE,CAAC;KAC3F,CAAC,CACH,EACD,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAC7B,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,OAA+B,EAAE,EAAE,CAChE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE,eAAe,CAAC,WAAW,EAAE;QACvF,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,CAAC,WAAW,CAAC;QAC/D,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC,CACN,CACF,CACF,CACJ,CAAA;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AAC/D,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAiC,EAAE;IACvE,IAAI,CAAC,CAAC,KAAK,YAAY,eAAe,CAAC,eAAe,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,SAAS,CAAA;IACnH,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,YAAY,QAAQ,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAA;IAC9E,IAAI,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC9C,OAAO,OAAO,CACZ,mBAAmB,EACnB,KAAK,CAAC,MAAM,CAAC,WAAW,IAAI,6BAA6B,EACzD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CACzB,CAAA;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA","sourcesContent":["/**\n * Destination policy shared by the web tools, including every redirect hop.\n *\n * @since 1.0.0\n */\n\nimport * as Capability from \"@smthrs/capability/Capability\"\nimport { GrantStore } from \"@smthrs/kernel/GrantStore\"\nimport {\n authorizePreflight,\n Destination,\n fromHttpClientError,\n supportsDestinationPinning\n} from \"@smthrs/kernel/HttpClient\"\nimport { Context, Effect, Option } from \"effect\"\nimport * as FetchHttpClient from \"effect/unstable/http/FetchHttpClient\"\nimport * as HttpClient from \"effect/unstable/http/HttpClient\"\nimport * as HttpClientError from \"effect/unstable/http/HttpClientError\"\nimport { lookup } from \"node:dns/promises\"\nimport { BlockList, isIP } from \"node:net\"\nimport * as StdError from \"../StdError.ts\"\nimport { parseHttpUrl } from \"./Url.ts\"\n\n/** Resolver seam: all addresses must be public before an unprivileged request.\n * @since 1.0.0\n * @private\n */\nexport const ResolveHost = Context.Reference<\n (hostname: string) => Effect.Effect<ReadonlyArray<string>, unknown>\n>(\"@smthrs/std/HttpNetwork/ResolveHost\", {\n defaultValue: () => (hostname) =>\n Effect.tryPromise(async () => (await lookup(hostname, { all: true })).map((a) => a.address))\n})\n\nconst blocked = new BlockList()\nfor (\n const [address, prefix] of [\n [\"0.0.0.0\", 8],\n [\"10.0.0.0\", 8],\n [\"127.0.0.0\", 8],\n [\"169.254.0.0\", 16],\n [\"172.16.0.0\", 12],\n [\"192.168.0.0\", 16],\n [\"192.0.0.0\", 24],\n [\"100.64.0.0\", 10],\n [\"198.18.0.0\", 15],\n [\"224.0.0.0\", 4],\n [\"240.0.0.0\", 4]\n ] as const\n) blocked.addSubnet(address, prefix, \"ipv4\")\n// Allow global IPv6 and mapped IPv4 only, excluding transition tunnels.\nconst publicV6 = new BlockList()\npublicV6.addSubnet(\"2000::\", 3, \"ipv6\")\npublicV6.addSubnet(\"::ffff:0:0\", 96, \"ipv6\")\nblocked.addSubnet(\"2002::\", 16, \"ipv6\")\nblocked.addSubnet(\"2001::\", 32, \"ipv6\")\n\nconst isPublic = (address: string): boolean => {\n const family = isIP(address)\n if (family === 4) return !blocked.check(address, \"ipv4\")\n return family === 6 && publicV6.check(address, \"ipv6\") && !blocked.check(address, \"ipv6\")\n}\n\nconst failure = (code: StdError.Code, message: string, path: string) => new StdError.StdError({ code, message, path })\n\nconst check = Effect.fn(\"HttpNetwork.check\")(function*(value: string, client: HttpClient.HttpClient) {\n const url = parseHttpUrl(value)\n if (url === undefined) {\n return yield* Effect.fail(failure(\"invalid_input\", \"URL must use http or https without user information\", value))\n }\n if (!supportsDestinationPinning(client)) {\n return yield* Effect.fail(failure(\"unsupported\", \"HTTP host must support destination pinning\", value))\n }\n const hostname = url.hostname.replace(/^\\[|\\]$/g, \"\")\n const local = hostname.replace(/\\.$/, \"\").toLowerCase()\n const literal = isIP(hostname) !== 0\n const localhost = local === \"localhost\" || local.endsWith(\".localhost\")\n const resolve = yield* ResolveHost\n // Refuse localhost before DNS unless the origin is explicitly authorized.\n const privateGrant = Effect.gen(function*() {\n const store = yield* GrantStore\n const capability = yield* Effect.try({\n try: () => Capability.make(\"net:private\", url.origin),\n catch: () => failure(\"invalid_input\", \"Private HTTP origin exceeds the capability resource limit\", value)\n })\n yield* store.check(capability).pipe(\n Effect.mapError(() =>\n failure(\"permission_denied\", \"Private HTTP destination requires a net:private grant\", value)\n )\n )\n })\n if (localhost) yield* privateGrant\n const addresses = literal ? [hostname] : [\n ...yield* resolve(hostname).pipe(\n Effect.mapError(() => failure(\"request_failed\", \"Could not resolve HTTP destination\", value))\n )\n ]\n if (addresses.length === 0 || addresses.some((address) => isIP(address) === 0)) {\n return yield* Effect.fail(failure(\"request_failed\", \"HTTP destination has no valid addresses\", value))\n }\n if (!localhost && !addresses.every(isPublic)) yield* privateGrant\n return Object.freeze({ origin: url.origin, addresses: Object.freeze(addresses) })\n})\n\n/** Decorates the supplied client before following redirects through the guard.\n * The transport must honor manual redirects, as required by the kernel client.\n * @since 1.0.0\n * @private\n */\nexport const guarded = (\n client: HttpClient.HttpClient,\n follow = true\n): HttpClient.HttpClient.With<HttpClientError.HttpClientError, GrantStore> => {\n const checked = HttpClient.transform(\n client,\n (execute, request) =>\n authorizePreflight(\n request,\n check(request.url, client).pipe(\n Effect.mapError((cause) =>\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({ request, cause, description: cause.message })\n })\n ),\n Effect.flatMap((destination) =>\n Effect.updateContext(execute, (context: Context.Context<never>) =>\n Context.add(Context.add(context, Destination, destination), FetchHttpClient.RequestInit, {\n ...Context.getOrUndefined(context, FetchHttpClient.RequestInit),\n redirect: \"manual\"\n }))\n )\n )\n )\n )\n return follow ? HttpClient.followRedirects(checked) : checked\n}\n\n/** Recovers the typed refusal carried through Effect's HTTP error channel.\n * @since 1.0.0\n * @private\n */\nexport const refusal = (error: unknown): StdError.StdError | undefined => {\n if (!(error instanceof HttpClientError.HttpClientError) || error.reason._tag !== \"TransportError\") return undefined\n if (error.reason.cause instanceof StdError.StdError) return error.reason.cause\n if (Option.isSome(fromHttpClientError(error))) {\n return failure(\n \"permission_denied\",\n error.reason.description ?? \"HTTP permission was refused\",\n error.reason.request.url\n )\n }\n return undefined\n}\n"]}
|
|
1
|
+
{"version":3,"file":"HttpNetwork.js","sourceRoot":"","sources":["../../../src/internal/HttpNetwork.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,UAAU,MAAM,+BAA+B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAChD,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,eAAe,MAAM,6BAA6B,CAAA;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA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C,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAC7B,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,OAA+B,EAAE,EAAE,CAChE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE,eAAe,CAAC,WAAW,EAAE;QACvF,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,CAAC,WAAW,CAAC;QAC/D,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC,CACN,CACF,CACF,CACJ,CAAA;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AAC/D,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAiC,EAAE;IACvE,IAAI,CAAC,CAAC,KAAK,YAAY,eAAe,CAAC,eAAe,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,SAAS,CAAA;IACnH,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,YAAY,QAAQ,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAA;IAC9E,IAAI,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC9C,OAAO,OAAO,CACZ,mBAAmB,EACnB,KAAK,CAAC,MAAM,CAAC,WAAW,IAAI,6BAA6B,EACzD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CACzB,CAAA;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA","sourcesContent":["/**\n * Destination policy shared by the web tools, including every redirect hop.\n *\n * @since 1.0.0\n */\n\nimport * as Capability from \"@smthrs/capability/Capability\"\nimport { GrantStore } from \"@smthrs/kernel/GrantStore\"\nimport {\n authorizePreflight,\n Destination,\n fromHttpClientError,\n supportsDestinationPinning\n} from \"@smthrs/kernel/HttpClient\"\nimport { Context, Effect, Option } from \"effect\"\nimport * as FetchHttpClient from \"effect/http/FetchHttpClient\"\nimport * as HttpClient from \"effect/http/HttpClient\"\nimport * as HttpClientError from \"effect/http/HttpClientError\"\nimport { lookup } from \"node:dns/promises\"\nimport { BlockList, isIP } from \"node:net\"\nimport * as StdError from \"../StdError.ts\"\nimport { parseHttpUrl } from \"./Url.ts\"\n\n/** Resolver seam: all addresses must be public before an unprivileged request.\n * @since 1.0.0\n * @private\n */\nexport const ResolveHost = Context.Reference<\n (hostname: string) => Effect.Effect<ReadonlyArray<string>, unknown>\n>(\"@smthrs/std/HttpNetwork/ResolveHost\", {\n defaultValue: () => (hostname) =>\n Effect.tryPromise(async () => (await lookup(hostname, { all: true })).map((a) => a.address))\n})\n\nconst blocked = new BlockList()\nfor (\n const [address, prefix] of [\n [\"0.0.0.0\", 8],\n [\"10.0.0.0\", 8],\n [\"127.0.0.0\", 8],\n [\"169.254.0.0\", 16],\n [\"172.16.0.0\", 12],\n [\"192.168.0.0\", 16],\n [\"192.0.0.0\", 24],\n [\"100.64.0.0\", 10],\n [\"198.18.0.0\", 15],\n [\"224.0.0.0\", 4],\n [\"240.0.0.0\", 4]\n ] as const\n) blocked.addSubnet(address, prefix, \"ipv4\")\n// Allow global IPv6 and mapped IPv4 only, excluding transition tunnels.\nconst publicV6 = new BlockList()\npublicV6.addSubnet(\"2000::\", 3, \"ipv6\")\npublicV6.addSubnet(\"::ffff:0:0\", 96, \"ipv6\")\nblocked.addSubnet(\"2002::\", 16, \"ipv6\")\nblocked.addSubnet(\"2001::\", 32, \"ipv6\")\n\nconst isPublic = (address: string): boolean => {\n const family = isIP(address)\n if (family === 4) return !blocked.check(address, \"ipv4\")\n return family === 6 && publicV6.check(address, \"ipv6\") && !blocked.check(address, \"ipv6\")\n}\n\nconst failure = (code: StdError.Code, message: string, path: string) => new StdError.StdError({ code, message, path })\n\nconst check = Effect.fn(\"HttpNetwork.check\")(function*(value: string, client: HttpClient.HttpClient) {\n const url = parseHttpUrl(value)\n if (url === undefined) {\n return yield* Effect.fail(failure(\"invalid_input\", \"URL must use http or https without user information\", value))\n }\n if (!supportsDestinationPinning(client)) {\n return yield* Effect.fail(failure(\"unsupported\", \"HTTP host must support destination pinning\", value))\n }\n const hostname = url.hostname.replace(/^\\[|\\]$/g, \"\")\n const local = hostname.replace(/\\.$/, \"\").toLowerCase()\n const literal = isIP(hostname) !== 0\n const localhost = local === \"localhost\" || local.endsWith(\".localhost\")\n const resolve = yield* ResolveHost\n // Refuse localhost before DNS unless the origin is explicitly authorized.\n const privateGrant = Effect.gen(function*() {\n const store = yield* GrantStore\n const capability = yield* Effect.try({\n try: () => Capability.make(\"net:private\", url.origin),\n catch: () => failure(\"invalid_input\", \"Private HTTP origin exceeds the capability resource limit\", value)\n })\n yield* store.check(capability).pipe(\n Effect.mapError(() =>\n failure(\"permission_denied\", \"Private HTTP destination requires a net:private grant\", value)\n )\n )\n })\n if (localhost) yield* privateGrant\n const addresses = literal ? [hostname] : [\n ...yield* resolve(hostname).pipe(\n Effect.mapError(() => failure(\"request_failed\", \"Could not resolve HTTP destination\", value))\n )\n ]\n if (addresses.length === 0 || addresses.some((address) => isIP(address) === 0)) {\n return yield* Effect.fail(failure(\"request_failed\", \"HTTP destination has no valid addresses\", value))\n }\n if (!localhost && !addresses.every(isPublic)) yield* privateGrant\n return Object.freeze({ origin: url.origin, addresses: Object.freeze(addresses) })\n})\n\n/** Decorates the supplied client before following redirects through the guard.\n * The transport must honor manual redirects, as required by the kernel client.\n * @since 1.0.0\n * @private\n */\nexport const guarded = (\n client: HttpClient.HttpClient,\n follow = true\n): HttpClient.HttpClient.With<HttpClientError.HttpClientError, GrantStore> => {\n const checked = HttpClient.transform(\n client,\n (execute, request) =>\n authorizePreflight(\n request,\n check(request.url, client).pipe(\n Effect.mapError((cause) =>\n new HttpClientError.HttpClientError({\n reason: new HttpClientError.TransportError({ request, cause, description: cause.message })\n })\n ),\n Effect.flatMap((destination) =>\n Effect.updateContext(execute, (context: Context.Context<never>) =>\n Context.add(Context.add(context, Destination, destination), FetchHttpClient.RequestInit, {\n ...Context.getOrUndefined(context, FetchHttpClient.RequestInit),\n redirect: \"manual\"\n }))\n )\n )\n )\n )\n return follow ? HttpClient.followRedirects(checked) : checked\n}\n\n/** Recovers the typed refusal carried through Effect's HTTP error channel.\n * @since 1.0.0\n * @private\n */\nexport const refusal = (error: unknown): StdError.StdError | undefined => {\n if (!(error instanceof HttpClientError.HttpClientError) || error.reason._tag !== \"TransportError\") return undefined\n if (error.reason.cause instanceof StdError.StdError) return error.reason.cause\n if (Option.isSome(fromHttpClientError(error))) {\n return failure(\n \"permission_denied\",\n error.reason.description ?? \"HTTP permission was refused\",\n error.reason.request.url\n )\n }\n return undefined\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;;;;;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AM,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"}
|
|
@@ -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;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AG,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;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,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AAE9D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,IAAY,EACZ,QAAgB,EAChB,OAA2C,EAC/B,EAAE;IACd,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,IAAI,KAAK,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC;QACjC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,UAAU,EAAE,YAAY,EAAE,CAAC,EAAE,CAAA;IACjF,CAAC;IACD,IAAI,KAAK,GAAG,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,GAAG,QAAQ,CAAA;IACrE,IAAI,GAAG,GAA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,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 * 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/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 |
|
|
@@ -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
|
|
@@ -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
|
@@ -63,7 +63,7 @@ through Effect's context, so a composition adds a platform package that provides
|
|
|
63
63
|
them:
|
|
64
64
|
|
|
65
65
|
```bash
|
|
66
|
-
pnpm add @effect/platform-node
|
|
66
|
+
pnpm add @effect/platform-node @effect/platform-node-shared
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
`NodeServices.layer` from `@effect/platform-node` provides `FileSystem`, `Path`,
|