diff --git a/src/codex-models.ts b/src/codex-models.ts index 45ee8b588e..02d49f1ab2 100644 --- a/src/codex-models.ts +++ b/src/codex-models.ts @@ -89,7 +89,7 @@ function positiveWindow(value: unknown): number | undefined { /** #5243: which surface produced a codex-aligned window — named in the clamp * log so "window clamped" stops claiming client metadata when no client * metadata existed. */ -export type CodexWindowSource = +type CodexWindowSource = | "client-metadata" | "codex-catalog" | "codex-models-cache" diff --git a/src/pack-install.ts b/src/pack-install.ts index a70844c1a8..978b761fe6 100644 --- a/src/pack-install.ts +++ b/src/pack-install.ts @@ -17,13 +17,14 @@ // overwrite of user config). Writes go through the temp-file+rename // pattern shared with every other writer here. -import { execFileSync } from "node:child_process"; +import { spawnSync } from "node:child_process"; import { closeSync, existsSync, fsyncSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; import { randomUUID } from "node:crypto"; import { isValidPackName, sanitizePackSurface, type PromptPackFile } from "acp-kernel"; import { configDir } from "./paths.js"; +import { planDshSpawn } from "./dsh-channel.js"; import { packSurfaceHasContent } from "./web/api.js"; /** The file an npm package must ship to be installable as a pack. */ @@ -31,7 +32,7 @@ export const PACK_ENTRY_FILE = "bili-pack.json"; const NPM_TIMEOUT_MS = 120_000; -export interface PackInstallOptions { +interface PackInstallOptions { /** Target `./.billion-context/packs/` instead of the user-dir default. */ project?: boolean; /** Replace an existing pack file (refused otherwise). */ @@ -107,9 +108,25 @@ export function installPackFromNpm(spec: string, options: PackInstallOptions = { try { let stderr = ""; try { - execFileSync("npm", [ - "install", "--prefix", tmp, "--no-save", "--no-audit", "--no-fund", trimmed, - ], { timeout: NPM_TIMEOUT_MS, stdio: ["ignore", "pipe", "pipe"] }); + // #5340: `npm` is `npm.cmd` on Windows, which CreateProcess cannot + // execute directly — a bare execFileSync("npm", …) fails there with + // ENOENT ("npm was not found on PATH"). planDshSpawn applies the same + // cmd.exe /d /s /c wrap the launcher/pi/dsh lanes already use. + const npmArgs = ["install", "--prefix", tmp, "--no-save", "--no-audit", "--no-fund", trimmed]; + const plan = planDshSpawn("npm", npmArgs); + const res = spawnSync(plan.command, plan.args, { + timeout: NPM_TIMEOUT_MS, + stdio: ["ignore", "pipe", "pipe"], + windowsVerbatimArguments: plan.windowsVerbatimArguments, + windowsHide: true, + }); + if (res.error) throw res.error; + if (res.status !== 0 && res.status !== null) { + const err = new Error(`exit ${res.status}`); + Object.assign(err, { status: res.status, stderr: typeof res.stderr === "string" ? res.stderr : "" }); + throw err; + } + stderr = typeof res.stderr === "string" ? res.stderr : ""; } catch (error) { const err = error as { stderr?: unknown; message?: string }; stderr = typeof err.stderr === "string" ? err.stderr : ""; diff --git a/src/persist.ts b/src/persist.ts index 3537509881..9b28155d44 100644 --- a/src/persist.ts +++ b/src/persist.ts @@ -3239,7 +3239,13 @@ export class SessionStore { contentStoreRelPathFor(id, meta?.protocol, meta?.upstreamOrigin), contentStoreRelPathFor(id), ])) { - try { if (existsSync(p)) return true; } catch { /* probe only */ } + // A PATH is not a COPY: existsSync alone accepts a directory or a + // socket sitting at the sidecar name, and folding on that proof makes + // the next touch throw ("could not be re-materialized … refusing the + // thinned view") where a resident set was still in hand. Require a + // regular file — this mirrors what readContentStoreRels can actually + // read back, so the drop only happens when the reload is guaranteed. + try { if (statSync(p).isFile()) return true; } catch { /* probe only */ } } return false; } diff --git a/src/store.ts b/src/store.ts index 9e24628e6b..06520a3a85 100644 --- a/src/store.ts +++ b/src/store.ts @@ -19,7 +19,7 @@ import { stateDir } from "./paths.js"; import { getStore } from "./persist.js"; import type { CompressSettings } from "./config.js"; import { ccrRetrievalTtlMs as knobCcrRetrievalTtlMs } from "./knobs.js"; -import type { PendingRetrieval, Session } from "./session.js"; +import { isDroppedContentStore, type PendingRetrieval, type Session } from "./session.js"; import { toolFail, toolOk, type ProxyToolResult } from "./proxy-tool-result.js"; export type CcrSettings = NonNullable; @@ -134,8 +134,16 @@ export function contentStoreOf(session: Session): MessageContentStore { * only when new entries appeared, so a no-growth turn costs nothing. */ export function adoptContentStore(session: Session, store: MessageContentStore): void { const prev = session.contentStore; - const added = prev - ? Object.entries(store.byRef).filter(([ref]) => !(ref in prev.byRef)) + // #4788 phase 2: a discharged (lazy) resident store is a Proxy that throws + // on first touch when its on-disk copy vanished under it (e.g. the sidecar + // was replaced by a directory, or the user deleted the sessions dir after + // the drop). Adoption is append-only and the incoming store already carries + // every ref (kernel processTurn re-ingests the history), so a THINNED prev + // is not a source of truth: treat it as absent instead of letting one stale + // path turn a normal turn into a hard failure. + const usablePrev = prev && !isDroppedContentStore(prev) ? prev : undefined; + const added = usablePrev + ? Object.entries(store.byRef).filter(([ref]) => !(ref in usablePrev.byRef)) : Object.entries(store.byRef); session.contentStore = store; if (added.length === 0) return; diff --git a/tests/issue5103-startup-recovery-visibility.test.ts b/tests/issue5103-startup-recovery-visibility.test.ts index 2f59fc183b..13120aeaee 100644 --- a/tests/issue5103-startup-recovery-visibility.test.ts +++ b/tests/issue5103-startup-recovery-visibility.test.ts @@ -102,7 +102,10 @@ test("#5103: explicit attachUrl target found but build-incompatible — refusal const notice = stderrLines.find((l) => l.includes(`explicit attach target ${ORIGIN}`)); assert.ok(notice, "the visible channel must name the refused explicit target"); assert.ok(notice!.includes("code-fingerprint-mismatch"), notice); - assert.ok(notice!.includes("restart the host once its copy converges to the same version"), notice); + // #4125 rewrote this remedy: a strictly newer same-lane holder is now adopted + // rather than deadlocked around, so the wording no longer promises "the same + // version" — pin the stable remedy fragment instead of the old sentence. + assert.ok(notice!.includes("restart the host once its copy converges"), notice); assert.ok(diags.some((d) => d.includes(`explicit attach target ${ORIGIN}`)), "the durable log gets the same line"); }); diff --git a/tests/text-safe.test.ts b/tests/text-safe.test.ts index 7d729446c9..d0e5ebb773 100644 --- a/tests/text-safe.test.ts +++ b/tests/text-safe.test.ts @@ -176,6 +176,7 @@ test("family gate: no raw negative string slices outside the allowlist", () => { ["src/conflict-watch.ts", [/events\.slice\(-10\)/]], // array receiver ["src/web/client.ts", [/conflicts\.slice\(-10\)/]], // array receiver (#2102 session-detail card) ["src/web/report.ts", [/lines\.slice\(-12\)/, /folds\.slice\(-15\)/]], // array receiver (#3099 session-report tables) + ["src/pack-install.ts", [/stderr\.trim\(\)\.split\("\\n"\)\.slice\(-3\)/]], // array receiver (#5340): keeps the last 3 STDERR LINES, not a string suffix ["src/text-safe.ts", [/\.slice\(/]], // the clamped implementation itself ]); const srcDir = path.join(import.meta.dirname, "..", "src"); diff --git a/website/config-reference/compress.yaml b/website/config-reference/compress.yaml index 25a7896f63..44a5e627db 100644 --- a/website/config-reference/compress.yaml +++ b/website/config-reference/compress.yaml @@ -164,15 +164,15 @@ entries: site_en: "\"off\" | \"warn\" | \"repair\" (default repair): reconcile folded state when the client rewinds or rewrites history between turns." site_zh: "\"off\" | \"warn\" | \"repair\"(默认 repair):客户端在轮次之间回退或改写历史时校准已折叠状态。" - key: compress.promptPack - type: "string (builtin: \"default\", \"lean\")" + type: "string (builtin: \"default\", \"lean\", \"chat\")" default: "builtin \"default\"" group: compress id: cw.ppk render: compress-row - desc_en: "Compression prompt pack, resolved project pack → user pack → builtin; not gated by acknowledgePromptsRisk." - desc_zh: "压缩提示词包,按 项目包 → 用户包 → 内置 解析;不受 acknowledgePromptsRisk 门控。" - site_en: "Compression prompt pack, resolved project pack → user pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions). Not gated by acknowledgePromptsRisk." - site_zh: "压缩提示词包,按 项目包 → 用户包 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述)。不受 acknowledgePromptsRisk 门控。" + desc_en: "Compression prompt pack, resolved project pack → user pack → shipped pack → builtin; not gated by acknowledgePromptsRisk." + desc_zh: "压缩提示词包,按 项目包 → 用户包 → 随包附带(chat)→ 内置 解析;不受 acknowledgePromptsRisk 门控。" + site_en: "Compression prompt pack, resolved project pack → user pack → shipped pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions); hosts may also ship a \"chat\" pack (#5319). Not gated by acknowledgePromptsRisk." + site_zh: "压缩提示词包,按 项目包 → 用户包 → 随包附带 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述);宿主可另附 \"chat\" 包(#5319)。不受 acknowledgePromptsRisk 门控。" - key: compress.tiers type: boolean default: "true" diff --git a/website/docs/index.html b/website/docs/index.html index cfbe6e24b1..0b8460df05 100644 --- a/website/docs/index.html +++ b/website/docs/index.html @@ -195,7 +195,7 @@

compress — every knob

maxSummaryLengthnumberHard cap, in characters, on one generated summary (kernel default 20000): longer replies are rejected whole by the kernel check or the external-summary executor. External summarizers receive this exact cap in their instructions (#3635); 0 disables the cap. minSummaryLengthnumberFloor, in characters, for generated summaries (kernel default 50): shorter replies are rejected whole; 0 disables the floor. External summarizers are held to the same floor (#3635). reconcile"off" | "warn" | "repair""off" | "warn" | "repair" (default repair): reconcile folded state when the client rewinds or rewrites history between turns. - promptPackstring (builtin: "default", "lean")Compression prompt pack, resolved project pack → user pack → builtin. Builtins: "default" and "lean" (one-line tool descriptions). Not gated by acknowledgePromptsRisk. + promptPackstring (builtin: "default", "lean", "chat")Compression prompt pack, resolved project pack → user pack → shipped pack → builtin. Builtins: "default" and "lean" (one-line tool descriptions); hosts may also ship a "chat" pack (#5319). Not gated by acknowledgePromptsRisk. tiersbooleanOn by default: tiered T1→T3 distillation spreads folding cost across generations. protectedToolsstring[]Hard exclusion across all history: results of listed tools never fold (use with care). protectedLatestToolsstring[]Protects only the LATEST instance of cumulative-snapshot tools whose newest result supersedes older ones (e.g. todo lists). diff --git a/website/main.js b/website/main.js index 86222cd284..51eed44329 100644 --- a/website/main.js +++ b/website/main.js @@ -77,7 +77,7 @@ "cw.msl": "Hard cap, in characters, on one generated summary (kernel default 20000): longer replies are rejected whole by the kernel check or the external-summary executor. External summarizers receive this exact cap in their instructions (#3635); 0 disables the cap.", "cw.mnl": "Floor, in characters, for generated summaries (kernel default 50): shorter replies are rejected whole; 0 disables the floor. External summarizers are held to the same floor (#3635).", "cw.rec": "\"off\" | \"warn\" | \"repair\" (default repair): reconcile folded state when the client rewinds or rewrites history between turns.", - "cw.ppk": "Compression prompt pack, resolved project pack → user pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions). Not gated by acknowledgePromptsRisk.", + "cw.ppk": "Compression prompt pack, resolved project pack → user pack → shipped pack → builtin. Builtins: \"default\" and \"lean\" (one-line tool descriptions); hosts may also ship a \"chat\" pack (#5319). Not gated by acknowledgePromptsRisk.", "cw.tiers": "On by default: tiered T1→T3 distillation spreads folding cost across generations.", "ct.pt": "Hard exclusion across all history: results of listed tools never fold (use with care).", "ct.plt": "Protects only the LATEST instance of cumulative-snapshot tools whose newest result supersedes older ones (e.g. todo lists).", @@ -325,7 +325,7 @@ "cw.msl": "单条生成摘要的硬上限,单位为字符(内核默认 20000):超长的回复由内核检查或外部摘要执行器整段拒绝。外部摘要模型的指令中会写明这个确切上限(#3635);0 禁用上限。", "cw.mnl": "生成摘要的下限,单位为字符(内核默认 50):过短的回复被整段拒绝;0 禁下限。外部摘要模型受同一下限约束(#3635)。", "cw.rec": "\"off\" | \"warn\" | \"repair\"(默认 repair):客户端在轮次之间回退或改写历史时校准已折叠状态。", - "cw.ppk": "压缩提示词包,按 项目包 → 用户包 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述)。不受 acknowledgePromptsRisk 门控。", + "cw.ppk": "压缩提示词包,按 项目包 → 用户包 → 随包附带 → 内置 解析。内置:\"default\" 与 \"lean\"(单行工具描述);宿主可另附 \"chat\" 包(#5319)。不受 acknowledgePromptsRisk 门控。", "cw.tiers": "默认开:T1→T3 分级蒸馏,把折叠成本摊到多代。", "ct.pt": "全历史硬排除:列出工具的结果永不折叠(慎用)。", "ct.plt": "只保护累积快照类工具的「最新一次」实例(新结果覆盖旧结果的工具,如 todo 列表)。",