Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): hash-verify dir-dist assets; keep Pi out of the task-summary one-shot fallback
Chris637d657b3d62
diff --git a/apps/desktop/src/main/maker-ipc/help.ts b/apps/desktop/src/main/maker-ipc/help.tsindex 9aec2a07da..77b8cf1272 100644--- a/apps/desktop/src/main/maker-ipc/help.ts+++ b/apps/desktop/src/main/maker-ipc/help.ts@@ -8,7 +8,7 @@ import { createLogger } from '../logger.js';import { isAgentOneShotRouteDisabled } from '../maker-host/model-route-guard-live.js';import { getDbClient } from '../localDb/client/current.js';import { sessions } from '../localDb/schema.js';-import { requestUtilityText } from '../utility-model/oneShotCandidates.js';+import { agentSupportsOneShot, requestUtilityText } from '../utility-model/oneShotCandidates.js';import { MAKER_INVOKE } from './channels.js';import { DESKTOP_VISIBLE_SESSION_SOURCES } from '../../shared/sessionSource.js';import type {@@ -254,11 +254,9 @@ async function getMostRecentSessionAgent(): Promise<AgentKind | null> {}}-// help 兜底走 maker.oneShot;目前仅 claude-code / codex 实现了它,PiAgent 继承 BaseAgent-// 的 not-implemented。选中不支持 oneShot 的 agent 会让 HELP_ASK / 置顶摘要抛错并直接-// no-answer,即便其它 agent 兜底仍可用。Pi 实现 oneShot 前从候选里剔除(实现后加回即可)。-const HELP_ONESHOT_CAPABLE_AGENTS: ReadonlySet<AgentKind> = new Set(['claude-code', 'codex']);-+// help 兜底走 maker.oneShot;只有实现了 oneShot 的 agent(agentSupportsOneShot)才可选。+// PiAgent 继承 BaseAgent 的 not-implemented,选中它会让 HELP_ASK / 置顶摘要抛错并直接+// no-answer,即便其它 agent 兜底仍可用 —— 故从候选里剔除(与任务摘要兜底共用同一判定)。export async function pickHelpAgent(maker: Maker,preferredAgent: AgentKind | null,@@ -266,7 +264,7 @@ export async function pickHelpAgent(const candidates: AgentKind[] = preferredAgent? [...new Set<AgentKind>([preferredAgent, 'claude-code', 'codex', 'pi'])]: ['claude-code', 'codex', 'pi'];- const ordered = candidates.filter((agentKind) => HELP_ONESHOT_CAPABLE_AGENTS.has(agentKind));+ const ordered = candidates.filter((agentKind) => agentSupportsOneShot(agentKind));const available = new Set(maker.listAvailableAgents());for (const agentKind of ordered) {if (!available.has(agentKind)) continue;diff --git a/apps/desktop/src/main/sessionTaskSummary.ts b/apps/desktop/src/main/sessionTaskSummary.tsindex 1b64c6bd0f..621f63ecc6 100644--- a/apps/desktop/src/main/sessionTaskSummary.ts+++ b/apps/desktop/src/main/sessionTaskSummary.ts@@ -26,7 +26,7 @@ import { and, count, eq, gt, isNotNull, isNull, lt, or, sql } from 'drizzle-orm'import { getMaker } from './maker-host/index.js';import { isAgentOneShotRouteDisabled } from './maker-host/model-route-guard-live.js';-import { requestUtilityText } from './utility-model/oneShotCandidates.js';+import { agentSupportsOneShot, requestUtilityText } from './utility-model/oneShotCandidates.js';import { getDbClient } from './localDb/client/current.js';import { latestMessageText } from './localDb/latestMessageText.js';import { messages, sessions } from './localDb/schema.js';@@ -155,9 +155,12 @@ async function generateSummaryOnce(sessionId: string): Promise<void> {});// 停用轴:agent one-shot 兜底是新的付费调用,该 agent 的默认路由被停用时不派发// (摘要 best-effort,直接放弃本轮,PR #744 review)。+ // oneShot 能力轴:Pi 未实现 oneShot(继承 BaseAgent 的 not-implemented),对 Pi 会话+ // 走该兜底会抛错、外层 catch 静默把摘要留空。此处摘要绑定会话自身 agent,不像 help+ // 那样跨 agent 兜底 —— 会话 agent 不支持 oneShot 时直接跳过兜底(仅靠 utility-model)。const text = utility.ok? utility.text- : (await isAgentOneShotRouteDisabled(agentKind))+ : (!agentSupportsOneShot(agentKind) || (await isAgentOneShotRouteDisabled(agentKind)))? '': await getMaker().oneShot(agentKind, prompt, { maxTokens: 120 });const summary = sanitize(text, maxCharsForTier(tier));diff --git a/apps/desktop/src/main/utility-model/oneShotCandidates.ts b/apps/desktop/src/main/utility-model/oneShotCandidates.tsindex 3972ca2a83..717bb03489 100644--- a/apps/desktop/src/main/utility-model/oneShotCandidates.ts+++ b/apps/desktop/src/main/utility-model/oneShotCandidates.ts@@ -30,6 +30,16 @@ import type {const log = createLogger('utility-model:one-shot');+/**+ * 实现了 `Agent.oneShot` 的 agent 集合(当前 claude-code / codex)。PiAgent 继承 BaseAgent+ * 的 not-implemented,选中它调 oneShot 会抛错;help 兜底与任务摘要兜底都据此跳过 Pi,避免+ * best-effort 结果被静默丢弃。Pi 实现 oneShot 后把它加入本集合即可。+ */+const ONESHOT_CAPABLE_AGENTS: ReadonlySet<AgentKind> = new Set(['claude-code', 'codex']);+export function agentSupportsOneShot(agentKind: AgentKind): boolean {+ return ONESHOT_CAPABLE_AGENTS.has(agentKind);+}+export type UtilityTextCapability = {transports: readonly UtilityModelTransport[];};diff --git a/scripts/__tests__/ensure-agent-binaries.test.mjs b/scripts/__tests__/ensure-agent-binaries.test.mjsindex a63b05913d..f33e8acb69 100644--- a/scripts/__tests__/ensure-agent-binaries.test.mjs+++ b/scripts/__tests__/ensure-agent-binaries.test.mjs@@ -97,7 +97,22 @@ test('verifyDirDistManifest: rejects size drift, empty manifests, and malformedwriteDirDistManifest(dir);assert.equal(verifyDirDistManifest(dir), true);+ // 同长度内容被替换/损坏(字节数不变)→ 现按 sha256 拒绝(供应链加固 P1)+ writeDirDistManifest(dir);+ assert.equal(verifyDirDistManifest(dir), true);+ fs.writeFileSync(path.join(dir, 'photon.wasm'), Buffer.alloc(512, 9)); // 同长度、不同内容+ assert.equal(verifyDirDistManifest(dir), false);++ // 旧版本写的 size-only 清单(无 sha256)→ 一律不可信,拒绝(自愈重下)+ fs.writeFileSync(path.join(dir, 'photon.wasm'), Buffer.alloc(512, 2)); // 复原内容+ fs.writeFileSync(+ path.join(dir, '.manifest'),+ JSON.stringify({ files: [{ path: 'photon.wasm', size: 512 }] }),+ );+ assert.equal(verifyDirDistManifest(dir), false);+// 字节数漂移(截断/损坏)→ 拒绝+ writeDirDistManifest(dir);fs.writeFileSync(path.join(dir, 'photon.wasm'), Buffer.alloc(8, 2));assert.equal(verifyDirDistManifest(dir), false);diff --git a/tools/shared/dir-dist-manifest.mjs b/tools/shared/dir-dist-manifest.mjsindex 30d5fba43e..5f0d5bfb43 100644--- a/tools/shared/dir-dist-manifest.mjs+++ b/tools/shared/dir-dist-manifest.mjs@@ -8,10 +8,16 @@import fs from 'node:fs';import path from 'node:path';+import { sha256File } from './verify-sha256.mjs';+export const DIR_DIST_MANIFEST_FILE = '.manifest';const MARKER_FILES = new Set(['.version', DIR_DIST_MANIFEST_FILE]);-/** 递归收集 destDir 下全部普通文件(排序稳定),写 .manifest。symlink/目录不入清单。 */+/**+ * 递归收集 destDir 下全部普通文件(排序稳定),写 .manifest。symlink/目录不入清单。+ * 每条同时记录字节数与 sha256:只比字节数挡不住「同长度被替换/损坏」的资产(供应链+ * 加固,codex review P1)—— 主执行文件与所有旁侧资产(theme/wasm/prebuild 等)都记哈希。+ */export function writeDirDistManifest(destDir) {const files = [];const walk = (dir) => {@@ -27,7 +33,7 @@ export function writeDirDistManifest(destDir) {if (!entry.isFile()) continue;const rel = path.relative(destDir, abs).split(path.sep).join('/');if (MARKER_FILES.has(rel)) continue;- files.push({ path: rel, size: fs.statSync(abs).size });+ files.push({ path: rel, size: fs.statSync(abs).size, sha256: sha256File(abs) });}};walk(destDir);@@ -38,7 +44,11 @@ export function writeDirDistManifest(destDir) {return files.length;}-/** 校验 destDir 与清单一致:清单缺失/空/任一文件缺失或字节数不符 → false。 */+/**+ * 校验 destDir 与清单一致:清单缺失/空/任一文件缺失、字节数不符或 sha256 不符 → false。+ * 每条都按记录的 sha256 重算比对(fail-closed):清单缺 sha256(旧版本写的 size-only 清单)+ * 一律视为不可信 → false,让上层重下/重 promote 生成带哈希的新清单(自愈,一次性)。+ */export function verifyDirDistManifest(destDir) {let manifest;try {@@ -49,14 +59,30 @@ export function verifyDirDistManifest(destDir) {const files = Array.isArray(manifest?.files) ? manifest.files : null;if (!files || files.length === 0) return false;for (const entry of files) {- if (!entry || typeof entry.path !== 'string' || !Number.isFinite(entry.size)) return false;+ if (+ !entry+ || typeof entry.path !== 'string'+ || !Number.isFinite(entry.size)+ || typeof entry.sha256 !== 'string'+ || !/^[0-9a-f]{64}$/.test(entry.sha256)+ ) {+ return false;+ }+ const abs = path.join(destDir, ...entry.path.split('/'));let stat;try {- stat = fs.statSync(path.join(destDir, ...entry.path.split('/')));+ stat = fs.statSync(abs);} catch {return false;}if (!stat.isFile() || stat.size !== entry.size) return false;+ let actual;+ try {+ actual = sha256File(abs);+ } catch {+ return false;+ }+ if (actual !== entry.sha256) return false;}return true;}