feat(contracts): regenerate bundle with hook-event-request#12
feat(contracts): regenerate bundle with hook-event-request#12joshuajbouw wants to merge 2 commits into
Conversation
Submodule bump + sync-contracts-wit.sh regeneration. The hook.wit record was added in unicity-astrid/wit#TBD to back the @unicity-astrid/wit/hook/hook-event-request reference in astrid-capsule-hook-bridge/Capsule.toml. With this commit, the bundled astrid-contracts.wit (consumed by codegenWitEvents in the JS SDK) carries the record, so any consumer that switches from hand-coded types to generated types gets the correct shape. Depends on unicity-astrid/wit#TBD landing first — once that merges, this PR's submodule pointer becomes reachable from main.
There was a problem hiding this comment.
Code Review
This pull request updates the contracts subproject commit and introduces a new hook-event-request record to the WIT contracts file astrid-contracts.wit. The reviewer noted that the TypeScript contracts file packages/astrid-sdk/src/contracts.ts needs to be regenerated and committed to keep the TS SDK in sync with the updated WIT contracts.
| record hook-event-request { | ||
| /// Semantic hook name (e.g. `before_tool_call`, `session_start`, | ||
| /// `on_compaction_started`). Matches the mapping table in | ||
| /// `astrid-capsule-hook-bridge`. | ||
| hook: string, | ||
| /// Original lifecycle event payload, serialized as JSON. Opaque | ||
| /// to the bus — subscribers parse based on the hook name. | ||
| payload: string, | ||
| /// Per-request correlation id for scoped replies. `none` for | ||
| /// fire-and-forget hooks. | ||
| correlation-id: option<string>, | ||
| } |
There was a problem hiding this comment.
The TypeScript contracts file packages/astrid-sdk/src/contracts.ts is checked into the repository but has not been regenerated to include the new hook-event-request types. Please run the generation script (e.g., node packages/astrid-sdk/scripts/generate-contracts.mjs) and commit the updated contracts.ts file to ensure the TS SDK remains in sync with the WIT contracts.
There was a problem hiding this comment.
Done. The WIT carried the new hook-event-request record but src/contracts.ts was never regenerated on this branch (the prior commit only bumped the WIT and the contracts submodule, not the generated TS). Regenerated via the package prebuild step (node scripts/generate-contracts.mjs) and committed — the diff is purely additive, adding the HookEventRequest interface (type count 99 → 100), and tsc -b is clean. The generator is deterministic (walks the WIT AST in source order, no sorting/timestamps/randomness), so the same WIT always yields identical output.
The prior commit bumped the WIT (hook-event-request record) and the contracts submodule pointer but never re-ran the generator, leaving src/contracts.ts stale. Regenerated via the package prebuild step (node scripts/generate-contracts.mjs); purely additive — adds the HookEventRequest interface (type count 99 -> 100). tsc -b is clean.
## Summary Mirrors the Rust SDK and the host `astrid:process@1.0.0` **persistent-process tier** (host: astrid-runtime/astrid#867; Rust SDK: astrid-runtime/sdk-rust#53; contract: astrid-runtime/wit#12), so JS/TS capsule authors can spawn a background child that **outlives the pooled, stateless instance** that started it — unlike `process.BackgroundProcessHandle`, whose kernel resource is reaped on instance reset. ## Changes - **`contracts` submodule → the merged `astrid:process@1.0.0` persistent tier** (wit commit `1a06cf4`, the #12 squash). Deliberately the **#12-only** commit (predates #11), so the `astrid:contracts` events bundle (`astrid-contracts.wit` / generated `contracts.ts`) is untouched (`sync-contracts-wit.sh --check` stays green) and unrelated open SDK PRs are unaffected. On `main`, `astrid-build` reads the host WIT **live from `contracts/host/`** (`CANONICAL_WIT_DIR`), so the bump is all ComponentizeJS needs. - **`wit-imports.d.ts`** (hand-written host ABI types): persistent types + free-function declarations on `astrid:process/host@1.0.0` — `spawnPersistent`, `attach`, `listProcesses`, `status`, `statusMany`, `readLogs`, `readSince`, `writeStdin`, `closeStdin`, `signal`, `wait`, `stop`, `releaseProcess`, `watch`, `unwatch`; `ProcessInfo`, `ProcessPhase`, `LogStream`, `LogCursor`, `LogChunk`, `OverflowPolicy`, `ResourceLimits`; `ErrorCode` gains `no-such-process` / `registry-full` / `persist-unsupported`; `ProcessSignal` gains `stop` / `cont`; `SpawnRequest` gains the 8 persistent fields. - **`process.ts`** ergonomic layer: `spawnPersistent(cmd, args, options)` + the persistent `SpawnPersistentOptions` knobs; `PersistentProcess` class (`status` / `readLogs` (drain) / `readSince` (non-draining cursor → byte-faithful `LogChunkResult`; `logCursorStart()`) / `writeStdin` / `closeStdin` / `signal` / `wait` (bounded) / `stop` (consumes — SIGTERM→grace→SIGKILL) / `release`); module fns `attach(id)` (id-wrapper reattach — works without the host's deferred `attach` resource fn), `listProcesses`, `statusMany`; ergonomic types. `buildSpawnRequest` updated for the new `SpawnRequest` fields (required). - **`index.ts`**: top-level re-exports for the new public types. ## Not exposed (host-deferred) `watch` / `unwatch` (open publish-authority RFC question — poll via `status` + bounded `wait`) and resource-limit enforcement (`limits` is plumbed through but the host doesn't enforce it yet). ## Test Plan - [x] `npm run build` (tsc) green across the workspace - [x] **End-to-end:** the `examples/test-capsule` **componentizes** against the persistent WIT — ComponentizeJS produced a 12.96 MB WASM with **169 host imports**, proving the new host functions wire through the JS build path - [x] `scripts/sync-contracts-wit.sh --check` passes (events bundle untouched) - [x] Git diff scoped to 5 files (contracts pointer + 3 SDK sources + CHANGELOG); no `contracts.ts` drift
Summary
Submodule bump +
sync-contracts-wit.shregeneration to landhook-event-requestin the bundledpackages/astrid-sdk/wit-contracts/astrid-contracts.wit.Depends on
astrid-runtime/wit#11 — the record itself is added there. This PR
bumps the submodule pointer to the wit feat branch; once that PR
merges to main, the commit becomes reachable from main.
Context
Audit of all 18 capsule
Capsule.tomlfiles surfaced one referentialmiss:
astrid-capsule-hook-bridgereferences@unicity-astrid/wit/hook/hook-event-request, but the record didn'texist anywhere in this repo's bundled WIT. Adding it to the bundle
keeps the JS SDK's
codegenWitEventsoutput complete.Test plan
grep -c hook-event-request packages/astrid-sdk/wit-contracts/astrid-contracts.witreturns 1.