cadre run should autoscaffold missing agent files instead of failing validation (#113)#116
cadre run should autoscaffold missing agent files instead of failing validation (#113)#116
cadre run should autoscaffold missing agent files instead of failing validation (#113)#116Conversation
jafreck
left a comment
There was a problem hiding this comment.
Overall the approach is solid — scaffoldMissingAgents is a clean extraction, the --no-autoscaffold opt-out works correctly with Commander's flag pattern, and the re-validation after scaffolding is right. Three issues need fixing before merge: the backend not being passed in init.ts, the logging style inconsistency between init.ts and index.ts, and the duplicate describe block in the test file. Also note the branch is currently behind main and will need a rebase.
| // 8. Create .github/agents/ directory and scaffold missing agent files | ||
| const agentDir = join(repoPath, '.github', 'agents'); | ||
| await ensureDir(agentDir); | ||
| const scaffolded = await scaffoldMissingAgents(agentDir); |
There was a problem hiding this comment.
scaffoldMissingAgents is called without a backend argument, so it always defaults to 'copilot' and will produce .agent.md filenames regardless of what config.agent?.backend is set to. If a user configures claude, cadre init will scaffold files with the wrong naming convention (.agent.md instead of <name>/CLAUDE.md).
The config isn't available here yet since runInit writes it at earlier steps, but the collectAnswers result (the backend field, if present) could be threaded through, or scaffoldMissingAgents could be deferred to after config is written and re-read. Alternatively, accept a backend param in runInit itself.
| // 9. Print success summary | ||
| console.log(''); | ||
| if (scaffolded > 0) { | ||
| console.log(chalk.blue(`ℹ️ Auto-scaffolded ${scaffolded} missing agent file(s)`)); |
There was a problem hiding this comment.
Logging style inconsistency: this uses chalk.blue(...) but the equivalent notice in src/index.ts uses a plain console.log string with no chalk styling. Pick one style and apply it consistently so the output looks uniform whether the scaffold is triggered by cadre init or cadre run.
|
|
||
| expect(count).toBe(0); | ||
| expect(writeFile).not.toHaveBeenCalled(); | ||
| }); |
There was a problem hiding this comment.
There are two separate describe('scaffoldMissingAgents helper', ...) blocks in this file — this one and the one that starts at line ~215. They cover overlapping scenarios (both test skipping existing files, writing missing files, copilot filename format, etc.), which means some assertions are duplicated and the suite is harder to read. Merge the two blocks into one and keep the superset of unique test cases.
…/agents.ts` (attempt 1)
…c/cli/agents.ts`
…ctory creation (attempt 1)
…to `cadre run` (attempt 2)
…to `cadre run` (attempt 1)
…ogic to `cadre run`
…'copilot' explicitly
19ef233 to
ea321c0
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #116 +/- ##
==========================================
+ Coverage 77.79% 78.24% +0.44%
==========================================
Files 72 72
Lines 7683 7726 +43
Branches 1040 1064 +24
==========================================
+ Hits 5977 6045 +68
+ Misses 1686 1659 -27
- Partials 20 22 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
{ "title": "Auto-scaffold missing agent files on run", "body": "## Summary\n\nWhen `cadre run` or `cadre init` encounters missing built-in agent files, it now automatically scaffolds them instead of failing with a validation error. Closes #113.\n\n## Changes\n\n### `src/cli/agents.ts`\n- Extracted a new exported `scaffoldMissingAgents(agentDir, backend?, templateDir?)` helper that only creates files currently missing (skips existing), returns the count of files written, and uses the correct backend-aware filename format\n\n### `src/index.ts`\n- Added `--no-autoscaffold` flag to the `cadre run` command\n- After validation failures, scaffoldable missing files (matching entries in `AGENT_DEFINITIONS`) are auto-scaffolded before the run proceeds\n- Logs `ℹ️ Auto-scaffolded N missing agent file(s) — continuing.` when files are created\n- Non-scaffoldable (custom) missing files still cause a validation failure scoped to only those files\n- `--no-autoscaffold` reverts to the original strict fail-on-missing behavior\n\n### `src/cli/init.ts`\n- `runInit` now calls `scaffoldMissingAgents` after creating the agent directory, so a freshly initialized repo has all built-in agent files ready without a separate command\n- Prints the same notice if any files are created\n\n### Tests\n- `tests/agents-cli.test.ts`: new unit tests for `scaffoldMissingAgents` (skips existing files, returns correct count)\n- `tests/cli-index.test.ts`: new tests covering the autoscaffold happy path, `--no-autoscaffold` suppression, and non-scaffoldable failure\n- `tests/init.test.ts`: new test verifying `scaffoldMissingAgents` is called with the resolved agent directory during `cadre init`\n\n## Testing\n\nAll existing tests continue to pass, and new unit tests cover every acceptance criterion: the autoscaffold-on-missing happy path, opt-out via `--no-autoscaffold`, non-template file failures, and `cadre init` integration. Build and full test suite (`npx vitest run`) exit 0 with no regressions.", "labels": ["enhancement"] }Closes #113