@moretea-labs/forge 1.7.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 (175) hide show
  1. package/AGENTS.md +2 -0
  2. package/CHANGELOG.md +13 -0
  3. package/CLAUDE.md +2 -0
  4. package/THIRD_PARTY_NOTICES.md +1 -1
  5. package/agents/openai.yaml +1 -1
  6. package/assets/partials-agents/02-operating-mode.partial.md +2 -0
  7. package/assets/plugin-registry.v1.json +3 -3
  8. package/assets/skill-version.json +2 -2
  9. package/assets/templates/helpers/check-architecture-sync.sh +17 -0
  10. package/assets/templates/helpers/inspect-project-state.ts +8 -6
  11. package/assets/templates/helpers/migrate-workflow-docs.ts +9 -7
  12. package/assets/templates/helpers/workflow-contract.ts +5 -1
  13. package/docs/architecture/CURRENT.md +12 -4
  14. package/docs/forge-plugin-management.md +1 -1
  15. package/docs/operations/controller-performance-and-502.md +19 -0
  16. package/docs/operations/homebrew.md +2 -2
  17. package/package.json +5 -2
  18. package/scripts/architecture-event.ts +2 -820
  19. package/scripts/architecture-queue.sh +2 -645
  20. package/scripts/archive-architecture-request.sh +2 -242
  21. package/scripts/archive-workflow.sh +1 -291
  22. package/scripts/benchmark-work-efficiency.ts +0 -0
  23. package/scripts/capability-config.ts +2 -392
  24. package/scripts/capability-resolver.ts +2 -503
  25. package/scripts/capture-plan.sh +1 -332
  26. package/scripts/check-agent-tooling.sh +2 -1531
  27. package/scripts/check-architecture-sync.sh +2 -302
  28. package/scripts/check-brain-manifest.sh +2 -253
  29. package/scripts/check-context-files.sh +2 -47
  30. package/scripts/check-deploy-sql-order.sh +2 -115
  31. package/scripts/check-runtime-architecture.mjs +243 -16
  32. package/scripts/check-skill-version.ts +3 -191
  33. package/scripts/check-source-duplication.mjs +61 -0
  34. package/scripts/check-stable-baseline.ts +0 -0
  35. package/scripts/check-task-sync.sh +2 -63
  36. package/scripts/check-task-workflow.sh +2 -1000
  37. package/scripts/codex-handoff-resume.sh +2 -267
  38. package/scripts/context-contract-sync.sh +2 -514
  39. package/scripts/contract-run.ts +2 -463
  40. package/scripts/contract-worktree.sh +1 -702
  41. package/scripts/ensure-task-workflow.sh +1 -1192
  42. package/scripts/inspect-project-state.ts +4 -279
  43. package/scripts/lib/project-init-lib.sh +7 -2
  44. package/scripts/lib/run-forge-helper.sh +19 -0
  45. package/scripts/lib/run-forge-helper.ts +26 -0
  46. package/scripts/migrate-project-template.sh +1 -33
  47. package/scripts/migrate-workflow-docs.ts +4 -412
  48. package/scripts/new-plan.sh +1 -180
  49. package/scripts/new-spec.sh +1 -47
  50. package/scripts/new-sprint.sh +1 -46
  51. package/scripts/plan-to-todo.sh +1 -771
  52. package/scripts/prepare-codex-handoff.sh +2 -201
  53. package/scripts/prepare-handoff.sh +1 -78
  54. package/scripts/refresh-current-status.sh +2 -467
  55. package/scripts/run-governed-gate.ts +3 -0
  56. package/scripts/select-agent-context-blocks.sh +2 -64
  57. package/scripts/ship-worktrees.sh +1 -531
  58. package/scripts/sprint-backlog.sh +1 -834
  59. package/scripts/stage-runtime-release.ts +2 -1
  60. package/scripts/summarize-failures.sh +2 -123
  61. package/scripts/switch-plan.sh +1 -150
  62. package/scripts/sync-brain-docs.sh +2 -379
  63. package/scripts/sync-generated-authority.mjs +175 -0
  64. package/scripts/verify-contract.sh +2 -593
  65. package/scripts/verify-sprint.sh +1 -500
  66. package/scripts/workflow-contract.ts +4 -201
  67. package/scripts/workstream-sync.sh +2 -261
  68. package/src/cli/agent-jobs/executor-health.ts +1 -1
  69. package/src/cli/commands/plugin.ts +12 -3
  70. package/src/cli/controller/check-runner.ts +7 -2
  71. package/src/cli/controller/context-pack.ts +46 -21
  72. package/src/cli/github/contracts.ts +16 -0
  73. package/src/cli/github/github.ts +2 -16
  74. package/src/cli/github/session.ts +2 -1
  75. package/src/cli/local-bridge/facade-api.ts +37 -47
  76. package/src/cli/local-bridge/server.ts +2 -2
  77. package/src/cli/mcp/legacy-tool-service.ts +10 -33
  78. package/src/cli/mcp/post-finalize-work-attribution.ts +150 -0
  79. package/src/cli/mcp/repository-tools.ts +85 -89
  80. package/src/cli/mcp/server.ts +57 -13
  81. package/src/cli/mcp/tool-contract.ts +14 -0
  82. package/src/cli/mcp/toolset.ts +2 -2
  83. package/src/cli/mcp/transports/http.ts +23 -0
  84. package/src/cli/repositories/command-classifier.ts +2 -2
  85. package/src/cli/repositories/command-executor.ts +24 -6
  86. package/src/cli/repositories/repository-snapshot.ts +5 -2
  87. package/src/cli/repositories/structured-git.ts +57 -3
  88. package/src/cli/repository/inspector.ts +11 -3
  89. package/src/runtime/context/generic-lsp-provider.ts +1 -1
  90. package/src/runtime/context/semantic-navigation-contract.ts +61 -0
  91. package/src/runtime/context/semantic-navigation.ts +9 -61
  92. package/src/runtime/control-plane/execution/direct-edit-work-completion.ts +18 -25
  93. package/src/runtime/control-plane/execution/repository-work-attribution.ts +106 -0
  94. package/src/runtime/control-plane/execution/retained-work-resume.ts +203 -0
  95. package/src/runtime/control-plane/execution/work-completion-authority.ts +58 -0
  96. package/src/runtime/control-plane/execution/work-evidence-policy.ts +200 -0
  97. package/src/runtime/control-plane/execution/work-execution-support.ts +386 -0
  98. package/src/runtime/control-plane/execution/work-finalization-service.ts +1913 -0
  99. package/src/runtime/control-plane/execution/work-handle-authority.ts +96 -0
  100. package/src/runtime/control-plane/execution/work-handle-store.ts +1 -1
  101. package/src/runtime/control-plane/execution/work-operation-service.ts +468 -0
  102. package/src/runtime/control-plane/execution/work-path-scope.ts +37 -0
  103. package/src/runtime/control-plane/execution/work-preparation-service.ts +479 -0
  104. package/src/runtime/control-plane/execution/work-process-evidence.ts +129 -0
  105. package/src/runtime/control-plane/execution/work-task-receipt.ts +4 -43
  106. package/src/runtime/control-plane/execution/work-terminal-cleanup.ts +13 -3
  107. package/src/runtime/control-plane/execution/work-verification-context.ts +56 -0
  108. package/src/runtime/control-plane/execution/work-verification-service.ts +388 -0
  109. package/src/runtime/control-plane/execution/work-verification-snapshot.ts +5 -1
  110. package/src/runtime/control-plane/facade/controller-round-relay.ts +164 -37
  111. package/src/runtime/control-plane/facade/controller-session-store.ts +183 -24
  112. package/src/runtime/control-plane/facade/goal-workloop-access.ts +15 -1
  113. package/src/runtime/control-plane/facade/goal-workloop.ts +329 -148
  114. package/src/runtime/control-plane/facade/index.ts +2 -0
  115. package/src/runtime/control-plane/facade/plan-contract-store.ts +90 -22
  116. package/src/runtime/control-plane/facade/repository-work-admission.ts +147 -0
  117. package/src/runtime/control-plane/facade/requirement-authority.ts +83 -0
  118. package/src/runtime/control-plane/facade/types.ts +68 -5
  119. package/src/runtime/control-plane/facade/work-contract-store.ts +3 -209
  120. package/src/runtime/control-plane/facade/work-state-machine.ts +250 -0
  121. package/src/runtime/control-plane/global-scheduler/maintenance.ts +14 -7
  122. package/src/runtime/control-plane/global-scheduler/scheduler.ts +5 -1
  123. package/src/runtime/control-plane/launcher/chatgpt-work-binding-store.ts +13 -0
  124. package/src/runtime/control-plane/launcher/chatgpt-work-continuation.ts +15 -6
  125. package/src/runtime/control-plane/launcher/launch-reservation-store.ts +54 -5
  126. package/src/runtime/control-plane/launcher/thin-launcher.ts +56 -7
  127. package/src/runtime/control-plane/persistence/requirement-store.ts +0 -12
  128. package/src/runtime/control-plane/repo-actor/registry.ts +4 -2
  129. package/src/runtime/control-plane/routing/route-policy.ts +18 -6
  130. package/src/runtime/control-plane/routing/workspace-admission.ts +70 -0
  131. package/src/runtime/evidence/process-check-execution.ts +18 -0
  132. package/src/runtime/execution/jobs/child-reference.ts +6 -2
  133. package/src/runtime/execution/process-runtime/check-result.ts +53 -18
  134. package/src/runtime/execution/process-runtime/check-runner-sidecar.ts +7 -1
  135. package/src/runtime/execution/process-runtime/command-facade.ts +39 -17
  136. package/src/runtime/execution/process-runtime/lightweight-managed.ts +20 -3
  137. package/src/runtime/execution/process-runtime/persisted-check.ts +4 -1
  138. package/src/runtime/execution/process-runtime/runtime.ts +10 -0
  139. package/src/runtime/execution/process-runtime/types.ts +2 -12
  140. package/src/runtime/execution/work-activity.ts +21 -0
  141. package/src/runtime/execution/workers/executor.ts +18 -13
  142. package/src/runtime/gateway/mcp/execution-tools.ts +35 -2930
  143. package/src/runtime/gateway/mcp/legacy-ios-tool-adapter.ts +61 -0
  144. package/src/runtime/gateway/mcp/router.ts +2 -2
  145. package/src/runtime/gateway/mcp/runtime-tool-definitions.ts +21 -2
  146. package/src/runtime/gateway/mcp/runtime-tools.ts +805 -1009
  147. package/src/runtime/plugins/app-store-connect-adapter.ts +93 -28
  148. package/src/runtime/plugins/browser-adapter.ts +256 -1083
  149. package/src/runtime/plugins/browser-handoff-host.ts +2 -25
  150. package/src/runtime/plugins/browser-handoff.ts +18 -3
  151. package/src/runtime/plugins/browser-macos-bridge.ts +121 -16
  152. package/src/runtime/plugins/browser-manifest-surface.ts +603 -0
  153. package/src/runtime/plugins/browser-native-session-service.ts +222 -0
  154. package/src/runtime/plugins/browser-runtime-contract.ts +2 -0
  155. package/src/runtime/plugins/browser-runtime.ts +10 -0
  156. package/src/runtime/plugins/browser-session-store.ts +121 -0
  157. package/src/runtime/plugins/browser-session-types.ts +98 -0
  158. package/src/runtime/plugins/desktop-operator-registration.ts +4 -4
  159. package/src/runtime/plugins/external-adapter.ts +92 -58
  160. package/src/runtime/plugins/macos-capability-broker.ts +0 -8
  161. package/src/runtime/plugins/store.ts +66 -9
  162. package/src/runtime/plugins/types.ts +3 -1
  163. package/src/runtime/recovery/maintenance-executor.ts +61 -25
  164. package/src/runtime/root/package-connector-service.ts +46 -4
  165. package/src/runtime/root/package-runtime-release.ts +1 -1
  166. package/src/runtime/root/package-runtime-service.ts +33 -2
  167. package/src/runtime/root/release-manifest.ts +137 -16
  168. package/src/runtime/root/release-materialize.ts +109 -35
  169. package/src/runtime/root/types.ts +10 -0
  170. package/src/runtime/standalone-recovery/core.ts +425 -194
  171. package/src/runtime/standalone-recovery/entry.ts +1 -1
  172. package/src/runtime/standalone-recovery/installer.ts +1 -1
  173. package/src/runtime/workflow/schedules/engine.ts +113 -87
  174. package/src/runtime/workflow/schedules/settlement.ts +26 -23
  175. package/src/runtime/workflow/schedules/store.ts +79 -10
