cmdx 1.1.0 → 1.1.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.
- checksums.yaml +4 -4
- data/.cursor/prompts/docs.md +9 -0
- data/.cursor/prompts/rspec.md +13 -12
- data/.cursor/prompts/yardoc.md +11 -6
- data/CHANGELOG.md +13 -2
- data/README.md +1 -0
- data/docs/ai_prompts.md +269 -195
- data/docs/basics/call.md +124 -58
- data/docs/basics/chain.md +190 -160
- data/docs/basics/context.md +242 -154
- data/docs/basics/setup.md +302 -32
- data/docs/callbacks.md +390 -94
- data/docs/configuration.md +181 -65
- data/docs/deprecation.md +245 -0
- data/docs/getting_started.md +161 -39
- data/docs/internationalization.md +590 -70
- data/docs/interruptions/exceptions.md +135 -118
- data/docs/interruptions/faults.md +150 -125
- data/docs/interruptions/halt.md +134 -80
- data/docs/logging.md +181 -118
- data/docs/middlewares.md +150 -377
- data/docs/outcomes/result.md +140 -112
- data/docs/outcomes/states.md +134 -99
- data/docs/outcomes/statuses.md +204 -146
- data/docs/parameters/coercions.md +232 -281
- data/docs/parameters/defaults.md +224 -169
- data/docs/parameters/definitions.md +289 -141
- data/docs/parameters/namespacing.md +250 -161
- data/docs/parameters/validations.md +260 -133
- data/docs/testing.md +191 -197
- data/docs/workflows.md +143 -98
- data/lib/cmdx/callback.rb +23 -19
- data/lib/cmdx/callback_registry.rb +1 -3
- data/lib/cmdx/chain_inspector.rb +23 -23
- data/lib/cmdx/chain_serializer.rb +38 -19
- data/lib/cmdx/coercion.rb +20 -12
- data/lib/cmdx/coercion_registry.rb +51 -32
- data/lib/cmdx/configuration.rb +84 -31
- data/lib/cmdx/context.rb +32 -21
- data/lib/cmdx/core_ext/hash.rb +13 -13
- data/lib/cmdx/core_ext/module.rb +1 -1
- data/lib/cmdx/core_ext/object.rb +12 -12
- data/lib/cmdx/correlator.rb +60 -39
- data/lib/cmdx/errors.rb +105 -131
- data/lib/cmdx/fault.rb +66 -45
- data/lib/cmdx/immutator.rb +20 -21
- data/lib/cmdx/lazy_struct.rb +78 -70
- data/lib/cmdx/log_formatters/json.rb +1 -1
- data/lib/cmdx/log_formatters/key_value.rb +1 -1
- data/lib/cmdx/log_formatters/line.rb +1 -1
- data/lib/cmdx/log_formatters/logstash.rb +1 -1
- data/lib/cmdx/log_formatters/pretty_json.rb +1 -1
- data/lib/cmdx/log_formatters/pretty_key_value.rb +1 -1
- data/lib/cmdx/log_formatters/pretty_line.rb +1 -1
- data/lib/cmdx/log_formatters/raw.rb +2 -2
- data/lib/cmdx/logger.rb +19 -14
- data/lib/cmdx/logger_ansi.rb +33 -17
- data/lib/cmdx/logger_serializer.rb +85 -24
- data/lib/cmdx/middleware.rb +39 -21
- data/lib/cmdx/middleware_registry.rb +4 -3
- data/lib/cmdx/parameter.rb +151 -89
- data/lib/cmdx/parameter_inspector.rb +34 -21
- data/lib/cmdx/parameter_registry.rb +36 -30
- data/lib/cmdx/parameter_serializer.rb +21 -14
- data/lib/cmdx/result.rb +136 -135
- data/lib/cmdx/result_ansi.rb +31 -17
- data/lib/cmdx/result_inspector.rb +32 -27
- data/lib/cmdx/result_logger.rb +23 -14
- data/lib/cmdx/result_serializer.rb +65 -27
- data/lib/cmdx/task.rb +234 -113
- data/lib/cmdx/task_deprecator.rb +22 -25
- data/lib/cmdx/task_processor.rb +89 -88
- data/lib/cmdx/task_serializer.rb +27 -14
- data/lib/cmdx/utils/monotonic_runtime.rb +2 -4
- data/lib/cmdx/validator.rb +25 -16
- data/lib/cmdx/validator_registry.rb +53 -31
- data/lib/cmdx/validators/exclusion.rb +1 -1
- data/lib/cmdx/validators/format.rb +2 -2
- data/lib/cmdx/validators/inclusion.rb +2 -2
- data/lib/cmdx/validators/length.rb +2 -2
- data/lib/cmdx/validators/numeric.rb +3 -3
- data/lib/cmdx/validators/presence.rb +2 -2
- data/lib/cmdx/version.rb +1 -1
- data/lib/cmdx/workflow.rb +54 -33
- data/lib/generators/cmdx/task_generator.rb +6 -6
- data/lib/generators/cmdx/workflow_generator.rb +6 -6
- metadata +3 -1
data/docs/ai_prompts.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# AI Prompt Templates
|
2
2
|
|
3
|
-
|
3
|
+
AI prompt templates provide structured guidance for generating production-ready CMDx Task and Workflow objects. These templates ensure consistent code quality, proper framework usage, and comprehensive testing coverage when working with AI assistants.
|
4
4
|
|
5
5
|
## Table of Contents
|
6
6
|
|
@@ -9,196 +9,216 @@ This guide provides AI prompt templates for building CMDx Task and Workflow obje
|
|
9
9
|
- [Task Generation Templates](#task-generation-templates)
|
10
10
|
- [Workflow Generation Templates](#workflow-generation-templates)
|
11
11
|
- [Testing Templates](#testing-templates)
|
12
|
-
- [
|
12
|
+
- [Error Handling and Edge Cases](#error-handling-and-edge-cases)
|
13
|
+
- [Best Practices](#best-practices)
|
13
14
|
|
14
15
|
## TLDR
|
15
16
|
|
16
|
-
|
17
|
-
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
> [!NOTE]
|
18
|
+
> Pre-written prompts help AI assistants generate well-structured CMDx code with proper validations, error handling, and comprehensive tests.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# Task generation pattern
|
22
|
+
"Create a CMDx task that [ACTION] with parameters [PARAMS] and validation [RULES]"
|
23
|
+
|
24
|
+
# Workflow orchestration pattern
|
25
|
+
"Create a CMDx workflow that orchestrates [PROCESS] with steps [TASKS] and error handling [STRATEGY]"
|
26
|
+
|
27
|
+
# Testing pattern
|
28
|
+
"Generate RSpec tests with CMDx matchers for success, failure, and edge cases"
|
29
|
+
```
|
22
30
|
|
23
31
|
## Framework Context Template
|
24
32
|
|
25
|
-
|
33
|
+
> [!IMPORTANT]
|
34
|
+
> Always include this context when working with AI assistants to ensure proper CMDx code generation and adherence to framework conventions.
|
26
35
|
|
27
36
|
```
|
28
37
|
I'm working with CMDx, a Ruby framework for designing and executing business logic within service/command objects.
|
29
38
|
|
30
|
-
|
31
|
-
- Tasks inherit from CMDx::Task
|
32
|
-
- Workflows inherit from CMDx::Workflow
|
33
|
-
- Parameters
|
34
|
-
- Results contain status (success/failed/skipped), state, context,
|
35
|
-
- Callbacks execute at
|
36
|
-
- Middlewares wrap
|
37
|
-
- Chains link
|
39
|
+
CORE CONCEPTS:
|
40
|
+
- Tasks inherit from CMDx::Task with business logic in `call` method
|
41
|
+
- Workflows inherit from CMDx::Workflow to orchestrate multiple tasks
|
42
|
+
- Parameters support type coercion, validation, defaults, and nesting
|
43
|
+
- Results contain status (success/failed/skipped), state, context, metadata
|
44
|
+
- Callbacks execute at lifecycle points (before_validation, on_success, etc.)
|
45
|
+
- Middlewares wrap execution (authentication, logging, timeouts, correlation)
|
46
|
+
- Chains link tasks with shared context and failure propagation
|
38
47
|
|
39
48
|
CODING STANDARDS:
|
40
|
-
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
49
|
+
- Ruby 3.4+ syntax and conventions
|
50
|
+
- snake_case methods/variables, CamelCase classes
|
51
|
+
- Double quotes for strings, proper indentation
|
52
|
+
- YARD documentation with @param, @return, @example
|
53
|
+
- RSpec tests using CMDx custom matchers
|
54
|
+
- Task naming: VerbNounTask (ProcessOrderTask)
|
55
|
+
- Workflow naming: NounVerbWorkflow (OrderProcessingWorkflow)
|
47
56
|
|
48
|
-
|
57
|
+
REQUIREMENTS:
|
58
|
+
- Production-ready code with comprehensive error handling
|
59
|
+
- Parameter validation with meaningful error messages
|
60
|
+
- Proper context management and metadata usage
|
61
|
+
- Full test coverage including edge cases and failure scenarios
|
49
62
|
```
|
50
63
|
|
51
64
|
## Task Generation Templates
|
52
65
|
|
66
|
+
### Standard Task Template
|
67
|
+
|
53
68
|
```
|
54
|
-
Create a CMDx task that [SPECIFIC_ACTION] with
|
69
|
+
Create a CMDx task that [SPECIFIC_ACTION] with these requirements:
|
55
70
|
|
56
71
|
PARAMETERS:
|
57
|
-
- [
|
58
|
-
- [
|
72
|
+
- [name]: [type] - [description] - [required/optional] - [validation_rules]
|
73
|
+
- [name]: [type] - [description] - [default_value] - [constraints]
|
59
74
|
|
60
75
|
BUSINESS LOGIC:
|
61
|
-
|
62
|
-
|
63
|
-
|
76
|
+
1. [Validation step with error conditions]
|
77
|
+
2. [Core processing with success criteria]
|
78
|
+
3. [Side effects and external calls]
|
79
|
+
4. [Context updates and metadata]
|
64
80
|
|
65
|
-
|
66
|
-
- [
|
67
|
-
- [
|
81
|
+
ERROR HANDLING:
|
82
|
+
- [Specific error condition] → [failure response with metadata]
|
83
|
+
- [Edge case] → [appropriate handling strategy]
|
68
84
|
|
69
|
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
- Test parameter validation and context updates
|
85
|
+
CONTEXT UPDATES:
|
86
|
+
- [key]: [description of data added]
|
87
|
+
- [key]: [metadata or tracking information]
|
73
88
|
|
74
|
-
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
89
|
+
OUTPUT:
|
90
|
+
- Complete task implementation with YARD docs
|
91
|
+
- RSpec test file with success/failure/edge cases
|
92
|
+
- Parameter validation tests
|
93
|
+
- Integration tests for external dependencies
|
79
94
|
```
|
80
95
|
|
81
|
-
|
96
|
+
### Practical Example
|
97
|
+
|
82
98
|
```
|
83
|
-
Create a CMDx task that processes user
|
99
|
+
Create a CMDx task that processes user profile updates with these requirements:
|
84
100
|
|
85
101
|
PARAMETERS:
|
86
|
-
- user_id: integer -
|
87
|
-
-
|
88
|
-
-
|
102
|
+
- user_id: integer - User identifier - required - positive, exists in database
|
103
|
+
- profile_data: hash - Profile information - required - non-empty hash
|
104
|
+
- send_notification: boolean - Email update notification - optional - defaults to true
|
105
|
+
- audit_reason: string - Reason for update - optional - 3-255 characters when provided
|
89
106
|
|
90
107
|
BUSINESS LOGIC:
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
108
|
+
1. Validate user exists and is active (error if not found or inactive)
|
109
|
+
2. Sanitize and validate profile data fields (reject invalid formats)
|
110
|
+
3. Update user profile in database (handle transaction failures)
|
111
|
+
4. Send notification email if enabled (log failures, don't fail task)
|
112
|
+
5. Create audit log entry with before/after values
|
95
113
|
|
96
|
-
|
97
|
-
-
|
98
|
-
-
|
99
|
-
-
|
114
|
+
ERROR HANDLING:
|
115
|
+
- User not found → failed with metadata {error_code: 'USER_NOT_FOUND'}
|
116
|
+
- Invalid profile data → failed with metadata {invalid_fields: [...]}
|
117
|
+
- Database failure → failed with metadata {error_code: 'DB_ERROR', retryable: true}
|
100
118
|
|
101
|
-
|
102
|
-
-
|
103
|
-
-
|
104
|
-
-
|
119
|
+
CONTEXT UPDATES:
|
120
|
+
- updated_user: User object with new profile data
|
121
|
+
- profile_changes: Hash with {field: [old_value, new_value]}
|
122
|
+
- notification_sent: Boolean indicating email delivery status
|
105
123
|
```
|
106
124
|
|
107
125
|
## Workflow Generation Templates
|
108
126
|
|
127
|
+
### Standard Workflow Template
|
128
|
+
|
109
129
|
```
|
110
|
-
Create a CMDx workflow that orchestrates [BUSINESS_PROCESS] with
|
130
|
+
Create a CMDx workflow that orchestrates [BUSINESS_PROCESS] with these requirements:
|
111
131
|
|
112
132
|
WORKFLOW STEPS:
|
113
|
-
1. [
|
114
|
-
2. [
|
115
|
-
3. [
|
133
|
+
1. [TaskName]: [Purpose and responsibilities]
|
134
|
+
2. [TaskName]: [Dependencies and data requirements]
|
135
|
+
3. [TaskName]: [Conditional execution criteria]
|
116
136
|
|
117
|
-
|
118
|
-
- [
|
119
|
-
- [
|
120
|
-
- [Sequential requirements]
|
137
|
+
DATA FLOW:
|
138
|
+
- [Context key]: Flows from [Task A] to [Task B] for [purpose]
|
139
|
+
- [Shared state]: Available to [tasks] for [coordination]
|
121
140
|
|
122
|
-
ERROR
|
123
|
-
- [
|
124
|
-
- [
|
125
|
-
- [
|
141
|
+
ERROR STRATEGY:
|
142
|
+
- [Task failure] → [recovery action or compensation]
|
143
|
+
- [Critical failure] → [rollback requirements]
|
144
|
+
- [Partial failure] → [continuation strategy]
|
126
145
|
|
127
146
|
CONDITIONAL LOGIC:
|
128
|
-
- [
|
129
|
-
- [
|
147
|
+
- Skip [task] when [condition] is [value]
|
148
|
+
- Execute [alternative_task] if [criteria] met
|
149
|
+
- Branch execution based on [context_data]
|
130
150
|
|
131
|
-
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
151
|
+
OUTPUT:
|
152
|
+
- Complete workflow with task orchestration
|
153
|
+
- Individual task implementations
|
154
|
+
- Integration tests covering success/failure paths
|
155
|
+
- Error handling and rollback mechanisms
|
135
156
|
```
|
136
157
|
|
137
|
-
|
158
|
+
### Practical Example
|
159
|
+
|
138
160
|
```
|
139
|
-
Create a CMDx workflow that orchestrates user
|
161
|
+
Create a CMDx workflow that orchestrates user account deactivation with these requirements:
|
140
162
|
|
141
163
|
WORKFLOW STEPS:
|
142
|
-
1.
|
143
|
-
2.
|
144
|
-
3.
|
145
|
-
4.
|
146
|
-
5.
|
147
|
-
|
148
|
-
|
149
|
-
-
|
150
|
-
-
|
151
|
-
-
|
152
|
-
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
-
|
157
|
-
-
|
158
|
-
-
|
164
|
+
1. ValidateDeactivationRequestTask: Verify user permissions and business rules
|
165
|
+
2. BackupUserDataTask: Archive user data before deactivation
|
166
|
+
3. DeactivateAccountTask: Update account status and revoke access
|
167
|
+
4. NotifyStakeholdersTask: Send notifications to relevant parties
|
168
|
+
5. UpdateAnalyticsTask: Record deactivation metrics
|
169
|
+
|
170
|
+
DATA FLOW:
|
171
|
+
- user_id: Required input, flows through all tasks
|
172
|
+
- deactivation_reason: Used by validation, backup, and analytics
|
173
|
+
- backup_reference: Created by backup, used by analytics
|
174
|
+
- stakeholder_list: Determined by validation, used by notification
|
175
|
+
|
176
|
+
ERROR STRATEGY:
|
177
|
+
- Validation failure → halt workflow, return validation errors
|
178
|
+
- Backup failure → critical error, do not proceed with deactivation
|
179
|
+
- Account deactivation failure → rollback backup, restore previous state
|
180
|
+
- Notification failure → log error, continue workflow (non-critical)
|
181
|
+
- Analytics failure → log error, workflow succeeds (tracking only)
|
159
182
|
|
160
183
|
CONDITIONAL LOGIC:
|
161
|
-
- Skip
|
162
|
-
-
|
163
|
-
|
164
|
-
TESTING:
|
165
|
-
- Generate workflow integration tests
|
166
|
-
- Test success path and various failure scenarios
|
167
|
-
- Include individual task unit tests
|
184
|
+
- Skip stakeholder notification if user is internal test account
|
185
|
+
- Execute priority backup for premium users
|
186
|
+
- Send different notifications based on deactivation reason
|
168
187
|
```
|
169
188
|
|
170
189
|
## Testing Templates
|
171
190
|
|
172
191
|
### Task Testing Template
|
173
192
|
|
193
|
+
> [!TIP]
|
194
|
+
> Use CMDx custom matchers for cleaner, more expressive tests that follow framework conventions.
|
195
|
+
|
174
196
|
```
|
175
197
|
Generate comprehensive RSpec tests for [TASK_NAME] including:
|
176
198
|
|
177
|
-
PARAMETER VALIDATION
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
|
183
|
-
EXECUTION
|
184
|
-
-
|
185
|
-
-
|
186
|
-
-
|
187
|
-
-
|
188
|
-
|
189
|
-
INTEGRATION
|
190
|
-
-
|
191
|
-
-
|
192
|
-
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
- Test callback order and context
|
197
|
-
|
198
|
-
Use CMDx custom matchers like:
|
199
|
+
PARAMETER VALIDATION:
|
200
|
+
- Required parameters missing → proper error messages
|
201
|
+
- Type coercion edge cases → successful conversion or clear failures
|
202
|
+
- Validation rules → boundary conditions and invalid inputs
|
203
|
+
- Default values → proper application and override behavior
|
204
|
+
|
205
|
+
EXECUTION SCENARIOS:
|
206
|
+
- Happy path → successful execution with expected context updates
|
207
|
+
- Business rule violations → appropriate failure states with metadata
|
208
|
+
- External service failures → error handling and retry logic
|
209
|
+
- Edge cases → boundary conditions and unusual inputs
|
210
|
+
|
211
|
+
INTEGRATION POINTS:
|
212
|
+
- Database operations → transaction handling and rollback
|
213
|
+
- External APIs → network failures and response validation
|
214
|
+
- File system → permissions and storage errors
|
215
|
+
- Email/messaging → delivery failures and formatting
|
216
|
+
|
217
|
+
Use CMDx matchers:
|
199
218
|
- expect(result).to be_successful_task
|
200
|
-
- expect(result).to be_failed_task
|
201
|
-
- expect(
|
219
|
+
- expect(result).to be_failed_task.with_metadata(hash_including(...))
|
220
|
+
- expect(result).to have_context(key: value)
|
221
|
+
- expect(TaskClass).to have_parameter(:name).with_type(:integer)
|
202
222
|
```
|
203
223
|
|
204
224
|
### Workflow Testing Template
|
@@ -206,114 +226,168 @@ Use CMDx custom matchers like:
|
|
206
226
|
```
|
207
227
|
Generate comprehensive RSpec tests for [WORKFLOW_NAME] including:
|
208
228
|
|
209
|
-
INTEGRATION
|
210
|
-
-
|
211
|
-
-
|
212
|
-
-
|
213
|
-
-
|
229
|
+
INTEGRATION SCENARIOS:
|
230
|
+
- Complete success path → all tasks execute with proper data flow
|
231
|
+
- Early failure → workflow halts at appropriate point
|
232
|
+
- Mid-workflow failure → proper error propagation and cleanup
|
233
|
+
- Recovery scenarios → compensation and rollback behavior
|
214
234
|
|
215
|
-
|
216
|
-
-
|
217
|
-
-
|
218
|
-
-
|
235
|
+
TASK COORDINATION:
|
236
|
+
- Context passing → data flows correctly between tasks
|
237
|
+
- Conditional execution → tasks skip/execute based on conditions
|
238
|
+
- Parallel execution → concurrent tasks complete properly
|
239
|
+
- Sequential dependencies → tasks wait for predecessors
|
219
240
|
|
220
|
-
|
221
|
-
-
|
222
|
-
-
|
223
|
-
-
|
241
|
+
ERROR PROPAGATION:
|
242
|
+
- Individual task failures → workflow response and metadata
|
243
|
+
- Critical vs non-critical failures → appropriate handling
|
244
|
+
- Rollback mechanisms → state restoration and cleanup
|
245
|
+
- Error aggregation → multiple failure consolidation
|
224
246
|
|
225
|
-
|
226
|
-
-
|
227
|
-
-
|
228
|
-
-
|
247
|
+
EDGE CASES:
|
248
|
+
- Empty context → proper initialization and defaults
|
249
|
+
- Malformed inputs → validation and sanitization
|
250
|
+
- Resource constraints → timeout and resource management
|
251
|
+
- Concurrent execution → race conditions and locking
|
229
252
|
```
|
230
253
|
|
231
|
-
##
|
254
|
+
## Error Handling and Edge Cases
|
255
|
+
|
256
|
+
> [!WARNING]
|
257
|
+
> Always include comprehensive error handling in your prompts to ensure robust, production-ready code generation.
|
258
|
+
|
259
|
+
### Common Error Scenarios
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
# Parameter validation failures
|
263
|
+
expect(result).to be_failed_task
|
264
|
+
.with_metadata(
|
265
|
+
reason: "user_id is required",
|
266
|
+
messages: { user_id: ["can't be blank"] }
|
267
|
+
)
|
268
|
+
|
269
|
+
# Business rule violations
|
270
|
+
expect(result).to be_failed_task
|
271
|
+
.with_metadata(
|
272
|
+
error_code: "INSUFFICIENT_BALANCE",
|
273
|
+
retryable: false,
|
274
|
+
balance: current_balance,
|
275
|
+
required: requested_amount
|
276
|
+
)
|
277
|
+
|
278
|
+
# External service failures
|
279
|
+
expect(result).to be_failed_task
|
280
|
+
.with_metadata(
|
281
|
+
error_code: "SERVICE_UNAVAILABLE",
|
282
|
+
retryable: true,
|
283
|
+
retry_after: 30,
|
284
|
+
service: "payment_processor"
|
285
|
+
)
|
286
|
+
```
|
287
|
+
|
288
|
+
### Edge Case Coverage
|
289
|
+
|
290
|
+
Include these scenarios in your prompts:
|
291
|
+
|
292
|
+
| Scenario | Test Coverage | Expected Behavior |
|
293
|
+
|----------|---------------|-------------------|
|
294
|
+
| Empty inputs | Nil, empty strings, empty arrays | Validation errors or defaults |
|
295
|
+
| Boundary values | Min/max limits, zero, negative | Proper validation and coercion |
|
296
|
+
| Malformed data | Invalid JSON, corrupt files | Clear error messages |
|
297
|
+
| Resource limits | Memory, timeout, rate limits | Graceful degradation |
|
298
|
+
| Concurrent access | Race conditions, locks | Proper synchronization |
|
299
|
+
|
300
|
+
## Best Practices
|
301
|
+
|
302
|
+
### 1. Specific Requirements
|
232
303
|
|
233
|
-
|
304
|
+
> [!NOTE]
|
305
|
+
> Provide detailed, actionable requirements rather than vague descriptions to get better code generation.
|
234
306
|
|
235
|
-
**
|
307
|
+
**Effective:**
|
236
308
|
```
|
237
|
-
Create a task that validates
|
238
|
-
-
|
239
|
-
- Expiry date validation (not expired,
|
240
|
-
- CVV validation (3
|
241
|
-
-
|
309
|
+
Create a task that validates payment information including:
|
310
|
+
- Credit card number validation using Luhn algorithm
|
311
|
+
- Expiry date validation (not expired, within 10 years)
|
312
|
+
- CVV validation (3 digits for Visa/MC, 4 for Amex)
|
313
|
+
- Amount validation (positive, max $10,000, 2 decimal places)
|
314
|
+
- Return structured validation errors with field-specific messages
|
242
315
|
```
|
243
316
|
|
244
|
-
**
|
317
|
+
**Ineffective:**
|
245
318
|
```
|
246
|
-
Create a
|
319
|
+
Create a payment validation task
|
247
320
|
```
|
248
321
|
|
249
|
-
### 2.
|
322
|
+
### 2. Complete Context Flow
|
250
323
|
|
251
|
-
**
|
324
|
+
**Effective:**
|
252
325
|
```
|
253
|
-
|
254
|
-
|
255
|
-
-
|
256
|
-
-
|
257
|
-
-
|
258
|
-
-
|
326
|
+
Task receives user_id and order_data, validates inventory, processes payment,
|
327
|
+
updates order status, and adds to context:
|
328
|
+
- order: Order object with updated status
|
329
|
+
- payment_reference: Payment processor transaction ID
|
330
|
+
- inventory_reserved: Array of reserved item IDs
|
331
|
+
- processing_time: Duration in milliseconds
|
259
332
|
```
|
260
333
|
|
261
|
-
**
|
334
|
+
**Ineffective:**
|
262
335
|
```
|
263
|
-
Process
|
336
|
+
Process an order and update context
|
264
337
|
```
|
265
338
|
|
266
|
-
### 3.
|
339
|
+
### 3. Explicit Error Conditions
|
267
340
|
|
268
|
-
**
|
341
|
+
**Effective:**
|
269
342
|
```
|
270
|
-
Handle these
|
271
|
-
- Invalid card
|
272
|
-
- Expired card → failed
|
273
|
-
-
|
274
|
-
-
|
343
|
+
Handle these specific errors:
|
344
|
+
- Invalid card → failed with {error_code: 'INVALID_CARD', field: 'number'}
|
345
|
+
- Expired card → failed with {error_code: 'EXPIRED', retry_date: Date}
|
346
|
+
- Declined → failed with {error_code: 'DECLINED', retryable: false}
|
347
|
+
- Timeout → failed with {error_code: 'TIMEOUT', retryable: true, delay: 30}
|
275
348
|
```
|
276
349
|
|
277
|
-
**
|
350
|
+
**Ineffective:**
|
278
351
|
```
|
279
|
-
Handle payment errors
|
352
|
+
Handle payment errors appropriately
|
280
353
|
```
|
281
354
|
|
282
|
-
### 4.
|
355
|
+
### 4. Framework-Specific Patterns
|
283
356
|
|
284
|
-
**
|
357
|
+
**Effective:**
|
285
358
|
```
|
286
|
-
|
287
|
-
-
|
288
|
-
-
|
289
|
-
-
|
290
|
-
-
|
291
|
-
-
|
359
|
+
Follow CMDx conventions:
|
360
|
+
- Use present tense task names (ProcessPaymentTask, not PaymentProcessor)
|
361
|
+
- Include detailed metadata for failures
|
362
|
+
- Use callbacks for cross-cutting concerns (audit, logging)
|
363
|
+
- Leverage parameter coercion for input flexibility
|
364
|
+
- Return rich context updates for downstream tasks
|
292
365
|
```
|
293
366
|
|
294
|
-
**
|
367
|
+
**Ineffective:**
|
295
368
|
```
|
296
|
-
|
369
|
+
Use good Ruby practices
|
297
370
|
```
|
298
371
|
|
299
|
-
### 5.
|
372
|
+
### 5. Comprehensive Test Coverage
|
300
373
|
|
301
|
-
**
|
374
|
+
**Effective:**
|
302
375
|
```
|
303
|
-
|
304
|
-
-
|
305
|
-
-
|
306
|
-
-
|
307
|
-
-
|
308
|
-
-
|
376
|
+
Generate tests including:
|
377
|
+
- All parameter combinations and edge cases
|
378
|
+
- Success scenarios with various input types
|
379
|
+
- Each failure mode with proper error metadata
|
380
|
+
- Integration with external services (mocked)
|
381
|
+
- Performance characteristics and timeouts
|
382
|
+
- Callback execution and order
|
309
383
|
```
|
310
384
|
|
311
|
-
**
|
385
|
+
**Ineffective:**
|
312
386
|
```
|
313
|
-
|
387
|
+
Include basic tests
|
314
388
|
```
|
315
389
|
|
316
390
|
---
|
317
391
|
|
318
|
-
- **Prev:** [
|
392
|
+
- **Prev:** [Deprecation](deprecation.md)
|
319
393
|
- **Next:** [Tips and Tricks](tips_and_tricks.md)
|