Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/saved-assistant-history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sapiom/harness": patch
---

Show retained Assistant history in Studio's existing session history, including sessions with no Terminal.
8 changes: 8 additions & 0 deletions packages/harness/docs/assistant-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ so a successful GET can return an older `capturedAt`. Disposal and authority los
cancel capture; opening a retained record never resumes execution.
# Selected native availability

Open an Assistant entry from Studio's existing session history to read its saved
messages and tool excerpts. Mixed Terminal and Assistant entries are grouped by
Studio session ID. Sessions that have never started a Terminal remain visible.
The pane labels reconstructed, shortened and incomplete content, supports Back,
and discards results after an account, project or navigation change. Viewing a
record starts no native runtime. Native availability and Resume are separate
explicit actions.

Native inspection is explicit and separate from metadata listing. It validates
the authorized saved Studio/native association, reads only that native session
and its bounded history, and checks the saved execution context through the
Expand Down
238 changes: 238 additions & 0 deletions packages/harness/web/e2e/assistant-history.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
import { expect, test, type Page, type Route } from "@playwright/test";
import type { AssistantHistoryEntry } from "../../src/shared/assistant-history";

const cwd = "/Users/demo/acme-app";
const entry = (id: string): AssistantHistoryEntry => ({
kind: "assistant",
harnessSessionId: id,
title: `Saved ${id}`,
cwd,
createdAt: "2026-01-01T00:00:00.000Z",
updatedAt: "2026-09-14T00:00:00.000Z",
lifecycle: {
version: 1,
harnessSessionId: id,
revision: 2,
lifecycle: "ended",
execution: "paused",
updatedAt: 2,
},
history: "partial",
nativeResume: "unchecked",
recordRevision: 1,
});
const record = (id: string) => ({
schemaVersion: 1,
reconstructed: true,
revision: 1,
binding: {
harnessSessionId: id,
cwd,
conversationId: `ses_${id}`,
contextAuthorityScope: "PRIVATE_SCOPE",
},
capturedAt: "2026-09-14T00:00:00.000Z",
turnCount: 1,
messageCount: 2,
limitations: ["field-truncation", "attachment-content-omitted"],
turns: [
{
id: "user1",
incomplete: true,
acceptedContext: { hidden: "PRIVATE_CONTEXT" },
messages: [
{
id: "user1",
role: "user",
parentId: null,
createdAt: 1,
completedAt: null,
parts: [
{
id: "p1",
type: "text",
text: "Read the README",
truncated: false,
},
],
},
{
id: "answer1",
role: "assistant",
parentId: "user1",
createdAt: 2,
completedAt: 3,
parts: [
{
id: "p2",
type: "text",
text: `Saved answer ${id}`,
truncated: false,
},
{
id: "p3",
type: "tool",
callId: "call1",
name: "read",
status: "completed",
input: "README.md",
output: "A recorded excerpt",
error: null,
startedAt: 2,
completedAt: 3,
truncated: true,
},
],
},
],
},
],
});
const publish = (page: Page, message: unknown) =>
page.evaluate(
(message) => (window as any).__HARNESS_TEST__.publish(message),
message,
);
const authority = (page: Page, revision: number, key = "account-a") =>
publish(page, {
type: "assistant.state",
snapshot: {
hostInstanceId: "history-host",
authorityRevision: key,
revision,
enabled: true,
sessions: [],
lifecycles: [],
},
});
const rows = async (page: Page) => {
await page.getByTestId("history-trigger").click();
await page.getByTestId("past-sessions-trigger").hover();
};
async function setup(page: Page, mode = "valid") {
const probe = {
calls: [] as string[],
holdList: false,
holdRecord: false,
lists: [] as Route[],
records: [] as Route[],
};
await page.route("**/api/sessions/assistant-history?**", (route) => {
if (new URL(route.request().url()).searchParams.get("cwd") !== cwd)
return route.fulfill({ json: { entries: [] } });
if (probe.holdList) {
probe.lists.push(route);
return;
}
return route.fulfill({
json: { entries: [entry("assistant-only"), entry("sess-leasing")] },
});
});
await page.route("**/api/sessions/*/assistant/record", (route) => {
if (probe.holdRecord) {
probe.records.push(route);
return;
}
const id = new URL(route.request().url()).pathname.split("/")[3]!;
return route.fulfill({
status: mode === "missing" ? 404 : 200,
json: { record: record(mode === "foreign" ? "another-studio" : id) },
});
});
page.on("request", (request) => {
if (
/^\/opencode\/|\/assistant\/(inspect|resume|continue)$/.test(
new URL(request.url()).pathname,
)
)
probe.calls.push(request.url());
});
await page.goto("/?seed=0");
await expect(page.locator(".harness-terminal")).toBeVisible();
await authority(page, 1);
return probe;
}

