@howaboua/pi-durable-code 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 +251 -0
- package/README.md +93 -2
- package/dist/code/src/binary.d.ts +6 -0
- package/dist/code/src/cell-output.d.ts +33 -0
- package/dist/code/src/engine.d.ts +16 -0
- package/dist/code/src/history.d.ts +6 -0
- package/dist/code/src/host-assets.d.ts +4 -0
- package/dist/code/src/host-connection.d.ts +29 -0
- package/dist/code/src/host-process.d.ts +21 -0
- package/dist/code/src/host-protocol.d.ts +54 -0
- package/dist/code/src/host-runtime.d.ts +21 -0
- package/dist/code/src/host-session.d.ts +24 -0
- package/dist/code/src/index.d.ts +32 -0
- package/dist/code/src/install-host.d.ts +7 -0
- package/dist/code/src/presentation.d.ts +22 -0
- package/dist/code/src/result.d.ts +4 -0
- package/dist/code/src/runtime-contract.d.ts +24 -0
- package/dist/code/src/runtime-response.d.ts +2 -0
- package/dist/code/src/runtime-tools.d.ts +7 -0
- package/dist/execution/src/cell-contract.d.ts +49 -0
- package/dist/execution/src/cell-observation.d.ts +7 -0
- package/dist/execution/src/cell-progress.d.ts +4 -0
- package/dist/execution/src/cell-task.d.ts +17 -0
- package/dist/execution/src/cell-tools.d.ts +8 -0
- package/dist/execution/src/cells.d.ts +14 -0
- package/dist/execution/src/command-backend.d.ts +22 -0
- package/dist/execution/src/controls.d.ts +3 -0
- package/dist/execution/src/custom-command-config.d.ts +21 -0
- package/dist/execution/src/custom-commands.d.ts +62 -0
- package/dist/execution/src/exec-source.d.ts +21 -0
- package/dist/execution/src/forwarded-tools.d.ts +21 -0
- package/dist/execution/src/forwarding-hook.d.ts +6 -0
- package/dist/execution/src/forwarding.d.ts +15 -0
- package/dist/execution/src/history.d.ts +14 -0
- package/dist/execution/src/index.d.ts +6 -0
- package/dist/execution/src/invocation-state.d.ts +26 -0
- package/dist/execution/src/invocation.d.ts +35 -0
- package/dist/execution/src/native-tools.d.ts +11 -0
- package/dist/execution/src/nested-call.d.ts +26 -0
- package/dist/execution/src/nested-result.d.ts +8 -0
- package/dist/execution/src/nested.d.ts +3 -0
- package/dist/execution/src/output.d.ts +48 -0
- package/dist/execution/src/presentation.d.ts +59 -0
- package/dist/execution/src/progress.d.ts +23 -0
- package/dist/execution/src/projection.d.ts +5 -0
- package/dist/execution/src/shell/backend.d.ts +28 -0
- package/dist/execution/src/shell/format.d.ts +2 -0
- package/dist/execution/src/shell/node-backend.d.ts +9 -0
- package/dist/execution/src/shell/output.d.ts +19 -0
- package/dist/execution/src/shell/process-session.d.ts +50 -0
- package/dist/execution/src/shell/results.d.ts +14 -0
- package/dist/execution/src/shell/session-manager.d.ts +46 -0
- package/dist/execution/src/shell/session-store.d.ts +53 -0
- package/dist/execution/src/shell/shell-args.d.ts +4 -0
- package/dist/execution/src/shell/shell.d.ts +14 -0
- package/dist/execution/src/shell/wait.d.ts +7 -0
- package/dist/execution/src/shell.d.ts +14 -0
- package/dist/execution/src/tool-contract.d.ts +34 -0
- package/dist/execution/src/tool-origin.d.ts +11 -0
- package/dist/execution/src/tool-source.d.ts +6 -0
- package/dist/execution/src/tool-value.d.ts +3 -0
- package/dist/execution/src/wait-session.d.ts +6 -0
- package/dist/history.js +315 -0
- package/dist/index.js +5063 -0
- package/dist/presentation.js +198 -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,251 @@
|
|
|
1
|
+
Generic truncation recovery guidance follows Pi Stuff merged PR #552
|
|
2
|
+
revision 84bd5bce60a77c4298484d4b7c810d4fe5220a1b, retaining the MIT notices below.
|
|
3
|
+
|
|
4
|
+
Code Mode TypeScript protocol, process, session, installer, grammar, custom
|
|
5
|
+
command configuration and process execution code
|
|
6
|
+
adapted from @howaboua/pi-codex-conversion, revision
|
|
7
|
+
b2006db9def12c373ae48e70044d30f7d6b7e34f.
|
|
8
|
+
Official host assets, cancellation and help-backed discovery refreshed against
|
|
9
|
+
7f3295e67a8e6146b2a6922b56a06fa4db5c3a32, including local source commits.
|
|
10
|
+
Completed nested-call identities and successful-cell termination follow
|
|
11
|
+
3d0faf5a6f0bc67c0bd9248d07da6ddfa901b281.
|
|
12
|
+
Source: https://github.com/IgorWarzocha/howaboua-pi-stuff
|
|
13
|
+
Modifications: Durable-native lifecycle, ordinary-tool dispatch, original-name
|
|
14
|
+
projection, Node proxy transport, explicit host paths and cache location,
|
|
15
|
+
trusted-root command loading and namespace-bound command capabilities.
|
|
16
|
+
|
|
17
|
+
MIT License
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2026 Igor Warzocha
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
SOFTWARE.
|
|
38
|
+
|
|
39
|
+
Standalone runtime dependency: OpenAI Codex rust-v0.163.0,
|
|
40
|
+
commit 83086188ae0614bd882818ff1aa23f3194962012.
|
|
41
|
+
Source: https://github.com/openai/codex
|
|
42
|
+
The native host is provisioned separately. Its original notices follow.
|
|
43
|
+
|
|
44
|
+
OpenAI Codex
|
|
45
|
+
Copyright 2025 OpenAI
|
|
46
|
+
|
|
47
|
+
This project includes code derived from [Ratatui](https://github.com/ratatui/ratatui), licensed under the MIT license.
|
|
48
|
+
Copyright (c) 2016-2022 Florian Dehau
|
|
49
|
+
Copyright (c) 2023-2025 The Ratatui Developers
|
|
50
|
+
|
|
51
|
+
Apache License
|
|
52
|
+
Version 2.0, January 2004
|
|
53
|
+
http://www.apache.org/licenses/
|
|
54
|
+
|
|
55
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
56
|
+
|
|
57
|
+
1. Definitions.
|
|
58
|
+
|
|
59
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
60
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
61
|
+
|
|
62
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
63
|
+
the copyright owner that is granting the License.
|
|
64
|
+
|
|
65
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
66
|
+
other entities that control, are controlled by, or are under common
|
|
67
|
+
control with that entity. For the purposes of this definition,
|
|
68
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
69
|
+
direction or management of such entity, whether by contract or
|
|
70
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
71
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
72
|
+
|
|
73
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
74
|
+
exercising permissions granted by this License.
|
|
75
|
+
|
|
76
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
77
|
+
including but not limited to software source code, documentation
|
|
78
|
+
source, and configuration files.
|
|
79
|
+
|
|
80
|
+
"Object" form shall mean any form resulting from mechanical
|
|
81
|
+
transformation or translation of a Source form, including but
|
|
82
|
+
not limited to compiled object code, generated documentation,
|
|
83
|
+
and conversions to other media types.
|
|
84
|
+
|
|
85
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
86
|
+
Object form, made available under the License, as indicated by a
|
|
87
|
+
copyright notice that is included in or attached to the work
|
|
88
|
+
(an example is provided in the Appendix below).
|
|
89
|
+
|
|
90
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
91
|
+
form, that is based on (or derived from) the Work and for which the
|
|
92
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
93
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
94
|
+
of this License, Derivative Works shall not include works that remain
|
|
95
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
96
|
+
the Work and Derivative Works thereof.
|
|
97
|
+
|
|
98
|
+
"Contribution" shall mean any work of authorship, including
|
|
99
|
+
the original version of the Work and any modifications or additions
|
|
100
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
101
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
102
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
103
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
104
|
+
means any form of electronic, verbal, or written communication sent
|
|
105
|
+
to the Licensor or its representatives, including but not limited to
|
|
106
|
+
communication on electronic mailing lists, source code control systems,
|
|
107
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
108
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
109
|
+
excluding communication that is conspicuously marked or otherwise
|
|
110
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
111
|
+
|
|
112
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
113
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
114
|
+
subsequently incorporated within the Work.
|
|
115
|
+
|
|
116
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
117
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
118
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
119
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
120
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
121
|
+
Work and such Derivative Works in Source or Object form.
|
|
122
|
+
|
|
123
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
124
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
125
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
126
|
+
(except as stated in this section) patent license to make, have made,
|
|
127
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
128
|
+
where such license applies only to those patent claims licensable
|
|
129
|
+
by such Contributor that are necessarily infringed by their
|
|
130
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
131
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
132
|
+
institute patent litigation against any entity (including a
|
|
133
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
134
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
135
|
+
or contributory patent infringement, then any patent licenses
|
|
136
|
+
granted to You under this License for that Work shall terminate
|
|
137
|
+
as of the date such litigation is filed.
|
|
138
|
+
|
|
139
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
140
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
141
|
+
modifications, and in Source or Object form, provided that You
|
|
142
|
+
meet the following conditions:
|
|
143
|
+
|
|
144
|
+
(a) You must give any other recipients of the Work or
|
|
145
|
+
Derivative Works a copy of this License; and
|
|
146
|
+
|
|
147
|
+
(b) You must cause any modified files to carry prominent notices
|
|
148
|
+
stating that You changed the files; and
|
|
149
|
+
|
|
150
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
151
|
+
that You distribute, all copyright, patent, trademark, and
|
|
152
|
+
attribution notices from the Source form of the Work,
|
|
153
|
+
excluding those notices that do not pertain to any part of
|
|
154
|
+
the Derivative Works; and
|
|
155
|
+
|
|
156
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
157
|
+
distribution, then any Derivative Works that You distribute must
|
|
158
|
+
include a readable copy of the attribution notices contained
|
|
159
|
+
within such NOTICE file, excluding those notices that do not
|
|
160
|
+
pertain to any part of the Derivative Works, in at least one
|
|
161
|
+
of the following places: within a NOTICE text file distributed
|
|
162
|
+
as part of the Derivative Works; within the Source form or
|
|
163
|
+
documentation, if provided along with the Derivative Works; or,
|
|
164
|
+
within a display generated by the Derivative Works, if and
|
|
165
|
+
wherever such third-party notices normally appear. The contents
|
|
166
|
+
of the NOTICE file are for informational purposes only and
|
|
167
|
+
do not modify the License. You may add Your own attribution
|
|
168
|
+
notices within Derivative Works that You distribute, alongside
|
|
169
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
170
|
+
that such additional attribution notices cannot be construed
|
|
171
|
+
as modifying the License.
|
|
172
|
+
|
|
173
|
+
You may add Your own copyright statement to Your modifications and
|
|
174
|
+
may provide additional or different license terms and conditions
|
|
175
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
176
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
177
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
178
|
+
the conditions stated in this License.
|
|
179
|
+
|
|
180
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
181
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
182
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
183
|
+
this License, without any additional terms or conditions.
|
|
184
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
185
|
+
the terms of any separate license agreement you may have executed
|
|
186
|
+
with Licensor regarding such Contributions.
|
|
187
|
+
|
|
188
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
189
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
190
|
+
except as required for reasonable and customary use in describing the
|
|
191
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
192
|
+
|
|
193
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
194
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
195
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
196
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
197
|
+
implied, including, without limitation, any warranties or conditions
|
|
198
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
199
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
200
|
+
appropriateness of using or redistributing the Work and assume any
|
|
201
|
+
risks associated with Your exercise of permissions under this License.
|
|
202
|
+
|
|
203
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
204
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
205
|
+
unless required by applicable law (such as deliberate and grossly
|
|
206
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
207
|
+
liable to You for damages, including any direct, indirect, special,
|
|
208
|
+
incidental, or consequential damages of any character arising as a
|
|
209
|
+
result of this License or out of the use or inability to use the
|
|
210
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
211
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
212
|
+
other commercial damages or losses), even if such Contributor
|
|
213
|
+
has been advised of the possibility of such damages.
|
|
214
|
+
|
|
215
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
216
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
217
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
218
|
+
or other liability obligations and/or rights consistent with this
|
|
219
|
+
License. However, in accepting such obligations, You may act only
|
|
220
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
221
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
222
|
+
defend, and hold each Contributor harmless for any liability
|
|
223
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
224
|
+
of your accepting any such warranty or additional liability.
|
|
225
|
+
|
|
226
|
+
END OF TERMS AND CONDITIONS
|
|
227
|
+
|
|
228
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
229
|
+
|
|
230
|
+
To apply the Apache License to your work, attach the following
|
|
231
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
232
|
+
replaced with your own identifying information. (Don't include
|
|
233
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
234
|
+
comment syntax for the file format. We also recommend that a
|
|
235
|
+
file or class name and description of purpose be included on the
|
|
236
|
+
same "printed page" as the copyright notice for easier
|
|
237
|
+
identification within third-party archives.
|
|
238
|
+
|
|
239
|
+
Copyright 2025 OpenAI
|
|
240
|
+
|
|
241
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
242
|
+
you may not use this file except in compliance with the License.
|
|
243
|
+
You may obtain a copy of the License at
|
|
244
|
+
|
|
245
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
246
|
+
|
|
247
|
+
Unless required by applicable law or agreed to in writing, software
|
|
248
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
249
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
250
|
+
See the License for the specific language governing permissions and
|
|
251
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,94 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Code Mode for Durable
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run JavaScript that composes ordinary Durable tools. `exec` and `wait` are the model-facing surface. Shell execution and PTY sessions 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-code-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
|
+
Create the component before opening your harness, install its extension, and select that extension in the conversation.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Harness, createRegistry } from "@earendil-works/pi-durable";
|
|
17
|
+
import { createCodeMode, createNodeShellBackend } from "@howaboua/pi-durable-code";
|
|
18
|
+
|
|
19
|
+
let harness: Harness;
|
|
20
|
+
const code = createCodeMode({
|
|
21
|
+
shell: { backend: createNodeShellBackend({ environmentId: "local" }) },
|
|
22
|
+
cancelTask: (id, context) => harness.abortTask(id, context),
|
|
23
|
+
});
|
|
24
|
+
const registry = createRegistry();
|
|
25
|
+
registry.install(code.extension);
|
|
26
|
+
// Install your other extensions in the same registry.
|
|
27
|
+
harness = await Harness.open(storage, { models, registry, env }, context);
|
|
28
|
+
code.bind(harness);
|
|
29
|
+
const conversation = await harness.root(context, {
|
|
30
|
+
agent: { model, extensions: [code.extension, otherExtension] },
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`storage`, `models`, `model`, `env`, and `context` are your normal Durable setup. The shell backend's `environmentId` must equal your execution environment's `id`. A sandbox or remote environment needs a backend for that environment. No operation silently uses local shell execution instead.
|
|
35
|
+
|
|
36
|
+
An agent can now use JavaScript such as `text(await tools.some_tool({ ... }))`. Installed tools need no Code-specific adapter. `ALL_TOOLS` contains their original names, usage, descriptions, and input schemas. Names with punctuation remain callable through `tools[name]`.
|
|
37
|
+
|
|
38
|
+
Registrations with `executionHints.nativeOnly: true` remain native model tools and cannot be called inside cells. Binding the Harness enables this projection using the conversation's selected tools. Context management uses it for `new_context`.
|
|
39
|
+
|
|
40
|
+
Tool results expose meaningful `details` together with their result content. Empty details fall back to parsed JSON text or unchanged text. Images add a base64 `image_url` suitable for `image(result)` and `generatedImage(result)`. Tool failures throw in JavaScript. Durable still owns validation, wrappers, hooks, usage accounting, cancellation, and unsafe-operation recovery.
|
|
41
|
+
|
|
42
|
+
## Custom commands
|
|
43
|
+
|
|
44
|
+
Existing custom-tool TOML definitions are supported. Supply the directories and their trust decisions explicitly. The package never scans Pi's home directory or enables bundled examples.
|
|
45
|
+
|
|
46
|
+
The same custom-command factories are available from the separate Notebook package. Both packages use one internal implementation and register ordinary Durable tools.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { createCustomCommands, createNodeCommandBackend } from "@howaboua/pi-durable-code";
|
|
50
|
+
|
|
51
|
+
const commands = await createCustomCommands({
|
|
52
|
+
registry,
|
|
53
|
+
files: env,
|
|
54
|
+
backend: createNodeCommandBackend({ environmentId: env.id }),
|
|
55
|
+
roots: [
|
|
56
|
+
{ path: globalCommands, trusted: true },
|
|
57
|
+
{ path: projectCommands, trusted: projectIsTrusted },
|
|
58
|
+
],
|
|
59
|
+
onDiscoveryError: error => console.error(error.message),
|
|
60
|
+
}, context);
|
|
61
|
+
// Select commands.extension alongside code.extension in the conversation.
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Later trusted directories override earlier ones. Invalid overrides remain disabled instead of falling back to a different global command. Untrusted directories are not read.
|
|
65
|
+
|
|
66
|
+
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`. Every command accepts one string and returns one string. Relative command paths resolve from the TOML directory. Absolute JavaScript files run through the backend's JavaScript launcher. Bare commands resolve through that backend's `PATH`. Commands run directly without shell expansion, in the conversation's working directory.
|
|
67
|
+
|
|
68
|
+
`input` is `"arg"` by default or `"stdin"`. 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.
|
|
69
|
+
|
|
70
|
+
Definitions are reread before execution. The live loader refreshes ordinary registry registrations before model requests, so additions, removals, and metadata changes appear in `ALL_TOOLS`. `defer_loading = false` promotes only the current usage line into the Code prompt. `yield_time_ms` overrides the initial exec wait when source directly calls that tool. Multiple direct calls use the largest configured value.
|
|
71
|
+
|
|
72
|
+
`loadCustomCommandTools(options, context)` provides a snapshot loader instead when the host wants to publish registry updates itself. `commands.errors` exposes discovery errors. Call `await commands.close()` when removing the live loader.
|
|
73
|
+
|
|
74
|
+
## Runtime boundaries
|
|
75
|
+
|
|
76
|
+
The component automatically downloads the standalone OpenAI Codex V8 host pinned to `rust-v0.163.0`. Downloads are checksum verified. Supported platforms are Linux, macOS, and Windows on x64 and ARM64. `hostPath` selects an explicitly provisioned compatible host. `cacheDirectory` changes the download cache. Unix automatic installation needs `tar`.
|
|
77
|
+
|
|
78
|
+
Each cell has a fresh isolated V8 context with text, image, notification, timer, yield, and exit helpers. It has no filesystem, network, Node globals, or arbitrary imports. Use ordinary tools for those capabilities. `store(key, value)` and `load(key)` retain serializable data within one conversation's live host session. Lexical bindings do not survive between Code cells. Use the separate Notebook package when you need persistent bindings and imports.
|
|
79
|
+
|
|
80
|
+
Yielded cells remain owned by the conversation. `wait` observes the existing cell. Its output budget applies to that delivery, not the cell's accumulated lifetime. One bounded observation is retained until delivered, then native output collection continues. Termination cancels owned nested calls and interrupts V8. Interrupted work is reported rather than replayed after a process restart. Native host state and PTYs do not survive that restart.
|
|
81
|
+
|
|
82
|
+
Call `await code.close()` when disposing the component, then close your harness. This stops native hosts and shell sessions.
|
|
83
|
+
|
|
84
|
+
If the native host exits unexpectedly, interrupted output remains observable. Recreate the component before running new cells. The package does not silently replace a lost session with an empty one.
|
|
85
|
+
|
|
86
|
+
## Headless presentations
|
|
87
|
+
|
|
88
|
+
`@howaboua/pi-durable-code/presentation` exports `codeCapability`, `codeSummary` and `codeDetail`. These browser-safe descriptors are structurally compatible with the UI SDK without importing it. They perform no I/O and have no renderer.
|
|
89
|
+
|
|
90
|
+
The host supplies `{cell, result}`. Each field is explicitly nullable. A cell is `{id, status}`, with a canonical positive decimal task ID and the actual coordinator status: `running`, `completed`, `failed`, `aborted` or `interrupted`. Read these from exec/wait receipt details `cellId` and `status`. Do not substitute host request activity for cell lifecycle.
|
|
91
|
+
|
|
92
|
+
`result: null` means output has not been acquired. Otherwise pass the ordinary execution receipt. Parsing retains text, base64 images, `isError`, JSON details and structured diagnostics. Omitted fields normalize to empty content, false, null and empty diagnostics. Usage and controls remain Durable-owned, not presentation actions. Summary selects title, cell identity and status, output availability and nullable `isError`. Detail selects the full validated state. Summary can request detail without acquiring it.
|
|
93
|
+
|
|
94
|
+
The host authorizes `exec` and `wait` through ordinary registrations and publishes acquired receipts on the declared `results` stream. This is host publication, not a new runtime stream or tool bridge. Each receipt is one bounded observation, not cumulative output. Presentation disposal does not terminate cells, roll back effects or authorize replay. Acquisition, binding and cancellation policy belong to the host.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
2
|
+
import type { CellObservation } from "../../execution/src/index.ts";
|
|
3
|
+
import type { RuntimeResponse } from "./runtime-contract.ts";
|
|
4
|
+
/** One observation window, including delivery backpressure and bounded diagnostic traces. */
|
|
5
|
+
export declare class CodeCellOutput {
|
|
6
|
+
private readonly maxTokens;
|
|
7
|
+
private delivery;
|
|
8
|
+
private readonly output;
|
|
9
|
+
private remainingChars;
|
|
10
|
+
private imageChars;
|
|
11
|
+
private imageCount;
|
|
12
|
+
private omittedImages;
|
|
13
|
+
private truncated;
|
|
14
|
+
private revision;
|
|
15
|
+
private readonly notifications;
|
|
16
|
+
private append;
|
|
17
|
+
private readonly traces;
|
|
18
|
+
private droppedTraceCount;
|
|
19
|
+
private current;
|
|
20
|
+
constructor(maxTokens: number);
|
|
21
|
+
result(): ToolExecutionResult;
|
|
22
|
+
notify(text: string): void;
|
|
23
|
+
trace(id: string, name: string, input: unknown): {
|
|
24
|
+
done(result: ToolExecutionResult, callId: string): void;
|
|
25
|
+
failed(error: unknown): void;
|
|
26
|
+
};
|
|
27
|
+
replaceObservation(response: RuntimeResponse): void;
|
|
28
|
+
get hasOutput(): boolean;
|
|
29
|
+
get delivered(): Promise<void>;
|
|
30
|
+
acknowledge(revision: number): boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Project one acknowledged durable snapshot with the caller's own output budget. */
|
|
33
|
+
export declare function observeCodeCell(observation: CellObservation, maxTokens: number, acknowledge: (taskId: number, revision: number) => boolean): ToolExecutionResult;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Context } from "@earendil-works/chord";
|
|
2
|
+
import type { JsonObject, ToolExecutionResult } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { CellEngine, CellEngineApi } from "../../execution/src/cell-contract.ts";
|
|
4
|
+
import { type HostOptions } from "./binary.ts";
|
|
5
|
+
/** One host session per conversation. Store/load cannot cross conversation boundaries. */
|
|
6
|
+
export declare class CodeEngine implements CellEngine {
|
|
7
|
+
private readonly sessions;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private readonly deliveries;
|
|
10
|
+
private closed;
|
|
11
|
+
constructor(options?: HostOptions);
|
|
12
|
+
run(input: JsonObject, api: CellEngineApi, context: Context): Promise<ToolExecutionResult>;
|
|
13
|
+
/** Ack only the exact snapshot delivered. Repeated running observations must not repeat its content. */
|
|
14
|
+
acknowledge(taskId: number, revision: number): boolean;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { ExecutionHistoryRequest } from "../../execution/src/history.ts";
|
|
2
|
+
export declare const readForwardedToolCalls: (harness: {
|
|
3
|
+
conversation: (id: import("@earendil-works/pi-durable").ConversationId, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").Conversation | undefined>;
|
|
4
|
+
getTask: <R>(id: import("@earendil-works/pi-durable").TaskId<R>, context: import("@earendil-works/chord").Context) => Promise<import("@earendil-works/pi-durable").TaskRecord<import("@earendil-works/chord").JsonValue, import("@earendil-works/chord").JsonValue, R> | undefined>;
|
|
5
|
+
commit: <T>(change: (tx: import("@earendil-works/pi-durable").Tx) => T | Promise<T>, context: import("@earendil-works/chord").Context) => Promise<T>;
|
|
6
|
+
}, request: import("../../execution/src/history.ts").ExecutionHistoryRequest, context: import("@earendil-works/chord").Context) => Promise<ReadonlyMap<string, import("./presentation.ts").ForwardedToolCalls>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const HOST_RELEASE = "rust-v0.163.0";
|
|
2
|
+
export declare function codeModeHostBinaryName(platform: string): string;
|
|
3
|
+
export declare function resolveCodeModeHostAsset(platform: string, arch: string): readonly [string, string];
|
|
4
|
+
export declare function hostAssetUrl(assetName: string): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type HostMessage } from "./host-protocol.ts";
|
|
2
|
+
type HostConnectionOptions = {
|
|
3
|
+
binary: string;
|
|
4
|
+
onMessage: (message: HostMessage) => void;
|
|
5
|
+
onFailure: (error: Error) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare class CodeModeHostConnection {
|
|
8
|
+
private readonly process;
|
|
9
|
+
private readonly onMessage;
|
|
10
|
+
private readonly onFailure;
|
|
11
|
+
private requestId;
|
|
12
|
+
private ready;
|
|
13
|
+
private pending;
|
|
14
|
+
private initial;
|
|
15
|
+
constructor(options: HostConnectionOptions);
|
|
16
|
+
get running(): boolean;
|
|
17
|
+
nextRequestId(): number;
|
|
18
|
+
start(): Promise<void>;
|
|
19
|
+
private startProcess;
|
|
20
|
+
request(request: Record<string, unknown>, onValue?: (value: unknown) => void): Promise<unknown>;
|
|
21
|
+
requestWithId(id: number, request: Record<string, unknown>, onValue?: (value: unknown) => void): Promise<unknown>;
|
|
22
|
+
expectInitial(id: number): Promise<unknown>;
|
|
23
|
+
send(message: unknown): void;
|
|
24
|
+
rejectOperation(id: number, error: Error): void;
|
|
25
|
+
close(error: Error): void;
|
|
26
|
+
private handleMessage;
|
|
27
|
+
private failAll;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type HostProcessOptions = {
|
|
2
|
+
binary: string;
|
|
3
|
+
onMessage: (message: unknown) => void;
|
|
4
|
+
onFailure: (error: Error) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare class CodeModeHostProcess {
|
|
7
|
+
private readonly binary;
|
|
8
|
+
private readonly onMessage;
|
|
9
|
+
private readonly onFailure;
|
|
10
|
+
private child;
|
|
11
|
+
private buffer;
|
|
12
|
+
private stderr;
|
|
13
|
+
private queuedWriteBytes;
|
|
14
|
+
constructor(options: HostProcessOptions);
|
|
15
|
+
get running(): boolean;
|
|
16
|
+
start(): void;
|
|
17
|
+
send(message: unknown): void;
|
|
18
|
+
kill(): void;
|
|
19
|
+
private onData;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type HostMessage = {
|
|
2
|
+
type: "connection/ready";
|
|
3
|
+
selectedVersion: 1;
|
|
4
|
+
capabilities: string[];
|
|
5
|
+
} | {
|
|
6
|
+
type: "connection/rejected";
|
|
7
|
+
reason: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
type: "operation/response";
|
|
10
|
+
id: number;
|
|
11
|
+
result: HostResult;
|
|
12
|
+
} | {
|
|
13
|
+
type: "execute/initialResponse";
|
|
14
|
+
id: number;
|
|
15
|
+
result: HostResult;
|
|
16
|
+
} | ({
|
|
17
|
+
type: "delegate/request";
|
|
18
|
+
} & DelegateRequestMessage) | {
|
|
19
|
+
type: "delegate/cancel";
|
|
20
|
+
id: number;
|
|
21
|
+
} | {
|
|
22
|
+
type: "cell/closed";
|
|
23
|
+
cellId: string;
|
|
24
|
+
};
|
|
25
|
+
export interface DelegateRequestMessage {
|
|
26
|
+
id: number;
|
|
27
|
+
request: {
|
|
28
|
+
type: "notification/send";
|
|
29
|
+
cellId: string;
|
|
30
|
+
text: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "tool/invoke";
|
|
33
|
+
invocation: {
|
|
34
|
+
cell_id: string;
|
|
35
|
+
input?: unknown;
|
|
36
|
+
runtime_tool_call_id: string;
|
|
37
|
+
tool_name: {
|
|
38
|
+
name: string;
|
|
39
|
+
namespace?: string | undefined;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
type HostResult = {
|
|
45
|
+
status: "ok";
|
|
46
|
+
value: unknown;
|
|
47
|
+
} | {
|
|
48
|
+
status: "error";
|
|
49
|
+
message: string;
|
|
50
|
+
};
|
|
51
|
+
export declare function parseHostMessage(value: unknown): HostMessage;
|
|
52
|
+
export declare function executionCellId(value: unknown): string | undefined;
|
|
53
|
+
export declare function runtimeOutcome(value: unknown): unknown;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RuntimeCallbacks, RuntimeResponse, RuntimeTool } from "./runtime-contract.ts";
|
|
2
|
+
/** Standalone pinned V8 host. No filesystem, network or process capability enters the isolate. */
|
|
3
|
+
export declare class CodeHostRuntime {
|
|
4
|
+
private readonly session;
|
|
5
|
+
private readonly cells;
|
|
6
|
+
private readonly delegates;
|
|
7
|
+
private closed;
|
|
8
|
+
private failure;
|
|
9
|
+
private readonly failureController;
|
|
10
|
+
get failureSignal(): AbortSignal;
|
|
11
|
+
constructor(binary: string);
|
|
12
|
+
execute(source: string, tools: readonly RuntimeTool[], callbacks: RuntimeCallbacks, signal?: AbortSignal, onStarted?: (cellId: string) => void, yieldTimeMsOverride?: number): Promise<RuntimeResponse>;
|
|
13
|
+
wait(cellId: string, yieldTimeMs?: number, signal?: AbortSignal): Promise<RuntimeResponse>;
|
|
14
|
+
terminate(cellId: string): Promise<RuntimeResponse>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
private clear;
|
|
17
|
+
private cancelCell;
|
|
18
|
+
private handle;
|
|
19
|
+
private invoke;
|
|
20
|
+
private respond;
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HostMessage } from "./host-protocol.ts";
|
|
2
|
+
type HostSessionOptions = {
|
|
3
|
+
binary: string;
|
|
4
|
+
shutdownGraceMs?: number | undefined;
|
|
5
|
+
onMessage: (message: HostMessage) => void;
|
|
6
|
+
onFailure: (error: Error) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare class CodeModeHostSession {
|
|
9
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
10
|
+
private readonly connection;
|
|
11
|
+
private readonly shutdownGraceMs;
|
|
12
|
+
private readonly onFailure;
|
|
13
|
+
private ready;
|
|
14
|
+
constructor(options: HostSessionOptions);
|
|
15
|
+
start(): Promise<void>;
|
|
16
|
+
private startSession;
|
|
17
|
+
nextRequestId(): number;
|
|
18
|
+
expectInitial(id: number): Promise<unknown>;
|
|
19
|
+
requestWithId(id: number, request: Record<string, unknown>, onValue?: (value: unknown) => void): Promise<unknown>;
|
|
20
|
+
send(message: unknown): void;
|
|
21
|
+
rejectOperation(id: number, error: Error): void;
|
|
22
|
+
shutdown(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CellCoordinatorOptions } from "../../execution/src/index.ts";
|
|
2
|
+
import { type ShellRuntimeOptions } from "../../execution/src/shell.ts";
|
|
3
|
+
import type { HostOptions } from "./binary.ts";
|
|
4
|
+
export type { CustomCommandBackend, CustomCommandRequest, NodeCommandBackendOptions, } from "../../execution/src/command-backend.ts";
|
|
5
|
+
export { createNodeCommandBackend } from "../../execution/src/command-backend.ts";
|
|
6
|
+
export type { CustomCommandDefinition, CustomCommandParseOptions, } from "../../execution/src/custom-command-config.ts";
|
|
7
|
+
export { parseCustomCommand } from "../../execution/src/custom-command-config.ts";
|
|
8
|
+
export type { CustomCommandDiscovery, CustomCommandDiscoveryError, CustomCommandOptions, CustomCommandRoot, LiveCustomCommandOptions, } from "../../execution/src/custom-commands.ts";
|
|
9
|
+
export { createCustomCommands, discoverCustomCommands, loadCustomCommandTools, } from "../../execution/src/custom-commands.ts";
|
|
10
|
+
export { CODE_MODE_EXEC_CONSTRAINED_SAMPLING, CODE_MODE_EXEC_GRAMMAR, } from "../../execution/src/exec-source.ts";
|
|
11
|
+
export type { NodeShellBackendOptions, ShellOutputStream, ShellProcess, ShellProcessBackend, ShellProcessEvents, ShellRuntimeOptions, ShellSpawnRequest, } from "../../execution/src/shell.ts";
|
|
12
|
+
export { createNodeShellBackend } from "../../execution/src/shell.ts";
|
|
13
|
+
export type { ExecutionToolHints, ExecutionToolRegistration, } from "../../execution/src/tool-contract.ts";
|
|
14
|
+
export interface CodeModeOptions extends HostOptions {
|
|
15
|
+
shell: ShellRuntimeOptions;
|
|
16
|
+
cancelTask: CellCoordinatorOptions["cancelTask"];
|
|
17
|
+
}
|
|
18
|
+
/** Public Code product. Ordinary tools are discovered from the selected Durable registry. */
|
|
19
|
+
export declare function createCodeMode(options: CodeModeOptions): {
|
|
20
|
+
/** Bind the same Harness that owns this extension to retain native-only provider tools. */
|
|
21
|
+
/** Bind the owning Harness before execution to retain native nested display receipts. */
|
|
22
|
+
bind: (harness: Pick<import("@earendil-works/pi-durable").Harness, "conversation">) => void;
|
|
23
|
+
extension: {
|
|
24
|
+
name: string;
|
|
25
|
+
hooks?: readonly import("@earendil-works/pi-durable").HookRegistration[];
|
|
26
|
+
wraps?: readonly import("@earendil-works/pi-durable").Wrap<import("@earendil-works/pi-durable").ToolRegistration>[];
|
|
27
|
+
tasks?: readonly import("@earendil-works/pi-durable").AnyTask[];
|
|
28
|
+
tools: import("@earendil-works/pi-durable").ToolRegistration[];
|
|
29
|
+
sections: import("@earendil-works/pi-durable").PromptSection<import("@earendil-works/pi-durable").ToolRegistration>[];
|
|
30
|
+
};
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
};
|