Skip to content

feat(cli): add a global --home store-root flag - #427

Merged
KooshaPari merged 3 commits into
masterfrom
fix/restore-home-flag
Nov 28, 2026
Merged

KooshaPari merged 3 commits into
masterfrom
fix/restore-home-flag

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

User description

Refs #424 — addresses the missing argv-level store override (root cause A). Does not resolve root cause B (success decided at spawn; snapshot cleared before the child proves it resolved its session). Root cause B remains open and needs the restore spawn path to gate snapshot clearing on child liveness/session resolution.

What

  • Added a global --home <PATH> flag (alias --data-dir) to the kcode CLI in src/cli/args.rs, registered as global = true with value_name = "PATH", so it can be placed before any subcommand and applies to the whole process.
  • Added apply_home in src/cli/startup.rs: validates that the value exists and is a directory (metadata().is_dir()), rejects files and missing paths with anyhow::bail!, enforces require_kcode_path so a .jcode home is rejected, then sets KCODE_HOME via crate::env::set_var before store resolution. Called as apply_home(args.home.as_deref())? immediately after Args::parse().
  • Wired --home / --data-dir into is_telemetry_subcommand_invocation's global-flag skip list so the flag is not mistaken for the telemetry subcommand. This does not suppress generic startup bootstrap: telemetry status with an override home still creates logs/, migrations/, and sessions-bak-prune.stamp inside that home, while writing no telemetry identity.
  • Added unit test home_and_data_dir_are_global_and_apply_kcode_home in src/cli/args/tests/startup.rs covering parse of both spellings, rejection of a missing path, rejection of a .jcode directory, and successful KCODE_HOME propagation.
  • Extended telemetry_subcommand_skips_startup_telemetry with cases for --home and --data-dir=/... forms.

Scope

Covered:

  • Argv-level store override exists for the first time: a child can now be pointed at a non-default store via kcode --home <PATH> / kcode --data-dir=<PATH>.
  • Directory validation rejects non-directories and unavailable paths; .jcode homes are rejected in favor of a kcode home.
  • KCODE_HOME is set before any store resolution in run().

Not covered:

Validation

Validated at commit d2ecedb259ac1c17eae0b7e1f5958c3077dc1635, repository /Users/kooshapari/CodeProjects/phenotype/repos/KCode-space/fix/wtree, branch fix/restore-home-flag:

  1. CI at exact head: 13/13 contexts green; Aggregate gate database id 141011891620. This is the authoritative workspace check; no local workspace check is substituted.

  2. cargo test --lib cli::args::tests::startup::home_and_data_dir_are_global_and_apply_kcode_home

    • test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 311 filtered out
    • Run with a neutral TMPDIR. This harness's TMPDIR=~/.jcode/scratch makes tempfile::tempdir() create a path under a .jcode ancestor, which apply_home correctly rejects. With a neutral TMPDIR the test passes. This is a test-robustness caveat, not an apply_home failure.
  3. cargo test --lib cli::startup::tests::telemetry_subcommand_skips_startup_telemetry

    • test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 311 filtered out
  4. cargo fmt --all -- --check exit 0; git diff --check exit 0.

Gaps found in the diff (honest)

  • apply_home rejects a file path (Ok(_) => bail!("--home must point to a directory: …")) and missing paths, so the "value not rejected when it is a file" failure mode is handled. No gap there.
  • No pre-existing --data-dir CLI consumer conflicts: grep of src/ and crates/ found no other --data-dir/--data_dir argument; only internal data_dir variable naming. The alias is safe.
  • The flag does not itself make cross-home restore work end-to-end: it is a prerequisite mechanism. Until the restore spawn path forwards --home <resolved> (or hc run gains --env), a non-default store still cannot reach the child through the hc run --bg --outlive-parent hook. This PR should be described as enabling, not completing, restore: snapshot cleared on spawn, not on resume — child loses store location through hc hook (cross-home restore reports success with 0 windows) #424.
  • apply_home uses std::path::Path::metadata() which follows symlinks; a symlink to a directory passes validation. Not necessarily wrong, but worth noting if a strict "real directory" check is desired.
  • The value must be an absolute directory. require_kcode_path rejects relative paths and jcode-named components, and the value is not canonicalized before being stored in KCODE_HOME.

CodeAnt-AI Description

Choose a store directory with --home or --data-dir

What Changed

  • Set the store directory for a CLI invocation using either global option, including before a subcommand.
  • Reject missing paths, files, and incompatible product directories before startup.
  • Without an override, keep using the configured store directory; telemetry commands also accept the global options.

Impact

✅ Per-invocation store selection
✅ Invalid store paths rejected before startup
✅ Existing store selection preserved when no override is given

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

tx-agent: jcode
tx-validated: test
tx-scope: cli
tx-lane: jcode:session_sunflower_1795863359820_96546bd4d4e73237
Copilot AI balanced review requested due to automatic review settings November 28, 2026 11:47
@codeant-ai

codeant-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

CodeAnt  CodeAnt Review Status

✅  Review completed

