@refactco/refact-os 1.5.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +162 -0
  4. package/bin/refact-os.js +154 -0
  5. package/lib/adapters.js +302 -0
  6. package/lib/company.js +76 -0
  7. package/lib/frontmatter.js +30 -0
  8. package/lib/migrate.js +116 -0
  9. package/lib/project-utils.js +179 -0
  10. package/lib/refact-config.js +324 -0
  11. package/lib/scaffold.js +329 -0
  12. package/lib/validate.js +145 -0
  13. package/package.json +46 -0
  14. package/templates/base/AGENTS.md +9 -0
  15. package/templates/base/CLAUDE.md +3 -0
  16. package/templates/base/README.md +54 -0
  17. package/templates/base/agent/AGENTS.md +60 -0
  18. package/templates/base/agent/CLAUDE.md +7 -0
  19. package/templates/base/agent/claude-hooks.json +32 -0
  20. package/templates/base/agent/hooks/claude-sync-transcript.py +236 -0
  21. package/templates/base/agent/hooks/preflight-metadata.mjs +202 -0
  22. package/templates/base/agent/hooks/send-transcript-to-remote-server.py +238 -0
  23. package/templates/base/agent/hooks/sync-chat-transcript.py +188 -0
  24. package/templates/base/agent/hooks.json +29 -0
  25. package/templates/base/agent/scripts/import-project-chat-history.py +196 -0
  26. package/templates/base/agent/scripts/sync-asana.mjs +408 -0
  27. package/templates/base/agent/skills/adopt/SKILL.md +46 -0
  28. package/templates/base/agent/skills/close-ticket/SKILL.md +31 -0
  29. package/templates/base/agent/skills/extract-learnings/SKILL.md +90 -0
  30. package/templates/base/agent/skills/git-it/SKILL.md +138 -0
  31. package/templates/base/agent/skills/import-chat-history/SKILL.md +85 -0
  32. package/templates/base/agent/skills/ingest-input/SKILL.md +43 -0
  33. package/templates/base/agent/skills/open-ticket/SKILL.md +36 -0
  34. package/templates/base/agent/skills/process-docs/SKILL.md +69 -0
  35. package/templates/base/agent/skills/project-status/SKILL.md +35 -0
  36. package/templates/base/agent/skills/project-status/scripts/scan-status.mjs +153 -0
  37. package/templates/base/agent/skills/refact/SKILL.md +139 -0
  38. package/templates/base/agent/skills/setup-project/SKILL.md +140 -0
  39. package/templates/base/agent/skills/sync-asana/SKILL.md +106 -0
  40. package/templates/base/agent/skills/update-canonical-record/SKILL.md +28 -0
  41. package/templates/base/agent/skills/update-package/SKILL.md +51 -0
  42. package/templates/base/docs/context/project.md +30 -0
  43. package/templates/base/docs/decisions.md +22 -0
  44. package/templates/base/docs/index.md +31 -0
  45. package/templates/base/docs/sources/raw/.gitkeep +0 -0
  46. package/templates/base/docs/task/.gitkeep +0 -0
  47. package/templates/base/env.example +14 -0
  48. package/templates/base/gitignore +34 -0
  49. package/templates/overlays/client/agent/skills/create-deliverable/SKILL.md +29 -0
  50. package/templates/overlays/client/docs/deliverables/.gitkeep +0 -0
  51. package/templates/overlays/code/agent/skills/add-codebase/SKILL.md +239 -0
  52. package/templates/overlays/code/agent/skills/code-development/SKILL.md +58 -0
  53. package/templates/overlays/code/agent/skills/code-development/references/gitflow.md +144 -0
  54. package/templates/overlays/nextjs/agent/skills/nextjs-dev/SKILL.md +93 -0
  55. package/templates/overlays/nextjs/agent/skills/setup-netlify-deploy/SKILL.md +143 -0
  56. package/templates/overlays/nextjs/agent/skills/setup-nextjs-app/SKILL.md +118 -0
  57. package/templates/overlays/nextjs/agent/skills/setup-vercel-deploy/SKILL.md +116 -0
  58. package/templates/overlays/wordpress/agent/skills/install-wp-skills/SKILL.md +130 -0
  59. package/templates/overlays/wordpress/agent/skills/setup-kinsta-deploy/SKILL.md +201 -0
  60. package/templates/overlays/wordpress/agent/skills/wp-env/SKILL.md +478 -0
  61. package/templates/overlays/wordpress/wp-cli.yml.example +46 -0
