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.

29.7 KB
Raw Blame
import { describe, it, expect } from 'vitest'
import { normalizeFor } from './normalize'
import {
  AGENT_CONFIG,
  BUILTIN_AGENT_IDS,
  canBranch,
  canChat,
  chatReadsLocalOnly,
  mintsSessionId,
  supportsSessionIdFlag,
  readsClaudeShapedTranscript,
  canContextLink,
  canControlCanvas,
  canReadTitle,
  canRecur,
  canRename,
  canResume,
  canSubagent,
  canTransferFrom,
  canSwitchModel,
  createdAgentId,
  hasHooks,
  hasGatewayModels,
  hasPermissionMode,
  hasUsage,
  MODEL_SWITCH_CAPABLE,
  OWN_MODEL_CATALOGUE,
  reportsOwnCopy,
  RENAME_CAPABLE,
  hasSharedIdentity,
  agentLaunchProgram,
  resumeCommand,
  hasHooksOverSsh,
  CHAT_CAPABLE,
  TYPED_INPUT_CAPABLE,
  typesChatInput,
  readsScreenDialogs,
  queuesInputWhileWorking,
  interruptsFromChat,
  CHAT_INTERRUPT_CAPABLE,
  LOCAL_ONLY_HOOK_AGENTS,
  reportsSessionEnd,
  resumeCommandWith,
  submitsSeparately
} from './config'
import { CURSOR_HOOK_EVENTS } from './hook-events'

describe('CONTEXT_LINK_CAPABLE', () => {
  it('all three builtin agents can context-link', () => {
    expect(canContextLink('claude')).toBe(true)
    expect(canContextLink('codex')).toBe(true)
    expect(canContextLink('gemini')).toBe(true)
  })
  it('custom agents cannot', () => {
    expect(canContextLink('custom:abc')).toBe(false)
  })
})

describe('MODEL_SWITCH_CAPABLE', () => {
  it('is centralized on the base harness capability', () => {
    expect(canSwitchModel('claude')).toBe(true)
    expect(canSwitchModel('codex')).toBe(true)
    expect(canSwitchModel('copilot')).toBe(true)
    // grok joined once its leaf existed: `-m/--model` in the launch grammar plus `grok models` for
    // discovery. It is NOT in this list as an example of a non-capable agent any more.
    expect(canSwitchModel('grok')).toBe(true)
    // cursor: `--model <id>` (a root option, measured before and after `agent`). Its models are its
    // own catalogue, so it joins the list WITHOUT the gateway's models (OWN_MODEL_CATALOGUE).
    expect(canSwitchModel('cursor')).toBe(true)
    expect(canSwitchModel('antigravity')).toBe(true)
    expect(hasGatewayModels('cursor')).toBe(false)
    expect(hasGatewayModels('grok')).toBe(false)
    expect(hasGatewayModels('antigravity')).toBe(false)
    for (const id of ['claude', 'codex', 'copilot'] as const)
      expect(hasGatewayModels(id), id).toBe(true)
    for (const id of ['gemini', 'opencode', 'custom:plain'] as const) {
      expect(canSwitchModel(id), id).toBe(false)
      expect(hasGatewayModels(id), id).toBe(false)
    }
  })

  it('OWN_MODEL_CATALOGUE is a subset of the switch-capable list', () => {
    for (const id of OWN_MODEL_CATALOGUE)
      expect(MODEL_SWITCH_CAPABLE as readonly string[]).toContain(id)
  })
})

