feat(config): cwd-based workspaceRules routing#41
Conversation
Adds a new top-level config field `workspaceRules: WorkspaceRule[]` that
selects the active Honcho workspace based on the current working directory.
Useful when one Claude Code install spans multiple Honcho workspaces (e.g.
work / personal / experiments), and which workspace to use depends on which
project you're in.
Resolution order (highest priority first):
1. workspaceRules (NEW) — first cwdPrefix match wins
2. globalOverride (existing)
3. hosts.<host>.workspace (existing)
4. HONCHO_WORKSPACE env / raw.workspace / DEFAULT_WORKSPACE[host]
`cwdPrefix` supports leading `~` for $HOME. Matched as a prefix, not a glob.
When no rule matches, returns null and falls through to the existing chain,
so single-workspace setups are unaffected.
Example ~/.honcho/config.json:
{
"workspaceRules": [
{ "cwdPrefix": "~/work", "workspace": "work" },
{ "cwdPrefix": "~/personal", "workspace": "personal" },
{ "cwdPrefix": "~", "workspace": "default" }
]
}
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
10 tests covering no-rules / empty-rules short-circuit, exact and subdirectory matching, sibling-directory rejection, first-match ordering, tilde expansion (with and without trailing path), trailing- slash normalisation on both rule prefix and cwd, and rule-order determinism among identical prefixes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughAdds cwd-prefix-based workspace routing via a new ChangesWorkspace routing via cwd prefix rules
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 38-42: The cwd-prefix matching currently compares normalized and
prefix using a hardcoded "/" which fails on Windows; update the logic inside the
function that computes normalized and prefix (variables normalized, prefix, and
the loop over rules with rule.cwdPrefix and expandHome) to be separator-agnostic
by normalizing path separators before trimming and comparing (e.g., replace
backslashes with forward slashes or use Node's path.sep-aware normalization) and
then perform the equality and startsWith checks against the normalized forms so
matches work on Windows too.
🪄 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: ea9c97a0-732d-4acb-815d-ab34725ef17e
📒 Files selected for processing (3)
CHANGELOG.mdplugins/honcho/src/config.test.tsplugins/honcho/src/config.ts
CodeRabbit flagged that `resolveWorkspaceFromCwd` hardcoded "/" as the path separator, so Windows cwds (which `process.cwd()` returns with `\`) would miss valid subdirectory matches and fall through to the wrong resolution branch. Normalise both `cwd` and the rule's expanded `cwdPrefix` to forward slashes before trim + prefix comparison, and add four Windows-cwd tests (forward-slash prefix, backslash prefix, sibling rejection, trailing-backslash normalisation). Refs: plastic-labs#41 (comment)
|
Pushed Fix ( Tests (
CHANGELOG — added a second I left the 25%-docstring-coverage warning alone — the new exports ( |
Summary
Adds a
workspaceRulesarray to the config file. When set, each rule maps acwdPrefix(with~expanded to$HOME) to aworkspacename. Rules are checked in order; the first matching prefix wins. When no rule matches — or whenworkspaceRulesis unset — resolution falls through unchanged to the existingglobalOverride/ host-block / default chain, so behaviour for current users is byte-identical.{ "hosts": { "claude_code": { "workspace": "default", "aiPeer": "claude" } }, "workspaceRules": [ { "cwdPrefix": "~/code/work", "workspace": "work" }, { "cwdPrefix": "~/code/personal", "workspace": "personal" }, { "cwdPrefix": "~/code", "workspace": "experiments" } ] }Motivation
I run one Claude Code install across genuinely separate Honcho workspaces (work vs personal vs experiments) and want memory partitioned by domain so conclusions don't leak across contexts. Today the only workspace knobs are the flat
workspacefield, per-host blocks, andglobalOverride— all of which resolve to a single workspace per process. Without cwd routing the only option is a wrapper script per project that exports a different config path, which is operationally clumsy.How it relates to other open routing PRs
The other in-flight routing PRs all partition memory within a single workspace:
sessions{}mapper-repostrategy fromgit rev-parse --show-toplevelHONCHO_PROFILEenv varHONCHO_SESSIONenv varThese are complementary.
HONCHO_PROFILE(#33) is the closest neighbour — it routes the peer identity, this routes the workspace. They can coexist (e.g. cwd→workspace, thenHONCHO_PROFILE→aiPeer within it).Implementation
plugins/honcho/src/config.ts:WorkspaceRuleinterface and pure helperresolveWorkspaceFromCwd(cwd, rules).workspaceRules?: WorkspaceRule[]field onHonchoFileConfig.resolveConfigat the top of the precedence chain — whenresolveWorkspaceFromCwdreturns a non-null value, it setsworkspaceand uses the host block'saiPeer(or default) for identity; otherwise the existing logic runs untouched.~expanded to$HOMEforcwdPrefixand trailing slashes normalised on both sides.~/code/workdoes NOT match~/code/work-old(sibling directory).Tests
plugins/honcho/src/config.test.ts— 10 unit tests covering:/workmust not match/work-oldor/workshop)~expansion (with and without trailing path)Behaviour for existing users
workspaceRules: no-op, same code path as today.workspaceRulesbut cwd matches no rule: also no-op.CHANGELOG updated with an
[Unreleased]entry perCONTRIBUTING.md.Summary by CodeRabbit
New Features
~) expansion is supported; if no rule matches, existing resolution behavior applies.Bug Fixes