openspec-cn 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.
Files changed (235) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +153 -0
  3. package/bin/openspec.js +3 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.js +480 -0
  6. package/dist/commands/change.d.ts +35 -0
  7. package/dist/commands/change.js +277 -0
  8. package/dist/commands/completion.d.ts +72 -0
  9. package/dist/commands/completion.js +257 -0
  10. package/dist/commands/config.d.ts +8 -0
  11. package/dist/commands/config.js +198 -0
  12. package/dist/commands/feedback.d.ts +9 -0
  13. package/dist/commands/feedback.js +183 -0
  14. package/dist/commands/schema.d.ts +6 -0
  15. package/dist/commands/schema.js +869 -0
  16. package/dist/commands/show.d.ts +14 -0
  17. package/dist/commands/show.js +132 -0
  18. package/dist/commands/spec.d.ts +15 -0
  19. package/dist/commands/spec.js +225 -0
  20. package/dist/commands/validate.d.ts +24 -0
  21. package/dist/commands/validate.js +294 -0
  22. package/dist/commands/workflow/index.d.ts +17 -0
  23. package/dist/commands/workflow/index.js +12 -0
  24. package/dist/commands/workflow/instructions.d.ts +29 -0
  25. package/dist/commands/workflow/instructions.js +381 -0
  26. package/dist/commands/workflow/new-change.d.ts +11 -0
  27. package/dist/commands/workflow/new-change.js +44 -0
  28. package/dist/commands/workflow/schemas.d.ts +10 -0
  29. package/dist/commands/workflow/schemas.js +34 -0
  30. package/dist/commands/workflow/shared.d.ts +52 -0
  31. package/dist/commands/workflow/shared.js +111 -0
  32. package/dist/commands/workflow/status.d.ts +14 -0
  33. package/dist/commands/workflow/status.js +58 -0
  34. package/dist/commands/workflow/templates.d.ts +16 -0
  35. package/dist/commands/workflow/templates.js +68 -0
  36. package/dist/core/archive.d.ts +11 -0
  37. package/dist/core/archive.js +280 -0
  38. package/dist/core/artifact-graph/graph.d.ts +56 -0
  39. package/dist/core/artifact-graph/graph.js +141 -0
  40. package/dist/core/artifact-graph/index.d.ts +7 -0
  41. package/dist/core/artifact-graph/index.js +13 -0
  42. package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
  43. package/dist/core/artifact-graph/instruction-loader.js +214 -0
  44. package/dist/core/artifact-graph/resolver.d.ts +81 -0
  45. package/dist/core/artifact-graph/resolver.js +257 -0
  46. package/dist/core/artifact-graph/schema.d.ts +13 -0
  47. package/dist/core/artifact-graph/schema.js +108 -0
  48. package/dist/core/artifact-graph/state.d.ts +12 -0
  49. package/dist/core/artifact-graph/state.js +54 -0
  50. package/dist/core/artifact-graph/types.d.ts +45 -0
  51. package/dist/core/artifact-graph/types.js +43 -0
  52. package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
  53. package/dist/core/command-generation/adapters/amazon-q.js +26 -0
  54. package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
  55. package/dist/core/command-generation/adapters/antigravity.js +26 -0
  56. package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
  57. package/dist/core/command-generation/adapters/auggie.js +27 -0
  58. package/dist/core/command-generation/adapters/claude.d.ts +13 -0
  59. package/dist/core/command-generation/adapters/claude.js +50 -0
  60. package/dist/core/command-generation/adapters/cline.d.ts +14 -0
  61. package/dist/core/command-generation/adapters/cline.js +27 -0
  62. package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
  63. package/dist/core/command-generation/adapters/codebuddy.js +28 -0
  64. package/dist/core/command-generation/adapters/codex.d.ts +13 -0
  65. package/dist/core/command-generation/adapters/codex.js +27 -0
  66. package/dist/core/command-generation/adapters/continue.d.ts +13 -0
  67. package/dist/core/command-generation/adapters/continue.js +28 -0
  68. package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
  69. package/dist/core/command-generation/adapters/costrict.js +27 -0
  70. package/dist/core/command-generation/adapters/crush.d.ts +13 -0
  71. package/dist/core/command-generation/adapters/crush.js +30 -0
  72. package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
  73. package/dist/core/command-generation/adapters/cursor.js +44 -0
  74. package/dist/core/command-generation/adapters/factory.d.ts +13 -0
  75. package/dist/core/command-generation/adapters/factory.js +27 -0
  76. package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
  77. package/dist/core/command-generation/adapters/gemini.js +26 -0
  78. package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
  79. package/dist/core/command-generation/adapters/github-copilot.js +26 -0
  80. package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
  81. package/dist/core/command-generation/adapters/iflow.js +29 -0
  82. package/dist/core/command-generation/adapters/index.d.ts +27 -0
  83. package/dist/core/command-generation/adapters/index.js +27 -0
  84. package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
  85. package/dist/core/command-generation/adapters/kilocode.js +23 -0
  86. package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
  87. package/dist/core/command-generation/adapters/opencode.js +26 -0
  88. package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
  89. package/dist/core/command-generation/adapters/qoder.js +30 -0
  90. package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
  91. package/dist/core/command-generation/adapters/qwen.js +26 -0
  92. package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
  93. package/dist/core/command-generation/adapters/roocode.js +27 -0
  94. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  95. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  96. package/dist/core/command-generation/generator.d.ts +21 -0
  97. package/dist/core/command-generation/generator.js +27 -0
  98. package/dist/core/command-generation/index.d.ts +22 -0
  99. package/dist/core/command-generation/index.js +24 -0
  100. package/dist/core/command-generation/registry.d.ts +36 -0
  101. package/dist/core/command-generation/registry.js +88 -0
  102. package/dist/core/command-generation/types.d.ts +55 -0
  103. package/dist/core/command-generation/types.js +8 -0
  104. package/dist/core/completions/command-registry.d.ts +7 -0
  105. package/dist/core/completions/command-registry.js +456 -0
  106. package/dist/core/completions/completion-provider.d.ts +60 -0
  107. package/dist/core/completions/completion-provider.js +102 -0
  108. package/dist/core/completions/factory.d.ts +64 -0
  109. package/dist/core/completions/factory.js +75 -0
  110. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  111. package/dist/core/completions/generators/bash-generator.js +174 -0
  112. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  113. package/dist/core/completions/generators/fish-generator.js +157 -0
  114. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  115. package/dist/core/completions/generators/powershell-generator.js +207 -0
  116. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  117. package/dist/core/completions/generators/zsh-generator.js +250 -0
  118. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  119. package/dist/core/completions/installers/bash-installer.js +318 -0
  120. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  121. package/dist/core/completions/installers/fish-installer.js +143 -0
  122. package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
  123. package/dist/core/completions/installers/powershell-installer.js +327 -0
  124. package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
  125. package/dist/core/completions/installers/zsh-installer.js +449 -0
  126. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  127. package/dist/core/completions/templates/bash-templates.js +24 -0
  128. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  129. package/dist/core/completions/templates/fish-templates.js +39 -0
  130. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  131. package/dist/core/completions/templates/powershell-templates.js +25 -0
  132. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  133. package/dist/core/completions/templates/zsh-templates.js +36 -0
  134. package/dist/core/completions/types.d.ts +79 -0
  135. package/dist/core/completions/types.js +2 -0
  136. package/dist/core/config-prompts.d.ts +9 -0
  137. package/dist/core/config-prompts.js +34 -0
  138. package/dist/core/config-schema.d.ts +76 -0
  139. package/dist/core/config-schema.js +200 -0
  140. package/dist/core/config.d.ts +17 -0
  141. package/dist/core/config.js +30 -0
  142. package/dist/core/converters/json-converter.d.ts +6 -0
  143. package/dist/core/converters/json-converter.js +51 -0
  144. package/dist/core/global-config.d.ts +39 -0
  145. package/dist/core/global-config.js +115 -0
  146. package/dist/core/index.d.ts +2 -0
  147. package/dist/core/index.js +3 -0
  148. package/dist/core/init.d.ts +32 -0
  149. package/dist/core/init.js +433 -0
  150. package/dist/core/legacy-cleanup.d.ts +162 -0
  151. package/dist/core/legacy-cleanup.js +501 -0
  152. package/dist/core/list.d.ts +9 -0
  153. package/dist/core/list.js +171 -0
  154. package/dist/core/parsers/change-parser.d.ts +13 -0
  155. package/dist/core/parsers/change-parser.js +193 -0
  156. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  157. package/dist/core/parsers/markdown-parser.js +187 -0
  158. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  159. package/dist/core/parsers/requirement-blocks.js +201 -0
  160. package/dist/core/project-config.d.ts +64 -0
  161. package/dist/core/project-config.js +223 -0
  162. package/dist/core/schemas/base.schema.d.ts +13 -0
  163. package/dist/core/schemas/base.schema.js +13 -0
  164. package/dist/core/schemas/change.schema.d.ts +73 -0
  165. package/dist/core/schemas/change.schema.js +31 -0
  166. package/dist/core/schemas/index.d.ts +4 -0
  167. package/dist/core/schemas/index.js +4 -0
  168. package/dist/core/schemas/spec.schema.d.ts +18 -0
  169. package/dist/core/schemas/spec.schema.js +15 -0
  170. package/dist/core/shared/index.d.ts +8 -0
  171. package/dist/core/shared/index.js +8 -0
  172. package/dist/core/shared/skill-generation.d.ts +41 -0
  173. package/dist/core/shared/skill-generation.js +74 -0
  174. package/dist/core/shared/tool-detection.d.ts +66 -0
  175. package/dist/core/shared/tool-detection.js +140 -0
  176. package/dist/core/specs-apply.d.ts +73 -0
  177. package/dist/core/specs-apply.js +384 -0
  178. package/dist/core/styles/palette.d.ts +7 -0
  179. package/dist/core/styles/palette.js +8 -0
  180. package/dist/core/templates/index.d.ts +8 -0
  181. package/dist/core/templates/index.js +9 -0
  182. package/dist/core/templates/skill-templates.d.ts +112 -0
  183. package/dist/core/templates/skill-templates.js +2893 -0
  184. package/dist/core/update.d.ts +42 -0
  185. package/dist/core/update.js +306 -0
  186. package/dist/core/validation/constants.d.ts +34 -0
  187. package/dist/core/validation/constants.js +40 -0
  188. package/dist/core/validation/types.d.ts +18 -0
  189. package/dist/core/validation/types.js +2 -0
  190. package/dist/core/validation/validator.d.ts +33 -0
  191. package/dist/core/validation/validator.js +409 -0
  192. package/dist/core/view.d.ts +8 -0
  193. package/dist/core/view.js +168 -0
  194. package/dist/index.d.ts +3 -0
  195. package/dist/index.js +3 -0
  196. package/dist/prompts/searchable-multi-select.d.ts +27 -0
  197. package/dist/prompts/searchable-multi-select.js +149 -0
  198. package/dist/telemetry/config.d.ts +32 -0
  199. package/dist/telemetry/config.js +68 -0
  200. package/dist/telemetry/index.d.ts +31 -0
  201. package/dist/telemetry/index.js +145 -0
  202. package/dist/ui/ascii-patterns.d.ts +16 -0
  203. package/dist/ui/ascii-patterns.js +133 -0
  204. package/dist/ui/welcome-screen.d.ts +10 -0
  205. package/dist/ui/welcome-screen.js +146 -0
  206. package/dist/utils/change-metadata.d.ts +51 -0
  207. package/dist/utils/change-metadata.js +147 -0
  208. package/dist/utils/change-utils.d.ts +62 -0
  209. package/dist/utils/change-utils.js +121 -0
  210. package/dist/utils/file-system.d.ts +36 -0
  211. package/dist/utils/file-system.js +281 -0
  212. package/dist/utils/index.d.ts +5 -0
  213. package/dist/utils/index.js +7 -0
  214. package/dist/utils/interactive.d.ts +18 -0
  215. package/dist/utils/interactive.js +21 -0
  216. package/dist/utils/item-discovery.d.ts +4 -0
  217. package/dist/utils/item-discovery.js +72 -0
  218. package/dist/utils/match.d.ts +3 -0
  219. package/dist/utils/match.js +22 -0
  220. package/dist/utils/shell-detection.d.ts +20 -0
  221. package/dist/utils/shell-detection.js +41 -0
  222. package/dist/utils/task-progress.d.ts +8 -0
  223. package/dist/utils/task-progress.js +36 -0
  224. package/package.json +84 -0
  225. package/schemas/spec-driven/schema.yaml +148 -0
  226. package/schemas/spec-driven/templates/design.md +19 -0
  227. package/schemas/spec-driven/templates/proposal.md +23 -0
  228. package/schemas/spec-driven/templates/spec.md +8 -0
  229. package/schemas/spec-driven/templates/tasks.md +9 -0
  230. package/schemas/tdd/schema.yaml +213 -0
  231. package/schemas/tdd/templates/docs.md +15 -0
  232. package/schemas/tdd/templates/implementation.md +11 -0
  233. package/schemas/tdd/templates/spec.md +11 -0
  234. package/schemas/tdd/templates/test.md +11 -0
  235. package/scripts/postinstall.js +147 -0
