feat: add workspace list command

This commit is contained in:
xmanrui 2026-08-18 00:39:16 +08:00
parent c44340accb
commit 1fe6180813
17 changed files with 570 additions and 118 deletions

View file

@ -1,5 +1,13 @@
import { spawn } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { isAbsolute } from 'node:path';
function workspacePaths(value) {
if (!Array.isArray(value?.items)) return [];
return value.items.flatMap((item) => (
typeof item?.path === 'string' && isAbsolute(item.path) ? [item.path] : []
));
}
function sleep(ms, signal) {
return new Promise((resolve, reject) => {
@ -216,6 +224,11 @@ export class HarnessClient {
throw new Error(`Harness did not become ready: ${lastError?.message ?? 'timeout'}`);
}
async listWorkspaces(options = {}) {
await this.ensureRunning(options);
return workspacePaths(await this.rpc('workspace.list', {}, 30_000, options));
}
async workspaceId(options = {}) {
const { workspace = this.#workspace, ...rpcOptions } = options;
const { items } = await this.rpc('workspace.list', {}, 30_000, rpcOptions);