Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(agents): read the brand-logo map through Object.hasOwn, and correct two stale comments

enesa6b8c1e06b3b
diff --git a/src/core/session-name-sweep.ts b/src/core/session-name-sweep.ts
index e6bdd18e4..703daad64 100644
--- a/src/core/session-name-sweep.ts
+++ b/src/core/session-name-sweep.ts
@@ -53,13 +53,15 @@ export interface SessionNameSweepDeps {
* Which agents carry a READABLE session name. **Optional, and you almost certainly want the
* default** (`supportsTitleRead` below) — it is the rule, not a shell's opinion of it.
*
- * It lives here because the two shells were passing the same predicate and a wrong one is
- * INVISIBLE: swap it for `canRename` and every gemini node is skipped, so the agent-status
- * mirror (and the phone reading it) never sees a gemini session name — with a green test suite,
- * since nothing exercises a shell's wiring. That is the same duplicated-gate drift this branch
- * has already paid for three times (the remote installer's event lists, the grok raw-listener
- * block, this). Still injectable: the unit tests narrow it, and a caller with a genuinely
- * different set can pass its own.
+ * It lives here because the two shells were passing the same predicate and a wrong one is nearly
+ * invisible: swap it for `canRename` and every gemini node is skipped, so the agent-status mirror
+ * (and the phone reading it) never sees a gemini session name. Making it a DEFAULT here is what
+ * buys the guard — this file's own tests pin `supportsTitleRead` (reverting the default to
+ * `canRename` fails them), whereas the same mistake made independently in each shell's call site
+ * would have been caught by nothing, since no test exercises a shell's wiring. That is the same
+ * duplicated-gate drift this branch has already paid for three times (the remote installer's event
+ * lists, the grok raw-listener block, this). Still injectable: the unit tests narrow it, and a
+ * caller with a genuinely different set can pass its own.
*/
supports?: (agentId?: string) => boolean
}
diff --git a/src/renderer/lib/agentIcons.tsx b/src/renderer/lib/agentIcons.tsx
index d26b4f589..8ac1ec302 100644
--- a/src/renderer/lib/agentIcons.tsx
+++ b/src/renderer/lib/agentIcons.tsx
@@ -1,6 +1,6 @@
import type { AgentId } from '@shared/agents/config'
import { IconTerminal } from '../components/icons'
-import { AGENT_LOGO, BRAND_PULSE_CLASS, brandPulsePlan } from './brandPulse'
+import { BRAND_PULSE_CLASS, brandLogoSrc, brandPulsePlan } from './brandPulse'
import { GROK_MARK_PATH, GROK_MARK_VIEWBOX } from './grokMark'
// The logo map itself lives in the REACT-FREE lib/brandPulse.ts, because the notch HUD needs the
@@ -60,7 +60,9 @@ export function BrandPulse({ agentId, size }: { agentId?: AgentId; size: number
export function AgentIcon({ agentId, size = 16 }: { agentId: AgentId; size?: number }): React.JSX.Element {
if (agentId === 'grok') return <GrokMark size={size} />
- const src = AGENT_LOGO[agentId]
+ // `brandLogoSrc`, not `AGENT_LOGO[agentId]`: the id can be anything a hand-edited project.json
+ // says, and a prototype key ('constructor') would hand back a Function as the image source.
+ const src = brandLogoSrc(agentId)
if (src) {
return <img src={src} width={size} height={size} alt="" style={{ display: 'block' }} />
}
diff --git a/src/renderer/lib/brandPulse.test.tsx b/src/renderer/lib/brandPulse.test.tsx
index 4fe92115a..e07116666 100644
--- a/src/renderer/lib/brandPulse.test.tsx
+++ b/src/renderer/lib/brandPulse.test.tsx
@@ -7,6 +7,7 @@ import { describe, expect, it } from 'vitest'
import {
BRAND_PULSE_CLASS,
HUD_BRAND_PULSE_CLASS,
+ brandLogoSrc,
brandPulseBackground,
brandPulsePlan,
hasBrandLogo
@@ -89,6 +90,18 @@ describe('hasBrandLogo', () => {
}
expect(hasBrandLogo('custom:abc')).toBe(false)
})
+
+ it('does not answer for a prototype key, and never plans a Function as the image', () => {
+ // `data.agentId` is persisted in `.nodeterm/project.json` and hand-editable, and `AgentId` is
+ // open — so this is a reachable value, not a theoretical one. Under `agentId in AGENT_LOGO` the
+ // predicate said true and `AGENT_LOGO[agentId]` handed back Object.prototype's member, which
+ // then reached an `<img src>` / a CSS `url()` as a stringified function body.
+ for (const forged of ['constructor', '__proto__', 'toString', 'hasOwnProperty', 'valueOf']) {
+ expect(hasBrandLogo(forged), forged).toBe(false)
+ expect(brandPulsePlan(forged, 16), forged).toBeNull()
+ expect(brandLogoSrc(forged), forged).toBeUndefined()
+ }
+ })
})
describe('BrandPulse', () => {
diff --git a/src/renderer/lib/brandPulse.ts b/src/renderer/lib/brandPulse.ts
index c8084b8c9..03007e88a 100644
--- a/src/renderer/lib/brandPulse.ts
+++ b/src/renderer/lib/brandPulse.ts
@@ -27,9 +27,21 @@ export const AGENT_LOGO: Partial<Record<string, string>> = {
opencode: opencodeIcon
}
+/**
+ * This agent's brand asset, or undefined — the ONE way to read AGENT_LOGO.
+ *
+ * `Object.hasOwn`, never `agentId in AGENT_LOGO` and never a bare `AGENT_LOGO[agentId]`: `AgentId` is
+ * open and `data.agentId` comes from hand-editable `.nodeterm/project.json`, so a node carrying
+ * `"agentId": "constructor"` makes `in` answer true and the index hand back **`Function`** — which
+ * then reached an `<img src>` / a CSS `url()` as a stringified function body.
+ */
+export const brandLogoSrc = (agentId: AgentId): string | undefined =>
+ Object.hasOwn(AGENT_LOGO, agentId) ? AGENT_LOGO[agentId] : undefined
+
/** Does this agent have a brand mark to draw? grok is inlined rather than an asset, so it is not in
* AGENT_LOGO — ask through here rather than testing that map directly. */
-export const hasBrandLogo = (agentId: AgentId): boolean => agentId === 'grok' || agentId in AGENT_LOGO
+export const hasBrandLogo = (agentId: AgentId): boolean =>
+ agentId === 'grok' || brandLogoSrc(agentId) !== undefined
/** Canvas RUNNING-badge class (styles.css). */
export const BRAND_PULSE_CLASS = 'term-node__mascot--pulse'
@@ -66,7 +78,7 @@ export type BrandPulsePlan =
export function brandPulsePlan(agentId: AgentId | undefined, size: number): BrandPulsePlan | null {
if (!agentId || !hasBrandLogo(agentId)) return null
if (agentId === 'grok') return { kind: 'inline', size }
- const src = AGENT_LOGO[agentId]
+ const src = brandLogoSrc(agentId)
return src ? { kind: 'asset', src, size } : null
}
diff --git a/src/shared/agents/hook-events.ts b/src/shared/agents/hook-events.ts
index 163df4046..43158c7b5 100644
--- a/src/shared/agents/hook-events.ts
+++ b/src/shared/agents/hook-events.ts
@@ -46,9 +46,10 @@ export const CLAUDE_HOOK_EVENTS = [
* - `AfterModel` fires for EVERY streamed chunk (reference.md:236-237, "Fired for every chunk
* generated by the model"; its `fireAfterModelEvent(request, chunk)` runs inside the chunk
* loop), so subscribing would spawn a hook process per chunk. It is also the one that carries
- * `llm_response.usageMetadata.totalTokenCount` — the one number worth having — which is why a
- * gemini context meter must read the transcript instead of subscribing here. (Not built yet;
- * that is a separate task. Do not "just add AfterModel" to get the tokens.)
+ * `llm_response.usageMetadata.totalTokenCount` — the one number worth having — which is why the
+ * gemini context meter reads the TRANSCRIPT instead of subscribing here (`core/gemini-session.ts`
+ * `geminiContextParse`, fed by the same tail claude's meter uses). Do not "just add AfterModel"
+ * to get the tokens: the meter already has them, and this event would cost a process per chunk.
* - `BeforeModel` is NOT per-chunk — it fires once per model request (reference.md:187-190,
* "Fires before sending a request to the LLM"). It is left out for the plain reason the two
* below are: it reports nothing we render. A turn's start is already `BeforeAgent`, and a