@fission-ai/openspec 1.3.0 → 1.4.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 (179) hide show
  1. package/README.md +9 -6
  2. package/bin/openspec.js +3 -1
  3. package/dist/cli/index.d.ts +4 -1
  4. package/dist/cli/index.js +46 -2
  5. package/dist/commands/completion.js +7 -0
  6. package/dist/commands/config.js +64 -5
  7. package/dist/commands/context-store.d.ts +3 -0
  8. package/dist/commands/context-store.js +475 -0
  9. package/dist/commands/initiative.d.ts +13 -0
  10. package/dist/commands/initiative.js +318 -0
  11. package/dist/commands/workflow/index.d.ts +2 -0
  12. package/dist/commands/workflow/index.js +1 -0
  13. package/dist/commands/workflow/initiative-link.d.ts +24 -0
  14. package/dist/commands/workflow/initiative-link.js +47 -0
  15. package/dist/commands/workflow/instructions.d.ts +1 -1
  16. package/dist/commands/workflow/instructions.js +46 -83
  17. package/dist/commands/workflow/new-change.d.ts +6 -0
  18. package/dist/commands/workflow/new-change.js +114 -17
  19. package/dist/commands/workflow/set-change.d.ts +13 -0
  20. package/dist/commands/workflow/set-change.js +87 -0
  21. package/dist/commands/workflow/shared.d.ts +5 -3
  22. package/dist/commands/workflow/shared.js +6 -6
  23. package/dist/commands/workflow/status.js +24 -9
  24. package/dist/commands/workflow/templates.js +5 -4
  25. package/dist/commands/workspace/context-status.d.ts +4 -0
  26. package/dist/commands/workspace/context-status.js +59 -0
  27. package/dist/commands/workspace/open-target-selection.d.ts +13 -0
  28. package/dist/commands/workspace/open-target-selection.js +146 -0
  29. package/dist/commands/workspace/open-view.d.ts +62 -0
  30. package/dist/commands/workspace/open-view.js +249 -0
  31. package/dist/commands/workspace/open.d.ts +37 -0
  32. package/dist/commands/workspace/open.js +110 -0
  33. package/dist/commands/workspace/opener-selection.d.ts +11 -0
  34. package/dist/commands/workspace/opener-selection.js +98 -0
  35. package/dist/commands/workspace/operations.d.ts +29 -0
  36. package/dist/commands/workspace/operations.js +543 -0
  37. package/dist/commands/workspace/prompt-theme.d.ts +29 -0
  38. package/dist/commands/workspace/prompt-theme.js +24 -0
  39. package/dist/commands/workspace/registration.d.ts +13 -0
  40. package/dist/commands/workspace/registration.js +84 -0
  41. package/dist/commands/workspace/selection.d.ts +9 -0
  42. package/dist/commands/workspace/selection.js +115 -0
  43. package/dist/commands/workspace/setup-prompts.d.ts +13 -0
  44. package/dist/commands/workspace/setup-prompts.js +121 -0
  45. package/dist/commands/workspace/types.d.ts +103 -0
  46. package/dist/commands/workspace/types.js +36 -0
  47. package/dist/commands/workspace.d.ts +6 -0
  48. package/dist/commands/workspace.js +587 -0
  49. package/dist/core/artifact-graph/index.d.ts +3 -1
  50. package/dist/core/artifact-graph/index.js +1 -0
  51. package/dist/core/artifact-graph/instruction-loader.d.ts +41 -1
  52. package/dist/core/artifact-graph/instruction-loader.js +51 -9
  53. package/dist/core/artifact-graph/outputs.d.ts +14 -0
  54. package/dist/core/artifact-graph/outputs.js +39 -0
  55. package/dist/core/artifact-graph/state.js +2 -25
  56. package/dist/core/artifact-graph/types.d.ts +0 -5
  57. package/dist/core/artifact-graph/types.js +0 -14
  58. package/dist/core/change-metadata/index.d.ts +2 -0
  59. package/dist/core/change-metadata/index.js +2 -0
  60. package/dist/core/change-metadata/schema.d.ts +18 -0
  61. package/dist/core/change-metadata/schema.js +28 -0
  62. package/dist/core/change-status-policy.d.ts +50 -0
  63. package/dist/core/change-status-policy.js +70 -0
  64. package/dist/core/collections/index.d.ts +3 -0
  65. package/dist/core/collections/index.js +3 -0
  66. package/dist/core/collections/initiatives/collection.d.ts +4 -0
  67. package/dist/core/collections/initiatives/collection.js +17 -0
  68. package/dist/core/collections/initiatives/index.d.ts +6 -0
  69. package/dist/core/collections/initiatives/index.js +6 -0
  70. package/dist/core/collections/initiatives/operations.d.ts +49 -0
  71. package/dist/core/collections/initiatives/operations.js +175 -0
  72. package/dist/core/collections/initiatives/resolution.d.ts +87 -0
  73. package/dist/core/collections/initiatives/resolution.js +374 -0
  74. package/dist/core/collections/initiatives/schema.d.ts +41 -0
  75. package/dist/core/collections/initiatives/schema.js +134 -0
  76. package/dist/core/collections/initiatives/templates.d.ts +12 -0
  77. package/dist/core/collections/initiatives/templates.js +90 -0
  78. package/dist/core/collections/runtime.d.ts +46 -0
  79. package/dist/core/collections/runtime.js +194 -0
  80. package/dist/core/completions/command-registry.d.ts +1 -5
  81. package/dist/core/completions/command-registry.js +532 -32
  82. package/dist/core/completions/completion-provider.d.ts +11 -0
  83. package/dist/core/completions/completion-provider.js +27 -0
  84. package/dist/core/completions/generators/bash-generator.d.ts +3 -0
  85. package/dist/core/completions/generators/bash-generator.js +60 -4
  86. package/dist/core/completions/generators/fish-generator.js +3 -0
  87. package/dist/core/completions/generators/powershell-generator.d.ts +3 -0
  88. package/dist/core/completions/generators/powershell-generator.js +63 -4
  89. package/dist/core/completions/generators/zsh-generator.d.ts +3 -0
  90. package/dist/core/completions/generators/zsh-generator.js +46 -22
  91. package/dist/core/completions/installers/zsh-installer.d.ts +0 -8
  92. package/dist/core/completions/installers/zsh-installer.js +3 -31
  93. package/dist/core/completions/shared-flags.d.ts +12 -0
  94. package/dist/core/completions/shared-flags.js +28 -0
  95. package/dist/core/completions/templates/bash-templates.d.ts +1 -1
  96. package/dist/core/completions/templates/bash-templates.js +6 -0
  97. package/dist/core/completions/templates/fish-templates.d.ts +1 -1
  98. package/dist/core/completions/templates/fish-templates.js +6 -0
  99. package/dist/core/completions/templates/powershell-templates.d.ts +1 -1
  100. package/dist/core/completions/templates/powershell-templates.js +9 -0
  101. package/dist/core/completions/templates/zsh-templates.d.ts +1 -1
  102. package/dist/core/completions/templates/zsh-templates.js +9 -0
  103. package/dist/core/completions/types.d.ts +23 -1
  104. package/dist/core/config.js +3 -1
  105. package/dist/core/context-store/binding.d.ts +53 -0
  106. package/dist/core/context-store/binding.js +197 -0
  107. package/dist/core/context-store/errors.d.ts +20 -0
  108. package/dist/core/context-store/errors.js +22 -0
  109. package/dist/core/context-store/foundation.d.ts +55 -0
  110. package/dist/core/context-store/foundation.js +321 -0
  111. package/dist/core/context-store/index.d.ts +6 -0
  112. package/dist/core/context-store/index.js +6 -0
  113. package/dist/core/context-store/operations.d.ts +85 -0
  114. package/dist/core/context-store/operations.js +528 -0
  115. package/dist/core/context-store/registry.d.ts +45 -0
  116. package/dist/core/context-store/registry.js +229 -0
  117. package/dist/core/global-config.d.ts +6 -1
  118. package/dist/core/global-config.js +15 -16
  119. package/dist/core/index.d.ts +5 -1
  120. package/dist/core/index.js +4 -0
  121. package/dist/core/parsers/change-parser.js +7 -3
  122. package/dist/core/parsers/markdown-parser.d.ts +4 -0
  123. package/dist/core/parsers/markdown-parser.js +41 -1
  124. package/dist/core/parsers/requirement-blocks.js +5 -5
  125. package/dist/core/parsers/spec-structure.d.ts +9 -0
  126. package/dist/core/parsers/spec-structure.js +88 -0
  127. package/dist/core/planning-home.d.ts +21 -0
  128. package/dist/core/planning-home.js +108 -0
  129. package/dist/core/profiles.d.ts +1 -1
  130. package/dist/core/profiles.js +1 -1
  131. package/dist/core/specs-apply.js +9 -1
  132. package/dist/core/templates/workflows/apply-change.js +10 -4
  133. package/dist/core/templates/workflows/archive-change.js +21 -15
  134. package/dist/core/templates/workflows/bulk-archive-change.js +14 -10
  135. package/dist/core/templates/workflows/continue-change.js +6 -4
  136. package/dist/core/templates/workflows/explore.js +8 -10
  137. package/dist/core/templates/workflows/ff-change.js +8 -6
  138. package/dist/core/templates/workflows/new-change.js +6 -6
  139. package/dist/core/templates/workflows/onboard.js +13 -15
  140. package/dist/core/templates/workflows/propose.js +8 -6
  141. package/dist/core/templates/workflows/sync-specs.js +28 -10
  142. package/dist/core/templates/workflows/verify-change.js +16 -10
  143. package/dist/core/update.d.ts +5 -0
  144. package/dist/core/update.js +20 -0
  145. package/dist/core/validation/validator.d.ts +11 -0
  146. package/dist/core/validation/validator.js +28 -2
  147. package/dist/core/workspace/foundation.d.ts +67 -0
  148. package/dist/core/workspace/foundation.js +295 -0
  149. package/dist/core/workspace/index.d.ts +8 -0
  150. package/dist/core/workspace/index.js +8 -0
  151. package/dist/core/workspace/legacy-state.d.ts +28 -0
  152. package/dist/core/workspace/legacy-state.js +200 -0
  153. package/dist/core/workspace/link-input.d.ts +9 -0
  154. package/dist/core/workspace/link-input.js +32 -0
  155. package/dist/core/workspace/open-surface.d.ts +45 -0
  156. package/dist/core/workspace/open-surface.js +215 -0
  157. package/dist/core/workspace/openers.d.ts +21 -0
  158. package/dist/core/workspace/openers.js +124 -0
  159. package/dist/core/workspace/registry.d.ts +24 -0
  160. package/dist/core/workspace/registry.js +146 -0
  161. package/dist/core/workspace/skills.d.ts +57 -0
  162. package/dist/core/workspace/skills.js +334 -0
  163. package/dist/core/workspace/state-io.d.ts +10 -0
  164. package/dist/core/workspace/state-io.js +119 -0
  165. package/dist/telemetry/config.d.ts +7 -1
  166. package/dist/telemetry/config.js +87 -19
  167. package/dist/telemetry/index.js +19 -0
  168. package/dist/utils/change-metadata.d.ts +5 -2
  169. package/dist/utils/change-metadata.js +7 -13
  170. package/dist/utils/change-utils.d.ts +9 -0
  171. package/dist/utils/change-utils.js +7 -5
  172. package/dist/utils/file-system.d.ts +5 -0
  173. package/dist/utils/file-system.js +21 -1
  174. package/package.json +2 -1
  175. package/schemas/workspace-planning/schema.yaml +72 -0
  176. package/schemas/workspace-planning/templates/design.md +33 -0
  177. package/schemas/workspace-planning/templates/proposal.md +28 -0
  178. package/schemas/workspace-planning/templates/spec.md +9 -0
  179. package/schemas/workspace-planning/templates/tasks.md +15 -0
