← 返回更新日志

Pi v0.65.0

2026-04-03 · GitHub 原文
### 新功能 - **Session 运行时 API**:`createAgentSessionRuntime()` 和 `AgentSessionRuntime` 提供了一个基于闭包的运行时,每次切换 Session 时都会重建与当前工作目录(cwd)绑定的服务和 Session 配置。启动、`/new`、`/resume`、`/fork` 和导入均使用相同的创建路径。详见 [docs/sdk.md](docs/sdk.md) 和 [examples/sdk/13-session-runtime.ts](examples/sdk/13-session-runtime.ts)。 - **`/tree` 中的标签时间戳**:按 `Shift+T` 切换树节点的时间戳显示,支持智能日期格式化和分支操作中的时间戳保留([#2691](https://github.com/badlogic/pi-mono/pull/2691) by [@w-winter](https://github.com/w-winter)) - **`defineTool()` 辅助函数**:创建独立的自定义工具定义,支持完整的 TypeScript 参数类型推断,无需手动类型转换([#2746](https://github.com/badlogic/pi-mono/issues/2746))。详见 [docs/extensions.md](docs/extensions.md)。 - **统一诊断模型**:参数解析、服务创建、Session 选项解析和资源加载均返回结构化诊断信息(`info`/`warning`/`error`),而非直接打印日志或退出。应用层负责决定展示方式和退出行为。 ### 破坏性变更 - 移除扩展状态切换后事件 `session_switch` 和 `session_fork`。请改用 `session_start` 配合 `event.reason`(`"startup" | "reload" | "new" | "resume" | "fork"`)。对于 `"new"`、`"resume"` 和 `"fork"`,`session_start` 会包含 `previousSessionFile`。 - 从 `AgentSession` 中移除 Session 替换方法。请使用 `AgentSessionRuntime` 来执行 `newSession()`、`switchSession()`、`fork()` 和 `importFromJsonl()`。跨 cwd 的 Session 替换会重建所有 cwd 绑定的运行时状态,并替换实时的 `AgentSession` 实例。 - 从扩展和设置 API 中移除 `session_directory`。 - 未知的单横线 CLI 标志(例如 `-s`)现在会报错,而不是被静默忽略。 #### 迁移指南:扩展 迁移前: ```ts pi.on("session_switch", async (event, ctx) => { ... }); pi.on("session_fork", async (_event, ctx) => { ... }); ``` 迁移后: ```ts pi.on("session_start", async (event, ctx) => { // event.reason: "startup" | "reload" | "new" | "resume" | "fork" // event.previousSessionFile: 适用于 "new", "resume", "fork" }); ``` #### 迁移指南:SDK Session 替换 迁移前: ```ts await session.newSession(); await session.switchSession("/path/to/session.jsonl"); ``` 迁移后: ```ts import { type CreateAgentSessionRuntimeFactory, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, getAgentDir, SessionManager, } from "@mariozechner/pi-coding-agent"; const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => { const services = await createAgentSessionServices({ cwd }); return { ...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })), services, diagnostics: services.diagnostics, }; }; const runtime = await createAgentSessionRuntime(createRuntime, { cwd: process.cwd(), agentDir: getAgentDir(), sessionManager: SessionManager.create(process.cwd()), }); await runtime.newSession(); await runtime.switchSession("/path/to/session.jsonl"); await runtime.fork("entry-id"); // 替换后,runtime.session 为新的实时 Session。 // 重新绑定任何 Session 本地的订阅或扩展绑定。 ``` ### 新增 - 新增 `createAgentSessionRuntime()` 和 `AgentSessionRuntime` 以支持基于运行时的 Session 替换。运行时接收一个 `CreateAgentSessionRuntimeFactory` 闭包,该闭包捕获进程级固定输入,并为每个有效 cwd 重建 cwd 绑定的服务和 Session 配置。启动及后续的 `/new`、`/resume`、`/fork`、导入均使用同一工厂。 - 新增统一诊断模型(`info`/`warning`/`error`),用于参数解析、服务创建、Session 选项解析和资源加载。创建逻辑不再直接打印日志或退出,由应用层决定展示与退出行为。 - 为缺失显式 CLI 资源路径(`-e`、`--skill`、`--prompt-template`、`--theme`)的情况新增错误诊断 - 新增 `defineTool()`,使独立和基于数组的自定义工具定义在无需手动转换的情况下保留推断的参数类型([#2746](https://github.com/badlogic/pi-mono/issues/2746)) - 在 Session 树中新增标签时间戳,支持在 `/tree` 中通过 `Shift+T` 切换,具备智能日期格式化及分支操作中的时间戳保留功能([#2691](https://github.com/badlogic/pi-mono/pull/2691) by [@w-winter](https://github.com/w-winter)) ### 修复 - 修复启动资源加载逻辑,使其复用初始 `ResourceLoader` 用于第一个运行时,从而避免在 Session 启动前扩展被加载两次,并确保 `session_start` 处理器仍能为单例式扩展触发([#2766](https://github.com/badlogic/pi-mono/issues/2766)) - 修复重试结算逻辑,使重试的 Agent 运行在声明空闲前等待完整重试周期完成,防止瞬态错误后出现状态陈旧问题 - 修复主题 `export` 颜色解析,使其与 `colors` 以相同方式解析主题变量,因此 `/export` HTML 背景现在支持 `pageBg: "base"` 等条目,而无需内联十六进制值([#2707](https://github.com/badlogic/pi-mono/issues/2707)) - 修复 Bedrock 限流错误被误判为上下文溢出的问题,避免不必要的压缩操作,改为重试([#2699](https://github.com/badlogic/pi-mono/pull/2699) by [@xu0o0](https://github.com/xu0o0)) - 为较新的 Z.ai 模型新增工具流式传输支持([#2732](https://github.com/badlogic/pi-mono/pull/2732) by [@kaofelix](https://github.com/kaofelix))