Documentation
¶
Overview ¶
Package cmdutil provides shared helpers for CLI command implementations.
Index ¶
- Variables
- func IndexHashesComputed() int64
- func IsVaultRoot(dir string) bool
- func LoadRegistry(vaultPath string) (*schema.Registry, error)
- func RequireRealVaultIfGuessed(cmd *cobra.Command, vaultPath, commandName string) error
- func WriteJSON(w io.Writer, command string, result interface{}, vaultPath, indexHash string) error
- func WriteJSONError(w io.Writer, command, code, message string) error
- type VaultDB
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyWritten = envelope.ErrAlreadyWritten
ErrAlreadyWritten signals that an error envelope was already written. Aliased to the envelope package's sentinel so the command layer and the query layer raise the same one and main.go needs to recognize only that.
Functions ¶
func IndexHashesComputed ¶ added in v0.10.0
func IndexHashesComputed() int64
IndexHashesComputed reports how many full-file index hashes this process has computed. For tests: a command that does not report the hash must not pay for reading the whole index.
func IsVaultRoot ¶ added in v0.4.2
IsVaultRoot reports whether dir is a vault: it must hold the type registry at .vaultmind/config.yaml, not merely a .vaultmind/ directory.
The bare-directory test was wrong in the one place it mattered most. The tool keeps its model cache at ~/.vaultmind/models, so on any machine that has downloaded BGE-M3 weights the marker exists in the home directory — and the guessed-vault guard, whose whole job is to refuse a directory the user never chose, waved $HOME through and indexed it. Walk-up skips $HOME; the fallback to "." did not. A registry is written by `init` (or by `index` when a vault is named), never by a cache.
Exported so callers that must require a REAL vault even when the path was named — a propose-only reader, say — can ask without spelling the path.
func LoadRegistry ¶
LoadRegistry loads only the type registry from a vault's .vaultmind/config.yaml without opening the index database. Use this when you need schema information (e.g., for live validation) but not the index itself.
func RequireRealVaultIfGuessed ¶ added in v0.4.2
RequireRealVaultIfGuessed enforces the guessed-vs-named rule on its own, for commands that act on a vault path without going through OpenVaultDBOrWriteErr. With --json set it writes the error envelope and returns ErrAlreadyWritten.
It exists because guarding only the readers left the writer open. `index` is the command that CREATES .vaultmind/index.db — the marker every later walk-up discovers — so a guess there does not merely answer from the wrong vault once: it promotes the directory permanently and captures every future invocation from any child of it. The rule was written for `ask` in v0.3.0 and applied again to `arc candidates` in v0.4.0, both times without reaching the command that mints the marker.
func WriteJSONError ¶
WriteJSONError writes a JSON error envelope to the writer. It returns ErrAlreadyWritten on success. Every caller does `return cmdutil.WriteJSONError(...)`, and while this returned nil on success each of those was a command that wrote status "error" and then exited 0 — so `vaultmind … --json || handle_failure` never fired. Returning the sentinel from here fixes all of them at once and, more to the point, makes the broken combination unexpressible rather than merely absent.
Types ¶
type VaultDB ¶
type VaultDB struct {
DB *index.DB
Config *vault.Config
Reg *schema.Registry
// contains filtered or unexported fields
}
VaultDB bundles the commonly needed vault resources.
func OpenVaultDB ¶
OpenVaultDB loads config, opens the index DB, and creates the type registry.
func OpenVaultDBOrWriteErr ¶
OpenVaultDBOrWriteErr opens the vault DB. On failure with --json set, writes a JSON error envelope and returns ErrAlreadyWritten.
When no vault was named — no --vault, no VAULTMIND_VAULT — the path is whatever discovery fell back to, normally the working directory. Opening a non-vault directory in that case is wrong twice over: the command answers from a vault the user never chose (reporting "ok" and zero hits, which reads as "your vault has nothing on this" rather than "you have no vault"), and OpenVaultDB CREATES .vaultmind/index.db there on the way — quietly promoting that directory to a vault that every future walk-up will find. So a guessed path must prove it is already a vault before it is opened, while a named one keeps the permissive behaviour that lets any directory serve as a vault.
func (*VaultDB) GetIndexHash ¶
GetIndexHash returns the SHA-256 hash of the SQLite database file, computing it on the first call and returning the same value after.