@howaboua/pi-durable-code 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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +251 -0
  3. package/README.md +93 -2
  4. package/dist/activation.js +4759 -0
  5. package/dist/code/src/activation.d.ts +5 -0
  6. package/dist/code/src/binary.d.ts +6 -0
  7. package/dist/code/src/cell-output.d.ts +33 -0
  8. package/dist/code/src/engine.d.ts +16 -0
  9. package/dist/code/src/history.d.ts +6 -0
  10. package/dist/code/src/host-assets.d.ts +4 -0
  11. package/dist/code/src/host-connection.d.ts +29 -0
  12. package/dist/code/src/host-process.d.ts +21 -0
  13. package/dist/code/src/host-protocol.d.ts +54 -0
  14. package/dist/code/src/host-runtime.d.ts +21 -0
  15. package/dist/code/src/host-session.d.ts +24 -0
  16. package/dist/code/src/index.d.ts +32 -0
  17. package/dist/code/src/install-host.d.ts +7 -0
  18. package/dist/code/src/presentation.d.ts +22 -0
  19. package/dist/code/src/result.d.ts +4 -0
  20. package/dist/code/src/runtime-contract.d.ts +24 -0
  21. package/dist/code/src/runtime-response.d.ts +2 -0
  22. package/dist/code/src/runtime-tools.d.ts +7 -0
  23. package/dist/execution/src/cell-contract.d.ts +49 -0
  24. package/dist/execution/src/cell-observation.d.ts +7 -0
  25. package/dist/execution/src/cell-progress.d.ts +4 -0
  26. package/dist/execution/src/cell-task.d.ts +17 -0
  27. package/dist/execution/src/cell-tools.d.ts +8 -0
  28. package/dist/execution/src/cells.d.ts +14 -0
  29. package/dist/execution/src/command-backend.d.ts +22 -0
  30. package/dist/execution/src/controls.d.ts +3 -0
  31. package/dist/execution/src/custom-command-config.d.ts +21 -0
  32. package/dist/execution/src/custom-commands.d.ts +62 -0
  33. package/dist/execution/src/exec-source.d.ts +21 -0
  34. package/dist/execution/src/forwarded-tools.d.ts +21 -0
  35. package/dist/execution/src/forwarding-hook.d.ts +6 -0
  36. package/dist/execution/src/forwarding.d.ts +15 -0
  37. package/dist/execution/src/history.d.ts +14 -0
  38. package/dist/execution/src/index.d.ts +6 -0
  39. package/dist/execution/src/invocation-state.d.ts +26 -0
  40. package/dist/execution/src/invocation.d.ts +35 -0
  41. package/dist/execution/src/native-tools.d.ts +11 -0
  42. package/dist/execution/src/nested-call.d.ts +26 -0
  43. package/dist/execution/src/nested-result.d.ts +8 -0
  44. package/dist/execution/src/nested.d.ts +3 -0
  45. package/dist/execution/src/output.d.ts +48 -0
  46. package/dist/execution/src/presentation.d.ts +59 -0
  47. package/dist/execution/src/progress.d.ts +23 -0
  48. package/dist/execution/src/projection.d.ts +5 -0
  49. package/dist/execution/src/shell/backend.d.ts +28 -0
  50. package/dist/execution/src/shell/format.d.ts +2 -0
  51. package/dist/execution/src/shell/node-backend.d.ts +9 -0
  52. package/dist/execution/src/shell/output.d.ts +19 -0
  53. package/dist/execution/src/shell/process-session.d.ts +50 -0
  54. package/dist/execution/src/shell/results.d.ts +14 -0
  55. package/dist/execution/src/shell/session-manager.d.ts +46 -0
  56. package/dist/execution/src/shell/session-store.d.ts +53 -0
  57. package/dist/execution/src/shell/shell-args.d.ts +4 -0
  58. package/dist/execution/src/shell/shell.d.ts +14 -0
  59. package/dist/execution/src/shell/wait.d.ts +7 -0
  60. package/dist/execution/src/shell.d.ts +14 -0
  61. package/dist/execution/src/tool-contract.d.ts +34 -0
  62. package/dist/execution/src/tool-origin.d.ts +11 -0
  63. package/dist/execution/src/tool-source.d.ts +6 -0
  64. package/dist/execution/src/tool-value.d.ts +3 -0
  65. package/dist/execution/src/wait-session.d.ts +6 -0
  66. package/dist/history.js +315 -0
  67. package/dist/index.js +5063 -0
  68. package/dist/presentation.js +198 -0
  69. package/package.json +77 -5
