The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix: serialize pane theme updates across discovery scans
dee6300bddfe8e2
diff --git a/cli/src/lib/tmuxBackend.spec.ts b/cli/src/lib/tmuxBackend.spec.tsindex 50684e3dc..3d10ec79f 100644--- a/cli/src/lib/tmuxBackend.spec.ts+++ b/cli/src/lib/tmuxBackend.spec.ts@@ -1,7 +1,7 @@import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'import { delimiter, join } from 'node:path'-import { afterEach, describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import { TmuxBackend, clearEnvArgs } from './tmuxBackend.js'const originalPath = process.env.PATH@@ -58,6 +58,7 @@ esacwriteFileSync(tmux, `#!/bin/shprintf '%s\\n' "$*" >> "$TMUX_BACKEND_CALLS"case "$1" in+ set-option) sleep 0.05 ;;new-session) printf '%%7\\n' ;;list-panes) printf '%%7|100|harness-codex-1|/tmp/work\\n%%9|101|harness-claude-2|/tmp/other\\n' ;;esac@@ -74,17 +75,18 @@ esacawait backend.inventory()theme = { background: '#300a24', foreground: '#ffffff' }await backend.inventory()- await new Promise((resolve) => setTimeout(resolve, 50))-- const styleCalls = readFileSync(calls, 'utf8').trim().split('\n').filter((line) => line.includes('window-style'))- expect(styleCalls).toEqual([+ const styleCalls = () => readFileSync(calls, 'utf8').trim().split('\n').filter((line) => line.includes('window-style'))+ await vi.waitFor(() => expect(styleCalls()).toEqual(['new-session -d -P -F #{pane_id} -c /tmp/work -s harness-codex-1 ; set-option -w remain-on-exit on ; set-option -w window-style bg=#171b29,fg=#f5f5f5',// The pane this daemon did not create is styled on the first scan; %7 already was.'set-option -w -t %9 window-style bg=#171b29,fg=#f5f5f5',// The app changed its palette: every live pane, once.'set-option -w -t %7 window-style bg=#300a24,fg=#ffffff','set-option -w -t %9 window-style bg=#300a24,fg=#ffffff',- ])+ ]))+ await backend.inventory()+ await new Promise((resolve) => setTimeout(resolve, 80))+ expect(styleCalls()).toHaveLength(4)})it('carries tmux\'s own refusal into the failure reason', async () => {diff --git a/cli/src/lib/tmuxBackend.ts b/cli/src/lib/tmuxBackend.tsindex d99c74b75..065465ec2 100644--- a/cli/src/lib/tmuxBackend.ts+++ b/cli/src/lib/tmuxBackend.ts@@ -93,6 +93,8 @@ export class TmuxBackend implements TerminalBackend<TmuxRuntimeRef> {/** What each Harness pane's `window-style` was last set to, so a scan re-applies only changes. */private readonly styledPanes = new Map<string, string>()+ private readonly desiredStyles = new Map<string, string>()+ private readonly stylingPanes = new Set<string>()/*** [hostTheme] answers with the desktop's current pane colours (see `hostTheme.ts`); read at every@@ -263,17 +265,30 @@ export class TmuxBackend implements TerminalBackend<TmuxRuntimeRef> {private restyle(panes: readonly string[]): void {const style = windowStyleOf(this.hostTheme())const live = new Set(panes)- for (const pane of panes) {- if (this.styledPanes.get(pane) === style) continue- // Recorded only once tmux has taken it: a pane recorded on the attempt would never be- // retried after a timeout, until the theme happened to change again.- void setPaneWindowStyle(pane, style).then((applied) => {- if (applied && live.has(pane)) this.styledPanes.set(pane, style)- })+ for (const pane of this.desiredStyles.keys()) {+ if (!live.has(pane)) this.desiredStyles.delete(pane)}- for (const pane of [...this.styledPanes.keys()]) {+ for (const pane of this.styledPanes.keys()) {if (!live.has(pane)) this.styledPanes.delete(pane)}+ for (const pane of panes) {+ this.desiredStyles.set(pane, style)+ this.applyStyle(pane)+ }+ }++ private applyStyle(pane: string): void {+ const style = this.desiredStyles.get(pane)+ if (style === undefined || this.stylingPanes.has(pane) || this.styledPanes.get(pane) === style) return+ // Serialize writes per pane: scans can overlap a slow tmux command or a theme change.+ this.stylingPanes.add(pane)+ void setPaneWindowStyle(pane, style).then((applied) => {+ if (applied && this.desiredStyles.has(pane)) this.styledPanes.set(pane, style)+ }).finally(() => {+ this.stylingPanes.delete(pane)+ // Apply a newer theme immediately, but retry a failed unchanged write on the next scan.+ if (this.desiredStyles.get(pane) !== style) this.applyStyle(pane)+ })}async validate(runtime: TmuxRuntimeRef, expected: TerminalProcessExpectation): Promise<RuntimeValidation> {