import { CloudRemotePort } from '@agentproto/cloud-agent'; /** * `~/.agentproto/workspaces.json` — single source of truth for the * local agentproto control plane. Tracks which directories the user * has opted into as agentproto workspaces, plus which one is "active" * (the daemon's default working set when no workspace is named in * a tool call). * * Why a config file instead of recreating an MCP entry per workspace: * - One daemon = one MCP entry in the user's IDE (clean to read in * `claude mcp list`, no `dapper_willow` / `noble_lantern` spam). * - The daemon walks `workspaces[]` at boot and exposes them all; * tools that need a target take an optional `workspace` arg and * fall back to `active` when omitted. * - The CLI (`agentproto workspace add/list/remove/use`), the daemon, * and the acme-web onboarding dialog all read+write the same * file, so changes from one surface are immediately visible to * the others. * * File layout is intentionally boring (small, hand-editable JSON) — * future fields go on top, never break v1 readers. */ declare const WORKSPACES_CONFIG_VERSION: 1; /** Where a workspace's code lives off this machine. Lets a sandbox spawn * (`agent_start({ sandbox, workspaceSlug })`) clone the repo into the box * instead of needing the host path. Holds no secret: `credentialRef` only * names the keychain slot of the PAT used to clone and push. */ interface WorkspaceRemote { /** `https://` clone URL, never carrying userinfo (no `user:token@`). */ url: string; /** Branch new work branches from when no explicit base is given * (the box uses `origin/`). Absent ⇒ `main`. */ defaultBranch?: string; /** Keychain slot (`StoreRef.path`) holding the git PAT. */ credentialRef?: string; } declare const DEFAULT_REMOTE_BRANCH = "main"; interface WorkspaceEntry { /** Stable handle — what tools accept as `workspace`. Lowercase * ASCII, hyphen-only. The CLI sanitises arbitrary names down to * this shape so paste-from-finder Just Works. */ slug: string; /** Absolute filesystem path. Required absolute so the daemon can * serve the workspace regardless of its own cwd. */ path: string; /** ISO-8601 — first time the entry was added. Pure metadata, no * behavioural impact. */ addedAt: string; /** Last time the entry was touched (renamed, path edited, used as * active). Lets the CLI sort by recency without an N+1 stat. */ updatedAt: string; /** Free-text label the user can attach so workspaces with similar * slugs stay distinguishable in `agentproto workspace list`. */ label?: string; /** Optional off-machine clone source — see {@link WorkspaceRemote}. */ remote?: WorkspaceRemote; /** Set when the entry was registered by an installed app (`app-` * workspaces, see `app-workspace.ts`) — the owning appId. Lets the * runtime tell app-owned entries from user workspaces: only the owning * app's uninstall removes it, and it is never picked as the implicit * active workspace. */ ownerApp?: string; } interface WorkspacesConfig { version: typeof WORKSPACES_CONFIG_VERSION; /** Active workspace slug — daemon defaults to this when no * `workspace` arg is passed. May be undefined when no workspaces * are registered yet. */ active?: string; workspaces: WorkspaceEntry[]; } declare const DEFAULT_CONFIG_DIR: () => string; declare const DEFAULT_CONFIG_PATH: () => string; /** Reduce arbitrary user input to a safe slug. Aligns with what most * tooling validates against (`/^[a-z0-9][a-z0-9-]{0,63}$/`) so the * daemon never has to encode it for URLs or filesystem paths. */ declare function sanitizeSlug(input: string): string; /** Read the config from disk. Returns an empty config (no workspaces, * no active) when the file is missing — this is the legitimate * first-boot state, not an error. */ declare function loadWorkspacesConfig(path?: string): Promise; /** Sync twin of `loadWorkspacesConfig`, sharing its normalisation (and * therefore its slug sanitisation) exactly. * * Exists because bucket resolution runs on paths that cannot await: the * sessions registry loads its history synchronously at construction so * the dashboard has rows immediately, and flushes synchronously on * `process.on("exit")` where Node won't await. Both need to know which * slugs are registered. The file is <1KB, so the sync read is cheaper * than the machinery to avoid it. */ declare function loadWorkspacesConfigSync(path?: string): WorkspacesConfig; /** Write the config back. Creates the parent directory if missing. * Atomic-ish: writes to a temp file first, then renames over the * target — avoids the partial-write window where a concurrent reader * sees half a JSON object. */ declare function saveWorkspacesConfig(config: WorkspacesConfig, path?: string): Promise; /** * Pure helpers — caller manages persistence. Returns a NEW config * (never mutates) so callers can compose multiple updates before * a single save. */ declare function addWorkspace(config: WorkspacesConfig, input: { slug: string; path: string; label?: string; ownerApp?: string; }): WorkspacesConfig; /** Throws unless `raw` is a plain `https://` URL with a host and no * userinfo/query/fragment; returns it trimmed. A token embedded in a URL * would land in git config, process args and logs — the credential belongs * in `credentialRef`. */ declare function validateRemoteUrl(raw: string): string; /** Throws unless `raw` is a conservative git branch name; returns it trimmed. * It is interpolated into shell commands inside the box, so the charset is * deliberately narrow. */ declare function validateRemoteBranch(raw: string): string; /** Throws unless `raw` is a non-empty single-token keychain slot; returns it trimmed. */ declare function validateCredentialRef(raw: string): string; /** The port a cloud spawn passes to `@agentproto/cloud-agent` so it can * validate a declared remote and default its branch without importing this * module. */ declare const workspaceRemotePort: CloudRemotePort; /** Validate a candidate remote, returning a canonical copy. Throws on the * first problem. */ declare function validateWorkspaceRemote(input: WorkspaceRemote): WorkspaceRemote; /** Attach (or replace) the remote on an existing workspace. Throws when the * slug is unknown or the remote is invalid. */ declare function setWorkspaceRemote(config: WorkspacesConfig, slug: string, remote: WorkspaceRemote): WorkspacesConfig; /** Drop the remote from a workspace. Throws when the slug is unknown; a * workspace that had no remote is returned unchanged. */ declare function unsetWorkspaceRemote(config: WorkspacesConfig, slug: string): WorkspacesConfig; declare function removeWorkspace(config: WorkspacesConfig, slug: string): WorkspacesConfig; declare function setActiveWorkspace(config: WorkspacesConfig, slug: string): WorkspacesConfig; declare function findWorkspace(config: WorkspacesConfig, slug: string): WorkspaceEntry | undefined; /** Find a workspace whose path is an ancestor of (or equal to) the * given directory. Returns the most specific match (longest path) * when multiple workspaces nest under the same root. */ declare function findWorkspaceByPath(config: WorkspacesConfig, dir: string): WorkspaceEntry | undefined; /** The active workspace, or undefined when none is registered. Pure * convenience to avoid re-implementing the lookup at every caller. */ declare function getActiveWorkspace(config: WorkspacesConfig): WorkspaceEntry | undefined; export { DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_PATH, DEFAULT_REMOTE_BRANCH, WORKSPACES_CONFIG_VERSION, type WorkspaceEntry, type WorkspaceRemote, type WorkspacesConfig, addWorkspace, findWorkspace, findWorkspaceByPath, getActiveWorkspace, loadWorkspacesConfig, loadWorkspacesConfigSync, removeWorkspace, sanitizeSlug, saveWorkspacesConfig, setActiveWorkspace, setWorkspaceRemote, unsetWorkspaceRemote, validateCredentialRef, validateRemoteBranch, validateRemoteUrl, validateWorkspaceRemote, workspaceRemotePort };