Pi coding agent v1.2.0:破坏性变更、OpenRouter按Key过滤与Codem
v1.2.0
推荐理由
v1.2.0包含多处破坏性变更,特别是before_agent_start行为改变和会话状态逻辑调整,会直接打断现有扩展开发与自动化工作流。依赖Pi进行编码代理或MCP集成的开发者必须检查代码适配,避免运行时异常。
New Features
新功能
- Per-key OpenRouter model lists: with an OpenRouter key, Pi lists only the models that key may use, with the key's context size, max output, and prices, including regional endpoints set in models.json. See OpenRouter.
- Published configuration schemas: add $schema to settings.json, models.json, keybindings, and themes for editor validation and completion. See Settings, Models, Keybindings, and Themes.
- Clipboard copies over remote sessions: PI_CLIPBOARD_OSC52=1 sends copied text to a remote client's clipboard when Pi cannot detect the remote session, such as a multiplexer attached from another machine. See Pi Process Configuration.
- Codemode improvements: tool declarations show input constraints such as integer, minimum/maximum, and default, and codemode rows show elapsed and total time. See Codemode.
- before_agent_start for extension-triggered runs: runs started by pi.sendMessage(..., { triggerTurn: true }) go through the same setup as prompts. See Events and concurrency.
- 按密钥的 OpenRouter 模型列表:使用 OpenRouter 密钥时,Pi 仅列出该密钥可用的模型,并显示密钥的上下文大小、最大输出量和价格,包括在 models.json 中设置区域端点。请参阅 OpenRouter。
- 已发布的配置模式:在 settings.json、models.json、keybindings 和 themes 中添加 $schema,以支持编辑器的验证和自动补全。请参阅 Settings、Models、Keybindings 和 Themes。
- 远程会话中的剪贴板复制:当 Pi 无法检测到远程会话(例如从另一台机器附加的多路复用器)时,PI_CLIPBOARD_OSC52=1 会将复制的文本发送到远程客户端的剪贴板。请参阅 Pi Process Configuration。
- Codemode 改进:工具声明显示输入约束(如整数、最小值/最大值和默认值),Codemode 行显示已用时间和总时间。请参阅 Codemode。
- 扩展触发的运行支持 before_agent_start:由 pi.sendMessage(..., { triggerTurn: true }) 启动的运行会经过与提示相同的设置流程。请参阅 Events and concurrency。
Breaking Changes
破坏性变更
- Published generated configuration schemas for models, settings, keybindings, and themes at https://pi.dev/schemas/*.schema.json. The theme schema moved to https://pi.dev/schemas/theme.schema.json; themes loaded during startup now receive the same schema validation as later reloads. Update theme $schema references, define reusable colors under vars, and remove unsupported metadata (#9880, #10751 by @christianklotz)
- Changed before_agent_start to also fire for runs started by pi.sendMessage(..., { triggerTurn: true }) while idle. BeforeAgentStartEvent is now a union on messageType: "user" events carry prompt and images, and "custom" events carry the starting message and no prompt. Messages returned by handlers are added to both kinds of run, and pending deliverAs: "nextTurn" messages are delivered with the custom-message run. Handlers that should act only on user prompts must check event.messageType === "user" (#10267, #5581, #10739 by @davidbrai)
- Changed the session to count as busy while a run starts, including during before_agent_start handlers: ctx.isIdle() is false, pi.sendMessage() queues into the starting run instead of starting a second run that failed with "Agent is already processing", pi.sendUserMessage() requires deliverAs, and an abort requested meanwhile aborts the run once it starts (#10739 by @davidbrai)
- Changed pi mcp list --json to report resources: true for servers that offer resources instead of resources and resourceTemplates counts; Pi no longer lists resources when connecting (#10526)
- 在 https://pi.dev/schemas/*.schema.json 发布了模型、设置、键绑定和主题的生成配置模式。主题模式已移至 https://pi.dev/schemas/theme.schema.json;启动期间加载的主题现在将接受与后续重新加载相同的模式验证。更新主题的 $schema 引用,在 vars 下定义可重用颜色,并移除不支持的元数据 (#9880, #10751 by @christianklotz)
- 更改了 before_agent_start 的行为,使其也在空闲状态下由 pi.sendMessage(..., { triggerTurn: true }) 启动运行时触发。BeforeAgentStartEvent 现在是一个基于 messageType 的联合类型:“user”事件携带提示和图片,“custom”事件携带起始消息且不携带提示。处理程序返回的消息会被添加到这两种类型的运行中,而 pending deliverAs: "nextTurn" 消息会在 custom-message 运行中交付。仅应在用户提示上执行操作的处理程序必须检查 event.messageType === "user" (#10267, #5581, #10739 by @davidbrai)
- 更改了会话状态,使其在运行开始时(包括在 before_agent_start 处理程序期间)被视为忙碌:ctx.isIdle() 为 false,pi.sendMessage() 会排队进入正在开始的运行,而不是启动第二个因“Agent is already processing”而失败的运行,pi.sendUserMessage() 需要指定 deliverAs,且在此期间请求的中止将在运行开始后中止该运行 (#10739 by @davidbrai)
- 修改了 pi mcp list --json,使其对于提供资源的服务器报告 resources: true,而不是报告 resources 和 resourceTemplates 的计数;Pi 在连接时不再列出资源(#10526)
Added
新增
- Added reachesTools to tool definitions, so tools that reach other tools (such as codemode and tool_search) declare which tools a call may reach; the MCP extension uses it to wait for the servers a call needs and to decide whether a replacement codemode or tool_search tool can reach MCP tools
- Added aliases to tool namespaces; codemode's describeNamespace() and the namespace option of searchTools() match them, and MCP namespaces use the server name
- Added per-key OpenRouter model lists: with an OpenRouter key, Pi lists only the chat models that key may use, with the key's context size, max output, and prices, including guardrails and regional endpoints set as the base URL in models.json. The list is saved and used offline (#10353, #10672 by @davidbrai)
- Added PI_CLIPBOARD_OSC52=1 to send copied text to the terminal with OSC 52 after the local clipboard write, so copies reach a remote client's clipboard when Pi cannot detect the remote session, such as multiplexer attaches from another machine or remote IDE daemons (#10826, #10835, #10114)
- Added elapsed time while a codemode script runs and its total time once finished to the codemode tool row, like bash rows (#10708)
- 在工具定义中添加了 reachesTools,以便能够调用其他工具的工具(如 codemode 和 tool_search)声明其调用可能触及哪些工具;MCP 扩展使用此信息来等待调用所需的服务器,并判断替换后的 codemode 或 tool_search 工具是否能触及 MCP 工具
- 为工具命名空间添加了别名;codemode 的 describeNamespace() 和 searchTools() 的 namespace 选项会匹配这些别名,且 MCP 命名空间使用服务器名称
- 新增了基于密钥的 OpenRouter 模型列表:拥有 OpenRouter 密钥后,Pi 仅列出该密钥可用的聊天模型,包括密钥对应的上下文大小、最大输出量和价格,并将 guardrails 和区域端点设置为 models.json 中的基础 URL。该列表会被保存并在离线时使用(#10353、#10672 by @davidbrai)
- 新增 PI_CLIPBOARD_OSC52=1,以便在本地剪贴板写入后通过 OSC 52 将复制的文本发送到终端,从而当 Pi 无法检测远程会话(例如从另一台机器附加的多路复用器或远程 IDE 守护进程)时,使复制内容能到达远程客户端的剪贴板(#10826、#10835、#10114)
- 在 codemode 工具行中添加了 codemode 脚本运行时的经过时间以及完成后的总时间,类似于 bash 行的显示方式(#10708)
Changed
修改
- Changed the showHardwareCursor setting to use only the terminal cursor instead of also drawing Pi's reverse-video cursor
- Changed codemode tool declarations to show input constraints such as integer, minimum/maximum, length, pattern, and default as @ tags on property comments, so scripts see them without the tool repeating them in descriptions (#10707)
- Changed codemode declarations of MCP tools to spell out the result type (content, structuredContent, isError) instead of referring to CallToolResult<T>, which describeTool(), searchTools(), and ALL_TOOLS showed without defining it; the codemode description no longer includes the shared MCP types
- Changed serializeConversation() (compaction, branch summaries, bug reports) to omit thinking blocks; replayed thinking is often not in the live context, so including it could make a summarization request larger than the context it summarizes and fail
- 修改 showHardwareCursor 设置,使其仅使用终端光标,而不再绘制 Pi 的反向视频光标
- 修改 codemode 工具声明,以在属性注释中以 @ 标签形式展示输入约束(如整数、最小/最大值、长度、模式和默认值),这样脚本无需工具在描述中重复这些信息即可看到它们(#10707)
- 修改 MCP 工具的 codemode 声明,明确写出结果类型(content、structuredContent、isError),而不是引用 CallToolResult<T>,因为 describeTool()、searchTools() 和 ALL_TOOLS 在未定义该类型的情况下展示了它;codemode 描述现在不再包含共享的 MCP 类型
- 修改 serializeConversation()(压缩、分支摘要、错误报告),使其省略思考块;重放的思考内容通常不在实时上下文中,因此包含它们可能导致摘要请求的大小超过其所摘要的上下文,从而导致失败
Fixed
修复
- Fixed codemode ignoring a // @options: line that is not the first line of the script, which ran the script without the requested timeout_ms; the call now fails with an error before the script runs (#10631)
- Fixed Mistral streams being aborted mid-generation (e.g. during long thinking) after the request timeout; the timeout now applies only to waiting for response headers (#10609)
- Fixed a symlinked AGENTS.md in a git worktree nested inside its main repo causing no project context file to load (#10681)
- Fixed the code mode tool description claiming every failed tool call rejects; a tool that declares an output schema resolves with its value on failure too (e.g. bash with a nonzero exit)
- Fixed runs started by pi.sendMessage(..., { triggerTurn: true }) removing system prompt sections added in before_agent_start after their first tool call, which changed the prompt mid-run and broke the provider prompt cache twice per run (#10267, #10739 by @davidbrai)
- Fixed codemode blocking the process for seconds to minutes after scripts with many text() calls; joining the output items was quadratic (#10678)
- Fixed print mode (-p) exiting 0 without a warning when the final response was cut off at the model's output token limit; it now prints the partial text, writes a warning to stderr, and exits 1 (#10799)
- Fixed pi mcp login --help and the CLI docs describing --timeout as only the wait for the browser; it limits the whole sign-in (#10636)
- Fixed ~ not being expanded in !pattern, +path, and -path entries of the extensions, skills, prompts, and themes settings, so entries like !~/skills/pdf matched nothing (#10765)
- Fixed MCP servers with resources registering no tools until every resource was listed; Pi no longer lists resources when connecting, so /mcp and pi mcp list show that a server offers resources instead of counting them (#10526)
- Fixed MCP tool calls failing when the server returns structured content that is not an object (an array, null, or a primitive, as MCP 2026-07-28 allows); codemode declarations of MCP tools without an output schema now type structuredContent as unknown instead of an object (#10416)
- Fixed reading or writing auth.json on Windows failing with EPERM when the previous lock folder was still being deleted; Pi now retries briefly before reporting the error (#10801)
- Fixed OpenRouter router models such as openrouter/auto showing a cost of -$1,000,000 per 1M tokens; OpenRouter's negative placeholder prices are now 0 (#10672 by @davidbrai)
- Fixed Anthropic requests failing when the provider rejects the strict tool set for grammar size, tool count, or union limits; Pi now retries once with preferred tools non-strict (#10409)
- Fixed "The upstream provider returned an error" not being retried as a transient provider error (#10842)
- Fixed focused fullscreen overlays blocking mouse-wheel scrolling of the transcript (#10769)
- Fixed fragmented terminal color replies leaking hex values into the prompt and opening the external editor (related reports: #10256, #10657)
- Fixed inline images not rendering in Herdr since 1.1.0 (#10774 by @ogulcancelik)
- 修复了 codemode 忽略非脚本第一行的 // @options: 行,导致脚本在未应用请求的 timeout_ms 的情况下运行;现在调用会在脚本运行前因错误而失败(#10631)
- 修复了 Mistral 流在生成过程中(例如长时间思考时)因请求超时而中途被中止的问题;现在超时仅适用于等待响应头 (#10609)
- 修复了在 git worktree 中嵌套的 AGENTS.md 符号链接导致无法加载项目上下文文件的问题,该 worktree 嵌套在其主仓库内 (#10681)
- 修复了代码模式工具描述中声称每次工具调用失败都会拒绝的问题;声明了输出架构的工具在失败时也会解析其值(例如退出码非零的 bash)
- 修复了由 pi.sendMessage(..., { triggerTurn: true }) 启动的运行在首次工具调用后移除了 before_agent_start 中添加的系统提示部分的问题,这导致运行期间提示词发生变化,并使提供商提示缓存每轮失效两次 (#10267, #10739 by @davidbrai)
- 修复了包含大量 text() 调用的脚本导致代码模式阻塞进程数秒至数分钟的问题;连接输出项的操作复杂度为二次方 (#10678)
- 修复了当最终响应在模型输出令牌限制处被截断时,打印模式 (-p) 无声地以退出码 0 退出的问题;现在它会打印部分文本,将警告写入 stderr,并以退出码 1 退出 (#10799)
- 修复了 pi mcp login --help 和 CLI 文档中将 --timeout 描述为仅等待浏览器的问题;它实际上限制了整个登录过程 (#10636)
- 修复了扩展、技能、提示和主题设置中的 !pattern、+path 和 -path 条目未展开 ~ 的问题,因此像 !~/skills/pdf 这样的条目匹配不到任何内容 (#10765)
- 修复了 MCP 服务器在未列出所有资源前不注册任何工具的问题;Pi 在连接时不再列出资源,因此 /mcp 和 pi mcp list 会显示服务器提供了哪些资源,而不是统计数量 (#10526)
- 修复了当服务器返回非对象的结构化内容(如数组、null 或基本类型,MCP 2026-07-28 允许这些类型)时 MCP 工具调用失败的问题;未声明输出架构的 MCP 工具的代码模式声明现在将 structuredContent 的类型设为 unknown 而非 object (#10416)
- 修复了在前一个锁文件夹仍在删除时,在 Windows 上读取或写入 auth.json 失败并报错 EPERM 的问题;Pi 现在在报告错误前会短暂重试 (#10801)
- 修复了 OpenRouter 路由器模型(如 openrouter/auto)显示每百万令牌成本为 -$1,000,000 的问题;OpenRouter 的负数占位价格现在已设为 0 (#10672 by @davidbrai)
- 修复了当提供商因语法大小、工具数量或联合限制而拒绝严格工具集时 Anthropic 请求失败的问题;Pi 现在会重试一次,并将首选工具设为非严格模式 (#10409)
- 修复了上游提供商返回错误时未作为临时提供商错误重试的问题(#10842)
- 修复了聚焦的全屏覆盖层阻止转录内容的鼠标滚轮滚动的问题(#10769)
- 修复了碎片化的终端颜色回复将十六进制值泄漏到提示符中并打开外部编辑器的问题(相关报告:#10256,#10657)
- 修复了自 1.1.0 版本以来 Herdr 中内联图像无法渲染的问题(#10774 by @ogulcancelik)
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力