@howaboua/pi-durable-js-notebook 0.0.0-stage → 0.9.1

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +39 -0
  3. package/README.md +38 -2
  4. package/dist/execution/src/cell-contract.d.ts +49 -0
  5. package/dist/execution/src/cell-observation.d.ts +7 -0
  6. package/dist/execution/src/cell-progress.d.ts +4 -0
  7. package/dist/execution/src/cell-task.d.ts +17 -0
  8. package/dist/execution/src/cell-tools.d.ts +8 -0
  9. package/dist/execution/src/cells.d.ts +14 -0
  10. package/dist/execution/src/command-backend.d.ts +22 -0
  11. package/dist/execution/src/controls.d.ts +3 -0
  12. package/dist/execution/src/custom-command-config.d.ts +21 -0
  13. package/dist/execution/src/custom-commands.d.ts +62 -0
  14. package/dist/execution/src/exec-source.d.ts +21 -0
  15. package/dist/execution/src/forwarded-tools.d.ts +21 -0
  16. package/dist/execution/src/forwarding-hook.d.ts +6 -0
  17. package/dist/execution/src/forwarding.d.ts +15 -0
  18. package/dist/execution/src/index.d.ts +6 -0
  19. package/dist/execution/src/invocation-state.d.ts +26 -0
  20. package/dist/execution/src/invocation.d.ts +35 -0
  21. package/dist/execution/src/native-tools.d.ts +11 -0
  22. package/dist/execution/src/nested-call.d.ts +26 -0
  23. package/dist/execution/src/nested-result.d.ts +8 -0
  24. package/dist/execution/src/nested.d.ts +3 -0
  25. package/dist/execution/src/output.d.ts +48 -0
  26. package/dist/execution/src/presentation.d.ts +59 -0
  27. package/dist/execution/src/progress.d.ts +23 -0
  28. package/dist/execution/src/projection.d.ts +5 -0
  29. package/dist/execution/src/shell/backend.d.ts +28 -0
  30. package/dist/execution/src/shell/format.d.ts +2 -0
  31. package/dist/execution/src/shell/node-backend.d.ts +9 -0
  32. package/dist/execution/src/shell/output.d.ts +19 -0
  33. package/dist/execution/src/shell/process-session.d.ts +50 -0
  34. package/dist/execution/src/shell/results.d.ts +14 -0
  35. package/dist/execution/src/shell/session-manager.d.ts +46 -0
  36. package/dist/execution/src/shell/session-store.d.ts +53 -0
  37. package/dist/execution/src/shell/shell-args.d.ts +4 -0
  38. package/dist/execution/src/shell/shell.d.ts +14 -0
  39. package/dist/execution/src/shell/wait.d.ts +7 -0
  40. package/dist/execution/src/shell.d.ts +14 -0
  41. package/dist/execution/src/tool-contract.d.ts +34 -0
  42. package/dist/execution/src/tool-origin.d.ts +11 -0
  43. package/dist/execution/src/tool-source.d.ts +6 -0
  44. package/dist/execution/src/tool-value.d.ts +3 -0
  45. package/dist/execution/src/wait-session.d.ts +6 -0
  46. package/dist/index.js +6338 -0
  47. package/dist/js-notebook/src/bindings.d.ts +6 -0
  48. package/dist/js-notebook/src/client.d.ts +34 -0
  49. package/dist/js-notebook/src/data-state.d.ts +20 -0
  50. package/dist/js-notebook/src/data-storage.d.ts +17 -0
  51. package/dist/js-notebook/src/engine.d.ts +16 -0
  52. package/dist/js-notebook/src/index.d.ts +53 -0
  53. package/dist/js-notebook/src/kernel.d.ts +25 -0
  54. package/dist/js-notebook/src/managed-bindings.d.ts +20 -0
  55. package/dist/js-notebook/src/managed-source.d.ts +9 -0
  56. package/dist/js-notebook/src/notebook-control.d.ts +7 -0
  57. package/dist/js-notebook/src/portable-state.d.ts +79 -0
  58. package/dist/js-notebook/src/prelude.d.ts +1 -0
  59. package/dist/js-notebook/src/project.d.ts +67 -0
  60. package/dist/js-notebook/src/protocol.d.ts +115 -0
  61. package/dist/js-notebook/src/runtime-cache.d.ts +2 -0
  62. package/dist/js-notebook/src/runtime-contract.d.ts +117 -0
  63. package/dist/js-notebook/src/runtime.d.ts +8 -0
  64. package/dist/js-notebook/src/state-validation.d.ts +2 -0
  65. package/dist/js-notebook/src/storage.d.ts +18 -0
  66. package/dist/js-notebook/src/support.d.ts +12 -0
  67. package/dist/js-notebook/src/tool-calls.d.ts +11 -0
  68. package/dist/js-notebook/src/worker.d.ts +1 -0
  69. package/dist/notebook/src/cell.d.ts +34 -0
  70. package/dist/notebook/src/checkpoint-activity.d.ts +7 -0
  71. package/dist/notebook/src/checkpoint-format.d.ts +32 -0
  72. package/dist/notebook/src/checkpoint-store.d.ts +8 -0
  73. package/dist/notebook/src/command-output.d.ts +1 -0
  74. package/dist/notebook/src/deno-syntax-diagnostics.d.ts +1 -0
  75. package/dist/notebook/src/directory-lock.d.ts +10 -0
  76. package/dist/notebook/src/glob.d.ts +1 -0
  77. package/dist/notebook/src/jupyter-connection.d.ts +17 -0
  78. package/dist/notebook/src/jupyter-execution.d.ts +29 -0
  79. package/dist/notebook/src/jupyter-kernel.d.ts +43 -0
  80. package/dist/notebook/src/jupyter-output.d.ts +32 -0
  81. package/dist/notebook/src/jupyter-shell.d.ts +18 -0
  82. package/dist/notebook/src/jupyter-socket.d.ts +17 -0
  83. package/dist/notebook/src/jupyter-wire.d.ts +16 -0
  84. package/dist/notebook/src/profile-state-format.d.ts +36 -0
  85. package/dist/notebook/src/project-identity.d.ts +1 -0
  86. package/dist/notebook/src/project-state-format.d.ts +80 -0
  87. package/dist/notebook/src/project-state-lock.d.ts +1 -0
  88. package/dist/notebook/src/runtime-contract.d.ts +117 -0
  89. package/dist/notebook/src/runtime-health.d.ts +9 -0
  90. package/dist/notebook/src/storage-retention.d.ts +21 -0
  91. package/dist/notebook/src/tool-observation.d.ts +21 -0
  92. package/dist/worker.js +1545 -0
  93. package/package.json +51 -5
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { KernelExecutionResult } from "./jupyter-kernel.ts";
2
+ import type { RuntimeContentItem, ToolExecutionContext } from "./runtime-contract.ts";
3
+ export declare class NotebookCell {
4
+ readonly id: string;
5
+ readonly source: string;
6
+ readonly controller: AbortController;
7
+ readonly items: RuntimeContentItem[];
8
+ readonly maxOutputTokens: number;
9
+ context: ToolExecutionContext;
10
+ result?: KernelExecutionResult | undefined;
11
+ terminated: boolean;
12
+ private outputChars;
13
+ private outputTruncated;
14
+ private cursor;
15
+ private completedValue;
16
+ private yielded;
17
+ private blockersChanged;
18
+ private readonly blockers;
19
+ private readonly completed;
20
+ constructor(options: {
21
+ id: string;
22
+ source: string;
23
+ context: ToolExecutionContext;
24
+ maxOutputTokens: number;
25
+ });
26
+ observe(yieldTimeMs: number, signal?: AbortSignal): Promise<"result" | "yielded">;
27
+ markCompleted(): void;
28
+ isCompleted(): boolean;
29
+ waitForCompletion(): Promise<void>;
30
+ requestYield(): void;
31
+ setBlocked(blockerId: string, active: boolean): void;
32
+ takeContent(): RuntimeContentItem[];
33
+ emit(items: RuntimeContentItem[]): void;
34
+ }
@@ -0,0 +1,7 @@
1
+ import type { NotebookCheckpointIdentity } from "./checkpoint-format.ts";
2
+ export interface NotebookCheckpointActivity {
3
+ touch(): void;
4
+ release(): void;
5
+ }
6
+ export declare function activateNotebookCheckpoint(identity: NotebookCheckpointIdentity, signal?: AbortSignal): Promise<NotebookCheckpointActivity>;
7
+ export declare function expireNotebookSessionCheckpoints(agentDir: string, retentionAge: () => number | undefined, now?: number): Promise<void>;
@@ -0,0 +1,32 @@
1
+ import { type ProjectBindingMetadata } from "./project-state-format.ts";
2
+ export declare const CHECKPOINT_SCHEMA = 1;
3
+ interface CheckpointEntry extends ProjectBindingMetadata {
4
+ name: string;
5
+ kind: "value" | "function";
6
+ offset: number;
7
+ length: number;
8
+ }
9
+ export interface CheckpointManifest {
10
+ schema: number;
11
+ project: string;
12
+ projectGeneration?: string | undefined;
13
+ projectNames?: string[] | undefined;
14
+ session: string;
15
+ deno: string;
16
+ v8: string;
17
+ payload: string;
18
+ createdAt: string;
19
+ entries: CheckpointEntry[];
20
+ skipped: Array<{
21
+ name: string;
22
+ reason: string;
23
+ }>;
24
+ }
25
+ export interface NotebookCheckpointIdentity {
26
+ project: string;
27
+ session: string;
28
+ agentDir: string;
29
+ }
30
+ export declare function readCheckpointManifest(path: string): CheckpointManifest | undefined;
31
+ export declare function isValidCheckpointPayload(manifest: CheckpointManifest, path: string, maxBytes: number): boolean;
32
+ export {};
@@ -0,0 +1,8 @@
1
+ import { type NotebookCheckpointIdentity } from "./checkpoint-format.ts";
2
+ export declare function garbageCollectSupersededNotebookCheckpoints(identity: NotebookCheckpointIdentity): void;
3
+ export declare function removeNotebookCheckpoint(identity: NotebookCheckpointIdentity): void;
4
+ export declare function notebookCheckpointBindingNames(identity: NotebookCheckpointIdentity, maxBytes: number): string[];
5
+ export declare function checkpointPaths(identity: NotebookCheckpointIdentity): {
6
+ directory: string;
7
+ manifest: string;
8
+ };
@@ -0,0 +1 @@
1
+ export declare const commandOutputFormatterSource = "(value, plain) => {\n const metadata = Object.fromEntries(Object.entries(value).filter(([key]) =>\n key !== \"output\" && key !== \"chunk_id\" && key !== \"wall_time_seconds\"\n && (key !== \"original_token_count\" || value.truncated)));\n const projected = plain ? metadata : { output: value.output, ...metadata };\n let text;\n try { text = JSON.stringify(projected); } catch { text = String(projected); }\n return plain ? text + \"\\nOutput:\\n\" + value.output : text;\n}";
@@ -0,0 +1 @@
1
+ export declare function diagnoseDenoSyntax(deno: string, source: string, env: NodeJS.ProcessEnv, cellSource?: string): Promise<string | undefined>;
@@ -0,0 +1,10 @@
1
+ export interface DirectoryLock {
2
+ release(): void;
3
+ }
4
+ export declare function acquireDirectoryLock(path: string, options: {
5
+ waitMs: number;
6
+ staleMs: number;
7
+ pollMs: number;
8
+ signal?: AbortSignal | undefined;
9
+ stopWaiting?: (() => boolean) | undefined;
10
+ }): Promise<DirectoryLock | undefined>;
@@ -0,0 +1 @@
1
+ export declare function globMatcher(glob: string): (value: string) => boolean;
@@ -0,0 +1,17 @@
1
+ export interface JupyterConnectionInfo {
2
+ ip: "127.0.0.1";
3
+ transport: "tcp";
4
+ shell_port: number;
5
+ iopub_port: number;
6
+ stdin_port: number;
7
+ control_port: number;
8
+ hb_port: number;
9
+ signature_scheme: "hmac-sha256";
10
+ key: string;
11
+ kernel_name: "deno";
12
+ }
13
+ export declare function createJupyterConnectionFile(): Promise<{
14
+ info: JupyterConnectionInfo;
15
+ path: string;
16
+ dir: string;
17
+ }>;
@@ -0,0 +1,29 @@
1
+ import { type KernelExecutionResult } from "./jupyter-output.ts";
2
+ import { type JupyterMessage } from "./jupyter-wire.ts";
3
+ import type { RuntimeContentItem } from "./runtime-contract.ts";
4
+ interface JupyterExecutionHost {
5
+ deno: string;
6
+ env: NodeJS.ProcessEnv;
7
+ start(signal?: AbortSignal): Promise<void>;
8
+ sendShellRequest(request: JupyterMessage, timeoutMs?: number, requestType?: string): Promise<JupyterMessage>;
9
+ interrupt(): Promise<void>;
10
+ failKernel(error: Error): void;
11
+ }
12
+ /** Collection spans the cell reply/idle and a FIFO output marker's reply/idle. */
13
+ export declare class JupyterExecution {
14
+ private active;
15
+ private readonly session;
16
+ private readonly host;
17
+ constructor(session: string, host: JupyterExecutionHost);
18
+ isActive(): boolean;
19
+ reject(error: Error): void;
20
+ execute(code: string, options?: {
21
+ cellSource?: string | undefined;
22
+ signal?: AbortSignal | undefined;
23
+ onOutput?: ((item: RuntimeContentItem) => void) | undefined;
24
+ interruptOnAbort?: boolean | undefined;
25
+ }): Promise<KernelExecutionResult>;
26
+ accept(message: JupyterMessage): void;
27
+ private drainOutput;
28
+ }
29
+ export {};
@@ -0,0 +1,43 @@
1
+ import type { KernelExecutionResult } from "./jupyter-output.ts";
2
+ import type { RuntimeContentItem } from "./runtime-contract.ts";
3
+ export type { KernelExecutionResult } from "./jupyter-output.ts";
4
+ export declare class DenoJupyterKernel {
5
+ private readonly deno;
6
+ private readonly execution;
7
+ private readonly shellChannel;
8
+ private readonly env;
9
+ private readonly maxHeapMiB;
10
+ private readonly onFailure;
11
+ private readonly session;
12
+ private process;
13
+ private tempDir;
14
+ private connection;
15
+ private control;
16
+ private iopub;
17
+ private shellPump;
18
+ private iopubPump;
19
+ private startup;
20
+ private stderr;
21
+ private terminalFailure;
22
+ constructor(options: {
23
+ deno: string;
24
+ maxHeapMiB: number;
25
+ env?: NodeJS.ProcessEnv | undefined;
26
+ onFailure?: ((kernel: DenoJupyterKernel, error: Error) => void) | undefined;
27
+ });
28
+ start(signal?: AbortSignal): Promise<void>;
29
+ execute(code: string, options?: {
30
+ cellSource?: string | undefined;
31
+ signal?: AbortSignal | undefined;
32
+ onOutput?: ((item: RuntimeContentItem) => void) | undefined;
33
+ interruptOnAbort?: boolean | undefined;
34
+ }): Promise<KernelExecutionResult>;
35
+ complete(code?: string, cursorPosition?: number, signal?: AbortSignal): Promise<string[]>;
36
+ interrupt(): Promise<void>;
37
+ shutdown(): Promise<void>;
38
+ private startInner;
39
+ private waitForKernelReady;
40
+ private runIopubPump;
41
+ private failKernel;
42
+ private dispose;
43
+ }
@@ -0,0 +1,32 @@
1
+ import type { JupyterMessage } from "./jupyter-wire.ts";
2
+ import type { RuntimeContentItem } from "./runtime-contract.ts";
3
+ export declare const OUTPUT_DRAIN_MESSAGE = "pi_notebook_output_drained";
4
+ export interface KernelExecutionResult {
5
+ status: "ok" | "error" | "aborted";
6
+ items: RuntimeContentItem[];
7
+ errorText?: string | undefined;
8
+ errorName?: string | undefined;
9
+ errorValue?: string | undefined;
10
+ }
11
+ export interface ActiveKernelExecution {
12
+ requestId: string;
13
+ drain?: {
14
+ requestId: string;
15
+ marker: string;
16
+ idle: boolean;
17
+ seen: boolean;
18
+ } | undefined;
19
+ items: RuntimeContentItem[];
20
+ outputChars: number;
21
+ outputTruncated: boolean;
22
+ status: KernelExecutionResult["status"];
23
+ errorText?: string | undefined;
24
+ errorName?: string | undefined;
25
+ errorValue?: string | undefined;
26
+ onOutput?: ((item: RuntimeContentItem) => void) | undefined;
27
+ resolve(): void;
28
+ reject(error: Error): void;
29
+ }
30
+ export declare function applyKernelOutput(message: JupyterMessage, execution: ActiveKernelExecution): "idle" | undefined;
31
+ export declare function finishKernelExecution(execution: ActiveKernelExecution): KernelExecutionResult;
32
+ export declare function applyExecuteReplyError(result: KernelExecutionResult, reply: JupyterMessage): KernelExecutionResult;
@@ -0,0 +1,18 @@
1
+ import type { JupyterConnectionInfo } from "./jupyter-connection.ts";
2
+ import type { JupyterSocket } from "./jupyter-socket.ts";
3
+ import { type JupyterMessage } from "./jupyter-wire.ts";
4
+ /** Correlation, request timeouts and disconnect settlement belong to the shell channel. */
5
+ export declare class JupyterShellChannel {
6
+ private shell;
7
+ private connection;
8
+ private readonly shellReplies;
9
+ private readonly session;
10
+ private readonly stderr;
11
+ private readonly onFailure;
12
+ constructor(session: string, stderr: () => string, onFailure: (error: Error) => void);
13
+ attach(shell: JupyterSocket, connection: JupyterConnectionInfo): void;
14
+ close(): void;
15
+ request(type: string, content: Record<string, unknown>, timeoutMs?: number, signal?: AbortSignal): Promise<JupyterMessage>;
16
+ send(request: JupyterMessage, timeoutMs?: number, requestType?: string, signal?: AbortSignal): Promise<JupyterMessage>;
17
+ pump(socket: JupyterSocket, connection: JupyterConnectionInfo): Promise<void>;
18
+ }
@@ -0,0 +1,17 @@
1
+ export declare class JupyterSocket {
2
+ private socket;
3
+ private reader;
4
+ private buffered;
5
+ private readonly stopped;
6
+ private ready;
7
+ private readonly type;
8
+ private readonly port;
9
+ constructor(type: "DEALER" | "SUB", port: number);
10
+ connect(signal?: AbortSignal): Promise<void>;
11
+ send(frames: readonly Buffer[]): Promise<void>;
12
+ [Symbol.asyncIterator](): AsyncGenerator<Buffer[]>;
13
+ close(): void;
14
+ private read;
15
+ private readFrame;
16
+ private write;
17
+ }
@@ -0,0 +1,16 @@
1
+ export interface JupyterMessage {
2
+ header: {
3
+ msg_id: string;
4
+ session: string;
5
+ username: string;
6
+ date: string;
7
+ msg_type: string;
8
+ version: string;
9
+ };
10
+ parent_header: Record<string, unknown>;
11
+ metadata: Record<string, unknown>;
12
+ content: Record<string, unknown>;
13
+ }
14
+ export declare function createJupyterMessage(type: string, content: Record<string, unknown>, session: string): JupyterMessage;
15
+ export declare function encodeJupyterMessage(message: JupyterMessage, key: string): Buffer[];
16
+ export declare function decodeJupyterMessage(frames: Buffer[], key: string): JupyterMessage | undefined;
@@ -0,0 +1,36 @@
1
+ import { type ProjectStateEntry } from "./project-state-format.ts";
2
+ export declare const PROFILE_STATE_SCHEMA = 1;
3
+ export interface ProfileStateManifest {
4
+ schema: number;
5
+ name: string;
6
+ deno: string;
7
+ v8: string;
8
+ payload: string;
9
+ createdAt: string;
10
+ sourceProject: string;
11
+ entries: ProjectStateEntry[];
12
+ skipped: Array<{
13
+ name: string;
14
+ reason: string;
15
+ }>;
16
+ }
17
+ export interface ProfileStateSummary {
18
+ name: string;
19
+ createdAt: string;
20
+ sourceProject: string;
21
+ values: number;
22
+ definitions: number;
23
+ skipped: number;
24
+ }
25
+ export declare function profileStatePaths(name: string, agentDir: string): {
26
+ directory: string;
27
+ manifest: string;
28
+ lock: string;
29
+ };
30
+ export declare function profilesDirectory(agentDir: string): string;
31
+ export declare function assertProfileName(name: string): void;
32
+ export declare function readProfileStateManifest(path: string, expectedName?: string): ProfileStateManifest | undefined;
33
+ export declare function assertSafeProfileDirectory(directory: string, agentDir: string): void;
34
+ export declare function readProfileStatePayload(manifest: ProfileStateManifest, path: string, maxBytes: number): Buffer | undefined;
35
+ export declare function profileSummary(manifest: ProfileStateManifest): ProfileStateSummary;
36
+ export declare function hashProfileBytes(bytes: Uint8Array): string;
@@ -0,0 +1 @@
1
+ export declare function resolveNotebookProject(cwd: string): string;
@@ -0,0 +1,80 @@
1
+ import type { NotebookHook } from "./runtime-contract.ts";
2
+ export declare const PROJECT_STATE_SCHEMA = 2;
3
+ export declare const MAX_PROJECT_ENTRIES = 10000;
4
+ export declare const MAX_PROJECT_NAME_BYTES: number;
5
+ export declare const MAX_PROJECT_MANIFEST_BYTES: number;
6
+ export declare const MAX_PROJECT_DESCRIPTION_BYTES = 256;
7
+ export declare const MAX_PROJECT_USAGE_BYTES = 512;
8
+ export declare const MAX_PROJECT_USAGE_LINES = 4;
9
+ export interface ProjectStateEntry {
10
+ name: string;
11
+ kind: "value" | "function";
12
+ offset: number;
13
+ length: number;
14
+ hash: string;
15
+ description?: string | undefined;
16
+ usage?: string | undefined;
17
+ updatedAt?: string | undefined;
18
+ pinned?: true | undefined;
19
+ hook?: NotebookHook | undefined;
20
+ }
21
+ export interface ProjectBindingMetadata {
22
+ description?: string | undefined;
23
+ usage?: string | undefined;
24
+ }
25
+ export interface ProjectStateManifest {
26
+ schema: number;
27
+ project: string;
28
+ generation: string;
29
+ parentGeneration?: string | undefined;
30
+ deno: string;
31
+ v8: string;
32
+ payload: string;
33
+ createdAt: string;
34
+ sourceSession: string;
35
+ entries: ProjectStateEntry[];
36
+ skipped: Array<{
37
+ name: string;
38
+ reason: string;
39
+ }>;
40
+ }
41
+ export interface ProjectStateCandidate {
42
+ deno: string;
43
+ v8: string;
44
+ entries: Array<Omit<ProjectStateEntry, "hash">>;
45
+ skipped: Array<{
46
+ name: string;
47
+ reason: string;
48
+ }>;
49
+ }
50
+ export interface ProjectStateBaseline {
51
+ generation: string;
52
+ entries: Array<{
53
+ name: string;
54
+ hash: string;
55
+ } & ProjectBindingMetadata>;
56
+ }
57
+ export interface ProjectStateSummary {
58
+ baseline: ProjectStateBaseline;
59
+ restored: ProjectStateEntry[];
60
+ skipped: Array<{
61
+ name: string;
62
+ reason: string;
63
+ }>;
64
+ conflicts: string[];
65
+ message?: string | undefined;
66
+ }
67
+ export interface ProjectConflictRecord {
68
+ names: string[];
69
+ payload?: string | undefined;
70
+ }
71
+ export declare function baselineFromProjectManifest(manifest: ProjectStateManifest): ProjectStateBaseline;
72
+ export declare function emptyProjectStateSummary(): ProjectStateSummary;
73
+ export declare function hashStateBytes(bytes: Uint8Array): string;
74
+ export declare function parseEntry(value: unknown, payloadLength: number, requireHash: boolean): ProjectStateEntry | Omit<ProjectStateEntry, "hash"> | undefined;
75
+ export declare function parseProjectBindingMetadata(value: Record<string, unknown>): ProjectBindingMetadata | undefined;
76
+ export declare function parseSkipped(value: unknown): {
77
+ name: string;
78
+ reason: string;
79
+ } | undefined;
80
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export declare function withProjectStateLock<T>(path: string, operation: () => Promise<T>, signal?: AbortSignal): Promise<T>;
@@ -0,0 +1,117 @@
1
+ import type { NotebookStorageRetention } from "./storage-retention.ts";
2
+ export interface NotebookSessionContext {
3
+ cwd: string;
4
+ sessionId: string;
5
+ }
6
+ export interface NotebookRuntimeOptions {
7
+ maxHeapMiB: number;
8
+ agentDir: string;
9
+ profile?: string | undefined;
10
+ env?: NodeJS.ProcessEnv | undefined;
11
+ storage?: NotebookStorageRetention | undefined;
12
+ }
13
+ export interface ToolExecutionContext {
14
+ cwd: string;
15
+ sessionContext: NotebookSessionContext;
16
+ onUpdate?: ((result: {
17
+ content: Array<{
18
+ type: "text";
19
+ text: string;
20
+ } | {
21
+ type: "image";
22
+ data: string;
23
+ mimeType: string;
24
+ }>;
25
+ details?: unknown;
26
+ }) => void) | undefined;
27
+ setBlocked?: ((id: string, active: boolean) => void) | undefined;
28
+ onYield?: (() => Promise<void>) | undefined;
29
+ }
30
+ export interface NotebookToolIdentity {
31
+ name: string;
32
+ namespace?: string | undefined;
33
+ }
34
+ export interface NotebookToolDefinition {
35
+ name: string;
36
+ description: string;
37
+ usage: string;
38
+ help?: string | undefined;
39
+ textOutput?: "command" | "plain-command" | undefined;
40
+ invoke(input: unknown, context: ToolExecutionContext, signal: AbortSignal): Promise<unknown>;
41
+ }
42
+ export interface NotebookExecutionClient {
43
+ execute(source: string, context: ToolExecutionContext, signal?: AbortSignal, tools?: NotebookToolDefinition[]): Promise<RuntimeResponse>;
44
+ wait(cellId: string, yieldTimeMs: number, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
45
+ terminate(cellId: string, context: ToolExecutionContext, signal?: AbortSignal): Promise<RuntimeResponse>;
46
+ shutdown(): Promise<void>;
47
+ }
48
+ export interface RuntimeContentItem {
49
+ type: "input_text" | "input_image";
50
+ text?: string;
51
+ image_url?: string;
52
+ detail?: "auto" | "low" | "high" | "original" | null;
53
+ }
54
+ export interface NotebookMemoryUsage {
55
+ heapUsedBytes: number;
56
+ heapTotalBytes: number;
57
+ rssBytes: number;
58
+ externalBytes: number;
59
+ heapLimitBytes: number;
60
+ }
61
+ export type NotebookHook = "startup" | "tool_result";
62
+ export type NotebookControlRequest = {
63
+ action: "status";
64
+ query?: string | undefined;
65
+ } | {
66
+ action: "list";
67
+ query?: string | undefined;
68
+ } | {
69
+ action: "checkpoint";
70
+ } | {
71
+ action: "save";
72
+ name: string;
73
+ } | {
74
+ action: "load";
75
+ name: string;
76
+ } | {
77
+ action: "pin";
78
+ names: string[];
79
+ hook?: NotebookHook | false | undefined;
80
+ } | {
81
+ action: "unpin";
82
+ names: string[];
83
+ } | {
84
+ action: "release";
85
+ names: string[];
86
+ } | {
87
+ action: "prune";
88
+ query: string;
89
+ } | {
90
+ action: "restart";
91
+ } | {
92
+ action: "diagnostics";
93
+ } | {
94
+ action: "reset";
95
+ };
96
+ export interface NotebookControlResult {
97
+ message: string;
98
+ details: Record<string, unknown>;
99
+ }
100
+ export type RuntimeResponse = ({
101
+ kind: "yielded";
102
+ cellId: string;
103
+ contentItems: RuntimeContentItem[];
104
+ } | {
105
+ kind: "terminated";
106
+ cellId: string;
107
+ contentItems: RuntimeContentItem[];
108
+ } | {
109
+ kind: "result";
110
+ cellId: string;
111
+ contentItems: RuntimeContentItem[];
112
+ errorText?: string | undefined;
113
+ }) & {
114
+ maxOutputTokens?: number | undefined;
115
+ missingCell?: true | undefined;
116
+ notebookMemory?: NotebookMemoryUsage | undefined;
117
+ };
@@ -0,0 +1,9 @@
1
+ export type NotebookRuntimeHealthState = "not_started" | "ready" | "invalidated";
2
+ export interface NotebookRuntimeHealth {
3
+ state: NotebookRuntimeHealthState;
4
+ }
5
+ export declare const NOTEBOOK_INTERRUPTED_NOTICE = "Notebook runtime was invalidated by an interrupted cell. The next operation will recreate it from the last completed checkpoint; durable project bindings were preserved. External side effects were not rolled back";
6
+ export declare const NOTEBOOK_BOOTSTRAP_NOTICE = "Notebook runtime bootstrap was unavailable. The kernel was discarded; the next operation will recreate it from the last completed checkpoint. Durable project bindings were preserved";
7
+ export declare const NOTEBOOK_KERNEL_FAILURE_NOTICE = "Notebook runtime became unavailable during a host operation. The next operation will recreate it from the last completed checkpoint; durable project bindings were preserved. External side effects were not rolled back";
8
+ export declare function withNotebookRecoveryGuidance(message: string): string;
9
+ export declare function isNotebookBootstrapFailure(value: unknown): boolean;
@@ -0,0 +1,21 @@
1
+ export type NotebookJournalRetention = "off" | "week" | "on";
2
+ export type NotebookCheckpointRetention = "never" | "month" | "week";
3
+ export interface NotebookStoragePolicy {
4
+ journals?: NotebookJournalRetention;
5
+ checkpointCleanup?: NotebookCheckpointRetention;
6
+ }
7
+ /** Owns coalesced maintenance. The host supplies policy, never Pi-global paths. */
8
+ export declare class NotebookStorageRetention {
9
+ private pending;
10
+ private forceAgain;
11
+ readonly agentDir: string;
12
+ private readonly getPolicy;
13
+ constructor(agentDir: string, getPolicy?: () => NotebookStoragePolicy);
14
+ policy(): Required<NotebookStoragePolicy>;
15
+ schedule(): void;
16
+ maintain(force?: boolean): Promise<void>;
17
+ drain(): Promise<void>;
18
+ private pass;
19
+ }
20
+ export declare function notebookJournalsDirectory(agentDir: string): string;
21
+ export declare function removeExpiredNotebookJournalFiles(files: string[], now?: number): void;
@@ -0,0 +1,21 @@
1
+ import { type Context } from "@earendil-works/chord";
2
+ import { type TaskId, type ToolExecutionApi } from "@earendil-works/pi-durable";
3
+ import type { CellObservation } from "../../execution/src/cell-contract.ts";
4
+ export declare function notebookCellTaskId(value: string): TaskId<import("@earendil-works/pi-durable").ToolExecutionResult>;
5
+ export declare function observeNotebookCell(observation: CellObservation, maxTokens: number, api: ToolExecutionApi, context: Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult | {
6
+ structuredOutput?: import("@earendil-works/chord").JsonValue;
7
+ isError?: boolean;
8
+ diagnostics?: readonly import("@earendil-works/pi-durable").ToolDiagnostic[];
9
+ usage?: import("@earendil-works/pi-ai").Usage;
10
+ control?: import("@earendil-works/pi-durable").ToolControl;
11
+ output: (import("@earendil-works/pi-ai").ImageContent | {
12
+ type: "text";
13
+ text: string;
14
+ })[];
15
+ details: {
16
+ cell_id: string;
17
+ status: "aborted" | "completed" | "failed" | "interrupted" | "running";
18
+ forwardedToolCalls?: import("@earendil-works/chord").JsonValue;
19
+ runtime?: import("@earendil-works/chord").JsonValue;
20
+ };
21
+ }>;