Skip to content

[codex] Merge upstream terminal context and git model updates#23

Merged
aaditagrawal merged 1 commit intomainfrom
codex/upstream-1171-1032
Mar 18, 2026
Merged

[codex] Merge upstream terminal context and git model updates#23
aaditagrawal merged 1 commit intomainfrom
codex/upstream-1171-1032

Conversation

@aaditagrawal
Copy link
Owner

@aaditagrawal aaditagrawal commented Mar 18, 2026

Summary

This merges two upstream changes that were left out previously because of conflicts and adapts them to the fork's current multi-provider direction.

The first upstream change is terminal context support for chat composition and send flow (#1032). Users can now capture terminal output into the composer, persist that context in draft state, render it clearly in the timeline, and send it through the existing composer pipeline. The implementation stays provider-agnostic by attaching terminal context at the web/composer layer rather than relying on any provider-specific runtime behavior.

The second upstream change is configurable git text generation (#1171). Instead of applying the upstream Codex-only model setting directly, this PR adds a provider-aware git text generation override that fits the fork's existing provider/model architecture. Git actions now resolve their model with the following precedence: provider-specific git override, then active thread model, then provider git default. For Codex, the git default uses gpt-5.4-mini, and this PR also adds gpt-5.4-mini to the shared Codex model catalog.

Key Changes

The terminal context work brings over the upstream draft persistence, inline composer chip handling, terminal selection plumbing, and user-message rendering helpers. The two conflict-heavy files were apps/web/src/components/ChatView.tsx and apps/web/src/composerDraftStore.ts; both were merged manually so the new terminal context flow coexists with the fork's current composer state and provider/model selection logic.

The git text generation work adds reusable app-settings helpers for provider-scoped custom model lists and provider-scoped git model overrides. The settings UI now exposes a per-provider git model override selector. GitActionsControl was updated to consume the currently selected provider/model from chat state instead of inferring from a session-only provider, which keeps git generation aligned with the thread the user is actively composing in.

Validation

I ran the required repo checks successfully:

  • bun fmt
  • bun lint
  • bun typecheck

I also ran a targeted web test pass covering the merged and adapted areas:

  • bun --cwd apps/web test src/appSettings.test.ts src/components/ChatView.logic.test.ts src/components/ThreadTerminalDrawer.test.ts src/components/chat/ComposerPendingTerminalContexts.test.tsx src/components/chat/MessagesTimeline.test.tsx src/components/chat/userMessageTerminalContexts.test.ts src/lib/terminalContext.test.ts

Summary by CodeRabbit

  • New Features

    • Added terminal context support: users can now select and insert terminal output directly into chat messages.
    • Introduced per-provider Git text generation model selection in Settings.
    • Terminal contexts display as inline pills in the composer with expiry awareness.
  • Bug Fixes

    • Fixed handling of expired terminal contexts with user warnings.
    • Improved terminal context removal and synchronization.
  • Tests

    • Added comprehensive test coverage for terminal context features and chat functionality.

@github-actions github-actions bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Mar 18, 2026
@aaditagrawal aaditagrawal marked this pull request as ready for review March 18, 2026 09:55
@aaditagrawal aaditagrawal merged commit 984b5ce into main Mar 18, 2026
13 checks passed
@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

@aaditagrawal Sure! I'll start reviewing the PR now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 83bf9d40-ea22-42dd-9fd6-ae02b94a7ba6

📥 Commits

Reviewing files that changed from the base of the PR and between 0eee748 and c81ac7b.

📒 Files selected for processing (34)
  • .gitignore
  • apps/web/src/appSettings.test.ts
  • apps/web/src/appSettings.ts
  • apps/web/src/components/ChatView.browser.tsx
  • apps/web/src/components/ChatView.logic.test.ts
  • apps/web/src/components/ChatView.logic.ts
  • apps/web/src/components/ChatView.tsx
  • apps/web/src/components/ComposerPromptEditor.tsx
  • apps/web/src/components/GitActionsControl.tsx
  • apps/web/src/components/ThreadTerminalDrawer.test.ts
  • apps/web/src/components/ThreadTerminalDrawer.tsx
  • apps/web/src/components/chat/ChatHeader.tsx
  • apps/web/src/components/chat/ComposerPendingTerminalContexts.test.tsx
  • apps/web/src/components/chat/ComposerPendingTerminalContexts.tsx
  • apps/web/src/components/chat/MessagesTimeline.test.tsx
  • apps/web/src/components/chat/MessagesTimeline.tsx
  • apps/web/src/components/chat/TerminalContextInlineChip.tsx
  • apps/web/src/components/chat/userMessageTerminalContexts.test.ts
  • apps/web/src/components/chat/userMessageTerminalContexts.ts
  • apps/web/src/components/composerInlineChip.ts
  • apps/web/src/components/timelineHeight.test.ts
  • apps/web/src/components/timelineHeight.ts
  • apps/web/src/composer-editor-mentions.test.ts
  • apps/web/src/composer-editor-mentions.ts
  • apps/web/src/composer-logic.test.ts
  • apps/web/src/composer-logic.ts
  • apps/web/src/composerDraftStore.test.ts
  • apps/web/src/composerDraftStore.ts
  • apps/web/src/lib/terminalContext.test.ts
  • apps/web/src/lib/terminalContext.ts
  • apps/web/src/routes/__root.tsx
  • apps/web/src/routes/_chat.settings.tsx
  • apps/web/src/vscode-icons.ts
  • packages/contracts/src/model.ts

📝 Walkthrough

Walkthrough

This PR introduces terminal context integration into the chat interface, allowing users to capture and include terminal output inline within messages. It adds a new TerminalContext module with utilities for formatting, extracting, and managing terminal context blocks in prompts. Additionally, it implements per-provider Git text generation model overrides with a three-tier fallback system (explicit override → active thread model → provider default), extending AppSettings with provider-specific model configuration and related helpers.

Changes

Cohort / File(s) Summary
Git Text Generation Model Overrides
packages/contracts/src/model.ts, apps/web/src/appSettings.ts, apps/web/src/appSettings.test.ts
Added DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER constant and gpt-5.4-mini model option; extended AppSettings with gitTextGenerationModelByProvider field and new helpers (getCustomModelsForProvider, patchCustomModels, resolveGitTextGenerationModelSelection) for provider-specific model selection with fallback hierarchy.
Terminal Context Core Module
apps/web/src/lib/terminalContext.ts, apps/web/src/lib/terminalContext.test.ts
New comprehensive module providing TerminalContextDraft, TerminalContextSelection interfaces and utilities for extracting, validating, formatting, and inserting inline terminal context placeholders; includes helpers for deriving displayed message state and parsing context entries.
Terminal Context in Composer Editor
apps/web/src/components/ComposerPromptEditor.tsx, apps/web/src/composer-editor-mentions.ts, apps/web/src/composer-editor-mentions.test.ts, apps/web/src/composer-logic.ts
Extended ComposerPromptSegment union to include terminal-context type; added ComposerTerminalContextNode and decorator for inline token rendering; renamed isCollapsedCursorAdjacentToMention to isCollapsedCursorAdjacentToInlineToken; updated segment parsing and navigation logic to handle terminal context tokens alongside mentions.
Terminal Context Draft Storage
apps/web/src/composerDraftStore.ts, apps/web/src/composerDraftStore.test.ts
Added PersistedTerminalContextDraft interface and terminal context state management (setTerminalContexts, insertTerminalContext, addTerminalContext, removeTerminalContext, clearTerminalContexts); integrated context persistence and hydration; added deduplication and normalization helpers.
Terminal Context in Chat Flow
apps/web/src/components/ChatView.tsx, apps/web/src/components/ChatView.logic.ts, apps/web/src/components/ChatView.logic.test.ts, apps/web/src/components/ChatView.browser.tsx
Integrated terminal context tracking and synchronization into ChatView state; added deriveComposerSendState and buildExpiredTerminalContextToastCopy helpers; extended send flow to build prompts with terminal contexts via appendTerminalContextsToPrompt and show warnings for expired/omitted contexts; updated composer rendering to display terminal contexts conditionally.
Terminal Context UI Components
apps/web/src/components/chat/MessagesTimeline.tsx, apps/web/src/components/chat/ComposerPendingTerminalContexts.tsx, apps/web/src/components/chat/TerminalContextInlineChip.tsx, apps/web/src/components/chat/userMessageTerminalContexts.ts, apps/web/src/components/chat/userMessageTerminalContexts.test.ts, apps/web/src/components/chat/ComposerPendingTerminalContexts.test.tsx, apps/web/src/components/chat/MessagesTimeline.test.tsx
Added new components (ComposerPendingTerminalContextChip, ComposerPendingTerminalContexts, TerminalContextInlineChip) for rendering inline terminal context tokens; implemented message state derivation and inline label formatting utilities; updated MessagesTimeline to render user message body with embedded terminal context labels.
Terminal Drawer Enhancement
apps/web/src/components/ThreadTerminalDrawer.tsx, apps/web/src/components/ThreadTerminalDrawer.test.ts
Added terminal text selection detection and "Add to chat" action menu; introduced resolveTerminalSelectionActionPosition, terminalSelectionActionDelayForClickCount, and shouldHandleTerminalSelectionMouseUp utilities for positioning and timing selection actions; extended props to include onAddTerminalContext callback.
Git Model Selection UI
apps/web/src/components/GitActionsControl.tsx, apps/web/src/components/chat/ChatHeader.tsx
Updated GitActionsControl to accept provider and model props and compute gitTextGenerationModel via resolveGitTextGenerationModelSelection; extended ChatHeader props to pass gitProvider and gitModel through component hierarchy.
Settings and Configuration
apps/web/src/routes/_chat.settings.tsx, apps/web/src/vscode-icons.ts, apps/web/src/composerInlineChip.ts
Added Git section UI in settings for per-provider model override configuration; introduced inferEntryKindFromPath utility for path classification; extracted composerInlineChip styling constants for reuse across inline token components.
Timeline Height Calculation
apps/web/src/components/timelineHeight.ts, apps/web/src/components/timelineHeight.test.ts
Updated message height estimation to account for terminal context chrome by deriving displayed message state and combining inline terminal context text with visible text in line wrapping calculations.
Configuration and Root Route
.gitignore, apps/web/src/routes/__root.tsx
Added .vitest-\* pattern to .gitignore; simplified RootRouteView useEffect dependency from individual properties to entire settings object.

Sequence Diagram

sequenceDiagram
    actor User
    participant Terminal as Terminal Drawer
    participant Selection as Selection Handler
    participant ChatView as Chat View
    participant Store as Draft Store
    participant Composer as Composer Editor
    participant Server as Server

    User->>Terminal: Selects text in terminal
    Terminal->>Selection: Detects selection
    Selection->>Selection: Resolve position & timing
    Terminal->>ChatView: Calls onAddTerminalContext(selection)
    ChatView->>Store: insertTerminalContext(context)
    Store->>Store: Deduplicate & normalize
    ChatView->>Composer: insertInlineTerminalContextPlaceholder
    Composer->>Composer: Create token, update state
    Composer->>ChatView: Report terminalContextIds
    ChatView->>Composer: Render terminalContexts
    Composer->>User: Display inline context pills
    User->>Composer: Modifies message text
    ChatView->>ChatView: deriveComposerSendState
    User->>ChatView: Clicks Send
    ChatView->>ChatView: appendTerminalContextsToPrompt
    ChatView->>Server: Send message with contexts
    Server->>Server: Process terminal contexts
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • #2 — Touches provider/model configuration in MODEL_OPTIONS_BY_PROVIDER and DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER constants
  • #5 — Modifies provider/model selection and git-related settings integration (ChatHeader, GitActionsControl, settings UI)
  • #4 — Changes provider/model inference logic and DEFAULT_GIT_TEXT_GENERATION_MODEL_BY_PROVIDER usage across components

Poem

🐰 hop hop Terminal texts now float in chat so bright!
Inline pills and context blocks—a composer's delight!
Provider defaults dance with override care,
From selection to send, terminal contexts everywhere! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/upstream-1171-1032
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant