Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
Merge main Pi command updates into issue-3468
zqchris94c5e8e29d7f
diff --cc apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.tsindex 241fd7428b,ce625fe986..6c1912bfd1--- a/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/pi-package-store-security.test.ts@@@ -5065,97 -4427,99 +5080,192 @@@ describe('Pi package executable-code bo});expect(result.packages[129]?.warning).toBe('inspection-limit');});++ it('logs redacted correlated timings for every package startup stage', async () => {+ const { root, source } = await createSkillOnlyPackage('npm:startup-timing');+ const snapshotRoot = path.join(runtime.userData, 'startup-timing-snapshot');+ const startupTraceId = '0123456789abcdef';+ const store = await import('../pi-package-store.js');++ await expect(store.resolveManagedPiPackageResources({+ snapshotRoot,+ startupTraceId,+ })).resolves.toMatchObject({ skills: [expect.any(Object)] });++ const events = loggerRuntime.info.mock.calls+ .filter(([message]) => message === 'pi startup stage')+ .map(([, fields]) => fields as Record<string, unknown>);+ expect(events.map((event) => event.stage)).toEqual([+ 'package-list',+ 'package-inspection',+ 'package-compatibility',+ 'package-fingerprint',+ 'package-snapshot',+ ]);+ for (const event of events) {+ expect(event).toEqual({+ startupTraceId,+ stage: expect.any(String),+ durationMs: expect.any(Number),+ status: 'ok',+ packageCount: 1,+ resourceCount: 1,+ skippedPackageCount: 0,+ });+ }+ const serialized = JSON.stringify(events);+ expect(serialized).not.toContain(root);+ expect(serialized).not.toContain(source);+ expect(serialized).not.toContain(snapshotRoot);+ });++ it('distinguishes skipped startup stages from work completed within the same millisecond', async () => {+ await createSkillOnlyPackage('npm:startup-timing-native');+ const store = await import('../pi-package-store.js');+ const clock = vi.spyOn(Date, 'now').mockReturnValue(Date.now());+ try {+ await store.resolveManagedPiPackageResources({ startupTraceId: '0123456789abcdef' });+ const events = loggerRuntime.info.mock.calls+ .filter(([message]) => message === 'pi startup stage')+ .map(([, fields]) => fields as Record<string, unknown>);+ expect(events).toHaveLength(5);+ expect(events.find((event) => event.stage === 'package-snapshot')).toMatchObject({+ status: 'skipped', durationMs: 0, packageCount: 1, resourceCount: 1,+ });+ for (const event of events.filter((event) => event.stage !== 'package-snapshot')) {+ expect(event).toMatchObject({ status: 'ok', durationMs: 0 });+ }++ loggerRuntime.info.mockClear();+ await store.resolveManagedPiPackageResources({ startupTraceId: 'fedcba9876543210' });+ const cachedEvents = loggerRuntime.info.mock.calls+ .filter(([message]) => message === 'pi startup stage')+ .map(([, fields]) => fields as Record<string, unknown>);+ expect(cachedEvents).toHaveLength(5);+ for (const event of cachedEvents) {+ expect(event).toMatchObject({+ startupTraceId: 'fedcba9876543210', status: 'skipped', durationMs: 0,+ packageCount: 1, resourceCount: 1,+ });+ }+ } finally {+ clock.mockRestore();+ }+ });++ it('marks startup timing degraded when snapshot limits quarantine a package', async () => {+ await createSkillOnlyPackage('npm:startup-timing-limited');+ const store = await import('../pi-package-store.js');++ await store.resolveManagedPiPackageResources({+ snapshotRoot: path.join(runtime.userData, 'startup-timing-limited-snapshot'),+ snapshotLimits: { maxEntries: 1, maxBytes: 1024 * 1024, maxDurationMs: 10_000 },+ startupTraceId: 'fedcba9876543210',+ });++ const snapshotEvent = loggerRuntime.info.mock.calls+ .filter(([message]) => message === 'pi startup stage')+ .map(([, fields]) => fields as Record<string, unknown>)+ .find((fields) => fields.stage === 'package-snapshot');+ expect(snapshotEvent).toMatchObject({+ startupTraceId: 'fedcba9876543210',+ status: 'degraded',+ skippedPackageCount: 1,+ });+ });});+++ describe('native Pi core management', () => {+ it('streams the full list before projecting a receipt beyond the diagnostic stdout limit', async () => {+ const { executePiNativeManagementCommand } = await import('../pi-package-store.js');+ const sources = Array.from({ length: 160 }, (_, index) => `npm:package-${index}`);+ runtime.listOutput = 'User packages:\n' + sources.map(source =>+ ` ${source}\n /private/installation/${'x'.repeat(1000)}\n`).join('');+ expect(Buffer.byteLength(runtime.listOutput)).toBeGreaterThan(128 * 1024);+ const result = await executePiNativeManagementCommand({ kind: 'list' });+ expect(JSON.parse(String(result.output))).toEqual(sources.map(source => ({ source, filtered: false })));+ expect(String(result.output)).not.toContain('/private/installation');+ expect(runtime.spawns.map(call => call.args)).toEqual([['list', '--no-approve']]);+ });++ it.each([+ ['file:/home/alice/private-extension', 'private-extension'],+ ['file:///Users/alice/private-extension', 'private-extension'],+ ['FILE://localhost/Users/alice/private-extension', 'private-extension'],+ ['file://private-host/share/private-extension', 'private-extension'],+ ['file:///Users/alice%2Fprivate-extension', 'private-extension'],+ ['file:///C:/Users/alice/private-extension', 'private-extension'],+ ['file:///%ZZ/alice/private-extension', '[local-package]'],+ ['file://private-host/', '[local-package]'],+ ['/home/alice/private-extension', 'private-extension'],+ [String.raw`C:\Users\alice\private-extension`, 'private-extension'],+ ['npm:public-extension', 'npm:public-extension'],+ ['https://user:[email protected]/package?token=secret', 'https://example.test/package'],+ ])('redacts local locations in list receipts: %s', async (source, expected) => {+ const { executePiNativeManagementCommand } = await import('../pi-package-store.js');+ runtime.listOutput = `User packages:\n ${source}\n /Users/alice/install-location\n`;+ const result = await executePiNativeManagementCommand({ kind: 'list' });+ expect(JSON.parse(String(result.output))).toEqual([{ source: expected, filtered: false }]);+ expect(JSON.stringify(result)).not.toMatch(/alice|private-host|install-location|secret/);+ });++ it.each(['native-core', 'host-binary-update'] as const)('preserves completed packages when %s fails', async phase => {+ const { executePiNativeManagementCommand, piNativeManagementFailure, piPackageMutationMayHaveChangedState } = await import('../pi-package-store.js');+ if (phase === 'host-binary-update') runtime.fallbackError = new Error('network failure with private data');+ runtime.spawnHook = args => {+ if (args.includes('--self')) {+ runtime.exitCode = 1;+ runtime.stderr = phase === 'native-core' ? 'network timeout' : 'pi cannot self-update this installation';+ }+ };+ const error = await executePiNativeManagementCommand({ kind: 'all', force: false }).catch(error => error);+ expect(error).toBeInstanceOf(Error);+ expect(piPackageMutationMayHaveChangedState(error)).toBe(true);+ expect(piNativeManagementFailure(error)).toMatchObject({ phase, packagesUpdated: true,+ recovery: phase === 'native-core' ? 'retry-core-only' : 'check-host-update-and-retry-core' });+ expect(runtime.spawns.filter(call => call.args.includes('--extensions'))).toHaveLength(1);+ expect(JSON.stringify(piNativeManagementFailure(error))).not.toContain('private data');+ });++ it('uses the standalone updater only after the precise native unsupported result', async () => {+ const { executePiNativeManagementCommand } = await import('../pi-package-store.js');+ runtime.spawnHook = args => {+ if (args.includes('--self')) {+ runtime.exitCode = 1;+ runtime.stderr = 'error: pi cannot self-update this installation.';+ }+ };+ const result = await executePiNativeManagementCommand({ kind: 'self', force: true });+ expect(result).toMatchObject({ execution: 'host-binary-update', nativeSucceeded: false, afterVersion: '0.85.1', activation: 'new-root-tasks' });+ expect(runtime.fallbackCalls).toEqual([true]);+ });++ it('does not disguise a failed package phase of --all as a core fallback', async () => {+ const { executePiNativeManagementCommand } = await import('../pi-package-store.js');+ runtime.spawnHook = args => {+ if (args.includes('--extensions')) { runtime.exitCode = 1; runtime.stderr = 'pi cannot self-update this installation'; }+ };+ await expect(executePiNativeManagementCommand({ kind: 'all', force: false })).rejects.toThrow();+ expect(runtime.fallbackCalls).toEqual([]);+ expect(runtime.spawns.some(call => call.args.includes('--self'))).toBe(false);+ });++ it('preserves native network failures instead of treating every failed update as a fallback request', async () => {+ const { executePiNativeManagementCommand } = await import('../pi-package-store.js');+ runtime.spawnHook = args => { if (args.includes('--self')) { runtime.exitCode = 1; runtime.stderr = 'network timeout'; } };+ await expect(executePiNativeManagementCommand({ kind: 'self', force: false })).rejects.toThrow('network timeout');+ expect(runtime.fallbackCalls).toEqual([]);+ });++ it('reads the executable after an in-place update, not the old directory name or cached version', async () => {+ const { executePiNativeManagementCommand } = await import('../pi-package-store.js');+ runtime.version = '0.84.4';+ runtime.spawnHook = args => { if (args.includes('--self')) runtime.version = '0.85.1'; };+ const result = await executePiNativeManagementCommand({ kind: 'self', force: false });+ expect(result).toMatchObject({ beforeVersion: '0.84.4', afterVersion: '0.85.1', versionVerified: true, activeTasksPreserved: true, activation: 'new-root-tasks' });+ expect(runtime.spawns.map(call => call.args)).toEqual([['--version'], ['update', '--self', '--no-approve'], ['--version']]);+ expect(await executePiNativeManagementCommand({ kind: 'version' })).toMatchObject({ version: '0.85.1' });+ expect((await fs.readdir(runtime.userData)).some(name => name.includes('runtime-change'))).toBe(false);+ });+ });