@fission-ai/openspec 0.21.0 → 0.23.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.
@@ -1602,6 +1602,251 @@ All artifacts complete. All tasks complete.
1602
1602
  - If delta specs exist, always run the sync assessment and show the combined summary before prompting`
1603
1603
  };
1604
1604
  }
1605
+ /**
1606
+ * Template for openspec-bulk-archive-change skill
1607
+ * For archiving multiple completed changes at once
1608
+ */
1609
+ export function getBulkArchiveChangeSkillTemplate() {
1610
+ return {
1611
+ name: 'openspec-bulk-archive-change',
1612
+ description: 'Archive multiple completed changes at once. Use when archiving several parallel changes.',
1613
+ instructions: `Archive multiple completed changes in a single operation.
1614
+
1615
+ This skill allows you to batch-archive changes, handling spec conflicts intelligently by checking the codebase to determine what's actually implemented.
1616
+
1617
+ **Input**: None required (prompts for selection)
1618
+
1619
+ **Steps**
1620
+
1621
+ 1. **Get active changes**
1622
+
1623
+ Run \`openspec list --json\` to get all active changes.
1624
+
1625
+ If no active changes exist, inform user and stop.
1626
+
1627
+ 2. **Prompt for change selection**
1628
+
1629
+ Use **AskUserQuestion tool** with multi-select to let user choose changes:
1630
+ - Show each change with its schema
1631
+ - Include an option for "All changes"
1632
+ - Allow any number of selections (1+ works, 2+ is the typical use case)
1633
+
1634
+ **IMPORTANT**: Do NOT auto-select. Always let the user choose.
1635
+
1636
+ 3. **Batch validation - gather status for all selected changes**
1637
+
1638
+ For each selected change, collect:
1639
+
1640
+ a. **Artifact status** - Run \`openspec status --change "<name>" --json\`
1641
+ - Parse \`schemaName\` and \`artifacts\` list
1642
+ - Note which artifacts are \`done\` vs other states
1643
+
1644
+ b. **Task completion** - Read \`openspec/changes/<name>/tasks.md\`
1645
+ - Count \`- [ ]\` (incomplete) vs \`- [x]\` (complete)
1646
+ - If no tasks file exists, note as "No tasks"
1647
+
1648
+ c. **Delta specs** - Check \`openspec/changes/<name>/specs/\` directory
1649
+ - List which capability specs exist
1650
+ - For each, extract requirement names (lines matching \`### Requirement: <name>\`)
1651
+
1652
+ 4. **Detect spec conflicts**
1653
+
1654
+ Build a map of \`capability -> [changes that touch it]\`:
1655
+
1656
+ \`\`\`
1657
+ auth -> [change-a, change-b] <- CONFLICT (2+ changes)
1658
+ api -> [change-c] <- OK (only 1 change)
1659
+ \`\`\`
1660
+
1661
+ A conflict exists when 2+ selected changes have delta specs for the same capability.
1662
+
1663
+ 5. **Resolve conflicts agentically**
1664
+
1665
+ **For each conflict**, investigate the codebase:
1666
+
1667
+ a. **Read the delta specs** from each conflicting change to understand what each claims to add/modify
1668
+
1669
+ b. **Search the codebase** for implementation evidence:
1670
+ - Look for code implementing requirements from each delta spec
1671
+ - Check for related files, functions, or tests
1672
+
1673
+ c. **Determine resolution**:
1674
+ - If only one change is actually implemented -> sync that one's specs
1675
+ - If both implemented -> apply in chronological order (older first, newer overwrites)
1676
+ - If neither implemented -> skip spec sync, warn user
1677
+
1678
+ d. **Record resolution** for each conflict:
1679
+ - Which change's specs to apply
1680
+ - In what order (if both)
1681
+ - Rationale (what was found in codebase)
1682
+
1683
+ 6. **Show consolidated status table**
1684
+
1685
+ Display a table summarizing all changes:
1686
+
1687
+ \`\`\`
1688
+ | Change | Artifacts | Tasks | Specs | Conflicts | Status |
1689
+ |---------------------|-----------|-------|---------|-----------|--------|
1690
+ | schema-management | Done | 5/5 | 2 delta | None | Ready |
1691
+ | project-config | Done | 3/3 | 1 delta | None | Ready |
1692
+ | add-oauth | Done | 4/4 | 1 delta | auth (!) | Ready* |
1693
+ | add-verify-skill | 1 left | 2/5 | None | None | Warn |
1694
+ \`\`\`
1695
+
1696
+ For conflicts, show the resolution:
1697
+ \`\`\`
1698
+ * Conflict resolution:
1699
+ - auth spec: Will apply add-oauth then add-jwt (both implemented, chronological order)
1700
+ \`\`\`
1701
+
1702
+ For incomplete changes, show warnings:
1703
+ \`\`\`
1704
+ Warnings:
1705
+ - add-verify-skill: 1 incomplete artifact, 3 incomplete tasks
1706
+ \`\`\`
1707
+
1708
+ 7. **Confirm batch operation**
1709
+
1710
+ Use **AskUserQuestion tool** with a single confirmation:
1711
+
1712
+ - "Archive N changes?" with options based on status
1713
+ - Options might include:
1714
+ - "Archive all N changes"
1715
+ - "Archive only N ready changes (skip incomplete)"
1716
+ - "Cancel"
1717
+
1718
+ If there are incomplete changes, make clear they'll be archived with warnings.
1719
+
1720
+ 8. **Execute archive for each confirmed change**
1721
+
1722
+ Process changes in the determined order (respecting conflict resolution):
1723
+
1724
+ a. **Sync specs** if delta specs exist:
1725
+ - Use the openspec-sync-specs approach (agent-driven intelligent merge)
1726
+ - For conflicts, apply in resolved order
1727
+ - Track if sync was done
1728
+
1729
+ b. **Perform the archive**:
1730
+ \`\`\`bash
1731
+ mkdir -p openspec/changes/archive
1732
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
1733
+ \`\`\`
1734
+
1735
+ c. **Track outcome** for each change:
1736
+ - Success: archived successfully
1737
+ - Failed: error during archive (record error)
1738
+ - Skipped: user chose not to archive (if applicable)
1739
+
1740
+ 9. **Display summary**
1741
+
1742
+ Show final results:
1743
+
1744
+ \`\`\`
1745
+ ## Bulk Archive Complete
1746
+
1747
+ Archived 3 changes:
1748
+ - schema-management-cli -> archive/2026-01-19-schema-management-cli/
1749
+ - project-config -> archive/2026-01-19-project-config/
1750
+ - add-oauth -> archive/2026-01-19-add-oauth/
1751
+
1752
+ Skipped 1 change:
1753
+ - add-verify-skill (user chose not to archive incomplete)
1754
+
1755
+ Spec sync summary:
1756
+ - 4 delta specs synced to main specs
1757
+ - 1 conflict resolved (auth: applied both in chronological order)
1758
+ \`\`\`
1759
+
1760
+ If any failures:
1761
+ \`\`\`
1762
+ Failed 1 change:
1763
+ - some-change: Archive directory already exists
1764
+ \`\`\`
1765
+
1766
+ **Conflict Resolution Examples**
1767
+
1768
+ Example 1: Only one implemented
1769
+ \`\`\`
1770
+ Conflict: specs/auth/spec.md touched by [add-oauth, add-jwt]
1771
+
1772
+ Checking add-oauth:
1773
+ - Delta adds "OAuth Provider Integration" requirement
1774
+ - Searching codebase... found src/auth/oauth.ts implementing OAuth flow
1775
+
1776
+ Checking add-jwt:
1777
+ - Delta adds "JWT Token Handling" requirement
1778
+ - Searching codebase... no JWT implementation found
1779
+
1780
+ Resolution: Only add-oauth is implemented. Will sync add-oauth specs only.
1781
+ \`\`\`
1782
+
1783
+ Example 2: Both implemented
1784
+ \`\`\`
1785
+ Conflict: specs/api/spec.md touched by [add-rest-api, add-graphql]
1786
+
1787
+ Checking add-rest-api (created 2026-01-10):
1788
+ - Delta adds "REST Endpoints" requirement
1789
+ - Searching codebase... found src/api/rest.ts
1790
+
1791
+ Checking add-graphql (created 2026-01-15):
1792
+ - Delta adds "GraphQL Schema" requirement
1793
+ - Searching codebase... found src/api/graphql.ts
1794
+
1795
+ Resolution: Both implemented. Will apply add-rest-api specs first,
1796
+ then add-graphql specs (chronological order, newer takes precedence).
1797
+ \`\`\`
1798
+
1799
+ **Output On Success**
1800
+
1801
+ \`\`\`
1802
+ ## Bulk Archive Complete
1803
+
1804
+ Archived N changes:
1805
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
1806
+ - <change-2> -> archive/YYYY-MM-DD-<change-2>/
1807
+
1808
+ Spec sync summary:
1809
+ - N delta specs synced to main specs
1810
+ - No conflicts (or: M conflicts resolved)
1811
+ \`\`\`
1812
+
1813
+ **Output On Partial Success**
1814
+
1815
+ \`\`\`
1816
+ ## Bulk Archive Complete (partial)
1817
+
1818
+ Archived N changes:
1819
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
1820
+
1821
+ Skipped M changes:
1822
+ - <change-2> (user chose not to archive incomplete)
1823
+
1824
+ Failed K changes:
1825
+ - <change-3>: Archive directory already exists
1826
+ \`\`\`
1827
+
1828
+ **Output When No Changes**
1829
+
1830
+ \`\`\`
1831
+ ## No Changes to Archive
1832
+
1833
+ No active changes found. Use \`/opsx:new\` to create a new change.
1834
+ \`\`\`
1835
+
1836
+ **Guardrails**
1837
+ - Allow any number of changes (1+ is fine, 2+ is the typical use case)
1838
+ - Always prompt for selection, never auto-select
1839
+ - Detect spec conflicts early and resolve by checking codebase
1840
+ - When both changes are implemented, apply specs in chronological order
1841
+ - Skip spec sync only when implementation is missing (warn user)
1842
+ - Show clear per-change status before confirming
1843
+ - Use single confirmation for entire batch
1844
+ - Track and report all outcomes (success/skip/fail)
1845
+ - Preserve .openspec.yaml when moving to archive
1846
+ - Archive directory target uses current date: YYYY-MM-DD-<name>
1847
+ - If archive target exists, fail that change but continue with others`
1848
+ };
1849
+ }
1605
1850
  /**
1606
1851
  * Template for /opsx:sync slash command
1607
1852
  */
