Repository navigation
perf(pi-permission-system): load a prebuilt native runtime - #1114
Open
hyein-cbio wants to merge 2 commits into
Open
hyein-cbio wants to merge 2 commits into
hyein-cbio wants to merge 2 commits into
Conversation
Build one CommonJS runtime during packaging and load it through a small Pi-aware entry while retaining the TypeScript source as a fallback. Keep Pi host modules external, preserve source-relative asset resolution, and reload rebuilt native code without sharing session approval state. Fall back before initialization on JS load errors, but propagate factory errors to avoid duplicate permission hooks. Add native-artifact and loader regression tests plus a reproducible, isolated CLI loading benchmark with raw measurements. Validated with the package test suite, typecheck, lint, and packaged extension loading on Pi 1.0.0 and 1.5.0.
Reproduce a packed checkout ignoring a newer source-only command because extension.ts continues loading the old runtime snapshot. Remove the working-tree runtime after packing and on public-type verifier exit, including failed packing. Before native loading, check recursive TS/TSX source mtimes and fall back to source when the bundle is stale or freshness cannot be established. Accept equal packed-file timestamps. Add freshness and failure-path regressions without changing permission logic. Verify packed native loading and edited-source fallback on Pi 1.0.0 and 1.5.0. Validation: 186 test files, 6444 passing tests, package typecheck and lint, public-type verification, and runtime absence after verification. Refs gotgenes#1113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #1113.
A local investigation of loading time across the installed extensions identified
pi-permission-systemas one of the largest contributors.This PR addresses that loading overhead without changing permission policies or skipping enforcement.
The package-specific benchmark below is separate from that local cross-extension observation.
Changes
dist/runtime.cjsbundle duringprepack, alongside the existing public declarations.pi.extensionsat a smallextension.tsentry that native-loads the runtime instead of sending the full TS graph through Jiti.All changed files are under
packages/pi-permission-system/.There are no changes to permission-gate logic, policy format, defaults, or the public service API, and no new dependencies or consumer installation scripts.
Loading measurements
Pi 1.5.0, Node v26.13.0 benchmark driver, macOS arm64.
Each run starts an actual Pi CLI process in offline RPC mode with only this extension, a disposable agent directory, YOLO on, and both logs off.
There are nine trials per condition after warm-up, alternating the order of source and compiled runs.
These are isolated measurements, not a claim about the improvement of a full multi-extension TUI startup.
Disabling transform caching does not clear the OS filesystem cache.
The warm-up samples are retained, but these measurements do not establish first-install performance.
Raw trials, measurement metadata, and runtime hash.
Reproduce from the repository root:
pnpm --filter @gotgenes/pi-permission-system run build:runtime PI_BIN="$(command -v pi)" pnpm --filter @gotgenes/pi-permission-system run measure:loadingValidation
pnpm run check— entire workspace.pnpm run lint— repository-wide Biome, ESLint, Markdown and character checks.pnpm run test— all workspace package suites and root script tests;pi-permission-systemhas 6,441 passing tests.pnpm pack— runtime, declarations, entry and TS source included; development tests/scripts and raw benchmark data excluded.These checks do not claim exhaustive verification of interactive TUI dialogs or real cross-process subagent approval round-trips through the new bundled entry.
The existing source-based suites still pass.
Development behavior
If
dist/runtime.cjsexists, the entry prefers it.After editing TS in a checkout, rebuild with
build:runtimebefore reloading Pi; an unbuilt checkout continues to use TS directly.The real global Pi installation and user settings were not modified.