Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(agent-runtime): adopt Pi 1.1.0 (#1504)

Lanc7e96f80311d
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 2ed53da5f..913d2597b 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -36,8 +36,8 @@
"electron-updater": "^6.8.9"
},
"devDependencies": {
- "@earendil-works/pi-ai": "1.0.1",
- "@earendil-works/pi-mcp": "1.0.1",
+ "@earendil-works/pi-ai": "1.1.0",
+ "@earendil-works/pi-mcp": "1.1.0",
"@pi-desktop/agent-host": "workspace:*",
"@pi-desktop/agent-runtime": "workspace:*",
"@pi-desktop/host-runtime": "workspace:*",
diff --git a/docs/project/README.md b/docs/project/README.md
index f65c09da1..34a014956 100644
--- a/docs/project/README.md
+++ b/docs/project/README.md
@@ -6,5 +6,6 @@
- Documentation/code alignment audit: [2026-07-30 audit](2026-07-30-docs-code-audit.md)
- Plan implementation plan: [`plan-mode-implementation-plan.md`](plan-mode-implementation-plan.md)
- Pi 1.0.1 adoption: [`pi-101-adoption.md`](pi-101-adoption.md)
+- Pi 1.1.0 adoption: [`pi-110-adoption.md`](pi-110-adoption.md)
- GitHub Issues + Milestones: repository Issues page
- GitHub Projects: create after adding the `project` token scope
diff --git a/docs/project/pi-110-adoption.md b/docs/project/pi-110-adoption.md
new file mode 100644
index 000000000..9faa574c9
--- /dev/null
+++ b/docs/project/pi-110-adoption.md
@@ -0,0 +1,67 @@
+# Pi 1.1.0 adoption
+
+## Scope
+
+All five direct Pi dependencies used by Agent Runtime and Electron Main are
+pinned exactly to `1.1.0`. The three Desktop patches were rebased against the
+published 1.1.0 packages and the lockfile records their patch hashes.
+
+| Workspace entry | Direct dependencies |
+| --- | --- |
+| `packages/agent-runtime` | `@earendil-works/pi-agent-core`, `@earendil-works/pi-ai`, `@earendil-works/pi-coding-agent` |
+| `apps/desktop` | `@earendil-works/pi-ai`, `@earendil-works/pi-mcp` |
+
+The 1.1.0 upgrade adopts pi-ai's monotonic `AssistantMessage.durationMs` for
+completed-response throughput. If the final message has no valid duration,
+the existing sidecar stopwatch remains in use, including for interrupted
+responses. This uses the existing `responseDurationMs` transcript field; no IPC
+or storage schema changes are needed.
+
+The upstream release also brings its current provider support, retry fixes and
+context-estimation changes. The rebased PI-Desktop patches preserve hosted
+search replay and estimation, local request error details, bounded Anthropic
+OAuth retries, DeepSeek's published system-message capability, and the upstream
+3.5-characters-per-token estimator. The new OpenAI Decisions classifier is not
+enabled by default because invoking it adds a separate outbound classification
+request; the existing explicit classifier configuration remains authoritative.
+
+Official release notes: [Pi 1.1.0 changelog](https://github.com/earendil-works/pi/blob/v1.1.0/packages/ai/CHANGELOG.md).
+
+## Fresh-release policy
+
+The Pi 1.1.0 release group is inside the configured minimum-release-age window.
+`pnpm-workspace.yaml` therefore contains exact-version exclusions for the eight
+published release-group packages. The dependency check rejects missing,
+additional, wildcard, or non-1.1.0 exclusions. Remove the entries after the
+release group clears the age window and regenerate the lockfile; do not widen
+them.
+
+## Patch identity
+
+| Package | Patch SHA-256 |
+| --- | --- |
+| `@earendil-works/[email protected]` | `a2c96619d0f9a1d643a6c6a555ba6a7fb533147336c181f7d3b7f847be33a6eb` |
+| `@earendil-works/[email protected]` | `9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd` |
+| `@earendil-works/[email protected]` | `a2878f6aa1d66afa239d6be4252403a73df48b702b3e582aaae04bd90bf3d354` |
+
+The `check:pi-dependencies` and `check:pi-patches` scripts verify exact direct
+pins, installed package versions, patch mappings and lockfile identities, and
+representative patched source and declaration contracts.
+
+## Validation
+
+- Task candidate base: `origin/main` at `727e0b3a9932b8a5e8c9d75498e9372e642642f8`.
+- `pnpm check:pi-dependencies`, `pnpm check:pi-patches`, and
+ `node --test scripts/pi-patch-hash.test.mjs` passed.
+- `pnpm --filter @pi-desktop/agent-runtime test` passed (94 files, 1,308
+ tests); desktop typecheck, `pnpm lint`, and `pnpm build:js` passed.
+- `pnpm test:e2e` passed 23/23 protocol smoke checks. The two live-model
+ checks were skipped because no API key was set; the test endpoint was pointed
+ at localhost to prevent outbound model requests.
+- PR integration candidate validation is still pending.
+
+## Rollback
+
+Rollback the dependency manifests, lockfile, release-age entries, patch files,
+and version references together. Do not roll back an individual patched Pi
+package while retaining the others at 1.1.0.
diff --git a/docs/project/unreleased.md b/docs/project/unreleased.md
index d8c3950fa..fc2088d4f 100644
--- a/docs/project/unreleased.md
+++ b/docs/project/unreleased.md
@@ -3,3 +3,6 @@
- Plugins can query supported fetch redirect modes and explicitly refuse or
inspect redirects without following them. Existing calls keep following by
default; a local-only probe plugin demonstrates the new API.
+- Use Pi 1.1.0's 3.5-character text estimate for compaction limits and its
+ monotonic request duration for completed-response throughput; interrupted
+ streams keep the existing fallback.
diff --git a/docs/spec/02-architecture/02-tech-stack.md b/docs/spec/02-architecture/02-tech-stack.md
index d42d50ae8..12ccdd193 100644
--- a/docs/spec/02-architecture/02-tech-stack.md
+++ b/docs/spec/02-architecture/02-tech-stack.md
@@ -12,9 +12,9 @@
| Host backend | **Rust** | stable Rust toolchain | tools/plugins/permissions/persistence adapters |
| Rust async | tokio | stable | host services |
| Host RPC | stdio JSON-RPC (NDJSON) | frozen (D001) | Electron main ↔ Rust host |
-| Agent engine | `@earendil-works/pi-agent-core` | 1.0.1 | agent loop |
-| Model API | `@earendil-works/pi-ai` | 1.0.1 | provider adapters, OAuth, and stream handling |
-| Model catalog | pi-ai Providers/Models | pinned 1.0.1 + explicit provider refresh | account-scoped metadata and typed operations |
+| Agent engine | `@earendil-works/pi-agent-core` | 1.1.0 | agent loop |
+| Model API | `@earendil-works/pi-ai` | 1.1.0 | provider adapters, OAuth, and stream handling |
+| Model catalog | pi-ai Providers/Models | pinned 1.1.0 + explicit provider refresh | account-scoped metadata and typed operations |
> pi-ai owns published metadata, native thinking support, transports and auth.
> Host persists Desktop account rows, credentials, and explicit binding overrides.
diff --git a/docs/spec/02-architecture/06-pi-runtime-dependency-boundary.md b/docs/spec/02-architecture/06-pi-runtime-dependency-boundary.md
index 15c2d8958..f91008399 100644
--- a/docs/spec/02-architecture/06-pi-runtime-dependency-boundary.md
+++ b/docs/spec/02-architecture/06-pi-runtime-dependency-boundary.md
@@ -9,10 +9,10 @@ boundaries must keep that split clear as upstream packages evolve.
## 2. Current ownership
The sidecar pins `@earendil-works/pi-agent-core`, `pi-ai`, and
-`pi-coding-agent` together at exactly `1.0.1`; Desktop's `pi-ai` and `pi-mcp`
+`pi-coding-agent` together at exactly `1.1.0`; Desktop's `pi-ai` and `pi-mcp`
development dependencies use the same release. Target-release package patches
remain narrow compatibility deltas and are listed with their audited behavior
-in `docs/project/pi-101-adoption.md`.
+in `docs/project/pi-110-adoption.md`.
- `@earendil-works/pi-agent-core` supplies the agent loop and its stable agent,
event, and tool types. Agent Runtime owns desktop-specific compaction,
@@ -31,7 +31,7 @@ in `docs/project/pi-101-adoption.md`.
host-core checkpoint-compaction path, and durable session store do not use
the package's AgentSession.
-The extension shim is a versioned compatibility subset, not the full 1.0.1
+The extension shim is a versioned compatibility subset, not the full 1.1.0
coding-agent API. Its legacy `VERSION` marker remains sourced from
`TRUSTED_EXTENSION_KERNEL_VERSION` and intentionally identifies the modeled
0.87.1 extension surface.
diff --git a/docs/spec/03-runtime/01-ipc-protocol.md b/docs/spec/03-runtime/01-ipc-protocol.md
index 36cb4376e..b5b90f435 100644
--- a/docs/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/spec/03-runtime/01-ipc-protocol.md
@@ -1164,8 +1164,10 @@ assistant message before `message_end`. Error messages persist with the
transcript but are excluded from restored model context.
The context inspector consumes two additive usage signals. `MessageUsage` is
-the provider-reported assistant usage and `responseDurationMs` is the elapsed
-sidecar stream time used to display output tokens per second. `ToolTokenUsage`
+the provider-reported assistant usage and `responseDurationMs` is the
+elapsed request duration used to display output tokens per second. Completed
+responses use pi-ai 1.1.0's monotonic `AssistantMessage.durationMs`; when
+that value is unavailable, the sidecar stopwatch remains the fallback. `ToolTokenUsage`
is a runtime estimate from the tool call arguments and result; providers do not
report per-tool allocation, so the renderer labels these rows as estimates and
never merges them into the exact provider total. Older peers may omit all of
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.md
index b0139a09d..0ffa964ba 100644
--- a/docs/spec/03-runtime/02-agent-runtime.md
+++ b/docs/spec/03-runtime/02-agent-runtime.md
@@ -529,7 +529,9 @@ rejects. None of these values are configurable.
**Estimate calibration (D606).** Every threshold above is compared against one
number, corrected against observed request usage. The runtime estimator anchors
on the last assistant usage and delegates provider-message estimation to
-pi-ai; desktop-only rows use the existing character heuristic. With no usage
+pi-ai, whose 1.1.0 text estimate is 3.5 characters per token; text truncation
+converts token budgets with the same ratio. Desktop-only rows keep the existing
+character heuristic. With no usage
anchor, the budget also computes the output-cap estimator
over non-system conversation messages plus the current system prompt and active
tool schemas. System-transcript rows are chronological updates, already covered by that
@@ -1689,7 +1691,7 @@ with the original v3 `SessionManager`, Pi `ModelRuntime`, `SettingsManager`, and
leaf, compaction, model/thinking changes, and context-bearing custom messages;
it is never reconstructed from renderer `UiMessage` rows.
-The Pi 1.0.1 SDK also applies append-only `context_edit` entries to this model
+The Pi 1.1.0 SDK also applies append-only `context_edit` entries to this model
projection. An edit can omit or replace an earlier message for later provider
requests without rewriting its raw JSONL entry or the visible native history.
Native Pi extensions use the SDK's boundary hooks; all entries they append,
@@ -1759,7 +1761,7 @@ and never triggers a provider transport rebuild. Protocol errors such as
`EPROTO` keep their existing retry behavior. See
[certificate trust ADR](../../adr/provider-system-certificates.md).
-## Pi 1.0.1 execution boundary
+## Pi 1.1.0 execution boundary
Published model metadata and account entitlement come from one account-scoped
Pi Models collection. Effective binding projection is shared by launch, delegates
diff --git a/docs/spec/03-runtime/09-logging-and-observability.md b/docs/spec/03-runtime/09-logging-and-observability.md
index 19dafbeda..6e0743242 100644
--- a/docs/spec/03-runtime/09-logging-and-observability.md
+++ b/docs/spec/03-runtime/09-logging-and-observability.md
@@ -206,7 +206,9 @@ Renderer, Electron, host, and agent should propagate these identifiers.
The application still preserves bounded duration metadata needed by product
features: `ToolsExecuteResult.duration_ms`, transcript `toolDurationMs` and
`responseDurationMs`, delegation start/completion timestamps, and bounded
-provider diagnostics. These values support the transcript, context inspector,
+provider diagnostics. Completed assistant responses use pi-ai 1.1.0's
+monotonic request duration when available; interrupted responses retain the
+sidecar stopwatch estimate. These values support the transcript, context inspector,
throughput display, and audit records; they do not create timing log lines.
Host-core audit rows may retain the existing permission and execution timing
diff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.md
index 28db42871..188a6ed96 100644
--- a/docs/spec/03-runtime/11-provider-model-system.md
+++ b/docs/spec/03-runtime/11-provider-model-system.md
@@ -476,7 +476,7 @@ same vendor key.
### Anthropic token endpoint rate limits
-The pinned pi-ai 1.0.1 patch gives Anthropic authorization-code exchange and
+The pinned pi-ai 1.1.0 patch gives Anthropic authorization-code exchange and
refresh a shared, bounded token-request policy: retry only an explicit HTTP
429, at most three total requests. Wait at least 1 s then 2 s, or longer when
`Retry-After` gives delta seconds or an HTTP date. A server delay beyond the
diff --git a/docs/spec/03-runtime/21-image-generation.md b/docs/spec/03-runtime/21-image-generation.md
index ece281f52..bddedcd0d 100644
--- a/docs/spec/03-runtime/21-image-generation.md
+++ b/docs/spec/03-runtime/21-image-generation.md
@@ -128,7 +128,7 @@ previews, editing a generated file, collapsed results, and setup navigation.
Live verification is opt-in via `scripts/test-image-generation-live.mjs`, limited
to one generation plus one edit and never a default test command.
-## Pi 1.0.1 operation boundary
+## Pi 1.1.0 operation boundary
Image generation and edits execute through account-scoped Pi `Models.generateImages`.
Use native OpenRouter images or a registered compatible OpenAI-images adapter,
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index b8114ba81..5c0e707f1 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -3488,7 +3488,7 @@ window; opening a normal panel afterward must still work.
#### E2E-MCP-pi-client-owner-policy: Pi protocol under existing Desktop owners
-- **Preconditions**: Pi 1.0.1 with the pinned host-policy patch; offline stdio and
+- **Preconditions**: Pi 1.1.0 with the pinned host-policy patch; offline stdio and
HTTP fixtures, no paid provider or user credentials.
- **Steps**: Run `plugin-mcp.test.mjs`, `user-mcp.test.mjs`,
`mcp-stdio-launch.test.mjs`, `mcp-call-registry.test.mjs`, `mcp-oauth.test.mjs`,
@@ -8725,6 +8725,8 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
- Stopped throughput is present before and after reload. It uses exact output
usage when the provider supplied it; otherwise the UI labels the persisted
four-code-point estimate as approximate.
+ - Completed-response throughput uses pi-ai 1.1.0's monotonic request duration;
+ stopped partial responses retain the sidecar duration fallback.
- **Specs linked**: `03-runtime/01-ipc-protocol.md`,
`03-runtime/02-agent-runtime.md` §5b/§9,
`04-ux/07-ui-design-system.md` §8.2–8.3,
@@ -16853,7 +16855,7 @@ renderer's durable transcript reads. No real model or provider is contacted.
## E2E-OAUTH-pi-installation-identity-and-standalone-load
-- **Preconditions**: Pi 1.0.1; temporary Host secrets and account fixtures;
+- **Preconditions**: Pi 1.1.0; temporary Host secrets and account fixtures;
network/browser/callback I/O mocked; no user account or paid service.
- **Steps**: Run `installation-identity.test.mjs`, `vendor-oauth-login.test.mjs`
and `oauth-standalone-bundle.test.mjs` under `apps/desktop/test`.
diff --git a/docs/zh-CN/spec/02-architecture/02-tech-stack.md b/docs/zh-CN/spec/02-architecture/02-tech-stack.md
index 4560bb50f..f140bf20f 100644
--- a/docs/zh-CN/spec/02-architecture/02-tech-stack.md
+++ b/docs/zh-CN/spec/02-architecture/02-tech-stack.md
@@ -15,9 +15,9 @@
| 主机后端 | **Rust** | 稳定的 Rust 工具链 | tools/plugins/permissions/persistence 适配器 |
| Rust 异步 | 东京 | 稳定 | 主机服务 |
| 主机 RPC | stdio JSON-RPC (NDJSON) | 冷冻(D001) | Electron 主 ↔ Rust 主机 |
-| Agent 引擎 | `@earendil-works/pi-agent-core` | 1.0.1 | Agent 循环及稳定的 agent/event/tool 类型 |
-| 模型 API | `@earendil-works/pi-ai` | 1.0.1 | 提供商 |
-| Model catalog | pi-ai Providers/Models | pinned 1.0.1 + explicit provider refresh | account-scoped metadata and typed operations |
+| Agent 引擎 | `@earendil-works/pi-agent-core` | 1.1.0 | Agent 循环及稳定的 agent/event/tool 类型 |
+| 模型 API | `@earendil-works/pi-ai` | 1.1.0 | 提供商 |
+| Model catalog | pi-ai Providers/Models | pinned 1.1.0 + explicit provider refresh | account-scoped metadata and typed operations |
> pi-ai 提供已发布的模型元数据、原生思考能力、传输和认证。
> Host 持有 Desktop 账户行、凭据和显式绑定覆盖。
diff --git a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
index 6706af89f..f218e7c90 100644
--- a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
@@ -935,8 +935,9 @@ Electron拥有本地化并提供面向用户的分支名称;主机
转录本,但被排除在恢复的模型上下文之外。
上下文检查器消耗两个附加使用信号。 `MessageUsage` 是
-提供商报告的助理使用情况,`responseDurationMs` 是已用时间
-sidecar 用于显示每秒输出令牌的流时间。 `ToolTokenUsage`
+提供商报告的助理使用情况,`responseDurationMs` 是用于显示每秒输出令牌的
+请求耗时。完整响应优先使用 pi-ai 1.1.0 的单调时钟
+`AssistantMessage.durationMs`;没有该值时仍使用 sidecar 秒表。 `ToolTokenUsage`
是根据工具调用参数和结果估计的运行时间;提供商不
报告每个工具的分配,因此渲染器将这些行标记为估计值并
永远不会将它们合并到确切的提供商总数中。年长的同行可能会忽略所有
diff --git a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
index cc28d33bb..a67f6473f 100644
--- a/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
+++ b/docs/zh-CN/spec/03-runtime/02-agent-runtime.md
@@ -417,7 +417,7 @@ Headroom 是 16,384 个代币储备底线的最大值,模型最大输出
可配置。
**估算校准(D606)。** 上述每个阈值都对着同一个数字比较,而该数字会按请求的真实开销校正。pi 的 `estimateContextTokens`
-以最后一条助手用量为锚,其余一律按 `chars / 4` 估算:该常数会低估中文文本,且在没有锚点时完全不含系统提示与工具结构,
+以最后一条助手用量为锚,并使用 pi-ai 1.1.0 的 provider 消息估算(文本按每个 token 3.5 个字符);文本截断也按相同比例换算 token 预算。没有锚点时,估算完全不含系统提示与工具结构,
而下一次请求仍要为它们付费。两类误差分开处理——逐字符偏差以「猜测尾部」上的比例表示(与量级无关);无锚点残差只在与之
量级相当的样本(0.5×–2×)上按比例应用,否则只加上观测到的固定开销(上限 32,000 词元)。
@@ -1204,7 +1204,7 @@ System/Direct/Custom 代理路由保持不变。
provider transport 重建。`EPROTO` 等协议错误继续使用原有重试行为。详见
[证书信任 ADR](../../../adr/provider-system-certificates.md)。
-## Pi 1.0.1 execution boundary
+## Pi 1.1.0 execution boundary
Published model metadata and account entitlement come from one account-scoped
Pi Models collection. Effective binding projection is shared by launch, delegates
diff --git a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
index 4839af8c0..d4d837e4f 100644
--- a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
+++ b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
@@ -152,7 +152,8 @@ Renderer、Electron、host 和 agent 应传播这些标识符。
应用仍会保留产品功能所需的有界时长元数据:
`ToolsExecuteResult.duration_ms`、成绩单中的 `toolDurationMs` 和
`responseDurationMs`、委托任务的开始/完成时间戳,以及有界的 provider
-诊断信息。这些值用于成绩单、上下文检查器、吞吐量展示和审计记录;
+诊断信息。完整助理响应在可用时使用 pi-ai 1.1.0 的单调请求耗时;
+中断响应仍使用 sidecar 秒表估算。这些值用于成绩单、上下文检查器、吞吐量展示和审计记录;
它们不会创建 timing 日志行。
host-core 的 audit 行可以保留既有的权限和执行时长字段用于取证检查。
diff --git a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
index 4a3e19b2c..05aba2aa5 100644
--- a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
+++ b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
@@ -180,7 +180,7 @@ PI-Desktop 不得把用户永久限制在一份简短的固定模型列表上。
### 6.2 Catalog responsibilities
-1. pi-ai 1.0.1 Providers/Models own published metadata, transport, thinking
+1. pi-ai 1.1.0 Providers/Models own published metadata, transport, thinking
support and native operation types. Electron's historically named
`ModelsDevCatalog` is an account-aware adapter over this public API.
2. Startup is cache-only and disables ambient environment/file credentials.
@@ -387,7 +387,7 @@ Codex CLI 版本(`CODEX_MODELS_CLIENT_VERSION`),账户模型缺失时调
### Anthropic token 端点限流
-固定版本 pi-ai 1.0.1 的仓库补丁为 Anthropic 授权码交换与刷新提供同一套
+固定版本 pi-ai 1.1.0 的仓库补丁为 Anthropic 授权码交换与刷新提供同一套
有限策略:只重试明确的 HTTP 429,最多总共三次请求。先等待至少 1 秒、再
等待至少 2 秒;若 `Retry-After` 给出更长的秒数或 HTTP 日期,则遵守该时间。
服务器要求的等待超出剩余预算时结束本次尝试,不缩短等待后提前重试。
diff --git a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md
index 02f6c01dd..012733b60 100644
--- a/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md
+++ b/docs/zh-CN/spec/03-runtime/13-model-catalog-and-selection.md
@@ -136,7 +136,7 @@ type RecentModelRef = {
## 6. Refresh behavior
-The pinned pi-ai 1.0.1 catalog is the startup baseline. Startup reads no remote
+The pinned pi-ai 1.1.0 catalog is the startup baseline. Startup reads no remote
catalog and uses no ambient credentials. `providers.refreshModelCatalog` invokes
Pi's public refresh API; settings metadata lookups themselves are local.
diff --git a/docs/zh-CN/spec/03-runtime/21-image-generation.md b/docs/zh-CN/spec/03-runtime/21-image-generation.md
index e93a68695..c9d0df148 100644
--- a/docs/zh-CN/spec/03-runtime/21-image-generation.md
+++ b/docs/zh-CN/spec/03-runtime/21-image-generation.md
@@ -58,7 +58,7 @@
`node scripts/e2e-image-chat.mjs` 在隔离桌面中使用本地模型/图片 HTTP 夹具,覆盖相邻默认设置、Composer 提交、批量结果、引用生成文件编辑、收起详情和配置跳转。真实接口验证通过 `scripts/test-image-generation-live.mjs` 显式启用,仅限一次生成和一次编辑,不属于默认测试命令。
-## Pi 1.0.1 operation boundary
+## Pi 1.1.0 operation boundary
Image generation and edits execute through account-scoped Pi `Models.generateImages`.
Use native OpenRouter images or a registered compatible OpenAI-images adapter,
diff --git a/packages/agent-runtime/package.json b/packages/agent-runtime/package.json
index 9ca9604ec..77cfb661b 100644
--- a/packages/agent-runtime/package.json
+++ b/packages/agent-runtime/package.json
@@ -31,9 +31,9 @@
"clean": "node -e \"fs.rmSync('dist',{recursive:true,force:true});fs.rmSync('dist-bundle',{recursive:true,force:true})\""
},
"dependencies": {
- "@earendil-works/pi-agent-core": "1.0.1",
- "@earendil-works/pi-ai": "1.0.1",
- "@earendil-works/pi-coding-agent": "1.0.1",
+ "@earendil-works/pi-agent-core": "1.1.0",
+ "@earendil-works/pi-ai": "1.1.0",
+ "@earendil-works/pi-coding-agent": "1.1.0",
"@pi-desktop/shared": "workspace:*",
"jiti": "2.7.0",
"typebox": "1.3.27",
diff --git a/packages/agent-runtime/src/compaction-summary-input.test.ts b/packages/agent-runtime/src/compaction-summary-input.test.ts
index c2f14df00..4c22e388e 100644
--- a/packages/agent-runtime/src/compaction-summary-input.test.ts
+++ b/packages/agent-runtime/src/compaction-summary-input.test.ts
@@ -97,9 +97,12 @@ describe("estimateSummaryPromptTokens", () => {
it("counts the previous summary as part of the history request", () => {
const base = input([user("ask")]);
const carried = input([user("ask")], { previousSummary: "s".repeat(4_000) });
- expect(estimateSummaryPromptTokens(carried) - estimateSummaryPromptTokens(base)).toBe(
- 1_000,
+ const delta =
+ estimateSummaryPromptTokens(carried) - estimateSummaryPromptTokens(base);
+ expect(delta).toBeGreaterThanOrEqual(
+ Math.floor(4_000 / 3.5),
);
+ expect(delta).toBeLessThanOrEqual(Math.ceil(4_000 / 3.5));
});
it("uses the larger of the two requests on a split turn", () => {
diff --git a/packages/agent-runtime/src/compaction-summary-input.ts b/packages/agent-runtime/src/compaction-summary-input.ts
index 0fa5e94fb..4f68f4e10 100644
--- a/packages/agent-runtime/src/compaction-summary-input.ts
+++ b/packages/agent-runtime/src/compaction-summary-input.ts
@@ -3,7 +3,10 @@ import {
} from "@earendil-works/pi-agent-core";
import type { RetryPolicy, Usage } from "@earendil-works/pi-ai";
import { truncateMessageText } from "./agent-messages.js";
-import { estimateTokens } from "./pi-runtime-estimates.js";
+import {
+ ESTIMATED_TEXT_CHARS_PER_TOKEN,
+ estimateTokens,
+} from "./pi-runtime-estimates.js";
import { convertToLlm, serializeConversation } from "./pi-runtime-messages.js";
import type { CompactionPreparation } from "./pi-runtime-types.js";
import { DEFAULT_MAX_TOKENS } from "./provider-binding.js";
@@ -69,7 +72,6 @@ export const COMPACTION_SUMMARY_CHUNK_MARGIN = 0.9;
export const SUMMARY_CHUNK_TRUNCATION_MARKER =
"\n\n[message truncated: the summary request budget could not carry it whole]";
-
export type CompactionSummaryInput = Pick<
CompactionPreparation,
"messagesToSummarize" | "turnPrefixMessages" | "isSplitTurn" | "previousSummary"
@@ -77,8 +79,8 @@ export type CompactionSummaryInput = Pick<
/**
* Tokens the summary request(s) will carry for this input, using pi's own
- * serialization and the four-characters-per-token heuristic the rest of the
- * runtime uses. A split turn issues two requests (history, then turn prefix);
+ * serialization and text-token estimate. A split turn issues two requests
+ * (history, then turn prefix);
* the larger one is the one that has to fit.
*/
export function estimateSummaryPromptTokens(input: CompactionSummaryInput): number {
@@ -89,7 +91,9 @@ export function estimateSummaryPromptTokens(input: CompactionSummaryInput): numb
input.isSplitTurn && input.turnPrefixMessages.length > 0
? serializeConversation(convertToLlm(input.turnPrefixMessages)).length
: 0;
- return Math.ceil(Math.max(historyChars, turnPrefixChars) / 4);
+ return Math.ceil(
+ Math.max(historyChars, turnPrefixChars) / ESTIMATED_TEXT_CHARS_PER_TOKEN,
+ );
}
/**
@@ -220,7 +224,11 @@ export function planSummaryChunks(
}
current.push(
cost > budget
- ? truncateMessageText(message, budget * 4, SUMMARY_CHUNK_TRUNCATION_MARKER)
+ ? truncateMessageText(
+ message,
+ Math.floor(budget * ESTIMATED_TEXT_CHARS_PER_TOKEN),
+ SUMMARY_CHUNK_TRUNCATION_MARKER,
+ )
: message,
);
tokens += Math.min(cost, budget);
diff --git a/packages/agent-runtime/src/compaction-tail.ts b/packages/agent-runtime/src/compaction-tail.ts
index c1b8836ad..535f5b6aa 100644
--- a/packages/agent-runtime/src/compaction-tail.ts
+++ b/packages/agent-runtime/src/compaction-tail.ts
@@ -24,7 +24,10 @@
*/
import type { AgentMessage } from "@earendil-works/pi-agent-core";
-import { estimateTokens } from "./pi-runtime-estimates.js";
+import {
+ ESTIMATED_TEXT_CHARS_PER_TOKEN,
+ estimateTokens,
+} from "./pi-runtime-estimates.js";
import { isRecord, truncateMessageText } from "./agent-messages.js";
/**
@@ -62,7 +65,10 @@ export function truncateMessageToTail(
): AgentMessage {
return truncateMessageText(
message,
- Math.max(64, Math.floor(Math.max(1, maxTokens)) * 4),
+ Math.max(
+ 64,
+ Math.floor(Math.max(1, maxTokens) * ESTIMATED_TEXT_CHARS_PER_TOKEN),
+ ),
CHECKPOINT_TRUNCATION_MARKER,
);
}
diff --git a/packages/agent-runtime/src/context-budget.test.ts b/packages/agent-runtime/src/context-budget.test.ts
index 9fea7f9a0..d8f5319ea 100644
--- a/packages/agent-runtime/src/context-budget.test.ts
+++ b/packages/agent-runtime/src/context-budget.test.ts
@@ -197,7 +197,9 @@ describe("hosted search target model threading", () => {
const large = contextBudgetFor(target, [searchHistory("gpt-test", 10_100)])
.tokens;
expect(small).toBeGreaterThan(0);
- expect(large - small).toBe(2_500);
+ expect(large - small).toBe(
+ Math.ceil(10_100 / 3.5) - Math.ceil(100 / 3.5),
+ );
});
it("charges nothing for search the target model cannot replay", () => {
diff --git a/packages/agent-runtime/src/context-calibration.test.ts b/packages/agent-runtime/src/context-calibration.test.ts
index 49ea50922..672a6ad1c 100644
--- a/packages/agent-runtime/src/context-calibration.test.ts
+++ b/packages/agent-runtime/src/context-calibration.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
+import { ESTIMATED_TEXT_CHARS_PER_TOKEN } from "./pi-runtime-estimates.js";
import {
CONTEXT_CALIBRATION_ANOMALY_FREEZE,
CONTEXT_CALIBRATION_BOUNDARY_GUARD_RATIO,
@@ -209,11 +210,11 @@ describe("ContextEstimateCalibration", () => {
});
});
- // ③ Real CJK text: the chars/4 tail is the error this series exists for.
+ // ③ Real CJK text: the pi-ai text estimate is the error this series exists for.
it("corrects a real CJK tail to the measured cost", () => {
const calibration = new ContextEstimateCalibration();
const cjkChars = [...CJK_PARAGRAPH].length;
- const estimatedTail = Math.ceil(cjkChars / 4);
+ const estimatedTail = Math.ceil(cjkChars / ESTIMATED_TEXT_CHARS_PER_TOKEN);
// Measured cost of CJK text in the tokenizers this app talks to: between
// roughly 0.6 and 1.0 tokens per character.
const measuredTail = Math.round(cjkChars * 0.9);
diff --git a/packages/agent-runtime/src/context-calibration.ts b/packages/agent-runtime/src/context-calibration.ts
index d0f69e7a6..9994dec2b 100644
--- a/packages/agent-runtime/src/context-calibration.ts
+++ b/packages/agent-runtime/src/context-calibration.ts
@@ -8,11 +8,11 @@
* whose shape is:
*
* last assistant usage (real, when the transcript still carries one)
- * + ceil(chars / 4) over every message after it
+ * + pi-ai text-token estimates over every message after it
*
* Two systematic errors follow from that shape:
*
- * 1. `chars / 4` is an English-prose constant. Applied to CJK text it
+ * 1. The text-token estimate is an English-prose constant. Applied to CJK text it
* under-counts by roughly a factor of two to four, and CJK is the bulk of
* what some sessions send. ASCII fixtures never show it.
* 2. A projection with no assistant usage left — right after a compaction, or
diff --git a/packages/agent-runtime/src/delegation-history.test.ts b/packages/agent-runtime/src/delegation-history.test.ts
index d168d0771..b86c027ef 100644
--- a/packages/agent-runtime/src/delegation-history.test.ts
+++ b/packages/agent-runtime/src/delegation-history.test.ts
@@ -435,7 +435,7 @@ describe("seedDelegateMessages budget truncation (ADR 0299 §7)", () => {
bigRead("t2", BIG),
delegateAssistant("a3", "summary", "call-1"),
];
- const messages = seed(rows, 1050);
+ const messages = seed(rows, 1200);
expect(messages[0]).toMatchObject({
role: "user",
@@ -482,7 +482,7 @@ describe("seedDelegateMessages budget truncation (ADR 0299 §7)", () => {
),
).toBe(true);
expectWellFormedPairs(messages);
- expect(seededTokens(messages)).toBeLessThan(1050);
+ expect(seededTokens(messages)).toBeLessThan(1200);
});
it("drops parallel calls on one carrier as one unit", () => {
@@ -539,7 +539,7 @@ describe("seedDelegateMessages budget truncation (ADR 0299 §7)", () => {
bigRead("t1", MEDIUM),
delegateAssistant("a3", "done", "call-1"),
];
- const messages = seed(rows, 520);
+ const messages = seed(rows, 600);
// The older plain text survives while the newer tool pair goes first.
expect(
@@ -553,7 +553,7 @@ describe("seedDelegateMessages budget truncation (ADR 0299 §7)", () => {
).toBe(true);
expect(messages.some((message) => message.role === "toolResult")).toBe(false);
expectWellFormedPairs(messages);
- expect(seededTokens(messages)).toBeLessThan(520);
+ expect(seededTokens(messages)).toBeLessThan(600);
});
it("drops whole older messages once no tool pairs remain", () => {
@@ -562,7 +562,7 @@ describe("seedDelegateMessages budget truncation (ADR 0299 §7)", () => {
delegateAssistant("a2", `mid:${"b".repeat(2000)}`, "call-1"),
delegateAssistant("a3", `new:${"c".repeat(2000)}`, "call-1"),
];
- const messages = seed(rows, 1010);
+ const messages = seed(rows, 1200);
expect(messages).toHaveLength(3);
expect(messages[0]).toMatchObject({ role: "user" });
@@ -578,7 +578,7 @@ describe("seedDelegateMessages budget truncation (ADR 0299 §7)", () => {
`mid:${"b".repeat(2000)}`,
`new:${"c".repeat(2000)}`,
]);
- expect(seededTokens(messages)).toBeLessThan(1010);
+ expect(seededTokens(messages)).toBeLessThan(1200);
});
it("seeds the brief alone when nothing else fits", () => {
diff --git a/packages/agent-runtime/src/hosted-search-error-results.test.ts b/packages/agent-runtime/src/hosted-search-error-results.test.ts
index b56a3401a..ab5d8c5ff 100644
--- a/packages/agent-runtime/src/hosted-search-error-results.test.ts
+++ b/packages/agent-runtime/src/hosted-search-error-results.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
+import { ESTIMATED_TEXT_CHARS_PER_TOKEN } from "./pi-runtime-estimates.js";
import {
hostedSearchReplayProjection,
normalizeContext,
@@ -55,7 +56,7 @@ describe("typed Anthropic search error results", () => {
expect(projection).toEqual(result.wire);
const assistant = message(result);
const expectedChars = [request, result].reduce((sum, block) => sum + JSON.stringify(hostedSearchReplayProjection(block)).length, 0);
- expect(estimateMessageTokens(assistant, model)).toBe(Math.ceil(expectedChars / 4));
+ expect(estimateMessageTokens(assistant, model)).toBe(Math.ceil(expectedChars / ESTIMATED_TEXT_CHARS_PER_TOKEN));
let fetches = 0;
const events = [
{ type: "message_start", message: { id: "response-1", model: model.id, usage: { input_tokens: 1, output_tokens: 0 } } },
diff --git a/packages/agent-runtime/src/hosted-search-estimation.test.ts b/packages/agent-runtime/src/hosted-search-estimation.test.ts
index f355f188c..df292a17e 100644
--- a/packages/agent-runtime/src/hosted-search-estimation.test.ts
+++ b/packages/agent-runtime/src/hosted-search-estimation.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
+import { ESTIMATED_TEXT_CHARS_PER_TOKEN } from "./pi-runtime-estimates.js";
import type { AssistantMessage, Model, Api } from "@earendil-works/pi-ai";
import { estimateContextTokens, estimateMessageTokens } from "@earendil-works/pi-ai/utils/estimate";
import { convertResponsesMessages } from "@earendil-works/pi-ai/api/openai-responses-shared";
@@ -52,9 +53,9 @@ async function run(api: typeof apis[number], content: unknown[], options: Record
describe("real dependency hosted-search estimation and requests", () => {
it("preserves text/thinking/tool/image numeric baselines", () => {
const message = assistant([{ type: "text", text: "12345678" }, { type: "thinking", thinking: "1234" }, { type: "toolCall", id: "t", name: "run", arguments: { a: 1 } }]);
- expect(estimateMessageTokens(message)).toBe(6);
- expect(compaction.estimateTokens(message)).toBe(6);
- expect(estimateMessageTokens({ role: "user", content: [{ type: "image", data: "", mimeType: "image/png" }], timestamp: 1 })).toBe(1200);
+ expect(estimateMessageTokens(message)).toBe(7);
+ expect(compaction.estimateTokens(message)).toBe(7);
+ expect(estimateMessageTokens({ role: "user", content: [{ type: "image", data: "", mimeType: "image/png" }], timestamp: 1 })).toBe(Math.ceil(4_800 / ESTIMATED_TEXT_CHARS_PER_TOKEN));
expect(compaction.estimateTokens({ role: "custom", content: "12345" })).toBe(2);
expect(compaction.estimateTokens({ role: "bashExecution", command: "1234", output: "5678" })).toBe(2);
expect(compaction.estimateTokens({ role: "branchSummary", summary: "12345" })).toBe(2);
@@ -162,7 +163,7 @@ describe("real dependency hosted-search estimation and requests", () => {
expect(same).toHaveLength(1);
expect(other).toHaveLength(0);
expect(estimateMessageTokens(msg, { ...model("openai-responses"), id: "other" })).toBe(0);
- expect(estimateMessageTokens(msg)).toBe(Math.ceil(JSON.stringify(same[0]).length / 4));
+ expect(estimateMessageTokens(msg)).toBe(Math.ceil(JSON.stringify(same[0]).length / ESTIMATED_TEXT_CHARS_PER_TOKEN));
const decorated = { ...(content[0] as object), query: "ignored".repeat(1000), results: [{ url: "ignored".repeat(1000) }] };
expect(estimateMessageTokens(assistant([decorated]))).toBe(estimateMessageTokens(msg));
});
@@ -177,7 +178,7 @@ describe("real dependency hosted-search estimation and requests", () => {
expect(same[0]).toMatchObject({ type: "web_search_call", id: "ws_1" });
expect(other).toHaveLength(0);
expect(estimateMessageTokens(msg, { ...model(api), id: "other" })).toBe(0);
- expect(estimateMessageTokens(msg)).toBe(Math.ceil(JSON.stringify(same[0]).length / 4));
+ expect(estimateMessageTokens(msg)).toBe(Math.ceil(JSON.stringify(same[0]).length / ESTIMATED_TEXT_CHARS_PER_TOKEN));
});
it("declares search content and events without fake name/arguments", () => {
const block: HostedSearchContent = { type: "hostedSearch", phase: "web_search_call", blockId: "legacy" };
@@ -186,7 +187,7 @@ describe("real dependency hosted-search estimation and requests", () => {
expect(event.partial.content[0]).not.toHaveProperty("arguments");
const replay = convertResponsesMessages(model("openai-responses"), normalizeContext({ messages: [assistant([block])] }), new Set());
expect(replay).toEqual([{ type: "web_search_call", id: "legacy", status: "completed" }]);
- expect(estimateMessageTokens(assistant([block]))).toBe(Math.ceil(JSON.stringify(replay[0]).length / 4));
+ expect(estimateMessageTokens(assistant([block]))).toBe(Math.ceil(JSON.stringify(replay[0]).length / ESTIMATED_TEXT_CHARS_PER_TOKEN));
});
it("matches Anthropic replay estimates across models and search toggles", async () => {
const adapter = await import("@earendil-works/pi-ai/api/anthropic-messages");
@@ -201,7 +202,7 @@ describe("real dependency hosted-search estimation and requests", () => {
}).result();
const blocks = body?.messages.find(m => m.role === "assistant")?.content ?? [];
expect(blocks).toHaveLength(2);
- expect(estimateMessageTokens(msg)).toBe(Math.ceil(blocks.reduce<number>((sum, block) => sum + JSON.stringify(block).length, 0) / 4));
+ expect(estimateMessageTokens(msg)).toBe(Math.ceil(blocks.reduce<number>((sum, block) => sum + JSON.stringify(block).length, 0) / ESTIMATED_TEXT_CHARS_PER_TOKEN));
expect(body?.tools?.some(tool => tool.type.startsWith("web_search")) ?? false).toBe(webSearch);
}
});
diff --git a/packages/agent-runtime/src/pi-ai-provider-sync.test.ts b/packages/agent-runtime/src/pi-ai-provider-sync.test.ts
index fca62a0ef..0e2b90d7d 100644
--- a/packages/agent-runtime/src/pi-ai-provider-sync.test.ts
+++ b/packages/agent-runtime/src/pi-ai-provider-sync.test.ts
@@ -9,7 +9,7 @@ import { describe, expect, it } from "vitest";
const UNSUPPORTED: Record<string, string> = {
"amazon-bedrock":
"requires SigV4 request signing plus a region, not a base URL and API key",
- "azure-openai-responses":
+ azure:
"requires a per-resource endpoint and a deployment id",
"cloudflare-ai-gateway": "the base URL embeds the account and gateway id",
"cloudflare-workers-ai": "the base URL embeds the account id",
diff --git a/packages/agent-runtime/src/pi-runtime-estimates.ts b/packages/agent-runtime/src/pi-runtime-estimates.ts
index f43cd897d..0266e38ec 100644
--- a/packages/agent-runtime/src/pi-runtime-estimates.ts
+++ b/packages/agent-runtime/src/pi-runtime-estimates.ts
@@ -8,6 +8,9 @@ import { LocalRequestError } from "@earendil-works/pi-ai";
import { validateHostedSearchMessages } from "@earendil-works/pi-ai/utils/hosted-search";
import type { Api, Message, Model } from "@earendil-works/pi-ai";
+/** Keep character caps aligned with pi-ai 1.1.0's text-token estimator. */
+export const ESTIMATED_TEXT_CHARS_PER_TOKEN = 3.5;
+
export type ContextUsageEstimate = {
tokens: number;
usageTokens: number;
diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.ts
index 4dc5dc350..55a678610 100644
--- a/packages/agent-runtime/src/runtime.test.ts
+++ b/packages/agent-runtime/src/runtime.test.ts
@@ -221,6 +221,7 @@ function runtimeTool(runtime: DesktopAgentRuntime, name: string): AgentTool {
function assistantMessage(overrides: {
content: unknown[];
stopReason?: string;
+ durationMs?: number;
}) {
return {
role: "assistant",
@@ -237,6 +238,7 @@ function assistantMessage(overrides: {
},
stopReason: overrides.stopReason ?? "stop",
timestamp: 2,
+ ...(overrides.durationMs !== undefined ? { durationMs: overrides.durationMs } : {}),
content: overrides.content,
};
}
@@ -5614,6 +5616,85 @@ describe("DesktopAgentRuntime assistant thinking events", () => {
});
});
+describe("DesktopAgentRuntime response duration", () => {
+ const fallbackDurations = [
+ { label: "missing", durationMs: undefined },
+ { label: "zero", durationMs: 0 },
+ { label: "non-finite", durationMs: Number.NaN },
+ { label: "negative", durationMs: -1 },
+ ] as const;
+
+ it("uses pi-ai's monotonic duration for a completed response", async () => {
+ const onEvent = vi.fn();
+ const runtime = createRuntime({ onEvent });
+ const internals = runtime as unknown as {
+ handleAgentEvent(event: unknown): Promise<void>;
+ streamStartedAt: number | undefined;
+ };
+
+ await internals.handleAgentEvent({
+ type: "message_start",
+ message: { role: "assistant", content: [] },
+ });
+ // Make the local fallback visibly different from Pi's request duration.
+ internals.streamStartedAt = Date.now() - 2_000;
+ await internals.handleAgentEvent({
+ type: "message_end",
+ message: assistantMessage({
+ content: [{ type: "text", text: "answer" }],
+ durationMs: 47,
+ }),
+ });
+
+ expect(onEvent).toHaveBeenCalledWith(
+ expect.objectContaining({
+ event: expect.objectContaining({
+ type: "message_end",
+ message: expect.objectContaining({ responseDurationMs: 47 }),
+ }),
+ }),
+ );
+ await runtime.dispose();
+ });
+
+ it.each(fallbackDurations)(
+ "falls back to the sidecar stopwatch for a $label Pi duration",
+ async ({ durationMs }) => {
+ const onEvent = vi.fn();
+ const runtime = createRuntime({ onEvent });
+ const internals = runtime as unknown as {
+ handleAgentEvent(event: unknown): Promise<void>;
+ streamStartedAt: number | undefined;
+ };
+
+ await internals.handleAgentEvent({
+ type: "message_start",
+ message: { role: "assistant", content: [] },
+ });
+ internals.streamStartedAt = Date.now() - 2_000;
+ await internals.handleAgentEvent({
+ type: "message_end",
+ message: assistantMessage({
+ content: [{ type: "text", text: "answer" }],
+ ...(durationMs !== undefined ? { durationMs } : {}),
+ }),
+ });
+
+ type Envelope = {
+ event?: {
+ type?: string;
+ message?: { responseDurationMs?: number };
+ };
+ };
+ const terminal = onEvent.mock.calls
+ .map(([envelope]) => envelope as Envelope)
+ .find(({ event }) => event?.type === "message_end");
+ expect(terminal?.event?.message?.responseDurationMs).toBeGreaterThanOrEqual(2_000);
+ await runtime.dispose();
+ },
+ );
+});
+
describe("DesktopAgentRuntime compaction restore", () => {
it("restores summary plus retained tail while keeping the full transcript", async () => {
const retained = { role: "user" as const, content: "recent", timestamp: 2 };
@@ -10214,7 +10295,7 @@ describe("context estimate calibration", () => {
expect(initialBudget).toBeGreaterThan(raw);
// Two unanchored reports, each costing three times the estimate: CJK text
- // against the estimator's `chars / 4` constant. Below the sample threshold
+ // against pi-ai's 3.5-characters-per-token estimate. Below the sample threshold
// the gate has to stay exactly where it was.
for (let i = 0; i < 2; i++) {
(runtime as any).inFlightContextEstimate = {
diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.ts
index 742216fbc..6a824e70b 100644
--- a/packages/agent-runtime/src/runtime.ts
+++ b/packages/agent-runtime/src/runtime.ts
@@ -140,6 +140,7 @@ import { buildSessionContext } from "./session-context.js";
import { prepareCompaction } from "./pi-runtime-compaction-plan.js";
import { compact } from "./pi-runtime-compaction-summary.js";
import {
+ ESTIMATED_TEXT_CHARS_PER_TOKEN,
estimateContextTokens,
estimateTokens,
} from "./pi-runtime-estimates.js";
@@ -1470,7 +1471,7 @@ function truncateUserMessageForCheckpoint(
...message,
content: truncateTextForCheckpoint(
userMessageTextForCheckpoint(message),
- Math.max(1, tokenBudget) * 4,
+ Math.max(1, Math.floor(tokenBudget * ESTIMATED_TEXT_CHARS_PER_TOKEN)),
),
};
}
@@ -8070,10 +8071,17 @@ Do not invent objections or turn speculative risks into blockers. Stop when the
this.streamStartedAt = undefined;
break;
}
+ // Pi 1.1.0 measures from request start with a monotonic clock. Keep the
+ // sidecar stopwatch for stopped and older streams that have no final message.
+ const piDurationMs = event.message.durationMs;
const responseDurationMs =
- this.streamStartedAt !== undefined
- ? Math.max(0, endedAt - this.streamStartedAt)
- : undefined;
+ typeof piDurationMs === "number" &&
+ Number.isFinite(piDurationMs) &&
+ piDurationMs > 0
+ ? piDurationMs
+ : this.streamStartedAt !== undefined
+ ? Math.max(0, endedAt - this.streamStartedAt)
+ : undefined;
const responseOutputTokens =
aborted && (!usage || usage.outputTokens <= 0)
? estimateVisibleResponseOutputTokens({
diff --git a/packages/agent-runtime/src/subagent-context.test.ts b/packages/agent-runtime/src/subagent-context.test.ts
index 0e51803f9..5bd13decd 100644
--- a/packages/agent-runtime/src/subagent-context.test.ts
+++ b/packages/agent-runtime/src/subagent-context.test.ts
@@ -215,7 +215,7 @@ describe("prepareDelegateTurnContext", () => {
const messages: AgentMessage[] = [
userMessage(taskBrief),
assistantToolCall("soft-trigger"),
- toolResult("x".repeat(7_500), "soft-trigger"),
+ toolResult("x".repeat(7_000), "soft-trigger"),
];
const budget = contextBudgetFor(smallModel(), messages);
const { factory, prompts } = summaryModels(() => summarySuccess("SUMMARY TEXT"));
diff --git a/packages/agent-runtime/src/subagent-context.ts b/packages/agent-runtime/src/subagent-context.ts
index 2bb801697..a26c1fb68 100644
--- a/packages/agent-runtime/src/subagent-context.ts
+++ b/packages/agent-runtime/src/subagent-context.ts
@@ -50,6 +50,7 @@ import { generateSummaryWithUsage } from "./pi-runtime-compaction-summary.js";
import { createCompactionSummaryMessage, type CompactionSummaryMessage } from "./pi-runtime-messages.js";
import type { CompactionSettings, Entry, MessageEntry } from "./pi-runtime-types.js";
import type { UsageObserver } from "./request-usage.js";
+import { ESTIMATED_TEXT_CHARS_PER_TOKEN } from "./pi-runtime-estimates.js";
import { withCompactionRequestHeaders } from "./compaction-request.js";
import {
DEFAULT_MAX_TOKENS,
@@ -448,7 +449,10 @@ function truncateDelegateUserMessage(
tokenBudget: number,
): UserMessage {
const text = delegateUserMessageText(message);
- const maxChars = Math.max(1, tokenBudget) * 4;
+ const maxChars = Math.max(
+ 1,
+ Math.floor(tokenBudget * ESTIMATED_TEXT_CHARS_PER_TOKEN),
+ );
if (text.length <= maxChars) return message;
if (maxChars <= DELEGATE_RETENTION_TRUNCATION_MARKER.length) {
return {
diff --git a/packages/agent-runtime/src/thinking-level.test.ts b/packages/agent-runtime/src/thinking-level.test.ts
index 220cf042a..50a0d0881 100644
--- a/packages/agent-runtime/src/thinking-level.test.ts
+++ b/packages/agent-runtime/src/thinking-level.test.ts
@@ -6,7 +6,7 @@ import { agentThinkingLevel, clampThinkingLevel, omitThinkingModel, requestThink
describe("simple request thinking normalization", () => {
const providers = builtinProviders();
- for (const providerId of ["openai", "azure-openai-responses", "openai-codex"]) {
+ for (const providerId of ["openai", "azure", "openai-codex"]) {
it(`normalizes unsupported off using the published ${providerId} model`, () => {
const model = providers.find((provider) => provider.id === providerId)
?.getModels().find((entry) => entry.id === "gpt-6.1-sol");
diff --git a/patches/@[email protected] b/patches/@[email protected]
similarity index 91%
rename from patches/@[email protected]
rename to patches/@[email protected]
index d91895778..9036edeea 100644
--- a/patches/@[email protected]
+++ b/patches/@[email protected]
@@ -1,5 +1,5 @@
diff --git a/dist/agent-loop.js b/dist/agent-loop.js
-index edcfba73a4e8f548f19a17bdaf8982bd528c76bd..4374aa013b252013eca1bb9066cb1935ed3ca59c 100644
+index 77af960..b2faa02 100644
--- a/dist/agent-loop.js
+++ b/dist/agent-loop.js
@@ -294,6 +294,12 @@ async function streamAssistantResponse(context, config, signal, emit, streamFunc
@@ -16,7 +16,7 @@ index edcfba73a4e8f548f19a17bdaf8982bd528c76bd..4374aa013b252013eca1bb9066cb1935
partialMessage = event.partial;
context.messages[context.messages.length - 1] = partialMessage;
diff --git a/dist/agent.js b/dist/agent.js
-index a8ccfc0bd9bd84895b5f158c9dfa328e65f200ca..0f98e4736f7bbf4fed2c53a5596cda2f03fe0a26 100644
+index a8ccfc0..0f98e47 100644
--- a/dist/agent.js
+++ b/dist/agent.js
@@ -1,3 +1,4 @@
diff --git a/patches/@[email protected] b/patches/@[email protected]
similarity index 91%
rename from patches/@[email protected]
rename to patches/@[email protected]
index 62c0b05c3..d15666eaf 100644
--- a/patches/@[email protected]
+++ b/patches/@[email protected]
@@ -1,5 +1,5 @@
diff --git a/dist/api/anthropic-messages.js b/dist/api/anthropic-messages.js
-index 38571b31e143e913c2bf59dad73382982e93664a..27867e896c0ba13b843baddc6d2a4b87e5c8e4ab 100644
+index 38571b3..27867e8 100644
--- a/dist/api/anthropic-messages.js
+++ b/dist/api/anthropic-messages.js
@@ -1,3 +1,6 @@
@@ -238,7 +238,7 @@ index 38571b31e143e913c2bf59dad73382982e93664a..27867e896c0ba13b843baddc6d2a4b87
if (blocks.length === 0)
continue;
diff --git a/dist/api/azure-openai-responses.js b/dist/api/azure-openai-responses.js
-index dc2d8f9be2f47dc73dde758c630fe12dd7749d5d..e43cc048c4bb6fcb7c3a82d27d14843cd1819ffd 100644
+index 4615b1e..66929ee 100644
--- a/dist/api/azure-openai-responses.js
+++ b/dist/api/azure-openai-responses.js
@@ -1,3 +1,5 @@
@@ -247,7 +247,7 @@ index dc2d8f9be2f47dc73dde758c630fe12dd7749d5d..e43cc048c4bb6fcb7c3a82d27d14843c
import { AzureOpenAI } from "openai";
import { clampThinkingLevel } from "../models.js";
import { formatProviderError, normalizeProviderError } from "../utils/error-body.js";
-@@ -45,10 +47,8 @@ function formatAzureOpenAIError(error) {
+@@ -22,10 +24,8 @@ function formatAzureOpenAIError(error) {
*/
export const stream = (model, context, options) => {
const stream = new AssistantMessageEventStream();
@@ -258,7 +258,7 @@ index dc2d8f9be2f47dc73dde758c630fe12dd7749d5d..e43cc048c4bb6fcb7c3a82d27d14843c
const output = {
role: "assistant",
content: [],
-@@ -66,7 +66,10 @@ export const stream = (model, context, options) => {
+@@ -43,7 +43,10 @@ export const stream = (model, context, options) => {
stopReason: "pending",
timestamp: Date.now(),
};
@@ -269,7 +269,7 @@ index dc2d8f9be2f47dc73dde758c630fe12dd7749d5d..e43cc048c4bb6fcb7c3a82d27d14843c
// Create Azure OpenAI client
const apiKey = options?.apiKey;
if (!apiKey) {
-@@ -84,6 +87,8 @@ export const stream = (model, context, options) => {
+@@ -61,6 +64,8 @@ export const stream = (model, context, options) => {
...(options?.timeoutMs !== undefined ? { timeout: options.timeoutMs } : {}),
maxRetries: 0,
};
@@ -278,7 +278,7 @@ index dc2d8f9be2f47dc73dde758c630fe12dd7749d5d..e43cc048c4bb6fcb7c3a82d27d14843c
const { data: openaiStream, response } = await retryProviderRequest(() => client.responses.create(params, requestOptions).withResponse(), {
maxRetries: options?.maxRetries,
maxRetryDelayMs: options?.maxRetryDelayMs,
-@@ -108,6 +113,11 @@ export const stream = (model, context, options) => {
+@@ -85,6 +90,11 @@ export const stream = (model, context, options) => {
stream.end();
}
catch (error) {
@@ -290,7 +290,7 @@ index dc2d8f9be2f47dc73dde758c630fe12dd7749d5d..e43cc048c4bb6fcb7c3a82d27d14843c
for (const block of output.content) {
delete block.index;
// Streaming scratch buffers are only used during parsing; never persist them.
-@@ -115,14 +125,14 @@ export const stream = (model, context, options) => {
+@@ -92,14 +102,14 @@ export const stream = (model, context, options) => {
delete block.customInput;
}
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
@@ -307,43 +307,39 @@ index dc2d8f9be2f47dc73dde758c630fe12dd7749d5d..e43cc048c4bb6fcb7c3a82d27d14843c
const apiKey = options?.apiKey;
if (!apiKey) {
throw new Error(`No API key for provider: ${model.provider}`);
-@@ -137,7 +147,7 @@ export const streamSimple = (model, context, options) => {
+@@ -114,7 +124,7 @@ export const streamSimple = (model, context, options) => {
...base,
reasoningEffort,
});
-};
+});
- function normalizeAzureBaseUrl(baseUrl) {
- const trimmed = baseUrl.trim().replace(/\/+$/, "");
- let url;
-@@ -238,6 +248,12 @@ function buildParams(model, context, options, deploymentName, grammarToolInputPr
- if (options?.toolChoice !== undefined) {
- params.tool_choice = options.toolChoice;
+ function createClient(model, apiKey, options) {
+ const headers = { "User-Agent": getPiUserAgent(), ...model.headers };
+ if (options?.headers) {
+@@ -163,6 +173,10 @@ function buildParams(model, context, options, deploymentName, grammarToolInputPr
+ supportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,
+ });
}
-+ // Hosted web search (PI-Desktop): same opt-in as openai-responses; the
-+ // azure adapter reuses the shared stream processor, which already knows
-+ // how to extract web_search_call items.
++ // Hosted web search (PI-Desktop): attach the server-side tool when the model record opts in.
+ if (model.webSearch === true) {
+ params.tools = [...(params.tools ?? []), { type: "web_search" }];
+ }
- if (model.reasoning) {
- if (options?.reasoningEffort || options?.reasoningSummary) {
- const effort = options?.reasoningEffort
-@@ -255,6 +271,12 @@ function buildParams(model, context, options, deploymentName, grammarToolInputPr
+ if (options?.toolChoice !== undefined) {
+ params.tool_choice = options.toolChoice;
+ }
+@@ -184,6 +198,10 @@ function buildParams(model, context, options, deploymentName, grammarToolInputPr
};
}
}
-+ // Hosted web search (PI-Desktop): sources ride the opt-in `include`
-+ // channel; merged here because the reasoning block above assigns
-+ // `params.include` outright.
++ // Hosted search sources are opt-in and share the include array with reasoning metadata.
+ if (model.webSearch === true) {
+ params.include = [...new Set([...(params.include ?? []), "web_search_call.action.sources"])];
+ }
- // Last so custom keys override the named request fields. Per-request keys override model defaults.
- Object.assign(params, model.samplingParams, options?.samplingParams);
- return params;
+ // Last so model and request sampling parameters override named request fields.
+ const samplingParams = resolveSamplingParams(model, reasoningEffort ?? "off", options?.samplingParams);
+ if (samplingParams) {
diff --git a/dist/api/mistral-conversations.js b/dist/api/mistral-conversations.js
-index fbcc5e25ee6752a9c5461b41fa8544a090a17b3f..92b07a1a107a9e0993bc9872d685279ccd921139 100644
+index 2fc3ad3..b2bd5e6 100644
--- a/dist/api/mistral-conversations.js
+++ b/dist/api/mistral-conversations.js
@@ -658,6 +658,9 @@ function toChatMessages(messages, supportsImages) {
@@ -357,7 +353,7 @@ index fbcc5e25ee6752a9c5461b41fa8544a090a17b3f..92b07a1a107a9e0993bc9872d685279c
id: block.id,
type: "function",
diff --git a/dist/api/openai-codex-responses.js b/dist/api/openai-codex-responses.js
-index 40014b3b7eacb3a8e5e43daac2cec6446e8810c2..f8b215d3aec7b5124c4f9c5fa2fe5a1f0886015d 100644
+index 6ee63ec..d8f572c 100644
--- a/dist/api/openai-codex-responses.js
+++ b/dist/api/openai-codex-responses.js
@@ -411,6 +411,12 @@ function buildRequestBody(model, context, options, cacheSessionId, grammarToolIn
@@ -374,10 +370,10 @@ index 40014b3b7eacb3a8e5e43daac2cec6446e8810c2..f8b215d3aec7b5124c4f9c5fa2fe5a1f
const effort = options.reasoningEffort === "none"
? model.thinkingLevelMap?.off === undefined
diff --git a/dist/api/openai-completions.js b/dist/api/openai-completions.js
-index eecd83c753e3b758b8e44628f560b862f8252839..2390122f72d7a6f04a9e1e93b96f885392b91d5e 100644
+index a60f393..f03916c 100644
--- a/dist/api/openai-completions.js
+++ b/dist/api/openai-completions.js
-@@ -1041,21 +1041,27 @@ export function convertMessages(model, context, compat, options) {
+@@ -1044,21 +1044,27 @@ export function convertMessages(model, context, compat, options) {
if (preservedReasoningDetails) {
assistantMsg.reasoning_details = preservedReasoningDetails;
}
@@ -411,7 +407,7 @@ index eecd83c753e3b758b8e44628f560b862f8252839..2390122f72d7a6f04a9e1e93b96f8853
}
params.push(assistantMsg);
}
-@@ -1123,6 +1129,41 @@ export function convertMessages(model, context, compat, options) {
+@@ -1126,6 +1132,41 @@ export function convertMessages(model, context, compat, options) {
}
lastRole = msg.role;
}
@@ -453,7 +449,7 @@ index eecd83c753e3b758b8e44628f560b862f8252839..2390122f72d7a6f04a9e1e93b96f8853
return params;
}
function convertTools(tools, compat) {
-@@ -1267,6 +1308,9 @@ function detectCompat(model) {
+@@ -1270,6 +1311,9 @@ function detectCompat(model) {
requiresAssistantAfterToolResult: false,
requiresThinkingAsText: false,
requiresReasoningContentOnAssistantMessages: isDeepSeek,
@@ -463,7 +459,7 @@ index eecd83c753e3b758b8e44628f560b862f8252839..2390122f72d7a6f04a9e1e93b96f8853
thinkingFormat: isDeepSeek
? "deepseek"
: isZai
-@@ -1320,6 +1364,8 @@ function getCompat(model) {
+@@ -1323,6 +1367,8 @@ function getCompat(model) {
requiresThinkingAsText: model.compat.requiresThinkingAsText ?? detected.requiresThinkingAsText,
requiresReasoningContentOnAssistantMessages: model.compat.requiresReasoningContentOnAssistantMessages ??
detected.requiresReasoningContentOnAssistantMessages,
@@ -473,7 +469,7 @@ index eecd83c753e3b758b8e44628f560b862f8252839..2390122f72d7a6f04a9e1e93b96f8853
openRouterRouting: model.compat.openRouterRouting ?? {},
vercelGatewayRouting: model.compat.vercelGatewayRouting ?? detected.vercelGatewayRouting,
diff --git a/dist/api/openai-responses-shared.js b/dist/api/openai-responses-shared.js
-index f413fe5f2a1abcac39c38bbd4a77b38c349a5918..af7832b03b722013d7fcbc01423d6b36dd8c146b 100644
+index f413fe5..af7832b 100644
--- a/dist/api/openai-responses-shared.js
+++ b/dist/api/openai-responses-shared.js
@@ -1,3 +1,4 @@
@@ -648,7 +644,7 @@ index f413fe5f2a1abcac39c38bbd4a77b38c349a5918..af7832b03b722013d7fcbc01423d6b36
else if (event.type === "error") {
throw new Error(`Error Code ${event.code}: ${event.message}` || "Unknown error");
diff --git a/dist/api/openai-responses.js b/dist/api/openai-responses.js
-index 4d58c9772b49f0d40e31d42c251a6d993a4a673f..c928c3f640a0b58941ebfc509171ec1984be56ba 100644
+index 2a6b4e4..9e44070 100644
--- a/dist/api/openai-responses.js
+++ b/dist/api/openai-responses.js
@@ -1,3 +1,5 @@
@@ -737,24 +733,22 @@ index 4d58c9772b49f0d40e31d42c251a6d993a4a673f..c928c3f640a0b58941ebfc509171ec19
if (options?.toolChoice !== undefined) {
params.tool_choice = options.toolChoice;
}
-@@ -282,6 +299,12 @@ function buildParams(model, context, options, compat = getCompat(model), grammar
+@@ -283,6 +300,10 @@ function buildParams(model, context, options, compat = getCompat(model), grammar
if (model.provider === "xai")
params.include = ["reasoning.encrypted_content"];
}
-+ // Hosted web search (PI-Desktop): sources ride the opt-in `include`
-+ // channel; merged here because the reasoning block above assigns
-+ // `params.include` outright.
++ // Hosted search sources are opt-in and share the include array with reasoning metadata.
+ if (model.webSearch === true) {
+ params.include = [...new Set([...(params.include ?? []), "web_search_call.action.sources"])];
+ }
- // Last so custom keys override the named request fields. Per-request keys override model defaults.
- Object.assign(params, model.samplingParams, options?.samplingParams);
- return params;
+ // Last so model and request sampling parameters override named request fields.
+ const samplingParams = resolveSamplingParams(model, reasoningEffort ?? "off", options?.samplingParams);
+ if (samplingParams) {
diff --git a/dist/api/simple-options.js b/dist/api/simple-options.js
-index da0fc83be3031326465b7dc1c53030a0d184517a..d56ef2ab9d76579b6b335c1083da94f1a84e8e93 100644
+index 4e36f35..c817c2e 100644
--- a/dist/api/simple-options.js
+++ b/dist/api/simple-options.js
-@@ -4,7 +4,7 @@ const MIN_MAX_TOKENS = 1;
+@@ -5,7 +5,7 @@ const MIN_MAX_TOKENS = 1;
export function clampMaxTokensToContext(model, context, maxTokens) {
if (model.contextWindow <= 0)
return Math.max(MIN_MAX_TOKENS, maxTokens);
@@ -762,12 +756,12 @@ index da0fc83be3031326465b7dc1c53030a0d184517a..d56ef2ab9d76579b6b335c1083da94f1
+ const available = model.contextWindow - estimateContextTokens(context, model).tokens - CONTEXT_SAFETY_TOKENS;
return Math.min(maxTokens, Math.max(MIN_MAX_TOKENS, available));
}
- export function buildBaseOptions(model, context, options, apiKey) {
+ export function resolveSamplingParams(model, thinkingLevel, requestParams) {
diff --git a/dist/auth/oauth/anthropic.js b/dist/auth/oauth/anthropic.js
-index e136a751e45d059b721257f829f418a601ce3243..0d35358ce444ff32278521cf2b37997ada17f9d9 100644
+index 0823512..3af4225 100644
--- a/dist/auth/oauth/anthropic.js
+++ b/dist/auth/oauth/anthropic.js
-@@ -64,21 +64,90 @@ function formatErrorDetails(error) {
+@@ -66,21 +66,90 @@ function formatErrorDetails(error) {
}
return String(error);
}
@@ -871,7 +865,7 @@ index e136a751e45d059b721257f829f418a601ce3243..0d35358ce444ff32278521cf2b37997a
}
async function exchangeAuthorizationCode(code, state, verifier, redirectUri, signal) {
let responseBody;
-@@ -93,6 +162,8 @@ async function exchangeAuthorizationCode(code, state, verifier, redirectUri, sig
+@@ -95,6 +164,8 @@ async function exchangeAuthorizationCode(code, state, verifier, redirectUri, sig
}, signal);
}
catch (error) {
@@ -880,7 +874,7 @@ index e136a751e45d059b721257f829f418a601ce3243..0d35358ce444ff32278521cf2b37997a
throw new Error(`Token exchange request failed. url=${TOKEN_URL}; redirect_uri=${redirectUri}; response_type=authorization_code; details=${formatErrorDetails(error)}`);
}
let tokenData;
-@@ -100,7 +171,7 @@ async function exchangeAuthorizationCode(code, state, verifier, redirectUri, sig
+@@ -102,7 +173,7 @@ async function exchangeAuthorizationCode(code, state, verifier, redirectUri, sig
tokenData = JSON.parse(responseBody);
}
catch (error) {
@@ -889,7 +883,7 @@ index e136a751e45d059b721257f829f418a601ce3243..0d35358ce444ff32278521cf2b37997a
}
return {
type: "oauth",
-@@ -205,6 +276,8 @@ async function refreshAnthropicToken(refreshToken, signal) {
+@@ -213,6 +284,8 @@ async function refreshAnthropicToken(refreshToken, signal) {
}, signal);
}
catch (error) {
@@ -898,7 +892,7 @@ index e136a751e45d059b721257f829f418a601ce3243..0d35358ce444ff32278521cf2b37997a
throw new Error(`Anthropic token refresh request failed. url=${TOKEN_URL}; details=${formatErrorDetails(error)}`);
}
let data;
-@@ -212,7 +285,7 @@ async function refreshAnthropicToken(refreshToken, signal) {
+@@ -220,7 +293,7 @@ async function refreshAnthropicToken(refreshToken, signal) {
data = JSON.parse(responseBody);
}
catch (error) {
@@ -908,7 +902,7 @@ index e136a751e45d059b721257f829f418a601ce3243..0d35358ce444ff32278521cf2b37997a
return {
type: "oauth",
diff --git a/dist/index.d.ts b/dist/index.d.ts
-index 75c0d7ba79dbf893724a302829011bc0f8ded282..b0bf6975cb155df67e7cad59e4c65d751f47ec8b 100644
+index 75c0d7b..b0bf697 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -33,4 +33,7 @@ export * from "./utils/transcript.ts";
@@ -921,7 +915,7 @@ index 75c0d7ba79dbf893724a302829011bc0f8ded282..b0bf6975cb155df67e7cad59e4c65d75
//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/dist/index.js b/dist/index.js
-index 4fafddad713ac5811fe2b1dfea629b4b8f6627e1..2e4ed41e548807b836625b35ba753a8422aea160 100644
+index 4fafdda..2e4ed41 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -20,4 +20,6 @@ export * from "./utils/transcript.js";
@@ -933,17 +927,17 @@ index 4fafddad713ac5811fe2b1dfea629b4b8f6627e1..2e4ed41e548807b836625b35ba753a84
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/dist/providers/data/deepseek.json b/dist/providers/data/deepseek.json
-index 1443bb592b2913ba09579f3f555a2b09456e63cf..5fc0625778014863aa267ac5186db2cdf356d789 100644
+index 1443bb5..5fc0625 100644
--- a/dist/providers/data/deepseek.json
+++ b/dist/providers/data/deepseek.json
@@ -1 +1 @@
-{"openai-completions":{"chat:deepseek-flash":{"id":"deepseek-flash","name":"DeepSeek V4.1 Flash","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"thinkingLevelMap":{"minimal":null,"low":"low","medium":null,"high":"high","max":"max"},"input":["text","image"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.006,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true},"inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:deepseek-v4-pro":{"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"input":["text"],"cost":{"input":1.32,"output":3.96,"cacheRead":0.044,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true,"supportsMidConvoSystemMessages":true},"thinkingLevelMap":{"minimal":null,"low":null,"medium":null,"high":"high","max":"max"},"type":"chat"}}}
+{"openai-completions":{"chat:deepseek-flash":{"id":"deepseek-flash","name":"DeepSeek V4.1 Flash","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"thinkingLevelMap":{"minimal":null,"low":"low","medium":null,"high":"high","max":"max"},"input":["text","image"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.006,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true,"supportsMidConvoSystemMessages":true},"inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:deepseek-v4-pro":{"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"input":["text"],"cost":{"input":1.32,"output":3.96,"cacheRead":0.044,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true,"supportsMidConvoSystemMessages":true},"thinkingLevelMap":{"minimal":null,"low":null,"medium":null,"high":"high","max":"max"},"type":"chat"}}}
diff --git a/dist/types.d.ts b/dist/types.d.ts
-index b141efdc528c806524d40f097256f7173c12ba3b..d0007a3d5b0bd0a54fee93a3a26b1af7f5ce04a9 100644
+index b01603b..39a6d0a 100644
--- a/dist/types.d.ts
+++ b/dist/types.d.ts
-@@ -286,6 +286,30 @@ export interface ToolCall {
+@@ -288,6 +288,30 @@ export interface ToolCall {
/** OpenAI Responses namespace for calls to dynamically loaded or namespaced tools. */
namespace?: string;
}
@@ -974,7 +968,7 @@ index b141efdc528c806524d40f097256f7173c12ba3b..d0007a3d5b0bd0a54fee93a3a26b1af7
export interface Usage {
input: number;
output: number;
-@@ -371,7 +395,7 @@ export interface UserMessage {
+@@ -373,7 +397,7 @@ export interface UserMessage {
}
export interface AssistantMessage {
role: "assistant";
@@ -983,7 +977,7 @@ index b141efdc528c806524d40f097256f7173c12ba3b..d0007a3d5b0bd0a54fee93a3a26b1af7
api: Api;
provider: ProviderId;
model: string;
-@@ -386,6 +410,8 @@ export interface AssistantMessage {
+@@ -388,6 +412,8 @@ export interface AssistantMessage {
stopReason: StopReason;
deferred?: DeferredHandle;
errorMessage?: string;
@@ -992,7 +986,7 @@ index b141efdc528c806524d40f097256f7173c12ba3b..d0007a3d5b0bd0a54fee93a3a26b1af7
rawStopReason?: string;
/**
* Provider indication of whether the model explicitly ended its turn.
-@@ -606,6 +632,10 @@ export type AssistantMessageEvent = {
+@@ -623,6 +649,10 @@ export type AssistantMessageEvent = {
contentIndex: number;
toolCall: ToolCall;
partial: AssistantMessage;
@@ -1003,7 +997,7 @@ index b141efdc528c806524d40f097256f7173c12ba3b..d0007a3d5b0bd0a54fee93a3a26b1af7
} | {
type: "done";
reason: Extract<StopReason, "stop" | "length" | "toolUse" | "deferred">;
-@@ -640,6 +670,12 @@ export interface OpenAICompletionsCompat {
+@@ -657,6 +687,12 @@ export interface OpenAICompletionsCompat {
requiresThinkingAsText?: boolean;
/** Whether all replayed assistant messages must include an empty reasoning_content field when reasoning is enabled. Default: auto-detected from URL. */
requiresReasoningContentOnAssistantMessages?: boolean;
@@ -1016,7 +1010,7 @@ index b141efdc528c806524d40f097256f7173c12ba3b..d0007a3d5b0bd0a54fee93a3a26b1af7
/** Format for reasoning/thinking parameter. "openai" uses reasoning_effort, "openrouter" uses reasoning: { effort }, "deepseek" uses thinking: { type } plus reasoning_effort when supported, "together" uses reasoning: { enabled } plus reasoning_effort when supported, "baseten" uses configurable chat_template_args plus reasoning_effort when supported, "zai" uses thinking: { type }, "qwen" uses top-level enable_thinking: boolean, "qwen-chat-template" uses chat_template_kwargs.enable_thinking and preserve_thinking, "chat-template" uses configurable chat_template_kwargs, "string-thinking" uses top-level thinking: string, and "ant-ling" uses reasoning: { effort } only when the mapped effort is non-null. Default: "openai". */
thinkingFormat?: "openai" | "openrouter" | "deepseek" | "together" | "baseten" | "zai" | "qwen" | "chat-template" | "qwen-chat-template" | "string-thinking" | "ant-ling";
/** Kwargs to send as `chat_template_kwargs` when `thinkingFormat` is `chat-template`. Use `{ "$var": "thinking.enabled" }`, `{ "$var": "thinking.effort" }`, or `{ "$var": "thinking.budget" }` for pi-controlled thinking values. */
-@@ -918,6 +954,8 @@ export interface Model<TApi extends Api> extends BaseModel<TApi> {
+@@ -935,6 +971,8 @@ export interface Model<TApi extends Api> extends BaseModel<TApi> {
*/
type?: "chat";
reasoning: boolean;
@@ -1026,7 +1020,7 @@ index b141efdc528c806524d40f097256f7173c12ba3b..d0007a3d5b0bd0a54fee93a3a26b1af7
* Maps pi thinking levels to provider/model-specific values.
* Missing keys use provider defaults. null marks a level as unsupported.
diff --git a/dist/utils/assistant-message-frame.d.ts b/dist/utils/assistant-message-frame.d.ts
-index 08207197acab532d0f5f596363700a2d15a687d8..0584f6898e1d842c4414869b9080505b63c3a7b7 100644
+index 0820719..0584f68 100644
--- a/dist/utils/assistant-message-frame.d.ts
+++ b/dist/utils/assistant-message-frame.d.ts
@@ -1,4 +1,4 @@
@@ -1048,7 +1042,7 @@ index 08207197acab532d0f5f596363700a2d15a687d8..0584f6898e1d842c4414869b9080505b
/**
* Encodes one assistant stream. `partial` remains a shared live accumulator;
diff --git a/dist/utils/assistant-message-frame.js b/dist/utils/assistant-message-frame.js
-index c0e00197b2bdd4c815106daa036d844c07aca800..a86f5939accd25110d7a4d1e0d268646691d321d 100644
+index c0e0019..a86f593 100644
--- a/dist/utils/assistant-message-frame.js
+++ b/dist/utils/assistant-message-frame.js
@@ -1,15 +1,30 @@
@@ -1203,7 +1197,7 @@ index c0e00197b2bdd4c815106daa036d844c07aca800..a86f5939accd25110d7a4d1e0d268646
if (frame.content.type !== "text") {
throw new Error(`text_start frame contains ${frame.content.type} content`);
diff --git a/dist/utils/estimate.d.ts b/dist/utils/estimate.d.ts
-index 6dcca6eff16b95b83e047a6e27b65d9d7694bf2c..5ccaaf2358a0afeea3ce354e5799255ae8508f3d 100644
+index 6dcca6e..5ccaaf2 100644
--- a/dist/utils/estimate.d.ts
+++ b/dist/utils/estimate.d.ts
@@ -1,4 +1,4 @@
@@ -1224,14 +1218,14 @@ index 6dcca6eff16b95b83e047a6e27b65d9d7694bf2c..5ccaaf2358a0afeea3ce354e5799255a
//# sourceMappingURL=estimate.d.ts.map
\ No newline at end of file
diff --git a/dist/utils/estimate.js b/dist/utils/estimate.js
-index d04ff22cbe8d7357404b938e228b8e3a2dbdcb1d..28564cc73798163f7590290123b7476573d5bee5 100644
+index 45be26d..59a980b 100644
--- a/dist/utils/estimate.js
+++ b/dist/utils/estimate.js
@@ -1,95 +1,114 @@
import { getSystemMessageText } from "./text.js";
+import { hostedSearchReplayProjection, validateHostedSearchMessages } from "./hosted-search.js";
+import { LocalRequestError, prepareLocalRequest } from "./local-request-error.js";
- const CHARS_PER_TOKEN = 4;
+ const CHARS_PER_TOKEN = 3.5;
const ESTIMATED_IMAGE_CHARS = 4800;
export function calculateContextTokens(usage) {
return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
@@ -1399,7 +1393,7 @@ index d04ff22cbe8d7357404b938e228b8e3a2dbdcb1d..28564cc73798163f7590290123b74765
\ No newline at end of file
diff --git a/dist/utils/hosted-search.d.ts b/dist/utils/hosted-search.d.ts
new file mode 100644
-index 0000000000000000000000000000000000000000..a76ae5269313931b8476e1f153e76792875ad54c
+index 0000000..a76ae52
--- /dev/null
+++ b/dist/utils/hosted-search.d.ts
@@ -0,0 +1,10 @@
@@ -1415,7 +1409,7 @@ index 0000000000000000000000000000000000000000..a76ae5269313931b8476e1f153e76792
+export declare function validateHostedSearchMessages(messages: readonly Message[]): void;
diff --git a/dist/utils/hosted-search.js b/dist/utils/hosted-search.js
new file mode 100644
-index 0000000000000000000000000000000000000000..b98cb8d128310273014e4490e9c26144f45b56af
+index 0000000..b98cb8d
--- /dev/null
+++ b/dist/utils/hosted-search.js
@@ -0,0 +1,97 @@
@@ -1518,7 +1512,7 @@ index 0000000000000000000000000000000000000000..b98cb8d128310273014e4490e9c26144
+}
diff --git a/dist/utils/local-request-error.d.ts b/dist/utils/local-request-error.d.ts
new file mode 100644
-index 0000000000000000000000000000000000000000..a72f65b33c64b89f118a59bd286e62624711fd90
+index 0000000..a72f65b
--- /dev/null
+++ b/dist/utils/local-request-error.d.ts
@@ -0,0 +1,15 @@
@@ -1539,7 +1533,7 @@ index 0000000000000000000000000000000000000000..a72f65b33c64b89f118a59bd286e6262
+export declare function prepareLocalRequest<T>(phase: LocalRequestErrorPhase, prepare: () => T): T;
diff --git a/dist/utils/local-request-error.js b/dist/utils/local-request-error.js
new file mode 100644
-index 0000000000000000000000000000000000000000..4d276ddc8caee98dfeeeeaa9bcd234ad63dc414b
+index 0000000..4d276dd
--- /dev/null
+++ b/dist/utils/local-request-error.js
@@ -0,0 +1,38 @@
@@ -1583,7 +1577,7 @@ index 0000000000000000000000000000000000000000..4d276ddc8caee98dfeeeeaa9bcd234ad
+}
diff --git a/dist/utils/local-request-stream.d.ts b/dist/utils/local-request-stream.d.ts
new file mode 100644
-index 0000000000000000000000000000000000000000..879b78cbecb0cc2c4322049ed2c7d61f77be9375
+index 0000000..879b78c
--- /dev/null
+++ b/dist/utils/local-request-stream.d.ts
@@ -0,0 +1,3 @@
@@ -1592,7 +1586,7 @@ index 0000000000000000000000000000000000000000..879b78cbecb0cc2c4322049ed2c7d61f
+export declare function withLocalRequestErrors(model: Model<Api>, options: { signal?: AbortSignal } | undefined, prepare: () => AssistantMessageEventStream): AssistantMessageEventStream;
diff --git a/dist/utils/local-request-stream.js b/dist/utils/local-request-stream.js
new file mode 100644
-index 0000000000000000000000000000000000000000..5c63b882ae4cb618e964c5d2ce8d3c18e0fe4688
+index 0000000..5c63b88
--- /dev/null
+++ b/dist/utils/local-request-stream.js
@@ -0,0 +1,24 @@
@@ -1620,10 +1614,3 @@ index 0000000000000000000000000000000000000000..5c63b882ae4cb618e964c5d2ce8d3c18
+ return stream;
+ }
+}
-diff --git a/dist/providers/data/deepseek.json b/dist/providers/data/deepseek.json
---- a/dist/providers/data/deepseek.json
-+++ b/dist/providers/data/deepseek.json
-@@ -1 +1 @@
--{"openai-completions":{"chat:deepseek-flash":{"id":"deepseek-flash","name":"DeepSeek V4.1 Flash","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"thinkingLevelMap":{"minimal":null,"low":"low","medium":null,"high":"high","max":"max"},"input":["text","image"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.006,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true},"inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:deepseek-v4-pro":{"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"input":["text"],"cost":{"input":1.32,"output":3.96,"cacheRead":0.044,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true,"supportsMidConvoSystemMessages":true},"thinkingLevelMap":{"minimal":null,"low":null,"medium":null,"high":"high","max":"max"},"type":"chat"}}}
-+{"openai-completions":{"chat:deepseek-flash":{"id":"deepseek-flash","name":"DeepSeek V4.1 Flash","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"thinkingLevelMap":{"minimal":null,"low":"low","medium":null,"high":"high","max":"max"},"input":["text","image"],"cost":{"input":0.3,"output":1.2,"cacheRead":0.006,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true,"supportsMidConvoSystemMessages":true},"inputLimits":{"images":{"resize":{"maxWidth":2000,"maxHeight":2000,"maxBytes":4718592,"jpegQuality":80}}},"type":"chat"},"chat:deepseek-v4-pro":{"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","api":"openai-completions","baseUrl":"https://api.deepseek.com","provider":"deepseek","reasoning":true,"input":["text"],"cost":{"input":1.32,"output":3.96,"cacheRead":0.044,"cacheWrite":0},"contextWindow":1000000,"maxTokens":384000,"compat":{"supportsStore":false,"supportsDeveloperRole":false,"maxTokensField":"max_tokens","requiresReasoningContentOnAssistantMessages":true,"thinkingFormat":"deepseek","supportsStrictMode":true,"supportsMidConvoSystemMessages":true},"thinkingLevelMap":{"minimal":null,"low":null,"medium":null,"high":"high","max":"max"},"type":"chat"}}}
-\ No newline at end of file
diff --git a/patches/@[email protected] b/patches/@[email protected]
similarity index 95%
rename from patches/@[email protected]
rename to patches/@[email protected]
index 2d2ff1bfd..bd0b8a327 100644
--- a/patches/@[email protected]
+++ b/patches/@[email protected]
@@ -1,8 +1,8 @@
diff --git a/dist/core/agent-session.js b/dist/core/agent-session.js
-index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd334c602d1 100644
+index c5ad719..63f78d1 100644
--- a/dist/core/agent-session.js
+++ b/dist/core/agent-session.js
-@@ -68,10 +68,10 @@ function withoutDeletedHeaders(headers) {
+@@ -69,10 +69,10 @@ function withoutDeletedHeaders(headers) {
? Object.fromEntries(Object.entries(headers).filter((entry) => entry[1] !== null))
: undefined;
}
@@ -15,7 +15,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
}
return tokens;
}
-@@ -406,7 +406,7 @@ export class AgentSession {
+@@ -419,7 +419,7 @@ export class AgentSession {
_exceedsCompactionThreshold(model, projection) {
if (model.contextWindow <= 0)
return false;
@@ -24,7 +24,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
}
async _compactBeforeNextAssistantResponse(context) {
const projection = this.sessionManager.buildSessionProjection();
-@@ -578,7 +578,7 @@ export class AgentSession {
+@@ -591,7 +591,7 @@ export class AgentSession {
entryId = manager.appendContextEdit(draft.targetId, draft.replacement);
break;
case "compaction": {
@@ -33,7 +33,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
entryId = manager.appendCompaction(draft.summary, draft.firstKeptEntryId, tokensBefore, draft.details, true, draft.usage);
break;
}
-@@ -2142,7 +2142,7 @@ export class AgentSession {
+@@ -2178,7 +2178,7 @@ export class AgentSession {
}
const settings = this.settingsManager.getCompactionSettings(model);
const pathEntries = this.sessionManager.getBranch();
@@ -42,7 +42,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
if (!preparation) {
// Check why we can't compact
const lastEntry = pathEntries[pathEntries.length - 1];
-@@ -2199,7 +2199,7 @@ export class AgentSession {
+@@ -2235,7 +2235,7 @@ export class AgentSession {
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
const newEntries = this.sessionManager.getEntries();
this._refreshFinalizedContext();
@@ -51,7 +51,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
// Get the saved compaction entry for the extension event
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
if (this._extensionRunner && savedCompactionEntry) {
-@@ -2382,11 +2382,11 @@ export class AgentSession {
+@@ -2418,11 +2418,11 @@ export class AgentSession {
const hasContextEdits = projection.entries.some((entry) => entry.sourceEntry.type === "context_edit");
const directContextTokens = assistantMessage.usage ? calculateContextTokens(assistantMessage.usage) : 0;
if (hasContextEdits) {
@@ -65,7 +65,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
// Without provider usage, estimate.tokens is the pure message-size estimate.
// Only usage-backed estimates need the stale pre-compaction check.
if (estimate.lastUsageIndex !== null) {
-@@ -2432,7 +2432,7 @@ export class AgentSession {
+@@ -2468,7 +2468,7 @@ export class AgentSession {
return false;
}
const pathEntries = this.sessionManager.getBranch();
@@ -74,7 +74,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
if (!preparation) {
return false;
}
-@@ -2488,7 +2488,7 @@ export class AgentSession {
+@@ -2524,7 +2524,7 @@ export class AgentSession {
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
const newEntries = this.sessionManager.getEntries();
this._refreshFinalizedContext();
@@ -83,7 +83,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
// Get the saved compaction entry for the extension event
const savedCompactionEntry = newEntries.find((e) => e.type === "compaction" && e.summary === summary);
if (this._extensionRunner && savedCompactionEntry) {
-@@ -3424,7 +3424,7 @@ export class AgentSession {
+@@ -3462,7 +3462,7 @@ export class AgentSession {
if (!hasPostCompactionUsage)
return { tokens: null, contextWindow, percent: null };
}
@@ -93,7 +93,7 @@ index 33338d518743ba2fd4ee2d710c5496a6ddcd1856..7ea30773b6d3aa2e960fe8da753e0dd3
return {
tokens: estimate.tokens,
diff --git a/dist/core/bug-report.js b/dist/core/bug-report.js
-index bc4af31b57f4a8696a68d4f2a529a26669955382..24a4f8e28624523112cac6c73464e93fb650f03a 100644
+index bc4af31..24a4f8e 100644
--- a/dist/core/bug-report.js
+++ b/dist/core/bug-report.js
@@ -232,12 +232,12 @@ Numbered list, as specific as the transcript allows.
@@ -121,7 +121,7 @@ index bc4af31b57f4a8696a68d4f2a529a26669955382..24a4f8e28624523112cac6c73464e93f
const prompt = [
messages.length < options.messages.length
diff --git a/dist/core/compaction/branch-summarization.d.ts b/dist/core/compaction/branch-summarization.d.ts
-index 12cb88ef5398b2365d5823597b7ccf063af567d6..6ff73567bbd5289b8b3f2fb82f923a5b5dc7860e 100644
+index 12cb88e..6ff7356 100644
--- a/dist/core/compaction/branch-summarization.d.ts
+++ b/dist/core/compaction/branch-summarization.d.ts
@@ -6,7 +6,7 @@
@@ -143,7 +143,7 @@ index 12cb88ef5398b2365d5823597b7ccf063af567d6..6ff73567bbd5289b8b3f2fb82f923a5b
* Generate a summary of abandoned branch entries.
*
diff --git a/dist/core/compaction/branch-summarization.js b/dist/core/compaction/branch-summarization.js
-index 3f98859ddbc6de3b6075c08557fe396a61d1814e..b68f7adb1fd2145a6a0d1e74af05065d25c7925b 100644
+index 3f98859..b68f7ad 100644
--- a/dist/core/compaction/branch-summarization.js
+++ b/dist/core/compaction/branch-summarization.js
@@ -95,7 +95,7 @@ function getMessageFromEntry(entry) {
@@ -174,7 +174,7 @@ index 3f98859ddbc6de3b6075c08557fe396a61d1814e..b68f7adb1fd2145a6a0d1e74af05065d
return { summary: "No content to summarize" };
}
diff --git a/dist/core/compaction/compaction.d.ts b/dist/core/compaction/compaction.d.ts
-index 04416da43184fce4dc2fc33afeb920e2edddedc9..fdf79d9f200e78178aa46020341c7295024734a5 100644
+index 04416da..fdf79d9 100644
--- a/dist/core/compaction/compaction.d.ts
+++ b/dist/core/compaction/compaction.d.ts
@@ -6,7 +6,7 @@
@@ -229,7 +229,7 @@ index 04416da43184fce4dc2fc33afeb920e2edddedc9..fdf79d9f200e78178aa46020341c7295
* Generate summaries for compaction using prepared data.
* Returns CompactionResult - SessionManager adds uuid/parentUuid when saving.
diff --git a/dist/core/compaction/compaction.js b/dist/core/compaction/compaction.js
-index e4992e8d2bff8aa6d2a4b044c9cf571d9e7f2fa2..0797ad50e267863a32adf27cbc2d7037e07dcb21 100644
+index e4992e8..0797ad5 100644
--- a/dist/core/compaction/compaction.js
+++ b/dist/core/compaction/compaction.js
@@ -4,8 +4,10 @@
@@ -424,7 +424,7 @@ index e4992e8d2bff8aa6d2a4b044c9cf571d9e7f2fa2..0797ad50e267863a32adf27cbc2d7037
if (!firstKeptEntry?.id)
return undefined;
diff --git a/dist/core/compaction/utils.js b/dist/core/compaction/utils.js
-index 92ee18e6a99c46dd5fc6b249a6cf670938f5f963..ef4df7671fc2a2b778ede9e485eb03fc49ebc3a8 100644
+index 92ee18e..ef4df76 100644
--- a/dist/core/compaction/utils.js
+++ b/dist/core/compaction/utils.js
@@ -2,6 +2,7 @@
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8556b102f..38cc74d8c 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -199,9 +199,9 @@ overrides:
vite@5: '>=6.4.3 <7'
patchedDependencies:
- '@earendil-works/[email protected]': 02de513ae53cf7f1e92d0cfc7fce07cf880d31195f5ec621d2f2197ead92a9da
- '@earendil-works/[email protected]': 0c7a4701594d70c49699adfef275d7c1f997d1c55d103ab09f3377523d322981
- '@earendil-works/[email protected]': ab63d8f7817d606be15d14daedd329df64bb34e73b71c6842b02f67643ba0769
+ '@earendil-works/[email protected]': a2c96619d0f9a1d643a6c6a555ba6a7fb533147336c181f7d3b7f847be33a6eb
+ '@earendil-works/[email protected]': 9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd
+ '@earendil-works/[email protected]': a2878f6aa1d66afa239d6be4252403a73df48b702b3e582aaae04bd90bf3d354
importers:
@@ -227,11 +227,11 @@ importers:
version: 0.2.2
devDependencies:
'@earendil-works/pi-ai':
- specifier: 1.0.1
- version: 1.0.1(patch_hash=0c7a4701594d70c49699adfef275d7c1f997d1c55d103ab09f3377523d322981)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ specifier: 1.1.0
+ version: 1.1.0(patch_hash=9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-mcp':
- specifier: 1.0.1
- version: 1.0.1
+ specifier: 1.1.0
+ version: 1.1.0
'@pi-desktop/agent-host':
specifier: workspace:*
version: link:../../packages/agent-host
@@ -419,14 +419,14 @@ importers:
packages/agent-runtime:
dependencies:
'@earendil-works/pi-agent-core':
- specifier: 1.0.1
- version: 1.0.1(patch_hash=02de513ae53cf7f1e92d0cfc7fce07cf880d31195f5ec621d2f2197ead92a9da)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ specifier: 1.1.0
+ version: 1.1.0(patch_hash=a2c96619d0f9a1d643a6c6a555ba6a7fb533147336c181f7d3b7f847be33a6eb)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-ai':
- specifier: 1.0.1
- version: 1.0.1(patch_hash=0c7a4701594d70c49699adfef275d7c1f997d1c55d103ab09f3377523d322981)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ specifier: 1.1.0
+ version: 1.1.0(patch_hash=9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
'@earendil-works/pi-coding-agent':
- specifier: 1.0.1
- version: 1.0.1(patch_hash=ab63d8f7817d606be15d14daedd329df64bb34e73b71c6842b02f67643ba0769)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])
+ specifier: 1.1.0
+ version: 1.1.0(patch_hash=a2878f6aa1d66afa239d6be4252403a73df48b702b3e582aaae04bd90bf3d354)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])
'@pi-desktop/shared':
specifier: workspace:*
version: link:../shared
@@ -938,38 +938,38 @@ packages:
search-insights:
optional: true
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-woq15kjUZ38fUIMqFrFzTeT0fYYM0CfGS2ELCUE5Ufni32tdxfs0Av2+zz8PXFNxyiC3SB1EnyGPp63CLtp8Fg==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-gsHzKfyQ3t0ZIQ3cLBjJ5Vqy1TYnFyruHIV3g3BwmulCDYe5BW4yT9vaJk9QzN6YANILIO75uzuq+Gdxtzz1og==}
engines: {node: '>=22.19.0'}
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-os85rJM2hgCOOLdtcQ5WxRRhAbQiTNq9+48/pj6dOUU7czJhU8NTdHmDs41hBfAXR/ZQgstIgrjowEICEXimbQ==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-aX1KZomNCPmwYnXa3OivF3VYLJ+WPUkIJlEIZTgwdOZdY/+oToWTQ334WYpQeOz9POpiYFNMJLPwIhXQ4e48kg==}
engines: {node: '>=22.19.0'}
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-eSA53pdfDLuQTTJn3yz1VC8BBmcX33OKkk8WihOXdVBvbgqqC4zuR6Sf+TeeWuAmh8LuqARoK14R1s2HZqVcsw==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-1T7LAkc/5Bvc0v6w4vAGVdCrli0o/E0pEmYKTnixu95vSFArBjvbhS/G4ZwI0RUePgf0Imcu0VyqlM4EcXxqfw==}
engines: {node: '>=22.19.0'}
hasBin: true
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-RpZKpdKceYmIODfqKLJtZWUvfkbDGmEHxEEEYN+i21OFm8uY0sTcBMP4oaLf6SkBVBMPae1Z9GtW27+dIRAYPw==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-8Asc2AzhoNaXS1snmRFa96OhcWIlFM5k1Kuiz6p2DvIYgi5QHQccRAmDVY9oO92TzWrizpvQpconZGQ7JhlI7Q==}
engines: {node: '>=22.19.0'}
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-B7FGYpHpBPvS+Ux16CbCuVnE9S4v6c2h6ykocPNarC4msD/4JM/eFrCrO2wbRkedJZ25myFozSWHvCOx4QnN+w==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-SeEi/4hdcHNgA9UWlefZl7ZZpm3dzi2OoxNjDHsBJ9o298LNOtbL4DGKgitlEj6uCTccvtw6f2hlCkTPVJ2RXg==}
engines: {node: '>=22.19.0'}
hasBin: true
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-XuhcCpNT9FgsMQTzjmwy2hbakg9CODcDHtC+KeHfr37HjKdj4QsfOrOThxLXYRN4kmC5HDvFyLzthAnHe/T4jw==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-xGKwvu3SvVTeoIx8Z7UGoJprB4VK20wKORMhufcWGx61fIauhu3J+UqfB5eeoF1oE/geYBA598K6nh1SdABQkg==}
engines: {node: '>=22.19.0'}
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-SuJ/4KyqZ6j6Whlau710DmusWDKMWCxKXpWqZclY/Cl3tGUuX8IFmbTbW2VRoVuoJpZYVMg6DJmt1mwHMUt9uw==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-8gAK05/2pPozZZz6hCLOi8x2vsqzvsmO9gG92kbvuvTPm0qMHaFlaXX98ndXsrOi5pmzha7vNLguuG4+0Rgxjw==}
engines: {node: '>=22.19.0'}
- '@earendil-works/[email protected]':
- resolution: {integrity: sha512-Rk/pWLoDKWI7WvywhLxf+DTYppS7XWTN5IacpqlD+QF+CbrT/y5CCnAHqPEoF41y+XtQJKbNjjzUuJE4yq0Dfg==}
+ '@earendil-works/[email protected]':
+ resolution: {integrity: sha512-v7wkS0y2ErZvZkSfemqd9RrBZJ5x6p8Ujsv7NdJj01IXJyFM0kNL6rMdcKcvTe7EVTd6ugvDB9VPZSoaBF9QxQ==}
engines: {node: '>=22.19.0'}
'@electron-internal/[email protected]':
@@ -5321,13 +5321,13 @@ snapshots:
transitivePeerDependencies:
- '@algolia/client-search'
- '@earendil-works/[email protected]':
+ '@earendil-works/[email protected]':
dependencies:
esbuild: 0.28.2
- '@earendil-works/[email protected](patch_hash=02de513ae53cf7f1e92d0cfc7fce07cf880d31195f5ec621d2f2197ead92a9da)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
+ '@earendil-works/[email protected](patch_hash=a2c96619d0f9a1d643a6c6a555ba6a7fb533147336c181f7d3b7f847be33a6eb)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
dependencies:
- '@earendil-works/pi-ai': 1.0.1(patch_hash=0c7a4701594d70c49699adfef275d7c1f997d1c55d103ab09f3377523d322981)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ '@earendil-works/pi-ai': 1.1.0(patch_hash=9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
typebox: 1.3.27
transitivePeerDependencies:
- '@aws-sdk/credential-provider-node'
@@ -5342,11 +5342,11 @@ snapshots:
- ws
- zod
- '@earendil-works/[email protected](patch_hash=0c7a4701594d70c49699adfef275d7c1f997d1c55d103ab09f3377523d322981)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
+ '@earendil-works/[email protected](patch_hash=9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
dependencies:
'@anthropic-ai/sdk': 0.129.0([email protected])
'@aws-sdk/client-bedrock-runtime': 3.1127.0
- '@earendil-works/pi-telemetry': 1.0.1
+ '@earendil-works/pi-telemetry': 1.1.0
'@google/genai': 2.21.0([email protected])
'@smithy/node-http-handler': 4.12.1
http-proxy-agent: 9.1.0([email protected])
@@ -5367,11 +5367,11 @@ snapshots:
- ws
- zod
- '@earendil-works/[email protected](patch_hash=0c7a4701594d70c49699adfef275d7c1f997d1c55d103ab09f3377523d322981)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
+ '@earendil-works/[email protected](patch_hash=9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])':
dependencies:
'@anthropic-ai/sdk': 0.129.0([email protected])
'@aws-sdk/client-bedrock-runtime': 3.1127.0
- '@earendil-works/pi-telemetry': 1.0.1
+ '@earendil-works/pi-telemetry': 1.1.0
'@google/genai': 2.21.0([email protected])
'@smithy/node-http-handler': 4.12.1
http-proxy-agent: 9.1.0([email protected])
@@ -5392,18 +5392,18 @@ snapshots:
- ws
- zod
- '@earendil-works/[email protected]':
+ '@earendil-works/[email protected]':
dependencies:
quickjs-wasi: 3.6.2
- '@earendil-works/[email protected](patch_hash=ab63d8f7817d606be15d14daedd329df64bb34e73b71c6842b02f67643ba0769)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])':
+ '@earendil-works/[email protected](patch_hash=a2878f6aa1d66afa239d6be4252403a73df48b702b3e582aaae04bd90bf3d354)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])':
dependencies:
- '@earendil-works/chord': 1.0.1
- '@earendil-works/pi-agent-core': 1.0.1(patch_hash=02de513ae53cf7f1e92d0cfc7fce07cf880d31195f5ec621d2f2197ead92a9da)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
- '@earendil-works/pi-ai': 1.0.1(patch_hash=0c7a4701594d70c49699adfef275d7c1f997d1c55d103ab09f3377523d322981)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
- '@earendil-works/pi-codemode': 1.0.1
- '@earendil-works/pi-mcp': 1.0.1
- '@earendil-works/pi-tui': 1.0.1
+ '@earendil-works/chord': 1.1.0
+ '@earendil-works/pi-agent-core': 1.1.0(patch_hash=a2c96619d0f9a1d643a6c6a555ba6a7fb533147336c181f7d3b7f847be33a6eb)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ '@earendil-works/pi-ai': 1.1.0(patch_hash=9f3713107628b7e52bc90d1bab011e3d819fec598ce1eac47d389aad0bd96dcd)(@aws-sdk/[email protected])(@smithy/[email protected])([email protected])([email protected])([email protected])([email protected])
+ '@earendil-works/pi-codemode': 1.1.0
+ '@earendil-works/pi-mcp': 1.1.0
+ '@earendil-works/pi-tui': 1.1.0
'@silvia-odwyer/photon-node': 0.3.4
brace-expansion: 5.0.12
chalk: 6.0.0
@@ -5433,13 +5433,13 @@ snapshots:
- ws
- zod
- '@earendil-works/[email protected]':
+ '@earendil-works/[email protected]':
dependencies:
cross-spawn: 7.0.6
- '@earendil-works/[email protected]': {}
+ '@earendil-works/[email protected]': {}
- '@earendil-works/[email protected]':
+ '@earendil-works/[email protected]':
dependencies:
get-east-asian-width: 1.6.0
marked: 18.0.11
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 42cf76063..a9ca3dc70 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -13,17 +13,17 @@ allowBuilds:
# binary; its from-source install script was never approved and is not needed.
koffi: false
# pnpm records exact-version exclusions for the current, explicitly requested
-# Pi 1.0.1 release while it is inside the minimum release age window. Keep these
+# Pi 1.1.0 release while it is inside the minimum release age window. Keep these
# entries exact; do not widen them to package names or ranges.
minimumReleaseAgeExclude:
- - '@earendil-works/[email protected]'
- - '@earendil-works/[email protected]'
- - '@earendil-works/[email protected]'
- - '@earendil-works/[email protected]'
- - '@earendil-works/[email protected]'
- - '@earendil-works/[email protected]'
- - '@earendil-works/[email protected]'
- - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
+ - '@earendil-works/[email protected]'
# Advisory fixes for transitives whose parents still resolve the vulnerable
# version. Drop each one once its parent ships a release that resolves the
# patched version on its own.
@@ -53,9 +53,9 @@ overrides:
# every range to its floor — silently downgrading dependencies instead of
# refreshing them. Pin the intent: `pnpm update` means "newest within range".
patchedDependencies:
- '@earendil-works/[email protected]': patches/@[email protected]
- '@earendil-works/[email protected]': patches/@[email protected]
- '@earendil-works/[email protected]': patches/@[email protected]
+ '@earendil-works/[email protected]': patches/@[email protected]
+ '@earendil-works/[email protected]': patches/@[email protected]
+ '@earendil-works/[email protected]': patches/@[email protected]
resolutionMode: highest
# shamefully-hoist also lives in .npmrc, but pnpm 12 applies it only from
# here; without it public hoisting is empty and examples/ plugins cannot
diff --git a/scripts/check-pi-dependencies.mjs b/scripts/check-pi-dependencies.mjs
index 0f03ac6ae..623c68599 100644
--- a/scripts/check-pi-dependencies.mjs
+++ b/scripts/check-pi-dependencies.mjs
@@ -25,7 +25,7 @@ function parseArgs(argv) {
}
const root = parseArgs(process.argv.slice(2));
-const targetVersion = "1.0.1";
+const targetVersion = "1.1.0";
function readJson(path) {
return JSON.parse(readFileSync(join(root, path), "utf8"));
@@ -69,8 +69,8 @@ for (const packageName of ["@earendil-works/pi-ai", "@earendil-works/pi-mcp"]) {
const lockfile = readFileSync(join(root, "pnpm-lock.yaml"), "utf8");
for (const packageName of ["pi-agent-core", "pi-ai", "pi-coding-agent", "pi-mcp"]) {
- if (new RegExp(`@earendil-works/${packageName}@0\\.99\\.1(?:[(:]|$)`).test(lockfile)) {
- throw new Error(`pnpm-lock.yaml still contains @earendil-works/${packageName}@0.99.1`);
+ if (new RegExp(`@earendil-works/${packageName}@1\\.0\\.1(?:[(:]|$)`).test(lockfile)) {
+ throw new Error(`pnpm-lock.yaml still contains @earendil-works/${packageName}@1.0.1`);
}
}
const workspace = readFileSync(join(root, "pnpm-workspace.yaml"), "utf8");
@@ -81,17 +81,17 @@ const actualReleaseAgeExclusions = [...releaseAgeExclusions.matchAll(/^[ \t]+-[
.map((match) => match[1])
.sort();
const expectedReleaseAgeExclusions = [
- "@earendil-works/[email protected]",
- "@earendil-works/[email protected]",
- "@earendil-works/[email protected]",
- "@earendil-works/[email protected]",
- "@earendil-works/[email protected]",
- "@earendil-works/[email protected]",
- "@earendil-works/[email protected]",
- "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
+ "@earendil-works/[email protected]",
].sort();
if (JSON.stringify(actualReleaseAgeExclusions) !== JSON.stringify(expectedReleaseAgeExclusions)) {
- throw new Error("Pi minimumReleaseAgeExclude entries must match only the exact 1.0.1 release packages");
+ throw new Error("Pi minimumReleaseAgeExclude entries must match only the exact 1.1.0 release packages");
}
process.stdout.write(`Pi direct pins and installed package instances are aligned at ${targetVersion}.\n`);
diff --git a/scripts/check-pi-patches.mjs b/scripts/check-pi-patches.mjs
index 6e56f3c71..94072c554 100644
--- a/scripts/check-pi-patches.mjs
+++ b/scripts/check-pi-patches.mjs
@@ -25,7 +25,7 @@ function parseArgs(argv) {
}
const root = parseArgs(process.argv.slice(2));
-const targetVersion = "1.0.1";
+const targetVersion = "1.1.0";
const entries = [
{
name: "@earendil-works/pi-agent-core",
diff --git a/scripts/pi-patch-hash.test.mjs b/scripts/pi-patch-hash.test.mjs
index 60dda0cc8..507791b28 100644
--- a/scripts/pi-patch-hash.test.mjs
+++ b/scripts/pi-patch-hash.test.mjs
@@ -11,7 +11,7 @@ const here = dirname(fileURLToPath(import.meta.url));
const patchDependencyCheck = join(here, "check-pi-dependencies.mjs");
const patchCheck = join(here, "check-pi-patches.mjs");
-const TARGET = "1.0.1";
+const TARGET = "1.1.0";
const PATCHED = [
{
name: "@earendil-works/pi-agent-core",