#37 [Feature]: Add a fully offline CLI workspace with server-wins sync
Originally created by: thomijasir
Feature description
Allow authenticated CLI users to keep working with projects, environments, and secrets when the configured server is unavailable. Store changes securely on the local machine and synchronize them when connectivity returns.
This is separate from [#21]. That issue covers running commands from the read-only runtime cache. This issue covers an editable local workspace and server synchronization.
Current behavior
Project creation, environment management, secret editing, and imports call the server directly. They fail when a local server is stopped, a remote server is unavailable, or the user has no network connection.
The runtime cache can supply secrets to dopbase run, but it cannot accept changes or upload them later.
Why we need it
CLI work should not stop during a temporary outage. A developer should be able to create a project, add environments, edit secrets, and run commands locally. Dopbase can upload those changes after the server becomes reachable again.
This requires new client storage, synchronization APIs, revision tracking, and conflict handling. Keep it as a low-priority future feature until the main CLI workflow is stable.
Supported offline commands
The first release covers workspace data:
dopbase initdopbase project create|list|show|rename|deletedopbase env create|list|show|rename|delete|defaultdopbase secret list|get|set|deletedopbase import, including merge and replacedopbase run, using the latest local workspace state
Authentication, token management, administration, backup, restore, plaintext reveal, and export remain online-only.
Proposed CLI interface
dopbase syncperforms a complete synchronization.dopbase sync --dry-runpreviews uploads and conflicts without changing local or server state.dopbase sync statusreports the last successful sync, pending operations, and retained conflicts without requiring a connection.dopbase sync conflictslists redacted conflict summaries.dopbase sync conflicts purge --yesdeletes retained conflict records.
Each server-backed CLI command first makes a short synchronization attempt. If the server is unavailable, supported commands continue against the local workspace. Do not add a background daemon.
Authentication, authorization, validation, and other server responses are not connectivity failures. They must stop the command instead of switching to offline mode.
Local workspace
- Create a versioned local replica for each server instance and administrator identity.
- Store projects, environments, secrets, the last server cursor, and an ordered pending-operation queue.
- Encrypt entity data and operation payloads at rest with authenticated encryption.
- Use stable client-generated IDs for objects created offline so references do not change after synchronization.
- Apply offline mutations optimistically. Dependent operations must work, such as creating a project, adding an environment, and setting its secrets in one offline session.
- Preserve current stdout and JSON response shapes. Send offline and pending-state notices to stderr.
- Require one successful authenticated synchronization before offline editing is available.
- Permit an expired saved session to unlock the workspace while the server is unreachable. The server must check the current identity and permissions before accepting changes.
- Scope data to the stable server instance and administrator ID. Never upload one server or account queue to another.
- Warn during logout when pending changes exist. Lock the workspace after logout and allow only the same identity to unlock it after login.
- Never include secret values in logs, status output, errors, or conflict summaries.
Synchronization API
Add a versioned authenticated sync endpoint with:
- A stable client ID and idempotent operation IDs.
- Client-generated project and environment IDs.
- Ordered pending operations.
- Base entity revisions.
- Collection or subtree revisions for destructive operations.
- A monotonic server change cursor and deletion tombstones.
- Per-operation results:
applied,conflict,rejected, orretryable. - Canonical server changes and the next cursor.
- Dry-run processing without mutations.
Process operations in dependency order. Retrying after a timeout or lost response must not apply an operation twice. Each applied operation creates the normal server audit event and records its operation ID and original local timestamp.
Existing REST endpoints and online CLI behavior remain compatible.
Server-wins conflict policy
- Apply a local operation only when its base revision still matches the server.
- If the server changed the same object, reject the local operation and restore the server version locally.
- A server deletion wins over a local update.
- An existing server object wins when an offline creation conflicts by ID or unique name.
- Project deletion, environment deletion, and replace imports use collection or subtree revisions. Newer server-side children must not be deleted.
- Continue applying independent operations that do not conflict.
- If a parent creation conflicts, reject its dependent child operations. Do not attach them to an existing server object automatically.
- Retain rejected payloads in encrypted storage until the user purges them. Show only redacted summaries.
- Do not add force push. A user can review server state and repeat the intended command as a new operation.
Failure handling
- Keep operations pending after connection failures, timeouts, and retryable server errors.
- Mark validation and authorization failures as rejected with a safe explanation.
- Update the local replica and pending queue atomically.
- Detect damaged or unsupported workspace versions without deleting their data.
- If the server does not support sync, keep the current online-only behavior and explain that offline editing is unavailable.
Acceptance criteria
- [ ] A previously authenticated user can complete every supported workspace operation without a server connection.
- [ ] IDs created offline remain unchanged after synchronization.
- [ ] The next reachable server-backed command uploads pending changes automatically.
- [ ]
dopbase synccan be retried without duplicate objects, secrets, or audit events. - [ ] Server state wins every conflicting operation.
- [ ] Independent non-conflicting operations still synchronize.
- [ ] Rejected local changes remain encrypted and available as redacted conflict records until purged.
- [ ] Different servers and user accounts cannot read or upload another workspace.
- [ ] Secret values never appear in synchronization diagnostics.
- [ ] Existing online commands and runtime-cache behavior continue to work.
Test scenarios
- Complete project, environment, secret, initialization, import, and run workflows while offline.
- Create dependent objects offline, reconnect, and verify the final server state.
- Lose the response after an apply request, retry, and verify idempotency.
- Cover update, deletion, unique-name, replace-import, and parent-child conflicts.
- Cover batches containing valid independent operations and conflicts.
- Cover expired sessions, revoked permissions, different identities, and different servers.
- Cover encrypted storage permissions, damaged local data, queue limits, and crash recovery.
- Cover servers without sync support and confirm that authentication failures never trigger offline mode.
Dependencies
This needs coordinated CLI, API, database, audit, and security changes. It should not change the existing runtime-cache format from [#21].