synarcx 0.1.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 (288) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +90 -0
  3. package/bin/synarcx.js +3 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.js +474 -0
  6. package/dist/commands/change.d.ts +35 -0
  7. package/dist/commands/change.js +278 -0
  8. package/dist/commands/completion.d.ts +72 -0
  9. package/dist/commands/completion.js +264 -0
  10. package/dist/commands/config.d.ts +36 -0
  11. package/dist/commands/config.js +552 -0
  12. package/dist/commands/feedback.d.ts +9 -0
  13. package/dist/commands/feedback.js +170 -0
  14. package/dist/commands/schema.d.ts +6 -0
  15. package/dist/commands/schema.js +870 -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 +226 -0
  20. package/dist/commands/validate.d.ts +24 -0
  21. package/dist/commands/validate.js +295 -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 +327 -0
  26. package/dist/commands/workflow/new-change.d.ts +11 -0
  27. package/dist/commands/workflow/new-change.js +45 -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 +57 -0
  31. package/dist/commands/workflow/shared.js +117 -0
  32. package/dist/commands/workflow/status.d.ts +14 -0
  33. package/dist/commands/workflow/status.js +75 -0
  34. package/dist/commands/workflow/templates.d.ts +16 -0
  35. package/dist/commands/workflow/templates.js +69 -0
  36. package/dist/commands/workspace/open.d.ts +29 -0
  37. package/dist/commands/workspace/open.js +84 -0
  38. package/dist/commands/workspace/operations.d.ts +18 -0
  39. package/dist/commands/workspace/operations.js +461 -0
  40. package/dist/commands/workspace/selection.d.ts +5 -0
  41. package/dist/commands/workspace/selection.js +90 -0
  42. package/dist/commands/workspace/types.d.ts +83 -0
  43. package/dist/commands/workspace/types.js +36 -0
  44. package/dist/commands/workspace.d.ts +3 -0
  45. package/dist/commands/workspace.js +635 -0
  46. package/dist/core/archive.d.ts +11 -0
  47. package/dist/core/archive.js +319 -0
  48. package/dist/core/artifact-graph/graph.d.ts +56 -0
  49. package/dist/core/artifact-graph/graph.js +141 -0
  50. package/dist/core/artifact-graph/index.d.ts +8 -0
  51. package/dist/core/artifact-graph/index.js +14 -0
  52. package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
  53. package/dist/core/artifact-graph/instruction-loader.js +217 -0
  54. package/dist/core/artifact-graph/outputs.d.ts +14 -0
  55. package/dist/core/artifact-graph/outputs.js +39 -0
  56. package/dist/core/artifact-graph/resolver.d.ts +81 -0
  57. package/dist/core/artifact-graph/resolver.js +258 -0
  58. package/dist/core/artifact-graph/schema.d.ts +13 -0
  59. package/dist/core/artifact-graph/schema.js +108 -0
  60. package/dist/core/artifact-graph/state.d.ts +12 -0
  61. package/dist/core/artifact-graph/state.js +31 -0
  62. package/dist/core/artifact-graph/types.d.ts +45 -0
  63. package/dist/core/artifact-graph/types.js +43 -0
  64. package/dist/core/available-tools.d.ts +17 -0
  65. package/dist/core/available-tools.js +43 -0
  66. package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
  67. package/dist/core/command-generation/adapters/amazon-q.js +26 -0
  68. package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
  69. package/dist/core/command-generation/adapters/antigravity.js +26 -0
  70. package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
  71. package/dist/core/command-generation/adapters/auggie.js +27 -0
  72. package/dist/core/command-generation/adapters/bob.d.ts +14 -0
  73. package/dist/core/command-generation/adapters/bob.js +45 -0
  74. package/dist/core/command-generation/adapters/claude.d.ts +13 -0
  75. package/dist/core/command-generation/adapters/claude.js +50 -0
  76. package/dist/core/command-generation/adapters/cline.d.ts +14 -0
  77. package/dist/core/command-generation/adapters/cline.js +27 -0
  78. package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
  79. package/dist/core/command-generation/adapters/codebuddy.js +28 -0
  80. package/dist/core/command-generation/adapters/codex.d.ts +16 -0
  81. package/dist/core/command-generation/adapters/codex.js +39 -0
  82. package/dist/core/command-generation/adapters/continue.d.ts +13 -0
  83. package/dist/core/command-generation/adapters/continue.js +28 -0
  84. package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
  85. package/dist/core/command-generation/adapters/costrict.js +27 -0
  86. package/dist/core/command-generation/adapters/crush.d.ts +13 -0
  87. package/dist/core/command-generation/adapters/crush.js +30 -0
  88. package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
  89. package/dist/core/command-generation/adapters/cursor.js +44 -0
  90. package/dist/core/command-generation/adapters/factory.d.ts +13 -0
  91. package/dist/core/command-generation/adapters/factory.js +27 -0
  92. package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
  93. package/dist/core/command-generation/adapters/gemini.js +26 -0
  94. package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
  95. package/dist/core/command-generation/adapters/github-copilot.js +26 -0
  96. package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
  97. package/dist/core/command-generation/adapters/iflow.js +29 -0
  98. package/dist/core/command-generation/adapters/index.d.ts +32 -0
  99. package/dist/core/command-generation/adapters/index.js +32 -0
  100. package/dist/core/command-generation/adapters/junie.d.ts +13 -0
  101. package/dist/core/command-generation/adapters/junie.js +26 -0
  102. package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
  103. package/dist/core/command-generation/adapters/kilocode.js +23 -0
  104. package/dist/core/command-generation/adapters/kiro.d.ts +13 -0
  105. package/dist/core/command-generation/adapters/kiro.js +26 -0
  106. package/dist/core/command-generation/adapters/lingma.d.ts +13 -0
  107. package/dist/core/command-generation/adapters/lingma.js +30 -0
  108. package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
  109. package/dist/core/command-generation/adapters/opencode.js +27 -0
  110. package/dist/core/command-generation/adapters/pi.d.ts +18 -0
  111. package/dist/core/command-generation/adapters/pi.js +55 -0
  112. package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
  113. package/dist/core/command-generation/adapters/qoder.js +30 -0
  114. package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
  115. package/dist/core/command-generation/adapters/qwen.js +26 -0
  116. package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
  117. package/dist/core/command-generation/adapters/roocode.js +27 -0
  118. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  119. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  120. package/dist/core/command-generation/generator.d.ts +21 -0
  121. package/dist/core/command-generation/generator.js +27 -0
  122. package/dist/core/command-generation/index.d.ts +22 -0
  123. package/dist/core/command-generation/index.js +24 -0
  124. package/dist/core/command-generation/registry.d.ts +36 -0
  125. package/dist/core/command-generation/registry.js +98 -0
  126. package/dist/core/command-generation/types.d.ts +56 -0
  127. package/dist/core/command-generation/types.js +8 -0
  128. package/dist/core/completions/command-registry.d.ts +7 -0
  129. package/dist/core/completions/command-registry.js +596 -0
  130. package/dist/core/completions/completion-provider.d.ts +71 -0
  131. package/dist/core/completions/completion-provider.js +129 -0
  132. package/dist/core/completions/factory.d.ts +64 -0
  133. package/dist/core/completions/factory.js +75 -0
  134. package/dist/core/completions/generators/bash-generator.d.ts +35 -0
  135. package/dist/core/completions/generators/bash-generator.js +230 -0
  136. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  137. package/dist/core/completions/generators/fish-generator.js +160 -0
  138. package/dist/core/completions/generators/powershell-generator.d.ts +36 -0
  139. package/dist/core/completions/generators/powershell-generator.js +266 -0
  140. package/dist/core/completions/generators/zsh-generator.d.ts +47 -0
  141. package/dist/core/completions/generators/zsh-generator.js +274 -0
  142. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  143. package/dist/core/completions/installers/bash-installer.js +318 -0
  144. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  145. package/dist/core/completions/installers/fish-installer.js +143 -0
  146. package/dist/core/completions/installers/powershell-installer.d.ts +102 -0
  147. package/dist/core/completions/installers/powershell-installer.js +387 -0
  148. package/dist/core/completions/installers/zsh-installer.d.ts +117 -0
  149. package/dist/core/completions/installers/zsh-installer.js +421 -0
  150. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  151. package/dist/core/completions/templates/bash-templates.js +30 -0
  152. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  153. package/dist/core/completions/templates/fish-templates.js +45 -0
  154. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  155. package/dist/core/completions/templates/powershell-templates.js +34 -0
  156. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  157. package/dist/core/completions/templates/zsh-templates.js +45 -0
  158. package/dist/core/completions/types.d.ts +101 -0
  159. package/dist/core/completions/types.js +2 -0
  160. package/dist/core/config-prompts.d.ts +9 -0
  161. package/dist/core/config-prompts.js +34 -0
  162. package/dist/core/config-schema.d.ts +86 -0
  163. package/dist/core/config-schema.js +213 -0
  164. package/dist/core/config.d.ts +19 -0
  165. package/dist/core/config.js +38 -0
  166. package/dist/core/converters/json-converter.d.ts +6 -0
  167. package/dist/core/converters/json-converter.js +51 -0
  168. package/dist/core/global-config.d.ts +49 -0
  169. package/dist/core/global-config.js +124 -0
  170. package/dist/core/index.d.ts +3 -0
  171. package/dist/core/index.js +4 -0
  172. package/dist/core/init.d.ts +37 -0
  173. package/dist/core/init.js +585 -0
  174. package/dist/core/legacy-cleanup.d.ts +169 -0
  175. package/dist/core/legacy-cleanup.js +578 -0
  176. package/dist/core/list.d.ts +9 -0
  177. package/dist/core/list.js +172 -0
  178. package/dist/core/migration.d.ts +23 -0
  179. package/dist/core/migration.js +108 -0
  180. package/dist/core/parsers/change-parser.d.ts +13 -0
  181. package/dist/core/parsers/change-parser.js +197 -0
  182. package/dist/core/parsers/markdown-parser.d.ts +26 -0
  183. package/dist/core/parsers/markdown-parser.js +227 -0
  184. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  185. package/dist/core/parsers/requirement-blocks.js +201 -0
  186. package/dist/core/parsers/spec-structure.d.ts +9 -0
  187. package/dist/core/parsers/spec-structure.js +88 -0
  188. package/dist/core/profile-sync-drift.d.ts +38 -0
  189. package/dist/core/profile-sync-drift.js +197 -0
  190. package/dist/core/profiles.d.ts +26 -0
  191. package/dist/core/profiles.js +37 -0
  192. package/dist/core/project-config.d.ts +64 -0
  193. package/dist/core/project-config.js +224 -0
  194. package/dist/core/schemas/base.schema.d.ts +13 -0
  195. package/dist/core/schemas/base.schema.js +13 -0
  196. package/dist/core/schemas/change.schema.d.ts +73 -0
  197. package/dist/core/schemas/change.schema.js +31 -0
  198. package/dist/core/schemas/index.d.ts +4 -0
  199. package/dist/core/schemas/index.js +4 -0
  200. package/dist/core/schemas/spec.schema.d.ts +18 -0
  201. package/dist/core/schemas/spec.schema.js +15 -0
  202. package/dist/core/shared/index.d.ts +8 -0
  203. package/dist/core/shared/index.js +8 -0
  204. package/dist/core/shared/skill-generation.d.ts +49 -0
  205. package/dist/core/shared/skill-generation.js +90 -0
  206. package/dist/core/shared/tool-detection.d.ts +71 -0
  207. package/dist/core/shared/tool-detection.js +152 -0
  208. package/dist/core/specs-apply.d.ts +73 -0
  209. package/dist/core/specs-apply.js +393 -0
  210. package/dist/core/styles/palette.d.ts +7 -0
  211. package/dist/core/styles/palette.js +8 -0
  212. package/dist/core/templates/index.d.ts +8 -0
  213. package/dist/core/templates/index.js +9 -0
  214. package/dist/core/templates/skill-templates.d.ts +15 -0
  215. package/dist/core/templates/skill-templates.js +14 -0
  216. package/dist/core/templates/types.d.ts +19 -0
  217. package/dist/core/templates/types.js +5 -0
  218. package/dist/core/templates/workflows/analyze.d.ts +4 -0
  219. package/dist/core/templates/workflows/analyze.js +101 -0
  220. package/dist/core/templates/workflows/apply-change.d.ts +10 -0
  221. package/dist/core/templates/workflows/apply-change.js +308 -0
  222. package/dist/core/templates/workflows/archive-change.d.ts +10 -0
  223. package/dist/core/templates/workflows/archive-change.js +271 -0
  224. package/dist/core/templates/workflows/clarify.d.ts +4 -0
  225. package/dist/core/templates/workflows/clarify.js +108 -0
  226. package/dist/core/templates/workflows/debug.d.ts +4 -0
  227. package/dist/core/templates/workflows/debug.js +117 -0
  228. package/dist/core/templates/workflows/explore.d.ts +10 -0
  229. package/dist/core/templates/workflows/explore.js +479 -0
  230. package/dist/core/templates/workflows/propose.d.ts +10 -0
  231. package/dist/core/templates/workflows/propose.js +216 -0
  232. package/dist/core/templates/workflows/sync.d.ts +4 -0
  233. package/dist/core/templates/workflows/sync.js +108 -0
  234. package/dist/core/update.d.ts +82 -0
  235. package/dist/core/update.js +555 -0
  236. package/dist/core/validation/constants.d.ts +34 -0
  237. package/dist/core/validation/constants.js +40 -0
  238. package/dist/core/validation/types.d.ts +18 -0
  239. package/dist/core/validation/types.js +2 -0
  240. package/dist/core/validation/validator.d.ts +33 -0
  241. package/dist/core/validation/validator.js +418 -0
  242. package/dist/core/view.d.ts +8 -0
  243. package/dist/core/view.js +169 -0
  244. package/dist/core/workspace/foundation.d.ts +79 -0
  245. package/dist/core/workspace/foundation.js +367 -0
  246. package/dist/core/workspace/index.d.ts +5 -0
  247. package/dist/core/workspace/index.js +5 -0
  248. package/dist/core/workspace/link-input.d.ts +9 -0
  249. package/dist/core/workspace/link-input.js +32 -0
  250. package/dist/core/workspace/open-surface.d.ts +24 -0
  251. package/dist/core/workspace/open-surface.js +137 -0
  252. package/dist/core/workspace/openers.d.ts +21 -0
  253. package/dist/core/workspace/openers.js +119 -0
  254. package/dist/index.d.ts +3 -0
  255. package/dist/index.js +3 -0
  256. package/dist/prompts/searchable-multi-select.d.ts +28 -0
  257. package/dist/prompts/searchable-multi-select.js +159 -0
  258. package/dist/ui/ascii-patterns.d.ts +25 -0
  259. package/dist/ui/ascii-patterns.js +140 -0
  260. package/dist/ui/welcome-screen.d.ts +10 -0
  261. package/dist/ui/welcome-screen.js +144 -0
  262. package/dist/utils/change-metadata.d.ts +51 -0
  263. package/dist/utils/change-metadata.js +147 -0
  264. package/dist/utils/change-utils.d.ts +62 -0
  265. package/dist/utils/change-utils.js +122 -0
  266. package/dist/utils/command-references.d.ts +18 -0
  267. package/dist/utils/command-references.js +20 -0
  268. package/dist/utils/file-system.d.ts +41 -0
  269. package/dist/utils/file-system.js +301 -0
  270. package/dist/utils/index.d.ts +6 -0
  271. package/dist/utils/index.js +9 -0
  272. package/dist/utils/interactive.d.ts +18 -0
  273. package/dist/utils/interactive.js +21 -0
  274. package/dist/utils/item-discovery.d.ts +4 -0
  275. package/dist/utils/item-discovery.js +73 -0
  276. package/dist/utils/match.d.ts +3 -0
  277. package/dist/utils/match.js +22 -0
  278. package/dist/utils/shell-detection.d.ts +20 -0
  279. package/dist/utils/shell-detection.js +41 -0
  280. package/dist/utils/task-progress.d.ts +8 -0
  281. package/dist/utils/task-progress.js +36 -0
  282. package/package.json +76 -0
  283. package/schemas/synarcx/schema.yaml +153 -0
  284. package/schemas/synarcx/templates/design.md +19 -0
  285. package/schemas/synarcx/templates/proposal.md +23 -0
  286. package/schemas/synarcx/templates/spec.md +8 -0
  287. package/schemas/synarcx/templates/tasks.md +9 -0
  288. package/scripts/postinstall.js +83 -0
