Skip to content

cadre run should autoscaffold missing agent files instead of failing validation (#113)#116

Merged
jafreck merged 8 commits intomainfrom
cadre/issue-113
Feb 24, 2026
Merged

cadre run should autoscaffold missing agent files instead of failing validation (#113)#116
jafreck merged 8 commits intomainfrom
cadre/issue-113

Conversation

@jafreck
Copy link
Copy Markdown
Owner

@jafreck jafreck commented Feb 24, 2026

{
  "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

Copy link
Copy Markdown
Owner Author

@jafreck jafreck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/cli/init.ts Outdated
// 8. Create .github/agents/ directory and scaffold missing agent files
const agentDir = join(repoPath, '.github', 'agents');
await ensureDir(agentDir);
const scaffolded = await scaffoldMissingAgents(agentDir);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/cli/init.ts
// 9. Print success summary
console.log('');
if (scaffolded > 0) {
console.log(chalk.blue(`ℹ️ Auto-scaffolded ${scaffolded} missing agent file(s)`));
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/agents-cli.test.ts

expect(count).toBe(0);
expect(writeFile).not.toHaveBeenCalled();
});
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jafreck jafreck merged commit 783793a into main Feb 24, 2026
2 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 92.59259% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.24%. Comparing base (02a81f5) to head (ea321c0).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
src/cli/agents.ts 88.00% 3 Missing ⚠️
src/cli/init.ts 87.50% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jafreck jafreck added the cadre-generated Pull request automatically generated by cadre label Feb 24, 2026
@jafreck jafreck deleted the cadre/issue-113 branch February 25, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cadre-generated Pull request automatically generated by cadre

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cadre run should autoscaffold missing agent files instead of failing validation

1 participant