cmdx 0.5.0 → 1.0.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.cursor/rules/cursor-instructions.mdc +6 -0
  4. data/.rubocop.yml +19 -1
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +95 -28
  7. data/README.md +73 -25
  8. data/docs/ai_prompts.md +319 -0
  9. data/docs/basics/call.md +234 -14
  10. data/docs/basics/chain.md +280 -0
  11. data/docs/basics/context.md +241 -33
  12. data/docs/basics/setup.md +85 -12
  13. data/docs/callbacks.md +283 -0
  14. data/docs/configuration.md +155 -30
  15. data/docs/getting_started.md +145 -22
  16. data/docs/internationalization.md +148 -0
  17. data/docs/interruptions/exceptions.md +198 -11
  18. data/docs/interruptions/faults.md +196 -44
  19. data/docs/interruptions/halt.md +188 -35
  20. data/docs/logging.md +204 -53
  21. data/docs/middlewares.md +745 -0
  22. data/docs/outcomes/result.md +305 -10
  23. data/docs/outcomes/states.md +212 -31
  24. data/docs/outcomes/statuses.md +284 -30
  25. data/docs/parameters/coercions.md +411 -29
  26. data/docs/parameters/defaults.md +258 -25
  27. data/docs/parameters/definitions.md +247 -72
  28. data/docs/parameters/namespacing.md +259 -27
  29. data/docs/parameters/validations.md +173 -168
  30. data/docs/testing.md +560 -0
  31. data/docs/tips_and_tricks.md +103 -42
  32. data/docs/workflows.md +329 -0
  33. data/lib/cmdx/.DS_Store +0 -0
  34. data/lib/cmdx/callback.rb +69 -0
  35. data/lib/cmdx/callback_registry.rb +106 -0
  36. data/lib/cmdx/chain.rb +190 -0
  37. data/lib/cmdx/chain_inspector.rb +149 -0
  38. data/lib/cmdx/chain_serializer.rb +175 -0
  39. data/lib/cmdx/coercions/array.rb +37 -0
  40. data/lib/cmdx/coercions/big_decimal.rb +33 -0
  41. data/lib/cmdx/coercions/boolean.rb +41 -1
  42. data/lib/cmdx/coercions/complex.rb +31 -0
  43. data/lib/cmdx/coercions/date.rb +39 -0
  44. data/lib/cmdx/coercions/date_time.rb +39 -0
  45. data/lib/cmdx/coercions/float.rb +31 -0
  46. data/lib/cmdx/coercions/hash.rb +42 -0
  47. data/lib/cmdx/coercions/integer.rb +32 -0
  48. data/lib/cmdx/coercions/rational.rb +31 -0
  49. data/lib/cmdx/coercions/string.rb +31 -0
  50. data/lib/cmdx/coercions/time.rb +39 -0
  51. data/lib/cmdx/coercions/virtual.rb +31 -0
  52. data/lib/cmdx/configuration.rb +217 -9
  53. data/lib/cmdx/context.rb +173 -2
  54. data/lib/cmdx/core_ext/hash.rb +72 -0
  55. data/lib/cmdx/core_ext/module.rb +94 -0
  56. data/lib/cmdx/core_ext/object.rb +105 -0
  57. data/lib/cmdx/correlator.rb +217 -0
  58. data/lib/cmdx/error.rb +210 -8
  59. data/lib/cmdx/errors.rb +256 -1
  60. data/lib/cmdx/fault.rb +177 -2
  61. data/lib/cmdx/faults.rb +158 -2
  62. data/lib/cmdx/immutator.rb +121 -2
  63. data/lib/cmdx/lazy_struct.rb +261 -18
  64. data/lib/cmdx/log_formatters/json.rb +46 -0
  65. data/lib/cmdx/log_formatters/key_value.rb +46 -0
  66. data/lib/cmdx/log_formatters/line.rb +54 -0
  67. data/lib/cmdx/log_formatters/logstash.rb +64 -0
  68. data/lib/cmdx/log_formatters/pretty_json.rb +57 -0
  69. data/lib/cmdx/log_formatters/pretty_key_value.rb +51 -0
  70. data/lib/cmdx/log_formatters/pretty_line.rb +60 -0
  71. data/lib/cmdx/log_formatters/raw.rb +54 -0
  72. data/lib/cmdx/logger.rb +85 -0
  73. data/lib/cmdx/logger_ansi.rb +93 -7
  74. data/lib/cmdx/logger_serializer.rb +116 -0
  75. data/lib/cmdx/middleware.rb +74 -0
  76. data/lib/cmdx/middleware_registry.rb +106 -0
  77. data/lib/cmdx/middlewares/correlate.rb +266 -0
  78. data/lib/cmdx/middlewares/timeout.rb +232 -0
  79. data/lib/cmdx/parameter.rb +228 -1
  80. data/lib/cmdx/parameter_inspector.rb +61 -0
  81. data/lib/cmdx/parameter_registry.rb +125 -0
  82. data/lib/cmdx/parameter_serializer.rb +83 -0
  83. data/lib/cmdx/parameter_validator.rb +62 -0
  84. data/lib/cmdx/parameter_value.rb +109 -1
  85. data/lib/cmdx/parameters_inspector.rb +59 -0
  86. data/lib/cmdx/parameters_serializer.rb +102 -0
  87. data/lib/cmdx/railtie.rb +123 -3
  88. data/lib/cmdx/result.rb +367 -25
  89. data/lib/cmdx/result_ansi.rb +105 -9
  90. data/lib/cmdx/result_inspector.rb +76 -0
  91. data/lib/cmdx/result_logger.rb +90 -3
  92. data/lib/cmdx/result_serializer.rb +137 -0
  93. data/lib/cmdx/rspec/result_matchers.rb +917 -0
  94. data/lib/cmdx/rspec/task_matchers.rb +570 -0
  95. data/lib/cmdx/task.rb +405 -37
  96. data/lib/cmdx/task_serializer.rb +74 -2
  97. data/lib/cmdx/utils/ansi_color.rb +95 -0
  98. data/lib/cmdx/utils/log_timestamp.rb +48 -0
  99. data/lib/cmdx/utils/monotonic_runtime.rb +71 -4
  100. data/lib/cmdx/utils/name_affix.rb +78 -0
  101. data/lib/cmdx/validators/custom.rb +82 -0
  102. data/lib/cmdx/validators/exclusion.rb +94 -0
  103. data/lib/cmdx/validators/format.rb +102 -8
  104. data/lib/cmdx/validators/inclusion.rb +104 -0
  105. data/lib/cmdx/validators/length.rb +128 -0
  106. data/lib/cmdx/validators/numeric.rb +128 -0
  107. data/lib/cmdx/validators/presence.rb +93 -7
  108. data/lib/cmdx/version.rb +7 -1
  109. data/lib/cmdx/workflow.rb +394 -0
  110. data/lib/cmdx.rb +25 -64
  111. data/lib/generators/cmdx/install_generator.rb +37 -1
  112. data/lib/generators/cmdx/task_generator.rb +69 -1
  113. data/lib/generators/cmdx/templates/install.rb +43 -15
  114. data/lib/generators/cmdx/workflow_generator.rb +109 -0
  115. data/lib/locales/ar.yml +36 -0
  116. data/lib/locales/cs.yml +36 -0
  117. data/lib/locales/da.yml +36 -0
  118. data/lib/locales/de.yml +36 -0
  119. data/lib/locales/el.yml +36 -0
  120. data/lib/locales/en.yml +20 -20
  121. data/lib/locales/es.yml +20 -20
  122. data/lib/locales/fi.yml +36 -0
  123. data/lib/locales/fr.yml +36 -0
  124. data/lib/locales/he.yml +36 -0
  125. data/lib/locales/hi.yml +36 -0
  126. data/lib/locales/it.yml +36 -0
  127. data/lib/locales/ja.yml +36 -0
  128. data/lib/locales/ko.yml +36 -0
  129. data/lib/locales/nl.yml +36 -0
  130. data/lib/locales/no.yml +36 -0
  131. data/lib/locales/pl.yml +36 -0
  132. data/lib/locales/pt.yml +36 -0
  133. data/lib/locales/ru.yml +36 -0
  134. data/lib/locales/sv.yml +36 -0
  135. data/lib/locales/th.yml +36 -0
  136. data/lib/locales/tr.yml +36 -0
  137. data/lib/locales/vi.yml +36 -0
  138. data/lib/locales/zh.yml +36 -0
  139. metadata +77 -15
  140. data/docs/basics/run.md +0 -34
  141. data/docs/batch.md +0 -53
  142. data/docs/example.md +0 -82
  143. data/docs/hooks.md +0 -62
  144. data/lib/cmdx/batch.rb +0 -43
  145. data/lib/cmdx/parameters.rb +0 -35
  146. data/lib/cmdx/run.rb +0 -39
  147. data/lib/cmdx/run_inspector.rb +0 -26
  148. data/lib/cmdx/run_serializer.rb +0 -20
  149. data/lib/cmdx/task_hook.rb +0 -18
  150. data/lib/generators/cmdx/batch_generator.rb +0 -30
  151. /data/lib/generators/cmdx/templates/{batch.rb.tt → workflow.rb.tt} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4564456f58ece0df7606a6eee705e3ed5225b66e8cb1b3feae426ae990204fe4
