avorelo 0.3.8 → 0.4.0-rc.2
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 +16 -23
- package/README.md +62 -72
- package/bin/avorelo +9 -0
- package/package.json +147 -139
- package/scripts/README.md +40 -0
- package/scripts/avorelo-session-collision-guard.js +540 -0
- package/scripts/avorelo-workstream-preflight.js +918 -0
- package/scripts/cco-dashboard.js +346 -0
- package/scripts/cco-posttooluse.js +504 -0
- package/scripts/cco-pretooluse.js +381 -0
- package/scripts/cco-status.js +540 -0
- package/scripts/cco-stop.js +77 -0
- package/scripts/cco-userprompt-submit.js +83 -0
- package/scripts/lib/activation/account-state.js +37 -0
- package/scripts/lib/activation/activate-command.js +114 -0
- package/scripts/lib/activation/activation-runner.js +607 -0
- package/scripts/lib/activation/activation-self-healing.js +481 -0
- package/scripts/lib/activation/activation-state.js +96 -0
- package/scripts/lib/activation/activation-summary.js +241 -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/run-entry.js +346 -0
- package/scripts/lib/activation-distribution-readiness.js +507 -0
- package/scripts/lib/adapter-conformance.js +176 -0
- package/scripts/lib/adapter-readiness.js +428 -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-activation-readiness.js +878 -0
- package/scripts/lib/agent-enforcement.js +765 -0
- package/scripts/lib/agent-evolution-loop.js +479 -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-efficiency-dogfood-pack.js +437 -0
- package/scripts/lib/ai-efficiency-eval.js +207 -0
- package/scripts/lib/ai-efficiency-guard-contract.js +209 -0
- package/scripts/lib/ai-efficiency-measured-value.js +106 -0
- package/scripts/lib/ai-install-prompt.js +293 -0
- package/scripts/lib/ai-task-inference.js +155 -0
- package/scripts/lib/ai-value-ledger.js +121 -0
- package/scripts/lib/ai-value-proof-table.js +151 -0
- package/scripts/lib/ai-work-efficiency-routing.js +623 -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/artifact-receipt-hygiene.js +619 -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-governed-workflow.js +1020 -0
- package/scripts/lib/browser-proof-preflight.js +321 -0
- package/scripts/lib/cache-readiness.js +296 -0
- package/scripts/lib/canonical-reentry.js +162 -0
- package/scripts/lib/capability-contract-validator.js +177 -0
- package/scripts/lib/capability-hygiene.js +504 -0
- package/scripts/lib/capability-intake-quarantine.js +789 -0
- package/scripts/lib/capability-kernel-registry.js +566 -0
- package/scripts/lib/capability-kernel.js +202 -0
- package/scripts/lib/capability-manifest.js +255 -0
- package/scripts/lib/capability-outcome-normalizer.js +104 -0
- package/scripts/lib/capability-packs.js +314 -0
- package/scripts/lib/capability-recommender.js +513 -0
- package/scripts/lib/capability-registry.js +1062 -0
- package/scripts/lib/carry-forward-surfacing.js +194 -0
- package/scripts/lib/ccusage-adapter.js +188 -0
- package/scripts/lib/claude-session-evidence/index.js +1027 -0
- package/scripts/lib/cli-output-sanitizer.js +118 -0
- package/scripts/lib/company-loop.js +1149 -0
- package/scripts/lib/config.js +641 -0
- package/scripts/lib/context-acquisition-plan.js +359 -0
- package/scripts/lib/context-authority-rules.js +138 -0
- package/scripts/lib/context-budget-guard.js +170 -0
- package/scripts/lib/context-budget-scanner.js +257 -0
- package/scripts/lib/context-budget.js +167 -0
- package/scripts/lib/context-claim-safety.js +116 -0
- package/scripts/lib/context-compiler.js +236 -0
- package/scripts/lib/context-optimizer.js +715 -0
- package/scripts/lib/context-packet.js +121 -0
- package/scripts/lib/context-receipt.js +57 -0
- package/scripts/lib/context-reduction-plan.js +179 -0
- package/scripts/lib/context-safety.js +88 -0
- package/scripts/lib/context-savings-engine.js +158 -0
- package/scripts/lib/context-source-registry.js +393 -0
- package/scripts/lib/context-task-profiles.js +147 -0
- package/scripts/lib/cost-abuse-guard.js +975 -0
- package/scripts/lib/cost-evidence.js +287 -0
- package/scripts/lib/cost-to-outcome-signals.js +639 -0
- package/scripts/lib/cross-host-install-plan.js +308 -0
- package/scripts/lib/cross-host-install-readiness.js +242 -0
- package/scripts/lib/cross-host-value-flow.js +268 -0
- package/scripts/lib/dashboard.js +1056 -0
- package/scripts/lib/data-permissions-guard.js +1187 -0
- package/scripts/lib/deployment-environment-guard.js +1236 -0
- package/scripts/lib/design-partner-feedback.js +346 -0
- package/scripts/lib/dogfood-evidence-freshness.js +567 -0
- package/scripts/lib/efficiency-receipt.js +354 -0
- package/scripts/lib/entitlements.js +100 -0
- package/scripts/lib/execution-packet.js +559 -0
- package/scripts/lib/execution-route-governor.js +179 -0
- package/scripts/lib/experimentation-events.js +547 -0
- package/scripts/lib/external-capability-compliance.js +107 -0
- package/scripts/lib/external-readiness/ai-visibility/ai-visibility-runner.js +322 -0
- package/scripts/lib/external-readiness/calibration/benchmark-site-catalog.js +121 -0
- package/scripts/lib/external-readiness/calibration/completion-gate.js +112 -0
- package/scripts/lib/external-readiness/calibration/real-site-benchmark-runner.js +284 -0
- package/scripts/lib/external-readiness/drift-detector.js +100 -0
- package/scripts/lib/external-readiness/endpoint-prober.js +332 -0
- package/scripts/lib/external-readiness/external-readiness-runner.js +112 -0
- package/scripts/lib/external-readiness/full-agent-readiness-scorer.js +220 -0
- package/scripts/lib/external-readiness/golden-path-runner.js +333 -0
- package/scripts/lib/external-readiness/inside-out-runner.js +118 -0
- package/scripts/lib/external-readiness/proof-receipt-writer.js +112 -0
- package/scripts/lib/external-readiness/safe-fix-executor.js +117 -0
- package/scripts/lib/external-readiness/skills/category-boundary-guard.js +30 -0
- package/scripts/lib/external-readiness/skills/pmm-positioning-guard.js +69 -0
- package/scripts/lib/external-readiness/skills/safe-fix-policy.js +35 -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 +129 -0
- package/scripts/lib/full-readiness-gate.js +451 -0
- package/scripts/lib/governed-action-exposure-primitives.js +1514 -0
- package/scripts/lib/governed-exposure-planner.js +186 -0
- package/scripts/lib/governed-workspace-hygiene.js +946 -0
- package/scripts/lib/guard-suite-common.js +412 -0
- package/scripts/lib/guidance-builder.js +174 -0
- package/scripts/lib/hook-apply.js +1075 -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 +1051 -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 +635 -0
- package/scripts/lib/learning-experimentation-foundation.js +1484 -0
- package/scripts/lib/learning-memory.js +686 -0
- package/scripts/lib/lifecycle-hooks.js +982 -0
- package/scripts/lib/local-package-smoke.js +436 -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/model-work-class-routing.js +79 -0
- package/scripts/lib/next-run-context.js +436 -0
- package/scripts/lib/next-run-continuity.js +1207 -0
- package/scripts/lib/observability-recovery-guard.js +1030 -0
- package/scripts/lib/operating-value.js +1662 -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 +95 -0
- package/scripts/lib/orchestration/state.js +165 -0
- package/scripts/lib/orchestration/verification-manager.js +138 -0
- package/scripts/lib/outcome-evidence-stack.js +1083 -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 +2327 -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-home-receipt.js +1790 -0
- package/scripts/lib/product-learning-events.js +696 -0
- package/scripts/lib/production-confidence-control-tower.js +1209 -0
- package/scripts/lib/production-confidence.js +1858 -0
- package/scripts/lib/project-profile.js +555 -0
- package/scripts/lib/prompt-compiler-plan.js +94 -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-e2e/promise-completion.js +141 -0
- package/scripts/lib/proof-e2e/promise-dashboard-claims.js +135 -0
- package/scripts/lib/proof-e2e/promise-local-proof.js +156 -0
- package/scripts/lib/proof-e2e/promise-provider-neutral.js +136 -0
- package/scripts/lib/proof-e2e/promise-registry.js +219 -0
- package/scripts/lib/proof-e2e/promise-security-trust.js +141 -0
- package/scripts/lib/proof-e2e/promise-skills-risk.js +163 -0
- package/scripts/lib/proof-e2e/promise-token-savings.js +112 -0
- package/scripts/lib/proof-e2e/promise-work-management.js +126 -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/proof-savings-report.js +1549 -0
- package/scripts/lib/public-activation-distribution-gate.js +266 -0
- package/scripts/lib/public-cli.js +5631 -0
- package/scripts/lib/public-distribution-truth.js +211 -0
- package/scripts/lib/public-distribution.js +73 -0
- package/scripts/lib/public-install-claim-checker.js +300 -0
- package/scripts/lib/publish-provenance-readiness.js +287 -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 +147 -0
- package/scripts/lib/reentry-memory-store.js +183 -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-action-policy.js +104 -0
- package/scripts/lib/run-contract-receipt.js +48 -0
- package/scripts/lib/run-contract.js +288 -0
- package/scripts/lib/run-cost-to-verified-outcome.js +87 -0
- package/scripts/lib/run-improvements-lifecycle.js +330 -0
- package/scripts/lib/run-improvements.js +789 -0
- package/scripts/lib/run-proof-contract.js +116 -0
- package/scripts/lib/run-risk-classifier.js +131 -0
- package/scripts/lib/run-task-classifier.js +216 -0
- package/scripts/lib/runtime-decision-policy.js +387 -0
- package/scripts/lib/safe-path-engine.js +705 -0
- package/scripts/lib/safe-repair.js +877 -0
- package/scripts/lib/safe-run-controller.js +887 -0
- package/scripts/lib/scope-repair-before-approval.js +865 -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 +5053 -0
- package/scripts/lib/security-confidence/activation-safety.js +78 -0
- package/scripts/lib/security-confidence/adapters/adapter-contract.js +125 -0
- package/scripts/lib/security-confidence/adapters/mock-claude-bughunter-adapter.js +36 -0
- package/scripts/lib/security-confidence/adapters/mock-decepticon-adapter.js +34 -0
- package/scripts/lib/security-confidence/adapters/mock-mcp-scan-adapter.js +35 -0
- package/scripts/lib/security-confidence/adapters/mock-snyk-agent-scan-adapter.js +35 -0
- package/scripts/lib/security-confidence/adapters/mock-tank-adapter.js +34 -0
- package/scripts/lib/security-confidence/adapters/reference-registry.js +63 -0
- package/scripts/lib/security-confidence/auth-rbac-plan.js +39 -0
- package/scripts/lib/security-confidence/component-inventory.js +151 -0
- package/scripts/lib/security-confidence/constants.js +191 -0
- package/scripts/lib/security-confidence/dependency-script-risk.js +95 -0
- package/scripts/lib/security-confidence/evidence-hygiene.js +127 -0
- package/scripts/lib/security-confidence/feature-impact-classifier.js +80 -0
- package/scripts/lib/security-confidence/file-utils.js +161 -0
- package/scripts/lib/security-confidence/finding-triage.js +90 -0
- package/scripts/lib/security-confidence/findings.js +115 -0
- package/scripts/lib/security-confidence/index.js +29 -0
- package/scripts/lib/security-confidence/permission-budget.js +93 -0
- package/scripts/lib/security-confidence/redaction.js +82 -0
- package/scripts/lib/security-confidence/redteam-fixtures.js +53 -0
- package/scripts/lib/security-confidence/reference-adoption.js +229 -0
- package/scripts/lib/security-confidence/reference-taxonomy.js +155 -0
- package/scripts/lib/security-confidence/report-quality.js +99 -0
- package/scripts/lib/security-confidence/report-writer.js +79 -0
- package/scripts/lib/security-confidence/risk-classifier.js +187 -0
- package/scripts/lib/security-confidence/runner.js +179 -0
- package/scripts/lib/security-confidence/schema.js +188 -0
- package/scripts/lib/security-confidence/secret-safety.js +74 -0
- package/scripts/lib/security-confidence/security-capability-router.js +98 -0
- package/scripts/lib/security-confidence/web-security-smoke-plan.js +46 -0
- package/scripts/lib/security-risk-classifier.js +511 -0
- package/scripts/lib/security-scan.js +396 -0
- package/scripts/lib/session-context-optimizer.js +1211 -0
- package/scripts/lib/session-timing.js +322 -0
- package/scripts/lib/skill-hygiene.js +805 -0
- package/scripts/lib/skill-packs.js +161 -0
- package/scripts/lib/skills-operating-layer-v1.js +1023 -0
- package/scripts/lib/skills-operating-layer.js +629 -0
- package/scripts/lib/smallest-safe-plan.js +214 -0
- package/scripts/lib/smart-routing-plan.js +115 -0
- package/scripts/lib/smart-work-routing.js +768 -0
- package/scripts/lib/source-catalog.js +1022 -0
- package/scripts/lib/status-value-summary.js +32 -0
- package/scripts/lib/supply-chain-dependency-guard.js +1333 -0
- package/scripts/lib/supply-chain-guard.js +219 -0
- package/scripts/lib/support-bundle.js +561 -0
- package/scripts/lib/support-redaction.js +66 -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-evidence.js +862 -0
- package/scripts/lib/token-cost-intelligence.js +358 -0
- package/scripts/lib/token-efficiency-evidence.js +213 -0
- package/scripts/lib/token-efficiency-map.js +110 -0
- package/scripts/lib/token-evidence.js +703 -0
- package/scripts/lib/tokenish.js +17 -0
- package/scripts/lib/tool-output-sandbox.js +559 -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/webhook-idempotency-guard.js +990 -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-intelligence-radar.js +804 -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 +542 -0
- package/scripts/wuz-doctor.js +315 -0
- package/bin/avorelo.mjs +0 -7
- package/dist/avorelo.mjs +0 -24678
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { nowIso, safeWriteJson, safeReadJson } = require("./fsx");
|
|
4
|
+
const { inferTaskType } = require("./ai-task-inference");
|
|
5
|
+
const { computeContextBudget } = require("./context-budget");
|
|
6
|
+
const { computeTokenEfficiency } = require("./token-efficiency-map");
|
|
7
|
+
const { planGovernedExposure } = require("./governed-exposure-planner");
|
|
8
|
+
const { buildPromptCompilerPlan } = require("./prompt-compiler-plan");
|
|
9
|
+
const { computeRoutingPlan } = require("./smart-routing-plan");
|
|
10
|
+
const { classifyWorkClass } = require("./model-work-class-routing");
|
|
11
|
+
const { buildValueLedger, writeValueLedger, LEDGER_REL } = require("./ai-value-ledger");
|
|
12
|
+
const { buildValueProofTable } = require("./ai-value-proof-table");
|
|
13
|
+
const { computeMeasuredLocalValue } = require("./ai-efficiency-measured-value");
|
|
14
|
+
const { buildGuardIntegrationContract } = require("./ai-efficiency-guard-contract");
|
|
15
|
+
|
|
16
|
+
const CONTRACT = "avorelo.aiWorkEfficiencyRouting.v1";
|
|
17
|
+
const REPORT_DIR_REL = ".claude/cco/reports/ai-work-efficiency-routing";
|
|
18
|
+
const REPORT_JSON_REL = `${REPORT_DIR_REL}/latest-report.json`;
|
|
19
|
+
|
|
20
|
+
const COMPLEXITY_LIMITS = {
|
|
21
|
+
maxChangedFiles: 100,
|
|
22
|
+
maxStateArtifacts: 300,
|
|
23
|
+
maxWasteSignals: 20,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function buildAiWorkEfficiencyRouting(cwd, options = {}) {
|
|
27
|
+
const totalStartMs = Date.now();
|
|
28
|
+
|
|
29
|
+
const changedFiles = options.changedFiles || undefined;
|
|
30
|
+
const taskTypeOverride = options.taskType || undefined;
|
|
31
|
+
const guardOverride = options.guardOverride || undefined;
|
|
32
|
+
|
|
33
|
+
const task = inferTaskType(cwd, { changedFiles, taskType: taskTypeOverride });
|
|
34
|
+
|
|
35
|
+
const contextBudget = computeContextBudget(cwd, {
|
|
36
|
+
changedFiles: task.changedFiles,
|
|
37
|
+
...(options.stateArtifactOverride ? { stateArtifactOverride: options.stateArtifactOverride } : {}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
let governedExposure;
|
|
41
|
+
if (guardOverride) {
|
|
42
|
+
const baseExposure = planGovernedExposure(cwd, task);
|
|
43
|
+
governedExposure = {
|
|
44
|
+
...baseExposure,
|
|
45
|
+
guardEvidenceRefs: guardOverride,
|
|
46
|
+
status: guardOverride.some((g) => g.blocked) ? "blocked" : baseExposure.status,
|
|
47
|
+
};
|
|
48
|
+
} else {
|
|
49
|
+
governedExposure = planGovernedExposure(cwd, task);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const promptCompilerPlan = buildPromptCompilerPlan(task, governedExposure, contextBudget);
|
|
53
|
+
const tokenEfficiency = computeTokenEfficiency(contextBudget, governedExposure);
|
|
54
|
+
const routingPlan = computeRoutingPlan(task, governedExposure, contextBudget);
|
|
55
|
+
const modelTaskRouting = classifyWorkClass(task, routingPlan);
|
|
56
|
+
const valueLedger = buildValueLedger(task, routingPlan, contextBudget, tokenEfficiency, governedExposure, promptCompilerPlan);
|
|
57
|
+
|
|
58
|
+
const measuredLocalValue = computeMeasuredLocalValue(contextBudget, governedExposure, tokenEfficiency, promptCompilerPlan);
|
|
59
|
+
const guardIntegrationContract = buildGuardIntegrationContract(cwd);
|
|
60
|
+
|
|
61
|
+
const totalDurationMs = Date.now() - totalStartMs;
|
|
62
|
+
|
|
63
|
+
const filesInspected = task.changedFiles ? task.changedFiles.length : 0;
|
|
64
|
+
const artifactsInspected = contextBudget.estimatedContextItems || 0;
|
|
65
|
+
const bytesInspected = contextBudget.estimatedInputBytes || 0;
|
|
66
|
+
|
|
67
|
+
const performanceGuard = {
|
|
68
|
+
status: "pass",
|
|
69
|
+
durationMs: totalDurationMs,
|
|
70
|
+
filesInspected,
|
|
71
|
+
artifactsInspected,
|
|
72
|
+
bytesInspected,
|
|
73
|
+
limitsApplied: [],
|
|
74
|
+
reasonCodes: ["PERFORMANCE_GUARD_PASS"],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (task.changedFiles && task.changedFiles.length > COMPLEXITY_LIMITS.maxChangedFiles) {
|
|
78
|
+
performanceGuard.limitsApplied.push("SCAN_LIMIT_APPLIED");
|
|
79
|
+
performanceGuard.reasonCodes.push("SCAN_LIMIT_APPLIED");
|
|
80
|
+
}
|
|
81
|
+
if (artifactsInspected > COMPLEXITY_LIMITS.maxStateArtifacts) {
|
|
82
|
+
performanceGuard.limitsApplied.push("SCAN_SKIPPED_TOO_LARGE");
|
|
83
|
+
performanceGuard.reasonCodes.push("SCAN_SKIPPED_TOO_LARGE");
|
|
84
|
+
}
|
|
85
|
+
if (totalDurationMs > 1500) {
|
|
86
|
+
performanceGuard.status = "warn";
|
|
87
|
+
performanceGuard.reasonCodes.push("PERFORMANCE_GUARD_WARN");
|
|
88
|
+
}
|
|
89
|
+
if (totalDurationMs > 5000) {
|
|
90
|
+
performanceGuard.status = "blocked";
|
|
91
|
+
performanceGuard.reasonCodes.push("PERFORMANCE_GUARD_TRIGGERED");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const overhead = {
|
|
95
|
+
measured: true,
|
|
96
|
+
durationMs: totalDurationMs,
|
|
97
|
+
filesInspected,
|
|
98
|
+
stateArtifactsInspected: artifactsInspected,
|
|
99
|
+
limitsApplied: performanceGuard.limitsApplied,
|
|
100
|
+
reasonCodes: ["OVERHEAD_MEASURED"],
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (totalDurationMs > 5000) {
|
|
104
|
+
overhead.reasonCodes.push("STATUS_OVERHEAD_WARN");
|
|
105
|
+
} else {
|
|
106
|
+
overhead.reasonCodes.push("STATUS_OVERHEAD_WITHIN_LIMIT");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const isComplexityFallback = checkComplexityKillSwitch(task, contextBudget, tokenEfficiency, routingPlan);
|
|
110
|
+
|
|
111
|
+
const fullResult = {
|
|
112
|
+
task,
|
|
113
|
+
contextBudget,
|
|
114
|
+
governedExposure,
|
|
115
|
+
promptCompilerPlan,
|
|
116
|
+
tokenEfficiency,
|
|
117
|
+
routingPlan,
|
|
118
|
+
modelTaskRouting,
|
|
119
|
+
valueLedger,
|
|
120
|
+
overhead,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const valueProofTable = buildValueProofTable(fullResult);
|
|
124
|
+
|
|
125
|
+
const overallStatus = computeOverallStatus(task, routingPlan, governedExposure, contextBudget, valueLedger, isComplexityFallback);
|
|
126
|
+
const findings = collectFindings(fullResult, isComplexityFallback);
|
|
127
|
+
|
|
128
|
+
const integrations = buildIntegrations(overallStatus, valueLedger, routingPlan, contextBudget, measuredLocalValue);
|
|
129
|
+
|
|
130
|
+
const compactOutputQuality = buildCompactOutputQuality(findings, valueLedger, integrations);
|
|
131
|
+
|
|
132
|
+
const gatePolicy = {
|
|
133
|
+
mode: "mixed_warn_block",
|
|
134
|
+
blockRules: [
|
|
135
|
+
"GATE_BLOCK_RAW_PROMPT_DUMP", "GATE_BLOCK_RAW_CODE_DUMP", "GATE_BLOCK_RAW_LOG_DUMP",
|
|
136
|
+
"GATE_BLOCK_SECRET_EXPOSURE", "GATE_BLOCK_FAKE_SAVINGS", "GATE_BLOCK_FAKE_GREEN",
|
|
137
|
+
"GATE_BLOCK_MISSING_VALUE_PROOF", "GATE_BLOCK_ROUTE_WITHOUT_EVAL",
|
|
138
|
+
"GATE_BLOCK_MODEL_NETWORK_PROVIDER_CALL",
|
|
139
|
+
],
|
|
140
|
+
warnRules: [
|
|
141
|
+
"GATE_WARN_HEURISTIC_SAVINGS", "GATE_WARN_PARTIAL_DOGFOOD", "GATE_WARN_CONTRACT_ONLY_GUARD",
|
|
142
|
+
],
|
|
143
|
+
reasonCodes: ["GATE_POLICY_MIXED_WARN_BLOCK"],
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const report = {
|
|
147
|
+
schemaVersion: CONTRACT,
|
|
148
|
+
generatedAt: nowIso(),
|
|
149
|
+
status: overallStatus,
|
|
150
|
+
summary: buildSummary(overallStatus, findings, routingPlan, valueLedger),
|
|
151
|
+
task: {
|
|
152
|
+
type: task.type,
|
|
153
|
+
confidence: task.confidence,
|
|
154
|
+
source: task.source,
|
|
155
|
+
reasonCodes: task.reasonCodes,
|
|
156
|
+
},
|
|
157
|
+
governedExposure: {
|
|
158
|
+
status: governedExposure.status,
|
|
159
|
+
includeContextRefs: governedExposure.includeContextRefs,
|
|
160
|
+
excludeContextRefs: governedExposure.excludeContextRefs,
|
|
161
|
+
exposedCapabilityRefs: governedExposure.exposedCapabilityRefs,
|
|
162
|
+
suppressedCapabilityRefs: governedExposure.suppressedCapabilityRefs,
|
|
163
|
+
exposedToolRefs: governedExposure.exposedToolRefs,
|
|
164
|
+
suppressedToolRefs: governedExposure.suppressedToolRefs,
|
|
165
|
+
guardEvidenceRefs: governedExposure.guardEvidenceRefs,
|
|
166
|
+
memoryRefs: governedExposure.memoryRefs,
|
|
167
|
+
policyRefs: governedExposure.policyRefs,
|
|
168
|
+
proofExpectations: governedExposure.proofExpectations,
|
|
169
|
+
reasonCodes: governedExposure.reasonCodes,
|
|
170
|
+
},
|
|
171
|
+
promptCompilerPlan: {
|
|
172
|
+
status: promptCompilerPlan.status,
|
|
173
|
+
includeContextRefs: promptCompilerPlan.includeContextRefs,
|
|
174
|
+
excludeContextRefs: promptCompilerPlan.excludeContextRefs,
|
|
175
|
+
evidenceRefs: promptCompilerPlan.evidenceRefs,
|
|
176
|
+
proofExpectations: promptCompilerPlan.proofExpectations,
|
|
177
|
+
suppressedNoise: promptCompilerPlan.suppressedNoise,
|
|
178
|
+
safeNextRunDefaults: promptCompilerPlan.safeNextRunDefaults,
|
|
179
|
+
routeInstructions: promptCompilerPlan.routeInstructions,
|
|
180
|
+
forbiddenOutputRules: promptCompilerPlan.forbiddenOutputRules,
|
|
181
|
+
reasonCodes: promptCompilerPlan.reasonCodes,
|
|
182
|
+
},
|
|
183
|
+
contextBudget: {
|
|
184
|
+
status: contextBudget.status,
|
|
185
|
+
budgetClass: contextBudget.budgetClass,
|
|
186
|
+
estimatedInputBytes: contextBudget.estimatedInputBytes,
|
|
187
|
+
estimatedContextItems: contextBudget.estimatedContextItems,
|
|
188
|
+
heuristicTokenEstimate: contextBudget.heuristicTokenEstimate,
|
|
189
|
+
duplicateContextCount: contextBudget.duplicateContextCount,
|
|
190
|
+
staleContextCount: contextBudget.staleContextCount,
|
|
191
|
+
suppressedContextCount: contextBudget.suppressedContextCount,
|
|
192
|
+
reasonCodes: contextBudget.reasonCodes,
|
|
193
|
+
},
|
|
194
|
+
tokenEfficiency: {
|
|
195
|
+
status: tokenEfficiency.status,
|
|
196
|
+
avoidableWasteSignals: tokenEfficiency.avoidableWasteSignals,
|
|
197
|
+
estimatedSavings: tokenEfficiency.estimatedSavings,
|
|
198
|
+
reasonCodes: tokenEfficiency.reasonCodes,
|
|
199
|
+
},
|
|
200
|
+
routingPlan: {
|
|
201
|
+
status: routingPlan.status,
|
|
202
|
+
recommendedRoute: routingPlan.recommendedRoute,
|
|
203
|
+
routeConfidence: routingPlan.routeConfidence,
|
|
204
|
+
why: routingPlan.why,
|
|
205
|
+
requiredGuards: routingPlan.requiredGuards,
|
|
206
|
+
requiredProof: routingPlan.requiredProof,
|
|
207
|
+
approvalNeeded: routingPlan.approvalNeeded,
|
|
208
|
+
reasonCodes: routingPlan.reasonCodes,
|
|
209
|
+
},
|
|
210
|
+
modelTaskRouting: {
|
|
211
|
+
status: modelTaskRouting.status,
|
|
212
|
+
routeClass: modelTaskRouting.routeClass,
|
|
213
|
+
providerSpecific: false,
|
|
214
|
+
modelCallsMade: false,
|
|
215
|
+
reasonCodes: modelTaskRouting.reasonCodes,
|
|
216
|
+
},
|
|
217
|
+
valueLedger: {
|
|
218
|
+
status: valueLedger.status,
|
|
219
|
+
found: valueLedger.found,
|
|
220
|
+
prepared: valueLedger.prepared,
|
|
221
|
+
avoided: valueLedger.avoided,
|
|
222
|
+
proved: valueLedger.proved,
|
|
223
|
+
forReview: valueLedger.forReview,
|
|
224
|
+
safeNextAction: valueLedger.safeNextAction,
|
|
225
|
+
measurementTypes: valueLedger.measurementTypes,
|
|
226
|
+
reasonCodes: valueLedger.reasonCodes,
|
|
227
|
+
},
|
|
228
|
+
valueProofTable: valueProofTable.table,
|
|
229
|
+
measuredLocalValue,
|
|
230
|
+
guardIntegrationContract,
|
|
231
|
+
gatePolicy,
|
|
232
|
+
compactOutputQuality,
|
|
233
|
+
performanceGuard,
|
|
234
|
+
overhead,
|
|
235
|
+
findings,
|
|
236
|
+
integrations,
|
|
237
|
+
limits: {
|
|
238
|
+
localFirst: true,
|
|
239
|
+
deterministicFirst: true,
|
|
240
|
+
modelCalls: false,
|
|
241
|
+
networkCalls: false,
|
|
242
|
+
providerCalls: false,
|
|
243
|
+
rawPromptDump: false,
|
|
244
|
+
rawCodeDump: false,
|
|
245
|
+
rawLogDump: false,
|
|
246
|
+
secretDump: false,
|
|
247
|
+
autoModelSwitch: false,
|
|
248
|
+
autoProviderSwitch: false,
|
|
249
|
+
autoCapabilityExposure: false,
|
|
250
|
+
heavyDashboard: false,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return { report };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function computeOverallStatus(task, routingPlan, governedExposure, contextBudget, valueLedger, isComplexityFallback) {
|
|
258
|
+
if (task.type === "unknown" && task.confidence === "none") return "no_data";
|
|
259
|
+
if (routingPlan.status === "blocked") return "blocked";
|
|
260
|
+
if (governedExposure.status === "blocked") return "blocked";
|
|
261
|
+
if (isComplexityFallback) return "warn";
|
|
262
|
+
if (contextBudget.status === "warn") return "warn";
|
|
263
|
+
if (routingPlan.approvalNeeded) return "warn";
|
|
264
|
+
if (valueLedger.status === "no_data") return "warn";
|
|
265
|
+
return "pass";
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function checkComplexityKillSwitch(task, contextBudget, tokenEfficiency, routingPlan) {
|
|
269
|
+
const wasteCount = (tokenEfficiency.avoidableWasteSignals || []).length;
|
|
270
|
+
const changedCount = (task.changedFiles || []).length;
|
|
271
|
+
if (changedCount > COMPLEXITY_LIMITS.maxChangedFiles) return true;
|
|
272
|
+
if (contextBudget.estimatedContextItems > COMPLEXITY_LIMITS.maxStateArtifacts) return true;
|
|
273
|
+
if (wasteCount > COMPLEXITY_LIMITS.maxWasteSignals) return true;
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function buildSummary(status, findings, routingPlan, valueLedger) {
|
|
278
|
+
const blockCount = findings.filter((f) => f.severity === "block").length;
|
|
279
|
+
const warnCount = findings.filter((f) => f.severity === "warn").length;
|
|
280
|
+
const infoCount = findings.filter((f) => f.severity === "info").length;
|
|
281
|
+
|
|
282
|
+
const text = status === "pass"
|
|
283
|
+
? `Route ${routingPlan.recommendedRoute} ready. ${valueLedger.publicSafeSummary}`
|
|
284
|
+
: status === "blocked"
|
|
285
|
+
? `Blocked: ${valueLedger.forReview.length > 0 ? valueLedger.forReview[0] : "existing guard blocked."}`
|
|
286
|
+
: `Warning: ${warnCount} issue(s) to review. ${valueLedger.publicSafeSummary}`;
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
title: "AI work efficiency and routing",
|
|
290
|
+
text,
|
|
291
|
+
findingCounts: { info: infoCount, warn: warnCount, block: blockCount },
|
|
292
|
+
safeNextAction: valueLedger.safeNextAction,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function collectFindings(fullResult, isComplexityFallback) {
|
|
297
|
+
const findings = [];
|
|
298
|
+
const task = fullResult.task;
|
|
299
|
+
const ctx = fullResult.contextBudget;
|
|
300
|
+
const route = fullResult.routingPlan;
|
|
301
|
+
const exp = fullResult.governedExposure;
|
|
302
|
+
|
|
303
|
+
if (task.type !== "unknown") {
|
|
304
|
+
findings.push({
|
|
305
|
+
id: "task-inferred",
|
|
306
|
+
severity: "info",
|
|
307
|
+
reasonCode: "TASK_TYPE_INFERRED",
|
|
308
|
+
title: "Task type inferred",
|
|
309
|
+
message: `Task inferred as ${task.type} from ${task.source} evidence (${task.confidence} confidence).`,
|
|
310
|
+
evidenceRefs: [],
|
|
311
|
+
safeNextAction: "Verify task classification matches intent.",
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (ctx.status === "warn") {
|
|
316
|
+
findings.push({
|
|
317
|
+
id: "context-budget-warn",
|
|
318
|
+
severity: "warn",
|
|
319
|
+
reasonCode: ctx.budgetClass === "oversized" ? "CONTEXT_BUDGET_EXCEEDED" : "CONTEXT_BUDGET_WARN",
|
|
320
|
+
title: "Context budget warning",
|
|
321
|
+
message: `Context is ${ctx.budgetClass} (${ctx.estimatedContextItems} items, ~${ctx.heuristicTokenEstimate} tokens heuristic).`,
|
|
322
|
+
evidenceRefs: [],
|
|
323
|
+
safeNextAction: "Review and reduce context before proceeding.",
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (ctx.duplicateContextCount > 0) {
|
|
328
|
+
findings.push({
|
|
329
|
+
id: "duplicate-context",
|
|
330
|
+
severity: "info",
|
|
331
|
+
reasonCode: "DUPLICATE_CONTEXT_SIGNAL",
|
|
332
|
+
title: "Duplicate context detected",
|
|
333
|
+
message: `${ctx.duplicateContextCount} duplicate context ref(s) found.`,
|
|
334
|
+
evidenceRefs: [],
|
|
335
|
+
safeNextAction: "Deduplicate context refs.",
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (route.approvalNeeded) {
|
|
340
|
+
findings.push({
|
|
341
|
+
id: "approval-needed",
|
|
342
|
+
severity: "warn",
|
|
343
|
+
reasonCode: "ROUTE_REVIEW_REQUIRED",
|
|
344
|
+
title: "Human review required",
|
|
345
|
+
message: `Route ${route.recommendedRoute} requires approval before proceeding.`,
|
|
346
|
+
evidenceRefs: [],
|
|
347
|
+
safeNextAction: "Get human review before continuing.",
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const blockedGuards = (exp.guardEvidenceRefs || []).filter((g) => g.blocked);
|
|
352
|
+
for (const g of blockedGuards) {
|
|
353
|
+
findings.push({
|
|
354
|
+
id: `guard-blocked-${g.source}`,
|
|
355
|
+
severity: "block",
|
|
356
|
+
reasonCode: "EXISTING_GUARD_BLOCKED",
|
|
357
|
+
title: `Guard blocked: ${g.source}`,
|
|
358
|
+
message: `Existing ${g.source} guard is blocked. Route cannot bypass this.`,
|
|
359
|
+
evidenceRefs: [{ path: g.path, kind: "guard_output", selector: g.source, redacted: true }],
|
|
360
|
+
safeNextAction: `Resolve ${g.source} guard before proceeding.`,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (isComplexityFallback) {
|
|
365
|
+
findings.push({
|
|
366
|
+
id: "complexity-fallback",
|
|
367
|
+
severity: "warn",
|
|
368
|
+
reasonCode: "COMPLEXITY_LIMIT_REACHED",
|
|
369
|
+
title: "Complexity limit reached",
|
|
370
|
+
message: "Too many signals or files. Falling back to conservative recommendation.",
|
|
371
|
+
evidenceRefs: [],
|
|
372
|
+
safeNextAction: "Review scope and run a smaller proof-first task.",
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return findings;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function buildIntegrations(status, valueLedger, routingPlan, contextBudget, measuredLocalValue) {
|
|
380
|
+
const mlvCompact = measuredLocalValue && measuredLocalValue.suppressedContextRefs > 0
|
|
381
|
+
? ` ${measuredLocalValue.suppressedContextRefs} ref(s) suppressed.`
|
|
382
|
+
: "";
|
|
383
|
+
const statusLine = `AI route: ${routingPlan.recommendedRoute}; context ${contextBudget.budgetClass}; ${valueLedger.found.length} signal(s).${mlvCompact} Safe next action ready.`;
|
|
384
|
+
|
|
385
|
+
return {
|
|
386
|
+
productHome: {
|
|
387
|
+
cardSource: "aiWorkEfficiencyRouting",
|
|
388
|
+
status,
|
|
389
|
+
found: valueLedger.found.slice(0, 3),
|
|
390
|
+
fixedOrPrepared: valueLedger.prepared.slice(0, 3),
|
|
391
|
+
savedOrProved: valueLedger.avoided.slice(0, 3),
|
|
392
|
+
forReview: valueLedger.forReview.slice(0, 3),
|
|
393
|
+
safeNextAction: valueLedger.safeNextAction,
|
|
394
|
+
},
|
|
395
|
+
radar: {
|
|
396
|
+
included: true,
|
|
397
|
+
surface: "ai_work_efficiency_routing",
|
|
398
|
+
},
|
|
399
|
+
status: {
|
|
400
|
+
included: true,
|
|
401
|
+
compactLine: statusLine,
|
|
402
|
+
},
|
|
403
|
+
dashboard: {
|
|
404
|
+
included: true,
|
|
405
|
+
compactCardOnly: true,
|
|
406
|
+
},
|
|
407
|
+
valueSignals: {
|
|
408
|
+
included: true,
|
|
409
|
+
source: "aiWorkEfficiencyRouting",
|
|
410
|
+
},
|
|
411
|
+
receipts: {
|
|
412
|
+
included: true,
|
|
413
|
+
source: "aiWorkEfficiencyRouting",
|
|
414
|
+
},
|
|
415
|
+
nextRun: {
|
|
416
|
+
included: true,
|
|
417
|
+
safeDefaultsPrepared: true,
|
|
418
|
+
},
|
|
419
|
+
releaseGate: {
|
|
420
|
+
included: true,
|
|
421
|
+
mode: "warn",
|
|
422
|
+
},
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function buildCompactOutputQuality(findings, valueLedger, integrations) {
|
|
427
|
+
const maxBulletsPerSection = 5;
|
|
428
|
+
const reasonCodes = ["COMPACT_OUTPUT_QUALITY_PASS"];
|
|
429
|
+
|
|
430
|
+
const seenMessages = new Set();
|
|
431
|
+
let duplicatesSuppressed = 0;
|
|
432
|
+
for (const f of findings) {
|
|
433
|
+
if (seenMessages.has(f.message)) duplicatesSuppressed++;
|
|
434
|
+
else seenMessages.add(f.message);
|
|
435
|
+
}
|
|
436
|
+
if (duplicatesSuppressed > 0) reasonCodes.push("COMPACT_OUTPUT_DUPLICATES_SUPPRESSED");
|
|
437
|
+
|
|
438
|
+
const homeBullets = (integrations.productHome.found || []).length +
|
|
439
|
+
(integrations.productHome.fixedOrPrepared || []).length +
|
|
440
|
+
(integrations.productHome.savedOrProved || []).length +
|
|
441
|
+
(integrations.productHome.forReview || []).length;
|
|
442
|
+
if (homeBullets > maxBulletsPerSection * 4) reasonCodes.push("COMPACT_OUTPUT_LIMIT_APPLIED");
|
|
443
|
+
|
|
444
|
+
const rawDumpDetected = false;
|
|
445
|
+
const hasSafeNextAction = !!(valueLedger.safeNextAction && valueLedger.safeNextAction.length > 0);
|
|
446
|
+
if (hasSafeNextAction) reasonCodes.push("SAFE_NEXT_ACTION_PRESENT");
|
|
447
|
+
|
|
448
|
+
const usedPrepared = valueLedger.prepared.length > 0;
|
|
449
|
+
if (usedPrepared) reasonCodes.push("PREPARED_NOT_FIXED");
|
|
450
|
+
|
|
451
|
+
let status = "pass";
|
|
452
|
+
if (rawDumpDetected) status = "blocked";
|
|
453
|
+
else if (duplicatesSuppressed > 3) status = "warn";
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
status,
|
|
457
|
+
maxBulletsPerSection,
|
|
458
|
+
duplicatesSuppressed,
|
|
459
|
+
rawDumpDetected,
|
|
460
|
+
reasonCodes,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function generateAiWorkEfficiencyRouting(cwd, options = {}) {
|
|
465
|
+
const { report } = buildAiWorkEfficiencyRouting(cwd, options);
|
|
466
|
+
safeWriteJson(cwd, REPORT_JSON_REL, report);
|
|
467
|
+
return { report };
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function readLatestAiWorkEfficiencyRoutingReport(cwd) {
|
|
471
|
+
return safeReadJson(cwd, REPORT_JSON_REL);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function buildAiWorkEfficiencyRoutingSurface(cwd, options = {}) {
|
|
475
|
+
let report = readLatestAiWorkEfficiencyRoutingReport(cwd);
|
|
476
|
+
if (!report && options.buildIfMissing) {
|
|
477
|
+
const result = generateAiWorkEfficiencyRouting(cwd);
|
|
478
|
+
report = result.report;
|
|
479
|
+
}
|
|
480
|
+
if (!report) {
|
|
481
|
+
return {
|
|
482
|
+
showInStatus: false,
|
|
483
|
+
statusLine: "AI efficiency: no data",
|
|
484
|
+
status: "no_data",
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
showInStatus: true,
|
|
489
|
+
statusLine: report.integrations?.status?.compactLine || "AI efficiency: available",
|
|
490
|
+
status: report.status,
|
|
491
|
+
route: report.routingPlan?.recommendedRoute,
|
|
492
|
+
budgetClass: report.contextBudget?.budgetClass,
|
|
493
|
+
findingCounts: report.summary?.findingCounts,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function formatAiWorkEfficiencyRoutingText(report) {
|
|
498
|
+
const lines = [];
|
|
499
|
+
lines.push(`AI work efficiency and routing: ${report.status}`);
|
|
500
|
+
lines.push("");
|
|
501
|
+
|
|
502
|
+
if (report.valueLedger.found.length > 0) {
|
|
503
|
+
lines.push("Found:");
|
|
504
|
+
for (const f of report.valueLedger.found.slice(0, 5)) lines.push(` - ${f}`);
|
|
505
|
+
lines.push("");
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (report.valueLedger.prepared.length > 0) {
|
|
509
|
+
lines.push("Prepared:");
|
|
510
|
+
for (const p of report.valueLedger.prepared.slice(0, 5)) lines.push(` - ${p}`);
|
|
511
|
+
lines.push("");
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (report.valueLedger.avoided.length > 0) {
|
|
515
|
+
lines.push("Saved-or-Proved:");
|
|
516
|
+
for (const a of report.valueLedger.avoided.slice(0, 5)) lines.push(` - ${a}`);
|
|
517
|
+
lines.push("");
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (report.valueLedger.forReview.length > 0) {
|
|
521
|
+
lines.push("For review:");
|
|
522
|
+
for (const r of report.valueLedger.forReview.slice(0, 5)) lines.push(` - ${r}`);
|
|
523
|
+
lines.push("");
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const mlv = report.measuredLocalValue;
|
|
527
|
+
if (mlv && mlv.status !== "unavailable") {
|
|
528
|
+
lines.push("Measured local value:");
|
|
529
|
+
if (mlv.suppressedContextRefs > 0) lines.push(` - ${mlv.suppressedContextRefs} context ref(s) suppressed`);
|
|
530
|
+
if (mlv.capabilityRefsSuppressed > 0) lines.push(` - ${mlv.capabilityRefsSuppressed} capability(ies) suppressed`);
|
|
531
|
+
if (mlv.toolRefsSuppressed > 0) lines.push(` - ${mlv.toolRefsSuppressed} tool(s) suppressed`);
|
|
532
|
+
if (mlv.staleRefsSuppressed > 0) lines.push(` - ${mlv.staleRefsSuppressed} stale ref(s) suppressed`);
|
|
533
|
+
if (mlv.duplicateRefsSuppressed > 0) lines.push(` - ${mlv.duplicateRefsSuppressed} duplicate(s) suppressed`);
|
|
534
|
+
if (mlv.caveat) lines.push(` Caveat: ${mlv.caveat}`);
|
|
535
|
+
lines.push("");
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
lines.push("Safe next action:");
|
|
539
|
+
lines.push(` ${report.valueLedger.safeNextAction}`);
|
|
540
|
+
|
|
541
|
+
return lines.join("\n");
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function runAiEfficiencyGate(cwd, options = {}) {
|
|
545
|
+
const { report } = buildAiWorkEfficiencyRouting(cwd, options);
|
|
546
|
+
const blockFindings = [];
|
|
547
|
+
const warnFindings = [];
|
|
548
|
+
|
|
549
|
+
if (report.limits.rawPromptDump) blockFindings.push({ severity: "block", reason: "GATE_BLOCK_RAW_PROMPT_DUMP" });
|
|
550
|
+
if (report.limits.rawCodeDump) blockFindings.push({ severity: "block", reason: "GATE_BLOCK_RAW_CODE_DUMP" });
|
|
551
|
+
if (report.limits.rawLogDump) blockFindings.push({ severity: "block", reason: "GATE_BLOCK_RAW_LOG_DUMP" });
|
|
552
|
+
if (report.limits.secretDump) blockFindings.push({ severity: "block", reason: "GATE_BLOCK_SECRET_EXPOSURE" });
|
|
553
|
+
if (report.limits.modelCalls) blockFindings.push({ severity: "block", reason: "GATE_BLOCK_MODEL_NETWORK_PROVIDER_CALL" });
|
|
554
|
+
if (report.limits.networkCalls) blockFindings.push({ severity: "block", reason: "GATE_BLOCK_MODEL_NETWORK_PROVIDER_CALL" });
|
|
555
|
+
if (report.limits.providerCalls) blockFindings.push({ severity: "block", reason: "GATE_BLOCK_MODEL_NETWORK_PROVIDER_CALL" });
|
|
556
|
+
|
|
557
|
+
const mlv = report.measuredLocalValue || {};
|
|
558
|
+
if (mlv.publicClaimAllowed && mlv.measurementType === "heuristic") {
|
|
559
|
+
blockFindings.push({ severity: "block", reason: "GATE_BLOCK_FAKE_SAVINGS" });
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const guardContract = report.guardIntegrationContract || {};
|
|
563
|
+
const blockedGuards = (guardContract.guards || []).filter((g) => g.present && g.blocked);
|
|
564
|
+
if (blockedGuards.length > 0 && report.status === "pass") {
|
|
565
|
+
blockFindings.push({ severity: "block", reason: "GATE_BLOCK_FAKE_GREEN" });
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
for (const f of report.findings) {
|
|
569
|
+
if (f.severity === "block") {
|
|
570
|
+
blockFindings.push({ severity: "block", reason: f.reasonCode });
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (report.tokenEfficiency && report.tokenEfficiency.estimatedSavings &&
|
|
575
|
+
report.tokenEfficiency.estimatedSavings.type === "heuristic") {
|
|
576
|
+
warnFindings.push({ severity: "warn", reason: "GATE_WARN_HEURISTIC_SAVINGS" });
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const contractOnlyGuards = (guardContract.guards || []).filter((g) => !g.present && g.contractReady);
|
|
580
|
+
if (contractOnlyGuards.length > 0) {
|
|
581
|
+
warnFindings.push({ severity: "warn", reason: "GATE_WARN_CONTRACT_ONLY_GUARD" });
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (report.routingPlan && report.routingPlan.routeConfidence === "low") {
|
|
585
|
+
warnFindings.push({ severity: "warn", reason: "GATE_WARN_LOW_ROUTE_CONFIDENCE" });
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const allFindings = [...blockFindings, ...warnFindings];
|
|
589
|
+
const gateStatus = blockFindings.length > 0 ? "blocked" : warnFindings.length > 0 ? "warn" : "pass";
|
|
590
|
+
|
|
591
|
+
const reasonCodes = ["GATE_POLICY_MIXED_WARN_BLOCK"];
|
|
592
|
+
if (gateStatus === "pass") reasonCodes.push("GATE_PASS");
|
|
593
|
+
if (gateStatus === "warn") reasonCodes.push("GATE_WARN");
|
|
594
|
+
if (gateStatus === "blocked") reasonCodes.push("GATE_BLOCKED");
|
|
595
|
+
|
|
596
|
+
const safeNextAction = gateStatus === "blocked"
|
|
597
|
+
? "Resolve block findings before proceeding."
|
|
598
|
+
: gateStatus === "warn"
|
|
599
|
+
? "Review warn findings; may proceed with caution."
|
|
600
|
+
: "Gate passed. Continue with recommended route.";
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
status: gateStatus,
|
|
604
|
+
blockFindings,
|
|
605
|
+
warnFindings,
|
|
606
|
+
findings: allFindings,
|
|
607
|
+
reasonCodes,
|
|
608
|
+
evidenceRefs: report.findings.flatMap((f) => f.evidenceRefs || []),
|
|
609
|
+
safeNextAction,
|
|
610
|
+
reportStatus: report.status,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
module.exports = {
|
|
615
|
+
buildAiWorkEfficiencyRouting,
|
|
616
|
+
generateAiWorkEfficiencyRouting,
|
|
617
|
+
readLatestAiWorkEfficiencyRoutingReport,
|
|
618
|
+
buildAiWorkEfficiencyRoutingSurface,
|
|
619
|
+
formatAiWorkEfficiencyRoutingText,
|
|
620
|
+
runAiEfficiencyGate,
|
|
621
|
+
CONTRACT,
|
|
622
|
+
REPORT_JSON_REL,
|
|
623
|
+
};
|