mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
perf(pi): skip rewriting current managed extensions on every terminal spawn (#38481)
Each local terminal spawn with a Pi agent home rewrote three Orca-owned extension files (~54 KB) synchronously on the main thread even when their contents were already current. Compare the read we already do for the ownership check and write only when the content differs. Co-authored-by: m4air <m4air@Mac.localdomain>
This commit is contained in:
@@ -10,7 +10,9 @@ import {
|
||||
readFileSync,
|
||||
readdirSync,
|
||||
rmSync,
|
||||
statSync,
|
||||
symlinkSync,
|
||||
utimesSync,
|
||||
writeFileSync
|
||||
} from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
@@ -512,6 +514,19 @@ describe('PiTitlebarExtensionService', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('leaves current Orca-owned extensions untouched on later spawns', () => {
|
||||
const svc = new PiTitlebarExtensionService()
|
||||
svc.buildPtyEnv('pty-current-1', piHome, 'pi')
|
||||
const installed = ['orca-titlebar-spinner.ts', 'orca-prefill.ts', 'orca-agent-status.ts'].map(
|
||||
(name) => join(piHome, 'extensions', name)
|
||||
)
|
||||
installed.forEach((path) => utimesSync(path, 0, 0))
|
||||
|
||||
svc.buildPtyEnv('pty-current-2', piHome, 'pi')
|
||||
|
||||
expect(installed.map((path) => statSync(path).mtimeMs)).toEqual([0, 0, 0])
|
||||
})
|
||||
|
||||
it("does not overwrite a user's same-named Orca extension file", () => {
|
||||
const userStatusExtension = 'user-owned status extension'
|
||||
writeFileSync(join(piHome, 'extensions', 'orca-agent-status.ts'), userStatusExtension, 'utf-8')
|
||||
|
||||
@@ -87,16 +87,17 @@ export class PiTitlebarExtensionService {
|
||||
safeRemoveOverlay(overlayDir, this.getOverlayRoot(kind))
|
||||
}
|
||||
|
||||
private canOverwriteManagedExtension(path: string): boolean {
|
||||
try {
|
||||
return readFileSync(path, 'utf8').includes(ORCA_MANAGED_EXTENSION_MARKER)
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private writeManagedExtension(path: string, source: string): ManagedExtensionWriteResult {
|
||||
if (existsSync(path) && !this.canOverwriteManagedExtension(path)) {
|
||||
let installed: string | undefined
|
||||
try {
|
||||
installed = readFileSync(path, 'utf8')
|
||||
} catch {
|
||||
installed = undefined
|
||||
}
|
||||
if (installed === source) {
|
||||
return 'written'
|
||||
}
|
||||
if (installed !== undefined && !installed.includes(ORCA_MANAGED_EXTENSION_MARKER)) {
|
||||
return 'skipped-user-owned'
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user