avorelo 0.1.0 → 0.2.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.
Files changed (260) hide show
  1. package/LICENSE +23 -16
  2. package/README.md +91 -51
  3. package/bin/avorelo.mjs +7 -0
  4. package/dist/avorelo.mjs +14337 -0
  5. package/package.json +106 -120
  6. package/bin/avorelo +0 -9
  7. package/scripts/README.md +0 -40
  8. package/scripts/cco-dashboard.js +0 -252
  9. package/scripts/cco-status.js +0 -430
  10. package/scripts/lib/activation/account-state.js +0 -37
  11. package/scripts/lib/activation/activation-runner.js +0 -546
  12. package/scripts/lib/activation/activation-self-healing.js +0 -480
  13. package/scripts/lib/activation/activation-state.js +0 -83
  14. package/scripts/lib/activation/activation-summary.js +0 -191
  15. package/scripts/lib/activation/adapters/claude-code.js +0 -77
  16. package/scripts/lib/activation/adapters/codex-cli.js +0 -52
  17. package/scripts/lib/activation/adapters/cursor.js +0 -37
  18. package/scripts/lib/activation/adapters/github-agent.js +0 -39
  19. package/scripts/lib/activation/adapters/terminal.js +0 -42
  20. package/scripts/lib/activation/adapters/vscode.js +0 -39
  21. package/scripts/lib/activation/adapters/windsurf.js +0 -37
  22. package/scripts/lib/activation/ai-surface-detector.js +0 -151
  23. package/scripts/lib/activation/connect-account.js +0 -145
  24. package/scripts/lib/activation/detect-environment.js +0 -75
  25. package/scripts/lib/activation/detect-hosts.js +0 -62
  26. package/scripts/lib/activation/format-activation-output.js +0 -109
  27. package/scripts/lib/activation/next-action.js +0 -43
  28. package/scripts/lib/activation/repair-engine.js +0 -219
  29. package/scripts/lib/activation-distribution-readiness.js +0 -507
  30. package/scripts/lib/adapter-conformance.js +0 -176
  31. package/scripts/lib/adapter-readiness.js +0 -417
  32. package/scripts/lib/adapter-safety-boundaries.js +0 -335
  33. package/scripts/lib/adapter-technical-readiness-gate.js +0 -205
  34. package/scripts/lib/agent-access-governance.js +0 -455
  35. package/scripts/lib/agent-enforcement.js +0 -765
  36. package/scripts/lib/agent-policy-profile.js +0 -210
  37. package/scripts/lib/agent-security/action-evaluator.js +0 -507
  38. package/scripts/lib/agent-security/adapter-registry.js +0 -98
  39. package/scripts/lib/agent-security/auto-policy.js +0 -139
  40. package/scripts/lib/agent-security/bounded-scan.js +0 -93
  41. package/scripts/lib/agent-security/enforcement-adapter.js +0 -174
  42. package/scripts/lib/agent-security/enforcement-engine.js +0 -1129
  43. package/scripts/lib/agent-security/file-write-adapter.js +0 -183
  44. package/scripts/lib/agent-security/file-write-rules.js +0 -178
  45. package/scripts/lib/agent-security/index.js +0 -3342
  46. package/scripts/lib/agent-security/instruction-risk.js +0 -181
  47. package/scripts/lib/agent-security/mcp-action-adapter.js +0 -185
  48. package/scripts/lib/agent-security/mcp-action-rules.js +0 -184
  49. package/scripts/lib/agent-security/package-action-adapter.js +0 -175
  50. package/scripts/lib/agent-security/package-action-rules.js +0 -233
  51. package/scripts/lib/agent-security/performance.js +0 -148
  52. package/scripts/lib/agent-security/permission-minimizer.js +0 -403
  53. package/scripts/lib/agent-security/scan-cache.js +0 -74
  54. package/scripts/lib/agent-security/source-trust.js +0 -146
  55. package/scripts/lib/ai-install-prompt.js +0 -288
  56. package/scripts/lib/ai-workspace-hygiene.js +0 -1499
  57. package/scripts/lib/alpha-activation.js +0 -520
  58. package/scripts/lib/alpha-feedback.js +0 -263
  59. package/scripts/lib/alpha-readiness-gate.js +0 -332
  60. package/scripts/lib/anti-gaming.js +0 -169
  61. package/scripts/lib/artifact-health.js +0 -431
  62. package/scripts/lib/attribution.js +0 -180
  63. package/scripts/lib/audit.js +0 -289
  64. package/scripts/lib/avorelo-skill-registry.js +0 -810
  65. package/scripts/lib/batch-jobs.js +0 -71
  66. package/scripts/lib/brain-pack.js +0 -578
  67. package/scripts/lib/brand-boundary.js +0 -424
  68. package/scripts/lib/brand.js +0 -74
  69. package/scripts/lib/browser-capability.js +0 -1048
  70. package/scripts/lib/browser-proof-preflight.js +0 -321
  71. package/scripts/lib/cache-readiness.js +0 -187
  72. package/scripts/lib/canonical-reentry.js +0 -162
  73. package/scripts/lib/capability-packs.js +0 -314
  74. package/scripts/lib/capability-recommender.js +0 -512
  75. package/scripts/lib/capability-registry.js +0 -1059
  76. package/scripts/lib/carry-forward-surfacing.js +0 -194
  77. package/scripts/lib/ccusage-adapter.js +0 -188
  78. package/scripts/lib/company-loop.js +0 -1149
  79. package/scripts/lib/config.js +0 -637
  80. package/scripts/lib/context-acquisition-plan.js +0 -287
  81. package/scripts/lib/context-budget-guard.js +0 -170
  82. package/scripts/lib/context-budget-scanner.js +0 -257
  83. package/scripts/lib/context-optimizer.js +0 -715
  84. package/scripts/lib/context-reduction-plan.js +0 -178
  85. package/scripts/lib/context-safety.js +0 -88
  86. package/scripts/lib/context-savings-engine.js +0 -158
  87. package/scripts/lib/cost-evidence.js +0 -254
  88. package/scripts/lib/cross-host-install-plan.js +0 -308
  89. package/scripts/lib/cross-host-install-readiness.js +0 -237
  90. package/scripts/lib/cross-host-value-flow.js +0 -268
  91. package/scripts/lib/dashboard.js +0 -900
  92. package/scripts/lib/design-partner-feedback.js +0 -346
  93. package/scripts/lib/entitlements.js +0 -100
  94. package/scripts/lib/execution-packet.js +0 -559
  95. package/scripts/lib/experimentation-events.js +0 -547
  96. package/scripts/lib/external-capability-compliance.js +0 -107
  97. package/scripts/lib/external-user-simulation.js +0 -166
  98. package/scripts/lib/failure-recovery-readiness.js +0 -81
  99. package/scripts/lib/failure-recovery.js +0 -419
  100. package/scripts/lib/feedback-intelligence.js +0 -537
  101. package/scripts/lib/feedback-signals.js +0 -205
  102. package/scripts/lib/file-integrity.js +0 -68
  103. package/scripts/lib/fsx.js +0 -127
  104. package/scripts/lib/full-readiness-gate.js +0 -451
  105. package/scripts/lib/guidance-builder.js +0 -174
  106. package/scripts/lib/hook-apply.js +0 -1019
  107. package/scripts/lib/hook-baseline.js +0 -310
  108. package/scripts/lib/hook-config-preview.js +0 -275
  109. package/scripts/lib/hook-contracts.js +0 -290
  110. package/scripts/lib/hook-safety-boundary-readiness.js +0 -80
  111. package/scripts/lib/host-capability-matrix.js +0 -351
  112. package/scripts/lib/host-support-context.js +0 -254
  113. package/scripts/lib/http-hook-action.js +0 -538
  114. package/scripts/lib/install-ai-readiness.js +0 -84
  115. package/scripts/lib/install-intake-risk.js +0 -1037
  116. package/scripts/lib/install-journey-intelligence.js +0 -329
  117. package/scripts/lib/intervention-guidance.js +0 -57
  118. package/scripts/lib/known-limitations.js +0 -115
  119. package/scripts/lib/l8-path-truth.js +0 -146
  120. package/scripts/lib/launch-hardening-gate.js +0 -436
  121. package/scripts/lib/launch-readiness.js +0 -628
  122. package/scripts/lib/learning-memory.js +0 -686
  123. package/scripts/lib/lifecycle-hooks.js +0 -802
  124. package/scripts/lib/local-package-smoke.js +0 -423
  125. package/scripts/lib/local-pricing.js +0 -299
  126. package/scripts/lib/mcp-enforcement.js +0 -311
  127. package/scripts/lib/mcp-least-privilege-policy.js +0 -303
  128. package/scripts/lib/mcp-tool-inventory.js +0 -388
  129. package/scripts/lib/mcp-tool-risk.js +0 -0
  130. package/scripts/lib/memory.js +0 -335
  131. package/scripts/lib/metrics.js +0 -699
  132. package/scripts/lib/micro-proof.js +0 -133
  133. package/scripts/lib/next-run-context.js +0 -436
  134. package/scripts/lib/operating-value.js +0 -1648
  135. package/scripts/lib/optimization-v3.js +0 -122
  136. package/scripts/lib/orchestration/adapters/_shared.js +0 -49
  137. package/scripts/lib/orchestration/adapters/aider.js +0 -18
  138. package/scripts/lib/orchestration/adapters/claude-code.js +0 -35
  139. package/scripts/lib/orchestration/adapters/codex.js +0 -35
  140. package/scripts/lib/orchestration/adapters/gemini-cli.js +0 -18
  141. package/scripts/lib/orchestration/adapters/git.js +0 -25
  142. package/scripts/lib/orchestration/adapters/index.js +0 -31
  143. package/scripts/lib/orchestration/adapters/lm-studio.js +0 -18
  144. package/scripts/lib/orchestration/adapters/ollama.js +0 -18
  145. package/scripts/lib/orchestration/adapters/opencode.js +0 -18
  146. package/scripts/lib/orchestration/adapters/openrouter.js +0 -18
  147. package/scripts/lib/orchestration/adapters/test-runner.js +0 -25
  148. package/scripts/lib/orchestration/cli.js +0 -438
  149. package/scripts/lib/orchestration/execution-manager.js +0 -279
  150. package/scripts/lib/orchestration/handoff.js +0 -314
  151. package/scripts/lib/orchestration/index.js +0 -456
  152. package/scripts/lib/orchestration/inventory.js +0 -47
  153. package/scripts/lib/orchestration/model-discovery.js +0 -498
  154. package/scripts/lib/orchestration/model-profiler.js +0 -170
  155. package/scripts/lib/orchestration/model-profiles.js +0 -252
  156. package/scripts/lib/orchestration/model-refresh-policy.js +0 -72
  157. package/scripts/lib/orchestration/proof-writer.js +0 -349
  158. package/scripts/lib/orchestration/provider-discovery/aider.js +0 -49
  159. package/scripts/lib/orchestration/provider-discovery/claude-code.js +0 -56
  160. package/scripts/lib/orchestration/provider-discovery/codex.js +0 -49
  161. package/scripts/lib/orchestration/provider-discovery/common.js +0 -186
  162. package/scripts/lib/orchestration/provider-discovery/gemini.js +0 -106
  163. package/scripts/lib/orchestration/provider-discovery/lm-studio.js +0 -118
  164. package/scripts/lib/orchestration/provider-discovery/models-dev.js +0 -12
  165. package/scripts/lib/orchestration/provider-discovery/ollama.js +0 -100
  166. package/scripts/lib/orchestration/provider-discovery/opencode.js +0 -47
  167. package/scripts/lib/orchestration/provider-discovery/openrouter.js +0 -44
  168. package/scripts/lib/orchestration/risk-classifier.js +0 -130
  169. package/scripts/lib/orchestration/routing-policy.js +0 -486
  170. package/scripts/lib/orchestration/settings.js +0 -112
  171. package/scripts/lib/orchestration/state.js +0 -165
  172. package/scripts/lib/orchestration/verification-manager.js +0 -138
  173. package/scripts/lib/output-profiles.js +0 -146
  174. package/scripts/lib/package-content-audit.js +0 -368
  175. package/scripts/lib/package-runtime.js +0 -278
  176. package/scripts/lib/plan-surface.js +0 -53
  177. package/scripts/lib/plans.js +0 -2318
  178. package/scripts/lib/policy-provider.js +0 -27
  179. package/scripts/lib/prelaunch-activation-readiness.js +0 -409
  180. package/scripts/lib/prelaunch-evidence-store.js +0 -816
  181. package/scripts/lib/prelaunch-intelligence.js +0 -869
  182. package/scripts/lib/pricing-experiment.js +0 -118
  183. package/scripts/lib/pro-moment-events.js +0 -77
  184. package/scripts/lib/pro-moment-state.js +0 -227
  185. package/scripts/lib/pro-moments.js +0 -1216
  186. package/scripts/lib/product-learning-events.js +0 -629
  187. package/scripts/lib/project-profile.js +0 -555
  188. package/scripts/lib/prompt-compiler.js +0 -280
  189. package/scripts/lib/prompt-lint.js +0 -32
  190. package/scripts/lib/prompt-suggestions.js +0 -52
  191. package/scripts/lib/proof-canonical.js +0 -398
  192. package/scripts/lib/proof-drilldown.js +0 -383
  193. package/scripts/lib/proof-events.js +0 -342
  194. package/scripts/lib/proof-history.js +0 -243
  195. package/scripts/lib/proof-metrics.js +0 -296
  196. package/scripts/lib/proof-outcome-evidence.js +0 -134
  197. package/scripts/lib/proof-receipt.js +0 -335
  198. package/scripts/lib/proof-record.js +0 -461
  199. package/scripts/lib/public-activation-distribution-gate.js +0 -258
  200. package/scripts/lib/public-cli.js +0 -3891
  201. package/scripts/lib/public-distribution-truth.js +0 -211
  202. package/scripts/lib/public-install-claim-checker.js +0 -294
  203. package/scripts/lib/publish-provenance-readiness.js +0 -283
  204. package/scripts/lib/readiness-delta.js +0 -218
  205. package/scripts/lib/readiness-evidence-closure.js +0 -196
  206. package/scripts/lib/reentry-memory-capture.js +0 -241
  207. package/scripts/lib/reentry-memory-retrieval.js +0 -302
  208. package/scripts/lib/reentry-memory-status.js +0 -146
  209. package/scripts/lib/reentry-memory-store.js +0 -178
  210. package/scripts/lib/reentry-state.js +0 -66
  211. package/scripts/lib/release-candidate-bundle.js +0 -166
  212. package/scripts/lib/remediation.js +0 -81
  213. package/scripts/lib/repo-map.js +0 -391
  214. package/scripts/lib/run-improvements-lifecycle.js +0 -330
  215. package/scripts/lib/run-improvements.js +0 -789
  216. package/scripts/lib/runtime-decision-policy.js +0 -387
  217. package/scripts/lib/safe-path-engine.js +0 -705
  218. package/scripts/lib/safe-run-controller.js +0 -887
  219. package/scripts/lib/score.js +0 -262
  220. package/scripts/lib/seamless-enforcement.js +0 -329
  221. package/scripts/lib/seamless-outcome.js +0 -689
  222. package/scripts/lib/seamless-reality-gate.js +0 -5043
  223. package/scripts/lib/security-risk-classifier.js +0 -511
  224. package/scripts/lib/security-scan.js +0 -384
  225. package/scripts/lib/session-context-optimizer.js +0 -1211
  226. package/scripts/lib/session-timing.js +0 -315
  227. package/scripts/lib/skill-hygiene.js +0 -805
  228. package/scripts/lib/skill-packs.js +0 -161
  229. package/scripts/lib/skills-operating-layer.js +0 -580
  230. package/scripts/lib/smart-work-routing.js +0 -768
  231. package/scripts/lib/source-catalog.js +0 -700
  232. package/scripts/lib/status-value-summary.js +0 -32
  233. package/scripts/lib/support-bundle.js +0 -578
  234. package/scripts/lib/task-continuation.js +0 -440
  235. package/scripts/lib/test-helpers.js +0 -15
  236. package/scripts/lib/tier.js +0 -38
  237. package/scripts/lib/token-context-quality-gate.js +0 -370
  238. package/scripts/lib/token-cost-capture.js +0 -187
  239. package/scripts/lib/token-cost-intelligence.js +0 -358
  240. package/scripts/lib/token-efficiency-evidence.js +0 -213
  241. package/scripts/lib/token-evidence.js +0 -699
  242. package/scripts/lib/tokenish.js +0 -17
  243. package/scripts/lib/tool-output-sandbox.js +0 -304
  244. package/scripts/lib/trust-audit.js +0 -136
  245. package/scripts/lib/unified-events.js +0 -396
  246. package/scripts/lib/upgrade-interruption-recovery.js +0 -407
  247. package/scripts/lib/usage-ledger.js +0 -201
  248. package/scripts/lib/value-ledger.js +0 -130
  249. package/scripts/lib/value-proof-calibration.js +0 -531
  250. package/scripts/lib/visual-qa.js +0 -231
  251. package/scripts/lib/voice-alpha.js +0 -29
  252. package/scripts/lib/work-aware-orchestration.js +0 -976
  253. package/scripts/lib/work-control-receipts.js +0 -577
  254. package/scripts/lib/work-ledger.js +0 -1123
  255. package/scripts/lib/work-panel-preview.js +0 -352
  256. package/scripts/lib/workflow-discipline.js +0 -280
  257. package/scripts/lib/workflow-signals.js +0 -419
  258. package/scripts/lib/workspace-map.js +0 -281
  259. package/scripts/lib/workspace-registry.js +0 -1367
  260. package/scripts/lib/workspace-resolver.js +0 -480
