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.

docs(grok): correct the comments this branch made false, and record the GROK_HOME trap

enes5e4119ad21d2
diff --git a/src/core/agents/grok-paths.ts b/src/core/agents/grok-paths.ts
index 903e66611..6d7fc598c 100644
--- a/src/core/agents/grok-paths.ts
+++ b/src/core/agents/grok-paths.ts
@@ -5,8 +5,8 @@
// re-deriving `$GROK_HOME`.
//
// It lives in `src/core`, NOT `src/shared/agents`, even though its callers span three process
-// contexts: it reads `os.homedir()` and measures with `Buffer` at module scope, and `src/shared` is
-// renderer territory — the renderer imports `shared/agents/*`, and `tsconfig.web.json` carries node
+// contexts: it reads `os.homedir()` and measures with `Buffer` (per call — the point is that both
+// are node-only APIs, not when they run), and `src/shared` is renderer territory — the renderer imports `shared/agents/*`, and `tsconfig.web.json` carries node
// types, so a renderer import of this file would typecheck cleanly and fail only at bundle or run
// time. `src/core` is node-side by construction (no electron, no renderer), which is exactly this
// file's contract. Should a renderer surface ever need one of these helpers, split the genuinely
@@ -41,7 +41,24 @@ const REMOTE_HOME_MAX = 4096
// the error and take the typo check with it.
type GrokEnv = { GROK_HOME?: string }
-/** grok's config directory: `$GROK_HOME`, else `~/.grok`. Hooks AND sessions live under it. */
+/** grok's config directory: `$GROK_HOME`, else `~/.grok`. Hooks AND sessions live under it.
+ *
+ * KNOWN TRAP — the env this reads is the APP's, not the user's shell. A desktop app launched from
+ * Finder/Dock/a `.desktop` entry inherits the launcher's environment, which never sourced
+ * `.zshrc`/`.bashrc`; this repo already knows the class, which is why `findTmux()` resolves an
+ * absolute path "because GUI apps don't inherit the shell PATH". So for a user whose only
+ * `export GROK_HOME=…` lives in a shell rc file, the two sides disagree: nodeterm writes the hook
+ * file (and looks for sessions) under `~/.grok`, while the grok CLI — started by the shell inside a
+ * tmux pane, which DID source that rc — reads the exported path. Nothing errors. The hook file is
+ * written successfully, grok never loads it, and the consequence is total and silent: no RUNNING /
+ * NEEDS YOU badge, no unread dot, no completion notification, no session name, ever, with no
+ * diagnostic anywhere. The REMOTE path does not have this problem (`RemoteHooks.installGrokRemote`
+ * asks the host through a login shell and validates the answer with `isSafeRemoteGrokHome`).
+ *
+ * Deliberately NOT fixed here: resolving it means probing the user's login shell for `GROK_HOME`
+ * (a spawn, a cache, and a fail-open policy), which is its own change with its own failure modes —
+ * not a comment. It is item 2 in docs/grok-agent.md's device checklist ("is `GROK_HOME` set in your
+ * shell?") because a device run is what tells us whether anyone actually sets it. */
export function grokHomeDir(env: GrokEnv = process.env as GrokEnv, home: string = homedir()): string {
const fromEnv = env.GROK_HOME?.trim()
return fromEnv || path.join(home, '.grok')
diff --git a/src/core/agents/hooks/grok.test.ts b/src/core/agents/hooks/grok.test.ts
index d2aff51d7..94764dbce 100644
--- a/src/core/agents/hooks/grok.test.ts
+++ b/src/core/agents/hooks/grok.test.ts
@@ -45,8 +45,14 @@ describe('grok hook installer', () => {
for (const ev of ['PreToolUse', 'PostToolUse', 'PostToolUseFailure']) {
expect(cfg.hooks[ev][0].matcher, ev).toBe('.*')
}
- // Non-tool events must carry NO matcher — grok warns and ignores one there. Every one of them
- // is checked, so a matcher accidentally attached to an event in hook-events.ts cannot ship.
+ // Non-tool events must carry NO matcher, for two DIFFERENT reasons — both in
+ // ~/.grok/docs/user-guide/10-hooks.md:153. On `Stop` and `UserPromptSubmit` a matcher is
+ // "ignored with a warning (those events always fire)": harmless noise. On the other four it
+ // FILTERS, against something that is not a tool name at all — the start source on
+ // `SessionStart`, the end reason on `SessionEnd`, the notification type on `Notification`, the
+ // classified error type on `StopFailure` — so a stray `.*` there is not noise: anything it fails
+ // to match is an event we silently never receive. Every one of them is checked, so a matcher
+ // accidentally attached to an event in hook-events.ts cannot ship.
for (const ev of ['SessionStart', 'UserPromptSubmit', 'Stop', 'StopFailure', 'Notification', 'SessionEnd']) {
expect(cfg.hooks[ev][0].matcher, ev).toBeUndefined()
}
diff --git a/src/core/agents/hooks/install-helper.ts b/src/core/agents/hooks/install-helper.ts
index b13339272..0cc790e35 100644
--- a/src/core/agents/hooks/install-helper.ts
+++ b/src/core/agents/hooks/install-helper.ts
@@ -1,6 +1,7 @@
// The ONE implementation of the per-agent settings.json hook merge. Each agent's thin
-// service (claude/codex/gemini) calls these with its own config path, script filename,
-// and event list. Behavior (ported from the original claude-hooks.ts):
+// service calls these with its own config path, script filename, and event list — claude,
+// gemini and grok do (grok also passing per-event matchers); codex writes its own hooks.json
+// (see its note) and opencode ships a plugin, so neither routes through here. Behavior (ported from the original claude-hooks.ts):
// - write the managed script for `agentId` to <userData>/agent-hooks/<scriptFileName>
// (chmod 0o755, best-effort), then reference it as `sh "<scriptPath>"` from each event;
// - idempotent re-install: drop any prior managed entry for that event (command includes
diff --git a/src/main/index.ts b/src/main/index.ts
index 878c6b4bc..319f994db 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -292,7 +292,9 @@ const browserGuests = new Map<number, string>()
// Node → live tail bookkeeping, so closing a node (× → pty:destroy) releases its file tailers.
// Without this, a node closed mid-run never emits SessionEnd/PostToolUse, so context-tail (1s
// poll) and subagent-tail (400ms poll) would keep stat/read-ing forever. Keyed by node id.
-const nodeContextSession = new Map<string, string>() // nodeId → claude sessionId
+// nodeId → the agent session id of whichever hook-capable CLI runs in that node (claude's, and
+// since the grok branch in the raw listener, grok's).
+const nodeContextSession = new Map<string, string>()
const nodeSubagents = new Map<string, Set<string>>() // nodeId → active subagent tool_use_ids
// Enforce a single instance. A second instance would re-attach every node's tmux session
@@ -1476,8 +1478,11 @@ app.whenReady().then(async () => {
})
if (dir) rememberGrokSessionDir(g.sessionId, dir)
}
- // The session is over: its directory can only go stale from here (grok never reuses an id),
- // and the map is bounded — so drop it instead of waiting for eviction.
+ // The session is over, so nothing will read its directory again — and forgetting costs
+ // nothing even though grok IS resumable and `grok --resume <id>` reuses BOTH the id and the
+ // directory: a resumed session fires its own hooks, whose (cwd, sessionId) re-derive and
+ // re-remember the very same path. The map is bounded, so dropping now beats waiting for
+ // eviction to reach an entry nobody is asking about.
if (g.event === 'sessionend') forgetGrokSession(g.sessionId)
return
}
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 2c22e58d2..8ddd372f9 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -344,10 +344,14 @@ export function createAgentNode(
// The separator only participates when there is actually a prompt to separate (no dangling `--`),
// and never for a flag-prompt agent, whose prompt is not a positional at all.
const usesSep = !!promptArg && !!sep && !isFlagPrompt
+ // `withPrompt` is the NO-separator shape, and only that: it is read at exactly one place below,
+ // in the `!usesSep` arm. Reaching it with a prompt and no flag-prompt mode means `sep` was falsy,
+ // so an inline `${sep ? … : ''}` here could only ever expand to '' — the separator's one home is
+ // the `usesSep` arm, which spells it out.
const withPrompt = promptArg
? isFlagPrompt
? `${baseCmd} --prompt ${promptArg}`
- : `${baseCmd} ${sep ? `${sep} ` : ''}${promptArg}`
+ : `${baseCmd} ${promptArg}`
: baseCmd
// No mode passed (e.g. a legacy/test call site) = bare command, exactly as before this setting.
const flagged = (cmd: string): string =>
diff --git a/src/renderer/terminal/agent-restart.ts b/src/renderer/terminal/agent-restart.ts
index 68d1e99c9..73a4b5b67 100644
--- a/src/renderer/terminal/agent-restart.ts
+++ b/src/renderer/terminal/agent-restart.ts
@@ -17,8 +17,10 @@ import {
* an unknown CLI has no safe way to be asked to quit.
*
* grok: `/quit` (its `/exit` is an alias — the documented primary is the one we type), and its
- * relaunch line comes from `resumeCommand` → `grok --resume <id>`, so one entry here turns on the
- * header button, the node-menu row and the bulk "restart idle agents" action at once. */
+ * relaunch line comes from `resumeCommand` → `grok --resume <id>`, so one entry here turns on both
+ * surfaces at once: the single-node "Restart agent (resume)" row in the node context menu, and the
+ * bulk "restart idle agents" action (pane menu + command palette). There is no header button for
+ * either — `HIDEABLE_HEADER_BUTTONS` is refresh / mic / ai-name / comments. */
const EXIT_SEQUENCES: Record<string, string> = { claude: '/exit', codex: '/quit', grok: '/quit' }
export function exitSequence(agentId: string): string | null {
diff --git a/src/server/agent-status.ts b/src/server/agent-status.ts
index 51d457da3..32e7e78dc 100644
--- a/src/server/agent-status.ts
+++ b/src/server/agent-status.ts
@@ -51,7 +51,8 @@ export function wireAgentStatus(
opts: WireAgentStatusOptions = {}
): { contextTail: ContextTail } {
const hooks = opts.hooks ?? hookServer
- // nodeId → claude sessionId
+ // nodeId → the agent session id of whichever hook-capable CLI runs in that node (claude's, and
+ // since the grok branch below, grok's)
const nodeContextSession = new Map<string, string>()
// nodeId → active subagent tool_use_ids
const nodeSubagents = new Map<string, Set<string>>()
@@ -168,8 +169,11 @@ export function wireAgentStatus(
})
if (dir) rememberGrokSessionDir(g.sessionId, dir)
}
- // The session is over: its directory can only go stale from here (grok never reuses an id),
- // and the map is bounded — so drop it instead of waiting for eviction.
+ // The session is over, so nothing will read its directory again — and forgetting costs
+ // nothing even though grok IS resumable and `grok --resume <id>` reuses BOTH the id and the
+ // directory: a resumed session fires its own hooks, whose (cwd, sessionId) re-derive and
+ // re-remember the very same path. The map is bounded, so dropping now beats waiting for
+ // eviction to reach an entry nobody is asking about.
if (g.event === 'sessionend') forgetGrokSession(g.sessionId)
return
}
diff --git a/src/shared/agents/config.capabilities.test.ts b/src/shared/agents/config.capabilities.test.ts
index b458c295c..86c616bf2 100644
--- a/src/shared/agents/config.capabilities.test.ts
+++ b/src/shared/agents/config.capabilities.test.ts
@@ -74,7 +74,9 @@ describe('createdAgentId', () => {
* Grok claims a capability only once its per-agent machinery exists — an installer, a transcript
* parser, a discovery file — because claiming one early lights badges that never update and offers
* menu items that do nothing. Hooks arrived with the normalizer (normalizeGrok) plus the installer
- * that writes $GROK_HOME/hooks/nodeterm-status.json; context links and canvas control have not.
+ * that writes $GROK_HOME/hooks/nodeterm-status.json. Canvas control needed nothing new — grok scans
+ * `~/.claude/skills`, where manage-nodeterm-canvas already lives (asserted below). Context links did
+ * not arrive: they need a parser for grok's own transcript format.
*/
describe('grok capabilities', () => {
it('is a builtin with a launch command and a colour', () => {
diff --git a/src/shared/agents/hook-events.ts b/src/shared/agents/hook-events.ts
index 635d3d4ce..120b1538e 100644
--- a/src/shared/agents/hook-events.ts
+++ b/src/shared/agents/hook-events.ts
@@ -54,8 +54,11 @@ export const GROK_HOOK_EVENTS: readonly ManagedHookEvent[] = [
'StopFailure',
'Notification',
'SessionEnd',
- // Tool events need the regex matcher. `.*` matches every tool name; an omitted matcher is
- // documented as matching everything too, but `.*` is the form measured working here.
+ // The matcher is a REGEX, and an omitted one already matches everything
+ // (~/.grok/docs/user-guide/10-hooks.md:153) — so this is not a requirement, it is an explicit
+ // statement of "every tool". It is spelled `.*` and never `*`, because a bare `*` is not a
+ // valid regex at all (nothing to repeat) and the failure mode is silence: the tool lifecycle
+ // hooks simply never fire, so RUNNING clears mid-turn on a long tool call with nothing saying why.
{ event: 'PreToolUse', matcher: '.*' },
{ event: 'PostToolUse', matcher: '.*' },
{ event: 'PostToolUseFailure', matcher: '.*' }
diff --git a/src/shared/usage-limits.ts b/src/shared/usage-limits.ts
index fe3041bec..ec46dbb99 100644
--- a/src/shared/usage-limits.ts
+++ b/src/shared/usage-limits.ts
@@ -109,9 +109,13 @@ export const USAGE_PROVIDER_IDS = [
] as const
/**
- * Display names for usage providers that are NOT builtin agents — Grok, Kimi and the rest are
- * billing relationships we can read, not CLIs nodeterm spawns, so they have no AGENT_CONFIG
- * entry to borrow a label from.
+ * Display names for usage providers that have no `AGENT_CONFIG` entry to borrow a label from —
+ * Kimi, MiniMax and the rest are billing relationships we can read, not CLIs nodeterm spawns.
+ *
+ * `grok` is the exception, and its entry here is now DEAD: grok became a builtin agent, so
+ * `AGENT_CONFIG.grok.label` exists and `providerLabel` prefers it. The string is identical
+ * ('Grok'), so nothing visible changed — the row is kept as the fallback for a build where the
+ * agent is gone but the billing provider stays.
*/
const PROVIDER_LABELS: Record<string, string> = {
'claude-remote': 'Claude on SSH hosts',