describe('copilot capabilities', () => {
  it('is a builtin with measured interactive launch, hooks, resume, and model switching', () => {
    expect(BUILTIN_AGENT_IDS).toContain('copilot')
    expect(AGENT_CONFIG.copilot).toEqual({
      label: 'GitHub Copilot',
      color: '#8957e5',
      launchCmd: 'copilot',
      promptInjectionMode: 'flag-interactive',
      expectedProcess: 'copilot',
      vanillaEnvPattern: '^COPILOT_PROVIDER_'
    })
    expect(hasHooks('copilot')).toBe(true)
    expect(canResume('copilot')).toBe(true)
    expect(canControlCanvas('copilot')).toBe(true)
    expect(canSwitchModel('copilot')).toBe(true)
  })

  it('does not claim integrations whose Copilot-specific leaf is not implemented', () => {
    for (const can of [
      canContextLink,
      canSubagent,
      canRecur,
      canBranch,
      hasUsage,
      canTransferFrom,
      canRename,
      canReadTitle,
      hasPermissionMode
    ]) {
      expect(can('copilot')).toBe(false)
    }
  })

  it('shows its conversation in the chat panel from its OWN journal, never through claude\'s resolver', () => {
    // The ⌘M leaf is `core/copilot-chat.ts` (`<COPILOT_HOME>/session-state/<id>/events.jsonl`, keyed
    // strictly by session id). Joining CHAT_CAPABLE must not join CLAUDE_TRANSCRIPT_READABLE: that
    // list gates the find bar's index and the meter's rehydration, both of which resolve through
    // claude's cwd fallback and would hand a copilot node someone else's claude session.
    expect(canChat('copilot')).toBe(true)
    expect(readsClaudeShapedTranscript('copilot')).toBe(false)
  })
})

describe('opencode capabilities', () => {
  it('is a builtin with the parity capability set', () => {
    expect(BUILTIN_AGENT_IDS).toContain('opencode')
    expect(AGENT_CONFIG.opencode).toEqual({
      label: 'opencode',
      color: '#a78bfa',
      launchCmd: 'opencode',
      promptInjectionMode: 'flag-prompt',
      expectedProcess: 'opencode'
    })
    expect(hasHooks('opencode')).toBe(true)
    expect(canResume('opencode')).toBe(true)
    expect(canContextLink('opencode')).toBe(true)
    expect(canControlCanvas('opencode')).toBe(true)
  })
  it('stays out of the claude-only capability lists', () => {
    for (const can of [canSubagent, canRecur, canBranch, hasUsage, canTransferFrom, canRename, canReadTitle, hasPermissionMode]) {
      expect(can('opencode')).toBe(false)
    }
  })
  it('shows its conversation in the ⌘M chat panel — read through `opencode export`, never claude\'s resolver', () => {
    // Same pair grok pins below: opencode's sessions live in a database read by `opencode export`
    // (core/opencode-chat.ts), so claude's resolver — whose cwd fallback returns a stranger's newest
    // transcript — must never be asked for one.
    expect(canChat('opencode')).toBe(true)
    expect(readsClaudeShapedTranscript('opencode')).toBe(false)
  })
})

describe('createdAgentId', () => {
  it('reads data.agentId, with the legacy tags fallback', () => {
    expect(createdAgentId({ agentId: 'codex' })).toBe('codex')
    expect(createdAgentId({ tags: ['claude', 'x'] })).toBe('claude')
    expect(createdAgentId({ agentId: 'gemini', tags: ['claude'] })).toBe('gemini')
  })

  it('is undefined for a plain terminal, a foreign tag, or nothing at all', () => {
    expect(createdAgentId({})).toBeUndefined()
    expect(createdAgentId({ tags: ['review'] })).toBeUndefined()
    expect(createdAgentId(undefined)).toBeUndefined()
  })

  it('tolerates hand-edited project.json shapes', () => {
    // node data is deserialized JSON: nothing guarantees these types at runtime.
    expect(createdAgentId({ agentId: 42 })).toBeUndefined()
    expect(createdAgentId({ tags: 'claude' })).toBeUndefined()
  })
})

/**
 * 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. 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', () => {
    expect(BUILTIN_AGENT_IDS).toContain('grok')
    expect(AGENT_CONFIG.grok.launchCmd).toBe('grok')
    expect(AGENT_CONFIG.grok.label).toBe('Grok')
  })

  it('takes its prompt as a positional, BEHIND a `--` separator', () => {
    // Measured against the shipped 1.0.0 binary, whose usage is `grok [OPTIONS] [PROMPT] [COMMAND]`
    // — the prompt shares its slot with the subcommand list. `grok version` prints the version and
    // exits; `grok -- version` opens a session with "version" as the prompt. Without the separator
    // a prompt of `help`, `version`, `login`, `models` or `export` is executed as a command and
    // never reaches the model.
    expect(AGENT_CONFIG.grok.promptInjectionMode).toBe('argv')
    expect(AGENT_CONFIG.grok.argvPromptSeparator).toBe('--')
  })

  it('is the only agent besides cursor that asks for a separator', () => {
    // claude takes a positional too, but has no subcommand a one-word prompt could shadow — and
    // adding `--` there would change a command line that works today. cursor needs one for the
    // same reason as grok, but its CLI ignores `--` (see the cursor block below).
    for (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'grok' && a !== 'cursor')) {
      expect(AGENT_CONFIG[id].argvPromptSeparator, id).toBeUndefined()
    }
  })

  it('reports status through its own hooks', () => {
    // What had to be true first: a normalizer for grok's dialect (normalizeGrok) and an installer
    // that writes $GROK_HOME/hooks/nodeterm-status.json. Both exist now, so the badge, the unread
    // dot, the completion notification, the notch capsule and the session-id capture all apply.
    expect(hasHooks('grok')).toBe(true)
    expect(canResume('grok')).toBe(true)
  })

  it('syncs its session name in both directions', () => {
    // Write leg: grok's own `/rename <title>` (alias `/title`), the same one-way push into the
    // pane claude uses — so sessionRename.ts needs no change. Read leg: summary.json.
    expect(canRename('grok')).toBe(true)
  })

  it('drives the canvas, on the skill that is already installed for claude', () => {
    // The only capability grok gets with no per-agent leaf of its own: it scans `~/.claude/skills`
    // by default (Claude Code compat, see its user-guide/08-skills.md), which is where
    // manage-nodeterm-canvas is already written. See config.control.test.ts.
    expect(canControlCanvas('grok')).toBe(true)
  })

  it('reads a linked node, on the same already-installed skill the canvas verb uses', () => {
    // The leaf that had to exist first: `locateGrok` (core/handoff/locate.ts), resolving the
    // session directory a hook reported and returning `chat_history.jsonl` — NOT the
    // `updates.jsonl` grok's payloads advertise. That sibling is the ACP event stream: it does carry
    // conversation, but as CHUNKS interleaved with tool-call and hook events, so our line parser
    // finds no `type` on any line and the linked agent gets an empty transcript with no error. Discovery needs no installer of its own,
    // and that is now MEASURED rather than assumed: on 1.0.13, `grok inspect --json` lists
    // `get-linked-context` as `vendor: 'claude', compatibilityStatus: 'enabled'`.
    expect(canContextLink('grok')).toBe(true)
  })

  it('hands its conversation to another agent, and shows it in the chat panel', () => {
    // Both ride the reader task06 wrote. Transfer adds `renderGrokTranscript` beside the other
    // three renderers; the panel adds `chatMessagesFromGrok`. Neither re-derives grok's line
    // vocabulary — they build on the same `grokParse`, so the two views cannot drift apart.
    expect(canTransferFrom('grok')).toBe(true)
    expect(canChat('grok')).toBe(true)
  })

  it('is CHAT_CAPABLE and yet NOT readable by claude\'s resolver — the pair is the invariant', () => {
    // These two must never collapse back into one list. `canChat` means "we can render this
    // conversation ourselves"; `readsClaudeShapedTranscript` means "claude's resolver can locate and
    // parse this file". Grok is the first agent for which they differ, and the cost of merging them
    // is not cosmetic: `resolveTranscript` falls back to the newest CLAUDE transcript for the node's
    // cwd whenever its sessionId leg misses, which a grok id always does. A merged list would show a
    // grok node someone else's conversation in the find bar and meter it from that session.
    //
    // If a future change "simplifies" CLAUDE_TRANSCRIPT_READABLE away, this line fails first.
    expect(canChat('grok')).toBe(true)
    expect(readsClaudeShapedTranscript('grok')).toBe(false)
    // claude is the one agent where both hold — which is exactly why the shared list looked correct
    // for as long as it was claude-only.
    expect(canChat('claude')).toBe(true)
    expect(readsClaudeShapedTranscript('claude')).toBe(true)
  })

  it('fills a context meter from the numbers it states itself', () => {
    // grok states the numerator, the denominator AND the percentage (signals.json). The window is
    // read, never inferred from the model id — which puts grok with codex, not with gemini.
    expect(hasUsage('grok')).toBe(true)
  })

  it('joins USAGE_CAPABLE without joining the claude-transcript readers', () => {
    // The regression this project already survived once: `hasUsage` gated THREE features, and
    // joining it for the meter also switched on `context.ensure` and the find bar's index, both of
    // which resolve through claude's `resolveTranscript` — whose cwd fallback then hands the node
    // the newest CLAUDE transcript for that directory. A codex node metered and searched a
    // stranger's session, and the preconditions were default-true, so it would have shipped.
    //
    // These two must therefore DISAGREE for grok, exactly as they do for codex and gemini.
    expect(hasUsage('grok')).toBe(true)
    expect(readsClaudeShapedTranscript('grok')).toBe(false)
  })

  it('mints its own session id, gated on ITS OWN probe and never on claude\'s', () => {
    expect(mintsSessionId('grok')).toBe(true)
    // The third argument is grok's probe. Claude's answer must not move grok's gate in EITHER
    // direction — that is rule 9: a gate fed by a version probe belongs to the agent it probes, and
    // the two CLIs are installed and upgraded independently.
    expect(supportsSessionIdFlag('grok', false, true)).toBe(true)
    expect(supportsSessionIdFlag('grok', true, false)).toBe(false)
    // Unprobed reads as no: a bare command, never a blocked launch. There is no shorter call to
    // write — the third argument is required precisely so nobody can omit grok's probe by accident.
    expect(supportsSessionIdFlag('grok', true, false)).toBe(false)
    // And grok's probe must not move CLAUDE's gate either.
    expect(supportsSessionIdFlag('claude', true, false)).toBe(true)
    expect(supportsSessionIdFlag('claude', false, true)).toBe(false)
  })

  it('picks a model through the base-harness mapping, from grok\'s own catalogue', () => {
    // The whole capability is the leaf: membership plus `grok models` for discovery and `--model`
    // in the launch grammar. No frontend spells a grok model id, and none spells `grok` here either
    // — `modelsForAgent` decides who is offered which catalogue.
    expect(canSwitchModel('grok')).toBe(true)
  })

  it('shows one card per subagent INSTANCE, not one per type', () => {
    // Keyed by `subagentId`, measured by running two `explore` children in parallel: same type,
    // different ids. The premise this task started from — that grok only exposes a TYPE, so two
    // children of one type would have to share an aggregated card — was wrong, and running the two
    // is the only thing that could have told us.
    expect(canSubagent('grok')).toBe(true)
  })

  it('does not yet claim the capabilities whose per-agent leaf is unwritten', () => {
    expect(canBranch('grok')).toBe(false)
  })
})

/**
 * Antigravity (`agy`) joins with exactly ONE capability list: AGENT_HOOK_TARGETS. Its leaves are a
 * normalizer (normalizeAntigravity) and an installer for `~/.gemini/config/hooks.json`. Every other
 * list is a separate leaf it does not have yet, and joining one early lights a badge that never
 * updates or offers an action that silently does the wrong thing (rule 2 in CLAUDE.md). Each
 * exclusion below says which leaf is missing — measured facts (`agy` 1.2.3, Windows 11).
 */
