fix: scope all CLI commands to current directory in monorepos#102
Open
ninyawee wants to merge 2 commits intovercel-labs:mainfrom
Open
fix: scope all CLI commands to current directory in monorepos#102ninyawee wants to merge 2 commits intovercel-labs:mainfrom
ninyawee wants to merge 2 commits intovercel-labs:mainfrom
Conversation
`getLogPath()` always returned the most recently started session's log file, ignoring which directory the user is in. In a monorepo with multiple d3k instances running simultaneously, this means `d3k logs` could show logs from the wrong project. Now uses `getProjectName()` to match the current directory's session first, falling back to the most recent session if no match is found.
Contributor
|
Someone is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
Extract duplicated `findActiveSessions()` from 5 command files into a shared `utils/session.ts` with `findCurrentSession()` that uses `getProjectName()` to prefer the session matching the current working directory. Commands fixed: - `d3k errors` — was showing wrong project's errors - `d3k fix` — was analyzing wrong project's logs - `d3k crawl` — was crawling wrong project's app URL - `d3k find-component` — was using wrong project's CDP Also removes hardcoded `--cdp 9222` from crawl and find-component (now handled by the auto-inject in cli.ts from the previous PR). Net: -312 lines added, +107 lines removed (205 lines deleted).
d3k logs to current directory in monorepos
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.
Problem
In a monorepo with multiple
d3kinstances running simultaneously, every CLI command that reads session data picks the most recently started session globally — not the one for the current working directory.Affected commands:
logs,errors,fix,crawl,find-component.Each command had its own copy of
findActiveSessions()(duplicated 5 times) that returnedsessions[0]sorted bystartTimewithout checkingprojectName.Additionally,
crawlandfind-componenthardcoded--cdp 9222instead of using the session's actual CDP port.Fix
Extract shared
utils/session.tswithfindActiveSessions()andfindCurrentSession()— usesgetProjectName()to match the current directory's session, falls back to most recent if no match found.Replace all 5 copies in
logs.ts,errors.ts,fix.ts,crawl.ts,find-component.tswith imports from the shared util.Remove hardcoded
--cdp 9222fromcrawlandfind-component— they now calld3k agent-browserwithout--cdp, relying on the auto-inject from the session (see fix: auto-inject--cdpfrom session intod3k agent-browser#103).Net: -312 lines, +107 lines.
Commands audited
d3k logssessions[0]findCurrentSession()d3k errorssessions[0]findCurrentSession()d3k fixsessions[0]findCurrentSession()d3k crawlsessions[0]+ hardcoded CDP 9222findCurrentSession()+ no hardcoded CDPd3k find-componentsessions[0]+ hardcoded CDP 9222findCurrentSession()+ no hardcoded CDPd3k resumecwdd3k agent-browserd3k cdp-portAll 227 existing tests pass. Happy to adjust if this doesn't match your intended design.