test("groups mixed records by Studio ID and reads pure Assistant history without native work", async ({
page,
}, testInfo) => {
const probe = await setup(page);
await rows(page);
await expect(
page.getByTestId("assistant-history-sess-leasing"),
).toContainText("Terminal + Assistant");
await expect(page.getByTestId("exited-session-sess-leasing")).toHaveCount(0);
await expect(page.getByTestId("exited-session-sess-pricing")).toBeVisible();
await page.getByTestId("assistant-history-assistant-only").click();
const pane = page.getByTestId("assistant-history-pane");
await expect(pane).toHaveAttribute("data-session-id", "assistant-only");
await expect(pane).toContainText("Saved answer assistant-only");
await expect(pane).toContainText("Reconstructed");
await expect(pane).toContainText("Attachment contents are not saved");
await expect(pane).toContainText("Turn incomplete when recorded");
await pane.locator("summary").click();
await expect(pane).toContainText("A recorded excerpt");
await expect(pane).not.toContainText("PRIVATE_");
await expect(
pane.getByRole("button", { name: /Resume|Continue|New session/ }),
).toHaveCount(0);
await page.screenshot({ path: testInfo.outputPath("assistant-record.png") });
await pane.getByRole("button", { name: "Close" }).click();
await page.getByRole("button", { name: "Go back" }).click();
await expect(pane).toContainText("Saved answer assistant-only");
expect(probe.calls).toEqual([]);
});

for (const mode of ["missing", "foreign"]) {
test(`${mode} saved record never becomes a fabricated conversation`, async ({
page,
}) => {
const probe = await setup(page, mode);
await rows(page);
await page.getByTestId("assistant-history-assistant-only").click();
await expect(page.getByTestId("assistant-history-pane")).toContainText(
mode === "missing"
? "No Assistant conversation was recorded"
: "Assistant history is unavailable",
);
await expect(page.getByText("Saved answer another-studio")).toHaveCount(0);
expect(probe.calls).toEqual([]);
});
}

