@compaction/cli 0.1.4 → 0.2.0
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 +11 -1
- package/dist/cli/commands/compact.js +15 -6
- package/dist/cli/commands/context.d.ts +2 -0
- package/dist/cli/commands/context.js +130 -0
- package/dist/cli/commands/import.js +3 -1
- package/dist/cli/commands/run.js +13 -6
- package/dist/cli/index.js +4 -1
- package/dist/core/context-store-eval-cases.d.ts +6 -0
- package/dist/core/context-store-eval-cases.js +331 -0
- package/dist/core/context-store-eval.d.ts +140 -0
- package/dist/core/context-store-eval.js +138 -0
- package/dist/core/context-store-fs.d.ts +73 -0
- package/dist/core/context-store-fs.js +157 -0
- package/dist/core/context-store-sufficiency.d.ts +98 -0
- package/dist/core/context-store-sufficiency.js +135 -0
- package/dist/core/context-store.d.ts +155 -0
- package/dist/core/context-store.js +228 -0
- package/dist/core/report-generator.d.ts +19 -1
- package/dist/core/report-generator.js +51 -0
- package/dist/core/run-aggregator.d.ts +45 -0
- package/dist/core/run-aggregator.js +64 -0
- package/dist/core/trace-adapters.d.ts +8 -0
- package/dist/core/trace-adapters.js +4 -0
- package/dist/core/types.d.ts +33 -0
- package/package.json +1 -1
|
@@ -26,6 +26,58 @@ function roundTo(value, digits) {
|
|
|
26
26
|
const factor = 10 ** digits;
|
|
27
27
|
return Math.round((value + Number.EPSILON) * factor) / factor;
|
|
28
28
|
}
|
|
29
|
+
/** Minimum DISTINCT runs for a measured (not single-anecdote) estimate delta. */
|
|
30
|
+
export const MIN_RUNS_FOR_MEASURED_DELTA = 3;
|
|
31
|
+
/**
|
|
32
|
+
* Compute the measured-across-distinct-runs estimate delta over a set of per-run percent
|
|
33
|
+
* reductions (PURE). Applies the accepted criterion: N ≥ 3 AND the mean ±2·SE interval excludes
|
|
34
|
+
* zero. Estimate-class only — the result is NEVER billing-confirmed or eval-backed. Uses the
|
|
35
|
+
* sample standard deviation (n−1); with n<2 there is no dispersion (SE 0) so it cannot qualify.
|
|
36
|
+
*/
|
|
37
|
+
export function computeMeasuredEstimateDelta(percentReductions) {
|
|
38
|
+
const n = percentReductions.length;
|
|
39
|
+
const mean = n === 0 ? 0 : percentReductions.reduce((sum, x) => sum + x, 0) / n;
|
|
40
|
+
let se = 0;
|
|
41
|
+
if (n >= 2) {
|
|
42
|
+
const variance = percentReductions.reduce((sum, x) => sum + (x - mean) ** 2, 0) / (n - 1);
|
|
43
|
+
se = Math.sqrt(variance) / Math.sqrt(n);
|
|
44
|
+
}
|
|
45
|
+
const ciLow = mean - 2 * se;
|
|
46
|
+
const ciHigh = mean + 2 * se;
|
|
47
|
+
const excludesZero = ciLow > 0;
|
|
48
|
+
const qualifies = n >= MIN_RUNS_FOR_MEASURED_DELTA && excludesZero;
|
|
49
|
+
const meanR = roundTo(mean, 2);
|
|
50
|
+
const lowR = roundTo(ciLow, 2);
|
|
51
|
+
const highR = roundTo(ciHigh, 2);
|
|
52
|
+
let label;
|
|
53
|
+
if (qualifies) {
|
|
54
|
+
label =
|
|
55
|
+
`Measured-caveated ESTIMATE delta across ${n} distinct runs: mean ${meanR}% reduction ` +
|
|
56
|
+
`(±2·SE [${lowR}%, ${highR}%], excludes zero). Estimate (chars/4 + price-table) — ` +
|
|
57
|
+
"NOT billing-confirmed, NOT eval-backed, NOT realized savings, NOT extrapolated.";
|
|
58
|
+
}
|
|
59
|
+
else if (n < MIN_RUNS_FOR_MEASURED_DELTA) {
|
|
60
|
+
label =
|
|
61
|
+
`Single-run/anecdote estimate (${n} distinct run(s); need ≥${MIN_RUNS_FOR_MEASURED_DELTA} ` +
|
|
62
|
+
"for a measured delta). Local estimate — NOT billing-confirmed.";
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
label =
|
|
66
|
+
`Estimate delta across ${n} distinct runs does NOT meet the measured bar ` +
|
|
67
|
+
`(±2·SE [${lowR}%, ${highR}%] includes zero — dispersion too wide). Local estimate — NOT billing-confirmed.`;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
distinct_run_count: n,
|
|
71
|
+
mean_percent_reduction: meanR,
|
|
72
|
+
std_error: roundTo(se, 4),
|
|
73
|
+
ci_low: lowR,
|
|
74
|
+
ci_high: highR,
|
|
75
|
+
excludes_zero: excludesZero,
|
|
76
|
+
qualifies,
|
|
77
|
+
evidence_rung: qualifies ? "measured_caveated_estimate_delta" : "local_estimate_single_run",
|
|
78
|
+
label
|
|
79
|
+
};
|
|
80
|
+
}
|
|
29
81
|
/** Read the OPTIONAL content fingerprint digest from a report (older reports have none). */
|
|
30
82
|
function fingerprintDigestOf(report) {
|
|
31
83
|
const fp = report.trace_fingerprint;
|
|
@@ -153,6 +205,7 @@ export function aggregateCompactionReports(reports, skippedFiles = [], generated
|
|
|
153
205
|
const summary = {
|
|
154
206
|
...emptyBucket(),
|
|
155
207
|
average_percent_reduction: 0,
|
|
208
|
+
measured_estimate_delta: computeMeasuredEstimateDelta([]),
|
|
156
209
|
savings_by_policy: {},
|
|
157
210
|
savings_by_waste_pattern: {},
|
|
158
211
|
top_savings_runs: [],
|
|
@@ -183,6 +236,9 @@ export function aggregateCompactionReports(reports, skippedFiles = [], generated
|
|
|
183
236
|
}
|
|
184
237
|
summary.average_percent_reduction =
|
|
185
238
|
distinctReports.length === 0 ? 0 : roundTo(percentReductionTotal / distinctReports.length, 2);
|
|
239
|
+
// V0.2 Increment 2: the measured-across-distinct-runs estimate delta over the DISTINCT runs'
|
|
240
|
+
// per-run reductions. Qualifies for rung 1.5 only when N≥3 AND the mean ±2·SE excludes zero.
|
|
241
|
+
summary.measured_estimate_delta = computeMeasuredEstimateDelta(summary.top_savings_runs.map((run) => run.percent_reduction));
|
|
186
242
|
normalizeBucket(summary);
|
|
187
243
|
for (const bucket of Object.values(summary.savings_by_policy)) {
|
|
188
244
|
normalizeBucket(bucket);
|
|
@@ -250,6 +306,7 @@ export function formatRunSummary(summary) {
|
|
|
250
306
|
`- ${distinctnessLine(summary.distinctness)}`,
|
|
251
307
|
...formatBucketLines(summary).map((line) => `- ${line}`),
|
|
252
308
|
`- average percent reduction: ${summary.average_percent_reduction.toFixed(2)}%`,
|
|
309
|
+
`- measured estimate delta [${summary.measured_estimate_delta.evidence_rung}]: ${summary.measured_estimate_delta.label}`,
|
|
253
310
|
"",
|
|
254
311
|
"Savings by policy",
|
|
255
312
|
...(policyLines.length === 0 ? ["- none"] : policyLines),
|
|
@@ -288,6 +345,13 @@ export function formatRunSummaryMarkdown(summary) {
|
|
|
288
345
|
`- Total saving per run: ${formatCurrency(summary.total_saving_per_run)}`,
|
|
289
346
|
`- Saving figures are estimated and summed over the ${summary.distinctness.distinct_runs} distinct recorded run${summary.distinctness.distinct_runs === 1 ? "" : "s"} (${summary.distinctness.duplicate_runs} duplicate(s) detected by content fingerprint and excluded).`,
|
|
290
347
|
"",
|
|
348
|
+
"## Measured Estimate Delta (across distinct runs)",
|
|
349
|
+
"",
|
|
350
|
+
`- Rung: ${summary.measured_estimate_delta.evidence_rung}`,
|
|
351
|
+
`- Distinct runs: ${summary.measured_estimate_delta.distinct_run_count}`,
|
|
352
|
+
`- Mean percent reduction: ${summary.measured_estimate_delta.mean_percent_reduction.toFixed(2)}% (±2·SE [${summary.measured_estimate_delta.ci_low.toFixed(2)}%, ${summary.measured_estimate_delta.ci_high.toFixed(2)}%])`,
|
|
353
|
+
`- ${summary.measured_estimate_delta.label}`,
|
|
354
|
+
"",
|
|
291
355
|
"## Savings by policy",
|
|
292
356
|
"",
|
|
293
357
|
"| Policy | Runs | Tokens saved | Saving per run |",
|
|
@@ -19,6 +19,14 @@ export interface TraceAdapter {
|
|
|
19
19
|
displayName: string;
|
|
20
20
|
description: string;
|
|
21
21
|
supportedSource: TraceAdapterSource;
|
|
22
|
+
/**
|
|
23
|
+
* Honest integration-readiness label for this source (AGENTS.md Level 0–6 +
|
|
24
|
+
* validation status). All import sources are Level 1 (local export/import — no live
|
|
25
|
+
* integration); this string also discloses how PROVEN the source is (e.g. validated
|
|
26
|
+
* on a synthetic fixture vs real-artifact validation still open), so `--list-sources`
|
|
27
|
+
* never reads as a stronger integration claim than the evidence supports.
|
|
28
|
+
*/
|
|
29
|
+
readiness: string;
|
|
22
30
|
limitations: string[];
|
|
23
31
|
canHandle(input: unknown): boolean;
|
|
24
32
|
normalize(input: unknown, options: TraceAdapterOptions): TraceAdapterResult;
|
|
@@ -504,6 +504,7 @@ export const agentTraceAdapter = {
|
|
|
504
504
|
displayName: "Internal AgentTrace",
|
|
505
505
|
description: "Validates a local file that already matches the internal AgentTrace JSON shape.",
|
|
506
506
|
supportedSource: "agent-trace",
|
|
507
|
+
readiness: "Level 1 (local import) · canonical internal format, schema-validated",
|
|
507
508
|
limitations: [
|
|
508
509
|
"Only local JSON files are supported.",
|
|
509
510
|
"Live provider/runtime capture is future work.",
|
|
@@ -519,6 +520,7 @@ export const messagesAdapter = {
|
|
|
519
520
|
displayName: "Simple messages",
|
|
520
521
|
description: "Normalizes a local array of role/content messages, or an object with a messages array, into AgentTrace.",
|
|
521
522
|
supportedSource: "messages",
|
|
523
|
+
readiness: "Level 1 (local import) · generic role/content messages shape",
|
|
522
524
|
limitations: [
|
|
523
525
|
"Only local JSON files are supported.",
|
|
524
526
|
"Messages need supported roles and string content.",
|
|
@@ -535,6 +537,7 @@ export const codexExecJsonlAdapter = {
|
|
|
535
537
|
displayName: "Codex exec JSONL",
|
|
536
538
|
description: "Normalizes a local JSONL stream produced by Codex exec --json into AgentTrace without launching Codex or calling provider APIs.",
|
|
537
539
|
supportedSource: "codex-exec-jsonl",
|
|
540
|
+
readiness: "Level 1 (local export import) · validated end-to-end on a synthetic fixture; real-artifact validation OPEN (a real `codex exec --json` export has not yet been walked)",
|
|
538
541
|
limitations: [
|
|
539
542
|
"Only local user-supplied JSONL files are supported.",
|
|
540
543
|
"This adapter does not launch Codex, call OpenAI APIs, scrape private data, or upload artifacts.",
|
|
@@ -564,6 +567,7 @@ export const unknownAdapter = {
|
|
|
564
567
|
displayName: "Unknown local trace source",
|
|
565
568
|
description: "Detects supported local AgentTrace and simple messages shapes before normalizing with the matching adapter.",
|
|
566
569
|
supportedSource: "unknown",
|
|
570
|
+
readiness: "Level 1 (local import) · best-effort shape detection (AgentTrace / messages / Codex JSONL)",
|
|
567
571
|
limitations: [
|
|
568
572
|
"Detection is shape-based and local-file only.",
|
|
569
573
|
"AgentTrace, simple messages, and Codex exec JSONL shapes are detected in v0.",
|
package/dist/core/types.d.ts
CHANGED
|
@@ -247,6 +247,39 @@ export interface CompactionReport {
|
|
|
247
247
|
/** Non-sensitive structural count: number of messages hashed. */
|
|
248
248
|
message_count: number;
|
|
249
249
|
};
|
|
250
|
+
/**
|
|
251
|
+
* Composed per-run SAVINGS EVIDENCE record (additive, OPTIONAL, backward-compatible) —
|
|
252
|
+
* the V0.2 "evidence labels per result" surface. Older reports omit it. See
|
|
253
|
+
* `SavingsEvidence`. Composes EXISTING report numbers; makes no new/stronger claim.
|
|
254
|
+
*/
|
|
255
|
+
savings_evidence?: SavingsEvidence;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Composed, per-run savings-evidence record (V0.2 "evidence labels per result"). Ties the
|
|
259
|
+
* evidence chain into ONE place and states, per run, the cost-source label, the
|
|
260
|
+
* recoverability/semantic status, and exactly which `claims-and-evidence-ladder` rung the
|
|
261
|
+
* figure stands on — so no consumer reads a stronger claim than the evidence supports.
|
|
262
|
+
*
|
|
263
|
+
* A single run is rung 1 (local estimate). The measured rung 1.5
|
|
264
|
+
* (`measured_caveated_estimate_delta`) is produced ONLY by the aggregate increment across
|
|
265
|
+
* N≥3 distinct runs, NEVER here. `billing_confirmed` is ALWAYS false; `semantic_preservation`
|
|
266
|
+
* is ALWAYS `not_evaluated` (never auto-certified).
|
|
267
|
+
*/
|
|
268
|
+
export interface SavingsEvidence {
|
|
269
|
+
/** Is the run attributable to a verifiable identity (trace fingerprint present)? */
|
|
270
|
+
trace_identity: "fingerprinted" | "unidentified";
|
|
271
|
+
/** Honest cost-source label for this run's figures (mirrors `CostSource`). */
|
|
272
|
+
cost_source: "provider_reported" | "price_table_estimate" | "local_estimate" | "missing" | "unknown";
|
|
273
|
+
/** Deterministic recoverability status when an eval ran (`compact --eval`); else `not_evaluated`. */
|
|
274
|
+
recoverability: "passed" | "failed" | "not_computed" | "not_evaluated";
|
|
275
|
+
/** Semantic / meaning preservation is NEVER auto-certified — always `not_evaluated`. */
|
|
276
|
+
semantic_preservation: "not_evaluated";
|
|
277
|
+
/** Which claims-and-evidence-ladder rung this single-run figure stands on. */
|
|
278
|
+
evidence_rung: "local_estimate_single_run";
|
|
279
|
+
/** No v0 per-run figure is billing-confirmed. Always `false`. */
|
|
280
|
+
billing_confirmed: false;
|
|
281
|
+
/** One-line honest label (never asserts a stronger claim than the rung). */
|
|
282
|
+
label: string;
|
|
250
283
|
}
|
|
251
284
|
export interface CompactionPolicy {
|
|
252
285
|
policy_name: string;
|