forgedock 1.0.9 → 1.0.11

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.
@@ -0,0 +1,740 @@
1
+ # FORGE Annotation Protocol
2
+
3
+ **Version**: 1.0
4
+ **Status**: Draft
5
+ **License**: AGPL-3.0
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ The FORGE Annotation Protocol defines a machine-readable communication standard for AI development pipeline agents operating on GitHub. Agents write structured annotations as HTML comments inside GitHub issue and PR comments. Downstream agents read those annotations to reconstruct context — without relying on conversation history, shared memory, or a centralized server.
12
+
13
+ **Key properties**:
14
+ - **Transport**: Standard GitHub issue/PR comment API
15
+ - **Encoding**: HTML comment tags (`<!-- FORGE:TYPE -->`) containing Markdown body
16
+ - **Persistence**: GitHub issues/PRs are append-only — annotations survive compaction and session restarts
17
+ - **Query interface**: `gh` CLI with `--jq` filters on `.body | contains("FORGE:TYPE")`
18
+ - **Authoring agents**: Any AI agent that can write to the GitHub API
19
+ - **Reader agents**: Any AI agent that can read the GitHub API
20
+
21
+ The goal is interoperability: a pipeline agent from any tool (ForgeDock, Codex, aider, sweep, or a custom integration) should be able to produce and consume FORGE annotations, enabling chained multi-agent workflows where each agent picks up where the previous one left off.
22
+
23
+ ---
24
+
25
+ ## Syntax
26
+
27
+ Every annotation begins with an opening HTML comment tag on its own line:
28
+
29
+ ```
30
+ <!-- FORGE:{TYPE} -->
31
+ ```
32
+
33
+ The annotation body follows in Markdown. An annotation ends when the next `<!-- FORGE:` tag appears, or at the end of the comment. Completion sentinels use a `{TYPE}:COMPLETE` suffix:
34
+
35
+ ```
36
+ <!-- INVESTIGATION:COMPLETE -->
37
+ <!-- FORGE:CONTEXT:COMPLETE -->
38
+ <!-- FORGE:ARCHITECT:COMPLETE -->
39
+ <!-- FORGE:BUILDER:COMPLETE -->
40
+ <!-- FORGE:DECOMPOSED:COMPLETE -->
41
+ ```
42
+
43
+ **Partial annotations** (interrupted before completion) use `:PARTIAL`:
44
+
45
+ ```
46
+ <!-- FORGE:CONTEXT:PARTIAL -->
47
+ <!-- FORGE:ARCHITECT:PARTIAL -->
48
+ ```
49
+
50
+ An annotation comment without its completion sentinel indicates an interrupted run. Implementations SHOULD delete and restart partial annotations.
51
+
52
+ ---
53
+
54
+ ## Annotation Types
55
+
56
+ ### Issue Pipeline Annotations
57
+
58
+ These annotations are posted as GitHub **issue comments** and form the primary context chain for a pipeline run.
59
+
60
+ ---
61
+
62
+ #### `FORGE:INVESTIGATOR`
63
+
64
+ **Phase**: Investigation (Phase 1)
65
+ **Written by**: Investigator agent
66
+ **Read by**: Builder agent, Architect agent, Decomposer agent
67
+ **Completion sentinel**: `<!-- INVESTIGATION:COMPLETE -->`
68
+
69
+ Captures the outcome of investigating whether an issue is valid, what the root cause is, and what should be built.
70
+
71
+ **Schema**:
72
+
73
+ ```
74
+ <!-- FORGE:INVESTIGATOR -->
75
+ ## Investigation Report
76
+
77
+ **Verdict**: {CONFIRMED|PARTIAL|INVALID}
78
+ **Confidence**: {HIGH|MEDIUM|LOW}
79
+ **Severity**: {CRITICAL|HIGH|MEDIUM|LOW}
80
+ **Task Type**: {Bug Fix|Feature|Refactor|Maintenance|Investigation}
81
+
82
+ ### What Was Claimed
83
+ {Summary of what the issue describes}
84
+
85
+ ### What We Found
86
+ {What the code actually shows — specific evidence}
87
+
88
+ ### Root Cause
89
+ {Specific root cause with file:line references where applicable}
90
+
91
+ ### Affected Files
92
+ {Numbered list of files that need changes}
93
+
94
+ ### Evidence
95
+ {Specific findings — function names, line numbers, behavior observed}
96
+
97
+ ### Recommendation
98
+ {What to build or fix, concrete and actionable}
99
+
100
+ ### Related Issues
101
+ {Related issues found via domain context discovery, max 5}
102
+
103
+ ### Decomposition Assessment
104
+ **{YES|NO}** — {reason}
105
+ {If YES: proposed sub-issues with titles and dependencies}
106
+
107
+ <!-- INVESTIGATION:COMPLETE -->
108
+ ```
109
+
110
+ **Field semantics**:
111
+
112
+ | Field | Values | Required |
113
+ |-------|--------|----------|
114
+ | `Verdict` | `CONFIRMED` / `PARTIAL` / `INVALID` | Yes |
115
+ | `Confidence` | `HIGH` / `MEDIUM` / `LOW` | Yes |
116
+ | `Severity` | `CRITICAL` / `HIGH` / `MEDIUM` / `LOW` | Yes |
117
+ | `Task Type` | `Bug Fix` / `Feature` / `Refactor` / `Maintenance` / `Investigation` | Yes |
118
+ | `Decomposition Assessment` | `YES` or `NO` followed by reason | Yes |
119
+
120
+ **Routing rules**:
121
+ - `CONFIRMED` or `PARTIAL` with Decomposition = NO → proceed to build
122
+ - `CONFIRMED` or `PARTIAL` with Decomposition = YES → proceed to decomposition
123
+ - `INVALID` → close issue with explanation
124
+
125
+ **Detection query**:
126
+ ```bash
127
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
128
+ --jq '.[] | select(.body | contains("FORGE:INVESTIGATOR")) | .body'
129
+ ```
130
+
131
+ ---
132
+
133
+ #### `FORGE:DECOMPOSED`
134
+
135
+ **Phase**: Decomposition (Phase 2)
136
+ **Written by**: Decomposer agent
137
+ **Read by**: Orchestrator agent, parent issue tracker
138
+ **Completion sentinel**: `<!-- FORGE:DECOMPOSED:COMPLETE -->`
139
+
140
+ Posted on the parent issue after sub-issues are created. Signals that the issue has been decomposed and each sub-issue now runs its own pipeline.
141
+
142
+ **Schema**:
143
+
144
+ ```
145
+ <!-- FORGE:DECOMPOSED -->
146
+ ## Decomposition Complete
147
+
148
+ ### Sub-Issues Created
149
+ - #{NUMBER}: {TITLE}
150
+
151
+ ### Decomposition Rationale
152
+ {Brief summary explaining why decomposition was needed}
153
+
154
+ <!-- FORGE:DECOMPOSED:COMPLETE -->
155
+ ```
156
+
157
+ **Detection query**:
158
+ ```bash
159
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
160
+ --jq '.[] | select(.body | contains("FORGE:DECOMPOSED")) | .body'
161
+ ```
162
+
163
+ ---
164
+
165
+ #### `FORGE:CONTRACT`
166
+
167
+ **Phase**: Build — Contract (Phase 3C)
168
+ **Written by**: Builder agent
169
+ **Read by**: Builder agent (implementation phase), Review agents
170
+
171
+ Defines the scope of a build task before implementation begins. Acts as a binding agreement between the investigator's findings and what will actually be built.
172
+
173
+ **Schema**:
174
+
175
+ ```
176
+ <!-- FORGE:CONTRACT -->
177
+ ## Builder Contract
178
+
179
+ **Task type**: {TASK_TYPE}
180
+
181
+ ### Proposed Approach
182
+ {Brief description of the implementation approach}
183
+
184
+ ### Deliverables
185
+ | File | Change | Why |
186
+ |------|--------|-----|
187
+ | {filepath} | {what changes} | {why this change is needed} |
188
+
189
+ ### Acceptance Criteria
190
+ - [ ] {Specific, testable criterion}
191
+
192
+ ### Quality Considerations
193
+ {Auth model, new env vars, SQL safety, security surface, migration risk}
194
+
195
+ ### Out of Scope
196
+ {Items explicitly excluded from this PR}
197
+ ```
198
+
199
+ **Detection query**:
200
+ ```bash
201
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
202
+ --jq '.[] | select(.body | contains("FORGE:CONTRACT")) | .body'
203
+ ```
204
+
205
+ ---
206
+
207
+ #### `FORGE:CONTEXT`
208
+
209
+ **Phase**: Build — Context Gathering (Phase 3C.5)
210
+ **Written by**: Context agent
211
+ **Read by**: Builder agent (implementation phase)
212
+ **Completion sentinels**: `<!-- FORGE:CONTEXT:COMPLETE -->` (full), `<!-- FORGE:CONTEXT:PARTIAL -->` (time-limited)
213
+
214
+ Surfaces institutional memory before implementation begins. Aggregates past review findings, historical bugs, related code paths, and successful patterns from similar implementations.
215
+
216
+ **Schema**:
217
+
218
+ ```
219
+ <!-- FORGE:CONTEXT -->
220
+ ## Implementation Context for #{NUMBER}
221
+
222
+ ### Known Pitfalls for This Area
223
+ {Prevention rules from past review-findings on these files}
224
+
225
+ ### Historical Findings on These Files
226
+ {Past review-finding issues with pattern and prevention details}
227
+
228
+ ### Past Bugs in This Module
229
+ {Closed bug issues found via git log mining}
230
+
231
+ ### Related Code Paths (must stay consistent)
232
+ {Files that import or call the functions being changed}
233
+
234
+ ### Patterns That Cause Bugs Here
235
+ {Recurring bug types synthesized from historical findings}
236
+
237
+ ### Successful Similar Implementations
238
+ {Positive patterns from merged PRs in the same domain}
239
+
240
+ <!-- FORGE:CONTEXT:COMPLETE -->
241
+ ```
242
+
243
+ **Detection query**:
244
+ ```bash
245
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
246
+ --jq '.[] | select(.body | contains("FORGE:CONTEXT")) | .body'
247
+ ```
248
+
249
+ ---
250
+
251
+ #### `FORGE:ARCHITECT`
252
+
253
+ **Phase**: Build — Architecture Plan (Phase 3C.6)
254
+ **Written by**: Architect agent
255
+ **Read by**: Builder agent (implementation phase — primary input)
256
+ **Completion sentinels**: `<!-- FORGE:ARCHITECT:COMPLETE -->` (full), `<!-- FORGE:ARCHITECT:PARTIAL -->` (time-limited)
257
+
258
+ Contains the ordered implementation plan. The builder agent follows this plan exactly when present. It traces all affected code paths, establishes consistency rules, sequences changes, and assesses risks.
259
+
260
+ **Schema**:
261
+
262
+ ```
263
+ <!-- FORGE:ARCHITECT -->
264
+ ## Implementation Plan for #{NUMBER}
265
+
266
+ ### Affected Paths (ALL must be updated)
267
+ | # | File | Function/Class | Change Required | Why |
268
+ |---|------|----------------|-----------------|-----|
269
+ | 1 | {filepath} | {function or class} | {what to change} | {reason} |
270
+
271
+ ### Implementation Order
272
+ 1. {First change} — {why first}
273
+ 2. {Second change} — {why second}
274
+
275
+ ### Consistency Checks
276
+ - [ ] {Invariant that all paths must satisfy}
277
+
278
+ ### Risk Assessment
279
+ | Risk | Severity | Mitigation |
280
+ |------|----------|------------|
281
+ | {risk description} | HIGH/MEDIUM/LOW | {mitigation} |
282
+
283
+ ### Files to Read Before Coding
284
+ - `{filepath}` — {why to read it}
285
+
286
+ <!-- FORGE:ARCHITECT:COMPLETE -->
287
+ ```
288
+
289
+ **Detection query**:
290
+ ```bash
291
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
292
+ --jq '.[] | select(.body | contains("FORGE:ARCHITECT")) | .body'
293
+ ```
294
+
295
+ ---
296
+
297
+ #### `FORGE:BUILDER`
298
+
299
+ **Phase**: Build — Implementation Complete (Phase 3M)
300
+ **Written by**: Builder agent
301
+ **Read by**: Review agents, Close phase agent
302
+ **Completion sentinel**: `<!-- FORGE:BUILDER:COMPLETE -->`
303
+
304
+ Posted after all implementation work is done and committed. Captures the branch, commits, files changed, and testing checklist. This is the primary handoff annotation to the review phase.
305
+
306
+ **Schema**:
307
+
308
+ ```
309
+ <!-- FORGE:BUILDER -->
310
+ ## Implementation Complete
311
+
312
+ **Branch**: `{branch-name}`
313
+ **Commits**: {commit SHA(s)}
314
+ **Files changed**: {count}
315
+
316
+ ### Approach
317
+ {What was built, key decisions made}
318
+
319
+ ### Changes
320
+ - `{filepath}` — {what changed}
321
+
322
+ ### Acceptance Criteria Status
323
+ - [x] {criterion} — PASS
324
+ - [ ] {criterion} — FAIL (reason)
325
+
326
+ ### Testing Checklist
327
+ - [ ] {test scenario}
328
+
329
+ <!-- FORGE:BUILDER:COMPLETE -->
330
+ ```
331
+
332
+ **Detection query**:
333
+ ```bash
334
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
335
+ --jq '.[] | select(.body | contains("FORGE:BUILDER")) | .body'
336
+ ```
337
+
338
+ ---
339
+
340
+ #### `FORGE:REVIEW_STARTED`
341
+
342
+ **Phase**: Review (Phase 5B)
343
+ **Written by**: Orchestrator agent
344
+
345
+ Signals that the review phase has been invoked. Posted on the issue immediately before calling the review agent. Used to detect whether a review was initiated after compaction.
346
+
347
+ **Schema**:
348
+
349
+ ```
350
+ ## Submitting for Review
351
+
352
+ PR #{PR_NUMBER} created targeting `{base-branch}`. Invoking /review-pr with --auto-merge.
353
+
354
+ <!-- FORGE:REVIEW_STARTED -->
355
+ ```
356
+
357
+ **Detection query**:
358
+ ```bash
359
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
360
+ --jq '.[] | select(.body | contains("FORGE:REVIEW_STARTED")) | .body'
361
+ ```
362
+
363
+ ---
364
+
365
+ #### `FORGE:TRAJECTORY`
366
+
367
+ **Phase**: Summary (Phase 7)
368
+ **Written by**: Orchestrator agent
369
+
370
+ Records the complete pipeline run as an audit trail. One `FORGE:TRAJECTORY` comment per issue lifecycle. Includes phase-by-phase results, decisions, and anomalies.
371
+
372
+ **Schema**:
373
+
374
+ ```
375
+ <!-- FORGE:TRAJECTORY -->
376
+ ## Pipeline Trajectory — #{NUMBER}
377
+
378
+ | Phase | Result | Notes |
379
+ |-------|--------|-------|
380
+ | Phase 0: Context Load | ✅ Complete | {lane} → `{base-branch}` |
381
+ | Phase 1: Investigation | ✅ {VERDICT} ({CONFIDENCE}) | Task type: {TASK_TYPE} |
382
+ | Phase 2: Decomposition | ⏭ Skipped | {reason} |
383
+ | Phase 3: Build | ✅ Complete | Branch: `{branch}` |
384
+ | Phase 3G: Quality Gate | ✅ Gate passed | {N} iterations |
385
+ | Phase 4–5: Review + PR | ✅ Merged | PR #{PR_NUMBER} → `{base-branch}` |
386
+ | Phase 6: Close | ✅ Complete | Issue closed |
387
+
388
+ **Decisions**: {key decisions made during the run}
389
+ **Anomalies**: {anomalies or None}
390
+ **Pipeline completed**: {ISO 8601 timestamp}
391
+ ```
392
+
393
+ **Detection query**:
394
+ ```bash
395
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
396
+ --jq '.[] | select(.body | contains("FORGE:TRAJECTORY")) | .body'
397
+ ```
398
+
399
+ ---
400
+
401
+ ### Orchestration / Milestone Annotations
402
+
403
+ These annotations transfer investigation context across issue boundaries in decomposed or multi-issue milestone workflows.
404
+
405
+ ---
406
+
407
+ #### `FORGE:KNOWLEDGE_GIST`
408
+
409
+ **Phase**: Investigation — Knowledge Persistence (Phase 1C.5)
410
+ **Written by**: Investigator agent
411
+ **Read by**: Decomposer agent, Builder agent (via `FORGE:PRIOR_GIST`)
412
+ **Location**: Issue comment
413
+
414
+ Posted after investigation completes. Contains a URL to a GitHub Gist that holds the full investigation findings as a stable, linkable artifact. Downstream sub-issues embed the Gist URL as `FORGE:PRIOR_GIST` annotations so builders can fetch prior context.
415
+
416
+ **Schema**:
417
+
418
+ ```
419
+ <!-- FORGE:KNOWLEDGE_GIST: {https://gist.github.com/...} -->
420
+ ## Knowledge Gist Created
421
+
422
+ Investigation findings persisted as a linkable artifact.
423
+
424
+ **Gist**: {URL}
425
+ **Filename**: `{repo}_{issue_number}_{slug}.md`
426
+
427
+ _This Gist can be referenced by downstream issues for context transfer._
428
+ ```
429
+
430
+ **Gist content schema** (YAML frontmatter + Markdown body):
431
+
432
+ ```yaml
433
+ ---
434
+ issue: {NUMBER}
435
+ repo: {OWNER}/{REPO}
436
+ milestone: {MILESTONE_TITLE}
437
+ verdict: {CONFIRMED|PARTIAL|INVALID}
438
+ task_type: {TASK_TYPE}
439
+ confidence: {HIGH|MEDIUM|LOW}
440
+ severity: {CRITICAL|HIGH|MEDIUM|LOW}
441
+ created: {ISO 8601 timestamp}
442
+ source: FORGE:INVESTIGATOR
443
+ ---
444
+ ```
445
+
446
+ **Detection query**:
447
+ ```bash
448
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
449
+ --jq '[.[] | select(.body | test("<!-- FORGE:KNOWLEDGE_GIST: https://")) |
450
+ .body | capture("<!-- FORGE:KNOWLEDGE_GIST: (?<url>https://[^ ]+) -->").url] |
451
+ unique | .[]'
452
+ ```
453
+
454
+ ---
455
+
456
+ #### `FORGE:MILESTONE_INDEX`
457
+
458
+ **Phase**: Investigation — Milestone Index (Phase 1C.6)
459
+ **Written by**: Investigator agent
460
+ **Read by**: Builder agent (via milestone description lookup)
461
+ **Location**: GitHub Milestone description field (not issue comment)
462
+
463
+ A URL embedded in the milestone description pointing to an index Gist. The index aggregates all `FORGE:KNOWLEDGE_GIST` URLs for a milestone, giving any agent working on any milestone issue access to all prior investigations in one fetch.
464
+
465
+ **Syntax** (in milestone description):
466
+
467
+ ```
468
+ <!-- FORGE:MILESTONE_INDEX: {https://gist.github.com/...} -->
469
+ ```
470
+
471
+ **Detection query**:
472
+ ```bash
473
+ gh api repos/{OWNER}/{REPO}/milestones/{MILESTONE_NUMBER} \
474
+ --jq '.description' | \
475
+ grep -oP '(?<=<!-- FORGE:MILESTONE_INDEX: )https://[^ ]+(?= -->)'
476
+ ```
477
+
478
+ ---
479
+
480
+ #### `FORGE:PRIOR_GIST`
481
+
482
+ **Phase**: Decomposition (Phase 2C)
483
+ **Written by**: Decomposer agent
484
+ **Read by**: Builder agent (context phase)
485
+ **Location**: Sub-issue body
486
+
487
+ Embedded in sub-issue bodies by the decomposer. Points to the parent issue's Knowledge Gist. Allows the builder working on a sub-issue to fetch upstream investigation context without navigating the parent issue.
488
+
489
+ **Syntax** (in sub-issue body):
490
+
491
+ ```
492
+ <!-- FORGE:PRIOR_GIST: {https://gist.github.com/...} -->
493
+ ```
494
+
495
+ **Detection query** (from sub-issue body):
496
+ ```bash
497
+ gh issue view {NUMBER} -R {OWNER}/{REPO} --json body --jq '.body' | \
498
+ grep -oP '(?<=<!-- FORGE:PRIOR_GIST: )https://[^ ]+(?= -->)'
499
+ ```
500
+
501
+ ---
502
+
503
+ ### Pipeline Control Markers
504
+
505
+ These annotations appear inside command specification files (not issue comments) to mark phase boundaries and error states.
506
+
507
+ ---
508
+
509
+ #### `FORGE:DISPATCHER`
510
+
511
+ **Location**: Pipeline command spec (e.g., `work-on.md`)
512
+ **Purpose**: Marks the Universal Phase Dispatcher — the single source of truth for phase transitions and routing logic.
513
+
514
+ ```
515
+ <!-- FORGE:DISPATCHER — {description} -->
516
+ ```
517
+
518
+ ---
519
+
520
+ #### `FORGE:PHASE_COMPLETE`
521
+
522
+ **Location**: Pipeline command spec
523
+ **Purpose**: Inter-phase boundary annotation. Documents that a phase has completed and identifies the next phase. Used to prevent agents from misinterpreting intermediate results as terminal states.
524
+
525
+ ```
526
+ <!-- FORGE:PHASE_COMPLETE — {description of what completed}. See Universal Phase Dispatcher: next phase is {NEXT_PHASE}. Not terminal — continue immediately. -->
527
+ ```
528
+
529
+ ---
530
+
531
+ #### Error State Markers
532
+
533
+ Posted to issue comments when pipeline operations fail hard. Signal that human intervention is needed.
534
+
535
+ | Annotation | Trigger |
536
+ |-----------|---------|
537
+ | `<!-- FORGE:ANCESTRY_FAILED -->` | Post-commit ancestry audit found merge commits in the branch |
538
+ | `<!-- FORGE:GATE_FAILED -->` | Quality gate failed after maximum retry iterations |
539
+ | `<!-- FORGE:PUSH_BLOCKED -->` | Branch push blocked (e.g., protected branch policy) |
540
+ | `<!-- FORGE:PUSH_FAILED -->` | Branch push failed after `--force-with-lease` retry |
541
+
542
+ ---
543
+
544
+ ### Audit Annotations
545
+
546
+ ---
547
+
548
+ #### `FORGE:AUDIT`
549
+
550
+ **Written by**: Audit command agents
551
+ **Location**: Issue or PR comment
552
+
553
+ Posted by `/audit` and `/audit-agents` commands after running structured code audits.
554
+
555
+ ---
556
+
557
+ #### `FORGE:SECURITY_AUDIT`
558
+
559
+ **Written by**: Security audit command
560
+ **Location**: Issue comment
561
+
562
+ Posted by `/security-audit` after completing a 4-phase security posture audit.
563
+
564
+ ---
565
+
566
+ ## Context-Passing Chain
567
+
568
+ The annotations form an ordered context chain. Each phase reads the outputs of all preceding phases:
569
+
570
+ ```
571
+ Issue body
572
+ ↓
573
+ FORGE:INVESTIGATOR (Phase 1 → written to issue)
574
+ ↓
575
+ FORGE:DECOMPOSED (Phase 2 → written to issue, if decomposed)
576
+ ↓
577
+ FORGE:CONTRACT (Phase 3C → written to issue)
578
+ ↓
579
+ FORGE:CONTEXT (Phase 3C.5 → written to issue)
580
+ ↓
581
+ FORGE:ARCHITECT (Phase 3C.6 → written to issue)
582
+ ↓
583
+ FORGE:BUILDER (Phase 3M → written to issue)
584
+ ↓
585
+ FORGE:REVIEW_STARTED (Phase 5B → written to issue)
586
+ ↓
587
+ FORGE:TRAJECTORY (Phase 7 → written to issue)
588
+ ```
589
+
590
+ **Cross-issue context** (milestone / decomposed workflows):
591
+
592
+ ```
593
+ Parent: FORGE:INVESTIGATOR → FORGE:KNOWLEDGE_GIST (Gist URL)
594
+ ↓
595
+ Milestone description: FORGE:MILESTONE_INDEX (index Gist URL)
596
+ ↓
597
+ Sub-issue body: FORGE:PRIOR_GIST (URL from parent's Knowledge Gist)
598
+ ↓
599
+ Sub-issue: FORGE:CONTEXT reads FORGE:PRIOR_GIST to fetch upstream context
600
+ ```
601
+
602
+ ---
603
+
604
+ ## Label State Machine
605
+
606
+ In addition to annotations, FORGE-compliant pipelines track state via GitHub labels. Labels allow agents to determine the current phase without reading all comment history.
607
+
608
+ | Label | Meaning | Set by |
609
+ |-------|---------|--------|
610
+ | `workflow:investigating` | Investigation phase active | Investigator agent |
611
+ | `workflow:ready-to-build` | Investigation complete, build not started | Investigator agent |
612
+ | `workflow:building` | Build phase active | Builder agent |
613
+ | `workflow:in-review` | PR created, review active | Orchestrator agent |
614
+ | `workflow:merged` | PR merged, issue closed | Close phase agent |
615
+ | `workflow:invalid` | Issue closed as invalid | Investigator agent |
616
+ | `workflow:decomposed` | Issue decomposed into sub-issues | Decomposer agent |
617
+ | `needs-human` | Pipeline blocked, human intervention required | Any agent on error |
618
+
619
+ **Terminal labels** (pipeline stops when these are set):
620
+
621
+ - `workflow:merged`
622
+ - `workflow:invalid`
623
+ - `needs-human`
624
+ - `workflow:decomposed`
625
+
626
+ ---
627
+
628
+ ## Conformance
629
+
630
+ A conformant FORGE implementation:
631
+
632
+ 1. **Writes** annotations with the exact `<!-- FORGE:{TYPE} -->` opening tag
633
+ 2. **Reads** annotations using `.body | contains("FORGE:{TYPE}")` filtering
634
+ 3. **Honors** completion sentinels — does not proceed as if an annotation is complete when its sentinel is absent
635
+ 4. **Deletes and restarts** interrupted partial annotations before continuing a phase
636
+ 5. **Skips** phases that have a complete annotation already present (idempotent)
637
+ 6. **Writes** state to GitHub after every significant step (compaction resilience)
638
+ 7. **Re-reads** GitHub state at the start of each phase (does not rely on in-memory context)
639
+
640
+ ### Conformance Test: Annotation Presence
641
+
642
+ To verify that a pipeline run wrote all expected annotations for a completed issue:
643
+
644
+ ```bash
645
+ OWNER="your-org"
646
+ REPO="your-repo"
647
+ NUMBER=42
648
+
649
+ # Required annotations for a complete non-decomposed run
650
+ REQUIRED=("FORGE:INVESTIGATOR" "FORGE:CONTRACT" "FORGE:CONTEXT" "FORGE:ARCHITECT" "FORGE:BUILDER" "FORGE:TRAJECTORY")
651
+
652
+ for annotation in "${REQUIRED[@]}"; do
653
+ COUNT=$(gh api repos/${OWNER}/${REPO}/issues/${NUMBER}/comments \
654
+ --jq "[.[] | select(.body | contains(\"${annotation}\"))] | length")
655
+ if [ "$COUNT" -gt 0 ]; then
656
+ echo "✅ ${annotation} — present (${COUNT} comment(s))"
657
+ else
658
+ echo "❌ ${annotation} — MISSING"
659
+ fi
660
+ done
661
+ ```
662
+
663
+ ### Conformance Test: Completion Sentinels
664
+
665
+ ```bash
666
+ # Check that FORGE:INVESTIGATOR has INVESTIGATION:COMPLETE sentinel
667
+ BODY=$(gh api repos/${OWNER}/${REPO}/issues/${NUMBER}/comments \
668
+ --jq '.[] | select(.body | contains("FORGE:INVESTIGATOR")) | .body' | head -1)
669
+
670
+ if echo "$BODY" | grep -q "INVESTIGATION:COMPLETE"; then
671
+ echo "✅ FORGE:INVESTIGATOR — complete"
672
+ else
673
+ echo "❌ FORGE:INVESTIGATOR — incomplete (missing sentinel)"
674
+ fi
675
+ ```
676
+
677
+ ### Conformance Test: Label State
678
+
679
+ ```bash
680
+ # Verify terminal state was reached
681
+ LABELS=$(gh issue view ${NUMBER} -R ${OWNER}/${REPO} --json labels \
682
+ --jq '[.labels[].name | select(startswith("workflow:"))]')
683
+
684
+ TERMINAL=("workflow:merged" "workflow:invalid" "workflow:decomposed")
685
+ for label in "${TERMINAL[@]}"; do
686
+ if echo "$LABELS" | grep -q "$label"; then
687
+ echo "✅ Terminal label: ${label}"
688
+ exit 0
689
+ fi
690
+ done
691
+ echo "⚠ No terminal label found — pipeline may be incomplete"
692
+ ```
693
+
694
+ ---
695
+
696
+ ## Implementing FORGE in Your Tool
697
+
698
+ To make your AI coding tool FORGE-compatible:
699
+
700
+ 1. **Read existing annotations** before starting work on an issue:
701
+ ```bash
702
+ gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
703
+ --jq '.[] | {id: .id, body: .body}' | \
704
+ grep -A 999 "FORGE:"
705
+ ```
706
+
707
+ 2. **Write annotations** in the correct format after completing each phase. Use the schemas in this document.
708
+
709
+ 3. **Check for existing annotations** before writing (idempotency):
710
+ ```bash
711
+ # Don't write FORGE:INVESTIGATOR if one already exists with INVESTIGATION:COMPLETE
712
+ EXISTING=$(gh api repos/{OWNER}/{REPO}/issues/{NUMBER}/comments \
713
+ --jq '.[] | select(.body | contains("FORGE:INVESTIGATOR") and contains("INVESTIGATION:COMPLETE")) | .id')
714
+ if [ -n "$EXISTING" ]; then echo "Already investigated — skip"; fi
715
+ ```
716
+
717
+ 4. **Respect label state** — check `workflow:*` labels to determine where the pipeline is and whether it's in a terminal state.
718
+
719
+ 5. **Use the `gh` CLI** as the primary query interface. All FORGE implementations can assume `gh` is available.
720
+
721
+ ---
722
+
723
+ ## Versioning
724
+
725
+ This document describes FORGE Protocol **version 1.0**. Future revisions will:
726
+
727
+ - Increment the minor version for backward-compatible additions (new annotation types, new optional fields)
728
+ - Increment the major version for breaking changes (renamed annotations, removed required fields)
729
+
730
+ Annotations do not carry an explicit version field. Conformant readers MUST tolerate unknown annotation types gracefully (skip, don't fail).
731
+
732
+ ---
733
+
734
+ ## Reference
735
+
736
+ - [ForgeDock repository](https://github.com/RapierCraftStudios/ForgeDock)
737
+ - [ForgeDock commands](https://github.com/RapierCraftStudios/ForgeDock/tree/main/commands)
738
+ - [`work-on.md`](../commands/work-on.md) — Full pipeline implementation reference
739
+ - [`review-pr.md`](../commands/review-pr.md) — Review phase implementation reference
740
+ - [`autopilot.md`](../commands/autopilot.md) — Orchestration and milestone index implementation