@moretea-labs/forge 1.7.2 → 1.8.1

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 (900) hide show
  1. package/AGENTS.md +121 -62
  2. package/CHANGELOG.md +40 -0
  3. package/CLAUDE.md +57 -62
  4. package/CONTRIBUTING.md +3 -2
  5. package/README.md +2 -2
  6. package/SKILL.md +0 -1
  7. package/THIRD_PARTY_NOTICES.md +5 -2
  8. package/adapters/browser/index.ts +2 -0
  9. package/adapters/chatgpt/browser-delivery-host.ts +77 -0
  10. package/adapters/chatgpt/browser-delivery-runtime.ts +1256 -0
  11. package/adapters/chatgpt/controller-binding-store.ts +134 -0
  12. package/adapters/chatgpt/controller-round-host.ts +68 -0
  13. package/adapters/chatgpt/controller-round-settlement-store.ts +99 -0
  14. package/adapters/chatgpt/provider-delivery.ts +340 -0
  15. package/adapters/chatgpt/work-conversation-binding-store.ts +218 -0
  16. package/adapters/chatgpt/wsl-bridge-delivery-host.ts +63 -0
  17. package/adapters/computer/chatgpt-extension-target.ts +463 -0
  18. package/adapters/computer/chatgpt-target-router.ts +103 -0
  19. package/adapters/computer/chrome-extension/background.js +385 -0
  20. package/adapters/computer/chrome-extension/content.js +378 -0
  21. package/adapters/computer/chrome-extension/core.js +24 -0
  22. package/adapters/computer/chrome-extension/manifest.json +30 -0
  23. package/adapters/computer/desktop-operator-contract.ts +7 -0
  24. package/adapters/computer/desktop-operator-discovery.ts +181 -0
  25. package/adapters/computer/desktop-operator-negotiation.ts +174 -0
  26. package/adapters/computer/desktop-operator-provider.ts +312 -0
  27. package/adapters/computer/index.ts +1 -0
  28. package/adapters/computer/interaction-target-authority.ts +1068 -0
  29. package/adapters/controller-process/binding-store.ts +34 -0
  30. package/adapters/controller-process/controller-host.ts +26 -0
  31. package/adapters/mcp/access-mode.ts +132 -0
  32. package/adapters/mcp/audit.ts +32 -0
  33. package/adapters/mcp/auth.ts +406 -0
  34. package/adapters/mcp/instructions.ts +37 -0
  35. package/adapters/mcp/legacy-context.ts +18 -0
  36. package/adapters/mcp/multi-repository.ts +421 -0
  37. package/adapters/mcp/oauth.ts +464 -0
  38. package/adapters/mcp/paths.ts +143 -0
  39. package/adapters/mcp/policy.ts +232 -0
  40. package/adapters/mcp/proxy-env.ts +62 -0
  41. package/adapters/mcp/readiness-projection.ts +24 -0
  42. package/adapters/mcp/redaction.ts +21 -0
  43. package/adapters/mcp/repo.ts +24 -0
  44. package/adapters/mcp/runtime-gateway/artifact-adapter.ts +52 -0
  45. package/adapters/mcp/runtime-gateway/automation-receipt-adapter.ts +87 -0
  46. package/adapters/mcp/runtime-gateway/bounded-result-runtime.ts +62 -0
  47. package/adapters/mcp/runtime-gateway/cognition-settlement.ts +201 -0
  48. package/adapters/mcp/runtime-gateway/context-adapter.ts +1167 -0
  49. package/adapters/mcp/runtime-gateway/context-pack-sidecar.ts +91 -0
  50. package/adapters/mcp/runtime-gateway/controller-authority-adapter.ts +206 -0
  51. package/adapters/mcp/runtime-gateway/core-capability-adapter.ts +258 -0
  52. package/adapters/mcp/runtime-gateway/engineering-preconditions.ts +130 -0
  53. package/adapters/mcp/runtime-gateway/engineering-tool-contract.ts +15 -0
  54. package/adapters/mcp/runtime-gateway/execution-control-adapter.ts +28 -0
  55. package/adapters/mcp/runtime-gateway/execution-tools.ts +173 -0
  56. package/adapters/mcp/runtime-gateway/filesystem-adapter.ts +38 -0
  57. package/adapters/mcp/runtime-gateway/gateway-execution-adapter.ts +412 -0
  58. package/adapters/mcp/runtime-gateway/legacy-ios-tool-adapter.ts +105 -0
  59. package/adapters/mcp/runtime-gateway/maintenance-adapter.ts +44 -0
  60. package/adapters/mcp/runtime-gateway/model-adapter.ts +63 -0
  61. package/adapters/mcp/runtime-gateway/persisted-check-process.ts +3 -0
  62. package/adapters/mcp/runtime-gateway/plugin-adapter.ts +380 -0
  63. package/adapters/mcp/runtime-gateway/process-tools.ts +457 -0
  64. package/adapters/mcp/runtime-gateway/protected-computer-adapter.ts +88 -0
  65. package/adapters/mcp/runtime-gateway/recovery-adapter.ts +285 -0
  66. package/adapters/mcp/runtime-gateway/recovery-client-adapter.ts +70 -0
  67. package/adapters/mcp/runtime-gateway/recovery-tool-contract.ts +99 -0
  68. package/adapters/mcp/runtime-gateway/repository-compat-adapter.ts +79 -0
  69. package/adapters/mcp/runtime-gateway/result-adapter.ts +114 -0
  70. package/adapters/mcp/runtime-gateway/router.ts +242 -0
  71. package/adapters/mcp/runtime-gateway/routing-policy.ts +499 -0
  72. package/adapters/mcp/runtime-gateway/runtime-observation-adapter.ts +1200 -0
  73. package/adapters/mcp/runtime-gateway/runtime-readiness-observation.ts +218 -0
  74. package/adapters/mcp/runtime-gateway/runtime-tool-definitions.ts +574 -0
  75. package/adapters/mcp/runtime-gateway/runtime-tool-shared.ts +27 -0
  76. package/adapters/mcp/runtime-gateway/runtime-tools.ts +78 -0
  77. package/adapters/mcp/runtime-gateway/scheduler-adapter.ts +187 -0
  78. package/adapters/mcp/runtime-gateway/shared-adapter.ts +45 -0
  79. package/adapters/mcp/runtime-gateway/status-inbox-adapter.ts +962 -0
  80. package/adapters/mcp/runtime-gateway/typescript-navigation-sidecar.ts +136 -0
  81. package/adapters/mcp/runtime-gateway/work-adapter.ts +325 -0
  82. package/adapters/mcp/runtime-gateway/work-controller-operations.ts +257 -0
  83. package/adapters/mcp/runtime-gateway/work-detail-projection.ts +60 -0
  84. package/adapters/mcp/runtime-gateway/work-input-wire-migration.ts +246 -0
  85. package/adapters/mcp/runtime-gateway/work-learning-operations.ts +145 -0
  86. package/adapters/mcp/runtime-gateway/work-list-projection.ts +38 -0
  87. package/adapters/mcp/runtime-gateway/work-plan-operations.ts +382 -0
  88. package/adapters/mcp/runtime-gateway/work-repair-adapter.ts +308 -0
  89. package/adapters/mcp/runtime-gateway/work-requirement-operations.ts +148 -0
  90. package/adapters/mcp/runtime-gateway/work-semantic-operations.ts +263 -0
  91. package/adapters/mcp/runtime-gateway/work-validation-reconciler.ts +1 -0
  92. package/adapters/mcp/runtime-gateway/work-workflow-operations.ts +113 -0
  93. package/adapters/mcp/runtime-gateway/workflow-supervisor-adapter.ts +156 -0
  94. package/adapters/mcp/server.ts +1092 -0
  95. package/adapters/mcp/setup.ts +789 -0
  96. package/adapters/mcp/tool-capability-cache.ts +87 -0
  97. package/adapters/mcp/tool-mapping/access-tools.ts +387 -0
  98. package/adapters/mcp/tool-mapping/legacy-tool-service.ts +5139 -0
  99. package/adapters/mcp/tool-mapping/post-finalize-work-attribution.ts +145 -0
  100. package/adapters/mcp/tool-mapping/repository-tools.ts +1682 -0
  101. package/adapters/mcp/tool-mapping/tools.ts +9 -0
  102. package/adapters/mcp/tool-mapping/umbrella-tools.ts +117 -0
  103. package/adapters/mcp/toolset-names.ts +79 -0
  104. package/adapters/mcp/toolset-selection.ts +41 -0
  105. package/adapters/mcp/toolset.ts +337 -0
  106. package/adapters/mcp/transports/http-observation.ts +365 -0
  107. package/adapters/mcp/transports/http.ts +933 -0
  108. package/adapters/mcp/transports/oauth-http.ts +322 -0
  109. package/adapters/mcp/transports/session-registry.ts +519 -0
  110. package/adapters/mcp/transports/stdio.ts +8 -0
  111. package/adapters/mcp/tunnels/openai-secure-tunnel.ts +223 -0
  112. package/adapters/mcp/types.ts +41 -0
  113. package/assets/AGENTS.md +2 -16
  114. package/assets/CLAUDE.md +2 -16
  115. package/assets/hooks/AGENTS.md +3 -14
  116. package/assets/hooks/CLAUDE.md +3 -14
  117. package/assets/hooks/hook-input.sh +9 -2
  118. package/assets/hooks/lib/workflow-state.sh +28 -10
  119. package/assets/hooks/prompt-guard.sh +63 -37
  120. package/assets/hooks/security-sentinel.sh +2 -1
  121. package/assets/hooks/session-start-context.sh +7 -5
  122. package/assets/hooks/stop-orchestrator.sh +13 -3
  123. package/assets/initializer-question-pack.v4.json +11 -7
  124. package/assets/partials/05-workflow.partial.md +18 -73
  125. package/assets/partials/07-footer.partial.md +1 -1
  126. package/assets/partials-agents/02-operating-mode.partial.md +1 -2
  127. package/assets/partials-agents/04-task-protocol.partial.md +14 -59
  128. package/assets/partials-agents/06-quality-safety.partial.md +11 -16
  129. package/assets/partials-agents/08-deep-docs.partial.md +1 -2
  130. package/assets/plan-map.json +11 -11
  131. package/assets/plugin-registry.v1.json +11 -3
  132. package/assets/plugin-trust-policy.v1.json +6 -0
  133. package/assets/recovery/ForgeRecovery.ps1 +100 -0
  134. package/assets/recovery/forge-wsl-rescue +271 -0
  135. package/assets/reference-configs/agentic-development-flow.md +25 -0
  136. package/assets/reference-configs/development-protocol.md +11 -15
  137. package/assets/reference-configs/document-generation.md +1 -1
  138. package/assets/reference-configs/global-working-rules.md +28 -1
  139. package/assets/reference-configs/harness-overview.md +22 -112
  140. package/assets/reference-configs/hook-operations.md +1 -1
  141. package/assets/reference-configs/sprint-contracts.md +2 -2
  142. package/assets/skill-version.json +2 -2
  143. package/assets/templates/helpers/architecture-event.ts +3 -34
  144. package/assets/templates/helpers/architecture-queue.sh +61 -10
  145. package/assets/templates/helpers/archive-workflow.sh +90 -180
  146. package/assets/templates/helpers/capability-config.ts +8 -11
  147. package/assets/templates/helpers/capability-resolver.ts +37 -19
  148. package/assets/templates/helpers/capture-plan.sh +2 -2
  149. package/assets/templates/helpers/check-architecture-sync.sh +1 -9
  150. package/assets/templates/helpers/check-task-sync.sh +82 -11
  151. package/assets/templates/helpers/check-task-workflow.sh +1 -3
  152. package/assets/templates/helpers/context-contract-sync.sh +1 -12
  153. package/assets/templates/helpers/contract-worktree.sh +26 -24
  154. package/assets/templates/helpers/ensure-task-workflow.sh +6 -8
  155. package/assets/templates/helpers/inspect-project-state.ts +1 -1
  156. package/assets/templates/helpers/migrate-project-template.sh +1 -1
  157. package/assets/templates/helpers/migrate-workflow-docs.ts +53 -239
  158. package/assets/templates/helpers/new-plan.sh +2 -2
  159. package/assets/templates/helpers/plan-to-todo.sh +3 -31
  160. package/assets/templates/helpers/sprint-backlog.sh +1 -1
  161. package/assets/templates/helpers/switch-plan.sh +1 -1
  162. package/assets/templates/helpers/workflow-contract.ts +1 -0
  163. package/assets/workflow-contract.v1.json +63 -171
  164. package/assets/workflows/xiaohongshu/xiaohongshu.collect-metrics.v1.draft.json +118 -0
  165. package/assets/workflows/xiaohongshu/xiaohongshu.publish-image-note.v1.draft.json +316 -0
  166. package/assets/workflows/xiaohongshu/xiaohongshu.publish-long-text.v1.draft.json +324 -0
  167. package/docs/architecture/CURRENT.md +233 -28
  168. package/docs/architecture/EVOLUTION.md +13 -0
  169. package/docs/architecture/decisions/20260801-controller-home-sqlite-state.md +2 -1
  170. package/docs/architecture/decisions/20260803-release-identity-binding-and-exit-policy.md +14 -5
  171. package/docs/architecture/decisions/20260823-immediate-controller-relay.md +6 -3
  172. package/docs/architecture/decisions/20260831-independent-windows-wsl-host-rescue.md +59 -0
  173. package/docs/architecture/decisions/20260904-ios-device-migration-baseline.md +120 -0
  174. package/docs/architecture/decisions/20260904-repository-runtime-data-boundary.md +42 -0
  175. package/docs/architecture/decisions/20260907-assistant-learning-loop.md +37 -0
  176. package/docs/architecture/decisions/20260907-controller-round-transition-policy.md +311 -0
  177. package/docs/architecture/decisions/20260907-maintenance-diagnosis-bounded-read.md +39 -0
  178. package/docs/architecture/decisions/20260916-workflow-supervisor-authority.md +249 -0
  179. package/docs/architecture/decisions/20260917-cognitive-memory-foundation.md +82 -0
  180. package/docs/architecture/decisions/20260918-stable-candidate-release-lifecycle.md +221 -0
  181. package/docs/architecture/decisions/20260919-autonomous-work-liveness.md +62 -0
  182. package/docs/architecture/decisions/20260924-thin-semantic-working-context.md +72 -0
  183. package/docs/architecture/decisions/20261001-supervisor-turn-authority.md +237 -0
  184. package/docs/architecture/decisions/20261005-forge-v3-desktop-client-boundary.md +77 -0
  185. package/docs/architecture/domains/verification.md +8 -0
  186. package/docs/architecture/domains/workflow-engine.md +7 -1
  187. package/docs/architecture/index.md +3 -3
  188. package/docs/architecture/modules/controller-runtime/transport-lifecycle.md +19 -8
  189. package/docs/architecture/requests/2026-09-04-computer-plugin-workflow-taxonomy.md +124 -0
  190. package/docs/forge-chatgpt-mcp-setup.md +5 -3
  191. package/docs/forge-plugin-management.md +20 -4
  192. package/docs/forge-runtime-self-healing-loop.md +2 -0
  193. package/docs/operations/benchmark-cross-version-freeze.md +38 -0
  194. package/docs/operations/controller-browser-plugin.md +3 -1
  195. package/docs/operations/controller-performance-and-502.md +17 -0
  196. package/docs/operations/controller-reliability-runbook.md +2 -2
  197. package/docs/operations/features.md +1 -1
  198. package/docs/operations/features.zh-CN.md +1 -1
  199. package/docs/operations/homebrew.md +2 -2
  200. package/docs/operations/mcp-tool-exposure.md +2 -0
  201. package/docs/operations/platform-support.md +16 -8
  202. package/docs/operations/platform-support.zh-CN.md +2 -2
  203. package/docs/operations/releasing.md +2 -0
  204. package/docs/operations/standalone-disaster-recovery.md +38 -5
  205. package/docs/operations/uu-remote-rescue.md +41 -0
  206. package/docs/operations/windows-wsl-host-rescue.md +133 -0
  207. package/docs/public-usage-guide.md +1 -1
  208. package/docs/public-usage-guide.zh-CN.md +1 -1
  209. package/docs/tutorials/01-install-and-start.md +1 -1
  210. package/docs/tutorials/01-install-and-start.zh-CN.md +1 -1
  211. package/docs/tutorials/02-connect-chatgpt.md +4 -4
  212. package/docs/tutorials/02-connect-chatgpt.zh-CN.md +4 -4
  213. package/docs/wiki/Implementation.md +1 -1
  214. package/package.json +46 -26
  215. package/packages/kernel/cognition/api/index.ts +6 -0
  216. package/packages/kernel/cognition/application/activation-service.ts +451 -0
  217. package/packages/kernel/cognition/application/consolidation-service.ts +185 -0
  218. package/packages/kernel/cognition/application/legacy-experience-adapter.ts +38 -0
  219. package/packages/kernel/cognition/application/memory-service.ts +64 -0
  220. package/packages/kernel/cognition/domain/learning.ts +106 -0
  221. package/packages/kernel/cognition/domain/memory.ts +254 -0
  222. package/packages/kernel/controller/api/index.ts +3 -0
  223. package/packages/kernel/controller/application/continuation-service.ts +281 -0
  224. package/packages/kernel/controller/application/controller-round-service.ts +41 -0
  225. package/packages/kernel/controller/application/controller-service.ts +30 -0
  226. package/packages/kernel/controller/domain/controller-round-transition-policy.ts +529 -0
  227. package/packages/kernel/controller/domain/controller-round.ts +110 -0
  228. package/packages/kernel/controller/domain/execution-quality.ts +135 -0
  229. package/packages/kernel/controller/domain/types.ts +56 -0
  230. package/packages/kernel/controller/index.ts +1 -0
  231. package/packages/kernel/controller/infrastructure/controller-binding-store.ts +84 -0
  232. package/packages/kernel/controller/infrastructure/controller-round-store.ts +1970 -0
  233. package/packages/kernel/controller/infrastructure/controller-session-store.ts +804 -0
  234. package/packages/kernel/controller/ports/controller-host.ts +18 -0
  235. package/packages/kernel/goal/api/index.ts +1 -0
  236. package/packages/kernel/goal/domain/types.ts +40 -0
  237. package/packages/kernel/goal/index.ts +1 -0
  238. package/packages/kernel/identity/api/index.ts +15 -0
  239. package/packages/kernel/identity/application/identity-service.ts +67 -0
  240. package/packages/kernel/identity/domain/activity-projection.ts +43 -0
  241. package/packages/kernel/identity/domain/capability-broker.ts +60 -0
  242. package/packages/kernel/identity/domain/grant.ts +72 -0
  243. package/packages/kernel/identity/domain/owned-resource.ts +116 -0
  244. package/packages/kernel/identity/domain/scope.ts +63 -0
  245. package/packages/kernel/identity/domain/semantic-sync.ts +81 -0
  246. package/packages/kernel/identity/domain/types.ts +44 -0
  247. package/packages/kernel/identity/domain/user-request.ts +93 -0
  248. package/packages/kernel/identity/domain/workspace.ts +56 -0
  249. package/packages/kernel/identity/index.ts +1 -0
  250. package/packages/kernel/identity/infrastructure/activity-projection-store.ts +77 -0
  251. package/packages/kernel/identity/infrastructure/capability-broker.ts +81 -0
  252. package/packages/kernel/identity/infrastructure/grant-store.ts +284 -0
  253. package/packages/kernel/identity/infrastructure/identity-store.ts +75 -0
  254. package/packages/kernel/identity/infrastructure/owned-resource-store.ts +259 -0
  255. package/packages/kernel/identity/infrastructure/user-request-store.ts +182 -0
  256. package/packages/kernel/memory/api/index.ts +5 -0
  257. package/packages/kernel/memory/application/experience-service.ts +118 -0
  258. package/packages/kernel/memory/application/outcome-service.ts +77 -0
  259. package/packages/kernel/memory/domain/experience.ts +103 -0
  260. package/packages/kernel/memory/domain/operational-prior.ts +92 -0
  261. package/packages/kernel/memory/index.ts +1 -0
  262. package/packages/kernel/scheduler/api/index.ts +4 -0
  263. package/packages/kernel/scheduler/application/eligibility.ts +252 -0
  264. package/packages/kernel/scheduler/application/schedule-service.ts +27 -0
  265. package/packages/kernel/scheduler/application/settlement.ts +182 -0
  266. package/packages/kernel/scheduler/domain/schedule.ts +236 -0
  267. package/packages/kernel/scheduler/index.ts +1 -0
  268. package/packages/kernel/scheduler/infrastructure/schedule-store.ts +805 -0
  269. package/packages/kernel/work/api/index.ts +16 -0
  270. package/packages/kernel/work/application/work-service.ts +123 -0
  271. package/packages/kernel/work/domain/check-receipt.ts +43 -0
  272. package/packages/kernel/work/domain/context-closure-receipt.ts +32 -0
  273. package/packages/kernel/work/domain/current-task-lineage.ts +104 -0
  274. package/packages/kernel/work/domain/engineering-contracts.ts +157 -0
  275. package/packages/kernel/work/domain/engineering-design.ts +286 -0
  276. package/packages/kernel/work/domain/engineering-profile.ts +238 -0
  277. package/packages/kernel/work/domain/evaluation-promotion-receipt.ts +186 -0
  278. package/packages/kernel/work/domain/execution-concurrency.ts +247 -0
  279. package/packages/kernel/work/domain/execution-snapshot.ts +2 -0
  280. package/packages/kernel/work/domain/implementation-review.ts +193 -0
  281. package/packages/kernel/work/domain/objective-graph.ts +119 -0
  282. package/packages/kernel/work/domain/project-engineering-contract.ts +224 -0
  283. package/packages/kernel/work/domain/repository-completion-receipt.ts +73 -0
  284. package/{src/runtime/control-plane/facade/work-state-machine.ts → packages/kernel/work/domain/state-machine.ts} +37 -66
  285. package/packages/kernel/work/domain/types.ts +534 -0
  286. package/packages/kernel/work/index.ts +1 -0
  287. package/packages/kernel/work/infrastructure/work-contract-store.ts +1967 -0
  288. package/packages/kernel/work/ports/work-contract-store.ts +21 -0
  289. package/packages/plugin-runtime/browser/index.ts +3 -0
  290. package/packages/plugin-runtime/browser/provider-registry.ts +110 -0
  291. package/packages/plugin-runtime/browser/runtime-contract.ts +150 -0
  292. package/packages/plugin-runtime/browser/session-authority.ts +62 -0
  293. package/packages/plugin-runtime/computer/chatgpt-identity.ts +24 -0
  294. package/packages/plugin-runtime/computer/conversation-target.ts +143 -0
  295. package/packages/plugin-runtime/computer/index.ts +8 -0
  296. package/packages/plugin-runtime/computer/provider-error.ts +26 -0
  297. package/packages/plugin-runtime/computer/provider-registration.ts +52 -0
  298. package/packages/plugin-runtime/computer/provider-registry.ts +63 -0
  299. package/packages/plugin-runtime/computer/provider.ts +19 -0
  300. package/packages/plugin-runtime/computer/target-authority.ts +215 -0
  301. package/packages/plugin-runtime/computer/target-persistence.ts +54 -0
  302. package/packages/plugin-runtime/external/index.ts +1 -0
  303. package/packages/plugin-runtime/external/unix-jsonl-transport.ts +581 -0
  304. package/packages/plugin-runtime/index.ts +3 -0
  305. package/packages/protocols/browser/index.ts +1 -0
  306. package/packages/protocols/browser/session.ts +98 -0
  307. package/packages/protocols/computer/contract.ts +225 -0
  308. package/packages/protocols/computer/index.ts +1 -0
  309. package/packages/protocols/failure/contract.ts +158 -0
  310. package/packages/protocols/failure/index.ts +1 -0
  311. package/packages/protocols/handoff/index.ts +1 -0
  312. package/packages/protocols/handoff/status.ts +22 -0
  313. package/packages/protocols/mcp/execution-context.ts +11 -0
  314. package/packages/protocols/mcp/index.ts +2 -0
  315. package/packages/protocols/mcp/tool-contract.ts +42 -0
  316. package/packages/workflow-runtime/api/index.ts +2 -0
  317. package/packages/workflow-runtime/application/interpreter.ts +342 -0
  318. package/packages/workflow-runtime/domain/workflow-asset.ts +223 -0
  319. package/packages/workflow-runtime/index.ts +1 -0
  320. package/scripts/activate-source-baseline.ts +7 -9
  321. package/scripts/assemble-template.ts +1 -1
  322. package/scripts/bootstrap-runtime-maintenance-recovery.sh +4 -1
  323. package/scripts/canary-chatgpt-provider-delivery.ts +97 -0
  324. package/scripts/canary-controller-semantic-wait.ts +183 -0
  325. package/scripts/canary-global-hook.sh +2 -2
  326. package/scripts/check-mcp-compatibility.ts +85 -7
  327. package/scripts/check-platform-support.mjs +28 -2
  328. package/scripts/check-public-docs.sh +1 -1
  329. package/scripts/check-repository-hygiene.mjs +92 -0
  330. package/scripts/check-runtime-architecture.mjs +1643 -127
  331. package/scripts/check-source-duplication.mjs +9 -1
  332. package/scripts/controller-ngrok-rotation.sh +5 -4
  333. package/scripts/create-project-dirs.sh +10 -74
  334. package/scripts/forge-local-recovery-helper.mjs +282 -0
  335. package/scripts/forge-uu-remote-rescue-helper.d.mts +31 -0
  336. package/scripts/forge-uu-remote-rescue-helper.mjs +409 -0
  337. package/scripts/forge-windows-host-recovery-helper.mjs +136 -0
  338. package/scripts/hook-shim.sh +2 -2
  339. package/scripts/init-project.sh +12 -70
  340. package/scripts/install-desktop-operator-registration.ts +4 -2
  341. package/scripts/install-independent-windows-wsl-recovery.ts +125 -0
  342. package/scripts/install-standalone-recovery.ts +122 -10
  343. package/scripts/install-uu-remote-rescue-registration.ts +74 -0
  344. package/scripts/install-windows-host-recovery-registration.ts +22 -0
  345. package/scripts/lib/controller-home-env.sh +6 -3
  346. package/scripts/lib/project-init-lib.sh +42 -582
  347. package/scripts/migrate-chatgpt-automation-schedules.ts +2 -2
  348. package/scripts/migrate-windows-wsl-controller-home.ts +306 -0
  349. package/scripts/open-source-audit-allowlist.txt +11 -1
  350. package/scripts/portability-bindings.mjs +70 -0
  351. package/scripts/run-bounded-command.mjs +60 -0
  352. package/scripts/run-bun-test-file.ts +22 -6
  353. package/scripts/run-governed-gate.ts +4 -2
  354. package/scripts/run-mobile-monitor-bridge.ts +0 -1
  355. package/scripts/smoke-control-plane-failure-domain.ts +94 -0
  356. package/scripts/smoke-mcp-http-runtime.ts +6 -1
  357. package/scripts/smoke-runtime-recovery.ts +13 -11
  358. package/scripts/smoke-schedule-engine.ts +24 -16
  359. package/scripts/smoke-unattended-transport-recovery.ts +223 -0
  360. package/scripts/smoke-user-request-continuation-restart.ts +232 -0
  361. package/scripts/smoke-workflow-supervisor-chrome-adapter.ts +92 -0
  362. package/scripts/smoke-workflow-supervisor-process-restart.ts +276 -0
  363. package/scripts/smoke-workflow-supervisor-restart-recovery.ts +150 -0
  364. package/scripts/smoke-workflow-supervisor.ts +103 -0
  365. package/scripts/test-governance.ts +51 -2
  366. package/scripts/verify-forge-runtime.sh +2 -1
  367. package/src/cli/agent-jobs/executor-health.ts +11 -34
  368. package/src/cli/agent-jobs/integration.ts +18 -49
  369. package/src/cli/agent-jobs/job-manager.ts +17 -4
  370. package/src/cli/chatgpt-browser/bind-server.ts +2 -1
  371. package/src/cli/chatgpt-browser/binding.ts +20 -10
  372. package/src/cli/chatgpt-browser/bridge-extension.ts +75 -0
  373. package/src/cli/chatgpt-browser/bridge-provider.ts +376 -11
  374. package/src/cli/chatgpt-browser/engine.ts +10 -11
  375. package/src/cli/chatgpt-browser/native-provider.ts +24 -83
  376. package/src/cli/chatgpt-browser/oracle-provider.ts +5 -3
  377. package/src/cli/chatgpt-browser/types.ts +1 -0
  378. package/src/cli/commands/bootstrap-control.ts +334 -0
  379. package/src/cli/commands/brain-assistant.ts +52 -0
  380. package/src/cli/commands/brain.ts +191 -40
  381. package/src/cli/commands/chatgpt.ts +32 -67
  382. package/src/cli/commands/computer.ts +437 -0
  383. package/src/cli/commands/doctor.ts +18 -1
  384. package/src/cli/commands/init-hook.ts +71 -61
  385. package/src/cli/commands/init.ts +3 -1
  386. package/src/cli/commands/mcp.ts +16 -10
  387. package/src/cli/commands/plugin.ts +38 -12
  388. package/src/cli/commands/recovery.ts +507 -80
  389. package/src/cli/commands/runtime.ts +12 -7
  390. package/src/cli/commands/setup-profile.ts +97 -39
  391. package/src/cli/commands/status.ts +2 -1
  392. package/src/cli/controller/check-runner.ts +500 -100
  393. package/src/cli/controller/completion-backlog.ts +3 -3
  394. package/src/cli/controller/completion-orchestrator.ts +4 -43
  395. package/src/cli/controller/completion-target.ts +3 -72
  396. package/src/cli/controller/context/source-materializer.ts +81 -100
  397. package/src/cli/controller/context/types.ts +7 -1
  398. package/src/cli/controller/context-pack.ts +28 -6
  399. package/src/cli/controller/execution-completion.ts +4 -7
  400. package/src/cli/controller/execution-policy.ts +36 -153
  401. package/src/cli/controller/governance.ts +2 -3
  402. package/src/cli/controller/issue-store.ts +4 -99
  403. package/src/cli/controller/launch-agents.ts +59 -18
  404. package/src/cli/controller/operational-plan.ts +24 -51
  405. package/src/cli/controller/runtime-config.ts +5 -1
  406. package/src/cli/controller/stuck-state-migration.ts +2 -3
  407. package/src/cli/controller/systemd-user.ts +148 -0
  408. package/src/cli/controller/types.ts +10 -70
  409. package/src/cli/controller/worklog.ts +67 -13
  410. package/src/cli/editing/edit-operation-contract.ts +92 -0
  411. package/src/cli/editing/edit-session.ts +290 -20
  412. package/src/cli/github/plugin.ts +17 -12
  413. package/src/cli/hook/route-registry.ts +3 -5
  414. package/src/cli/hook/runtime.ts +49 -3
  415. package/src/cli/index.ts +3 -0
  416. package/src/cli/local-bridge/connector-freshness.ts +2 -2
  417. package/src/cli/local-bridge/console-automations.ts +20 -15
  418. package/src/cli/local-bridge/console-view-models.ts +3 -12
  419. package/src/cli/local-bridge/facade-api.ts +105 -205
  420. package/src/cli/local-bridge/job-store.ts +1 -1
  421. package/src/cli/local-bridge/server.ts +48 -174
  422. package/src/cli/local-bridge/types.ts +0 -1
  423. package/src/cli/mcp/access-mode.ts +2 -132
  424. package/src/cli/mcp/access-tools.ts +2 -387
  425. package/src/cli/mcp/audit.ts +2 -32
  426. package/src/cli/mcp/auth.ts +2 -404
  427. package/src/cli/mcp/instructions.ts +2 -34
  428. package/src/cli/mcp/legacy-context.ts +2 -16
  429. package/src/cli/mcp/legacy-tool-service.ts +2 -5308
  430. package/src/cli/mcp/multi-repository.ts +2 -436
  431. package/src/cli/mcp/oauth-client-retirement.ts +74 -0
  432. package/src/cli/mcp/oauth.ts +2 -375
  433. package/src/cli/mcp/openai-secure-tunnel.ts +2 -0
  434. package/src/cli/mcp/paths.ts +2 -140
  435. package/src/cli/mcp/policy.ts +2 -232
  436. package/src/cli/mcp/post-finalize-work-attribution.ts +2 -150
  437. package/src/cli/mcp/proxy-env.ts +2 -62
  438. package/src/cli/mcp/readiness-projection.ts +2 -24
  439. package/src/cli/mcp/redaction.ts +2 -21
  440. package/src/cli/mcp/repo.ts +2 -24
  441. package/src/cli/mcp/repository-tools.ts +2 -1613
  442. package/src/cli/mcp/server.ts +2 -951
  443. package/src/cli/mcp/setup.ts +2 -737
  444. package/src/cli/mcp/tool-capability-cache.ts +2 -87
  445. package/src/cli/mcp/tool-contract.ts +2 -14
  446. package/src/cli/mcp/tools.ts +2 -9
  447. package/src/cli/mcp/toolset-names.ts +2 -70
  448. package/src/cli/mcp/toolset-selection.ts +2 -41
  449. package/src/cli/mcp/toolset.ts +2 -336
  450. package/src/cli/mcp/transports/AGENTS.md +1 -10
  451. package/src/cli/mcp/transports/CLAUDE.md +1 -10
  452. package/src/cli/mcp/transports/http.ts +2 -1414
  453. package/src/cli/mcp/transports/session-registry.ts +2 -490
  454. package/src/cli/mcp/transports/stdio.ts +2 -8
  455. package/src/cli/mcp/types.ts +2 -41
  456. package/src/cli/mcp/umbrella-tools.ts +2 -117
  457. package/src/cli/repositories/command-executor.ts +91 -39
  458. package/src/cli/repositories/command-scope.ts +139 -4
  459. package/src/cli/repositories/controller-home.ts +167 -1
  460. package/src/cli/repositories/ephemeral-workspace.ts +20 -30
  461. package/src/cli/repositories/git-command-executor.ts +2 -2
  462. package/src/cli/repositories/identity.ts +13 -0
  463. package/src/cli/repositories/registry.ts +145 -60
  464. package/src/cli/repositories/repository-snapshot.ts +53 -7
  465. package/src/cli/repositories/runtime-storage.ts +27 -2
  466. package/src/cli/repositories/safe-patch.ts +34 -38
  467. package/src/cli/repositories/selected-path-actions.ts +22 -2
  468. package/src/cli/repositories/structured-git.ts +167 -27
  469. package/src/cli/repository/session-cache.ts +92 -6
  470. package/src/cli/runtime/helper-runner.ts +7 -0
  471. package/src/cli/runtime-invocation.ts +8 -1
  472. package/src/cli/tools/codegraph.ts +44 -25
  473. package/src/core/adoption/manifest-templates.ts +1 -1
  474. package/src/core/adoption/plan.ts +3 -26
  475. package/src/core/adoption/workflow-contract-plan.ts +17 -9
  476. package/src/effects/process-runner.ts +8 -14
  477. package/src/runtime/context/assistant-context.ts +167 -0
  478. package/src/runtime/context/assistant-work-context.ts +209 -0
  479. package/src/runtime/context/automatic-learning.ts +565 -0
  480. package/src/runtime/context/codegraph-cache-boundary.ts +255 -0
  481. package/src/runtime/context/codegraph-read-provider.ts +55 -22
  482. package/src/runtime/context/codegraph-sidecar.cjs +8 -1
  483. package/src/runtime/context/cognitive-attention.ts +173 -0
  484. package/src/runtime/context/cognitive-skill-canary.ts +158 -0
  485. package/src/runtime/context/context-closure.ts +305 -0
  486. package/src/runtime/context/context-pack-process.ts +103 -0
  487. package/src/runtime/context/context-plane.ts +203 -0
  488. package/src/runtime/context/direct-controller-learning.ts +298 -0
  489. package/src/runtime/context/project-engineering-contract.ts +60 -0
  490. package/src/runtime/context/semantic-navigation-contract.ts +9 -0
  491. package/src/runtime/context/semantic-navigation.ts +6 -34
  492. package/src/runtime/context/typescript-navigation-process.ts +145 -0
  493. package/src/runtime/context/typescript-navigation.ts +89 -3
  494. package/src/runtime/control-plane/bootstrap/capability-provider.ts +74 -0
  495. package/src/runtime/control-plane/bootstrap/control-api.ts +57 -0
  496. package/src/runtime/control-plane/bootstrap/index.ts +5 -0
  497. package/src/runtime/control-plane/bootstrap/state-machine.ts +141 -0
  498. package/src/runtime/control-plane/bootstrap/store.ts +21 -0
  499. package/src/runtime/control-plane/bootstrap/types.ts +87 -0
  500. package/src/runtime/control-plane/cleanup-artifact-retention.ts +531 -0
  501. package/src/runtime/control-plane/codegraph-cache-retention.ts +164 -0
  502. package/src/runtime/control-plane/concurrency/work-execution-concurrency.ts +282 -0
  503. package/src/runtime/control-plane/execution/controller-authority-recovery.ts +380 -0
  504. package/src/runtime/control-plane/execution/edit-validation-coordinator.ts +113 -16
  505. package/src/runtime/control-plane/execution/execution-identity.ts +23 -3
  506. package/src/runtime/control-plane/execution/implementation-review-content.ts +95 -0
  507. package/src/runtime/control-plane/execution/repository-work-attribution.ts +7 -30
  508. package/src/runtime/control-plane/execution/retained-work-resume.ts +439 -102
  509. package/src/runtime/control-plane/execution/session-store.ts +31 -1
  510. package/src/runtime/control-plane/execution/validation.ts +34 -11
  511. package/src/runtime/control-plane/execution/work-authority-reconciler.ts +87 -0
  512. package/src/runtime/control-plane/execution/work-check-evidence.ts +137 -0
  513. package/src/runtime/control-plane/execution/work-completion-authority.ts +31 -44
  514. package/src/runtime/control-plane/execution/work-delivery-service.ts +497 -0
  515. package/src/runtime/control-plane/execution/work-evidence-policy.ts +46 -53
  516. package/src/runtime/control-plane/execution/work-execution-support.ts +85 -164
  517. package/src/runtime/control-plane/execution/work-handle-authority.ts +349 -73
  518. package/src/runtime/control-plane/execution/work-handle-store.ts +55 -2
  519. package/src/runtime/control-plane/execution/work-head-settlement.ts +108 -0
  520. package/src/runtime/control-plane/execution/work-lifecycle-audit.ts +173 -28
  521. package/src/runtime/control-plane/execution/work-operation-service.ts +92 -40
  522. package/src/runtime/control-plane/execution/work-preparation-service.ts +145 -269
  523. package/src/runtime/control-plane/execution/work-remote-delivery.ts +2 -3
  524. package/src/runtime/control-plane/execution/work-revision-diff.ts +39 -0
  525. package/src/runtime/control-plane/execution/work-terminal-cleanup.ts +543 -225
  526. package/src/runtime/control-plane/execution/work-validation-reconciler.ts +59 -45
  527. package/src/runtime/control-plane/execution/work-verification-context.ts +1 -1
  528. package/src/runtime/control-plane/execution/work-verification-service.ts +662 -52
  529. package/src/runtime/control-plane/execution/work-verification-snapshot.ts +205 -16
  530. package/src/runtime/control-plane/facade/capability-registry.ts +380 -44
  531. package/src/runtime/control-plane/facade/check-normalization.ts +3 -9
  532. package/src/runtime/control-plane/facade/codex-delegation.ts +10 -11
  533. package/src/runtime/control-plane/facade/controller-connection.ts +135 -0
  534. package/src/runtime/control-plane/facade/controller-session-store.ts +2 -488
  535. package/src/runtime/control-plane/facade/goal-workloop-access.ts +6 -22
  536. package/src/runtime/control-plane/facade/goal-workloop.ts +565 -1202
  537. package/src/runtime/control-plane/facade/handoff-inbox-application.ts +145 -0
  538. package/src/runtime/control-plane/facade/handoff-inbox-store.ts +266 -52
  539. package/src/runtime/control-plane/facade/index.ts +4 -3
  540. package/src/runtime/control-plane/facade/operation-digest.ts +34 -73
  541. package/src/runtime/control-plane/facade/plan-contract-store.ts +671 -245
  542. package/src/runtime/control-plane/facade/policy-gate.ts +0 -23
  543. package/src/runtime/control-plane/facade/repository-work-admission.ts +31 -23
  544. package/src/runtime/control-plane/facade/requirement-authority.ts +121 -0
  545. package/src/runtime/control-plane/facade/requirement-board.ts +9 -4
  546. package/src/runtime/control-plane/facade/rh-work-operation-contract.ts +85 -0
  547. package/src/runtime/control-plane/facade/self-healing-loop.ts +18 -53
  548. package/src/runtime/control-plane/facade/semantic-admission.ts +8 -16
  549. package/src/runtime/control-plane/facade/suggested-actions.ts +15 -15
  550. package/src/runtime/control-plane/facade/types.ts +218 -620
  551. package/src/runtime/control-plane/facade/work-continuation.ts +8 -8
  552. package/src/runtime/control-plane/facade/work-contract-store.ts +2 -1043
  553. package/src/runtime/control-plane/generated-cache-retention.ts +336 -19
  554. package/src/runtime/control-plane/global-scheduler/autonomous-continuation.ts +248 -0
  555. package/src/runtime/control-plane/global-scheduler/durable-admission.ts +13 -2
  556. package/src/runtime/control-plane/global-scheduler/maintenance.ts +274 -84
  557. package/src/runtime/control-plane/global-scheduler/periodic-cleanup-entry.ts +55 -0
  558. package/src/runtime/control-plane/global-scheduler/periodic-cleanup-process.ts +98 -0
  559. package/src/runtime/control-plane/global-scheduler/reconciliation.ts +3 -2
  560. package/src/runtime/control-plane/global-scheduler/scheduler-worker-entry.ts +10 -0
  561. package/src/runtime/control-plane/global-scheduler/scheduler.ts +227 -109
  562. package/src/runtime/control-plane/global-scheduler/wake-signal.ts +42 -2
  563. package/src/runtime/control-plane/global-scheduler/worker-launch.ts +18 -6
  564. package/src/runtime/control-plane/governance/access-policy.ts +19 -2
  565. package/src/runtime/control-plane/governance/authorization.ts +20 -3
  566. package/src/runtime/control-plane/launcher/chatgpt-round-continuation.ts +160 -0
  567. package/src/runtime/control-plane/launcher/chatgpt-work-binding-store.ts +2 -177
  568. package/src/runtime/control-plane/launcher/chatgpt-work-continuation.ts +139 -670
  569. package/src/runtime/control-plane/launcher/local-conversation-controller.ts +238 -0
  570. package/src/runtime/control-plane/launcher/provider-mcp-bootstrap.ts +25 -6
  571. package/src/runtime/control-plane/launcher/thin-launcher.ts +96 -194
  572. package/src/runtime/control-plane/lifecycle-retention-metrics.ts +60 -0
  573. package/src/runtime/control-plane/persistence/cognition-store.ts +820 -0
  574. package/src/runtime/control-plane/persistence/experience-store.ts +302 -0
  575. package/src/runtime/control-plane/persistence/operational-prior-store.ts +348 -0
  576. package/src/runtime/control-plane/persistence/requirement-store.ts +230 -80
  577. package/src/runtime/control-plane/persistence/sqlite-store.ts +654 -78
  578. package/src/runtime/control-plane/persistence/workflow-content-store.ts +98 -0
  579. package/src/runtime/control-plane/persistence/workflow-registry-store.ts +186 -0
  580. package/src/runtime/control-plane/persistence/workflow-run-store.ts +123 -0
  581. package/src/runtime/control-plane/release-retention.ts +154 -26
  582. package/src/runtime/control-plane/repository-namespace-retention.ts +208 -0
  583. package/src/runtime/control-plane/runtime-cleanup.ts +844 -38
  584. package/src/runtime/control-plane/runtime-generation.ts +6 -0
  585. package/src/runtime/control-plane/workspace/project-onboarding.ts +80 -0
  586. package/src/runtime/control-plane/workspace/semantic-sync-service.ts +479 -0
  587. package/src/runtime/control-plane/workspace/workspace-store.ts +249 -0
  588. package/src/runtime/diagnostics/incident-repair.ts +573 -0
  589. package/src/runtime/diagnostics/mcp-timing.ts +239 -6
  590. package/src/runtime/diagnostics/performance.ts +6 -14
  591. package/src/runtime/diagnostics/read-only-tool.ts +1 -1
  592. package/src/runtime/evidence/artifact-store.ts +216 -35
  593. package/src/runtime/evidence/evidence-store.ts +112 -8
  594. package/src/runtime/evidence/operational-shadow.ts +38 -0
  595. package/src/runtime/evidence/output-handle-index.ts +225 -0
  596. package/src/runtime/evidence/process-check-receipt.ts +5 -43
  597. package/src/runtime/evidence/result-store.ts +158 -44
  598. package/src/runtime/evidence/sensitive-output.ts +4 -4
  599. package/src/runtime/execution/jobs/receipt-recovery.ts +1 -1
  600. package/src/runtime/execution/jobs/store.ts +124 -6
  601. package/src/runtime/execution/managed-workspace.ts +112 -5
  602. package/src/runtime/execution/process-runtime/canary.ts +19 -5
  603. package/src/runtime/execution/process-runtime/check-classification.ts +48 -0
  604. package/src/runtime/execution/process-runtime/check-facade.ts +24 -10
  605. package/src/runtime/execution/process-runtime/check-receipt.ts +1 -1
  606. package/src/runtime/execution/process-runtime/check-result-retention.ts +132 -0
  607. package/src/runtime/execution/process-runtime/check-result.ts +177 -2
  608. package/src/runtime/execution/process-runtime/check-runner-sidecar.ts +58 -9
  609. package/src/runtime/execution/process-runtime/check-storage.ts +187 -0
  610. package/src/runtime/execution/process-runtime/command-facade.ts +117 -114
  611. package/src/runtime/execution/process-runtime/gc.ts +15 -2
  612. package/src/runtime/execution/process-runtime/handle-index.ts +176 -0
  613. package/src/runtime/execution/process-runtime/host-command-lane.ts +139 -0
  614. package/src/runtime/execution/process-runtime/index.ts +4 -0
  615. package/src/runtime/execution/process-runtime/interactive-admission.ts +2 -1
  616. package/src/runtime/execution/process-runtime/lightweight-managed.ts +283 -73
  617. package/src/runtime/execution/process-runtime/persisted-check.ts +130 -23
  618. package/src/runtime/execution/process-runtime/process-runner-entry.ts +47 -5
  619. package/src/runtime/execution/process-runtime/process-scope.ts +160 -0
  620. package/src/runtime/execution/process-runtime/resource-claims.ts +125 -64
  621. package/src/runtime/execution/process-runtime/runtime.ts +167 -17
  622. package/src/runtime/execution/process-runtime/store.ts +30 -2
  623. package/src/runtime/execution/process-runtime/types.ts +27 -0
  624. package/src/runtime/execution/workers/executor.ts +18 -19
  625. package/src/runtime/execution/workers/worker-entry.ts +1 -1
  626. package/src/runtime/gateway/mcp/execution-tools.ts +2 -207
  627. package/src/runtime/gateway/mcp/legacy-ios-tool-adapter.ts +2 -61
  628. package/src/runtime/gateway/mcp/persisted-check-process.ts +2 -3
  629. package/src/runtime/gateway/mcp/process-tools.ts +2 -289
  630. package/src/runtime/gateway/mcp/router.ts +2 -1125
  631. package/src/runtime/gateway/mcp/runtime-tool-definitions.ts +2 -565
  632. package/src/runtime/gateway/mcp/runtime-tools.ts +2 -6655
  633. package/src/runtime/gateway/mcp/work-validation-reconciler.ts +2 -1
  634. package/src/runtime/maintenance/cleanup.ts +38 -24
  635. package/src/runtime/platform/browser-product-discovery.ts +174 -0
  636. package/src/runtime/platform/computer-platform.ts +14 -0
  637. package/src/runtime/platform/executable-discovery.ts +54 -0
  638. package/src/runtime/platform/fetch-http-server.ts +90 -0
  639. package/src/runtime/platform/service-inventory.ts +130 -0
  640. package/src/runtime/platform/service-manager.ts +146 -0
  641. package/src/runtime/platform/windows-host-discovery.ts +118 -0
  642. package/src/runtime/platform/windows-recovery-deployment.ts +67 -0
  643. package/src/runtime/plugins/action-application.ts +192 -0
  644. package/src/runtime/plugins/app-store-connect-adapter.ts +47 -35
  645. package/src/runtime/plugins/browser-adapter.ts +898 -135
  646. package/src/runtime/plugins/browser-automation-service.ts +33 -34
  647. package/src/runtime/plugins/browser-macos-bridge.ts +386 -46
  648. package/src/runtime/plugins/browser-manifest-surface.ts +75 -17
  649. package/src/runtime/plugins/browser-native-session-service.ts +64 -14
  650. package/src/runtime/plugins/browser-provider-registry.ts +2 -109
  651. package/src/runtime/plugins/browser-registration.ts +32 -0
  652. package/src/runtime/plugins/browser-runtime-contract.ts +2 -154
  653. package/src/runtime/plugins/browser-runtime.ts +55 -10
  654. package/src/runtime/plugins/browser-session-authority.ts +101 -291
  655. package/src/runtime/plugins/browser-session-legacy-migration.ts +203 -0
  656. package/src/runtime/plugins/browser-session-store.ts +243 -80
  657. package/src/runtime/plugins/browser-session-types.ts +2 -98
  658. package/src/runtime/plugins/capability-authorization-grants.ts +272 -59
  659. package/src/runtime/plugins/catalog-trust.ts +82 -0
  660. package/src/runtime/plugins/computer-chatgpt-browser-adapter-installer.ts +219 -0
  661. package/src/runtime/plugins/computer-chatgpt-macos-target.ts +891 -0
  662. package/src/runtime/plugins/computer-registration.ts +1050 -0
  663. package/src/runtime/plugins/config-store.ts +119 -0
  664. package/src/runtime/plugins/desktop-operator-external-policy.ts +964 -0
  665. package/src/runtime/plugins/desktop-operator-registration.ts +123 -12
  666. package/src/runtime/plugins/errors.ts +8 -1
  667. package/src/runtime/plugins/external-adapter.ts +82 -323
  668. package/src/runtime/plugins/external-provider-policy.ts +48 -0
  669. package/src/runtime/plugins/external-registration.ts +30 -2
  670. package/src/runtime/plugins/external-unix-socket-probe.cjs +9 -3
  671. package/src/runtime/plugins/external-unix-socket.ts +64 -193
  672. package/src/runtime/plugins/first-party-external-registration.ts +163 -0
  673. package/src/runtime/plugins/first-party-registry.ts +3 -1
  674. package/src/runtime/plugins/github-adapter.ts +1 -2
  675. package/src/runtime/plugins/gmail-adapter.ts +29 -8
  676. package/src/runtime/plugins/google-calendar-adapter.ts +8 -8
  677. package/src/runtime/plugins/google-shared.ts +45 -53
  678. package/src/runtime/plugins/google-tasks-adapter.ts +8 -8
  679. package/src/runtime/plugins/ios-adapter.ts +2 -3
  680. package/src/runtime/plugins/lightweight-action.ts +208 -2
  681. package/src/runtime/plugins/local-system-adapter.ts +192 -2
  682. package/src/runtime/plugins/macos-capability-broker.ts +15 -105
  683. package/src/runtime/plugins/managed-process-adapter.ts +12 -5
  684. package/src/runtime/plugins/plugin-action-sidecar.ts +17 -13
  685. package/src/runtime/plugins/plugin-management-adapter.ts +1 -1
  686. package/src/runtime/plugins/resend-adapter.ts +15 -24
  687. package/src/runtime/plugins/store.ts +1003 -387
  688. package/src/runtime/plugins/types.ts +28 -1
  689. package/src/runtime/plugins/uu-remote-rescue-registration.ts +155 -0
  690. package/src/runtime/plugins/windows-host-recovery-install.ts +68 -0
  691. package/src/runtime/plugins/windows-host-recovery-registration.ts +85 -0
  692. package/src/runtime/plugins/xiaohongshu-publish.ts +102 -430
  693. package/src/runtime/projections/controller-context.ts +12 -6
  694. package/src/runtime/projections/git-status-sampler.ts +73 -22
  695. package/src/runtime/projections/invalidation.ts +7 -3
  696. package/src/runtime/projections/materialized-view.ts +93 -43
  697. package/src/runtime/recovery/actions.ts +3 -3
  698. package/src/runtime/recovery/capability-action-application.ts +229 -0
  699. package/src/runtime/recovery/index.ts +3 -0
  700. package/src/runtime/recovery/lifecycle-inventory.ts +338 -0
  701. package/src/runtime/recovery/local-jobs-repair.ts +14 -14
  702. package/src/runtime/recovery/maintenance-executor.ts +701 -168
  703. package/src/runtime/recovery/quarantine-retention.ts +256 -0
  704. package/src/runtime/recovery/store.ts +29 -11
  705. package/src/runtime/release/identity.ts +6 -0
  706. package/src/runtime/release/release-coordinator.ts +296 -0
  707. package/src/runtime/release/release-session.ts +716 -0
  708. package/src/runtime/release/release-state-migration.ts +25 -0
  709. package/src/runtime/resources/leases/store.ts +56 -25
  710. package/src/runtime/root/active-execution-power-assertion.ts +139 -0
  711. package/src/runtime/root/assistant-learning-loop.ts +45 -0
  712. package/src/runtime/root/browser-session-composition.ts +59 -0
  713. package/src/runtime/root/computer-composition.ts +376 -0
  714. package/src/runtime/root/computer-target-composition.ts +16 -0
  715. package/src/runtime/root/computer-target-persistence.ts +39 -0
  716. package/src/runtime/root/controller-progression-composition.ts +192 -0
  717. package/src/runtime/root/controller-round-composition.ts +126 -0
  718. package/src/runtime/root/controller-services.ts +2 -0
  719. package/src/runtime/root/deployment-topology.ts +106 -0
  720. package/src/runtime/root/entry.ts +8 -6
  721. package/src/runtime/root/gateway-adapter.ts +3 -3
  722. package/src/runtime/root/known-good-recovery.ts +184 -0
  723. package/src/runtime/root/local-bridge.ts +5 -3
  724. package/src/runtime/root/mcp-transport.ts +116 -23
  725. package/src/runtime/root/ownership.ts +261 -9
  726. package/src/runtime/root/package-connector-service.ts +212 -74
  727. package/src/runtime/root/package-runtime-release.ts +199 -33
  728. package/src/runtime/root/package-runtime-service.ts +77 -108
  729. package/src/runtime/root/release-execution-canary.ts +103 -0
  730. package/src/runtime/root/release-loader.ts +150 -0
  731. package/src/runtime/root/release-manifest.ts +185 -7
  732. package/src/runtime/root/release-materialize.ts +474 -31
  733. package/src/runtime/root/release-store.ts +425 -37
  734. package/src/runtime/root/runtime-lane.ts +191 -0
  735. package/src/runtime/root/runtime.ts +379 -32
  736. package/src/runtime/root/scheduled-controller-composition.ts +76 -0
  737. package/src/runtime/root/scheduler.ts +12 -4
  738. package/src/runtime/root/service-runner.ts +3 -3
  739. package/src/runtime/root/service.ts +73 -45
  740. package/src/runtime/root/status.ts +49 -0
  741. package/src/runtime/root/types.ts +55 -3
  742. package/src/runtime/root/workflow-supervisor-composition.ts +493 -0
  743. package/src/runtime/root/workflow-supervisor-runtime.ts +209 -0
  744. package/src/runtime/root/write-fence.ts +50 -2
  745. package/src/runtime/safe-tooling/google-credential-store.ts +76 -21
  746. package/src/runtime/safe-tooling/google-oauth-broker.ts +25 -7
  747. package/src/runtime/safe-tooling/workspace-auth.ts +1 -1
  748. package/src/runtime/shared/bounded-child-supervisor.ts +9 -1
  749. package/src/runtime/shared/local-bridge-surface.ts +1 -1
  750. package/src/runtime/shared/process-environment.ts +36 -10
  751. package/src/runtime/shared/response-budget.ts +1 -3
  752. package/src/runtime/shared/storage-capacity.ts +68 -0
  753. package/src/runtime/standalone-recovery/controller-home-migration.ts +1108 -0
  754. package/src/runtime/standalone-recovery/core.ts +4609 -495
  755. package/src/runtime/standalone-recovery/entry.ts +642 -81
  756. package/src/runtime/standalone-recovery/independent-host-rescue.ts +172 -0
  757. package/src/runtime/standalone-recovery/installer.ts +399 -177
  758. package/src/runtime/standalone-recovery/mcp-server.ts +79 -0
  759. package/src/runtime/standalone-recovery/mutation-identity-contract.ts +21 -0
  760. package/src/runtime/standalone-recovery/operation-lock.ts +160 -0
  761. package/src/runtime/standalone-recovery/performance.ts +173 -0
  762. package/src/runtime/standalone-recovery/release.ts +58 -5
  763. package/src/runtime/standalone-recovery/service-labels.ts +5 -2
  764. package/src/runtime/standalone-recovery/watchdog-heartbeat.ts +5 -2
  765. package/src/runtime/watchdog/workflow-watchdog.ts +1 -1
  766. package/src/runtime/workflow/schedules/browser-probe.ts +17 -6
  767. package/src/runtime/workflow/schedules/chatgpt-automation-migration.ts +11 -4
  768. package/src/runtime/workflow/schedules/engine.ts +298 -484
  769. package/src/runtime/workflow/schedules/pending-activation.ts +1 -1
  770. package/src/runtime/workflow/schedules/settlement.ts +2 -191
  771. package/src/runtime/workflow/schedules/store.ts +2 -607
  772. package/src/runtime/workflow/schedules/types.ts +2 -127
  773. package/src/runtime/workflow/schedules/work-continuation.ts +220 -16
  774. package/src/runtime/workflows/first-party/xiaohongshu.ts +122 -0
  775. package/src/runtime/workflows/runtime.ts +482 -0
  776. package/src/testing/test-governance.ts +95 -30
  777. package/supervisor/chatgpt-conversation.ts +23 -0
  778. package/supervisor/client.ts +201 -0
  779. package/supervisor/control-plane.ts +868 -0
  780. package/supervisor/entry.ts +15 -0
  781. package/supervisor/forge-validators.ts +80 -0
  782. package/supervisor/index.ts +5 -0
  783. package/supervisor/native-browser-adapter.ts +786 -0
  784. package/supervisor/native-messaging/host.ts +39 -0
  785. package/supervisor/native-messaging/manifest.ts +26 -0
  786. package/supervisor/native-messaging/protocol.ts +27 -0
  787. package/supervisor/paths.ts +18 -0
  788. package/supervisor/protocol.ts +202 -0
  789. package/supervisor/server.ts +404 -0
  790. package/supervisor/store.ts +1451 -0
  791. package/supervisor/tsconfig.json +8 -0
  792. package/supervisor/types.ts +255 -0
  793. package/assets/templates/helpers/archive-architecture-request.sh +0 -244
  794. package/docs/architecture/history/README.md +0 -7
  795. package/docs/architecture/history/chatgpt-handoff-facade.md +0 -397
  796. package/docs/architecture/history/global-hook-runtime.md +0 -166
  797. package/docs/architecture/history/ios-semantic-automation-provider-v2.md +0 -170
  798. package/docs/architecture/requests/archive/2026/20260528-154740-ai-hooks-ai-hooks-hook-input-sh.md +0 -59
  799. package/docs/architecture/requests/archive/2026/20260528-154816-assets-hooks-assets-hooks-hook-input-sh.md +0 -59
  800. package/docs/architecture/requests/archive/2026/20260528-161851-ai-harness-workflow-contract-json-ai-harness-workflow-contract-json.md +0 -59
  801. package/docs/architecture/requests/archive/2026/20260528-161853-scripts-check-task-workflow-sh-scripts-check-task-workflow-sh.md +0 -59
  802. package/docs/architecture/requests/archive/2026/20260528-161911-assets-workflow-contract-v1-json-assets-workflow-contract-v1-json.md +0 -59
  803. package/docs/architecture/requests/archive/2026/20260528-222416-ai-hooks-ai-hooks-hook-input-sh.md +0 -59
  804. package/docs/architecture/requests/archive/2026/20260528-222444-ai-hooks-ai-hooks-pre-edit-guard-sh.md +0 -59
  805. package/docs/architecture/requests/archive/2026/20260528-222457-ai-hooks-ai-hooks-pre-edit-guard-sh.md +0 -59
  806. package/docs/architecture/requests/archive/2026/20260528-222648-ai-hooks-ai-hooks-pre-edit-guard-sh.md +0 -59
  807. package/docs/architecture/requests/archive/2026/20260528-222705-ai-hooks-ai-hooks-worktree-guard-sh.md +0 -59
  808. package/docs/architecture/requests/archive/2026/20260528-222726-ai-hooks-ai-hooks-prompt-guard-sh.md +0 -59
  809. package/docs/architecture/requests/archive/2026/20260528-222727-ai-hooks-ai-hooks-prompt-guard-sh.md +0 -59
  810. package/docs/architecture/requests/archive/2026/20260528-224736-ai-hooks-ai-hooks-hook-input-sh.md +0 -59
  811. package/docs/architecture/requests/archive/2026/20260528-233259-ai-hooks-ai-hooks-prompt-guard-sh.md +0 -59
  812. package/docs/architecture/requests/archive/2026/20260528-233335-assets-hooks-assets-hooks-prompt-guard-sh.md +0 -59
  813. package/docs/architecture/requests/archive/2026/20260528-233456-ai-hooks-ai-hooks-prompt-guard-sh.md +0 -59
  814. package/docs/architecture/requests/archive/2026/20260528-233457-assets-hooks-assets-hooks-prompt-guard-sh.md +0 -59
  815. package/docs/architecture/requests/archive/2026/20260528-233637-ai-hooks-ai-hooks-prompt-guard-sh.md +0 -59
  816. package/docs/architecture/requests/archive/2026/20260528-233638-assets-hooks-assets-hooks-prompt-guard-sh.md +0 -59
  817. package/docs/architecture/requests/archive/2026/20260529-000322-root-package-json.md +0 -59
  818. package/docs/architecture/requests/archive/2026/20260529-004238-ai-hooks-ai-hooks-lib-workflow-state-sh.md +0 -59
  819. package/docs/architecture/requests/archive/2026/20260529-020654-ai-harness-policy-json-ai-harness-policy-json.md +0 -63
  820. package/docs/architecture/requests/archive/2026/20260529-094236-ai-hooks-ai-hooks-prompt-guard-sh.md +0 -60
  821. package/docs/architecture/requests/archive/2026/20260529-094323-assets-hooks-assets-hooks-prompt-guard-sh.md +0 -60
  822. package/docs/architecture/requests/archive/2026/20260529-094331-ai-hooks-ai-hooks-prompt-guard-sh.md +0 -60
  823. package/docs/architecture/requests/archive/2026/20260529-094339-assets-hooks-assets-hooks-prompt-guard-sh.md +0 -60
  824. package/docs/architecture/requests/archive/2026/20260529-094430-assets-hooks-assets-hooks-session-start-context-sh.md +0 -60
  825. package/docs/architecture/requests/archive/2026/20260529-094446-ai-hooks-ai-hooks-session-start-context-sh.md +0 -60
  826. package/docs/architecture/requests/archive/2026/20260613-002040-runtime-harness-hook-adapters.md +0 -68
  827. package/docs/architecture/requests/archive/2026/root.md +0 -68
  828. package/docs/architecture/requests/archive/2026/runtime-harness-hook-adapters.md +0 -76
  829. package/docs/architecture/requests/archive/2026/verification-evals-checks.md +0 -68
  830. package/docs/architecture/requests/archive/2026/workflow-engine-contract-assets.md +0 -69
  831. package/scripts/archive-architecture-request.sh +0 -4
  832. package/scripts/benchmark-background-check-overlap.ts +0 -228
  833. package/scripts/benchmark-controller-hotpath.ts +0 -212
  834. package/scripts/benchmark-controller-round2.ts +0 -139
  835. package/scripts/benchmark-ios-agent-device.ts +0 -514
  836. package/scripts/benchmark-mcp-host.sh +0 -117
  837. package/scripts/benchmark-mcp-transport.ts +0 -170
  838. package/scripts/benchmark-quality-harness.ts +0 -146
  839. package/scripts/benchmark-route-session-concurrency.ts +0 -915
  840. package/scripts/benchmark-thin-harness-gateway-ab.ts +0 -632
  841. package/scripts/benchmark-thin-harness-mcp-e2e.ts +0 -498
  842. package/scripts/benchmark-thin-harness.ts +0 -251
  843. package/scripts/benchmark-typescript-navigation.ts +0 -186
  844. package/scripts/benchmark-work-efficiency.ts +0 -334
  845. package/scripts/build-controller-ui.ts +0 -28
  846. package/scripts/check-npm-release.sh +0 -32
  847. package/scripts/check-public-release-surface.sh +0 -19
  848. package/scripts/check-release-published.sh +0 -57
  849. package/scripts/check-release-readiness.sh +0 -37
  850. package/scripts/check-release-version.mjs +0 -74
  851. package/scripts/check-tarball-install-smoke.sh +0 -67
  852. package/scripts/package-source-archive.sh +0 -147
  853. package/scripts/public-release-files.txt +0 -39
  854. package/scripts/public-release.ts +0 -174
  855. package/scripts/publish-release-tarball.sh +0 -27
  856. package/scripts/route-nl-vs-ts-eval.ts +0 -679
  857. package/scripts/run-skill-evals.ts +0 -1022
  858. package/scripts/stage-runtime-release.ts +0 -39
  859. package/src/cli/controller/progress.ts +0 -656
  860. package/src/cli/controller/work-mode.ts +0 -181
  861. package/src/cli/local-bridge/console-assets.ts +0 -17
  862. package/src/cli/local-bridge/dashboard.ts +0 -17
  863. package/src/cli/local-bridge/frontend/src/App.tsx +0 -10
  864. package/src/cli/local-bridge/frontend/src/components/Button.tsx +0 -1
  865. package/src/cli/local-bridge/frontend/src/components/DetailPane.tsx +0 -3
  866. package/src/cli/local-bridge/frontend/src/components/SearchField.tsx +0 -1
  867. package/src/cli/local-bridge/frontend/src/components/SectionHeader.tsx +0 -1
  868. package/src/cli/local-bridge/frontend/src/components/Segmented.tsx +0 -1
  869. package/src/cli/local-bridge/frontend/src/components/StatusText.tsx +0 -3
  870. package/src/cli/local-bridge/frontend/src/design/icons.tsx +0 -11
  871. package/src/cli/local-bridge/frontend/src/design/tokens.css +0 -8
  872. package/src/cli/local-bridge/frontend/src/features/automations/AutomationsView.tsx +0 -153
  873. package/src/cli/local-bridge/frontend/src/features/capabilities/CapabilitiesView.tsx +0 -37
  874. package/src/cli/local-bridge/frontend/src/features/overview/OverviewView.tsx +0 -183
  875. package/src/cli/local-bridge/frontend/src/features/repositories/RepositoriesView.tsx +0 -2
  876. package/src/cli/local-bridge/frontend/src/features/system/SystemView.tsx +0 -2
  877. package/src/cli/local-bridge/frontend/src/features/work/WorkView.tsx +0 -4
  878. package/src/cli/local-bridge/frontend/src/lib/api.ts +0 -30
  879. package/src/cli/local-bridge/frontend/src/lib/format.ts +0 -4
  880. package/src/cli/local-bridge/frontend/src/lib/routes.ts +0 -7
  881. package/src/cli/local-bridge/frontend/src/main.tsx +0 -1
  882. package/src/cli/local-bridge/frontend/src/shell/AppShell.tsx +0 -1
  883. package/src/cli/local-bridge/frontend/src/shell/CommandBar.tsx +0 -2
  884. package/src/cli/local-bridge/frontend/src/shell/Sidebar.tsx +0 -4
  885. package/src/cli/local-bridge/frontend/src/styles.css +0 -28
  886. package/src/cli/local-bridge/frontend/src/types.ts +0 -15
  887. package/src/cli/local-bridge/frontend/src/vite-env.d.ts +0 -1
  888. package/src/cli/local-bridge/frontend/vite.config.ts +0 -27
  889. package/src/cli/local-bridge/ui-dist/app.css +0 -1
  890. package/src/cli/local-bridge/ui-dist/app.js +0 -11228
  891. package/src/runtime/control-plane/execution/direct-edit-work-completion.ts +0 -385
  892. package/src/runtime/control-plane/execution/work-finalization-service.ts +0 -1913
  893. package/src/runtime/control-plane/execution/work-path-scope.ts +0 -37
  894. package/src/runtime/control-plane/execution/work-task-receipt.ts +0 -449
  895. package/src/runtime/control-plane/facade/controller-round-relay.ts +0 -1118
  896. package/src/runtime/control-plane/facade/work-admission-policy.ts +0 -93
  897. package/src/runtime/control-plane/facade/work-task-projection.ts +0 -66
  898. package/src/runtime/control-plane/routing/index.ts +0 -1
  899. package/src/runtime/control-plane/routing/route-policy.ts +0 -382
  900. package/src/runtime/control-plane/routing/workspace-admission.ts +0 -70