test("late history and record reads cannot cross account or navigation barriers", async ({
page,
}) => {
const probe = await setup(page);
probe.holdList = true;
await rows(page);
await expect.poll(() => probe.lists.length).toBe(1);
await authority(page, 2, "account-b");
await probe.lists[0]!.fulfill({ json: { entries: [entry("old-account")] } });
await expect(
page
.getByTestId("past-sessions-card")
.getByText("Loading…", { exact: true }),
).toHaveCount(0);
await expect(
page.getByText("Saved old-account", { exact: true }),
).toHaveCount(0);
await page.keyboard.press("Escape");
probe.holdList = false;
probe.holdRecord = true;
await rows(page);
await page.getByTestId("assistant-history-assistant-only").click();
await expect.poll(() => probe.records.length).toBeGreaterThan(0);
await page
.getByTestId("assistant-history-pane")
.getByRole("button", { name: "Close", exact: true })
.click();
await Promise.all(
probe.records.map((route) =>
route.fulfill({ json: { record: record("assistant-only") } }),
),
);
await expect(page.getByTestId("assistant-history-pane")).toHaveCount(0);
await expect(page.getByText("Saved answer assistant-only")).toHaveCount(0);
expect(probe.calls).toEqual([]);
});
55 changes: 50 additions & 5 deletions packages/harness/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ import { TelemetryNotice } from "./components/TelemetryNotice";
import { TemplatesPanel } from "./components/TemplatesPanel";
import { Terminal } from "./components/Terminal";
import { AssistantPane } from "./components/AssistantPane";
import { AssistantHistoryPane } from "./components/AssistantHistoryPane";
import type { AssistantHistoryEntry } from "../../src/shared/assistant-history";
import type { ChatDraftStore } from "./components/OpenCodeChat";
import { Toast } from "./components/Toast";
import { TooltipLayer } from "./components/TooltipLayer";
Expand Down Expand Up @@ -731,9 +733,18 @@ export const App = (): JSX.Element => {
// A PAST session under review: picked from the history menu, shown
// in the terminal slot as a review pane — resuming/starting is the pane's
// explicit action, never a side effect of the click that got here.
const [reviewSummary, setReviewSummary] = useState<SessionSummary | null>(
const [reviewSummary, setTerminalReviewSummary] = useState<SessionSummary | null>(
null,
);
const [assistantReview, setAssistantReview] = useState<{
entry: AssistantHistoryEntry; authority: string; navigation: number;
} | null>(null);
const setReviewSummary = useCallback((summary: SessionSummary | null) => {
setAssistantReview(null);
setTerminalReviewSummary(summary);
}, []);
const activeAssistantReview = assistantReview?.authority === harness.assistantHistoryAuthority &&
assistantReview.navigation === studioRestoreGenerationRef.current ? assistantReview : null;
// Template gallery opened from the command palette (browse is reachable
// from anywhere, not only the add dialog / welcome panel entries).
const [templatesOpen, setTemplatesOpen] = useState(false);
Expand Down Expand Up @@ -1239,6 +1250,8 @@ export const App = (): JSX.Element => {
});
} else if (templatesOpen) {
recordVisit({ kind: "templates" });
} else if (activeAssistantReview) {
recordVisit({ kind: "assistant-review", entry: activeAssistantReview.entry, authority: activeAssistantReview.authority });
} else if (reviewSummary) {
recordVisit({ kind: "review", summary: reviewSummary });
} else if (composing) {
Expand All @@ -1261,6 +1274,7 @@ export const App = (): JSX.Element => {
effectiveStudioSelection,
templatesOpen,
reviewSummary,
activeAssistantReview,
composing,
activeSessionIdForNav,
focusedAgentPath,
Expand All @@ -1280,10 +1294,12 @@ export const App = (): JSX.Element => {
setTemplatesOpen(visit.kind === "templates");
setComposing(visit.kind === "composer");
setReviewSummary(visit.kind === "review" ? visit.summary : null);
if (visit.kind === "assistant-review")
setAssistantReview({ entry: visit.entry, authority: visit.authority, navigation: studioRestoreGenerationRef.current });
if (
visit.kind === "templates" ||
visit.kind === "composer" ||
visit.kind === "review"
visit.kind === "review" || visit.kind === "assistant-review"
) {
setStudioSelection(null);
}
Expand Down Expand Up @@ -1600,7 +1616,7 @@ export const App = (): JSX.Element => {
)
? null
: activeSession;
const showReview = reviewSummary != null;
const showReview = reviewSummary != null || activeAssistantReview != null;
const showDead = !showReview && conversationSession?.status === "exited";
// An agent selected with no session that can WORK on it: honest absence, and
// opening one lands on the "start a session" state.
Expand Down Expand Up @@ -2476,6 +2492,19 @@ export const App = (): JSX.Element => {
setSelectedProject(null);
closeMobileDrawer();
};
const reviewAssistant = (entry: AssistantHistoryEntry): void => {
const authority = harness.assistantHistoryAuthority;
if (!authority) return;
studioRestoreGenerationRef.current++;
setReviewSummary(null);
setAssistantReview({ entry, authority, navigation: studioRestoreGenerationRef.current });
setStudioSelection(null);
setSelectedProject(null);
setComposing(false);
setTemplatesOpen(false);
setOverviewOpen(false);
closeMobileDrawer();
};

// Jump from the Studio to the real code, in the editor the user picked.
const openInEditor = (path: string): void => {
Expand Down Expand Up @@ -2969,6 +2998,9 @@ export const App = (): JSX.Element => {
setOverviewOpen(false);
}}
onReviewSummary={reviewPastSession}
onReviewAssistant={reviewAssistant}
assistantHistory={harness.assistantHistory}
assistantHistoryUnavailable={harness.assistantHistoryUnavailable}
history={harness.history}
historyLoading={harness.historyLoading}
onOpenHistory={(cwds) => void harness.loadHistory(cwds)}
Expand Down Expand Up @@ -3199,7 +3231,7 @@ export const App = (): JSX.Element => {
openedAgentName={
showAgentEmpty ? (focusedWorkflow?.name ?? null) : null
}
reviewTitle={reviewSummary ? reviewSummary.title : null}
reviewTitle={activeAssistantReview?.entry.title ?? reviewSummary?.title ?? null}
// With no active CLI the centre still offers the ordinary
// composer, but a selected project map must keep its real
// session tabs visible so the user can activate one. Treating
Expand Down Expand Up @@ -3347,7 +3379,19 @@ export const App = (): JSX.Element => {
)}

<div className="terminal-slot">
{showReview && reviewSummary ? (
{activeAssistantReview ? (
<AssistantHistoryPane
key={`${activeAssistantReview.authority}:${activeAssistantReview.entry.harnessSessionId}`}
entry={activeAssistantReview.entry}
bootToken={harness.bootToken}
onClose={() => setAssistantReview(null)}
terminalNotStarted={state.sessions.find((session) => session.id === activeAssistantReview.entry.harnessSessionId)?.terminalState === "not-started"}
terminalLabel={state.sessions.find((session) => session.id === activeAssistantReview.entry.harnessSessionId)?.status !== "exited" ? "Open Terminal" : "View Terminal history"}
onOpenTerminal={state.sessions.some((session) => session.id === activeAssistantReview.entry.harnessSessionId && session.terminalState !== "not-started")
? () => openSession(activeAssistantReview.entry.harnessSessionId)
: undefined}
/>
) : showReview && reviewSummary ? (
<PastSessionPane
summary={reviewSummary}
loadRecord={harness.sessionRecord}
Expand Down Expand Up @@ -3379,6 +3423,7 @@ export const App = (): JSX.Element => {
>
<DeadSessionPane
session={conversationSession}
terminalOnly={assistantNeedsEnd(conversationSession.id)}
resumeMode={deadResumeMode}
loadRecord={harness.sessionRecord}
onResume={() =>
Expand Down
Loading
Loading