describe('antigravity capabilities', () => {
  it('is offered ABOVE gemini wherever agents are listed (BUILTIN_AGENT_IDS is display order)', () => {
    // Google moved personal accounts from Gemini CLI to Antigravity on 2026-06-18.
    expect(BUILTIN_AGENT_IDS.indexOf('antigravity')).toBeLessThan(BUILTIN_AGENT_IDS.indexOf('gemini'))
  })

  it('reports status on THIS machine only — an SSH host has no agy hook installer yet', () => {
    // `--after` asks this before accepting a dependency in an SSH project: a node that can never
    // report "done" there would hold its dependant QUEUED forever.
    expect(hasHooksOverSsh('antigravity')).toBe(false)
    expect(LOCAL_ONLY_HOOK_AGENTS as readonly string[]).toEqual(['antigravity'])
    for (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'antigravity')) {
      expect(hasHooksOverSsh(id), id).toBe(hasHooks(id))
    }
  })

  it('is a builtin that launches `agy`, prompt through --prompt-interactive', () => {
    expect(BUILTIN_AGENT_IDS).toContain('antigravity')
    expect(AGENT_CONFIG.antigravity.launchCmd).toBe('agy')
    expect(AGENT_CONFIG.antigravity.expectedProcess).toBe('agy')
    expect(AGENT_CONFIG.antigravity.label).toBe('Antigravity')
    expect(AGENT_CONFIG.antigravity.promptInjectionMode).toBe('flag-interactive')
    expect(AGENT_CONFIG.antigravity.promptFlag).toBe('--prompt-interactive')
  })

  it('is the only agent that overrides the interactive prompt flag', () => {
    // copilot's `--interactive` must stay the default, byte-identical.
    for (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'antigravity')) {
      expect(AGENT_CONFIG[id].promptFlag, id).toBeUndefined()
    }
  })

  it('reports status through its own hooks', () => {
    // Badge, unread, completion notification, `--after` dependency and trigger target all follow.
    expect(hasHooks('antigravity')).toBe(true)
  })

  it('joins the measured transcript, context-link, canvas-control, model-switch, and permission-mode capabilities without joining claude-transcript readers', () => {
    expect(hasUsage('antigravity')).toBe(true)
    expect(canChat('antigravity')).toBe(true)
    expect(readsClaudeShapedTranscript('antigravity')).toBe(false)
    expect(canTransferFrom('antigravity')).toBe(true)
    expect(canContextLink('antigravity')).toBe(true)
    expect(canControlCanvas('antigravity')).toBe(true)
    expect(hasPermissionMode('antigravity')).toBe(true)
    expect(canSwitchModel('antigravity')).toBe(true)
  })

  it('does not claim the capabilities whose per-agent leaf is unwritten', () => {
    // No SessionEnd-shaped event exists among agy's five, so a DROPPED chip would be a coin flip.
    expect(reportsSessionEnd('antigravity')).toBe(false)
    // `agy --conversation=<id>` resumes; the id is validated at the interpolation site
    // (SAFE_SESSION_ID) and a dead one is ignored by agy itself (it starts fresh). Not minted.
    expect(canResume('antigravity')).toBe(true)
    expect(resumeCommand('antigravity', '5f0c2f8e-9a51-4c41-9d2e-2b6f0f3e7a11')).toBe(
      'agy --conversation=5f0c2f8e-9a51-4c41-9d2e-2b6f0f3e7a11'
    )
    expect(resumeCommand('antigravity', "x'; rm -rf ~")).toBeNull()
    expect(mintsSessionId('antigravity')).toBe(false)
    // No subagent/recurring/branch events are wired (invoke_subagent exists in the enum, unmeasured).
    expect(canSubagent('antigravity')).toBe(false)
    expect(canRecur('antigravity')).toBe(false)
    expect(canBranch('antigravity')).toBe(false)
    // Title lives in SQLite (unmeasured) and there is no rename command; read ⊇ write holds.
    expect(canReadTitle('antigravity')).toBe(false)
    expect(canRename('antigravity')).toBe(false)
    expect(RENAME_CAPABLE as readonly string[]).not.toContain('antigravity')
    // No shared app-server mode, and agy does not announce its own copies.
    expect(hasSharedIdentity('antigravity')).toBe(false)
    expect(reportsOwnCopy('antigravity')).toBe(false)
  })
})