@@ -43,9 +43,20 @@ function forbidBetween(path, startNeedle, endNeedle, expression, description) {
43
43
  }
44
44
  if (expression.test(source.slice(start, end))) failures.push(`${path} violates ${description}`);
45
45
  }
46
+ const GENERATED_SOURCE_DIRECTORY_NAMES = new Set([
47
+ 'node_modules',
48
+ 'dist',
49
+ 'build',
50
+ 'coverage',
51
+ 'target',
52
+ ]);
53
+
46
54
  function sourceFiles(directory) {
55
+ const absolute = resolve(root, directory);
56
+ if (!existsSync(absolute)) return [];
47
57
  const files = [];
48
- for (const entry of readdirSync(resolve(root, directory), { withFileTypes: true })) {
58
+ for (const entry of readdirSync(absolute, { withFileTypes: true })) {
59
+ if (entry.isDirectory() && GENERATED_SOURCE_DIRECTORY_NAMES.has(entry.name)) continue;
49
60
  const path = `${directory}/${entry.name}`;
50
61
  if (entry.isDirectory()) files.push(...sourceFiles(path));
51
62
  else if (entry.isFile() && path.endsWith('.ts')) files.push(path);
@@ -53,18 +64,133 @@ function sourceFiles(directory) {
53
64
  return files;
54
65
  }
55
66
 
56
- function relativeStaticTypeScriptDependencyGraph(directory = 'src') {
57
- let ts;
67
+ function productionTypeScriptFiles() {
68
+ return [
69
+ ...sourceFiles('src'),
70
+ ...sourceFiles('packages'),
71
+ ...sourceFiles('adapters'),
72
+ ...sourceFiles('apps'),
73
+ ...sourceFiles('plugins'),
74
+ ].sort();
75
+ }
76
+
77
+ let typeScriptCompiler;
78
+ let typeScriptCompilerLoadAttempted = false;
79
+ function loadTypeScriptCompiler() {
80
+ if (typeScriptCompilerLoadAttempted) return typeScriptCompiler;
81
+ typeScriptCompilerLoadAttempted = true;
58
82
  try {
59
- ts = createRequire(import.meta.url)('typescript');
83
+ typeScriptCompiler = createRequire(import.meta.url)('typescript');
60
84
  } catch (error) {
61
- failures.push(`TypeScript dependency is required for architecture import-cycle analysis: ${error instanceof Error ? error.message : String(error)}`);
62
- return new Map();
85
+ failures.push(`TypeScript dependency is required for architecture import analysis: ${error instanceof Error ? error.message : String(error)}`);
86
+ }
87
+ return typeScriptCompiler;
88
+ }
89
+
90
+ const WORK_LIFECYCLE_PATCH_FIELDS = new Set(['status', 'phase', 'dispatchState', 'evidenceState', 'workKind']);
91
+
92
+ function unwrapTypeScriptExpression(ts, node) {
93
+ let current = node;
94
+ while (ts.isParenthesizedExpression(current)
95
+ || ts.isAsExpression(current)
96
+ || ts.isTypeAssertionExpression(current)
97
+ || ts.isNonNullExpression(current)
98
+ || (typeof ts.isSatisfiesExpression === 'function' && ts.isSatisfiesExpression(current))) {
99
+ current = current.expression;
100
+ }
101
+ return current;
102
+ }
103
+
104
+ function staticTypeScriptPropertyName(ts, name) {
105
+ if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name)) return name.text;
106
+ if (ts.isComputedPropertyName(name) && ts.isStringLiteralLike(name.expression)) return name.expression.text;
107
+ return undefined;
108
+ }
109
+
110
+ function inlineWorkLifecyclePatchFields(ts, node) {
111
+ const expression = unwrapTypeScriptExpression(ts, node);
112
+ if (!ts.isObjectLiteralExpression(expression)) return [];
113
+ const fields = new Set();
114
+ for (const property of expression.properties) {
115
+ if (ts.isSpreadAssignment(property)) {
116
+ for (const field of inlineWorkLifecyclePatchFields(ts, property.expression)) fields.add(field);
117
+ continue;
118
+ }
119
+ if (!(ts.isPropertyAssignment(property)
120
+ || ts.isShorthandPropertyAssignment(property)
121
+ || ts.isMethodDeclaration(property)
122
+ || ts.isGetAccessorDeclaration(property)
123
+ || ts.isSetAccessorDeclaration(property))) continue;
124
+ const name = staticTypeScriptPropertyName(ts, property.name);
125
+ if (name && WORK_LIFECYCLE_PATCH_FIELDS.has(name)) fields.add(name);
126
+ }
127
+ return [...fields].sort();
128
+ }
129
+
130
+ function genericWorkLifecycleMutationRecords(files) {
131
+ const ts = loadTypeScriptCompiler();
132
+ if (!ts) return [];
133
+ const records = [];
134
+ for (const path of [...files].sort()) {
135
+ const sourceFile = ts.createSourceFile(path, text(path), ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
136
+ function visit(node) {
137
+ if (ts.isCallExpression(node) && node.arguments.length >= 3) {
138
+ const callee = node.expression;
139
+ const callName = ts.isIdentifier(callee)
140
+ ? callee.text
141
+ : ts.isPropertyAccessExpression(callee)
142
+ ? callee.name.text
143
+ : undefined;
144
+ if (callName === 'updateWorkContract') {
145
+ const fields = inlineWorkLifecyclePatchFields(ts, node.arguments[2]);
146
+ if (fields.length > 0) {
147
+ const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
148
+ records.push({ path, line: line + 1, fields });
149
+ }
150
+ }
151
+ }
152
+ ts.forEachChild(node, visit);
153
+ }
154
+ visit(sourceFile);
155
+ }
156
+ return records;
157
+ }
158
+
159
+ function staticTypeScriptImportRecords(files) {
160
+ const ts = loadTypeScriptCompiler();
161
+ if (!ts) return [];
162
+ const records = [];
163
+ for (const path of [...files].sort()) {
164
+ const sourceFile = ts.createSourceFile(path, text(path), ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
165
+ function visit(node) {
166
+ let specifier;
167
+ if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node))
168
+ && node.moduleSpecifier
169
+ && ts.isStringLiteralLike(node.moduleSpecifier)) {
170
+ specifier = node.moduleSpecifier.text;
171
+ } else if (ts.isImportEqualsDeclaration(node)
172
+ && ts.isExternalModuleReference(node.moduleReference)
173
+ && node.moduleReference.expression
174
+ && ts.isStringLiteralLike(node.moduleReference.expression)) {
175
+ specifier = node.moduleReference.expression.text;
176
+ } else if (ts.isCallExpression(node)
177
+ && node.expression.kind === ts.SyntaxKind.ImportKeyword
178
+ && node.arguments.length === 1
179
+ && ts.isStringLiteralLike(node.arguments[0])) {
180
+ specifier = node.arguments[0].text;
181
+ }
182
+ if (specifier) records.push({ from: path, specifier });
183
+ ts.forEachChild(node, visit);
184
+ }
185
+ visit(sourceFile);
63
186
  }
187
+ return records;
188
+ }
64
189
 
65
- const files = sourceFiles(directory).sort();
66
- const known = new Set(files);
67
- const graph = new Map(files.map((path) => [path, new Set()]));
190
+ function staticTypeScriptDependencyGraph(files) {
191
+ const orderedFiles = [...files].sort();
192
+ const known = new Set(orderedFiles);
193
+ const graph = new Map(orderedFiles.map((path) => [path, new Set()]));
68
194
 
69
195
  function resolveTypeScriptImport(fromPath, specifier) {
70
196
  if (!specifier.startsWith('.')) return undefined;
@@ -79,28 +205,390 @@ function relativeStaticTypeScriptDependencyGraph(directory = 'src') {
79
205
  return candidates.find((candidate) => known.has(candidate));
80
206
  }
81
207
 
82
- for (const path of files) {
83
- const sourceFile = ts.createSourceFile(path, text(path), ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
84
- for (const statement of sourceFile.statements) {
85
- let specifier;
86
- if ((ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement))
87
- && statement.moduleSpecifier
88
- && ts.isStringLiteralLike(statement.moduleSpecifier)) {
89
- specifier = statement.moduleSpecifier.text;
90
- } else if (ts.isImportEqualsDeclaration(statement)
91
- && ts.isExternalModuleReference(statement.moduleReference)
92
- && statement.moduleReference.expression
93
- && ts.isStringLiteralLike(statement.moduleReference.expression)) {
94
- specifier = statement.moduleReference.expression.text;
208
+ for (const { from, specifier } of staticTypeScriptImportRecords(orderedFiles)) {
209
+ const target = resolveTypeScriptImport(from, specifier);
210
+ if (target) graph.get(from).add(target);
211
+ }
212
+ return graph;
213
+ }
214
+
215
+ function relativeStaticTypeScriptDependencyGraph(directory = 'src') {
216
+ return staticTypeScriptDependencyGraph(sourceFiles(directory));
217
+ }
218
+
219
+ function productionStaticTypeScriptDependencyGraph() {
220
+ return staticTypeScriptDependencyGraph(productionTypeScriptFiles());
221
+ }
222
+
223
+ function dependencyEdges(graph) {
224
+ const edges = [];
225
+ for (const [from, targets] of graph) {
226
+ for (const to of targets) edges.push(`${from} -> ${to}`);
227
+ }
228
+ return edges.sort();
229
+ }
230
+
231
+ function edgeSet(graph, predicate) {
232
+ return new Set(dependencyEdges(graph).filter((edge) => predicate(edge)));
233
+ }
234
+
235
+ function edgeParts(edge) {
236
+ const separator = edge.indexOf(' -> ');
237
+ return { from: edge.slice(0, separator), to: edge.slice(separator + 4) };
238
+ }
239
+
240
+ function architectureRoot(path) {
241
+ if (path.startsWith('packages/kernel/')) return path.split('/').slice(0, 3).join('/');
242
+ if (path.startsWith('adapters/')) return path.split('/').slice(0, 2).join('/');
243
+ if (path.startsWith('apps/')) return path.split('/').slice(0, 2).join('/');
244
+ if (path.startsWith('plugins/')) return path.split('/').slice(0, 2).join('/');
245
+ if (path.startsWith('src/runtime/root/')) return 'src/runtime/root';
246
+ return path.startsWith('src/') ? 'src' : path.split('/')[0];
247
+ }
248
+
249
+ function requireExactShrinkingDebt(label, actual, allowed) {
250
+ for (const edge of actual) {
251
+ if (!allowed.has(edge)) failures.push(`${label} introduced forbidden dependency: ${edge}`);
252
+ }
253
+ for (const edge of allowed) {
254
+ if (!actual.has(edge)) failures.push(`${label} allowlist contains retired dependency; remove it so the debt ledger only shrinks: ${edge}`);
255
+ }
256
+ }
257
+
258
+ function requireExactShrinkingInventory(label, actual, allowed) {
259
+ for (const entry of actual) {
260
+ if (!allowed.has(entry)) failures.push(`${label} introduced forbidden entry: ${entry}`);
261
+ }
262
+ for (const entry of allowed) {
263
+ if (!actual.has(entry)) failures.push(`${label} allowlist contains retired entry; remove it so the debt ledger only shrinks: ${entry}`);
264
+ }
265
+ }
266
+
267
+ // Thin rh_work boundary: semantic Requirement/Plan/Work records and explicit
268
+ // launcher/schedule/workflow intent only. Repository execution, checks and Git
269
+ // delivery stay on their typed capability surfaces; old lifecycle verbs are gone.
270
+ requireText('adapters/mcp/runtime-gateway/runtime-tools.ts', "if (name === 'rh_work') return callWorkAdapter(ctx, args);");
271
+ requireText('adapters/mcp/runtime-gateway/work-controller-operations.ts', "const RH_WORK_CONTROLLER_OPERATIONS = new Set(['launcher_start']);");
272
+ requireText('adapters/mcp/runtime-gateway/work-adapter.ts', "if (operation === 'launcher_start')");
273
+ requireText('adapters/mcp/runtime-gateway/work-requirement-operations.ts', 'export async function callRhWorkRequirementOperation');
274
+ requireText('adapters/mcp/runtime-gateway/work-plan-operations.ts', 'export async function callRhWorkPlanOperation');
275
+ requireText('adapters/mcp/runtime-gateway/work-plan-operations.ts', 'export async function callRhWorkPlanCreateOperation');
276
+ requireText('adapters/mcp/runtime-gateway/work-adapter.ts', 'callRhWorkRequirementOperation(ctx, repository, operation, args)');
277
+ requireText('adapters/mcp/runtime-gateway/work-adapter.ts', 'callRhWorkPlanOperation(store, operation, args)');
278
+ requireText('adapters/mcp/runtime-gateway/work-adapter.ts', 'callRhWorkPlanCreateOperation(store, operation, args');
279
+ forbid('adapters/mcp/runtime-gateway/work-adapter.ts', /operation === ['"](?:continue|verify|review|finalize|stop|delegate|controller_get_owner|controller_claim|controller_disposition|controller_release)['"]/, 'thin rh_work must not route retired lifecycle/controller operations');
280
+ forbid('adapters/mcp/runtime-gateway/work-adapter.ts', /\b(?:transitionWorkHandle|writeWorkHandle|markWorkHandleFailed|executeWorkVerification|requestWorkImplementationReview)\b/, 'rh_work must not own mechanical execution, verification or review authority');
281
+ forbid('adapters/mcp/runtime-gateway/work-adapter.ts', /repositoryGit(?:Commit|FinishWorkflow|MergeBranch|DeleteBranch|RebaseOnto)\s*\(/, 'rh_work must not perform physical Git delivery');
282
+ forbid('adapters/mcp/runtime-gateway/work-adapter.ts', /control-plane\/facade\/work-contract-store|kernel\/work\/infrastructure/, 'rh_work must consume canonical semantic APIs instead of persistence infrastructure');
283
+ forbid('adapters/mcp/runtime-gateway/work-plan-operations.ts', /plan_approve|plan_accept_step|plan_supersede|approvePlanContractAsync|acceptPlanStepEvidence|supersedePlanContract/, 'retired Plan approval/acceptance/supersession APIs must not remain on the runtime surface');
284
+ forbid('src/runtime/control-plane/facade/plan-contract-store.ts', /approvePlanContract|approvePendingPlanRevision|supersedePlanContract|plan_revision_approved/, 'legacy Plan approval/supersession writers must stay retired');
285
+
286
+ // #197 MCP mega-adapter decomposition. These are debt ledgers, not target
287
+ // architecture: entries may only disappear. New domain-authority imports or
288
+ // switch cases must be implemented in the owning domain adapter/application API,
289
+ // never added to runtime-tools/router while decomposition is in progress.
290
+ const MCP_GATEWAY_AUTHORITY_IMPORT_PATTERN = /(?:packages\/kernel\/|src\/runtime\/|src\/cli\/(?:repositories|editing)\/)/;
291
+
292
+ function gatewayAuthorityImportInventoryFromSources(sources, importPattern = MCP_GATEWAY_AUTHORITY_IMPORT_PATTERN) {
293
+
294
+ const ts = loadTypeScriptCompiler();
295
+ if (!ts) return new Set();
296
+ const records = new Set();
297
+ for (const { path, source } of sources) {
298
+ const sourceFile = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
299
+ function visit(node) {
300
+ if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node))
301
+ && node.moduleSpecifier
302
+ && ts.isStringLiteralLike(node.moduleSpecifier)
303
+ && importPattern.test(node.moduleSpecifier.text)) {
304
+ records.add(`${path}::${node.moduleSpecifier.text}`);
95
305
  }
96
- if (!specifier) continue;
97
- const target = resolveTypeScriptImport(path, specifier);
98
- if (target) graph.get(path).add(target);
306
+ ts.forEachChild(node, visit);
99
307
  }
308
+ visit(sourceFile);
100
309
  }
101
- return graph;
310
+ return records;
311
+ }
312
+
313
+ function runtimeToolSwitchCaseInventory(source) {
314
+ const marker = 'export async function callRuntimeTool';
315
+ const start = source.indexOf(marker);
316
+ if (start < 0) return new Set();
317
+ return new Set([...source.slice(start).matchAll(/case\s+['"]([^'"]+)['"]\s*:/g)].map((match) => match[1]));
318
+ }
319
+
320
+ const SUPERVISOR_CONCRETE_BROWSER_TRANSPORT_IMPORT_PATTERN = /(?:browser-macos-bridge|browser-adapter|chrome-extension|native-messaging)/;
321
+
322
+ function supervisorConcreteBrowserTransportImportsFromSources(sources) {
323
+ return gatewayAuthorityImportInventoryFromSources(sources, SUPERVISOR_CONCRETE_BROWSER_TRANSPORT_IMPORT_PATTERN);
324
+ }
325
+
326
+ const supervisorComputerBoundaryFixture = process.env.FORGE_SUPERVISOR_COMPUTER_BOUNDARY_FIXTURE;
327
+ if (supervisorComputerBoundaryFixture) {
328
+ const fixture = JSON.parse(supervisorComputerBoundaryFixture);
329
+ const sources = Array.isArray(fixture.sources) ? fixture.sources : [];
330
+ const actual = supervisorConcreteBrowserTransportImportsFromSources(sources);
331
+ if (actual.size > 0) {
332
+ console.error('[supervisor-computer-boundary-guardrail] FAILED');
333
+ for (const record of actual) console.error(`- Workflow Supervisor semantic code must depend on Computer target ports, never concrete Browser transports: ${record}`);
334
+ process.exit(1);
335
+ }
336
+ console.log('[supervisor-computer-boundary-guardrail] OK');
337
+ process.exit(0);
338
+ }
339
+
340
+ const MCP_RUNTIME_GATEWAY_AUTHORITY_IMPORT_DEBT = new Set([
341
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts::../../../src/runtime/execution/process-runtime/check-result',
342
+ ]);
343
+
344
+ const MCP_RUNTIME_TOOLS_SWITCH_CASE_DEBT = new Set();
345
+
346
+ const mcpAdapterBoundaryFixture = process.env.FORGE_MCP_RUNTIME_ADAPTER_BOUNDARY_FIXTURE;
347
+ if (mcpAdapterBoundaryFixture) {
348
+ const fixture = JSON.parse(mcpAdapterBoundaryFixture);
349
+ const sources = Array.isArray(fixture.sources) ? fixture.sources : [];
350
+ requireExactShrinkingDebt(
351
+ 'MCP runtime adapter authority-import fixture debt',
352
+ gatewayAuthorityImportInventoryFromSources(sources),
353
+ new Set(Array.isArray(fixture.allowedImports) ? fixture.allowedImports : []),
354
+ );
355
+ const runtimeSource = sources.find((entry) => entry.path === 'adapters/mcp/runtime-gateway/runtime-tools.ts')?.source ?? '';
356
+ requireExactShrinkingInventory(
357
+ 'MCP runtime-tools switch-case fixture debt',
358
+ runtimeToolSwitchCaseInventory(runtimeSource),
359
+ new Set(Array.isArray(fixture.allowedCases) ? fixture.allowedCases : []),
360
+ );
361
+ if (failures.length) {
362
+ console.error('[mcp-runtime-adapter-boundary-guardrail] FAILED');
363
+ for (const failure of failures) console.error(`- ${failure}`);
364
+ process.exit(1);
365
+ }
366
+ console.log('[mcp-runtime-adapter-boundary-guardrail] OK');
367
+ process.exit(0);
368
+ }
369
+
370
+ requireExactShrinkingDebt(
371
+ 'MCP runtime mega-adapter direct domain-authority import debt',
372
+ gatewayAuthorityImportInventoryFromSources([
373
+ { path: 'adapters/mcp/runtime-gateway/runtime-tools.ts', source: text('adapters/mcp/runtime-gateway/runtime-tools.ts') },
374
+ { path: 'adapters/mcp/runtime-gateway/router.ts', source: text('adapters/mcp/runtime-gateway/router.ts') },
375
+ ]),
376
+ MCP_RUNTIME_GATEWAY_AUTHORITY_IMPORT_DEBT,
377
+ );
378
+ requireExactShrinkingInventory(
379
+ 'MCP runtime-tools switch-case debt',
380
+ runtimeToolSwitchCaseInventory(text('adapters/mcp/runtime-gateway/runtime-tools.ts')),
381
+ MCP_RUNTIME_TOOLS_SWITCH_CASE_DEBT,
382
+ );
383
+ const supervisorSemanticSources = sourceFiles('supervisor')
384
+ .filter((path) => !path.startsWith('supervisor/native-messaging/'))
385
+ .map((path) => ({ path, source: text(path) }));
386
+ requireExactShrinkingDebt(
387
+ 'Workflow Supervisor concrete Browser transport imports',
388
+ supervisorConcreteBrowserTransportImportsFromSources(supervisorSemanticSources),
389
+ new Set(),
390
+ );
391
+ for (const path of supervisorSemanticSources.map((entry) => entry.path)) {
392
+ forbid(path, /\b(?:windowId|tabId|window\.name)\b/, 'Workflow Supervisor semantic code must not own provider tab/window identity; Computer target authority owns provider bindings');
393
+ }
394
+
395
+
396
+ const MCP_PURE_TRANSPORT_FORBIDDEN_IMPORT_PATTERN = /(?:packages\/kernel\/|src\/runtime\/)/;
397
+ requireExactShrinkingDebt(
398
+ 'MCP pure transport adapter authority imports',
399
+ gatewayAuthorityImportInventoryFromSources([
400
+ { path: 'adapters/mcp/runtime-gateway/shared-adapter.ts', source: text('adapters/mcp/runtime-gateway/shared-adapter.ts') },
401
+ { path: 'adapters/mcp/runtime-gateway/result-adapter.ts', source: text('adapters/mcp/runtime-gateway/result-adapter.ts') },
402
+ ], MCP_PURE_TRANSPORT_FORBIDDEN_IMPORT_PATTERN),
403
+ new Set(),
404
+ );
405
+
406
+ // Hard cutover: retired lifecycle decoders remain absent. One bounded
407
+ // frozen-session wire decoder may translate the pre-Thin semantic.v1 carrier
408
+ // and current-conversation enrollment into current owners because host MCP
409
+ // schemas can remain frozen across Runtime reconnect. That decoder owns no
410
+ // lifecycle or persistence and must not grow retired lifecycle carriers.
411
+ for (const path of [
412
+ 'adapters/mcp/runtime-gateway/work-controller-recovery-operations.ts',
413
+ 'adapters/mcp/controller-round-compatibility.ts',
414
+ 'adapters/mcp/frozen-client-semantic-compatibility.ts',
415
+ ]) requireMissing(path);
416
+ requireText(
417
+ 'adapters/mcp/runtime-gateway/work-input-wire-migration.ts',
418
+ "const FROZEN_SEMANTIC_V1_PREFIX = 'semantic.v1:';",
419
+ );
420
+ requireText(
421
+ 'adapters/mcp/runtime-gateway/work-input-wire-migration.ts',
422
+ "const FROZEN_CURRENT_CONVERSATION_ENROLLMENT = 'controller.current_conversation.enroll';",
423
+ );
424
+ forbid(
425
+ 'adapters/mcp/runtime-gateway/work-input-wire-migration.ts',
426
+ /schedule\.delete:|work\.review:|controller\.(?:authority|provider|disposition|round):|plan\.step\.retry:/,
427
+ 'the bounded frozen-session decoder must not restore retired lifecycle carriers',
428
+ );
429
+ for (const path of sourceFiles('adapters/mcp')) {
430
+ if (path === 'adapters/mcp/runtime-gateway/work-input-wire-migration.ts') continue;
431
+ forbid(path, /semantic\.v1:/, 'semantic.v1 frozen-session decoding must have exactly one transport owner');
432
+ }
433
+
434
+ const SEMANTIC_AUTHORITY_CRITICAL_ROOTS = [
435
+ 'packages/kernel',
436
+ 'src/runtime/control-plane',
437
+ 'src/runtime/execution',
438
+ 'adapters/mcp/runtime-gateway',
439
+ 'src/cli/local-bridge',
440
+ ];
441
+ const HUMAN_READABLE_SEMANTIC_FIELDS = new Set(['message', 'reason', 'description', 'checkId', 'check_id']);
442
+ const HUMAN_READABLE_STRING_MATCH_METHODS = new Set(['includes', 'startsWith', 'endsWith', 'match', 'search']);
443
+
444
+ function humanReadableSemanticExpression(ts, node) {
445
+ if (ts.isIdentifier(node)) return HUMAN_READABLE_SEMANTIC_FIELDS.has(node.text);
446
+ if (ts.isPropertyAccessExpression(node)) return HUMAN_READABLE_SEMANTIC_FIELDS.has(node.name.text);
447
+ if (ts.isElementAccessExpression(node)
448
+ && node.argumentExpression
449
+ && ts.isStringLiteralLike(node.argumentExpression)) {
450
+ return HUMAN_READABLE_SEMANTIC_FIELDS.has(node.argumentExpression.text);
451
+ }
452
+ if (ts.isParenthesizedExpression(node)
453
+ || ts.isAsExpression(node)
454
+ || ts.isTypeAssertionExpression(node)
455
+ || ts.isNonNullExpression(node)) {
456
+ return humanReadableSemanticExpression(ts, node.expression);
457
+ }
458
+ if (ts.isConditionalExpression(node)) {
459
+ return humanReadableSemanticExpression(ts, node.whenTrue)
460
+ || humanReadableSemanticExpression(ts, node.whenFalse);
461
+ }
462
+ if (ts.isCallExpression(node)
463
+ && ts.isPropertyAccessExpression(node.expression)
464
+ && ['trim', 'toLowerCase', 'toUpperCase'].includes(node.expression.name.text)) {
465
+ return humanReadableSemanticExpression(ts, node.expression.expression);
466
+ }
467
+ return false;
468
+ }
469
+
470
+ function isHumanReadableSemanticMatcherCall(ts, node) {
471
+ if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression)) return false;
472
+ const method = node.expression.name.text;
473
+ if (HUMAN_READABLE_STRING_MATCH_METHODS.has(method)
474
+ && humanReadableSemanticExpression(ts, node.expression.expression)) return true;
475
+ return method === 'test' && node.arguments.some((argument) => humanReadableSemanticExpression(ts, argument));
476
+ }
477
+
478
+ function semanticAuthorityStringMatchRecordsFromSources(sources) {
479
+ const ts = loadTypeScriptCompiler();
480
+ if (!ts) return new Set();
481
+ const records = new Set();
482
+ for (const { path, source } of [...sources].sort((left, right) => left.path.localeCompare(right.path))) {
483
+ const sourceFile = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
484
+ function collectCondition(expression) {
485
+ function visitCondition(node) {
486
+ if (isHumanReadableSemanticMatcherCall(ts, node)) {
487
+ records.add(`${path}::${node.getText(sourceFile).replace(/\s+/g, ' ').trim()}`);
488
+ }
489
+ ts.forEachChild(node, visitCondition);
490
+ }
491
+ visitCondition(expression);
492
+ }
493
+ function visit(node) {
494
+ if (ts.isIfStatement(node) || ts.isWhileStatement(node) || ts.isDoStatement(node)) collectCondition(node.expression);
495
+ else if (ts.isConditionalExpression(node)) collectCondition(node.condition);
496
+ else if (ts.isForStatement(node) && node.condition) collectCondition(node.condition);
497
+ ts.forEachChild(node, visit);
498
+ }
499
+ visit(sourceFile);
500
+ }
501
+ return records;
502
+ }
503
+
504
+ function semanticAuthorityProductionStringMatchRecords() {
505
+ const paths = SEMANTIC_AUTHORITY_CRITICAL_ROOTS.flatMap((directory) => sourceFiles(directory));
506
+ return semanticAuthorityStringMatchRecordsFromSources(paths.map((path) => ({ path, source: text(path) })));
507
+ }
508
+
509
+ const LEGACY_INTERACTION_AUTHORITY_OWNER_DECLARATION = /\b(?:class|interface|type|function|const)\s+\w*(?:Browser|Desktop)\w*(?:Authority|Persistence)\b/;
510
+ function legacyInteractionAuthorityOwnerRecordsFromSources(sources) {
511
+ const records = new Set();
512
+ for (const { path, source } of sources) {
513
+ for (const line of String(source).split('\n')) {
514
+ if (LEGACY_INTERACTION_AUTHORITY_OWNER_DECLARATION.test(line)) records.add(`${path}::${line.trim()}`);
515
+ }
516
+ }
517
+ return records;
518
+ }
519
+
520
+ const interactionAuthorityGuardrailFixture = process.env.FORGE_INTERACTION_AUTHORITY_GUARDRAIL_FIXTURE;
521
+ if (interactionAuthorityGuardrailFixture) {
522
+ const fixture = JSON.parse(interactionAuthorityGuardrailFixture);
523
+ const actual = legacyInteractionAuthorityOwnerRecordsFromSources(Array.isArray(fixture.sources) ? fixture.sources : []);
524
+ if (actual.size > 0) {
525
+ console.error('[interaction-authority-guardrail] FAILED');
526
+ for (const record of actual) console.error(`- Browser/Desktop durable interaction authority must live only in Computer target authority: ${record}`);
527
+ process.exit(1);
528
+ }
529
+ console.log('[interaction-authority-guardrail] OK');
530
+ process.exit(0);
102
531
  }
103
532
 
533
+ const semanticAuthorityGuardrailFixture = process.env.FORGE_SEMANTIC_AUTHORITY_GUARDRAIL_FIXTURE;
534
+ if (semanticAuthorityGuardrailFixture) {
535
+ const fixture = JSON.parse(semanticAuthorityGuardrailFixture);
536
+ const actual = semanticAuthorityStringMatchRecordsFromSources(Array.isArray(fixture.sources) ? fixture.sources : []);
537
+ const allowed = new Set(Array.isArray(fixture.allowed) ? fixture.allowed : []);
538
+ requireExactShrinkingInventory('semantic authority fixture debt', actual, allowed);
539
+ if (failures.length) {
540
+ console.error('[semantic-authority-guardrail] FAILED');
541
+ for (const failure of failures) console.error(`- ${failure}`);
542
+ process.exit(1);
543
+ }
544
+ console.log(`[semantic-authority-guardrail] OK (${actual.size} debt entries)`);
545
+ process.exit(0);
546
+ }
547
+
548
+ const SEMANTIC_STRING_AUTHORITY_DEBT = new Set([
549
+ `adapters/mcp/runtime-gateway/execution-tools.ts::message.includes(':')`,
550
+ `adapters/mcp/runtime-gateway/process-tools.ts::message.includes(':')`,
551
+ `adapters/mcp/runtime-gateway/context-adapter.ts::error.message.startsWith('PLUGIN_NOT_FOUND:')`,
552
+ `packages/kernel/controller/domain/controller-round-transition-policy.ts::reason.startsWith('consecutive_failures:')`,
553
+ `packages/kernel/controller/domain/controller-round-transition-policy.ts::reason.startsWith('repeated_state:')`,
554
+ `packages/kernel/controller/domain/controller-round-transition-policy.ts::reason.startsWith('round_budget_exhausted:')`,
555
+ `packages/kernel/controller/application/continuation-service.ts::error.message.startsWith('CONTROLLER_RELAY_ROUND_ALREADY_OPEN:')`,
556
+ `src/cli/local-bridge/job-store.ts::message.startsWith(\"LOCAL_JOB_ID_REQUIRED:\")`,
557
+ `src/cli/local-bridge/job-store.ts::message.startsWith(\"LOCAL_JOB_PATH_INVALID:\")`,
558
+ `src/cli/local-bridge/server.ts::message.startsWith(\"REPOSITORY_SELF_PROTECTED\")`,
559
+ `src/runtime/control-plane/execution/work-execution-support.ts::reason.includes('infrastructure')`,
560
+ `src/runtime/control-plane/execution/work-execution-support.ts::reason.includes('terminal')`,
561
+ `src/runtime/control-plane/execution/work-execution-support.ts::reason.includes('timed out')`,
562
+ `src/runtime/control-plane/execution/work-execution-support.ts::reason.includes('unavailable')`,
563
+ `src/runtime/control-plane/execution/work-head-settlement.ts::error.message.includes('CONTROL_PLANE_REVISION_CONFLICT')`,
564
+ `src/runtime/control-plane/facade/requirement-authority.ts::error.message.startsWith('REQUIREMENT_ALREADY_EXISTS:')`,
565
+ `src/runtime/control-plane/global-scheduler/reconciliation.ts::message.includes(':')`,
566
+ `src/runtime/control-plane/global-scheduler/scheduler.ts::error.message.startsWith('LOCK_HELD:')`,
567
+ `src/runtime/control-plane/launcher/chatgpt-work-continuation.ts::error.message.includes(':')`,
568
+ `src/runtime/control-plane/persistence/sqlite-store.ts::(error instanceof Error ? error.message : String(error)).startsWith('CONTROL_PLANE_SQLITE_BUSY:')`,
569
+ `src/runtime/control-plane/persistence/sqlite-store.ts::/database is locked|SQLITE_BUSY/i.test(message)`,
570
+ `src/runtime/control-plane/persistence/sqlite-store.ts::message.startsWith('CONTROL_PLANE_')`,
571
+ `src/runtime/control-plane/persistence/sqlite-store.ts::message.startsWith('CONTROL_PLANE_SQLITE_CORRUPT:')`,
572
+ `src/runtime/execution/process-runtime/lightweight-managed.ts::error.message.startsWith('PROCESS_REQUEST_CONFLICT:')`,
573
+ `src/runtime/execution/process-runtime/process-runner-entry.ts::message.startsWith('PROCESS_RUNNER_ALREADY_STARTED:')`,
574
+ `src/runtime/execution/process-runtime/process-runner-entry.ts::message.startsWith('PROCESS_RUNNER_RECEIPT_CORRUPT:')`,
575
+ `src/runtime/execution/thin-harness/fast-executor.ts::message.includes(':')`,
576
+ `src/runtime/execution/thin-harness/fast-executor.ts::message.includes('\\0')`,
577
+ `src/runtime/execution/thin-harness/fingerprint-worker.ts::error.message.startsWith('SNAPSHOT_BUDGET')`,
578
+ `src/runtime/execution/thin-harness/fingerprint-worker.ts::message.startsWith('CANCELLED')`,
579
+ `src/runtime/execution/thin-harness/fingerprint-worker.ts::message.startsWith('SNAPSHOT_BUDGET')`,
580
+ `src/runtime/execution/thin-harness/fingerprint-worker.ts::message.startsWith('SNAPSHOT_TOO_DIRTY')`,
581
+ `src/runtime/execution/thin-harness/fingerprint-worker.ts::message.startsWith('SNAPSHOT_WORKER_TIMEOUT')`,
582
+ `src/runtime/execution/workers/executor.ts::message.startsWith('LEGACY_JOB_TIMEOUT:')`,
583
+ ]);
584
+ requireExactShrinkingInventory(
585
+ 'human-readable semantic authority debt',
586
+ semanticAuthorityProductionStringMatchRecords(),
587
+ SEMANTIC_STRING_AUTHORITY_DEBT,
588
+ );
589
+
590
+ // Kernel V2 B7 graph analysis. Legacy boundary debt below is exact and must only shrink.
591
+ // Inventory is derived from the production graph before the gate is activated.
104
592
  function stronglyConnectedComponents(graph) {
105
593
  let index = 0;
106
594
  const indices = new Map();
@@ -143,7 +631,7 @@ function stronglyConnectedComponents(graph) {
143
631
  }
144
632
 
145
633
  function requireAcyclicProductionTypeScript() {
146
- const graph = relativeStaticTypeScriptDependencyGraph('src');
634
+ const graph = productionStaticTypeScriptDependencyGraph();
147
635
  const cyclic = stronglyConnectedComponents(graph).filter((component) =>
148
636
  component.length > 1 || (component.length === 1 && graph.get(component[0])?.has(component[0])),
149
637
  );
@@ -159,7 +647,7 @@ const architectureRootMarkdown = readdirSync(resolve(root, 'docs/architecture'),
159
647
  .sort();
160
648
  for (const name of architectureRootMarkdown) {
161
649
  if (!allowedArchitectureRootMarkdown.has(name)) {
162
- failures.push(`docs/architecture/${name} must be archived under docs/architecture/history/ instead of acting as parallel root architecture authority`);
650
+ failures.push(`docs/architecture/${name} must be merged into CURRENT.md/EVOLUTION.md or deleted instead of acting as parallel root architecture authority; Git history is the archive`);
163
651
  }
164
652
  }
165
653
 
@@ -170,7 +658,7 @@ for (const path of ['README.md', 'docs/ROADMAP.md', 'docs/architecture/CURRENT.m
170
658
  }
171
659
 
172
660
  const required = [
173
- 'src/runtime/gateway/mcp/router.ts',
661
+ 'adapters/mcp/runtime-gateway/router.ts',
174
662
  'src/cli/agent-jobs/executable-resolver.ts',
175
663
  'src/runtime/control-plane/global-scheduler/scheduler.ts',
176
664
  'src/runtime/control-plane/global-scheduler/config.ts',
@@ -195,27 +683,59 @@ const required = [
195
683
  'src/runtime/execution/workers/worker-entry.ts',
196
684
  'src/runtime/execution/thin-harness/index.ts',
197
685
  'src/runtime/execution/thin-harness/execution-router.ts',
198
- 'src/runtime/control-plane/routing/route-policy.ts',
199
- 'src/runtime/control-plane/routing/workspace-admission.ts',
200
686
  'src/runtime/control-plane/facade/requirement-authority.ts',
201
687
  'src/runtime/control-plane/facade/repository-work-admission.ts',
202
688
  'src/runtime/control-plane/execution/retained-work-resume.ts',
203
689
  'src/runtime/control-plane/execution/work-handle-authority.ts',
204
690
  'src/runtime/control-plane/execution/work-verification-context.ts',
205
691
  'src/runtime/control-plane/execution/work-verification-service.ts',
692
+ 'src/runtime/control-plane/execution/implementation-review-content.ts',
693
+ 'packages/protocols/handoff/status.ts',
694
+ 'packages/kernel/work/domain/implementation-review.ts',
695
+ 'packages/kernel/work/domain/state-machine.ts',
696
+ 'packages/kernel/identity/domain/scope.ts',
697
+ 'packages/kernel/memory/domain/operational-prior.ts',
698
+ 'packages/kernel/memory/api/index.ts',
699
+ 'packages/kernel/memory/index.ts',
700
+ 'src/runtime/evidence/operational-shadow.ts',
701
+ 'src/runtime/control-plane/persistence/operational-prior-store.ts',
702
+ 'evaluation/lib/shadow-operational-prior.ts',
703
+ 'packages/kernel/work/domain/check-receipt.ts',
704
+ 'packages/kernel/work/domain/execution-snapshot.ts',
705
+ 'packages/kernel/work/domain/repository-completion-receipt.ts',
706
+ 'packages/kernel/work/domain/types.ts',
707
+ 'packages/kernel/work/application/work-service.ts',
708
+ 'packages/kernel/work/ports/work-contract-store.ts',
709
+ 'packages/kernel/work/infrastructure/work-contract-store.ts',
710
+ 'packages/kernel/work/api/index.ts',
711
+ 'packages/kernel/controller/domain/types.ts',
712
+ 'packages/kernel/controller/ports/controller-host.ts',
713
+ 'packages/kernel/controller/infrastructure/controller-session-store.ts',
714
+ 'packages/kernel/controller/application/controller-service.ts',
715
+ 'packages/kernel/controller/api/index.ts',
206
716
  'src/runtime/control-plane/execution/repository-work-attribution.ts',
207
717
  'src/runtime/control-plane/execution/work-completion-authority.ts',
208
718
  'src/runtime/control-plane/execution/work-evidence-policy.ts',
209
719
  'src/runtime/control-plane/execution/work-execution-support.ts',
210
- 'src/runtime/control-plane/execution/work-finalization-service.ts',
211
720
  'src/runtime/control-plane/execution/work-preparation-service.ts',
212
721
  'src/runtime/control-plane/execution/work-operation-service.ts',
213
- 'src/runtime/control-plane/facade/work-state-machine.ts',
214
722
  'src/runtime/evidence/process-check-execution.ts',
215
723
  'src/runtime/context/semantic-navigation-contract.ts',
216
- 'src/cli/mcp/tool-contract.ts',
724
+ 'packages/protocols/mcp/tool-contract.ts',
725
+ 'packages/protocols/mcp/execution-context.ts',
217
726
  'src/cli/github/contracts.ts',
218
- 'src/runtime/gateway/mcp/runtime-tool-definitions.ts',
727
+ 'adapters/mcp/runtime-gateway/runtime-tool-definitions.ts',
728
+ 'adapters/mcp/server.ts',
729
+ 'adapters/mcp/oauth.ts',
730
+ 'adapters/mcp/multi-repository.ts',
731
+ 'adapters/mcp/toolset.ts',
732
+ 'adapters/mcp/tool-mapping/tools.ts',
733
+ 'adapters/mcp/tool-mapping/legacy-tool-service.ts',
734
+ 'adapters/mcp/tool-mapping/repository-tools.ts',
735
+ 'adapters/mcp/tool-mapping/access-tools.ts',
736
+ 'adapters/mcp/transports/http.ts',
737
+ 'adapters/mcp/transports/stdio.ts',
738
+ 'adapters/mcp/transports/session-registry.ts',
219
739
  'docs/architecture/CURRENT.md',
220
740
  'src/runtime/resources/leases/store.ts',
221
741
  'src/runtime/evidence/event-ledger.ts',
@@ -245,17 +765,138 @@ const required = [
245
765
  ];
246
766
  for (const path of required) text(path);
247
767
  requireAcyclicProductionTypeScript();
768
+ // Operational priors retain their bounded mechanical consumers. The accepted
769
+ // assistant-loop ADR adds semantic experience through its own API/adapter;
770
+ // neither consumer may move persistence or semantic acceptance into the reducer.
771
+ const stage7fMemoryImports = staticTypeScriptImportRecords(productionTypeScriptFiles());
772
+ const stage7fKernelMemoryConsumers = new Set([
773
+ 'src/runtime/evidence/operational-shadow.ts',
774
+ 'src/runtime/control-plane/persistence/operational-prior-store.ts',
775
+ 'src/runtime/context/assistant-context.ts',
776
+ 'src/runtime/context/assistant-work-context.ts',
777
+ 'src/runtime/control-plane/persistence/experience-store.ts',
778
+ 'src/cli/commands/brain-assistant.ts',
779
+ ]);
780
+ const stage7fOperationalStoreConsumers = new Set([
781
+ 'src/runtime/control-plane/execution/work-verification-service.ts',
782
+ 'src/runtime/execution/process-runtime/check-facade.ts',
783
+ ]);
784
+ for (const { from, specifier } of stage7fMemoryImports) {
785
+ if (from.startsWith('packages/kernel/memory/') && /(?:src\/runtime|control-plane|sqlite-store|context-plane)/.test(specifier)) {
786
+ failures.push(`Stage7F Kernel Memory must remain pure and persistence-free: ${from} -> ${specifier}`);
787
+ }
788
+ if (/packages\/kernel\/memory/.test(specifier)
789
+ && !stage7fKernelMemoryConsumers.has(from)
790
+ && !from.startsWith('packages/kernel/memory/')) {
791
+ failures.push(`Stage7F Memory has an unauthorized production consumer: ${from} -> ${specifier}`);
792
+ }
793
+ if (/operational-shadow/.test(specifier) && from !== 'src/runtime/control-plane/persistence/operational-prior-store.ts') {
794
+ failures.push(`Stage7F typed operational extractor may feed only the derived persistence adapter: ${from} -> ${specifier}`);
795
+ }
796
+ if (/operational-prior-store/.test(specifier) && !stage7fOperationalStoreConsumers.has(from)) {
797
+ failures.push(`Stage7F operational Memory store has an unauthorized active consumer: ${from} -> ${specifier}`);
798
+ }
799
+ }
800
+ forbid('src/runtime/control-plane/persistence/operational-prior-store.ts', /context-plane|brain|pks|requirement-authority|plan-contract|approval|authorization/, 'Stage7F operational Memory must remain mechanical derived state only');
801
+ requireText('src/runtime/control-plane/persistence/operational-prior-store.ts', "OPERATIONAL_MEMORY_NAMESPACE = 'operational_memory_prior'");
802
+ requireText('src/runtime/control-plane/persistence/operational-prior-store.ts', 'resolveCheckCompletionGraceWaitMs');
803
+ requireText('src/runtime/execution/process-runtime/check-facade.ts', 'resolveCheckCompletionGraceWaitMs');
248
804
  for (const path of sourceFiles('src/runtime/control-plane')) {
249
805
  forbid(path, /(?:from\s+['"]|import\s*\(\s*['"])(?:\.\.\/)+gateway\//, 'control-plane domain/application code must not depend on Gateway transport');
250
806
  }
251
- requireText('src/runtime/control-plane/routing/route-policy.ts', "export function decideRoute");
252
- requireText('src/runtime/control-plane/routing/route-policy.ts', 'inputFingerprint');
253
- requireText('src/runtime/control-plane/routing/route-policy.ts', 'policyVersion');
807
+ for (const path of [
808
+ 'adapters/mcp/tool-mapping/repository-tools.ts',
809
+ 'adapters/mcp/tool-mapping/legacy-tool-service.ts',
810
+ 'adapters/mcp/runtime-gateway/runtime-observation-adapter.ts',
811
+ ]) {
812
+ forbid(path, /assessWorkMode|parseExplicitTaskMode|assess_work_mode|assess_work_request|recommendedMode\s*:/, 'production capability/context surfaces must not expose or infer engineering work modes');
813
+ }
814
+ // Engineering execution strategy belongs to the model. Forge must not carry a
815
+ // route/mode/driver vocabulary, a task-size or complexity heuristic, or a
816
+ // second router that decides Direct/Work/Goal, worker/provider, verify, review,
817
+ // or completion on the model's behalf.
818
+ requireMissing('src/runtime/control-plane/routing/route-policy.ts');
819
+ requireMissing('src/runtime/control-plane/routing/index.ts');
820
+ for (const path of [...sourceFiles('src'), ...sourceFiles('adapters'), ...sourceFiles('packages')]) {
821
+ forbid(
822
+ path,
823
+ /\bRouteExecutionMode\b|\bRouteWorkMode\b|\bRouteExecutionPath\b|\bExplicitTaskMode\b|\bWorkRouteDecisionSnapshot\b|\bWorkContractDriverPolicy\b|\bExecutionModeSelection\b|\bselectExecutionMode\b|\bmodeInput\b/,
824
+ 'Forge must not model engineering execution modes, work modes, execution paths, drivers, or mode selection',
825
+ );
826
+ forbid(
827
+ path,
828
+ /['"](?:direct_control|goal_workloop|handoff_only)['"]/,
829
+ 'retired engineering mode tokens must not return as typed Forge vocabulary',
830
+ );
831
+ forbid(
832
+ path,
833
+ /\bdirect_edit\b\s*\|\s*['"]bounded_work['"]|['"]bounded_work['"]\s*\|\s*['"]quick_agent['"]|['"]quick_agent['"]\s*\|\s*['"]issue_task['"]/,
834
+ 'retired work-mode vocabulary must not return',
835
+ );
836
+ }
837
+ forbid(
838
+ 'packages/kernel/work/domain/types.ts',
839
+ /\bmode:\s*ExecutionMode\b|\bdriver:\s*WorkContractDriverPolicy\b|routeDecision/,
840
+ 'WorkContract must persist no engineering-mode, driver, or route-decision authority',
841
+ );
842
+ for (const path of [...sourceFiles('src'), ...sourceFiles('adapters')]) {
843
+ forbid(
844
+ path,
845
+ /\bisSmallScopedTask\b|\bsmallScopedTask\b|\bdurableWorkRequired\b|\bcoordinationRequired\b|\bexplicitParallelMode\b|\bexpectedFiles\b|\bexpectedChangedLines\b|\brequiresInvestigation\b|\brequiresLongRunningChecks\b|\brequiresParallelism\b|\bindependentTaskCount\b|\bagentRequested\b|\broutingKey\(|\bproviderOrder\(|\bKIND_RANK\b/,
846
+ 'Forge must not infer engineering method, worker choice, or Work topology from task size, complexity, path classification, or semantic intent',
847
+ );
848
+ }
849
+ forbid(
850
+ 'src/runtime/plugins/store.ts',
851
+ /acceptSubmittedWorkContract|localSystemActionRequiresWork/,
852
+ 'plugin capability execution must not manufacture semantic Work from action risk',
853
+ );
854
+ forbid(
855
+ 'src/runtime/control-plane/facade/goal-workloop.ts',
856
+ /repositoryChangeIntent|directEditWithinBoundary|maxChangedFiles\s*<|maxChangedLines\s*</,
857
+ 'Work-kind classification must not be inferred from predicted scope size or a task-size threshold',
858
+ );
859
+ forbid(
860
+ 'src/runtime/control-plane/facade/goal-workloop.ts',
861
+ /linkedEngineeringBlockerWorkId|work-linked-engineering-blocker-/,
862
+ 'continuation must not manufacture child Work; an unrelated blocker names an explicitly created owning Work',
863
+ );
864
+ requireText('src/runtime/control-plane/facade/goal-workloop.ts', 'ENGINEERING_BLOCKER_LINKED_WORK_REQUIRED');
865
+ for (const path of [...sourceFiles('src'), ...sourceFiles('adapters')]) {
866
+ forbid(path, /operation:\s*['"](?:plan_approve|plan_accept_step|plan_supersede)['"]/, 'retired Plan approval/acceptance/supersession operations must not be advertised or suggested');
867
+ }
868
+ forbid(
869
+ 'src/runtime/control-plane/facade/rh-work-operation-contract.ts',
870
+ /plan_approve|plan_accept_step|plan_supersede/,
871
+ 'retired Plan lifecycle operations must not remain accepted rh_work ABI operations',
872
+ );
873
+ for (const path of [
874
+ 'src/runtime/control-plane/facade/goal-workloop.ts',
875
+ 'src/runtime/control-plane/facade/goal-workloop-access.ts',
876
+ 'src/cli/local-bridge/facade-api.ts',
877
+ 'src/cli/local-bridge/server.ts',
878
+ ]) {
879
+ forbid(path, /force_mode|forceMode/, 'retired mode-override tokens must not return as caller-visible input');
880
+ }
881
+ requireText('src/runtime/plugins/capability-authorization-grants.ts', 'migrateLegacyPluginCapabilityGrants');
882
+ requireText('src/runtime/plugins/capability-authorization-grants.ts', 'findActiveCanonicalGrant');
883
+ requireText('src/runtime/plugins/capability-authorization-grants.ts', 'legacyPluginGrantMigrationMarkerPath');
884
+ forbid(
885
+ 'src/runtime/plugins/capability-authorization-grants.ts',
886
+ /saveStore\(|writeJsonAtomic\(\s*pluginCapabilityAuthorizationGrantStorePath|writeFileSync/,
887
+ 'the legacy plugin capability authorization file is migration input only; the canonical Grant authority is the single writer',
888
+ );
889
+ for (const path of [
890
+ ...sourceFiles('src/runtime/control-plane'),
891
+ ...sourceFiles('adapters/mcp'),
892
+ ]) {
893
+ forbid(path, /directEditWithinBoundary|DirectEditBoundary/, 'task-size authorization shortcuts must not be reintroduced');
894
+ }
254
895
  requireText('src/runtime/control-plane/execution/work-verification-service.ts', 'runPersistedCheckViaProcessRuntime({');
255
896
  requireText('src/runtime/control-plane/execution/work-verification-service.ts', 'interactiveWaitMs: input.interactiveWaitMs ?? 0');
256
897
  requireText('src/runtime/control-plane/execution/work-verification-service.ts', 'checkContentRevision');
257
898
  requireText('src/runtime/control-plane/execution/work-verification-service.ts', 'observedGitHead');
258
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', 'executeWorkVerification({');
899
+ forbid('adapters/mcp/runtime-gateway/work-adapter.ts', /executeWorkVerification|recordWorkCheckEvidence/, 'rh_work must not execute or attribute repository checks');
259
900
  requireText('src/cli/local-bridge/facade-api.ts', 'executeWorkVerification({');
260
901
  forbid(
261
902
  'src/cli/local-bridge/facade-api.ts',
@@ -263,7 +904,7 @@ forbid(
263
904
  'Local Bridge Work verification must use the canonical persisted Work verification service',
264
905
  );
265
906
  forbid(
266
- 'src/runtime/gateway/mcp/runtime-tools.ts',
907
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
267
908
  /function\s+classifyTerminalCheckEvidence\s*\(/,
268
909
  'terminal Check evidence classification belongs to Process Runtime, not the Gateway transport',
269
910
  );
@@ -272,20 +913,83 @@ forbid(
272
913
  /runControllerCheck\s*\(/,
273
914
  'route Work verification through persisted Process Runtime instead of synchronous check execution',
274
915
  );
275
- for (const adapter of [
276
- 'src/cli/controller/work-mode.ts',
277
- 'src/runtime/control-plane/facade/types.ts',
916
+
917
+
918
+ // Thin Work authority: semantic state is open/completed/cancelled. Review and
919
+ // verification may exist as evidence/capabilities, never as generic Work/Git
920
+ // admission authority. The old delivery/finalizer modules are intentionally gone.
921
+ requireText('packages/kernel/work/domain/types.ts', "export const SEMANTIC_WORK_STATES = ['open', 'completed', 'cancelled'] as const;");
922
+ requireText('packages/kernel/work/domain/types.ts', 'export type SemanticWorkState = (typeof SEMANTIC_WORK_STATES)[number];');
923
+ requireText('packages/kernel/work/api/index.ts', "export * from '../application/work-service'");
924
+ requireText('src/cli/repositories/selected-path-actions.ts', 'beforeCommitGuard');
925
+ requireMissing('src/runtime/control-plane/execution/direct-edit-work-completion.ts');
926
+ requireMissing('src/runtime/control-plane/execution/content-equivalent-commit-authority.ts');
927
+ requireMissing('src/runtime/control-plane/execution/work-finalization-service.ts');
928
+ forbid('adapters/mcp/runtime-gateway/work-adapter.ts', /ImplementationReview|executeWorkVerification|work_finalize/, 'rh_work must not regain review, verification, or finalization behavior authority');
929
+ forbid('src/cli/repositories/selected-path-actions.ts', /ImplementationReview|workRequiresImplementationReview|requestWorkImplementationReview/, 'repository Git safety must not depend on Work review methodology');
930
+
931
+ // The model-facing rh_work surface is the thin semantic ABI: the schema enum must
932
+ // come from the single operation registry, that registry's model list must not
933
+ // re-advertise legacy engineering lifecycle verbs, and the schema must not
934
+ // hand-write lifecycle-only inputs. Legacy verbs stay reachable only through the
935
+ // bounded server-side compatibility carrier, never as advertised model surface.
936
+ requireText('adapters/mcp/runtime-gateway/runtime-tool-definitions.ts', '[...RH_WORK_MODEL_OPERATIONS]');
937
+ forbid(
938
+ 'adapters/mcp/runtime-gateway/runtime-tool-definitions.ts',
939
+ /review_decision|implementation_review_findings|review_rationale|requiredPlanStepId/,
940
+ 'the model-facing rh_work schema must not hand-write legacy lifecycle review inputs',
941
+ );
942
+ const rhWorkOperationContract = text('src/runtime/control-plane/facade/rh-work-operation-contract.ts');
943
+ const rhWorkModelOperations = (rhWorkOperationContract.match(/RH_WORK_MODEL_OPERATIONS = \[([\s\S]*?)\] as const/) ?? [])[1] ?? '';
944
+ if (!rhWorkModelOperations.trim()) {
945
+ failures.push('rh_work operation contract must define RH_WORK_MODEL_OPERATIONS as the thin model-facing ABI');
946
+ }
947
+ for (const legacyModelVerb of [
948
+ 'continue', 'verify', 'review', 'finalize', 'stop', 'delegate',
949
+ 'controller_claim', 'controller_release', 'controller_disposition', 'controller_get_owner',
278
950
  ]) {
279
- requireText(adapter, '@deprecated Compatibility adapter');
280
- requireText(adapter, 'decideRoute(');
281
- forbid(adapter, /expectedFiles\s*>|expectedChangedLines\s*>|KIND_RANK|providerOrder\s*\(/, 'delegate all routing thresholds and provider selection to Route Policy');
951
+ if (new RegExp(`['"]${legacyModelVerb}['"]`).test(rhWorkModelOperations)) {
952
+ failures.push(`RH_WORK_MODEL_OPERATIONS must not re-advertise the legacy engineering lifecycle verb: ${legacyModelVerb}`);
953
+ }
282
954
  }
283
- let routeAuthorityCount = 0;
955
+ requireText('packages/kernel/controller/infrastructure/controller-round-store.ts', 'readControllerRoundContextSnapshot');
956
+ const controllerRoundTransitionPolicyPath = 'packages/kernel/controller/domain/controller-round-transition-policy.ts';
957
+ if (existsSync(resolve(root, controllerRoundTransitionPolicyPath))) {
958
+ requireText(controllerRoundTransitionPolicyPath, "case 'provider_dispatch_outcome_unknown'");
959
+ requireText(controllerRoundTransitionPolicyPath, "blockedReason: 'provider_dispatch_outcome_unknown'");
960
+ forbid(
961
+ 'packages/kernel/controller/infrastructure/controller-round-store.ts',
962
+ /blockedReason\s*(?:===|:)\s*['"]provider_dispatch_outcome_unknown['"]/,
963
+ 'ControllerRound outcome-unknown lifecycle semantics must be owned by the canonical transition policy, not the store',
964
+ );
965
+ } else {
966
+ requireText('packages/kernel/controller/infrastructure/controller-round-store.ts', "blockedReason === 'provider_dispatch_outcome_unknown'");
967
+ requireText('packages/kernel/controller/infrastructure/controller-round-store.ts', "blockedReason: 'provider_dispatch_outcome_unknown'");
968
+ }
969
+ requireText('src/runtime/control-plane/launcher/chatgpt-work-continuation.ts', 'CHATGPT_AUTOMATION_SUBMISSION_OUTCOME_UNKNOWN');
970
+ requireMissing('adapters/chatgpt/controller-host.ts');
971
+ requireText('packages/kernel/controller/application/continuation-service.ts', 'const outcomeUnknown =');
972
+ requireText('packages/kernel/controller/application/continuation-service.ts', 'outcomeUnknown });');
973
+ requireText('adapters/chatgpt/controller-round-host.ts', 'buildChatgptControllerRoundPrompt');
974
+ requireText('adapters/chatgpt/controller-round-settlement-store.ts', 'recordChatgptControllerRoundSettlement');
975
+ forbid('packages/kernel/controller/infrastructure/controller-round-store.ts', /browserSessionId|conversationUrl|recordControllerRoundTabSettlement|buildControllerRoundRelayPrompt|capability_id=/, 'Kernel ControllerRound must remain provider/transport neutral; ChatGPT/MCP rendering and settlement belong to adapters');
976
+ forbid(
977
+ 'src/runtime/control-plane/global-scheduler/maintenance.ts',
978
+ /beginControllerRoundProviderDispatch|runWorkChatgptContinuation|createChatgptControllerHost/,
979
+ 'Scheduler maintenance must never become a Work-bound ChatGPT provider writer',
980
+ );
981
+ forbid(
982
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
983
+ /function\s+(?:assert|evaluate|derive)[A-Za-z0-9_]*ImplementationReview/,
984
+ 'Gateway transport must not implement implementation-review policy authority',
985
+ );
986
+ requireMissing('src/runtime/control-plane/execution/work-finalization-service.ts');
987
+ requireMissing('src/cli/controller/work-mode.ts');
988
+ forbid('src/runtime/control-plane/facade/types.ts', /repeated_infrastructure_failure|codex_worker_requires_review/, 'Handoff compatibility types may represent only genuine human blockers');
284
989
  for (const path of sourceFiles('src')) {
285
- routeAuthorityCount += (text(path).match(/export function decideRoute\s*\(/g) ?? []).length;
990
+ forbid(path, /export function decideRoute\s*\(/, 'Route Policy was deleted; Forge must not regain an execution-strategy router');
286
991
  forbid(path, /requirePlanForGoalWorkloop\s*:\s*true/, 'never restore mandatory Plan gating in production');
287
992
  }
288
- if (routeAuthorityCount !== 1) failures.push(`exactly one decideRoute authority is required; found ${routeAuthorityCount}`);
289
993
  forbid(
290
994
  'src/runtime/control-plane/facade/goal-workloop.ts',
291
995
  /function\s+(?:evaluateWorkCompletionEvidence|evaluateWorkImplementationEvidence|verificationRecordAppliesToCurrentWorkspace)\s*\(/,
@@ -293,14 +997,175 @@ forbid(
293
997
  );
294
998
  requireText('src/runtime/control-plane/facade/goal-workloop.ts', "from '../execution/work-evidence-policy'");
295
999
  for (const path of sourceFiles('src/runtime/control-plane')) {
296
- if (path === 'src/runtime/control-plane/facade/work-contract-store.ts' || path === 'src/runtime/control-plane/execution/work-completion-authority.ts') continue;
1000
+ if (path === 'src/runtime/control-plane/execution/work-completion-authority.ts') continue;
297
1001
  forbid(
298
1002
  path,
299
1003
  /\brecordWorkCompletionReceipt\s*\(/,
300
1004
  'route Work completion through the canonical work-completion-authority instead of writing terminal receipts directly',
301
1005
  );
302
1006
  }
303
- requireText('src/runtime/control-plane/execution/work-finalization-service.ts', 'completeWorkWithReceipt(');
1007
+ // B2 ownership fence: production code may consume only the Kernel Work API/domain,
1008
+ // never the retired facade store/state-machine or Kernel persistence implementation.
1009
+ for (const path of sourceFiles('src')) {
1010
+ forbid(path, /(?:from\s+['"]|import\s*\(\s*['"])[^'"]*(?:work-contract-store|work-implementation-review)['"]/, 'production source must consume packages/kernel/work instead of retired Work facade authority');
1011
+ forbid(path, /packages\/kernel\/work\/infrastructure\/work-contract-store/, 'production source must consume the Work application/API boundary, not persistence infrastructure');
1012
+ }
1013
+ for (const record of genericWorkLifecycleMutationRecords([...sourceFiles('src'), ...sourceFiles('adapters')])) {
1014
+ failures.push(`${record.path}:${record.line} violates Work lifecycle authority: updateWorkContract patch owns ${record.fields.join(', ')}; use explicit Kernel lifecycle commands`);
1015
+ }
1016
+ forbid(
1017
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
1018
+ /control-plane\/facade\/work-contract-store|kernel\/work\/infrastructure/,
1019
+ 'MCP Gateway must not mutate Work through facade/persistence authority',
1020
+ );
1021
+ forbid(
1022
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
1023
+ /\b(?:appendWorkEvidence|recordWorkCompletionReceipt)\s*\(/,
1024
+ 'MCP Gateway must submit Work application commands instead of writing lifecycle/evidence records directly',
1025
+ );
1026
+ requireText('src/runtime/control-plane/facade/goal-workloop.ts', 'packages/kernel/work/api/index');
1027
+ requireText('packages/kernel/work/domain/types.ts', 'predecessorWorkId?: string');
1028
+ forbid('src/runtime/control-plane/facade/goal-workloop.ts', /PLAN_(?:STEP_|SUCCESSOR_|NOT_EXECUTABLE|EXECUTION_BASELINE)/, 'Work admission must not consult Plan item status, binding, dependency or approval state');
1029
+ requireText('src/runtime/control-plane/facade/goal-workloop.ts', "requestedBy ?? 'chatgpt') === 'scheduler'");
1030
+ // V2 Goal authority convergence: lifecycle enums are canonical Kernel Goal
1031
+ // domain facts and explicit Controller goal_complete is the Requirement semantic
1032
+ // acceptance boundary. PlanStep progression is retired: Plan items are authored
1033
+ // working memory that never selects, gates or progresses Work.
1034
+ requireText('packages/kernel/goal/domain/types.ts', 'export const REQUIREMENT_STATES');
1035
+ requireText('packages/kernel/goal/domain/types.ts', 'export const PLAN_CONTRACT_STATUSES');
1036
+ requireText('packages/kernel/goal/domain/types.ts', 'export const PLAN_STEP_STATUSES');
1037
+ requireText('src/runtime/control-plane/persistence/requirement-store.ts', 'packages/kernel/goal/api/index');
1038
+ requireText('src/runtime/control-plane/facade/types.ts', 'packages/kernel/goal/api/index');
1039
+ requireText('src/runtime/control-plane/persistence/requirement-store.ts', 'reviseRequirementSemantic');
1040
+ requireText('src/runtime/control-plane/facade/plan-contract-store.ts', 'revisePlanSemanticContext');
1041
+ requireText('docs/architecture/decisions/20260924-thin-semantic-working-context.md', 'only three cross-domain model-authored semantic records');
1042
+ requireText('docs/architecture/decisions/20260924-thin-semantic-working-context.md', 'semantic revision must be applied to the latest persisted aggregate inside the same storage transaction');
1043
+ forbid('src/runtime/control-plane/facade/requirement-authority.ts', /continueRequirement|acceptRequirementOutcome|completeRequirementGoal|requirement_semantic_acceptance|requirement_semantic_continue/, 'Requirement semantic state changes must use revisioned requirement_revise CAS only');
1044
+ requireText('src/runtime/control-plane/facade/plan-contract-store.ts', 'PLAN_REQUIREMENT_TERMINAL');
1045
+ forbid('adapters/mcp/runtime-gateway/work-controller-operations.ts', /completeRequirementGoal|requirementAcceptance/, 'Controller disposition must not complete or accept Requirement semantics');
1046
+ forbid('adapters/mcp/runtime-gateway/runtime-tools.ts', /\bacceptRequirementOutcome\s*\(/, 'MCP transport must never own Requirement semantic completion');
1047
+ forbid('src/runtime/control-plane/facade/rh-work-operation-contract.ts', /requirement_continue/, 'retired Requirement lifecycle compatibility operation must not remain accepted');
1048
+ requireText('adapters/mcp/tool-mapping/post-finalize-work-attribution.ts', 'semanticWorkState(work)');
1049
+ forbid('adapters/mcp/tool-mapping/post-finalize-work-attribution.ts', /isTerminalWorkContractStatus|lifecycleClosed|work\.status\s*!==?\s*['"]completed['"]/, 'post-completion readonly attribution must follow semantic Work state, not legacy lifecycle projections');
1050
+ forbid('adapters/mcp/runtime-gateway/work-controller-operations.ts', /goal_complete[^\n]{0,200}requirementId|requirementId[^\n]{0,200}goal_complete/, 'Controller goal_complete may settle continuation but must not own Requirement completion');
1051
+ // B3 ControllerSession authority and provider-neutral host boundary.
1052
+ requireText('packages/kernel/controller/domain/types.ts', 'export interface ControllerBinding');
1053
+ requireText('packages/kernel/controller/domain/types.ts', 'export interface ControllerLease');
1054
+ requireText('packages/kernel/controller/ports/controller-host.ts', 'export interface ControllerHost');
1055
+ requireText('packages/kernel/controller/ports/controller-host.ts', 'resume(binding: ControllerBinding, roundContext: ControllerRoundContext)');
1056
+ requireText('packages/kernel/controller/infrastructure/controller-session-store.ts', 'claimControllerSession');
1057
+ requireText('packages/kernel/controller/infrastructure/controller-session-store.ts', 'releaseControllerSessionWithAuthority');
1058
+ requireText('src/runtime/control-plane/facade/controller-session-store.ts', '@deprecated Kernel V2 compatibility shim');
1059
+ forbid('packages/kernel/controller/index.ts', /infrastructure\//, 'Kernel module root must expose only its public API');
1060
+ forbid('packages/kernel/controller/application/controller-service.ts', /export\s+\*\s+from\s+['"]\.\.\/infrastructure\//, 'Controller application façade must not wildcard-export infrastructure');
1061
+ // B4 Scheduler continuation authority: Schedule owns occurrence state only;
1062
+ // continuation resolves exact Work + retained ControllerSession + opaque ControllerBinding
1063
+ // and dispatches exclusively through ControllerHost.resume.
1064
+ requireText('packages/kernel/scheduler/domain/schedule.ts', 'export interface RepositorySchedule');
1065
+ requireText('packages/kernel/scheduler/domain/schedule.ts', 'export interface ScheduleOccurrence');
1066
+ requireText('packages/kernel/scheduler/infrastructure/schedule-store.ts', "'occurrences'");
1067
+ requireText('packages/kernel/scheduler/infrastructure/schedule-store.ts', 'saveScheduleDecision');
1068
+ requireText('packages/kernel/scheduler/application/schedule-service.ts', 'createSchedule');
1069
+ requireText('packages/kernel/scheduler/api/index.ts', "../application/schedule-service");
1070
+ forbid('packages/kernel/scheduler/api/index.ts', /\.\.\/infrastructure\//, 'Scheduler public API must expose application/domain surfaces, not infrastructure stores');
1071
+ requireText('packages/kernel/scheduler/application/eligibility.ts', 'evaluateScheduleTriggerEligibility');
1072
+ requireText('packages/kernel/scheduler/application/eligibility.ts', 'evaluateScheduleOccurrenceAdmission');
1073
+ requireText('packages/kernel/scheduler/application/eligibility.ts', 'scheduleTriggerWindowKey');
1074
+ requireText('packages/kernel/scheduler/application/settlement.ts', 'applyScheduleFailure');
1075
+ requireText('packages/kernel/scheduler/application/settlement.ts', 'applyScheduleRetryableFailure');
1076
+ requireText('packages/kernel/scheduler/application/settlement.ts', 'settleScheduledExecution');
1077
+ requireText('src/runtime/workflow/schedules/settlement.ts', '@deprecated Kernel V2 compatibility shim');
1078
+ requireMissing('packages/kernel/scheduler/domain/continuation.ts');
1079
+ requireMissing('packages/kernel/scheduler/application/continuation-service.ts');
1080
+ requireMissing('packages/kernel/scheduler/infrastructure/continuation-dispatch-store.ts');
1081
+ requireText('packages/kernel/controller/application/continuation-service.ts', 'resumeControllerRoundOccurrence');
1082
+ requireText('packages/kernel/controller/application/continuation-service.ts', 'getRetainedControllerSession');
1083
+ requireText('packages/kernel/controller/application/continuation-service.ts', 'getControllerWorkBinding');
1084
+ requireText('packages/kernel/controller/application/continuation-service.ts', 'beginControllerRoundProviderDispatch');
1085
+ requireText('packages/kernel/controller/application/continuation-service.ts', 'host.resume(bindingRecord.binding');
1086
+ requireText('packages/kernel/controller/infrastructure/controller-round-store.ts', 'controller-provider-dispatch-start');
1087
+ requireText('packages/kernel/controller/domain/controller-round-transition-policy.ts', "type: 'provider_dispatch_started'");
1088
+ forbid('packages/kernel/controller/application/continuation-service.ts', /scheduler_continuation_dispatch|ScheduledContinuationDispatch/, 'Controller continuation must not recreate Scheduler-owned continuation lifecycle persistence');
1089
+ requireText('src/runtime/root/controller-progression-composition.ts', 'reconcileControllerProgression');
1090
+ requireText('src/runtime/root/controller-progression-composition.ts', 'ensureWorkflowSupervisorEnrollmentForWork');
1091
+ requireText('src/runtime/control-plane/global-scheduler/autonomous-continuation.ts', 'reconcileControllerProgression');
1092
+ requireText('src/runtime/workflow/schedules/engine.ts', 'reconcileControllerProgression');
1093
+ requireText('adapters/mcp/runtime-gateway/work-controller-operations.ts', 'reconcileControllerProgression');
1094
+ forbid(
1095
+ 'src/runtime/control-plane/launcher/chatgpt-round-continuation.ts',
1096
+ /beginControllerRoundProviderDispatch|runWorkChatgptContinuation|openChatgptControllerRoundFromSource|continueChatgptControllerRoundFromSource/,
1097
+ 'current-source compatibility may close an already-open legacy round but must never send or open a new Work-bound ChatGPT turn',
1098
+ );
1099
+ forbid(
1100
+ 'src/runtime/control-plane/launcher/chatgpt-work-continuation.ts',
1101
+ /runWorkChatgptContinuation|prepareWorkChatgptContinuationTransport/,
1102
+ 'Work-bound ChatGPT provider delivery is Workflow Supervisor-owned; this module may expose only standalone prompt and Browser settlement primitives',
1103
+ );
1104
+ requireText('src/runtime/root/scheduled-controller-composition.ts', 'CHATGPT_CONTROLLER_HOST_SUPERVISOR_OWNED');
1105
+ requireText('src/runtime/control-plane/launcher/thin-launcher.ts', 'LAUNCHER_CHATGPT_SUPERVISOR_OWNED');
1106
+ requireMissing('adapters/scheduler/controller-binding.ts');
1107
+ requireText('adapters/controller-process/controller-host.ts', 'createProcessControllerHost');
1108
+ requireText('src/runtime/workflow/schedules/engine.ts', 'workflow_supervisor_owns_outer_turn');
1109
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'registerWorkflowSupervisorTask');
1110
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'reserveWorkflowSupervisorEnrollment');
1111
+ requireText('supervisor/entry.ts', 'forgeWorkflowSupervisorValidators()');
1112
+ forbid('supervisor/client.ts', /reserveWorkflowSupervisorSchedulerRecovery|reserve_scheduler_recovery/, 'Scheduler recovery is not a Supervisor RPC; reconciliation stays on the canonical effect ledger');
1113
+ forbid('supervisor/control-plane.ts', /reserveSchedulerRecovery/, 'Scheduler recovery must not regrow as a second Supervisor recovery authority');
1114
+ forbid('supervisor/server.ts', /reserve_scheduler_recovery/, 'Supervisor RPC surface must not expose retired Scheduler recovery authority');
1115
+ requireText('supervisor/forge-validators.ts', "requirement.state !== 'done'");
1116
+ requireText('supervisor/forge-validators.ts', "requirement.state === 'waiting_for_user'");
1117
+ forbid('src/runtime/root/workflow-supervisor-composition.ts', /WorkflowSupervisorStore|supervisor\.sqlite|registerTask\(|reserveEffect\(/, 'Forge composition must access Supervisor state only through daemon RPC, never open its database or become a second writer');
1118
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'workflowSupervisorBoundaryForWork');
1119
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', '`forge:${repoId}:work:${workId}`');
1120
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'registeredTask.taskId');
1121
+ forbid('src/runtime/root/workflow-supervisor-composition.ts', /forge:\$\{repoId\}:conversation:\$\{conversationId\}/, 'Supervisor task identity must remain conversation-stable through registration, not be recomputed from the current Work conversation');
1122
+ forbid('supervisor/client.ts', /task_has_effect|taskHasAnyEffect/, 'Supervisor boundary is derived from canonical Work+conversation facts; do not add a second ownership projection RPC');
1123
+ requireText('src/runtime/workflow/schedules/engine.ts', 'evaluateScheduleTriggerEligibility');
1124
+ requireText('src/runtime/workflow/schedules/engine.ts', 'evaluateScheduleOccurrenceAdmission');
1125
+ requireText('src/runtime/workflow/schedules/engine.ts', 'controller_session_id');
1126
+ requireText('src/runtime/workflow/schedules/engine.ts', 'controller_binding_id');
1127
+ requireText('src/runtime/workflow/schedules/store.ts', '@deprecated Kernel V2 compatibility shim');
1128
+ requireText('src/runtime/workflow/schedules/store.ts', 'packages/kernel/scheduler/api/index');
1129
+ forbid('src/runtime/workflow/schedules/store.ts', /scheduler\/infrastructure\//, 'legacy Schedule shim must route through the Kernel Scheduler public API');
1130
+ requireText('src/runtime/workflow/schedules/types.ts', '@deprecated Kernel V2 compatibility shim');
1131
+ for (const path of sourceFiles('packages/kernel/scheduler')) {
1132
+ forbid(path, /(?:from\s+['"]|import\s*\(\s*['"])[^'"]*adapters\//, 'Kernel Scheduler must not import provider adapters');
1133
+ forbid(path, /\b(?:runWorkChatgptContinuation|launchSuperController|getChatgptWorkConversationBinding)\b|\bbrowser_session_id\b|\bconversation_url\b|\blaunch_args\b/, 'Kernel Scheduler must not own provider transport or provider binding payload fields');
1134
+ }
1135
+ forbid('src/runtime/workflow/schedules/engine.ts', /\brunWorkChatgptContinuation\b|\blaunchSuperController\b/, 'Schedule execution must dispatch Controller continuation through Kernel Scheduler + ControllerHost, never launch providers directly');
1136
+ for (const path of sourceFiles('src')) {
1137
+ forbid(path, /(?:from\s+['"]|import\s*\(\s*['"])[^'"]*workflow\/schedules\/(?:store|types|settlement)['"]/, 'production source must consume packages/kernel/scheduler instead of retired Schedule store/types/settlement authority');
1138
+ }
1139
+ for (const path of sourceFiles('src')) {
1140
+ forbid(path, /(?:from\s+['"]|import\s*\(\s*['"])[^'"]*controller-session-store['"]/, 'production source must consume packages/kernel/controller instead of retired ControllerSession facade authority');
1141
+ }
1142
+ const B7_KERNEL_INTERNAL_COMPATIBILITY_SHIMS = new Set([
1143
+ 'src/runtime/control-plane/facade/controller-session-store.ts',
1144
+ 'src/runtime/control-plane/facade/work-contract-store.ts',
1145
+ 'src/runtime/control-plane/facade/types.ts',
1146
+ 'src/runtime/workflow/schedules/settlement.ts',
1147
+ 'src/runtime/workflow/schedules/types.ts',
1148
+ ]);
1149
+ // The compatibility-shim ledger may only shrink. A shim with no remaining
1150
+ // importer at all is migration debt, not a boundary: delete the file and its
1151
+ // entry in the same slice instead of keeping an unused authority surface alive.
1152
+ // Shims that survive only because a test still imports them are bounded debt to
1153
+ // be removed together with that test, never a reason to keep production authority.
1154
+ const shimImportRecords = staticTypeScriptImportRecords([...productionTypeScriptFiles(), ...sourceFiles('tests')]);
1155
+ for (const shim of B7_KERNEL_INTERNAL_COMPATIBILITY_SHIMS) {
1156
+ const shimBasename = shim.slice(shim.lastIndexOf('/') + 1).replace(/\.ts$/, '');
1157
+ const importedBy = shimImportRecords.filter((record) => record.from !== shim
1158
+ && (record.specifier === `./${shimBasename}` || record.specifier.endsWith(`/${shimBasename}`)));
1159
+ if (importedBy.length === 0) {
1160
+ failures.push(`${shim} is a dead compatibility shim with no importer; delete it and remove its compatibility-shim entry`);
1161
+ }
1162
+ }
1163
+ for (const path of sourceFiles('src')) {
1164
+ if (B7_KERNEL_INTERNAL_COMPATIBILITY_SHIMS.has(path)) continue;
1165
+ forbid(path, /packages\/kernel\/[^'"/]+\/(?:domain|application|infrastructure)\//, 'active legacy Runtime code must consume Kernel public api/index surfaces; direct internals are compatibility-boundary-only');
1166
+ }
1167
+ requireText('src/runtime/control-plane/facade/types.ts', 'packages/kernel/work/domain/types');
1168
+ requireText('src/runtime/control-plane/facade/types.ts', 'packages/kernel/controller/domain/types');
304
1169
  forbid(
305
1170
  'src/runtime/plugins/browser-handoff-host.ts',
306
1171
  /browser\/sessions|saveBrowserSession|writeBrowserSession|sessionPath/,
@@ -313,25 +1178,29 @@ forbid(
313
1178
  );
314
1179
  requireText('src/runtime/plugins/browser-runtime.ts', 'browserActionCanReplayAfterDispatch');
315
1180
  forbid(
316
- 'src/runtime/gateway/mcp/runtime-tools.ts',
1181
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
317
1182
  /\b(?:createRequirement|resumeRetainedCancelledWorkContract)\s*\(/,
318
1183
  'keep Requirement admission and retained-cancelled Work lifecycle authority out of the MCP transport',
319
1184
  );
320
1185
  forbid(
321
- 'src/runtime/gateway/mcp/runtime-tools.ts',
1186
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
322
1187
  /\b(?:updateWorkContract|writeWorkHandle)\s*\(/,
323
1188
  'keep WorkContract/WorkHandle persistence policy out of the MCP transport',
324
1189
  );
325
1190
  forbid(
326
- 'src/runtime/gateway/mcp/execution-tools.ts',
1191
+ 'adapters/mcp/runtime-gateway/execution-tools.ts',
327
1192
  /\bcreateWorkContract\s*\(/,
328
1193
  'route compatibility work preparation through canonical Work admission authority',
329
1194
  );
330
1195
  forbid(
331
- 'src/cli/mcp/legacy-tool-service.ts',
1196
+ 'adapters/mcp/tool-mapping/legacy-tool-service.ts',
332
1197
  /\bcreateWorkContract\s*\(/,
333
1198
  'keep the legacy MCP surface as translation over canonical Work admission authority',
334
1199
  );
1200
+ requireMissing('src/runtime/control-plane/routing/workspace-admission.ts');
1201
+ forbid('packages/kernel/work/domain/types.ts', /requireHandoffOnAmbiguity|requireWorktree|directMainProhibited/, 'retired Work placement/handoff policy fields must not return as durable authority');
1202
+ forbid('adapters/mcp/runtime-gateway/work-adapter.ts', /require_handoff_on_ambiguity|require_worktree|direct_main_prohibited/, 'retired placement/handoff wire flags must not drive repository topology');
1203
+ forbid('src/cli/controller/execution-policy.ts', /requiresHumanAcceptance|autoRunDeclaredChecks|autoCompleteAfterSuccessfulRun|requiresScopedPaths|requiresDiffEvidence|requiresAnyVerificationEvidence|requiresAcceptanceEvidence|READ_ONLY_INTENT|DESTRUCTIVE_INTENT|SENSITIVE_PATH_PATTERNS/, 'task risk/text/path classification must not decide workflow, placement, verification, scope, or acceptance authority');
335
1204
  requireMissing('src/runtime/control-plane/daemon-entry.ts');
336
1205
  requireMissing('scripts/smoke-runtime-control-plane.ts');
337
1206
  requireMissing('src/cli/controller/lifecycle.ts');
@@ -356,6 +1225,55 @@ requireMissing('src/runtime/bootstrap/runtime-authority.ts');
356
1225
  requireMissing('src/runtime/bootstrap/activation-transaction.ts');
357
1226
  requireMissing('src/runtime/bootstrap/stable-bootstrap.ts');
358
1227
  requireMissing('src/runtime/supervisor');
1228
+ requireText('supervisor/store.ts', 'BEGIN IMMEDIATE');
1229
+ requireText('supervisor/store.ts', 'completions_one_per_source_effect');
1230
+ requireText('supervisor/store.ts', 'WORKFLOW_SUPERVISOR_SOURCE_EFFECT_COMPLETION_CONFLICT');
1231
+ requireText('supervisor/paths.ts', 'resolveControllerHome');
1232
+ requireText('supervisor/paths.ts', "join(resolveWorkflowSupervisorForgeHome(controllerHome), 'supervisor')");
1233
+ forbid('supervisor/paths.ts', /control-plane\/persistence\/sqlite-store|workflow-run-store|packages\/kernel\/(?:work|controller)/, 'Workflow Supervisor path authority may share the canonical Controller Home root but must not depend on lower lifecycle persistence or Kernel authorities');
1234
+ forbid('supervisor/store.ts', /resolveControllerHome|FORGE_CONTROLLER_HOME|control-plane\/persistence\/sqlite-store|workflow-run-store|packages\/kernel\/(?:work|controller)/, 'Workflow Supervisor persistence must resolve its root only through supervisor/paths and remain a separate database authority');
1235
+ requireMissing('supervisor/service.ts');
1236
+ requireText('src/runtime/root/runtime.ts', 'startWorkflowSupervisorRuntime');
1237
+ requireText('src/runtime/root/runtime.ts', 'WORKFLOW_SUPERVISOR_STOPPED');
1238
+ requireText('src/runtime/root/workflow-supervisor-runtime.ts', 'startWorkflowSupervisorRuntime(controllerHome: string)');
1239
+ requireText('src/runtime/root/workflow-supervisor-runtime.ts', 'new WorkflowSupervisorStore(forgeHome, {');
1240
+ requireText('src/runtime/root/workflow-supervisor-runtime.ts', 'activeReleaseId: () => getRuntimeWriteClaim()?.releaseId');
1241
+ requireText('src/runtime/root/workflow-supervisor-runtime.ts', 'createWorkflowSupervisorServer');
1242
+ requireText('src/runtime/root/workflow-supervisor-runtime.ts', 'startWorkflowSupervisorNativeBrowserAdapter');
1243
+ requireText('supervisor/native-browser-adapter.ts', 'targetPort: ComputerChatgptConversationTargetPort;');
1244
+ forbid('supervisor/native-browser-adapter.ts', /MacOs|AppleEvents|browser-macos-bridge|\bwindowId\b|\btabId\b|window\.name/, 'Workflow Supervisor browser consumer must depend only on the provider-neutral Computer ChatGPT target port');
1245
+ forbid('supervisor/native-browser-adapter.ts', /supervisor\/store|sqlite|scheduler|packages\/kernel\/(?:work|controller)|control-plane\/persistence/, 'Native Supervisor browser adapter is transport-only and must not own durable lifecycle, Scheduler, Work, Controller, or persistence authority');
1246
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'resolveWorkflowSupervisorForgeHome(options.controllerHome)');
1247
+ forbid('src/runtime/root/workflow-supervisor-runtime.ts', /createPlatformServiceManagerHost|launchd|systemd|startDetached/, 'Workflow Supervisor reuses the Canonical Runtime process lifecycle and must not own a second OS service');
1248
+ requireText('supervisor/entry.ts', "argument('--controller-home')");
1249
+ forbid('supervisor/entry.ts', /FORGE_HOME|--forge-home/, 'Workflow Supervisor foreground entry must use the canonical Controller Home authority rather than a second Forge-home root');
1250
+ requireText('supervisor/control-plane.ts', 'await validator(task, parsed.proposal)');
1251
+ requireText('supervisor/protocol.ts', 'SUPERVISOR_BLOCK_END');
1252
+ requireText('supervisor/server.ts', 'createWorkflowSupervisorServer');
1253
+ forbid('supervisor/server.ts', /from ['"]\.\/store['"]|supervisor\.sqlite|BEGIN IMMEDIATE/, 'Supervisor transport must relay typed commands through the control plane and never own persistence');
1254
+ requireText('adapters/computer/chrome-extension/manifest.json', 'nativeMessaging');
1255
+ requireText('adapters/computer/chrome-extension/background.js', 'computer_extension_claim');
1256
+ requireText('adapters/computer/chrome-extension/background.js', 'computer_extension_complete');
1257
+ requireText('adapters/computer/chrome-extension/background.js', 'chrome.runtime.connectNative');
1258
+ forbid('adapters/computer/chrome-extension/background.js', /browser_begin_effect|browser_observe_effect|browser_poll|browser_tasks|browser_observe_assistant|task_register|reserve_enrollment/, 'Computer Chrome provider must not consume or mutate Workflow Supervisor effect authority; it executes only typed Computer target commands');
1259
+ requireText('adapters/computer/chrome-extension/content.js', 'ForgeComputerChatgptCore');
1260
+ requireMissing('supervisor/chrome-extension');
1261
+ requireText('src/runtime/plugins/browser-adapter.ts', "browserMode: browserMode(raw.browserMode) ?? 'managed_persistent'");
1262
+ requireText('src/runtime/plugins/browser-adapter.ts', "nativeAttachMode: browserNativeAttachMode(raw.nativeAttachMode) ?? 'disabled'");
1263
+ requireText('supervisor/native-messaging/host.ts', 'ALLOWED_BROWSER_METHODS');
1264
+ requireText('supervisor/native-messaging/host.ts', 'computer_extension_claim');
1265
+ forbid('supervisor/native-messaging/host.ts', /['"](?:browser_tasks|browser_poll|browser_begin_effect|browser_observe_effect|browser_observe_dispatch_failure|browser_observe_provider_turn|browser_observe_assistant|bootstrap_poll|bootstrap_project_url|bootstrap_begin_effect|bootstrap_observe_effect|bootstrap_bind_conversation)['"]/, 'Chrome Native Messaging transport must not expose Workflow Supervisor effect RPCs; extension traffic terminates at Computer target commands');
1266
+ requireText('supervisor/store.ts', 'recordEffectNotAppliedProof');
1267
+ requireText('supervisor/store.ts', '`effect-dispatch:${effectId}:${generation}`');
1268
+ requireText('supervisor/control-plane.ts', 'PERSISTED_BROWSER_EVIDENCE_KEYS');
1269
+ requireText('supervisor/control-plane.ts', "reason: 'not_applied_proof_incomplete'");
1270
+ requireText('supervisor/server.ts', "if (!['applied','unknown'].includes(outcome))");
1271
+ forbid('adapters/computer/chrome-extension/background.js', /chrome\.storage|supervisor\.sqlite|BEGIN IMMEDIATE/, 'Computer Chrome provider must reconstruct provider bindings from live inventory and Computer target authority rather than browser shadow persistence');
1272
+ forbid('adapters/computer/chrome-extension/content.js', /chrome\.storage|supervisor\.sqlite|BEGIN IMMEDIATE/, 'Computer Chrome content script must remain a page capability surface rather than durable authority');
1273
+ forbid('supervisor/native-messaging/host.ts', /task_register|reserve_enrollment|supervisor\.sqlite|BEGIN IMMEDIATE|bun:sqlite|node:sqlite|from ['"][^'"]*(?:store|control-plane)['"]/, 'Chrome Native Messaging host must remain a stateless browser-method relay and never own Supervisor persistence/lifecycle');
1274
+ forbid('adapters/computer/chrome-extension/background.js', /task_register|reserve_enrollment|supervisor\.sqlite|BEGIN IMMEDIATE|chrome\.storage/, 'Computer Chrome provider must never become durable workflow authority');
1275
+ forbid('adapters/computer/chrome-extension/content.js', /task_register|reserve_enrollment|supervisor\.sqlite|BEGIN IMMEDIATE|chrome\.storage/, 'Computer Chrome content script must observe/execute one exact page only and never own durable workflow state');
1276
+
359
1277
  requireMissing('docs/architecture/current/stable-external-runtime-supervisor.md');
360
1278
  requireMissing('docs/architecture/modules/controller-runtime/stable-supervisor.md');
361
1279
  requireMissing('docs/operations/stable-external-runtime-supervisor.md');
@@ -368,10 +1286,10 @@ requireMissing('docs/architecture/transactional-adoption-planner.md');
368
1286
  requireMissing('docs/architecture/global-hook-runtime.md');
369
1287
  requireMissing('docs/architecture/ios-semantic-automation-provider-v2.md');
370
1288
  requireMissing('docs/architecture/chatgpt-handoff-facade.md');
371
- requireText('docs/architecture/history/global-hook-runtime.md', 'Status: **Historical Evidence — Not Runtime Authority**');
372
- requireText('docs/architecture/history/ios-semantic-automation-provider-v2.md', 'Status: **Historical Design Evidence — Not Runtime Authority**');
373
- requireText('docs/architecture/history/chatgpt-handoff-facade.md', 'Status: **Historical Design Rationale — Not Runtime Authority**');
374
- requireText('docs/architecture/history/README.md', 'Status: **Historical Evidence — Not Runtime Authority**');
1289
+ requireMissing('docs/architecture/history/global-hook-runtime.md');
1290
+ requireMissing('docs/architecture/history/ios-semantic-automation-provider-v2.md');
1291
+ requireMissing('docs/architecture/history/chatgpt-handoff-facade.md');
1292
+ requireMissing('docs/architecture/history/README.md');
375
1293
  requireMissing('docs/operations/20260802-requirement-portfolio-migration.md');
376
1294
  requireMissing('docs/runbooks/RELIABILITY-SESSION-PROTOCOL.md');
377
1295
  requireMissing('docs/architecture/decisions/20260718-mcp-session-lifecycle-and-ingress-isolation.md');
@@ -535,7 +1453,7 @@ forbid(
535
1453
  requireText('scripts/smoke-schedule-engine.ts', 'listHandoffItems');
536
1454
  requireText('scripts/smoke-schedule-engine.ts', 'listExecutionJobs');
537
1455
  requireText('scripts/smoke-schedule-engine.ts', "operation: 'runtime_maintenance_apply'");
538
- const server = text('src/cli/mcp/server.ts');
1456
+ const server = text('adapters/mcp/server.ts');
539
1457
  const runtimeCall = server.indexOf('callRuntimeTool(ctx, name, args)');
540
1458
  const durableCall = server.indexOf('routeDurableMcpCall(ctx, name, args)');
541
1459
  const legacyCall = server.indexOf('callMultiRepositoryTool(ctx, name, args)');
@@ -556,28 +1474,26 @@ if (executionRegion.includes('forceDurable: true') && executionRegion.includes('
556
1474
  failures.push('Public MCP Work mutations must not force the retired durable ExecutionJob path');
557
1475
  }
558
1476
  forbid(
559
- 'src/runtime/gateway/mcp/router.ts',
1477
+ 'adapters/mcp/runtime-gateway/router.ts',
560
1478
  /\bcreateExecutionJob\b|\bgetExecutionJob\b/,
561
1479
  'Gateway Router must not retain dormant ExecutionJob creation or lookup paths',
562
1480
  );
563
- requireText('src/runtime/gateway/mcp/router.ts', 'executionJobCreationRetired');
564
- requireText('src/runtime/gateway/mcp/router.ts', "'EXECUTION_JOB_RETIRED'");
565
- requireText('src/runtime/gateway/mcp/execution-tools.ts', 'isDurableWorkOperation');
566
- requireText('src/runtime/gateway/mcp/execution-tools.ts', "'work_execute'");
567
- requireText('src/runtime/gateway/mcp/execution-tools.ts', "'work_validate'");
568
- requireText('src/runtime/gateway/mcp/execution-tools.ts', "'work_finalize'");
1481
+ requireText('adapters/mcp/runtime-gateway/router.ts', 'executionJobCreationRetired');
1482
+ requireText('adapters/mcp/runtime-gateway/router.ts', "'EXECUTION_JOB_RETIRED'");
1483
+ requireText('adapters/mcp/runtime-gateway/execution-tools.ts', 'isDurableWorkOperation');
1484
+ requireText('adapters/mcp/runtime-gateway/execution-tools.ts', "'work_execute'");
1485
+ requireText('adapters/mcp/runtime-gateway/execution-tools.ts', "'work_validate'");
1486
+ forbid('adapters/mcp/runtime-gateway/execution-tools.ts', /work_finalize/, 'execution tools must not restore a Work finalization operation');
569
1487
  requireText('src/runtime/execution/workers/executor.ts', 'executeWork(runtimeContext');
570
1488
  requireText('src/runtime/execution/workers/executor.ts', 'validateWork(runtimeContext');
571
- requireText('src/runtime/execution/workers/executor.ts', 'finalizeWork(runtimeContext');
572
1489
  forbid(
573
1490
  'src/runtime/execution/workers/executor.ts',
574
1491
  /gateway\/mcp\/execution-tools|callExecutionTool\s*\(/,
575
1492
  'Execution Worker must invoke control-plane Work application services directly, never MCP transport',
576
1493
  );
577
1494
  requireText('src/runtime/execution/workers/executor.ts', '__from_durable_worker');
578
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', 'managedProcessOperationDigest');
579
1495
  forbid(
580
- 'src/runtime/gateway/mcp/runtime-tools.ts',
1496
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
581
1497
  /\bcreateExecutionJob\b/,
582
1498
  'Runtime MCP tools must not retain dormant ExecutionJob creation paths',
583
1499
  );
@@ -592,12 +1508,12 @@ forbid(
592
1508
  'Local Bridge HTTP creation routes must return retirement handoffs without dormant Job submission or dispatch code',
593
1509
  );
594
1510
  forbid(
595
- 'src/cli/mcp/repository-tools.ts',
1511
+ 'adapters/mcp/tool-mapping/repository-tools.ts',
596
1512
  /\bsubmitLocalBridgeJob\b|\bexecuteLocalBridgeJob\b|\bwaitForRepositoryCommandHandoff\b/,
597
1513
  'Repository command MCP fallback must use Process Runtime or an external-Controller handoff, never Local Bridge Jobs',
598
1514
  );
599
1515
  forbid(
600
- 'src/cli/mcp/legacy-tool-service.ts',
1516
+ 'adapters/mcp/tool-mapping/legacy-tool-service.ts',
601
1517
  /\bsubmitLocalBridgeJob\b|\bexecuteLocalBridgeJob\b|\bacceptTaskJob\b|\bdispatchAcceptedTaskJob\b|\bstartTaskJob\b|\blegacy_agent_run\b/,
602
1518
  'Legacy MCP compatibility may read or cancel historical Jobs and Runs but must not create or dispatch new ones',
603
1519
  );
@@ -638,24 +1554,23 @@ forbid(
638
1554
  'Local Bridge HTTP must not call Agent Run create/start/retry write boundaries',
639
1555
  );
640
1556
  forbid(
641
- 'src/cli/mcp/legacy-tool-service.ts',
1557
+ 'adapters/mcp/tool-mapping/legacy-tool-service.ts',
642
1558
  /\bretryAgentJob\b/,
643
1559
  'Legacy MCP must not call Agent Run retry',
644
1560
  );
645
- forbid('src/runtime/gateway/mcp/router.ts', /Use process_get \/ process_wait \/ process_logs/, 'Gateway follow-up instructions must use an always-exposed neutral Work facade');
1561
+ forbid('adapters/mcp/runtime-gateway/router.ts', /Use process_get \/ process_wait \/ process_logs/, 'Gateway follow-up instructions must use an always-exposed neutral Work facade');
646
1562
  requireMatch(
647
- 'src/runtime/gateway/mcp/router.ts',
1563
+ 'adapters/mcp/runtime-gateway/routing-policy.ts',
648
1564
  /const DIRECT_REPOSITORY_TOOLS = new Set\(\[[\s\S]*?'repository_list'[\s\S]*?'repository_get'[\s\S]*?'repository_workbench'[\s\S]*?\]\);/,
649
1565
  'declare DIRECT_REPOSITORY_TOOLS with repository_list, repository_get, and repository_workbench',
650
1566
  );
651
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', "case 'controller_context'");
652
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', "case 'local_bridge_status'");
653
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', 'readAgentExecutableReadinessSnapshot');
654
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', 'connectorExposedTools');
655
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', 'currentCallableTools');
656
- forbid('src/runtime/gateway/mcp/runtime-tools.ts', /inspectAgentExecutableReadiness|resolveAgentExecutable|writeAgentExecutableReadinessSnapshot/, 'Gateway readiness must only read the Daemon-produced Agent executable snapshot');
1567
+ requireText('adapters/mcp/runtime-gateway/runtime-observation-adapter.ts', "case 'controller_context'");
1568
+ requireText('adapters/mcp/runtime-gateway/runtime-observation-adapter.ts', "case 'local_bridge_status'");
1569
+ requireText('adapters/mcp/runtime-gateway/runtime-tools.ts', 'connectorExposedTools');
1570
+ requireText('adapters/mcp/runtime-gateway/runtime-tools.ts', 'currentCallableTools');
1571
+ forbid('adapters/mcp/runtime-gateway/runtime-observation-adapter.ts', /inspectAgentExecutableReadiness|resolveAgentExecutable|writeAgentExecutableReadinessSnapshot/, 'Runtime observation adapter must not perform Agent executable discovery or mutate readiness snapshots');
657
1572
  forbidBetween(
658
- 'src/runtime/gateway/mcp/runtime-tools.ts',
1573
+ 'adapters/mcp/runtime-gateway/runtime-observation-adapter.ts',
659
1574
  "case 'repository_runtime_snapshot':",
660
1575
  "case 'runtime_performance_diagnostics':",
661
1576
  /rebuildRepositoryProjection\s*\(/,
@@ -669,9 +1584,9 @@ forbid(
669
1584
  );
670
1585
  requireText('src/runtime/projections/controller-context.ts', 'controllerContextProjectionPayloadMatchesSourceIdentity');
671
1586
  requireText('src/runtime/projections/controller-context.ts', 'sourceIdentityMatches');
672
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', 'CONTEXT_PROJECTION_SOURCE_MISMATCH');
673
- forbid('src/runtime/gateway/mcp/router.ts', /const DIRECT_HOT_READ_TOOLS = new Set\([\s\S]*?['"]controller_context['"][\s\S]*?\);/, 'controller_context must use a materialized projection or Durable Job, never the legacy Gateway path');
674
- forbid('src/runtime/gateway/mcp/router.ts', /const DIRECT_HOT_READ_TOOLS = new Set\([\s\S]*?['"](?:local_bridge_status|get_local_job|get_local_job_output)['"][\s\S]*?\);/, 'Local Bridge observations must use bounded snapshots, never reconciliation in the Gateway');
1587
+ requireText('adapters/mcp/runtime-gateway/runtime-observation-adapter.ts', 'CONTEXT_PROJECTION_SOURCE_MISMATCH');
1588
+ forbid('adapters/mcp/runtime-gateway/router.ts', /const DIRECT_HOT_READ_TOOLS = new Set\([\s\S]*?['"]controller_context['"][\s\S]*?\);/, 'controller_context must use a materialized projection or Durable Job, never the legacy Gateway path');
1589
+ forbid('adapters/mcp/runtime-gateway/router.ts', /const DIRECT_HOT_READ_TOOLS = new Set\([\s\S]*?['"](?:local_bridge_status|get_local_job|get_local_job_output)['"][\s\S]*?\);/, 'Local Bridge observations must use bounded snapshots, never reconciliation in the Gateway');
675
1590
  requireText('src/runtime/execution/jobs/types.ts', 'requestId: string');
676
1591
  requireText('src/runtime/execution/jobs/types.ts', 'semanticKey: string');
677
1592
  requireText('src/runtime/execution/jobs/types.ts', 'admissionTimeoutMs: number');
@@ -683,7 +1598,7 @@ requireText('src/runtime/control-plane/facade/operation-digest.ts', 'operationId
683
1598
  requireText('src/runtime/control-plane/facade/operation-digest.ts', 'resultRef');
684
1599
  requireText('src/runtime/control-plane/facade/operation-digest.ts', 'nextActions');
685
1600
  requireText('src/runtime/control-plane/facade/operation-digest.ts', 'admissionTimeoutMs');
686
- forbid('src/runtime/gateway/mcp/router.ts', /Math\.min\(\s*typeof args\.timeout_ms[\s\S]{0,140}?,\s*120_000\s*\)/, 'Agent parent timeout must never silently truncate timeout_ms to 120 seconds');
1601
+ forbid('adapters/mcp/runtime-gateway/router.ts', /Math\.min\(\s*typeof args\.timeout_ms[\s\S]{0,140}?,\s*120_000\s*\)/, 'Agent parent timeout must never silently truncate timeout_ms to 120 seconds');
687
1602
  requireText('src/runtime/execution/jobs/store.ts', "'active.json'");
688
1603
  requireText('src/runtime/execution/jobs/store.ts', "'recent.json'");
689
1604
  requireText('src/runtime/execution/jobs/store.ts', "'requests'");
@@ -754,13 +1669,13 @@ forbidBetween(
754
1669
  /rebuildRepositoryProjection\s*\(/,
755
1670
  'Projection rebuild must happen outside the Repo Actor mailbox lock',
756
1671
  );
757
- requireText('src/runtime/workflow/schedules/store.ts', "'occurrences.json'");
1672
+ requireText('packages/kernel/scheduler/infrastructure/schedule-store.ts', "'occurrences'");
758
1673
  requireText('src/runtime/projections/git-status-sampler.ts', 'writeRepositoryGitStatusSample');
759
1674
  requireText('src/runtime/projections/git-status-sampler.ts', 'readRepositoryGitStatusSample');
760
- requireText('src/cli/mcp/repository-tools.ts', 'readRepositoryGitStatusSample');
761
- requireText('src/cli/mcp/repository-tools.ts', 'args.refresh === true');
1675
+ requireText('adapters/mcp/tool-mapping/repository-tools.ts', 'readRepositoryGitStatusSample');
1676
+ requireText('adapters/mcp/tool-mapping/repository-tools.ts', 'args.refresh === true');
762
1677
  forbidBetween(
763
- 'src/cli/mcp/repository-tools.ts',
1678
+ 'adapters/mcp/tool-mapping/repository-tools.ts',
764
1679
  "case 'repository_git_status':",
765
1680
  "case 'repository_git_diff':",
766
1681
  /repositoryGitStatus\s*\(/,
@@ -769,83 +1684,684 @@ forbidBetween(
769
1684
  requireText('src/runtime/control-plane/execution/session-store.ts', 'lastValidatedAt: now');
770
1685
  requireText('src/runtime/control-plane/execution/validation.ts', 'warnings.push');
771
1686
  requireText('src/runtime/control-plane/execution/work-handle-store.ts', "failed: ['validating', 'editing', 'committed', 'merged', 'cleaned', 'failed_terminal_cleanup']");
772
- requireText('src/runtime/gateway/mcp/execution-tools.ts', "from '../../control-plane/execution/work-finalization-service'");
773
- requireText('src/runtime/gateway/mcp/execution-tools.ts', "from '../../control-plane/execution/work-preparation-service'");
774
- requireText('src/runtime/gateway/mcp/execution-tools.ts', "from '../../control-plane/execution/work-operation-service'");
775
- requireText('src/runtime/gateway/mcp/execution-tools.ts', 'Compatibility exports: implementation authority lives in control-plane execution.');
776
- requireText('src/runtime/gateway/mcp/execution-tools.ts', 'resetFinalizationStagesForRequest,');
777
- requireText('src/runtime/gateway/mcp/execution-tools.ts', 'selectDefaultWorkValidationChecks');
778
- requireText('src/runtime/gateway/mcp/runtime-tools.ts', "callExecutionTool(ctx, 'work_finalize'");
1687
+ requireText('adapters/mcp/runtime-gateway/execution-tools.ts', "from '../../../src/runtime/control-plane/execution/work-preparation-service'");
1688
+ requireText('adapters/mcp/runtime-gateway/execution-tools.ts', "from '../../../src/runtime/control-plane/execution/work-operation-service'");
1689
+ requireText('adapters/mcp/runtime-gateway/execution-tools.ts', 'selectDefaultWorkValidationChecks');
779
1690
  forbid(
780
- 'src/runtime/gateway/mcp/runtime-tools.ts',
1691
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
781
1692
  /repositoryGit(?:Commit|FinishWorkflow|MergeBranch|DeleteBranch|RebaseOnto)\s*\(/,
782
1693
  'rh_work facade finalization must delegate to the canonical Work finalization application service instead of performing Git delivery itself',
783
1694
  );
784
1695
  forbid(
785
- 'src/runtime/gateway/mcp/execution-tools.ts',
1696
+ 'adapters/mcp/runtime-gateway/execution-tools.ts',
786
1697
  /function\s+finalizeWork\s*\(/,
787
1698
  'MCP execution transport must delegate Work finalization to the control-plane application service',
788
1699
  );
789
1700
  forbid(
790
- 'src/runtime/gateway/mcp/execution-tools.ts',
791
- /function\s+(?:prepareWork|adoptExistingWorkHead)\s*\(/,
792
- 'MCP execution transport must delegate Work preparation/adoption to the control-plane application service',
1701
+ 'adapters/mcp/runtime-gateway/execution-tools.ts',
1702
+ /function\s+prepareWork\s*\(/,
1703
+ 'MCP execution transport must delegate Work preparation to the control-plane application service',
793
1704
  );
794
1705
  forbid(
795
- 'src/runtime/gateway/mcp/execution-tools.ts',
1706
+ 'adapters/mcp/runtime-gateway/execution-tools.ts',
796
1707
  /function\s+(?:executeWork|validateWork)\s*\(/,
797
1708
  'MCP execution transport must delegate Work execute/validate operations to the control-plane application service',
798
1709
  );
799
1710
  forbid(
800
- 'src/runtime/gateway/mcp/execution-tools.ts',
1711
+ 'adapters/mcp/runtime-gateway/execution-tools.ts',
801
1712
  /(?:ensureManagedWorkspace|admitPreparedRepositoryWorkContract)\s*\(/,
802
1713
  'MCP execution transport must not own managed-workspace or WorkContract preparation admission',
803
1714
  );
804
1715
  requireText('src/runtime/control-plane/execution/work-preparation-service.ts', 'export function prepareWork(');
805
- requireText('src/runtime/control-plane/execution/work-preparation-service.ts', 'function adoptExistingWorkHead(');
1716
+ requireText('src/runtime/control-plane/execution/work-preparation-service.ts', "const useWorktree = isolation !== 'reuse';");
1717
+ forbid(
1718
+ 'src/runtime/control-plane/execution/work-preparation-service.ts',
1719
+ /adoptExistingWorkHead|WORK_HEAD_ADOPTION_/,
1720
+ 'Work preparation must keep the start revision frozen; changed source HEADs are never adopted during implementation',
1721
+ );
1722
+ forbid(
1723
+ 'src/runtime/control-plane/execution/work-handle-authority.ts',
1724
+ /alignRepositoryMutationBase|WORK_DIRECT_PRE_MUTATION_RECONCILIATION_/,
1725
+ 'Repository mutation authority must not advance a Work baseline to follow target-branch movement',
1726
+ );
1727
+ requireMissing('src/runtime/control-plane/execution/direct-canonical-work-reconciliation.ts');
806
1728
  requireText('src/runtime/control-plane/execution/work-operation-service.ts', 'export async function executeWork(');
807
1729
  requireText('src/runtime/control-plane/execution/work-operation-service.ts', 'export async function validateWork(');
808
- requireText('src/runtime/control-plane/execution/work-finalization-service.ts', 'resetFinalizationStagesForRequest');
809
- requireText('src/runtime/control-plane/execution/work-finalization-service.ts', 'finalizationComplete');
810
- forbidBetween(
811
- 'src/runtime/control-plane/execution/work-finalization-service.ts',
812
- 'export async function finalizeWork(',
813
- '// WORK_FINALIZATION_SERVICE_END',
814
- /withControllerLock\([\s\S]{0,900}?(?:repositoryGitCommit|repositoryGitFinishWorkflow|runCleanup|repositoryGitDeleteBranch)/,
815
- 'Work finalization must not hold the controller lock while committing, merging, deleting branches, or removing worktrees',
816
- );
817
- requireText('src/runtime/workflow/schedules/types.ts', "'repository-event'");
818
- requireText('src/runtime/workflow/schedules/types.ts', "'dependency-checkpoint'");
819
- requireText('src/runtime/workflow/schedules/store.ts', 'saveScheduleDecision');
820
- requireText('src/runtime/workflow/schedules/settlement.ts', 'backoffMinutes');
1730
+ requireMissing('src/runtime/control-plane/execution/work-finalization-service.ts');
1731
+ requireText('packages/kernel/scheduler/domain/schedule.ts', "'repository-event'");
1732
+ requireText('packages/kernel/scheduler/domain/schedule.ts', "'dependency-checkpoint'");
1733
+ requireText('packages/kernel/scheduler/infrastructure/schedule-store.ts', 'saveScheduleDecision');
1734
+ requireText('packages/kernel/scheduler/application/settlement.ts', 'backoffMinutes');
821
1735
  requireText('src/runtime/release/release-gate.ts', 'releaseReady');
822
- requireText('src/cli/mcp/transports/http.ts', "'/ready'");
823
- requireText('src/cli/mcp/transports/http.ts', "'/repos/:repoId/health'");
1736
+ requireText('adapters/mcp/transports/http-observation.ts', "'/ready'");
1737
+ requireText('adapters/mcp/transports/http-observation.ts', "'/repos/:repoId/health'");
824
1738
  requireText('src/runtime/control-plane/governance/external-effects.ts', 'EXTERNAL_EFFECT_AUTHORIZATION_REQUIRED');
825
1739
  requireText('src/runtime/control-plane/governance/external-effects.ts', 'AUTOMATED_REQUIREMENT_REQUIRES_CANDIDATE');
826
- requireText('src/cli/mcp/tools.ts', "export * from './legacy-tool-service'");
1740
+ requireText('adapters/mcp/tool-mapping/tools.ts', "export * from './legacy-tool-service'");
1741
+ requireText('src/cli/mcp/tools.ts', '@deprecated Kernel V2 compatibility shim');
827
1742
 
828
1743
  for (const path of [
829
- 'src/runtime/gateway/mcp/router.ts',
830
- 'src/runtime/gateway/mcp/runtime-tools.ts',
1744
+ 'adapters/mcp/runtime-gateway/router.ts',
1745
+ 'adapters/mcp/runtime-gateway/runtime-tools.ts',
1746
+ 'adapters/mcp/runtime-gateway/work-adapter.ts',
831
1747
  'src/runtime/control-plane/global-scheduler/scheduler.ts',
832
1748
  'src/runtime/control-plane/repo-actor/actor.ts',
833
1749
  'src/runtime/workflow/schedules/engine.ts',
834
1750
  'src/runtime/workflow/schedules/work-continuation.ts',
835
- 'src/cli/mcp/transports/http.ts',
1751
+ 'adapters/mcp/transports/http.ts',
836
1752
  ]) {
837
1753
  forbid(path, /\b(?:spawnSync|execSync|execFileSync)\s*\(/, 'the non-blocking Gateway/Controller hot-path rule');
838
1754
  }
839
1755
 
840
1756
  requireText('scripts/run-governed-gate.ts', "label: 'source duplication'");
841
1757
  requireText('scripts/run-governed-gate.ts', "args: ['scripts/check-source-duplication.mjs']");
842
- requireText('scripts/run-governed-gate.ts', "label: 'controller UI bundle'");
843
- requireText('scripts/run-governed-gate.ts', "args: ['run', 'check:controller-ui']");
844
1758
  requireText('docs/architecture/CURRENT.md', '## State ownership');
845
1759
  requireText('docs/architecture/CURRENT.md', '## Runtime and MCP boundary');
846
1760
  requireText('docs/architecture/CURRENT.md', '## Testing and verification');
847
1761
  requireText('plans/README.md', 'not the runtime execution queue');
848
- if (text('src/cli/mcp/tools.ts').split(/\r?\n/).length > 40) failures.push('src/cli/mcp/tools.ts must remain a thin compatibility facade');
1762
+ // Compatibility-facade thinness is enforced by ownership/consumer boundaries, not source line counts.
1763
+ const b7ProductionFiles = productionTypeScriptFiles();
1764
+ const b7ProductionImports = staticTypeScriptImportRecords(b7ProductionFiles);
1765
+ const b7ProductionGraph = staticTypeScriptDependencyGraph(b7ProductionFiles);
1766
+ for (const { from, specifier } of b7ProductionImports) {
1767
+ if (from.startsWith('packages/kernel/') && specifier.startsWith('@modelcontextprotocol/')) {
1768
+ failures.push(`Kernel modules must remain independent of MCP SDK transport contracts: ${from} -> ${specifier}`);
1769
+ }
1770
+ if (from.startsWith('packages/kernel/')
1771
+ && ['adapters/mcp', 'src/cli/mcp', 'runtime/gateway/mcp'].some((segment) => specifier.includes(segment))) {
1772
+ failures.push(`Kernel modules must never depend on MCP adapters or retired MCP gateway paths: ${from} -> ${specifier}`);
1773
+ }
1774
+ if (from.startsWith('packages/plugin-runtime/')
1775
+ && ['adapters/', 'src/runtime/'].some((segment) => specifier.includes(segment))) {
1776
+ failures.push(`Plugin Runtime provider dispatch must not depend on concrete adapters or Runtime implementations: ${from} -> ${specifier}`);
1777
+ }
1778
+ if (from.startsWith('adapters/computer/') && specifier.includes('src/runtime/')) {
1779
+ failures.push(`Computer adapters must consume provider-neutral ports and contracts rather than depend on Runtime implementations: ${from} -> ${specifier}`);
1780
+ }
1781
+ if (from.startsWith('packages/plugin-runtime/computer/')
1782
+ && (['controller-home', 'external-registration'].some((segment) => specifier.includes(segment))
1783
+ || ['node:fs', 'fs', 'node:path', 'path'].includes(specifier))) {
1784
+ failures.push(`Computer provider runtime must remain independent of Controller Home and filesystem-backed provider discovery: ${from} -> ${specifier}`);
1785
+ }
1786
+ if (from !== 'src/runtime/plugins/macos-capability-broker.ts' && specifier.includes('macos-capability-broker')) {
1787
+ failures.push(`Deprecated macOS capability broker is compatibility/test-only and must have no production consumers: ${from} -> ${specifier}`);
1788
+ }
1789
+ }
1790
+ for (const edge of dependencyEdges(b7ProductionGraph)) {
1791
+ const { from, to } = edgeParts(edge);
1792
+ if (from.startsWith('packages/kernel/') && to.startsWith('packages/kernel/')) {
1793
+ const fromModule = architectureRoot(from);
1794
+ const toModule = architectureRoot(to);
1795
+ if (fromModule !== toModule && !to.startsWith(`${toModule}/api/`) && to !== `${toModule}/index.ts`) {
1796
+ failures.push(`Kernel sibling modules must use public API boundaries: ${edge}`);
1797
+ }
1798
+ }
1799
+ if (from.startsWith('adapters/') && to.startsWith('adapters/') && architectureRoot(from) !== architectureRoot(to)) {
1800
+ failures.push(`adapter sibling wiring belongs in a composition root, not another adapter: ${edge}`);
1801
+ }
1802
+ if (from.startsWith('adapters/') && to.startsWith('packages/kernel/')) {
1803
+ const kernelModule = architectureRoot(to);
1804
+ if (!to.startsWith(`${kernelModule}/api/`) && to !== `${kernelModule}/index.ts`) {
1805
+ failures.push(`adapters must consume Kernel public APIs, not internal implementation: ${edge}`);
1806
+ }
1807
+ }
1808
+ if (from.startsWith('packages/kernel/')
1809
+ && (to.startsWith('adapters/mcp/') || to.startsWith('src/cli/mcp/') || to.startsWith('src/runtime/gateway/mcp/'))) {
1810
+ failures.push(`Kernel modules must never depend on MCP adapters or retired MCP gateway paths: ${edge}`);
1811
+ }
1812
+ if (/^packages\/kernel\/[^/]+\/(?:domain|application)\//.test(from) && to.startsWith('src/')) {
1813
+ failures.push(`Kernel domain/application must depend only on Kernel/protocol ports, never legacy src mechanisms: ${edge}`);
1814
+ }
1815
+ if (from.startsWith('packages/plugin-runtime/') && (to.startsWith('adapters/') || to.startsWith('src/runtime/'))) {
1816
+ failures.push(`Plugin Runtime provider dispatch must not depend on concrete adapters or Runtime implementations: ${edge}`);
1817
+ }
1818
+ if (from.startsWith('packages/plugin-runtime/computer/')
1819
+ && (to.includes('/controller-home') || to.endsWith('/external-registration.ts'))) {
1820
+ failures.push(`Computer provider runtime must remain independent of Controller Home and provider discovery implementations: ${edge}`);
1821
+ }
1822
+ if (to === 'src/runtime/plugins/macos-capability-broker.ts' && from !== to) {
1823
+ failures.push(`Deprecated macOS capability broker is compatibility/test-only and must have no production consumers: ${edge}`);
1824
+ }
1825
+ }
1826
+ for (const compositionPath of [
1827
+ 'src/runtime/root/scheduled-controller-composition.ts',
1828
+ 'src/runtime/root/controller-round-composition.ts',
1829
+ ]) requireText(compositionPath, 'Kernel V2 composition root');
1830
+
1831
+ // Exact legacy edges are frozen below after a read-only graph inventory; new debt is never accepted.
1832
+ // The V2 baseline lineage is immutable; this gate must not require rebasing onto unrelated main work.
1833
+ const b7KernelLegacyEdges = edgeSet(b7ProductionGraph, (edge) => {
1834
+ const { from, to } = edgeParts(edge);
1835
+ return from.startsWith('packages/kernel/') && to.startsWith('src/');
1836
+ });
1837
+ const B7_ALLOWED_KERNEL_LEGACY_EDGES = new Set([
1838
+ 'packages/kernel/work/infrastructure/work-contract-store.ts -> src/cli/repositories/controller-home.ts',
1839
+ 'packages/kernel/work/infrastructure/work-contract-store.ts -> src/cli/repositories/locks.ts',
1840
+ 'packages/kernel/work/infrastructure/work-contract-store.ts -> src/runtime/shared/json-files.ts',
1841
+ 'packages/kernel/work/infrastructure/work-contract-store.ts -> src/runtime/control-plane/persistence/sqlite-store.ts',
1842
+ 'packages/kernel/controller/infrastructure/controller-session-store.ts -> src/cli/repositories/controller-home.ts',
1843
+ 'packages/kernel/controller/infrastructure/controller-session-store.ts -> src/cli/repositories/locks.ts',
1844
+ 'packages/kernel/controller/infrastructure/controller-session-store.ts -> src/runtime/control-plane/execution/session-store.ts',
1845
+ 'packages/kernel/controller/infrastructure/controller-session-store.ts -> src/runtime/shared/json-files.ts',
1846
+ 'packages/kernel/controller/infrastructure/controller-session-store.ts -> src/runtime/control-plane/persistence/sqlite-store.ts',
1847
+ 'packages/kernel/controller/infrastructure/controller-round-store.ts -> src/cli/repositories/locks.ts',
1848
+ 'packages/kernel/controller/infrastructure/controller-round-store.ts -> src/runtime/control-plane/persistence/requirement-store.ts',
1849
+ 'packages/kernel/controller/infrastructure/controller-round-store.ts -> src/runtime/control-plane/persistence/sqlite-store.ts',
1850
+ 'packages/kernel/controller/infrastructure/controller-round-store.ts -> src/runtime/execution/work-activity.ts',
1851
+ 'packages/kernel/controller/infrastructure/controller-round-store.ts -> src/runtime/control-plane/facade/handoff-inbox-store.ts',
1852
+ 'packages/kernel/controller/infrastructure/controller-binding-store.ts -> src/cli/repositories/locks.ts',
1853
+ 'packages/kernel/controller/infrastructure/controller-binding-store.ts -> src/runtime/control-plane/persistence/sqlite-store.ts',
1854
+ 'packages/kernel/scheduler/infrastructure/schedule-store.ts -> src/cli/repositories/controller-home.ts',
1855
+ 'packages/kernel/scheduler/infrastructure/schedule-store.ts -> src/cli/repositories/locks.ts',
1856
+ 'packages/kernel/scheduler/infrastructure/schedule-store.ts -> src/runtime/control-plane/facade/handoff-inbox-store.ts',
1857
+ 'packages/kernel/scheduler/infrastructure/schedule-store.ts -> src/runtime/shared/json-files.ts',
1858
+ 'packages/kernel/scheduler/infrastructure/schedule-store.ts -> src/runtime/evidence/event-ledger.ts',
1859
+ ]);
1860
+ requireExactShrinkingDebt('Kernel -> legacy src dependency debt', b7KernelLegacyEdges, B7_ALLOWED_KERNEL_LEGACY_EDGES);
1861
+ const b7ProductionEdges = new Set(dependencyEdges(b7ProductionGraph));
1862
+ for (const requiredEdge of [
1863
+ 'packages/kernel/work/domain/types.ts -> packages/kernel/identity/api/index.ts',
1864
+ 'packages/kernel/scheduler/domain/schedule.ts -> packages/kernel/identity/api/index.ts',
1865
+ ]) {
1866
+ if (!b7ProductionEdges.has(requiredEdge)) failures.push(`Portable semantic identity contract must be consumed through the Kernel Identity boundary: ${requiredEdge}`);
1867
+ }
1868
+
1869
+ const b7LifecycleOwnerMarkers = new Map([
1870
+ ['WorkContract transition authority', ['packages/kernel/work/domain/state-machine.ts']],
1871
+ ['ControllerSession claim authority', ['packages/kernel/controller/infrastructure/controller-session-store.ts']],
1872
+ ['ControllerRound relay authority', ['packages/kernel/controller/infrastructure/controller-round-store.ts']],
1873
+ ['Schedule occurrence authority', ['packages/kernel/scheduler/infrastructure/schedule-store.ts']],
1874
+ ['Forge instance identity authority', ['packages/kernel/identity/infrastructure/identity-store.ts']],
1875
+ ]);
1876
+ for (const [label, owners] of b7LifecycleOwnerMarkers) {
1877
+ for (const owner of owners) text(owner);
1878
+ if (new Set(owners).size !== 1) failures.push(`${label} must have exactly one declared durable owner`);
1879
+ }
1880
+ const b7UniqueMutationSymbols = new Map([
1881
+ ['transitionWorkContractPhase', 'Work lifecycle mutation'],
1882
+ ['claimControllerSession', 'ControllerSession claim mutation'],
1883
+ ['beginInitialControllerRoundDispatch', 'ControllerRound dispatch mutation'],
1884
+ ['ensureForgeInstanceIdentity', 'Forge instance identity creation'],
1885
+ ]);
1886
+ for (const [symbol, label] of b7UniqueMutationSymbols) {
1887
+ let count = 0;
1888
+ for (const path of productionTypeScriptFiles()) {
1889
+ count += (text(path).match(new RegExp(`export\\s+(?:async\\s+)?function\\s+${symbol}\\s*\\(`, 'g')) ?? []).length;
1890
+ }
1891
+ if (count !== 1) failures.push(`${label} must have exactly one exported production owner; found ${count} for ${symbol}`);
1892
+ }
1893
+ // Thin Plan authority: Plan items are authored working memory. Work execution,
1894
+ // Plan admission and Plan revision must never re-acquire PlanStep execution
1895
+ // writers, Plan approval/acceptance gates or Plan-derived Work progression.
1896
+ const retiredPlanExecutionSymbols = [
1897
+ 'claimPlanStepForWork',
1898
+ 'completePlanStepForWork',
1899
+ 'acceptPlanStepEvidence',
1900
+ 'repairPlanStepForTechnicalRetry',
1901
+ 'repairDanglingPlanStepWorkBinding',
1902
+ 'replanActivePlanBoundWorkScope',
1903
+ 'retireTerminalPlanBoundWorkAuthorities',
1904
+ 'getPlanExecutionBaselineRevision',
1905
+ 'updatePlanContractWithExecutionBaseline',
1906
+ 'refreshPlanBoundWorkRevision',
1907
+ 'retirePlanBoundWorkContract',
1908
+ 'rebindPlanBoundWorkContract',
1909
+ ];
1910
+ for (const path of productionTypeScriptFiles()) {
1911
+ const source = text(path);
1912
+ for (const symbol of retiredPlanExecutionSymbols) {
1913
+ if (new RegExp(`\\b${symbol}\\b`).test(source)) failures.push(`${path} must not reintroduce retired PlanStep execution writer ${symbol}`);
1914
+ }
1915
+ }
1916
+ const retiredPlanGateCodes = /PLAN_STEP_(?:SEMANTIC_ACCEPTANCE_REQUIRED|TERMINAL_WORK_RECONCILIATION_REQUIRED|DEPENDENCIES_PENDING|ALREADY_ACTIVE|ALREADY_COMPLETED|MULTIPLE_PRIMARY_WORKS|BOUND_WORK_MISSING|REUSES_ACTIVE_WORK|WORK_CONTRACT_MISMATCH)|PLAN_NOT_EXECUTABLE|PLAN_EXECUTION_BASELINE_LOCKED|PLAN_OBLIGATION_CONTINUITY_REQUIRED|PLAN_STEP_SEMANTIC_ACCEPTANCE/;
1917
+ for (const path of [
1918
+ 'src/runtime/control-plane/facade/goal-workloop.ts',
1919
+ 'src/runtime/control-plane/facade/plan-contract-store.ts',
1920
+ 'src/runtime/control-plane/facade/requirement-authority.ts',
1921
+ 'src/runtime/control-plane/global-scheduler/autonomous-continuation.ts',
1922
+ 'adapters/mcp/runtime-gateway/work-plan-operations.ts',
1923
+ 'adapters/mcp/runtime-gateway/work-repair-adapter.ts',
1924
+ ]) {
1925
+ if (retiredPlanGateCodes.test(text(path))) failures.push(`${path} must not reintroduce a PlanStep execution gate`);
1926
+ }
1927
+ for (const path of ['packages/kernel/progression/api/index.ts']) requireMissing(path);
1928
+ for (const path of productionTypeScriptFiles()) {
1929
+ if (/packages\/kernel\/progression/.test(text(path))) failures.push(`${path} must not depend on the retired PlanStep progression engine`);
1930
+ }
1931
+ for (const retiredPath of [
1932
+ 'src/runtime/control-plane/execution/work-finalization-service.ts',
1933
+ 'src/runtime/control-plane/execution/direct-edit-work-completion.ts',
1934
+ 'src/runtime/control-plane/execution/content-equivalent-commit-authority.ts',
1935
+ 'adapters/mcp/controller-round-compatibility.ts',
1936
+ 'adapters/mcp/frozen-client-semantic-compatibility.ts',
1937
+ 'adapters/mcp/runtime-gateway/work-controller-recovery-operations.ts',
1938
+ 'adapters/mcp/runtime-gateway/work-plan-repair-operations.ts',
1939
+ ]) requireMissing(retiredPath);
1940
+ for (const path of [...sourceFiles('src'), ...sourceFiles('adapters')]) {
1941
+ forbid(path, /tool:\s*['"]rh_work['"][\s\S]{0,180}?operation:\s*['"](?:continue|verify|review|finalize|stop|plan_approve|plan_accept_step|controller_claim|controller_release|controller_disposition)['"]/, 'retired Work lifecycle operations must not return as current rh_work behavioral authority');
1942
+ }
1943
+ // Thin semantic Work lifecycle: Work is open/completed/cancelled and
1944
+ // work.complete is a mechanical durable close. Review findings are durable
1945
+ // observations, never a completion gate.
1946
+ requireText('packages/kernel/work/domain/types.ts', "export const SEMANTIC_WORK_STATES = ['open', 'completed', 'cancelled'] as const;");
1947
+ requireText('packages/kernel/work/domain/types.ts', 'export type SemanticWorkState = (typeof SEMANTIC_WORK_STATES)[number];');
1948
+ requireText('adapters/mcp/runtime-gateway/work-semantic-operations.ts', "const RH_WORK_SEMANTIC_OPERATIONS = new Set(['start', 'get', 'revise', 'complete']);");
1949
+ for (const path of [
1950
+ 'packages/kernel/work/domain/state-machine.ts',
1951
+ 'src/runtime/control-plane/execution/work-evidence-policy.ts',
1952
+ 'src/runtime/control-plane/facade/goal-workloop.ts',
1953
+ ]) {
1954
+ forbid(path, /READ_ONLY_REVIEW_CLEAN_SCOPE|cleanReadOnlyReviewEvidence|READ_ONLY_REVIEW_FINDINGS_BLOCK/, 'read-only review findings must not gate terminal completion');
1955
+ }
1956
+ // Work lifecycle collapse: semantic Work completion is one durable
1957
+ // expected_revision CAS close. Verify/review/finalize/delivery/cleanup are
1958
+ // mechanical facts owned elsewhere; they must never be wired back into the
1959
+ // semantic close path as a gate.
1960
+ for (const path of [
1961
+ 'adapters/mcp/runtime-gateway/work-semantic-operations.ts',
1962
+ ]) {
1963
+ forbid(path, /transitionWorkContractPhase|requestWorkImplementationReview|recordWorkImplementationReview|finalizeGoalWorkloop|verifyGoalWorkloop|reviewGoalWorkloop/, 'semantic Work completion must not invoke a mechanical lifecycle transition');
1964
+ forbid(path, /implementationReview|completionReceipt|dispatchState|evidenceState|ControllerRound|controllerRound/, 'semantic Work completion must not read mechanical lifecycle or controller authority');
1965
+ }
1966
+ forbidBetween(
1967
+ 'packages/kernel/work/infrastructure/work-contract-store.ts',
1968
+ 'export function reviseWorkSemanticContext(',
1969
+ 'export function getWorkContract(',
1970
+ /WORK_IMPLEMENTATION_REVIEW|WORK_COMPLETION_RECEIPT|WORK_VERIFICATION|WORK_CLEANUP|WORK_DELIVERY|WORK_FINALIZE/,
1971
+ 'the semantic close must not require review, verification, delivery, cleanup or finalize',
1972
+ );
1973
+ requireText('packages/kernel/work/infrastructure/work-contract-store.ts', 'WORK_REVISION_CONFLICT:');
1974
+ forbidBetween(
1975
+ 'packages/kernel/work/infrastructure/work-contract-store.ts',
1976
+ 'export function semanticWorkState(',
1977
+ 'export function workSemanticView(',
1978
+ /'failed'|'ready'|'blocked'|'running'/,
1979
+ 'semantic Work state must expose only open/completed/cancelled; execution vocabulary is not a semantic state',
1980
+ );
1981
+ // Controller de-authority: ordinary Work/capability execution is fenced by
1982
+ // semantic CAS plus concrete target/resource/effect owners, never by a
1983
+ // Work-wide ControllerSession lease. Explicit autonomous-continuation round
1984
+ // operations retain their narrow dispatch/effect authority until Slice 4.
1985
+ forbid(
1986
+ 'packages/kernel/work/domain/state-machine.ts',
1987
+ /WORK_PHASE_EVIDENCE_|WORK_COMPLETION_PHASE_/,
1988
+ 'legacy phase evidence must not regain semantic Work authority',
1989
+ );
1990
+ for (const path of [
1991
+ 'adapters/mcp/runtime-gateway/work-workflow-operations.ts',
1992
+ 'src/runtime/workflows/runtime.ts',
1993
+ ]) {
1994
+ forbid(path, /assertFacadeControllerRoundAuthority|getControllerSession|getControllerRoundRelay|controllerSessionAuthorityMatches|WORKFLOW_CONTROLLER_AUTHORITY|WORKFLOW_CONTROLLER_NOT_OWNER/, 'ordinary Workflow execution must not depend on Work-wide Controller authority');
1995
+ }
1996
+ forbid(
1997
+ 'adapters/mcp/runtime-gateway/work-adapter.ts',
1998
+ /claimNewFacadeWork|mintControllerSessionAuthority|resumeControllerSession|bindFacadeControllerOwnership|currentFacadeTerminalizationAuthority|currentTerminalCleanupAuthority|withControllerSessionTerminalizationFence/,
1999
+ 'ordinary Work start/continue/review/stop/finalize must not mint or require Work-wide Controller authority',
2000
+ );
2001
+ for (const path of [
2002
+ 'packages/kernel/work/domain/types.ts',
2003
+ 'packages/kernel/work/domain/execution-concurrency.ts',
2004
+ 'src/runtime/control-plane/concurrency/work-execution-concurrency.ts',
2005
+ 'src/runtime/execution/process-runtime/types.ts',
2006
+ ]) {
2007
+ forbid(path, /controller_release/, 'Work/Process concurrency must wake on concrete Work/resource/scheduler facts, not Controller ownership release');
2008
+ }
2009
+ for (const path of [
2010
+ 'src/runtime/control-plane/execution/work-execution-support.ts',
2011
+ 'src/runtime/control-plane/execution/work-operation-service.ts',
2012
+ 'src/runtime/control-plane/execution/work-terminal-cleanup.ts',
2013
+ 'src/runtime/control-plane/execution/work-preparation-service.ts',
2014
+ ]) {
2015
+ forbid(path, /assertWorkControllerOwnership|releasePreparedWorkOwnership|claimPreparedWorkOwnership|claimHeadAdoptionOwnership|withControllerSessionTerminalizationFence|getControllerSession|claimControllerSession|resumeControllerSession|releaseControllerSessionWithAuthority|releaseObservedControllerSession|controllerClaimed/, 'ordinary Work preparation/execution/finalization/cleanup must not use ControllerSession as authority');
2016
+ }
2017
+ forbid(
2018
+ 'src/runtime/recovery/maintenance-executor.ts',
2019
+ /withControllerSessionTerminalizationFence|listControllerSessions|getControllerSession|controllerWorkIds|controller_session/,
2020
+ 'stale Work maintenance must re-check concrete Work/source/resource facts instead of using ControllerSession as lifecycle authority',
2021
+ );
2022
+ requireText('src/runtime/control-plane/facade/handoff-inbox-store.ts', 'migrateLegacyHandoffInbox');
2023
+ requireText('src/runtime/control-plane/facade/handoff-inbox-store.ts', 'HANDOFF_LEGACY_STORE_READ_ONLY');
2024
+ requireText('src/runtime/control-plane/facade/handoff-inbox-store.ts', 'UserRequest owns the durable write');
2025
+ forbid('src/runtime/control-plane/facade/handoff-inbox-store.ts', /writeLegacyHandoffInboxStore|export function writeHandoffInboxStore/, 'legacy Handoff store must never remain a writable second authority');
2026
+ forbid('src/runtime/plugins/store.ts', /status:\s*terminalRemoteEffect\s*\?\s*['\"]completed['\"]/, 'plugin/effect delivery results must never claim semantic Work completion');
2027
+ requireText('src/runtime/plugins/store.ts', "semanticState: 'open' as const");
2028
+ for (const path of sourceFiles('src')) {
2029
+ forbid(path, /\bcancelWorkContract\s*\(/, 'runtime/maintenance code must never auto-cancel semantic Work; cancellation belongs to explicit semantic CAS');
2030
+ }
2031
+ requireText('src/runtime/control-plane/facade/goal-workloop.ts', "state: 'cancelled'");
2032
+ requireText('src/runtime/recovery/maintenance-executor.ts', "result: 'work_semantic_completion_required'");
2033
+ requireText('src/runtime/control-plane/execution/work-authority-reconciler.ts', "'semantic_work_open_ownerless'");
2034
+ forbid(
2035
+ 'packages/kernel/scheduler/infrastructure/schedule-store.ts',
2036
+ /repeated_infrastructure_failure|activeScheduleFailureHandoff|stableScheduleFailureHandoffId|resolveRecoveredScheduleFailureHandoffs/,
2037
+ 'mechanical Scheduler failures must remain runtime/backoff facts and must not create human-request authority',
2038
+ );
2039
+ {
2040
+ const workStoreSource = text('packages/kernel/work/infrastructure/work-contract-store.ts');
2041
+ const receiptWriterStart = workStoreSource.indexOf('export function recordWorkCompletionReceipt(');
2042
+ const receiptWriterEnd = workStoreSource.indexOf('\nexport interface AcceptSubmittedWorkInput', receiptWriterStart);
2043
+ const receiptWriter = receiptWriterStart >= 0 && receiptWriterEnd > receiptWriterStart
2044
+ ? workStoreSource.slice(receiptWriterStart, receiptWriterEnd)
2045
+ : '';
2046
+ if (!receiptWriter) fail('recordWorkCompletionReceipt writer not found');
2047
+ if (/status:\s*['"]completed['"]|dispatchState:\s*['"]terminal['"]|phase:\s*['"]cleanup['"]|WORK_IMPLEMENTATION_REVIEW_REQUIRED|transitionWorkContractPhase|requestWorkImplementationReview/.test(receiptWriter)) {
2048
+ fail('delivery/effect receipt recording must not terminalize Work or reintroduce review/lifecycle gates');
2049
+ }
2050
+ }
2051
+ forbid(
2052
+ 'src/runtime/control-plane/execution/work-completion-authority.ts',
2053
+ /completeRequirementFromWork|projectRequirementDeliveryFromCompletedWork|completeWorkWithReceipt/,
2054
+ 'delivery evidence must not auto-complete Work or Requirement',
2055
+ );
2056
+ for (const path of [
2057
+ 'adapters/mcp/runtime-gateway/work-adapter.ts',
2058
+ 'adapters/mcp/runtime-gateway/repository-compat-adapter.ts',
2059
+ 'src/runtime/control-plane/facade/goal-workloop.ts',
2060
+ ]) {
2061
+ forbid(path, /lifecycleClosed|finalStatus:\s*['"]completed['"]|directEditWorkCompletion/, 'mechanical delivery/finalize responses must not masquerade as semantic Work completion');
2062
+ }
2063
+ // Temporary migration assertion on automatic dispatch admission. Explicit
2064
+ // operator repair may reconstruct a historical dispatch-owner pre-click proof;
2065
+ // unknown observation reasons must never be automatic retry authority. Remove
2066
+ // this string fence when the existing effect admission contract is AST-fenced.
2067
+ forbidBetween(
2068
+ 'supervisor/store.ts',
2069
+ 'nextBrowserEffect(',
2070
+ 'effectDispatchBudget(',
2071
+ /composer_missing|send_button_missing|latestRetryEvidenceEventId/,
2072
+ 'dispatch generation may advance only from canonical effect_not_applied proof; effect_unknown never authorizes replay',
2073
+ );
2074
+ requireText('packages/kernel/controller/domain/controller-round-transition-policy.ts', "Pick<ControllerRoundRelayRecord, 'relayScopeId' | 'originWorkId' | 'roundCount'>");
2075
+ forbid(
2076
+ 'packages/kernel/controller/domain/controller-round-transition-policy.ts',
2077
+ /controllerRoundProviderEffectId[\s\S]{0,400}authorityId/,
2078
+ 'canonical continuation/provider effect identity must survive Controller authority rotation',
2079
+ );
2080
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'reserveWorkflowSupervisorEnrollment(forgeHome, registeredTask.taskId, lowerLayer.providerEffectId)');
2081
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'providerDispatchEffectId: effect.effectId');
2082
+ requireText('supervisor/protocol.ts', '(?:fx|crpe)_');
2083
+ // Cognitive Plane stays one advisory application path: all Controller tools expose the
2084
+ // same optional settlement metadata, the MCP server settles it after the primary
2085
+ // outcome, and Supervisor/external launchers consume Cognition-only projections.
2086
+ requireText('adapters/mcp/toolset.ts', 'injectCognitionSettlementFields(injectAutomationEnvelopeFields(injectDurableCommandFields(definition)))');
2087
+ requireText('adapters/mcp/server.ts', 'settleCognitionAfterTool(ctx, name, args, localResult)');
2088
+ forbid('adapters/mcp/runtime-gateway/runtime-tools.ts', /settleCognitionEnvelope/, 'cognition settlement belongs to the canonical all-tool MCP boundary, not the rh_* facade only');
2089
+ requireText('src/runtime/root/workflow-supervisor-composition.ts', 'renderCognitiveAttentionForWork');
2090
+ requireText('src/runtime/control-plane/launcher/thin-launcher.ts', 'renderCognitiveAttentionForWork');
2091
+ forbid('src/runtime/root/workflow-supervisor-composition.ts', /renderAssistantWorkContext/, 'Supervisor prompts may receive bounded Cognition, not the legacy lower-layer AssistantWorkContext blob');
2092
+ forbid('src/runtime/control-plane/launcher/thin-launcher.ts', /renderAssistantWorkContext/, 'external controller prompts may receive bounded Cognition, not the legacy lower-layer AssistantWorkContext blob');
2093
+ requireText('packages/kernel/cognition/application/activation-service.ts', 'structuredConceptAliasCueScore');
2094
+ requireText('packages/kernel/cognition/application/activation-service.ts', 'fairScopedRead');
2095
+ requireText('packages/kernel/cognition/application/activation-service.ts', 'seenFamilies');
2096
+
2097
+ for (const path of [
2098
+ 'adapters/mcp/runtime-gateway/work-learning-operations.ts',
2099
+ 'src/runtime/control-plane/persistence/experience-store.ts',
2100
+ ]) {
2101
+ forbid(path, /assertFacadeControllerRoundAuthority|controllerSessionAuthorityMatches|getControllerSession|EXPERIENCE_CONTROLLER_NOT_OWNER|EXPERIENCE_ROUND_AUTHORITY_MISMATCH|EXPERIENCE_CLAIM_AUTHORITY_MISMATCH/, 'advisory learning writes must use Work provenance and evidence, not Controller ownership');
2102
+ }
2103
+ forbid(
2104
+ 'src/cli/commands/brain-assistant.ts',
2105
+ /authority-env|BRAIN_CONTROLLER_AUTHORITY_REQUIRED|BRAIN_AUTHORITY_ENV_INVALID/,
2106
+ 'advisory experience CLI must not require a Controller capability',
2107
+ );
2108
+ for (const path of [
2109
+ 'src/runtime/gateway/mcp/execution-tools.ts',
2110
+ 'src/runtime/gateway/mcp/legacy-ios-tool-adapter.ts',
2111
+ 'src/runtime/gateway/mcp/persisted-check-process.ts',
2112
+ 'src/runtime/gateway/mcp/process-tools.ts',
2113
+ 'src/runtime/gateway/mcp/router.ts',
2114
+ 'src/runtime/gateway/mcp/runtime-tool-definitions.ts',
2115
+ 'src/runtime/gateway/mcp/runtime-tools.ts',
2116
+ 'src/runtime/gateway/mcp/work-validation-reconciler.ts',
2117
+ ]) requireText(path, '@deprecated Kernel V2 compatibility shim');
2118
+ for (const path of [
2119
+ 'src/cli/mcp/access-tools.ts',
2120
+ 'src/cli/mcp/legacy-context.ts',
2121
+ 'src/cli/mcp/legacy-tool-service.ts',
2122
+ 'src/cli/mcp/multi-repository.ts',
2123
+ 'src/cli/mcp/repository-tools.ts',
2124
+ 'src/cli/mcp/server.ts',
2125
+ 'src/cli/mcp/tools.ts',
2126
+ 'src/cli/mcp/toolset.ts',
2127
+ ]) requireText(path, '@deprecated Kernel V2 compatibility shim');
2128
+ requireText('src/runtime/control-plane/execution/work-execution-support.ts', 'packages/protocols/mcp/execution-context');
2129
+ requireText('src/runtime/control-plane/execution/work-preparation-service.ts', 'packages/protocols/mcp/execution-context');
2130
+ requireText('src/runtime/control-plane/execution/work-operation-service.ts', 'packages/protocols/mcp/execution-context');
2131
+ for (const path of [
2132
+ 'adapters/mcp/transports/http.ts',
2133
+ 'adapters/mcp/transports/session-registry.ts',
2134
+ 'adapters/mcp/transports/stdio.ts',
2135
+ ]) forbid(path, /recordWorkCompletionReceipt|transitionWorkContractPhase|releaseControllerSessionWithAuthority|recordWorkImplementationReview/, 'MCP transport/session lifecycle must never terminalize Work or Controller authority');
2136
+
2137
+ // Kernel V2 B6: semantic Forge identity is independent of Runtime processes,
2138
+ // transport sessions, OAuth credentials, tunnel ids, and endpoint rotation.
2139
+ for (const path of [
2140
+ 'packages/kernel/identity/domain/types.ts',
2141
+ 'packages/kernel/identity/application/identity-service.ts',
2142
+ 'packages/kernel/identity/infrastructure/identity-store.ts',
2143
+ 'packages/kernel/identity/api/index.ts',
2144
+ ]) text(path);
2145
+ for (const symbol of ['ForgeInstanceIdentity', 'Principal', 'CredentialReference', 'CapabilityGrant', 'ConnectionIdentity']) {
2146
+ requireText('packages/kernel/identity/domain/types.ts', `interface ${symbol}`);
2147
+ }
2148
+ requireText('packages/kernel/identity/application/identity-service.ts', 'export function connectionIdentity');
2149
+ requireText('packages/kernel/identity/infrastructure/identity-store.ts', "'identity', 'forge-instance.json'");
2150
+ requireText('packages/kernel/identity/infrastructure/identity-store.ts', 'linkSync(temporary, path)');
2151
+ forbid(
2152
+ 'packages/kernel/identity/domain/types.ts',
2153
+ /\b(?:tunnelId|mcpServerUrl|endpointUrl|runtimeApiKey|accessToken|refreshToken|oauthToken|bearerToken)\b/,
2154
+ 'Kernel identity contracts must contain semantic ids or credential references, never transport endpoint/tunnel/token material',
2155
+ );
2156
+ forbidBetween(
2157
+ 'packages/kernel/identity/application/identity-service.ts',
2158
+ 'const semanticKey = [',
2159
+ "].join('\\u0000')",
2160
+ /\b(?:endpoint|url|tunnel|pid|process|session)\b/i,
2161
+ 'ConnectionIdentity semantic key must remain independent of endpoint, tunnel, process, and session identity',
2162
+ );
2163
+ forbidBetween(
2164
+ 'packages/kernel/identity/infrastructure/identity-store.ts',
2165
+ 'const identity: ForgeInstanceIdentity = {',
2166
+ '};',
2167
+ /\b(?:pid|process|endpoint|url|tunnel|token)\b/i,
2168
+ 'ForgeInstanceIdentity creation must remain independent of process and adapter transport/auth metadata',
2169
+ );
2170
+ for (const path of [
2171
+ 'src/cli/mcp/auth.ts',
2172
+ 'src/cli/mcp/setup.ts',
2173
+ 'src/cli/mcp/openai-secure-tunnel.ts',
2174
+ ]) {
2175
+ requireText(path, '@deprecated Kernel V2 compatibility shim');
2176
+ }
2177
+ requireText('adapters/mcp/auth.ts', 'forgeInstanceId?: string');
2178
+ forbid('adapters/mcp/auth.ts', /server:\s*\{[\s\S]{0,512}?instanceId\??:\s*string/, 'MCP server process identity must not share semantic Forge instanceId naming');
2179
+ requireText('adapters/mcp/setup.ts', 'ensureForgeInstanceIdentity');
2180
+ requireText('adapters/mcp/setup.ts', 'MCP_FORGE_INSTANCE_ID_MISMATCH');
2181
+ requireText('src/runtime/root/types.ts', 'forgeInstanceId: string');
2182
+ requireText('src/runtime/root/types.ts', 'runtimeInstanceId: string');
2183
+ requireText('src/runtime/root/runtime.ts', 'readonly forgeInstanceId: string');
2184
+ requireText('src/runtime/root/runtime.ts', 'ensureForgeInstanceIdentity');
2185
+ requireText('src/runtime/root/entry.ts', 'forgeInstanceId: runtime.forgeInstanceId');
2186
+ requireText('adapters/mcp/transports/http.ts', 'forgeInstanceId: forgeInstance.instanceId');
2187
+ requireText('adapters/mcp/transports/http-observation.ts', 'controllerInstanceId: process.env.FORGE_MCP_INSTANCE_ID');
2188
+ forbid('adapters/mcp/transports/http.ts', /\{\s*instanceId:\s*process\.env\.FORGE_MCP_INSTANCE_ID/, 'MCP process identity must not be exposed as semantic Forge instanceId');
2189
+ requireText('adapters/mcp/transports/http.ts', "adapterId: 'mcp-http'");
2190
+ requireText('adapters/mcp/transports/session-registry.ts', 'connectionId: string');
2191
+ requireText('adapters/mcp/transports/session-registry.ts', 'reservation.connectionId !== input.connectionId');
2192
+ requireText('adapters/mcp/tunnels/openai-secure-tunnel.ts', 'tunnelMatches: boolean');
2193
+ requireText('adapters/mcp/tunnels/openai-secure-tunnel.ts', 'credentialReference(config.runtimeApiKeyRef');
2194
+ forbid('adapters/mcp/tunnels/openai-secure-tunnel.ts', /\bidentityMatches\b/, 'tunnel binding match must not masquerade as Forge semantic identity');
2195
+
2196
+ // C0 Computer capability boundary: Browser and Desktop remain separate providers.
2197
+ // Controller-scoped plugins are owned by the serving ForgeInstance. A synthetic
2198
+ // RepositoryRecord must not reappear as a canonical execution or manifest path.
2199
+ const controllerRepoCallPattern = new RegExp(['controllerPlugin', 'Repository\\s*\\('].join(''));
2200
+ const legacyControllerRepoPattern = new RegExp(['CONTROLLER_SCOPE_REPO_ID|__controller__|controllerPlugin', 'Repository'].join(''));
2201
+ for (const path of productionTypeScriptFiles()) {
2202
+ forbid(path, controllerRepoCallPattern, 'production controller-plugin paths must not recreate a fake controller RepositoryRecord');
2203
+ }
2204
+ requireText('src/runtime/plugins/store.ts', 'const CONTROLLER_PLUGIN_SCOPE_KEY = FORGE_INSTANCE_SCOPE_KEY');
2205
+ forbidBetween(
2206
+ 'src/runtime/plugins/store.ts',
2207
+ 'function controllerPluginActionScope',
2208
+ 'function pluginActionExecutionFields',
2209
+ legacyControllerRepoPattern,
2210
+ 'the canonical controller action scope must use the ForgeInstance scope, not the legacy controller repository sentinel',
2211
+ );
2212
+ for (const [start, end, description] of [
2213
+ ['export function listControllerPluginManifests(', 'function getControllerPluginManifestForExecution', 'controller manifest listing'],
2214
+ ['export function getControllerPluginManifest(', 'function writeControllerRegistry', 'controller manifest lookup'],
2215
+ ['export function submitControllerPluginAction(', 'async function executePluginActionInScope', 'controller action submission'],
2216
+ ['export function executeControllerScopedPluginAction(', 'export function executeAssistantPluginAction', 'controller action execution'],
2217
+ ]) {
2218
+ forbidBetween(
2219
+ 'src/runtime/plugins/store.ts',
2220
+ start,
2221
+ end,
2222
+ legacyControllerRepoPattern,
2223
+ `${description} must not depend on the legacy controller repository sentinel`,
2224
+ );
2225
+ }
2226
+ // Legacy controller coordinates remain read-only migration/compatibility inputs
2227
+ // or explicit rejection paths; they are not allowed to become new write paths.
2228
+ requireText('src/runtime/plugins/store.ts', 'One-way read compatibility for pre-cutover controller receipts only.');
2229
+ requireText('adapters/mcp/runtime-gateway/plugin-adapter.ts', 'PLUGIN_CONTROLLER_REPOSITORY_SENTINEL_RETIRED');
2230
+ requireText('src/runtime/plugins/app-store-connect-adapter.ts', 'APP_STORE_CONNECT_LEGACY_CONTROLLER_SCOPE_WRITE_RETIRED');
2231
+ requireText('packages/protocols/computer/contract.ts', 'COMPUTER_BROWSER_AUTOMATION_CAPABILITY');
2232
+ requireText('packages/protocols/computer/contract.ts', 'ComputerRuntimeProviderCapabilityId');
2233
+ requireText('packages/plugin-runtime/computer/provider.ts', 'ComputerRuntimeProviderCapabilityId');
2234
+ requireText('packages/plugin-runtime/computer/provider-registry.ts', 'COMPUTER_PROVIDER_AMBIGUOUS');
2235
+ requireText('packages/plugin-runtime/computer/provider-registry.ts', 'COMPUTER_PROVIDER_DUPLICATE_ID');
2236
+ forbid('packages/plugin-runtime/computer/provider-registry.ts', /throw new Error\(/, 'Computer provider resolution must expose typed provider errors rather than raw order-dependent failures');
2237
+
2238
+ requireText('packages/protocols/computer/contract.ts', 'COMPUTER_CAPABILITY_PROTOCOL_VERSION');
2239
+ requireText('packages/protocols/computer/contract.ts', 'COMPUTER_CAPABILITY_EXECUTION_METHOD');
2240
+ requireText('packages/protocols/computer/contract.ts', 'export interface ComputerCapabilityAdvertisement');
2241
+ forbid('adapters/computer/desktop-operator-negotiation.ts', /interface\s+ComputerCapabilityAdvertisement/, 'Desktop Operator negotiation must consume the provider-neutral Computer capability advertisement contract instead of redefining it');
2242
+ requireText('packages/plugin-runtime/computer/provider.ts', 'export interface ComputerProvider');
2243
+ requireText('packages/plugin-runtime/computer/provider-registry.ts', 'export class ComputerProviderRegistry');
2244
+ requireText('adapters/computer/desktop-operator-contract.ts', 'DESKTOP_OPERATOR_PROVIDER_PLUGIN_ID');
2245
+ requireText('adapters/computer/desktop-operator-negotiation.ts', 'negotiateDesktopOperatorComputerHandshake');
2246
+ requireText('adapters/computer/desktop-operator-negotiation.ts', 'buildDesktopOperatorComputerInvocation');
2247
+ requireText('adapters/computer/desktop-operator-provider.ts', 'createDesktopOperatorComputerProvider');
2248
+ requireText('adapters/computer/desktop-operator-discovery.ts', 'ComputerProviderRegistrationLookup');
2249
+ requireText('adapters/computer/desktop-operator-discovery.ts', "source: 'registration'");
2250
+ requireText('adapters/computer/desktop-operator-discovery.ts', "PLUGIN_COMPUTER_PROVIDER_REGISTRATION_REQUIRED");
2251
+ forbid('adapters/computer/desktop-operator-discovery.ts', /legacy_fallback|DesktopOperatorLegacyFallbackMode|unregistered_v0_2/, 'Computer provider discovery must not bypass canonical Desktop Operator registration with a legacy socket fallback');
2252
+ forbid('src/runtime/root/computer-composition.ts', /legacyFallback|unregistered_v0_2/, 'Computer Runtime composition must not enable an unregistered Desktop Operator compatibility provider');
2253
+ requireText('src/cli/commands/computer.ts', "new Command('computer')");
2254
+ requireText('src/cli/commands/computer.ts', 'installOfficialPlugin(COMPUTER_PROVIDER_PLUGIN_ID');
2255
+ requireText('src/cli/commands/computer.ts', 'provider release: independent');
2256
+ requireText('src/cli/commands/computer.ts', 'COMPUTER_PROVIDER_UNINSTALLER_MISSING');
2257
+ requireText('src/cli/commands/computer.ts', 'readControllerStoredPluginManifest');
2258
+ requireText('src/cli/commands/computer.ts', 'syncControllerPluginManifest');
2259
+ requireText('src/cli/commands/computer.ts', 'removeControllerPluginManifestProjection');
2260
+ requireText('src/cli/commands/computer.ts', 'withOfficialPluginLifecycleLock');
2261
+ forbid('src/cli/commands/computer.ts', new RegExp(`${controllerRepoCallPattern.source}|syncAssistantPluginRegistry|getAssistantPluginManifest\\s*\\(`), 'Computer status/doctor must use Controller-scoped stored/targeted provider APIs rather than a fake repository or global execution-style manifest lookup');
2262
+ requireText('src/cli/commands/plugin.ts', 'external-plugin:${pluginId}');
2263
+ requireText('src/runtime/plugins/store.ts', 'export function readControllerStoredPluginManifest');
2264
+ requireText('src/runtime/plugins/store.ts', 'export function syncControllerPluginManifest');
2265
+ requireText('src/runtime/plugins/store.ts', 'export function removeControllerPluginManifestProjection');
2266
+ requireText('src/runtime/plugins/store.ts', 'export function readStoredAssistantPluginManifest');
2267
+ requireText('src/runtime/plugins/store.ts', 'export function syncAssistantPluginManifest');
2268
+ requireText('src/runtime/plugins/store.ts', 'export function removeAssistantPluginManifestProjection');
2269
+ requireText('src/cli/index.ts', 'buildComputerCommand');
2270
+ requireText('src/cli/index.ts', "'computer'");
2271
+
2272
+ forbid('adapters/computer/desktop-operator-provider.ts', /getExternalPluginRegistration|controller-home|computerCapabilities|internalCapabilities|browserAutomationProtocolVersion|browserAutomationActions|macos_browser_automation|computer_execute/, 'Desktop Operator provider transport must consume discovery and negotiation results rather than own Controller lookup or wire negotiation');
2273
+ forbid('adapters/computer/desktop-operator-negotiation.ts', /getExternalPluginRegistration|controller-home|desktop-operator-discovery/, 'Desktop Operator negotiation must depend on protocol/contract facts, not endpoint discovery');
2274
+ forbid('adapters/computer/desktop-operator-discovery.ts', /macos_browser_automation|LEGACY_BROWSER_AUTOMATION/, 'Desktop Operator discovery must own endpoint resolution only, not compatibility protocol negotiation');
2275
+ forbid('adapters/computer/desktop-operator-provider.ts', /getExternalPluginAdapter|AssistantPluginActionExecutionInput|desktop_session_open|NATIVE_BROWSER_BUNDLE_IDS|activateDesktopOperatorBrowserApplication/, 'Desktop Operator Computer transport adapter must not own Runtime plugin-action application activation glue');
2276
+ for (const path of sourceFiles('adapters/computer')) {
2277
+ forbid(path, /AssistantPluginError/, 'Computer adapters must expose provider errors through plugin-runtime rather than depend on Runtime plugin error types');
2278
+ }
2279
+ requireText('src/runtime/root/computer-composition.ts', 'lookupRegistration: (providerPluginId) =>');
2280
+ requireText('src/runtime/root/computer-composition.ts', 'computerProviderRegistrationSnapshot(registration)');
2281
+ requireText('src/runtime/root/computer-composition.ts', 'getExternalPluginAdapter(input.controllerHome, DESKTOP_OPERATOR_PROVIDER_PLUGIN_ID)');
2282
+ requireText('src/runtime/plugins/browser-automation-service.ts', 'executeRuntimeComputerBrowserAutomation');
2283
+ requireText('src/runtime/plugins/browser-adapter.ts', 'activateRuntimeComputerBrowserApplication');
2284
+ forbid('src/runtime/plugins/browser-automation-service.ts', /desktop_operator|macos-capability-broker|desktop-operator\.sock|macos_browser_automation/, 'Browser automation must depend on the provider-neutral Computer boundary, not Desktop Operator transport details');
2285
+ forbid('src/runtime/plugins/browser-adapter.ts', /desktop_operator|Desktop Operator|getExternalPluginAdapter|desktop_session_open/, 'Browser adapter must not know the concrete Desktop Operator application provider');
2286
+ for (const path of sourceFiles('src/runtime/plugins').filter((entry) => /\/browser-(?!registration\.ts)[^/]+\.ts$/.test(entry))) {
2287
+ forbid(path, /desktop_operator|Desktop Operator|desktop-operator\.sock|macos_browser_automation/, 'Browser modules must depend on Computer capabilities rather than concrete Desktop Operator transport identity');
2288
+ }
2289
+ requireText('src/runtime/plugins/macos-capability-broker.ts', '@deprecated C0 compatibility shim');
2290
+ requireText('src/runtime/plugins/macos-capability-broker.ts', 'executeRuntimeComputerBrowserAutomation');
2291
+ forbid('src/runtime/plugins/macos-capability-broker.ts', /callDesktopOperatorComputerBrowserAutomation/, 'Deprecated macOS broker execution must delegate to Runtime Computer composition rather than call the concrete provider directly');
2292
+ requireText('src/runtime/control-plane/facade/types.ts', 'semanticCapabilities?: string[]');
2293
+ forbid('src/runtime/control-plane/facade/capability-registry.ts', /plugin\.desktop_operator/, 'Control Plane capability discovery must rank provider-declared semantic capabilities rather than concrete Desktop Operator plugin identity');
2294
+ requireText('src/runtime/plugins/external-provider-policy.ts', 'resolveExternalProviderPolicy');
2295
+ requireText('src/runtime/plugins/desktop-operator-external-policy.ts', 'verifyExactForegroundDesktopSession');
2296
+ forbid('src/runtime/plugins/external-adapter.ts', /desktop_operator|desktopOperator|DESKTOP_|['\"]desktop_[a-z_]|desktop-operator-external-policy/, 'Generic external plugin adapter must delegate provider-specific Desktop policy through ExternalProviderPolicy');
2297
+ requireText('src/runtime/plugins/desktop-operator-registration.ts', 'COMPUTER_OBSERVE_CAPABILITY');
2298
+ requireText('src/runtime/plugins/desktop-operator-registration.ts', 'COMPUTER_INPUT_CAPABILITY');
2299
+ requireText('src/runtime/plugins/desktop-operator-registration.ts', 'COMPUTER_CAPTURE_CAPABILITY');
2300
+ requireText('src/runtime/plugins/desktop-operator-registration.ts', 'pluginVersion: options.pluginVersion');
2301
+ forbid('src/runtime/plugins/desktop-operator-registration.ts', /pluginVersion:\s*options\.pluginVersion\s*\?\?|pluginVersion:\s*['"]0\./, 'Forge must not invent the Desktop Operator provider release version');
2302
+ requireText('packages/plugin-runtime/external/unix-jsonl-transport.ts', 'EXTERNAL_RPC_METHOD_PATTERN');
2303
+ requireText('src/runtime/plugins/external-unix-socket.ts', 'callExternalUnixJsonl');
2304
+ forbid('src/runtime/plugins/external-unix-socket.ts', /createConnection|EXTERNAL_RPC_METHOD_PATTERN|packages\/protocols\/computer|computer_execute|macos_browser_automation/, 'Runtime external Unix socket compatibility layer must delegate async transport and must not own Computer/Desktop provider method identities');
2305
+ forbid('adapters/computer/desktop-operator-provider.ts', /src\/runtime\/plugins\/external-unix-socket|callExternalUnixSocket/, 'Computer provider adapters must consume provider-neutral plugin-runtime transport rather than Runtime socket implementation');
2306
+
2307
+ // C0 Browser runtime authority: contracts and provider selection belong to plugin-runtime/protocols.
2308
+ requireText('packages/plugin-runtime/browser/runtime-contract.ts', 'export interface BrowserTransaction');
2309
+ requireText('packages/plugin-runtime/browser/provider-registry.ts', 'export class BrowserProviderRegistry');
2310
+ requireText('packages/plugin-runtime/browser/provider-registry.ts', 'export class BrowserProviderSelectionError');
2311
+ forbid('packages/plugin-runtime/browser/provider-registry.ts', /AssistantPluginError|src\/runtime|adapters\//, 'Browser provider selection must remain provider-neutral inside plugin-runtime');
2312
+ requireText('packages/protocols/browser/session.ts', 'export interface BrowserSessionState');
2313
+ for (const path of [
2314
+ 'src/runtime/plugins/browser-runtime-contract.ts',
2315
+ 'src/runtime/plugins/browser-provider-registry.ts',
2316
+ 'src/runtime/plugins/browser-session-types.ts',
2317
+ ]) {
2318
+ requireText(path, '@deprecated C0 compatibility shim');
2319
+ }
2320
+ for (const path of sourceFiles('src/runtime/plugins')) {
2321
+ if (['src/runtime/plugins/browser-runtime-contract.ts', 'src/runtime/plugins/browser-provider-registry.ts', 'src/runtime/plugins/browser-session-types.ts'].includes(path)) continue;
2322
+ forbid(path, /from\s+['"]\.\/browser-(?:runtime-contract|provider-registry|session-types)['"]/, 'active Browser runtime code must consume plugin-runtime/protocol Browser contracts, not retired local owners');
2323
+ }
2324
+ // Computer SurfaceTarget is the only durable interaction-target authority. Browser
2325
+ // compatibility may retain old type/API names, but it must not recreate a Browser
2326
+ // or Desktop authority/persistence owner alongside Computer.
2327
+ requireMissing('adapters/browser/session-authority.ts');
2328
+ requireMissing('adapters/browser/sqlite-session-authority.ts');
2329
+ requireMissing('packages/plugin-runtime/browser/session-persistence.ts');
2330
+ requireMissing('src/runtime/root/browser-session-persistence.ts');
2331
+ forbid('packages/plugin-runtime/browser/session-authority.ts', /\bBrowserSession(?:Authority|Persistence)Port\b/, 'Browser compatibility contracts must not expose a second durable authority or persistence port');
2332
+ requireText('src/runtime/plugins/browser-session-authority.ts', 'findComputerBackedBrowserSession');
2333
+ requireText('src/runtime/plugins/browser-session-authority.ts', 'saveComputerBackedBrowserSession');
2334
+ forbid('src/runtime/plugins/browser-session-authority.ts', /\b(?:writeControlPlaneRecord|deleteControlPlaneRecord|withControlPlaneTransaction|createBrowserSessionAuthority|runtimeBrowserSessionAuthority)\b/, 'Browser compatibility facade must delegate semantic identity to Computer and cannot persist its own authority');
2335
+ requireText('src/runtime/plugins/browser-session-legacy-migration.ts', 'readLegacyBrowserSessionMigrationEntries');
2336
+ requireText('src/runtime/plugins/browser-session-store.ts', 'PLUGIN_BROWSER_SESSION_CONTEXT_REQUIRED');
2337
+ forbid('src/runtime/plugins/browser-session-store.ts', /writeJsonAtomic\(sessionPath|readLegacyBrowserSessionJson|rmSync\(sessionPath/, 'steady-state Browser session identity must never fall back to repository-local JSON outside Computer target authority');
2338
+ forbid('src/runtime/plugins/browser-session-legacy-migration.ts', /\b(?:writeControlPlaneRecord|deleteControlPlaneRecord|withControlPlaneTransaction|createBrowserSessionAuthority|runtimeBrowserSessionAuthority)\b/, 'legacy Browser migration may read retired state but cannot mutate or recreate Browser durable authority');
2339
+ requireText('src/runtime/root/browser-session-composition.ts', 'BrowserSessionExecutionContext');
2340
+ forbid('src/runtime/root/browser-session-composition.ts', /\b(?:createBrowserSessionAuthority|runtimeBrowserSessionAuthority|createRuntimeBrowserSessionPersistence)\b/, 'Browser Runtime composition may carry execution context but cannot compose a second durable interaction authority');
2341
+ for (const path of [
2342
+ ...sourceFiles('adapters/browser'),
2343
+ ...sourceFiles('packages/plugin-runtime/browser'),
2344
+ ...sourceFiles('src/runtime/plugins'),
2345
+ ...sourceFiles('src/runtime/root'),
2346
+ ]) {
2347
+ if (path === 'src/runtime/plugins/browser-session-legacy-migration.ts') continue;
2348
+ forbid(path, LEGACY_INTERACTION_AUTHORITY_OWNER_DECLARATION, 'Browser/Desktop durable interaction authority must live only in Computer target authority');
2349
+ }
2350
+ // Workflow Asset authority: editable content stays in files; machine registry stays metadata-only.
2351
+ requireText('packages/workflow-runtime/domain/workflow-asset.ts', 'export interface WorkflowAssetDefinition');
2352
+ requireText('packages/workflow-runtime/domain/workflow-asset.ts', 'workflowAssetContentDigest');
2353
+ requireText('src/runtime/control-plane/persistence/workflow-content-store.ts', 'ensureControllerWorkflowContentRoot');
2354
+ requireText('src/runtime/control-plane/persistence/workflow-registry-store.ts', "WORKFLOW_REGISTRY_NAMESPACE = 'workflow_registry'");
2355
+ requireText('src/runtime/control-plane/persistence/workflow-registry-store.ts', 'WORKFLOW_REGISTRY_CONTENT_IDENTITY_CHANGED');
2356
+ forbid('src/runtime/control-plane/persistence/workflow-registry-store.ts', /\b(?:prompts|scripts|templates|selectors|resources)\s*:/, 'Workflow machine registry must not persist editable prompt/script/template/selector/resource bodies');
2357
+ for (const path of sourceFiles('packages/workflow-runtime')) {
2358
+ forbid(path, /xiaohongshu|douyin|instagram|reddit|facebook/i, 'generic Workflow Runtime contracts must not own site/business choreography');
2359
+ forbid(path, /from\s+['"][^'"]*(?:src\/runtime|adapters)\//, 'Workflow Runtime package contracts must remain independent from Runtime/adapters implementation authority');
2360
+ }
2361
+ requireText('src/runtime/plugins/browser-registration.ts', 'export const browserPluginAdapter');
2362
+ requireText('src/runtime/plugins/first-party-registry.ts', "from './browser-registration'");
2363
+ forbid('src/runtime/plugins/first-party-registry.ts', /from\s+['"]\.\/browser-adapter['"]/, 'first-party registry must depend on the thin Browser registration entrypoint, not the action implementation');
2364
+ forbid('src/runtime/plugins/browser-adapter.ts', /export\s+const\s+browserPluginAdapter/, 'Browser action implementation must not also own first-party plugin registration');
849
2365
 
850
2366
  if (failures.length) {
851
2367
  console.error('[runtime-architecture] FAILED');