Skip to content

Commit 5860d14

Browse files
committed
cli: single-site the store path, and record why the connection rung must NOT be
WERNI's duplicate-value audit run on this tree (grep the DEFAULT VALUE, not the function, because an internal copy twelve lines from the original reads as one behaviour). Two candidates, opposite dispositions, and the second is the useful one. *** THE ONE I NEARLY BROKE *** The connection ladder's HOME rung rebuilds `.local/share` — the prefix `default_data_home()` derives twelve lines above it. That is exactly the shape the audit exists to find, and collapsing them would have been a defect: default_data_home() where THIS MODULE's data lives — XDG_DATA_HOME first, then the Windows AppData rungs, then HOME/.local/share the ladder's rung where `ck` LOOKS — HOME only, matching subc-core's PROD_CONNECTION_RELATIVE_PATH Re-derived at source: `ck`'s reader consults HOME and does NOT consult XDG_DATA_HOME for that rung. So routing mine through `default_data_home()` would make this CLI look somewhere `ck` never looks the moment an operator sets XDG_DATA_HOME — reintroducing the looks-where-ck-does-not class that the SUBC_CONNECTION_FILE fix closed in this same function two commits ago, by way of tidying. Recorded at the site rather than in this message, because the audit will report the pair again and the obvious remedy is the defect. A reported duplicate is a candidate until it is resolved against the other side's AUTHORITY; these two have different authorities. *** THE ONE THAT WAS REAL *** Five identical `global.data_dir.join("store.db")` calls across the lease-free read verbs. No second authority makes that correct — the daemon opens the same file from the same dir through cortexkit-store — so it is five places for a rename to land in four. One helper now. Gate green, floor unchanged (no tests added; both changes are shape).
1 parent 4f8b1f8 commit 5860d14

1 file changed

Lines changed: 36 additions & 5 deletions

File tree

crates/credentials-module/src/bin/credentials_cli.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ fn request_admin_status(global: &GlobalArgs) -> Result<serde_json::Value, CliErr
26832683
}
26842684
}
26852685

2686-
let db = global.data_dir.join("store.db");
2686+
let db = store_path(global);
26872687
if !db.exists() {
26882688
return Err(CliError::Usage(format!(
26892689
"no vault at {} (run 'ck auth bootstrap' first)",
@@ -3195,7 +3195,7 @@ fn cmd_audit(global: &GlobalArgs, args: &[String]) -> Result<(), CliError> {
31953195
// plaintext, so this needs neither the lease nor a master key. It used to take the
31963196
// lease, which meant the forensic log was unreadable while the vault ran -- i.e.
31973197
// whenever anyone actually wanted it.
3198-
let db = global.data_dir.join("store.db");
3198+
let db = store_path(global);
31993199
if !db.exists() {
32003200
return Err(CliError::Usage(format!(
32013201
"no vault at {} (run 'ck auth bootstrap' first)",
@@ -3274,7 +3274,7 @@ fn cmd_events(global: &GlobalArgs, args: &[String]) -> Result<(), CliError> {
32743274
.map_err(|e| CliError::Usage(format!("--limit not an integer: {e}")))?
32753275
.unwrap_or(20);
32763276

3277-
let db = global.data_dir.join("store.db");
3277+
let db = store_path(global);
32783278
if !db.exists() {
32793279
return Err(CliError::Usage(format!(
32803280
"no vault at {} (run 'ck auth bootstrap' first)",
@@ -3453,7 +3453,7 @@ fn cmd_grants(global: &GlobalArgs) -> Result<(), CliError> {
34533453
fn cmd_usable(global: &GlobalArgs) -> Result<(), CliError> {
34543454
use credentials_core::usable::{self, ScanError, Usability};
34553455

3456-
let db = global.data_dir.join("store.db");
3456+
let db = store_path(global);
34573457
if !db.exists() {
34583458
return Err(CliError::Usage(format!(
34593459
"no vault at {} (run 'ck auth bootstrap' first)",
@@ -3667,7 +3667,7 @@ fn warn_unsafe_opencode_tombstones() {
36673667
/// fingerprint names, so a vault left mid-rotation still verifies) and reads through a
36683668
/// lease-free connection, exactly like `events` and `usable`.
36693669
fn cmd_verify_audit(global: &GlobalArgs) -> Result<(), CliError> {
3670-
let db = global.data_dir.join("store.db");
3670+
let db = store_path(global);
36713671
if !db.exists() {
36723672
return Err(CliError::Usage(format!(
36733673
"no vault at {} (run 'ck auth bootstrap' first)",
@@ -3821,6 +3821,17 @@ fn resolve_data_home_from(
38213821
/// `~/.local/share/cortexkit/run/subc-connection.json`. Only an EXISTING file is
38223822
/// returned — no daemon means the offline lease path, which is the correct
38233823
/// fallback, not an error.
3824+
/// The vault store's path under a data directory.
3825+
///
3826+
/// One site rather than five identical `join("store.db")` calls. The filename is not
3827+
/// this CLI's to choose -- the daemon opens it through `cortexkit-store` from the same
3828+
/// data dir -- so a literal repeated per read verb is five places for a rename to land
3829+
/// in four. Unlike the connection-file rung above, there is no second authority here
3830+
/// that would make the duplication correct.
3831+
fn store_path(global: &GlobalArgs) -> PathBuf {
3832+
global.data_dir.join("store.db")
3833+
}
3834+
38243835
fn discover_subc_connection_file() -> Option<PathBuf> {
38253836
const CONNECTION_FILE_NAME: &str = "subc-connection.json";
38263837

@@ -3854,6 +3865,26 @@ fn discover_subc_connection_file() -> Option<PathBuf> {
38543865
return Some(p);
38553866
}
38563867
}
3868+
// *** THIS REBUILDS THE PREFIX `default_data_home()` DERIVES TWELVE LINES ABOVE, AND
3869+
// THAT DUPLICATION IS CORRECT. DO NOT COLLAPSE THEM. ***
3870+
//
3871+
// They look like one behaviour written twice and they answer different questions:
3872+
//
3873+
// default_data_home() where THIS MODULE's data lives -- XDG_DATA_HOME first,
3874+
// then the Windows AppData rungs, then HOME/.local/share
3875+
// this rung where `ck` LOOKS for a connection file -- HOME only,
3876+
// matching subc-core's PROD_CONNECTION_RELATIVE_PATH
3877+
//
3878+
// `ck`'s reader consults HOME and does NOT consult XDG_DATA_HOME for this rung
3879+
// (bin/ck.rs, `connection_file_candidates_with`, re-derived at source 2026-09-05).
3880+
// So routing this through `default_data_home()` would make the CLI look somewhere
3881+
// `ck` never looks the moment an operator sets XDG_DATA_HOME -- reintroducing the
3882+
// looks-where-ck-does-not class that the SUBC_CONNECTION_FILE rung above was added
3883+
// to close, in the same function, by way of tidying.
3884+
//
3885+
// Recorded because a duplicate-value audit REPORTS THIS PAIR, and the obvious
3886+
// remedy is the defect. A reported duplicate is a candidate until it is resolved
3887+
// against the other side's authority; these two have different authorities.
38573888
if let Some(home) = non_empty_env("HOME") {
38583889
let p = PathBuf::from(home)
38593890
.join(".local")

0 commit comments

Comments
 (0)