makit 0.0.98 → 0.0.111

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +41 -0
  3. data/exe/makit +5 -0
  4. data/lib/makit/apache.rb +7 -11
  5. data/lib/makit/cli/build_commands.rb +500 -0
  6. data/lib/makit/cli/generators/base_generator.rb +74 -0
  7. data/lib/makit/cli/generators/dotnet_generator.rb +50 -0
  8. data/lib/makit/cli/generators/generator_factory.rb +49 -0
  9. data/lib/makit/cli/generators/node_generator.rb +50 -0
  10. data/lib/makit/cli/generators/ruby_generator.rb +77 -0
  11. data/lib/makit/cli/generators/rust_generator.rb +50 -0
  12. data/lib/makit/cli/generators/templates/dotnet_templates.rb +167 -0
  13. data/lib/makit/cli/generators/templates/node_templates.rb +161 -0
  14. data/lib/makit/cli/generators/templates/ruby/gemfile.rb +26 -0
  15. data/lib/makit/cli/generators/templates/ruby/gemspec.rb +40 -0
  16. data/lib/makit/cli/generators/templates/ruby/main_lib.rb +33 -0
  17. data/lib/makit/cli/generators/templates/ruby/rakefile.rb +35 -0
  18. data/lib/makit/cli/generators/templates/ruby/readme.rb +63 -0
  19. data/lib/makit/cli/generators/templates/ruby/test.rb +39 -0
  20. data/lib/makit/cli/generators/templates/ruby/test_helper.rb +29 -0
  21. data/lib/makit/cli/generators/templates/ruby/version.rb +29 -0
  22. data/lib/makit/cli/generators/templates/rust_templates.rb +128 -0
  23. data/lib/makit/cli/main.rb +48 -19
  24. data/lib/makit/cli/project_commands.rb +868 -0
  25. data/lib/makit/cli/repository_commands.rb +661 -0
  26. data/lib/makit/cli/utility_commands.rb +521 -0
  27. data/lib/makit/command_runner.rb +187 -128
  28. data/lib/makit/commands/compatibility.rb +365 -0
  29. data/lib/makit/commands/factory.rb +359 -0
  30. data/lib/makit/commands/middleware/base.rb +73 -0
  31. data/lib/makit/commands/middleware/cache.rb +248 -0
  32. data/lib/makit/commands/middleware/command_logger.rb +323 -0
  33. data/lib/makit/commands/middleware/unified_logger.rb +243 -0
  34. data/lib/makit/commands/middleware/validator.rb +269 -0
  35. data/lib/makit/commands/request.rb +254 -0
  36. data/lib/makit/commands/result.rb +323 -0
  37. data/lib/makit/commands/runner.rb +317 -0
  38. data/lib/makit/commands/strategies/base.rb +160 -0
  39. data/lib/makit/commands/strategies/synchronous.rb +134 -0
  40. data/lib/makit/commands.rb +24 -3
  41. data/lib/makit/configuration/gitlab_helper.rb +60 -0
  42. data/lib/makit/configuration/project.rb +127 -0
  43. data/lib/makit/configuration/rakefile_helper.rb +43 -0
  44. data/lib/makit/configuration/step.rb +34 -0
  45. data/lib/makit/configuration.rb +14 -0
  46. data/lib/makit/content/default_gitignore.rb +4 -2
  47. data/lib/makit/content/default_rakefile.rb +4 -2
  48. data/lib/makit/content/gem_rakefile.rb +4 -2
  49. data/lib/makit/context.rb +1 -0
  50. data/lib/makit/data.rb +9 -10
  51. data/lib/makit/directories.rb +48 -52
  52. data/lib/makit/directory.rb +38 -52
  53. data/lib/makit/docs/files.rb +5 -10
  54. data/lib/makit/docs/rake.rb +16 -20
  55. data/lib/makit/dotnet/cli.rb +65 -0
  56. data/lib/makit/dotnet/project.rb +153 -0
  57. data/lib/makit/dotnet/solution.rb +38 -0
  58. data/lib/makit/dotnet/solution_classlib.rb +239 -0
  59. data/lib/makit/dotnet/solution_console.rb +264 -0
  60. data/lib/makit/dotnet/solution_maui.rb +354 -0
  61. data/lib/makit/dotnet/solution_wasm.rb +275 -0
  62. data/lib/makit/dotnet/solution_wpf.rb +304 -0
  63. data/lib/makit/dotnet.rb +54 -171
  64. data/lib/makit/email.rb +46 -17
  65. data/lib/makit/environment.rb +22 -19
  66. data/lib/makit/examples/runner.rb +370 -0
  67. data/lib/makit/exceptions.rb +45 -0
  68. data/lib/makit/fileinfo.rb +3 -5
  69. data/lib/makit/files.rb +12 -16
  70. data/lib/makit/gems.rb +40 -39
  71. data/lib/makit/git/cli.rb +54 -0
  72. data/lib/makit/git/repository.rb +90 -0
  73. data/lib/makit/git.rb +44 -91
  74. data/lib/makit/gitlab_runner.rb +0 -1
  75. data/lib/makit/humanize.rb +31 -23
  76. data/lib/makit/indexer.rb +15 -24
  77. data/lib/makit/logging/configuration.rb +305 -0
  78. data/lib/makit/logging/format_registry.rb +84 -0
  79. data/lib/makit/logging/formatters/base.rb +39 -0
  80. data/lib/makit/logging/formatters/console_formatter.rb +127 -0
  81. data/lib/makit/logging/formatters/json_formatter.rb +65 -0
  82. data/lib/makit/logging/formatters/plain_text_formatter.rb +71 -0
  83. data/lib/makit/logging/formatters/text_formatter.rb +64 -0
  84. data/lib/makit/logging/log_request.rb +115 -0
  85. data/lib/makit/logging/logger.rb +159 -0
  86. data/lib/makit/logging/sinks/base.rb +91 -0
  87. data/lib/makit/logging/sinks/console.rb +72 -0
  88. data/lib/makit/logging/sinks/file_sink.rb +92 -0
  89. data/lib/makit/logging/sinks/structured.rb +129 -0
  90. data/lib/makit/logging/sinks/unified_file_sink.rb +303 -0
  91. data/lib/makit/logging.rb +452 -37
  92. data/lib/makit/markdown.rb +18 -18
  93. data/lib/makit/mp/basic_object_mp.rb +5 -4
  94. data/lib/makit/mp/command_mp.rb +5 -5
  95. data/lib/makit/mp/command_request.mp.rb +3 -2
  96. data/lib/makit/mp/project_mp.rb +85 -96
  97. data/lib/makit/mp/string_mp.rb +245 -73
  98. data/lib/makit/nuget.rb +27 -25
  99. data/lib/makit/port.rb +25 -27
  100. data/lib/makit/process.rb +127 -29
  101. data/lib/makit/protoc.rb +27 -24
  102. data/lib/makit/rake/cli.rb +196 -0
  103. data/lib/makit/rake.rb +6 -6
  104. data/lib/makit/ruby/cli.rb +185 -0
  105. data/lib/makit/ruby.rb +25 -0
  106. data/lib/makit/secrets.rb +18 -18
  107. data/lib/makit/serializer.rb +29 -27
  108. data/lib/makit/services/builder.rb +186 -0
  109. data/lib/makit/services/error_handler.rb +226 -0
  110. data/lib/makit/services/repository_manager.rb +229 -0
  111. data/lib/makit/services/validator.rb +112 -0
  112. data/lib/makit/setup/classlib.rb +53 -0
  113. data/lib/makit/setup/gem.rb +250 -0
  114. data/lib/makit/setup/runner.rb +40 -0
  115. data/lib/makit/show.rb +16 -16
  116. data/lib/makit/storage.rb +32 -37
  117. data/lib/makit/symbols.rb +12 -0
  118. data/lib/makit/task_hooks.rb +125 -0
  119. data/lib/makit/task_info.rb +63 -21
  120. data/lib/makit/tasks/at_exit.rb +13 -0
  121. data/lib/makit/tasks/build.rb +18 -0
  122. data/lib/makit/tasks/clean.rb +11 -0
  123. data/lib/makit/tasks/hook_manager.rb +239 -0
  124. data/lib/makit/tasks/init.rb +47 -0
  125. data/lib/makit/tasks/integrate.rb +15 -0
  126. data/lib/makit/tasks/pull_incoming.rb +12 -0
  127. data/lib/makit/tasks/setup.rb +6 -0
  128. data/lib/makit/tasks/sync.rb +11 -0
  129. data/lib/makit/tasks/task_monkey_patch.rb +79 -0
  130. data/lib/makit/tasks.rb +5 -150
  131. data/lib/makit/test_cache.rb +239 -0
  132. data/lib/makit/v1/makit.v1_pb.rb +34 -35
  133. data/lib/makit/v1/makit.v1_services_pb.rb +2 -0
  134. data/lib/makit/version.rb +1 -60
  135. data/lib/makit/wix.rb +23 -23
  136. data/lib/makit/yaml.rb +18 -6
  137. data/lib/makit.rb +2 -261
  138. metadata +109 -145
  139. data/lib/makit/cli/clean.rb +0 -14
  140. data/lib/makit/cli/clone.rb +0 -59
  141. data/lib/makit/cli/init.rb +0 -38
  142. data/lib/makit/cli/make.rb +0 -54
  143. data/lib/makit/cli/new.rb +0 -37
  144. data/lib/makit/cli/nuget_cache.rb +0 -38
  145. data/lib/makit/cli/pull.rb +0 -31
  146. data/lib/makit/cli/setup.rb +0 -71
  147. data/lib/makit/cli/work.rb +0 -21
  148. data/lib/makit/content/default_gitignore.txt +0 -222
