Ir al contenido

Daemon contract & TS types

Esta página aún no está disponible en tu idioma.

crates/chronos-contract is the wire contract between chronosd and its clients. It has two halves: ipc — plain serializable message DTOs, the source of the generated TypeScript types — and transport — a framed, cross-platform local transport (Unix socket on macOS, named pipe on Windows). Like chronos-core, the crate depends on nothing else in the workspace, so the CLI can depend on the contract without pulling in the daemon’s internals.

The TypeScript package packages/contract-ts (@aluxion/chronos-contract) is generated from the Rust source of truth by typeshare, from the #[typeshare]-annotated DTOs:

Terminal window
cargo install typeshare-cli # one-time, if not already on PATH
just gen-contract # writes packages/contract-ts/src/generated.ts

src/generated.ts is committed so consumers don’t need the Rust toolchain — but it is generated output: never edit it by hand. The dashboard and any future cloud client consume these types instead of hand-rolling DTOs, so panel and daemon never drift.

Typecheck the package with:

Terminal window
pnpm install && pnpm typecheck
  • All *View data typesWorkspaceView, SessionView, InsightsView, AgentEventView, FileEntryView, FileChangeView, CheckResultView, McpView, ContextView, MemoryView, ScriptOutcomeView, and the rest.
  • The Response frame — an adjacently tagged ({ kind, data }) discriminated union, matching exactly what the daemon emits and the dashboard switches on.

Request is intentionally not exported to TS: it is internally tagged ({ op, ...fields }, the shape the web client posts to /rpc), and typeshare only models adjacently tagged enums. Forcing it through typeshare would change the wire format and break the existing client for no gain.

Whenever you change types in chronos-contract:

  1. Edit the Rust DTOs in crates/chronos-contract.
  2. Run just gen-contract to regenerate packages/contract-ts/src/generated.ts.
  3. Update the dashboard and API consumers in the same PR.

The regenerated types and every consumer update land together — a PR that changes the contract without regenerating, or regenerates without updating consumers, is incomplete.