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
210 changes: 148 additions & 62 deletions AGENTS.md

Large diffs are not rendered by default.

100 changes: 1 addition & 99 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,99 +1 @@
# Personal Preference

## TypeScript

- Never use `any` unless 100% necessary or specifically instructed.
- Use effect only if the project uses effect or specifically instructed, use effect reference repository for latest architecture patterns.

## Commands

- Don't run dev server commands (e.g `pnpm run dev`, `bun run dev`) - assume it's already running.
- Don't run build commands unless specifically told to.
- Focus on checking commands like `pnpm run check`, `bun run lint` `bun run typecheck`, etc.

## Package Managers

- Use `pnpm`, `vp - vite plus` if the project already uses it, otherwise use `pnpm`
- Never use `npm` or `yarn`

## Tech Stack Preference

When uncertain, prefer: Effect, Tailwind, TypeScript, React, Clerk, TanStack, Vercel, Vite.

## Code Style

- Always strive for concise, simple solutions.
- If a problem can be solved in a simpler way, propose it.
- No pre-mature optimizations, propose if required.
- Use single word filename whenever possible otherwise split into kabab-case(only if no options).

## General Preferences

- If asked to do too much work at once, stop and state that clearly.
- After you yourself have verified the work, get the work peer reviewed by another agent: `codex` for `code reviews`, `focused deep checks`, `tweaks`, `tests review` shell out to `gpt-6.1-sol` with thinking `low` or `medium` depending on complexity.
- Avoid defensive future-facing design. This leads to pre-mature assumptions which are never true.

## Maintainability

Long term maintainability is a core priority. If you add new functionality, first check if there is shared logic that can be extracted to a separate module. Duplicate logic across multiple files is a code smell and should be avoided. Don't be afraid to change existing code. Don't take shortcuts by just adding local logic to solve a problem.

## Package Roles

- `packages/aikit` - Low level SDK that provides unified LLM API for multiple LLM providers.
- `packages/harness` - Effect powered main Agent Harness application, uses `packages/aikit` under the hood.
- `packages/plugin` - The published SDK third-party plugin and sandbox-driver packages build against. It owns the shared contract (plugin, tool, sandbox mount, event and settings types); `packages/harness` depends on it, never the other way round.
- `packages/tui` - Paused: kept in the tree but outside the workspace; not checked, built, bundled or published.
- `.scratch/packages` - Local, ignored reference archive for packages that are no longer developed.

## Vendored Repositories

This project vendors external repositories under `.repos/` as read-only reference material for coding agents.

- Prefer examples and patterns from the vendored source code over generated guesses or web search results.
- Do not edit files under .repos/ unless explicitly asked.
- Do not import from `.repos/`; application code must continue importing from normal package dependencies.
- When writing Effect code, read `.repos/effect-smol/LLMS.md` first and inspect `.repos/effect-smol/` for examples of idiomatic usage, tests, module structure, and API design.

## Personal Notes & Document Spec

This project uses private design documents under `.notes/` as implementation reference for coding agents. When specified use it for planning, designing and brainstorming. When creating, mention in doc current date and git commit ID if available.

- Allow the design docs to be reviewed by subagents when see fit.
- Propose improvements when see fit.

## Testing

- Never write unit tests after you write code.
- Highly prefer E2E tests as the sole testing mechanism. Use them to verify complex features work (spawn the real CLI, boot the real runtime, hit the real provider or sandbox).
- At the end of an E2E test, produce a verifiable and repeatable artifact under `__artifacts__/` (e.g. a path-normalised `toMatchFileSnapshot("./__artifacts__/<name>.json")` that fails on drift and regenerates with `-u`). Do not use `__snapshots__/`.
- If you must test a system in isolation, first write down all the ways it could fail, then write the code. Only keep an isolated test if it catches a real bug the E2E tests miss (wire-protocol parsing, OAuth refresh, cancellation/concurrency, data integrity, security boundaries).

## Task Completion Requirements

- `vp check` and `vp run typecheck` must pass before considering tasks completed, unless otherwise specified.
- Use `vp test` for the built-in Vite+ test command and `vp run test` when you specifically need the test package script.

## Commit & Pull Request Guidelines

Conventional Commit style with optional package scopes, e.g `feat(aikit): ...`, `fix(aikit): ...`, and `chore: ...`. Keep commit subjects imperative and concise.

## Releasing

