@compaction/cli 0.1.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/LICENSE +663 -0
- package/README.md +319 -0
- package/dist/cli/commands/adapter.d.ts +2 -0
- package/dist/cli/commands/adapter.js +49 -0
- package/dist/cli/commands/aggregate.d.ts +2 -0
- package/dist/cli/commands/aggregate.js +60 -0
- package/dist/cli/commands/analyze.d.ts +2 -0
- package/dist/cli/commands/analyze.js +55 -0
- package/dist/cli/commands/apply-context.d.ts +12 -0
- package/dist/cli/commands/apply-context.js +80 -0
- package/dist/cli/commands/apply.d.ts +2 -0
- package/dist/cli/commands/apply.js +65 -0
- package/dist/cli/commands/approve.d.ts +2 -0
- package/dist/cli/commands/approve.js +55 -0
- package/dist/cli/commands/audit.d.ts +2 -0
- package/dist/cli/commands/audit.js +63 -0
- package/dist/cli/commands/billing-delta.d.ts +2 -0
- package/dist/cli/commands/billing-delta.js +246 -0
- package/dist/cli/commands/capture-claude-code.d.ts +19 -0
- package/dist/cli/commands/capture-claude-code.js +198 -0
- package/dist/cli/commands/capture-provider-usage.d.ts +35 -0
- package/dist/cli/commands/capture-provider-usage.js +113 -0
- package/dist/cli/commands/capture.d.ts +2 -0
- package/dist/cli/commands/capture.js +76 -0
- package/dist/cli/commands/compact.d.ts +2 -0
- package/dist/cli/commands/compact.js +206 -0
- package/dist/cli/commands/eval.d.ts +2 -0
- package/dist/cli/commands/eval.js +66 -0
- package/dist/cli/commands/export-session-seed.d.ts +11 -0
- package/dist/cli/commands/export-session-seed.js +42 -0
- package/dist/cli/commands/feedback.d.ts +2 -0
- package/dist/cli/commands/feedback.js +233 -0
- package/dist/cli/commands/import.d.ts +2 -0
- package/dist/cli/commands/import.js +60 -0
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.js +216 -0
- package/dist/cli/commands/integrations.d.ts +2 -0
- package/dist/cli/commands/integrations.js +29 -0
- package/dist/cli/commands/launch-treatment-session.d.ts +14 -0
- package/dist/cli/commands/launch-treatment-session.js +50 -0
- package/dist/cli/commands/optimize.d.ts +2 -0
- package/dist/cli/commands/optimize.js +33 -0
- package/dist/cli/commands/recommend.d.ts +4 -0
- package/dist/cli/commands/recommend.js +66 -0
- package/dist/cli/commands/review.d.ts +2 -0
- package/dist/cli/commands/review.js +60 -0
- package/dist/cli/commands/run.d.ts +2 -0
- package/dist/cli/commands/run.js +49 -0
- package/dist/cli/commands/spend.d.ts +2 -0
- package/dist/cli/commands/spend.js +24 -0
- package/dist/cli/commands/summary.d.ts +2 -0
- package/dist/cli/commands/summary.js +19 -0
- package/dist/cli/engine-degrade.d.ts +40 -0
- package/dist/cli/engine-degrade.js +59 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +59 -0
- package/dist/core/adapter-validation.d.ts +32 -0
- package/dist/core/adapter-validation.js +185 -0
- package/dist/core/adapters/claude-code-adapter.d.ts +51 -0
- package/dist/core/adapters/claude-code-adapter.js +539 -0
- package/dist/core/adapters/claude-code-discovery.d.ts +40 -0
- package/dist/core/adapters/claude-code-discovery.js +100 -0
- package/dist/core/aggregate-format.d.ts +62 -0
- package/dist/core/aggregate-format.js +349 -0
- package/dist/core/api-client/client.d.ts +43 -0
- package/dist/core/api-client/client.js +143 -0
- package/dist/core/api-client/config.d.ts +36 -0
- package/dist/core/api-client/config.js +44 -0
- package/dist/core/api-client/index.d.ts +13 -0
- package/dist/core/api-client/index.js +14 -0
- package/dist/core/api-client/payload.d.ts +93 -0
- package/dist/core/api-client/payload.js +180 -0
- package/dist/core/api-client/types.d.ts +95 -0
- package/dist/core/api-client/types.js +21 -0
- package/dist/core/artifact-writer.d.ts +2 -0
- package/dist/core/artifact-writer.js +14 -0
- package/dist/core/audit-report.d.ts +91 -0
- package/dist/core/audit-report.js +422 -0
- package/dist/core/billing-delta/billing-delta-record.d.ts +290 -0
- package/dist/core/billing-delta/billing-delta-record.js +394 -0
- package/dist/core/capture-adapter.d.ts +74 -0
- package/dist/core/capture-adapter.js +2 -0
- package/dist/core/command-runner.d.ts +29 -0
- package/dist/core/command-runner.js +96 -0
- package/dist/core/content-hash.d.ts +1 -0
- package/dist/core/content-hash.js +5 -0
- package/dist/core/cost-calculator.d.ts +6 -0
- package/dist/core/cost-calculator.js +20 -0
- package/dist/core/feedback-bundle.d.ts +159 -0
- package/dist/core/feedback-bundle.js +406 -0
- package/dist/core/openai-agents-capture.d.ts +66 -0
- package/dist/core/openai-agents-capture.js +475 -0
- package/dist/core/policy-types.d.ts +85 -0
- package/dist/core/policy-types.js +29 -0
- package/dist/core/pricing.d.ts +23 -0
- package/dist/core/pricing.js +55 -0
- package/dist/core/provider-usage/credential-redaction.d.ts +23 -0
- package/dist/core/provider-usage/credential-redaction.js +60 -0
- package/dist/core/provider-usage/provider-usage-adapter.d.ts +65 -0
- package/dist/core/provider-usage/provider-usage-adapter.js +147 -0
- package/dist/core/provider-usage/provider-usage-client.d.ts +89 -0
- package/dist/core/provider-usage/provider-usage-client.js +96 -0
- package/dist/core/report-generator.d.ts +7 -0
- package/dist/core/report-generator.js +275 -0
- package/dist/core/run-aggregator.d.ts +50 -0
- package/dist/core/run-aggregator.js +251 -0
- package/dist/core/run-labels.d.ts +52 -0
- package/dist/core/run-labels.js +80 -0
- package/dist/core/run-trace-converter.d.ts +3 -0
- package/dist/core/run-trace-converter.js +94 -0
- package/dist/core/safety-report.d.ts +52 -0
- package/dist/core/safety-report.js +440 -0
- package/dist/core/savings.d.ts +22 -0
- package/dist/core/savings.js +36 -0
- package/dist/core/session-aggregate.d.ts +211 -0
- package/dist/core/session-aggregate.js +490 -0
- package/dist/core/skill-injection-detector.d.ts +51 -0
- package/dist/core/skill-injection-detector.js +146 -0
- package/dist/core/spend-attribution.d.ts +169 -0
- package/dist/core/spend-attribution.js +611 -0
- package/dist/core/standalone-capsule-provenance.d.ts +4 -0
- package/dist/core/standalone-capsule-provenance.js +62 -0
- package/dist/core/state-capsule.d.ts +3 -0
- package/dist/core/state-capsule.js +147 -0
- package/dist/core/token-accounting.d.ts +62 -0
- package/dist/core/token-accounting.js +81 -0
- package/dist/core/token-estimator.d.ts +3 -0
- package/dist/core/token-estimator.js +18 -0
- package/dist/core/trace-adapters.d.ts +53 -0
- package/dist/core/trace-adapters.js +714 -0
- package/dist/core/trace-fingerprint.d.ts +79 -0
- package/dist/core/trace-fingerprint.js +102 -0
- package/dist/core/trace-intake.d.ts +41 -0
- package/dist/core/trace-intake.js +164 -0
- package/dist/core/trace-parser.d.ts +203 -0
- package/dist/core/trace-parser.js +143 -0
- package/dist/core/types.d.ts +238 -0
- package/dist/core/types.js +2 -0
- package/dist/core/usage-metadata.d.ts +51 -0
- package/dist/core/usage-metadata.js +122 -0
- package/dist/core/waste-detector.d.ts +8 -0
- package/dist/core/waste-detector.js +58 -0
- package/package.json +90 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session + multi-session LOCAL aggregate (Strong-MVP Track E).
|
|
3
|
+
*
|
|
4
|
+
* Rolls up the per-run artifacts a developer already produced —
|
|
5
|
+
* `.compaction/runs/<run>/report.json` and (when present) `strong-eval.json` plus an
|
|
6
|
+
* optional local `run-labels.json` — into:
|
|
7
|
+
* - a PER-SESSION summary (a session may contain multiple runs), and
|
|
8
|
+
* - a CROSS-SESSION aggregate (totals across every session/run).
|
|
9
|
+
*
|
|
10
|
+
* This is the future admin/buyer value WITHOUT a hosted dashboard: everything is LOCAL,
|
|
11
|
+
* file-based, read-only over existing artifacts. NO network, NO upload, NO telemetry,
|
|
12
|
+
* NO database, NO auth, NO server.
|
|
13
|
+
*
|
|
14
|
+
* EVIDENCE HONESTY (mvp-capability-matrix rows 2/3/10/13/21, README evidence ladder):
|
|
15
|
+
* - Token figures carry their per-figure source: provider-reported ONLY when the run's
|
|
16
|
+
* token accounting was `measured` (provider usage metadata present); otherwise
|
|
17
|
+
* local-estimate (chars/4). The aggregate states how many runs are in each tier and
|
|
18
|
+
* NEVER labels an estimate as provider-reported.
|
|
19
|
+
* - Cost / savings are ESTIMATED (price-table over the token figures). NEVER
|
|
20
|
+
* billing-confirmed, NEVER realized, NEVER extrapolated to a time period.
|
|
21
|
+
* - Output tokens are carried only where a run actually recorded them (from
|
|
22
|
+
* strong-eval token_accounting); runs without strong-eval contribute `unknown`
|
|
23
|
+
* output tokens and are counted separately, never inferred.
|
|
24
|
+
* - Verification outcome counts (ready/conditional/not_ready, recoverability /
|
|
25
|
+
* commitment / task-check pass/fail) are copied from strong-eval; runs without a
|
|
26
|
+
* strong-eval are counted as `not_evaluated`, never as a pass.
|
|
27
|
+
*
|
|
28
|
+
* The builders are PURE (no IO) so the rollup math, label tagging, and the content-free
|
|
29
|
+
* share bundle are unit-testable; the reader (`collectRunRecords`) does the only IO and
|
|
30
|
+
* touches nothing but local files.
|
|
31
|
+
*/
|
|
32
|
+
import { type RunLabels } from "./run-labels.js";
|
|
33
|
+
import type { CompactionReport } from "./types.js";
|
|
34
|
+
export declare const AGGREGATE_ARTIFACT_DIRECTORY = ".compaction/aggregates";
|
|
35
|
+
/** Evidence tier of a run's TOKEN figures (kept distinct from operator-asserted provider labels). */
|
|
36
|
+
export type RunTokenEvidence = "provider_reported" | "local_estimate" | "unknown";
|
|
37
|
+
/** Verification outcome of a run, copied from strong-eval (or not_evaluated when absent). */
|
|
38
|
+
export type VerificationReadiness = "ready" | "conditional" | "not_ready" | "not_evaluated";
|
|
39
|
+
export type CheckOutcome = "pass" | "fail" | "unsupported" | "not_evaluated";
|
|
40
|
+
/**
|
|
41
|
+
* One normalized run record assembled from a run directory's local artifacts. The ONLY
|
|
42
|
+
* fields carried are bounded numbers / enums / short label strings — never trace content.
|
|
43
|
+
*/
|
|
44
|
+
export interface RunRecord {
|
|
45
|
+
run_id: string;
|
|
46
|
+
run_directory: string;
|
|
47
|
+
report_path: string;
|
|
48
|
+
model: string;
|
|
49
|
+
/** Token evidence tier for this run (drives the provider-reported vs local-estimate split). */
|
|
50
|
+
token_evidence: RunTokenEvidence;
|
|
51
|
+
input_tokens_before: number;
|
|
52
|
+
input_tokens_after: number;
|
|
53
|
+
input_tokens_saved: number;
|
|
54
|
+
/** Output tokens where the run recorded them (strong-eval token_accounting); else unknown. */
|
|
55
|
+
output_tokens_before: number | "unknown";
|
|
56
|
+
output_tokens_after: number | "unknown";
|
|
57
|
+
estimated_cost_before_usd: number;
|
|
58
|
+
estimated_cost_after_usd: number;
|
|
59
|
+
estimated_saving_usd: number;
|
|
60
|
+
/** Verification outcomes (not_evaluated when no strong-eval.json was present). */
|
|
61
|
+
readiness: VerificationReadiness;
|
|
62
|
+
recoverability: CheckOutcome;
|
|
63
|
+
commitment_preservation: CheckOutcome;
|
|
64
|
+
task_check: CheckOutcome;
|
|
65
|
+
/** Whether a strong-eval.json was present for this run. */
|
|
66
|
+
strong_eval_present: boolean;
|
|
67
|
+
/** Local-only labels (project/workflow/provider/user_label/session). */
|
|
68
|
+
labels: RunLabels;
|
|
69
|
+
/** Notes about partial/missing artifacts for this run (honest provenance). */
|
|
70
|
+
notes: string[];
|
|
71
|
+
}
|
|
72
|
+
export interface SkippedRunDirectory {
|
|
73
|
+
run_directory: string;
|
|
74
|
+
reason: string;
|
|
75
|
+
}
|
|
76
|
+
/** Aggregated token/cost/savings totals over a set of runs, with the evidence split. */
|
|
77
|
+
export interface AggregateTotals {
|
|
78
|
+
run_count: number;
|
|
79
|
+
/** Token-evidence split: how many runs contributed provider-reported vs local-estimate figures. */
|
|
80
|
+
runs_provider_reported: number;
|
|
81
|
+
runs_local_estimate: number;
|
|
82
|
+
runs_unknown_token_evidence: number;
|
|
83
|
+
total_input_tokens_before: number;
|
|
84
|
+
total_input_tokens_after: number;
|
|
85
|
+
total_input_tokens_saved: number;
|
|
86
|
+
/** Output tokens summed ONLY over runs that recorded them; unknown for the rest. */
|
|
87
|
+
total_output_tokens_before: number;
|
|
88
|
+
total_output_tokens_after: number;
|
|
89
|
+
runs_with_output_tokens: number;
|
|
90
|
+
runs_without_output_tokens: number;
|
|
91
|
+
/** Estimated spend/savings (price-table; NOT billing-confirmed, NOT realized, NOT extrapolated). */
|
|
92
|
+
total_estimated_cost_before_usd: number;
|
|
93
|
+
total_estimated_cost_after_usd: number;
|
|
94
|
+
total_estimated_savings_usd: number;
|
|
95
|
+
/** Number of compactions = number of recorded runs rolled up (each run is one compaction). */
|
|
96
|
+
compactions: number;
|
|
97
|
+
}
|
|
98
|
+
export interface VerificationCounts {
|
|
99
|
+
/** Readiness verdict counts. */
|
|
100
|
+
ready: number;
|
|
101
|
+
conditional: number;
|
|
102
|
+
not_ready: number;
|
|
103
|
+
not_evaluated: number;
|
|
104
|
+
/** Per-axis recoverability check counts. */
|
|
105
|
+
recoverability_pass: number;
|
|
106
|
+
recoverability_fail: number;
|
|
107
|
+
recoverability_not_evaluated: number;
|
|
108
|
+
/** Per-axis commitment-preservation check counts. */
|
|
109
|
+
commitment_pass: number;
|
|
110
|
+
commitment_fail: number;
|
|
111
|
+
commitment_not_evaluated: number;
|
|
112
|
+
/** Per-axis fixture task-check counts. */
|
|
113
|
+
task_check_pass: number;
|
|
114
|
+
task_check_fail: number;
|
|
115
|
+
task_check_unsupported: number;
|
|
116
|
+
task_check_not_evaluated: number;
|
|
117
|
+
}
|
|
118
|
+
export interface BreakdownBucket {
|
|
119
|
+
key: string;
|
|
120
|
+
totals: AggregateTotals;
|
|
121
|
+
verification: VerificationCounts;
|
|
122
|
+
}
|
|
123
|
+
export interface SessionSummary {
|
|
124
|
+
session_id: string;
|
|
125
|
+
/** True when the session id came from an explicit local `session` label (vs run-id fallback). */
|
|
126
|
+
explicit_session_label: boolean;
|
|
127
|
+
run_ids: string[];
|
|
128
|
+
/** Distinct local labels observed across the session's runs. */
|
|
129
|
+
labels: {
|
|
130
|
+
projects: string[];
|
|
131
|
+
workflows: string[];
|
|
132
|
+
providers: string[];
|
|
133
|
+
user_labels: string[];
|
|
134
|
+
};
|
|
135
|
+
totals: AggregateTotals;
|
|
136
|
+
verification: VerificationCounts;
|
|
137
|
+
}
|
|
138
|
+
export interface AggregateReport {
|
|
139
|
+
aggregate_id: string;
|
|
140
|
+
generated_at: string;
|
|
141
|
+
source_glob: string;
|
|
142
|
+
/** Local-only label filters applied to this rollup (empty when none). */
|
|
143
|
+
applied_filters: RunLabels;
|
|
144
|
+
/** Operator-supplied provenance labels for THIS rollup (who/what produced it). Local only. */
|
|
145
|
+
rollup_labels: RunLabels;
|
|
146
|
+
session_count: number;
|
|
147
|
+
totals: AggregateTotals;
|
|
148
|
+
verification: VerificationCounts;
|
|
149
|
+
sessions: SessionSummary[];
|
|
150
|
+
/** Provider/runtime breakdown (operator-asserted provider label; unlabeled when absent). */
|
|
151
|
+
by_provider: BreakdownBucket[];
|
|
152
|
+
/** Project breakdown (local label). */
|
|
153
|
+
by_project: BreakdownBucket[];
|
|
154
|
+
/** Workflow breakdown (local label). */
|
|
155
|
+
by_workflow: BreakdownBucket[];
|
|
156
|
+
skipped_run_directories: SkippedRunDirectory[];
|
|
157
|
+
evidence_labels: AggregateEvidenceLabels;
|
|
158
|
+
limitations: string[];
|
|
159
|
+
}
|
|
160
|
+
/** The explicit per-field evidence labels, surfaced in the artifact so no figure is unlabeled. */
|
|
161
|
+
export interface AggregateEvidenceLabels {
|
|
162
|
+
input_tokens: string;
|
|
163
|
+
output_tokens: string;
|
|
164
|
+
estimated_cost: string;
|
|
165
|
+
estimated_savings: string;
|
|
166
|
+
compactions: string;
|
|
167
|
+
verification: string;
|
|
168
|
+
provider_runtime: string;
|
|
169
|
+
}
|
|
170
|
+
export declare const AGGREGATE_EVIDENCE_LABELS: AggregateEvidenceLabels;
|
|
171
|
+
/** True when a run passes every supplied local-label filter (case-sensitive exact match). */
|
|
172
|
+
export declare function runMatchesFilters(run: RunRecord, filters: RunLabels): boolean;
|
|
173
|
+
export interface BuildAggregateOptions {
|
|
174
|
+
generatedAt?: string;
|
|
175
|
+
sourceGlob?: string;
|
|
176
|
+
/** Local-only label filters: only runs matching ALL supplied fields are rolled up. */
|
|
177
|
+
filters?: RunLabels;
|
|
178
|
+
/** Operator provenance labels for this rollup (who/what produced it). Local only. */
|
|
179
|
+
rollupLabels?: RunLabels;
|
|
180
|
+
skippedRunDirectories?: SkippedRunDirectory[];
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* PURE rollup: fold a set of normalized run records into the per-session + cross-session
|
|
184
|
+
* aggregate report. No IO. Applies the supplied local-label filters first.
|
|
185
|
+
*/
|
|
186
|
+
export declare function buildAggregateReport(runs: RunRecord[], options?: BuildAggregateOptions): AggregateReport;
|
|
187
|
+
/**
|
|
188
|
+
* Assemble a normalized RunRecord from a run directory's local artifacts. report.json is
|
|
189
|
+
* REQUIRED (skipped otherwise). strong-eval.json and run-labels.json are OPTIONAL: absence
|
|
190
|
+
* is recorded honestly (not_evaluated verification, unknown output tokens), never inferred.
|
|
191
|
+
*/
|
|
192
|
+
export declare function assembleRunRecord(input: {
|
|
193
|
+
runId: string;
|
|
194
|
+
runDirectory: string;
|
|
195
|
+
reportPath: string;
|
|
196
|
+
report: CompactionReport;
|
|
197
|
+
strongEval: unknown;
|
|
198
|
+
labels: RunLabels;
|
|
199
|
+
}): RunRecord;
|
|
200
|
+
/**
|
|
201
|
+
* Read every run directory under `runsDirectory`, assembling one RunRecord per directory that
|
|
202
|
+
* carries a valid report.json. The ONLY IO path. Reads exclusively local files; makes NO
|
|
203
|
+
* network call. Directories without a valid report.json are recorded as skipped, never dropped
|
|
204
|
+
* silently.
|
|
205
|
+
*/
|
|
206
|
+
export declare function collectRunRecords(runsDirectory?: string): Promise<{
|
|
207
|
+
runs: RunRecord[];
|
|
208
|
+
skipped: SkippedRunDirectory[];
|
|
209
|
+
}>;
|
|
210
|
+
/** Read records + build the report in one call (local IO + pure rollup). */
|
|
211
|
+
export declare function createAggregateReport(runsDirectory?: string, options?: Omit<BuildAggregateOptions, "skippedRunDirectories">): Promise<AggregateReport>;
|