Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.
TypeScript agent-teamagentic-aiai-agentsai-assistantclaude-codecodexcursorelectrongrokgrok-bot-alternativelinuxlocal-firstmacosmcpmulti-agentopenclaw-alternativeopencodewindows
Don't leave other apps' app.asar open when listing apps (#97) (#98)
Eduardo Machado51ccd5865ba2
diff --git a/src/core/apps-os.ts b/src/core/apps-os.tsindex 9fd662c..19adc36 100644--- a/src/core/apps-os.ts+++ b/src/core/apps-os.ts@@ -4,6 +4,7 @@// person's language, an icon and how to start it. The Mac's are in apps.ts (macApps).import { execFile, spawn } from 'node:child_process'import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'+import { createRequire } from 'node:module'import { homedir } from 'node:os'import { posix } from 'node:path'@@ -123,8 +124,21 @@ export function dataUrl(file: string): string | undefined {}}+// Whether a file is on disk, without opening it. Inside Electron, node:fs treats any .asar it's+// asked about as an archive: it opens it and keeps it open in its cache, which on Windows locks+// other apps' app.asar and breaks their updates (#97). original-fs is the unpatched one. In+// server mode (plain Node) there's no original-fs, and node:fs is already the plain one.+export const diskExists: (p: string) => boolean = (() => {+ if (!process.versions['electron']) return existsSync+ try {+ return (createRequire(import.meta.url)('original-fs') as typeof import('node:fs')).existsSync+ } catch {+ return existsSync+ }+})()+// A program made with Chromium or Electron, by what sits next to it.-export function isChromium(program: string, exists: (p: string) => boolean = existsSync): boolean {+export function isChromium(program: string, exists: (p: string) => boolean = diskExists): boolean {const dir = dirname(program)return ['resources/app.asar', 'resources.pak', 'chrome_100_percent.pak', 'chrome-sandbox', 'v8_context_snapshot.bin', 'libcef.so', 'libcef.dll'].some((f) => exists(join(dir, f)))}@@ -242,7 +256,7 @@ type WinRow = { name?: string; path?: string; exe?: string; id?: string; logo?:// Uninstallers, help files and the like aren't apps a person would give an agent.const NOT_AN_APP = /\b(uninstall|desinstalar|deinstall|readme|leia-me|help|ajuda|documentation|release notes|website|license|licen[cç]a)\b/i-export function parseWinApps(json: string, exists: (p: string) => boolean = existsSync): SystemApp[] {+export function parseWinApps(json: string, exists: (p: string) => boolean = diskExists): SystemApp[] {let rows: WinRow[] = []try {const v = JSON.parse(json.trim() || '[]') as WinRow | WinRow[]diff --git a/test/apps-os.test.ts b/test/apps-os.test.tsindex 0a0d846..2de6183 100644--- a/test/apps-os.test.ts+++ b/test/apps-os.test.ts@@ -1,4 +1,4 @@-import { describe, expect, it } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import { appOfWindow, desktopDirs, execArgs, iconFile, parseDesktopEntry, parseWinApps, parseWinOpen } from '../src/core/apps-os'describe('Linux application menu', () => {@@ -85,3 +85,34 @@ describe('Windows Start menu', () => {expect(parseWinOpen(JSON.stringify({ pid: 3, name: 'obs64' }))).toEqual([{ pid: 3, name: 'obs64' }])})})++describe('diskExists (#97)', () => {+ afterEach(() => {+ vi.doUnmock('node:module')+ vi.resetModules()+ vi.unstubAllGlobals()+ })++ it("is node:fs's existsSync outside Electron, which doesn't open .asar archives", async () => {+ const fs = await import('node:fs')+ const { diskExists } = await import('../src/core/apps-os')+ expect(diskExists).toBe(fs.existsSync)+ })++ it("inside Electron, asks original-fs, so other apps' app.asar isn't left open", async () => {+ const calls: string[] = []+ vi.doMock('node:module', async (orig) => ({+ ...(await orig<typeof import('node:module')>()),+ createRequire: () => (id: string) => {+ if (id !== 'original-fs') throw new Error(id)+ return { existsSync: (p: string) => (calls.push(p), p.endsWith('app.asar')) }+ }+ }))+ vi.stubGlobal('process', { ...process, versions: { ...process.versions, electron: '39.0.0' } })+ const { isChromium, parseWinApps } = await import('../src/core/apps-os')+ expect(isChromium('/opt/Obsidian/obsidian')).toBe(true)+ expect(calls).toEqual(['/opt/Obsidian/resources/app.asar'])+ expect(parseWinApps(JSON.stringify([{ name: 'Obsidian', path: 'o.lnk', exe: 'C:\\Obsidian\\Obsidian.exe' }]))[0]?.chromium).toBe(true)+ expect(calls[1]).toBe('C:\\Obsidian\\resources\\app.asar')+ })+})