Every package is published by CI from `.github/workflows/publish.yml`, which runs `vp run release <channel>` (`scripts/release.mjs`). It publishes the packages in dependency order, derived from their `package.json` workspace dependencies (`scripts/workspace.mjs`), pinning each package to the exact versions uploaded in the same run. `scripts/publish.mjs` builds a single package, rewrites its manifest and publishes it from a temp dir.

- **canary**: every push to `canary`, without `vp check` or typecheck, for quick testing. Versions are `<version>-canary.<run>.<attempt>.g<sha>`. It also packages the desktop app (`apps/desktop`, `vp run package <channel>`) as "CodeWork Canary" for macOS arm64, Linux x64/arm64 and Windows x64/arm64, and replaces the `nightly` prerelease with it.
- **dev**: every push to `dev`. Versions are `<version>-dev.<YYYYMMDDHHMMSS>` (UTC).
- **latest**: run the workflow by hand on `main`. It publishes each package whose manifest version is not on npm yet and skips the rest.

GitHub Releases (`scripts/github.mjs`): dev replaces the `devel` prerelease with the CLI binaries; latest makes a `<pkg>@v<version>` release per package not released yet, the CLI's carrying the binaries. canary replaces the `nightly` prerelease with the desktop app.

Versions are bumped locally with `vp run bump <aikit|plugin|harness|cli|desktop> [version]`, which runs `bumpp` with the package's `bump.config.ts` and commits and tags `<pkg>@v<version>` without pushing.

Flow:

1. Update `CHANGELOG.md` — move the entry from `[Unreleased]` into a versioned section.
2. `vp run bump <pkg>` for each package to release.
3. `git push && git push --tags`, then merge to `main`.
4. Run the Publish workflow on `main`.

`vp run release <channel> --dry-run` previews the chain locally.
@AGENTS.md
43 changes: 43 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contributing to CodeWork

Thanks for helping out. This guide is short so it saves time for you and for us.

## What We Welcome

Pull requests are welcome, and we're glad to see them. The ones we can merge quickly:

- Fix a bug you can reproduce.
- Solve a real problem you or other users have hit.
- Improve performance, docs or tests.

New features are welcome too, but please open an issue first. Every feature we merge is one we support for a long time, across every provider and every surface (the RPC server, the CLI and the desktop app). Talking it through first saves you building something we can't take on.

If a feature could be a plugin, it probably should be. The plugin contract in `packages/plugin` exists so CodeWork can grow without its core getting heavier.

## The One Rule

**Understand your code.** You should be able to explain what your change does and how it fits with the rest of the system.

Using AI to write code is fine, and CodeWork itself is a coding agent. Just review what it wrote before you send it. If you use an agent, run it from the repository root so it reads [AGENTS.md](AGENTS.md).

## Issues

Keep issues short and concrete:

- Say what happened and what you expected, or what you'd like to see.
- Explain why it matters.
- Include steps to reproduce a bug, your version (`codework --version`), and your platform.
- If you'd like to work on it yourself, say so.

## Before You Open a PR

1. Set up the repository with [00_development.md](docs/operations/00_development.md).
2. Run `vp run verify`. It's the check CI runs on every pull request.
3. Run the tests for the code you changed. CI doesn't run them, so this part is on you. [13_testing.md](docs/internals/13_testing.md) explains how.
4. Target the `canary` branch.

Please don't edit `CHANGELOG.md` or bump versions. The maintainers write release notes and cut releases.

## Questions

