Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li

### Added
- **GitHub rows open on the Mac.** Open a saved run, notification or pull request from a widget without marking it read.
- **cmux session navigation.** A Claude card selects its cmux panel through the bundled CLI when the running process identifies both workspace and surface and socket access allows it. Otherwise it brings cmux forward.
- **Local Docker and AI models.** Registry widgets can show up to 200 local containers and observed Ollama or MLX models. Fremkit refuses remote Docker contexts, distinguishes a missing CLI from a stopped daemon, and keeps the container list when stats fail.
- **The Uptime tile shows time since boot.** The reading comes from macOS and remains unavailable when the system cannot provide it.
- **Borrow the Edge display.** Hide or show the dashboard from the helper menu without quitting it. Hidden state survives display rearrangements, and the mouse fence pauses while the Edge is borrowed. Touch and data collection continue; the dashboard reappears after a helper restart.
Expand Down
15 changes: 11 additions & 4 deletions docs/claude-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Only the tool name and a short summary reach Fremkit. Tool inputs and outputs ar
never stored.

The hook also adds a `client` object saying where the session lives: the terminal application's
bundle id, `TERM_PROGRAM`, the pid of the `claude` process, its tty, and — under Orca — the pane
and tab it runs in. It is the only way anything can know: the server otherwise sees a session id
and a working directory, and two sessions in two panes of the same folder are the same pair of
strings. It is what makes the ↗ on a card work.
bundle id, `TERM_PROGRAM`, the pid of the `claude` process, its tty, and the Orca pane
handle when present. For cmux, the server reads workspace and surface ids from the live
process. The server otherwise sees only a session id and a working directory, which cannot
distinguish two panes of the same folder. These details make the ↗ on a card work.

That object stays on the server. The dashboard is told which *kind* of application it is and what
to call it (`Orca`, `Terminal`, `iTerm2`, `VS Code`), never the pane key or the tty.
Expand All @@ -61,10 +61,17 @@ corner. What happens depends on the application:
| Client | What is raised |
|---|---|
| Orca | the exact pane, through `orca terminal switch --terminal <handle>` |
| cmux | the exact panel through the bundled `cmux focus-panel` CLI when the socket permits external clients; otherwise the application |
| Terminal.app, iTerm2 | the tab whose tty matches, through AppleScript — macOS asks once to allow it |
| VS Code | the window already open on that folder |
| anything else | the application, by its bundle id |

The helper starts Fremkit outside cmux. With cmux socket control set to `cmuxOnly`, the
`focus-panel` command is denied and touching a card brings cmux forward without selecting
its panel. Exact panel selection requires a socket mode that allows the helper's process,
such as `allowAll`; that mode expands local socket access. Keep `cmuxOnly` if you prefer the
restricted mode and use the application fallback.

A session whose hook never said where it lives — one Fremkit found by scanning processes, or one
from before this existed — shows no arrow at all.

Expand Down
43 changes: 41 additions & 2 deletions server/src/claude/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ export async function clientOfProcess(pid: number, reader: Reader = read): Promi
const bundleId = pick('__CFBundleIdentifier')
const program = pick('TERM_PROGRAM')
const terminal = pick('ORCA_TERMINAL_HANDLE')
const workspace = pick('CMUX_WORKSPACE_ID')
const surface = pick('CMUX_SURFACE_ID')
const tty = await ttyOfProcess(pid, reader)
if (!bundleId && !program && !terminal) return undefined
if (!bundleId && !program && !terminal && !workspace) return undefined
return {
...(bundleId && BUNDLE_RE.test(bundleId) ? { bundleId } : {}),
...(program ? { program } : {}),
pid,
...(workspace && surface && UUID_RE.test(workspace) && UUID_RE.test(surface) ? { cmux: { workspace, surface } } : {}),
...(tty ? { tty } : {}),
...(terminal && ORCA_TERMINAL_RE.test(terminal) ? { orca: { terminal } } : {}),
}
Expand Down Expand Up @@ -100,6 +103,9 @@ export async function appOfProcess(pid: number, reader: Reader = read): Promise<
const ORCA_CLI = '/Applications/Orca.app/Contents/Resources/bin/orca'
const ORCA_BUNDLE = 'com.stablyai.orca'
const VSCODE_BUNDLE = 'com.microsoft.VSCode'
const CMUX_BUNDLE = 'com.cmuxterm.app'
const CMUX_CLI = '/Applications/cmux.app/Contents/Resources/bin/cmux'
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i

