Skip to content

refactor: use import.meta.dirname and fs/promises in opencode plugin#1247

Open
jjangga0214 wants to merge 3 commits into
obra:mainfrom
jjangga0214:refactor/bootstrap-import-meta-dirname
Open

refactor: use import.meta.dirname and fs/promises in opencode plugin#1247
jjangga0214 wants to merge 3 commits into
obra:mainfrom
jjangga0214:refactor/bootstrap-import-meta-dirname

Conversation

@jjangga0214
Copy link
Copy Markdown

@jjangga0214 jjangga0214 commented Apr 22, 2026

What problem are you trying to solve?

Replace synchronous file operations with async equivalents using fs/promises, replace __dirname calculation with import.meta.dirname, remove unused code, and improve the bootstrap duplicate detection filtering from a simple string inclusion check to a more precise prefix match using the bootstrap prelude.

What does this PR change?

  • Use import.meta.dirname instead of fileURLToPath(import.meta.url) for __dirname equivalent
  • Switch from fs to fs/promises for async file operations (readFile, exists via try/catch)
  • Remove unused normalizePath function and unused function parameters (client, directory)
  • Improve duplicate bootstrap injection check: changed from checking if text includes 'EXTREMELY_IMPORTANT' to checking if text starts with the full bootstrap prelude for more precise filtering
  • Use single quotes consistently for strings
  • Use consistent spacing in template literals

Is this change appropriate for the core library?

Yes, this is infrastructure improvement that benefits all users by:

  • Using modern ES modules patterns (import.meta.dirname)
  • Using async/await patterns consistently
  • Removing dead code
  • Maintaining the same functionality while making duplicate detection more robust

What alternatives did you consider?

Kept the same bootstrap duplicate prevention logic but improved from includes('EXTREMELY_IMPORTANT') to startsWith(bootstrapPrelude) for more precise matching to avoid false positives.

Existing PRs

  • I have reviewed all open AND closed PRs for duplicates or prior art
  • Related PRs: none found

Environment tested

Harness (e.g. Claude Code, Cursor) Harness version Model Model version/ID
OpenCode latest nemotron-3-super-free opencode/nemotron-3-super-free

Evaluation

  • Verified import works: node --input-type=module -e "import('./.opencode/plugins/superpowers.js')"

Rigor

  • This change was tested adversarially, not just on the happy path
  • I did not modify carefully-tuned content (Red Flags table, rationalizations, "human partner" language) without extensive evals showing the change is an improvement

Human review

  • A human has reviewed the COMPLETE proposed diff before submission

- Replace __dirname calculation with import.meta.dirname
- Switch to fs/promises for async file operations
- Remove unused normalizePath function and unused parameters
- Keep bootstrap duplicate check using startsWith with prelude string
@jjangga0214 jjangga0214 changed the title refactor: use import.meta.dirname and fs/promises in superpowers plugin refactor: use import.meta.dirname and fs/promises in opencode plugin Apr 22, 2026
@obra obra added the opencode label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants