ai-spec-dev 0.31.0 → 0.35.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/.claude/commands/add-lesson.md +34 -0
- package/.claude/commands/check-layers.md +65 -0
- package/.claude/commands/installed-deps.md +35 -0
- package/.claude/commands/recall-lessons.md +40 -0
- package/.claude/commands/scan-singletons.md +45 -0
- package/.claude/commands/verify-imports.md +48 -0
- package/.claude/settings.local.json +15 -1
- package/README.md +531 -213
- package/RELEASE_LOG.md +460 -0
- package/cli/commands/config.ts +93 -0
- package/cli/commands/create.ts +1233 -0
- package/cli/commands/dashboard.ts +62 -0
- package/cli/commands/export.ts +66 -0
- package/cli/commands/init.ts +190 -0
- package/cli/commands/learn.ts +30 -0
- package/cli/commands/logs.ts +106 -0
- package/cli/commands/mock.ts +175 -0
- package/cli/commands/model.ts +156 -0
- package/cli/commands/restore.ts +22 -0
- package/cli/commands/review.ts +63 -0
- package/cli/commands/scan.ts +99 -0
- package/cli/commands/trend.ts +36 -0
- package/cli/commands/types.ts +69 -0
- package/cli/commands/update.ts +178 -0
- package/cli/commands/vcr.ts +70 -0
- package/cli/commands/workspace.ts +219 -0
- package/cli/index.ts +34 -2240
- package/cli/utils.ts +83 -0
- package/core/combined-generator.ts +13 -3
- package/core/dashboard-generator.ts +340 -0
- package/core/design-dialogue.ts +124 -0
- package/core/dsl-feedback.ts +285 -0
- package/core/error-feedback.ts +46 -2
- package/core/project-index.ts +301 -0
- package/core/reviewer.ts +84 -6
- package/core/run-logger.ts +109 -3
- package/core/run-trend.ts +261 -0
- package/core/self-evaluator.ts +139 -7
- package/core/spec-generator.ts +14 -8
- package/core/task-generator.ts +17 -0
- package/core/types-generator.ts +219 -0
- package/core/vcr.ts +210 -0
- package/dist/cli/index.js +6692 -4512
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +6692 -4512
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.d.mts +19 -5
- package/dist/index.d.ts +19 -5
- package/dist/index.js +420 -224
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +418 -224
- package/dist/index.mjs.map +1 -1
- package/docs-assets/purpose/architecture-overview.svg +64 -0
- package/docs-assets/purpose/create-pipeline.svg +113 -0
- package/docs-assets/purpose/task-layering.svg +74 -0
- package/package.json +6 -3
- package/prompts/codegen.prompt.ts +97 -9
- package/prompts/design.prompt.ts +59 -0
- package/prompts/spec.prompt.ts +8 -1
- package/prompts/tasks.prompt.ts +27 -2
- package/purpose.md +600 -174
- package/tests/dsl-extractor.test.ts +264 -0
- package/tests/dsl-feedback.test.ts +266 -0
- package/tests/dsl-validator.test.ts +283 -0
- package/tests/error-feedback.test.ts +292 -0
- package/tests/provider-utils.test.ts +173 -0
- package/tests/run-trend.test.ts +186 -0
- package/tests/self-evaluator.test.ts +339 -0
- package/tests/spec-assessor.test.ts +142 -0
- package/tests/task-generator.test.ts +230 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Append a lesson learned to the project constitution's §9 accumulated lessons section.
|
|
2
|
+
|
|
3
|
+
**Input:** $ARGUMENTS (paste a review finding, bug description, or any lesson to remember)
|
|
4
|
+
|
|
5
|
+
**Steps:**
|
|
6
|
+
|
|
7
|
+
1. Read `.ai-spec-constitution.md` in the current directory. If it doesn't exist, check for it in the git root.
|
|
8
|
+
|
|
9
|
+
2. Check if a `## 9. 积累教训` (or `## 9. Accumulated Lessons`) section exists.
|
|
10
|
+
- If not, append it at the end of the file.
|
|
11
|
+
|
|
12
|
+
3. Before appending, **deduplicate**: scan existing lesson entries. If the first 60 characters of the new lesson closely match an existing entry (case-insensitive, ignoring punctuation), do NOT add a duplicate — instead say "Similar lesson already exists: [existing entry]" and stop.
|
|
13
|
+
|
|
14
|
+
4. Classify the lesson into one of these categories:
|
|
15
|
+
- `[bug]` — logic error or crash that occurred
|
|
16
|
+
- `[security]` — auth, injection, exposure issue
|
|
17
|
+
- `[pattern]` — wrong architectural pattern used
|
|
18
|
+
- `[perf]` — performance regression
|
|
19
|
+
- `[convention]` — naming, structure, file organization issue
|
|
20
|
+
- `[other]` — anything else
|
|
21
|
+
|
|
22
|
+
5. Append in this exact format:
|
|
23
|
+
```
|
|
24
|
+
- [YYYY-MM-DD] [category] <one-sentence description of what went wrong and how to avoid it>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Example output:**
|
|
28
|
+
```
|
|
29
|
+
- [2026-04-01] [pattern] Store directly called axios instead of going through the API layer — stores must only call functions from src/api/, never import axios directly.
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
6. Confirm: "Lesson added to §9. Constitution now has N lessons. Consider running `ai-spec init --consolidate` when lessons exceed 8."
|
|
33
|
+
|
|
34
|
+
**Important:** Be concise. One sentence per lesson. Focus on the actionable rule, not the incident narrative.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Check generated or modified code for layer architecture violations.
|
|
2
|
+
|
|
3
|
+
**Input:** $ARGUMENTS (file path or directory to check; leave empty to check recent changes)
|
|
4
|
+
|
|
5
|
+
**What counts as a layer violation:**
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Typical layered architecture:
|
|
9
|
+
|
|
10
|
+
routes / controllers
|
|
11
|
+
↓ (can call)
|
|
12
|
+
services
|
|
13
|
+
↓ (can call)
|
|
14
|
+
repositories / DB / ORM
|
|
15
|
+
↓ (can call)
|
|
16
|
+
external APIs / infra
|
|
17
|
+
|
|
18
|
+
stores (state management)
|
|
19
|
+
↓ (can call)
|
|
20
|
+
api layer (src/api/)
|
|
21
|
+
↓ (can call)
|
|
22
|
+
HTTP client (axios / fetch)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Violations to detect:**
|
|
26
|
+
|
|
27
|
+
1. **Store → HTTP direct**: a Pinia/Vuex/Zustand store imports `axios`, `fetch`, or an HTTP client directly instead of going through `src/api/`
|
|
28
|
+
2. **Route → DB direct**: a route/controller file imports Prisma client, Mongoose models, or raw SQL directly — should go through a service
|
|
29
|
+
3. **Component → Service direct**: a UI component imports a service layer function directly instead of going through a store or composable
|
|
30
|
+
4. **Service → Route import**: a service imports anything from the routes layer (circular)
|
|
31
|
+
5. **Cross-feature direct import**: feature A directly imports internal files from feature B (should go through a shared interface)
|
|
32
|
+
|
|
33
|
+
**Steps:**
|
|
34
|
+
|
|
35
|
+
1. Determine which files to check (same logic as `/verify-imports`).
|
|
36
|
+
|
|
37
|
+
2. For each file, read its imports and the file's own layer (infer from path: `routes/`, `controllers/`, `services/`, `stores/`, `components/`, `api/`, `repositories/`).
|
|
38
|
+
|
|
39
|
+
3. Check each import against the allowed call directions above.
|
|
40
|
+
|
|
41
|
+
4. Output:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
=== Layer Architecture Report ===
|
|
45
|
+
|
|
46
|
+
✘ src/stores/cartStore.ts [layer: store]
|
|
47
|
+
imports axios directly from 'axios'
|
|
48
|
+
→ Violation: store must not make HTTP calls directly
|
|
49
|
+
→ Fix: move HTTP call to src/api/cart.ts, import that function here
|
|
50
|
+
|
|
51
|
+
✘ src/views/OrderList.vue [layer: component]
|
|
52
|
+
imports orderService from '@/services/orderService'
|
|
53
|
+
→ Violation: component should call store, not service directly
|
|
54
|
+
→ Fix: expose this via src/stores/orderStore.ts action
|
|
55
|
+
|
|
56
|
+
✔ src/services/userService.ts — no violations
|
|
57
|
+
✔ src/api/user.ts — no violations
|
|
58
|
+
|
|
59
|
+
─────────────────────────────────
|
|
60
|
+
Total: 4 files | ✔ 2 clean | ✘ 2 violations
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
5. If you can't determine the project's layer structure from file paths alone, read the project constitution (`.ai-spec-constitution.md` §1 Architecture Rules) first.
|
|
64
|
+
|
|
65
|
+
6. If no violations found: "Layer architecture check passed ✔ — no cross-layer violations detected."
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
List all installed packages in the current project as a dependency whitelist for code generation.
|
|
2
|
+
|
|
3
|
+
**Steps:**
|
|
4
|
+
|
|
5
|
+
1. Read `package.json` from the current directory (or git root if not found here).
|
|
6
|
+
|
|
7
|
+
2. Collect all keys from `dependencies` and `devDependencies`.
|
|
8
|
+
|
|
9
|
+
3. Also detect non-Node language markers:
|
|
10
|
+
- `go.mod` present → Go project, list module dependencies from go.mod
|
|
11
|
+
- `Cargo.toml` present → Rust project, list [dependencies] from Cargo.toml
|
|
12
|
+
- `requirements.txt` / `pyproject.toml` present → Python project, list packages
|
|
13
|
+
|
|
14
|
+
4. Output in this format:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
=== Installed Packages — ONLY use these in generated code ===
|
|
18
|
+
|
|
19
|
+
Runtime dependencies:
|
|
20
|
+
express, prisma, @prisma/client, jsonwebtoken, redis, zod, ...
|
|
21
|
+
|
|
22
|
+
Dev dependencies:
|
|
23
|
+
typescript, jest, @types/express, ts-node, ...
|
|
24
|
+
|
|
25
|
+
⚠ Hard rules for code generation:
|
|
26
|
+
1. NEVER import a package not listed above — implement the equivalent using what IS installed
|
|
27
|
+
2. If you need HTTP client → use: [detected: axios / fetch / got / ky — pick from list]
|
|
28
|
+
3. If you need validation → use: [detected: zod / joi / yup / class-validator — pick from list]
|
|
29
|
+
4. If you need date handling → use: [detected: dayjs / date-fns / moment — pick from list]
|
|
30
|
+
5. If a capability needs a missing package → say so explicitly, do NOT silently add an import
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
5. After the list, highlight any commonly confused alternatives detected (e.g., if both `axios` and native `fetch` patterns exist in the codebase, flag this ambiguity).
|
|
34
|
+
|
|
35
|
+
This manifest should be treated as ground truth for the entire coding session — copy it into your context when asking Claude to generate code.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Surface relevant accumulated lessons from the project constitution before starting a task.
|
|
2
|
+
|
|
3
|
+
**Input:** $ARGUMENTS (describe the task you're about to do, e.g. "add a payment API endpoint" or "build a user profile page")
|
|
4
|
+
|
|
5
|
+
**Steps:**
|
|
6
|
+
|
|
7
|
+
1. Read `.ai-spec-constitution.md` in the current directory (or git root).
|
|
8
|
+
- If not found, say "No constitution found. Run `ai-spec init` to generate one." and stop.
|
|
9
|
+
|
|
10
|
+
2. Find the `## 9. 积累教训` or `## 9. Accumulated Lessons` section.
|
|
11
|
+
- If not found, say "No accumulated lessons yet (§9 section missing). This is normal for new projects." and stop.
|
|
12
|
+
|
|
13
|
+
3. Read all lesson entries. For each one, score its relevance to the current task description on a scale:
|
|
14
|
+
- **High** — directly related (same domain, same layer, same pattern)
|
|
15
|
+
- **Medium** — adjacent (same tech area but different feature)
|
|
16
|
+
- **Low** — unrelated
|
|
17
|
+
|
|
18
|
+
4. Output only High and Medium relevance lessons:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
=== Relevant Lessons for: "<task description>" ===
|
|
22
|
+
|
|
23
|
+
⚠ HIGH relevance — apply these directly:
|
|
24
|
+
- [2026-03-15] [pattern] ...lesson text...
|
|
25
|
+
- [2026-03-20] [security] ...lesson text...
|
|
26
|
+
|
|
27
|
+
💡 MEDIUM relevance — keep in mind:
|
|
28
|
+
- [2026-02-10] [convention] ...lesson text...
|
|
29
|
+
|
|
30
|
+
Total lessons in §9: N | Shown: M relevant
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
5. If there are High relevance lessons, add:
|
|
34
|
+
```
|
|
35
|
+
Before writing any code, confirm you've accounted for each ⚠ lesson above.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
6. If no lessons are relevant, say: "No directly relevant lessons found. Proceed, and remember to `/add-lesson` after review."
|
|
39
|
+
|
|
40
|
+
**Purpose:** Prevents repeating past mistakes by making institutional knowledge visible at the start of every task.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Scan the current project for all "singleton config files" — files that must never be duplicated and can only be modified in place.
|
|
2
|
+
|
|
3
|
+
**What to scan for:**
|
|
4
|
+
|
|
5
|
+
Search the project (excluding node_modules, dist, .git) for files matching these patterns:
|
|
6
|
+
- i18n / locale files: `**/locales/**/*.json`, `**/i18n/**/*.{json,ts,js}`, `**/*.locale.{ts,js}`, `**/lang/**/*.{json,ts,js}`
|
|
7
|
+
- Constants / enums: `**/constants/**/*.{ts,js}`, `**/enums/**/*.{ts,js}`, `**/*constants*.{ts,js}`, `**/*enums*.{ts,js}`
|
|
8
|
+
- Route index files: `**/routes/index.{ts,js}`, `**/router/index.{ts,js}`, `**/routes.{ts,js}`
|
|
9
|
+
- Store index files: `**/stores/index.{ts,js}`, `**/store/index.{ts,js}`
|
|
10
|
+
- Global config: `**/config/index.{ts,js}`, `**/config.{ts,js,json}` (project root level only)
|
|
11
|
+
- Error codes: `**/*error*code*.{ts,js}`, `**/*ErrorCode*.{ts,js}`
|
|
12
|
+
|
|
13
|
+
**Output format:**
|
|
14
|
+
|
|
15
|
+
Print a manifest like this:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
=== Singleton Config Files — MODIFY ONLY, NEVER RECREATE ===
|
|
19
|
+
|
|
20
|
+
i18n / Locale:
|
|
21
|
+
- src/locales/zh-CN.json ← append new keys here
|
|
22
|
+
- src/locales/en-US.json ← append new keys here
|
|
23
|
+
|
|
24
|
+
Constants / Enums:
|
|
25
|
+
- src/constants/index.ts ← add new constants here
|
|
26
|
+
- src/enums/status.ts ← add new enum values here
|
|
27
|
+
|
|
28
|
+
Route Registration:
|
|
29
|
+
- src/router/index.ts ← register new routes here
|
|
30
|
+
|
|
31
|
+
Store Registration:
|
|
32
|
+
- src/stores/index.ts ← register new stores here
|
|
33
|
+
|
|
34
|
+
Error Codes:
|
|
35
|
+
- src/constants/errorCodes.ts ← add new error codes here
|
|
36
|
+
|
|
37
|
+
⚠ Rules:
|
|
38
|
+
1. When adding translations → append keys to the files above, never create a new locale file
|
|
39
|
+
2. When adding constants/enums → add values to existing file, never create a parallel file
|
|
40
|
+
3. When adding a new route → register it in the route index above
|
|
41
|
+
4. When adding a new store → register it in the store index above
|
|
42
|
+
5. If a file in the list doesn't exist yet, create it once — then it becomes the singleton
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
After printing the manifest, ask: "Do you want me to save this manifest to `.ai-spec-constitution.md` §8 for future use?"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Verify that all import paths in generated or modified files actually exist in the project.
|
|
2
|
+
|
|
3
|
+
**Input:** $ARGUMENTS (file path, directory path, or leave empty to check all recently modified files)
|
|
4
|
+
|
|
5
|
+
**Steps:**
|
|
6
|
+
|
|
7
|
+
1. Determine which files to check:
|
|
8
|
+
- If a file path is given → check that file only
|
|
9
|
+
- If a directory is given → check all `.ts` / `.js` / `.tsx` / `.jsx` files in it
|
|
10
|
+
- If empty → check files modified in the last git commit (`git diff --name-only HEAD~1`)
|
|
11
|
+
|
|
12
|
+
2. For each file, extract all import statements:
|
|
13
|
+
- `import ... from '...'`
|
|
14
|
+
- `require('...')`
|
|
15
|
+
- `import('...')`
|
|
16
|
+
|
|
17
|
+
3. Classify each import:
|
|
18
|
+
- **External package** (no leading `./`, `../`, `@/`, `~/`) → verify it's in `package.json` dependencies
|
|
19
|
+
- **Alias path** (`@/`, `~/`, `#`) → resolve using `tsconfig.json` `paths` or `vite.config` `alias`, then verify the resolved path exists
|
|
20
|
+
- **Relative path** (`./`, `../`) → resolve relative to the file, verify the file exists (check `.ts`, `.tsx`, `.js`, `/index.ts` variants)
|
|
21
|
+
|
|
22
|
+
4. Output:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
=== Import Verification Report ===
|
|
26
|
+
|
|
27
|
+
✔ src/api/user.ts
|
|
28
|
+
@/utils/request → src/utils/request.ts ✔
|
|
29
|
+
@/types/user → src/types/user.ts ✔
|
|
30
|
+
|
|
31
|
+
✘ src/stores/orderStore.ts
|
|
32
|
+
@/utils/http → NOT FOUND ← did you mean @/utils/request?
|
|
33
|
+
../services/paymentService → NOT FOUND ← file doesn't exist
|
|
34
|
+
|
|
35
|
+
✔ src/router/index.ts
|
|
36
|
+
(all imports verified)
|
|
37
|
+
|
|
38
|
+
─────────────────────────────────
|
|
39
|
+
Total: 3 files | ✔ 2 clean | ✘ 1 with broken imports
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
5. For each broken import, suggest the most likely correct path by:
|
|
43
|
+
- Searching for files with a similar name in the project
|
|
44
|
+
- Checking git history for recently renamed files
|
|
45
|
+
|
|
46
|
+
6. If all imports are clean, say: "All imports verified ✔ — no hallucinated paths found."
|
|
47
|
+
|
|
48
|
+
**Why this matters:** AI models frequently invent import paths (`@/utils/http` instead of `@/utils/request`) that look plausible but don't exist, causing silent build failures.
|
|
@@ -4,7 +4,21 @@
|
|
|
4
4
|
"Bash(npm run:*)",
|
|
5
5
|
"Bash(python3 -c \":*)",
|
|
6
6
|
"Bash(grep -E \"^./\\\\w+/|^./\\\\w+\\\\.ts$\")",
|
|
7
|
-
"Bash(wc -l core/*.ts prompts/*.ts)"
|
|
7
|
+
"Bash(wc -l core/*.ts prompts/*.ts)",
|
|
8
|
+
"Bash(npx tsc:*)",
|
|
9
|
+
"Bash(npm install:*)",
|
|
10
|
+
"Bash(npx vitest:*)",
|
|
11
|
+
"Bash(npm test:*)",
|
|
12
|
+
"Bash(for f:*)",
|
|
13
|
+
"Bash(do echo:*)",
|
|
14
|
+
"Read(//Users/hongzhong/Documents/文稿 - hongzhong的MacBook Pro/code/ai-spec-dev-poc/**)",
|
|
15
|
+
"Bash(done)",
|
|
16
|
+
"Bash(node dist/cli/index.js dashboard)",
|
|
17
|
+
"Bash(grep -E \"\\\\.\\(ts|js\\)$\")",
|
|
18
|
+
"Read(//Users/hongzhong/Documents/文稿 - hongzhong的MacBook Pro/code/**)",
|
|
19
|
+
"Bash(npx tsx:*)",
|
|
20
|
+
"WebFetch(domain:github.com)",
|
|
21
|
+
"WebFetch(domain:raw.githubusercontent.com)"
|
|
8
22
|
]
|
|
9
23
|
}
|
|
10
24
|
}
|