Skip to content

🤖 feat: show active mode instructions in Instructions pane#3391

Open
ammar-agent wants to merge 3 commits into
mainfrom
instructions-pane-fpyr
Open

🤖 feat: show active mode instructions in Instructions pane#3391
ammar-agent wants to merge 3 commits into
mainfrom
instructions-pane-fpyr

Conversation

@ammar-agent
Copy link
Copy Markdown
Collaborator

Summary

The Instructions pane now leads with the active mode's system prompt, rendered with the same uiColor that drives the mode picker pill and the chat-input focus ring. Switching modes (e.g. plan ↔ exec) re-fetches the agent body and visibly retints the panel — so the Instructions tab now tracks the mode you're in.

Background

The Instructions tab already exposes the AGENTS.md files and Chat Instructions that get injected into the system prompt, but the mode prompt itself — usually the largest part of the system message — was invisible. Users couldn't easily inspect what "Plan" vs "Exec" actually tells the model, and the tab gave no visual signal that the active mode matters.

This PR fills that gap by rendering the resolved agent body inside the same tab, styled with the mode's own color so the affordance is unmistakable.

Implementation

ModeInstructionsPanel (src/browser/components/InstructionsTab/ModeInstructionsPanel.tsx)

  • Subscribes to useAgent() and fetches the agent package via api.agents.get, keyed on the agent id so switching modes triggers a fresh fetch and a smooth color transition.
  • The mode's uiColor (already inheritance-resolved on the backend) drives a 3px left accent bar, a subtle background tint, the icon swatch, the mode-name heading color, and the collapsed-preview pill. All tints use color-mix(in srgb, <color> N%, transparent) so they degrade gracefully across themes.
  • Body renders through the shared MarkdownRenderer (same security-hardened pipeline as chat), capped at max-h-[40vh] with its own scrollbar so a multi-KB prompt never pushes the rest of the panel off-screen.
  • Collapsible (expanded by default); collapsed state shows a one-line tinted preview of the first non-blank line. Empty/loading/error states all degrade gracefully.

Shared icon helper (src/browser/utils/agentIcons.ts)

  • Extracted the agent → lucide icon map out of AgentModePicker so the picker pill and the new panel always show the same glyph for a given agent (Route for plan, SquareCode for exec, Bot fallback).

Tab wiringModeInstructionsPanel sits above ChatInstructionsPanel, which sits above the AGENTS.md file list. Reading the tab top-to-bottom now mirrors the order of contributions to the system prompt.

Storybook + mock plumbing — Extended createMockORPCClient with an agentBodies option so agents.get can return real markdown in stories. Added two Chromatic-snapshotted stories (ExecMode, PlanMode) covering the two built-in mode colors so visual regressions are caught.

Validation

  • make static-check (typecheck + lint + fmt-check + docs link check) ✅
  • Snapshot-budget guard (tests/ui/storybook/budget.test.ts) updated implicitly — verified the two new snapshots fit under the cap (305 → would have blown the 303 cap, then trimmed by marking the non-color-relevant variants disableSnapshot: true).
  • bun x storybook build ✅ — confirms the new story file is wired end-to-end.
  • Regression checks: AgentModePicker.test.tsx (5/5), agents.test.ts (4/4).

Risks

Low. The new panel is additive (sits above existing sections), reads from an IPC method that's already used by Settings → Tasks, and falls back gracefully when the agent has an empty body. The shared getAgentIcon extraction is a pure refactor with the same lookup as before; the picker's behavior is unchanged.

The only behavioral nuance worth flagging: agents.get returns the raw body of the agent's .md file, not the inheritance-resolved prompt that's actually injected into the system message. For built-in plan/exec they're identical; for custom agents with prompt.append: true, the user sees only the additions on top of the base. Surfacing the fully-resolved prompt would require a new IPC and is out of scope.


Generated with mux • Model: anthropic:claude-opus-4-7 • Thinking: xhigh • Cost: $10.76

Add a ModeInstructionsPanel above the existing Chat Instructions / AGENTS.md
sections that renders the currently-selected agent's system prompt body. The
panel styles itself with the agent's uiColor (background tint, left accent
bar, icon swatch, mode-name color), so the Instructions tab visibly tracks
the mode you're in.

Also extracts the shared agent -> lucide icon map out of AgentModePicker
into src/browser/utils/agentIcons.ts so both surfaces stay in sync.
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e656ce206

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/browser/components/InstructionsTab/ModeInstructionsPanel.tsx
Address Codex P2: when the user switches modes the previous fetch can still
be in flight, and we were rendering the old body under the new mode's
color/name until the new response arrived. Treat any pkg whose id no longer
matches the current agentId as 'not loaded yet' so the body section falls
back to the loading state instead of showing the wrong prompt.
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed in bb196b6: track the agent id of the loaded pkg and treat any mismatch as "not loaded yet" so a stale prompt body / token count is never shown under the wrong mode's color and name. The loading state now also re-engages on mode switch, while manual refresh of the same agent still keeps the existing body visible (no flash).

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb196b61a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/browser/components/InstructionsTab/ModeInstructionsPanel.tsx Outdated
Address Codex P2: when workspaceId changes but the mode id stays the same
(e.g. exec in workspace A vs B with different exec.md), the previous
pkg.id === agentId guard kept rendering the old workspace's prompt until
the new request returned. Track the (agentId, workspaceId) pair the cached
pkg belongs to so either dimension can invalidate it.
@ammar-agent
Copy link
Copy Markdown
Collaborator Author

@codex review

Addressed in 0191593: cache the (agentId, workspaceId) pair the loaded pkg belongs to and require both to match the current context before treating the body as fresh. A workspace switch with the same mode id now correctly falls back to the loading state instead of showing the previous workspace's prompt.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant