@parcha/agentrun-import 0.1.0-beta.59 → 0.1.0-beta.61
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 +67 -10
- package/dist/cache.d.ts +90 -0
- package/dist/cache.js +266 -0
- package/dist/cli.js +34 -10
- package/dist/home.d.ts +112 -9
- package/dist/home.js +184 -109
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/internal.d.ts +18 -0
- package/dist/internal.js +12 -0
- package/dist/lines.d.ts +20 -3
- package/dist/lines.js +88 -31
- package/dist/pool-worker.js +22 -34
- package/dist/pool.d.ts +34 -8
- package/dist/pool.js +59 -14
- package/dist/read.js +4 -1
- package/dist/reader.d.ts +3 -0
- package/dist/readers/claude-code.d.ts +24 -0
- package/dist/readers/claude-code.js +77 -37
- package/dist/readers/codex.d.ts +58 -5
- package/dist/readers/codex.js +103 -73
- package/dist/readers/line-readers.d.ts +7 -0
- package/dist/readers/line-readers.js +10 -0
- package/dist/readers/pi.js +9 -2
- package/dist/record-index.d.ts +30 -3
- package/dist/record-index.js +128 -43
- package/dist/scan-wasm.d.ts +1 -0
- package/dist/scan-wasm.js +2 -0
- package/dist/scan.d.ts +21 -0
- package/dist/scan.js +164 -0
- package/dist/text.d.ts +3 -0
- package/dist/text.js +38 -2
- package/dist/types.d.ts +18 -0
- package/package.json +1 -1
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
|
|
@@ -67,10 +70,11 @@ export type ParseOptions = {
|
|
|
67
70
|
* their times and models, text-free as the totals are. `started`: the time (ms) of the first request of the session's
|
|
68
71
|
* own files (not its subagents'), absent when it has none. For a caller that buckets the same numbers (wrapped.ts). */
|
|
69
72
|
requests?: (totals: SessionTotals, requests: readonly SessionRequest[], started: number | undefined) => void;
|
|
70
|
-
/** Threads that read the sources' files ahead, largest first, without a state and with the registry's readers
|
|
71
|
-
* the cores this process may run on, at most
|
|
72
|
-
*
|
|
73
|
-
*
|
|
73
|
+
/** Threads that read the sources' files ahead, largest first, without a state and with the registry's readers. Default:
|
|
74
|
+
* the cores this process may run on less one (two on two), at most 16, and no more than the workers whose heaps (16 MB
|
|
75
|
+
* young generation plus `workerOldMb` each) fit in the memory still free (the machine's, at most its container's
|
|
76
|
+
* limit) once `readAhead` is set aside; at least 1 (pool.ts, defaultThreads). Each read is kept only when it is the
|
|
77
|
+
* one parseHome would make in order; 1 reads every file in order on this thread. At most MOST_THREADS (64). */
|
|
74
78
|
threads?: number;
|
|
75
79
|
/** With threads, a cap on the bytes of finished reads made ahead of the one being taken that may wait (default
|
|
76
80
|
* readAheadBytes(): 1 GiB, or a sixteenth of the machine's memory when less); at it, the threads read only the file
|
|
@@ -78,8 +82,9 @@ export type ParseOptions = {
|
|
|
78
82
|
* more memory and waits less behind a large file. A cap on finished reads waiting, plus at most one read in flight
|
|
79
83
|
* per thread; not on the process's memory. */
|
|
80
84
|
readAhead?: number;
|
|
81
|
-
/** With threads, each worker's old generation in MB (default OLD_MB, 64
|
|
82
|
-
*
|
|
85
|
+
/** With threads, each worker's old generation in MB (default OLD_MB, 64; at least MIN_OLD_MB, 8: at 1 or 2 V8 ends the
|
|
86
|
+
* process as a worker starts, at 3 to 7 the workers run out of memory). A worker that runs out of it gives its file back, which is read on this
|
|
87
|
+
* thread, and another takes its place; past 2 x threads such losses the rest is read here. */
|
|
83
88
|
workerOldMb?: number;
|
|
84
89
|
};
|
|
85
90
|
/** One model request of a session: when (ms), by which model ("provider/model", the session's when the request names none),
|
|
@@ -102,13 +107,111 @@ export declare class ReadFailures extends Error {
|
|
|
102
107
|
readonly failures: ReadFailure[];
|
|
103
108
|
constructor(failures: ReadFailure[]);
|
|
104
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
|
+
};
|
|
105
156
|
/** The most threads parseHome takes: each is a worker with a heap of its own, and past the cores the largest files set
|
|
106
157
|
* the time anyway. More is refused before any worker starts. */
|
|
107
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
|
+
};
|
|
108
165
|
/** A session's cost with its subagents': Claude Code's written cost holds its subagents' already (its cost-state), so it
|
|
109
166
|
* stays as it is; every other source writes a subagent's cost on the subagent's own session, so each is added. Unknown
|
|
110
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. */
|
|
111
168
|
export declare function withSubagentCosts(source: string, cost: number | undefined, subagents: readonly (number | undefined)[]): number | undefined;
|
|
112
169
|
/** Every session of `sources` under `home`, as totals, sorted by key. */
|
|
113
|
-
export declare function parseHome(home: string, { sources, readers, state, catalog, calculateCost, env, failures, requests, threads, readAhead, workerOldMb }?: ParseOptions): Promise<SessionTotals[]>;
|
|
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
|
+
}[];
|
|
114
217
|
export {};
|