@moretea-labs/forge 1.6.0 → 1.7.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 (469) hide show
  1. package/AGENTS.md +4 -0
  2. package/CHANGELOG.md +39 -0
  3. package/CLAUDE.md +4 -0
  4. package/README.md +2 -2
  5. package/README.zh-CN.md +1 -1
  6. package/SKILL.md +2 -2
  7. package/THIRD_PARTY_NOTICES.md +1 -1
  8. package/agents/openai.yaml +1 -1
  9. package/assets/hooks/hook-input.sh +11 -8
  10. package/assets/hooks/lib/session-state.sh +10 -7
  11. package/assets/hooks/lib/workflow-state.sh +13 -177
  12. package/assets/hooks/post-tool-observer.sh +8 -2
  13. package/assets/hooks/prompt-guard.sh +5 -81
  14. package/assets/hooks/session-start-context.sh +56 -1
  15. package/assets/partials/05-workflow.partial.md +1 -1
  16. package/assets/partials-agents/02-operating-mode.partial.md +2 -0
  17. package/assets/partials-agents/03-orchestration.partial.md +1 -1
  18. package/assets/plugin-registry.v1.json +3 -3
  19. package/assets/reference-configs/document-generation.md +1 -1
  20. package/assets/reference-configs/harness-overview.md +1 -1
  21. package/assets/reference-configs/sprint-contracts.md +3 -3
  22. package/assets/skill-version.json +2 -2
  23. package/assets/templates/contract.template.md +2 -7
  24. package/assets/templates/helpers/capture-plan.sh +2 -2
  25. package/assets/templates/helpers/check-architecture-sync.sh +17 -0
  26. package/assets/templates/helpers/check-task-workflow.sh +4 -4
  27. package/assets/templates/helpers/contract-worktree.sh +1 -21
  28. package/assets/templates/helpers/ensure-task-workflow.sh +11 -36
  29. package/assets/templates/helpers/inspect-project-state.ts +8 -6
  30. package/assets/templates/helpers/migrate-project-template.sh +22 -45
  31. package/assets/templates/helpers/migrate-workflow-docs.ts +9 -7
  32. package/assets/templates/helpers/new-plan.sh +1 -1
  33. package/assets/templates/helpers/plan-to-todo.sh +12 -37
  34. package/assets/templates/helpers/ship-worktrees.sh +2 -29
  35. package/assets/templates/helpers/verify-contract.sh +1 -111
  36. package/assets/templates/helpers/verify-sprint.sh +3 -180
  37. package/assets/templates/helpers/workflow-contract.ts +5 -1
  38. package/assets/templates/plan.template.md +1 -1
  39. package/assets/templates/review.template.md +9 -34
  40. package/assets/workflow-contract.v1.json +10 -19
  41. package/docs/README.md +10 -10
  42. package/docs/architecture/CURRENT.md +178 -0
  43. package/docs/architecture/EVOLUTION.md +42 -0
  44. package/docs/architecture/current/README.md +4 -156
  45. package/docs/architecture/decisions/20260803-release-identity-binding-and-exit-policy.md +2 -2
  46. package/docs/architecture/decisions/20260823-immediate-controller-relay.md +53 -0
  47. package/docs/architecture/decisions/20260826-browser-runtime-v2.md +73 -0
  48. package/docs/architecture/history/README.md +7 -0
  49. package/docs/architecture/{chatgpt-handoff-facade.md → history/chatgpt-handoff-facade.md} +4 -0
  50. package/docs/architecture/{global-hook-runtime.md → history/global-hook-runtime.md} +7 -3
  51. package/docs/architecture/{ios-semantic-automation-provider-v2.md → history/ios-semantic-automation-provider-v2.md} +6 -2
  52. package/docs/architecture/history.md +3 -34
  53. package/docs/architecture/index.md +15 -98
  54. package/docs/architecture/modules/controller-runtime/transport-lifecycle.md +1 -1
  55. package/docs/architecture/reviews/2026-08-22-semantic-harness-convergence-acceptance.md +39 -0
  56. package/docs/architecture/versions/1.6.md +38 -0
  57. package/docs/architecture/versions/1.7.md +41 -0
  58. package/docs/forge-chatgpt-browser-engine.md +2 -2
  59. package/docs/forge-chatgpt-mcp-setup.md +4 -28
  60. package/docs/forge-chatgpt-supervised-automation.md +3 -3
  61. package/docs/forge-github-issue-launcher.md +1 -1
  62. package/docs/forge-plugin-management.md +1 -1
  63. package/docs/forge-runtime-self-healing-loop.md +1 -1
  64. package/docs/operations/controller-browser-plugin.md +26 -6
  65. package/docs/operations/controller-performance-and-502.md +143 -0
  66. package/docs/operations/controller-reliability-runbook.md +1 -1
  67. package/docs/operations/features.md +2 -2
  68. package/docs/operations/github-repository.md +1 -1
  69. package/docs/operations/homebrew.md +2 -2
  70. package/docs/operations/mcp-tool-exposure.md +5 -3
  71. package/docs/wiki/Architecture.md +6 -6
  72. package/docs/wiki/Implementation.md +2 -2
  73. package/docs/wiki/Integrations.md +2 -2
  74. package/docs/wiki/Work-Lifecycle.md +1 -1
  75. package/package.json +33 -11
  76. package/scripts/activate-source-baseline.ts +17 -13
  77. package/scripts/architecture-event.ts +2 -820
  78. package/scripts/architecture-queue.sh +2 -645
  79. package/scripts/archive-architecture-request.sh +2 -242
  80. package/scripts/archive-workflow.sh +1 -291
  81. package/scripts/benchmark-background-check-overlap.ts +228 -0
  82. package/scripts/benchmark-mcp-host.sh +117 -0
  83. package/scripts/benchmark-mcp-transport.ts +170 -0
  84. package/scripts/benchmark-quality-harness.ts +146 -0
  85. package/scripts/benchmark-route-session-concurrency.ts +207 -6
  86. package/scripts/benchmark-thin-harness-mcp-e2e.ts +7 -1
  87. package/scripts/benchmark-typescript-navigation.ts +186 -0
  88. package/scripts/benchmark-work-efficiency.ts +334 -0
  89. package/scripts/capability-config.ts +2 -392
  90. package/scripts/capability-resolver.ts +2 -503
  91. package/scripts/capture-plan.sh +1 -332
  92. package/scripts/check-agent-tooling.sh +2 -1558
  93. package/scripts/check-architecture-sync.sh +2 -371
  94. package/scripts/check-brain-manifest.sh +2 -253
  95. package/scripts/check-context-files.sh +2 -47
  96. package/scripts/check-deploy-sql-order.sh +2 -115
  97. package/scripts/check-mcp-compatibility.ts +14 -0
  98. package/scripts/check-runtime-architecture.mjs +349 -79
  99. package/scripts/check-skill-version.ts +3 -191
  100. package/scripts/check-source-duplication.mjs +61 -0
  101. package/scripts/check-stable-baseline.ts +92 -0
  102. package/scripts/check-task-sync.sh +2 -63
  103. package/scripts/check-task-workflow.sh +2 -1000
  104. package/scripts/codex-handoff-resume.sh +2 -267
  105. package/scripts/context-contract-sync.sh +2 -514
  106. package/scripts/contract-run.ts +2 -463
  107. package/scripts/contract-worktree.sh +1 -722
  108. package/scripts/ensure-task-workflow.sh +1 -1225
  109. package/scripts/host-temporary-cloud-mcp-e2e.sh +265 -0
  110. package/scripts/inspect-project-state.ts +4 -279
  111. package/scripts/install-standalone-recovery.ts +24 -0
  112. package/scripts/lib/project-init-lib.sh +22 -46
  113. package/scripts/lib/run-forge-helper.sh +19 -0
  114. package/scripts/lib/run-forge-helper.ts +26 -0
  115. package/scripts/migrate-project-template.sh +1 -1189
  116. package/scripts/migrate-workflow-docs.ts +4 -412
  117. package/scripts/new-plan.sh +1 -180
  118. package/scripts/new-spec.sh +1 -47
  119. package/scripts/new-sprint.sh +1 -46
  120. package/scripts/plan-to-todo.sh +1 -796
  121. package/scripts/prepare-codex-handoff.sh +2 -201
  122. package/scripts/prepare-handoff.sh +1 -78
  123. package/scripts/refresh-current-status.sh +2 -467
  124. package/scripts/run-governed-gate.ts +5 -1
  125. package/scripts/select-agent-context-blocks.sh +2 -64
  126. package/scripts/ship-worktrees.sh +1 -558
  127. package/scripts/smoke-ios-physical-device.ts +4 -2
  128. package/scripts/smoke-runtime-recovery.ts +1 -35
  129. package/scripts/smoke-schedule-engine.ts +1 -20
  130. package/scripts/sprint-backlog.sh +1 -834
  131. package/scripts/stage-runtime-release.ts +2 -1
  132. package/scripts/summarize-failures.sh +2 -123
  133. package/scripts/switch-plan.sh +1 -150
  134. package/scripts/sync-brain-docs.sh +2 -379
  135. package/scripts/sync-generated-authority.mjs +175 -0
  136. package/scripts/verify-contract.sh +2 -703
  137. package/scripts/verify-forge-runtime.sh +0 -1
  138. package/scripts/verify-sprint.sh +1 -677
  139. package/scripts/workflow-contract.ts +4 -205
  140. package/scripts/workstream-sync.sh +2 -261
  141. package/src/cli/agent-jobs/executor-health.ts +1 -1
  142. package/src/cli/commands/init-hook.ts +3 -3
  143. package/src/cli/commands/mcp.ts +9 -5
  144. package/src/cli/commands/plugin.ts +12 -3
  145. package/src/cli/commands/recovery.ts +25 -3
  146. package/src/cli/commands/runtime.ts +55 -3
  147. package/src/cli/commands/security.ts +12 -1
  148. package/src/cli/commands/setup-profile.ts +31 -21
  149. package/src/cli/controller/check-runner.ts +113 -5
  150. package/src/cli/controller/composite-result.ts +1 -1
  151. package/src/cli/controller/context/focus.ts +51 -0
  152. package/src/cli/controller/context/instruction-context.ts +114 -0
  153. package/src/cli/controller/context/known-paths.ts +76 -0
  154. package/src/cli/controller/context/query-planning.ts +110 -0
  155. package/src/cli/controller/context/rule-resolution.ts +532 -0
  156. package/src/cli/controller/context/source-materializer.ts +278 -0
  157. package/src/cli/controller/context/structural.ts +16 -0
  158. package/src/cli/controller/context/types.ts +286 -0
  159. package/src/cli/controller/context-pack.ts +828 -487
  160. package/src/cli/controller/launch-agents.ts +77 -2
  161. package/src/cli/controller/operational-plan.ts +2 -2
  162. package/src/cli/controller/work-mode.ts +6 -4
  163. package/src/cli/editing/edit-session.ts +60 -7
  164. package/src/cli/github/contracts.ts +16 -0
  165. package/src/cli/github/github.ts +135 -16
  166. package/src/cli/github/session.ts +2 -1
  167. package/src/cli/installer/managed-entries.ts +15 -1
  168. package/src/cli/local-bridge/console-automations.ts +54 -78
  169. package/src/cli/local-bridge/console-view-models.ts +1 -35
  170. package/src/cli/local-bridge/facade-api.ts +37 -264
  171. package/src/cli/local-bridge/frontend/src/App.tsx +3 -3
  172. package/src/cli/local-bridge/frontend/src/features/automations/AutomationsView.tsx +23 -13
  173. package/src/cli/local-bridge/frontend/src/features/capabilities/CapabilitiesView.tsx +37 -4
  174. package/src/cli/local-bridge/frontend/src/features/overview/OverviewView.tsx +6 -4
  175. package/src/cli/local-bridge/frontend/src/lib/api.ts +1 -6
  176. package/src/cli/local-bridge/frontend/src/lib/routes.ts +1 -1
  177. package/src/cli/local-bridge/frontend/src/shell/Sidebar.tsx +2 -2
  178. package/src/cli/local-bridge/frontend/src/styles.css +1 -1
  179. package/src/cli/local-bridge/frontend/src/types.ts +5 -8
  180. package/src/cli/local-bridge/job-store.ts +1 -490
  181. package/src/cli/local-bridge/server.ts +2 -515
  182. package/src/cli/local-bridge/ui-dist/app.css +1 -1
  183. package/src/cli/local-bridge/ui-dist/app.js +3703 -3757
  184. package/src/cli/mcp/auth.ts +5 -5
  185. package/src/cli/mcp/instructions.ts +3 -2
  186. package/src/cli/mcp/legacy-tool-service.ts +10 -222
  187. package/src/cli/mcp/multi-repository.ts +16 -5
  188. package/src/cli/mcp/oauth.ts +175 -26
  189. package/src/cli/mcp/post-finalize-work-attribution.ts +150 -0
  190. package/src/cli/mcp/repository-tools.ts +282 -146
  191. package/src/cli/mcp/server.ts +586 -116
  192. package/src/cli/mcp/tool-capability-cache.ts +1 -1
  193. package/src/cli/mcp/tool-contract.ts +14 -0
  194. package/src/cli/mcp/toolset-selection.ts +1 -1
  195. package/src/cli/mcp/toolset.ts +44 -7
  196. package/src/cli/mcp/transports/http.ts +124 -14
  197. package/src/cli/mcp/transports/session-registry.ts +43 -5
  198. package/src/cli/mcp/types.ts +3 -3
  199. package/src/cli/repositories/command-classifier.ts +103 -21
  200. package/src/cli/repositories/command-executor.ts +78 -526
  201. package/src/cli/repositories/command-process.ts +108 -0
  202. package/src/cli/repositories/command-scope.ts +99 -41
  203. package/src/cli/repositories/controller-home.ts +7 -8
  204. package/src/cli/repositories/git-command-executor.ts +2 -0
  205. package/src/cli/repositories/locks.ts +53 -16
  206. package/src/cli/repositories/repository-snapshot.ts +124 -0
  207. package/src/cli/repositories/selected-path-actions.ts +17 -9
  208. package/src/cli/repositories/structured-git.ts +118 -6
  209. package/src/cli/repository/inspector.ts +563 -65
  210. package/src/cli/repository/session-cache.ts +58 -17
  211. package/src/cli/v81-entry.ts +1 -4
  212. package/src/effects/fs-transaction.ts +85 -17
  213. package/src/runtime/context/codegraph-read-provider.ts +233 -2
  214. package/src/runtime/context/codegraph-sidecar.cjs +74 -40
  215. package/src/runtime/context/generic-lsp-provider.ts +355 -0
  216. package/src/runtime/context/lsp-client.ts +283 -0
  217. package/src/runtime/context/semantic-navigation-contract.ts +61 -0
  218. package/src/runtime/context/semantic-navigation.ts +223 -0
  219. package/src/runtime/context/swift-navigation.ts +565 -0
  220. package/src/runtime/context/typescript-navigation.ts +226 -0
  221. package/src/runtime/control-plane/dispatch-priority.ts +28 -0
  222. package/src/runtime/control-plane/execution/direct-edit-work-completion.ts +48 -16
  223. package/src/runtime/control-plane/execution/edit-validation-coordinator.ts +86 -24
  224. package/src/runtime/control-plane/execution/repository-work-attribution.ts +106 -0
  225. package/src/runtime/control-plane/execution/retained-work-resume.ts +203 -0
  226. package/src/runtime/control-plane/execution/session-store.ts +18 -0
  227. package/src/runtime/control-plane/execution/verification-evidence.ts +58 -3
  228. package/src/runtime/control-plane/execution/work-completion-authority.ts +58 -0
  229. package/src/runtime/control-plane/execution/work-evidence-policy.ts +200 -0
  230. package/src/runtime/control-plane/execution/work-execution-support.ts +386 -0
  231. package/src/runtime/control-plane/execution/work-finalization-service.ts +1913 -0
  232. package/src/runtime/control-plane/execution/work-handle-authority.ts +96 -0
  233. package/src/runtime/control-plane/execution/work-handle-store.ts +27 -2
  234. package/src/runtime/control-plane/execution/work-lifecycle-audit.ts +258 -0
  235. package/src/runtime/control-plane/execution/work-operation-service.ts +468 -0
  236. package/src/runtime/control-plane/execution/work-path-scope.ts +37 -0
  237. package/src/runtime/control-plane/execution/work-preparation-service.ts +479 -0
  238. package/src/runtime/control-plane/execution/work-process-evidence.ts +129 -0
  239. package/src/runtime/control-plane/execution/work-remote-delivery.ts +215 -0
  240. package/src/runtime/control-plane/execution/work-task-receipt.ts +22 -18
  241. package/src/runtime/control-plane/execution/work-terminal-cleanup.ts +156 -11
  242. package/src/runtime/control-plane/execution/work-validation-reconciler.ts +22 -14
  243. package/src/runtime/control-plane/execution/work-verification-context.ts +56 -0
  244. package/src/runtime/control-plane/execution/work-verification-service.ts +388 -0
  245. package/src/runtime/control-plane/execution/work-verification-snapshot.ts +90 -9
  246. package/src/runtime/control-plane/facade/capability-registry.ts +129 -25
  247. package/src/runtime/control-plane/facade/controller-round-relay.ts +1118 -0
  248. package/src/runtime/control-plane/facade/controller-session-store.ts +302 -12
  249. package/src/runtime/control-plane/facade/goal-workloop-access.ts +17 -1
  250. package/src/runtime/control-plane/facade/goal-workloop.ts +928 -190
  251. package/src/runtime/control-plane/facade/index.ts +3 -0
  252. package/src/runtime/control-plane/facade/plan-contract-store.ts +275 -42
  253. package/src/runtime/control-plane/facade/repository-work-admission.ts +147 -0
  254. package/src/runtime/control-plane/facade/requirement-authority.ts +83 -0
  255. package/src/runtime/control-plane/facade/semantic-admission.ts +205 -0
  256. package/src/runtime/control-plane/facade/suggested-actions.ts +5 -1
  257. package/src/runtime/control-plane/facade/types.ts +90 -10
  258. package/src/runtime/control-plane/facade/work-contract-store.ts +157 -261
  259. package/src/runtime/control-plane/facade/work-state-machine.ts +250 -0
  260. package/src/runtime/control-plane/generated-cache-retention.ts +271 -0
  261. package/src/runtime/control-plane/global-scheduler/config.ts +44 -0
  262. package/src/runtime/control-plane/global-scheduler/dispatch-capacity.ts +80 -0
  263. package/src/runtime/control-plane/global-scheduler/durable-admission.ts +46 -0
  264. package/src/runtime/control-plane/global-scheduler/maintenance.ts +152 -0
  265. package/src/runtime/control-plane/global-scheduler/projection-refresh.ts +84 -0
  266. package/src/runtime/control-plane/global-scheduler/reconciliation.ts +3 -3
  267. package/src/runtime/control-plane/global-scheduler/scheduler.ts +278 -543
  268. package/src/runtime/control-plane/global-scheduler/source-scan.ts +59 -0
  269. package/src/runtime/control-plane/global-scheduler/state.ts +88 -0
  270. package/src/runtime/control-plane/global-scheduler/worker-attachment.ts +57 -0
  271. package/src/runtime/control-plane/global-scheduler/worker-exit-decision.ts +38 -0
  272. package/src/runtime/control-plane/global-scheduler/worker-exit-reconciler.ts +175 -0
  273. package/src/runtime/control-plane/global-scheduler/worker-launch.ts +111 -0
  274. package/src/runtime/control-plane/global-scheduler/worker-lifecycle-store.ts +64 -0
  275. package/src/runtime/control-plane/global-scheduler/worker-lifecycle.ts +150 -0
  276. package/src/runtime/control-plane/global-scheduler/worker-process.ts +119 -0
  277. package/src/runtime/control-plane/global-scheduler/worker-stderr.ts +60 -0
  278. package/src/runtime/control-plane/launcher/chatgpt-work-binding-store.ts +63 -0
  279. package/src/runtime/control-plane/launcher/chatgpt-work-continuation.ts +365 -117
  280. package/src/runtime/control-plane/launcher/launch-reservation-store.ts +89 -0
  281. package/src/runtime/control-plane/launcher/thin-launcher.ts +244 -11
  282. package/src/runtime/control-plane/persistence/controller-home-migration.ts +487 -0
  283. package/src/runtime/control-plane/persistence/requirement-store.ts +0 -12
  284. package/src/runtime/control-plane/persistence/sqlite-store.ts +33 -2
  285. package/src/runtime/control-plane/release-retention.ts +62 -2
  286. package/src/runtime/control-plane/repo-actor/registry.ts +4 -2
  287. package/src/runtime/control-plane/routing/route-policy.ts +24 -21
  288. package/src/runtime/control-plane/routing/workspace-admission.ts +70 -0
  289. package/src/runtime/control-plane/runtime-status-client.ts +0 -2
  290. package/src/runtime/diagnostics/mcp-timing.ts +13 -0
  291. package/src/runtime/diagnostics/mcp-transport-benchmark.ts +129 -0
  292. package/src/runtime/diagnostics/performance.ts +24 -1
  293. package/src/runtime/evidence/event-ledger.ts +1 -1
  294. package/src/runtime/evidence/process-check-execution.ts +18 -0
  295. package/src/runtime/execution/jobs/child-reference.ts +6 -2
  296. package/src/runtime/execution/jobs/store.ts +58 -4
  297. package/src/runtime/execution/jobs/types.ts +1 -1
  298. package/src/runtime/execution/managed-workspace.ts +203 -1
  299. package/src/runtime/execution/process-runtime/check-facade.ts +51 -4
  300. package/src/runtime/execution/process-runtime/check-result.ts +88 -0
  301. package/src/runtime/execution/process-runtime/check-runner-sidecar.ts +7 -1
  302. package/src/runtime/execution/process-runtime/check-scheduling.ts +114 -0
  303. package/src/runtime/execution/process-runtime/command-facade.ts +367 -40
  304. package/src/runtime/execution/process-runtime/gc.ts +38 -6
  305. package/src/runtime/execution/process-runtime/lightweight-managed.ts +1201 -0
  306. package/src/runtime/execution/process-runtime/persisted-check.ts +51 -5
  307. package/src/runtime/execution/process-runtime/resource-claims.ts +10 -6
  308. package/src/runtime/execution/process-runtime/runtime.ts +53 -3
  309. package/src/runtime/execution/process-runtime/store.ts +1 -0
  310. package/src/runtime/execution/process-runtime/types.ts +4 -12
  311. package/src/runtime/execution/thin-harness/async-process.ts +12 -2
  312. package/src/runtime/execution/thin-harness/search-worker.ts +54 -5
  313. package/src/runtime/execution/work-activity.ts +21 -0
  314. package/src/runtime/execution/workers/executor.ts +18 -61
  315. package/src/runtime/gateway/mcp/execution-tools.ts +35 -1852
  316. package/src/runtime/gateway/mcp/legacy-ios-tool-adapter.ts +61 -0
  317. package/src/runtime/gateway/mcp/process-tools.ts +83 -37
  318. package/src/runtime/gateway/mcp/router.ts +186 -84
  319. package/src/runtime/gateway/mcp/runtime-tool-definitions.ts +565 -0
  320. package/src/runtime/gateway/mcp/runtime-tools.ts +2378 -1947
  321. package/src/runtime/plugins/app-store-connect-adapter.ts +216 -47
  322. package/src/runtime/plugins/browser-adapter.ts +2662 -829
  323. package/src/runtime/plugins/browser-automation-service.ts +10 -0
  324. package/src/runtime/plugins/browser-handoff-host.ts +2 -25
  325. package/src/runtime/plugins/browser-handoff.ts +110 -5
  326. package/src/runtime/plugins/browser-macos-bridge.ts +701 -63
  327. package/src/runtime/plugins/browser-manifest-surface.ts +603 -0
  328. package/src/runtime/plugins/browser-native-session-service.ts +222 -0
  329. package/src/runtime/plugins/browser-node-bridge.ts +6 -34
  330. package/src/runtime/plugins/browser-provider-registry.ts +109 -0
  331. package/src/runtime/plugins/browser-runtime-contract.ts +154 -0
  332. package/src/runtime/plugins/browser-runtime.ts +193 -0
  333. package/src/runtime/plugins/browser-session-authority.ts +332 -0
  334. package/src/runtime/plugins/browser-session-store.ts +121 -0
  335. package/src/runtime/plugins/browser-session-types.ts +98 -0
  336. package/src/runtime/plugins/capability-authorization-grants.ts +354 -0
  337. package/src/runtime/plugins/desktop-operator-registration.ts +10 -4
  338. package/src/runtime/plugins/external-adapter.ts +358 -3
  339. package/src/runtime/plugins/external-unix-socket.ts +7 -1
  340. package/src/runtime/plugins/first-party-registry.ts +2 -0
  341. package/src/runtime/plugins/github-adapter.ts +125 -0
  342. package/src/runtime/plugins/ios/agent-device-provider.ts +1 -1
  343. package/src/runtime/plugins/ios/agent-device-typed-provider.ts +52 -9
  344. package/src/runtime/plugins/ios/remote-xpc-hid.ts +1171 -0
  345. package/src/runtime/plugins/ios-adapter.ts +106 -16
  346. package/src/runtime/plugins/ios-agent-device.ts +234 -64
  347. package/src/runtime/plugins/ios-physical-device.ts +1143 -392
  348. package/src/runtime/plugins/lightweight-action.ts +153 -0
  349. package/src/runtime/plugins/local-system-adapter.ts +123 -6
  350. package/src/runtime/plugins/macos-capability-broker.ts +47 -9
  351. package/src/runtime/plugins/plugin-action-sidecar.ts +59 -0
  352. package/src/runtime/plugins/plugin-management-adapter.ts +49 -8
  353. package/src/runtime/plugins/resend-adapter.ts +1 -1
  354. package/src/runtime/plugins/store.ts +330 -33
  355. package/src/runtime/plugins/types.ts +38 -3
  356. package/src/runtime/plugins/xiaohongshu-publish.ts +515 -0
  357. package/src/runtime/projections/git-status-sampler.ts +16 -16
  358. package/src/runtime/projections/materialized-view.ts +28 -10
  359. package/src/runtime/recovery/maintenance-executor.ts +426 -25
  360. package/src/runtime/root/mcp-transport.ts +180 -10
  361. package/src/runtime/root/package-connector-service.ts +230 -10
  362. package/src/runtime/root/package-runtime-release.ts +143 -17
  363. package/src/runtime/root/package-runtime-service.ts +461 -22
  364. package/src/runtime/root/release-manifest.ts +144 -18
  365. package/src/runtime/root/release-materialize.ts +125 -32
  366. package/src/runtime/root/release-store.ts +48 -11
  367. package/src/runtime/root/runtime.ts +23 -5
  368. package/src/runtime/root/service.ts +100 -29
  369. package/src/runtime/root/types.ts +12 -0
  370. package/src/runtime/safe-tooling/ios-development.ts +321 -63
  371. package/src/runtime/shared/trusted-executable.ts +62 -0
  372. package/src/runtime/shared/trusted-node-executable.ts +48 -0
  373. package/src/runtime/standalone-recovery/core.ts +1079 -240
  374. package/src/runtime/standalone-recovery/entry.ts +100 -24
  375. package/src/runtime/standalone-recovery/installer.ts +20 -4
  376. package/src/runtime/standalone-recovery/service-labels.ts +2 -0
  377. package/src/runtime/standalone-recovery/watchdog-heartbeat.ts +160 -0
  378. package/src/runtime/workflow/schedules/browser-probe.ts +81 -3
  379. package/src/runtime/workflow/schedules/engine.ts +364 -202
  380. package/src/runtime/workflow/schedules/github-issue-watch.ts +158 -0
  381. package/src/runtime/workflow/schedules/settlement.ts +64 -17
  382. package/src/runtime/workflow/schedules/store.ts +209 -19
  383. package/src/runtime/workflow/schedules/types.ts +2 -4
  384. package/src/runtime/workflow/schedules/work-continuation.ts +26 -13
  385. package/src/testing/test-governance.ts +8 -40
  386. package/assets/reference-configs/heartbeat-triage.md +0 -57
  387. package/assets/templates/helpers/harness-trace-grade.sh +0 -150
  388. package/assets/templates/helpers/heartbeat-triage.sh +0 -361
  389. package/assets/templates/helpers/maintenance-triage.sh +0 -167
  390. package/docs/architecture/current/approved-target-architecture.zh-CN.md +0 -1501
  391. package/docs/architecture/current/architecture-invariants.md +0 -331
  392. package/docs/architecture/current/automation-and-schedule-engine.md +0 -459
  393. package/docs/architecture/current/codegraph-context-provider.md +0 -238
  394. package/docs/architecture/current/control-plane-authority-inventory.md +0 -94
  395. package/docs/architecture/current/controller-repository-decoupling.md +0 -148
  396. package/docs/architecture/current/dispatch-and-agent-strategy.md +0 -373
  397. package/docs/architecture/current/entity-model.md +0 -612
  398. package/docs/architecture/current/external-plugin-governance.md +0 -396
  399. package/docs/architecture/current/failure-recovery.md +0 -447
  400. package/docs/architecture/current/governance.md +0 -213
  401. package/docs/architecture/current/human-interaction-plane.md +0 -87
  402. package/docs/architecture/current/implementation-status.md +0 -128
  403. package/docs/architecture/current/job-and-run-lifecycle.md +0 -413
  404. package/docs/architecture/current/legacy-governance.md +0 -58
  405. package/docs/architecture/current/local-workspace-target-grants.md +0 -70
  406. package/docs/architecture/current/migration-roadmap.md +0 -105
  407. package/docs/architecture/current/multi-repository-execution.md +0 -371
  408. package/docs/architecture/current/operations-runbook.md +0 -45
  409. package/docs/architecture/current/peer-supercontroller-runtime.md +0 -32
  410. package/docs/architecture/current/personal-assistant-plugin-baseline.md +0 -206
  411. package/docs/architecture/current/repository-access-modes.md +0 -102
  412. package/docs/architecture/current/route-policy.md +0 -15
  413. package/docs/architecture/current/route-session-concurrency.md +0 -85
  414. package/docs/architecture/current/runtime-architecture-simplification.md +0 -214
  415. package/docs/architecture/current/runtime-directory-map.md +0 -49
  416. package/docs/architecture/current/runtime-health-and-resource-lifecycle.md +0 -85
  417. package/docs/architecture/current/scheduler-and-resource-claims.md +0 -422
  418. package/docs/architecture/current/session-aware-execution-and-authorization.md +0 -77
  419. package/docs/architecture/current/system-overview.md +0 -169
  420. package/docs/architecture/current/target-requirements-traceability.md +0 -202
  421. package/docs/architecture/current/thin-harness-governance-policy.md +0 -32
  422. package/docs/architecture/current/thin-harness-v1.md +0 -321
  423. package/docs/architecture/current/verification-and-release-gates.md +0 -391
  424. package/docs/forge-autonomous-goal-loop.md +0 -9
  425. package/docs/forge-provider-configuration.md +0 -7
  426. package/docs/operations/chatgpt-personal-assistant-runtime.md +0 -93
  427. package/docs/operations/gmail-assistant-routines.md +0 -186
  428. package/docs/operations/personal-assistant-operator-guide.md +0 -61
  429. package/docs/operations/provider-configuration.md +0 -31
  430. package/scripts/harness-trace-grade.sh +0 -150
  431. package/scripts/heartbeat-triage.sh +0 -361
  432. package/scripts/maintenance-triage.sh +0 -167
  433. package/src/cli/local-bridge/frontend/src/features/settings/SettingsView.tsx +0 -2
  434. package/src/cli/repositories/goal-registry.ts +0 -239
  435. package/src/runtime/assistant/action-proposals.ts +0 -279
  436. package/src/runtime/assistant/intent.ts +0 -395
  437. package/src/runtime/assistant/model-provider.ts +0 -460
  438. package/src/runtime/assistant/openapi.ts +0 -223
  439. package/src/runtime/assistant/policy.ts +0 -89
  440. package/src/runtime/assistant/readiness.ts +0 -258
  441. package/src/runtime/assistant/routine-runtime.ts +0 -477
  442. package/src/runtime/assistant/schedule-binding.ts +0 -171
  443. package/src/runtime/assistant/standing-grants.ts +0 -375
  444. package/src/runtime/assistant/store.ts +0 -243
  445. package/src/runtime/assistant/types.ts +0 -135
  446. package/src/runtime/control-plane/goal-loop/config-facade.ts +0 -700
  447. package/src/runtime/control-plane/goal-loop/config-store.ts +0 -570
  448. package/src/runtime/control-plane/goal-loop/config-types.ts +0 -213
  449. package/src/runtime/control-plane/goal-loop/executor-router.ts +0 -109
  450. package/src/runtime/control-plane/goal-loop/failure-taxonomy.ts +0 -149
  451. package/src/runtime/control-plane/goal-loop/goal-contract-store.ts +0 -304
  452. package/src/runtime/control-plane/goal-loop/goal-loop-engine.ts +0 -1001
  453. package/src/runtime/control-plane/goal-loop/handoff-packet.ts +0 -160
  454. package/src/runtime/control-plane/goal-loop/index.ts +0 -13
  455. package/src/runtime/control-plane/goal-loop/local-tools.ts +0 -290
  456. package/src/runtime/control-plane/goal-loop/policy-gates.ts +0 -203
  457. package/src/runtime/control-plane/goal-loop/provider-dispatch.ts +0 -93
  458. package/src/runtime/control-plane/goal-loop/provider-registry.ts +0 -545
  459. package/src/runtime/control-plane/goal-loop/types.ts +0 -378
  460. package/src/runtime/control-plane/startup-recovery.ts +0 -198
  461. package/src/runtime/gateway/mcp/resource-policy.ts +0 -186
  462. package/src/runtime/personal-assistant/gmail-triage-manager.ts +0 -231
  463. package/src/runtime/personal-assistant/reporting-runtime.ts +0 -344
  464. package/src/runtime/personal-assistant/triage-runtime.ts +0 -748
  465. package/src/runtime/workflow/findings/store.ts +0 -204
  466. package/src/runtime/workflow/findings/types.ts +0 -58
  467. package/src/runtime/workflow/portfolio/engine.ts +0 -20
  468. package/src/runtime/workflow/portfolio/store.ts +0 -185
  469. package/src/runtime/workflow/portfolio/types.ts +0 -29
@@ -0,0 +1,265 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ BUN_BIN="${BUN_BIN:-bun}"
6
+ RUNTIME_PORT="${FORGE_CLOUD_MCP_RUNTIME_PORT:-18765}"
7
+ GATEWAY_PORT="${FORGE_CLOUD_MCP_GATEWAY_PORT:-18767}"
8
+ HOLD_SECONDS="${FORGE_CLOUD_MCP_HOLD_SECONDS:-1500}"
9
+ TUNNEL_ID="${FORGE_CLOUD_TUNNEL_ID:-}"
10
+ TUNNEL_ALIAS="${FORGE_CLOUD_TUNNEL_ALIAS:-forge-cloud-ci}"
11
+ TUNNEL_CLIENT_VERSION="${FORGE_TUNNEL_CLIENT_VERSION:-v0.0.12}"
12
+ MCP_AUTH_MODE="${FORGE_CLOUD_MCP_AUTH_MODE:-none}"
13
+ RUNTIME_API_KEY="${FORGE_CLOUD_TUNNEL_RUNTIME_API_KEY:-}"
14
+
15
+ if [[ -z "$TUNNEL_ID" ]]; then
16
+ echo 'FORGE_CLOUD_TUNNEL_ID is required' >&2
17
+ exit 2
18
+ fi
19
+ if [[ -z "$RUNTIME_API_KEY" ]]; then
20
+ echo 'FORGE_CLOUD_TUNNEL_RUNTIME_API_KEY is required' >&2
21
+ exit 2
22
+ fi
23
+ if ! [[ "$HOLD_SECONDS" =~ ^[0-9]+$ ]]; then
24
+ echo 'FORGE_CLOUD_MCP_HOLD_SECONDS must be a non-negative integer' >&2
25
+ exit 2
26
+ fi
27
+
28
+ TMP_ROOT="$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/forge-cloud-mcp-e2e.XXXXXX")"
29
+ CONTROLLER_HOME="$TMP_ROOT/controller-home"
30
+ SETUP_LOG="$TMP_ROOT/setup.log"
31
+ INSTALL_JSON="$TMP_ROOT/runtime-install.json"
32
+ GATEWAY_LOG="$TMP_ROOT/gateway.log"
33
+ TUNNEL_ARCHIVE="$TMP_ROOT/tunnel-client.zip"
34
+ TUNNEL_DIR="$TMP_ROOT/tunnel-client"
35
+ TUNNEL_CLIENT="$TUNNEL_DIR/tunnel-client"
36
+ TUNNEL_STATUS_JSON="$TMP_ROOT/tunnel-status.json"
37
+ RUNTIME_PID=''
38
+ GATEWAY_PID=''
39
+
40
+ stop_pid() {
41
+ local pid="$1"
42
+ [[ -n "$pid" ]] || return 0
43
+ kill -0 "$pid" 2>/dev/null || return 0
44
+ kill "$pid" 2>/dev/null || true
45
+ for _ in $(seq 1 40); do
46
+ kill -0 "$pid" 2>/dev/null || return 0
47
+ sleep 0.25
48
+ done
49
+ kill -KILL "$pid" 2>/dev/null || true
50
+ for _ in $(seq 1 20); do
51
+ kill -0 "$pid" 2>/dev/null || return 0
52
+ sleep 0.1
53
+ done
54
+ return 1
55
+ }
56
+
57
+ tunnel_status_ready() {
58
+ "$TUNNEL_CLIENT" runtimes status "$TUNNEL_ALIAS" --json > "$TUNNEL_STATUS_JSON" 2>/dev/null || return 1
59
+ node - "$TUNNEL_STATUS_JSON" <<'NODE'
60
+ const fs = require('node:fs');
61
+ const status = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
62
+ process.exit(status.process_running === true && status.healthy === true && status.ready === true ? 0 : 1);
63
+ NODE
64
+ }
65
+
66
+ print_tunnel_status_summary() {
67
+ if [[ ! -s "$TUNNEL_STATUS_JSON" ]]; then
68
+ printf 'FORGE_CLOUD_TUNNEL_STATUS unavailable\n' >&2
69
+ return
70
+ fi
71
+ node - "$TUNNEL_STATUS_JSON" <<'NODE'
72
+ const fs = require('node:fs');
73
+ try {
74
+ const status = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
75
+ const flag = (name) => status[name] === true ? 'true' : status[name] === false ? 'false' : 'unknown';
76
+ console.error(`FORGE_CLOUD_TUNNEL_STATUS process_running=${flag('process_running')} healthy=${flag('healthy')} ready=${flag('ready')}`);
77
+ } catch {
78
+ console.error('FORGE_CLOUD_TUNNEL_STATUS unreadable');
79
+ }
80
+ NODE
81
+ }
82
+
83
+ wait_for_tunnel_ready() {
84
+ local attempts="$1"
85
+ for _ in $(seq 1 "$attempts"); do
86
+ if tunnel_status_ready; then
87
+ return 0
88
+ fi
89
+ sleep 1
90
+ done
91
+ print_tunnel_status_summary
92
+ return 1
93
+ }
94
+
95
+ cleanup() {
96
+ local original_status=$?
97
+ local cleanup_failed=0
98
+ trap - EXIT INT TERM
99
+ if [[ -x "$TUNNEL_CLIENT" ]]; then
100
+ "$TUNNEL_CLIENT" runtimes stop "$TUNNEL_ALIAS" --json >/dev/null 2>&1 || cleanup_failed=1
101
+ fi
102
+ stop_pid "$GATEWAY_PID" || cleanup_failed=1
103
+ stop_pid "$RUNTIME_PID" || cleanup_failed=1
104
+ unset RUNTIME_API_KEY
105
+ for _ in $(seq 1 20); do
106
+ rm -rf "$TMP_ROOT" 2>/dev/null || true
107
+ [[ ! -e "$TMP_ROOT" ]] && break
108
+ sleep 0.25
109
+ done
110
+ if [[ -e "$TMP_ROOT" ]]; then
111
+ echo 'FORGE_CLOUD_MCP_CLEANUP_FAILED: temporary root remained after bounded teardown' >&2
112
+ cleanup_failed=1
113
+ fi
114
+ if (( cleanup_failed != 0 )); then
115
+ exit 1
116
+ fi
117
+ exit "$original_status"
118
+ }
119
+ trap cleanup EXIT INT TERM
120
+
121
+ cd "$ROOT"
122
+
123
+ "$BUN_BIN" bin/forge.mjs mcp setup chatgpt \
124
+ --user-level \
125
+ --controller-home "$CONTROLLER_HOME" \
126
+ --host 127.0.0.1 \
127
+ --port "$RUNTIME_PORT" \
128
+ --local-controller-port $((RUNTIME_PORT + 1)) \
129
+ --connector-port "$GATEWAY_PORT" > "$SETUP_LOG"
130
+
131
+ # Package Runtime normally materializes its own persistent OAuth Connector from
132
+ # chatgpt.localEndpoint. This temporary Secure Tunnel benchmark owns the
133
+ # connector port itself with the explicit MCP_AUTH_MODE below, so suppress the
134
+ # package connector in this disposable Controller Home before installation.
135
+ MCP_LOCAL_CONFIG="$CONTROLLER_HOME/mcp/mcp.local.json"
136
+ node - "$MCP_LOCAL_CONFIG" <<'NODE'
137
+ const fs = require('node:fs');
138
+ const path = process.argv[2];
139
+ const config = JSON.parse(fs.readFileSync(path, 'utf8'));
140
+ if (!config.chatgpt || typeof config.chatgpt.localEndpoint !== 'string') {
141
+ console.error('FORGE_CLOUD_MCP_SETUP_LOCAL_ENDPOINT_MISSING');
142
+ process.exit(1);
143
+ }
144
+ delete config.chatgpt.localEndpoint;
145
+ fs.writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
146
+ NODE
147
+
148
+ "$BUN_BIN" bin/forge.mjs repo register "$ROOT" \
149
+ --controller-home "$CONTROLLER_HOME" \
150
+ --json > "$TMP_ROOT/repository.json"
151
+
152
+ "$BUN_BIN" bin/forge.mjs runtime service install-package \
153
+ --controller-home "$CONTROLLER_HOME" \
154
+ --host 127.0.0.1 \
155
+ --port "$RUNTIME_PORT" \
156
+ --portable > "$INSTALL_JSON"
157
+ RUNTIME_PID="$(node -e "const x=require(process.argv[1]); const pid=x?.pid; if(!Number.isInteger(pid)||pid<=0) process.exit(2); process.stdout.write(String(pid))" "$INSTALL_JSON")"
158
+
159
+ curl --fail --silent --show-error \
160
+ --retry 30 --retry-delay 1 --retry-connrefused \
161
+ "http://127.0.0.1:${RUNTIME_PORT}/ready" > "$TMP_ROOT/runtime-ready.json"
162
+
163
+ FORGE_CONTROLLER_LIFECYCLE_OWNER=1 \
164
+ "$BUN_BIN" bin/forge.mjs mcp serve \
165
+ --repo "$ROOT" \
166
+ --controller-home "$CONTROLLER_HOME" \
167
+ --transport http \
168
+ --host 127.0.0.1 \
169
+ --port "$GATEWAY_PORT" \
170
+ --profile controller \
171
+ --auth "$MCP_AUTH_MODE" > "$GATEWAY_LOG" 2>&1 &
172
+ GATEWAY_PID=$!
173
+
174
+ case "$MCP_AUTH_MODE" in
175
+ oauth)
176
+ for _ in $(seq 1 30); do
177
+ if curl --fail --silent "http://127.0.0.1:${GATEWAY_PORT}/.well-known/oauth-authorization-server" > "$TMP_ROOT/local-oauth.json" 2>/dev/null; then
178
+ break
179
+ fi
180
+ if ! kill -0 "$GATEWAY_PID" 2>/dev/null; then
181
+ cat "$GATEWAY_LOG" >&2
182
+ exit 1
183
+ fi
184
+ sleep 1
185
+ done
186
+ test -s "$TMP_ROOT/local-oauth.json"
187
+ ;;
188
+ none)
189
+ MCP_INITIALIZE_HEADERS="$TMP_ROOT/mcp-initialize.headers"
190
+ MCP_INITIALIZE_BODY="$TMP_ROOT/mcp-initialize.body"
191
+ MCP_INITIALIZE_PAYLOAD='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"forge-cloud-readiness","version":"1"}}}'
192
+ for _ in $(seq 1 30); do
193
+ if curl --fail --silent --show-error \
194
+ --dump-header "$MCP_INITIALIZE_HEADERS" \
195
+ --output "$MCP_INITIALIZE_BODY" \
196
+ --request POST \
197
+ --header 'content-type: application/json' \
198
+ --header 'accept: application/json, text/event-stream' \
199
+ --data "$MCP_INITIALIZE_PAYLOAD" \
200
+ "http://127.0.0.1:${GATEWAY_PORT}/mcp" 2>/dev/null \
201
+ && grep -Eiq '^mcp-session-id:[[:space:]]*[^[:space:]]+' "$MCP_INITIALIZE_HEADERS" \
202
+ && grep -q 'forge-mcp' "$MCP_INITIALIZE_BODY"; then
203
+ break
204
+ fi
205
+ if ! kill -0 "$GATEWAY_PID" 2>/dev/null; then
206
+ cat "$GATEWAY_LOG" >&2
207
+ exit 1
208
+ fi
209
+ sleep 1
210
+ done
211
+ grep -Eiq '^mcp-session-id:[[:space:]]*[^[:space:]]+' "$MCP_INITIALIZE_HEADERS"
212
+ grep -q 'forge-mcp' "$MCP_INITIALIZE_BODY"
213
+ ;;
214
+ bearer)
215
+ echo 'FORGE_CLOUD_MCP_AUTH_MODE=bearer is not supported by the unauthenticated Secure Tunnel connector path; use oauth or none.' >&2
216
+ exit 2
217
+ ;;
218
+ *)
219
+ echo "unsupported FORGE_CLOUD_MCP_AUTH_MODE: $MCP_AUTH_MODE" >&2
220
+ exit 2
221
+ ;;
222
+ esac
223
+
224
+ mkdir -p "$TUNNEL_DIR"
225
+ TUNNEL_CLIENT_ASSET="tunnel-client-${TUNNEL_CLIENT_VERSION}-linux-amd64.zip"
226
+ curl -LfsS \
227
+ "https://github.com/openai/tunnel-client/releases/download/${TUNNEL_CLIENT_VERSION}/${TUNNEL_CLIENT_ASSET}" \
228
+ -o "$TUNNEL_ARCHIVE"
229
+ unzip -q "$TUNNEL_ARCHIVE" -d "$TUNNEL_DIR"
230
+ chmod +x "$TUNNEL_CLIENT" "$TUNNEL_DIR/cloudflared"
231
+
232
+ FORGE_RUNTIME_API_KEY="$RUNTIME_API_KEY" \
233
+ "$TUNNEL_CLIENT" runtimes connect \
234
+ --alias "$TUNNEL_ALIAS" \
235
+ --tunnel-id "$TUNNEL_ID" \
236
+ --runtime-api-key 'env:FORGE_RUNTIME_API_KEY' \
237
+ --mcp-server-url "http://127.0.0.1:${GATEWAY_PORT}/mcp" \
238
+ --profile "$TUNNEL_ALIAS" \
239
+ --profile-dir "$TMP_ROOT/tunnel-profiles" \
240
+ --json > "$TMP_ROOT/tunnel-connect.json"
241
+
242
+ if ! wait_for_tunnel_ready 30; then
243
+ echo 'FORGE_CLOUD_TUNNEL_NOT_READY' >&2
244
+ exit 1
245
+ fi
246
+
247
+ printf 'FORGE_CLOUD_TUNNEL_ID=%s\n' "$TUNNEL_ID"
248
+ printf 'FORGE_CLOUD_TUNNEL_ALIAS=%s\n' "$TUNNEL_ALIAS"
249
+ printf 'FORGE_CLOUD_MCP_RUN_ID=%s\n' "${GITHUB_RUN_ID:-unknown}"
250
+ printf 'FORGE_CLOUD_MCP_RUNNER_OS=%s\n' "${RUNNER_OS:-unknown}"
251
+ printf 'FORGE_CLOUD_MCP_RUNNER_ARCH=%s\n' "${RUNNER_ARCH:-unknown}"
252
+ printf 'FORGE_CLOUD_MCP_AUTH_MODE=%s\n' "$MCP_AUTH_MODE"
253
+
254
+ elapsed=0
255
+ while (( elapsed < HOLD_SECONDS )); do
256
+ kill -0 "$RUNTIME_PID" 2>/dev/null || { echo 'runtime exited' >&2; exit 1; }
257
+ kill -0 "$GATEWAY_PID" 2>/dev/null || { cat "$GATEWAY_LOG" >&2; exit 1; }
258
+ if ! wait_for_tunnel_ready 5; then
259
+ echo 'FORGE_CLOUD_TUNNEL_LOST_READINESS' >&2
260
+ exit 1
261
+ fi
262
+ sleep 60
263
+ elapsed=$((elapsed + 60))
264
+ printf 'FORGE_CLOUD_MCP_HEARTBEAT elapsed=%ss tunnel_id=%s\n' "$elapsed" "$TUNNEL_ID"
265
+ done
@@ -1,280 +1,5 @@
1
- import { existsSync, readFileSync, readdirSync } from "fs";
2
- import { join, resolve } from "path";
3
- import { loadWorkflowContract, resolveWorkflowContractForRepo } from "./workflow-contract.ts";
1
+ #!/usr/bin/env bun
2
+ export * from "../assets/templates/helpers/inspect-project-state";
3
+ import { runTrackedForgeHelper } from "./lib/run-forge-helper";
4
4
 
