ace-git-worktree 0.19.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 (61) hide show
  1. checksums.yaml +7 -0
  2. data/.ace-defaults/git/worktree.yml +250 -0
  3. data/.ace-defaults/nav/protocols/wfi-sources/ace-git-worktree.yml +19 -0
  4. data/CHANGELOG.md +957 -0
  5. data/LICENSE +21 -0
  6. data/README.md +40 -0
  7. data/Rakefile +14 -0
  8. data/docs/demo/ace-git-worktree-getting-started.gif +0 -0
  9. data/docs/demo/ace-git-worktree-getting-started.tape.yml +28 -0
  10. data/docs/demo/fixtures/README.md +3 -0
  11. data/docs/demo/fixtures/sample.txt +1 -0
  12. data/docs/getting-started.md +114 -0
  13. data/docs/handbook.md +38 -0
  14. data/docs/usage.md +334 -0
  15. data/exe/ace-git-worktree +24 -0
  16. data/handbook/agents/worktree.ag.md +189 -0
  17. data/handbook/skills/as-git-worktree/SKILL.md +27 -0
  18. data/handbook/skills/as-git-worktree-create/SKILL.md +21 -0
  19. data/handbook/skills/as-git-worktree-manage/SKILL.md +20 -0
  20. data/handbook/workflow-instructions/git/worktree-create.wf.md +262 -0
  21. data/handbook/workflow-instructions/git/worktree-manage.wf.md +384 -0
  22. data/handbook/workflow-instructions/git/worktree.wf.md +224 -0
  23. data/lib/ace/git/worktree/atoms/git_command.rb +121 -0
  24. data/lib/ace/git/worktree/atoms/path_expander.rb +189 -0
  25. data/lib/ace/git/worktree/atoms/slug_generator.rb +235 -0
  26. data/lib/ace/git/worktree/atoms/task_id_extractor.rb +91 -0
  27. data/lib/ace/git/worktree/cli/commands/config.rb +50 -0
  28. data/lib/ace/git/worktree/cli/commands/create.rb +80 -0
  29. data/lib/ace/git/worktree/cli/commands/list.rb +76 -0
  30. data/lib/ace/git/worktree/cli/commands/prune.rb +43 -0
  31. data/lib/ace/git/worktree/cli/commands/remove.rb +48 -0
  32. data/lib/ace/git/worktree/cli/commands/shared_helpers.rb +66 -0
  33. data/lib/ace/git/worktree/cli/commands/switch.rb +44 -0
  34. data/lib/ace/git/worktree/cli.rb +103 -0
  35. data/lib/ace/git/worktree/commands/config_command.rb +351 -0
  36. data/lib/ace/git/worktree/commands/create_command.rb +961 -0
  37. data/lib/ace/git/worktree/commands/list_command.rb +247 -0
  38. data/lib/ace/git/worktree/commands/prune_command.rb +260 -0
  39. data/lib/ace/git/worktree/commands/remove_command.rb +522 -0
  40. data/lib/ace/git/worktree/commands/switch_command.rb +249 -0
  41. data/lib/ace/git/worktree/configuration.rb +167 -0
  42. data/lib/ace/git/worktree/models/worktree_config.rb +502 -0
  43. data/lib/ace/git/worktree/models/worktree_info.rb +303 -0
  44. data/lib/ace/git/worktree/models/worktree_metadata.rb +294 -0
  45. data/lib/ace/git/worktree/molecules/config_loader.rb +125 -0
  46. data/lib/ace/git/worktree/molecules/current_task_linker.rb +136 -0
  47. data/lib/ace/git/worktree/molecules/hook_executor.rb +361 -0
  48. data/lib/ace/git/worktree/molecules/parent_task_resolver.rb +186 -0
  49. data/lib/ace/git/worktree/molecules/pr_creator.rb +253 -0
  50. data/lib/ace/git/worktree/molecules/task_committer.rb +329 -0
  51. data/lib/ace/git/worktree/molecules/task_fetcher.rb +244 -0
  52. data/lib/ace/git/worktree/molecules/task_pusher.rb +183 -0
  53. data/lib/ace/git/worktree/molecules/task_status_updater.rb +447 -0
  54. data/lib/ace/git/worktree/molecules/worktree_creator.rb +832 -0
  55. data/lib/ace/git/worktree/molecules/worktree_lister.rb +337 -0
  56. data/lib/ace/git/worktree/molecules/worktree_remover.rb +416 -0
  57. data/lib/ace/git/worktree/organisms/task_worktree_orchestrator.rb +906 -0
  58. data/lib/ace/git/worktree/organisms/worktree_manager.rb +714 -0
  59. data/lib/ace/git/worktree/version.rb +9 -0
  60. data/lib/ace/git/worktree.rb +215 -0
  61. metadata +218 -0
