avorelo 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/bin/avorelo +9 -0
  4. package/package.json +135 -0
  5. package/scripts/README.md +40 -0
  6. package/scripts/cco-dashboard.js +252 -0
  7. package/scripts/cco-status.js +430 -0
  8. package/scripts/lib/activation/account-state.js +37 -0
  9. package/scripts/lib/activation/activation-runner.js +546 -0
  10. package/scripts/lib/activation/activation-self-healing.js +480 -0
  11. package/scripts/lib/activation/activation-state.js +83 -0
  12. package/scripts/lib/activation/activation-summary.js +191 -0
  13. package/scripts/lib/activation/adapters/claude-code.js +77 -0
  14. package/scripts/lib/activation/adapters/codex-cli.js +52 -0
  15. package/scripts/lib/activation/adapters/cursor.js +37 -0
  16. package/scripts/lib/activation/adapters/github-agent.js +39 -0
  17. package/scripts/lib/activation/adapters/terminal.js +42 -0
  18. package/scripts/lib/activation/adapters/vscode.js +39 -0
  19. package/scripts/lib/activation/adapters/windsurf.js +37 -0
  20. package/scripts/lib/activation/ai-surface-detector.js +151 -0
  21. package/scripts/lib/activation/connect-account.js +145 -0
  22. package/scripts/lib/activation/detect-environment.js +75 -0
  23. package/scripts/lib/activation/detect-hosts.js +62 -0
  24. package/scripts/lib/activation/format-activation-output.js +109 -0
  25. package/scripts/lib/activation/next-action.js +43 -0
  26. package/scripts/lib/activation/repair-engine.js +219 -0
  27. package/scripts/lib/activation-distribution-readiness.js +507 -0
  28. package/scripts/lib/adapter-conformance.js +176 -0
  29. package/scripts/lib/adapter-readiness.js +417 -0
  30. package/scripts/lib/adapter-safety-boundaries.js +335 -0
  31. package/scripts/lib/adapter-technical-readiness-gate.js +205 -0
  32. package/scripts/lib/agent-access-governance.js +455 -0
  33. package/scripts/lib/agent-enforcement.js +765 -0
  34. package/scripts/lib/agent-policy-profile.js +210 -0
  35. package/scripts/lib/agent-security/action-evaluator.js +507 -0
  36. package/scripts/lib/agent-security/adapter-registry.js +98 -0
  37. package/scripts/lib/agent-security/auto-policy.js +139 -0
  38. package/scripts/lib/agent-security/bounded-scan.js +93 -0
  39. package/scripts/lib/agent-security/enforcement-adapter.js +174 -0
  40. package/scripts/lib/agent-security/enforcement-engine.js +1129 -0
  41. package/scripts/lib/agent-security/file-write-adapter.js +183 -0
  42. package/scripts/lib/agent-security/file-write-rules.js +178 -0
  43. package/scripts/lib/agent-security/index.js +3342 -0
  44. package/scripts/lib/agent-security/instruction-risk.js +181 -0
  45. package/scripts/lib/agent-security/mcp-action-adapter.js +185 -0
  46. package/scripts/lib/agent-security/mcp-action-rules.js +184 -0
  47. package/scripts/lib/agent-security/package-action-adapter.js +175 -0
  48. package/scripts/lib/agent-security/package-action-rules.js +233 -0
  49. package/scripts/lib/agent-security/performance.js +148 -0
  50. package/scripts/lib/agent-security/permission-minimizer.js +403 -0
  51. package/scripts/lib/agent-security/scan-cache.js +74 -0
  52. package/scripts/lib/agent-security/source-trust.js +146 -0
  53. package/scripts/lib/ai-install-prompt.js +288 -0
  54. package/scripts/lib/ai-workspace-hygiene.js +1499 -0
  55. package/scripts/lib/alpha-activation.js +520 -0
  56. package/scripts/lib/alpha-feedback.js +263 -0
  57. package/scripts/lib/alpha-readiness-gate.js +332 -0
  58. package/scripts/lib/anti-gaming.js +169 -0
  59. package/scripts/lib/artifact-health.js +431 -0
  60. package/scripts/lib/attribution.js +180 -0
  61. package/scripts/lib/audit.js +289 -0
  62. package/scripts/lib/avorelo-skill-registry.js +810 -0
  63. package/scripts/lib/batch-jobs.js +71 -0
  64. package/scripts/lib/brain-pack.js +578 -0
  65. package/scripts/lib/brand-boundary.js +424 -0
  66. package/scripts/lib/brand.js +74 -0
  67. package/scripts/lib/browser-capability.js +1048 -0
  68. package/scripts/lib/browser-proof-preflight.js +321 -0
  69. package/scripts/lib/cache-readiness.js +187 -0
  70. package/scripts/lib/canonical-reentry.js +162 -0
  71. package/scripts/lib/capability-packs.js +314 -0
  72. package/scripts/lib/capability-recommender.js +512 -0
  73. package/scripts/lib/capability-registry.js +1059 -0
  74. package/scripts/lib/carry-forward-surfacing.js +194 -0
  75. package/scripts/lib/ccusage-adapter.js +188 -0
  76. package/scripts/lib/company-loop.js +1149 -0
  77. package/scripts/lib/config.js +637 -0
  78. package/scripts/lib/context-acquisition-plan.js +287 -0
  79. package/scripts/lib/context-budget-guard.js +170 -0
  80. package/scripts/lib/context-budget-scanner.js +257 -0
  81. package/scripts/lib/context-optimizer.js +715 -0
  82. package/scripts/lib/context-reduction-plan.js +178 -0
  83. package/scripts/lib/context-safety.js +88 -0
  84. package/scripts/lib/context-savings-engine.js +158 -0
  85. package/scripts/lib/cost-evidence.js +254 -0
  86. package/scripts/lib/cross-host-install-plan.js +308 -0
  87. package/scripts/lib/cross-host-install-readiness.js +237 -0
  88. package/scripts/lib/cross-host-value-flow.js +268 -0
  89. package/scripts/lib/dashboard.js +900 -0
  90. package/scripts/lib/design-partner-feedback.js +346 -0
  91. package/scripts/lib/entitlements.js +100 -0
  92. package/scripts/lib/execution-packet.js +559 -0
  93. package/scripts/lib/experimentation-events.js +547 -0
  94. package/scripts/lib/external-capability-compliance.js +107 -0
  95. package/scripts/lib/external-user-simulation.js +166 -0
  96. package/scripts/lib/failure-recovery-readiness.js +81 -0
  97. package/scripts/lib/failure-recovery.js +419 -0
  98. package/scripts/lib/feedback-intelligence.js +537 -0
  99. package/scripts/lib/feedback-signals.js +205 -0
  100. package/scripts/lib/file-integrity.js +68 -0
  101. package/scripts/lib/fsx.js +127 -0
  102. package/scripts/lib/full-readiness-gate.js +451 -0
  103. package/scripts/lib/guidance-builder.js +174 -0
  104. package/scripts/lib/hook-apply.js +1019 -0
  105. package/scripts/lib/hook-baseline.js +310 -0
  106. package/scripts/lib/hook-config-preview.js +275 -0
  107. package/scripts/lib/hook-contracts.js +290 -0
  108. package/scripts/lib/hook-safety-boundary-readiness.js +80 -0
  109. package/scripts/lib/host-capability-matrix.js +351 -0
  110. package/scripts/lib/host-support-context.js +254 -0
  111. package/scripts/lib/http-hook-action.js +538 -0
  112. package/scripts/lib/install-ai-readiness.js +84 -0
  113. package/scripts/lib/install-intake-risk.js +1037 -0
  114. package/scripts/lib/install-journey-intelligence.js +329 -0
  115. package/scripts/lib/intervention-guidance.js +57 -0
  116. package/scripts/lib/known-limitations.js +115 -0
  117. package/scripts/lib/l8-path-truth.js +146 -0
  118. package/scripts/lib/launch-hardening-gate.js +436 -0
  119. package/scripts/lib/launch-readiness.js +628 -0
  120. package/scripts/lib/learning-memory.js +686 -0
  121. package/scripts/lib/lifecycle-hooks.js +802 -0
  122. package/scripts/lib/local-package-smoke.js +423 -0
  123. package/scripts/lib/local-pricing.js +299 -0
  124. package/scripts/lib/mcp-enforcement.js +311 -0
  125. package/scripts/lib/mcp-least-privilege-policy.js +303 -0
  126. package/scripts/lib/mcp-tool-inventory.js +388 -0
  127. package/scripts/lib/mcp-tool-risk.js +0 -0
  128. package/scripts/lib/memory.js +335 -0
  129. package/scripts/lib/metrics.js +699 -0
  130. package/scripts/lib/micro-proof.js +133 -0
  131. package/scripts/lib/next-run-context.js +436 -0
  132. package/scripts/lib/operating-value.js +1648 -0
  133. package/scripts/lib/optimization-v3.js +122 -0
  134. package/scripts/lib/orchestration/adapters/_shared.js +49 -0
  135. package/scripts/lib/orchestration/adapters/aider.js +18 -0
  136. package/scripts/lib/orchestration/adapters/claude-code.js +35 -0
  137. package/scripts/lib/orchestration/adapters/codex.js +35 -0
  138. package/scripts/lib/orchestration/adapters/gemini-cli.js +18 -0
  139. package/scripts/lib/orchestration/adapters/git.js +25 -0
  140. package/scripts/lib/orchestration/adapters/index.js +31 -0
  141. package/scripts/lib/orchestration/adapters/lm-studio.js +18 -0
  142. package/scripts/lib/orchestration/adapters/ollama.js +18 -0
  143. package/scripts/lib/orchestration/adapters/opencode.js +18 -0
  144. package/scripts/lib/orchestration/adapters/openrouter.js +18 -0
  145. package/scripts/lib/orchestration/adapters/test-runner.js +25 -0
  146. package/scripts/lib/orchestration/cli.js +438 -0
  147. package/scripts/lib/orchestration/execution-manager.js +279 -0
  148. package/scripts/lib/orchestration/handoff.js +314 -0
  149. package/scripts/lib/orchestration/index.js +456 -0
  150. package/scripts/lib/orchestration/inventory.js +47 -0
  151. package/scripts/lib/orchestration/model-discovery.js +498 -0
  152. package/scripts/lib/orchestration/model-profiler.js +170 -0
  153. package/scripts/lib/orchestration/model-profiles.js +252 -0
  154. package/scripts/lib/orchestration/model-refresh-policy.js +72 -0
  155. package/scripts/lib/orchestration/proof-writer.js +349 -0
  156. package/scripts/lib/orchestration/provider-discovery/aider.js +49 -0
  157. package/scripts/lib/orchestration/provider-discovery/claude-code.js +56 -0
  158. package/scripts/lib/orchestration/provider-discovery/codex.js +49 -0
  159. package/scripts/lib/orchestration/provider-discovery/common.js +186 -0
  160. package/scripts/lib/orchestration/provider-discovery/gemini.js +106 -0
  161. package/scripts/lib/orchestration/provider-discovery/lm-studio.js +118 -0
  162. package/scripts/lib/orchestration/provider-discovery/models-dev.js +12 -0
  163. package/scripts/lib/orchestration/provider-discovery/ollama.js +100 -0
  164. package/scripts/lib/orchestration/provider-discovery/opencode.js +47 -0
  165. package/scripts/lib/orchestration/provider-discovery/openrouter.js +44 -0
  166. package/scripts/lib/orchestration/risk-classifier.js +130 -0
  167. package/scripts/lib/orchestration/routing-policy.js +486 -0
  168. package/scripts/lib/orchestration/settings.js +112 -0
  169. package/scripts/lib/orchestration/state.js +165 -0
  170. package/scripts/lib/orchestration/verification-manager.js +138 -0
  171. package/scripts/lib/output-profiles.js +146 -0
  172. package/scripts/lib/package-content-audit.js +368 -0
  173. package/scripts/lib/package-runtime.js +278 -0
  174. package/scripts/lib/plan-surface.js +53 -0
  175. package/scripts/lib/plans.js +2318 -0
  176. package/scripts/lib/policy-provider.js +27 -0
  177. package/scripts/lib/prelaunch-activation-readiness.js +409 -0
  178. package/scripts/lib/prelaunch-evidence-store.js +816 -0
  179. package/scripts/lib/prelaunch-intelligence.js +869 -0
  180. package/scripts/lib/pricing-experiment.js +118 -0
  181. package/scripts/lib/pro-moment-events.js +77 -0
  182. package/scripts/lib/pro-moment-state.js +227 -0
  183. package/scripts/lib/pro-moments.js +1216 -0
  184. package/scripts/lib/product-learning-events.js +629 -0
  185. package/scripts/lib/project-profile.js +555 -0
  186. package/scripts/lib/prompt-compiler.js +280 -0
  187. package/scripts/lib/prompt-lint.js +32 -0
  188. package/scripts/lib/prompt-suggestions.js +52 -0
  189. package/scripts/lib/proof-canonical.js +398 -0
  190. package/scripts/lib/proof-drilldown.js +383 -0
  191. package/scripts/lib/proof-events.js +342 -0
  192. package/scripts/lib/proof-history.js +243 -0
  193. package/scripts/lib/proof-metrics.js +296 -0
  194. package/scripts/lib/proof-outcome-evidence.js +134 -0
  195. package/scripts/lib/proof-receipt.js +335 -0
  196. package/scripts/lib/proof-record.js +461 -0
  197. package/scripts/lib/public-activation-distribution-gate.js +258 -0
  198. package/scripts/lib/public-cli.js +3891 -0
  199. package/scripts/lib/public-distribution-truth.js +211 -0
  200. package/scripts/lib/public-install-claim-checker.js +294 -0
  201. package/scripts/lib/publish-provenance-readiness.js +283 -0
  202. package/scripts/lib/readiness-delta.js +218 -0
  203. package/scripts/lib/readiness-evidence-closure.js +196 -0
  204. package/scripts/lib/reentry-memory-capture.js +241 -0
  205. package/scripts/lib/reentry-memory-retrieval.js +302 -0
  206. package/scripts/lib/reentry-memory-status.js +146 -0
  207. package/scripts/lib/reentry-memory-store.js +178 -0
  208. package/scripts/lib/reentry-state.js +66 -0
  209. package/scripts/lib/release-candidate-bundle.js +166 -0
  210. package/scripts/lib/remediation.js +81 -0
  211. package/scripts/lib/repo-map.js +391 -0
  212. package/scripts/lib/run-improvements-lifecycle.js +330 -0
  213. package/scripts/lib/run-improvements.js +789 -0
  214. package/scripts/lib/runtime-decision-policy.js +387 -0
  215. package/scripts/lib/safe-path-engine.js +705 -0
  216. package/scripts/lib/safe-run-controller.js +887 -0
  217. package/scripts/lib/score.js +262 -0
  218. package/scripts/lib/seamless-enforcement.js +329 -0
  219. package/scripts/lib/seamless-outcome.js +689 -0
  220. package/scripts/lib/seamless-reality-gate.js +5043 -0
  221. package/scripts/lib/security-risk-classifier.js +511 -0
  222. package/scripts/lib/security-scan.js +384 -0
  223. package/scripts/lib/session-context-optimizer.js +1211 -0
  224. package/scripts/lib/session-timing.js +315 -0
  225. package/scripts/lib/skill-hygiene.js +805 -0
  226. package/scripts/lib/skill-packs.js +161 -0
  227. package/scripts/lib/skills-operating-layer.js +580 -0
  228. package/scripts/lib/smart-work-routing.js +768 -0
  229. package/scripts/lib/source-catalog.js +700 -0
  230. package/scripts/lib/status-value-summary.js +32 -0
  231. package/scripts/lib/support-bundle.js +578 -0
  232. package/scripts/lib/task-continuation.js +440 -0
  233. package/scripts/lib/test-helpers.js +15 -0
  234. package/scripts/lib/tier.js +38 -0
  235. package/scripts/lib/token-context-quality-gate.js +370 -0
  236. package/scripts/lib/token-cost-capture.js +187 -0
  237. package/scripts/lib/token-cost-intelligence.js +358 -0
  238. package/scripts/lib/token-efficiency-evidence.js +213 -0
  239. package/scripts/lib/token-evidence.js +699 -0
  240. package/scripts/lib/tokenish.js +17 -0
  241. package/scripts/lib/tool-output-sandbox.js +304 -0
  242. package/scripts/lib/trust-audit.js +136 -0
  243. package/scripts/lib/unified-events.js +396 -0
  244. package/scripts/lib/upgrade-interruption-recovery.js +407 -0
  245. package/scripts/lib/usage-ledger.js +201 -0
  246. package/scripts/lib/value-ledger.js +130 -0
  247. package/scripts/lib/value-proof-calibration.js +531 -0
  248. package/scripts/lib/visual-qa.js +231 -0
  249. package/scripts/lib/voice-alpha.js +29 -0
  250. package/scripts/lib/work-aware-orchestration.js +976 -0
  251. package/scripts/lib/work-control-receipts.js +577 -0
  252. package/scripts/lib/work-ledger.js +1123 -0
  253. package/scripts/lib/work-panel-preview.js +352 -0
  254. package/scripts/lib/workflow-discipline.js +280 -0
  255. package/scripts/lib/workflow-signals.js +419 -0
  256. package/scripts/lib/workspace-map.js +281 -0
  257. package/scripts/lib/workspace-registry.js +1367 -0
  258. package/scripts/lib/workspace-resolver.js +480 -0
