Skip to content

COR-5419 Populate Cwd from workspace_roots[0] for Cursor handlers#10

Merged
jake-corridor merged 2 commits into
mainfrom
cor-5215-populate-cwd-cursor-handlers
Apr 27, 2026
Merged

COR-5419 Populate Cwd from workspace_roots[0] for Cursor handlers#10
jake-corridor merged 2 commits into
mainfrom
cor-5215-populate-cwd-cursor-handlers

Conversation

@ashwin-corridor

@ashwin-corridor ashwin-corridor commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Populate ctx.Cwd for every unified Cursor handler from input.WorkspaceRoots[0], and add a Cwd field to PromptContext so the Cursor prompt path can carry the workspace root the same way the other unified contexts already do.

Cursor launches hook binaries from its config directory (~/.cursor) rather than the project root, so consumers that fall back to os.Getwd() end up reporting a misleading path. Every Cursor hook payload already includes a workspace_roots array with the actual project directories, so we just thread it through.

Changes in unified.go:

  • StopContextcursor-stop now sets Cwd from workspace_roots[0].
  • OnBeforeExecutioncursor-before-shell falls back to workspace_roots[0] when input.Cwd is empty; cursor-before-mcp populates Cwd from workspace_roots[0].
  • OnAfterFileEditcursor-after-file-edit populates Cwd from workspace_roots[0].
  • PromptContext gains a Cwd field; cursor-before-submit-prompt populates it from workspace_roots[0].
  • New unexported cursorWorkspaceRoot([]string) string helper.

Motivation

Unblocks the consumer-side fix in CorridorSecurity/corridor#4216, which lands a workaround that reads RawCursor.WorkspaceRoots directly. Once this hookshot version is picked up, the consumer can drop that workaround and rely on ctx.Cwd end-to-end on every Cursor handler.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test ./... — all existing tests pass
  • Bump hookshot version in corridor and verify Directory Matches dashboard no longer shows ~/.cursor rows

Made with Cursor


Open in Devin Review

Cursor launches hook binaries from its config directory (~/.cursor)
rather than the project root, so handlers that fall back to os.Getwd()
report a misleading path. Every Cursor hook payload includes a
workspace_roots array with the actual project directories, so use that
to populate ctx.Cwd for stop, before-shell (as a fallback), before-mcp,
after-file-edit, and prompt-submit handlers.

Adds a Cwd field to PromptContext so the Cursor prompt path can carry
the workspace root the same way the other unified contexts already do.

This unblocks the hookshot consumer in CorridorSecurity/corridor PR
#4216, which can now drop the os.Getwd() fallback once it picks up
this hookshot version.

Made-with: Cursor

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: This PR propagates accurate working directory (Cwd) values from Cursor's workspace_roots into multiple contexts and adds a helper; it introduces no command execution, file I/O, or network calls.

Risk: Low risk. The changes only pass contextual strings to handlers and improve the basis for path validation, with no new attack surface or exploitable paths identified.

Recommendations:

  • When handlers use ctx.Cwd for path checks, normalize and bound paths with filepath.Clean and filepath.Rel to the intended project root, treating Cwd as untrusted input.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Covers the cursorWorkspaceRoot helper (nil/empty/single/multiple) and
each unified Cursor handler that now populates ctx.Cwd from
workspace_roots[0]: stop, before-shell (input.Cwd preferred when set,
fallback otherwise), before-mcp, after-file-edit, and
before-submit-prompt. Also pins behavior when workspace_roots is empty.

Made-with: Cursor
@jake-corridor
jake-corridor merged commit ab1cd06 into main Apr 27, 2026
3 checks passed
@jake-corridor jake-corridor changed the title Populate Cwd from workspace_roots[0] for Cursor handlers COR-5419 Populate Cwd from workspace_roots[0] for Cursor handlers Apr 27, 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.

4 participants