@entelligentsia/forgecli 0.10.1 → 0.11.2

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 (161) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/README.md +21 -3
  3. package/dist/CHANGELOG-forge-plugin.md +22 -0
  4. package/dist/extensions/forgecli/add-pipeline.d.ts +19 -0
  5. package/dist/extensions/forgecli/add-pipeline.js +143 -0
  6. package/dist/extensions/forgecli/add-pipeline.js.map +1 -0
  7. package/dist/extensions/forgecli/add-task.d.ts +20 -0
  8. package/dist/extensions/forgecli/add-task.js +154 -0
  9. package/dist/extensions/forgecli/add-task.js.map +1 -0
  10. package/dist/extensions/forgecli/calibrate.d.ts +61 -0
  11. package/dist/extensions/forgecli/calibrate.js +488 -0
  12. package/dist/extensions/forgecli/calibrate.js.map +1 -0
  13. package/dist/extensions/forgecli/fix-bug.d.ts +9 -1
  14. package/dist/extensions/forgecli/fix-bug.js +70 -8
  15. package/dist/extensions/forgecli/fix-bug.js.map +1 -1
  16. package/dist/extensions/forgecli/forge-commands.js +15 -22
  17. package/dist/extensions/forgecli/forge-commands.js.map +1 -1
  18. package/dist/extensions/forgecli/forge-subagent.js +34 -7
  19. package/dist/extensions/forgecli/forge-subagent.js.map +1 -1
  20. package/dist/extensions/forgecli/forge-update-command.d.ts +9 -0
  21. package/dist/extensions/forgecli/forge-update-command.js +106 -7
  22. package/dist/extensions/forgecli/forge-update-command.js.map +1 -1
  23. package/dist/extensions/forgecli/health-check.d.ts +22 -1
  24. package/dist/extensions/forgecli/health-check.js +177 -4
  25. package/dist/extensions/forgecli/health-check.js.map +1 -1
  26. package/dist/extensions/forgecli/hook-dispatcher.d.ts +25 -1
  27. package/dist/extensions/forgecli/hook-dispatcher.js +104 -9
  28. package/dist/extensions/forgecli/hook-dispatcher.js.map +1 -1
  29. package/dist/extensions/forgecli/hooks/check-update.d.ts +81 -0
  30. package/dist/extensions/forgecli/hooks/check-update.js +308 -0
  31. package/dist/extensions/forgecli/hooks/check-update.js.map +1 -0
  32. package/dist/extensions/forgecli/hooks/forge-permissions.d.ts +32 -0
  33. package/dist/extensions/forgecli/hooks/forge-permissions.js +119 -0
  34. package/dist/extensions/forgecli/hooks/forge-permissions.js.map +1 -0
  35. package/dist/extensions/forgecli/hooks/triage-error.d.ts +23 -0
  36. package/dist/extensions/forgecli/hooks/triage-error.js +62 -0
  37. package/dist/extensions/forgecli/hooks/triage-error.js.map +1 -0
  38. package/dist/extensions/forgecli/hooks/write-guard.d.ts +28 -0
  39. package/dist/extensions/forgecli/hooks/write-guard.js +225 -0
  40. package/dist/extensions/forgecli/hooks/write-guard.js.map +1 -0
  41. package/dist/extensions/forgecli/index.js +60 -0
  42. package/dist/extensions/forgecli/index.js.map +1 -1
  43. package/dist/extensions/forgecli/init-context.d.ts +1 -1
  44. package/dist/extensions/forgecli/init-context.js +21 -6
  45. package/dist/extensions/forgecli/init-context.js.map +1 -1
  46. package/dist/extensions/forgecli/materialize.d.ts +16 -0
  47. package/dist/extensions/forgecli/materialize.js +195 -0
  48. package/dist/extensions/forgecli/materialize.js.map +1 -0
  49. package/dist/extensions/forgecli/migrate.d.ts +19 -0
  50. package/dist/extensions/forgecli/migrate.js +258 -0
  51. package/dist/extensions/forgecli/migrate.js.map +1 -0
  52. package/dist/extensions/forgecli/migration-engine.d.ts +111 -0
  53. package/dist/extensions/forgecli/migration-engine.js +533 -0
  54. package/dist/extensions/forgecli/migration-engine.js.map +1 -0
  55. package/dist/extensions/forgecli/quiz-agent.d.ts +17 -0
  56. package/dist/extensions/forgecli/quiz-agent.js +98 -0
  57. package/dist/extensions/forgecli/quiz-agent.js.map +1 -0
  58. package/dist/extensions/forgecli/remove-command.d.ts +17 -0
  59. package/dist/extensions/forgecli/remove-command.js +124 -0
  60. package/dist/extensions/forgecli/remove-command.js.map +1 -0
  61. package/dist/extensions/forgecli/report-bug.d.ts +25 -0
  62. package/dist/extensions/forgecli/report-bug.js +159 -0
  63. package/dist/extensions/forgecli/report-bug.js.map +1 -0
  64. package/dist/extensions/forgecli/retrospective.d.ts +19 -0
  65. package/dist/extensions/forgecli/retrospective.js +156 -0
  66. package/dist/extensions/forgecli/retrospective.js.map +1 -0
  67. package/dist/extensions/forgecli/run-sprint.js +34 -0
  68. package/dist/extensions/forgecli/run-sprint.js.map +1 -1
  69. package/dist/extensions/forgecli/run-task.d.ts +9 -1
  70. package/dist/extensions/forgecli/run-task.js +64 -10
  71. package/dist/extensions/forgecli/run-task.js.map +1 -1
  72. package/dist/extensions/forgecli/session-registry.d.ts +27 -2
  73. package/dist/extensions/forgecli/session-registry.js +52 -1
  74. package/dist/extensions/forgecli/session-registry.js.map +1 -1
  75. package/dist/extensions/forgecli/status-command.d.ts +19 -0
  76. package/dist/extensions/forgecli/status-command.js +140 -0
  77. package/dist/extensions/forgecli/status-command.js.map +1 -0
  78. package/dist/extensions/forgecli/store-query.d.ts +22 -0
  79. package/dist/extensions/forgecli/store-query.js +107 -0
  80. package/dist/extensions/forgecli/store-query.js.map +1 -0
  81. package/dist/extensions/forgecli/store-repair.d.ts +17 -0
  82. package/dist/extensions/forgecli/store-repair.js +123 -0
  83. package/dist/extensions/forgecli/store-repair.js.map +1 -0
  84. package/dist/extensions/forgecli/thread-switcher.js +213 -28
  85. package/dist/extensions/forgecli/thread-switcher.js.map +1 -1
  86. package/dist/extensions/forgecli/update-tools.d.ts +23 -0
  87. package/dist/extensions/forgecli/update-tools.js +136 -0
  88. package/dist/extensions/forgecli/update-tools.js.map +1 -0
  89. package/dist/extensions/forgecli/viewport-theme.js +4 -0
  90. package/dist/extensions/forgecli/viewport-theme.js.map +1 -1
  91. package/dist/forge-payload/.claude-plugin/plugin.json +1 -1
  92. package/dist/forge-payload/.schemas/config.schema.json +83 -0
  93. package/dist/forge-payload/.schemas/migrations.json +2049 -0
  94. package/dist/forge-payload/commands/regenerate.md +17 -1
  95. package/dist/forge-payload/meta/personas/README.md +16 -0
  96. package/dist/forge-payload/meta/personas/meta-architect.md +70 -0
  97. package/dist/forge-payload/meta/personas/meta-bug-fixer.md +73 -0
  98. package/dist/forge-payload/meta/personas/meta-collator.md +72 -0
  99. package/dist/forge-payload/meta/personas/meta-engineer.md +70 -0
  100. package/dist/forge-payload/meta/personas/meta-orchestrator.md +71 -0
  101. package/dist/forge-payload/meta/personas/meta-product-manager.md +82 -0
  102. package/dist/forge-payload/meta/personas/meta-qa-engineer.md +91 -0
  103. package/dist/forge-payload/meta/personas/meta-supervisor.md +92 -0
  104. package/dist/forge-payload/meta/skill-recommendations.md +154 -0
  105. package/dist/forge-payload/meta/skills/meta-architect-skills.md +43 -0
  106. package/dist/forge-payload/meta/skills/meta-bug-fixer-skills.md +43 -0
  107. package/dist/forge-payload/meta/skills/meta-collator-skills.md +41 -0
  108. package/dist/forge-payload/meta/skills/meta-engineer-skills.md +43 -0
  109. package/dist/forge-payload/meta/skills/meta-generic-skills.md +58 -0
  110. package/dist/forge-payload/meta/skills/meta-qa-engineer-skills.md +46 -0
  111. package/dist/forge-payload/meta/skills/meta-supervisor-skills.md +43 -0
  112. package/dist/forge-payload/meta/store-schema/bug.schema.md +71 -0
  113. package/dist/forge-payload/meta/store-schema/event.schema.md +76 -0
  114. package/dist/forge-payload/meta/store-schema/feature.schema.md +65 -0
  115. package/dist/forge-payload/meta/store-schema/sprint.schema.md +64 -0
  116. package/dist/forge-payload/meta/store-schema/task.schema.md +78 -0
  117. package/dist/forge-payload/meta/templates/meta-code-review.md +26 -0
  118. package/dist/forge-payload/meta/templates/meta-plan-review.md +28 -0
  119. package/dist/forge-payload/meta/templates/meta-plan.md +28 -0
  120. package/dist/forge-payload/meta/templates/meta-progress.md +25 -0
  121. package/dist/forge-payload/meta/templates/meta-retrospective.md +28 -0
  122. package/dist/forge-payload/meta/templates/meta-sprint-manifest.md +26 -0
  123. package/dist/forge-payload/meta/templates/meta-sprint-requirements.md +91 -0
  124. package/dist/forge-payload/meta/templates/meta-task-prompt.md +26 -0
  125. package/dist/forge-payload/meta/tool-specs/collate.spec.md +88 -0
  126. package/dist/forge-payload/meta/tool-specs/generation-manifest.spec.md +139 -0
  127. package/dist/forge-payload/meta/tool-specs/manage-config.spec.md +143 -0
  128. package/dist/forge-payload/meta/tool-specs/seed-store.spec.md +91 -0
  129. package/dist/forge-payload/meta/tool-specs/store-cli.spec.md +328 -0
  130. package/dist/forge-payload/meta/tool-specs/validate-store.spec.md +191 -0
  131. package/dist/forge-payload/meta/workflows/_fragments/context-injection.md +75 -0
  132. package/dist/forge-payload/meta/workflows/_fragments/event-emission-schema.md +73 -0
  133. package/dist/forge-payload/meta/workflows/_fragments/finalize.md +13 -0
  134. package/dist/forge-payload/meta/workflows/_fragments/friction-emit.md +73 -0
  135. package/dist/forge-payload/meta/workflows/_fragments/progress-reporting.md +38 -0
  136. package/dist/forge-payload/meta/workflows/_fragments/store-cli-verbs.md +39 -0
  137. package/dist/forge-payload/meta/workflows/meta-approve.md +119 -0
  138. package/dist/forge-payload/meta/workflows/meta-collate.md +89 -0
  139. package/dist/forge-payload/meta/workflows/meta-commit.md +93 -0
  140. package/dist/forge-payload/meta/workflows/meta-enhance.md +286 -0
  141. package/dist/forge-payload/meta/workflows/meta-fix-bug.md +501 -0
  142. package/dist/forge-payload/meta/workflows/meta-implement.md +132 -0
  143. package/dist/forge-payload/meta/workflows/meta-migrate.md +455 -0
  144. package/dist/forge-payload/meta/workflows/meta-orchestrate.md +993 -0
  145. package/dist/forge-payload/meta/workflows/meta-plan-task.md +133 -0
  146. package/dist/forge-payload/meta/workflows/meta-quiz-agent.md +135 -0
  147. package/dist/forge-payload/meta/workflows/meta-retrospective.md +65 -0
  148. package/dist/forge-payload/meta/workflows/meta-review-implementation.md +119 -0
  149. package/dist/forge-payload/meta/workflows/meta-review-plan.md +108 -0
  150. package/dist/forge-payload/meta/workflows/meta-review-sprint-completion.md +65 -0
  151. package/dist/forge-payload/meta/workflows/meta-sprint-intake.md +76 -0
  152. package/dist/forge-payload/meta/workflows/meta-sprint-plan.md +147 -0
  153. package/dist/forge-payload/meta/workflows/meta-update-implementation.md +76 -0
  154. package/dist/forge-payload/meta/workflows/meta-update-plan.md +76 -0
  155. package/dist/forge-payload/meta/workflows/meta-validate.md +111 -0
  156. package/dist/forge-payload/tools/check-structure.cjs +344 -0
  157. package/dist/forge-payload/tools/list-skills.js +76 -0
  158. package/dist/forge-payload/tools/store-cli.cjs +27 -1
  159. package/dist/forge-payload/tools/substitute-placeholders.cjs +60 -8
  160. package/dist/forge-payload/tools/verify-integrity.cjs +86 -0
  161. package/package.json +2 -2
