@mainahq/core 0.2.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/README.md +31 -0
- package/package.json +37 -0
- package/src/ai/__tests__/ai.test.ts +207 -0
- package/src/ai/__tests__/design-approaches.test.ts +192 -0
- package/src/ai/__tests__/spec-questions.test.ts +191 -0
- package/src/ai/__tests__/tiers.test.ts +110 -0
- package/src/ai/commit-msg.ts +28 -0
- package/src/ai/design-approaches.ts +76 -0
- package/src/ai/index.ts +205 -0
- package/src/ai/pr-summary.ts +60 -0
- package/src/ai/spec-questions.ts +74 -0
- package/src/ai/tiers.ts +52 -0
- package/src/ai/try-generate.ts +89 -0
- package/src/ai/validate.ts +66 -0
- package/src/benchmark/__tests__/reporter.test.ts +525 -0
- package/src/benchmark/__tests__/runner.test.ts +113 -0
- package/src/benchmark/__tests__/story-loader.test.ts +152 -0
- package/src/benchmark/reporter.ts +332 -0
- package/src/benchmark/runner.ts +91 -0
- package/src/benchmark/story-loader.ts +88 -0
- package/src/benchmark/types.ts +95 -0
- package/src/cache/__tests__/keys.test.ts +97 -0
- package/src/cache/__tests__/manager.test.ts +312 -0
- package/src/cache/__tests__/ttl.test.ts +94 -0
- package/src/cache/keys.ts +44 -0
- package/src/cache/manager.ts +231 -0
- package/src/cache/ttl.ts +77 -0
- package/src/config/__tests__/config.test.ts +376 -0
- package/src/config/index.ts +198 -0
- package/src/context/__tests__/budget.test.ts +179 -0
- package/src/context/__tests__/engine.test.ts +163 -0
- package/src/context/__tests__/episodic.test.ts +291 -0
- package/src/context/__tests__/relevance.test.ts +323 -0
- package/src/context/__tests__/retrieval.test.ts +143 -0
- package/src/context/__tests__/selector.test.ts +174 -0
- package/src/context/__tests__/semantic.test.ts +252 -0
- package/src/context/__tests__/treesitter.test.ts +229 -0
- package/src/context/__tests__/working.test.ts +236 -0
- package/src/context/budget.ts +130 -0
- package/src/context/engine.ts +394 -0
- package/src/context/episodic.ts +251 -0
- package/src/context/relevance.ts +325 -0
- package/src/context/retrieval.ts +325 -0
- package/src/context/selector.ts +93 -0
- package/src/context/semantic.ts +331 -0
- package/src/context/treesitter.ts +216 -0
- package/src/context/working.ts +192 -0
- package/src/db/__tests__/db.test.ts +151 -0
- package/src/db/index.ts +211 -0
- package/src/db/schema.ts +84 -0
- package/src/design/__tests__/design.test.ts +310 -0
- package/src/design/__tests__/generate-hld-lld.test.ts +109 -0
- package/src/design/__tests__/review.test.ts +561 -0
- package/src/design/index.ts +297 -0
- package/src/design/review.ts +327 -0
- package/src/explain/__tests__/explain.test.ts +173 -0
- package/src/explain/index.ts +181 -0
- package/src/features/__tests__/analyzer.test.ts +358 -0
- package/src/features/__tests__/checklist.test.ts +454 -0
- package/src/features/__tests__/numbering.test.ts +319 -0
- package/src/features/__tests__/quality.test.ts +295 -0
- package/src/features/__tests__/traceability.test.ts +147 -0
- package/src/features/analyzer.ts +445 -0
- package/src/features/checklist.ts +366 -0
- package/src/features/index.ts +18 -0
- package/src/features/numbering.ts +404 -0
- package/src/features/quality.ts +349 -0
- package/src/features/test-stubs.ts +157 -0
- package/src/features/traceability.ts +260 -0
- package/src/feedback/__tests__/async-feedback.test.ts +52 -0
- package/src/feedback/__tests__/collector.test.ts +219 -0
- package/src/feedback/__tests__/compress.test.ts +150 -0
- package/src/feedback/__tests__/preferences.test.ts +169 -0
- package/src/feedback/collector.ts +135 -0
- package/src/feedback/compress.ts +92 -0
- package/src/feedback/preferences.ts +108 -0
- package/src/git/__tests__/git.test.ts +62 -0
- package/src/git/index.ts +110 -0
- package/src/hooks/__tests__/runner.test.ts +266 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/runner.ts +130 -0
- package/src/index.ts +356 -0
- package/src/init/__tests__/init.test.ts +228 -0
- package/src/init/index.ts +364 -0
- package/src/language/__tests__/detect.test.ts +77 -0
- package/src/language/__tests__/profile.test.ts +51 -0
- package/src/language/detect.ts +70 -0
- package/src/language/profile.ts +110 -0
- package/src/prompts/__tests__/defaults.test.ts +52 -0
- package/src/prompts/__tests__/engine.test.ts +183 -0
- package/src/prompts/__tests__/evolution-resolve.test.ts +169 -0
- package/src/prompts/__tests__/evolution.test.ts +187 -0
- package/src/prompts/__tests__/loader.test.ts +105 -0
- package/src/prompts/candidates/review-v2.md +55 -0
- package/src/prompts/defaults/ai-review.md +49 -0
- package/src/prompts/defaults/commit.md +30 -0
- package/src/prompts/defaults/context.md +26 -0
- package/src/prompts/defaults/design-approaches.md +57 -0
- package/src/prompts/defaults/design-hld-lld.md +55 -0
- package/src/prompts/defaults/design.md +53 -0
- package/src/prompts/defaults/explain.md +31 -0
- package/src/prompts/defaults/fix.md +32 -0
- package/src/prompts/defaults/index.ts +38 -0
- package/src/prompts/defaults/review.md +41 -0
- package/src/prompts/defaults/spec-questions.md +59 -0
- package/src/prompts/defaults/tests.md +72 -0
- package/src/prompts/engine.ts +137 -0
- package/src/prompts/evolution.ts +409 -0
- package/src/prompts/loader.ts +71 -0
- package/src/review/__tests__/review.test.ts +288 -0
- package/src/review/comprehensive.ts +362 -0
- package/src/review/index.ts +417 -0
- package/src/stats/__tests__/tracker.test.ts +323 -0
- package/src/stats/index.ts +11 -0
- package/src/stats/tracker.ts +492 -0
- package/src/ticket/__tests__/ticket.test.ts +273 -0
- package/src/ticket/index.ts +185 -0
- package/src/utils.ts +87 -0
- package/src/verify/__tests__/ai-review.test.ts +242 -0
- package/src/verify/__tests__/coverage.test.ts +83 -0
- package/src/verify/__tests__/detect.test.ts +175 -0
- package/src/verify/__tests__/diff-filter.test.ts +338 -0
- package/src/verify/__tests__/fix.test.ts +478 -0
- package/src/verify/__tests__/linters/clippy.test.ts +45 -0
- package/src/verify/__tests__/linters/go-vet.test.ts +27 -0
- package/src/verify/__tests__/linters/ruff.test.ts +64 -0
- package/src/verify/__tests__/mutation.test.ts +141 -0
- package/src/verify/__tests__/pipeline.test.ts +553 -0
- package/src/verify/__tests__/proof.test.ts +97 -0
- package/src/verify/__tests__/secretlint.test.ts +190 -0
- package/src/verify/__tests__/semgrep.test.ts +217 -0
- package/src/verify/__tests__/slop.test.ts +366 -0
- package/src/verify/__tests__/sonar.test.ts +113 -0
- package/src/verify/__tests__/syntax-guard.test.ts +227 -0
- package/src/verify/__tests__/trivy.test.ts +191 -0
- package/src/verify/__tests__/visual.test.ts +139 -0
- package/src/verify/ai-review.ts +276 -0
- package/src/verify/coverage.ts +134 -0
- package/src/verify/detect.ts +171 -0
- package/src/verify/diff-filter.ts +183 -0
- package/src/verify/fix.ts +317 -0
- package/src/verify/linters/clippy.ts +52 -0
- package/src/verify/linters/go-vet.ts +32 -0
- package/src/verify/linters/ruff.ts +47 -0
- package/src/verify/mutation.ts +143 -0
- package/src/verify/pipeline.ts +328 -0
- package/src/verify/proof.ts +277 -0
- package/src/verify/secretlint.ts +168 -0
- package/src/verify/semgrep.ts +170 -0
- package/src/verify/slop.ts +493 -0
- package/src/verify/sonar.ts +146 -0
- package/src/verify/syntax-guard.ts +251 -0
- package/src/verify/trivy.ts +161 -0
- package/src/verify/visual.ts +460 -0
- package/src/workflow/__tests__/context.test.ts +110 -0
- package/src/workflow/context.ts +81 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
You are reviewing code changes in a {{language}} codebase.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
|
|
11
|
+
Review ONLY the added/modified lines (lines starting with '+').
|
|
12
|
+
|
|
13
|
+
### Priority 1 — Correctness
|
|
14
|
+
1. Security vulnerabilities (injection, XSS, auth bypass)
|
|
15
|
+
2. Business logic errors (wrong conditions, missing edge cases)
|
|
16
|
+
3. Missing error handling (unhandled promises, uncaught exceptions)
|
|
17
|
+
4. Violations of constitution or team conventions
|
|
18
|
+
|
|
19
|
+
### Priority 2 — Integration
|
|
20
|
+
5. Hardcoded paths or environment-specific values (must use process.cwd(), env vars, or config)
|
|
21
|
+
6. Framework conventions violated (e.g., Astro BASE_URL needs trailing slash, Starlight slug resolution)
|
|
22
|
+
7. CSS cascade/specificity issues (especially with third-party themes — check if overrides actually win)
|
|
23
|
+
8. Accessibility: color contrast ratios below WCAG AA (4.5:1 for normal text, 3:1 for large text)
|
|
24
|
+
|
|
25
|
+
### Priority 3 — Consistency
|
|
26
|
+
9. Dark mode: if light mode styles exist, dark mode must also be handled
|
|
27
|
+
10. Links: verify all internal hrefs resolve to actual pages (no 404s)
|
|
28
|
+
11. Assets: verify all src/href paths include correct base URL prefix
|
|
29
|
+
|
|
30
|
+
Do NOT comment on:
|
|
31
|
+
- Style issues (handled by Biome)
|
|
32
|
+
- Naming conventions (handled by linter)
|
|
33
|
+
- Minor refactoring suggestions
|
|
34
|
+
- Lock files (bun.lock, package-lock.json)
|
|
35
|
+
|
|
36
|
+
If anything is ambiguous, use [NEEDS CLARIFICATION: specific question] instead of guessing.
|
|
37
|
+
|
|
38
|
+
For each issue found, respond in this exact format:
|
|
39
|
+
```yaml
|
|
40
|
+
issues:
|
|
41
|
+
- file: "path/to/file.ts"
|
|
42
|
+
line: 42
|
|
43
|
+
severity: "critical|major|minor"
|
|
44
|
+
issue: "Brief description"
|
|
45
|
+
suggestion: "How to fix it"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
If no issues found:
|
|
49
|
+
```yaml
|
|
50
|
+
issues: []
|
|
51
|
+
summary: "No issues found."
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Diff to review
|
|
55
|
+
{{diff}}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
You are reviewing code changes for semantic issues that static analysis cannot catch.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Review Mode
|
|
7
|
+
{{reviewMode}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
|
|
11
|
+
Analyze the diff and referenced function bodies below. Report ONLY issues that are:
|
|
12
|
+
1. Cross-function consistency violations (caller passes wrong args, mismatched types, wrong order)
|
|
13
|
+
2. Missing edge cases (null/undefined not handled, empty arrays, boundary values)
|
|
14
|
+
3. Dead branches (conditions that can never be true given the data flow)
|
|
15
|
+
4. API contract violations (return type doesn't match declared interface, missing required fields)
|
|
16
|
+
|
|
17
|
+
{{#if specContext}}
|
|
18
|
+
Also check:
|
|
19
|
+
5. Spec compliance — does the implementation match the requirements in the spec?
|
|
20
|
+
6. Architecture — does the structure follow the design described in the plan?
|
|
21
|
+
7. Test coverage gaps — are there untested paths in the changed code?
|
|
22
|
+
{{/if}}
|
|
23
|
+
|
|
24
|
+
Severity rules:
|
|
25
|
+
- mechanical mode: ALL findings are "warning" severity (never "error")
|
|
26
|
+
- deep mode: findings may be "warning" or "error"
|
|
27
|
+
|
|
28
|
+
Respond in this exact JSON format (no markdown fences, no extra text):
|
|
29
|
+
{"findings":[{"file":"path","line":42,"message":"description","severity":"warning","ruleId":"ai-review/cross-function"}]}
|
|
30
|
+
|
|
31
|
+
Valid ruleIds: ai-review/cross-function, ai-review/edge-case, ai-review/dead-code, ai-review/contract, ai-review/spec-compliance, ai-review/architecture, ai-review/coverage-gap
|
|
32
|
+
|
|
33
|
+
If no issues found: {"findings":[]}
|
|
34
|
+
|
|
35
|
+
## Diff
|
|
36
|
+
{{diff}}
|
|
37
|
+
|
|
38
|
+
## Referenced Functions
|
|
39
|
+
{{referencedFunctions}}
|
|
40
|
+
|
|
41
|
+
{{#if specContext}}
|
|
42
|
+
## Spec
|
|
43
|
+
{{specContext}}
|
|
44
|
+
{{/if}}
|
|
45
|
+
|
|
46
|
+
{{#if planContext}}
|
|
47
|
+
## Plan
|
|
48
|
+
{{planContext}}
|
|
49
|
+
{{/if}}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
You are generating a conventional commit message from staged changes.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
Analyze the diff below and produce a single conventional commit message.
|
|
11
|
+
|
|
12
|
+
Rules:
|
|
13
|
+
- Format: `<type>(<scope>): <short description>`
|
|
14
|
+
- Types: feat, fix, refactor, test, docs, chore, ci, perf
|
|
15
|
+
- Scope: the package or module affected (e.g. core, cli, cache, prompts)
|
|
16
|
+
- Subject line: imperative mood, max 72 characters, no period at end
|
|
17
|
+
- Body (optional): explain WHY, not WHAT — include if the change is non-obvious
|
|
18
|
+
- Footer (optional): reference issues with `Closes #123` or `Refs #456`
|
|
19
|
+
|
|
20
|
+
Do NOT:
|
|
21
|
+
- Generate multiple commits for one diff
|
|
22
|
+
- Use vague messages like "fix stuff" or "updates"
|
|
23
|
+
- Include style-only changes as feat or fix
|
|
24
|
+
|
|
25
|
+
If the intent of the change is ambiguous, use [NEEDS CLARIFICATION: what is the business purpose of this change?] before generating.
|
|
26
|
+
|
|
27
|
+
Respond with ONLY the commit message, no explanation:
|
|
28
|
+
|
|
29
|
+
## Diff to commit
|
|
30
|
+
{{diff}}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
You are generating a focused context summary for an AI coding session.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
Given the raw context below (files, git log, recent changes), produce a concise summary that helps an AI assistant understand the current state of the codebase.
|
|
8
|
+
|
|
9
|
+
Output structure:
|
|
10
|
+
1. **Current task** — what is being worked on right now?
|
|
11
|
+
2. **Relevant files** — list the files most relevant to the task with one-line descriptions
|
|
12
|
+
3. **Recent changes** — summary of recent commits and what changed
|
|
13
|
+
4. **Dependencies** — key external dependencies and their versions relevant to the task
|
|
14
|
+
5. **Known issues** — open TODOs, failing tests, or known blockers
|
|
15
|
+
|
|
16
|
+
Rules:
|
|
17
|
+
- Keep the total output under {{budget}} tokens
|
|
18
|
+
- Prioritize information that changes frequently (recent commits, open issues) over stable facts
|
|
19
|
+
- Omit boilerplate files (lock files, generated code, config files) unless they are the focus
|
|
20
|
+
- Use bullet points, not prose paragraphs
|
|
21
|
+
- Include file paths relative to the repo root
|
|
22
|
+
|
|
23
|
+
If the task context is missing or ambiguous, use [NEEDS CLARIFICATION: what is the current task or goal?] before summarizing.
|
|
24
|
+
|
|
25
|
+
## Raw context
|
|
26
|
+
{{raw_context}}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
You are proposing architectural approaches for a design decision, with tradeoffs and a recommendation.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
|
|
11
|
+
Given the design context below, propose 2-3 distinct approaches to the architectural decision.
|
|
12
|
+
|
|
13
|
+
For each approach, provide:
|
|
14
|
+
1. **Name** — a short descriptive label (2-4 words)
|
|
15
|
+
2. **Description** — how this approach works (2-3 sentences)
|
|
16
|
+
3. **Pros** — concrete advantages (2-3 bullet points)
|
|
17
|
+
4. **Cons** — concrete disadvantages (2-3 bullet points)
|
|
18
|
+
5. **Recommendation** — boolean, true for at most one approach
|
|
19
|
+
|
|
20
|
+
Rules:
|
|
21
|
+
- Approaches must be genuinely different, not minor variations
|
|
22
|
+
- Pros and cons must be specific to this decision, not generic
|
|
23
|
+
- Exactly one approach should be recommended with reasoning
|
|
24
|
+
- Consider: complexity, performance, maintainability, alignment with existing architecture
|
|
25
|
+
- If the context is too vague to propose meaningful approaches, return an empty array
|
|
26
|
+
|
|
27
|
+
Output format: valid JSON array. Each approach object has:
|
|
28
|
+
- `name` (string): short label
|
|
29
|
+
- `description` (string): how it works
|
|
30
|
+
- `pros` (string[]): advantages
|
|
31
|
+
- `cons` (string[]): disadvantages
|
|
32
|
+
- `recommended` (boolean): true for the recommended approach
|
|
33
|
+
|
|
34
|
+
Example:
|
|
35
|
+
```json
|
|
36
|
+
[
|
|
37
|
+
{
|
|
38
|
+
"name": "Event-driven pipeline",
|
|
39
|
+
"description": "Each verification step emits events consumed by the next. Steps run independently and communicate through an event bus.",
|
|
40
|
+
"pros": ["Easy to add new steps", "Steps can run in parallel", "Clear separation of concerns"],
|
|
41
|
+
"cons": ["Harder to debug event flow", "Event ordering complexity", "More infrastructure code"],
|
|
42
|
+
"recommended": true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "Sequential middleware chain",
|
|
46
|
+
"description": "Steps are chained as middleware functions. Each step receives input, processes it, and passes to the next.",
|
|
47
|
+
"pros": ["Simple mental model", "Easy to debug", "Familiar pattern"],
|
|
48
|
+
"cons": ["Cannot parallelize", "Adding steps requires chain modification", "Tight coupling"],
|
|
49
|
+
"recommended": false
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Output ONLY the JSON array, no surrounding text or markdown fences.
|
|
55
|
+
|
|
56
|
+
## Design context
|
|
57
|
+
{{context}}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
You are generating High-Level Design (HLD) and Low-Level Design (LLD) sections for an Architecture Decision Record.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
|
|
8
|
+
Given the spec below, generate HLD and LLD sections in markdown. Use concrete details from the spec — never invent requirements.
|
|
9
|
+
|
|
10
|
+
For any section where the spec does not provide enough information, write `[NEEDS CLARIFICATION]` instead of guessing.
|
|
11
|
+
|
|
12
|
+
Output ONLY the markdown sections below (no preamble, no fences):
|
|
13
|
+
|
|
14
|
+
## High-Level Design
|
|
15
|
+
### System Overview
|
|
16
|
+
(2-3 sentences describing what this change does at a system level)
|
|
17
|
+
|
|
18
|
+
### Component Boundaries
|
|
19
|
+
(List each component/module affected and its responsibility)
|
|
20
|
+
|
|
21
|
+
### Data Flow
|
|
22
|
+
(Describe how data moves through the components)
|
|
23
|
+
|
|
24
|
+
### External Dependencies
|
|
25
|
+
(List any new dependencies, APIs, or services)
|
|
26
|
+
|
|
27
|
+
## Low-Level Design
|
|
28
|
+
### Interfaces & Types
|
|
29
|
+
(TypeScript interfaces and types to be created or modified)
|
|
30
|
+
|
|
31
|
+
### Function Signatures
|
|
32
|
+
(Key function signatures with parameter and return types)
|
|
33
|
+
|
|
34
|
+
### DB Schema Changes
|
|
35
|
+
(Any database table or column changes, or "None")
|
|
36
|
+
|
|
37
|
+
### Sequence of Operations
|
|
38
|
+
(Step-by-step order of operations for the main flow)
|
|
39
|
+
|
|
40
|
+
### Error Handling
|
|
41
|
+
(How errors are handled at each step)
|
|
42
|
+
|
|
43
|
+
### Edge Cases
|
|
44
|
+
(Known edge cases and how they are addressed)
|
|
45
|
+
|
|
46
|
+
## Spec
|
|
47
|
+
{{spec}}
|
|
48
|
+
|
|
49
|
+
## Project Conventions
|
|
50
|
+
{{conventions}}
|
|
51
|
+
|
|
52
|
+
{{#if context}}
|
|
53
|
+
## Codebase Context
|
|
54
|
+
{{context}}
|
|
55
|
+
{{/if}}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
You are scaffolding an Architecture Decision Record (ADR) for a technical decision.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
Generate a complete ADR markdown document based on the context below.
|
|
11
|
+
|
|
12
|
+
ADR structure (follow exactly):
|
|
13
|
+
```markdown
|
|
14
|
+
# ADR-{{number}}: {{title}}
|
|
15
|
+
|
|
16
|
+
**Date:** {{date}}
|
|
17
|
+
**Status:** Proposed | Accepted | Deprecated | Superseded
|
|
18
|
+
|
|
19
|
+
## Context
|
|
20
|
+
What is the situation that forces us to make this decision?
|
|
21
|
+
|
|
22
|
+
## Decision
|
|
23
|
+
What have we decided to do?
|
|
24
|
+
|
|
25
|
+
## Consequences
|
|
26
|
+
### Positive
|
|
27
|
+
- ...
|
|
28
|
+
|
|
29
|
+
### Negative
|
|
30
|
+
- ...
|
|
31
|
+
|
|
32
|
+
### Risks
|
|
33
|
+
- ...
|
|
34
|
+
|
|
35
|
+
## Alternatives considered
|
|
36
|
+
| Option | Pros | Cons | Rejected because |
|
|
37
|
+
|--------|------|------|-----------------|
|
|
38
|
+
| ... | ... | ... | ... |
|
|
39
|
+
|
|
40
|
+
## References
|
|
41
|
+
- Links to relevant code, docs, or prior decisions
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Rules:
|
|
45
|
+
- Be specific and concrete — avoid generic statements
|
|
46
|
+
- State consequences honestly, including negative ones
|
|
47
|
+
- Alternatives must be real options that were actually considered
|
|
48
|
+
- The decision section must be unambiguous
|
|
49
|
+
|
|
50
|
+
If the decision context is incomplete, use [NEEDS CLARIFICATION: what constraints drove this decision?] before generating.
|
|
51
|
+
|
|
52
|
+
## Design context
|
|
53
|
+
{{context}}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
You are explaining code to a developer unfamiliar with this module.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Instructions
|
|
7
|
+
Explain the code below clearly and concisely. Include a Mermaid diagram where it helps understanding.
|
|
8
|
+
|
|
9
|
+
Structure your explanation as:
|
|
10
|
+
1. **Purpose** — what problem does this code solve?
|
|
11
|
+
2. **How it works** — step-by-step walkthrough of the key logic
|
|
12
|
+
3. **Diagram** — a Mermaid flowchart or sequence diagram showing the main flow
|
|
13
|
+
4. **Key decisions** — why important design choices were made (if apparent from the code)
|
|
14
|
+
5. **Gotchas** — non-obvious behaviors, edge cases, or known limitations
|
|
15
|
+
|
|
16
|
+
Rules:
|
|
17
|
+
- Write for a senior developer who is new to this codebase
|
|
18
|
+
- Be precise — use actual function/variable names from the code
|
|
19
|
+
- Keep the diagram to the essential flow (5–15 nodes)
|
|
20
|
+
- Do NOT suggest refactoring unless asked
|
|
21
|
+
|
|
22
|
+
If the purpose of the code is unclear, use [NEEDS CLARIFICATION: what is the intended behavior of this module?] before explaining.
|
|
23
|
+
|
|
24
|
+
Mermaid diagram format:
|
|
25
|
+
```mermaid
|
|
26
|
+
flowchart TD
|
|
27
|
+
A[Entry point] --> B[Step]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Code to explain
|
|
31
|
+
{{code}}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
You are generating code fixes for linter errors and security findings.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
Given the findings below, generate the minimal code changes needed to resolve each issue.
|
|
11
|
+
|
|
12
|
+
Rules:
|
|
13
|
+
- Fix ONLY what is reported — do not refactor unrelated code
|
|
14
|
+
- Preserve the original logic unless the logic itself is the bug
|
|
15
|
+
- For security findings: prefer safe APIs over disabling rules
|
|
16
|
+
- For linter errors: apply the fix the linter suggests unless it conflicts with the constitution
|
|
17
|
+
- Show each fix as a unified diff or a before/after code block
|
|
18
|
+
- One fix per finding — do not combine unrelated fixes
|
|
19
|
+
|
|
20
|
+
Priority order:
|
|
21
|
+
1. Critical security vulnerabilities (fix immediately)
|
|
22
|
+
2. Runtime errors and crashes
|
|
23
|
+
3. Type errors and undefined behavior
|
|
24
|
+
4. Linter warnings
|
|
25
|
+
|
|
26
|
+
If a finding is a false positive or requires design changes beyond a line fix, use [NEEDS CLARIFICATION: this finding may require architectural changes — confirm the intended approach].
|
|
27
|
+
|
|
28
|
+
## Findings to fix
|
|
29
|
+
{{findings}}
|
|
30
|
+
|
|
31
|
+
## Relevant source
|
|
32
|
+
{{source}}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
|
|
3
|
+
export type PromptTask =
|
|
4
|
+
| "review"
|
|
5
|
+
| "commit"
|
|
6
|
+
| "tests"
|
|
7
|
+
| "fix"
|
|
8
|
+
| "explain"
|
|
9
|
+
| "design"
|
|
10
|
+
| "context"
|
|
11
|
+
| "spec-questions"
|
|
12
|
+
| "design-approaches"
|
|
13
|
+
| "ai-review"
|
|
14
|
+
| "design-hld-lld";
|
|
15
|
+
|
|
16
|
+
const FALLBACK_TEMPLATE = `You are a helpful AI assistant completing the "{{task}}" task.
|
|
17
|
+
|
|
18
|
+
## Constitution (non-negotiable)
|
|
19
|
+
{{constitution}}
|
|
20
|
+
|
|
21
|
+
## Instructions
|
|
22
|
+
Complete the requested task based on the input provided below.
|
|
23
|
+
|
|
24
|
+
If anything is ambiguous, use [NEEDS CLARIFICATION: specific question] instead of guessing.
|
|
25
|
+
|
|
26
|
+
## Input
|
|
27
|
+
{{input}}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
export async function loadDefault(task: PromptTask): Promise<string> {
|
|
31
|
+
try {
|
|
32
|
+
const filePath = join(import.meta.dir, `${task}.md`);
|
|
33
|
+
const text = await Bun.file(filePath).text();
|
|
34
|
+
return text;
|
|
35
|
+
} catch {
|
|
36
|
+
return FALLBACK_TEMPLATE;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
You are reviewing code changes in a {{language}} codebase.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
Review ONLY the added/modified lines (lines starting with '+').
|
|
11
|
+
Focus on:
|
|
12
|
+
1. Security vulnerabilities (injection, XSS, auth bypass)
|
|
13
|
+
2. Business logic errors (wrong conditions, missing edge cases)
|
|
14
|
+
3. Missing error handling (unhandled promises, uncaught exceptions)
|
|
15
|
+
4. Violations of constitution or team conventions
|
|
16
|
+
|
|
17
|
+
Do NOT comment on:
|
|
18
|
+
- Style issues (handled by Biome)
|
|
19
|
+
- Naming conventions (handled by linter)
|
|
20
|
+
- Minor refactoring suggestions
|
|
21
|
+
|
|
22
|
+
If anything is ambiguous, use [NEEDS CLARIFICATION: specific question] instead of guessing.
|
|
23
|
+
|
|
24
|
+
For each issue found, respond in this exact format:
|
|
25
|
+
```yaml
|
|
26
|
+
issues:
|
|
27
|
+
- file: "path/to/file.ts"
|
|
28
|
+
line: 42
|
|
29
|
+
severity: "critical|major|minor"
|
|
30
|
+
issue: "Brief description"
|
|
31
|
+
suggestion: "How to fix it"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
If no issues found:
|
|
35
|
+
```yaml
|
|
36
|
+
issues: []
|
|
37
|
+
summary: "No issues found."
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Diff to review
|
|
41
|
+
{{diff}}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
You are analyzing an implementation plan to generate clarifying questions that surface ambiguity before test stubs are written.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Instructions
|
|
10
|
+
|
|
11
|
+
Given the implementation plan below, identify 3-5 clarifying questions that should be answered before writing test stubs or implementation code.
|
|
12
|
+
|
|
13
|
+
Focus on:
|
|
14
|
+
1. **Ambiguous requirements** — where multiple valid interpretations exist
|
|
15
|
+
2. **Missing edge cases** — boundary conditions, error scenarios, empty/null inputs not addressed
|
|
16
|
+
3. **Unstated assumptions** — implicit decisions that could go either way
|
|
17
|
+
4. **Integration boundaries** — how this feature interacts with existing systems
|
|
18
|
+
5. **Acceptance criteria gaps** — what "done" means for each task
|
|
19
|
+
|
|
20
|
+
Do NOT ask:
|
|
21
|
+
- Questions answered in the plan itself
|
|
22
|
+
- Generic questions that apply to any feature
|
|
23
|
+
- Questions about implementation details (HOW) — focus on requirements (WHAT)
|
|
24
|
+
- More than 5 questions
|
|
25
|
+
|
|
26
|
+
Output format: valid JSON array. Each question object has:
|
|
27
|
+
- `question` (string): the clarifying question
|
|
28
|
+
- `type` ("text" | "select"): "text" for open-ended, "select" for multiple choice
|
|
29
|
+
- `options` (string[], optional): choices for "select" type questions
|
|
30
|
+
- `reason` (string): why this question matters for spec quality
|
|
31
|
+
|
|
32
|
+
Example:
|
|
33
|
+
```json
|
|
34
|
+
[
|
|
35
|
+
{
|
|
36
|
+
"question": "Should the cache invalidate on branch switch or only on explicit clear?",
|
|
37
|
+
"type": "select",
|
|
38
|
+
"options": ["Branch switch", "Explicit clear only", "Both"],
|
|
39
|
+
"reason": "The plan mentions caching but doesn't specify invalidation strategy"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"question": "What should happen when the API key is missing during interactive mode?",
|
|
43
|
+
"type": "text",
|
|
44
|
+
"reason": "Error handling for missing credentials isn't specified"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
If the plan is clear and complete with no ambiguities, return an empty array: `[]`
|
|
50
|
+
|
|
51
|
+
If the plan is empty or too vague to analyze, return:
|
|
52
|
+
```json
|
|
53
|
+
[{"question": "The plan is empty or too vague — fill in plan.md with tasks before running interactive spec.", "type": "text", "reason": "No content to analyze"}]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Output ONLY the JSON array, no surrounding text or markdown fences.
|
|
57
|
+
|
|
58
|
+
## Implementation plan
|
|
59
|
+
{{plan}}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
You are generating TDD test stubs from an implementation plan.
|
|
2
|
+
|
|
3
|
+
## Constitution (non-negotiable)
|
|
4
|
+
{{constitution}}
|
|
5
|
+
|
|
6
|
+
## Team conventions
|
|
7
|
+
{{conventions}}
|
|
8
|
+
|
|
9
|
+
## Test Thinking Framework
|
|
10
|
+
|
|
11
|
+
For each feature/function, think through FIVE categories of tests:
|
|
12
|
+
|
|
13
|
+
### 1. Happy Path (Smoke Tests)
|
|
14
|
+
The basic flow works as expected. User does the normal thing, gets the normal result.
|
|
15
|
+
- Input valid data → get expected output
|
|
16
|
+
- Standard workflow → completes successfully
|
|
17
|
+
|
|
18
|
+
### 2. Edge Cases
|
|
19
|
+
Boundary conditions, empty inputs, maximums, minimums, off-by-one.
|
|
20
|
+
- Empty array/string/object → handles gracefully
|
|
21
|
+
- Single item vs many items
|
|
22
|
+
- Maximum values, zero values, negative values
|
|
23
|
+
- Unicode, special characters, very long strings
|
|
24
|
+
|
|
25
|
+
### 3. Error Handling
|
|
26
|
+
What happens when things go wrong? Every failure mode should be tested.
|
|
27
|
+
- Invalid input → returns Result error (never throws)
|
|
28
|
+
- Missing dependencies → graceful degradation
|
|
29
|
+
- Network/filesystem failures → clear error message
|
|
30
|
+
- Concurrent access → no data corruption
|
|
31
|
+
|
|
32
|
+
### 4. Security
|
|
33
|
+
Think like an attacker. What inputs could cause harm?
|
|
34
|
+
- Path traversal: `../../etc/passwd` in file paths
|
|
35
|
+
- Injection: SQL injection in search queries, command injection in shell args
|
|
36
|
+
- XSS: HTML/script tags in user-provided text
|
|
37
|
+
- Oversized input: gigabyte strings, deeply nested objects
|
|
38
|
+
- Prototype pollution: `__proto__`, `constructor` in object keys
|
|
39
|
+
|
|
40
|
+
### 5. Integration Boundaries
|
|
41
|
+
Where this module meets the outside world.
|
|
42
|
+
- Database operations: test with real SQLite, not mocks where possible
|
|
43
|
+
- File system: use temp directories, clean up in afterEach
|
|
44
|
+
- External processes: mock Bun.spawn, verify correct args passed
|
|
45
|
+
- Module boundaries: test the public API, not internal helpers
|
|
46
|
+
|
|
47
|
+
## Instructions
|
|
48
|
+
|
|
49
|
+
Given the implementation plan below, generate test stubs using `bun:test`.
|
|
50
|
+
|
|
51
|
+
Rules:
|
|
52
|
+
- Use `describe` / `test` / `expect` from `bun:test`
|
|
53
|
+
- Write one `test(...)` per behavior, not per function
|
|
54
|
+
- Each stub must have a clear description of what it asserts
|
|
55
|
+
- Use `expect(...).toThrow()` for error cases (or check Result.ok === false)
|
|
56
|
+
- Group tests by the five categories above inside nested `describe` blocks
|
|
57
|
+
- Mock external dependencies (filesystem, network, DB) with `mock()` or `spyOn()`
|
|
58
|
+
- Stubs should fail until the implementation is written — do not pre-fill assertions
|
|
59
|
+
- ALWAYS include at least one security test per module that handles user input
|
|
60
|
+
|
|
61
|
+
Do NOT:
|
|
62
|
+
- Generate implementation code
|
|
63
|
+
- Use Jest-specific APIs (`jest.fn()`, `jest.mock()`)
|
|
64
|
+
- Write tests that test implementation details instead of behavior
|
|
65
|
+
- Skip edge cases because "they seem unlikely"
|
|
66
|
+
|
|
67
|
+
If the plan is underspecified, use [NEEDS CLARIFICATION: which behaviors should be tested?] before generating.
|
|
68
|
+
|
|
69
|
+
Output format: a single TypeScript file with all test stubs, ready to run with `bun test`.
|
|
70
|
+
|
|
71
|
+
## Implementation plan
|
|
72
|
+
{{plan}}
|