@@ -2068,6 +2313,252 @@ Target archive directory already exists.
2068
2313
  - If delta specs exist, always run the sync assessment and show the combined summary before prompting`
2069
2314
  };
2070
2315
  }
2316
+ /**
2317
+ * Template for /opsx:bulk-archive slash command
2318
+ */
2319
+ export function getOpsxBulkArchiveCommandTemplate() {
2320
+ return {
2321
+ name: 'OPSX: Bulk Archive',
2322
+ description: 'Archive multiple completed changes at once',
2323
+ category: 'Workflow',
2324
+ tags: ['workflow', 'archive', 'experimental', 'bulk'],
2325
+ content: `Archive multiple completed changes in a single operation.
2326
+
2327
+ This skill allows you to batch-archive changes, handling spec conflicts intelligently by checking the codebase to determine what's actually implemented.
2328
+
2329
+ **Input**: None required (prompts for selection)
2330
+
2331
+ **Steps**
2332
+
2333
+ 1. **Get active changes**
2334
+
2335
+ Run \`openspec list --json\` to get all active changes.
2336
+
2337
+ If no active changes exist, inform user and stop.
2338
+
2339
+ 2. **Prompt for change selection**
2340
+
2341
+ Use **AskUserQuestion tool** with multi-select to let user choose changes:
2342
+ - Show each change with its schema
2343
+ - Include an option for "All changes"
2344
+ - Allow any number of selections (1+ works, 2+ is the typical use case)
2345
+
2346
+ **IMPORTANT**: Do NOT auto-select. Always let the user choose.
2347
+
2348
+ 3. **Batch validation - gather status for all selected changes**
2349
+
2350
+ For each selected change, collect:
2351
+
2352
+ a. **Artifact status** - Run \`openspec status --change "<name>" --json\`
2353
+ - Parse \`schemaName\` and \`artifacts\` list
2354
+ - Note which artifacts are \`done\` vs other states
2355
+
2356
+ b. **Task completion** - Read \`openspec/changes/<name>/tasks.md\`
2357
+ - Count \`- [ ]\` (incomplete) vs \`- [x]\` (complete)
2358
+ - If no tasks file exists, note as "No tasks"
2359
+
2360
+ c. **Delta specs** - Check \`openspec/changes/<name>/specs/\` directory
2361
+ - List which capability specs exist
2362
+ - For each, extract requirement names (lines matching \`### Requirement: <name>\`)
2363
+
2364
+ 4. **Detect spec conflicts**
2365
+
2366
+ Build a map of \`capability -> [changes that touch it]\`:
2367
+
2368
+ \`\`\`
2369
+ auth -> [change-a, change-b] <- CONFLICT (2+ changes)
2370
+ api -> [change-c] <- OK (only 1 change)
2371
+ \`\`\`
2372
+
2373
+ A conflict exists when 2+ selected changes have delta specs for the same capability.
2374
+
2375
+ 5. **Resolve conflicts agentically**
2376
+
2377
+ **For each conflict**, investigate the codebase:
2378
+
2379
+ a. **Read the delta specs** from each conflicting change to understand what each claims to add/modify
2380
+
2381
+ b. **Search the codebase** for implementation evidence:
2382
+ - Look for code implementing requirements from each delta spec
2383
+ - Check for related files, functions, or tests
2384
+
2385
+ c. **Determine resolution**:
2386
+ - If only one change is actually implemented -> sync that one's specs
2387
+ - If both implemented -> apply in chronological order (older first, newer overwrites)
2388
+ - If neither implemented -> skip spec sync, warn user
2389
+
2390
+ d. **Record resolution** for each conflict:
2391
+ - Which change's specs to apply
2392
+ - In what order (if both)
2393
+ - Rationale (what was found in codebase)
2394
+
2395
+ 6. **Show consolidated status table**
2396
+
2397
+ Display a table summarizing all changes:
2398
+
2399
+ \`\`\`
2400
+ | Change | Artifacts | Tasks | Specs | Conflicts | Status |
2401
+ |---------------------|-----------|-------|---------|-----------|--------|
2402
+ | schema-management | Done | 5/5 | 2 delta | None | Ready |
2403
+ | project-config | Done | 3/3 | 1 delta | None | Ready |
2404
+ | add-oauth | Done | 4/4 | 1 delta | auth (!) | Ready* |
2405
+ | add-verify-skill | 1 left | 2/5 | None | None | Warn |
2406
+ \`\`\`
2407
+
2408
+ For conflicts, show the resolution:
2409
+ \`\`\`
2410
+ * Conflict resolution:
2411
+ - auth spec: Will apply add-oauth then add-jwt (both implemented, chronological order)
2412
+ \`\`\`
2413
+
2414
+ For incomplete changes, show warnings:
2415
+ \`\`\`
2416
+ Warnings:
2417
+ - add-verify-skill: 1 incomplete artifact, 3 incomplete tasks
2418
+ \`\`\`
2419
+
2420
+ 7. **Confirm batch operation**
2421
+
2422
+ Use **AskUserQuestion tool** with a single confirmation:
2423
+
2424
+ - "Archive N changes?" with options based on status
2425
+ - Options might include:
2426
+ - "Archive all N changes"
2427
+ - "Archive only N ready changes (skip incomplete)"
2428
+ - "Cancel"
2429
+
2430
+ If there are incomplete changes, make clear they'll be archived with warnings.
2431
+
2432
+ 8. **Execute archive for each confirmed change**
2433
+
2434
+ Process changes in the determined order (respecting conflict resolution):
2435
+
2436
+ a. **Sync specs** if delta specs exist:
2437
+ - Use the openspec-sync-specs approach (agent-driven intelligent merge)
2438
+ - For conflicts, apply in resolved order
2439
+ - Track if sync was done
2440
+
2441
+ b. **Perform the archive**:
2442
+ \`\`\`bash
2443
+ mkdir -p openspec/changes/archive
2444
+ mv openspec/changes/<name> openspec/changes/archive/YYYY-MM-DD-<name>
2445
+ \`\`\`
2446
+
2447
+ c. **Track outcome** for each change:
2448
+ - Success: archived successfully
2449
+ - Failed: error during archive (record error)
2450
+ - Skipped: user chose not to archive (if applicable)
2451
+
2452
+ 9. **Display summary**
2453
+
2454
+ Show final results:
2455
+
2456
+ \`\`\`
2457
+ ## Bulk Archive Complete
2458
+
2459
+ Archived 3 changes:
2460
+ - schema-management-cli -> archive/2026-01-19-schema-management-cli/
2461
+ - project-config -> archive/2026-01-19-project-config/
2462
+ - add-oauth -> archive/2026-01-19-add-oauth/
2463
+
2464
+ Skipped 1 change:
2465
+ - add-verify-skill (user chose not to archive incomplete)
2466
+
2467
+ Spec sync summary:
2468
+ - 4 delta specs synced to main specs
2469
+ - 1 conflict resolved (auth: applied both in chronological order)
2470
+ \`\`\`
2471
+
2472
+ If any failures:
2473
+ \`\`\`
2474
+ Failed 1 change:
2475
+ - some-change: Archive directory already exists
2476
+ \`\`\`
2477
+
2478
+ **Conflict Resolution Examples**
2479
+
2480
+ Example 1: Only one implemented
2481
+ \`\`\`
2482
+ Conflict: specs/auth/spec.md touched by [add-oauth, add-jwt]
2483
+
2484
+ Checking add-oauth:
2485
+ - Delta adds "OAuth Provider Integration" requirement
2486
+ - Searching codebase... found src/auth/oauth.ts implementing OAuth flow
2487
+
2488
+ Checking add-jwt:
2489
+ - Delta adds "JWT Token Handling" requirement
2490
+ - Searching codebase... no JWT implementation found
2491
+
2492
+ Resolution: Only add-oauth is implemented. Will sync add-oauth specs only.
2493
+ \`\`\`
2494
+
2495
+ Example 2: Both implemented
2496
+ \`\`\`
2497
+ Conflict: specs/api/spec.md touched by [add-rest-api, add-graphql]
2498
+
2499
+ Checking add-rest-api (created 2026-01-10):
2500
+ - Delta adds "REST Endpoints" requirement
2501
+ - Searching codebase... found src/api/rest.ts
2502
+
2503
+ Checking add-graphql (created 2026-01-15):
2504
+ - Delta adds "GraphQL Schema" requirement
2505
+ - Searching codebase... found src/api/graphql.ts
2506
+
2507
+ Resolution: Both implemented. Will apply add-rest-api specs first,
2508
+ then add-graphql specs (chronological order, newer takes precedence).
2509
+ \`\`\`
2510
+
2511
+ **Output On Success**
2512
+
2513
+ \`\`\`
2514
+ ## Bulk Archive Complete
2515
+
2516
+ Archived N changes:
2517
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
2518
+ - <change-2> -> archive/YYYY-MM-DD-<change-2>/
2519
+
2520
+ Spec sync summary:
2521
+ - N delta specs synced to main specs
2522
+ - No conflicts (or: M conflicts resolved)
2523
+ \`\`\`
2524
+
2525
+ **Output On Partial Success**
2526
+
2527
+ \`\`\`
2528
+ ## Bulk Archive Complete (partial)
2529
+
2530
+ Archived N changes:
2531
+ - <change-1> -> archive/YYYY-MM-DD-<change-1>/
2532
+
2533
+ Skipped M changes:
2534
+ - <change-2> (user chose not to archive incomplete)
2535
+
2536
+ Failed K changes:
2537
+ - <change-3>: Archive directory already exists
2538
+ \`\`\`
2539
+
2540
+ **Output When No Changes**
2541
+
2542
+ \`\`\`
2543
+ ## No Changes to Archive
2544
+
2545
+ No active changes found. Use \`/opsx:new\` to create a new change.
2546
+ \`\`\`
2547
+
2548
+ **Guardrails**
2549
+ - Allow any number of changes (1+ is fine, 2+ is the typical use case)
2550
+ - Always prompt for selection, never auto-select
2551
+ - Detect spec conflicts early and resolve by checking codebase
2552
+ - When both changes are implemented, apply specs in chronological order
2553
+ - Skip spec sync only when implementation is missing (warn user)
2554
+ - Show clear per-change status before confirming
2555
+ - Use single confirmation for entire batch
2556
+ - Track and report all outcomes (success/skip/fail)
2557
+ - Preserve .openspec.yaml when moving to archive
2558
+ - Archive directory target uses current date: YYYY-MM-DD-<name>
2559
+ - If archive target exists, fail that change but continue with others`
2560
+ };
2561
+ }
2071
2562
  /**
2072
2563
  * Template for /opsx:verify slash command
2073
2564
  */
