specpilot 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +54 -1
  2. package/dist/commands/add-specs.d.ts.map +1 -1
  3. package/dist/commands/add-specs.js +4 -9
  4. package/dist/commands/add-specs.js.map +1 -1
  5. package/dist/commands/init.d.ts.map +1 -1
  6. package/dist/commands/init.js +83 -14
  7. package/dist/commands/init.js.map +1 -1
  8. package/dist/commands/list.d.ts.map +1 -1
  9. package/dist/commands/list.js +23 -3
  10. package/dist/commands/list.js.map +1 -1
  11. package/dist/commands/migrate.d.ts.map +1 -1
  12. package/dist/commands/migrate.js.map +1 -1
  13. package/dist/commands/specify.d.ts.map +1 -1
  14. package/dist/commands/specify.js +98 -15
  15. package/dist/commands/specify.js.map +1 -1
  16. package/dist/commands/validate.d.ts.map +1 -1
  17. package/dist/commands/validate.js.map +1 -1
  18. package/dist/utils/agentConfigGenerator.d.ts +15 -0
  19. package/dist/utils/agentConfigGenerator.d.ts.map +1 -0
  20. package/dist/utils/agentConfigGenerator.js +234 -0
  21. package/dist/utils/agentConfigGenerator.js.map +1 -0
  22. package/dist/utils/codeAnalyzer.js +10 -10
  23. package/dist/utils/codeAnalyzer.js.map +1 -1
  24. package/dist/utils/frameworks.d.ts +2 -0
  25. package/dist/utils/frameworks.d.ts.map +1 -0
  26. package/dist/utils/frameworks.js +11 -0
  27. package/dist/utils/frameworks.js.map +1 -0
  28. package/dist/utils/ideConfigGenerator.d.ts +20 -0
  29. package/dist/utils/ideConfigGenerator.d.ts.map +1 -0
  30. package/dist/utils/ideConfigGenerator.js +176 -0
  31. package/dist/utils/ideConfigGenerator.js.map +1 -0
  32. package/dist/utils/logger.d.ts.map +1 -1
  33. package/dist/utils/logger.js +8 -12
  34. package/dist/utils/logger.js.map +1 -1
  35. package/dist/utils/projectDetector.d.ts.map +1 -1
  36. package/dist/utils/projectDetector.js.map +1 -1
  37. package/dist/utils/projectMigrator.d.ts.map +1 -1
  38. package/dist/utils/projectMigrator.js +36 -33
  39. package/dist/utils/projectMigrator.js.map +1 -1
  40. package/dist/utils/specFileGenerator.d.ts +25 -0
  41. package/dist/utils/specFileGenerator.d.ts.map +1 -0
  42. package/dist/utils/specFileGenerator.js +677 -0
  43. package/dist/utils/specFileGenerator.js.map +1 -0
  44. package/dist/utils/specGenerator.d.ts +11 -14
  45. package/dist/utils/specGenerator.d.ts.map +1 -1
  46. package/dist/utils/specGenerator.js +24 -430
  47. package/dist/utils/specGenerator.js.map +1 -1
  48. package/dist/utils/specValidator.d.ts.map +1 -1
  49. package/dist/utils/specValidator.js +4 -6
  50. package/dist/utils/specValidator.js.map +1 -1
  51. package/dist/utils/templateEngine.d.ts +9 -3
  52. package/dist/utils/templateEngine.d.ts.map +1 -1
  53. package/dist/utils/templateEngine.js +36 -36
  54. package/dist/utils/templateEngine.js.map +1 -1
  55. package/package.json +8 -4
