@parcha/agentrun-import 0.1.0-beta.60 → 0.1.0-beta.62

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/README.md CHANGED
@@ -85,6 +85,61 @@ a bundle (`bun build --compile`) carries it, prints the same bytes as under Node
85
85
  fails instead of pricing nothing. pi-ai is a dependency of the package, so `npx @parcha/agentrun-import` runs the
86
86
  CLI as it is; the library loads it only to price.
87
87
 
88
+ ## Cache breaks
89
+
90
+ ```js
91
+ import { analyzeCache, cacheHome, readSession } from "@parcha/agentrun-import";
92
+
93
+ const session = await readSession(file, "claude-code", { chain: true });
94
+ const { hitRate, breaks } = await analyzeCache(session);
95
+ // breaks: [{ turn, at, dropPct, rewritten, extraCost, cause, diverged? }]
96
+ ```
97
+
98
+ - `hitRate` is the cache read over the whole prompt (`input + cacheRead + cacheWrite`, input already uncached), null for a
99
+ session that sent none.
100
+ - A break is a turn whose cache read dropped more than 80% (`BREAK_DROP`) against the turn before it; the first turn is
101
+ never one, and a drop of exactly 80% is none. A turn compared is a request with usage that sent a prompt. `turn`
102
+ counts the session's requests from 1; `at` is ms since the epoch; `dropPct` the share of the turn before's read lost.
103
+ - `rewritten`: of the read lost, the tokens the turn paid for again, as a cache write or as uncached input. `extraCost`:
104
+ USD, what the turn paid above reading them from the cache, at its model's list prices (pi-ai's catalog, or the
105
+ `catalog` handed in); null when the model is not listed or `catalog: false`.
106
+ - `cause`, the first of `CACHE_CAUSES` the transcript shows evidence of:
107
+
108
+ | Cause | Evidence |
109
+ | --- | --- |
110
+ | `model` | the turn ran on another model than the turn before |
111
+ | `idle` | the gap since the turn before is past the cache's life: 5 minutes, or an hour when the latest cache write was a 1h one (`cacheWrite1h`) |
112
+ | `compaction` | a compaction since the turn before: Claude Code's `compact_boundary` or `isCompactSummary` record, Codex's `compacted`. It counts in the file that holds it first; across a session's files it carries to the next file's first turn, and a later file's copy of it is never consulted |
113
+ | `edited` | the prompt leaves the chain of the turn before (its prompt and answer) at an earlier message: `diverged` is that message's index |
114
+ | `sidechain` | the turn opens a sidechain after a main-chain turn (Claude Code's `isSidechain`) |
115
+ | `unknown` | none of the above: the transcript shows no cause for the drop. That names no cause, the provider's included. A cache evicted early, or a request served where its cache was not, reads this way, and so does an edit the analyzer cannot see: across two of a session's files (their chains are not compared), in a Codex rollout, or in a session read without its chain |
116
+
117
+ `chain: true` keeps the session's `chain` beside its turns: each record's id and its parent's (Claude Code's
118
+ `uuid`/`parentUuid`, pi's `id`/`parentId`), a 16-hex sha256 of its content, never the content, and which record opens
119
+ each request. The analyzer finds an edit by comparing the hashes of the two prompts' message chains from the root. A
120
+ sidechain's prompt is a conversation of its own, never an edit of the main one's. A Codex rollout names no record to
121
+ rewind to, so a Codex break is never `edited`; pi writes no compaction or sidechain record in the sessions seen, so a pi
122
+ break is never `compaction` or `sidechain`. A session read without its chain names `model` and `idle` alone.
123
+
124
+ `cacheHome(home, options)` analyzes every session `parseHome` totals (the same options but `state`), keyed the same way,
125
+ of the sources that write a chain (`CACHE_SOURCES`: Claude Code, Codex and pi; another source is refused with a
126
+ `RangeError`, since OpenCode's claude-agent requests mirror a Claude Code session's and would count twice),
127
+ one file at a time: `hitRate` over the session's requests and its subagents', and its breaks. A session's files (a Codex
128
+ thread that goes on in a new rollout) are one conversation in the import's order: a file's first turn is compared with
129
+ the last turn of the file before it (its model, time and cache life carried over), and turns count on across them. Two
130
+ sessions are never compared. Each subagent is a conversation of its own, its breaks with its `subagent` number: a
131
+ subagent's thread that goes on in a new rollout is one, its files joined the same way.
132
+ `analyzeCache` hands back the `last` turn it compared, for the next file's `before`. `cacheTotals(sessions)` counts the breaks and sums their priced extra cost by
133
+ cause.
134
+
135
+ ```sh
136
+ node dist/cli.js <home> [--sources claude-code,codex,pi] --cache
137
+ ```
138
+
139
+ A JSONL line per session, sorted by key as `--known-answer`'s: `{key, source, hitRate, breaks: [{turn, at, dropPct,
140
+ rewritten, extraCost, cause}]}`, then one line `{totals: {sessions, breaks, extraCost, unpriced}}`. Numbers and cause
141
+ names only.
142
+
88
143
  ## Usage
89
144
 
90
145
  `normalizeUsage(format, raw, options?)` reads one request's usage as `"anthropic"`, `"openai"`, `"pi"`, `"opencode"` or `"copilot"` writes it:
@@ -0,0 +1,114 @@
1
+ import { type ParseOptions } from "./home.js";
2
+ import { type CalculateCost, type Catalog } from "./price.js";
3
+ import { type Locator } from "./reader.js";
4
+ import { type Source } from "./readers/index.js";
5
+ import type { SessionOf, Usage } from "./types.js";
6
+ /** The causes of a break, in the order they are tried: the first the transcript shows evidence of is the break's. */
7
+ export declare const CACHE_CAUSES: readonly ["model", "idle", "compaction", "edited", "sidechain", "unknown"];
8
+ export type CacheCause = (typeof CACHE_CAUSES)[number];
9
+ /** A break is a drop of more than this part of the turn before's cache read. */
10
+ export declare const BREAK_DROP = 0.8;
11
+ /** How long a cache lives unread: 5 minutes, or an hour where it was written for one (Anthropic's 1h cache). */
12
+ export declare const CACHE_TTL_MS: number;
13
+ export declare const CACHE_TTL_LONG_MS: number;
14
+ /** One break. `turn`: the request's number among the session's assistant turns, from 1 (the first is never a break);
15
+ * `at`: its time (ms since the epoch); `dropPct`: how much of the turn before's cache read it lost, in percent;
16
+ * `rewritten`: the tokens of the read lost that it paid for again, as a cache write or uncached input; `extraCost`: USD,
17
+ * what those cost above reading them from the cache, at the request's model's list prices (null when unpriced);
18
+ * `diverged`: for an edit, the index of the first message where its prompt and the turn before's differ. */
19
+ export type CacheBreak = {
20
+ turn: number;
21
+ at: number;
22
+ dropPct: number;
23
+ rewritten: number;
24
+ extraCost: number | null;
25
+ cause: CacheCause;
26
+ diverged?: number;
27
+ };
28
+ /** `hitRate`: the cache read over the whole prompt (input, cache read and write), null for a session that sent none.
29
+ * `last`: the last turn compared, to carry into the session's next file (CacheOptions.before). `compacted`: whether
30
+ * a compaction this file holds first (no copy) comes after that turn (anywhere in the file when it compared none, or
31
+ * after the carried turn). */
32
+ export type CacheReport = {
33
+ hitRate: number | null;
34
+ breaks: CacheBreak[];
35
+ last?: CacheCarry;
36
+ compacted: boolean;
37
+ };
38
+ /** The turn a file of a session ended on, which the session's next file compares its first turn with: its model, its
39
+ * time, its usage, whether the latest cache write by then was a 1h one, and whether a compaction came after it (the
40
+ * evidence is where the compaction was first read; a later file's copy of it is never consulted). */
41
+ export type CacheCarry = {
42
+ model?: string;
43
+ at: number;
44
+ usage: Usage;
45
+ long: boolean;
46
+ compacted?: boolean;
47
+ };
48
+ export type CacheOptions = {
49
+ /** The catalog to price with; false prices none (every extraCost null). Default: pi-ai's. */
50
+ catalog?: Catalog | false;
51
+ /** pi-ai's calculateCost, when the caller imported pi-ai itself; else priceRequests loads it. */
52
+ calculateCost?: CalculateCost;
53
+ /** The last turn of the session's file before this one (CacheReport.last): this file's first turn is compared with
54
+ * it, and its turns are no session's first. Absent for a session's first file. */
55
+ before?: CacheCarry;
56
+ };
57
+ /** A session's cache, from a read with `chain: true` (readSession(locator, source, { chain: true })). A session read
58
+ * without its chain names a model change or an idle gap; its other breaks are unknown. A turn compared is a request with
59
+ * usage that sent a prompt (a request that failed before it sent any, or whose usage is unknown, is passed over); a
60
+ * break compares it with the one before it. */
61
+ export declare function analyzeCache(session: Pick<SessionOf, "turns" | "chain" | "model">, options?: CacheOptions): Promise<CacheReport>;
62
+ /** One session's cache under a home, keyed as parseHome keys its totals (`key`, `file`, `source`, `id`): `hitRate` over
63
+ * its requests and its subagents' (the tokens parseHome totals), and the breaks in each of its files (`turn` counted
64
+ * across them, in the import's order) and in each subagent's, which is a conversation of its own (`subagent`: its
65
+ * number among the session's, from 1; `turn` counted in it). */
66
+ export type SessionCache = {
67
+ key: string;
68
+ file: string;
69
+ source: string;
70
+ id: string;
71
+ hitRate: number | null;
72
+ breaks: (CacheBreak & {
73
+ subagent?: number;
74
+ })[];
75
+ };
76
+ /** The sources whose sessions cacheHome analyzes: those that write each request's chain (ChainRecord). OpenCode's
77
+ * claude-agent requests mirror a Claude Code session's, so its breaks would count twice in cacheTotals. */
78
+ export declare const CACHE_SOURCES: readonly Source[];
79
+ /** Every session of `sources` under `home` with its cache (SessionCache), sorted by key: the sessions parseHome totals,
80
+ * each file read with its chain, and analyzed as it is read (one at a time: a whole home's turns would not fit). Its
81
+ * options are parseHome's but `state`: each call reads every file from its start. A source not in CACHE_SOURCES is
82
+ * refused (RangeError) before any file is read. */
83
+ export declare function cacheHome(home: string, { sources, readers, catalog, calculateCost, env, failures }?: Omit<ParseOptions, "state">): Promise<SessionCache[]>;
84
+ /** One file of a session analyzed alone, both ways (the cache before it written for 5 minutes or for an hour, `long`):
85
+ * which holds is known once the session's files before it are joined (sessionBreaks). With its first turn compared and
86
+ * the chain up to it (`head`), to compare with the last turn of the file before; `skipped`, the turns before that one. */
87
+ export type FileCache = {
88
+ alone: CacheReport;
89
+ long: CacheReport;
90
+ head?: Pick<SessionOf, "turns" | "chain" | "model">;
91
+ skipped: number;
92
+ };
93
+ /** `session` (one file's read, with its chain) as sessionBreaks joins it. */
94
+ export declare function fileCache(session: Pick<SessionOf, "turns" | "chain" | "model">, options?: Omit<CacheOptions, "before">): Promise<FileCache>;
95
+ /** A file of a conversation as sessionBreaks joins it: its FileCache (none for a file not read) and its requests. */
96
+ export type JoinedFile = {
97
+ file: FileCache | undefined;
98
+ requests: number;
99
+ };
100
+ /** A session's breaks: its own files (`parts`), one conversation, then each subagent's (`subagents`: each one's files,
101
+ * conversationOf's groups, in the import's order), its breaks with its `subagent` number from 1. */
102
+ export declare function sessionBreaks(parts: readonly JoinedFile[], subagents: readonly (readonly JoinedFile[])[], options?: Omit<CacheOptions, "before">): Promise<SessionCache["breaks"]>;
103
+ /** Which conversation a subagent's file holds, as a key: a thread naming its parent (a Codex subagent) is its thread, in
104
+ * however many rollouts; any other file (a Claude Code subagent's, whose name a workflow's may share a folder deeper) is
105
+ * its own. */
106
+ export declare const conversationOf: (locator: Locator, session: Pick<SessionOf, "id" | "child" | "parent">) => string;
107
+ /** The breaks of `sessions` by cause, each cause there with 0 where none: how many, and their extra cost (USD, of the
108
+ * priced ones); `unpriced`, the breaks whose extra cost is unknown. */
109
+ export declare function cacheTotals(sessions: readonly Pick<SessionCache, "breaks">[]): {
110
+ sessions: number;
111
+ breaks: Record<CacheCause, number>;
112
+ extraCost: Record<CacheCause, number>;
113
+ unpriced: number;
114
+ };
package/dist/cache.js ADDED
@@ -0,0 +1,272 @@
1
+ // The cache analyzer: a session's cache hit rate, and each turn whose cache read dropped more than 80% against the turn
2
+ // before it (a break), with the tokens it paid for again, what that cost, and the cause its transcript shows. It reads
3
+ // the session's chain (ChainRecord: ids, parents and hashes, never text), so it hands back numbers and cause names only.
4
+ import { groupsOf, keyOf, ReadFailures, readSource, requestsIn, requestsOf } from "./home.js";
5
+ import { builtinCatalog, priceRequests } from "./price.js";
6
+ import { locatorKey } from "./reader.js";
7
+ import { READERS } from "./readers/index.js";
8
+ /** The causes of a break, in the order they are tried: the first the transcript shows evidence of is the break's. */
9
+ export const CACHE_CAUSES = ["model", "idle", "compaction", "edited", "sidechain", "unknown"];
10
+ /** A break is a drop of more than this part of the turn before's cache read. */
11
+ export const BREAK_DROP = 0.8;
12
+ /** How long a cache lives unread: 5 minutes, or an hour where it was written for one (Anthropic's 1h cache). */
13
+ export const CACHE_TTL_MS = 5 * 60_000;
14
+ export const CACHE_TTL_LONG_MS = 60 * 60_000;
15
+ const round = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
16
+ const promptOf = ({ input, cacheRead, cacheWrite }) => input + cacheRead + cacheWrite;
17
+ /** A session's cache, from a read with `chain: true` (readSession(locator, source, { chain: true })). A session read
18
+ * without its chain names a model change or an idle gap; its other breaks are unknown. A turn compared is a request with
19
+ * usage that sent a prompt (a request that failed before it sent any, or whose usage is unknown, is passed over); a
20
+ * break compares it with the one before it. */
21
+ export async function analyzeCache(session, options = {}) {
22
+ return analyzed(session, options, options.before?.long ?? false);
23
+ }
24
+ /** analyzeCache, with `long`: whether the latest cache write before the file was a 1h one. A file analyzed alone (no
25
+ * `before`) takes it from the session's earlier files once they are joined: cacheHome analyzes each file both ways. */
26
+ async function analyzed(session, { catalog, calculateCost, before: carried }, written) {
27
+ const answers = session.turns.filter((turn) => turn.role === "assistant");
28
+ const chain = session.chain ?? [];
29
+ // The record that opens each request, by its index among the answers, and each record by id (the first of a repeat).
30
+ const opens = new Map();
31
+ const byId = new Map();
32
+ chain.forEach((record, at) => {
33
+ if (record.request !== undefined && !opens.has(record.request))
34
+ opens.set(record.request, at);
35
+ if (record.id !== undefined && !byId.has(record.id))
36
+ byId.set(record.id, record);
37
+ });
38
+ const prices = catalog === false ? undefined : (catalog ?? (await builtinCatalog()));
39
+ let read = 0;
40
+ let prompt = 0;
41
+ const breaks = [];
42
+ // The turn before, at index -1 when it is the session's previous file's.
43
+ let before = carried ? { index: -1, answer: { at: carried.at, ...(carried.model ? { model: carried.model } : {}) }, usage: carried.usage } : undefined;
44
+ // Whether the latest request that wrote the cache wrote it for an hour.
45
+ let long = written;
46
+ for (const [index, answer] of answers.entries()) {
47
+ const usage = answer.usage;
48
+ if (!usage || promptOf(usage) === 0)
49
+ continue;
50
+ read += usage.cacheRead;
51
+ prompt += promptOf(usage);
52
+ if (before && before.usage.cacheRead > 0 && (before.usage.cacheRead - usage.cacheRead) / before.usage.cacheRead > BREAK_DROP) {
53
+ const lost = before.usage.cacheRead - usage.cacheRead;
54
+ const rewritten = Math.min(lost, usage.cacheWrite + usage.input);
55
+ const { cause, diverged } = causeOf(before.index, before.answer, index, answer, { long, compacted: carried?.compacted === true, chain, opens, byId });
56
+ const model = answer.model ?? session.model;
57
+ breaks.push({
58
+ turn: index + 1,
59
+ at: answer.at,
60
+ dropPct: round((lost / before.usage.cacheRead) * 100, 2),
61
+ rewritten,
62
+ extraCost: prices ? await extraCostOf(model, usage, rewritten, prices, calculateCost) : null,
63
+ cause,
64
+ ...(diverged !== undefined ? { diverged } : {}),
65
+ });
66
+ }
67
+ if (usage.cacheWrite > 0)
68
+ long = (usage.cacheWrite1h ?? 0) > 0;
69
+ before = { index, answer, usage };
70
+ }
71
+ // A compaction of this file's own after the last turn compared (the carried one's, or none: the whole file).
72
+ const from = before && before.index >= 0 ? opens.get(before.index) : -1;
73
+ const compacted = (before?.index === -1 && carried?.compacted === true) || (from !== undefined && chain.slice(from + 1).some(isCompaction));
74
+ const last = before ? { ...(before.answer.model ?? session.model ? { model: (before.answer.model ?? session.model) } : {}), at: before.answer.at, usage: before.usage, long, compacted } : undefined;
75
+ return { hitRate: prompt > 0 ? round(read / prompt, 4) : null, breaks, ...(last ? { last } : {}), compacted };
76
+ }
77
+ /** A compaction where it was first read: a copy of one an earlier file holds is that file's evidence, carried from it. */
78
+ const isCompaction = (record) => record.compact === true && !record.copy;
79
+ /** The first cause, in CACHE_CAUSES' order, the transcript shows for the break at request `index` after `last`. */
80
+ function causeOf(lastIndex, last, index, answer, { long, compacted, chain, opens, byId }) {
81
+ if (last.model && answer.model && last.model !== answer.model)
82
+ return { cause: "model" };
83
+ if (answer.at - last.at > (long ? CACHE_TTL_LONG_MS : CACHE_TTL_MS))
84
+ return { cause: "idle" };
85
+ // The turn before in the session's previous file: a compaction after it there (carried), or one this file opens with,
86
+ // is since it; its chain is that file's, so no edit or sidechain is named across the two.
87
+ if (lastIndex < 0 && compacted)
88
+ return { cause: "compaction" };
89
+ const from = lastIndex < 0 ? -1 : opens.get(lastIndex);
90
+ const to = opens.get(index);
91
+ if (from === undefined || to === undefined)
92
+ return { cause: "unknown" };
93
+ if (chain.slice(from + 1, to).some(isCompaction))
94
+ return { cause: "compaction" };
95
+ if (from < 0)
96
+ return { cause: "unknown" };
97
+ const was = chain[from];
98
+ const now = chain[to];
99
+ // A sidechain's prompt is a conversation of its own, never an edit of the main one's.
100
+ if (was.id !== undefined && now.id !== undefined && !was.sidechain === !now.sidechain) {
101
+ // The turn before's prompt with its own answer, and this turn's prompt: this one should go on from all of it.
102
+ const had = hashesTo(was.id, byId);
103
+ const has = now.parent === undefined ? [] : hashesTo(now.parent, byId);
104
+ let same = 0;
105
+ while (same < had.length && same < has.length && had[same] === has[same])
106
+ same += 1;
107
+ if (same < had.length)
108
+ return { cause: "edited", diverged: same };
109
+ }
110
+ if (now.sidechain && !was.sidechain)
111
+ return { cause: "sidechain" };
112
+ return { cause: "unknown" };
113
+ }
114
+ /** The hashes of the chain that ends at `id`, from its root: the conversation as a request held it. */
115
+ function hashesTo(id, byId) {
116
+ const out = [];
117
+ const visited = new Set();
118
+ for (let at = id; at !== undefined && !visited.has(at);) {
119
+ visited.add(at);
120
+ const record = byId.get(at);
121
+ if (!record)
122
+ break;
123
+ out.push(record.hash);
124
+ at = record.parent;
125
+ }
126
+ return out.reverse();
127
+ }
128
+ /** What the request paid for `rewritten` tokens above reading them from the cache: its usage priced as it was, less as
129
+ * it would have been with them read (taken from its cache write first, then its uncached input; the write's 1h part in
130
+ * proportion). */
131
+ async function extraCostOf(model, usage, rewritten, catalog, calculateCost) {
132
+ const fromWrite = Math.min(rewritten, usage.cacheWrite);
133
+ const cacheWrite = usage.cacheWrite - fromWrite;
134
+ const held = {
135
+ ...usage,
136
+ input: usage.input - (rewritten - fromWrite),
137
+ cacheRead: usage.cacheRead + rewritten,
138
+ cacheWrite,
139
+ ...(usage.cacheWrite1h !== undefined ? { cacheWrite1h: usage.cacheWrite > 0 ? Math.round((usage.cacheWrite1h * cacheWrite) / usage.cacheWrite) : 0 } : {}),
140
+ };
141
+ const paid = await priceRequests([{ ...(model ? { model } : {}), usage }], catalog, calculateCost);
142
+ const would = await priceRequests([{ ...(model ? { model } : {}), usage: held }], catalog, calculateCost);
143
+ return paid === undefined || would === undefined ? null : round(paid - would, 6);
144
+ }
145
+ /** The sources whose sessions cacheHome analyzes: those that write each request's chain (ChainRecord). OpenCode's
146
+ * claude-agent requests mirror a Claude Code session's, so its breaks would count twice in cacheTotals. */
147
+ export const CACHE_SOURCES = ["claude-code", "codex", "pi"];
148
+ /** readSource's prices for a whole read: none, its parts kept with each request's usage (the hit rate's), unpriced. */
149
+ const UNPRICED = { ready: true, load: async () => { } };
150
+ /** Every session of `sources` under `home` with its cache (SessionCache), sorted by key: the sessions parseHome totals,
151
+ * each file read with its chain, and analyzed as it is read (one at a time: a whole home's turns would not fit). Its
152
+ * options are parseHome's but `state`: each call reads every file from its start. A source not in CACHE_SOURCES is
153
+ * refused (RangeError) before any file is read. */
154
+ export async function cacheHome(home, { sources = CACHE_SOURCES, readers = READERS, catalog, calculateCost, env, failures } = {}) {
155
+ const refused = sources.filter((source) => !CACHE_SOURCES.includes(source));
156
+ if (refused.length)
157
+ throw new RangeError(`cacheHome reads ${CACHE_SOURCES.join(", ")}, not ${refused.join(", ")}`);
158
+ const prices = catalog === false ? false : (catalog ?? (await builtinCatalog()) ?? false);
159
+ const priced = { catalog: prices, ...(calculateCost ? { calculateCost } : {}) };
160
+ const out = [];
161
+ const failed = [];
162
+ // One per run, as parseHome keeps one per import: what a reader looks up once (the Codex rollouts index) is shared.
163
+ const lookups = new Map();
164
+ for (const source of sources) {
165
+ // Each file analyzed as it is read, on its own; and its first turn compared, with the chain before it, kept to compare
166
+ // with the last turn of the session's file before it once the files are joined (a Codex thread goes on in a new
167
+ // rollout).
168
+ // Each file alone two ways, the cache before it written for 5 minutes or for an hour (`long`): which holds is known
169
+ // once the session's files before it are joined, and holds until the file writes the cache itself.
170
+ const reports = new Map();
171
+ const { tops, children, unread } = await readSource(home, source, readers, env, undefined, lookups, UNPRICED, true, undefined, async (read) => {
172
+ reports.set(locatorKey(read.locator), await fileCache(read.session, priced));
173
+ const { turns: _turns, chain: _chain, firstPrompt: _prompt, titleText: _title, sourceTitle: _source, cwd: _cwd, ...session } = read.session;
174
+ return { locator: read.locator, session: { ...session, turns: [] }, requests: read.requests.map(({ at, usage }) => ({ role: "assistant", text: "", calls: [], at, ...(usage ? { usage } : {}) })) };
175
+ });
176
+ failed.push(...unread.map(({ locator, error }) => ({ key: keyOf(home, locator).key, file: locator.file, source, error })));
177
+ for (const { parts, children: subagents } of groupsOf(tops, children)) {
178
+ let read = 0;
179
+ let prompt = 0;
180
+ for (const { usage } of [...parts, ...subagents].flatMap((part) => [...requestsIn(part.read)])) {
181
+ if (!usage)
182
+ continue;
183
+ read += usage.cacheRead;
184
+ prompt += promptOf(usage);
185
+ }
186
+ const fileOf = (part) => ({ file: reports.get(locatorKey(part.locator)), requests: requestsOf(part.read) });
187
+ // Each subagent a conversation of its own, in the import's order: a thread that goes on in another rollout is one.
188
+ const conversations = new Map();
189
+ for (const part of subagents) {
190
+ const key = conversationOf(part.locator, part.read.session);
191
+ (conversations.get(key) ?? conversations.set(key, []).get(key)).push(part);
192
+ }
193
+ const breaks = await sessionBreaks(parts.map(fileOf), [...conversations.values()].map((files) => files.map(fileOf)), priced);
194
+ const first = parts[0];
195
+ out.push({ ...keyOf(home, first.locator), source, id: first.read.session.id, hitRate: prompt > 0 ? round(read / prompt, 4) : null, breaks });
196
+ }
197
+ }
198
+ if (failed.length && !failures)
199
+ throw new ReadFailures(failed);
200
+ failures?.push(...failed);
201
+ return out.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
202
+ }
203
+ /** `session` (one file's read, with its chain) as sessionBreaks joins it. */
204
+ export async function fileCache(session, options = {}) {
205
+ return { alone: await analyzed(session, options, false), long: await analyzed(session, options, true), ...headOf(session) };
206
+ }
207
+ /** One conversation's breaks: its files in the import's order, each file's first turn compared with the last turn before
208
+ * it in the files before, its turns counted on from theirs, and a 1h cache write held until a file writes again. */
209
+ async function joined(files, options) {
210
+ const breaks = [];
211
+ let counted = 0;
212
+ let carry;
213
+ for (const { file, requests } of files) {
214
+ if (!file)
215
+ continue;
216
+ if (carry && file.head) {
217
+ const { breaks: [edge], } = await analyzeCache(file.head, { ...options, before: carry });
218
+ if (edge)
219
+ breaks.push({ ...edge, turn: edge.turn + file.skipped + counted });
220
+ }
221
+ // The file as the cache before it was written: a 1h write in an earlier file holds until this one writes.
222
+ const mine = carry?.long ? file.long : file.alone;
223
+ for (const found of mine.breaks)
224
+ breaks.push({ ...found, turn: found.turn + counted });
225
+ // A file with no turn compared passes the carry on, with any compaction of its own.
226
+ carry = mine.last ?? (carry && { ...carry, compacted: carry.compacted === true || mine.compacted });
227
+ counted += requests;
228
+ }
229
+ return breaks;
230
+ }
231
+ /** A session's breaks: its own files (`parts`), one conversation, then each subagent's (`subagents`: each one's files,
232
+ * conversationOf's groups, in the import's order), its breaks with its `subagent` number from 1. */
233
+ export async function sessionBreaks(parts, subagents, options = {}) {
234
+ const breaks = await joined(parts, options);
235
+ for (const [n, files] of subagents.entries())
236
+ for (const found of await joined(files, options))
237
+ breaks.push({ ...found, subagent: n + 1 });
238
+ return breaks;
239
+ }
240
+ /** Which conversation a subagent's file holds, as a key: a thread naming its parent (a Codex subagent) is its thread, in
241
+ * however many rollouts; any other file (a Claude Code subagent's, whose name a workflow's may share a folder deeper) is
242
+ * its own. */
243
+ export const conversationOf = (locator, session) => (session.child && session.parent ? `thread\0${session.id}` : `file\0${locatorKey(locator)}`);
244
+ /** The breaks of `sessions` by cause, each cause there with 0 where none: how many, and their extra cost (USD, of the
245
+ * priced ones); `unpriced`, the breaks whose extra cost is unknown. */
246
+ export function cacheTotals(sessions) {
247
+ const breaks = Object.fromEntries(CACHE_CAUSES.map((cause) => [cause, 0]));
248
+ const extraCost = Object.fromEntries(CACHE_CAUSES.map((cause) => [cause, 0]));
249
+ let unpriced = 0;
250
+ for (const { cause, extraCost: usd } of sessions.flatMap((session) => session.breaks)) {
251
+ breaks[cause] += 1;
252
+ if (usd === null)
253
+ unpriced += 1;
254
+ else
255
+ extraCost[cause] = round(extraCost[cause] + usd, 6);
256
+ }
257
+ return { sessions: sessions.length, breaks, extraCost, unpriced };
258
+ }
259
+ /** A file's first turn compared (a request with usage that sent a prompt), with the chain up to it, as a session of that
260
+ * turn alone; `skipped`, the turns before it. None for a file with no such turn. */
261
+ function headOf(session) {
262
+ const answers = session.turns.filter((turn) => turn.role === "assistant");
263
+ const index = answers.findIndex(({ usage }) => usage !== undefined && promptOf(usage) > 0);
264
+ if (index < 0)
265
+ return { skipped: 0 };
266
+ const chain = session.chain ?? [];
267
+ const opens = chain.findIndex(({ request }) => request === index);
268
+ const answer = answers[index];
269
+ // Only whether a compaction of this file's own came before it: the chain's ids are this file's alone.
270
+ const compacted = opens > 0 && chain.slice(0, opens).some(isCompaction);
271
+ return { head: { turns: [{ role: "assistant", text: "", calls: [], at: answer.at, ...(answer.model ? { model: answer.model } : {}), usage: answer.usage }], chain: [...(compacted ? [{ compact: true }] : []), { request: 0 }], ...(session.model ? { model: session.model } : {}) }, skipped: index };
272
+ }
package/dist/cli.js CHANGED
@@ -7,7 +7,14 @@
7
7
  // OpenCode database); turns, the person's user messages; calls, model requests (its subagents' with them); cost, USD,
8
8
  // null when unknown. --threads and --read-ahead are parseHome's `threads` and
9
9
  // `readAhead` (BYTES: a whole number, or with k, m or g after it for KiB, MiB or GiB); fewer threads or a smaller
10
- // read-ahead hold less memory. --help (-h) prints the usage and exits 0; a usage error exits 2.
10
+ // read-ahead hold less memory.
11
+ // node dist/cli.js <home> [--sources claude-code,codex,pi] --cache
12
+ // (the sources that write a chain, CACHE_SOURCES: another is a usage error).
13
+ // The cache analyzer's answer, keyed the same way: a line per session, {key, source, hitRate, breaks: [{turn, at, dropPct,
14
+ // rewritten, extraCost, cause}]} (a subagent's break with its subagent's number), then one totals line: {totals:
15
+ // {sessions, breaks, extraCost, unpriced}}, the breaks and their extra cost by cause. Numbers and cause names only. It
16
+ // reads one file at a time, so --threads and --read-ahead do not apply to it.
17
+ // --help (-h) prints the usage and exits 0; a usage error exits 2.
11
18
  // A file that cannot be read makes the answer incomplete: no line is printed, one stderr line names each such file by
12
19
  // its source, key and error code (never its path), and the exit is 1.
13
20
  //
@@ -16,10 +23,11 @@
16
23
  import { parseArgs } from "node:util";
17
24
  import { calculateCost } from "@earendil-works/pi-ai";
18
25
  import { builtinModels } from "@earendil-works/pi-ai/providers/all";
26
+ import { CACHE_SOURCES, cacheHome, cacheTotals } from "./cache.js";
19
27
  import { MOST_THREADS, parseHome } from "./home.js";
20
28
  import { catalogOf } from "./price.js";
21
29
  import { SOURCES } from "./readers/index.js";
22
- const USAGE = `usage: agentrun-import <home> [--sources ${SOURCES.join(",")}] [--threads N] [--read-ahead BYTES[k|m|g]] --known-answer`;
30
+ const USAGE = `usage: agentrun-import <home> [--sources ${SOURCES.join(",")}] [--threads N] [--read-ahead BYTES[k|m|g]] --known-answer | --cache`;
23
31
  const UNITS = { "": 1, k: 2 ** 10, m: 2 ** 20, g: 2 ** 30 };
24
32
  /** A flag's whole number (with a unit when `units`), or a usage error. */
25
33
  function wholeOf(flag, value, least, units = false, most = Number.MAX_SAFE_INTEGER) {
@@ -41,7 +49,7 @@ const codeOf = (error) => {
41
49
  async function main() {
42
50
  let parsed;
43
51
  try {
44
- parsed = parseArgs({ allowPositionals: true, options: { sources: { type: "string" }, threads: { type: "string" }, "read-ahead": { type: "string" }, "known-answer": { type: "boolean" }, help: { type: "boolean", short: "h" } } });
52
+ parsed = parseArgs({ allowPositionals: true, options: { sources: { type: "string" }, threads: { type: "string" }, "read-ahead": { type: "string" }, "known-answer": { type: "boolean" }, cache: { type: "boolean" }, help: { type: "boolean", short: "h" } } });
45
53
  }
46
54
  catch (error) {
47
55
  usage(error.message);
@@ -53,23 +61,39 @@ async function main() {
53
61
  }
54
62
  if (positionals.length !== 1)
55
63
  usage("one home directory, please");
56
- if (!values["known-answer"])
57
- usage("--known-answer is the one output there is");
64
+ if (!values["known-answer"] === !values.cache)
65
+ usage("one output, please: --known-answer or --cache");
66
+ const known = values.cache ? CACHE_SOURCES : SOURCES;
58
67
  // A source named twice is read once: a repeat would print its every session twice.
59
- const sources = values.sources === undefined ? SOURCES : [...new Set(values.sources.split(",").map((name) => name.trim()))];
60
- const unknown = sources.filter((name) => !SOURCES.includes(name));
68
+ const sources = values.sources === undefined ? known : [...new Set(values.sources.split(",").map((name) => name.trim()))];
69
+ const unknown = sources.filter((name) => !known.includes(name));
61
70
  if (unknown.length || !sources.length)
62
71
  usage(`unknown source: ${unknown.join(", ") || "(none)"}`);
63
72
  const threads = values.threads === undefined ? undefined : wholeOf("--threads", values.threads, 1, false, MOST_THREADS);
64
73
  const readAhead = values["read-ahead"] === undefined ? undefined : wholeOf("--read-ahead", values["read-ahead"], 0, true);
65
74
  const failures = [];
66
- const sessions = await parseHome(positionals[0], { sources: sources, catalog: catalogOf(builtinModels().getModels()), calculateCost: calculateCost, failures, ...(threads === undefined ? {} : { threads }), ...(readAhead === undefined ? {} : { readAhead }) });
67
- if (failures.length) {
75
+ const options = { sources: sources, catalog: catalogOf(builtinModels().getModels()), calculateCost: calculateCost, failures };
76
+ const failed = () => {
68
77
  for (const { source, key, error } of failures)
69
78
  process.stderr.write(`agentrun-import: cannot read ${source} ${key} (${codeOf(error)})\n`);
70
- process.exitCode = 1;
79
+ if (failures.length)
80
+ process.exitCode = 1;
81
+ return failures.length > 0;
82
+ };
83
+ if (values.cache) {
84
+ const caches = await cacheHome(positionals[0], options);
85
+ if (failed())
86
+ return;
87
+ for (const { key, source, hitRate, breaks } of caches) {
88
+ const listed = breaks.map(({ turn, at, dropPct, rewritten, extraCost, cause, subagent }) => ({ turn, at, dropPct, rewritten, extraCost, cause, ...(subagent !== undefined ? { subagent } : {}) }));
89
+ process.stdout.write(`${JSON.stringify({ key, source, hitRate, breaks: listed })}\n`);
90
+ }
91
+ process.stdout.write(`${JSON.stringify({ totals: cacheTotals(caches) })}\n`);
71
92
  return;
72
93
  }
94
+ const sessions = await parseHome(positionals[0], { ...options, ...(threads === undefined ? {} : { threads }), ...(readAhead === undefined ? {} : { readAhead }) });
95
+ if (failed())
96
+ return;
73
97
  for (const { key, source, tokens, cost, turns, calls } of sessions) {
74
98
  const { input, output, cacheRead, cacheWrite, cacheWrite1h } = tokens;
75
99
  process.stdout.write(`${JSON.stringify({ key, source, tokens: { input, output, cacheRead, cacheWrite, cacheWrite1h }, cost, turns, calls })}\n`);
package/dist/home.d.ts CHANGED
@@ -1,9 +1,12 @@
1
+ import type { Stats } from "node:fs";
1
2
  import { type CalculateCost, type Catalog } from "./price.js";
2
3
  import { type Readers } from "./read.js";
3
- import { type Env } from "./reader.js";
4
+ import { type Env, type Locator, type SessionRead } from "./reader.js";
4
5
  import { type Source } from "./readers/index.js";
6
+ import { type Counts } from "./counts.js";
7
+ import { type PoolRead } from "./pool.js";
5
8
  import { type RecordIndex } from "./record-index.js";
6
- import type { Usage } from "./types.js";
9
+ import type { Mirror, Usage } from "./types.js";
7
10
  import { type Tokens } from "./usage.js";
8
11
  export type SessionTotals = {
9
12
  /** The sha256 (hex) of the session's first file's path relative to the home, with "/" between its parts, and
@@ -104,13 +107,111 @@ export declare class ReadFailures extends Error {
104
107
  readonly failures: ReadFailure[];
105
108
  constructor(failures: ReadFailure[]);
106
109
  }
110
+ /** A session's key: the sha256 of its file's path relative to the home, "/" between its parts, `#<id>` after it when its
111
+ * locator names one. */
112
+ export declare const keyOf: (home: string, { file, id }: Locator) => {
113
+ key: string;
114
+ file: string;
115
+ };
116
+ /** What a total takes of one session a read found, and no more: its session's counts and ids, and each request's model
117
+ * and tokens, packed. A whole SessionRead holds every request as objects (its calls, uuids, key, effort); a source of
118
+ * millions of requests held so until its totals are taken outgrows the heap. */
119
+ type Meta = Pick<SessionRead["session"], "id" | "child" | "parent" | "users" | "copies" | "costUsd" | "model">;
120
+ /** A part as read, its requests as the reader counted them (Counts: each one's model, tokens and time), trimmed to them.
121
+ * A part is held so until its requests are priced (Counted), and to the totals with a requests sink. */
122
+ type AsRead = {
123
+ session: Meta;
124
+ counts: Counts;
125
+ /** Only where a request names another source's session that holds it too (OpenCode's claude-agent turns): each
126
+ * request's Mirror, and the cost it wrote (NaN for none), so the totals can leave the mirrored ones out (mirror.ts). */
127
+ mirrors?: {
128
+ of: (Mirror | undefined)[];
129
+ cost: Float64Array;
130
+ };
131
+ };
132
+ /** A part once its requests are priced, as they are read when the prices are in hand: their tokens summed (exact: whole
133
+ * counts, the source's sums at most 2^53 - 1), and each request's cost, unrounded, to be summed in the totals' order.
134
+ * Without a requests sink a part is kept so: 8 bytes a request, not the request's model, tokens and time. */
135
+ type Counted = {
136
+ session: Meta;
137
+ /** Its requests. */
138
+ n: number;
139
+ /** input, output, cacheRead, cacheWrite, cacheWrite1h, reasoning: its requests' sums. */
140
+ tokens: Float64Array;
141
+ /** Each request's cost (0 for one of no tokens); undefined when there are no prices (no catalog, or no pi-ai). */
142
+ costs: Float64Array | undefined;
143
+ /** Whether a request could not be priced: its tokens unknown, or its model listed nowhere. */
144
+ unpriceable: boolean;
145
+ };
146
+ type Compact = AsRead | Counted;
147
+ export declare const requestsOf: (read: Compact) => number;
148
+ /** The prices requests are taken at, loaded once one is needed, as the totals would: the catalog, and pi-ai's
149
+ * calculateCost when the catalog is there. `ready` once both are as they will be. */
150
+ export type Pricer = {
151
+ ready: boolean;
152
+ catalog?: Catalog | undefined;
153
+ calculate?: CalculateCost | undefined;
154
+ load: () => Promise<void>;
155
+ };
107
156
  /** The most threads parseHome takes: each is a worker with a heap of its own, and past the cores the largest files set
108
157
  * the time anyway. More is refused before any worker starts. */