5
- type Mode = "initialize" | "migrate" | "audit" | "repair";
6
-
7
- type InspectionResult = {
8
- repo: string;
9
- mode: Mode;
10
- legacy_contract_version: string;
11
- drift_signals: string[];
12
- required_decisions: string[];
13
- safe_defaults: string[];
14
- detected_paths: string[];
15
- upgrade_plan: UpgradePlanItem[];
16
- };
17
-
18
- type UpgradePlanItem = {
19
- id: string;
20
- signal: string;
21
- action: string;
22
- risk: string;
23
- ownership: string;
24
- paths: string[];
25
- target_paths?: string[];
26
- summary: string;
27
- };
28
-
29
- function parseArgs(argv: string[]) {
30
- let repo = process.cwd();
31
- let format: "json" | "text" = "json";
32
-
33
- for (let i = 0; i < argv.length; i += 1) {
34
- const arg = argv[i];
35
- if (arg === "--repo") {
36
- repo = argv[i + 1] ? resolve(argv[i + 1]) : repo;
37
- i += 1;
38
- continue;
39
- }
40
- if (arg === "--format") {
41
- format = argv[i + 1] === "text" ? "text" : "json";
42
- i += 1;
43
- }
44
- }
45
-
46
- return { repo, format };
47
- }
48
-
49
- function fileHasContent(path: string, pattern: RegExp): boolean {
50
- if (!existsSync(path)) return false;
51
- return pattern.test(readFileSync(path, "utf-8"));
52
- }
53
-
54
- function jsonPathExists(path: string, keys: string[]): boolean {
55
- if (!existsSync(path)) return false;
56
- try {
57
- let value: unknown = JSON.parse(readFileSync(path, "utf-8"));
58
- for (const key of keys) {
59
- if (!value || typeof value !== "object" || !(key in value)) return false;
60
- value = (value as Record<string, unknown>)[key];
61
- }
62
- return true;
63
- } catch {
64
- return false;
65
- }
66
- }
67
-
68
- function hasAnyPath(repo: string, relPaths: string[]): boolean {
69
- return relPaths.some((relPath) => existsSync(join(repo, relPath)));
70
- }
71
-
72
- function hasCustomClaudeHooks(repo: string): boolean {
73
- const hooksDir = join(repo, ".claude", "hooks");
74
- if (!existsSync(hooksDir)) return false;
75
- try {
76
- return readdirSync(hooksDir).some((entry) => /^custom-.*\.sh$/.test(entry));
77
- } catch {
78
- return false;
79
- }
80
- }
81
-
82
- function detectMode(repo: string): Mode {
83
- const hasTasks = existsSync(join(repo, "tasks"));
84
- const hasPlan = existsSync(join(repo, "plans"));
85
- const hasLegacyDocs =
86
- existsSync(join(repo, "docs", "plan.md")) || existsSync(join(repo, "docs", "TODO.md"));
87
- const hasLegacySkillFactory =
88
- existsSync(join(repo, ".claude", "skill-factory")) ||
89
- existsSync(join(repo, "scripts", "skill-factory-check.sh")) ||
90
- existsSync(join(repo, "scripts", "skill-factory-create.sh")) ||
91
- existsSync(join(repo, ".ai", "hooks", "memory-intake.sh")) ||
92
- existsSync(join(repo, ".ai", "hooks", "skill-factory-session-end.sh"));
93
-
94
- if (hasTasks && hasPlan) return "audit";
95
- if (hasLegacyDocs || hasLegacySkillFactory) return "migrate";
96
- if (!hasTasks && !hasPlan && !hasLegacyDocs) return "initialize";
97
- return "repair";
98
- }
99
-
100
- export function inspectRepo(repo: string): InspectionResult {
101
- const contract = loadWorkflowContract(resolveWorkflowContractForRepo(repo));
102
- const latestContract = loadWorkflowContract();
103
- const upgradeActions = latestContract.migrations.upgrade?.actions ?? contract.migrations.upgrade?.actions ?? [];
104
- const detectedPathSet = new Set(
105
- [...new Set([...contract.migrations.legacyPaths, ...latestContract.migrations.legacyPaths])]
106
- .map((relPath) => relPath)
107
- .filter((relPath) => existsSync(join(repo, relPath)))
108
- );
109
- const driftSignals: string[] = [];
110
- const requiredDecisions: string[] = [];
111
- const safeDefaults = [
112
- "Preserve repo-local tasks-first workflow",
113
- "Archive uncertain legacy content instead of overwriting it",
114
- "Delete only manifest-owned known_generated legacy files",
115
- "Distill repeated corrections into tasks/lessons.md and hidden contracts into docs/researches/",
116
- ];
117
-
118
- const runtimeManifest = join(repo, contract.artifacts.runtimeManifest);
119
- const todoFile = join(repo, contract.documents.deferredGoalLedger ?? contract.documents.taskChecklist ?? "tasks/todos.md");
120
- const legacySingularTodoFile = join(repo, "tasks", "todo.md");
121
- const legacyTaskSprintDir = join(repo, "tasks", "sprints");
122
- const policyFile = join(repo, ".ai", "harness", "policy.json");
123
- const generatedClaudeHookPaths = [
124
- ".claude/hooks/run-hook.sh",
125
- ".claude/hooks/finalize-handoff.sh",
126
- ".claude/hooks/session-start-context.sh",
127
- ".claude/hooks/hook-input.sh",
128
- ".claude/hooks/lib/workflow-state.sh",
129
- ".claude/hooks/lib/session-state.sh",
130
- ];
131
- const ignoredReferenceOrSecretPaths = [
132
- "_ref",
133
- "_ops",
134
- ];
135
-
136
- if (!existsSync(runtimeManifest)) {
137
- driftSignals.push("missing-runtime-contract-manifest");
138
- }
139
- if (existsSync(policyFile) && !jsonPathExists(policyFile, ["upgrade", "strategy_version"])) {
140
- driftSignals.push("policy-missing-upgrade-strategy");
141
- }
142
- if (existsSync(join(repo, "docs", "plan.md"))) {
143
- driftSignals.push("legacy-docs-plan");
144
- }
145
- if (existsSync(join(repo, "docs", "TODO.md"))) {
146
- driftSignals.push("legacy-docs-todo");
147
- }
148
- if (existsSync(legacySingularTodoFile) && legacySingularTodoFile !== todoFile) {
149
- driftSignals.push("legacy-singular-todo-file");
150
- }
151
- if (existsSync(legacyTaskSprintDir)) {
152
- driftSignals.push("legacy-task-sprint-prds");
153
- }
154
- if (
155
- existsSync(join(repo, ".claude", "skill-factory")) ||
156
- existsSync(join(repo, "scripts", "skill-factory-check.sh")) ||
157
- existsSync(join(repo, "scripts", "skill-factory-create.sh")) ||
158
- existsSync(join(repo, ".ai", "hooks", "memory-intake.sh")) ||
159
- existsSync(join(repo, ".ai", "hooks", "skill-factory-session-end.sh"))
160
- ) {
161
- driftSignals.push("legacy-skill-factory-surface");
162
- }
163
- if (existsSync(join(repo, "docs", "PROGRESS.md"))) {
164
- driftSignals.push("legacy-docs-progress");
165
- }
166
- if (
167
- existsSync(todoFile) &&
168
- (
169
- !fileHasContent(todoFile, /^# Deferred Goal Ledger\s*$/m) ||
170
- !fileHasContent(todoFile, /^\> \*\*Status\*\*:\s*Backlog\s*$/m)
171
- )
172
- ) {
173
- driftSignals.push("legacy-task-checklist-format");
174
- }
175
- if (hasAnyPath(repo, generatedClaudeHookPaths)) {
176
- driftSignals.push("stale-generated-claude-hook-shims");
177
- }
178
-
179
- if (driftSignals.includes("missing-runtime-contract-manifest")) {
180
- requiredDecisions.push("Install runtime workflow contract manifest");
181
- }
182
- if (driftSignals.includes("policy-missing-upgrade-strategy")) {
183
- requiredDecisions.push("Merge versioned upgrade strategy into harness policy");
184
- }
185
- if (driftSignals.includes("legacy-docs-plan") || driftSignals.includes("legacy-docs-todo")) {
186
- requiredDecisions.push("Run legacy document migration before template refresh");
187
- }
188
- if (driftSignals.includes("legacy-singular-todo-file")) {
189
- requiredDecisions.push("Migrate legacy tasks/todo.md into tasks/todos.md");
190
- }
191
- if (driftSignals.includes("legacy-task-sprint-prds")) {
192
- requiredDecisions.push("Move legacy tasks/sprints/*.sprint.md into plans/sprints/*.sprint.md");
193
- }
194
- if (driftSignals.includes("legacy-docs-progress")) {
195
- requiredDecisions.push("Archive legacy docs/PROGRESS.md into research report or changelog surfaces");
196
- }
197
- if (driftSignals.includes("legacy-skill-factory-surface")) {
198
- requiredDecisions.push("Remove repo-local Skill Factory and auto-memory surfaces");
199
- }
200
- if (driftSignals.includes("stale-generated-claude-hook-shims")) {
201
- requiredDecisions.push("Remove manifest-owned generated .claude/hooks shims and keep .ai/hooks as source of truth");
202
- }
203
-
204
- const upgradeSignals = new Set(driftSignals);
205
- if (hasCustomClaudeHooks(repo)) {
206
- upgradeSignals.add("custom-claude-hooks");
207
- }
208
- if (hasAnyPath(repo, ignoredReferenceOrSecretPaths)) {
209
- upgradeSignals.add("ignored-reference-or-secret-surfaces");
210
- }
211
- const upgradePlan = upgradeActions
212
- .filter((action) => upgradeSignals.has(action.signal))
213
- .map((action) => {
214
- for (const relPath of action.paths) {
215
- if (!relPath.includes("*") && existsSync(join(repo, relPath))) {
216
- detectedPathSet.add(relPath);
217
- }
218
- }
219
- return {
220
- id: action.id,
221
- signal: action.signal,
222
- action: action.action,
223
- risk: action.risk,
224
- ownership: action.ownership,
225
- paths: action.paths,
226
- target_paths: action.targetPaths,
227
- summary: action.summary,
228
- };
229
- });
230
-
231
- let legacyContractVersion = "current-v1";
232
- if (driftSignals.includes("legacy-docs-plan") || driftSignals.includes("legacy-docs-todo")) {
233
- legacyContractVersion = "pre-tasks-first";
234
- } else if (driftSignals.includes("missing-runtime-contract-manifest")) {
235
- legacyContractVersion = "tasks-first-without-contract-manifest";
236
- }
237
-
238
- return {
239
- repo,
240
- mode: detectMode(repo),
241
- legacy_contract_version: legacyContractVersion,
242
- drift_signals: driftSignals,
243
- required_decisions: requiredDecisions,
244
- safe_defaults: safeDefaults,
245
- detected_paths: [...detectedPathSet].sort(),
246
- upgrade_plan: upgradePlan,
247
- };
248
- }
249
-
250
- function renderText(result: InspectionResult): string {
251
- const lines = [
252
- `repo: ${result.repo}`,
253
- `mode: ${result.mode}`,
254
- `legacy_contract_version: ${result.legacy_contract_version}`,
255
- `drift_signals: ${result.drift_signals.join(", ") || "(none)"}`,
256
- `required_decisions: ${result.required_decisions.join(" | ") || "(none)"}`,
257
- `safe_defaults: ${result.safe_defaults.join(" | ")}`,
258
- `upgrade_plan:`,
259
- ];
260
- if (result.upgrade_plan.length === 0) {
261
- lines.push("- (none)");
262
- } else {
263
- for (const item of result.upgrade_plan) {
264
- const target = item.target_paths?.length ? ` -> ${item.target_paths.join(", ")}` : "";
265
- lines.push(
266
- `- ${item.action} ${item.id} [${item.risk}, ${item.ownership}]: ${item.paths.join(", ")}${target}`
267
- );
268
- }
269
- }
270
- return lines.join("\n");
271
- }
272
-
273
- const { repo, format } = parseArgs(process.argv.slice(2));
274
- const result = inspectRepo(repo);
275
-
276
- if (format === "text") {
277
- console.log(renderText(result));
278
- } else {
279
- console.log(JSON.stringify(result, null, 2));
280
- }
5
+ if (import.meta.main) runTrackedForgeHelper("inspect-project-state.ts");
@@ -44,6 +44,22 @@ const recoveryTunnelService = launchdService(
44
44
  'RECOVERY_TUNNEL_SERVICE',
45
45
  );
46
46
  if (Boolean(recoveryTunnelService) !== Boolean(recoveryPublicUrl)) throw new Error('RECOVERY_PUBLIC_URL_AND_TUNNEL_SERVICE_MUST_BE_CONFIGURED_TOGETHER');
47
+ const primaryConnectorLocalUrl = endpointOption('--primary-connector-local-url');
48
+ const primaryConnectorBase = launchdService(
49
+ option('--primary-connector-service-label'),
50
+ option('--primary-connector-service-plist'),
51
+ 'RECOVERY_PRIMARY_CONNECTOR',
52
+ );
53
+ if (primaryConnectorLocalUrl && !primaryConnectorBase) throw new Error('RECOVERY_PRIMARY_CONNECTOR_LABEL_REQUIRED_FOR_LOCAL_URL');
54
+ const primaryConnectorService = primaryConnectorBase
55
+ ? { ...primaryConnectorBase, ...(primaryConnectorLocalUrl ? { localMcpUrl: primaryConnectorLocalUrl } : {}) }
56
+ : undefined;
57
+ const primaryPublicTunnelService = launchdService(
58
+ option('--primary-tunnel-service-label'),
59
+ option('--primary-tunnel-service-plist'),
60
+ 'RECOVERY_PRIMARY_TUNNEL',
61
+ );
62
+ if (primaryPublicTunnelService && !primaryConnectorService) throw new Error('RECOVERY_PRIMARY_CONNECTOR_REQUIRED_FOR_PRIMARY_TUNNEL');
47
63
 
48
64
  const result = await installStandaloneRecovery({
49
65
  controllerHome,
@@ -54,6 +70,8 @@ const result = await installStandaloneRecovery({
54
70
  publicMcpUrl,
55
71
  recoveryPublicUrl,
56
72
  recoveryTunnelService,
73
+ primaryPublicTunnelService,
74
+ primaryConnectorService,
57
75
  });
58
76
  const config = result.config;
59
77
  console.log(JSON.stringify({
@@ -70,5 +88,11 @@ console.log(JSON.stringify({
70
88
  recoveryTunnelService: config.recoveryTunnelService
71
89
  ? { platform: config.recoveryTunnelService.platform, label: config.recoveryTunnelService.label, plistPath: config.recoveryTunnelService.plistPath }
72
90
  : undefined,
91
+ primaryConnectorService: config.primaryConnectorService
92
+ ? { platform: config.primaryConnectorService.platform, label: config.primaryConnectorService.label, plistPath: config.primaryConnectorService.plistPath, localMcpUrl: config.primaryConnectorService.localMcpUrl }
93
+ : undefined,
94
+ primaryPublicTunnelService: config.primaryPublicTunnelService
95
+ ? { platform: config.primaryPublicTunnelService.platform, label: config.primaryPublicTunnelService.label, plistPath: config.primaryPublicTunnelService.plistPath }
96
+ : undefined,
73
97
  },
74
98
  }, null, 2));