@tlockney/cdp-kernel 0.3.0 → 0.5.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.
- package/README.md +60 -404
- package/THIRD-PARTY-NOTICES +62 -0
- package/dist/bun-target.d.ts +4 -2
- package/dist/bun-target.js +35 -8
- package/dist/cdp.d.ts +6 -1
- package/dist/cdp.js +25 -10
- package/dist/celld-target.d.ts +1 -1
- package/dist/celld-target.js +46 -8
- package/dist/children.d.ts +7 -0
- package/dist/children.js +32 -0
- package/dist/debugger.d.ts +42 -0
- package/dist/debugger.js +545 -0
- package/dist/globals.d.ts +3 -3
- package/dist/globals.js +3 -3
- package/dist/history.d.ts +18 -0
- package/dist/history.js +45 -0
- package/dist/kernel.js +211 -32
- package/dist/main.js +3 -1
- package/dist/mod.d.ts +5 -3
- package/dist/mod.js +5 -3
- package/dist/murmur2.d.ts +2 -0
- package/dist/murmur2.js +41 -0
- package/dist/package.d.ts +16 -2
- package/dist/package.js +26 -3
- package/dist/sourcemap.d.ts +22 -0
- package/dist/sourcemap.js +86 -0
- package/dist/target.d.ts +39 -3
- package/dist/target.js +281 -30
- package/dist/text.d.ts +11 -1
- package/dist/text.js +72 -2
- package/dist/transform.d.ts +19 -0
- package/dist/transform.js +74 -13
- package/dist/wire.d.ts +8 -1
- package/dist/wire.js +3 -1
- package/dist/workerd-target.d.ts +9 -1
- package/dist/workerd-target.js +108 -9
- package/dist/ws-client.d.ts +5 -1
- package/dist/ws-client.js +46 -13
- package/dist/zmtp.d.ts +7 -1
- package/dist/zmtp.js +30 -1
- package/package.json +10 -4
- package/runtime/bootstrap.mjs +138 -12
- package/runtime/bun-channel.d.mts +3 -0
- package/runtime/bun-channel.mjs +2 -2
- package/runtime/comm.mjs +11 -1
- package/runtime/deno-compat.d.mts +2 -0
- package/runtime/deno-compat.mjs +17 -2
- package/runtime/display.d.mts +2 -0
- package/runtime/display.mjs +17 -2
- package/runtime/evaluator.d.mts +4 -0
- package/runtime/evaluator.mjs +8 -0
- package/runtime/introspect.d.mts +13 -0
- package/runtime/introspect.mjs +120 -0
- package/runtime/node-hooks.d.mts +61 -1
- package/runtime/node-hooks.mjs +354 -21
- package/runtime/workerd-worker.mjs +82 -6
package/README.md
CHANGED
|
@@ -1,430 +1,86 @@
|
|
|
1
1
|
# cdp-kernel
|
|
2
2
|
|
|
3
|
-
A Jupyter kernel
|
|
4
|
-
|
|
5
|
-
Node or Deno; the code you type runs in a separate **target**
|
|
6
|
-
Node or Deno over
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
A Jupyter kernel for TypeScript and JavaScript, extracted from the one built
|
|
4
|
+
into Deno 2.9.6 (`deno jupyter`), that runs notebooks on several JavaScript runtimes. The kernel
|
|
5
|
+
host runs on Node or Deno; the code you type runs in a separate **target**
|
|
6
|
+
runtime: Node or Deno over the Chrome DevTools Protocol, or Bun, workerd and
|
|
7
|
+
celld, which evaluate cells in-process. In principle, anything else whose
|
|
8
|
+
inspector speaks CDP works too.
|
|
9
|
+
|
|
10
|
+
**Website:** <https://cdp-kernel.org/> ·
|
|
11
|
+
**Docs:** [cdp-kernel.org/docs](https://cdp-kernel.org/docs/)
|
|
9
12
|
|
|
10
13
|
This is early software. It passes a conformance suite derived from Deno's
|
|
11
14
|
own Jupyter integration tests on every target, and it's packaged for npm and
|
|
12
|
-
JSR as `@tlockney/cdp-kernel`, but it hasn't seen much real use yet.
|
|
13
|
-
feasibility study behind it covers the design,
|
|
14
|
-
the other options considered (workerd, Bun, rusty_v8, FFI), and the
|
|
15
|
-
evidence: [read it online](https://claude.ai/artifact/S66TnTmhCzPy2EW7jbeeue)
|
|
16
|
-
(also in the repo as
|
|
17
|
-
[`docs/life-after-deno-jupyter.html`](docs/life-after-deno-jupyter.html)). It
|
|
18
|
-
was written before packaging, so it calls the project a spike.
|
|
19
|
-
The scripts that produced its runtime findings are in [`probes/`](probes/).
|
|
20
|
-
|
|
21
|
-
## Why this shape
|
|
22
|
-
|
|
23
|
-
Deno 2.9's kernel is already two halves joined by thirteen ops
|
|
24
|
-
(denoland/deno#34083 rewrote it in JS and dropped libzmq):
|
|
25
|
-
|
|
26
|
-
- `cli/js/jupyter_kernel.js`: ZMTP and the Jupyter wire protocol in plain
|
|
27
|
-
JS over TCP.
|
|
28
|
-
- A REPL isolate driven by CDP calls: `Runtime.evaluate` with
|
|
29
|
-
`replMode: true`, `callFunctionOn`, `getProperties`,
|
|
30
|
-
`globalLexicalScopeNames`.
|
|
15
|
+
JSR as `@tlockney/cdp-kernel`, but it hasn't seen much real use yet.
|
|
31
16
|
|
|
32
|
-
|
|
17
|
+
## Features
|
|
33
18
|
|
|
34
|
-
-
|
|
35
|
-
`
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
(`
|
|
40
|
-
-
|
|
19
|
+
- The `Deno.jupyter` display API (`jupyter.display`, `md`, `html`, `svg`,
|
|
20
|
+
`image`, …) on every target.
|
|
21
|
+
- TypeScript, TSX, top-level `await`, and `npm:`/`jsr:` imports, with an
|
|
22
|
+
optional lockfile.
|
|
23
|
+
- Deno projects (`deno.json` import maps, JSX settings) and Workers
|
|
24
|
+
projects (`wrangler` bindings in `env`).
|
|
25
|
+
- JupyterLab's visual debugger on Node and Deno targets.
|
|
26
|
+
- anywidget-style widgets and Jupyter comms.
|
|
27
|
+
- `prompt()` and `confirm()`, interrupt that keeps state, Shift-Tab
|
|
28
|
+
inspection, completion and history.
|
|
41
29
|
|
|
42
30
|
## Install
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
`cdp-node-deno` (Node with the Deno compatibility namespace), `cdp-bun`,
|
|
46
|
-
`cdp-workerd`, or `cdp-celld`. Then pick the kernel in JupyterLab or VS Code.
|
|
47
|
-
|
|
48
|
-
**From npm** (host runs on Node 24+; Node 26 is what's been tested):
|
|
32
|
+
Node 24+ host, from npm:
|
|
49
33
|
|
|
50
34
|
```sh
|
|
51
35
|
npm install -g @tlockney/cdp-kernel
|
|
52
|
-
cdp-kernel install --runtime node
|
|
53
|
-
cdp-kernel install --runtime deno
|
|
54
|
-
cdp-kernel install --runtime node --deno-compat
|
|
55
|
-
cdp-kernel install --runtime bun
|
|
56
|
-
cdp-kernel install --runtime workerd
|
|
57
|
-
cdp-kernel install --runtime celld
|
|
36
|
+
cdp-kernel install --runtime node # or deno, bun, workerd, celld
|
|
58
37
|
```
|
|
59
38
|
|
|
60
|
-
|
|
61
|
-
package. Re-run `install` after upgrading either.
|
|
62
|
-
|
|
63
|
-
**From JSR** (host runs on Deno):
|
|
39
|
+
Deno host, from JSR:
|
|
64
40
|
|
|
65
41
|
```sh
|
|
66
42
|
deno run -A jsr:@tlockney/cdp-kernel/cli install --runtime deno
|
|
67
43
|
```
|
|
68
44
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
directory's `node_modules` (a Workers project has one through wrangler),
|
|
75
|
-
or the one on `PATH` (`npm install -g workerd`; 2026-10-15 is what's been
|
|
76
|
-
tested). A celld target uses `~/.local/bin/celld`, where celld's installer
|
|
77
|
-
puts it, or the one on `PATH` (0.6.2 is what's been tested; celld has no
|
|
78
|
-
Windows build).
|
|
79
|
-
|
|
80
|
-
Deno 2.9+ refuses package versions less than 24 hours old by default
|
|
81
|
-
([minimum dependency age](https://docs.deno.com/go/minimum-dependency-age)).
|
|
82
|
-
In a release's first day, the install command fails with "blocked by the
|
|
83
|
-
minimum dependency age policy". Wait out the day, or install an earlier
|
|
84
|
-
release. Passing `--min-dep-age=0` gets the install through, but the
|
|
85
|
-
kernelspec doesn't carry the flag, so the kernel still won't launch until
|
|
86
|
-
the release is a day old.
|
|
87
|
-
|
|
88
|
-
**From a checkout**, for working on the kernel itself:
|
|
89
|
-
|
|
90
|
-
```sh
|
|
91
|
-
npm ci
|
|
92
|
-
npm run install:node # kernelspec cdp-node
|
|
93
|
-
npm run install:deno # kernelspec cdp-deno
|
|
94
|
-
npm run install:node-deno # kernelspec cdp-node-deno
|
|
95
|
-
npm run install:bun # kernelspec cdp-bun
|
|
96
|
-
npm run install:workerd # kernelspec cdp-workerd
|
|
97
|
-
npm run install:celld # kernelspec cdp-celld
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
These kernelspecs point at the checkout, so don't move it after installing.
|
|
101
|
-
|
|
102
|
-
In a cell:
|
|
103
|
-
|
|
104
|
-
- `jupyter.display`, `jupyter.md`, `jupyter.html`, `jupyter.svg`,
|
|
105
|
-
`jupyter.image`, `jupyter.format`, `jupyter.broadcast`, and
|
|
106
|
-
`Symbol.for("Jupyter.display")`: the same API as `Deno.jupyter`.
|
|
107
|
-
- `Deno.jupyter` also works:
|
|
108
|
-
- On a Deno target it is a proxy over the real namespace. Deno's own
|
|
109
|
-
getter throws outside `deno jupyter`.
|
|
110
|
-
- On Node it needs `--deno-compat`. That installs a `Deno` namespace for
|
|
111
|
-
file, env and process APIs (`runtime/deno-compat.mjs`).
|
|
112
|
-
- The shim is opt-in because libraries detect Deno with `typeof Deno`, and
|
|
113
|
-
would take Deno code paths that call APIs it doesn't cover.
|
|
114
|
-
- Imports work: TypeScript, TSX, enums, top-level `await`, and `const`
|
|
115
|
-
redeclaration across cells. Specifiers can be `./local.ts`, bare packages
|
|
116
|
-
from the notebook's `node_modules`, `node:` builtins, and `npm:pkg@range`
|
|
117
|
-
or `jsr:@scope/pkg@range`.
|
|
118
|
-
- On Node, `npm:` and `jsr:` install on first use into
|
|
119
|
-
`~/.cache/cdp-kernel/npm`.
|
|
120
|
-
- On Deno they use Deno's global cache, unless the notebook is in a Deno
|
|
121
|
-
project (below).
|
|
122
|
-
- On Bun they install with `bun add` into `~/.cache/cdp-kernel/bun`. Other
|
|
123
|
-
bare imports resolve from the notebook's directory, so without a
|
|
124
|
-
`node_modules` there, Bun auto-installs them.
|
|
125
|
-
- On workerd, the host bundles every import other than a builtin
|
|
126
|
-
(`node:`, `cloudflare:`) with esbuild, using Workers' resolution
|
|
127
|
-
conditions, and sends it with the cell. `npm:` and `jsr:` install into
|
|
128
|
-
the npm cache first, as on Node.
|
|
129
|
-
- **Deno projects.** If a `deno.json` or `deno.jsonc` sits in the notebook's
|
|
130
|
-
directory or above it, a Deno target uses it, as `deno jupyter` does:
|
|
131
|
-
- its import map (`"@/": "./lib/"` aliases, mapped packages);
|
|
132
|
-
- its `nodeModulesDir` setting, with `package.json` dependencies from the
|
|
133
|
-
project's `node_modules`;
|
|
134
|
-
- its JSX and decorator `compilerOptions`: `jsx` (`react-jsx`,
|
|
135
|
-
`react-jsxdev`, `precompile`, `react`), `jsxImportSource`,
|
|
136
|
-
`jsxFactory`, `jsxFragmentFactory`, `experimentalDecorators`.
|
|
137
|
-
|
|
138
|
-
The import map wins over `node_modules`, as in Deno. The kernel never
|
|
139
|
-
writes to the project's lockfile. A `deno.json` that doesn't parse is
|
|
140
|
-
reported in the first cell's output, and the kernel runs as in a plain
|
|
141
|
-
directory. Outside a project, the target runs with
|
|
142
|
-
`--node-modules-dir=none --no-lock`.
|
|
143
|
-
- `prompt()` and `confirm()` work over the stdin channel, except on
|
|
144
|
-
workerd. Interrupt keeps state, except for a busy cell on Bun or workerd
|
|
145
|
-
(below).
|
|
146
|
-
|
|
147
|
-
## Bun
|
|
148
|
-
|
|
149
|
-
Bun's `--inspect` speaks the WebKit Inspector Protocol, which lacks what the
|
|
150
|
-
CDP backend relies on: `replMode`, `Runtime.addBinding`,
|
|
151
|
-
`Runtime.terminateExecution`, and top-level `await` in `Runtime.evaluate`.
|
|
152
|
-
So the Bun target has its own backend (`src/bun-target.ts`,
|
|
153
|
-
`runtime/bun-channel.mjs`):
|
|
154
|
-
|
|
155
|
-
- **No inspector.** The host and Bun exchange JSON lines over a pipe on
|
|
156
|
-
fd 3, which only the host holds, so there is no port to discover.
|
|
157
|
-
- **Cells run in-process.** Each cell becomes global code wrapped in an
|
|
158
|
-
async function (`transformCellForEval` in `src/transform.ts`). Its
|
|
159
|
-
top-level declarations become properties of `globalThis`, so later
|
|
160
|
-
cells, and closures from this one, see them. This is the
|
|
161
|
-
tslab/IJavascript technique.
|
|
162
|
-
- **Same output ordering.** stdout and stderr stay pipes, ordered against
|
|
163
|
-
display messages by the same barrier markers as the CDP targets.
|
|
164
|
-
- **Interrupt.** A cell that's waiting on a promise is interrupted in place,
|
|
165
|
-
keeping state. A busy one (`while (true) {}`) can't be reached, so Bun is
|
|
166
|
-
stopped and restarts on the next cell without the earlier state. The cell
|
|
167
|
-
output says so.
|
|
168
|
-
|
|
169
|
-
What differs from the CDP targets is listed under [Known gaps](#known-gaps).
|
|
170
|
-
|
|
171
|
-
## workerd
|
|
172
|
-
|
|
173
|
-
workerd's inspector can evaluate code, but outside a request there is no
|
|
174
|
-
I/O context: timers, `fetch` and `crypto.randomUUID()` throw "Disallowed
|
|
175
|
-
operation called within global scope". So the workerd target runs its
|
|
176
|
-
cells inside a driver Worker (`src/workerd-target.ts`,
|
|
177
|
-
`runtime/workerd-worker.mjs`):
|
|
178
|
-
|
|
179
|
-
- **One session.** The host opens a single WebSocket to the driver, and
|
|
180
|
-
every cell runs inside that session's request. Cells get Workers'
|
|
181
|
-
`fetch`, `Request`, `caches`, timers and randomness, and anything one
|
|
182
|
-
cell makes carries over to the next: globals, a Durable Object stub, a
|
|
183
|
-
stream, a timer still pending.
|
|
184
|
-
- **A private socket.** Outside a Workers project, the host writes a
|
|
185
|
-
workerd config into a private temporary directory and serves the driver
|
|
186
|
-
on a Unix socket there, opened with a per-launch token. There is no TCP
|
|
187
|
-
port and no inspector.
|
|
188
|
-
- **Cells.** Cells are transformed as for Bun and run by workerd's
|
|
189
|
-
`UnsafeEval` binding (hence `--experimental`).
|
|
190
|
-
- **Output.** `console` output and display messages come back over the
|
|
191
|
-
session as they happen, in order.
|
|
192
|
-
- **Interrupt.** A cell that's waiting on something is abandoned in place,
|
|
193
|
-
keeping state, as on Bun. A busy one gets Bun's treatment too: workerd is
|
|
194
|
-
stopped and restarts on the next cell.
|
|
195
|
-
|
|
196
|
-
What workerd's own process prints, such as its warnings, goes to the Jupyter
|
|
197
|
-
server log, not the notebook.
|
|
198
|
-
|
|
199
|
-
### Workers projects
|
|
200
|
-
|
|
201
|
-
If a `wrangler.jsonc`, `wrangler.json` or `wrangler.toml` sits in the
|
|
202
|
-
notebook's directory or above it, the driver runs on the project's own
|
|
203
|
-
Miniflare, the simulator `wrangler dev` uses, with the project's bindings
|
|
204
|
-
(`src/workers-project.ts`):
|
|
205
|
-
|
|
206
|
-
- `env` holds the bindings: whatever wrangler translates for Miniflare.
|
|
207
|
-
Vars, KV, D1 and Durable Objects are tested; R2, Queues and the others
|
|
208
|
-
go through the same path but aren't.
|
|
209
|
-
- The project's `main` is bundled into the driver, so its Durable Object
|
|
210
|
-
classes run, and `worker` is its default export:
|
|
211
|
-
`await worker.fetch(new Request("https://x/"), env)`.
|
|
212
|
-
- State lives in the project's `.wrangler/state/cdp-kernel`, beside
|
|
213
|
-
`wrangler dev`'s own, so the two never open the same Durable Object.
|
|
214
|
-
- The first cell's output names the bindings. If the project can't load,
|
|
215
|
-
for example because wrangler isn't installed in it, the first cell says
|
|
216
|
-
why and the kernel runs on plain workerd.
|
|
217
|
-
|
|
218
|
-
wrangler and Miniflare come from the project's `node_modules`, so they match
|
|
219
|
-
its versions. Miniflare 4 and 5 both work. Miniflare listens on a loopback
|
|
220
|
-
TCP port, so there the per-launch token is what keeps other local processes
|
|
221
|
-
out.
|
|
222
|
-
|
|
223
|
-
## celld
|
|
224
|
-
|
|
225
|
-
[celld](https://github.com/denoland/celld) runs Workers and Durable Objects
|
|
226
|
-
on your own storage. Like workerd it has no I/O outside a request, so the
|
|
227
|
-
celld target runs the same driver Worker over the same WebSocket session
|
|
228
|
-
(`src/celld-target.ts`). Cells, output, interrupts and host-bundled imports
|
|
229
|
-
all work as on workerd. The differences:
|
|
230
|
-
|
|
231
|
-
- **No `UnsafeEval` needed.** celld allows a plain global `eval`, so it runs
|
|
232
|
-
without workerd's `--experimental`.
|
|
233
|
-
- **One module.** The host bundles the driver, and a project's `main`, into
|
|
234
|
-
a single module, and gives celld the result with `no_bundle`. celld
|
|
235
|
-
doesn't need its own esbuild.
|
|
236
|
-
- **Loopback TCP.** celld listens only on TCP, so the session is a loopback
|
|
237
|
-
WebSocket opened with a per-launch token. The kernel picks a free port
|
|
238
|
-
and runs `celld dev --no-watch` on a generated config.
|
|
239
|
-
- **Projects.** In a celld project (a `wrangler.jsonc` or `wrangler.json`
|
|
240
|
-
at or above the notebook), the generated config copies the project's
|
|
241
|
-
compatibility settings and bindings: vars, KV, D1, R2, Durable Objects,
|
|
242
|
-
Queues, Workflows, services, Worker Loaders. `env` and `worker` then work
|
|
243
|
-
as on workerd. The generated config is written to the project's
|
|
244
|
-
`.celld/cdp-kernel` and removed when the kernel stops. The state stays
|
|
245
|
-
there across kernels, beside `celld dev`'s own `.celld/dev`. celld rejects `wrangler.toml`; a project
|
|
246
|
-
that can't load is reported in the first cell, and the driver runs alone.
|
|
247
|
-
- **Stopping.** `celld dev` runs its node in a separate process group and
|
|
248
|
-
waits for it to stop gracefully, which a busy cell never allows. So an
|
|
249
|
-
interrupt of a busy cell kills the node, then `celld dev`.
|
|
250
|
-
|
|
251
|
-
## Editor types
|
|
252
|
-
|
|
253
|
-
Cells run untyped, as in `deno jupyter`. Notebook code your editor
|
|
254
|
-
type-checks can declare the globals.
|
|
45
|
+
Each install writes a Jupyter kernelspec (`cdp-node`, `cdp-deno`, …). Pick
|
|
46
|
+
it in JupyterLab or VS Code. Linux and macOS are supported; Windows isn't
|
|
47
|
+
yet. See [Install](https://cdp-kernel.org/docs/install)
|
|
48
|
+
for `--deno-compat`, release-day installs on Deno, target runtime
|
|
49
|
+
requirements, and installing from a checkout.
|
|
255
50
|
|
|
256
|
-
|
|
257
|
-
dependency, then reference it once from a cell or a `.d.ts` in the project:
|
|
51
|
+
## Quick start
|
|
258
52
|
|
|
259
53
|
```ts
|
|
260
|
-
|
|
261
|
-
await jupyter.display(jupyter.md`typed`);
|
|
262
|
-
const name: string | null = prompt("Name?", "", { password: false });
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
That declares `jupyter`, `prompt` and `confirm`. With the `cdp-node-deno`
|
|
266
|
-
kernel, use `@tlockney/cdp-kernel/globals/deno-compat` instead: it adds the
|
|
267
|
-
`Deno` namespace the compatibility shim implements. A custom display is a
|
|
268
|
-
class with a `[jupyter.$display]()` method returning a MIME bundle.
|
|
269
|
-
`jupyter.$display` is `Symbol.for("Jupyter.display")` at runtime, but only
|
|
270
|
-
`jupyter.$display` carries the precise type.
|
|
271
|
-
|
|
272
|
-
**Deno notebooks.** Use `Deno.jupyter`, which Deno already types and which a
|
|
273
|
-
Deno target provides. The JSR package doesn't ship these globals, because
|
|
274
|
-
JSR doesn't allow packages to augment global types.
|
|
275
|
-
|
|
276
|
-
## Widgets and comms
|
|
277
|
-
|
|
278
|
-
`deno jupyter` has no comms. Here they're supported in both directions, so
|
|
279
|
-
anywidget-style widgets work in frontends with the `anywidget` extension:
|
|
280
|
-
JupyterLab, Notebook 7 and VS Code. Install it with
|
|
281
|
-
`pip install anywidget`; that's the frontend half, no Python kernel needed.
|
|
282
|
-
|
|
283
|
-
```ts
|
|
284
|
-
const counter = jupyter.widget({
|
|
285
|
-
esm: `export default {
|
|
286
|
-
render({ model, el }) {
|
|
287
|
-
const btn = document.createElement("button");
|
|
288
|
-
const update = () => { btn.textContent = \`count is \${model.get("count")}\`; };
|
|
289
|
-
btn.onclick = () => { model.set("count", model.get("count") + 1); model.save_changes(); };
|
|
290
|
-
model.on("change:count", update);
|
|
291
|
-
update();
|
|
292
|
-
el.append(btn);
|
|
293
|
-
},
|
|
294
|
-
};`,
|
|
295
|
-
state: { count: 0 },
|
|
296
|
-
});
|
|
297
|
-
counter.on("change:count", (value) => console.log("clicked to", value));
|
|
298
|
-
counter; // display it
|
|
299
|
-
```
|
|
54
|
+
import { format } from "npm:date-fns@4";
|
|
300
55
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
- `get(key)`, and `set(key, value)` or `set({ ... })`, which syncs to every
|
|
304
|
-
view.
|
|
305
|
-
- `on("change:key" | "change" | "msg:custom", listener)` and `off(...)`.
|
|
306
|
-
- `send(content, buffers)` for custom messages.
|
|
307
|
-
- `close()`.
|
|
308
|
-
|
|
309
|
-
`Uint8Array`, `ArrayBuffer` and `DataView` values in the state travel as
|
|
310
|
-
binary buffers. JupyterLab restores widget state after a page reload over
|
|
311
|
-
the `jupyter.widget.control` comm.
|
|
312
|
-
|
|
313
|
-
The comm layer underneath is available directly, for other comm-based
|
|
314
|
-
protocols:
|
|
315
|
-
|
|
316
|
-
```ts
|
|
317
|
-
const comm = jupyter.comm.open("my.target", { hello: 1 });
|
|
318
|
-
comm.onMsg(({ data, buffers }) => console.log(data, buffers.length));
|
|
319
|
-
comm.send({ ping: true });
|
|
320
|
-
jupyter.comm.registerTarget("echo", (comm) => comm.onMsg((m) => comm.send(m.data)));
|
|
56
|
+
const now: Date = new Date();
|
|
57
|
+
await jupyter.display(jupyter.md`**Today** is ${format(now, "PPPP")}`);
|
|
321
58
|
```
|
|
322
59
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
the gaps those tests leave: display ordering, TS, imports, `npm:`/`jsr:`,
|
|
351
|
-
completion, and `update_display_data`. Set `CDPK_E2E_OFFLINE=1` to skip the
|
|
352
|
-
registry-dependent checks. Set `CDPK_E2E_CLI` to run it through a different
|
|
353
|
-
CLI: an installed npm bin, or `deno run -A src/main.ts` to test a Deno host.
|
|
354
|
-
|
|
355
|
-
## Releasing
|
|
356
|
-
|
|
357
|
-
One version number lives in three places: `package.json`, `deno.jsonc` and
|
|
358
|
-
`src/package.ts`. `test/package.test.ts` fails if they disagree. To release:
|
|
359
|
-
|
|
360
|
-
1. Bump all three, commit, and merge to `main`.
|
|
361
|
-
2. Tag and push: `git tag v0.1.1 && git push origin v0.1.1`.
|
|
362
|
-
|
|
363
|
-
The `publish` workflow then:
|
|
364
|
-
|
|
365
|
-
1. Checks that the tag matches the version.
|
|
366
|
-
2. Runs the type check, the unit tests, and the e2e suite against the packed
|
|
367
|
-
npm tarball and against a Deno host.
|
|
368
|
-
3. Publishes to JSR (`deno publish`).
|
|
369
|
-
4. Publishes to npm (`npm publish`).
|
|
370
|
-
|
|
371
|
-
Both registries authenticate the workflow through GitHub OIDC, so no tokens
|
|
372
|
-
are stored:
|
|
373
|
-
- **npm:** a trusted publisher for `tlockney/cdp-kernel` + `publish.yml`.
|
|
374
|
-
- **JSR:** the package is linked to this repo in its JSR settings.
|
|
375
|
-
|
|
376
|
-
Neither registry lets a version be republished. Each job skips a version
|
|
377
|
-
its registry already has, so re-running a release only fills in the half
|
|
378
|
-
that failed.
|
|
379
|
-
|
|
380
|
-
## Known gaps
|
|
381
|
-
|
|
382
|
-
- Widgets are anywidget-style (`jupyter.widget`). The classic ipywidgets
|
|
383
|
-
controls (sliders, dropdowns) are Python classes, so they're not available.
|
|
384
|
-
- No `inspect_request` content and no history. Deno has neither.
|
|
385
|
-
- No debugger.
|
|
386
|
-
- `npm:` on Node:
|
|
387
|
-
- one npm alias per `name@range`;
|
|
388
|
-
- no lockfile;
|
|
389
|
-
- peer dependencies resolve by real name from the shared cache.
|
|
390
|
-
- No type checking. Deno doesn't type-check REPL cells either.
|
|
391
|
-
- Results are formatted with `util.inspect` on Node, so they look slightly
|
|
392
|
-
different from Deno's `Deno.inspect`.
|
|
393
|
-
- WebGPU texture and buffer display is dropped.
|
|
394
|
-
- On Bun:
|
|
395
|
-
- Interrupting a busy cell restarts Bun and loses state. An awaiting cell
|
|
396
|
-
keeps it.
|
|
397
|
-
- Top-level declarations are properties of `globalThis`. A `const` can be
|
|
398
|
-
reassigned, and declaring a global's name (`const fetch = ...`) replaces
|
|
399
|
-
that global rather than shadowing it.
|
|
400
|
-
- Only a trailing expression statement shows a result: `x` does, but
|
|
401
|
-
`if (c) { x }` doesn't.
|
|
402
|
-
- Bun 1.4 can't import a module whose path contains `?`.
|
|
403
|
-
- No `--deno-compat` namespace.
|
|
404
|
-
- On workerd:
|
|
405
|
-
- All cells share one request, so it never ends. Unlike production
|
|
406
|
-
Workers, there is no per-request CPU or duration limit, and
|
|
407
|
-
`ctx.waitUntil` isn't available in a cell.
|
|
408
|
-
- No `prompt()` or `confirm()` answers: they return `null`, as without a
|
|
409
|
-
stdin channel. `jupyter.image(path)` can't read files; pass the bytes.
|
|
410
|
-
- Each imported module is bundled with its dependencies. Two imports that
|
|
411
|
-
share a dependency each get their own copy.
|
|
412
|
-
- Interrupting a busy cell restarts workerd and loses state.
|
|
413
|
-
- Top-level declarations and results behave as on Bun: declarations are
|
|
414
|
-
`globalThis` properties, and only a trailing expression shows a result.
|
|
415
|
-
- In a Workers project, `main` is bundled with esbuild directly, not with
|
|
416
|
-
wrangler's build. Custom `build` commands, `alias` and module `rules`
|
|
417
|
-
aren't applied.
|
|
418
|
-
- On celld, as on workerd, except:
|
|
419
|
-
- Only the binding and compatibility keys of a project's config are
|
|
420
|
-
copied. `assets`, `triggers` and `containers` aren't, and neither is
|
|
421
|
-
`.dev.vars`. Relative paths inside the copied keys resolve from
|
|
422
|
-
`.celld/cdp-kernel`, not from the project.
|
|
423
|
-
- Interrupting a busy cell restarts celld and loses state.
|
|
424
|
-
|
|
425
|
-
## Provenance
|
|
426
|
-
|
|
427
|
-
`src/zmtp.ts`, `src/wire.ts`, `src/kernel.ts`, `src/text.ts` and
|
|
428
|
-
`runtime/display.mjs` are ports of Deno's `cli/js/jupyter_kernel.js` and
|
|
429
|
-
`cli/js/40_jupyter.js` at v2.9.6 (commit `e518fbd`), Copyright 2018-2026 the
|
|
430
|
-
Deno authors, MIT license. Each file header says which parts.
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
New to Jupyter? Start with
|
|
63
|
+
[Getting started](https://cdp-kernel.org/docs/getting-started).
|
|
64
|
+
|
|
65
|
+
- Guides: [Writing notebooks](https://cdp-kernel.org/docs/notebooks),
|
|
66
|
+
[The `jupyter` namespace](https://cdp-kernel.org/docs/jupyter-api),
|
|
67
|
+
[Choosing a runtime](https://cdp-kernel.org/docs/runtimes),
|
|
68
|
+
[Widgets and comms](https://cdp-kernel.org/docs/widgets),
|
|
69
|
+
[Debugger](https://cdp-kernel.org/docs/debugger)
|
|
70
|
+
- Reference: [Editor types](https://cdp-kernel.org/docs/editor-types),
|
|
71
|
+
[Known gaps](https://cdp-kernel.org/docs/known-gaps)
|
|
72
|
+
- Internals: [Architecture](https://cdp-kernel.org/docs/architecture),
|
|
73
|
+
[Runtime integrations](https://cdp-kernel.org/docs/integrations)
|
|
74
|
+
- Contributing: [Development](https://cdp-kernel.org/docs/development)
|
|
75
|
+
|
|
76
|
+
The [feasibility study](https://cdp-kernel.org/docs/feasibility-study)
|
|
77
|
+
behind the project covers the design, the alternatives considered (workerd,
|
|
78
|
+
Bun, rusty_v8, FFI), and the evidence.
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT. Parts are ports of Deno's Jupyter kernel, Copyright 2018-2026 the Deno
|
|
83
|
+
authors. The debugger's MurmurHash2 follows JupyterLab's (BSD-3-Clause) and
|
|
84
|
+
Gary Court's (MIT); their notices are in
|
|
85
|
+
[THIRD-PARTY-NOTICES](THIRD-PARTY-NOTICES). See
|
|
86
|
+
[Architecture › Provenance](https://cdp-kernel.org/docs/architecture#provenance).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Third-party notices for cdp-kernel
|
|
2
|
+
|
|
3
|
+
cdp-kernel itself is under the MIT license in LICENSE. The files below carry
|
|
4
|
+
code from other projects under their own licenses.
|
|
5
|
+
|
|
6
|
+
--------------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
src/murmur2.ts follows JupyterLab's packages/debugger/src/hash.ts
|
|
9
|
+
(Copyright (c) Jupyter Development Team), which is distributed under the
|
|
10
|
+
following license:
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2015-2026 Project Jupyter Contributors
|
|
13
|
+
All rights reserved.
|
|
14
|
+
|
|
15
|
+
Redistribution and use in source and binary forms, with or without
|
|
16
|
+
modification, are permitted provided that the following conditions are met:
|
|
17
|
+
|
|
18
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
19
|
+
list of conditions and the following disclaimer.
|
|
20
|
+
|
|
21
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
22
|
+
this list of conditions and the following disclaimer in the documentation
|
|
23
|
+
and/or other materials provided with the distribution.
|
|
24
|
+
|
|
25
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
26
|
+
contributors may be used to endorse or promote products derived from
|
|
27
|
+
this software without specific prior written permission.
|
|
28
|
+
|
|
29
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
30
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
31
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
32
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
33
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
34
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
35
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
36
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
37
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
38
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
39
|
+
|
|
40
|
+
JupyterLab's hash.ts is in turn adapted from Gary Court's murmurhash2_gc.js
|
|
41
|
+
(https://github.com/garycourt/murmurhash-js), distributed under the following
|
|
42
|
+
license:
|
|
43
|
+
|
|
44
|
+
Copyright (c) 2011 Gary Court
|
|
45
|
+
|
|
46
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
47
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
48
|
+
in the Software without restriction, including without limitation the rights
|
|
49
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
50
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
51
|
+
furnished to do so, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
The above copyright notice and this permission notice shall be included in all
|
|
54
|
+
copies or substantial portions of the Software.
|
|
55
|
+
|
|
56
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
57
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
58
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
59
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
60
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
61
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
62
|
+
SOFTWARE.
|
package/dist/bun-target.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CdpParams, type EvaluateResult, type RemoteObject } from "./cdp.ts";
|
|
2
2
|
import { transformCellForEval } from "./transform.ts";
|
|
3
3
|
import { type KernelTarget, type TargetEvents } from "./target.ts";
|
|
4
4
|
/**
|
|
@@ -51,8 +51,10 @@ export declare class BunTarget implements KernelTarget {
|
|
|
51
51
|
stack: string;
|
|
52
52
|
}>;
|
|
53
53
|
propertyNames(expression: string): Promise<string[]>;
|
|
54
|
+
/** Resolved by property descriptor in the target, so nothing runs (#10). */
|
|
55
|
+
inspect(path: string, detail: number): Promise<string | null>;
|
|
54
56
|
/** None: top-level declarations here are properties of globalThis. */
|
|
55
57
|
lexicalNames(): Promise<string[]>;
|
|
56
|
-
replyInput(value: string | null): void;
|
|
58
|
+
replyInput(value: string | null, interrupted?: boolean): void;
|
|
57
59
|
kill(): void;
|
|
58
60
|
}
|