avorelo 0.1.0 → 0.3.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 +23 -16
- package/README.md +90 -51
- package/bin/avorelo.mjs +7 -0
- package/dist/avorelo.mjs +19741 -0
- package/package.json +135 -120
- package/bin/avorelo +0 -9
- package/scripts/README.md +0 -40
- package/scripts/cco-dashboard.js +0 -252
- package/scripts/cco-status.js +0 -430
- package/scripts/lib/activation/account-state.js +0 -37
- package/scripts/lib/activation/activation-runner.js +0 -546
- package/scripts/lib/activation/activation-self-healing.js +0 -480
- package/scripts/lib/activation/activation-state.js +0 -83
- package/scripts/lib/activation/activation-summary.js +0 -191
- package/scripts/lib/activation/adapters/claude-code.js +0 -77
- package/scripts/lib/activation/adapters/codex-cli.js +0 -52
- package/scripts/lib/activation/adapters/cursor.js +0 -37
- package/scripts/lib/activation/adapters/github-agent.js +0 -39
- package/scripts/lib/activation/adapters/terminal.js +0 -42
- package/scripts/lib/activation/adapters/vscode.js +0 -39
- package/scripts/lib/activation/adapters/windsurf.js +0 -37
- package/scripts/lib/activation/ai-surface-detector.js +0 -151
- package/scripts/lib/activation/connect-account.js +0 -145
- package/scripts/lib/activation/detect-environment.js +0 -75
- package/scripts/lib/activation/detect-hosts.js +0 -62
- package/scripts/lib/activation/format-activation-output.js +0 -109
- package/scripts/lib/activation/next-action.js +0 -43
- package/scripts/lib/activation/repair-engine.js +0 -219
- package/scripts/lib/activation-distribution-readiness.js +0 -507
- package/scripts/lib/adapter-conformance.js +0 -176
- package/scripts/lib/adapter-readiness.js +0 -417
- package/scripts/lib/adapter-safety-boundaries.js +0 -335
- package/scripts/lib/adapter-technical-readiness-gate.js +0 -205
- package/scripts/lib/agent-access-governance.js +0 -455
- package/scripts/lib/agent-enforcement.js +0 -765
- package/scripts/lib/agent-policy-profile.js +0 -210
- package/scripts/lib/agent-security/action-evaluator.js +0 -507
- package/scripts/lib/agent-security/adapter-registry.js +0 -98
- package/scripts/lib/agent-security/auto-policy.js +0 -139
- package/scripts/lib/agent-security/bounded-scan.js +0 -93
- package/scripts/lib/agent-security/enforcement-adapter.js +0 -174
- package/scripts/lib/agent-security/enforcement-engine.js +0 -1129
- package/scripts/lib/agent-security/file-write-adapter.js +0 -183
- package/scripts/lib/agent-security/file-write-rules.js +0 -178
- package/scripts/lib/agent-security/index.js +0 -3342
- package/scripts/lib/agent-security/instruction-risk.js +0 -181
- package/scripts/lib/agent-security/mcp-action-adapter.js +0 -185
- package/scripts/lib/agent-security/mcp-action-rules.js +0 -184
- package/scripts/lib/agent-security/package-action-adapter.js +0 -175
- package/scripts/lib/agent-security/package-action-rules.js +0 -233
- package/scripts/lib/agent-security/performance.js +0 -148
- package/scripts/lib/agent-security/permission-minimizer.js +0 -403
- package/scripts/lib/agent-security/scan-cache.js +0 -74
- package/scripts/lib/agent-security/source-trust.js +0 -146
- package/scripts/lib/ai-install-prompt.js +0 -288
- package/scripts/lib/ai-workspace-hygiene.js +0 -1499
- package/scripts/lib/alpha-activation.js +0 -520
- package/scripts/lib/alpha-feedback.js +0 -263
- package/scripts/lib/alpha-readiness-gate.js +0 -332
- package/scripts/lib/anti-gaming.js +0 -169
- package/scripts/lib/artifact-health.js +0 -431
- package/scripts/lib/attribution.js +0 -180
- package/scripts/lib/audit.js +0 -289
- package/scripts/lib/avorelo-skill-registry.js +0 -810
- package/scripts/lib/batch-jobs.js +0 -71
- package/scripts/lib/brain-pack.js +0 -578
- package/scripts/lib/brand-boundary.js +0 -424
- package/scripts/lib/brand.js +0 -74
- package/scripts/lib/browser-capability.js +0 -1048
- package/scripts/lib/browser-proof-preflight.js +0 -321
- package/scripts/lib/cache-readiness.js +0 -187
- package/scripts/lib/canonical-reentry.js +0 -162
- package/scripts/lib/capability-packs.js +0 -314
- package/scripts/lib/capability-recommender.js +0 -512
- package/scripts/lib/capability-registry.js +0 -1059
- package/scripts/lib/carry-forward-surfacing.js +0 -194
- package/scripts/lib/ccusage-adapter.js +0 -188
- package/scripts/lib/company-loop.js +0 -1149
- package/scripts/lib/config.js +0 -637
- package/scripts/lib/context-acquisition-plan.js +0 -287
- package/scripts/lib/context-budget-guard.js +0 -170
- package/scripts/lib/context-budget-scanner.js +0 -257
- package/scripts/lib/context-optimizer.js +0 -715
- package/scripts/lib/context-reduction-plan.js +0 -178
- package/scripts/lib/context-safety.js +0 -88
- package/scripts/lib/context-savings-engine.js +0 -158
- package/scripts/lib/cost-evidence.js +0 -254
- package/scripts/lib/cross-host-install-plan.js +0 -308
- package/scripts/lib/cross-host-install-readiness.js +0 -237
- package/scripts/lib/cross-host-value-flow.js +0 -268
- package/scripts/lib/dashboard.js +0 -900
- package/scripts/lib/design-partner-feedback.js +0 -346
- package/scripts/lib/entitlements.js +0 -100
- package/scripts/lib/execution-packet.js +0 -559
- package/scripts/lib/experimentation-events.js +0 -547
- package/scripts/lib/external-capability-compliance.js +0 -107
- package/scripts/lib/external-user-simulation.js +0 -166
- package/scripts/lib/failure-recovery-readiness.js +0 -81
- package/scripts/lib/failure-recovery.js +0 -419
- package/scripts/lib/feedback-intelligence.js +0 -537
- package/scripts/lib/feedback-signals.js +0 -205
- package/scripts/lib/file-integrity.js +0 -68
- package/scripts/lib/fsx.js +0 -127
- package/scripts/lib/full-readiness-gate.js +0 -451
- package/scripts/lib/guidance-builder.js +0 -174
- package/scripts/lib/hook-apply.js +0 -1019
- package/scripts/lib/hook-baseline.js +0 -310
- package/scripts/lib/hook-config-preview.js +0 -275
- package/scripts/lib/hook-contracts.js +0 -290
- package/scripts/lib/hook-safety-boundary-readiness.js +0 -80
- package/scripts/lib/host-capability-matrix.js +0 -351
- package/scripts/lib/host-support-context.js +0 -254
- package/scripts/lib/http-hook-action.js +0 -538
- package/scripts/lib/install-ai-readiness.js +0 -84
- package/scripts/lib/install-intake-risk.js +0 -1037
- package/scripts/lib/install-journey-intelligence.js +0 -329
- package/scripts/lib/intervention-guidance.js +0 -57
- package/scripts/lib/known-limitations.js +0 -115
- package/scripts/lib/l8-path-truth.js +0 -146
- package/scripts/lib/launch-hardening-gate.js +0 -436
- package/scripts/lib/launch-readiness.js +0 -628
- package/scripts/lib/learning-memory.js +0 -686
- package/scripts/lib/lifecycle-hooks.js +0 -802
- package/scripts/lib/local-package-smoke.js +0 -423
- package/scripts/lib/local-pricing.js +0 -299
- package/scripts/lib/mcp-enforcement.js +0 -311
- package/scripts/lib/mcp-least-privilege-policy.js +0 -303
- package/scripts/lib/mcp-tool-inventory.js +0 -388
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +0 -335
- package/scripts/lib/metrics.js +0 -699
- package/scripts/lib/micro-proof.js +0 -133
- package/scripts/lib/next-run-context.js +0 -436
- package/scripts/lib/operating-value.js +0 -1648
- package/scripts/lib/optimization-v3.js +0 -122
- package/scripts/lib/orchestration/adapters/_shared.js +0 -49
- package/scripts/lib/orchestration/adapters/aider.js +0 -18
- package/scripts/lib/orchestration/adapters/claude-code.js +0 -35
- package/scripts/lib/orchestration/adapters/codex.js +0 -35
- package/scripts/lib/orchestration/adapters/gemini-cli.js +0 -18
- package/scripts/lib/orchestration/adapters/git.js +0 -25
- package/scripts/lib/orchestration/adapters/index.js +0 -31
- package/scripts/lib/orchestration/adapters/lm-studio.js +0 -18
- package/scripts/lib/orchestration/adapters/ollama.js +0 -18
- package/scripts/lib/orchestration/adapters/opencode.js +0 -18
- package/scripts/lib/orchestration/adapters/openrouter.js +0 -18
- package/scripts/lib/orchestration/adapters/test-runner.js +0 -25
- package/scripts/lib/orchestration/cli.js +0 -438
- package/scripts/lib/orchestration/execution-manager.js +0 -279
- package/scripts/lib/orchestration/handoff.js +0 -314
- package/scripts/lib/orchestration/index.js +0 -456
- package/scripts/lib/orchestration/inventory.js +0 -47
- package/scripts/lib/orchestration/model-discovery.js +0 -498
- package/scripts/lib/orchestration/model-profiler.js +0 -170
- package/scripts/lib/orchestration/model-profiles.js +0 -252
- package/scripts/lib/orchestration/model-refresh-policy.js +0 -72
- package/scripts/lib/orchestration/proof-writer.js +0 -349
- package/scripts/lib/orchestration/provider-discovery/aider.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +0 -56
- package/scripts/lib/orchestration/provider-discovery/codex.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/common.js +0 -186
- package/scripts/lib/orchestration/provider-discovery/gemini.js +0 -106
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +0 -118
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +0 -12
- package/scripts/lib/orchestration/provider-discovery/ollama.js +0 -100
- package/scripts/lib/orchestration/provider-discovery/opencode.js +0 -47
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +0 -44
- package/scripts/lib/orchestration/risk-classifier.js +0 -130
- package/scripts/lib/orchestration/routing-policy.js +0 -486
- package/scripts/lib/orchestration/settings.js +0 -112
- package/scripts/lib/orchestration/state.js +0 -165
- package/scripts/lib/orchestration/verification-manager.js +0 -138
- package/scripts/lib/output-profiles.js +0 -146
- package/scripts/lib/package-content-audit.js +0 -368
- package/scripts/lib/package-runtime.js +0 -278
- package/scripts/lib/plan-surface.js +0 -53
- package/scripts/lib/plans.js +0 -2318
- package/scripts/lib/policy-provider.js +0 -27
- package/scripts/lib/prelaunch-activation-readiness.js +0 -409
- package/scripts/lib/prelaunch-evidence-store.js +0 -816
- package/scripts/lib/prelaunch-intelligence.js +0 -869
- package/scripts/lib/pricing-experiment.js +0 -118
- package/scripts/lib/pro-moment-events.js +0 -77
- package/scripts/lib/pro-moment-state.js +0 -227
- package/scripts/lib/pro-moments.js +0 -1216
- package/scripts/lib/product-learning-events.js +0 -629
- package/scripts/lib/project-profile.js +0 -555
- package/scripts/lib/prompt-compiler.js +0 -280
- package/scripts/lib/prompt-lint.js +0 -32
- package/scripts/lib/prompt-suggestions.js +0 -52
- package/scripts/lib/proof-canonical.js +0 -398
- package/scripts/lib/proof-drilldown.js +0 -383
- package/scripts/lib/proof-events.js +0 -342
- package/scripts/lib/proof-history.js +0 -243
- package/scripts/lib/proof-metrics.js +0 -296
- package/scripts/lib/proof-outcome-evidence.js +0 -134
- package/scripts/lib/proof-receipt.js +0 -335
- package/scripts/lib/proof-record.js +0 -461
- package/scripts/lib/public-activation-distribution-gate.js +0 -258
- package/scripts/lib/public-cli.js +0 -3891
- package/scripts/lib/public-distribution-truth.js +0 -211
- package/scripts/lib/public-install-claim-checker.js +0 -294
- package/scripts/lib/publish-provenance-readiness.js +0 -283
- package/scripts/lib/readiness-delta.js +0 -218
- package/scripts/lib/readiness-evidence-closure.js +0 -196
- package/scripts/lib/reentry-memory-capture.js +0 -241
- package/scripts/lib/reentry-memory-retrieval.js +0 -302
- package/scripts/lib/reentry-memory-status.js +0 -146
- package/scripts/lib/reentry-memory-store.js +0 -178
- package/scripts/lib/reentry-state.js +0 -66
- package/scripts/lib/release-candidate-bundle.js +0 -166
- package/scripts/lib/remediation.js +0 -81
- package/scripts/lib/repo-map.js +0 -391
- package/scripts/lib/run-improvements-lifecycle.js +0 -330
- package/scripts/lib/run-improvements.js +0 -789
- package/scripts/lib/runtime-decision-policy.js +0 -387
- package/scripts/lib/safe-path-engine.js +0 -705
- package/scripts/lib/safe-run-controller.js +0 -887
- package/scripts/lib/score.js +0 -262
- package/scripts/lib/seamless-enforcement.js +0 -329
- package/scripts/lib/seamless-outcome.js +0 -689
- package/scripts/lib/seamless-reality-gate.js +0 -5043
- package/scripts/lib/security-risk-classifier.js +0 -511
- package/scripts/lib/security-scan.js +0 -384
- package/scripts/lib/session-context-optimizer.js +0 -1211
- package/scripts/lib/session-timing.js +0 -315
- package/scripts/lib/skill-hygiene.js +0 -805
- package/scripts/lib/skill-packs.js +0 -161
- package/scripts/lib/skills-operating-layer.js +0 -580
- package/scripts/lib/smart-work-routing.js +0 -768
- package/scripts/lib/source-catalog.js +0 -700
- package/scripts/lib/status-value-summary.js +0 -32
- package/scripts/lib/support-bundle.js +0 -578
- package/scripts/lib/task-continuation.js +0 -440
- package/scripts/lib/test-helpers.js +0 -15
- package/scripts/lib/tier.js +0 -38
- package/scripts/lib/token-context-quality-gate.js +0 -370
- package/scripts/lib/token-cost-capture.js +0 -187
- package/scripts/lib/token-cost-intelligence.js +0 -358
- package/scripts/lib/token-efficiency-evidence.js +0 -213
- package/scripts/lib/token-evidence.js +0 -699
- package/scripts/lib/tokenish.js +0 -17
- package/scripts/lib/tool-output-sandbox.js +0 -304
- package/scripts/lib/trust-audit.js +0 -136
- package/scripts/lib/unified-events.js +0 -396
- package/scripts/lib/upgrade-interruption-recovery.js +0 -407
- package/scripts/lib/usage-ledger.js +0 -201
- package/scripts/lib/value-ledger.js +0 -130
- package/scripts/lib/value-proof-calibration.js +0 -531
- package/scripts/lib/visual-qa.js +0 -231
- package/scripts/lib/voice-alpha.js +0 -29
- package/scripts/lib/work-aware-orchestration.js +0 -976
- package/scripts/lib/work-control-receipts.js +0 -577
- package/scripts/lib/work-ledger.js +0 -1123
- package/scripts/lib/work-panel-preview.js +0 -352
- package/scripts/lib/workflow-discipline.js +0 -280
- package/scripts/lib/workflow-signals.js +0 -419
- package/scripts/lib/workspace-map.js +0 -281
- package/scripts/lib/workspace-registry.js +0 -1367
- package/scripts/lib/workspace-resolver.js +0 -480
|
@@ -1,461 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shared Proof Record Model (ProofRecordV1).
|
|
5
|
-
*
|
|
6
|
-
* A ProofRecordV1 is composed per-run from existing metrics + outcome events.
|
|
7
|
-
* This is a derivation layer - it reads existing JSONL and composes a structured
|
|
8
|
-
* proof object. No new storage format is introduced.
|
|
9
|
-
*
|
|
10
|
-
* All 4 proof surfaces (micro-proof, receipt, drilldown, scorecard) derive from this model.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const { readSessionMetrics } = require("./metrics");
|
|
14
|
-
const { readOutcomeEvents } = require("./unified-events");
|
|
15
|
-
const { countByDimension, countByFamily } = require("./proof-events");
|
|
16
|
-
const { validateProofRecord } = require("./anti-gaming");
|
|
17
|
-
const {
|
|
18
|
-
buildBoundedStateContext,
|
|
19
|
-
extractCanonicalProofEntries,
|
|
20
|
-
latestCanonicalEntriesByFamily,
|
|
21
|
-
latestTerminalCanonicalSignal,
|
|
22
|
-
formatNextBoundedAction,
|
|
23
|
-
normalizeTaskContractSummary,
|
|
24
|
-
} = require("./proof-canonical");
|
|
25
|
-
|
|
26
|
-
function uniqueStrings(values) {
|
|
27
|
-
return [...new Set((values || []).map((value) => String(value || "").trim()).filter(Boolean))];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function latestValue(signals, field) {
|
|
31
|
-
const values = (signals || []).map((signal) => signal?.[field]).filter((value) => value !== undefined && value !== null && value !== "");
|
|
32
|
-
return values.length > 0 ? values[values.length - 1] : null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function signalReasonCodes(signal) {
|
|
36
|
-
return Array.isArray(signal?.reason_codes) ? signal.reason_codes : [];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function buildCanonicalContext(metrics, outcomeEvents, boundedState) {
|
|
40
|
-
const entries = [...(metrics || []), ...(outcomeEvents || [])];
|
|
41
|
-
const canonicalEntries = extractCanonicalProofEntries(entries);
|
|
42
|
-
const latestByFamily = latestCanonicalEntriesByFamily(entries);
|
|
43
|
-
const taskContractSignal = latestByFamily.get("task_contract")?.signal || null;
|
|
44
|
-
const safeStopSignal = latestByFamily.get("safe_stop")?.signal || null;
|
|
45
|
-
const completionSignal = latestByFamily.get("completion_truth")?.signal || null;
|
|
46
|
-
const terminalSignal = latestTerminalCanonicalSignal(entries);
|
|
47
|
-
const controlSignals = canonicalEntries
|
|
48
|
-
.filter((entry) => entry.signal.family === "control_decision")
|
|
49
|
-
.map((entry) => entry.signal);
|
|
50
|
-
const materialSignals = canonicalEntries
|
|
51
|
-
.filter((entry) => entry.signal.family === "material_step")
|
|
52
|
-
.map((entry) => entry.signal);
|
|
53
|
-
const embeddedTaskContract = canonicalEntries
|
|
54
|
-
.map((entry) => normalizeTaskContractSummary(entry.signal.task_contract))
|
|
55
|
-
.filter(Boolean)
|
|
56
|
-
.at(-1) || null;
|
|
57
|
-
const taskContract = normalizeTaskContractSummary(taskContractSignal) || embeddedTaskContract || null;
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
canonicalEntries,
|
|
61
|
-
controlSignals,
|
|
62
|
-
materialSignals,
|
|
63
|
-
taskContract,
|
|
64
|
-
safeStopSignal,
|
|
65
|
-
completionSignal,
|
|
66
|
-
terminalSignal,
|
|
67
|
-
boundedState: boundedState || null,
|
|
68
|
-
evidenceRefs: uniqueStrings([
|
|
69
|
-
...(taskContract?.evidence_refs || []),
|
|
70
|
-
...(safeStopSignal?.evidence_refs || []),
|
|
71
|
-
...(completionSignal?.evidence_refs || []),
|
|
72
|
-
...(boundedState?.evidence_refs || []),
|
|
73
|
-
...materialSignals.flatMap((signal) => signal.evidence_refs || []),
|
|
74
|
-
...controlSignals.flatMap((signal) => signal.evidence_refs || []),
|
|
75
|
-
]),
|
|
76
|
-
artifactRefs: uniqueStrings([
|
|
77
|
-
...(boundedState?.artifact_refs || []),
|
|
78
|
-
safeStopSignal?.progress_ref,
|
|
79
|
-
completionSignal?.artifact_ref,
|
|
80
|
-
completionSignal?.output_artifact_reference,
|
|
81
|
-
...materialSignals.map((signal) => signal.artifact_ref || signal.output_artifact_reference),
|
|
82
|
-
boundedState?.artifact_path,
|
|
83
|
-
]),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function fallbackCompletionStatus(metrics, allCodes) {
|
|
88
|
-
const hasTaskCompleted = allCodes.includes("TASK_COMPLETED");
|
|
89
|
-
const hasStopSnapshot = allCodes.includes("STOP_SNAPSHOT");
|
|
90
|
-
const hasFailRetry = allCodes.includes("FAIL_RETRY_GUARD");
|
|
91
|
-
|
|
92
|
-
if (hasTaskCompleted) return "completed";
|
|
93
|
-
if (hasStopSnapshot) return "safe_stop";
|
|
94
|
-
if (hasFailRetry) return "partial";
|
|
95
|
-
if ((metrics || []).length > 0) return "ended_without_completion";
|
|
96
|
-
return "unknown";
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function fallbackOutcomeType(allCodes) {
|
|
100
|
-
if (allCodes.includes("TASK_COMPLETED")) return "useful_result";
|
|
101
|
-
if (allCodes.includes("STOP_SNAPSHOT")) return "safe_stop_with_next_action";
|
|
102
|
-
if (allCodes.includes("FAIL_RETRY_GUARD")) return "partial_with_recovery";
|
|
103
|
-
return "indeterminate";
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Build a ProofRecordV1 for a given session.
|
|
108
|
-
*
|
|
109
|
-
* @param {string} cwd - workspace root
|
|
110
|
-
* @param {string} sessionId - session identifier
|
|
111
|
-
* @returns {object} ProofRecordV1
|
|
112
|
-
*/
|
|
113
|
-
function buildProofRecord(cwd, sessionId) {
|
|
114
|
-
const metrics = readSessionMetrics(cwd, sessionId);
|
|
115
|
-
const outcomeEvents = readOutcomeEvents(cwd).filter((e) => e.session_id === sessionId);
|
|
116
|
-
|
|
117
|
-
return composeProofRecord(sessionId, metrics, outcomeEvents, {
|
|
118
|
-
boundedState: buildBoundedStateContext(cwd),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Compose a proof record from pre-loaded data (useful for testing).
|
|
124
|
-
*/
|
|
125
|
-
function composeProofRecord(sessionId, metrics, outcomeEvents, options = {}) {
|
|
126
|
-
const allCodes = metrics.flatMap((m) => m.reasonCodes || []);
|
|
127
|
-
const timestamps = metrics.map((m) => Date.parse(m.ts || 0)).filter((t) => Number.isFinite(t));
|
|
128
|
-
const startedAt = timestamps.length ? new Date(Math.min(...timestamps)).toISOString() : null;
|
|
129
|
-
const endedAt = timestamps.length ? new Date(Math.max(...timestamps)).toISOString() : null;
|
|
130
|
-
|
|
131
|
-
const dimensionCounts = countByDimension(metrics);
|
|
132
|
-
const familyCounts = countByFamily(metrics);
|
|
133
|
-
const canonical = buildCanonicalContext(metrics, outcomeEvents, options.boundedState || null);
|
|
134
|
-
|
|
135
|
-
const core = buildCoreIdentity(sessionId, metrics, allCodes, startedAt, endedAt, canonical);
|
|
136
|
-
const outcome = buildOutcomeProof(metrics, allCodes, outcomeEvents, canonical, core);
|
|
137
|
-
const efficiency = buildEfficiencyProof(metrics, allCodes, canonical);
|
|
138
|
-
const trust = buildTrustProof(metrics, allCodes, canonical, core, outcome);
|
|
139
|
-
const control = buildControlProof(metrics, allCodes, canonical);
|
|
140
|
-
const ux = buildUxExposure(metrics, allCodes);
|
|
141
|
-
const repoTruth = buildRepoTruth(canonical, core, outcome);
|
|
142
|
-
|
|
143
|
-
const record = {
|
|
144
|
-
version: 1,
|
|
145
|
-
...core,
|
|
146
|
-
outcome,
|
|
147
|
-
efficiency,
|
|
148
|
-
trust,
|
|
149
|
-
control,
|
|
150
|
-
ux,
|
|
151
|
-
task_contract: canonical.taskContract,
|
|
152
|
-
repo_truth: repoTruth,
|
|
153
|
-
dimension_counts: dimensionCounts,
|
|
154
|
-
family_counts: familyCounts,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const validation = validateProofRecord(record);
|
|
158
|
-
record.anti_gaming = validation;
|
|
159
|
-
|
|
160
|
-
return record;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function buildCoreIdentity(sessionId, metrics, allCodes, startedAt, endedAt, canonical) {
|
|
164
|
-
const terminal = canonical.completionSignal || canonical.safeStopSignal || canonical.terminalSignal;
|
|
165
|
-
const completionStatus =
|
|
166
|
-
canonical.completionSignal?.completion_status ||
|
|
167
|
-
(canonical.safeStopSignal ? "safe_stop" : null) ||
|
|
168
|
-
fallbackCompletionStatus(metrics, allCodes);
|
|
169
|
-
|
|
170
|
-
const finalOutcomeType =
|
|
171
|
-
canonical.completionSignal?.final_outcome_type ||
|
|
172
|
-
(canonical.safeStopSignal ? "safe_stop_with_next_action" : null) ||
|
|
173
|
-
fallbackOutcomeType(allCodes);
|
|
174
|
-
|
|
175
|
-
const reentryStatus =
|
|
176
|
-
terminal?.reentry_status ||
|
|
177
|
-
canonical.boundedState?.reentry_status ||
|
|
178
|
-
(completionStatus === "safe_stop" ? "reentry_available" : "not_applicable");
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
run_id: sessionId,
|
|
182
|
-
session_id: sessionId,
|
|
183
|
-
workspace_id: null,
|
|
184
|
-
task_type: inferTaskType(metrics),
|
|
185
|
-
user_id: metrics[0]?.meta?.userId || "local-user",
|
|
186
|
-
started_at: startedAt,
|
|
187
|
-
ended_at: endedAt,
|
|
188
|
-
completion_status: completionStatus,
|
|
189
|
-
final_outcome_type: finalOutcomeType,
|
|
190
|
-
bounded_or_unbounded: "bounded",
|
|
191
|
-
reentry_status: reentryStatus,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function buildOutcomeProof(metrics, allCodes, outcomeEvents, canonical, core) {
|
|
196
|
-
const hasTaskCompleted = allCodes.includes("TASK_COMPLETED");
|
|
197
|
-
const hasStopSnapshot = allCodes.includes("STOP_SNAPSHOT");
|
|
198
|
-
const hasReport = allCodes.includes("REPORT_WRITTEN");
|
|
199
|
-
const completionSignal = canonical.completionSignal;
|
|
200
|
-
const safeStopSignal = canonical.safeStopSignal;
|
|
201
|
-
const boundedState = canonical.boundedState;
|
|
202
|
-
|
|
203
|
-
let usefulResultState = "unknown";
|
|
204
|
-
if (completionSignal?.useful_result_state) usefulResultState = completionSignal.useful_result_state;
|
|
205
|
-
else if (boundedState?.artifact_truth_status === "meaningful") usefulResultState = "useful";
|
|
206
|
-
else if (boundedState?.artifact_truth_status === "weak_but_structurally_valid") usefulResultState = "bounded_useful";
|
|
207
|
-
else if (hasTaskCompleted) usefulResultState = "useful";
|
|
208
|
-
else if (core.completion_status === "safe_stop") usefulResultState = "bounded_useful";
|
|
209
|
-
else usefulResultState = "not_determined";
|
|
210
|
-
|
|
211
|
-
let completionQualityState = "unknown";
|
|
212
|
-
if (completionSignal?.completion_quality_state) completionQualityState = completionSignal.completion_quality_state;
|
|
213
|
-
else if (boundedState?.readiness_status === "pass") completionQualityState = "high";
|
|
214
|
-
else if (boundedState?.readiness_status === "internal_only") completionQualityState = "bounded";
|
|
215
|
-
else if (hasTaskCompleted && hasReport) completionQualityState = "high";
|
|
216
|
-
else if (hasTaskCompleted) completionQualityState = "medium";
|
|
217
|
-
else if (core.completion_status === "safe_stop") completionQualityState = "bounded";
|
|
218
|
-
else completionQualityState = "low";
|
|
219
|
-
|
|
220
|
-
const nextBoundedAction =
|
|
221
|
-
formatNextBoundedAction(completionSignal?.next_bounded_action) ||
|
|
222
|
-
formatNextBoundedAction(safeStopSignal?.next_bounded_action) ||
|
|
223
|
-
formatNextBoundedAction(boundedState?.next_bounded_action) ||
|
|
224
|
-
(core.completion_status === "safe_stop" ? "review_snapshot_and_resume" : null);
|
|
225
|
-
|
|
226
|
-
const artifactRef =
|
|
227
|
-
completionSignal?.output_artifact_reference ||
|
|
228
|
-
completionSignal?.artifact_ref ||
|
|
229
|
-
canonical.artifactRefs[0] ||
|
|
230
|
-
null;
|
|
231
|
-
|
|
232
|
-
const artifactType =
|
|
233
|
-
completionSignal?.output_artifact_type ||
|
|
234
|
-
(hasReport ? "session_report" : artifactRef ? "runtime_artifact" : null);
|
|
235
|
-
|
|
236
|
-
const evidenceBackedCompletion =
|
|
237
|
-
typeof completionSignal?.evidence_backed_completion === "boolean"
|
|
238
|
-
? completionSignal.evidence_backed_completion
|
|
239
|
-
: (core.completion_status === "completed" || core.completion_status === "safe_stop") &&
|
|
240
|
-
canonical.evidenceRefs.length > 0;
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
output_artifact_type: artifactType,
|
|
244
|
-
output_artifact_reference: artifactRef,
|
|
245
|
-
useful_result_state: usefulResultState,
|
|
246
|
-
completion_quality_state: completionQualityState,
|
|
247
|
-
evidence_backed_completion: evidenceBackedCompletion,
|
|
248
|
-
evidence_status: canonical.evidenceRefs.length > 0 ? "related_evidence_present" : "no_evidence",
|
|
249
|
-
partial_completion_reason:
|
|
250
|
-
completionSignal?.partial_completion_reason ||
|
|
251
|
-
(!hasTaskCompleted && core.completion_status === "safe_stop" ? "safe_stop_reached" : null),
|
|
252
|
-
safe_stop_reason:
|
|
253
|
-
safeStopSignal?.safe_stop_reason ||
|
|
254
|
-
(core.completion_status === "safe_stop" || hasStopSnapshot ? "bounded_execution_limit" : null),
|
|
255
|
-
next_bounded_action: nextBoundedAction,
|
|
256
|
-
unresolved_items:
|
|
257
|
-
Array.isArray(completionSignal?.unresolved_items) && completionSignal.unresolved_items.length > 0
|
|
258
|
-
? completionSignal.unresolved_items
|
|
259
|
-
: [],
|
|
260
|
-
evidence_refs: canonical.evidenceRefs,
|
|
261
|
-
claim_boundary: completionSignal?.claim_boundary || boundedState?.claim_boundary || null,
|
|
262
|
-
where_am_i_now: completionSignal?.where_am_i_now || boundedState?.where_am_i_now || null,
|
|
263
|
-
readiness_status: boundedState?.readiness_status || null,
|
|
264
|
-
exposure_scope: boundedState?.exposure_scope || null,
|
|
265
|
-
artifact_truth_status: boundedState?.artifact_truth_status || null,
|
|
266
|
-
counts_as_meaningful_output:
|
|
267
|
-
typeof boundedState?.counts_as_meaningful_output === "boolean"
|
|
268
|
-
? boundedState.counts_as_meaningful_output
|
|
269
|
-
: null,
|
|
270
|
-
progress_ref: safeStopSignal?.progress_ref || boundedState?.artifact_path || null,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function buildEfficiencyProof(metrics, allCodes, canonical) {
|
|
275
|
-
const largeOutputMetrics = metrics.filter((m) => (m.reasonCodes || []).includes("CTX_LARGE_OUTPUT"));
|
|
276
|
-
const canonicalLargeOutputs = canonical.materialSignals.filter(
|
|
277
|
-
(signal) => signal.step_type === "large_output_managed"
|
|
278
|
-
);
|
|
279
|
-
const largeOutputBytes = largeOutputMetrics.reduce((sum, m) => {
|
|
280
|
-
const bytes = Number(m.meta?.bytes || 0);
|
|
281
|
-
return sum + (Number.isFinite(bytes) ? bytes : 0);
|
|
282
|
-
}, 0) || canonicalLargeOutputs.reduce((sum, signal) => sum + Number(signal.bytes || 0), 0);
|
|
283
|
-
|
|
284
|
-
const largeOutputEvents = largeOutputMetrics.length || canonicalLargeOutputs.length;
|
|
285
|
-
const scanSkips =
|
|
286
|
-
allCodes.filter((code) => code === "CTX_SCAN_SKIPPED_UNCHANGED").length ||
|
|
287
|
-
canonical.materialSignals.filter((signal) => signal.step_type === "scan_skipped").length;
|
|
288
|
-
const loopInterrupts = allCodes.filter((code) => code === "LOOP_REPEATED_TOOL").length;
|
|
289
|
-
const failRetries =
|
|
290
|
-
allCodes.filter((code) => code === "FAIL_RETRY_GUARD").length ||
|
|
291
|
-
canonical.materialSignals.filter((signal) => signal.step_type === "retry_guard").length;
|
|
292
|
-
const permFatigueConsolidated = allCodes.filter((code) => code === "PERM_FATIGUE_CONSOLIDATED").length;
|
|
293
|
-
const toolCalls = metrics.filter((m) => m.event === "PreToolUse").length;
|
|
294
|
-
|
|
295
|
-
const timeSavedMinutes = loopInterrupts * 3 + largeOutputEvents;
|
|
296
|
-
const timeSavedConfidence = loopInterrupts + largeOutputEvents >= 3 ? "medium" : "low";
|
|
297
|
-
|
|
298
|
-
return {
|
|
299
|
-
large_output_bytes_managed: largeOutputBytes || 0,
|
|
300
|
-
large_output_events: largeOutputEvents,
|
|
301
|
-
tools_considered: toolCalls,
|
|
302
|
-
tools_loaded: toolCalls,
|
|
303
|
-
tools_skipped: scanSkips,
|
|
304
|
-
retries_count: failRetries + loopInterrupts,
|
|
305
|
-
dead_end_count: 0,
|
|
306
|
-
recovery_count: failRetries,
|
|
307
|
-
approval_interruptions_avoided: permFatigueConsolidated,
|
|
308
|
-
time_saved_estimate:
|
|
309
|
-
timeSavedMinutes > 0
|
|
310
|
-
? { minutes: timeSavedMinutes, confidence: timeSavedConfidence, basis: "heuristic" }
|
|
311
|
-
: null,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
function buildTrustProof(metrics, allCodes, canonical, core, outcome) {
|
|
316
|
-
const securityEvidence = canonical.evidenceRefs.filter((ref) => ref.includes("/security/") || ref.includes("\\security\\"));
|
|
317
|
-
const evidenceBundleReference =
|
|
318
|
-
securityEvidence[0] ||
|
|
319
|
-
(canonical.evidenceRefs.length > 0 ? canonical.evidenceRefs[0] : null) ||
|
|
320
|
-
(allCodes.some((code) => code === "SEC_TRUST_AUDIT" || code === "SEC_REMEDIATION_JOB_CREATED")
|
|
321
|
-
? ".claude/cco/security/"
|
|
322
|
-
: null);
|
|
323
|
-
const safeStopSignal = canonical.safeStopSignal;
|
|
324
|
-
const boundedState = canonical.boundedState;
|
|
325
|
-
const trustUnknownHigh = allCodes.filter((code) => code === "SEC_TRUST_UNKNOWN_HIGH").length;
|
|
326
|
-
|
|
327
|
-
return {
|
|
328
|
-
evidence_bundle_reference: evidenceBundleReference,
|
|
329
|
-
has_related_evidence: canonical.evidenceRefs.length > 0,
|
|
330
|
-
has_suppression_audit:
|
|
331
|
-
allCodes.includes("SEC_SUPPRESSION_AUDIT") ||
|
|
332
|
-
canonical.materialSignals.some((signal) => signal.step_type === "suppression_audit"),
|
|
333
|
-
unverified_claim_count: trustUnknownHigh,
|
|
334
|
-
uncertainty_annotations_count: trustUnknownHigh,
|
|
335
|
-
traceability_status: metrics.length > 0 ? "traceable" : "no_data",
|
|
336
|
-
rollback_available:
|
|
337
|
-
safeStopSignal?.rollback_available ??
|
|
338
|
-
boundedState?.rollback_available ??
|
|
339
|
-
(core.completion_status === "safe_stop"),
|
|
340
|
-
rollback_trigger: boundedState?.rollback_trigger || null,
|
|
341
|
-
readiness_status: boundedState?.readiness_status || null,
|
|
342
|
-
artifact_truth_status: boundedState?.artifact_truth_status || null,
|
|
343
|
-
progress_preserved:
|
|
344
|
-
safeStopSignal?.progress_preserved ??
|
|
345
|
-
(core.completion_status === "safe_stop" && Boolean(outcome.progress_ref)),
|
|
346
|
-
reentry_anchor_saved:
|
|
347
|
-
safeStopSignal?.reentry_anchor_saved ??
|
|
348
|
-
(core.completion_status === "safe_stop" && Boolean(outcome.progress_ref)),
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function buildRepoTruth(canonical, core, outcome) {
|
|
353
|
-
const boundedState = canonical.boundedState || null;
|
|
354
|
-
if (!boundedState && !outcome?.claim_boundary && !outcome?.where_am_i_now) return null;
|
|
355
|
-
|
|
356
|
-
return {
|
|
357
|
-
where_am_i_now: outcome?.where_am_i_now || boundedState?.where_am_i_now || null,
|
|
358
|
-
what_can_i_honestly_claim: outcome?.claim_boundary || boundedState?.claim_boundary || null,
|
|
359
|
-
readiness_status: outcome?.readiness_status || boundedState?.readiness_status || null,
|
|
360
|
-
exposure_scope: outcome?.exposure_scope || boundedState?.exposure_scope || null,
|
|
361
|
-
artifact_truth_status: outcome?.artifact_truth_status || boundedState?.artifact_truth_status || null,
|
|
362
|
-
counts_as_meaningful_output:
|
|
363
|
-
typeof outcome?.counts_as_meaningful_output === "boolean"
|
|
364
|
-
? outcome.counts_as_meaningful_output
|
|
365
|
-
: typeof boundedState?.counts_as_meaningful_output === "boolean"
|
|
366
|
-
? boundedState.counts_as_meaningful_output
|
|
367
|
-
: null,
|
|
368
|
-
reentry_status: core?.reentry_status || boundedState?.reentry_status || null,
|
|
369
|
-
rollback_available: Boolean(boundedState?.rollback_available),
|
|
370
|
-
rollback_trigger: boundedState?.rollback_trigger || null,
|
|
371
|
-
next_bounded_action: outcome?.next_bounded_action || formatNextBoundedAction(boundedState?.next_bounded_action),
|
|
372
|
-
reason_summary: boundedState?.reentry_reason_summary || null,
|
|
373
|
-
evidence_refs: boundedState?.evidence_refs || [],
|
|
374
|
-
artifact_refs: boundedState?.artifact_refs || [],
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function mapScopeStatus(scopeStatus, riskyBlocked, policyHits) {
|
|
379
|
-
if (scopeStatus === "no_violations_detected" || scopeStatus === "violations_handled") {
|
|
380
|
-
return scopeStatus;
|
|
381
|
-
}
|
|
382
|
-
if (scopeStatus === "within_policy") return "no_violations_detected";
|
|
383
|
-
if (scopeStatus === "unknown" || !scopeStatus) {
|
|
384
|
-
return riskyBlocked === 0 && policyHits === 0 ? "no_violations_detected" : "violations_handled";
|
|
385
|
-
}
|
|
386
|
-
return riskyBlocked === 0 && policyHits === 0 ? "no_violations_detected" : "violations_handled";
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
function buildControlProof(metrics, allCodes, canonical) {
|
|
390
|
-
const secMetrics = metrics.filter((m) =>
|
|
391
|
-
(m.reasonCodes || []).some((code) => String(code).startsWith("SEC_"))
|
|
392
|
-
);
|
|
393
|
-
const canonicalRiskSignals = canonical.controlSignals.filter(
|
|
394
|
-
(signal) =>
|
|
395
|
-
signal.decision === "deny" ||
|
|
396
|
-
signal.decision === "ask" ||
|
|
397
|
-
signal.approval_required === true ||
|
|
398
|
-
signalReasonCodes(signal).some((code) => String(code).startsWith("SEC_")) ||
|
|
399
|
-
signal.source === "policy"
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
const riskyAttempts = Math.max(secMetrics.length, canonicalRiskSignals.length);
|
|
403
|
-
const riskyBlocked = Math.max(
|
|
404
|
-
secMetrics.filter((m) => m.action === "deny").length,
|
|
405
|
-
canonicalRiskSignals.filter((signal) => signal.decision === "deny").length
|
|
406
|
-
);
|
|
407
|
-
const riskyDowngraded = Math.max(
|
|
408
|
-
secMetrics.filter((m) => m.action === "ask").length,
|
|
409
|
-
canonicalRiskSignals.filter((signal) => signal.decision === "ask").length
|
|
410
|
-
);
|
|
411
|
-
|
|
412
|
-
const approvalTriggered = Math.max(
|
|
413
|
-
metrics.filter((m) => m.event === "PermissionRequest").length,
|
|
414
|
-
canonical.controlSignals.filter((signal) => signal.approval_required === true).length
|
|
415
|
-
);
|
|
416
|
-
const approvalAvoided = allCodes.filter((code) => code === "PERM_FATIGUE_CONSOLIDATED").length;
|
|
417
|
-
const policyHits = Math.max(
|
|
418
|
-
allCodes.filter((code) => code === "TEAM_BLOCK_PATTERN").length,
|
|
419
|
-
canonical.controlSignals.filter((signal) => signal.policy_boundary && signal.decision !== "allow").length
|
|
420
|
-
);
|
|
421
|
-
const latestScopeStatus = latestValue(canonical.controlSignals, "scope_status");
|
|
422
|
-
const safeStopCount = canonical.safeStopSignal ? 1 : allCodes.filter((code) => code === "STOP_SNAPSHOT").length;
|
|
423
|
-
|
|
424
|
-
return {
|
|
425
|
-
risky_action_attempts: riskyAttempts,
|
|
426
|
-
risky_actions_blocked: riskyBlocked,
|
|
427
|
-
risky_actions_downgraded: riskyDowngraded,
|
|
428
|
-
approval_requests_triggered: approvalTriggered,
|
|
429
|
-
approval_requests_avoided: approvalAvoided,
|
|
430
|
-
policy_boundary_hits: policyHits,
|
|
431
|
-
trusted_scope_preserved: mapScopeStatus(latestScopeStatus, riskyBlocked, policyHits),
|
|
432
|
-
safe_stop_count: safeStopCount,
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
function buildUxExposure(metrics, allCodes) {
|
|
437
|
-
const microProofCount = allCodes.filter((code) => code === "PROOF_MICRO_RENDERED").length;
|
|
438
|
-
const receiptGenerated = allCodes.includes("PROOF_RECEIPT_GENERATED");
|
|
439
|
-
const receiptOpened = allCodes.includes("PROOF_RECEIPT_OPENED");
|
|
440
|
-
const drilldownOpened = allCodes.includes("PROOF_DRILLDOWN_OPENED");
|
|
441
|
-
|
|
442
|
-
return {
|
|
443
|
-
micro_proof_rendered_count: microProofCount,
|
|
444
|
-
receipt_generated: receiptGenerated,
|
|
445
|
-
receipt_opened: receiptOpened,
|
|
446
|
-
drilldown_opened: drilldownOpened,
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function inferTaskType(metrics) {
|
|
451
|
-
const tools = metrics.map((m) => m.tool).filter(Boolean);
|
|
452
|
-
if (tools.includes("Write") || tools.includes("Edit")) return "coding";
|
|
453
|
-
if (tools.includes("Bash")) return "command";
|
|
454
|
-
if (tools.includes("Read") || tools.includes("Grep") || tools.includes("Glob")) return "exploration";
|
|
455
|
-
return "general";
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
module.exports = {
|
|
459
|
-
buildProofRecord,
|
|
460
|
-
composeProofRecord,
|
|
461
|
-
};
|