Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Most code changes don't need a doc change; people and agents can read the code.
- `packages/harness` - the agent: the loop, tools, sandboxes, plugins, MCP, projects and spaces, settings and the durable store. Effect-native.
- `packages/plugin` - the SDK third-party plugins and sandbox drivers build against. It owns the contracts the harness implements.
- `packages/codework` - the `codework` CLI (`@codeworksh/cli`) and its RPC server. Ships on npm and as a Node SEA binary.
- `packages/schema` - schemas shared across packages: ids, projects, spaces, locations, events, sandbox instances, Relay and signed machine requests. Browser-safe, published, one subpath per module.
- `packages/schema` - schemas shared across packages: ids, projects, spaces, locations, events, sandbox instances, the host's RPC contract, Relay and signed machine requests. Browser-safe, published, one subpath per module.
- `apps/desktop` - the Electron app. `apps/server` is its app server, `apps/web` its UI, `apps/contract` the RPC contract between them, and `apps/widget` the widget SDK.
- `infra/relay` - Relay, the cloud API for accounts, workspaces and machines. `infra/catalog` serves the model catalog.
- `extras/` - example third-party plugins, handy as templates.
Expand Down
14 changes: 7 additions & 7 deletions apps/widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ The SDK for CodeWork desktop widgets. A widget has two halves: a view, a React c

## Entry Points

| Import | What it is |
| ----------------------------- | ------------------------------------------------------------------- |
| `@codeworksh/widget/view` | `defineWidget`, the shell and frame contexts, `useBus`, `useKv` |
| `@codeworksh/widget/backend` | `defineBackend` and the `Bus`, `Kv`, `Codework` and `Sync` services |
| `@codeworksh/widget/event` | the event log's wire schemas, shared by both halves |
| `@codeworksh/widget/codework` | the CodeWork RPC contract, from `@codeworksh/schema/host` |
| Import | What it is |
| ----------------------------- | --------------------------------------------------------------------------------- |
| `@codeworksh/widget/view` | `defineWidget`, the shell and frame contexts, `useBus`, `useKv` |
| `@codeworksh/widget/backend` | `defineBackend` and the `Bus`, `Kv`, `Codework` and `Sync` services |
| `@codeworksh/widget/event` | the event log's wire schemas, shared by both halves |
| `@codeworksh/widget/codework` | host wire records from `@codeworksh/schema/host/records`, `type Api`, and helpers |

## Boundaries

Expand All @@ -22,6 +22,6 @@ The SDK for CodeWork desktop widgets. A widget has two halves: a view, a React c
- [`src/view.ts`](./src/view.ts), [`src/view`](./src/view): the view half.
- [`src/backend.ts`](./src/backend.ts): the backend half.
- [`src/event.ts`](./src/event.ts): the event contract.
- [`src/codework.ts`](./src/codework.ts): the CodeWork RPC contract, re-exported, with the helpers clients share.
- [`src/codework.ts`](./src/codework.ts): the host wire records (`@codeworksh/schema/host/records`) and `type Api`, re-exported with the helpers clients share.