/**
 * Cursor's lists so far: AGENT_HOOK_TARGETS (badge, unread dot, completion notification, `--after`
 * dependency and trigger target; leaves `normalizeCursor` + the `~/.cursor/hooks.json` installer),
 * PERMISSION_MODE_CAPABLE and MODEL_SWITCH_CAPABLE (leaf: CURSOR_MODES in approval-mode.ts).
 * Everything else is a separate leaf that does not exist yet; docs/cursor-agent.md says which.
 */
describe('cursor capabilities', () => {
  it('reports status through its own hooks, locally and on an SSH host (RemoteHooks.installCursorRemote)', () => {
    expect(hasHooks('cursor')).toBe(true)
    expect(hasHooksOverSsh('cursor')).toBe(true)
  })

  it('takes a permission mode and a model on its launch line', () => {
    expect(hasPermissionMode('cursor')).toBe(true)
    expect(canSwitchModel('cursor')).toBe(true)
  })

  it('does not claim the capabilities whose per-agent leaf is unwritten', () => {
    for (const can of [canRecur, canBranch]) {
      expect(can('cursor')).toBe(false)
    }
    expect(readsClaudeShapedTranscript('cursor')).toBe(false)
  })
})

describe('copy feedback', () => {
  it('stays quiet for claude, whose CLI announces its own copies', () => {
    // Claude Code captures the mouse and prints "copied N chars to tmux buffer · paste with
    // prefix + ]" itself, so nodeterm's pill would be a second message for one gesture.
    expect(reportsOwnCopy('claude')).toBe(true)
  })

  it('speaks for every agent that says nothing itself', () => {
    // codex leaves the mouse to tmux: the drag copies via OSC 52 and the highlight vanishes on
    // release with no word from anyone. That silence is what the pill exists for.
    for (const id of ['codex', 'gemini', 'opencode', 'grok', 'copilot'])
      expect(reportsOwnCopy(id)).toBe(false)
  })

  it('speaks for a plain terminal and a custom agent (no agent id at all)', () => {
    expect(reportsOwnCopy(undefined)).toBe(false)
    expect(reportsOwnCopy('my-custom-agent')).toBe(false)
  })
})