4
- data.tar.gz: 412ffb7cfdfbbd71da1c34f2a8bb871f9d9c67b7ef89ab7453af969c4bf6340b
3
+ metadata.gz: c2d77bd913e65961bafa2851e2148df1daed63bd7047f512f53f10b9ec07b700
4
+ data.tar.gz: 7d86f82f6334bb4538fdbbaeafa60185de6cd55535e192832ccb8c40164996dd
5
5
  SHA512:
6
- metadata.gz: 9f416759468491771ec5c1ae8985ceef482287680cd494fc4747adea90a570d894a9725958ffd08167cd9c68e59311ea2f4080997ea1e1edf58db12433fad036
7
- data.tar.gz: 6e0c6a16bfede183fb61633f55e5bd53bed529b75a2d3fcdbb763885f28d2a614c94abc0cabb178c5743bef99e404648f126c31b0378a0b7da5125d2d8b888a1
6
+ metadata.gz: 4802141926139cf972a9869884fe59cddfca218a6ac8a54791e4a575ecef9f9b59039a71147097e5758e6171ef600c2d005110fc84bc27e5dd26f4930541b32d
7
+ data.tar.gz: b9eb23fd437ffc81ea9441273bf5602220167368af96d2190e9f2623d33eee7cf48af8c9fbfa947f802db0d378eb93f9661de04d8477759f312bf7bb0c9c1054
data/.DS_Store CHANGED
Binary file
@@ -0,0 +1,6 @@
1
+ ---
2
+ description:
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+ Use instructions found in [copilot-instructions.md](mdc:.github/copilot-instructions.md)
data/.rubocop.yml CHANGED
@@ -6,7 +6,6 @@ AllCops:
6
6
  NewCops: enable
