/**
 * Pure JSON serialiser for `olam workspace list --json`.
 *
 * Kept separate from the command action so the wire contract is
 * unit-testable without a filesystem round-trip (mirrors the pattern
 * used by `repos-list-json.ts`, `auth-list-json.ts`, and `renderPsJson`
 * in ps.ts).
 *
 * WHY this exists: agent/script drivers (CI pipelines, flywheel chain
 * skills, Rico) need to enumerate registered workspaces before spawning
 * worlds or dispatching work with `--workspace`. The human table is
 * colorized and reflows per terminal width, so scraping it is brittle and
 * breaks when column widths change. This serialiser gives drivers a stable,
 * color-free object: each entry carries the name, repo count, full repo
 * list, and updatedAt timestamp needed to select a workspace without
 * re-querying the filesystem.
 *
 * Secret redaction: `setupCmd` fields inside repos can carry inline secrets
 * (e.g. `setupCmd: "export GITHUB_TOKEN=ghp_..."`). The serialiser applies
 * `workspaceForApi` from @olam/core before emission so sensitive-key values
 * are replaced with `[redacted]`. The repo `url` and `path` fields contain
 * no credentials — workspace YAMLs store only the remote URL without
 * embedded auth.
 */
import { workspaceForApi } from '@olam/core/src/workspace/redact.js';
/**
 * Serialise the workspace catalog to the stable `--json` wire shape.
 * Returns a JSON string (no trailing newline — caller adds it).
 *
 * Applies `workspaceForApi` (redact.ts) before serialisation so any
 * sensitive-key values in repo fields (e.g. inside `setupCmd`) are
 * replaced with `[redacted]` before leaving the process.
 */
export function renderWorkspaceListJson(workspaces) {
    const entries = workspaces.map((ws) => {
        // Defense-in-depth: run the core API redaction pass before serialising.
        const safe = workspaceForApi(ws);
        const repos = safe.repos.map((r) => ({
            name: r.name,
            url: r.url,
            path: r.path ?? null,
            branch: r.branch ?? null,
            submodules: r.submodules ?? false,
        }));
        return {
            name: safe.name,
            repoCount: safe.repos.length,
            repos,
            defaultBranch: safe.defaults?.branch ?? null,
            updatedAt: safe.updatedAt,
        };
    });
    const payload = {
        count: entries.length,
        workspaces: entries,
    };
    return JSON.stringify(payload);
}
//# sourceMappingURL=workspace-list-json.js.map