@fission-ai/openspec 0.12.0 → 0.14.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 (49) hide show
  1. package/README.md +24 -3
  2. package/dist/commands/change.js +6 -6
  3. package/dist/core/archive.d.ts +1 -0
  4. package/dist/core/archive.js +3 -2
  5. package/dist/core/config.js +7 -0
  6. package/dist/core/configurators/cline.d.ts +8 -0
  7. package/dist/core/configurators/cline.js +15 -0
  8. package/dist/core/configurators/codebuddy.d.ts +8 -0
  9. package/dist/core/configurators/codebuddy.js +15 -0
  10. package/dist/core/configurators/costrict.d.ts +8 -0
  11. package/dist/core/configurators/costrict.js +15 -0
  12. package/dist/core/configurators/qoder.d.ts +30 -0
  13. package/dist/core/configurators/qoder.js +42 -0
  14. package/dist/core/configurators/qwen.d.ts +24 -0
  15. package/dist/core/configurators/qwen.js +37 -0
  16. package/dist/core/configurators/registry.js +15 -0
  17. package/dist/core/configurators/slash/auggie.d.ts +9 -0
  18. package/dist/core/configurators/slash/auggie.js +31 -0
  19. package/dist/core/configurators/slash/cline.d.ts +9 -0
  20. package/dist/core/configurators/slash/cline.js +23 -0
  21. package/dist/core/configurators/slash/codebuddy.d.ts +9 -0
  22. package/dist/core/configurators/slash/codebuddy.js +37 -0
  23. package/dist/core/configurators/slash/costrict.d.ts +9 -0
  24. package/dist/core/configurators/slash/costrict.js +31 -0
  25. package/dist/core/configurators/slash/crush.d.ts +9 -0
  26. package/dist/core/configurators/slash/crush.js +37 -0
  27. package/dist/core/configurators/slash/opencode.d.ts +3 -0
  28. package/dist/core/configurators/slash/opencode.js +41 -2
  29. package/dist/core/configurators/slash/qoder.d.ts +35 -0
  30. package/dist/core/configurators/slash/qoder.js +76 -0
  31. package/dist/core/configurators/slash/qwen.d.ts +37 -0
  32. package/dist/core/configurators/slash/qwen.js +74 -0
  33. package/dist/core/configurators/slash/registry.js +21 -0
  34. package/dist/core/init.d.ts +2 -0
  35. package/dist/core/init.js +68 -17
  36. package/dist/core/parsers/requirement-blocks.d.ts +6 -0
  37. package/dist/core/parsers/requirement-blocks.js +28 -5
  38. package/dist/core/templates/agents-template.d.ts +1 -1
  39. package/dist/core/templates/agents-template.js +5 -5
  40. package/dist/core/templates/cline-template.d.ts +2 -0
  41. package/dist/core/templates/cline-template.js +2 -0
  42. package/dist/core/templates/costrict-template.d.ts +2 -0
  43. package/dist/core/templates/costrict-template.js +2 -0
  44. package/dist/core/templates/index.d.ts +2 -0
  45. package/dist/core/templates/index.js +8 -0
  46. package/dist/core/templates/slash-command-templates.js +10 -4
  47. package/dist/core/validation/validator.d.ts +1 -0
  48. package/dist/core/validation/validator.js +57 -6
  49. package/package.json +2 -2
@@ -1,4 +1,6 @@
1
1
  import { SlashCommandConfigurator } from "./base.js";
2
+ import { FileSystemUtils } from "../../../utils/file-system.js";
3
+ import { OPENSPEC_MARKERS } from "../../config.js";
2
4
  const FILE_PATHS = {
3
5
  proposal: ".opencode/command/openspec-proposal.md",
4
6
  apply: ".opencode/command/openspec-apply.md",
@@ -17,11 +19,20 @@ The user has requested the following change proposal. Use the openspec instructi
17
19
  apply: `---
18
20
  agent: build
19
21
  description: Implement an approved OpenSpec change and keep tasks in sync.
20
- ---`,
22
+ ---
23
+ The user has requested to implement the following change proposal. Find the change proposal and follow the instructions below. If you're not sure or if ambiguous, ask for clarification from the user.
24
+ <UserRequest>
25
+ $ARGUMENTS
26
+ </UserRequest>
27
+ `,
21
28
  archive: `---
22
29
  agent: build
23
30
  description: Archive a deployed OpenSpec change and update specs.
24
- ---`,
31
+ ---
32
+ <ChangeId>
33
+ $ARGUMENTS
34
+ </ChangeId>
35
+ `,
25
36
  };