@@ -0,0 +1,89 @@
1
+ ---
2
+ requirements:
3
+ reasoning: Medium
4
+ context: Low
5
+ speed: High
6
+ deps:
7
+ personas: [collator]
8
+ skills: [collator, generic]
9
+ templates: []
10
+ sub_workflows: []
11
+ kb_docs: [MASTER_INDEX.md]
12
+ config_fields: [paths.engineering]
13
+ ---
14
+
15
+ # 🍃 Meta-Workflow: Collate
16
+
17
+ ## Purpose
18
+
19
+ Regenerate markdown views from the JSON store. This is a deterministic operation — prefer the generated tool, fall back to manual collation.
20
+
21
+ ## Iron Laws
22
+
23
+ - Collation is a read-and-rewrite of generated markdown. Do not mutate any JSON record under `.forge/store/`; the store is the source of truth and collation flows downstream from it.
24
+ - Read `.forge/personas/collator.md` first; print the persona identity line (emoji, name, tagline) to stdout before any other tool use.
25
+ - All store reads via `forge_store` (or `node "$FORGE_ROOT/tools/store-cli.cjs"`). Never edit `.forge/store/*.json` directly.
26
+
27
+ ## Store-Write Verification
28
+
29
+ Collation typically writes markdown views, not JSON records. If a remediation
30
+ step does call `forge_store` and the call exits non-zero or the `PreToolUse`
31
+ write-boundary hook blocks the call (exit 2):
32
+
33
+ 1. Parse the structured error (names the offending field + schema file).
34
+ 2. Correct the JSON to satisfy the schema.
35
+ 3. Retry. Repeat up to 3 times.
36
+ 4. After 3 failures, halt and escalate with original payload, corrected payload, and all error messages.
37
+
38
+ Never set `FORGE_SKIP_WRITE_VALIDATION=1` — operator-only emergency switch.
39
+
40
+ ## Algorithm
41
+
42
+ ```
43
+ 1. Preferred: Run Plugin Tool
44
+ - Read `paths.forgeRoot` from `.forge/config.json` as `FORGE_ROOT`
45
+ - Run: `node "$FORGE_ROOT/tools/collate.cjs" [SPRINT_ID]`
46
+ - If tool succeeds, proceed to Finalize
47
+
48
+ 2. Fallback: Manual Collation
49
+ - Read `.forge/config.json` for prefix, paths, project description
50
+ - Read all sprint/task/bug/event JSONs from `.forge/store/`
51
+ - Generate MASTER_INDEX.md (sprint registry, task registry, bug registry)
52
+ - Generate per-sprint TIMESHEET.md (from events)
53
+ - Generate any other configured views
54
+
55
+ 3. Rebuild context pack:
56
+ - Rebuild the architecture context pack so orchestrators have a fresh summary
57
+ after any KB updates (architecture docs may have changed during the sprint):
58
+ ```
59
+ FORGE_ROOT=$(node -e "console.log(require('./.forge/config.json').paths.forgeRoot)")
60
+ ENGINEERING=$(node "$FORGE_ROOT/tools/manage-config.cjs" get paths.engineering 2>/dev/null || echo engineering)
61
+ node "$FORGE_ROOT/tools/build-context-pack.cjs" \
62
+ --arch-dir "$ENGINEERING/architecture" \
63
+ --out-md .forge/cache/context-pack.md \
64
+ --out-json .forge/cache/context-pack.json
65
+ ```
66
+ - On exit 1 (architecture directory absent), skip silently.
67
+
68
+ 4. Finalize:
69
+ - **Do NOT emit a phase event yourself.** The orchestrator (or kickoff handler) owns event emission — it composes the canonical event from runtime telemetry (model, provider, tokens, wall times) plus the SUMMARY you write in the next step. Subagents that call `store-cli emit` for phase events hallucinate runtime facts (see Plan 11 / Slice 2). Write the SUMMARY and return.
70
+ - Invoke Tomoshibi via Skill tool to refresh KB and workflow links in agent
71
+ instruction files:
72
+ ```
73
+ Use the Skill tool:
74
+ skill: "forge:refresh-kb-links"
75
+ ```
76
+ ```
77
+
78
+ ## Generation Instructions
79
+
80
+ - **Persona Self-Load:** The generated workflow MUST begin by reading `.forge/personas/collator.md` as its first step (before any other tool use). This replaces the former inline `## Persona` section. The persona identity line (emoji, name, tagline) should be printed to stdout after reading the file.
81
+ - **Workflow Structure:** The generated `collate.md` must follow the strict "Algorithm" block format.
82
+ - **Context Isolation:** Forbid inline execution of large-scale file generation; use the `Agent` tool for sub-tasks.
83
+ - **Token Reporting:** The generated workflow MUST mandate the following before returning:
84
+ 1. Probe session token usage: invoke `/cost` if the host runtime supports it
85
+ (Claude Code only); on any other runtime treat as unavailable and proceed.
86
+ Do NOT shell out to a `cost-cli.cjs` — there is no such tool.
87
+ 2. Parse: `inputTokens`, `outputTokens`, `cacheReadTokens`, `cacheWriteTokens`, `estimatedCostUSD`.
88
+ 3. Write the usage sidecar via `node "$FORGE_ROOT/tools/store-cli.cjs" emit {sprintId} '{sidecar-json}' --sidecar`.
89
+ - **Event Emission:** Ensure the "complete" event includes the `eventId` passed by the orchestrator.
@@ -0,0 +1,93 @@
1
+ ---
2
+ requirements:
3
+ reasoning: Low
4
+ context: Low
5
+ speed: High
6
+ audience: subagent
7
+ phase: commit
8
+ context:
9
+ architecture: false
10
+ prior_summaries: none
11
+ persona: summary
12
+ master_index: false
13
+ diff_mode: false
14
+ deps:
15
+ personas: [engineer]
16
+ skills: [engineer, generic]
17
+ templates: [PROGRESS_TEMPLATE]
18
+ sub_workflows: []
19
+ kb_docs: []
20
+ config_fields: [commands.test, paths.engineering]
21
+ ---
22
+
23
+ # 🌱 Meta-Workflow: Commit Task
24
+
25
+ ## Purpose
26
+
27
+ Seal a completed and approved task by committing its artifacts to the VCS and updating the store.
28
+
29
+ ## Iron Laws
30
+
31
+ - Commit only the artifacts produced for this task; do not sweep unrelated working-tree changes into the commit. The commit boundary mirrors the task boundary.
32
+ - Read `.forge/personas/engineer.md` first; print the persona identity line (emoji, name, tagline) to stdout before any other tool use.
33
+ - All store I/O via `forge_store` (or `node "$FORGE_ROOT/tools/store-cli.cjs"`). Never edit `.forge/store/*.json` directly.
34
+
35
+ ## Store-Write Verification
36
+
37
+ Every `forge_store` write MUST succeed before advancing. If `store-cli` exits
38
+ non-zero or the `PreToolUse` write-boundary hook blocks the call (exit 2):
39
+
40
+ 1. Parse the structured error (names the offending field + schema file).
41
+ 2. Correct the JSON to satisfy the schema.
42
+ 3. Retry. Repeat up to 3 times.
43
+ 4. After 3 failures, halt and escalate with original payload, corrected payload, and all error messages.
44
+
45
+ Never set `FORGE_SKIP_WRITE_VALIDATION=1` — operator-only emergency switch.
46
+
47
+ ## Algorithm
48
+
49
+ ```
50
+
51
+ 0. Pre-flight Gate Check:
52
+ - Resolve FORGE_ROOT (`node -e "console.log(require('./.forge/config.json').paths.forgeRoot)"`).
53
+ - **Entity-mode resolution:** read the kickoff arguments. `--task {id}` → `entity_kind = "task"`, `record_id = {id}`. `--bug {id}` → `entity_kind = "bug"`, `record_id = {id}`. All store-cli calls below substitute `{entity_kind}` and `{record_id}` for the literal "task"/{taskId} placeholders.
54
+ - Run: `node "$FORGE_ROOT/tools/preflight-gate.cjs" --phase commit --{entity_kind} {record_id}`
55
+ - Exit 1 (gate failed) → print stderr and HALT. Do not proceed; do not attempt to produce the artifact.
56
+ - Exit 2 (misconfiguration) → print stderr and HALT.
57
+ - Exit 0 → continue.
58
+
59
+ 1. Load Context:
60
+ - Read the record manifest (task or bug, per entity_kind).
61
+ - Read ARCHITECT_APPROVAL.md from the record's artifact directory:
62
+ - Task mode: `engineering/sprints/{sprint}/{task}/ARCHITECT_APPROVAL.md`
63
+ - Bug mode: `engineering/bugs/{bugDir}/ARCHITECT_APPROVAL.md`
64
+
65
+ 2. Staging:
66
+ - Stage all record-related artifacts and the code changes:
67
+ - Task mode: PLAN.md, PROGRESS.md, REVIEW files, ARCHITECT_APPROVAL.md, and the implementation diff under the task directory plus modified source files.
68
+ - Bug mode: BUG_FIX_PLAN.md (Path B only — absent on Path A), TRIAGE.md, PROGRESS.md, REVIEW files, ARCHITECT_APPROVAL.md, the regression test, and the implementation diff.
69
+ - Verify no unrelated files are staged.
70
+
71
+ 3. Commit:
72
+ - Create a commit with a message following project conventions.
73
+ - Include the record ID in the commit message: task ID for task mode, bug ID for bug mode.
74
+ - Append a `Co-authored-by:` trailer crediting the AI assistant that actually ran the session. Resolve the identity from the host runtime: on Claude Code use `Co-authored-by: Claude <noreply@anthropic.com>`; on pi / Ollama / any other runtime use `Co-authored-by: {modelId} <noreply@{provider}.ai>` derived from the session's `provider` and `modelId` (e.g. `Co-authored-by: glm-5.1:cloud <noreply@ollama.ai>`); if neither is resolvable, omit the trailer rather than guess. Do NOT hardcode `Claude Opus 4.6 <noreply@anthropic.com>` — that literal is rejected as a regression of forge#82 (commits authored under the wrong model).
75
+ - Let git's configured `user.name` / `user.email` own the commit author; never pass `--author` to override it.
76
+
77
+ 4. Store Finalization:
78
+ - Transitions:
79
+ - **Task mode** — `approved → committed` (terminal): `node "$FORGE_ROOT/tools/store-cli.cjs" update-status task {taskId} status committed`
80
+ - **Bug mode** — `in-progress → fixed` (terminal): `node "$FORGE_ROOT/tools/store-cli.cjs" update-status bug {bugId} status fixed`. This is the ONLY phase in the bug pipeline that writes `bug.status` post-triage (see `meta-fix-bug.md § Iron Laws #2`). Do NOT write `approved` or `verified` — those values are vestigial enum members slated for removal.
81
+
82
+ 5. Finalize:
83
+ - **Do NOT emit a phase event yourself.** The orchestrator owns event emission — it composes the canonical event from runtime telemetry (model, provider, tokens, wall times) plus the SUMMARY you write in the next step. Subagents that call `store-cli emit` for phase events hallucinate runtime facts (see Plan 11 / Slice 2). Write the SUMMARY and return.
84
+ ```
85
+
86
+ ## Generation Instructions
87
+
88
+ - **Workflow Structure:** The generated `commit_task.md` must follow the strict "Algorithm" block format.
89
+ - **Context Isolation:** Forbid inline execution of commit operations; use the `Agent` tool for sub-tasks.
90
+ - **Project Specifics:**
91
+ - Embed project's commit message conventions.
92
+ - **Token Reporting:** See `_fragments/finalize.md` — wire via `file_ref:`.
93
+ - **Event Emission:** Ensure the "complete" event includes the `eventId` passed by the orchestrator.
@@ -0,0 +1,286 @@
1
+ ---
2
+ requirements:
3
+ reasoning: High
4
+ context: High
5
+ speed: Low
6
+ audience: orchestrator-only
7
+ deps:
8
+ personas: [engineer]
9
+ skills: [engineer, generic]
10
+ templates: []
11
+ sub_workflows: []
12
+ kb_docs: []
13
+ config_fields: [paths.engineering, paths.forgeRoot]
14
+ ---
15
+
16
+ # Meta-Workflow: Enhancement Agent
17
+
18
+ ## Iron Laws
19
+
20
+ - Orchestrator-only: this workflow runs with full tool access in the orchestrator session. NEVER delegate it to a subagent.
21
+ - Read `.forge/personas/engineer.md` first; print the persona identity line to stdout before any other tool use.
22
+ - All store I/O via `forge_store` (or `node "$FORGE_ROOT/tools/store-cli.cjs"`). Never edit `.forge/store/*.json` directly.
23
+ - Phase 1 only touches `{{KEY}}` token text; never rewrite persona prose, algorithm steps, or role definitions.
24
+
25
+ ## Store-Write Verification
26
+
27
+ Every `forge_store` write MUST succeed before advancing. If `store-cli` exits
28
+ non-zero or the `PreToolUse` write-boundary hook blocks the call (exit 2):
29
+
30
+ 1. Parse the structured error.
31
+ 2. Correct the JSON to satisfy the schema.
32
+ 3. Retry. Repeat up to 3 times. After 3 failures, halt and escalate.
33
+
34
+ Never set `FORGE_SKIP_WRITE_VALIDATION=1` — operator-only emergency switch.
35
+
36
+ ## Purpose
37
+
38
+ Autonomously improve the installed `.forge/` structural elements by:
39
+ - **Phase 1** (auto-apply, post-init): Fill any `{{KEY}}` placeholders left unsubstituted during init.
40
+ - **Phase 2** (propose-diffs, post-sprint): Scan sprint artifacts and friction events; propose persona/skill enrichments for user review.
41
+ - **Phase 3** (drift detection, on-demand): Compare full codebase state against structural-element knowledge; propose targeted patches.
42
+
43
+ This workflow is `audience: orchestrator-only` — it reads store events and proposes writes to
44
+ `.forge/` structural elements. It must run with full tool access. It is never delegated to a
45
+ subagent.
46
+
47
+ ## Note on `.forge/enhancement-proposals/` directory
48
+
49
+ Phases 2 and 3 write proposal artifacts to `.forge/enhancement-proposals/`. This directory is
50
+ distinct from `.forge/enhancements/` (FR-007, S14 scope). This workflow uses `mkdir -p` before
51
+ writing the first proposal artifact to avoid assuming the directory exists. No conflict with S14.
52
+
53
+ ## Confidence gating (Phase 1)
54
+
55
+ A key substitution is **high-confidence** when there is exactly one unambiguous signal source
56
+ (e.g., `scripts.test` in `package.json` is the sole candidate for `{{TEST_COMMAND}}`). It is
57
+ **low-confidence** when multiple candidates exist or no signal is found. Only high-confidence
58
+ fills are applied automatically. Low-confidence keys are listed in the Phase 1 report and left
59
+ unsubstituted for the user to fill manually.
60
+
61
+ ## Phase routing
62
+
63
+ Receive the phase flag from the command invocation:
64
+
65
+ | Flag | Mode |
66
+ |------|------|
67
+ | `--phase 1` or `--auto` | Auto-apply: placeholder fills only |
68
+ | `--phase 2` | Propose-diffs: sprint artifact + friction scan |
69
+ | `--phase 3` | Drift detection: full codebase vs structural-element comparison |
70
+
71
+ Default to `--phase 3` if no phase flag is given.
72
+
73
+ ---
74
+
75
+ ## Step 0 — Resolve roots
76
+
77
+ ```
78
+ FORGE_ROOT: !`echo "${CLAUDE_PLUGIN_ROOT}"`
79
+ ```
80
+
81
+ Read `.forge/config.json`. Resolve:
82
+ - `PROJECT_ROOT` = current working directory (absolute).
83
+ - `ENGINEERING_PATH` = `paths.engineering` from config (default `engineering`).
84
+
85
+ ---
86
+
87
+ ## Phase 1 — Auto-apply placeholder fills
88
+
89
+ ### When to run
90
+
91
+ Invoked by T09 post-init hook (`--auto`) or manually via `/forge:enhance --phase 1`.
92
+
93
+ ### Algorithm
94
+
95
+ 1. **Scan structural elements** for `{{KEY}}` patterns:
96
+ ```sh
97
+ grep -r '{{' "$PROJECT_ROOT/.forge/personas/" "$PROJECT_ROOT/.forge/skills/" \
98
+ "$PROJECT_ROOT/.forge/workflows/" "$PROJECT_ROOT/.forge/templates/" \
99
+ --include="*.md" -l 2>/dev/null
100
+ ```
101
+ Collect each unique `{{KEY}}` token found.
102
+
103
+ 2. **Skip runtime passthrough keys** — keys used at runtime (e.g., `{{TASK_ID}}`, `{{SPRINT_ID}}`,
104
+ `{{ARGUMENTS}}`) are intentional and must not be substituted. Read
105
+ `$FORGE_ROOT/tools/substitute-placeholders.cjs` to identify the RUNTIME_PASSTHROUGH_KEYS list.
106
+ Exclude them from the fill candidates.
107
+
108
+ 3. **Derive values from codebase signals** — for each remaining `{{KEY}}`, attempt to derive a
109
+ value with high confidence:
110
+
111
+ | Key | Signal source |
112
+ |-----|--------------|
113
+ | `{{STACK_SUMMARY}}` | `package.json` dependencies field (list top-level frameworks); or dominant file extension survey |
114
+ | `{{BRANCHING_CONVENTION}}` | `git branch -a` output pattern or `.git/config` |
115
+ | `{{TEST_COMMAND}}` | `package.json` → `scripts.test` |
116
+ | `{{BUILD_COMMAND}}` | `package.json` → `scripts.build` |
117
+ | `{{ENTITY_MODEL}}` | Scan source for ORM model files or type definitions |
118
+ | `{{KEY_DIRECTORIES}}` | Top-level directory listing (exclude `.git`, `node_modules`, `.forge`) |
119
+ | `{{IMPACT_CATEGORIES}}` | Derive from project type (web app → UI/API/DB/Infra; library → API/Docs/Tests) |
120
+
121
+ Any key without a single unambiguous signal → mark as **low-confidence** (skip auto-fill).
122
+
123
+ 4. **Apply high-confidence fills** — for each high-confidence key, perform in-place substitution
124
+ in all structural element files that contain the key. Use `substitute-placeholders.cjs` if it
125
+ supports a targeted single-key mode; otherwise apply the substitution directly with a read/write
126
+ cycle per file.
127
+
128
+ **Minimal modification principle**: Phase 1 only touches `{{KEY}}` token text. It never rewrites
129
+ persona prose, algorithm steps, or role definitions.
130
+
131
+ 5. **Update `project-context.json`** — write the newly discovered values into
132
+ `$PROJECT_ROOT/.forge/project-context.json` so that future invocations of
133
+ `substitute-placeholders.cjs` use the derived values.
134
+
135
+ 6. **Snapshot gate** — if at least one fill was applied:
136
+ ```sh
137
+ node "$FORGE_ROOT/tools/manage-versions.cjs" add-snapshot \
138
+ --source post-init \
139
+ --enhanced-elements "<comma-separated list of relative .forge/ paths that were modified>"
140
+ ```
141
+ If no fills were applied, skip the snapshot call entirely.
142
+
143
+ 7. **Emit enhancement event** to the store:
144
+ ```sh
145
+ node "$FORGE_ROOT/tools/store-cli.cjs" emit enhancement '{
146
+ "eventId": "<ISO timestamp slug>_enhance_phase1",
147
+ "taskId": "enhancement",
148
+ "sprintId": "enhancement",
149
+ "role": "enhancement-agent",
150
+ "action": "enhancement-completed",
151
+ "phase": "post-init",
152
+ "iteration": 1,
153
+ "notes": "{\"phase\":1,\"fillCount\":<N>,\"snapshotCreated\":<true|false>}"
154
+ }'
155
+ ```
156
+
157
+ 8. **Report**:
158
+ ```
159
+ ## Phase 1 Enhancement Complete
160
+
161
+ Fills applied: N key(s) — {{KEY1}}, {{KEY2}}, ...
162
+ Uncertain keys (not filled): M — {{KEY3}}, ... (manual intervention needed)
163
+ Snapshot: [written as snap-{index}] | [skipped — no fills]
164
+ ```
165
+
166
+ ---
167
+
168
+ ## Phase 2 — Propose enrichment diffs (post-sprint)
169
+
170
+ ### When to run
171
+
172
+ Invoked by T09 post-sprint hook or manually via `/forge:enhance --phase 2`.
173
+
174
+ ### Algorithm
175
+
176
+ 1. **Collect friction events**:
177
+ ```sh
178
+ node -e "
179
+ const fs = require('fs'), path = require('path');
180
+ const eventsDir = '.forge/store/events';
181
+ const allFiles = fs.readdirSync(eventsDir, { withFileTypes: true })
182
+ .flatMap(d => d.isDirectory()
183
+ ? fs.readdirSync(path.join(eventsDir, d.name)).map(f => path.join(eventsDir, d.name, f))
184
+ : [path.join(eventsDir, d.name)]
185
+ )
186
+ .filter(f => f.endsWith('.json'));
187
+ const friction = allFiles
188
+ .map(f => { try { return JSON.parse(fs.readFileSync(f,'utf8')); } catch { return null; } })
189
+ .filter(e => e && e.type === 'friction');
190
+ console.log(JSON.stringify(friction));
191
+ "
192
+ ```
193
+
194
+ 2. **Deduplicate** friction events by composite key `workflow + persona + issue`. Keep the most
195
+ recent occurrence of each composite key.
196
+
197
+ 3. **Read most recent completed sprint** from `.forge/store/sprints/` (status `done` or
198
+ `retrospective-done`), sorted by completion date. Read its task records from
199
+ `.forge/store/tasks/` filtered by the sprint ID.
200
+
201
+ 4. **Synthesize enrichment proposals** — for each friction event:
202
+ - Identify which persona or skill file it references.
203
+ - Propose a targeted addition: e.g., "architect persona lacks routing pattern knowledge —
204
+ suggest adding `{{KB_PATH}}/routing.md` reference to deps.kb_docs."
205
+ - For large committed file sets (> 5 files in the sprint), also check whether
206
+ `engineer-skills.md` or `architect-skills.md` should reference new patterns.
207
+
208
+ 5. **Write proposal artifact**:
209
+ ```sh
210
+ mkdir -p "$PROJECT_ROOT/.forge/enhancement-proposals"
211
+ ```
212
+ Write to `$PROJECT_ROOT/.forge/enhancement-proposals/phase2-<timestamp>.md`. Format:
213
+ one section per proposed change, with a fenced diff block showing before/after text.
214
+
215
+ 6. **Present to user**:
216
+ ```
217
+ ## Phase 2 Enhancement Proposals
218
+
219
+ N change(s) proposed — review: .forge/enhancement-proposals/phase2-<timestamp>.md
220
+
221
+ [A] Apply all [r] Review individually [n] Skip
222
+ ```
223
+
224
+ 7. **On approval** — for each approved change:
225
+ - Apply the edit in-place.
226
+ - Call `manage-versions.cjs add-snapshot --source post-sprint:<SPRINT_ID> --enhanced-elements <list>`.
227
+
228
+ 8. **Emit enhancement event** (same schema as Phase 1, with `"phase": "post-sprint"`).
229
+
230
+ 9. **Report**: N changes applied, M skipped, snapshot written or skipped.
231
+
232
+ ---
233
+
234
+ ## Phase 3 — Drift detection (on-demand / delegated from calibrate)
235
+
236
+ ### When to run
237
+
238
+ Invoked by `/forge:enhance --phase 3` (default when no phase given), or delegated by
239
+ `/forge:calibrate` after its Step 4 drift categorization.
240
+
241
+ ### Algorithm
242
+
243
+ 1. **Read codebase state** from `$PROJECT_ROOT/.forge/project-context.json`:
244
+ key directories, entities, commands, stack summary, test command, build command.
245
+
246
+ 2. **Read all structural elements** from `.forge/personas/`, `.forge/skills/`,
247
+ `.forge/workflows/`, `.forge/templates/`.
248
+
249
+ 3. **Compare**: for each structural element, verify:
250
+ - It correctly references known entities and key directories.
251
+ - It uses valid `{{KB_PATH}}` references (paths that exist in `engineering/`).
252
+ - Its `deps.kb_docs` list includes docs referenced in its body.
253
+
254
+ 4. **Read friction events** (same collection as Phase 2 Step 1).
255
+
256
+ 5. **Read `calibrationBaseline`** from `$PROJECT_ROOT/.forge/config.json` to understand what
257
+ was last confirmed correct.
258
+
259
+ 6. **Write drift report**:
260
+ ```sh
261
+ mkdir -p "$PROJECT_ROOT/.forge/enhancement-proposals"
262
+ ```
263
+ Write to `$PROJECT_ROOT/.forge/enhancement-proposals/phase3-<timestamp>.md`.
264
+
265
+ 7. **Present to user**:
266
+ ```
267
+ ## Phase 3 Drift Report
268
+
269
+ N discrepancy(ies) found — review: .forge/enhancement-proposals/phase3-<timestamp>.md
270
+
271
+ [A] Apply all [r] Review individually [n] Skip
272
+ ```
273
+
274
+ 8. **On approval** — apply changes and call `manage-versions.cjs add-snapshot --source on-demand`.
275
+
276
+ 9. **Emit enhancement event** (`"phase": "on-demand"`).
277
+
278
+ 10. **Report**: N changes applied, snapshot written or skipped.
279
+
280
+ ---
281
+
282
+ ## On error
283
+
284
+ If any step fails unexpectedly, describe what went wrong and offer:
285
+
286
+ > "This looks like a Forge bug. Would you like to file a report? Run `/forge:report-bug`."