Login
Cambria CLI Implementation Reference
Login

Last Updated: 2025-12-23
CLI Version: 0.2.0-dev
Status: Feature-complete for core local operations

This document describes the implemented Cambria command-line interface and how it maps onto the underlying Go code. It supersedes the earlier planning document CAMBRIA_CLI_PLAN.md.

This is not a design plan and does not contain implementation snippets. Each section points to the concrete implementation files under cmd/cambria and the associated APIs under pkg/vcs, pkg/auth, and pkg/store.


1. CLI Entry Point and Globals

1.1 Registered Subcommands

Defined in the Commands slice of the root cli.Command in main.go:

  1. initinitCommand() (see cmd/cambria/init.go)
  2. openopenCommand() (see cmd/cambria/open.go)
  3. closecloseCommand() (see cmd/cambria/close.go)
  4. addaddCommand() (see cmd/cambria/add.go)
  5. rmrmCommand() (see cmd/cambria/rm.go)
  6. mvmvCommand() (see cmd/cambria/mv.go)
  7. commitcommitCommand() (see cmd/cambria/commit.go)
  8. checkoutcheckoutCommand() (see cmd/cambria/checkout.go)
  9. statusstatusCommand() (see cmd/cambria/status.go)
  10. diffdiffCommand() (see cmd/cambria/diff.go)
  11. loglogCommand() (see cmd/cambria/log.go)
  12. branchbranchCommand() (see cmd/cambria/branch.go)
  13. tagtagCommand() (see cmd/cambria/tag.go)
  14. mergemergeCommand() (see cmd/cambria/merge.go)
  15. useruserCommand() (see cmd/cambria/user.go)

This list represents the current, complete CLI surface of the cambria binary.

1.2 Global Flags

Configured on the root command in main.go and available to all subcommands:

Repository discovery logic is centralized in FindRepository in cmd/cambria/common.go (see below).


2. Shared CLI Utilities

2.1 Common Helpers (cmd/cambria/common.go)

This file implements reusable helpers used across multiple commands:

These helpers rely on vcs.Repository and the SQLite-backed store.DB for database access.


3. Repository Lifecycle Commands

3.1 cambria init

3.2 cambria open

3.3 cambria close


4. Working Directory and File Operations

All of these commands rely on FindRepository and, where applicable, on vcs.NewWorkDir to interact with the VFILE-backed working directory state.

4.1 cambria add

4.2 cambria rm

4.3 cambria mv


5. Commit, Status, and Diff

5.1 cambria commit

Initial-commit path:

Normal-commit path:

5.2 cambria status

5.3 cambria diff


6. History, Branches, and Tags

6.1 cambria log

6.2 cambria branch

Branch listing and manipulation act on the user-facing names; the label prefix logic (for example, "branch:") is encapsulated in the vcs package.

6.3 cambria tag


7. Merge Operations

7.1 cambria merge

Merge state and detection of an in-progress merge integrate with repo.GetPendingMerge and the VFILE or metadata structures in pkg/vcs.


8. User Management

8.1 cambria user

All subcommands use FindRepository and vcs.OpenRepository to locate the repository database and then operate via pkg/store and pkg/auth.

8.1.1 user new

8.1.2 user list {#812-user-list}

8.1.3 user password

8.1.4 user capabilities


9. Repository Discovery and Version Semantics

While individual commands make direct use of FindRepository and ResolveVersion, the following behaviors are shared across the CLI:


10. Fossil Mapping and Coverage Summary

The table below maps implemented Cambria CLI commands to their Fossil counterparts and highlights where functionality is present in the current codebase.

Fossil Command Cambria Command Implementation Files Status (Local-only)
fossil new cambria init cmd/cambria/init.go, pkg/vcs/repo.go Implemented
fossil open cambria open cmd/cambria/open.go, cmd/cambria/common.go Implemented
fossil close cambria close cmd/cambria/close.go Implemented
fossil add cambria add cmd/cambria/add.go, pkg/vcs/workdir.go Implemented
fossil rm cambria rm cmd/cambria/rm.go, pkg/vcs/remove.go Implemented
fossil mv cambria mv cmd/cambria/mv.go, pkg/vcs/rename.go Implemented
fossil commit cambria commit cmd/cambria/commit.go, pkg/vcs/checkin.go Implemented
fossil checkout cambria checkout cmd/cambria/checkout.go, pkg/vcs/checkout.go Implemented
fossil status cambria status cmd/cambria/status.go, pkg/vcs/vfile.go Implemented
fossil diff cambria diff cmd/cambria/diff.go, pkg/vcs/diff.go Implemented
fossil timeline cambria log cmd/cambria/log.go, pkg/vcs/log.go Implemented
fossil branch cambria branch cmd/cambria/branch.go, pkg/vcs/label.go Implemented
fossil tag cambria tag cmd/cambria/tag.go, pkg/vcs/label.go Implemented
fossil merge cambria merge cmd/cambria/merge.go, pkg/vcs/merge.go Implemented
fossil user cambria user cmd/cambria/user.go, pkg/auth/*, pkg/store/user.go Implemented
Network commands (none yet) doc_cambria/CAMBRIA_SYNC_PLAN.md Not yet implemented

"Status" here refers only to the local, file-system based operations currently wired through the CLI and backing VCS, auth, and store APIs.


11. How to Extend the CLI

When adding new commands or extending existing ones, follow these patterns used in the current implementation:

  1. Route through vcs.Repository:
    Always use vcs.OpenRepository or vcs.InitRepository and the high-level methods on vcs.Repository rather than calling pkg/store directly from CLI code.

  2. Use FindRepository and ResolveVersion:
    New commands that need repository resolution or version interpretation should reuse the helpers in cmd/cambria/common.go for consistent behavior.

  3. Keep CLI logic thin:
    Parse flags and arguments in cmd/cambria, but keep business logic (checkin, merge, network sync, and so on) in pkg/vcs, pkg/auth, and pkg/store.

  4. Follow existing UX patterns:

    • Reuse status and summary formats from status, commit, merge, and log where applicable.
    • Prefer descriptive error messages that wrap underlying errors with context.
  5. Update this document:
    Whenever a new CLI command is added under cmd/cambria, add a corresponding section here with:

    • Command name and purpose.
    • Usage synopsis and key flags.
    • Pointers to implementation files and relevant pkg/* APIs.

This document, together with AGENTS.md and the doc_cambria/* design documents, should give a complete and current picture of the Cambria CLI implementation without duplicating source code.