@@ -1,1195 +1,4 @@
1
1
  #!/bin/bash
2
2
  set -euo pipefail
3
-
4
3
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
- if REPO_ROOT="$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null)"; then
6
- cd "$REPO_ROOT"
7
- elif [[ "$SCRIPT_DIR" == */.ai/harness/scripts ]]; then
8
- cd "$SCRIPT_DIR/../../.."
9
- else
10
- cd "$SCRIPT_DIR/.."
11
- fi
12
-
13
- usage() {
14
- cat <<'USAGE_EOF'
15
- Usage: scripts/ensure-task-workflow.sh [--new-plan] [--slug <slug>] [--title <title>]
16
- USAGE_EOF
17
- }
18
-
19
- normalize_slug() {
20
- printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//; s/-{2,}/-/g'
21
- }
22
-
23
- ACTIVE_PLAN_MARKER=".ai/harness/active-plan"
24
- LEGACY_ACTIVE_PLAN_MARKER=".claude/.active-plan"
25
-
26
- read_active_plan_marker() {
27
- local marker_file="$1"
28
- local marker_plan
29
-
30
- if [[ -f "$marker_file" ]]; then
31
- marker_plan="$(cat "$marker_file" 2>/dev/null | xargs)"
32
- if [[ -n "$marker_plan" && -f "$marker_plan" ]]; then
33
- printf '%s' "$marker_plan"
34
- return 0
35
- fi
36
- fi
37
-
38
- return 1
39
- }
40
-
41
- get_active_plan() {
42
- read_active_plan_marker "$ACTIVE_PLAN_MARKER" \
43
- || read_active_plan_marker "$LEGACY_ACTIVE_PLAN_MARKER"
44
- }
45
-
46
- ensure_templates() {
47
- mkdir -p .claude/templates
48
-
49
- if [[ ! -f ".claude/templates/spec.template.md" ]]; then
50
- cat > .claude/templates/spec.template.md <<'SPEC_TEMPLATE_EOF'
51
- # Product Spec: {{PROJECT_NAME}}
52
-
53
- > **Status**: Draft
54
- > **Last Updated**: {{TIMESTAMP}}
55
- > **Owner**: Planner
56
-
57
- ## Product Outcome
58
-
59
- Describe the stable user or operator outcome this repo should deliver.
60
-
61
- ## Success Criteria
62
-
63
- - Primary workflow:
64
- - Quality bar:
65
- - Out of scope:
66
-
67
- ## Constraints
68
-
69
- - Technical:
70
- - Compliance:
71
- - Delivery:
72
-
73
- ## Acceptance Scenarios
74
-
75
- - Given
76
- When
77
- Then
78
-
79
- ## Open Questions
80
-
81
- - ...
82
- SPEC_TEMPLATE_EOF
83
- fi
84
-
85
- if [[ ! -f ".claude/templates/research.template.md" ]]; then
86
- cat > .claude/templates/research.template.md <<'RESEARCH_TEMPLATE_EOF'
87
- # {{PROJECT_NAME}} — Research Notes
88
-
89
- > **Last Updated**: {{DATE}}
90
- > **Scope**: (what area of the codebase was researched)
91
- > **Usage**: Store deep codebase findings and hidden contracts here, not in chat-only summaries.
92
-
93
- ## Codebase Map
94
- | File | Purpose | Key Exports |
95
- |------|---------|-------------|
96
-
97
- ## Architecture Observations
98
- ### Patterns & Conventions
99
- ### Implicit Contracts
100
- ### Edge Cases & Intricacies
101
-
102
- ## Technical Debt / Risks
103
-
104
- ## Research Conclusions
105
- ### What to Preserve
106
- ### What to Change
107
- ### Open Questions
108
- RESEARCH_TEMPLATE_EOF
109
- fi
110
-
111
- if [[ ! -f ".claude/templates/prd.template.md" ]]; then
112
- cat > .claude/templates/prd.template.md <<'PRD_TEMPLATE_EOF'
113
- # PRD: {{PRD_TITLE}}
114
-
115
- > **Status**: Draft
116
- > **Slug**: {{PRD_SLUG}}
117
- > **Created**: {{TIMESTAMP}}
118
- > **Updated**: {{TIMESTAMP}}
119
- > **Source Spec**: `docs/spec.md`
120
- > **Tier**: compact
121
-
122
- <!--
123
- PRD tier contract:
124
- - compact: one focused product/tool or fewer than three P0 modules, target 150-300 lines.
125
- - standard: multi-module product, target 300-600 lines and hard cap 800 lines.
126
- - If the PRD would exceed 800 lines, split it into smaller PRDs.
127
- - Output files live in plans/prds/<YYYYMMDD>-<HHMM>-<slug>.prd.md.
128
- - Inline responses should include only the AI Quick-Read Card and file path.
129
- -->
130
-
131
- ## AI Quick-Read Card
132
-
133
- - Problem:
134
- - Users:
135
- - Platform:
136
- - P0 surface:
137
- - Core metric:
138
- - Hard constraint:
139
- - Key risk:
140
- - Unknowns:
141
- - Acceptance scenarios:
142
- - Suggested next step:
143
-
144
- ## Problem
145
-
146
- ### Product Direction
147
-
148
- - Hard Constraints:
149
- - Recommended Defaults:
150
- - Freedoms:
151
-
152
- ### Feasibility Boundary
153
-
154
- - Confirmed:
155
- - [UNKNOWN]:
156
- - [UNVERIFIED]:
157
-
158
- ## Users
159
-
160
- ### Primary Users
161
-
162
- - User:
163
- - Need:
164
- - Success signal:
165
-
166
- ### Secondary Users
167
-
168
- - User:
169
- - Need:
170
- - Success signal:
171
-
172
- ## Success Criteria
173
-
174
- | Metric | Target | Measurement Method | Degradation Threshold |
175
- |---|---:|---|---:|
176
- | Example metric | 95% | Describe how to measure it | 90% |
177
-
178
- ## Acceptance Scenarios
179
-
180
- ### Scenario 1
181
-
182
- - Given:
183
- - When:
184
- - Then:
185
- - Machine-checkable evidence:
186
-
187
- ### Scenario 2
188
-
189
- - Given:
190
- - When:
191
- - Then:
192
- - Machine-checkable evidence:
193
-
194
- ## Non-goals
195
-
196
- -
197
-
198
- ## Module Behaviors (P0)
199
-
200
- ### Module 1
201
-
202
- - Purpose:
203
- - Hard Constraints:
204
- - Recommended Defaults:
205
- - Freedoms:
206
- - Normal path:
207
- - Failure path 1:
208
- - Failure path 2:
209
- - States:
210
- - Empty:
211
- - Loading:
212
- - Ready:
213
- - Error:
214
- - Dependencies:
215
- - Open decisions: None
216
-
217
- ## Data Model
218
-
219
- ```jsonc
220
- {
221
- "version": "1",
222
- "entities": [
223
- {
224
- "id": "example_entity",
225
- "owner": "user", // who owns the data
226
- "fields": {
227
- "id": "string", // stable identifier
228
- "created_at": "datetime" // creation timestamp
229
- }
230
- }
231
- ],
232
- "relationships": []
233
- }
234
- ```
235
-
236
- ## Performance Targets
237
-
238
- | Target | Number | Measurement Method | Degradation Threshold |
239
- |---|---:|---|---:|
240
- | Initial usable response | 2 seconds | Local stopwatch or automated timing | 4 seconds |
241
-
242
- ## Known Unknowns
243
-
244
- | Item | Impact | Resolution Path | Owner |
245
- |---|---|---|---|
246
- | [UNKNOWN] Example unknown | Explain impact | Explain how to resolve | Maintainer |
247
-
248
- ## Developer Handoff
249
-
250
- You are implementing this PRD.
251
-
252
- - Build first:
253
- - Do not reinterpret:
254
- - You may improve:
255
- - Verify with:
256
-
257
- ### Acceptance Scripts
258
-
259
- 1.
260
- 2.
261
- 3.
262
-
263
- ## Adjacent Patterns
264
-
265
- Use this section only in standard tier or when explicitly requested. Prefer adjacent product patterns and common workflow debt. Do not name a competitor, API, platform limit, or package size unless the fact is sourced; otherwise mark it `[UNVERIFIED]`.
266
-
267
- ## Commercialization Notes
268
-
269
- Use only when the request involves pricing, packaging, monetization, or buyer/user separation.
270
-
271
- ## Frontend Perspective
272
-
273
- Use only when the frontend shape affects product behavior, state ownership, accessibility, or implementation risk.
274
-
275
- ## Backend Perspective
276
-
277
- Use only when APIs, persistence, jobs, permissions, or data ownership affect product behavior or implementation risk.
278
- PRD_TEMPLATE_EOF
279
- fi
280
-
281
- if [[ ! -f ".claude/templates/plan.template.md" ]]; then
282
- cat > .claude/templates/plan.template.md <<'PLAN_TEMPLATE_EOF'
283
- # Plan: {{TITLE}}
284
-
285
- > **Status**: Draft
286
- > **Created**: {{TIMESTAMP}}
287
- > **Slug**: {{SLUG}}
288
- > **Spec**: `docs/spec.md`
289
- > **Research**: See `docs/researches/`
290
- > **Task Contract**: `tasks/contracts/{{ARTIFACT_STEM}}.contract.md`
291
- > **Task Review**: `tasks/reviews/{{ARTIFACT_STEM}}.review.md`
292
- > **Implementation Notes**: `tasks/notes/{{ARTIFACT_STEM}}.notes.md`
293
-
294
- ## Agentic Routing
295
- - Selected route:
296
- - Routing reason:
297
- - Due diligence:
298
- - P1 map:
299
- - P2 trace:
300
- - P3 decision rationale:
301
-
302
- ## Workflow Inventory
303
- Complete this inventory before implementation. If any line is unknown, keep the plan in Draft and fill it before projection.
304
-
305
- - Active plan: `{{PLAN_FILE}}`
306
- - Sprint contract: `tasks/contracts/{{ARTIFACT_STEM}}.contract.md`
307
- - Sprint review: `tasks/reviews/{{ARTIFACT_STEM}}.review.md`
308
- - Implementation notes: `tasks/notes/{{ARTIFACT_STEM}}.notes.md`
309
- - Deferred-goal ledger: `tasks/todos.md`
310
- - Current checks: `.ai/harness/checks/latest.json`
311
- - Run snapshots: `.ai/harness/runs/`
312
- - Scope authority: `tasks/contracts/{{ARTIFACT_STEM}}.contract.md` `allowed_paths`
313
- - Concurrency rule: `.ai/harness/active-plan` selects the active plan for this worktree when present; `.ai/harness/active-worktree` records the owning worktree; `.claude/.active-plan` is a legacy fallback during transition. If another worktree already owns active work, open or switch to the matching worktree instead of serializing unrelated plans.
314
- - Execution isolation: approved contract-level work projects through `scripts/plan-to-todo.sh --plan {{PLAN_FILE}}` and may start `scripts/contract-worktree.sh start --plan {{PLAN_FILE}}`.
315
-
316
- ## Approach
317
- ### Strategy
318
- ### Trade-offs
319
- | Option | Pros | Cons | Decision |
320
- |--------|------|------|----------|
321
-
322
- ## Detailed Design
323
- ### File Changes
324
- | File | Action | Description |
325
- |------|--------|-------------|
326
-
327
- ### Code Snippets
328
- ### Data Flow
329
-
330
- ## Risk Assessment
331
- | Risk | Likelihood | Impact | Mitigation |
332
- |------|------------|--------|------------|
333
-
334
- ## Task Contracts
335
- - Contract file: `tasks/contracts/{{ARTIFACT_STEM}}.contract.md`
336
- - Review file: `tasks/reviews/{{ARTIFACT_STEM}}.review.md`
337
- - Implementation notes file: `tasks/notes/{{ARTIFACT_STEM}}.notes.md`
338
- - Template: `.claude/templates/contract.template.md`
339
- - Verification command: `bash scripts/verify-contract.sh --contract tasks/contracts/{{ARTIFACT_STEM}}.contract.md --strict`
340
- - Active plan rule: `.ai/harness/active-plan` is authoritative for this worktree when present; `.ai/harness/active-worktree` records the owning worktree; `.claude/.active-plan` is a legacy fallback during transition. Do not infer active execution from the latest non-archived plan.
341
-
342
- ## Handoff
343
-
344
- - Checks file: `.ai/harness/checks/latest.json`
345
- - Session continuation: `.ai/harness/session/continuation.md`
346
-
347
- ## Evidence Contract
348
-
349
- - **State/progress path**:
350
- - **Verification evidence**:
351
- - **Impact review**:
352
- - **Stop condition**:
353
- - **Rollback surface**:
354
-
355
- ## Annotations
356
- <!-- [NOTE]: prefixed inline. Claude processes all and revises. -->
357
-
358
- ## Task Breakdown
359
- - [ ] ...
360
- PLAN_TEMPLATE_EOF
361
- fi
362
-
363
- if [[ ! -f ".claude/templates/contract.template.md" ]]; then
364
- cat > .claude/templates/contract.template.md <<'CONTRACT_TEMPLATE_EOF'
365
- # Task Contract: {{TASK_SLUG}}
366
-
367
- > **Status**: Pending
368
- > **Plan**: {{PLAN_FILE}}
369
- > **Task Profile**: {{TASK_PROFILE}}
370
- > **Owner**: {{OWNER}}
371
- > **Capability ID**: {{CAPABILITY_ID}}
372
- > **Last Updated**: {{TIMESTAMP}}
373
- > **Review File**: `{{REVIEW_FILE}}`
374
- > **Notes File**: `{{NOTES_FILE}}`
375
-
376
- ## Goal
377
-
378
- Describe the exact outcome this task must deliver.
379
-
380
- ## Scope
381
-
382
- - In scope:
383
- - Out of scope:
384
-
385
- ## Workflow Inventory
386
-
387
- - Source plan: `{{PLAN_FILE}}`
388
- - Deferred-goal ledger: `tasks/todos.md`
389
- - Review file: `{{REVIEW_FILE}}`
390
- - Notes file: `{{NOTES_FILE}}`
391
- - Checks file: `.ai/harness/checks/latest.json`
392
- - Run snapshots: `.ai/harness/runs/`
393
- - Scope gate: edit only paths listed under `allowed_paths`; update this contract before widening scope.
394
- - Completion evidence: `scripts/verify-sprint.sh` reports this contract's direct checks and declared scope. Then perform a fresh semantic impact review.
395
-
396
- ## Allowed Paths
397
-
398
- ```yaml
399
- allowed_paths:
400
- - plans/
401
- - tasks/todos.md
402
- - {{CONTRACT_FILE}}
403
- - {{REVIEW_FILE}}
404
- - {{NOTES_FILE}}
405
- - .ai/context/capabilities.json
406
- - src/
407
- - tests/
408
- ```
409
-
410
- ## Delegation Contract
411
-
412
- ```yaml
413
- delegation:
414
- budget:
415
- tokens: null
416
- tool_calls: null
417
- wall_time_minutes: null
418
- permission_scope:
419
- mode: inherit_allowed_paths
420
- writable_paths: []
421
- network: inherited
422
- roles:
423
- parent:
424
- mode: narrate_and_gatekeep
425
- purpose: approval_checkpoint_owner
426
- explorer:
427
- mode: read_only
428
- purpose: codebase_research
429
- worker:
430
- mode: edit_within_allowed_paths
431
- purpose: implementation
432
- verifier:
433
- mode: read_only
434
- purpose: exit_criteria_review
435
- ```
436
-
437
- ## Exit Criteria (Machine Verifiable)
438
-
439
- ```yaml
440
- exit_criteria:
441
- files_exist:
442
- - src/modules/{{TASK_SLUG}}/index.ts
443
- - {{NOTES_FILE}}
444
- tests_pass:
445
- - path: tests/unit/{{TASK_SLUG}}.test.ts
446
- commands_succeed:
447
- - bun run typecheck
448
- files_contain:
449
- - path: src/modules/{{TASK_SLUG}}/index.ts
450
- pattern: "export"
451
- ```
452
-
453
- ## Acceptance Notes (Human Review)
454
-
455
- - Functional behavior:
456
- - Edge cases:
457
- - Regression risks:
458
-
459
- ## Rollback Point
460
-
461
- - Commit / checkpoint:
462
- - Revert strategy:
463
- CONTRACT_TEMPLATE_EOF
464
- fi
465
-
466
- if [[ ! -f ".claude/templates/review.template.md" ]]; then
467
- cat > .claude/templates/review.template.md <<'REVIEW_TEMPLATE_EOF'
468
- # Task Review: {{TASK_SLUG}}
469
-
470
- > **Status**: Pending
471
- > **Plan**: {{PLAN_FILE}}
472
- > **Contract**: {{CONTRACT_FILE}}
473
- > **Notes File**: {{NOTES_FILE}}
474
- > **Checks File**: {{CHECKS_FILE}}
475
- > **Last Updated**: {{TIMESTAMP}}
476
- > **Summary**:
477
-
478
- ## Semantic Impact Review
479
-
480
- - User intent:
481
- - Affected domains and downstream consumers:
482
- - State transitions and persistence/restart impact:
483
- - Missing impact areas or uncertainty:
484
- - Residual risks and recovery:
485
-
486
- ## Verification Evidence
487
-
488
- - Focused/full checks:
489
- - Commands run:
490
- - Manual checks:
491
- - Supporting artifacts:
492
-
493
- ## Failing Items
494
-
495
- - ...
496
-
497
- ## Retest Steps
498
-
499
- - Re-run:
500
- - Re-check:
501
-
502
- ## Summary
503
-
504
- - ...
505
- REVIEW_TEMPLATE_EOF
506
- fi
507
-
508
- if [[ ! -f ".claude/templates/implementation-notes.template.md" ]]; then
509
- cat > .claude/templates/implementation-notes.template.md <<'NOTES_TEMPLATE_EOF'
510
- # Implementation Notes: {{TASK_SLUG}}
511
-
512
- > **Status**: Active
513
- > **Plan**: {{PLAN_FILE}}
514
- > **Contract**: {{CONTRACT_FILE}}
515
- > **Review**: {{REVIEW_FILE}}
516
- > **Last Updated**: {{TIMESTAMP}}
517
- > **Lifecycle**: notes
518
-
519
- ## Design Decisions
520
-
521
- - ...
522
-
523
- ## Deviations From Plan Or Spec
524
-
525
- - None recorded.
526
-
527
- ## Tradeoffs Considered
528
-
529
- | Option | Decision | Reason |
530
- |--------|----------|--------|
531
- | ... | ... | ... |
532
-
533
- ## Open Questions
534
-
535
- - None.
536
-
537
- ## Evidence Links
538
-
539
- - Checks: `.ai/harness/checks/latest.json`
540
- - Run snapshots: `.ai/harness/runs/`
541
-
542
- ## Promotion Candidates
543
-
544
- - Promote to `tasks/lessons.md` only after a repeated correction or failure pattern.
545
- - Promote to `docs/researches/` only when it is durable repo knowledge with evidence.
546
- - Promote to harness asset files only after verification across more than one task or fixture.
547
- NOTES_TEMPLATE_EOF
548
- fi
549
- }
550
-
551
- ensure_idle_todo() {
552
- mkdir -p tasks
553
- if [[ ! -f "tasks/todos.md" ]]; then
554
- cat > tasks/todos.md <<'TODO_EOF'
555
- # Deferred Goal Ledger
556
-
557
- > **Status**: Backlog
558
- > **Updated**: (ensure-task-workflow)
559
- > **Scope**: Medium/long-term goals deferred from active plan execution
560
-
561
- Current plan tasks live in the active plan's `## Task Breakdown`.
562
- Do not duplicate that execution checklist here. Record only work intentionally deferred beyond this slice, with the tradeoff and revisit trigger.
563
-
564
- ## Deferred Goals
565
-
566
- | Goal | Why Deferred | Tradeoff | Revisit Trigger |
567
- |------|--------------|----------|-----------------|
568
- | (none) | No deferred medium/long-term goal recorded yet. | Keep the current slice bounded. | Add a row when a real follow-up is postponed. |
569
- TODO_EOF
570
- fi
571
- }
572
-
573
- ensure_current_status_snapshot() {
574
- mkdir -p tasks
575
- if [[ -x "scripts/refresh-current-status.sh" ]]; then
576
- bash "scripts/refresh-current-status.sh" --clear --write --reason "ensure-task-workflow" >/dev/null 2>&1 || true
577
- return 0
578
- fi
579
-
580
- if [[ ! -f "tasks/current.md" ]]; then
581
- cat > tasks/current.md <<'CURRENT_STATUS_EOF'
582
- # Current Status Snapshot
583
-
584
- <!-- generated-by: forge refresh-current-status v1 -->
585
- <!-- updated_at: bootstrap -->
586
- <!-- stale_after: 24h -->
587
-
588
- > **Status**: Idle
589
- > **Updated At**: bootstrap
590
- > **Source Branch**: main
591
- > **Source Commit**: bootstrap
592
- > **Target Branch**: main
593
- > **Stale After**: 24h
594
- > **Reason**: bootstrap
595
- > **Derived From**: active-plan, workstreams, handoff, checks, git status
596
-
597
- This file is a tracked mainline snapshot derived from repo artifacts. It is not a live lock, not a kanban board, and not an implementation gate. If it is stale, read the source artifacts below.
598
- CURRENT_STATUS_EOF
599
- fi
600
- }
601
-
602
- ensure_auxiliary_files() {
603
- mkdir -p plans plans/archive plans/prds plans/sprints tasks/issues tasks/archive tasks/contracts tasks/reviews tasks/notes tasks/workstreams docs/architecture/domains docs/architecture/modules docs/architecture/requests docs/architecture/snapshots docs/architecture/diagrams scripts .ai/context .ai/harness/checks .ai/harness/session .ai/harness/controller/packets .ai/harness/projections .ai/harness/transfers .ai/harness/scripts .ai/harness/failures .ai/harness/security .ai/harness/planning .ai/harness/architecture .ai/harness/worktrees .ai/harness/runs .ai/harness/jobs .ai/harness/local-jobs .ai/harness/controller .ai/harness/edit-sessions
604
-
605
- if [[ ! -f "docs/spec.md" ]]; then
606
- cat > docs/spec.md <<'SPEC_EOF'
607
- # Product Spec
608
-
609
- > **Status**: Draft
610
- > **Owner**: Planner
611
- SPEC_EOF
612
- fi
613
-
614
- if [[ ! -f "tasks/lessons.md" ]]; then
615
- cat > tasks/lessons.md <<'LESSONS_EOF'
616
- # Lessons Learned (Self-Improvement Loop)
617
-
618
- > Capture correction-derived prevention rules here.
619
- > Promote repeated patterns into durable project rules during spa day.
620
-
621
- ## Template
622
- - Date:
623
- - Triggered by correction:
624
- - Mistake pattern:
625
- - Prevention rule:
626
- - Where to apply next time:
627
- LESSONS_EOF
628
- fi
629
-
630
- mkdir -p docs/researches
631
- if [[ ! -f "docs/researches/README.md" ]]; then
632
- cat > docs/researches/README.md <<'RESEARCH_README_EOF'
633
- # Research Reports
634
-
635
- Durable research reports live in this directory as dated Markdown files.
636
-
637
- Use `YYYYMMDD-topic.md` names for new reports. Keep task-local implementation
638
- decisions in `tasks/notes/`, and keep repeated correction-derived rules in
639
- `tasks/lessons.md`.
640
- RESEARCH_README_EOF
641
- fi
642
-
643
- if [[ ! -f ".ai/harness/checks/latest.json" ]]; then
644
- echo "{}" > ".ai/harness/checks/latest.json"
645
- fi
646
-
647
- if [[ ! -f ".ai/harness/session/continuation.md" ]]; then
648
- cat > ".ai/harness/session/continuation.md" <<'HANDOFF_EOF'
649
- # Forge Session Continuation Snapshot
650
-
651
- > **Reason**: bootstrap
652
- HANDOFF_EOF
653
- fi
654
-
655
- if [[ ! -f ".ai/harness/session/resume.md" ]]; then
656
- cat > ".ai/harness/session/resume.md" <<'RESUME_EOF'
657
- # Codex Resume Packet
658
-
659
- > **Reason**: bootstrap
660
- RESUME_EOF
661
- fi
662
-
663
- if [[ ! -f ".ai/harness/events.jsonl" ]]; then
664
- : > ".ai/harness/events.jsonl"
665
- fi
666
-
667
- if [[ ! -f ".ai/harness/architecture/events.jsonl" ]]; then
668
- : > ".ai/harness/architecture/events.jsonl"
669
- fi
670
-
671
- if [[ ! -f ".ai/harness/architecture/.gitkeep" ]]; then
672
- : > ".ai/harness/architecture/.gitkeep"
673
- fi
674
-
675
- if [[ ! -f ".ai/harness/failures/latest.jsonl" ]]; then
676
- : > ".ai/harness/failures/latest.jsonl"
677
- fi
678
-
679
- if [[ ! -f ".ai/harness/security/.gitkeep" ]]; then
680
- : > ".ai/harness/security/.gitkeep"
681
- fi
682
-
683
- if [[ ! -f ".ai/harness/runs/.gitkeep" ]]; then
684
- : > ".ai/harness/runs/.gitkeep"
685
- fi
686
- if [[ ! -f ".ai/harness/worktrees/.gitkeep" ]]; then
687
- : > ".ai/harness/worktrees/.gitkeep"
688
- fi
689
- if [[ ! -f ".ai/harness/jobs/.gitkeep" ]]; then
690
- : > ".ai/harness/jobs/.gitkeep"
691
- fi
692
- if [[ ! -f ".ai/harness/edit-sessions/.gitkeep" ]]; then
693
- : > ".ai/harness/edit-sessions/.gitkeep"
694
- fi
695
-
696
- if [[ ! -f "docs/architecture/requests/.gitkeep" ]]; then
697
- : > "docs/architecture/requests/.gitkeep"
698
- fi
699
-
700
- if [[ ! -f "docs/architecture/snapshots/.gitkeep" ]]; then
701
- : > "docs/architecture/snapshots/.gitkeep"
702
- fi
703
-
704
- if [[ ! -f "docs/architecture/diagrams/.gitkeep" ]]; then
705
- : > "docs/architecture/diagrams/.gitkeep"
706
- fi
707
-
708
- if [[ ! -f "docs/architecture/domains/.gitkeep" ]]; then
709
- : > "docs/architecture/domains/.gitkeep"
710
- fi
711
-
712
- if [[ ! -f "docs/architecture/modules/.gitkeep" ]]; then
713
- : > "docs/architecture/modules/.gitkeep"
714
- fi
715
-
716
- if [[ ! -f "tasks/workstreams/.gitkeep" ]]; then
717
- : > "tasks/workstreams/.gitkeep"
718
- fi
719
-
720
- if [[ ! -f ".ai/context/capabilities.json" ]]; then
721
- cat > ".ai/context/capabilities.json" <<'CAPABILITIES_EOF'
722
- {
723
- "version": 1,
724
- "capabilities": []
725
- }
726
- CAPABILITIES_EOF
727
- fi
728
-
729
- if [[ ! -f "docs/architecture/index.md" ]]; then
730
- cat > "docs/architecture/index.md" <<'ARCHITECTURE_INDEX_EOF'
731
- # Architecture Index
732
-
733
- > Umbrella architecture ledger for current boundaries, drift requests, snapshots, and diagrams.
734
-
735
- ## Current Snapshot
736
-
737
- - Latest snapshot: (none yet)
738
- - Semantic diagram source: (none yet)
739
- - Latest human diagram: (none yet)
740
-
741
- ## Architecture Drift Flow
742
-
743
- - `scripts/architecture-queue.sh` records architecture-sensitive edits as requests.
744
- - `scripts/archive-architecture-request.sh` archives handled requests after an agent records the resolution status and linked artifacts.
745
- - `scripts/context-contract-sync.sh` keeps only the controlled architecture block in functional-block `AGENTS.md` and `CLAUDE.md` files aligned.
746
- - `scripts/workstream-sync.sh` keeps durable multi-session progress under `tasks/workstreams/<domain>/<capability>/` and projects only pointers into local contracts.
747
- - Semantic architecture diagrams live as Mermaid fenced blocks in the relevant module or snapshot Markdown.
748
- - Human-readable architecture diagrams are optional `mermaid` HTML files in `docs/architecture/diagrams/` and should link back to the Markdown semantic source.
749
-
750
- ## Pending Requests
751
-
752
- <!-- BEGIN ARCHITECTURE PENDING REQUESTS -->
753
- - (none)
754
- <!-- END ARCHITECTURE PENDING REQUESTS -->
755
-
756
- ARCHITECTURE_INDEX_EOF
757
- fi
758
-
759
- if [[ ! -f ".ai/harness/policy.json" ]]; then
760
- cat > ".ai/harness/policy.json" <<'POLICY_EOF'
761
- {
762
- "version": 1,
763
- "active_plan": {
764
- "marker_file": ".ai/harness/active-plan",
765
- "legacy_marker_file": ".claude/.active-plan",
766
- "directory": "plans",
767
- "archive_directory": "plans/archive",
768
- "glob": "plan-*.md",
769
- "active_worktree_marker_file": ".ai/harness/active-worktree",
770
- "source_of_truth": "per-worktree explicit marker with active-worktree owner; legacy Claude marker fallback only"
771
- },
772
- "tasks": {
773
- "todo_file": "tasks/todos.md",
774
- "current_status_file": "tasks/current.md",
775
- "lessons_file": "tasks/lessons.md",
776
- "research_dir": "docs/researches",
777
- "workstreams_dir": "tasks/workstreams",
778
- "contracts_dir": "tasks/contracts",
779
- "reviews_dir": "tasks/reviews",
780
- "notes_dir": "tasks/notes"
781
- },
782
- "reference_material": {
783
- "dir": "_ref",
784
- "mode": "external-ignored",
785
- "commit_policy": "never commit _ref contents",
786
- "rule": "use _ref as an occasional ignored external reference checkout cache for upstream/source comparison only; refresh from external sources instead of editing as product code; when it influences a decision, cite the source repo plus commit/tag and path in tasks/notes/ or docs/researches/"
787
- },
788
- "operations": {
789
- "dir": "deploy",
790
- "private_dir": "_ops",
791
- "tracked": ["deploy/README.md", "deploy/scripts/", "deploy/submissions/", "deploy/runbooks/", "deploy/release-checklists/", "deploy/sql/", "deploy/*.md", "deploy/env/.env.example"],
792
- "ignored": ["_ops/"],
793
- "rule": "commit deployment runbooks, submission materials, release checklists, helper scripts, ordered SQL files, and env examples under deploy/; keep deploy SQL in deploy/sql/ with 4-digit ascending prefixes; keep keys, tokens, real env values, provider state, artifacts, logs, and scratch files in ignored _ops/ only"
794
- },
795
- "context": {
796
- "profile": "stable-root-progressive-subdir",
797
- "map_file": ".ai/context/context-map.json",
798
- "capability_registry_file": ".ai/context/capabilities.json",
799
- "capability_resolver": "scripts/capability-resolver.ts",
800
- "capability_match_rule": "longest-prefix; same-length ambiguity fails",
801
- "functional_block_selector": {
802
- "script": "scripts/select-agent-context-blocks.sh",
803
- "config_file": ".ai/context/agent-context-blocks.txt",
804
- "env": "FORGE_CONTEXT_BLOCKS",
805
- "rule": "compatibility selector; capability registry is the source of truth"
806
- }
807
- },
808
- "harness": {
809
- "policy_file": ".ai/harness/policy.json",
810
- "checks_file": ".ai/harness/checks/latest.json",
811
- "failure_log_file": ".ai/harness/failures/latest.jsonl",
812
- "events_file": ".ai/harness/events.jsonl",
813
- "architecture_events_file": ".ai/harness/architecture/events.jsonl",
814
- "runs_dir": ".ai/harness/runs",
815
- "helper_runtime_dir": "scripts",
816
- "helper_compat_dir": "scripts",
817
- "helper_source": "compat-bootstrap"
818
- },
819
- "architecture": {
820
- "index_file": "docs/architecture/index.md",
821
- "requests_dir": "docs/architecture/requests",
822
- "snapshots_dir": "docs/architecture/snapshots",
823
- "diagrams_dir": "docs/architecture/diagrams",
824
- "domains_dir": "docs/architecture/domains",
825
- "modules_dir": "docs/architecture/modules",
826
- "diagram_skill": "mermaid",
827
- "diagram_skill_source": "~/.codex/skills/mermaid",
828
- "vendoring_policy": "do-not-vendor-diagram-skill-assets",
829
- "freshness_gate": "advisory",
830
- "gate_min_severity": "medium",
831
- "pending_card_scope": "capability",
832
- "pending_block_begin": "<!-- BEGIN ARCHITECTURE PENDING REQUESTS -->",
833
- "pending_block_end": "<!-- END ARCHITECTURE PENDING REQUESTS -->",
834
- "queue_script": "scripts/architecture-queue.sh",
835
- "contract_block_begin": "<!-- BEGIN ARCHITECTURE CONTRACT -->",
836
- "contract_block_end": "<!-- END ARCHITECTURE CONTRACT -->",
837
- "rule": "hooks record architecture queue cards and sync controlled local context blocks; agents author semantic snapshots and diagrams"
838
- },
839
- "workstreams": {
840
- "dir": "tasks/workstreams",
841
- "scope": "capability",
842
- "projection": "local-contract-active-pointer-and-current-slice",
843
- "todo_projection": "tasks/todos.md",
844
- "rule": "durable multi-session progress lives under tasks/workstreams/<domain>/<capability>; current plan execution lives in the plan Task Breakdown; tasks/todos.md records deferred goals only"
845
- },
846
- "information_lifecycle": {
847
- "notes": {
848
- "dir": "tasks/notes",
849
- "purpose": "task-local implementation decisions, deviations, tradeoffs, and open questions",
850
- "promotion": "archive on workflow close; promote only repeated or durable findings"
851
- },
852
- "evidence": {
853
- "latest": ".ai/harness/checks/latest.json",
854
- "snapshots_dir": ".ai/harness/runs",
855
- "purpose": "raw verification records used to audit notes, reviews, and future promotion"
856
- },
857
- "assets": {
858
- "sources": [".ai/harness/policy.json", ".ai/harness/workflow-contract.json", ".ai/hooks/", "scripts/", "docs/reference-configs/"],
859
- "promotion_rule": "only promote patterns after verified reuse across tasks or fixtures"
860
- },
861
- "memory": {
862
- "sources": ["docs/researches/", "tasks/lessons.md", "gbrain"],
863
- "rule": "memory is advisory; current repo state and evidence override summaries"
864
- },
865
- "external_knowledge": {
866
- "default_brain_path": "brain/<project>/*",
867
- "project_path": "brain/<project>/*",
868
- "manifest_file": ".ai/harness/brain-manifest.json",
869
- "drift_check": "scripts/check-brain-manifest.sh",
870
- "sync_script": "scripts/sync-brain-docs.sh",
871
- "hook_trigger": "PostToolUse Edit|Write for manifest entries with sync.direction=repo-to-brain",
872
- "rule": "external knowledge stores long-lived explanations, runbooks, and patterns only; repo-local contracts, hooks, scripts, checks, and evidence remain authoritative",
873
- "sync_rule": "only explicitly opted-in repo-to-brain manifest entries may be written to the default brain vault; pointer-only externalized stubs remain check-only"
874
- }
875
- },
876
- "session": {
877
- "continuation_file": ".ai/harness/session/continuation.md",
878
- "resume_file": ".ai/harness/session/resume.md",
879
- "global_resume_dir": "~/.codex/handoffs",
880
- "auto_start_new_session": false,
881
- "authority": "rebuildable-host-session-cache-only"
882
- },
883
- "plan_capture": {
884
- "script": "scripts/capture-plan.sh",
885
- "sources": ["host-plan-mode", "forge-plan"],
886
- "rule": "Codex Plan mode and Waza think planning should capture decision-complete plans into plans/plan-*.md; implementation approval then projects the active approved plan through scripts/plan-to-todo.sh"
887
- },
888
- "planning": {
889
- "pending_orchestration_file": ".ai/harness/planning/pending.json",
890
- "source_of_truth": "transient host planning bridge only; captured plans are source artifacts, while migrated Runtime Plan/Work lifecycle state is authoritative in the Canonical Runtime"
891
- },
892
- "guards": {
893
- "edit_plan_gate": "advice",
894
- "edit_plan_gate_modes": ["advice", "off"],
895
- "rule": "pre-edit-guard may expose Plan/spec context, but Plan lifecycle never authorizes implementation; only real safety/resource boundaries block execution"
896
- },
897
- "sidecar_research": {
898
- "default": true,
899
- "output_dir": "docs/researches",
900
- "preferred_runners": ["subagent", "codex exec --json", "main-thread trace"],
901
- "spawn_decision": "main agent decides from task breadth, context impact, raw-log volume, and callable runner availability; do not ask the user for spawn confirmation",
902
- "fallback_runner": "main-thread trace",
903
- "main_thread_policy": "if spawning is not worthwhile or no sidecar runner is callable, perform bounded research in the main thread; consume conclusions and evidence paths, not raw logs"
904
- },
905
- "documentation": {
906
- "profile": "minimal-agentic",
907
- "required": ["docs/spec.md", "docs/architecture/index.md"],
908
- "on_demand": ["docs/brief.md", "docs/tech-stack.md", "docs/decisions.md", "docs/architecture.md", "docs/packages.md"],
909
- "reference_configs": ["harness-overview.md", "agentic-development-flow.md", "external-tooling.md", "sprint-contracts.md", "handoff-protocol.md", "document-generation.md", "global-working-rules.md"],
910
- "reference_source": "user-level-runtime-docs",
911
- "reference_stub_marker": "<!-- forge: reference-config-stub v1 -->",
912
- "reference_resolver": "forge docs path <doc-id>",
913
- "rule": "create optional docs only when the agent has concrete repo evidence or the user asks; docs/reference-configs contains repo-local pointer stubs while full generic runtime docs live in the user-level/package forge install"
914
- },
915
- "lsp_profiles": {
916
- "default": "typescript-lsp",
917
- "selection": "functional-block-first",
918
- "rule": "use block-level LSP/tooling hints before broad repo assumptions"
919
- },
920
- "worktree_strategy": {
921
- "auto_on_conflict": true,
922
- "auto_for_contract_tasks": true,
923
- "branch_prefix": "codex/",
924
- "base_branch": "main",
925
- "worktree_dir_template": "../{{repo}}-wt-{{slug}}",
926
- "start_script": "scripts/contract-worktree.sh start --plan <plan-file>",
927
- "finish_script": "scripts/contract-worktree.sh finish",
928
- "cleanup_script": "scripts/contract-worktree.sh cleanup --slug <slug>",
929
- "conflict_signals": [
930
- "dirty_worktree_overlaps_task_files",
931
- "current_branch_not_suitable_for_task",
932
- "existing_changes_unrelated_but_would_block_review",
933
- "task_requires_clean_validation_surface"
934
- ],
935
- "validation_route": "forge:/review",
936
- "merge_back": {
937
- "target": "main",
938
- "requires_clean_check": true,
939
- "preserve_unrelated_changes": true
940
- }
941
- },
942
- "upgrade": {
943
- "strategy_version": 1,
944
- "supported_legacy_versions": ["pre-tasks-first", "tasks-first-without-contract-manifest", "current-v1"],
945
- "action_classes": {
946
- "preserve": "keep user-authored hooks, ignored reference material, private operations state, secrets, and local env files unchanged",
947
- "archive": "move user-authored legacy workflow documents or checklists into archive/research surfaces before refresh",
948
- "reconfigure": "merge managed config defaults without overwriting explicit repo overrides",
949
- "remove": "delete only workflow-contract actions marked ownership=known_generated"
950
- },
951
- "cleanup": {
952
- "source": ".ai/harness/workflow-contract.json#migrations.upgrade.actions",
953
- "remove_only_ownership": "known_generated",
954
- "unknown_files": "preserve-or-archive",
955
- "custom_hooks": "preserve",
956
- "ignored_reference_material": "preserve",
957
- "local_operations_state": "preserve",
958
- "local_secrets": "preserve"
959
- },
960
- "reporting": {
961
- "inspector_field": "upgrade_plan",
962
- "dry_run_required": true
963
- }
964
- },
965
- "profiles": {
966
- "orchestration": "shared-long-running-harness",
967
- "evaluation": "browser-qa",
968
- "handoff": "artifact-aware",
969
- "recovery": "hybrid",
970
- "state": "file-backed"
971
- },
972
- "external_tooling": {
973
- "routing": {
974
- "primary": "forge",
975
- "optional_complex_helper": "gstack",
976
- "optional_daily_helper": "waza",
977
- "optional_knowledge_helper": "gbrain"
978
- },
979
- "hosts": [
980
- "claude-code",
981
- "codex"
982
- ],
983
- "mode": "optional-enhancements",
984
- "detection": "init-migrate",
985
- "readiness_report": "scripts/check-agent-tooling.sh --host codex",
986
- "waza": {
987
- "source_repo": "tw93/Waza",
988
- "source_url": "https://github.com/tw93/Waza.git",
989
- "managed_skills": ["think", "hunt", "check", "health"],
990
- "primary_host": "codex",
991
- "codex_primary_path": "~/.codex/skills",
992
- "staging_cache_path": "~/.agents/skills",
993
- "sync_mode": "stage-upstream-then-copy-to-codex",
994
- "host_drift_policy": "report-per-host-version-staging-and-upstream-drift"
995
- },
996
- "codex_automation_profile": {
997
- "required_skills": [],
998
- "optional_skills": ["health", "check", "mermaid"],
999
- "mode": "optional-codex-runtime-reference",
1000
- "source": "~/.codex/skills",
1001
- "routes": {
1002
- "workflow_health_optional": "waza:health",
1003
- "review_helper_optional": "waza:check",
1004
- "architecture_diagram_optional": "mermaid"
1005
- },
1006
- "vendoring_policy": "do-not-vendor-skill-body"
1007
- },
1008
- "diagram_design": {
1009
- "skill_name": "mermaid",
1010
- "primary_host": "codex",
1011
- "codex_primary_path": "~/.codex/skills/mermaid",
1012
- "sync_mode": "external-installed-skill",
1013
- "vendoring_policy": "do-not-vendor"
1014
- },
1015
- "gbrain": {
1016
- "mcp": "candidate-disabled"
1017
- },
1018
- "codegraph": {
1019
- "package": "@colbymchenry/codegraph",
1020
- "primary_host": "both",
1021
- "install_mode": "target-aware-mcp",
1022
- "codex_config_path": "~/.codex/config.toml",
1023
- "claude_config_path": "~/.claude.json",
1024
- "index_dir": ".codegraph",
1025
- "readiness": "forge-bundled-backend; host-mcp-optional",
1026
- "hook_policy": "do-not-block-hooks",
1027
- "install_command": "bun add -g @colbymchenry/codegraph && forge tools configure codegraph --target codex --location global",
1028
- "project_init_command": "codegraph init -i .",
1029
- "sync_command": "codegraph sync .",
1030
- "vendoring_policy": "do-not-add-package-dependency"
1031
- }
1032
- },
1033
- "agentic_development": {
1034
- "routing": {
1035
- "direct": "forge:/direct",
1036
- "plan": "forge:/plan",
1037
- "debug": "forge:/debug",
1038
- "review": "forge:/review",
1039
- "release": "forge:/release",
1040
- "scale": "forge:/scale"
1041
- },
1042
- "due_diligence": {
1043
- "levels": ["P1_GLOBAL_ARCHITECTURE", "P2_DATA_FLOW_TRACE", "P3_DESIGN_DECISION"],
1044
- "explicit_report_required_for": ["architecture", "debug", "risky_refactor", "deployment", "auth_payment_data", "shared_contract"]
1045
- }
1046
- },
1047
- "enforcement": {
1048
- "worktree_guard": "warn-by-default",
1049
- "verification_gate": "contract-and-review",
1050
- "completion_requires_checks": true
1051
- }
1052
- }
1053
- POLICY_EOF
1054
- fi
1055
-
1056
- if [[ ! -f ".ai/harness/brain-manifest.json" ]]; then
1057
- cat > ".ai/harness/brain-manifest.json" <<'BRAIN_MANIFEST_EOF'
1058
- {
1059
- "version": 1,
1060
- "project": "<project>",
1061
- "mode": "repo-contract-external-knowledge",
1062
- "default_brain_path": "brain/<project>/*",
1063
- "rules": [
1064
- "repo-local contracts, hooks, scripts, checks, and evidence remain authoritative",
1065
- "default brain stores long-lived explanations, runbooks, decisions, references, and patterns",
1066
- "hook runtime may sync explicitly opted-in repo-to-brain entries only; it must not query gbrain, MCP, or unregistered default brain paths"
1067
- ],
1068
- "entries": []
1069
- }
1070
- BRAIN_MANIFEST_EOF
1071
- fi
1072
-
1073
- if [[ ! -f ".ai/context/context-map.json" ]]; then
1074
- cat > ".ai/context/context-map.json" <<'CONTEXT_EOF'
1075
- {
1076
- "version": 1,
1077
- "profile": "stable-root-progressive-subdir",
1078
- "functional_block_selector": {
1079
- "script": "scripts/select-agent-context-blocks.sh",
1080
- "config_file": ".ai/context/agent-context-blocks.txt",
1081
- "env": "FORGE_CONTEXT_BLOCKS",
1082
- "rule": "compatibility selector; capability registry is the source of truth"
1083
- },
1084
- "lsp_profiles": {
1085
- "default": "typescript-lsp",
1086
- "selection": "functional-block-first"
1087
- },
1088
- "root_context_files": [
1089
- "CLAUDE.md",
1090
- "AGENTS.md",
1091
- "docs/spec.md",
1092
- "tasks/current.md",
1093
- "tasks/todos.md",
1094
- "tasks/lessons.md",
1095
- ".ai/context/capabilities.json",
1096
- ".ai/harness/policy.json"
1097
- ],
1098
- "discoverable_contexts": [
1099
- {
1100
- "path": "docs/reference-configs/*.md",
1101
- "priority": "low",
1102
- "char_budget": 900,
1103
- "purpose": "deep-doc"
1104
- },
1105
- {
1106
- "path": "tasks/workstreams/**/*.md",
1107
- "priority": "high",
1108
- "char_budget": 1200,
1109
- "purpose": "capability-workstream"
1110
- }
1111
- ],
1112
- "budgets": {
1113
- "root_total_chars": 12000,
1114
- "per_discoverable_file_chars": 1200
1115
- }
1116
- }
1117
- CONTEXT_EOF
1118
- fi
1119
- }
1120
-
1121
- slug=""
1122
- title=""
1123
- new_plan=0
1124
-
1125
- while [[ $# -gt 0 ]]; do
1126
- case "$1" in
1127
- --new-plan)
1128
- new_plan=1
1129
- shift
1130
- ;;
1131
- --slug)
1132
- [[ -n "${2:-}" ]] || { echo "Error: --slug requires a value" >&2; usage; exit 1; }
1133
- slug="$2"
1134
- shift 2
1135
- ;;
1136
- --title)
1137
- [[ -n "${2:-}" ]] || { echo "Error: --title requires a value" >&2; usage; exit 1; }
1138
- title="$2"
1139
- shift 2
1140
- ;;
1141
- --help|-h)
1142
- usage
1143
- exit 0
1144
- ;;
1145
- *)
1146
- echo "Unknown argument: $1" >&2
1147
- usage
1148
- exit 1
1149
- ;;
1150
- esac
1151
- done
1152
-
1153
- ensure_templates
1154
- ensure_auxiliary_files
1155
- ensure_idle_todo
1156
- ensure_current_status_snapshot
1157
-
1158
- active_plan="$(get_active_plan || true)"
1159
- if [[ -n "$active_plan" && "$new_plan" -eq 0 ]]; then
1160
- echo "Workflow ready. Active plan: $active_plan"
1161
- exit 0
1162
- fi
1163
-
1164
- if [[ ! -f "docs/spec.md" ]]; then
1165
- if [[ -x "scripts/new-spec.sh" ]]; then
1166
- bash "scripts/new-spec.sh"
1167
- fi
1168
- fi
1169
-
1170
- if [[ -z "$slug" ]]; then
1171
- if [[ "$new_plan" -eq 1 ]]; then
1172
- echo "--new-plan requires --slug" >&2
1173
- exit 1
1174
- fi
1175
- echo "Workflow ready. No active plan present."
1176
- echo "Create one with: bash scripts/ensure-task-workflow.sh --slug <slug> --title <title>"
1177
- exit 0
1178
- fi
1179
-
1180
- slug="$(normalize_slug "$slug")"
1181
- if [[ -z "$slug" ]]; then
1182
- echo "Slug is empty after normalization" >&2
1183
- exit 1
1184
- fi
1185
-
1186
- if [[ -z "$title" ]]; then
1187
- title="$slug"
1188
- fi
1189
-
1190
- if [[ -x "scripts/new-plan.sh" ]]; then
1191
- bash "scripts/new-plan.sh" --slug "$slug" --title "$title"
1192
- else
1193
- echo "Missing scripts/new-plan.sh" >&2
1194
- exit 1
1195
- fi
4
+ exec "$SCRIPT_DIR/lib/run-forge-helper.sh" "ensure-task-workflow.sh" "$@"