7
7
  DisplayCopNames: true
8
8
  DisplayStyleGuide: true
9
- TargetRubyVersion: 3.1.0
10
9
  Gemspec/DevelopmentDependencies:
11
10
  EnforcedStyle: gemspec
12
11
  Layout/EmptyLinesAroundAttributeAccessor:
@@ -15,12 +14,20 @@ Layout/EmptyLinesAroundClassBody:
15
14
  EnforcedStyle: empty_lines_except_namespace
16
15
  Layout/EmptyLinesAroundModuleBody:
17
16
  EnforcedStyle: empty_lines_except_namespace
17
+ Layout/ExtraSpacing:
18
+ Exclude:
19
+ - 'lib/generators/cmdx/templates/install.rb'
18
20
  Layout/LineLength:
19
21
  Enabled: false
22
+ Lint/MissingSuper:
23
+ Exclude:
24
+ - 'lib/cmdx/middlewares/**/*'
25
+ - 'spec/**/**/*'
20
26
  Metrics/AbcSize:
21
27
  Enabled: false
22
28
  Metrics/BlockLength:
23
29
  Exclude:
30
+ - 'lib/cmdx/rspec/**/*'
24
31
  - 'spec/**/**/*'
25
32
  - '*.gemspec'
26
33
  Metrics/ClassLength:
@@ -37,8 +44,15 @@ Naming/MethodParameterName:
37
44
  Enabled: false
38
45
  RSpec/AnyInstance:
39
46
  Enabled: false
47
+ RSpec/DescribeClass:
48
+ Exclude:
49
+ - 'spec/integrations/**/*'
40
50
  RSpec/ExampleLength:
41
51
  Enabled: false
52
+ RSpec/MessageSpies:
53
+ Enabled: false
54
+ RSpec/MultipleMemoizedHelpers:
55
+ Enabled: false
42
56
  RSpec/MultipleExpectations:
43
57
  Enabled: false
44
58
  RSpec/NestedGroups:
@@ -46,6 +60,10 @@ RSpec/NestedGroups:
46
60
  RSpec/SpecFilePathFormat:
47
61
  CustomTransform:
48
62
  CMDx: cmdx
63
+ RSpec/StubbedMock:
64
+ Enabled: false
65
+ RSpec/VerifiedDoubles:
66
+ Enabled: false
49
67
  RSpec/VerifiedDoubleReference:
50
68
  Enabled: false
51
69
  Style/Documentation:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.4.2
1
+ 3.4.4
data/CHANGELOG.md CHANGED
@@ -1,51 +1,118 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [TODO]
9
+
10
+ - Add table and pretty_table log formatters
11
+ - Add method and proc style validations
12
+ - Refactor parameter modules and classes for more robust usages
13
+
1
14
  ## [Unreleased]
2
15
 
