@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,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local-only run labels (Strong-MVP Track E, task 3).
|
|
3
|
+
*
|
|
4
|
+
* A tiny, OPTIONAL, file-based tag a developer can attach to a recorded run so the
|
|
5
|
+
* multi-session aggregate can group / filter / attribute it. These labels are written
|
|
6
|
+
* to `.compaction/runs/<run>/run-labels.json` — they are LOCAL ONLY and are NEVER
|
|
7
|
+
* uploaded. They carry no trace content: only short operator-supplied strings
|
|
8
|
+
* (project / workflow / provider-runtime / a free-form user label / an explicit
|
|
9
|
+
* session id).
|
|
10
|
+
*
|
|
11
|
+
* Honesty: a label is metadata the operator typed. It does NOT change any token, cost,
|
|
12
|
+
* savings, or verification figure, and it carries no evidence weight — it is purely an
|
|
13
|
+
* organizing tag for the local rollup. Provider/runtime supplied as a LABEL is operator-
|
|
14
|
+
* asserted, never provider-verified, and is kept distinct from the token-source evidence
|
|
15
|
+
* label (provider-reported vs local-estimate) that the token accounting carries.
|
|
16
|
+
*/
|
|
17
|
+
/** Marker used wherever a label was not supplied rather than guessed. */
|
|
18
|
+
export const NO_LABEL = "unlabeled";
|
|
19
|
+
/** Schema version for the run-labels file (additive changes bump the minor). */
|
|
20
|
+
export const RUN_LABELS_VERSION = "1.0.0";
|
|
21
|
+
export const RUN_LABELS_NOTE = "Local-only organizing labels. Operator-supplied strings; NEVER uploaded; carry no trace content " +
|
|
22
|
+
"and no evidence weight. provider here is operator-ASSERTED, not provider-verified.";
|
|
23
|
+
const MAX_LABEL_LENGTH = 200;
|
|
24
|
+
/** Trim, drop empties, and cap length. Returns undefined when the value is not a usable label. */
|
|
25
|
+
function normalizeLabel(value) {
|
|
26
|
+
if (typeof value !== "string")
|
|
27
|
+
return undefined;
|
|
28
|
+
const trimmed = value.trim();
|
|
29
|
+
if (trimmed.length === 0)
|
|
30
|
+
return undefined;
|
|
31
|
+
return trimmed.slice(0, MAX_LABEL_LENGTH);
|
|
32
|
+
}
|
|
33
|
+
/** Normalize a supplied label set to the bounded, trimmed shape (drops empty/invalid fields). */
|
|
34
|
+
export function normalizeRunLabels(labels) {
|
|
35
|
+
const out = {};
|
|
36
|
+
const project = normalizeLabel(labels.project);
|
|
37
|
+
const workflow = normalizeLabel(labels.workflow);
|
|
38
|
+
const provider = normalizeLabel(labels.provider);
|
|
39
|
+
const userLabel = normalizeLabel(labels.user_label);
|
|
40
|
+
const session = normalizeLabel(labels.session);
|
|
41
|
+
if (project !== undefined)
|
|
42
|
+
out.project = project;
|
|
43
|
+
if (workflow !== undefined)
|
|
44
|
+
out.workflow = workflow;
|
|
45
|
+
if (provider !== undefined)
|
|
46
|
+
out.provider = provider;
|
|
47
|
+
if (userLabel !== undefined)
|
|
48
|
+
out.user_label = userLabel;
|
|
49
|
+
if (session !== undefined)
|
|
50
|
+
out.session = session;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** True when at least one label field is present after normalization. */
|
|
54
|
+
export function hasAnyLabel(labels) {
|
|
55
|
+
return Object.keys(normalizeRunLabels(labels)).length > 0;
|
|
56
|
+
}
|
|
57
|
+
/** Build the on-disk artifact from a supplied (already-normalizable) label set. */
|
|
58
|
+
export function buildRunLabelsFile(labels, writtenAt = new Date().toISOString()) {
|
|
59
|
+
return {
|
|
60
|
+
labels_version: RUN_LABELS_VERSION,
|
|
61
|
+
written_at: writtenAt,
|
|
62
|
+
note: RUN_LABELS_NOTE,
|
|
63
|
+
...normalizeRunLabels(labels)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Parse a value read from a run-labels.json into the bounded label set (tolerant; drops junk). */
|
|
67
|
+
export function parseRunLabels(value) {
|
|
68
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
69
|
+
return {};
|
|
70
|
+
const record = value;
|
|
71
|
+
const pick = (key) => typeof record[key] === "string" ? record[key] : undefined;
|
|
72
|
+
return normalizeRunLabels({
|
|
73
|
+
project: pick("project"),
|
|
74
|
+
workflow: pick("workflow"),
|
|
75
|
+
provider: pick("provider"),
|
|
76
|
+
user_label: pick("user_label"),
|
|
77
|
+
session: pick("session")
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=run-labels.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { CURRENT_AGENT_TRACE_ARTIFACT_VERSION } from "./trace-parser.js";
|
|
2
|
+
const LOCAL_RUN_MODEL = "local-command-runner";
|
|
3
|
+
function compactPreview(value) {
|
|
4
|
+
const normalized = value.trim().replace(/\s+/g, " ");
|
|
5
|
+
return normalized.length > 120 ? `${normalized.slice(0, 117)}...` : normalized;
|
|
6
|
+
}
|
|
7
|
+
function createMessage(id, role, timestamp, content) {
|
|
8
|
+
return { id, role, timestamp, content };
|
|
9
|
+
}
|
|
10
|
+
function outputLines(value) {
|
|
11
|
+
return value
|
|
12
|
+
.split(/\r?\n/)
|
|
13
|
+
.map((content, index) => ({ content, lineNumber: index + 1 }))
|
|
14
|
+
.filter((line) => line.content.length > 0);
|
|
15
|
+
}
|
|
16
|
+
function nextMessageId(index) {
|
|
17
|
+
return `msg_${index.toString().padStart(3, "0")}`;
|
|
18
|
+
}
|
|
19
|
+
export function localCommandRunToAgentTrace(run) {
|
|
20
|
+
const commandLine = [run.command.executable, ...run.command.args].join(" ");
|
|
21
|
+
const messages = [
|
|
22
|
+
createMessage("msg_001", "system", run.startedAt, "Local compaction.dev command run. Environment variables are not captured, output is stored locally, and no upload is performed."),
|
|
23
|
+
createMessage("msg_002", "user", run.startedAt, `Run local command: ${commandLine}`)
|
|
24
|
+
];
|
|
25
|
+
let nextIndex = 3;
|
|
26
|
+
for (const line of outputLines(run.stdout)) {
|
|
27
|
+
messages.push({
|
|
28
|
+
id: nextMessageId(nextIndex),
|
|
29
|
+
role: "tool",
|
|
30
|
+
toolName: "stdout.line",
|
|
31
|
+
timestamp: run.endedAt,
|
|
32
|
+
content: line.content,
|
|
33
|
+
metadata: {
|
|
34
|
+
stream: "stdout",
|
|
35
|
+
lineNumber: line.lineNumber,
|
|
36
|
+
byteLength: Buffer.byteLength(line.content, "utf8")
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
nextIndex += 1;
|
|
40
|
+
}
|
|
41
|
+
for (const line of outputLines(run.stderr)) {
|
|
42
|
+
messages.push({
|
|
43
|
+
id: nextMessageId(nextIndex),
|
|
44
|
+
role: "tool",
|
|
45
|
+
toolName: "stderr.line",
|
|
46
|
+
timestamp: run.endedAt,
|
|
47
|
+
content: line.content,
|
|
48
|
+
metadata: {
|
|
49
|
+
stream: "stderr",
|
|
50
|
+
lineNumber: line.lineNumber,
|
|
51
|
+
byteLength: Buffer.byteLength(line.content, "utf8")
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
nextIndex += 1;
|
|
55
|
+
}
|
|
56
|
+
const status = run.exitCode === 0 ? "succeeded" : "finished with a non-zero exit status";
|
|
57
|
+
const stdoutSummary = run.stdout.length === 0 ? "stdout was empty" : `stdout preview: ${compactPreview(run.stdout)}`;
|
|
58
|
+
const stderrSummary = run.stderr.length === 0 ? "stderr was empty" : `stderr preview: ${compactPreview(run.stderr)}`;
|
|
59
|
+
messages.push({
|
|
60
|
+
id: nextMessageId(nextIndex),
|
|
61
|
+
role: "assistant",
|
|
62
|
+
timestamp: run.endedAt,
|
|
63
|
+
content: `Command ${status}. Exit code: ${run.exitCode ?? "none"}. Signal: ${run.signal ?? "none"}. Duration: ${run.durationMs} ms. ${stdoutSummary}. ${stderrSummary}.`,
|
|
64
|
+
metadata: {
|
|
65
|
+
exitCode: run.exitCode,
|
|
66
|
+
signal: run.signal,
|
|
67
|
+
startedAt: run.startedAt,
|
|
68
|
+
endedAt: run.endedAt,
|
|
69
|
+
durationMs: run.durationMs,
|
|
70
|
+
pid: run.pid,
|
|
71
|
+
stdoutBytes: Buffer.byteLength(run.stdout, "utf8"),
|
|
72
|
+
stderrBytes: Buffer.byteLength(run.stderr, "utf8"),
|
|
73
|
+
rawOutputBytes: Buffer.byteLength(run.rawOutput, "utf8")
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
id: `trace_${run.runId}`,
|
|
78
|
+
title: `Local command run: ${run.command.executable}`,
|
|
79
|
+
artifactVersion: CURRENT_AGENT_TRACE_ARTIFACT_VERSION,
|
|
80
|
+
source: "local_command",
|
|
81
|
+
createdAt: run.startedAt,
|
|
82
|
+
generatedAt: run.endedAt,
|
|
83
|
+
model: LOCAL_RUN_MODEL,
|
|
84
|
+
command: {
|
|
85
|
+
command: run.command.executable,
|
|
86
|
+
args: run.command.args,
|
|
87
|
+
cwd: process.cwd()
|
|
88
|
+
},
|
|
89
|
+
durationMs: run.durationMs,
|
|
90
|
+
exitCode: run.exitCode,
|
|
91
|
+
messages
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=run-trace-converter.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { PolicyMiddlewareStateCapsule } from "./policy-types.js";
|
|
2
|
+
import type { AgentTrace, ApprovalReadinessStatus, TraceMessage, TraceSource } from "./types.js";
|
|
3
|
+
export type SafetyStatus = "pass" | "warn" | "fail";
|
|
4
|
+
export type SafetyRiskLevel = "low" | "medium" | "high";
|
|
5
|
+
export type { ApprovalReadinessStatus };
|
|
6
|
+
export type EvidenceSourceType = "demo" | "fixture" | "imported_local" | "real_captured" | "provider_reported_usage" | "unknown";
|
|
7
|
+
export type ReviewerType = "human" | "internal" | "independent" | "automated" | "none";
|
|
8
|
+
export interface SafetyReportCheck {
|
|
9
|
+
id: string;
|
|
10
|
+
label: string;
|
|
11
|
+
status: SafetyStatus;
|
|
12
|
+
required: boolean;
|
|
13
|
+
details: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SafetyReport {
|
|
16
|
+
run_id: string;
|
|
17
|
+
generated_at: string;
|
|
18
|
+
policy_name: string;
|
|
19
|
+
status: SafetyStatus;
|
|
20
|
+
checks: SafetyReportCheck[];
|
|
21
|
+
warnings: string[];
|
|
22
|
+
failures: string[];
|
|
23
|
+
source_pointer_count: number;
|
|
24
|
+
compacted_message_count: number;
|
|
25
|
+
tokens_saved: number;
|
|
26
|
+
savings_scope: "policy_level";
|
|
27
|
+
source_recoverability: boolean | "unknown";
|
|
28
|
+
risk_level: SafetyRiskLevel;
|
|
29
|
+
recommendation: string;
|
|
30
|
+
evidence_source_type: EvidenceSourceType;
|
|
31
|
+
reviewer_type: ReviewerType;
|
|
32
|
+
review_summary_present: boolean;
|
|
33
|
+
approval_readiness_status: ApprovalReadinessStatus;
|
|
34
|
+
approval_readiness_reason: string;
|
|
35
|
+
}
|
|
36
|
+
export interface CreateSafetyReportInput {
|
|
37
|
+
runId: string;
|
|
38
|
+
generatedAt?: string;
|
|
39
|
+
originalTrace: AgentTrace;
|
|
40
|
+
compactedMessages: TraceMessage[];
|
|
41
|
+
stateCapsules: PolicyMiddlewareStateCapsule[];
|
|
42
|
+
compactedMessageIds: string[];
|
|
43
|
+
tokensSaved: number;
|
|
44
|
+
policyName: string;
|
|
45
|
+
reviewerType?: ReviewerType;
|
|
46
|
+
reviewSummaryPresent?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export declare function evidenceSourceTypeFromTrace(source: TraceSource): EvidenceSourceType;
|
|
49
|
+
export declare function approvalReadinessStatusFromReport(status: SafetyStatus, evidenceSourceType: EvidenceSourceType, reviewerType: ReviewerType, reviewSummaryPresent: boolean): ApprovalReadinessStatus;
|
|
50
|
+
export declare function approvalReadinessReasonFromReport(status: SafetyStatus, approvalStatus: ApprovalReadinessStatus, evidenceSourceType: EvidenceSourceType, reviewerType: ReviewerType, reviewSummaryPresent: boolean): string;
|
|
51
|
+
export declare function createSafetyReport(input: CreateSafetyReportInput): SafetyReport;
|
|
52
|
+
export declare function formatSafetyMarkdownReport(report: SafetyReport): string;
|