Skip to content

Set TERM_PROGRAM for Agent Host terminals created by VS Code clients - #338612

Merged
Anthony Kim (anthonykim1) merged 4 commits into
mainfrom
anthonykim1/agent-host-terminal-identifier
Sep 29, 2026
Merged

Anthony Kim (anthonykim1) merged 4 commits into
mainfrom
anthonykim1/agent-host-terminal-identifier

Conversation

@anthonykim1

@anthonykim1 Anthony Kim (anthonykim1) commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #338608

  • Add a vscodeTerminalIdentity option to AgentHostTerminalManager.createTerminal that sets TERM_PROGRAM=vscode and TERM_PROGRAM_VERSION to the agent host's product version.
  • Pass the requesting connection's AgentHostClientType from the createTerminal protocol handler to IAgentService.createTerminal.
  • Enable the identity only for known VS Code clients (Editor Window or Agents Window), as identified by clientInfo at initialize.
  • Keep the inherited environment for unknown clients, and for agent tool shells and ! commands, which call the terminal manager directly.
  • Leave attach, reconnect, and ownership transfer unchanged, since they don't spawn a process.
  • Keep the protocol, generated AHP files, and workbench code unchanged; the host decides from existing connection state.

Validation

  • After a one-shot npm run transpile-client, agentHostTerminalManager.test.ts and protocolServerHandler.test.ts pass (192 tests), both with TERM_PROGRAM/TERM_PROGRAM_VERSION unset and with conflicting inherited values.
  • Targeted ESLint on the changed files passed with no warnings.
  • Full typechecking is left to CI.

Manual test

  1. Start the updated build, open the Agents Window, and create a new Agent Host terminal.
  2. Run printf 'TERM_PROGRAM=%s\nTERM_PROGRAM_VERSION=%s\n' "$TERM_PROGRAM" "$TERM_PROGRAM_VERSION".
  3. Verify the output is vscode and the build's version.
  4. Ask the agent to run echo "$TERM_PROGRAM" and verify the tool shell keeps the inherited value.

Inspirations from:

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 04:43
@anthonykim1 Anthony Kim (anthonykim1) added bug Issue identified by VS Code Team member as probable bug terminal General terminal issues that don't fall under another label agents-window agent-host Issues for the agent-host implementation (not the protocol) labels Sep 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The implementation is scoped, backward-compatible, and comprehensively covers the stated terminal lifecycle cases.

Review effort: Balanced
Findings: None

What changed in this PR

Adds client-specific terminal identity metadata so newly created Agent Host terminals receive the correct TERM_PROGRAM values without affecting existing or non-VS Code terminals.

Changes:

  • Sends validated terminal identity metadata during creation.
  • Applies identity variables while preserving unmarked terminal environments.
  • Adds coverage for creation, attachment, reconnection, validation, and alternate clients.
File Description
agentHostTerminalService.test.ts Tests VS Code client identity metadata.
agentHostPty.test.ts Tests creation, attachment, and reconnection behavior.
agentHostTerminalService.ts Supplies the client product version.
agentHostPty.ts Adds identity metadata to creation requests.
agentHostTerminalManager.test.ts Tests validation and environment handling.
agentHostTerminalManager.ts Applies requested identity to spawned terminals.
agentTerminalMeta.ts Defines metadata serialization and validation.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.141.0 milestone Sep 29, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the VS Code-specific createTerminal metadata with the client
identity the host already receives at initialize. createTerminal now
forwards the requesting connection's client context, and terminals
created by VS Code clients get TERM_PROGRAM=vscode and the host's
TERM_PROGRAM_VERSION. Other clients, attachments, and tool shells keep
the inherited environment.
@anthonykim1 Anthony Kim (anthonykim1) changed the title Set terminal identity for Agent Host terminals created from VS Code Set TERM_PROGRAM for Agent Host terminals created by VS Code clients Sep 29, 2026
createTerminal only needs to know whether a VS Code client made the
request, so take AgentHostClientType instead of the full client
telemetry context.
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review September 29, 2026 06:01
@anthonykim1
Anthony Kim (anthonykim1) merged commit 00b318c into main Sep 29, 2026
35 checks passed
@anthonykim1
Anthony Kim (anthonykim1) deleted the anthonykim1/agent-host-terminal-identifier branch September 29, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-host Issues for the agent-host implementation (not the protocol) agents-window bug Issue identified by VS Code Team member as probable bug terminal General terminal issues that don't fall under another label

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Agent Host terminals created from VS Code do not set TERM_PROGRAM

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo