@rrgarciach/flow-spec 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/init.js +91 -0
- package/package.json +28 -0
- package/template/.cursor/rules/use-base-rules.mdc +37 -0
- package/template/ai-specs/agents/backend-developer.md +121 -0
- package/template/ai-specs/agents/frontend-developer.md +134 -0
- package/template/ai-specs/agents/product-strategy-analyst.md +53 -0
- package/template/ai-specs/flow-spec-instructions.md +389 -0
- package/template/ai-specs/scripts/code_review.sh +35 -0
- package/template/ai-specs/skills/code-auditing/SKILL.md +155 -0
- package/template/ai-specs/skills/code-auditing/references/audit-methodology.md +371 -0
- package/template/ai-specs/skills/code-auditing/references/dead-code-methodology.md +261 -0
- package/template/ai-specs/skills/commit/SKILL.md +101 -0
- package/template/ai-specs/skills/enrich-us/SKILL.md +42 -0
- package/template/ai-specs/skills/explain/SKILL.md +84 -0
- package/template/ai-specs/skills/meta-prompt/SKILL.md +19 -0
- package/template/ai-specs/skills/update-docs/SKILL.md +13 -0
- package/template/ai-specs/skills/using-git-worktrees/SKILL.md +375 -0
- package/template/ai-specs/skills/writing-skills/SKILL.md +655 -0
- package/template/ai-specs/skills/writing-skills/anthropic-best-practices.md +1150 -0
- package/template/ai-specs/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/template/ai-specs/skills/writing-skills/graphviz-conventions.dot +172 -0
- package/template/ai-specs/skills/writing-skills/persuasion-principles.md +187 -0
- package/template/ai-specs/skills/writing-skills/render-graphs.js +168 -0
- package/template/ai-specs/skills/writing-skills/testing-skills-with-subagents.md +384 -0
- package/template/docs/api-spec.yml +29 -0
- package/template/docs/backend-standards.md +53 -0
- package/template/docs/base-standards.md +114 -0
- package/template/docs/data-model.md +26 -0
- package/template/docs/development_guide.md +36 -0
- package/template/docs/documentation-standards.md +49 -0
- package/template/docs/frontend-standards.md +45 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: commit
|
|
3
|
+
description: Create focused commits and pull requests following repository standards.
|
|
4
|
+
author: Flow Spec
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
---
|
|
7
|
+
# commit Skill
|
|
8
|
+
|
|
9
|
+
Use it when this workflow is required in the project.
|
|
10
|
+
|
|
11
|
+
## Instructions
|
|
12
|
+
|
|
13
|
+
# Role
|
|
14
|
+
|
|
15
|
+
You are an expert in version control and release workflows. You create clear, comprehensive commits and Pull Requests that align with project standards and make review and traceability straightforward.
|
|
16
|
+
|
|
17
|
+
# Arguments
|
|
18
|
+
|
|
19
|
+
**Optional.** `$ARGUMENTS` may contain:
|
|
20
|
+
|
|
21
|
+
- **Nothing (empty)**: Stage and commit all relevant changes in the working tree, then open a single PR.
|
|
22
|
+
- **Feature/ticket identifiers**: e.g. ticket IDs (e.g. `SCRUM-123`), branch names, or short feature labels. When provided, stage and PR **only** the changes that belong to those features; leave all other changes unstaged and uncommitted.
|
|
23
|
+
- **Description-only / no-git mode**: If the user **explicitly** says something like "no PR", "only commit" (meaning only produce the commit text), "only description", "don't touch git", "just the message", or "dry run", then do **not** run any git commands or create a PR. Only determine scope, list what would be staged, and output the proposed commit message (subject + body). The user can copy and run git commands themselves.
|
|
24
|
+
|
|
25
|
+
# Goal
|
|
26
|
+
|
|
27
|
+
1. Produce a **single, comprehensive commit** that accurately describes the relevant changes.
|
|
28
|
+
2. **Push** the branch and **create (or update) a Pull Request** for review.
|
|
29
|
+
3. If arguments were given: **stage and commit only** the changes tied to those features; do not touch other modified files.
|
|
30
|
+
|
|
31
|
+
# Process and rules
|
|
32
|
+
|
|
33
|
+
## 0. Description-only / no-git mode (check first)
|
|
34
|
+
|
|
35
|
+
If the user **explicitly** requested no git operations (e.g. "no PR", "only commit", "only description", "don't touch git", "just the message", "dry run"):
|
|
36
|
+
|
|
37
|
+
- Perform **only** steps 1–3: inspect state, resolve scope (which files/hunks would be staged), and write the full commit message (subject + body).
|
|
38
|
+
- **Do not** run `git add`, `git commit`, `git push`, or `gh pr create`. Do not modify the repository in any way.
|
|
39
|
+
- Output for the user:
|
|
40
|
+
1. List of files (and hunks, if partial) that would be staged.
|
|
41
|
+
2. The proposed commit message in a copy-pasteable block.
|
|
42
|
+
- Then stop; skip steps 4, 5, and 6.
|
|
43
|
+
|
|
44
|
+
## 1. Inspect current state
|
|
45
|
+
|
|
46
|
+
- Run `git status` and `git diff` (and `git diff --staged` if needed) to list all modified, added, and deleted files.
|
|
47
|
+
- Identify the current branch. If not on a feature branch, decide whether to create one from the base branch (e.g. `main` or `develop`) before committing.
|
|
48
|
+
|
|
49
|
+
## 2. Resolve scope: full commit vs feature-scoped commit
|
|
50
|
+
|
|
51
|
+
- **If `$ARGUMENTS` is empty or not provided**
|
|
52
|
+
- Treat all relevant changes (excluding files that should not be committed, e.g. `.env`, build artifacts, local config) as the scope for this commit.
|
|
53
|
+
- Stage all of those and proceed to step 3.
|
|
54
|
+
|
|
55
|
+
- **If `$ARGUMENTS` is provided (e.g. ticket IDs or feature names)**
|
|
56
|
+
- Map each argument to the changes that clearly belong to it (by path, ticket id in branch name, or context in diffs).
|
|
57
|
+
- Stage **only** the files/hunks that belong to those features.
|
|
58
|
+
- Leave any other modified files **unstaged** and do not include them in the commit.
|
|
59
|
+
- If a file contains both feature-related and unrelated changes, use `git add -p` (or equivalent) to stage only the hunks that belong to the requested features.
|
|
60
|
+
- If no changes clearly match the given arguments, report this and do not commit.
|
|
61
|
+
|
|
62
|
+
## 3. Commit message
|
|
63
|
+
|
|
64
|
+
- Write the commit message **in English** (per `docs/base-standards.md`).
|
|
65
|
+
- Make it **descriptive** (per Git Workflow in `backend-standards.md` and `frontend-standards.md`).
|
|
66
|
+
- Structure it so that:
|
|
67
|
+
- **Subject line**: Short, imperative summary (e.g. "Add candidate filters to position list", "Fix validation for application deadline"). Optionally prefix with a scope or ticket id (e.g. `SCRUM-123: Add candidate filters`).
|
|
68
|
+
- **Body** (if needed): Bullet points or short paragraphs describing what changed and why (areas touched, new behavior, fixes). Reference ticket IDs here if they apply.
|
|
69
|
+
- Do not commit secrets, `.env`, or other sensitive or generated artifacts.
|
|
70
|
+
|
|
71
|
+
## 4. Commit and push
|
|
72
|
+
|
|
73
|
+
- Create the commit with the message from step 3.
|
|
74
|
+
- Push the current branch to the remote (`git push origin <branch>`). If the branch does not exist on the remote, push with `-u` to set upstream.
|
|
75
|
+
|
|
76
|
+
## 5. Pull Request
|
|
77
|
+
|
|
78
|
+
- Use the **GitHub CLI (`gh`)** for all GitHub operations (per repository standards).
|
|
79
|
+
- Create or update the PR for the current branch:
|
|
80
|
+
- **Title**: Clear, aligned with the commit (e.g. include ticket ID if applicable: `[SCRUM-123] Add candidate filters to position list`).
|
|
81
|
+
- **Description**: Summarize the change set, link to the ticket if relevant, and note any testing or follow-ups.
|
|
82
|
+
- If the repo uses branch protection or required checks, mention that the PR is ready for review once checks pass.
|
|
83
|
+
|
|
84
|
+
## 6. Summary for the user
|
|
85
|
+
|
|
86
|
+
- Report what was committed (files and scope).
|
|
87
|
+
- If arguments were provided: confirm which features/tickets were included and that other changes were left unstaged.
|
|
88
|
+
- Provide the PR URL (from `gh` output).
|
|
89
|
+
|
|
90
|
+
# References
|
|
91
|
+
|
|
92
|
+
- `docs/base-standards.md`: English-only for commit messages and technical artifacts.
|
|
93
|
+
- `docs/backend-standards.md` and `docs/frontend-standards.md`: Git Workflow (feature branches, descriptive commits, small focused branches).
|
|
94
|
+
- Repository git workflow conventions: Use `gh` for GitHub and PR creation; optional ticket-based branch and PR linking.
|
|
95
|
+
|
|
96
|
+
# Notes
|
|
97
|
+
|
|
98
|
+
- **Description-only**: When the user asks for no PR or only the commit text, output the staging plan and message only; do not run any git or `gh` commands.
|
|
99
|
+
- Do not run destructive git commands (e.g. `git push --force` without explicit user request).
|
|
100
|
+
- If there are conflicts or the push is rejected, report the situation and suggest next steps (e.g. pull/rebase then push), but do not force-push unless the user asks.
|
|
101
|
+
- When arguments are provided, **only** the changes tied to those features are staged and committed; everything else remains in the working tree for a separate commit or PR.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: enrich-us
|
|
3
|
+
description: Analyze and enhance user stories with complete, implementation-ready technical detail from direct ticket input or monday.com.
|
|
4
|
+
author: Flow Spec
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
---
|
|
7
|
+
# enrich-us Skill
|
|
8
|
+
|
|
9
|
+
Use it when this workflow is required in the project.
|
|
10
|
+
|
|
11
|
+
## Instructions
|
|
12
|
+
|
|
13
|
+
Please analyze and enrich the ticket: $ARGUMENTS.
|
|
14
|
+
|
|
15
|
+
Follow these steps:
|
|
16
|
+
|
|
17
|
+
1. Determine the ticket input source:
|
|
18
|
+
- **Direct input mode (default when ticket text is provided):** Use the ticket content shared by the user in the prompt/chat.
|
|
19
|
+
- **Monday mode (optional):** If the user provides a monday.com item id/key, or asks to use monday (including references like "the one in progress"), use the Monday MCP to fetch the item details.
|
|
20
|
+
- Boards in this workflow store a custom **ID column** (a text column) holding a readable key such as `PROJ-123`. Resolve the item by looking it up via that column value (not the internal numeric item id) using the MCP's "find item by column value" capability.
|
|
21
|
+
2. Act as a product expert with technical knowledge.
|
|
22
|
+
3. Understand the problem described in the ticket.
|
|
23
|
+
4. Decide whether or not the User Story is completely detailed according to product best practices. Validate that it includes:
|
|
24
|
+
- Full functionality description
|
|
25
|
+
- Comprehensive list of fields to update
|
|
26
|
+
- Required endpoints structure and URLs
|
|
27
|
+
- Files/modules to modify according to architecture and best practices
|
|
28
|
+
- Definition of done (implementation and delivery steps)
|
|
29
|
+
- Documentation and unit test updates
|
|
30
|
+
- Non-functional requirements (security, performance, observability, etc.)
|
|
31
|
+
5. If the story lacks enough technical detail for autonomous implementation, provide an improved version that is clearer, more specific, and concise, aligned with step 4. Use project technical context from `@documentation`. Return the result in markdown.
|
|
32
|
+
6. Output format must always include:
|
|
33
|
+
- `## Original`
|
|
34
|
+
- `## Enhanced`
|
|
35
|
+
7. Monday write-back is optional and only applies in Monday mode:
|
|
36
|
+
- Update the monday.com item by appending the enhanced content after the original content (as an update/comment on the item), with clear `h2` sections `[original]` and `[enhanced]` and readable formatting (lists/code snippets when useful).
|
|
37
|
+
- If the item's status column indicates it needs refinement (e.g. a label like `To Refine`), move it to the label that indicates refinement is complete (e.g. `Pending refinement validation`), per the board's configured status labels.
|
|
38
|
+
|
|
39
|
+
## Notes
|
|
40
|
+
|
|
41
|
+
- Do not require monday.com when the user already provided full ticket content directly.
|
|
42
|
+
- If input is ambiguous (for example, user gives a short reference without content), ask whether to resolve via monday.com or request the full ticket text.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: explain
|
|
3
|
+
description: Teach underlying concepts with clear mental models to close skill gaps behind user questions.
|
|
4
|
+
author: Flow Spec
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
---
|
|
7
|
+
# explain Skill
|
|
8
|
+
|
|
9
|
+
Use it when this workflow is required in the project.
|
|
10
|
+
|
|
11
|
+
## Instructions
|
|
12
|
+
|
|
13
|
+
# Instructions
|
|
14
|
+
|
|
15
|
+
You are an expert learning facilitator. Your role is to help the user **understand the concepts behind their request**, not just answer the question. You do not optimize for speed or unblocking; you optimize for **skill acquisition**, **conceptual clarity**, **mental models**, and **transferable understanding**. Your purpose is to close the skill gap behind the user's question.
|
|
16
|
+
|
|
17
|
+
When the user's prompt is clearly a question, identify the **skill gap** behind it (infer the type: fundamentals, mental model, tooling, systems interaction, or debugging methodology) and tailor the explanation accordingly. Do not expose your internal diagnosis; use it to shape depth and focus. Teach the underlying concepts so they can reason about similar problems later.
|
|
18
|
+
|
|
19
|
+
**Never jump to fixes.** Explain the system before discussing behavior. Do not provide checklists, quick procedural steps, unexplained code, or shallow debugging advice without conceptual explanation.
|
|
20
|
+
|
|
21
|
+
**Ground explanations** in official documentation and established design patterns. Do not speculate or invent APIs or parameters; if uncertain, state uncertainty. Reducing hallucination is part of your role.
|
|
22
|
+
|
|
23
|
+
**Behavior and tone:** Structured, not verbose. No marketing tone, motivational fluff, or emojis. Do not say "as an AI" or similar. Do not provide direct fixes or code snippets unless the user explicitly asks for them in a follow-up.
|
|
24
|
+
|
|
25
|
+
## Handling the topic
|
|
26
|
+
|
|
27
|
+
- **If arguments are provided** ($ARGUMENTS): Use them as the user prompt (question or request to explain) and proceed with the response below.
|
|
28
|
+
- **If no arguments are passed:** Use the **context of the conversation** as the topic to explain. If there is no prior conversation or no clear topic in context, **ask the user explicitly** what topic or concept they want explained; do not invent a topic.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Your objective
|
|
33
|
+
|
|
34
|
+
Given the topic (from arguments or conversation context), produce a **concept-focused learning response** that includes all of the following, in order. Adapt depth and examples to the question; keep each section concise but complete.
|
|
35
|
+
|
|
36
|
+
### 1. Skill gap and concept summary
|
|
37
|
+
|
|
38
|
+
- **If the prompt is a question**: State briefly what skill or concept gap the question reveals (e.g. "understanding of caching strategies", "familiarity with TDD", "how RAG differs from fine-tuning").
|
|
39
|
+
- **Concept summary**: In 2–4 short paragraphs, explain the core concept(s) in plain language. Your explanation should answer:
|
|
40
|
+
- **What** is happening?
|
|
41
|
+
- **Why** does it behave this way?
|
|
42
|
+
- **Where** in the system does this effect originate? (when relevant)
|
|
43
|
+
- Cover **technical concepts** when relevant: e.g. caching strategy, RAG, async execution, lazy loading, API design, state management, security (auth, CORS, etc.).
|
|
44
|
+
- Cover **design and process concepts** when relevant: e.g. TDD, DDD, SOLID, design patterns (Factory, Repository, Observer…), separation of concerns, API versioning.
|
|
45
|
+
- Use precise terms and one or two concrete examples tied to the user's context when possible.
|
|
46
|
+
|
|
47
|
+
### 2. Alternatives to the solution
|
|
48
|
+
|
|
49
|
+
- List **2–4 alternative approaches** to solving the same problem or achieving the same goal.
|
|
50
|
+
- For each: name it, one-sentence description, and when it tends to be a better or worse fit (trade-offs: complexity, performance, maintainability, team familiarity).
|
|
51
|
+
- **Deepen the section**: Also include, when relevant:
|
|
52
|
+
- Edge cases and failure modes.
|
|
53
|
+
- Common misconceptions and what experienced developers pay attention to.
|
|
54
|
+
- Keep it scoped to what the user asked; avoid unnecessary breadth.
|
|
55
|
+
|
|
56
|
+
### 3. Visual or mental model (when appropriate)
|
|
57
|
+
|
|
58
|
+
- If the concept benefits from structure or flow, provide **one** of:
|
|
59
|
+
- A **mental model** (e.g. "Think of X as…", "The flow is: 1)… 2)…").
|
|
60
|
+
- A **diagram** in text (ASCII/Mermaid) or a short description of a diagram they could draw (boxes, arrows, layers).
|
|
61
|
+
- Skip this section only if the topic is purely factual and a model would not add clarity.
|
|
62
|
+
|
|
63
|
+
### 4. Quiz to validate learnings (interactive)
|
|
64
|
+
|
|
65
|
+
- Provide **3–5 short quiz questions** (multiple choice or short answer) that check:
|
|
66
|
+
- Understanding of the main concept.
|
|
67
|
+
- When to choose one approach over another.
|
|
68
|
+
- Common pitfalls or misconceptions.
|
|
69
|
+
- **Do not give the answers yet.** Present only the questions. Tell the user to answer them (in the chat), and that you will provide the answer key and feedback **after they submit their answers**. Wait for the user's response before revealing the correct answers or giving the answer key.
|
|
70
|
+
|
|
71
|
+
### Adaptive strategies
|
|
72
|
+
|
|
73
|
+
- **When the user is seeing the concept for the first time:** Start from first principles, define key terms precisely, contrast with adjacent concepts, use a minimal concrete example, then abstract.
|
|
74
|
+
- **When the user says they don't get it (or similar):** Change explanatory strategy: use an analogy, a simpler example, or rebuild the abstraction step by step.
|
|
75
|
+
|
|
76
|
+
### Success criterion
|
|
77
|
+
|
|
78
|
+
A successful response should make the user feel: *"I understand how this system works and why it behaves that way."* Not: *"I applied a fix."*
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
# User prompt (question or request to explain)
|
|
83
|
+
|
|
84
|
+
$ARGUMENTS
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: meta-prompt
|
|
3
|
+
description: Rewrite prompts using prompt-engineering best practices for precise and complete results.
|
|
4
|
+
author: Flow Spec
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
---
|
|
7
|
+
# meta-prompt Skill
|
|
8
|
+
|
|
9
|
+
Use it when this workflow is required in the project.
|
|
10
|
+
|
|
11
|
+
## Instructions
|
|
12
|
+
|
|
13
|
+
# Instructions
|
|
14
|
+
|
|
15
|
+
You are an expert in prompt engineering.
|
|
16
|
+
Given the following prompt, prepare it using best practices for structure (role, objective...) and format to achieve a precise and exhaustive result. Stick only to the requested objective by carefully analyzing what is asked in the original prompt
|
|
17
|
+
|
|
18
|
+
# Original prompt:
|
|
19
|
+
[The prompt that the user introduces in the command]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: update-docs
|
|
3
|
+
description: Identify and update required technical documentation based on implemented changes.
|
|
4
|
+
author: Flow Spec
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
---
|
|
7
|
+
# update-docs Skill
|
|
8
|
+
|
|
9
|
+
Use it when this workflow is required in the project.
|
|
10
|
+
|
|
11
|
+
## Instructions
|
|
12
|
+
|
|
13
|
+
Use `docs/documentation-standards.md` to update whatever documentation is needed according to the changes made
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: using-git-worktrees
|
|
3
|
+
description: Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
|
|
4
|
+
author: Flow Spec
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Using Git Worktrees
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.
|
|
13
|
+
|
|
14
|
+
**Core principle:** Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.
|
|
15
|
+
|
|
16
|
+
**Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace."
|
|
17
|
+
|
|
18
|
+
## Step 0: Detect Existing Isolation
|
|
19
|
+
|
|
20
|
+
**Before creating anything, check if you are already in an isolated workspace.**
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
|
|
24
|
+
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
|
|
25
|
+
BRANCH=$(git branch --show-current)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Submodule guard:** `GIT_DIR != GIT_COMMON` is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# If this returns a path, you're in a submodule, not a worktree — treat as normal repo
|
|
32
|
+
git rev-parse --show-superproject-working-tree 2>/dev/null
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**If `GIT_DIR != GIT_COMMON` (and not a submodule):** You are already in a linked worktree. Skip to Step 3 (Project Setup). Do NOT create another worktree.
|
|
36
|
+
|
|
37
|
+
Report with branch state:
|
|
38
|
+
- On a branch: "Already in isolated workspace at `<path>` on branch `<name>`."
|
|
39
|
+
- Detached HEAD: "Already in isolated workspace at `<path>` (detached HEAD, externally managed). Branch creation needed at finish time."
|
|
40
|
+
|
|
41
|
+
**If `GIT_DIR == GIT_COMMON` (or in a submodule):** You are in a normal repo checkout.
|
|
42
|
+
|
|
43
|
+
Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:
|
|
44
|
+
|
|
45
|
+
> "Would you like me to set up an isolated worktree? It protects your current branch from changes."
|
|
46
|
+
|
|
47
|
+
Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 3.
|
|
48
|
+
|
|
49
|
+
## Step 1: Create Isolated Workspace
|
|
50
|
+
|
|
51
|
+
**You have two mechanisms. Try them in this order.**
|
|
52
|
+
|
|
53
|
+
### 1a. Native Worktree Tools (preferred)
|
|
54
|
+
|
|
55
|
+
The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag. If you do, use it and skip to Step 3.
|
|
56
|
+
|
|
57
|
+
Native tools handle directory placement, branch creation, and cleanup automatically. Using `git worktree add` when you have a native tool creates phantom state your harness can't see or manage.
|
|
58
|
+
|
|
59
|
+
If the native flow does not propagate Claude/Cursor settings and the user expects parity with the main checkout, copy `.claude/settings.json` and `.claude/settings.local.json` from the primary workspace using the same loop as Step 1b **after** the native tool finishes—only when files exist on disk.
|
|
60
|
+
|
|
61
|
+
Only proceed to Step 1b if you have no native worktree tool available.
|
|
62
|
+
|
|
63
|
+
### 1b. Git Worktree Fallback
|
|
64
|
+
|
|
65
|
+
**Only use this if Step 1a does not apply** — you have no native worktree tool available. Create a worktree manually using git.
|
|
66
|
+
|
|
67
|
+
#### Directory Selection
|
|
68
|
+
|
|
69
|
+
Follow this priority order. Explicit user preference always beats observed filesystem state.
|
|
70
|
+
|
|
71
|
+
1. **Check your instructions for a declared worktree directory preference.** If the user has already specified one, use it without asking.
|
|
72
|
+
|
|
73
|
+
2. **Check for an existing project-local worktree directory:**
|
|
74
|
+
```bash
|
|
75
|
+
ls -d .worktrees 2>/dev/null # Preferred (hidden)
|
|
76
|
+
ls -d worktrees 2>/dev/null # Alternative
|
|
77
|
+
```
|
|
78
|
+
If found, use it. If both exist, `.worktrees` wins.
|
|
79
|
+
|
|
80
|
+
3. **Check for an existing global directory:**
|
|
81
|
+
```bash
|
|
82
|
+
project=$(basename "$(git rev-parse --show-toplevel)")
|
|
83
|
+
ls -d ~/.config/superpowers/worktrees/$project 2>/dev/null
|
|
84
|
+
```
|
|
85
|
+
If found, use it (backward compatibility with legacy global path).
|
|
86
|
+
|
|
87
|
+
4. **If there is no other guidance available**, default to `.worktrees/` at the project root.
|
|
88
|
+
|
|
89
|
+
5. **Optional sibling-directory layout** (only when the user or project docs declare it): keep worktrees outside the repo tree next to the project folder:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
SOURCE_ROOT=$(git rev-parse --show-toplevel)
|
|
93
|
+
PROJECT_ROOT=$(basename "$SOURCE_ROOT")
|
|
94
|
+
LOCATION="../${PROJECT_ROOT}-worktrees"
|
|
95
|
+
# path="$LOCATION/$BRANCH_NAME"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
This avoids nesting worktrees under `SOURCE_ROOT`; `.gitignore` checks for `.worktrees` / `worktrees` under the repo do not apply here.
|
|
99
|
+
|
|
100
|
+
#### Safety Verification (project-local directories only)
|
|
101
|
+
|
|
102
|
+
**MUST verify directory is ignored before creating worktree:**
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**If NOT ignored:** Add to .gitignore, commit the change, then proceed.
|
|
109
|
+
|
|
110
|
+
**Why critical:** Prevents accidentally committing worktree contents to repository.
|
|
111
|
+
|
|
112
|
+
Global directories (`~/.config/superpowers/worktrees/`) need no verification.
|
|
113
|
+
|
|
114
|
+
#### Create the Worktree
|
|
115
|
+
|
|
116
|
+
**Capture the main checkout root before `git worktree add`.** After `cd` into the new worktree, `git rev-parse --show-toplevel` points at the worktree directory, not the checkout where `.claude/settings*.json` usually lives.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
project=$(basename "$(git rev-parse --show-toplevel)")
|
|
120
|
+
SOURCE_ROOT=$(git rev-parse --show-toplevel)
|
|
121
|
+
|
|
122
|
+
# Determine path based on chosen location
|
|
123
|
+
# For project-local: path="$LOCATION/$BRANCH_NAME"
|
|
124
|
+
# For global: path="~/.config/superpowers/worktrees/$project/$BRANCH_NAME"
|
|
125
|
+
|
|
126
|
+
git worktree add "$path" -b "$BRANCH_NAME"
|
|
127
|
+
cd "$path"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Sandbox fallback:** If `git worktree add` fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
|
|
131
|
+
|
|
132
|
+
#### Copy Claude configuration (Step 1b only)
|
|
133
|
+
|
|
134
|
+
After creating the worktree with git (Step 1b), copy local Claude settings from the **main checkout** so Cursor/Claude CLI behavior matches the primary workspace. These files are often untracked.
|
|
135
|
+
|
|
136
|
+
Do **not** copy if the user declines or if a native tool (Step 1a) already propagates settings—respect the harness.
|
|
137
|
+
|
|
138
|
+
Run **after** `cd "$path"` (still using `SOURCE_ROOT` captured above):
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
copied_claude_settings=false
|
|
142
|
+
for claude_settings in ".claude/settings.json" ".claude/settings.local.json"; do
|
|
143
|
+
if [ -f "$SOURCE_ROOT/$claude_settings" ]; then
|
|
144
|
+
mkdir -p ".claude"
|
|
145
|
+
cp -p "$SOURCE_ROOT/$claude_settings" "./$claude_settings"
|
|
146
|
+
echo "Copied $claude_settings to worktree"
|
|
147
|
+
copied_claude_settings=true
|
|
148
|
+
fi
|
|
149
|
+
done
|
|
150
|
+
|
|
151
|
+
if [ "$copied_claude_settings" = false ]; then
|
|
152
|
+
echo "No local Claude settings found (.claude/settings.json or .claude/settings.local.json)"
|
|
153
|
+
fi
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Symlinks:** If the source tree uses symlinks for `.claude` (e.g. `.claude/skills` → `../../ai-specs/skills`), copying only these JSON files does not recreate symlink targets. Either repeat the same symlink layout in the worktree or rely on project-relative paths inside `settings.json`.
|
|
157
|
+
|
|
158
|
+
## Step 3: Project Setup
|
|
159
|
+
|
|
160
|
+
Auto-detect and run appropriate setup:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Node.js
|
|
164
|
+
if [ -f package.json ]; then npm install; fi
|
|
165
|
+
|
|
166
|
+
# Rust
|
|
167
|
+
if [ -f Cargo.toml ]; then cargo build; fi
|
|
168
|
+
|
|
169
|
+
# Python
|
|
170
|
+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
|
171
|
+
if [ -f pyproject.toml ]; then poetry install; fi
|
|
172
|
+
|
|
173
|
+
# Go
|
|
174
|
+
if [ -f go.mod ]; then go mod download; fi
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Step 4: Verify Clean Baseline
|
|
178
|
+
|
|
179
|
+
Run tests to ensure workspace starts clean:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Use project-appropriate command
|
|
183
|
+
npm test / cargo test / pytest / go test ./...
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**If tests fail:** Report failures, ask whether to proceed or investigate.
|
|
187
|
+
|
|
188
|
+
**If tests pass:** Report ready.
|
|
189
|
+
|
|
190
|
+
### Report
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
Worktree ready at <full-path>
|
|
194
|
+
Claude settings copied (or none found / skipped per harness)
|
|
195
|
+
Tests passing (<N> tests, 0 failures)
|
|
196
|
+
Ready to implement <feature-name>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Step 5: Cleanup — Remove the Worktree When Done
|
|
200
|
+
|
|
201
|
+
**Run cleanup once the work is complete.** "Done" means: branch merged, PR closed, the experiment was discarded, or the user has explicitly confirmed they no longer need the isolated workspace. Never remove a worktree that still contains uncommitted, unpushed, or unmerged changes the user may want.
|
|
202
|
+
|
|
203
|
+
### 5.0 Detect Cleanup Mode
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
|
|
207
|
+
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- **If `GIT_DIR == GIT_COMMON`:** You were never in a linked worktree (Step 0 sent you straight to Step 3). There is nothing to clean up — skip Step 5 entirely.
|
|
211
|
+
- **If `GIT_DIR != GIT_COMMON`:** You are inside a linked worktree. Continue with cleanup.
|
|
212
|
+
|
|
213
|
+
### 5.1 Verify Work Is Saved
|
|
214
|
+
|
|
215
|
+
Before removing anything, confirm there is no work to lose:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
git status --porcelain # Must be empty (no uncommitted changes)
|
|
219
|
+
git log @{u}.. 2>/dev/null # Must be empty (no unpushed commits)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**If either command returns output:** Stop. Report the unsaved work to the user and ask how to proceed (commit/push, stash, or force discard). Never delete a worktree with unsaved work without explicit user confirmation.
|
|
223
|
+
|
|
224
|
+
Capture the worktree path and branch name before leaving the directory:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
WORKTREE_PATH=$(git rev-parse --show-toplevel)
|
|
228
|
+
BRANCH_NAME=$(git branch --show-current)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### 5.2 Native Worktree Tools (preferred)
|
|
232
|
+
|
|
233
|
+
If you used a native worktree tool in Step 1a (`EnterWorktree`, `WorktreeCreate`, `/worktree`, etc.), use the matching native command to remove the worktree (e.g. `LeaveWorktree`, `WorktreeRemove`, `/worktree remove`). Native tools clean up directories, branches, and harness state consistently.
|
|
234
|
+
|
|
235
|
+
Only proceed to 5.3 if no native cleanup tool is available.
|
|
236
|
+
|
|
237
|
+
### 5.3 Git Worktree Fallback Cleanup
|
|
238
|
+
|
|
239
|
+
**Only use this if Step 5.2 does not apply** — you created the worktree manually in Step 1b.
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# 1. Move out of the worktree before deleting it
|
|
243
|
+
cd "$GIT_COMMON/.." # or any path inside the main checkout
|
|
244
|
+
|
|
245
|
+
# 2. Remove the worktree
|
|
246
|
+
git worktree remove "$WORKTREE_PATH"
|
|
247
|
+
|
|
248
|
+
# 3. If files are still present (e.g. ignored artifacts blocking removal),
|
|
249
|
+
# confirm with the user, then force-remove
|
|
250
|
+
git worktree remove --force "$WORKTREE_PATH"
|
|
251
|
+
|
|
252
|
+
# 4. Delete the local branch only if it was created for this worktree
|
|
253
|
+
# AND has been merged or is no longer needed
|
|
254
|
+
git branch -d "$BRANCH_NAME" # safe delete (refuses if unmerged)
|
|
255
|
+
git branch -D "$BRANCH_NAME" # force delete (only with user confirmation)
|
|
256
|
+
|
|
257
|
+
# 5. Prune stale worktree metadata if the directory was deleted manually
|
|
258
|
+
git worktree prune
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Sandbox fallback:** If removal fails due to permissions, report the failure and the path that needs manual cleanup. Do not retry destructively.
|
|
262
|
+
|
|
263
|
+
### 5.4 Verify Cleanup
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
git worktree list # WORKTREE_PATH must no longer appear
|
|
267
|
+
ls -d "$WORKTREE_PATH" 2>/dev/null # Must return nothing
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Report
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
Worktree removed: <full-path>
|
|
274
|
+
Branch <name> deleted (or kept, if still needed)
|
|
275
|
+
Main checkout left untouched
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Quick Reference
|
|
279
|
+
|
|
280
|
+
| Situation | Action |
|
|
281
|
+
|-----------|--------|
|
|
282
|
+
| Already in linked worktree | Skip creation (Step 0) |
|
|
283
|
+
| In a submodule | Treat as normal repo (Step 0 guard) |
|
|
284
|
+
| Native worktree tool available | Use it (Step 1a) |
|
|
285
|
+
| No native tool | Git worktree fallback (Step 1b) |
|
|
286
|
+
| `.worktrees/` exists | Use it (verify ignored) |
|
|
287
|
+
| `worktrees/` exists | Use it (verify ignored) |
|
|
288
|
+
| Both exist | Use `.worktrees/` |
|
|
289
|
+
| Neither exists | Check instruction file, then default `.worktrees/` |
|
|
290
|
+
| User/project declares sibling worktrees | `../${PROJECT_ROOT}-worktrees` (Step 1b item 5) |
|
|
291
|
+
| Global path exists | Use it (backward compat) |
|
|
292
|
+
| Directory not ignored | Add to .gitignore + commit |
|
|
293
|
+
| Permission error on create | Sandbox fallback, work in place |
|
|
294
|
+
| Tests fail during baseline | Report failures + ask |
|
|
295
|
+
| No package.json/Cargo.toml | Skip dependency install |
|
|
296
|
+
| Work complete, in linked worktree | Run Step 5 cleanup |
|
|
297
|
+
| Never created a worktree | Skip Step 5 |
|
|
298
|
+
| Uncommitted/unpushed changes at cleanup | Stop and ask user |
|
|
299
|
+
| Native cleanup tool available | Use it (Step 5.2) |
|
|
300
|
+
| No native cleanup tool | `git worktree remove` (Step 5.3) |
|
|
301
|
+
| Worktree directory deleted manually | `git worktree prune` |
|
|
302
|
+
| Git fallback: clone Claude behavior into worktree | Copy `.claude/settings*.json` from `SOURCE_ROOT` (Step 1b) |
|
|
303
|
+
| Repo uses `.claude` symlinks | Copy JSON only is not enough—recreate symlinks or paths |
|
|
304
|
+
|
|
305
|
+
## Common Mistakes
|
|
306
|
+
|
|
307
|
+
### Fighting the harness
|
|
308
|
+
|
|
309
|
+
- **Problem:** Using `git worktree add` when the platform already provides isolation
|
|
310
|
+
- **Fix:** Step 0 detects existing isolation. Step 1a defers to native tools.
|
|
311
|
+
|
|
312
|
+
### Skipping detection
|
|
313
|
+
|
|
314
|
+
- **Problem:** Creating a nested worktree inside an existing one
|
|
315
|
+
- **Fix:** Always run Step 0 before creating anything
|
|
316
|
+
|
|
317
|
+
### Skipping ignore verification
|
|
318
|
+
|
|
319
|
+
- **Problem:** Worktree contents get tracked, pollute git status
|
|
320
|
+
- **Fix:** Always use `git check-ignore` before creating project-local worktree
|
|
321
|
+
|
|
322
|
+
### Assuming directory location
|
|
323
|
+
|
|
324
|
+
- **Problem:** Creates inconsistency, violates project conventions
|
|
325
|
+
- **Fix:** Follow priority: existing > global legacy > instruction file > default
|
|
326
|
+
|
|
327
|
+
### Proceeding with failing tests
|
|
328
|
+
|
|
329
|
+
- **Problem:** Can't distinguish new bugs from pre-existing issues
|
|
330
|
+
- **Fix:** Report failures, get explicit permission to proceed
|
|
331
|
+
|
|
332
|
+
### Removing a worktree with unsaved work
|
|
333
|
+
|
|
334
|
+
- **Problem:** `git worktree remove --force` discards uncommitted/unpushed changes silently
|
|
335
|
+
- **Fix:** Always run `git status --porcelain` and `git log @{u}..` before removal; stop and ask if either is non-empty
|
|
336
|
+
|
|
337
|
+
### Deleting the branch before it is merged
|
|
338
|
+
|
|
339
|
+
- **Problem:** `git branch -D` destroys commits that were never merged or pushed
|
|
340
|
+
- **Fix:** Prefer `git branch -d` (safe delete); only force-delete after explicit user confirmation
|
|
341
|
+
|
|
342
|
+
### Mixing native and manual cleanup
|
|
343
|
+
|
|
344
|
+
- **Problem:** Running `git worktree remove` on a worktree created by a native tool leaves phantom harness state
|
|
345
|
+
- **Fix:** Whatever created the worktree must remove it (native tool ↔ native tool, git ↔ git)
|
|
346
|
+
|
|
347
|
+
### Copying Claude settings from the wrong directory
|
|
348
|
+
|
|
349
|
+
- **Problem:** Using `git rev-parse --show-toplevel` after `cd` into the new worktree resolves to the worktree path, so copies find no settings or copy from the wrong place
|
|
350
|
+
- **Fix:** Set `SOURCE_ROOT=$(git rev-parse --show-toplevel)` in the main checkout **before** `git worktree add`, then use `$SOURCE_ROOT` in the copy loop
|
|
351
|
+
|
|
352
|
+
## Red Flags
|
|
353
|
+
|
|
354
|
+
**Never:**
|
|
355
|
+
- Create a worktree when Step 0 detects existing isolation
|
|
356
|
+
- Use `git worktree add` when you have a native worktree tool (e.g., `EnterWorktree`). This is the #1 mistake — if you have it, use it.
|
|
357
|
+
- Skip Step 1a by jumping straight to Step 1b's git commands
|
|
358
|
+
- Create worktree without verifying it's ignored (project-local)
|
|
359
|
+
- Skip baseline test verification
|
|
360
|
+
- Proceed with failing tests without asking
|
|
361
|
+
- Remove a worktree that still has uncommitted, unpushed, or unmerged work without explicit user confirmation
|
|
362
|
+
- Force-delete a branch (`git branch -D`) without confirming it is merged or no longer needed
|
|
363
|
+
- Run `git worktree remove` on a worktree created by a native tool
|
|
364
|
+
|
|
365
|
+
**Always:**
|
|
366
|
+
- Run Step 0 detection first
|
|
367
|
+
- Prefer native tools over git fallback
|
|
368
|
+
- Follow directory priority: existing > global legacy > instruction file > default
|
|
369
|
+
- Verify directory is ignored for project-local
|
|
370
|
+
- Auto-detect and run project setup
|
|
371
|
+
- Verify clean test baseline
|
|
372
|
+
- Run Step 5 cleanup once the work is done, using the same mechanism that created the worktree
|
|
373
|
+
- Verify there is nothing to lose before removing a worktree (`git status --porcelain`, `git log @{u}..`)
|
|
374
|
+
- Confirm with `git worktree list` and a directory check that cleanup actually completed
|
|
375
|
+
- After Step 1b (git fallback), copy `.claude/settings.json` and `.claude/settings.local.json` from `SOURCE_ROOT` captured before `git worktree add`
|