Skip to content
Open
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
21 changes: 20 additions & 1 deletion src/OpenCodeViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "./transport/SseClient";

const LAST_AGENT_KEY = "opencode.lastUsedAgent";
const LAST_SESSION_KEY_PREFIX = "opencode.lastSession";

interface DevServerConfig {
origin: string;
Expand Down Expand Up @@ -141,6 +142,9 @@ export class OpenCodeViewProvider implements vscode.WebviewViewProvider {
case "agent-changed":
await this._handleAgentChanged(message.agent);
break;
case "session-changed":
await this._handleSessionChanged(message.sessionId ?? null);
break;
case "open-file":
await this._handleOpenFile(
message.url,
Expand All @@ -154,6 +158,13 @@ export class OpenCodeViewProvider implements vscode.WebviewViewProvider {
}
}

private _lastSessionKey(): string {
const workspaceRoot = this._openCodeService.getWorkspaceRoot();
return workspaceRoot
? `${LAST_SESSION_KEY_PREFIX}:${workspaceRoot}`
: LAST_SESSION_KEY_PREFIX;
}

private async _handleOpenFile(
url: string,
startLine?: number,
Expand Down Expand Up @@ -243,7 +254,9 @@ export class OpenCodeViewProvider implements vscode.WebviewViewProvider {
private async _handleReady() {
try {
const currentSessionId =
this._openCodeService.getCurrentSessionId() ?? undefined;
this._globalState.get<string>(this._lastSessionKey()) ??
this._openCodeService.getCurrentSessionId() ??
undefined;
const currentSessionTitle =
this._openCodeService.getCurrentSessionTitle();

Expand Down Expand Up @@ -302,6 +315,12 @@ export class OpenCodeViewProvider implements vscode.WebviewViewProvider {
logger.info("[ViewProvider] Agent selection persisted:", agent);
}

private async _handleSessionChanged(sessionId: string | null) {
await this._globalState.update(this._lastSessionKey(), sessionId ?? undefined);
const logger = getLogger();
logger.info("[ViewProvider] Session selection persisted", { sessionId });
}

// SSE Proxy handlers using resilient SseClient
private _handleSSESubscribe(message: { id: string; url: string }) {
const { id, url } = message;
Expand Down
10 changes: 10 additions & 0 deletions src/shared/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ describe("WebviewMessageSchema", () => {
expect(WebviewMessageSchema.parse(msg)).toEqual(msg);
});

it("parses session-changed message", () => {
const msg = { type: "session-changed", sessionId: "ses_123" };
expect(WebviewMessageSchema.parse(msg)).toEqual(msg);
});

it("parses cleared session-changed message", () => {
const msg = { type: "session-changed", sessionId: null };
expect(WebviewMessageSchema.parse(msg)).toEqual(msg);
});

it("parses search-files message", () => {
const msg = { type: "search-files", query: "index" };
expect(WebviewMessageSchema.parse(msg)).toEqual(msg);
Expand Down
4 changes: 4 additions & 0 deletions src/shared/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ export const WebviewMessageSchema = z.discriminatedUnion("type", [
type: z.literal("agent-changed"),
agent: z.string(),
}),
z.object({
type: z.literal("session-changed"),
sessionId: z.string().nullish(),
}),
z.object({
type: z.literal("open-file"),
url: z.string(),
Expand Down
63 changes: 62 additions & 1 deletion src/webview/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,62 @@ body.vscode-high-contrast {
border-left: 2px solid transparent;
}

.session-rename-form {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
gap: var(--spacing-xs);
}

.session-rename-input {
flex: 1;
min-width: 0;
padding: var(--padding-button-compact);
border: 1px solid var(--focus-border);
border-radius: 4px;
background-color: var(--input-background);
color: var(--input-foreground);
font-family: var(--font-family);
font-size: var(--font-size-small);
font-weight: 500;
box-sizing: border-box;
}

.session-rename-input:focus {
outline: 1px solid var(--focus-border);
outline-offset: 0;
}

.session-rename-action {
display: inline-flex;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
border: 1px solid transparent;
border-radius: 4px;
background-color: transparent;
color: var(--input-foreground);
cursor: pointer;
opacity: 0.7;
}

.session-rename-action:hover:not(:disabled) {
background-color: var(--hover-background);
opacity: 1;
}

.session-rename-action:disabled {
cursor: not-allowed;
opacity: 0.35;
}

.session-rename-action:focus-visible {
outline: 1px solid var(--focus-border);
outline-offset: 0;
}

.dropdown-arrow {
font-size: 10px;
opacity: 0.7;
Expand Down Expand Up @@ -1292,11 +1348,16 @@ body.vscode-high-contrast {
opacity: 0.7;
}

.new-session-button:hover {
.new-session-button:hover:not(:disabled) {
background-color: var(--hover-background);
opacity: 1;
}

.new-session-button:disabled {
cursor: not-allowed;
opacity: 0.35;
}

.new-session-button:focus-visible {
outline: 1px solid var(--focus-border);
outline-offset: 0;
Expand Down
Loading