Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codex-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 22 additions & 5 deletions src/pack-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
// 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. */
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). */
Expand Down Expand Up @@ -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 : "";
Expand Down
8 changes: 7 additions & 1 deletion src/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 11 additions & 3 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompressSettings["ccr"]>;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion tests/issue5103-startup-recovery-visibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down
1 change: 1 addition & 0 deletions tests/text-safe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 5 additions & 5 deletions website/config-reference/compress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ <h3 data-i18n="d.cf.t_compress">compress — every knob</h3>
<tr><td class="mono">maxSummaryLength</td><td class="mech">number</td><td data-i18n="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.</td></tr>
<tr><td class="mono">minSummaryLength</td><td class="mech">number</td><td data-i18n="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).</td></tr>
<tr><td class="mono">reconcile</td><td class="mech">"off" | "warn" | "repair"</td><td data-i18n="cw.rec">"off" | "warn" | "repair" (default repair): reconcile folded state when the client rewinds or rewrites history between turns.</td></tr>
<tr><td class="mono">promptPack</td><td class="mech">string (builtin: "default", "lean")</td><td data-i18n="cw.ppk">Compression prompt pack, resolved project pack → user pack → builtin. Builtins: "default" and "lean" (one-line tool descriptions). Not gated by acknowledgePromptsRisk.</td></tr>
<tr><td class="mono">promptPack</td><td class="mech">string (builtin: "default", "lean", "chat")</td><td data-i18n="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.</td></tr>
<tr><td class="mono">tiers</td><td class="mech">boolean</td><td data-i18n="cw.tiers">On by default: tiered T1→T3 distillation spreads folding cost across generations.</td></tr>
<tr><td class="mono">protectedTools</td><td class="mech">string[]</td><td data-i18n="ct.pt">Hard exclusion across all history: results of listed tools never fold (use with care).</td></tr>
<tr><td class="mono">protectedLatestTools</td><td class="mech">string[]</td><td data-i18n="ct.plt">Protects only the LATEST instance of cumulative-snapshot tools whose newest result supersedes older ones (e.g. todo lists).</td></tr>
Expand Down
4 changes: 2 additions & 2 deletions website/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down Expand Up @@ -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 列表)。",
Expand Down