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,900 @@
|
|
|
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
|
+
|