Skip to content

fix(opencode): handle Windows project basenames#656

Open
dnlrsls wants to merge 7 commits into
Gentleman-Programming:mainfrom
dnlrsls:fix/652-windows-project-path
Open

fix(opencode): handle Windows project basenames#656
dnlrsls wants to merge 7 commits into
Gentleman-Programming:mainfrom
dnlrsls:fix/652-windows-project-path

Conversation

@dnlrsls

@dnlrsls dnlrsls commented Jul 23, 2026

Copy link
Copy Markdown

Linked Issue

Closes #652

PR Type

  • type:bug - Bug fix
  • type:feature - New feature
  • type:docs - Documentation only
  • type:refactor - Code refactoring (no behavior change)
  • type:chore - Maintenance, dependencies, tooling
  • type:breaking-change - Breaking change

Summary

  • Derive OpenCode project basenames from both Windows and POSIX separators.
  • Apply the same basename logic to Git-root fallback, cwd fallback, and project migration.
  • Add runtime regressions for Windows compaction, migration, and preserved POSIX behavior.

Changes

File Change
plugin/opencode/engram.ts Add separator-agnostic project basename handling.
plugin/opencode/engram.test.ts Add Windows and POSIX runtime regression coverage.
internal/setup/plugins/opencode/engram.ts Synchronize the embedded OpenCode plugin copy.

Test Plan

  • Unit tests pass locally: go test ./...
  • E2E tests pass locally: go test -tags e2e ./internal/server/...
  • Manually tested the affected functionality

Additional verification:

  • node --test plugin/opencode/engram.test.ts (3 passed)
  • node --check plugin/opencode/engram.ts
  • node --check internal/setup/plugins/opencode/engram.ts
  • go test ./internal/setup -run OpenCode -count=1
  • Canonical and embedded plugin copies have identical SHA-256 hashes.

go test ./... was attempted on Windows. It still hits unrelated existing Windows-specific failures and a cmd/engram timeout; the affected OpenCode-focused tests pass, and Linux CI remains authoritative for the full suite.

Automated Checks

Check What it verifies Status
Check Issue Reference PR body contains Closes #N / Fixes #N / Resolves #N Pending
Check Issue Has status:approved Linked issue has status:approved label Pending
Check PR Has type: Label* PR has exactly one type:* label Pending
Unit Tests go test ./... passes Pending
E2E Tests go test -tags e2e ./internal/server/... passes Pending

