Skip to content

feat(contracts): regenerate bundle with hook-event-request#12

Open
joshuajbouw wants to merge 2 commits into
mainfrom
feat/sync-hook-event-request
Open

feat(contracts): regenerate bundle with hook-event-request#12
joshuajbouw wants to merge 2 commits into
mainfrom
feat/sync-hook-event-request

Conversation

@joshuajbouw

@joshuajbouw joshuajbouw commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Submodule bump + sync-contracts-wit.sh regeneration to land
hook-event-request in the bundled
packages/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.toml files surfaced one referential
miss: astrid-capsule-hook-bridge references
@unicity-astrid/wit/hook/hook-event-request, but the record didn't
exist anywhere in this repo's bundled WIT. Adding it to the bundle
keeps the JS SDK's codegenWitEvents output complete.

Test plan

  • grep -c hook-event-request packages/astrid-sdk/wit-contracts/astrid-contracts.wit
    returns 1.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +315 to +326
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>,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
joshuajbouw added a commit that referenced this pull request Jun 7, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant