Skip to content

fix: prevent EROFS crash when launched outside a git repo#43

Merged
BYK merged 1 commit intomainfrom
fix/erofs-root-path-crash
Mar 20, 2026
Merged

fix: prevent EROFS crash when launched outside a git repo#43
BYK merged 1 commit intomainfrom
fix/erofs-root-path-crash

Conversation

@BYK
Copy link
Owner

@BYK BYK commented Mar 20, 2026

When OpenCode launches outside a git repo, projectPath resolves to / and AGENTS.md file operations attempt to write to the filesystem root (e.g. mkdirSync('/') on macOS → EROFS).

Changes

src/index.ts

  • Added import { join } from "path"
  • Added isValidProjectPath() guard that rejects /, "", and falsy paths
  • Replaced template literal path construction (\${projectPath}/${path}`) with join(projectPath, path)`
  • Guarded both AGENTS.md import (startup) and export (session.idle) blocks with the path check

test/index.test.ts

  • Added unit tests for isValidProjectPath (root, empty, normal, relative paths)
  • Added integration test verifying plugin initializes without crashing when projectPath is /

Fixes #25

When OpenCode launches outside a git repo, projectPath resolves to '/'
and AGENTS.md file operations attempt to write to the filesystem root
(e.g. mkdirSync('//') on macOS → EROFS).

Changes:
- Add isValidProjectPath() guard that rejects '/', '', and falsy paths
- Replace template literal path construction with path.join()
- Guard both AGENTS.md import and export blocks with the path check
- Add unit tests for isValidProjectPath and plugin init with '/' path

Fixes #25
@BYK BYK enabled auto-merge (squash) March 20, 2026 14:52
@BYK BYK merged commit b8aac4e into main Mar 20, 2026
1 check passed
@BYK BYK deleted the fix/erofs-root-path-crash branch March 20, 2026 14:52
@BYK BYK restored the fix/erofs-root-path-crash branch March 20, 2026 14:53
@BYK BYK deleted the fix/erofs-root-path-crash branch March 20, 2026 14:53
@craft-deployer craft-deployer bot mentioned this pull request Mar 20, 2026
2 tasks
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.

EROFS crash when OpenCode launched outside a git repo (//AGENTS.md path)

1 participant