Repository navigation
feat(fork): no3y Code iOS app with notifications from the Mac - #401
Conversation
…ple team The iOS app now builds as no3y Code (com.noahhendrickson.no3ycode, team 4WDT6B6JDX) with the fork's icons, so it can be signed and shipped to TestFlight from this repo. Ping's team, linked domains and Expo project are swapped out or dropped, and OTA updates stay off. The identity lives in apps/mobile/fork/identity.ts and is applied through two small fenced hooks in app.config.ts: one before upstream derives the widget, share-extension, app-group and keychain IDs, one on the final config. It is on by default; NO3Y_MOBILE_IDENTITY=0 builds upstream's identity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The no3y app cannot use Ping's relay for push, so a small service on the Mac does it instead. apps/mobile/fork/push-service/no3yPush.mts pairs with the local T3 server as an ordinary read-only client, watches the orchestration shell stream, and pushes to APNs with the fork's own key when a thread finishes, fails, or waits on an approval or an answer. It reuses the official projectThreadAwarenessV2 rule and the relay's 5-second completion hold, and its payload matches the relay's so upstream's tap handler opens the thread. The app asks for notification permission at launch and registers its APNs token with the service through Tailscale Serve at /no3y-push/register on each saved Tailscale HTTPS route. No server, contract, or web code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code-quality review of e73a3d7. Not approving. The rebrand half (identity.ts plus two fenced hooks) is in good shape. The push service is where the structural problems are.
1. The push service hand-rolls the Effect RPC wire protocol. The repo already has a Node client for it.
no3yPush.mts:360-417 builds {_tag:"Request", id:"1", tag:"orchestration.subscribeShell"} by hand. It also sends manual Acks keyed to the hardcoded request id, runs its own 30s Ping interval, and picks apart Chunk/Exit/Defect frames with five as casts. That is a private copy of effect/rpc's socket protocol. It breaks silently on any framing change, and an upstream sync won't flag it, because the manifest only watches App.tsx.
The file already depends on effect and @t3tools/contracts, and apps/mobile already has @effect/platform-node. That makes the "dependency-free" claim in the PR body inaccurate. The canonical move is ~15 lines, already written in scripts/mobile-behavior/environment.ts:215-232: RpcClient.layerProtocolSocket() + Socket.layerWebSocket(...) + RpcSerialization.layerJson + NodeWS.layerWebSocketConstructor, then RpcClient.make(WsRpcGroup) and client["orchestration.subscribeShell"]({}) as a typed Stream. That one change deletes the frame parsing, the Ack bookkeeping, the ping timer, decodeItem, and the "skipped an item the schema did not accept" path. The ticket fetch and environment descriptor can use HttpClientResponse.schemaBodyJson the same way, which removes the as { ticket: string } / as { environmentId: unknown } casts.
2. "Imported, not copied" is only half true. The alert policy is a second, divergent copy of AgentAwarenessRelay.
projectThreadAwarenessV2 is imported, but the relay's decision is more than that function. apps/server/src/relay/AgentAwarenessRelay.ts wraps it with policy that observeThread (no3yPush.mts:293-320) leaves out:
- Subagent waits. Child threads are not listed lineage, so
projectThreadAwarenessV2returnsnullfor them. The relay rolls a waiting child up to its top-level thread throughpendingSubagentRequest(trackSubagentRequest/currentSubagentRequestFor). The push service never passes one, so an approval requested inside a delegated subagent never alerts. That case is common for anyone delegating work. - Settled during the hold. The relay explicitly still alerts a completion that settles inside the 5s window (
AgentAwarenessRelay.ts:640-665, with a test: "still publishes a completion when the thread settles during the hold"). Here, settlement flipsalertKeytonull, the timer'slastKeys.get(...) === keycheck fails, and the "Agent finished" push is dropped.
The fix has nothing to do with the push service's internals. The decision logic should exist once. The relay's per-thread policy (resolveAgentAwarenessRelayPublishSnapshot, the subagent request map, the held-completion rule) is pure enough to pull into packages/shared/src/agentAwareness as a small transition model, which both the relay and this service would consume. If that's upstream-touching work the fork doesn't want, then at minimum:
- make subagent rollup and the settle-during-hold rule explicit here, with tests that mirror the relay's,
- correct the manifest's "imported rather than copied" wording, and
- add
apps/server/src/relay/AgentAwarenessRelay.tsandpackages/shared/src/agentAwareness.tstono3y-push.watch, so a sync that changes the relay policy shows up.
The hand-tracked lastKeys / settleTimers maps, and the silent boolean threaded through observeThread, are also a weak model. A per-thread record like { key, pending?: Timer }, with the snapshot baseline handled in applyShellItem rather than by a flag, would remove the boolean parameter and the duplicated map lookups.
3. no3yPush.mts is a 567-line grab-bag. Decompose it before it grows.
One file currently holds: an APNs JWT + HTTP/2 client with sandbox/production fallback, a JSON-file device store, an HTTP registration server, the pure transition tracker, the hand-rolled RPC socket, OAuth pairing, launchd/Tailscale installation, and a CLI. Its tests import the pure tracker from a module that also carries side-effectful state: cachedJwt, plus home computed at import from process.env. Suggested split under fork/push-service/:
alerts.ts:alertKey, the tracker,notificationForState,apnsPayload. Pure; the tests import only this.apns.ts: JWT +sendToApns+ the environment-learning retry.devices.ts: the device store and the registration server.no3yPush.mts: the CLI,pair,install, and the (RpcClient-based) watch loop.
After the split, each piece is short enough to scan, and the shape of the service is obvious.
4. Identity constants are duplicated, and a guard test pins the duplication.
TEAM_ID/BUNDLE_IDinno3yPush.mts:20-21restateNO3Y_APPLE_TEAM_ID/NO3Y_BUNDLE_IDENTIFIERfromidentity.ts.MOUNT_PATHrestatesNO3Y_PUSH_REGISTER_PATHfrompushRegistration.ts.apps/web/src/__fork_guards__/no3yPush.test.tsthen asserts the literal'const MOUNT_PATH = "/no3y-push"'in one file and'NO3Y_PUSH_REGISTER_PATH = "/no3y-push/register"'in the other. That is a guard keeping two copies in sync by string-matching source.
Put the shared values (team ID, base bundle ID, push mount path) in one small module, say apps/mobile/fork/no3yConstants.ts, and have identity.ts, pushRegistration.ts and the service import it. The second guard case then has nothing to check and can be deleted. Node's type stripping handles a plain .ts import from the .mts service.
The service also sends only to the production bundle topic. .dev/.preview builds register, then fail with DeviceTokenNotForTopic, because apns-topic is hardcoded. Store the topic with the device at registration (the app knows its bundle ID), or say in the manifest that only production builds get pushes.
5. The manifest contradicts itself.
The no3y-mobile-identity intent still says "Push notifications, Live Activities and T3 Connect sign-in still target Ping's relay and Clerk and do not work in this build". The next entry, no3y-push, exists to make push notifications work. Rewrite that sentence to point at no3y-push.
Smaller boundary notes
- Casts instead of schemas.
readJson<T>returnsJSON.parse(...) as Tfor bothconfig.jsonanddevices.json, andwarnIfPairingExpiresre-reads the config asPartial<Config>to dodgereadConfig's throw. The file already usesSchemafor stream items, so giveConfigandDeviceschemas and decode them. That removes thePartial<>workaround and makes a hand-edited or corrupted file fail loudly instead of becoming{ devices: [] }. - Non-thread pushes diverge from the relay. The test and expiry pushes use empty
environmentId/threadId, which produce"thread-id": "/". The relay'snotificationThreadId(infra/relay/src/agentActivity/ApnsClient.ts:207) falls back to"t3-agent-alerts". Mirror it, so payloads really do "match the relay's". - Registration is unauthenticated.
/no3y-push/registeraccepts any well-formed token from anyone on the tailnet, and from then on that device receives every thread and project title. The app already holds a bearer credential for that exact origin. Sending it, and having the service verify it against the T3 server, keeps the boundary in the server's auth model instead of relying on network position.
Summary
Blockers, in order:
- Replace the hand-rolled RPC framing with
RpcClient.make(WsRpcGroup), as in the existing precedent. - Stop forking the relay's alert policy, or at least close the subagent-wait and settle-during-hold gaps and watch the relay files.
- Split
no3yPush.mtsalong the lines above, and consolidate the duplicated identity/path constants (which deletes the string-matching guard).
The rebrand hooks and the pushRegistration.ts installer are fine as they are.
🤖 Signed: Claude Opus 5.5 (claude-opus-5-5) via Claude Code (automated review of e73a3d7)
NoahHendrickson
left a comment
There was a problem hiding this comment.
Code review of e73a3d74f63fa10537548d37f77dd3e5116d97c8.
2 important findings and 8 nits, inline below. Both important ones are in the push service: dev and preview builds are sent with the wrong APNs topic, and subagent approval waits are never alerted.
🤖 Reviewed by Claude Opus 5.5 (claude-opus-5-5) via Claude Code
| ":method": "POST", | ||
| ":path": `/3/device/${device.token}`, | ||
| authorization: `bearer ${apnsJwt()}`, | ||
| "apns-topic": BUNDLE_ID, |
There was a problem hiding this comment.
Important — Dev and preview builds never get pushes. Every APNs request uses the hardcoded production topic com.noahhendrickson.no3ycode, but identity.ts signs those variants as .dev and .preview, and the device record stores no bundle ID. A .dev build's token fails production with BadDeviceToken, then fails the sandbox retry with DeviceTokenNotForTopic, on every alert.
Suggested fix: have pushRegistration send the app's bundle ID with the token, store it on the device, and use it as apns-topic.
There was a problem hiding this comment.
Fixed in fc9d3e2. The phone sends its bundle ID (Application.applicationId) with the token. The service stores it as the device's topic and uses it for apns-topic. Devices registered before this default to production's topic, and a bundle that isn't a no3y one is rejected.
| type ThreadShell = Extract<OrchestrationV2ShellStreamItem, { kind: "thread.updated" }>["thread"]; | ||
| type ObservedThread = ProjectThreadAwarenessV2Input["thread"] & Pick<ThreadShell, "projectId">; | ||
|
|
||
| function awareness(tracker: Tracker, thread: ObservedThread) { |
There was a problem hiding this comment.
Important — There's no alert when a subagent waits on an approval or answer. awareness() calls projectThreadAwarenessV2 without pendingSubagentRequest, and the child thread itself returns null from isListedThreadLineage. So the wait shows on neither row: the parent stays running, alertKey is null, and the run sits blocked with no push. AgentAwarenessRelay.ts handles this case, so the manifest's "like the relay does" isn't accurate yet.
Suggested fix: track child threads by lineage.rootThreadId and pass the waiting child's request as pendingSubagentRequest when evaluating the root thread, keyed by the child's request ID.
There was a problem hiding this comment.
Fixed in fc9d3e2. The tracker keeps each thread's latest shell. A subagent that subagentAwaitsUser is tracked by id and resolved to its top-level thread with the relay's parent walk. The newest waiting child goes in as pendingSubagentRequest, and its request id goes into the alert key, so back-to-back child approvals each alert. New test: "alerts on the top-level thread when its subagent waits on an approval".
| }; | ||
|
|
||
| void (async () => { | ||
| const current = await Notifications.getPermissionsAsync(); |
There was a problem hiding this comment.
Nit — The opt-out build still asks for notification permission at launch and posts its token to the Mac. App.tsx installs this with no check of NO3Y_MOBILE_IDENTITY, and it bypasses upstream's permission flow in notificationPermissions.ts. With NO3Y_MOBILE_IDENTITY=0 (com.t3tools.t3code), the system dialog appears with no context on first launch. Gate it on the no3y identity, for example through Constants.expoConfig.ios.bundleIdentifier or an extra flag.
There was a problem hiding this comment.
Fixed in fc9d3e2. installNo3yPushRegistration returns early unless the running bundle ID is a no3y one, so a NO3Y_MOBILE_IDENTITY=0 build never asks for permission or posts its token.
| tailscale([ | ||
| "serve", | ||
| "--bg", | ||
| "--https=443", |
There was a problem hiding this comment.
Nit — Registration 404s when the T3 server's Tailscale Serve port isn't 443. The service is always mounted with --https=443, but tailscaleServePort is configurable, and the phone posts to the saved route's own origin, port included (for example :8443/no3y-push/register, which reaches the T3 server). Read the configured port, or take it as an install argument.
There was a problem hiding this comment.
Not changed. The T3 server here is served on 443, which matches the install. Reading tailscaleServePort from the server settings is left for later, if that port ever changes.
| async function pair(link: string | undefined) { | ||
| const token = link ? pairingTokenFromUrl(link) : null; | ||
| if (!token) throw new Error("Pass the pairing link from Settings → Sharing & access."); | ||
| const serverOrigin = |
There was a problem hiding this comment.
Nit — The server origin is captured once at pair time and reused forever. If the desktop server comes up on a different port (it scans upward from 3773 when that port is busy), the service keeps reconnecting to the old port until it's paired again by hand. Re-read server-runtime.json origin on each reconnect.
There was a problem hiding this comment.
Fixed in fc9d3e2. readConfig re-reads origin from server-runtime.json on each reconnect and alert, falling back to the paired origin.
| for (const project of item.snapshot.projects) | ||
| tracker.projectTitles.set(project.id, project.title); | ||
| // A projects-only refresh arrives with no threads; the first snapshot sets the baseline. | ||
| for (const thread of item.snapshot.threads) observeThread(tracker, thread, true); |
There was a problem hiding this comment.
Nit — Finishes and waits that happen while the socket is down are never alerted. Each reconnect builds a fresh tracker, and the first snapshot silently becomes the baseline, so a run that completes during the reconnect backoff never sends "Agent finished". The relay avoids this with terminalWorkSinceStart. Keep lastKeys across reconnects, or alert on entries whose run finished after the last connection.
There was a problem hiding this comment.
Fixed in fc9d3e2. The tracker now lives across reconnects (it's replaced only if the environment ID changes). Only the first snapshot is a silent baseline. A reconnect's snapshot compares against the kept keys, so a run that finished during the backoff alerts. Held completions are no longer cleared when the socket closes.
| export function observeThread(tracker: Tracker, thread: ObservedThread, silent: boolean) { | ||
| const state = awareness(tracker, thread); | ||
| const key = alertKey(state, thread.pendingRuntimeRequest?.id ?? null); | ||
| const previous = tracker.lastKeys.get(thread.id) ?? null; |
There was a problem hiding this comment.
Nit — previous defaults to null for any thread the tracker hasn't seen. A settled thread that first appears through thread.updated, such as an unarchived thread moving back to active, then looks like a new transition and fires "Agent finished" for old work. Treat a first sighting as a baseline unless a run started while the tracker was watching.
There was a problem hiding this comment.
Fixed in fc9d3e2. A thread first seen already completed or failed alerts only if latestRunCompletedAt is after the tracker started, the relay's terminalWorkSinceStart rule. A first sighting that's waiting still alerts. New test covers both.
| const retried = await sendToApns({ ...device, environment: other }, payload); | ||
| if (retried.status === 200) { | ||
| saveDevices( | ||
| readDevices().map((d) => (d.token === device.token ? { ...d, environment: other } : d)), |
There was a problem hiding this comment.
Nit — notifyAll is fired without await for each notification and does unlocked read-modify-write cycles on devices.json (environment learning, 410 removal, registration). Concurrent sends can overwrite each other. For example, a learned sandbox environment can get reverted by a stale save. Keep devices in memory with one serialized writer.
There was a problem hiding this comment.
Fixed in fc9d3e2. Sends go through one promise chain, and registrations queue on the same chain, so devices.json has one writer at a time.
| ping = setInterval(() => socket.send(JSON.stringify({ _tag: "Ping" })), 30_000); | ||
| }); | ||
| socket.addEventListener("message", (event) => { | ||
| const parsed: unknown = JSON.parse(String(event.data)); |
There was a problem hiding this comment.
Nit — One malformed frame crashes the service. JSON.parse(String(event.data)) sits outside any try, and in Node a throw from an EventTarget listener becomes uncaughtException. launchd restarts the process, but the pending settle timers are lost, and the restart's silent snapshot swallows any held completion. Wrap the parse in try/catch, the same way the per-item decode already is.
There was a problem hiding this comment.
Fixed in fc9d3e2. The frame parse is wrapped. A frame that isn't JSON is logged and skipped.
| response.writeHead(200).end("ok"); | ||
| return; | ||
| } | ||
| if (request.method !== "POST" || path !== "/register") { |
There was a problem hiding this comment.
Nit — /no3y-push/register accepts any well-formed hex token with no credential, so any tailnet peer, including shared-in nodes, can subscribe to every alert along with its project and thread titles. Consider requiring a shared secret, or the T3 bearer the phone already holds for that route.
There was a problem hiding this comment.
Not changed in this PR. Checking the phone's T3 bearer against the server is the right boundary, but the route is only reachable inside the tailnet, so I've left it for the maintainer to decide whether it's worth doing now.
An automation bound to an existing thread (a bot check-in, say) makes no new thread, so its finish and approval alerts were noise. Before alerting, the push service reads the thread's recent turn items and stays silent when the run was started by an automation's message in a thread that already had history. Runs an automation launches as new threads still alert, and a failed check alerts anyway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR-review automations launch each run as a new thread that the roster hides, and those runs still alerted on the phone. The push service now applies the roster rule first: a thread with a scheduledTaskId that is not pinned sends nothing. Runs from automations that list their runs, and pinned runs, still alert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The phone sends its bundle ID with its token, and the service uses it as the APNs topic, so dev and preview builds get pushes. Upstream-identity builds no longer ask for notification permission. - A subagent waiting on an approval or an answer alerts on its top-level thread, rolled up the way AgentAwarenessRelay does. - A completion settled during the 5-second hold still alerts. - The tracker survives reconnects, so work that finished while the socket was down alerts, and a thread first seen already finished stays silent unless it finished while the service was running. - Sends and registrations are serialized so devices.json writes can't overwrite each other; a malformed frame is skipped instead of crashing; the server origin is re-read from server-runtime.json on each reconnect; non-thread pushes group under the relay's "t3-agent-alerts". - Team ID, bundle ID and the mount path live once in no3yConstants.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Replies to the code-quality review of Fixed
Not in this commit, for the maintainer to decide
|
Thread transfer impact
This comment will update automatically after the next completed run. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fork had no iOS app of its own: upstream's App Store app can't show fork UI, and a rebuilt copy can't use Ping's Apple team, Clerk sign-in, or relay pushes. This makes
apps/mobilebuild as no3y Code under the fork's own Apple team and adds a push service on the Mac so the app still gets agent notifications.Rebrand (
no3y-mobile-identity)apps/mobile/fork/identity.tsswaps in the no3y name, icons, bundle IDs (com.noahhendrickson.no3ycode,.dev,.preview) and team4WDT6B6JDX. It drops Ping's linked domains and Expo project, and turns OTA updates off.app.config.ts. The first runs before upstream derives the widget, share-extension, app-group and keychain IDs, so every target follows the new identity.NO3Y_MOBILE_IDENTITY=0builds upstream's identity. Upstream'sapp.config.test.tspins it to 0 with one fenced line.t3code://scheme stays shared, because the widgets andApp.tsxhardcode it.Notifications (
no3y-push)apps/mobile/fork/push-service/no3yPush.mtsis a plain Node service with no new dependencies. It pairs with the local T3 server as a read-only client and watchesorchestration.subscribeShell. It pushes to APNs with the fork's key, which lives in~/.no3y-pushand never in the repo.projectThreadAwarenessV2rule (imported) and restates the relay's per-thread policy: a subagent's wait alerts on its top-level thread, completions are held 5 seconds and still alert if settled during the hold, and work that finished while disconnected alerts on reconnect. Its payload matches the relay's, so upstream's tap handler opens the thread./no3y-push/registeron each saved Tailscale HTTPS route, where Tailscale Serve mounts the service beside the T3 server.node no3yPush.mts installadds a launchd login item and the Tailscale route.Verified
apps/mobile/fork/identity.test.ts(all three variants plus the opt-out) andapps/mobile/fork/push-service/no3yPush.test.ts(one alert per wait, the completion hold, and a payload the app's tap handler opens). Guard tests for both manifest entries are included.vp run check:changedand.fork/lint-owned.mjspass.Known limits
🤖 Signed: Claude Opus 5.5 (
claude-opus-5-5) via Claude CodeReview fixes (fc9d3e2): Claude Opus 5.5 (
claude-opus-5-5) via Claude Code.Research input: Gemini 4 Neon (
gemini-4-neon, Antigravity) and GPT-6.2 Sol (gpt-6.2-sol, Codex) gave second opinions on the approach; no code from them.