@@ -11,33 +11,37 @@ export declare class ChangeMetadataError extends Error {
11
11
  * Validates that a schema name is valid (exists in available schemas).
12
12
  *
13
13
  * @param schemaName - The schema name to validate
14
+ * @param projectRoot - Optional project root for project-local schema resolution
14
15
  * @returns The validated schema name
15
16
  * @throws Error if schema is not found
16
17
  */
17
- export declare function validateSchemaName(schemaName: string): string;
18
+ export declare function validateSchemaName(schemaName: string, projectRoot?: string): string;
18
19
  /**
19
20
  * Writes change metadata to .openspec.yaml in the change directory.
20
21
  *
21
22
  * @param changeDir - The path to the change directory
22
23
  * @param metadata - The metadata to write
24
+ * @param projectRoot - Optional project root for project-local schema resolution
23
25
  * @throws ChangeMetadataError if validation fails or write fails
24
26
  */
25
- export declare function writeChangeMetadata(changeDir: string, metadata: ChangeMetadata): void;
27
+ export declare function writeChangeMetadata(changeDir: string, metadata: ChangeMetadata, projectRoot?: string): void;
26
28
  /**
27
29
  * Reads change metadata from .openspec.yaml in the change directory.
28
30
  *
29
31
  * @param changeDir - The path to the change directory
32
+ * @param projectRoot - Optional project root for project-local schema resolution
30
33
  * @returns The validated metadata, or null if no metadata file exists
31
34
  * @throws ChangeMetadataError if the file exists but is invalid
32
35
  */
33
- export declare function readChangeMetadata(changeDir: string): ChangeMetadata | null;
36
+ export declare function readChangeMetadata(changeDir: string, projectRoot?: string): ChangeMetadata | null;
34
37
  /**
35
38
  * Resolves the schema for a change, with explicit override taking precedence.
36
39
  *
37
40
  * Resolution order:
38
41
  * 1. Explicit schema (if provided)
39
42
  * 2. Schema from .openspec.yaml metadata (if exists)
40
- * 3. Default 'spec-driven'
43
+ * 3. Schema from openspec/config.yaml (if exists)
44
+ * 4. Default 'spec-driven'
41
45
  *
42
46
  * @param changeDir - The path to the change directory
43
47
  * @param explicitSchema - Optional explicit schema override
@@ -3,6 +3,7 @@ import * as path from 'node:path';
3
3
  import * as yaml from 'yaml';
4
4
  import { ChangeMetadataSchema } from '../core/artifact-graph/types.js';
5
5
  import { listSchemas } from '../core/artifact-graph/resolver.js';
6
+ import { readProjectConfig } from '../core/project-config.js';
6
7
  const METADATA_FILENAME = '.openspec.yaml';
7
8
  /**
8
9
  * Error thrown when change metadata validation fails.
@@ -21,11 +22,12 @@ export class ChangeMetadataError extends Error {
21
22
  * Validates that a schema name is valid (exists in available schemas).
22
23
  *
23
24
  * @param schemaName - The schema name to validate
25
+ * @param projectRoot - Optional project root for project-local schema resolution
24
26
  * @returns The validated schema name
25
27
  * @throws Error if schema is not found
26
28
  */
27
- export function validateSchemaName(schemaName) {
28
- const availableSchemas = listSchemas();
29
+ export function validateSchemaName(schemaName, projectRoot) {
30
+ const availableSchemas = listSchemas(projectRoot);
29
31
  if (!availableSchemas.includes(schemaName)) {
30
32
  throw new Error(`Unknown schema '${schemaName}'. Available: ${availableSchemas.join(', ')}`);
31
33
  }
@@ -36,12 +38,13 @@ export function validateSchemaName(schemaName) {
36
38
  *
37
39
  * @param changeDir - The path to the change directory
38
40
  * @param metadata - The metadata to write
41
+ * @param projectRoot - Optional project root for project-local schema resolution
39
42
  * @throws ChangeMetadataError if validation fails or write fails
40
43
  */
41
- export function writeChangeMetadata(changeDir, metadata) {
44
+ export function writeChangeMetadata(changeDir, metadata, projectRoot) {
42
45
  const metaPath = path.join(changeDir, METADATA_FILENAME);
43
46
  // Validate schema exists
44
- validateSchemaName(metadata.schema);
47
+ validateSchemaName(metadata.schema, projectRoot);
45
48
  // Validate with Zod
46
49
  const parseResult = ChangeMetadataSchema.safeParse(metadata);
47
50
  if (!parseResult.success) {
@@ -61,10 +64,11 @@ export function writeChangeMetadata(changeDir, metadata) {
61
64
  * Reads change metadata from .openspec.yaml in the change directory.
62
65
  *
63
66
  * @param changeDir - The path to the change directory
67
+ * @param projectRoot - Optional project root for project-local schema resolution
64
68
  * @returns The validated metadata, or null if no metadata file exists
65
69
  * @throws ChangeMetadataError if the file exists but is invalid
66
70
  */
67
- export function readChangeMetadata(changeDir) {
71
+ export function readChangeMetadata(changeDir, projectRoot) {
68
72
  const metaPath = path.join(changeDir, METADATA_FILENAME);
69
73
  if (!fs.existsSync(metaPath)) {
70
74
  return null;
@@ -91,7 +95,7 @@ export function readChangeMetadata(changeDir) {
91
95
  throw new ChangeMetadataError(`Invalid metadata: ${parseResult.error.message}`, metaPath);
92
96
  }
93
97
  // Validate that the schema exists
94
- const availableSchemas = listSchemas();
98
+ const availableSchemas = listSchemas(projectRoot);
95
99
  if (!availableSchemas.includes(parseResult.data.schema)) {
96
100
  throw new ChangeMetadataError(`Unknown schema '${parseResult.data.schema}'. Available: ${availableSchemas.join(', ')}`, metaPath);
97
101
  }
@@ -103,28 +107,41 @@ export function readChangeMetadata(changeDir) {
103
107
  * Resolution order:
104
108
  * 1. Explicit schema (if provided)
105
109
  * 2. Schema from .openspec.yaml metadata (if exists)
106
- * 3. Default 'spec-driven'
110
+ * 3. Schema from openspec/config.yaml (if exists)
111
+ * 4. Default 'spec-driven'
107
112
  *
108
113
  * @param changeDir - The path to the change directory
109
114
  * @param explicitSchema - Optional explicit schema override
110
115
  * @returns The resolved schema name
111
116
  */
112
117
  export function resolveSchemaForChange(changeDir, explicitSchema) {
118
+ // Derive project root from changeDir (changeDir is typically projectRoot/openspec/changes/change-name)
119
+ const projectRoot = path.resolve(changeDir, '../../..');
113
120
  // 1. Explicit override wins
114
121
  if (explicitSchema) {
115
122
  return explicitSchema;
116
123
  }
117
124
  // 2. Try reading from metadata
118
125
  try {
119
- const metadata = readChangeMetadata(changeDir);
126
+ const metadata = readChangeMetadata(changeDir, projectRoot);
120
127
  if (metadata?.schema) {
121
128
  return metadata.schema;
122
129
  }
123
130
  }
124
131
  catch {
125
- // If metadata read fails, fall back to default
132
+ // If metadata read fails, continue to next option
126
133
  }
127
- // 3. Default
134
+ // 3. Try reading from project config
135
+ try {
136
+ const config = readProjectConfig(projectRoot);
137
+ if (config?.schema) {
138
+ return config.schema;
139
+ }
140
+ }
141
+ catch {
142
+ // If config read fails, fall back to default
143
+ }
144
+ // 4. Default
128
145
  return 'spec-driven';
129
146
  }
130
147
  //# sourceMappingURL=change-metadata.js.map
@@ -5,6 +5,13 @@ export interface CreateChangeOptions {
5
5
  /** The workflow schema to use (default: 'spec-driven') */
6
6
  schema?: string;
7
7
  }
8
+ /**
9
+ * Result of creating a change.
10
+ */
11
+ export interface CreateChangeResult {
12
+ /** The schema that was actually used (resolved from options, config, or default) */
13
+ schema: string;
14
+ }
8
15
  /**
9
16
  * Result of validating a change name.
10
17
  */
@@ -39,13 +46,17 @@ export declare function validateChangeName(name: string): ValidationResult;
39
46
  * @throws Error if the schema name is invalid
40
47
  * @throws Error if the change directory already exists
41
48
  *
49
+ * @returns Result containing the resolved schema name
50
+ *
42
51
  * @example
43
52
  * // Creates openspec/changes/add-auth/ with default schema
44
- * await createChange('/path/to/project', 'add-auth')
53
+ * const result = await createChange('/path/to/project', 'add-auth')
54
+ * console.log(result.schema) // 'spec-driven' or value from config
45
55
  *
46
56
  * @example
47
57
  * // Creates openspec/changes/add-auth/ with TDD schema
48
- * await createChange('/path/to/project', 'add-auth', { schema: 'tdd' })
58
+ * const result = await createChange('/path/to/project', 'add-auth', { schema: 'tdd' })
59
+ * console.log(result.schema) // 'tdd'
49
60
  */
50
- export declare function createChange(projectRoot: string, name: string, options?: CreateChangeOptions): Promise<void>;
61
+ export declare function createChange(projectRoot: string, name: string, options?: CreateChangeOptions): Promise<CreateChangeResult>;
51
62
  //# sourceMappingURL=change-utils.d.ts.map