Status Commit Started (UTC) Finished (UTC)
✅  #5938b Incremental review completed c798266 Nov 28, 2026 · 13:58 13:58
✅  #35584 Reviewed your PR 3c26c15 Nov 28, 2026 · 11:47 11:50

@codeant-ai

codeant-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c151da8d-828c-41a0-b052-a7995a702dee
Commits

Reviewing files that changed from the base of the PR and between fd01a4a and d2ecedb.

Files selected for processing: 4

  • src/cli/args.rs
  • src/cli/args/tests.rs
  • src/cli/args/tests/startup.rs
  • src/cli/startup.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Nov 28, 2026
@codeant-ai

codeant-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

CodeAnt  CodeAnt Nitpicks

1 code suggestion

1. apply_home leaves KCODE_HOME pointing at this temporary directory; after temp is dropped, later tests may resolve storage through a deleted path and fail depending on test order.

Stale reference · src/cli/args/tests.rs:1111

@codeant-ai

codeant-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: c79826602e3c

Comment thread src/cli/args/tests.rs Resolved
@kilo-code-bot

kilo-code-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0
Files Reviewed (2 files)
  • src/cli/args/tests.rs
  • src/cli/args/tests/startup.rs

The incremental diff is a pure test reorganization: the SavedHome helper and three KCODE_HOME tests were moved verbatim from tests.rs into a new tests/startup.rs submodule (mod startup;). Content is identical; no logic, API, or behavior changes. The prior outdated inline comment (hardcoded /tmp) is already resolved in the moved code, which uses tempfile::tempdir().

Previous Review Summaries (2 snapshots, latest commit c798266)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c798266)

Status: No Issues Found | Recommendation: Merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0
Files Reviewed (2 files)
  • src/cli/args/tests.rs
  • src/cli/startup.rs

Previous review (commit 3c26c15)

Status: 1 Suggestion Found | Recommendation: Merge (address minor test portability)

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
src/cli/args/tests.rs 1105 Test hardcodes /tmp via tempdir_in("/tmp"), which fails on platforms without /tmp (e.g. Windows). Use tempfile::tempdir() for portability.
Files Reviewed (3 files)
  • src/cli/args.rs - 0 issues (global --home/--data-dir flag registered correctly)
  • src/cli/startup.rs - 0 issues (apply_home validates dir, rejects jcode paths via require_kcode_path, sets KCODE_HOME before store resolution; telemetry skip list updated)
  • src/cli/args/tests.rs - 1 suggestion (portability)

Note: The KCODE_HOME-not-reset test-pollution concern (line 1111) was already raised by CodeAnt; not duplicated here.

Fix these issues in Kilo Cloud


Reviewed by free · Input: 23.5K · Output: 2K · Cached: 160.2K

tx-task: #427
tx-intent: prove startup home restoration and sequencing
tx-parent: 3c26c15
tx-agent: jcode
tx-validated: none
tx-scope: startup
tx-lane: jcode:session_maple_1795874139763_383323c231559970
@codeant-ai codeant-ai Bot added size:L This PR changes 100-499 lines, ignoring generated files and removed size:M This PR changes 30-99 lines, ignoring generated files labels Nov 28, 2026
tx-task: #427
tx-intent: split startup tests under size budget
tx-parent: c798266
tx-agent: jcode
tx-validated: lint
tx-scope: test
tx-lane: jcode:session_eagle_1795875099835_ec4792821a662eba
@sonarqubecloud

Copy link
Copy Markdown

@KooshaPari

Copy link
Copy Markdown
Owner Author

Runtime verification at d2ecedb (this branch), real binary kcode v0.93.524-k0.1.0-dev (d2ecedb25), fresh temp homes, KCODE_HOME/telemetry env unset:

Rejected (rc=1, before any store work): --home missing path, regular file, ~/.jcode, relative path; also --home <missing> telemetry status.
Accepted: --home <existing dir>, --data-dir=<existing dir>, and the flag placed after the subcommand (global). --help exits before apply_home (expected).

KCODE_HOME propagation proven by execution: (1) <home>/no_telemetry -> enabled:false, opt_out_source:marker_file; (2) --home <empty> -> telemetry_id:null while the no-flag run reports the real id; (3) the override home receives logs/, migrations/, sessions-bak-prune.stamp and the real store is untouched.

Nuance: the telemetry path still bootstraps generic store state (logs, migrations, prune stamp) in the override home; it writes no telemetry identity. The flag is only excluded from subcommand detection, not from startup bootstrap.

Full evidence: ~/CodeProjects/temp/pr427-runtime/REPORT.md (+ raw results.txt, rejections.txt). Build was local ([mac]) because nixos was unreachable at the time (ssh TCP timeout, twice); incremental debug build, exit 0.

Scope unchanged: root cause B and restore-path forwarding of --home remain out of scope.

@KooshaPari
KooshaPari merged commit 3796baa into master Nov 28, 2026
25 checks passed
@KooshaPari
KooshaPari deleted the fix/restore-home-flag branch November 29, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: Bottom status line readability degrades in crowded multi-pane layouts

2 participants