@zhuan-ai/zhuanspec 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 (210) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +461 -0
  3. package/README.zh.md +434 -0
  4. package/bin/zhuanspec.js +3 -0
  5. package/dist/cli/index.d.ts +2 -0
  6. package/dist/cli/index.js +356 -0
  7. package/dist/commands/artifact-workflow.d.ts +13 -0
  8. package/dist/commands/artifact-workflow.js +916 -0
  9. package/dist/commands/change.d.ts +35 -0
  10. package/dist/commands/change.js +277 -0
  11. package/dist/commands/completion.d.ts +72 -0
  12. package/dist/commands/completion.js +221 -0
  13. package/dist/commands/config.d.ts +8 -0
  14. package/dist/commands/config.js +198 -0
  15. package/dist/commands/show.d.ts +14 -0
  16. package/dist/commands/show.js +132 -0
  17. package/dist/commands/spec.d.ts +15 -0
  18. package/dist/commands/spec.js +225 -0
  19. package/dist/commands/validate.d.ts +24 -0
  20. package/dist/commands/validate.js +294 -0
  21. package/dist/core/archive.d.ts +30 -0
  22. package/dist/core/archive.js +438 -0
  23. package/dist/core/artifact-graph/graph.d.ts +56 -0
  24. package/dist/core/artifact-graph/graph.js +141 -0
  25. package/dist/core/artifact-graph/index.d.ts +7 -0
  26. package/dist/core/artifact-graph/index.js +13 -0
  27. package/dist/core/artifact-graph/instruction-loader.d.ts +134 -0
  28. package/dist/core/artifact-graph/instruction-loader.js +180 -0
  29. package/dist/core/artifact-graph/resolver.d.ts +61 -0
  30. package/dist/core/artifact-graph/resolver.js +187 -0
  31. package/dist/core/artifact-graph/schema.d.ts +13 -0
  32. package/dist/core/artifact-graph/schema.js +108 -0
  33. package/dist/core/artifact-graph/state.d.ts +12 -0
  34. package/dist/core/artifact-graph/state.js +54 -0
  35. package/dist/core/artifact-graph/types.d.ts +45 -0
  36. package/dist/core/artifact-graph/types.js +43 -0
  37. package/dist/core/completions/command-registry.d.ts +7 -0
  38. package/dist/core/completions/command-registry.js +362 -0
  39. package/dist/core/completions/completion-provider.d.ts +60 -0
  40. package/dist/core/completions/completion-provider.js +102 -0
  41. package/dist/core/completions/factory.d.ts +51 -0
  42. package/dist/core/completions/factory.js +57 -0
  43. package/dist/core/completions/generators/zsh-generator.d.ts +58 -0
  44. package/dist/core/completions/generators/zsh-generator.js +319 -0
  45. package/dist/core/completions/installers/zsh-installer.d.ts +136 -0
  46. package/dist/core/completions/installers/zsh-installer.js +449 -0
  47. package/dist/core/completions/types.d.ts +78 -0
  48. package/dist/core/completions/types.js +2 -0
  49. package/dist/core/config-schema.d.ts +76 -0
  50. package/dist/core/config-schema.js +200 -0
  51. package/dist/core/config.d.ts +16 -0
  52. package/dist/core/config.js +29 -0
  53. package/dist/core/configurators/agents.d.ts +8 -0
  54. package/dist/core/configurators/agents.js +15 -0
  55. package/dist/core/configurators/base.d.ts +7 -0
  56. package/dist/core/configurators/base.js +2 -0
  57. package/dist/core/configurators/claude.d.ts +8 -0
  58. package/dist/core/configurators/claude.js +15 -0
  59. package/dist/core/configurators/cline.d.ts +8 -0
  60. package/dist/core/configurators/cline.js +15 -0
  61. package/dist/core/configurators/codebuddy.d.ts +8 -0
  62. package/dist/core/configurators/codebuddy.js +15 -0
  63. package/dist/core/configurators/costrict.d.ts +8 -0
  64. package/dist/core/configurators/costrict.js +15 -0
  65. package/dist/core/configurators/iflow.d.ts +8 -0
  66. package/dist/core/configurators/iflow.js +15 -0
  67. package/dist/core/configurators/qoder.d.ts +30 -0
  68. package/dist/core/configurators/qoder.js +42 -0
  69. package/dist/core/configurators/qwen.d.ts +24 -0
  70. package/dist/core/configurators/qwen.js +37 -0
  71. package/dist/core/configurators/registry.d.ts +9 -0
  72. package/dist/core/configurators/registry.js +43 -0
  73. package/dist/core/configurators/slash/amazon-q.d.ts +9 -0
  74. package/dist/core/configurators/slash/amazon-q.js +46 -0
  75. package/dist/core/configurators/slash/antigravity.d.ts +9 -0
  76. package/dist/core/configurators/slash/antigravity.js +23 -0
  77. package/dist/core/configurators/slash/auggie.d.ts +9 -0
  78. package/dist/core/configurators/slash/auggie.js +31 -0
  79. package/dist/core/configurators/slash/base.d.ts +19 -0
  80. package/dist/core/configurators/slash/base.js +69 -0
  81. package/dist/core/configurators/slash/claude.d.ts +9 -0
  82. package/dist/core/configurators/slash/claude.js +37 -0
  83. package/dist/core/configurators/slash/cline.d.ts +9 -0
  84. package/dist/core/configurators/slash/cline.js +23 -0
  85. package/dist/core/configurators/slash/codebuddy.d.ts +9 -0
  86. package/dist/core/configurators/slash/codebuddy.js +37 -0
  87. package/dist/core/configurators/slash/codex.d.ts +14 -0
  88. package/dist/core/configurators/slash/codex.js +109 -0
  89. package/dist/core/configurators/slash/costrict.d.ts +9 -0
  90. package/dist/core/configurators/slash/costrict.js +31 -0
  91. package/dist/core/configurators/slash/crush.d.ts +9 -0
  92. package/dist/core/configurators/slash/crush.js +37 -0
  93. package/dist/core/configurators/slash/cursor.d.ts +9 -0
  94. package/dist/core/configurators/slash/cursor.js +37 -0
  95. package/dist/core/configurators/slash/factory.d.ts +10 -0
  96. package/dist/core/configurators/slash/factory.js +35 -0
  97. package/dist/core/configurators/slash/gemini.d.ts +9 -0
  98. package/dist/core/configurators/slash/gemini.js +22 -0
  99. package/dist/core/configurators/slash/github-copilot.d.ts +9 -0
  100. package/dist/core/configurators/slash/github-copilot.js +34 -0
  101. package/dist/core/configurators/slash/iflow.d.ts +9 -0
  102. package/dist/core/configurators/slash/iflow.js +37 -0
  103. package/dist/core/configurators/slash/kilocode.d.ts +9 -0
  104. package/dist/core/configurators/slash/kilocode.js +17 -0
  105. package/dist/core/configurators/slash/opencode.d.ts +12 -0
  106. package/dist/core/configurators/slash/opencode.js +72 -0
  107. package/dist/core/configurators/slash/qoder.d.ts +35 -0
  108. package/dist/core/configurators/slash/qoder.js +76 -0
  109. package/dist/core/configurators/slash/qwen.d.ts +32 -0
  110. package/dist/core/configurators/slash/qwen.js +49 -0
  111. package/dist/core/configurators/slash/registry.d.ts +8 -0
  112. package/dist/core/configurators/slash/registry.js +75 -0
  113. package/dist/core/configurators/slash/roocode.d.ts +9 -0
  114. package/dist/core/configurators/slash/roocode.js +23 -0
  115. package/dist/core/configurators/slash/toml-base.d.ts +10 -0
  116. package/dist/core/configurators/slash/toml-base.js +53 -0
  117. package/dist/core/configurators/slash/windsurf.d.ts +9 -0
  118. package/dist/core/configurators/slash/windsurf.js +23 -0
  119. package/dist/core/converters/json-converter.d.ts +6 -0
  120. package/dist/core/converters/json-converter.js +51 -0
  121. package/dist/core/global-config.d.ts +39 -0
  122. package/dist/core/global-config.js +115 -0
  123. package/dist/core/index.d.ts +2 -0
  124. package/dist/core/index.js +3 -0
  125. package/dist/core/init.d.ts +60 -0
  126. package/dist/core/init.js +861 -0
  127. package/dist/core/list.d.ts +9 -0
  128. package/dist/core/list.js +171 -0
  129. package/dist/core/parsers/change-parser.d.ts +13 -0
  130. package/dist/core/parsers/change-parser.js +193 -0
  131. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  132. package/dist/core/parsers/markdown-parser.js +187 -0
  133. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  134. package/dist/core/parsers/requirement-blocks.js +201 -0
  135. package/dist/core/project-config.d.ts +34 -0
  136. package/dist/core/project-config.js +79 -0
  137. package/dist/core/schemas/base.schema.d.ts +13 -0
  138. package/dist/core/schemas/base.schema.js +13 -0
  139. package/dist/core/schemas/change.schema.d.ts +73 -0
  140. package/dist/core/schemas/change.schema.js +31 -0
  141. package/dist/core/schemas/index.d.ts +4 -0
  142. package/dist/core/schemas/index.js +4 -0
  143. package/dist/core/schemas/spec.schema.d.ts +18 -0
  144. package/dist/core/schemas/spec.schema.js +15 -0
  145. package/dist/core/skill-discovery.d.ts +24 -0
  146. package/dist/core/skill-discovery.js +153 -0
  147. package/dist/core/specs-apply.d.ts +73 -0
  148. package/dist/core/specs-apply.js +384 -0
  149. package/dist/core/styles/palette.d.ts +7 -0
  150. package/dist/core/styles/palette.js +8 -0
  151. package/dist/core/templates/agents-root-stub.d.ts +2 -0
  152. package/dist/core/templates/agents-root-stub.js +17 -0
  153. package/dist/core/templates/agents-template.d.ts +2 -0
  154. package/dist/core/templates/agents-template.js +706 -0
  155. package/dist/core/templates/claude-template.d.ts +2 -0
  156. package/dist/core/templates/claude-template.js +2 -0
  157. package/dist/core/templates/cline-template.d.ts +2 -0
  158. package/dist/core/templates/cline-template.js +2 -0
  159. package/dist/core/templates/costrict-template.d.ts +2 -0
  160. package/dist/core/templates/costrict-template.js +2 -0
  161. package/dist/core/templates/index.d.ts +17 -0
  162. package/dist/core/templates/index.js +37 -0
  163. package/dist/core/templates/project-template.d.ts +8 -0
  164. package/dist/core/templates/project-template.js +32 -0
  165. package/dist/core/templates/skill-templates.d.ts +103 -0
  166. package/dist/core/templates/skill-templates.js +2131 -0
  167. package/dist/core/templates/slash-command-templates.d.ts +4 -0
  168. package/dist/core/templates/slash-command-templates.js +81 -0
  169. package/dist/core/update.d.ts +4 -0
  170. package/dist/core/update.js +88 -0
  171. package/dist/core/validation/constants.d.ts +34 -0
  172. package/dist/core/validation/constants.js +40 -0
  173. package/dist/core/validation/types.d.ts +18 -0
  174. package/dist/core/validation/types.js +2 -0
  175. package/dist/core/validation/validator.d.ts +33 -0
  176. package/dist/core/validation/validator.js +409 -0
  177. package/dist/core/view.d.ts +8 -0
  178. package/dist/core/view.js +168 -0
  179. package/dist/index.d.ts +3 -0
  180. package/dist/index.js +3 -0
  181. package/dist/utils/change-metadata.d.ts +47 -0
  182. package/dist/utils/change-metadata.js +130 -0
  183. package/dist/utils/change-utils.d.ts +51 -0
  184. package/dist/utils/change-utils.js +100 -0
  185. package/dist/utils/file-system.d.ts +19 -0
  186. package/dist/utils/file-system.js +177 -0
  187. package/dist/utils/index.d.ts +4 -0
  188. package/dist/utils/index.js +5 -0
  189. package/dist/utils/interactive.d.ts +18 -0
  190. package/dist/utils/interactive.js +21 -0
  191. package/dist/utils/item-discovery.d.ts +4 -0
  192. package/dist/utils/item-discovery.js +72 -0
  193. package/dist/utils/match.d.ts +3 -0
  194. package/dist/utils/match.js +22 -0
  195. package/dist/utils/shell-detection.d.ts +20 -0
  196. package/dist/utils/shell-detection.js +41 -0
  197. package/dist/utils/task-progress.d.ts +8 -0
  198. package/dist/utils/task-progress.js +36 -0
  199. package/package.json +81 -0
  200. package/schemas/spec-driven/schema.yaml +205 -0
  201. package/schemas/spec-driven/templates/design.md +19 -0
  202. package/schemas/spec-driven/templates/proposal.md +43 -0
  203. package/schemas/spec-driven/templates/spec.md +8 -0
  204. package/schemas/spec-driven/templates/tasks.md +25 -0
  205. package/schemas/tdd/schema.yaml +213 -0
  206. package/schemas/tdd/templates/docs.md +0 -0
  207. package/schemas/tdd/templates/implementation.md +11 -0
  208. package/schemas/tdd/templates/spec.md +11 -0
  209. package/schemas/tdd/templates/test.md +11 -0
  210. package/scripts/postinstall.js +147 -0
