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
2 changes: 1 addition & 1 deletion .agents/plugins/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"plugins": [
{
"name": "billion-context",
"version": "0.1.214",
"version": "0.1.215",
"source": {
"source": "local",
"path": "./plugins/codex"
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"name": "billion-context",
"source": "./",
"description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens",
"version": "0.1.214",
"version": "0.1.215",
"author": {
"name": "ranxianglei"
},
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billion-context",
"version": "0.1.214",
"version": "0.1.215",
"description": "Context-compression plugin for Claude Code · month-long single sessions (billions of tokens) · high compression quality even in small context windows (100K is enough) · 5× fewer tokens",
"author": {
"name": "ranxianglei"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billion-context",
"version": "0.1.214",
"version": "0.1.215",
"description": "A context-compression plugin \u2014 small context windows (a 100K context is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and compression quality \u2014 for all agents: pi, OpenCode, Codex, Claude Code, and more. billion-context is all you need.",
"type": "module",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion plugins/codex/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "billion-context",
"version": "0.1.214",
"version": "0.1.215",
"description": "Context-compression plugin for Codex — small context windows (100K is enough), 5x fewer tokens, month-long single sessions (billions of tokens), and high compression quality.",
"author": {
"name": "ranxianglei"
Expand Down
14 changes: 9 additions & 5 deletions src/paths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, readdirSync } from "node:fs";
import { existsSync, readdirSync, statSync } from "node:fs";
import { homedir } from "node:os";
import path from "node:path";

Expand Down Expand Up @@ -30,24 +30,28 @@ export function configDir(): string {
}

/** Resolve a config ref (BILI_CONFIG_FILE / -c/--config value): a path
* (contains a separator, or names an existing file in CWD) stays a path;
* (contains a separator, or names an existing FILE in CWD — a directory is
* never a valid config file) stays a path;
* a bare NAME selects <configDir>/NAME.json — "billion-context" is the
* default file itself, so per-purpose siblings ("dsh-test", "ework-qq")
* switch the whole config without touching env vars. */
export function resolveConfigFileRef(ref: string): string {
if (ref.includes("/") || ref.includes("\\") || existsSync(ref)) return path.resolve(ref);
if (ref.includes("/") || ref.includes("\\") || statSync(ref, { throwIfNoEntry: false })?.isFile()) return path.resolve(ref);
return path.join(configDir(), `${ref}.json`);
}

/** Fail-fast check for a -c/--config ref (keeps main() exit-free for tests):
* a bare NAME (no separator, no CWD file) whose <configDir>/NAME.json is
* missing is an error — the message names the resolved path plus every
* available sibling so a typo can't silently start the proxy on an empty
* config. Explicit PATHS (and refs naming an existing CWD file) keep their
* config. Explicit PATHS (and refs naming an existing CWD FILE — statSync:
* a directory is NOT a file, so a CWD directory named like a bare config
* name falls through to named resolution and fails fast instead of booting
* with a default config via EISDIR) keep their
* historical missing→empty behavior and return null. */
export function checkNamedConfigRef(ref: string): string | null {
if (!ref || ref.trim().length === 0) return null;
if (ref.includes("/") || ref.includes("\\") || existsSync(ref)) return null;
if (ref.includes("/") || ref.includes("\\") || statSync(ref, { throwIfNoEntry: false })?.isFile()) return null;
const dir = configDir();
if (existsSync(path.join(dir, `${ref}.json`))) return null;
let names: string[] = [];
Expand Down
24 changes: 22 additions & 2 deletions src/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3296,7 +3296,13 @@ export class SessionStore {
// anything (the content-store re-key happens inside and must land in
// the same write). Cold-load alignment retired: see loadSync note.
this.consumePendingLedgerAlign(session);
if (!this.saveContentStore(session)) return;
if (!this.saveContentStore(session)) {
// #6793-review: this save will not run — drop the #6780 arm so it
// cannot pin this session's lastMessages + metadata fingerprint
// in memory forever (leak on eviction).
this.durabilityArms.delete(session.id);
return;
}
if (this.writerOffActive() || this.envelopeFrozen(session.id)) {
if (this.envelopeFrozen(session.id)) this.noteFrozenSkip(session.id, "scheduled");
// Phase 3 (#2960): index-only persistence — the builder closure
Expand Down Expand Up @@ -3381,6 +3387,12 @@ export class SessionStore {
});
return;
}
// #6793-review: the durability arm is only consulted by the writer-off
// coalesced run above. The debounced path always builds the full record
// and never reads the arm — clear it here, otherwise an armed-but-
// debounced save (JSON-writer process) leaks one arm (pinning
// lastMessages + a metadata snapshot) per evicted session.
this.durabilityArms.delete(session.id);
if (!this.enabled) return;
this.tryRecoverSidecar(); // #5188: dirty activity is the "still wanted" signal for a lost sidecar
const id = session.id;
Expand Down Expand Up @@ -3577,7 +3589,12 @@ export class SessionStore {
* either. Do NOT regress this by eager-snapshotting the record here. */
async writeNow(session: Session): Promise<void> {
this.consumePendingLedgerAlign(session); // #5608-D: before any serialization
if (!this.saveContentStore(session)) throw new Error(`Originals were not saved for ${session.id}`);
if (!this.saveContentStore(session)) {
// #6793-review: see scheduleSave — the arm is useless without a
// writer-off coalesced run; clear it before propagating.
this.durabilityArms.delete(session.id);
throw new Error(`Originals were not saved for ${session.id}`);
}
if (this.writerOffActive() || this.envelopeFrozen(session.id)) {
if (this.envelopeFrozen(session.id)) this.noteFrozenSkip(session.id, "writeNow");
// #3133: drop the armed microtask (token mismatch below) — this
Expand All @@ -3595,6 +3612,9 @@ export class SessionStore {
this.dropResidentContentStore(session);
return;
}
// #6793-review: full-build path (store.writeNow) never consults the
// durability arm — clear it so it cannot pin state after eviction.
this.durabilityArms.delete(session.id);
const proofRevision = session.revisionEpoch; // #4788 D2: capture BEFORE the chain builds
this.saveWritesInFlight.add(session.id);
const rec: { v: PersistedSession | null } = { v: null };
Expand Down
21 changes: 21 additions & 0 deletions tests/config-named-ref.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ test("checkNamedConfigRef: missing name fails with the sibling list (gate off)",
assert.ok(!(err as string).includes("summary-credentials"), "auxiliary *.json.*.json sidecars are not named configs");
});

test("a CWD DIRECTORY named like a bare ref is not a config file (PR#6793 review M1)", () => {
// A directory in the CWD with the same name as a bare ref must not shadow
// named-config resolution: existsSync(dir)===true used to keep the ref a
// "path", and readFileSync(dir) then threw EISDIR, so the proxy booted on
// the DEFAULT config, silently defeating the fail-fast gate.
const cwdDir = path.join(process.cwd(), "dsh-test");
fs.mkdirSync(cwdDir, { recursive: true });
try {
assert.equal(resolveConfigFileRef("dsh-test"), path.join(configDir, "dsh-test.json"));
assert.equal(checkNamedConfigRef("dsh-test"), null, "real named config in configDir still passes");
fs.rmSync(path.join(configDir, "dsh-test.json"), { force: true });
try {
assert.ok(checkNamedConfigRef("dsh-test"), "a shadowing directory must not satisfy the gate");
} finally {
fs.writeFileSync(path.join(configDir, "dsh-test.json"), "{}");
}
} finally {
fs.rmdirSync(cwdDir);
}
});

test("checkNamedConfigRef: paths and empty refs keep historical behavior (null)", () => {
assert.equal(checkNamedConfigRef(""), null);
assert.equal(checkNamedConfigRef(" "), null);
Expand Down
Loading