@howaboua/pi-durable-notebook 0.0.0-stage → 0.10.0
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/LICENSE +21 -0
- package/NOTICE +54 -0
- package/README.md +105 -2
- package/dist/activation.js +11433 -0
- package/dist/execution/src/cell-contract.d.ts +49 -0
- package/dist/execution/src/cell-observation.d.ts +7 -0
- package/dist/execution/src/cell-progress.d.ts +4 -0
- package/dist/execution/src/cell-task.d.ts +17 -0
- package/dist/execution/src/cell-tools.d.ts +8 -0
- package/dist/execution/src/cells.d.ts +14 -0
- package/dist/execution/src/command-backend.d.ts +22 -0
- package/dist/execution/src/controls.d.ts +3 -0
- package/dist/execution/src/custom-command-config.d.ts +21 -0
- package/dist/execution/src/custom-commands.d.ts +62 -0
- package/dist/execution/src/exec-source.d.ts +21 -0
- package/dist/execution/src/forwarded-tools.d.ts +21 -0
- package/dist/execution/src/forwarding-hook.d.ts +6 -0
- package/dist/execution/src/forwarding.d.ts +15 -0
- package/dist/execution/src/history.d.ts +14 -0
- package/dist/execution/src/index.d.ts +6 -0
- package/dist/execution/src/invocation-state.d.ts +26 -0
- package/dist/execution/src/invocation.d.ts +35 -0
- package/dist/execution/src/native-tools.d.ts +11 -0
- package/dist/execution/src/nested-call.d.ts +26 -0
- package/dist/execution/src/nested-result.d.ts +8 -0
- package/dist/execution/src/nested.d.ts +3 -0
- package/dist/execution/src/output.d.ts +48 -0
- package/dist/execution/src/presentation.d.ts +59 -0
- package/dist/execution/src/progress.d.ts +23 -0
- package/dist/execution/src/projection.d.ts +5 -0
- package/dist/execution/src/shell/backend.d.ts +28 -0
- package/dist/execution/src/shell/format.d.ts +2 -0
- package/dist/execution/src/shell/node-backend.d.ts +9 -0
- package/dist/execution/src/shell/output.d.ts +19 -0
- package/dist/execution/src/shell/process-session.d.ts +50 -0
- package/dist/execution/src/shell/results.d.ts +14 -0
- package/dist/execution/src/shell/session-manager.d.ts +46 -0
- package/dist/execution/src/shell/session-store.d.ts +53 -0
- package/dist/execution/src/shell/shell-args.d.ts +4 -0
- package/dist/execution/src/shell/shell.d.ts +14 -0
- package/dist/execution/src/shell/wait.d.ts +7 -0
- package/dist/execution/src/shell.d.ts +14 -0
- package/dist/execution/src/tool-contract.d.ts +34 -0
- package/dist/execution/src/tool-origin.d.ts +11 -0
- package/dist/execution/src/tool-source.d.ts +6 -0
- package/dist/execution/src/tool-value.d.ts +3 -0
- package/dist/execution/src/wait-session.d.ts +6 -0
- package/dist/history.js +315 -0
- package/dist/index.js +11718 -0
- package/dist/notebook/src/activation.d.ts +5 -0
- package/dist/notebook/src/binding-metadata-source.d.ts +2 -0
- package/dist/notebook/src/bridge-protocol.d.ts +29 -0
- package/dist/notebook/src/bridge-server.d.ts +20 -0
- package/dist/notebook/src/cell.d.ts +34 -0
- package/dist/notebook/src/checkpoint-activity.d.ts +7 -0
- package/dist/notebook/src/checkpoint-format.d.ts +32 -0
- package/dist/notebook/src/checkpoint-manager.d.ts +41 -0
- package/dist/notebook/src/checkpoint-runtime.d.ts +18 -0
- package/dist/notebook/src/checkpoint-store.d.ts +8 -0
- package/dist/notebook/src/checkpoint.d.ts +15 -0
- package/dist/notebook/src/client.d.ts +18 -0
- package/dist/notebook/src/command-output.d.ts +1 -0
- package/dist/notebook/src/control-contract.d.ts +5 -0
- package/dist/notebook/src/deno-archive.d.ts +2 -0
- package/dist/notebook/src/deno-assets.d.ts +11 -0
- package/dist/notebook/src/deno-binary.d.ts +6 -0
- package/dist/notebook/src/deno-syntax-diagnostics.d.ts +1 -0
- package/dist/notebook/src/directory-lock.d.ts +10 -0
- package/dist/notebook/src/engine.d.ts +21 -0
- package/dist/notebook/src/execution-runtime.d.ts +33 -0
- package/dist/notebook/src/execution-settlement.d.ts +15 -0
- package/dist/notebook/src/glob.d.ts +1 -0
- package/dist/notebook/src/history.d.ts +6 -0
- package/dist/notebook/src/index.d.ts +57 -0
- package/dist/notebook/src/isolated-runtime.d.ts +19 -0
- package/dist/notebook/src/isolated-storage.d.ts +2 -0
- package/dist/notebook/src/journal-document.d.ts +36 -0
- package/dist/notebook/src/journal.d.ts +37 -0
- package/dist/notebook/src/jupyter-connection.d.ts +17 -0
- package/dist/notebook/src/jupyter-execution.d.ts +29 -0
- package/dist/notebook/src/jupyter-kernel.d.ts +43 -0
- package/dist/notebook/src/jupyter-output.d.ts +32 -0
- package/dist/notebook/src/jupyter-shell.d.ts +18 -0
- package/dist/notebook/src/jupyter-socket.d.ts +17 -0
- package/dist/notebook/src/jupyter-wire.d.ts +16 -0
- package/dist/notebook/src/lifecycle-contract.d.ts +32 -0
- package/dist/notebook/src/lifecycle-inspection.d.ts +7 -0
- package/dist/notebook/src/lifecycle-pins.d.ts +10 -0
- package/dist/notebook/src/lifecycle-release.d.ts +12 -0
- package/dist/notebook/src/lifecycle-result.d.ts +43 -0
- package/dist/notebook/src/lifecycle-runtime.d.ts +35 -0
- package/dist/notebook/src/lifecycle.d.ts +13 -0
- package/dist/notebook/src/lsp-process.d.ts +23 -0
- package/dist/notebook/src/notebook-bootstrap.d.ts +1 -0
- package/dist/notebook/src/notebook-control.d.ts +26 -0
- package/dist/notebook/src/notebook-diagnostic-report.d.ts +25 -0
- package/dist/notebook/src/notebook-diagnostics.d.ts +10 -0
- package/dist/notebook/src/npm-imports.d.ts +10 -0
- package/dist/notebook/src/presentation.d.ts +3 -0
- package/dist/notebook/src/profile-lifecycle.d.ts +22 -0
- package/dist/notebook/src/profile-state-format.d.ts +36 -0
- package/dist/notebook/src/profile-state.d.ts +29 -0
- package/dist/notebook/src/project-identity.d.ts +1 -0
- package/dist/notebook/src/project-state-commit.d.ts +23 -0
- package/dist/notebook/src/project-state-conflicts.d.ts +7 -0
- package/dist/notebook/src/project-state-files.d.ts +9 -0
- package/dist/notebook/src/project-state-format.d.ts +80 -0
- package/dist/notebook/src/project-state-lock.d.ts +1 -0
- package/dist/notebook/src/project-state-merge.d.ts +31 -0
- package/dist/notebook/src/project-state-metadata.d.ts +20 -0
- package/dist/notebook/src/project-state-runtime.d.ts +13 -0
- package/dist/notebook/src/project-state.d.ts +18 -0
- package/dist/notebook/src/recovery.d.ts +28 -0
- package/dist/notebook/src/runtime-contract.d.ts +117 -0
- package/dist/notebook/src/runtime-health.d.ts +9 -0
- package/dist/notebook/src/session-identity.d.ts +2 -0
- package/dist/notebook/src/session-observations.d.ts +35 -0
- package/dist/notebook/src/session-runtime.d.ts +48 -0
- package/dist/notebook/src/session-startup.d.ts +23 -0
- package/dist/notebook/src/storage-retention.d.ts +21 -0
- package/dist/notebook/src/tool-callbacks.d.ts +20 -0
- package/dist/notebook/src/tool-observation.d.ts +21 -0
- package/dist/presentation.js +144 -0
- package/package.json +78 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Context, JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { ConversationId, Harness, JsonObject, TaskId, ToolExecutionApi, ToolExecutionResult, ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { ForwardedToolCalls } from "./forwarded-tools.ts";
|
|
4
|
+
/** Drivers own language/runtime globals. The coordinator owns durable execution and tool calls. */
|
|
5
|
+
export interface CellEngine {
|
|
6
|
+
run(input: JsonObject, api: CellEngineApi, context: Context): Promise<ToolExecutionResult>;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface CellEngineApi {
|
|
10
|
+
readonly taskId: TaskId;
|
|
11
|
+
readonly conversationId: ConversationId;
|
|
12
|
+
readonly signal: AbortSignal;
|
|
13
|
+
readonly toolApi: ToolExecutionApi;
|
|
14
|
+
/** Current selected, wrapped registrations, excluding this execution surface. */
|
|
15
|
+
readonly registrations: readonly ToolRegistration[];
|
|
16
|
+
readonly tools: Readonly<Record<string, (args: JsonValue, signal?: AbortSignal) => Promise<ToolExecutionResult & {
|
|
17
|
+
readonly callId: string;
|
|
18
|
+
}>>>;
|
|
19
|
+
/** Replace the durable driver snapshot, including text, images and runtime errors. */
|
|
20
|
+
publish(result: ToolExecutionResult, context: Context): Promise<void>;
|
|
21
|
+
/** Wake exec/wait observers without settling or cancelling this cell. */
|
|
22
|
+
requestYield(context: Context): Promise<void>;
|
|
23
|
+
/** Optional driver-specific progress, persisted without a provider transcript. */
|
|
24
|
+
checkpoint(value: JsonValue, context: Context): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export type CellObservation = {
|
|
27
|
+
/** A mistaken shell handle was polled directly, not an incremental cell snapshot. */
|
|
28
|
+
readonly recoveredSession?: true;
|
|
29
|
+
readonly cellId: TaskId<ToolExecutionResult>;
|
|
30
|
+
readonly status: "running" | "completed" | "failed" | "aborted" | "interrupted";
|
|
31
|
+
readonly result: ToolExecutionResult;
|
|
32
|
+
readonly forwardedToolCalls?: ForwardedToolCalls;
|
|
33
|
+
readonly checkpoint?: JsonValue;
|
|
34
|
+
};
|
|
35
|
+
export type CellCoordinatorOptions = {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly engine: CellEngine;
|
|
38
|
+
readonly surfaceTools: readonly string[];
|
|
39
|
+
/** Surface registrations that may also be called through ordinary nested dispatch. */
|
|
40
|
+
readonly callableSurfaceTools?: readonly string[];
|
|
41
|
+
/** Admit queued normal cells; the engine owns serial execution and cancellation. */
|
|
42
|
+
readonly normalQueueLimit?: number;
|
|
43
|
+
/** Combined live and isolated admission bound where the runtime shares worker slots. */
|
|
44
|
+
readonly activeCellLimit?: number;
|
|
45
|
+
/** Notebook admits independent checkpoint-copy cells alongside its single live cell. */
|
|
46
|
+
readonly isolatedConcurrency?: number;
|
|
47
|
+
/** Individual task cancellation is a host operation, not part of the tool invocation API. */
|
|
48
|
+
readonly cancelTask: (id: TaskId, context: Context) => ReturnType<Harness["abortTask"]>;
|
|
49
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type TaskId, type ToolExecutionApi, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellObservation } from "./cell-contract.ts";
|
|
4
|
+
import { type InvocationState } from "./invocation-state.ts";
|
|
5
|
+
/** Task documents retire on settlement. Completed cells retain driver snapshots here. */
|
|
6
|
+
export declare const CellStateDoc: import("@earendil-works/pi-durable").ConversationDocFamilyToken<InvocationState, null>;
|
|
7
|
+
export declare function observeCell(kind: string, id: TaskId<ToolExecutionResult>, api: ToolExecutionApi, context: Context, budget?: number): Promise<CellObservation>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import { type TaskId, type ToolExecutionApi, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
/** The observer owns subscriptions and in-flight callbacks until exec/wait returns. */
|
|
4
|
+
export declare function observeCellProgress(id: TaskId<ToolExecutionResult>, api: ToolExecutionApi, context: Context, budget: number): Promise<() => Promise<void>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type JsonObject, type TaskId, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
2
|
+
import type { CellCoordinatorOptions } from "./cell-contract.ts";
|
|
3
|
+
import { createNestedToolTask } from "./nested.ts";
|
|
4
|
+
/** Own the durable cell phases and the process-local driver lifetime together. */
|
|
5
|
+
export declare function createCellTask(options: CellCoordinatorOptions, nestedTask: ReturnType<typeof createNestedToolTask>): {
|
|
6
|
+
task: import("@earendil-works/pi-durable").Task<JsonObject, {
|
|
7
|
+
phase: "start";
|
|
8
|
+
} | {
|
|
9
|
+
phase: "execute";
|
|
10
|
+
}, ToolExecutionResult, Record<string, never>>;
|
|
11
|
+
readonly closed: boolean;
|
|
12
|
+
observeYield(id: TaskId): {
|
|
13
|
+
wake: Promise<void>;
|
|
14
|
+
consume(): boolean;
|
|
15
|
+
};
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Context, type JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { TaskRuntime, ToolControl, ToolExecutionApi, ToolExecutionResult, ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellCoordinatorOptions } from "./cell-contract.ts";
|
|
4
|
+
import { createNestedToolTask } from "./nested.ts";
|
|
5
|
+
/** Preserve invocation order for controls even when nested tools settle out of order. */
|
|
6
|
+
export declare function cellTools(runtime: Pick<TaskRuntime<unknown, unknown, unknown, Record<string, never>>, "taskId" | "signal" | "waitForTask" | "report">, toolApi: ToolExecutionApi, registrations: readonly ToolRegistration[], nestedTask: ReturnType<typeof createNestedToolTask>, controls: (ToolControl | undefined)[], cancelTask: CellCoordinatorOptions["cancelTask"], cellContext: Context): Record<string, (args: JsonValue, signal?: AbortSignal) => Promise<ToolExecutionResult & {
|
|
7
|
+
readonly callId: string;
|
|
8
|
+
}>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import { type Harness, type JsonObject, type TaskId, type ToolExecutionApi, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellCoordinatorOptions, CellObservation } from "./cell-contract.ts";
|
|
4
|
+
export type { CellCoordinatorOptions } from "./cell-contract.ts";
|
|
5
|
+
export declare function createCellCoordinator(options: CellCoordinatorOptions): {
|
|
6
|
+
extension: import("@earendil-works/pi-durable").Extension<import("@earendil-works/pi-durable").ToolRegistration>;
|
|
7
|
+
/** Shared nested dispatch for guest handlers owned by an ordinary tool task. */
|
|
8
|
+
nestedTask: import("@earendil-works/pi-durable").Task<import("./nested-call.ts").NestedInput, import("./nested-call.ts").Checkpoint, ToolExecutionResult, Record<string, never>>;
|
|
9
|
+
bind(harness: Pick<Harness, "conversation">): void;
|
|
10
|
+
start(input: JsonObject, api: ToolExecutionApi, context: Context): Promise<TaskId<ToolExecutionResult>>;
|
|
11
|
+
wait(id: TaskId<ToolExecutionResult>, api: ToolExecutionApi, context: Context, yieldTimeMs?: number, maxTokens?: number, sessionYieldTimeMs?: number): Promise<CellObservation>;
|
|
12
|
+
cancel(id: TaskId<ToolExecutionResult>, api: ToolExecutionApi, context: Context, maxTokens?: number): Promise<CellObservation>;
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface CustomCommandRequest {
|
|
2
|
+
command: string;
|
|
3
|
+
args: readonly string[];
|
|
4
|
+
cwd: string;
|
|
5
|
+
stdin?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Direct command capability. Implementations must enforce the output and cancellation contract. */
|
|
8
|
+
export interface CustomCommandBackend {
|
|
9
|
+
readonly environmentId: string;
|
|
10
|
+
readonly platform: string;
|
|
11
|
+
readonly javascriptRuntime: string;
|
|
12
|
+
/** No shell expansion. Return trimmed stdout, stderr when empty, or '(no output)'.
|
|
13
|
+
* Cap combined bytes at 50 KiB and reject nonzero exits. Cancellation must drain the owned process group. */
|
|
14
|
+
run(request: CustomCommandRequest, signal?: AbortSignal): Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
export interface NodeCommandBackendOptions {
|
|
17
|
+
/** Explicitly verified local process namespace. Must match the invocation environment. */
|
|
18
|
+
environmentId: string;
|
|
19
|
+
env?: NodeJS.ProcessEnv;
|
|
20
|
+
javascriptRuntime?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function createNodeCommandBackend(options: NodeCommandBackendOptions): CustomCommandBackend;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ToolControl } from "@earendil-works/pi-durable";
|
|
2
|
+
/** Nested-cell policy: union additions, any successful termination, first handoff in call order. */
|
|
3
|
+
export declare function combineControls(controls: readonly (ToolControl | undefined)[], allowTermination?: boolean): ToolControl | undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface CustomCommandDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
usage: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
output?: string;
|
|
6
|
+
deferLoading: boolean;
|
|
7
|
+
command: string;
|
|
8
|
+
args: string[];
|
|
9
|
+
input: "arg" | "stdin";
|
|
10
|
+
yieldTimeMs?: number;
|
|
11
|
+
sourcePath: string;
|
|
12
|
+
disabledReason?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CustomCommandParseOptions {
|
|
15
|
+
platform: string;
|
|
16
|
+
/** JavaScript launcher in the command backend's namespace. */
|
|
17
|
+
javascriptRuntime: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const CUSTOM_TOOL_NAME_PATTERN: RegExp;
|
|
20
|
+
export declare function customCommandName(path: string, platform: string): string;
|
|
21
|
+
export declare function parseCustomCommand(path: string, text: string, options: CustomCommandParseOptions): CustomCommandDefinition;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type Registry } from "@earendil-works/pi-durable";
|
|
3
|
+
import { type FileSystem } from "@earendil-works/pi-durable/env";
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
import type { CustomCommandBackend } from "./command-backend.ts";
|
|
6
|
+
import { type CustomCommandDefinition } from "./custom-command-config.ts";
|
|
7
|
+
import type { ExecutionToolRegistration } from "./tool-contract.ts";
|
|
8
|
+
export interface CustomCommandRoot {
|
|
9
|
+
path: string;
|
|
10
|
+
/** The host owns trust. An untrusted root is never read. Later trusted roots override earlier roots. */
|
|
11
|
+
trusted: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface CustomCommandOptions {
|
|
14
|
+
files: FileSystem;
|
|
15
|
+
backend: CustomCommandBackend;
|
|
16
|
+
roots: readonly CustomCommandRoot[];
|
|
17
|
+
name?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CustomCommandDiscoveryError {
|
|
20
|
+
path: string;
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CustomCommandDiscovery {
|
|
24
|
+
tools: CustomCommandDefinition[];
|
|
25
|
+
errors: CustomCommandDiscoveryError[];
|
|
26
|
+
}
|
|
27
|
+
export interface LiveCustomCommandOptions extends CustomCommandOptions {
|
|
28
|
+
registry: Registry;
|
|
29
|
+
onDiscoveryError?(error: CustomCommandDiscoveryError): void;
|
|
30
|
+
}
|
|
31
|
+
/** Explicit trusted-root discovery. No ambient Pi directory, parent search, or bundled examples. */
|
|
32
|
+
export declare function discoverCustomCommands(options: CustomCommandOptions, context: Context): Promise<CustomCommandDiscovery>;
|
|
33
|
+
/** Load TOML commands as ordinary registrations. Re-run this factory and install its returned extension to refresh inventory. */
|
|
34
|
+
export declare function loadCustomCommandTools(options: CustomCommandOptions, context: Context): Promise<{
|
|
35
|
+
extension: import("@earendil-works/pi-durable").Extension<ExecutionToolRegistration<Type.TObject<{
|
|
36
|
+
input: Type.TString;
|
|
37
|
+
}>>>;
|
|
38
|
+
tools: ExecutionToolRegistration<Type.TObject<{
|
|
39
|
+
input: Type.TString;
|
|
40
|
+
}>>[];
|
|
41
|
+
errors: CustomCommandDiscoveryError[];
|
|
42
|
+
}>;
|
|
43
|
+
/** Live config inventory through supported ordinary registry publications, not a Code dispatch adapter. */
|
|
44
|
+
export declare function createCustomCommands(options: LiveCustomCommandOptions, context: Context): Promise<{
|
|
45
|
+
extension: {
|
|
46
|
+
name: string;
|
|
47
|
+
tools?: readonly ExecutionToolRegistration<Type.TObject<{
|
|
48
|
+
input: Type.TString;
|
|
49
|
+
}>>[];
|
|
50
|
+
sections?: readonly import("@earendil-works/pi-durable").PromptSection<ExecutionToolRegistration<Type.TObject<{
|
|
51
|
+
input: Type.TString;
|
|
52
|
+
}>>>[];
|
|
53
|
+
wraps?: readonly import("@earendil-works/pi-durable").Wrap<ExecutionToolRegistration<Type.TObject<{
|
|
54
|
+
input: Type.TString;
|
|
55
|
+
}>>>[];
|
|
56
|
+
tasks?: readonly import("@earendil-works/pi-durable").AnyTask[];
|
|
57
|
+
hooks: import("@earendil-works/pi-durable").HookRegistration[];
|
|
58
|
+
};
|
|
59
|
+
refresh: (refreshContext: Context) => Promise<import("@earendil-works/pi-durable").RegistrySnapshot<import("@earendil-works/pi-durable").ToolRegistration<Type.TSchema, import("@earendil-works/chord").JsonValue>>>;
|
|
60
|
+
readonly errors: readonly CustomCommandDiscoveryError[];
|
|
61
|
+
close(): Promise<void>;
|
|
62
|
+
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const MAX_CODE_MODE_OUTPUT_TOKENS = 100000;
|
|
2
|
+
export declare const DEFAULT_CODE_MODE_EXEC_YIELD_MS = 30000;
|
|
3
|
+
export declare const TRUNCATED_OUTPUT_NOTICE = "[Output truncated; later results may be omitted. Narrow reads or fetch missing help separately. Do not rerun side effects for output.]";
|
|
4
|
+
/** Grow top-level wait observations after incomplete receipts. Requested waits remain a floor. */
|
|
5
|
+
export declare function adaptiveWaitMs(requestedMs: number, previousIncompleteWaits: number): number;
|
|
6
|
+
export declare const CODE_MODE_EXEC_GRAMMAR: string;
|
|
7
|
+
export declare const CODE_MODE_EXEC_CONSTRAINED_SAMPLING: {
|
|
8
|
+
readonly type: "grammar";
|
|
9
|
+
readonly variants: {
|
|
10
|
+
readonly openai_lark: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/** A source cell with optional leading execution budget. Both drivers share this boundary. */
|
|
14
|
+
export declare function parseExecSource(source: string, capabilities?: {
|
|
15
|
+
allowIsolated?: boolean;
|
|
16
|
+
}): {
|
|
17
|
+
code: string;
|
|
18
|
+
yieldTimeMs: number | null;
|
|
19
|
+
maxOutputTokens: number | null;
|
|
20
|
+
isolated: boolean;
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ExecutionResultReceipt, type JsonValue } from "./presentation.ts";
|
|
2
|
+
export type ForwardedToolStatus = "pending" | "running" | "completed" | "failed" | "aborted" | "interrupted";
|
|
3
|
+
/** Display data only; omitted arguments are never substituted into execution. */
|
|
4
|
+
export interface ForwardedToolCall {
|
|
5
|
+
readonly callId: string;
|
|
6
|
+
readonly parentCallId: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly arguments?: JsonValue;
|
|
9
|
+
readonly status: ForwardedToolStatus;
|
|
10
|
+
readonly result: ExecutionResultReceipt | null;
|
|
11
|
+
readonly omittedFields: readonly ("arguments" | "result")[];
|
|
12
|
+
}
|
|
13
|
+
/** Cumulative cell snapshot. Repeated exec/wait observations retain call identities. */
|
|
14
|
+
export interface ForwardedToolCalls {
|
|
15
|
+
readonly version: 1;
|
|
16
|
+
readonly cellId: string;
|
|
17
|
+
readonly calls: readonly ForwardedToolCall[];
|
|
18
|
+
readonly omittedCalls: number;
|
|
19
|
+
}
|
|
20
|
+
/** Old receipts return null. A present malformed receipt is an error, never an inferred call. */
|
|
21
|
+
export declare function parseForwardedToolCalls(details: unknown): ForwardedToolCalls | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Harness } from "@earendil-works/pi-durable";
|
|
2
|
+
/** Observe real native dispatch, including children made by a native tool's own API. */
|
|
3
|
+
export declare function forwardingHook(): {
|
|
4
|
+
bind(harness: Pick<Harness, "conversation">): void;
|
|
5
|
+
hook: import("@earendil-works/pi-durable").HookRegistration;
|
|
6
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ConversationId, type TaskId, type ToolExecutionResult, type Tx } from "@earendil-works/pi-durable";
|
|
2
|
+
import type { ForwardedToolCall, ForwardedToolCalls, ForwardedToolStatus } from "./forwarded-tools.ts";
|
|
3
|
+
import type { ExecutionResultReceipt } from "./presentation.ts";
|
|
4
|
+
/** The budget applies only to display copies, never invocation inputs or runtime results. */
|
|
5
|
+
export declare function boundForwardedToolCalls(value: ForwardedToolCalls, budget: number): ForwardedToolCalls;
|
|
6
|
+
export declare function displayResult(result: ToolExecutionResult, budget: number): ExecutionResultReceipt;
|
|
7
|
+
export declare function forwardedStatus(result: ToolExecutionResult, fallback: ForwardedToolStatus): ForwardedToolStatus;
|
|
8
|
+
/** Update the current cell's existing receipt; no transcript entry or parallel history. */
|
|
9
|
+
export declare function forwardCall(tx: Tx, cellId: TaskId | undefined, call: ForwardedToolCall, admission?: boolean, nativeTask?: {
|
|
10
|
+
taskId: TaskId;
|
|
11
|
+
ownerTaskId: TaskId;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function forwardInvocationResult(tx: Tx, taskId: TaskId, result: ToolExecutionResult, status: ForwardedToolStatus): Promise<void>;
|
|
14
|
+
/** Acquire native progress/results while the caller's task-scoped receipts still exist. */
|
|
15
|
+
export declare function captureNativeCalls(tx: Tx, conversationId: ConversationId, owner: TaskId, cellId: TaskId | undefined): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { ConversationId, Harness } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { ForwardedToolCalls } from "./forwarded-tools.ts";
|
|
4
|
+
export interface ExecutionHistoryRequest {
|
|
5
|
+
readonly conversationId: ConversationId;
|
|
6
|
+
readonly cellIds: readonly string[];
|
|
7
|
+
readonly maxOutputTokens?: number;
|
|
8
|
+
}
|
|
9
|
+
type HistoryHarness = Pick<Harness, "conversation" | "getTask" | "commit">;
|
|
10
|
+
/** Verified retained direct calls only, not a reconstructed native descendant graph.
|
|
11
|
+
* Current fork-visible history excludes later results from the parent conversation.
|
|
12
|
+
*/
|
|
13
|
+
export declare function executionHistory(mode: "notebook" | "code" | "worker-code"): (harness: HistoryHarness, request: ExecutionHistoryRequest, context: Context) => Promise<ReadonlyMap<string, ForwardedToolCalls>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { CellObservation } from "./cell-contract.ts";
|
|
2
|
+
export { type CellCoordinatorOptions, createCellCoordinator } from "./cells.ts";
|
|
3
|
+
export { adaptiveWaitMs, MAX_CODE_MODE_OUTPUT_TOKENS } from "./exec-source.ts";
|
|
4
|
+
export { readToolContract } from "./tool-contract.ts";
|
|
5
|
+
export { directToolYieldTime } from "./tool-source.ts";
|
|
6
|
+
export { toolValue } from "./tool-value.ts";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type JsonRepresentation, type JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import { type TaskId, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { ForwardedToolCalls } from "./forwarded-tools.ts";
|
|
4
|
+
type StoredResult = JsonRepresentation<ToolExecutionResult>;
|
|
5
|
+
export type InvocationState = {
|
|
6
|
+
result: StoredResult;
|
|
7
|
+
checkpoint?: JsonValue;
|
|
8
|
+
yieldCount?: number;
|
|
9
|
+
isolated?: boolean;
|
|
10
|
+
droppedBytes?: number;
|
|
11
|
+
droppedLines?: number;
|
|
12
|
+
forwardingCellId?: TaskId;
|
|
13
|
+
forwardingBudget?: number;
|
|
14
|
+
forwardedToolCalls?: JsonRepresentation<ForwardedToolCalls>;
|
|
15
|
+
/** Admission identities only, bounded to retained display calls; native slots may retire first. */
|
|
16
|
+
forwardedNativeTasks?: {
|
|
17
|
+
callId: string;
|
|
18
|
+
taskId: TaskId;
|
|
19
|
+
ownerTaskId: TaskId;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
export declare const InvocationDoc: import("@earendil-works/pi-durable").TaskDocToken<InvocationState>;
|
|
23
|
+
/** Version-one task receipts remain readable after their task documents retire. */
|
|
24
|
+
export declare function readStoredResult(result: ToolExecutionResult): ToolExecutionResult;
|
|
25
|
+
export declare function storeResult(result: ToolExecutionResult): StoredResult;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import type { TextContent } from "@earendil-works/pi-ai";
|
|
3
|
+
import { type TaskRuntime, type ToolDiagnostic, type ToolExecutionApi, type ToolExecutionResult, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
|
+
import { OutputBuffer, type OutputLimits } from "./output.ts";
|
|
5
|
+
import { Progress } from "./progress.ts";
|
|
6
|
+
export declare function executionError(code: string, message: string): ToolExecutionResult;
|
|
7
|
+
export declare function errorText(error: unknown): string;
|
|
8
|
+
/** One invocation owns its output, progress commits, environment and child-task API. */
|
|
9
|
+
export declare function createInvocation<I, S, R, H extends object>(runtime: TaskRuntime<I, S, R, H>, tool: Pick<ToolRegistration, "outputLimits" | "replay">, context: Context): {
|
|
10
|
+
/** Resolve the environment after the tracker exists, so environment failures still settle bounded hook results. */
|
|
11
|
+
executionApi(): Promise<ToolExecutionApi>;
|
|
12
|
+
finish(result: ToolExecutionResult): Promise<{
|
|
13
|
+
result: ToolExecutionResult;
|
|
14
|
+
pending: {
|
|
15
|
+
promise: Promise<void>;
|
|
16
|
+
resolve(): void;
|
|
17
|
+
reject(error: unknown): void;
|
|
18
|
+
}[];
|
|
19
|
+
retained: {
|
|
20
|
+
readonly text: string;
|
|
21
|
+
readonly droppedBytes: number;
|
|
22
|
+
readonly droppedLines: number;
|
|
23
|
+
};
|
|
24
|
+
content: (import("@earendil-works/pi-ai").ImageContent | TextContent)[];
|
|
25
|
+
}>;
|
|
26
|
+
stop(error: unknown): Promise<void>;
|
|
27
|
+
limits: OutputLimits;
|
|
28
|
+
output: OutputBuffer;
|
|
29
|
+
progress: Progress;
|
|
30
|
+
};
|
|
31
|
+
export declare function boundResult(result: ToolExecutionResult, limits: OutputLimits): ToolExecutionResult;
|
|
32
|
+
export declare function truncation(dropped: {
|
|
33
|
+
droppedLines: number;
|
|
34
|
+
droppedBytes: number;
|
|
35
|
+
}, retain?: "head" | "tail"): ToolDiagnostic;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import { type JsonObject, type NestedToolExecutionResult, type TaskRuntime } from "@earendil-works/pi-durable";
|
|
3
|
+
export declare function nativeToolCalls<I, S, R, H extends object>(runtime: TaskRuntime<I, S, R, H>, callId: string, replay: "safe" | "unsafe" | undefined, assertLive: () => void, context: Context): {
|
|
4
|
+
execute: (name: string, args: JsonObject, context: Context, options?: {
|
|
5
|
+
readonly key?: string;
|
|
6
|
+
readonly progress?: boolean;
|
|
7
|
+
}) => Promise<NestedToolExecutionResult>;
|
|
8
|
+
finish(): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
/** Custom cell callers own native nested slots too, including after recovery. */
|
|
11
|
+
export declare function cleanupNativeCalls<I, S, R, H extends object>(runtime: TaskRuntime<I, S, R, H>, context: Context): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { ToolCall } from "@earendil-works/pi-ai";
|
|
3
|
+
import { type Agent, type HookApi, type JsonObject, type TaskId, type TaskRuntime, type ToolExecutionResult, type ToolHookCall, type ToolHooks, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
4
|
+
export type NestedInput = {
|
|
5
|
+
name: string;
|
|
6
|
+
arguments: JsonValue;
|
|
7
|
+
cellId?: TaskId;
|
|
8
|
+
parent?: NonNullable<ToolHookCall["parent"]>;
|
|
9
|
+
};
|
|
10
|
+
export type Checkpoint = {
|
|
11
|
+
phase: "call";
|
|
12
|
+
} | {
|
|
13
|
+
phase: "execute";
|
|
14
|
+
arguments: JsonObject;
|
|
15
|
+
replay: "safe" | "unsafe";
|
|
16
|
+
};
|
|
17
|
+
export type Runtime = TaskRuntime<NestedInput, Checkpoint, ToolExecutionResult, Record<string, never>>;
|
|
18
|
+
export declare function nestedCall(runtime: Runtime, input: NestedInput): ToolHookCall;
|
|
19
|
+
export declare function checked(tool: ToolRegistration, call: ToolCall, args: unknown): JsonObject;
|
|
20
|
+
/** Decode equivalent structured requests before registration preparation and hooks. */
|
|
21
|
+
export declare function prepareNestedInput(tool: ToolRegistration, input: unknown): unknown;
|
|
22
|
+
/** Public hook registrations erase their handler type. Select by the built-in task name before restoring it. */
|
|
23
|
+
export declare function eachHook<K extends keyof ToolHooks>(agent: Agent, name: K, api: HookApi & {
|
|
24
|
+
signal: AbortSignal;
|
|
25
|
+
report(error: unknown): void;
|
|
26
|
+
}, invoke: (hook: ToolHooks[K]) => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import type { ToolCall } from "@earendil-works/pi-ai";
|
|
3
|
+
import { type JsonObject, type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
4
|
+
import type { Runtime } from "./nested-call.ts";
|
|
5
|
+
/** An audit record, deliberately with no assistant or tool-result model contribution. */
|
|
6
|
+
export declare const NestedResultEntry: import("@earendil-works/pi-durable").Entry<JsonObject>;
|
|
7
|
+
export declare function interrupted(runtime: Runtime, call: ToolCall, code: "interrupted" | "aborted", message: string, context: Context): Promise<void>;
|
|
8
|
+
export declare function settle(runtime: Runtime, call: ToolCall, result: ToolExecutionResult, ending: "completed" | "failed" | "aborted", context: Context): Promise<void>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
2
|
+
import { type Checkpoint, type NestedInput } from "./nested-call.ts";
|
|
3
|
+
export declare function createNestedToolTask(name: string): import("@earendil-works/pi-durable").Task<NestedInput, Checkpoint, ToolExecutionResult, Record<string, never>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ShellOutputSkip } from "@earendil-works/pi-durable/env";
|
|
2
|
+
/** Retention limits of one tool's output. */
|
|
3
|
+
export type OutputLimits = {
|
|
4
|
+
readonly maxBytes: number;
|
|
5
|
+
readonly maxLines: number;
|
|
6
|
+
readonly retain: "head" | "tail";
|
|
7
|
+
};
|
|
8
|
+
/** Retained output and what the limits dropped. */
|
|
9
|
+
type BoundedOutput = {
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly droppedBytes: number;
|
|
12
|
+
readonly droppedLines: number;
|
|
13
|
+
};
|
|
14
|
+
/** An exact slice of the input within the limits, and what it left out. */
|
|
15
|
+
type OutputSlice = {
|
|
16
|
+
readonly text: string;
|
|
17
|
+
readonly bytes: number;
|
|
18
|
+
readonly droppedBytes: number;
|
|
19
|
+
readonly droppedLines: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Bound `text` to whole lines within the limits: the first lines for `head`, the last lines for `tail`. The result is an
|
|
23
|
+
* exact slice, trailing newline included. A single line longer than `maxBytes` is cut at the byte limit on a character
|
|
24
|
+
* boundary.
|
|
25
|
+
*/
|
|
26
|
+
export declare function boundOutput(text: string, limits: OutputLimits): OutputSlice;
|
|
27
|
+
/**
|
|
28
|
+
* Bounded running output of one tool call. Accepting a chunk costs time proportional to the chunk: head retention stops
|
|
29
|
+
* storing once the window is full, and tail retention drops stored text the window no longer needs when it snapshots.
|
|
30
|
+
* Counts of the whole stream are kept so the dropped totals stay exact.
|
|
31
|
+
*/
|
|
32
|
+
export declare class OutputBuffer {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(limits: OutputLimits);
|
|
35
|
+
/** Bytes currently held; bounded by the limits plus one chunk. */
|
|
36
|
+
get storedBytes(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Accept a chunk; returns whether anything was accepted. `skipped` is output omitted right before the chunk, which
|
|
39
|
+
* must be more than the tail window by at least one byte or line (`ShellOutputInfo.skipped`); only tail retention
|
|
40
|
+
* accepts it.
|
|
41
|
+
*/
|
|
42
|
+
push(chunk: string | Uint8Array, skipped?: ShellOutputSkip): boolean;
|
|
43
|
+
/** Flush an incomplete trailing character as a replacement character; call when the stream ends. */
|
|
44
|
+
end(): void;
|
|
45
|
+
/** Retained, sanitized output and what the limits dropped from the whole stream. */
|
|
46
|
+
snapshot(): BoundedOutput;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
2
|
+
readonly [key: string]: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export type ExecutionCellStatus = "running" | "completed" | "failed" | "aborted" | "interrupted";
|
|
5
|
+
export interface ExecutionCellReference {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly status: ExecutionCellStatus;
|
|
8
|
+
}
|
|
9
|
+
/** Display receipt only. Usage and tool controls remain owned by Durable. */
|
|
10
|
+
export interface ExecutionResultReceipt {
|
|
11
|
+
readonly content: readonly ({
|
|
12
|
+
readonly type: "text";
|
|
13
|
+
readonly text: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly type: "image";
|
|
16
|
+
readonly data: string;
|
|
17
|
+
readonly mimeType: string;
|
|
18
|
+
})[];
|
|
19
|
+
readonly isError: boolean;
|
|
20
|
+
readonly details: JsonValue;
|
|
21
|
+
readonly diagnostics: readonly {
|
|
22
|
+
readonly severity: "info" | "warn" | "error";
|
|
23
|
+
readonly message: string;
|
|
24
|
+
readonly code?: string;
|
|
25
|
+
}[];
|
|
26
|
+
}
|
|
27
|
+
/** Host-projected identity and independently acquired, bounded exec/wait or control receipt. */
|
|
28
|
+
export interface ExecutionPresentationState {
|
|
29
|
+
readonly cell: ExecutionCellReference | null;
|
|
30
|
+
readonly result: ExecutionResultReceipt | null;
|
|
31
|
+
}
|
|
32
|
+
export interface ExecutionSummaryModel {
|
|
33
|
+
readonly title: string;
|
|
34
|
+
readonly cell: ExecutionCellReference | null;
|
|
35
|
+
readonly hasResult: boolean;
|
|
36
|
+
readonly isError: boolean | null;
|
|
37
|
+
}
|
|
38
|
+
export declare function parseExecutionResultReceipt(value: JsonValue | undefined): ExecutionResultReceipt | null;
|
|
39
|
+
/** No acquisition, invocation, cancellation, replay or runtime-status inference. */
|
|
40
|
+
declare function parseExecutionPresentationState(value: JsonValue): ExecutionPresentationState;
|
|
41
|
+
export declare function executionCapability(id: string, actions: readonly string[]): {
|
|
42
|
+
id: string;
|
|
43
|
+
version: number;
|
|
44
|
+
actions: readonly string[];
|
|
45
|
+
streams: readonly ["results"];
|
|
46
|
+
presentations: readonly ["summary", "detail"];
|
|
47
|
+
parseState: typeof parseExecutionPresentationState;
|
|
48
|
+
};
|
|
49
|
+
export declare function executionSummary(title: string): {
|
|
50
|
+
id: string;
|
|
51
|
+
select: (state: ExecutionPresentationState) => ExecutionSummaryModel;
|
|
52
|
+
requests: readonly ["detail"];
|
|
53
|
+
};
|
|
54
|
+
export declare const executionDetail: {
|
|
55
|
+
id: string;
|
|
56
|
+
select: (state: ExecutionPresentationState) => ExecutionPresentationState;
|
|
57
|
+
requests: readonly [];
|
|
58
|
+
};
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Each progress commit buys a pause proportional to what it wrote. */
|
|
2
|
+
export declare const PROGRESS_BYTES_PER_SECOND: number;
|
|
3
|
+
type ProgressWaiter = {
|
|
4
|
+
promise: Promise<void>;
|
|
5
|
+
resolve(): void;
|
|
6
|
+
reject(error: unknown): void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Adaptive progress commits, like the environment's shell output capture: the first change after an idle period
|
|
10
|
+
* commits at once; each commit then delays the next by the configured interval and its written size at 100 KiB/s. At most
|
|
11
|
+
* one commit is in flight; changes made meanwhile coalesce into the next one.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Progress {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(write: () => Promise<number>, onError: (error: unknown) => void, minIntervalMs: number);
|
|
16
|
+
/** Schedule a commit. */
|
|
17
|
+
mark(): void;
|
|
18
|
+
/** Schedule a commit; the promise settles with the commit that includes this change. */
|
|
19
|
+
markAndWait(): Promise<void>;
|
|
20
|
+
/** Stop committing and wait for the commit in flight; returns the waiters the final commit must settle. */
|
|
21
|
+
stop(): Promise<ProgressWaiter[]>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ShellOutputStream = "stdout" | "stderr" | "pty";
|
|
2
|
+
export interface ShellSpawnRequest {
|
|
3
|
+
readonly shell: string;
|
|
4
|
+
readonly args: readonly string[];
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
readonly env: NodeJS.ProcessEnv;
|
|
7
|
+
readonly tty: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ShellProcessEvents {
|
|
10
|
+
/** Bytes may split UTF-8 characters. A backend can also deliver already-decoded text. */
|
|
11
|
+
output(stream: ShellOutputStream, chunk: Uint8Array | string): void;
|
|
12
|
+
/** Deliver once, after streams close or the backend's documented drain grace expires. */
|
|
13
|
+
closed(exitCode: number): void;
|
|
14
|
+
}
|
|
15
|
+
export interface ShellProcess {
|
|
16
|
+
write(chars: string): Promise<void>;
|
|
17
|
+
/** Idempotent. Must stop the owned process and release streams before resolving. */
|
|
18
|
+
terminate(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** Explicit native process capability. Implement this for a sandbox or remote namespace. */
|
|
21
|
+
export interface ShellProcessBackend {
|
|
22
|
+
readonly environmentId: string;
|
|
23
|
+
readonly platform: string;
|
|
24
|
+
readonly env: NodeJS.ProcessEnv;
|
|
25
|
+
readonly defaultShell: string;
|
|
26
|
+
/** Startup failure rejects. Never substitute a different host or process backend. */
|
|
27
|
+
spawn(request: ShellSpawnRequest, events: ShellProcessEvents): Promise<ShellProcess>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ShellProcessBackend } from "./backend.ts";
|
|
2
|
+
export interface NodeShellBackendOptions {
|
|
3
|
+
/** Bind only to a namespace the host has verified is local. */
|
|
4
|
+
environmentId: string;
|
|
5
|
+
env?: NodeJS.ProcessEnv;
|
|
6
|
+
defaultShell?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Local child_process and node-pty capability. Construction does not start a process. */
|
|
9
|
+
export declare function createNodeShellBackend(options: NodeShellBackendOptions): ShellProcessBackend;
|