Skip to content

feat(agents): route child replies to the initiating tab across CLI, MCP, and split panes - #470

Merged
simion merged 2 commits into
simion:mainfrom
nvkvin:feature/inter-agent-communication
Nov 26, 2026
Merged

simion merged 2 commits into
simion:mainfrom
nvkvin:feature/inter-agent-communication

Conversation

@nvkvin

@nvkvin nvkvin commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

When a parent task has multiple agents running (either in multiple tabs or split panes) and spawns a child task in another project, an unqualified reply from the child (termic send <parent> or MCP task_send without tab) previously routed to the parent task's is_default tab (or single active agent) instead of the agent tab that spawned the child.

This adds end-to-end tab lineage tracking (spawned_by_tab via $TERMIC_TAB_ID / X-Termic-Tab), extends exact tab-ID targeting to split-pane agents across CLI and MCP, updates agent briefings/instructions/skills to carry tab identity, and hardens spawn/resume tab selection in the store RPC bridge.

What changed

  • Tab lineage persistence & protocol (termic-proto, termic-server, src-tauri/src/lib.rs, src-tauri/src/peers.rs):
    • Bumped PROTOCOL_VERSION to 27, adding parent_tab to Command::New, caller_task to Command::Send, and spawned_by_tab to TaskSummary and Task.
    • Extended task_link_spawn / apply_spawn_link to record spawned_by_tab alongside spawned_by.
    • Forwarded parentTabId on CLI/MCP task creation so the store writes lineage atomically.
  • Unqualified child reply routing & split-pane addressing (src-tauri/src/cli_server.rs, src/lib/cliRpc.ts, src/lib/cliAgentState.ts):
    • Published split-pane agent tabs via optional pane_tab_states alongside strip tab_states (preserving strip-tab indices, title lookups, tab close, and tab rename).
    • Allowed exact tab IDs to resolve split-pane tabs for agent state, prompt delivery (send), log reading, PTY attach, and prop reads/writes (handle_prop).
    • For child-to-parent replies without an explicit --tab, handle_send forwards the raw stored spawned_by_tab as preferredTabId without eagerly rewriting or falling back to a sibling title match; sendPromptHandler routes to that tab when live and falls back cleanly to is_default when closed/dead.
    • Locked spawn delivery (waitForAgentPty + injectPromptTracked) onto a single resolved targetTabId, returning { mode, capable, tabId } accurately.
    • Restored closed durable main agents on non-agent strips via shared tabFromPersisted (in src/store/app.ts) to preserve original tab IDs, CLI, and sessions without duplicating defaults or leaving an unconsumed markUnattendedSpawn marker behind.
  • MCP headers, tool schemas, and upgrade notice (src-tauri/src/mcp_server.rs, src/components/settings/McpSection.tsx, locales):
    • Added X-Termic-Tab (MCP_TAB_HEADER) to the shell header helper and termic mcp-headers, plus claude_needs_update / codex_needs_update detection with an upgrade prompt banner in Settings -> MCP (mcp.needsTabUpdate).
    • Defaulted parentTab (same-task only for task_new/task_review), caller_task (task_send), and bare task_prop writes from X-Termic-Tab; accepted explicit parentTask/parentTab on task_review; scoped P_TAB help to selector rules and documented per-tool omitted-tab behavior on task_send, task_wait, and task_log.
  • Briefings, skill, CLI help & docs (src/lib/agentBriefing.ts, termic-cli, src-tauri/assets/skills/termic/, docs/):
    • Included optional tab:<id> in bilateral agent message headers and single-line TERMIC_TAB_ID report-back flags in prompt templates/briefings, paired-machine instructions, CLI help (new, send, wait, attach, logs), and reference docs.

Testing

  • Vitest:
    • Focused suites (src/lib/agentBriefing.test.ts, src/lib/cliAgentState.test.ts, src/store/cliSend.integration.test.ts, src/store/cliTabProps.integration.test.ts, src/store/resume.integration.test.ts, src/store/app.test.ts): 6 files, 235 passed (added 12 new tests across briefing formatting, split-pane state/props, preferredTabId routing, spawn lock-in, and non-agent-strip durable resume).
    • Full npm test: 255 of 256 files passed (3959 of 3961 tests); the only failure is pre-existing upstream e2e/fixedWaits.test.ts on untouched e2e/specs/peers.e2e.ts lines 947 and 971.
  • Rust (cargo test):
    • cargo test --workspace --lib --manifest-path src-tauri/Cargo.toml: passed (termic_lib: 1770 passed / 8 ignored; termic_cli: 98 passed; termic_proto: 29 passed; termic_remote: 73 passed).
    • Earlier cargo test --workspace --manifest-path src-tauri/Cargo.toml (before the final TypeScript-only fix, with zero Rust changes afterward): passed all crates including termic_server (17 unit + 8 e2e).
  • Build & static checks: npm run build (tsc -b && vite build), npm run typecheck:e2e, and git diff --check all passed after the final edit.

@simion

simion commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Looks correct and safe to merge, lineage threading and the trust boundary on the tab id both check out. One nit: if the initiating split-pane agent has since exited, sendPromptHandler silently falls back to the default strip tab because mainPersistedAgents excludes pane tabs, worth a test or a note in the task_send description.

Thanks for the contribution!
— Simion's agent here, he'll take a look at this shortly.

@nvkvin

nvkvin commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 64336c9:

  • Documented the exited split-pane fallback behavior on task_send in src-tauri/src/mcp_server.rs (with RECORDED updated to 31360).
  • Added two integration tests in src/store/cliSend.integration.test.ts covering both an exited split-pane preferredTabId falling back to the live default strip tab and resume excluding persisted split-pane entries in favor of the default strip tab.

@simion simion left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix, nice job tracing the lineage through CLI, MCP, and split panes consistently. Thanks for the thorough testing writeup.

@simion
simion merged commit f712d9c into simion:main Nov 26, 2026
4 of 7 checks passed
simion added a commit that referenced this pull request Nov 26, 2026
#470 deliberately signs the copied briefing with the sending tab
(`${TERMIC_TAB_ID:+ tab:$TERMIC_TAB_ID}`) so a reply comes back to it,
and the task spec still expected the old signature on every platform.

Refs #470

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018opNL4DeF5MZjpvmckKSwo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants