@earendil-works/pi-durable 0.99.1 → 0.99.2
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 +435 -46
- package/dist/entries.d.ts +20 -2
- package/dist/entries.d.ts.map +1 -1
- package/dist/entries.js +14 -1
- package/dist/entries.js.map +1 -1
- package/dist/env/index.d.ts +13 -38
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js +2 -0
- package/dist/env/index.js.map +1 -1
- package/dist/env/node.d.ts.map +1 -1
- package/dist/env/node.js +51 -58
- package/dist/env/node.js.map +1 -1
- package/dist/harness/compaction.d.ts +56 -0
- package/dist/harness/compaction.d.ts.map +1 -0
- package/dist/harness/compaction.js +385 -0
- package/dist/harness/compaction.js.map +1 -0
- package/dist/harness/config.d.ts +10 -1
- package/dist/harness/config.d.ts.map +1 -1
- package/dist/harness/config.js +6 -0
- package/dist/harness/config.js.map +1 -1
- package/dist/harness/context.d.ts +8 -0
- package/dist/harness/context.d.ts.map +1 -1
- package/dist/harness/context.js +32 -21
- package/dist/harness/context.js.map +1 -1
- package/dist/harness/events.d.ts +166 -0
- package/dist/harness/events.d.ts.map +1 -0
- package/dist/harness/events.js +319 -0
- package/dist/harness/events.js.map +1 -0
- package/dist/harness/generation.d.ts +37 -6
- package/dist/harness/generation.d.ts.map +1 -1
- package/dist/harness/generation.js +350 -72
- package/dist/harness/generation.js.map +1 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/harness.js +124 -3
- package/dist/harness/harness.js.map +1 -1
- package/dist/harness/inbox.d.ts +57 -0
- package/dist/harness/inbox.d.ts.map +1 -0
- package/dist/harness/inbox.js +99 -0
- package/dist/harness/inbox.js.map +1 -0
- package/dist/harness/json.d.ts +10 -0
- package/dist/harness/json.d.ts.map +1 -0
- package/dist/harness/json.js +33 -0
- package/dist/harness/json.js.map +1 -0
- package/dist/harness/live.d.ts +66 -7
- package/dist/harness/live.d.ts.map +1 -1
- package/dist/harness/live.js +71 -7
- package/dist/harness/live.js.map +1 -1
- package/dist/harness/output.d.ts +62 -0
- package/dist/harness/output.d.ts.map +1 -0
- package/dist/harness/output.js +261 -0
- package/dist/harness/output.js.map +1 -0
- package/dist/harness/prompt.d.ts +10 -5
- package/dist/harness/prompt.d.ts.map +1 -1
- package/dist/harness/prompt.js +66 -13
- package/dist/harness/prompt.js.map +1 -1
- package/dist/harness/registry.d.ts.map +1 -1
- package/dist/harness/registry.js +11 -2
- package/dist/harness/registry.js.map +1 -1
- package/dist/harness/scheduler.d.ts +37 -12
- package/dist/harness/scheduler.d.ts.map +1 -1
- package/dist/harness/scheduler.js +632 -72
- package/dist/harness/scheduler.js.map +1 -1
- package/dist/harness/submissions.d.ts +12 -7
- package/dist/harness/submissions.d.ts.map +1 -1
- package/dist/harness/submissions.js +72 -33
- package/dist/harness/submissions.js.map +1 -1
- package/dist/harness/tool.d.ts +36 -0
- package/dist/harness/tool.d.ts.map +1 -0
- package/dist/harness/tool.js +412 -0
- package/dist/harness/tool.js.map +1 -0
- package/dist/harness/types.d.ts +185 -11
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/usage.d.ts +18 -0
- package/dist/harness/usage.d.ts.map +1 -0
- package/dist/harness/usage.js +57 -0
- package/dist/harness/usage.js.map +1 -0
- package/dist/harness/view.d.ts +43 -0
- package/dist/harness/view.d.ts.map +1 -0
- package/dist/harness/view.js +194 -0
- package/dist/harness/view.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/session/observation.d.ts +18 -11
- package/dist/session/observation.d.ts.map +1 -1
- package/dist/session/observation.js +24 -13
- package/dist/session/observation.js.map +1 -1
- package/dist/session/session.d.ts +10 -1
- package/dist/session/session.d.ts.map +1 -1
- package/dist/session/session.js +18 -4
- package/dist/session/session.js.map +1 -1
- package/dist/session/transaction.d.ts +10 -1
- package/dist/session/transaction.d.ts.map +1 -1
- package/dist/session/transaction.js +83 -27
- package/dist/session/transaction.js.map +1 -1
- package/dist/storage/jsonl/storage.d.ts +22 -2
- package/dist/storage/jsonl/storage.d.ts.map +1 -1
- package/dist/storage/jsonl/storage.js +1 -1
- package/dist/storage/jsonl/storage.js.map +1 -1
- package/dist/storage/memory.js +1 -1
- package/dist/storage/memory.js.map +1 -1
- package/dist/storage/sqlite/migrations.js +1 -1
- package/dist/storage/sqlite/migrations.js.map +1 -1
- package/dist/testing/storage-benchmark.d.ts.map +1 -1
- package/dist/testing/storage-benchmark.js +0 -1
- package/dist/testing/storage-benchmark.js.map +1 -1
- package/dist/testing/storage-conformance.d.ts.map +1 -1
- package/dist/testing/storage-conformance.js +34 -2
- package/dist/testing/storage-conformance.js.map +1 -1
- package/dist/tools/bash.d.ts +28 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +69 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +89 -0
- package/dist/tools/edit-diff.d.ts.map +1 -0
- package/dist/tools/edit-diff.js +386 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit.d.ts +18 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +116 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/env.d.ts +5 -0
- package/dist/tools/env.d.ts.map +1 -0
- package/dist/tools/env.js +7 -0
- package/dist/tools/env.js.map +1 -0
- package/dist/tools/file-mutation-queue.d.ts +5 -0
- package/dist/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/tools/file-mutation-queue.js +46 -0
- package/dist/tools/file-mutation-queue.js.map +1 -0
- package/dist/tools/image.d.ts +2 -0
- package/dist/tools/image.d.ts.map +1 -0
- package/dist/tools/image.js +92 -0
- package/dist/tools/image.js.map +1 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +5 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/path-utils.d.ts +5 -0
- package/dist/tools/path-utils.d.ts.map +1 -0
- package/dist/tools/path-utils.js +26 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/read.d.ts +17 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +100 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/write.d.ts +10 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +30 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/{env/utils/truncate.d.ts → truncate.d.ts} +1 -17
- package/dist/truncate.d.ts.map +1 -0
- package/dist/truncate.js +146 -0
- package/dist/truncate.js.map +1 -0
- package/dist/types.d.ts +86 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/pico-v5-handoff.md +366 -86
- package/docs/pico-v5.md +1373 -283
- package/package.json +11 -3
- package/dist/env/utils/adaptive-publisher.d.ts +0 -24
- package/dist/env/utils/adaptive-publisher.d.ts.map +0 -1
- package/dist/env/utils/adaptive-publisher.js +0 -79
- package/dist/env/utils/adaptive-publisher.js.map +0 -1
- package/dist/env/utils/output-capture.d.ts +0 -31
- package/dist/env/utils/output-capture.d.ts.map +0 -1
- package/dist/env/utils/output-capture.js +0 -238
- package/dist/env/utils/output-capture.js.map +0 -1
- package/dist/env/utils/truncate.d.ts.map +0 -1
- package/dist/env/utils/truncate.js +0 -294
- package/dist/env/utils/truncate.js.map +0 -1
package/dist/env/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import type { TruncationResult } from "./utils/truncate.ts";
|
|
3
2
|
/** Result of a fallible operation. Expected failures are returned instead of thrown. */
|
|
4
3
|
export type Result<TValue, TError> = {
|
|
5
4
|
ok: true;
|
|
@@ -23,6 +22,8 @@ export declare class FileError extends Error {
|
|
|
23
22
|
export type ExecutionErrorCode = "aborted" | "timeout" | "shell_unavailable" | "spawn_error" | "callback_error" | "unknown";
|
|
24
23
|
export declare class ExecutionError extends Error {
|
|
25
24
|
code: ExecutionErrorCode;
|
|
25
|
+
/** Spill file of a command that timed out or was aborted after its output crossed the spill thresholds. */
|
|
26
|
+
spillPath?: string;
|
|
26
27
|
constructor(code: ExecutionErrorCode, message: string, cause?: Error);
|
|
27
28
|
}
|
|
28
29
|
export interface FileInfo {
|
|
@@ -76,51 +77,25 @@ export interface FileSystem {
|
|
|
76
77
|
} | undefined, context: Context): Promise<Result<string, FileError>>;
|
|
77
78
|
cleanup(context: Context): Promise<void>;
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
export interface
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
export interface ShellOutputCaptureOptions {
|
|
86
|
-
limits: ShellOutputLimits;
|
|
87
|
-
spill?: boolean;
|
|
88
|
-
}
|
|
89
|
-
export type ShellOutputTruncation = Omit<TruncationResult, "content">;
|
|
90
|
-
export interface ShellOutputMetadata {
|
|
91
|
-
truncation: ShellOutputTruncation;
|
|
92
|
-
spillPath?: string;
|
|
93
|
-
lastLineBytes?: number;
|
|
80
|
+
/** Spill the complete output to a temporary file once it exceeds either threshold. */
|
|
81
|
+
export interface ShellSpillOptions {
|
|
82
|
+
afterBytes: number;
|
|
83
|
+
/** Complete or partial lines. */
|
|
84
|
+
afterLines: number;
|
|
94
85
|
}
|
|
95
|
-
export interface
|
|
96
|
-
text: string;
|
|
97
|
-
}
|
|
98
|
-
export type ShellOutputUpdate = {
|
|
99
|
-
kind: "replace";
|
|
100
|
-
output: ShellOutputView;
|
|
101
|
-
} | {
|
|
102
|
-
kind: "append";
|
|
103
|
-
text: string;
|
|
104
|
-
metadata: ShellOutputMetadata;
|
|
105
|
-
} | {
|
|
106
|
-
kind: "slide";
|
|
107
|
-
drop: number;
|
|
108
|
-
text: string;
|
|
109
|
-
metadata: ShellOutputMetadata;
|
|
110
|
-
} | {
|
|
111
|
-
kind: "metadata";
|
|
112
|
-
metadata: ShellOutputMetadata;
|
|
113
|
-
};
|
|
114
|
-
export interface ShellExecResult extends ShellOutputMetadata {
|
|
86
|
+
export interface ShellExecResult {
|
|
115
87
|
exitCode: number;
|
|
88
|
+
/** Temporary file holding the complete raw output, when the spill thresholds were exceeded. */
|
|
89
|
+
spillPath?: string;
|
|
116
90
|
}
|
|
117
91
|
export interface ShellExecOptions {
|
|
118
92
|
cwd?: string;
|
|
119
93
|
env?: Record<string, string>;
|
|
120
94
|
inheritEnv?: boolean;
|
|
121
95
|
timeout?: number;
|
|
122
|
-
|
|
123
|
-
|
|
96
|
+
/** Every decoded chunk of combined stdout and stderr as it arrives: raw, unbounded, and unthrottled. */
|
|
97
|
+
onOutput?: (text: string, context: Context) => void;
|
|
98
|
+
spill?: ShellSpillOptions;
|
|
124
99
|
}
|
|
125
100
|
export interface Shell {
|
|
126
101
|
exec(command: string, options: ShellExecOptions | undefined, context: Context): Promise<Result<ShellExecResult, ExecutionError>>;
|
package/dist/env/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,wFAAwF;AACxF,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG,wBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAA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,QAAQ,EAAE,MAAM,CAAC;IACjB,+FAA+F;IAC/F,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wGAAwG;IACxG,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,WAAW,KAAK;IACrB,IAAI,CACH,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GAAG,SAAS,EACrC,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,YAAa,SAAQ,UAAU,EAAE,KAAK;CAAG"}
|
package/dist/env/index.js
CHANGED
|
@@ -36,6 +36,8 @@ export class FileError extends Error {
|
|
|
36
36
|
}
|
|
37
37
|
export class ExecutionError extends Error {
|
|
38
38
|
code;
|
|
39
|
+
/** Spill file of a command that timed out or was aborted after its output crossed the spill thresholds. */
|
|
40
|
+
spillPath;
|
|
39
41
|
constructor(code, message, cause) {
|
|
40
42
|
super(message, cause === undefined ? undefined : { cause });
|
|
41
43
|
this.name = "ExecutionError";
|
package/dist/env/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAK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GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAUD,MAAM,OAAO,cAAe,SAAQ,KAAK;IACjC,IAAI,CAAqB;IAChC,2GAA2G;IACpG,SAAS,CAAU;IAE1B,YAAY,IAAwB,EAAE,OAAe,EAAE,KAAa;QACnE,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD","sourcesContent":["import type { Context } from \"@earendil-works/chord\";\n\n/** Result of a fallible operation. Expected failures are returned instead of thrown. */\nexport type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport function ok<TValue, TError>(value: TValue): Result<TValue, TError> {\n\treturn { ok: true, value };\n}\n\nexport function err<TValue, TError>(error: TError): Result<TValue, TError> {\n\treturn { ok: false, error };\n}\n\nexport function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue {\n\tif (!result.ok) throw result.error;\n\treturn result.value;\n}\n\nexport function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined {\n\treturn result.ok ? result.value : undefined;\n}\n\nexport function toError(error: unknown): Error {\n\tif (error instanceof Error) return error;\n\tif (typeof error === \"string\") return new Error(error);\n\ttry {\n\t\treturn new Error(JSON.stringify(error));\n\t} catch {\n\t\treturn new Error(String(error));\n\t}\n}\n\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\nexport type FileErrorCode =\n\t| \"aborted\"\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\nexport class FileError extends Error {\n\tpublic code: FileErrorCode;\n\tpublic path?: string;\n\n\tconstructor(code: FileErrorCode, message: string, path?: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"FileError\";\n\t\tthis.code = code;\n\t\tthis.path = path;\n\t}\n}\n\nexport type ExecutionErrorCode =\n\t| \"aborted\"\n\t| \"timeout\"\n\t| \"shell_unavailable\"\n\t| \"spawn_error\"\n\t| \"callback_error\"\n\t| \"unknown\";\n\nexport class ExecutionError extends Error {\n\tpublic code: ExecutionErrorCode;\n\t/** Spill file of a command that timed out or was aborted after its output crossed the spill thresholds. */\n\tpublic spillPath?: string;\n\n\tconstructor(code: ExecutionErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"ExecutionError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport interface FileInfo {\n\tname: string;\n\tpath: string;\n\tkind: FileKind;\n\tsize: number;\n\tmtimeMs: number;\n}\n\nexport interface TextLine {\n\ttext: string;\n\tterminated: boolean;\n}\n\nexport interface TextLineReader {\n\treadLine(context: Context): Promise<Result<TextLine | undefined, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** Portable filesystem capability. Operations return failures rather than throwing. */\nexport interface FileSystem {\n\tcwd: string;\n\tabsolutePath(path: string, context: Context): Promise<Result<string, FileError>>;\n\tjoinPath(parts: string[], context: Context): Promise<Result<string, FileError>>;\n\treadTextFile(path: string, context: Context): Promise<Result<string, FileError>>;\n\topenTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;\n\treadTextLines(\n\t\tpath: string,\n\t\toptions: { maxLines?: number } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string[], FileError>>;\n\treadBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;\n\twriteFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\tappendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\t/** Truncate or extend a file to exactly `size` bytes. */\n\ttruncateFile(path: string, size: number, context: Context): Promise<Result<void, FileError>>;\n\t/** Flush file contents and metadata needed to retrieve them from an open file handle. */\n\tflushFile(path: string, context: Context): Promise<Result<void, FileError>>;\n\trenameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;\n\tfileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;\n\tlistDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;\n\tcanonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;\n\texists(path: string, context: Context): Promise<Result<boolean, FileError>>;\n\tcreateDir(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tremove(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean; force?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tcreateTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;\n\tcreateTempFile(\n\t\toptions: { prefix?: string; suffix?: string } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string, FileError>>;\n\tcleanup(context: Context): Promise<void>;\n}\n\n/** Spill the complete output to a temporary file once it exceeds either threshold. */\nexport interface ShellSpillOptions {\n\tafterBytes: number;\n\t/** Complete or partial lines. */\n\tafterLines: number;\n}\n\nexport interface ShellExecResult {\n\texitCode: number;\n\t/** Temporary file holding the complete raw output, when the spill thresholds were exceeded. */\n\tspillPath?: string;\n}\n\nexport interface ShellExecOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tinheritEnv?: boolean;\n\ttimeout?: number;\n\t/** Every decoded chunk of combined stdout and stderr as it arrives: raw, unbounded, and unthrottled. */\n\tonOutput?: (text: string, context: Context) => void;\n\tspill?: ShellSpillOptions;\n}\n\nexport interface Shell {\n\texec(\n\t\tcommand: string,\n\t\toptions: ShellExecOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<ShellExecResult, ExecutionError>>;\n\tcleanup(context: Context): Promise<void>;\n}\n\nexport interface ExecutionEnv extends FileSystem, Shell {}\n"]}
|
package/dist/env/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/env/node.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACN,KAAK,YAAY,EACjB,cAAc,EAEd,SAAS,EACT,KAAK,QAAQ,EAGb,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAEpB,KAAK,cAAc,EAEnB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/env/node.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACN,KAAK,YAAY,EACjB,cAAc,EAEd,SAAS,EACT,KAAK,QAAQ,EAGb,KAAK,MAAM,EACX,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAEpB,KAAK,cAAc,EAEnB,MAAM,YAAY,CAAC;AAiZpB,qBAAa,gBAAiB,YAAW,YAAY;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,CAAoB;IACrC,OAAO,CAAC,eAAe,CAAqB;IAE5C,YAAY,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;KAAE,EAIrF;IAEK,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAEtF;IAEK,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,OAAO,GAA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GACd,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAUlC;IAEK,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CASpG;IAEK,cAAc,CACnB,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,EACzD,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAUpC;IAEK,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9C;CACD"}
|
package/dist/env/node.js
CHANGED
|
@@ -6,11 +6,10 @@ import { homedir, constants as osConstants, tmpdir } from "node:os";
|
|
|
6
6
|
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { ExecutionError, err, FileError, ok, toError, } from "./index.js";
|
|
9
|
-
import { OutputCapture } from "./utils/output-capture.js";
|
|
10
9
|
const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
11
10
|
const MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;
|
|
12
11
|
const EXIT_STDIO_GRACE_MS = 100;
|
|
13
|
-
const SPILL_HIGH_WATER_MARK =
|
|
12
|
+
const SPILL_HIGH_WATER_MARK = 1024 * 1024;
|
|
14
13
|
function resolveTimeoutMs(timeout) {
|
|
15
14
|
if (timeout === undefined)
|
|
16
15
|
return ok(undefined);
|
|
@@ -437,18 +436,23 @@ export class NodeExecutionEnv {
|
|
|
437
436
|
callbackError = new ExecutionError("callback_error", cause.message, cause);
|
|
438
437
|
onAbort();
|
|
439
438
|
};
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
439
|
+
// One decoder per stream, so a character split across chunks of one stream survives interleaving.
|
|
440
|
+
const stdoutDecoder = new TextDecoder();
|
|
441
|
+
const stderrDecoder = new TextDecoder();
|
|
442
|
+
// No output reaches the caller after exec() settled, for example from a descendant holding stdio open.
|
|
443
|
+
const emit = (text) => {
|
|
444
|
+
if (settled || text === "" || options?.onOutput === undefined || callbackError !== undefined)
|
|
445
|
+
return;
|
|
446
|
+
try {
|
|
447
|
+
options.onOutput(text, context);
|
|
448
|
+
}
|
|
449
|
+
catch (error) {
|
|
450
|
+
failCallback(error);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
// Output seen before the spill starts: counted against the thresholds and kept for the spill's prefix.
|
|
454
|
+
let seenBytes = 0;
|
|
455
|
+
let seenNewlines = 0;
|
|
452
456
|
const settle = (result) => {
|
|
453
457
|
if (settled)
|
|
454
458
|
return;
|
|
@@ -459,7 +463,6 @@ export class NodeExecutionEnv {
|
|
|
459
463
|
signal.removeEventListener("abort", onAbort);
|
|
460
464
|
if (child?.pid)
|
|
461
465
|
this.activeChildPids.delete(child.pid);
|
|
462
|
-
capture.dispose();
|
|
463
466
|
resolvePromise(result);
|
|
464
467
|
};
|
|
465
468
|
const pauseOutput = () => {
|
|
@@ -506,7 +509,6 @@ export class NodeExecutionEnv {
|
|
|
506
509
|
if (!created.ok)
|
|
507
510
|
throw created.error;
|
|
508
511
|
spillPath = created.value;
|
|
509
|
-
capture.setSpillPath(spillPath);
|
|
510
512
|
spillStream = createWriteStream(spillPath, { flags: "a", highWaterMark: SPILL_HIGH_WATER_MARK });
|
|
511
513
|
spillStream.on("error", failSpill);
|
|
512
514
|
for (const queued of spillQueue)
|
|
@@ -561,69 +563,60 @@ export class NodeExecutionEnv {
|
|
|
561
563
|
else
|
|
562
564
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
563
565
|
}
|
|
564
|
-
const feed = (chunk) => {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
}
|
|
573
|
-
else if (capture.truncated) {
|
|
574
|
-
for (const prefix of spillPrefix)
|
|
575
|
-
startSpill(prefix);
|
|
576
|
-
spillPrefix.length = 0;
|
|
577
|
-
startSpill(chunk);
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
spillPrefix.push(chunk);
|
|
581
|
-
}
|
|
566
|
+
const feed = (decoder) => (chunk) => {
|
|
567
|
+
emit(decoder.decode(chunk, { stream: true }));
|
|
568
|
+
const spill = options?.spill;
|
|
569
|
+
if (spill === undefined || chunk.length === 0)
|
|
570
|
+
return;
|
|
571
|
+
if (spillStart !== undefined) {
|
|
572
|
+
startSpill(chunk);
|
|
573
|
+
return;
|
|
582
574
|
}
|
|
583
|
-
|
|
584
|
-
|
|
575
|
+
seenBytes += chunk.length;
|
|
576
|
+
for (let index = chunk.indexOf(0x0a); index !== -1; index = chunk.indexOf(0x0a, index + 1))
|
|
577
|
+
seenNewlines++;
|
|
578
|
+
const lines = seenNewlines + (chunk[chunk.length - 1] === 0x0a ? 0 : 1);
|
|
579
|
+
if (seenBytes <= spill.afterBytes && lines <= spill.afterLines) {
|
|
580
|
+
spillPrefix.push(chunk);
|
|
581
|
+
return;
|
|
585
582
|
}
|
|
583
|
+
for (const prefix of spillPrefix)
|
|
584
|
+
startSpill(prefix);
|
|
585
|
+
spillPrefix.length = 0;
|
|
586
|
+
startSpill(chunk);
|
|
586
587
|
};
|
|
587
|
-
child.stdout?.on("data", feed);
|
|
588
|
-
child.stderr?.on("data", feed);
|
|
588
|
+
child.stdout?.on("data", feed(stdoutDecoder));
|
|
589
|
+
child.stderr?.on("data", feed(stderrDecoder));
|
|
589
590
|
void waitForChildProcess(child, () => spillError === undefined &&
|
|
590
591
|
spillStart !== undefined &&
|
|
591
592
|
(spillStream === undefined || spillBackpressured)).then(async ({ code, signal: exitSignal }) => {
|
|
592
593
|
await finishSpill();
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
capture.flush();
|
|
596
|
-
}
|
|
597
|
-
catch (error) {
|
|
598
|
-
failCallback(error);
|
|
599
|
-
}
|
|
594
|
+
emit(stdoutDecoder.decode());
|
|
595
|
+
emit(stderrDecoder.decode());
|
|
600
596
|
if (callbackError) {
|
|
601
597
|
settle(err(callbackError));
|
|
602
598
|
return;
|
|
603
599
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
600
|
+
const interrupted = timedOut
|
|
601
|
+
? new ExecutionError("timeout", `timeout:${options?.timeout}`)
|
|
602
|
+
: signal?.aborted
|
|
603
|
+
? new ExecutionError("aborted", "aborted")
|
|
604
|
+
: undefined;
|
|
605
|
+
if (interrupted !== undefined) {
|
|
606
|
+
if (spillPath !== undefined)
|
|
607
|
+
interrupted.spillPath = spillPath;
|
|
608
|
+
settle(err(interrupted));
|
|
610
609
|
return;
|
|
611
610
|
}
|
|
612
611
|
if (spillError) {
|
|
613
612
|
settle(err(spillError));
|
|
614
613
|
return;
|
|
615
614
|
}
|
|
616
|
-
const output = capture.snapshot();
|
|
617
615
|
// A process killed by a signal (e.g. OOM killer) has no exit code; map it
|
|
618
616
|
// to the conventional 128 + signal number so callers do not mistake it
|
|
619
617
|
// for a successful exit.
|
|
620
618
|
const exitCode = code ?? (exitSignal ? 128 + (osConstants.signals[exitSignal] ?? 0) : 1);
|
|
621
|
-
settle(ok({
|
|
622
|
-
exitCode,
|
|
623
|
-
truncation: output.truncation,
|
|
624
|
-
...(output.spillPath === undefined ? {} : { spillPath: output.spillPath }),
|
|
625
|
-
...(output.lastLineBytes === undefined ? {} : { lastLineBytes: output.lastLineBytes }),
|
|
626
|
-
}));
|
|
619
|
+
settle(ok({ exitCode, ...(spillPath === undefined ? {} : { spillPath }) }));
|
|
627
620
|
}, (error) => settle(err(new ExecutionError("spawn_error", error.message, error))));
|
|
628
621
|
});
|
|
629
622
|
}
|