agent-console 1.3.3: reconnect on return, sidebar dots, permission-wait, chat icon (#760)

qingnian108's follow-up to #747 and #758, on top of 1.3.2.

- A permission request still open when its turn ends is cancelled by the
  daemon (manager and ACP session both), and an ACP request the Agent
  withdraws ($/cancel_request, through the handler's AbortSignal) closes
  as cancelled. The page waits only on cards that still show buttons, so
  a finished turn no longer leaves 等待授权 with nothing to click. The
  等待授权 pill scrolls to the waiting card.
- 添加到对话 uses a speech-bubble icon.
- Sidebar dot: blinks while running, green after a completed turn, red
  on failure, amber while waiting.
- Wrapper: every disconnect / invalid-link end state offers Reconnect;
  the last safe back URL is kept in sessionStorage (safeBack re-checked
  on read). Coming back to the page (visible / focus) probes the child
  for 4 s instead of waiting out timers pushed back while hidden.

Review (head 0c8ee32b): every changed source line read. 1.3.2's Codex
model_catalog_json change is kept (codex/provider.ts untouched, rebuilt
dist still carries it). No new network in tests, page text set through
textContent/React, no new timers in the page or daemon; the wrapper's
sessionStorage back passes the same loopback check (tested with an evil
stored value).

Run (mote, macOS), standalone copy of packages/agent-console:
- npm ci; npm run check OK.
- vitest: 65 files, 489 passed / 17 skipped.
- npm run build, then verify:build: committed app/ and daemon/dist
  identical to the rebuild.
On the PR merged onto main 5026f636: root `bun test
packages/agent-console` 6/6, `bun scripts/check.mjs` exit 0.

Not tried: scripts/e2e-v1.mjs (Playwright, scenario 28), the page with a
live Cursor/Claude/Codex, Windows/Linux.
This commit is contained in:
qingnian108
2026-11-05 18:14:53 +08:00
committed by GitHub
parent 5026f6362e
commit 41e90a18d3
30 changed files with 870 additions and 131 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ export function App() {
return (
<Layout
sidebar={<Sidebar pendingByThread={new Set(pending.map((p) => useTimeline.getState().threadId!).filter(Boolean))} />}
topbar={<Topbar pendingCount={pending.length} />}
topbar={<Topbar pendingCount={pending.length} pendingKey={pending[0]?.key} />}
panel={<Panel />}
>
{state === "reconnecting" && <div className="connbar">{t("boot.reconnecting")}</div>}
@@ -28,6 +28,8 @@ const PATHS: Record<string, string> = {
stopFill: "M8 8h8v8H8z",
shield: "M12 3l8 3v6c0 5-3.5 9-8 11-4.5-2-8-6-8-11V6l8-3z",
quote: "M5 7h5v5H7c0 2 1 3 3 4M14 7h5v5h-3c0 2 1 3 3 4",
// 添加到对话 (selection pop-up): speech bubble + three dots
chat: "M5 5h14v10H9l-4 4V5zM9 10h.01M12 10h.01M15 10h.01",
pencil: "M4 20h4L19 9a2.1 2.1 0 0 0-3-3L5 17v3zM14 7l3 3",
shieldCheck: "M12 3l8 3v6c0 5-3.5 9-8 11-4.5-2-8-6-8-11V6l8-3zM8.5 12.2l2.4 2.4 4.6-4.8",
zap: "M13 2L4 14h7l-1 8 9-12h-7l1-8z",
@@ -124,7 +124,7 @@ export function QuoteSelect() {
onPointerDown={(e) => e.preventDefault()}
onClick={add}
>
<Icon name="quote" size={13} />
<Icon name="chat" size={13} />
<span>{t("quote.add")}</span>
</button>,
document.body,
@@ -6,6 +6,7 @@ import { useUi } from "../stores/ui";
import { ws } from "../main";
import type { Project, ThreadMeta } from "../types/models";
import { relTime } from "../util/format";
import { threadDotClass } from "../util/threadDot";
import { Menu, useMenu, type MenuItem } from "./Menu";
import { Dialog, ConfirmDialog } from "./Dialog";
import { Icon } from "./Icons";
@@ -14,12 +15,7 @@ import { displayThreadTitle, errMsg, t as tr, tf } from "../i18n/index.js";
const THREAD_PAGE = 10;
function dotClass(t: ThreadMeta, pendingIds: Set<string>): string {
if (pendingIds.has(t.id)) return "dot wait";
if (t.status === "running" || t.status === "initializing") return "dot run";
if (t.status === "error" || t.lastTurnStatus === "failed") return "dot err";
return "dot";
}
const dotClass = threadDotClass;
export function Sidebar({ pendingByThread }: { pendingByThread: Set<string> }) {
const { projects, threads } = useData();
@@ -25,7 +25,7 @@ function useNow(running: boolean): number {
return now;
}
export function Topbar({ pendingCount }: { pendingCount: number }) {
export function Topbar({ pendingCount, pendingKey }: { pendingCount: number; pendingKey?: string }) {
const { projects, threads } = useData();
const ui = useUi();
const { version } = useConnection();
@@ -101,7 +101,11 @@ export function Topbar({ pendingCount }: { pendingCount: number }) {
) : (
<span className="tb-title ghost">{project ? t("topbar.pickThread") : t("app.title")}</span>
)}
{pill && <span className={`tb-pill ${pill.cls}`}>{pill.cls === "run" && <span className="tb-pill-dot" />}{pill.text}</span>}
{pill && (pill.cls === "wait" && pendingKey
// 等待授权 brings the card that waits into view (it may be far up a long conversation)
? <button type="button" className={`tb-pill ${pill.cls}`} title={t("topbar.showRequest")}
onClick={() => window.dispatchEvent(new CustomEvent("ac-show-item", { detail: { key: pendingKey } }))}>{pill.text}</button>
: <span className={`tb-pill ${pill.cls}`}>{pill.cls === "run" && <span className="tb-pill-dot" />}{pill.text}</span>)}
<div className="tb-right">
{thread?.model && <span className="tb-model">{thread.model}</span>}
{panelBtns.map((b) => (
@@ -23,7 +23,7 @@ export const messages: Record<LocaleId, MessageTree> = {
},
topbar: {
pickThread: "选择一个对话", sidebar: "侧栏(Ctrl+B)", clickRename: "点击改名",
waitAuth: "等待授权", running: "运行中 {s}s", error: "出错",
waitAuth: "等待授权", showRequest: "查看授权请求", running: "运行中 {s}s", error: "出错",
closedResume: "已关闭 · 发送消息将续接", threadInfo: "对话信息",
panelChanges: "改动(Ctrl+J)", panelFiles: "文件", panelTerminal: "终端",
},
@@ -241,7 +241,7 @@ export const messages: Record<LocaleId, MessageTree> = {
},
topbar: {
pickThread: "Select a conversation", sidebar: "Sidebar (Ctrl+B)", clickRename: "Click to rename",
waitAuth: "Waiting for approval", running: "Running {s}s", error: "Error",
waitAuth: "Waiting for approval", showRequest: "Show the request", running: "Running {s}s", error: "Error",
closedResume: "Closed · send a message to resume", threadInfo: "Conversation info",
panelChanges: "Changes (Ctrl+J)", panelFiles: "Files", panelTerminal: "Terminal",
},
@@ -1,13 +1,13 @@
// Current conversation timeline: threads.get snapshot + thread:<id> channel increments → DisplayItem[].
import { create } from "zustand";
import type { TimelineEvent } from "../timeline/types";
import { applyEvent, newTimelineState, reduceTimeline, type DisplayItem } from "../timeline/reducer";
import { applyEvent, newTimelineState, pendingRequests, reduceTimeline, type DisplayItem } from "../timeline/reducer";
import { ws } from "../main";
import type { SlashCommand } from "../composer/slashMenu";
import { Outbox, newClientId, withOutbox, type SendDisplay, type SendPayload } from "../timeline/outbox";
export type QueueItem = { id: string; text: string; attachments?: { path: string; mime: string }[] };
export type PendingReq = { requestId: string; kind: "permission" | "question" };
export type PendingReq = { requestId: string; kind: "permission" | "question"; key?: string };
type TlStore = {
threadId: string | null;
@@ -92,17 +92,16 @@ export const useTimeline = create<TlStore>((set, get) => {
}
applyEvent(st, ev);
// pending is derived from timeline items (pending permission/question → composer waiting state)
const pending = st.items
.filter((i) => (i.kind === "permission" || i.kind === "question") && i.status === "pending")
.map((i) => ({ requestId: (i as { requestId: string }).requestId, kind: i.kind as "permission" | "question" }));
set({ ...view(threadId), pending });
set({ ...view(threadId), pending: pendingRequests(st.items) });
return;
}
if (data.type === "status" && data.status) {
runtimeStatus = data.status;
if (busyStatus(runtimeStatus) || runtimeStatus === "error" || runtimeStatus === "closed") outbox.busy(threadId);
syncRuntimeFlags();
set(view(threadId));
// Going idle closes the open cards (syncRuntimeFlags): the waiting state follows them, or the top bar would
// keep 等待授权 with no card to click
set({ ...view(threadId), pending: pendingRequests(st.items) });
return;
}
if (data.type === "queue" && data.queue) {
@@ -110,7 +109,8 @@ export const useTimeline = create<TlStore>((set, get) => {
return;
}
if (data.type === "pending" && data.pending) {
set({ pending: data.pending });
// Only requests the timeline shows a live card for
set({ pending: pendingRequests(st.items).filter((p) => data.pending!.some((d) => d.requestId === p.requestId)) });
return;
}
if (data.type === "commands" && data.commands) {
@@ -158,7 +158,9 @@ export const useTimeline = create<TlStore>((set, get) => {
syncRuntimeFlags();
set({
...view(threadId),
queue: g.queue ?? [], pending: g.pending ?? [], lastUserText: r.lastUserText,
// Not g.pending: the daemon's list could hold a request the timeline already closed (a 1.2 daemon kept
// one whose turn had ended). Waiting follows the cards that show buttons.
queue: g.queue ?? [], pending: pendingRequests(st.items), lastUserText: r.lastUserText,
});
// Subscribe only once the snapshot is ready: the server replays events after afterSeq=stSeqMax, joining the snapshot seamlessly
if (get().threadId === threadId) subscribeChannel(threadId);
@@ -122,7 +122,10 @@ textarea.tinput { height: auto; min-height: 60px; padding: 6px 10px; resize: ver
/* Status dot */
.dot { width: 6px; height: 6px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.run { background: var(--accent-2); animation: breathe 1.6s infinite; }
.dot.ok { background: var(--ok); }
/* Running: strong dark<->light blink so it reads at a glance in both themes. */
.dot.run { background: var(--fg); animation: dot-blink 1s steps(1, end) infinite; box-shadow: 0 0 0 1px color-mix(in oklab, var(--fg) 45%, transparent); }
@keyframes dot-blink { 50% { background: var(--bg); } }
.dot.err { background: var(--danger); }
.dot.wait { background: var(--warn); animation: breathe 1.6s infinite; }
@keyframes breathe { 50% { opacity: .35; } }
@@ -66,7 +66,7 @@
.t-item.on::before { content: ""; position: absolute; left: -1px; top: 7px; bottom: 7px; width: 2px; border-radius: 2px; background: var(--accent-2); }
.t-item.archived { opacity: 0.55; }
.t-item.archived .t-title { font-style: italic; }
.t-item .dot { width: 5px; height: 5px; }
.t-item .dot { width: 6px; height: 6px; }
.t-pin { width: 12px; flex: none; display: inline-flex; color: var(--muted); }
.t-pin svg { width: 10px; height: 10px; }
.t-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@@ -124,6 +124,7 @@ body.col-drag iframe, body.col-drag .xterm { pointer-events: none; }
.tb-pill.run { background: var(--run-bg); color: var(--run-fg); }
.tb-pill-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent-2) 20%, transparent); animation: breathe 1.6s infinite; }
.tb-pill.wait { color: var(--warn); }
button.tb-pill { border: 0; font-family: inherit; cursor: pointer; }
.tb-pill.err { color: var(--danger); }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.tb-model { font-size: var(--fs-s); color: var(--muted); margin-right: 4px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
@@ -237,6 +237,8 @@ export function applyEvent(st: State, ev: TimelineEvent): void {
it.status = ev.cancelled ? "cancelled" : "resolved";
it.choice = ev.optionId;
if (ev.auto) it.auto = true;
} else if (it?.kind === "question" && ev.cancelled && it.status === "pending") {
it.status = "cancelled"; // the daemon cancels open questions with permission_resolved{cancelled} too
}
return;
}
@@ -270,6 +272,10 @@ export function applyEvent(st: State, ev: TimelineEvent): void {
return;
case "turn_ended":
breakGroup(st);
// A request still open when its turn ends can't be answered any more: the Agent moved on. Daemons before the fix
// left such a request open in the timeline (Cursor 1.2.0: "[canceled] http/2 stream closed" right after asking),
// and the page kept "等待授权" for a card showing 已取消. Close it here so replayed history never waits on it.
closeOpenRequests(st);
st.items.push({
kind: "turnend", key: `te:${ev.seq}`, status: ev.status,
durationMs: ev.durationMs ?? (st.turnStart.has(ev.turnId) ? Math.max(0, ev.ts - st.turnStart.get(ev.turnId)!) : undefined),
@@ -291,6 +297,28 @@ export function applyEvent(st: State, ev: TimelineEvent): void {
}
}
/** Requests still waiting for the user are always ones whose turn is still running (see turn_ended) */
function closeOpenRequests(st: State): void {
for (const idx of st.reqLoc.values()) {
const it = st.items[idx];
if ((it?.kind === "permission" || it?.kind === "question") && it.status === "pending") it.status = "cancelled";
}
}
export type PendingRequest = { requestId: string; kind: "permission" | "question"; key: string };
/** The requests the page waits on (top bar 等待授权, composer locked): exactly the cards that show buttons, so the
* page never waits on a request it has no card for (the daemon's own list may hold one the timeline already closed) */
export function pendingRequests(items: DisplayItem[]): PendingRequest[] {
const out: PendingRequest[] = [];
for (const it of items) {
if ((it.kind === "permission" || it.kind === "question") && it.status === "pending") {
out.push({ requestId: it.requestId, kind: it.kind, key: it.key });
}
}
return out;
}
// snapshot + live events -> display items. When runtimeStatus is not running, unresolved permissions/questions are marked cancelled.
export function reduceTimeline(
events: TimelineEvent[],
@@ -0,0 +1,17 @@
import { describe, it, expect } from "vitest";
import { threadDotClass } from "./threadDot";
const t = (status: any, lastTurnStatus: any = null, id = "a") => ({ id, status, lastTurnStatus }) as any;
describe("threadDotClass", () => {
it("maps states with priority wait > run > err > ok > idle", () => {
expect(threadDotClass(t("running", "completed"), new Set(["a"]))).toBe("dot wait");
expect(threadDotClass(t("running", "failed"), new Set())).toBe("dot run");
expect(threadDotClass(t("initializing"), new Set())).toBe("dot run");
expect(threadDotClass(t("idle", "failed"), new Set())).toBe("dot err");
expect(threadDotClass(t("error", "completed"), new Set())).toBe("dot err");
expect(threadDotClass(t("idle", "completed"), new Set())).toBe("dot ok");
expect(threadDotClass(t("idle", "interrupted"), new Set())).toBe("dot");
expect(threadDotClass(t("idle", null), new Set())).toBe("dot");
});
});
@@ -0,0 +1,13 @@
import type { ThreadMeta } from "../types/models";
/** Sidebar status dot class. Priority: wait > run > err > ok (completed) > idle grey. */
export function threadDotClass(
t: Pick<ThreadMeta, "id" | "status" | "lastTurnStatus">,
pendingIds: Set<string>,
): string {
if (pendingIds.has(t.id)) return "dot wait";
if (t.status === "running" || t.status === "initializing") return "dot run";
if (t.status === "error" || t.lastTurnStatus === "failed") return "dot err";
if (t.lastTurnStatus === "completed") return "dot ok";
return "dot";
}