@@ -0,0 +1,365 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+ require "fileutils"
5
+ require_relative "runner"
6
+ require_relative "request"
7
+ require_relative "result"
8
+
9
+ module Makit
10
+ module Commands
11
+ # Compatibility layer that provides legacy interface methods for the new Commands::Runner
12
+ #
13
+ # This class bridges the gap between the old CommandRunner interface and the new
14
+ # Commands::Runner architecture, allowing existing code to work without modification
15
+ # while benefiting from the improved architecture.
16
+ class Compatibility
17
+ # @!attribute [r] runner
18
+ # @return [Runner] the underlying Commands::Runner instance
19
+ attr_reader :runner
20
+
21
+ # Initialize compatibility layer
22
+ #
23
+ # @param runner [Runner] the Commands::Runner instance to wrap
24
+ def initialize(runner = nil)
25
+ @runner = runner || create_runner_with_caching
26
+ end
27
+
28
+ # Parse command request from various input types (legacy interface)
29
+ #
30
+ # @param source [String, Hash, Request] command source
31
+ # @return [Request] normalized request
32
+ def parse_command_request(source)
33
+ case source
34
+ when String
35
+ Request.from_string(source)
36
+ when Hash
37
+ Request.from_hash(source)
38
+ when Request
39
+ source
40
+ when Makit::V1::CommandRequest
41
+ # Convert legacy CommandRequest to new Request
42
+ Request.new(
43
+ command: source.name,
44
+ arguments: source.arguments.to_a,
45
+ directory: source.directory,
46
+ timeout: source.timeout,
47
+ environment: {},
48
+ metadata: { legacy: true },
49
+ )
50
+ else
51
+ raise ArgumentError, "Invalid source type: #{source.class}"
52
+ end
53
+ end
54
+
55
+ # Parse arguments (legacy interface)
56
+ #
57
+ # @param args [String, Array, Hash, Request] arguments to parse
58
+ # @return [Request] parsed request
59
+ def parse_args(args)
60
+ parse_command_request(args)
61
+ end
62
+
63
+ # Execute command (legacy run interface)
64
+ #
65
+ # @param request_or_string [Request, String, Hash] command to run
66
+ # @return [Result] execution result converted to legacy format
67
+ def run(request_or_string)
68
+ request = parse_command_request(request_or_string)
69
+ result = @runner.execute(request)
70
+ # Store directory in result metadata for legacy compatibility
71
+ result.metadata[:directory] = request.directory
72
+ convert_to_legacy_command(result)
73
+ end
74
+
75
+ # Execute command with caching (legacy cache_run interface)
76
+ #
77
+ # @param request_or_string [Request, String, Hash] command to run
78
+ # @param timestamp [Time, nil] cache timestamp
79
+ # @return [Result] execution result converted to legacy format
80
+ def cache_run(request_or_string, timestamp = nil)
81
+ request = parse_command_request(request_or_string)
82
+
83
+ # Add cache metadata
84
+ cache_key = generate_cache_key(request)
85
+ request.metadata[:cache_key] = cache_key
86
+ request.metadata[:cache_timestamp] = timestamp || default_timestamp
87
+
88
+ # Execute with caching middleware
89
+ result = @runner.execute(request)
90
+ # Store directory in result metadata for legacy compatibility
91
+ result.metadata[:directory] = request.directory
92
+ convert_to_legacy_command(result)
93
+ end
94
+
95
+ # Execute command with caching without raising on error (legacy cache_try interface)
96
+ #
97
+ # @param request_or_string [Request, String, Hash] command to try
98
+ # @param timestamp [Time, nil] cache timestamp
99
+ # @return [Result] execution result converted to legacy format
100
+ def cache_try(request_or_string, timestamp = nil)
101
+ request = parse_command_request(request_or_string)
102
+ request.metadata[:exit_on_error] = false
103
+
104
+ # Add cache metadata
105
+ cache_key = generate_cache_key(request)
106
+ request.metadata[:cache_key] = cache_key
107
+ request.metadata[:cache_timestamp] = timestamp || default_timestamp
108
+
109
+ # Execute with caching middleware
110
+ result = @runner.execute(request)
111
+ # Store directory in result metadata for legacy compatibility
112
+ result.metadata[:directory] = request.directory
113
+ convert_to_legacy_command(result)
114
+ end
115
+
116
+ # Execute command without raising on error (legacy try interface)
117
+ #
118
+ # @param request_or_string [Request, String, Hash] command to try
119
+ # @return [Result] execution result converted to legacy format
120
+ def try(request_or_string)
121
+ request = parse_command_request(request_or_string)
122
+ request.metadata[:exit_on_error] = false
123
+
124
+ result = @runner.execute(request)
125
+ # Store directory in result metadata for legacy compatibility
126
+ result.metadata[:directory] = request.directory
127
+ convert_to_legacy_command(result)
128
+ end
129
+
130
+ # Show command information (legacy show interface)
131
+ #
132
+ # @param request_or_string [Request, String, Hash] command to show
133
+ # @return [Result] execution result converted to legacy format
134
+ def show(request_or_string)
135
+ request = parse_command_request(request_or_string)
136
+ request.metadata[:show_output] = true
137
+
138
+ result = @runner.execute(request)
139
+ # Store directory in result metadata for legacy compatibility
140
+ result.metadata[:directory] = request.directory
141
+ show_command(convert_to_legacy_command(result))
142
+ convert_to_legacy_command(result)
143
+ end
144
+
145
+ # Search command history for matching commands (legacy interface)
146
+ #
147
+ # @param query [String] search query
148
+ # @return [Array<Object>] matching command results
149
+ def search(query)
150
+ # For now, return empty array since we don't have command history in new architecture
151
+ # This could be enhanced with a command history middleware
152
+ []
153
+ end
154
+
155
+ # Get cache filename for a command (legacy interface)
156
+ #
157
+ # @param command [Object] command object
158
+ # @return [String] cache filename
159
+ def get_cache_filename(command)
160
+ require "digest"
161
+ if command.respond_to?(:name) && command.respond_to?(:arguments)
162
+ content = "#{command.name} #{command.arguments.join(" ")}"
163
+ else
164
+ content = command.to_s
165
+ end
166
+ hash = Digest::SHA256.hexdigest(content)
167
+ cache_dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands", "cache")
168
+ FileUtils.mkdir_p(cache_dir)
169
+ File.join(cache_dir, "#{hash}.pb")
170
+ end
171
+
172
+ # Log rake commands to file (legacy interface)
173
+ #
174
+ # @return [void]
175
+ def log_rake_commands
176
+ dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
177
+ FileUtils.mkdir_p(dir)
178
+
179
+ # For now, create empty file since we don't have command history
180
+ # This could be enhanced with a command history middleware
181
+ File.open(File.join(dir, "rake.commands.txt"), "w") do |file|
182
+ file.puts "# No command history available in new architecture"
183
+ file.puts "# This functionality will be restored with command history middleware"
184
+ end
185
+ end
186
+
187
+ # Log slowest commands to file (legacy interface)
188
+ #
189
+ # @return [void]
190
+ def log_slowest_commands
191
+ dir = File.join(Makit::Directories::PROJECT_ARTIFACTS, "commands")
192
+ FileUtils.mkdir_p(dir)
193
+
194
+ # For now, create empty file since we don't have command history
195
+ # This could be enhanced with a command history middleware
196
+ File.open(File.join(dir, "slow.commands.txt"), "w") do |file|
197
+ file.puts "# No command history available in new architecture"
198
+ file.puts "# This functionality will be restored with command history middleware"
199
+ end
200
+ end
201
+
202
+ # Display command summary (legacy show_command interface)
203
+ #
204
+ # @param command [Makit::V1::Command, Result] command result to display
205
+ def show_command(command)
206
+ # Convert new Result to legacy format if needed
207
+ legacy_command = command.is_a?(Result) ? convert_to_legacy_command(command) : command
208
+
209
+ if legacy_command.exit_code.zero?
210
+ puts get_command_summary(legacy_command) + " (#{legacy_command.duration&.seconds || 0} seconds)".colorize(:cyan)
211
+ puts indent_string(legacy_command.output, 2).colorize(:default) if should_show_output_on_success?
212
+ else
213
+ puts get_command_summary(legacy_command) + " (exit code #{legacy_command.exit_code})".colorize(:default)
214
+ puts " directory: #{legacy_command.directory}\n"
215
+ puts " duration: #{legacy_command.duration&.seconds || 0} seconds\n"
216
+ puts indent_string(legacy_command.output, 2) if legacy_command.output&.length&.positive?
217
+ puts indent_string(legacy_command.error, 2) if legacy_command.error&.length&.positive?
218
+ end
219
+ end
220
+
221
+ private
222
+
223
+ # Create a runner with caching middleware
224
+ #
225
+ # @return [Runner] runner with caching middleware
226
+ def create_runner_with_caching
227
+ require_relative "middleware/cache"
228
+
229
+ Runner.new(
230
+ middleware: [
231
+ Middleware::Cache.new,
232
+ Middleware::CommandLogger.new(
233
+ log_stdout: true,
234
+ log_stderr: true,
235
+ log_performance: true,
236
+ max_output_lines: 50,
237
+ ),
238
+ ],
239
+ )
240
+ end
241
+
242
+ # Convert new Result to legacy Makit::V1::Command format
243
+ #
244
+ # @param result [Result] result to convert
245
+ # @return [Makit::V1::Command] legacy command object
246
+ def convert_to_legacy_command(result)
247
+ # Create a legacy command object that duck-types with Makit::V1::Command
248
+ legacy_command = OpenStruct.new
249
+ legacy_command.name = result.command.split.first
250
+ legacy_command.arguments = result.command.split[1..] || []
251
+ # Get directory from metadata if available, otherwise use current directory
252
+ legacy_command.directory = result.metadata[:directory] || Dir.pwd
253
+ legacy_command.exit_code = result.exit_code
254
+ legacy_command.output = result.stdout
255
+ legacy_command.error = result.stderr
256
+ legacy_command.started_at = convert_time_to_protobuf_timestamp(result.started_at)
257
+ legacy_command.duration = convert_duration_to_protobuf(result.duration)
258
+
259
+ # Add success? method for compatibility
260
+ def legacy_command.success?
261
+ exit_code.zero?
262
+ end
263
+
264
+ legacy_command
265
+ end
266
+
267
+ # Generate cache key for a request
268
+ #
269
+ # @param request [Request] request to generate key for
270
+ # @return [String] cache key
271
+ def generate_cache_key(request)
272
+ require "digest"
273
+ content = "#{request.command} #{request.arguments.join(" ")}"
274
+ Digest::SHA256.hexdigest(content)
275
+ end
276
+
277
+ # Get default timestamp for caching
278
+ #
279
+ # @return [Time] default timestamp
280
+ def default_timestamp
281
+ if defined?(Makit::GIT_FILE_INFOS) && Makit::GIT_FILE_INFOS.any?
282
+ Makit::GIT_FILE_INFOS.first.mtime
283
+ else
284
+ Time.now
285
+ end
286
+ end
287
+
288
+ # Get command summary string (legacy interface)
289
+ #
290
+ # @param command [Object] command object
291
+ # @return [String] command summary
292
+ def get_command_summary(command)
293
+ symbol = "⚠️" # warning by default
294
+ symbol = "✓" if command.exit_code&.zero?
295
+ symbol = "✗" if command.exit_code != 0
296
+
297
+ summary = "#{symbol} #{command.name} #{command.arguments.join(" ")}"
298
+
299
+ # Apply line wrapping if available
300
+ if summary.respond_to?(:to_lines) && summary.length > 80
301
+ summary.to_lines(80, command.name.length + 3)
302
+ else
303
+ summary
304
+ end
305
+ end
306
+
307
+ # Indent string helper
308
+ #
309
+ # @param input_string [String] string to indent
310
+ # @param indent_spaces [Integer] number of spaces to indent
311
+ # @return [String] indented string
312
+ def indent_string(input_string, indent_spaces)
313
+ return "" unless input_string
314
+
315
+ indentation = " " * indent_spaces
316
+ input_string.lines.map { |line| indentation + line }.join
317
+ end
318
+
319
+ # Check if output should be shown on success
320
+ #
321
+ # @return [Boolean] true if output should be shown
322
+ def should_show_output_on_success?
323
+ # Check if the legacy runner has this setting
324
+ if defined?(Makit::RUNNER) && Makit::RUNNER.respond_to?(:show_output_on_success)
325
+ Makit::RUNNER.show_output_on_success
326
+ else
327
+ false
328
+ end
329
+ end
330
+
331
+ # Convert Time to protobuf timestamp format
332
+ #
333
+ # @param time [Time] time to convert
334
+ # @return [Google::Protobuf::Timestamp] protobuf timestamp
335
+ def convert_time_to_protobuf_timestamp(time)
336
+ return nil unless time
337
+
338
+ if defined?(Google::Protobuf::Timestamp)
339
+ Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
340
+ else
341
+ # Fallback object with same interface
342
+ OpenStruct.new(seconds: time.to_i, nanos: time.nsec)
343
+ end
344
+ end
345
+
346
+ # Convert duration to protobuf duration format
347
+ #
348
+ # @param duration [Float] duration in seconds
349
+ # @return [Google::Protobuf::Duration] protobuf duration
350
+ def convert_duration_to_protobuf(duration)
351
+ return nil unless duration
352
+
353
+ seconds = duration.to_i
354
+ nanos = ((duration - seconds) * 1_000_000_000).to_i
355
+
356
+ if defined?(Google::Protobuf::Duration)
357
+ Google::Protobuf::Duration.new(seconds: seconds, nanos: nanos)
358
+ else
359
+ # Fallback object with same interface
360
+ OpenStruct.new(seconds: seconds, nanos: nanos)
361
+ end
362
+ end
363
+ end
364
+ end
365
+ end