@@ -0,0 +1,5 @@
1
+ import { type ComponentInstance, type ComponentRequest } from "@howaboua/pi-durable-components";
2
+ import { type CodeModeOptions, createCodeMode } from "./index.ts";
3
+ /** Optional complete constructor override; replaces baseline JSON configuration. */
4
+ export declare const codeOptions: import("@howaboua/pi-durable-components").ComponentCapability<CodeModeOptions>;
5
+ export declare function createComponent(request: ComponentRequest): ComponentInstance<ReturnType<typeof createCodeMode>>;
@@ -0,0 +1,6 @@
1
+ export interface HostOptions {
2
+ /** Explicit supported standalone host. Overrides automatic provisioning. */
3
+ hostPath?: string;
4
+ cacheDirectory?: string;
5
+ }
6
+ export declare function ensureHost(options: HostOptions, signal?: AbortSignal): Promise<string>;
@@ -0,0 +1,33 @@
1
+ import type { ToolExecutionResult } from "@earendil-works/pi-durable";
2
+ import type { CellObservation } from "../../execution/src/index.ts";
3
+ import type { RuntimeResponse } from "./runtime-contract.ts";
4
+ /** One observation window, including delivery backpressure and bounded diagnostic traces. */
5
+ export declare class CodeCellOutput {
6
+ private readonly maxTokens;
7
+ private delivery;
8
+ private readonly output;
9
+ private remainingChars;
10
+ private imageChars;
11
+ private imageCount;
12
+ private omittedImages;
13
+ private truncated;
14
+ private revision;
15
+ private readonly notifications;
16
+ private append;
17
+ private readonly traces;
18
+ private droppedTraceCount;
19
+ private current;
20
+ constructor(maxTokens: number);
21
+ result(): ToolExecutionResult;
22
+ notify(text: string): void;
23
+ trace(id: string, name: string, input: unknown): {
24
+ done(result: ToolExecutionResult, callId: string): void;
25
+ failed(error: unknown): void;
26
+ };
27
+ replaceObservation(response: RuntimeResponse): void;
28
+ get hasOutput(): boolean;
29
+ get delivered(): Promise<void>;
30
+ acknowledge(revision: number): boolean;
31
+ }
32
+ /** Project one acknowledged durable snapshot with the caller's own output budget. */
33
+ export declare function observeCodeCell(observation: CellObservation, maxTokens: number, acknowledge: (taskId: number, revision: number) => boolean): ToolExecutionResult;
@@ -0,0 +1,16 @@
1
+ import { type Context } from "@earendil-works/chord";
2
+ import type { JsonObject, ToolExecutionResult } from "@earendil-works/pi-durable";
3
+ import type { CellEngine, CellEngineApi } from "../../execution/src/cell-contract.ts";
4
+ import { type HostOptions } from "./binary.ts";
5
+ /** One host session per conversation. Store/load cannot cross conversation boundaries. */
6
+ export declare class CodeEngine implements CellEngine {
7
+ private readonly sessions;
8
+ private readonly options;
9
+ private readonly deliveries;
10
+ private closed;
11
+ constructor(options?: HostOptions);
12
+ run(input: JsonObject, api: CellEngineApi, context: Context): Promise<ToolExecutionResult>;
13
+ /** Ack only the exact snapshot delivered. Repeated running observations must not repeat its content. */
14
+ acknowledge(taskId: number, revision: number): boolean;
15
+ close(): Promise<void>;
16
+ }
@@ -0,0 +1,6 @@
1
+ export type { ExecutionHistoryRequest } from "../../execution/src/history.ts";
2
+ export declare const readForwardedToolCalls: (harness: {
3
+ conversation: (id: import("@earendil-works/pi-durable").ConversationId, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").Conversation | undefined>;
4
+ getTask: <R>(id: import("@earendil-works/pi-durable").TaskId<R>, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").TaskRecord<import("@earendil-works/chord").JsonValue, import("@earendil-works/chord").JsonValue, R> | undefined>;
5
+ commit: <T>(change: (tx: import("@earendil-works/pi-durable").Tx) => T | Promise<T>, context: import("@earendil-works/chord").Context) => Promise<T>;
6
+ }, request: import("../../execution/src/history.ts").ExecutionHistoryRequest, context: import("@earendil-works/chord").Context) => Promise<ReadonlyMap<string, import("./presentation.ts").ForwardedToolCalls>>;
@@ -0,0 +1,4 @@
1
+ export declare const HOST_RELEASE = "rust-v0.163.0";
2
+ export declare function codeModeHostBinaryName(platform: string): string;
3
+ export declare function resolveCodeModeHostAsset(platform: string, arch: string): readonly [string, string];
4
+ export declare function hostAssetUrl(assetName: string): string;
@@ -0,0 +1,29 @@
1
+ import { type HostMessage } from "./host-protocol.ts";
2
+ type HostConnectionOptions = {
3
+ binary: string;
4
+ onMessage: (message: HostMessage) => void;
5
+ onFailure: (error: Error) => void;
6
+ };
7
+ export declare class CodeModeHostConnection {
8
+ private readonly process;
9
+ private readonly onMessage;
10
+ private readonly onFailure;
11
+ private requestId;
12
+ private ready;
13
+ private pending;
14
+ private initial;
15
+ constructor(options: HostConnectionOptions);
16
+ get running(): boolean;
17
+ nextRequestId(): number;
18
+ start(): Promise<void>;
19
+ private startProcess;
20
+ request(request: Record<string, unknown>, onValue?: (value: unknown) => void): Promise<unknown>;
21
+ requestWithId(id: number, request: Record<string, unknown>, onValue?: (value: unknown) => void): Promise<unknown>;
22
+ expectInitial(id: number): Promise<unknown>;
23
+ send(message: unknown): void;
24
+ rejectOperation(id: number, error: Error): void;
25
+ close(error: Error): void;
26
+ private handleMessage;
27
+ private failAll;
28
+ }
29
+ export {};
@@ -0,0 +1,21 @@
1
+ type HostProcessOptions = {
2
+ binary: string;
3
+ onMessage: (message: unknown) => void;
4
+ onFailure: (error: Error) => void;
5
+ };
6
+ export declare class CodeModeHostProcess {
7
+ private readonly binary;
8
+ private readonly onMessage;
9
+ private readonly onFailure;
10
+ private child;
11
+ private buffer;
12
+ private stderr;
13
+ private queuedWriteBytes;
14
+ constructor(options: HostProcessOptions);
15
+ get running(): boolean;
16
+ start(): void;
17
+ send(message: unknown): void;
18
+ kill(): void;
19
+ private onData;
20
+ }
21
+ export {};
@@ -0,0 +1,54 @@
1
+ export type HostMessage = {
2
+ type: "connection/ready";
3
+ selectedVersion: 1;
4
+ capabilities: string[];
5
+ } | {
6
+ type: "connection/rejected";
7
+ reason: unknown;
8
+ } | {
9
+ type: "operation/response";
10
+ id: number;
11
+ result: HostResult;
12
+ } | {
13
+ type: "execute/initialResponse";
14
+ id: number;
15
+ result: HostResult;
16
+ } | ({
17
+ type: "delegate/request";
18
+ } & DelegateRequestMessage) | {
19
+ type: "delegate/cancel";
20
+ id: number;
21
+ } | {
22
+ type: "cell/closed";
23
+ cellId: string;
24
+ };
25
+ export interface DelegateRequestMessage {
26
+ id: number;
27
+ request: {
28
+ type: "notification/send";
29
+ cellId: string;
30
+ text: string;
31
+ } | {
32
+ type: "tool/invoke";
33
+ invocation: {
34
+ cell_id: string;
35
+ input?: unknown;
36
+ runtime_tool_call_id: string;
37
+ tool_name: {
38
+ name: string;
39
+ namespace?: string | undefined;
40
+ };
41
+ };
42
+ };
43
+ }
44
+ type HostResult = {
45
+ status: "ok";
46
+ value: unknown;
47
+ } | {
48
+ status: "error";
49
+ message: string;
50
+ };
51
+ export declare function parseHostMessage(value: unknown): HostMessage;
52
+ export declare function executionCellId(value: unknown): string | undefined;
53
+ export declare function runtimeOutcome(value: unknown): unknown;
54
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { RuntimeCallbacks, RuntimeResponse, RuntimeTool } from "./runtime-contract.ts";
2
+ /** Standalone pinned V8 host. No filesystem, network or process capability enters the isolate. */
3
+ export declare class CodeHostRuntime {
4
+ private readonly session;
5
+ private readonly cells;
6
+ private readonly delegates;
7
+ private closed;
8
+ private failure;
9
+ private readonly failureController;
10
+ get failureSignal(): AbortSignal;
11
+ constructor(binary: string);
12
+ execute(source: string, tools: readonly RuntimeTool[], callbacks: RuntimeCallbacks, signal?: AbortSignal, onStarted?: (cellId: string) => void, yieldTimeMsOverride?: number): Promise<RuntimeResponse>;
13
+ wait(cellId: string, yieldTimeMs?: number, signal?: AbortSignal): Promise<RuntimeResponse>;
14
+ terminate(cellId: string): Promise<RuntimeResponse>;
15
+ close(): Promise<void>;
16
+ private clear;
17
+ private cancelCell;
18
+ private handle;
19
+ private invoke;
20
+ private respond;
21
+ }
@@ -0,0 +1,24 @@
1
+ import type { HostMessage } from "./host-protocol.ts";
2
+ type HostSessionOptions = {
3
+ binary: string;
4
+ shutdownGraceMs?: number | undefined;
5
+ onMessage: (message: HostMessage) => void;
6
+ onFailure: (error: Error) => void;
7
+ };
8
+ export declare class CodeModeHostSession {
9
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
10
+ private readonly connection;
11
+ private readonly shutdownGraceMs;
12
+ private readonly onFailure;
13
+ private ready;
14
+ constructor(options: HostSessionOptions);
15
+ start(): Promise<void>;
16
+ private startSession;
17
+ nextRequestId(): number;
18
+ expectInitial(id: number): Promise<unknown>;
19
+ requestWithId(id: number, request: Record<string, unknown>, onValue?: (value: unknown) => void): Promise<unknown>;
20
+ send(message: unknown): void;
21
+ rejectOperation(id: number, error: Error): void;
22
+ shutdown(): Promise<void>;
23
+ }
24
+ export {};
@@ -0,0 +1,32 @@
1
+ import { type CellCoordinatorOptions } from "../../execution/src/index.ts";
2
+ import { type ShellRuntimeOptions } from "../../execution/src/shell.ts";
3
+ import type { HostOptions } from "./binary.ts";
4
+ export type { CustomCommandBackend, CustomCommandRequest, NodeCommandBackendOptions, } from "../../execution/src/command-backend.ts";
5
+ export { createNodeCommandBackend } from "../../execution/src/command-backend.ts";
6
+ export type { CustomCommandDefinition, CustomCommandParseOptions, } from "../../execution/src/custom-command-config.ts";
7
+ export { parseCustomCommand } from "../../execution/src/custom-command-config.ts";
8
+ export type { CustomCommandDiscovery, CustomCommandDiscoveryError, CustomCommandOptions, CustomCommandRoot, LiveCustomCommandOptions, } from "../../execution/src/custom-commands.ts";
9
+ export { createCustomCommands, discoverCustomCommands, loadCustomCommandTools, } from "../../execution/src/custom-commands.ts";
10
+ export { CODE_MODE_EXEC_CONSTRAINED_SAMPLING, CODE_MODE_EXEC_GRAMMAR, } from "../../execution/src/exec-source.ts";
11
+ export type { NodeShellBackendOptions, ShellOutputStream, ShellProcess, ShellProcessBackend, ShellProcessEvents, ShellRuntimeOptions, ShellSpawnRequest, } from "../../execution/src/shell.ts";
12
+ export { createNodeShellBackend } from "../../execution/src/shell.ts";
13
+ export type { ExecutionToolHints, ExecutionToolRegistration, } from "../../execution/src/tool-contract.ts";
14
+ export interface CodeModeOptions extends HostOptions {
15
+ shell: ShellRuntimeOptions;
16
+ cancelTask: CellCoordinatorOptions["cancelTask"];
17
+ }
18
+ /** Public Code product. Ordinary tools are discovered from the selected Durable registry. */
19
+ export declare function createCodeMode(options: CodeModeOptions): {
20
+ /** Bind the same Harness that owns this extension to retain native-only provider tools. */
21
+ /** Bind the owning Harness before execution to retain native nested display receipts. */
22
+ bind: (harness: Pick<import("@earendil-works/pi-durable").Harness, "conversation">) => void;
23
+ extension: {
24
+ name: string;
25
+ hooks?: readonly import("@earendil-works/pi-durable").HookRegistration[];
26
+ wraps?: readonly import("@earendil-works/pi-durable").Wrap<import("@earendil-works/pi-durable").ToolRegistration>[];
27
+ tasks?: readonly import("@earendil-works/pi-durable").AnyTask[];
28
+ tools: import("@earendil-works/pi-durable").ToolRegistration[];
29
+ sections: import("@earendil-works/pi-durable").PromptSection<import("@earendil-works/pi-durable").ToolRegistration>[];
30
+ };
31
+ close(): Promise<void>;
32
+ };
@@ -0,0 +1,7 @@
1
+ export interface InstallCodeModeHostOptions {
2
+ destination: string;
3
+ platform: string;
4
+ arch: string;
5
+ signal?: AbortSignal | undefined;
6
+ }
7
+ export declare function installCodeModeHost(options: InstallCodeModeHostOptions): Promise<void>;
@@ -0,0 +1,22 @@
1
+ export type { ForwardedToolCall, ForwardedToolCalls, ForwardedToolStatus, } from "../../execution/src/forwarded-tools.ts";
2
+ export { parseForwardedToolCalls } from "../../execution/src/forwarded-tools.ts";
3
+ export type { ExecutionCellReference, ExecutionCellStatus, ExecutionPresentationState as CodePresentationState, ExecutionResultReceipt, ExecutionSummaryModel, } from "../../execution/src/presentation.ts";
4
+ /** Host binds ordinary registrations and publishes acquired observations on results. */
5
+ export declare const codeCapability: {
6
+ id: string;
7
+ version: number;
8
+ actions: readonly string[];
9
+ streams: readonly ["results"];
10
+ presentations: readonly ["summary", "detail"];
11
+ parseState: (value: import("../../execution/src/presentation.ts").JsonValue) => import("../../execution/src/presentation.ts").ExecutionPresentationState;
12
+ };
13
+ export declare const codeSummary: {
14
+ id: string;
15
+ select: (state: import("../../execution/src/presentation.ts").ExecutionPresentationState) => import("../../execution/src/presentation.ts").ExecutionSummaryModel;
16
+ requests: readonly ["detail"];
17
+ };
18
+ export declare const codeDetail: {
19
+ id: string;
20
+ select: (state: import("../../execution/src/presentation.ts").ExecutionPresentationState) => import("../../execution/src/presentation.ts").ExecutionPresentationState;
21
+ requests: readonly [];
22
+ };
@@ -0,0 +1,4 @@
1
+ import type { ToolExecutionResult } from "@earendil-works/pi-durable";
2
+ import type { RuntimeResponse } from "./runtime-contract.ts";
3
+ /** The source bridge bounds text at four characters per requested token and images independently. */
4
+ export declare function runtimeResult(response: RuntimeResponse, maxTokens?: number): ToolExecutionResult;
@@ -0,0 +1,24 @@
1
+ export type RuntimeContentItem = {
2
+ type: "input_text";
3
+ text: string;
4
+ } | {
5
+ type: "input_image";
6
+ image_url: string;
7
+ detail?: "auto" | "low" | "high" | "original" | null;
8
+ };
9
+ export interface RuntimeResponse {
10
+ kind: "yielded" | "terminated" | "result";
11
+ cellId: string;
12
+ contentItems: RuntimeContentItem[];
13
+ errorText?: string;
14
+ }
15
+ export interface RuntimeTool {
16
+ name: string;
17
+ description: string;
18
+ inputSchema: unknown;
19
+ invoke(input: unknown, signal: AbortSignal, callId: string): Promise<unknown>;
20
+ }
21
+ export interface RuntimeCallbacks {
22
+ notify(text: string): Promise<void>;
23
+ yield?(): Promise<void>;
24
+ }
@@ -0,0 +1,2 @@
1
+ import type { RuntimeResponse } from "./runtime-contract.ts";
2
+ export declare function parseRuntimeResponse(value: unknown): RuntimeResponse;
@@ -0,0 +1,7 @@
1
+ import { type Context } from "@earendil-works/chord";
2
+ import type { CellEngineApi } from "../../execution/src/cell-contract.ts";
3
+ import { readToolContract } from "../../execution/src/index.ts";
4
+ import type { CodeCellOutput } from "./cell-output.ts";
5
+ import type { RuntimeTool } from "./runtime-contract.ts";
6
+ /** Adapt ordinary registrations and their full results at the native delegate boundary. */
7
+ export declare function runtimeTools(api: CellEngineApi, contracts: ReturnType<typeof readToolContract>[], observation: CodeCellOutput, context: Context): RuntimeTool[];
@@ -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
+ };