11# Story 11.2: Implement ` devrail init ` Core Script
22
3- Status: backlog
3+ Status: review
44
55## Story
66
@@ -20,51 +20,94 @@ so that my project is DevRail-compliant with a single command.
2020
2121## Tasks / Subtasks
2222
23- - [ ] Task 1: Implement core script (AC: 1, 2, 6)
24- - [ ] 1.1 Create script following design from Story 11.1
25- - [ ] 1.2 Implement ` .devrail.yml ` parsing
26- - [ ] 1.3 Implement file generation for core files (Makefile, DEVELOPMENT.md, .editorconfig, .gitignore)
27- - [ ] 1.4 Implement file generation for agent files (CLAUDE.md, AGENTS.md, .cursorrules)
28- - [ ] 1.5 Implement file generation for pre-commit config (.pre-commit-config.yaml)
29- - [ ] 1.6 Implement CI platform detection and generation (.github/workflows or .gitlab-ci.yml)
30-
31- - [ ] Task 2: Implement interactive mode (AC: 3)
32- - [ ] 2.1 Add interactive prompts for language selection
33- - [ ] 2.2 Add interactive prompts for CI platform selection
34- - [ ] 2.3 Generate ` .devrail.yml ` from interactive responses
35-
36- - [ ] Task 3: Implement conflict resolution (AC: 4)
37- - [ ] 3.1 Detect existing files before generation
38- - [ ] 3.2 Implement prompt/skip/overwrite/merge strategies
39- - [ ] 3.3 Default to prompt when files exist
40-
41- - [ ] Task 4: Implement --dry-run (AC: 7)
42- - [ ] 4.1 Add --dry-run flag that shows planned file operations without writing
43-
44- - [ ] Task 5: Test and validate (AC: 5)
45- - [ ] 5.1 Test against empty directory (greenfield)
46- - [ ] 5.2 Test against existing project (retrofit)
47- - [ ] 5.3 Test idempotency (re-run produces no changes)
48- - [ ] 5.4 Verify generated files match template repos
23+ - [x] Task 1: Create script skeleton with option parsing (AC: 1, 7)
24+ - [x] 1.1 Create ` devrail-init.sh ` in dev-toolchain repo with POSIX-compatible shebang and usage/help
25+ - [x] 1.2 Parse CLI options: ` --languages ` , ` --ci ` , ` --all ` , ` --agents-only ` , ` --yes ` , ` --force ` , ` --dry-run ` , ` --version `
26+ - [x] 1.3 Implement dry-run mode (track operations, print summary, write nothing)
27+
28+ - [x] Task 2: Implement Layer 1 — Agent instruction files (AC: 1, 5)
29+ - [x] 2.1 Embed CLAUDE.md, AGENTS.md, .cursorrules, .opencode/agents.yaml content as heredocs
30+ - [x] 2.2 Write scaffold function that creates files with conflict detection
31+ - [x] 2.3 Implement ` --agents-only ` shortcut
32+
33+ - [x] Task 3: Implement Layer 2 — Pre-commit hooks (AC: 1, 2, 5)
34+ - [x] 3.1 Embed .pre-commit-config.yaml template with language-conditional hook blocks
35+ - [x] 3.2 Generate language-aware config based on ` .devrail.yml ` languages list
36+ - [x] 3.3 Check for ` pre-commit ` installation and print instructions if missing
37+
38+ - [x] Task 4: Implement Layer 3 — Makefile + container (AC: 1, 2, 4, 5)
39+ - [x] 4.1 Embed Makefile, DEVELOPMENT.md, .editorconfig, .gitignore, .gitleaksignore content
40+ - [x] 4.2 Implement ` .devrail.yml ` creation from ` --languages ` flag or interactive prompt
41+ - [x] 4.3 Implement Makefile merge strategy (detect markers, backup+include for non-DevRail Makefiles)
42+ - [x] 4.4 Implement .gitignore append-with-marker pattern
43+
44+ - [x] Task 5: Implement Layer 4 — CI pipelines (AC: 1, 2, 5)
45+ - [x] 5.1 Embed GitHub Actions ci.yml, PR template, CODEOWNERS
46+ - [x] 5.2 Embed GitLab CI .gitlab-ci.yml, MR template, CODEOWNERS
47+ - [x] 5.3 Select platform from ` --ci ` flag or interactive prompt
48+
49+ - [x] Task 6: Implement interactive mode (AC: 3)
50+ - [x] 6.1 Add interactive prompts for language selection (multi-select from 8 ecosystems)
51+ - [x] 6.2 Add interactive prompts for CI platform selection (github/gitlab/none)
52+ - [x] 6.3 Add 4-layer adoption prompts per design doc
53+ - [x] 6.4 Generate ` .devrail.yml ` from interactive responses
54+
55+ - [x] Task 7: Implement conflict resolution (AC: 4, 6)
56+ - [x] 7.1 Detect existing files before each write
57+ - [x] 7.2 Interactive mode: prompt with [ s] kip / [ o] verwrite / [ b] ackup+overwrite
58+ - [x] 7.3 ` --yes ` mode: skip existing files
59+ - [x] 7.4 ` --force ` mode: overwrite without prompting
60+
61+ - [x] Task 8: Test and validate (AC: 5, 6, 7)
62+ - [x] 8.1 Write bats tests for option parsing and scaffold functions
63+ - [x] 8.2 Test greenfield: empty directory, all layers
64+ - [x] 8.3 Test retrofit: existing project with Makefile, verify merge strategy
65+ - [x] 8.4 Test idempotency: re-run produces no changes
66+ - [x] 8.5 Test dry-run: verify no files written
67+ - [x] 8.6 Test --agents-only: verify only Layer 1 files created
68+ - [x] 8.7 Verify generated files match template repo content
4969
5070## Dev Notes
5171
52- - Blocked by Story 11.1 (design must be completed first)
53- - Implementation language TBD (bash script vs Go CLI vs Python CLI) — decided in 11.1
54- - Must follow DevRail critical rules (idempotent scripts, shared logging, etc.)
72+ - Design doc: ` _bmad-output/planning-artifacts/devrail-init-design.md ` (Story 11.1, done)
73+ - Implementation: single POSIX-compatible shell script with embedded heredocs
74+ - Lives in dev-toolchain repo at ` scripts/devrail-init.sh `
75+ - File contents sourced from github-repo-template and gitlab-repo-template
76+ - Makefile and DEVELOPMENT.md downloaded from GitHub raw URLs (too large for heredoc embedding)
77+ - ` make init ` (container-side) remains separate — generates per-language tool configs (ruff.toml, etc.)
78+ - ` devrail init ` (host-side) generates project structure files (Makefile, CI, agent files, etc.)
5579
5680### References
5781
58- - [ Source: Story 11.1 design document ] — CLI specification
82+ - [ Source: devrail-init- design.md ] — CLI specification and design decisions
5983- [ Source: github-repo-template/] — reference files for generation
6084- [ Source: gitlab-repo-template/] — reference files for generation
6185
6286## Dev Agent Record
6387
6488### Agent Model Used
6589
90+ Claude Opus 4.6
91+
6692### Debug Log References
6793
94+ - ` make check ` passed on dev-toolchain repo
95+ - 16/16 bats tests pass
96+ - Manual testing: greenfield (19 files), idempotency (all skipped), dry-run (no files), agents-only (4 files), GitLab CI, Makefile backup+merge
97+
6898### Completion Notes List
6999
100+ - Script is 1082 lines of bash (after shfmt formatting)
101+ - Small files (agent instructions, .editorconfig, .gitleaksignore, CI workflows) embedded as heredocs
102+ - Large files (Makefile, DEVELOPMENT.md) downloaded from ` raw.githubusercontent.com/devrail-dev/github-repo-template/main/ `
103+ - Pre-commit config generated dynamically based on language list — only active hooks for declared languages
104+ - GitHub CI generates 6 separate workflow files (lint, format, test, security, scan, docs) matching template structure
105+ - Makefile merge: detects DevRail markers for in-place update, backs up non-DevRail Makefiles with include guidance
106+ - .gitignore: appends below ` # --- DevRail --- ` marker, skips if marker already present
107+ - Container version tag (` $DEVRAIL_VERSION ` ) flows through to all generated files
108+ - PR: https://github.com/devrail-dev/dev-toolchain/pull/11
109+
70110### File List
111+
112+ - ` dev-toolchain/scripts/devrail-init.sh ` — new script (created)
113+ - ` dev-toolchain/tests/test-devrail-init.sh ` — new bats tests (created)
0 commit comments