[Open an issue](https://github.com/codeworksh/codework/issues). We're happy to help.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ List every provider and model with `codework models`.
- **Persistent sessions** — resume any session by ID; state lives in a local database.
- **Sandboxes** — run locally or in `daytona`, `vercel`, `memory`, or `sqldb` sandboxes.
- **Server mode** — `codework serve` owns sessions and sandboxes; clients attach with `--server`.
- **Plugins** — `codework plugin add <pkg>` adds tools, prompts, and sandbox drivers, per project or globally (`-g`).
- **Plugins** — `codework plugin add <pkg>` adds tools, prompt sections, and MCP servers, per project or globally (`-g`).

See the [docs](https://codework.sh/docs/) for every command and flag.

Expand All @@ -65,12 +65,11 @@ Requires Node.js 24.14.1+ and pnpm.
git clone https://github.com/codeworksh/codework.git
cd codework
pnpm install
pnpm cli -- --help # run the CLI from source
pnpm exec vp check
pnpm exec vp run typecheck
vp run dev:cli --help # run the CLI from source
vp run verify # the checks CI runs
```

Read [AGENTS.md](./AGENTS.md) for repository conventions, and [open an issue](https://github.com/codeworksh/codework/issues) for bugs or ideas.
Read [CONTRIBUTING.md](./CONTRIBUTING.md) before opening a pull request, [docs/operations/00_development.md](./docs/operations/00_development.md) to run the dev servers, and [AGENTS.md](./AGENTS.md) for repository conventions.

## Acknowledgements

Expand Down
19 changes: 19 additions & 0 deletions apps/contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contract

The app server's RPC contract, shared by the app server ([`apps/server`](../server)) and the UI ([`apps/web`](../web)). One file, [`src/contract.ts`](./src/contract.ts), exported as `Contract`: the schemas, errors and the `Contract.Api` RPC group.

## Boundaries

- This is the desktop app's own protocol, not the harness protocol. The UI speaks only this; the app server translates to CodeWork RPC servers through the mirror in [`@codeworksh/widget/codework`](../widget/src/codework.ts).
- It holds desktop-only shapes too, such as thread status and grouping for issue tracking, which never reach the harness.
- It depends only on `effect`, `@codeworksh/schema` and `@codeworksh/widget`, and builds on the widget SDK's event and mirror schemas rather than redefining them.

A change here is a change to both sides: update the handler in [`apps/server/src/handlers.ts`](../server/src/handlers.ts) and the callers in `apps/web` together.

## Code Map

- [`src/contract.ts`](./src/contract.ts): every schema and the `Api` group.

## Working Locally

`vp run typecheck` here checks the contract alone. See [desktop internals](../../docs/internals/11_desktop.md) for how the app server and UI use it.
39 changes: 39 additions & 0 deletions apps/desktop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Desktop

The Electron app. Main hosts the window, serves the UI from [`apps/web`](../web) and starts the app server from [`apps/server`](../server) as a child process. It is a client: agents run on a CodeWork RPC server, never here.

## What It Owns

- **The window and its scheme.** Main serves the built UI from `codework://app` when packaged and `codeworkdev://app` from the repo, or proxies to a web dev server when `CODEWORK_WEB_URL` is set.
- **The app server's lifetime.** Main runs it with Electron's own binary and `ELECTRON_RUN_AS_NODE`, so no system Node is needed. If the app server exits, the app quits, and quitting waits for it to stop.
- **The bridge.** The renderer is sandboxed and sees only the narrow `desktopBridge` from the preload: the app server's URL and token, the home folder, a folder picker and reveal.
- **Channels.** Each channel (`latest`, `dev`, `canary`, and `local` from the repo) installs side by side with its own identity and data.

Main holds no CodeWork state and makes no RPC calls of its own. Everything the UI shows comes through the app server, so the app keeps one owner for app.db and one client of each host.

## Code Map

- [`src/main.ts`](./src/main.ts): app lifecycle, the custom scheme, the window and the single-instance lock.
- [`src/server.ts`](./src/server.ts): starts the app server and reads its ready line.
- [`src/preload.ts`](./src/preload.ts): the `desktopBridge` the renderer sees.
- [`src/ipc.ts`](./src/ipc.ts): IPC channel names shared by main and preload.
- [`src/manifest.ts`](./src/manifest.ts): the packaged manifest and the current channel.
- [`electron.config.ts`](./electron.config.ts): electron-builder config, one identity per channel.
- [`scripts/dev.mjs`](./scripts/dev.mjs): the dev loop behind `vp run dev:desktop`.
- [`scripts/package.mjs`](./scripts/package.mjs): builds the web app, the app server and this app, then packages them.

## Working Locally

From the repository root, with a dev home exported:

```sh
vp run dev:desktop
```

This starts the UI on Vite, watches the Electron and app server bundles, and opens Electron as **CodeWork Local**. To package a build, run this from `apps/desktop`:

```sh
vp run package <canary|dev|latest> [electron-builder args] # e.g. latest --mac --arm64 --dir
```

See [development](../../docs/operations/00_development.md) for the dev home and run order, and [desktop internals](../../docs/internals/11_desktop.md) for processes, channels and data.
34 changes: 34 additions & 0 deletions apps/server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# App Server

The desktop app's own Node server. Electron main starts it, and the UI talks to it over WebSocket RPC. It owns `app.db` and is a client of one or more CodeWork RPC servers, local and paired.

## What It Owns

- **app.db.** Kept at `<home>/desktop/<channel>/app.db`, where `<home>` is `CODEWORK_HOME_DIR`, else `~/.codework`. Tests name the file with `CODEWORK_DATABASE`.
- **The machine list.** Every RPC server the app knows is a row: local ones found through a home, remote ones paired with a one-time code.
- **A mirror of host state.** The sync keeps app.db a copy of each machine's sessions, threads and usage, so reads answer while a machine is away. Commands go to the machine a session is on.
- **Desktop-only state.** Issue tracking, tabs, the desk, per-package kv and the event bus live here and nowhere else.
- **Widget backends.** Built-in backends from [`@codeworksh/web/backends`](../web/src/widgets/backends.ts) run inside this process.

## Boundaries

- It never touches project files. Folders, projects, clones, git diffs and skills are all RPC calls to a host. The host is where agents run and where files live, so the app works the same against a remote machine.
- It never runs `codework serve`. A local server's lifecycle goes through `codework service <action>`.
- The UI speaks [`@codeworksh/contract`](../contract). This server speaks the harness protocol through the mirror in [`@codeworksh/widget/codework`](../widget/src/codework.ts).

## Code Map

- [`src/index.ts`](./src/index.ts): process entry.
- [`src/server.ts`](./src/server.ts): the RPC listener, its token check and the layer graph.
- [`src/handlers.ts`](./src/handlers.ts): the contract's handlers.
- [`src/servers.ts`](./src/servers.ts): the machine table and local homes.
- [`src/codework.ts`](./src/codework.ts): connections to CodeWork RPC servers.
- [`src/pairing.ts`](./src/pairing.ts): pairing remote machines.
- [`src/sync.ts`](./src/sync.ts), [`src/mirror.ts`](./src/mirror.ts): mirroring host state into app.db.
- [`src/reads.ts`](./src/reads.ts): reads served from app.db.
- [`src/event.ts`](./src/event.ts), [`src/widgets.ts`](./src/widgets.ts): the event bus and widget backends.
- [`src/cli.ts`](./src/cli.ts): installing and running the `codework` CLI for local servers.

## Working Locally

It runs as part of `vp run dev:desktop` from the root. On its own, `vp run dev` here rebuilds the bundle on change and `vp test` runs the tests; the `live` project needs OrbStack machines. See [development](../../docs/operations/00_development.md), [testing](../../docs/internals/13_testing.md) and [desktop internals](../../docs/internals/11_desktop.md).
28 changes: 28 additions & 0 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Web

The desktop app's UI: React, TanStack Router and Tailwind, rendered inside Electron. It shows what the app server mirrors from CodeWork RPC servers and sends commands back through it.

## Boundaries

- It reaches CodeWork state only through the app server, over [`@codeworksh/contract`](../contract). It never speaks the harness protocol, so one connection carries every machine.
- Account and workspace calls are the exception: they go straight to Relay over HTTP.
- Electron hands it the app server's URL and token through `window.desktopBridge`. A plain browser has no bridge, so its calls fail and widgets say so.
- It also exports the built-in widget backends as `@codeworksh/web/backends`, which the app server runs.

## Code Map

- [`src/main.tsx`](./src/main.tsx): entry, router and auth providers.
- [`src/routes`](./src/routes): file-based routes.
- [`src/kernel/rpc.ts`](./src/kernel/rpc.ts): the app server's RPC client as atoms.
- [`src/kernel/host.ts`](./src/kernel/host.ts): the bus and kv that widget views see.
- [`src/kernel/relay.ts`](./src/kernel/relay.ts): Relay calls for accounts and workspaces.
- [`src/kernel/keep.ts`](./src/kernel/keep.ts): reuses unchanged items between reads, so memoized rows skip rendering.
- [`src/shell`](./src/shell): the app frame, title bar, palette and switcher.
- [`src/wm`](./src/wm): the window manager for widget instances and tabs.
- [`src/widgets`](./src/widgets): built-in widgets (threads, session, changes) and [`backends.ts`](./src/widgets/backends.ts).
- [`src/settings`](./src/settings): settings pages, machines included.
- [`src/components`](./src/components): shared components; `ui` holds the shadcn primitives.

## Working Locally

Run it inside the app with `vp run dev:desktop` from the root; UI changes hot-reload. Vite listens on the fixed `127.0.0.1:5173`, so one checkout runs the desktop app at a time. See [development](../../docs/operations/00_development.md), and [desktop internals](../../docs/internals/11_desktop.md) for the bus, the window manager and UI performance.
Loading