Skip to content

feat(config): HONCHO_HOME env override for per-domain state dir#49

Open
vshuraeff wants to merge 5 commits into
plastic-labs:mainfrom
vshuraeff:honcho-home
Open

feat(config): HONCHO_HOME env override for per-domain state dir#49
vshuraeff wants to merge 5 commits into
plastic-labs:mainfrom
vshuraeff:honcho-home

Conversation

@vshuraeff

@vshuraeff vshuraeff commented May 31, 2026

Copy link
Copy Markdown

Summary

Adds a HONCHO_HOME env var that overrides the plugin's state directory (default ~/.honcho), so a single install can give different directory trees their own config, caches, queue, and logs — e.g. work vs personal projects, kept fully isolated.

# in your work tree (via direnv / a shell wrapper):
export HONCHO_HOME=~/.honcho-work     # its own config.json + caches + activity.log + verbose.log
# everywhere else: unset -> ~/.honcho, byte-identical to today

Motivation

I run one Claude Code install across genuinely separate Honcho workspaces (work vs personal) and need memory partitioned by domain so conclusions — and the local context-cache.json — never cross contexts. Workspace routing alone (the flat workspace field / per-host blocks / the cwd workspaceRules proposed in #41) selects the workspace but still shares one ~/.honcho state dir, so the single, non-workspace-keyed context-cache.json can serve another domain's cached context for up to the TTL. Relocating the whole state dir per tree closes that.

This is complementary to #41: #41 routes the workspace by cwd; this routes the state directory by env. They compose cleanly (cwd → workspace via #41, env → isolated caches/logs via this).

Implementation

  • New exported pure helper getHonchoHome() in plugins/honcho/src/config.ts: returns process.env.HONCHO_HOME (trimmed; leading ~/ expanded via homedir()), else join(homedir(), ".honcho").
  • CONFIG_DIR (config.ts) and CACHE_DIR (cache.ts) now derive from it; log.ts (activity.log) and visual.ts (verbose.log) too, so all state stays co-located. Dropped a now-unused homedir import in cache.ts.

Behaviour for existing users

Unset / empty / whitespace HONCHO_HOME → falls through to ~/.honcho unchanged. No behaviour change unless the var is explicitly set.

Tests

  • plugins/honcho/src/honcho-home.test.tsgetHonchoHome unit tests (unset/empty/whitespace fallback, absolute, ~/ expansion, trim, relative passthrough).
  • plugins/honcho/src/honcho-home-e2e.test.ts + honcho-home-probe.ts — subprocess e2e: each scenario spawns a child with a controlled HOME + HONCHO_HOME (so the module-load-time state-dir constants are captured fresh), performs real writes into throwaway temp dirs, and asserts config/cache/activity.log/verbose.log relocation + co-location, plus no leak to the default dir.
$ bun test src/honcho-home.test.ts src/honcho-home-e2e.test.ts
 12 pass, 0 fail
$ bun x tsc --noEmit   # clean

Verified red phase: reverting the implementation to main fails exactly the relocation/co-location tests while the backward-compat tests still pass.

CHANGELOG updated with an [Unreleased] entry per CONTRIBUTING.md.

Summary by CodeRabbit

  • New Features

    • Added HONCHO_HOME environment variable to override the plugin's state directory location (defaults to ~/.honcho). Supports tilde expansion and absolute paths, relocating all configuration, cache, and logs.
  • Documentation

    • Updated README to document the new HONCHO_HOME environment variable and usage examples.

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@vshuraeff, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 8 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ace0e76-1538-48d1-8a2d-e4066e5f9a2d

📥 Commits

Reviewing files that changed from the base of the PR and between 326d47e and 2e51355.

📒 Files selected for processing (1)
  • plugins/honcho/src/config.ts

Walkthrough

Adds HONCHO_HOME support: new exported getHonchoHome() resolves HONCHO_HOME with tilde expansion and fallback to ~/.honcho; cache, logging, and visual modules now use it; unit tests and subprocess e2e probe validate resolution and co-location; README and CHANGELOG updated.

Changes

HONCHO_HOME State Directory Override

Layer / File(s) Summary
getHonchoHome() core implementation
plugins/honcho/src/config.ts
New exported getHonchoHome() resolves HONCHO_HOME (tilde ~/ expansion, trim, absolute resolution) and CONFIG_DIR now derives from it.
Unit tests for getHonchoHome()
plugins/honcho/src/honcho-home.test.ts
Tests cover unset/empty/whitespace fallback to ~/.honcho, absolute and relative paths, ~/ and ~ expansion, trimming, and isolate env per test.
Module integration across cache, log, and visual
plugins/honcho/src/cache.ts, plugins/honcho/src/log.ts, plugins/honcho/src/visual.ts
cache.ts and log.ts compute CACHE_DIR from getHonchoHome(); visual.ts derives VERBOSE_LOG from getHonchoHome() and ensures the directory exists; cache/log path constants adjusted accordingly.
E2E subprocess test suite with probe harness
plugins/honcho/src/honcho-home-e2e.test.ts, plugins/honcho/src/honcho-home-probe.ts
E2E test spawns a probe with controlled HOME/HONCHO_HOME, probe initializes modules, creates/writes state artifacts, and returns resolved paths and existence checks for assertions.
Docs and changelog
README.md, CHANGELOG.md
README Configuration and Environment Variables sections updated to document HONCHO_HOME; CHANGELOG Unreleased entry documents feature, tilde expansion, fallback behavior, log relocation, and test coverage.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • erosika

Poem

🐰 A burrow to call your own, wherever you roam—
With HONCHO_HOME the rabbit hops free,
Tildes expand and logs come along,
State files gather where home feels like home,
Tests nod approval—hop on, delight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: introducing HONCHO_HOME environment variable for overriding the plugin state directory, which is the primary focus across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@plugins/honcho/src/config.ts`:
- Around line 249-253: getHonchoHome currently returns relative HONCHO_HOME
values verbatim so CONFIG_DIR/CACHE_DIR become unstable across different CWDs;
change getHonchoHome to normalize and return an absolute path by expanding a
bare "~" or "~/" to homedir() and then calling path.resolve(homedir(),
envWithoutTilde) (or path.resolve(env) when env is already absolute) so any
relative value is resolved against the user's home and not the process CWD;
update references to getHonchoHome (used to build CONFIG_DIR/CACHE_DIR) and
adjust the honcho-home.test.ts unit that expected a passthrough to assert the
resolved absolute path instead.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4760c9a4-4021-4c02-bbc9-8baa24ce1e9e

📥 Commits

Reviewing files that changed from the base of the PR and between 8c75206 and 3c0dd6e.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • plugins/honcho/src/cache.ts
  • plugins/honcho/src/config.ts
  • plugins/honcho/src/honcho-home-e2e.test.ts
  • plugins/honcho/src/honcho-home-probe.ts
  • plugins/honcho/src/honcho-home.test.ts
  • plugins/honcho/src/log.ts
  • plugins/honcho/src/visual.ts

Comment thread plugins/honcho/src/config.ts
vshuraeff added 2 commits May 31, 2026 20:22
add jsdoc to getHonchoHome and the ensure*/writeVerbose state-dir helpers plus the e2e test helpers, to clear coderabbit's docstring-coverage check. comments only, no behaviour change.

@coderabbitai coderabbitai Bot 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.

♻️ Duplicate comments (1)
plugins/honcho/src/config.ts (1)

259-261: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Relative HONCHO_HOME is still CWD-dependent despite the stability guarantee.

resolve(env) anchors relative values to the current process CWD, so different hook launch directories can still split state. Anchor relative paths to homedir() instead.

🔧 Proposed fix
   if (env) {
     if (env === "~") return homedir();
-    if (env.startsWith("~/")) return join(homedir(), env.slice(2));
+    if (env.startsWith("~/")) return resolve(homedir(), env.slice(2));
     // resolve any other value (including a relative path) to an absolute path
     // now, so the state dir stays stable regardless of the cwd a hook runs from.
-    return resolve(env);
+    return resolve(homedir(), env);
   }
In Node.js, what base directory does `path.resolve("relative/path")` use, and does `path.resolve(homedir(), "relative/path")` produce a CWD-independent absolute path?
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/honcho/src/config.ts` around lines 259 - 261, The current return of
resolve(env) in HONCHO_HOME handling still makes relative paths CWD-dependent;
change the logic so that when HONCHO_HOME (env) is not absolute (use
path.isAbsolute or similar), resolve it against os.homedir() (homedir()) instead
of the process CWD, and only call path.resolve(homedir(), env) for relative
values while leaving absolute inputs unchanged; update any code paths that call
resolve(env) to use this new conditional resolution so state dir is stable
across hook CWDs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@plugins/honcho/src/config.ts`:
- Around line 259-261: The current return of resolve(env) in HONCHO_HOME
handling still makes relative paths CWD-dependent; change the logic so that when
HONCHO_HOME (env) is not absolute (use path.isAbsolute or similar), resolve it
against os.homedir() (homedir()) instead of the process CWD, and only call
path.resolve(homedir(), env) for relative values while leaving absolute inputs
unchanged; update any code paths that call resolve(env) to use this new
conditional resolution so state dir is stable across hook CWDs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6cbfa9d8-8db4-421a-aafc-6614aaa724d7

📥 Commits

Reviewing files that changed from the base of the PR and between 3c0dd6e and 326d47e.

📒 Files selected for processing (7)
  • README.md
  • plugins/honcho/src/cache.ts
  • plugins/honcho/src/config.ts
  • plugins/honcho/src/honcho-home-e2e.test.ts
  • plugins/honcho/src/honcho-home.test.ts
  • plugins/honcho/src/log.ts
  • plugins/honcho/src/visual.ts
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • plugins/honcho/src/cache.ts
  • plugins/honcho/src/visual.ts
  • plugins/honcho/src/log.ts
  • plugins/honcho/src/honcho-home.test.ts
  • plugins/honcho/src/honcho-home-e2e.test.ts

getConfigDir/getConfigPath/configExists landed in the pr diff scope (adjacent to getHonchoHome) without jsdoc, holding coverage at 77.78%. document them to clear the 80% threshold. comments only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant