feat: add glob/prefix support to session path mapping#24
Conversation
allows users to map multiple directories to the same session name using glob patterns in the sessions config field. useful for git worktree setups and monorepos. - exact paths take priority over globs - globs sorted by specificity (longest literal prefix wins) - tilde expansion and path.resolve() normalization - empty keys/values are silently skipped - uses Bun.Glob for matching (zero new deps) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
WalkthroughAdded a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@plugins/honcho/src/config.ts`:
- Around line 546-575: The matcher currently compares against raw session keys
so different spellings of the same path can collide; update matchSessionForPath
to first collapse/deduplicate entries by normalized key (use normalizePath(key)
as the map key and let later entries override earlier ones) so the last saved
mapping wins predictably, then perform the existing exact-match pass on
non-globs and the glob pass on entries derived from that deduplicated map (keep
using isGlobPattern, GLOB_META_RE and Bun.Glob for ordering and matching).
In `@README.md`:
- Around line 268-287: Update the "Per-path overrides" docs for the sessions
field to mention that session pattern keys are normalized with path.resolve(),
so any relative pattern (e.g., "**/my-project") is anchored to process.cwd()
rather than matching anywhere in the filesystem; state that users should prefer
absolute paths or ~/... keys (or be aware of the cwd-anchor behavior) and that
this normalization only applies to the per-directory strategy and does not
change precedence rules (exact > more specific glob).
🪄 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: 943af0fa-b080-4766-944b-9b2f8ee59517
📒 Files selected for processing (3)
README.mdplugins/honcho/src/config.test.tsplugins/honcho/src/config.ts
relative paths in the global config are always a mistake — resolve() would silently anchor them to process.cwd(), producing non-deterministic matches. now only keys starting with / or ~ are considered. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
plugins/honcho/src/config.ts (1)
555-568:⚠️ Potential issue | 🟠 MajorEquivalent normalized keys are still order-dependent.
Line 556 compares normalized paths, but the matcher still walks the original
sessionsentries. If the config contains multiple spellings of the same path or glob, the older spelling still wins, so a later save can remain invisible and deletes stay non-deterministic. Please deduplicate by normalized key before the exact/glob passes so the last write wins predictably.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugins/honcho/src/config.ts` around lines 555 - 568, The code still iterates the original entries so different spellings of the same path/glob are order-dependent; deduplicate by normalized key first so the last write wins. Build a Map keyed by normalizePath(key) (use the same normalizePath/GLOB_META_RE helpers) while iterating the original entries and always overwrite the Map entry (map.set(normalizedKey, [key, name])) so later entries win; then replace uses of entries with Array.from(map.values()) for the exact-match loop and for the globEntries creation/sort so both exact and glob passes operate on deduplicated, normalized keys.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@plugins/honcho/src/config.ts`:
- Around line 13-18: The session-key filter currently accepts any "~" prefixed
key but normalizePath only expands "~" and "~/...", causing keys like
"~worktree" to be left unresolved; update the predicate used where session keys
are filtered to match normalizePath's supported patterns by importing isAbsolute
from "path" and replacing the predicate with: key === "~" ||
key.startsWith("~/") || isAbsolute(key); reference the normalizePath function
and the session-key filter (the predicate that checks keys) when making this
change.
---
Duplicate comments:
In `@plugins/honcho/src/config.ts`:
- Around line 555-568: The code still iterates the original entries so different
spellings of the same path/glob are order-dependent; deduplicate by normalized
key first so the last write wins. Build a Map keyed by normalizePath(key) (use
the same normalizePath/GLOB_META_RE helpers) while iterating the original
entries and always overwrite the Map entry (map.set(normalizedKey, [key, name]))
so later entries win; then replace uses of entries with Array.from(map.values())
for the exact-match loop and for the globEntries creation/sort so both exact and
glob passes operate on deduplicated, normalized keys.
🪄 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: 77c0d08b-c9b3-498e-85b9-3b8f3e58d5d5
📒 Files selected for processing (2)
plugins/honcho/src/config.test.tsplugins/honcho/src/config.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- plugins/honcho/src/config.test.ts
…tterns
~worktree would pass startsWith("~") but normalizePath only expands
~/... and bare ~, so it'd fall through to resolve() and anchor to cwd.
use isAbsolute() instead, which also covers Windows paths.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
plugins/honcho/src/config.test.ts (1)
117-126: Clarify comment: specificity is equal, length is the tie-breaker.The test name says "** wins tie-break by length" but the comment only says "** is longer so it sorts first and wins." It might be worth noting explicitly that both patterns have equal specificity (same
firstMetaposition) since readers might wonder why*isn't considered more specific.Suggested comment clarification
test("** vs * specificity: ** wins tie-break by length for direct children", () => { const sessions = { "~/Code/*": "shallow", "~/Code/**": "deep", }; - // Both match, ** is longer so it sorts first and wins + // Both have firstMeta at same position (equal specificity), ** is longer so it wins tie-break expect(matchSessionForPath(`${HOME}/Code/foo`, sessions)).toBe("deep");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@plugins/honcho/src/config.test.ts` around lines 117 - 126, Update the test comment (and optionally the test name) to clarify that both patterns ("~/Code/*" and "~/Code/**") have equal specificity (same firstMeta position) and therefore the tie-breaker is length so the longer "**" sorts first; locate the comment inside the test named "** vs * specificity: ** wins tie-break by length for direct children" and change the inline comment to explicitly state "specificity is equal, tie-break by pattern length, so ** wins."
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@plugins/honcho/src/config.test.ts`:
- Around line 144-148: The test uses process.cwd() which can be
environment-dependent and may accidentally match the "~/Code/foo" entry; update
the test that calls matchSessionForPath so it uses a synthetic,
guaranteed-nonmatching path (e.g., construct a path like `${HOME}/Code/not-this`
or another clearly distinct path) instead of process.cwd(), ensuring the
sessions map { "": "...", "relative/path": "...", "~worktree": "...",
"~/Code/foo": "real" } will not match and the expectation
matchSessionForPath(..., sessions) toBeNull() is stable.
---
Nitpick comments:
In `@plugins/honcho/src/config.test.ts`:
- Around line 117-126: Update the test comment (and optionally the test name) to
clarify that both patterns ("~/Code/*" and "~/Code/**") have equal specificity
(same firstMeta position) and therefore the tie-breaker is length so the longer
"**" sorts first; locate the comment inside the test named "** vs * specificity:
** wins tie-break by length for direct children" and change the inline comment
to explicitly state "specificity is equal, tie-break by pattern length, so **
wins."
🪄 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: 711b7506-cfd8-431f-9b0d-546e1bca2535
📒 Files selected for processing (2)
plugins/honcho/src/config.test.tsplugins/honcho/src/config.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- plugins/honcho/src/config.ts
Summary
sessionsconfig field so entries like~/Code/project.worktrees/*match multiple directories to the same session namepath.resolve()normalization on both keys and cwdBun.Globfor matching — zero new dependencies*,**,?,[...],{a,b}), specificity ordering, normalization, and edge casesMotivation
Users with git worktree setups need to map multiple directories to the same session without adding an explicit config entry per path:
{ "sessions": { "~/Code/project": "my-project", "~/Code/project.worktrees/*": "my-project" } }Test plan
bun test src/config.test.ts— 23/23 passingbunx tsc --noEmit— clean~/.honcho/config.json, launch Claude Code in matching directories, verify session name via/honcho:status🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Tests