rewound 0.4.3 → 0.4.4
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/dist/adapters/codex.js +28 -2
- package/dist/db.js +6 -0
- package/package.json +1 -1
package/dist/adapters/codex.js
CHANGED
|
@@ -2,6 +2,7 @@ import crypto from "node:crypto";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { consumeCompleteLines, walkJsonlFiles } from "./jsonl.js";
|
|
4
4
|
const ROLLOUT_RE = /rollout-.*\.jsonl$/;
|
|
5
|
+
const SCAFFOLDING_RE = /^\s*<(environment_context|user_instructions|permissions_context)\b/;
|
|
5
6
|
const UUID_RE = /([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\.jsonl$/;
|
|
6
7
|
function contentText(content) {
|
|
7
8
|
if (typeof content === "string")
|
|
@@ -40,6 +41,7 @@ export class CodexAdapter {
|
|
|
40
41
|
let startedAt;
|
|
41
42
|
let endedAt;
|
|
42
43
|
let parseErrors = 0;
|
|
44
|
+
let usageDelta;
|
|
43
45
|
const push = (m) => {
|
|
44
46
|
messages.push({ ...m, uuid: messageUuid(m.ts, m.role, m.text || m.toolText || ""), isSidechain: false });
|
|
45
47
|
if (m.ts) {
|
|
@@ -82,8 +84,26 @@ export class CodexAdapter {
|
|
|
82
84
|
model = p.model;
|
|
83
85
|
continue;
|
|
84
86
|
}
|
|
87
|
+
if (record.type === "event_msg") {
|
|
88
|
+
// token_count events carry per-turn usage in last_token_usage; the
|
|
89
|
+
// cumulative total_token_usage is deliberately ignored — summing
|
|
90
|
+
// per-turn deltas stays correct under incremental byte-offset parsing.
|
|
91
|
+
if (p.type === "token_count") {
|
|
92
|
+
const info = p.info;
|
|
93
|
+
const last = info?.last_token_usage;
|
|
94
|
+
if (last) {
|
|
95
|
+
const n = (v) => (typeof v === "number" && Number.isFinite(v) ? v : 0);
|
|
96
|
+
const cached = n(last.cached_input_tokens);
|
|
97
|
+
usageDelta ??= { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
98
|
+
usageDelta.input += Math.max(0, n(last.input_tokens) - cached);
|
|
99
|
+
usageDelta.output += n(last.output_tokens);
|
|
100
|
+
usageDelta.cacheRead += cached;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
85
105
|
if (record.type !== "response_item")
|
|
86
|
-
continue; // compacted,
|
|
106
|
+
continue; // compacted, drift: skip
|
|
87
107
|
const itemType = p.type;
|
|
88
108
|
if (itemType === "message") {
|
|
89
109
|
const role = p.role === "assistant" ? "assistant" : p.role === "user" ? "user" : undefined;
|
|
@@ -92,7 +112,12 @@ export class CodexAdapter {
|
|
|
92
112
|
const text = contentText(p.content);
|
|
93
113
|
if (!text)
|
|
94
114
|
continue;
|
|
95
|
-
|
|
115
|
+
if (role === "user" && SCAFFOLDING_RE.test(text)) {
|
|
116
|
+
push({ role, ts, text: "", toolText: text, tools: [] });
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
push({ role, ts, text, tools: [], model: role === "assistant" ? model : undefined });
|
|
120
|
+
}
|
|
96
121
|
}
|
|
97
122
|
else if (itemType === "reasoning") {
|
|
98
123
|
const text = [contentText(p.summary), contentText(p.content)].filter(Boolean).join("\n\n");
|
|
@@ -120,6 +145,7 @@ export class CodexAdapter {
|
|
|
120
145
|
startedAt,
|
|
121
146
|
endedAt,
|
|
122
147
|
messages,
|
|
148
|
+
usageDelta,
|
|
123
149
|
parseErrors,
|
|
124
150
|
bytesConsumed,
|
|
125
151
|
};
|
package/dist/db.js
CHANGED
|
@@ -215,6 +215,12 @@ export function upsertSessionMessages(db, session, opts) {
|
|
|
215
215
|
}
|
|
216
216
|
return acc;
|
|
217
217
|
}, { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 });
|
|
218
|
+
if (session.usageDelta) {
|
|
219
|
+
usageSums.input += session.usageDelta.input;
|
|
220
|
+
usageSums.output += session.usageDelta.output;
|
|
221
|
+
usageSums.cacheRead += session.usageDelta.cacheRead;
|
|
222
|
+
usageSums.cacheWrite += session.usageDelta.cacheWrite;
|
|
223
|
+
}
|
|
218
224
|
const messageCount = (existing?.messageCount ?? 0) + session.messages.length;
|
|
219
225
|
const inputTokens = (existing?.inputTokens ?? 0) + usageSums.input;
|
|
220
226
|
const outputTokens = (existing?.outputTokens ?? 0) + usageSums.output;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rewound",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Grep for everything your AI coding agents ever did. Local SQLite/FTS5 search over Claude Code session transcripts: CLI, MCP server, and web UI.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "David Erner",
|