26
37
  export class OpenCodeSlashCommandConfigurator extends SlashCommandConfigurator {
27
38
  toolId = "opencode";
@@ -32,5 +43,33 @@ export class OpenCodeSlashCommandConfigurator extends SlashCommandConfigurator {
32
43
  getFrontmatter(id) {
33
44
  return FRONTMATTER[id];
34
45
  }
46
+ async generateAll(projectPath, _openspecDir) {
47
+ const createdOrUpdated = await super.generateAll(projectPath, _openspecDir);
48
+ await this.rewriteArchiveFile(projectPath);
49
+ return createdOrUpdated;
50
+ }
51
+ async updateExisting(projectPath, _openspecDir) {
52
+ const updated = await super.updateExisting(projectPath, _openspecDir);
53
+ const rewroteArchive = await this.rewriteArchiveFile(projectPath);
54
+ if (rewroteArchive && !updated.includes(FILE_PATHS.archive)) {
55
+ updated.push(FILE_PATHS.archive);
56
+ }
57
+ return updated;
58
+ }
59
+ async rewriteArchiveFile(projectPath) {
60
+ const archivePath = FileSystemUtils.joinPath(projectPath, FILE_PATHS.archive);
61
+ if (!await FileSystemUtils.fileExists(archivePath)) {
62
+ return false;
63
+ }
64
+ const body = this.getBody("archive");
65
+ const frontmatter = this.getFrontmatter("archive");
66
+ const sections = [];
67
+ if (frontmatter) {
68
+ sections.push(frontmatter.trim());
69
+ }
70
+ sections.push(`${OPENSPEC_MARKERS.start}\n${body}\n${OPENSPEC_MARKERS.end}`);
71
+ await FileSystemUtils.writeFile(archivePath, sections.join("\n") + "\n");
72
+ return true;
73
+ }
35
74
  }
36
75
  //# sourceMappingURL=opencode.js.map
@@ -0,0 +1,35 @@
1
+ import { SlashCommandConfigurator } from './base.js';
2
+ import { SlashCommandId } from '../../templates/index.js';
3
+ /**
4
+ * Qoder Slash Command Configurator
5
+ *
6
+ * Manages OpenSpec slash commands for Qoder AI assistant.
7
+ * Creates three workflow commands: proposal, apply, and archive.
8
+ * Uses colon-separated command format (/openspec:proposal).
9
+ *
10
+ * @extends {SlashCommandConfigurator}
11
+ */
12
+ export declare class QoderSlashCommandConfigurator extends SlashCommandConfigurator {
13
+ /** Unique identifier for Qoder tool */
14
+ readonly toolId = "qoder";
15
+ /** Indicates slash commands are available for this tool */
16
+ readonly isAvailable = true;
17
+ /**
18
+ * Get relative file path for a slash command
19
+ *
20
+ * @param {SlashCommandId} id - Command identifier (proposal, apply, or archive)
21
+ * @returns {string} Relative path from project root to command file
22
+ */
23
+ protected getRelativePath(id: SlashCommandId): string;
24
+ /**
25
+ * Get YAML frontmatter for a slash command
26
+ *
27
+ * Frontmatter defines how the command appears in Qoder's UI,
28
+ * including display name, description, and categorization.
29
+ *
30
+ * @param {SlashCommandId} id - Command identifier (proposal, apply, or archive)
31
+ * @returns {string} YAML frontmatter block with command metadata
32
+ */
33
+ protected getFrontmatter(id: SlashCommandId): string;
34
+ }
35
+ //# sourceMappingURL=qoder.d.ts.map
@@ -0,0 +1,76 @@
1
+ import { SlashCommandConfigurator } from './base.js';
2
+ /**
3
+ * File paths for Qoder slash commands
4
+ * Maps each OpenSpec workflow stage to its command file location
5
+ * Commands are stored in .qoder/commands/openspec/ directory
6
+ */
7
+ const FILE_PATHS = {
8
+ // Create and validate new change proposals
9
+ proposal: '.qoder/commands/openspec/proposal.md',
10
+ // Implement approved changes with task tracking
11
+ apply: '.qoder/commands/openspec/apply.md',
12
+ // Archive completed changes and update specs
13
+ archive: '.qoder/commands/openspec/archive.md'
14
+ };
15
+ /**
16
+ * YAML frontmatter for Qoder slash commands
17
+ * Defines metadata displayed in Qoder's command palette
18
+ * Each command is categorized and tagged for easy discovery
19
+ */
20
+ const FRONTMATTER = {
21
+ proposal: `---
22
+ name: OpenSpec: Proposal
23
+ description: Scaffold a new OpenSpec change and validate strictly.
24
+ category: OpenSpec
25
+ tags: [openspec, change]
26
+ ---`,
27
+ apply: `---
28
+ name: OpenSpec: Apply
29
+ description: Implement an approved OpenSpec change and keep tasks in sync.
30
+ category: OpenSpec
31
+ tags: [openspec, apply]
32
+ ---`,
33
+ archive: `---
34
+ name: OpenSpec: Archive
35
+ description: Archive a deployed OpenSpec change and update specs.
36
+ category: OpenSpec
37
+ tags: [openspec, archive]
38
+ ---`
39
+ };
40
+ /**
41
+ * Qoder Slash Command Configurator
42
+ *
43
+ * Manages OpenSpec slash commands for Qoder AI assistant.
44
+ * Creates three workflow commands: proposal, apply, and archive.
45
+ * Uses colon-separated command format (/openspec:proposal).
46
+ *
47
+ * @extends {SlashCommandConfigurator}
48
+ */
49
+ export class QoderSlashCommandConfigurator extends SlashCommandConfigurator {
50
+ /** Unique identifier for Qoder tool */
51
+ toolId = 'qoder';
52
+ /** Indicates slash commands are available for this tool */
53
+ isAvailable = true;
54
+ /**
55
+ * Get relative file path for a slash command
56
+ *
57
+ * @param {SlashCommandId} id - Command identifier (proposal, apply, or archive)
58
+ * @returns {string} Relative path from project root to command file
59
+ */
60
+ getRelativePath(id) {
61
+ return FILE_PATHS[id];
62
+ }
63
+ /**
64
+ * Get YAML frontmatter for a slash command
65
+ *
66
+ * Frontmatter defines how the command appears in Qoder's UI,
67
+ * including display name, description, and categorization.
68
+ *
69
+ * @param {SlashCommandId} id - Command identifier (proposal, apply, or archive)
70
+ * @returns {string} YAML frontmatter block with command metadata
71
+ */
72
+ getFrontmatter(id) {
73
+ return FRONTMATTER[id];
74
+ }
75
+ }
76
+ //# sourceMappingURL=qoder.js.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Qwen slash command configurator for OpenSpec integration.
3
+ * This class handles the generation of Qwen-specific slash command files
4
+ * in the .qwen/commands directory structure.
5
+ *
6
+ * @implements {SlashCommandConfigurator}
7
+ */
8
+ import { SlashCommandConfigurator } from './base.js';
9
+ import { SlashCommandId } from '../../templates/index.js';
10
+ /**
11
+ * QwenSlashCommandConfigurator class provides integration with Qwen Code
12
+ * by creating the necessary slash command files in the .qwen/commands directory.
13
+ *
14
+ * The slash commands include:
15
+ * - /openspec-proposal: Create an OpenSpec change proposal
16
+ * - /openspec-apply: Apply an approved OpenSpec change
17
+ * - /openspec-archive: Archive a deployed OpenSpec change
18
+ */
19
+ export declare class QwenSlashCommandConfigurator extends SlashCommandConfigurator {
20
+ /** Unique identifier for the Qwen tool */
21
+ readonly toolId = "qwen";
22
+ /** Availability status for the Qwen tool */
23
+ readonly isAvailable = true;
24
+ /**
25
+ * Returns the relative file path for a given slash command ID.
26
+ * @param {SlashCommandId} id - The slash command identifier
27
+ * @returns {string} The relative path to the command file
28
+ */
29
+ protected getRelativePath(id: SlashCommandId): string;
30
+ /**
31
+ * Returns the YAML frontmatter for a given slash command ID.
32
+ * @param {SlashCommandId} id - The slash command identifier
33
+ * @returns {string} The YAML frontmatter string
34
+ */
35
+ protected getFrontmatter(id: SlashCommandId): string;
36
+ }
37
+ //# sourceMappingURL=qwen.d.ts.map
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Qwen slash command configurator for OpenSpec integration.
3
+ * This class handles the generation of Qwen-specific slash command files
4
+ * in the .qwen/commands directory structure.
5
+ *
6
+ * @implements {SlashCommandConfigurator}
7
+ */
8
+ import { SlashCommandConfigurator } from './base.js';
9
+ /**
10
+ * Mapping of slash command IDs to their corresponding file paths in .qwen/commands directory.
11
+ * @type {Record<SlashCommandId, string>}
12
+ */
13
+ const FILE_PATHS = {
14
+ proposal: '.qwen/commands/openspec-proposal.md',
15
+ apply: '.qwen/commands/openspec-apply.md',
16
+ archive: '.qwen/commands/openspec-archive.md'
17
+ };
18
+ /**
19
+ * YAML frontmatter definitions for Qwen command files.
20
+ * These provide metadata for each slash command to ensure proper recognition by Qwen Code.
21
+ * @type {Record<SlashCommandId, string>}
22
+ */
23
+ const FRONTMATTER = {
24
+ proposal: `---
25
+ name: /openspec-proposal
26
+ id: openspec-proposal
27
+ category: OpenSpec
28
+ description: Scaffold a new OpenSpec change and validate strictly.
29
+ ---`,
30
+ apply: `---
31
+ name: /openspec-apply
32
+ id: openspec-apply
33
+ category: OpenSpec
34
+ description: Implement an approved OpenSpec change and keep tasks in sync.
35
+ ---`,
36
+ archive: `---
37
+ name: /openspec-archive
38
+ id: openspec-archive
39
+ category: OpenSpec
40
+ description: Archive a deployed OpenSpec change and update specs.
41
+ ---`
42
+ };
43
+ /**
44
+ * QwenSlashCommandConfigurator class provides integration with Qwen Code
45
+ * by creating the necessary slash command files in the .qwen/commands directory.
46
+ *
47
+ * The slash commands include:
48
+ * - /openspec-proposal: Create an OpenSpec change proposal
49
+ * - /openspec-apply: Apply an approved OpenSpec change
50
+ * - /openspec-archive: Archive a deployed OpenSpec change
51
+ */
52
+ export class QwenSlashCommandConfigurator extends SlashCommandConfigurator {
53
+ /** Unique identifier for the Qwen tool */
54
+ toolId = 'qwen';
55
+ /** Availability status for the Qwen tool */
56
+ isAvailable = true;
57
+ /**
58
+ * Returns the relative file path for a given slash command ID.
59
+ * @param {SlashCommandId} id - The slash command identifier
60
+ * @returns {string} The relative path to the command file
61
+ */
62
+ getRelativePath(id) {
63
+ return FILE_PATHS[id];
64
+ }
65
+ /**
66
+ * Returns the YAML frontmatter for a given slash command ID.
67
+ * @param {SlashCommandId} id - The slash command identifier
68
+ * @returns {string} The YAML frontmatter string
69
+ */
70
+ getFrontmatter(id) {
71
+ return FRONTMATTER[id];
72
+ }
73
+ }
74
+ //# sourceMappingURL=qwen.js.map
@@ -1,4 +1,6 @@
1
1
  import { ClaudeSlashCommandConfigurator } from './claude.js';
2
+ import { CodeBuddySlashCommandConfigurator } from './codebuddy.js';
3
+ import { QoderSlashCommandConfigurator } from './qoder.js';
2
4
  import { CursorSlashCommandConfigurator } from './cursor.js';
3
5
  import { WindsurfSlashCommandConfigurator } from './windsurf.js';
4
6
  import { KiloCodeSlashCommandConfigurator } from './kilocode.js';
@@ -7,10 +9,17 @@ import { CodexSlashCommandConfigurator } from './codex.js';
7
9
  import { GitHubCopilotSlashCommandConfigurator } from './github-copilot.js';
8
10
  import { AmazonQSlashCommandConfigurator } from './amazon-q.js';
9
11
  import { FactorySlashCommandConfigurator } from './factory.js';
12
+ import { AuggieSlashCommandConfigurator } from './auggie.js';
13
+ import { ClineSlashCommandConfigurator } from './cline.js';
14
+ import { CrushSlashCommandConfigurator } from './crush.js';
15
+ import { CostrictSlashCommandConfigurator } from './costrict.js';
16
+ import { QwenSlashCommandConfigurator } from './qwen.js';
10
17
  export class SlashCommandRegistry {
11
18
  static configurators = new Map();
12
19
  static {
13
20
  const claude = new ClaudeSlashCommandConfigurator();
21
+ const codeBuddy = new CodeBuddySlashCommandConfigurator();
22
+ const qoder = new QoderSlashCommandConfigurator();
14
23
  const cursor = new CursorSlashCommandConfigurator();
15
24
  const windsurf = new WindsurfSlashCommandConfigurator();
16
25
  const kilocode = new KiloCodeSlashCommandConfigurator();
@@ -19,7 +28,14 @@ export class SlashCommandRegistry {
19
28
  const githubCopilot = new GitHubCopilotSlashCommandConfigurator();
20
29
  const amazonQ = new AmazonQSlashCommandConfigurator();
21
30
  const factory = new FactorySlashCommandConfigurator();
31
+ const auggie = new AuggieSlashCommandConfigurator();
32
+ const cline = new ClineSlashCommandConfigurator();
33
+ const crush = new CrushSlashCommandConfigurator();
34
+ const costrict = new CostrictSlashCommandConfigurator();
35
+ const qwen = new QwenSlashCommandConfigurator();
22
36
  this.configurators.set(claude.toolId, claude);
37
+ this.configurators.set(codeBuddy.toolId, codeBuddy);
38
+ this.configurators.set(qoder.toolId, qoder);
23
39
  this.configurators.set(cursor.toolId, cursor);
24
40
  this.configurators.set(windsurf.toolId, windsurf);
25
41
  this.configurators.set(kilocode.toolId, kilocode);
@@ -28,6 +44,11 @@ export class SlashCommandRegistry {
28
44
  this.configurators.set(githubCopilot.toolId, githubCopilot);
29
45
  this.configurators.set(amazonQ.toolId, amazonQ);
30
46
  this.configurators.set(factory.toolId, factory);
47
+ this.configurators.set(auggie.toolId, auggie);
48
+ this.configurators.set(cline.toolId, cline);
49
+ this.configurators.set(crush.toolId, crush);
50
+ this.configurators.set(costrict.toolId, costrict);
51
+ this.configurators.set(qwen.toolId, qwen);
31
52
  }
32
53
  static register(configurator) {
33
54
  this.configurators.set(configurator.toolId, configurator);
@@ -39,6 +39,8 @@ export declare class InitCommand {
39
39
  private isToolConfigured;
40
40
  private createDirectoryStructure;
41
41
  private generateFiles;
42
+ private ensureTemplateFiles;
43
+ private writeTemplateFiles;
42
44
  private configureAITools;
43
45
  private configureRootAgentsStub;
44
46
  private displaySuccessMessage;
package/dist/core/init.js CHANGED
@@ -6,7 +6,7 @@ import { FileSystemUtils } from '../utils/file-system.js';
6
6
  import { TemplateManager } from './templates/index.js';
7
7
  import { ToolRegistry } from './configurators/registry.js';
8
8
  import { SlashCommandRegistry } from './configurators/slash/registry.js';
9
- import { AI_TOOLS, OPENSPEC_DIR_NAME, } from './config.js';
9
+ import { AI_TOOLS, OPENSPEC_DIR_NAME, OPENSPEC_MARKERS, } from './config.js';
10
10
  import { PALETTE } from './styles/palette.js';
11
11
  const PROGRESS_SPINNER = {
12
12
  interval: 80,
@@ -254,7 +254,7 @@ export class InitCommand {
254
254
  const openspecPath = path.join(projectPath, openspecDir);
255
255
  // Validation happens silently in the background
256
256
  const extendMode = await this.validate(projectPath, openspecPath);
257
- const existingToolStates = await this.getExistingToolStates(projectPath);
257
+ const existingToolStates = await this.getExistingToolStates(projectPath, extendMode);
258
258
  this.renderBanner(extendMode);
259
259
  // Get configuration (after validation to avoid prompts if validation fails)
260
260
  const config = await this.getConfiguration(existingToolStates, extendMode);
@@ -276,7 +276,9 @@ export class InitCommand {
276
276
  });
277
277
  }
278
278
  else {
279
- ora({ stream: process.stdout }).info(PALETTE.midGray('ℹ OpenSpec already initialized. Skipping base scaffolding.'));
279
+ ora({ stream: process.stdout }).info(PALETTE.midGray('ℹ OpenSpec already initialized. Checking for missing files...'));
280
+ await this.createDirectoryStructure(openspecPath);
281
+ await this.ensureTemplateFiles(openspecPath, config);
280
282
  }
281
283
  // Step 2: Configure AI tools
282
284
  const toolSpinner = this.startSpinner('Configuring AI tools...');
@@ -413,25 +415,64 @@ export class InitCommand {
413
415
  initialSelected,
414
416
  });
415
417
  }
416
- async getExistingToolStates(projectPath) {
417
- const states = {};
418
- for (const tool of AI_TOOLS) {
419
- states[tool.value] = await this.isToolConfigured(projectPath, tool.value);
418
+ async getExistingToolStates(projectPath, extendMode) {
419
+ // Fresh initialization - no tools configured yet
420
+ if (!extendMode) {
421
+ return Object.fromEntries(AI_TOOLS.map(t => [t.value, false]));
420
422
  }
421
- return states;
423
+ // Extend mode - check all tools in parallel for better performance
424
+ const entries = await Promise.all(AI_TOOLS.map(async (t) => [t.value, await this.isToolConfigured(projectPath, t.value)]));
425
+ return Object.fromEntries(entries);
422
426
  }
423
427
  async isToolConfigured(projectPath, toolId) {
428
+ // A tool is only considered "configured by OpenSpec" if its files contain OpenSpec markers.
429
+ // For tools with both config files and slash commands, BOTH must have markers.
430
+ // For slash commands, at least one file with markers is sufficient (not all required).
431
+ // Helper to check if a file exists and contains OpenSpec markers
432
+ const fileHasMarkers = async (absolutePath) => {
433
+ try {
434
+ const content = await FileSystemUtils.readFile(absolutePath);
435
+ return content.includes(OPENSPEC_MARKERS.start) && content.includes(OPENSPEC_MARKERS.end);
436
+ }
437
+ catch {
438
+ return false;
439
+ }
440
+ };
441
+ let hasConfigFile = false;
442
+ let hasSlashCommands = false;
443
+ // Check if the tool has a config file with OpenSpec markers
424
444
  const configFile = ToolRegistry.get(toolId)?.configFileName;
425
- if (configFile &&
426
- (await FileSystemUtils.fileExists(path.join(projectPath, configFile))))
427
- return true;
445
+ if (configFile) {
446
+ const configPath = path.join(projectPath, configFile);
447
+ hasConfigFile = (await FileSystemUtils.fileExists(configPath)) && (await fileHasMarkers(configPath));
448
+ }
449
+ // Check if any slash command file exists with OpenSpec markers
428
450
  const slashConfigurator = SlashCommandRegistry.get(toolId);
429
- if (!slashConfigurator)
430
- return false;
431
- for (const target of slashConfigurator.getTargets()) {
432
- const absolute = slashConfigurator.resolveAbsolutePath(projectPath, target.id);
433
- if (await FileSystemUtils.fileExists(absolute))
434
- return true;
451
+ if (slashConfigurator) {
452
+ for (const target of slashConfigurator.getTargets()) {
453
+ const absolute = slashConfigurator.resolveAbsolutePath(projectPath, target.id);
454
+ if ((await FileSystemUtils.fileExists(absolute)) && (await fileHasMarkers(absolute))) {
455
+ hasSlashCommands = true;
456
+ break; // At least one file with markers is sufficient
457
+ }
458
+ }
459
+ }
460
+ // Tool is only configured if BOTH exist with markers
461
+ // OR if the tool has no config file requirement (slash commands only)
462
+ // OR if the tool has no slash commands requirement (config file only)
463
+ const hasConfigFileRequirement = configFile !== undefined;
464
+ const hasSlashCommandRequirement = slashConfigurator !== undefined;
465
+ if (hasConfigFileRequirement && hasSlashCommandRequirement) {
466
+ // Both are required - both must be present with markers
467
+ return hasConfigFile && hasSlashCommands;
468
+ }
469
+ else if (hasConfigFileRequirement) {
470
+ // Only config file required
471
+ return hasConfigFile;
472
+ }
473
+ else if (hasSlashCommandRequirement) {
474
+ // Only slash commands required
475
+ return hasSlashCommands;
435
476
  }
436
477
  return false;
437
478
  }
@@ -447,12 +488,22 @@ export class InitCommand {
447
488
  }
448
489
  }
449
490
  async generateFiles(openspecPath, config) {
491
+ await this.writeTemplateFiles(openspecPath, config, false);
492
+ }
493
+ async ensureTemplateFiles(openspecPath, config) {
494
+ await this.writeTemplateFiles(openspecPath, config, true);
495
+ }
496
+ async writeTemplateFiles(openspecPath, config, skipExisting) {
450
497
  const context = {
451
498
  // Could be enhanced with prompts for project details
452
499
  };
453
500
  const templates = TemplateManager.getTemplates(context);
454
501
  for (const template of templates) {
455
502
  const filePath = path.join(openspecPath, template.path);
503
+ // Skip if file exists and we're in skipExisting mode
504
+ if (skipExisting && (await FileSystemUtils.fileExists(filePath))) {
505
+ continue;
506
+ }
456
507
  const content = typeof template.content === 'function'
457
508
  ? template.content(context)
458
509
  : template.content;
@@ -23,6 +23,12 @@ export interface DeltaPlan {
23
23
  from: string;
24
24
  to: string;
25
25
  }>;
26
+ sectionPresence: {
27
+ added: boolean;
28
+ modified: boolean;
29
+ removed: boolean;
30
+ renamed: boolean;
31
+ };
26
32
  }
27
33
  /**
28
34
  * Parse a delta-formatted spec change file content into a DeltaPlan with raw blocks.
@@ -80,11 +80,26 @@ function normalizeLineEndings(content) {
80
80
  export function parseDeltaSpec(content) {
81
81
  const normalized = normalizeLineEndings(content);
82
82
  const sections = splitTopLevelSections(normalized);
83
- const added = parseRequirementBlocksFromSection(sections['ADDED Requirements'] || '');
84
- const modified = parseRequirementBlocksFromSection(sections['MODIFIED Requirements'] || '');
85
- const removedNames = parseRemovedNames(sections['REMOVED Requirements'] || '');
86
- const renamedPairs = parseRenamedPairs(sections['RENAMED Requirements'] || '');
87
- return { added, modified, removed: removedNames, renamed: renamedPairs };
83
+ const addedLookup = getSectionCaseInsensitive(sections, 'ADDED Requirements');
84
+ const modifiedLookup = getSectionCaseInsensitive(sections, 'MODIFIED Requirements');
85
+ const removedLookup = getSectionCaseInsensitive(sections, 'REMOVED Requirements');
86
+ const renamedLookup = getSectionCaseInsensitive(sections, 'RENAMED Requirements');
87
+ const added = parseRequirementBlocksFromSection(addedLookup.body);
88
+ const modified = parseRequirementBlocksFromSection(modifiedLookup.body);
89
+ const removedNames = parseRemovedNames(removedLookup.body);
90
+ const renamedPairs = parseRenamedPairs(renamedLookup.body);
91
+ return {
92
+ added,
93
+ modified,
94
+ removed: removedNames,
95
+ renamed: renamedPairs,
96
+ sectionPresence: {
97
+ added: addedLookup.found,
98
+ modified: modifiedLookup.found,
99
+ removed: removedLookup.found,
100
+ renamed: renamedLookup.found,
101
+ },
102
+ };
88
103
  }
89
104
  function splitTopLevelSections(content) {
90
105
  const lines = content.split('\n');
@@ -105,6 +120,14 @@ function splitTopLevelSections(content) {
105
120
  }
106
121
  return result;
107
122
  }
123
+ function getSectionCaseInsensitive(sections, desired) {
124
+ const target = desired.toLowerCase();
125
+ for (const [title, body] of Object.entries(sections)) {
126
+ if (title.toLowerCase() === target)
127
+ return { body, found: true };
128
+ }
129
+ return { body: '', found: false };
130
+ }
108
131
  function parseRequirementBlocksFromSection(sectionBody) {
109
132
  if (!sectionBody)
110
133
  return [];
@@ -1,2 +1,2 @@
1
- export declare const agentsTemplate = "# OpenSpec Instructions\n\nInstructions for AI coding assistants using OpenSpec for spec-driven development.\n\n## TL;DR Quick Checklist\n\n- Search existing work: `openspec spec list --long`, `openspec list` (use `rg` only for full-text search)\n- Decide scope: new capability vs modify existing capability\n- Pick a unique `change-id`: kebab-case, verb-led (`add-`, `update-`, `remove-`, `refactor-`)\n- Scaffold: `proposal.md`, `tasks.md`, `design.md` (only if needed), and delta specs per affected capability\n- Write deltas: use `## ADDED|MODIFIED|REMOVED|RENAMED Requirements`; include at least one `#### Scenario:` per requirement\n- Validate: `openspec validate [change-id] --strict` and fix issues\n- Request approval: Do not start implementation until proposal is approved\n\n## Three-Stage Workflow\n\n### Stage 1: Creating Changes\nCreate proposal when you need to:\n- Add features or functionality\n- Make breaking changes (API, schema)\n- Change architecture or patterns \n- Optimize performance (changes behavior)\n- Update security patterns\n\nTriggers (examples):\n- \"Help me create a change proposal\"\n- \"Help me plan a change\"\n- \"Help me create a proposal\"\n- \"I want to create a spec proposal\"\n- \"I want to create a spec\"\n\nLoose matching guidance:\n- Contains one of: `proposal`, `change`, `spec`\n- With one of: `create`, `plan`, `make`, `start`, `help`\n\nSkip proposal for:\n- Bug fixes (restore intended behavior)\n- Typos, formatting, comments\n- Dependency updates (non-breaking)\n- Configuration changes\n- Tests for existing behavior\n\n**Workflow**\n1. Review `openspec/project.md`, `openspec list`, and `openspec list --specs` to understand current context.\n2. Choose a unique verb-led `change-id` and scaffold `proposal.md`, `tasks.md`, optional `design.md`, and spec deltas under `openspec/changes/<id>/`.\n3. Draft spec deltas using `## ADDED|MODIFIED|REMOVED Requirements` with at least one `#### Scenario:` per requirement.\n4. Run `openspec validate <id> --strict` and resolve any issues before sharing the proposal.\n\n### Stage 2: Implementing Changes\nTrack these steps as TODOs and complete them one by one.\n1. **Read proposal.md** - Understand what's being built\n2. **Read design.md** (if exists) - Review technical decisions\n3. **Read tasks.md** - Get implementation checklist\n4. **Implement tasks sequentially** - Complete in order\n5. **Confirm completion** - Ensure every item in `tasks.md` is finished before updating statuses\n6. **Update checklist** - After all work is done, set every task to `- [x]` so the list reflects reality\n7. **Approval gate** - Do not start implementation until the proposal is reviewed and approved\n\n### Stage 3: Archiving Changes\nAfter deployment, create separate PR to:\n- Move `changes/[name]/` \u2192 `changes/archive/YYYY-MM-DD-[name]/`\n- Update `specs/` if capabilities changed\n- Use `openspec archive [change] --skip-specs --yes` for tooling-only changes\n- Run `openspec validate --strict` to confirm the archived change passes checks\n\n## Before Any Task\n\n**Context Checklist:**\n- [ ] Read relevant specs in `specs/[capability]/spec.md`\n- [ ] Check pending changes in `changes/` for conflicts\n- [ ] Read `openspec/project.md` for conventions\n- [ ] Run `openspec list` to see active changes\n- [ ] Run `openspec list --specs` to see existing capabilities\n\n**Before Creating Specs:**\n- Always check if capability already exists\n- Prefer modifying existing specs over creating duplicates\n- Use `openspec show [spec]` to review current state\n- If request is ambiguous, ask 1\u20132 clarifying questions before scaffolding\n\n### Search Guidance\n- Enumerate specs: `openspec spec list --long` (or `--json` for scripts)\n- Enumerate changes: `openspec list` (or `openspec change list --json` - deprecated but available)\n- Show details:\n - Spec: `openspec show <spec-id> --type spec` (use `--json` for filters)\n - Change: `openspec show <change-id> --json --deltas-only`\n- Full-text search (use ripgrep): `rg -n \"Requirement:|Scenario:\" openspec/specs`\n\n## Quick Start\n\n### CLI Commands\n\n```bash\n# Essential commands\nopenspec list # List active changes\nopenspec list --specs # List specifications\nopenspec show [item] # Display change or spec\nopenspec diff [change] # Show spec differences\nopenspec validate [item] # Validate changes or specs\nopenspec archive [change] [--yes|-y] # Archive after deployment (add --yes for non-interactive runs)\n\n# Project management\nopenspec init [path] # Initialize OpenSpec\nopenspec update [path] # Update instruction files\n\n# Interactive mode\nopenspec show # Prompts for selection\nopenspec validate # Bulk validation mode\n\n# Debugging\nopenspec show [change] --json --deltas-only\nopenspec validate [change] --strict\n```\n\n### Command Flags\n\n- `--json` - Machine-readable output\n- `--type change|spec` - Disambiguate items\n- `--strict` - Comprehensive validation\n- `--no-interactive` - Disable prompts\n- `--skip-specs` - Archive without spec updates\n- `--yes`/`-y` - Skip confirmation prompts (non-interactive archive)\n\n## Directory Structure\n\n```\nopenspec/\n\u251C\u2500\u2500 project.md # Project conventions\n\u251C\u2500\u2500 specs/ # Current truth - what IS built\n\u2502 \u2514\u2500\u2500 [capability]/ # Single focused capability\n\u2502 \u251C\u2500\u2500 spec.md # Requirements and scenarios\n\u2502 \u2514\u2500\u2500 design.md # Technical patterns\n\u251C\u2500\u2500 changes/ # Proposals - what SHOULD change\n\u2502 \u251C\u2500\u2500 [change-name]/\n\u2502 \u2502 \u251C\u2500\u2500 proposal.md # Why, what, impact\n\u2502 \u2502 \u251C\u2500\u2500 tasks.md # Implementation checklist\n\u2502 \u2502 \u251C\u2500\u2500 design.md # Technical decisions (optional; see criteria)\n\u2502 \u2502 \u2514\u2500\u2500 specs/ # Delta changes\n\u2502 \u2502 \u2514\u2500\u2500 [capability]/\n\u2502 \u2502 \u2514\u2500\u2500 spec.md # ADDED/MODIFIED/REMOVED\n\u2502 \u2514\u2500\u2500 archive/ # Completed changes\n```\n\n## Creating Change Proposals\n\n### Decision Tree\n\n```\nNew request?\n\u251C\u2500 Bug fix restoring spec behavior? \u2192 Fix directly\n\u251C\u2500 Typo/format/comment? \u2192 Fix directly \n\u251C\u2500 New feature/capability? \u2192 Create proposal\n\u251C\u2500 Breaking change? \u2192 Create proposal\n\u251C\u2500 Architecture change? \u2192 Create proposal\n\u2514\u2500 Unclear? \u2192 Create proposal (safer)\n```\n\n### Proposal Structure\n\n1. **Create directory:** `changes/[change-id]/` (kebab-case, verb-led, unique)\n\n2. **Write proposal.md:**\n```markdown\n## Why\n[1-2 sentences on problem/opportunity]\n\n## What Changes\n- [Bullet list of changes]\n- [Mark breaking changes with **BREAKING**]\n\n## Impact\n- Affected specs: [list capabilities]\n- Affected code: [key files/systems]\n```\n\n3. **Create spec deltas:** `specs/[capability]/spec.md`\n```markdown\n## ADDED Requirements\n### Requirement: New Feature\nThe system SHALL provide...\n\n#### Scenario: Success case\n- **WHEN** user performs action\n- **THEN** expected result\n\n## MODIFIED Requirements\n### Requirement: Existing Feature\n[Complete modified requirement]\n\n## REMOVED Requirements\n### Requirement: Old Feature\n**Reason**: [Why removing]\n**Migration**: [How to handle]\n```\nIf multiple capabilities are affected, create multiple delta files under `changes/[change-id]/specs/<capability>/spec.md`\u2014one per capability.\n\n4. **Create tasks.md:**\n```markdown\n## 1. Implementation\n- [ ] 1.1 Create database schema\n- [ ] 1.2 Implement API endpoint\n- [ ] 1.3 Add frontend component\n- [ ] 1.4 Write tests\n```\n\n5. **Create design.md when needed:**\nCreate `design.md` if any of the following apply; otherwise omit it:\n- Cross-cutting change (multiple services/modules) or a new architectural pattern\n- New external dependency or significant data model changes\n- Security, performance, or migration complexity\n- Ambiguity that benefits from technical decisions before coding\n\nMinimal `design.md` skeleton:\n```markdown\n## Context\n[Background, constraints, stakeholders]\n\n## Goals / Non-Goals\n- Goals: [...]\n- Non-Goals: [...]\n\n## Decisions\n- Decision: [What and why]\n- Alternatives considered: [Options + rationale]\n\n## Risks / Trade-offs\n- [Risk] \u2192 Mitigation\n\n## Migration Plan\n[Steps, rollback]\n\n## Open Questions\n- [...]\n```\n\n## Spec File Format\n\n### Critical: Scenario Formatting\n\n**CORRECT** (use #### headers):\n```markdown\n#### Scenario: User login success\n- **WHEN** valid credentials provided\n- **THEN** return JWT token\n```\n\n**WRONG** (don't use bullets or bold):\n```markdown\n- **Scenario: User login** \u274C\n**Scenario**: User login \u274C\n### Scenario: User login \u274C\n```\n\nEvery requirement MUST have at least one scenario.\n\n### Requirement Wording\n- Use SHALL/MUST for normative requirements (avoid should/may unless intentionally non-normative)\n\n### Delta Operations\n\n- `## ADDED Requirements` - New capabilities\n- `## MODIFIED Requirements` - Changed behavior\n- `## REMOVED Requirements` - Deprecated features\n- `## RENAMED Requirements` - Name changes\n\nHeaders matched with `trim(header)` - whitespace ignored.\n\n#### When to use ADDED vs MODIFIED\n- ADDED: Introduces a new capability or sub-capability that can stand alone as a requirement. Prefer ADDED when the change is orthogonal (e.g., adding \"Slash Command Configuration\") rather than altering the semantics of an existing requirement.\n- MODIFIED: Changes the behavior, scope, or acceptance criteria of an existing requirement. Always paste the full, updated requirement content (header + all scenarios). The archiver will replace the entire requirement with what you provide here; partial deltas will drop previous details.\n- RENAMED: Use when only the name changes. If you also change behavior, use RENAMED (name) plus MODIFIED (content) referencing the new name.\n\nCommon pitfall: Using MODIFIED to add a new concern without including the previous text. This causes loss of detail at archive time. If you aren\u2019t explicitly changing the existing requirement, add a new requirement under ADDED instead.\n\nAuthoring a MODIFIED requirement correctly:\n1) Locate the existing requirement in `openspec/specs/<capability>/spec.md`.\n2) Copy the entire requirement block (from `### Requirement: ...` through its scenarios).\n3) Paste it under `## MODIFIED Requirements` and edit to reflect the new behavior.\n4) Ensure the header text matches exactly (whitespace-insensitive) and keep at least one `#### Scenario:`.\n\nExample for RENAMED:\n```markdown\n## RENAMED Requirements\n- FROM: `### Requirement: Login`\n- TO: `### Requirement: User Authentication`\n```\n\n## Troubleshooting\n\n### Common Errors\n\n**\"Change must have at least one delta\"**\n- Check `changes/[name]/specs/` exists with .md files\n- Verify files have operation prefixes (## ADDED Requirements)\n\n**\"Requirement must have at least one scenario\"**\n- Check scenarios use `#### Scenario:` format (4 hashtags)\n- Don't use bullet points or bold for scenario headers\n\n**Silent scenario parsing failures**\n- Exact format required: `#### Scenario: Name`\n- Debug with: `openspec show [change] --json --deltas-only`\n\n### Validation Tips\n\n```bash\n# Always use strict mode for comprehensive checks\nopenspec validate [change] --strict\n\n# Debug delta parsing\nopenspec show [change] --json | jq '.deltas'\n\n# Check specific requirement\nopenspec show [spec] --json -r 1\n```\n\n## Happy Path Script\n\n```bash\n# 1) Explore current state\nopenspec spec list --long\nopenspec list\n# Optional full-text search:\n# rg -n \"Requirement:|Scenario:\" openspec/specs\n# rg -n \"^#|Requirement:\" openspec/changes\n\n# 2) Choose change id and scaffold\nCHANGE=add-two-factor-auth\nmkdir -p openspec/changes/$CHANGE/{specs/auth}\nprintf \"## Why\\n...\\n\\n## What Changes\\n- ...\\n\\n## Impact\\n- ...\\n\" > openspec/changes/$CHANGE/proposal.md\nprintf \"## 1. Implementation\\n- [ ] 1.1 ...\\n\" > openspec/changes/$CHANGE/tasks.md\n\n# 3) Add deltas (example)\ncat > openspec/changes/$CHANGE/specs/auth/spec.md << 'EOF'\n## ADDED Requirements\n### Requirement: Two-Factor Authentication\nUsers MUST provide a second factor during login.\n\n#### Scenario: OTP required\n- **WHEN** valid credentials are provided\n- **THEN** an OTP challenge is required\nEOF\n\n# 4) Validate\nopenspec validate $CHANGE --strict\n```\n\n## Multi-Capability Example\n\n```\nopenspec/changes/add-2fa-notify/\n\u251C\u2500\u2500 proposal.md\n\u251C\u2500\u2500 tasks.md\n\u2514\u2500\u2500 specs/\n \u251C\u2500\u2500 auth/\n \u2502 \u2514\u2500\u2500 spec.md # ADDED: Two-Factor Authentication\n \u2514\u2500\u2500 notifications/\n \u2514\u2500\u2500 spec.md # ADDED: OTP email notification\n```\n\nauth/spec.md\n```markdown\n## ADDED Requirements\n### Requirement: Two-Factor Authentication\n...\n```\n\nnotifications/spec.md\n```markdown\n## ADDED Requirements\n### Requirement: OTP Email Notification\n...\n```\n\n## Best Practices\n\n### Simplicity First\n- Default to <100 lines of new code\n- Single-file implementations until proven insufficient\n- Avoid frameworks without clear justification\n- Choose boring, proven patterns\n\n### Complexity Triggers\nOnly add complexity with:\n- Performance data showing current solution too slow\n- Concrete scale requirements (>1000 users, >100MB data)\n- Multiple proven use cases requiring abstraction\n\n### Clear References\n- Use `file.ts:42` format for code locations\n- Reference specs as `specs/auth/spec.md`\n- Link related changes and PRs\n\n### Capability Naming\n- Use verb-noun: `user-auth`, `payment-capture`\n- Single purpose per capability\n- 10-minute understandability rule\n- Split if description needs \"AND\"\n\n### Change ID Naming\n- Use kebab-case, short and descriptive: `add-two-factor-auth`\n- Prefer verb-led prefixes: `add-`, `update-`, `remove-`, `refactor-`\n- Ensure uniqueness; if taken, append `-2`, `-3`, etc.\n\n## Tool Selection Guide\n\n| Task | Tool | Why |\n|------|------|-----|\n| Find files by pattern | Glob | Fast pattern matching |\n| Search code content | Grep | Optimized regex search |\n| Read specific files | Read | Direct file access |\n| Explore unknown scope | Task | Multi-step investigation |\n\n## Error Recovery\n\n### Change Conflicts\n1. Run `openspec list` to see active changes\n2. Check for overlapping specs\n3. Coordinate with change owners\n4. Consider combining proposals\n\n### Validation Failures\n1. Run with `--strict` flag\n2. Check JSON output for details\n3. Verify spec file format\n4. Ensure scenarios properly formatted\n\n### Missing Context\n1. Read project.md first\n2. Check related specs\n3. Review recent archives\n4. Ask for clarification\n\n## Quick Reference\n\n### Stage Indicators\n- `changes/` - Proposed, not yet built\n- `specs/` - Built and deployed\n- `archive/` - Completed changes\n\n### File Purposes\n- `proposal.md` - Why and what\n- `tasks.md` - Implementation steps\n- `design.md` - Technical decisions\n- `spec.md` - Requirements and behavior\n\n### CLI Essentials\n```bash\nopenspec list # What's in progress?\nopenspec show [item] # View details\nopenspec diff [change] # What's changing?\nopenspec validate --strict # Is it correct?\nopenspec archive [change] [--yes|-y] # Mark complete (add --yes for automation)\n```\n\nRemember: Specs are truth. Changes are proposals. Keep them in sync.\n";
1
+ export declare const agentsTemplate = "# OpenSpec Instructions\n\nInstructions for AI coding assistants using OpenSpec for spec-driven development.\n\n## TL;DR Quick Checklist\n\n- Search existing work: `openspec spec list --long`, `openspec list` (use `rg` only for full-text search)\n- Decide scope: new capability vs modify existing capability\n- Pick a unique `change-id`: kebab-case, verb-led (`add-`, `update-`, `remove-`, `refactor-`)\n- Scaffold: `proposal.md`, `tasks.md`, `design.md` (only if needed), and delta specs per affected capability\n- Write deltas: use `## ADDED|MODIFIED|REMOVED|RENAMED Requirements`; include at least one `#### Scenario:` per requirement\n- Validate: `openspec validate [change-id] --strict` and fix issues\n- Request approval: Do not start implementation until proposal is approved\n\n## Three-Stage Workflow\n\n### Stage 1: Creating Changes\nCreate proposal when you need to:\n- Add features or functionality\n- Make breaking changes (API, schema)\n- Change architecture or patterns \n- Optimize performance (changes behavior)\n- Update security patterns\n\nTriggers (examples):\n- \"Help me create a change proposal\"\n- \"Help me plan a change\"\n- \"Help me create a proposal\"\n- \"I want to create a spec proposal\"\n- \"I want to create a spec\"\n\nLoose matching guidance:\n- Contains one of: `proposal`, `change`, `spec`\n- With one of: `create`, `plan`, `make`, `start`, `help`\n\nSkip proposal for:\n- Bug fixes (restore intended behavior)\n- Typos, formatting, comments\n- Dependency updates (non-breaking)\n- Configuration changes\n- Tests for existing behavior\n\n**Workflow**\n1. Review `openspec/project.md`, `openspec list`, and `openspec list --specs` to understand current context.\n2. Choose a unique verb-led `change-id` and scaffold `proposal.md`, `tasks.md`, optional `design.md`, and spec deltas under `openspec/changes/<id>/`.\n3. Draft spec deltas using `## ADDED|MODIFIED|REMOVED Requirements` with at least one `#### Scenario:` per requirement.\n4. Run `openspec validate <id> --strict` and resolve any issues before sharing the proposal.\n\n### Stage 2: Implementing Changes\nTrack these steps as TODOs and complete them one by one.\n1. **Read proposal.md** - Understand what's being built\n2. **Read design.md** (if exists) - Review technical decisions\n3. **Read tasks.md** - Get implementation checklist\n4. **Implement tasks sequentially** - Complete in order\n5. **Confirm completion** - Ensure every item in `tasks.md` is finished before updating statuses\n6. **Update checklist** - After all work is done, set every task to `- [x]` so the list reflects reality\n7. **Approval gate** - Do not start implementation until the proposal is reviewed and approved\n\n### Stage 3: Archiving Changes\nAfter deployment, create separate PR to:\n- Move `changes/[name]/` \u2192 `changes/archive/YYYY-MM-DD-[name]/`\n- Update `specs/` if capabilities changed\n- Use `openspec archive <change-id> --skip-specs --yes` for tooling-only changes (always pass the change ID explicitly)\n- Run `openspec validate --strict` to confirm the archived change passes checks\n\n## Before Any Task\n\n**Context Checklist:**\n- [ ] Read relevant specs in `specs/[capability]/spec.md`\n- [ ] Check pending changes in `changes/` for conflicts\n- [ ] Read `openspec/project.md` for conventions\n- [ ] Run `openspec list` to see active changes\n- [ ] Run `openspec list --specs` to see existing capabilities\n\n**Before Creating Specs:**\n- Always check if capability already exists\n- Prefer modifying existing specs over creating duplicates\n- Use `openspec show [spec]` to review current state\n- If request is ambiguous, ask 1\u20132 clarifying questions before scaffolding\n\n### Search Guidance\n- Enumerate specs: `openspec spec list --long` (or `--json` for scripts)\n- Enumerate changes: `openspec list` (or `openspec change list --json` - deprecated but available)\n- Show details:\n - Spec: `openspec show <spec-id> --type spec` (use `--json` for filters)\n - Change: `openspec show <change-id> --json --deltas-only`\n- Full-text search (use ripgrep): `rg -n \"Requirement:|Scenario:\" openspec/specs`\n\n## Quick Start\n\n### CLI Commands\n\n```bash\n# Essential commands\nopenspec list # List active changes\nopenspec list --specs # List specifications\nopenspec show [item] # Display change or spec\nopenspec validate [item] # Validate changes or specs\nopenspec archive <change-id> [--yes|-y] # Archive after deployment (add --yes for non-interactive runs)\n\n# Project management\nopenspec init [path] # Initialize OpenSpec\nopenspec update [path] # Update instruction files\n\n# Interactive mode\nopenspec show # Prompts for selection\nopenspec validate # Bulk validation mode\n\n# Debugging\nopenspec show [change] --json --deltas-only\nopenspec validate [change] --strict\n```\n\n### Command Flags\n\n- `--json` - Machine-readable output\n- `--type change|spec` - Disambiguate items\n- `--strict` - Comprehensive validation\n- `--no-interactive` - Disable prompts\n- `--skip-specs` - Archive without spec updates\n- `--yes`/`-y` - Skip confirmation prompts (non-interactive archive)\n\n## Directory Structure\n\n```\nopenspec/\n\u251C\u2500\u2500 project.md # Project conventions\n\u251C\u2500\u2500 specs/ # Current truth - what IS built\n\u2502 \u2514\u2500\u2500 [capability]/ # Single focused capability\n\u2502 \u251C\u2500\u2500 spec.md # Requirements and scenarios\n\u2502 \u2514\u2500\u2500 design.md # Technical patterns\n\u251C\u2500\u2500 changes/ # Proposals - what SHOULD change\n\u2502 \u251C\u2500\u2500 [change-name]/\n\u2502 \u2502 \u251C\u2500\u2500 proposal.md # Why, what, impact\n\u2502 \u2502 \u251C\u2500\u2500 tasks.md # Implementation checklist\n\u2502 \u2502 \u251C\u2500\u2500 design.md # Technical decisions (optional; see criteria)\n\u2502 \u2502 \u2514\u2500\u2500 specs/ # Delta changes\n\u2502 \u2502 \u2514\u2500\u2500 [capability]/\n\u2502 \u2502 \u2514\u2500\u2500 spec.md # ADDED/MODIFIED/REMOVED\n\u2502 \u2514\u2500\u2500 archive/ # Completed changes\n```\n\n## Creating Change Proposals\n\n### Decision Tree\n\n```\nNew request?\n\u251C\u2500 Bug fix restoring spec behavior? \u2192 Fix directly\n\u251C\u2500 Typo/format/comment? \u2192 Fix directly \n\u251C\u2500 New feature/capability? \u2192 Create proposal\n\u251C\u2500 Breaking change? \u2192 Create proposal\n\u251C\u2500 Architecture change? \u2192 Create proposal\n\u2514\u2500 Unclear? \u2192 Create proposal (safer)\n```\n\n### Proposal Structure\n\n1. **Create directory:** `changes/[change-id]/` (kebab-case, verb-led, unique)\n\n2. **Write proposal.md:**\n```markdown\n# Change: [Brief description of change]\n\n## Why\n[1-2 sentences on problem/opportunity]\n\n## What Changes\n- [Bullet list of changes]\n- [Mark breaking changes with **BREAKING**]\n\n## Impact\n- Affected specs: [list capabilities]\n- Affected code: [key files/systems]\n```\n\n3. **Create spec deltas:** `specs/[capability]/spec.md`\n```markdown\n## ADDED Requirements\n### Requirement: New Feature\nThe system SHALL provide...\n\n#### Scenario: Success case\n- **WHEN** user performs action\n- **THEN** expected result\n\n## MODIFIED Requirements\n### Requirement: Existing Feature\n[Complete modified requirement]\n\n## REMOVED Requirements\n### Requirement: Old Feature\n**Reason**: [Why removing]\n**Migration**: [How to handle]\n```\nIf multiple capabilities are affected, create multiple delta files under `changes/[change-id]/specs/<capability>/spec.md`\u2014one per capability.\n\n4. **Create tasks.md:**\n```markdown\n## 1. Implementation\n- [ ] 1.1 Create database schema\n- [ ] 1.2 Implement API endpoint\n- [ ] 1.3 Add frontend component\n- [ ] 1.4 Write tests\n```\n\n5. **Create design.md when needed:**\nCreate `design.md` if any of the following apply; otherwise omit it:\n- Cross-cutting change (multiple services/modules) or a new architectural pattern\n- New external dependency or significant data model changes\n- Security, performance, or migration complexity\n- Ambiguity that benefits from technical decisions before coding\n\nMinimal `design.md` skeleton:\n```markdown\n## Context\n[Background, constraints, stakeholders]\n\n## Goals / Non-Goals\n- Goals: [...]\n- Non-Goals: [...]\n\n## Decisions\n- Decision: [What and why]\n- Alternatives considered: [Options + rationale]\n\n## Risks / Trade-offs\n- [Risk] \u2192 Mitigation\n\n## Migration Plan\n[Steps, rollback]\n\n## Open Questions\n- [...]\n```\n\n## Spec File Format\n\n### Critical: Scenario Formatting\n\n**CORRECT** (use #### headers):\n```markdown\n#### Scenario: User login success\n- **WHEN** valid credentials provided\n- **THEN** return JWT token\n```\n\n**WRONG** (don't use bullets or bold):\n```markdown\n- **Scenario: User login** \u274C\n**Scenario**: User login \u274C\n### Scenario: User login \u274C\n```\n\nEvery requirement MUST have at least one scenario.\n\n### Requirement Wording\n- Use SHALL/MUST for normative requirements (avoid should/may unless intentionally non-normative)\n\n### Delta Operations\n\n- `## ADDED Requirements` - New capabilities\n- `## MODIFIED Requirements` - Changed behavior\n- `## REMOVED Requirements` - Deprecated features\n- `## RENAMED Requirements` - Name changes\n\nHeaders matched with `trim(header)` - whitespace ignored.\n\n#### When to use ADDED vs MODIFIED\n- ADDED: Introduces a new capability or sub-capability that can stand alone as a requirement. Prefer ADDED when the change is orthogonal (e.g., adding \"Slash Command Configuration\") rather than altering the semantics of an existing requirement.\n- MODIFIED: Changes the behavior, scope, or acceptance criteria of an existing requirement. Always paste the full, updated requirement content (header + all scenarios). The archiver will replace the entire requirement with what you provide here; partial deltas will drop previous details.\n- RENAMED: Use when only the name changes. If you also change behavior, use RENAMED (name) plus MODIFIED (content) referencing the new name.\n\nCommon pitfall: Using MODIFIED to add a new concern without including the previous text. This causes loss of detail at archive time. If you aren\u2019t explicitly changing the existing requirement, add a new requirement under ADDED instead.\n\nAuthoring a MODIFIED requirement correctly:\n1) Locate the existing requirement in `openspec/specs/<capability>/spec.md`.\n2) Copy the entire requirement block (from `### Requirement: ...` through its scenarios).\n3) Paste it under `## MODIFIED Requirements` and edit to reflect the new behavior.\n4) Ensure the header text matches exactly (whitespace-insensitive) and keep at least one `#### Scenario:`.\n\nExample for RENAMED:\n```markdown\n## RENAMED Requirements\n- FROM: `### Requirement: Login`\n- TO: `### Requirement: User Authentication`\n```\n\n## Troubleshooting\n\n### Common Errors\n\n**\"Change must have at least one delta\"**\n- Check `changes/[name]/specs/` exists with .md files\n- Verify files have operation prefixes (## ADDED Requirements)\n\n**\"Requirement must have at least one scenario\"**\n- Check scenarios use `#### Scenario:` format (4 hashtags)\n- Don't use bullet points or bold for scenario headers\n\n**Silent scenario parsing failures**\n- Exact format required: `#### Scenario: Name`\n- Debug with: `openspec show [change] --json --deltas-only`\n\n### Validation Tips\n\n```bash\n# Always use strict mode for comprehensive checks\nopenspec validate [change] --strict\n\n# Debug delta parsing\nopenspec show [change] --json | jq '.deltas'\n\n# Check specific requirement\nopenspec show [spec] --json -r 1\n```\n\n## Happy Path Script\n\n```bash\n# 1) Explore current state\nopenspec spec list --long\nopenspec list\n# Optional full-text search:\n# rg -n \"Requirement:|Scenario:\" openspec/specs\n# rg -n \"^#|Requirement:\" openspec/changes\n\n# 2) Choose change id and scaffold\nCHANGE=add-two-factor-auth\nmkdir -p openspec/changes/$CHANGE/{specs/auth}\nprintf \"## Why\\n...\\n\\n## What Changes\\n- ...\\n\\n## Impact\\n- ...\\n\" > openspec/changes/$CHANGE/proposal.md\nprintf \"## 1. Implementation\\n- [ ] 1.1 ...\\n\" > openspec/changes/$CHANGE/tasks.md\n\n# 3) Add deltas (example)\ncat > openspec/changes/$CHANGE/specs/auth/spec.md << 'EOF'\n## ADDED Requirements\n### Requirement: Two-Factor Authentication\nUsers MUST provide a second factor during login.\n\n#### Scenario: OTP required\n- **WHEN** valid credentials are provided\n- **THEN** an OTP challenge is required\nEOF\n\n# 4) Validate\nopenspec validate $CHANGE --strict\n```\n\n## Multi-Capability Example\n\n```\nopenspec/changes/add-2fa-notify/\n\u251C\u2500\u2500 proposal.md\n\u251C\u2500\u2500 tasks.md\n\u2514\u2500\u2500 specs/\n \u251C\u2500\u2500 auth/\n \u2502 \u2514\u2500\u2500 spec.md # ADDED: Two-Factor Authentication\n \u2514\u2500\u2500 notifications/\n \u2514\u2500\u2500 spec.md # ADDED: OTP email notification\n```\n\nauth/spec.md\n```markdown\n## ADDED Requirements\n### Requirement: Two-Factor Authentication\n...\n```\n\nnotifications/spec.md\n```markdown\n## ADDED Requirements\n### Requirement: OTP Email Notification\n...\n```\n\n## Best Practices\n\n### Simplicity First\n- Default to <100 lines of new code\n- Single-file implementations until proven insufficient\n- Avoid frameworks without clear justification\n- Choose boring, proven patterns\n\n### Complexity Triggers\nOnly add complexity with:\n- Performance data showing current solution too slow\n- Concrete scale requirements (>1000 users, >100MB data)\n- Multiple proven use cases requiring abstraction\n\n### Clear References\n- Use `file.ts:42` format for code locations\n- Reference specs as `specs/auth/spec.md`\n- Link related changes and PRs\n\n### Capability Naming\n- Use verb-noun: `user-auth`, `payment-capture`\n- Single purpose per capability\n- 10-minute understandability rule\n- Split if description needs \"AND\"\n\n### Change ID Naming\n- Use kebab-case, short and descriptive: `add-two-factor-auth`\n- Prefer verb-led prefixes: `add-`, `update-`, `remove-`, `refactor-`\n- Ensure uniqueness; if taken, append `-2`, `-3`, etc.\n\n## Tool Selection Guide\n\n| Task | Tool | Why |\n|------|------|-----|\n| Find files by pattern | Glob | Fast pattern matching |\n| Search code content | Grep | Optimized regex search |\n| Read specific files | Read | Direct file access |\n| Explore unknown scope | Task | Multi-step investigation |\n\n## Error Recovery\n\n### Change Conflicts\n1. Run `openspec list` to see active changes\n2. Check for overlapping specs\n3. Coordinate with change owners\n4. Consider combining proposals\n\n### Validation Failures\n1. Run with `--strict` flag\n2. Check JSON output for details\n3. Verify spec file format\n4. Ensure scenarios properly formatted\n\n### Missing Context\n1. Read project.md first\n2. Check related specs\n3. Review recent archives\n4. Ask for clarification\n\n## Quick Reference\n\n### Stage Indicators\n- `changes/` - Proposed, not yet built\n- `specs/` - Built and deployed\n- `archive/` - Completed changes\n\n### File Purposes\n- `proposal.md` - Why and what\n- `tasks.md` - Implementation steps\n- `design.md` - Technical decisions\n- `spec.md` - Requirements and behavior\n\n### CLI Essentials\n```bash\nopenspec list # What's in progress?\nopenspec show [item] # View details\nopenspec validate --strict # Is it correct?\nopenspec archive <change-id> [--yes|-y] # Mark complete (add --yes for automation)\n```\n\nRemember: Specs are truth. Changes are proposals. Keep them in sync.\n";
2
2
  //# sourceMappingURL=agents-template.d.ts.map