ai-spec-dev 0.1.0 โ 0.14.1
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/settings.local.json +18 -0
- package/README.md +1211 -146
- package/RELEASE_LOG.md +1444 -0
- package/cli/index.ts +1961 -0
- package/cli/welcome.ts +151 -0
- package/core/code-generator.ts +740 -0
- package/core/combined-generator.ts +63 -0
- package/core/constitution-consolidator.ts +141 -0
- package/core/constitution-generator.ts +89 -0
- package/core/context-loader.ts +453 -0
- package/core/contract-bridge.ts +217 -0
- package/core/dsl-extractor.ts +337 -0
- package/core/dsl-types.ts +166 -0
- package/core/dsl-validator.ts +450 -0
- package/core/error-feedback.ts +354 -0
- package/core/frontend-context-loader.ts +602 -0
- package/core/global-constitution.ts +88 -0
- package/core/key-store.ts +49 -0
- package/core/knowledge-memory.ts +171 -0
- package/core/mock-server-generator.ts +571 -0
- package/core/openapi-exporter.ts +361 -0
- package/core/requirement-decomposer.ts +198 -0
- package/core/reviewer.ts +259 -0
- package/core/spec-assessor.ts +99 -0
- package/core/spec-generator.ts +428 -0
- package/core/spec-refiner.ts +89 -0
- package/core/spec-updater.ts +227 -0
- package/core/spec-versioning.ts +213 -0
- package/core/task-generator.ts +174 -0
- package/core/test-generator.ts +273 -0
- package/core/workspace-loader.ts +256 -0
- package/dist/cli/index.js +6717 -672
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +6717 -670
- package/dist/cli/index.mjs.map +1 -1
- package/dist/index.d.mts +147 -27
- package/dist/index.d.ts +147 -27
- package/dist/index.js +2337 -286
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2329 -285
- package/dist/index.mjs.map +1 -1
- package/git/worktree.ts +109 -0
- package/index.ts +9 -0
- package/package.json +4 -28
- package/prompts/codegen.prompt.ts +259 -0
- package/prompts/consolidate.prompt.ts +73 -0
- package/prompts/constitution.prompt.ts +63 -0
- package/prompts/decompose.prompt.ts +168 -0
- package/prompts/dsl.prompt.ts +203 -0
- package/prompts/frontend-spec.prompt.ts +191 -0
- package/prompts/global-constitution.prompt.ts +61 -0
- package/prompts/spec-assess.prompt.ts +53 -0
- package/prompts/spec.prompt.ts +102 -0
- package/prompts/tasks.prompt.ts +35 -0
- package/prompts/testgen.prompt.ts +84 -0
- package/prompts/update.prompt.ts +131 -0
- package/purpose.docx +0 -0
- package/purpose.md +444 -0
- package/tsconfig.json +14 -0
- package/tsup.config.ts +10 -0
package/git/worktree.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import * as fs from "fs-extra";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
|
|
6
|
+
export class GitWorktreeManager {
|
|
7
|
+
constructor(private baseDir: string) {}
|
|
8
|
+
|
|
9
|
+
private isGitRepo(): boolean {
|
|
10
|
+
try {
|
|
11
|
+
execSync("git rev-parse --is-inside-work-tree", { cwd: this.baseDir, stdio: "ignore" });
|
|
12
|
+
return true;
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private sanitizeFeatureName(idea: string): string {
|
|
19
|
+
return idea
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
22
|
+
.replace(/^-+|-+$/g, "")
|
|
23
|
+
.substring(0, 30) || `feature-${Date.now()}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Symlink dependency directories from the base repo into the worktree so that
|
|
28
|
+
* tools like `vite`, `tsc`, etc. are available without re-installing.
|
|
29
|
+
*
|
|
30
|
+
* Handles: node_modules (npm/yarn/pnpm), vendor (PHP Composer)
|
|
31
|
+
*/
|
|
32
|
+
private async linkDependencies(worktreePath: string): Promise<void> {
|
|
33
|
+
const candidates = ["node_modules", "vendor"];
|
|
34
|
+
|
|
35
|
+
for (const dir of candidates) {
|
|
36
|
+
const src = path.join(this.baseDir, dir);
|
|
37
|
+
const dest = path.join(worktreePath, dir);
|
|
38
|
+
|
|
39
|
+
if (!(await fs.pathExists(src))) continue;
|
|
40
|
+
if (await fs.pathExists(dest)) continue; // already there (or linked)
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
await fs.ensureSymlink(src, dest, "dir");
|
|
44
|
+
console.log(chalk.gray(` Symlinked ${dir}/ from base repo โ worktree`));
|
|
45
|
+
} catch (err) {
|
|
46
|
+
// Non-fatal: symlink may fail on some systems (e.g. cross-device)
|
|
47
|
+
console.log(chalk.yellow(` โ Could not symlink ${dir}/: ${(err as Error).message}`));
|
|
48
|
+
console.log(chalk.yellow(` Run \`npm install\` inside the worktree manually.`));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async createWorktree(idea: string): Promise<string | null> {
|
|
54
|
+
if (!this.isGitRepo()) {
|
|
55
|
+
console.log(chalk.yellow("โ ๏ธ Not a git repository. Skipping worktree creation."));
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const featureName = this.sanitizeFeatureName(idea);
|
|
60
|
+
const branchName = `feature/${featureName}`;
|
|
61
|
+
const repoName = path.basename(this.baseDir);
|
|
62
|
+
const worktreePath = path.resolve(this.baseDir, "..", `${repoName}-${featureName}`);
|
|
63
|
+
|
|
64
|
+
console.log(chalk.cyan(`\n--- Setting up Git Worktree ---`));
|
|
65
|
+
|
|
66
|
+
if (await fs.pathExists(worktreePath)) {
|
|
67
|
+
console.log(chalk.yellow(`โ ๏ธ Worktree directory already exists at: ${worktreePath}`));
|
|
68
|
+
await this.linkDependencies(worktreePath);
|
|
69
|
+
return worktreePath;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
let branchExists = false;
|
|
74
|
+
try {
|
|
75
|
+
execSync(`git show-ref --verify refs/heads/${branchName}`, {
|
|
76
|
+
cwd: this.baseDir,
|
|
77
|
+
stdio: "ignore",
|
|
78
|
+
});
|
|
79
|
+
branchExists = true;
|
|
80
|
+
} catch {}
|
|
81
|
+
|
|
82
|
+
console.log(chalk.gray(`Creating worktree at: ${worktreePath}`));
|
|
83
|
+
|
|
84
|
+
if (branchExists) {
|
|
85
|
+
execSync(`git worktree add "${worktreePath}" ${branchName}`, {
|
|
86
|
+
cwd: this.baseDir,
|
|
87
|
+
stdio: "inherit",
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
execSync(`git worktree add -b ${branchName} "${worktreePath}"`, {
|
|
91
|
+
cwd: this.baseDir,
|
|
92
|
+
stdio: "inherit",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log(
|
|
97
|
+
chalk.green(`โ Worktree successfully created and isolated on branch '${branchName}'`)
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// Link node_modules / vendor so the project can run immediately
|
|
101
|
+
await this.linkDependencies(worktreePath);
|
|
102
|
+
|
|
103
|
+
return worktreePath;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(chalk.red("Failed to create git worktree:"), error);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./core/spec-generator";
|
|
2
|
+
export * from "./core/context-loader";
|
|
3
|
+
export * from "./core/spec-refiner";
|
|
4
|
+
export * from "./core/code-generator";
|
|
5
|
+
export * from "./core/reviewer";
|
|
6
|
+
export * from "./core/constitution-generator";
|
|
7
|
+
export * from "./core/task-generator";
|
|
8
|
+
export * from "./core/combined-generator";
|
|
9
|
+
export * from "./git/worktree";
|
package/package.json
CHANGED
|
@@ -1,49 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-spec-dev",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "AI-driven Development Orchestrator SDK & CLI",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
6
|
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": {
|
|
11
|
-
"types": "./dist/index.d.mts",
|
|
12
|
-
"default": "./dist/index.mjs"
|
|
13
|
-
},
|
|
14
|
-
"require": {
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"default": "./dist/index.js"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
7
|
"bin": {
|
|
21
8
|
"ai-spec": "dist/cli/index.js"
|
|
22
9
|
},
|
|
23
|
-
"files": [
|
|
24
|
-
"dist",
|
|
25
|
-
"README.md"
|
|
26
|
-
],
|
|
27
10
|
"scripts": {
|
|
28
11
|
"build": "tsup",
|
|
29
|
-
"dev": "tsup --watch"
|
|
30
|
-
"prepublishOnly": "npm run build"
|
|
12
|
+
"dev": "tsup --watch"
|
|
31
13
|
},
|
|
32
14
|
"keywords": [
|
|
33
15
|
"ai",
|
|
34
16
|
"spec",
|
|
35
17
|
"codegen",
|
|
36
18
|
"gemini",
|
|
37
|
-
"claude"
|
|
38
|
-
"openai",
|
|
39
|
-
"cli",
|
|
40
|
-
"sdk"
|
|
19
|
+
"claude"
|
|
41
20
|
],
|
|
42
|
-
"author": "
|
|
21
|
+
"author": "",
|
|
43
22
|
"license": "MIT",
|
|
44
|
-
"engines": {
|
|
45
|
-
"node": ">=18.0.0"
|
|
46
|
-
},
|
|
47
23
|
"dependencies": {
|
|
48
24
|
"@anthropic-ai/sdk": "^0.38.0",
|
|
49
25
|
"@google/generative-ai": "^0.21.0",
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
export const codeGenSystemPrompt = `You are a Senior Full-Stack Developer implementing features based on provided specifications.
|
|
2
|
+
|
|
3
|
+
Rules:
|
|
4
|
+
1. Follow the existing project's code conventions, naming patterns, and file structure exactly
|
|
5
|
+
2. Write complete, production-ready code โ no placeholders, no TODOs, no stub implementations
|
|
6
|
+
3. Include proper error handling, input validation, and logging
|
|
7
|
+
4. Output ONLY raw code content โ NO markdown fences, NO explanations, NO comments outside the code
|
|
8
|
+
5. Match the imports, exports, and module patterns visible in the existing codebase
|
|
9
|
+
6. If modifying an existing file, preserve all unchanged code exactly โ return the FULL file content with only the new additions merged in
|
|
10
|
+
|
|
11
|
+
CRITICAL โ Dependency Hallucination Prevention (MUST follow):
|
|
12
|
+
7. You will be given an "=== Installed Packages ===" section listing ALL packages available in this project.
|
|
13
|
+
NEVER import or use ANY package, library, or module that does not appear in that list.
|
|
14
|
+
This includes (but is not limited to): i18n libraries, UI component libraries, utility libraries, state management libraries.
|
|
15
|
+
If a feature would normally need a missing library, implement the equivalent functionality using only what IS installed.
|
|
16
|
+
Violating this rule will break the project and is unacceptable.
|
|
17
|
+
|
|
18
|
+
CRITICAL โ File Reuse Rules:
|
|
19
|
+
8. NEVER create a new file if an existing file serves the same purpose. Check the shared config file list before planning any new file.
|
|
20
|
+
9. i18n / locale files: ONLY add translation keys if an i18n file already exists in the project. If no i18n/locale files are listed in "Installed Packages" or shared config files, do NOT add any i18n code.
|
|
21
|
+
10. constants / enums files: ALWAYS add new values to the EXISTING constants or enums file. Never create a new parallel file.
|
|
22
|
+
11. When in doubt: prefer "modify existing" over "create new".
|
|
23
|
+
|
|
24
|
+
CRITICAL โ Component Reuse (MUST follow):
|
|
25
|
+
12. Before writing any UI component or element: check the "Existing reusable components" list in the context.
|
|
26
|
+
If a component serving the same purpose already exists in src/components/, import and use it โ do NOT create a duplicate.
|
|
27
|
+
13. Check the "Existing page examples" for how the project's UI library components (e.g. antd, element-plus, arco-design) are actually used.
|
|
28
|
+
Copy those exact component names and import patterns. Do NOT use generic HTML elements where the UI library already provides a component.
|
|
29
|
+
|
|
30
|
+
CRITICAL โ Frontend Architecture Layer Separation (MUST follow):
|
|
31
|
+
14. State management stores (Pinia, Vuex, Redux, Zustand) MUST NOT make HTTP requests directly.
|
|
32
|
+
Stores call functions from the API layer (src/api/ or src/apis/). The API layer makes HTTP requests.
|
|
33
|
+
If the existing store patterns in the context show no HTTP calls, do not add any.
|
|
34
|
+
13. API files import the HTTP client using ONLY the exact import line shown in "HTTP client import" in the context.
|
|
35
|
+
NEVER invent a different import path (e.g., '@/utils/request', '@/utils/http') unless that exact path appears in the provided context.
|
|
36
|
+
|
|
37
|
+
CRITICAL โ Learn conventions from examples, do not invent them:
|
|
38
|
+
15. The "=== Existing Shared Config Files ===" section below shows real files from the project.
|
|
39
|
+
Study them carefully and match their exact structure, naming conventions, and patterns.
|
|
40
|
+
- Router files: replicate the exact same file structure, path naming, and registration approach you see.
|
|
41
|
+
- Store files: replicate the exact module pattern shown.
|
|
42
|
+
- Do NOT apply generic framework defaults (e.g., Vue Router docs examples) if the project shows a different convention.
|
|
43
|
+
- If you see a modules/ directory pattern in the examples, follow it. If you see a flat file pattern, follow that instead.
|
|
44
|
+
The examples are ground truth. Your prior knowledge about "typical" project layouts is secondary.
|
|
45
|
+
|
|
46
|
+
CRITICAL โ Route/Store index registration (MUST follow):
|
|
47
|
+
16. When creating a new route module file (e.g., src/router/routes/taskManagement.ts), you MUST ALSO update
|
|
48
|
+
the corresponding index file (src/router/routes/index.ts) to import the new module and add it to the export array.
|
|
49
|
+
This is non-negotiable. A route module that is not registered in the index will never be loaded.
|
|
50
|
+
Pattern: add "import taskManagement from './taskManagement'" at the top and "taskManagement" inside the "export default [...]".
|
|
51
|
+
|
|
52
|
+
CRITICAL โ Cross-file function name consistency (MUST follow):
|
|
53
|
+
17. When you see an "=== Files Already Generated in This Run ===" section, those file contents are the AUTHORITATIVE source
|
|
54
|
+
of truth for exported function/variable names.
|
|
55
|
+
NEVER rename, guess, or substitute alternative names. If the file exports "getTaskList", import "getTaskList" โ not "getTasks".
|
|
56
|
+
If no such section is present, derive function names strictly from the DSL endpoint IDs shown in the spec.`;
|
|
57
|
+
|
|
58
|
+
// โโโ Go Codegen System Prompt โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
59
|
+
|
|
60
|
+
export const codeGenGoSystemPrompt = `You are a Senior Go Developer implementing features based on provided specifications.
|
|
61
|
+
|
|
62
|
+
Rules:
|
|
63
|
+
1. Follow standard Go project layout (cmd/, internal/, pkg/, api/). Match whatever layout already exists in the project.
|
|
64
|
+
2. Write idiomatic Go โ use named return errors, defer for cleanup, context propagation, structured logging (slog or zap if present).
|
|
65
|
+
3. Write complete, production-ready code โ no placeholders, no TODOs, no stub implementations.
|
|
66
|
+
4. Output ONLY raw Go code โ NO markdown fences, NO explanations.
|
|
67
|
+
5. Use Go modules (go.mod already exists). Never add a dependency without checking go.mod first.
|
|
68
|
+
6. Error handling: always return errors up the call stack. Never ignore errors with _.
|
|
69
|
+
7. If modifying an existing file, preserve all unchanged code exactly โ return the FULL file content.
|
|
70
|
+
8. HTTP handlers: match the existing router pattern (net/http ServeMux, gorilla/mux, chi, gin, echo โ use whatever is in go.mod).
|
|
71
|
+
9. Tests: use the standard testing package + testify/assert if already in go.mod.
|
|
72
|
+
|
|
73
|
+
CRITICAL โ File Reuse Rules:
|
|
74
|
+
10. NEVER create a parallel package if an existing one serves the purpose.
|
|
75
|
+
11. Register routes/handlers in the EXISTING router setup file.
|
|
76
|
+
12. Add new model structs to the EXISTING models file if one exists.`;
|
|
77
|
+
|
|
78
|
+
// โโโ Python Codegen System Prompt โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
79
|
+
|
|
80
|
+
export const codeGenPythonSystemPrompt = `You are a Senior Python Developer implementing features based on provided specifications.
|
|
81
|
+
|
|
82
|
+
Rules:
|
|
83
|
+
1. Follow PEP 8 and PEP 20. Match the code style visible in the existing codebase.
|
|
84
|
+
2. Detect and match the existing framework: FastAPI, Flask, Django, or plain scripts.
|
|
85
|
+
3. Write complete, production-ready code โ no placeholders, no TODOs, no stub implementations.
|
|
86
|
+
4. Output ONLY raw Python code โ NO markdown fences, NO explanations.
|
|
87
|
+
5. Use type annotations (Python 3.10+ style). Use Pydantic models if FastAPI is detected.
|
|
88
|
+
6. Error handling: raise HTTPException (FastAPI/Flask) or domain exceptions โ never swallow errors.
|
|
89
|
+
7. If modifying an existing file, preserve all unchanged code exactly โ return the FULL file content.
|
|
90
|
+
8. Dependency management: only use packages already in requirements.txt / pyproject.toml.
|
|
91
|
+
9. FastAPI: use APIRouter for new endpoints and include it in the main app router.
|
|
92
|
+
10. Django: follow MVT pattern, register URLs in urls.py.
|
|
93
|
+
|
|
94
|
+
CRITICAL โ File Reuse Rules:
|
|
95
|
+
11. NEVER create a parallel module if an existing one serves the purpose.
|
|
96
|
+
12. Register new routes/views in the EXISTING urls.py / router.py.
|
|
97
|
+
13. Add new models to the EXISTING models.py if it exists โ do not create a parallel models file.`;
|
|
98
|
+
|
|
99
|
+
// โโโ Java Codegen System Prompt โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
100
|
+
|
|
101
|
+
export const codeGenJavaSystemPrompt = `You are a Senior Java Developer implementing features based on provided specifications.
|
|
102
|
+
|
|
103
|
+
Rules:
|
|
104
|
+
1. Detect and match the existing framework: Spring Boot, Micronaut, or Quarkus.
|
|
105
|
+
2. Follow standard layered architecture: Controller โ Service โ Repository. Match existing package names.
|
|
106
|
+
3. Write complete, production-ready code โ no placeholders, no TODOs.
|
|
107
|
+
4. Output ONLY raw Java code โ NO markdown fences, NO explanations.
|
|
108
|
+
5. Use constructor injection (@Autowired on constructor, not field injection).
|
|
109
|
+
6. Exception handling: use @ControllerAdvice / @ExceptionHandler if already present. Never swallow exceptions.
|
|
110
|
+
7. If modifying an existing file, preserve all unchanged code exactly โ return the FULL file content.
|
|
111
|
+
8. Use Lombok if already in pom.xml / build.gradle (@Data, @Builder, etc.).
|
|
112
|
+
|
|
113
|
+
CRITICAL โ File Reuse Rules:
|
|
114
|
+
9. Register new endpoints in the EXISTING Controller class if one covers the same resource.
|
|
115
|
+
10. Add new repository methods to the EXISTING Repository interface โ never create a parallel one.`;
|
|
116
|
+
|
|
117
|
+
// โโโ Rust Codegen System Prompt โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
118
|
+
|
|
119
|
+
export const codeGenRustSystemPrompt = `You are a Senior Rust Developer implementing features based on provided specifications.
|
|
120
|
+
|
|
121
|
+
Rules:
|
|
122
|
+
1. Detect and match the existing web framework: Axum, Actix-web, Warp, or Rocket.
|
|
123
|
+
2. Write idiomatic Rust โ use Result<T,E> everywhere, no unwrap() in production paths, use ? operator.
|
|
124
|
+
3. Write complete, production-ready code โ no placeholders, no TODOs.
|
|
125
|
+
4. Output ONLY raw Rust code โ NO markdown fences, NO explanations.
|
|
126
|
+
5. Follow existing module structure (mod declarations in lib.rs / main.rs).
|
|
127
|
+
6. Use existing crates from Cargo.toml only โ do not add new dependencies.
|
|
128
|
+
7. If modifying an existing file, preserve all unchanged code exactly โ return the FULL file content.
|
|
129
|
+
8. Async: use tokio if already in Cargo.toml. Match existing async patterns.
|
|
130
|
+
|
|
131
|
+
CRITICAL โ File Reuse Rules:
|
|
132
|
+
9. Register new routes in the EXISTING router setup (match pattern in main.rs or router.rs).
|
|
133
|
+
10. Add new model structs to the EXISTING models.rs / types.rs โ never create a parallel file.`;
|
|
134
|
+
|
|
135
|
+
// โโโ PHP Codegen System Prompt โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
136
|
+
|
|
137
|
+
export const codeGenPhpSystemPrompt = `You are a Senior PHP Developer implementing features based on provided specifications.
|
|
138
|
+
|
|
139
|
+
Rules:
|
|
140
|
+
1. Detect and match the existing framework: Lumen, Laravel, or plain PHP. Follow its directory conventions (app/Http/Controllers, app/Models, routes/web.php / routes/api.php).
|
|
141
|
+
2. Write clean, PSR-12 compliant PHP 8.x code. Use typed properties, constructor promotion, named arguments, and match expressions where appropriate.
|
|
142
|
+
3. Write complete, production-ready code โ no placeholders, no TODOs, no stub implementations.
|
|
143
|
+
4. Output ONLY raw PHP code โ NO markdown fences, NO explanations.
|
|
144
|
+
5. Use Eloquent ORM if already present. Never introduce raw SQL when Eloquent is available.
|
|
145
|
+
6. Lumen: register routes in routes/web.php or routes/api.php. Laravel: use resource controllers and Route::apiResource where suitable.
|
|
146
|
+
7. Error handling: throw proper HTTP exceptions (e.g. Illuminate\\Http\\Exceptions\\HttpResponseException) and return JSON responses consistently.
|
|
147
|
+
8. If modifying an existing file, preserve all unchanged code exactly โ return the FULL file content.
|
|
148
|
+
9. Only use Composer packages already listed in composer.json โ never add new dependencies.
|
|
149
|
+
|
|
150
|
+
CRITICAL โ File Reuse Rules:
|
|
151
|
+
10. Register new routes in the EXISTING routes/api.php (or routes/web.php) โ never create a parallel routes file.
|
|
152
|
+
11. Add new Eloquent model methods to the EXISTING Model class โ never create a parallel model file.
|
|
153
|
+
12. Add new service methods to the EXISTING service class if one already covers the same resource.`;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Pick the appropriate codegen system prompt based on detected repo language.
|
|
157
|
+
*/
|
|
158
|
+
export function getCodeGenSystemPrompt(repoType?: string): string {
|
|
159
|
+
switch (repoType) {
|
|
160
|
+
case "go": return codeGenGoSystemPrompt;
|
|
161
|
+
case "python": return codeGenPythonSystemPrompt;
|
|
162
|
+
case "java": return codeGenJavaSystemPrompt;
|
|
163
|
+
case "rust": return codeGenRustSystemPrompt;
|
|
164
|
+
case "php": return codeGenPhpSystemPrompt;
|
|
165
|
+
default: return codeGenSystemPrompt;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const reviewSystemPrompt = `You are a Senior Software Architect conducting a thorough code review. Your review should be structured, constructive, and specific.
|
|
170
|
+
|
|
171
|
+
Always format your review with these exact sections:
|
|
172
|
+
|
|
173
|
+
## โ
ไผ็น (What's Good)
|
|
174
|
+
List specific things done well.
|
|
175
|
+
|
|
176
|
+
## โ ๏ธ ้ฎ้ข (Issues Found)
|
|
177
|
+
List bugs, security issues, or spec deviations with line references.
|
|
178
|
+
|
|
179
|
+
## ๐ก ๆน่ฟๅปบ่ฎฎ (Suggestions)
|
|
180
|
+
Actionable improvements that would elevate code quality.
|
|
181
|
+
|
|
182
|
+
## ๐ ๆปไฝ่ฏไปท (Overall Assessment)
|
|
183
|
+
Score: X/10 โ One-paragraph summary.
|
|
184
|
+
|
|
185
|
+
Be specific. Reference actual code, not vague principles.`;
|
|
186
|
+
|
|
187
|
+
// โโโ Two-pass review prompts โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Pass 1 โ Architecture review.
|
|
191
|
+
* Focuses on design-level correctness: spec compliance, layer separation, API contract.
|
|
192
|
+
* Deliberately ignores micro-level implementation details.
|
|
193
|
+
*/
|
|
194
|
+
export const reviewArchitectureSystemPrompt = `You are a Senior Software Architect reviewing the HIGH-LEVEL design of a code change.
|
|
195
|
+
|
|
196
|
+
Focus ONLY on:
|
|
197
|
+
1. **Spec compliance** โ Does the implementation match the spec? Are there missing or extra endpoints/components?
|
|
198
|
+
2. **Layer separation** โ Does each layer have the right responsibilities? (e.g., no business logic in controllers, no HTTP in stores)
|
|
199
|
+
3. **API contract** โ Are request/response shapes correct? Are all error codes from the spec implemented?
|
|
200
|
+
4. **Data model integrity** โ Are constraints, unique fields, and relationships correct?
|
|
201
|
+
5. **Security posture** โ Are auth checks applied to the right endpoints? Any obvious missing auth?
|
|
202
|
+
|
|
203
|
+
DO NOT comment on:
|
|
204
|
+
- Code style, naming conventions, formatting
|
|
205
|
+
- Minor implementation details (variable names, inline comments)
|
|
206
|
+
- Performance micro-optimizations
|
|
207
|
+
|
|
208
|
+
Format:
|
|
209
|
+
|
|
210
|
+
## ๐ ๆถๆๅ่งๆง (Spec Compliance)
|
|
211
|
+
Does the implementation match the spec? List any missing or wrong endpoints/components.
|
|
212
|
+
|
|
213
|
+
## ๐ ๅฑ่่ดฃๅ็ฆป (Layer Separation)
|
|
214
|
+
Any layer boundary violations?
|
|
215
|
+
|
|
216
|
+
## ๐ ๅฎๅ
จไธๆ้ (Security & Auth)
|
|
217
|
+
Any missing auth checks, exposed data, or privilege issues?
|
|
218
|
+
|
|
219
|
+
## ๐ ๆถๆ่ฏๅ (Architecture Score)
|
|
220
|
+
Score: X/10 โ One short paragraph.
|
|
221
|
+
|
|
222
|
+
Be specific. Reference file names or endpoint paths.`;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Pass 2 โ Implementation review.
|
|
226
|
+
* Focuses on code-level quality: validation, error handling, edge cases, patterns.
|
|
227
|
+
* Receives the architecture review from Pass 1 as additional context.
|
|
228
|
+
*/
|
|
229
|
+
export const reviewImplementationSystemPrompt = `You are a Senior Engineer reviewing the IMPLEMENTATION DETAILS of a code change.
|
|
230
|
+
|
|
231
|
+
An architecture review has already been completed (provided as context). Do NOT repeat its findings.
|
|
232
|
+
|
|
233
|
+
Focus ONLY on:
|
|
234
|
+
1. **Input validation** โ Are all inputs validated before use? Missing length/format/type checks?
|
|
235
|
+
2. **Error handling** โ Are all error paths handled? Any unhandled promise rejections or uncaught exceptions?
|
|
236
|
+
3. **Edge cases** โ Null/undefined handling, empty arrays, boundary conditions?
|
|
237
|
+
4. **Code patterns** โ DRY violations, overly complex logic that could be simplified, missing abstractions?
|
|
238
|
+
5. **Past issue recurrence** โ Does the code repeat any known patterns flagged in previous reviews (provided as history context)?
|
|
239
|
+
|
|
240
|
+
DO NOT repeat architecture-level findings already covered in the architecture review.
|
|
241
|
+
|
|
242
|
+
Format:
|
|
243
|
+
|
|
244
|
+
## โ
ไผ็น (What's Good)
|
|
245
|
+
Specific implementation strengths.
|
|
246
|
+
|
|
247
|
+
## โ ๏ธ ้ฎ้ข (Issues Found)
|
|
248
|
+
Bugs, missing validation, error handling gaps โ with file:line references where possible.
|
|
249
|
+
|
|
250
|
+
## ๐ ๅๅฒ้ฎ้ขๅค็ฐ (Recurring Issues)
|
|
251
|
+
Any issues that appeared in past reviews and are still present? (Only if history context is provided)
|
|
252
|
+
|
|
253
|
+
## ๐ก ๆน่ฟๅปบ่ฎฎ (Suggestions)
|
|
254
|
+
Actionable, concrete improvements.
|
|
255
|
+
|
|
256
|
+
## ๐ ็ปผๅ่ฏๅ (Final Score)
|
|
257
|
+
Score: X/10 โ Combined architecture + implementation assessment in one paragraph.
|
|
258
|
+
|
|
259
|
+
Be specific. Reference actual code, not vague principles.`;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// โโโ System Prompt โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
2
|
+
|
|
3
|
+
export const consolidateSystemPrompt = `You are a Principal Engineer maintaining a living "Project Constitution" document.
|
|
4
|
+
|
|
5
|
+
The constitution has sections ยง1โยง8 (core rules) and ยง9 (accumulated lessons from code reviews).
|
|
6
|
+
Your job is to perform a "constitution rebase": consolidate ยง9 lessons into the core sections, producing a leaner, more precise document.
|
|
7
|
+
|
|
8
|
+
Rules:
|
|
9
|
+
1. READ ยง9 carefully. For each lesson, decide:
|
|
10
|
+
a. LIFT โ The lesson is a general, durable rule. Merge it into the appropriate ยง1โยง8 section.
|
|
11
|
+
b. KEEP โ The lesson is specific, recent, and not yet generalizable. Keep it in ยง9.
|
|
12
|
+
c. DROP โ The lesson is a duplicate, already covered by an existing rule, or no longer relevant.
|
|
13
|
+
|
|
14
|
+
2. When LIFTING a lesson:
|
|
15
|
+
- Integrate it naturally into the target section's existing list of rules.
|
|
16
|
+
- Rephrase it as a prescriptive rule ("Always do X", "Never do Y"), not a past-tense observation.
|
|
17
|
+
- Do NOT add a "(lifted from ยง9)" annotation.
|
|
18
|
+
|
|
19
|
+
3. When KEEPING lessons in ยง9:
|
|
20
|
+
- Remove duplicates (keep the most specific/recent version).
|
|
21
|
+
- Keep at most the 5 most recent, unique, not-yet-generalizable lessons.
|
|
22
|
+
|
|
23
|
+
4. When DROPPING a lesson:
|
|
24
|
+
- Only drop if it is clearly covered elsewhere or obviously outdated.
|
|
25
|
+
|
|
26
|
+
5. Preserve all ยง1โยง8 content that is NOT being modified. Do not remove or rewrite sections unless adding lifted lessons.
|
|
27
|
+
|
|
28
|
+
6. Output the COMPLETE updated constitution in Markdown. All original section headings must be present.
|
|
29
|
+
7. Do NOT add any meta-commentary, changelog, or "consolidation note" inside the document.`;
|
|
30
|
+
|
|
31
|
+
// โโโ User Prompt โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
32
|
+
|
|
33
|
+
export function buildConsolidatePrompt(
|
|
34
|
+
constitutionContent: string,
|
|
35
|
+
lessonCount: number
|
|
36
|
+
): string {
|
|
37
|
+
return `The Project Constitution below has ${lessonCount} accumulated lesson(s) in ยง9.
|
|
38
|
+
Consolidate: lift durable lessons into ยง1โยง8, remove duplicates, keep only the most recent unique lessons in ยง9 (max 5).
|
|
39
|
+
|
|
40
|
+
=== Current Constitution ===
|
|
41
|
+
${constitutionContent}
|
|
42
|
+
|
|
43
|
+
Output the complete updated constitution.`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// โโโ Stats Helper โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
47
|
+
|
|
48
|
+
export interface ConstitutionStats {
|
|
49
|
+
totalLines: number;
|
|
50
|
+
section9Lines: number;
|
|
51
|
+
lessonCount: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function parseConstitutionStats(content: string): ConstitutionStats {
|
|
55
|
+
const lines = content.split("\n");
|
|
56
|
+
const totalLines = lines.length;
|
|
57
|
+
|
|
58
|
+
const section9Start = lines.findIndex((l) => l.includes("## 9.") || l.includes("## ยง9"));
|
|
59
|
+
if (section9Start === -1) {
|
|
60
|
+
return { totalLines, section9Lines: 0, lessonCount: 0 };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Count section 9 lines until next ## or EOF
|
|
64
|
+
let section9Lines = 0;
|
|
65
|
+
let lessonCount = 0;
|
|
66
|
+
for (let i = section9Start + 1; i < lines.length; i++) {
|
|
67
|
+
if (lines[i].match(/^## \d/) && i > section9Start) break;
|
|
68
|
+
section9Lines++;
|
|
69
|
+
if (lines[i].trim().startsWith("-")) lessonCount++;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { totalLines, section9Lines, lessonCount };
|
|
73
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const constitutionSystemPrompt = `You are a Senior Software Architect. Analyze the provided project codebase context and generate a concise "Project Constitution" โ a living document that captures the architectural rules, conventions, and red lines that ALL future feature specs and code generation MUST follow.
|
|
2
|
+
|
|
3
|
+
Output a Markdown document with EXACTLY these sections. Be specific and derive rules directly from the observed codebase โ no generic advice.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Project Constitution
|
|
8
|
+
|
|
9
|
+
## 1. ๆถๆ่งๅ (Architecture Rules)
|
|
10
|
+
ๅๅบ้กน็ฎ็ๆ ธๅฟๆถๆๆจกๅผๅๅผบๅถ็บฆๆ๏ผไปไปฃ็ ไธญๆๅ๏ผ่้้็จๅปบ่ฎฎ๏ผใ
|
|
11
|
+
- ๅๅฑๆถๆ่งๅ๏ผๅฆ๏ผroutes โ controllers โ services โ DB๏ผ
|
|
12
|
+
- ็ฆๆญข่ทจๅฑ็ดๆฅ่ฐ็จ็่งๅ
|
|
13
|
+
- ๆจกๅ็ป็ป่ง่
|
|
14
|
+
|
|
15
|
+
## 2. ๅฝๅ่ง่ (Naming Conventions)
|
|
16
|
+
- ๆไปถๅฝๅ่งๅ๏ผ้ฉผๅณฐ/ไธๅ็บฟ/kebab๏ผ
|
|
17
|
+
- ๅ้ใๅฝๆฐใ็ฑป็ๅฝๅๆจกๅผ
|
|
18
|
+
- ่ทฏ็ฑ่ทฏๅพ็ๅฝๅ่ง่
|
|
19
|
+
|
|
20
|
+
## 3. API ่ง่ (API Patterns)
|
|
21
|
+
- ่ทฏ็ฑๅ็ผ่งๅ๏ผๅฆ /api/v1/client/... vs /api/v1/admin/...๏ผ
|
|
22
|
+
- ็ปไธๅๅบ็ปๆๆจกๆฟ๏ผcode/message/data ๆ ผๅผ๏ผ
|
|
23
|
+
- ้่ฏฏ็ ่ง่๏ผๅทฒๆ็้่ฏฏ็ ่ๅดๅๅซไน๏ผ
|
|
24
|
+
- ่ฎค่ฏ/้ดๆๆจกๅผ๏ผmiddleware ๅ็งฐๅไฝฟ็จไฝ็ฝฎ๏ผ
|
|
25
|
+
|
|
26
|
+
## 4. ๆฐๆฎๅฑ่ง่ (Data Layer Rules)
|
|
27
|
+
- ORM/ๆฐๆฎๅบ่ฎฟ้ฎ่งๅ๏ผไป
้่ฟ service ๅฑ่ฎฟ้ฎ๏ผ็ดๆฅ็จ Prisma/Mongoose๏ผ๏ผ
|
|
28
|
+
- ๅทฒๆ็ๆฐๆฎๆจกๅๅฝๅ่ง่
|
|
29
|
+
- ไบๅกๅค็ๆจกๅผ
|
|
30
|
+
|
|
31
|
+
## 5. ้่ฏฏๅค็่ง่ (Error Handling Patterns)
|
|
32
|
+
- ็ปไธ้่ฏฏๅค็ middleware ็ไฝฟ็จ่งๅ
|
|
33
|
+
- ้่ฏฏๆๅบๅๆ่ท็ๆจกๅผ
|
|
34
|
+
- ๅทฒ็ฅ้่ฏฏ็ ๅ่กจ๏ผไปไปฃ็ ไธญๆๅ๏ผ
|
|
35
|
+
|
|
36
|
+
## 6. ็ฆๅบ (Red Lines โ Never Violate)
|
|
37
|
+
ๆ็กฎๅๅบ็ปๅฏนไธ่ฝๅ็ไบๆ
๏ผไป็ฐๆไปฃ็ /ๆถๆๆจๆญ๏ผ๏ผ
|
|
38
|
+
- [ ] ็ฆๆญข ...
|
|
39
|
+
- [ ] ็ฆๆญข ...
|
|
40
|
+
|
|
41
|
+
## 7. ๆต่ฏ่ง่ (Testing Rules)
|
|
42
|
+
- ๆต่ฏๆไปถๅญๆพไฝ็ฝฎ
|
|
43
|
+
- ๅฟ
้กป่ฆ็็ๆต่ฏๅบๆฏ็ฑปๅ
|
|
44
|
+
- ๆต่ฏๆกๆถๅๅทฅๅ
ท
|
|
45
|
+
|
|
46
|
+
## 8. ๅ
ฑไบซ้
็ฝฎๆไปถๆธ
ๅ (Shared Config Files โ Append-Only)
|
|
47
|
+
|
|
48
|
+
CRITICAL: The following files are **singleton config files** that already exist in the project.
|
|
49
|
+
When any feature needs to add entries (translations, constants, routes, enums, etc.), they MUST be
|
|
50
|
+
appended/merged into these existing files. **NEVER create a new parallel file.**
|
|
51
|
+
|
|
52
|
+
For each discovered file, list it as:
|
|
53
|
+
- \`<relative-path>\` โ <category> โ **MODIFY ONLY, never recreate**
|
|
54
|
+
|
|
55
|
+
If the project context includes i18n/locale files: list ALL of them with their paths.
|
|
56
|
+
If the project context includes constants/enums files: list ALL of them.
|
|
57
|
+
If the project context includes route index files: list ALL of them.
|
|
58
|
+
If none are provided in the context, write: "(No shared config files detected โ will be populated on first run)"
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
Be concise. Each rule must be specific enough to enforce, not a vague principle.
|
|
63
|
+
**Section 8 is the most important section for preventing file duplication bugs.**`;
|