Intelligent Terminal

repository·main·Indexed 23 days ago

https://github.com/microsoft/intelligent-terminal

An experimental fork of Windows Terminal featuring native integration with AI agents via the Agent Client Protocol (ACP). It allows users to interact with agents, such as GitHub Copilot, that have direct context of terminal state and shell output. The repository also includes the base/numerics C++ library for safe, performant numeric operations, providing CheckedNumeric, ClampedNumeric, and StrictNumeric templates for overflow detection and saturating arithmetic.

Tokens
182.1K
Snippets
268
Records
822
Agent score
80%

What's inside Intelligent Terminal

  1. Overview of base/numerics library

    main

    The base/numerics library is a dependency-free, header-only C++ library providing templates for safe and performant numeric operations and conversions. It is organized into several specialized headers:

    • checked_math.h: Provides CheckedNumeric for arithmetic and conversions that detect errors like overflow or truncation.
    • clamped_math.h: Provides ClampedNumeric for fast, non-sticky saturating (clamped) arithmetic.
    • safe_conversions.h: Provides StrictNumeric and various casting templates for safe type conversions.
    • safe_math.h: A convenience header that includes all the above.

    Type Coercion Priority: When using these types, they implicitly convert from standard C numeric types. The coercion priority is:

    1. StrictNumeric $\rightarrow$ ClampedNumeric $\rightarrow$ CheckedNumeric.
  2. Understand the Windows Terminal v1.0 Roadmap and Milestones

    main

    The Windows Terminal project follows a 4-week milestone cycle to deliver updates:

    • Weeks 1-2 (Dev Work): Focuses on features and fixes for Windows releases and the Terminal itself. Internal self-hosters receive releases at the end of week 2.
    • Week 3 (Quality & Stability): Focuses on bug fixes, performance, stability, UI polish, and testing. Updates are pushed to the Microsoft Store at the end of week 3.
    • Week 4 (Release): Final release is made available via the Microsoft Store and GitHub Releases on the Tuesday of the 4th week. This phase includes documentation, community engagement, and planning for future milestones.

    Users are encouraged to report bugs to help drive the quality-oriented v1.0 release.

  3. Elevation Quality of Life Improvements in Intelligent Terminal

    main

    To improve the user experience when working with elevated (administrator) permissions, the terminal provides several features to manage elevation levels without supporting unsafe 'mixed elevation' (running elevated and unelevated tabs in the same window).

    Key features include:

    • Visible indicators: A visual cue that the current terminal window is running in an elevated state.
    • Always-run elevated: Configuration options to ensure the entire Terminal application runs elevated.
    • Profile-specific elevation: Configuration to ensure a specific profile (e.g., PowerShell or Command Prompt) always opens in an elevated state.
    • Direct elevation: The ability to open new tabs or panes directly in an elevated state from an existing unelevated window.
    • Dynamic appearance: Profile appearances that change based on whether the terminal is currently elevated.
  4. What is shell integration and why is it required?

    main

    Shell integration is a mechanism that teaches your shell to emit OSC 133 marks after every prompt. Intelligent Terminal uses these marks to detect command boundaries and exit codes.

    This integration is essential for the following features:

    • Auto-fix: Automatically detecting and proposing fixes for failed commands.
    • Command navigation: Navigating through command history.
    • Agent state: Powering the status information in the bottom-bar agent.

    Without these marks, Intelligent Terminal cannot determine when a command has finished or whether it succeeded or failed.

  5. What is Quake Mode in Intelligent Terminal

    main
    Quake Mode is a feature that allows users to summon their terminal window from anywhere in the OS using a global hotkey. This is typically accompanied by a "dropdown" animation where the window slides in from the top of the screen, similar to the console in the game Quake. The feature aims to provide quick, unobtrusive access to the terminal without needing to manually switch windows via Alt+Tab.
  6. What is the Suggestions UI in Windows Terminal

    main

    The Suggestions UI is an ephemeral, Intellisense-like interface within Windows Terminal that appears at the point of text insertion. It provides actionable UI elements to the user based on the current context, helping to provide immediate content suggestions.

    It serves as a unified interface for various suggestion sources, including:

    • Recent commands: Powered by shell integration.
    • Recent directories: Powered by shell integration.
    • Shell completions: Native completions from the shell (e.g., PowerShell).
    • Tasks: sendInput actions defined in user settings.
    • Buffer Completions: Autocomplete based on words currently in the buffer.
    • Extensions: Custom suggestion sources provided via extensions.
  7. How WSL Agent Sessions work

    main

    WSL sessions are managed through a hybrid mechanism where the host (Windows) maintains the parsing logic, but the data is fetched from within the Linux distribution.

    Key Concepts:

    • Scanning: The system scans only running distributions at startup to avoid the multi-second delay of auto-booting stopped distros.
    • Data Fetching: The host uses a hybrid approach where the distro fetches bytes (via a tar extraction process) and the host performs the parsing. This ensures that Linux file paths and metadata (like mtimes) are correctly interpreted.
    • Display: WSL rows in the session view are prefixed with a short distro tag (e.g., Ubuntu ) to distinguish them from host sessions.
    • Liveness Limitations: The WSL session list is a one-time snapshot taken at startup. It does not reflect new sessions created inside WSL after the application has started, nor does it show live status (Working/Idle/Attention) for WSL rows.
  8. Understand the Tab Tear-off and Merge UX design

    main

    The Tab Tear-off feature is designed to allow users to move tabs out of the current Windows Terminal (wt.exe) instance into a new window or merge them into an existing instance, similar to a web browser.

    Simplified V1 Behavior

    In the initial implementation, the transfer of a tab is not live but occurs upon release:

    • Reordering: If a tab is dragged and released onto a different position on the same wt.exe tab bar, the tabs are simply reordered.
    • Merging: If a tab is released onto the tab bar of a different running wt.exe instance, the IPC manager relays the communication channel and details to the destination instance. The tab opens in the destination instance, and the source instance closes the tab.
    • New Window: If a tab is released anywhere that is not an existing wt.exe instance, a new wt.exe instance is created, and the connection is sent as the default startup parameter.
  9. BackendD3D Rendering Pipeline

    main

    The BackendD3D implementation is the primary high-performance renderer. It implements the IBackend::Render entrypoint. The rendering process follows a specific sequence of internal function calls:

    1. _handleSettingsUpdate: Processes changes in settings.
      • Font changes trigger _updateFontDependents and _d2dRenderTargetUpdateFontSettings.
      • Miscellaneous changes trigger _recreateCustomShader and _recreateCustomRenderTargetView.
      • Size changes trigger _recreateBackgroundColorBitmap.
      • Other changes trigger _recreateConstBuffer and _setupDeviceContextState.
    2. _drawBackground: Handles background rendering by calling _uploadBackgroundBitmap.
    3. _drawCursorPart1: Runs before text rendering to draw cursors behind the text.
    4. _drawText: The core text rendering logic.
    5. _drawCursorPart2: Runs after text rendering to draw inverted cursors.
    6. _drawSelection: Handles selection rendering.
    7. _handleSettingsUpdate (Post-render): Executes custom shaders via _executeCustomShader.
  10. Visual Indicators for Selection (Selection Markers)

    main

    The terminal uses specific visual markers to indicate selection state and active endpoints:

    • Y-Beam: Used in standard line selection mode. A full y-beam appears at the cursor when entering mark mode from a single point. When holding <kbd>shift</kbd> to expand a selection, the y-beam is split, and the relevant half acts as a marker for the active endpoint.
    • Flipped Markers: If a selection endpoint hits the beginning or end of a line, the marker is horizontally flipped. If the active endpoint crosses the inactive endpoint, the marker flips to always point away from the selection.
    • L-Shaped Marker: Used for block selections instead of a y-beam. This marker hugs the corner of the active selection endpoint.
    • Cursor Behavior: When markMode is enabled, the cursor stops blinking.
  11. Understand the ACP 1.0 Proxy/Conductor model

    main

    The ACP 1.0 architecture moves away from monolithic reactors toward a model of composable transform proxies managed by a Conductor.

    Core Abstractions

    • Proxies: Standalone, reorderable components (e.g., autofix, context, recommendation) that perform 1:1 ACP transforms. They are chained via _proxy/initialize and _proxy/successor methods. Some proxies are thin enough to be 'absorbed' into neighbors (e.g., model-pinning into the context proxy).
    • Conductor: A library-managed component that orchestrates the session lifecycle. It uses a builder pattern to define how sessions are created and how proxies are inserted into the chain.
    • N:1 Multiplexer (WTA Master): While the Conductor handles linear 1:1 chains (Client $\rightarrow$ Conductor $\rightarrow$ Agent), the Intelligent Terminal (WTA) requires an N:1 topology where multiple helper panes share a single Agent CLI. The WTA master acts as a specialized conductor that manages this multiplexing and the overall WTA lifecycle (spawn, pipe discovery, routing).