/**
 * Reading a session name and PUSHING one back are different capabilities, and gemini has only the
 * first: its transcript carries a model-generated name (the `update_topic` tool's `args.title`,
 * measured in `core/__fixtures__/gemini/session.jsonl`), but its command set
 * (`/chat list|save|resume|delete|share`, measured on 0.54.4) has no rename — `save <tag>` is a
 * tagged checkpoint. One list for both would light the rename UI on a node where it does nothing.
 */
describe('title read vs rename write', () => {
  it('gemini can be read but never written', () => {
    expect(canReadTitle('gemini')).toBe(true)
    expect(canRename('gemini')).toBe(false)
  })

  it('claude and grok do both', () => {
    for (const id of ['claude', 'grok'] as const) {
      expect(canReadTitle(id), id).toBe(true)
      expect(canRename(id), id).toBe(true)
    }
  })

  it('every rename-capable agent is also title-readable — the write leg needs the read leg to settle', () => {
    for (const id of RENAME_CAPABLE) expect(canReadTitle(id), id).toBe(true)
  })

  it('codex reads but does not write — the same split gemini forced', () => {
    // With the shared app-server a codex node owns a THREAD, and that thread has a `Thread.name`
    // we can read over the server's own socket (core/codex-session-name.ts). There is still no
    // measured rename command, and one list for both legs would light the rename UI on a node
    // where the write silently does nothing.
    expect(canReadTitle('codex')).toBe(true)
    expect(canRename('codex')).toBe(false)
  })

  it('only codex has a shared identity, and it is asked through the helper', () => {
    expect(hasSharedIdentity('codex')).toBe(true)
    for (const id of ['claude', 'gemini', 'grok', 'opencode', 'copilot', 'custom:abc'] as const) {
      expect(hasSharedIdentity(id), id).toBe(false)
    }
  })

  it('the launch program is the bare CLI unless the caller says shared identity is available', () => {
    // The default is the pre-feature command, byte for byte: an unprobed machine, an SSH project,
    // a test, a call site that never opted in — all emit `codex`. Same shape as gatePermissionMode.
    expect(agentLaunchProgram('codex', 'codex')).toBe('codex')
    expect(agentLaunchProgram('codex', 'codex', false)).toBe('codex')
    expect(agentLaunchProgram('codex', 'codex', true)).toBe('nodeterm-codex')
    // A non-member never gets rerouted, whatever the caller claims.
    expect(agentLaunchProgram('claude', 'claude', true)).toBe('claude')
    expect(resumeCommand('codex', 'thread-1')).toBe('codex resume thread-1')
    expect(resumeCommand('codex', 'thread-1', true)).toBe('nodeterm-codex resume thread-1')
    expect(resumeCommand('claude', 'abc', true)).toBe('claude --resume abc')
  })

  it('a custom agent claims neither', () => {
    expect(canReadTitle('custom:abc')).toBe(false)
    expect(canRename('custom:abc')).toBe(false)
  })
})

