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 @@ -36,6 +36,7 @@ tagged `vX.Y.Z`.
### 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.
- **Optional Apple Silicon CPU temperature.** Install macmon separately and enable it in Screen privacy settings. Sampling stays local and off by default; a recent reading does not delay system metrics.
- **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
2 changes: 1 addition & 1 deletion docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Each `cities` item: `label` (string), `timezone` (timezone), `hour12` (boolean,

## cpu

*CPU* — load and, when the machine reports one, temperature.
*CPU* — load and, when the machine reports one, temperature. On Apple Silicon, install the third-party open-source tool with `brew install macmon`, then enable **Read the CPU temperature with macmon** in Screen privacy settings. Fremkit does not install macmon. After opt-in, it runs only `/opt/homebrew/bin/macmon` or `/usr/local/bin/macmon` locally every 10 seconds, returns the last reading without delaying CPU load, and falls back to the system value if no recent macmon sample is available.

Minimum size 8 × 4, default 8 × 4. Compact width 4 cells.

Expand Down
3 changes: 3 additions & 0 deletions server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { backupRoutes } from './backup/routes.js'
import { bambuRoutes } from './bambu/routes.js'
import { createShortcutsProvider } from './providers/shortcuts.js'
import { createServiceStatusProvider } from './providers/service-status.js'
import { createSystemProvider } from './providers/system.js'
import { findInstance, findInstances } from './config/instances.js'
import { migrateHomeySecret } from './config/migrate.js'
import { BYTES_CSP, isByteRoute } from './http/headers.js'
Expand Down Expand Up @@ -149,6 +150,8 @@ export async function buildApp(opts: AppOptions): Promise<FastifyInstance> {
)
hub = new Hub(registry)
for (const p of opts.providers ?? []) registry.register(p)
// Consent lives in the config store, so this provider is registered beside the Claude providers.
registry.register(createSystemProvider({ macmonTemperatureEnabled: () => store.get().privacy.macmonTemperature }))
registry.register(createClaudeSessionsProvider(tracker))
registry.register(createClaudeUsageProvider(usage))
registry.register(createClaudeAccountProvider({
Expand Down
2 changes: 1 addition & 1 deletion server/src/config/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function migrateConfig(raw: unknown): Config {
connections: [],
secrets: { backend: defaultSecretsBackend() },
locale: defaultLocale(),
privacy: { claudeAccountUsage: false, showAccountEmail: false, codexAccount: false, codexHistorySources: [] },
privacy: { claudeAccountUsage: false, showAccountEmail: false, codexAccount: false, codexHistorySources: [], macmonTemperature: false },
// A v1 config predates the marketplace by a long way; nothing can have been installed.
marketplace: { installed: {} },
pages: v1.pages.map((p) => ({
Expand Down
4 changes: 3 additions & 1 deletion server/src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ const PrivacySchema = z.object({
showAccountEmail: z.boolean().default(false),
codexAccount: z.boolean().default(false),
codexHistorySources: z.array(HistorySourceSchema).max(10).default([]),
/** Read CPU temperature from the optional local macmon executable. */
macmonTemperature: z.boolean().default(false),
}).prefault({})

/**
Expand Down Expand Up @@ -352,7 +354,7 @@ export const DEFAULT_CONFIG: Config = {
connections: [],
secrets: { backend: defaultSecretsBackend() },
locale: defaultLocale(),
privacy: { claudeAccountUsage: false, showAccountEmail: false, codexAccount: false, codexHistorySources: [] },
privacy: { claudeAccountUsage: false, showAccountEmail: false, codexAccount: false, codexHistorySources: [], macmonTemperature: false },
marketplace: { installed: {} },
pages: [
{
Expand Down
2 changes: 0 additions & 2 deletions server/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createDockerProvider, createLocalModelsProvider } from './local-operations.js'
import type { Provider } from './types.js'
import { systemProvider } from './system.js'
import { processesProvider } from './processes.js'
import { createVolumeProvider } from './volume.js'
import { createSpotifyProvider } from './spotify.js'
Expand All @@ -13,7 +12,6 @@ import { createBatteryProvider } from './battery.js'
export const providers: Provider[] = [
createDockerProvider(),
createLocalModelsProvider(),
systemProvider,
processesProvider,
createVolumeProvider(),
createSpotifyProvider(),
Expand Down
67 changes: 67 additions & 0 deletions server/src/providers/mac-thermals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { execFile } from 'node:child_process'
import { promisify } from 'node:util'

export interface MacTemperature {
cpuCelsius: number | null
updatedAt: number | null
error: 'unconfigured' | 'offline' | 'invalid' | 'unsupported' | null
}

const unknown = (error: MacTemperature['error']): MacTemperature => ({ cpuCelsius: null, updatedAt: null, error })
const exec = promisify(execFile)
type Runner = (file: string, args: string[]) => Promise<string>
const run: Runner = async (file, args) => (await exec(file, args, { timeout: 4000, maxBuffer: 64 * 1024, encoding: 'utf8' })).stdout

/** Accept only a recent bounded sensor reading, never an estimate from CPU load. */
export function parseMacTemperature(output: string, now: number): MacTemperature {
try {
const data = JSON.parse(output.trim())
const updatedAt = typeof data?.timestamp === 'string' ? Date.parse(data.timestamp) : NaN
const value = data?.temp?.cpu_temp_avg
if (!Number.isFinite(updatedAt) || now - updatedAt > 30_000 || updatedAt - now > 5_000) return unknown('invalid')
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value >= 150) return unknown('invalid')
return { cpuCelsius: Math.round(value * 10) / 10, updatedAt, error: null }
} catch { return unknown('invalid') }
}

/** Return the last reading immediately. A bounded macmon refresh runs in the background. */
export function createMacTemperatureReader(options: { run?: Runner; now?: () => number; platform?: string; arch?: string } = {}) {
const execute = options.run ?? run
const now = options.now ?? Date.now
const supported = (options.platform ?? process.platform) === 'darwin' && (options.arch ?? process.arch) === 'arm64'
let cached = unknown(null)
let checkedAt = -Infinity
let pending: Promise<void> | null = null
function failed(error: MacTemperature['error']): void {
// Keep the last valid sample until it expires, even when one refresh fails.
cached = cached.cpuCelsius !== null && cached.updatedAt !== null
? { ...cached, error } : unknown(error)
}
async function refresh(): Promise<void> {
for (const binary of ['/opt/homebrew/bin/macmon', '/usr/local/bin/macmon']) {
try {
const sample = parseMacTemperature(await execute(binary, ['pipe', '-s', '1', '-i', '500']), now())
if (sample.cpuCelsius !== null) cached = sample
else failed(sample.error)
checkedAt = now()
return
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
failed('offline')
checkedAt = now()
return
}
}
}
failed('unconfigured')
checkedAt = now()
}
return (): MacTemperature => {
if (!supported) return unknown('unsupported')
if (!pending && now() - checkedAt >= 10_000) {
pending = refresh().finally(() => { pending = null })
}
return cached.updatedAt !== null && now() - cached.updatedAt > 30_000
? { ...cached, cpuCelsius: null, error: cached.error ?? 'invalid' } : cached
}
}
56 changes: 41 additions & 15 deletions server/src/providers/system.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import si from 'systeminformation'
import { uptime } from 'node:os'
import type { Provider } from './types.js'
import { createMacTemperatureReader } from './mac-thermals.js'

const round = (n: number) => Math.round(n * 10) / 10

Expand Down Expand Up @@ -45,19 +46,44 @@ function uptimeSeconds(): number | null {
}
}

export const systemProvider: Provider = {
channel: 'system',
intervalMs: 2000,
async poll() {
const [load, mem, fs, net, temp] = await Promise.all([
si.currentLoad(), si.mem(), si.fsSize(), si.networkStats(), si.cpuTemperature(),
])
return {
uptimeSeconds: uptimeSeconds(),
cpu: { load: round(load.currentLoad), cores: load.cpus.map((c) => round(c.load)), temp: temp.main > 0 ? round(temp.main) : null },
memory: { total: mem.total, used: mem.active, free: mem.available, swapUsed: mem.swapused, swapTotal: mem.swaptotal },
disks: normalizeDisks(fs),
network: net.map((n) => ({ iface: n.iface, rx: Math.max(0, Math.round(n.rx_sec ?? 0)), tx: Math.max(0, Math.round(n.tx_sec ?? 0)) })),
}
},
export function createSystemProvider(options: {
macmonTemperatureEnabled?: () => boolean
readMacTemperature?: ReturnType<typeof createMacTemperatureReader>
} = {}): Provider {
const readMacTemperature = options.readMacTemperature ?? createMacTemperatureReader()
return {
channel: 'system',
intervalMs: 2000,
async poll() {
const [load, mem, fs, net, temp] = await Promise.all([
si.currentLoad(), si.mem(), si.fsSize(), si.networkStats(), si.cpuTemperature(),
])
const measured = options.macmonTemperatureEnabled?.() ? readMacTemperature() : null
const macmonTemp = measured?.cpuCelsius ?? null
const systemTemp = temp.main > 0 ? round(temp.main) : null
return {
uptimeSeconds: uptimeSeconds(),
cpu: {
load: round(load.currentLoad),
cores: load.cpus.map((c) => round(c.load)),
temp: macmonTemp ?? systemTemp,
tempSource: macmonTemp !== null ? 'macmon' : systemTemp !== null ? 'system' : null,
tempError: measured?.error ?? null,
},
memory: {
total: mem.total,
used: mem.active,
free: mem.available,
swapUsed: mem.swapused,
swapTotal: mem.swaptotal,
},
disks: normalizeDisks(fs),
network: net.map((n) => ({
iface: n.iface,
rx: Math.max(0, Math.round(n.rx_sec ?? 0)),
tx: Math.max(0, Math.round(n.tx_sec ?? 0)),
})),
}
},
}
}
13 changes: 12 additions & 1 deletion server/test/config-migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('ConfigStore migration', () => {
})
})

describe('privacy.claudeAccountUsage on an older config', () => {
describe('privacy settings on an older config', () => {
const page = (widgets: object[]) => ({ id: 'home', name: 'Accueil', widgets })
const widget = (widgetId: string) => ({ instanceId: 'a', widgetId, x: 0, y: 0, w: 8, h: 4 })

Expand Down Expand Up @@ -156,6 +156,17 @@ describe('privacy.claudeAccountUsage on an older config', () => {
it('leaves a fresh install off', () => {
expect(DEFAULT_CONFIG.privacy.claudeAccountUsage).toBe(false)
})
it('keeps macmon sampling off for existing configs and fresh installs', () => {
const page = { id: 'home', name: 'Home', widgets: [{ instanceId: 'cpu-1', widgetId: 'cpu', x: 0, y: 0, w: 8, h: 4 }] }
expect(migrateConfig({ version: 2, pages: [page] }).privacy.macmonTemperature).toBe(false)
expect(migrateConfig({ ...DEFAULT_CONFIG, privacy: { claudeAccountUsage: false } }).privacy.macmonTemperature).toBe(false)
expect(DEFAULT_CONFIG.privacy.macmonTemperature).toBe(false)
})

it('preserves explicit consent to macmon sampling', () => {
expect(migrateConfig({ ...DEFAULT_CONFIG, privacy: { claudeAccountUsage: false, macmonTemperature: true } })
.privacy.macmonTemperature).toBe(true)
})
})

describe('privacy.showAccountEmail on an older config', () => {
Expand Down
74 changes: 74 additions & 0 deletions server/test/mac-thermals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { describe, it, expect, vi } from 'vitest'
import { createMacTemperatureReader, parseMacTemperature } from '../src/providers/mac-thermals.js'

const now = 1800000000000
const reading = (value: unknown = 67.483, time = now) => JSON.stringify({ timestamp: new Date(time).toISOString(), temp: { cpu_temp_avg: value, gpu_temp_avg: 70.688 } })
const flush = () => new Promise<void>((resolve) => setTimeout(resolve, 0))

describe('measured Apple Silicon CPU temperature', () => {
it('accepts a recent bounded CPU sample without publishing GPU data', () => {
expect(parseMacTemperature(reading(), now)).toEqual({ cpuCelsius: 67.5, updatedAt: now, error: null })
})
it.each([0, -1, NaN, Infinity, 150, '67.5', null])('rejects invalid CPU sample %s', (value) => {
expect(parseMacTemperature(reading(value), now)).toMatchObject({ cpuCelsius: null, error: 'invalid' })
})
it.each(['not json', '{}', reading(67, now - 30001), reading(67, now + 5001)])('rejects malformed or stale samples', (output) => {
expect(parseMacTemperature(output, now)).toMatchObject({ cpuCelsius: null, error: 'invalid' })
})
it('returns cached data immediately while refreshing only once per ten seconds', async () => {
let clock = now
const run = vi.fn(async () => reading(67, clock))
const read = createMacTemperatureReader({ platform: 'darwin', arch: 'arm64', now: () => clock, run })
expect(read()).toMatchObject({ cpuCelsius: null, error: null })
expect(read().cpuCelsius).toBeNull()
await flush()
expect(read().cpuCelsius).toBe(67)
expect(run).toHaveBeenCalledTimes(1)
clock += 10000
expect(read().cpuCelsius).toBe(67)
await flush()
expect(run).toHaveBeenCalledTimes(2)
})
it('keeps a previous sample until it expires after a failed refresh', async () => {
let clock = now
const run = vi.fn().mockResolvedValueOnce(reading()).mockRejectedValueOnce(new Error('denied'))
const read = createMacTemperatureReader({ platform: 'darwin', arch: 'arm64', now: () => clock, run })
read(); await flush()
expect(read().cpuCelsius).toBe(67.5)
clock += 10000
read(); await flush()
expect(read()).toMatchObject({ cpuCelsius: 67.5, error: 'offline' })
clock += 20001
expect(read()).toMatchObject({ cpuCelsius: null, error: 'offline' })
})
it('keeps a recent sample when the next response is malformed', async () => {
let clock = now
const run = vi.fn().mockResolvedValueOnce(reading()).mockResolvedValueOnce('not json')
const read = createMacTemperatureReader({ platform: 'darwin', arch: 'arm64', now: () => clock, run })
read(); await flush()
clock += 10000
read(); await flush()
expect(read()).toMatchObject({ cpuCelsius: 67.5, error: 'invalid' })
})
it('does not expose an expired cached sample after a long pause', async () => {
let clock = now
const run = vi.fn(async () => reading(67, clock))
const read = createMacTemperatureReader({ platform: 'darwin', arch: 'arm64', now: () => clock, run })
read(); await flush()
expect(read().cpuCelsius).toBe(67)
clock += 3600000
expect(read().cpuCelsius).toBeNull()
await flush()
expect(read().cpuCelsius).toBe(67)
})
it('uses only fixed install paths and never runs on unsupported systems', async () => {
const run = vi.fn(async (_file: string, _args: string[]) => { throw Object.assign(new Error('missing'), { code: 'ENOENT' }) })
const read = createMacTemperatureReader({ platform: 'darwin', arch: 'arm64', run })
read(); await flush()
expect(read().error).toBe('unconfigured')
expect(run.mock.calls.map((args) => args[0])).toEqual(['/opt/homebrew/bin/macmon', '/usr/local/bin/macmon'])
const other = createMacTemperatureReader({ platform: 'linux', arch: 'arm64', run })
expect(other().error).toBe('unsupported')
expect(run).toHaveBeenCalledTimes(2)
})
})
35 changes: 35 additions & 0 deletions server/test/system-thermals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect, it, vi } from 'vitest'
import si from 'systeminformation'

vi.mock('systeminformation', () => ({
default: {
currentLoad: async () => ({ currentLoad: 12, cpus: [{ load: 12 }] }),
mem: async () => ({ total: 100, active: 40, available: 60 }),
fsSize: async () => [],
networkStats: async () => [],
cpuTemperature: vi.fn(async () => ({ main: 0 })),
},
}))

import { createSystemProvider } from '../src/providers/system.js'

it('never runs the optional sensor before consent and keeps polling without waiting for it', async () => {
let enabled = false
const readMacTemperature = vi.fn(() => ({ cpuCelsius: 55, updatedAt: 1800000000000, error: null as null }))
const provider = createSystemProvider({ macmonTemperatureEnabled: () => enabled, readMacTemperature })
expect((await provider.poll!() as { cpu: { temp: number | null; tempSource: string | null; tempError: string | null } }).cpu)
.toMatchObject({ temp: null, tempSource: null, tempError: null })
expect(readMacTemperature).not.toHaveBeenCalled()
enabled = true
expect((await provider.poll!() as { cpu: { temp: number | null; tempSource: string | null; tempError: string | null } }).cpu)
.toMatchObject({ temp: 55, tempSource: 'macmon', tempError: null })
expect(readMacTemperature).toHaveBeenCalledTimes(1)
})

it('reports a missing macmon tool while preserving the system fallback', async () => {
const readMacTemperature = vi.fn(() => ({ cpuCelsius: null, updatedAt: null, error: 'unconfigured' as const }))
vi.mocked(si.cpuTemperature).mockResolvedValueOnce({ main: 42 } as Awaited<ReturnType<typeof si.cpuTemperature>>)
const provider = createSystemProvider({ macmonTemperatureEnabled: () => true, readMacTemperature })
expect((await provider.poll!() as { cpu: { temp: number | null; tempSource: string | null; tempError: string | null } }).cpu)
.toMatchObject({ temp: 42, tempSource: 'system', tempError: 'unconfigured' })
})
3 changes: 2 additions & 1 deletion server/test/system-uptime.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { uptime } from 'node:os'
import { systemProvider } from '../src/providers/system.js'
import { createSystemProvider } from '../src/providers/system.js'

vi.mock('node:os', () => ({ uptime: vi.fn() }))
vi.mock('systeminformation', () => ({ default: {
Expand All @@ -12,6 +12,7 @@ vi.mock('systeminformation', () => ({ default: {
} }))

describe('OS uptime in the system snapshot', () => {
const systemProvider = createSystemProvider()
beforeEach(() => vi.mocked(uptime).mockReset())

it.each([0, 90061.9])('publishes system uptime %s seconds rather than process uptime', async (seconds) => {
Expand Down
7 changes: 7 additions & 0 deletions ui/src/admin/ScreenInspector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ function setCodexSource(source: CodexSource, on: boolean): void {
? [...new Set([...c.privacy.codexHistorySources, source])]
: c.privacy.codexHistorySources.filter(value => value !== source) })
}
function setMacmonTemperature(on: boolean): void {
s.apply((c) => { c.privacy.macmonTemperature = on })
}
/**
* Off, the server leaves the account e-mail out of every snapshot it publishes; this box does
* not hide it in a widget, it decides whether any widget is sent it at all.
Expand Down Expand Up @@ -306,6 +309,10 @@ function setBackground(patch: Partial<Background>): void {
@update:model-value="setCodexSource(source, $event)" />
</div>
</details>
<BaseCheckbox :model-value="privacy.macmonTemperature"
:label="t('admin.inspector.screen.macmonTemperature')"
@update:model-value="setMacmonTemperature($event)" />
<p class="ro">{{ t('admin.inspector.screen.macmonTemperature.hint') }}</p>
</BaseSection>
</template>

Expand Down
Loading
Loading