@ias-ai/zhima-spec 1.3.1

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 (307) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +206 -0
  3. package/bin/zhima.js +3 -0
  4. package/dist/cli/index.d.ts +2 -0
  5. package/dist/cli/index.js +462 -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 +264 -0
  10. package/dist/commands/config.d.ts +36 -0
  11. package/dist/commands/config.js +611 -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 +336 -0
  26. package/dist/commands/workflow/new-change.d.ts +13 -0
  27. package/dist/commands/workflow/new-change.js +92 -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 +116 -0
  32. package/dist/commands/workflow/status.d.ts +14 -0
  33. package/dist/commands/workflow/status.js +87 -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 +23 -0
  39. package/dist/commands/workspace/operations.js +475 -0
  40. package/dist/commands/workspace/selection.d.ts +6 -0
  41. package/dist/commands/workspace/selection.js +113 -0
  42. package/dist/commands/workspace/types.d.ts +88 -0
  43. package/dist/commands/workspace/types.js +36 -0
  44. package/dist/commands/workspace.d.ts +6 -0
  45. package/dist/commands/workspace.js +868 -0
  46. package/dist/core/archive.d.ts +11 -0
  47. package/dist/core/archive.js +318 -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 +196 -0
  53. package/dist/core/artifact-graph/instruction-loader.js +317 -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 +257 -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 +47 -0
  63. package/dist/core/artifact-graph/types.js +48 -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 +33 -0
  99. package/dist/core/command-generation/adapters/index.js +33 -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 +29 -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/vjsp.d.ts +13 -0
  119. package/dist/core/command-generation/adapters/vjsp.js +27 -0
  120. package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
  121. package/dist/core/command-generation/adapters/windsurf.js +51 -0
  122. package/dist/core/command-generation/generator.d.ts +21 -0
  123. package/dist/core/command-generation/generator.js +27 -0
  124. package/dist/core/command-generation/index.d.ts +22 -0
  125. package/dist/core/command-generation/index.js +24 -0
  126. package/dist/core/command-generation/registry.d.ts +36 -0
  127. package/dist/core/command-generation/registry.js +98 -0
  128. package/dist/core/command-generation/types.d.ts +56 -0
  129. package/dist/core/command-generation/types.js +8 -0
  130. package/dist/core/completions/command-registry.d.ts +7 -0
  131. package/dist/core/completions/command-registry.js +626 -0
  132. package/dist/core/completions/completion-provider.d.ts +71 -0
  133. package/dist/core/completions/completion-provider.js +129 -0
  134. package/dist/core/completions/factory.d.ts +64 -0
  135. package/dist/core/completions/factory.js +75 -0
  136. package/dist/core/completions/generators/bash-generator.d.ts +35 -0
  137. package/dist/core/completions/generators/bash-generator.js +230 -0
  138. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  139. package/dist/core/completions/generators/fish-generator.js +160 -0
  140. package/dist/core/completions/generators/powershell-generator.d.ts +36 -0
  141. package/dist/core/completions/generators/powershell-generator.js +266 -0
  142. package/dist/core/completions/generators/zsh-generator.d.ts +47 -0
  143. package/dist/core/completions/generators/zsh-generator.js +274 -0
  144. package/dist/core/completions/installers/bash-installer.d.ts +87 -0
  145. package/dist/core/completions/installers/bash-installer.js +318 -0
  146. package/dist/core/completions/installers/fish-installer.d.ts +43 -0
  147. package/dist/core/completions/installers/fish-installer.js +143 -0
  148. package/dist/core/completions/installers/powershell-installer.d.ts +102 -0
  149. package/dist/core/completions/installers/powershell-installer.js +387 -0
  150. package/dist/core/completions/installers/zsh-installer.d.ts +117 -0
  151. package/dist/core/completions/installers/zsh-installer.js +421 -0
  152. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  153. package/dist/core/completions/templates/bash-templates.js +30 -0
  154. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  155. package/dist/core/completions/templates/fish-templates.js +45 -0
  156. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  157. package/dist/core/completions/templates/powershell-templates.js +34 -0
  158. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  159. package/dist/core/completions/templates/zsh-templates.js +45 -0
  160. package/dist/core/completions/types.d.ts +101 -0
  161. package/dist/core/completions/types.js +2 -0
  162. package/dist/core/config-prompts.d.ts +9 -0
  163. package/dist/core/config-prompts.js +34 -0
  164. package/dist/core/config-schema.d.ts +86 -0
  165. package/dist/core/config-schema.js +213 -0
  166. package/dist/core/config.d.ts +18 -0
  167. package/dist/core/config.js +39 -0
  168. package/dist/core/converters/json-converter.d.ts +6 -0
  169. package/dist/core/converters/json-converter.js +51 -0
  170. package/dist/core/global-config.d.ts +49 -0
  171. package/dist/core/global-config.js +124 -0
  172. package/dist/core/index.d.ts +4 -0
  173. package/dist/core/index.js +5 -0
  174. package/dist/core/init.d.ts +37 -0
  175. package/dist/core/init.js +593 -0
  176. package/dist/core/legacy-cleanup.d.ts +162 -0
  177. package/dist/core/legacy-cleanup.js +514 -0
  178. package/dist/core/list.d.ts +9 -0
  179. package/dist/core/list.js +171 -0
  180. package/dist/core/migration.d.ts +23 -0
  181. package/dist/core/migration.js +108 -0
  182. package/dist/core/parsers/change-parser.d.ts +13 -0
  183. package/dist/core/parsers/change-parser.js +197 -0
  184. package/dist/core/parsers/markdown-parser.d.ts +26 -0
  185. package/dist/core/parsers/markdown-parser.js +227 -0
  186. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  187. package/dist/core/parsers/requirement-blocks.js +201 -0
  188. package/dist/core/parsers/spec-structure.d.ts +9 -0
  189. package/dist/core/parsers/spec-structure.js +88 -0
  190. package/dist/core/planning-home.d.ts +21 -0
  191. package/dist/core/planning-home.js +124 -0
  192. package/dist/core/profile-sync-drift.d.ts +38 -0
  193. package/dist/core/profile-sync-drift.js +200 -0
  194. package/dist/core/profiles.d.ts +26 -0
  195. package/dist/core/profiles.js +40 -0
  196. package/dist/core/project-config.d.ts +64 -0
  197. package/dist/core/project-config.js +223 -0
  198. package/dist/core/schemas/base.schema.d.ts +13 -0
  199. package/dist/core/schemas/base.schema.js +13 -0
  200. package/dist/core/schemas/change.schema.d.ts +73 -0
  201. package/dist/core/schemas/change.schema.js +31 -0
  202. package/dist/core/schemas/index.d.ts +4 -0
  203. package/dist/core/schemas/index.js +4 -0
  204. package/dist/core/schemas/spec.schema.d.ts +18 -0
  205. package/dist/core/schemas/spec.schema.js +15 -0
  206. package/dist/core/shared/index.d.ts +8 -0
  207. package/dist/core/shared/index.js +8 -0
  208. package/dist/core/shared/skill-generation.d.ts +49 -0
  209. package/dist/core/shared/skill-generation.js +96 -0
  210. package/dist/core/shared/tool-detection.d.ts +71 -0
  211. package/dist/core/shared/tool-detection.js +158 -0
  212. package/dist/core/specs-apply.d.ts +73 -0
  213. package/dist/core/specs-apply.js +392 -0
  214. package/dist/core/styles/palette.d.ts +7 -0
  215. package/dist/core/styles/palette.js +8 -0
  216. package/dist/core/templates/index.d.ts +8 -0
  217. package/dist/core/templates/index.js +9 -0
  218. package/dist/core/templates/skill-templates.d.ts +19 -0
  219. package/dist/core/templates/skill-templates.js +18 -0
  220. package/dist/core/templates/types.d.ts +19 -0
  221. package/dist/core/templates/types.js +5 -0
  222. package/dist/core/templates/workflows/apply-change.d.ts +10 -0
  223. package/dist/core/templates/workflows/apply-change.js +314 -0
  224. package/dist/core/templates/workflows/archive-change.d.ts +10 -0
  225. package/dist/core/templates/workflows/archive-change.js +277 -0
  226. package/dist/core/templates/workflows/bulk-archive-change.d.ts +10 -0
  227. package/dist/core/templates/workflows/bulk-archive-change.js +492 -0
  228. package/dist/core/templates/workflows/continue-change.d.ts +10 -0
  229. package/dist/core/templates/workflows/continue-change.js +234 -0
  230. package/dist/core/templates/workflows/explore.d.ts +10 -0
  231. package/dist/core/templates/workflows/explore.js +459 -0
  232. package/dist/core/templates/workflows/feedback.d.ts +9 -0
  233. package/dist/core/templates/workflows/feedback.js +108 -0
  234. package/dist/core/templates/workflows/ff-change.d.ts +10 -0
  235. package/dist/core/templates/workflows/ff-change.js +200 -0
  236. package/dist/core/templates/workflows/new-change.d.ts +10 -0
  237. package/dist/core/templates/workflows/new-change.js +143 -0
  238. package/dist/core/templates/workflows/onboard.d.ts +10 -0
  239. package/dist/core/templates/workflows/onboard.js +563 -0
  240. package/dist/core/templates/workflows/propose.d.ts +10 -0
  241. package/dist/core/templates/workflows/propose.js +218 -0
  242. package/dist/core/templates/workflows/sync-specs.d.ts +10 -0
  243. package/dist/core/templates/workflows/sync-specs.js +290 -0
  244. package/dist/core/templates/workflows/verify-change.d.ts +10 -0
  245. package/dist/core/templates/workflows/verify-change.js +338 -0
  246. package/dist/core/update.d.ts +82 -0
  247. package/dist/core/update.js +557 -0
  248. package/dist/core/validation/constants.d.ts +34 -0
  249. package/dist/core/validation/constants.js +40 -0
  250. package/dist/core/validation/types.d.ts +18 -0
  251. package/dist/core/validation/types.js +2 -0
  252. package/dist/core/validation/validator.d.ts +33 -0
  253. package/dist/core/validation/validator.js +418 -0
  254. package/dist/core/view.d.ts +8 -0
  255. package/dist/core/view.js +168 -0
  256. package/dist/core/workspace/foundation.d.ts +87 -0
  257. package/dist/core/workspace/foundation.js +379 -0
  258. package/dist/core/workspace/index.d.ts +6 -0
  259. package/dist/core/workspace/index.js +6 -0
  260. package/dist/core/workspace/link-input.d.ts +9 -0
  261. package/dist/core/workspace/link-input.js +32 -0
  262. package/dist/core/workspace/open-surface.d.ts +24 -0
  263. package/dist/core/workspace/open-surface.js +137 -0
  264. package/dist/core/workspace/openers.d.ts +21 -0
  265. package/dist/core/workspace/openers.js +119 -0
  266. package/dist/core/workspace/skills.d.ts +55 -0
  267. package/dist/core/workspace/skills.js +334 -0
  268. package/dist/index.d.ts +3 -0
  269. package/dist/index.js +3 -0
  270. package/dist/prompts/searchable-multi-select.d.ts +28 -0
  271. package/dist/prompts/searchable-multi-select.js +159 -0
  272. package/dist/ui/ascii-patterns.d.ts +16 -0
  273. package/dist/ui/ascii-patterns.js +133 -0
  274. package/dist/ui/welcome-screen.d.ts +10 -0
  275. package/dist/ui/welcome-screen.js +146 -0
  276. package/dist/utils/change-metadata.d.ts +51 -0
  277. package/dist/utils/change-metadata.js +147 -0
  278. package/dist/utils/change-utils.d.ts +71 -0
  279. package/dist/utils/change-utils.js +123 -0
  280. package/dist/utils/command-references.d.ts +18 -0
  281. package/dist/utils/command-references.js +20 -0
  282. package/dist/utils/file-system.d.ts +41 -0
  283. package/dist/utils/file-system.js +301 -0
  284. package/dist/utils/index.d.ts +6 -0
  285. package/dist/utils/index.js +9 -0
  286. package/dist/utils/interactive.d.ts +18 -0
  287. package/dist/utils/interactive.js +21 -0
  288. package/dist/utils/item-discovery.d.ts +4 -0
  289. package/dist/utils/item-discovery.js +72 -0
  290. package/dist/utils/match.d.ts +3 -0
  291. package/dist/utils/match.js +22 -0
  292. package/dist/utils/shell-detection.d.ts +20 -0
  293. package/dist/utils/shell-detection.js +41 -0
  294. package/dist/utils/task-progress.d.ts +8 -0
  295. package/dist/utils/task-progress.js +36 -0
  296. package/package.json +82 -0
  297. package/schemas/spec-driven/schema.yaml +153 -0
  298. package/schemas/spec-driven/templates/design.md +19 -0
  299. package/schemas/spec-driven/templates/proposal.md +23 -0
  300. package/schemas/spec-driven/templates/spec.md +8 -0
  301. package/schemas/spec-driven/templates/tasks.md +9 -0
  302. package/schemas/workspace-planning/schema.yaml +72 -0
  303. package/schemas/workspace-planning/templates/design.md +33 -0
  304. package/schemas/workspace-planning/templates/proposal.md +28 -0
  305. package/schemas/workspace-planning/templates/spec.md +9 -0
  306. package/schemas/workspace-planning/templates/tasks.md +15 -0
  307. package/scripts/postinstall.js +83 -0
