avorelo 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 +21 -0
- package/README.md +56 -0
- package/bin/avorelo +9 -0
- package/package.json +135 -0
- package/scripts/README.md +40 -0
- package/scripts/cco-dashboard.js +252 -0
- package/scripts/cco-status.js +430 -0
- package/scripts/lib/activation/account-state.js +37 -0
- package/scripts/lib/activation/activation-runner.js +546 -0
- package/scripts/lib/activation/activation-self-healing.js +480 -0
- package/scripts/lib/activation/activation-state.js +83 -0
- package/scripts/lib/activation/activation-summary.js +191 -0
- package/scripts/lib/activation/adapters/claude-code.js +77 -0
- package/scripts/lib/activation/adapters/codex-cli.js +52 -0
- package/scripts/lib/activation/adapters/cursor.js +37 -0
- package/scripts/lib/activation/adapters/github-agent.js +39 -0
- package/scripts/lib/activation/adapters/terminal.js +42 -0
- package/scripts/lib/activation/adapters/vscode.js +39 -0
- package/scripts/lib/activation/adapters/windsurf.js +37 -0
- package/scripts/lib/activation/ai-surface-detector.js +151 -0
- package/scripts/lib/activation/connect-account.js +145 -0
- package/scripts/lib/activation/detect-environment.js +75 -0
- package/scripts/lib/activation/detect-hosts.js +62 -0
- package/scripts/lib/activation/format-activation-output.js +109 -0
- package/scripts/lib/activation/next-action.js +43 -0
- package/scripts/lib/activation/repair-engine.js +219 -0
- package/scripts/lib/activation-distribution-readiness.js +507 -0
- package/scripts/lib/adapter-conformance.js +176 -0
- package/scripts/lib/adapter-readiness.js +417 -0
- package/scripts/lib/adapter-safety-boundaries.js +335 -0
- package/scripts/lib/adapter-technical-readiness-gate.js +205 -0
- package/scripts/lib/agent-access-governance.js +455 -0
- package/scripts/lib/agent-enforcement.js +765 -0
- package/scripts/lib/agent-policy-profile.js +210 -0
- package/scripts/lib/agent-security/action-evaluator.js +507 -0
- package/scripts/lib/agent-security/adapter-registry.js +98 -0
- package/scripts/lib/agent-security/auto-policy.js +139 -0
- package/scripts/lib/agent-security/bounded-scan.js +93 -0
- package/scripts/lib/agent-security/enforcement-adapter.js +174 -0
- package/scripts/lib/agent-security/enforcement-engine.js +1129 -0
- package/scripts/lib/agent-security/file-write-adapter.js +183 -0
- package/scripts/lib/agent-security/file-write-rules.js +178 -0
- package/scripts/lib/agent-security/index.js +3342 -0
- package/scripts/lib/agent-security/instruction-risk.js +181 -0
- package/scripts/lib/agent-security/mcp-action-adapter.js +185 -0
- package/scripts/lib/agent-security/mcp-action-rules.js +184 -0
- package/scripts/lib/agent-security/package-action-adapter.js +175 -0
- package/scripts/lib/agent-security/package-action-rules.js +233 -0
- package/scripts/lib/agent-security/performance.js +148 -0
- package/scripts/lib/agent-security/permission-minimizer.js +403 -0
- package/scripts/lib/agent-security/scan-cache.js +74 -0
- package/scripts/lib/agent-security/source-trust.js +146 -0
- package/scripts/lib/ai-install-prompt.js +288 -0
- package/scripts/lib/ai-workspace-hygiene.js +1499 -0
- package/scripts/lib/alpha-activation.js +520 -0
- package/scripts/lib/alpha-feedback.js +263 -0
- package/scripts/lib/alpha-readiness-gate.js +332 -0
- package/scripts/lib/anti-gaming.js +169 -0
- package/scripts/lib/artifact-health.js +431 -0
- package/scripts/lib/attribution.js +180 -0
- package/scripts/lib/audit.js +289 -0
- package/scripts/lib/avorelo-skill-registry.js +810 -0
- package/scripts/lib/batch-jobs.js +71 -0
- package/scripts/lib/brain-pack.js +578 -0
- package/scripts/lib/brand-boundary.js +424 -0
- package/scripts/lib/brand.js +74 -0
- package/scripts/lib/browser-capability.js +1048 -0
- package/scripts/lib/browser-proof-preflight.js +321 -0
- package/scripts/lib/cache-readiness.js +187 -0
- package/scripts/lib/canonical-reentry.js +162 -0
- package/scripts/lib/capability-packs.js +314 -0
- package/scripts/lib/capability-recommender.js +512 -0
- package/scripts/lib/capability-registry.js +1059 -0
- package/scripts/lib/carry-forward-surfacing.js +194 -0
- package/scripts/lib/ccusage-adapter.js +188 -0
- package/scripts/lib/company-loop.js +1149 -0
- package/scripts/lib/config.js +637 -0
- package/scripts/lib/context-acquisition-plan.js +287 -0
- package/scripts/lib/context-budget-guard.js +170 -0
- package/scripts/lib/context-budget-scanner.js +257 -0
- package/scripts/lib/context-optimizer.js +715 -0
- package/scripts/lib/context-reduction-plan.js +178 -0
- package/scripts/lib/context-safety.js +88 -0
- package/scripts/lib/context-savings-engine.js +158 -0
- package/scripts/lib/cost-evidence.js +254 -0
- package/scripts/lib/cross-host-install-plan.js +308 -0
- package/scripts/lib/cross-host-install-readiness.js +237 -0
- package/scripts/lib/cross-host-value-flow.js +268 -0
- package/scripts/lib/dashboard.js +900 -0
- package/scripts/lib/design-partner-feedback.js +346 -0
- package/scripts/lib/entitlements.js +100 -0
- package/scripts/lib/execution-packet.js +559 -0
- package/scripts/lib/experimentation-events.js +547 -0
- package/scripts/lib/external-capability-compliance.js +107 -0
- package/scripts/lib/external-user-simulation.js +166 -0
- package/scripts/lib/failure-recovery-readiness.js +81 -0
- package/scripts/lib/failure-recovery.js +419 -0
- package/scripts/lib/feedback-intelligence.js +537 -0
- package/scripts/lib/feedback-signals.js +205 -0
- package/scripts/lib/file-integrity.js +68 -0
- package/scripts/lib/fsx.js +127 -0
- package/scripts/lib/full-readiness-gate.js +451 -0
- package/scripts/lib/guidance-builder.js +174 -0
- package/scripts/lib/hook-apply.js +1019 -0
- package/scripts/lib/hook-baseline.js +310 -0
- package/scripts/lib/hook-config-preview.js +275 -0
- package/scripts/lib/hook-contracts.js +290 -0
- package/scripts/lib/hook-safety-boundary-readiness.js +80 -0
- package/scripts/lib/host-capability-matrix.js +351 -0
- package/scripts/lib/host-support-context.js +254 -0
- package/scripts/lib/http-hook-action.js +538 -0
- package/scripts/lib/install-ai-readiness.js +84 -0
- package/scripts/lib/install-intake-risk.js +1037 -0
- package/scripts/lib/install-journey-intelligence.js +329 -0
- package/scripts/lib/intervention-guidance.js +57 -0
- package/scripts/lib/known-limitations.js +115 -0
- package/scripts/lib/l8-path-truth.js +146 -0
- package/scripts/lib/launch-hardening-gate.js +436 -0
- package/scripts/lib/launch-readiness.js +628 -0
- package/scripts/lib/learning-memory.js +686 -0
- package/scripts/lib/lifecycle-hooks.js +802 -0
- package/scripts/lib/local-package-smoke.js +423 -0
- package/scripts/lib/local-pricing.js +299 -0
- package/scripts/lib/mcp-enforcement.js +311 -0
- package/scripts/lib/mcp-least-privilege-policy.js +303 -0
- package/scripts/lib/mcp-tool-inventory.js +388 -0
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +335 -0
- package/scripts/lib/metrics.js +699 -0
- package/scripts/lib/micro-proof.js +133 -0
- package/scripts/lib/next-run-context.js +436 -0
- package/scripts/lib/operating-value.js +1648 -0
- package/scripts/lib/optimization-v3.js +122 -0
- package/scripts/lib/orchestration/adapters/_shared.js +49 -0
- package/scripts/lib/orchestration/adapters/aider.js +18 -0
- package/scripts/lib/orchestration/adapters/claude-code.js +35 -0
- package/scripts/lib/orchestration/adapters/codex.js +35 -0
- package/scripts/lib/orchestration/adapters/gemini-cli.js +18 -0
- package/scripts/lib/orchestration/adapters/git.js +25 -0
- package/scripts/lib/orchestration/adapters/index.js +31 -0
- package/scripts/lib/orchestration/adapters/lm-studio.js +18 -0
- package/scripts/lib/orchestration/adapters/ollama.js +18 -0
- package/scripts/lib/orchestration/adapters/opencode.js +18 -0
- package/scripts/lib/orchestration/adapters/openrouter.js +18 -0
- package/scripts/lib/orchestration/adapters/test-runner.js +25 -0
- package/scripts/lib/orchestration/cli.js +438 -0
- package/scripts/lib/orchestration/execution-manager.js +279 -0
- package/scripts/lib/orchestration/handoff.js +314 -0
- package/scripts/lib/orchestration/index.js +456 -0
- package/scripts/lib/orchestration/inventory.js +47 -0
- package/scripts/lib/orchestration/model-discovery.js +498 -0
- package/scripts/lib/orchestration/model-profiler.js +170 -0
- package/scripts/lib/orchestration/model-profiles.js +252 -0
- package/scripts/lib/orchestration/model-refresh-policy.js +72 -0
- package/scripts/lib/orchestration/proof-writer.js +349 -0
- package/scripts/lib/orchestration/provider-discovery/aider.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +56 -0
- package/scripts/lib/orchestration/provider-discovery/codex.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/common.js +186 -0
- package/scripts/lib/orchestration/provider-discovery/gemini.js +106 -0
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +118 -0
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +12 -0
- package/scripts/lib/orchestration/provider-discovery/ollama.js +100 -0
- package/scripts/lib/orchestration/provider-discovery/opencode.js +47 -0
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +44 -0
- package/scripts/lib/orchestration/risk-classifier.js +130 -0
- package/scripts/lib/orchestration/routing-policy.js +486 -0
- package/scripts/lib/orchestration/settings.js +112 -0
- package/scripts/lib/orchestration/state.js +165 -0
- package/scripts/lib/orchestration/verification-manager.js +138 -0
- package/scripts/lib/output-profiles.js +146 -0
- package/scripts/lib/package-content-audit.js +368 -0
- package/scripts/lib/package-runtime.js +278 -0
- package/scripts/lib/plan-surface.js +53 -0
- package/scripts/lib/plans.js +2318 -0
- package/scripts/lib/policy-provider.js +27 -0
- package/scripts/lib/prelaunch-activation-readiness.js +409 -0
- package/scripts/lib/prelaunch-evidence-store.js +816 -0
- package/scripts/lib/prelaunch-intelligence.js +869 -0
- package/scripts/lib/pricing-experiment.js +118 -0
- package/scripts/lib/pro-moment-events.js +77 -0
- package/scripts/lib/pro-moment-state.js +227 -0
- package/scripts/lib/pro-moments.js +1216 -0
- package/scripts/lib/product-learning-events.js +629 -0
- package/scripts/lib/project-profile.js +555 -0
- package/scripts/lib/prompt-compiler.js +280 -0
- package/scripts/lib/prompt-lint.js +32 -0
- package/scripts/lib/prompt-suggestions.js +52 -0
- package/scripts/lib/proof-canonical.js +398 -0
- package/scripts/lib/proof-drilldown.js +383 -0
- package/scripts/lib/proof-events.js +342 -0
- package/scripts/lib/proof-history.js +243 -0
- package/scripts/lib/proof-metrics.js +296 -0
- package/scripts/lib/proof-outcome-evidence.js +134 -0
- package/scripts/lib/proof-receipt.js +335 -0
- package/scripts/lib/proof-record.js +461 -0
- package/scripts/lib/public-activation-distribution-gate.js +258 -0
- package/scripts/lib/public-cli.js +3891 -0
- package/scripts/lib/public-distribution-truth.js +211 -0
- package/scripts/lib/public-install-claim-checker.js +294 -0
- package/scripts/lib/publish-provenance-readiness.js +283 -0
- package/scripts/lib/readiness-delta.js +218 -0
- package/scripts/lib/readiness-evidence-closure.js +196 -0
- package/scripts/lib/reentry-memory-capture.js +241 -0
- package/scripts/lib/reentry-memory-retrieval.js +302 -0
- package/scripts/lib/reentry-memory-status.js +146 -0
- package/scripts/lib/reentry-memory-store.js +178 -0
- package/scripts/lib/reentry-state.js +66 -0
- package/scripts/lib/release-candidate-bundle.js +166 -0
- package/scripts/lib/remediation.js +81 -0
- package/scripts/lib/repo-map.js +391 -0
- package/scripts/lib/run-improvements-lifecycle.js +330 -0
- package/scripts/lib/run-improvements.js +789 -0
- package/scripts/lib/runtime-decision-policy.js +387 -0
- package/scripts/lib/safe-path-engine.js +705 -0
- package/scripts/lib/safe-run-controller.js +887 -0
- package/scripts/lib/score.js +262 -0
- package/scripts/lib/seamless-enforcement.js +329 -0
- package/scripts/lib/seamless-outcome.js +689 -0
- package/scripts/lib/seamless-reality-gate.js +5043 -0
- package/scripts/lib/security-risk-classifier.js +511 -0
- package/scripts/lib/security-scan.js +384 -0
- package/scripts/lib/session-context-optimizer.js +1211 -0
- package/scripts/lib/session-timing.js +315 -0
- package/scripts/lib/skill-hygiene.js +805 -0
- package/scripts/lib/skill-packs.js +161 -0
- package/scripts/lib/skills-operating-layer.js +580 -0
- package/scripts/lib/smart-work-routing.js +768 -0
- package/scripts/lib/source-catalog.js +700 -0
- package/scripts/lib/status-value-summary.js +32 -0
- package/scripts/lib/support-bundle.js +578 -0
- package/scripts/lib/task-continuation.js +440 -0
- package/scripts/lib/test-helpers.js +15 -0
- package/scripts/lib/tier.js +38 -0
- package/scripts/lib/token-context-quality-gate.js +370 -0
- package/scripts/lib/token-cost-capture.js +187 -0
- package/scripts/lib/token-cost-intelligence.js +358 -0
- package/scripts/lib/token-efficiency-evidence.js +213 -0
- package/scripts/lib/token-evidence.js +699 -0
- package/scripts/lib/tokenish.js +17 -0
- package/scripts/lib/tool-output-sandbox.js +304 -0
- package/scripts/lib/trust-audit.js +136 -0
- package/scripts/lib/unified-events.js +396 -0
- package/scripts/lib/upgrade-interruption-recovery.js +407 -0
- package/scripts/lib/usage-ledger.js +201 -0
- package/scripts/lib/value-ledger.js +130 -0
- package/scripts/lib/value-proof-calibration.js +531 -0
- package/scripts/lib/visual-qa.js +231 -0
- package/scripts/lib/voice-alpha.js +29 -0
- package/scripts/lib/work-aware-orchestration.js +976 -0
- package/scripts/lib/work-control-receipts.js +577 -0
- package/scripts/lib/work-ledger.js +1123 -0
- package/scripts/lib/work-panel-preview.js +352 -0
- package/scripts/lib/workflow-discipline.js +280 -0
- package/scripts/lib/workflow-signals.js +419 -0
- package/scripts/lib/workspace-map.js +281 -0
- package/scripts/lib/workspace-registry.js +1367 -0
- package/scripts/lib/workspace-resolver.js +480 -0
|
@@ -0,0 +1,461 @@
|
|
|
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
|
+
};
|