@@ -0,0 +1,134 @@
1
+ import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
2
+ import { z } from 'zod';
3
+ export const INITIATIVE_COLLECTION_ID = 'initiatives';
4
+ export const INITIATIVE_FILE_NAME = 'initiative.yaml';
5
+ export const INITIATIVE_REQUIREMENTS_FILE_NAME = 'requirements.md';
6
+ export const INITIATIVE_DESIGN_FILE_NAME = 'design.md';
7
+ export const INITIATIVE_DECISIONS_FILE_NAME = 'decisions.md';
8
+ export const INITIATIVE_QUESTIONS_FILE_NAME = 'questions.md';
9
+ export const INITIATIVE_TASKS_FILE_NAME = 'tasks.md';
10
+ export const INITIATIVE_MARKDOWN_FILE_NAMES = [
11
+ INITIATIVE_REQUIREMENTS_FILE_NAME,
12
+ INITIATIVE_DESIGN_FILE_NAME,
13
+ INITIATIVE_DECISIONS_FILE_NAME,
14
+ INITIATIVE_QUESTIONS_FILE_NAME,
15
+ INITIATIVE_TASKS_FILE_NAME,
16
+ ];
17
+ export const INITIATIVE_FILE_NAMES = [
18
+ INITIATIVE_FILE_NAME,
19
+ ...INITIATIVE_MARKDOWN_FILE_NAMES,
20
+ ];
21
+ export const INITIATIVE_STATUSES = [
22
+ 'exploring',
23
+ 'active',
24
+ 'complete',
25
+ 'archived',
26
+ ];
27
+ const INITIATIVE_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
28
+ function assertNoNul(value, label) {
29
+ if (value.includes('\0')) {
30
+ throw new Error(`${label} must not contain NUL bytes`);
31
+ }
32
+ }
33
+ function nonBlankString(label) {
34
+ return z.string().refine((value) => value.trim().length > 0, {
35
+ message: `${label} must not be empty`,
36
+ });
37
+ }
38
+ const InitiativeMetadataValueSchema = z.lazy(() => z.union([
39
+ z.string(),
40
+ z.number().finite(),
41
+ z.boolean(),
42
+ z.null(),
43
+ z.array(InitiativeMetadataValueSchema),
44
+ z.record(z.string(), InitiativeMetadataValueSchema),
45
+ ]));
46
+ const InitiativeMetadataSchema = z.record(z.string(), InitiativeMetadataValueSchema);
47
+ const InitiativeStateSchema = z.object({
48
+ version: z.literal(1),
49
+ id: z.string(),
50
+ title: nonBlankString('title'),
51
+ summary: nonBlankString('summary'),
52
+ status: z.enum(INITIATIVE_STATUSES),
53
+ created: z.string().regex(INITIATIVE_DATE_PATTERN, {
54
+ message: 'created must be YYYY-MM-DD format',
55
+ }),
56
+ owners: z.array(nonBlankString('owner')).default([]),
57
+ metadata: InitiativeMetadataSchema.default({}),
58
+ }).strict();
59
+ function formatZodIssues(error) {
60
+ return error.issues
61
+ .map((issue) => {
62
+ const location = issue.path.length > 0 ? issue.path.join('.') : 'root';
63
+ return `${location}: ${issue.message}`;
64
+ })
65
+ .join('; ');
66
+ }
67
+ function parseYamlObject(content, label) {
68
+ try {
69
+ return parseYaml(content);
70
+ }
71
+ catch (error) {
72
+ const message = error instanceof Error ? error.message : String(error);
73
+ throw new Error(`Invalid ${label}: ${message}`);
74
+ }
75
+ }
76
+ export function validateInitiativeId(id) {
77
+ assertNoNul(id, 'Initiative id');
78
+ if (id.length === 0) {
79
+ throw new Error('Initiative id must not be empty');
80
+ }
81
+ if (id === '.' || id === '..') {
82
+ throw new Error(`Initiative id must not be '${id}'`);
83
+ }
84
+ if (/[\\/]/u.test(id)) {
85
+ throw new Error('Initiative id must not contain path separators');
86
+ }
87
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(id)) {
88
+ throw new Error('Initiative id must be kebab-case with lowercase letters, numbers, and single hyphen separators');
89
+ }
90
+ return id;
91
+ }
92
+ export function isValidInitiativeId(id) {
93
+ try {
94
+ validateInitiativeId(id);
95
+ return true;
96
+ }
97
+ catch {
98
+ return false;
99
+ }
100
+ }
101
+ function parseInitiativeStateInput(raw) {
102
+ const result = InitiativeStateSchema.safeParse(raw);
103
+ if (!result.success) {
104
+ throw new Error(`Invalid initiative state: ${formatZodIssues(result.error)}`);
105
+ }
106
+ validateInitiativeId(result.data.id);
107
+ return {
108
+ version: 1,
109
+ id: result.data.id,
110
+ title: result.data.title,
111
+ summary: result.data.summary,
112
+ status: result.data.status,
113
+ created: result.data.created,
114
+ owners: result.data.owners,
115
+ metadata: result.data.metadata,
116
+ };
117
+ }
118
+ export function parseInitiativeState(content) {
119
+ return parseInitiativeStateInput(parseYamlObject(content, 'initiative state'));
120
+ }
121
+ export function serializeInitiativeState(state) {
122
+ const parsedState = parseInitiativeStateInput(state);
123
+ return stringifyYaml({
124
+ version: 1,
125
+ id: parsedState.id,
126
+ title: parsedState.title,
127
+ summary: parsedState.summary,
128
+ status: parsedState.status,
129
+ created: parsedState.created,
130
+ owners: parsedState.owners,
131
+ metadata: parsedState.metadata,
132
+ });
133
+ }
134
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1,12 @@
1
+ import { type InitiativeMarkdownFileName, type InitiativeState } from './schema.js';
2
+ export interface InitiativeTemplateFile {
3
+ fileName: InitiativeMarkdownFileName;
4
+ content: string;
5
+ }
6
+ export declare function buildInitiativeRequirementsTemplate(state: InitiativeState): string;
7
+ export declare function buildInitiativeDesignTemplate(state: InitiativeState): string;
8
+ export declare function buildInitiativeDecisionsTemplate(state: InitiativeState): string;
9
+ export declare function buildInitiativeQuestionsTemplate(): string;
10
+ export declare function buildInitiativeTasksTemplate(): string;
11
+ export declare function buildDefaultInitiativeFiles(state: InitiativeState): InitiativeTemplateFile[];
12
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1,90 @@
1
+ import { INITIATIVE_DECISIONS_FILE_NAME, INITIATIVE_DESIGN_FILE_NAME, INITIATIVE_MARKDOWN_FILE_NAMES, INITIATIVE_QUESTIONS_FILE_NAME, INITIATIVE_REQUIREMENTS_FILE_NAME, INITIATIVE_TASKS_FILE_NAME, } from './schema.js';
2
+ function withTrailingNewline(content) {
3
+ return content.endsWith('\n') ? content : `${content}\n`;
4
+ }
5
+ export function buildInitiativeRequirementsTemplate(state) {
6
+ return withTrailingNewline(`# Requirements
7
+
8
+ ## Product Intent
9
+
10
+ ${state.summary}
11
+
12
+ ## Accepted Requirements
13
+
14
+ - TBD
15
+
16
+ ## Out Of Scope
17
+
18
+ - TBD
19
+ `);
20
+ }
21
+ export function buildInitiativeDesignTemplate(state) {
22
+ return withTrailingNewline(`# Design
23
+
24
+ ## Context
25
+
26
+ ${state.summary}
27
+
28
+ ## Approach
29
+
30
+ TBD
31
+
32
+ ## Affected Areas
33
+
34
+ - TBD
35
+
36
+ ## Dependencies
37
+
38
+ - TBD
39
+
40
+ ## Risks
41
+
42
+ - TBD
43
+ `);
44
+ }
45
+ export function buildInitiativeDecisionsTemplate(state) {
46
+ return withTrailingNewline(`# Decisions
47
+
48
+ ## Accepted Decisions
49
+
50
+ ### ${state.created}: ${state.title}
51
+
52
+ - Decision: TBD
53
+ - Why: TBD
54
+ - Implications: TBD
55
+ `);
56
+ }
57
+ export function buildInitiativeQuestionsTemplate() {
58
+ return withTrailingNewline(`# Questions
59
+
60
+ ## Open Questions
61
+
62
+ - TBD
63
+
64
+ ## Resolved Questions
65
+
66
+ - TBD
67
+ `);
68
+ }
69
+ export function buildInitiativeTasksTemplate() {
70
+ return withTrailingNewline(`# Tasks
71
+
72
+ ## Coordination Tasks
73
+
74
+ - [ ] TBD
75
+ `);
76
+ }
77
+ export function buildDefaultInitiativeFiles(state) {
78
+ const templates = {
79
+ [INITIATIVE_REQUIREMENTS_FILE_NAME]: buildInitiativeRequirementsTemplate(state),
80
+ [INITIATIVE_DESIGN_FILE_NAME]: buildInitiativeDesignTemplate(state),
81
+ [INITIATIVE_DECISIONS_FILE_NAME]: buildInitiativeDecisionsTemplate(state),
82
+ [INITIATIVE_QUESTIONS_FILE_NAME]: buildInitiativeQuestionsTemplate(),
83
+ [INITIATIVE_TASKS_FILE_NAME]: buildInitiativeTasksTemplate(),
84
+ };
85
+ return INITIATIVE_MARKDOWN_FILE_NAMES.map((fileName) => ({
86
+ fileName,
87
+ content: templates[fileName],
88
+ }));
89
+ }
90
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1,46 @@
1
+ export type CollectionMetadata = Readonly<Record<string, unknown>>;
2
+ export type CollectionHooks = Readonly<Record<string, unknown>>;
3
+ export interface CollectionDefinition<THandle = unknown> {
4
+ id: string;
5
+ mount: string;
6
+ metadata?: CollectionMetadata;
7
+ hooks?: CollectionHooks;
8
+ createHandle?: (context: MountedCollectionContext) => THandle;
9
+ }
10
+ export interface CollectionRegistry {
11
+ list(): readonly CollectionDefinition[];
12
+ get<THandle = unknown>(collectionId: string): CollectionDefinition<THandle> | undefined;
13
+ require<THandle = unknown>(collectionId: string): CollectionDefinition<THandle>;
14
+ }
15
+ export interface MountedCollectionContext {
16
+ storeRoot: string;
17
+ collectionId: string;
18
+ mount: string;
19
+ mountRoot: string;
20
+ resolvePath(relativePath?: string): string;
21
+ toStorePath(relativePath?: string): string;
22
+ }
23
+ export interface MountedCollection<THandle = unknown> {
24
+ collectionId: string;
25
+ mount: string;
26
+ mountRoot: string;
27
+ context: MountedCollectionContext;
28
+ handle: THandle | undefined;
29
+ resolvePath(relativePath?: string): string;
30
+ toStorePath(relativePath?: string): string;
31
+ }
32
+ export interface MountedCollectionRegistry {
33
+ list(): readonly MountedCollection[];
34
+ get<THandle = unknown>(collectionId: string): MountedCollection<THandle> | undefined;
35
+ require<THandle = unknown>(collectionId: string): MountedCollection<THandle>;
36
+ }
37
+ export interface MountCollectionsInput {
38
+ storeRoot: string;
39
+ collections: CollectionRegistry;
40
+ }
41
+ export declare function validateCollectionId(id: string): string;
42
+ export declare function validateMount(mount: string): string;
43
+ export declare function parseCollectionPath(input?: string): string;
44
+ export declare function createCollectionRegistry(definitions: readonly CollectionDefinition[]): CollectionRegistry;
45
+ export declare function mountCollections(input: MountCollectionsInput): MountedCollectionRegistry;
46
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,194 @@
1
+ import * as path from 'node:path';
2
+ import { FileSystemUtils } from '../../utils/file-system.js';
3
+ function assertNoNul(value, label) {
4
+ if (value.includes('\0')) {
5
+ throw new Error(`${label} must not contain NUL bytes`);
6
+ }
7
+ }
8
+ function validateKebabSegment(value, label) {
9
+ assertNoNul(value, label);
10
+ if (value.length === 0) {
11
+ throw new Error(`${label} must not be empty`);
12
+ }
13
+ if (value === '.' || value === '..') {
14
+ throw new Error(`${label} must not be '${value}'`);
15
+ }
16
+ if (/[\\/]/u.test(value)) {
17
+ throw new Error(`${label} must not contain path separators`);
18
+ }
19
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(value)) {
20
+ throw new Error(`${label} must be kebab-case with lowercase letters, numbers, and single hyphen separators`);
21
+ }
22
+ return value;
23
+ }
24
+ export function validateCollectionId(id) {
25
+ return validateKebabSegment(id, 'Collection id');
26
+ }
27
+ export function validateMount(mount) {
28
+ assertNoNul(mount, 'Collection mount');
29
+ if (mount.startsWith('.')) {
30
+ throw new Error(`Collection mount '${mount}' is reserved`);
31
+ }
32
+ return validateKebabSegment(mount, 'Collection mount');
33
+ }
34
+ function isWindowsDrivePath(value) {
35
+ return /^[A-Za-z]:/u.test(value);
36
+ }
37
+ function isUncPath(value) {
38
+ return value.startsWith('\\\\') || value.startsWith('//');
39
+ }
40
+ export function parseCollectionPath(input = '') {
41
+ assertNoNul(input, 'Collection path');
42
+ if (input.length === 0) {
43
+ return '';
44
+ }
45
+ if (input.includes('\\')) {
46
+ throw new Error('Collection path must use forward slashes');
47
+ }
48
+ if (isWindowsDrivePath(input)) {
49
+ throw new Error('Collection path must not be a Windows drive path');
50
+ }
51
+ if (isUncPath(input) || path.posix.isAbsolute(input)) {
52
+ throw new Error('Collection path must be relative');
53
+ }
54
+ const segments = input.split('/');
55
+ for (const segment of segments) {
56
+ if (segment.length === 0) {
57
+ throw new Error('Collection path must not contain empty segments');
58
+ }
59
+ if (segment === '.' || segment === '..') {
60
+ throw new Error('Collection path must not contain dot segments');
61
+ }
62
+ }
63
+ return segments.join('/');
64
+ }
65
+ function compareCollectionDefinitions(a, b) {
66
+ return a.id.localeCompare(b.id);
67
+ }
68
+ export function createCollectionRegistry(definitions) {
69
+ const byId = new Map();
70
+ const mountOwners = new Map();
71
+ for (const definition of definitions) {
72
+ const id = validateCollectionId(definition.id);
73
+ const mount = validateMount(definition.mount);
74
+ if (byId.has(id)) {
75
+ throw new Error(`Duplicate collection id '${id}'`);
76
+ }
77
+ const existingMountOwner = mountOwners.get(mount);
78
+ if (existingMountOwner) {
79
+ throw new Error(`Duplicate collection mount '${mount}' for '${existingMountOwner}' and '${id}'`);
80
+ }
81
+ const normalizedDefinition = {
82
+ ...definition,
83
+ id,
84
+ mount,
85
+ };
86
+ byId.set(id, normalizedDefinition);
87
+ mountOwners.set(mount, id);
88
+ }
89
+ const sortedDefinitions = Array.from(byId.values()).sort(compareCollectionDefinitions);
90
+ return {
91
+ list() {
92
+ return [...sortedDefinitions];
93
+ },
94
+ get(collectionId) {
95
+ const id = validateCollectionId(collectionId);
96
+ return byId.get(id);
97
+ },
98
+ require(collectionId) {
99
+ const definition = this.get(collectionId);
100
+ if (!definition) {
101
+ throw new Error(`Unknown collection '${collectionId}'`);
102
+ }
103
+ return definition;
104
+ },
105
+ };
106
+ }
107
+ function isWindowsLikePath(candidatePath) {
108
+ return /^[A-Za-z]:[\\/]/u.test(candidatePath) || candidatePath.startsWith('\\\\');
109
+ }
110
+ function relativePath(fromPath, toPath) {
111
+ if (isWindowsLikePath(fromPath) || isWindowsLikePath(toPath)) {
112
+ return path.win32.relative(path.win32.normalize(fromPath), path.win32.normalize(toPath));
113
+ }
114
+ return path.posix.relative(fromPath.replace(/\\/g, '/'), toPath.replace(/\\/g, '/'));
115
+ }
116
+ function isRelativePathAbsolute(value, windowsLike) {
117
+ return windowsLike ? path.win32.isAbsolute(value) : path.posix.isAbsolute(value);
118
+ }
119
+ function isSameOrDescendant(rootPath, candidatePath) {
120
+ const windowsLike = isWindowsLikePath(rootPath) || isWindowsLikePath(candidatePath);
121
+ const relative = relativePath(rootPath, candidatePath);
122
+ const escapesRoot = /^\.\.(?:[\\/]|$)/u.test(relative);
123
+ return (relative === '' ||
124
+ (!escapesRoot && !isRelativePathAbsolute(relative, windowsLike)));
125
+ }
126
+ function getMountRoot(storeRoot, mount) {
127
+ return FileSystemUtils.joinPath(storeRoot, validateMount(mount));
128
+ }
129
+ function resolvePathInsideMount(mountRoot, relativePath) {
130
+ const collectionPath = parseCollectionPath(relativePath);
131
+ const resolvedPath = collectionPath.length > 0
132
+ ? FileSystemUtils.joinPath(mountRoot, collectionPath)
133
+ : mountRoot;
134
+ if (!isSameOrDescendant(mountRoot, resolvedPath)) {
135
+ throw new Error(`Collection path escapes mount: ${relativePath ?? ''}`);
136
+ }
137
+ return resolvedPath;
138
+ }
139
+ function toStorePath(mount, relativePath) {
140
+ const collectionPath = parseCollectionPath(relativePath);
141
+ return collectionPath.length > 0
142
+ ? `${validateMount(mount)}/${collectionPath}`
143
+ : validateMount(mount);
144
+ }
145
+ function createMountedCollection(storeRoot, definition) {
146
+ const mountRoot = getMountRoot(storeRoot, definition.mount);
147
+ const resolveMountedPath = (relativePath) => resolvePathInsideMount(mountRoot, relativePath);
148
+ const resolveStorePath = (relativePath) => toStorePath(definition.mount, relativePath);
149
+ const context = {
150
+ storeRoot,
151
+ collectionId: definition.id,
152
+ mount: definition.mount,
153
+ mountRoot,
154
+ resolvePath: resolveMountedPath,
155
+ toStorePath: resolveStorePath,
156
+ };
157
+ return {
158
+ collectionId: definition.id,
159
+ mount: definition.mount,
160
+ mountRoot,
161
+ context,
162
+ handle: definition.createHandle?.(context),
163
+ resolvePath: resolveMountedPath,
164
+ toStorePath: resolveStorePath,
165
+ };
166
+ }
167
+ export function mountCollections(input) {
168
+ if (input.storeRoot.length === 0) {
169
+ throw new Error('Context store root must not be empty');
170
+ }
171
+ const byId = new Map();
172
+ for (const definition of input.collections.list()) {
173
+ const mountedCollection = createMountedCollection(input.storeRoot, definition);
174
+ byId.set(mountedCollection.collectionId, mountedCollection);
175
+ }
176
+ const sortedCollections = Array.from(byId.values()).sort((a, b) => a.collectionId.localeCompare(b.collectionId));
177
+ return {
178
+ list() {
179
+ return [...sortedCollections];
180
+ },
181
+ get(collectionId) {
182
+ const id = validateCollectionId(collectionId);
183
+ return byId.get(id);
184
+ },
185
+ require(collectionId) {
186
+ const mountedCollection = this.get(collectionId);
187
+ if (!mountedCollection) {
188
+ throw new Error(`Unknown mounted collection '${collectionId}'`);
189
+ }
190
+ return mountedCollection;
191
+ },
192
+ };
193
+ }
194
+ //# sourceMappingURL=runtime.js.map
@@ -1,7 +1,3 @@
1
- import { CommandDefinition } from './types.js';
2
- /**
3
- * Registry of all OpenSpec CLI commands with their flags and metadata.
4
- * This registry is used to generate shell completion scripts.
5
- */
1
+ import type { CommandDefinition } from './types.js';
6
2
  export declare const COMMAND_REGISTRY: CommandDefinition[];
7
3
  //# sourceMappingURL=command-registry.d.ts.map