@astrale-os/adapter-cloudflare 0.2.0 → 0.3.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 (65) hide show
  1. package/dist/build.d.ts +2 -1
  2. package/dist/build.d.ts.map +1 -1
  3. package/dist/build.js +1 -1
  4. package/dist/build.js.map +1 -1
  5. package/dist/client.d.ts +14 -13
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +25 -18
  8. package/dist/client.js.map +1 -1
  9. package/dist/cloudflare.d.ts +4 -1
  10. package/dist/cloudflare.d.ts.map +1 -1
  11. package/dist/cloudflare.js +40 -18
  12. package/dist/cloudflare.js.map +1 -1
  13. package/dist/codegen/worker.d.ts +3 -3
  14. package/dist/codegen/worker.d.ts.map +1 -1
  15. package/dist/codegen/worker.js +19 -8
  16. package/dist/codegen/worker.js.map +1 -1
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.js +2 -2
  19. package/dist/params.d.ts +3 -0
  20. package/dist/params.d.ts.map +1 -1
  21. package/package.json +2 -2
  22. package/src/build.ts +2 -1
  23. package/src/client.ts +43 -18
  24. package/src/cloudflare.ts +41 -14
  25. package/src/codegen/worker.ts +19 -8
  26. package/src/index.ts +2 -2
  27. package/src/params.ts +4 -0
  28. package/template/CLAUDE.md +24 -0
  29. package/template/README.md +24 -15
  30. package/template/astrale.config.ts +4 -4
  31. package/template/client/README.md +9 -9
  32. package/template/client/__tests__/app.test.tsx +58 -19
  33. package/template/client/__tests__/harness.ts +16 -0
  34. package/template/client/__tests__/kernel.test.ts +23 -3
  35. package/template/client/src/shell/use-async.ts +4 -1
  36. package/template/client/src/status/components/StatusCard.tsx +115 -5
  37. package/template/client/src/status/hooks/useCheckable.query.ts +48 -40
  38. package/template/client/src/status/index.ts +2 -2
  39. package/template/client/src/status/status.api.ts +18 -1
  40. package/template/client/src/status/status.mappers.ts +89 -6
  41. package/template/client/src/status/status.types.ts +17 -2
  42. package/template/client/src/styles.css +235 -14
  43. package/template/client/src/views/status.tsx +1 -1
  44. package/template/core/monitor/index.ts +2 -2
  45. package/template/core/monitor/node.ts +12 -6
  46. package/template/domain.ts +6 -4
  47. package/template/functions/index.ts +31 -7
  48. package/template/package.json +2 -2
  49. package/template/pnpm-lock.yaml +57 -43
  50. package/template/pnpm-workspace.yaml +2 -0
  51. package/template/runtime/index.ts +8 -17
  52. package/template/runtime/monitoring/index.ts +8 -0
  53. package/template/runtime/{monitor → monitoring/monitor}/check.ts +3 -3
  54. package/template/runtime/{monitor → monitoring/monitor}/index.ts +3 -2
  55. package/template/runtime/{monitor → monitoring/monitor}/seed.ts +19 -10
  56. package/template/runtime/{monitor → monitoring/monitor}/watch.ts +5 -5
  57. package/template/runtime/{status-page → monitoring/page}/add.ts +2 -2
  58. package/template/runtime/{status-page → monitoring/page}/check.ts +2 -2
  59. package/template/runtime/{status-page → monitoring/page}/create.ts +3 -3
  60. package/template/runtime/monitoring/page/index.ts +9 -0
  61. package/template/schema/monitor.ts +6 -8
  62. package/template/views/index.ts +1 -1
  63. package/template/.agents/skills/astrale-cli/SKILL.md +0 -458
  64. package/template/.agents/skills/astrale-domain/SKILL.md +0 -371
  65. package/template/runtime/status-page/index.ts +0 -8