@@ -0,0 +1,239 @@
1
+ ---
2
+ name: add-codebase
3
+ description: Clone or scaffold an external codebase into apps/<slot>/, stripping .git so it merges into the parent repo.
4
+ pattern: procedure
5
+ when_to_use: /refact add codebase <url | wordpress | seo | api | mobile>.
6
+ when_not_to_use: Editing code already under apps/ (use code-development).
7
+ next_skills: []
8
+ sub_agents: []
9
+ ---
10
+
11
+ # Add Codebase Reference
12
+
13
+ Use this reference when the user invokes `/refact add codebase ...` (or similar phrasings: "drop the client repo into apps", "scaffold a new WordPress codebase", "add a plugin to the WP app", etc.).
14
+
15
+ ## Goal
16
+
17
+ Manage the `apps/` directory: import existing GitHub repos as **vendored snapshots**, or scaffold fresh app slots.
18
+
19
+ `apps/` is tracked as part of this engagement repo. Imported clones have their `.git` directory stripped on entry, so each slot merges cleanly into the parent's git history with no nested repos or submodule confusion. Once placed, edit files in `apps/<slot>/` like any other source — there is no separate upstream to push back to from here.
20
+
21
+ ## Argument shapes
22
+
23
+ | User input | Flow | Where it lands |
24
+ |---|---|---|
25
+ | `<git-url>` (https or ssh) | **Flow A** — clone, detect, place, deref | `apps/<slot>/` |
26
+ | `wordpress` | **Flow B** — fresh WP scaffold | `apps/wordpress/` |
27
+ | `seo`, `api`, `mobile` | **Flow C** — empty slot | `apps/<slot>/` |
28
+
29
+ If the user passes anything else (e.g. `nextjs`, `front-end`, `wordpress plugin`), ask one focused clarifying question — these are not part of the supported set yet, so do **not** invent a scaffold.
30
+
31
+ ## Preflight (always)
32
+
33
+ 1. Confirm we are inside a refact-os scaffold:
34
+ - `agent/AGENTS.md` exists at the project root, AND
35
+ - `.cursor/` directory exists.
36
+ If not, stop and tell the user to run the scaffolder first (`npx refact-os init`).
37
+ 2. Ensure the `apps/` directory exists at the project root. Create it if missing.
38
+
39
+ ---
40
+
41
+ ## Flow A — URL clone
42
+
43
+ Triggered when the argument looks like a URL: starts with `http://`, `https://`, `git@`, or `ssh://`, or matches `<owner>/<repo>` shorthand (in which case expand to `https://github.com/<owner>/<repo>`).
44
+
45
+ ### A1. Clone to a staging directory first
46
+
47
+ Do **not** clone directly into `apps/<slot>/` — we need to inspect the contents before placing them. Use a staging dir under `apps/.staging-<rand>/`:
48
+
49
+ ```bash
50
+ STAGING="apps/.staging-$(date +%s)-$$"
51
+ git clone --no-tags "<url>" "$STAGING"
52
+ ```
53
+
54
+ If the clone fails (auth, network, repo moved), surface the exact error and stop. Do **not** retry by swapping protocols.
55
+
56
+ ### A2. Capture provenance BEFORE stripping .git
57
+
58
+ While the `.git` is still present, capture origin URL, HEAD SHA, default branch, and recent history into a single breadcrumb file:
59
+
60
+ ```bash
61
+ ORIGIN_URL="$(git -C "$STAGING" remote get-url origin)"
62
+ HEAD_SHA="$(git -C "$STAGING" rev-parse HEAD)"
63
+ DEFAULT_BRANCH="$(git -C "$STAGING" symbolic-ref --short HEAD 2>/dev/null || echo 'detached')"
64
+ RECENT_LOG="$(git -C "$STAGING" log --oneline -n 50 2>/dev/null || echo '(no history available)')"
65
+ IMPORT_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
66
+ ```
67
+
68
+ You will write these into `apps/<slot>/REFACT-SOURCE.md` in step A5.
69
+
70
+ ### A3. Detect the codebase type
71
+
72
+ Run these checks inside `$STAGING` in order; stop at the first match:
73
+
74
+ | Indicator | Suggested slot | Notes |
75
+ |---|---|---|
76
+ | Root has `wp-config.php` or `wp-config-sample.php` or `wp-load.php` | `wordpress` | Full WP core checkout |
77
+ | Root has `wp-content/` directory | `wordpress` | wp-content-only or full |
78
+ | Root has `.wp-env.json` and `wp-content/` mapped | `wordpress` | Refact-style WP project |
79
+ | Root has `composer.json` referencing `roots/bedrock` or `johnpbloch/wordpress-core` | `wordpress` | Bedrock-style |
80
+ | Root has a `*.php` file with `Plugin Name:` header line | **stop — single plugin** | See A3.1 |
81
+ | Root has `style.css` with `Theme Name:` header line | **stop — single theme** | See A3.2 |
82
+ | Root has `next.config.*` or `package.json` with `next` dependency | `front-end` | Next.js |
83
+ | Root has `package.json` with `react` dep (no Next) or `vite.config.*` | `front-end` | Generic React / Vite |
84
+ | Root has `package.json` with `expo` or `react-native` dep | `mobile` | |
85
+ | Root has `Cargo.toml`, `go.mod`, `pyproject.toml` only | `api` | Backend / service |
86
+ | None of the above | (ask the user) | See A3.3 |
87
+
88
+ #### A3.1 Single plugin
89
+
90
+ If detection identifies a single WordPress plugin (root `*.php` with `Plugin Name:` header and no `wp-content/`), stop and tell the user:
91
+
92
+ > "This URL looks like a single WordPress plugin, not a full codebase. Run `/refact add codebase wordpress` first to set up `apps/wordpress/`, then re-add this URL — I'll place it under `wp-content/plugins/<repo-name>/`."
93
+
94
+ Do **not** proceed. Remove the staging dir (`rm -rf "$STAGING"`).
95
+
96
+ If `apps/wordpress/` **already exists**, you may offer to place the plugin under `apps/wordpress/wp-content/plugins/<repo-name>/` directly — but ask before doing so.
97
+
98
+ #### A3.2 Single theme
99
+
100
+ Same shape as A3.1, but for themes. The destination would be `apps/wordpress/wp-content/themes/<repo-name>/`.
101
+
102
+ #### A3.3 Ambiguous
103
+
104
+ If no indicator matches, ask the user one question:
105
+
106
+ > "I couldn't auto-detect the type of this codebase. What slot name should I use under `apps/`? Common: `wordpress`, `front-end`, `seo`, `api`, `mobile`. Anything else works too."
107
+
108
+ Accept any slug (kebab-case, ASCII letters/digits/hyphens).
109
+
110
+ ### A4. Confirm the slot with the user
111
+
112
+ Even when detection succeeds, propose the slot and let the user override:
113
+
114
+ > "Detected: WordPress codebase. I'll place it at `apps/wordpress/`. OK, or different slot name?"
115
+
116
+ The vocabulary is **not fixed** — detection suggests, the user decides. Validate the final slot name is kebab-case ASCII (no spaces, no `/`, no `..`).
117
+
118
+ ### A5. Conflict guard
119
+
120
+ If `apps/<slot>/` already exists AND is non-empty, **stop** with:
121
+
122
+ > "An `apps/<slot>/` codebase already exists. Refusing to overwrite. To replace it, remove `apps/<slot>/` manually first, then re-run this command."
123
+
124
+ Clean up the staging dir (`rm -rf "$STAGING"`) before surfacing the error.
125
+
126
+ ### A6. Move staging → slot, strip .git, write breadcrumb
127
+
128
+ ```bash
129
+ mv "$STAGING" "apps/<slot>"
130
+ rm -rf "apps/<slot>/.git"
131
+ ```
132
+
133
+ Then write `apps/<slot>/REFACT-SOURCE.md` with the values captured in A2:
134
+
135
+ ```markdown
136
+ # Source
137
+
138
+ This codebase was imported via `/refact add codebase` on <IMPORT_DATE>.
139
+
140
+ - **Origin:** <ORIGIN_URL>
141
+ - **HEAD at import:** <HEAD_SHA>
142
+ - **Default branch:** <DEFAULT_BRANCH>
143
+
144
+ The original `.git` directory has been removed — this is a vendored, reference-only snapshot. Do **not** commit, push, or treat this as a live clone.
145
+
146
+ ## Recent history (at time of import)
147
+
148
+ ```
149
+ <RECENT_LOG>
150
+ ```
151
+ ```
152
+
153
+ ### A7. Report
154
+
155
+ Tell the user:
156
+ - The slot path (`apps/<slot>/`)
157
+ - The origin URL and HEAD SHA
158
+ - That `.git` was removed and a breadcrumb was written
159
+ - That this is reference-only — to make changes upstream, work in a separate clone
160
+
161
+ ---
162
+
163
+ ## Flow B — Fresh WordPress scaffold
164
+
165
+ Triggered by `/refact add codebase wordpress` (with no further argument).
166
+
167
+ ### B1. Conflict guard
168
+
169
+ If `apps/wordpress/` already exists, **stop** with:
170
+
171
+ > "An `apps/wordpress/` codebase already exists. Refusing to overwrite. Remove `apps/wordpress/` manually first to start over."
172
+
173
+ ### B2. Create skeleton
174
+
175
+ ```bash
176
+ mkdir -p apps/wordpress/wp-content/plugins
177
+ mkdir -p apps/wordpress/wp-content/themes
178
+ mkdir -p apps/wordpress/wp-content/mu-plugins
179
+ touch apps/wordpress/wp-content/plugins/.gitkeep
180
+ touch apps/wordpress/wp-content/themes/.gitkeep
181
+ touch apps/wordpress/wp-content/mu-plugins/.gitkeep
182
+ ```
183
+
184
+ ### B3. Write a stub README
185
+
186
+ Write `apps/wordpress/REFACT-SOURCE.md`:
187
+
188
+ ```markdown
189
+ # Source
190
+
191
+ Created fresh via `/refact add codebase wordpress` on <DATE>.
192
+
193
+ This slot is an empty WordPress codebase shell. Drop the client's WordPress source here — plugins under `wp-content/plugins/`, themes under `wp-content/themes/`, mu-plugins under `wp-content/mu-plugins/`.
194
+ ```
195
+
196
+ ### B4. Report
197
+
198
+ Tell the user the slot exists with empty `wp-content/{plugins,themes,mu-plugins}/` ready for content.
199
+
200
+ ---
201
+
202
+ ## Flow C — Fresh empty slot (`seo` / `api` / `mobile`)
203
+
204
+ Triggered by `/refact add codebase {seo|api|mobile}`.
205
+
206
+ ### C1. Conflict guard
207
+
208
+ If `apps/<slot>/` already exists, **stop** with the same per-slot refusal message used in A5.
209
+
210
+ ### C2. Create skeleton
211
+
212
+ ```bash
213
+ mkdir -p apps/<slot>
214
+ ```
215
+
216
+ Write `apps/<slot>/REFACT-SOURCE.md`:
217
+
218
+ ```markdown
219
+ # Source
220
+
221
+ Created fresh via `/refact add codebase <slot>` on <DATE>.
222
+
223
+ This slot is a vendored, reference-only placeholder. Drop a related codebase here, or use `/refact add codebase <url>` to import an existing repo into this slot.
224
+ ```
225
+
226
+ ### C3. Report
227
+
228
+ Tell the user the slot exists and is empty, ready for content.
229
+
230
+ ---
231
+
232
+ ## Guardrails
233
+
234
+ - **Commits to `apps/*` go to the parent engagement repo, not to any upstream.** Imported clones have `.git` removed precisely so there's no path back to the original remote. If the user wants changes upstreamed, they need a separate clone for that.
235
+ - **Never** overwrite an existing slot. Always refuse and ask the user to remove it manually first.
236
+ - **Never** invent a scaffold for an unsupported keyword. Ask the user instead.
237
+ - **Never** silently rename the slot if detection is ambiguous. Always confirm with the user before placing files.
238
+ - **Never** skip the `REFACT-SOURCE.md` breadcrumb after a URL clone — it's the only paper trail of where the code came from.
239
+ - If a clone or scaffold fails partway, clean up the partial slot (`rm -rf apps/<slot>`) before surfacing the error so a retry doesn't trip the conflict guard.
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: code-development
3
+ description: Use whenever the user asks to add a feature, fix a bug, refactor code, or otherwise change committed code in this project. Enforces the team's branching/PR workflow (GitFlow) before any edits begin, and routes to other code-development references as needed.
4
+ pattern: procedure
5
+ when_to_use: Any task that will result in committed code changes — "add a feature", "fix the bug", "refactor", "update the styling", "wire up the endpoint".
6
+ when_not_to_use: Read-only questions, exploration, documentation lookups, or chat/transcript processing (those go through /refact).
7
+ next_skills: []
8
+ sub_agents: []
9
+ ---
10
+
11
+ # Code Development Skill
12
+
13
+ This skill is the gate every code change passes through. Before editing files, it makes sure the agent is on the right branch and following the team's GitFlow.
14
+
15
+ ## When to invoke
16
+
17
+ Invoke this skill at the **start** of any task that will result in committed code changes:
18
+
19
+ - "Add a feature…"
20
+ - "Fix the bug where…"
21
+ - "Refactor the …"
22
+ - "Update the styling of…"
23
+ - "Wire up the new endpoint…"
24
+ - Any user message that implies an edit to versioned files.
25
+
26
+ Do **not** invoke for: read-only questions, exploration, documentation lookups, or chat history / transcript processing (those go through `/refact`).
27
+
28
+ ## Protocol
29
+
30
+ For every development task, in order:
31
+
32
+ 1. **Consult `agent/skills/code-development/references/gitflow.md`** before touching any file. Run the preflight checks (clean working tree, current branch, remote present), sync the base branch, and create a properly named feature branch. If preflight fails, stop and report rather than working on the wrong branch.
33
+ 2. **Do the work** on the feature branch. Make focused commits with Conventional Commits messages (see the gitflow reference).
34
+ 3. **Push and open a PR into the base branch** (`staging` unless the project's `agent/AGENTS.md` says otherwise). Use the PR body template in `gitflow.md`.
35
+ 4. **Report the PR URL** and surface CI status to the user.
36
+
37
+ ## References
38
+
39
+ | Topic | Reference |
40
+ |---|---|
41
+ | Branching, commits, PR workflow | `agent/skills/code-development/references/gitflow.md` |
42
+
43
+ Add more references here as the project grows (testing conventions, code style, deploy process, …). Each new reference becomes another step the skill can route to.
44
+
45
+ ## Hard rules
46
+
47
+ - Never edit committed files while still on the base branch (`staging` / `main`). Create the feature branch first.
48
+ - Never open a PR into `main` unless the user explicitly requests a `staging → main` promotion.
49
+ - Never bypass the gitflow reference "just for a small change." Small changes still need a branch and a PR.
50
+ - If the project's actual base branch is not `staging`, ask the user once, update `agent/AGENTS.md`, and continue with the corrected name.
51
+
52
+ ## When unsure
53
+
54
+ Ask one focused clarifying question rather than guessing on:
55
+
56
+ - Whether a ticket ID exists for the work.
57
+ - The intended scope of the change (one branch vs. several).
58
+ - Whether the user wants the PR opened immediately or held as a draft.
@@ -0,0 +1,144 @@
1
+ # GitFlow Reference
2
+
3
+ The team's branching workflow. The `code-development` skill consults this **before** any edit that adds a feature, fixes a bug, or otherwise changes committed code. Read it once at the start of a development task and follow it end-to-end.
4
+
5
+ ## TL;DR
6
+
7
+ ```
8
+ staging ──●──────────●────────●── (integration branch — never commit directly)
9
+ \ /\ /
10
+ \ / \ /
11
+ feat/x fix/y (your work happens here)
12
+ ```
13
+
14
+ 1. Start from a clean, up-to-date `staging`.
15
+ 2. Cut a feature branch: `feat/<ticket>-<slug>`, `fix/<ticket>-<slug>`, or `chore/<slug>`.
16
+ 3. Commit in small, conventional-commit-style chunks.
17
+ 4. Push and open a PR **into `staging`** (never into `main`).
18
+ 5. Stop and surface CI failures / review feedback rather than force-pushing past them.
19
+
20
+ ## Hard rules
21
+
22
+ 1. **Never commit or push directly to `staging` or `main`.** Both are protected integration branches. If you find yourself on one with uncommitted changes, stash them, switch to a feature branch, then pop the stash.
23
+ 2. **Never open a PR into `main`** unless the user has explicitly asked for a `staging → main` promotion. Default PR target is always `staging`.
24
+ 3. **Never force-push** (`--force`, `--force-with-lease`) without explicit user permission. If the remote rejects a push, stop and surface the error.
25
+ 4. **Never `git reset --hard`, `git clean -fd`, or delete branches** without confirming with the user — these destroy work.
26
+ 5. **Never skip hooks** (`--no-verify`, `--no-gpg-sign`). If a pre-commit hook fails, fix the underlying issue and re-commit.
27
+ 6. **Never amend a commit that has already been pushed** to a shared branch — create a new commit instead.
28
+
29
+ ## Step 1 — Preflight
30
+
31
+ Before touching files, confirm the starting state:
32
+
33
+ ```bash
34
+ git status # working tree should be clean
35
+ git rev-parse --abbrev-ref HEAD # what branch am I on?
36
+ git remote -v # confirm origin exists
37
+ ```
38
+
39
+ If the working tree is dirty with unrelated changes, stop and ask the user how to proceed (stash, commit elsewhere, discard). Do **not** sweep their in-progress work into your feature commit.
40
+
41
+ ## Step 2 — Sync `staging`
42
+
43
+ ```bash
44
+ git fetch origin
45
+ git switch staging
46
+ git pull --ff-only origin staging
47
+ ```
48
+
49
+ If `--ff-only` fails, `staging` has diverged locally — stop and ask the user how to reconcile rather than merging or rebasing autonomously.
50
+
51
+ ## Step 3 — Create the feature branch
52
+
53
+ ### Branch naming
54
+
55
+ | Kind | Pattern | Example |
56
+ |---|---|---|
57
+ | New feature | `feat/<ticket>-<slug>` | `feat/ABC-123-testimonial-carousel` |
58
+ | Bug fix | `fix/<ticket>-<slug>` | `fix/ABC-456-checkout-total` |
59
+ | Maintenance, deps, tooling | `chore/<slug>` | `chore/upgrade-phpcs` |
60
+ | Docs only | `docs/<slug>` | `docs/onboarding-guide` |
61
+
62
+ Rules:
63
+
64
+ - `<ticket>` is the issue / Asana / Linear ID when one exists. If there is no ticket, ask the user before omitting it — sometimes one needs to be created first.
65
+ - `<slug>` is lowercase kebab-case, ≤ 5 words, describing the change.
66
+ - One branch per logical change. If scope expands mid-flight, stop and ask whether to split.
67
+
68
+ ### Create and switch
69
+
70
+ ```bash
71
+ git switch -c feat/<ticket>-<slug>
72
+ ```
73
+
74
+ ## Step 4 — Develop and commit
75
+
76
+ ### Commit style: Conventional Commits
77
+
78
+ ```
79
+ <type>(<scope>): <subject>
80
+
81
+ <optional body — the *why*, links to ticket, anything non-obvious>
82
+ ```
83
+
84
+ - **Types:** `feat`, `fix`, `chore`, `refactor`, `docs`, `test`, `perf`, `build`, `ci`, `style`.
85
+ - **Subject:** imperative mood, no trailing period, ≤ 72 chars.
86
+ - **Scope:** short module name (e.g. `feat(blocks): …`, `fix(checkout): …`). Omit if it doesn't fit.
87
+
88
+ ### Commit hygiene
89
+
90
+ - Stage files explicitly (`git add path/to/file`) — avoid `git add -A` / `git add .` so secrets, generated files, and unrelated edits don't sneak in.
91
+ - Run the project's test / lint / build commands locally before pushing. CI must be green before review.
92
+ - Keep commits focused — one logical change per commit makes review and revert easier.
93
+
94
+ ## Step 5 — Push
95
+
96
+ ```bash
97
+ git push -u origin feat/<ticket>-<slug>
98
+ ```
99
+
100
+ If the remote already has a branch with the same name that you didn't create, stop and ask the user.
101
+
102
+ ## Step 6 — Open the PR
103
+
104
+ ```bash
105
+ gh pr create --base staging --head feat/<ticket>-<slug> \
106
+ --title "<conventional-commit-style title>" \
107
+ --body "<see body template below>"
108
+ ```
109
+
110
+ PR body template:
111
+
112
+ ```markdown
113
+ ## Summary
114
+ - <1–3 bullets — what changed>
115
+
116
+ ## Why
117
+ - <link the ticket; explain the motivation if non-obvious>
118
+
119
+ ## Test plan
120
+ - [ ] <how a reviewer can verify locally>
121
+ - [ ] <screenshots / Loom for visual or admin changes>
122
+
123
+ ## Notes
124
+ - <migrations, follow-ups, anything reviewers should know>
125
+ ```
126
+
127
+ After opening:
128
+
129
+ - Report the PR URL back to the user.
130
+ - If CI fails, surface the failing job output — do not silently re-run or rewrite history to mask the failure.
131
+
132
+ ## Step 7 — Respond to review
133
+
134
+ - Push new commits to address feedback; don't squash or rebase a pushed branch without asking.
135
+ - When the PR is approved and merged, the feature branch can be deleted on GitHub. Delete the local branch with `git branch -d <name>` (use `-d`, not `-D`, so git refuses if anything is unmerged).
136
+
137
+ ## When to stop and ask the user
138
+
139
+ - The base branch isn't actually called `staging` (the repo uses `develop`, `dev`, `trunk`, etc.). Confirm before proceeding.
140
+ - The working tree starts dirty with unrelated changes.
141
+ - A pull / push / merge fails for any reason.
142
+ - The scope of the change grows beyond what the original branch name implies.
143
+ - You're about to do anything destructive (`reset --hard`, `clean -fd`, branch deletion, force push).
144
+ - The task seems to require committing to `staging` or `main` directly — there is almost always a better path.
@@ -0,0 +1,93 @@
1
+ ---
2
+ name: nextjs-dev
3
+ description: Work safely inside an existing Next.js app: locate the app, run dev/build/lint checks, and diagnose common App Router issues.
4
+ pattern: procedure
5
+ when_to_use: /refact nextjs dev | run the Next.js app | fix Next.js bug | update a Next.js route, component, server action, or API endpoint.
6
+ when_not_to_use: Creating or adopting a new app (use setup-nextjs-app), or deployment setup (use setup-vercel-deploy).
7
+ next_skills: []
8
+ sub_agents: []
9
+ ---
10
+
11
+ # Next.js Development Reference
12
+
13
+ Use this reference for day-to-day development work in an existing Next.js app.
14
+
15
+ ## Goal
16
+
17
+ Keep agents grounded in the target app's actual conventions: App Router versus Pages Router, package manager, component library, environment variables, and available checks.
18
+
19
+ ## Preflight
20
+
21
+ 1. Identify the target app:
22
+ - If the user named a path, use it.
23
+ - Otherwise look for `apps/*/next.config.*` or `apps/*/package.json` with a `next` dependency.
24
+ - If multiple apps match, ask which one to use.
25
+ 2. Read the app's local `AGENTS.md` if present, then the root `agent/AGENTS.md`.
26
+ 3. Detect package manager from lockfiles, preferring the closest lockfile to the app.
27
+ 4. Read `package.json` scripts before running commands. Do not assume `lint`, `typecheck`, `test`, or `build` exists.
28
+ 5. Check for framework shape:
29
+ - `app/` or `src/app/` means App Router.
30
+ - `pages/` or `src/pages/` means Pages Router.
31
+ - Mixed router apps require extra care; preserve the existing boundary.
32
+
33
+ ## Development flow
34
+
35
+ 1. Reproduce or understand the requested behavior before editing when practical.
36
+ 2. Make the smallest app-local change that fits the existing structure.
37
+ 3. Preserve server/client boundaries:
38
+ - Add `"use client"` only when the component needs browser-only state, effects, event handlers, or client APIs.
39
+ - Keep data fetching, secrets, filesystem access, and privileged SDK calls server-side.
40
+ - Do not pass non-serializable values from Server Components into Client Components.
41
+ 4. Keep route handlers and Server Actions explicit about runtime assumptions. Do not move code to Edge runtime unless the dependencies are Edge-safe.
42
+ 5. Use the project's existing styling system. Do not introduce Tailwind, shadcn/ui, CSS-in-JS, or a component library unless the project already uses it or the user asks.
43
+ 6. If environment variables are needed, update `.env.example` or docs with names only. Never write real secret values.
44
+
45
+ ## Common checks
46
+
47
+ Run the smallest relevant checks available in `package.json`:
48
+
49
+ ```bash
50
+ npm run lint
51
+ npm run typecheck
52
+ npm test
53
+ npm run build
54
+ ```
55
+
56
+ Use the actual package manager. For narrowly scoped component edits, lint/typecheck may be enough. For routing, metadata, server actions, middleware/proxy, or config changes, prefer a production build if available.
57
+
58
+ ## Local dev server
59
+
60
+ Before starting a dev server:
61
+
62
+ 1. Check whether one is already running in the IDE terminals.
63
+ 2. Use the app's existing dev script.
64
+ 3. If the default port is occupied, surface the conflict and ask before changing ports.
65
+
66
+ Typical command:
67
+
68
+ ```bash
69
+ npm run dev
70
+ ```
71
+
72
+ ## Debugging checklist
73
+
74
+ - Hydration mismatch: check time/random values, browser-only APIs, conditional rendering by viewport, and inconsistent server/client data.
75
+ - Server/Client Component error: remove unnecessary `"use client"` or split the interactive leaf into a client component.
76
+ - Route not found: verify segment folder names, dynamic segment syntax, route groups, parallel routes, and whether the app uses `src/`.
77
+ - Metadata issue: check `metadata`, `generateMetadata`, and whether the route is static or dynamic.
78
+ - API/route handler issue: check method exports, returned `Response`, runtime dependencies, and auth/env availability.
79
+ - Build-only failure: run the production build and fix the first real error rather than chasing dev overlay noise.
80
+
81
+ ## Guardrails
82
+
83
+ - Never commit `.env*` files with real values.
84
+ - Never disable TypeScript, ESLint, auth, or validation to make a build pass.
85
+ - Never add `"use client"` at a high layout boundary without a reason; it can pull too much of the tree client-side.
86
+ - Never edit generated framework output (`.next/`, `out/`, coverage, cache folders).
87
+ - Never assume Vercel deployment unless `vercel.json`, `.vercel/`, project docs, or the user says so.
88
+
89
+ ## When to stop and ask
90
+
91
+ - Multiple matching apps exist and the user did not name one.
92
+ - A fix requires changing the routing strategy, auth provider, database client, or deployment runtime.
93
+ - Existing checks are absent or failing before your change and the failure affects confidence in the work.
@@ -0,0 +1,143 @@
1
+ ---
2
+ name: setup-netlify-deploy
3
+ description: Link a Next.js app to Netlify and document deployment settings without assuming every Next.js project deploys to Netlify.
4
+ pattern: procedure
5
+ requires_approval: true
6
+ when_to_use: /refact setup netlify deploy | deploy Next.js to Netlify | link this Next.js app to Netlify | configure Netlify for this app.
7
+ when_not_to_use: Non-Netlify hosting, local-only development, or generic Next.js code changes.
8
+ next_skills:
9
+ - nextjs-dev
10
+ sub_agents: []
11
+ ---
12
+
13
+ # Netlify Deploy Setup Reference
14
+
15
+ Use this reference when the user explicitly wants a Next.js app linked or configured for Netlify. Do not run this automatically for every Next.js project.
16
+
17
+ ## Goal
18
+
19
+ Set up Netlify deployment metadata and verification while keeping hosting choices explicit. This skill may call external services, create project links, and change deploy settings, so it requires user approval before writes.
20
+
21
+ ## Preflight
22
+
23
+ 1. Confirm the target app path. If multiple Next.js apps exist, ask which app to deploy.
24
+ 2. Confirm Netlify is the intended hosting provider.
25
+ 3. Check whether the Netlify CLI exists:
26
+
27
+ ```bash
28
+ netlify --version
29
+ ```
30
+
31
+ If missing, ask before installing it. Prefer `npx netlify-cli` for one-off setup unless the user wants a global CLI.
32
+
33
+ 4. Check authentication:
34
+
35
+ ```bash
36
+ netlify status
37
+ ```
38
+
39
+ If unauthenticated, stop and ask the user to run `netlify login`. Do not handle credentials or tokens in chat.
40
+
41
+ 5. Inspect existing Netlify state:
42
+ - `.netlify/state.json` means the app or repo may already be linked.
43
+ - `netlify.toml` may define build base, command, publish directory, redirects, headers, functions, or plugins.
44
+ - Existing GitHub workflows may already deploy the app.
45
+
46
+ ## Link flow
47
+
48
+ 1. From the target app directory, run one of:
49
+
50
+ ```bash
51
+ netlify init
52
+ netlify link
53
+ ```
54
+
55
+ Use `init` for a new Netlify site and `link` for an existing Netlify site.
56
+
57
+ 2. If the repo is a monorepo, make sure Netlify's base directory points at the app directory (`apps/<app-name>`) unless the repo intentionally builds from root.
58
+ 3. Do not commit `.netlify/` unless the team intentionally tracks Netlify project metadata. If unsure, ask. Many teams keep it local and document the site name/id instead.
59
+ 4. Record hosting (`netlify`) and each environment's `branch` + `url` (production and staging) in `.refact-os.json` › `stack.nextjs` when stable. Keep app-specific build details (team, site name, app root, build command, publish directory) in `apps/<app-name>/docs/deploy.md`.
60
+
61
+ ## Build settings
62
+
63
+ Prefer Netlify's Next.js detection when it works. Only add or edit `netlify.toml` when the repo needs explicit settings, such as a monorepo app root or custom redirects.
64
+
65
+ Typical app-local settings when `netlify.toml` lives inside `apps/<app-name>/`:
66
+
67
+ ```toml
68
+ [build]
69
+ command = "npm run build"
70
+ publish = ".next"
71
+ ```
72
+
73
+ Typical root-level monorepo settings:
74
+
75
+ ```toml
76
+ [build]
77
+ base = "apps/<app-name>"
78
+ command = "npm run build"
79
+ publish = "apps/<app-name>/.next"
80
+ ```
81
+
82
+ Use the actual package manager command. If the project already has a `netlify.toml`, read it first and preserve unrelated settings.
83
+
84
+ ## Environment variables
85
+
86
+ 1. List required variable names from docs, `.env.example`, and code references.
87
+ 2. Inspect Netlify env var names only with explicit user approval:
88
+
89
+ ```bash
90
+ netlify env:list
91
+ ```
92
+
93
+ 3. Never paste secret values into files, chat, logs, or docs. Document names and purpose only.
94
+ 4. Keep local `.env.local` uncommitted.
95
+
96
+ ## Verification
97
+
98
+ Prefer local production checks before deploying:
99
+
100
+ ```bash
101
+ npm run build
102
+ netlify build
103
+ ```
104
+
105
+ Use the app's actual package manager. If `netlify build` fails because the project is not linked or env vars are missing, surface the missing piece rather than guessing.
106
+
107
+ For a draft deploy, confirm with the user, then run:
108
+
109
+ ```bash
110
+ netlify deploy
111
+ ```
112
+
113
+ For production promotion, require explicit approval:
114
+
115
+ ```bash
116
+ netlify deploy --prod
117
+ ```
118
+
119
+ ## Git integration
120
+
121
+ If Netlify Git integration is enabled, prefer PR/branch deploys over ad-hoc CLI production deploys. Document:
122
+
123
+ - Production branch.
124
+ - Branch deploy behavior.
125
+ - Deploy previews.
126
+ - Monorepo base directory.
127
+ - Required Netlify environment variables.
128
+
129
+ ## Guardrails
130
+
131
+ - Never assume Netlify just because the app is Next.js.
132
+ - Never deploy to production without explicit user approval.
133
+ - Never print, commit, or store secret values.
134
+ - Never change DNS, domains, production branch, build image, or team ownership without confirmation.
135
+ - Never overwrite existing `netlify.toml` or CI workflows without reading them and explaining the change.
136
+ - Never add Next.js runtime/plugin config blindly; use the current project settings and Netlify detection unless a build error proves explicit config is needed.
137
+
138
+ ## When to stop and ask
139
+
140
+ - The app is already linked to a different Netlify site than the user named.
141
+ - The repo root and Netlify base directory disagree.
142
+ - Required environment variables are unknown or missing.
143
+ - The user asks to promote a deploy to production or change domain settings.