16
+ ## [1.0.1] - 2025-07-07
17
+
18
+ ### Added
19
+ - Added comprehensive internationalization support with 24 language locales
20
+ - Arabic, Chinese, Czech, Danish, Dutch, English, Finnish, French, German, Greek
21
+ - Hebrew, Hindi, Italian, Japanese, Korean, Norwegian, Polish, Portuguese
22
+ - Russian, Spanish, Swedish, Thai, Turkish, Vietnamese
23
+ - Added TLDR sections to documentation for improved accessibility
24
+
25
+ ### Changed
26
+ - Improved configuration template with better defaults and examples
27
+
28
+ ## [1.0.0] - 2025-07-03
29
+
30
+ ### Added
31
+ - Added `Hook` class for flexible callback management
32
+ - Added `perform!` and `perform` method aliases for class-level `call!` and `call` methods
33
+ - Added comprehensive YARDoc documentation throughout codebase
34
+ - Added configuration-based hook registration system
35
+ - Added Cursor and GitHub Copilot configuration files for enhanced IDE support
36
+ - Added middleware support for tasks enabling extensible request/response processing
37
+ - Added pattern matching support for result objects
38
+ - Added support for direct instantiation of Task and Workflow objects
39
+ - Added Zeitwerk-based gem loading for improved performance and reliability
40
+
41
+ ### Changed
42
+ - Changed `ArgumentError` to `TypeError` for type validation consistency
43
+ - Changed configuration from hash-based to PORO (Plain Old Ruby Object) class structure
44
+ - Improved documentation readability, consistency, and completeness
45
+ - Improved test suite readability, consistency, and coverage
46
+ - Renamed `Batch` to `Workflow` to better reflect functionality
47
+ - Renamed `Hook` to `Callback` for naming consistency
48
+ - Renamed `Parameters` to `ParameterRegistry` for clarity
49
+ - Renamed `Run` and associated components to `Chain` for better semantic meaning
50
+ - Updated `Chain` to use thread-based execution instead of context passing
51
+ - Updated `Immutator` to use `SKIP_CMDX_FREEZING` environment variable instead of `RACK_ENV`/`RAILS_ENV`
52
+ - Updated hooks from a hash structure to registry pattern
53
+
54
+ ### Removed
55
+ - Removed deprecated `task_timeout` and `batch_timeout` configuration settings
56
+
3
57
  ## [0.5.0] - 2025-03-21
4
58
 
5
59
  ### Added
6
- - Add `to_a` alias on array of hashes serializers
7
- - Add `state`, `status`, `outcome`, and `runtime` to run serializer
8
- - Add `on_[state]` and `on_[status]` based result callback handlers
9
- - Add `on_executed` state task hook
10
- - Add `on_good` and `on_bad` status task hook
60
+ - Added `on_[state]` and `on_[status]` based result callback handlers
61
+ - Added `on_executed` state hook for task completion tracking
62
+ - Added `on_good` and `on_bad` status hooks for success/failure handling
63
+ - Added `state`, `status`, `outcome`, and `runtime` fields to run serializer
64
+ - Added `to_a` alias for array of hashes serializers
65
+
11
66
  ### Changed
12
- - Changed status and state hook order
67
+ - Reordered status and state hook execution for more predictable behavior
13
68
 
14
69
  ## [0.4.0] - 2025-03-17
15
70
 
16
71
  ### Added
17
- - Add ansi util
18
- - Add string to json parsing in hash coercion
19
- - Add string to json parsing in array coercion
72
+ - Added ANSI color utility for enhanced terminal output
73
+ - Added JSON string parsing support in array coercion
74
+ - Added JSON string parsing support in hash coercion
75
+
20
76
  ### Changed
21
- - Skip assigning log settings if logger is nil
22
- - Improve ANSI escape sequence
23
- - Improve run inspector output
77
+ - Improved ANSI escape sequence handling
78
+ - Improved run inspector output formatting
79
+
80
+ ### Fixed
81
+ - Fixed log settings assignment when logger is nil to prevent errors
24
82
 
25
83
  ## [0.3.0] - 2025-03-14
84
+
26
85
  ### Added
27
- - Add `progname` to logger instances
28
- - Add `LoggerSerializer` to standardize log output
86
+ - Added `LoggerSerializer` for standardized log output formatting
87
+ - Added `progname` support for logger instances
88
+
29
89
  ### Changed
30
- - Revert default log formatter to `Line`
31
- - Removed `pid` from result serializer
32
- - Fix serialization of frozen run
33
- - Fix `call!` not marking state of failure as interrupted
90
+ - Removed `pid` (process ID) from result serializer output
91
+ - Reverted default log formatter from `PrettyLine` back to `Line`
92
+
93
+ ### Fixed
94
+ - Fixed `call!` method not properly marking failure state as interrupted
95
+ - Fixed serialization issues with frozen run objects
34
96
 
35
97
  ## [0.2.0] - 2025-03-12
98
+
36
99
  ### Added
37
- - Add `PrettyJson` log formatter
38
- - Add `PrettyKeyValue` log formatter
39
- - Add `PrettyLine` log formatter
100
+ - Added `PrettyJson` log formatter for structured JSON output
101
+ - Added `PrettyKeyValue` log formatter for key-value pair output
102
+ - Added `PrettyLine` log formatter for enhanced line-based output
103
+
40
104
  ### Changed
