Skip to content
Python

Mark every permission-mode change in the transcript

Devika Verma42da42512c3a
diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsx
index 0c56417b..234ebd6e 100644
--- a/surfaces/gui/src/App.tsx
+++ b/surfaces/gui/src/App.tsx
@@ -52,6 +52,7 @@ import { Icon } from "./components/Icon";
import { Sidebar } from "./components/Sidebar";
import { ThinkingBlock, Transcript } from "./components/Transcript";
import { Composer } from "./components/Composer";
+import { modeNotice, type ModeMark } from "./modeNotice";
import { Markdown } from "./components/Markdown";
import { SearchModal } from "./components/SearchModal";
import { SessionIntro } from "./components/SessionIntro";
@@ -117,18 +118,6 @@ function readLastSessions(): Record<string, LastSession> {
}
}
-// Shown once the first time Auto-Approve is active in a session (spec §1.5). Says what the
-// mode buys, what it can never override, and — deliberately unhedged — where it can be
-// wrong. It reduces interruptions, not risk, and the last line has to leave that clear.
-const AUTO_APPROVE_NOTICE = [
- "Your session model lets routine actions through without asking; anything it isn't sure " +
- "about still comes to you — whatever the rules settle outright, it never sees.",
- "It reduces interruptions from lower-risk actions, not the risk from what it can't tell: " +
- "what a script will do, or whether an instruction came from you or from a web page or " +
- "email. Shell commands aren't sandboxed — they reach anything you can. These are model " +
- "judgments, not guarantees — a false allow executes unchecked.",
-].join("\n\n");
-
function rememberLastSession(agent: string, sessionId: string, workspace: string | null) {
if (!agent || !sessionId) return;
try {
@@ -199,10 +188,11 @@ export function App() {
const [streaming, setStreamingState] = useState("");
// Ref mirror of `streaming`: the WS handler closure is built once per socket and can't read
// fresh state — the interrupted/error flush below needs the live buffer at event time.
- // Auto-Approve banner: once per session, however the mode was entered (picked in the
- // composer, applied by a plan approval, or restored with the session). Keyed on the
- // session id, so toggling out and back stays quiet but a new session explains itself.
+ // Mode markers in the transcript: which session has already seen the full Auto-Approve
+ // explanation, and what mode the transcript last recorded (so a switch can be told apart
+ // from a re-render or a session change). See `modeNotice`.
const autoApproveNoticeFor = useRef("");
+ const lastModeMark = useRef<ModeMark>(null);
const streamingRef = useRef("");
const setStreaming = (value: string | ((s: string) => string)) => {
streamingRef.current = typeof value === "function" ? value(streamingRef.current) : value;
@@ -888,12 +878,10 @@ export function App() {
}, [sessionId]);
useEffect(() => {
- if (mode !== "auto-approve" || autoApproveNoticeFor.current === sessionId) return;
- autoApproveNoticeFor.current = sessionId;
- setItems((p) => [
- ...p,
- { kind: "notice", tone: "info", title: "Auto-Approve is on.", text: AUTO_APPROVE_NOTICE },
- ]);
+ const item = modeNotice(mode, sessionId, lastModeMark.current, autoApproveNoticeFor.current);
+ lastModeMark.current = { session: sessionId, mode };
+ if (mode === "auto-approve") autoApproveNoticeFor.current = sessionId;
+ if (item) setItems((p) => [...p, item]);
}, [mode, sessionId]);
useEffect(() => {
if (atBottomRef.current) scrollToBottom();
diff --git a/surfaces/gui/src/components/Composer.tsx b/surfaces/gui/src/components/Composer.tsx
index 568bc393..5596c072 100644
--- a/surfaces/gui/src/components/Composer.tsx
+++ b/surfaces/gui/src/components/Composer.tsx
@@ -50,6 +50,12 @@ const PERMISSION_OPTIONS: ModeOption[] = [
},
];
+/** The picker's label for a mode value ("auto-approve" -> "Auto-Approve"). Exported so the
+ * transcript's mode markers read the same names the user just chose from. */
+export function modeLabel(value: string): string {
+ return PERMISSION_OPTIONS.find((o) => o.value === value)?.label || value;
+}
+
// No hardcoded model fallback: until the server supplies the list (a few seconds after a
// cold app boot), the picker renders a disabled "Loading models…" chip. A baked-in list
// goes stale and silently offers ids the backend never confirmed (caught 2026-07-21).
diff --git a/surfaces/gui/src/components/Transcript.test.tsx b/surfaces/gui/src/components/Transcript.test.tsx
index 758e4233..c477de54 100644
--- a/surfaces/gui/src/components/Transcript.test.tsx
+++ b/surfaces/gui/src/components/Transcript.test.tsx
@@ -332,7 +332,7 @@ describe("mode notice", () => {
];
it("renders the title and one paragraph per blank-line break", () => {
- render(<Transcript items={BANNER} running={false} />);
+ render(<Transcript items={BANNER} running={false} onApprove={() => {}} />);
const block = screen.getByTestId("mode-notice");
expect(block.textContent).toContain("Auto-Approve is on.");
expect(block.querySelectorAll("p")).toHaveLength(2);
@@ -341,7 +341,9 @@ describe("mode notice", () => {
});
it("leaves untitled status notices as plain one-liners", () => {
- render(<Transcript items={[{ kind: "notice", tone: "info", text: "Context compacted" }]} running={false} />);
+ render(
+ <Transcript items={[{ kind: "notice", tone: "info", text: "Context compacted" }]} running={false} onApprove={() => {}} />,
+ );
expect(screen.queryByTestId("mode-notice")).toBeNull();
expect(screen.getByText("Context compacted").className).not.toContain("notice-block");
});
diff --git a/surfaces/gui/src/modeNotice.test.ts b/surfaces/gui/src/modeNotice.test.ts
new file mode 100644
index 00000000..f0b72f31
--- /dev/null
+++ b/surfaces/gui/src/modeNotice.test.ts
@@ -0,0 +1,70 @@
+import { describe, expect, it } from "vitest";
+import { AUTO_APPROVE_NOTICE, modeNotice, type ModeMark } from "./modeNotice";
+
+// The transcript has to answer "which mode was this exchange under?" after the fact. The
+// full explanation is a once-per-session thing; the markers are what make the log readable.
+const S = "session-1";
+const mark = (session: string, mode: string): ModeMark => ({ session, mode });
+
+describe("modeNotice", () => {
+ it("explains Auto-Approve in full the first time a session is in it", () => {
+ const item = modeNotice("auto-approve", S, null, "");
+ expect(item).not.toBeNull();
+ expect(item).toMatchObject({ kind: "notice", tone: "info", title: "Auto-Approve is on." });
+ // The prose, not just the heading — the block layout keys off `title`.
+ expect((item as { text: string }).text).toBe(AUTO_APPROVE_NOTICE);
+ });
+
+ it("marks a switch away from Auto-Approve with one line", () => {
+ const item = modeNotice("discuss", S, mark(S, "auto-approve"), S);
+ expect(item).toMatchObject({ kind: "notice", tone: "info", text: "Discuss is on." });
+ expect(item).not.toHaveProperty("title"); // a marker, not the banner
+ });
+
+ it("marks a switch BACK to Auto-Approve without repeating the explanation", () => {
+ // The reported behaviour: leaving and returning left no trace at all.
+ const item = modeNotice("auto-approve", S, mark(S, "discuss"), S);
+ expect(item).toMatchObject({ text: "Auto-Approve is on." });
+ expect(item).not.toHaveProperty("title");
+ });
+
+ it("uses the picker's own labels, so the transcript names what the user chose", () => {
+ expect(modeNotice("interactive", S, mark(S, "discuss"), S)).toMatchObject({
+ text: "Ask for approval is on.",
+ });
+ expect(modeNotice("auto", S, mark(S, "discuss"), S)).toMatchObject({
+ text: "Bypass approvals is on.",
+ });
+ });
+
+ it("says nothing when the mode has not changed", () => {
+ expect(modeNotice("discuss", S, mark(S, "discuss"), "")).toBeNull();
+ expect(modeNotice("auto-approve", S, mark(S, "auto-approve"), S)).toBeNull();
+ });
+
+ it("says nothing on the first render of a session that is not in Auto-Approve", () => {
+ // No previous mark means nothing to compare against — announcing the starting mode
+ // would put a marker at the top of every transcript.
+ expect(modeNotice("interactive", S, null, "")).toBeNull();
+ });
+
+ it("treats switching sessions as a session change, not a mode change", () => {
+ // Opening another session that happens to be in a different mode must not read as a
+ // switch inside this one.
+ expect(modeNotice("discuss", "session-2", mark(S, "auto-approve"), S)).toBeNull();
+ });
+
+ it("explains again in a new session, since the first banner scrolled away with the old one", () => {
+ const item = modeNotice("auto-approve", "session-2", mark(S, "auto-approve"), S);
+ expect(item).toMatchObject({ title: "Auto-Approve is on." });
+ });
+
+ it("never claims to detect prompt injection", () => {
+ // The copy is load-bearing: the reviewer cannot spot a normalized injection (OPE-114),
+ // so the banner must not imply it does. Guarded here because it is the exact overclaim
+ // the wording was written to avoid.
+ expect(AUTO_APPROVE_NOTICE.toLowerCase()).not.toContain("injection");
+ expect(AUTO_APPROVE_NOTICE).toContain("aren't sandboxed");
+ expect(AUTO_APPROVE_NOTICE).toContain("a false allow executes unchecked");
+ });
+});
diff --git a/surfaces/gui/src/modeNotice.ts b/surfaces/gui/src/modeNotice.ts
new file mode 100644
index 00000000..58045c0f
--- /dev/null
+++ b/surfaces/gui/src/modeNotice.ts
@@ -0,0 +1,55 @@
+// What the transcript records when the permission mode changes.
+//
+// Two different jobs, deliberately: the first time Auto-Approve is active in a session the
+// user gets the full explanation, and every later switch gets a one-line marker. Without
+// the marker a transcript is unreadable after the fact — nothing says which mode any given
+// exchange ran under, and for a tool built on an auditable trail that matters more than the
+// prose does.
+import { modeLabel } from "./components/Composer";
+import type { Item } from "./types";
+
+// Spec §1.5. Says what the mode buys, what it can never override, and — deliberately
+// unhedged — where it can be wrong. It reduces interruptions, not risk, and the closing
+// line has to leave that clear.
+export const AUTO_APPROVE_NOTICE = [
+ "Your session model lets routine actions through without asking; anything it isn't sure " +
+ "about still comes to you — whatever the rules settle outright, it never sees.",
+ "It reduces interruptions from lower-risk actions, not the risk from what it can't tell: " +
+ "what a script will do, or whether an instruction came from you or from a web page or " +
+ "email. Shell commands aren't sandboxed — they reach anything you can. These are model " +
+ "judgments, not guarantees — a false allow executes unchecked.",
+].join("\n\n");
+
+/** The mode the transcript was last showing, per session. */
+export type ModeMark = { session: string; mode: string } | null;
+
+/**
+ * The item a mode change should append, or null when nothing should be said.
+ *
+ * Pure on purpose: the caller owns the refs, so this stays testable without rendering the
+ * app. `bannerShownFor` is the session that has already seen the full explanation.
+ */
+export function modeNotice(
+ mode: string,
+ sessionId: string,
+ previous: ModeMark,
+ bannerShownFor: string,
+): Item | null {
+ // First time this session is in Auto-Approve, however it got there — picked in the
+ // composer, applied by a plan approval, or restored with the session.
+ if (mode === "auto-approve" && bannerShownFor !== sessionId) {
+ return {
+ kind: "notice",
+ tone: "info",
+ title: "Auto-Approve is on.",
+ text: AUTO_APPROVE_NOTICE,
+ };
+ }
+ // A later change WITHIN the same session: mark it, don't re-explain it. Switching
+ // sessions is not a mode change, so it says nothing — otherwise every session you opened
+ // would announce the mode it happened to be in.
+ if (previous && previous.session === sessionId && previous.mode !== mode) {
+ return { kind: "notice", tone: "info", text: `${modeLabel(mode)} is on.` };
+ }
+ return null;
+}