9.6 KiB
Spec: Instances CLI & Auth Codes
Date: 2026-04-02 Status: Draft Related specs:
- Spec 1: API Server Core
- Spec 2: Auth System
- Spec 4: App Connectivity
- Multi-Instance Design
- App Spec: Add Workspace Feature
Overview
Three additions to the OpenACP core to support the Add Workspace feature in the desktop app:
openacp instancesCLI subcommand — list and create instances with app-friendly JSON output.- Extend
start --jsonoutput — include full instance info after startup (wizard or normal start). - Auth code exchange — one-time codes for secure remote connection, replacing JWT-in-URL.
GET /api/v1/workspaceendpoint — lets authenticated clients fetch workspace identity info.
1. openacp instances CLI Subcommand
Relationship to openacp status --all
openacp status --all already exists and lists all instances in a table format for terminal users. The new openacp instances list command targets app consumption: its JSON output uses a different schema (directory = parent of .openacp root, root = .openacp path) compared to status --all --json which returns runtime fields (channels, runMode, pid). Human-readable output of instances list reuses the same table rendering as status --all.
openacp instances list
Lists all registered instances with live status.
openacp instances list [--json]
Status check per instance:
- Read
<root>/openacp.pid— file missing →stopped - If PID file exists, check process alive (kill -0) → dead process →
stopped - If process alive,
GET http://localhost:<port>/api/v1/system/health→ confirm alive →running
JSON output (--json):
[
{
"id": "main",
"name": "Main",
"directory": "/Users/user",
"root": "/Users/user/.openacp",
"status": "running",
"port": 21420
},
{
"id": "my-project",
"name": "My Project",
"directory": "/Users/user/my-project",
"root": "/Users/user/my-project/.openacp",
"status": "stopped",
"port": null
}
]
All paths are absolute — no ~/ prefix. directory = path.dirname(root) (the human-facing project folder, not the .openacp subdirectory itself).
Human-readable output (no --json): Same table format as openacp status --all. Can share rendering logic.
openacp instances create
Creates or registers a new instance at a given directory, non-interactively.
openacp instances create
--dir <path> Target directory — system appends /.openacp internally (user-facing convention from multi-instance spec)
[--from <path>] Clone from this existing instance directory (same convention: parent dir, not /.openacp)
[--name <name>] Instance name (default: openacp-<N>)
[--agent <agentName>] Set default agent in config
[--no-interactive] Skip setup wizard entirely
[--json] Print resulting instance info as JSON to stdout
Flow:
→ Resolve --dir to absolute path (expand ~/, resolve symlinks)
→ Check <dir>/.openacp already exists?
→ Yes + already in registry:
→ Error: "Instance already exists at <dir> (id: <id>)"
→ Exit 1
→ Yes + not in registry:
→ Read instanceName from <dir>/.openacp/config.json
→ Register entry in ~/.openacp/instances.json
→ Skip creation, go to output step
→ No .openacp yet:
→ --from <fromPath> provided:
→ Validate <fromPath>/.openacp/config.json exists (error if not found)
→ Clone using existing copy logic (from multi-instance spec)
→ Register new instance in ~/.openacp/instances.json
→ --no-interactive (no --from):
→ Create <dir>/.openacp/ directory structure
→ Write minimal config.json: { instanceName: <name>, runMode: "daemon" }
→ Write agents.json with default agent if --agent provided
→ Register in ~/.openacp/instances.json
→ Output step:
→ --json: print instance info JSON to stdout, exit 0
→ No --json: print "Instance created: <name> at <dir>", exit 0
JSON output (--json):
{
"id": "my-project",
"name": "My Project",
"directory": "/Users/user/my-project",
"root": "/Users/user/my-project/.openacp",
"status": "stopped",
"port": null
}
2. Extend start --json and Onboarding Output
Current start --json Output
openacp start --json (and the default command when starting) already outputs:
{ "success": true, "data": { "pid": 1234, "instanceId": "main", "dir": "/Users/user/.openacp" } }
dir here is the .openacp root path.
Required Change
Extend the data payload to include name and directory (the parent folder, i.e., the human-facing project folder):
{
"success": true,
"data": {
"pid": 1234,
"instanceId": "main",
"name": "Main",
"directory": "/Users/user",
"dir": "/Users/user/.openacp",
"port": 21420
}
}
dir is kept for backward compatibility. directory is path.dirname(dir).
Onboarding Wizard with --json
When openacp (or openacp start) is run with --json and no config exists:
- The setup wizard runs normally (interactive terminal prompts —
--jsoncontrols output format, not interactivity). - After wizard completes and server starts, the extended
start --jsonoutput is emitted.
The app reads this JSON from sidecar stdout to capture the newly created instance's id immediately after setup completes.
3. Auth Code Exchange
Motivation
The current openacp remote spec embeds the JWT directly in the URL (?token=eyJ...). Tokens in URLs can be logged by proxies, cached by browsers, and exposed in QR codes. Replacing the JWT with a short-lived one-time code means the actual token is never exposed in a URL.
New Endpoints
| Method | Path | Auth | Description |
|---|---|---|---|
POST |
/api/v1/auth/codes |
Secret token only | Generate one-time code |
POST |
/api/v1/auth/exchange |
None (code is credential) | Exchange code for JWT |
POST /api/v1/auth/codes
Only callable with secret token auth.
Request body:
{
"role": "admin",
"name": "remote-14h30-31-03-2026",
"expire": "24h",
"scopes": ["sessions:read"]
}
Same fields as POST /api/v1/auth/tokens — the code carries the intended token parameters.
Response:
{
"code": "abc123xyz",
"expiresAt": "2026-04-02T14:35:00Z"
}
Storage: In-memory Map code → { tokenParams, expiresAt, used: false }. Codes expire after 5 minutes. Cleanup on exchange or expiry.
POST /api/v1/auth/exchange
No authentication required — the code is the credential.
Request body:
{ "code": "abc123xyz" }
Flow:
→ Look up code in store
→ Not found: 401 "Invalid code"
→ Found but expired: 401 "Code expired"
→ Found but already used: 401 "Code already used"
→ Mark code as used (single-use, prevent replay)
→ Call internal token generation with stored tokenParams
→ Return same response as POST /api/v1/auth/tokens
Response:
{
"accessToken": "eyJ...",
"tokenId": "tok_abc123",
"expiresAt": "2026-04-03T14:30:00Z",
"refreshDeadline": "2026-04-09T14:30:00Z"
}
openacp remote — Updated Link Format
openacp remote
→ POST /api/v1/auth/codes (secret token) → code "abc123xyz"
→ Generate links:
openacp://connect?host=<tunnel>&code=abc123xyz
https://<tunnel>?code=abc123xyz
http://localhost:<port>?code=abc123xyz
The token= query param in all link formats is replaced by code=. The auth spec's existing link formats are updated accordingly.
4. GET /api/v1/workspace
Returns identity information about the current workspace/instance. Used by the app after connecting to a remote workspace to retrieve the instance id and display info.
Auth: Any valid auth (secret token or JWT — no specific scope required beyond authentication).
Response:
{
"id": "main",
"name": "Main",
"directory": "/Users/user",
"version": "2026.401.1"
}
directory is path.dirname(instanceRoot) — the parent of the .openacp folder, i.e., the human-facing project folder.
directory is the server-side filesystem path. For remote workspaces, it is meaningful for display only — connection routing uses host, not directory.
Files to Add / Modify
New Files (core)
src/cli/commands/instances.ts—instances listandinstances createsubcommandssrc/plugins/api-server/routes/workspace.ts—GET /api/v1/workspaceroutesrc/plugins/api-server/auth/code-store.ts— in-memory code store (TTL + single-use)src/plugins/api-server/routes/auth-codes.ts—POST /api/v1/auth/codesandPOST /api/v1/auth/exchangeroutes
Modified Files (core)
src/cli.ts— registerinstancessubcommand in instance-aware command mapsrc/cli/commands/index.ts— exportcmdInstancessrc/cli/commands/start.ts— extend--jsonoutput withname,directory,portsrc/cli/commands/default.ts— extend--jsonoutput (startup after wizard) with same fieldssrc/plugins/api-server/routes/auth.ts— register new code exchange routessrc/plugins/api-server/server.ts— register workspace route
Modified Files (app)
See companion spec: App Spec: Add Workspace Feature