@@ -0,0 +1,327 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ import os from 'os';
4
+ /**
5
+ * Installer for PowerShell completion scripts.
6
+ * Works with both Windows PowerShell 5.1 and PowerShell Core 7+
7
+ */
8
+ export class PowerShellInstaller {
9
+ homeDir;
10
+ /**
11
+ * Markers for PowerShell profile configuration management
12
+ */
13
+ PROFILE_MARKERS = {
14
+ start: '# OPENSPEC:START',
15
+ end: '# OPENSPEC:END',
16
+ };
17
+ constructor(homeDir = os.homedir()) {
18
+ this.homeDir = homeDir;
19
+ }
20
+ /**
21
+ * Get PowerShell profile path
22
+ * Prefers $PROFILE environment variable, falls back to platform defaults
23
+ *
24
+ * @returns Profile path
25
+ */
26
+ getProfilePath() {
27
+ // Check $PROFILE environment variable (set when running in PowerShell)
28
+ if (process.env.PROFILE) {
29
+ return process.env.PROFILE;
30
+ }
31
+ // Fall back to platform-specific defaults
32
+ if (process.platform === 'win32') {
33
+ // Windows: Documents/PowerShell/Microsoft.PowerShell_profile.ps1
34
+ return path.join(this.homeDir, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1');
35
+ }
36
+ else {
37
+ // macOS/Linux: .config/powershell/Microsoft.PowerShell_profile.ps1
38
+ return path.join(this.homeDir, '.config', 'powershell', 'Microsoft.PowerShell_profile.ps1');
39
+ }
40
+ }
41
+ /**
42
+ * Get all PowerShell profile paths to configure.
43
+ * On Windows, returns both PowerShell Core and Windows PowerShell 5.1 paths.
44
+ * On Unix, returns PowerShell Core path only.
45
+ */
46
+ getAllProfilePaths() {
47
+ // If PROFILE env var is set, use only that path
48
+ if (process.env.PROFILE) {
49
+ return [process.env.PROFILE];
50
+ }
51
+ if (process.platform === 'win32') {
52
+ return [
53
+ // PowerShell Core 6+ (cross-platform)
54
+ path.join(this.homeDir, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1'),
55
+ // Windows PowerShell 5.1 (Windows-only)
56
+ path.join(this.homeDir, 'Documents', 'WindowsPowerShell', 'Microsoft.PowerShell_profile.ps1'),
57
+ ];
58
+ }
59
+ else {
60
+ // Unix systems: PowerShell Core only
61
+ return [path.join(this.homeDir, '.config', 'powershell', 'Microsoft.PowerShell_profile.ps1')];
62
+ }
63
+ }
64
+ /**
65
+ * Get the installation path for the completion script
66
+ *
67
+ * @returns Installation path
68
+ */
69
+ getInstallationPath() {
70
+ const profilePath = this.getProfilePath();
71
+ const profileDir = path.dirname(profilePath);
72
+ return path.join(profileDir, 'OpenSpecCompletion.ps1');
73
+ }
74
+ /**
75
+ * Backup an existing completion file if it exists
76
+ *
77
+ * @param targetPath - Path to the file to backup
78
+ * @returns Path to the backup file, or undefined if no backup was needed
79
+ */
80
+ async backupExistingFile(targetPath) {
81
+ try {
82
+ await fs.access(targetPath);
83
+ // File exists, create a backup
84
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
85
+ const backupPath = `${targetPath}.backup-${timestamp}`;
86
+ await fs.copyFile(targetPath, backupPath);
87
+ return backupPath;
88
+ }
89
+ catch {
90
+ // File doesn't exist, no backup needed
91
+ return undefined;
92
+ }
93
+ }
94
+ /**
95
+ * Generate PowerShell profile configuration content
96
+ *
97
+ * @param scriptPath - Path to the completion script
98
+ * @returns Configuration content
99
+ */
100
+ generateProfileConfig(scriptPath) {
101
+ return [
102
+ '# OpenSpec shell completions configuration',
103
+ `if (Test-Path "${scriptPath}") {`,
104
+ ` . "${scriptPath}"`,
105
+ '}',
106
+ ].join('\n');
107
+ }
108
+ /**
109
+ * Configure PowerShell profile to source the completion script
110
+ *
111
+ * @param scriptPath - Path to the completion script
112
+ * @returns true if configured successfully, false otherwise
113
+ */
114
+ async configureProfile(scriptPath) {
115
+ const profilePaths = this.getAllProfilePaths();
116
+ let anyConfigured = false;
117
+ for (const profilePath of profilePaths) {
118
+ try {
119
+ // Create profile file if it doesn't exist
120
+ const profileDir = path.dirname(profilePath);
121
+ await fs.mkdir(profileDir, { recursive: true });
122
+ let profileContent = '';
123
+ try {
124
+ profileContent = await fs.readFile(profilePath, 'utf-8');
125
+ }
126
+ catch {
127
+ // Profile doesn't exist yet, that's fine
128
+ }
129
+ // Check if already configured
130
+ const scriptLine = `. "${scriptPath}"`;
131
+ if (profileContent.includes(scriptLine)) {
132
+ continue; // Already configured, skip
133
+ }
134
+ // Add OpenSpec completion configuration with markers
135
+ const openspecBlock = [
136
+ '',
137
+ '# OPENSPEC:START - OpenSpec completion (managed block, do not edit manually)',
138
+ scriptLine,
139
+ '# OPENSPEC:END',
140
+ '',
141
+ ].join('\n');
142
+ const newContent = profileContent + openspecBlock;
143
+ await fs.writeFile(profilePath, newContent, 'utf-8');
144
+ anyConfigured = true;
145
+ }
146
+ catch (error) {
147
+ // Continue to next profile if this one fails
148
+ console.warn(`Warning: Could not configure ${profilePath}: ${error}`);
149
+ }
150
+ }
151
+ return anyConfigured;
152
+ }
153
+ /**
154
+ * Remove PowerShell profile configuration
155
+ * Used during uninstallation
156
+ *
157
+ * @returns true if removed successfully, false otherwise
158
+ */
159
+ async removeProfileConfig() {
160
+ const profilePaths = this.getAllProfilePaths();
161
+ let anyRemoved = false;
162
+ for (const profilePath of profilePaths) {
163
+ try {
164
+ // Read profile content
165
+ let profileContent;
166
+ try {
167
+ profileContent = await fs.readFile(profilePath, 'utf-8');
168
+ }
169
+ catch {
170
+ continue; // Profile doesn't exist, nothing to remove
171
+ }
172
+ // Remove OPENSPEC:START -> OPENSPEC:END block
173
+ const startMarker = '# OPENSPEC:START';
174
+ const endMarker = '# OPENSPEC:END';
175
+ const startIndex = profileContent.indexOf(startMarker);
176
+ if (startIndex === -1) {
177
+ continue; // No OpenSpec block found
178
+ }
179
+ const endIndex = profileContent.indexOf(endMarker, startIndex);
180
+ if (endIndex === -1) {
181
+ console.warn(`Warning: Found start marker but no end marker in ${profilePath}`);
182
+ continue;
183
+ }
184
+ // Remove the block (including markers and surrounding newlines)
185
+ const beforeBlock = profileContent.substring(0, startIndex);
186
+ const afterBlock = profileContent.substring(endIndex + endMarker.length);
187
+ // Clean up extra newlines
188
+ const newContent = (beforeBlock.trimEnd() + '\n' + afterBlock.trimStart()).trim() + '\n';
189
+ await fs.writeFile(profilePath, newContent, 'utf-8');
190
+ anyRemoved = true;
191
+ }
192
+ catch (error) {
193
+ console.warn(`Warning: Could not clean ${profilePath}: ${error}`);
194
+ }
195
+ }
196
+ return anyRemoved;
197
+ }
198
+ /**
199
+ * Install the completion script
200
+ *
201
+ * @param completionScript - The completion script content to install
202
+ * @returns Installation result with status and instructions
203
+ */
204
+ async install(completionScript) {
205
+ try {
206
+ const targetPath = this.getInstallationPath();
207
+ // Check if already installed with same content
208
+ let isUpdate = false;
209
+ try {
210
+ const existingContent = await fs.readFile(targetPath, 'utf-8');
211
+ if (existingContent === completionScript) {
212
+ // Already installed and up to date
213
+ return {
214
+ success: true,
215
+ installedPath: targetPath,
216
+ message: 'Completion script is already installed (up to date)',
217
+ instructions: [
218
+ 'The completion script is already installed and up to date.',
219
+ 'If completions are not working, try restarting PowerShell or run: . $PROFILE',
220
+ ],
221
+ };
222
+ }
223
+ // File exists but content is different - this is an update
224
+ isUpdate = true;
225
+ }
226
+ catch (error) {
227
+ // File doesn't exist or can't be read, proceed with installation
228
+ console.debug(`Unable to read existing completion file at ${targetPath}: ${error.message}`);
229
+ }
230
+ // Ensure the directory exists
231
+ const targetDir = path.dirname(targetPath);
232
+ await fs.mkdir(targetDir, { recursive: true });
233
+ // Backup existing file if updating
234
+ const backupPath = isUpdate ? await this.backupExistingFile(targetPath) : undefined;
235
+ // Write the completion script
236
+ await fs.writeFile(targetPath, completionScript, 'utf-8');
237
+ // Auto-configure PowerShell profile
238
+ const profileConfigured = await this.configureProfile(targetPath);
239
+ // Generate instructions if profile wasn't auto-configured
240
+ const instructions = profileConfigured ? undefined : this.generateInstructions(targetPath);
241
+ // Determine appropriate message
242
+ let message;
243
+ if (isUpdate) {
244
+ message = backupPath
245
+ ? 'Completion script updated successfully (previous version backed up)'
246
+ : 'Completion script updated successfully';
247
+ }
248
+ else {
249
+ message = profileConfigured
250
+ ? 'Completion script installed and PowerShell profile configured successfully'
251
+ : 'Completion script installed successfully for PowerShell';
252
+ }
253
+ return {
254
+ success: true,
255
+ installedPath: targetPath,
256
+ backupPath,
257
+ profileConfigured,
258
+ message,
259
+ instructions,
260
+ };
261
+ }
262
+ catch (error) {
263
+ return {
264
+ success: false,
265
+ message: `Failed to install completion script: ${error instanceof Error ? error.message : String(error)}`,
266
+ };
267
+ }
268
+ }
269
+ /**
270
+ * Generate user instructions for enabling completions
271
+ *
272
+ * @param installedPath - Path where the script was installed
273
+ * @returns Array of instruction strings
274
+ */
275
+ generateInstructions(installedPath) {
276
+ const profilePath = this.getProfilePath();
277
+ return [
278
+ 'Completion script installed successfully.',
279
+ '',
280
+ `To enable completions, add the following to your PowerShell profile (${profilePath}):`,
281
+ '',
282
+ ' # Source OpenSpec completions',
283
+ ` if (Test-Path "${installedPath}") {`,
284
+ ` . "${installedPath}"`,
285
+ ' }',
286
+ '',
287
+ 'Then restart PowerShell or run: . $PROFILE',
288
+ ];
289
+ }
290
+ /**
291
+ * Uninstall the completion script
292
+ *
293
+ * @param options - Optional uninstall options
294
+ * @param options.yes - Skip confirmation prompt (handled by command layer)
295
+ * @returns Uninstallation result
296
+ */
297
+ async uninstall(options) {
298
+ try {
299
+ const targetPath = this.getInstallationPath();
300
+ // Check if installed
301
+ try {
302
+ await fs.access(targetPath);
303
+ }
304
+ catch {
305
+ return {
306
+ success: false,
307
+ message: 'Completion script is not installed',
308
+ };
309
+ }
310
+ // Remove the completion script
311
+ await fs.unlink(targetPath);
312
+ // Remove profile configuration
313
+ await this.removeProfileConfig();
314
+ return {
315
+ success: true,
316
+ message: 'Completion script uninstalled successfully',
317
+ };
318
+ }
319
+ catch (error) {
320
+ return {
321
+ success: false,
322
+ message: `Failed to uninstall completion script: ${error instanceof Error ? error.message : String(error)}`,
323
+ };
324
+ }
325
+ }
326
+ }
327
+ //# sourceMappingURL=powershell-installer.js.map
@@ -0,0 +1,125 @@
1
+ import { InstallationResult } from '../factory.js';
2
+ /**
3
+ * Installer for Zsh completion scripts.
4
+ * Supports both Oh My Zsh and standard Zsh configurations.
5
+ */
6
+ export declare class ZshInstaller {
7
+ private readonly homeDir;
8
+ /**
9
+ * Markers for .zshrc configuration management
10
+ */
11
+ private readonly ZSHRC_MARKERS;
12
+ constructor(homeDir?: string);
13
+ /**
14
+ * Check if Oh My Zsh is installed
15
+ *
16
+ * @returns true if Oh My Zsh is detected via $ZSH env var or directory exists
17
+ */
18
+ isOhMyZshInstalled(): Promise<boolean>;
19
+ /**
20
+ * Get the appropriate installation path for the completion script
21
+ *
22
+ * @returns Object with installation path and whether it's Oh My Zsh
23
+ */
24
+ getInstallationPath(): Promise<{
25
+ path: string;
26
+ isOhMyZsh: boolean;
27
+ }>;
28
+ /**
29
+ * Backup an existing completion file if it exists
30
+ *
31
+ * @param targetPath - Path to the file to backup
32
+ * @returns Path to the backup file, or undefined if no backup was needed
33
+ */
34
+ backupExistingFile(targetPath: string): Promise<string | undefined>;
35
+ /**
36
+ * Get the path to .zshrc file
37
+ *
38
+ * @returns Path to .zshrc
39
+ */
40
+ private getZshrcPath;
41
+ /**
42
+ * Generate .zshrc configuration content
43
+ *
44
+ * @param completionsDir - Directory containing completion scripts
45
+ * @returns Configuration content
46
+ */
47
+ private generateZshrcConfig;
48
+ /**
49
+ * Configure .zshrc to enable completions
50
+ * Only applies to standard Zsh (not Oh My Zsh)
51
+ *
52
+ * @param completionsDir - Directory containing completion scripts
53
+ * @returns true if configured successfully, false otherwise
54
+ */
55
+ configureZshrc(completionsDir: string): Promise<boolean>;
56
+ /**
57
+ * Check if .zshrc has OpenSpec configuration markers
58
+ *
59
+ * @returns true if .zshrc exists and has markers
60
+ */
61
+ private hasZshrcConfig;
62
+ /**
63
+ * Check if fpath configuration is needed for a given directory
64
+ * Used to verify if Oh My Zsh (or other) completions directory is already in fpath
65
+ *
66
+ * @param completionsDir - Directory to check for in fpath
67
+ * @returns true if configuration is needed, false if directory is already referenced
68
+ */
69
+ private needsFpathConfig;
70
+ /**
71
+ * Remove .zshrc configuration
72
+ * Used during uninstallation
73
+ *
74
+ * @returns true if removed successfully, false otherwise
75
+ */
76
+ removeZshrcConfig(): Promise<boolean>;
77
+ /**
78
+ * Install the completion script
79
+ *
80
+ * @param completionScript - The completion script content to install
81
+ * @returns Installation result with status and instructions
82
+ */
83
+ install(completionScript: string): Promise<InstallationResult>;
84
+ /**
85
+ * Generate Oh My Zsh fpath verification guidance
86
+ *
87
+ * @param completionsDir - Custom completions directory path
88
+ * @returns Array of guidance strings, or undefined if not needed
89
+ */
90
+ private generateOhMyZshFpathGuidance;
91
+ /**
92
+ * Generate user instructions for enabling completions
93
+ *
94
+ * @param isOhMyZsh - Whether Oh My Zsh is being used
95
+ * @param installedPath - Path where the script was installed
96
+ * @returns Array of instruction strings
97
+ */
98
+ private generateInstructions;
99
+ /**
100
+ * Uninstall the completion script
101
+ *
102
+ * @returns true if uninstalled successfully, false otherwise
103
+ */
104
+ uninstall(): Promise<{
105
+ success: boolean;
106
+ message: string;
107
+ }>;
108
+ /**
109
+ * Check if completion script is currently installed
110
+ *
111
+ * @returns true if the completion script exists
112
+ */
113
+ isInstalled(): Promise<boolean>;
114
+ /**
115
+ * Get information about the current installation
116
+ *
117
+ * @returns Installation status information
118
+ */
119
+ getInstallationInfo(): Promise<{
120
+ installed: boolean;
121
+ path?: string;
122
+ isOhMyZsh?: boolean;
123
+ }>;
124
+ }
125
+ //# sourceMappingURL=zsh-installer.d.ts.map