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
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Of note: Most CodeWork contributions will come from CodeWork itself, often contr
The most common defect is a change that works on the path you tested and is missing everywhere else. Start with the core: harness and CLI first, then `apps/server`, then the UI. Before calling work done, walk this list and say which entries applied:

- **Providers.** Every aikit provider needs a decision, even if it's "not supported here".
- **Contracts.** Plugin-facing types go in `packages/plugin`, the app server's RPC in `apps/contract`, and Relay and signed machine requests in `packages/schema`. The host's RPC contract lives in `packages/codework/src/server/contract.ts` and is mirrored by hand in `apps/widget/src/codework.ts`, so a change there lands in both.
- **Contracts.** Plugin-facing types go in `packages/plugin`, the app server's RPC in `apps/contract`, and schemas shared across packages (ids, projects, spaces, events, sandbox instances, the host's RPC contract, Relay and signed machine requests) in `packages/schema`, one module per subpath. The host's RPC contract is `@codeworksh/schema/host`: the server implements it and the apps import it, so a change there reaches both.
- **Modes.** The CLI in-process and with `--server`; local, virtual and remote sandboxes.
- **Connections.** Local network, Tailscale and Relay, across more than one machine.
- **Reverse states.** Every way in needs a way out and a way to see it. A one-way door is a bug.
Expand Down 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` - wire schemas for Relay and signed machine requests. Private, and bundled into its consumers.
- `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.
- `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
4 changes: 2 additions & 2 deletions apps/contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ The app server's RPC contract, shared by the app server ([`apps/server`](../serv

## 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).
- 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 their contract, [`@codeworksh/schema/host`](../../packages/schema/src/host.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.
- It depends only on `effect`, `@codeworksh/schema` and `@codeworksh/widget`, and builds on the widget SDK's event schemas and the host's contract 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.

Expand Down
46 changes: 21 additions & 25 deletions apps/contract/src/contract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Machine } from "@codeworksh/schema";
import { optional } from "@codeworksh/schema/common";
import { Machine } from "@codeworksh/schema/machine";
import { Schema } from "effect";
import { Rpc, RpcGroup } from "effect/rpc";
import {
Expand All @@ -24,9 +25,6 @@ import { Event, EventTimeout, Publish, Request, Synced } from "@codeworksh/widge

export { CodeworkUnavailable, LineRequest, LineThread, SyncError, SyncThread, ThreadLine };

/** The organization the UI shows until auth exists; every synced project starts in it. */
export const PERSONAL_ORGANIZATION = "personal";

/**
* Where a thread's work is, as Linear's workflow states. `enqueued` and `working` follow its runs: a
* run starting sets `working`, which stays when it ends; prompts parked before a run set `enqueued`.
Expand Down Expand Up @@ -252,16 +250,16 @@ export const SettingsFile = Schema.Struct({
exists: Schema.Boolean,
version: Schema.String,
/** The file's JSONC as a value; absent when it does not parse. */
value: Schema.optionalKey(Schema.Unknown),
error: Schema.optionalKey(Schema.String),
value: optional(Schema.Unknown),
error: optional(Schema.String),
/** For `settings.jsonc`: what applies where this file sets nothing. */
inherited: Schema.optionalKey(
inherited: optional(
Schema.Struct({
retry: Schema.Struct({ maxRetries: Schema.Int, baseDelayMs: Schema.Int, maxDelayMs: Schema.Int }),
}),
),
/** For `mcp.json`: the servers as sessions use them, user and project merged. */
servers: Schema.optionalKey(
servers: optional(
Schema.Array(
Schema.Struct({ name: Schema.String, from: Schema.Literals(["user", "project"]), enabled: Schema.Boolean }),
),
Expand Down Expand Up @@ -586,18 +584,17 @@ export const SyncStatus = Schema.Struct({
});
export type SyncStatus = typeof SyncStatus.Type;

/** A custom group of an organization's threads, in its own `ordering`. */
/** A custom group of threads, in its own `ordering`. */
export const Grouping = Schema.Struct({
id: Schema.String,
organizationId: Schema.String,
name: Schema.String,
/** Hex, `#rrggbb`. */
color: Schema.NullOr(Schema.String),
ordering: Schema.Number,
});
export type Grouping = typeof Grouping.Type;