@@ -1,458 +0,0 @@
1
- ---
2
- name: astrale-cli
3
- description: Reference for the Astrale CLI (binary `astrale`, package `@astrale-os/astrale`) - CLI setup, command composition, graph exploration and querying, kernel calls, instance bookmarks and admin-provisioned instances, identity management, delegation tokens, browser sessions, output behavior, debugging, and local storage.
4
- ---
5
-
6
- # Astrale CLI
7
-
8
- `astrale` is the CLI for connecting to Astrale kernels. It authenticates,
9
- selects an instance, calls kernel operations, inspects graph nodes, mints
10
- delegation tokens, and prepares authenticated browser sessions for agents.
11
-
12
- The command surface lives in the code. Use `astrale --help` and
13
- `astrale <cmd> --help` as the source of truth for commands, flags, defaults,
14
- and examples. This skill should only hold cross-cutting model details and
15
- common recipes that help compose those commands correctly.
16
-
17
- - Binary: `astrale`
18
- - npm package: `@astrale-os/astrale`
19
- - Runtime: Bun
20
- - Framework: Commander.js
21
- - Dev entrypoint: `bun cli/bin/astrale.ts <command>`
22
-
23
- ## Command Surface
24
-
25
- Current top-level commands:
26
-
27
- ```bash
28
- astrale whoami
29
- astrale use <name>
30
- astrale update
31
- astrale call <path> [params...]
32
- astrale token
33
- astrale get <path>
34
- astrale ls [path]
35
- astrale describe <path>
36
- astrale query <cypher>
37
- astrale logs <service>
38
- astrale status
39
- astrale browser
40
- astrale instance ...
41
- astrale domain ...
42
- astrale admin ...
43
- astrale identity ...
44
- astrale auth ...
45
- astrale idp ...
46
- ```
47
-
48
- Command groups:
49
-
50
- | Group | Commands |
51
- |---|---|
52
- | Kernel | `call`, `token`, `get`, `ls`, `describe`, `query`, `logs` |
53
- | Context | `status`, `whoami`, `use` |
54
- | Management | `admin`, `instance`, `domain`, `identity`, `auth`, `idp`, `update` |
55
- | Agent | `browser` |
56
-
57
- Shared kernel options are merged onto kernel-touching commands at registration
58
- time: `--format`, `--json`, `--raw`, `--url`, `-i/--instance`, `--timeout`,
59
- `--as`, `--creds`, and `--debug`. Check `astrale <cmd> --help` before relying
60
- on an option for a specific command.
61
-
62
- ## Path Syntax
63
-
64
- Clients address graph entities and operations with Paths.
65
-
66
- | Form | Grammar | Use when |
67
- |---|---|---|
68
- | Absolute path | `/domain`, `/domain/class.Name`, `/domain/interface.Name` | Domain, Class namespace, or Interface namespace |
69
- | Static method | `/:domain:class.Name:method` or `/domain/class.Name/method` | Class-level or interface-level operation |
70
- | Instance method | `<nodePath>::method` or `@id::method` | Operation on a node instance |
71
- | Id reference | `@nodeId` | Reference a node by UID |
72
- | Self reference | `@self` | CLI-side shorthand for the active caller node |
73
-
74
- Load-bearing rules:
75
-
76
- - Keep the `class.` or `interface.` prefix in namespace segments:
77
- `/:host.astrale.ai:class.KernelInstance:list`, not
78
- `/:host.astrale.ai:KernelInstance:list`.
79
- - Static methods declared on an Interface are reached through the declaring
80
- interface namespace, not through a concrete Class namespace.
81
- - Instance dispatch uses double colon `::`; single colon is for domain-path
82
- static method syntax.
83
- - Prefer the domain-path form `/:domain:class.Name:method` for static calls
84
- when possible. It resolves by domain membership rather than tree layout.
85
- - `@<id>` takes a graph node UUID only — `@<slug>` is NOT_FOUND. And a
86
- permission error naming a node that "should exist" often means the node
87
- does NOT exist (missing targets surface as permission denied, not
88
- NOT_FOUND) — verify with `astrale get <path>` before chasing grants.
89
-
90
- Examples:
91
-
92
- ```bash
93
- astrale call /:blog.acme.com:class.Author:list
94
- astrale call /:blog.acme.com:class.Monitor:watch url=https://astrale.ai
95
- astrale call /blog.acme.com/alice::deactivate
96
- astrale call @f00d...::deactivate
97
- ```
98
-
99
- ### @self
100
-
101
- `@self` is a CLI-side literal expanded before a call is signed and sent. It
102
- resolves to the active identity's registered node id on the target instance.
103
- The kernel receives the concrete `@<nodeId>` value.
104
-
105
- Supported positions:
106
-
107
- - Path head: `@self`, `@self::method`, `@self/child`
108
- - Param value head: `key=@self`, `key=@self::method`
109
-
110
- Not expanded:
111
-
112
- - `--url`
113
- - `--data`
114
- - stdin JSON
115
- - substrings such as `prefix@self`
116
- - comma lists such as `@self,@other`
117
-
118
- For JSON payloads, resolve manually before building the payload.
119
-
120
- ```bash
121
- astrale describe @self
122
- astrale call @self::deactivate
123
- astrale call /:d:class.X:m owner=@self
124
- ```
125
-
126
- If `@self` expands to a deleted or stale id, refresh the registration with
127
- `astrale identity register <name> -i <instance>`.
128
-
129
- For IdP-backed identities (`astrale auth login`), `@self` just works: on the
130
- first use against an instance the CLI does ONE kernel `whoami` round-trip,
131
- caches the node id as a registration, and expands locally afterwards. If that
132
- lookup fails (offline, expired session), the error carries the manual recipe:
133
-
134
- ```bash
135
- astrale call "/:kernel.astrale.ai:interface.Identity:whoami" --json # → { id }
136
- astrale describe @<that-id>
137
- ```
138
-
139
- ## Instances
140
-
141
- `astrale instance` manages admin-provisioned instances and local bookmarks.
142
-
143
- Use:
144
-
145
- ```bash
146
- astrale instance create my-app
147
- astrale instance status my-app
148
- astrale instance use my-app
149
- astrale instance active
150
- astrale instance bookmark staging --url https://kernel.example.com
151
- astrale instance forget staging
152
- ```
153
-
154
- Important distinctions:
155
-
156
- - `instance use` changes the active target instance.
157
- - `instance active` shows the active target instance.
158
- - `instance bookmark` records an existing remote kernel URL locally.
159
- - `instance forget` removes a local bookmark only.
160
- - `instance delete` is destructive for admin-managed instances.
161
- - In scripts, prefer explicit `-i <instance>` over relying on ambient active
162
- instance state.
163
-
164
- ## Domain Dev Workflow
165
-
166
- **The `astrale` CLI is connect-only — it does not build, run, or deploy
167
- domains.** The `astrale domain` group manages the admin catalog and installs a
168
- running domain onto an instance (`list`, `publish`, `install`); it does NOT
169
- build or run domains. `astrale domain list` shows the published catalog (add
170
- `--check` to probe each URL's reachability, `--default-only` for the
171
- install-on-every-instance set, `-q` to pipe install URLs). Building, running,
172
- and deploying live in two separate tools:
173
-
174
- - **`create-astrale-domain`** scaffolds a new standalone domain project
175
- (`pnpm create astrale-domain <slug>`), writing an `astrale.config.ts`.
176
- - **`astrale-domain`** (the `@astrale-os/sdk` bin, behind the project's
177
- `pnpm dev` / `pnpm prod` scripts) runs `dev | prod | deploy <env> | build`.
178
-
179
- Domains are **installed by URL or catalog origin**, never from a file (there is
180
- no committed `spec.json`). `astrale domain install` has two modes:
181
-
182
- - **default (via admin)** — `astrale domain install <origin|url> -i <slug>`
183
- installs a PUBLISHED domain through the admin control plane
184
- (`DomainEntry.install`), addressed by its catalog `origin` (the unique
185
- registry key) or `url`. Run it bare to pick from the catalog interactively.
186
- The target instance is the active one or `-i <slug>` and **must be
187
- admin-managed** (otherwise it fails loudly and points you at `--direct`).
188
- - **`--direct`** — `astrale domain install <url> --direct` installs a url
189
- straight onto the instance kernel (`Root.installDomain`), bypassing the
190
- catalog. Works on ANY instance you can authenticate to (managed, bookmarked,
191
- or local), using your own authority, and is the only mode that runs the
192
- identity-override consent gate. Use it for dev/local instances and
193
- freshly-deployed, not-yet-published workers.
194
-
195
- With the **managed (`astrale`) adapter**, `pnpm prod` publishes the bundle
196
- through the platform AND installs it on the configured instance in one step —
197
- no manual `domain install`. The service serves at
198
- `https://<name>-<hash>.svc.<region>.astrale.ai` (the CLI session is the auth).
199
-
200
- For authoring domains end-to-end (schema, handlers, external APIs, deploys),
201
- load the **astrale-domain** skill; for graph-level schema surgery on a live
202
- kernel, **astrale-live-domain-edit**.
203
-
204
- ## Auth And Credentials
205
-
206
- Keep the auth model simple:
207
-
208
- - `astrale auth login` authenticates with an IdP and stores an IdP-backed local
209
- identity/session.
210
- - `astrale identity create <name>` creates a local key-backed identity.
211
- - `astrale identity register <name> -i <instance>` registers that identity with
212
- a target instance.
213
- - `astrale use <name>` switches the active identity or active instance when the
214
- name is unambiguous. Use `--identity` or `--instance` when it is ambiguous.
215
- - `--as <identity>` makes a kernel command call as that identity.
216
- - `--creds <token>` sends an already minted credential and skips normal signing.
217
-
218
- Useful checks:
219
-
220
- ```bash
221
- astrale status
222
- astrale whoami
223
- astrale auth status
224
- astrale identity list
225
- astrale identity whoami
226
- ```
227
-
228
- `astrale auth token --raw` prints a cached IdP provider token for shell use.
229
- That is different from `astrale token`, which mints a delegation token for
230
- kernel/worker calls.
231
-
232
- ### Session lifetime and refresh
233
-
234
- IdP sessions refresh themselves: every kernel command silently exchanges the
235
- refresh token when the cached access token is stale, and concurrent `astrale`
236
- processes serialize that exchange on a per-identity file lock (refresh tokens
237
- are single-use — the lock is what makes parallel agent-driven commands safe).
238
- One `astrale auth login` should therefore last until the IdP itself ends the
239
- session. Access tokens are also cached **per audience**, so alternating
240
- commands between instances does not burn a refresh per flip.
241
-
242
- Refresh failures come in two distinct flavors — read the error before
243
- re-authenticating:
244
-
245
- - "could not be refreshed … run: astrale auth login" — the grant is dead
246
- (IdP session ended, idle/absolute timeout, logout elsewhere). Re-login is
247
- the only fix.
248
- - "Could not reach the IdP … retry the command" — transient network/IdP
249
- outage. The cached session is still valid; do NOT re-login, just retry.
250
-
251
- ### Agent auth
252
-
253
- An agent driving the CLI needs no special flow: it shares `~/.astrale`, so one
254
- human `astrale auth login` is enough and every subsequent command (including
255
- parallel ones) self-refreshes. For fully headless setups with no human login,
256
- use a key-backed identity — `astrale identity create <name>` then
257
- `astrale identity register <name> -i <instance>` — which signs locally and
258
- never expires; or hand the agent a TTL-bound delegation token minted with
259
- `astrale token` and passed via `--creds`.
260
-
261
- ## Delegation Tokens
262
-
263
- `astrale token` mints a delegation token for the active instance and identity.
264
- Use it when another process, script, or worker needs to call with delegated
265
- authority.
266
-
267
- Common flow:
268
-
269
- ```bash
270
- export TOKEN=$(astrale token --audience dist.astrale.ai --raw)
271
- astrale call /:dist.astrale.ai:class.Domain:install \
272
- --url https://dist.astrale.ai \
273
- --creds "$TOKEN" \
274
- -d '{"name":"alice"}'
275
- ```
276
-
277
- Notes:
278
-
279
- - Default TTL is 3600 seconds.
280
- - `--audience <aud>` should match the receiving service or worker expectation.
281
- - `--for <identity>` is an alias for `--as <identity>`.
282
- - Use `--raw` when assigning the token to an environment variable.
283
- - Use `--json` when a machine should parse token metadata.
284
-
285
- ## Graph Exploration
286
-
287
- Use these commands for graph inspection:
288
-
289
- ```bash
290
- astrale ls /
291
- astrale get /some/path
292
- astrale describe /some/path
293
- astrale query 'MATCH (n) RETURN n LIMIT 5'
294
- astrale call <path> --describe
295
- ```
296
-
297
- Gotchas:
298
-
299
- - `query` is read-only; the kernel rejects write keywords such as `CREATE`,
300
- `DELETE`, `SET`, `MERGE`, `REMOVE`, and `DETACH`.
301
- - `describe` can return large properties such as serialized schemas. Pipe to
302
- `jq` or use command-specific flags when available.
303
- - `ls` has list-specific output controls such as `-q/--quiet`, `--count`, and
304
- `-l/--long`; check `astrale ls --help`.
305
- - For operation schemas, prefer `astrale call <path> --describe` before
306
- executing a call you are unsure about.
307
- - **`class.<Name>` materializes as a `Folder` node** (kind `Folder`, name
308
- prefixed `class.`) whose children are the class's callable Functions. There
309
- is no `Class` node at that tree position — the Class definition lives inside
310
- the Domain's serialized `schema` prop. So `--filter Class` returns zero; use
311
- `--filter Folder`, or descend into `class.<X>` and filter on `Function`.
312
-
313
- ## Output / TTY Behavior
314
-
315
- Output is selected from stdout shape and flags:
316
-
317
- - TTY default: human-readable output, usually YAML for objects and tables for
318
- lists.
319
- - Pipe, redirect, `--json`, or `--raw`: machine-oriented output.
320
- - `--json`: always valid JSON for tools like `jq`.
321
- - `--raw`: unwrap scalars for shell assignment and write raw bytes for binary
322
- responses.
323
- - `--format yaml|json`: explicit structured output where supported.
324
- - `call --output <file>` writes binary/raw output to a file.
325
- - Piped stdin is read by `astrale call`; stdin on a TTY is ignored.
326
- - `--data` takes precedence over stdin and `key=value` params.
327
- - `key=value` values are auto-coerced: `true`/`false`/`null`, numeric strings
328
- → numbers, `{…}`/`[…]` → parsed JSON; everything else stays a string. To
329
- force a digits-only STRING (or pass nested values), use `--data`.
330
- - **Big payloads go through stdin** — argv caps around 128 KB, so multi-MB
331
- JSON (e.g. a base64 bundle) must be piped:
332
- `echo "$PAYLOAD_JSON" | astrale call <path> --json`.
333
-
334
- Examples:
335
-
336
- ```bash
337
- astrale ls / --json | jq .
338
- TOKEN=$(astrale token --audience dist.astrale.ai --raw)
339
- astrale call /:d:class.Asset:render id=123 --output asset.png
340
- astrale call /:d:class.X:m -d '{"name":"alice"}'
341
- ```
342
-
343
- ## Driving The GUI
344
-
345
- Use `astrale browser` to prepare an authenticated GUI browser session that an
346
- agent can drive with `agent-browser`.
347
-
348
- Install once:
349
-
350
- ```bash
351
- npm install -g agent-browser && agent-browser install
352
- npx skills add vercel-labs/agent-browser
353
- ```
354
-
355
- Connect and verify:
356
-
357
- ```bash
358
- astrale browser
359
- astrale browser --check
360
- astrale browser --login
361
- astrale browser --cdp 9222
362
- ```
363
-
364
- After `astrale browser` connects, it prints the exact `agent-browser --profile`
365
- command to use. Driving the page is agent-browser's job:
366
-
367
- ```bash
368
- agent-browser --profile <dir> snapshot
369
- agent-browser --profile <dir> open <url>
370
- agent-browser --profile <dir> click @e3
371
- agent-browser --profile <dir> eval '<js>'
372
- ```
373
-
374
- The GUI session uses an httpOnly cookie. There is no token-injection shortcut;
375
- the persistent browser profile is the session boundary.
376
-
377
- ## Debugging And Common Errors
378
-
379
- Start with local context:
380
-
381
- ```bash
382
- astrale status
383
- astrale admin status
384
- astrale instance active
385
- astrale auth status
386
- astrale whoami
387
- ```
388
-
389
- Use diagnostics:
390
-
391
- - Add `--debug` to kernel commands for full error diagnostics — including
392
- the server-side cause chain (`data.cause`), which shows the ROOT failure
393
- inside wrapped errors (e.g. what actually failed under a
394
- `Delegation mint failed` or `KERNEL_ERROR`).
395
- - Use global `--log-level debug` for verbose CLI logging.
396
- - Use global `--log-format json` when an agent or script should parse logs.
397
- - Use `--json` or `--raw` for structured command output.
398
- - Use `--ci` and `--no-prompt` in non-interactive automation.
399
- - Use `--timeout <ms>` when a kernel call is valid but slow.
400
- - Use `astrale logs <service-slug> [--tail N]` to tail a MANAGED SERVICE's
401
- runtime logs — console output, 5xx accesses, and uncaught exception stacks
402
- (the readable side of `internal error; reference = …` responses). The slug
403
- is the first label of the service's `…svc.<region>.astrale.ai` URL (also
404
- accepts the full URL). In-memory, last ~500 lines, resets on runtime
405
- restart; services deployed before log capture need one redeploy.
406
-
407
- Common error classes and first checks:
408
-
409
- | Error shape | First check |
410
- |---|---|
411
- | Connection error | `astrale status`; verify the instance URL and network path |
412
- | Authentication error | `astrale auth status`, `astrale whoami`, active identity |
413
- | Permission denied | Does the named node actually exist (`astrale get`)? Then active identity and target operation permissions |
414
- | Not found | Path spelling, active instance, installed domain |
415
- | Validation error | `astrale call <path> --describe` |
416
- | Timeout | Target availability and `--timeout <ms>` |
417
-
418
- If a command fails only in a script, compare TTY vs non-TTY behavior and pass
419
- explicit `--json`, `--raw`, `-i <instance>`, and `--as <identity>` as needed.
420
-
421
- ## Storage
422
-
423
- CLI state lives under `ASTRALE_HOME` when set, otherwise `~/.astrale`.
424
-
425
- Core paths:
426
-
427
- ```text
428
- ~/.astrale/
429
- config.json CLI and admin config
430
- install.json Script-install metadata for `astrale update`
431
- instances.json Active instance and local instance records
432
- identities.json Active identity and identity metadata
433
- idps/ IdP provider metadata
434
- idp-sessions/ Cached IdP sessions
435
- keys/ Local identity keypairs
436
- data/ Local data directory used by local adapters
437
- browser.json Last connected GUI browser session
438
- browser/<host>/ Persistent browser profile for GUI auth
439
- ```
440
-
441
- Optional overrides:
442
-
443
- - `ASTRALE_HOME`: root for CLI state.
444
- - `ASTRALE_KEYS_DIR`: keypair directory.
445
- - `ASTRALE_DATA_DIR`: data directory.
446
-
447
- Keep storage references centralized in this section. Other sections should
448
- describe behavior, not repeat file locations.
449
-
450
- ## Source Map
451
-
452
- - Entry: `cli/bin/astrale.ts`
453
- - Program and help wiring: `cli/src/program.ts`
454
- - Command registration helpers: `cli/src/registry.ts`, `cli/src/command.ts`
455
- - Commands: `cli/src/commands/`
456
- - Shared output, auth, browser, paths, and local helpers: `cli/src/lib/`
457
- - Kernel command plumbing and error formatting: `cli/src/kernel/`
458
- - Tests for help and command behavior: `cli/src/commands/__tests__/`