loopgen 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 loopgen contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,414 @@
1
+ # loopgen
2
+
3
+ [![npm version](https://img.shields.io/npm/v/loopgen.svg)](https://www.npmjs.com/package/loopgen)
4
+ [![CI](https://github.com/Nagiici/Loopgen/actions/workflows/ci.yml/badge.svg)](https://github.com/Nagiici/Loopgen/actions/workflows/ci.yml)
5
+ [![license: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
6
+
7
+ **AI coding assistants can make unlimited changes. loopgen generates the guardrails.**
8
+
9
+ loopgen scans your project and generates bounded, inspectable **agent loop** configs — so your own
10
+ CI, tests, and lint verify every iteration before it goes further. Works with Claude Code, Codex,
11
+ Cursor, and local models (Ollama, LM Studio, llama.cpp).
12
+
13
+ ```bash
14
+ npx loopgen init # opens a local wizard in demo mode — no setup, nothing written to your project
15
+ ```
16
+
17
+ > **What's a "loop"?** A bounded, verifiable cycle: make the smallest change → run your verification
18
+ > commands → log what happened to a state file → stop or repeat, up to a hard iteration limit.
19
+
20
+ - 🛡️ **Safety by default** — bounded iterations (default 3), required verification, forbidden secret
21
+ paths, maker/checker separation, and a state-file audit log.
22
+ - 🔌 **Tool-agnostic** — one scan generates config for Codex, Claude, Cursor, and local runtimes.
23
+ - 🏠 **Local-first** — no telemetry, no cloud calls; API keys are referenced by env-var name only.
24
+
25
+ <!-- TODO: add a 15s demo GIF of the wizard (scan → preview diff → apply) here. -->
26
+
27
+ 📖 中文说明见 [中文](#中文) · English documentation [below](#english).
28
+
29
+ ---
30
+
31
+ ## 中文
32
+
33
+ ### 项目简介
34
+
35
+ `loopgen` 会扫描你的项目,推断语言、包管理器、测试/构建命令和 CI 配置,然后生成一组可审查的 loop 文件:
36
+
37
+ - 通用 `.loopgen/playbooks/*.md`:不依赖任何特定 AI 工具,适合先理解 loop engineering 的工作方式。
38
+ - Codex 配置:`.codex/skills/*`、`.codex/automations/*`、checker agent。
39
+ - Claude 配置:`.claude/skills/*`、`.claude/loops/*`、checker notes。
40
+ - 本地/开源模型适配器:Ollama 与 OpenAI-compatible server(例如 LM Studio、llama.cpp)的配置和 runbook。
41
+ - 状态记录:`.loopgen/state/*.md`,用于记录每次循环尝试、结果和阻塞点。
42
+
43
+ 核心目标是降低使用门槛:你可以先用内置 demo 项目预览效果,不需要接入真实项目,也不会写入真实项目文件。
44
+
45
+ ### 适合谁先尝试
46
+
47
+ 如果你有一个带 npm scripts 和 GitHub Actions 的 TypeScript/Node 项目,并且已经在用 Claude Code、Codex 或
48
+ Cursor,loopgen 能自动识别你的 test/lint/build 命令,并在 5 分钟内生成可直接使用的 agent 配置。其他角色(QA、
49
+ Ops、Product 等)也有对应模板。
50
+
51
+ ### 快速上手
52
+
53
+ #### 最快方式:npx(无需克隆)
54
+
55
+ ```bash
56
+ npx loopgen init # 在 demo 模式下打开本地向导,无需配置,也不会写入文件
57
+ ```
58
+
59
+ #### 从源码运行(开发场景)
60
+
61
+ ```bash
62
+ npm install
63
+ npm run build
64
+ npm run loopgen -- scan --demo
65
+ npm run loopgen -- preview --demo
66
+ ```
67
+
68
+ `--demo` 会使用内置示例项目 `examples/demo-webapp`,只生成预览,不会写入你的真实项目。
69
+
70
+ #### 3. 启动本地 Web 向导
71
+
72
+ ```bash
73
+ npm run loopgen -- init .
74
+ ```
75
+
76
+ 打开终端中打印的本地地址,通常是:
77
+
78
+ ```text
79
+ http://127.0.0.1:8787
80
+ ```
81
+
82
+ 在 Web 向导中:
83
+
84
+ 1. 选择 **Try demo**:快速查看 loop engineering 的效果。
85
+ 2. 选择 **Use my project**:扫描真实项目。
86
+ 3. 点击 **Choose folder** 从本地桌面选择项目目录,或手动粘贴项目路径。
87
+ 4. 按角色或场景选择模板。
88
+ 5. 点击 **Generate preview** 查看 diff。
89
+ 6. 确认无误后再点击 **Apply files** 写入项目。
90
+
91
+ #### 4. 在真实项目中生成预览
92
+
93
+ ```bash
94
+ npm run loopgen -- scan .
95
+ npm run loopgen -- preview . --templates test-repair --adapters codex,claude
96
+ ```
97
+
98
+ 生成 Ollama runbook:
99
+
100
+ ```bash
101
+ npm run loopgen -- preview . \
102
+ --templates test-repair \
103
+ --adapters ollama \
104
+ --ollama-model llama3.1
105
+ ```
106
+
107
+ 生成 LM Studio 或 llama.cpp 等 OpenAI-compatible runbook:
108
+
109
+ ```bash
110
+ npm run loopgen -- preview . \
111
+ --templates test-repair \
112
+ --adapters openai-compatible \
113
+ --openai-compatible-model qwen2.5-coder \
114
+ --openai-compatible-base-url http://localhost:1234/v1
115
+ ```
116
+
117
+ `loopgen` 只生成配置和运行手册,不会自动调用本地模型。API key 只通过环境变量名引用,不会把密钥值写入文件。
118
+
119
+ #### 5. 确认后写入文件
120
+
121
+ ```bash
122
+ npm run loopgen -- apply . --templates test-repair --adapters codex,claude
123
+ ```
124
+
125
+ 如果你已经确认 diff,可以使用:
126
+
127
+ ```bash
128
+ npm run loopgen -- apply . --templates test-repair --adapters codex,claude --yes
129
+ ```
130
+
131
+ ### 常用命令
132
+
133
+ ```bash
134
+ npm run loopgen -- init [project]
135
+ npm run loopgen -- scan --demo
136
+ npm run loopgen -- scan [project] --json
137
+ npm run loopgen -- preview --demo
138
+ npm run loopgen -- preview [project] --templates all --adapters codex,claude
139
+ npm run loopgen -- preview [project] --templates test-repair --adapters ollama --ollama-model llama3.1
140
+ npm run loopgen -- preview [project] --templates test-repair --adapters openai-compatible --openai-compatible-model qwen2.5-coder
141
+ npm run loopgen -- apply [project] --templates all --adapters codex,claude
142
+ ```
143
+
144
+ `apply` 会先展示 diff。没有 `--yes` 时,它会要求你确认后才写入文件。
145
+
146
+ 可用 adapter:
147
+
148
+ - `agents-md`:通用 `AGENTS.md`,可被 Claude Code、Codex、Cursor、Copilot、Gemini CLI、Aider 等读取
149
+ - `codex`
150
+ - `claude`
151
+ - `cursor`:`.cursor/rules/*.mdc` 规则
152
+ - `windsurf`:`.windsurfrules`
153
+ - `ollama`
154
+ - `openai-compatible`
155
+
156
+ 本地模型参数:
157
+
158
+ - `--ollama-model`
159
+ - `--ollama-base-url`,默认 `http://localhost:11434`
160
+ - `--openai-compatible-model`
161
+ - `--openai-compatible-base-url`,常见值包括 LM Studio 的 `http://localhost:1234/v1` 和 llama.cpp 的 `http://localhost:8080/v1`
162
+ - `--openai-compatible-api-key-env`,只填写环境变量名,例如 `LOCAL_LLM_API_KEY`
163
+
164
+ ### 模板场景
165
+
166
+ 当前模板库覆盖五类技术协作场景:
167
+
168
+ - **Maintenance**:CI 修复、测试修复、依赖升级、PR 评论处理。
169
+ - **Delivery**:发布准备、变更日志生成、回滚检查、版本升级检查。
170
+ - **Quality**:类型错误收敛、lint 清理、测试覆盖补洞、死代码清理。
171
+ - **Knowledge**:README 更新、架构说明、onboarding 指南、决策记录。
172
+ - **Cross-functional**:需求澄清、QA 验收清单、数据处理检查、客户问题复盘。
173
+
174
+ ### 生成文件
175
+
176
+ `loopgen` 会生成一组小而可审查的文件:
177
+
178
+ - `.loopgen/loopgen.loop.yaml`:中间 loop 表示。
179
+ - `.loopgen/playbooks/*.md`:通用 loop playbook。
180
+ - `.loopgen/state/*.md`:循环状态、尝试记录和阻塞点。
181
+ - `AGENTS.md`:通用 agent 指令文件,可被大多数 AI 编码工具读取。
182
+ - `.codex/skills/*`、`.codex/automations/*`、`.codex/agents/*`:Codex 适配输出。
183
+ - `.claude/skills/*`、`.claude/loops/*`、`.claude/agents/*`:Claude 适配输出。
184
+ - `.cursor/rules/*.mdc` 与 `.windsurfrules`:Cursor 与 Windsurf 规则。
185
+ - `.loopgen/adapters/ollama/config.json` 与 `.loopgen/adapters/ollama/*.md`:Ollama 本地运行时配置和 runbook。
186
+ - `.loopgen/adapters/openai-compatible/config.json` 与 `.loopgen/adapters/openai-compatible/*.md`:OpenAI-compatible server 配置和 runbook。
187
+
188
+ 默认安全策略包括:有限迭代、maker/checker 分离、必须验证、禁止读取敏感路径、状态文件记录。
189
+
190
+ 本地模型 runbook 会包含 loop 目标、上下文来源、验证命令、停止条件、状态文件路径、模型提示词模板,以及对应运行时的 `curl` 示例。
191
+
192
+ ### 故障排查
193
+
194
+ - 如果没有推断出验证命令,生成的 loop 会进入 draft 模式,并带有 TODO 验证命令。
195
+ - 如果选择了 Ollama 或 OpenAI-compatible adapter 但没有填写模型名,`loopgen` 仍会生成文件,并在 config 和 runbook 中留下 warning/TODO。
196
+ - 如果 Web 向导提示缺少静态资源,请先运行 `npm run build`。
197
+ - Demo 模式只能预览,不能写入文件;需要写入时请切换到 **Use my project**。
198
+ - 如果 loop 尝试读取 `.env`、生产密钥或 credential 文件,应立即停止并视为安全违规。
199
+ - 如果同一失败在最大迭代次数后仍重复出现,应停止并请求人工输入。
200
+
201
+ ### 贡献模板
202
+
203
+ 新增模板时,请修改 `src/core/templates.ts`,补充目标、上下文、步骤、验证命令、停止条件和模板元数据,并为生成结果添加测试。模板应保持明确、有限、可审查。
204
+
205
+ ---
206
+
207
+ ## English
208
+
209
+ ### Overview
210
+
211
+ `loopgen` scans a project, infers the language, package manager, verification commands and CI setup, then generates inspectable loop engineering files:
212
+
213
+ - Tool-agnostic `.loopgen/playbooks/*.md` files for anyone who wants to understand the loop before using an agent tool.
214
+ - Codex outputs: `.codex/skills/*`, `.codex/automations/*`, and checker agents.
215
+ - Claude outputs: `.claude/skills/*`, `.claude/loops/*`, and checker notes.
216
+ - Local/open-source model adapters: config and runbooks for Ollama and OpenAI-compatible servers such as LM Studio and llama.cpp.
217
+ - State files: `.loopgen/state/*.md` for recording attempts, outcomes and blockers.
218
+
219
+ The product goal is low-friction adoption. You can start with the built-in demo project, preview generated loops, and learn the value of loop engineering without writing to your real project.
220
+
221
+ ### Why loopgen?
222
+
223
+ Most AI coding agents optimize for speed and run with broad permissions. loopgen makes the opposite
224
+ trade-off the **default**, so an agent's work stays reviewable:
225
+
226
+ - **Bounded iterations** (default 3) — the loop stops instead of grinding forever.
227
+ - **Required verification** — success is defined by your real `test`/`lint`/`build` commands, not the model's say-so.
228
+ - **Forbidden secret paths** — `.env`, `secrets/**`, and credential files are off-limits by construction.
229
+ - **Maker/checker separation** — a separate checker reviews the diff and verification output before continuing.
230
+ - **State-file audit log** — every attempt, outcome, and blocker is written to `.loopgen/state/*.md`.
231
+
232
+ ### Who should start here
233
+
234
+ If you have a TypeScript/Node project with npm scripts and GitHub Actions and you already use Claude
235
+ Code, Codex, or Cursor, loopgen auto-detects your `test`/`lint`/`build` commands and generates
236
+ ready-to-use agent configs in under five minutes. Other roles (QA, Ops, Product, Data) have matching
237
+ templates too.
238
+
239
+ ### What you get
240
+
241
+ A small, inspectable set of files. For example, a generated Codex skill looks like:
242
+
243
+ ```markdown
244
+ ---
245
+ name: loopgen-test-repair
246
+ description: Diagnose failing tests in my-app, fix the underlying issue, and verify the relevant suite.
247
+ ---
248
+
249
+ # Test repair
250
+
251
+ ## Verify
252
+ - `npm run test`
253
+
254
+ ## Stop conditions
255
+ - A verification command is missing or undefined.
256
+ - The same failure repeats after the maximum iteration count.
257
+
258
+ State file: `.loopgen/state/test-repair.md`
259
+ Maximum iterations: 3
260
+ ```
261
+
262
+ ### Quick Start
263
+
264
+ #### Fastest: npx (no clone required)
265
+
266
+ ```bash
267
+ npx loopgen init # opens the local wizard in demo mode — no setup, nothing written
268
+ ```
269
+
270
+ #### From source (development)
271
+
272
+ ```bash
273
+ npm install
274
+ npm run build
275
+ npm run loopgen -- scan --demo
276
+ npm run loopgen -- preview --demo
277
+ ```
278
+
279
+ `--demo` uses the built-in `examples/demo-webapp` fixture. It is preview-only and will not write files to your real project.
280
+
281
+ #### 3. Start the local Web wizard
282
+
283
+ ```bash
284
+ npm run loopgen -- init .
285
+ ```
286
+
287
+ Open the printed local URL, usually:
288
+
289
+ ```text
290
+ http://127.0.0.1:8787
291
+ ```
292
+
293
+ In the wizard:
294
+
295
+ 1. Choose **Try demo** to see loop engineering outputs quickly.
296
+ 2. Choose **Use my project** to scan a real project.
297
+ 3. Click **Choose folder** to select a local project directory, or paste the project path manually.
298
+ 4. Filter templates by role or category.
299
+ 5. Click **Generate preview** to inspect the diff.
300
+ 6. Click **Apply files** only after reviewing the generated files.
301
+
302
+ #### 4. Preview loops for a real project
303
+
304
+ ```bash
305
+ npm run loopgen -- scan .
306
+ npm run loopgen -- preview . --templates test-repair --adapters codex,claude
307
+ ```
308
+
309
+ Generate Ollama runbooks:
310
+
311
+ ```bash
312
+ npm run loopgen -- preview . \
313
+ --templates test-repair \
314
+ --adapters ollama \
315
+ --ollama-model llama3.1
316
+ ```
317
+
318
+ Generate LM Studio, llama.cpp, or other OpenAI-compatible runbooks:
319
+
320
+ ```bash
321
+ npm run loopgen -- preview . \
322
+ --templates test-repair \
323
+ --adapters openai-compatible \
324
+ --openai-compatible-model qwen2.5-coder \
325
+ --openai-compatible-base-url http://localhost:1234/v1
326
+ ```
327
+
328
+ `loopgen` only generates configuration and runbooks. It does not execute local models automatically. API keys are referenced by environment variable name only; secret values are never written into generated files.
329
+
330
+ #### 5. Apply after review
331
+
332
+ ```bash
333
+ npm run loopgen -- apply . --templates test-repair --adapters codex,claude
334
+ ```
335
+
336
+ If you already reviewed the diff:
337
+
338
+ ```bash
339
+ npm run loopgen -- apply . --templates test-repair --adapters codex,claude --yes
340
+ ```
341
+
342
+ ### CLI
343
+
344
+ ```bash
345
+ npm run loopgen -- init [project]
346
+ npm run loopgen -- scan --demo
347
+ npm run loopgen -- scan [project] --json
348
+ npm run loopgen -- preview --demo
349
+ npm run loopgen -- preview [project] --templates all --adapters codex,claude
350
+ npm run loopgen -- preview [project] --templates test-repair --adapters ollama --ollama-model llama3.1
351
+ npm run loopgen -- preview [project] --templates test-repair --adapters openai-compatible --openai-compatible-model qwen2.5-coder
352
+ npm run loopgen -- apply [project] --templates all --adapters codex,claude
353
+ ```
354
+
355
+ `apply` always shows a diff first. Without `--yes`, it asks for confirmation before writing files.
356
+
357
+ Available adapters:
358
+
359
+ - `agents-md` — one `AGENTS.md` read by Claude Code, Codex, Cursor, Copilot, Gemini CLI, Aider, and more
360
+ - `codex`
361
+ - `claude`
362
+ - `cursor` — `.cursor/rules/*.mdc` rules
363
+ - `windsurf` — a `.windsurfrules` file
364
+ - `ollama`
365
+ - `openai-compatible`
366
+
367
+ Local model flags:
368
+
369
+ - `--ollama-model`
370
+ - `--ollama-base-url`, defaulting to `http://localhost:11434`
371
+ - `--openai-compatible-model`
372
+ - `--openai-compatible-base-url`, commonly `http://localhost:1234/v1` for LM Studio or `http://localhost:8080/v1` for llama.cpp
373
+ - `--openai-compatible-api-key-env`, an environment variable name such as `LOCAL_LLM_API_KEY`
374
+
375
+ ### Template Library
376
+
377
+ The current library covers five categories:
378
+
379
+ - **Maintenance**: CI failure repair, test repair, dependency upgrade, PR comment handling.
380
+ - **Delivery**: release preparation, changelog generation, rollback checks, version upgrade checks.
381
+ - **Quality**: type error reduction, lint cleanup, coverage gap fill, dead code cleanup.
382
+ - **Knowledge**: README refresh, architecture notes, onboarding guides, decision records.
383
+ - **Cross-functional**: requirements clarification, QA acceptance checklists, data processing checks, customer issue retros.
384
+
385
+ ### Generated Files
386
+
387
+ `loopgen` writes a small, inspectable set of files:
388
+
389
+ - `.loopgen/loopgen.loop.yaml`: intermediate loop representation.
390
+ - `.loopgen/playbooks/*.md`: tool-agnostic loop playbooks.
391
+ - `.loopgen/state/*.md`: attempts, outcomes and blockers.
392
+ - `AGENTS.md`: a universal agent instruction file read by most AI coding tools.
393
+ - `.codex/skills/*`, `.codex/automations/*`, `.codex/agents/*`: Codex-oriented outputs.
394
+ - `.claude/skills/*`, `.claude/loops/*`, `.claude/agents/*`: Claude-oriented outputs.
395
+ - `.cursor/rules/*.mdc` and `.windsurfrules`: Cursor and Windsurf rules.
396
+ - `.loopgen/adapters/ollama/config.json` and `.loopgen/adapters/ollama/*.md`: Ollama runtime config and runbooks.
397
+ - `.loopgen/adapters/openai-compatible/config.json` and `.loopgen/adapters/openai-compatible/*.md`: OpenAI-compatible runtime config and runbooks.
398
+
399
+ Generated loops include safety defaults: bounded iterations, maker/checker separation, required verification, forbidden secret paths and state-file logging.
400
+
401
+ Local model runbooks include the loop goal, context sources, verification commands, stop criteria, state-file path, a model prompt template and a runtime-specific `curl` example.
402
+
403
+ ### Troubleshooting
404
+
405
+ - If no verification command is inferred, generated loops stay in draft mode with a TODO verification command.
406
+ - If you select Ollama or OpenAI-compatible adapters without a model name, `loopgen` still generates files and adds warnings/TODOs to the config and runbook.
407
+ - If the Web wizard says assets are missing, run `npm run build`.
408
+ - Demo mode is preview-only. Switch to **Use my project** before applying files.
409
+ - If a loop tries to read `.env`, production secrets or credential files, stop and treat it as a safety violation.
410
+ - If the same failure repeats after the maximum iteration count, stop and ask for human input.
411
+
412
+ ### Contributing Templates
413
+
414
+ Add template definitions in `src/core/templates.ts`, including the goal, context sources, steps, verification commands, stop conditions and template metadata. Add tests for generated outputs. Keep templates explicit, bounded and easy to inspect.
@@ -0,0 +1,77 @@
1
+ export function generateAgentsFiles(scan, loops) {
2
+ return [
3
+ {
4
+ path: "AGENTS.md",
5
+ content: renderAgents(scan, loops)
6
+ }
7
+ ];
8
+ }
9
+ function renderAgents(scan, loops) {
10
+ const commands = [
11
+ scan.commands.install ? `- Install: \`${scan.commands.install}\`` : undefined,
12
+ scan.commands.test ? `- Test: \`${scan.commands.test}\`` : undefined,
13
+ scan.commands.lint ? `- Lint: \`${scan.commands.lint}\`` : undefined,
14
+ scan.commands.build ? `- Build: \`${scan.commands.build}\`` : undefined,
15
+ scan.commands.format ? `- Format: \`${scan.commands.format}\`` : undefined
16
+ ]
17
+ .filter(Boolean)
18
+ .join("\n") || "- No verification commands were inferred. Add them before running a loop.";
19
+ const loopSections = loops.map((loop) => renderLoopSection(loop)).join("\n\n");
20
+ return `# AGENTS.md
21
+
22
+ Generated by [loopgen](https://www.npmjs.com/package/loopgen) for ${scan.projectName}. This file is read by
23
+ many AI coding agents (Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Aider, and others). It
24
+ describes bounded, verifiable loops with safety rails: keep changes small, run verification, and stop at
25
+ the iteration limit.
26
+
27
+ ## Project
28
+
29
+ - Primary language: ${scan.primaryLanguage}
30
+ - Package managers: ${scan.packageManagers.join(", ") || "none detected"}
31
+
32
+ ### Verification commands
33
+
34
+ ${commands}
35
+
36
+ ## Safety rules for every loop
37
+
38
+ - Make the smallest change that can satisfy the goal.
39
+ - Run the verification commands before declaring success; never declare success without output.
40
+ - Keep maker and checker work separate: propose, verify, then review the diff and command output.
41
+ - Do not read or modify secret or credential files (see each loop's forbidden paths).
42
+ - Append an attempt log to the loop's state file after every iteration.
43
+ - Stop and ask a human when a stop condition is met instead of guessing.
44
+
45
+ ## Loops
46
+
47
+ ${loopSections}
48
+ `;
49
+ }
50
+ function renderLoopSection(loop) {
51
+ return `### ${loop.title} (\`${loop.id}\`)
52
+
53
+ ${loop.goal}
54
+
55
+ - Category: ${loop.category}
56
+ - Trigger: ${loop.trigger.type} (${loop.trigger.cadence})
57
+ - Max iterations: ${loop.stopCriteria.maxIterations}
58
+ - State file: \`${loop.stateFile}\`
59
+
60
+ Context to gather:
61
+ ${loop.contextSources.map((source) => `- ${source}`).join("\n")}
62
+
63
+ Steps:
64
+ ${loop.actions.map((action, index) => `${index + 1}. ${action}`).join("\n")}
65
+
66
+ Verify:
67
+ ${loop.verification.commands.map((command) => `- \`${command}\``).join("\n")}
68
+
69
+ Acceptance criteria: ${loop.verification.acceptanceCriteria}
70
+
71
+ Do not read or modify: ${loop.permissions.forbiddenPaths.map((item) => `\`${item}\``).join(", ")}
72
+
73
+ Stop and ask for human input when:
74
+ ${loop.stopCriteria.requireHumanInputOn.map((condition) => `- ${condition}`).join("\n")}${loop.verification.requiresHumanCommandDefinition
75
+ ? "\n\n> This loop is a draft until the TODO verification command is replaced."
76
+ : ""}`;
77
+ }
@@ -0,0 +1,88 @@
1
+ export function generateClaudeFiles(scan, loops) {
2
+ return loops.flatMap((loop) => [
3
+ {
4
+ path: `.claude/skills/loopgen-${loop.id}/SKILL.md`,
5
+ content: claudeSkill(scan, loop)
6
+ },
7
+ {
8
+ path: `.claude/loops/${loop.id}.md`,
9
+ content: claudeLoopGuide(scan, loop)
10
+ },
11
+ {
12
+ path: `.claude/agents/loopgen-${loop.id}-checker.md`,
13
+ content: claudeChecker(loop)
14
+ }
15
+ ]);
16
+ }
17
+ function claudeSkill(scan, loop) {
18
+ return `---
19
+ name: loopgen-${loop.id}
20
+ description: ${loop.goal}
21
+ ---
22
+
23
+ # ${loop.title}
24
+
25
+ This skill runs a bounded loop-engineering workflow for ${scan.projectName}.
26
+
27
+ ## Goal
28
+
29
+ ${loop.goal}
30
+
31
+ ## Context
32
+
33
+ ${loop.contextSources.map((source) => `- ${source}`).join("\n")}
34
+
35
+ ## Steps
36
+
37
+ ${loop.actions.map((action, index) => `${index + 1}. ${action}`).join("\n")}
38
+
39
+ ## Verify
40
+
41
+ ${loop.verification.commands.map((command) => `- \`${command}\``).join("\n")}
42
+
43
+ Acceptance criteria: ${loop.verification.acceptanceCriteria}
44
+
45
+ ## Stop conditions
46
+
47
+ ${loop.stopCriteria.requireHumanInputOn.map((condition) => `- ${condition}`).join("\n")}
48
+
49
+ State file: \`${loop.stateFile}\`
50
+ Maximum iterations: ${loop.stopCriteria.maxIterations}
51
+ ${loop.verification.requiresHumanCommandDefinition ? "\nThis loop is a draft until the TODO verification command is replaced.\n" : ""}
52
+ `;
53
+ }
54
+ function claudeLoopGuide(scan, loop) {
55
+ return `# Claude Code loop guide: ${loop.title}
56
+
57
+ Project: ${scan.projectName}
58
+ Loop id: ${loop.id}
59
+
60
+ Use the \`loopgen-${loop.id}\` skill. Keep maker and checker work separate:
61
+
62
+ 1. Maker reads context, edits, and runs verification.
63
+ 2. Checker reviews the diff, command output, and state entry.
64
+ 3. Maker only continues when checker feedback is actionable and within the iteration limit.
65
+
66
+ Allowed commands:
67
+ ${loop.permissions.allowedCommands.map((command) => `- ${command}`).join("\n") || "- No commands inferred. Configure commands before running."}
68
+
69
+ Forbidden paths:
70
+ ${loop.permissions.forbiddenPaths.map((item) => `- ${item}`).join("\n")}
71
+
72
+ PR creation: ${loop.permissions.allowPrCreation ? "allowed after verification" : "not allowed by this loop"}
73
+ `;
74
+ }
75
+ function claudeChecker(loop) {
76
+ return `# Checker instructions for ${loop.title}
77
+
78
+ Approve only when:
79
+
80
+ - The change directly supports \`${loop.id}\`.
81
+ - Verification commands were run or a blocker is documented.
82
+ - The state file \`${loop.stateFile}\` includes the attempt, result, and next step.
83
+ - No forbidden path was read or modified.
84
+ - The loop stayed within ${loop.stopCriteria.maxIterations} iterations.
85
+
86
+ Reject when tests are weakened, generated files are committed without need, or the implementation expands beyond the loop goal.
87
+ `;
88
+ }
@@ -0,0 +1,97 @@
1
+ export function generateCodexFiles(scan, loops) {
2
+ return loops.flatMap((loop) => [
3
+ {
4
+ path: `.codex/skills/loopgen-${loop.id}/SKILL.md`,
5
+ content: codexSkill(scan, loop)
6
+ },
7
+ {
8
+ path: `.codex/automations/${loop.id}.md`,
9
+ content: codexAutomationPrompt(scan, loop)
10
+ },
11
+ {
12
+ path: `.codex/agents/loopgen-${loop.id}-checker.toml`,
13
+ content: checkerAgent(loop)
14
+ }
15
+ ]);
16
+ }
17
+ function codexSkill(scan, loop) {
18
+ return `---
19
+ name: loopgen-${loop.id}
20
+ description: ${loop.goal}
21
+ ---
22
+
23
+ # ${loop.title}
24
+
25
+ Use this skill when working on ${scan.projectName} and the goal is:
26
+
27
+ ${loop.goal}
28
+
29
+ ## Required context
30
+
31
+ Read these sources before editing:
32
+
33
+ ${loop.contextSources.map((source) => `- ${source}`).join("\n")}
34
+
35
+ ## Loop
36
+
37
+ ${loop.actions.map((action, index) => `${index + 1}. ${action}`).join("\n")}
38
+
39
+ ## Verification
40
+
41
+ Run these commands before success:
42
+
43
+ ${loop.verification.commands.map((command) => `- \`${command}\``).join("\n")}
44
+
45
+ Acceptance criteria: ${loop.verification.acceptanceCriteria}
46
+
47
+ ## Safety
48
+
49
+ - Maximum iterations: ${loop.stopCriteria.maxIterations}
50
+ - Timeout minutes: ${loop.stopCriteria.timeoutMinutes}
51
+ - State file: \`${loop.stateFile}\`
52
+ - Do not read or modify: ${loop.permissions.forbiddenPaths.map((item) => `\`${item}\``).join(", ")}
53
+ - PR creation allowed: ${loop.permissions.allowPrCreation ? "yes" : "no"}
54
+ ${loop.verification.requiresHumanCommandDefinition ? "- This loop is in draft mode until the TODO verification command is replaced.\n" : ""}
55
+ `;
56
+ }
57
+ function codexAutomationPrompt(scan, loop) {
58
+ return `# Codex automation prompt: ${loop.title}
59
+
60
+ Project: ${scan.projectName}
61
+ Loop id: ${loop.id}
62
+ Skill: loopgen-${loop.id}
63
+ State file: ${loop.stateFile}
64
+
65
+ Goal:
66
+ ${loop.goal}
67
+
68
+ Trigger:
69
+ - Type: ${loop.trigger.type}
70
+ - Cadence: ${loop.trigger.cadence}
71
+ - Sources: ${loop.trigger.sources.join(", ")}
72
+
73
+ Instructions:
74
+ 1. Start from a clean branch or isolated worktree.
75
+ 2. Read the state file and required context.
76
+ 3. Perform one small maker iteration.
77
+ 4. Run verification commands.
78
+ 5. Use the checker agent instructions in \`.codex/agents/loopgen-${loop.id}-checker.toml\` before declaring success.
79
+ 6. Append the result, commands run, and remaining risks to the state file.
80
+
81
+ Allowed commands:
82
+ ${loop.permissions.allowedCommands.map((command) => `- ${command}`).join("\n") || "- No commands inferred. Configure commands before running."}
83
+
84
+ Stop and ask for human input when:
85
+ ${loop.stopCriteria.requireHumanInputOn.map((condition) => `- ${condition}`).join("\n")}
86
+ `;
87
+ }
88
+ function checkerAgent(loop) {
89
+ return `name = "loopgen-${loop.id}-checker"
90
+ description = "Checks whether a loopgen maker iteration satisfied the goal without broad or unsafe changes."
91
+ instructions = """
92
+ Review the maker changes for loop ${loop.id}.
93
+ Confirm the diff is small, the verification commands were run, and the state file was updated.
94
+ Reject the iteration if it touches forbidden paths, weakens tests without justification, omits verification, or exceeds the stop criteria.
95
+ """
96
+ `;
97
+ }