Skip to content

refactor: extract stateless JavaScript execution sandbox into internal package#27

Merged
apzuk3 merged 7 commits intomainfrom
refactor/sandbox-runtime-contract
Mar 30, 2026
Merged

refactor: extract stateless JavaScript execution sandbox into internal package#27
apzuk3 merged 7 commits intomainfrom
refactor/sandbox-runtime-contract

Conversation

@apzuk3
Copy link
Copy Markdown
Contributor

@apzuk3 apzuk3 commented Mar 30, 2026

Summary

This pull request radically restructures how Focusd executes custom user rules and classifications by decoupling the JavaScript engine from domain logic.

Key Changes:

  • Stateless Sandbox Engine (@internal/sandbox): Extracted all v8go logic and esbuild transpilation out of the usage package into a generic, standalone execution module.
  • Pluggable Contributors (Contributor Interface): Introduced a registry system where external packages (like usage or the new @focusd/core package) can globally inject polyfills, TS types, and native Go function callbacks (RegisterGlobals) directly into V8 isolates seamlessly on startup.
  • Dynamic TypeScript Definitions via Wails IPC: Removed all hardcoded Monaco Type definitions from the React frontend. Instead, sandbox.GenerateTypes() writes out a combined types.d.ts file from all contributors on startup. Monaco then fetches these types dynamically using the new internal/fs/service.go securely through a Wails binding (ReadConfigFileSync).
  • Cleaned Up Dependencies: Removed messy context injection (like passing MinutesUsedInPeriod closures per-execution). The usageContributor now queries the usage Service natively since it attaches the database query directly to the RegisterGlobals V8 isolate initialization.
  • Removed iOS Build Artifacts: Cleaned up lingering broken Wails templates in build/ios.

This sets the stage for easy extensibility: if we want to add HTTP or filesystem capabilities to rules later, we only need to write a new Contributor and register it!

@apzuk3 apzuk3 temporarily deployed to Production release March 30, 2026 13:00 — with GitHub Actions Inactive
@apzuk3 apzuk3 temporarily deployed to Production release March 30, 2026 14:26 — with GitHub Actions Inactive
@apzuk3 apzuk3 merged commit 2f804bf into main Mar 30, 2026
1 check passed
@apzuk3 apzuk3 deleted the refactor/sandbox-runtime-contract branch March 30, 2026 14:32
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