@@ -0,0 +1,351 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ace
4
+ module Git
5
+ module Worktree
6
+ module Commands
7
+ # Config command
8
+ #
9
+ # Displays and validates worktree configuration.
10
+ # Shows current settings, configuration file locations, and validation results.
11
+ #
12
+ # @example Show current configuration
13
+ # ConfigCommand.new.run(["--show"])
14
+ #
15
+ # @example Validate configuration
16
+ # ConfigCommand.new.run(["--validate"])
17
+ class ConfigCommand
18
+ # Initialize a new ConfigCommand
19
+ def initialize
20
+ @manager = Organisms::WorktreeManager.new
21
+ end
22
+
23
+ # Run the config command
24
+ #
25
+ # @param args [Array<String>] Command arguments
26
+ # @return [Integer] Exit code (0 for success, 1 for error)
27
+ def run(args = [])
28
+ options = parse_arguments(args)
29
+ return show_help if options[:help]
30
+
31
+ # Default to showing configuration if no action specified
32
+ options[:show] = true unless options[:validate] || options[:show] || options[:files]
33
+
34
+ validate_options(options)
35
+
36
+ results = []
37
+
38
+ if options[:show]
39
+ results << show_configuration
40
+ end
41
+
42
+ if options[:validate]
43
+ results << validate_configuration
44
+ end
45
+
46
+ if options[:files]
47
+ results << show_configuration_files
48
+ end
49
+
50
+ # Return success if all operations succeeded
51
+ (results.all? { |result| result == 0 }) ? 0 : 1
52
+ rescue ArgumentError => e
53
+ puts "Error: #{e.message}"
54
+ puts
55
+ show_help
56
+ 1
57
+ rescue => e
58
+ puts "Error: #{e.message}"
59
+ 1
60
+ end
61
+
62
+ # Show help for the config command
63
+ #
64
+ # @return [Integer] Exit code
65
+ def show_help
66
+ puts <<~HELP
67
+ ace-git-worktree config - Manage worktree configuration
68
+
69
+ USAGE:
70
+ ace-git-worktree config [OPTIONS]
71
+
72
+ ACTIONS:
73
+ --show Show current configuration (default)
74
+ --validate Validate configuration
75
+ --files Show configuration file locations
76
+
77
+ OPTIONS:
78
+ --verbose, -v Show detailed information
79
+ --help, -h Show this help message
80
+
81
+ EXAMPLES:
82
+ # Show current configuration
83
+ ace-git-worktree config
84
+ ace-git-worktree config --show
85
+
86
+ # Validate configuration
87
+ ace-git-worktree config --validate
88
+
89
+ # Show configuration file locations
90
+ ace-git-worktree config --files
91
+
92
+ # Show everything
93
+ ace-git-worktree config --show --validate --files
94
+
95
+ CONFIGURATION FILES:
96
+ .ace/git/worktree.yml Project-specific configuration
97
+ .ace-defaults/git/worktree.yml Example configuration template
98
+ ~/.ace/git/worktree.yml User-specific configuration
99
+
100
+ CONFIGURATION OPTIONS:
101
+ git.worktree.root_path Worktree root directory
102
+ git.worktree.mise_trust_auto Automatic mise trust
103
+ git.worktree.task.* Task-related settings
104
+ git.worktree.cleanup.* Cleanup behavior settings
105
+
106
+ VALIDATION:
107
+ Checks for:
108
+ • Valid configuration structure
109
+ • Required configuration fields
110
+ • Accessible worktree root directory
111
+ • Valid template variables
112
+ • Consistent settings
113
+
114
+ For configuration examples, see .ace-defaults/git/worktree.yml
115
+ HELP
116
+ 0
117
+ end
118
+
119
+ private
120
+
121
+ # Parse command line arguments
122
+ #
123
+ # @param args [Array<String>] Command arguments
124
+ # @return [Hash] Parsed options
125
+ def parse_arguments(args)
126
+ options = {
127
+ show: false,
128
+ validate: false,
129
+ files: false,
130
+ verbose: false,
131
+ help: false
132
+ }
133
+
134
+ i = 0
135
+ while i < args.length
136
+ arg = args[i]
137
+
138
+ case arg
139
+ when "--show"
140
+ options[:show] = true
141
+ when "--validate"
142
+ options[:validate] = true
143
+ when "--files"
144
+ options[:files] = true
145
+ when "--verbose", "-v"
146
+ options[:verbose] = true
147
+ when "--help", "-h"
148
+ options[:help] = true
149
+ when /^--/
150
+ raise ArgumentError, "Unknown option: #{arg}"
151
+ else
152
+ # Accept subcommand arguments (show, validate) as aliases for flags
153
+ case arg
154
+ when "show"
155
+ options[:show] = true
156
+ when "validate"
157
+ options[:validate] = true
158
+ else
159
+ raise ArgumentError, "Unexpected argument: #{arg}"
160
+ end
161
+ end
162
+
163
+ i += 1
164
+ end
165
+
166
+ options
167
+ end
168
+
169
+ # Validate parsed options
170
+ #
171
+ # @param options [Hash] Parsed options
172
+ def validate_options(options)
173
+ # No specific validation needed for config command
174
+ end
175
+
176
+ # Show current configuration
177
+ #
178
+ # @return [Integer] Exit code
179
+ def show_configuration
180
+ puts "Current Worktree Configuration:"
181
+ puts "=" * 50
182
+
183
+ config = @manager.configuration
184
+
185
+ # Basic settings
186
+ puts "Root Path: #{config.root_path}"
187
+ puts "Absolute Root: #{config.absolute_root_path}"
188
+ puts "Mise Trust Auto: #{config.mise_trust_auto? ? "enabled" : "disabled"}"
189
+ puts
190
+
191
+ # Task settings
192
+ puts "Task Settings:"
193
+ puts " Directory Format: #{config.directory_format}"
194
+ puts " Branch Format: #{config.branch_format}"
195
+ puts " Auto Mark In Progress: #{config.auto_mark_in_progress? ? "enabled" : "disabled"}"
196
+ puts " Auto Commit Task: #{config.auto_commit_task? ? "enabled" : "disabled"}"
197
+ puts " Add Worktree Metadata: #{config.add_worktree_metadata? ? "enabled" : "disabled"}"
198
+ puts
199
+
200
+ if config.auto_commit_task?
201
+ puts "Commit Message Format:"
202
+ puts " #{config.commit_message_format}"
203
+ puts
204
+ end
205
+
206
+ # Cleanup settings
207
+ puts "Cleanup Settings:"
208
+ puts " On Merge: #{config.cleanup_on_merge? ? "enabled" : "disabled"}"
209
+ puts " On Delete: #{config.cleanup_on_delete? ? "enabled" : "disabled"}"
210
+ puts
211
+
212
+ # Template variables
213
+ puts "Available Template Variables:"
214
+ puts " {id} - Task numeric ID (e.g., 081)"
215
+ puts " {task_id} - Full task ID (e.g., task.081)"
216
+ puts " {slug} - URL-safe slug from task title"
217
+ puts
218
+
219
+ # Example usage
220
+ puts "Example Usage:"
221
+ task_id = "081"
222
+ task_slug = "fix-authentication-bug"
223
+ puts " Directory: #{config.directory_format.gsub("{id}", task_id).gsub("{slug}", task_slug)}"
224
+ puts " Branch: #{config.branch_format.gsub("{id}", task_id).gsub("{slug}", task_slug)}"
225
+ puts
226
+
227
+ 0
228
+ rescue => e
229
+ puts "Error showing configuration: #{e.message}"
230
+ 1
231
+ end
232
+
233
+ # Validate configuration
234
+ #
235
+ # @return [Integer] Exit code
236
+ def validate_configuration
237
+ puts "Configuration Validation:"
238
+ puts "=" * 30
239
+
240
+ result = @manager.validate_configuration
241
+
242
+ if result[:success]
243
+ puts "✅ Configuration is valid"
244
+ puts
245
+
246
+ if result[:errors].any?
247
+ puts "Warnings:"
248
+ result[:errors].each { |error| puts " ⚠️ #{error}" }
249
+ end
250
+ else
251
+ puts "❌ Configuration validation failed"
252
+ puts
253
+ puts "Errors:"
254
+ result[:errors].each { |error| puts " ❌ #{error}" }
255
+ puts
256
+
257
+ puts "Suggestions:"
258
+ puts " • Check .ace/git/worktree.yml for syntax errors"
259
+ puts " • Ensure all required fields are present"
260
+ puts " • Verify template variables are correct"
261
+ puts " • Check that worktree root directory is accessible"
262
+ puts " • See .ace-defaults/git/worktree.yml for examples"
263
+ puts
264
+
265
+ return 1
266
+ end
267
+
268
+ puts
269
+
270
+ 0
271
+ rescue => e
272
+ puts "Error validating configuration: #{e.message}"
273
+ 1
274
+ end
275
+
276
+ # Show configuration file locations
277
+ #
278
+ # @return [Integer] Exit code
279
+ def show_configuration_files
280
+ puts "Configuration Files:"
281
+ puts "=" * 20
282
+
283
+ # Get configuration files from config loader
284
+ config_loader = @manager.instance_variable_get(:@config_loader)
285
+ config_files = config_loader.config_files
286
+
287
+ config_files.each do |file|
288
+ if File.exist?(file)
289
+ puts "✅ #{file} (exists)"
290
+
291
+ # Show some info about the file
292
+ begin
293
+ stat = File.stat(file)
294
+ size = stat.size
295
+ mtime = stat.mtime.strftime("%Y-%m-%d %H:%M:%S")
296
+ puts " Size: #{format_bytes(size)}"
297
+ puts " Modified: #{mtime}"
298
+
299
+ # Check if it's the active config
300
+ if file.include?(".ace/git/worktree.yml")
301
+ puts " 📍 Active project configuration"
302
+ elsif file.include?(".ace-defaults/")
303
+ puts " 📋 Example template"
304
+ elsif file.include?("~/.ace/")
305
+ puts " 👤 User configuration"
306
+ end
307
+ rescue => e
308
+ puts " ⚠️ Error reading file info: #{e.message}"
309
+ end
310
+ else
311
+ puts "❌ #{file} (not found)"
312
+ end
313
+ puts
314
+ end
315
+
316
+ # Show configuration cascade order
317
+ puts "Configuration Priority (highest to lowest):"
318
+ puts " 1. .ace/git/worktree.yml (project-specific)"
319
+ puts " 2. ~/.ace/git/worktree.yml (user-specific)"
320
+ puts " 3. .ace-defaults/git/worktree.yml (defaults)"
321
+ puts
322
+ puts "Note: Later configurations override earlier ones."
323
+ puts
324
+
325
+ 0
326
+ rescue => e
327
+ puts "Error showing configuration files: #{e.message}"
328
+ 1
329
+ end
330
+
331
+ # Format bytes in human readable format
332
+ #
333
+ # @param bytes [Integer] Number of bytes
334
+ # @return [String] Formatted string
335
+ def format_bytes(bytes)
336
+ units = %w[B KB MB GB]
337
+ size = bytes.to_f
338
+ unit_index = 0
339
+
340
+ while size >= 1024 && unit_index < units.length - 1
341
+ size /= 1024
342
+ unit_index += 1
343
+ end
344
+
345
+ "#{size.round(1)} #{units[unit_index]}"
346
+ end
347
+ end
348
+ end
349
+ end
350
+ end
351
+ end