@@ -0,0 +1,629 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const crypto = require("crypto");
6
+ const { ensureCcoDirs, nowIso } = require("./fsx");
7
+
8
+ const PRODUCT_LEARNING_EVENTS_REL_PATH = ".claude/cco/events/product-learning.jsonl";
9
+ const VALID_EVENT_NAMES = new Set([
10
+ "capability_recommended",
11
+ "capability_used",
12
+ "capability_skipped",
13
+ "capability_failed",
14
+ "capability_helpful",
15
+ "capability_not_helpful",
16
+ "dogfood_persona_reviewed",
17
+ "dogfood_gap_found",
18
+ "dogfood_action_taken",
19
+ "dogfood_deferred_item",
20
+ "dogfood_user_friction",
21
+ "route_requested",
22
+ "route_selected",
23
+ "route_fallback_used",
24
+ "route_blocked_for_safety",
25
+ "model_unavailable",
26
+ "cheaper_safe_path_selected",
27
+ "expensive_path_avoided",
28
+ "prompt_compiled",
29
+ "context_pressure_detected",
30
+ "broad_scan_avoided",
31
+ "repeated_work_detected",
32
+ "token_waste_warning",
33
+ "compact_context_generated",
34
+ "guard_decision",
35
+ "access_governance_evaluated",
36
+ "access_subject_unknown",
37
+ "access_scope_requires_approval",
38
+ "access_receipt_written",
39
+ "access_blocked",
40
+ "access_warned",
41
+ "source_scan_completed",
42
+ "source_reviewed",
43
+ "source_deferred",
44
+ "source_blocked",
45
+ "source_adoption_receipt_written",
46
+ "skill_parsed",
47
+ "skill_parse_warning",
48
+ "skill_bound",
49
+ "skill_binding_warning",
50
+ "skill_router_hit",
51
+ "skill_router_skipped",
52
+ "adapter_generated",
53
+ "adapter_generation_skipped",
54
+ "safe_path_evaluated",
55
+ "safe_path_recommended",
56
+ "safe_path_applied",
57
+ "safe_path_skipped",
58
+ "access_reduced",
59
+ "approval_boundary_used",
60
+ "block_preserved",
61
+ "jit_temporary_scope_recommended",
62
+ "skill_context_safety_warning",
63
+ "skills_security_dogfood_completed",
64
+ "intake_scan_completed",
65
+ "intake_unknown_item_detected",
66
+ "intake_high_risk_item_detected",
67
+ "intake_blocked_item_detected",
68
+ "intake_safe_next_action_recommended",
69
+ "intake_receipt_written",
70
+ "intake_feeds_governance",
71
+ "intake_feeds_safe_path",
72
+ "suspicious_skill_flagged",
73
+ "prompt_injection_pattern_detected",
74
+ "secret_exposure_prevented",
75
+ "approval_required",
76
+ "activation_started",
77
+ "activation_completed",
78
+ "activation_gap_found",
79
+ "doctor_gap_found",
80
+ "first_value_action_completed",
81
+ "free_capability_used",
82
+ "pro_moment_candidate_detected",
83
+ "pro_moment_eligible",
84
+ "pro_moment_suppressed",
85
+ "pro_nudge_shown",
86
+ "pro_nudge_clicked",
87
+ "pro_nudge_dismissed",
88
+ "pro_nudge_cooldown_started",
89
+ "pro_capability_requested",
90
+ "pro_feature_requested",
91
+ "pro_limit_reached",
92
+ "upgrade_page_viewed",
93
+ "checkout_started",
94
+ "checkout_abandoned",
95
+ "upgrade_completed",
96
+ "pro_nudge_not_now_clicked",
97
+ "pro_nudge_dont_show_again_clicked",
98
+ "pro_nudge_multiple_dismissals",
99
+ "pro_nudge_hidden_due_to_cooldown",
100
+ "disable_avorelo_started",
101
+ "feedback_negative_submitted",
102
+ "gated_capability_hit",
103
+ "upgrade_signal_detected",
104
+ "work_control_receipt_written",
105
+ "work_control_handoff_generated",
106
+ "work_control_block_preserved",
107
+ "work_control_approval_required",
108
+ "work_control_next_action_recommended",
109
+ "work_control_do_not_repeat_generated",
110
+ "session_context_generated",
111
+ "session_context_handoff_generated",
112
+ "context_budget_applied",
113
+ "broad_rediscovery_avoided",
114
+ "huge_json_dump_avoided",
115
+ "continuation_packet_used",
116
+ "model_effort_recommendation_generated",
117
+ "pricing_confusion_detected",
118
+ "feedback_submitted",
119
+ "feedback_category",
120
+ "feedback_sentiment",
121
+ "feature_request",
122
+ "friction_reported",
123
+ "unclear_value_reported",
124
+ // Context Intelligence Completion v1
125
+ "brain_pack_generated",
126
+ "brain_pack_initialized",
127
+ "brain_pack_used_in_session_context",
128
+ "recipe_detected",
129
+ "dynamic_commands_generated",
130
+ "target_specific_handoff_generated",
131
+ "skills_route_fallback_recommended",
132
+ "dogfood_feedback_captured",
133
+ "capability_recommendation_embedded",
134
+ // Workspace Registry v1
135
+ "workspace_registry_generated",
136
+ "workspace_registry_summary_generated",
137
+ "workspace_registry_drift_detected",
138
+ "workspace_asset_unknown_detected",
139
+ "workspace_asset_high_risk_detected",
140
+ "workspace_registry_used_in_session_context",
141
+ "workspace_registry_used_in_brain_pack",
142
+ "workspace_registry_value_measured",
143
+ "workspace_registry_next_action_recommended",
144
+ // Operating Loop Value Surface v1
145
+ "operating_value_generated",
146
+ "operating_value_summary_generated",
147
+ "operating_value_moment_generated",
148
+ "operating_value_validated",
149
+ "rediscovery_avoided_measured",
150
+ "context_reduction_estimated",
151
+ "manual_steps_avoided_estimated",
152
+ "risk_avoided_measured",
153
+ "capability_routing_quality_measured",
154
+ "seamlessness_measured",
155
+ "willingness_to_pay_signal_generated",
156
+ "local_value_dashboard_generated",
157
+ "local_value_dashboard_opened",
158
+ // Value Proof Hardening / Reality Calibration v1
159
+ "value_proof_calibrated",
160
+ "value_claim_overclaim_risk_detected",
161
+ "value_claim_downgraded",
162
+ "value_claim_allowed_for_dashboard",
163
+ "value_claim_blocked_for_website",
164
+ "value_evidence_gap_detected",
165
+ // Seamless Activation + Self-Healing Setup v1
166
+ "activation_scan_completed",
167
+ "activation_safe_fix_planned",
168
+ "activation_safe_fix_applied",
169
+ "activation_verification_completed",
170
+ "activation_ready",
171
+ "activation_hard_blocker_detected",
172
+ "activation_agent_repair_plan_generated",
173
+ "activation_dashboard_ready",
174
+ "activation_model_routing_detected",
175
+ // Skill Hygiene & Routing Guard v1
176
+ "skill_hygiene_completed",
177
+ "skill_duplicate_group_detected",
178
+ "skill_shadow_candidate_detected",
179
+ "skill_bounded_contribution_accepted",
180
+ "skill_bounded_contribution_rejected",
181
+ "skill_conflict_detected",
182
+ "skill_context_heavy_detected",
183
+ "skill_security_hygiene_detected",
184
+ "skill_route_deduped",
185
+ "skill_route_blocked_by_hygiene",
186
+ "skill_intake_checked",
187
+ "skill_intake_blocked",
188
+ "skill_intake_merge_recommended",
189
+ // Measurement Evidence Foundation v1
190
+ "dogfood_reality_gate_completed",
191
+ "dogfood_finding_reconciled",
192
+ "launch_ready_journey_checked",
193
+ "local_pricing_initialized",
194
+ "local_pricing_validated",
195
+ "local_pricing_unavailable",
196
+ "token_evidence_generated",
197
+ "token_evidence_fallback_used",
198
+ "session_timing_event_recorded",
199
+ "session_timing_summary_generated",
200
+ "cost_evidence_generated",
201
+ "cost_estimate_unavailable",
202
+ "cost_estimate_generated",
203
+ "measurement_evidence_calibrated",
204
+ // Install Intake Risk Foundation v1
205
+ "install_intake_risk_scan_completed",
206
+ "install_intake_risk_receipt_written",
207
+ // Agent Model Orchestration Foundation v1
208
+ "orchestration_route_planned",
209
+ "orchestration_stage_planned",
210
+ "worker_limited_detected",
211
+ "fallback_recommended",
212
+ "fallback_used",
213
+ "local_worker_recommended",
214
+ "local_worker_used",
215
+ "escalation_recommended",
216
+ "handoff_prompt_generated",
217
+ "orchestration_receipt_written",
218
+ "worker_selection_blocked",
219
+ // Prompt / Context / Token Optimization Foundation v1
220
+ "context_pack_generated",
221
+ "context_budget_estimated",
222
+ "context_budget_warning",
223
+ "context_over_budget",
224
+ "context_compaction_used",
225
+ "context_item_excluded",
226
+ "skill_context_lazy_loaded",
227
+ "handoff_context_pack_attached",
228
+ "local_worker_context_boundary_used",
229
+ "no_secrets_context_boundary_applied",
230
+ "context_optimization_receipt_written",
231
+ // Seamless Customer Outcome + Value Reality Gate v1
232
+ "seamless_mode_applied",
233
+ "automatic_optimization_applied",
234
+ "user_interrupt_avoided",
235
+ "interruption_required",
236
+ "outcome_preservation_checked",
237
+ "task_completion_preserved",
238
+ "value_summary_generated",
239
+ "estimated_premium_call_avoided",
240
+ "context_tokens_avoided_estimated",
241
+ "manual_decision_avoided",
242
+ "quality_escalation_recommended",
243
+ "seamless_reality_gate_completed",
244
+ // Seamless Automation Enforcement v1
245
+ "enforcement_guard_compact_applied",
246
+ "enforcement_route_compact_applied",
247
+ "enforcement_context_compact_applied",
248
+ "enforcement_block_outcome_preserved",
249
+ "enforcement_escalation_automatic",
250
+ // Task-Specific Continuation + Value Evidence Hardening v1
251
+ "task_continuation_generated",
252
+ "task_specific_safe_next_action_generated",
253
+ "generic_safe_next_action_detected",
254
+ "value_evidence_collected",
255
+ "value_summary_evidence_backed",
256
+ "value_summary_autowrite_completed",
257
+ "value_summary_autowrite_skipped",
258
+ // AI Workspace Hygiene + Capability Registry v1
259
+ "ai_workspace_hygiene_scanned",
260
+ "ai_workspace_asset_detected",
261
+ "ai_workspace_duplicate_instruction_detected",
262
+ "ai_workspace_high_context_cost_detected",
263
+ "ai_workspace_unknown_mcp_detected",
264
+ "ai_workspace_capability_registry_built",
265
+ "ai_workspace_hygiene_report_written",
266
+ // Work-Aware Orchestration + Workspace Relevance v1
267
+ "work_orchestration_plan_generated",
268
+ "work_orchestration_stage_planned",
269
+ "stage_worker_selected",
270
+ "stage_context_selected",
271
+ "local_or_cheap_stage_used",
272
+ "strong_worker_reserved",
273
+ "fallback_worker_planned",
274
+ "workspace_relevance_used",
275
+ "unknown_workspace_asset_excluded",
276
+ "high_context_asset_excluded",
277
+ "stage_handoff_prepared",
278
+ "orchestration_value_evidence_written",
279
+ // PR #136 — AI-Native Company Loop + Unified Work Ledger
280
+ "work_ledger_built",
281
+ "work_ledger_entry_linked",
282
+ "work_ledger_rollup_generated",
283
+ "company_loop_report_generated",
284
+ "internal_persona_review_generated",
285
+ "friction_cluster_detected",
286
+ "feedback_signal_loaded",
287
+ "next_pr_recommendation_generated",
288
+ "cost_cogs_quality_rollup_generated",
289
+ // PR #137 — Execution Packet + Project Profile + Work Panel Preview v1
290
+ "project_profile_detected",
291
+ "execution_packet_compiled",
292
+ "agent_prompt_compiled",
293
+ "work_panel_preview_generated",
294
+ "blocked_scope_applied",
295
+ "proof_requirements_attached",
296
+ "diff_before_write_required",
297
+ "packet_approval_required",
298
+ "packet_ready_for_worker",
299
+ // PR #138 — Seamless Smart Work Routing + Worker Handoff Runtime v1
300
+ "smart_work_route_built",
301
+ "smart_route_execution_path_selected",
302
+ "worker_handoff_prepared",
303
+ "protocol_readiness_evaluated",
304
+ "same_surface_preferred",
305
+ "cross_vendor_blocked_by_default",
306
+ "remote_agent_delegation_blocked",
307
+ "smart_route_receipt_written",
308
+ // PR #139 — Safe Run Command + Execution Controller v1
309
+ "safe_run_started",
310
+ "safe_run_plan_built",
311
+ "safe_run_local_step_allowed",
312
+ "safe_run_local_step_blocked",
313
+ "safe_run_local_step_completed",
314
+ "safe_run_receipt_written",
315
+ "safe_run_approval_required",
316
+ "safe_run_blocked",
317
+ "safe_run_completed",
318
+ // PR #140 — Hook Baseline + Lifecycle Automation Preview v1
319
+ "hook_baseline_built",
320
+ "adapter_readiness_detected",
321
+ "hook_config_preview_generated",
322
+ "lifecycle_hook_handler_invoked",
323
+ "lifecycle_pre_tool_use_blocked",
324
+ "lifecycle_stop_proof_required",
325
+ "lifecycle_session_end_summary_written",
326
+ "hook_preview_receipt_written",
327
+ // PR #141 — Explicit Hook Apply + Lifecycle Live v1
328
+ "hook_apply_plan_built",
329
+ "hook_apply_approval_required",
330
+ "hook_config_applied",
331
+ "hook_apply_validation_passed",
332
+ "hook_apply_validation_failed",
333
+ "hook_rollback_performed",
334
+ "hook_uninstall_performed",
335
+ "hook_doctor_run",
336
+ "hook_recursion_guard_triggered",
337
+ "lifecycle_live_smoke_passed",
338
+ // PR #142 — Activation Alpha Readiness + First Value v1
339
+ "alpha_activation_started",
340
+ "alpha_activation_checked",
341
+ "first_value_path_selected",
342
+ "first_value_completed",
343
+ "alpha_readiness_gate_run",
344
+ "alpha_feedback_added",
345
+ "support_bundle_generated",
346
+ "activation_friction_detected",
347
+ "e2e_value_dogfood_completed",
348
+ // PR #143 — Token Efficiency + Context Quality Hardening v1
349
+ "token_efficiency_evidence_generated",
350
+ "tool_output_sandbox_summary_written",
351
+ "raw_tool_output_artifact_written",
352
+ "repo_map_generated",
353
+ "context_acquisition_plan_generated",
354
+ "cache_readiness_checked",
355
+ "token_context_quality_gate_run",
356
+ "full_repo_dump_blocked",
357
+ "context_quality_fallback_required",
358
+ "e2e_token_value_dogfood_completed",
359
+ // PR #144 — Launch Hardening + Failure Recovery v1
360
+ "launch_hardening_gate_run",
361
+ "failure_recovery_plan_built",
362
+ "artifact_health_scanned",
363
+ "artifact_cleanup_plan_built",
364
+ "artifact_cleanup_applied",
365
+ "doctor_hardening_run",
366
+ "support_bundle_redaction_checked",
367
+ "json_contract_validated",
368
+ "cross_platform_sanity_checked",
369
+ "e2e_failure_mode_dogfood_completed",
370
+ // PR #145 — MCP Least-Privilege Tool Governance v1
371
+ "mcp_tool_inventory_scanned",
372
+ "mcp_tool_risk_classified",
373
+ "mcp_policy_preview_generated",
374
+ "mcp_pre_tool_use_decision_written",
375
+ "mcp_unknown_tool_detected",
376
+ "mcp_suspicious_metadata_detected",
377
+ "mcp_broad_permission_detected",
378
+ "mcp_tool_blocked",
379
+ "mcp_tool_approval_required",
380
+ "e2e_mcp_risk_dogfood_completed",
381
+ // PR #146 — One-Prompt AI Install + Pre-Launch Activation Readiness v1
382
+ "ai_install_prompt_generated",
383
+ "ai_install_prompt_copied_ready",
384
+ "prelaunch_activation_readiness_run",
385
+ "first_value_check_run",
386
+ "ai_install_flow_started",
387
+ "ai_install_flow_completed",
388
+ "ai_install_flow_blocked",
389
+ "ai_install_safety_boundary_detected",
390
+ "e2e_ai_install_dogfood_completed",
391
+ // PR #147 — Pre-Launch Intelligence Layer v1
392
+ "prelaunch_intelligence_run",
393
+ "feedback_intelligence_built",
394
+ "friction_cluster_detected",
395
+ "token_cost_intelligence_built",
396
+ "install_journey_intelligence_built",
397
+ "prelaunch_recommendation_generated",
398
+ "insufficient_prelaunch_data_detected",
399
+ "e2e_prelaunch_intelligence_dogfood_completed",
400
+ // Experimentation / Product Learning Foundation v1
401
+ "experiment_assigned",
402
+ "experiment_exposed",
403
+ "experiment_variant_rendered",
404
+ "experiment_goal_completed",
405
+ "experiment_guardrail_triggered",
406
+ "experiment_result_reviewed",
407
+ "experiment_decision_made",
408
+ "page_viewed",
409
+ "hero_viewed",
410
+ "hero_cta_clicked",
411
+ "secondary_cta_clicked",
412
+ "install_command_copied",
413
+ "docs_clicked",
414
+ "demo_started",
415
+ "demo_completed",
416
+ "pricing_viewed",
417
+ "pricing_plan_clicked",
418
+ "free_plan_clicked",
419
+ "pro_plan_clicked",
420
+ "teams_interest_clicked",
421
+ "faq_opened",
422
+ "security_section_viewed",
423
+ "value_section_viewed",
424
+ "trust_page_viewed",
425
+ "comprehension_survey_shown",
426
+ "comprehension_survey_answered",
427
+ "message_recall_answered",
428
+ "objection_selected",
429
+ "confusion_signal_detected",
430
+ "activation_failed",
431
+ "activation_safe_repair_attempted",
432
+ "activation_safe_repair_completed",
433
+ "activation_next_action_shown",
434
+ "activation_account_skipped",
435
+ "activation_account_connected",
436
+ "first_value_shown",
437
+ "first_value_acknowledged",
438
+ "prompt_shaped",
439
+ "context_pack_created",
440
+ "context_reduction_applied",
441
+ "workspace_map_created",
442
+ "workspace_map_used",
443
+ "skill_risk_scan_completed",
444
+ "risky_instruction_detected",
445
+ "guard_decision_made",
446
+ "unsafe_action_blocked",
447
+ "safe_path_suggested",
448
+ "route_recommended",
449
+ "route_applied",
450
+ "proof_generated",
451
+ "handoff_created",
452
+ "reentry_used",
453
+ "proof_history_requested",
454
+ "proof_export_requested",
455
+ "visual_qa_started",
456
+ "visual_qa_completed",
457
+ "visual_qa_finding_detected",
458
+ "trust_faq_opened",
459
+ "security_concern_clicked",
460
+ "uninstall_started",
461
+ // PR #161 — Public Activation Distribution Truth v1
462
+ "public_distribution_truth_built",
463
+ "package_content_audit_run",
464
+ "local_package_smoke_run",
465
+ "public_install_claim_check_run",
466
+ "publish_provenance_readiness_run",
467
+ "false_install_claim_detected",
468
+ "forbidden_package_file_detected",
469
+ "public_activation_distribution_gate_run",
470
+ "e2e_public_distribution_dogfood_completed",
471
+ ]);
472
+
473
+ const FORBIDDEN_PAYLOAD_KEYS = new Set([
474
+ "rawPrompt",
475
+ "prompt",
476
+ "rawCode",
477
+ "code",
478
+ "fileContents",
479
+ "secret",
480
+ "token",
481
+ "credential",
482
+ "apiKey",
483
+ ]);
484
+
485
+ function sha256(value) {
486
+ return crypto.createHash("sha256").update(String(value || "")).digest("hex");
487
+ }
488
+
489
+ function redactString(value) {
490
+ const text = String(value || "");
491
+ return text
492
+ .replace(/sk-[A-Za-z0-9]{16,}/g, "[redacted-openai-key]")
493
+ .replace(/ghp_[A-Za-z0-9]{20,}/g, "[redacted-github-token]")
494
+ .replace(/AKIA[0-9A-Z]{16}/g, "[redacted-aws-key]")
495
+ .replace(/((?:api[_ -]?key|token|password|secret|authorization)\s*[:=]\s*)([^\s'"]+)/ig, "$1[redacted]");
496
+ }
497
+
498
+ function redactPayload(payload) {
499
+ if (Array.isArray(payload)) {
500
+ return payload.map((value) => redactPayload(value));
501
+ }
502
+ if (!payload || typeof payload !== "object") {
503
+ if (typeof payload === "string") {
504
+ return redactString(payload);
505
+ }
506
+ return payload;
507
+ }
508
+
509
+ const redacted = {};
510
+ Object.keys(payload).forEach((key) => {
511
+ if (FORBIDDEN_PAYLOAD_KEYS.has(key)) {
512
+ redacted[`${key}Hash`] = sha256(JSON.stringify(payload[key]));
513
+ redacted[`${key}Length`] = String(payload[key] || "").length;
514
+ return;
515
+ }
516
+ const value = payload[key];
517
+ if (typeof value === "string" && (key.toLowerCase().includes("path") || key.toLowerCase().includes("file"))) {
518
+ redacted[key] = "[redacted-path]";
519
+ redacted[`${key}Hash`] = sha256(value);
520
+ return;
521
+ }
522
+ redacted[key] = redactPayload(value);
523
+ });
524
+ return redacted;
525
+ }
526
+
527
+ function validateProductLearningEvent(event) {
528
+ const errors = [];
529
+ if (!event || typeof event !== "object") {
530
+ errors.push("Event must be an object");
531
+ return { valid: false, errors };
532
+ }
533
+ if (!VALID_EVENT_NAMES.has(event.eventName)) {
534
+ errors.push(`Unknown eventName: ${event.eventName}`);
535
+ }
536
+ if (!event.category) {
537
+ errors.push("Event category is required");
538
+ }
539
+ if (event.payload && typeof event.payload !== "object") {
540
+ errors.push("payload must be an object when present");
541
+ }
542
+ Object.keys(event.payload || {}).forEach((key) => {
543
+ if (FORBIDDEN_PAYLOAD_KEYS.has(key)) {
544
+ errors.push(`Forbidden payload key present: ${key}`);
545
+ }
546
+ });
547
+ return { valid: errors.length === 0, errors };
548
+ }
549
+
550
+ function appendProductLearningEvent(cwd, event) {
551
+ ensureCcoDirs(cwd);
552
+ const normalized = {
553
+ schemaVersion: 1,
554
+ eventName: event.eventName,
555
+ category: event.category,
556
+ occurredAt: event.occurredAt || nowIso(),
557
+ surface: event.surface || "local",
558
+ status: event.status || "observed",
559
+ payload: redactPayload(event.payload || {}),
560
+ };
561
+ const validation = validateProductLearningEvent(normalized);
562
+ if (!validation.valid) {
563
+ return {
564
+ ok: false,
565
+ errors: validation.errors,
566
+ event: normalized,
567
+ };
568
+ }
569
+
570
+ const absPath = path.join(cwd, PRODUCT_LEARNING_EVENTS_REL_PATH);
571
+ fs.mkdirSync(path.dirname(absPath), { recursive: true });
572
+ fs.appendFileSync(absPath, `${JSON.stringify(normalized)}\n`, "utf8");
573
+ return {
574
+ ok: true,
575
+ path: PRODUCT_LEARNING_EVENTS_REL_PATH,
576
+ event: normalized,
577
+ };
578
+ }
579
+
580
+ function readProductLearningEvents(cwd) {
581
+ const absPath = path.join(cwd, PRODUCT_LEARNING_EVENTS_REL_PATH);
582
+ if (!fs.existsSync(absPath)) return [];
583
+ return fs.readFileSync(absPath, "utf8")
584
+ .split(/\r?\n/)
585
+ .map((line) => line.trim())
586
+ .filter(Boolean)
587
+ .map((line) => {
588
+ try {
589
+ return JSON.parse(line);
590
+ } catch {
591
+ return null;
592
+ }
593
+ })
594
+ .filter(Boolean);
595
+ }
596
+
597
+ function summarizeLatestLearningSignals(cwd, limit = 20) {
598
+ const events = readProductLearningEvents(cwd).slice(-limit);
599
+ const counts = {};
600
+ const categoryCounts = {};
601
+ events.forEach((event) => {
602
+ counts[event.eventName] = (counts[event.eventName] || 0) + 1;
603
+ categoryCounts[event.category] = (categoryCounts[event.category] || 0) + 1;
604
+ });
605
+ return {
606
+ totalEvents: events.length,
607
+ topEvents: Object.entries(counts)
608
+ .sort((left, right) => right[1] - left[1])
609
+ .slice(0, 5)
610
+ .map(([eventName, count]) => ({ eventName, count })),
611
+ categories: Object.entries(categoryCounts)
612
+ .sort((left, right) => right[1] - left[1])
613
+ .map(([category, count]) => ({ category, count })),
614
+ latestPath: PRODUCT_LEARNING_EVENTS_REL_PATH,
615
+ };
616
+ }
617
+
618
+ module.exports = {
619
+ PRODUCT_LEARNING_EVENTS_REL_PATH,
620
+ VALID_EVENT_NAMES,
621
+ FORBIDDEN_PAYLOAD_KEYS,
622
+ sha256,
623
+ redactString,
624
+ redactPayload,
625
+ validateProductLearningEvent,
626
+ appendProductLearningEvent,
627
+ readProductLearningEvents,
628
+ summarizeLatestLearningSignals,
629
+ };