Skip to content

fix: code audit round 2 — safety, hot-reload, error diagnostics#982

Merged
jackwener merged 2 commits intomainfrom
fix/code-audit-round2
Apr 13, 2026
Merged

fix: code audit round 2 — safety, hot-reload, error diagnostics#982
jackwener merged 2 commits intomainfrom
fix/code-audit-round2

Conversation

@jackwener
Copy link
Copy Markdown
Owner

Summary

Addresses 4 items from the code audit:

  • pruneEmptyDirs path safetystartsWith() could match overlapping directory names (e.g., /a-site vs /a). Now uses path.relative() for correct boundary checking.
  • evaluateWithArgs safe evaluate — New IPage.evaluateWithArgs(js, args) method that auto-serializes args via JSON.stringify() as const declarations. Prevents injection by design. Available for adapters to adopt incrementally.
  • User adapter hot-reload — In daemon mode, detects mtime changes on ~/.opencli/clis/ adapter files and invalidates module cache. Edits take effect without daemon restart.
  • Error cause chainrenderError now preserves err.cause in verbose mode, so nested errors (browser → adapter → pipeline) show the full chain for debugging.

Test plan

  • Typecheck passes
  • All 196 test files pass (1489 tests)
  • Verify evaluateWithArgs works with a sample adapter
  • Verify daemon picks up user adapter changes without restart

…d, error cause chain

1. pruneEmptyDirs: use path.relative() instead of startsWith() to prevent
   false boundary matches on overlapping directory names
2. evaluateWithArgs: add safe evaluate method that auto-serializes args via
   JSON.stringify, preventing injection by design
3. Hot-reload: detect mtime changes on user adapter files in daemon mode,
   invalidate module cache so edits take effect without restart
4. toEnvelope: preserve error cause chain in verbose mode for better
   production debugging
- pruneEmptyDirs: resolve() paths before relative() check
- evaluateWithArgs: validate keys are valid JS identifiers
- hot-reload: only bust ESM cache on reload, not first load
- toEnvelope: move cause serialization into toEnvelope itself
  so all consumers (AI agents, MCP tools) get cause chain
@jackwener jackwener merged commit 72bc86c into main Apr 13, 2026
13 checks passed
@jackwener jackwener deleted the fix/code-audit-round2 branch April 13, 2026 01:36
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