Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): report launch command-line budget accurately
Yash K837c30d8cc75
diff --git a/packages/maker-core/src/agents/pi/__tests__/project-resource-cli.test.ts b/packages/maker-core/src/agents/pi/__tests__/project-resource-cli.test.tsindex 9370b3bbdd..2d843f7f4f 100644--- a/packages/maker-core/src/agents/pi/__tests__/project-resource-cli.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/project-resource-cli.test.ts@@ -174,7 +174,7 @@ describe('pi project resource path order and spawn argv budget', () => {);expect(estimateSpawnArgvLength(args)).toBeGreaterThan(PI_WINDOWS_SPAWN_ARGV_BUDGET);expect(estimateSpawnArgvLength(args)).toBeLessThan(PI_POSIX_SPAWN_ARGV_BUDGET);- expect(() => assertPiSpawnArgvFitsPlatform(args, 'win32')).toThrow(/too many Pi skills/);+ expect(() => assertPiSpawnArgvFitsPlatform(args, 'win32')).toThrow(/launch command line exceeds/);expect(() => assertPiSpawnArgvFitsPlatform(args, 'darwin')).not.toThrow();});@@ -184,8 +184,30 @@ describe('pi project resource path order and spawn argv budget', () => {(_, index) => `/Users/very/long/cindy/project/.pi/skills/skill-${String(index).padStart(4, '0')}/with/nested/folders`,);expect(estimateSpawnArgvLength(args)).toBeGreaterThan(PI_POSIX_SPAWN_ARGV_BUDGET);- expect(() => assertPiSpawnArgvFitsPlatform(args, 'darwin')).toThrow(/too many Pi skills/);- expect(() => assertPiSpawnArgvFitsPlatform(args, 'linux')).toThrow(/too many Pi skills/);+ expect(() => assertPiSpawnArgvFitsPlatform(args, 'darwin')).toThrow(/launch command line exceeds/);+ expect(() => assertPiSpawnArgvFitsPlatform(args, 'linux')).toThrow(/launch command line exceeds/);+ });++ it.each(['win32', 'linux'] as const)('reports prompt-dominated failures without exposing arguments (%s)', (platform) => {+ const args = ['--append-system-prompt', 'private-prompt'.repeat(12_000), '--api-key', 'private-key'];+ const length = estimateSpawnArgvLength(args, platform);+ const promptLength = estimateSpawnArgvLength(args.slice(0, 2), platform);+ const budget = platform === 'win32' ? PI_WINDOWS_SPAWN_ARGV_BUDGET : PI_POSIX_SPAWN_ARGV_BUDGET;+ const unit = platform === 'win32' ? 'UTF-16 code units' : 'UTF-8 bytes';+ expect(() => assertPiSpawnArgvFitsPlatform(args, platform)).toThrow(+ `Pi launch command line exceeds the ${platform} budget: estimated ${length} ${unit}, limit ${budget} `+ + `(prompt arguments: ${promptLength}; resource arguments: 0; other arguments: ${length - promptLength}).`,+ );+ });++ it('reports resource-dominated failures without suggesting that prompts caused them', () => {+ const args = ['--skill', 'private-skill'.repeat(2_500), '--model', 'private-model'];+ const length = estimateSpawnArgvLength(args, 'win32');+ const resourceLength = estimateSpawnArgvLength(args.slice(0, 2), 'win32');+ expect(() => assertPiSpawnArgvFitsPlatform(args, 'win32')).toThrow(+ `Pi launch command line exceeds the win32 budget: estimated ${length} UTF-16 code units, limit 30000 `+ + `(prompt arguments: 0; resource arguments: ${resourceLength}; other arguments: ${length - resourceLength}).`,+ );});// POSIX 侧按 UTF-8 字节:按字符数估会让一段中文提示词「看起来没超」,@@ -196,7 +218,7 @@ describe('pi project resource path order and spawn argv budget', () => {expect(estimateSpawnArgvLength(['--append-system-prompt', cjk], 'linux')).toBeGreaterThan(PI_POSIX_SPAWN_ARGV_BUDGET);expect(() => assertPiSpawnArgvFitsPlatform(['--append-system-prompt', cjk], 'linux'))- .toThrow(/too many Pi skills/);+ .toThrow(/launch command line exceeds/);});// Windows 侧必须按 UTF-16 字符:CreateProcess 的 32767 上限是字符数,不是字节。diff --git a/packages/maker-core/src/agents/pi/project-resource-cli.ts b/packages/maker-core/src/agents/pi/project-resource-cli.tsindex 98f5e7b1df..7bb8ebe842 100644--- a/packages/maker-core/src/agents/pi/project-resource-cli.ts+++ b/packages/maker-core/src/agents/pi/project-resource-cli.ts@@ -223,9 +223,26 @@ export function assertPiSpawnArgvFitsPlatform(platform: NodeJS.Platform = process.platform,): void {const budget = piSpawnArgvBudget(platform);- if (budget === null || estimateSpawnArgvLength(args, platform) <= budget) return;+ if (budget === null) return;+ const length = estimateSpawnArgvLength(args, platform);+ if (length <= budget) return;++ let promptLength = 0;+ let resourceLength = 0;+ for (let index = 0; index < args.length - 1; index += 1) {+ const flag = args[index];+ if (flag === '--append-system-prompt' || flag === '--system-prompt') {+ promptLength += estimateSpawnArgvLength(args.slice(index, index + 2), platform);+ index += 1;+ } else if (flag === '--skill' || flag === '--prompt-template' || flag === '--extension') {+ resourceLength += estimateSpawnArgvLength(args.slice(index, index + 2), platform);+ index += 1;+ }+ }+ const unit = platform === 'win32' ? 'UTF-16 code units' : 'UTF-8 bytes';throw new Error(- 'This project has too many Pi skills, prompts, or extensions to start a task. Remove some and try again.',+ `Pi launch command line exceeds the ${platform} budget: estimated ${length} ${unit}, limit ${budget} `+ + `(prompt arguments: ${promptLength}; resource arguments: ${resourceLength}; other arguments: ${length - promptLength - resourceLength}).`,);}