jdi-cli 0.1.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 (159) hide show
  1. package/AGENTS.md +209 -0
  2. package/ARCHITECTURE.md +210 -0
  3. package/COMMANDS.md +241 -0
  4. package/CREATE-EXAMPLE.md +385 -0
  5. package/CREATE.md +315 -0
  6. package/EXTENSION.md +141 -0
  7. package/LICENSE +21 -0
  8. package/MEMORY.md +471 -0
  9. package/PORTABILITY.md +438 -0
  10. package/README.md +789 -0
  11. package/bin/git-hooks/post-commit +16 -0
  12. package/bin/git-hooks/pre-commit +21 -0
  13. package/bin/jdi-build.ps1 +381 -0
  14. package/bin/jdi-build.sh +332 -0
  15. package/bin/jdi-doctor.ps1 +403 -0
  16. package/bin/jdi-doctor.sh +400 -0
  17. package/bin/jdi-install-caveman.ps1 +97 -0
  18. package/bin/jdi-install-caveman.sh +99 -0
  19. package/bin/jdi-install-playwright.ps1 +319 -0
  20. package/bin/jdi-install-playwright.sh +284 -0
  21. package/bin/jdi-install.ps1 +154 -0
  22. package/bin/jdi-install.sh +132 -0
  23. package/bin/jdi-uninstall.ps1 +309 -0
  24. package/bin/jdi-uninstall.sh +264 -0
  25. package/bin/jdi-update.ps1 +215 -0
  26. package/bin/jdi-update.sh +209 -0
  27. package/bin/jdi.js +460 -0
  28. package/bin/lib/jdi-monitor.ps1 +66 -0
  29. package/bin/lib/jdi-monitor.sh +74 -0
  30. package/bin/lib/jdi-truncate.ps1 +96 -0
  31. package/bin/lib/jdi-truncate.sh +99 -0
  32. package/bin/lib/ui.js +197 -0
  33. package/core/agents/jdi-adopter.md +465 -0
  34. package/core/agents/jdi-architect.md +894 -0
  35. package/core/agents/jdi-asker.md +153 -0
  36. package/core/agents/jdi-bootstrap.md +247 -0
  37. package/core/agents/jdi-planner.md +254 -0
  38. package/core/agents/jdi-researcher.md +303 -0
  39. package/core/commands/jdi-adopt.md +155 -0
  40. package/core/commands/jdi-bootstrap.md +81 -0
  41. package/core/commands/jdi-create.md +80 -0
  42. package/core/commands/jdi-discuss.md +80 -0
  43. package/core/commands/jdi-do.md +200 -0
  44. package/core/commands/jdi-loop.md +315 -0
  45. package/core/commands/jdi-new.md +131 -0
  46. package/core/commands/jdi-plan.md +73 -0
  47. package/core/commands/jdi-ship.md +146 -0
  48. package/core/commands/jdi-verify.md +159 -0
  49. package/core/skills/clean-code/SKILL.md +261 -0
  50. package/core/skills/dry/SKILL.md +150 -0
  51. package/core/skills/frontend-rules/SKILL.md +386 -0
  52. package/core/skills/frontend-validator/SKILL.md +567 -0
  53. package/core/skills/kiss/SKILL.md +178 -0
  54. package/core/skills/solid/SKILL.md +281 -0
  55. package/core/skills/yagni/SKILL.md +207 -0
  56. package/core/templates/agent.md +72 -0
  57. package/core/templates/doer-specialist.md +216 -0
  58. package/core/templates/reviewer-specialist.md +405 -0
  59. package/core/templates/skill.md +66 -0
  60. package/package.json +70 -0
  61. package/runtimes/antigravity/agents.md +74 -0
  62. package/runtimes/antigravity/skills/clean-code/SKILL.md +252 -0
  63. package/runtimes/antigravity/skills/dry/SKILL.md +141 -0
  64. package/runtimes/antigravity/skills/frontend-rules/SKILL.md +376 -0
  65. package/runtimes/antigravity/skills/frontend-validator/SKILL.md +559 -0
  66. package/runtimes/antigravity/skills/jdi-adopt/SKILL.md +155 -0
  67. package/runtimes/antigravity/skills/jdi-adopter/SKILL.md +436 -0
  68. package/runtimes/antigravity/skills/jdi-architect/SKILL.md +872 -0
  69. package/runtimes/antigravity/skills/jdi-asker/SKILL.md +125 -0
  70. package/runtimes/antigravity/skills/jdi-asker/references/context-template.md +34 -0
  71. package/runtimes/antigravity/skills/jdi-asker/references/decision-format.md +19 -0
  72. package/runtimes/antigravity/skills/jdi-asker/scripts/find_phase_dir.sh +25 -0
  73. package/runtimes/antigravity/skills/jdi-bootstrap/SKILL.md +81 -0
  74. package/runtimes/antigravity/skills/jdi-create/SKILL.md +80 -0
  75. package/runtimes/antigravity/skills/jdi-discuss/SKILL.md +80 -0
  76. package/runtimes/antigravity/skills/jdi-discuss/scripts/run_command.sh +62 -0
  77. package/runtimes/antigravity/skills/jdi-do/SKILL.md +200 -0
  78. package/runtimes/antigravity/skills/jdi-loop/SKILL.md +315 -0
  79. package/runtimes/antigravity/skills/jdi-new/SKILL.md +131 -0
  80. package/runtimes/antigravity/skills/jdi-plan/SKILL.md +73 -0
  81. package/runtimes/antigravity/skills/jdi-planner/SKILL.md +225 -0
  82. package/runtimes/antigravity/skills/jdi-researcher/SKILL.md +274 -0
  83. package/runtimes/antigravity/skills/jdi-ship/SKILL.md +146 -0
  84. package/runtimes/antigravity/skills/jdi-verify/SKILL.md +159 -0
  85. package/runtimes/antigravity/skills/kiss/SKILL.md +169 -0
  86. package/runtimes/antigravity/skills/solid/SKILL.md +272 -0
  87. package/runtimes/antigravity/skills/yagni/SKILL.md +198 -0
  88. package/runtimes/claude/CLAUDE.md +91 -0
  89. package/runtimes/claude/agents/jdi-adopter.md +430 -0
  90. package/runtimes/claude/agents/jdi-architect.md +864 -0
  91. package/runtimes/claude/agents/jdi-asker.md +119 -0
  92. package/runtimes/claude/agents/jdi-bootstrap.md +213 -0
  93. package/runtimes/claude/agents/jdi-planner.md +221 -0
  94. package/runtimes/claude/agents/jdi-researcher.md +269 -0
  95. package/runtimes/claude/commands/jdi-adopt.md +155 -0
  96. package/runtimes/claude/commands/jdi-bootstrap.md +81 -0
  97. package/runtimes/claude/commands/jdi-create.md +80 -0
  98. package/runtimes/claude/commands/jdi-discuss.md +80 -0
  99. package/runtimes/claude/commands/jdi-do.md +200 -0
  100. package/runtimes/claude/commands/jdi-loop.md +315 -0
  101. package/runtimes/claude/commands/jdi-new.md +131 -0
  102. package/runtimes/claude/commands/jdi-plan.md +73 -0
  103. package/runtimes/claude/commands/jdi-ship.md +146 -0
  104. package/runtimes/claude/commands/jdi-verify.md +159 -0
  105. package/runtimes/claude/settings.example.json +132 -0
  106. package/runtimes/claude/skills/clean-code/SKILL.md +247 -0
  107. package/runtimes/claude/skills/dry/SKILL.md +136 -0
  108. package/runtimes/claude/skills/frontend-rules/SKILL.md +369 -0
  109. package/runtimes/claude/skills/frontend-validator/SKILL.md +553 -0
  110. package/runtimes/claude/skills/kiss/SKILL.md +164 -0
  111. package/runtimes/claude/skills/solid/SKILL.md +267 -0
  112. package/runtimes/claude/skills/yagni/SKILL.md +193 -0
  113. package/runtimes/copilot/agents/jdi-adopter.agent.md +430 -0
  114. package/runtimes/copilot/agents/jdi-architect.agent.md +864 -0
  115. package/runtimes/copilot/agents/jdi-asker.agent.md +119 -0
  116. package/runtimes/copilot/agents/jdi-bootstrap.agent.md +213 -0
  117. package/runtimes/copilot/agents/jdi-planner.agent.md +221 -0
  118. package/runtimes/copilot/agents/jdi-researcher.agent.md +269 -0
  119. package/runtimes/copilot/copilot-instructions.md +80 -0
  120. package/runtimes/copilot/prompts/jdi-adopt.prompt.md +155 -0
  121. package/runtimes/copilot/prompts/jdi-bootstrap.prompt.md +81 -0
  122. package/runtimes/copilot/prompts/jdi-create.prompt.md +80 -0
  123. package/runtimes/copilot/prompts/jdi-discuss.prompt.md +80 -0
  124. package/runtimes/copilot/prompts/jdi-do.prompt.md +200 -0
  125. package/runtimes/copilot/prompts/jdi-loop.prompt.md +315 -0
  126. package/runtimes/copilot/prompts/jdi-new.prompt.md +131 -0
  127. package/runtimes/copilot/prompts/jdi-plan.prompt.md +73 -0
  128. package/runtimes/copilot/prompts/jdi-ship.prompt.md +146 -0
  129. package/runtimes/copilot/prompts/jdi-verify.prompt.md +159 -0
  130. package/runtimes/opencode/AGENTS.md +87 -0
  131. package/runtimes/opencode/agents/jdi-adopter.md +434 -0
  132. package/runtimes/opencode/agents/jdi-architect.md +861 -0
  133. package/runtimes/opencode/agents/jdi-asker.md +123 -0
  134. package/runtimes/opencode/agents/jdi-bootstrap.md +217 -0
  135. package/runtimes/opencode/agents/jdi-planner.md +225 -0
  136. package/runtimes/opencode/agents/jdi-researcher.md +273 -0
  137. package/runtimes/opencode/commands/jdi-adopt.md +155 -0
  138. package/runtimes/opencode/commands/jdi-bootstrap.md +81 -0
  139. package/runtimes/opencode/commands/jdi-create.md +80 -0
  140. package/runtimes/opencode/commands/jdi-discuss.md +80 -0
  141. package/runtimes/opencode/commands/jdi-do.md +200 -0
  142. package/runtimes/opencode/commands/jdi-loop.md +315 -0
  143. package/runtimes/opencode/commands/jdi-new.md +131 -0
  144. package/runtimes/opencode/commands/jdi-plan.md +73 -0
  145. package/runtimes/opencode/commands/jdi-ship.md +146 -0
  146. package/runtimes/opencode/commands/jdi-verify.md +159 -0
  147. package/runtimes/opencode/opencode.example.jsonc +169 -0
  148. package/runtimes/opencode/skills/clean-code/SKILL.md +247 -0
  149. package/runtimes/opencode/skills/dry/SKILL.md +136 -0
  150. package/runtimes/opencode/skills/frontend-rules/SKILL.md +369 -0
  151. package/runtimes/opencode/skills/frontend-validator/SKILL.md +553 -0
  152. package/runtimes/opencode/skills/kiss/SKILL.md +164 -0
  153. package/runtimes/opencode/skills/solid/SKILL.md +267 -0
  154. package/runtimes/opencode/skills/yagni/SKILL.md +193 -0
  155. package/templates-jdi-folder/config.json +18 -0
  156. package/templates-jdi-folder/registry.md +31 -0
  157. package/templates-jdi-folder/reviewers.md +33 -0
  158. package/templates-jdi-folder/skills-registry.md +32 -0
  159. package/templates-jdi-folder/specialists.md +39 -0
