@parcha/agentrun-import 0.1.0-beta.58 → 0.1.0-beta.60
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 +111 -20
- package/dist/cli.js +23 -8
- package/dist/home.d.ts +24 -1
- package/dist/home.js +394 -146
- package/dist/index.d.ts +7 -5
- package/dist/index.js +4 -2
- package/dist/internal.d.ts +18 -0
- package/dist/internal.js +12 -0
- package/dist/lines.d.ts +24 -1
- package/dist/lines.js +135 -25
- package/dist/mirror.d.ts +13 -0
- package/dist/mirror.js +15 -0
- package/dist/pool-worker.d.ts +6 -0
- package/dist/pool-worker.js +50 -0
- package/dist/pool.d.ts +106 -0
- package/dist/pool.js +288 -0
- package/dist/price.d.ts +13 -5
- package/dist/price.js +31 -21
- package/dist/read.d.ts +14 -4
- package/dist/read.js +41 -7
- package/dist/reader.d.ts +38 -8
- package/dist/readers/claude-code.d.ts +24 -0
- package/dist/readers/claude-code.js +51 -35
- package/dist/readers/codex.d.ts +60 -1
- package/dist/readers/codex.js +494 -52
- package/dist/readers/copilot.d.ts +4 -0
- package/dist/readers/copilot.js +224 -0
- package/dist/readers/index.d.ts +2 -0
- package/dist/readers/index.js +4 -0
- package/dist/readers/line-readers.d.ts +7 -0
- package/dist/readers/line-readers.js +10 -0
- package/dist/readers/opencode.d.ts +42 -0
- package/dist/readers/opencode.js +920 -0
- package/dist/readers/pi.js +2 -2
- package/dist/record-index.d.ts +32 -1
- package/dist/record-index.js +133 -13
- 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 +36 -2
- package/dist/types.d.ts +20 -3
- package/dist/usage.d.ts +6 -2
- package/dist/usage.js +42 -1
- package/package.json +4 -2
package/dist/types.d.ts
CHANGED
|
@@ -15,10 +15,19 @@ export type Usage = {
|
|
|
15
15
|
cacheWrite1h?: number;
|
|
16
16
|
reasoning?: number;
|
|
17
17
|
};
|
|
18
|
+
/** Another source's session that holds the same request: OpenCode's claude-agent provider runs Claude Code, which writes
|
|
19
|
+
* each request into its own session file too. A total of both sources counts the request once, in `source`'s. */
|
|
20
|
+
export type Mirror = {
|
|
21
|
+
source: string;
|
|
22
|
+
sessionId: string;
|
|
23
|
+
};
|
|
18
24
|
/** An assistant turn is one model request: `model` the one it ran on ("provider/model"), `effort` the effort or
|
|
19
25
|
* thinking level it ran at, `usage` its tokens, each absent when the source does not say; `key`, the source's own id of
|
|
20
|
-
* the request (Claude Code's message id with its request id, Codex's response id); `error`, why it failed
|
|
21
|
-
*
|
|
26
|
+
* the request (Claude Code's message id with its request id, Codex's response id); `error`, why it failed; `mirrors`, the
|
|
27
|
+
* other source's session that holds the same request (Mirror). `folded`: its usage
|
|
28
|
+
* (zeros) is counted in a later request of the same session, where its source wrote a total, not each request's own
|
|
29
|
+
* (Droid): its zeros are no unknown. A note is a line the harness itself wrote in the conversation: no request, nor the
|
|
30
|
+
* person's. */
|
|
22
31
|
export type Turn = ({
|
|
23
32
|
role: "user";
|
|
24
33
|
text: string;
|
|
@@ -35,10 +44,15 @@ export type Turn = ({
|
|
|
35
44
|
at: number;
|
|
36
45
|
costUsd?: number;
|
|
37
46
|
key?: string;
|
|
47
|
+
/** The source's own ids of the request's later parts, each a key of its own (Copilot's later chunks of a split
|
|
48
|
+
* response, each a message with its own messageId): a later import counts them once too. */
|
|
49
|
+
keys?: string[];
|
|
38
50
|
model?: string;
|
|
39
51
|
effort?: string;
|
|
40
52
|
usage?: Usage;
|
|
41
53
|
error?: string;
|
|
54
|
+
folded?: true;
|
|
55
|
+
mirrors?: Mirror;
|
|
42
56
|
} | {
|
|
43
57
|
role: "toolResult";
|
|
44
58
|
callId: string;
|
|
@@ -47,7 +61,8 @@ export type Turn = ({
|
|
|
47
61
|
isError: boolean;
|
|
48
62
|
at: number;
|
|
49
63
|
}) & {
|
|
50
|
-
/** The source's own ids of the records the turn was read from (Claude Code's uuids
|
|
64
|
+
/** The source's own ids of the records the turn was read from (Claude Code's uuids, an OpenCode prompt's fingerprint): a
|
|
65
|
+
* later import counts them once. */
|
|
51
66
|
uuids?: string[];
|
|
52
67
|
};
|
|
53
68
|
export type Answer = Extract<Turn, {
|
|
@@ -92,4 +107,6 @@ export type SessionOf<S extends string = string> = {
|
|
|
92
107
|
copies: number;
|
|
93
108
|
/** The effort or thinking level most of its requests ran at, as the source names it; with its turns only. */
|
|
94
109
|
effort?: string;
|
|
110
|
+
/** Each other source's session its requests' mirrors name, in the order first named (with or without its turns). */
|
|
111
|
+
mirrors?: Mirror[];
|
|
95
112
|
};
|
package/dist/usage.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { Usage } from "./types.js";
|
|
2
|
-
export type UsageFormat = "anthropic" | "openai" | "pi" | "openrouter";
|
|
2
|
+
export type UsageFormat = "anthropic" | "openai" | "pi" | "openrouter" | "opencode" | "copilot";
|
|
3
|
+
/** What a format's reading may need beyond the counts: the version of the program that wrote them (OpenCode's). */
|
|
4
|
+
export type UsageOptions = {
|
|
5
|
+
version?: string;
|
|
6
|
+
};
|
|
3
7
|
/** A request's usage as `format` writes it, as Usage; undefined unless input and output are counts (an absent cache
|
|
4
8
|
* count is 0) and the input left is not negative. The 1h part of the cache write, or the reasoning part of the output,
|
|
5
9
|
* is kept only when it is a count of at most the whole. */
|
|
6
|
-
export declare function normalizeUsage(format: UsageFormat, raw: unknown): Usage | undefined;
|
|
10
|
+
export declare function normalizeUsage(format: UsageFormat, raw: unknown, options?: UsageOptions): Usage | undefined;
|
|
7
11
|
/** A request's tokens as an OpenTelemetry GenAI span carries them: `input` INCLUSIVE of the cache (the uncached input, the
|
|
8
12
|
* cache read and the cache write together), as gen_ai.usage.input_tokens is defined and as Sentry reads it (it takes
|
|
9
13
|
* the cache counts out of it again, so an exclusive figure would go negative). The other counts as Usage has them. */
|
package/dist/usage.js
CHANGED
|
@@ -6,8 +6,32 @@
|
|
|
6
6
|
// pi already split as Usage is, cacheWrite1h included.
|
|
7
7
|
// openrouter Chat Completions' names: prompt_tokens holds prompt_tokens_details.cached_tokens and .cache_write_tokens,
|
|
8
8
|
// subtracted; completion_tokens holds completion_tokens_details.reasoning_tokens, kept beside it.
|
|
9
|
+
// opencode {input, output, reasoning, cache: {read, write}, total?}: input already leaves the cache out. Since
|
|
10
|
+
// OpenCode 1.3.16 output leaves the reasoning out (anomalyco/opencode 280eb16e77, #21047: "ensure reasoning
|
|
11
|
+
// tokens arent double counted"; AI SDK 6 came in 1.3.4, and output was still the SDK's whole outputTokens
|
|
12
|
+
// until then), so output is output + reasoning (reasoning kept beside it, as OpenAI's). Before it, output
|
|
13
|
+
// held the reasoning already: a session's `version` older than 1.3.16 keeps output as it is. Where a step
|
|
14
|
+
// records its `total`, output is what the total leaves after the input and the cache, when that is at
|
|
15
|
+
// least the output, whatever the version. All nought is no usage: a request cut before its usage came.
|
|
16
|
+
// copilot GitHub Copilot CLI's {inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens, reasoningTokens}:
|
|
17
|
+
// inputTokens holds the cache read and write (github/copilot-sdk docs/features/usage-and-billing.md),
|
|
18
|
+
// subtracted; reasoningTokens is part of outputTokens, kept as `reasoning` beside it.
|
|
9
19
|
// A trace exporter's figure is otelUsage's: the same counts, its input inclusive of the cache.
|
|
10
20
|
import { isObject } from "./text.js";
|
|
21
|
+
/** The first OpenCode whose output leaves the reasoning out. */
|
|
22
|
+
const OPENCODE_SPLIT = [1, 3, 16];
|
|
23
|
+
/** Whether `version` ("1.2.3", a pre-release after it) is an OpenCode older than 1.3.16; unknown is not. */
|
|
24
|
+
function beforeSplit(version) {
|
|
25
|
+
const parts = /^v?(\d+)\.(\d+)\.(\d+)/.exec(version ?? "");
|
|
26
|
+
if (!parts)
|
|
27
|
+
return false;
|
|
28
|
+
for (let i = 0; i < 3; i += 1) {
|
|
29
|
+
const [at, split] = [Number(parts[i + 1]), OPENCODE_SPLIT[i]];
|
|
30
|
+
if (at !== split)
|
|
31
|
+
return at < split;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
11
35
|
/** Each format's names for input, cache read, cache write, output and the reasoning part of the output (a dotted name is
|
|
12
36
|
* a nested one), and whether its input holds its cache counts. */
|
|
13
37
|
const NAMES = {
|
|
@@ -15,6 +39,7 @@ const NAMES = {
|
|
|
15
39
|
openai: { input: "input_tokens", cacheRead: "cached_input_tokens", cacheWrite: "cache_write_input_tokens", output: "output_tokens", reasoning: "reasoning_output_tokens", cachedIn: true },
|
|
16
40
|
pi: { input: "input", cacheRead: "cacheRead", cacheWrite: "cacheWrite", output: "output", cachedIn: false },
|
|
17
41
|
openrouter: { input: "prompt_tokens", cacheRead: "prompt_tokens_details.cached_tokens", cacheWrite: "prompt_tokens_details.cache_write_tokens", output: "completion_tokens", reasoning: "completion_tokens_details.reasoning_tokens", cachedIn: true },
|
|
42
|
+
copilot: { input: "inputTokens", cacheRead: "cacheReadTokens", cacheWrite: "cacheWriteTokens", output: "outputTokens", reasoning: "reasoningTokens", cachedIn: true },
|
|
18
43
|
};
|
|
19
44
|
const count = (value) => (Number.isSafeInteger(value) && value >= 0 ? value : undefined);
|
|
20
45
|
/** The value at a dotted name in `raw`, undefined where any part is missing. */
|
|
@@ -22,9 +47,11 @@ const at = (raw, name) => name.split(".").reduce((value, part) => (isObject(valu
|
|
|
22
47
|
/** A request's usage as `format` writes it, as Usage; undefined unless input and output are counts (an absent cache
|
|
23
48
|
* count is 0) and the input left is not negative. The 1h part of the cache write, or the reasoning part of the output,
|
|
24
49
|
* is kept only when it is a count of at most the whole. */
|
|
25
|
-
export function normalizeUsage(format, raw) {
|
|
50
|
+
export function normalizeUsage(format, raw, options = {}) {
|
|
26
51
|
if (!isObject(raw))
|
|
27
52
|
return undefined;
|
|
53
|
+
if (format === "opencode")
|
|
54
|
+
return openCodeUsage(raw, beforeSplit(options.version));
|
|
28
55
|
const names = NAMES[format];
|
|
29
56
|
const usage = { input: count(at(raw, names.input)), output: count(at(raw, names.output)), cacheRead: count(at(raw, names.cacheRead) ?? 0), cacheWrite: count(at(raw, names.cacheWrite) ?? 0) };
|
|
30
57
|
if (usage.input === undefined || usage.output === undefined || usage.cacheRead === undefined || usage.cacheWrite === undefined)
|
|
@@ -42,6 +69,20 @@ export function normalizeUsage(format, raw) {
|
|
|
42
69
|
out.reasoning = reasoning;
|
|
43
70
|
return out;
|
|
44
71
|
}
|
|
72
|
+
function openCodeUsage(raw, holdsReasoning) {
|
|
73
|
+
const cache = isObject(raw.cache) ? raw.cache : {};
|
|
74
|
+
const [input, output, reasoning, cacheRead, cacheWrite] = [raw.input, raw.output, raw.reasoning ?? 0, cache.read ?? 0, cache.write ?? 0].map(count);
|
|
75
|
+
if (input === undefined || output === undefined || reasoning === undefined || cacheRead === undefined || cacheWrite === undefined)
|
|
76
|
+
return undefined;
|
|
77
|
+
const total = count(raw.total);
|
|
78
|
+
const left = total === undefined ? -1 : total - input - cacheRead - cacheWrite;
|
|
79
|
+
const usage = { input, output: left >= output ? left : holdsReasoning ? output : output + reasoning, cacheRead, cacheWrite };
|
|
80
|
+
if (usage.input + usage.output + usage.cacheRead + usage.cacheWrite === 0)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (raw.reasoning !== undefined && reasoning <= usage.output)
|
|
83
|
+
usage.reasoning = reasoning;
|
|
84
|
+
return usage;
|
|
85
|
+
}
|
|
45
86
|
export function otelUsage(usage) {
|
|
46
87
|
return { input: usage.input + usage.cacheRead + usage.cacheWrite, output: usage.output, cacheRead: usage.cacheRead, cacheWrite: usage.cacheWrite, ...(usage.reasoning === undefined ? {} : { reasoning: usage.reasoning }) };
|
|
47
88
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-import",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"description": "Reads the coding-agent sessions under a home (Claude Code, Codex, pi) into one Session shape, with normalized token usage, subagents under their parent, byte-offset cursors for re-reads, and per-session totals.",
|
|
3
|
+
"version": "0.1.0-beta.60",
|
|
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",
|
|
7
7
|
"claude-code",
|
|
8
8
|
"codex",
|
|
9
|
+
"copilot",
|
|
9
10
|
"pi",
|
|
11
|
+
"opencode",
|
|
10
12
|
"sessions",
|
|
11
13
|
"usage"
|
|
12
14
|
],
|