anchorspec 1.3.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 (273) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +230 -0
  3. package/bin/anchorspec.js +3 -0
  4. package/bin/openspec.js +3 -0
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/cli/index.js +455 -0
  7. package/dist/commands/change.d.ts +35 -0
  8. package/dist/commands/change.js +277 -0
  9. package/dist/commands/completion.d.ts +72 -0
  10. package/dist/commands/completion.js +257 -0
  11. package/dist/commands/config.d.ts +36 -0
  12. package/dist/commands/config.js +552 -0
  13. package/dist/commands/feedback.d.ts +9 -0
  14. package/dist/commands/feedback.js +183 -0
  15. package/dist/commands/schema.d.ts +6 -0
  16. package/dist/commands/schema.js +869 -0
  17. package/dist/commands/show.d.ts +14 -0
  18. package/dist/commands/show.js +132 -0
  19. package/dist/commands/spec.d.ts +15 -0
  20. package/dist/commands/spec.js +225 -0
  21. package/dist/commands/validate.d.ts +24 -0
  22. package/dist/commands/validate.js +294 -0
  23. package/dist/commands/workflow/index.d.ts +17 -0
  24. package/dist/commands/workflow/index.js +12 -0
  25. package/dist/commands/workflow/instructions.d.ts +29 -0
  26. package/dist/commands/workflow/instructions.js +381 -0
  27. package/dist/commands/workflow/new-change.d.ts +11 -0
  28. package/dist/commands/workflow/new-change.js +44 -0
  29. package/dist/commands/workflow/schemas.d.ts +10 -0
  30. package/dist/commands/workflow/schemas.js +34 -0
  31. package/dist/commands/workflow/shared.d.ts +57 -0
  32. package/dist/commands/workflow/shared.js +116 -0
  33. package/dist/commands/workflow/status.d.ts +14 -0
  34. package/dist/commands/workflow/status.js +75 -0
  35. package/dist/commands/workflow/templates.d.ts +16 -0
  36. package/dist/commands/workflow/templates.js +68 -0
  37. package/dist/core/archive.d.ts +11 -0
  38. package/dist/core/archive.js +318 -0
  39. package/dist/core/artifact-graph/graph.d.ts +56 -0
  40. package/dist/core/artifact-graph/graph.js +141 -0
  41. package/dist/core/artifact-graph/index.d.ts +7 -0
  42. package/dist/core/artifact-graph/index.js +13 -0
  43. package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
  44. package/dist/core/artifact-graph/instruction-loader.js +214 -0
  45. package/dist/core/artifact-graph/resolver.d.ts +81 -0
  46. package/dist/core/artifact-graph/resolver.js +257 -0
  47. package/dist/core/artifact-graph/schema.d.ts +13 -0
  48. package/dist/core/artifact-graph/schema.js +108 -0
  49. package/dist/core/artifact-graph/state.d.ts +12 -0
  50. package/dist/core/artifact-graph/state.js +54 -0
  51. package/dist/core/artifact-graph/types.d.ts +45 -0
  52. package/dist/core/artifact-graph/types.js +43 -0
  53. package/dist/core/available-tools.d.ts +17 -0
  54. package/dist/core/available-tools.js +43 -0
  55. package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
  56. package/dist/core/command-generation/adapters/amazon-q.js +26 -0
  57. package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
  58. package/dist/core/command-generation/adapters/antigravity.js +26 -0
  59. package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
  60. package/dist/core/command-generation/adapters/auggie.js +27 -0
  61. package/dist/core/command-generation/adapters/bob.d.ts +14 -0
  62. package/dist/core/command-generation/adapters/bob.js +45 -0
  63. package/dist/core/command-generation/adapters/claude.d.ts +13 -0
  64. package/dist/core/command-generation/adapters/claude.js +50 -0
  65. package/dist/core/command-generation/adapters/cline.d.ts +14 -0
  66. package/dist/core/command-generation/adapters/cline.js +27 -0
  67. package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
  68. package/dist/core/command-generation/adapters/codebuddy.js +28 -0
  69. package/dist/core/command-generation/adapters/codex.d.ts +16 -0
  70. package/dist/core/command-generation/adapters/codex.js +39 -0
  71. package/dist/core/command-generation/adapters/continue.d.ts +13 -0
  72. package/dist/core/command-generation/adapters/continue.js +28 -0
  73. package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
  74. package/dist/core/command-generation/adapters/costrict.js +27 -0
  75. package/dist/core/command-generation/adapters/crush.d.ts +13 -0
  76. package/dist/core/command-generation/adapters/crush.js +30 -0
  77. package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
  78. package/dist/core/command-generation/adapters/cursor.js +44 -0
  79. package/dist/core/command-generation/adapters/factory.d.ts +13 -0
  80. package/dist/core/command-generation/adapters/factory.js +27 -0
  81. package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
  82. package/dist/core/command-generation/adapters/gemini.js +26 -0
  83. package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
  84. package/dist/core/command-generation/adapters/github-copilot.js +26 -0
  85. package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
  86. package/dist/core/command-generation/adapters/iflow.js +29 -0
  87. package/dist/core/command-generation/adapters/index.d.ts +32 -0
  88. package/dist/core/command-generation/adapters/index.js +32 -0
  89. package/dist/core/command-generation/adapters/junie.d.ts +13 -0
  90. package/dist/core/command-generation/adapters/junie.js +26 -0
  91. package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
  92. package/dist/core/command-generation/adapters/kilocode.js +23 -0
  93. package/dist/core/command-generation/adapters/kiro.d.ts +13 -0
  94. package/dist/core/command-generation/adapters/kiro.js +26 -0
  95. package/dist/core/command-generation/adapters/lingma.d.ts +13 -0
  96. package/dist/core/command-generation/adapters/lingma.js +30 -0
  97. package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
  98. package/dist/core/command-generation/adapters/opencode.js +29 -0
  99. package/dist/core/command-generation/adapters/pi.d.ts +18 -0
  100. package/dist/core/command-generation/adapters/pi.js +55 -0
  101. package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
  102. package/dist/core/command-generation/adapters/qoder.js +30 -0
  103. package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
  104. package/dist/core/command-generation/adapters/qwen.js +26 -0
  105. package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
  106. package/dist/core/command-generation/adapters/roocode.js +27 -0
  107. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  108. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  109. package/dist/core/command-generation/generator.d.ts +21 -0
  110. package/dist/core/command-generation/generator.js +27 -0
  111. package/dist/core/command-generation/index.d.ts +22 -0
  112. package/dist/core/command-generation/index.js +24 -0
  113. package/dist/core/command-generation/registry.d.ts +36 -0
  114. package/dist/core/command-generation/registry.js +98 -0
  115. package/dist/core/command-generation/types.d.ts +56 -0
  116. package/dist/core/command-generation/types.js +8 -0
  117. package/dist/core/completions/command-registry.d.ts +7 -0
  118. package/dist/core/completions/command-registry.js +461 -0
  119. package/dist/core/completions/completion-provider.d.ts +60 -0
  120. package/dist/core/completions/completion-provider.js +102 -0
  121. package/dist/core/completions/factory.d.ts +64 -0
  122. package/dist/core/completions/factory.js +75 -0
  123. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  124. package/dist/core/completions/generators/bash-generator.js +174 -0
  125. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  126. package/dist/core/completions/generators/fish-generator.js +157 -0
  127. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  128. package/dist/core/completions/generators/powershell-generator.js +207 -0
  129. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  130. package/dist/core/completions/generators/zsh-generator.js +250 -0
  131. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  132. package/dist/core/completions/installers/bash-installer.js +318 -0
  133. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  134. package/dist/core/completions/installers/fish-installer.js +143 -0
  135. package/dist/core/completions/installers/powershell-installer.d.ts +102 -0
  136. package/dist/core/completions/installers/powershell-installer.js +387 -0
  137. package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
  138. package/dist/core/completions/installers/zsh-installer.js +449 -0
  139. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  140. package/dist/core/completions/templates/bash-templates.js +24 -0
  141. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  142. package/dist/core/completions/templates/fish-templates.js +39 -0
  143. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  144. package/dist/core/completions/templates/powershell-templates.js +25 -0
  145. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  146. package/dist/core/completions/templates/zsh-templates.js +36 -0
  147. package/dist/core/completions/types.d.ts +79 -0
  148. package/dist/core/completions/types.js +2 -0
  149. package/dist/core/config-prompts.d.ts +9 -0
  150. package/dist/core/config-prompts.js +34 -0
  151. package/dist/core/config-schema.d.ts +86 -0
  152. package/dist/core/config-schema.js +213 -0
  153. package/dist/core/config.d.ts +18 -0
  154. package/dist/core/config.js +37 -0
  155. package/dist/core/converters/json-converter.d.ts +6 -0
  156. package/dist/core/converters/json-converter.js +51 -0
  157. package/dist/core/global-config.d.ts +44 -0
  158. package/dist/core/global-config.js +125 -0
  159. package/dist/core/index.d.ts +2 -0
  160. package/dist/core/index.js +3 -0
  161. package/dist/core/init.d.ts +37 -0
  162. package/dist/core/init.js +593 -0
  163. package/dist/core/legacy-cleanup.d.ts +162 -0
  164. package/dist/core/legacy-cleanup.js +514 -0
  165. package/dist/core/list.d.ts +9 -0
  166. package/dist/core/list.js +171 -0
  167. package/dist/core/migration.d.ts +23 -0
  168. package/dist/core/migration.js +108 -0
  169. package/dist/core/parsers/change-parser.d.ts +13 -0
  170. package/dist/core/parsers/change-parser.js +193 -0
  171. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  172. package/dist/core/parsers/markdown-parser.js +187 -0
  173. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  174. package/dist/core/parsers/requirement-blocks.js +201 -0
  175. package/dist/core/profile-sync-drift.d.ts +38 -0
  176. package/dist/core/profile-sync-drift.js +200 -0
  177. package/dist/core/profiles.d.ts +26 -0
  178. package/dist/core/profiles.js +40 -0
  179. package/dist/core/project-config.d.ts +64 -0
  180. package/dist/core/project-config.js +223 -0
  181. package/dist/core/schemas/base.schema.d.ts +13 -0
  182. package/dist/core/schemas/base.schema.js +13 -0
  183. package/dist/core/schemas/change.schema.d.ts +73 -0
  184. package/dist/core/schemas/change.schema.js +31 -0
  185. package/dist/core/schemas/index.d.ts +4 -0
  186. package/dist/core/schemas/index.js +4 -0
  187. package/dist/core/schemas/spec.schema.d.ts +18 -0
  188. package/dist/core/schemas/spec.schema.js +15 -0
  189. package/dist/core/shared/index.d.ts +8 -0
  190. package/dist/core/shared/index.js +8 -0
  191. package/dist/core/shared/skill-generation.d.ts +49 -0
  192. package/dist/core/shared/skill-generation.js +96 -0
  193. package/dist/core/shared/tool-detection.d.ts +71 -0
  194. package/dist/core/shared/tool-detection.js +158 -0
  195. package/dist/core/specs-apply.d.ts +73 -0
  196. package/dist/core/specs-apply.js +384 -0
  197. package/dist/core/styles/palette.d.ts +7 -0
  198. package/dist/core/styles/palette.js +8 -0
  199. package/dist/core/templates/index.d.ts +8 -0
  200. package/dist/core/templates/index.js +9 -0
  201. package/dist/core/templates/skill-templates.d.ts +19 -0
  202. package/dist/core/templates/skill-templates.js +18 -0
  203. package/dist/core/templates/types.d.ts +19 -0
  204. package/dist/core/templates/types.js +5 -0
  205. package/dist/core/templates/workflows/apply-change.d.ts +10 -0
  206. package/dist/core/templates/workflows/apply-change.js +308 -0
  207. package/dist/core/templates/workflows/archive-change.d.ts +10 -0
  208. package/dist/core/templates/workflows/archive-change.js +271 -0
  209. package/dist/core/templates/workflows/bulk-archive-change.d.ts +10 -0
  210. package/dist/core/templates/workflows/bulk-archive-change.js +488 -0
  211. package/dist/core/templates/workflows/continue-change.d.ts +10 -0
  212. package/dist/core/templates/workflows/continue-change.js +232 -0
  213. package/dist/core/templates/workflows/explore.d.ts +10 -0
  214. package/dist/core/templates/workflows/explore.js +461 -0
  215. package/dist/core/templates/workflows/feedback.d.ts +9 -0
  216. package/dist/core/templates/workflows/feedback.js +108 -0
  217. package/dist/core/templates/workflows/ff-change.d.ts +10 -0
  218. package/dist/core/templates/workflows/ff-change.js +198 -0
  219. package/dist/core/templates/workflows/new-change.d.ts +10 -0
  220. package/dist/core/templates/workflows/new-change.js +143 -0
  221. package/dist/core/templates/workflows/onboard.d.ts +10 -0
  222. package/dist/core/templates/workflows/onboard.js +565 -0
  223. package/dist/core/templates/workflows/propose.d.ts +10 -0
  224. package/dist/core/templates/workflows/propose.js +216 -0
  225. package/dist/core/templates/workflows/sync-specs.d.ts +10 -0
  226. package/dist/core/templates/workflows/sync-specs.js +272 -0
  227. package/dist/core/templates/workflows/verify-change.d.ts +10 -0
  228. package/dist/core/templates/workflows/verify-change.js +332 -0
  229. package/dist/core/update.d.ts +77 -0
  230. package/dist/core/update.js +537 -0
  231. package/dist/core/validation/constants.d.ts +34 -0
  232. package/dist/core/validation/constants.js +40 -0
  233. package/dist/core/validation/types.d.ts +18 -0
  234. package/dist/core/validation/types.js +2 -0
  235. package/dist/core/validation/validator.d.ts +33 -0
  236. package/dist/core/validation/validator.js +409 -0
  237. package/dist/core/view.d.ts +8 -0
  238. package/dist/core/view.js +168 -0
  239. package/dist/index.d.ts +3 -0
  240. package/dist/index.js +3 -0
  241. package/dist/prompts/searchable-multi-select.d.ts +28 -0
  242. package/dist/prompts/searchable-multi-select.js +159 -0
  243. package/dist/ui/ascii-patterns.d.ts +16 -0
  244. package/dist/ui/ascii-patterns.js +133 -0
  245. package/dist/ui/welcome-screen.d.ts +10 -0
  246. package/dist/ui/welcome-screen.js +146 -0
  247. package/dist/utils/change-metadata.d.ts +51 -0
  248. package/dist/utils/change-metadata.js +147 -0
  249. package/dist/utils/change-utils.d.ts +62 -0
  250. package/dist/utils/change-utils.js +121 -0
  251. package/dist/utils/command-references.d.ts +18 -0
  252. package/dist/utils/command-references.js +20 -0
  253. package/dist/utils/file-system.d.ts +36 -0
  254. package/dist/utils/file-system.js +281 -0
  255. package/dist/utils/index.d.ts +6 -0
  256. package/dist/utils/index.js +9 -0
  257. package/dist/utils/interactive.d.ts +18 -0
  258. package/dist/utils/interactive.js +21 -0
  259. package/dist/utils/item-discovery.d.ts +4 -0
  260. package/dist/utils/item-discovery.js +72 -0
  261. package/dist/utils/match.d.ts +3 -0
  262. package/dist/utils/match.js +22 -0
  263. package/dist/utils/shell-detection.d.ts +20 -0
  264. package/dist/utils/shell-detection.js +41 -0
  265. package/dist/utils/task-progress.d.ts +8 -0
  266. package/dist/utils/task-progress.js +36 -0
  267. package/package.json +78 -0
  268. package/schemas/spec-driven/schema.yaml +153 -0
  269. package/schemas/spec-driven/templates/design.md +19 -0
  270. package/schemas/spec-driven/templates/proposal.md +23 -0
  271. package/schemas/spec-driven/templates/spec.md +8 -0
  272. package/schemas/spec-driven/templates/tasks.md +9 -0
  273. package/scripts/postinstall.js +83 -0