@@ -0,0 +1,585 @@
1
+ /**
2
+ * Init Command
3
+ *
4
+ * Sets up synarcx with Agent Skills and /syn:* slash commands.
5
+ * This is the unified setup command that replaces both the old init and experimental commands.
6
+ */
7
+ import path from 'path';
8
+ import chalk from 'chalk';
9
+ import ora from 'ora';
10
+ import * as fs from 'fs';
11
+ import { createRequire } from 'module';
12
+ import { FileSystemUtils } from '../utils/file-system.js';
13
+ import { transformToHyphenCommands } from '../utils/command-references.js';
14
+ import { AI_TOOLS, SYNSPEC_DIR_NAME, } from './config.js';
15
+ import { PALETTE } from './styles/palette.js';
16
+ import { isInteractive } from '../utils/interactive.js';
17
+ import { serializeConfig } from './config-prompts.js';
18
+ import { generateCommands, CommandAdapterRegistry, } from './command-generation/index.js';
19
+ import { detectLegacyArtifacts, cleanupLegacyArtifacts, formatCleanupSummary, formatDetectionSummary, } from './legacy-cleanup.js';
20
+ import { getToolsWithSkillsDir, getToolStates, getSkillTemplates, getCommandContents, generateSkillContent, } from './shared/index.js';
21
+ import { getGlobalConfig } from './global-config.js';
22
+ import { getProfileWorkflows, ALL_WORKFLOWS } from './profiles.js';
23
+ import { getAvailableTools } from './available-tools.js';
24
+ import { migrateIfNeeded } from './migration.js';
25
+ const require = createRequire(import.meta.url);
26
+ const { version: SYNC_VERSION } = require('../../package.json');
27
+ // -----------------------------------------------------------------------------
28
+ // Constants
29
+ // -----------------------------------------------------------------------------
30
+ const DEFAULT_SCHEMA = 'synarcx';
31
+ const PROGRESS_SPINNER = {
32
+ interval: 80,
33
+ frames: ['░░░', '▒░░', '▒▒░', '▒▒▒', '▓▒▒', '▓▓▒', '▓▓▓', '▒▓▓', '░▒▓'],
34
+ };
35
+ const WORKFLOW_TO_SKILL_DIR = {
36
+ 'explore': 'syn-explore',
37
+ 'apply': 'syn-apply',
38
+ 'archive': 'syn-archive',
39
+ 'propose': 'syn-propose',
40
+ 'sync': 'syn-sync',
41
+ 'clarify': 'syn-clarify',
42
+ 'analyze': 'syn-analyze',
43
+ 'debug': 'syn-debug',
44
+ };
45
+ // -----------------------------------------------------------------------------
46
+ // Init Command Class
47
+ // -----------------------------------------------------------------------------
48
+ export class InitCommand {
49
+ toolsArg;
50
+ force;
51
+ interactiveOption;
52
+ profileOverride;
53
+ constructor(options = {}) {
54
+ this.toolsArg = options.tools;
55
+ this.force = options.force ?? false;
56
+ this.interactiveOption = options.interactive;
57
+ this.profileOverride = options.profile;
58
+ }
59
+ async execute(targetPath) {
60
+ const projectPath = path.resolve(targetPath);
61
+ const openspecDir = SYNSPEC_DIR_NAME;
62
+ const openspecPath = path.join(projectPath, openspecDir);
63
+ // Validation happens silently in the background
64
+ const extendMode = await this.validate(projectPath, openspecPath);
65
+ // Check for legacy artifacts and handle cleanup
66
+ await this.handleLegacyCleanup(projectPath, extendMode);
67
+ // Detect available tools in the project (task 7.1)
68
+ const detectedTools = getAvailableTools(projectPath);
69
+ // Migration check: migrate existing projects to profile system (task 7.3)
70
+ if (extendMode) {
71
+ migrateIfNeeded(projectPath, detectedTools);
72
+ }
73
+ // Show animated welcome screen (interactive mode only)
74
+ const canPrompt = this.canPromptInteractively();
75
+ if (canPrompt) {
76
+ const { showWelcomeScreen } = await import('../ui/welcome-screen.js');
77
+ await showWelcomeScreen();
78
+ }
79
+ // Validate profile override early so invalid values fail before tool setup.
80
+ // The resolved value is consumed later when generation reads effective config.
81
+ this.resolveProfileOverride();
82
+ // Get tool states before processing
83
+ const toolStates = getToolStates(projectPath);
84
+ // Get tool selection (pass detected tools for pre-selection)
85
+ const selectedToolIds = await this.getSelectedTools(toolStates, extendMode, detectedTools, projectPath);
86
+ // Validate selected tools
87
+ const validatedTools = this.validateTools(selectedToolIds, toolStates);
88
+ // Create directory structure and config
89
+ await this.createDirectoryStructure(openspecPath, extendMode);
90
+ // Generate skills and commands for each tool
91
+ const results = await this.generateSkillsAndCommands(projectPath, validatedTools);
92
+ // Create config.yaml if needed
93
+ const configStatus = await this.createConfig(openspecPath, extendMode);
94
+ // Display success message
95
+ this.displaySuccessMessage(projectPath, validatedTools, results, configStatus);
96
+ }
97
+ // ═══════════════════════════════════════════════════════════
98
+ // VALIDATION & SETUP
99
+ // ═══════════════════════════════════════════════════════════
100
+ async validate(projectPath, openspecPath) {
101
+ const extendMode = await FileSystemUtils.directoryExists(openspecPath);
102
+ // Check write permissions
103
+ if (!(await FileSystemUtils.ensureWritePermissions(projectPath))) {
104
+ throw new Error(`Insufficient permissions to write to ${projectPath}`);
105
+ }
106
+ return extendMode;
107
+ }
108
+ canPromptInteractively() {
109
+ if (this.interactiveOption === false)
110
+ return false;
111
+ if (this.toolsArg !== undefined)
112
+ return false;
113
+ return isInteractive({ interactive: this.interactiveOption });
114
+ }
115
+ resolveProfileOverride() {
116
+ if (this.profileOverride === undefined) {
117
+ return undefined;
118
+ }
119
+ if (this.profileOverride === 'core' || this.profileOverride === 'custom') {
120
+ return this.profileOverride;
121
+ }
122
+ throw new Error(`Invalid profile "${this.profileOverride}". Available profiles: core, custom`);
123
+ }
124
+ // ═══════════════════════════════════════════════════════════
125
+ // LEGACY CLEANUP
126
+ // ═══════════════════════════════════════════════════════════
127
+ async handleLegacyCleanup(projectPath, extendMode) {
128
+ // Detect legacy artifacts
129
+ const detection = await detectLegacyArtifacts(projectPath);
130
+ if (!detection.hasLegacyArtifacts) {
131
+ return; // No legacy artifacts found
132
+ }
133
+ // Show what was detected
134
+ console.log();
135
+ console.log(formatDetectionSummary(detection));
136
+ console.log();
137
+ const canPrompt = this.canPromptInteractively();
138
+ if (this.force || !canPrompt) {
139
+ // --force flag or non-interactive mode: proceed with cleanup automatically.
140
+ // Legacy slash commands are 100% OpenSpec-managed, and config file cleanup
141
+ // only removes markers (never deletes files), so auto-cleanup is safe.
142
+ await this.performLegacyCleanup(projectPath, detection);
143
+ return;
144
+ }
145
+ // Interactive mode: prompt for confirmation
146
+ const { confirm } = await import('@inquirer/prompts');
147
+ const shouldCleanup = await confirm({
148
+ message: 'Upgrade and clean up legacy files?',
149
+ default: true,
150
+ });
151
+ if (!shouldCleanup) {
152
+ console.log(chalk.dim('Initialization cancelled.'));
153
+ console.log(chalk.dim('Run with --force to skip this prompt, or manually remove legacy files.'));
154
+ process.exit(0);
155
+ }
156
+ await this.performLegacyCleanup(projectPath, detection);
157
+ }
158
+ async performLegacyCleanup(projectPath, detection) {
159
+ const spinner = ora('Cleaning up legacy files...').start();
160
+ const result = await cleanupLegacyArtifacts(projectPath, detection);
161
+ spinner.succeed('Legacy files cleaned up');
162
+ const summary = formatCleanupSummary(result);
163
+ if (summary) {
164
+ console.log();
165
+ console.log(summary);
166
+ }
167
+ console.log();
168
+ }
169
+ // ═══════════════════════════════════════════════════════════
170
+ // TOOL SELECTION
171
+ // ═══════════════════════════════════════════════════════════
172
+ async getSelectedTools(toolStates, extendMode, detectedTools, projectPath) {
173
+ // Check for --tools flag first
174
+ const nonInteractiveSelection = this.resolveToolsArg();
175
+ if (nonInteractiveSelection !== null) {
176
+ return nonInteractiveSelection;
177
+ }
178
+ const validTools = getToolsWithSkillsDir();
179
+ const detectedToolIds = new Set(detectedTools.map((t) => t.value));
180
+ const configuredToolIds = new Set([...toolStates.entries()]
181
+ .filter(([, status]) => status.configured)
182
+ .map(([toolId]) => toolId));
183
+ const shouldPreselectDetected = !extendMode && configuredToolIds.size === 0;
184
+ const canPrompt = this.canPromptInteractively();
185
+ // Non-interactive mode: use detected tools as fallback (task 7.8)
186
+ if (!canPrompt) {
187
+ if (detectedToolIds.size > 0) {
188
+ return [...detectedToolIds];
189
+ }
190
+ throw new Error(`No tools detected and no --tools flag provided. Valid tools:\n ${validTools.join('\n ')}\n\nUse --tools all, --tools none, or --tools claude,cursor,...`);
191
+ }
192
+ if (validTools.length === 0) {
193
+ throw new Error(`No tools available for skill generation.`);
194
+ }
195
+ // Interactive mode: show searchable multi-select
196
+ const { searchableMultiSelect } = await import('../prompts/searchable-multi-select.js');
197
+ // Build choices: pre-select configured tools; keep detected tools visible but unselected.
198
+ const sortedChoices = validTools
199
+ .map((toolId) => {
200
+ const tool = AI_TOOLS.find((t) => t.value === toolId);
201
+ const status = toolStates.get(toolId);
202
+ const configured = status?.configured ?? false;
203
+ const detected = detectedToolIds.has(toolId);
204
+ return {
205
+ name: tool?.name || toolId,
206
+ value: toolId,
207
+ configured,
208
+ detected: detected && !configured,
209
+ preSelected: configured || (shouldPreselectDetected && detected && !configured),
210
+ };
211
+ })
212
+ .sort((a, b) => {
213
+ // Configured tools first, then detected (not configured), then everything else.
214
+ if (a.configured && !b.configured)
215
+ return -1;
216
+ if (!a.configured && b.configured)
217
+ return 1;
218
+ if (a.detected && !b.detected)
219
+ return -1;
220
+ if (!a.detected && b.detected)
221
+ return 1;
222
+ return 0;
223
+ });
224
+ const configuredNames = validTools
225
+ .filter((toolId) => configuredToolIds.has(toolId))
226
+ .map((toolId) => AI_TOOLS.find((t) => t.value === toolId)?.name || toolId);
227
+ if (configuredNames.length > 0) {
228
+ console.log(`synarcx configured: ${configuredNames.join(', ')} (pre-selected)`);
229
+ }
230
+ const detectedOnlyNames = detectedTools
231
+ .filter((tool) => !configuredToolIds.has(tool.value))
232
+ .map((tool) => tool.name);
233
+ if (detectedOnlyNames.length > 0) {
234
+ const detectionLabel = shouldPreselectDetected
235
+ ? 'pre-selected for first-time setup'
236
+ : 'not pre-selected';
237
+ console.log(`Detected tool directories: ${detectedOnlyNames.join(', ')} (${detectionLabel})`);
238
+ }
239
+ const selectedTools = await searchableMultiSelect({
240
+ message: `Select tools to set up (${validTools.length} available)`,
241
+ pageSize: 15,
242
+ choices: sortedChoices,
243
+ validate: (selected) => selected.length > 0 || 'Select at least one tool',
244
+ });
245
+ if (selectedTools.length === 0) {
246
+ throw new Error('At least one tool must be selected');
247
+ }
248
+ return selectedTools;
249
+ }
250
+ resolveToolsArg() {
251
+ if (typeof this.toolsArg === 'undefined') {
252
+ return null;
253
+ }
254
+ const raw = this.toolsArg.trim();
255
+ if (raw.length === 0) {
256
+ throw new Error('The --tools option requires a value. Use "all", "none", or a comma-separated list of tool IDs.');
257
+ }
258
+ const availableTools = getToolsWithSkillsDir();
259
+ const availableSet = new Set(availableTools);
260
+ const availableList = ['all', 'none', ...availableTools].join(', ');
261
+ const lowerRaw = raw.toLowerCase();
262
+ if (lowerRaw === 'all') {
263
+ return availableTools;
264
+ }
265
+ if (lowerRaw === 'none') {
266
+ return [];
267
+ }
268
+ const tokens = raw
269
+ .split(',')
270
+ .map((token) => token.trim())
271
+ .filter((token) => token.length > 0);
272
+ if (tokens.length === 0) {
273
+ throw new Error('The --tools option requires at least one tool ID when not using "all" or "none".');
274
+ }
275
+ const normalizedTokens = tokens.map((token) => token.toLowerCase());
276
+ if (normalizedTokens.some((token) => token === 'all' || token === 'none')) {
277
+ throw new Error('Cannot combine reserved values "all" or "none" with specific tool IDs.');
278
+ }
279
+ const invalidTokens = tokens.filter((_token, index) => !availableSet.has(normalizedTokens[index]));
280
+ if (invalidTokens.length > 0) {
281
+ throw new Error(`Invalid tool(s): ${invalidTokens.join(', ')}. Available values: ${availableList}`);
282
+ }
283
+ // Deduplicate while preserving order
284
+ const deduped = [];
285
+ for (const token of normalizedTokens) {
286
+ if (!deduped.includes(token)) {
287
+ deduped.push(token);
288
+ }
289
+ }
290
+ return deduped;
291
+ }
292
+ validateTools(toolIds, toolStates) {
293
+ const validatedTools = [];
294
+ for (const toolId of toolIds) {
295
+ const tool = AI_TOOLS.find((t) => t.value === toolId);
296
+ if (!tool) {
297
+ const validToolIds = getToolsWithSkillsDir();
298
+ throw new Error(`Unknown tool '${toolId}'. Valid tools:\n ${validToolIds.join('\n ')}`);
299
+ }
300
+ if (!tool.skillsDir) {
301
+ const validToolsWithSkills = getToolsWithSkillsDir();
302
+ throw new Error(`Tool '${toolId}' does not support skill generation.\nTools with skill generation support:\n ${validToolsWithSkills.join('\n ')}`);
303
+ }
304
+ const preState = toolStates.get(tool.value);
305
+ validatedTools.push({
306
+ value: tool.value,
307
+ name: tool.name,
308
+ skillsDir: tool.skillsDir,
309
+ wasConfigured: preState?.configured ?? false,
310
+ });
311
+ }
312
+ return validatedTools;
313
+ }
314
+ // ═══════════════════════════════════════════════════════════
315
+ // DIRECTORY STRUCTURE
316
+ // ═══════════════════════════════════════════════════════════
317
+ async createDirectoryStructure(openspecPath, extendMode) {
318
+ if (extendMode) {
319
+ // In extend mode, just ensure directories exist without spinner
320
+ const directories = [
321
+ openspecPath,
322
+ path.join(openspecPath, 'specs'),
323
+ path.join(openspecPath, 'changes'),
324
+ path.join(openspecPath, 'changes', 'archive'),
325
+ ];
326
+ for (const dir of directories) {
327
+ await FileSystemUtils.createDirectory(dir);
328
+ }
329
+ return;
330
+ }
331
+ const spinner = this.startSpinner('Creating synarcx structure...');
332
+ const directories = [
333
+ openspecPath,
334
+ path.join(openspecPath, 'specs'),
335
+ path.join(openspecPath, 'changes'),
336
+ path.join(openspecPath, 'changes', 'archive'),
337
+ ];
338
+ for (const dir of directories) {
339
+ await FileSystemUtils.createDirectory(dir);
340
+ }
341
+ spinner.stopAndPersist({
342
+ symbol: PALETTE.white('▌'),
343
+ text: PALETTE.white('synarcx structure created'),
344
+ });
345
+ }
346
+ // ═══════════════════════════════════════════════════════════
347
+ // SKILL & COMMAND GENERATION
348
+ // ═══════════════════════════════════════════════════════════
349
+ async generateSkillsAndCommands(projectPath, tools) {
350
+ const createdTools = [];
351
+ const refreshedTools = [];
352
+ const failedTools = [];
353
+ const commandsSkipped = [];
354
+ let removedCommandCount = 0;
355
+ let removedSkillCount = 0;
356
+ // Read global config for profile and delivery settings (use --profile override if set)
357
+ const globalConfig = getGlobalConfig();
358
+ const profile = this.resolveProfileOverride() ?? globalConfig.profile ?? 'core';
359
+ const delivery = globalConfig.delivery ?? 'both';
360
+ const workflows = getProfileWorkflows(profile, globalConfig.workflows);
361
+ // Get skill and command templates filtered by profile workflows
362
+ const shouldGenerateSkills = delivery !== 'commands';
363
+ const shouldGenerateCommands = delivery !== 'skills';
364
+ const skillTemplates = shouldGenerateSkills ? getSkillTemplates(workflows) : [];
365
+ const commandContents = shouldGenerateCommands ? getCommandContents(workflows) : [];
366
+ // Process each tool
367
+ for (const tool of tools) {
368
+ const spinner = ora(`Setting up ${tool.name}...`).start();
369
+ const toolConfig = AI_TOOLS.find(t => t.value === tool.value);
370
+ const hasCommands = toolConfig?.hasCommands ?? false;
371
+ const generateSkillsForTool = shouldGenerateSkills && !hasCommands;
372
+ try {
373
+ // Generate skill files if delivery includes skills and tool doesn't have slash commands
374
+ if (generateSkillsForTool) {
375
+ // Use tool-specific skillsDir
376
+ const skillsDir = path.join(projectPath, tool.skillsDir, 'skills');
377
+ // Create skill directories and SKILL.md files
378
+ for (const { template, dirName } of skillTemplates) {
379
+ const skillDir = path.join(skillsDir, dirName);
380
+ const skillFile = path.join(skillDir, 'SKILL.md');
381
+ // Generate SKILL.md content with YAML frontmatter including generatedBy
382
+ // Use hyphen-based command references for tools where filename = command name
383
+ const transformer = tool.value === 'pi' ? transformToHyphenCommands : undefined;
384
+ const skillContent = generateSkillContent(template, SYNC_VERSION, transformer);
385
+ // Write the skill file
386
+ await FileSystemUtils.writeFile(skillFile, skillContent);
387
+ }
388
+ }
389
+ if (!generateSkillsForTool) {
390
+ const skillsDir = path.join(projectPath, tool.skillsDir, 'skills');
391
+ removedSkillCount += await this.removeSkillDirs(skillsDir);
392
+ }
393
+ // Generate commands if delivery includes commands
394
+ if (shouldGenerateCommands) {
395
+ const adapter = CommandAdapterRegistry.get(tool.value);
396
+ if (adapter) {
397
+ const generatedCommands = generateCommands(commandContents, adapter);
398
+ for (const cmd of generatedCommands) {
399
+ const commandFile = path.isAbsolute(cmd.path) ? cmd.path : path.join(projectPath, cmd.path);
400
+ await FileSystemUtils.writeFile(commandFile, cmd.fileContent);
401
+ }
402
+ }
403
+ else {
404
+ commandsSkipped.push(tool.value);
405
+ }
406
+ }
407
+ if (!shouldGenerateCommands) {
408
+ removedCommandCount += await this.removeCommandFiles(projectPath, tool.value);
409
+ }
410
+ spinner.succeed(`Setup complete for ${tool.name}`);
411
+ if (tool.wasConfigured) {
412
+ refreshedTools.push(tool);
413
+ }
414
+ else {
415
+ createdTools.push(tool);
416
+ }
417
+ }
418
+ catch (error) {
419
+ spinner.fail(`Failed for ${tool.name}`);
420
+ failedTools.push({ name: tool.name, error: error });
421
+ }
422
+ }
423
+ return {
424
+ createdTools,
425
+ refreshedTools,
426
+ failedTools,
427
+ commandsSkipped,
428
+ removedCommandCount,
429
+ removedSkillCount,
430
+ };
431
+ }
432
+ // ═══════════════════════════════════════════════════════════
433
+ // CONFIG FILE
434
+ // ═══════════════════════════════════════════════════════════
435
+ async createConfig(openspecPath, extendMode) {
436
+ const configPath = path.join(openspecPath, 'config.yaml');
437
+ const configYmlPath = path.join(openspecPath, 'config.yml');
438
+ const configYamlExists = fs.existsSync(configPath);
439
+ const configYmlExists = fs.existsSync(configYmlPath);
440
+ if (configYamlExists || configYmlExists) {
441
+ return 'exists';
442
+ }
443
+ // In non-interactive mode without --force, skip config creation
444
+ if (!this.canPromptInteractively() && !this.force) {
445
+ return 'skipped';
446
+ }
447
+ try {
448
+ const yamlContent = serializeConfig({ schema: DEFAULT_SCHEMA });
449
+ await FileSystemUtils.writeFile(configPath, yamlContent);
450
+ return 'created';
451
+ }
452
+ catch {
453
+ return 'skipped';
454
+ }
455
+ }
456
+ // ═══════════════════════════════════════════════════════════
457
+ // UI & OUTPUT
458
+ // ═══════════════════════════════════════════════════════════
459
+ displaySuccessMessage(projectPath, tools, results, configStatus) {
460
+ console.log();
461
+ console.log(chalk.bold('synarcx Setup Complete'));
462
+ console.log();
463
+ // Show created vs refreshed tools
464
+ if (results.createdTools.length > 0) {
465
+ console.log(`Created: ${results.createdTools.map((t) => t.name).join(', ')}`);
466
+ }
467
+ if (results.refreshedTools.length > 0) {
468
+ console.log(`Refreshed: ${results.refreshedTools.map((t) => t.name).join(', ')}`);
469
+ }
470
+ // Show counts (respecting profile filter)
471
+ const successfulTools = [...results.createdTools, ...results.refreshedTools];
472
+ if (successfulTools.length > 0) {
473
+ const globalConfig = getGlobalConfig();
474
+ const profile = this.profileOverride ?? globalConfig.profile ?? 'core';
475
+ const delivery = globalConfig.delivery ?? 'both';
476
+ const workflows = getProfileWorkflows(profile, globalConfig.workflows);
477
+ const toolDirs = [...new Set(successfulTools.map((t) => t.skillsDir))].join(', ');
478
+ const skillCount = delivery !== 'commands' ? getSkillTemplates(workflows).length : 0;
479
+ const commandCount = delivery !== 'skills' ? getCommandContents(workflows).length : 0;
480
+ if (skillCount > 0 && commandCount > 0) {
481
+ console.log(`${skillCount} skills and ${commandCount} commands in ${toolDirs}/`);
482
+ }
483
+ else if (skillCount > 0) {
484
+ console.log(`${skillCount} skills in ${toolDirs}/`);
485
+ }
486
+ else if (commandCount > 0) {
487
+ console.log(`${commandCount} commands in ${toolDirs}/`);
488
+ }
489
+ }
490
+ // Show failures
491
+ if (results.failedTools.length > 0) {
492
+ console.log(chalk.red(`Failed: ${results.failedTools.map((f) => `${f.name} (${f.error.message})`).join(', ')}`));
493
+ }
494
+ // Show skipped commands
495
+ if (results.commandsSkipped.length > 0) {
496
+ console.log(chalk.dim(`Commands skipped for: ${results.commandsSkipped.join(', ')} (no adapter)`));
497
+ }
498
+ if (results.removedCommandCount > 0) {
499
+ console.log(chalk.dim(`Removed: ${results.removedCommandCount} command files (delivery: skills)`));
500
+ }
501
+ if (results.removedSkillCount > 0) {
502
+ console.log(chalk.dim(`Removed: ${results.removedSkillCount} skill directories (delivery: commands)`));
503
+ }
504
+ // Config status
505
+ if (configStatus === 'created') {
506
+ console.log(`Config: synspec/config.yaml (schema: ${DEFAULT_SCHEMA})`);
507
+ }
508
+ else if (configStatus === 'exists') {
509
+ // Show actual filename (config.yaml or config.yml)
510
+ const configYaml = path.join(projectPath, SYNSPEC_DIR_NAME, 'config.yaml');
511
+ const configYml = path.join(projectPath, SYNSPEC_DIR_NAME, 'config.yml');
512
+ const configName = fs.existsSync(configYaml) ? 'config.yaml' : fs.existsSync(configYml) ? 'config.yml' : 'config.yaml';
513
+ console.log(`Config: synspec/${configName} (exists)`);
514
+ }
515
+ else {
516
+ console.log(chalk.dim(`Config: skipped (non-interactive mode)`));
517
+ }
518
+ // Getting started (task 7.6: show propose if in profile)
519
+ const globalCfg = getGlobalConfig();
520
+ const activeProfile = this.profileOverride ?? globalCfg.profile ?? 'core';
521
+ const activeWorkflows = [...getProfileWorkflows(activeProfile, globalCfg.workflows)];
522
+ console.log();
523
+ if (activeWorkflows.includes('propose')) {
524
+ console.log(chalk.bold('Getting started:'));
525
+ console.log(' Start your first change: /syn:propose "your idea"');
526
+ }
527
+ else {
528
+ console.log("Done. Run 'synarcx config profile' to configure your workflows.");
529
+ }
530
+ // Restart instruction if any tools were configured
531
+ if (results.createdTools.length > 0 || results.refreshedTools.length > 0) {
532
+ console.log();
533
+ console.log(chalk.white('Restart your IDE for slash commands to take effect.'));
534
+ }
535
+ console.log();
536
+ }
537
+ startSpinner(text) {
538
+ return ora({
539
+ text,
540
+ stream: process.stdout,
541
+ color: 'gray',
542
+ spinner: PROGRESS_SPINNER,
543
+ }).start();
544
+ }
545
+ async removeSkillDirs(skillsDir) {
546
+ let removed = 0;
547
+ for (const workflow of ALL_WORKFLOWS) {
548
+ const dirName = WORKFLOW_TO_SKILL_DIR[workflow];
549
+ if (!dirName)
550
+ continue;
551
+ const skillDir = path.join(skillsDir, dirName);
552
+ try {
553
+ if (fs.existsSync(skillDir)) {
554
+ await fs.promises.rm(skillDir, { recursive: true, force: true });
555
+ removed++;
556
+ }
557
+ }
558
+ catch {
559
+ // Ignore errors
560
+ }
561
+ }
562
+ return removed;
563
+ }
564
+ async removeCommandFiles(projectPath, toolId) {
565
+ let removed = 0;
566
+ const adapter = CommandAdapterRegistry.get(toolId);
567
+ if (!adapter)
568
+ return 0;
569
+ for (const workflow of ALL_WORKFLOWS) {
570
+ const cmdPath = adapter.getFilePath(workflow);
571
+ const fullPath = path.isAbsolute(cmdPath) ? cmdPath : path.join(projectPath, cmdPath);
572
+ try {
573
+ if (fs.existsSync(fullPath)) {
574
+ await fs.promises.unlink(fullPath);
575
+ removed++;
576
+ }
577
+ }
578
+ catch {
579
+ // Ignore errors
580
+ }
581
+ }
582
+ return removed;
583
+ }
584
+ }
585
+ //# sourceMappingURL=init.js.map