109
158
  export declare const MOST_THREADS = 64;
159
+ /** Each request of a part read whole (readSource's `whole`), as the sink takes it: a part priced as read keeps none. */
160
+ export declare function requestsIn(read: Compact): Generator<SessionRequest>;
161
+ type Part = {
162
+ locator: Locator;
163
+ read: Compact;
164
+ };
110
165
  /** A session's cost with its subagents': Claude Code's written cost holds its subagents' already (its cost-state), so it
111
166
  * stays as it is; every other source writes a subagent's cost on the subagent's own session, so each is added. Unknown
112
167
  * when the session's is, or when one it adds is: never a subagent counted at 0. parseHome's totals and serve's import. */
113
168
  export declare function withSubagentCosts(source: string, cost: number | undefined, subagents: readonly (number | undefined)[]): number | undefined;
114
169
  /** Every session of `sources` under `home`, as totals, sorted by key. */
115
170
  export declare function parseHome(home: string, { sources, readers, state, catalog, calculateCost, env, failures, requests, threads: asked, readAhead, workerOldMb }?: ParseOptions): Promise<SessionTotals[]>;
171
+ /** What a pass that reads chains (the cache analyzer's) does with each session read, as it is read: it returns what of
172
+ * it the pass keeps (a whole home's turns would not fit). */
173
+ export type Each = (read: SessionRead) => Promise<SessionRead>;
174
+ /** A source's locators in the import's order, its subagents' with their sizes, and (with a pool) how to take each one's read. */
175
+ type Listing = {
176
+ listed: {
177
+ locator: Locator;
178
+ stats: Stats;
179
+ }[];
180
+ childList: {
181
+ locator: Locator;
182
+ of: Locator;
183
+ size: number;
184
+ }[];
185
+ reads?: (() => Promise<PoolRead>)[];
186
+ ids?: number[];
187
+ };
188
+ /** `source`'s locators read in the import's order, sessions first, then the subagents beside them, through one `seen`.
189
+ * A pass handed a state goes on from its cursors, and comes out as a fresh pass would: a record copied into many files
190
+ * counts in the first of them in the order as it is now. The whole source is read again when a locator it read before is
191
+ * gone, when its reader could not go on from its cursor (a new inode, truncated, rewritten), or when a locator holding a
192
+ * copy now comes before the one its record counts in (an append moved an older file after its resumed copy, a new file
193
+ * sorts before one it shares records with). A change of order among locators that share no record reads nothing again.
194
+ * With `each` (Each), each file is read with its chain and its turns, never through the pool, and the part keeps what
195
+ * `each` returns. */
196
+ export declare function readSource(home: string, source: string, readers: Readers, env: Env | undefined, state: HomeState | undefined, lookups: Map<string, unknown>, pricer: Pricer, whole: boolean, listing?: Listing, each?: Each): Promise<{
197
+ tops: Part[];
198
+ children: (Part & {
199
+ of: Locator;
200
+ })[];
201
+ unread: {
202
+ locator: Locator;
203
+ error: unknown;
204
+ }[];
205
+ }>;
206
+ /** A source's sessions: each with its files (`parts`, in the import's order) and its subagents' (`children`); `untied`, a
207
+ * subagent's whose session is not under the home, a session of its own. A session whose every file holds only records
208
+ * an earlier file holds (copies) is none: its records count where they were first read. serve's import leaves such a
209
+ * file out the same way. */
210
+ export declare function groupsOf(tops: Part[], children: (Part & {
211
+ of: Locator;
212
+ })[]): {
213
+ parts: Part[];
214
+ children: Part[];
215
+ untied?: true;
216
+ }[];
116
217
  export {};