41
- - Make `PrettyLine` the default log formatter
42
- - Rename `MethodName` util to `NameAffix`
43
- - Rename `DatetimeFormatter` util to `LogTimestamp`
44
- - Rename `Runtime` util to `MonotonicRuntime`
45
- - Fix logging non hash values from raising an error
46
- - Fix bubbling of faults with nested halted calls
47
- - Wrap result logger in a `Logger#with_logger` block
105
+ - Renamed `DatetimeFormatter` utility to `LogTimestamp` for better clarity
106
+ - Renamed `MethodName` utility to `NameAffix` for better clarity
107
+ - Renamed `Runtime` utility to `MonotonicRuntime` for better clarity
108
+ - Updated `PrettyLine` to be the default log formatter
109
+ - Updated result logger to be wrapped in `Logger#with_logger` block for better context
110
+
111
+ ### Fixed
112
+ - Fixed error when logging non-hash values
113
+ - Fixed fault bubbling behavior with nested halted calls
48
114
 
49
115
  ## [0.1.0] - 2025-03-07
116
+
50
117
  ### Added
51
118
  - Initial release
data/README.md CHANGED
@@ -6,9 +6,7 @@
6
6
  [![CI](https://github.com/drexed/cmdx/actions/workflows/ci.yml/badge.svg)](https://github.com/drexed/cmdx/actions/workflows/ci.yml)
7
7
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=shields)](http://makeapullrequest.com)
8
8
 
9
- `CMDx` is a framework for expressive processing of business logic. Design
10
- code of varying levels of complexity that is built through branching and
11
- composition, informative halting, and exhaustive tracing/debugging.
9
+ `CMDx` is a Ruby framework for building maintainable, observable business logic through composable command objects. Design robust workflows with automatic parameter validation, structured error handling, comprehensive logging, and intelligent execution flow control that scales from simple tasks to complex multi-step processes.
12
10
 
13
11
  ## Installation
14
12
 
@@ -28,34 +26,84 @@ Or install it yourself as:
28
26
 
29
27
  $ gem install cmdx
30
28
 
29
+ ## Quick Example
30
+
31
+ ```ruby
32
+ # Setup task
33
+ class SendWelcomeEmailTask < CMDx::Task
34
+ use CMDx::Middlewares::Timeout, seconds: 5
35
+
36
+ on_success :track_email_delivery!
37
+
38
+ required :user_id, type: :integer, numeric: { min: 1 }
39
+ optional :template, type: :string, default: "welcome"
40
+
41
+ def call
42
+ if user.nil?
43
+ fail!(reason: "User not found", code: 404)
44
+ elsif user.unconfirmed?
45
+ skip!(reason: "Email not verified")
46
+ else
47
+ response = UserMailer.welcome(user, template).deliver_now
48
+ context.message_id = response.message_id
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def user
55
+ @user ||= User.find_by(id: user_id)
56
+ end
57
+
58
+ def track_email_delivery!
59
+ user.touch(:welcomed_at)
60
+ end
61
+ end
62
+
63
+ # Execute task
64
+ result = SendWelcomeEmailTask.call(user_id: 123, template: "premium_welcome")
65
+
66
+ # Handle result
67
+ if result.success?
68
+ puts "Welcome email sent <message_id: #{result.context.message_id}>"
69
+ elsif result.skipped?
70
+ puts "Skipped: #{result.metadata[:reason]}"
71
+ elsif result.failed?
72
+ puts "Failed: #{result.metadata[:reason]} with code: #{result.metadata[:code]}"
73
+ end
74
+ ```
75
+
31
76
  ## Table of contents
32
77
 
33
- - [Getting Started](https://github.com/drexed/cmdx/blob/main/docs/getting_started.md)
34
- - [Configuration](https://github.com/drexed/cmdx/blob/main/docs/configuration.md)
78
+ - [Getting Started](docs/getting_started.md)
79
+ - [Configuration](docs/configuration.md)
35
80
  - Basics
36
- - [Setup](https://github.com/drexed/cmdx/blob/main/docs/basics/setup.md)
37
- - [Call](https://github.com/drexed/cmdx/blob/main/docs/basics/call.md)
38
- - [Context](https://github.com/drexed/cmdx/blob/main/docs/basics/context.md)
39
- - [Run](https://github.com/drexed/cmdx/blob/main/docs/basics/run.md)
81
+ - [Setup](docs/basics/setup.md)
82
+ - [Call](docs/basics/call.md)
83
+ - [Context](docs/basics/context.md)
84
+ - [Chain](docs/basics/chain.md)
40
85
  - Interruptions
41
- - [Halt](https://github.com/drexed/cmdx/blob/main/docs/interruptions/halt.md)
42
- - [Faults](https://github.com/drexed/cmdx/blob/main/docs/interruptions/faults.md)
43
- - [Exceptions](https://github.com/drexed/cmdx/blob/main/docs/interruptions/exceptions.md)
86
+ - [Halt](docs/interruptions/halt.md)
87
+ - [Faults](docs/interruptions/faults.md)
88
+ - [Exceptions](docs/interruptions/exceptions.md)
44
89
  - Parameters
45
- - [Definitions](https://github.com/drexed/cmdx/blob/main/docs/parameters/definitions.md)
46
- - [Namespacing](https://github.com/drexed/cmdx/blob/main/docs/parameters/namespacing.md)
47
- - [Coercions](https://github.com/drexed/cmdx/blob/main/docs/parameters/coercions.md)
48
- - [Validations](https://github.com/drexed/cmdx/blob/main/docs/parameters/validations.md)
49
- - [Defaults](https://github.com/drexed/cmdx/blob/main/docs/parameters/defaults.md)
90
+ - [Definitions](docs/parameters/definitions.md)
91
+ - [Namespacing](docs/parameters/namespacing.md)
92
+ - [Coercions](docs/parameters/coercions.md)
93
+ - [Validations](docs/parameters/validations.md)
94
+ - [Defaults](docs/parameters/defaults.md)
50
95
  - Outcomes
51
96
  - [Result](#results)
52
- - [States](https://github.com/drexed/cmdx/blob/main/docs/outcomes/states.md)
53
- - [Statuses](https://github.com/drexed/cmdx/blob/main/docs/outcomes/statuses.md)
54
- - [Hooks](https://github.com/drexed/cmdx/blob/main/docs/hooks.md)
55
- - [Batch](https://github.com/drexed/cmdx/blob/main/docs/batch.md)
56
- - [Logging](https://github.com/drexed/cmdx/blob/main/docs/logging.md)
57
- - [Tips & Tricks](https://github.com/drexed/cmdx/blob/main/docs/tips_and_tricks.md)
58
- - [Example](https://github.com/drexed/cmdx/blob/main/docs/example.md)
97
+ - [States](docs/outcomes/states.md)
98
+ - [Statuses](docs/outcomes/statuses.md)
99
+ - [Callbacks](docs/callbacks.md)
100
+ - [Middlewares](docs/middlewares.md)
101
+ - [Workflows](docs/workflows.md)
102
+ - [Logging](docs/logging.md)
103
+ - [Internationalization (i18n)](docs/internationalization.md)
104
+ - [Testing](docs/testing.md)
105
+ - [AI Prompts](docs/ai_prompts.md)
106
+ - [Tips & Tricks](docs/tips_and_tricks.md)
59
107
 
60
108
  ## Development
61
109
 
@@ -73,4 +121,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
73
121
 
74
122
  ## Code of Conduct
75
123
 
76
- Everyone interacting in the CMDx projects codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/drexed/cmdx/blob/main/CODE_OF_CONDUCT.md).
124
+ Everyone interacting in the CMDx project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
@@ -0,0 +1,319 @@
1
+ # AI Prompt Templates
2
+
3
+ This guide provides AI prompt templates for building CMDx Task and Workflow objects, helping you leverage AI assistants to generate well-structured, production-ready command objects.
4
+
5
+ ## Table of Contents
6
+
7
+ - [TLDR](#tldr)
8
+ - [Framework Context Template](#framework-context-template)
9
+ - [Task Generation Templates](#task-generation-templates)
10
+ - [Workflow Generation Templates](#workflow-generation-templates)
11
+ - [Testing Templates](#testing-templates)
12
+ - [Best Practices for AI Prompts](#best-practices-for-ai-prompts)
13
+
14
+ ## TLDR
15
+
16
+ - **Purpose** - Pre-written prompts to help AI assistants generate production-ready CMDx code
17
+ - **Templates** - Framework context, task generation, workflow generation, and testing templates
18
+ - **Framework context** - Essential CMDx concepts and coding standards for AI understanding
19
+ - **Task templates** - Structured prompts for generating tasks with parameters, validations, and tests
20
+ - **Workflow templates** - Prompts for orchestrating multi-step business processes
21
+ - **Testing templates** - Comprehensive RSpec test generation with CMDx matchers
22
+
23
+ ## Framework Context Template
24
+
25
+ Use this context in your AI conversations to ensure proper CMDx code generation:
26
+
27
+ ```
28
+ I'm working with CMDx, a Ruby framework for designing and executing business logic within service/command objects.
29
+
30
+ KEY FRAMEWORK CONCEPTS:
31
+ - Tasks inherit from CMDx::Task and implement business logic in a `call` method
32
+ - Workflows inherit from CMDx::Workflow and orchestrate multiple tasks
33
+ - Parameters are defined with type coercion, validation, and defaults
34
+ - Results contain status (success/failed/skipped), state, context, and metadata
35
+ - Callbacks execute at specific lifecycle points (before_validation, on_success, etc.)
36
+ - Middlewares wrap task execution (authentication, logging, timeouts)
37
+ - Chains link multiple tasks together with shared context
38
+
39
+ CODING STANDARDS:
40
+ - Use Ruby 3.4+ syntax and conventions
41
+ - Follow snake_case for methods/variables, CamelCase for classes
42
+ - Use double quotes for strings
43
+ - Include comprehensive YARD documentation
44
+ - Write RSpec tests with CMDx custom matchers
45
+ - Name tasks as VerbNounTask (e.g., ProcessOrderTask)
46
+ - Name workflows as NounVerbWorkflow (e.g., OrderProcessingWorkflow)
47
+
48
+ Generate code that is production-ready with proper error handling, validation, and testing.
49
+ ```
50
+
51
+ ## Task Generation Templates
52
+
53
+ ```
54
+ Create a CMDx task that [SPECIFIC_ACTION] with the following requirements:
55
+
56
+ PARAMETERS:
57
+ - [parameter_name]: [type] - [description] - [required/optional]
58
+ - [parameter_name]: [type] - [description] - [validation_rules]
59
+
60
+ BUSINESS LOGIC:
61
+ - [Step 1 description]
62
+ - [Step 2 description]
63
+ - [Error conditions to handle]
64
+
65
+ CONTEXT UPDATES:
66
+ - [What data should be added to context]
67
+ - [What side effects should occur]
68
+
69
+ TESTING:
70
+ - Generate comprehensive RSpec tests using CMDx matchers
71
+ - Include success, failure, and edge case scenarios
72
+ - Test parameter validation and context updates
73
+
74
+ Please include:
75
+ - Proper parameter definitions with validations
76
+ - Error handling and metadata
77
+ - YARD documentation
78
+ - RSpec test file
79
+ ```
80
+
81
+ **Example Usage:**
82
+ ```
83
+ Create a CMDx task that processes user email preferences with the following requirements:
84
+
85
+ PARAMETERS:
86
+ - user_id: integer - ID of the user - required, positive
87
+ - email_types: array - Types of emails to enable - required, inclusion in ['marketing', 'notifications', 'alerts']
88
+ - enabled: boolean - Whether to enable or disable - optional, defaults to true
89
+
90
+ BUSINESS LOGIC:
91
+ - Validate user exists and is active
92
+ - Update user's email preferences in database
93
+ - Send confirmation email if preferences changed
94
+ - Log preference changes for audit trail
95
+
96
+ CONTEXT UPDATES:
97
+ - Add updated user object to context
98
+ - Add preference_changes hash with before/after values
99
+ - Add confirmation_sent boolean
100
+
101
+ TESTING:
102
+ - Generate comprehensive RSpec tests using CMDx matchers
103
+ - Include success, failure, and edge case scenarios
104
+ - Test parameter validation and context updates
105
+ ```
106
+
107
+ ## Workflow Generation Templates
108
+
109
+ ```
110
+ Create a CMDx workflow that orchestrates [BUSINESS_PROCESS] with the following requirements:
111
+
112
+ WORKFLOW STEPS:
113
+ 1. [Task 1]: [Description and purpose]
114
+ 2. [Task 2]: [Description and purpose]
115
+ 3. [Task 3]: [Description and purpose]
116
+
117
+ TASK DEPENDENCIES:
118
+ - [How tasks share data through context]
119
+ - [Which tasks can run in parallel]
120
+ - [Sequential requirements]
121
+
122
+ ERROR HANDLING:
123
+ - [How to handle individual task failures]
124
+ - [Rollback requirements]
125
+ - [Compensation logic]
126
+
127
+ CONDITIONAL LOGIC:
128
+ - [When to skip certain tasks]
129
+ - [Branching based on context]
130
+
131
+ TESTING:
132
+ - Generate workflow integration tests
133
+ - Test success path and various failure scenarios
134
+ - Include individual task unit tests
135
+ ```
136
+
137
+ **Example Usage:**
138
+ ```
139
+ Create a CMDx workflow that orchestrates user onboarding with the following requirements:
140
+
141
+ WORKFLOW STEPS:
142
+ 1. ValidateUserDataTask: Validate and sanitize user registration data
143
+ 2. CreateUserAccountTask: Create user account in database
144
+ 3. SendWelcomeEmailTask: Send personalized welcome email
145
+ 4. SetupDefaultPreferencesTask: Configure default user preferences
146
+ 5. TrackOnboardingEventTask: Log onboarding completion for analytics
147
+
148
+ TASK DEPENDENCIES:
149
+ - All tasks run sequentially
150
+ - User data flows through context from validation to account creation
151
+ - Welcome email uses created user object
152
+ - Preferences setup requires user ID
153
+ - Analytics tracking happens last with full context
154
+
155
+ ERROR HANDLING:
156
+ - If account creation fails, don't send email or setup preferences
157
+ - If email fails, continue with preferences but log the failure
158
+ - If preferences fail, still complete onboarding but flag for followup
159
+
160
+ CONDITIONAL LOGIC:
161
+ - Skip welcome email if user opted out during registration
162
+ - Skip analytics if user has privacy settings enabled
163
+
164
+ TESTING:
165
+ - Generate workflow integration tests
166
+ - Test success path and various failure scenarios
167
+ - Include individual task unit tests
168
+ ```
169
+
170
+ ## Testing Templates
171
+
172
+ ### Task Testing Template
173
+
174
+ ```
175
+ Generate comprehensive RSpec tests for [TASK_NAME] including:
176
+
177
+ PARAMETER VALIDATION TESTS:
178
+ - Test all required parameters
179
+ - Test type coercion and validation rules
180
+ - Test default values
181
+ - Test invalid parameter combinations
182
+
183
+ EXECUTION TESTS:
184
+ - Test successful execution with various inputs
185
+ - Test all error conditions and edge cases
186
+ - Test context updates and side effects
187
+ - Test metadata and timing information
188
+
189
+ INTEGRATION TESTS:
190
+ - Test external service interactions
191
+ - Test database operations
192
+ - Test file system operations (if applicable)
193
+
194
+ CALLBACK TESTS:
195
+ - Test lifecycle callbacks execute correctly
196
+ - Test callback order and context
197
+
198
+ Use CMDx custom matchers like:
199
+ - expect(result).to be_successful_task
200
+ - expect(result).to be_failed_task
201
+ - expect(TaskClass).to handle_exceptions_gracefully
202
+ ```
203
+
204
+ ### Workflow Testing Template
205
+
206
+ ```
207
+ Generate comprehensive RSpec tests for [WORKFLOW_NAME] including:
208
+
209
+ INTEGRATION TESTS:
210
+ - Test complete workflow execution
211
+ - Test various success scenarios
212
+ - Test different failure points
213
+ - Test context flow between tasks
214
+
215
+ INDIVIDUAL TASK TESTS:
216
+ - Test each task in isolation
217
+ - Test task parameter validation
218
+ - Test task-specific logic
219
+
220
+ CONDITIONAL LOGIC TESTS:
221
+ - Test all branching paths
222
+ - Test edge cases in decision logic
223
+ - Test context preservation across branches
224
+
225
+ ERROR HANDLING TESTS:
226
+ - Test failure propagation
227
+ - Test recovery mechanisms
228
+ - Test compensation logic
229
+ ```
230
+
231
+ ## Best Practices for AI Prompts
232
+
233
+ ### 1. Be Specific About Requirements
234
+
235
+ **Good:**
236
+ ```
237
+ Create a task that validates credit card information, including:
238
+ - Card number validation with Luhn algorithm
239
+ - Expiry date validation (not expired, reasonable future date)
240
+ - CVV validation (3-4 digits depending on card type)
241
+ - Cardholder name validation (2-50 characters, letters and spaces only)
242
+ ```
243
+
244
+ **Avoid:**
245
+ ```
246
+ Create a task that validates credit cards
247
+ ```
248
+
249
+ ### 2. Include Context About Data Flow
250
+
251
+ **Good:**
252
+ ```
253
+ The task should receive user_id and payment_amount, validate the payment method,
254
+ charge the card, and update the context with:
255
+ - transaction_id
256
+ - charged_amount
257
+ - payment_method_last_four
258
+ - charge_timestamp
259
+ ```
260
+
261
+ **Avoid:**
262
+ ```
263
+ Process a payment
264
+ ```
265
+
266
+ ### 3. Specify Error Conditions
267
+
268
+ **Good:**
269
+ ```
270
+ Handle these error conditions:
271
+ - Invalid card number → failed result with metadata { error_code: 'INVALID_CARD' }
272
+ - Expired card → failed result with metadata { error_code: 'EXPIRED_CARD' }
273
+ - Insufficient funds → failed result with metadata { error_code: 'DECLINED', retryable: false }
274
+ - Network timeout → failed result with metadata { error_code: 'TIMEOUT', retryable: true }
275
+ ```
276
+
277
+ **Avoid:**
278
+ ```
279
+ Handle payment errors
280
+ ```
281
+
282
+ ### 4. Request Complete Examples
283
+
284
+ **Good:**
285
+ ```
286
+ Generate a complete working example including:
287
+ - Task class with full implementation
288
+ - Parameter definitions with validations
289
+ - RSpec test file with success/failure scenarios
290
+ - YARD documentation
291
+ - Usage examples in comments
292
+ ```
293
+
294
+ **Avoid:**
295
+ ```
296
+ Show me the basic structure
297
+ ```
298
+
299
+ ### 5. Specify Framework Patterns
300
+
301
+ **Good:**
302
+ ```
303
+ Follow CMDx patterns:
304
+ - Use present tense verbs in task names (ProcessPaymentTask, not ProcessingPaymentTask)
305
+ - Include proper error handling with metadata
306
+ - Use callbacks for audit logging
307
+ - Return detailed context updates
308
+ - Include comprehensive parameter validation
309
+ ```
310
+
311
+ **Avoid:**
312
+ ```
313
+ Use best practices
314
+ ```
315
+
316
+ ---
317
+
318
+ - **Prev:** [Testing](testing.md)
319
+ - **Next:** [Tips and Tricks](tips_and_tricks.md)