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,335 @@
1
+ "use strict";
2
+
3
+ // ── Adapter Safety Boundaries ─────────────────────────────────────────────────
4
+ // Contract: avorelo.adapterSafetyBoundaries.v1
5
+ // Answers: "Are adapter safety contracts enforced? No cross-adapter state leaks?
6
+ // Hook timeout respected? MCP isolation verified?"
7
+ // Reads configs and artifacts. Does NOT mutate. Does NOT run hooks.
8
+
9
+ const fs = require("fs");
10
+ const path = require("path");
11
+ const { nowIso } = require("./fsx");
12
+ const { appendProductLearningEvent } = require("./product-learning-events");
13
+
14
+ const CONTRACT = "avorelo.adapterSafetyBoundaries.v1";
15
+ const SCHEMA_VERSION = 1;
16
+ const ARTIFACT_DIR_REL = ".claude/cco/orchestration/adapter-readiness";
17
+ const ARTIFACT_REL = ARTIFACT_DIR_REL + "/latest-adapter-safety-boundaries.json";
18
+
19
+ function safeReadJson(absPath) {
20
+ try {
21
+ if (!fs.existsSync(absPath)) return null;
22
+ return JSON.parse(fs.readFileSync(absPath, "utf8").replace(/^/, ""));
23
+ } catch { return null; }
24
+ }
25
+
26
+ function safeReadText(absPath, maxChars) {
27
+ try {
28
+ if (!fs.existsSync(absPath)) return null;
29
+ const fd = fs.openSync(absPath, "r");
30
+ const buf = Buffer.alloc(maxChars || 8000);
31
+ const n = fs.readSync(fd, buf, 0, buf.length, 0);
32
+ fs.closeSync(fd);
33
+ return buf.slice(0, n).toString("utf8");
34
+ } catch { return null; }
35
+ }
36
+
37
+ function pass(id, label, evidence, detail) {
38
+ return { id, label, status: "pass", evidence: evidence || null, detail: detail || null, safeNextAction: null };
39
+ }
40
+ function warn(id, label, safeNextAction, evidence, detail) {
41
+ return { id, label, status: "warn", evidence: evidence || null, detail: detail || null, safeNextAction: safeNextAction || "Review and resolve." };
42
+ }
43
+ function blocked(id, label, safeNextAction, evidence, detail) {
44
+ return { id, label, status: "blocked", evidence: evidence || null, detail: detail || null, safeNextAction: safeNextAction || "Fix blocker before proceeding." };
45
+ }
46
+
47
+ // ── Safety Checks ─────────────────────────────────────────────────────────────
48
+
49
+ function checkNoCrossAdapterStateLeak(cwd) {
50
+ // Check that state directories are per-host isolated
51
+ const hostsStateDir = path.join(cwd, ".claude/cco/state/hosts");
52
+ if (!fs.existsSync(hostsStateDir)) {
53
+ return pass("no_cross_adapter_state_leak", "No cross-adapter state found (hosts state dir absent)",
54
+ { hostsStateDirExists: false }, "Host state isolation not needed until multi-host session detected.");
55
+ }
56
+
57
+ // Check if host state files exist and that they have distinct ids (not sharing state)
58
+ let hostFiles = [];
59
+ try { hostFiles = fs.readdirSync(hostsStateDir).filter(function(f) { return f.endsWith(".json"); }); } catch { /* ignore */ }
60
+
61
+ const hostIds = new Set();
62
+ let hasConflict = false;
63
+ for (const f of hostFiles) {
64
+ const data = safeReadJson(path.join(hostsStateDir, f));
65
+ if (data && data.id) {
66
+ if (hostIds.has(data.id)) { hasConflict = true; break; }
67
+ hostIds.add(data.id);
68
+ }
69
+ }
70
+
71
+ if (hasConflict) {
72
+ return blocked("no_cross_adapter_state_leak", "Cross-adapter state conflict detected",
73
+ "Remove duplicate host state files from .claude/cco/state/hosts/.",
74
+ { hostFileCount: hostFiles.length });
75
+ }
76
+
77
+ return pass("no_cross_adapter_state_leak", "No cross-adapter state conflict",
78
+ { hostFileCount: hostFiles.length, hostIds: Array.from(hostIds) });
79
+ }
80
+
81
+ function checkHookTimeoutRespected(cwd) {
82
+ const settingsPath = path.join(cwd, ".claude/settings.json");
83
+ const settings = safeReadJson(settingsPath);
84
+ if (!settings) {
85
+ return warn("hook_timeout_respected", "No .claude/settings.json found",
86
+ "Run: node bin/avorelo activate to generate settings.json with hook timeout config.",
87
+ null, ".claude/settings.json not found.");
88
+ }
89
+
90
+ // Check if hooks have timeout configured
91
+ const hooks = settings.hooks || {};
92
+ const hookEntries = Object.values(hooks);
93
+ const allHaveTimeout = hookEntries.length === 0 || hookEntries.every(function(h) {
94
+ const hooksArr = Array.isArray(h) ? h : [h];
95
+ return hooksArr.every(function(entry) {
96
+ return !entry || entry.timeout !== undefined || entry.timeoutMs !== undefined;
97
+ });
98
+ });
99
+
100
+ if (!allHaveTimeout) {
101
+ return warn("hook_timeout_respected", "Some hooks may lack explicit timeout",
102
+ "Add timeoutMs to hook definitions in .claude/settings.json.",
103
+ { hookCount: hookEntries.length });
104
+ }
105
+
106
+ return pass("hook_timeout_respected", "Hook configuration present",
107
+ { hookCount: hookEntries.length, settingsPresent: true });
108
+ }
109
+
110
+ function checkMcpIsolation(cwd) {
111
+ const settingsPath = path.join(cwd, ".claude/settings.json");
112
+ const settings = safeReadJson(settingsPath);
113
+ if (!settings) {
114
+ return warn("mcp_isolation", "No .claude/settings.json found for MCP config check",
115
+ "Run: node bin/avorelo activate to initialize settings.",
116
+ null);
117
+ }
118
+
119
+ // Check for dangerouslyAllowUnrestrictedMcpTools or similar unsafe flags
120
+ const settingsText = safeReadText(settingsPath, 5000) || "";
121
+ if (/dangerouslyAllowUnrestrictedMcpTools.*true|skipMcpValidation.*true/i.test(settingsText)) {
122
+ return blocked("mcp_isolation", "Unsafe MCP config flag detected",
123
+ "Remove dangerouslyAllowUnrestrictedMcpTools or skipMcpValidation from settings.",
124
+ { flagFound: true });
125
+ }
126
+
127
+ return pass("mcp_isolation", "No unsafe MCP isolation flags found",
128
+ { settingsChecked: true });
129
+ }
130
+
131
+ function checkNoTokenInAdapterConfig(cwd) {
132
+ const pathsToCheck = [
133
+ ".claude/settings.json",
134
+ ".claude/settings.local.json",
135
+ ".cursor/settings.json",
136
+ ".windsurf/settings.json",
137
+ ];
138
+
139
+ const issues = [];
140
+ for (const relPath of pathsToCheck) {
141
+ const absPath = path.join(cwd, relPath);
142
+ const text = safeReadText(absPath, 5000);
143
+ if (text && /token|secret|password|_authToken/i.test(text)) {
144
+ // Filter out false positives from non-credential fields
145
+ if (/["']?(?:token|secret|password|_authToken)["']?\s*[:=]\s*["'][^"']{6,}/i.test(text)) {
146
+ issues.push(relPath);
147
+ }
148
+ }
149
+ }
150
+
151
+ if (issues.length > 0) {
152
+ return blocked("no_token_in_adapter_config", "Token/secret found in adapter config",
153
+ "Remove tokens from adapter config files: " + issues.join(", "),
154
+ { files: issues });
155
+ }
156
+
157
+ return pass("no_token_in_adapter_config", "No tokens found in adapter config files",
158
+ { checked: pathsToCheck });
159
+ }
160
+
161
+ function checkHookSafetyBoundaryArtifact(cwd) {
162
+ const artifactPath = path.join(cwd, ".claude/cco/orchestration/full-readiness/latest-hook-safety-boundary.json");
163
+ const artifact = safeReadJson(artifactPath);
164
+ if (!artifact) {
165
+ // Check alternate path
166
+ const altPath = path.join(cwd, ".claude/cco/orchestration/hook-safety-boundary/latest-hook-safety-boundary-readiness.json");
167
+ const altArtifact = safeReadJson(altPath);
168
+ if (!altArtifact) {
169
+ return warn("hook_safety_boundary_artifact", "Hook safety boundary artifact not found",
170
+ "Run: node bin/avorelo hook-safety --json to generate hook safety boundary.",
171
+ null, "Artifact not found.");
172
+ }
173
+ return pass("hook_safety_boundary_artifact", "Hook safety boundary artifact present",
174
+ { path: altPath });
175
+ }
176
+ return pass("hook_safety_boundary_artifact", "Hook safety boundary artifact present",
177
+ { path: artifactPath });
178
+ }
179
+
180
+ function checkNoAutoApplyWithoutApproval(cwd) {
181
+ const settingsPath = path.join(cwd, ".claude/settings.json");
182
+ const text = safeReadText(settingsPath, 8000);
183
+ if (!text) {
184
+ return warn("no_auto_apply_without_approval", "Cannot verify auto-apply policy — settings.json missing",
185
+ "Run: node bin/avorelo activate to initialize settings.",
186
+ null);
187
+ }
188
+
189
+ // Check for auto-apply patterns that skip user approval
190
+ if (/autoApply.*true|autoHookApply.*true|skipApproval.*true/i.test(text)) {
191
+ return blocked("no_auto_apply_without_approval", "Auto-apply without approval found in settings",
192
+ "Remove autoApply/autoHookApply/skipApproval flags. All hook config changes require explicit approval.",
193
+ { flagFound: true });
194
+ }
195
+
196
+ return pass("no_auto_apply_without_approval", "No auto-apply without approval found",
197
+ { settingsChecked: true });
198
+ }
199
+
200
+ // ── Build Adapter Safety Boundaries ───────────────────────────────────────────
201
+
202
+ function buildAdapterSafetyBoundaries(cwd, options) {
203
+ const checks = [
204
+ checkNoCrossAdapterStateLeak(cwd),
205
+ checkHookTimeoutRespected(cwd),
206
+ checkMcpIsolation(cwd),
207
+ checkNoTokenInAdapterConfig(cwd),
208
+ checkHookSafetyBoundaryArtifact(cwd),
209
+ checkNoAutoApplyWithoutApproval(cwd),
210
+ ];
211
+
212
+ const blockers = checks.filter(function(c) { return c.status === "blocked"; });
213
+ const warnings = checks.filter(function(c) { return c.status === "warn"; });
214
+
215
+ var status;
216
+ if (blockers.length > 0) {
217
+ status = "blocked";
218
+ } else if (warnings.length > 0) {
219
+ status = "warn";
220
+ } else {
221
+ status = "pass";
222
+ }
223
+
224
+ const safeNextAction = blockers.length > 0
225
+ ? "Fix safety boundary blockers immediately. Remove tokens from configs. Remove auto-apply flags."
226
+ : warnings.length > 0
227
+ ? "Review safety warnings. Ensure hook timeout and MCP isolation config is in place."
228
+ : "All adapter safety boundaries verified. Proceed to host support context.";
229
+
230
+ return {
231
+ contract: CONTRACT,
232
+ schemaVersion: SCHEMA_VERSION,
233
+ generatedAt: nowIso(),
234
+ status,
235
+ checks,
236
+ blockerCount: blockers.length,
237
+ warningCount: warnings.length,
238
+ approvalRequiredBeforeApply: true,
239
+ safeNextAction,
240
+ noPublicLaunchClaim: true,
241
+ redacted: true,
242
+ };
243
+ }
244
+
245
+ // ── Write ─────────────────────────────────────────────────────────────────────
246
+
247
+ function writeAdapterSafetyBoundaries(cwd, boundaries) {
248
+ const dir = path.join(cwd, ARTIFACT_DIR_REL);
249
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
250
+ fs.writeFileSync(path.join(cwd, ARTIFACT_REL), JSON.stringify(boundaries, null, 2));
251
+ }
252
+
253
+ // ── Surface ───────────────────────────────────────────────────────────────────
254
+
255
+ function buildAdapterSafetyBoundariesSurface(cwd, options) {
256
+ const boundaries = buildAdapterSafetyBoundaries(cwd, options);
257
+ writeAdapterSafetyBoundaries(cwd, boundaries);
258
+ try {
259
+ appendProductLearningEvent(cwd, {
260
+ event: "adapter_safety_boundaries_built",
261
+ contract: CONTRACT,
262
+ status: boundaries.status,
263
+ blockerCount: boundaries.blockerCount,
264
+ });
265
+ } catch { /* non-fatal */ }
266
+ return {
267
+ status: boundaries.status,
268
+ blockerCount: boundaries.blockerCount,
269
+ warningCount: boundaries.warningCount,
270
+ approvalRequiredBeforeApply: true,
271
+ noPublicLaunchClaim: true,
272
+ };
273
+ }
274
+
275
+ // ── Format ────────────────────────────────────────────────────────────────────
276
+
277
+ function formatAdapterSafetyBoundariesText(boundaries) {
278
+ var lines = [
279
+ "Adapter Safety Boundaries [" + (boundaries.status || "?").toUpperCase() + "]",
280
+ " Approval required before apply: true",
281
+ " Blockers: " + (boundaries.blockerCount || 0),
282
+ " Warnings: " + (boundaries.warningCount || 0),
283
+ ];
284
+ if (boundaries.checks) {
285
+ boundaries.checks.forEach(function(c) {
286
+ if (c.status === "blocked" || c.status === "warn") {
287
+ lines.push(" [" + c.status.toUpperCase() + "] " + c.label + (c.safeNextAction ? " → " + c.safeNextAction : ""));
288
+ }
289
+ });
290
+ }
291
+ lines.push(" Next: " + (boundaries.safeNextAction || "Review adapter safety boundaries."));
292
+ return lines.join("\n");
293
+ }
294
+
295
+ // ── Validate Host Safety Boundaries ──────────────────────────────────────────
296
+ // Per-host validation wrapper used by PR #163 cross-host checks.
297
+
298
+ function validateHostSafetyBoundaries(cwd, hostId, options) {
299
+ options = options || {};
300
+ const boundaries = buildAdapterSafetyBoundaries(cwd, options);
301
+ // Filter checks relevant to this host (most checks are host-agnostic)
302
+ const hostChecks = boundaries.checks.filter(function(c) {
303
+ // All checks apply to detected hosts; filter only if host-specific id patterns
304
+ return true;
305
+ });
306
+ const blockers = hostChecks.filter(function(c) { return c.status === "blocked"; });
307
+ const warnings = hostChecks.filter(function(c) { return c.status === "warn"; });
308
+ const status = blockers.length > 0 ? "blocked" : warnings.length > 0 ? "warn" : "pass";
309
+ return {
310
+ hostId: hostId || "unknown",
311
+ status,
312
+ checks: hostChecks,
313
+ blockerCount: blockers.length,
314
+ warningCount: warnings.length,
315
+ approvalRequiredBeforeApply: true,
316
+ safeNextAction: boundaries.safeNextAction,
317
+ };
318
+ }
319
+
320
+ module.exports = {
321
+ CONTRACT,
322
+ SCHEMA_VERSION,
323
+ ARTIFACT_REL,
324
+ buildAdapterSafetyBoundaries,
325
+ writeAdapterSafetyBoundaries,
326
+ buildAdapterSafetyBoundariesSurface,
327
+ formatAdapterSafetyBoundariesText,
328
+ checkNoCrossAdapterStateLeak,
329
+ checkHookTimeoutRespected,
330
+ checkMcpIsolation,
331
+ checkNoTokenInAdapterConfig,
332
+ checkHookSafetyBoundaryArtifact,
333
+ checkNoAutoApplyWithoutApproval,
334
+ validateHostSafetyBoundaries,
335
+ };
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+
3
+ // ── Adapter Technical Readiness Gate ─────────────────────────────────────────
4
+ // Contract: avorelo.adapterTechnicalReadinessGate.v1
5
+ // Answers: "Are all plugin/adapter technical readiness signals green? Is it safe
6
+ // to proceed to alpha launch with multi-host adapter support?"
7
+ // Aggregates: host-capability-matrix, cross-host-install, cross-host-value-flow,
8
+ // adapter-safety-boundaries, host-support-context, browser-proof-preflight
9
+ // Read-only. Does NOT write to any adapter config. Does NOT launch browsers.
10
+
11
+ const fs = require("fs");
12
+ const path = require("path");
13
+ const { nowIso } = require("./fsx");
14
+ const { appendProductLearningEvent } = require("./product-learning-events");
15
+ const { buildHostCapabilityMatrix } = require("./host-capability-matrix");
16
+ const { buildCrossHostInstallReadiness } = require("./cross-host-install-readiness");
17
+ const { buildCrossHostValueFlow } = require("./cross-host-value-flow");
18
+ const { buildAdapterSafetyBoundaries } = require("./adapter-safety-boundaries");
19
+ const { buildHostSupportContext } = require("./host-support-context");
20
+ const { buildBrowserProofPreflight } = require("./browser-proof-preflight");
21
+
22
+ const CONTRACT = "avorelo.adapterTechnicalReadinessGate.v1";
23
+ const SCHEMA_VERSION = 1;
24
+ const ARTIFACT_DIR_REL = ".claude/cco/orchestration/adapter-readiness";
25
+ const ARTIFACT_REL = ARTIFACT_DIR_REL + "/latest-technical-gate.json";
26
+
27
+ // ── Score Weights ─────────────────────────────────────────────────────────────
28
+ // Each sub-module contributes a portion of the total score (100 pts total).
29
+ // Safety boundaries are weighted highest — a blocker there is critical.
30
+ const SCORE_WEIGHTS = {
31
+ adapter_safety_boundaries: 25, // Safety is highest priority
32
+ cross_host_value_flow: 20, // Value must flow across hosts
33
+ host_capability_matrix: 15, // Know what each host can do
34
+ cross_host_install: 15, // Install path must work
35
+ host_support_context: 15, // Support must be diagnosable per host
36
+ browser_proof_preflight: 10, // Browser preflight: local-first verified
37
+ };
38
+
39
+ const STATUS_SCORE = { pass: 1.0, warn: 0.5, blocked: 0.0, info: 1.0 };
40
+
41
+ function scoreSignal(moduleName, status) {
42
+ const weight = SCORE_WEIGHTS[moduleName] || 0;
43
+ const factor = STATUS_SCORE[status] != null ? STATUS_SCORE[status] : 0.5;
44
+ return Math.round(weight * factor);
45
+ }
46
+
47
+ // ── Build Gate ────────────────────────────────────────────────────────────────
48
+
49
+ function buildAdapterTechnicalReadinessGate(cwd, options) {
50
+ // Run all sub-modules (read-only, no side effects)
51
+ const hostMatrix = buildHostCapabilityMatrix(cwd, options);
52
+ const crossInstall = buildCrossHostInstallReadiness(cwd, options);
53
+ const valueFlow = buildCrossHostValueFlow(cwd, options);
54
+ const safetyBoundaries = buildAdapterSafetyBoundaries(cwd, options);
55
+ const supportContext = buildHostSupportContext(cwd, options);
56
+ const browserPreflight = buildBrowserProofPreflight(cwd, options);
57
+
58
+ // Summary per sub-module
59
+ const signals = {
60
+ host_capability_matrix: { status: hostMatrix.status, blockers: hostMatrix.blockerCount, warnings: hostMatrix.warningCount },
61
+ cross_host_install: { status: crossInstall.status, blockers: crossInstall.blockerCount, warnings: crossInstall.warningCount },
62
+ cross_host_value_flow: { status: valueFlow.status, blockers: valueFlow.blockerCount, warnings: valueFlow.warningCount },
63
+ adapter_safety_boundaries: { status: safetyBoundaries.status, blockers: safetyBoundaries.blockerCount, warnings: safetyBoundaries.warningCount },
64
+ host_support_context: { status: supportContext.status, blockers: supportContext.blockerCount, warnings: supportContext.warningCount },
65
+ browser_proof_preflight: { status: browserPreflight.status, blockers: browserPreflight.blockerCount, warnings: browserPreflight.warningCount, browserRequired: false, noBrowserLaunch: true },
66
+ };
67
+
68
+ // Score
69
+ var score = 0;
70
+ Object.keys(signals).forEach(function(k) {
71
+ score += scoreSignal(k, signals[k].status);
72
+ });
73
+
74
+ // Overall status
75
+ const anyBlocked = Object.values(signals).some(function(s) { return s.status === "blocked"; });
76
+ const anyWarn = Object.values(signals).some(function(s) { return s.status === "warn"; });
77
+
78
+ var status;
79
+ if (anyBlocked) {
80
+ status = "blocked";
81
+ } else if (anyWarn) {
82
+ status = "warn";
83
+ } else {
84
+ status = "pass";
85
+ }
86
+
87
+ // Counts
88
+ const totalBlockers = Object.values(signals).reduce(function(n, s) { return n + (s.blockers || 0); }, 0);
89
+ const totalWarnings = Object.values(signals).reduce(function(n, s) { return n + (s.warnings || 0); }, 0);
90
+
91
+ // Safe next action
92
+ var safeNextAction;
93
+ if (anyBlocked) {
94
+ const blockedModules = Object.entries(signals)
95
+ .filter(function([, s]) { return s.status === "blocked"; })
96
+ .map(function([k]) { return k; });
97
+ safeNextAction = "Fix adapter readiness blockers in: " + blockedModules.join(", ") + ". Resolve before alpha launch.";
98
+ } else if (anyWarn) {
99
+ safeNextAction = "Review adapter readiness warnings. Run bounded tasks to populate proof/ledger/support-bundle artifacts.";
100
+ } else {
101
+ safeNextAction = "Adapter Technical Readiness gate passed (score " + score + "/100). Multi-host adapter support verified. Safe to proceed to alpha launch candidate prep.";
102
+ }
103
+
104
+ // Verdict for company loop
105
+ var verdict;
106
+ if (score >= 90) {
107
+ verdict = "adapter_ready";
108
+ } else if (score >= 60) {
109
+ verdict = "adapter_partial";
110
+ } else {
111
+ verdict = "adapter_not_ready";
112
+ }
113
+
114
+ return {
115
+ contract: CONTRACT,
116
+ schemaVersion: SCHEMA_VERSION,
117
+ generatedAt: nowIso(),
118
+ status,
119
+ score,
120
+ verdict,
121
+ signals,
122
+ totalBlockers,
123
+ totalWarnings,
124
+ blockerCount: totalBlockers,
125
+ warningCount: totalWarnings,
126
+ safeNextAction,
127
+ browserRequired: false,
128
+ noBrowserLaunch: true,
129
+ noWorksEverywhereClaim: true,
130
+ noPublicLaunchClaim: true,
131
+ redacted: true,
132
+ };
133
+ }
134
+
135
+ // ── Write ─────────────────────────────────────────────────────────────────────
136
+
137
+ function writeAdapterTechnicalReadinessGate(cwd, gate) {
138
+ const dir = path.join(cwd, ARTIFACT_DIR_REL);
139
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
140
+ fs.writeFileSync(path.join(cwd, ARTIFACT_REL), JSON.stringify(gate, null, 2));
141
+ }
142
+
143
+ // ── Surface ───────────────────────────────────────────────────────────────────
144
+
145
+ function buildAdapterTechnicalReadinessSurface(cwd, options) {
146
+ const gate = buildAdapterTechnicalReadinessGate(cwd, options);
147
+ writeAdapterTechnicalReadinessGate(cwd, gate);
148
+ try {
149
+ appendProductLearningEvent(cwd, {
150
+ event: "adapter_technical_readiness_gate_run",
151
+ contract: CONTRACT,
152
+ status: gate.status,
153
+ score: gate.score,
154
+ verdict: gate.verdict,
155
+ totalBlockers: gate.totalBlockers,
156
+ browserRequired: false,
157
+ });
158
+ } catch { /* non-fatal */ }
159
+ return {
160
+ status: gate.status,
161
+ score: gate.score,
162
+ verdict: gate.verdict,
163
+ signals: gate.signals,
164
+ blockerCount: gate.blockerCount,
165
+ warningCount: gate.warningCount,
166
+ browserRequired: false,
167
+ noBrowserLaunch: true,
168
+ noPublicLaunchClaim: true,
169
+ };
170
+ }
171
+
172
+ // ── Format ────────────────────────────────────────────────────────────────────
173
+
174
+ function formatAdapterTechnicalReadinessText(gate) {
175
+ var lines = [
176
+ "Adapter Technical Readiness Gate [" + (gate.status || "?").toUpperCase() + "] score=" + (gate.score || 0) + "/100 verdict=" + (gate.verdict || "?"),
177
+ " Browser required: no | Browser launched: no",
178
+ ];
179
+ if (gate.signals) {
180
+ Object.entries(gate.signals).forEach(function([k, s]) {
181
+ var suffix = "";
182
+ if (s.blockers > 0) suffix += " (" + s.blockers + " blocker" + (s.blockers !== 1 ? "s" : "") + ")";
183
+ if (s.warnings > 0) suffix += " (" + s.warnings + " warning" + (s.warnings !== 1 ? "s" : "") + ")";
184
+ lines.push(" " + k + ": " + s.status + suffix);
185
+ });
186
+ }
187
+ lines.push(
188
+ " Total blockers: " + (gate.totalBlockers || 0),
189
+ " Total warnings: " + (gate.totalWarnings || 0),
190
+ " Next: " + (gate.safeNextAction || "Review adapter technical readiness.")
191
+ );
192
+ return lines.join("\n");
193
+ }
194
+
195
+ module.exports = {
196
+ CONTRACT,
197
+ SCHEMA_VERSION,
198
+ ARTIFACT_REL,
199
+ SCORE_WEIGHTS,
200
+ buildAdapterTechnicalReadinessGate,
201
+ writeAdapterTechnicalReadinessGate,
202
+ buildAdapterTechnicalReadinessSurface,
203
+ formatAdapterTechnicalReadinessText,
204
+ scoreSignal,
205
+ };