@fabersep/cache 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/LICENSE +202 -0
- package/README.md +182 -2
- package/data/measured-modes.json +94 -0
- package/dist/src/cli.d.ts +3 -0
- package/dist/src/cli.js +229 -0
- package/dist/src/config.d.ts +56 -0
- package/dist/src/config.js +92 -0
- package/dist/src/core.d.ts +122 -0
- package/dist/src/core.js +538 -0
- package/dist/src/cost.d.ts +25 -0
- package/dist/src/cost.js +39 -0
- package/dist/src/doctor.d.ts +26 -0
- package/dist/src/doctor.js +84 -0
- package/dist/src/engines/agy.d.ts +17 -0
- package/dist/src/engines/agy.js +175 -0
- package/dist/src/engines/claude.d.ts +67 -0
- package/dist/src/engines/claude.js +275 -0
- package/dist/src/hygiene.d.ts +8 -0
- package/dist/src/hygiene.js +84 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +8 -0
- package/dist/src/key.d.ts +16 -0
- package/dist/src/key.js +7 -0
- package/dist/src/lock.d.ts +9 -0
- package/dist/src/lock.js +92 -0
- package/dist/src/mcp.d.ts +126 -0
- package/dist/src/mcp.js +194 -0
- package/dist/src/measured.d.ts +48 -0
- package/dist/src/measured.js +50 -0
- package/dist/src/packet.d.ts +29 -0
- package/dist/src/packet.js +64 -0
- package/dist/src/records.d.ts +49 -0
- package/dist/src/records.js +35 -0
- package/dist/src/registry.d.ts +42 -0
- package/dist/src/registry.js +69 -0
- package/dist/src/stats.d.ts +31 -0
- package/dist/src/stats.js +91 -0
- package/dist/src/version.d.ts +2 -0
- package/dist/src/version.js +22 -0
- package/package.json +51 -4
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { DEFAULT_PACKET, expandHome, projectConfig } from './config.js';
|
|
5
|
+
import { scanHygiene } from './hygiene.js';
|
|
6
|
+
export const READY_LINE = 'Reply with the single word: ready';
|
|
7
|
+
export class PacketError extends Error {
|
|
8
|
+
details;
|
|
9
|
+
constructor(message, details = []) {
|
|
10
|
+
super(details.length ? `${message}\n${details.map((d) => ` ${d}`).join('\n')}` : message);
|
|
11
|
+
this.details = details;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function sha256(text) {
|
|
15
|
+
return crypto.createHash('sha256').update(text).digest('hex');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The project's packet: its files in order (FR-01.1), refused when over the size limit or when a
|
|
19
|
+
* file holds a secret or a machine path (FR-01.5, FR-10.1). Nothing is sent before this passes.
|
|
20
|
+
*/
|
|
21
|
+
export function buildPacket(config, projectDir) {
|
|
22
|
+
const configured = projectConfig(config, projectDir).packet;
|
|
23
|
+
const names = configured ?? DEFAULT_PACKET;
|
|
24
|
+
const files = [];
|
|
25
|
+
for (const label of names) {
|
|
26
|
+
const full = path.resolve(projectDir, expandHome(label));
|
|
27
|
+
let content;
|
|
28
|
+
try {
|
|
29
|
+
content = fs.readFileSync(full, 'utf8');
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
if (configured)
|
|
33
|
+
throw new PacketError(`packet file not found: ${label}`);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
files.push({ label, bytes: Buffer.byteLength(content), sha: sha256(content), content });
|
|
37
|
+
}
|
|
38
|
+
if (files.length === 0)
|
|
39
|
+
throw new PacketError('the packet is empty: no packet file was found');
|
|
40
|
+
const bytes = files.reduce((n, f) => n + f.bytes, 0);
|
|
41
|
+
if (bytes > config.limits.maxPacketBytes) {
|
|
42
|
+
throw new PacketError(`packet is ${bytes} bytes, over the limit of ${config.limits.maxPacketBytes}`, files.map((f) => `${f.label}: ${f.bytes} bytes`));
|
|
43
|
+
}
|
|
44
|
+
const findings = [];
|
|
45
|
+
for (const f of files) {
|
|
46
|
+
for (const h of scanHygiene(f.content))
|
|
47
|
+
findings.push(formatFinding(f.label, h));
|
|
48
|
+
}
|
|
49
|
+
if (findings.length)
|
|
50
|
+
throw new PacketError('packet refused by the secret and machine-path scan', findings);
|
|
51
|
+
const text = files.map((f) => `===== ${f.label} =====\n${f.content.trimEnd()}\n`).join('\n');
|
|
52
|
+
return { files, text, bytes };
|
|
53
|
+
}
|
|
54
|
+
function formatFinding(label, h) {
|
|
55
|
+
return `${label} line ${h.line} [${h.category}/${h.pattern}]: ${h.redactedSnippet}`;
|
|
56
|
+
}
|
|
57
|
+
/** The base's first message: the packet, then the fixed ready line. */
|
|
58
|
+
export function baseMessage(packet) {
|
|
59
|
+
return `${packet.text}\n${READY_LINE}`;
|
|
60
|
+
}
|
|
61
|
+
/** A run with no base: the packet in front of the task, in one message. */
|
|
62
|
+
export function packetInFront(packet, task) {
|
|
63
|
+
return `${packet.text}\n${task}`;
|
|
64
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type RecordKind = 'build' | 'warmup' | 'run' | 'open';
|
|
2
|
+
export interface Usage {
|
|
3
|
+
input: number;
|
|
4
|
+
cacheWrite: number;
|
|
5
|
+
/** The part of cacheWrite written with the one-hour lifetime, when the engine says. */
|
|
6
|
+
cacheWrite1h?: number;
|
|
7
|
+
cacheRead: number;
|
|
8
|
+
output: number;
|
|
9
|
+
}
|
|
10
|
+
/** One JSON line per build, warm-up, run and open (FR-09.1). */
|
|
11
|
+
export interface RunRecord {
|
|
12
|
+
at: string;
|
|
13
|
+
kind: RecordKind;
|
|
14
|
+
project: string;
|
|
15
|
+
profile: string;
|
|
16
|
+
mode: string;
|
|
17
|
+
engine: string;
|
|
18
|
+
engineVersion: string;
|
|
19
|
+
model: string;
|
|
20
|
+
/** The tool set the run had (`all` for the engine's default). */
|
|
21
|
+
tools: string;
|
|
22
|
+
key: string;
|
|
23
|
+
/** Session forked from (base or warm), when any. */
|
|
24
|
+
fromSession: string | null;
|
|
25
|
+
session: string | null;
|
|
26
|
+
/** with-base | no-base | lock-timeout | warmup-failed (for runs). */
|
|
27
|
+
base: string;
|
|
28
|
+
first: Usage | null;
|
|
29
|
+
total: Usage | null;
|
|
30
|
+
refPrefix: number | null;
|
|
31
|
+
readShare: number | null;
|
|
32
|
+
/**
|
|
33
|
+
* The run's cost as the engine reports it (US dollars). Kept only for runs that resume nothing
|
|
34
|
+
* (builds, runs with no base): Claude Code adds the parent session's cost to a fork's total.
|
|
35
|
+
*/
|
|
36
|
+
costUsd?: number | null;
|
|
37
|
+
/** The fork's own tokens: input + cache write of its first request (FR-09.5). */
|
|
38
|
+
ownTokens: number | null;
|
|
39
|
+
cacheMiss: boolean;
|
|
40
|
+
outcome: 'ok' | 'error' | 'stopped';
|
|
41
|
+
error?: string;
|
|
42
|
+
attempt?: number;
|
|
43
|
+
task?: string;
|
|
44
|
+
unverified?: boolean;
|
|
45
|
+
note?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function recordsDir(home: string): string;
|
|
48
|
+
export declare function appendRecord(home: string, rec: RunRecord): void;
|
|
49
|
+
export declare function readRecords(home: string): RunRecord[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
export function recordsDir(home) {
|
|
4
|
+
return path.join(home, 'records');
|
|
5
|
+
}
|
|
6
|
+
export function appendRecord(home, rec) {
|
|
7
|
+
const dir = recordsDir(home);
|
|
8
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
9
|
+
const file = path.join(dir, `${rec.at.slice(0, 7)}.jsonl`);
|
|
10
|
+
fs.appendFileSync(file, JSON.stringify(rec) + '\n');
|
|
11
|
+
}
|
|
12
|
+
export function readRecords(home) {
|
|
13
|
+
const dir = recordsDir(home);
|
|
14
|
+
let names = [];
|
|
15
|
+
try {
|
|
16
|
+
names = fs.readdirSync(dir).filter((n) => n.endsWith('.jsonl')).sort();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const n of names) {
|
|
23
|
+
for (const line of fs.readFileSync(path.join(dir, n), 'utf8').split('\n')) {
|
|
24
|
+
if (!line.trim())
|
|
25
|
+
continue;
|
|
26
|
+
try {
|
|
27
|
+
out.push(JSON.parse(line));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// A torn line is skipped.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface BaseEntry {
|
|
2
|
+
key: string;
|
|
3
|
+
project: string;
|
|
4
|
+
profile: string;
|
|
5
|
+
mode: string;
|
|
6
|
+
engine: string;
|
|
7
|
+
engineVersion: string;
|
|
8
|
+
model: string;
|
|
9
|
+
baseSession: string;
|
|
10
|
+
/** The session tasks fork: the warm-up when the mode needs one, else null (fork the base). */
|
|
11
|
+
warmSession: string | null;
|
|
12
|
+
created: number;
|
|
13
|
+
lastRead: number;
|
|
14
|
+
uses: number;
|
|
15
|
+
/** The reference first-request prefix for the read share (FR-09.2). */
|
|
16
|
+
refPrefix: number;
|
|
17
|
+
/** What the key was made of, for `doctor` (FR-09.4). */
|
|
18
|
+
parts: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
interface RegistryFile {
|
|
21
|
+
bases: Record<string, BaseEntry>;
|
|
22
|
+
/** First no-base call per key, for the second-call rule (FR-04.4). */
|
|
23
|
+
seen: Record<string, number>;
|
|
24
|
+
}
|
|
25
|
+
/** The host-local registry (FR-03.1), written atomically under its own lock. */
|
|
26
|
+
export declare class Registry {
|
|
27
|
+
readonly home: string;
|
|
28
|
+
readonly file: string;
|
|
29
|
+
readonly lockFile: string;
|
|
30
|
+
constructor(home: string);
|
|
31
|
+
keyLock(key: string): string;
|
|
32
|
+
load(): RegistryFile;
|
|
33
|
+
get(key: string): BaseEntry | undefined;
|
|
34
|
+
private update;
|
|
35
|
+
put(entry: BaseEntry): void;
|
|
36
|
+
touch(key: string, now: number, used?: boolean): void;
|
|
37
|
+
/** Replace an entry the engine can no longer resume; the next build overwrites it. */
|
|
38
|
+
forget(key: string): void;
|
|
39
|
+
markSeen(key: string, now: number): void;
|
|
40
|
+
seenAt(key: string): number | undefined;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { withLockSync } from './lock.js';
|
|
4
|
+
/** The host-local registry (FR-03.1), written atomically under its own lock. */
|
|
5
|
+
export class Registry {
|
|
6
|
+
home;
|
|
7
|
+
file;
|
|
8
|
+
lockFile;
|
|
9
|
+
constructor(home) {
|
|
10
|
+
this.home = home;
|
|
11
|
+
this.file = path.join(home, 'registry.json');
|
|
12
|
+
this.lockFile = path.join(home, 'locks', 'registry.lock');
|
|
13
|
+
}
|
|
14
|
+
keyLock(key) {
|
|
15
|
+
return path.join(this.home, 'locks', `${key}.lock`);
|
|
16
|
+
}
|
|
17
|
+
load() {
|
|
18
|
+
try {
|
|
19
|
+
const raw = JSON.parse(fs.readFileSync(this.file, 'utf8'));
|
|
20
|
+
return { bases: raw.bases ?? {}, seen: raw.seen ?? {} };
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return { bases: {}, seen: {} };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
get(key) {
|
|
27
|
+
return this.load().bases[key];
|
|
28
|
+
}
|
|
29
|
+
update(change) {
|
|
30
|
+
withLockSync(this.lockFile, () => {
|
|
31
|
+
const data = this.load();
|
|
32
|
+
change(data);
|
|
33
|
+
fs.mkdirSync(this.home, { recursive: true });
|
|
34
|
+
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
35
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 1) + '\n');
|
|
36
|
+
fs.renameSync(tmp, this.file);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
put(entry) {
|
|
40
|
+
this.update((d) => {
|
|
41
|
+
d.bases[entry.key] = entry;
|
|
42
|
+
delete d.seen[entry.key];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
touch(key, now, used = true) {
|
|
46
|
+
this.update((d) => {
|
|
47
|
+
const e = d.bases[key];
|
|
48
|
+
if (!e)
|
|
49
|
+
return;
|
|
50
|
+
e.lastRead = now;
|
|
51
|
+
if (used)
|
|
52
|
+
e.uses += 1;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Replace an entry the engine can no longer resume; the next build overwrites it. */
|
|
56
|
+
forget(key) {
|
|
57
|
+
this.update((d) => {
|
|
58
|
+
delete d.bases[key];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
markSeen(key, now) {
|
|
62
|
+
this.update((d) => {
|
|
63
|
+
d.seen[key] = now;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
seenAt(key) {
|
|
67
|
+
return this.load().seen[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface StatsRow {
|
|
2
|
+
project: string;
|
|
3
|
+
profile: string;
|
|
4
|
+
engine: string;
|
|
5
|
+
mode: string;
|
|
6
|
+
runs: number;
|
|
7
|
+
runsWithBase: number;
|
|
8
|
+
meanReadShare: number | null;
|
|
9
|
+
underBar: number;
|
|
10
|
+
builds: number;
|
|
11
|
+
buildCacheWrite: number;
|
|
12
|
+
warmups: number;
|
|
13
|
+
warmupCacheWrite: number;
|
|
14
|
+
/** Stable-part tokens read from cache instead of sent fresh (FR-09.3). */
|
|
15
|
+
savedTokens: number;
|
|
16
|
+
/** What the group cost, in input-token equivalents: builds, warm-ups and runs. */
|
|
17
|
+
paidEquivalents: number;
|
|
18
|
+
/** Conservative saving against sending the context fresh to every run, net of builds and warm-ups. */
|
|
19
|
+
savedEquivalents: number;
|
|
20
|
+
/** savedEquivalents / (paid + saved); null with no fork. */
|
|
21
|
+
savedShare: number | null;
|
|
22
|
+
/** Dollars, priced from the engine's own cost of the runs that resume nothing; null when unknown. */
|
|
23
|
+
paidUsd: number | null;
|
|
24
|
+
savedUsd: number | null;
|
|
25
|
+
}
|
|
26
|
+
export declare function computeStats(home: string, opts?: {
|
|
27
|
+
project?: string;
|
|
28
|
+
since?: string;
|
|
29
|
+
}): StatsRow[];
|
|
30
|
+
/** The plain-language stats block for one project, profile, engine and mode. */
|
|
31
|
+
export declare function formatStatsRow(r: StatsRow): string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { readRecords } from './records.js';
|
|
2
|
+
import { resolveProject } from './config.js';
|
|
3
|
+
import { forkSaving, inputEquivalents, usdPerEquivalent } from './cost.js';
|
|
4
|
+
export function computeStats(home, opts = {}) {
|
|
5
|
+
const project = opts.project ? resolveProject(opts.project) : undefined;
|
|
6
|
+
const since = opts.since ? Date.parse(opts.since) : undefined;
|
|
7
|
+
if (opts.since && Number.isNaN(since))
|
|
8
|
+
throw new Error(`--since: not a date: ${opts.since}`);
|
|
9
|
+
const groups = new Map();
|
|
10
|
+
for (const r of readRecords(home)) {
|
|
11
|
+
if (project && r.project !== project)
|
|
12
|
+
continue;
|
|
13
|
+
if (since !== undefined && Date.parse(r.at) < since)
|
|
14
|
+
continue;
|
|
15
|
+
const g = [r.project, r.profile, r.engine, r.mode].join('\u0000');
|
|
16
|
+
const list = groups.get(g) ?? [];
|
|
17
|
+
list.push(r);
|
|
18
|
+
groups.set(g, list);
|
|
19
|
+
}
|
|
20
|
+
const rows = [];
|
|
21
|
+
for (const list of groups.values()) {
|
|
22
|
+
const runs = list.filter((r) => r.kind === 'run');
|
|
23
|
+
const withBase = runs.filter((r) => (r.base === 'with-base' || r.base === 'prefix') && r.readShare !== null && r.outcome === 'ok');
|
|
24
|
+
const builds = list.filter((r) => r.kind === 'build' && r.outcome === 'ok');
|
|
25
|
+
const warmups = list.filter((r) => r.kind === 'warmup');
|
|
26
|
+
const head = list[0];
|
|
27
|
+
const paid = list.reduce((n, r) => n + inputEquivalents(r.total), 0);
|
|
28
|
+
const overhead = [...builds, ...warmups].reduce((n, r) => n + inputEquivalents(r.total), 0);
|
|
29
|
+
const forks = runs.filter((r) => r.base === 'with-base' && r.outcome === 'ok');
|
|
30
|
+
const saved = forks.length ? forks.reduce((n, r) => n + forkSaving(r), 0) - overhead : 0;
|
|
31
|
+
const rate = usdPerEquivalent(list);
|
|
32
|
+
rows.push({
|
|
33
|
+
project: head.project,
|
|
34
|
+
profile: head.profile,
|
|
35
|
+
engine: head.engine,
|
|
36
|
+
mode: head.mode,
|
|
37
|
+
runs: runs.length,
|
|
38
|
+
runsWithBase: withBase.length,
|
|
39
|
+
meanReadShare: withBase.length ? round3(withBase.reduce((n, r) => n + (r.readShare ?? 0), 0) / withBase.length) : null,
|
|
40
|
+
underBar: runs.filter((r) => r.cacheMiss).length,
|
|
41
|
+
builds: builds.length,
|
|
42
|
+
buildCacheWrite: builds.reduce((n, r) => n + (r.first?.cacheWrite ?? 0), 0),
|
|
43
|
+
warmups: warmups.length,
|
|
44
|
+
warmupCacheWrite: warmups.reduce((n, r) => n + (r.first?.cacheWrite ?? 0), 0),
|
|
45
|
+
savedTokens: withBase.reduce((n, r) => n + (r.first?.cacheRead ?? 0), 0),
|
|
46
|
+
paidEquivalents: Math.round(paid),
|
|
47
|
+
savedEquivalents: Math.round(saved),
|
|
48
|
+
savedShare: forks.length && paid + saved > 0 ? round3(saved / (paid + saved)) : null,
|
|
49
|
+
paidUsd: rate === null ? null : round4(paid * rate),
|
|
50
|
+
savedUsd: rate === null || !forks.length ? null : round4(saved * rate),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return rows.sort((a, b) => a.project.localeCompare(b.project) || a.profile.localeCompare(b.profile));
|
|
54
|
+
}
|
|
55
|
+
function round3(x) {
|
|
56
|
+
return Math.round(x * 1000) / 1000;
|
|
57
|
+
}
|
|
58
|
+
function round4(x) {
|
|
59
|
+
return Math.round(x * 10000) / 10000;
|
|
60
|
+
}
|
|
61
|
+
function plural(n, word) {
|
|
62
|
+
return `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
63
|
+
}
|
|
64
|
+
function short(n) {
|
|
65
|
+
return n >= 10_000 ? `${Math.round(n / 1000)}K` : String(Math.round(n));
|
|
66
|
+
}
|
|
67
|
+
function dollars(n) {
|
|
68
|
+
return `$${n.toFixed(Math.abs(n) < 1 ? 4 : 2)}`;
|
|
69
|
+
}
|
|
70
|
+
/** The plain-language stats block for one project, profile, engine and mode. */
|
|
71
|
+
export function formatStatsRow(r) {
|
|
72
|
+
const share = r.meanReadShare === null ? 'n/a' : `${Math.round(r.meanReadShare * 100)}%`;
|
|
73
|
+
const lines = [
|
|
74
|
+
`${r.project} (${r.engine}, ${r.mode} mode, ${r.profile} profile)`,
|
|
75
|
+
` runs: ${r.runs}, ${r.runsWithBase} of them started from the warm base; ${plural(r.builds, 'base build')}, ${plural(r.warmups, 'warm-up')}`,
|
|
76
|
+
` cache: on average a run read ${share} of its project context from cache` +
|
|
77
|
+
(r.underBar ? `; ${r.underBar} read less than expected (faber-cache doctor says why)` : ''),
|
|
78
|
+
];
|
|
79
|
+
const paid = r.paidUsd === null ? `${short(r.paidEquivalents)} input-token equivalents` : dollars(r.paidUsd);
|
|
80
|
+
if (r.savedShare === null) {
|
|
81
|
+
lines.push(` cost: paid ${paid}; no run has started from a base yet, so nothing saved`);
|
|
82
|
+
}
|
|
83
|
+
else if (r.savedEquivalents <= 0) {
|
|
84
|
+
lines.push(` cost: paid ${paid}; too few runs per base so far to pay back building it`);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const saved = r.savedUsd === null ? `${short(r.savedEquivalents)} input-token equivalents` : dollars(r.savedUsd);
|
|
88
|
+
lines.push(` saved: at least ${saved} (${Math.round(r.savedShare * 100)}%) against sending the context fresh to every run; paid ${paid}`);
|
|
89
|
+
}
|
|
90
|
+
return lines.join('\n');
|
|
91
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
let cached;
|
|
5
|
+
/** The installed package version, read from package.json (dist/src/ -> ../../package.json). */
|
|
6
|
+
export function getPackageVersion() {
|
|
7
|
+
if (cached)
|
|
8
|
+
return cached;
|
|
9
|
+
try {
|
|
10
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const raw = JSON.parse(fs.readFileSync(path.resolve(here, '../../package.json'), 'utf8'));
|
|
12
|
+
if (typeof raw.version === 'string' && raw.version.trim()) {
|
|
13
|
+
cached = raw.version.trim();
|
|
14
|
+
return cached;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Fallback below
|
|
19
|
+
}
|
|
20
|
+
cached = '0.0.0';
|
|
21
|
+
return cached;
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabersep/cache",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Pay for your project's context once, not once per Claude Code session: a warm base session and a fork per task.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/fabersep/cache.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/fabersep/cache#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/fabersep/cache/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"fabersep",
|
|
17
|
+
"ai-agents",
|
|
18
|
+
"prompt-caching",
|
|
19
|
+
"claude-code",
|
|
20
|
+
"mcp",
|
|
21
|
+
"fork"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bin": {
|
|
25
|
+
"faber-cache": "dist/src/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./dist/src/index.js"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist/src",
|
|
32
|
+
"data",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"README.md",
|
|
35
|
+
"CHANGELOG.md"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.json",
|
|
45
|
+
"prepublishOnly": "npm run build",
|
|
46
|
+
"test": "npm run build && node --test dist/test/*.test.js",
|
|
47
|
+
"bench": "npm run build && node bench/ab.mjs"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^22.10.2",
|
|
51
|
+
"typescript": "^5.8.3"
|
|
52
|
+
}
|
|
53
|
+
}
|