@@ -1,900 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const {
6
- ensureProjectConfig,
7
- getEffectiveConfig,
8
- latestSecurityScanMeta,
9
- latestTrustAuditMeta,
10
- latestMemoryProfileMeta,
11
- latestIntelSignalsMeta,
12
- latestOutcomeEventsMeta,
13
- safeReadJson,
14
- } = require("./fsx");
15
- const { summarizeLastSessions, weeklyRollup } = require("./metrics");
16
- const { loadMemoryProfile, buildMemorySummary, buildContextBudgetPlan, inferTaskType } = require("./memory");
17
- const { applyRecommendationDecision } = require("./optimization-v3");
18
- const { buildPromptSuggestions } = require("./prompt-suggestions");
19
- const { CAPABILITY_MAP } = require("./adapter-conformance");
20
- const { loadPricingExperiment, buildPricingMeter } = require("./pricing-experiment");
21
- const { readOutcomeEvents, aggregateOutcomeEvents } = require("./unified-events");
22
- const { readLatestCcusageImport } = require("./ccusage-adapter");
23
- const { computeProofMetrics } = require("./proof-metrics");
24
- const { validateScorecard, validateProofMetrics } = require("./anti-gaming");
25
- const { loadLatestIntervention } = require("./intervention-guidance");
26
- const { buildReentryMemoryStatus } = require("./reentry-memory-status");
27
- const { buildBudgetStatus } = require("./context-budget-guard");
28
- const { buildCostEvidenceSummary, buildImportedVsInternalDelta } = require("./cost-evidence");
29
- const { buildCurrentStateSurface } = require("./canonical-reentry");
30
- const { buildAgentSecuritySurface, buildAgentSecurityModeControl } = require("./agent-security");
31
- const { buildBrowserCapabilitySurface } = require("./browser-capability");
32
- const { buildActivationSummary } = require("./activation/activation-summary");
33
- const { buildAgentAccessGovernanceSurface } = require("./agent-access-governance");
34
- const { buildSafePathSurface } = require("./safe-path-engine");
35
- const { buildSkillsOperatingLayerSurface } = require("./skills-operating-layer");
36
- const { buildInstallIntakeRiskSurface } = require("./install-intake-risk");
37
- const { buildWorkControlSurface } = require("./work-control-receipts");
38
- const { buildSessionContextSurface } = require("./session-context-optimizer");
39
- const { buildWorkflowDisciplineStatus } = require("./workflow-discipline");
40
- const { collectWorkflowSignals } = require("./workflow-signals");
41
- const { buildOrchestrationStatus, buildAgentModelOrchestrationSurface } = require("./orchestration");
42
- const { buildAiWorkspaceHygieneSurface } = require("./ai-workspace-hygiene");
43
-
44
- function safeReadOperatingValueSurface(cwd) {
45
- try {
46
- const { buildOperatingValueSurface } = require("./operating-value");
47
- return buildOperatingValueSurface(cwd);
48
- } catch {
49
- return null;
50
- }
51
- }
52
-
53
- function safeReadBrainPackSurface(cwd) {
54
- try {
55
- const { buildBrainPackSurface } = require("./brain-pack");
56
- return buildBrainPackSurface(cwd);
57
- } catch {
58
- return null;
59
- }
60
- }
61
-
62
- function safeRequireWorkspaceRegistrySurface() {
63
- try {
64
- const { buildWorkspaceRegistrySurface } = require("./workspace-registry");
65
- return buildWorkspaceRegistrySurface;
66
- } catch {
67
- return null;
68
- }
69
- }
70
-
71
- function latestReportPath(cwd) {
72
- const dir = path.join(cwd, ".claude", "cco", "reports");
73
- try {
74
- const files = fs.readdirSync(dir).filter((f) => f.endsWith(".md"));
75
- if (!files.length) return null;
76
- const latest = files.map((f) => ({ f, t: fs.statSync(path.join(dir, f)).mtimeMs })).sort((a, b) => b.t - a.t)[0];
77
- return path.posix.join(".claude/cco/reports", latest.f);
78
- } catch {
79
- return null;
80
- }
81
- }
82
-
83
- function explainReasonCode(code) {
84
- const map = {
85
- PROMPT_NO_DOD: "Prompt missing Definition of Done.",
86
- PROMPT_NO_OUTPUT_FORMAT: "Prompt missing explicit output format.",
87
- PROMPT_NO_CONSTRAINTS: "Prompt missing constraints.",
88
- LOOP_REPEATED_TOOL: "Repeated tool sequence detected.",
89
- CTX_LARGE_OUTPUT: "Large output stored out-of-band to reduce context pressure.",
90
- CTX_SCAN_SKIPPED_UNCHANGED: "Repeated scan skipped for unchanged file content.",
91
- FAIL_RETRY_GUARD: "Failure retry guard triggered to prevent repeated waste.",
92
- EVIDENCE_RUNTIME_RETRY_REVIEW: "Measured runtime evidence triggered a bounded retry review before rerunning.",
93
- EVIDENCE_ESTIMATED_LOW_VALUE_REROUTE: "Estimated low-value retry signals forced a cheaper-safer deterministic reroute.",
94
- SEC_CURL_PIPE_SH: "Remote script piped into shell blocked.",
95
- SEC_REMOTE_FETCH: "Remote fetch pattern detected.",
96
- SEC_REMOTE_INCLUDE: "Remote include/import pattern detected.",
97
- SEC_UNPINNED_GIT_DEP: "Unpinned git dependency detected.",
98
- SEC_SUPPRESSION_AUDIT: "Suppression audit recorded from allowlist rules.",
99
- SEC_REMEDIATION_JOB_CREATED: "Remediation job artifact generated.",
100
- SEC_TRUST_UNKNOWN_HIGH: "High-risk scan on unknown changed trusted-surface files.",
101
- PERM_FATIGUE_CONSOLIDATED: "Repeated safe permission requests auto-consolidated.",
102
- IDLE_DEFERRED_SCAN: "Idle-time deferred scan hint generated.",
103
- STOP_SNAPSHOT: "Stop event snapshot captured.",
104
- TASK_COMPLETED: "Task completion summary generated.",
105
- WORKTREE_EVENT: "Worktree lifecycle trust check recorded.",
106
- BATCH_JOB_CREATED: "Batch job created for asynchronous processing.",
107
- BATCH_JOB_COMPLETED: "Batch job completed.",
108
- SMART_ROUTE_CHEAPER_SAFER: "Smart routing automatically downgraded launch to a cheaper-safer route.",
109
- };
110
- return map[code] || code;
111
- }
112
-
113
- function defaultRecommendations() {
114
- return [
115
- "Enable ENABLE_TOOL_SEARCH to reduce idle MCP schema overhead.",
116
- "Tune MAX_MCP_OUTPUT_TOKENS for noisy tools.",
117
- "Use clear DoD and output format to reduce retries.",
118
- ];
119
- }
120
-
121
- function confidenceFromSignals(signalCount) {
122
- if (signalCount >= 8) return "high";
123
- if (signalCount >= 3) return "medium";
124
- return "low";
125
- }
126
-
127
- function benefitSummary(weekly, nextBestAction, memorySummary, memoryEfficiencyScore) {
128
- const savings = weekly.savingsFirstSummary || {};
129
- const minutesSavedEstimate = Number(savings.estimatedMinutesSaved || 0);
130
- const signalCount = weekly.loopsInterrupted + weekly.riskyIntercepts + weekly.largeOutputsStored;
131
-
132
- return {
133
- minutesSavedEstimate,
134
- riskEventsPrevented: weekly.riskyIntercepts,
135
- contextPressureEvents: Number(savings.outputsTrimmed || weekly.largeOutputsStored || 0),
136
- confidenceLabel: savings.confidenceLabel || confidenceFromSignals(signalCount),
137
- savingsEvidence: {
138
- source: "metrics.savingsFirstSummary",
139
- loopsPrevented: Number(savings.loopsPrevented || 0),
140
- outputsTrimmed: Number(savings.outputsTrimmed || 0),
141
- },
142
- nextBestAction,
143
- recommendationTraces: weekly.recommendationTraces || [],
144
- memoryEfficiencyScore,
145
- memoryProject: memorySummary.projectId,
146
- };
147
- }
148
-
149
- function suppressionSummary(weekly, recommendationDecision) {
150
- return {
151
- suppressionEvents: weekly.suppressionEvents || 0,
152
- trustAlerts: weekly.trustAlerts || 0,
153
- recommendationSuppressions: recommendationDecision?.suppressedRecommendations?.length || 0,
154
- };
155
- }
156
-
157
- function trustSummary(cwd) {
158
- const meta = latestTrustAuditMeta(cwd);
159
- if (!meta) return { latestAuditPath: null, unknownFiles: 0, untrustedFiles: 0 };
160
- try {
161
- const abs = path.join(cwd, meta.relPath);
162
- const audit = JSON.parse(fs.readFileSync(abs, "utf8"));
163
- return {
164
- latestAuditPath: meta.relPath,
165
- unknownFiles: Number(audit?.summary?.unknown || 0),
166
- untrustedFiles: Number(audit?.summary?.untrusted || 0),
167
- };
168
- } catch {
169
- return { latestAuditPath: meta.relPath, unknownFiles: 0, untrustedFiles: 0 };
170
- }
171
- }
172
-
173
- function cloudSyncSummary(cwd) {
174
- const sync = safeReadJson(cwd, ".claude/cco/cloud/last-sync.json", null);
175
- if (!sync) return { enabled: false, lastSyncAt: null, syncedEvents: 0, outbox: ".claude/cco/cloud/outbox/events.jsonl" };
176
- return {
177
- enabled: true,
178
- lastSyncAt: sync.ts || null,
179
- syncedEvents: Number(sync.syncedEvents || 0),
180
- outbox: sync.outbox || ".claude/cco/cloud/outbox/events.jsonl",
181
- };
182
- }
183
-
184
- function latestInterventionSummary(cwd) {
185
- const latest = loadLatestIntervention(cwd);
186
- if (!latest) return null;
187
- return {
188
- kind: latest.kind || "intervention",
189
- eventName: latest.eventName || "unknown",
190
- createdAt: latest.createdAt || null,
191
- whatHappened: latest.whatHappened || "",
192
- nextAction: latest.nextAction || "",
193
- preservedState: latest.preservedState || "",
194
- artifactPath: latest.artifactPath || null,
195
- };
196
- }
197
-
198
- function intelSignalsSummary(cwd) {
199
- const meta = latestIntelSignalsMeta(cwd);
200
- if (!meta) {
201
- return {
202
- latestSignalsPath: null,
203
- runId: null,
204
- totalItems: 0,
205
- promotedCandidates: 0,
206
- blockedHighRisk: 0,
207
- topRecommendations: [],
208
- };
209
- }
210
-
211
- try {
212
- const abs = path.join(cwd, meta.relPath);
213
- const signal = JSON.parse(fs.readFileSync(abs, "utf8"));
214
- const items = Array.isArray(signal.items) ? signal.items : [];
215
- return {
216
- latestSignalsPath: meta.relPath,
217
- runId: signal.runId || null,
218
- totalItems: Number(signal.totalItems || items.length || 0),
219
- promotedCandidates: Number(signal.promotedCandidates || 0),
220
- blockedHighRisk: Number(signal.blockedHighRisk || 0),
221
- topRecommendations: items.slice(0, 5).map((item) => ({
222
- recommendationId: item?.recommendation?.recommendationId || item?.itemId || "unknown",
223
- theme: item?.score?.theme || "optimization",
224
- title: item?.title || "",
225
- priority: Number(item?.score?.priority || 0),
226
- sourcePlatform: item?.sourcePlatform || "unknown",
227
- sourceLane: item?.sourceLane || "unknown",
228
- url: item?.url || "",
229
- })),
230
- };
231
- } catch {
232
- return {
233
- latestSignalsPath: meta.relPath,
234
- runId: null,
235
- totalItems: 0,
236
- promotedCandidates: 0,
237
- blockedHighRisk: 0,
238
- topRecommendations: [],
239
- };
240
- }
241
- }
242
-
243
- function outcomeReadinessSummary(cwd) {
244
- const events = readOutcomeEvents(cwd);
245
- const aggregation = aggregateOutcomeEvents(events, { days: 7 });
246
- const latestMeta = latestOutcomeEventsMeta(cwd);
247
- return {
248
- latestEventsPath: latestMeta?.relPath || null,
249
- eventsCount: events.length,
250
- // Legacy mixed-unit totals remain exposed for compatibility only.
251
- measuredValueTotal: Number(aggregation.weeklyRepoSummary?.measuredValueTotal || 0),
252
- counterfactualValueTotal: Number(aggregation.weeklyRepoSummary?.estimatedCounterfactualTotal || 0),
253
- measuredCostTotal: Number(aggregation.weeklyRepoSummary?.measuredCostTotal || 0),
254
- estimatedCostCounterfactualTotal: Number(aggregation.weeklyRepoSummary?.estimatedCostCounterfactualTotal || 0),
255
- tokenUsageTotal: Number(aggregation.weeklyRepoSummary?.tokenUsageTotal || 0),
256
- legacyMixedUnitTotals: aggregation.weeklyRepoSummary?.legacyMixedUnitTotals || {
257
- measuredValueTotal: Number(aggregation.weeklyRepoSummary?.measuredValueTotal || 0),
258
- estimatedCounterfactualTotal: Number(aggregation.weeklyRepoSummary?.estimatedCounterfactualTotal || 0),
259
- },
260
- costAwareTotals: aggregation.weeklyRepoSummary?.costAwareTotals || {
261
- measuredCostTotal: Number(aggregation.weeklyRepoSummary?.measuredCostTotal || 0),
262
- estimatedCostCounterfactualTotal: Number(aggregation.weeklyRepoSummary?.estimatedCostCounterfactualTotal || 0),
263
- tokenUsageTotal: Number(aggregation.weeklyRepoSummary?.tokenUsageTotal || 0),
264
- },
265
- confidenceLabel: aggregation.savingsSummary?.confidenceLabel || "low",
266
- byCategory: aggregation.weeklyRepoSummary?.byCategory || {},
267
- aggregation,
268
- };
269
- }
270
-
271
- function measuredUsageSummary(cwd) {
272
- const latest = readLatestCcusageImport(cwd);
273
- if (!latest) {
274
- return {
275
- available: false,
276
- importedAt: null,
277
- flavor: null,
278
- totalCost: 0,
279
- totalTokens: 0,
280
- rows: 0,
281
- artifact: null,
282
- };
283
- }
284
- return {
285
- available: true,
286
- importedAt: latest.importedAt || null,
287
- flavor: latest.flavor || "claude",
288
- totalCost: Number(latest.summary?.totalCost || 0),
289
- totalTokens: Number(latest.summary?.totalTokens || 0),
290
- rows: Number(latest.summary?.rows || 0),
291
- artifact: latest.artifact || null,
292
- };
293
- }
294
-
295
- function buildPlatformBreakdown() {
296
- return Object.keys(CAPABILITY_MAP).map((key) => {
297
- const c = CAPABILITY_MAP[key];
298
- return {
299
- platform: c.platform,
300
- supportsHooksCount: Array.isArray(c.supportsHooks) ? c.supportsHooks.length : 0,
301
- supportsPermissionDecision: Boolean(c.supportsPermissionDecision),
302
- supportsToolOutputReplacement: Boolean(c.supportsToolOutputReplacement),
303
- partialSupportNotes: c.partialSupportNotes || [],
304
- };
305
- });
306
- }
307
-
308
- function buildTeamUnifiedView(config, weekly, benefit, cloudSync) {
309
- const orgId = config.cloud?.orgId || "local-org";
310
- return {
311
- version: 1,
312
- orgId,
313
- projects: [config.cloud?.projectId || "local-project"],
314
- platformBreakdown: buildPlatformBreakdown(),
315
- benefitSummary: {
316
- minutesSavedEstimate: benefit.minutesSavedEstimate,
317
- riskEventsPrevented: benefit.riskEventsPrevented,
318
- contextPressureEvents: benefit.contextPressureEvents,
319
- },
320
- riskSummary: {
321
- trustAlerts: weekly.trustAlerts || 0,
322
- riskyIntercepts: weekly.riskyIntercepts || 0,
323
- },
324
- costSummary: {
325
- mcpToolCalls: weekly.mcpToolCalls || 0,
326
- largeOutputsStored: weekly.largeOutputsStored || 0,
327
- compactPressureEvents: weekly.compactPressureEvents || 0,
328
- },
329
- nextBestActions: (weekly.recommendations || []).slice(0, 3),
330
- cloudSync,
331
- };
332
- }
333
-
334
- function recommendationCategory(recommendationId) {
335
- const id = String(recommendationId || "");
336
- if (id.includes("SECURITY") || id.includes("TRUST") || id.includes("PERMISSION")) return "security";
337
- if (id.includes("LOOP") || id.includes("RETRY") || id.includes("PROMPT")) return "loop";
338
- if (id.includes("MCP") || id.includes("CONTEXT") || id.includes("COMPACT") || id.includes("THINKING")) return "context";
339
- return "team";
340
- }
341
-
342
- function buildWhatChangedThisWeek(weekly) {
343
- const changes = [];
344
- const savings = weekly.savingsFirstSummary || {};
345
-
346
- if (Number(savings.loopsPrevented || 0) > 0) {
347
- changes.push(`${savings.loopsPrevented} loop reruns were prevented, saving review and retry time.`);
348
- }
349
-
350
- if (Number(savings.outputsTrimmed || 0) > 0) {
351
- changes.push(`${savings.outputsTrimmed} large outputs were trimmed to reduce context pressure.`);
352
- }
353
-
354
- if (Number(weekly.riskyIntercepts || 0) > 0 || Number(weekly.trustAlerts || 0) > 0) {
355
- changes.push(`${Number(weekly.riskyIntercepts || 0)} risky actions were intercepted and ${Number(weekly.trustAlerts || 0)} trust alerts were surfaced.`);
356
- }
357
-
358
- if (!changes.length) {
359
- changes.push("No major waste or risk spikes were detected this week. Keep current defaults and continue monitoring.");
360
- }
361
-
362
- return changes.slice(0, 4);
363
- }
364
-
365
- function buildOrderedActions(weekly, topRecommendedFixes, nextBestAction, teamDefaultsApplied) {
366
- const actions = {
367
- security: [],
368
- loop: [],
369
- context: [],
370
- team: [],
371
- };
372
-
373
- if (Number(weekly.riskyIntercepts || 0) > 0 || Number(weekly.trustAlerts || 0) > 0) {
374
- actions.security.push({
375
- id: "ACT_SECURITY_AUDIT",
376
- category: "security",
377
- text: "Run avorelo audit and resolve the top active security finding first.",
378
- source: "weekly-signals",
379
- });
380
- }
381
-
382
- if (Number(weekly.loopsInterrupted || 0) > 0) {
383
- actions.loop.push({
384
- id: "ACT_LOOP_REPLAN",
385
- category: "loop",
386
- text: "Review repeated loops and tighten Definition of Done before reruns.",
387
- source: "weekly-signals",
388
- });
389
- }
390
-
391
- if (Number(weekly.largeOutputsStored || 0) > 0) {
392
- actions.context.push({
393
- id: "ACT_CONTEXT_HYGIENE",
394
- category: "context",
395
- text: "Tune output caps and keep large outputs out-of-band to reduce context pressure.",
396
- source: "weekly-signals",
397
- });
398
- }
399
-
400
- if (
401
- teamDefaultsApplied?.profile ||
402
- teamDefaultsApplied?.recommendationMode ||
403
- teamDefaultsApplied?.securityModeFloor ||
404
- teamDefaultsApplied?.scanFreshnessHoursFloor
405
- ) {
406
- actions.team.push({
407
- id: "ACT_TEAM_DEFAULTS_REVIEW",
408
- category: "team",
409
- text: "Confirm team defaults remain aligned with current repo risk and cost profile.",
410
- source: "team-defaults",
411
- });
412
- }
413
-
414
- (topRecommendedFixes || []).forEach((fix) => {
415
- const category = recommendationCategory(fix.recommendationId);
416
- actions[category].push({
417
- id: String(fix.recommendationId || "ACT_RECOMMENDATION"),
418
- category,
419
- text: String(fix.text || "Review recommended fix."),
420
- source: "recommendation-engine",
421
- });
422
- });
423
-
424
- const ordered = [
425
- ...actions.security,
426
- ...actions.loop,
427
- ...actions.context,
428
- ...actions.team,
429
- ];
430
-
431
- const deduped = [];
432
- const seen = new Set();
433
- ordered.forEach((item) => {
434
- const k = `${item.id}::${item.text}`;
435
- if (seen.has(k)) return;
436
- seen.add(k);
437
- deduped.push(item);
438
- });
439
-
440
- if (!deduped.length) {
441
- deduped.push({
442
- id: "ACT_NEXT_BEST",
443
- category: "context",
444
- text: nextBestAction || "Run avorelo status to generate focused next steps.",
445
- source: "fallback",
446
- });
447
- }
448
-
449
- return deduped.slice(0, 6);
450
- }
451
-
452
- function buildTeamRollup(weekly, topRecommendedFixes, nextBestAction, teamDefaultsApplied) {
453
- const savings = weekly.savingsFirstSummary || {
454
- loopsDetected: 0,
455
- loopsPrevented: 0,
456
- outputsTrimmed: 0,
457
- estimatedMinutesSaved: 0,
458
- confidenceLabel: "low",
459
- };
460
-
461
- return {
462
- teamRollupVersion: 2,
463
- windowDays: Number(weekly.periodDays || 7),
464
- sessions: Number(weekly.sessions || 0),
465
- summaryFraming: "This week in Time + Risk + Cost: what changed, what to fix next, and what to keep stable.",
466
- whatChangedThisWeek: buildWhatChangedThisWeek(weekly),
467
- savingsFirstSummary: savings,
468
- riskSummary: {
469
- riskyIntercepts: Number(weekly.riskyIntercepts || 0),
470
- trustAlerts: Number(weekly.trustAlerts || 0),
471
- suppressionEvents: Number(weekly.suppressionEvents || 0),
472
- },
473
- topRecommendedFixes: (topRecommendedFixes || []).slice(0, 3),
474
- orderedActions: buildOrderedActions(weekly, topRecommendedFixes, nextBestAction, teamDefaultsApplied),
475
- nextBestAction: nextBestAction || "Run avorelo status to generate focused next steps.",
476
- };
477
- }
478
-
479
- function buildUpsellSignals(weekly, config, memorySummary) {
480
- const signals = [];
481
- const tier = config.tier || "free";
482
-
483
- if (tier === "free") {
484
- if ((weekly.riskyIntercepts || 0) >= 5) {
485
- signals.push({
486
- targetTier: "pro",
487
- feature: "advanced_recommendation_policies",
488
- reason: "Frequent security/risk signals suggest value from policy-driven controls.",
489
- evidence: { riskyIntercepts: weekly.riskyIntercepts },
490
- });
491
- }
492
-
493
- if ((weekly.trustAlerts || 0) >= 2 || (weekly.suppressionEvents || 0) >= 3) {
494
- signals.push({
495
- targetTier: "pro",
496
- feature: "pr_only_remediation_workflow",
497
- reason: "Remediation activity volume indicates value from structured approval workflows.",
498
- evidence: { trustAlerts: weekly.trustAlerts || 0, suppressionEvents: weekly.suppressionEvents || 0 },
499
- });
500
- }
501
-
502
- if ((weekly.sessions || 0) >= 12 || Number(memorySummary.memoryScore || 0) < 55) {
503
- signals.push({
504
- targetTier: "teams",
505
- feature: "managed_settings",
506
- reason: "Usage/memory profile suggests value from shared policy packs and managed settings.",
507
- evidence: { sessions: weekly.sessions, memoryScore: memorySummary.memoryScore },
508
- });
509
- }
510
- }
511
-
512
- return signals;
513
- }
514
-
515
- function applySimplifyMode(config, contextBudgetPlan, recommendationDecision) {
516
- const simplify = config.simplifyMode || {};
517
- if (!simplify.enabled) {
518
- return {
519
- simplifyModeStatus: {
520
- enabled: false,
521
- effectiveContextChars: contextBudgetPlan.maxContextChars,
522
- effectiveToolOutputBytes: contextBudgetPlan.maxToolOutputBytes,
523
- recommendationCap: null,
524
- verbosityLevel: "standard",
525
- },
526
- contextBudgetPlan,
527
- recommendationDecision,
528
- };
529
- }
530
-
531
- const nextBudget = {
532
- ...contextBudgetPlan,
533
- maxContextChars: Math.min(contextBudgetPlan.maxContextChars, Number(simplify.maxContextChars || contextBudgetPlan.maxContextChars)),
534
- maxToolOutputBytes: Math.min(contextBudgetPlan.maxToolOutputBytes, Number(simplify.maxToolOutputBytes || contextBudgetPlan.maxToolOutputBytes)),
535
- };
536
-
537
- const cap = Math.max(1, Number(simplify.recommendationCap || 6));
538
- const displayed = (recommendationDecision.displayedRecommendations || []).slice(0, cap);
539
- const suppressedExtra = (recommendationDecision.displayedRecommendations || []).slice(cap).map((r) => ({
540
- recommendationId: r.recommendationId || r.id,
541
- reason: "simplify-cap",
542
- weight: Number(r.weight || 0),
543
- }));
544
-
545
- const nextDecision = {
546
- ...recommendationDecision,
547
- displayedRecommendations: displayed,
548
- suppressedRecommendations: [...(recommendationDecision.suppressedRecommendations || []), ...suppressedExtra],
549
- nextBestAction: displayed[0]?.text || recommendationDecision.nextBestAction,
550
- reason: `${recommendationDecision.reason};simplify=true;cap=${cap}`,
551
- };
552
-
553
- return {
554
- simplifyModeStatus: {
555
- enabled: true,
556
- effectiveContextChars: nextBudget.maxContextChars,
557
- effectiveToolOutputBytes: nextBudget.maxToolOutputBytes,
558
- recommendationCap: cap,
559
- verbosityLevel: simplify.verbosityLevel || "compact",
560
- },
561
- contextBudgetPlan: nextBudget,
562
- recommendationDecision: nextDecision,
563
- };
564
- }
565
-
566
- function buildStatusDashboard(cwd, options = {}) {
567
- ensureProjectConfig(cwd);
568
- const { config, teamPolicy, teamDefaultsApplied } = getEffectiveConfig(cwd);
569
- const limit = Number.isFinite(Number(options.limit)) ? Math.max(1, Number(options.limit)) : 7;
570
-
571
- const sessions = summarizeLastSessions(cwd, limit, config.profile).map((s) => ({
572
- sessionId: s.sessionId,
573
- durationEstimateMin: s.durationEstimateMin,
574
- toolCalls: s.toolCalls,
575
- loopsInterrupted: s.loopsInterrupted,
576
- riskyIntercepts: s.riskyIntercepts,
577
- largeOutputsStored: s.largeOutputsStored,
578
- topReasonCodes: s.topReasonCodes,
579
- topReasonExplanations: s.topReasonCodes.map((c) => ({ code: c, text: explainReasonCode(c) })),
580
- recommendationTraces: s.recommendationTraces,
581
- recommendations: s.recommendations.slice(0, 5),
582
- }));
583
-
584
- const rollupWindowDays = Math.max(1, Number(teamPolicy?.rollupWindowDays || 7));
585
- const weeklyRaw = weeklyRollup(cwd, rollupWindowDays, config.profile);
586
- const memoryProfile = loadMemoryProfile(cwd);
587
- const memorySummary = buildMemorySummary(memoryProfile);
588
- const inferredTaskType = inferTaskType(weeklyRaw.recommendationTraces || []);
589
- const contextBudgetPlan = buildContextBudgetPlan(config.profile, inferredTaskType, memoryProfile);
590
-
591
- const weeklyRecommendations =
592
- config.recommendationMode === "static" ? defaultRecommendations() : weeklyRaw.recommendations;
593
-
594
- const recommendationDecisionRaw = applyRecommendationDecision({
595
- traces: weeklyRaw.recommendationTraces || [],
596
- memoryProfile,
597
- signals: weeklyRaw,
598
- profileName: config.profile,
599
- });
600
-
601
- const simplifyOverlay = applySimplifyMode(config, contextBudgetPlan, recommendationDecisionRaw);
602
-
603
- const weekly = {
604
- ...weeklyRaw,
605
- recommendations: weeklyRecommendations,
606
- };
607
-
608
- const topReasonExplanations = weekly.topReasonCodes.map((c) => ({ code: c, text: explainReasonCode(c) }));
609
- const nextBestAction = simplifyOverlay.recommendationDecision.nextBestAction || weekly.recommendations[0] || "Run avorelo status to generate focused next steps.";
610
- const topRecommendedFixes = (simplifyOverlay.recommendationDecision.displayedRecommendations || []).slice(0, 5).map((r) => ({
611
- recommendationId: r.recommendationId || r.id,
612
- text: r.text,
613
- confidence: r.confidence || "low",
614
- evidence: r.signalEvidence || [],
615
- actionPath: r.actionPath || "",
616
- }));
617
- const memoryEfficiencyScore = Number(memorySummary.memoryScore || 0);
618
-
619
- const promptSuggestions = buildPromptSuggestions({
620
- profile: config.profile,
621
- contextBudgetPlan: simplifyOverlay.contextBudgetPlan,
622
- recommendationDecision: simplifyOverlay.recommendationDecision,
623
- });
624
-
625
- const outcomeReadiness = outcomeReadinessSummary(cwd);
626
- const measuredUsage = measuredUsageSummary(cwd);
627
- const cloudSync = cloudSyncSummary(cwd);
628
- const intelSignals = intelSignalsSummary(cwd);
629
- const pricingExperiment = loadPricingExperiment(cwd);
630
- const pricingMeter = buildPricingMeter({
631
- weekly,
632
- config,
633
- cohort: pricingExperiment?.cohort || config.pricingExperiment?.cohort || "unassigned",
634
- });
635
- const costEvidence = buildCostEvidenceSummary({
636
- aggregation: outcomeReadiness.aggregation,
637
- measuredUsage,
638
- });
639
- const currentState = buildCurrentStateSurface(cwd);
640
- const activation = buildActivationSummary(cwd);
641
- const agentSecurity = buildAgentSecuritySurface(cwd, config);
642
- const agentAccessGovernance = buildAgentAccessGovernanceSurface(cwd);
643
- const safePath = buildSafePathSurface(cwd);
644
- const installIntakeRisk = buildInstallIntakeRiskSurface(cwd);
645
- const skillsOperatingLayer = buildSkillsOperatingLayerSurface(cwd);
646
- const workControl = (() => { try { return buildWorkControlSurface(cwd); } catch { return null; } })();
647
- const sessionContext = (() => { try { return buildSessionContextSurface(cwd); } catch { return null; } })();
648
- const aiWorkspaceHygiene = (() => { try { return buildAiWorkspaceHygieneSurface(cwd); } catch { return null; } })();
649
- const brainPack = safeReadBrainPackSurface(cwd);
650
- const workspaceRegistry = (() => {
651
- try {
652
- const fn = safeRequireWorkspaceRegistrySurface();
653
- return fn ? fn(cwd) : null;
654
- } catch { return null; }
655
- })();
656
- const browserCapability = (() => { try { return buildBrowserCapabilitySurface(cwd); } catch { return null; } })();
657
- const settingsControls = {
658
- agentSecurityMode: buildAgentSecurityModeControl(config),
659
- };
660
- const workflowDiscipline = (() => {
661
- try {
662
- const wdCfg = config.workflowDiscipline || {};
663
- if (!wdCfg.enabled || wdCfg.mode === "off") {
664
- return buildWorkflowDisciplineStatus({}, wdCfg);
665
- }
666
- const budgetStatus = (() => { try { const { buildBudgetStatus } = require("./context-budget-guard"); return buildBudgetStatus(cwd, config.contextBudgetGuard); } catch { return null; } })();
667
- const signals = collectWorkflowSignals({
668
- cwd,
669
- budgetStatus,
670
- agentSecuritySurface: agentSecurity,
671
- agentSecurityMode: config?.agentSecurity?.mode,
672
- });
673
- const status = buildWorkflowDisciplineStatus(signals, wdCfg);
674
- status.signals = signals;
675
- return status;
676
- } catch {
677
- return null;
678
- }
679
- })();
680
-
681
- const benefit = benefitSummary(weekly, nextBestAction, memorySummary, memoryEfficiencyScore);
682
- const orchestration = (() => {
683
- try {
684
- return buildOrchestrationStatus(cwd);
685
- } catch {
686
- return null;
687
- }
688
- })();
689
-
690
- const agentModelOrchestration = (() => {
691
- try {
692
- return buildAgentModelOrchestrationSurface(cwd);
693
- } catch {
694
- return null;
695
- }
696
- })();
697
-
698
- const promptContextTokenOptimization = (() => {
699
- try {
700
- const { buildContextOptimizerSurface } = require("./context-optimizer");
701
- return buildContextOptimizerSurface(cwd);
702
- } catch {
703
- return null;
704
- }
705
- })();
706
-
707
- return {
708
- statusDashboardVersion: 4,
709
- cwd,
710
- dashboardFraming: "Time + Risk + Cost",
711
- tier: config.tier,
712
- config,
713
- activation,
714
- currentState,
715
- agentSecurity,
716
- agentAccessGovernance,
717
- safePath,
718
- installIntakeRisk,
719
- skillsOperatingLayer,
720
- workControl,
721
- sessionContext,
722
- brainPack,
723
- workspaceRegistry,
724
- browserCapability,
725
- orchestration,
726
- agentModelOrchestration,
727
- promptContextTokenOptimization,
728
- aiWorkspaceHygiene,
729
- settingsControls,
730
- teamPolicy,
731
- teamDefaultsApplied,
732
- latestReport: latestReportPath(cwd),
733
- latestSecurityScan: latestSecurityScanMeta(cwd)?.relPath || null,
734
- latestTrustAudit: latestTrustAuditMeta(cwd)?.relPath || null,
735
- latestMemoryProfile: latestMemoryProfileMeta(cwd)?.relPath || null,
736
- sessions,
737
- weeklySummary: weekly,
738
- memorySummary,
739
- contextBudgetPlan: simplifyOverlay.contextBudgetPlan,
740
- recommendationDecision: simplifyOverlay.recommendationDecision,
741
- simplifyModeStatus: simplifyOverlay.simplifyModeStatus,
742
- benefitSummary: {
743
- ...benefit,
744
- costEvidence: {
745
- measuredCost: costEvidence.preferredMeasuredCost,
746
- estimatedCostCounterfactual: costEvidence.preferredEstimatedCostCounterfactual,
747
- tokenUsage: costEvidence.preferredTokenUsage,
748
- costSource: costEvidence.source,
749
- basis: costEvidence.basis,
750
- },
751
- intelSignals: intelSignals.totalItems,
752
- newRecommendationsFromIntel: intelSignals.promotedCandidates,
753
- highRiskIntelBlocked: intelSignals.blockedHighRisk,
754
- },
755
- intelSignals,
756
- newRecommendationsFromIntel: intelSignals.promotedCandidates,
757
- highRiskIntelBlocked: intelSignals.blockedHighRisk,
758
- suppressionSummary: suppressionSummary(weekly, simplifyOverlay.recommendationDecision),
759
- trustSummary: trustSummary(cwd),
760
- recommendationTraces: simplifyOverlay.recommendationDecision.displayedRecommendations || [],
761
- topRecommendedFixes,
762
- topReasonExplanations,
763
- upsellSignals: buildUpsellSignals(weekly, config, memorySummary),
764
- nextBestAction,
765
- promptSuggestions,
766
- nextBestPrompt: promptSuggestions.nextBestPrompt,
767
- latestIntervention: latestInterventionSummary(cwd),
768
- cloudSync,
769
- measuredUsageImportFreshness: measuredUsage.importedAt,
770
- importedVsInternalDelta: buildImportedVsInternalDelta({
771
- aggregation: outcomeReadiness.aggregation,
772
- measuredUsage,
773
- }),
774
- pricingExperiment: {
775
- enabled: pricingExperiment?.enabled !== false,
776
- selectedModel: pricingExperiment?.selectedModel || "pending",
777
- cohort: pricingExperiment?.cohort || config.pricingExperiment?.cohort || "unassigned",
778
- },
779
- pricingMeter,
780
- teamRollup: buildTeamRollup(weekly, topRecommendedFixes, nextBestAction, teamDefaultsApplied),
781
- teamUnifiedView: buildTeamUnifiedView(config, weekly, benefit, cloudSync),
782
- controls: {
783
- promptLintBypass: "[cco:raw]",
784
- disableCommand: "/plugin disable avorelo@avorelo-marketplace",
785
- },
786
- reentryMemory: (() => { try { return buildReentryMemoryStatus(cwd, config.memory); } catch { return null; } })(),
787
- contextBudgetGuard: (() => {
788
- try {
789
- const warningStatus = buildBudgetStatus(cwd, config.contextBudgetGuard);
790
- if (!config.contextBudgetGuard?.enabled) return warningStatus;
791
- if (config.contextBudgetGuard?.dashboardVisibility === "off") return null;
792
- if (!config.contextBudgetGuard?.reductionPlan) return warningStatus;
793
- const { generateReductionPlan } = require("./context-reduction-plan");
794
- const plan = generateReductionPlan(cwd, config.contextBudgetGuard);
795
- const dashVis = config.contextBudgetGuard?.dashboardVisibility || "basic";
796
- const base = {
797
- ...warningStatus,
798
- reductionPlan: {
799
- schemaVersion: plan.schemaVersion,
800
- mode: plan.mode,
801
- estimatedTotalTokens: plan.budget.estimatedTotalTokens,
802
- recommendedLimitTokens: plan.budget.recommendedLimitTokens,
803
- overBudget: plan.budget.overBudget,
804
- estimatedReductionTokens: plan.budget.estimatedReductionTokens,
805
- estimatedReductionPercent: plan.budget.estimatedReductionPercent,
806
- nextBestAction: plan.nextBestAction,
807
- topHotspot: (plan.hotspots || [])[0] || null,
808
- },
809
- };
810
- if (dashVis === "advanced") {
811
- base.reductionPlan.hotspots = plan.hotspots;
812
- base.reductionPlan.recommendedContext = plan.recommendedContext;
813
- base.reductionPlan.excludedOrReduced = plan.excludedOrReduced;
814
- base.reductionPlan.approvalRequired = plan.approvalRequired;
815
- base.reductionPlan.proof = plan.proof;
816
- }
817
- return base;
818
- } catch {
819
- return null;
820
- }
821
- })(),
822
- workflowDiscipline,
823
- capabilityLayer: (() => {
824
- try {
825
- const { buildCapabilityLayerSurface } = require("./capability-recommender");
826
- // Re-use signals already computed above when available
827
- const prebuiltSignals = workflowDiscipline?.signals || null;
828
- return buildCapabilityLayerSurface(cwd, config, prebuiltSignals);
829
- } catch {
830
- return null;
831
- }
832
- })(),
833
- operatingValue: safeReadOperatingValueSurface(cwd),
834
- };
835
- }
836
-
837
- /**
838
- * Effectiveness Scorecard (Surface 4).
839
- *
840
- * Provides managers/buyers/admins with a focused scorecard showing
841
- * real operational value across the 4 proof dimensions.
842
- */
843
- function buildEffectivenessScorecard(cwd, options = {}) {
844
- const days = Number(options.days || 7);
845
- const proofMetrics = computeProofMetrics(cwd, { days });
846
-
847
- const scorecard = {
848
- version: 1,
849
- period_days: days,
850
- total_sessions: proofMetrics.total_sessions,
851
- generated_at: new Date().toISOString(),
852
-
853
- outcomes: {
854
- completion_rate: proofMetrics.completion_rate,
855
- evidence_backed_completion_rate: proofMetrics.evidence_backed_completion_rate,
856
- time_to_first_useful_result: proofMetrics.time_to_first_useful_result,
857
- },
858
-
859
- efficiency: {
860
- retries_per_task: proofMetrics.retries_per_task,
861
- dead_end_rate: proofMetrics.dead_end_rate,
862
- large_outputs_managed: proofMetrics.large_outputs_managed,
863
- unnecessary_tool_load_avoided: proofMetrics.unnecessary_tool_load_avoided,
864
- },
865
-
866
- trust: {
867
- evidence_coverage: proofMetrics.evidence_coverage,
868
- honest_fallback_rate: proofMetrics.honest_fallback_rate,
869
- recovery_success_rate: proofMetrics.recovery_success_rate,
870
- },
871
-
872
- control: {
873
- risky_actions_blocked_or_downgraded: proofMetrics.risky_actions_blocked_or_downgraded,
874
- approval_interruptions_avoided: proofMetrics.approval_interruptions_avoided,
875
- },
876
- };
877
-
878
- // Anti-gaming validation
879
- const metricsValidation = validateProofMetrics(proofMetrics);
880
- const scorecardValidation = validateScorecard(scorecard);
881
-
882
- scorecard.anti_gaming = {
883
- metrics_valid: metricsValidation.valid,
884
- scorecard_valid: scorecardValidation.valid,
885
- warnings: [...metricsValidation.warnings, ...scorecardValidation.warnings],
886
- };
887
-
888
- return scorecard;
889
- }
890
-
891
- module.exports = {
892
- explainReasonCode,
893
- buildStatusDashboard,
894
- buildEffectivenessScorecard,
895
- };
896
-
897
-
898
-
899
-
900
-