Skip to content

fix: scope all CLI commands to current directory in monorepos#102

Open
ninyawee wants to merge 2 commits intovercel-labs:mainfrom
ninyawee:fix/logs-monorepo-scoping
Open

fix: scope all CLI commands to current directory in monorepos#102
ninyawee wants to merge 2 commits intovercel-labs:mainfrom
ninyawee:fix/logs-monorepo-scoping

Conversation

@ninyawee
Copy link
Copy Markdown

@ninyawee ninyawee commented Apr 6, 2026

Problem

In a monorepo with multiple d3k instances 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 returned sessions[0] sorted by startTime without checking projectName.

Additionally, crawl and find-component hardcoded --cdp 9222 instead of using the session's actual CDP port.

Fix

  1. Extract shared utils/session.ts with findActiveSessions() and findCurrentSession() — uses getProjectName() to match the current directory's session, falls back to most recent if no match found.

  2. Replace all 5 copies in logs.ts, errors.ts, fix.ts, crawl.ts, find-component.ts with imports from the shared util.

  3. Remove hardcoded --cdp 9222 from crawl and find-component — they now call d3k agent-browser without --cdp, relying on the auto-inject from the session (see fix: auto-inject --cdp from session into d3k agent-browser #103).

Net: -312 lines, +107 lines.

Commands audited

Command Before After
d3k logs sessions[0] findCurrentSession()
d3k errors sessions[0] findCurrentSession()
d3k fix sessions[0] findCurrentSession()
d3k crawl sessions[0] + hardcoded CDP 9222 findCurrentSession() + no hardcoded CDP
d3k find-component sessions[0] + hardcoded CDP 9222 findCurrentSession() + no hardcoded CDP
d3k resume Already uses cwd No change needed
d3k agent-browser See #103 See #103
d3k cdp-port See #103 See #103

All 227 existing tests pass. Happy to adjust if this doesn't match your intended design.

`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.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 6, 2026

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).
@ninyawee ninyawee changed the title fix: scope d3k logs to current directory in monorepos fix: scope all CLI commands to current directory in monorepos Apr 6, 2026
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