@a5c-ai/babysitter-sdk 0.0.186 → 0.0.187-staging.02a0ee21
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/cli/commands/costStats.d.ts +13 -0
- package/dist/cli/commands/costStats.d.ts.map +1 -0
- package/dist/cli/commands/costStats.js +319 -0
- package/dist/cli/commands/harnessPhase2.js +10 -10
- package/dist/cli/commands/instructions.d.ts.map +1 -1
- package/dist/cli/commands/instructions.js +5 -3
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +16 -1
- package/dist/config/defaults.d.ts +10 -0
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +19 -0
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +2 -1
- package/dist/cost/claudeCodeParser.d.ts +81 -0
- package/dist/cost/claudeCodeParser.d.ts.map +1 -0
- package/dist/cost/claudeCodeParser.js +232 -0
- package/dist/cost/collector.d.ts +42 -0
- package/dist/cost/collector.d.ts.map +1 -0
- package/dist/cost/collector.js +105 -0
- package/dist/cost/index.d.ts +18 -0
- package/dist/cost/index.d.ts.map +1 -0
- package/dist/cost/index.js +37 -0
- package/dist/cost/journal.d.ts +40 -0
- package/dist/cost/journal.d.ts.map +1 -0
- package/dist/cost/journal.js +137 -0
- package/dist/cost/types.d.ts +164 -0
- package/dist/cost/types.d.ts.map +1 -0
- package/dist/cost/types.js +231 -0
- package/dist/harness/claudeCode.js +1 -1
- package/dist/harness/cursor.js +1 -1
- package/dist/harness/discovery.d.ts.map +1 -1
- package/dist/harness/discovery.js +8 -1
- package/dist/harness/geminiCli.js +1 -1
- package/dist/harness/githubCopilot.js +1 -1
- package/dist/harness/index.d.ts +1 -0
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +3 -1
- package/dist/harness/invoker.d.ts.map +1 -1
- package/dist/harness/invoker.js +1 -0
- package/dist/harness/openclaw.d.ts +20 -0
- package/dist/harness/openclaw.d.ts.map +1 -0
- package/dist/harness/openclaw.js +338 -0
- package/dist/harness/opencode.d.ts.map +1 -1
- package/dist/harness/opencode.js +75 -5
- package/dist/harness/registry.d.ts.map +1 -1
- package/dist/harness/registry.js +2 -0
- package/dist/hooks/dispatcher.d.ts +9 -0
- package/dist/hooks/dispatcher.d.ts.map +1 -1
- package/dist/hooks/dispatcher.js +94 -0
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/logging/runLogger.js +2 -2
- package/dist/prompts/babysitterMdDiscovery.d.ts +38 -0
- package/dist/prompts/babysitterMdDiscovery.d.ts.map +1 -0
- package/dist/prompts/babysitterMdDiscovery.js +150 -0
- package/dist/prompts/compose.d.ts.map +1 -1
- package/dist/prompts/compose.js +5 -0
- package/dist/prompts/context.d.ts +4 -0
- package/dist/prompts/context.d.ts.map +1 -1
- package/dist/prompts/context.js +37 -0
- package/dist/prompts/index.d.ts +1 -1
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/parts/index.d.ts +3 -0
- package/dist/prompts/parts/index.d.ts.map +1 -1
- package/dist/prompts/parts/index.js +7 -1
- package/dist/prompts/parts/parallelPhaseDetection.d.ts +6 -0
- package/dist/prompts/parts/parallelPhaseDetection.d.ts.map +1 -0
- package/dist/prompts/parts/parallelPhaseDetection.js +10 -0
- package/dist/prompts/parts/projectInstructions.d.ts +8 -0
- package/dist/prompts/parts/projectInstructions.d.ts.map +1 -0
- package/dist/prompts/parts/projectInstructions.js +28 -0
- package/dist/prompts/parts/runOverlapDetection.d.ts +6 -0
- package/dist/prompts/parts/runOverlapDetection.d.ts.map +1 -0
- package/dist/prompts/parts/runOverlapDetection.js +10 -0
- package/dist/prompts/templates/commands/doctor.md +9 -9
- package/dist/prompts/templates/intent-fidelity-checks.md +3 -1
- package/dist/prompts/templates/parallel-phase-detection.md +59 -0
- package/dist/prompts/templates/process-creation.md +9 -2
- package/dist/prompts/templates/process-guidelines.md +5 -2
- package/dist/prompts/templates/run-overlap-detection.md +63 -0
- package/dist/prompts/templates/task-examples.md +47 -0
- package/dist/prompts/templates/task-kinds.md +44 -2
- package/dist/runtime/intrinsics/breakpoint.d.ts.map +1 -1
- package/dist/runtime/intrinsics/breakpoint.js +20 -1
- package/dist/runtime/orchestrateIteration.d.ts.map +1 -1
- package/dist/runtime/orchestrateIteration.js +14 -0
- package/dist/session/types.d.ts +2 -0
- package/dist/session/types.d.ts.map +1 -1
- package/dist/storage/createRunDir.d.ts.map +1 -1
- package/dist/storage/createRunDir.js +2 -0
- package/dist/storage/icloudWarning.d.ts +6 -0
- package/dist/storage/icloudWarning.d.ts.map +1 -0
- package/dist/storage/icloudWarning.js +84 -0
- package/dist/storage/journal.d.ts.map +1 -1
- package/dist/storage/journal.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cost:stats command - Show cost tracking statistics from run journals
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* babysitter cost:stats [runId] [--json] [--all] [--runs-dir <dir>]
|
|
6
|
+
*
|
|
7
|
+
* With runId: reads journal for that run, finds COST_TRACKED events, prints table
|
|
8
|
+
* With --all: aggregates across all runs in the runs directory
|
|
9
|
+
* With --json: outputs JSON instead of table
|
|
10
|
+
*/
|
|
11
|
+
import type { CostStatsOptions } from "../../cost/types";
|
|
12
|
+
export declare function handleCostStats(options: CostStatsOptions): Promise<number>;
|
|
13
|
+
//# sourceMappingURL=costStats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"costStats.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/costStats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,gBAAgB,EAKjB,MAAM,kBAAkB,CAAC;AAwP1B,wBAAsB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAwChF"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* cost:stats command - Show cost tracking statistics from run journals
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* babysitter cost:stats [runId] [--json] [--all] [--runs-dir <dir>]
|
|
7
|
+
*
|
|
8
|
+
* With runId: reads journal for that run, finds COST_TRACKED events, prints table
|
|
9
|
+
* With --all: aggregates across all runs in the runs directory
|
|
10
|
+
* With --json: outputs JSON instead of table
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.handleCostStats = handleCostStats;
|
|
47
|
+
const node_fs_1 = require("node:fs");
|
|
48
|
+
const path = __importStar(require("node:path"));
|
|
49
|
+
const defaults_1 = require("../../config/defaults");
|
|
50
|
+
const storage_1 = require("../../storage");
|
|
51
|
+
const journal_1 = require("../../cost/journal");
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// ANSI Colors
|
|
54
|
+
// ============================================================================
|
|
55
|
+
const COLORS = {
|
|
56
|
+
reset: "\x1b[0m",
|
|
57
|
+
bold: "\x1b[1m",
|
|
58
|
+
dim: "\x1b[2m",
|
|
59
|
+
cyan: "\x1b[36m",
|
|
60
|
+
green: "\x1b[32m",
|
|
61
|
+
yellow: "\x1b[33m",
|
|
62
|
+
red: "\x1b[31m",
|
|
63
|
+
};
|
|
64
|
+
function supportsColors() {
|
|
65
|
+
if (process.env.NO_COLOR !== undefined)
|
|
66
|
+
return false;
|
|
67
|
+
if (process.env.FORCE_COLOR !== undefined)
|
|
68
|
+
return true;
|
|
69
|
+
return Boolean(process.stdout?.isTTY);
|
|
70
|
+
}
|
|
71
|
+
function col(text, color, useColors) {
|
|
72
|
+
return useColors ? `${COLORS[color]}${text}${COLORS.reset}` : text;
|
|
73
|
+
}
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Single Run
|
|
76
|
+
// ============================================================================
|
|
77
|
+
async function costStatsForRun(runsDir, runId) {
|
|
78
|
+
const runDir = path.join(runsDir, runId);
|
|
79
|
+
let stat;
|
|
80
|
+
try {
|
|
81
|
+
stat = await node_fs_1.promises.stat(runDir);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (!stat.isDirectory())
|
|
87
|
+
return null;
|
|
88
|
+
const events = await (0, storage_1.loadJournal)(runDir);
|
|
89
|
+
return (0, journal_1.computeRunCostStats)(runId, events);
|
|
90
|
+
}
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// All Runs
|
|
93
|
+
// ============================================================================
|
|
94
|
+
async function costStatsForAllRuns(runsDir) {
|
|
95
|
+
let entries;
|
|
96
|
+
try {
|
|
97
|
+
entries = await node_fs_1.promises.readdir(runsDir);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
entries = [];
|
|
101
|
+
}
|
|
102
|
+
const runs = [];
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
const runDir = path.join(runsDir, entry);
|
|
105
|
+
try {
|
|
106
|
+
const s = await node_fs_1.promises.stat(runDir);
|
|
107
|
+
if (!s.isDirectory())
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const events = await (0, storage_1.loadJournal)(runDir);
|
|
114
|
+
const stats = (0, journal_1.computeRunCostStats)(entry, events);
|
|
115
|
+
if (stats.eventCount === 0)
|
|
116
|
+
continue;
|
|
117
|
+
runs.push(stats);
|
|
118
|
+
}
|
|
119
|
+
let totalInputTokens = 0;
|
|
120
|
+
let totalOutputTokens = 0;
|
|
121
|
+
let totalCacheCreation = 0;
|
|
122
|
+
let totalCacheRead = 0;
|
|
123
|
+
let totalCostUsd = 0;
|
|
124
|
+
let totalEvents = 0;
|
|
125
|
+
for (const r of runs) {
|
|
126
|
+
totalInputTokens += r.totalInputTokens;
|
|
127
|
+
totalOutputTokens += r.totalOutputTokens;
|
|
128
|
+
totalCacheCreation += r.totalCacheCreation;
|
|
129
|
+
totalCacheRead += r.totalCacheRead;
|
|
130
|
+
totalCostUsd += r.totalCostUsd;
|
|
131
|
+
totalEvents += r.eventCount;
|
|
132
|
+
}
|
|
133
|
+
totalCostUsd = Math.round(totalCostUsd * 1_000_000) / 1_000_000;
|
|
134
|
+
return {
|
|
135
|
+
totalRuns: runs.length,
|
|
136
|
+
totalEvents,
|
|
137
|
+
totalInputTokens,
|
|
138
|
+
totalOutputTokens,
|
|
139
|
+
totalCacheCreation,
|
|
140
|
+
totalCacheRead,
|
|
141
|
+
totalCostUsd,
|
|
142
|
+
overallCostUsd: totalCostUsd,
|
|
143
|
+
runs,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
// ============================================================================
|
|
147
|
+
// Formatting
|
|
148
|
+
// ============================================================================
|
|
149
|
+
function fmtNum(n) {
|
|
150
|
+
return n.toLocaleString("en-US");
|
|
151
|
+
}
|
|
152
|
+
function fmtUsd(n) {
|
|
153
|
+
return `$${n.toFixed(4)}`;
|
|
154
|
+
}
|
|
155
|
+
function pad(s, width, right = false) {
|
|
156
|
+
if (right)
|
|
157
|
+
return s.padStart(width);
|
|
158
|
+
return s.padEnd(width);
|
|
159
|
+
}
|
|
160
|
+
function printSingleRunTable(stats, useColors) {
|
|
161
|
+
console.log("");
|
|
162
|
+
console.log(col(`Run: ${stats.runId}`, "bold", useColors));
|
|
163
|
+
console.log(col(`Date: ${stats.date}`, "dim", useColors));
|
|
164
|
+
console.log("");
|
|
165
|
+
if (stats.eventCount === 0) {
|
|
166
|
+
console.log(col(" No COST_TRACKED events found in this run.", "yellow", useColors));
|
|
167
|
+
console.log("");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// Summary row
|
|
171
|
+
console.log(col(" Summary", "cyan", useColors));
|
|
172
|
+
console.log(` Events: ${col(fmtNum(stats.eventCount), "bold", useColors)}`);
|
|
173
|
+
console.log(` Input tokens: ${col(fmtNum(stats.totalInputTokens), "bold", useColors)}`);
|
|
174
|
+
console.log(` Output tokens: ${col(fmtNum(stats.totalOutputTokens), "bold", useColors)}`);
|
|
175
|
+
console.log(` Cache write: ${col(fmtNum(stats.totalCacheCreation), "bold", useColors)}`);
|
|
176
|
+
console.log(` Cache read: ${col(fmtNum(stats.totalCacheRead), "bold", useColors)}`);
|
|
177
|
+
console.log(` Total cost: ${col(fmtUsd(stats.totalCostUsd), "green", useColors)}`);
|
|
178
|
+
console.log("");
|
|
179
|
+
// Per-model breakdown
|
|
180
|
+
const models = Object.keys(stats.byModel).sort();
|
|
181
|
+
if (models.length > 0) {
|
|
182
|
+
console.log(col(" By Model", "cyan", useColors));
|
|
183
|
+
const hdr = [
|
|
184
|
+
pad("Model", 24),
|
|
185
|
+
pad("Events", 8, true),
|
|
186
|
+
pad("Input Tokens", 14, true),
|
|
187
|
+
pad("Output Tokens", 15, true),
|
|
188
|
+
pad("Cache Write", 13, true),
|
|
189
|
+
pad("Cache Read", 12, true),
|
|
190
|
+
pad("Cost ($)", 12, true),
|
|
191
|
+
].join(" ");
|
|
192
|
+
console.log(col(` ${hdr}`, "dim", useColors));
|
|
193
|
+
console.log(col(` ${"-".repeat(hdr.length)}`, "dim", useColors));
|
|
194
|
+
for (const model of models) {
|
|
195
|
+
const m = stats.byModel[model];
|
|
196
|
+
const row = [
|
|
197
|
+
pad(m.model, 24),
|
|
198
|
+
pad(fmtNum(m.eventCount), 8, true),
|
|
199
|
+
pad(fmtNum(m.inputTokens), 14, true),
|
|
200
|
+
pad(fmtNum(m.outputTokens), 15, true),
|
|
201
|
+
pad(fmtNum(m.cacheCreationTokens), 13, true),
|
|
202
|
+
pad(fmtNum(m.cacheReadTokens), 12, true),
|
|
203
|
+
pad(fmtUsd(m.costUsd), 12, true),
|
|
204
|
+
].join(" ");
|
|
205
|
+
console.log(` ${row}`);
|
|
206
|
+
}
|
|
207
|
+
console.log("");
|
|
208
|
+
}
|
|
209
|
+
// Per-kind breakdown
|
|
210
|
+
const kinds = Object.keys(stats.byKind).sort();
|
|
211
|
+
if (kinds.length > 0) {
|
|
212
|
+
console.log(col(" By Task Kind", "cyan", useColors));
|
|
213
|
+
const hdr = [
|
|
214
|
+
pad("Kind", 24),
|
|
215
|
+
pad("Events", 8, true),
|
|
216
|
+
pad("Cost ($)", 12, true),
|
|
217
|
+
].join(" ");
|
|
218
|
+
console.log(col(` ${hdr}`, "dim", useColors));
|
|
219
|
+
console.log(col(` ${"-".repeat(hdr.length)}`, "dim", useColors));
|
|
220
|
+
for (const kind of kinds) {
|
|
221
|
+
const k = stats.byKind[kind];
|
|
222
|
+
const row = [
|
|
223
|
+
pad(k.kind, 24),
|
|
224
|
+
pad(fmtNum(k.eventCount), 8, true),
|
|
225
|
+
pad(fmtUsd(k.costUsd), 12, true),
|
|
226
|
+
].join(" ");
|
|
227
|
+
console.log(` ${row}`);
|
|
228
|
+
}
|
|
229
|
+
console.log("");
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function printAggregateTable(agg, useColors) {
|
|
233
|
+
console.log("");
|
|
234
|
+
console.log(col("Cost Stats \u2014 All Runs", "bold", useColors));
|
|
235
|
+
console.log("");
|
|
236
|
+
if (agg.totalRuns === 0) {
|
|
237
|
+
console.log(col(" No runs with COST_TRACKED events found.", "yellow", useColors));
|
|
238
|
+
console.log("");
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
console.log(` Total runs with cost data: ${col(fmtNum(agg.totalRuns), "bold", useColors)}`);
|
|
242
|
+
console.log(` Total events: ${col(fmtNum(agg.totalEvents), "bold", useColors)}`);
|
|
243
|
+
console.log(` Total input tokens: ${col(fmtNum(agg.totalInputTokens), "bold", useColors)}`);
|
|
244
|
+
console.log(` Total output tokens: ${col(fmtNum(agg.totalOutputTokens), "bold", useColors)}`);
|
|
245
|
+
console.log(` Total cache write: ${col(fmtNum(agg.totalCacheCreation), "bold", useColors)}`);
|
|
246
|
+
console.log(` Total cache read: ${col(fmtNum(agg.totalCacheRead), "bold", useColors)}`);
|
|
247
|
+
console.log(` Total cost: ${col(fmtUsd(agg.totalCostUsd), "green", useColors)}`);
|
|
248
|
+
console.log("");
|
|
249
|
+
if (agg.runs.length > 0) {
|
|
250
|
+
console.log(col(" Per-Run Breakdown", "cyan", useColors));
|
|
251
|
+
const hdr = [
|
|
252
|
+
pad("Run ID", 28),
|
|
253
|
+
pad("Date", 24),
|
|
254
|
+
pad("Events", 8, true),
|
|
255
|
+
pad("Input", 12, true),
|
|
256
|
+
pad("Output", 12, true),
|
|
257
|
+
pad("Cost ($)", 12, true),
|
|
258
|
+
].join(" ");
|
|
259
|
+
console.log(col(` ${hdr}`, "dim", useColors));
|
|
260
|
+
console.log(col(` ${"-".repeat(hdr.length)}`, "dim", useColors));
|
|
261
|
+
const sorted = [...agg.runs].sort((a, b) => b.totalCostUsd - a.totalCostUsd);
|
|
262
|
+
for (const r of sorted) {
|
|
263
|
+
const row = [
|
|
264
|
+
pad(r.runId, 28),
|
|
265
|
+
pad(r.date.slice(0, 24), 24),
|
|
266
|
+
pad(fmtNum(r.eventCount), 8, true),
|
|
267
|
+
pad(fmtNum(r.totalInputTokens), 12, true),
|
|
268
|
+
pad(fmtNum(r.totalOutputTokens), 12, true),
|
|
269
|
+
pad(fmtUsd(r.totalCostUsd), 12, true),
|
|
270
|
+
].join(" ");
|
|
271
|
+
console.log(` ${row}`);
|
|
272
|
+
}
|
|
273
|
+
console.log("");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// ============================================================================
|
|
277
|
+
// Main Handler
|
|
278
|
+
// ============================================================================
|
|
279
|
+
async function handleCostStats(options) {
|
|
280
|
+
const runsDir = options.runsDir ?? process.env[defaults_1.CONFIG_ENV_VARS.RUNS_DIR] ?? defaults_1.DEFAULTS.runsDir;
|
|
281
|
+
const resolvedRunsDir = path.resolve(runsDir);
|
|
282
|
+
const useColors = supportsColors();
|
|
283
|
+
if (options.all) {
|
|
284
|
+
const agg = await costStatsForAllRuns(resolvedRunsDir);
|
|
285
|
+
if (options.json) {
|
|
286
|
+
console.log(JSON.stringify(agg, null, 2));
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
printAggregateTable(agg, useColors);
|
|
290
|
+
}
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
if (options.runId) {
|
|
294
|
+
const stats = await costStatsForRun(resolvedRunsDir, options.runId);
|
|
295
|
+
if (!stats) {
|
|
296
|
+
const msg = `Run not found: ${options.runId} (looked in ${resolvedRunsDir})`;
|
|
297
|
+
if (options.json) {
|
|
298
|
+
console.error(JSON.stringify({ error: msg }));
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
console.error(msg);
|
|
302
|
+
}
|
|
303
|
+
return 1;
|
|
304
|
+
}
|
|
305
|
+
if (options.json) {
|
|
306
|
+
console.log(JSON.stringify(stats, null, 2));
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
printSingleRunTable(stats, useColors);
|
|
310
|
+
}
|
|
311
|
+
return 0;
|
|
312
|
+
}
|
|
313
|
+
// No runId and no --all: print help
|
|
314
|
+
console.error("Usage: babysitter cost:stats [runId] [--all] [--json] [--runs-dir <dir>]");
|
|
315
|
+
console.error(" runId Show cost stats for a specific run");
|
|
316
|
+
console.error(" --all Aggregate cost stats across all runs");
|
|
317
|
+
console.error(" --json Output JSON instead of table");
|
|
318
|
+
return 1;
|
|
319
|
+
}
|
|
@@ -126,22 +126,22 @@ async function resolveEffect(action, harnessName, options, piSession, discovered
|
|
|
126
126
|
if (piSession) {
|
|
127
127
|
const bashCommand = [command, ...shellArgs.map(harnessUtils_1.shellQuoteArg)].join(" ");
|
|
128
128
|
const bashResult = await piSession.executeBash(bashCommand);
|
|
129
|
+
const ok = bashResult.exitCode === 0;
|
|
129
130
|
return {
|
|
130
|
-
status:
|
|
131
|
-
value:
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
: new Error(`Shell command exited with code ${bashResult.exitCode ?? "null"}: ${bashResult.output}`),
|
|
131
|
+
status: "ok",
|
|
132
|
+
value: ok
|
|
133
|
+
? bashResult.output
|
|
134
|
+
: { success: false, exitCode: bashResult.exitCode ?? 1, stdout: bashResult.output, stderr: "", error: `Shell command exited with code ${bashResult.exitCode ?? "null"}: ${bashResult.output}` },
|
|
135
135
|
stdout: bashResult.output,
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
const shellResult = await (0, harnessPhase1_1.execShellEffect)(command, shellArgs, cwd);
|
|
139
|
+
const shellOk = shellResult.exitCode === 0;
|
|
139
140
|
return {
|
|
140
|
-
status:
|
|
141
|
-
value:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
: new Error(`Shell command exited with code ${shellResult.exitCode}: ${shellResult.stderr}`),
|
|
141
|
+
status: "ok",
|
|
142
|
+
value: shellOk
|
|
143
|
+
? shellResult.stdout
|
|
144
|
+
: { success: false, exitCode: shellResult.exitCode, stdout: shellResult.stdout, stderr: shellResult.stderr, error: `Shell command exited with code ${shellResult.exitCode}: ${shellResult.stderr}` },
|
|
145
145
|
stdout: shellResult.stdout,
|
|
146
146
|
stderr: shellResult.stderr,
|
|
147
147
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoBH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,eAAe,GAAG,gBAAgB,GAAG,aAAa,GAAG,qBAAqB,CAAC;IACvF,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/instructions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAoBH,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,eAAe,GAAG,gBAAgB,GAAG,aAAa,GAAG,qBAAqB,CAAC;IACvF,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;CACf;AAqID;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAmFjB"}
|
|
@@ -30,11 +30,12 @@ const COMPOSERS = {
|
|
|
30
30
|
promptType: "babysit-skill",
|
|
31
31
|
partsIncluded: [
|
|
32
32
|
"non-negotiables", "dependencies", "interview", "user-profile",
|
|
33
|
-
"process-creation", "intent-fidelity-checks", "run-creation",
|
|
33
|
+
"process-creation", "intent-fidelity-checks", "run-overlap-detection", "run-creation",
|
|
34
34
|
"iteration", "effects", "breakpoint-handling", "results-posting",
|
|
35
35
|
"loop-control", "completion-proof", "task-kinds", "task-examples",
|
|
36
36
|
"quick-reference", "recovery", "process-guidelines", "critical-rules",
|
|
37
37
|
"see-also",
|
|
38
|
+
"project-instructions",
|
|
38
39
|
],
|
|
39
40
|
},
|
|
40
41
|
"process-create": {
|
|
@@ -43,14 +44,15 @@ const COMPOSERS = {
|
|
|
43
44
|
partsIncluded: [
|
|
44
45
|
"interview", "user-profile", "process-creation",
|
|
45
46
|
"intent-fidelity-checks", "process-guidelines",
|
|
46
|
-
"task-kinds", "task-examples",
|
|
47
|
+
"parallel-phase-detection", "task-kinds", "task-examples",
|
|
48
|
+
"project-instructions",
|
|
47
49
|
],
|
|
48
50
|
},
|
|
49
51
|
"orchestrate": {
|
|
50
52
|
fn: prompts_1.composeOrchestrationPrompt,
|
|
51
53
|
promptType: "orchestrate",
|
|
52
54
|
partsIncluded: [
|
|
53
|
-
"run-creation", "iteration", "effects", "breakpoint-handling",
|
|
55
|
+
"run-overlap-detection", "run-creation", "iteration", "effects", "breakpoint-handling",
|
|
54
56
|
"results-posting", "loop-control", "completion-proof",
|
|
55
57
|
"quick-reference", "recovery", "critical-rules",
|
|
56
58
|
],
|
package/dist/cli/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,sBAAsB,IAAI,6BAA6B,EAAoB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,sBAAsB,IAAI,6BAA6B,EAAoB,MAAM,oBAAoB,CAAC;AAixB/G;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BlE;AAOD,2EAA2E;AAC3E,QAAA,MAAM,sBAAsB,sCAAgC,CAAC;AA0tD7D,OAAO,EAAE,aAAa,IAAI,cAAc,EAAE,sBAAsB,IAAI,uBAAuB,EAAE,CAAC;AAE9F,wBAAgB,mBAAmB;eAEf,MAAM,EAAE,GAA2B,OAAO,CAAC,MAAM,CAAC;kBAkqBpD,MAAM;EAIvB"}
|
package/dist/cli/main.js
CHANGED
|
@@ -63,6 +63,7 @@ const profile_1 = require("./commands/profile");
|
|
|
63
63
|
const processLibrary_1 = require("./commands/processLibrary");
|
|
64
64
|
const plugin_1 = require("./commands/plugin");
|
|
65
65
|
const tokensStats_1 = require("./commands/tokensStats");
|
|
66
|
+
const costStats_1 = require("./commands/costStats");
|
|
66
67
|
const compressionStatus_1 = require("./commands/compressionStatus");
|
|
67
68
|
const compressionToggle_1 = require("./commands/compressionToggle");
|
|
68
69
|
const compressionReset_1 = require("./commands/compressionReset");
|
|
@@ -121,6 +122,7 @@ Other commands (agents should never call these directly unless explicitly instru
|
|
|
121
122
|
babysitter plugin:update-registry [<pluginName>] [--plugin-name <name>] [--plugin-version <ver>] [--global|--project] [--json] [--verbose]
|
|
122
123
|
babysitter plugin:remove-from-registry [<pluginName>] [--plugin-name <name>] [--global|--project] [--json] [--verbose]
|
|
123
124
|
babysitter tokens:stats [runId] [--all] [--runs-dir <dir>] [--json]
|
|
125
|
+
babysitter cost:stats [runId] [--all] [--runs-dir <dir>] [--json]
|
|
124
126
|
babysitter compression:status [--json]
|
|
125
127
|
babysitter compression:toggle <layer> <on|off> [--json]
|
|
126
128
|
babysitter compression:set <layer.key> <value> [--json]
|
|
@@ -549,9 +551,10 @@ function parseArgs(argv) {
|
|
|
549
551
|
parsed.keepDays = parsePositiveInteger(raw, "--keep-days");
|
|
550
552
|
continue;
|
|
551
553
|
}
|
|
552
|
-
// tokens:stats flags
|
|
554
|
+
// tokens:stats / cost:stats flags
|
|
553
555
|
if (arg === "--all") {
|
|
554
556
|
parsed.tokensAll = true;
|
|
557
|
+
parsed.costAll = true;
|
|
555
558
|
parsed.retrospectAll = true;
|
|
556
559
|
continue;
|
|
557
560
|
}
|
|
@@ -593,6 +596,9 @@ function parseArgs(argv) {
|
|
|
593
596
|
else if (parsed.command === "tokens:stats") {
|
|
594
597
|
[parsed.tokensRunId] = positionals;
|
|
595
598
|
}
|
|
599
|
+
else if (parsed.command === "cost:stats") {
|
|
600
|
+
[parsed.costRunId] = positionals;
|
|
601
|
+
}
|
|
596
602
|
else if (parsed.command === "compression:toggle") {
|
|
597
603
|
const [layer, onOff] = positionals;
|
|
598
604
|
parsed.compressionLayer = layer;
|
|
@@ -2052,6 +2058,7 @@ const VALID_COMMANDS = [
|
|
|
2052
2058
|
"health",
|
|
2053
2059
|
"configure",
|
|
2054
2060
|
"tokens:stats",
|
|
2061
|
+
"cost:stats",
|
|
2055
2062
|
"compression:status",
|
|
2056
2063
|
"compression:toggle",
|
|
2057
2064
|
"compression:set",
|
|
@@ -2900,6 +2907,14 @@ function createBabysitterCli() {
|
|
|
2900
2907
|
runsDir: parsed.runsDir,
|
|
2901
2908
|
});
|
|
2902
2909
|
}
|
|
2910
|
+
if (parsed.command === "cost:stats") {
|
|
2911
|
+
return await (0, costStats_1.handleCostStats)({
|
|
2912
|
+
runId: parsed.costRunId,
|
|
2913
|
+
all: parsed.costAll,
|
|
2914
|
+
json: parsed.json,
|
|
2915
|
+
runsDir: parsed.runsDir,
|
|
2916
|
+
});
|
|
2917
|
+
}
|
|
2903
2918
|
// Compression commands
|
|
2904
2919
|
if (parsed.command === "compression:status") {
|
|
2905
2920
|
return (0, compressionStatus_1.handleCompressionStatus)({ json: parsed.json });
|
|
@@ -122,6 +122,16 @@ export declare const DEFAULTS: Readonly<BabysitterConfig>;
|
|
|
122
122
|
* Override: set BABYSITTER_STATE_DIR to use a different path.
|
|
123
123
|
*/
|
|
124
124
|
export declare function getGlobalStateDir(): string;
|
|
125
|
+
/**
|
|
126
|
+
* Returns the global babysitter log directory (~/.a5c/logs/).
|
|
127
|
+
*
|
|
128
|
+
* Structured hook/CLI/process logs are user-global by default so every
|
|
129
|
+
* harness entrypoint resolves the same log root regardless of plugin install
|
|
130
|
+
* location or current working directory.
|
|
131
|
+
*
|
|
132
|
+
* Override: set BABYSITTER_LOG_DIR to use a different path.
|
|
133
|
+
*/
|
|
134
|
+
export declare function getGlobalLogDir(): string;
|
|
125
135
|
/**
|
|
126
136
|
* Retrieves configuration with environment variable overrides merged in.
|
|
127
137
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CASlB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAwEtC,CAAC;AAEX;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAQ1C;AAiDD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAqCjF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,sBAAsB,CA2E/E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAEjE"}
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;;OAGG;IACH,eAAe,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CASlB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,gBAAgB,CAwEtC,CAAC;AAEX;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAQ1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAQxC;AAiDD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAqCjF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,sBAAsB,CA2E/E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAEjE"}
|
package/dist/config/defaults.js
CHANGED
|
@@ -42,6 +42,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
43
|
exports.DEFAULTS = exports.CONFIG_ENV_VARS = void 0;
|
|
44
44
|
exports.getGlobalStateDir = getGlobalStateDir;
|
|
45
|
+
exports.getGlobalLogDir = getGlobalLogDir;
|
|
45
46
|
exports.getConfig = getConfig;
|
|
46
47
|
exports.validateConfig = validateConfig;
|
|
47
48
|
exports.getDefaults = getDefaults;
|
|
@@ -148,6 +149,24 @@ function getGlobalStateDir() {
|
|
|
148
149
|
: path.join(os.homedir(), ".a5c");
|
|
149
150
|
return path.join(globalRoot, "state");
|
|
150
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Returns the global babysitter log directory (~/.a5c/logs/).
|
|
154
|
+
*
|
|
155
|
+
* Structured hook/CLI/process logs are user-global by default so every
|
|
156
|
+
* harness entrypoint resolves the same log root regardless of plugin install
|
|
157
|
+
* location or current working directory.
|
|
158
|
+
*
|
|
159
|
+
* Override: set BABYSITTER_LOG_DIR to use a different path.
|
|
160
|
+
*/
|
|
161
|
+
function getGlobalLogDir() {
|
|
162
|
+
if (process.env.BABYSITTER_LOG_DIR) {
|
|
163
|
+
return path.resolve(process.env.BABYSITTER_LOG_DIR);
|
|
164
|
+
}
|
|
165
|
+
const globalRoot = process.env.BABYSITTER_GLOBAL_STATE_DIR?.trim()
|
|
166
|
+
? path.resolve(process.env.BABYSITTER_GLOBAL_STATE_DIR)
|
|
167
|
+
: path.join(os.homedir(), ".a5c");
|
|
168
|
+
return path.join(globalRoot, "logs");
|
|
169
|
+
}
|
|
151
170
|
/**
|
|
152
171
|
* Valid log levels for validation
|
|
153
172
|
*/
|
package/dist/config/index.d.ts
CHANGED
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
* }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export { type LogLevel, type BabysitterConfig, type ConfigValidationResult, DEFAULTS, CONFIG_ENV_VARS, getConfig, getGlobalStateDir, validateConfig, getDefaults, isValidLogLevel, } from "./defaults";
|
|
24
|
+
export { type LogLevel, type BabysitterConfig, type ConfigValidationResult, DEFAULTS, CONFIG_ENV_VARS, getConfig, getGlobalLogDir, getGlobalStateDir, validateConfig, getDefaults, isValidLogLevel, } from "./defaults";
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAG3B,QAAQ,EACR,eAAe,EAGf,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAG3B,QAAQ,EACR,eAAe,EAGf,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,eAAe,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/config/index.js
CHANGED
|
@@ -23,13 +23,14 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isValidLogLevel = exports.getDefaults = exports.validateConfig = exports.getGlobalStateDir = exports.getConfig = exports.CONFIG_ENV_VARS = exports.DEFAULTS = void 0;
|
|
26
|
+
exports.isValidLogLevel = exports.getDefaults = exports.validateConfig = exports.getGlobalStateDir = exports.getGlobalLogDir = exports.getConfig = exports.CONFIG_ENV_VARS = exports.DEFAULTS = void 0;
|
|
27
27
|
var defaults_1 = require("./defaults");
|
|
28
28
|
// Constants
|
|
29
29
|
Object.defineProperty(exports, "DEFAULTS", { enumerable: true, get: function () { return defaults_1.DEFAULTS; } });
|
|
30
30
|
Object.defineProperty(exports, "CONFIG_ENV_VARS", { enumerable: true, get: function () { return defaults_1.CONFIG_ENV_VARS; } });
|
|
31
31
|
// Functions
|
|
32
32
|
Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return defaults_1.getConfig; } });
|
|
33
|
+
Object.defineProperty(exports, "getGlobalLogDir", { enumerable: true, get: function () { return defaults_1.getGlobalLogDir; } });
|
|
33
34
|
Object.defineProperty(exports, "getGlobalStateDir", { enumerable: true, get: function () { return defaults_1.getGlobalStateDir; } });
|
|
34
35
|
Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return defaults_1.validateConfig; } });
|
|
35
36
|
Object.defineProperty(exports, "getDefaults", { enumerable: true, get: function () { return defaults_1.getDefaults; } });
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code JSONL session file parser for cost data collection.
|
|
3
|
+
*
|
|
4
|
+
* Parses Claude Code session JSONL files (main session and subagent files)
|
|
5
|
+
* to extract token usage data and compute costs. Each assistant message with
|
|
6
|
+
* a `usage` block becomes a {@link CostEventData} entry.
|
|
7
|
+
*
|
|
8
|
+
* JSONL format (one JSON object per line):
|
|
9
|
+
* ```json
|
|
10
|
+
* {
|
|
11
|
+
* "type": "assistant",
|
|
12
|
+
* "message": {
|
|
13
|
+
* "model": "claude-opus-4-6",
|
|
14
|
+
* "usage": {
|
|
15
|
+
* "input_tokens": 3,
|
|
16
|
+
* "cache_creation_input_tokens": 26928,
|
|
17
|
+
* "cache_read_input_tokens": 0,
|
|
18
|
+
* "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 26928 },
|
|
19
|
+
* "output_tokens": 28,
|
|
20
|
+
* "service_tier": "standard"
|
|
21
|
+
* }
|
|
22
|
+
* },
|
|
23
|
+
* "timestamp": "2026-04-05T..."
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { CostEventData, ModelCostStats } from "./types";
|
|
28
|
+
/**
|
|
29
|
+
* Parse a single Claude Code session JSONL file into cost events.
|
|
30
|
+
*
|
|
31
|
+
* Reads the file, splits by newline, and for each line that represents an
|
|
32
|
+
* assistant message with usage data, extracts token counts and computes
|
|
33
|
+
* the USD cost using the extended pricing model.
|
|
34
|
+
*
|
|
35
|
+
* @param sessionJsonlPath - Absolute path to the `.jsonl` file.
|
|
36
|
+
* @returns Array of cost events extracted from assistant messages.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseClaudeCodeSession(sessionJsonlPath: string): Promise<CostEventData[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Parse a Claude Code session JSONL file and all associated subagent files.
|
|
41
|
+
*
|
|
42
|
+
* Subagent files live at `<sessionDir>/subagents/agent-*.jsonl` where
|
|
43
|
+
* `<sessionDir>` is derived by stripping the `.jsonl` extension from the
|
|
44
|
+
* main session file path.
|
|
45
|
+
*
|
|
46
|
+
* @param sessionJsonlPath - Absolute path to the main session `.jsonl` file.
|
|
47
|
+
* @returns Merged array of cost events from the main session and all subagents.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseClaudeCodeSessionWithSubagents(sessionJsonlPath: string): Promise<CostEventData[]>;
|
|
50
|
+
/** Aggregated usage summary returned by {@link aggregateUsageData}. */
|
|
51
|
+
export interface AggregatedUsage {
|
|
52
|
+
/** Total number of cost events. */
|
|
53
|
+
eventCount: number;
|
|
54
|
+
/** Total base input tokens across all events. */
|
|
55
|
+
totalInputTokens: number;
|
|
56
|
+
/** Total output tokens across all events. */
|
|
57
|
+
totalOutputTokens: number;
|
|
58
|
+
/** Total cache-creation tokens (top-level) across all events. */
|
|
59
|
+
totalCacheCreationTokens: number;
|
|
60
|
+
/** Total cache-read tokens across all events. */
|
|
61
|
+
totalCacheReadTokens: number;
|
|
62
|
+
/** Total 5-minute cache-creation tokens. */
|
|
63
|
+
totalCacheCreation5mTokens: number;
|
|
64
|
+
/** Total 1-hour cache-creation tokens. */
|
|
65
|
+
totalCacheCreation1hTokens: number;
|
|
66
|
+
/** Total computed cost in USD. */
|
|
67
|
+
totalCostUsd: number;
|
|
68
|
+
/** Per-model breakdown of usage statistics. */
|
|
69
|
+
byModel: Record<string, ModelCostStats>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Aggregate usage data across an array of cost events.
|
|
73
|
+
*
|
|
74
|
+
* Sums token counts and costs, producing both overall totals and a
|
|
75
|
+
* per-model breakdown.
|
|
76
|
+
*
|
|
77
|
+
* @param events - Array of cost events (e.g. from {@link parseClaudeCodeSessionWithSubagents}).
|
|
78
|
+
* @returns Aggregated usage summary with per-model breakdown.
|
|
79
|
+
*/
|
|
80
|
+
export declare function aggregateUsageData(events: CostEventData[]): AggregatedUsage;
|
|
81
|
+
//# sourceMappingURL=claudeCodeParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claudeCodeParser.d.ts","sourceRoot":"","sources":["../../src/cost/claudeCodeParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAqC7D;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CA+D1B;AAMD;;;;;;;;;GASG;AACH,wBAAsB,mCAAmC,CACvD,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,aAAa,EAAE,CAAC,CA+B1B;AAMD,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,gBAAgB,EAAE,MAAM,CAAC;IACzB,6CAA6C;IAC7C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,wBAAwB,EAAE,MAAM,CAAC;IACjC,iDAAiD;IACjD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,4CAA4C;IAC5C,0BAA0B,EAAE,MAAM,CAAC;IACnC,0CAA0C;IAC1C,0BAA0B,EAAE,MAAM,CAAC;IACnC,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe,CAqD3E"}
|