@@ -0,0 +1,677 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecFileGenerator = void 0;
4
+ const path_1 = require("path");
5
+ const fs_1 = require("fs");
6
+ /**
7
+ * Generates all `.specs/` markdown and YAML files.
8
+ * Responsible only for content inside the specs directory.
9
+ */
10
+ class SpecFileGenerator {
11
+ constructor(templateEngine) {
12
+ this.templateEngine = templateEngine;
13
+ // ── README templates ────────────────────────────────────────────
14
+ this.NEW_PROJECT_README = `# SpecPilot Specifications
15
+
16
+ This folder contains structured documentation for your project.
17
+
18
+ ## 🚀 Quick Start: Generate Your Specs with AI
19
+
20
+ Your specs files have been scaffolded with placeholders. Use your AI agent to draft them based on the project description you provided during \`specpilot init\`.
21
+
22
+ ### Step 1: Copy the Onboarding Prompt
23
+ 1. Open [\`development/prompts.md\`](development/prompts.md).
24
+ 2. Find the **"New Project Onboarding Prompt"** section.
25
+ 3. Copy the entire fenced code block (\`\`\`...\`\`\`).
26
+
27
+ ### Step 2: Paste into Your AI Agent
28
+ 1. In your IDE (VS Code, Cursor, etc.), open the AI chat.
29
+ 2. Paste the prompt and run it.
30
+ 3. The AI will draft all spec files based on your project description.
31
+
32
+ ### Step 3: Review & Refine
33
+ - The generated specs are a **starting point** based on the AI's understanding.
34
+ - Review each file — change, add, or remove anything as your project evolves.
35
+ - Add details the AI couldn't know before you start coding.
36
+ - Run \`specpilot validate\` to ensure consistency.
37
+
38
+ ## 📁 File Structure
39
+ - \`project/\`: Metadata and requirements
40
+ - \`architecture/\`: Design and APIs
41
+ - \`planning/\`: Tasks and roadmap
42
+ - \`quality/\`: Testing
43
+ - \`development/\`: Docs and prompts
44
+
45
+ ## 🛠️ Commands
46
+ \\\`\\\`\\\`bash
47
+ # Validate your specs
48
+ specpilot validate
49
+
50
+ # Add specs to an existing project later
51
+ specpilot add-specs
52
+ \\\`\\\`\\\`
53
+
54
+ For AI guidelines and prompt history, see [\`development/prompts.md\`](development/prompts.md).`;
55
+ this.EXISTING_PROJECT_README = `# SpecPilot Specifications
56
+
57
+ This folder contains structured documentation for your codebase.
58
+
59
+ ## 🚀 Quick Start: Populate Your Specs
60
+
61
+ Your specs files have been scaffolded with placeholders. Use your AI agent to populate them by analyzing your existing codebase.
62
+
63
+ ### Step 1: Copy the Onboarding Prompt
64
+ 1. Open [\`development/prompts.md\`](development/prompts.md).
65
+ 2. Find the **"Existing Project Onboarding Prompt"** section.
66
+ 3. Copy the entire fenced code block (\`\`\`...\`\`\`).
67
+
68
+ ### Step 2: Paste into Your AI Agent
69
+ 1. In your IDE (VS Code, Cursor, etc.), open the AI chat.
70
+ 2. Paste the prompt and run it.
71
+ 3. The AI will analyze your codebase and populate all spec files.
72
+
73
+ ### Step 3: Review & Iterate
74
+ - Check the generated content in each \`.specs\` file.
75
+ - Refine as needed (e.g., add missing details).
76
+ - Run \`specpilot validate\` to ensure consistency.
77
+
78
+ ## 📁 File Structure
79
+ - \`project/\`: Metadata and requirements
80
+ - \`architecture/\`: Design and APIs
81
+ - \`planning/\`: Tasks and roadmap
82
+ - \`quality/\`: Testing
83
+ - \`development/\`: Docs and prompts
84
+
85
+ ## 🛠️ Commands
86
+ \\\`\\\`\\\`bash
87
+ # Validate your specs
88
+ specpilot validate
89
+
90
+ # Update specs after code changes
91
+ specpilot add-specs
92
+ \\\`\\\`\\\`
93
+
94
+ For AI guidelines and prompt history, see [\`development/prompts.md\`](development/prompts.md).`;
95
+ }
96
+ /** Generate all spec files into the pre-created specs directory. */
97
+ async generateAll(specsDir, context) {
98
+ await this.generateReadmeMd(specsDir, context);
99
+ await this.generateProjectYaml((0, path_1.join)(specsDir, 'project'), context);
100
+ await this.generateRequirementsMd((0, path_1.join)(specsDir, 'project'), context);
101
+ await this.generateArchitectureMd((0, path_1.join)(specsDir, 'architecture'), context);
102
+ await this.generateApiYaml((0, path_1.join)(specsDir, 'architecture'), context);
103
+ await this.generateTasksMd((0, path_1.join)(specsDir, 'planning'), context);
104
+ await this.generateRoadmapMd((0, path_1.join)(specsDir, 'planning'), context);
105
+ await this.generateDocsMd((0, path_1.join)(specsDir, 'development'), context);
106
+ await this.generateContextMd((0, path_1.join)(specsDir, 'development'), context);
107
+ await this.generatePromptsMd((0, path_1.join)(specsDir, 'development'), context);
108
+ await this.generateTestsMd((0, path_1.join)(specsDir, 'quality'), context);
109
+ }
110
+ async generateReadmeMd(specsDir, context) {
111
+ const template = context.mode === 'existing' ? this.EXISTING_PROJECT_README : this.NEW_PROJECT_README;
112
+ const rendered = this.templateEngine.renderFromString(template, context);
113
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'README.md'), rendered);
114
+ }
115
+ async generateProjectYaml(specsDir, context) {
116
+ const template = this.templateEngine.getBuiltinTemplate(context.language, context.framework, 'project.yaml');
117
+ const content = this.templateEngine.renderFromString(template, context);
118
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'project.yaml'), content);
119
+ }
120
+ async generateArchitectureMd(specsDir, context) {
121
+ const template = this.templateEngine.getBuiltinTemplate(context.language, context.framework, 'architecture.md');
122
+ const content = this.templateEngine.renderFromString(template, context);
123
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'architecture.md'), content);
124
+ }
125
+ async generateRequirementsMd(specsDir, context) {
126
+ const content = `---
127
+ title: Requirements
128
+ project: {{projectName}}
129
+ language: {{language}}
130
+ framework: {{framework}}
131
+ lastUpdated: {{currentDate}}
132
+ sourceOfTruth: project/project.yaml
133
+ ---
134
+
135
+ # {{projectName}} Requirements
136
+
137
+ ## Project Overview
138
+ {{description}}
139
+
140
+ ## Functional Requirements
141
+ [TODO: Add requirements with proper template]
142
+
143
+ ## Cross-References
144
+ - Architecture: ../architecture/architecture.md
145
+ - API: ../architecture/api.yaml
146
+ - Project config: ../project/project.yaml
147
+
148
+ ---
149
+ *Last updated: {{currentDate}}*`;
150
+ const rendered = this.templateEngine.renderFromString(content, context);
151
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'requirements.md'), rendered);
152
+ }
153
+ async generateApiYaml(specsDir, context) {
154
+ const content = `# .specs/architecture/api.yaml
155
+ # ------------------------------------------------------------
156
+ # API & Interface Specification
157
+ # Remove the section(s) that don't apply to your project.
158
+ # meta: project={{projectName}} language={{language}} framework={{framework}} updated={{currentDate}}
159
+ # ------------------------------------------------------------
160
+
161
+ project: "{{projectName}}"
162
+ version: "1.0.0"
163
+ lastUpdated: "{{currentDate}}"
164
+
165
+ # ============================================================
166
+ # OPTION A: REST API (remove if not a web API project)
167
+ # ============================================================
168
+ openapi: "3.0.0"
169
+ info:
170
+ title: "{{projectName}} API"
171
+ version: "1.0.0"
172
+ description: "[TODO: Describe your API]"
173
+
174
+ servers:
175
+ - url: "http://localhost:3000"
176
+ description: "Local development"
177
+
178
+ paths:
179
+ /example:
180
+ get:
181
+ summary: "[TODO: Replace with your first endpoint]"
182
+ responses:
183
+ "200":
184
+ description: "Success"
185
+
186
+ # ============================================================
187
+ # OPTION B: CLI Interface (remove if not a CLI project)
188
+ # ============================================================
189
+ cli:
190
+ name: "{{projectName}}"
191
+ version: "1.0.0"
192
+ commands:
193
+ - name: "[TODO: first-command]"
194
+ description: "[TODO: What does this command do?]"
195
+ arguments:
196
+ - name: "[TODO: arg]"
197
+ description: "[TODO: argument description]"
198
+ required: true
199
+ options:
200
+ - flag: "--example <value>"
201
+ description: "[TODO: option description]"
202
+
203
+ # ============================================================
204
+ # OPTION C: GraphQL (remove if not a GraphQL project)
205
+ # ============================================================
206
+ graphql:
207
+ endpoint: "/graphql"
208
+ queries:
209
+ - name: "[TODO: firstQuery]"
210
+ description: "[TODO: What does this query return?]"
211
+ mutations:
212
+ - name: "[TODO: firstMutation]"
213
+ description: "[TODO: What does this mutation do?]"
214
+ `;
215
+ const rendered = this.templateEngine.renderFromString(content, context);
216
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'api.yaml'), rendered);
217
+ }
218
+ async generateTasksMd(specsDir, context) {
219
+ const content = `---
220
+ fileID: TASKS-001
221
+ lastUpdated: {{currentDate}}
222
+ version: 1.0
223
+ contributors: [{{author}}]
224
+ relatedFiles: [roadmap.md, project.yaml, requirements.md]
225
+ ---
226
+
227
+ # {{projectName}} — Task Tracking
228
+
229
+ Task ID conventions
230
+
231
+ - BL-###: Backlog items
232
+ - CS-###: Current Sprint items
233
+ - CD-###: Completed items
234
+
235
+ Notes
236
+
237
+ - IDs are stable; do not change once assigned (even if reordered or moved between sections).
238
+ - Reference tasks by ID in commits, prompts, PRs, and discussions.
239
+ - When moving an item from Backlog to Current Sprint, retain its original BL ID or create a CS mirror that references the BL ID.
240
+ - Archive guidance: when Completed grows large, move older entries to \`tasks-archive.md\` and add a pointer here.
241
+
242
+ ## Backlog
243
+
244
+ 1. [BL-001] Plan initial feature set
245
+ 2. [BL-002] Gather user feedback and feature requests
246
+ 3. [BL-003] Write documentation and usage guide
247
+
248
+ ## Current Sprint
249
+
250
+ 1. [CS-001] Set up project foundation and tooling
251
+ 2. [CS-002] Implement core features
252
+ 3. [CS-003] Write unit tests
253
+
254
+ ## Completed
255
+
256
+ 1. [CD-001] Initialise .specs directory ({{currentDate}})
257
+
258
+ ## Cross-References
259
+
260
+ - Roadmap (milestones): ./roadmap.md
261
+ - Requirements: ../project/requirements.md
262
+ - Project config: ../project/project.yaml`;
263
+ const rendered = this.templateEngine.renderFromString(content, context);
264
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'tasks.md'), rendered);
265
+ }
266
+ async generateRoadmapMd(specsDir, context) {
267
+ const content = `---
268
+ title: Roadmap
269
+ project: {{projectName}}
270
+ language: {{language}}
271
+ framework: {{framework}}
272
+ lastUpdated: {{currentDate}}
273
+ sourceOfTruth: project/project.yaml
274
+ ---
275
+
276
+ <!--
277
+ PURPOSE: Release-level milestone planner — the "when are we shipping what" file.
278
+ Scope: Quarter-level phases, version targets, feature groupings, goals, and risks.
279
+ Update cadence: Per release / per sprint planning session.
280
+
281
+ Boundary guide:
282
+ - roadmap.md → release milestones, timeline, objectives, and risks (this file)
283
+ - tasks.md → individual work items and sprint status
284
+ -->
285
+
286
+ # {{projectName}} — Development Roadmap
287
+
288
+ ## v0.1.0 — Foundation _(current)_
289
+ **Goal:** Get a working skeleton in place.
290
+ - [x] Project initialised
291
+ - [ ] Core data model implemented
292
+ - [ ] Basic CLI / API working
293
+
294
+ ## v0.2.0 — Core Features
295
+ **Goal:** Deliver the primary user-facing functionality.
296
+ - [ ] Feature A
297
+ - [ ] Feature B
298
+ - [ ] Unit test coverage ≥ 80 %
299
+
300
+ ## v1.0.0 — Production Ready
301
+ **Goal:** Stable, documented, deployable release.
302
+ - [ ] All P0/P1 requirements met
303
+ - [ ] Documentation complete
304
+ - [ ] CI/CD pipeline green
305
+
306
+ ## Unscheduled / Icebox
307
+ - [ ] Nice-to-have feature ideas go here
308
+
309
+ ## Objectives
310
+ - [Primary goal for this project]
311
+ - [Secondary goal]
312
+
313
+ ## Goals & Success Criteria
314
+ | Goal | Success Metric | Target |
315
+ |------|----------------|--------|
316
+ | [Primary goal] | [How we measure it] | [Target value] |
317
+
318
+ ## Risks and Mitigations
319
+ - [Risk 1]: [Mitigation]
320
+ - [Risk 2]: [Mitigation]
321
+
322
+ ## Cross-References
323
+ - Sprint tasks: ./tasks.md
324
+ - Requirements: ../project/requirements.md
325
+
326
+ ---
327
+ *Last updated: {{currentDate}}*`;
328
+ const rendered = this.templateEngine.renderFromString(content, context);
329
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'roadmap.md'), rendered);
330
+ }
331
+ async generateDocsMd(specsDir, context) {
332
+ const content = `---
333
+ fileID: DOC-001
334
+ lastUpdated: {{currentDate}}
335
+ version: 1.0
336
+ contributors: []
337
+ relatedFiles: [project/project.yaml, development/context.md, planning/roadmap.md, planning/tasks.md]
338
+ ---
339
+
340
+ # {{projectName}} \u2014 Development Documentation
341
+
342
+ ## Spec File Conventions
343
+
344
+ All \`.specs/\` files must include a YAML front-matter header with:
345
+ - \`fileID\`: Unique identifier (e.g., \`REQ-001\`, \`ARCH-001\`)
346
+ - \`lastUpdated\`: Date in YYYY-MM-DD format
347
+ - \`version\`: Semantic version (e.g., \`1.0\`)
348
+ - \`contributors\`: Array of contributor handles
349
+ - \`relatedFiles\`: Array of related spec file paths
350
+
351
+ Section IDs use the format \`[PREFIX-NNN.S]\` (e.g., \`[REQ-001.1]\`) and must be stable — do not change once assigned.
352
+
353
+ ## Development Procedures
354
+
355
+ ### Workflow
356
+
357
+ 1. Update relevant \`.specs/\` files before committing
358
+ 2. Write tests before implementation
359
+ 3. Use small, focused commits with conventional commit messages (\`type(scope): description\`)
360
+ 4. Log all AI interactions in \`development/prompts.md\`
361
+
362
+ ### Spec Update Checklist (before each commit)
363
+
364
+ - [ ] \`tasks.md\` \u2014 task status updated
365
+ - [ ] \`context.md\` \u2014 decisions and lessons logged
366
+ - [ ] \`requirements.md\` \u2014 updated if features changed
367
+ - [ ] \`architecture.md\` \u2014 updated if structure changed
368
+ - [ ] \`api.yaml\` \u2014 updated if CLI interface changed
369
+ - [ ] \`tests.md\` \u2014 updated if test strategy changed
370
+
371
+ ## CLI Commands Reference
372
+
373
+ \\\`\\\`\\\`bash
374
+ # Initialize a new project
375
+ specpilot init <project-name> [--lang <language>] [--framework <framework>] [--no-prompts]
376
+
377
+ # Add .specs/ to an existing project
378
+ specpilot add-specs
379
+
380
+ # List available templates
381
+ specpilot list
382
+
383
+ # Validate spec files
384
+ specpilot validate [--fix]
385
+
386
+ # Migrate to newer spec structure
387
+ specpilot migrate
388
+
389
+ # Update specs with current project context (shows diff + confirmation)
390
+ specpilot specify
391
+ \\\`\\\`\\\`
392
+
393
+ ## Cross-References
394
+ - Context: ./context.md
395
+ - Roadmap: ../planning/roadmap.md
396
+ - Tasks: ../planning/tasks.md
397
+ - Project config: ../project/project.yaml
398
+
399
+ > For contributing guidelines, troubleshooting, and support, see README.md.
400
+
401
+ ---
402
+ *Last updated: {{currentDate}}*`;
403
+ const rendered = this.templateEngine.renderFromString(content, context);
404
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'docs.md'), rendered);
405
+ }
406
+ async generateContextMd(specsDir, context) {
407
+ const content = `---
408
+ title: Development Context
409
+ project: {{projectName}}
410
+ language: {{language}}
411
+ framework: {{framework}}
412
+ lastUpdated: {{currentDate}}
413
+ sourceOfTruth: project/project.yaml
414
+ ---
415
+
416
+ # {{projectName}} Development Context
417
+
418
+ ## Project Memory
419
+ [TODO: Add project context and decisions]
420
+
421
+ ## Cross-References
422
+ - Docs: ./docs.md
423
+ - Roadmap: ../planning/roadmap.md
424
+ - Project config: ../project/project.yaml
425
+
426
+ ---
427
+ *Last updated: {{currentDate}}*`;
428
+ const rendered = this.templateEngine.renderFromString(content, context);
429
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'context.md'), rendered);
430
+ }
431
+ async generatePromptsMd(specsDir, context) {
432
+ const isNew = context.mode !== 'existing';
433
+ const pc = context.projectContext;
434
+ // ── Shared conventions block (used by both prompts) ──────────
435
+ const conventions = `**Conventions & Rules:**
436
+ 1. **IDs**: Use semantic prefixes (REQ-, TASK-, ARCH-, TEST-, etc.) with zero-padded numbers (e.g., REQ-001, TASK-042)
437
+ 2. **Status values**: Must be one of: not-started, in-progress, completed, blocked, deprecated
438
+ 3. **Priority values**: Must be: critical, high, medium, low
439
+ 4. **Dates**: Use ISO 8601 format (YYYY-MM-DD)
440
+ 5. **YAML**: Use proper indentation (2 spaces), include all required fields
441
+ 6. **Markdown**: Use ATX headers (#), fenced code blocks, and consistent formatting
442
+ 7. **Traceability**: Link requirements to tasks, tasks to tests, architecture to implementation
443
+ 8. **❌ CRITICAL**: Never modify the .specs folder structure or file names. Only update file CONTENTS. The directory structure is IMMUTABLE.
444
+
445
+ **File Structure Standards:**
446
+
447
+ - \\\`project/project.yaml\\\`: name, version, description, tech_stack[], dependencies[], metadata
448
+ - \\\`project/requirements.md\\\`: ## Functional/Non-Functional Requirements with REQ-XXX IDs, priority, status
449
+ - \\\`architecture/architecture.md\\\`: ## Overview, Components, Data Flow, Tech Stack, Decisions (ADR format)
450
+ - \\\`architecture/api.yaml\\\`: OpenAPI 3.0 spec or endpoints list with methods, paths, descriptions
451
+ - \\\`planning/tasks.md\\\`: ## Backlog/In Progress/Completed with TASK-XXX, assignee, priority, dependencies
452
+ - \\\`planning/roadmap.md\\\`: ## Milestones with versions, dates, features, status
453
+ - \\\`quality/tests.md\\\`: ## Test Strategy, Test Cases (TEST-XXX), Coverage Goals, CI/CD integration
454
+ - \\\`development/docs.md\\\`: ## Getting Started, Architecture, API, Deployment, Contributing
455
+ - \\\`development/context.md\\\`: ## Project Context, Key Decisions, Known Issues, Future Considerations`;
456
+ // ── New-project prompt ────────────────────────────────────────
457
+ const projectContextBlock = pc
458
+ ? `**Project context (provided by the developer):**
459
+ - **What it does:** ${pc.whatItDoes}
460
+ - **Target users:** ${pc.targetUsers}
461
+ - **Expected scale:** ${pc.expectedScale}
462
+ - **Key constraints:** ${pc.constraints}`
463
+ : `**Project context:**
464
+ - **What it does:** [DESCRIBE YOUR PROJECT HERE]
465
+ - **Target users:** Not specified — use your judgment and mark as [ASSUMPTION]
466
+ - **Expected scale:** Not specified — use your judgment and mark as [ASSUMPTION]
467
+ - **Key constraints:** Not specified — use your judgment and mark as [ASSUMPTION]`;
468
+ const newProjectPrompt = `You are the specification co-pilot for a new project called "{{projectName}}".
469
+ Tech stack: {{language}}{{#if framework}} / {{framework}}{{/if}}
470
+
471
+ ${projectContextBlock}
472
+
473
+ **For any areas not covered above, make reasonable assumptions. Clearly label ALL assumptions with [ASSUMPTION] so the developer can review and revise them.**
474
+
475
+ Based on this context, populate all .specs files following these strict conventions:
476
+
477
+ ${conventions}
478
+
479
+ **Your Process:**
480
+ 1. Read the project context above carefully
481
+ 2. For each .specs file, generate content that:
482
+ - Derives requirements, architecture, and tasks from the project description
483
+ - Follows the conventions above exactly
484
+ - Maintains internal consistency (cross-references work)
485
+ - Scales appropriately to project ambition (prototype = concise, production = comprehensive)
486
+ 3. Propose a realistic roadmap with milestones
487
+ 4. Draft a test strategy appropriate for the project type
488
+
489
+ **Output Format:**
490
+ For each file, provide the complete content in a markdown code block:
491
+ \\\\\`\\\\\`\\\\\`markdown
492
+ // filepath: .specs/project/project.yaml
493
+ [full file content]
494
+ \\\\\`\\\\\`\\\\\`
495
+
496
+ **Constraints:**
497
+ - These specs are a starting point — the developer will review and refine them
498
+ - Flag uncertainties and assumptions with [ASSUMPTION] comments
499
+ - Keep descriptions clear, concise, and technical
500
+ - Ensure all IDs are unique within their domain
501
+
502
+ After populating all files, provide a summary of:
503
+ - What you understood about the project
504
+ - Assumptions you made and why
505
+ - Recommended next steps before the developer starts coding
506
+
507
+ **Important:** These specifications are generated based on the AI's understanding of the project description. They are a draft — the developer should review, change, add, or remove anything as the project evolves. Add more detail into the spec files before starting AI-assisted coding.
508
+
509
+ Begin drafting now.`;
510
+ // ── Existing-project prompt ──────────────────────────────────
511
+ const existingProjectPrompt = `You are onboarding as the specification co-pilot for this repository. We just initialized the .specs directory using SpecPilot SDD. Your task is to inspect the codebase and populate all .specs files following these strict conventions:
512
+
513
+ ${conventions}
514
+
515
+ **Your Process:**
516
+ 1. Analyze the codebase: language, framework, structure, existing tests, dependencies
517
+ 2. For each .specs file, generate content that:
518
+ - Reflects the actual implementation state
519
+ - Follows the conventions above exactly
520
+ - Maintains internal consistency (cross-references work)
521
+ - Scales appropriately to project size (small projects = concise specs, large = comprehensive)
522
+ 3. Identify gaps: missing tests, undocumented APIs, unclear requirements, architectural debt
523
+ 4. Propose actionable next steps in planning/tasks.md
524
+
525
+ **Output Format:**
526
+ For each file, provide the complete content in a markdown code block:
527
+ \\\\\`\\\\\`\\\\\`markdown
528
+ // filepath: .specs/project/project.yaml
529
+ [full file content]
530
+ \\\\\`\\\\\`\\\\\`
531
+
532
+ **Constraints:**
533
+ - Maintain the exact file paths and names from the .specs structure
534
+ - Don't invent features that don't exist in the code
535
+ - Flag uncertainties with TODO comments
536
+ - Keep descriptions clear, concise, and technical
537
+ - Ensure all IDs are unique within their domain
538
+
539
+ After populating all files, provide a summary of:
540
+ - What was discovered about the project
541
+ - What's documented vs. what's implemented
542
+ - Critical gaps or risks
543
+ - Recommended immediate actions
544
+
545
+ Begin your analysis now.`;
546
+ // ── Assemble the full prompts.md ─────────────────────────────
547
+ const primaryLabel = isNew ? 'New Project' : 'Existing Project';
548
+ const secondaryLabel = isNew ? 'Existing Project' : 'New Project';
549
+ const primaryPrompt = isNew ? newProjectPrompt : existingProjectPrompt;
550
+ const secondaryPrompt = isNew ? existingProjectPrompt : newProjectPrompt;
551
+ const primaryNote = isNew
552
+ ? 'Use this prompt to have your AI agent draft all specification files based on your project description.'
553
+ : 'Use this prompt to have your AI agent analyze your codebase and populate all specification files.';
554
+ const secondaryNote = isNew
555
+ ? 'If you later need to re-generate specs from an existing codebase (e.g., after significant implementation), use this prompt instead.'
556
+ : 'If you start a fresh module or sub-project and want to plan specs before writing code, use this prompt instead.';
557
+ const content = `---
558
+ title: Prompts Log
559
+ project: {{projectName}}
560
+ language: {{language}}
561
+ framework: {{framework}}
562
+ lastUpdated: {{currentDate}}
563
+ sourceOfTruth: project/project.yaml
564
+ ---
565
+
566
+ # Development Prompts Log
567
+
568
+ ## Overview
569
+ This file (prompts.md) contains ALL AI interactions for {{projectName}}. Update .specs/prompts.md with every AI interaction.
570
+
571
+ **🚨 MANDATE**: Update with every AI interaction.
572
+
573
+ ## ${primaryLabel} Onboarding Prompt
574
+
575
+ ${primaryNote}
576
+
577
+ ~~~
578
+ ${primaryPrompt}
579
+ ~~~
580
+
581
+ ---
582
+
583
+ ## ${secondaryLabel} Onboarding Prompt (Reference)
584
+
585
+ ${secondaryNote}
586
+
587
+ ~~~
588
+ ${secondaryPrompt}
589
+ ~~~
590
+
591
+ ---
592
+
593
+ ## Re-Anchor Prompt
594
+
595
+ > Paste this into your AI agent when: the session has been running > 1 hour, you've made > 20 exchanges, or the AI seems to have forgotten project rules.
596
+
597
+ ~~~
598
+ You are working on {{projectName}} ({{language}}{{#if framework}} / {{framework}}{{/if}}).
599
+
600
+ CRITICAL RULES — re-read these before continuing:
601
+ 1. NEVER commit, push, or deploy unless I explicitly ask you to.
602
+ 2. NEVER modify .specs/ folder structure or file names — only update file contents.
603
+ 3. After EVERY code change, proactively update all affected .specs/ files without being asked.
604
+ 4. Spec-First Development — update .specs/ before writing code.
605
+ 5. Log this and all AI interactions in .specs/development/prompts.md.
606
+
607
+ For full project context, read .specs/project/project.yaml.
608
+ ~~~
609
+
610
+ ---
611
+
612
+ ## Prompt History
613
+
614
+ | Date | User | Prompt Summary | Context |
615
+ |------|------|----------------|---------|
616
+ | YYYY-MM-DD | @username | Example prompt | Brief context or outcome |
617
+
618
+ ## Common Commands
619
+
620
+ \\\`\\\`\\\`bash
621
+ # Generate specs for new project
622
+ specpilot init
623
+
624
+ # Add specs to existing project
625
+ specpilot add-specs
626
+
627
+ # Validate spec files
628
+ specpilot validate
629
+ \\\`\\\`\\\`
630
+
631
+ ## AI Agent Guidelines
632
+
633
+ When working with AI agents on this codebase:
634
+ - Always reference relevant .specs files for context
635
+ - Update specifications before/after significant changes
636
+ - Use the conventions defined in the onboarding prompt
637
+ - Link code changes to tasks (TASK-XXX) and requirements (REQ-XXX)
638
+ - Keep development/context.md current with architectural decisions
639
+ - **🚨 MANDATE**: Never modify the .specs folder structure or file names - only update file contents
640
+ - **🚨 RELEASE MANDATE**: Never commit, push, create tags, publish releases, or publish to npm without explicit user consent and approval
641
+
642
+ ## Cross-References
643
+ - Context: ./context.md
644
+ - Project config: ../project/project.yaml
645
+
646
+ ---
647
+ *Last updated: {{currentDate}}*`;
648
+ const rendered = this.templateEngine.renderFromString(content, context);
649
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'prompts.md'), rendered);
650
+ }
651
+ async generateTestsMd(specsDir, context) {
652
+ const content = `---
653
+ title: Test Strategy
654
+ project: {{projectName}}
655
+ language: {{language}}
656
+ framework: {{framework}}
657
+ lastUpdated: {{currentDate}}
658
+ sourceOfTruth: project/project.yaml
659
+ ---
660
+
661
+ # {{projectName}} Test Strategy
662
+
663
+ ## Overview
664
+ [TODO: Add testing strategy and approach]
665
+
666
+ ## Cross-References
667
+ - Requirements: ../project/requirements.md
668
+ - Project config: ../project/project.yaml
669
+
670
+ ---
671
+ *Last updated: {{currentDate}}*`;
672
+ const rendered = this.templateEngine.renderFromString(content, context);
673
+ (0, fs_1.writeFileSync)((0, path_1.join)(specsDir, 'tests.md'), rendered);
674
+ }
675
+ }
676
+ exports.SpecFileGenerator = SpecFileGenerator;
677
+ //# sourceMappingURL=specFileGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specFileGenerator.js","sourceRoot":"","sources":["../../src/utils/specFileGenerator.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,2BAAmC;AAGnC;;;GAGG;AACH,MAAa,iBAAiB;IAC5B,YAAoB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;QAElD,mEAAmE;QAE3D,uBAAkB,GAAG;;;;;;;;;;;;;;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