@@ -0,0 +1,71 @@
1
+ import type { ChangeMetadata } from '../core/artifact-graph/types.js';
2
+ /**
3
+ * Options for creating a change.
4
+ */
5
+ export interface CreateChangeOptions {
6
+ /** The workflow schema to use (default: 'spec-driven') */
7
+ schema?: string;
8
+ /** Default schema to use when no explicit schema or project config is present */
9
+ defaultSchema?: string;
10
+ /** Directory that should contain the change directories */
11
+ changesDir?: string;
12
+ /** Additional metadata to persist in the change's .zhima.yaml */
13
+ metadata?: Partial<Pick<ChangeMetadata, 'goal' | 'affected_areas'>>;
14
+ }
15
+ /**
16
+ * Result of creating a change.
17
+ */
18
+ export interface CreateChangeResult {
19
+ /** The schema that was actually used (resolved from options, config, or default) */
20
+ schema: string;
21
+ /** Absolute path to the created change directory */
22
+ changeDir: string;
23
+ }
24
+ /**
25
+ * Result of validating a change name.
26
+ */
27
+ export interface ValidationResult {
28
+ valid: boolean;
29
+ error?: string;
30
+ }
31
+ /**
32
+ * Validates that a change name follows kebab-case conventions.
33
+ *
34
+ * Valid names:
35
+ * - Start with a lowercase letter
36
+ * - Contain only lowercase letters, numbers, and hyphens
37
+ * - Do not start or end with a hyphen
38
+ * - Do not contain consecutive hyphens
39
+ *
40
+ * @param name - The change name to validate
41
+ * @returns Validation result with `valid: true` or `valid: false` with an error message
42
+ *
43
+ * @example
44
+ * validateChangeName('add-auth') // { valid: true }
45
+ * validateChangeName('Add-Auth') // { valid: false, error: '...' }
46
+ */
47
+ export declare function validateChangeName(name: string): ValidationResult;
48
+ /**
49
+ * Creates a new change directory with metadata file.
50
+ *
51
+ * @param projectRoot - The root directory of the project (where `zhima/` lives)
52
+ * @param name - The change name (must be valid kebab-case)
53
+ * @param options - Optional settings for the change
54
+ * @throws Error if the change name is invalid
55
+ * @throws Error if the schema name is invalid
56
+ * @throws Error if the change directory already exists
57
+ *
58
+ * @returns Result containing the resolved schema name
59
+ *
60
+ * @example
61
+ * // Creates zhima/changes/add-auth/ with default schema
62
+ * const result = await createChange('/path/to/project', 'add-auth')
63
+ * console.log(result.schema) // 'spec-driven' or value from config
64
+ *
65
+ * @example
66
+ * // Creates zhima/changes/add-auth/ with custom schema
67
+ * const result = await createChange('/path/to/project', 'add-auth', { schema: 'my-workflow' })
68
+ * console.log(result.schema) // 'my-workflow'
69
+ */
70
+ export declare function createChange(projectRoot: string, name: string, options?: CreateChangeOptions): Promise<CreateChangeResult>;
71
+ //# sourceMappingURL=change-utils.d.ts.map
@@ -0,0 +1,123 @@
1
+ import path from 'path';
2
+ import { FileSystemUtils } from './file-system.js';
3
+ import { writeChangeMetadata, validateSchemaName } from './change-metadata.js';
4
+ import { readProjectConfig } from '../core/project-config.js';
5
+ const DEFAULT_SCHEMA = 'spec-driven';
6
+ /**
7
+ * Validates that a change name follows kebab-case conventions.
8
+ *
9
+ * Valid names:
10
+ * - Start with a lowercase letter
11
+ * - Contain only lowercase letters, numbers, and hyphens
12
+ * - Do not start or end with a hyphen
13
+ * - Do not contain consecutive hyphens
14
+ *
15
+ * @param name - The change name to validate
16
+ * @returns Validation result with `valid: true` or `valid: false` with an error message
17
+ *
18
+ * @example
19
+ * validateChangeName('add-auth') // { valid: true }
20
+ * validateChangeName('Add-Auth') // { valid: false, error: '...' }
21
+ */
22
+ export function validateChangeName(name) {
23
+ // Pattern: starts with lowercase letter, followed by lowercase letters/numbers,
24
+ // optionally followed by hyphen + lowercase letters/numbers (repeatable)
25
+ const kebabCasePattern = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
26
+ if (!name) {
27
+ return { valid: false, error: 'Change name cannot be empty' };
28
+ }
29
+ if (!kebabCasePattern.test(name)) {
30
+ // Provide specific error messages for common mistakes
31
+ if (/[A-Z]/.test(name)) {
32
+ return { valid: false, error: 'Change name must be lowercase (use kebab-case)' };
33
+ }
34
+ if (/\s/.test(name)) {
35
+ return { valid: false, error: 'Change name cannot contain spaces (use hyphens instead)' };
36
+ }
37
+ if (/_/.test(name)) {
38
+ return { valid: false, error: 'Change name cannot contain underscores (use hyphens instead)' };
39
+ }
40
+ if (name.startsWith('-')) {
41
+ return { valid: false, error: 'Change name cannot start with a hyphen' };
42
+ }
43
+ if (name.endsWith('-')) {
44
+ return { valid: false, error: 'Change name cannot end with a hyphen' };
45
+ }
46
+ if (/--/.test(name)) {
47
+ return { valid: false, error: 'Change name cannot contain consecutive hyphens' };
48
+ }
49
+ if (/[^a-z0-9-]/.test(name)) {
50
+ return { valid: false, error: 'Change name can only contain lowercase letters, numbers, and hyphens' };
51
+ }
52
+ if (/^[0-9]/.test(name)) {
53
+ return { valid: false, error: 'Change name must start with a letter' };
54
+ }
55
+ return { valid: false, error: 'Change name must follow kebab-case convention (e.g., add-auth, refactor-db)' };
56
+ }
57
+ return { valid: true };
58
+ }
59
+ /**
60
+ * Creates a new change directory with metadata file.
61
+ *
62
+ * @param projectRoot - The root directory of the project (where `zhima/` lives)
63
+ * @param name - The change name (must be valid kebab-case)
64
+ * @param options - Optional settings for the change
65
+ * @throws Error if the change name is invalid
66
+ * @throws Error if the schema name is invalid
67
+ * @throws Error if the change directory already exists
68
+ *
69
+ * @returns Result containing the resolved schema name
70
+ *
71
+ * @example
72
+ * // Creates zhima/changes/add-auth/ with default schema
73
+ * const result = await createChange('/path/to/project', 'add-auth')
74
+ * console.log(result.schema) // 'spec-driven' or value from config
75
+ *
76
+ * @example
77
+ * // Creates zhima/changes/add-auth/ with custom schema
78
+ * const result = await createChange('/path/to/project', 'add-auth', { schema: 'my-workflow' })
79
+ * console.log(result.schema) // 'my-workflow'
80
+ */
81
+ export async function createChange(projectRoot, name, options = {}) {
82
+ // Validate the name first
83
+ const validation = validateChangeName(name);
84
+ if (!validation.valid) {
85
+ throw new Error(validation.error);
86
+ }
87
+ const defaultSchema = options.defaultSchema ?? DEFAULT_SCHEMA;
88
+ // Determine schema: explicit option → project config → supplied default
89
+ let schemaName;
90
+ if (options.schema) {
91
+ schemaName = options.schema;
92
+ }
93
+ else {
94
+ // Try to read from project config
95
+ try {
96
+ const config = readProjectConfig(projectRoot);
97
+ schemaName = config?.schema ?? defaultSchema;
98
+ }
99
+ catch {
100
+ // If config read fails, use default
101
+ schemaName = defaultSchema;
102
+ }
103
+ }
104
+ // Validate the resolved schema
105
+ validateSchemaName(schemaName, projectRoot);
106
+ // Build the change directory path
107
+ const changeDir = path.join(options.changesDir ?? path.join(projectRoot, 'zhima', 'changes'), name);
108
+ // Check if change already exists
109
+ if (await FileSystemUtils.directoryExists(changeDir)) {
110
+ throw new Error(`Change '${name}' already exists at ${changeDir}`);
111
+ }
112
+ // Create the directory (including parent directories if needed)
113
+ await FileSystemUtils.createDirectory(changeDir);
114
+ // Write metadata file with schema and creation date
115
+ const today = new Date().toISOString().split('T')[0];
116
+ writeChangeMetadata(changeDir, {
117
+ schema: schemaName,
118
+ created: today,
119
+ ...options.metadata,
120
+ }, projectRoot);
121
+ return { schema: schemaName, changeDir };
122
+ }
123
+ //# sourceMappingURL=change-utils.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Command Reference Utilities
3
+ *
4
+ * Utilities for transforming command references to tool-specific formats.
5
+ */
6
+ /**
7
+ * Transforms colon-based command references to hyphen-based format.
8
+ * Converts `/zm:` patterns to `/opsx-` for tools that use hyphen syntax.
9
+ *
10
+ * @param text - The text containing command references
11
+ * @returns Text with command references transformed to hyphen format
12
+ *
13
+ * @example
14
+ * transformToHyphenCommands('/zm:new') // returns '/opsx-new'
15
+ * transformToHyphenCommands('Use /zm:apply to implement') // returns 'Use /opsx-apply to implement'
16
+ */
17
+ export declare function transformToHyphenCommands(text: string): string;
18
+ //# sourceMappingURL=command-references.d.ts.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Command Reference Utilities
3
+ *
4
+ * Utilities for transforming command references to tool-specific formats.
5
+ */
6
+ /**
7
+ * Transforms colon-based command references to hyphen-based format.
8
+ * Converts `/zm:` patterns to `/opsx-` for tools that use hyphen syntax.
9
+ *
10
+ * @param text - The text containing command references
11
+ * @returns Text with command references transformed to hyphen format
12
+ *
13
+ * @example
14
+ * transformToHyphenCommands('/zm:new') // returns '/opsx-new'
15
+ * transformToHyphenCommands('Use /zm:apply to implement') // returns 'Use /opsx-apply to implement'
16
+ */
17
+ export function transformToHyphenCommands(text) {
18
+ return text.replace(/\/zm:/g, '/opsx-');
19
+ }
20
+ //# sourceMappingURL=command-references.js.map
@@ -0,0 +1,41 @@
1
+ export declare class FileSystemUtils {
2
+ /**
3
+ * Converts a path to use forward slashes (POSIX style).
4
+ * Essential for cross-platform compatibility with glob libraries like fast-glob.
5
+ */
6
+ static toPosixPath(p: string): string;
7
+ /**
8
+ * Returns a canonical absolute path when the target exists.
9
+ * Falls back to path.resolve() so callers can still produce a stable absolute path.
10
+ */
11
+ static canonicalizeExistingPath(targetPath: string): string;
12
+ private static isWindowsBasePath;
13
+ private static normalizeSegments;
14
+ static joinPath(basePath: string, ...segments: string[]): string;
15
+ static createDirectory(dirPath: string): Promise<void>;
16
+ static fileExists(filePath: string): Promise<boolean>;
17
+ /**
18
+ * Finds the first existing parent directory by walking up the directory tree.
19
+ * @param dirPath Starting directory path
20
+ * @returns The first existing directory path, or null if root is reached without finding one
21
+ */
22
+ private static findFirstExistingDirectory;
23
+ static canWriteFile(filePath: string): Promise<boolean>;
24
+ static directoryExists(dirPath: string): Promise<boolean>;
25
+ static writeFile(filePath: string, content: string): Promise<void>;
26
+ static readFile(filePath: string): Promise<string>;
27
+ static updateFileWithMarkers(filePath: string, content: string, startMarker: string, endMarker: string): Promise<void>;
28
+ static ensureWritePermissions(dirPath: string): Promise<boolean>;
29
+ }
30
+ /**
31
+ * Removes a marker block from file content.
32
+ * Only removes markers that are on their own lines (ignores inline mentions).
33
+ * Cleans up double blank lines that may result from removal.
34
+ *
35
+ * @param content - File content with markers
36
+ * @param startMarker - The start marker string
37
+ * @param endMarker - The end marker string
38
+ * @returns Content with marker block removed, or original content if markers not found/invalid
39
+ */
40
+ export declare function removeMarkerBlock(content: string, startMarker: string, endMarker: string): string;
41
+ //# sourceMappingURL=file-system.d.ts.map
@@ -0,0 +1,301 @@
1
+ import * as nodeFs from 'fs';
2
+ import path from 'path';
3
+ const fs = nodeFs.promises;
4
+ const { constants: fsConstants } = nodeFs;
5
+ function isMarkerOnOwnLine(content, markerIndex, markerLength) {
6
+ let leftIndex = markerIndex - 1;
7
+ while (leftIndex >= 0 && content[leftIndex] !== '\n') {
8
+ const char = content[leftIndex];
9
+ if (char !== ' ' && char !== '\t' && char !== '\r') {
10
+ return false;
11
+ }
12
+ leftIndex--;
13
+ }
14
+ let rightIndex = markerIndex + markerLength;
15
+ while (rightIndex < content.length && content[rightIndex] !== '\n') {
16
+ const char = content[rightIndex];
17
+ if (char !== ' ' && char !== '\t' && char !== '\r') {
18
+ return false;
19
+ }
20
+ rightIndex++;
21
+ }
22
+ return true;
23
+ }
24
+ function findMarkerIndex(content, marker, fromIndex = 0) {
25
+ let currentIndex = content.indexOf(marker, fromIndex);
26
+ while (currentIndex !== -1) {
27
+ if (isMarkerOnOwnLine(content, currentIndex, marker.length)) {
28
+ return currentIndex;
29
+ }
30
+ currentIndex = content.indexOf(marker, currentIndex + marker.length);
31
+ }
32
+ return -1;
33
+ }
34
+ export class FileSystemUtils {
35
+ /**
36
+ * Converts a path to use forward slashes (POSIX style).
37
+ * Essential for cross-platform compatibility with glob libraries like fast-glob.
38
+ */
39
+ static toPosixPath(p) {
40
+ return p.replace(/\\/g, '/');
41
+ }
42
+ /**
43
+ * Returns a canonical absolute path when the target exists.
44
+ * Falls back to path.resolve() so callers can still produce a stable absolute path.
45
+ */
46
+ static canonicalizeExistingPath(targetPath) {
47
+ try {
48
+ // Prefer the native resolver so Windows short-path aliases are expanded.
49
+ return nodeFs.realpathSync.native(targetPath);
50
+ }
51
+ catch {
52
+ try {
53
+ return nodeFs.realpathSync(targetPath);
54
+ }
55
+ catch {
56
+ return path.resolve(targetPath);
57
+ }
58
+ }
59
+ }
60
+ static isWindowsBasePath(basePath) {
61
+ return /^[A-Za-z]:[\\/]/.test(basePath) || basePath.startsWith('\\');
62
+ }
63
+ static normalizeSegments(segments) {
64
+ return segments
65
+ .flatMap((segment) => segment.split(/[\\/]+/u))
66
+ .filter((part) => part.length > 0);
67
+ }
68
+ static joinPath(basePath, ...segments) {
69
+ const normalizedSegments = this.normalizeSegments(segments);
70
+ if (this.isWindowsBasePath(basePath)) {
71
+ const normalizedBasePath = path.win32.normalize(basePath);
72
+ return normalizedSegments.length
73
+ ? path.win32.join(normalizedBasePath, ...normalizedSegments)
74
+ : normalizedBasePath;
75
+ }
76
+ const posixBasePath = basePath.replace(/\\/g, '/');
77
+ return normalizedSegments.length
78
+ ? path.posix.join(posixBasePath, ...normalizedSegments)
79
+ : path.posix.normalize(posixBasePath);
80
+ }
81
+ static async createDirectory(dirPath) {
82
+ await fs.mkdir(dirPath, { recursive: true });
83
+ }
84
+ static async fileExists(filePath) {
85
+ try {
86
+ await fs.access(filePath);
87
+ return true;
88
+ }
89
+ catch (error) {
90
+ if (error.code !== 'ENOENT') {
91
+ console.debug(`Unable to check if file exists at ${filePath}: ${error.message}`);
92
+ }
93
+ return false;
94
+ }
95
+ }
96
+ /**
97
+ * Finds the first existing parent directory by walking up the directory tree.
98
+ * @param dirPath Starting directory path
99
+ * @returns The first existing directory path, or null if root is reached without finding one
100
+ */
101
+ static async findFirstExistingDirectory(dirPath) {
102
+ let currentDir = dirPath;
103
+ while (true) {
104
+ try {
105
+ const stats = await fs.stat(currentDir);
106
+ if (stats.isDirectory()) {
107
+ return currentDir;
108
+ }
109
+ // Path component exists but is not a directory (edge case)
110
+ console.debug(`Path component ${currentDir} exists but is not a directory`);
111
+ return null;
112
+ }
113
+ catch (error) {
114
+ if (error.code === 'ENOENT') {
115
+ // Directory doesn't exist, move up one level
116
+ const parentDir = path.dirname(currentDir);
117
+ if (parentDir === currentDir) {
118
+ // Reached filesystem root without finding existing directory
119
+ return null;
120
+ }
121
+ currentDir = parentDir;
122
+ }
123
+ else {
124
+ // Unexpected error (permissions, I/O error, etc.)
125
+ console.debug(`Error checking directory ${currentDir}: ${error.message}`);
126
+ return null;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ static async canWriteFile(filePath) {
132
+ try {
133
+ const stats = await fs.stat(filePath);
134
+ if (!stats.isFile()) {
135
+ return true;
136
+ }
137
+ // On Windows, stats.mode doesn't reliably indicate write permissions.
138
+ // Use fs.access with W_OK to check actual write permissions cross-platform.
139
+ try {
140
+ await fs.access(filePath, fsConstants.W_OK);
141
+ return true;
142
+ }
143
+ catch {
144
+ return false;
145
+ }
146
+ }
147
+ catch (error) {
148
+ if (error.code === 'ENOENT') {
149
+ // File doesn't exist - find first existing parent directory and check its permissions
150
+ const parentDir = path.dirname(filePath);
151
+ const existingDir = await this.findFirstExistingDirectory(parentDir);
152
+ if (existingDir === null) {
153
+ // No existing parent directory found (edge case)
154
+ return false;
155
+ }
156
+ // Check if the existing parent directory is writable
157
+ try {
158
+ await fs.access(existingDir, fsConstants.W_OK);
159
+ return true;
160
+ }
161
+ catch {
162
+ return false;
163
+ }
164
+ }
165
+ console.debug(`Unable to determine write permissions for ${filePath}: ${error.message}`);
166
+ return false;
167
+ }
168
+ }
169
+ static async directoryExists(dirPath) {
170
+ try {
171
+ const stats = await fs.stat(dirPath);
172
+ return stats.isDirectory();
173
+ }
174
+ catch (error) {
175
+ if (error.code !== 'ENOENT') {
176
+ console.debug(`Unable to check if directory exists at ${dirPath}: ${error.message}`);
177
+ }
178
+ return false;
179
+ }
180
+ }
181
+ static async writeFile(filePath, content) {
182
+ const dir = path.dirname(filePath);
183
+ await this.createDirectory(dir);
184
+ await fs.writeFile(filePath, content, 'utf-8');
185
+ }
186
+ static async readFile(filePath) {
187
+ return await fs.readFile(filePath, 'utf-8');
188
+ }
189
+ static async updateFileWithMarkers(filePath, content, startMarker, endMarker) {
190
+ let existingContent = '';
191
+ if (await this.fileExists(filePath)) {
192
+ existingContent = await this.readFile(filePath);
193
+ const startIndex = findMarkerIndex(existingContent, startMarker);
194
+ const endIndex = startIndex !== -1
195
+ ? findMarkerIndex(existingContent, endMarker, startIndex + startMarker.length)
196
+ : findMarkerIndex(existingContent, endMarker);
197
+ if (startIndex !== -1 && endIndex !== -1) {
198
+ if (endIndex < startIndex) {
199
+ throw new Error(`Invalid marker state in ${filePath}. End marker appears before start marker.`);
200
+ }
201
+ const before = existingContent.substring(0, startIndex);
202
+ const after = existingContent.substring(endIndex + endMarker.length);
203
+ existingContent = before + startMarker + '\n' + content + '\n' + endMarker + after;
204
+ }
205
+ else if (startIndex === -1 && endIndex === -1) {
206
+ existingContent = startMarker + '\n' + content + '\n' + endMarker + '\n\n' + existingContent;
207
+ }
208
+ else {
209
+ throw new Error(`Invalid marker state in ${filePath}. Found start: ${startIndex !== -1}, Found end: ${endIndex !== -1}`);
210
+ }
211
+ }
212
+ else {
213
+ existingContent = startMarker + '\n' + content + '\n' + endMarker;
214
+ }
215
+ await this.writeFile(filePath, existingContent);
216
+ }
217
+ static async ensureWritePermissions(dirPath) {
218
+ try {
219
+ // If directory doesn't exist, check parent directory permissions
220
+ if (!await this.directoryExists(dirPath)) {
221
+ const parentDir = path.dirname(dirPath);
222
+ if (!await this.directoryExists(parentDir)) {
223
+ await this.createDirectory(parentDir);
224
+ }
225
+ return await this.ensureWritePermissions(parentDir);
226
+ }
227
+ const testFile = path.join(dirPath, '.zhima-test-' + Date.now() + '-' + Math.random().toString(36).slice(2));
228
+ await fs.writeFile(testFile, '');
229
+ // On Windows, file may be temporarily locked by antivirus or indexing services.
230
+ // Retry unlink with a small delay if it fails.
231
+ const maxRetries = 3;
232
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
233
+ try {
234
+ await fs.unlink(testFile);
235
+ break;
236
+ }
237
+ catch (unlinkError) {
238
+ if (attempt === maxRetries - 1) {
239
+ // Last attempt failed, but we successfully wrote the file, so permissions are OK
240
+ // Just log and continue - the temp file will be cleaned up eventually
241
+ console.debug(`Could not clean up test file ${testFile}: ${unlinkError.message}`);
242
+ }
243
+ else {
244
+ // Wait briefly before retrying (Windows file lock release)
245
+ await new Promise((resolve) => setTimeout(resolve, 50));
246
+ }
247
+ }
248
+ }
249
+ return true;
250
+ }
251
+ catch (error) {
252
+ console.debug(`Insufficient permissions to write to ${dirPath}: ${error.message}`);
253
+ return false;
254
+ }
255
+ }
256
+ }
257
+ /**
258
+ * Removes a marker block from file content.
259
+ * Only removes markers that are on their own lines (ignores inline mentions).
260
+ * Cleans up double blank lines that may result from removal.
261
+ *
262
+ * @param content - File content with markers
263
+ * @param startMarker - The start marker string
264
+ * @param endMarker - The end marker string
265
+ * @returns Content with marker block removed, or original content if markers not found/invalid
266
+ */
267
+ export function removeMarkerBlock(content, startMarker, endMarker) {
268
+ const startIndex = findMarkerIndex(content, startMarker);
269
+ const endIndex = startIndex !== -1
270
+ ? findMarkerIndex(content, endMarker, startIndex + startMarker.length)
271
+ : findMarkerIndex(content, endMarker);
272
+ if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) {
273
+ return content;
274
+ }
275
+ // Find the start of the line containing the start marker
276
+ let lineStart = startIndex;
277
+ while (lineStart > 0 && content[lineStart - 1] !== '\n') {
278
+ lineStart--;
279
+ }
280
+ // Find the end of the line containing the end marker
281
+ let lineEnd = endIndex + endMarker.length;
282
+ while (lineEnd < content.length && content[lineEnd] !== '\n') {
283
+ lineEnd++;
284
+ }
285
+ // Include the trailing newline if present
286
+ if (lineEnd < content.length && content[lineEnd] === '\n') {
287
+ lineEnd++;
288
+ }
289
+ const before = content.substring(0, lineStart);
290
+ const after = content.substring(lineEnd);
291
+ // Clean up double blank lines (handle both Unix \n and Windows \r\n)
292
+ let result = before + after;
293
+ result = result.replace(/(\r?\n){3,}/g, '\n\n');
294
+ // Trim trailing whitespace but preserve leading whitespace and original newline style
295
+ if (result.trimEnd() === '') {
296
+ return '';
297
+ }
298
+ const newline = content.includes('\r\n') ? '\r\n' : '\n';
299
+ return result.trimEnd() + newline;
300
+ }
301
+ //# sourceMappingURL=file-system.js.map
@@ -0,0 +1,6 @@
1
+ export { validateChangeName, createChange } from './change-utils.js';
2
+ export type { ValidationResult, CreateChangeOptions } from './change-utils.js';
3
+ export { readChangeMetadata, writeChangeMetadata, resolveSchemaForChange, validateSchemaName, ChangeMetadataError, } from './change-metadata.js';
4
+ export { FileSystemUtils, removeMarkerBlock } from './file-system.js';
5
+ export { transformToHyphenCommands } from './command-references.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ // Shared utilities
2
+ export { validateChangeName, createChange } from './change-utils.js';
3
+ // Change metadata utilities
4
+ export { readChangeMetadata, writeChangeMetadata, resolveSchemaForChange, validateSchemaName, ChangeMetadataError, } from './change-metadata.js';
5
+ // File system utilities
6
+ export { FileSystemUtils, removeMarkerBlock } from './file-system.js';
7
+ // Command reference utilities
8
+ export { transformToHyphenCommands } from './command-references.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ export type InteractiveOptions = {
2
+ /**
3
+ * Explicit "disable prompts" flag passed by internal callers.
4
+ */
5
+ noInteractive?: boolean;
6
+ /**
7
+ * Commander-style negated option: `--no-interactive` sets this to false.
8
+ */
9
+ interactive?: boolean;
10
+ };
11
+ /**
12
+ * Resolves whether non-interactive mode is requested.
13
+ * Handles both explicit `noInteractive: true` and Commander.js style `interactive: false`.
14
+ * Use this helper instead of manually checking options.noInteractive to avoid bugs.
15
+ */
16
+ export declare function resolveNoInteractive(value?: boolean | InteractiveOptions): boolean;
17
+ export declare function isInteractive(value?: boolean | InteractiveOptions): boolean;
18
+ //# sourceMappingURL=interactive.d.ts.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Resolves whether non-interactive mode is requested.
3
+ * Handles both explicit `noInteractive: true` and Commander.js style `interactive: false`.
4
+ * Use this helper instead of manually checking options.noInteractive to avoid bugs.
5
+ */
6
+ export function resolveNoInteractive(value) {
7
+ if (typeof value === 'boolean')
8
+ return value;
9
+ return value?.noInteractive === true || value?.interactive === false;
10
+ }
11
+ export function isInteractive(value) {
12
+ if (resolveNoInteractive(value))
13
+ return false;
14
+ if (process.env.OPEN_SPEC_INTERACTIVE === '0')
15
+ return false;
16
+ // Respect the standard CI environment variable (set by GitHub Actions, GitLab CI, Travis, etc.)
17
+ if ('CI' in process.env)
18
+ return false;
19
+ return !!process.stdin.isTTY;
20
+ }
21
+ //# sourceMappingURL=interactive.js.map
@@ -0,0 +1,4 @@
1
+ export declare function getActiveChangeIds(root?: string): Promise<string[]>;
2
+ export declare function getSpecIds(root?: string): Promise<string[]>;
3
+ export declare function getArchivedChangeIds(root?: string): Promise<string[]>;
4
+ //# sourceMappingURL=item-discovery.d.ts.map