Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a7d3db8
feat(relay): add relay API with Clerk sign-in and default workspace
sanchitrk Nov 17, 2026
f6d3342
feat: connect machines to workspaces through the relay
sanchitrk Nov 17, 2026
ae1399c
feat(desktop): sign in with Clerk and pick a workspace
sanchitrk Nov 17, 2026
9277255
feat(desktop): connect, list and rename machines from the app
sanchitrk Nov 17, 2026
2b92e16
feat(desktop): install codework from the app
sanchitrk Nov 17, 2026
b4cdd3a
fix(desktop): keep sign-up inside the app
sanchitrk Nov 17, 2026
0c8e497
feat(relay): create workspaces
sanchitrk Nov 17, 2026
9f4439c
feat(desktop): create workspaces and a Linear-style workspace menu
sanchitrk Nov 17, 2026
7d734dd
fix(desktop): no blank page while signing out
sanchitrk Nov 17, 2026
82d9c31
feat(desktop): profile settings and a Linear-style light theme
sanchitrk Nov 17, 2026
dfbc16d
fix
sanchitrk Nov 17, 2026
9acbfe0
tweaks
sanchitrk Nov 17, 2026
b334533
feat(relay): list pending connects, decline them and remove machines
sanchitrk Nov 17, 2026
acd267a
feat(desktop): machines page with requests, manual codes and disconnect
sanchitrk Nov 17, 2026
15cd915
fix: declined connects, typed codes and fresher machine state
sanchitrk Nov 17, 2026
e16f503
fix: confirmed machine links, recoverable sign-in and a connection st…
sanchitrk Nov 18, 2026
08fa096
fix: connect hints, custom-home commands and sign-in outage on first …
sanchitrk Nov 18, 2026
7813797
fix: handle session expiry, stale machine links and home switches
sanchitrk Nov 18, 2026
7114e82
fix(desktop): restore the metrics page width
sanchitrk Nov 18, 2026
65d81ac
feat(desktop): a Linear-style dark theme
sanchitrk Nov 18, 2026
14a1d17
fix(desktop): show setup step failures in red
sanchitrk Nov 18, 2026
bb9d23b
feat: bind every machine link to one identity key (#172)
sanchitrk Nov 19, 2026
00a8ac3
feat: pair machines with keys, and a Machines page that says what's t…
sanchitrk Nov 23, 2026
0d4b046
fix(web): keep membershipOf local to the Machines settings
sanchitrk Nov 23, 2026
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
1 change: 1 addition & 0 deletions apps/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@codeworksh/schema": "workspace:*",
"@codeworksh/widget": "workspace:*",
"effect": "4.0.5"
},
Expand Down
113 changes: 105 additions & 8 deletions apps/contract/src/contract.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Machine } from "@codeworksh/schema";
import { Schema } from "effect";
import { Rpc, RpcGroup } from "effect/rpc";
import {
Expand Down Expand Up @@ -374,7 +375,7 @@ export const ServerKind = Schema.Literals(["local", "remote"]);
/** The server the app always has, which cannot be removed. */
export const LOCAL_SERVER = "local";

/** How a server is named: the user's `override`, else the `host` name its server reports, else where it is. */
/** How a local server is named: the user's `override`, else the `host` name its server reports. */
const ServerNaming = {
/** As shown. */
name: Schema.String,
Expand Down Expand Up @@ -405,13 +406,57 @@ export const LocalServerStatus = Schema.Struct({
});
export type LocalServerStatus = typeof LocalServerStatus.Type;

/** A remote server: only where to reach it; it has no executable or home here. */
/**
* What keeps a paired machine from connecting: `machine`, its address answers with another key;
* `clock`, its clock is past the proof window from this computer's.
*/
export const Mismatch = Schema.Union([
Schema.Struct({
kind: Schema.Literal("machine"),
/** The fingerprint of the key the address answers with, `SHA256:<thumbprint>`; none when it presents none. */
fingerprint: Schema.NullOr(Schema.String),
}),
Schema.Struct({
kind: Schema.Literal("clock"),
/** The machine's clock minus this computer's, in milliseconds; positive when the machine is ahead. */
skew: Schema.Number,
}),
]);
export type Mismatch = typeof Mismatch.Type;

/**
* A paired machine: a server on another computer, reached with a pairing code. It has no executable or
* home here. Its hostname and label are the machine's own, as it last reported them.
*/
export const RemoteServerStatus = Schema.Struct({
id: Schema.String,
kind: Schema.Literal("remote"),
...ServerNaming,
/** As shown: its label, else its hostname, else where it is. */
name: Schema.String,
/** The computer's own name; none before the machine was ever reached. */
host: Schema.NullOr(Schema.String),
/** The friendly name stored on the machine; none when it has none. */
label: Schema.NullOr(Schema.String),
isDefault: Schema.Boolean,
url: Schema.String,
/** Whether this app's key is paired on it; false once the server refuses it (revoked or lapsed): pair again. */
paired: Schema.Boolean,
/** The fingerprint of the key it paired with, `SHA256:<thumbprint>`; none on a row from before keys. */
fingerprint: Schema.NullOr(Schema.String),
/** What last kept it from connecting while paired; pairing again takes the key a `machine` mismatch answers with. */
mismatch: Schema.NullOr(Mismatch),
/** Whether it is answering now. */
online: Schema.Boolean,
/** When it last answered, in epoch milliseconds; none before it ever did. */
seenAt: Schema.NullOr(Schema.Number),
/** The build it last reported; none before it was ever reached. */
version: Schema.NullOr(Schema.String),
/** The machine's own id, as it last reported it; none before it was reached or before its first connect. */
machineId: Schema.NullOr(Schema.String),
/** The workspaces it is linked to, each with the thumbprint of its key, as it last reported them. */
workspaces: Schema.Array(
Schema.Struct({ id: Schema.String, keyId: Schema.String, leaving: Schema.optionalKey(Schema.Boolean) }),
),
});
export type RemoteServerStatus = typeof RemoteServerStatus.Type;

Expand All @@ -431,8 +476,9 @@ export const CliAction = Schema.Literals(["start", "restart", "stop"]);
export type CliAction = typeof CliAction.Type;

/**
* A new server. A local one needs a home of its own, since a home names one server; a remote one
* needs its WebSocket URL. A blank or absent `name` is no override.
* A new server. A local one needs a home of its own, since a home names one server; a blank or absent
* `name` is no override. A remote one needs its WebSocket URL and a pairing code from
* `codework service pair` on that machine; it is named by its own label.
*/
export const ServerAdd = Schema.Union([
Schema.Struct({
Expand All @@ -442,13 +488,18 @@ export const ServerAdd = Schema.Union([
home: Schema.String,
args: Schema.String,
}),
Schema.Struct({ kind: Schema.Literal("remote"), name: Schema.optionalKey(Schema.String), url: Schema.String }),
Schema.Struct({
kind: Schema.Literal("remote"),
url: Schema.String,
code: Schema.String,
}),
]);
export type ServerAdd = typeof ServerAdd.Type;

/**
* Changes to a server; an absent field is left as it is. A `null` path goes back to the one found;
* a blank `name` removes the override; `env` replaces every variable. `url` is for a remote server only, the rest but `name` for a local one.
* a blank `name` removes the override; `env` replaces every variable. `url` and `code` are for a remote
* server only, the rest for a local one; a `code` pairs again, at the new `url` when given.
*/
export const ServerUpdate = Schema.Struct({
id: Schema.String,
Expand All @@ -458,6 +509,7 @@ export const ServerUpdate = Schema.Struct({
args: Schema.optionalKey(Schema.String),
env: Schema.optionalKey(Schema.Array(CliEnvVar)),
url: Schema.optionalKey(Schema.String),
code: Schema.optionalKey(Schema.String),
});
export type ServerUpdate = typeof ServerUpdate.Type;

Expand All @@ -467,6 +519,11 @@ export class ServersError extends Schema.TaggedError<ServersError>()("Server.Ser
message: Schema.String,
}) {}

/** A remote server refused the pairing code: wrong, used or expired. */
export class PairingRefused extends Schema.TaggedError<PairingRefused>()("Server.PairingRefused", {
message: Schema.String,
}) {}

/** The app bus topics the sync publishes on. */
export const syncTopics = {
/** `SyncChanged` after each applied batch; stored. */
Expand Down Expand Up @@ -817,6 +874,30 @@ export const Api = RpcGroup.make(
success: ModelList,
error: Schema.Union([CodeworkUnavailable, ModelsError]),
}),
/** The default machine and the workspaces it is connected to. */
Rpc.make("machine.info", {
success: Machine.Status,
error: CodeworkUnavailable,
}),
/** Names the default machine for people; an empty name goes back to the OS's. */
Rpc.make("machine.rename", {
payload: { givenName: Schema.String },
success: Machine.Status,
error: CodeworkUnavailable,
}),
/** Disconnects the default machine, or the paired machine `serverId`, from a workspace. */
Rpc.make("machine.disconnect", {
payload: { ...Machine.Disconnect.fields, serverId: Schema.optionalKey(Schema.String) },
success: Machine.Disconnected,
error: Schema.Union([CodeworkUnavailable, ServersError, Machine.ConnectError]),
}),
/** Connects the default machine, or the paired machine `serverId`, to a workspace: the code to approve, then the link. */
Rpc.make("machine.connect", {
payload: { workspaceId: Schema.String, serverId: Schema.optionalKey(Schema.String) },
success: Machine.ConnectEvent,
error: Schema.Union([CodeworkUnavailable, ServersError, Machine.ConnectError]),
stream: true,
}),
/** The OS home directory, and the folder `host.create` makes projects in. */
Rpc.make("host.info", {
success: Schema.Struct({ home: Schema.String, projects: Schema.String }),
Expand Down Expand Up @@ -970,15 +1051,25 @@ export const Api = RpcGroup.make(
payload: ServerHealth,
success: Schema.Void,
}),
/** A remote server is paired with its code before it is stored. */
Rpc.make("servers.add", {
payload: ServerAdd,
success: Schema.String,
error: ServersError,
error: Schema.Union([ServersError, PairingRefused]),
}),
/** A new home for the default server reconnects the app at once. */
Rpc.make("servers.update", {
payload: ServerUpdate,
success: Schema.Void,
error: Schema.Union([ServersError, PairingRefused]),
}),
/**
* Sets the label stored on a paired machine, over its connection; an empty one clears it. Pairing is
* direct access to the machine, so this needs nothing more.
*/
Rpc.make("servers.label", {
payload: { id: Schema.String, label: Schema.String },
success: Schema.Void,
error: ServersError,
}),
/** The default server and the built-in one stay. */
Expand All @@ -993,6 +1084,12 @@ export const Api = RpcGroup.make(
success: Schema.Void,
error: ServersError,
}),
/** Installs codework with the install script, into its default folder, then starts the local server `id`. */
Rpc.make("servers.install", {
payload: { id: Schema.String },
success: Schema.Void,
error: ServersError,
}),
/** Runs `codework service <action>` with a local server's executable, home, arguments and variables. */
Rpc.make("servers.service", {
payload: { id: Schema.String, action: CliAction },
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"package": "node scripts/package.mjs"
},
"devDependencies": {
"@clerk/electron": "0.1.10",
"@types/node": "catalog:",
"bumpp": "^12.3.0",
"electron": "44.4.2",
"electron-builder": "^26.15.3",
"electron-store": "8.2.0",
"typescript": "catalog:",
"vite-plus": "catalog:"
}
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Synchronous IPC: the renderer reads the app server's RPC URL once, at load. */
/** Synchronous IPC: the renderer reads the app server's RPC URL and token once, at load. */
export const SERVER_CHANNEL = "codework:server";
/** Synchronous IPC: the user's home directory, the folder a new project starts from. */
export const HOME_CHANNEL = "codework:home";
Expand Down
20 changes: 14 additions & 6 deletions apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createClerkBridge } from "@clerk/electron";
import { storage } from "@clerk/electron/storage";
import { app, BrowserWindow, dialog, ipcMain, net, protocol, shell } from "electron";
import { readFile, stat } from "node:fs/promises";
import path from "node:path";
Expand All @@ -14,7 +16,7 @@ app.setPath(
path.join(app.getPath("appData"), channel() === "latest" ? "codework" : `codework${channel()}`),
);

const SCHEME = app.isPackaged ? "codework" : "codework-dev";
const SCHEME = app.isPackaged ? "codework" : "codeworkdev";
const HOST = "app";
const APP_URL = `${SCHEME}://${HOST}/`;

Expand Down Expand Up @@ -50,10 +52,16 @@ const MIME_TYPES: Record<string, string> = {
".txt": "text/plain",
};

// Must run synchronously before Electron emits `ready`.
protocol.registerSchemesAsPrivileged([
{
// Must run synchronously before Electron emits `ready`. Clerk's bridge registers the renderer's scheme
// as privileged (one registration per process), keeps the signed-in session encrypted under userData,
// and carries OAuth back to the renderer on the same origin.
createClerkBridge({
storage: storage({ path: path.join(app.getPath("userData"), "clerk") }),
// The app takes the lock itself, below, before any window opens.
manageSingleInstanceLock: false,
renderer: {
scheme: SCHEME,
host: HOST,
privileges: {
standard: true,
secure: true,
Expand All @@ -63,7 +71,7 @@ protocol.registerSchemesAsPrivileged([
codeCache: true,
},
},
]);
});

async function serveAsset(request: Request): Promise<Response> {
const url = new URL(request.url);
Expand Down Expand Up @@ -105,7 +113,7 @@ function handleRequest(request: Request): Promise<Response> {
if (DEV_SERVER_URL) {
const url = new URL(request.url);
if (url.host !== HOST) return Promise.resolve(new Response(null, { status: 404 }));
// Module scripts carry `Origin: codework-dev://app`; forwarding it makes
// Module scripts carry `Origin: codeworkdev://app`; forwarding it makes
// net.fetch a CORS request the dev server never allows, failing every script.
const headers = new Headers(request.headers);
headers.delete("origin");
Expand Down
7 changes: 6 additions & 1 deletion apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { exposeClerkBridge } from "@clerk/electron/preload";
import { contextBridge, ipcRenderer } from "electron";
import { HOME_CHANNEL, PICK_FOLDER_CHANNEL, REVEAL_CHANNEL, SERVER_CHANNEL } from "./ipc.ts";
import type { Endpoint } from "./server.ts";

contextBridge.exposeInMainWorld("desktopBridge", {
platform: process.platform,
// Main creates the window only after the server is ready, so this is set.
server: ipcRenderer.sendSync(SERVER_CHANNEL) as string,
server: ipcRenderer.sendSync(SERVER_CHANNEL) as Endpoint,
home: ipcRenderer.sendSync(HOME_CHANNEL) as string,
// On Windows the CodeWork server runs in WSL, which has no use for the Windows paths these deal in.
...(process.platform !== "win32" && {
pickFolder: (from: string) => ipcRenderer.invoke(PICK_FOLDER_CHANNEL, from) as Promise<string | null>,
reveal: (path: string) => ipcRenderer.invoke(REVEAL_CHANNEL, path) as Promise<void>,
}),
});

// The narrow bridge @clerk/electron/react uses for token storage and OAuth.
exposeClerkBridge();
19 changes: 13 additions & 6 deletions apps/desktop/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ const ENTRY = app.isPackaged
// How long the server gets to stop by itself on quit before it is killed.
const STOP_GRACE_MS = 5000;

/** Starts the app server and resolves with its RPC URL once it listens. */
export function startServer(): Promise<string> {
/** Where the renderer reaches the app server, and the token its door takes. */
export interface Endpoint {
readonly url: string;
readonly token: string;
}

/** Starts the app server and resolves with its RPC endpoint once it listens. */
export function startServer(): Promise<Endpoint> {
// Electron's own binary in Node mode: no system Node needed, and the child
// does not become a second GUI app instance.
const child = spawn(process.execPath, [ENTRY], {
Expand Down Expand Up @@ -56,14 +62,15 @@ export function startServer(): Promise<string> {
});

createInterface({ input: child.stdout }).on("line", (line) => {
// The ready line carries the token, so it is the one line never echoed.
if (!ready && line.startsWith('{"type":"ready"')) {
ready = true;
const { port } = JSON.parse(line) as { port: number };
const url = `ws://127.0.0.1:${port}/rpc`;
const { port, token } = JSON.parse(line) as { port: number; token: string };
const endpoint: Endpoint = { url: `ws://127.0.0.1:${port}/rpc`, token };
ipcMain.on(SERVER_CHANNEL, (event) => {
event.returnValue = url;
event.returnValue = endpoint;
});
resolve(url);
resolve(endpoint);
return;
}
console.log(`[server] ${line}`);
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { defineConfig } from "vite-plus";

// The main process is bundled to CJS; only `electron` (and Node built-ins)
// stay external — everything else is inlined into the artifact.
const isExternal = (id: string) => id === "electron" || id.startsWith("electron/") || id.startsWith("node:");
// `@clerk/electron-passkeys` is an optional native module Clerk imports only when passkeys are on,
// which they are not.
const isExternal = (id: string) =>
id === "electron" || id.startsWith("electron/") || id.startsWith("node:") || id === "@clerk/electron-passkeys";

// One config per entry: a sandboxed preload cannot require sibling files, so
// modules shared with main must be inlined rather than split into a chunk.
Expand Down
1 change: 1 addition & 0 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@codeworksh/contract": "workspace:*",
"@codeworksh/schema": "workspace:*",
"@codeworksh/web": "workspace:*",
"@codeworksh/widget": "workspace:*",
"@effect/platform-node": "4.0.5",
Expand Down
Loading