describe('cursor capabilities (transcript leaf)', () => {
  it("shows its conversation in ⌘M from its own SQLite store, never through claude's resolver", () => {
    expect(canChat('cursor')).toBe(true)
    expect(readsClaudeShapedTranscript('cursor')).toBe(false)
  })
  it('is local-only for the chat view: a remote node says "not supported yet"', () => {
    expect(chatReadsLocalOnly('cursor')).toBe(true)
  })
  it('joins context link, transfer-from and the title READ leg', () => {
    expect(canContextLink('cursor')).toBe(true)
    expect(canTransferFrom('cursor')).toBe(true)
    expect(canReadTitle('cursor')).toBe(true)
  })
})

/**
 * Cursor orchestration parity (docs/cursor-agent.md "Orchestration parity"), MEASURED on
 * cursor-agent 2026.10.01 in the interactive TUI.
 */
describe('cursor capabilities (orchestration)', () => {
  it('drives the canvas: ~/.claude/skills is listed by cursor, so membership is the whole wiring', () => {
    expect(canControlCanvas('cursor')).toBe(true)
  })
  it('shows subagent cards (start: parent Task preToolUse, end: parent stop)', () => {
    expect(canSubagent('cursor')).toBe(true)
  })
  it('renames: /rename lands in the store meta the READ leg reads, so read ⊇ write holds', () => {
    expect(canRename('cursor')).toBe(true)
    expect(canReadTitle('cursor')).toBe(true)
  })
  it('submits a one-way line with a SEPARATE Enter; claude and grok keep the one-shot paste', () => {
    expect(submitsSeparately('cursor')).toBe(true)
    for (const id of ['claude', 'grok', 'codex', 'gemini']) expect(submitsSeparately(id), id).toBe(false)
  })
  it('does NOT join RECURRING_CAPABLE: the loop skill was seen arming, its ticks were never measured', () => {
    expect(canRecur('cursor')).toBe(false)
  })
})

describe('cursor capabilities (context meter)', () => {
  it('joins USAGE_CAPABLE with the agent’s own store numbers', () => {
    expect(hasUsage('cursor')).toBe(true)
  })
  it('stays off claude’s transcript resolver: no find-bar index, no cold-resume, no cwd fallback', () => {
    // hasUsage also gates context.ensure and the find bar's index in older code; the split is
    // readsClaudeShapedTranscript, which must stay false or a cursor node is handed a stranger's claude session.
    expect(readsClaudeShapedTranscript('cursor')).toBe(false)
    expect(readsClaudeShapedTranscript('claude')).toBe(true)
  })
})

