feat: enhance waitForReady function to accept working directory parameter for context-aware readiness checks
This commit is contained in:
@@ -1,10 +1,3 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to the OpenChamber VS Code extension will be documented in this file.
|
|
||||||
|
|
||||||
## [Unreleased]
|
|
||||||
|
|
||||||
|
|
||||||
## [1.4.9] - 2026-01-14
|
## [1.4.9] - 2026-01-14
|
||||||
|
|
||||||
- Added session editor panel to view sessions alongside files.
|
- Added session editor panel to view sessions alongside files.
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.com/btriapitsyn/openchamber/raw/HEAD/docs/references/badges/openchamber-logo-dark.svg"><img src="https://github.com/btriapitsyn/openchamber/raw/HEAD/docs/references/badges/openchamber-logo-light.svg" width="32" height="32" align="absmiddle" /></picture> OpenChamber VS Code Extension
|
# OpenChamber VS Code Extension
|
||||||
|
|
||||||
[](https://github.com/btriapitsyn/openchamber/stargazers)
|
[](https://github.com/btriapitsyn/openchamber/stargazers)
|
||||||
[](https://github.com/btriapitsyn/openchamber/network/members)
|
[](https://github.com/btriapitsyn/openchamber/network/members)
|
||||||
[](https://github.com/btriapitsyn/openchamber/releases/latest)
|
[](https://github.com/btriapitsyn/openchamber/releases/latest)
|
||||||
[](https://opencode.ai)
|
[](https://discord.gg/ZYRSdnwwKA)
|
||||||
[](https://zread.ai/btriapitsyn/openchamber)
|
|
||||||
[](https://discord.gg/ZYRSdnwwKA)
|
|
||||||
[](https://ko-fi.com/G2G41SAWNS)
|
[](https://ko-fi.com/G2G41SAWNS)
|
||||||
|
|
||||||
OpenChamber inside VS Code: embeds the OpenChamber chat UI in the activity bar and connects it to the [OpenCode](https://opencode.ai) API.
|
OpenChamber inside VS Code: embeds the OpenChamber chat UI in the activity bar and connects it to the [OpenCode](https://opencode.ai) API.
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ function getCandidateBaseUrls(serverUrl: string): string[] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function waitForReady(serverUrl: string, timeoutMs = 5000): Promise<ReadyResult> {
|
async function waitForReady(serverUrl: string, timeoutMs = 5000, workingDirectory = ''): Promise<ReadyResult> {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const candidates = getCandidateBaseUrls(serverUrl);
|
const candidates = getCandidateBaseUrls(serverUrl);
|
||||||
|
|
||||||
@@ -90,7 +90,11 @@ async function waitForReady(serverUrl: string, timeoutMs = 5000): Promise<ReadyR
|
|||||||
const timeout = setTimeout(() => controller.abort(), 1500);
|
const timeout = setTimeout(() => controller.abort(), 1500);
|
||||||
|
|
||||||
// Keep using /config since the UI proxies to it (via /api -> strip prefix).
|
// Keep using /config since the UI proxies to it (via /api -> strip prefix).
|
||||||
const res = await fetch(`${baseUrl}/config`, {
|
const url = new URL(`${baseUrl}/config`);
|
||||||
|
if (workingDirectory) {
|
||||||
|
url.searchParams.set('directory', workingDirectory);
|
||||||
|
}
|
||||||
|
const res = await fetch(url.toString(), {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: { Accept: 'application/json' },
|
headers: { Accept: 'application/json' },
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
@@ -209,17 +213,30 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
|
|||||||
managedApiUrlOverride = null;
|
managedApiUrlOverride = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Let the SDK/OS choose a random available port (port: 0)
|
// SDK spawns `opencode serve` in current process cwd.
|
||||||
server = await createOpencodeServer({
|
// Some OpenCode endpoints behave differently based on server process cwd,
|
||||||
hostname: '127.0.0.1',
|
// so ensure we start it from the workspace directory.
|
||||||
port: 0,
|
const originalCwd = process.cwd();
|
||||||
timeout: READY_CHECK_TIMEOUT_MS,
|
try {
|
||||||
signal: undefined,
|
process.chdir(workingDirectory);
|
||||||
});
|
// Let the SDK/OS choose a random available port (port: 0)
|
||||||
|
server = await createOpencodeServer({
|
||||||
|
hostname: '127.0.0.1',
|
||||||
|
port: 0,
|
||||||
|
timeout: READY_CHECK_TIMEOUT_MS,
|
||||||
|
signal: undefined,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
process.chdir(originalCwd);
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (server && server.url) {
|
if (server && server.url) {
|
||||||
// Wait for actual HTTP readiness (stdout "listening" isn't always enough on Windows)
|
// Validate readiness for the current workspace context.
|
||||||
const ready = await waitForReady(server.url, 10000);
|
const ready = await waitForReady(server.url, 10000, workingDirectory);
|
||||||
if (ready.ok) {
|
if (ready.ok) {
|
||||||
managedApiUrlOverride = ready.baseUrl;
|
managedApiUrlOverride = ready.baseUrl;
|
||||||
detectedPort = resolvePortFromUrl(ready.baseUrl);
|
detectedPort = resolvePortFromUrl(ready.baseUrl);
|
||||||
@@ -227,7 +244,6 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
|
|||||||
apiPrefixDetected = apiPrefix.length > 0;
|
apiPrefixDetected = apiPrefix.length > 0;
|
||||||
setStatus('connected');
|
setStatus('connected');
|
||||||
} else {
|
} else {
|
||||||
// Cleanup zombie process if readiness check fails
|
|
||||||
try {
|
try {
|
||||||
server.close();
|
server.close();
|
||||||
} catch {
|
} catch {
|
||||||
@@ -270,6 +286,7 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
|
|||||||
server = null;
|
server = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
managedApiUrlOverride = null;
|
managedApiUrlOverride = null;
|
||||||
detectedPort = null;
|
detectedPort = null;
|
||||||
setStatus('disconnected');
|
setStatus('disconnected');
|
||||||
|
|||||||
Reference in New Issue
Block a user