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,689 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// ── Seamless Customer Outcome Contract ────────────────────────────────────────
|
|
4
|
+
//
|
|
5
|
+
// Internal operating contract that makes Avorelo's foundations work together
|
|
6
|
+
// as a seamless customer outcome layer.
|
|
7
|
+
//
|
|
8
|
+
// Contract: avorelo.seamlessOutcome.v1
|
|
9
|
+
//
|
|
10
|
+
// Non-goals: new dashboard, new orchestrator, pricing decisions, public
|
|
11
|
+
// positioning, exact billing savings, LLM calls, network calls.
|
|
12
|
+
//
|
|
13
|
+
// The seamless outcome contract has three modes:
|
|
14
|
+
// automatic — work silently when safe; interrupt only when required
|
|
15
|
+
// assisted — recommend silently, require approval for impactful decisions
|
|
16
|
+
// manual_debug — expose full detail for debugging and auditing
|
|
17
|
+
|
|
18
|
+
const fs = require("fs");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
const { appendProductLearningEvent } = require("./product-learning-events");
|
|
21
|
+
|
|
22
|
+
const CONTRACT = "avorelo.seamlessOutcome.v1";
|
|
23
|
+
const SCHEMA_VERSION = 1;
|
|
24
|
+
|
|
25
|
+
const SEAMLESS_OUTCOME_DIR_REL = ".claude/cco/orchestration/seamless-outcome";
|
|
26
|
+
const LATEST_OUTCOME_RECEIPT_REL = ".claude/cco/orchestration/seamless-outcome/latest-outcome.json";
|
|
27
|
+
const LATEST_VALUE_SUMMARY_REL = ".claude/cco/orchestration/seamless-outcome/latest-value-summary.json";
|
|
28
|
+
|
|
29
|
+
const MODES = Object.freeze(["automatic", "assisted", "manual_debug"]);
|
|
30
|
+
|
|
31
|
+
// Actions that always require interruption regardless of mode
|
|
32
|
+
const ALWAYS_INTERRUPT_ACTION_TYPES = new Set([
|
|
33
|
+
"deploy_publish",
|
|
34
|
+
"auth_billing_ci_prod_change",
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
// Actions that require interruption in assisted mode
|
|
38
|
+
const ASSISTED_INTERRUPT_ACTION_TYPES = new Set([
|
|
39
|
+
"file_write",
|
|
40
|
+
"command_run",
|
|
41
|
+
"network_request",
|
|
42
|
+
"browser_action",
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
// Risk levels that require interruption in assisted mode
|
|
46
|
+
const ASSISTED_INTERRUPT_RISK_LEVELS = new Set(["high", "critical"]);
|
|
47
|
+
|
|
48
|
+
// Risk levels that can be silently reduced in automatic mode
|
|
49
|
+
const AUTO_REDUCIBLE_RISK_LEVELS = new Set(["low", "medium"]);
|
|
50
|
+
|
|
51
|
+
// ── Mode resolution ───────────────────────────────────────────────────────────
|
|
52
|
+
|
|
53
|
+
function getSeamlessMode(configOrOptions = {}) {
|
|
54
|
+
const raw = String(
|
|
55
|
+
configOrOptions.seamlessMode ||
|
|
56
|
+
configOrOptions.mode ||
|
|
57
|
+
process.env.AVORELO_SEAMLESS_MODE ||
|
|
58
|
+
"automatic"
|
|
59
|
+
).toLowerCase().trim();
|
|
60
|
+
|
|
61
|
+
if (MODES.includes(raw)) return raw;
|
|
62
|
+
return "automatic";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ── Interrupt decision ────────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
function shouldInterruptForDecision(input = {}) {
|
|
68
|
+
const mode = getSeamlessMode(input);
|
|
69
|
+
const actionType = String(input.actionType || "").toLowerCase().trim();
|
|
70
|
+
const riskLevel = String(input.riskLevel || "").toLowerCase().trim();
|
|
71
|
+
const isDestructive = Boolean(input.isDestructive);
|
|
72
|
+
const isIrreversible = Boolean(input.isIrreversible);
|
|
73
|
+
const hasSecretsRisk = Boolean(input.hasSecretsRisk);
|
|
74
|
+
const requiresExplicitApproval = Boolean(input.requiresExplicitApproval);
|
|
75
|
+
|
|
76
|
+
// Always interrupt for these categories regardless of mode
|
|
77
|
+
if (ALWAYS_INTERRUPT_ACTION_TYPES.has(actionType)) {
|
|
78
|
+
return { interrupt: true, reason: "action_type_always_requires_approval", mode };
|
|
79
|
+
}
|
|
80
|
+
if (isDestructive && isIrreversible) {
|
|
81
|
+
return { interrupt: true, reason: "destructive_irreversible_action", mode };
|
|
82
|
+
}
|
|
83
|
+
if (hasSecretsRisk) {
|
|
84
|
+
return { interrupt: true, reason: "secrets_exposure_risk", mode };
|
|
85
|
+
}
|
|
86
|
+
if (requiresExplicitApproval) {
|
|
87
|
+
return { interrupt: true, reason: "explicit_policy_requires_approval", mode };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Assisted mode interrupts for higher-risk actions
|
|
91
|
+
if (mode === "assisted") {
|
|
92
|
+
if (ASSISTED_INTERRUPT_ACTION_TYPES.has(actionType) && ASSISTED_INTERRUPT_RISK_LEVELS.has(riskLevel)) {
|
|
93
|
+
return { interrupt: true, reason: "assisted_mode_high_risk_action", mode };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Manual debug mode always exposes, but doesn't necessarily interrupt
|
|
98
|
+
// (it's about visibility, not blocking)
|
|
99
|
+
|
|
100
|
+
return { interrupt: false, reason: "safe_to_apply_silently", mode };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ── Silent application decision ───────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
function shouldApplySilently(input = {}) {
|
|
106
|
+
const mode = getSeamlessMode(input);
|
|
107
|
+
const interruptDecision = shouldInterruptForDecision(input);
|
|
108
|
+
|
|
109
|
+
if (interruptDecision.interrupt) {
|
|
110
|
+
return { silent: false, reason: interruptDecision.reason, mode };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (mode === "manual_debug") {
|
|
114
|
+
return { silent: false, reason: "manual_debug_exposes_all_decisions", mode };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const riskLevel = String(input.riskLevel || "low").toLowerCase().trim();
|
|
118
|
+
if (!AUTO_REDUCIBLE_RISK_LEVELS.has(riskLevel) && mode === "automatic") {
|
|
119
|
+
return { silent: false, reason: "risk_level_requires_awareness_in_automatic_mode", mode };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return { silent: true, reason: "safe_routine_optimization", mode };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ── Outcome-preserving safety check ──────────────────────────────────────────
|
|
126
|
+
|
|
127
|
+
function buildOutcomePreservationCheck(input = {}) {
|
|
128
|
+
const {
|
|
129
|
+
originalAction,
|
|
130
|
+
reductionApplied,
|
|
131
|
+
riskLevel,
|
|
132
|
+
actionType,
|
|
133
|
+
target,
|
|
134
|
+
taskDescription,
|
|
135
|
+
taskStillExecutable,
|
|
136
|
+
qualityRiskIntroduced,
|
|
137
|
+
fallbackAvailable,
|
|
138
|
+
escalationRecommended,
|
|
139
|
+
safeNextAction,
|
|
140
|
+
interruptRequired,
|
|
141
|
+
reasonCodes,
|
|
142
|
+
continuationType,
|
|
143
|
+
suggestedScope,
|
|
144
|
+
suggestedCommand,
|
|
145
|
+
verificationNextStep,
|
|
146
|
+
} = input;
|
|
147
|
+
|
|
148
|
+
const mode = getSeamlessMode(input);
|
|
149
|
+
const interruptDecision = shouldInterruptForDecision({
|
|
150
|
+
...input,
|
|
151
|
+
actionType: actionType || "unknown",
|
|
152
|
+
riskLevel: riskLevel || "low",
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// If reduction may prevent completion, escalate unless fallback exists
|
|
156
|
+
const needsEscalation =
|
|
157
|
+
escalationRecommended === true ||
|
|
158
|
+
(taskStillExecutable === false && fallbackAvailable !== true);
|
|
159
|
+
|
|
160
|
+
const effectiveInterruptRequired =
|
|
161
|
+
interruptRequired === true ||
|
|
162
|
+
interruptDecision.interrupt ||
|
|
163
|
+
(needsEscalation && !fallbackAvailable);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
contract: CONTRACT,
|
|
167
|
+
schemaVersion: SCHEMA_VERSION,
|
|
168
|
+
originalAction: originalAction || null,
|
|
169
|
+
reductionApplied: reductionApplied !== undefined ? Boolean(reductionApplied) : null,
|
|
170
|
+
riskReduced: riskLevel
|
|
171
|
+
? ["medium", "high", "critical"].includes(String(riskLevel).toLowerCase()) && Boolean(reductionApplied)
|
|
172
|
+
: null,
|
|
173
|
+
taskStillExecutable: taskStillExecutable !== undefined ? taskStillExecutable : "unknown",
|
|
174
|
+
qualityRiskIntroduced: qualityRiskIntroduced !== undefined ? qualityRiskIntroduced : "unknown",
|
|
175
|
+
fallbackAvailable: fallbackAvailable !== undefined ? Boolean(fallbackAvailable) : false,
|
|
176
|
+
escalationRecommended: needsEscalation,
|
|
177
|
+
safeNextAction: safeNextAction || null,
|
|
178
|
+
interruptRequired: effectiveInterruptRequired,
|
|
179
|
+
reasonCodes: Array.isArray(reasonCodes) ? reasonCodes : [],
|
|
180
|
+
mode,
|
|
181
|
+
target: target || null,
|
|
182
|
+
taskDescription: taskDescription ? String(taskDescription).slice(0, 200) : null,
|
|
183
|
+
continuationType: continuationType || null,
|
|
184
|
+
suggestedScope: suggestedScope || null,
|
|
185
|
+
suggestedCommand: suggestedCommand || null,
|
|
186
|
+
verificationNextStep: verificationNextStep || null,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ── End-of-run value summary ──────────────────────────────────────────────────
|
|
191
|
+
|
|
192
|
+
function buildEndOfRunValueSummary(input = {}) {
|
|
193
|
+
const {
|
|
194
|
+
mode,
|
|
195
|
+
completedItems,
|
|
196
|
+
preparedItems,
|
|
197
|
+
nextAction,
|
|
198
|
+
completionStatus,
|
|
199
|
+
estimatedPremiumCallsAvoided,
|
|
200
|
+
localStagesUsed,
|
|
201
|
+
estimatedContextTokensAvoided,
|
|
202
|
+
broadScansAvoided,
|
|
203
|
+
manualDecisionsAvoided,
|
|
204
|
+
repeatedWorkAvoided,
|
|
205
|
+
safePathReductionsApplied,
|
|
206
|
+
unsafeActionsBlocked,
|
|
207
|
+
unknownToolsIsolated,
|
|
208
|
+
secretsExposurePrevented,
|
|
209
|
+
approvalsRequiredOnlyWhenNecessary,
|
|
210
|
+
testsRun,
|
|
211
|
+
proofArtifacts,
|
|
212
|
+
receiptsWritten,
|
|
213
|
+
validationStatus,
|
|
214
|
+
qualityPreserved,
|
|
215
|
+
qualityRiskIntroduced,
|
|
216
|
+
escalationRecommended,
|
|
217
|
+
strongWorkerReservedForCriticalStage,
|
|
218
|
+
latestProofPath,
|
|
219
|
+
latestReceiptPaths,
|
|
220
|
+
eventCounts,
|
|
221
|
+
} = input;
|
|
222
|
+
|
|
223
|
+
const resolvedMode = getSeamlessMode({ mode });
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
contract: CONTRACT,
|
|
227
|
+
schemaVersion: SCHEMA_VERSION,
|
|
228
|
+
mode: resolvedMode,
|
|
229
|
+
completed: {
|
|
230
|
+
status: completionStatus || "unknown",
|
|
231
|
+
completedItems: Number(completedItems || 0),
|
|
232
|
+
preparedItems: Number(preparedItems || 0),
|
|
233
|
+
nextAction: nextAction || null,
|
|
234
|
+
},
|
|
235
|
+
saved: {
|
|
236
|
+
estimatedPremiumCallsAvoided: Number(estimatedPremiumCallsAvoided || 0),
|
|
237
|
+
localStagesUsed: Number(localStagesUsed || 0),
|
|
238
|
+
estimatedContextTokensAvoided: Number(estimatedContextTokensAvoided || 0),
|
|
239
|
+
broadScansAvoided: Number(broadScansAvoided || 0),
|
|
240
|
+
manualDecisionsAvoided: Number(manualDecisionsAvoided || 0),
|
|
241
|
+
repeatedWorkAvoided: Number(repeatedWorkAvoided || 0),
|
|
242
|
+
},
|
|
243
|
+
protected: {
|
|
244
|
+
safePathReductionsApplied: Number(safePathReductionsApplied || 0),
|
|
245
|
+
unsafeActionsBlocked: Number(unsafeActionsBlocked || 0),
|
|
246
|
+
unknownToolsIsolated: Number(unknownToolsIsolated || 0),
|
|
247
|
+
secretsExposurePrevented: Number(secretsExposurePrevented || 0),
|
|
248
|
+
approvalsRequiredOnlyWhenNecessary: approvalsRequiredOnlyWhenNecessary !== false,
|
|
249
|
+
},
|
|
250
|
+
verified: {
|
|
251
|
+
testsRun: Number(testsRun || 0),
|
|
252
|
+
proofArtifacts: Number(proofArtifacts || 0),
|
|
253
|
+
receiptsWritten: Number(receiptsWritten || 0),
|
|
254
|
+
validationStatus: validationStatus || "unknown",
|
|
255
|
+
},
|
|
256
|
+
quality: {
|
|
257
|
+
qualityPreserved: qualityPreserved !== false,
|
|
258
|
+
qualityRiskIntroduced: Boolean(qualityRiskIntroduced),
|
|
259
|
+
escalationRecommended: Boolean(escalationRecommended),
|
|
260
|
+
strongWorkerReservedForCriticalStage: Boolean(strongWorkerReservedForCriticalStage),
|
|
261
|
+
},
|
|
262
|
+
evidence: {
|
|
263
|
+
latestProofPath: latestProofPath || null,
|
|
264
|
+
latestReceiptPaths: Array.isArray(latestReceiptPaths) ? latestReceiptPaths.slice(0, 5) : [],
|
|
265
|
+
eventCounts: eventCounts && typeof eventCounts === "object" ? eventCounts : {},
|
|
266
|
+
},
|
|
267
|
+
caveats: [
|
|
268
|
+
"Token/cost savings are estimated, not billing-exact",
|
|
269
|
+
"Premium call avoidance is based on local worker detection, not account billing",
|
|
270
|
+
],
|
|
271
|
+
redacted: true,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ── Seamless outcome surface (for status/dashboard) ──────────────────────────
|
|
276
|
+
|
|
277
|
+
function buildSeamlessOutcomeSurface(cwd) {
|
|
278
|
+
const abs = path.join(cwd, LATEST_VALUE_SUMMARY_REL);
|
|
279
|
+
let latestSummary = null;
|
|
280
|
+
try {
|
|
281
|
+
if (fs.existsSync(abs)) {
|
|
282
|
+
latestSummary = JSON.parse(fs.readFileSync(abs, "utf8").replace(/^/, ""));
|
|
283
|
+
}
|
|
284
|
+
} catch {
|
|
285
|
+
latestSummary = null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const mode = getSeamlessMode({});
|
|
289
|
+
|
|
290
|
+
if (!latestSummary) {
|
|
291
|
+
return {
|
|
292
|
+
contract: CONTRACT,
|
|
293
|
+
status: "no_summary_yet",
|
|
294
|
+
mode,
|
|
295
|
+
lastSummaryPath: null,
|
|
296
|
+
taskCompletionStatus: "unknown",
|
|
297
|
+
estimatedSavingsAvailable: false,
|
|
298
|
+
riskReductionAvailable: false,
|
|
299
|
+
interruptionsRequired: 0,
|
|
300
|
+
nextAction: "Run `avorelo route` + `avorelo outcome --json` to generate a value summary.",
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
contract: CONTRACT,
|
|
306
|
+
status: "available",
|
|
307
|
+
mode: latestSummary.mode || mode,
|
|
308
|
+
lastSummaryPath: LATEST_VALUE_SUMMARY_REL,
|
|
309
|
+
taskCompletionStatus: latestSummary.completed?.status || "unknown",
|
|
310
|
+
estimatedSavingsAvailable: (
|
|
311
|
+
(latestSummary.saved?.estimatedPremiumCallsAvoided || 0) > 0 ||
|
|
312
|
+
(latestSummary.saved?.estimatedContextTokensAvoided || 0) > 0
|
|
313
|
+
),
|
|
314
|
+
riskReductionAvailable: (
|
|
315
|
+
(latestSummary.protected?.safePathReductionsApplied || 0) > 0 ||
|
|
316
|
+
(latestSummary.protected?.unsafeActionsBlocked || 0) > 0
|
|
317
|
+
),
|
|
318
|
+
interruptionsRequired: 0,
|
|
319
|
+
nextAction: latestSummary.completed?.nextAction || null,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ── File I/O ──────────────────────────────────────────────────────────────────
|
|
324
|
+
|
|
325
|
+
function writeValueSummary(cwd, summary) {
|
|
326
|
+
const dir = path.join(cwd, SEAMLESS_OUTCOME_DIR_REL);
|
|
327
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
328
|
+
fs.writeFileSync(
|
|
329
|
+
path.join(cwd, LATEST_VALUE_SUMMARY_REL),
|
|
330
|
+
JSON.stringify(summary, null, 2),
|
|
331
|
+
"utf8"
|
|
332
|
+
);
|
|
333
|
+
return LATEST_VALUE_SUMMARY_REL;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function readLatestValueSummary(cwd) {
|
|
337
|
+
try {
|
|
338
|
+
const abs = path.join(cwd, LATEST_VALUE_SUMMARY_REL);
|
|
339
|
+
if (!fs.existsSync(abs)) return null;
|
|
340
|
+
return JSON.parse(fs.readFileSync(abs, "utf8").replace(/^/, ""));
|
|
341
|
+
} catch {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ── Event emission helpers ────────────────────────────────────────────────────
|
|
347
|
+
|
|
348
|
+
function emitSeamlessEvent(cwd, eventName, payload = {}) {
|
|
349
|
+
try {
|
|
350
|
+
appendProductLearningEvent(cwd, {
|
|
351
|
+
eventName,
|
|
352
|
+
category: "seamless_outcome",
|
|
353
|
+
surface: "local",
|
|
354
|
+
status: "observed",
|
|
355
|
+
payload: {
|
|
356
|
+
contract: CONTRACT,
|
|
357
|
+
...payload,
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
} catch {
|
|
361
|
+
// product-learning event emission is best-effort
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function buildAndWriteValueSummary(cwd, input = {}) {
|
|
366
|
+
const summary = buildEndOfRunValueSummary(input);
|
|
367
|
+
const path_ = writeValueSummary(cwd, summary);
|
|
368
|
+
|
|
369
|
+
emitSeamlessEvent(cwd, "value_summary_generated", {
|
|
370
|
+
mode: summary.mode,
|
|
371
|
+
completionStatus: summary.completed.status,
|
|
372
|
+
estimatedPremiumCallsAvoided: summary.saved.estimatedPremiumCallsAvoided,
|
|
373
|
+
estimatedContextTokensAvoided: summary.saved.estimatedContextTokensAvoided,
|
|
374
|
+
unsafeActionsBlocked: summary.protected.unsafeActionsBlocked,
|
|
375
|
+
qualityPreserved: summary.quality.qualityPreserved,
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
return { summary, path: path_ };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ── Outcome surface builder for context-optimizer / handoff integration ───────
|
|
382
|
+
|
|
383
|
+
function buildValueSummaryFromReceipts(cwd, opts = {}) {
|
|
384
|
+
let contextReceipt = null;
|
|
385
|
+
let orchReceipt = null;
|
|
386
|
+
let intakeReceipt = null;
|
|
387
|
+
|
|
388
|
+
try {
|
|
389
|
+
const { readLatestContextOptimizationReceipt } = require("./context-optimizer");
|
|
390
|
+
contextReceipt = readLatestContextOptimizationReceipt(cwd);
|
|
391
|
+
} catch {}
|
|
392
|
+
|
|
393
|
+
try {
|
|
394
|
+
const { readLatestOrchestrationReceipt } = require("./orchestration");
|
|
395
|
+
orchReceipt = readLatestOrchestrationReceipt(cwd);
|
|
396
|
+
} catch {}
|
|
397
|
+
|
|
398
|
+
try {
|
|
399
|
+
const { LATEST_INSTALL_INTAKE_RECEIPT_REL_PATH } = require("./install-intake-risk");
|
|
400
|
+
const abs = path.join(cwd, LATEST_INSTALL_INTAKE_RECEIPT_REL_PATH);
|
|
401
|
+
if (fs.existsSync(abs)) {
|
|
402
|
+
intakeReceipt = JSON.parse(fs.readFileSync(abs, "utf8").replace(/^/, ""));
|
|
403
|
+
}
|
|
404
|
+
} catch {}
|
|
405
|
+
|
|
406
|
+
const estimatedContextTokensAvoided =
|
|
407
|
+
contextReceipt?.savings?.estimatedTokensAvoided || 0;
|
|
408
|
+
const localStagesUsed =
|
|
409
|
+
orchReceipt?.localStagesUsed || orchReceipt?.stageList?.filter((s) => s?.quotaSignal === "local").length || 0;
|
|
410
|
+
const estimatedPremiumCallsAvoided =
|
|
411
|
+
orchReceipt?.premiumCallsAvoided || (localStagesUsed > 0 ? localStagesUsed : 0);
|
|
412
|
+
const unknownToolsIsolated =
|
|
413
|
+
intakeReceipt?.summary?.unknownItems || 0;
|
|
414
|
+
const highRiskItems =
|
|
415
|
+
intakeReceipt?.summary?.highRiskItems || 0;
|
|
416
|
+
|
|
417
|
+
// Read orchestration proof for proof path
|
|
418
|
+
let latestProofPath = null;
|
|
419
|
+
try {
|
|
420
|
+
const { LATEST_ORCHESTRATION_RECEIPT_REL_PATH } = require("./orchestration");
|
|
421
|
+
latestProofPath = LATEST_ORCHESTRATION_RECEIPT_REL_PATH;
|
|
422
|
+
} catch {}
|
|
423
|
+
|
|
424
|
+
return buildAndWriteValueSummary(cwd, {
|
|
425
|
+
mode: opts.mode,
|
|
426
|
+
completionStatus: orchReceipt?.status || "unknown",
|
|
427
|
+
completedItems: orchReceipt?.stagesCompleted || 0,
|
|
428
|
+
preparedItems: orchReceipt?.stageList?.length || 0,
|
|
429
|
+
nextAction: orchReceipt?.nextAction || opts.nextAction || null,
|
|
430
|
+
estimatedPremiumCallsAvoided,
|
|
431
|
+
localStagesUsed,
|
|
432
|
+
estimatedContextTokensAvoided,
|
|
433
|
+
broadScansAvoided: contextReceipt?.savings?.broadScansAvoided || 0,
|
|
434
|
+
manualDecisionsAvoided: opts.manualDecisionsAvoided || 0,
|
|
435
|
+
repeatedWorkAvoided: contextReceipt?.savings?.repeatedWorkAvoided || 0,
|
|
436
|
+
safePathReductionsApplied: opts.safePathReductionsApplied || 0,
|
|
437
|
+
unsafeActionsBlocked: opts.unsafeActionsBlocked || 0,
|
|
438
|
+
unknownToolsIsolated,
|
|
439
|
+
secretsExposurePrevented: opts.secretsExposurePrevented || 0,
|
|
440
|
+
approvalsRequiredOnlyWhenNecessary: true,
|
|
441
|
+
testsRun: opts.testsRun || 0,
|
|
442
|
+
proofArtifacts: opts.proofArtifacts || 0,
|
|
443
|
+
receiptsWritten: opts.receiptsWritten || 0,
|
|
444
|
+
validationStatus: opts.validationStatus || "unknown",
|
|
445
|
+
qualityPreserved: opts.qualityPreserved !== false,
|
|
446
|
+
qualityRiskIntroduced: Boolean(opts.qualityRiskIntroduced),
|
|
447
|
+
escalationRecommended: Boolean(opts.escalationRecommended),
|
|
448
|
+
strongWorkerReservedForCriticalStage: Boolean(opts.strongWorkerReservedForCriticalStage),
|
|
449
|
+
latestProofPath,
|
|
450
|
+
latestReceiptPaths: [
|
|
451
|
+
contextReceipt ? ".claude/cco/orchestration/context-optimizer/latest-receipt.json" : null,
|
|
452
|
+
intakeReceipt ? ".claude/cco/security/install-intake/latest-receipt.json" : null,
|
|
453
|
+
latestProofPath,
|
|
454
|
+
].filter(Boolean),
|
|
455
|
+
eventCounts: opts.eventCounts || {},
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ── Value Evidence Collection ─────────────────────────────────────────────────
|
|
460
|
+
//
|
|
461
|
+
// Reads real receipts and returns structured evidence for each value field.
|
|
462
|
+
// Each field carries evidenceBacked + estimateMethod so consumers can check
|
|
463
|
+
// whether a summary entry is supported by observed data or is just a default.
|
|
464
|
+
//
|
|
465
|
+
// Rules:
|
|
466
|
+
// - no network calls, no LLM calls, purely computational
|
|
467
|
+
// - never throws; returns defaults with estimateMethod:"not_available" on error
|
|
468
|
+
// - no optimistic defaults: if a receipt is absent, value stays 0/not_available
|
|
469
|
+
|
|
470
|
+
function collectValueEvidence(cwd) {
|
|
471
|
+
let contextReceipt = null;
|
|
472
|
+
let orchReceipt = null;
|
|
473
|
+
let intakeReceipt = null;
|
|
474
|
+
let safePathReceipt = null;
|
|
475
|
+
let guardReceipt = null;
|
|
476
|
+
let proofReceipt = null;
|
|
477
|
+
|
|
478
|
+
try {
|
|
479
|
+
const { readLatestContextOptimizationReceipt } = require("./context-optimizer");
|
|
480
|
+
contextReceipt = readLatestContextOptimizationReceipt(cwd);
|
|
481
|
+
} catch {}
|
|
482
|
+
|
|
483
|
+
try {
|
|
484
|
+
const { readLatestOrchestrationReceipt } = require("./orchestration");
|
|
485
|
+
orchReceipt = readLatestOrchestrationReceipt(cwd);
|
|
486
|
+
} catch {}
|
|
487
|
+
|
|
488
|
+
try {
|
|
489
|
+
const { LATEST_INSTALL_INTAKE_RECEIPT_REL_PATH } = require("./install-intake-risk");
|
|
490
|
+
const abs = path.join(cwd, LATEST_INSTALL_INTAKE_RECEIPT_REL_PATH);
|
|
491
|
+
if (fs.existsSync(abs)) {
|
|
492
|
+
intakeReceipt = JSON.parse(fs.readFileSync(abs, "utf8").replace(/^/, ""));
|
|
493
|
+
}
|
|
494
|
+
} catch {}
|
|
495
|
+
|
|
496
|
+
try {
|
|
497
|
+
const abs = path.join(cwd, ".claude", "cco", "security", "safe-path", "latest-receipt.json");
|
|
498
|
+
if (fs.existsSync(abs)) {
|
|
499
|
+
safePathReceipt = JSON.parse(fs.readFileSync(abs, "utf8").replace(/^/, ""));
|
|
500
|
+
}
|
|
501
|
+
} catch {}
|
|
502
|
+
|
|
503
|
+
try {
|
|
504
|
+
const abs = path.join(cwd, ".claude", "cco", "evidence", "agent-security", "latest-enforcement.json");
|
|
505
|
+
if (fs.existsSync(abs)) {
|
|
506
|
+
guardReceipt = JSON.parse(fs.readFileSync(abs, "utf8").replace(/^/, ""));
|
|
507
|
+
}
|
|
508
|
+
} catch {}
|
|
509
|
+
|
|
510
|
+
try {
|
|
511
|
+
const abs = path.join(cwd, ".claude", "cco", "orchestration", "current-proof.json");
|
|
512
|
+
if (fs.existsSync(abs)) {
|
|
513
|
+
proofReceipt = JSON.parse(fs.readFileSync(abs, "utf8").replace(/^/, ""));
|
|
514
|
+
}
|
|
515
|
+
} catch {}
|
|
516
|
+
|
|
517
|
+
// ── Build evidence-backed field assessments ──────────────────────────────
|
|
518
|
+
|
|
519
|
+
// Premium calls avoided: only count when orchestration receipt shows local stages
|
|
520
|
+
const localStagesUsed = orchReceipt?.localStagesUsed
|
|
521
|
+
|| (Array.isArray(orchReceipt?.stageList)
|
|
522
|
+
? orchReceipt.stageList.filter((s) => s?.quotaSignal === "local").length
|
|
523
|
+
: 0);
|
|
524
|
+
const premiumCallsAvoided = localStagesUsed > 0 ? localStagesUsed : 0;
|
|
525
|
+
const premiumCallsEvidence = {
|
|
526
|
+
value: premiumCallsAvoided,
|
|
527
|
+
evidenceBacked: orchReceipt != null && localStagesUsed > 0,
|
|
528
|
+
estimateMethod: orchReceipt
|
|
529
|
+
? (localStagesUsed > 0 ? "receipt" : "not_available")
|
|
530
|
+
: "not_available",
|
|
531
|
+
caveat: orchReceipt == null
|
|
532
|
+
? "No orchestration receipt found; cannot count premium calls avoided."
|
|
533
|
+
: localStagesUsed === 0
|
|
534
|
+
? "No local stages used in latest orchestration receipt."
|
|
535
|
+
: null,
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
// Context tokens avoided: only count when context receipt has compaction/exclusions
|
|
539
|
+
const estimatedTokensAvoided = contextReceipt?.savings?.estimatedTokensAvoided || 0;
|
|
540
|
+
const hasCompactionEvidence =
|
|
541
|
+
contextReceipt != null &&
|
|
542
|
+
(contextReceipt.compactionUsed === true ||
|
|
543
|
+
(contextReceipt.excludedCount != null && contextReceipt.excludedCount > 0) ||
|
|
544
|
+
estimatedTokensAvoided > 0);
|
|
545
|
+
const contextTokensEvidence = {
|
|
546
|
+
value: hasCompactionEvidence ? estimatedTokensAvoided : 0,
|
|
547
|
+
evidenceBacked: hasCompactionEvidence,
|
|
548
|
+
estimateMethod: hasCompactionEvidence ? "receipt" : "not_available",
|
|
549
|
+
caveat: !contextReceipt
|
|
550
|
+
? "No context receipt found; cannot estimate tokens avoided."
|
|
551
|
+
: !hasCompactionEvidence
|
|
552
|
+
? "Context receipt present but no compaction or exclusions detected."
|
|
553
|
+
: "Token count is estimated from context receipt, not billing-exact.",
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// Unsafe actions blocked: only count when guard/safe-path shows a block/approval_required
|
|
557
|
+
const guardDecision = guardReceipt?.decision || "unknown";
|
|
558
|
+
const safePathDecision = safePathReceipt?.safePathDecision || "unknown";
|
|
559
|
+
const unsafeActionsBlocked =
|
|
560
|
+
["block", "approval_required"].includes(guardDecision) ||
|
|
561
|
+
["block", "approval_required"].includes(safePathDecision) ? 1 : 0;
|
|
562
|
+
const unsafeActionsEvidence = {
|
|
563
|
+
value: unsafeActionsBlocked,
|
|
564
|
+
evidenceBacked: guardReceipt != null || safePathReceipt != null,
|
|
565
|
+
estimateMethod: (guardReceipt || safePathReceipt) ? "receipt" : "not_available",
|
|
566
|
+
caveat: !guardReceipt && !safePathReceipt
|
|
567
|
+
? "No guard or safe-path receipt found; cannot count unsafe actions blocked."
|
|
568
|
+
: unsafeActionsBlocked === 0
|
|
569
|
+
? "Guard/safe-path receipts present but no blocked/approval decisions."
|
|
570
|
+
: null,
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
// Unknown tools isolated: only count from intake receipt
|
|
574
|
+
const unknownToolsIsolated = intakeReceipt?.summary?.unknownItems || 0;
|
|
575
|
+
const unknownToolsEvidence = {
|
|
576
|
+
value: unknownToolsIsolated,
|
|
577
|
+
evidenceBacked: intakeReceipt != null,
|
|
578
|
+
estimateMethod: intakeReceipt ? "receipt" : "not_available",
|
|
579
|
+
caveat: !intakeReceipt
|
|
580
|
+
? "No install intake receipt found; cannot count unknown tools isolated."
|
|
581
|
+
: unknownToolsIsolated === 0
|
|
582
|
+
? "Intake receipt present but no unknown items found."
|
|
583
|
+
: null,
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// Verification: only count when proof receipt exists and has completed/verified status
|
|
587
|
+
const proofStatus = proofReceipt?.status || "unknown";
|
|
588
|
+
const hasVerificationEvidence =
|
|
589
|
+
proofReceipt != null && ["completed", "verified", "pass"].includes(proofStatus);
|
|
590
|
+
const verificationEvidence = {
|
|
591
|
+
evidenceBacked: hasVerificationEvidence,
|
|
592
|
+
estimateMethod: proofReceipt ? "receipt" : "not_available",
|
|
593
|
+
status: proofStatus,
|
|
594
|
+
caveat: !proofReceipt
|
|
595
|
+
? "No proof receipt found; cannot confirm verification."
|
|
596
|
+
: !hasVerificationEvidence
|
|
597
|
+
? `Proof receipt present but status is '${proofStatus}', not completed/verified.`
|
|
598
|
+
: null,
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
return {
|
|
602
|
+
premiumCallsAvoided: premiumCallsEvidence,
|
|
603
|
+
contextTokensAvoided: contextTokensEvidence,
|
|
604
|
+
unsafeActionsBlocked: unsafeActionsEvidence,
|
|
605
|
+
unknownToolsIsolated: unknownToolsEvidence,
|
|
606
|
+
verification: verificationEvidence,
|
|
607
|
+
sourceReceipts: {
|
|
608
|
+
orchReceipt: orchReceipt != null,
|
|
609
|
+
contextReceipt: contextReceipt != null,
|
|
610
|
+
intakeReceipt: intakeReceipt != null,
|
|
611
|
+
safePathReceipt: safePathReceipt != null,
|
|
612
|
+
guardReceipt: guardReceipt != null,
|
|
613
|
+
proofReceipt: proofReceipt != null,
|
|
614
|
+
},
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// ── Evidence-backed value summary builder ─────────────────────────────────────
|
|
619
|
+
//
|
|
620
|
+
// Builds a value summary that includes evidence-backing metadata.
|
|
621
|
+
// Fields without receipts show 0 / not_available with a caveat instead of
|
|
622
|
+
// optimistic defaults.
|
|
623
|
+
|
|
624
|
+
function buildEvidenceBackedValueSummary(cwd, opts = {}) {
|
|
625
|
+
const evidence = collectValueEvidence(cwd);
|
|
626
|
+
|
|
627
|
+
const caveats = [
|
|
628
|
+
"Token/cost savings are estimated, not billing-exact",
|
|
629
|
+
"Premium call avoidance is based on local worker detection, not account billing",
|
|
630
|
+
];
|
|
631
|
+
|
|
632
|
+
if (evidence.premiumCallsAvoided.caveat) caveats.push(evidence.premiumCallsAvoided.caveat);
|
|
633
|
+
if (evidence.contextTokensAvoided.caveat) caveats.push(evidence.contextTokensAvoided.caveat);
|
|
634
|
+
if (evidence.unsafeActionsBlocked.caveat) caveats.push(evidence.unsafeActionsBlocked.caveat);
|
|
635
|
+
if (evidence.unknownToolsIsolated.caveat) caveats.push(evidence.unknownToolsIsolated.caveat);
|
|
636
|
+
|
|
637
|
+
return {
|
|
638
|
+
contract: CONTRACT,
|
|
639
|
+
schemaVersion: SCHEMA_VERSION,
|
|
640
|
+
evidenceBacked: true,
|
|
641
|
+
mode: getSeamlessMode({ mode: opts.mode }),
|
|
642
|
+
saved: {
|
|
643
|
+
estimatedPremiumCallsAvoided: evidence.premiumCallsAvoided.value,
|
|
644
|
+
estimatedPremiumCallsAvoided_evidence: evidence.premiumCallsAvoided.evidenceBacked,
|
|
645
|
+
estimatedPremiumCallsAvoided_method: evidence.premiumCallsAvoided.estimateMethod,
|
|
646
|
+
estimatedContextTokensAvoided: evidence.contextTokensAvoided.value,
|
|
647
|
+
estimatedContextTokensAvoided_evidence: evidence.contextTokensAvoided.evidenceBacked,
|
|
648
|
+
estimatedContextTokensAvoided_method: evidence.contextTokensAvoided.estimateMethod,
|
|
649
|
+
},
|
|
650
|
+
protected: {
|
|
651
|
+
unsafeActionsBlocked: evidence.unsafeActionsBlocked.value,
|
|
652
|
+
unsafeActionsBlocked_evidence: evidence.unsafeActionsBlocked.evidenceBacked,
|
|
653
|
+
unsafeActionsBlocked_method: evidence.unsafeActionsBlocked.estimateMethod,
|
|
654
|
+
unknownToolsIsolated: evidence.unknownToolsIsolated.value,
|
|
655
|
+
unknownToolsIsolated_evidence: evidence.unknownToolsIsolated.evidenceBacked,
|
|
656
|
+
unknownToolsIsolated_method: evidence.unknownToolsIsolated.estimateMethod,
|
|
657
|
+
},
|
|
658
|
+
verified: {
|
|
659
|
+
verificationStatus: evidence.verification.status,
|
|
660
|
+
verificationEvidenceBacked: evidence.verification.evidenceBacked,
|
|
661
|
+
verificationMethod: evidence.verification.estimateMethod,
|
|
662
|
+
},
|
|
663
|
+
sourceReceipts: evidence.sourceReceipts,
|
|
664
|
+
caveats: [...new Set(caveats.filter(Boolean))],
|
|
665
|
+
redacted: true,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
module.exports = {
|
|
670
|
+
CONTRACT,
|
|
671
|
+
SCHEMA_VERSION,
|
|
672
|
+
MODES,
|
|
673
|
+
SEAMLESS_OUTCOME_DIR_REL,
|
|
674
|
+
LATEST_OUTCOME_RECEIPT_REL,
|
|
675
|
+
LATEST_VALUE_SUMMARY_REL,
|
|
676
|
+
getSeamlessMode,
|
|
677
|
+
shouldInterruptForDecision,
|
|
678
|
+
shouldApplySilently,
|
|
679
|
+
buildOutcomePreservationCheck,
|
|
680
|
+
buildEndOfRunValueSummary,
|
|
681
|
+
buildSeamlessOutcomeSurface,
|
|
682
|
+
writeValueSummary,
|
|
683
|
+
readLatestValueSummary,
|
|
684
|
+
buildAndWriteValueSummary,
|
|
685
|
+
buildValueSummaryFromReceipts,
|
|
686
|
+
collectValueEvidence,
|
|
687
|
+
buildEvidenceBackedValueSummary,
|
|
688
|
+
emitSeamlessEvent,
|
|
689
|
+
};
|