@@ -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
@@ -0,0 +1,449 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ import os from 'os';
4
+ import { FileSystemUtils } from '../../../utils/file-system.js';
5
+ /**
6
+ * Installer for Zsh completion scripts.
7
+ * Supports both Oh My Zsh and standard Zsh configurations.
8
+ */
9
+ export class ZshInstaller {
10
+ homeDir;
11
+ /**
12
+ * Markers for .zshrc configuration management
13
+ */
14
+ ZSHRC_MARKERS = {
15
+ start: '# ANCHORSPEC:START',
16
+ end: '# ANCHORSPEC:END',
17
+ };
18
+ constructor(homeDir = os.homedir()) {
19
+ this.homeDir = homeDir;
20
+ }
21
+ /**
22
+ * Check if Oh My Zsh is installed
23
+ *
24
+ * @returns true if Oh My Zsh is detected via $ZSH env var or directory exists
25
+ */
26
+ async isOhMyZshInstalled() {
27
+ // First check for $ZSH environment variable (standard OMZ setup)
28
+ if (process.env.ZSH) {
29
+ return true;
30
+ }
31
+ // Fall back to checking for ~/.oh-my-zsh directory
32
+ const ohMyZshPath = path.join(this.homeDir, '.oh-my-zsh');
33
+ try {
34
+ const stat = await fs.stat(ohMyZshPath);
35
+ return stat.isDirectory();
36
+ }
37
+ catch {
38
+ return false;
39
+ }
40
+ }
41
+ /**
42
+ * Get the appropriate installation path for the completion script
43
+ *
44
+ * @returns Object with installation path and whether it's Oh My Zsh
45
+ */
46
+ async getInstallationPath() {
47
+ const isOhMyZsh = await this.isOhMyZshInstalled();
48
+ if (isOhMyZsh) {
49
+ // Oh My Zsh custom completions directory
50
+ return {
51
+ path: path.join(this.homeDir, '.oh-my-zsh', 'custom', 'completions', '_anchorspec'),
52
+ isOhMyZsh: true,
53
+ };
54
+ }
55
+ else {
56
+ // Standard Zsh completions directory
57
+ return {
58
+ path: path.join(this.homeDir, '.zsh', 'completions', '_anchorspec'),
59
+ isOhMyZsh: false,
60
+ };
61
+ }
62
+ }
63
+ /**
64
+ * Backup an existing completion file if it exists
65
+ *
66
+ * @param targetPath - Path to the file to backup
67
+ * @returns Path to the backup file, or undefined if no backup was needed
68
+ */
69
+ async backupExistingFile(targetPath) {
70
+ try {
71
+ await fs.access(targetPath);
72
+ // File exists, create a backup
73
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
74
+ const backupPath = `${targetPath}.backup-${timestamp}`;
75
+ await fs.copyFile(targetPath, backupPath);
76
+ return backupPath;
77
+ }
78
+ catch {
79
+ // File doesn't exist, no backup needed
80
+ return undefined;
81
+ }
82
+ }
83
+ /**
84
+ * Get the path to .zshrc file
85
+ *
86
+ * @returns Path to .zshrc
87
+ */
88
+ getZshrcPath() {
89
+ return path.join(this.homeDir, '.zshrc');
90
+ }
91
+ /**
92
+ * Generate .zshrc configuration content
93
+ *
94
+ * @param completionsDir - Directory containing completion scripts
95
+ * @returns Configuration content
96
+ */
97
+ generateZshrcConfig(completionsDir) {
98
+ return [
99
+ '# AnchorSpec shell completions configuration',
100
+ `fpath=("${completionsDir}" $fpath)`,
101
+ 'autoload -Uz compinit',
102
+ 'compinit',
103
+ ].join('\n');
104
+ }
105
+ /**
106
+ * Configure .zshrc to enable completions
107
+ * Only applies to standard Zsh (not Oh My Zsh)
108
+ *
109
+ * @param completionsDir - Directory containing completion scripts
110
+ * @returns true if configured successfully, false otherwise
111
+ */
112
+ async configureZshrc(completionsDir) {
113
+ // Check if auto-configuration is disabled
114
+ if (process.env.ANCHORSPEC_NO_AUTO_CONFIG === '1') {
115
+ return false;
116
+ }
117
+ try {
118
+ const zshrcPath = this.getZshrcPath();
119
+ const config = this.generateZshrcConfig(completionsDir);
120
+ // Check write permissions
121
+ const canWrite = await FileSystemUtils.canWriteFile(zshrcPath);
122
+ if (!canWrite) {
123
+ return false;
124
+ }
125
+ // Use marker-based update
126
+ await FileSystemUtils.updateFileWithMarkers(zshrcPath, config, this.ZSHRC_MARKERS.start, this.ZSHRC_MARKERS.end);
127
+ return true;
128
+ }
129
+ catch (error) {
130
+ // Fail gracefully - don't break installation
131
+ console.debug(`Unable to configure .zshrc for completions: ${error.message}`);
132
+ return false;
133
+ }
134
+ }
135
+ /**
136
+ * Check if .zshrc has AnchorSpec configuration markers
137
+ *
138
+ * @returns true if .zshrc exists and has markers
139
+ */
140
+ async hasZshrcConfig() {
141
+ try {
142
+ const zshrcPath = this.getZshrcPath();
143
+ const content = await fs.readFile(zshrcPath, 'utf-8');
144
+ return content.includes(this.ZSHRC_MARKERS.start) && content.includes(this.ZSHRC_MARKERS.end);
145
+ }
146
+ catch {
147
+ return false;
148
+ }
149
+ }
150
+ /**
151
+ * Check if fpath configuration is needed for a given directory
152
+ * Used to verify if Oh My Zsh (or other) completions directory is already in fpath
153
+ *
154
+ * @param completionsDir - Directory to check for in fpath
155
+ * @returns true if configuration is needed, false if directory is already referenced
156
+ */
157
+ async needsFpathConfig(completionsDir) {
158
+ try {
159
+ const zshrcPath = this.getZshrcPath();
160
+ const content = await fs.readFile(zshrcPath, 'utf-8');
161
+ // Check if fpath already includes this directory
162
+ return !content.includes(completionsDir);
163
+ }
164
+ catch (error) {
165
+ // If we can't read .zshrc, assume config is needed
166
+ console.debug(`Unable to read .zshrc to check fpath config: ${error instanceof Error ? error.message : String(error)}`);
167
+ return true;
168
+ }
169
+ }
170
+ /**
171
+ * Remove .zshrc configuration
172
+ * Used during uninstallation
173
+ *
174
+ * @returns true if removed successfully, false otherwise
175
+ */
176
+ async removeZshrcConfig() {
177
+ try {
178
+ const zshrcPath = this.getZshrcPath();
179
+ // Check if file exists
180
+ try {
181
+ await fs.access(zshrcPath);
182
+ }
183
+ catch {
184
+ // File doesn't exist, nothing to remove
185
+ return true;
186
+ }
187
+ // Read file content
188
+ const content = await fs.readFile(zshrcPath, 'utf-8');
189
+ // Check if markers exist
190
+ if (!content.includes(this.ZSHRC_MARKERS.start) || !content.includes(this.ZSHRC_MARKERS.end)) {
191
+ // Markers don't exist, nothing to remove
192
+ return true;
193
+ }
194
+ // Remove content between markers (including markers)
195
+ const lines = content.split('\n');
196
+ const startIndex = lines.findIndex((line) => line.trim() === this.ZSHRC_MARKERS.start);
197
+ const endIndex = lines.findIndex((line) => line.trim() === this.ZSHRC_MARKERS.end);
198
+ if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
199
+ // Invalid marker placement
200
+ return false;
201
+ }
202
+ // Remove lines between markers (inclusive)
203
+ lines.splice(startIndex, endIndex - startIndex + 1);
204
+ // Remove trailing empty lines at the start if the markers were at the top
205
+ while (lines.length > 0 && lines[0].trim() === '') {
206
+ lines.shift();
207
+ }
208
+ // Write back
209
+ await fs.writeFile(zshrcPath, lines.join('\n'), 'utf-8');
210
+ return true;
211
+ }
212
+ catch (error) {
213
+ // Fail gracefully
214
+ console.debug(`Unable to remove .zshrc configuration: ${error.message}`);
215
+ return false;
216
+ }
217
+ }
218
+ /**
219
+ * Install the completion script
220
+ *
221
+ * @param completionScript - The completion script content to install
222
+ * @returns Installation result with status and instructions
223
+ */
224
+ async install(completionScript) {
225
+ try {
226
+ const { path: targetPath, isOhMyZsh } = await this.getInstallationPath();
227
+ // Check if already installed with same content
228
+ let isUpdate = false;
229
+ try {
230
+ const existingContent = await fs.readFile(targetPath, 'utf-8');
231
+ if (existingContent === completionScript) {
232
+ // Already installed and up to date
233
+ return {
234
+ success: true,
235
+ installedPath: targetPath,
236
+ isOhMyZsh,
237
+ message: 'Completion script is already installed (up to date)',
238
+ instructions: [
239
+ 'The completion script is already installed and up to date.',
240
+ 'If completions are not working, try: exec zsh',
241
+ ],
242
+ };
243
+ }
244
+ // File exists but content is different - this is an update
245
+ isUpdate = true;
246
+ }
247
+ catch (error) {
248
+ // File doesn't exist or can't be read, proceed with installation
249
+ console.debug(`Unable to read existing completion file at ${targetPath}: ${error.message}`);
250
+ }
251
+ // Ensure the directory exists
252
+ const targetDir = path.dirname(targetPath);
253
+ await fs.mkdir(targetDir, { recursive: true });
254
+ // Backup existing file if updating
255
+ const backupPath = isUpdate ? await this.backupExistingFile(targetPath) : undefined;
256
+ // Write the completion script
257
+ await fs.writeFile(targetPath, completionScript, 'utf-8');
258
+ // Auto-configure .zshrc
259
+ let zshrcConfigured = false;
260
+ if (isOhMyZsh) {
261
+ // For Oh My Zsh, verify that custom/completions is in fpath
262
+ // If not, add it to .zshrc
263
+ const needsConfig = await this.needsFpathConfig(targetDir);
264
+ if (needsConfig) {
265
+ zshrcConfigured = await this.configureZshrc(targetDir);
266
+ }
267
+ }
268
+ else {
269
+ // Standard Zsh always needs .zshrc configuration
270
+ zshrcConfigured = await this.configureZshrc(targetDir);
271
+ }
272
+ // Generate instructions (only if .zshrc wasn't auto-configured)
273
+ let instructions = zshrcConfigured ? undefined : this.generateInstructions(isOhMyZsh, targetPath);
274
+ // Add fpath guidance for Oh My Zsh installations
275
+ if (isOhMyZsh) {
276
+ const fpathGuidance = this.generateOhMyZshFpathGuidance(targetDir);
277
+ if (fpathGuidance) {
278
+ instructions = instructions ? [...instructions, '', ...fpathGuidance] : fpathGuidance;
279
+ }
280
+ }
281
+ // Determine appropriate message based on update status
282
+ let message;
283
+ if (isUpdate) {
284
+ message = backupPath
285
+ ? 'Completion script updated successfully (previous version backed up)'
286
+ : 'Completion script updated successfully';
287
+ }
288
+ else {
289
+ message = isOhMyZsh
290
+ ? 'Completion script installed successfully for Oh My Zsh'
291
+ : zshrcConfigured
292
+ ? 'Completion script installed and .zshrc configured successfully'
293
+ : 'Completion script installed successfully for Zsh';
294
+ }
295
+ return {
296
+ success: true,
297
+ installedPath: targetPath,
298
+ backupPath,
299
+ isOhMyZsh,
300
+ zshrcConfigured,
301
+ message,
302
+ instructions,
303
+ };
304
+ }
305
+ catch (error) {
306
+ return {
307
+ success: false,
308
+ isOhMyZsh: false,
309
+ message: `Failed to install completion script: ${error instanceof Error ? error.message : String(error)}`,
310
+ };
311
+ }
312
+ }
313
+ /**
314
+ * Generate Oh My Zsh fpath verification guidance
315
+ *
316
+ * @param completionsDir - Custom completions directory path
317
+ * @returns Array of guidance strings, or undefined if not needed
318
+ */
319
+ generateOhMyZshFpathGuidance(completionsDir) {
320
+ return [
321
+ 'Note: Oh My Zsh typically auto-loads completions from custom/completions.',
322
+ `Verify that ${completionsDir} is in your fpath by running:`,
323
+ ' echo $fpath | grep "custom/completions"',
324
+ '',
325
+ 'If not found, completions may not work. Restart your shell to ensure changes take effect.',
326
+ ];
327
+ }
328
+ /**
329
+ * Generate user instructions for enabling completions
330
+ *
331
+ * @param isOhMyZsh - Whether Oh My Zsh is being used
332
+ * @param installedPath - Path where the script was installed
333
+ * @returns Array of instruction strings
334
+ */
335
+ generateInstructions(isOhMyZsh, installedPath) {
336
+ if (isOhMyZsh) {
337
+ return [
338
+ 'Completion script installed to Oh My Zsh completions directory.',
339
+ 'Restart your shell or run: exec zsh',
340
+ 'Completions should activate automatically.',
341
+ ];
342
+ }
343
+ else {
344
+ const completionsDir = path.dirname(installedPath);
345
+ const zshrcPath = path.join(this.homeDir, '.zshrc');
346
+ return [
347
+ 'Completion script installed to ~/.zsh/completions/',
348
+ '',
349
+ 'To enable completions, add the following to your ~/.zshrc file:',
350
+ '',
351
+ ` # Add completions directory to fpath`,
352
+ ` fpath=(${completionsDir} $fpath)`,
353
+ '',
354
+ ' # Initialize completion system',
355
+ ' autoload -Uz compinit',
356
+ ' compinit',
357
+ '',
358
+ 'Then restart your shell or run: exec zsh',
359
+ '',
360
+ `Check if these lines already exist in ${zshrcPath} before adding.`,
361
+ ];
362
+ }
363
+ }
364
+ /**
365
+ * Uninstall the completion script
366
+ *
367
+ * @returns true if uninstalled successfully, false otherwise
368
+ */
369
+ async uninstall() {
370
+ try {
371
+ const { path: targetPath, isOhMyZsh } = await this.getInstallationPath();
372
+ // Try to remove completion script
373
+ let scriptRemoved = false;
374
+ try {
375
+ await fs.access(targetPath);
376
+ await fs.unlink(targetPath);
377
+ scriptRemoved = true;
378
+ }
379
+ catch {
380
+ // Script not installed
381
+ }
382
+ // Try to remove .zshrc configuration (only for standard Zsh)
383
+ let zshrcWasPresent = false;
384
+ let zshrcCleaned = false;
385
+ if (!isOhMyZsh) {
386
+ zshrcWasPresent = await this.hasZshrcConfig();
387
+ if (zshrcWasPresent) {
388
+ zshrcCleaned = await this.removeZshrcConfig();
389
+ }
390
+ }
391
+ if (!scriptRemoved && !zshrcWasPresent) {
392
+ return {
393
+ success: false,
394
+ message: 'Completion script is not installed',
395
+ };
396
+ }
397
+ const messages = [];
398
+ if (scriptRemoved) {
399
+ messages.push(`Completion script removed from ${targetPath}`);
400
+ }
401
+ if (zshrcCleaned && !isOhMyZsh) {
402
+ messages.push('Removed AnchorSpec configuration from ~/.zshrc');
403
+ }
404
+ return {
405
+ success: true,
406
+ message: messages.join('. '),
407
+ };
408
+ }
409
+ catch (error) {
410
+ return {
411
+ success: false,
412
+ message: `Failed to uninstall completion script: ${error instanceof Error ? error.message : String(error)}`,
413
+ };
414
+ }
415
+ }
416
+ /**
417
+ * Check if completion script is currently installed
418
+ *
419
+ * @returns true if the completion script exists
420
+ */
421
+ async isInstalled() {
422
+ try {
423
+ const { path: targetPath } = await this.getInstallationPath();
424
+ await fs.access(targetPath);
425
+ return true;
426
+ }
427
+ catch {
428
+ return false;
429
+ }
430
+ }
431
+ /**
432
+ * Get information about the current installation
433
+ *
434
+ * @returns Installation status information
435
+ */
436
+ async getInstallationInfo() {
437
+ const installed = await this.isInstalled();
438
+ if (!installed) {
439
+ return { installed: false };
440
+ }
441
+ const { path: targetPath, isOhMyZsh } = await this.getInstallationPath();
442
+ return {
443
+ installed: true,
444
+ path: targetPath,
445
+ isOhMyZsh,
446
+ };
447
+ }
448
+ }
449
+ //# sourceMappingURL=zsh-installer.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Static template strings for Bash completion scripts.
3
+ * These are Bash-specific helper functions that never change.
4
+ */
5
+ export declare const BASH_DYNAMIC_HELPERS = "# Dynamic completion helpers\n\n_openspec_complete_changes() {\n local changes\n changes=$(openspec __complete changes 2>/dev/null | cut -f1)\n COMPREPLY=($(compgen -W \"$changes\" -- \"$cur\"))\n}\n\n_openspec_complete_specs() {\n local specs\n specs=$(openspec __complete specs 2>/dev/null | cut -f1)\n COMPREPLY=($(compgen -W \"$specs\" -- \"$cur\"))\n}\n\n_openspec_complete_items() {\n local items\n items=$(openspec __complete changes 2>/dev/null | cut -f1; openspec __complete specs 2>/dev/null | cut -f1)\n COMPREPLY=($(compgen -W \"$items\" -- \"$cur\"))\n}";
6
+ //# sourceMappingURL=bash-templates.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Static template strings for Bash completion scripts.
3
+ * These are Bash-specific helper functions that never change.
4
+ */
5
+ export const BASH_DYNAMIC_HELPERS = `# Dynamic completion helpers
6
+
7
+ _anchorspec_complete_changes() {
8
+ local changes
9
+ changes=$(anchorspec __complete changes 2>/dev/null | cut -f1)
10
+ COMPREPLY=($(compgen -W "$changes" -- "$cur"))
11
+ }
12
+
13
+ _anchorspec_complete_specs() {
14
+ local specs
15
+ specs=$(anchorspec __complete specs 2>/dev/null | cut -f1)
16
+ COMPREPLY=($(compgen -W "$specs" -- "$cur"))
17
+ }
18
+
19
+ _anchorspec_complete_items() {
20
+ local items
21
+ items=$(anchorspec __complete changes 2>/dev/null | cut -f1; anchorspec __complete specs 2>/dev/null | cut -f1)
22
+ COMPREPLY=($(compgen -W "$items" -- "$cur"))
23
+ }`;
24
+ //# sourceMappingURL=bash-templates.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Static template strings for Fish completion scripts.
3
+ * These are Fish-specific helper functions that never change.
4
+ */
5
+ export declare const FISH_STATIC_HELPERS = "# Helper function to check if a subcommand is present\nfunction __fish_openspec_using_subcommand\n set -l cmd (commandline -opc)\n set -e cmd[1]\n for i in $argv\n if contains -- $i $cmd\n return 0\n end\n end\n return 1\nend\n\nfunction __fish_openspec_no_subcommand\n set -l cmd (commandline -opc)\n test (count $cmd) -eq 1\nend";
6
+ export declare const FISH_DYNAMIC_HELPERS = "# Dynamic completion helpers\n\nfunction __fish_openspec_changes\n openspec __complete changes 2>/dev/null | while read -l id desc\n printf '%s\\t%s\\n' \"$id\" \"$desc\"\n end\nend\n\nfunction __fish_openspec_specs\n openspec __complete specs 2>/dev/null | while read -l id desc\n printf '%s\\t%s\\n' \"$id\" \"$desc\"\n end\nend\n\nfunction __fish_openspec_items\n __fish_openspec_changes\n __fish_openspec_specs\nend";
7
+ //# sourceMappingURL=fish-templates.d.ts.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Static template strings for Fish completion scripts.
3
+ * These are Fish-specific helper functions that never change.
4
+ */
5
+ export const FISH_STATIC_HELPERS = `# Helper function to check if a subcommand is present
6
+ function __fish_anchorspec_using_subcommand
7
+ set -l cmd (commandline -opc)
8
+ set -e cmd[1]
9
+ for i in $argv
10
+ if contains -- $i $cmd
11
+ return 0
12
+ end
13
+ end
14
+ return 1
15
+ end
16
+
17
+ function __fish_anchorspec_no_subcommand
18
+ set -l cmd (commandline -opc)
19
+ test (count $cmd) -eq 1
20
+ end`;
21
+ export const FISH_DYNAMIC_HELPERS = `# Dynamic completion helpers
22
+
23
+ function __fish_anchorspec_changes
24
+ anchorspec __complete changes 2>/dev/null | while read -l id desc
25
+ printf '%s\\t%s\\n' "$id" "$desc"
26
+ end
27
+ end
28
+
29
+ function __fish_anchorspec_specs
30
+ anchorspec __complete specs 2>/dev/null | while read -l id desc
31
+ printf '%s\\t%s\\n' "$id" "$desc"
32
+ end
33
+ end
34
+
35
+ function __fish_anchorspec_items
36
+ __fish_anchorspec_changes
37
+ __fish_anchorspec_specs
38
+ end`;
39
+ //# sourceMappingURL=fish-templates.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Static template strings for PowerShell completion scripts.
3
+ * These are PowerShell-specific helper functions that never change.
4
+ */
5
+ export declare const POWERSHELL_DYNAMIC_HELPERS = "# Dynamic completion helpers\n\nfunction Get-OpenSpecChanges {\n $output = openspec __complete changes 2>$null\n if ($output) {\n $output | ForEach-Object {\n ($_ -split \"\\t\")[0]\n }\n }\n}\n\nfunction Get-OpenSpecSpecs {\n $output = openspec __complete specs 2>$null\n if ($output) {\n $output | ForEach-Object {\n ($_ -split \"\\t\")[0]\n }\n }\n}\n";
6
+ //# sourceMappingURL=powershell-templates.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Static template strings for PowerShell completion scripts.
3
+ * These are PowerShell-specific helper functions that never change.
4
+ */
5
+ export const POWERSHELL_DYNAMIC_HELPERS = `# Dynamic completion helpers
6
+
7
+ function Get-AnchorSpecChanges {
8
+ $output = anchorspec __complete changes 2>$null
9
+ if ($output) {
10
+ $output | ForEach-Object {
11
+ ($_ -split "\\t")[0]
12
+ }
13
+ }
14
+ }
15
+
16
+ function Get-AnchorSpecSpecs {
17
+ $output = anchorspec __complete specs 2>$null
18
+ if ($output) {
19
+ $output | ForEach-Object {
20
+ ($_ -split "\\t")[0]
21
+ }
22
+ }
23
+ }
24
+ `;
25
+ //# sourceMappingURL=powershell-templates.js.map