| name | flow-init |
| description | Initialize project with AGENTS.md and rules, handling both Greenfield (new) and Brownfield (existing) projects. |
| disable-model-invocation | true |
Task: Initialize Project Agent Documentation
Overview
Analyze the project, conduct an interview (for Greenfield projects), and
generate 3 AGENTS.md files (root, documents/, scripts/), a CLAUDE.md symlink
(for Claude Code compatibility), rules, and scaffolding.
The agent uses template files from assets/ as reference and writes files directly.
Context
The user wants to bootstrap an AI agent's understanding of the project. The agent needs to autonomously explore the codebase, recognize the technology stack, understand the directory structure, and infer key architectural patterns.
- **Greenfield (New Projects)**: Requires interviewing the user, creating scaffolding (`documents/`, configs), and setting up rules.
- **Brownfield (Existing Projects)**: Requires discovery, reverse-engineering architecture, and **extracting existing instructions** from `./AGENTS.md` into the appropriate subdirectory files.
File Structure: flow-init produces 3 AGENTS.md files:
./AGENTS.md — core agent rules, project metadata, planning rules, TDD flow
./documents/AGENTS.md — documentation system rules (SRS/SDS/GODS formats, compressed style)
./scripts/AGENTS.md — development commands (standard interface, detected commands)
Rules & Constraints
1. **No Hallucinations**: Only document tooling and architecture that is explicitly found in the codebase or provided by the user.
2. **Standard Format**: Generated files must follow the provided templates in `assets/`.
3. **Idempotency (Brownfield)**: If components already exist, show diffs and ask for per-file confirmation before applying changes.
4. **Greenfield/Brownfield Detection**: The agent determines project type autonomously by analyzing output of the analysis script (file count, stack, file tree, presence of config files). Do NOT rely on an `is_new` flag from any script.
5. **Scripts are read-only**: Analysis scripts must NOT create, write, or modify any files. All file creation is the agent's responsibility.
6. **No rule copying**: Do NOT copy rules to IDE-specific rules directories. Rule management is outside flow-init scope.
7. **Mandatory**: The agent MUST use a task management tool (e.g., todo write) to track the execution steps.
8. **Per-File Diff Confirmation**: For existing files, always show the diff to the user and ask for confirmation before applying. Never silently overwrite.
9. **Preserve User Content**: In brownfield, extract and preserve user's existing instructions. Templates are fallbacks for greenfield only.
10. **Extract, Don't Duplicate**: In brownfield, if `./AGENTS.md` contains sections about documentation or development commands, these MUST be extracted into `./documents/AGENTS.md` and `./scripts/AGENTS.md` respectively, and REMOVED from `./AGENTS.md`.
Instructions
<step_by_step>
-
Initialize
- Use a task management tool (e.g., todo write) to create a plan based on these steps.
-
Analyze Project
-
Greenfield Workflow (Interview)
- Condition: Only if Greenfield.
- Action: Launch the
interviewer subagent (or conduct Q&A inline if subagent unavailable).
-
Prompt: "You are helping initialize a new (Greenfield) project.
Conduct a brief interview to gather:
- Project Name: Name?
- Vision Statement: What is the long-term goal and value?
- Target Audience: Who is this for?
- Problem Statement: What problem are we solving?
- Solution & Differentiators: How do we solve it and why is it better?
- Risks & Assumptions: What could go wrong?
- Tech Stack: Languages/Frameworks? (If not detected)
- Architecture: Patterns?
- Key Decisions: Tools/Methodologies?
- Deno Tooling: Do you want to build tooling around the project on Deno? (yes/no)
- Devcontainer: Would you like to set up a devcontainer for reproducible development environments? (yes/no)
Return a SINGLE JSON object: {
"project_name": "...",
"vision_statement": "...",
"target_audience": "...",
"problem_statement": "...",
"solution_differentiators": "...",
"risks_assumptions": "...",
"stack": ["..."],
"architecture": "...",
"key_decisions": "...",
"preferences": ["tdd", "strict-mode", ...],
"use_deno_tooling": boolean,
"use_devcontainer": boolean
}"
-
Brownfield Workflow (Discovery & Extraction)
- Condition: Only if Brownfield.
- Action: Analyze the project to infer architecture and key decisions.
- Read key config files (
package.json, deno.json, README.md, etc.).
- Infer:
- Architecture: (e.g., "React SPA", "Express API", "CLI Tool").
- Key Decisions: (e.g., "Tailwind for styling", "Jest for testing").
- Extract from existing
./AGENTS.md (if it exists):
- Read the entire file.
- Identify sections semantically:
- Sections about documentation rules, doc hierarchy, SRS/SDS formats, writing style, whiteboard -> these belong in
./documents/AGENTS.md.
- Sections about development commands, build scripts, test commands, detected commands -> these belong in
./scripts/AGENTS.md.
- Everything else (project identity, vision, architecture, planning rules, TDD, code docs, custom project rules) -> stays in
./AGENTS.md.
- Save extracted content for use in step 6.
- Important: The extracted content from the user's existing file takes priority over template content. Templates are fallbacks only.
-
Component Inventory
- Use the
inventory section from the analysis output (step 2) to check which components exist.
- Report findings to user as a checklist.
- For Brownfield: ask "Create missing components? Update existing via diff? [create missing / update all / select]"
-
Generate AGENTS.md Files
-
Claude Code Compatibility (CLAUDE.md Symlinks)
- Create relative symlinks
CLAUDE.md -> AGENTS.md in every directory that has an AGENTS.md:
./CLAUDE.md -> ./AGENTS.md
./documents/CLAUDE.md -> ./AGENTS.md
./scripts/CLAUDE.md -> ./AGENTS.md
- For each symlink:
- If
CLAUDE.md does not exist: create the symlink, report to user.
- If
CLAUDE.md exists and is already a correct symlink to AGENTS.md: skip silently.
- If
CLAUDE.md exists as a regular file or wrong symlink: warn the user, show the current content/target, and ask for confirmation before replacing with the symlink.
-
OpenCode Compatibility Check
- The
inventory section from the analysis output (step 2) includes opencode_json.exists and opencode_json.has_subdirectory_globs.
- If
opencode_json.exists is true and has_subdirectory_globs is false: warn user and propose adding documents/AGENTS.md and scripts/AGENTS.md to the instructions array in opencode.json.
-
Generate Documentation
- Generate core documentation files in
documents/:
documents/requirements.md (SRS): Fill based on interview data (Greenfield) or inferred context (Brownfield). Skip if file exists and has more than 50 lines.
documents/design.md (SDS): Create initial structure. Skip if file exists and has more than 50 lines.
documents/whiteboard.md:
- For Brownfield: Include "Discovered Context" (file tree) and README summary. Skip if file exists and has more than 10 lines.
- For Greenfield: Initialize with empty notes.
- Note: Use LLM capabilities to generate high-quality, context-aware content from actual project data -- not empty placeholders.
-
Configure Development Commands
- Read analysis output to get detected stack.
- Check Interview Data: If
use_deno_tooling: true, FORCE usage of flow-skill-configure-deno-commands.
- Skill Lookup: For each stack item, check if a specialized skill exists (e.g.,
Deno -> flow-skill-configure-deno-commands).
- If specialized skill exists: Read and follow its
SKILL.md.
- If NO specialized skill:
- Ask user for preferred scripting language (shell/python/stack-native).
- Analyze existing config files.
- Create standard command interface (
check, test, dev, prod) in scripts/.
- Update project config (e.g.,
package.json) to reference these scripts.
- Skip condition: If
scripts/ already exists with standard commands and user chose "create missing" -> skip.
- Verify: Run
check command to ensure it works.
- Devcontainer Setup (Optional)
- For Greenfield: Check
use_devcontainer from interview data.
- For Brownfield: Ask the user: "Would you like to set up a devcontainer for reproducible development environments?"
- If user declines: Skip this step entirely.
- If user agrees: Delegate to the
flow-skill-setup-ai-ide-devcontainer skill. Read and follow its SKILL.md.
- Cleanup & Verify
</step_by_step>
Verification
[ ] Analysis script run and output read.
[ ] Greenfield/Brownfield determined by agent judgment (not `is_new` flag).
[ ] Interview conducted (Greenfield) or discovery performed (Brownfield).
[ ] For Brownfield: documentation and script sections extracted from existing AGENTS.md.
[ ] For existing files: diffs shown and per-file confirmation requested.
[ ] Existing user content preserved (custom rules, extracted sections used as-is).
[ ] 3 AGENTS.md files generated: root, documents/, scripts/.
[ ] `CLAUDE.md` symlinks created in all directories with `AGENTS.md` (root, documents/, scripts/).
[ ] No duplication: sections moved to subdirectories are removed from root AGENTS.md.
[ ] `documents/` folder populated with generated content from actual project data.
[ ] Development commands configured (scripts created + config updated).
[ ] OpenCode compatibility checked (if applicable) via `inventory` output.
[ ] Analysis script re-run passes (exit code 0, `verification.passed: true`).
[ ] Check command runs successfully.
[ ] Devcontainer: user asked; if agreed, `.devcontainer/devcontainer.json` exists and is valid JSON.
[ ] Temporary files cleaned up.