/** A bundle id, as `open -b` will take it. */
const BUNDLE_RE = /^[A-Za-z0-9.-]{1,120}$/
Expand Down Expand Up @@ -184,11 +190,44 @@ export async function focusClient(
reader: Reader = read,
): Promise<FocusResult> {
try {
// Hooks written before cmux support already identify the app. Read the live process once
// to recover its panel and reuse its client details for the no-hook fallback below.
const livePid = pid ?? client?.pid
let live: SessionClient | undefined
if (livePid && Number.isSafeInteger(livePid) && livePid > 1 &&
(!client?.bundleId || client.bundleId.toLowerCase() === CMUX_BUNDLE)) {
live = await clientOfProcess(livePid, reader)
}
if (client?.bundleId?.toLowerCase() === CMUX_BUNDLE && live?.bundleId &&
live.bundleId.toLowerCase() !== CMUX_BUNDLE) {
client = { ...client, bundleId: live.bundleId, cmux: undefined }
}
// A terminal launched from cmux can inherit its bundle id and panel IDs.
// TERM_PROGRAM identifies the actual host in that case.
const program = (live?.program ?? client?.program)?.toLowerCase()
const otherProgramBundle = program === 'vscode' ? VSCODE_BUNDLE
: program === 'iterm.app' ? 'com.googlecode.iterm2'
: program === 'apple_terminal' ? 'com.apple.Terminal' : undefined
if (otherProgramBundle && client?.bundleId?.toLowerCase() === CMUX_BUNDLE) {
client = { ...client, bundleId: otherProgramBundle, program, cmux: undefined }
}
const panel = live?.cmux ?? client?.cmux
// A shell launched inside cmux may pass CMUX_* to an unrelated client. The bundle must
// still identify cmux, and an explicit Orca pane takes precedence.
if (panel && UUID_RE.test(panel.workspace) && UUID_RE.test(panel.surface) &&
!otherProgramBundle && (live?.bundleId ?? client?.bundleId)?.toLowerCase() === CMUX_BUNDLE &&
!live?.orca?.terminal && !client?.orca?.terminal) {
try {
await runner(CMUX_CLI, ['focus-panel', '--panel', panel.surface, '--workspace', panel.workspace])
await runner('/usr/bin/open', ['-b', CMUX_BUNDLE])
return { ok: true, how: 'pane' }
} catch { return await focusApp(CMUX_BUNDLE, runner) }
}
if (!client?.bundleId && pid) {
// No report from a hook: the process's own environment says the same things the hook
// would have — the exact Orca pane, the terminal, the tty. Failing that, the process tree
// still says which application owns it.
const fromEnv = await clientOfProcess(pid, reader)
const fromEnv = livePid === pid ? live : await clientOfProcess(pid, reader)
if (fromEnv && (fromEnv.orca?.terminal || fromEnv.program)) {
client = fromEnv
} else {
Expand Down
1 change: 1 addition & 0 deletions server/src/claude/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface SessionClient {
pid?: number
tty?: string
terminalSession?: string
cmux?: { workspace: string; surface: string }
orca?: { pane?: string; tab?: string; terminal?: string }
}

Expand Down
69 changes: 69 additions & 0 deletions server/test/claude-focus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,72 @@ describe('the focus command', () => {
await expect(provider(new ClaudeTracker()).commands!.focus({}, { loopback: true })).rejects.toThrow()
})
})


describe('cmux session navigation', () => {
const workspace = '85F7E39D-4EC1-43B6-ADA7-CDCDF7A354EB'
const surface = '22C82604-948E-469D-B2B4-849070102A18'
it('uses the live process panel even when the hook already named cmux', async () => {
const calls: string[][] = []
const reader = async (_cmd: string, args: string[]) => args[0] === 'eww'
? `claude TERM_PROGRAM=ghostty __CFBundleIdentifier=com.cmuxterm.app CMUX_WORKSPACE_ID=${workspace} CMUX_SURFACE_ID=${surface}` : 'ttys003'
const result = await focusClient({ bundleId: 'com.cmuxterm.app', program: 'ghostty', pid: 123 }, '/x',
async (cmd, args) => { calls.push([cmd, ...args]) }, 123, reader)
expect(result).toEqual({ ok: true, how: 'pane' })
expect(calls).toEqual([
['/Applications/cmux.app/Contents/Resources/bin/cmux', 'focus-panel', '--panel', surface, '--workspace', workspace],
['/usr/bin/open', '-b', 'com.cmuxterm.app'],
])
})
it.each([
['vscode', 'com.microsoft.VSCode', ['/usr/bin/open', '-b', 'com.microsoft.VSCode', '/project']],
['iTerm.app', 'com.googlecode.iterm2', ['/usr/bin/open', '-b', 'com.googlecode.iterm2']],
['Apple_Terminal', 'com.apple.Terminal', ['/usr/bin/open', '-b', 'com.apple.Terminal']],
])('honours %s over inherited cmux IDs', async (program, _bundle, expected) => {
const calls: string[][] = []
const reader = async (_cmd: string, args: string[]) => args[0] === 'eww'
? `claude TERM_PROGRAM=${program} __CFBundleIdentifier=com.cmuxterm.app CMUX_WORKSPACE_ID=${workspace} CMUX_SURFACE_ID=${surface}` : 'ttys003'
const result = await focusClient({ bundleId: 'com.cmuxterm.app', pid: 123 }, '/project',
async (cmd, args) => { calls.push([cmd, ...args]) }, 123, reader)
expect(result.ok).toBe(true)
expect(calls.some(call => call[0].endsWith('/cmux'))).toBe(false)
expect(calls.at(-1)).toEqual(expected)
})
it('falls back to fronting cmux when selecting the panel fails', async () => {
const calls: string[][] = []
const reader = async (_cmd: string, args: string[]) => args[0] === 'eww'
? `claude __CFBundleIdentifier=com.cmuxterm.app CMUX_WORKSPACE_ID=${workspace} CMUX_SURFACE_ID=${surface}` : 'ttys003'
const result = await focusClient({ bundleId: 'com.cmuxterm.app' }, '/x', async (cmd, args) => {
calls.push([cmd, ...args])
if (cmd.endsWith('/cmux')) throw new Error('panel closed')
}, 123, reader)
expect(result).toEqual({ ok: true, how: 'app' })
expect(calls.at(-1)).toEqual(['/usr/bin/open', '-b', 'com.cmuxterm.app'])
})
it('does not route an inherited cmux handle ahead of an Orca pane', async () => {
const calls: string[][] = []
const reader = async (_cmd: string, args: string[]) => args[0] === 'eww'
? `claude __CFBundleIdentifier=com.cmuxterm.app ORCA_TERMINAL_HANDLE=term_123 CMUX_WORKSPACE_ID=${workspace} CMUX_SURFACE_ID=${surface}` : 'ttys003'
const result = await focusClient({ bundleId: 'com.stablyai.orca', orca: { terminal: 'term_123' } }, '/x',
async (cmd, args) => { calls.push([cmd, ...args]) }, 123, reader)
expect(result).toEqual({ ok: true, how: 'pane' })
expect(calls[0]?.[0]).toContain('/orca')
expect(calls.some(call => call[0].endsWith('/cmux'))).toBe(false)
})
it('uses the live client when an unrelated process inherited CMUX variables', async () => {
const calls: string[][] = []
const reader = async (_cmd: string, args: string[]) => args[0] === 'eww'
? `code __CFBundleIdentifier=com.microsoft.VSCode CMUX_WORKSPACE_ID=${workspace} CMUX_SURFACE_ID=${surface}` : 'ttys003'
const result = await focusClient({ bundleId: 'com.cmuxterm.app' }, '/project',
async (cmd, args) => { calls.push([cmd, ...args]) }, 123, reader)
expect(result).toEqual({ ok: true, how: 'app' })
expect(calls).toEqual([['/usr/bin/open', '-b', 'com.microsoft.VSCode', '/project']])
})
it('never puts invalid process handles into a link', async () => {
const calls: string[][] = []
const reader = async () => 'CMUX_WORKSPACE_ID=--bad CMUX_SURFACE_ID=../../evil __CFBundleIdentifier=com.cmuxterm.app'
expect(await focusClient({ bundleId: 'com.cmuxterm.app' }, '/x', async (cmd, args) => { calls.push([cmd, ...args]) }, 123, reader))
.toEqual({ ok: true, how: 'app' })
expect(calls).toEqual([['/usr/bin/open', '-b', 'com.cmuxterm.app']])
})
})
Loading