Contributor Checklist

  • I linked an approved issue above (Closes #N)
  • I added exactly one type: label to this PR
  • I ran unit tests locally: go test ./...
  • I ran e2e tests locally: go test -tags e2e ./internal/server/...
  • Docs updated (not required; no user-facing workflow changed)
  • Commits follow conventional commits format
  • No Co-Authored-By trailers in commits

Notes for Reviewers

The bounded reliability review approved this candidate with two non-blocking warnings: trailing directory separators are not normalized, and the TypeScript regression file is not yet registered in repository CI. Both are intentionally left as follow-up scope rather than changing the frozen candidate after approval.

Summary by CodeRabbit

  • Bug Fixes
    • Improved project name detection for Windows-style paths by correctly extracting the last non-empty directory segment across both / and \.
    • Made migration context derivation consistent during compaction recovery, ensuring accurate old_project/project values and correct /projects/migrate request behavior (including skipping migration when unchanged).
  • Tests
    • Added coverage for experimental.session.compacting, validating request payloads and triggering conditions across Windows/POSIX paths and edge cases (e.g., trailing separators, nested directories, and Git-root-derived basenames).

@dnlrsls dnlrsls added the type:bug Bug fix label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The OpenCode Engram plugin now derives project names with a separator-agnostic basename helper. Tests cover Windows paths in compaction recovery and migration, plus the existing POSIX fallback.

Changes

OpenCode project naming

Layer / File(s) Summary
Cross-platform basename extraction
internal/setup/plugins/opencode/engram.ts, plugin/opencode/engram.ts
Adds basename extraction for / and \ separators and uses paired project-name values for fallback and migration handling.
Path handling regression coverage
plugin/opencode/engram.test.ts
Tests Windows basename handling, trailing separators, Git-root fallback, migration behavior, and POSIX fallback behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 651 — Directly matches the Windows path-handling fix and regression tests in this PR.

Suggested reviewers: gentleman-programming

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing Windows project basename handling in the OpenCode plugin.
Linked Issues check ✅ Passed The changes address #652 by using cross-platform basename logic, including the oldProject path, with Windows regression coverage and POSIX behavior preserved.
Out of Scope Changes check ✅ Passed The added helper, synced plugin copy, and regression tests are all directly in scope for the Windows basename fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/setup/plugins/opencode/engram.ts`:
- Around line 156-159: Update basename in
internal/setup/plugins/opencode/engram.ts at lines 156-159 to filter empty path
components before selecting the final segment, preserving "unknown" for empty
paths and returning the actual final directory for trailing separators. Apply
the identical change to basename in plugin/opencode/engram.ts at lines 156-159
to keep both implementations synchronized.

In `@plugin/opencode/engram.test.ts`:
- Around line 37-48: Add a test covering the Git-root fallback in the compaction
recovery flow, alongside the existing Windows basename test. Configure the Git
command mock so remote get-url fails while rev-parse --show-toplevel returns a
Windows path, then assert the generated context uses the basename as the project
name rather than the full path.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9cc683be-aaf9-41af-8791-a0b65211c58e

📥 Commits

Reviewing files that changed from the base of the PR and between 763a6ba and c6eb13b.

📒 Files selected for processing (3)
  • internal/setup/plugins/opencode/engram.ts
  • plugin/opencode/engram.test.ts
  • plugin/opencode/engram.ts

Comment thread plugin/opencode/engram.test.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/setup/plugins/opencode/engram.ts`:
- Around line 156-159: Update basename in
internal/setup/plugins/opencode/engram.ts (lines 156-159) and
plugin/opencode/engram.ts (lines 156-159) to detect Windows drive-root paths
such as C:\ and C:/ and return the existing unknown fallback instead of the
drive label; add regression coverage for both root forms and ensure both
implementations behave identically.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 25b80757-60da-4ea8-abf6-265203e28bd3

📥 Commits

Reviewing files that changed from the base of the PR and between c6eb13b and b8ee6d6.

📒 Files selected for processing (3)
  • internal/setup/plugins/opencode/engram.ts
  • plugin/opencode/engram.test.ts
  • plugin/opencode/engram.ts

Comment thread internal/setup/plugins/opencode/engram.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugin/opencode/engram.test.ts (1)

11-31: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Restore mocked globals after each test.

createPlugin overwrites globalThis.Bun and globalThis.fetch without cleanup, so later tests can observe these mocks and become order-dependent. Return a cleanup callback or restore both globals in an afterEach/finally path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugin/opencode/engram.test.ts` around lines 11 - 31, Update createPlugin to
capture the original globalThis.Bun and globalThis.fetch values before
installing mocks, and provide cleanup that restores both globals after each
test; ensure all tests invoke this cleanup through afterEach or a finally path
so mocked state cannot leak between tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/setup/plugins/opencode/engram.ts`:
- Around line 204-205: The migration key extraction in both plugin copies must
handle Windows paths. In internal/setup/plugins/opencode/engram.ts and
plugin/opencode/engram.ts, update oldProject to use basename(ctx.directory);
adjust the regression expectation in plugin/opencode/engram.test.ts so
old_project is "Blackie".

---

Outside diff comments:
In `@plugin/opencode/engram.test.ts`:
- Around line 11-31: Update createPlugin to capture the original globalThis.Bun
and globalThis.fetch values before installing mocks, and provide cleanup that
restores both globals after each test; ensure all tests invoke this cleanup
through afterEach or a finally path so mocked state cannot leak between tests.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5974931a-2e25-4a4e-8d36-ddfff73cd410

📥 Commits

Reviewing files that changed from the base of the PR and between b8ee6d6 and 560fe42.

📒 Files selected for processing (3)
  • internal/setup/plugins/opencode/engram.ts
  • plugin/opencode/engram.test.ts
  • plugin/opencode/engram.ts

Comment thread internal/setup/plugins/opencode/engram.ts Outdated

@coderabbitai coderabbitai 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.

♻️ Duplicate comments (1)
internal/setup/plugins/opencode/engram.ts (1)

156-158: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Handle Windows drive roots consistently in both copies and tests.

The helper returns "C:" for C:\\ and C:/, producing an invalid project name when OpenCode runs from a drive root.

  • internal/setup/plugins/opencode/engram.ts#L156-L158: return "unknown" when the only remaining segment matches /^[A-Za-z]:$/.
  • plugin/opencode/engram.ts#L156-L158: apply the identical guard in the embedded copy.
  • plugin/opencode/engram.test.ts#L50-L60: add regression assertions for both C:\\ and C:/.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/setup/plugins/opencode/engram.ts` around lines 156 - 158, Update
basename in internal/setup/plugins/opencode/engram.ts:156-158 and
plugin/opencode/engram.ts:156-158 to return "unknown" when the extracted segment
is a Windows drive root matching /^[A-Za-z]:$/. Add regression assertions in
plugin/opencode/engram.test.ts:50-60 covering both C:\ and C:/ inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@internal/setup/plugins/opencode/engram.ts`:
- Around line 156-158: Update basename in
internal/setup/plugins/opencode/engram.ts:156-158 and
plugin/opencode/engram.ts:156-158 to return "unknown" when the extracted segment
is a Windows drive root matching /^[A-Za-z]:$/. Add regression assertions in
plugin/opencode/engram.test.ts:50-60 covering both C:\ and C:/ inputs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6489feb6-1d9e-4aed-ace8-c951a7cf8621

📥 Commits

Reviewing files that changed from the base of the PR and between 560fe42 and 4cd6312.

📒 Files selected for processing (3)
  • internal/setup/plugins/opencode/engram.ts
  • plugin/opencode/engram.test.ts
  • plugin/opencode/engram.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(opencode): compaction recovery emits absolute Windows path as project

1 participant