describe('cursor capabilities (session continuity)', () => {
  it('resumes with `--resume <id>` before the `agent` subcommand', () => {
    expect(canResume('cursor')).toBe(true)
    expect(resumeCommandWith('cursor-agent', 'cursor', 'abc-123')).toBe('cursor-agent --resume abc-123')
    expect(resumeCommandWith('cursor-agent', 'cursor', 'x; rm -rf ~')).toBeNull()
  })
  it('mints with no probe of its own (the flag is resume, a fresh uuid is adopted)', () => {
    expect(mintsSessionId('cursor')).toBe(true)
    expect(supportsSessionIdFlag('cursor', false, false)).toBe(true)
  })
  it('reports a session end (normalizeCursor maps sessionEnd, CURSOR_HOOK_EVENTS subscribes it)', () => {
    expect(reportsSessionEnd('cursor')).toBe(true)
    expect(CURSOR_HOOK_EVENTS).toContain('sessionEnd')
  })
})

/**
 * Cursor wave 2 (F2): NEEDS YOU from a pane read, the SSH hook installer, the lost-stop net.
 * No capability list gates the approval watch: it is the hook server's own seam
 * (core/agents/cursor-approval.ts) and only `agentId === 'cursor'` posts reach it.
 */
describe('cursor NEEDS YOU, SSH hooks and lost stop', () => {
  it('is no longer local-only: RemoteHooks installs into the host ~/.cursor/hooks.json', () => {
    expect(LOCAL_ONLY_HOOK_AGENTS as readonly string[]).not.toContain('cursor')
    expect(hasHooksOverSsh('cursor')).toBe(true)
  })

  it('the normalizer itself still never says blocked (the pane read adds it, not a hook)', () => {
    for (const hook_event_name of ['preToolUse', 'beforeShellExecution', 'beforeMCPExecution', 'notification']) {
      const ev = normalizeFor('cursor', { nodeId: 'n', agentId: 'cursor', payload: { hook_event_name, tool_use_id: 't' } })
      expect(ev?.state === 'blocked', hook_event_name).toBe(false)
    }
  })
})

describe('typed chat input (TYPED_INPUT_CAPABLE)', () => {
  it('types only for claude — M-Enter is a measured newline there and unmeasured anywhere else', () => {
    expect(typesChatInput('claude')).toBe(true)
    for (const id of CHAT_CAPABLE.filter((a) => a !== 'claude')) expect(typesChatInput(id)).toBe(false)
  })

  it('is a subset of CHAT_CAPABLE: only the chat view types', () => {
    for (const id of TYPED_INPUT_CAPABLE) expect((CHAT_CAPABLE as readonly string[]).includes(id)).toBe(true)
  })
})

describe('readsScreenDialogs — whose own dialogs the chat view can see on screen', () => {
  it('is claude only: its reader would read every other CLI\'s screen as a permanent dialog', () => {
    expect(readsScreenDialogs('claude')).toBe(true)
    for (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'claude')) expect(readsScreenDialogs(id)).toBe(false)
  })
})

describe('interruptsFromChat — who Esc in the chat view may interrupt', () => {
  it('is claude only, and stays within the screen readers: core reads the screen before the Esc', () => {
    expect(interruptsFromChat('claude')).toBe(true)
    for (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'claude')) expect(interruptsFromChat(id)).toBe(false)
    for (const id of CHAT_INTERRUPT_CAPABLE) expect(readsScreenDialogs(id)).toBe(true)
  })
})

describe('queuesInputWhileWorking — who may be sent to mid-turn from the chat view', () => {
  it('is claude only: every other CLI\'s mid-turn input is unmeasured and may answer what is on screen', () => {
    expect(queuesInputWhileWorking('claude')).toBe(true)
    for (const id of BUILTIN_AGENT_IDS.filter((a) => a !== 'claude')) expect(queuesInputWhileWorking(id)).toBe(false)
  })
})