feat: add list-cwd action to scope peer discovery by working directory#58
Open
iRonin wants to merge 1 commit into
Open
feat: add list-cwd action to scope peer discovery by working directory#58iRonin wants to merge 1 commit into
iRonin wants to merge 1 commit into
Conversation
intercom({ action: "list-cwd" }) lists only sessions that share the caller's
working directory — the default scope an orchestrator usually wants — while
list stays all-directories. An optional cwd narrows to a specific directory
(absolute, or relative to the caller's cwd; "." means the current cwd).
Directory matching goes through a normalized comparison (new cwd.ts:
normalizeCwd/sameCwd) so a peer whose cwd string differs only by a trailing
slash, a "."/".." segment, or a symlink (e.g. macOS /tmp <-> /private/tmp)
still matches. When the filtered directory has no peers but the caller's own
cwd does, the empty result points back to it so a mistargeted filter is
obvious instead of silently empty.
Adds cwd.test.ts covering normalize/sameCwd: trailing slash, lexical
"."/".." collapse, symlink resolution, and missing-dir fallback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an
intercom({ action: "list-cwd" })action that lists only the sessions sharing the caller's working directory — the scoped-discovery default an orchestrator usually wants — whileliststays all-directories. An optionalcwdnarrows to a specific directory (absolute, or relative to the caller's cwd;"."means the current cwd).Why
When several pi sessions run on one machine across different projects,
listreturns every peer regardless of directory. A coordinating agent almost always wants just the peers in the current working tree.Doing that with a raw
s.cwd === currentCwdstring match is subtly wrong — it hides genuine same-directory peers whose cwd string differs only by:/workvs/work/),./..segment, or/tmp↔/private/tmp, or any symlinked project root).So the new
cwd.tsnormalizes both sides before comparing —resolve()for the lexical variants andrealpathSync()for symlinks (best-effort, with a graceful fallback if the directory no longer exists; memoized since the set of distinct cwds is small and stable).Small robustness touch: if you filter by a directory that has no peers while your own cwd does (easy to do by passing a guessed parent path), the empty result points back to your real cwd and its peer count instead of a silently misleading "no sessions".
Scope
Purely additive — a new action mirroring
list, reusing the existingformatSessionListRowand result conventions. Zero behavior change tolist/send/ask/reply/pending/status.Design note
I chose a separate
list-cwdaction over adding acwdfilter tolist, for explicitness and back-compat (existinglistcallers and output are untouched, and the intent reads clearly at the call site). Happy to refactor into alistfilter instead if you'd prefer a single action.Tests
New
cwd.test.tscoversnormalizeCwd/sameCwd: trailing slash, lexical./..collapse, symlink resolution (real fixture), and the missing-dir fallback. Full suite green (96/96, including the 5 new).