package/dist/home.js CHANGED
@@ -32,11 +32,11 @@ export class ReadFailures extends Error {
32
32
  }
33
33
  /** A session's key: the sha256 of its file's path relative to the home, "/" between its parts, `#<id>` after it when its
34
34
  * locator names one. */
35
- const keyOf = (home, { file, id }) => {
35
+ export const keyOf = (home, { file, id }) => {
36
36
  const path = relative(home, file).split(sep).join("/");
37
37
  return { key: createHash("sha256").update(id === undefined ? path : `${path}#${id}`).digest("hex"), file: path };
38
38
  };
39
- const requestsOf = (read) => ("n" in read ? read.n : read.counts.n);
39
+ export const requestsOf = (read) => ("n" in read ? read.n : read.counts.n);
40
40
  /** A file of copies alone: it holds only records an earlier file holds, and no prompt. A session of such files alone, and
41
41
  * no subagent, is no session (totalsOf). */
42
42
  const copiesAlone = (session, requests) => session.copies > 0 && session.users === 0 && requests === 0;
@@ -82,6 +82,13 @@ function requestAt(c, i, fallback) {
82
82
  usage.reasoning = c.values[o + 5];
83
83
  return { ...request, usage };
84
84
  }
85
+ /** Each request of a part read whole (readSource's `whole`), as the sink takes it: a part priced as read keeps none. */
86
+ export function* requestsIn(read) {
87
+ if ("n" in read)
88
+ throw new Error("a part priced as read keeps no requests");
89
+ for (let i = 0; i < read.counts.n; i += 1)
90
+ yield requestAt(read.counts, i, read.session.model);
91
+ }
85
92
  /** `session`'s requests (`c`) priced (Counted), their tokens added to `sums` (the source's so far). */
86
93
  function counted(session, c, pricer, sums) {
87
94
  const { n } = c;
@@ -292,7 +299,15 @@ async function listSource(home, source, readers, env, sized = false) {
292
299
  const childList = await Promise.all(children.map(async (child) => ({ ...child, size: sized ? ((await stat(child.locator.file).catch(() => undefined))?.size ?? 0) : 0 })));
293
300
  return { listed, childList };
294
301
  }
295
- async function readSource(home, source, readers, env, state, lookups, pricer, whole, listing) {
302
+ /** `source`'s locators read in the import's order, sessions first, then the subagents beside them, through one `seen`.
303
+ * A pass handed a state goes on from its cursors, and comes out as a fresh pass would: a record copied into many files
304
+ * counts in the first of them in the order as it is now. The whole source is read again when a locator it read before is
305
+ * gone, when its reader could not go on from its cursor (a new inode, truncated, rewritten), or when a locator holding a
306
+ * copy now comes before the one its record counts in (an append moved an older file after its resumed copy, a new file
307
+ * sorts before one it shares records with). A change of order among locators that share no record reads nothing again.
308
+ * With `each` (Each), each file is read with its chain and its turns, never through the pool, and the part keeps what
309
+ * `each` returns. */
310
+ export async function readSource(home, source, readers, env, state, lookups, pricer, whole, listing, each) {
296
311
  const reader = readerOf(source, readers);
297
312
  // The pool's listing, when parseHome read this source ahead (pool.ts); each read is taken below in order, or made again.
298
313
  const { listed, childList, reads: ahead } = listing ?? (await listSource(home, source, readers, env));
@@ -376,8 +391,10 @@ async function readSource(home, source, readers, env, state, lookups, pricer, wh
376
391
  return made.sessions;
377
392
  }
378
393
  }
379
- // With no state the cursor is dropped: the read makes no copy for it.
380
- const options = { turns: false, totals: true, seen, lookups, [DROPS_CURSOR]: !kept };
394
+ // With no state the cursor is dropped: the read makes no copy for it. A pass that reads chains (`each`) reads each
395
+ // file with its turns and its chain; with no state it keeps no cursor, so a last line with no newline yet is in
396
+ // `seen` like any other, and its copy in a later file counts once.
397
+ const options = each ? { seen, chain: true, lookups, keepsCursor: kept !== undefined } : { turns: false, totals: true, seen, lookups, [DROPS_CURSOR]: !kept };
381
398
  const result = await reader.read(locator, cursor, options).catch((error) => void unread.push({ locator, error }));
382
399
  if (!result) {
383
400
  // A locator read before that cannot be read now gives up its cursor and the records it held, as a fresh pass
@@ -402,7 +419,7 @@ async function readSource(home, source, readers, env, state, lookups, pricer, wh
402
419
  if (state)
403
420
  state.read += result.read;
404
421
  kept?.cursors.set(key, result.cursor);
405
- return result.sessions;
422
+ return each ? Promise.all(result.sessions.map(each)) : result.sessions;
406
423
  };
407
424
  const tops = [];
408
425
  const children = [];
@@ -439,7 +456,11 @@ async function readSource(home, source, readers, env, state, lookups, pricer, wh
439
456
  state.sources[source] = undefined;
440
457
  }
441
458
  }
442
- async function totalsOf(home, source, tops, children, pricer, priceWith, calculateCost, sink) {
459
+ /** A source's sessions: each with its files (`parts`, in the import's order) and its subagents' (`children`); `untied`, a
460
+ * subagent's whose session is not under the home, a session of its own. A session whose every file holds only records
461
+ * an earlier file holds (copies) is none: its records count where they were first read. serve's import leaves such a
462
+ * file out the same way. */
463
+ export function groupsOf(tops, children) {
443
464
  // Sessions by id, their locators in the import's order; one naming its parent (a Codex subagent's thread) is the
444
465
  // parent's, as is each one beside a session's (Claude Code's subagents).
445
466
  const sessions = new Map();
@@ -481,12 +502,11 @@ async function totalsOf(home, source, tops, children, pricer, priceWith, calcula
481
502
  // A subagent whose session is not under the home: a line of its own, but its prompts are its parent agent's.
482
503
  for (const part of untied)
483
504
  sessions.set(`\0${locatorKey(part.locator)}`, { parts: [part], children: [], untied: true });
505
+ return [...sessions.values()].filter(({ parts, children }) => !(parts.every(({ read }) => copiesAlone(read.session, requestsOf(read))) && children.length === 0));
506
+ }
507
+ async function totalsOf(home, source, tops, children, pricer, priceWith, calculateCost, sink) {
484
508
  const out = [];
485
- for (const { parts, children: subagents, untied } of sessions.values()) {
486
- // A session whose every file holds only records an earlier file holds (copies) is no session: its records count where
487
- // they were first read. serve's import leaves such a file out the same way.
488
- if (parts.every(({ read }) => copiesAlone(read.session, requestsOf(read))) && subagents.length === 0)
489
- continue;
509
+ for (const { parts, children: subagents, untied } of groupsOf(tops, children)) {
490
510
  const first = parts[0];
491
511
  const tokens = noTokens();
492
512
  let reasoning = 0;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { Answer, Ended, Mirror, ToolCall, Turn, Usage } from "./types.js";
1
+ export type { Answer, ChainRecord, Ended, Mirror, ToolCall, Turn, Usage } from "./types.js";
2
2
  export { ACTIVE_GAP_MS } from "./types.js";
3
3
  export { mostEffortOf, personsWords } from "./text.js";
4
4
  export { addTokens, noTokens, normalizeUsage, type OtelUsage, otelUsage, type Tokens, type UsageFormat, type UsageOptions } from "./usage.js";
@@ -12,3 +12,4 @@ export { builtinCatalog, type CalculateCost, type Catalog, catalogOf, type Liste
12
12
  export { mirroredIn, ownRequests, sessionKey } from "./mirror.js";
13
13
  export { type HomeState, type ParseOptions, parseHome, type ReadFailure, ReadFailures, type SessionRequest, type SessionTotals, withSubagentCosts } from "./home.js";
14
14
  export { type Wrapped, wrappedHome } from "./wrapped.js";
15
+ export { analyzeCache, BREAK_DROP, CACHE_SOURCES, cacheHome, cacheTotals, conversationOf, fileCache, type FileCache, type JoinedFile, sessionBreaks, type SessionCache, type CacheBreak, type CacheCause, CACHE_CAUSES, type CacheOptions, type CacheReport, CACHE_TTL_LONG_MS, CACHE_TTL_MS } from "./cache.js";
package/dist/index.js CHANGED
@@ -11,3 +11,4 @@ export { builtinCatalog, catalogOf, priceRequests } from "./price.js";
11
11
  export { mirroredIn, ownRequests, sessionKey } from "./mirror.js";
12
12
  export { parseHome, ReadFailures, withSubagentCosts } from "./home.js";
13
13
  export { wrappedHome } from "./wrapped.js";
14
+ export { analyzeCache, BREAK_DROP, CACHE_SOURCES, cacheHome, cacheTotals, conversationOf, fileCache, sessionBreaks, CACHE_CAUSES, CACHE_TTL_LONG_MS, CACHE_TTL_MS } from "./cache.js";
package/dist/lines.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type Counts } from "./counts.js";
2
2
  import { type Env, type Reader, type ReadOptions } from "./reader.js";
3
3
  import { type Shape } from "./scan.js";
4
- import { type Answer, type SessionOf, type Turn } from "./types.js";
4
+ import { type Answer, type ChainRecord, type SessionOf, type Turn } from "./types.js";
5
5
  /** One file's read so far, all of it plain data (no function, Maps and Sets allowed), so a cursor can carry it and
6
6
  * structuredClone or v8.serialize can copy it. `answers` holds every request read, whether turns are kept or not: what
7
7
  * a total counts; a totals read's are in `counts` instead, each its model, usage and time alone. `own` is the source's own (LineSource.start). A turns: true read's holds the session's text (its
@@ -36,6 +36,9 @@ export type ReadContext<O = unknown> = {
36
36
  seen: Set<string>;
37
37
  keep: boolean;
38
38
  add: (turn: Turn) => void;
39
+ /** The session's chain, when the read keeps one (ReadOptions.chain): the source pushes each record of the
40
+ * conversation onto it, in the order read, and marks the record that opens each request. */
41
+ chain?: ChainRecord[];
39
42
  };
40
43
  /** A JSONL source: where its files are, and how it reads one record of one into the session. */
41
44
  export type LineSource<S extends string, O> = Pick<Reader<S>, "source" | "name" | "harness" | "order"> & {
@@ -91,15 +94,17 @@ export type FileCursor = {
91
94
  /** The last bytes before `offset` (up to 64, base64): a file rewritten in place to at least the same length no longer
92
95
  * has them there, and is read from its start. */
93
96
  mark: string;
94
- /** Whether the read kept turns, and whether it was a totals read: a cursor of another kind is no place to go on from. */
97
+ /** Whether the read kept turns, whether it was a totals read, and whether it kept a chain: a cursor of another kind is
98
+ * no place to go on from. */
95
99
  keep: boolean;
96
100
  totals?: boolean;
101
+ chain?: boolean;
97
102
  /** Its reader's state shape when saved (LineSource.stateVersion). */
98
103
  stateVersion?: number;
99
104
  state: ReadState;
100
105
  };
101
106
  /** Whether `spec`'s line reader would go on from `cursor` in `file` now (a read with `options`), as it decides when it
102
107
  * reads: so a reader built on it can choose how to read before reading. A file it cannot open is no place to go on. */
103
- export declare function resumes<S extends string, O>(spec: LineSource<S, O>, file: string, cursor: FileCursor | undefined, { turns: keep, totals: asked }?: ReadOptions): Promise<boolean>;
108
+ export declare function resumes<S extends string, O>(spec: LineSource<S, O>, file: string, cursor: FileCursor | undefined, { turns: keep, totals: asked, chain }?: ReadOptions): Promise<boolean>;
104
109
  /** The Reader of a JSONL source: each file one locator, its cursor a FileCursor. */
105
110
  export declare function lineReader<S extends string, O>(spec: LineSource<S, O>): Reader<S, FileCursor>;
package/dist/lines.js CHANGED
@@ -47,24 +47,24 @@ const ahead = (read) => {
47
47
  read.catch(() => { });
48
48
  return read;
49
49
  };
50
- /** Whether a read from `cursor` of the open file goes on from it: the same source, kind of read and state shape
51
- * (LineSource.stateVersion), the same file (device and inode), no shorter, and the bytes before its offset as they
52
- * were. Else it reads the file from its start. */
53
- async function goesOn(spec, keep, totals, cursor, handle, stats) {
54
- return cursor.source === spec.source && cursor.keep === keep && (cursor.totals ?? false) === totals && cursor.stateVersion === spec.stateVersion && cursor.dev === stats.dev && cursor.ino === stats.ino && stats.size >= cursor.offset && (await markOf(handle, cursor.offset)) === cursor.mark;
50
+ /** Whether a read from `cursor` of the open file goes on from it: the same source, kind of read (turns, totals, chain)
51
+ * and state shape (LineSource.stateVersion), the same file (device and inode), no shorter, and the bytes before its
52
+ * offset as they were. Else it reads the file from its start. */
53
+ async function goesOn(spec, keep, totals, chained, cursor, handle, stats) {
54
+ return cursor.source === spec.source && cursor.keep === keep && (cursor.totals ?? false) === totals && (cursor.chain ?? false) === chained && cursor.stateVersion === spec.stateVersion && cursor.dev === stats.dev && cursor.ino === stats.ino && stats.size >= cursor.offset && (await markOf(handle, cursor.offset)) === cursor.mark;
55
55
  }
56
56
  /** Whether a read with these options is a totals read: asked for, with no turns kept, from a source that has one. */
57
57
  const totalsRead = (spec, keep, asked) => asked && !keep && spec.totals === true;
58
58
  /** Whether `spec`'s line reader would go on from `cursor` in `file` now (a read with `options`), as it decides when it
59
59
  * reads: so a reader built on it can choose how to read before reading. A file it cannot open is no place to go on. */
60
- export async function resumes(spec, file, cursor, { turns: keep = true, totals: asked = false } = {}) {
60
+ export async function resumes(spec, file, cursor, { turns: keep = true, totals: asked = false, chain = false } = {}) {
61
61
  if (cursor === undefined)
62
62
  return false;
63
63
  const handle = await open(file, "r").catch(() => undefined);
64
64
  if (!handle)
65
65
  return false;
66
66
  try {
67
- return await goesOn(spec, keep, totalsRead(spec, keep, asked), cursor, handle, await handle.stat());
67
+ return await goesOn(spec, keep, totalsRead(spec, keep, asked), chain && keep, cursor, handle, await handle.stat());
68
68
  }
69
69
  finally {
70
70
  await handle.close();
@@ -76,18 +76,20 @@ const overlay = (base) => {
76
76
  return { has: (key) => extra.has(key) || base.has(key), add: (key) => extra.add(key) };
77
77
  };
78
78
  /** One session file of `spec`'s source, read from its start or from `cursor`. */
79
- async function readLines(spec, shape, file, cursor, { turns: keep = true, totals: asked = false, seen, keepsCursor = true, [DROPS_CURSOR]: dropsCursor = false, [NO_READ_AHEAD]: inTurn = false, maxLine = Infinity } = {}) {
79
+ async function readLines(spec, shape, file, cursor, { turns: keep = true, totals: asked = false, seen, keepsCursor = true, [DROPS_CURSOR]: dropsCursor = false, [NO_READ_AHEAD]: inTurn = false, maxLine = Infinity, chain = false } = {}) {
80
80
  const { source } = spec;
81
81
  const totals = totalsRead(spec, keep, asked);
82
82
  const fields = totals ? shape : undefined;
83
83
  const handle = await open(file, "r");
84
84
  try {
85
85
  const stats = await handle.stat();
86
+ // A chain is kept with the turns alone.
87
+ const chained = chain && keep;
86
88
  // The cursor's presence checked here, so `resumed` narrows it where its state and offset are read.
87
- const resumed = cursor !== undefined && (await goesOn(spec, keep, totals, cursor, handle, stats));
89
+ const resumed = cursor !== undefined && (await goesOn(spec, keep, totals, chained, cursor, handle, stats));
88
90
  const state = (resumed
89
91
  ? structuredClone(cursor.state)
90
- : { session: { source, id: "", file, state: "completed", child: false, turns: [], users: 0, activeMs: 0, copies: 0 }, turns: [], answers: [], names: new Map(), priced: { sum: 0, unknown: false }, activeMs: 0, own: spec.start(), ...(totals ? { counts: counts() } : {}), ...(seen ? {} : { seen: new Set() }) });
92
+ : { session: { source, id: "", file, state: "completed", child: false, turns: [], users: 0, activeMs: 0, copies: 0, ...(chained ? { chain: [] } : {}) }, turns: [], answers: [], names: new Map(), priced: { sum: 0, unknown: false }, activeMs: 0, own: spec.start(), ...(totals ? { counts: counts() } : {}), ...(seen ? {} : { seen: new Set() }) });
91
93
  const context = {
92
94
  state,
93
95
  seen: seen ?? (state.seen ??= new Set()),
@@ -103,6 +105,7 @@ async function readLines(spec, shape, file, cursor, { turns: keep = true, totals
103
105
  else
104
106
  state.answers.push(turn);
105
107
  },
108
+ ...(state.session.chain ? { chain: state.session.chain } : {}),
106
109
  };
107
110
  const line = (value) => {
108
111
  if (!isObject(value))
@@ -215,7 +218,7 @@ async function readLines(spec, shape, file, cursor, { turns: keep = true, totals
215
218
  if (resumed)
216
219
  session = withoutText(session);
217
220
  }
218
- return { sessions: [{ locator: { file }, session, requests: state.answers, ...(state.counts ? { counts: state.counts } : {}) }], cursor: { source, dev: stats.dev, ino: stats.ino, offset, mark, keep, ...(totals ? { totals } : {}), ...(spec.stateVersion !== undefined ? { stateVersion: spec.stateVersion } : {}), state: kept }, read, resumed };
221
+ return { sessions: [{ locator: { file }, session, requests: state.answers, ...(state.counts ? { counts: state.counts } : {}) }], cursor: { source, dev: stats.dev, ino: stats.ino, offset, mark, keep, ...(totals ? { totals } : {}), ...(chained ? { chain: true } : {}), ...(spec.stateVersion !== undefined ? { stateVersion: spec.stateVersion } : {}), state: kept }, read, resumed };
219
222
  }
220
223
  finally {
221
224
  await handle.close();
@@ -224,6 +227,8 @@ async function readLines(spec, shape, file, cursor, { turns: keep = true, totals
224
227
  /** The session as read so far, the state left as it is. */
225
228
  function finish(spec, file, state, context) {
226
229
  const out = { ...state.session, file };
230
+ if (out.chain)
231
+ out.chain = [...out.chain];
227
232
  const turns = spec.finish ? spec.finish(out, context.keep ? [...state.turns] : [], context) : context.keep ? [...state.turns] : [];
228
233
  if (!out.id)
229
234
  out.id = spec.idOf(file);
package/dist/reader.d.ts CHANGED
@@ -66,6 +66,9 @@ export type ReadOptions = {
66
66
  * decoded. The read pool's workers set it to an eighth of their heap (pool.ts), so that no one line can end the
67
67
  * process; parseHome then reads the file on its own thread, with no such bound. Default: none. */
68
68
  maxLine?: number;
69
+ /** true keeps the session's chain (SessionOf.chain) for analyzeCache, its turns with it: each record's id, its
70
+ * parent's and a hash of its content, never the content. A cursor read with it is resumed with it. Default false. */
71
+ chain?: boolean;
69
72
  /** What a reader looks up once for a whole import, shared across its files: one map per import, each reader keying
70
73
  * its own entries. Without one, each read looks up afresh. */
71
74
  lookups?: Map<string, unknown>;
@@ -6,7 +6,7 @@ import { lineReader } from "../lines.js";
6
6
  import { entries } from "../reader.js";
7
7
  import { addNew, ownerOf, recordIndex } from "../record-index.js";
8
8
  import { packed, packInto } from "../record-key.js";
9
- import { argsOf, effortOf, FAILED, INTERRUPTED, isObject, str, textOf } from "../text.js";
9
+ import { argsOf, effortOf, FAILED, hashOf, INTERRUPTED, isObject, str, textOf } from "../text.js";
10
10
  import { normalizeUsage } from "../usage.js";
11
11
  // The titles Claude Code writes into a session's file, each again as it changes, and the field each holds it in.
12
12
  const TITLES = new Map([
@@ -37,7 +37,21 @@ const keyOf = (message, value) => {
37
37
  };
38
38
  const PACKED = packed();
39
39
  /** Claude Code's record; false for one read already (the import's earlier file, or this file's own repeat). */
40
- function record(value, at, { state, seen, keep, add }) {
40
+ /** A record of the conversation as the chain holds it (ChainRecord): its uuid, its parent's, a hash of what it put in the
41
+ * conversation, and whether it is a compaction (a compact_boundary, which starts a new chain, or the summary after it)
42
+ * or a sidechain's. Each record the file holds, a copy too: a later record's chain runs through it. */
43
+ const linkOf = (value, uuid) => {
44
+ const message = isObject(value.message) ? value.message : undefined;
45
+ const compact = value.isCompactSummary === true || (value.type === "system" && value.subtype === "compact_boundary");
46
+ return {
47
+ id: uuid,
48
+ ...(str(value.parentUuid) ? { parent: value.parentUuid } : {}),
49
+ hash: hashOf([value.type, value.subtype ?? null, message ? [message.role, message.content] : (value.content ?? value.attachment ?? null)]),
50
+ ...(compact ? { compact: true } : {}),
51
+ ...(value.isSidechain === true ? { sidechain: true } : {}),
52
+ };
53
+ };
54
+ function record(value, at, { state, seen, keep, add, chain }) {
41
55
  const { session, names, own, counts } = state;
42
56
  // Claude Code names a session's file for its id (<id>.jsonl): the file's own, whatever a record in it says. A resumed
43
57
  // session's file can open with records copied from the session it resumed, each still naming that one.
@@ -60,8 +74,16 @@ function record(value, at, { state, seen, keep, add }) {
60
74
  // A record written twice (a session carried on in its own file, or copied into a resumed one's) is read once, and moves
61
75
  // no time a second time, whatever its type.
62
76
  const uuid = str(value.uuid);
63
- if (uuid && seen.has(`u:${uuid}`))
77
+ const link = chain && uuid ? linkOf(value, uuid) : undefined;
78
+ if (link)
79
+ chain.push(link);
80
+ if (uuid && seen.has(`u:${uuid}`)) {
81
+ // A copy is in the chain (a later record's runs through it), but happened in the earlier file: a compaction it
82
+ // repeats is no evidence for a break in this one.
83
+ if (link)
84
+ link.copy = true;
64
85
  return false;
86
+ }
65
87
  if (uuid)
66
88
  seen.add(`u:${uuid}`);
67
89
  if ((value.type !== "user" && value.type !== "assistant") || !isObject(value.message))
@@ -150,6 +172,8 @@ function record(value, at, { state, seen, keep, add }) {
150
172
  if (key)
151
173
  own.keyed.set(key, turn);
152
174
  add(turn);
175
+ if (link)
176
+ link.request = state.answers.length - 1;
153
177
  }
154
178
  if (key)
155
179
  seen.add(`m:${key}`);
@@ -51,16 +51,18 @@ function codexFailed(output) {
51
51
  }
52
52
  return undefined;
53
53
  }
54
- function readRecord(value, at, { state, keep, add }) {
54
+ function readRecord(value, at, { state, keep, add, chain }) {
55
55
  const { session, names, turns, own: codex, counts } = state;
56
56
  const payload = isObject(value.payload) ? value.payload : {};
57
57
  // One request's output items are one turn; its usage, when it comes, is that turn's. A usage with no request (a
58
58
  // compaction's, one whose output is no item read here) is a turn of its own. Each is held by its index: in the read's
59
- // answers, or a totals read's counts, each request its model, usage and time alone.
59
+ // answers, or a totals read's counts, each request its model, usage and time alone. A read's request is in the chain
60
+ // too (a totals read keeps none).
60
61
  const answer = () => {
61
62
  if (counts)
62
63
  return addRequest(counts, session.model, undefined, at);
63
64
  add({ role: "assistant", text: "", calls: [], at, ...(session.model ? { model: session.model } : {}), ...(state.effort ? { effort: state.effort } : {}) });
65
+ chain?.push({ request: state.answers.length - 1 });
64
66
  return state.answers.length - 1;
65
67
  };
66
68
  const request = () => {
@@ -81,6 +83,12 @@ function readRecord(value, at, { state, keep, add }) {
81
83
  state.answers[i].key = response;
82
84
  codex.openAt = codex.unpaidAt = undefined;
83
85
  };
86
+ // A rollout's prompt only grows, but for a compaction, which replaces the history with its summary: the chain holds the
87
+ // requests and the compactions, in their order, and no record ids (a rollout names none to rewind to).
88
+ if (value.type === "compacted") {
89
+ chain?.push({ compact: true });
90
+ return;
91
+ }
84
92
  if (value.type === "session_meta") {
85
93
  // A fork writes its parent's session_meta after its own (Codex 0.154): one whose id is the thread this rollout forked
86
94
  // from is that copy, and says nothing of this rollout. Any other later session_meta still counts, as Codex writes it.
@@ -2,10 +2,15 @@
2
2
  import { basename, join } from "node:path";
3
3
  import { lineReader } from "../lines.js";
4
4
  import { entries } from "../reader.js";
5
- import { argsOf, effortOf, FAILED, isObject, str, textOf, timeOf } from "../text.js";
5
+ import { argsOf, effortOf, FAILED, hashOf, isObject, str, textOf, timeOf } from "../text.js";
6
6
  import { normalizeUsage } from "../usage.js";
7
- function record(value, at, { state, keep, add }) {
7
+ function record(value, at, { state, keep, add, chain }) {
8
8
  const { session, priced } = state;
9
+ // Each entry after the session's own names the one before it (parentId): a branch names an earlier one. pi writes no
10
+ // compaction or sidechain record in the sessions read here, so the chain marks none.
11
+ const link = chain && value.type !== "session" && str(value.id) ? { id: value.id, ...(str(value.parentId) ? { parent: value.parentId } : {}), hash: hashOf([value.type, isObject(value.message) ? [value.message.role, value.message.content] : (value.modelId ?? value.thinkingLevel ?? null)]) } : undefined;
12
+ if (link)
13
+ chain.push(link);
9
14
  if (value.type === "session") {
10
15
  if (str(value.id))
11
16
  session.id = value.id;
@@ -74,6 +79,8 @@ function record(value, at, { state, keep, add }) {
74
79
  ...(tokens ? { usage: tokens } : {}),
75
80
  ...(message.stopReason === "error" ? { error: keep ? (str(message.errorMessage) ?? "unknown error") : FAILED } : {}),
76
81
  });
82
+ if (link)
83
+ link.request = state.answers.length - 1;
77
84
  }
78
85
  }
79
86
  const spec = {
package/dist/text.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import type { Turn } from "./types.js";
2
+ /** A record's content as a ChainRecord holds it: the first 16 hex of the sha256 of its JSON, never the content. */
3
+ export declare const hashOf: (content: unknown) => string;
2
4
  /** What a request read without turns keeps of its error: that it failed, never the message (a path, a provider's text). */
3
5
  export declare const FAILED = "failed";
4
6
  export declare const isObject: (value: unknown) => value is Record<string, unknown>;
package/dist/text.js CHANGED
@@ -1,3 +1,7 @@
1
+ // What every reader reads a record's fields with.
2
+ import { createHash } from "node:crypto";
3
+ /** A record's content as a ChainRecord holds it: the first 16 hex of the sha256 of its JSON, never the content. */
4
+ export const hashOf = (content) => createHash("sha256").update(JSON.stringify(content) ?? "").digest("hex").slice(0, 16);
1
5
  /** What a request read without turns keeps of its error: that it failed, never the message (a path, a provider's text). */
2
6
  export const FAILED = "failed";
3
7
  export const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
package/dist/types.d.ts CHANGED
@@ -68,6 +68,22 @@ export type Turn = ({
68
68
  export type Answer = Extract<Turn, {
69
69
  role: "assistant";
70
70
  }>;
71
+ /** One record of a session's conversation, as the cache analyzer (analyzeCache) reads it: never its text. `id` and
72
+ * `parent` are the source's own (Claude Code's uuid and parentUuid, pi's id and parentId), absent where the source's
73
+ * records name none (Codex, whose prompt only grows); `hash`, of what the record put in the conversation (two records of
74
+ * the same content hash the same); `compact`, a compaction or summary boundary; `sidechain`, a record of a sidechain
75
+ * (Claude Code's isSidechain); `copy`, a record an earlier file of the import holds (a moved or resumed session's
76
+ * file repeats them): in the chain, but no event of this file's; `request`, the index among the session's assistant
77
+ * turns of the request it opens. */
78
+ export type ChainRecord = {
79
+ id?: string;
80
+ parent?: string;
81
+ hash?: string;
82
+ compact?: true;
83
+ sidechain?: true;
84
+ copy?: true;
85
+ request?: number;
86
+ };
71
87
  export type Ended = "completed" | "failed" | "stopped";
72
88
  /** The longest gap between two records counted as time at work, as WakaTime counts it: a longer gap is a session left
73
89
  * open and counts nothing. Claude Code's Bash tool runs a call for up to 10 minutes with nothing written. */
@@ -109,4 +125,6 @@ export type SessionOf<S extends string = string> = {
109
125
  effort?: string;
110
126
  /** Each other source's session its requests' mirrors name, in the order first named (with or without its turns). */
111
127
  mirrors?: Mirror[];
128
+ /** Its records in the order read, as the cache analyzer reads them (ChainRecord): only when read with `chain: true`. */
129
+ chain?: ChainRecord[];
112
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-import",
3
- "version": "0.1.0-beta.60",
3
+ "version": "0.1.0-beta.62",
4
4
  "description": "Reads the coding-agent sessions under a home (Claude Code, Codex, pi, OpenCode, GitHub Copilot CLI) into one Session shape, with normalized token usage, subagents under their parent, byte-offset cursors for re-reads, and per-session totals.",
5
5
  "keywords": [
6
6
  "agentrun",