wtf-p 0.3.0 → 0.5.0

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 (183) hide show
  1. package/README.md +146 -208
  2. package/bin/commands/doctor.js +88 -2
  3. package/bin/commands/install-logic.js +127 -36
  4. package/bin/commands/status.js +22 -4
  5. package/bin/commands/update.js +5 -4
  6. package/bin/install.js +66 -26
  7. package/bin/lib/analyze-impact.js +105 -0
  8. package/bin/lib/bib-format.js +161 -0
  9. package/bin/lib/bib-index.js +104 -0
  10. package/bin/lib/checkpoint.js +183 -0
  11. package/bin/lib/citation-fetcher.js +299 -0
  12. package/bin/lib/citation-ranker.js +133 -0
  13. package/bin/lib/context-primer.js +214 -0
  14. package/bin/lib/manifest.js +80 -2
  15. package/bin/lib/scholar-lookup.js +188 -0
  16. package/bin/lib/semantic-scholar.js +184 -0
  17. package/bin/lib/utils.js +22 -1
  18. package/bin/uninstall.js +270 -111
  19. package/core/write-the-f-paper/references/agent-model-matrix.md +62 -0
  20. package/core/write-the-f-paper/references/checkpoints.md +160 -9
  21. package/core/write-the-f-paper/references/context-fidelity.md +153 -0
  22. package/core/write-the-f-paper/references/deviation-rules.md +150 -0
  23. package/core/write-the-f-paper/references/git-integration.md +80 -0
  24. package/core/write-the-f-paper/references/orchestrator-pattern.md +167 -0
  25. package/core/write-the-f-paper/references/planning-config.md +135 -0
  26. package/core/write-the-f-paper/references/ui-brand.md +186 -0
  27. package/core/write-the-f-paper/templates/UAT.md +80 -0
  28. package/core/write-the-f-paper/templates/base-prefs.yaml +42 -0
  29. package/core/write-the-f-paper/templates/config.json +31 -5
  30. package/core/write-the-f-paper/workflows/create-outline.wcn.md +1 -1
  31. package/core/write-the-f-paper/workflows/execute-outline.md +163 -0
  32. package/core/write-the-f-paper/workflows/execute-outline.wcn.md +73 -0
  33. package/core/write-the-f-paper/workflows/execute-section.wcn.md +141 -169
  34. package/core/write-the-f-paper/workflows/plan-section.wcn.md +96 -103
  35. package/core/write-the-f-paper/workflows/research-gap.md +27 -3
  36. package/core/write-the-f-paper/workflows/research-gap.wcn.md +18 -1
  37. package/core/write-the-f-paper/workflows/verify-work.md +251 -0
  38. package/core/write-the-f-paper/workflows/verify-work.wcn.md +74 -0
  39. package/package.json +19 -7
  40. package/vendors/claude/.claude-plugin/plugin.json +2 -2
  41. package/vendors/claude/agents/wtfp/argument-verifier.md +189 -0
  42. package/vendors/claude/agents/wtfp/citation-expert.md +45 -0
  43. package/vendors/claude/agents/wtfp/citation-formatter.md +42 -0
  44. package/vendors/claude/agents/wtfp/coherence-checker.md +167 -0
  45. package/vendors/claude/agents/wtfp/outliner.md +259 -0
  46. package/vendors/claude/agents/wtfp/plan-checker.md +249 -0
  47. package/vendors/claude/agents/wtfp/prose-polisher.md +166 -0
  48. package/vendors/claude/agents/wtfp/research-synthesizer.md +215 -0
  49. package/vendors/claude/agents/wtfp/section-planner.md +364 -0
  50. package/vendors/claude/agents/wtfp/section-reviewer.md +182 -0
  51. package/vendors/claude/agents/wtfp/section-writer.md +312 -0
  52. package/vendors/claude/commands/wtfp/add-todo.md +108 -0
  53. package/vendors/claude/commands/wtfp/analyze-bib.md +60 -249
  54. package/vendors/claude/commands/wtfp/audit-milestone.md +286 -0
  55. package/vendors/claude/commands/wtfp/check-refs.md +60 -131
  56. package/vendors/claude/commands/wtfp/check-todos.md +152 -0
  57. package/vendors/claude/commands/wtfp/checkpoint.md +105 -0
  58. package/vendors/claude/commands/wtfp/contribute.md +1 -1
  59. package/vendors/claude/commands/wtfp/create-outline.md +109 -195
  60. package/vendors/claude/commands/wtfp/create-poster.md +1 -1
  61. package/vendors/claude/commands/wtfp/create-slides.md +1 -1
  62. package/vendors/claude/commands/wtfp/discuss-section.md +1 -1
  63. package/vendors/claude/commands/wtfp/execute-outline.md +257 -0
  64. package/vendors/claude/commands/wtfp/export-latex.md +1 -1
  65. package/vendors/claude/commands/wtfp/help.md +174 -280
  66. package/vendors/claude/commands/wtfp/insert-section.md +1 -1
  67. package/vendors/claude/commands/wtfp/list-assumptions.md +1 -1
  68. package/vendors/claude/commands/wtfp/map-project.md +35 -124
  69. package/vendors/claude/commands/wtfp/new-paper.md +88 -362
  70. package/vendors/claude/commands/wtfp/pause-writing.md +1 -1
  71. package/vendors/claude/commands/wtfp/plan-milestone-gaps.md +255 -0
  72. package/vendors/claude/commands/wtfp/plan-revision.md +1 -1
  73. package/vendors/claude/commands/wtfp/plan-section.md +165 -190
  74. package/vendors/claude/commands/wtfp/polish-prose.md +66 -118
  75. package/vendors/claude/commands/wtfp/progress.md +82 -254
  76. package/vendors/claude/commands/wtfp/quick.md +107 -0
  77. package/vendors/claude/commands/wtfp/remove-section.md +1 -1
  78. package/vendors/claude/commands/wtfp/report-bug.md +1 -1
  79. package/vendors/claude/commands/wtfp/request-feature.md +1 -1
  80. package/vendors/claude/commands/wtfp/research-gap.md +138 -151
  81. package/vendors/claude/commands/wtfp/resume-writing.md +1 -1
  82. package/vendors/claude/commands/wtfp/review-section.md +55 -333
  83. package/vendors/claude/commands/wtfp/settings.md +197 -0
  84. package/vendors/claude/commands/wtfp/submit-milestone.md +248 -99
  85. package/vendors/claude/commands/wtfp/update.md +112 -0
  86. package/vendors/claude/commands/wtfp/verify-work.md +254 -0
  87. package/vendors/claude/commands/wtfp/write-section.md +144 -180
  88. package/vendors/claude/mcp/research-server/package.json +13 -0
  89. package/vendors/claude/mcp/research-server/src/index.js +133 -0
  90. package/vendors/gemini/agents/wtfp/argument-verifier.md +184 -0
  91. package/vendors/gemini/agents/wtfp/citation-expert.md +41 -0
  92. package/vendors/gemini/agents/wtfp/citation-formatter.md +38 -0
  93. package/vendors/gemini/agents/wtfp/coherence-checker.md +162 -0
  94. package/vendors/gemini/agents/wtfp/outliner.md +252 -0
  95. package/vendors/gemini/agents/wtfp/plan-checker.md +244 -0
  96. package/vendors/gemini/agents/wtfp/prose-polisher.md +158 -0
  97. package/vendors/gemini/agents/wtfp/research-synthesizer.md +205 -0
  98. package/vendors/gemini/agents/wtfp/section-planner.md +355 -0
  99. package/vendors/gemini/agents/wtfp/section-reviewer.md +175 -0
  100. package/vendors/gemini/agents/wtfp/section-writer.md +304 -0
  101. package/vendors/gemini/commands/wtfp/add-todo.toml +102 -0
  102. package/vendors/gemini/commands/wtfp/analyze-bib.toml +126 -0
  103. package/vendors/gemini/commands/wtfp/audit-milestone.toml +278 -0
  104. package/vendors/gemini/commands/wtfp/check-refs.toml +123 -0
  105. package/vendors/gemini/commands/wtfp/check-todos.toml +145 -0
  106. package/vendors/gemini/commands/wtfp/checkpoint.toml +96 -0
  107. package/vendors/gemini/commands/wtfp/contribute.toml +269 -0
  108. package/vendors/gemini/commands/wtfp/create-outline.toml +180 -0
  109. package/vendors/gemini/commands/wtfp/create-poster.toml +36 -0
  110. package/vendors/gemini/commands/wtfp/create-slides.toml +35 -0
  111. package/vendors/gemini/commands/wtfp/discuss-section.toml +62 -0
  112. package/vendors/gemini/commands/wtfp/execute-outline.toml +247 -0
  113. package/vendors/gemini/commands/wtfp/export-latex.toml +209 -0
  114. package/vendors/gemini/commands/wtfp/help.toml +184 -0
  115. package/vendors/gemini/commands/wtfp/insert-section.toml +123 -0
  116. package/vendors/gemini/commands/wtfp/list-assumptions.toml +104 -0
  117. package/vendors/gemini/commands/wtfp/map-project.toml +99 -0
  118. package/vendors/gemini/commands/wtfp/new-paper.toml +160 -0
  119. package/vendors/gemini/commands/wtfp/pause-writing.toml +140 -0
  120. package/vendors/gemini/commands/wtfp/plan-milestone-gaps.toml +249 -0
  121. package/vendors/gemini/commands/wtfp/plan-revision.toml +171 -0
  122. package/vendors/gemini/commands/wtfp/plan-section.toml +212 -0
  123. package/vendors/gemini/commands/wtfp/polish-prose.toml +114 -0
  124. package/vendors/gemini/commands/wtfp/progress.toml +145 -0
  125. package/vendors/gemini/commands/wtfp/quick.toml +96 -0
  126. package/vendors/gemini/commands/wtfp/remove-section.toml +140 -0
  127. package/vendors/gemini/commands/wtfp/report-bug.toml +126 -0
  128. package/vendors/gemini/commands/wtfp/request-feature.toml +155 -0
  129. package/vendors/gemini/commands/wtfp/research-gap.toml +214 -0
  130. package/vendors/gemini/commands/wtfp/resume-writing.toml +136 -0
  131. package/vendors/gemini/commands/wtfp/review-section.toml +121 -0
  132. package/vendors/gemini/commands/wtfp/settings.toml +191 -0
  133. package/vendors/gemini/commands/wtfp/submit-milestone.toml +351 -0
  134. package/vendors/gemini/commands/wtfp/update.toml +107 -0
  135. package/vendors/gemini/commands/wtfp/verify-work.toml +245 -0
  136. package/vendors/gemini/commands/wtfp/write-section.toml +228 -0
  137. package/vendors/opencode/agents/wtfp/argument-verifier.md +184 -0
  138. package/vendors/opencode/agents/wtfp/citation-expert.md +41 -0
  139. package/vendors/opencode/agents/wtfp/citation-formatter.md +38 -0
  140. package/vendors/opencode/agents/wtfp/coherence-checker.md +162 -0
  141. package/vendors/opencode/agents/wtfp/outliner.md +252 -0
  142. package/vendors/opencode/agents/wtfp/plan-checker.md +244 -0
  143. package/vendors/opencode/agents/wtfp/prose-polisher.md +158 -0
  144. package/vendors/opencode/agents/wtfp/research-synthesizer.md +205 -0
  145. package/vendors/opencode/agents/wtfp/section-planner.md +355 -0
  146. package/vendors/opencode/agents/wtfp/section-reviewer.md +175 -0
  147. package/vendors/opencode/agents/wtfp/section-writer.md +304 -0
  148. package/vendors/opencode/commands/wtfp/add-todo.md +103 -0
  149. package/vendors/opencode/commands/wtfp/analyze-bib.md +127 -0
  150. package/vendors/opencode/commands/wtfp/audit-milestone.md +279 -0
  151. package/vendors/opencode/commands/wtfp/check-refs.md +124 -0
  152. package/vendors/opencode/commands/wtfp/check-todos.md +146 -0
  153. package/vendors/opencode/commands/wtfp/checkpoint.md +97 -0
  154. package/vendors/opencode/commands/wtfp/contribute.md +266 -0
  155. package/vendors/opencode/commands/wtfp/create-outline.md +181 -0
  156. package/vendors/opencode/commands/wtfp/create-poster.md +37 -0
  157. package/vendors/opencode/commands/wtfp/create-slides.md +36 -0
  158. package/vendors/opencode/commands/wtfp/discuss-section.md +63 -0
  159. package/vendors/opencode/commands/wtfp/execute-outline.md +248 -0
  160. package/vendors/opencode/commands/wtfp/export-latex.md +210 -0
  161. package/vendors/opencode/commands/wtfp/help.md +185 -0
  162. package/vendors/opencode/commands/wtfp/insert-section.md +124 -0
  163. package/vendors/opencode/commands/wtfp/list-assumptions.md +105 -0
  164. package/vendors/opencode/commands/wtfp/map-project.md +100 -0
  165. package/vendors/opencode/commands/wtfp/new-paper.md +161 -0
  166. package/vendors/opencode/commands/wtfp/pause-writing.md +141 -0
  167. package/vendors/opencode/commands/wtfp/plan-milestone-gaps.md +250 -0
  168. package/vendors/opencode/commands/wtfp/plan-revision.md +174 -0
  169. package/vendors/opencode/commands/wtfp/plan-section.md +214 -0
  170. package/vendors/opencode/commands/wtfp/polish-prose.md +115 -0
  171. package/vendors/opencode/commands/wtfp/progress.md +146 -0
  172. package/vendors/opencode/commands/wtfp/quick.md +97 -0
  173. package/vendors/opencode/commands/wtfp/remove-section.md +141 -0
  174. package/vendors/opencode/commands/wtfp/report-bug.md +127 -0
  175. package/vendors/opencode/commands/wtfp/request-feature.md +156 -0
  176. package/vendors/opencode/commands/wtfp/research-gap.md +215 -0
  177. package/vendors/opencode/commands/wtfp/resume-writing.md +137 -0
  178. package/vendors/opencode/commands/wtfp/review-section.md +123 -0
  179. package/vendors/opencode/commands/wtfp/settings.md +192 -0
  180. package/vendors/opencode/commands/wtfp/submit-milestone.md +352 -0
  181. package/vendors/opencode/commands/wtfp/update.md +108 -0
  182. package/vendors/opencode/commands/wtfp/verify-work.md +246 -0
  183. package/vendors/opencode/commands/wtfp/write-section.md +228 -0
@@ -0,0 +1,163 @@
1
+ <purpose>
2
+ Execute all document sections via wave-based parallel execution. Sections are grouped
3
+ by wave number (from PLAN.md frontmatter). Each wave runs in parallel; waves execute
4
+ sequentially. After the final wave, spawn coherence-checker for cross-section verification.
5
+ </purpose>
6
+
7
+ <process>
8
+
9
+ <step name="load_state" priority="first">
10
+ Before any operation, read project state:
11
+
12
+ ```bash
13
+ cat .planning/STATE.md 2>/dev/null
14
+ cat .planning/config.json 2>/dev/null
15
+ ```
16
+
17
+ Parse current position, accumulated decisions. Load planning config.
18
+
19
+ ```bash
20
+ MODEL_PROFILE=$(cat .planning/config.json 2>/dev/null | grep -o '"model_profile"[[:space:]]*:[[:space:]]*"[^"]*"' | grep -o '"[^"]*"$' | tr -d '"' || echo "balanced")
21
+ ```
22
+ </step>
23
+
24
+ <step name="validate_environment">
25
+ Verify outline exists and plans are ready:
26
+
27
+ ```bash
28
+ [ ! -f .planning/ROADMAP.md ] && echo "ERROR: No outline. Run /wtfp:create-outline" && exit 1
29
+ ```
30
+
31
+ Check that PLAN.md files exist for sections:
32
+ ```bash
33
+ PLAN_COUNT=$(ls .planning/sections/*/*-PLAN.md 2>/dev/null | wc -l)
34
+ [ "$PLAN_COUNT" -eq 0 ] && echo "ERROR: No plans found. Run /wtfp:plan-section for each section" && exit 1
35
+ ```
36
+
37
+ Check for already-completed sections (SUMMARY.md exists):
38
+ ```bash
39
+ SUMMARY_COUNT=$(ls .planning/sections/*/*-SUMMARY.md 2>/dev/null | wc -l)
40
+ ```
41
+
42
+ If all sections already have SUMMARYs, warn: "All sections already written. Re-execute?"
43
+ </step>
44
+
45
+ <step name="build_wave_plan">
46
+ Parse ROADMAP.md and all PLAN.md files to group by wave:
47
+
48
+ ```bash
49
+ for plan in .planning/sections/*/*-PLAN.md; do
50
+ section_dir=$(dirname "$plan")
51
+ section_name=$(basename "$section_dir")
52
+ wave=$(grep -m1 'wave:' "$plan" | grep -o '[0-9]*')
53
+ echo "wave=$wave section=$section_name plan=$plan"
54
+ done | sort -t= -k2 -n
55
+ ```
56
+
57
+ Build execution plan:
58
+ - Group sections by wave number
59
+ - Within each wave: list all plans per section
60
+ - Identify max_wave for termination
61
+
62
+ Present plan before execution.
63
+ </step>
64
+
65
+ <step name="resolve_models">
66
+ Resolve models from profile for writer and coherence-checker:
67
+
68
+ | Agent | quality | balanced | budget |
69
+ |-------|---------|----------|--------|
70
+ | section-writer | opus | sonnet | sonnet |
71
+ | coherence-checker | sonnet | sonnet | haiku |
72
+
73
+ Store writer_model and checker_model for spawn calls.
74
+ </step>
75
+
76
+ <step name="execute_waves">
77
+ For wave = 1 to max_wave:
78
+
79
+ **1. Display wave banner** with section list.
80
+
81
+ **2. For each section in wave:**
82
+ - Find all PLAN.md files for the section
83
+ - Load section-specific context (CONTEXT.md, RESEARCH.md, prior SUMMARYs)
84
+ - Spawn Task() for each plan with section-writer agent
85
+
86
+ ```
87
+ Task(
88
+ prompt="First, read ~/.claude/agents/wtfp/section-writer.md...\n\n" + context,
89
+ subagent_type="general-purpose",
90
+ model="{writer_model}",
91
+ description="Write {section-name}"
92
+ )
93
+ ```
94
+
95
+ Sections within the same wave spawn in parallel.
96
+
97
+ **3. Collect returns** from all writers in this wave.
98
+
99
+ **4. Handle results:**
100
+ - WRITING COMPLETE: Update STATE.md, mark section in ROADMAP.md
101
+ - CHECKPOINT REACHED: Present to user, get response
102
+ - WRITING BLOCKED: Present to user with options (retry, skip, abort)
103
+
104
+ **5. Verify all wave sections resolved** before proceeding to next wave.
105
+
106
+ **6. Update progress** in STATE.md and ROADMAP.md.
107
+ </step>
108
+
109
+ <step name="spawn_coherence_checker">
110
+ After the final wave completes:
111
+
112
+ Read all written content inline:
113
+ ```bash
114
+ ALL_PAPER_CONTENT=$(cat paper/*.md 2>/dev/null)
115
+ ARGMAP=$(cat .planning/structure/argument-map.md 2>/dev/null)
116
+ NARRATIVE=$(cat .planning/structure/narrative-arc.md 2>/dev/null)
117
+ OUTLINE=$(cat .planning/structure/outline.md 2>/dev/null)
118
+ ```
119
+
120
+ Spawn coherence-checker with explicit inline context (not file references):
121
+
122
+ ```
123
+ Task(
124
+ prompt="First, read ~/.claude/agents/wtfp/coherence-checker.md...\n\n" +
125
+ "<paper_content>" + ALL_PAPER_CONTENT + "</paper_content>" +
126
+ "<argument_map>" + ARGMAP + "</argument_map>" +
127
+ "<narrative_arc>" + NARRATIVE + "</narrative_arc>" +
128
+ "<outline>" + OUTLINE + "</outline>",
129
+ subagent_type="general-purpose",
130
+ model="{checker_model}",
131
+ description="Verify Cross-Section Coherence"
132
+ )
133
+ ```
134
+
135
+ **Why inline:** Coherence-checker is read-only and needs all content in context. File references would require the agent to re-read everything, wasting context budget.
136
+ </step>
137
+
138
+ <step name="handle_coherence_result">
139
+ Route based on coherence-checker return:
140
+
141
+ **COHERENT:** All sections pass cross-verification.
142
+ - Update STATE.md with coherence status
143
+ - Proceed to completion
144
+
145
+ **GAPS FOUND:** Issues detected across sections.
146
+ - Present gap list to user
147
+ - Options:
148
+ - Fix now: Re-spawn writers for affected sections
149
+ - Accept: Proceed with known gaps
150
+ - Plan revision: Create revision plans for affected sections
151
+ </step>
152
+
153
+ </process>
154
+
155
+ <success_criteria>
156
+ - [ ] Wave execution plan built from ROADMAP.md and PLAN.md frontmatter
157
+ - [ ] All waves executed in dependency order
158
+ - [ ] Parallel Task() spawns within each wave
159
+ - [ ] Checkpoints handled between waves
160
+ - [ ] Coherence-checker spawned after final wave with inline paper content
161
+ - [ ] Coherence result routed (COHERENT or GAPS FOUND)
162
+ - [ ] STATE.md and ROADMAP.md updated throughout
163
+ </success_criteria>
@@ -0,0 +1,73 @@
1
+ <purpose>
2
+ Execute all sections via wave-based parallel execution. Sections grouped by wave number.
3
+ Each wave runs parallel; waves run sequentially. After final wave, spawn coherence-checker.
4
+ </purpose>
5
+
6
+ <process>
7
+
8
+ [step:load_state p=1]
9
+ RUN: cat .planning/STATE.md 2>/dev/null
10
+ RUN: cat .planning/config.json 2>/dev/null
11
+ RESOLVE: MODEL_PROFILE from config (default: balanced)
12
+ [/step]
13
+
14
+ [step:validate_environment]
15
+ REQUIRE: .planning/ROADMAP.md (else: /wtfp:create-outline)
16
+ REQUIRE: .planning/sections/*/*-PLAN.md (else: /wtfp:plan-section)
17
+ CHECK: existing SUMMARY.md count (warn if all complete)
18
+ [/step]
19
+
20
+ [step:build_wave_plan]
21
+ PARSE: all PLAN.md frontmatter for wave numbers
22
+ GROUP: sections by wave (wave 1 = independent, wave N = depends on N-1)
23
+ PRESENT: execution plan (waves, sections per wave, total words)
24
+ [/step]
25
+
26
+ [step:resolve_models]
27
+ MODEL_TABLE{agent,quality,balanced,budget}:
28
+ section-writer | opus | sonnet | sonnet
29
+ coherence-checker | sonnet | sonnet | haiku
30
+ STORE: writer_model, checker_model
31
+ [/step]
32
+
33
+ [step:execute_waves]
34
+ FOR wave = 1 to max_wave:
35
+ 1. EMIT: wave banner with section list
36
+ 2. FOR each section in wave:
37
+ - LOAD: CONTEXT.md, RESEARCH.md, prior SUMMARYs
38
+ - SPAWN: Task(section-writer, model=writer_model) per PLAN.md
39
+ - Parallel within wave
40
+ 3. COLLECT: all returns
41
+ 4. ROUTE:
42
+ - WRITING COMPLETE → update STATE.md, ROADMAP.md
43
+ - CHECKPOINT REACHED → present to user, get response
44
+ - WRITING BLOCKED → present options: retry | skip | abort
45
+ 5. VERIFY: all wave sections resolved before next wave
46
+ 6. UPDATE: progress in STATE.md
47
+ [/step]
48
+
49
+ [step:spawn_coherence_checker]
50
+ AFTER final wave:
51
+ READ_INLINE: paper/*.md, argument-map.md, narrative-arc.md, outline.md
52
+ SPAWN: Task(coherence-checker, model=checker_model)
53
+ CONTEXT: <paper_content>, <argument_map>, <narrative_arc>, <outline> (all inline)
54
+ NOTE: inline context avoids redundant file reads in checker agent
55
+ [/step]
56
+
57
+ [step:handle_coherence_result]
58
+ ROUTE:
59
+ COHERENT → update STATE.md, proceed to completion
60
+ GAPS FOUND → present gaps, OPTIONS: fix now | accept | plan revision
61
+ [/step]
62
+
63
+ </process>
64
+
65
+ <success_criteria>
66
+ - [ ] Wave execution plan built from ROADMAP.md and PLAN.md frontmatter
67
+ - [ ] All waves executed in dependency order
68
+ - [ ] Parallel Task() spawns within each wave
69
+ - [ ] Checkpoints handled between waves
70
+ - [ ] Coherence-checker spawned after final wave with inline paper content
71
+ - [ ] Coherence result routed (COHERENT or GAPS FOUND)
72
+ - [ ] STATE.md and ROADMAP.md updated throughout
73
+ </success_criteria>
@@ -1,219 +1,191 @@
1
1
  <purpose>
2
- Execute a section prompt (PLAN.md) and create the outcome summary (SUMMARY.md).
2
+ Execute a section prompt (PLAN.md) via thin orchestrator pattern. Orchestrator validates, loads context, resolves model profile, spawns section-writer agent, then runs argument-verifier for goal-backward verification. Creates SUMMARY.md.
3
3
  </purpose>
4
4
 
5
+ <architecture>
6
+ ORCHESTRATOR: /wtfp:write-section (this command)
7
+ AGENTS: section-writer (executes PLAN.md, writes prose), argument-verifier (goal-backward check)
8
+ PATTERN: Orchestrator loads context → spawns writer → spawns verifier → handle gaps
9
+ WHY_SUBAGENTS: Writer gets fresh context window with full PLAN.md + project context. Verifier checks independently whether section achieves its purpose, not just that tasks completed.
10
+ </architecture>
11
+
5
12
  <required_reading>
13
+ READ: ~/.claude/write-the-f-paper/references/orchestrator-pattern.md
14
+ READ: ~/.claude/write-the-f-paper/references/context-fidelity.md
15
+ READ: ~/.claude/write-the-f-paper/references/agent-model-matrix.md
16
+ READ: ~/.claude/write-the-f-paper/references/git-integration.md
6
17
  Read STATE.md before any operation to load project context.
7
18
  </required_reading>
8
19
 
9
20
  <process>
10
21
 
11
- [step:load_project_state p=1]
22
+ [step:validate_and_resolve_model p=1]
23
+ RUN: ls .planning/ 2>/dev/null
24
+ RUN: MODEL_PROFILE=$(cat .planning/config.json 2>/dev/null | grep -o '"model_profile"[[:space:]]*:[[:space:]]*"[^"]*"' | grep -o '"[^"]*"$' | tr -d '"' || echo "balanced")
25
+
26
+ MODEL_LOOKUP{agent,quality,balanced,budget}:
27
+ section-writer | opus | sonnet | sonnet
28
+ argument-verifier | sonnet | sonnet | haiku
29
+
30
+ RESOLVE: writer_model, verifier_model from MODEL_PROFILE
31
+ [/step]
32
+
33
+ [step:load_project_state]
12
34
  RUN: cat .planning/STATE.md 2>/dev/null
13
35
  PARSE: current, word, argument, open
14
36
  IF file_exists → parse_fields
15
- IF file_missing_but_.planning/_exists → ```
16
- IF .planning/_doesnt_exist → ERROR ""
37
+ IF file_missing_but_.planning/_exists → OFFER reconstruct|continue
38
+ IF .planning/_doesnt_exist → ERROR "project not initialized"
17
39
  [/step]
18
40
 
19
41
  [step:identify_plan]
20
42
  RUN: cat .planning/ROADMAP.md
21
43
  RUN: cat .planning/config.json 2>/dev/null
44
+ FIND: first PLAN without matching SUMMARY in section dir
45
+ IF ambiguous → ASK user which plan
22
46
  [/step]
23
47
 
24
- [step:record_start_time]
25
- RUN: PLAN_START_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
26
- [/step]
48
+ [step:load_context_md]
49
+ CRITICAL: Load CONTEXT.md early, pass to writer agent.
27
50
 
28
- [step:load_prompt]
29
- RUN: cat .planning/sections/XX-name/{section}-{plan}-PLAN.md
30
- IF plan_references_CONTEXT.md → The CONTEXT.md file provides the user's vision ...
31
- [/step]
51
+ RUN: SECTION_DIR=$(ls -d .planning/sections/${SECTION}-* 2>/dev/null | head -1)
52
+ RUN: CONTEXT_CONTENT=$(cat "${SECTION_DIR}"/*-CONTEXT.md 2>/dev/null)
53
+ RUN: PLAN_CONTENT=$(cat "${SECTION_DIR}"/${SECTION}-${PLAN}-PLAN.md)
32
54
 
33
- [step:previous_section_check]
55
+ CONTEXT.md rules:
56
+ Locked decisions → writer MUST implement exactly
57
+ Deferred ideas → writer MUST NOT include
58
+ Discretion areas → writer uses judgment
34
59
  [/step]
35
60
 
36
- [step:execute]
37
- IF `type=auto` → - Determine writing mode from task (co-author, ...
38
- IF mode=co-author → Write the prose directly
39
- IF mode=scaffold → Create detailed outline for user to fill
40
- IF mode=reviewer → Analyze existing text, provide feedback
61
+ [step:record_start_time]
62
+ RUN: PLAN_START_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
41
63
  [/step]
42
64
 
43
- <writing_modes>
44
- ## Writing Mode Execution
45
-
46
- **Co-Author Mode (Claude drafts):**
47
- - Write complete prose following outline/structure
48
- - Match user's voice from prior sections
49
- - Flag claims needing citations with [CITE: topic]
50
- - Flag uncertain statements with [VERIFY: claim]
51
- - Aim for word target specified in task
52
-
53
- **Scaffold Mode (Claude outlines):**
54
- - Create detailed paragraph-level outline
55
- - Specify what each paragraph should accomplish
56
- - Identify where citations should go
57
- - Note transition needs between paragraphs
58
- - Leave actual prose writing to user
59
-
60
- **Reviewer Mode (Claude critiques):**
61
- - Read existing text carefully
62
- - Identify strengths first
63
- - Note logical gaps or weak arguments
64
- - Suggest specific improvements
65
- - Ask clarifying questions before major changes
66
- </writing_modes>
67
-
68
- <deviation_rules>
69
-
70
- ## Automatic Adjustment Handling
71
-
72
- **While writing, you WILL discover issues.** This is normal.
73
-
74
- Apply these rules automatically. Track all adjustments for Summary documentation.
75
-
76
- ---
77
-
78
- [rule:autofix_factual_errors]
79
- TRIGGER: incorrect_fact | wrong_citation | logical_contradiction
80
- ACTION: fix immediately + track for summary
81
- PERMISSION: none_required
82
- [/rule]---
83
-
84
- [rule:autoadd_missing_critical_elements]
85
- TRIGGER: required_element_missing_for_section_completeness
86
- ACTION: add immediately + track for summary
87
- [/rule]---
88
-
89
- [rule:autofix_blocking_issues]
90
- TRIGGER: something_prevents_completing_the_writing_task
91
- ACTION: fix immediately to unblock + track for summary
92
- [/rule]---
93
-
94
- [rule:ask_about_structural_changes]
95
- TRIGGER: writing_requires_significant_restructuring
96
- ACTION: stop + present to user + wait for decision
97
- [/rule]---
98
-
99
- [rule:log_enhancement_ideas]
100
- TRIGGER: improvement_that_would_enhance_writing_but_isn't_essential_now
101
- ACTION: add to notes automatically + continue writing
102
- [/rule]---
103
-
104
- **RULE PRIORITY (when multiple could apply):**
105
-
106
- 1. **If Rule 4 applies** → STOP and ask (structural decision)
107
- 2. **If Rules 1-3 apply** → Fix automatically, track for Summary
108
- 3. **If Rule 5 applies** → Log for later, continue
109
-
110
- </deviation_rules>
111
-
112
- <three_layer_verification>
113
- ## Verification During Execution
114
-
115
- After each task, run verification checks:
116
-
117
- **1. Citation Check (Mechanical)**
118
- - All claims have citations or are clearly original claims
119
- - Citations formatted correctly
120
- - No [CITE: ] placeholders remaining
121
- - Page numbers where style requires
122
-
123
- **2. Argument Coherence (Logical)**
124
- - Claims follow from evidence
125
- - No logical contradictions with prior sections
126
- - Thesis supported by content
127
- - Flow between paragraphs makes sense
128
-
129
- **3. Rubric Check (Requirements)**
130
- - Word count within target range
131
- - Required elements present
132
- - Formatting requirements met
133
- - Section accomplishes its goal
134
- </three_layer_verification>
135
-
136
- <task_commit>
137
- ## Task Commit Protocol
138
-
139
- After each task completes (verification passed, done criteria met), commit immediately:
140
-
141
- **1. Identify modified files:**
142
-
143
- Track files changed during this specific task:
144
-
145
- ```bash
146
- git status --short
147
- ```
148
-
149
- **2. Stage only task-related files:**
150
-
151
- ```bash
152
- # Example - adjust to actual files modified
153
- git add paper/sections/introduction.md
154
- git add paper/references.bib
155
- ```
156
-
157
- **3. Determine commit type:**
158
-
159
- | Type | When to Use | Example |
160
- |------|-------------|---------|
161
- | `content` | New prose, new paragraphs | content(02-01): draft introduction hook |
162
- | `cite` | Adding/fixing citations | cite(02-01): add Smith2023 to literature review |
163
- | `revise` | Revising existing text | revise(02-01): strengthen thesis statement |
164
- | `fix` | Fixing errors | fix(02-01): correct misattributed quote |
165
- | `structure` | Reorganizing | structure(02-01): reorder methods subsections |
166
-
167
- **4. Craft commit message:**
168
-
169
- ```bash
170
- git commit -m "{type}({section}-{plan}): {task description}
171
-
172
- - {key change 1}
173
- - {key change 2}
174
- "
175
- ```
176
-
177
- **5. Record commit hash for SUMMARY.md**
178
- </task_commit>
179
-
180
- [step:checkpoint_protocol]
65
+ [step:spawn_section_writer]
66
+ EMIT:
67
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
68
+ WTF-P ► WRITING SECTION {X} PLAN {Y}
69
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
70
+
71
+ BUILD writer_prompt with inlined content:
72
+ - <writing_context> STATE, PROJECT, ROADMAP, prior summaries, structure docs
73
+ - <plan> full PLAN.md content
74
+ - <user_decisions> CONTEXT_CONTENT (from CONTEXT.md)
75
+ - <output> target paper file path, SUMMARY.md path
76
+
77
+ SPAWN:
78
+ Task(
79
+ prompt="First, read ~/.claude/agents/wtfp/section-writer.md for your role and instructions.\n\n" + writer_prompt,
80
+ subagent_type="general-purpose",
81
+ model="{writer_model}",
82
+ description="Write Section {X} Plan {Y}"
83
+ )
84
+
85
+ HANDLE returns:
86
+ "## WRITING COMPLETE" → proceed to argument-verifier
87
+ "## CHECKPOINT REACHED" → present to user, wait, then resume agent
88
+ "## WRITING BLOCKED" → present blocker, ask user
181
89
  [/step]
182
90
 
183
- [step:verification_failure_gate]
91
+ [step:spawn_argument_verifier]
92
+ IF config.workflow.verifier=false → SKIP to record_completion
93
+
94
+ GOAL-BACKWARD VERIFICATION: Does written prose achieve section's purpose?
95
+ Not "did tasks complete" but "does the output deliver what the section promises?"
96
+
97
+ BUILD verifier_prompt:
98
+ - <plan> original PLAN.md (what was intended)
99
+ - <written_content> actual paper output (what was produced)
100
+ - <user_decisions> CONTEXT_CONTENT (what user wanted)
101
+ - <structure> argument-map.md, outline.md (what structure expects)
102
+
103
+ SPAWN:
104
+ Task(
105
+ prompt="First, read ~/.claude/agents/wtfp/argument-verifier.md for your role and instructions.\n\n" + verifier_prompt,
106
+ subagent_type="general-purpose",
107
+ model="{verifier_model}",
108
+ description="Verify Section {X} Plan {Y}"
109
+ )
110
+
111
+ HANDLE returns:
112
+ "VERIFIED" → proceed to record_completion
113
+ "GAPS_FOUND" → present gaps to user, offer: fix now | note for later | accept as-is
114
+ "HUMAN_NEEDED" → present concern, wait for user decision
184
115
  [/step]
185
116
 
186
117
  [step:record_completion_time]
187
118
  RUN: PLAN_END_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
188
119
  [/step]
189
120
 
190
- [step:create_summary]
191
- [/step]
192
-
193
121
  [step:update_state]
122
+ UPDATE STATE.md: position, word count, argument strength, last activity
194
123
  [/step]
195
124
 
196
125
  [step:update_roadmap]
197
- IF more_plans_remain_in_this_section → - Update plan count: "2/3 plans complete"
198
- IF this_was_the_last_plan_in_the_section → - Mark section complete: status → "Complete"
126
+ IF more_plans_remain_in_this_section → Update plan count: "2/3 plans complete"
127
+ IF this_was_the_last_plan_in_the_section → Mark section complete: status → "Complete"
199
128
  [/step]
200
129
 
201
130
  [step:git_commit_metadata]
202
131
  RUN: git add .planning/sections/XX-name/{section}-{plan}-SUMMARY.md
132
+ RUN: git add .planning/STATE.md
133
+ RUN: git add .planning/ROADMAP.md
134
+ COMMIT: "docs({section}-{plan}): complete [plan-name] - [N] tasks, [word-count] words"
203
135
  [/step]
204
136
 
205
137
  [step:offer_next]
206
138
  RUN: ls -1 .planning/sections/[current-section-dir]/*-PLAN.md 2>/dev/null | wc -l
139
+ RUN: ls -1 .planning/sections/[current-section-dir]/*-SUMMARY.md 2>/dev/null | wc -l
140
+
141
+ ROUTE_A (more plans remain):
142
+ EMIT: "{Y} of {X} plans complete. Next: /wtfp:write-section {next-plan}"
143
+
144
+ ROUTE_B (section complete, more sections remain):
145
+ EMIT: "Section {Z} complete. Next: /wtfp:plan-section {Z+1}"
146
+
147
+ ROUTE_C (document complete):
148
+ EMIT: "All sections complete. Next: /wtfp:submit-draft"
207
149
  [/step]
208
150
 
209
151
  </process>
210
152
 
211
- <success_criteria>
153
+ <writing_modes>
154
+ Co-Author (Claude drafts): Write prose, match voice, flag [CITE:] and [VERIFY:], hit word target.
155
+ Scaffold (Claude outlines): Paragraph-level outline, citation placement, transitions. User writes.
156
+ Reviewer (Claude critiques): Strengths first, gaps, suggestions. Ask before major changes.
157
+ </writing_modes>
158
+
159
+ <deviation_rules>
160
+ RULE_PRIORITY:
161
+ 1. Rule 4 (structural changes) → STOP, ask user
162
+ 2. Rules 1-3 (errors, missing elements, blockers) → auto-fix, track for SUMMARY
163
+ 3. Rule 5 (enhancements) → log for later, continue
164
+
165
+ [rule:autofix_factual_errors] TRIGGER: incorrect_fact | wrong_citation | contradiction → fix + track [/rule]
166
+ [rule:autoadd_missing_critical] TRIGGER: required_element_missing → add + track [/rule]
167
+ [rule:autofix_blocking] TRIGGER: something_prevents_task_completion → fix + track [/rule]
168
+ [rule:ask_structural] TRIGGER: significant_restructuring_needed → STOP + present + wait [/rule]
169
+ [rule:log_enhancements] TRIGGER: nice_improvement_not_essential → log + continue [/rule]
170
+ </deviation_rules>
212
171
 
213
- - All tasks from PLAN.md completed
214
- - All verifications pass (citation, coherence, rubric)
215
- - SUMMARY.md created with substantive content
216
- - STATE.md updated (position, word count, argument strength)
217
- - ROADMAP.md updated
218
- - Paper content committed with meaningful messages
219
- </success_criteria>
172
+ <task_commit>
173
+ After each task: git status → stage task files → commit with type prefix.
174
+ TYPES: content | cite | revise | fix | structure
175
+ FORMAT: "{type}({section}-{plan}): {description}"
176
+ Record hash for SUMMARY.md.
177
+ </task_commit>
178
+
179
+ <success_criteria>
180
+ - [ ] Model profile resolved, agent models determined
181
+ - [ ] CONTEXT.md loaded early and passed to writer agent
182
+ - [ ] Section-writer agent spawned with full context + PLAN.md
183
+ - [ ] All tasks from PLAN.md completed
184
+ - [ ] All verifications pass (citation, coherence, rubric)
185
+ - [ ] Argument-verifier confirmed section achieves purpose (or skipped per config)
186
+ - [ ] SUMMARY.md created with substantive content
187
+ - [ ] STATE.md updated (position, word count, argument strength)
188
+ - [ ] ROADMAP.md updated
189
+ - [ ] Paper content committed with meaningful messages
190
+ - [ ] User knows next steps
191
+ </success_criteria>