@howaboua/pi-durable-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.
- package/LICENSE +21 -0
- package/NOTICE +54 -0
- package/README.md +105 -2
- 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/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 +54 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Igor Warzocha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Applicable PR #552 changes adapted from howaboua-pi-stuff revision
|
|
2
|
+
84bd5bce60a77c4298484d4b7c810d4fe5220a1b. Existing Deno isolated candidates, commit-ordered snapshot reads
|
|
3
|
+
and Deno 2.9.8 provisioning pins are carried. TypeScript execution mode
|
|
4
|
+
and QuickJS Notebook are excluded. See docs/parity for native adaptations.
|
|
5
|
+
|
|
6
|
+
Notebook runtime source adapted from @howaboua/pi-codex-conversion
|
|
7
|
+
Repository: https://github.com/IgorWarzocha/howaboua-pi-stuff
|
|
8
|
+
Revision: b2006db9def12c373ae48e70044d30f7d6b7e34f
|
|
9
|
+
Source: packages/pi-codex-conversion/src/tools/notebook-mode and code-mode/
|
|
10
|
+
notebook-tool.ts, command-output.ts, types.ts, custom-tools.ts,
|
|
11
|
+
custom-tool-runner.ts
|
|
12
|
+
|
|
13
|
+
FIFO Jupyter output draining follows revision
|
|
14
|
+
fa9e42d577f9a2739a2cf14909b56bb3e8b89aea, inspected in snapshot
|
|
15
|
+
036dc876da5afc4ec27b64878ebb1cfb30c8211d.
|
|
16
|
+
Help-backed discovery and nested argument preparation refreshed against
|
|
17
|
+
7f3295e67a8e6146b2a6922b56a06fa4db5c3a32, including local source commits.
|
|
18
|
+
Journal retention and activity-protected checkpoint expiry follow revision
|
|
19
|
+
81d48c1e2937244991b9f054450215a95b8ea8c6, inspected at
|
|
20
|
+
12c4357b2c401fe9be8c6c82d2ae252c0f986937. Storage policy is supplied through
|
|
21
|
+
public factory options rather than Pi-global configuration files.
|
|
22
|
+
Stable startup binding inventories and lifecycle help refreshed against
|
|
23
|
+
3d0faf5a6f0bc67c0bd9248d07da6ddfa901b281.
|
|
24
|
+
Operating guidance also follows src/prompt/build-system-prompt.ts at
|
|
25
|
+
a06eae4d141fae421a8d0108a4a560013d6508a8.
|
|
26
|
+
|
|
27
|
+
Custom command discovery uses explicit trusted roots and an environment-bound
|
|
28
|
+
process backend. Shared command factories publish ordinary Durable registrations.
|
|
29
|
+
|
|
30
|
+
The component provisions Deno 2.9.7 on first runtime use. Deno is MIT licensed.
|
|
31
|
+
No Deno executable is included in this npm package. Platform archive and
|
|
32
|
+
executable checksums and sizes are retained from the source revision.
|
|
33
|
+
|
|
34
|
+
MIT License
|
|
35
|
+
|
|
36
|
+
Copyright (c) 2026 Igor Warzocha
|
|
37
|
+
|
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
39
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
40
|
+
in the Software without restriction, including without limitation the rights
|
|
41
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
42
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
43
|
+
furnished to do so, subject to the following conditions:
|
|
44
|
+
|
|
45
|
+
The above copyright notice and this permission notice shall be included in all
|
|
46
|
+
copies or substantial portions of the Software.
|
|
47
|
+
|
|
48
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
49
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
50
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
51
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
52
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
53
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
54
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Notebook for Durable
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run TypeScript in a persistent Deno kernel. Globals and imports survive between cells. Serializable values and self-contained functions restore from checkpoints without replaying the cells that created them. Shell tools are included.
|
|
4
|
+
|
|
5
|
+
Requires Node 22.19 or newer and Durable 1.4.0.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.9.1/howaboua-pi-durable-notebook-0.9.1.tgz
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The shell's native PTY addon requires Python, Make and a C++ compiler on Linux. If install scripts are disabled, run `npm rebuild node-pty` before using interactive shells. Pipe-based commands do not require the addon.
|
|
12
|
+
|
|
13
|
+
Install the extension before opening your harness. Bind native execution explicitly to the same filesystem namespace as the conversation.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Harness, createRegistry } from '@earendil-works/pi-durable';
|
|
17
|
+
import { NodeExecutionEnv } from '@earendil-works/pi-durable/env/node';
|
|
18
|
+
import { createNotebookMode, createNodeShellBackend } from '@howaboua/pi-durable-notebook';
|
|
19
|
+
|
|
20
|
+
const env = new NodeExecutionEnv({ cwd: process.cwd() });
|
|
21
|
+
let harness: Harness;
|
|
22
|
+
const notebook = createNotebookMode({
|
|
23
|
+
stateDirectory: '/absolute/path/to/notebook-state',
|
|
24
|
+
native: { environmentId: env.id },
|
|
25
|
+
shell: { backend: createNodeShellBackend({ environmentId: env.id }) },
|
|
26
|
+
cancelTask: (id, context) => harness.abortTask(id, context),
|
|
27
|
+
});
|
|
28
|
+
const registry = createRegistry();
|
|
29
|
+
registry.install(notebook.extension);
|
|
30
|
+
// Install the other tools you want the notebook to call.
|
|
31
|
+
harness = await Harness.open(storage, { models, registry, env: () => env }, context);
|
|
32
|
+
notebook.bind(harness);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`storage`, `models`, and `context` are your normal Durable setup. Select the Notebook extension and the other extensions you want in the conversation. Select only one of Code and Notebook at a time.
|
|
36
|
+
|
|
37
|
+
The agent uses `exec` with TypeScript source. Plain source is accepted by the tool's freeform preparation. JSON tool callers use `{ "code": "text(await tools.some_tool({ ... }))" }`. `ALL_TOOLS` contains the selected tool contracts. Every ordinary Durable registration is callable without a Notebook adapter. Durable owns validation, wrappers, hooks, task ownership, usage accounting, and interruption handling.
|
|
38
|
+
|
|
39
|
+
Ordinary registration `executionHints` can supply custom usage, output help, a discovery schema, promotion, and a direct-call yield budget. Tools remain deferred by default. Promoted tools add one usage line to the prompt. Direct-call yield hints take precedence over the cell's pragma. Tool names remain unchanged and punctuation is callable through `tools[name]`.
|
|
40
|
+
|
|
41
|
+
Registrations with `executionHints.nativeOnly: true` stay native model tools and are unavailable inside cells, including through retained tool functions. Binding the Harness enables their native projection. Context management uses this boundary for `new_context`.
|
|
42
|
+
|
|
43
|
+
Tool results preserve their details and content. Images expose a base64 `image_url` usable with `image(result)`. Tool failures throw inside the cell. Bare expression values are discarded, so use `text(value)` to emit output.
|
|
44
|
+
|
|
45
|
+
Call `notebook` with `{}` or `{ "input": "help" }` for state management help. Inside exec, `await tools.notebook({})` also returns help. It covers checkpoints, protected project bindings, profiles, disposal, recovery, and historical diagnostics. New npm imports require approval and exact-version `npm:` specifiers. Successfully used imports are inventoried per project. This approval guidance is not a package sandbox.
|
|
46
|
+
|
|
47
|
+
## Custom commands
|
|
48
|
+
|
|
49
|
+
Existing custom-tool TOML definitions are supported through ordinary Durable registrations. Supply their directories and trust decisions explicitly; the package does not scan Pi's home directory or enable bundled examples.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { createCustomCommands, createNodeCommandBackend } from '@howaboua/pi-durable-notebook';
|
|
53
|
+
|
|
54
|
+
const commands = await createCustomCommands({
|
|
55
|
+
registry,
|
|
56
|
+
files: env,
|
|
57
|
+
backend: createNodeCommandBackend({ environmentId: env.id }),
|
|
58
|
+
roots: [
|
|
59
|
+
{ path: globalCommands, trusted: true },
|
|
60
|
+
{ path: projectCommands, trusted: projectIsTrusted },
|
|
61
|
+
],
|
|
62
|
+
onDiscoveryError: error => console.error(error.message),
|
|
63
|
+
}, context);
|
|
64
|
+
// Select commands.extension alongside notebook.extension in the conversation.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Each top-level `.toml` filename names a tool. Required fields are `usage` and `command`; optional fields are `description`, `output`, `args`, `input`, `defer_loading`, and `yield_time_ms`. Later trusted directories override earlier ones. Invalid overrides remain disabled rather than falling back to a global command. Untrusted directories are not read.
|
|
68
|
+
|
|
69
|
+
Commands accept one string, passed as a final argument by default or through stdin with `input = "stdin"`. They run without shell expansion in the conversation's working directory. Relative command paths resolve from the TOML directory; bare commands use the backend's `PATH`; absolute JavaScript files use its JavaScript launcher. Filesystem and process backends must share the conversation's environment namespace.
|
|
70
|
+
|
|
71
|
+
Successful output is stdout with trailing whitespace removed, then stderr when stdout is empty, then `(no output)`. Nonzero exits include stderr. Combined output is capped at 50 KiB. Cancellation drains the owned process group where supported.
|
|
72
|
+
|
|
73
|
+
Definitions are reread before execution. The live loader refreshes ordinary registry registrations before model requests, exposing additions, removals and metadata changes in `ALL_TOOLS`. `defer_loading = false` promotes the usage line into the Notebook prompt. Direct-call `yield_time_ms` hints take precedence over the exec pragma; multiple direct calls use the largest hint. No Notebook-specific command bridge is required.
|
|
74
|
+
|
|
75
|
+
`loadCustomCommandTools(options, context)` provides a snapshot loader for hosts that publish registry updates themselves. `commands.errors` exposes discovery errors. Call `await commands.close()` when removing the live loader.
|
|
76
|
+
|
|
77
|
+
## Runtime and persistence
|
|
78
|
+
|
|
79
|
+
Deno 2.9.8 downloads only when execution or diagnostics first needs it. Archives and extracted binaries are verified against pinned sizes and SHA-256 checksums. Linux, macOS, and Windows support x64 and ARM64. `stateDirectory` owns the executable cache, private session checkpoints, project generations, conflict journals, named profiles, and standard `.ipynb` journals. `maxHeapMiB` defaults to 4096. `profile` optionally loads a named profile at kernel startup.
|
|
80
|
+
|
|
81
|
+
Each conversation has a private kernel. Project bindings merge under cross-process locks. Other live kernels are not mutated. Checkpoints restore by value, not by replay. Imported modules, promises, weak collections, and live resource handles must be recreated after restart. Function restoration requires self-contained definitions. Durable pins protect bindings from release and pruning. Startup and tool-result hooks are deliberately awaited, and hook calls do not recursively trigger hooks.
|
|
82
|
+
|
|
83
|
+
Notebook journals expire after one week without updates by default. Session
|
|
84
|
+
checkpoint expiry is off by default. Supply `getStoragePolicy` to read live host
|
|
85
|
+
settings, using `journals: 'off' | 'week' | 'on'` and
|
|
86
|
+
`checkpointCleanup: 'never' | 'month' | 'week'`. `on` keeps journals indefinitely.
|
|
87
|
+
`off` stops recording and removes saved journals when maintenance runs. Execution,
|
|
88
|
+
checkpoints and binding recovery still work with journals off. Historical
|
|
89
|
+
diagnostics report that recording must be re-enabled.
|
|
90
|
+
|
|
91
|
+
Call `await notebook.maintainStorage()` after a settings change to apply it
|
|
92
|
+
immediately. Automatic maintenance otherwise runs at most daily when the Notebook
|
|
93
|
+
is used. Journal writes also check the current policy, including during a running
|
|
94
|
+
cell. Checkpoint expiry uses seven or thirty days of inactivity. Cross-process
|
|
95
|
+
leases protect active native sessions even while their kernels are idle, and
|
|
96
|
+
closing a session records its final use. Project bindings and named profiles are
|
|
97
|
+
never aged out. Cleanup is confined to this factory's `stateDirectory` and is
|
|
98
|
+
drained on close.
|
|
99
|
+
|
|
100
|
+
This is native Deno, with filesystem, network, process, and codec capabilities. It is not a JavaScript-only substitute or a security sandbox. `native.environmentId` must match the execution environment. Remote and container environments must explicitly provision the harness and Deno in the same native namespace. A mismatch fails rather than falling back to host files. `native.env` selects the kernel process environment when supplied.
|
|
101
|
+
|
|
102
|
+
One normal exec cell can be active per conversation. A leading `// @exec: {"isolated":true}` starts a separate Deno kernel from committed saved state, with up to four isolated cells alongside the normal cell. Each successful isolated cell saves a named candidate without changing live bindings. Use `notebook` list to find candidates and load to add their supported bindings by value. Release or rename collisions before loading. Arbitrary closures, types, imports and live handles do not transfer.
|
|
103
|
+
|
|
104
|
+
`wait` observes or terminates a cell without replaying it. Termination cancels owned nested work and invalidates that cell's kernel. External tool and file effects remain shared and are not rolled back. Restart, reset and close stop isolated cells too. After a host restart, interrupted work is reported instead of being executed again. Live kernels and PTYs do not survive a host restart.
|
|
105
|
+
|
|
106
|
+
Call `await notebook.close()` before closing your harness. It joins active cells and closes kernels, bridge servers, and owned shell sessions.
|
|
@@ -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>>;
|