See [desktop internals](../../docs/internals/11_desktop.md#widgets-and-the-bus) for how the app server runs backends and the bus replays events.
4 changes: 2 additions & 2 deletions docs/internals/01_architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CodeWork runs agents in one place: the host process that owns a home. Everything
| App | `apps/*` | The Electron shell, the app server, the UI, the app's RPC contract and the widget SDK. |
| Cloud | `infra/relay`, `infra/catalog` | Accounts, workspaces and machines; the model catalog bucket. Never runs an agent. |

`packages/schema` sits outside the domains. It holds the schemas more than one package speaks: ids, projects, spaces, locations, events and sandbox instances, which the core persists and plugins read, and the wire pieces of Relay's HTTP API, signed machine requests, pairing, and the listener's door (how a client offers its token on the WebSocket). It holds shapes only, no services and nothing from Node or aikit, so the desktop renderer can load it too. It is published as `@codeworksh/schema`, one subpath per module, so a consumer loads only what it imports.
`packages/schema` sits outside the domains. It holds the schemas more than one package speaks: ids, projects, spaces, locations, events and sandbox instances, which the core persists and plugins read; the host's RPC contract and the harness errors and wire records it carries; and the wire pieces of Relay's HTTP API, signed machine requests, pairing, and the listener's door (how a client offers its token on the WebSocket). It holds shapes only, no services and nothing from Node or aikit, so the desktop renderer can load it too. It is published as `@codeworksh/schema`, one subpath per module, so a consumer loads only what it imports.

## Dependency Direction

Expand All @@ -23,7 +23,7 @@ The workspace dependencies point one way:

The rules behind that shape:

- **`plugin` never imports `harness`.** A third-party plugin builds against `@codeworksh/plugin` alone. A capability a plugin could provide gets its contract in `plugin` first, and the harness implements against it.
- **`plugin` never imports `harness`.** A third-party plugin builds against `@codeworksh/plugin` (with its peer dependencies `@codeworksh/aikit`, `@codeworksh/schema` and `effect`), never `@codeworksh/harness`. A capability a plugin could provide gets its contract in `plugin` first, and the harness implements against it.
- **The core never imports the host.** Nothing in `harness` reaches for the CLI or the RPC server. That is what lets three hosts (`serve`, in-process `run`, `acp`) boot the same harness.
- **`aikit` is a plain SDK.** It has no Effect dependency and emits an `AsyncIterable` of canonical events. The harness meets it at one boundary, [llm.ts](../../packages/harness/src/runner/llm.ts), which owns interruption and durable terminal errors.
- **Apps reach the host only over RPC.** The app server never imports harness code and never reads project files. Space state it shows (skills, git changes) is mirrored from daemon events on the host's event stream.
Expand Down
2 changes: 1 addition & 1 deletion docs/internals/05_projects.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Projects

A project is a body of work across every place it is checked out. A space is one directory of a project in one env. A location is a space plus the exact directory a run works in. The shapes live in `packages/schema` ([project.ts](../../packages/schema/src/project.ts), [space.ts](../../packages/schema/src/space.ts), [location.ts](../../packages/schema/src/location.ts), [repo.ts](../../packages/schema/src/repo.ts)), because every plugin context carries a resolved location. Resolving one needs the database, git and a mount, so that code lives in the harness, mostly in [project.ts](../../packages/harness/src/project/project.ts).
A project is a body of work across every place it is checked out. A space is one directory of a project in one env. A location is a space plus the exact directory a run works in. The shapes live in `packages/schema` ([project.ts](../../packages/schema/src/project.ts), [space.ts](../../packages/schema/src/space.ts), [location.ts](../../packages/schema/src/location.ts), [repo.ts](../../packages/schema/src/repo.ts)), because the core, plugins, the host RPC contract and the apps all share them. Resolving one needs the database, git and a mount, so that code lives in the harness, mostly in [project.ts](../../packages/harness/src/project/project.ts).

## Identity Is Portable, Paths Are Not

Expand Down
4 changes: 2 additions & 2 deletions docs/internals/09_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ The RPC server (`codework serve`) is the only place an agent runs. It serves one

## One Contract

The contract is [host.ts](../../packages/schema/src/host.ts) in `@codeworksh/schema`, with the wire shapes of events in [envelope.ts](../../packages/schema/src/host/envelope.ts), message parts in [part.ts](../../packages/schema/src/host/part.ts) and the door's middleware and errors in [principal.ts](../../packages/schema/src/host/principal.ts). It is served at a versioned path. The version moves only with a breaking wire change.
The contract is [host.ts](../../packages/schema/src/host.ts) in `@codeworksh/schema`, with its wire data records split into [records.ts](../../packages/schema/src/host/records.ts), event envelopes in [envelope.ts](../../packages/schema/src/host/envelope.ts), message parts in [part.ts](../../packages/schema/src/host/part.ts) and the door's middleware and errors in [principal.ts](../../packages/schema/src/host/principal.ts). It is served at a versioned path. The version moves only with a breaking wire change.

The server, the CLI, the desktop app and widgets all import that one declaration. It lives in the schema package because the app's renderer loads it too, so it holds shapes only: the harness error classes in its error unions live in `packages/schema` beside it, and the harness re-exports them. What runs on the server stays in [packages/codework/src/server](../../packages/codework/src/server): encoding events against the harness's registry, the home's token and the door's implementation.
The server, the CLI and the desktop app server all import that one `Host.Api` declaration. Wire records live in `host/records.ts` (re-exported by `host.ts` and `@codeworksh/widget/codework`) so the desktop renderer, app contract and widgets load them without pulling in `effect/rpc`, `Host.Api` or server errors. The harness error classes in the contract's error unions live in `packages/schema` beside it, and the harness re-exports them. What runs on the server stays in [packages/codework/src/server](../../packages/codework/src/server): encoding events against the harness's registry, the home's token and the door's implementation.

Event `data` crosses the wire in its encoded form and is decoded lazily on the client against its own registry. Decoded payloads are not wire-safe, and a server may know event types a client does not, such as ones a plugin registers. A client skips a type it cannot decode. It must never fail on one.

Expand Down
2 changes: 1 addition & 1 deletion docs/internals/11_desktop.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Each channel installs side by side with its own identity ([electron.config.ts](.

The app server never touches project files. Browsing folders, creating and cloning projects, git diffs and skills are all RPC calls to a host ([handlers.ts](../../apps/server/src/handlers.ts)). A host call that names its machine runs over the connection Sync holds for it. One that names none goes to the default machine, over the app's main connection. The native folder picker only returns a path on this computer, so it is offered only for the default machine.

The UI speaks [apps/contract](../../apps/contract/src/contract.ts), never the harness protocol. The app server speaks the harness protocol through the host's contract in `@codeworksh/schema/host`, the one the server implements, which the widget SDK re-exports as `@codeworksh/widget/codework`. A reply it cannot decode, such as one from a server built against a different contract, surfaces as `CodeworkUnavailable`. A default server that answers `server.info` but fails `thread.list` shows as Incompatible.
The UI speaks [apps/contract](../../apps/contract/src/contract.ts), never the harness protocol. The app server speaks the harness protocol through the host's contract in `@codeworksh/schema/host`, the one the server implements; the widget SDK's `@codeworksh/widget/codework` re-exports the wire records from `@codeworksh/schema/host/records` (plus `type Api` and shared client helpers) so UI code never pulls in `effect/rpc` or server errors. A reply it cannot decode, such as one from a server built against a different contract, surfaces as `CodeworkUnavailable`. A default server that answers `server.info` but fails `thread.list` shows as Incompatible.

The CLI owns a local server's lifecycle ([cli.ts](../../apps/server/src/cli.ts)). The app runs `codework service <action>` with the server's `CODEWORK_HOME_DIR`, and never runs `serve` itself. It finds `codework` in the install script's folder, then through a login shell, because an app opened from the Dock lacks the terminal's PATH.

Expand Down
4 changes: 2 additions & 2 deletions docs/operations/00_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Every checkout shares Relay's one local database, and its README has the fix for
vp run dev:cli serve --port 0
```

This runs `packages/codework/src/index.ts` from source with the `development` condition, so the harness, aikit and plugin sources are used directly. `--port 0` picks a free port, because the installed server usually holds the default 7433. The server writes its address to `<home>/service.json`, which is how every client finds it. `vp run dev:cli service status` shows it.
This runs `packages/codework/src/index.ts` from source with the `development` condition, so the harness, aikit, plugin and schema sources are used directly. `--port 0` picks a free port, because the installed server usually holds the default 7433. The server writes its address to `<home>/service.json`, which is how every client finds it. `vp run dev:cli service status` shows it.

Flags after the task name go to the CLI. Any other command runs against the same home, for example `vp run dev:cli run "hello"` or `vp run dev:cli thread list`. Restart the server after changing harness or codework code; nothing reloads it.
Flags after the task name go to the CLI. Any other command runs against the same home, for example `vp run dev:cli run "hello"` or `vp run dev:cli thread list`. Restart the server after changing schema, harness or codework code; nothing reloads it.

### 3. Desktop App and App Server

Expand Down