Skip to content
Merged
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
8 changes: 3 additions & 5 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Deploy website to GitHub Pages

on:
push:
branches: [master]
paths:
- "website/**"
- ".github/workflows/pages.yml"
# Push trigger suspended (#4598): the repo has no GitHub Pages site, so every
# website push red-lined the deploy job. Manual dispatch stays until the
# publishing direction is decided.
workflow_dispatch:

permissions:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Versions follow the merge of a `*_release-v*` branch; CI publishes to npm on tag

## [Unreleased]

### Fixed
- 块区间边界在重存时不再回退:折叠后客户端重发的视图不含已覆盖原文,重入库时该批次无法重新解析区间(-1/-1),旧逻辑会把已解析的真实区间抹掉。现在区间证据一旦解析即持久(入库 `CASE` 保留;sqlite/mysql 双后端),未知块保持诚实缺口(#4608)。

### Added

### D5-5 — 渲染源窗口化 + 判官 tailStart 视图域修复
Expand Down
3 changes: 3 additions & 0 deletions scripts/live-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export const LIVE_FILES = [
// #4434 (split-brain surface): spawns bili CLI children against a throwaway
// origin; own probe server is listen(0) so only the zone band matters
"tests/issue-split-brain-surface.test.ts",
// #3890: spawns the drain fixture; that fixture is listen(0) and reports
// READY <port>, so no zone band is needed — the entry is for the tripwire
"tests/issue3890-parent-gone-confirm-drain.test.ts",
];

/** Band width per live file: the zone ladder drifts +1 per EADDRINUSE retry;
Expand Down
2 changes: 1 addition & 1 deletion src/agent/client-build-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import path from "node:path";
import { isVersionNewer } from "../update.js";
import { logHostEvent } from "./host-log.js";

export type ClientBuildCheck = {
type ClientBuildCheck = {
/** Short human label used in the note text ("dsh", "pi", ...). */
label: string;
/** The client's npm id, as shown in the note (@deepseek-ai/dsh, ...). */
Expand Down
35 changes: 25 additions & 10 deletions src/log-mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,32 @@ function escapeRegExp(s: string): string {
* publish-boundary text, rewriting it to `~` (the shell universal for $HOME).
* This is the identity leak #3959 proved in the wild — a public diagnostics
* report naming /home/<user>/... hands a stranger the reporter's username and
* home layout. Only THIS machine's os.homedir() is rewritten, as an ANCHORED
* match on BOTH flanks: preceded by start-of-string or a non-token boundary
* (whitespace / quote / bracket / colon / equals) AND followed by a path
* separator (/ or \), a quote, whitespace or end-of-string — so sibling homes
* (/home/<other>), URL hosts and URL pathnames are all left alone. The result
* stays actionable: ~/.cache/billion-context/... is exactly where the user
* looks to recover. Idempotent (~ has no homedir in it). */
* home layout. Every spelling of THIS machine's home root is rewritten —
* os.homedir() plus the $HOME and %USERPROFILE% env values (on Windows they
* diverge: os.homedir() reads USERPROFILE while git-bash-style tool output
* carries $HOME paths, so masking only one leaks the other; POSIX values
* dedupe to one root) — each as an ANCHORED match on BOTH flanks: preceded by
* start-of-string or a non-token boundary (whitespace / quote / bracket /
* colon / equals) AND followed by a path separator (/ or \), a quote,
* whitespace or end-of-string — so sibling homes (/home/<other>), URL hosts
* and URL pathnames are all left alone. The result stays actionable:
* ~/.cache/billion-context/... is exactly where the user looks to recover.
* Idempotent (~ has no homedir in it). */
function publishHomeRoots(): string[] {
const roots = new Set<string>();
for (const raw of [os.homedir(), process.env.HOME, process.env.USERPROFILE]) {
if (typeof raw !== "string") continue;
const r = raw.replace(/[/\\]+$/, "");
if (r) roots.add(r);
}
return [...roots].sort((a, b) => b.length - a.length);
}

export function maskPathsForPublish(text: string): string {
const home = os.homedir();
if (!text || !home) return text;
const re = new RegExp("(?<![/\\w.\\-])" + escapeRegExp(home) + "(?=[/\\\\\"'\\s]|$)", "g");
if (!text) return text;
const roots = publishHomeRoots();
if (roots.length === 0) return text;
const re = new RegExp("(?<![/\\w.\\-])(" + roots.map(escapeRegExp).join("|") + ")(?=[/\\\\\"'\\s]|$)", "g");
return text.replace(re, "~");
}

Expand Down
6 changes: 5 additions & 1 deletion src/storage/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,11 @@ export class MysqlBackend implements StorageBackend {
summary_hash, one_hash, supersedes_block_id, active, created_at, covered_hash, payload_json)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
ord = VALUES(ord), start_seq = VALUES(start_seq), end_seq = VALUES(end_seq),
ord = VALUES(ord),
// #4608: keep durable interval evidence when a later batch can no
// longer re-derive it (post-fold client resends carry no covered raws)
start_seq = IF(VALUES(start_seq) >= 0, VALUES(start_seq), start_seq),
end_seq = IF(VALUES(end_seq) >= 0, VALUES(end_seq), end_seq),
start_ref = VALUES(start_ref), end_ref = VALUES(end_ref), tier = VALUES(tier),
summary_hash = VALUES(summary_hash), one_hash = VALUES(one_hash),
supersedes_block_id = VALUES(supersedes_block_id), active = VALUES(active),
Expand Down
13 changes: 11 additions & 2 deletions src/storage/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,11 @@ export class UnifiedStore {
.prepare("SELECT summary_hash, one_hash FROM blocks WHERE session_id = ? AND block_id = ?")
.get(s.sessionId, b.blockId) as { summary_hash: string; one_hash: string | null } | undefined;
if (existing) {
// #4608: preserve interval bounds across resaves. A later batch that
// no longer contains the covered raws (a post-fold client resend sees
// the folded view, not the raw tail) re-derives -1/-1 "unknown" from
// its own log; once real evidence exists it is durable — the upsert's
// CASE keeps the stored bounds when the incoming side is unknown.
// #4242: redirect the row BEFORE the undo/release so a
// released-to-zero old hash is no longer FK-referenced by
// this blocks row when the content DELETE fires. The
Expand All @@ -917,7 +922,9 @@ export class UnifiedStore {
summary_hash, one_hash, supersedes_block_id, active, created_at, covered_hash, payload_json)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(session_id, block_id) DO UPDATE SET
ord = excluded.ord, start_seq = excluded.start_seq, end_seq = excluded.end_seq,
ord = excluded.ord,
start_seq = CASE WHEN excluded.start_seq >= 0 THEN excluded.start_seq ELSE blocks.start_seq END,
end_seq = CASE WHEN excluded.end_seq >= 0 THEN excluded.end_seq ELSE blocks.end_seq END,
start_ref = excluded.start_ref, end_ref = excluded.end_ref, tier = excluded.tier,
summary_hash = excluded.summary_hash, one_hash = excluded.one_hash,
supersedes_block_id = excluded.supersedes_block_id, active = excluded.active,
Expand Down Expand Up @@ -955,7 +962,9 @@ export class UnifiedStore {
summary_hash, one_hash, supersedes_block_id, active, created_at, covered_hash, payload_json)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(session_id, block_id) DO UPDATE SET
ord = excluded.ord, start_seq = excluded.start_seq, end_seq = excluded.end_seq,
ord = excluded.ord,
start_seq = CASE WHEN excluded.start_seq >= 0 THEN excluded.start_seq ELSE blocks.start_seq END,
end_seq = CASE WHEN excluded.end_seq >= 0 THEN excluded.end_seq ELSE blocks.end_seq END,
start_ref = excluded.start_ref, end_ref = excluded.end_ref, tier = excluded.tier,
summary_hash = excluded.summary_hash, one_hash = excluded.one_hash,
supersedes_block_id = excluded.supersedes_block_id, active = excluded.active,
Expand Down
2 changes: 1 addition & 1 deletion src/web/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function renderPage(origin: string, version: string, embed = false, theme
// that request used to miss every admin route and get relayed onto the
// configured upstream (a wasted request + 403 noise in the log).
return `<!doctype html><html lang="zh-CN"${theme ? ` data-theme="${theme}"` : ""}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="data:,"><title>billion-context</title><style>${WEB_STYLES}</style></head><body${embed ? ' class="embed"' : ""}>
<header class="topbar"><div class="brand"><span class="logo">∞</span>billion-context<span class="ver">v${version}</span></div><nav class="nav"><a href="#/overview" data-nav="overview" class="active" data-i18n="nav.overview">${zh("nav.overview")}</a><a href="#/sessions" data-nav="sessions" data-i18n="nav.sessions">${zh("nav.sessions")}</a><a href="#/config" data-nav="config" data-i18n="nav.config">${zh("nav.config")}</a><a href="#/connect" data-nav="connect" data-i18n="nav.connect">${zh("nav.connect")}</a><a href="#/logs" data-nav="logs" data-i18n="nav.logs">${zh("nav.logs")}</a></nav><div class="actions"><a class="fork-link" href="https://github.com/ranxianglei/billion-context" target="_blank" rel="noopener" data-i18n="fork.label">${zh("fork.label")}</a><button id="language-toggle" class="lang-btn">English</button></div></header>
<header class="topbar"><div class="brand"><span class="logo">∞</span>billion-context<span class="ver">v${version}</span></div><nav class="nav"><a href="#/overview" data-nav="overview" class="active" data-i18n="nav.overview">${zh("nav.overview")}</a><a href="#/sessions" data-nav="sessions" data-i18n="nav.sessions">${zh("nav.sessions")}</a><a href="#/config" data-nav="config" data-i18n="nav.config">${zh("nav.config")}</a><a href="#/connect" data-nav="connect" data-i18n="nav.connect">${zh("nav.connect")}</a><a href="#/logs" data-nav="logs" data-i18n="nav.logs">${zh("nav.logs")}</a><a href="#/updates" data-nav="updates" data-i18n="nav.updates">${zh("nav.updates")}</a></nav><div class="actions"><a class="fork-link" href="https://github.com/ranxianglei/billion-context" target="_blank" rel="noopener" data-i18n="fork.label">${zh("fork.label")}</a><button id="language-toggle" class="lang-btn">English</button></div></header>
<div id="passthrough-banner" class="banner warn" hidden></div>
<div id="update-banner" class="banner warn" hidden></div>
<div id="stale-banner" class="banner warn" hidden></div>
Expand Down
2 changes: 1 addition & 1 deletion tests/generation-boundary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ test("#4305: injectSystem appends the note only when the boundary is active", ()
const parsed = { system: "You are a helpful assistant.", messages: [] };
const off = injectSystem({ ...parsed }, OPTS, undefined, defaultConfig(400_000), undefined, true, false, false) as string;
assert.ok(!off.includes(GENERATION_BOUNDARY_NOTE), "inactive: system block unchanged by this feature");
const on = injectSystem({ ...parsed }, OPTS, undefined, defaultConfig(400_000), undefined, true, false, true) as string;
const on = injectSystem({ ...parsed }, OPTS, undefined, defaultConfig(400_000), undefined, true, false, false, true) as string;
assert.ok(on.includes(GENERATION_BOUNDARY_NOTE), "active: note rides the ACP standing block");
assert.ok(on.startsWith("You are a helpful assistant."), "client system block stays byte-exact (appended, never merged)");
// sysParts order contract: client head, standing prompt (attribution outermost), THEN the note.
Expand Down
5 changes: 3 additions & 2 deletions tests/golden/storage-render/anthropic.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
"foldAt": 9,
"editedAt": 12,
"summaryFrom": 9,
"stateDigest": "2afbea1dbbc9381f8ec7b49a4fa6b5d55b4084ff20304f20a1f51cb120b9a49f",
"stateDigest": "6727f42bd91879a7aa370e1ce0c78963bcba0df92e50390d4a8011f8f0da334d",
"sectionDigests": {
"state": "f93dc1c876c672d4",
"blockContents": "dc7d13d250c94bb4",
"stats": "c6f1d434975d047d",
"metadata": "9c05fef8fb761941"
"metadata": "f1ec4aab3aff777a"
},
"stateKeyDigests": {
"blocks": "3a454b9a16e4f0b9",
Expand All @@ -98,6 +98,7 @@
"lastPassIds": "f13452893a1b4980",
"hiddenOrphanRefs": "4f53cda18c2baa0c",
"deadRefs": "74234e98afe7498f",
"refLedgerAligned": "74234e98afe7498f",
"terminalStreak": "5feceb66ffc86f38",
"nextRuleId": "6b86b273ff34fce1",
"absorbed": "4f53cda18c2baa0c",
Expand Down
5 changes: 3 additions & 2 deletions tests/golden/storage-render/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
"foldAt": 9,
"editedAt": 12,
"summaryFrom": 9,
"stateDigest": "a4abd4cb1cc9ade667c277fb1095641d6135cae0ac2d6ee2905920365f4f56b4",
"stateDigest": "e149c301f382438ee063a38f70dd794207b88e94bdf3c14c5191da0eeaa99bc9",
"sectionDigests": {
"state": "8390f21336885863",
"blockContents": "94a58f96d7c5cfc3",
"stats": "24d705b0e39bd13c",
"metadata": "68d1e5ca212cef7b"
"metadata": "55733fb81ccf7d69"
},
"stateKeyDigests": {
"blocks": "d9770feee91dafc6",
Expand All @@ -98,6 +98,7 @@
"lastPassIds": "d18ace2914339891",
"hiddenOrphanRefs": "4f53cda18c2baa0c",
"deadRefs": "74234e98afe7498f",
"refLedgerAligned": "74234e98afe7498f",
"terminalStreak": "5feceb66ffc86f38",
"nextRuleId": "6b86b273ff34fce1",
"absorbed": "4f53cda18c2baa0c",
Expand Down
5 changes: 3 additions & 2 deletions tests/golden/storage-render/google.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
"foldAt": 9,
"editedAt": 12,
"summaryFrom": 9,
"stateDigest": "9ad5cff9d94aa21024b20aa870e94cd0a62c9dedc452ad7e76d8821a3635f30a",
"stateDigest": "80e83935e5fa7b052a3cb0f1d641bd81cb6ee59f91f3c1f2f31c204de29368a5",
"sectionDigests": {
"state": "2e1def3a3234afdc",
"blockContents": "473264d9df8ba338",
"stats": "900481685c848462",
"metadata": "2f0093fdaa6fb5a7"
"metadata": "88cd02a467b4457e"
},
"stateKeyDigests": {
"blocks": "0cfd0b9c0fc53073",
Expand All @@ -98,6 +98,7 @@
"lastPassIds": "1e3edaf045fbb7d1",
"hiddenOrphanRefs": "4f53cda18c2baa0c",
"deadRefs": "74234e98afe7498f",
"refLedgerAligned": "74234e98afe7498f",
"terminalStreak": "5feceb66ffc86f38",
"nextRuleId": "6b86b273ff34fce1",
"absorbed": "4f53cda18c2baa0c",
Expand Down
5 changes: 3 additions & 2 deletions tests/golden/storage-render/responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
"foldAt": 9,
"editedAt": 12,
"summaryFrom": 9,
"stateDigest": "f1c5b00ba772868d48c8addcb150a54908eb308f9bd3a4fd46d7a79084effdbc",
"stateDigest": "08526d3552fca7ac7552cd16a221893a652fbe740c9b8dccac6db57b3d6302ee",
"sectionDigests": {
"state": "db313e8eba2d65fc",
"blockContents": "b6701268a0bdcd8a",
"stats": "327d3967b8371aa8",
"metadata": "e4cac45276f335cc"
"metadata": "b5c39d84db67f424"
},
"stateKeyDigests": {
"blocks": "34b0dc17f8c24595",
Expand All @@ -98,6 +98,7 @@
"lastPassIds": "de5c5da67428b09f",
"hiddenOrphanRefs": "4f53cda18c2baa0c",
"deadRefs": "74234e98afe7498f",
"refLedgerAligned": "74234e98afe7498f",
"terminalStreak": "5feceb66ffc86f38",
"nextRuleId": "6b86b273ff34fce1",
"absorbed": "4f53cda18c2baa0c",
Expand Down
5 changes: 4 additions & 1 deletion tests/snapshot-render-chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ let nextSessionId = 0;

/** Install a fabricated unified-store tail view and render `client` through it. */
function render(blocks: BlockLike[], client: BiliMessage[], rows: BiliMessage[]): { session: Session; view: BiliMessage[] } {
const rawRows = rows.map((m, i) => ({ seq: i + 1, content: JSON.stringify(m) }));
const rawRows = rows.map((m, i) => ({ seq: i + 1, msgId: m.id, content: JSON.stringify(m) }));
const inWindow = (seq: number, intervals: readonly [number, number][]) => intervals.some(([a, b]) => seq >= a && seq <= b);
const fake = {
unifiedTailSeqs: () => rawRows.map((r) => r.seq),
unifiedTailViewRows: () => rawRows,
unifiedMessageIdRows: () => rawRows.map(({ seq, msgId }) => ({ seq, msgId })),
unifiedUncoveredRows: (_id: string, intervals: readonly [number, number][]) => rawRows.filter((r) => !inWindow(r.seq, intervals)),
};
_setStoreForTest(fake as unknown as SessionStore);
nextSessionId++;
Expand Down
Loading
Loading