@howaboua/pi-durable-notebook 0.0.0-stage → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +54 -0
  3. package/README.md +105 -2
  4. package/dist/activation.js +11433 -0
  5. package/dist/execution/src/cell-contract.d.ts +49 -0
  6. package/dist/execution/src/cell-observation.d.ts +7 -0
  7. package/dist/execution/src/cell-progress.d.ts +4 -0
  8. package/dist/execution/src/cell-task.d.ts +17 -0
  9. package/dist/execution/src/cell-tools.d.ts +8 -0
  10. package/dist/execution/src/cells.d.ts +14 -0
  11. package/dist/execution/src/command-backend.d.ts +22 -0
  12. package/dist/execution/src/controls.d.ts +3 -0
  13. package/dist/execution/src/custom-command-config.d.ts +21 -0
  14. package/dist/execution/src/custom-commands.d.ts +62 -0
  15. package/dist/execution/src/exec-source.d.ts +21 -0
  16. package/dist/execution/src/forwarded-tools.d.ts +21 -0
  17. package/dist/execution/src/forwarding-hook.d.ts +6 -0
  18. package/dist/execution/src/forwarding.d.ts +15 -0
  19. package/dist/execution/src/history.d.ts +14 -0
  20. package/dist/execution/src/index.d.ts +6 -0
  21. package/dist/execution/src/invocation-state.d.ts +26 -0
  22. package/dist/execution/src/invocation.d.ts +35 -0
  23. package/dist/execution/src/native-tools.d.ts +11 -0
  24. package/dist/execution/src/nested-call.d.ts +26 -0
  25. package/dist/execution/src/nested-result.d.ts +8 -0
  26. package/dist/execution/src/nested.d.ts +3 -0
  27. package/dist/execution/src/output.d.ts +48 -0
  28. package/dist/execution/src/presentation.d.ts +59 -0
  29. package/dist/execution/src/progress.d.ts +23 -0
  30. package/dist/execution/src/projection.d.ts +5 -0
  31. package/dist/execution/src/shell/backend.d.ts +28 -0
  32. package/dist/execution/src/shell/format.d.ts +2 -0
  33. package/dist/execution/src/shell/node-backend.d.ts +9 -0
  34. package/dist/execution/src/shell/output.d.ts +19 -0
  35. package/dist/execution/src/shell/process-session.d.ts +50 -0
  36. package/dist/execution/src/shell/results.d.ts +14 -0
  37. package/dist/execution/src/shell/session-manager.d.ts +46 -0
  38. package/dist/execution/src/shell/session-store.d.ts +53 -0
  39. package/dist/execution/src/shell/shell-args.d.ts +4 -0
  40. package/dist/execution/src/shell/shell.d.ts +14 -0
  41. package/dist/execution/src/shell/wait.d.ts +7 -0
  42. package/dist/execution/src/shell.d.ts +14 -0
  43. package/dist/execution/src/tool-contract.d.ts +34 -0
  44. package/dist/execution/src/tool-origin.d.ts +11 -0
  45. package/dist/execution/src/tool-source.d.ts +6 -0
  46. package/dist/execution/src/tool-value.d.ts +3 -0
  47. package/dist/execution/src/wait-session.d.ts +6 -0
  48. package/dist/history.js +315 -0
  49. package/dist/index.js +11718 -0
  50. package/dist/notebook/src/activation.d.ts +5 -0
  51. package/dist/notebook/src/binding-metadata-source.d.ts +2 -0
  52. package/dist/notebook/src/bridge-protocol.d.ts +29 -0
  53. package/dist/notebook/src/bridge-server.d.ts +20 -0
  54. package/dist/notebook/src/cell.d.ts +34 -0
  55. package/dist/notebook/src/checkpoint-activity.d.ts +7 -0
  56. package/dist/notebook/src/checkpoint-format.d.ts +32 -0
  57. package/dist/notebook/src/checkpoint-manager.d.ts +41 -0
  58. package/dist/notebook/src/checkpoint-runtime.d.ts +18 -0
  59. package/dist/notebook/src/checkpoint-store.d.ts +8 -0
  60. package/dist/notebook/src/checkpoint.d.ts +15 -0
  61. package/dist/notebook/src/client.d.ts +18 -0
  62. package/dist/notebook/src/command-output.d.ts +1 -0
  63. package/dist/notebook/src/control-contract.d.ts +5 -0
  64. package/dist/notebook/src/deno-archive.d.ts +2 -0
  65. package/dist/notebook/src/deno-assets.d.ts +11 -0
  66. package/dist/notebook/src/deno-binary.d.ts +6 -0
  67. package/dist/notebook/src/deno-syntax-diagnostics.d.ts +1 -0
  68. package/dist/notebook/src/directory-lock.d.ts +10 -0
  69. package/dist/notebook/src/engine.d.ts +21 -0
  70. package/dist/notebook/src/execution-runtime.d.ts +33 -0
  71. package/dist/notebook/src/execution-settlement.d.ts +15 -0
  72. package/dist/notebook/src/glob.d.ts +1 -0
  73. package/dist/notebook/src/history.d.ts +6 -0
  74. package/dist/notebook/src/index.d.ts +57 -0
  75. package/dist/notebook/src/isolated-runtime.d.ts +19 -0
  76. package/dist/notebook/src/isolated-storage.d.ts +2 -0
  77. package/dist/notebook/src/journal-document.d.ts +36 -0
  78. package/dist/notebook/src/journal.d.ts +37 -0
  79. package/dist/notebook/src/jupyter-connection.d.ts +17 -0
  80. package/dist/notebook/src/jupyter-execution.d.ts +29 -0
  81. package/dist/notebook/src/jupyter-kernel.d.ts +43 -0
  82. package/dist/notebook/src/jupyter-output.d.ts +32 -0
  83. package/dist/notebook/src/jupyter-shell.d.ts +18 -0
  84. package/dist/notebook/src/jupyter-socket.d.ts +17 -0
  85. package/dist/notebook/src/jupyter-wire.d.ts +16 -0
  86. package/dist/notebook/src/lifecycle-contract.d.ts +32 -0
  87. package/dist/notebook/src/lifecycle-inspection.d.ts +7 -0
  88. package/dist/notebook/src/lifecycle-pins.d.ts +10 -0
  89. package/dist/notebook/src/lifecycle-release.d.ts +12 -0
  90. package/dist/notebook/src/lifecycle-result.d.ts +43 -0
  91. package/dist/notebook/src/lifecycle-runtime.d.ts +35 -0
  92. package/dist/notebook/src/lifecycle.d.ts +13 -0
  93. package/dist/notebook/src/lsp-process.d.ts +23 -0
  94. package/dist/notebook/src/notebook-bootstrap.d.ts +1 -0
  95. package/dist/notebook/src/notebook-control.d.ts +26 -0
  96. package/dist/notebook/src/notebook-diagnostic-report.d.ts +25 -0
  97. package/dist/notebook/src/notebook-diagnostics.d.ts +10 -0
  98. package/dist/notebook/src/npm-imports.d.ts +10 -0
  99. package/dist/notebook/src/presentation.d.ts +3 -0
  100. package/dist/notebook/src/profile-lifecycle.d.ts +22 -0
  101. package/dist/notebook/src/profile-state-format.d.ts +36 -0
  102. package/dist/notebook/src/profile-state.d.ts +29 -0
  103. package/dist/notebook/src/project-identity.d.ts +1 -0
  104. package/dist/notebook/src/project-state-commit.d.ts +23 -0
  105. package/dist/notebook/src/project-state-conflicts.d.ts +7 -0
  106. package/dist/notebook/src/project-state-files.d.ts +9 -0
  107. package/dist/notebook/src/project-state-format.d.ts +80 -0
  108. package/dist/notebook/src/project-state-lock.d.ts +1 -0
  109. package/dist/notebook/src/project-state-merge.d.ts +31 -0
  110. package/dist/notebook/src/project-state-metadata.d.ts +20 -0
  111. package/dist/notebook/src/project-state-runtime.d.ts +13 -0
  112. package/dist/notebook/src/project-state.d.ts +18 -0
  113. package/dist/notebook/src/recovery.d.ts +28 -0
  114. package/dist/notebook/src/runtime-contract.d.ts +117 -0
  115. package/dist/notebook/src/runtime-health.d.ts +9 -0
  116. package/dist/notebook/src/session-identity.d.ts +2 -0
  117. package/dist/notebook/src/session-observations.d.ts +35 -0
  118. package/dist/notebook/src/session-runtime.d.ts +48 -0
  119. package/dist/notebook/src/session-startup.d.ts +23 -0
  120. package/dist/notebook/src/storage-retention.d.ts +21 -0
  121. package/dist/notebook/src/tool-callbacks.d.ts +20 -0
  122. package/dist/notebook/src/tool-observation.d.ts +21 -0
  123. package/dist/presentation.js +144 -0
  124. package/package.json +78 -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
- # Temporary Holding Version
1
+ # Notebook for Durable
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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.10.0/howaboua-pi-durable-notebook-0.10.0.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.