Skip to content

Commit 9674529

Browse files
Apply PR #19545: feat: opencode remote control + opencode serve dependencies
2 parents da3756a + 2b3d027 commit 9674529

File tree

118 files changed

+15105
-360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+15105
-360
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"on":
2+
push:
3+
branches:
4+
- opencode-remote-voice
5+
name: Deploy to apn-relay
6+
jobs:
7+
porter-deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
- name: Set Github tag
13+
id: vars
14+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
15+
- name: Setup porter
16+
uses: porter-dev/setup-porter@v0.1.0
17+
- name: Deploy stack
18+
timeout-minutes: 30
19+
run: porter apply
20+
env:
21+
PORTER_APP_NAME: apn-relay
22+
PORTER_CLUSTER: "5534"
23+
PORTER_DEPLOYMENT_TARGET_ID: d60e67f5-b0a6-4275-8ed6-3cebaf092147
24+
PORTER_HOST: https://dashboard.porter.run
25+
PORTER_PROJECT: "18525"
26+
PORTER_TAG: ${{ steps.vars.outputs.sha_short }}
27+
PORTER_TOKEN: ${{ secrets.PORTER_APP_18525_975734319 }}

AGENTS.md

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
- To regenerate the JavaScript SDK, run `./packages/sdk/js/script/build.ts`.
2-
- ALWAYS USE PARALLEL TOOLS WHEN APPLICABLE.
3-
- The default branch in this repo is `dev`.
4-
- Local `main` ref may not exist; use `dev` or `origin/dev` for diffs.
5-
- Prefer automation: execute requested actions without confirmation unless blocked by missing info or safety/irreversibility.
1+
# OpenCode Monorepo Agent Guide
62

7-
## Style Guide
3+
This file is for coding agents working in `/Users/ryanvogel/dev/opencode`.
84

9-
### General Principles
5+
## Scope And Precedence
106

117
- Keep things in one function unless composable or reusable
128
- Avoid `try`/`catch` where possible
@@ -56,48 +52,48 @@ else foo = 2
5652

5753
### Control Flow
5854

59-
Avoid `else` statements. Prefer early returns.
55+
- Prefer early returns over nested `else` blocks.
56+
- Keep functions focused; split only when it improves reuse or readability.
6057

61-
```ts
62-
// Good
63-
function foo() {
64-
if (condition) return 1
65-
return 2
66-
}
58+
### Error Handling
6759

68-
// Bad
69-
function foo() {
70-
if (condition) return 1
71-
else return 2
72-
}
73-
```
60+
- Fail with actionable messages.
61+
- Avoid swallowing errors silently.
62+
- Log enough context to debug production issues (IDs, env, status), but never secrets.
63+
- In UI code, degrade gracefully for missing capabilities.
7464

75-
### Schema Definitions (Drizzle)
65+
### Data / DB
7666

77-
Use snake_case for field names so column names don't need to be redefined as strings.
67+
- For Drizzle schema, use snake_case fields and columns.
68+
- Keep migration and schema changes minimal and explicit.
69+
- Follow package-specific DB guidance in `packages/opencode/AGENTS.md`.
7870

79-
```ts
80-
// Good
81-
const table = sqliteTable("session", {
82-
id: text().primaryKey(),
83-
project_id: text().notNull(),
84-
created_at: integer().notNull(),
85-
})
71+
### Testing Philosophy
8672

87-
// Bad
88-
const table = sqliteTable("session", {
89-
id: text("id").primaryKey(),
90-
projectID: text("project_id").notNull(),
91-
createdAt: integer("created_at").notNull(),
92-
})
93-
```
73+
- Prefer testing real behavior over mocks.
74+
- Add regression tests for bug fixes where practical.
75+
- Keep fixtures small and focused.
76+
77+
## Agent Workflow Tips
78+
79+
- Read existing code paths before introducing new abstractions.
80+
- Match local patterns first; do not impose a new style per file.
81+
- If a package has its own `AGENTS.md`, review it before editing.
82+
- For OpenCode Effect services, follow `packages/opencode/AGENTS.md` strictly.
83+
84+
## Known Operational Notes
85+
86+
- `packages/app/AGENTS.md` says: never restart app/server processes during that package's debugging workflow.
87+
- `packages/app/AGENTS.md` also documents local backend+web split for UI work.
88+
- `packages/opencode/AGENTS.md` contains mandatory Effect and database conventions.
9489