/** Where a moved thread or group goes in its organization's list: first, last, or between two neighbours. */
/** Where a moved thread or group goes in its list: first, last, or between two neighbours. */
export const Position = Schema.Union([
Schema.Literals(["first", "last"]),
Schema.Struct({ after: Schema.String, before: Schema.String }),
Expand All @@ -623,7 +620,7 @@ export const SyncTracking = Schema.Union([
]);
export type SyncTracking = typeof SyncTracking.Type;

/** What All Threads splits an organization's threads by. */
/** What All Threads splits the threads by. */
export const ThreadsBy = Schema.Literals(["status", "priority", "grouping"]);
export type ThreadsBy = typeof ThreadsBy.Type;

Expand Down Expand Up @@ -662,9 +659,9 @@ export const ThreadList = Schema.Union([
export type ThreadList = typeof ThreadList.Type;

/**
* An organization's threads split into lists, each present even when empty: by status, by priority
* (urgent first, none last), or by group (groups in their `ordering`, ungrouped last). The
* organization's groups come with it, in their `ordering`, whatever the split.
* The threads split into lists, each present even when empty: by status, by priority (urgent first,
* none last), or by group (groups in their `ordering`, ungrouped last). The groups come with it, in
* their `ordering`, whatever the split.
*/
export const AllThreads = Schema.Struct({
lists: Schema.Array(ThreadList),
Expand Down Expand Up @@ -798,7 +795,7 @@ export class MetricsError extends Schema.TaggedError<MetricsError>()("Server.Met
message: Schema.String,
}) {}

/** A desktop edit refused: a value out of range, or a thread, session, group or organization not found. */
/** A desktop edit refused: a value out of range, or a thread, session or group not found. */
export class TrackingError extends Schema.TaggedError<TrackingError>()("Server.TrackingError", {
message: Schema.String,
}) {}
Expand All @@ -811,7 +808,7 @@ const OnMachine = { machineId: Schema.optionalKey(Schema.String) };

export const Api = RpcGroup.make(
/**
* An organization's active projects, newest activity first, each with its sessions that are not
* The active projects, newest activity first, each with its sessions that are not
* deleted: on the default machine only, or on every machine. Read from app.db alone.
*/
/** A project's directories, its main checkout first; read from app.db alone. */
Expand Down Expand Up @@ -845,7 +842,7 @@ export const Api = RpcGroup.make(
error: Schema.Union([CodeworkUnavailable, ChangesError]),
}),
Rpc.make("sidebar.list", {
payload: { organizationId: Schema.String, machines: Schema.Literals(["default", "all"]) },
payload: { machines: Schema.Literals(["default", "all"]) },
success: Schema.Array(SidebarProject),
}),
/** One page of a thread's line with its pending inbox, read from app.db alone; below `floor`, `sync.page` first. */
Expand All @@ -854,9 +851,9 @@ export const Api = RpcGroup.make(
success: ThreadLine,
error: SyncError,
}),
/** An organization's threads that are not deleted, subagents left out, split by `by` into lists in `ordering`. Read from app.db alone. */
/** The threads that are not deleted, subagents left out, split by `by` into lists in `ordering`. Read from app.db alone. */
Rpc.make("threads.list", {
payload: { organizationId: Schema.String, by: ThreadsBy },
payload: { by: ThreadsBy },
success: AllThreads,
}),
/** Usage from `since` to `until`, both local days included, summed over threads and stores. Read from app.db alone. */
Expand Down Expand Up @@ -916,7 +913,7 @@ export const Api = RpcGroup.make(
/** A new git-initialised folder under `projects`; `commitError` says why the first commit was skipped. */
Rpc.make("host.create", {
payload: { ...OnMachine, name: Schema.String },
success: Schema.Struct({ path: Schema.String, commitError: Schema.optionalKey(Schema.String) }),
success: Schema.Struct({ path: Schema.String, commitError: optional(Schema.String) }),
error: Schema.Union([CodeworkUnavailable, HostError]),
}),
/** The `origin` URL of a project's main checkout, credentials taken out; null when it has none. */
Expand Down Expand Up @@ -996,7 +993,7 @@ export const Api = RpcGroup.make(
/** Whether `gh` is installed and signed in; `hint` says what to do when it is not. */
Rpc.make("github.status", {
payload: OnMachine,
success: Schema.Struct({ ready: Schema.Boolean, hint: Schema.optionalKey(Schema.String) }),
success: Schema.Struct({ ready: Schema.Boolean, hint: optional(Schema.String) }),
error: CodeworkUnavailable,
}),
/** A repository by `owner/name`, `host/owner/name`, its URL, or a bare name of the signed-in user's. */
Expand Down Expand Up @@ -1134,7 +1131,7 @@ export const Api = RpcGroup.make(
success: Schema.Void,
error: TrackingError,
}),
/** Puts a thread in a group of its organization; `null` ungroups it. */
/** Puts a thread in a group; `null` ungroups it. */
Rpc.make("threads.setGroup", {
payload: { threadId: Schema.String, groupingId: Schema.NullOr(Schema.String) },
success: Schema.Void,
Expand All @@ -1151,10 +1148,9 @@ export const Api = RpcGroup.make(
success: Schema.Void,
error: TrackingError,
}),
/** A new group, last in its organization. */
/** A new group, last in the list. */
Rpc.make("groups.create", {
payload: {
organizationId: Schema.String,
name: Schema.String,
color: Schema.optionalKey(Schema.NullOr(Schema.String)),
},
Expand Down
2 changes: 1 addition & 1 deletion apps/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The desktop app's own Node server. Electron main starts it, and the UI talks to

- 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).
- The UI speaks [`@codeworksh/contract`](../contract). This server speaks the harness protocol through its contract, [`@codeworksh/schema/host`](../../packages/schema/src/host.ts).

## Code Map

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os from "node:os";
import path from "node:path";
import { Codework } from "./codework.ts";
import { type CliAction, type CliInstall, type CliServer, ServersError, type ServerStatus } from "@codeworksh/contract";
import { Jws } from "@codeworksh/schema";
import { Jws } from "@codeworksh/schema/jws";
import { Servers } from "./servers.ts";

// Where the install script puts the binary unless told otherwise.
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/codework.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Codework as Mirror } from "@codeworksh/widget/codework";
import { Host as Mirror } from "@codeworksh/schema/host";
import { Codework as Client } from "@codeworksh/widget/backend";
import { NodeSocket } from "@effect/platform-node";
import { Deferred, Duration, Effect, FileSystem, Layer, Option, Schedule, Schema, Stream } from "effect";
Expand All @@ -7,7 +7,7 @@ import { Socket } from "effect/socket";
/* @effect-diagnostics nodeBuiltinImport:off -- a home's registration is a file path. */
import path from "node:path";
import { CodeworkUnavailable, HostError } from "@codeworksh/contract";
import { Door } from "@codeworksh/schema";
import { Door } from "@codeworksh/schema/door";
import { Pairing } from "./pairing.ts";
import { Servers } from "./servers.ts";

Expand Down
Loading