Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.
TypeScript
feat(desktop): diagnose local engine CLIs with version and a copyable update command (#84)
Kelvina99c79770a3c
diff --git a/electron/main.cjs b/electron/main.cjsindex db91307..5f32809 100644--- a/electron/main.cjs+++ b/electron/main.cjs@@ -5,6 +5,7 @@ const fs = require('node:fs')const os = require('node:os')const { spawn } = require('node:child_process')const http = require('node:http')+const https = require('node:https')const crypto = require('node:crypto')const { pathToFileURL } = require('node:url')const autoUpdater = require('./autoUpdater.cjs')@@ -1393,20 +1394,85 @@ ipcMain.handle('app:is-focused', () => {// Keep in sync with src/lib/engines.ts. Official daemon detectEngines() only// probes engines with adapters (claude/cursor/codex/grok/opencode/pi). The rest-// are listed so the Me page can show what is installed on THIS machine; they-// cannot be assigned to people.+// are listed so the Me page can diagnose what is installed on THIS machine.const LOCAL_CLIS = [- { id: 'claude', bin: 'claude' },- { id: 'cursor', bin: 'cursor-agent' },- { id: 'codex', bin: 'codex' },- { id: 'grok', bin: 'grok' },- { id: 'opencode', bin: 'opencode' },- { id: 'pi', bin: 'pi' },- { id: 'gemini', bin: 'gemini' },- { id: 'qwen', bin: 'qwen' },- { id: 'hermes', bin: 'hermes' },+ {+ id: 'claude', bin: 'claude', versionArgs: ['--version'],+ npm: '@anthropic-ai/claude-code', brew: 'claude-code',+ selfUpdate: 'claude update',+ },+ {+ id: 'cursor', bin: 'cursor-agent', versionArgs: ['--version'], latestVia: 'cursor-about',+ selfUpdate: 'cursor-agent update',+ },+ {+ id: 'codex', bin: 'codex', versionArgs: ['--version'],+ npm: '@openai/codex',+ },+ {+ id: 'grok', bin: 'grok', versionArgs: ['--version'], latestVia: 'grok-check',+ npm: '@xai-official/grok',+ selfUpdate: 'grok update',+ },+ {+ id: 'opencode', bin: 'opencode', versionArgs: ['--version'],+ npm: 'opencode-ai',+ selfUpdate: 'opencode upgrade',+ },+ {+ id: 'pi', bin: 'pi', versionArgs: ['--version'],+ npm: '@earendil-works/pi-coding-agent', npmFlags: '--ignore-scripts',+ selfUpdate: 'pi update',+ },+ {+ id: 'gemini', bin: 'gemini', versionArgs: ['--version'],+ npm: '@google/gemini-cli', brew: 'gemini-cli',+ },+ {+ id: 'qwen', bin: 'qwen', versionArgs: ['--version'],+ npm: '@qwen-code/qwen-code',+ },+ {+ id: 'hermes', bin: 'hermes', versionArgs: ['version'],+ selfUpdate: 'hermes update',+ },]+const NPM_LATEST_TTL_MS = 30 * 60 * 1000+const npmLatestCache = new Map()++function realpathOf(binPath) {+ try {+ return fs.realpathSync(binPath)+ } catch {+ return binPath+ }+}++function isHomebrewInstall(binPath, real) {+ const hay = `${binPath}\n${real}`+ return /(^|[/\\])(Homebrew|homebrew|linuxbrew|Cellar)([/\\]|$)/i.test(hay)+ || binPath.startsWith('/opt/homebrew/')+}++function npmUpdateCommand(spec) {+ if (!spec.npm) return null+ const flags = spec.npmFlags ? `${spec.npmFlags} ` : ''+ return `npm install -g ${flags}${spec.npm}@latest`+}++// Prefer the CLI's own updater when it has one (`pi update`, `claude update`).+// That path is what vendors document, and it works the same on Windows.+// Only fall back to brew/npm when the binary has no self-update command.+function inferUpdateCommand(spec, binPath) {+ if (spec.selfUpdate) return spec.selfUpdate+ const real = realpathOf(binPath)+ if (spec.brew && isHomebrewInstall(binPath, real)) {+ return `brew upgrade ${spec.brew}`+ }+ return npmUpdateCommand(spec)+}+function detectSearchPath() {const home = os.homedir()const extra = [@@ -1425,19 +1491,116 @@ function detectSearchPath() {return parts.join(path.delimiter)}-function spawnText(cmd, args, envPath) {+function spawnText(cmd, args, envPath, timeoutMs = 8000) {return new Promise((resolve) => {+ let settled = falseconst child = spawn(cmd, args, {- stdio: ['ignore', 'pipe', 'ignore'],+ stdio: ['ignore', 'pipe', 'pipe'],env: { ...process.env, PATH: envPath ?? process.env.PATH },})let out = ''- child.stdout?.on('data', (buf) => { out += buf.toString('utf8') })- child.on('error', () => resolve(''))- child.on('close', () => resolve(out.trim()))+ const onChunk = (buf) => { out += buf.toString('utf8') }+ child.stdout?.on('data', onChunk)+ child.stderr?.on('data', onChunk)+ const finish = (value) => {+ if (settled) return+ settled = true+ clearTimeout(timer)+ resolve(value)+ }+ const timer = setTimeout(() => { try { child.kill() } catch { /* ignore */ }; finish(out.trim()) }, timeoutMs)+ child.on('error', () => finish(''))+ child.on('close', () => finish(out.trim()))})}+function parseCliVersion(text) {+ if (!text) return null+ const m = text.match(/v?(\d{4}\.\d{2}\.\d{2}(?:-[\w.]+)?|\d+\.\d+\.\d+(?:[-+][\w.]+)?)/i)+ return m ? m[1] : null+}++function versionParts(v) {+ const main = String(v).replace(/^v/i, '').split(/[-+]/)[0]+ return main.split('.').map((n) => Number.parseInt(n, 10) || 0)+}++function isCliOutdated(current, latest) {+ if (!current || !latest) return false+ if (current === latest) return false+ const a = versionParts(current)+ const b = versionParts(latest)+ const n = Math.max(a.length, b.length)+ for (let i = 0; i < n; i++) {+ const x = a[i] ?? 0+ const y = b[i] ?? 0+ if (y > x) return true+ if (y < x) return false+ }+ return false+}++function fetchJson(url, timeoutMs = 5000) {+ return new Promise((resolve) => {+ const req = https.get(url, {+ headers: { 'User-Agent': 'cumora-desktop', Accept: 'application/json' },+ }, (res) => {+ if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {+ res.resume()+ fetchJson(res.headers.location, timeoutMs).then(resolve)+ return+ }+ let body = ''+ res.on('data', (chunk) => { body += chunk })+ res.on('end', () => {+ try { resolve(JSON.parse(body)) } catch { resolve(null) }+ })+ })+ req.on('error', () => resolve(null))+ req.setTimeout(timeoutMs, () => { req.destroy(); resolve(null) })+ })+}++async function npmLatest(pkg) {+ const cached = npmLatestCache.get(pkg)+ if (cached && Date.now() - cached.at < NPM_LATEST_TTL_MS) return cached.version+ const data = await fetchJson(`https://registry.npmjs.org/${encodeURIComponent(pkg)}/latest`)+ const version = typeof data?.version === 'string' ? data.version : null+ if (version) npmLatestCache.set(pkg, { at: Date.now(), version })+ return version+}++function parseCursorAbout(text) {+ const latestLine = text.split(/\r?\n/).find((line) => /^\s*Latest\b/i.test(line))+ if (!latestLine) return null+ return parseCliVersion(latestLine)+}++function parseGrokCheck(text) {+ try {+ const data = JSON.parse(text)+ return typeof data.latestVersion === 'string' ? data.latestVersion : null+ } catch {+ return parseCliVersion(text)+ }+}++async function detectCliLatest(spec, resolved, envPath) {+ try {+ if (spec.latestVia === 'cursor-about') {+ const about = await spawnText(resolved, ['about'], envPath, 10000)+ return parseCursorAbout(about) || parseCliVersion(about)+ }+ if (spec.latestVia === 'grok-check') {+ const check = await spawnText(resolved, ['update', '--check', '--json'], envPath, 12000)+ const fromCheck = parseGrokCheck(check)+ if (fromCheck) return fromCheck+ }+ if (spec.npm) return await npmLatest(spec.npm)+ } catch { /* keep local-only */ }+ return null+}+async function resolveCliPath(bin, envPath) {const whichCmd = process.platform === 'win32' ? 'where' : 'which'const fromWhich = (await spawnText(whichCmd, [bin], envPath)).split(/\r?\n/)[0]?.trim()@@ -1480,11 +1643,26 @@ async function detectLocalHostNames() {ipcMain.handle('detect:local-clis', async () => {const envPath = detectSearchPath()const hostNames = await detectLocalHostNames()- const clis = []- for (const { id, bin } of LOCAL_CLIS) {- const resolved = await resolveCliPath(bin, envPath)- if (resolved) clis.push({ id, bin, path: resolved })+ const found = []+ for (const spec of LOCAL_CLIS) {+ const resolved = await resolveCliPath(spec.bin, envPath)+ if (resolved) found.push({ spec, path: resolved })}+ const clis = await Promise.all(found.map(async ({ spec, path: resolved }) => {+ const rawVersion = await spawnText(resolved, spec.versionArgs, envPath, 6000)+ const version = parseCliVersion(rawVersion)+ const latest = await detectCliLatest(spec, resolved, envPath)+ const outdated = isCliOutdated(version, latest)+ return {+ id: spec.id,+ bin: spec.bin,+ path: resolved,+ version,+ latest,+ outdated,+ updateCommand: outdated ? inferUpdateCommand(spec, resolved) : null,+ }+ }))return { hostNames, clis }})diff --git a/src/desktop/MeView.tsx b/src/desktop/MeView.tsxindex 9f1f650..dd9964b 100644--- a/src/desktop/MeView.tsx+++ b/src/desktop/MeView.tsx@@ -771,7 +771,15 @@ function SkypeSoundSection() {const KIND_ICON: Record<string, string> = { cloud: '☁', local: '💻', vps: '🖥' }const STATUS_COLOR: Record<string, string> = { online: '#3BB273', busy: '#E6A23C', offline: 'var(--ink-300)' }-type AgentRow = { id: string; bin: string; path: string | null }+type AgentRow = {+ id: string+ bin: string+ path: string | null+ version?: string | null+ latest?: string | null+ outdated?: boolean+ updateCommand?: string | null+}const CLI_ORDER = ['claude', 'cursor', 'codex', 'grok', 'opencode',@@ -805,7 +813,15 @@ function isThisMachine(computer: Computer, hostNames: string[], localComputerCoufunction mergeAgentRows(computer: Computer,- localClis: Array<{ id: string; bin: string; path: string }> | null,+ localClis: Array<{+ id: string+ bin: string+ path: string+ version?: string | null+ latest?: string | null+ outdated?: boolean+ updateCommand?: string | null+ }> | null,thisMachine: boolean,): AgentRow[] {const byId = new Map<string, AgentRow>()@@ -845,17 +861,34 @@ function ComputersTab() {const [repairCode, setRepairCode] = useState<string | null>(null)const [repairCopied, setRepairCopied] = useState(false)const [busyId, setBusyId] = useState<string | null>(null)+ const [copiedCli, setCopiedCli] = useState<string | null>(null)const [localDetect, setLocalDetect] = useState<{hostNames: string[]- clis: Array<{ id: string; bin: string; path: string }>+ clis: Array<{+ id: string+ bin: string+ path: string+ version?: string | null+ latest?: string | null+ outdated?: boolean+ updateCommand?: string | null+ }>} | null>(null)+ const canDetectLocal = typeof window !== 'undefined' && typeof window.cumora?.detect?.localClis === 'function'+ const [cliScanning, setCliScanning] = useState(canDetectLocal)async function scanLocal() {const fn = typeof window !== 'undefined' ? window.cumora?.detect?.localClis : undefined- if (!fn) return+ if (!fn) {+ setCliScanning(false)+ return+ }+ setCliScanning(true)try {setLocalDetect(await fn())- } catch { /* keep previous */ }+ } catch { /* keep previous */ } finally {+ setCliScanning(false)+ }}useEffect(() => {@@ -863,6 +896,7 @@ function ComputersTab() {void scanLocal()}, [])useEffect(() => { if (!repairCopied) return; const id = window.setTimeout(() => setRepairCopied(false), 1600); return () => window.clearTimeout(id) }, [repairCopied])+ useEffect(() => { if (!copiedCli) return; const id = window.setTimeout(() => setCopiedCli(null), 1600); return () => window.clearTimeout(id) }, [copiedCli])async function toggleRepair(id: string) {if (repairFor === id) { setRepairFor(null); setRepairCode(null); return }@@ -947,10 +981,11 @@ function ComputersTab() {const expanded = repairFor === c.idconst repairCmd = repairCode ? `npx cumora@latest agent computer --pair ${repairCode}${serverFlag}` : ''const thisMachine = isThisMachine(c, localDetect?.hostNames ?? [], localComputerCount)- const rows = repairable+ const awaitingCli = repairable && c.kind === 'local' && cliScanning+ const rows = repairable && !awaitingCli? mergeAgentRows(c, thisMachine ? (localDetect?.clis ?? null) : null, thisMachine): []- const detecting = busyId === c.id+ const detecting = busyId === c.id || awaitingClireturn (<div key={c.id} className="bg-cloud rounded-[14px]" style={{ border: '1px solid var(--ink-100)' }}><div@@ -972,14 +1007,22 @@ function ComputersTab() {</span>)}</div>- <div className="text-[12px] text-ink-500 mt-0.5">+ <div className="flex items-center text-[12px] text-ink-500 mt-0.5">{repairable? (<>- {n === 1 ? t('me.agentsCountOne', { n }) : t('me.agentsCountOther', { n })}- {rows.length > 0 && <>{' · '}{t('me.agentsDetected', { n: rows.length })}</>}+ <span>+ {awaitingCli+ ? t('me.agentsDiagnosing')+ : rows.length > 0+ ? (rows.length === 1 ? t('me.agentsCliDetectedOne', { n: rows.length }) : t('me.agentsCliDetectedOther', { n: rows.length }))+ : (n === 1 ? t('me.agentsCountOne', { n }) : t('me.agentsCountOther', { n }))}+ </span>{c.daemonVersion && (- <>{' · '}<span className="font-mono text-[11px] text-ink-400">{t('me.daemonVersion', { version: c.daemonVersion })}</span></>+ <>+ <span className="shrink-0 text-ink-300" style={{ marginLeft: 10, marginRight: 10 }}>·</span>+ <span>{t('me.daemonVersionLocal', { version: c.daemonVersion })}</span>+ </>)}</>)@@ -1006,27 +1049,88 @@ function ComputersTab() {)}</div>{repairable && (- rows.length === 0 ? (+ awaitingCli ? (+ <div className="px-4 pb-4 space-y-2" aria-busy="true">+ <div className="text-[12px] text-ink-500">{t('me.agentsDiagnosing')}</div>+ {[0, 1, 2].map((i) => (+ <div+ key={i}+ className="rounded-[12px] px-3 py-2.5 bg-paper"+ style={{ border: '1px solid var(--ink-200)' }}+ >+ <div className="h-3.5 w-24 rounded-md bg-ink-200" />+ <div className="mt-2 h-2.5 w-[70%] rounded-md bg-ink-200/80" />+ </div>+ ))}+ </div>+ ) : rows.length === 0 ? (<div className="px-4 pb-4 text-[12px] text-ink-400">{t('me.agentsNoEngines')}</div>) : (<div className="px-4 pb-4 space-y-2">{rows.map((row) => {const engineId = asRunnableEngine(row.id)- const advertised = engineId != null && c.availableEngines.includes(engineId)- const isDefault = advertised && row.id === c.availableEngines[0]+ const copyKey = `${c.id}:${row.id}`return (- <div key={row.id} className="flex items-center gap-3 rounded-[12px] px-3 py-2.5"+ <div key={row.id} className="rounded-[12px] px-3 py-2.5"style={{ border: '1px solid var(--ink-100)' }}>- <div className="flex-1 min-w-0">- <div className="text-[13px] font-semibold text-ink-900">{engineLabel(row.id)}</div>- <div className="font-mono text-[11px] text-ink-400 truncate">- {row.bin}{row.path ? ` · ${row.path}` : ''}+ <div className="flex items-start gap-3">+ <div className="flex-1 min-w-0">+ <div className="flex items-center gap-2 min-w-0">+ <div className="text-[13px] font-semibold text-ink-900 shrink-0">{engineLabel(row.id)}</div>+ {row.outdated && (+ <span+ className="text-[12px] font-semibold px-2 py-0.5 rounded-full shrink-0 bg-gold/20 text-gold-deep"+ >+ {t('me.agentsCliUpdateAvailable')}+ </span>+ )}+ {!engineId && (+ <span className="text-[12px] text-ink-400 truncate">{t('me.agentsNotRunnable')}</span>+ )}+ </div>+ <div className="mt-1 flex items-center min-w-0 font-mono text-[12px] text-ink-400">+ <span className="shrink-0">{row.bin}</span>+ {row.path && (+ <>+ <span className="shrink-0 text-ink-300" style={{ marginLeft: 10, marginRight: 10 }}>·</span>+ <span className="truncate">{row.path}</span>+ </>+ )}+ </div>+ {(row.version || row.latest) && (+ <div className="mt-1 flex items-center text-[12px] text-ink-500">+ <span>{row.version ? t('me.agentsCliLocal', { version: row.version }) : t('me.agentsCliUnknown')}</span>+ {row.latest && (+ <>+ <span className="shrink-0 text-ink-300" style={{ marginLeft: 10, marginRight: 10 }}>·</span>+ <span>{t('me.agentsCliLatest', { latest: row.latest })}</span>+ </>+ )}+ {!row.outdated && row.latest && row.version === row.latest && (+ <>+ <span className="shrink-0 text-ink-300" style={{ marginLeft: 10, marginRight: 10 }}>·</span>+ <span>{t('me.agentsCliCurrent')}</span>+ </>+ )}+ </div>+ )}</div></div>- {isDefault ? (- <span className="text-[12px] font-semibold text-skype-deep">✓ {t('me.agentsIsDefault')}</span>- ) : engineId ? null : (- <span className="text-[11px] text-ink-400 shrink-0">{t('me.agentsNotRunnable')}</span>+ {row.updateCommand && (+ <div className="mt-2 flex items-center gap-2">+ <pre className="flex-1 min-w-0 font-mono text-[11px] truncate bg-ink-900 text-cloud rounded-[8px] px-2 py-1.5 select-all">{row.updateCommand}</pre>+ <button+ type="button"+ onClick={(e) => {+ e.stopPropagation()+ void navigator.clipboard?.writeText(row.updateCommand!)+ setCopiedCli(copyKey)+ }}+ className="text-[12px] font-semibold text-skype-deep hover:underline shrink-0"+ >+ {copiedCli === copyKey ? t('me.copied') : t('me.agentsCopyUpdate')}+ </button>+ </div>)}</div>)diff --git a/src/lib/runtime.ts b/src/lib/runtime.tsindex 3a62364..637995a 100644--- a/src/lib/runtime.ts+++ b/src/lib/runtime.ts@@ -89,7 +89,15 @@ interface CumoraBridge {detect?: {localClis: () => Promise<{hostNames: string[]- clis: Array<{ id: string; bin: string; path: string }>+ clis: Array<{+ id: string+ bin: string+ path: string+ version?: string | null+ latest?: string | null+ outdated?: boolean+ updateCommand?: string | null+ }>}>}/** Auto-update bridge — ported from alma's pattern. Surfacesdiff --git a/src/locales/en.ts b/src/locales/en.tsindex 39f5e0b..fa47fe7 100644--- a/src/locales/en.ts+++ b/src/locales/en.ts@@ -1232,6 +1232,7 @@ export const en = {'me.updateAvailableShort': 'update','me.updateToVersion': 'Update to v{version}','me.daemonVersion': 'v{version}',+ 'me.daemonVersionLocal': 'local v{version}','me.hideAction': 'Hide','me.reconnect': 'Reconnect','me.remove': 'Remove',@@ -1262,13 +1263,22 @@ export const en = {'me.computersGenerating': 'Generating…','me.engineDefaultHint': 'just the default — this computer can still run agents on any detected engine','me.agentsDetected': '{n} detected',+ 'me.agentsCliDetectedOne': '{n} engine detected',+ 'me.agentsCliDetectedOther': '{n} engines detected','me.agentsRefresh': 'Refresh','me.agentsRefreshing': 'Refreshing…',+ 'me.agentsDiagnosing': 'Checking local engines…','me.agentsIsDefault': 'Default','me.agentsOffline': 'This computer is offline. The list is still the last pairing report.','me.agentsNoEngines': 'The daemon reported no engines at pairing. Re-run the pairing command on that computer to scan PATH again.','me.agentsNotRunnable': 'Detected only — Cumora cannot run this yet','me.agentsNeedPair': 'Re-pair to use',+ 'me.agentsCliUnknown': 'version unknown',+ 'me.agentsCliLocal': 'local {version}',+ 'me.agentsCliLatest': 'latest {latest}',+ 'me.agentsCliCurrent': 'up to date',+ 'me.agentsCliUpdateAvailable': 'update available',+ 'me.agentsCopyUpdate': 'Copy command','me.computerStatus.online': 'online','me.computerStatus.busy': 'busy','me.computerStatus.offline': 'offline',diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.tsindex 6b56342..58f7017 100644--- a/src/locales/zh-CN.ts+++ b/src/locales/zh-CN.ts@@ -1234,6 +1234,7 @@ export const zhCN: Partial<Record<keyof typeof en, string>> = {'me.updateAvailableShort': '更新','me.updateToVersion': '升级到 v{version}','me.daemonVersion': 'v{version}',+ 'me.daemonVersionLocal': '本地 v{version}','me.hideAction': '收起','me.reconnect': '重新连接','me.remove': '移除',@@ -1264,13 +1265,22 @@ export const zhCN: Partial<Record<keyof typeof en, string>> = {'me.computersGenerating': '生成中…','me.engineDefaultHint': '只是默认值 —— 这台计算机仍可在任意被检测到的引擎上跑智能体','me.agentsDetected': '{n} 已检测',+ 'me.agentsCliDetectedOne': '{n} 个引擎已被检测',+ 'me.agentsCliDetectedOther': '{n} 个引擎已被检测','me.agentsRefresh': '刷新','me.agentsRefreshing': '刷新中…',+ 'me.agentsDiagnosing': '正在检测本机引擎…','me.agentsIsDefault': '默认','me.agentsOffline': '这台计算机离线。列表仍是上次配对时的检测结果。','me.agentsNoEngines': '配对时 daemon 没有报任何引擎。要重新扫 PATH,请在那台机器上再跑一次配对命令。','me.agentsNotRunnable': '仅识别,Cumora 还不能当引擎跑','me.agentsNeedPair': '重新配对后使用',+ 'me.agentsCliUnknown': '版本未知',+ 'me.agentsCliLocal': '本地 {version}',+ 'me.agentsCliLatest': '官方 {latest}',+ 'me.agentsCliCurrent': '已是最新',+ 'me.agentsCliUpdateAvailable': '有更新',+ 'me.agentsCopyUpdate': '复制命令','me.computerStatus.online': '在线','me.computerStatus.busy': '忙碌','me.computerStatus.offline': '离线',