Skip to content

Commit 5042c76

Browse files
committed
Template cleanup and reorganization
1 parent 23e0c5c commit 5042c76

7 files changed

Lines changed: 257 additions & 376 deletions

File tree

.github/workflows/scripts/create-release-packages.sh

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ generate_commands() {
4242
mkdir -p "$output_dir"
4343
for template in templates/commands/*.md; do
4444
[[ -f "$template" ]] || continue
45-
local name description script_command body
45+
local name description script_command agent_script_command body
4646
name=$(basename "$template" .md)
4747

4848
# Normalize line endings
@@ -57,13 +57,29 @@ generate_commands() {
5757
script_command="(Missing script command for $script_variant)"
5858
fi
5959

60+
# Extract agent_script command from YAML frontmatter if present
61+
agent_script_command=$(printf '%s\n' "$file_content" | awk '
62+
/^agent_scripts:$/ { in_agent_scripts=1; next }
63+
in_agent_scripts && /^[[:space:]]*'"$script_variant"':[[:space:]]*/ {
64+
sub(/^[[:space:]]*'"$script_variant"':[[:space:]]*/, "")
65+
print
66+
exit
67+
}
68+
in_agent_scripts && /^[a-zA-Z]/ { in_agent_scripts=0 }
69+
')
70+
6071
# Replace {SCRIPT} placeholder with the script command
6172
body=$(printf '%s\n' "$file_content" | sed "s|{SCRIPT}|${script_command}|g")
6273

63-
# Remove the scripts: section from frontmatter while preserving YAML structure
74+
# Replace {AGENT_SCRIPT} placeholder with the agent script command if found
75+
if [[ -n $agent_script_command ]]; then
76+
body=$(printf '%s\n' "$body" | sed "s|{AGENT_SCRIPT}|${agent_script_command}|g")
77+
fi
78+
79+
# Remove the scripts: and agent_scripts: sections from frontmatter while preserving YAML structure
6480
body=$(printf '%s\n' "$body" | awk '
6581
/^---$/ { print; if (++dash_count == 1) in_frontmatter=1; else in_frontmatter=0; next }
66-
in_frontmatter && /^scripts:$/ { skip_scripts=1; next }
82+
in_frontmatter && /^(scripts|agent_scripts):$/ { skip_scripts=1; next }
6783
in_frontmatter && /^[a-zA-Z].*:/ && skip_scripts { skip_scripts=0 }
6884
in_frontmatter && skip_scripts && /^[[:space:]]/ { next }
6985
{ print }
@@ -113,24 +129,7 @@ build_variant() {
113129
fi
114130

115131
[[ -d templates ]] && { mkdir -p "$SPEC_DIR/templates"; find templates -type f -not -path "templates/commands/*" -exec cp --parents {} "$SPEC_DIR"/ \; ; echo "Copied templates -> .specify/templates"; }
116-
# Inject variant into plan-template.md within .specify/templates if present
117-
local plan_tpl="$base_dir/.specify/templates/plan-template.md"
118-
if [[ -f "$plan_tpl" ]]; then
119-
plan_norm=$(tr -d '\r' < "$plan_tpl")
120-
# Extract script command from YAML frontmatter
121-
script_command=$(printf '%s\n' "$plan_norm" | awk -v sv="$script" '/^[[:space:]]*'"$script"':[[:space:]]*/ {sub(/^[[:space:]]*'"$script"':[[:space:]]*/, ""); print; exit}')
122-
if [[ -n $script_command ]]; then
123-
# Always prefix with .specify/ for plan usage
124-
script_command=".specify/$script_command"
125-
# Replace {SCRIPT} placeholder with the script command and __AGENT__ with agent name
126-
substituted=$(sed "s|{SCRIPT}|${script_command}|g" "$plan_tpl" | tr -d '\r' | sed "s|__AGENT__|${agent}|g")
127-
# Strip YAML frontmatter from plan template output (keep body only)
128-
stripped=$(printf '%s\n' "$substituted" | awk 'BEGIN{fm=0;dash=0} /^---$/ {dash++; if(dash==1){fm=1; next} else if(dash==2){fm=0; next}} {if(!fm) print}')
129-
printf '%s\n' "$stripped" > "$plan_tpl"
130-
else
131-
echo "Warning: no plan-template script command found for $script in YAML frontmatter" >&2
132-
fi
133-
fi
132+
134133
# NOTE: We substitute {ARGS} internally. Outward tokens differ intentionally:
135134
# * Markdown/prompt (claude, copilot, cursor, opencode): $ARGUMENTS
136135
# * TOML (gemini, qwen): {{args}}

templates/commands/plan.md

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ description: Execute the implementation planning workflow using the plan templat
33
scripts:
44
sh: scripts/bash/setup-plan.sh --json
55
ps: scripts/powershell/setup-plan.ps1 -Json
6+
agent_scripts:
7+
sh: scripts/bash/update-agent-context.sh __AGENT__
8+
ps: scripts/powershell/update-agent-context.ps1 -AgentType __AGENT__
69
---
710

811
The user input to you can be provided directly by the agent or as a command argument - you **MUST** consider it before proceeding with the prompt (if not empty).
@@ -11,36 +14,72 @@ User input:
1114

1215
$ARGUMENTS
1316

14-
Given the implementation details provided as an argument, do this:
15-
16-
1. Run `{SCRIPT}` from the repo root and parse JSON for FEATURE_SPEC, IMPL_PLAN, SPECS_DIR, BRANCH. All future file paths must be absolute.
17-
- BEFORE proceeding, inspect FEATURE_SPEC for a `## Clarifications` section with at least one `Session` subheading. If missing or clearly ambiguous areas remain (vague adjectives, unresolved critical choices), PAUSE and instruct the user to run `/clarify` first to reduce rework. Only continue if: (a) Clarifications exist OR (b) an explicit user override is provided (e.g., "proceed without clarification"). Do not attempt to fabricate clarifications yourself.
18-
2. Read and analyze the feature specification to understand:
19-
- The feature requirements and user stories
20-
- Functional and non-functional requirements
21-
- Success criteria and acceptance criteria
22-
- Any technical constraints or dependencies mentioned
23-
24-
3. Read the constitution at `/memory/constitution.md` to understand constitutional requirements.
25-
26-
4. Execute the implementation plan template:
27-
- Load `/templates/plan-template.md` (already copied to IMPL_PLAN path)
28-
- Set Input path to FEATURE_SPEC
29-
- Run the Execution Flow (main) function steps 1-9
30-
- The template is self-contained and executable
31-
- Follow error handling and gate checks as specified
32-
- Let the template guide artifact generation in $SPECS_DIR:
33-
* Phase 0 generates research.md
34-
* Phase 1 generates data-model.md, contracts/, quickstart.md
35-
* Phase 2 generates tasks.md
36-
- Incorporate user-provided details from arguments into Technical Context: {ARGS}
37-
- Update Progress Tracking as you complete each phase
38-
39-
5. Verify execution completed:
40-
- Check Progress Tracking shows all phases complete
41-
- Ensure all required artifacts were generated
42-
- Confirm no ERROR states in execution
43-
44-
6. Report results with branch name, file paths, and generated artifacts.
45-
46-
Use absolute paths with the repository root for all file operations to avoid path issues.
17+
## Execution Steps
18+
19+
1. **Setup**: Run `{SCRIPT}` from repo root and parse JSON for FEATURE_SPEC, IMPL_PLAN, SPECS_DIR, BRANCH.
20+
- Before proceeding: Check FEATURE_SPEC has `## Clarifications` section. If missing or ambiguous, instruct user to run `/clarify` first.
21+
22+
2. **Load context**: Read FEATURE_SPEC and `.specify/memory/constitution.md`. Load IMPL_PLAN template (already copied).
23+
24+
3. **Execute plan workflow**: Follow the structure in IMPL_PLAN template to:
25+
- Fill Technical Context (mark unknowns as "NEEDS CLARIFICATION")
26+
- Fill Constitution Check section from constitution
27+
- Evaluate gates (ERROR if violations unjustified)
28+
- Phase 0: Generate research.md (resolve all NEEDS CLARIFICATION)
29+
- Phase 1: Generate data-model.md, contracts/, quickstart.md
30+
- Phase 1: Update agent context by running the agent script
31+
- Re-evaluate Constitution Check post-design
32+
33+
4. **Stop and report**: Command ends after Phase 2 planning. Report branch, IMPL_PLAN path, and generated artifacts.
34+
35+
## Phases
36+
37+
### Phase 0: Outline & Research
38+
39+
1. **Extract unknowns from Technical Context** above:
40+
- For each NEEDS CLARIFICATION → research task
41+
- For each dependency → best practices task
42+
- For each integration → patterns task
43+
44+
2. **Generate and dispatch research agents**:
45+
```
46+
For each unknown in Technical Context:
47+
Task: "Research {unknown} for {feature context}"
48+
For each technology choice:
49+
Task: "Find best practices for {tech} in {domain}"
50+
```
51+
52+
3. **Consolidate findings** in `research.md` using format:
53+
- Decision: [what was chosen]
54+
- Rationale: [why chosen]
55+
- Alternatives considered: [what else evaluated]
56+
57+
**Output**: research.md with all NEEDS CLARIFICATION resolved
58+
59+
### Phase 1: Design & Contracts
60+
61+
**Prerequisites:** `research.md` complete
62+
63+
1. **Extract entities from feature spec**`data-model.md`:
64+
- Entity name, fields, relationships
65+
- Validation rules from requirements
66+
- State transitions if applicable
67+
68+
2. **Generate API contracts** from functional requirements:
69+
- For each user action → endpoint
70+
- Use standard REST/GraphQL patterns
71+
- Output OpenAPI/GraphQL schema to `/contracts/`
72+
73+
3. **Agent context update**:
74+
- Run `{AGENT_SCRIPT}`
75+
- These scripts detect which AI agent is in use
76+
- Update the appropriate agent-specific context file
77+
- Add only new technology from current plan
78+
- Preserve manual additions between markers
79+
80+
**Output**: data-model.md, /contracts/*, quickstart.md, agent-specific file
81+
82+
## Key rules
83+
84+
- Use absolute paths
85+
- ERROR on gate failures or unresolved clarifications

templates/commands/specify.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,56 @@ Given that feature description, do this:
1818
1. Run the script `{SCRIPT}` from repo root and parse its JSON output for BRANCH_NAME and SPEC_FILE. All file paths must be absolute.
1919
**IMPORTANT** You must only ever run this script once. The JSON is provided in the terminal as output - always refer to it to get the actual content you're looking for.
2020
2. Load `templates/spec-template.md` to understand required sections.
21-
3. Write the specification to SPEC_FILE using the template structure, replacing placeholders with concrete details derived from the feature description (arguments) while preserving section order and headings.
22-
4. Report completion with branch name, spec file path, and readiness for the next phase.
2321

24-
Note: The script creates and checks out the new branch and initializes the spec file before writing.
22+
3. Follow this execution flow:
23+
24+
1. Parse user description from Input
25+
If empty: ERROR "No feature description provided"
26+
2. Extract key concepts from description
27+
Identify: actors, actions, data, constraints
28+
3. For each unclear aspect:
29+
Mark with [NEEDS CLARIFICATION: specific question]
30+
4. Fill User Scenarios & Testing section
31+
If no clear user flow: ERROR "Cannot determine user scenarios"
32+
5. Generate Functional Requirements
33+
Each requirement must be testable
34+
Mark ambiguous requirements
35+
6. Identify Key Entities (if data involved)
36+
7. Run Review Checklist
37+
If any [NEEDS CLARIFICATION]: WARN "Spec has uncertainties"
38+
If implementation details found: ERROR "Remove tech details"
39+
8. Return: SUCCESS (spec ready for planning)
40+
41+
4. Write the specification to SPEC_FILE using the template structure, replacing placeholders with concrete details derived from the feature description (arguments) while preserving section order and headings.
42+
5. Report completion with branch name, spec file path, and readiness for the next phase.
43+
44+
**NOTE:** The script creates and checks out the new branch and initializes the spec file before writing.
45+
46+
## General Guidelines
47+
48+
## Quick Guidelines
49+
50+
- Focus on WHAT users need and WHY
51+
- Avoid HOW to implement (no tech stack, APIs, code structure)
52+
- Written for business stakeholders, not developers
53+
54+
### Section Requirements
55+
56+
- **Mandatory sections**: Must be completed for every feature
57+
- **Optional sections**: Include only when relevant to the feature
58+
- When a section doesn't apply, remove it entirely (don't leave as "N/A")
59+
60+
### For AI Generation
61+
62+
When creating this spec from a user prompt:
63+
64+
1. **Mark all ambiguities**: Use [NEEDS CLARIFICATION: specific question] for any assumption you'd need to make
65+
2. **Don't guess**: If the prompt doesn't specify something (e.g., "login system" without auth method), mark it
66+
3. **Think like a tester**: Every vague requirement should fail the "testable and unambiguous" checklist item
67+
4. **Common underspecified areas**:
68+
- User types and permissions
69+
- Data retention/deletion policies
70+
- Performance targets and scale
71+
- Error handling behaviors
72+
- Integration requirements
73+
- Security/compliance needs

templates/commands/tasks.md

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,65 @@ User input:
1111

1212
$ARGUMENTS
1313

14-
1. Run `{SCRIPT}` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute.
15-
2. Load and analyze available design documents:
16-
- Always read plan.md for tech stack and libraries
17-
- IF EXISTS: Read data-model.md for entities
18-
- IF EXISTS: Read contracts/ for API endpoints
19-
- IF EXISTS: Read research.md for technical decisions
20-
- IF EXISTS: Read quickstart.md for test scenarios
14+
## Execution Steps
2115

22-
Note: Not all projects have all documents. For example:
23-
- CLI tools might not have contracts/
24-
- Simple libraries might not need data-model.md
25-
- Generate tasks based on what's available
16+
1. **Setup**: Run `{SCRIPT}` from repo root and parse FEATURE_DIR and AVAILABLE_DOCS list. All paths must be absolute.
2617

27-
3. Generate tasks following the template:
28-
- Use `/templates/tasks-template.md` as the base
29-
- Replace example tasks with actual tasks based on:
30-
* **Setup tasks**: Project init, dependencies, linting
31-
* **Test tasks [P]**: One per contract, one per integration scenario
32-
* **Core tasks**: One per entity, service, CLI command, endpoint
33-
* **Integration tasks**: DB connections, middleware, logging
34-
* **Polish tasks [P]**: Unit tests, performance, docs
18+
2. **Load design documents**: Read from FEATURE_DIR:
19+
- **Required**: plan.md (tech stack, libraries, structure)
20+
- **Optional**: data-model.md (entities), contracts/ (API endpoints), research.md (decisions), quickstart.md (test scenarios)
21+
- Note: Not all projects have all documents. Generate tasks based on what's available.
3522

36-
4. Task generation rules:
37-
- Each contract file → contract test task marked [P]
38-
- Each entity in data-model → model creation task marked [P]
39-
- Each endpoint → implementation task (not parallel if shared files)
40-
- Each user story → integration test marked [P]
41-
- Different files = can be parallel [P]
42-
- Same file = sequential (no [P])
23+
3. **Execute task generation workflow** (follow the template structure):
24+
- Load plan.md and extract tech stack, libraries, project structure
25+
- If data-model.md exists: Extract entities → generate model tasks
26+
- If contracts/ exists: Each file → generate endpoint/API tasks
27+
- If research.md exists: Extract decisions → generate setup tasks
28+
- Generate tasks by category: Setup, Core Implementation, Integration, Polish
29+
- **Tests are OPTIONAL**: Only generate test tasks if explicitly requested in the feature spec or user asks for TDD approach
30+
- Apply task rules:
31+
* Different files = mark [P] for parallel
32+
* Same file = sequential (no [P])
33+
* If tests requested: Tests before implementation (TDD order)
34+
- Number tasks sequentially (T001, T002...)
35+
- Generate dependency graph
36+
- Create parallel execution examples
37+
- Validate task completeness (all entities have implementations, all endpoints covered)
4338

44-
5. Order tasks by dependencies:
45-
- Setup before everything
46-
- Tests before implementation (TDD)
47-
- Models before services
48-
- Services before endpoints
49-
- Core before integration
50-
- Everything before polish
51-
52-
6. Include parallel execution examples:
53-
- Group [P] tasks that can run together
54-
- Show actual Task agent commands
55-
56-
7. Create FEATURE_DIR/tasks.md with:
57-
- Correct feature name from implementation plan
58-
- Numbered tasks (T001, T002, etc.)
39+
4. **Generate tasks.md**: Use `.specify/templates/tasks-template.md` as structure, fill with:
40+
- Correct feature name from plan.md
41+
- Numbered tasks (T001, T002...) in dependency order
5942
- Clear file paths for each task
43+
- [P] markers for parallelizable tasks
44+
- Phase groupings based on what's needed (Setup, Core Implementation, Integration, Polish)
45+
- If tests requested: Include separate "Tests First (TDD)" phase before Core Implementation
6046
- Dependency notes
47+
48+
5. **Report**: Output path to generated tasks.md and summary of task counts by phase.
6149
- Parallel execution guidance
6250

6351
Context for task generation: {ARGS}
6452

6553
The tasks.md should be immediately executable - each task must be specific enough that an LLM can complete it without additional context.
54+
55+
## Task Generation Rules
56+
57+
**IMPORTANT**: Tests are optional. Only generate test tasks if the user explicitly requested testing or TDD approach in the feature specification.
58+
59+
1. **From Contracts**:
60+
- Each contract/endpoint → implementation task
61+
- If tests requested: Each contract → contract test task [P] before implementation
62+
63+
2. **From Data Model**:
64+
- Each entity → model creation task [P]
65+
- Relationships → service layer tasks
66+
67+
3. **From User Stories**:
68+
- Each story → implementation tasks
69+
- If tests requested: Each story → integration test [P]
70+
- If quickstart.md exists: Validation tasks
71+
72+
4. **Ordering**:
73+
- Without tests: Setup → Models → Services → Endpoints → Integration → Polish
74+
- With tests (TDD): Setup → Tests → Models → Services → Endpoints → Integration → Polish
75+
- Dependencies block parallel execution

0 commit comments

Comments
 (0)