@@ -0,0 +1,200 @@
1
+ ---
2
+ name: jdi-do
3
+ description: Executes phase. Automatic routing to project's doer specialist. Wave-based parallel if phase has >=3 independent tasks.
4
+ argument_hint: "<phase_number> [--sequential]"
5
+ runtime_intent:
6
+ invokes_agent: dynamic
7
+ runtime_overrides:
8
+ claude:
9
+ allowed-tools: [Read, Write, Edit, Bash, Grep, Glob, AskUserQuestion, Agent]
10
+ copilot:
11
+ tools: [read, write, edit, grep, glob, terminal]
12
+ opencode:
13
+ subtask: true
14
+ model: anthropic/claude-sonnet-4-20250514
15
+ antigravity:
16
+ triggers:
17
+ - "/jdi-do"
18
+ - "execute phase {N}"
19
+ ---
20
+
21
+ <objective>
22
+ Executes all tasks of the given phase. Reads PLAN.md, groups into waves, dispatches doer specialist (jdi-doer-{slug}). Wave-based parallelism, sequential dispatch (one Agent per message with `run_in_background`).
23
+ </objective>
24
+
25
+ <arguments>
26
+ - `phase_number` (required)
27
+ - `--sequential` (optional): forces sequential execution even if waves allow parallel. Useful for debug.
28
+ </arguments>
29
+
30
+ <process>
31
+
32
+ ### Step 1: Validation
33
+ ```bash
34
+ test -d .jdi/ || { echo "Not a JDI project. /jdi-new."; exit 1; }
35
+ test -f .jdi/STATE.md || { echo "STATE.md missing."; exit 1; }
36
+
37
+ # Verify specialist exists
38
+ ls .jdi/agents/jdi-doer-*.md 2>/dev/null | head -1 || {
39
+ echo "Doer specialist missing. Run /jdi-bootstrap."
40
+ exit 1
41
+ }
42
+
43
+ # Verify PLAN.md exists for phase
44
+ ls .jdi/phases/{NN}*/PLAN.md 2>/dev/null || {
45
+ echo "PLAN.md missing for phase {N}. Run /jdi-plan {N}."
46
+ exit 1
47
+ }
48
+
49
+ # Context budget warm-up (does not block)
50
+ JDI_LIB="$(dirname "$(command -v jdi 2>/dev/null || echo /usr/local/bin/jdi)")/../lib"
51
+ if [ -f "$JDI_LIB/jdi-monitor.sh" ]; then
52
+ bash "$JDI_LIB/jdi-monitor.sh" .jdi/PROJECT.md .jdi/DECISIONS.md .jdi/phases/{NN}*/PLAN.md .jdi/phases/{NN}*/CONTEXT.md || true
53
+ fi
54
+ # Windows: pwsh -File "$JDI_LIB/jdi-monitor.ps1" -Paths @(...)
55
+ ```
56
+
57
+ ### Step 2: Resolve doer specialist(s)
58
+
59
+ Read `.jdi/specialists.md`. Detect single vs multi-stack.
60
+
61
+ ```bash
62
+ DOER_COUNT=$(grep -cE 'jdi-doer-[a-z0-9-]+' .jdi/specialists.md)
63
+ echo "Specialists registered: $DOER_COUNT"
64
+
65
+ if [ "$DOER_COUNT" -eq 0 ]; then
66
+ echo "No doer registered. Run /jdi-bootstrap."
67
+ exit 1
68
+ fi
69
+ ```
70
+
71
+ **Single-stack** (`DOER_COUNT == 1`): take that doer, ignore task.specialist.
72
+ ```bash
73
+ DOER=$(grep -oE 'jdi-doer-[a-z0-9-]+' .jdi/specialists.md | head -1)
74
+ ```
75
+
76
+ **Multi-stack** (`DOER_COUNT > 1`): for each task in PLAN.md, read its `**Specialist:**` field (planner set this). Dispatch to that specialist. Tasks in same wave can spawn DIFFERENT specialists in parallel.
77
+
78
+ ```bash
79
+ # Per task, extract specialist from PLAN.md
80
+ TASK_SPEC=$(awk -v t="$task_id" '/^#### '"$task_id"':/{flag=1} flag && /^\*\*Specialist:\*\*/{print $2; exit}' .jdi/phases/{NN}*/PLAN.md)
81
+ ```
82
+
83
+ If task lacks specialist field (legacy PLAN.md pre-1.12) → fallback to first doer registered.
84
+
85
+ ### Step 3: Read PLAN.md, group waves
86
+
87
+ Parse PLAN.md, extract:
88
+ - List of pending tasks (`status: pending`)
89
+ - Each task's wave
90
+ - Files_modified
91
+
92
+ If `--sequential` or phase has <3 parallel tasks: use sequential execution (1 doer at a time).
93
+
94
+ Otherwise: wave-based parallel.
95
+
96
+ ### Step 4: Intra-wave overlap check (safety)
97
+
98
+ For each wave:
99
+ - Get list of files_modified per task
100
+ - Check pair-by-pair: do 2 tasks share a file?
101
+ - If yes -> override to sequential for that wave (warn user)
102
+
103
+ ### Step 5: Execute waves
104
+
105
+ **For each wave in order:**
106
+
107
+ ```
108
+ [wave {W}/{total}] starting, {N} tasks
109
+ ```
110
+
111
+ **If parallel (>=2 tasks in wave + no overlap + not --sequential):**
112
+
113
+ Sequential dispatch — ONE `Agent()` per message with `run_in_background: true`. Each task resolves its OWN `subagent_type` from task.specialist (multi-stack):
114
+
115
+ ```
116
+ # For each task in wave, resolve specialist:
117
+ TASK_SPECIALIST = <task.specialist field from PLAN.md> OR <single doer fallback>
118
+
119
+ Agent(
120
+ subagent_type="${TASK_SPECIALIST}", # may differ per task in multi-stack
121
+ description="Execute T-{X}.{Y} phase {N}",
122
+ prompt="phase={N}, task=T-{X}.{Y}, mode=single_task",
123
+ run_in_background: true
124
+ )
125
+ ```
126
+
127
+ Within a wave, multi-stack projects may spawn DIFFERENT specialists in parallel (e.g. `jdi-doer-myapp-backend` and `jdi-doer-myapp-frontend` simultaneously — different file scopes, disjoint `files_modified`).
128
+
129
+ Wait for all to return before next wave.
130
+
131
+ **If sequential:** same prompt, no `run_in_background`, one at a time.
132
+
133
+ Doer reads PLAN.md/PROJECT.md/CONTEXT.md on its own — specialist convention.
134
+
135
+ ### Step 6: After each wave
136
+
137
+ Read updated PLAN.md (doer updates status). Count:
138
+ - completed
139
+ - blocked
140
+ - pending
141
+
142
+ If any task `blocked` in critical wave -> stop execution, mark phase `partial`, skip to Step 8.
143
+
144
+ ### Step 7: After all waves
145
+
146
+ Verify SUMMARY.md was created:
147
+ ```bash
148
+ test -f .jdi/phases/{NN}*/SUMMARY.md || { echo "warn: SUMMARY missing"; }
149
+ ```
150
+
151
+ ### Step 8: Update STATE
152
+
153
+ ```markdown
154
+ current_phase: {N}
155
+ phase_status: {executed|partial}
156
+ next_step: /jdi-verify {N}
157
+ ```
158
+
159
+ ```bash
160
+ git add .jdi/STATE.md
161
+ git commit -m "chore(state): phase {N} executed"
162
+ ```
163
+
164
+ ### Step 9: Confirm
165
+
166
+ ```
167
+ Phase {N}: {done}/{total} tasks ({blocked} blocked), {W} waves, {count} files.
168
+ SUMMARY: .jdi/phases/{NN-slug}/SUMMARY.md
169
+ Next: /jdi-verify {N}
170
+ ```
171
+
172
+ </process>
173
+
174
+ <gates>
175
+ - pre: PLAN.md exists + doer specialist registered in .jdi/specialists.md
176
+ - post: tasks executed (partial or total), SUMMARY.md created, STATE updated
177
+ </gates>
178
+
179
+ <errors>
180
+ - Doer missing -> /jdi-bootstrap
181
+ - PLAN missing -> /jdi-plan
182
+ - Doer fails on task -> task stays `blocked`, continue with the rest (does not abort all)
183
+ - Entire wave blocked -> abort phase, mark `partial`
184
+ </errors>
185
+
186
+ <runtime_notes>
187
+
188
+ **Claude Code:**
189
+ - Real sequential dispatch works via `run_in_background: true` in separate Agent calls
190
+ - Wait for completion via tool result notifications
191
+
192
+ **Copilot:**
193
+ - Subagent spawning does not return reliable signal
194
+ - Default = automatic `--sequential` in Copilot
195
+ - Loop foreach task, dispatch one at a time
196
+
197
+ **OpenCode/Antigravity:**
198
+ - Use runtime's native Task/spawn
199
+ - Parallelism if runtime supports
200
+ </runtime_notes>
@@ -0,0 +1,315 @@
1
+ ---
2
+ name: jdi-loop
3
+ description: Ralph loop — orchestrates auto dev↔review until APPROVED verdict. 5 iter cap, human gate + reset (max 3 resets = 15 iter absolute). Oscillation detection cuts dead loop early.
4
+ argument_hint: "<phase_number> [--max-iter=5] [--max-resets=3]"
5
+ runtime_intent:
6
+ invokes_agent: dynamic
7
+ runtime_overrides:
8
+ claude:
9
+ allowed-tools: [Read, Write, Edit, Bash, Grep, Glob, AskUserQuestion, Agent]
10
+ copilot:
11
+ tools: [read, write, edit, grep, glob, terminal]
12
+ opencode:
13
+ subtask: true
14
+ model: anthropic/claude-sonnet-4-20250514
15
+ antigravity:
16
+ triggers:
17
+ - "/jdi-loop"
18
+ - "ralph loop phase {N}"
19
+ - "auto review phase {N}"
20
+ ---
21
+
22
+ <objective>
23
+ Runs the `/jdi-do {N}` -> `/jdi-verify {N}` cycle in loop until APPROVED or APPROVED_WITH_WARNINGS verdict, with no human action between iters. Absolute cap: 5 iter per round + max 3 resets (15 iter total). Ask user before resetting.
24
+
25
+ Ralph pattern (Huntley + ASDLC):
26
+ - Generator/Judge separation (doer writes, reviewer reads)
27
+ - Bounded iteration (explicit cap)
28
+ - Objective exit criteria (REVIEW.md APPROVED verdict)
29
+ - Context rotation (each Agent spawn = fresh context)
30
+ - State persistence (LOOP.md + git commits)
31
+ - Oscillation detection (finding hash compare)
32
+ </objective>
33
+
34
+ <arguments>
35
+ - `phase_number` (required)
36
+ - `--max-iter=N` (optional, default 5): iter per round before human gate
37
+ - `--max-resets=N` (optional, default 3): reset rounds before kill switch
38
+ </arguments>
39
+
40
+ <process>
41
+
42
+ ### Step 1: Validation
43
+
44
+ ```bash
45
+ test -d .jdi/ || { echo "Not a JDI project. /jdi-new."; exit 1; }
46
+ test -f .jdi/STATE.md || { echo "STATE.md missing."; exit 1; }
47
+
48
+ # Specialists registered
49
+ ls .jdi/agents/jdi-doer-*.md 2>/dev/null | head -1 || {
50
+ echo "Doer missing. /jdi-bootstrap."; exit 1;
51
+ }
52
+ ls .jdi/agents/jdi-reviewer-*.md 2>/dev/null | head -1 || {
53
+ echo "Reviewer missing. /jdi-bootstrap."; exit 1;
54
+ }
55
+
56
+ # PLAN exists
57
+ ls .jdi/phases/{NN}*/PLAN.md 2>/dev/null || {
58
+ echo "PLAN missing for phase {N}. /jdi-plan {N}."; exit 1;
59
+ }
60
+ ```
61
+
62
+ ### Step 2: Initialize or resume LOOP.md
63
+
64
+ Path: `.jdi/phases/{NN-slug}/LOOP.md`
65
+
66
+ ```bash
67
+ LOOP_FILE=".jdi/phases/{NN-slug}/LOOP.md"
68
+
69
+ if [ ! -f "$LOOP_FILE" ]; then
70
+ cat > "$LOOP_FILE" <<EOF
71
+ ---
72
+ phase: {N}
73
+ iter: 0
74
+ total_resets: 0
75
+ status: running
76
+ max_iter_per_round: ${MAX_ITER:-5}
77
+ max_resets: ${MAX_RESETS:-3}
78
+ created_at: $(date -Iseconds)
79
+ ---
80
+
81
+ ## History
82
+
83
+ EOF
84
+ fi
85
+ ```
86
+
87
+ If already exists:
88
+ - Read `iter`, `total_resets`, `status` from frontmatter
89
+ - Terminal states (abort):
90
+ - `status == converged` -> abort: "Phase already converged. /jdi-ship {N}"
91
+ - `status == killed` -> abort: "Hard cap reached. Plan needs human review."
92
+ - Resumable states (continue — go back to running):
93
+ - `status == escalated` -> reset `iter: 0`, `status: running`, `total_resets` preserved, append marker `--- RESUMED from escalated at {ts} ---` in history. Continue loop.
94
+ - `status == paused` -> reset `iter: 0`, `status: running`, `total_resets` preserved, append marker `--- RESUMED from paused at {ts} ---` in history. Continue loop.
95
+ - Active state:
96
+ - `status == running` -> resume from current iter (session crash mid-loop case)
97
+
98
+ ### Step 3: Main loop
99
+
100
+ ```
101
+ loop:
102
+ iter++
103
+
104
+ # --- Step A: dispatch doer ---
105
+ Agent(
106
+ subagent_type=$DOER,
107
+ description="Loop iter {iter} doer phase {N}",
108
+ prompt="phase={N}, mode=ralph_loop, iter={iter}"
109
+ )
110
+
111
+ # Doer detects ralph mode via presence of LOOP.md + REVIEW.md (Step 1 of specialist).
112
+ # If REVIEW.md verdict=BLOCKED, focuses on fixing blockers.
113
+
114
+ # --- Step B: dispatch reviewer ---
115
+ Agent(
116
+ subagent_type=$REVIEWER,
117
+ description="Loop iter {iter} reviewer phase {N}",
118
+ prompt="phase={N}, mode=verify, iter={iter}"
119
+ )
120
+
121
+ # --- Step C: parse verdict ---
122
+ REVIEW_FILE=".jdi/phases/{NN-slug}/REVIEW.md"
123
+ test -f "$REVIEW_FILE" || { echo "REVIEW.md not created at iter {iter}"; exit 1; }
124
+
125
+ VERDICT=$(grep -oE 'Verdict:\*\* (APPROVED|APPROVED_WITH_WARNINGS|BLOCKED)' "$REVIEW_FILE" | awk '{print $2}')
126
+
127
+ # --- Step D: hash findings (oscillation detection) ---
128
+ FINDING_BODY=$(awk '
129
+ /^## Blockers/ { flag=1; next }
130
+ /^## Warnings/ { flag=1; next }
131
+ /^## / { flag=0 }
132
+ flag { print }
133
+ ' "$REVIEW_FILE")
134
+
135
+ FINDING_HASH=$(echo "$FINDING_BODY" | sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[^ ]*//g' | tr '[:upper:]' '[:lower:]' | grep -v '^[[:space:]]*$' | sort -u | sha256sum | cut -c1-12)
136
+ [ -z "$FINDING_HASH" ] && FINDING_HASH=$(echo -n "" | sha256sum | cut -c1-12)
137
+
138
+ # --- Step E: append history to LOOP.md ---
139
+ # Append line in ## History of LOOP.md:
140
+ # - iter {N}: {VERDICT}, hash={HASH}, commit={SHA}, ts={ISO}
141
+
142
+ COMMIT_SHA=$(git rev-parse --short HEAD)
143
+ cat >> "$LOOP_FILE" <<EOF
144
+ - iter $iter: $VERDICT, hash=$FINDING_HASH, commit=$COMMIT_SHA, ts=$(date -Iseconds)
145
+ EOF
146
+
147
+ # Update frontmatter (iter, status)
148
+ # ... sed/awk substitute "iter:" line in frontmatter
149
+
150
+ # --- Step F: convergence check ---
151
+ if [ "$VERDICT" = "APPROVED" ] || [ "$VERDICT" = "APPROVED_WITH_WARNINGS" ]; then
152
+ # converged
153
+ Update LOOP.md frontmatter -> status: converged
154
+ Update STATE.md -> phase_status: verified, phase_verdict: $VERDICT, next_step: /jdi-ship {N}
155
+ git add .jdi/phases/{NN-slug}/LOOP.md .jdi/STATE.md
156
+ git commit -m "chore({phase-slug}): loop converged at iter $iter ($VERDICT)"
157
+ echo "Phase {N} converged at iter $iter. Verdict: $VERDICT"
158
+ echo "Next: /jdi-ship {N}"
159
+ exit 0
160
+ fi
161
+
162
+ # --- Step G: oscillation detection (early-escalate) ---
163
+ # Compare FINDING_HASH with previous iter's hash
164
+ # Guard: need >=2 iter lines in LOOP.md history to compare
165
+ ITER_COUNT=$(grep -cE '^- iter [0-9]+:' "$LOOP_FILE")
166
+ if [ "$ITER_COUNT" -ge 2 ]; then
167
+ PREV_HASH=$(grep -E '^- iter [0-9]+:' "$LOOP_FILE" | tail -2 | head -1 | grep -oE 'hash=[a-f0-9]+' | cut -d= -f2)
168
+ else
169
+ PREV_HASH=""
170
+ fi
171
+
172
+ if [ -n "$PREV_HASH" ] && [ "$FINDING_HASH" = "$PREV_HASH" ]; then
173
+ AskUserQuestion(
174
+ question="Oscillation detected on phase {N}. Iter $iter and $((iter-1)) have SAME finding hash ($FINDING_HASH). Loop not progressing. What now?",
175
+ options=[
176
+ "Continue (reset counter, 5 more iter)" => continue_with_reset,
177
+ "Abort loop (status=escalated, stays in REVIEW.md)" => abort,
178
+ "Adjust plan (status=paused, you edit PLAN.md/CONTEXT.md, re-run /jdi-loop {N})" => pause
179
+ ]
180
+ )
181
+
182
+ case answer:
183
+ continue_with_reset: goto reset_logic
184
+ abort: goto abort_logic
185
+ pause: goto pause_logic
186
+ fi
187
+
188
+ # --- Step H: cap check ---
189
+ if [ "$iter" -ge "${MAX_ITER:-5}" ]; then
190
+ AskUserQuestion(
191
+ question="Phase {N}: $iter iter without APPROVED. Cost grows. What now?",
192
+ options=[
193
+ "Continue (reset counter, ${MAX_ITER:-5} more iter)" => continue_with_reset,
194
+ "Abort (status=escalated)" => abort,
195
+ "Adjust plan (status=paused)" => pause
196
+ ]
197
+ )
198
+
199
+ case answer:
200
+ continue_with_reset: goto reset_logic
201
+ abort: goto abort_logic
202
+ pause: goto pause_logic
203
+ fi
204
+
205
+ # otherwise, next iter
206
+ continue
207
+ ```
208
+
209
+ ### Step 4: Reset logic
210
+
211
+ ```
212
+ reset_logic:
213
+ total_resets++
214
+
215
+ if [ "$total_resets" -ge "${MAX_RESETS:-3}" ]; then
216
+ # Absolute kill switch
217
+ Update LOOP.md -> status: killed
218
+ Update STATE.md -> phase_status: blocked, phase_verdict: BLOCKED, next_step: human review of PLAN.md/CONTEXT.md (loop killed)
219
+ git add .jdi/phases/{NN-slug}/LOOP.md .jdi/STATE.md
220
+ git commit -m "chore({phase-slug}): loop killed (3 resets, $((iter * total_resets)) iter total)"
221
+ echo "Hard cap reached (${MAX_RESETS:-3} resets). Loop killed."
222
+ echo "Action: manually review PLAN.md or CONTEXT.md. Maybe fragment phase."
223
+ exit 1
224
+ fi
225
+
226
+ # Reset counter, history append-only
227
+ iter=0
228
+ Update LOOP.md frontmatter -> iter: 0, total_resets: $total_resets
229
+ Append in LOOP.md history: "--- RESET $total_resets at $(date -Iseconds) ---"
230
+ echo "Reset $total_resets/${MAX_RESETS:-3}. New round of ${MAX_ITER:-5} iter."
231
+ goto loop
232
+ ```
233
+
234
+ ### Step 5: Abort logic
235
+
236
+ ```
237
+ abort_logic:
238
+ Update LOOP.md -> status: escalated
239
+ Update STATE.md -> phase_status: blocked, phase_verdict: BLOCKED, next_step: review REVIEW.md, fix manually or /jdi-loop {N} to resume
240
+ git add .jdi/phases/{NN-slug}/LOOP.md .jdi/STATE.md
241
+ git commit -m "chore({phase-slug}): loop aborted at iter $iter (user escalated)"
242
+ echo "Loop aborted. REVIEW.md has latest findings."
243
+ echo "Re-run /jdi-loop {N} to resume (status returns to running automatically)."
244
+ exit 0
245
+ ```
246
+
247
+ ### Step 6: Pause logic
248
+
249
+ ```
250
+ pause_logic:
251
+ Update LOOP.md -> status: paused
252
+ Update STATE.md -> phase_status: paused, next_step: edit PLAN.md/CONTEXT.md and re-run /jdi-loop {N}
253
+ echo "Loop paused. Edit PLAN.md or CONTEXT.md."
254
+ echo "When ready: /jdi-loop {N}. Will resume with status=running, iter=0, same total_resets."
255
+ exit 0
256
+ ```
257
+
258
+ ### Step 7: Final confirmation (convergence)
259
+
260
+ ```
261
+ Phase {N}: converged at $iter iter (resets: $total_resets). Verdict: $VERDICT.
262
+ LOOP.md + REVIEW.md in .jdi/phases/{NN-slug}/
263
+ Next: /jdi-ship {N}
264
+ ```
265
+
266
+ </process>
267
+
268
+ <gates>
269
+ - pre: PLAN.md + doer + reviewer registered in specialists.md/reviewers.md
270
+ - post: final status in LOOP.md ∈ {converged, escalated, paused, killed} + STATE updated
271
+ - invariant: each iter = doer commit + reviewer commit (granular audit trail)
272
+ </gates>
273
+
274
+ <errors>
275
+ - Doer/reviewer missing -> /jdi-bootstrap
276
+ - PLAN missing -> /jdi-plan
277
+ - LOOP.md corrupted (invalid frontmatter) -> backup to LOOP.md.bak, recreate from scratch
278
+ - REVIEW.md not created by reviewer -> exit 1 with error
279
+ - No changes in working dir after doer iter (doer did nothing) -> warn, but continue (reviewer may still find uncorrected previous issues)
280
+ </errors>
281
+
282
+ <runtime_notes>
283
+
284
+ **Claude Code:**
285
+ - Native AskUserQuestion for human gate
286
+ - Sequential Agent dispatch inside the loop (does not parallelize doer+reviewer — sequential by design)
287
+
288
+ **Copilot:**
289
+ - No native AskUserQuestion — use question in main chat and wait for answer before proceeding
290
+ - Loop control inline in command body (orchestrator = Copilot's main thread)
291
+
292
+ **OpenCode:**
293
+ - subtask: true for subagent dispatch
294
+ - Human gate question via main prompt
295
+
296
+ **Antigravity:**
297
+ - Skill discovered by trigger ("ralph loop phase 2", "auto review phase 2")
298
+ - AskUserQuestion via skill prose (ask + wait for text answer)
299
+ - Loop control inline in skill body
300
+ </runtime_notes>
301
+
302
+ <rules>
303
+ - NEVER skip human gate when iter >= max_iter or oscillation detected — controlled cost is invariant
304
+ - NEVER reset total_resets — only iter
305
+ - LOOP.md history is APPEND-ONLY (audit trail, never erase)
306
+ - Reviewer remains read-only always — doer is the only writer
307
+ - Each iter produces atomic commits (granularity preserved)
308
+ - Absolute hard cap = max_iter * max_resets (default 15) — non-negotiable kill switch
309
+ </rules>
310
+
311
+ <references>
312
+ - Ralph Wiggum technique (ghuntley.com/ralph)
313
+ - ASDLC Ralph Loop pattern (asdlc.io/patterns/ralph-loop)
314
+ - Convergence: P(C) = 1 - (1 - p_success)^n
315
+ </references>
@@ -0,0 +1,131 @@
1
+ ---
2
+ name: jdi-new
3
+ description: Entry point for new project. Runs research + asker, generates PROJECT.md + ROADMAP.md.
4
+ argument_hint: "<short project description>"
5
+ runtime_intent:
6
+ invokes_agent: jdi-researcher
7
+ runtime_overrides:
8
+ claude:
9
+ allowed-tools: [Read, Write, Bash, Grep, Glob, AskUserQuestion, WebSearch, WebFetch, Agent]
10
+ copilot:
11
+ tools: [read, write, grep, glob, terminal]
12
+ opencode:
13
+ agent: jdi-researcher
14
+ subtask: true
15
+ model: anthropic/claude-sonnet-4-20250514
16
+ antigravity:
17
+ triggers:
18
+ - "/jdi-new"
19
+ - "create project"
20
+ - "new app"
21
+ ---
22
+
23
+ <objective>
24
+ Initializes new JDI project. Runs research + key questions + generates PROJECT.md, ROADMAP.md, STATE.md, DECISIONS.md.
25
+ </objective>
26
+
27
+ <arguments>
28
+ - `description` (optional but recommended): short text of what to build.
29
+
30
+ Examples:
31
+ - `/jdi-new "TODO app .NET 10 + React 19"`
32
+ - `/jdi-new "Inventory REST API in Python + FastAPI"`
33
+ - `/jdi-new "Go CLI tool for log parsing"`
34
+ - `/jdi-new` (asker starts from scratch)
35
+ </arguments>
36
+
37
+ <process>
38
+
39
+ ### Step 1: Validation
40
+ ```bash
41
+ test -d .jdi/ && {
42
+ echo ".jdi/ already exists. Use /jdi-new --reset to start over (CAUTION: wipes state)."
43
+ exit 1
44
+ }
45
+
46
+ # Suggest /jdi-adopt if directory is NOT empty (likely brownfield)
47
+ file_count=$(find . -maxdepth 3 -type f \
48
+ -not -path './.git/*' -not -path './node_modules/*' \
49
+ -not -path './.venv/*' -not -path './venv/*' \
50
+ -not -path './target/*' -not -path './dist/*' -not -path './build/*' \
51
+ -not -path './bin/*' -not -path './obj/*' \
52
+ 2>/dev/null | wc -l)
53
+
54
+ if [ "$file_count" -ge 3 ]; then
55
+ # Ask before continuing — could be greenfield in monorepo
56
+ echo "Directory has $file_count code files. Looks like existing project."
57
+ echo "For brownfield projects, /jdi-adopt detects stack/code-design automatically."
58
+ echo "Continue with /jdi-new anyway? (recommended: /jdi-adopt)"
59
+ # AskUserQuestion: [Continue /jdi-new] / [Switch to /jdi-adopt] / [Cancel]
60
+ fi
61
+ ```
62
+
63
+ PowerShell:
64
+ ```powershell
65
+ if (Test-Path .jdi) { Write-Error ".jdi/ already exists. Use /jdi-new --reset."; exit 1 }
66
+ $files = Get-ChildItem -Recurse -File -Depth 3 -ErrorAction SilentlyContinue |
67
+ Where-Object { $_.FullName -notmatch '\\(\.git|node_modules|\.venv|venv|target|dist|build|bin|obj)\\' }
68
+ if ($files.Count -ge 3) {
69
+ Write-Host "Directory has $($files.Count) files. Consider /jdi-adopt instead of /jdi-new."
70
+ # Sequential AskUserQuestion
71
+ }
72
+ ```
73
+
74
+ If `--reset` passed, AskUserQuestion confirms + wipes `.jdi/`.
75
+
76
+ ### Step 2: Spawn researcher
77
+ Invoke `jdi-researcher` passing description. Wait.
78
+
79
+ ### Step 3: Verify outputs
80
+ ```bash
81
+ test -f .jdi/PROJECT.md || { echo "PROJECT.md not created"; exit 1; }
82
+ test -f .jdi/ROADMAP.md || { echo "ROADMAP.md not created"; exit 1; }
83
+ test -f .jdi/STATE.md || { echo "STATE.md not created"; exit 1; }
84
+ ```
85
+
86
+ ### Step 4: Create config.json (token/context budget)
87
+
88
+ If `.jdi/config.json` does not yet exist, write the default below. Defaults (200k context, 60/70% warn/critical, coverage 80%) cover 95% of cases. User edits if running a 1M-window model or wanting tighter thresholds.
89
+
90
+ ```json
91
+ {
92
+ "$schema_version": "1.1",
93
+ "context_window": 200000,
94
+ "thresholds": {
95
+ "warn_pct": 60,
96
+ "critical_pct": 70
97
+ },
98
+ "budgets": {
99
+ "max_context_chars": 6000,
100
+ "max_plan_chars": 12000,
101
+ "max_summary_chars": 8192
102
+ },
103
+ "compaction": {
104
+ "keep_phases": 2,
105
+ "archive_after": 5
106
+ },
107
+ "coverage_min": 80
108
+ }
109
+ ```
110
+
111
+ Canonical reference for the default also lives in `templates-jdi-folder/config.json` (shipped by npm package) — for users wanting to regenerate manually.
112
+
113
+ ### Step 5: Confirm
114
+
115
+ ```
116
+ {project_name} initialized. {N} phases planned in .jdi/.
117
+ Next: /jdi-bootstrap
118
+ ```
119
+
120
+ </process>
121
+
122
+ <gates>
123
+ - pre: directory without existing `.jdi/` (or `--reset`)
124
+ - post: PROJECT.md + ROADMAP.md + STATE.md + DECISIONS.md + config.json created, initial commit made
125
+ </gates>
126
+
127
+ <errors>
128
+ - `.jdi/` already exists -> suggest `--reset` or use current project
129
+ - Researcher cancelled -> exit clean
130
+ - Researcher failed -> show error, no commit
131
+ </errors>