95-
## Testing
90+
## Regeneration / Special Scripts
9691

97-
- Avoid mocks as much as possible
98-
- Test actual implementation, do not duplicate logic into tests
99-
- Tests cannot run from repo root (guard: `do-not-run-tests-from-root`); run from package dirs like `packages/opencode`.
92+
- Regenerate JS SDK with: `./packages/sdk/js/script/build.ts`
10093

101-
## Type Checking
94+
## Quick Checklist Before Finishing
10295

103-
- Always run `bun typecheck` from package directories (e.g., `packages/opencode`), never `tsc` directly.
96+
- Ran relevant package checks.
97+
- Updated docs/config when behavior changed.
98+
- Avoided committing unrelated files.
99+
- Kept edits minimal and aligned with local conventions.

bun.lock

Lines changed: 1795 additions & 309 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eas.json

Whitespace-only changes.

packages/apn-relay/.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
PORT=8787
2+
3+
DATABASE_HOST=
4+
DATABASE_USERNAME=
5+
DATABASE_PASSWORD=
6+
DATABASE_NAME=main
7+
8+
APNS_TEAM_ID=
9+
APNS_KEY_ID=
10+
APNS_PRIVATE_KEY=
11+
APNS_DEFAULT_BUNDLE_ID=com.anomalyco.mobilevoice

packages/apn-relay/AGENTS.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# apn-relay Agent Guide
2+
3+
This file defines package-specific guidance for agents working in `packages/apn-relay`.
4+
5+
## Scope And Precedence
6+
7+
- Follow root `AGENTS.md` first.
8+
- This file provides stricter package-level conventions for relay service work.
9+
- If future local guides are added, closest guide wins.
10+
11+
## Project Overview
12+
13+
- Minimal APNs relay service (Hono + Bun + PlanetScale via Drizzle).
14+
- Core routes:
15+
- `GET /health`
16+
- `GET /`
17+
- `POST /v1/device/register`
18+
- `POST /v1/device/unregister`
19+
- `POST /v1/event`
20+
21+
## Commands
22+
23+
Run all commands from `packages/apn-relay`.
24+
25+
- Install deps: `bun install`
26+
- Start relay locally: `bun run dev`
27+
- Typecheck: `bun run typecheck`
28+
- DB connectivity check: `bun run db:check`
29+
30+
## Build / Test Expectations
31+
32+
- There is no dedicated package test script currently.
33+
- Required validation for behavior changes:
34+
- `bun run typecheck`
35+
- `bun run db:check` when DB/env changes are involved
36+
- manual endpoint verification against `/health`, `/v1/device/register`, `/v1/event`
37+
38+
## Single-Test Guidance
39+
40+
- No single-test command exists for this package today.
41+
- For focused checks, run endpoint-level manual tests against a local dev server.
42+
43+
## Code Style Guidelines
44+
45+
### Formatting / Structure
46+
47+
- Keep handlers compact and explicit.
48+
- Prefer small local helpers for repeated route logic.
49+
- Avoid broad refactors when a targeted fix is enough.
50+
51+
### Types / Validation
52+
53+
- Validate request bodies with `zod` at route boundaries.
54+
- Keep payload and DB row shapes explicit and close to usage.
55+
- Avoid `any`; narrow unknown input immediately after parsing.
56+
57+
### Naming
58+
59+
- Follow existing concise naming in this package (`reg`, `unreg`, `evt`, `row`, `key`).
60+
- For DB columns, keep snake_case alignment with schema.
61+
62+
### Error Handling
63+
64+
- Return clear JSON errors for invalid input.
65+
- Keep handler failures observable via `app.onError` and structured logs.
66+
- Do not leak secrets in responses or logs.
67+
68+
### Logging
69+
70+
- Log delivery lifecycle at key checkpoints:
71+
- registration/unregistration attempts
72+
- event fanout start/end
73+
- APNs send failures and retries
74+
- Mask sensitive values; prefer token suffixes and metadata.
75+
76+
### APNs Environment Rules
77+
78+
- Keep APNs env explicit per registration (`sandbox` / `production`).
79+
- For `BadEnvironmentKeyInToken`, retry once with flipped env and persist correction.
80+
- Avoid infinite retry loops; one retry max per delivery attempt.
81+
82+
## Database Conventions
83+
84+
- Schema is in `src/schema.sql.ts`.
85+
- Keep table/column names snake_case.
86+
- Maintain index naming consistency with existing schema.
87+
- For upserts, update only fields required by current behavior.
88+
89+
## API Behavior Expectations
90+
91+
- `register`/`unregister` must be idempotent.
92+
- `event` should return success envelope even when no devices are registered.
93+
- Delivery logs should capture per-attempt result and error payload.
94+
95+
## Operational Notes
96+
97+
- Ensure `APNS_PRIVATE_KEY` supports escaped newline format (`\n`) and raw multiline.
98+
- Validate that `APNS_DEFAULT_BUNDLE_ID` matches mobile app bundle identifier.
99+
- Avoid coupling route behavior to deployment platform specifics.
100+
101+
## Before Finishing
102+
103+
- Run `bun run typecheck`.
104+
- If DB/env behavior changed, run `bun run db:check`.
105+
- Manually exercise affected endpoints.
106+
- Confirm logs are useful and secret-safe.

