fix(vscode): improve extension activation and error handling
This commit is contained in:
@@ -4,7 +4,7 @@ import { opencodeClient } from '@/lib/opencode/client';
|
||||
import { useDirectoryStore } from './useDirectoryStore';
|
||||
import type { WorktreeMetadata } from '@/types/worktree';
|
||||
import { listWorktrees, mapWorktreeToMetadata } from '@/lib/git/worktreeService';
|
||||
import type { Session } from '@opencode-ai/sdk';
|
||||
import type { Session } from '@opencode-ai/sdk/v2';
|
||||
|
||||
const OPENCHAMBER_DIR = '.openchamber';
|
||||
|
||||
@@ -178,7 +178,7 @@ export const useAgentGroupsStore = create<AgentGroupsStore>()(
|
||||
// Fetch all sessions from the main project directory
|
||||
// All worktree sessions are visible from here
|
||||
const response = await apiClient.session.list({
|
||||
query: { directory: normalizedCurrent },
|
||||
directory: normalizedCurrent,
|
||||
});
|
||||
const allSessions: Session[] = Array.isArray(response.data) ? response.data : [];
|
||||
|
||||
|
||||
@@ -33,7 +33,10 @@
|
||||
],
|
||||
"icon": "assets/app-icon.png",
|
||||
"main": "./dist/extension.js",
|
||||
"activationEvents": [],
|
||||
"activationEvents": [
|
||||
"onCommand:openchamber.openSidebar",
|
||||
"onView:openchamber.chatView"
|
||||
],
|
||||
"contributes": {
|
||||
"viewsContainers": {
|
||||
"activitybar": [
|
||||
@@ -174,10 +177,10 @@
|
||||
"scripts": {
|
||||
"vscode:prepublish": "bun run build",
|
||||
"build": "bun run build:extension && bun run build:webview",
|
||||
"build:extension": "esbuild src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --minify",
|
||||
"build:extension": "esbuild src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --minify --main-fields=module,main",
|
||||
"build:webview": "VITE_OPENCODE_URL=/api vite build",
|
||||
"dev": "concurrently -n \"ext,web\" -c \"cyan,magenta\" \"bun run watch:extension\" \"bun run watch:webview\"",
|
||||
"watch:extension": "esbuild src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --watch --sourcemap",
|
||||
"watch:extension": "esbuild src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --watch --sourcemap --main-fields=module,main",
|
||||
"watch:webview": "vite build --watch",
|
||||
"type-check": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.webview.json",
|
||||
"lint": "bunx eslint --ext .ts,.tsx src webview",
|
||||
|
||||
@@ -102,26 +102,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
};
|
||||
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('openchamber.openSidebar', async () => {
|
||||
// Best-effort: open the container (if available), then focus the chat view.
|
||||
try {
|
||||
await vscode.commands.executeCommand('workbench.view.extension.openchamber');
|
||||
} catch {
|
||||
// Ignore: not all VS Code forks expose this command.
|
||||
}
|
||||
|
||||
await vscode.commands.executeCommand('openchamber.chatView.focus');
|
||||
})
|
||||
);
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('openchamber.focusChat', async () => {
|
||||
await vscode.commands.executeCommand('openchamber.chatView.focus');
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
// Migration: clear legacy auto-set API URLs (ports 47680-47689 were auto-assigned by older extension versions)
|
||||
const config = vscode.workspace.getConfiguration('openchamber');
|
||||
const legacyApiUrl = config.get<string>('apiUrl') || '';
|
||||
@@ -144,6 +124,31 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
)
|
||||
);
|
||||
|
||||
// Register sidebar/focus commands AFTER the webview view provider is registered
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('openchamber.openSidebar', async () => {
|
||||
// Best-effort: open the container (if available), then focus the chat view.
|
||||
try {
|
||||
await vscode.commands.executeCommand('workbench.view.extension.openchamber');
|
||||
} catch (e) {
|
||||
outputChannel?.appendLine(`[OpenChamber] workbench.view.extension.openchamber failed: ${e}`);
|
||||
}
|
||||
|
||||
try {
|
||||
await vscode.commands.executeCommand('openchamber.chatView.focus');
|
||||
} catch (e) {
|
||||
outputChannel?.appendLine(`[OpenChamber] openchamber.chatView.focus failed: ${e}`);
|
||||
vscode.window.showErrorMessage(`OpenChamber: Failed to open sidebar - ${e}`);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('openchamber.focusChat', async () => {
|
||||
await vscode.commands.executeCommand('openchamber.chatView.focus');
|
||||
})
|
||||
);
|
||||
|
||||
void maybeMoveChatToRightSidebarOnStartup();
|
||||
|
||||
// Create Agent Manager panel provider
|
||||
|
||||
Reference in New Issue
Block a user