Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): 对齐 0.84.3 的 powershell、压缩失败与 xAI 路由 (#3539)
Chris Zhang1ed7e9c962bc
diff --git a/apps/desktop/src/renderer/components/new-chat/PermissionPrompt.tsx b/apps/desktop/src/renderer/components/new-chat/PermissionPrompt.tsxindex d79736a989..b3db7254bb 100644--- a/apps/desktop/src/renderer/components/new-chat/PermissionPrompt.tsx+++ b/apps/desktop/src/renderer/components/new-chat/PermissionPrompt.tsx@@ -50,7 +50,7 @@ export function formatToolInput(toolName: string, input: Record<string, unknown>const text = JSON.stringify(input, null, 2);return text.length > 500 ? text.slice(0, 500) + '...' : text;};- if (name === 'bash') {+ if (name === 'bash' || name === 'powershell') {return firstString(input, ['command']) ?? fallback();}if (name === 'read' || name === 'edit' || name === 'write') {diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/formatToolInput.test.ts b/apps/desktop/src/renderer/components/new-chat/__tests__/formatToolInput.test.tsindex fb6d13a0a8..64bec76925 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/formatToolInput.test.ts+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/formatToolInput.test.ts@@ -8,9 +8,11 @@ import { describe, expect, it } from 'vitest';import { formatToolInput } from '../PermissionPrompt';describe('formatToolInput (harness-agnostic)', () => {- it('extracts the command for both Bash and bash', () => {+ it('extracts the command for Bash and PowerShell tools', () => {expect(formatToolInput('Bash', { command: 'ls -la' })).toBe('ls -la');expect(formatToolInput('bash', { command: 'git status' })).toBe('git status');+ expect(formatToolInput('powershell', { command: 'Get-Content .\\README.md' }))+ .toBe('Get-Content .\\README.md');});it('extracts the file path across file_path / path (CC and pi)', () => {diff --git a/docs/design-previews/pr-3539-powershell-permission-prompt/index.html b/docs/design-previews/pr-3539-powershell-permission-prompt/index.htmlnew file mode 100644index 0000000000..dc77a7af81--- /dev/null+++ b/docs/design-previews/pr-3539-powershell-permission-prompt/index.html@@ -0,0 +1,264 @@+<!doctype html>+<html lang="zh-CN">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1" />+ <title>PR #3539 · PowerShell PermissionPrompt UI evidence preview</title>+ <style>+ * { box-sizing: border-box; }+ html, body { min-height: 100%; }+ body {+ margin: 0;+ background: #ecece8;+ color: #1a1a1a;+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;+ -webkit-font-smoothing: antialiased;+ }+ button, kbd { font: inherit; }+ .page {+ width: min(1360px, calc(100vw - 64px));+ margin: 0 auto;+ padding: 42px 0 48px;+ }+ .evidence-header {+ display: flex;+ align-items: flex-start;+ justify-content: space-between;+ gap: 24px;+ margin-bottom: 24px;+ }+ .eyebrow {+ margin: 0 0 7px;+ color: #666661;+ font-size: 12px;+ font-weight: 600;+ letter-spacing: .04em;+ line-height: 16px;+ text-transform: uppercase;+ }+ h1 {+ margin: 0;+ font-size: 24px;+ font-weight: 650;+ letter-spacing: -.02em;+ line-height: 32px;+ }+ .summary {+ max-width: 780px;+ margin: 8px 0 0;+ color: #666661;+ font-size: 13px;+ line-height: 20px;+ }+ .preview-badge {+ flex: 0 0 auto;+ padding: 7px 10px;+ border: 1px solid #c9a751;+ border-radius: 999px;+ background: #fff8df;+ color: #6f5414;+ font-size: 12px;+ font-weight: 600;+ line-height: 16px;+ }+ .comparison {+ display: grid;+ grid-template-columns: repeat(2, minmax(0, 1fr));+ overflow: hidden;+ border: 1px solid #d1d1cc;+ border-radius: 18px;+ box-shadow: 0 18px 48px rgba(36, 36, 32, .10);+ }+ .scene {+ min-width: 0;+ padding: 28px;+ }+ .scene + .scene { border-left: 1px solid #d1d1cc; }+ .scene.light {+ --surface: hsl(60 12.5% 97%);+ --chat-input-bg: #fff;+ --chat-input-border: #d7d7d4;+ --chat-input-text: #000;+ --status-bar-meta: #737373;+ --perm-code-bg: #f5f5f5;+ --perm-code-border: #d7d7d4;+ --perm-allow-btn-bg: #fff;+ --perm-allow-btn-text: #262626;+ --perm-allow-kbd-bg: #f5f5f5;+ --perm-allow-kbd-border: #d7d7d4;+ background: var(--surface);+ color: var(--chat-input-text);+ }+ .scene.dark {+ --surface: hsl(60 2% 12%);+ --chat-input-bg: #2c2c2a;+ --chat-input-border: #3c3c3a;+ --chat-input-text: #d4d4d4;+ --status-bar-meta: #a3a3a3;+ --perm-code-bg: #1f1f1e;+ --perm-code-border: #3c3c3a;+ --perm-allow-btn-bg: #fff;+ --perm-allow-btn-text: #262626;+ --perm-allow-kbd-bg: #e5e5e5;+ --perm-allow-kbd-border: #d7d7d4;+ background: var(--surface);+ color: var(--chat-input-text);+ }+ .scene-label {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 12px;+ margin-bottom: 40px;+ color: var(--status-bar-meta);+ font-size: 12px;+ line-height: 16px;+ }+ .scene-label strong {+ color: var(--chat-input-text);+ font-weight: 600;+ }+ .stage {+ display: flex;+ min-height: 300px;+ align-items: flex-end;+ }+ .permission-prompt {+ width: 100%;+ max-width: 914px;+ padding: 16px;+ border: 1px solid var(--chat-input-border);+ border-radius: 12px;+ background: var(--chat-input-bg);+ }+ .permission-title {+ margin: 0;+ color: var(--chat-input-text);+ font-size: 15px;+ font-weight: 600;+ line-height: 18.75px;+ }+ .code-block {+ max-height: 120px;+ margin-top: 12px;+ overflow: auto;+ padding: 10px 14px;+ border: 1px solid var(--perm-code-border);+ border-radius: 8px;+ background: var(--perm-code-bg);+ color: var(--chat-input-text);+ font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;+ font-size: 13px;+ line-height: 1.625;+ }+ pre {+ margin: 0;+ white-space: pre-wrap;+ overflow-wrap: anywhere;+ }+ .actions {+ display: flex;+ flex-wrap: wrap;+ align-items: center;+ justify-content: flex-end;+ gap: 8px;+ margin-top: 16px;+ }+ .action {+ display: flex;+ align-items: center;+ gap: 8px;+ min-height: 34px;+ padding: 7px 12px;+ border: 1px solid var(--chat-input-border);+ border-radius: 8px;+ background: transparent;+ color: var(--chat-input-text);+ font-size: 13px;+ font-weight: 500;+ line-height: 16px;+ }+ .action.primary {+ border-color: var(--chat-input-border);+ background: var(--perm-allow-btn-bg);+ color: var(--perm-allow-btn-text);+ }+ kbd {+ padding: 1px 6px;+ border: 1px solid var(--chat-input-border);+ border-radius: 4px;+ background: var(--perm-code-bg);+ color: var(--status-bar-meta);+ font-size: 11px;+ font-weight: 400;+ line-height: 14px;+ }+ .primary kbd {+ border-color: var(--perm-allow-kbd-border);+ background: var(--perm-allow-kbd-bg);+ color: var(--perm-allow-btn-text);+ opacity: .7;+ }+ .evidence-note {+ margin: 18px 2px 0;+ color: #666661;+ font-size: 12px;+ line-height: 18px;+ }+ code {+ font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;+ font-size: 11px;+ }+ @media (max-width: 900px) {+ .page { width: min(680px, calc(100vw - 32px)); padding-top: 24px; }+ .evidence-header { flex-direction: column; }+ .comparison { grid-template-columns: 1fr; }+ .scene + .scene { border-top: 1px solid #d1d1cc; border-left: 0; }+ }+ </style>+ </head>+ <body>+ <main class="page">+ <header class="evidence-header">+ <div>+ <p class="eyebrow">PR #3539 · UI evidence</p>+ <h1>PowerShell 审批提示显示 command 正文</h1>+ <p class="summary">复用现有 PermissionPrompt 的真实布局、颜色 token、字号与中文按钮文案;本预览仅用于审阅从 JSON 回退改为命令正文后的用户可见结果。</p>+ </div>+ <div class="preview-badge">预览 · 非 Windows 实机</div>+ </header>++ <section class="comparison" aria-label="PermissionPrompt Light 与 Dark 预览">+ <article class="scene light">+ <div class="scene-label"><strong>Light</strong><span>Desktop 预览 · Windows 命令示例</span></div>+ <div class="stage">+ <section class="permission-prompt" aria-label="Light PermissionPrompt">+ <p class="permission-title">允许 powershell?</p>+ <div class="code-block"><pre>Get-Content -LiteralPath "C:\Users\Public\Documents\release-notes.txt"</pre></div>+ <div class="actions">+ <button class="action" type="button"><span>拒绝</span><kbd>Esc</kbd></button>+ <button class="action primary" type="button"><span>允许一次</span><kbd>Enter</kbd></button>+ </div>+ </section>+ </div>+ </article>++ <article class="scene dark">+ <div class="scene-label"><strong>Dark</strong><span>Desktop 预览 · Windows 命令示例</span></div>+ <div class="stage">+ <section class="permission-prompt" aria-label="Dark PermissionPrompt">+ <p class="permission-title">允许 powershell?</p>+ <div class="code-block"><pre>Get-Content -LiteralPath "C:\Users\Public\Documents\release-notes.txt"</pre></div>+ <div class="actions">+ <button class="action" type="button"><span>拒绝</span><kbd>Esc</kbd></button>+ <button class="action primary" type="button"><span>允许一次</span><kbd>Enter</kbd></button>+ </div>+ </section>+ </div>+ </article>+ </section>++ <p class="evidence-note">证据属性:<strong>高保真 HTML 预览,非 Windows 实机截图</strong>。样式依据 <code>PermissionPrompt.tsx</code> 与现有 Light/Dark token;未新增产品状态、交互或视觉设计。</p>+ </main>+ </body>+</html>diff --git a/docs/design-previews/pr-3539-powershell-permission-prompt/powershell-permission-prompt-preview.png b/docs/design-previews/pr-3539-powershell-permission-prompt/powershell-permission-prompt-preview.pngnew file mode 100644index 0000000000..944eb2c9acBinary files /dev/null and b/docs/design-previews/pr-3539-powershell-permission-prompt/powershell-permission-prompt-preview.png differdiff --git a/docs/dev-rules/pi-harness.md b/docs/dev-rules/pi-harness.mdindex de1949cd19..5106b0cd57 100644--- a/docs/dev-rules/pi-harness.md+++ b/docs/dev-rules/pi-harness.md@@ -181,7 +181,7 @@ Claude Code 仍用独立百分比。env:`CINDY_PI_API_KEY`、## 6. 上线门禁-- [x] **平台分发**:pin 已升级到 Pi `v0.83.0`,darwin arm64/x64、linux arm64/x64、+- [x] **平台分发**:pin 已升级到 Pi `v0.84.3`,darwin arm64/x64、linux arm64/x64、win32 arm64/x64 六份官方资产都进入 digest pin;下载器兼容 Unix `pi/` 嵌套包与Windows 根目录平铺 zip。当前 Mac 已完成六资产 SHA-256 下载验收;非本机 OS 的最终启动 smoke 仍由对应发布 runner 执行。2026-08 起 pi 与 cc/codex 一样只走diff --git a/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts b/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.tsindex 23d49be1eb..879f278065 100644--- a/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/cindyBridgeSource.test.ts@@ -161,6 +161,47 @@ function loadBashPackageHomeHelper(): {};}+function powerShellOverlayEnabled(platform: NodeJS.Platform, factory: unknown): boolean {+ const source = CINDY_BRIDGE_EXTENSION_SOURCE;+ const start = source.indexOf('const createPowerShellTool =');+ const end = source.indexOf('// Cindy owns a separate Pi extension store.', start);+ if (start < 0 || end <= start) throw new Error('PowerShell overlay was not found');+ const condition = /^\s*if \((.*createPowerShellTool.*)\) \{$/m.exec(source.slice(start, end))?.[1];+ if (!condition) throw new Error('PowerShell overlay condition was not found');+ return Boolean(runInNewContext(condition, {+ createPowerShellTool: factory,+ process: { platform },+ }));+}++function loadPowerShellReadEvidence(+ cwd: string,+): (input: unknown) => { targets: string[]; unresolved: boolean } {+ const source = CINDY_BRIDGE_EXTENSION_SOURCE;+ const start = source.indexOf('const POWERSHELL_DIRECT_FILE_READ_COMMANDS');+ const end = source.indexOf('function bashInputReadEvidence', start);+ if (start < 0 || end <= start) throw new Error('PowerShell read evidence helper was not found');+ const executableSource = [+ 'type BashInputReadEvidence = { targets: string[]; unresolved: boolean };',+ source.slice(start, end),+ '(globalThis as any).powershellInputReadEvidence = powershellInputReadEvidence;',+ ].join('\n');+ const compiled = ts.transpileModule(executableSource, {+ compilerOptions: {+ module: ts.ModuleKind.None,+ target: ts.ScriptTarget.ES2022,+ },+ }).outputText;+ const context: Record<string, unknown> = {+ path,+ process: { cwd: () => cwd },+ };+ runInNewContext(compiled, context);+ return context.powershellInputReadEvidence as (+ input: unknown,+ ) => { targets: string[]; unresolved: boolean };+}+function loadPiPackageMutationCommandHelper(): (input: unknown) => boolean {const source = CINDY_BRIDGE_EXTENSION_SOURCE;const parserStart = source.indexOf('function readShellRedirectionTarget');@@ -356,6 +397,136 @@ describe('cindy-bridge extension source', () => {expect(evidence('read', { path: 42 }).touchesCredential).toBe(true);});+ it('canonicalizes direct PowerShell read operands through a directory symlink or junction', () => {+ const tempRoot = mkdtempSync(path.join(tmpdir(), 'cindy-pi-powershell-link-'));+ try {+ const sshDir = path.join(tempRoot, 'secrets', '.ssh');+ const keyPath = path.join(sshDir, 'id_rsa');+ const innocentLink = path.join(tempRoot, 'innocent');+ mkdirSync(sshDir, { recursive: true });+ writeFileSync(keyPath, 'secret');+ symlinkSync(sshDir, innocentLink, process.platform === 'win32' ? 'junction' : 'dir');+ const operand = process.platform === 'win32'+ ? '.\\innocent\\id_rsa'+ : './innocent/id_rsa';+ const evidence = loadPowerShellReadEvidence(tempRoot);++ const commands = [+ ...['Get-Content', 'gc', 'cat', 'type', 'Microsoft.PowerShell.Management\\Get-Content']+ .map((commandName) => commandName + ' ' + operand),+ 'Get-Content -Path ' + operand,+ "Get-Content -LiteralPath '" + operand + "' -Raw",+ 'Write-Output ok; Get-Content ' + operand,+ 'Get-Content ' + operand + ' | Out-String',+ 'Write-Output ok | Get-Content ' + operand,+ 'Write-Output "ok; still"; Get-Content ' + operand,+ 'Write-Output ok\nGet-Content ' + operand,+ 'Write-Output ok\rGet-Content ' + operand,+ '# harmless preface\nGet-Content ' + operand,+ ];+ for (const command of commands) {+ const result = evidence({ command });+ expect(result.unresolved, command).toBe(false);+ expect(result.targets, command).toHaveLength(1);+ expect(realpathSync(result.targets[0]), command).toBe(realpathSync(keyPath));+ }+ } finally {+ rmSync(tempRoot, { recursive: true, force: true });+ }+ });++ it('fails closed for relative PowerShell reads after a directory change', () => {+ const tempRoot = mkdtempSync(path.join(tmpdir(), 'cindy-pi-powershell-cwd-'));+ try {+ const sshDir = path.join(tempRoot, 'secrets', '.ssh');+ const keyPath = path.join(sshDir, 'work');+ const innocentLink = path.join(tempRoot, 'innocent');+ mkdirSync(sshDir, { recursive: true });+ writeFileSync(keyPath, 'secret');+ symlinkSync(sshDir, innocentLink, process.platform === 'win32' ? 'junction' : 'dir');+ const location = process.platform === 'win32' ? '.\\innocent' : './innocent';+ const evidence = loadPowerShellReadEvidence(tempRoot);++ for (const locationCommand of [+ `Set-Location ${location}`,+ `cd ${location}`,+ `chdir ${location}`,+ `sl ${location}`,+ `Push-Location ${location}`,+ `pushd ${location}`,+ 'Pop-Location',+ 'popd',+ ]) {+ const command = `${locationCommand}; Get-Content work`;+ expect(evidence({ command }), command).toEqual({ targets: [], unresolved: true });+ }++ expect(evidence({ command: `Set-Location ${location}` })).toEqual({+ targets: [],+ unresolved: false,+ });+ expect(evidence({ command: `Set-Location ${location}; Get-Content '${keyPath}'` })).toEqual({+ targets: [path.normalize(keyPath)],+ unresolved: false,+ });++ expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain(+ 'isCindyShellTool(event.toolName) && (bashReadEvidence.unresolved || touchesCredentialPath(bashReadTargets))',+ );+ expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain(+ "if (credentialRead && permission.mode === 'bypassPermissions')",+ );+ expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain('await ctx.ui.input(');+ } finally {+ rmSync(tempRoot, { recursive: true, force: true });+ }+ });++ it('fails closed when a direct PowerShell read operand is not statically resolvable', () => {+ const evidence = loadPowerShellReadEvidence(process.cwd());+ for (const command of [+ 'Get-Content $target',+ 'Get-Content "${target}"',+ 'Get-Content (Join-Path . id_rsa)',+ 'Get-Content ./safe"name".txt',+ "Get-Content ./safe'name'.txt",+ 'Get-Content ./safe*.txt',+ 'Get-Content -Encoding utf8 ./safe.txt',+ 'Get-Content\u00a0./safe.txt',+ 'Write-Output ok; Get-Content $target',+ 'Write-Output ok; Get-Content (Join-Path . id_rsa)',+ 'git status | Get-Content $target',+ 'git status > status.txt; Get-Content ./safe.txt',+ '(Get-Content ./safe.txt)',+ '{ Get-Content ./safe.txt }',+ 'git status & Get-Content ./safe.txt',+ 'Get-`Content ./safe.txt',+ 'Write-Output ok && Get-Content ./safe.txt',+ 'Write-Output ok\u2028Get-Content ./safe.txt',+ "Write-Output ok; Get-Content './unterminated",+ ]) {+ expect(evidence({ command }), command).toEqual({ targets: [], unresolved: true });+ }+ expect(evidence({ command: 'Write-Output ok' })).toEqual({ targets: [], unresolved: false });+ });++ it('keeps ordinary PowerShell operators out of credential-read evidence', () => {+ const evidence = loadPowerShellReadEvidence(process.cwd());+ for (const command of [+ 'git status | Out-String',+ 'git status > status.txt',+ '(git status)',+ '{ git status }',+ 'git status &',+ 'Write-Output foo`nbar',+ "Write-Output '(Get-Content ./safe.txt)'",+ 'Write-Output ok && Write-Output done',+ 'Write-Output ok\u2028Write-Output done',+ ]) {+ expect(evidence({ command }), command).toEqual({ targets: [], unresolved: false });+ }+ });+it.skipIf(process.platform === 'win32')('collects canonical credential targets without flagging ordinary symlinks',() => {@@ -964,7 +1135,8 @@ describe('cindy-bridge extension source', () => {hasUnresolvedTarget: false,});expect(source).toContain("event.toolName === 'bash'\n ? bashInputReadEvidence(event.input)");- expect(source).toContain('bashReadEvidence.unresolved || touchesCredentialPath(bashReadTargets)');+ expect(source).toContain("event.toolName === 'powershell'\n ? powershellInputReadEvidence(event.input)");+ expect(source).toContain('isCindyShellTool(event.toolName) && (bashReadEvidence.unresolved || touchesCredentialPath(bashReadTargets))');expect(source).toContain('resolvedCredentialPaths: credentialEvidenceForHost');} finally {rmSync(tempRoot, { recursive: true, force: true });@@ -978,6 +1150,10 @@ describe('cindy-bridge extension source', () => {for (const tool of ['createBashTool', 'createFindTool', 'createGrepTool', 'createLsTool']) {expect(source).toContain(tool + ',');}+ expect(source).toContain('import * as piCodingAgent from');+ expect(source).toContain('createPowerShellTool');+ expect(source).toContain('function isCindyShellTool');+ expect(source).toContain('function powershellInputReadEvidence');expect(source).toContain("const args = ['--files', '--hidden', '--no-require-git']");expect(source).toContain("if (pattern.includes('/')) {");expect(source).toContain('path.basename(relative)');@@ -1064,6 +1240,18 @@ describe('cindy-bridge extension source', () => {});});+ it('registers the native PowerShell overlay on Windows when Pi exports its factory', () => {+ expect(powerShellOverlayEnabled('win32', () => undefined)).toBe(true);+ expect(powerShellOverlayEnabled('win32', undefined)).toBe(false);+ });++ it.each(['darwin', 'linux'] as const)(+ 'does not register the native PowerShell overlay on %s',+ (platform) => {+ expect(powerShellOverlayEnabled(platform, () => undefined)).toBe(false);+ },+ );+it('keeps Pi vision bridge tool security invariants (registration, size, magic-byte, redirect, redaction)', () => {const source = CINDY_BRIDGE_EXTENSION_SOURCE;// 工具只在已启用且可解析 primary 后端时注册(fallback-only 不注册)。@@ -1100,12 +1288,24 @@ describe('cindy-bridge extension source', () => {expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain("pi.on('tool_call'");expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain('FILE_WRITE_BUILTINS.has(event.toolName)');expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain("pi.on('tool_result'");- expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain("captureToolName !== 'bash'");expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain("String(captureToolName ?? '').startsWith('mcp__')");expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain('captureToolName = gatewayCall?.qualifiedName');expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain('captureInput = gatewayCall?.args');});+ it('routes PowerShell results through the same opaque turn-change capture as bash', () => {+ const source = CINDY_BRIDGE_EXTENSION_SOURCE;+ const handlerStart = source.indexOf("pi.on('tool_result'");+ const handlerEnd = source.indexOf('// ── 视觉桥工具', handlerStart);+ expect(handlerStart).toBeGreaterThanOrEqual(0);+ expect(handlerEnd).toBeGreaterThan(handlerStart);+ const handler = source.slice(handlerStart, handlerEnd);++ expect(source).toContain("return toolName === 'bash' || toolName === 'powershell';");+ expect(handler).toContain('if (!isCindyShellTool(captureToolName)');+ expect(handler).toContain('TURN_CHANGE_CAPTURE_TITLE');+ });+it('exposes a constant two-tool MCP gateway while preserving the real MCP identity for approval', () => {expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain("const CINDY_MCP_LIST_TOOLS = 'cindy_mcp_list_tools'");expect(CINDY_BRIDGE_EXTENSION_SOURCE).toContain("const CINDY_MCP_CALL_TOOL = 'cindy_mcp_call_tool'");@@ -1329,7 +1529,7 @@ describe('cindy-bridge extension source', () => {it('hard-blocks writes only in read-only reference roots, not external writable roots', () => {const source = CINDY_BRIDGE_EXTENSION_SOURCE;const readOnlyGate = source.indexOf('permission.readOnlyRoots.some((root) =>');- const credentialGate = source.indexOf("if (event.toolName === 'bash' && commandReadsProcessEnviron", readOnlyGate);+ const credentialGate = source.indexOf('if (isCindyShellTool(event.toolName) && commandReadsProcessEnviron', readOnlyGate);expect(readOnlyGate).toBeGreaterThan(-1);expect(credentialGate).toBeGreaterThan(readOnlyGate);expect(source.slice(readOnlyGate, credentialGate)).not.toContain('permission.writableRoots');diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.tsindex cf3c51200c..14dee18fb3 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-agent.integration.test.ts@@ -362,7 +362,13 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewa'content-type': 'text/event-stream','cache-control': 'no-cache',});- res.end(scriptedResponses.shift() ?? anthropicStreamBody('pong from fake gateway'));+ const url = req.url ?? '';+ const fallback = url.includes('/responses')+ ? responsesStreamBody('pong from fake gateway', 'pi-test-model')+ : url.includes('/chat/completions')+ ? chatCompletionsStreamBody('pong from fake gateway', 'pi-test-model')+ : anthropicStreamBody('pong from fake gateway');+ res.end(scriptedResponses.shift() ?? fallback);});});await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));@@ -831,6 +837,8 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewaresponsesStreamBody('pong from xai responses', 'grok-4.5'),'/v1/responses',);+ // Pi v0.84.3 moved bundled xAI models onto Responses with encrypted+ // reasoning replay. grok-build-0.1 is no longer Chat Completions.await run('itest-native-xai-completions','xai/grok-build-0.1',@@ -1388,7 +1396,18 @@ describe.skipIf(!piAvailable)('PiAgent integration (real pi binary + fake gatewaconst activeConfigHomes = readdirSync(runTmp, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => path.join(runTmp, entry.name))- .filter((candidate) => existsSync(path.join(candidate, 'models.json')));+ .filter((candidate) => {+ const modelsPath = path.join(candidate, 'models.json');+ if (!existsSync(modelsPath)) return false;+ try {+ const parsed = JSON.parse(readFileSync(modelsPath, 'utf8')) as {+ providers?: Record<string, unknown>;+ };+ return Boolean(parsed.providers?.localbyom);+ } catch {+ return false;+ }+ });expect(activeConfigHomes).toHaveLength(1);const configHome = activeConfigHomes[0];if (!configHome) throw new Error('active Pi config home missing');diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.tsindex eafd955eb0..1b894330de 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.ts@@ -76,6 +76,18 @@ describe('classifyPiToolForAutoReview', () => {expect(verdict('bash', {})).not.toBe('auto-approve');});+ it('routes Pi 0.84.3 powershell through the same shell classifier, not unknown-tool gray', () => {+ expect(verdict('powershell', { command: 'git status' })).toBe('auto-approve');+ expect(verdict('powershell', { command: 'sudo whoami' })).toBe('prompt-each-time');+ expect(verdict('powershell', { command: 'rm -rf /' })).toBe('prompt-each-time');+ expect(verdict('powershell', {})).not.toBe('auto-approve');+ expect(verdict(+ 'powershell',+ { command: 'Get-Content innocent.txt' },+ ['/Users/t/.ssh/id_rsa'],+ )).toBe('prompt-each-time');+ });+it('approves plain reads but always prompts for credential paths (bridge-drift defense)', () => {expect(verdict('read', { path: `${WS}/src/a.ts` })).toBe('auto-approve');expect(verdict('read', { path: '/Users/t/.ssh/id_rsa' })).toBe('prompt-each-time');diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-translator.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-translator.test.tsindex 899ef12c16..3ceb53ba4b 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-translator.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-translator.test.ts@@ -1016,6 +1016,23 @@ describe('pi translator', () => {expect(full).toMatchObject({ data: { fullText: stale } });});+ it('ignores Pi 0.84.3 session_compact_failed RPC leaks without hanging compaction UI', () => {+ const ctx = createPiTranslateContext(noopLogger);+ const { queue, events } = makeQueue();+ translatePiEvent(+ ev({+ type: 'session_compact_failed',+ reason: 'overflow',+ aborted: false,+ errorMessage: 'quota',+ }),+ queue,+ ctx,+ );+ expect(events.some((event) => event.type === 'compact_boundary')).toBe(false);+ expect(events.some((event) => event.type === 'error')).toBe(false);+ });+it('maps compaction_end (threshold) → compact_boundary with token deltas + updates contextTokens', () => {const ctx = createPiTranslateContext(noopLogger);const { queue, events } = makeQueue();diff --git a/packages/maker-core/src/agents/pi/auto-review-policy.ts b/packages/maker-core/src/agents/pi/auto-review-policy.tsindex 7ce61f0dae..509900738f 100644--- a/packages/maker-core/src/agents/pi/auto-review-policy.ts+++ b/packages/maker-core/src/agents/pi/auto-review-policy.ts@@ -5,7 +5,7 @@** pi 侧的到达面与 CC 不同:bridge 在 pi 进程内直通「只读内置四件套且入参不碰凭证* 路径」(见 cindy-bridge-source.ts READONLY_BUILTINS + touchesCredentialPath),- * `bypassPermissions` 全放行 —— 能到这里的是 bash / edit / write / 桥接 MCP 工具 /+ * `bypassPermissions` 全放行 —— 能到这里的是 bash / powershell / edit / write / 桥接 MCP 工具 /* 凭证路径的只读调用 / 未来新增内置工具。只读分支扫全部字符串入参判凭证,与 bridge* 同判定:bridge 升级上来的凭证读在 auto 档必须落弹窗,不能被 path 字段缺失反向放行。*@@ -67,6 +67,9 @@ const READ_ONLY_TOOLS: ReadonlySet<string> = new Set(['read', 'grep', 'find', 'l/** 会改文件、带结构化 `path` 入参的 pi 内置工具。 */const FILE_WRITE_TOOLS: ReadonlySet<string> = new Set(['write', 'edit']);+/** Pi v0.84.3 起 Windows 可选 powershell 与 bash 同为 shell 执行面,入参都是 `command`。 */+const SHELL_TOOLS: ReadonlySet<string> = new Set(['bash', 'powershell']);+function stringField(input: Record<string, unknown>, key: string): string | undefined {const v = input[key];return typeof v === 'string' && v.length > 0 ? v : undefined;@@ -143,7 +146,7 @@ export function normalizePiToolForAutoReview(ctx: PiAutoReviewContext): Reviewabif (FILE_WRITE_TOOLS.has(toolName)) {return { kind: 'file-write', path: stringField(input, 'path') };}- if (toolName === 'bash') {+ if (SHELL_TOOLS.has(toolName)) {const evidenceAction = canonicalCredentialEvidenceAction(ctx.resolvedCredentialPaths);if (evidenceAction) return evidenceAction;return { kind: 'exec', command: stringField(input, 'command') ?? '' };diff --git a/packages/maker-core/src/agents/pi/cindy-bridge-source.ts b/packages/maker-core/src/agents/pi/cindy-bridge-source.tsindex d26e9fb79b..b2ec564239 100644--- a/packages/maker-core/src/agents/pi/cindy-bridge-source.ts+++ b/packages/maker-core/src/agents/pi/cindy-bridge-source.ts@@ -68,6 +68,7 @@ import {createGrepTool,createLsTool,} from '@earendil-works/pi-coding-agent';+import * as piCodingAgent from '@earendil-works/pi-coding-agent';const PERMISSION_TITLE = 'cindy:permission';const TURN_CHANGE_CAPTURE_TITLE = 'cindy:turn-change-capture';@@ -76,6 +77,9 @@ const PERMISSION_USER_DENY = 'user-deny';const PERMISSION_AUTO_REVIEW_DENY = 'auto-review-deny';const READONLY_BUILTINS = new Set(['read', 'grep', 'find', 'ls']);const FILE_WRITE_BUILTINS = new Set(['edit', 'write']);+function isCindyShellTool(toolName: unknown): boolean {+ return toolName === 'bash' || toolName === 'powershell';+}const MANAGED_RG_PATH_ENV = 'CINDY_PI_MANAGED_RG_PATH';const SUBAGENT_RUN_DIR_ENV = 'CINDY_PI_SUBAGENT_RUN_DIR';const PI_PACKAGE_MANAGEMENT_ENV = 'CINDY_PI_PACKAGE_MANAGEMENT';@@ -730,6 +734,235 @@ function bashExpandedPathCandidates(}}+const POWERSHELL_DIRECT_FILE_READ_COMMANDS = new Set(['get-content', 'gc', 'cat', 'type']);+const POWERSHELL_WORKING_DIRECTORY_COMMANDS = new Set([+ 'set-location', 'cd', 'chdir', 'sl',+ 'push-location', 'pushd', 'pop-location', 'popd',+]);+const POWERSHELL_GET_CONTENT_SWITCHES = new Set(['-raw', '-wait', '-force', '-asbytestream']);++type PowerShellDirectArguments = { words: string[]; unresolved: boolean };+type PowerShellDirectStatements = { statements: string[]; unresolved: boolean };++function powershellDirectStatements(command: string): PowerShellDirectStatements {+ const statements: string[] = [];+ let current = '';+ let quote: "'" | '"' | null = null;+ const flush = () => {+ const statement = current.trim();+ if (statement) statements.push(statement);+ current = '';+ };+ for (let cursor = 0; cursor < command.length; cursor += 1) {+ const character = command[cursor];+ if (quote) {+ current += character;+ if (character === quote) {+ if (quote === "'" && command[cursor + 1] === "'") {+ current += command[cursor + 1];+ cursor += 1;+ } else {+ quote = null;+ }+ }+ continue;+ }+ if (character === "'" || character === '"') {+ quote = character;+ current += character;+ continue;+ }+ if (character === '|') {+ flush();+ if (command[cursor + 1] === '|') cursor += 1;+ continue;+ }+ if (character === String.fromCharCode(96) || /[&(){}<>]/.test(character)) {+ return { statements, unresolved: true };+ }+ const startsComment = character === '#'+ && (current.length === 0 || /\s/.test(current[current.length - 1]));+ if (startsComment) {+ while (cursor + 1 < command.length && command[cursor + 1] !== '\n') cursor += 1;+ flush();+ continue;+ }+ if (character === '\u2028' || character === '\u2029') {+ return { statements, unresolved: true };+ }+ if (character === ';' || character === '\n' || character === '\r') {+ flush();+ continue;+ }+ current += character;+ }+ if (quote) return { statements, unresolved: true };+ flush();+ return { statements, unresolved: false };+}++function powershellMayHideDirectFileRead(command: string): boolean {+ let surface = '';+ let quote: "'" | '"' | null = null;+ for (let cursor = 0; cursor < command.length; cursor += 1) {+ const character = command[cursor];+ if (quote) {+ if (quote === '"' && character === String.fromCharCode(96)) {+ cursor += 1;+ } else if (character === quote) {+ if (quote === "'" && command[cursor + 1] === "'") cursor += 1;+ else quote = null;+ }+ continue;+ }+ if (character === "'" || character === '"') {+ quote = character;+ continue;+ }+ const startsComment = character === '#'+ && (surface.length === 0 || /[\s;|&(){}<>]/.test(surface[surface.length - 1]));+ if (startsComment) {+ while (cursor + 1 < command.length && !/[\r\n]/.test(command[cursor + 1])) cursor += 1;+ continue;+ }+ if (character === String.fromCharCode(96)) {+ const escaped = command[cursor + 1];+ if (escaped === '\r' && command[cursor + 2] === '\n') cursor += 2;+ else if (escaped === '\r' || escaped === '\n') cursor += 1;+ else if (escaped) {+ surface += /[\s;|&(){}<>]/.test(escaped) ? '_' : escaped;+ cursor += 1;+ }+ continue;+ }+ surface += character;+ }+ return /(?:^|[;\r\n\u2028\u2029|&(){}])\s*(?:[A-Za-z][A-Za-z0-9.-]*\\)?(?:get-content|gc|cat|type)(?=\s|[;|&(){}<>]|$)/i.test(surface);+}++function powershellDirectArguments(command: string, start: number): PowerShellDirectArguments {+ const words: string[] = [];+ let cursor = start;+ while (cursor < command.length) {+ while (/[ \t\r]/.test(command[cursor] ?? '')) cursor += 1;+ if (cursor >= command.length || command[cursor] === '#') break;+ if (/\s/.test(command[cursor])) return { words, unresolved: true };+ const quote = command[cursor] === "'" || command[cursor] === '"' ? command[cursor] : null;+ let word = '';+ if (quote) {+ cursor += 1;+ let closed = false;+ while (cursor < command.length) {+ const character = command[cursor];+ if (character === quote) {+ if (quote === "'" && command[cursor + 1] === "'") {+ word += "'";+ cursor += 2;+ continue;+ }+ cursor += 1;+ closed = true;+ break;+ }+ if (quote === '"' && (character === '$' || character === String.fromCharCode(96))) {+ return { words, unresolved: true };+ }+ word += character;+ cursor += 1;+ }+ if (!closed || (cursor < command.length && !/[ \t\r#]/.test(command[cursor]))) {+ return { words, unresolved: true };+ }+ } else {+ while (cursor < command.length && !/[ \t\r]/.test(command[cursor])) {+ const character = command[cursor];+ if (/\s/.test(character) || /[;|&(){}<>]/.test(character)) {+ return { words, unresolved: true };+ }+ if (+ character === '$'+ || character === ','+ || character === "'"+ || character === '"'+ || character === String.fromCharCode(96)+ ) {+ return { words, unresolved: true };+ }+ word += character;+ cursor += 1;+ }+ }+ if (!word) return { words, unresolved: true };+ words.push(word);+ }+ return { words, unresolved: false };+}++function powershellDirectCommand(command: string): { name: string; end: number } | null {+ const match = /^\s*(?:[A-Za-z][A-Za-z0-9.-]*\\)?([A-Za-z][A-Za-z0-9-]*)(?=\s|$)/.exec(command);+ return match ? { name: match[1].toLowerCase(), end: match[0].length } : null;+}++function powershellStaticReadTarget(word: string, literal: boolean, cwd: string | null): string | null {+ if (!word || word === '-' || word.startsWith('@') || word.startsWith('~')) return null;+ if (/^[A-Za-z][A-Za-z0-9.-]*:/.test(word) && !/^[A-Za-z]:[\\/]/.test(word)) return null;+ if (!literal && /[*?\[]/.test(word)) return null;+ if (path.isAbsolute(word)) return path.normalize(word);+ return cwd === null ? null : path.resolve(cwd, word);+}++function powershellDirectReadEvidence(command: string, cwd: string | null): BashInputReadEvidence {+ const direct = powershellDirectCommand(command);+ if (!direct || !POWERSHELL_DIRECT_FILE_READ_COMMANDS.has(direct.name)) {+ // Invoke-Expression, the call operator, variable command names and other indirect forms+ // are intentionally outside this narrow direct-read contract.+ return { targets: [], unresolved: false };+ }+ const parsed = powershellDirectArguments(command, direct.end);+ if (parsed.unresolved) return { targets: [], unresolved: true };+ let targetWord: string | null = null;+ let literal = false;+ for (let index = 0; index < parsed.words.length; index += 1) {+ const word = parsed.words[index];+ const lower = word.toLowerCase();+ if (lower === '-path' || lower === '-literalpath') {+ if (targetWord !== null || index + 1 >= parsed.words.length) return { targets: [], unresolved: true };+ literal = lower === '-literalpath';+ targetWord = parsed.words[index + 1];+ index += 1;+ continue;+ }+ if (POWERSHELL_GET_CONTENT_SWITCHES.has(lower)) continue;+ if (word.startsWith('-') || targetWord !== null) return { targets: [], unresolved: true };+ targetWord = word;+ }+ const target = targetWord === null ? null : powershellStaticReadTarget(targetWord, literal, cwd);+ return target ? { targets: [target], unresolved: false } : { targets: [], unresolved: true };+}++function powershellInputReadEvidence(input: unknown): BashInputReadEvidence {+ if (!input || typeof input !== 'object') return { targets: [], unresolved: false };+ const command = (input as Record<string, unknown>).command;+ if (typeof command !== 'string' || !command) return { targets: [], unresolved: false };+ const payload = powershellDirectStatements(command);+ if (payload.unresolved) {+ return powershellMayHideDirectFileRead(command)+ ? { targets: [], unresolved: true }+ : { targets: [], unresolved: false };+ }+ const targets: string[] = [];+ let unresolved = false;+ let cwd: string | null = process.cwd();+ for (const statement of payload.statements) {+ const direct = powershellDirectCommand(statement);+ if (direct && POWERSHELL_WORKING_DIRECTORY_COMMANDS.has(direct.name)) cwd = null;+ const evidence = powershellDirectReadEvidence(statement, cwd);+ targets.push(...evidence.targets);+ unresolved ||= evidence.unresolved;+ }+ return { targets: [...new Set(targets)], unresolved };+}+function bashInputReadEvidence(input: unknown): BashInputReadEvidence {if (!input || typeof input !== 'object') return { targets: [], unresolved: false };const command = (input as Record<string, unknown>).command;@@ -2968,6 +3201,52 @@ export default async function cindyBridge(pi: any) {},});+ // Pi v0.84.3 Windows powershell is the same spawn family as bash. Overlay only+ // on Windows and when the runtime exports the factory so 0.83.0 sessions keep loading.+ const createPowerShellTool = (piCodingAgent as { createPowerShellTool?: typeof createBashTool }).createPowerShellTool;+ if (process.platform === 'win32' && typeof createPowerShellTool === 'function') {+ const powershellTool = createPowerShellTool(process.cwd(), {+ exposeSessionEnvironment: false,+ spawnHook: ({ command, cwd, env }) => ({+ command,+ cwd,+ env: isolatedBashEnvironment(env, bashPackageHome),+ }),+ });+ var powershellParameters = powershellTool.parameters;+ if (+ powershellParameters &&+ typeof powershellParameters === 'object' &&+ powershellParameters.properties &&+ typeof powershellParameters.properties === 'object' &&+ powershellParameters.properties.timeout &&+ typeof powershellParameters.properties.timeout === 'object'+ ) {+ powershellParameters.properties.timeout.description = cindyBashTimeoutDescription();+ }+ if (typeof powershellTool.description === 'string') {+ powershellTool.description =+ powershellTool.description ++ ' Cindy enforces a ' ++ CINDY_PI_BASH_DEFAULT_TIMEOUT_SECONDS ++ 's default and a ' ++ CINDY_PI_BASH_MAX_TIMEOUT_SECONDS ++ 's maximum.';+ }+ pi.registerTool({+ ...powershellTool,+ execute: async (id: string, params: unknown, signal: AbortSignal, onUpdate: unknown) => {+ const nextParams = applyCindyBashTimeoutParams(params);+ if (bashCommandMutatesPiPackages(nextParams)) {+ throw new Error(+ 'Direct Pi extension changes are unavailable through bash. Use cindy_pi_extension so Cindy can request confirmation.',+ );+ }+ return powershellTool.execute(id, nextParams as any, signal, onUpdate as any);+ },+ });+ }+// Cindy owns a separate Pi extension store. Directly running the bundled Pi// CLI from bash writes to Pi's default user home and bypasses Cindy's// compatibility/approval state. Normal local tasks therefore receive one@@ -3175,7 +3454,7 @@ export default async function cindyBridge(pi: any) {// bash 读取任意进程的初始环境(/proc/<pid|self>/environ)是绕过密钥剥离的旁路:// spawn 边界虽删了子进程 env 的私密变量,父 pi 进程仍持有,cat /proc/PPID/environ// 同 UID 直取代理 token / 网关 / BYOM key(codex 报)→ 一律硬拦,含 Full access。- if (event.toolName === 'bash' && commandReadsProcessEnviron(event.input?.command)) {+ if (isCindyShellTool(event.toolName) && commandReadsProcessEnviron(event.input?.command)) {return { block: true, reason: 'Cindy blocks reading process environment (/proc/*/environ), even with Full access.' };}// 凭证/密钥路径的内置只读工具与 bash 输入重定向都必须携带 canonical@@ -3183,18 +3462,20 @@ export default async function cindyBridge(pi: any) {// parser 提取真实输入目标,才能识别工作区 symlink 指向的凭证文件。const bashReadEvidence = event.toolName === 'bash'? bashInputReadEvidence(event.input)- : { targets: [], unresolved: false };+ : event.toolName === 'powershell'+ ? powershellInputReadEvidence(event.input)+ : { targets: [], unresolved: false };const bashReadTargets = bashReadEvidence.targets;const readonlyCredentialEvidence = READONLY_BUILTINS.has(event.toolName)? collectReadonlyCredentialEvidence(event.toolName, event.input): null;const resolvedCredentialReadPaths = readonlyCredentialEvidence? [...new Set(collectResolvedCredentialPaths(readonlyCredentialEvidence.paths))]- : event.toolName === 'bash'+ : isCindyShellTool(event.toolName)? [...new Set(collectResolvedCredentialPaths(bashReadTargets))]: [];const credentialRead = readonlyCredentialEvidence?.touchesCredential === true- || (event.toolName === 'bash' && (bashReadEvidence.unresolved || touchesCredentialPath(bashReadTargets)))+ || (isCindyShellTool(event.toolName) && (bashReadEvidence.unresolved || touchesCredentialPath(bashReadTargets)))|| resolvedCredentialReadPaths.length > 0;const credentialEvidenceForHost = resolvedCredentialEvidenceForHost(resolvedCredentialReadPaths,@@ -3286,7 +3567,7 @@ export default async function cindyBridge(pi: any) {: null;const captureToolName = gatewayCall?.qualifiedName ?? event.toolName;const captureInput = gatewayCall?.args ?? event.input ?? {};- if (captureToolName !== 'bash' && !String(captureToolName ?? '').startsWith('mcp__')) return;+ if (!isCindyShellTool(captureToolName) && !String(captureToolName ?? '').startsWith('mcp__')) return;try {await ctx.ui.confirm(TURN_CHANGE_CAPTURE_TITLE,diff --git a/packages/maker-core/src/agents/pi/translator.ts b/packages/maker-core/src/agents/pi/translator.tsindex 1edea217ec..7af0a8314d 100644--- a/packages/maker-core/src/agents/pi/translator.ts+++ b/packages/maker-core/src/agents/pi/translator.ts@@ -1098,6 +1098,9 @@ export function translatePiEvent(case 'summarization_retry_attempt_start':case 'summarization_retry_finished':case 'bash_execution_update':+ // Pi v0.84.3 extension telemetry. If it ever leaks onto the RPC stream,+ // ignore it: compaction_end already carries aborted/errorMessage.+ case 'session_compact_failed':return;case 'extension_error': {