packages/apn-relay/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM oven/bun:1.3.11-alpine
2+
3+
WORKDIR /app
4+
5+
COPY package.json ./
6+
COPY tsconfig.json ./
7+
COPY drizzle.config.ts ./
8+
RUN bun install --production
9+
10+
COPY src ./src
11+
12+
EXPOSE 8787
13+
14+
CMD ["bun", "run", "src/index.ts"]

packages/apn-relay/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# APN Relay
2+
3+
Minimal APNs relay for OpenCode mobile background notifications.
4+
5+
## What it does
6+
7+
- Registers iOS device tokens for a shared secret.
8+
- Receives OpenCode event posts (`complete`, `permission`, `error`).
9+
- Sends APNs notifications to mapped devices.
10+
- Stores delivery rows in PlanetScale.
11+
12+
## Routes
13+
14+
- `GET /health`
15+
- `GET /` (simple dashboard)
16+
- `POST /v1/device/register`
17+
- `POST /v1/device/unregister`
18+
- `POST /v1/event`
19+
20+
## Environment
21+
22+
Use `.env.example` as a starting point.
23+
24+
- `DATABASE_HOST`
25+
- `DATABASE_USERNAME`
26+
- `DATABASE_PASSWORD`
27+
- `APNS_TEAM_ID`
28+
- `APNS_KEY_ID`
29+
- `APNS_PRIVATE_KEY`
30+
- `APNS_DEFAULT_BUNDLE_ID`
31+
32+
## Run locally
33+
34+
```bash
35+
bun install
36+
bun run src/index.ts
37+
```
38+
39+
## Docker
40+
41+
Build from this directory:
42+
43+
```bash
44+
docker build -t apn-relay .
45+
docker run --rm -p 8787:8787 --env-file .env apn-relay
46+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineConfig } from "drizzle-kit"
2+
3+
export default defineConfig({
4+
out: "./migration",
5+
strict: true,
6+
schema: ["./src/**/*.sql.ts"],
7+
dialect: "mysql",
8+
dbCredentials: {
9+
host: process.env.DATABASE_HOST ?? "",
10+
user: process.env.DATABASE_USERNAME ?? "",
11+
password: process.env.DATABASE_PASSWORD ?? "",
12+
database: process.env.DATABASE_NAME ?? "main",
13+
ssl: {
14+
rejectUnauthorized: false,
15+
},
16+
},
17+
})

packages/apn-relay/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "https://json.schemastore.org/package.json",
3+
"name": "@opencode-ai/apn-relay",
4+
"version": "0.0.0",
5+
"private": true,
6+
"type": "module",
7+
"license": "MIT",
8+
"scripts": {
9+
"dev": "bun run src/index.ts",
10+
"db:check": "bun run --env-file .env src/check.ts",
11+
"typecheck": "tsgo --noEmit"
12+
},
13+
"dependencies": {
14+
"@planetscale/database": "1.19.0",
15+
"drizzle-orm": "1.0.0-beta.19-d95b7a4",
16+
"hono": "4.10.7",
17+
"jose": "6.0.11",
18+
"zod": "4.1.8"
19+
},
20+
"devDependencies": {
21+
"@tsconfig/bun": "1.0.9",
22+
"@types/bun": "1.3.11",
23+
"@typescript/native-preview": "7.0.0-dev.20251207.1",
24+
"drizzle-kit": "1.0.0-beta.19-d95b7a4",
25+
"typescript": "5.8.2"
26+
}
27+
}

0 commit comments

Comments
 (0)