agentscamp 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.
Files changed (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -0
  3. package/content/agents/accessibility-auditor.md +66 -0
  4. package/content/agents/agent-architect.md +65 -0
  5. package/content/agents/agent-reliability-reviewer.md +40 -0
  6. package/content/agents/agent-tool-integration-engineer.md +38 -0
  7. package/content/agents/api-architect.md +84 -0
  8. package/content/agents/backend-developer.md +92 -0
  9. package/content/agents/browser-agent-engineer.md +37 -0
  10. package/content/agents/cloud-architect.md +72 -0
  11. package/content/agents/code-reviewer.md +69 -0
  12. package/content/agents/data-engineer.md +67 -0
  13. package/content/agents/data-scientist.md +79 -0
  14. package/content/agents/debugger.md +89 -0
  15. package/content/agents/dependency-manager.md +64 -0
  16. package/content/agents/devops-engineer.md +94 -0
  17. package/content/agents/documentation-engineer.md +52 -0
  18. package/content/agents/finetuning-engineer.md +43 -0
  19. package/content/agents/frontend-developer.md +78 -0
  20. package/content/agents/git-github-expert.md +66 -0
  21. package/content/agents/golang-pro.md +72 -0
  22. package/content/agents/graphql-architect.md +85 -0
  23. package/content/agents/kubernetes-specialist.md +87 -0
  24. package/content/agents/llm-cost-optimizer.md +39 -0
  25. package/content/agents/llm-evaluation-engineer.md +42 -0
  26. package/content/agents/llm-inference-engineer.md +42 -0
  27. package/content/agents/llm-integration-engineer.md +39 -0
  28. package/content/agents/llm-observability-engineer.md +41 -0
  29. package/content/agents/mcp-server-engineer.md +43 -0
  30. package/content/agents/ml-engineer.md +67 -0
  31. package/content/agents/mobile-developer.md +89 -0
  32. package/content/agents/performance-engineer.md +79 -0
  33. package/content/agents/postgres-migration-engineer.md +42 -0
  34. package/content/agents/prompt-engineer.md +58 -0
  35. package/content/agents/prompt-injection-auditor.md +42 -0
  36. package/content/agents/python-pro.md +77 -0
  37. package/content/agents/rag-pipeline-engineer.md +42 -0
  38. package/content/agents/react-specialist.md +83 -0
  39. package/content/agents/refactoring-specialist.md +78 -0
  40. package/content/agents/retrieval-engineer.md +41 -0
  41. package/content/agents/rust-pro.md +89 -0
  42. package/content/agents/security-auditor.md +78 -0
  43. package/content/agents/sql-pro.md +53 -0
  44. package/content/agents/sre-engineer.md +66 -0
  45. package/content/agents/system-architect.md +77 -0
  46. package/content/agents/terraform-specialist.md +73 -0
  47. package/content/agents/test-engineer.md +79 -0
  48. package/content/agents/typescript-pro.md +82 -0
  49. package/content/agents/vector-search-engineer.md +43 -0
  50. package/content/agents/voice-agent-engineer.md +38 -0
  51. package/content/agents/workflow-orchestrator.md +70 -0
  52. package/content/commands/add-docstrings.md +92 -0
  53. package/content/commands/add-human-approval.md +40 -0
  54. package/content/commands/add-mcp-server.md +50 -0
  55. package/content/commands/add-streaming-endpoint.md +34 -0
  56. package/content/commands/benchmark-rerankers.md +44 -0
  57. package/content/commands/breakdown-task.md +86 -0
  58. package/content/commands/commit.md +117 -0
  59. package/content/commands/create-pr.md +109 -0
  60. package/content/commands/db-migrate.md +47 -0
  61. package/content/commands/explain-code.md +71 -0
  62. package/content/commands/explain-error.md +98 -0
  63. package/content/commands/extract-function.md +107 -0
  64. package/content/commands/find-bug.md +93 -0
  65. package/content/commands/fix-failing-test.md +106 -0
  66. package/content/commands/new-component.md +119 -0
  67. package/content/commands/plan-feature.md +71 -0
  68. package/content/commands/profile-postgres-queries.md +41 -0
  69. package/content/commands/red-team-llm.md +45 -0
  70. package/content/commands/refactor.md +82 -0
  71. package/content/commands/review-pr.md +101 -0
  72. package/content/commands/run-evals.md +34 -0
  73. package/content/commands/scaffold-pgvector-schema.md +42 -0
  74. package/content/commands/scaffold-vllm-config.md +44 -0
  75. package/content/commands/security-scan.md +129 -0
  76. package/content/commands/set-perf-budget.md +47 -0
  77. package/content/commands/setup-claude-ci.md +60 -0
  78. package/content/commands/sync-branch.md +138 -0
  79. package/content/commands/update-readme.md +108 -0
  80. package/content/commands/write-tests.md +81 -0
  81. package/content/manifest.json +1709 -0
  82. package/content/skills/adr-writer.md +90 -0
  83. package/content/skills/branch-rebaser.md +86 -0
  84. package/content/skills/bundle-analyzer.md +77 -0
  85. package/content/skills/changelog-from-prs.md +81 -0
  86. package/content/skills/chunking-strategy-optimizer.md +34 -0
  87. package/content/skills/claude-settings-auditor.md +38 -0
  88. package/content/skills/conventional-commits.md +80 -0
  89. package/content/skills/coverage-gap-finder.md +72 -0
  90. package/content/skills/dead-code-finder.md +65 -0
  91. package/content/skills/dependency-audit.md +64 -0
  92. package/content/skills/embedding-index-tuner.md +34 -0
  93. package/content/skills/embedding-set-inspector.md +34 -0
  94. package/content/skills/finetune-dataset-builder.md +33 -0
  95. package/content/skills/graphrag-scaffolder.md +39 -0
  96. package/content/skills/hook-writer.md +39 -0
  97. package/content/skills/human-in-the-loop-gate.md +33 -0
  98. package/content/skills/llm-as-judge-scorer.md +33 -0
  99. package/content/skills/llm-eval-suite-scaffolder.md +30 -0
  100. package/content/skills/llm-guardrails-designer.md +33 -0
  101. package/content/skills/llm-output-schema-generator.md +32 -0
  102. package/content/skills/mcp-server-scaffolder.md +33 -0
  103. package/content/skills/mock-data-factory.md +75 -0
  104. package/content/skills/multimodal-document-extractor.md +39 -0
  105. package/content/skills/openapi-doc-writer.md +88 -0
  106. package/content/skills/plugin-scaffolder.md +38 -0
  107. package/content/skills/postgres-index-strategist.md +38 -0
  108. package/content/skills/pr-description.md +87 -0
  109. package/content/skills/prompt-cache-optimizer.md +34 -0
  110. package/content/skills/prompt-optimizer.md +40 -0
  111. package/content/skills/prompt-pii-redactor.md +33 -0
  112. package/content/skills/provider-fallback-wrapper.md +33 -0
  113. package/content/skills/qlora-finetune-runner.md +33 -0
  114. package/content/skills/readme-generator.md +84 -0
  115. package/content/skills/secret-scanner.md +65 -0
  116. package/content/skills/sql-optimizer.md +77 -0
  117. package/content/skills/test-scaffolder.md +74 -0
  118. package/content/skills/tool-definition-generator.md +33 -0
  119. package/content/skills/web-research-pipeline.md +39 -0
  120. package/dist/index.js +384 -0
  121. package/package.json +44 -0
@@ -0,0 +1,44 @@
1
+ ---
2
+ description: "Measure whether adding a reranker actually improves retrieval, by scoring reranked vs. un-reranked results on a labeled query set."
3
+ argument-hint: "<path to eval set / retrieval results, or a description of the pipeline>"
4
+ allowed-tools: "Read, Grep, Glob, Bash"
5
+ model: sonnet
6
+ ---
7
+
8
+ ## Scope
9
+
10
+ Treat `$ARGUMENTS` as the retrieval setup to benchmark — a path to an eval set and retrieval results, or a description of the pipeline (retriever, candidate count, reranker). Restate what you're comparing in one sentence before running.
11
+
12
+ Goal: quantify the lift a **reranker** adds over first-stage retrieval, so the decision to ship it (and pay its latency/cost) is measured, not assumed.
13
+
14
+ > [!NOTE]
15
+ > A reranker reorders candidates the retriever already found — it cannot recover an answer that first-stage retrieval missed. So always over-retrieve (top-25–50) before reranking, and measure recall at the **first stage** too.
16
+
17
+ ## Step 1 — Establish the eval set
18
+
19
+ Use a labeled set of queries with known-relevant passages (gold spans). If none exists, say so and help build a small one (20–50 queries) before benchmarking — a benchmark without ground truth is theater.
20
+
21
+ ## Step 2 — Produce two result sets
22
+
23
+ For each query, capture the **top-k before reranking** (raw retriever order) and the **top-k after reranking** (e.g. via [Cohere Rerank](/tools/cohere-rerank) or another cross-encoder), over the same candidate pool.
24
+
25
+ ## Step 3 — Score both
26
+
27
+ Compute, for k ∈ {3, 5, 10}:
28
+
29
+ - **recall@k** — fraction of queries with a gold passage in the top-k.
30
+ - **nDCG@k** — rank-aware quality (rewards putting the right passage higher).
31
+ - **MRR** — mean reciprocal rank of the first gold passage.
32
+
33
+ Report a side-by-side table: metric | retriever-only | + reranker | delta.
34
+
35
+ ## Step 4 — Weigh the cost
36
+
37
+ State the added **per-query latency** and **cost** of the rerank call. Reranking only the top candidates keeps both modest, but make the trade-off explicit.
38
+
39
+ ## Step 5 — Recommend
40
+
41
+ Give a clear verdict: ship the reranker, skip it, or change candidate depth / rerank model. Justify it from the numbers — e.g. "+0.14 nDCG@5 for +90ms is worth it" or "negligible lift, not worth the latency here."
42
+
43
+ > [!WARNING]
44
+ > Don't tune the reranker against the same handful of queries you eyeball. Use the frozen eval set, and report all metrics, not just the one that improved.
@@ -0,0 +1,86 @@
1
+ ---
2
+ description: "Decompose a task into an ordered checklist of small, verifiable steps."
3
+ argument-hint: "<task>"
4
+ allowed-tools: "Read, Grep, Glob"
5
+ ---
6
+
7
+ Break the task in `$ARGUMENTS` into the smallest sensible, dependency-ordered steps and return them as a Markdown checklist. This is a planning pass only — read the code to ground the plan, but do not edit, run, or create any files.
8
+
9
+ ## Scope
10
+
11
+ Treat `$ARGUMENTS` as the task to decompose — a feature request, a bug, a refactor, or a migration ("add rate limiting to the login route", "split the `Invoice` model into separate billing tables"). If it names files, paths, or symbols, those are your starting points for investigation.
12
+
13
+ If `$ARGUMENTS` is empty, do not guess. Ask the user what task they want broken down, and stop until they answer.
14
+
15
+ ## Step 1 — Ground the task in the code
16
+
17
+ Read enough of the repo to plan against reality, not assumptions. Find the files the task touches and the seams it crosses before you split anything.
18
+
19
+ ```bash
20
+ # Locate the symbols, routes, or modules named in the task
21
+ grep -rn "loginHandler" src/
22
+
23
+ # Map the surrounding structure
24
+ find src -path '*auth*' -name '*.ts'
25
+ ```
26
+
27
+ Open the entry points and trace one level of callers and callees. Note existing tests, types, and config that the change will ripple into.
28
+
29
+ > [!NOTE]
30
+ > If the task as written is ambiguous or hides a decision (which library? sync or async? backward-compatible?), surface that as an open question in the output instead of silently picking one. A plan built on a wrong assumption wastes the whole execution pass.
31
+
32
+ ## Step 2 — Split into the smallest sensible steps
33
+
34
+ Cut the work into steps that are each independently verifiable and small enough to land as one focused commit. A good step changes one thing and can be checked on its own.
35
+
36
+ Aim for steps that are:
37
+
38
+ - **Atomic** — one concern each (add the schema; *then* wire the endpoint; *then* the test).
39
+ - **Verifiable** — you can state a concrete check that proves it is done.
40
+ - **Reversible** — a step that turns out wrong can be redone without unwinding the others.
41
+
42
+ Avoid two failure modes: steps so coarse they hide three decisions, and steps so fine they fragment a single edit across five lines.
43
+
44
+ > [!TIP]
45
+ > Lead with the steps that de-risk the work — the unknown, the spike, the schema or interface everything else depends on. Settled, mechanical steps come last.
46
+
47
+ ## Step 3 — Order by dependency and mark parallelism
48
+
49
+ Sort the steps so each one only depends on steps above it. For every step, record what it needs and whether anything blocks it.
50
+
51
+ Then mark which steps are independent and can run in parallel — steps that share no inputs and touch no common files. Group them so the executor (or multiple agents) can fan them out.
52
+
53
+ ```text
54
+ 1. Define rate-limit config + types (no deps)
55
+ 2. Add Redis-backed counter store (depends on 1)
56
+ 3. Wire middleware into login route (depends on 2)
57
+ 4. Update API docs (depends on 1) [parallel with 2–3]
58
+ 5. Add tests for limit + reset window (depends on 3)
59
+ ```
60
+
61
+ > [!WARNING]
62
+ > Two steps are only safe to parallelize if they do not edit the same files and neither reads the other's output. When in doubt, serialize — a false "parallel" tag causes merge conflicts and rework that costs more than the time saved.
63
+
64
+ ## Step 4 — Define done for each step and overall
65
+
66
+ Give every step a one-line **definition of done** — a concrete, checkable condition, not a restatement of the step ("tests pass for the reset window", not "tests are done"). Then write one overall definition of done for the whole task: the observable end state that means the work is complete.
67
+
68
+ ## Output format
69
+
70
+ Return a single Markdown checklist. Number the steps in execution order, tag parallel-eligible ones, and end each with its definition of done.
71
+
72
+ ```markdown
73
+ ## Plan — <task>
74
+
75
+ - [ ] **1. Define rate-limit config + types** — _done when_ `RateLimitConfig` exists and is imported by the middleware.
76
+ - [ ] **2. Add Redis-backed counter store** — _done when_ `increment`/`reset` are covered by unit tests.
77
+ - [ ] **3. Wire middleware into login route** — _done when_ a 6th request in the window returns `429`.
78
+ - [ ] **4. Update API docs** _(parallel with 2–3)_ — _done when_ the docs describe the limit, window, and reset header.
79
+ - [ ] **5. Add tests for limit + reset window** — _done when_ `npm test` passes for the new cases.
80
+
81
+ **Definition of done (overall):** Login enforces N requests/window per IP, returns `429` with a reset header past the limit, and is documented and tested.
82
+
83
+ **Open questions:** <anything that needs a decision before step 1 — or "none">
84
+ ```
85
+
86
+ Keep the plan tight: enough steps to be unambiguous, never so many that the checklist becomes noise. Do not begin executing — hand the checklist back to the user.
@@ -0,0 +1,117 @@
1
+ ---
2
+ description: "Stage changes and write a Conventional Commits message describing them."
3
+ ---
4
+
5
+ Create a well-formed git commit for the current changes. Follow the steps below exactly, and only commit what the user intends.
6
+
7
+ ## Scope
8
+
9
+ If `$ARGUMENTS` is provided, treat it as guidance for what to commit — for example specific paths to stage (`src/lib/auth.ts`), a hint about the change type (`fix`, `feat`), or a short description of intent. If `$ARGUMENTS` is empty, infer everything from the working tree.
10
+
11
+ ## Step 1 — Inspect the working tree
12
+
13
+ Run these in parallel and read the output before doing anything else.
14
+
15
+ ```bash
16
+ git status
17
+ git diff
18
+ git diff --staged
19
+ git log --oneline -10
20
+ ```
21
+
22
+ - `git status` shows what is staged, unstaged, and untracked.
23
+ - `git diff` / `git diff --staged` reveal the actual content of the changes — read these to understand what happened, not just file names.
24
+ - `git log --oneline -10` shows the repository's existing message style. Match its tone and format where it does not conflict with the rules below.
25
+
26
+ ## Step 2 — Stage the right files
27
+
28
+ Stage only files that belong in this commit.
29
+
30
+ ```bash
31
+ # Stage specific paths derived from $ARGUMENTS or your analysis
32
+ git add src/lib/auth.ts src/lib/session.ts
33
+
34
+ # Or stage everything when all changes are part of one logical unit
35
+ git add -A
36
+ ```
37
+
38
+ > [!WARNING]
39
+ > Do not blindly `git add -A` if the diff mixes unrelated work. Split unrelated changes into separate commits so history stays reviewable.
40
+
41
+ > [!NOTE]
42
+ > Never stage secrets, credentials, `.env` files, large build artifacts, or local-only config. If you see any in `git status`, stop and flag them to the user instead of committing.
43
+
44
+ ## Step 3 — Write the message
45
+
46
+ Write a [Conventional Commits](https://www.conventionalcommits.org/) message:
47
+
48
+ ```
49
+ <type>(<optional scope>): <short summary>
50
+
51
+ <optional body explaining what and why>
52
+
53
+ <optional footer: BREAKING CHANGE / issue refs>
54
+ ```
55
+
56
+ ### Rules for the subject line
57
+
58
+ - Use one of these `type` values:
59
+
60
+ | type | use for |
61
+ | --- | --- |
62
+ | `feat` | a new feature |
63
+ | `fix` | a bug fix |
64
+ | `docs` | documentation only |
65
+ | `style` | formatting, no logic change |
66
+ | `refactor` | code change that is neither a fix nor a feature |
67
+ | `perf` | performance improvement |
68
+ | `test` | adding or fixing tests |
69
+ | `build` | build system or dependencies |
70
+ | `ci` | CI configuration |
71
+ | `chore` | maintenance, tooling, misc |
72
+
73
+ - Keep the summary in the imperative mood ("add", not "added" or "adds").
74
+ - Lower-case the summary and omit the trailing period.
75
+ - Keep the subject line at or under 72 characters.
76
+
77
+ ### Rules for the body
78
+
79
+ - Add a body only when the change needs explanation. Wrap lines at ~72 characters.
80
+ - Explain the *why* and the user-facing or behavioral impact — the diff already shows the *how*.
81
+ - For a breaking change, add a `BREAKING CHANGE:` footer describing the migration.
82
+
83
+ ### Example
84
+
85
+ ```
86
+ feat(auth): add refresh-token rotation
87
+
88
+ Issue short-lived refresh tokens and rotate them on every use to
89
+ limit the blast radius of a leaked token. Old tokens are revoked
90
+ on rotation.
91
+
92
+ Closes #142
93
+ ```
94
+
95
+ ## Step 4 — Commit and verify
96
+
97
+ Use a HEREDOC so multi-line messages render correctly.
98
+
99
+ ```bash
100
+ git commit -m "$(cat <<'EOF'
101
+ feat(auth): add refresh-token rotation
102
+
103
+ Issue short-lived refresh tokens and rotate them on every use.
104
+
105
+ Closes #142
106
+ EOF
107
+ )"
108
+ ```
109
+
110
+ Then confirm the result:
111
+
112
+ ```bash
113
+ git status
114
+ git log -1 --stat
115
+ ```
116
+
117
+ Report the final commit hash and subject line. Do not push unless the user explicitly asks.
@@ -0,0 +1,109 @@
1
+ ---
2
+ description: "Push the current branch and open a GitHub pull request with a generated title and body."
3
+ argument-hint: "[base branch or notes]"
4
+ allowed-tools: "Bash"
5
+ ---
6
+
7
+ Open a GitHub pull request for the current branch. Follow the steps below exactly. Push the branch if needed, but do not merge, and confirm the base branch before you create anything.
8
+
9
+ ## Scope
10
+
11
+ If `$ARGUMENTS` is provided, treat it as the base branch to target (`develop`, `release/2.0`) and/or freeform notes to weave into the body — for example a hint about scope (`backend only`), an issue to close (`Closes #214`), or a reviewer to request. If `$ARGUMENTS` is empty, default the base to the repository's main branch and derive the entire title and body from the commits and diff.
12
+
13
+ ## Step 1 — Inspect the branch and confirm the base
14
+
15
+ Run these in parallel and read the output before doing anything else.
16
+
17
+ ```bash
18
+ # Current branch name and where HEAD sits relative to its upstream
19
+ git status -sb
20
+
21
+ # The repository's default branch (use as the base when none is given)
22
+ gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
23
+
24
+ # Commits unique to this branch, oldest first
25
+ git log <base>..HEAD --oneline
26
+
27
+ # The full diff against the base
28
+ git diff <base>...HEAD --stat
29
+ git diff <base>...HEAD
30
+ ```
31
+
32
+ Substitute the real base (`$ARGUMENTS` or the default branch) for `<base>`. The `...` (three-dot) range shows what this branch adds since it diverged, which is exactly what the PR will contain.
33
+
34
+ > [!NOTE]
35
+ > Confirm the base branch with the user before creating the PR. Targeting the wrong base (e.g. `main` instead of `develop`) is the most common and most disruptive mistake. If you defaulted to the repo's main branch, say so explicitly.
36
+
37
+ > [!WARNING]
38
+ > If `git log <base>..HEAD` is empty, the branch has no new commits and there is nothing to open a PR for. Stop and tell the user instead of creating an empty PR.
39
+
40
+ ## Step 2 — Ensure the branch is pushed
41
+
42
+ The remote must have your commits before a PR can reference them.
43
+
44
+ ```bash
45
+ # Push and set the upstream on first push; the branch name is inferred from HEAD
46
+ git push -u origin HEAD
47
+ ```
48
+
49
+ > [!WARNING]
50
+ > Only push the current feature branch. Never force-push (`--force`) a shared branch or push to `main`/`develop` directly. If `git status -sb` shows the branch is already up to date with its upstream, skip this step.
51
+
52
+ ## Step 3 — Derive the title and body
53
+
54
+ Read the commits and diff from Step 1, then synthesize the PR content. Do not just paste commit messages — describe the change as a whole.
55
+
56
+ **Title** — one concise, imperative line (matching the commit style), at or under ~72 characters. For a single-commit branch, the commit subject is usually a good title.
57
+
58
+ **Body** — fill in this structure, using your reading of the diff:
59
+
60
+ ```markdown
61
+ ## Summary
62
+ <1-3 sentences on what this PR does and why.>
63
+
64
+ ## Changes
65
+ - <key change, grouped by area or concern>
66
+ - <another notable change>
67
+
68
+ ## Testing
69
+ - <how it was verified: tests added/run, manual steps, or "not yet tested">
70
+
71
+ ## Risk
72
+ - <blast radius, migrations, rollback notes, or "low — isolated change">
73
+ ```
74
+
75
+ > [!WARNING]
76
+ > Do not include secrets, tokens, internal URLs, or customer data in the title or body — a PR description is public to everyone with repo access. Summarize sensitive context instead of pasting it.
77
+
78
+ ## Step 4 — Create the pull request
79
+
80
+ Pass the body via a HEREDOC so multi-line Markdown renders correctly.
81
+
82
+ ```bash
83
+ gh pr create \
84
+ --base "<base>" \
85
+ --head "$(git branch --show-current)" \
86
+ --title "<generated title>" \
87
+ --body "$(cat <<'EOF'
88
+ ## Summary
89
+ <1-3 sentences on what this PR does and why.>
90
+
91
+ ## Changes
92
+ - <key change, grouped by area or concern>
93
+ - <another notable change>
94
+
95
+ ## Testing
96
+ - <how it was verified: tests added/run, manual steps, or "not yet tested">
97
+
98
+ ## Risk
99
+ - <blast radius, migrations, rollback notes, or "low — isolated change">
100
+ EOF
101
+ )"
102
+ ```
103
+
104
+ > [!NOTE]
105
+ > Add `--draft` if the work is not ready for review, and `--reviewer <user>` or `--label <label>` when the user asks. Do not merge the PR — opening it is the end of this command.
106
+
107
+ ## Report
108
+
109
+ Print the URL that `gh pr create` returns, plus the resolved base branch and the number of commits included so the user can confirm the PR landed where they expected. If anything blocked creation (no commits, dirty tree, unconfirmed base), report that instead of forcing the PR open.
@@ -0,0 +1,47 @@
1
+ ---
2
+ description: "Generate and apply a database migration the safe way — using the project's migration tool, with expand-contract discipline for breaking changes, lock-free DDL, and a reversible up/down."
3
+ argument-hint: "<the schema change to make, or a path to a pending migration to review>"
4
+ allowed-tools: "Read, Grep, Glob, Bash, Edit"
5
+ model: sonnet
6
+ ---
7
+
8
+ ## Scope
9
+
10
+ Treat `$ARGUMENTS` as the schema change to make (e.g. "add a `status` column to `orders`", "rename `user.name` to `full_name`") or a path to a pending migration to review. Restate the change and whether it's **additive** (safe) or **breaking** (needs expand-contract) in one sentence before writing anything.
11
+
12
+ Goal: produce a migration that's **safe on a live database** — uses the project's migration tool, avoids long locks, and is reversible — not a hand-run `ALTER` that locks a hot table mid-deploy.
13
+
14
+ > [!NOTE]
15
+ > This command writes and applies a migration with safe-migration discipline. For a brand-new pgvector schema specifically, use [Scaffold a pgvector Schema](/commands/db/scaffold-pgvector-schema); for planning a large, multi-step breaking change end to end, hand off to the [postgres-migration-engineer](/agents/data-ai/postgres-migration-engineer).
16
+
17
+ ## Step 1 — Detect the migration tool
18
+
19
+ Find the project's migration framework (Prisma, Drizzle, Alembic, Flyway, golang-migrate, Rails, Knex, …) and match its file naming, format, and up/down conventions. Never hand-run DDL outside the tool that owns the schema. If [pgroll](/tools/pgroll) is in use, generate its JSON migration instead.
20
+
21
+ ## Step 2 — Classify the change
22
+
23
+ Decide if the change is **additive** (new nullable column, new table, new index — safe to apply directly) or **breaking** (rename, retype, `NOT NULL`, drop, new constraint on existing data). Breaking changes on a table with real data/traffic must be decomposed.
24
+
25
+ ## Step 3 — Decompose breaking changes (expand-contract)
26
+
27
+ For a breaking change, split it into separate, reversible migrations: **expand** (additive) → **backfill** (batched) → **dual-write** (app) → **migrate reads** (app) → **contract** (drop old, a later release). Don't collapse add and remove into one migration. See [Zero-Downtime Postgres Migrations](/guides/database/zero-downtime-postgres-migrations).
28
+
29
+ ## Step 4 — Use lock-free DDL
30
+
31
+ Substitute online operations for the ones that lock:
32
+
33
+ - `CREATE INDEX CONCURRENTLY` (not plain `CREATE INDEX`).
34
+ - `ADD CONSTRAINT … NOT VALID` then `VALIDATE CONSTRAINT` (not a constraint that scans under lock).
35
+ - Add columns nullable with a **constant** default (a volatile default rewrites the table).
36
+ - Batched, resumable backfills (never one giant `UPDATE`).
37
+
38
+ ## Step 5 — Make it reversible
39
+
40
+ Write the `down`/rollback for the migration (or confirm the tool generates a correct one). For expand-contract, ensure the old path survives until the contract step, so any phase can be rolled back without data loss.
41
+
42
+ ## Step 6 — Plan, apply, verify
43
+
44
+ Show the SQL the tool will run (a dry-run/plan where supported) and call out any statement that would take an `ACCESS EXCLUSIVE` lock. Apply it, then verify: the migration recorded, a `CONCURRENTLY`-built index is `VALID`, and the schema matches intent.
45
+
46
+ > [!WARNING]
47
+ > The migrations that cause outages take a long lock or rewrite a large table: a plain `CREATE INDEX`, `SET NOT NULL` directly, an `ALTER TYPE` rewrite, a volatile-default column add, or a single huge `UPDATE`. If the change implies any of these on a table with data, stop and decompose it before applying.
@@ -0,0 +1,71 @@
1
+ ---
2
+ description: "Explain what the given code does, in clear prose with a short summary."
3
+ argument-hint: "[file or symbol]"
4
+ ---
5
+
6
+ Explain the code identified by `$ARGUMENTS`. The argument may be a file path, a function or class name, a module, or a line range. Produce an explanation that a teammate could read once and understand without opening the source themselves.
7
+
8
+ ## Locate the target
9
+
10
+ Resolve `$ARGUMENTS` before explaining anything.
11
+
12
+ - If it is a path (e.g. `src/auth/session.ts`), read that file.
13
+ - If it is a symbol (e.g. `validateToken` or `class UserStore`), search the codebase to find its definition, then read the surrounding context.
14
+ - If it is a path with a range (e.g. `parser.go:40-120`), read those lines plus enough above and below to understand the scope.
15
+ - If it is ambiguous or matches multiple results, list the candidates and ask which one is meant. Do not guess.
16
+
17
+ > [!NOTE]
18
+ > Read the actual source before writing a single word of explanation. Never describe code from the name alone.
19
+
20
+ ## Understand before you write
21
+
22
+ Trace the behavior, not just the syntax. Before drafting, work out:
23
+
24
+ - The **purpose**: what problem this code solves and who calls it.
25
+ - The **inputs**: parameters, arguments, environment, or global state it reads.
26
+ - The **outputs**: return values, mutations, writes, network calls, or thrown errors.
27
+ - The **control flow**: branches, loops, early returns, and the happy path versus edge cases.
28
+ - The **dependencies**: other functions, modules, or services it relies on.
29
+ - Any **non-obvious details**: concurrency, caching, side effects, or subtle correctness concerns.
30
+
31
+ ## Output format
32
+
33
+ Structure the response with these sections.
34
+
35
+ ### Summary
36
+
37
+ Two or three sentences in plain language stating what the code does and why it exists. A reader should be able to stop here and have the gist.
38
+
39
+ ### How it works
40
+
41
+ Walk through the logic in execution order. Use prose for the narrative and a short list for distinct steps. Quote only the small, load-bearing fragments that matter — do not paste the whole file back.
42
+
43
+ ```text
44
+ 1. Receives <input> and validates <condition>.
45
+ 2. Transforms it via <step>.
46
+ 3. Returns <output> or raises <error> when <edge case>.
47
+ ```
48
+
49
+ ### Inputs and outputs
50
+
51
+ Be precise about types and contracts.
52
+
53
+ | Aspect | Detail |
54
+ | --- | --- |
55
+ | Inputs | parameters, types, expected shape |
56
+ | Returns | return type and meaning |
57
+ | Side effects | I/O, mutations, network, logging |
58
+ | Errors | what is thrown or returned on failure |
59
+
60
+ ### Edge cases and gotchas
61
+
62
+ Call out anything surprising: silent failure modes, off-by-one risks, assumptions about input, thread safety, or behavior that contradicts the function name.
63
+
64
+ ## Guidelines
65
+
66
+ - Match the explanation's depth to the code's complexity. A three-line helper needs a sentence; a state machine needs the full breakdown.
67
+ - Use the project's own terminology — variable and domain names as they appear in the source.
68
+ - Prefer correctness over completeness. If you are unsure how something behaves, say so explicitly rather than inventing an explanation.
69
+
70
+ > [!WARNING]
71
+ > Do not modify the code. This command only explains. If you spot a bug while reading, mention it in the gotchas section but make no edits.
@@ -0,0 +1,98 @@
1
+ ---
2
+ description: "Diagnose an error message or stack trace and propose a fix."
3
+ argument-hint: "<error message or stack trace>"
4
+ allowed-tools: "Read, Grep, Glob, Bash"
5
+ ---
6
+
7
+ Diagnose the error in `$ARGUMENTS` against this codebase and propose a specific fix. Your job is to explain *why* it happens and *how* to fix it — not to restate the message back. Do not change any files; report your findings and the recommended fix.
8
+
9
+ ## Scope
10
+
11
+ `$ARGUMENTS` is the raw error to diagnose — an exception message, a stack trace, a compiler/type error, or a chunk of failing log output. Parse it for the signal that matters:
12
+
13
+ - The **error type/class** and message (`TypeError`, `NullPointerException`, `ECONNREFUSED`, `error[E0382]`, ...).
14
+ - The **top in-repo frame** — the first stack frame pointing at a file *in this project*, not in `node_modules`, the standard library, or a vendored dependency. That frame is usually where the fix lives.
15
+ - Any **identifiers** in the message: variable names, function names, file paths, line numbers, error codes.
16
+
17
+ If `$ARGUMENTS` is empty, do not guess. Ask the user to paste the full error or stack trace, or point you at the failing command (e.g. `npm test`, `cargo build`) so you can reproduce it and capture the output yourself.
18
+
19
+ ## Step 1 — Locate the originating code
20
+
21
+ Find the exact line the error blames, then read enough around it to understand the context.
22
+
23
+ ```bash
24
+ # Jump to the file:line from the top in-repo stack frame
25
+ # e.g. "at src/lib/auth.ts:42" -> open that file around line 42
26
+ ```
27
+
28
+ When the trace is minified, transpiled, or points at a build artifact, search for the symbols in the message instead:
29
+
30
+ ```bash
31
+ # Find where the named function / variable / message string is defined
32
+ rg -n "functionFromTheTrace|the exact error string" src
33
+ ```
34
+
35
+ > [!NOTE]
36
+ > Trust the *first in-repo frame*, not the last frame. The deepest frame is often inside a library doing exactly what it was told — the bug is usually at the boundary where your code called it with bad input.
37
+
38
+ ## Step 2 — Identify the likely root cause
39
+
40
+ Explain in plain terms what actually went wrong, one level beneath the message. Map the error to its underlying condition rather than echoing the text:
41
+
42
+ | The message says | The real cause is usually |
43
+ | --- | --- |
44
+ | `Cannot read properties of undefined` | a value was never assigned, an async result wasn't awaited, or a lookup missed |
45
+ | `NullPointerException` / `nil` deref | an unchecked optional or a failed-but-ignored return |
46
+ | `ECONNREFUSED` / `connection refused` | wrong host/port, service not running, or env var unset |
47
+ | `Module not found` | missing dependency, bad import path, or stale build cache |
48
+ | type / borrow / lint error | a contract the compiler is enforcing — read it literally |
49
+
50
+ State the cause as a single clear sentence: *"`session` is `undefined` here because `getSession()` returns a Promise that the caller never awaits, so the `.user` access runs before it resolves."*
51
+
52
+ ## Step 3 — Confirm before you commit to an answer
53
+
54
+ When practical, verify the hypothesis instead of asserting it. Use read-only checks only.
55
+
56
+ ```bash
57
+ # Re-run the failing command to confirm the error and see the full trace
58
+ npm test 2>&1 | tail -40
59
+
60
+ # Inspect runtime conditions the trace implies (env, service, versions)
61
+ # prints key names only — omit `cut -d= -f1` if you need the values
62
+ printenv | cut -d= -f1 | rg -i 'DATABASE|API|PORT'
63
+ ```
64
+
65
+ > [!NOTE]
66
+ > Reproduce or confirm the cause with a read-only command whenever it's cheap to do so — a confirmed diagnosis beats a plausible one.
67
+
68
+ > [!WARNING]
69
+ > Stay read-only. Do not run migrations, installs, formatters, or anything that mutates the repo, the database, or remote state to "test" a theory. Confirm by reading and by re-running the same failing command, nothing more.
70
+
71
+ ## Step 4 — Report the diagnosis and fix
72
+
73
+ When the cause is clear, report it directly:
74
+
75
+ ```markdown
76
+ ## Error: <error type — one-line summary>
77
+
78
+ **Origin:** `path/to/file.ts:42` — <what this line was doing>
79
+
80
+ **Root cause:** <the plain-terms why, one level below the message>
81
+
82
+ **Fix:** <the specific change — code, not vibes>
83
+
84
+ - const user = getSession().user;
85
+ + const user = (await getSession()).user;
86
+
87
+ **Confidence:** High — reproduced via `npm test`; the trace points squarely here.
88
+ ```
89
+
90
+ When the cause is **ambiguous**, list the top candidates ranked by likelihood, each with the evidence for it and the one-line check that would confirm or rule it out:
91
+
92
+ ```markdown
93
+ **Most likely (≈70%):** <cause> — confirm with `<read-only check>`
94
+ **Possible (≈20%):** <cause> — confirm with `<read-only check>`
95
+ **Long shot (≈10%):** <cause> — confirm with `<read-only check>`
96
+ ```
97
+
98
+ End with the single highest-value next step: the fix to apply, or the one check that collapses the remaining ambiguity.