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.

Two environments: dev at dev-api.codync.dev for Debug builds, main at api.codync.dev for Release

leepokai05169f37d0e6
diff --git a/CLAUDE.md b/CLAUDE.md
index c4fc7376..717e4bc7 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -26,6 +26,7 @@ Bot-based remote for coding agents: persistent named bots on your computer, mess
- API: `POST /api/<method>` + SSE with the bearer token (`~/.codync/token`) is **loopback only** (Mac app, SSH tunnel, local helpers). Phones and other remote clients use the E2E channel (`/channel` direct, or the Cloudflare relay). Default port **19222**.
- Remote access (Cloudflare relay primary, direct LAN/Tailscale alternative, accounts, SSH): [docs/remote-relay-spec.md](docs/remote-relay-spec.md).
- Remote screen (`host/src/screen.rs` is the reference): phones view/control the computer over WebRTC (hardware H.264, non-trickle SDP relayed by `screenOffer`, input on data channels `input` / `input-fast`); bots get the built-in `computer` MCP server (`codync-host mcp computer`, `host/src/mcp.rs`) when their `computer` flag is on. Capture/input live in a helper on `~/.codync/screen.sock`: `apps/screen` (macOS, launchd agent via `SMAppService`, owns the TCC grants) or `apps/screen-linux` (`codync-screen`: portals + GStreamer, started by the host). Off by default; `setScreenEnabled` is accepted only from loopback. An interactive phone takes over (bots may only look).
+- Environments: **dev** (`dev-api.codync.dev`, Clerk development instance, Debug builds) and **main** (`api.codync.dev`, Clerk production, Release builds); `apps/shared/Config/<env>.plist` becomes `AccountConfig.plist`. Details: [spec §14.0](docs/remote-relay-spec.md).
- Push: iOS registers its APNs token with `relay/` → gets an AES-GCM ticket → gives it (plus its X25519 push key) to the host; the host seals title/body to that key and a Notification Service Extension opens it, so `relay/` sees only generic text. Only two alert kinds: *needs you* and *done*, suppressed while the iOS app is connected.
- Usage: local only — `claude -p /usage --no-session-persistence`, the Claude status line (`codync-host statusline`, wrapping any existing one), Claude ACP `usage_update` rate-limit meta, Codex rollout files. Never call provider APIs with agent credentials.
- macOS app is thin: embeds `codync-host` in `Contents/MacOS` (Xcode post-build script runs cargo), installs it as a launchd agent via `codync-host install`; menu bar shows status/pairing/usage and opens the native chat window (NavigationSplitView over `CodyncUI`). Not sandboxed, not Mac App Store (the host must spawn CLIs).
diff --git a/Codync.xcodeproj/project.pbxproj b/Codync.xcodeproj/project.pbxproj
index e06ca775..40173251 100644
--- a/Codync.xcodeproj/project.pbxproj
+++ b/Codync.xcodeproj/project.pbxproj
@@ -18,7 +18,6 @@
2F0A1C29DBBD1D700C10BE46 /* CodyncApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F45CCA6BBDCF412897AEC105 /* CodyncApp.swift */; };
31A78A067C217F77FBDEDFD0 /* Push.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55AABA9596547D7459B1CC5B /* Push.swift */; };
331338197BF906B069159B11 /* SSHTunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A4EBC39B2AC89EAA4F5033F /* SSHTunnel.swift */; };
- 44FDF4571F4536E3215679E8 /* AccountConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3454B60AEA40B1DCFA5E54AE /* AccountConfig.plist */; };
484455D97513F09142D21D0D /* Capture.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE4D28E8291EEB43E17B11FA /* Capture.swift */; };
48DAAA1384E5B8D0BA27C895 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E47C60032C326157E0386B8 /* SwiftUI.framework */; };
498C81B8C82557C85F912238 /* HostLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75CAC64DDC41D4A222A12DDE /* HostLink.swift */; };
@@ -35,7 +34,6 @@
8CD641A45F144BF41D703D2A /* CodyncMacApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2969919CCC8BC89F277C43A6 /* CodyncMacApp.swift */; };
9593C1951D727D36D6B8C0E9 /* ComputerStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0C143ED8FF93F6BBD82F942 /* ComputerStatus.swift */; };
9D0736B9670D57132AFBB34E /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C60BD13E7283ECB7A1AE4D3 /* NotificationService.swift */; };
- 9FE9864DA43399578A892992 /* AccountConfig.plist in Resources */ = {isa = PBXBuildFile; fileRef = D5252F097812608BF90F7647 /* AccountConfig.plist */; };
A12D125989D2EA1AC5308218 /* WidgetGalleryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E8563C243AB130DFA063CAD /* WidgetGalleryView.swift */; };
AA601649E43A5AF73DCF5B5E /* WebRTC in Frameworks */ = {isa = PBXBuildFile; productRef = 2D9748E611692583AFC5A152 /* WebRTC */; };
ACCB28F3DB9C89108B7911E3 /* Input.swift in Sources */ = {isa = PBXBuildFile; fileRef = 842DA106CA15E3810C3C9461 /* Input.swift */; };
@@ -130,7 +128,6 @@
22F1B304BD18E48C91FC73E3 /* Widgets.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Widgets.entitlements; sourceTree = "<group>"; };
232B2C00B9575BFF7068BB62 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
2969919CCC8BC89F277C43A6 /* CodyncMacApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodyncMacApp.swift; sourceTree = "<group>"; };
- 3454B60AEA40B1DCFA5E54AE /* AccountConfig.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = AccountConfig.plist; sourceTree = "<group>"; };
3A4EBC39B2AC89EAA4F5033F /* SSHTunnel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHTunnel.swift; sourceTree = "<group>"; };
47BCE8E2AFA6CA829DBC489A /* UsageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UsageView.swift; sourceTree = "<group>"; };
4CFB70DD8757C90695CDA211 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
@@ -163,7 +160,6 @@
D0A657FB98BBE0D73807B263 /* Session.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Session.swift; sourceTree = "<group>"; };
D2C705F063CD20F5B3036BD4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
D3831394C093AF3A4E504BC5 /* IconButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconButton.swift; sourceTree = "<group>"; };
- D5252F097812608BF90F7647 /* AccountConfig.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = AccountConfig.plist; sourceTree = "<group>"; };
DE4AE9A34F61B3D28E0C2550 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
E1B79D48C1D6F90D53751B3F /* RootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootView.swift; sourceTree = "<group>"; };
E4B8EAB09016D328195FE2AD /* AccountSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSession.swift; sourceTree = "<group>"; };
@@ -389,7 +385,6 @@
E5F3C27CC2117EB5AF702188 /* Resources */ = {
isa = PBXGroup;
children = (
- 3454B60AEA40B1DCFA5E54AE /* AccountConfig.plist */,
D2C705F063CD20F5B3036BD4 /* Assets.xcassets */,
232B2C00B9575BFF7068BB62 /* Info.plist */,
F0B6AECA1FDDD3064F3D4447 /* iOS.entitlements */,
@@ -415,7 +410,6 @@
FBD5ECB1F12422DB8CC87897 /* Resources */ = {
isa = PBXGroup;
children = (
- D5252F097812608BF90F7647 /* AccountConfig.plist */,
E8B808BC2A9AA0ECD666A454 /* Assets.xcassets */,
);
path = Resources;
@@ -433,6 +427,7 @@
F03A20C030394F9A65472B30 /* CopyFiles */,
1AC8A5FB72DF4C3DAEDBA56F /* Frameworks */,
A39B341E188CE8DB0A29ACC0 /* Embed Dependencies */,
+ 7471650ADCC84E2BBDF4E47C /* Codync environment */,
C0A14ED49FC6A533FEABD5B2 /* Embed codync-host */,
);
buildRules = (
@@ -477,6 +472,7 @@
8C91DA62A73BD91999C1FD70 /* Resources */,
B2AF485DB7DA2A4791E60288 /* Frameworks */,
265004DE0479E150BA3E6AB7 /* Embed Foundation Extensions */,
+ 9900BE8858E71975C4052787 /* Codync environment */,
);
buildRules = (
);
@@ -597,7 +593,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 9FE9864DA43399578A892992 /* AccountConfig.plist in Resources */,
D4AB92074A9C0D9C72B4080A /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -606,7 +601,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 44FDF4571F4536E3215679E8 /* AccountConfig.plist in Resources */,
513F59BF65DED5379AB950A1 /* Assets.xcassets in Resources */,
C937F66F810AA238B73E8363 /* PrivacyInfo.xcprivacy in Resources */,
);
@@ -623,6 +617,46 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
+ 7471650ADCC84E2BBDF4E47C /* Codync environment */ = {
+ isa = PBXShellScriptBuildPhase;
+ alwaysOutOfDate = 1;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputFileListPaths = (
+ );
+ inputPaths = (
+ );
+ name = "Codync environment";
+ outputFileListPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "# Debug builds use dev (dev-api.codync.dev), Release builds use main (api.codync.dev).\ncp \"$SRCROOT/apps/shared/Config/$CODYNC_ENV.plist\" \"$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/AccountConfig.plist\"\n";
+ showEnvVarsInLog = 0;
+ };
+ 9900BE8858E71975C4052787 /* Codync environment */ = {
+ isa = PBXShellScriptBuildPhase;
+ alwaysOutOfDate = 1;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputFileListPaths = (
+ );
+ inputPaths = (
+ );
+ name = "Codync environment";
+ outputFileListPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "# Debug builds use dev (dev-api.codync.dev), Release builds use main (api.codync.dev).\ncp \"$SRCROOT/apps/shared/Config/$CODYNC_ENV.plist\" \"$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/AccountConfig.plist\"\n";
+ showEnvVarsInLog = 0;
+ };
C0A14ED49FC6A533FEABD5B2 /* Embed codync-host */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
@@ -766,6 +800,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_STYLE = Automatic;
+ CODYNC_ENV = main;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 17;
DEAD_CODE_STRIPPING = YES;
@@ -935,6 +970,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_STYLE = Automatic;
+ CODYNC_ENV = dev;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 17;
DEAD_CODE_STRIPPING = YES;
diff --git a/apps/ios/Resources/AccountConfig.plist b/apps/shared/Config/dev.plist
similarity index 86%
rename from apps/ios/Resources/AccountConfig.plist
rename to apps/shared/Config/dev.plist
index 96dfb506..99416545 100644
--- a/apps/ios/Resources/AccountConfig.plist
+++ b/apps/shared/Config/dev.plist
@@ -5,6 +5,6 @@
<key>clerkPublishableKey</key>
<string>pk_test_c3VubnktbW9sbHVzay04NjUxLmNsZXJrLmFjY291bnRzLmRldiQ</string>
<key>cloudURL</key>
- <string>https://staging-api.codync.dev</string>
+ <string>https://dev-api.codync.dev</string>
</dict>
</plist>
diff --git a/apps/macos/Resources/AccountConfig.plist b/apps/shared/Config/main.plist
similarity index 59%
rename from apps/macos/Resources/AccountConfig.plist
rename to apps/shared/Config/main.plist
index 96dfb506..1b02a0b9 100644
--- a/apps/macos/Resources/AccountConfig.plist
+++ b/apps/shared/Config/main.plist
@@ -2,9 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
+ <!-- Filled in when the production Clerk instance and api.codync.dev go live; empty keeps accounts and the cloud off. -->
<key>clerkPublishableKey</key>
- <string>pk_test_c3VubnktbW9sbHVzay04NjUxLmNsZXJrLmFjY291bnRzLmRldiQ</string>
+ <string></string>
<key>cloudURL</key>
- <string>https://staging-api.codync.dev</string>
+ <string></string>
</dict>
</plist>
diff --git a/cloud/README.md b/cloud/README.md
index 1555d0da..1c99c449 100644
--- a/cloud/README.md
+++ b/cloud/README.md
@@ -45,11 +45,11 @@ Env: `CODYNC_HOST_BIN` (default `../host/target/debug/codync-host`), `CODYNC_E2E
Staging (the integration stage runs this; production needs the owner):
```bash
-npx wrangler d1 create codync-staging # put database_id into [env.staging]
-npx wrangler d1 migrations apply codync-staging --env staging --remote
-npx wrangler secret put CLERK_SECRET_KEY --env staging
-npx wrangler secret put CLERK_WEBHOOK_SECRET --env staging
-npx wrangler deploy --env staging # → https://staging-api.codync.dev
+npx wrangler d1 create codync-dev # put database_id into [env.dev]
+npx wrangler d1 migrations apply codync-dev --env dev --remote
+npx wrangler secret put CLERK_SECRET_KEY --env dev
+npx wrangler secret put CLERK_WEBHOOK_SECRET --env dev
+npx wrangler deploy --env dev # → https://dev-api.codync.dev
```
| Name | Kind | Purpose |
diff --git a/cloud/package.json b/cloud/package.json
index 18c72e83..7d35d113 100644
--- a/cloud/package.json
+++ b/cloud/package.json
@@ -6,8 +6,9 @@
"license": "MIT",
"type": "module",
"scripts": {
- "dev": "wrangler dev --env dev",
- "deploy:staging": "wrangler deploy --env staging",
+ "dev": "wrangler dev --env local",
+ "deploy:dev": "wrangler deploy --env dev",
+ "deploy:main": "wrangler deploy",
"typecheck": "tsc && tsc -p test/e2e",
"test": "vitest run",
"e2e": "node --experimental-strip-types --no-warnings test/e2e/relay.e2e.ts"
diff --git a/cloud/test/e2e/relay.e2e.ts b/cloud/test/e2e/relay.e2e.ts
index b589c280..8ca43ce0 100644
--- a/cloud/test/e2e/relay.e2e.ts
+++ b/cloud/test/e2e/relay.e2e.ts
@@ -21,7 +21,7 @@ const HOST_BIN = process.env.CODYNC_HOST_BIN ?? join(ROOT, "host/target/debug/co
const FAKE_AGENT = join(ROOT, "host/tests/fake_agent.py");
const CLOUD_PORT = Number(process.env.CODYNC_E2E_CLOUD_PORT ?? 8787);
const CLOUD = `http://127.0.0.1:${CLOUD_PORT}`;
-const ISSUER = "https://clerk.test.local"; // [env.dev] CLERK_ISSUER
+const ISSUER = "https://clerk.test.local"; // [env.local] CLERK_ISSUER
const WRANGLER = join(CLOUD_DIR, "node_modules/.bin/wrangler");
const tmp = mkdtempSync(join(tmpdir(), "codync-e2e-"));
@@ -68,7 +68,7 @@ async function stop(child: ChildProcess) {
/// Async on purpose: a blocking spawn stalls the event loop past wrangler's keep-alive timeout, and
/// the next `fetch` then reuses a socket the server already closed (ECONNRESET).
function d1(sql: string): Promise<Json[]> {
- const args = ["d1", "execute", "codync-dev", "--local", "--env", "dev", "--persist-to", persist, "--json", "--command", sql];
+ const args = ["d1", "execute", "codync-local", "--local", "--env", "local", "--persist-to", persist, "--json", "--command", sql];
return new Promise((resolve, reject) =>
execFile(WRANGLER, args, { cwd: CLOUD_DIR, encoding: "utf8" }, (err, stdout, stderr) => {
if (err) return reject(new Error(`d1 failed: ${stderr}`));
@@ -142,13 +142,13 @@ const computerOnline = async (id: string) => (await d1(`SELECT online FROM compu
async function main() {
step("1. local D1 + wrangler dev");
- const migrate = spawnSync(WRANGLER, ["d1", "migrations", "apply", "codync-dev", "--local", "--env", "dev", "--persist-to", persist], {
+ const migrate = spawnSync(WRANGLER, ["d1", "migrations", "apply", "codync-local", "--local", "--env", "local", "--persist-to", persist], {
cwd: CLOUD_DIR,
encoding: "utf8",
env: { ...process.env, CI: "1" },
});
if (migrate.status !== 0) throw new Error(`migrations failed: ${migrate.stderr}`);
- run(WRANGLER, ["dev", "--env", "dev", "--ip", "127.0.0.1", "--port", String(CLOUD_PORT), "--persist-to", persist, "--var", `CLERK_JWT_KEY:${jwtKey}`]);
+ run(WRANGLER, ["dev", "--env", "local", "--ip", "127.0.0.1", "--port", String(CLOUD_PORT), "--persist-to", persist, "--var", `CLERK_JWT_KEY:${jwtKey}`]);
await waitFor("cloud /v1/health", () => fetch(`${CLOUD}/v1/health`).then((r) => r.ok || undefined).catch(() => undefined), 60_000);
step("2–3. host registers and comes online");
diff --git a/cloud/wrangler.toml b/cloud/wrangler.toml
index c31f19e5..0d76f06d 100644
--- a/cloud/wrangler.toml
+++ b/cloud/wrangler.toml
@@ -7,7 +7,9 @@ compatibility_flags = ["nodejs_compat"]
tag = "v1"
new_sqlite_classes = ["ComputerRelay"]
-# production (deploying needs the owner's go-ahead)
+# main: production at api.codync.dev (Clerk production instance)
+routes = [{ pattern = "api.codync.dev", custom_domain = true }]
+
[vars]
CLERK_ISSUER = "<production Clerk Frontend API URL>"
@@ -30,19 +32,20 @@ simple = { limit = 10, period = 60 }
[triggers]
crons = ["*/15 * * * *"]
-[env.staging]
-name = "codync-cloud-staging"
-routes = [{ pattern = "staging-api.codync.dev", custom_domain = true }]
+# dev: the deployed test environment at dev-api.codync.dev (Clerk development instance).
+[env.dev]
+name = "codync-cloud-dev"
+routes = [{ pattern = "dev-api.codync.dev", custom_domain = true }]
vars = { CLERK_ISSUER = "https://sunny-mollusk-8651.clerk.accounts.dev" }
-d1_databases = [{ binding = "DB", database_name = "codync-staging", database_id = "8956a285-8c88-4a5b-a05c-5f79be324448", migrations_dir = "migrations" }]
+d1_databases = [{ binding = "DB", database_name = "codync-dev", database_id = "0c03c398-3cec-4f06-a76e-998176ca19ae", migrations_dir = "migrations" }]
durable_objects.bindings = [{ name = "RELAY", class_name = "ComputerRelay" }]
ratelimits = [{ name = "REGISTER_LIMITER", namespace_id = "1002", simple = { limit = 10, period = 60 } }]
triggers = { crons = ["*/15 * * * *"] }
-# wrangler dev / e2e: local D1; CLERK_JWT_KEY is injected by the test (--var).
-[env.dev]
-name = "codync-cloud-dev"
+# local: wrangler dev / e2e with a local D1; CLERK_JWT_KEY is injected by the test (--var).
+[env.local]
+name = "codync-cloud-local"
vars = { CLERK_ISSUER = "https://clerk.test.local" }
-d1_databases = [{ binding = "DB", database_name = "codync-dev", database_id = "dev", migrations_dir = "migrations" }]
+d1_databases = [{ binding = "DB", database_name = "codync-local", database_id = "local", migrations_dir = "migrations" }]
durable_objects.bindings = [{ name = "RELAY", class_name = "ComputerRelay" }]
ratelimits = [{ name = "REGISTER_LIMITER", namespace_id = "1003", simple = { limit = 10, period = 60 } }]
diff --git a/docs/clerk-macos.md b/docs/clerk-macos.md
index 48525386..4fb31769 100644
--- a/docs/clerk-macos.md
+++ b/docs/clerk-macos.md
@@ -14,7 +14,7 @@ The footer displays **Account**, never the Mac user's local name.
requests allowed redirect URLs.
5. Copy only the **publishable key** into
`apps/macos/Resources/AccountConfig.plist` (`clerkPublishableKey`), next to
- `cloudURL`, the Codync cloud the app talks to (staging for now). A development
+ `cloudURL`, the Codync cloud the app talks to (dev for now). A development
launch can override them with `CODYNC_CLERK_PUBLISHABLE_KEY` and `CODYNC_CLOUD_URL`.
The checked-in public configuration uses the Codync development instance
diff --git a/docs/cloudflare-account-device-plan.md b/docs/cloudflare-account-device-plan.md
index 6c1724d7..149a5861 100644
--- a/docs/cloudflare-account-device-plan.md
+++ b/docs/cloudflare-account-device-plan.md
@@ -325,7 +325,7 @@ WebRTC 優先直連,必要時使用 TURN;憑證需短效且受裝置授權
- 完成 claim、grant、傳輸安全、撤權 lease 與 host identity 的協定細節。
- 核對 Clerk 原生 iOS 配置、Cloudflare D1 一致性與 migration 能力。
- 核對 iOS 上架所需的登入選項、帳號刪除流程;若需 Apple 登入則列入 P1。
-- 決定 staging/production 環境、API domain、秘密輪替與資料保存政策。
+- 決定 dev/main(production)環境、API domain、秘密輪替與資料保存政策。
完成條件:沒有「雲端已撤權但有效連線可無限使用」或「知道 host ID 就能認領」的空白設計。
@@ -394,7 +394,7 @@ Worker 執行 typecheck 與具 D1 binding 的整合測試;Rust 執行 auth/
## 16. 部署、監控、成本與回滾
-- local、staging、production 使用不同 Clerk instance/D1/Worker secrets;release 不含測試 key 或 staging API URL。
+- local、dev、main(production) 使用不同 Clerk instance/D1/Worker secrets;release 不含測試 key 或 dev API URL。
- 部署順序:相容的雲端 API → 新 host → 新手機 → 關閉舊配對/ticket 路徑。每步設定最低協定版本與遙測指標。
- D1 schema 使用先擴充再移除;migration 前做可還原備份並演練還原。回滾不能把已撤銷 grant 恢復為有效。
- 初期採帳號 allowlist 與功能旗標。關閉雲端功能時保留本機工作能力,但不得靜默恢復舊的不安全遠端權限。
diff --git a/docs/remote-relay-spec.md b/docs/remote-relay-spec.md
index 2dddf129..82cce136 100644
--- a/docs/remote-relay-spec.md
+++ b/docs/remote-relay-spec.md
@@ -221,13 +221,13 @@ Codync-Sig: v=1,kid=<b64url pub>,ts=<ms>,nonce=<b64url 16 random bytes>,sig=<b64
```
codync-sig-v1
<METHOD 大寫>
-<authority:小寫的 Host header 值,含非預設 port,例如 codync-cloud-staging.x.workers.dev 或 127.0.0.1:8787>
+<authority:小寫的 Host header 值,含非預設 port,例如 codync-cloud-dev.x.workers.dev 或 127.0.0.1:8787>
<path + query,與實際送出的 request-target 逐字相同>
<ts>
<nonce>
<b64url(SHA-256(body bytes))> ← 無 body(GET、WS)用空字串的 hash
```
-驗證:`|now - ts| ≤ 300_000`;`(kid, nonce)` 在 10 分鐘內未出現過(HTTP:D1 `sig_nonces`;relay:DO 的 `nonces` 表);Ed25519 驗證(Worker 用 WebCrypto `Ed25519`)。Worker 以 `new URL(request.url).host`(小寫)比對 authority,所以 staging 簽的 header 在 production 無效。失敗 → `401 {"error":{"code":"badSignature"}}`。向量:`requestSig`。
+驗證:`|now - ts| ≤ 300_000`;`(kid, nonce)` 在 10 分鐘內未出現過(HTTP:D1 `sig_nonces`;relay:DO 的 `nonces` 表);Ed25519 驗證(Worker 用 WebCrypto `Ed25519`)。Worker 以 `new URL(request.url).host`(小寫)比對 authority,所以 dev 簽的 header 在 production 無效。失敗 → `401 {"error":{"code":"badSignature"}}`。向量:`requestSig`。
---
@@ -489,9 +489,9 @@ class_name = "ComputerRelay"
[triggers]
crons = ["*/15 * * * *"]
-[env.staging]
+[env.dev]
vars = { CLERK_ISSUER = "https://sunny-mollusk-8651.clerk.accounts.dev" }
-d1_databases = [{ binding = "DB", database_name = "codync-staging", database_id = "<由 wrangler d1 create 取得>", migrations_dir = "migrations" }]
+d1_databases = [{ binding = "DB", database_name = "codync-dev", database_id = "<由 wrangler d1 create 取得>", migrations_dir = "migrations" }]
durable_objects.bindings = [{ name = "RELAY", class_name = "ComputerRelay" }]
triggers = { crons = ["*/15 * * * *"] }
@@ -500,7 +500,7 @@ vars = { CLERK_ISSUER = "https://clerk.test.local" }
d1_databases = [{ binding = "DB", database_name = "codync-dev", database_id = "dev", migrations_dir = "migrations" }]
durable_objects.bindings = [{ name = "RELAY", class_name = "ComputerRelay" }]
```
-Worker 名稱:production `codync-cloud`,staging `codync-cloud-staging`。
+Worker 名稱:production `codync-cloud`,dev `codync-cloud-dev`。
### 8.2 D1 schema(`migrations/0001_init.sql`)
@@ -999,7 +999,7 @@ public struct RosterItem: Identifiable, Sendable { public var ref: BotReference;
### 11.1 共通
- `apps/shared/AccountSession.swift`:新增 `func sessionToken() async throws -> String`(ClerkKit 1.5.6 的 session token API,以實際 SDK 名稱為準)。
-- 設定檔:`ClerkConfig.plist` 改名為 `AccountConfig.plist`,keys `clerkPublishableKey`、`cloudURL`(目前填 staging URL);env `CODYNC_CLOUD_URL` 可覆寫。兩個 App 都要。
+- 設定檔:`ClerkConfig.plist` 改名為 `AccountConfig.plist`,keys `clerkPublishableKey`、`cloudURL`(目前填 dev URL);env `CODYNC_CLOUD_URL` 可覆寫。兩個 App 都要。
- `project.yml`:`MARKETING_VERSION: 3.0.0`;iOS、Widgets、NotificationService 加 `keychain-access-groups: [$(AppIdentifierPrefix)com.pokai.Codync]`,Info.plist 加 `CodyncKeychainGroup`;新增 `NotificationService` app-extension target(`apps/ios/NotificationService/`,bundle id `com.pokai.Codync.ios.NotificationService`,依賴 CodyncKit,embed 進 iOS App);macOS **不加** entitlements(§3.2);改完執行 `xcodegen generate`。
- `.github/workflows/release-macos.yml`:配合 `AccountConfig.plist` 改名。
@@ -1082,19 +1082,29 @@ public struct RosterItem: Identifiable, Sendable { public var ref: BotReference;
---
-## 14. 部署(staging 可由實作者執行;production 需 owner 確認)
+## 14. 部署(dev 可由實作者執行;production 需 owner 確認)
+
+### 14.0 環境:main 與 dev
+
+| 環境 | Cloud Worker | D1 | Clerk | App build |
+|---|---|---|---|---|
+| **dev** | `codync-cloud-dev` → `https://dev-api.codync.dev`(`wrangler deploy --env dev`) | `codync-dev` | development instance `sunny-mollusk-8651` | Debug(`CODYNC_ENV=dev`) |
+| **main** | `codync-cloud` → `https://api.codync.dev`(`wrangler deploy`) | `codync` | production instance(待建立,網域 `codync.dev`) | Release(`CODYNC_ENV=main`) |
+| local | `wrangler dev --env local`(e2e) | 本機 `codync-local` | 測試 RSA key(`CLERK_JWT_KEY`) | — |
+
+`apps/shared/Config/<env>.plist` 在 build 時複製成 App 內的 `AccountConfig.plist`;`main.plist` 在 production 上線前留空,Release build 的帳號與雲端功能因此關閉。Host 的雲端 URL 由 Mac App 的 Cloud 開關以 `setCloud` 寫入(或 `CODYNC_CLOUD_URL`)。
### 14.1 Staging
```bash
cd cloud && npm ci
-npx wrangler d1 create codync-staging # 將 database_id 填入 [env.staging]
-npx wrangler d1 migrations apply codync-staging --env staging --remote
-npx wrangler secret put CLERK_SECRET_KEY --env staging # owner 輸入 sk_test_…
-npx wrangler secret put CLERK_WEBHOOK_SECRET --env staging # owner 輸入 whsec_…
-npx wrangler deploy --env staging # → https://staging-api.codync.dev(custom domain;production 用 api.codync.dev)
+npx wrangler d1 create codync-dev # 將 database_id 填入 [env.dev]
+npx wrangler d1 migrations apply codync-dev --env dev --remote
+npx wrangler secret put CLERK_SECRET_KEY --env dev # owner 輸入 sk_test_…
+npx wrangler secret put CLERK_WEBHOOK_SECRET --env dev # owner 輸入 whsec_…
+npx wrangler deploy --env dev # → https://dev-api.codync.dev(custom domain;production 用 api.codync.dev)
```
-Host 測 staging:`codync-host cloud --url https://staging-api.codync.dev`(或 env `CODYNC_CLOUD_URL`)。Apple:`AccountConfig.plist` 的 `cloudURL`。
+Host 測 dev:`codync-host cloud --url https://dev-api.codync.dev`(或 env `CODYNC_CLOUD_URL`)。Apple:`AccountConfig.plist` 的 `cloudURL`。
### 14.2 Secrets 與 vars
@@ -1104,12 +1114,12 @@ Host 測 staging:`codync-host cloud --url https://staging-api.codync.dev`(
| `CLERK_WEBHOOK_SECRET` | secret(owner 輸入) | Svix 簽章 |
| `CLERK_ISSUER` | var | Clerk Frontend API URL |
| `CLERK_AUTHORIZED_PARTIES` | var(選填) | 逗號分隔 |
-| `CLERK_JWT_KEY` | var(只給 dev/e2e) | networkless 驗證用的公鑰 PEM;staging/production 不設 |
+| `CLERK_JWT_KEY` | var(只給 dev/e2e) | networkless 驗證用的公鑰 PEM;dev/production 不設 |
### 14.3 Owner 手動步驟
-0. 允許實作者建立 staging 資源:`wrangler login` 已登入的 Cloudflare 帳號(或提供 `CLOUDFLARE_API_TOKEN`,權限 Workers Scripts:Edit、D1:Edit、Durable Objects)。
-1. Clerk Dashboard(staging = `sunny-mollusk-8651`):確認 iOS native app(`com.pokai.Codync.ios`)已註冊並允許 `com.pokai.Codync.ios://callback`;**Sessions → Customize session token** 加入 `{"email": "{{user.primary_email_address}}"}`;**Webhooks** 新增 `https://staging-api.codync.dev/v1/webhooks/clerk`,訂閱 `user.deleted`,複製 signing secret。
+0. 允許實作者建立 dev 資源:`wrangler login` 已登入的 Cloudflare 帳號(或提供 `CLOUDFLARE_API_TOKEN`,權限 Workers Scripts:Edit、D1:Edit、Durable Objects)。
+1. Clerk Dashboard(dev = `sunny-mollusk-8651`):確認 iOS native app(`com.pokai.Codync.ios`)已註冊並允許 `com.pokai.Codync.ios://callback`;**Sessions → Customize session token** 加入 `{"email": "{{user.primary_email_address}}"}`;**Webhooks** 新增 `https://dev-api.codync.dev/v1/webhooks/clerk`,訂閱 `user.deleted`,複製 signing secret。
2. 輸入上面兩個 secrets。
3. Production:另建 Clerk production instance、`wrangler d1 create codync`、填 `wrangler.toml` 頂層、secrets 不加 `--env`、`npx wrangler deploy`;把 production URL 填入 `host/src/cloud.rs` 的 `DEFAULT_CLOUD_URL` 與 Release 版 `AccountConfig.plist`。
4. Apple Developer:新增 `com.pokai.Codync.ios.NotificationService` App ID 與 keychain access group 後,讓 Xcode 自動簽章更新 provisioning profiles。
diff --git a/project.yml b/project.yml
index 59a29d16..3ec01e88 100644
--- a/project.yml
+++ b/project.yml
@@ -25,12 +25,20 @@ settings:
DEVELOPMENT_TEAM: 7FUM8A8H72
DEAD_CODE_STRIPPING: YES
ENABLE_USER_SCRIPT_SANDBOXING: NO
+ configs:
+ # Which Codync cloud a build talks to: apps/shared/Config/<env>.plist becomes AccountConfig.plist.
+ Debug:
+ CODYNC_ENV: dev
+ Release:
+ CODYNC_ENV: main
targets:
macOS:
type: application
platform: macOS
sources:
- path: apps/shared
+ excludes:
+ - Config
- path: apps/macos
excludes:
- LaunchAgents
@@ -66,6 +74,12 @@ targets:
ENABLE_APP_SANDBOX: NO
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
postBuildScripts:
+ - name: Codync environment
+ basedOnDependencyAnalysis: false
+ showEnvVars: false
+ script: |
+ # Debug builds use dev (dev-api.codync.dev), Release builds use main (api.codync.dev).
+ cp "$SRCROOT/apps/shared/Config/$CODYNC_ENV.plist" "$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/AccountConfig.plist"
- name: Embed codync-host
basedOnDependencyAnalysis: false
showEnvVars: false
@@ -123,6 +137,8 @@ targets:
platform: iOS
sources:
- path: apps/shared
+ excludes:
+ - Config
- path: apps/ios
excludes:
- Widgets
@@ -138,6 +154,13 @@ targets:
embed: true
- target: NotificationService
embed: true
+ postBuildScripts:
+ - name: Codync environment
+ basedOnDependencyAnalysis: false
+ showEnvVars: false
+ script: |
+ # Debug builds use dev (dev-api.codync.dev), Release builds use main (api.codync.dev).
+ cp "$SRCROOT/apps/shared/Config/$CODYNC_ENV.plist" "$TARGET_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/AccountConfig.plist"
settings:
base:
PRODUCT_NAME: Codync