@@ -0,0 +1,51 @@
1
+ import { CompletionGenerator } from './types.js';
2
+ import { InstallationResult } from './installers/zsh-installer.js';
3
+ import { SupportedShell } from '../../utils/shell-detection.js';
4
+ /**
5
+ * Interface for completion installers
6
+ */
7
+ export interface CompletionInstaller {
8
+ install(script: string): Promise<InstallationResult>;
9
+ uninstall(): Promise<{
10
+ success: boolean;
11
+ message: string;
12
+ }>;
13
+ }
14
+ export type { InstallationResult };
15
+ /**
16
+ * Factory for creating completion generators and installers
17
+ * This design makes it easy to add support for additional shells
18
+ */
19
+ export declare class CompletionFactory {
20
+ private static readonly SUPPORTED_SHELLS;
21
+ /**
22
+ * Create a completion generator for the specified shell
23
+ *
24
+ * @param shell - The target shell
25
+ * @returns CompletionGenerator instance
26
+ * @throws Error if shell is not supported
27
+ */
28
+ static createGenerator(shell: SupportedShell): CompletionGenerator;
29
+ /**
30
+ * Create a completion installer for the specified shell
31
+ *
32
+ * @param shell - The target shell
33
+ * @returns CompletionInstaller instance
34
+ * @throws Error if shell is not supported
35
+ */
36
+ static createInstaller(shell: SupportedShell): CompletionInstaller;
37
+ /**
38
+ * Check if a shell is supported
39
+ *
40
+ * @param shell - The shell to check
41
+ * @returns true if the shell is supported
42
+ */
43
+ static isSupported(shell: string): shell is SupportedShell;
44
+ /**
45
+ * Get list of all supported shells
46
+ *
47
+ * @returns Array of supported shell names
48
+ */
49
+ static getSupportedShells(): SupportedShell[];
50
+ }
51
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { ZshGenerator } from './generators/zsh-generator.js';
2
+ import { ZshInstaller } from './installers/zsh-installer.js';
3
+ /**
4
+ * Factory for creating completion generators and installers
5
+ * This design makes it easy to add support for additional shells
6
+ */
7
+ export class CompletionFactory {
8
+ static SUPPORTED_SHELLS = ['zsh'];
9
+ /**
10
+ * Create a completion generator for the specified shell
11
+ *
12
+ * @param shell - The target shell
13
+ * @returns CompletionGenerator instance
14
+ * @throws Error if shell is not supported
15
+ */
16
+ static createGenerator(shell) {
17
+ switch (shell) {
18
+ case 'zsh':
19
+ return new ZshGenerator();
20
+ default:
21
+ throw new Error(`Unsupported shell: ${shell}`);
22
+ }
23
+ }
24
+ /**
25
+ * Create a completion installer for the specified shell
26
+ *
27
+ * @param shell - The target shell
28
+ * @returns CompletionInstaller instance
29
+ * @throws Error if shell is not supported
30
+ */
31
+ static createInstaller(shell) {
32
+ switch (shell) {
33
+ case 'zsh':
34
+ return new ZshInstaller();
35
+ default:
36
+ throw new Error(`Unsupported shell: ${shell}`);
37
+ }
38
+ }
39
+ /**
40
+ * Check if a shell is supported
41
+ *
42
+ * @param shell - The shell to check
43
+ * @returns true if the shell is supported
44
+ */
45
+ static isSupported(shell) {
46
+ return this.SUPPORTED_SHELLS.includes(shell);
47
+ }
48
+ /**
49
+ * Get list of all supported shells
50
+ *
51
+ * @returns Array of supported shell names
52
+ */
53
+ static getSupportedShells() {
54
+ return [...this.SUPPORTED_SHELLS];
55
+ }
56
+ }
57
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1,58 @@
1
+ import { CompletionGenerator, CommandDefinition } from '../types.js';
2
+ /**
3
+ * Generates Zsh completion scripts for the ZhuanSpec CLI.
4
+ * Follows Zsh completion system conventions using the _zhuanspec function.
5
+ */
6
+ export declare class ZshGenerator implements CompletionGenerator {
7
+ readonly shell: "zsh";
8
+ /**
9
+ * Generate a Zsh completion script
10
+ *
11
+ * @param commands - Command definitions to generate completions for
12
+ * @returns Zsh completion script as a string
13
+ */
14
+ generate(commands: CommandDefinition[]): string;
15
+ /**
16
+ * Generate a single completion function
17
+ *
18
+ * @param functionName - Name of the completion function
19
+ * @param varName - Name of the local array variable
20
+ * @param varLabel - Label for the completion items
21
+ * @param commandLines - Command line(s) to populate the array
22
+ * @param comment - Optional comment describing the function
23
+ */
24
+ private generateCompletionFunction;
25
+ /**
26
+ * Generate dynamic completion helper functions for change and spec IDs
27
+ */
28
+ private generateDynamicCompletionHelpers;
29
+ /**
30
+ * Generate completion function for a specific command
31
+ */
32
+ private generateCommandFunction;
33
+ /**
34
+ * Generate completion function for a subcommand
35
+ */
36
+ private generateSubcommandFunction;
37
+ /**
38
+ * Generate flag specification for _arguments
39
+ */
40
+ private generateFlagSpec;
41
+ /**
42
+ * Generate positional argument specification
43
+ */
44
+ private generatePositionalSpec;
45
+ /**
46
+ * Escape special characters in descriptions
47
+ */
48
+ private escapeDescription;
49
+ /**
50
+ * Escape special characters in values
51
+ */
52
+ private escapeValue;
53
+ /**
54
+ * Sanitize command names for use in function names
55
+ */
56
+ private sanitizeFunctionName;
57
+ }
58
+ //# sourceMappingURL=zsh-generator.d.ts.map
@@ -0,0 +1,319 @@
1
+ /**
2
+ * Generates Zsh completion scripts for the ZhuanSpec CLI.
3
+ * Follows Zsh completion system conventions using the _zhuanspec function.
4
+ */
5
+ export class ZshGenerator {
6
+ shell = 'zsh';
7
+ /**
8
+ * Generate a Zsh completion script
9
+ *
10
+ * @param commands - Command definitions to generate completions for
11
+ * @returns Zsh completion script as a string
12
+ */
13
+ generate(commands) {
14
+ const script = [];
15
+ // Header comment
16
+ script.push('#compdef zhuanspec');
17
+ script.push('');
18
+ script.push('# Zsh completion script for ZhuanSpec CLI');
19
+ script.push('# Auto-generated - do not edit manually');
20
+ script.push('');
21
+ // Main completion function
22
+ script.push('_zhuanspec() {');
23
+ script.push(' local context state line');
24
+ script.push(' typeset -A opt_args');
25
+ script.push('');
26
+ // Generate main command argument specification
27
+ script.push(' local -a commands');
28
+ script.push(' commands=(');
29
+ for (const cmd of commands) {
30
+ const escapedDesc = this.escapeDescription(cmd.description);
31
+ script.push(` '${cmd.name}:${escapedDesc}'`);
32
+ }
33
+ script.push(' )');
34
+ script.push('');
35
+ // Main _arguments call
36
+ script.push(' _arguments -C \\');
37
+ script.push(' "1: :->command" \\');
38
+ script.push(' "*::arg:->args"');
39
+ script.push('');
40
+ // Command dispatch logic
41
+ script.push(' case $state in');
42
+ script.push(' command)');
43
+ script.push(' _describe "zhuanspec command" commands');
44
+ script.push(' ;;');
45
+ script.push(' args)');
46
+ script.push(' case $words[1] in');
47
+ // Generate completion for each command
48
+ for (const cmd of commands) {
49
+ script.push(` ${cmd.name})`);
50
+ script.push(` _zhuanspec_${this.sanitizeFunctionName(cmd.name)}`);
51
+ script.push(' ;;');
52
+ }
53
+ script.push(' esac');
54
+ script.push(' ;;');
55
+ script.push(' esac');
56
+ script.push('}');
57
+ script.push('');
58
+ // Generate individual command completion functions
59
+ for (const cmd of commands) {
60
+ script.push(...this.generateCommandFunction(cmd));
61
+ script.push('');
62
+ }
63
+ // Add dynamic completion helper functions
64
+ script.push(...this.generateDynamicCompletionHelpers());
65
+ // Register the completion function
66
+ script.push('compdef _zhuanspec zhuanspec');
67
+ script.push('');
68
+ return script.join('\n');
69
+ }
70
+ /**
71
+ * Generate a single completion function
72
+ *
73
+ * @param functionName - Name of the completion function
74
+ * @param varName - Name of the local array variable
75
+ * @param varLabel - Label for the completion items
76
+ * @param commandLines - Command line(s) to populate the array
77
+ * @param comment - Optional comment describing the function
78
+ */
79
+ generateCompletionFunction(functionName, varName, varLabel, commandLines, comment) {
80
+ const lines = [];
81
+ if (comment) {
82
+ lines.push(comment);
83
+ }
84
+ lines.push(`${functionName}() {`);
85
+ lines.push(` local -a ${varName}`);
86
+ if (commandLines.length === 1) {
87
+ lines.push(` ${commandLines[0]}`);
88
+ }
89
+ else {
90
+ lines.push(` ${varName}=(`);
91
+ for (let i = 0; i < commandLines.length; i++) {
92
+ const suffix = i < commandLines.length - 1 ? ' \\' : '';
93
+ lines.push(` ${commandLines[i]}${suffix}`);
94
+ }
95
+ lines.push(' )');
96
+ }
97
+ lines.push(` _describe "${varLabel}" ${varName}`);
98
+ lines.push('}');
99
+ lines.push('');
100
+ return lines;
101
+ }
102
+ /**
103
+ * Generate dynamic completion helper functions for change and spec IDs
104
+ */
105
+ generateDynamicCompletionHelpers() {
106
+ const lines = [];
107
+ lines.push('# Dynamic completion helpers');
108
+ lines.push('');
109
+ // Helper function for completing change IDs
110
+ lines.push('# Use zhuanspec __complete to get available changes');
111
+ lines.push('_zhuanspec_complete_changes() {');
112
+ lines.push(' local -a changes');
113
+ lines.push(' while IFS=$\'\\t\' read -r id desc; do');
114
+ lines.push(' changes+=("$id:$desc")');
115
+ lines.push(' done < <(zhuanspec __complete changes 2>/dev/null)');
116
+ lines.push(' _describe "change" changes');
117
+ lines.push('}');
118
+ lines.push('');
119
+ // Helper function for completing spec IDs
120
+ lines.push('# Use zhuanspec __complete to get available specs');
121
+ lines.push('_zhuanspec_complete_specs() {');
122
+ lines.push(' local -a specs');
123
+ lines.push(' while IFS=$\'\\t\' read -r id desc; do');
124
+ lines.push(' specs+=("$id:$desc")');
125
+ lines.push(' done < <(zhuanspec __complete specs 2>/dev/null)');
126
+ lines.push(' _describe "spec" specs');
127
+ lines.push('}');
128
+ lines.push('');
129
+ // Helper function for completing both changes and specs
130
+ lines.push('# Get both changes and specs');
131
+ lines.push('_zhuanspec_complete_items() {');
132
+ lines.push(' local -a items');
133
+ lines.push(' while IFS=$\'\\t\' read -r id desc; do');
134
+ lines.push(' items+=("$id:$desc")');
135
+ lines.push(' done < <(zhuanspec __complete changes 2>/dev/null)');
136
+ lines.push(' while IFS=$\'\\t\' read -r id desc; do');
137
+ lines.push(' items+=("$id:$desc")');
138
+ lines.push(' done < <(zhuanspec __complete specs 2>/dev/null)');
139
+ lines.push(' _describe "item" items');
140
+ lines.push('}');
141
+ lines.push('');
142
+ return lines;
143
+ }
144
+ /**
145
+ * Generate completion function for a specific command
146
+ */
147
+ generateCommandFunction(cmd) {
148
+ const funcName = `_zhuanspec_${this.sanitizeFunctionName(cmd.name)}`;
149
+ const lines = [];
150
+ lines.push(`${funcName}() {`);
151
+ // If command has subcommands, handle them
152
+ if (cmd.subcommands && cmd.subcommands.length > 0) {
153
+ lines.push(' local context state line');
154
+ lines.push(' typeset -A opt_args');
155
+ lines.push('');
156
+ lines.push(' local -a subcommands');
157
+ lines.push(' subcommands=(');
158
+ for (const subcmd of cmd.subcommands) {
159
+ const escapedDesc = this.escapeDescription(subcmd.description);
160
+ lines.push(` '${subcmd.name}:${escapedDesc}'`);
161
+ }
162
+ lines.push(' )');
163
+ lines.push('');
164
+ lines.push(' _arguments -C \\');
165
+ // Add command flags
166
+ for (const flag of cmd.flags) {
167
+ lines.push(' ' + this.generateFlagSpec(flag) + ' \\');
168
+ }
169
+ lines.push(' "1: :->subcommand" \\');
170
+ lines.push(' "*::arg:->args"');
171
+ lines.push('');
172
+ lines.push(' case $state in');
173
+ lines.push(' subcommand)');
174
+ lines.push(' _describe "subcommand" subcommands');
175
+ lines.push(' ;;');
176
+ lines.push(' args)');
177
+ lines.push(' case $words[1] in');
178
+ for (const subcmd of cmd.subcommands) {
179
+ lines.push(` ${subcmd.name})`);
180
+ lines.push(` _zhuanspec_${this.sanitizeFunctionName(cmd.name)}_${this.sanitizeFunctionName(subcmd.name)}`);
181
+ lines.push(' ;;');
182
+ }
183
+ lines.push(' esac');
184
+ lines.push(' ;;');
185
+ lines.push(' esac');
186
+ }
187
+ else {
188
+ // Command without subcommands
189
+ lines.push(' _arguments \\');
190
+ // Add flags
191
+ for (const flag of cmd.flags) {
192
+ lines.push(' ' + this.generateFlagSpec(flag) + ' \\');
193
+ }
194
+ // Add positional argument completion
195
+ if (cmd.acceptsPositional) {
196
+ const positionalSpec = this.generatePositionalSpec(cmd.positionalType);
197
+ lines.push(' ' + positionalSpec);
198
+ }
199
+ else {
200
+ // Remove trailing backslash from last flag
201
+ if (lines[lines.length - 1].endsWith(' \\')) {
202
+ lines[lines.length - 1] = lines[lines.length - 1].slice(0, -2);
203
+ }
204
+ }
205
+ }
206
+ lines.push('}');
207
+ // Generate subcommand functions if they exist
208
+ if (cmd.subcommands) {
209
+ for (const subcmd of cmd.subcommands) {
210
+ lines.push('');
211
+ lines.push(...this.generateSubcommandFunction(cmd.name, subcmd));
212
+ }
213
+ }
214
+ return lines;
215
+ }
216
+ /**
217
+ * Generate completion function for a subcommand
218
+ */
219
+ generateSubcommandFunction(parentName, subcmd) {
220
+ const funcName = `_zhuanspec_${this.sanitizeFunctionName(parentName)}_${this.sanitizeFunctionName(subcmd.name)}`;
221
+ const lines = [];
222
+ lines.push(`${funcName}() {`);
223
+ lines.push(' _arguments \\');
224
+ // Add flags
225
+ for (const flag of subcmd.flags) {
226
+ lines.push(' ' + this.generateFlagSpec(flag) + ' \\');
227
+ }
228
+ // Add positional argument completion
229
+ if (subcmd.acceptsPositional) {
230
+ const positionalSpec = this.generatePositionalSpec(subcmd.positionalType);
231
+ lines.push(' ' + positionalSpec);
232
+ }
233
+ else {
234
+ // Remove trailing backslash from last flag
235
+ if (lines[lines.length - 1].endsWith(' \\')) {
236
+ lines[lines.length - 1] = lines[lines.length - 1].slice(0, -2);
237
+ }
238
+ }
239
+ lines.push('}');
240
+ return lines;
241
+ }
242
+ /**
243
+ * Generate flag specification for _arguments
244
+ */
245
+ generateFlagSpec(flag) {
246
+ const parts = [];
247
+ // Handle mutually exclusive short and long forms
248
+ if (flag.short) {
249
+ parts.push(`'(-${flag.short} --${flag.name})'{-${flag.short},--${flag.name}}'`);
250
+ }
251
+ else {
252
+ parts.push(`'--${flag.name}`);
253
+ }
254
+ // Add description
255
+ const escapedDesc = this.escapeDescription(flag.description);
256
+ parts.push(`[${escapedDesc}]`);
257
+ // Add value completion if flag takes a value
258
+ if (flag.takesValue) {
259
+ if (flag.values && flag.values.length > 0) {
260
+ // Provide specific value completions
261
+ const valueList = flag.values.map(v => this.escapeValue(v)).join(' ');
262
+ parts.push(`:value:(${valueList})`);
263
+ }
264
+ else {
265
+ // Generic value placeholder
266
+ parts.push(':value:');
267
+ }
268
+ }
269
+ // Close the quote (needed for both short and long forms)
270
+ parts.push("'");
271
+ return parts.join('');
272
+ }
273
+ /**
274
+ * Generate positional argument specification
275
+ */
276
+ generatePositionalSpec(positionalType) {
277
+ switch (positionalType) {
278
+ case 'change-id':
279
+ return "'*: :_zhuanspec_complete_changes'";
280
+ case 'spec-id':
281
+ return "'*: :_zhuanspec_complete_specs'";
282
+ case 'change-or-spec-id':
283
+ return "'*: :_zhuanspec_complete_items'";
284
+ case 'path':
285
+ return "'*:path:_files'";
286
+ case 'shell':
287
+ return "'*:shell:(zsh)'";
288
+ default:
289
+ return "'*: :_default'";
290
+ }
291
+ }
292
+ /**
293
+ * Escape special characters in descriptions
294
+ */
295
+ escapeDescription(desc) {
296
+ return desc
297
+ .replace(/\\/g, '\\\\')
298
+ .replace(/'/g, "\\'")
299
+ .replace(/\[/g, '\\[')
300
+ .replace(/]/g, '\\]')
301
+ .replace(/:/g, '\\:');
302
+ }
303
+ /**
304
+ * Escape special characters in values
305
+ */
306
+ escapeValue(value) {
307
+ return value
308
+ .replace(/\\/g, '\\\\')
309
+ .replace(/'/g, "\\'")
310
+ .replace(/ /g, '\\ ');
311
+ }
312
+ /**
313
+ * Sanitize command names for use in function names
314
+ */
315
+ sanitizeFunctionName(name) {
316
+ return name.replace(/-/g, '_');
317
+ }
318
+ }
319
+ //# sourceMappingURL=zsh-generator.js.map
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Installation result information
3
+ */
4
+ export interface InstallationResult {
5
+ success: boolean;
6
+ installedPath?: string;
7
+ backupPath?: string;
8
+ isOhMyZsh: boolean;
9
+ zshrcConfigured?: boolean;
10
+ message: string;
11
+ instructions?: string[];
12
+ }
13
+ /**
14
+ * Installer for Zsh completion scripts.
15
+ * Supports both Oh My Zsh and standard Zsh configurations.
16
+ */
17
+ export declare class ZshInstaller {
18
+ private readonly homeDir;
19
+ /**
20
+ * Markers for .zshrc configuration management
21
+ */
22
+ private readonly ZSHRC_MARKERS;
23
+ constructor(homeDir?: string);
24
+ /**
25
+ * Check if Oh My Zsh is installed
26
+ *
27
+ * @returns true if Oh My Zsh is detected via $ZSH env var or directory exists
28
+ */
29
+ isOhMyZshInstalled(): Promise<boolean>;
30
+ /**
31
+ * Get the appropriate installation path for the completion script
32
+ *
33
+ * @returns Object with installation path and whether it's Oh My Zsh
34
+ */
35
+ getInstallationPath(): Promise<{
36
+ path: string;
37
+ isOhMyZsh: boolean;
38
+ }>;
39
+ /**
40
+ * Backup an existing completion file if it exists
41
+ *
42
+ * @param targetPath - Path to the file to backup
43
+ * @returns Path to the backup file, or undefined if no backup was needed
44
+ */
45
+ backupExistingFile(targetPath: string): Promise<string | undefined>;
46
+ /**
47
+ * Get the path to .zshrc file
48
+ *
49
+ * @returns Path to .zshrc
50
+ */
51
+ private getZshrcPath;
52
+ /**
53
+ * Generate .zshrc configuration content
54
+ *
55
+ * @param completionsDir - Directory containing completion scripts
56
+ * @returns Configuration content
57
+ */
58
+ private generateZshrcConfig;
59
+ /**
60
+ * Configure .zshrc to enable completions
61
+ * Only applies to standard Zsh (not Oh My Zsh)
62
+ *
63
+ * @param completionsDir - Directory containing completion scripts
64
+ * @returns true if configured successfully, false otherwise
65
+ */
66
+ configureZshrc(completionsDir: string): Promise<boolean>;
67
+ /**
68
+ * Check if .zshrc has ZhuanSpec configuration markers
69
+ *
70
+ * @returns true if .zshrc exists and has markers
71
+ */
72
+ private hasZshrcConfig;
73
+ /**
74
+ * Check if fpath configuration is needed for a given directory
75
+ * Used to verify if Oh My Zsh (or other) completions directory is already in fpath
76
+ *
77
+ * @param completionsDir - Directory to check for in fpath
78
+ * @returns true if configuration is needed, false if directory is already referenced
79
+ */
80
+ private needsFpathConfig;
81
+ /**
82
+ * Remove .zshrc configuration
83
+ * Used during uninstallation
84
+ *
85
+ * @returns true if removed successfully, false otherwise
86
+ */
87
+ removeZshrcConfig(): Promise<boolean>;
88
+ /**
89
+ * Install the completion script
90
+ *
91
+ * @param completionScript - The completion script content to install
92
+ * @returns Installation result with status and instructions
93
+ */
94
+ install(completionScript: string): Promise<InstallationResult>;
95
+ /**
96
+ * Generate Oh My Zsh fpath verification guidance
97
+ *
98
+ * @param completionsDir - Custom completions directory path
99
+ * @returns Array of guidance strings, or undefined if not needed
100
+ */
101
+ private generateOhMyZshFpathGuidance;
102
+ /**
103
+ * Generate user instructions for enabling completions
104
+ *
105
+ * @param isOhMyZsh - Whether Oh My Zsh is being used
106
+ * @param installedPath - Path where the script was installed
107
+ * @returns Array of instruction strings
108
+ */
109
+ private generateInstructions;
110
+ /**
111
+ * Uninstall the completion script
112
+ *
113
+ * @returns true if uninstalled successfully, false otherwise
114
+ */
115
+ uninstall(): Promise<{
116
+ success: boolean;
117
+ message: string;
118
+ }>;
119
+ /**
120
+ * Check if completion script is currently installed
121
+ *
122
+ * @returns true if the completion script exists
123
+ */
124
+ isInstalled(): Promise<boolean>;
125
+ /**
126
+ * Get information about the current installation
127
+ *
128
+ * @returns Installation status information
129
+ */
130
+ getInstallationInfo(): Promise<{
131
+ installed: boolean;
132
+ path?: string;
133
+ isOhMyZsh?: boolean;
134
+ }>;
135
+ }
136
+ //# sourceMappingURL=zsh-installer.d.ts.map