From b7c4f50118e2e2c2b9531a07b0020414467a01b7 Mon Sep 17 00:00:00 2001 From: Mike Lyons Date: Wed, 25 Nov 2026 12:30:05 -0500 Subject: [PATCH 01/27] Spike: Expo mobile client for Ness backends Adds a standalone Expo app under mobile/ that pairs with a Ness backend (desktop WS server or harness-server) via the Settings QR, a pasted link, or a deep link, then mirrors state with the shared rootReducer and WebSocketClientTransport imported straight from src/shared. Screens: worktree list with rolled-up status, a json-mode chat transcript, send-message, and allow/deny for pending permission requests. Verified on Expo web and in Expo Go on the iOS simulator against a headless backend. Root build untouched apart from excluding mobile/** from vitest. Co-Authored-By: Claude Opus 5.5 --- mobile/.gitignore | 41 + mobile/AGENTS.md | 41 + mobile/App.tsx | 447 ++ mobile/CLAUDE.md | 1 + mobile/app.json | 43 + mobile/assets/android-icon-background.png | Bin 0 -> 17549 bytes mobile/assets/android-icon-foreground.png | Bin 0 -> 78796 bytes mobile/assets/android-icon-monochrome.png | Bin 0 -> 4140 bytes mobile/assets/favicon.png | Bin 0 -> 1129 bytes mobile/assets/icon.png | Bin 0 -> 393493 bytes mobile/assets/splash-icon.png | Bin 0 -> 17547 bytes mobile/index.ts | 8 + mobile/metro.config.js | 21 + mobile/package-lock.json | 6357 +++++++++++++++++++++ mobile/package.json | 27 + mobile/src/ness.ts | 120 + mobile/src/storage.ts | 34 + mobile/tsconfig.json | 6 + vitest.config.ts | 3 +- 19 files changed, 7148 insertions(+), 1 deletion(-) create mode 100644 mobile/.gitignore create mode 100644 mobile/AGENTS.md create mode 100644 mobile/App.tsx create mode 100644 mobile/CLAUDE.md create mode 100644 mobile/app.json create mode 100644 mobile/assets/android-icon-background.png create mode 100644 mobile/assets/android-icon-foreground.png create mode 100644 mobile/assets/android-icon-monochrome.png create mode 100644 mobile/assets/favicon.png create mode 100644 mobile/assets/icon.png create mode 100644 mobile/assets/splash-icon.png create mode 100644 mobile/index.ts create mode 100644 mobile/metro.config.js create mode 100644 mobile/package-lock.json create mode 100644 mobile/package.json create mode 100644 mobile/src/ness.ts create mode 100644 mobile/src/storage.ts create mode 100644 mobile/tsconfig.json diff --git a/mobile/.gitignore b/mobile/.gitignore new file mode 100644 index 000000000..d914c328f --- /dev/null +++ b/mobile/.gitignore @@ -0,0 +1,41 @@ +# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files + +# dependencies +node_modules/ + +# Expo +.expo/ +dist/ +web-build/ +expo-env.d.ts + +# Native +.kotlin/ +*.orig.* +*.jks +*.p8 +*.p12 +*.key +*.mobileprovision + +# Metro +.metro-health-check* + +# debug +npm-debug.* +yarn-debug.* +yarn-error.* + +# macOS +.DS_Store +*.pem + +# local env files +.env*.local + +# typescript +*.tsbuildinfo + +# generated native folders +/ios +/android diff --git a/mobile/AGENTS.md b/mobile/AGENTS.md new file mode 100644 index 000000000..be05e778d --- /dev/null +++ b/mobile/AGENTS.md @@ -0,0 +1,41 @@ +This is an Expo/React Native mobile application. Prioritize mobile-first patterns, performance, and cross-platform compatibility. + +## Expo has changed — do not trust your training data + +Expo ships breaking changes every SDK release. APIs you remember are likely renamed, moved, or removed. Before writing any code that touches an Expo, EAS, or React Native API: + +1. Read the major version of the `expo` package in `package.json`. +2. Fetch the matching versioned docs: `https://docs.expo.dev/versions/v.0.0/` +3. For anything else, fetch https://docs.expo.dev/llms.txt — an index of all Expo docs with corrections to common LLM misconceptions. Follow its links to the specific page you need; never answer from memory. + +## Commands + +Use `bunx` instead of `npx` if the project uses bun (`bun.lock` present). + +```bash +npx expo install # ALWAYS use instead of npm/yarn/pnpm/bun add — resolves SDK-compatible versions +npx expo start # start the dev server +npx expo lint # lint +npx tsc --noEmit # typecheck +npx expo-doctor # diagnose dependency and config issues +npx expo install --fix # fix incompatible package versions +``` + +Run lint and typecheck before declaring any task done. + +## Navigation & Routing + +- Use **Expo Router** for all navigation. Routes live in `src/app/` — every file there is a screen, `_layout.tsx` files define navigators. Keep non-route code (components, hooks, utils) outside `src/app/`. +- Import `Link`, `router`, and `useLocalSearchParams` from `expo-router`. +- Docs: https://docs.expo.dev/router/introduction.md + +## Building with EAS + +Use EAS to build, sign, and submit the app in the cloud (`eas build`, `eas submit`) and to ship over-the-air updates (`eas update`) — no local Xcode or Android Studio required. Run EAS CLI as `bunx eas-cli ` in Bun projects, or `npx eas-cli@latest ` otherwise; substitute that for bare `eas` in docs examples. +Docs: https://docs.expo.dev/eas/index.md + +## Rules + +- If `ios/` and `android/` directories do not exist, they are generated (Continuous Native Generation). Never create or edit them by hand — configure native behavior in `app.json` and config plugins. +- Expo Go only includes its bundled native modules. After adding a library with native code, the app needs a development build: `npx expo run:ios|android` locally, or `eas build --profile development`. +- Prefer recommended Expo modules over third-party libraries, and check your available skills before adding dependencies. Docs: https://docs.expo.dev/versions/latest/index.md diff --git a/mobile/App.tsx b/mobile/App.tsx new file mode 100644 index 000000000..ce2bc2fd2 --- /dev/null +++ b/mobile/App.tsx @@ -0,0 +1,447 @@ +// Spike UI: pair → worktree list → one chat. Deliberately a single file +// with state-switched screens (no Expo Router) — the point is to prove +// the data path, not the navigation shell. +import { StatusBar } from 'expo-status-bar' +import { CameraView, useCameraPermissions } from 'expo-camera' +import { useEffect, useMemo, useRef, useState } from 'react' +import { + ActivityIndicator, + FlatList, + KeyboardAvoidingView, + Linking, + Platform, + Pressable, + SafeAreaView, + StyleSheet, + Text, + TextInput, + View +} from 'react-native' +import { parseConnectionUrl } from '../src/shared/transport/parse-connection-url' +import type { JsonClaudeChatEntry, JsonClaudePendingApproval } from '../src/shared/state/json-claude' +import type { PtyStatus } from '../src/shared/state/terminals' +import { NessClient, rollupStatus, tabsOf, useConnected, useNess } from './src/ness' +import { clearConnection, loadConnection, saveConnection, type SavedConnection } from './src/storage' + +const STATUS_COLOR: Record = { + idle: '#555', + waiting: '#3b82f6', + processing: '#eab308', + 'needs-approval': '#ef4444' +} + +export default function App() { + const [conn, setConn] = useState(undefined) + useEffect(() => { + void loadConnection().then(setConn) + }, []) + + // Deep-link pairing: ://pair?url=. In Expo Go + // that's exp:///--/pair?url=…; a production app would register + // ness:// so the desktop QR could open it straight from the system + // camera, no in-app scanner needed. + useEffect(() => { + const handle = (link: string | null | undefined) => { + if (!link) return + const m = /[?&]url=([^&]+)/.exec(link) + if (!m) return + const r = parseConnectionUrl(decodeURIComponent(m[1])) + if (!r.ok) return + const c = { wsUrl: r.parsed.wsUrl, token: r.parsed.token } + void saveConnection(c) + setConn(c) + } + void Linking.getInitialURL().then(handle) + const sub = Linking.addEventListener('url', (e) => handle(e.url)) + return () => sub.remove() + }, []) + + if (conn === undefined) return + if (!conn) { + return ( + { + void saveConnection(c) + setConn(c) + }} + /> + ) + } + return ( + { + void clearConnection() + setConn(null) + }} + /> + ) +} + +// ── Pairing ──────────────────────────────────────────────────────────── + +function PairScreen({ onPaired }: { onPaired: (c: SavedConnection) => void }) { + const [text, setText] = useState('') + const [error, setError] = useState(null) + const [scanning, setScanning] = useState(false) + const [permission, requestPermission] = useCameraPermissions() + const handled = useRef(false) + + // Same parser the desktop "Add Backend" modal uses, so the Settings QR + // (http://:/?token=…) and a pasted link both work. + function tryPair(raw: string): void { + const r = parseConnectionUrl(raw) + if (!r.ok) { + setError(r.error) + return + } + onPaired({ wsUrl: r.parsed.wsUrl, token: r.parsed.token }) + } + + return ( + + + Scan the QR in Ness → Settings → Web & mobile, or paste the link. + + {scanning ? ( + + { + if (handled.current) return + handled.current = true + setScanning(false) + tryPair(data) + }} + /> + + ) : ( + diff --git a/src/renderer/components/MobileApp.tsx b/src/renderer/components/MobileApp.tsx index e4219d729..ae2deb7c5 100644 --- a/src/renderer/components/MobileApp.tsx +++ b/src/renderer/components/MobileApp.tsx @@ -84,6 +84,8 @@ export function MobileApp(): JSX.Element { const [newWorktreeRepo, setNewWorktreeRepo] = useState(undefined) const [showNewWorktree, setShowNewWorktree] = useState(false) const [newWorktreeFocusPath, setNewWorktreeFocusPath] = useState(null) + // "Build a custom tool…" prefill, same as the desktop's newWorktreePrefill. + const [newWorktreePrefill, setNewWorktreePrefill] = useState<{ branch: string; prompt: string } | null>(null) useEffect(() => { if (!activeWorktreeId) return @@ -197,7 +199,37 @@ export function MobileApp(): JSX.Element { [activeWorktree] ) + // Same routing as the desktop's handleSendToAgent: the phone's selected + // tab if it takes messages, else a pane's active one, else the first. + const handleSendToAgent = useCallback( + (wtPath: string, text: string) => { + const tree = panes[wtPath] + const leaves = tree ? getLeaves(tree) : [] + const sendable = (t: TerminalTab): boolean => t.type === 'agent' || t.type === 'json-claude' + const all = leaves.flatMap((l) => l.tabs) + const claimed = all.find((t) => t.id === selectedTabByWorktree[wtPath]) + const target = + (claimed && sendable(claimed) ? claimed : undefined) ?? + leaves.map((l) => l.tabs.find((t) => t.id === l.activeTabId)).find((t): t is TerminalTab => !!t && sendable(t)) ?? + all.find(sendable) + if (!target) return + setSelectedTabByWorktree((prev) => ({ ...prev, [wtPath]: target.id })) + setRightPanelOpen(false) + if (target.type === 'json-claude') backend.sendJsonClaudeMessage(target.id, text) + else backend.writeTerminal(target.id, '\x1b[200~' + text + '\x1b[201~') + }, + [panes, selectedTabByWorktree] + ) + + const handleBuildCustomTool = useCallback((branch: string, prompt: string) => { + setNewWorktreePrefill({ branch, prompt }) + setNewWorktreeRepo(undefined) + setShowNewWorktree(true) + setRightPanelOpen(false) + }, []) + const handleOpenNewWorktree = useCallback((repoRoot?: string) => { + setNewWorktreePrefill(null) setNewWorktreeRepo(repoRoot) setShowNewWorktree(true) setPickerOpen(false) @@ -344,6 +376,8 @@ export function MobileApp(): JSX.Element { onCancel={() => setShowNewWorktree(false)} repoRoots={wtState.repoRoots} defaultRepoRoot={newWorktreeRepo ?? activeWorktree?.repoRoot} + initialBranch={newWorktreePrefill?.branch} + initialPrompt={newWorktreePrefill?.prompt} /> )} @@ -351,8 +385,12 @@ export function MobileApp(): JSX.Element { {rightPanelOpen && ( setRightPanelOpen(false)} /> )} diff --git a/src/renderer/components/MobileRightPanel.tsx b/src/renderer/components/MobileRightPanel.tsx index 26fb445c8..ea428c5cd 100644 --- a/src/renderer/components/MobileRightPanel.tsx +++ b/src/renderer/components/MobileRightPanel.tsx @@ -1,35 +1,47 @@ import { useCallback } from 'react' import { useRepoConfigs, useSettings } from '../store' import { useBackend } from '../backend' -import { PRStatusPanel, MergeLocallyPanel } from './PRStatusPanel' -import { BranchCommitsPanel } from './BranchCommitsPanel' -import { CostPanel } from './CostPanel' +import { RightColumnToolbar } from './RightColumnToolbar' +import { RightPanelStack, useRightPanelConfig } from './RightColumn' +import { BUILD_CUSTOM_TOOL_BRANCH, BUILD_CUSTOM_TOOL_PROMPT } from '../../shared/tools' import type { Worktree, PRStatus } from '../types' interface MobileRightPanelProps { activeWorktree: Worktree | null + worktrees: Worktree[] + /** The tab the phone has selected — what the desktop calls the focused + * tab. Todos / Agents / Context / Subscriptions read its session. */ + focusedTabId: string | null prStatuses: Record prLoading: boolean + onSendToAgent: (worktreePath: string, text: string) => void + /** Opens the new-worktree screen pre-filled, as the desktop does. */ + onBuildCustomTool: (branch: string, prompt: string) => void onClose: () => void } -// Fullscreen takeover that surfaces the useful slices of the desktop -// right panel — PR status, local merge, branch commits, cost. File -// panels (ChangedFiles / AllFiles) are intentionally omitted: their -// primary interaction is "tap a file to open a diff tab", and mobile -// can't render diff/file tabs meaningfully. +// Fullscreen takeover with the desktop's full right column: the same +// panels, in the repo's configured order, with the same visibility / +// reorder toolbar (RightPanelStack is shared with RightColumn). Openers +// that need a diff or file tab — which a phone can't show — are left out, +// so those rows don't open anything; everything else is identical. export function MobileRightPanel({ activeWorktree, + worktrees, + focusedTabId, prStatuses, prLoading, + onSendToAgent, + onBuildCustomTool, onClose }: MobileRightPanelProps): JSX.Element { const backend = useBackend() const repoConfigs = useRepoConfigs() const settings = useSettings() const hasGithubToken = settings.hasGithubToken || !!settings.githubAuthSource - const activeRepoConfig = activeWorktree ? repoConfigs[activeWorktree.repoRoot] ?? null : null - void activeRepoConfig + const activeRepoRoot = activeWorktree?.repoRoot ?? null + const activeRepoConfig = activeRepoRoot ? repoConfigs[activeRepoRoot] ?? null : null + const config = useRightPanelConfig(activeWorktree?.path ?? null, activeRepoRoot, activeRepoConfig) const handleRefresh = useCallback(() => { void backend.refreshPRsAll() @@ -38,6 +50,8 @@ export function MobileRightPanel({ const handleRemoveWorktree = useCallback( (path: string): void => { if (!activeWorktree) return + // A stray tap is easy on a phone and removal can't be undone here. + if (!window.confirm(`Remove worktree ${activeWorktree.branch || path}? It will be deleted from disk.`)) return void backend.removeWorktree(activeWorktree.repoRoot, path) onClose() }, @@ -53,26 +67,33 @@ export function MobileRightPanel({ )} {activeWorktree && ( <> -