appydave-tools 0.15.0 → 0.16.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/CLAUDE.md +113 -29
- data/README.md +262 -86
- data/bin/subtitle_manager.rb +18 -12
- data/bin/subtitle_processor.rb +158 -0
- data/docs/archive/codebase-audit-2025-01.md +424 -0
- data/docs/archive/documentation-framework-proposal.md +808 -0
- data/docs/archive/purpose-and-philosophy.md +110 -0
- data/docs/archive/test-coverage-quick-wins.md +342 -0
- data/docs/archive/tool-discovery.md +199 -0
- data/docs/archive/tool-documentation-analysis.md +592 -0
- data/docs/tools/bank-reconciliation.md +269 -0
- data/docs/tools/cli-actions.md +444 -0
- data/docs/tools/configuration.md +329 -0
- data/docs/{usage → tools}/gpt-context.md +118 -7
- data/docs/tools/index.md +324 -0
- data/docs/tools/move-images.md +295 -0
- data/docs/tools/name-manager.md +322 -0
- data/docs/tools/prompt-tools.md +209 -0
- data/docs/tools/subtitle-processor.md +242 -0
- data/docs/tools/youtube-automation.md +258 -0
- data/docs/tools/youtube-manager.md +248 -0
- data/lib/appydave/tools/{subtitle_manager → subtitle_processor}/clean.rb +1 -1
- data/lib/appydave/tools/{subtitle_manager → subtitle_processor}/join.rb +5 -2
- data/lib/appydave/tools/version.rb +1 -1
- data/lib/appydave/tools.rb +2 -4
- data/package.json +1 -1
- metadata +29 -12
- data/lib/mj-paste-test/main.rb +0 -35
- data/lib/mj-paste-test/prompts.txt +0 -18
- data/lib/mj-paste-test/readme-leonardo.md +0 -0
- /data/lib/appydave/tools/{subtitle_manager → subtitle_processor}/_doc-clean.md +0 -0
- /data/lib/appydave/tools/{subtitle_manager → subtitle_processor}/_doc-join.md +0 -0
- /data/lib/appydave/tools/{subtitle_manager → subtitle_processor}/_doc-todo.md +0 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Bank Reconciliation
|
|
2
|
+
|
|
3
|
+
Process and reconcile bank transaction data with filtering, transformation, and cleanup capabilities.
|
|
4
|
+
|
|
5
|
+
## What It Does
|
|
6
|
+
|
|
7
|
+
**Bank Reconciliation** handles financial transaction processing:
|
|
8
|
+
|
|
9
|
+
- Cleans and normalizes transaction CSV data
|
|
10
|
+
- Transforms transaction formats for analysis
|
|
11
|
+
- Filters transactions by criteria
|
|
12
|
+
- Processes transaction batches
|
|
13
|
+
- Handles multiple bank CSV formats
|
|
14
|
+
- Prepares data for reconciliation systems
|
|
15
|
+
|
|
16
|
+
## How to Use
|
|
17
|
+
|
|
18
|
+
### Clean Transactions
|
|
19
|
+
|
|
20
|
+
Normalize transaction CSV files:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bank_reconciliation clean -i "*.csv" -f ./transactions -o cleaned_transactions.csv
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Transform Transactions
|
|
27
|
+
|
|
28
|
+
Convert transactions to different formats:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
bank_reconciliation transform -i "*.csv" -f ./transactions -o transformed.csv
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Process Transactions
|
|
35
|
+
|
|
36
|
+
Full processing pipeline:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
bank_reconciliation process -i "*.csv" -f ./transactions -o processed.csv
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Filter Transactions
|
|
43
|
+
|
|
44
|
+
Select specific transactions:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
bank_reconciliation filter -i "*.csv" -f ./transactions -o filtered.csv
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Command Reference
|
|
51
|
+
|
|
52
|
+
### Clean Command
|
|
53
|
+
```bash
|
|
54
|
+
bank_reconciliation clean [options]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
| Option | Short | Long | Description |
|
|
58
|
+
|--------|-------|------|-------------|
|
|
59
|
+
| Include Pattern | `-i` | `--include PATTERN` | GLOB pattern for source files |
|
|
60
|
+
| Transaction Folder | `-f` | `--transaction FOLDER` | Folder with CSV files |
|
|
61
|
+
| Output File | `-o` | `--output FILE` | Output CSV file |
|
|
62
|
+
| Help | `-h` | `--help` | Show help |
|
|
63
|
+
|
|
64
|
+
### Transform Command
|
|
65
|
+
```bash
|
|
66
|
+
bank_reconciliation transform [options]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Option | Short | Long | Description |
|
|
70
|
+
|--------|-------|------|-------------|
|
|
71
|
+
| Include Pattern | `-i` | `--include PATTERN` | GLOB pattern for source files |
|
|
72
|
+
| Transaction Folder | `-f` | `--transaction FOLDER` | Folder with CSV files |
|
|
73
|
+
| Output File | `-o` | `--output FILE` | Output file |
|
|
74
|
+
| Format | `-F` | `--format FORMAT` | Output format (csv, json, etc.) |
|
|
75
|
+
| Help | `-h` | `--help` | Show help |
|
|
76
|
+
|
|
77
|
+
### Process Command
|
|
78
|
+
```bash
|
|
79
|
+
bank_reconciliation process [options]
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Option | Short | Long | Description |
|
|
83
|
+
|--------|-------|------|-------------|
|
|
84
|
+
| Include Pattern | `-i` | `--include PATTERN` | GLOB pattern for source files |
|
|
85
|
+
| Transaction Folder | `-f` | `--transaction FOLDER` | Folder with CSV files |
|
|
86
|
+
| Output File | `-o` | `--output FILE` | Output file |
|
|
87
|
+
| Help | `-h` | `--help` | Show help |
|
|
88
|
+
|
|
89
|
+
### Filter Command
|
|
90
|
+
```bash
|
|
91
|
+
bank_reconciliation filter [options]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
| Option | Short | Long | Description |
|
|
95
|
+
|--------|-------|------|-------------|
|
|
96
|
+
| Include Pattern | `-i` | `--include PATTERN` | GLOB pattern for source files |
|
|
97
|
+
| Transaction Folder | `-f` | `--transaction FOLDER` | Folder with CSV files |
|
|
98
|
+
| Output File | `-o` | `--output FILE` | Output file |
|
|
99
|
+
| Min Amount | `-m` | `--min-amount AMOUNT` | Minimum transaction amount |
|
|
100
|
+
| Max Amount | `-M` | `--max-amount AMOUNT` | Maximum transaction amount |
|
|
101
|
+
| Help | `-h` | `--help` | Show help |
|
|
102
|
+
|
|
103
|
+
## Use Cases for AI Agents
|
|
104
|
+
|
|
105
|
+
### 1. Transaction Data Cleanup
|
|
106
|
+
```bash
|
|
107
|
+
# AI orchestrates cleaning of multiple bank exports
|
|
108
|
+
bank_reconciliation clean -i "*.csv" -f ./monthly-statements
|
|
109
|
+
```
|
|
110
|
+
**AI discovers**: Data quality issues, formatting inconsistencies. Can systematically clean transaction data.
|
|
111
|
+
|
|
112
|
+
### 2. Bank Format Unification
|
|
113
|
+
```bash
|
|
114
|
+
# Convert multiple bank formats to standard
|
|
115
|
+
# Different banks export different CSV layouts
|
|
116
|
+
# Transform normalizes to single format
|
|
117
|
+
bank_reconciliation transform -i "*.csv" -f ./exports
|
|
118
|
+
```
|
|
119
|
+
**AI discovers**: Format variations across banks. Can unify disparate data sources.
|
|
120
|
+
|
|
121
|
+
### 3. Reconciliation Preparation
|
|
122
|
+
```bash
|
|
123
|
+
# Process transactions before reconciliation
|
|
124
|
+
# Clean, transform, and normalize in sequence
|
|
125
|
+
bank_reconciliation process -i "*.csv" -f ./transactions
|
|
126
|
+
```
|
|
127
|
+
**AI discovers**: Full workflow. Can prepare data for reconciliation system.
|
|
128
|
+
|
|
129
|
+
### 4. Large Transaction Filtering
|
|
130
|
+
```bash
|
|
131
|
+
# Identify high-value transactions
|
|
132
|
+
bank_reconciliation filter -i "*.csv" -f ./transactions -m 1000
|
|
133
|
+
```
|
|
134
|
+
**AI discovers**: Transaction patterns, high-value activity. Can analyze spending by category.
|
|
135
|
+
|
|
136
|
+
### 5. Fraud Detection Preparation
|
|
137
|
+
```bash
|
|
138
|
+
# Extract unusual transactions for review
|
|
139
|
+
bank_reconciliation filter -i "*.csv" -f ./transactions
|
|
140
|
+
# AI analyzes filtered results for anomalies
|
|
141
|
+
```
|
|
142
|
+
**AI discovers**: Transaction dataset. Can identify suspicious patterns.
|
|
143
|
+
|
|
144
|
+
### 6. Tax Reporting
|
|
145
|
+
```bash
|
|
146
|
+
# Filter transactions for tax categories
|
|
147
|
+
# Process Q1, Q2, Q3, Q4 separately
|
|
148
|
+
bank_reconciliation process -i "q1*.csv" -o "q1-reconciled.csv"
|
|
149
|
+
```
|
|
150
|
+
**AI discovers**: Quarterly data. Can prepare tax reporting documents.
|
|
151
|
+
|
|
152
|
+
### 7. Vendor Analysis
|
|
153
|
+
```bash
|
|
154
|
+
# Process all transactions
|
|
155
|
+
# AI analyzes to identify top vendors
|
|
156
|
+
# Groups spending by vendor
|
|
157
|
+
bank_reconciliation process -i "*.csv" -f ./all-transactions
|
|
158
|
+
```
|
|
159
|
+
**AI discovers**: Complete transaction data. Can generate vendor reports.
|
|
160
|
+
|
|
161
|
+
### 8. Budget vs. Actual
|
|
162
|
+
```bash
|
|
163
|
+
# Process actual transactions
|
|
164
|
+
# AI compares against budget
|
|
165
|
+
# Calculates variances
|
|
166
|
+
bank_reconciliation process -i "*.csv" -f ./actual-spend
|
|
167
|
+
```
|
|
168
|
+
**AI discovers**: Spending patterns. Can reconcile against budget.
|
|
169
|
+
|
|
170
|
+
### 9. Batch Reconciliation
|
|
171
|
+
```bash
|
|
172
|
+
# Process multiple months of data
|
|
173
|
+
for month in jan feb mar apr may jun; do
|
|
174
|
+
bank_reconciliation process -i "$month*.csv" -o "$month-processed.csv"
|
|
175
|
+
done
|
|
176
|
+
```
|
|
177
|
+
**AI discovers**: Monthly patterns, trends. Can automate recurring reconciliation.
|
|
178
|
+
|
|
179
|
+
### 10. Data Quality Audit
|
|
180
|
+
```bash
|
|
181
|
+
# Clean, then compare before/after
|
|
182
|
+
# Identify what was changed
|
|
183
|
+
# Assess data quality improvements
|
|
184
|
+
bank_reconciliation clean -i "*.csv" -f ./raw -o ./cleaned
|
|
185
|
+
```
|
|
186
|
+
**AI discovers**: Data issues, cleaning effectiveness. Can audit data quality metrics.
|
|
187
|
+
|
|
188
|
+
## Supported Bank Formats
|
|
189
|
+
|
|
190
|
+
The tool handles CSV export formats from:
|
|
191
|
+
|
|
192
|
+
- Major US Banks (Chase, Bank of America, Wells Fargo, etc.)
|
|
193
|
+
- International Banks (different date/amount formats)
|
|
194
|
+
- Credit Card Issuers (Visa, Mastercard processors)
|
|
195
|
+
- Investment Platforms (broker exports)
|
|
196
|
+
- Payment Services (PayPal, Stripe, Square)
|
|
197
|
+
|
|
198
|
+
## Transaction CSV Structure
|
|
199
|
+
|
|
200
|
+
Expected columns (flexible, auto-detected):
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
Date | Description | Amount | Balance | Type | Reference
|
|
204
|
+
-----|-------------|--------|---------|------|----------
|
|
205
|
+
1/1 | Starbucks | -5.00 | 1000 | DR | COFFEE123
|
|
206
|
+
1/2 | Salary | 5000 | 6000 | CR | PAYROLL
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Workflow Integration
|
|
210
|
+
|
|
211
|
+
Typical reconciliation workflow:
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
1. Export from Banks (manual or API)
|
|
215
|
+
2. Clean Data (bank_reconciliation clean)
|
|
216
|
+
3. Transform if Needed (bank_reconciliation transform)
|
|
217
|
+
4. Filter as Needed (bank_reconciliation filter)
|
|
218
|
+
5. Load to Accounting System (QuickBooks, etc.)
|
|
219
|
+
6. Reconcile (accounting software)
|
|
220
|
+
7. Report (taxes, budgets, analysis)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Troubleshooting
|
|
224
|
+
|
|
225
|
+
| Issue | Solution |
|
|
226
|
+
|-------|----------|
|
|
227
|
+
| "File not found" | Verify CSV files exist in specified folder |
|
|
228
|
+
| "Invalid CSV format" | Use `clean` command first to fix formatting |
|
|
229
|
+
| "No data processed" | Check include pattern (e.g., `*.csv` not `*.txt`) |
|
|
230
|
+
| "Amount format error" | Ensure amounts are numeric, clean first |
|
|
231
|
+
|
|
232
|
+
## Tips & Tricks
|
|
233
|
+
|
|
234
|
+
1. **Always clean first**: `clean` fixes encoding and formatting issues
|
|
235
|
+
2. **Keep raw exports**: Backup original CSVs before processing
|
|
236
|
+
3. **Use patterns efficiently**: `-i "*.csv"` or `-i "201[0-9]-*.csv"`
|
|
237
|
+
4. **Process by period**: Monthly/quarterly processing is easier to debug
|
|
238
|
+
5. **Validate output**: Check processed CSV before importing to accounting system
|
|
239
|
+
|
|
240
|
+
## Example Workflow
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# Step 1: Export from banks
|
|
244
|
+
# Download CSVs from Chase, Bank of America, Credit Card companies
|
|
245
|
+
|
|
246
|
+
# Step 2: Clean all exports
|
|
247
|
+
bank_reconciliation clean -i "*.csv" -f ./exports -o all-cleaned.csv
|
|
248
|
+
|
|
249
|
+
# Step 3: Transform to standard format
|
|
250
|
+
bank_reconciliation transform -i "all-cleaned.csv" -F "csv" -o standard-format.csv
|
|
251
|
+
|
|
252
|
+
# Step 4: Process for reconciliation
|
|
253
|
+
bank_reconciliation process -i "standard-format.csv" -o reconciliation-ready.csv
|
|
254
|
+
|
|
255
|
+
# Step 5: Load into accounting system
|
|
256
|
+
# Import reconciliation-ready.csv into QuickBooks, Xero, Wave, etc.
|
|
257
|
+
|
|
258
|
+
# Step 6: Manual reconciliation review
|
|
259
|
+
# Compare against bank statements
|
|
260
|
+
# Mark items as reconciled
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
**Status**: Private financial tool - Not for public use
|
|
266
|
+
**Security**: All transaction data is sensitive - Keep locally, never share
|
|
267
|
+
**Related**: Configuration management for secure storage
|
|
268
|
+
|
|
269
|
+
**Note**: Bank reconciliation is a private tool for personal financial management. Keep data secure and local.
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# CLI Actions Framework
|
|
2
|
+
|
|
3
|
+
Base framework and pattern for building command-line actions with option parsing, validation, and execution.
|
|
4
|
+
|
|
5
|
+
## What It Does
|
|
6
|
+
|
|
7
|
+
**CLI Actions** provides a template method pattern for building consistent CLI tools:
|
|
8
|
+
|
|
9
|
+
- Base class for all CLI operations
|
|
10
|
+
- Handles option parsing automatically
|
|
11
|
+
- Enforces validation before execution
|
|
12
|
+
- Provides consistent help messages
|
|
13
|
+
- Simplifies building new CLI commands
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
CLI Actions use the Template Method pattern:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
BaseAction (abstract)
|
|
21
|
+
├── GetVideoAction (retrieves YouTube video details)
|
|
22
|
+
├── UpdateVideoAction (updates video metadata)
|
|
23
|
+
└── PromptCompletionAction (generates completions)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Each action follows this lifecycle:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
1. Parse Options (convert command-line args to options dict)
|
|
30
|
+
2. Validate Options (ensure required options are present)
|
|
31
|
+
3. Execute (perform the actual work with validated options)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How to Use
|
|
35
|
+
|
|
36
|
+
### Using Existing Actions
|
|
37
|
+
|
|
38
|
+
Actions are invoked through CLI commands:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# GetVideoAction via youtube_manager
|
|
42
|
+
youtube_manager get -v dQw4w9WgXcQ
|
|
43
|
+
|
|
44
|
+
# UpdateVideoAction via youtube_manager
|
|
45
|
+
youtube_manager update -v dQw4w9WgXcQ -t "New Title"
|
|
46
|
+
|
|
47
|
+
# PromptCompletionAction via prompt_tools (deprecated)
|
|
48
|
+
prompt_tools completion -p "Your prompt here"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Creating New Actions
|
|
52
|
+
|
|
53
|
+
Inherit from BaseAction:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
module Appydave
|
|
57
|
+
module Tools
|
|
58
|
+
module CliActions
|
|
59
|
+
class MyNewAction < BaseAction
|
|
60
|
+
protected
|
|
61
|
+
|
|
62
|
+
def define_options(opts, options)
|
|
63
|
+
opts.on('-n', '--name NAME', 'User name') { |v| options[:name] = v }
|
|
64
|
+
opts.on('-e', '--email EMAIL', 'Email address') { |v| options[:email] = v }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def validate_options(options)
|
|
68
|
+
raise ArgumentError, 'Name required' unless options[:name]
|
|
69
|
+
raise ArgumentError, 'Email required' unless options[:email]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def execute(options)
|
|
73
|
+
puts "Hello #{options[:name]}!"
|
|
74
|
+
puts "Email: #{options[:email]}"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Invoke the Action
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
action = Appydave::Tools::CliActions::MyNewAction.new
|
|
86
|
+
action.action(['-n', 'John', '-e', 'john@example.com'])
|
|
87
|
+
# Output: Hello John!
|
|
88
|
+
# Email: john@example.com
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## API Reference
|
|
92
|
+
|
|
93
|
+
### BaseAction
|
|
94
|
+
|
|
95
|
+
Base class for all CLI actions:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
class BaseAction
|
|
99
|
+
# Main entry point
|
|
100
|
+
def action(args)
|
|
101
|
+
# Parses options, validates, executes
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
protected
|
|
105
|
+
|
|
106
|
+
# Override in subclasses
|
|
107
|
+
def define_options(opts, options)
|
|
108
|
+
# Define command-line options
|
|
109
|
+
# Use opts.on() to add options
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def validate_options(options)
|
|
113
|
+
# Validate parsed options
|
|
114
|
+
# Raise ArgumentError if invalid
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def execute(options)
|
|
118
|
+
# Perform the actual work
|
|
119
|
+
# options contains parsed and validated options
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Generated automatically based on class name
|
|
123
|
+
def command_usage
|
|
124
|
+
# "myaction [options]"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Included Actions
|
|
130
|
+
|
|
131
|
+
### GetVideoAction
|
|
132
|
+
|
|
133
|
+
Retrieves YouTube video metadata:
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
action = Appydave::Tools::CliActions::GetVideoAction.new
|
|
137
|
+
action.action(['-v', 'dQw4w9WgXcQ'])
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Options**:
|
|
141
|
+
- `-v` / `--video-id` VIDEO_ID - YouTube video ID (required)
|
|
142
|
+
|
|
143
|
+
**Output**: Video details (title, description, tags, category, metrics)
|
|
144
|
+
|
|
145
|
+
### UpdateVideoAction
|
|
146
|
+
|
|
147
|
+
Updates YouTube video metadata:
|
|
148
|
+
|
|
149
|
+
```ruby
|
|
150
|
+
action = Appydave::Tools::CliActions::UpdateVideoAction.new
|
|
151
|
+
action.action(['-v', 'dQw4w9WgXcQ', '-t', 'New Title'])
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Options**:
|
|
155
|
+
- `-v` / `--video-id` VIDEO_ID - YouTube video ID (required)
|
|
156
|
+
- `-t` / `--title` TITLE - New video title
|
|
157
|
+
- `-d` / `--description` DESC - New description
|
|
158
|
+
- `-g` / `--tags` TAGS - Comma-separated tags
|
|
159
|
+
- `-c` / `--category-id` ID - YouTube category ID
|
|
160
|
+
|
|
161
|
+
**Output**: Confirmation of updated fields
|
|
162
|
+
|
|
163
|
+
### PromptCompletionAction
|
|
164
|
+
|
|
165
|
+
⚠️ **DEPRECATED**: Uses legacy OpenAI API. See prompt-tools.md.
|
|
166
|
+
|
|
167
|
+
Generates text completions:
|
|
168
|
+
|
|
169
|
+
```ruby
|
|
170
|
+
action = Appydave::Tools::CliActions::PromptCompletionAction.new
|
|
171
|
+
action.action(['-p', 'Write a haiku about programming'])
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Options**:
|
|
175
|
+
- `-p` / `--prompt` TEXT - Prompt text (required)
|
|
176
|
+
- `-m` / `--model` MODEL - Model name (default: text-davinci-003)
|
|
177
|
+
- `-t` / `--temperature` NUM - Randomness 0-2
|
|
178
|
+
- `-l` / `--max-tokens` NUM - Max response length
|
|
179
|
+
|
|
180
|
+
**Note**: Uses deprecated API, plan migration to modern alternatives.
|
|
181
|
+
|
|
182
|
+
## Use Cases for AI Agents
|
|
183
|
+
|
|
184
|
+
### 1. Building Custom Actions
|
|
185
|
+
```ruby
|
|
186
|
+
# AI creates new CLI action for specific task
|
|
187
|
+
# Inherits from BaseAction, implements template methods
|
|
188
|
+
class MyAction < BaseAction
|
|
189
|
+
protected
|
|
190
|
+
def define_options(opts, options)
|
|
191
|
+
# Define CLI options
|
|
192
|
+
end
|
|
193
|
+
def validate_options(options)
|
|
194
|
+
# Validate inputs
|
|
195
|
+
end
|
|
196
|
+
def execute(options)
|
|
197
|
+
# Do work
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
```
|
|
201
|
+
**AI discovers**: Template pattern, structure. Can build new CLI tools quickly.
|
|
202
|
+
|
|
203
|
+
### 2. Action Composition
|
|
204
|
+
```ruby
|
|
205
|
+
# AI chains multiple actions
|
|
206
|
+
get_action = GetVideoAction.new
|
|
207
|
+
get_action.action(['-v', video_id])
|
|
208
|
+
|
|
209
|
+
update_action = UpdateVideoAction.new
|
|
210
|
+
update_action.action(['-v', video_id, '-t', 'Updated Title'])
|
|
211
|
+
```
|
|
212
|
+
**AI discovers**: How to orchestrate multiple operations. Can build workflows.
|
|
213
|
+
|
|
214
|
+
### 3. Error Handling
|
|
215
|
+
```ruby
|
|
216
|
+
# AI wraps actions with error handling
|
|
217
|
+
begin
|
|
218
|
+
action = MyAction.new
|
|
219
|
+
action.action(args)
|
|
220
|
+
rescue ArgumentError => e
|
|
221
|
+
puts "Validation error: #{e.message}"
|
|
222
|
+
rescue => e
|
|
223
|
+
puts "Execution error: #{e.message}"
|
|
224
|
+
end
|
|
225
|
+
```
|
|
226
|
+
**AI discovers**: Error handling patterns. Can build robust CLI tools.
|
|
227
|
+
|
|
228
|
+
### 4. Option Preprocessing
|
|
229
|
+
```ruby
|
|
230
|
+
# AI modifies options before execution
|
|
231
|
+
action = MyAction.new
|
|
232
|
+
options = parse_custom_format(input)
|
|
233
|
+
# Transform to standard format
|
|
234
|
+
standard_options = transform_to_action_format(options)
|
|
235
|
+
action.action(standard_options)
|
|
236
|
+
```
|
|
237
|
+
**AI discovers**: Option flow. Can preprocess inputs for actions.
|
|
238
|
+
|
|
239
|
+
### 5. Batch Action Execution
|
|
240
|
+
```ruby
|
|
241
|
+
# AI executes action multiple times
|
|
242
|
+
items.each do |item|
|
|
243
|
+
action = MyAction.new
|
|
244
|
+
action.action(['-i', item])
|
|
245
|
+
end
|
|
246
|
+
```
|
|
247
|
+
**AI discovers**: Repetition pattern. Can automate batch operations.
|
|
248
|
+
|
|
249
|
+
### 6. Action Validation
|
|
250
|
+
```ruby
|
|
251
|
+
# AI tests action definition
|
|
252
|
+
action = MyAction.new
|
|
253
|
+
test_options = ['-required', 'value']
|
|
254
|
+
begin
|
|
255
|
+
action.action(test_options)
|
|
256
|
+
rescue ArgumentError => e
|
|
257
|
+
puts "Validation working: #{e.message}"
|
|
258
|
+
end
|
|
259
|
+
```
|
|
260
|
+
**AI discovers**: Validation logic. Can test actions before deployment.
|
|
261
|
+
|
|
262
|
+
### 7. Help Message Extraction
|
|
263
|
+
```ruby
|
|
264
|
+
# AI generates documentation from actions
|
|
265
|
+
action = MyAction.new
|
|
266
|
+
usage = action.command_usage
|
|
267
|
+
# Generate docs from action definition
|
|
268
|
+
```
|
|
269
|
+
**AI discovers**: Command structure. Can auto-generate documentation.
|
|
270
|
+
|
|
271
|
+
### 8. Dynamic Action Creation
|
|
272
|
+
```ruby
|
|
273
|
+
# AI creates actions dynamically
|
|
274
|
+
action_class = Class.new(BaseAction) do
|
|
275
|
+
protected
|
|
276
|
+
def define_options(opts, options)
|
|
277
|
+
# ...
|
|
278
|
+
end
|
|
279
|
+
def validate_options(options)
|
|
280
|
+
# ...
|
|
281
|
+
end
|
|
282
|
+
def execute(options)
|
|
283
|
+
# ...
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
action = action_class.new
|
|
288
|
+
action.action(args)
|
|
289
|
+
```
|
|
290
|
+
**AI discovers**: Metaprogramming patterns. Can generate actions on-the-fly.
|
|
291
|
+
|
|
292
|
+
### 9. Action Composition Framework
|
|
293
|
+
```ruby
|
|
294
|
+
# AI builds workflow from action definitions
|
|
295
|
+
workflow = [
|
|
296
|
+
{ action: GetVideoAction, args: ['-v', video_id] },
|
|
297
|
+
{ action: UpdateVideoAction, args: ['-v', video_id, '-t', new_title] },
|
|
298
|
+
{ action: PublishAction, args: ['-v', video_id] }
|
|
299
|
+
]
|
|
300
|
+
|
|
301
|
+
workflow.each do |step|
|
|
302
|
+
action = step[:action].new
|
|
303
|
+
action.action(step[:args])
|
|
304
|
+
end
|
|
305
|
+
```
|
|
306
|
+
**AI discovers**: Workflow composition. Can orchestrate complex processes.
|
|
307
|
+
|
|
308
|
+
### 10. Template Enforcement
|
|
309
|
+
```ruby
|
|
310
|
+
# AI validates that all actions follow template
|
|
311
|
+
# Check that subclasses implement required methods
|
|
312
|
+
unless MyAction.instance_methods(false).include?(:execute)
|
|
313
|
+
raise "Action must implement execute method"
|
|
314
|
+
end
|
|
315
|
+
```
|
|
316
|
+
**AI discovers**: Pattern compliance. Can enforce architecture.
|
|
317
|
+
|
|
318
|
+
## Creating Custom Actions
|
|
319
|
+
|
|
320
|
+
### Step 1: Define the Class
|
|
321
|
+
|
|
322
|
+
```ruby
|
|
323
|
+
module Appydave
|
|
324
|
+
module Tools
|
|
325
|
+
module CliActions
|
|
326
|
+
class EmailAction < BaseAction
|
|
327
|
+
protected
|
|
328
|
+
|
|
329
|
+
def define_options(opts, options)
|
|
330
|
+
opts.on('-t', '--to EMAIL', 'Recipient email') { |v| options[:to] = v }
|
|
331
|
+
opts.on('-s', '--subject TEXT', 'Email subject') { |v| options[:subject] = v }
|
|
332
|
+
opts.on('-b', '--body TEXT', 'Email body') { |v| options[:body] = v }
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def validate_options(options)
|
|
336
|
+
raise ArgumentError, 'Recipient required' unless options[:to]
|
|
337
|
+
raise ArgumentError, 'Subject required' unless options[:subject]
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def execute(options)
|
|
341
|
+
# Send email logic
|
|
342
|
+
puts "Sending email to #{options[:to]}"
|
|
343
|
+
puts "Subject: #{options[:subject]}"
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Step 2: Test the Action
|
|
352
|
+
|
|
353
|
+
```ruby
|
|
354
|
+
action = EmailAction.new
|
|
355
|
+
action.action(['-t', 'user@example.com', '-s', 'Hello'])
|
|
356
|
+
# Output: Sending email to user@example.com
|
|
357
|
+
# Subject: Hello
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Step 3: Integrate with CLI
|
|
361
|
+
|
|
362
|
+
```ruby
|
|
363
|
+
# In your CLI script
|
|
364
|
+
class MyCLI
|
|
365
|
+
def initialize
|
|
366
|
+
@commands = {
|
|
367
|
+
'email' => Appydave::Tools::CliActions::EmailAction.new
|
|
368
|
+
}
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
def run
|
|
372
|
+
command, *args = ARGV
|
|
373
|
+
@commands[command].action(args) if @commands[command]
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
## Best Practices
|
|
379
|
+
|
|
380
|
+
1. **Validate early**: Check all required options in validate_options
|
|
381
|
+
2. **Fail fast**: Raise ArgumentError immediately if validation fails
|
|
382
|
+
3. **Clear messages**: Provide specific error messages for validation failures
|
|
383
|
+
4. **Define all options**: Document every option in define_options
|
|
384
|
+
5. **Keep execute focused**: One action per class, single responsibility
|
|
385
|
+
6. **Test thoroughly**: Test each action independently before using
|
|
386
|
+
7. **Document options**: Add comments explaining what options do
|
|
387
|
+
8. **Handle errors gracefully**: Catch and report errors in execute
|
|
388
|
+
|
|
389
|
+
## Example: Complete Action
|
|
390
|
+
|
|
391
|
+
```ruby
|
|
392
|
+
module Appydave
|
|
393
|
+
module Tools
|
|
394
|
+
module CliActions
|
|
395
|
+
class FetchDataAction < BaseAction
|
|
396
|
+
protected
|
|
397
|
+
|
|
398
|
+
def define_options(opts, options)
|
|
399
|
+
opts.on('-u', '--url URL', 'API endpoint') { |v| options[:url] = v }
|
|
400
|
+
opts.on('-f', '--format FORMAT', 'Output format') { |v| options[:format] = v }
|
|
401
|
+
opts.on('-t', '--timeout SEC', Integer, 'Request timeout') { |v| options[:timeout] = v }
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
def validate_options(options)
|
|
405
|
+
raise ArgumentError, 'URL required' unless options[:url]
|
|
406
|
+
options[:format] ||= 'json'
|
|
407
|
+
options[:timeout] ||= 30
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def execute(options)
|
|
411
|
+
url = options[:url]
|
|
412
|
+
format = options[:format]
|
|
413
|
+
timeout = options[:timeout]
|
|
414
|
+
|
|
415
|
+
puts "Fetching from #{url}"
|
|
416
|
+
puts "Format: #{format}"
|
|
417
|
+
puts "Timeout: #{timeout}s"
|
|
418
|
+
|
|
419
|
+
# Actual fetch logic here
|
|
420
|
+
end
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
## Troubleshooting
|
|
428
|
+
|
|
429
|
+
| Issue | Solution |
|
|
430
|
+
|-------|----------|
|
|
431
|
+
| "Unknown option" | Define option in define_options with opts.on |
|
|
432
|
+
| "Validation error" | Check validate_options, ensure required options set |
|
|
433
|
+
| "Method not implemented" | Define execute method in subclass |
|
|
434
|
+
| "Wrong argument count" | Check action() is called with args array |
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
438
|
+
**Related Tools**:
|
|
439
|
+
- All CLI commands use CLI Actions framework
|
|
440
|
+
- `youtube_manager` - Uses GetVideoAction, UpdateVideoAction
|
|
441
|
+
- `prompt_tools` - Uses PromptCompletionAction (deprecated)
|
|
442
|
+
|
|
443
|
+
**Pattern**: Template Method Pattern for consistent CLI behavior
|
|
444
|
+
**Architecture**: Part of appydave-tools internal framework
|