avorelo 0.1.0 → 0.3.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 +23 -16
- package/README.md +90 -51
- package/bin/avorelo.mjs +7 -0
- package/dist/avorelo.mjs +19741 -0
- package/package.json +135 -120
- package/bin/avorelo +0 -9
- package/scripts/README.md +0 -40
- package/scripts/cco-dashboard.js +0 -252
- package/scripts/cco-status.js +0 -430
- package/scripts/lib/activation/account-state.js +0 -37
- package/scripts/lib/activation/activation-runner.js +0 -546
- package/scripts/lib/activation/activation-self-healing.js +0 -480
- package/scripts/lib/activation/activation-state.js +0 -83
- package/scripts/lib/activation/activation-summary.js +0 -191
- package/scripts/lib/activation/adapters/claude-code.js +0 -77
- package/scripts/lib/activation/adapters/codex-cli.js +0 -52
- package/scripts/lib/activation/adapters/cursor.js +0 -37
- package/scripts/lib/activation/adapters/github-agent.js +0 -39
- package/scripts/lib/activation/adapters/terminal.js +0 -42
- package/scripts/lib/activation/adapters/vscode.js +0 -39
- package/scripts/lib/activation/adapters/windsurf.js +0 -37
- package/scripts/lib/activation/ai-surface-detector.js +0 -151
- package/scripts/lib/activation/connect-account.js +0 -145
- package/scripts/lib/activation/detect-environment.js +0 -75
- package/scripts/lib/activation/detect-hosts.js +0 -62
- package/scripts/lib/activation/format-activation-output.js +0 -109
- package/scripts/lib/activation/next-action.js +0 -43
- package/scripts/lib/activation/repair-engine.js +0 -219
- package/scripts/lib/activation-distribution-readiness.js +0 -507
- package/scripts/lib/adapter-conformance.js +0 -176
- package/scripts/lib/adapter-readiness.js +0 -417
- package/scripts/lib/adapter-safety-boundaries.js +0 -335
- package/scripts/lib/adapter-technical-readiness-gate.js +0 -205
- package/scripts/lib/agent-access-governance.js +0 -455
- package/scripts/lib/agent-enforcement.js +0 -765
- package/scripts/lib/agent-policy-profile.js +0 -210
- package/scripts/lib/agent-security/action-evaluator.js +0 -507
- package/scripts/lib/agent-security/adapter-registry.js +0 -98
- package/scripts/lib/agent-security/auto-policy.js +0 -139
- package/scripts/lib/agent-security/bounded-scan.js +0 -93
- package/scripts/lib/agent-security/enforcement-adapter.js +0 -174
- package/scripts/lib/agent-security/enforcement-engine.js +0 -1129
- package/scripts/lib/agent-security/file-write-adapter.js +0 -183
- package/scripts/lib/agent-security/file-write-rules.js +0 -178
- package/scripts/lib/agent-security/index.js +0 -3342
- package/scripts/lib/agent-security/instruction-risk.js +0 -181
- package/scripts/lib/agent-security/mcp-action-adapter.js +0 -185
- package/scripts/lib/agent-security/mcp-action-rules.js +0 -184
- package/scripts/lib/agent-security/package-action-adapter.js +0 -175
- package/scripts/lib/agent-security/package-action-rules.js +0 -233
- package/scripts/lib/agent-security/performance.js +0 -148
- package/scripts/lib/agent-security/permission-minimizer.js +0 -403
- package/scripts/lib/agent-security/scan-cache.js +0 -74
- package/scripts/lib/agent-security/source-trust.js +0 -146
- package/scripts/lib/ai-install-prompt.js +0 -288
- package/scripts/lib/ai-workspace-hygiene.js +0 -1499
- package/scripts/lib/alpha-activation.js +0 -520
- package/scripts/lib/alpha-feedback.js +0 -263
- package/scripts/lib/alpha-readiness-gate.js +0 -332
- package/scripts/lib/anti-gaming.js +0 -169
- package/scripts/lib/artifact-health.js +0 -431
- package/scripts/lib/attribution.js +0 -180
- package/scripts/lib/audit.js +0 -289
- package/scripts/lib/avorelo-skill-registry.js +0 -810
- package/scripts/lib/batch-jobs.js +0 -71
- package/scripts/lib/brain-pack.js +0 -578
- package/scripts/lib/brand-boundary.js +0 -424
- package/scripts/lib/brand.js +0 -74
- package/scripts/lib/browser-capability.js +0 -1048
- package/scripts/lib/browser-proof-preflight.js +0 -321
- package/scripts/lib/cache-readiness.js +0 -187
- package/scripts/lib/canonical-reentry.js +0 -162
- package/scripts/lib/capability-packs.js +0 -314
- package/scripts/lib/capability-recommender.js +0 -512
- package/scripts/lib/capability-registry.js +0 -1059
- package/scripts/lib/carry-forward-surfacing.js +0 -194
- package/scripts/lib/ccusage-adapter.js +0 -188
- package/scripts/lib/company-loop.js +0 -1149
- package/scripts/lib/config.js +0 -637
- package/scripts/lib/context-acquisition-plan.js +0 -287
- package/scripts/lib/context-budget-guard.js +0 -170
- package/scripts/lib/context-budget-scanner.js +0 -257
- package/scripts/lib/context-optimizer.js +0 -715
- package/scripts/lib/context-reduction-plan.js +0 -178
- package/scripts/lib/context-safety.js +0 -88
- package/scripts/lib/context-savings-engine.js +0 -158
- package/scripts/lib/cost-evidence.js +0 -254
- package/scripts/lib/cross-host-install-plan.js +0 -308
- package/scripts/lib/cross-host-install-readiness.js +0 -237
- package/scripts/lib/cross-host-value-flow.js +0 -268
- package/scripts/lib/dashboard.js +0 -900
- package/scripts/lib/design-partner-feedback.js +0 -346
- package/scripts/lib/entitlements.js +0 -100
- package/scripts/lib/execution-packet.js +0 -559
- package/scripts/lib/experimentation-events.js +0 -547
- package/scripts/lib/external-capability-compliance.js +0 -107
- package/scripts/lib/external-user-simulation.js +0 -166
- package/scripts/lib/failure-recovery-readiness.js +0 -81
- package/scripts/lib/failure-recovery.js +0 -419
- package/scripts/lib/feedback-intelligence.js +0 -537
- package/scripts/lib/feedback-signals.js +0 -205
- package/scripts/lib/file-integrity.js +0 -68
- package/scripts/lib/fsx.js +0 -127
- package/scripts/lib/full-readiness-gate.js +0 -451
- package/scripts/lib/guidance-builder.js +0 -174
- package/scripts/lib/hook-apply.js +0 -1019
- package/scripts/lib/hook-baseline.js +0 -310
- package/scripts/lib/hook-config-preview.js +0 -275
- package/scripts/lib/hook-contracts.js +0 -290
- package/scripts/lib/hook-safety-boundary-readiness.js +0 -80
- package/scripts/lib/host-capability-matrix.js +0 -351
- package/scripts/lib/host-support-context.js +0 -254
- package/scripts/lib/http-hook-action.js +0 -538
- package/scripts/lib/install-ai-readiness.js +0 -84
- package/scripts/lib/install-intake-risk.js +0 -1037
- package/scripts/lib/install-journey-intelligence.js +0 -329
- package/scripts/lib/intervention-guidance.js +0 -57
- package/scripts/lib/known-limitations.js +0 -115
- package/scripts/lib/l8-path-truth.js +0 -146
- package/scripts/lib/launch-hardening-gate.js +0 -436
- package/scripts/lib/launch-readiness.js +0 -628
- package/scripts/lib/learning-memory.js +0 -686
- package/scripts/lib/lifecycle-hooks.js +0 -802
- package/scripts/lib/local-package-smoke.js +0 -423
- package/scripts/lib/local-pricing.js +0 -299
- package/scripts/lib/mcp-enforcement.js +0 -311
- package/scripts/lib/mcp-least-privilege-policy.js +0 -303
- package/scripts/lib/mcp-tool-inventory.js +0 -388
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +0 -335
- package/scripts/lib/metrics.js +0 -699
- package/scripts/lib/micro-proof.js +0 -133
- package/scripts/lib/next-run-context.js +0 -436
- package/scripts/lib/operating-value.js +0 -1648
- package/scripts/lib/optimization-v3.js +0 -122
- package/scripts/lib/orchestration/adapters/_shared.js +0 -49
- package/scripts/lib/orchestration/adapters/aider.js +0 -18
- package/scripts/lib/orchestration/adapters/claude-code.js +0 -35
- package/scripts/lib/orchestration/adapters/codex.js +0 -35
- package/scripts/lib/orchestration/adapters/gemini-cli.js +0 -18
- package/scripts/lib/orchestration/adapters/git.js +0 -25
- package/scripts/lib/orchestration/adapters/index.js +0 -31
- package/scripts/lib/orchestration/adapters/lm-studio.js +0 -18
- package/scripts/lib/orchestration/adapters/ollama.js +0 -18
- package/scripts/lib/orchestration/adapters/opencode.js +0 -18
- package/scripts/lib/orchestration/adapters/openrouter.js +0 -18
- package/scripts/lib/orchestration/adapters/test-runner.js +0 -25
- package/scripts/lib/orchestration/cli.js +0 -438
- package/scripts/lib/orchestration/execution-manager.js +0 -279
- package/scripts/lib/orchestration/handoff.js +0 -314
- package/scripts/lib/orchestration/index.js +0 -456
- package/scripts/lib/orchestration/inventory.js +0 -47
- package/scripts/lib/orchestration/model-discovery.js +0 -498
- package/scripts/lib/orchestration/model-profiler.js +0 -170
- package/scripts/lib/orchestration/model-profiles.js +0 -252
- package/scripts/lib/orchestration/model-refresh-policy.js +0 -72
- package/scripts/lib/orchestration/proof-writer.js +0 -349
- package/scripts/lib/orchestration/provider-discovery/aider.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +0 -56
- package/scripts/lib/orchestration/provider-discovery/codex.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/common.js +0 -186
- package/scripts/lib/orchestration/provider-discovery/gemini.js +0 -106
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +0 -118
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +0 -12
- package/scripts/lib/orchestration/provider-discovery/ollama.js +0 -100
- package/scripts/lib/orchestration/provider-discovery/opencode.js +0 -47
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +0 -44
- package/scripts/lib/orchestration/risk-classifier.js +0 -130
- package/scripts/lib/orchestration/routing-policy.js +0 -486
- package/scripts/lib/orchestration/settings.js +0 -112
- package/scripts/lib/orchestration/state.js +0 -165
- package/scripts/lib/orchestration/verification-manager.js +0 -138
- package/scripts/lib/output-profiles.js +0 -146
- package/scripts/lib/package-content-audit.js +0 -368
- package/scripts/lib/package-runtime.js +0 -278
- package/scripts/lib/plan-surface.js +0 -53
- package/scripts/lib/plans.js +0 -2318
- package/scripts/lib/policy-provider.js +0 -27
- package/scripts/lib/prelaunch-activation-readiness.js +0 -409
- package/scripts/lib/prelaunch-evidence-store.js +0 -816
- package/scripts/lib/prelaunch-intelligence.js +0 -869
- package/scripts/lib/pricing-experiment.js +0 -118
- package/scripts/lib/pro-moment-events.js +0 -77
- package/scripts/lib/pro-moment-state.js +0 -227
- package/scripts/lib/pro-moments.js +0 -1216
- package/scripts/lib/product-learning-events.js +0 -629
- package/scripts/lib/project-profile.js +0 -555
- package/scripts/lib/prompt-compiler.js +0 -280
- package/scripts/lib/prompt-lint.js +0 -32
- package/scripts/lib/prompt-suggestions.js +0 -52
- package/scripts/lib/proof-canonical.js +0 -398
- package/scripts/lib/proof-drilldown.js +0 -383
- package/scripts/lib/proof-events.js +0 -342
- package/scripts/lib/proof-history.js +0 -243
- package/scripts/lib/proof-metrics.js +0 -296
- package/scripts/lib/proof-outcome-evidence.js +0 -134
- package/scripts/lib/proof-receipt.js +0 -335
- package/scripts/lib/proof-record.js +0 -461
- package/scripts/lib/public-activation-distribution-gate.js +0 -258
- package/scripts/lib/public-cli.js +0 -3891
- package/scripts/lib/public-distribution-truth.js +0 -211
- package/scripts/lib/public-install-claim-checker.js +0 -294
- package/scripts/lib/publish-provenance-readiness.js +0 -283
- package/scripts/lib/readiness-delta.js +0 -218
- package/scripts/lib/readiness-evidence-closure.js +0 -196
- package/scripts/lib/reentry-memory-capture.js +0 -241
- package/scripts/lib/reentry-memory-retrieval.js +0 -302
- package/scripts/lib/reentry-memory-status.js +0 -146
- package/scripts/lib/reentry-memory-store.js +0 -178
- package/scripts/lib/reentry-state.js +0 -66
- package/scripts/lib/release-candidate-bundle.js +0 -166
- package/scripts/lib/remediation.js +0 -81
- package/scripts/lib/repo-map.js +0 -391
- package/scripts/lib/run-improvements-lifecycle.js +0 -330
- package/scripts/lib/run-improvements.js +0 -789
- package/scripts/lib/runtime-decision-policy.js +0 -387
- package/scripts/lib/safe-path-engine.js +0 -705
- package/scripts/lib/safe-run-controller.js +0 -887
- package/scripts/lib/score.js +0 -262
- package/scripts/lib/seamless-enforcement.js +0 -329
- package/scripts/lib/seamless-outcome.js +0 -689
- package/scripts/lib/seamless-reality-gate.js +0 -5043
- package/scripts/lib/security-risk-classifier.js +0 -511
- package/scripts/lib/security-scan.js +0 -384
- package/scripts/lib/session-context-optimizer.js +0 -1211
- package/scripts/lib/session-timing.js +0 -315
- package/scripts/lib/skill-hygiene.js +0 -805
- package/scripts/lib/skill-packs.js +0 -161
- package/scripts/lib/skills-operating-layer.js +0 -580
- package/scripts/lib/smart-work-routing.js +0 -768
- package/scripts/lib/source-catalog.js +0 -700
- package/scripts/lib/status-value-summary.js +0 -32
- package/scripts/lib/support-bundle.js +0 -578
- package/scripts/lib/task-continuation.js +0 -440
- package/scripts/lib/test-helpers.js +0 -15
- package/scripts/lib/tier.js +0 -38
- package/scripts/lib/token-context-quality-gate.js +0 -370
- package/scripts/lib/token-cost-capture.js +0 -187
- package/scripts/lib/token-cost-intelligence.js +0 -358
- package/scripts/lib/token-efficiency-evidence.js +0 -213
- package/scripts/lib/token-evidence.js +0 -699
- package/scripts/lib/tokenish.js +0 -17
- package/scripts/lib/tool-output-sandbox.js +0 -304
- package/scripts/lib/trust-audit.js +0 -136
- package/scripts/lib/unified-events.js +0 -396
- package/scripts/lib/upgrade-interruption-recovery.js +0 -407
- package/scripts/lib/usage-ledger.js +0 -201
- package/scripts/lib/value-ledger.js +0 -130
- package/scripts/lib/value-proof-calibration.js +0 -531
- package/scripts/lib/visual-qa.js +0 -231
- package/scripts/lib/voice-alpha.js +0 -29
- package/scripts/lib/work-aware-orchestration.js +0 -976
- package/scripts/lib/work-control-receipts.js +0 -577
- package/scripts/lib/work-ledger.js +0 -1123
- package/scripts/lib/work-panel-preview.js +0 -352
- package/scripts/lib/workflow-discipline.js +0 -280
- package/scripts/lib/workflow-signals.js +0 -419
- package/scripts/lib/workspace-map.js +0 -281
- package/scripts/lib/workspace-registry.js +0 -1367
- package/scripts/lib/workspace-resolver.js +0 -480
|
@@ -1,1123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require("node:fs");
|
|
4
|
-
const path = require("node:path");
|
|
5
|
-
const crypto = require("node:crypto");
|
|
6
|
-
|
|
7
|
-
const CONTRACT = "avorelo.workLedger.v1";
|
|
8
|
-
const SCHEMA_VERSION = 1;
|
|
9
|
-
|
|
10
|
-
const LEDGER_DIR_REL = ".claude/cco/orchestration/work-ledger";
|
|
11
|
-
const LATEST_LEDGER_REL = `${LEDGER_DIR_REL}/latest-ledger.json`;
|
|
12
|
-
|
|
13
|
-
const ENTRY_TYPES = Object.freeze([
|
|
14
|
-
"route",
|
|
15
|
-
"context",
|
|
16
|
-
"guard",
|
|
17
|
-
"safe_path",
|
|
18
|
-
"intake",
|
|
19
|
-
"workspace_hygiene",
|
|
20
|
-
"orchestration",
|
|
21
|
-
"smart_route",
|
|
22
|
-
"safe_run",
|
|
23
|
-
"proof",
|
|
24
|
-
"outcome",
|
|
25
|
-
"reality_gate",
|
|
26
|
-
"product_learning",
|
|
27
|
-
"dogfood",
|
|
28
|
-
"feedback",
|
|
29
|
-
// PR #140 — Hook Baseline + Lifecycle Automation Preview
|
|
30
|
-
"hook_baseline",
|
|
31
|
-
"adapter_readiness",
|
|
32
|
-
"hook_config_preview",
|
|
33
|
-
"lifecycle_hook",
|
|
34
|
-
// PR #141 — Explicit Hook Apply + Lifecycle Live
|
|
35
|
-
"hook_apply",
|
|
36
|
-
"hook_doctor",
|
|
37
|
-
"hook_rollback",
|
|
38
|
-
"hook_uninstall",
|
|
39
|
-
// PR #142 — Activation Alpha Readiness + First Value
|
|
40
|
-
"alpha_activation",
|
|
41
|
-
"alpha_readiness_gate",
|
|
42
|
-
"alpha_feedback",
|
|
43
|
-
"support_bundle",
|
|
44
|
-
// PR #143 — Token Efficiency + Context Quality Hardening
|
|
45
|
-
"token_efficiency_evidence",
|
|
46
|
-
"tool_output_sandbox",
|
|
47
|
-
"repo_map",
|
|
48
|
-
"context_acquisition_plan",
|
|
49
|
-
"cache_readiness",
|
|
50
|
-
"token_context_quality_gate",
|
|
51
|
-
// PR #144 — Launch Hardening + Failure Recovery v1
|
|
52
|
-
"failure_recovery",
|
|
53
|
-
"launch_hardening_gate",
|
|
54
|
-
"artifact_health",
|
|
55
|
-
"artifact_cleanup",
|
|
56
|
-
"doctor_hardening",
|
|
57
|
-
// PR #145 — MCP Least-Privilege Tool Governance v1
|
|
58
|
-
"mcp_tool_inventory",
|
|
59
|
-
"mcp_tool_risk",
|
|
60
|
-
"mcp_policy_preview",
|
|
61
|
-
"mcp_pre_tool_use_decision",
|
|
62
|
-
// PR #146 � One-Prompt AI Install + Pre-Launch Activation Readiness
|
|
63
|
-
"ai_install_prompt",
|
|
64
|
-
"prelaunch_activation_readiness",
|
|
65
|
-
"install_journey_intelligence",
|
|
66
|
-
// PR #147 � Pre-Launch Intelligence Layer
|
|
67
|
-
"prelaunch_intelligence",
|
|
68
|
-
"feedback_intelligence",
|
|
69
|
-
"token_cost_intelligence",
|
|
70
|
-
"token_cost_capture_checked",
|
|
71
|
-
"feedback_evidence_imported",
|
|
72
|
-
"token_cost_evidence_imported",
|
|
73
|
-
"token_cost_summary_generated",
|
|
74
|
-
"proof_outcome_evidence_checked",
|
|
75
|
-
"failure_recovery_checked",
|
|
76
|
-
"hook_safety_boundary_checked",
|
|
77
|
-
"readiness_evidence_gap_closed",
|
|
78
|
-
// PR #148 � Full Readiness / Release Candidate Gate
|
|
79
|
-
"full_readiness_gate",
|
|
80
|
-
"readiness_evidence_closure",
|
|
81
|
-
"known_limitations",
|
|
82
|
-
"external_user_simulation",
|
|
83
|
-
"release_candidate_bundle",
|
|
84
|
-
"activation_distribution_readiness",
|
|
85
|
-
"activation_distribution_check",
|
|
86
|
-
"activation_distribution_evidence",
|
|
87
|
-
"design_partner_feedback_session",
|
|
88
|
-
"design_partner_feedback_summary",
|
|
89
|
-
"readiness_delta",
|
|
90
|
-
// PR #161 — Public Activation Distribution Truth v1
|
|
91
|
-
"public_distribution_truth",
|
|
92
|
-
"package_content_audit",
|
|
93
|
-
"local_package_smoke",
|
|
94
|
-
"public_install_claim_check",
|
|
95
|
-
"publish_provenance_readiness",
|
|
96
|
-
"public_activation_distribution_gate",
|
|
97
|
-
"unknown",
|
|
98
|
-
]);
|
|
99
|
-
|
|
100
|
-
// Artifact source paths (relative to cwd)
|
|
101
|
-
const ARTIFACT_PATHS = Object.freeze({
|
|
102
|
-
orchestration_plan:
|
|
103
|
-
".claude/cco/orchestration/work-aware-orchestration/latest-plan.json",
|
|
104
|
-
context_pack:
|
|
105
|
-
".claude/cco/orchestration/context-optimizer/latest-pack.json",
|
|
106
|
-
context_receipt:
|
|
107
|
-
".claude/cco/orchestration/context-optimizer/latest-receipt.json",
|
|
108
|
-
workspace_hygiene:
|
|
109
|
-
".claude/cco/orchestration/ai-workspace-hygiene/latest-report.json",
|
|
110
|
-
outcome:
|
|
111
|
-
".claude/cco/orchestration/seamless-outcome/latest-outcome.json",
|
|
112
|
-
value_summary:
|
|
113
|
-
".claude/cco/orchestration/seamless-outcome/latest-value-summary.json",
|
|
114
|
-
reality_gate:
|
|
115
|
-
".claude/cco/orchestration/seamless-outcome/latest-reality-gate.json",
|
|
116
|
-
safe_path:
|
|
117
|
-
".claude/cco/security/safe-path/latest-receipt.json",
|
|
118
|
-
agent_access_governance:
|
|
119
|
-
".claude/cco/security/agent-access-governance/latest-receipt.json",
|
|
120
|
-
product_learning:
|
|
121
|
-
".claude/cco/events/product-learning.jsonl",
|
|
122
|
-
feedback_dir: ".claude/cco/feedback",
|
|
123
|
-
smart_route:
|
|
124
|
-
".claude/cco/orchestration/smart-work-routing/latest-route.json",
|
|
125
|
-
safe_run:
|
|
126
|
-
".claude/cco/orchestration/safe-run/latest-run.json",
|
|
127
|
-
// PR #140 — Hook Baseline + Lifecycle Automation Preview
|
|
128
|
-
hook_baseline:
|
|
129
|
-
".claude/cco/orchestration/hook-baseline/latest-baseline.json",
|
|
130
|
-
adapter_readiness:
|
|
131
|
-
".claude/cco/orchestration/adapter-readiness/latest-readiness.json",
|
|
132
|
-
hook_config_preview:
|
|
133
|
-
".claude/cco/orchestration/hook-baseline/latest-preview.json",
|
|
134
|
-
lifecycle_hook_session_start:
|
|
135
|
-
".claude/cco/orchestration/lifecycle-hooks/latest-sessionstart.json",
|
|
136
|
-
lifecycle_hook_pre_tool_use:
|
|
137
|
-
".claude/cco/orchestration/lifecycle-hooks/latest-pretooluse.json",
|
|
138
|
-
lifecycle_hook_stop:
|
|
139
|
-
".claude/cco/orchestration/lifecycle-hooks/latest-stop.json",
|
|
140
|
-
lifecycle_hook_session_end:
|
|
141
|
-
".claude/cco/orchestration/lifecycle-hooks/latest-sessionend.json",
|
|
142
|
-
// PR #141 — Explicit Hook Apply + Lifecycle Live
|
|
143
|
-
hook_apply:
|
|
144
|
-
".claude/cco/orchestration/hook-apply/latest-apply.json",
|
|
145
|
-
hook_doctor:
|
|
146
|
-
".claude/cco/orchestration/hook-apply/latest-doctor.json",
|
|
147
|
-
hook_rollback:
|
|
148
|
-
".claude/cco/orchestration/hook-apply/latest-rollback.json",
|
|
149
|
-
// PR #142 — Activation Alpha Readiness + First Value
|
|
150
|
-
alpha_activation:
|
|
151
|
-
".claude/cco/orchestration/activation/latest-activation.json",
|
|
152
|
-
alpha_readiness_gate:
|
|
153
|
-
".claude/cco/orchestration/alpha-readiness/latest-gate.json",
|
|
154
|
-
support_bundle:
|
|
155
|
-
".claude/cco/support/latest-support-bundle.json",
|
|
156
|
-
// PR #143 — Token Efficiency + Context Quality Hardening
|
|
157
|
-
token_efficiency_evidence:
|
|
158
|
-
".claude/cco/orchestration/token-efficiency/latest-evidence.json",
|
|
159
|
-
tool_output_sandbox:
|
|
160
|
-
".claude/cco/orchestration/tool-output/latest-summary.json",
|
|
161
|
-
repo_map:
|
|
162
|
-
".claude/cco/orchestration/repo-map/latest-map.json",
|
|
163
|
-
context_acquisition_plan:
|
|
164
|
-
".claude/cco/orchestration/context-acquisition/latest-plan.json",
|
|
165
|
-
cache_readiness:
|
|
166
|
-
".claude/cco/orchestration/cache-readiness/latest-readiness.json",
|
|
167
|
-
token_context_quality_gate:
|
|
168
|
-
".claude/cco/orchestration/token-efficiency/latest-quality-gate.json",
|
|
169
|
-
// PR #144
|
|
170
|
-
failure_recovery: ".claude/cco/orchestration/failure-recovery/latest-recovery.json",
|
|
171
|
-
launch_hardening_gate: ".claude/cco/orchestration/launch-hardening/latest-gate.json",
|
|
172
|
-
artifact_health: ".claude/cco/orchestration/artifact-health/latest-health.json",
|
|
173
|
-
artifact_cleanup: ".claude/cco/orchestration/artifact-health/latest-cleanup.json",
|
|
174
|
-
// PR #145 — MCP Least-Privilege Tool Governance v1
|
|
175
|
-
mcp_tool_inventory: ".claude/cco/orchestration/mcp-tool-governance/latest-inventory.json",
|
|
176
|
-
mcp_tool_risk: ".claude/cco/orchestration/mcp-tool-governance/latest-risk.json",
|
|
177
|
-
mcp_policy_preview: ".claude/cco/orchestration/mcp-tool-governance/latest-policy-preview.json",
|
|
178
|
-
mcp_pre_tool_use_decision: ".claude/cco/orchestration/mcp-tool-governance/latest-pretooluse-decision.json",
|
|
179
|
-
// PR #161 — Public Activation Distribution Truth v1
|
|
180
|
-
public_distribution_truth: ".claude/cco/orchestration/public-distribution/latest-truth.json",
|
|
181
|
-
package_content_audit: ".claude/cco/orchestration/public-distribution/latest-package-content-audit.json",
|
|
182
|
-
local_package_smoke: ".claude/cco/orchestration/public-distribution/latest-local-package-smoke.json",
|
|
183
|
-
public_install_claim_check: ".claude/cco/orchestration/public-distribution/latest-install-claim-check.json",
|
|
184
|
-
publish_provenance_readiness: ".claude/cco/orchestration/public-distribution/latest-publish-provenance-readiness.json",
|
|
185
|
-
public_activation_distribution_gate: ".claude/cco/orchestration/public-distribution/latest-gate.json",
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
function createRunId(input) {
|
|
189
|
-
const base = input
|
|
190
|
-
? `${input.slice(0, 40)}-${Date.now()}`
|
|
191
|
-
: `ledger-${Date.now()}`;
|
|
192
|
-
return `ledger-${crypto
|
|
193
|
-
.createHash("sha1")
|
|
194
|
-
.update(base)
|
|
195
|
-
.digest("hex")
|
|
196
|
-
.slice(0, 12)}`;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function safeReadJson(filePath) {
|
|
200
|
-
try {
|
|
201
|
-
if (!fs.existsSync(filePath)) return null;
|
|
202
|
-
const raw = fs.readFileSync(filePath, "utf8");
|
|
203
|
-
return JSON.parse(raw);
|
|
204
|
-
} catch {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function safeReadJsonl(filePath, limit = 200) {
|
|
210
|
-
try {
|
|
211
|
-
if (!fs.existsSync(filePath)) return null;
|
|
212
|
-
const raw = fs.readFileSync(filePath, "utf8");
|
|
213
|
-
const lines = raw
|
|
214
|
-
.split("\n")
|
|
215
|
-
.filter((l) => l.trim())
|
|
216
|
-
.slice(-limit);
|
|
217
|
-
const events = [];
|
|
218
|
-
for (const line of lines) {
|
|
219
|
-
try {
|
|
220
|
-
events.push(JSON.parse(line));
|
|
221
|
-
} catch {
|
|
222
|
-
// skip malformed line
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return events;
|
|
226
|
-
} catch {
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function readAvailableWorkArtifacts(cwd) {
|
|
232
|
-
const artifacts = {};
|
|
233
|
-
for (const [key, rel] of Object.entries(ARTIFACT_PATHS)) {
|
|
234
|
-
const full = path.join(cwd, rel);
|
|
235
|
-
if (key === "product_learning") {
|
|
236
|
-
artifacts[key] = { path: full, rel, exists: fs.existsSync(full) };
|
|
237
|
-
} else if (key === "feedback_dir") {
|
|
238
|
-
artifacts[key] = { path: full, rel, exists: fs.existsSync(full) };
|
|
239
|
-
} else {
|
|
240
|
-
artifacts[key] = { path: full, rel, exists: fs.existsSync(full) };
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return artifacts;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function normalizeLedgerEntry(type, source, artifactData, options = {}) {
|
|
247
|
-
const { evidencePath, evidenceKind = "receipt" } = options;
|
|
248
|
-
const entry = {
|
|
249
|
-
entryId: `entry-${crypto.randomBytes(4).toString("hex")}`,
|
|
250
|
-
type,
|
|
251
|
-
source,
|
|
252
|
-
stageId: options.stageId || null,
|
|
253
|
-
status: options.status || "unknown",
|
|
254
|
-
summary: options.summary || "not_available",
|
|
255
|
-
evidencePath: evidencePath || null,
|
|
256
|
-
evidenceKind,
|
|
257
|
-
valueSignals: options.valueSignals || [],
|
|
258
|
-
riskSignals: options.riskSignals || [],
|
|
259
|
-
qualitySignals: options.qualitySignals || [],
|
|
260
|
-
frictionSignals: options.frictionSignals || [],
|
|
261
|
-
nextAction: options.nextAction || null,
|
|
262
|
-
reasonCodes: options.reasonCodes || [],
|
|
263
|
-
timestamp: options.timestamp || new Date().toISOString(),
|
|
264
|
-
redacted: true,
|
|
265
|
-
};
|
|
266
|
-
return entry;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function readOrchestrationEntry(cwd, artifacts) {
|
|
270
|
-
const art = artifacts.orchestration_plan;
|
|
271
|
-
if (!art.exists) return null;
|
|
272
|
-
|
|
273
|
-
const data = safeReadJson(art.path);
|
|
274
|
-
if (!data) {
|
|
275
|
-
return normalizeLedgerEntry("orchestration", "work_aware_orchestration", null, {
|
|
276
|
-
status: "warn",
|
|
277
|
-
summary: "Orchestration plan file exists but could not be parsed.",
|
|
278
|
-
evidencePath: art.rel,
|
|
279
|
-
evidenceKind: "receipt",
|
|
280
|
-
frictionSignals: ["corrupted_receipt"],
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const stageCount = Array.isArray(data.stages) ? data.stages.length : 0;
|
|
285
|
-
const taskType = data.task?.taskType || "unknown";
|
|
286
|
-
const riskLevel = data.task?.riskLevel || "unknown";
|
|
287
|
-
const localStages = Array.isArray(data.stages)
|
|
288
|
-
? data.stages.filter((s) => s.workerSelection?.costTier === "free_local").length
|
|
289
|
-
: 0;
|
|
290
|
-
const handoffReady = data.stageHandoff?.ready === true;
|
|
291
|
-
const valueEvidence = data.valueEvidence || {};
|
|
292
|
-
|
|
293
|
-
const valueSignals = [];
|
|
294
|
-
if (localStages > 0) valueSignals.push(`${localStages} local/cheap stage(s)`);
|
|
295
|
-
if (handoffReady) valueSignals.push("handoff_prepared");
|
|
296
|
-
if (valueEvidence.manualDecisionsAvoided > 0)
|
|
297
|
-
valueSignals.push("manual_decisions_avoided");
|
|
298
|
-
if (valueEvidence.unknownAssetsExcluded > 0)
|
|
299
|
-
valueSignals.push("unknown_assets_excluded");
|
|
300
|
-
|
|
301
|
-
const riskSignals = [];
|
|
302
|
-
if (riskLevel === "high" || riskLevel === "critical") riskSignals.push(`task_risk_${riskLevel}`);
|
|
303
|
-
|
|
304
|
-
const frictionSignals = [];
|
|
305
|
-
const contextReasonCodes = Array.isArray(data.stages)
|
|
306
|
-
? data.stages.flatMap((s) => s.contextSelection?.reasonCodes || [])
|
|
307
|
-
: [];
|
|
308
|
-
if (contextReasonCodes.includes("NO_HYGIENE_REPORT"))
|
|
309
|
-
frictionSignals.push("no_hygiene_report_for_context");
|
|
310
|
-
if (contextReasonCodes.includes("INSPECT_MAP_FIRST"))
|
|
311
|
-
frictionSignals.push("inspect_before_context_selection");
|
|
312
|
-
|
|
313
|
-
return normalizeLedgerEntry("orchestration", "work_aware_orchestration", data, {
|
|
314
|
-
status: data.status || "pass",
|
|
315
|
-
summary: `Orchestration plan: ${stageCount} stage(s), task type ${taskType}, risk ${riskLevel}.`,
|
|
316
|
-
evidencePath: art.rel,
|
|
317
|
-
evidenceKind: "receipt",
|
|
318
|
-
stageId: "orchestration",
|
|
319
|
-
valueSignals,
|
|
320
|
-
riskSignals,
|
|
321
|
-
frictionSignals,
|
|
322
|
-
reasonCodes: [],
|
|
323
|
-
nextAction: data.nextAction || null,
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function readContextEntry(cwd, artifacts) {
|
|
328
|
-
const art = artifacts.context_receipt;
|
|
329
|
-
if (!art.exists) {
|
|
330
|
-
const packArt = artifacts.context_pack;
|
|
331
|
-
if (!packArt.exists) return null;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
const source = art.exists ? art : artifacts.context_pack;
|
|
335
|
-
const data = safeReadJson(source.path);
|
|
336
|
-
if (!data) return null;
|
|
337
|
-
|
|
338
|
-
const tokensSaved = data.tokensSaved || data.estimatedTokensAvoided || 0;
|
|
339
|
-
const filesSelected = data.filesSelected || data.selectedFiles?.length || 0;
|
|
340
|
-
const filesExcluded = data.filesExcluded || data.excludedFiles?.length || 0;
|
|
341
|
-
const broadScansAvoided = data.broadScansAvoided || 0;
|
|
342
|
-
|
|
343
|
-
const valueSignals = [];
|
|
344
|
-
if (tokensSaved > 0) valueSignals.push(`~${tokensSaved} context tokens saved (estimate)`);
|
|
345
|
-
if (broadScansAvoided > 0) valueSignals.push(`${broadScansAvoided} broad scan(s) avoided`);
|
|
346
|
-
if (filesExcluded > 0) valueSignals.push(`${filesExcluded} file(s) excluded`);
|
|
347
|
-
|
|
348
|
-
return normalizeLedgerEntry("context", "context_optimizer", data, {
|
|
349
|
-
status: data.status || "pass",
|
|
350
|
-
summary: `Context: ${filesSelected} file(s) selected, ${filesExcluded} excluded, ~${tokensSaved} tokens saved (estimate).`,
|
|
351
|
-
evidencePath: source.rel,
|
|
352
|
-
evidenceKind: "receipt",
|
|
353
|
-
valueSignals,
|
|
354
|
-
riskSignals: [],
|
|
355
|
-
frictionSignals: [],
|
|
356
|
-
reasonCodes: data.reasonCodes || [],
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function readWorkspaceHygieneEntry(cwd, artifacts) {
|
|
361
|
-
const art = artifacts.workspace_hygiene;
|
|
362
|
-
if (!art.exists) return null;
|
|
363
|
-
|
|
364
|
-
const data = safeReadJson(art.path);
|
|
365
|
-
if (!data) {
|
|
366
|
-
return normalizeLedgerEntry("workspace_hygiene", "ai_workspace_hygiene", null, {
|
|
367
|
-
status: "warn",
|
|
368
|
-
summary: "Workspace hygiene report exists but could not be parsed.",
|
|
369
|
-
evidencePath: art.rel,
|
|
370
|
-
frictionSignals: ["corrupted_receipt"],
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const score = data.score || 0;
|
|
375
|
-
const totalAssets = data.summary?.totalAssets || 0;
|
|
376
|
-
const highRisk = data.summary?.highRiskAssets || 0;
|
|
377
|
-
const needsReview = data.summary?.needsReviewAssets || 0;
|
|
378
|
-
const status = data.status || (score >= 80 ? "pass" : score >= 60 ? "warn" : "fail");
|
|
379
|
-
|
|
380
|
-
const valueSignals = [];
|
|
381
|
-
if (highRisk > 0) valueSignals.push(`${highRisk} high-risk asset(s) detected`);
|
|
382
|
-
if (needsReview > 0) valueSignals.push(`${needsReview} asset(s) need review`);
|
|
383
|
-
|
|
384
|
-
const riskSignals = [];
|
|
385
|
-
if (highRisk > 0) riskSignals.push(`high_risk_assets:${highRisk}`);
|
|
386
|
-
|
|
387
|
-
return normalizeLedgerEntry("workspace_hygiene", "ai_workspace_hygiene", data, {
|
|
388
|
-
status,
|
|
389
|
-
summary: `Workspace hygiene: score ${score}/100, ${totalAssets} asset(s), ${highRisk} high-risk.`,
|
|
390
|
-
evidencePath: art.rel,
|
|
391
|
-
evidenceKind: "receipt",
|
|
392
|
-
valueSignals,
|
|
393
|
-
riskSignals,
|
|
394
|
-
reasonCodes: data.topReasonCodes || [],
|
|
395
|
-
nextAction: data.nextAction || null,
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function readOutcomeEntry(cwd, artifacts) {
|
|
400
|
-
const vsArt = artifacts.value_summary;
|
|
401
|
-
const outArt = artifacts.outcome;
|
|
402
|
-
|
|
403
|
-
const art = vsArt.exists ? vsArt : outArt.exists ? outArt : null;
|
|
404
|
-
if (!art) return null;
|
|
405
|
-
|
|
406
|
-
const data = safeReadJson(art.path);
|
|
407
|
-
if (!data) return null;
|
|
408
|
-
|
|
409
|
-
const completed = data.completed || {};
|
|
410
|
-
const saved = data.saved || {};
|
|
411
|
-
const protected_ = data.protected || {};
|
|
412
|
-
const verified = data.verified || {};
|
|
413
|
-
const quality = data.quality || {};
|
|
414
|
-
const evidenceBacked = data.evidenceBacked !== false;
|
|
415
|
-
|
|
416
|
-
const valueSignals = [];
|
|
417
|
-
if (completed.completedItems > 0)
|
|
418
|
-
valueSignals.push(`${completed.completedItems} completed`);
|
|
419
|
-
if (completed.preparedItems > 0)
|
|
420
|
-
valueSignals.push(`${completed.preparedItems} prepared`);
|
|
421
|
-
if (saved.localStagesUsed > 0)
|
|
422
|
-
valueSignals.push(`${saved.localStagesUsed} local stage(s) used`);
|
|
423
|
-
if (protected_.unsafeActionsBlocked > 0)
|
|
424
|
-
valueSignals.push(`${protected_.unsafeActionsBlocked} unsafe action(s) blocked`);
|
|
425
|
-
if (verified.testsRun > 0)
|
|
426
|
-
valueSignals.push(`${verified.testsRun} test(s) run`);
|
|
427
|
-
|
|
428
|
-
const frictionSignals = [];
|
|
429
|
-
if (!evidenceBacked) frictionSignals.push("value_summary_not_evidence_backed");
|
|
430
|
-
if (completed.status === "unknown") frictionSignals.push("completion_status_unknown");
|
|
431
|
-
|
|
432
|
-
return normalizeLedgerEntry("outcome", "seamless_outcome", data, {
|
|
433
|
-
status: data.status || "pass",
|
|
434
|
-
summary: `Outcome: ${completed.completedItems || 0} completed, ${saved.localStagesUsed || 0} local stages, ${protected_.unsafeActionsBlocked || 0} blocked.`,
|
|
435
|
-
evidencePath: art.rel,
|
|
436
|
-
evidenceKind: "receipt",
|
|
437
|
-
valueSignals,
|
|
438
|
-
frictionSignals,
|
|
439
|
-
reasonCodes: data.caveats || [],
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
function readRealityGateEntry(cwd, artifacts) {
|
|
444
|
-
const art = artifacts.reality_gate;
|
|
445
|
-
if (!art.exists) return null;
|
|
446
|
-
|
|
447
|
-
const data = safeReadJson(art.path);
|
|
448
|
-
if (!data) return null;
|
|
449
|
-
|
|
450
|
-
const score = data.score || 0;
|
|
451
|
-
const summary = data.summary || {};
|
|
452
|
-
const status = data.status || "unknown";
|
|
453
|
-
|
|
454
|
-
const qualitySignals = [];
|
|
455
|
-
if (summary.pass > 0) qualitySignals.push(`${summary.pass} check(s) passed`);
|
|
456
|
-
if (summary.warn > 0) qualitySignals.push(`${summary.warn} warning(s)`);
|
|
457
|
-
if (summary.fail > 0) qualitySignals.push(`${summary.fail} failure(s)`);
|
|
458
|
-
|
|
459
|
-
const frictionSignals = [];
|
|
460
|
-
if (summary.fail > 0) frictionSignals.push(`reality_gate_failures:${summary.fail}`);
|
|
461
|
-
if (summary.warn > 0) frictionSignals.push(`reality_gate_warnings:${summary.warn}`);
|
|
462
|
-
|
|
463
|
-
return normalizeLedgerEntry("reality_gate", "seamless_reality_gate", data, {
|
|
464
|
-
status,
|
|
465
|
-
summary: `Reality Gate: ${score}/100 — ${summary.pass || 0} pass, ${summary.warn || 0} warn, ${summary.fail || 0} fail.`,
|
|
466
|
-
evidencePath: art.rel,
|
|
467
|
-
evidenceKind: "receipt",
|
|
468
|
-
qualitySignals,
|
|
469
|
-
frictionSignals,
|
|
470
|
-
nextAction: data.gaps?.[0]?.nextAction || null,
|
|
471
|
-
reasonCodes: (data.gaps || []).map((g) => g.id).slice(0, 5),
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
function readGuardEntry(cwd, artifacts) {
|
|
476
|
-
const art = artifacts.safe_path;
|
|
477
|
-
if (!art.exists) return null;
|
|
478
|
-
|
|
479
|
-
const data = safeReadJson(art.path);
|
|
480
|
-
if (!data) return null;
|
|
481
|
-
|
|
482
|
-
const decision = data.lastDecision || data.decision || "unknown";
|
|
483
|
-
const blocked = decision === "block" ? 1 : 0;
|
|
484
|
-
const reductions = data.reductionsApplied || data.reductionsRecommended || 0;
|
|
485
|
-
|
|
486
|
-
const riskSignals = [];
|
|
487
|
-
if (blocked > 0) riskSignals.push("unsafe_action_blocked");
|
|
488
|
-
if ((data.topReasonCodes || []).includes("DESTRUCTIVE_COMMAND"))
|
|
489
|
-
riskSignals.push("destructive_command_detected");
|
|
490
|
-
if ((data.topReasonCodes || []).includes("DEPLOYMENT_CONFIG"))
|
|
491
|
-
riskSignals.push("deployment_config_access_guarded");
|
|
492
|
-
|
|
493
|
-
const valueSignals = [];
|
|
494
|
-
if (reductions > 0) valueSignals.push(`${reductions} reduction(s) applied`);
|
|
495
|
-
if (blocked > 0) valueSignals.push("unsafe_action_blocked");
|
|
496
|
-
|
|
497
|
-
return normalizeLedgerEntry("guard", "safe_path", data, {
|
|
498
|
-
status: "pass",
|
|
499
|
-
summary: `Safe Path: last decision ${decision}, ${reductions} reduction(s).`,
|
|
500
|
-
evidencePath: art.rel,
|
|
501
|
-
evidenceKind: "receipt",
|
|
502
|
-
riskSignals,
|
|
503
|
-
valueSignals,
|
|
504
|
-
reasonCodes: data.topReasonCodes || [],
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function readAgentAccessEntry(cwd, artifacts) {
|
|
509
|
-
const art = artifacts.agent_access_governance;
|
|
510
|
-
if (!art.exists) return null;
|
|
511
|
-
|
|
512
|
-
const data = safeReadJson(art.path);
|
|
513
|
-
if (!data) return null;
|
|
514
|
-
|
|
515
|
-
const unknownSubjects = data.unknownSubjects || 0;
|
|
516
|
-
const status = data.status || "foundation";
|
|
517
|
-
|
|
518
|
-
const riskSignals = [];
|
|
519
|
-
if (unknownSubjects > 0) riskSignals.push(`unknown_subjects:${unknownSubjects}`);
|
|
520
|
-
|
|
521
|
-
return normalizeLedgerEntry("guard", "agent_access_governance", data, {
|
|
522
|
-
status: status === "pass" ? "pass" : "warn",
|
|
523
|
-
summary: `Agent Access Governance: status ${status}, ${unknownSubjects} unknown subject(s).`,
|
|
524
|
-
evidencePath: art.rel,
|
|
525
|
-
evidenceKind: "receipt",
|
|
526
|
-
riskSignals,
|
|
527
|
-
reasonCodes: data.topReasonCodes || [],
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function readProductLearningEntry(cwd, artifacts) {
|
|
532
|
-
const art = artifacts.product_learning;
|
|
533
|
-
if (!art.exists) return null;
|
|
534
|
-
|
|
535
|
-
const events = safeReadJsonl(art.path, 500);
|
|
536
|
-
if (!events || events.length === 0) return null;
|
|
537
|
-
|
|
538
|
-
const eventCounts = {};
|
|
539
|
-
const categories = {};
|
|
540
|
-
for (const ev of events) {
|
|
541
|
-
const name = ev.eventName || "unknown";
|
|
542
|
-
eventCounts[name] = (eventCounts[name] || 0) + 1;
|
|
543
|
-
const cat = ev.category || "unknown";
|
|
544
|
-
categories[cat] = (categories[cat] || 0) + 1;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
const topEvents = Object.entries(eventCounts)
|
|
548
|
-
.sort((a, b) => b[1] - a[1])
|
|
549
|
-
.slice(0, 5)
|
|
550
|
-
.map(([n, c]) => `${n}:${c}`);
|
|
551
|
-
|
|
552
|
-
return normalizeLedgerEntry("product_learning", "product_learning_events", null, {
|
|
553
|
-
status: "pass",
|
|
554
|
-
summary: `Product Learning: ${events.length} event(s). Top: ${topEvents.slice(0, 3).join(", ")}.`,
|
|
555
|
-
evidencePath: art.rel,
|
|
556
|
-
evidenceKind: "jsonl",
|
|
557
|
-
valueSignals: [`${events.length} events recorded`],
|
|
558
|
-
frictionSignals: [],
|
|
559
|
-
reasonCodes: [],
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
function readSmartRouteEntry(cwd, artifacts) {
|
|
564
|
-
const art = artifacts.smart_route;
|
|
565
|
-
if (!art || !art.exists) return null;
|
|
566
|
-
|
|
567
|
-
const data = safeReadJson(art.path);
|
|
568
|
-
if (!data) return null;
|
|
569
|
-
|
|
570
|
-
const decision = data.decision || "unknown";
|
|
571
|
-
const pathType = (data.executionPath && data.executionPath.pathType) || "unknown";
|
|
572
|
-
const reasonCodes = (data.executionPath && data.executionPath.reasonCodes) || [];
|
|
573
|
-
const proofRequired = (data.executionPath && data.executionPath.proofRequired) || false;
|
|
574
|
-
const sameSurfacePreferred = (data.executionPath && data.executionPath.sameSurfacePreferred) !== false;
|
|
575
|
-
|
|
576
|
-
const valueSignals = [];
|
|
577
|
-
if (pathType === "local_or_cheap" || pathType === "local_deterministic") {
|
|
578
|
-
valueSignals.push("local_or_cheap_path_selected");
|
|
579
|
-
}
|
|
580
|
-
if (sameSurfacePreferred) valueSignals.push("same_surface_preferred");
|
|
581
|
-
|
|
582
|
-
const riskSignals = [];
|
|
583
|
-
if (reasonCodes.includes("DESTRUCTIVE_ACTION_BLOCKED")) riskSignals.push("destructive_action_blocked");
|
|
584
|
-
if (reasonCodes.includes("SECRETS_EXCLUDED_FROM_CONTEXT")) riskSignals.push("secrets_excluded");
|
|
585
|
-
if (reasonCodes.includes("DEPLOY_REQUIRES_APPROVAL")) riskSignals.push("deploy_approval_required");
|
|
586
|
-
if (reasonCodes.includes("EXTERNAL_AGENT_REQUIRES_APPROVAL")) riskSignals.push("remote_agent_blocked");
|
|
587
|
-
|
|
588
|
-
return normalizeLedgerEntry("smart_route", "smart_work_routing", data, {
|
|
589
|
-
status: decision === "blocked" ? "warn" : "pass",
|
|
590
|
-
summary: `Smart route: decision=${decision}, path=${pathType}, proof=${proofRequired ? "required" : "optional"}.`,
|
|
591
|
-
evidencePath: art.rel,
|
|
592
|
-
evidenceKind: "receipt",
|
|
593
|
-
valueSignals,
|
|
594
|
-
riskSignals,
|
|
595
|
-
reasonCodes: reasonCodes.slice(0, 5),
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function readSafeRunEntry(cwd, artifacts) {
|
|
600
|
-
const art = artifacts.safe_run;
|
|
601
|
-
if (!art || !art.exists) return null;
|
|
602
|
-
|
|
603
|
-
const data = safeReadJson(art.path);
|
|
604
|
-
if (!data) return null;
|
|
605
|
-
|
|
606
|
-
const decision = data.decision || "prepared";
|
|
607
|
-
const localStepsRun = (data.executionSummary && data.executionSummary.localStepsRun) || 0;
|
|
608
|
-
const localStepsPassed = (data.executionSummary && data.executionSummary.localStepsPassed) || 0;
|
|
609
|
-
|
|
610
|
-
const valueSignals = [];
|
|
611
|
-
if (localStepsPassed > 0) valueSignals.push(`${localStepsPassed} local proof step(s) passed`);
|
|
612
|
-
if (data.safety && data.safety.deployBlocked) valueSignals.push("deploy_blocked");
|
|
613
|
-
if (data.safety && data.safety.secretsExcluded) valueSignals.push("secrets_excluded");
|
|
614
|
-
if (data.safety && data.safety.remoteAgentExecutionBlocked) valueSignals.push("remote_agent_execution_blocked");
|
|
615
|
-
|
|
616
|
-
const frictionSignals = [];
|
|
617
|
-
if (decision === "approval_required") frictionSignals.push("approval_required");
|
|
618
|
-
if (decision === "blocked") frictionSignals.push("task_blocked");
|
|
619
|
-
const failed = (data.executionSummary && data.executionSummary.localStepsFailed) || 0;
|
|
620
|
-
if (failed > 0) frictionSignals.push(`local_steps_failed:${failed}`);
|
|
621
|
-
|
|
622
|
-
return normalizeLedgerEntry("safe_run", "safe_run_controller", data, {
|
|
623
|
-
// blocked/approval_required = safety working correctly (warn), not a failure
|
|
624
|
-
status: decision === "verified" ? "pass" : "warn",
|
|
625
|
-
summary: `Safe run: decision=${decision}, localStepsRun=${localStepsRun}.`,
|
|
626
|
-
evidencePath: art.rel,
|
|
627
|
-
evidenceKind: "receipt",
|
|
628
|
-
valueSignals,
|
|
629
|
-
frictionSignals,
|
|
630
|
-
reasonCodes: [],
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function readFeedbackEntries(cwd, artifacts) {
|
|
635
|
-
const art = artifacts.feedback_dir;
|
|
636
|
-
if (!art.exists) return [];
|
|
637
|
-
|
|
638
|
-
const entries = [];
|
|
639
|
-
try {
|
|
640
|
-
const files = fs.readdirSync(art.path).filter((f) => f.endsWith(".json"));
|
|
641
|
-
for (const f of files.slice(0, 20)) {
|
|
642
|
-
const filePath = path.join(art.path, f);
|
|
643
|
-
const data = safeReadJson(filePath);
|
|
644
|
-
if (!data) continue;
|
|
645
|
-
entries.push(
|
|
646
|
-
normalizeLedgerEntry("feedback", data.source || "manual", data, {
|
|
647
|
-
status: "pass",
|
|
648
|
-
summary: data.summary
|
|
649
|
-
? data.summary.slice(0, 120)
|
|
650
|
-
: "Feedback signal loaded.",
|
|
651
|
-
evidencePath: path.join(art.rel, f),
|
|
652
|
-
evidenceKind: "feedback",
|
|
653
|
-
frictionSignals: data.frictionType ? [data.frictionType] : [],
|
|
654
|
-
reasonCodes: data.frictionType ? [data.frictionType] : [],
|
|
655
|
-
})
|
|
656
|
-
);
|
|
657
|
-
}
|
|
658
|
-
} catch {
|
|
659
|
-
// skip feedback dir read errors
|
|
660
|
-
}
|
|
661
|
-
return entries;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
function readHookBaselineEntry(cwd, artifacts) {
|
|
665
|
-
const art = artifacts.hook_baseline;
|
|
666
|
-
if (!art || !art.exists) return null;
|
|
667
|
-
const data = safeReadJson(art.path);
|
|
668
|
-
if (!data) return null;
|
|
669
|
-
return normalizeLedgerEntry("hook_baseline", "hook_baseline", data, {
|
|
670
|
-
status: "pass",
|
|
671
|
-
summary: `Hook baseline: ${data.hookCount || 0} events registered. Install status: ${data.installStatus || "preview_only"}.`,
|
|
672
|
-
evidencePath: art.rel,
|
|
673
|
-
evidenceKind: "receipt",
|
|
674
|
-
valueSignals: ["hook_baseline_ready", "lifecycle_automation_prepared"],
|
|
675
|
-
frictionSignals: data.installStatus === "preview_only" ? ["hooks_not_yet_installed"] : [],
|
|
676
|
-
reasonCodes: ["HOOK_BASELINE_BUILT"],
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
function readAdapterReadinessEntry(cwd, artifacts) {
|
|
681
|
-
const art = artifacts.adapter_readiness;
|
|
682
|
-
if (!art || !art.exists) return null;
|
|
683
|
-
const data = safeReadJson(art.path);
|
|
684
|
-
if (!data) return null;
|
|
685
|
-
const detectedCount = (data.hosts || []).filter((h) => h.detected && !h.fallback).length;
|
|
686
|
-
return normalizeLedgerEntry("adapter_readiness", "adapter_readiness", data, {
|
|
687
|
-
status: data.status === "needs_review" ? "warn" : "pass",
|
|
688
|
-
summary: `Adapter readiness: ${data.status}. ${detectedCount} host(s) detected.`,
|
|
689
|
-
evidencePath: art.rel,
|
|
690
|
-
evidenceKind: "receipt",
|
|
691
|
-
valueSignals: detectedCount > 0 ? ["host_adapter_detected"] : ["generic_cli_fallback_available"],
|
|
692
|
-
frictionSignals: data.status === "needs_review" ? ["adapter_config_needs_review"] : [],
|
|
693
|
-
reasonCodes: ["ADAPTER_READINESS_DETECTED"],
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
function readHookConfigPreviewEntry(cwd, artifacts) {
|
|
698
|
-
const art = artifacts.hook_config_preview;
|
|
699
|
-
if (!art || !art.exists) return null;
|
|
700
|
-
const data = safeReadJson(art.path);
|
|
701
|
-
if (!data) return null;
|
|
702
|
-
return normalizeLedgerEntry("hook_config_preview", "hook_config_preview", data, {
|
|
703
|
-
status: "pass",
|
|
704
|
-
summary: `Hook config preview: mode=${data.mode || "preview_only"}. No user config modified. Approval required.`,
|
|
705
|
-
evidencePath: art.rel,
|
|
706
|
-
evidenceKind: "receipt",
|
|
707
|
-
valueSignals: ["hook_config_preview_ready"],
|
|
708
|
-
frictionSignals: ["hooks_not_yet_applied"],
|
|
709
|
-
reasonCodes: ["HOOK_CONFIG_PREVIEW_GENERATED"],
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function readHookApplyEntry(cwd, artifacts) {
|
|
714
|
-
const art = artifacts.hook_apply;
|
|
715
|
-
if (!art || !art.exists) return null;
|
|
716
|
-
const data = safeReadJson(art.path);
|
|
717
|
-
if (!data) return null;
|
|
718
|
-
const isApplied = data.applied === true;
|
|
719
|
-
const isRolledBack = data.status === "rolled_back";
|
|
720
|
-
const isUninstalled = data.status === "uninstalled";
|
|
721
|
-
const isDryRun = data.status === "dry_run";
|
|
722
|
-
return normalizeLedgerEntry("hook_apply", "hook_apply", data, {
|
|
723
|
-
status: isApplied ? "pass" : isDryRun ? "pass" : "warn",
|
|
724
|
-
summary: `Hook apply: status=${data.status}. Hosts applied: ${(data.hostsApplied || []).map((h) => h.host).join(", ") || "none"}.`,
|
|
725
|
-
evidencePath: art.rel,
|
|
726
|
-
evidenceKind: "receipt",
|
|
727
|
-
valueSignals: isApplied ? ["hooks_applied", "lifecycle_live"] : isDryRun ? ["hook_apply_dry_run_ready"] : [],
|
|
728
|
-
frictionSignals: !isApplied && !isDryRun && !isRolledBack && !isUninstalled
|
|
729
|
-
? ["hooks_not_yet_applied"]
|
|
730
|
-
: [],
|
|
731
|
-
reasonCodes: isApplied ? ["HOOKS_APPLIED", "LIFECYCLE_LIVE"]
|
|
732
|
-
: isRolledBack ? ["HOOKS_ROLLED_BACK"]
|
|
733
|
-
: isUninstalled ? ["HOOKS_UNINSTALLED"]
|
|
734
|
-
: isDryRun ? ["DRY_RUN_ONLY"]
|
|
735
|
-
: ["APPROVAL_REQUIRED"],
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
function readHookDoctorEntry(cwd, artifacts) {
|
|
740
|
-
const art = artifacts.hook_doctor;
|
|
741
|
-
if (!art || !art.exists) return null;
|
|
742
|
-
const data = safeReadJson(art.path);
|
|
743
|
-
if (!data) return null;
|
|
744
|
-
return normalizeLedgerEntry("hook_doctor", "hook_doctor", data, {
|
|
745
|
-
status: data.status === "pass" ? "pass" : data.status === "warn" ? "warn" : "warn",
|
|
746
|
-
summary: `Hook doctor: ${data.status}. pass=${data.summary?.pass || 0} warn=${data.summary?.warn || 0} fail=${data.summary?.fail || 0}.`,
|
|
747
|
-
evidencePath: art.rel,
|
|
748
|
-
evidenceKind: "receipt",
|
|
749
|
-
valueSignals: data.status === "pass" ? ["lifecycle_live_smoke_passed"] : [],
|
|
750
|
-
frictionSignals: data.status !== "pass" ? ["hook_doctor_needs_attention"] : [],
|
|
751
|
-
reasonCodes: ["HOOK_DOCTOR_RUN"],
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
// PR #142 — Activation Alpha Readiness + First Value
|
|
756
|
-
function readAlphaActivationEntry(cwd, artifacts) {
|
|
757
|
-
const art = artifacts.alpha_activation;
|
|
758
|
-
if (!art || !art.exists) return null;
|
|
759
|
-
const data = safeReadJson(art.path);
|
|
760
|
-
if (!data) return null;
|
|
761
|
-
const checksPass = (data.checks || []).filter((c) => c.status === "pass").length;
|
|
762
|
-
const checksWarn = (data.checks || []).filter((c) => c.status === "warn").length;
|
|
763
|
-
const checksFail = (data.checks || []).filter((c) => c.status === "fail").length;
|
|
764
|
-
return normalizeLedgerEntry("alpha_activation", "alpha_activation", data, {
|
|
765
|
-
status: data.status === "ready" ? "pass" : data.status === "blocked" ? "fail" : "warn",
|
|
766
|
-
summary: `Alpha activation: ${data.status}. Stage: ${data.activationStage || "unknown"}. Checks: ${checksPass} pass, ${checksWarn} warn, ${checksFail} fail.`,
|
|
767
|
-
evidencePath: art.rel,
|
|
768
|
-
evidenceKind: "receipt",
|
|
769
|
-
valueSignals: data.status === "ready" ? ["activation_ready"] : [],
|
|
770
|
-
frictionSignals: data.status !== "ready" ? [`activation_${data.status}`] : [],
|
|
771
|
-
reasonCodes: ["ALPHA_ACTIVATION_CHECKED"],
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
function readAlphaReadinessGateEntry(cwd, artifacts) {
|
|
776
|
-
const art = artifacts.alpha_readiness_gate;
|
|
777
|
-
if (!art || !art.exists) return null;
|
|
778
|
-
const data = safeReadJson(art.path);
|
|
779
|
-
if (!data) return null;
|
|
780
|
-
return normalizeLedgerEntry("alpha_readiness_gate", "alpha_readiness_gate", data, {
|
|
781
|
-
status: data.status === "pass" ? "pass" : data.status === "fail" ? "fail" : "warn",
|
|
782
|
-
summary: `Alpha readiness gate: ${data.status} (score: ${data.score || 0}/100). pass=${data.summary?.pass || 0} warn=${data.summary?.warn || 0} fail=${data.summary?.fail || 0}.`,
|
|
783
|
-
evidencePath: art.rel,
|
|
784
|
-
evidenceKind: "receipt",
|
|
785
|
-
valueSignals: data.status === "pass" ? ["alpha_readiness_confirmed"] : [],
|
|
786
|
-
frictionSignals: data.status !== "pass" ? ["alpha_readiness_incomplete"] : [],
|
|
787
|
-
reasonCodes: ["ALPHA_READINESS_GATE_RUN"],
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
function readSupportBundleEntry(cwd, artifacts) {
|
|
792
|
-
const art = artifacts.support_bundle;
|
|
793
|
-
if (!art || !art.exists) return null;
|
|
794
|
-
const data = safeReadJson(art.path);
|
|
795
|
-
if (!data) return null;
|
|
796
|
-
return normalizeLedgerEntry("support_bundle", "support_bundle", data, {
|
|
797
|
-
status: data.status === "ready" ? "pass" : "warn",
|
|
798
|
-
summary: `Support bundle: ${data.status}. ${data.summary?.artifactsAvailable || 0} artifacts, ${data.summary?.feedbackItems || 0} feedback items.`,
|
|
799
|
-
evidencePath: art.rel,
|
|
800
|
-
evidenceKind: "receipt",
|
|
801
|
-
valueSignals: ["support_bundle_available"],
|
|
802
|
-
frictionSignals: [],
|
|
803
|
-
reasonCodes: ["SUPPORT_BUNDLE_GENERATED"],
|
|
804
|
-
});
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
function buildWorkLedger(cwd, options = {}) {
|
|
808
|
-
const runId = createRunId(options.runIdInput || cwd);
|
|
809
|
-
const artifacts = readAvailableWorkArtifacts(cwd);
|
|
810
|
-
const entries = [];
|
|
811
|
-
const warnings = [];
|
|
812
|
-
|
|
813
|
-
const readers = [
|
|
814
|
-
() => readOrchestrationEntry(cwd, artifacts),
|
|
815
|
-
() => readContextEntry(cwd, artifacts),
|
|
816
|
-
() => readWorkspaceHygieneEntry(cwd, artifacts),
|
|
817
|
-
() => readGuardEntry(cwd, artifacts),
|
|
818
|
-
() => readAgentAccessEntry(cwd, artifacts),
|
|
819
|
-
() => readSmartRouteEntry(cwd, artifacts),
|
|
820
|
-
() => readSafeRunEntry(cwd, artifacts),
|
|
821
|
-
() => readOutcomeEntry(cwd, artifacts),
|
|
822
|
-
() => readRealityGateEntry(cwd, artifacts),
|
|
823
|
-
() => readProductLearningEntry(cwd, artifacts),
|
|
824
|
-
// PR #140 — Hook Baseline + Lifecycle Automation Preview
|
|
825
|
-
() => readHookBaselineEntry(cwd, artifacts),
|
|
826
|
-
() => readAdapterReadinessEntry(cwd, artifacts),
|
|
827
|
-
() => readHookConfigPreviewEntry(cwd, artifacts),
|
|
828
|
-
// PR #141 — Explicit Hook Apply + Lifecycle Live
|
|
829
|
-
() => readHookApplyEntry(cwd, artifacts),
|
|
830
|
-
() => readHookDoctorEntry(cwd, artifacts),
|
|
831
|
-
// PR #142 — Activation Alpha Readiness + First Value
|
|
832
|
-
() => readAlphaActivationEntry(cwd, artifacts),
|
|
833
|
-
() => readAlphaReadinessGateEntry(cwd, artifacts),
|
|
834
|
-
() => readSupportBundleEntry(cwd, artifacts),
|
|
835
|
-
];
|
|
836
|
-
|
|
837
|
-
for (const reader of readers) {
|
|
838
|
-
try {
|
|
839
|
-
const entry = reader();
|
|
840
|
-
if (entry) entries.push(entry);
|
|
841
|
-
} catch (err) {
|
|
842
|
-
warnings.push(`Reader error: ${err.message}`);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
const feedbackEntries = readFeedbackEntries(cwd, artifacts);
|
|
847
|
-
entries.push(...feedbackEntries);
|
|
848
|
-
|
|
849
|
-
// Rollup
|
|
850
|
-
const completed = [];
|
|
851
|
-
const saved = [];
|
|
852
|
-
const protected_ = [];
|
|
853
|
-
const verified = [];
|
|
854
|
-
const quality = [];
|
|
855
|
-
const friction = [];
|
|
856
|
-
const feedbackSummary = [];
|
|
857
|
-
|
|
858
|
-
for (const e of entries) {
|
|
859
|
-
if ((e.type === "orchestration" || e.type === "smart_route" || e.type === "safe_run") && e.status !== "warn" && e.status !== "fail") {
|
|
860
|
-
completed.push(e.summary);
|
|
861
|
-
}
|
|
862
|
-
for (const v of e.valueSignals || []) {
|
|
863
|
-
if (
|
|
864
|
-
v.includes("token") ||
|
|
865
|
-
v.includes("local") ||
|
|
866
|
-
v.includes("avoided") ||
|
|
867
|
-
v.includes("excluded")
|
|
868
|
-
) {
|
|
869
|
-
saved.push(v);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
for (const r of e.riskSignals || []) {
|
|
873
|
-
protected_.push(r);
|
|
874
|
-
}
|
|
875
|
-
if (e.type === "reality_gate") {
|
|
876
|
-
for (const q of e.qualitySignals || []) {
|
|
877
|
-
verified.push(q);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
if (e.type === "outcome") {
|
|
881
|
-
for (const v of e.valueSignals || []) {
|
|
882
|
-
if (v.includes("test")) verified.push(v);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
if (e.type === "workspace_hygiene" || e.type === "orchestration") {
|
|
886
|
-
for (const q of e.qualitySignals || []) quality.push(q);
|
|
887
|
-
}
|
|
888
|
-
for (const f of e.frictionSignals || []) {
|
|
889
|
-
friction.push(f);
|
|
890
|
-
}
|
|
891
|
-
if (e.type === "feedback") {
|
|
892
|
-
feedbackSummary.push(e.summary);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
const gateEntry = entries.find((e) => e.type === "reality_gate");
|
|
897
|
-
const nextAction =
|
|
898
|
-
gateEntry?.nextAction ||
|
|
899
|
-
entries.find((e) => e.nextAction)?.nextAction ||
|
|
900
|
-
"Run node bin/avorelo outcome to see current state.";
|
|
901
|
-
|
|
902
|
-
const rollup = {
|
|
903
|
-
completed: completed.length > 0 ? completed : ["not_available"],
|
|
904
|
-
saved: [...new Set(saved)].slice(0, 8),
|
|
905
|
-
protected: [...new Set(protected_)].slice(0, 8),
|
|
906
|
-
verified: [...new Set(verified)].slice(0, 8),
|
|
907
|
-
quality: [...new Set(quality)].slice(0, 8),
|
|
908
|
-
friction: [...new Set(friction)].slice(0, 10),
|
|
909
|
-
feedback: feedbackSummary.slice(0, 5),
|
|
910
|
-
nextAction,
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
const existingPaths = Object.values(artifacts)
|
|
914
|
-
.filter((a) => a.exists && a.rel && !a.rel.endsWith("/"))
|
|
915
|
-
.map((a) => a.rel);
|
|
916
|
-
|
|
917
|
-
const plEventArt = artifacts.product_learning;
|
|
918
|
-
const plEvents = plEventArt.exists ? safeReadJsonl(plEventArt.path, 500) : null;
|
|
919
|
-
const eventCounts = {};
|
|
920
|
-
if (plEvents) {
|
|
921
|
-
for (const ev of plEvents) {
|
|
922
|
-
const name = ev.eventName || "unknown";
|
|
923
|
-
eventCounts[name] = (eventCounts[name] || 0) + 1;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
const feedbackArt = artifacts.feedback_dir;
|
|
928
|
-
const feedbackPaths = [];
|
|
929
|
-
if (feedbackArt.exists) {
|
|
930
|
-
try {
|
|
931
|
-
const files = fs.readdirSync(feedbackArt.path).filter((f) => f.endsWith(".json"));
|
|
932
|
-
feedbackPaths.push(...files.map((f) => path.join(feedbackArt.rel, f)));
|
|
933
|
-
} catch {
|
|
934
|
-
// ignore
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
const overallStatus =
|
|
939
|
-
entries.some((e) => e.status === "fail")
|
|
940
|
-
? "fail"
|
|
941
|
-
: entries.some((e) => e.status === "warn")
|
|
942
|
-
? "warn"
|
|
943
|
-
: entries.length === 0
|
|
944
|
-
? "empty"
|
|
945
|
-
: "pass";
|
|
946
|
-
|
|
947
|
-
const ledger = {
|
|
948
|
-
contract: CONTRACT,
|
|
949
|
-
schemaVersion: SCHEMA_VERSION,
|
|
950
|
-
runId,
|
|
951
|
-
status: overallStatus,
|
|
952
|
-
createdAt: new Date().toISOString(),
|
|
953
|
-
updatedAt: new Date().toISOString(),
|
|
954
|
-
entries,
|
|
955
|
-
rollup,
|
|
956
|
-
evidence: {
|
|
957
|
-
receiptPaths: existingPaths,
|
|
958
|
-
eventCounts,
|
|
959
|
-
dogfoodPaths: [],
|
|
960
|
-
feedbackPaths,
|
|
961
|
-
},
|
|
962
|
-
caveats: [
|
|
963
|
-
"Savings and token estimates are approximations based on receipt data.",
|
|
964
|
-
"Absent receipts produce not_available entries.",
|
|
965
|
-
warnings.length > 0 ? `Reader warnings: ${warnings.join("; ")}` : null,
|
|
966
|
-
].filter(Boolean),
|
|
967
|
-
warnings: warnings.length > 0 ? warnings : undefined,
|
|
968
|
-
redacted: true,
|
|
969
|
-
};
|
|
970
|
-
|
|
971
|
-
return ledger;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
function writeWorkLedger(cwd, ledger) {
|
|
975
|
-
const dir = path.join(cwd, LEDGER_DIR_REL);
|
|
976
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
977
|
-
const filePath = path.join(cwd, LATEST_LEDGER_REL);
|
|
978
|
-
fs.writeFileSync(filePath, JSON.stringify(ledger, null, 2), "utf8");
|
|
979
|
-
return filePath;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
function buildWorkLedgerSurface(cwd) {
|
|
983
|
-
const ledgerPath = path.join(cwd, LATEST_LEDGER_REL);
|
|
984
|
-
if (!fs.existsSync(ledgerPath)) {
|
|
985
|
-
return {
|
|
986
|
-
status: "not_available",
|
|
987
|
-
latestLedgerPath: LATEST_LEDGER_REL,
|
|
988
|
-
entryCount: 0,
|
|
989
|
-
completedCount: 0,
|
|
990
|
-
frictionCount: 0,
|
|
991
|
-
nextAction: "Run node bin/avorelo ledger to generate.",
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
const data = safeReadJson(ledgerPath);
|
|
995
|
-
if (!data) {
|
|
996
|
-
return {
|
|
997
|
-
status: "warn",
|
|
998
|
-
latestLedgerPath: LATEST_LEDGER_REL,
|
|
999
|
-
entryCount: 0,
|
|
1000
|
-
completedCount: 0,
|
|
1001
|
-
frictionCount: 0,
|
|
1002
|
-
nextAction: "Ledger file corrupt. Re-run node bin/avorelo ledger.",
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
const completedCount = (data.rollup?.completed || []).filter(
|
|
1006
|
-
(c) => c !== "not_available"
|
|
1007
|
-
).length;
|
|
1008
|
-
const frictionCount = (data.rollup?.friction || []).length;
|
|
1009
|
-
return {
|
|
1010
|
-
status: data.status || "unknown",
|
|
1011
|
-
latestLedgerPath: LATEST_LEDGER_REL,
|
|
1012
|
-
entryCount: (data.entries || []).length,
|
|
1013
|
-
completedCount,
|
|
1014
|
-
frictionCount,
|
|
1015
|
-
nextAction: data.rollup?.nextAction || null,
|
|
1016
|
-
};
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function formatWorkLedgerText(ledger, options = {}) {
|
|
1020
|
-
const debug = options.debug === true;
|
|
1021
|
-
const lines = [];
|
|
1022
|
-
|
|
1023
|
-
const statusLabel =
|
|
1024
|
-
ledger.status === "pass"
|
|
1025
|
-
? "pass"
|
|
1026
|
-
: ledger.status === "warn"
|
|
1027
|
-
? "warn"
|
|
1028
|
-
: ledger.status === "fail"
|
|
1029
|
-
? "fail"
|
|
1030
|
-
: ledger.status;
|
|
1031
|
-
|
|
1032
|
-
lines.push(`Avorelo Work Ledger: ${statusLabel}`);
|
|
1033
|
-
lines.push(`Run: ${ledger.runId}`);
|
|
1034
|
-
lines.push("");
|
|
1035
|
-
|
|
1036
|
-
const { rollup } = ledger;
|
|
1037
|
-
|
|
1038
|
-
if (rollup.completed.some((c) => c !== "not_available")) {
|
|
1039
|
-
lines.push("Completed:");
|
|
1040
|
-
for (const c of rollup.completed) {
|
|
1041
|
-
if (c !== "not_available") lines.push(` - ${c}`);
|
|
1042
|
-
}
|
|
1043
|
-
lines.push("");
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
if (rollup.saved.length > 0) {
|
|
1047
|
-
lines.push("Saved:");
|
|
1048
|
-
for (const s of rollup.saved) lines.push(` - ${s}`);
|
|
1049
|
-
lines.push("");
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
if (rollup.protected.length > 0) {
|
|
1053
|
-
lines.push("Protected:");
|
|
1054
|
-
for (const p of rollup.protected) lines.push(` - ${p}`);
|
|
1055
|
-
lines.push("");
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
if (rollup.verified.length > 0) {
|
|
1059
|
-
lines.push("Verified:");
|
|
1060
|
-
for (const v of rollup.verified) lines.push(` - ${v}`);
|
|
1061
|
-
lines.push("");
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
if (rollup.friction.length > 0) {
|
|
1065
|
-
lines.push("Friction:");
|
|
1066
|
-
for (const f of rollup.friction) lines.push(` - ${f}`);
|
|
1067
|
-
lines.push("");
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
if (rollup.feedback.length > 0) {
|
|
1071
|
-
lines.push("Feedback:");
|
|
1072
|
-
for (const fb of rollup.feedback) lines.push(` - ${fb}`);
|
|
1073
|
-
lines.push("");
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
if (rollup.nextAction) {
|
|
1077
|
-
lines.push(`Next:`);
|
|
1078
|
-
lines.push(` ${rollup.nextAction}`);
|
|
1079
|
-
lines.push("");
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
if (debug) {
|
|
1083
|
-
lines.push("--- Debug: Ledger Entries ---");
|
|
1084
|
-
for (const entry of ledger.entries) {
|
|
1085
|
-
lines.push(`[${entry.type}] ${entry.source}: ${entry.status}`);
|
|
1086
|
-
lines.push(` Summary: ${entry.summary}`);
|
|
1087
|
-
if (entry.evidencePath) lines.push(` Evidence: ${entry.evidencePath}`);
|
|
1088
|
-
if (entry.reasonCodes?.length > 0)
|
|
1089
|
-
lines.push(` Codes: ${entry.reasonCodes.join(", ")}`);
|
|
1090
|
-
if (entry.frictionSignals?.length > 0)
|
|
1091
|
-
lines.push(` Friction: ${entry.frictionSignals.join(", ")}`);
|
|
1092
|
-
}
|
|
1093
|
-
lines.push("");
|
|
1094
|
-
|
|
1095
|
-
lines.push("--- Debug: Evidence Paths ---");
|
|
1096
|
-
for (const p of ledger.evidence.receiptPaths) {
|
|
1097
|
-
lines.push(` ${p}`);
|
|
1098
|
-
}
|
|
1099
|
-
lines.push("");
|
|
1100
|
-
|
|
1101
|
-
if (ledger.caveats?.length > 0) {
|
|
1102
|
-
lines.push("--- Debug: Caveats ---");
|
|
1103
|
-
for (const c of ledger.caveats) lines.push(` ${c}`);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
return lines.join("\n");
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
module.exports = {
|
|
1111
|
-
CONTRACT,
|
|
1112
|
-
SCHEMA_VERSION,
|
|
1113
|
-
ENTRY_TYPES,
|
|
1114
|
-
LATEST_LEDGER_REL,
|
|
1115
|
-
ARTIFACT_PATHS,
|
|
1116
|
-
createRunId,
|
|
1117
|
-
readAvailableWorkArtifacts,
|
|
1118
|
-
normalizeLedgerEntry,
|
|
1119
|
-
buildWorkLedger,
|
|
1120
|
-
writeWorkLedger,
|
|
1121
|
-
buildWorkLedgerSurface,
|
|
1122
|
-
formatWorkLedgerText,
|
|
1123
|
-
};
|