Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

feat(cloud): accept Windows computers

leepokai8e4b2ce2c419
diff --git a/cloud/migrations/0002_windows_computers.sql b/cloud/migrations/0002_windows_computers.sql
new file mode 100644
index 00000000..f4e7ab18
--- /dev/null
+++ b/cloud/migrations/0002_windows_computers.sql
@@ -0,0 +1,63 @@
+-- Windows hosts: computers.platform also takes 'windows'. SQLite can't alter a CHECK, so
+-- computers is rebuilt, together with the tables that reference it (access_requests,
+-- grants): with foreign keys enforced, dropping a referenced table would count every
+-- referencing row as a violation. The children go first, then their parent; renaming
+-- computers_new afterwards updates the new children's references to `computers`.
+
+CREATE TABLE computers_new (
+ id TEXT PRIMARY KEY, -- computerId
+ sign_pub TEXT NOT NULL UNIQUE,
+ box_pub TEXT NOT NULL,
+ owner_user_id TEXT REFERENCES accounts(user_id),
+ name TEXT NOT NULL,
+ platform TEXT NOT NULL CHECK (platform IN ('macos','linux','windows')),
+ device TEXT, -- laptop|macmini|…|linux(host 的 Device)
+ version TEXT NOT NULL,
+ status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active','blocked')),
+ online INTEGER NOT NULL DEFAULT 0, -- DO 寫入
+ last_seen_at INTEGER, -- DO 寫入
+ claimed_at INTEGER,
+ created_at INTEGER NOT NULL,
+ updated_at INTEGER NOT NULL
+);
+INSERT INTO computers_new SELECT * FROM computers;
+
+CREATE TABLE access_requests_new (
+ id TEXT PRIMARY KEY, -- req_…
+ computer_id TEXT NOT NULL REFERENCES computers_new(id),
+ device_id TEXT NOT NULL REFERENCES devices(id),
+ user_id TEXT NOT NULL REFERENCES accounts(user_id),
+ status TEXT NOT NULL CHECK (status IN ('pending','approved','denied','expired','cancelled')),
+ commit_hash TEXT NOT NULL, -- SHA-256("codync/sascommit/v1" ‖ dk ‖ nD)
+ host_nonce TEXT, -- nH,host 設一次
+ device_nonce TEXT, -- nD,host_nonce 存在後裝置才可設
+ created_at INTEGER NOT NULL,
+ expires_at INTEGER NOT NULL, -- created_at + 10 min
+ decided_at INTEGER,
+ grant_id TEXT
+);
+INSERT INTO access_requests_new SELECT * FROM access_requests;
+
+CREATE TABLE grants_new (
+ id TEXT PRIMARY KEY, -- grt_…
+ computer_id TEXT NOT NULL REFERENCES computers_new(id),
+ device_id TEXT NOT NULL REFERENCES devices(id),
+ scopes TEXT NOT NULL, -- JSON array
+ status TEXT NOT NULL CHECK (status IN ('active','revoked')),
+ created_at INTEGER NOT NULL,
+ revoked_at INTEGER,
+ revoked_reason TEXT -- owner|deviceRevoked|unclaimed|accountDeleted
+);
+INSERT INTO grants_new SELECT * FROM grants;
+
+DROP TABLE access_requests;
+DROP TABLE grants;
+DROP TABLE computers;
+ALTER TABLE computers_new RENAME TO computers;
+ALTER TABLE access_requests_new RENAME TO access_requests;
+ALTER TABLE grants_new RENAME TO grants;
+
+CREATE INDEX computers_owner ON computers(owner_user_id);
+CREATE INDEX access_requests_computer ON access_requests(computer_id, status);
+CREATE UNIQUE INDEX access_requests_one_pending ON access_requests(computer_id, device_id) WHERE status = 'pending';
+CREATE UNIQUE INDEX grants_active ON grants(computer_id, device_id) WHERE status = 'active';
diff --git a/cloud/src/routes/account.ts b/cloud/src/routes/account.ts
index dce16eb3..b1fde809 100644
--- a/cloud/src/routes/account.ts
+++ b/cloud/src/routes/account.ts
@@ -146,7 +146,7 @@ export async function completeClaim(c: Ctx, [claimId]: string[]) {
const sig = fromB64url(b.sig, 64);
const computerId = str(b, "computerId", 22);
const name = str(b, "name");
- const platform = oneOf(b, "platform", ["macos", "linux"] as const);
+ const platform = oneOf(b, "platform", ["macos", "linux", "windows"] as const);
const device = optStr(b, "device", 32);
const version = str(b, "version", 32);
if (!sig) throw new ApiError("badRequest", "Invalid sig");
diff --git a/cloud/src/routes/host.ts b/cloud/src/routes/host.ts
index a619c7fd..64262e14 100644
--- a/cloud/src/routes/host.ts
+++ b/cloud/src/routes/host.ts
@@ -25,7 +25,7 @@ export async function hostRegister(c: Ctx) {
const b = body(c);
const boxKey = key(b, "boxKey", 32);
const name = str(b, "name");
- const platform = oneOf(b, "platform", ["macos", "linux"] as const);
+ const platform = oneOf(b, "platform", ["macos", "linux", "windows"] as const);
const device = optStr(b, "device", 32);
const version = str(b, "version", 32);
const id = await computerIdFor(fromB64url(s.kid, 32)!);
diff --git a/cloud/test/api.test.ts b/cloud/test/api.test.ts
index 9d50069c..bcdd4fd9 100644
--- a/cloud/test/api.test.ts
+++ b/cloud/test/api.test.ts
@@ -154,6 +154,16 @@ describe("Codync-Sig over HTTP", () => {
expect(again.body.error.code).toBe("badSignature");
});
+ it("registers Windows computers, and no unknown platform", async () => {
+ const as = (platform: string) =>
+ call("POST", "/v1/host/register", {
+ key: ref.signKey(),
+ body: { boxKey: ref.b64url(ref.boxKey().pub), name: "PC", platform, version: "2.9.0" },
+ });
+ expect((await as("windows")).status).toBe(200);
+ expect((await as("beos")).status).toBe(400);
+ });
+
it("rejects timestamps outside ±5 minutes and other authorities", async () => {
const key = ref.signKey();
expect((await register(key, { ts: Date.now() - 301_000 })).status).toBe(401);
diff --git a/host/src/service.rs b/host/src/service/mod.rs
similarity index 100%
rename from host/src/service.rs
rename to host/src/service/mod.rs