openclacky 0.7.0 → 0.7.2
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/.clacky/skills/commit/SKILL.md +29 -4
- data/.clackyrules +3 -1
- data/CHANGELOG.md +103 -2
- data/README.md +70 -161
- data/bin/clarky +11 -0
- data/docs/HOW-TO-USE-CN.md +96 -0
- data/docs/HOW-TO-USE.md +94 -0
- data/docs/config.example.yml +27 -0
- data/docs/deploy_subagent_design.md +540 -0
- data/docs/time_machine_design.md +247 -0
- data/docs/why-openclacky.md +0 -1
- data/lib/clacky/agent/cost_tracker.rb +180 -0
- data/lib/clacky/agent/llm_caller.rb +54 -0
- data/lib/clacky/{message_compressor.rb → agent/message_compressor.rb} +12 -36
- data/lib/clacky/agent/message_compressor_helper.rb +534 -0
- data/lib/clacky/agent/session_serializer.rb +152 -0
- data/lib/clacky/agent/skill_manager.rb +138 -0
- data/lib/clacky/agent/system_prompt_builder.rb +96 -0
- data/lib/clacky/agent/time_machine.rb +199 -0
- data/lib/clacky/agent/tool_executor.rb +434 -0
- data/lib/clacky/{tool_registry.rb → agent/tool_registry.rb} +1 -1
- data/lib/clacky/agent.rb +260 -1370
- data/lib/clacky/agent_config.rb +447 -10
- data/lib/clacky/cli.rb +275 -98
- data/lib/clacky/client.rb +12 -2
- data/lib/clacky/default_skills/code-explorer/SKILL.md +34 -0
- data/lib/clacky/default_skills/deploy/SKILL.md +13 -0
- data/lib/clacky/default_skills/deploy/scripts/rails_deploy.rb +383 -0
- data/lib/clacky/default_skills/deploy/tools/check_health.rb +116 -0
- data/lib/clacky/default_skills/deploy/tools/execute_deployment.rb +174 -0
- data/lib/clacky/default_skills/deploy/tools/fetch_runtime_logs.rb +67 -0
- data/lib/clacky/default_skills/deploy/tools/list_services.rb +80 -0
- data/lib/clacky/default_skills/deploy/tools/report_deploy_status.rb +67 -0
- data/lib/clacky/default_skills/deploy/tools/set_deploy_variables.rb +138 -0
- data/lib/clacky/default_skills/new/SKILL.md +2 -2
- data/lib/clacky/json_ui_controller.rb +195 -0
- data/lib/clacky/providers.rb +107 -0
- data/lib/clacky/skill.rb +48 -7
- data/lib/clacky/skill_loader.rb +7 -0
- data/lib/clacky/tools/edit.rb +105 -48
- data/lib/clacky/tools/file_reader.rb +44 -73
- data/lib/clacky/tools/invoke_skill.rb +89 -0
- data/lib/clacky/tools/list_tasks.rb +54 -0
- data/lib/clacky/tools/redo_task.rb +41 -0
- data/lib/clacky/tools/safe_shell.rb +1 -1
- data/lib/clacky/tools/shell.rb +74 -62
- data/lib/clacky/tools/trash_manager.rb +1 -1
- data/lib/clacky/tools/undo_task.rb +32 -0
- data/lib/clacky/tools/web_fetch.rb +2 -1
- data/lib/clacky/ui2/components/command_suggestions.rb +13 -3
- data/lib/clacky/ui2/components/inline_input.rb +23 -2
- data/lib/clacky/ui2/components/input_area.rb +65 -21
- data/lib/clacky/ui2/components/modal_component.rb +199 -62
- data/lib/clacky/ui2/layout_manager.rb +75 -25
- data/lib/clacky/ui2/line_editor.rb +23 -2
- data/lib/clacky/ui2/markdown_renderer.rb +31 -10
- data/lib/clacky/ui2/screen_buffer.rb +2 -0
- data/lib/clacky/ui2/ui_controller.rb +316 -37
- data/lib/clacky/ui2.rb +2 -0
- data/lib/clacky/ui_interface.rb +50 -0
- data/lib/clacky/utils/arguments_parser.rb +31 -3
- data/lib/clacky/utils/file_processor.rb +13 -18
- data/lib/clacky/version.rb +1 -1
- data/lib/clacky.rb +19 -9
- data/scripts/install.sh +274 -97
- data/scripts/uninstall.sh +12 -12
- metadata +40 -13
- data/.clacky/skills/test-skill/SKILL.md +0 -15
- data/lib/clacky/compression/base.rb +0 -231
- data/lib/clacky/compression/standard.rb +0 -339
- data/lib/clacky/config.rb +0 -117
- /data/lib/clacky/{hook_manager.rb → agent/hook_manager.rb} +0 -0
- /data/lib/clacky/{progress_indicator.rb → ui2/progress_indicator.rb} +0 -0
- /data/lib/clacky/{thinking_verbs.rb → ui2/thinking_verbs.rb} +0 -0
- /data/lib/clacky/{gitignore_parser.rb → utils/gitignore_parser.rb} +0 -0
- /data/lib/clacky/{model_pricing.rb → utils/model_pricing.rb} +0 -0
- /data/lib/clacky/{trash_directory.rb → utils/trash_directory.rb} +0 -0
data/docs/HOW-TO-USE.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# How to Use OpenClacky
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
gem install openclacky
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
**Requirements:** Ruby >= 3.1
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### 1. Start Clacky
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
clacky
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. Configure API Key (First Time)
|
|
20
|
+
|
|
21
|
+
In the chat interface, type:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
/config
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then follow the prompts to set your API key:
|
|
28
|
+
- **OpenAI**: Get key from https://platform.openai.com/api-keys
|
|
29
|
+
- **Anthropic**: Get key from https://console.anthropic.com/
|
|
30
|
+
|
|
31
|
+
### 3. Start Chatting
|
|
32
|
+
|
|
33
|
+
Just type your questions or requests in the chat:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
Help me write a Ruby script to parse CSV files
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
Create a web scraper for extracting article titles
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Key Features
|
|
44
|
+
|
|
45
|
+
### 🎯 Autonomous Agent Mode
|
|
46
|
+
Clacky can automatically execute complex tasks using built-in tools:
|
|
47
|
+
- **File Operations**: Read, write, edit, search files
|
|
48
|
+
- **Web Access**: Browse and search the web
|
|
49
|
+
- **Code Execution**: Run shell commands and test code
|
|
50
|
+
- **Project Management**: Git operations, testing, deployment
|
|
51
|
+
|
|
52
|
+
### 🔌 Skill System
|
|
53
|
+
Use powerful skills with simple shorthand commands:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
/commit # Smart git commit helper
|
|
57
|
+
/gem-release # Automated gem publishing
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Create your own skills in `.clacky/skills/` directory!
|
|
61
|
+
|
|
62
|
+
### 💬 Smart Memory Management
|
|
63
|
+
- **Automatic compression** for long conversations
|
|
64
|
+
- **Context preservation** while reducing token costs
|
|
65
|
+
- **Intelligent summarization** of conversation history
|
|
66
|
+
|
|
67
|
+
### ⚙️ Easy Configuration
|
|
68
|
+
- Interactive setup wizard
|
|
69
|
+
- Support for multiple API providers
|
|
70
|
+
- Cost tracking and usage limits
|
|
71
|
+
- Smart defaults for common use cases
|
|
72
|
+
|
|
73
|
+
## Common Commands in Chat
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
/config # Configure API settings
|
|
77
|
+
/help # Show available commands
|
|
78
|
+
/skills # List available skills
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Why Choose OpenClacky?
|
|
82
|
+
|
|
83
|
+
✅ **Simple Setup** - Just `gem install` and start chatting
|
|
84
|
+
✅ **Powerful Agent** - Executes complex tasks autonomously
|
|
85
|
+
✅ **Extensible** - Create custom skills for your workflows
|
|
86
|
+
✅ **Cost-Effective** - Smart memory compression saves tokens
|
|
87
|
+
✅ **Multi-Provider** - Works with OpenAI and Anthropic
|
|
88
|
+
✅ **Well-Tested** - 367+ passing tests ensure reliability
|
|
89
|
+
|
|
90
|
+
## Learn More
|
|
91
|
+
|
|
92
|
+
- GitHub: https://github.com/clacky-ai/open-clacky
|
|
93
|
+
- Report Issues: https://github.com/clacky-ai/open-clacky/issues
|
|
94
|
+
- Version: 0.7.0
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Clacky Configuration File
|
|
2
|
+
# This is a top-level array of model configurations
|
|
3
|
+
# The first model in the array is used as the default
|
|
4
|
+
|
|
5
|
+
# Claude Sonnet 4 (default - first in array)
|
|
6
|
+
- model: "claude-sonnet-4"
|
|
7
|
+
api_key: "your-api-key-here"
|
|
8
|
+
base_url: "https://api.anthropic.com"
|
|
9
|
+
anthropic_format: true
|
|
10
|
+
|
|
11
|
+
# Claude Opus 4
|
|
12
|
+
- model: "claude-opus-4"
|
|
13
|
+
api_key: "your-api-key-here"
|
|
14
|
+
base_url: "https://api.anthropic.com"
|
|
15
|
+
anthropic_format: true
|
|
16
|
+
|
|
17
|
+
# OpenAI GPT-4
|
|
18
|
+
- model: "gpt-4"
|
|
19
|
+
api_key: "your-openai-api-key-here"
|
|
20
|
+
base_url: "https://api.openai.com/v1"
|
|
21
|
+
anthropic_format: false
|
|
22
|
+
|
|
23
|
+
# Custom model (e.g., local or third-party)
|
|
24
|
+
- model: "custom-model"
|
|
25
|
+
api_key: "your-custom-api-key"
|
|
26
|
+
base_url: "https://your-api-endpoint.com"
|
|
27
|
+
anthropic_format: false
|
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
# Deploy Feature Design Document
|
|
2
|
+
|
|
3
|
+
## 1. Overview
|
|
4
|
+
|
|
5
|
+
This document describes the design of the deployment feature for OpenClacky that deploys user projects to Railway PaaS.
|
|
6
|
+
|
|
7
|
+
### 1.1 Dual-Mode Approach
|
|
8
|
+
|
|
9
|
+
The deployment feature uses **two distinct modes** to balance precision and flexibility:
|
|
10
|
+
|
|
11
|
+
1. **Rails Mode** (Priority)
|
|
12
|
+
- Fixed 8-step script execution
|
|
13
|
+
- No AI decision-making, pure automation
|
|
14
|
+
- Fast, predictable, and precise
|
|
15
|
+
- For standard Rails projects only
|
|
16
|
+
|
|
17
|
+
2. **Generic Mode**
|
|
18
|
+
- AI-guided subagent (DeployRole)
|
|
19
|
+
- Intelligent analysis and decision-making
|
|
20
|
+
- Flexible handling of edge cases
|
|
21
|
+
- For non-Rails or non-standard projects
|
|
22
|
+
|
|
23
|
+
**Design Philosophy**: Rails projects get precise, automated deployment; everything else gets intelligent, adaptive deployment.
|
|
24
|
+
|
|
25
|
+
### 1.2 Goals
|
|
26
|
+
|
|
27
|
+
- Port deployment functionality from clacky-ai-agent to OpenClacky (Ruby)
|
|
28
|
+
- Prioritize Rails project deployment (OpenClacky's primary focus)
|
|
29
|
+
- Maintain generality for other project types (Node.js, Python, etc.)
|
|
30
|
+
- Provide fast, reliable deployment experience
|
|
31
|
+
|
|
32
|
+
### 1.3 Reference Implementation
|
|
33
|
+
|
|
34
|
+
- Source project: `~/workspace/clacky-ai-agent`
|
|
35
|
+
- Key files:
|
|
36
|
+
- `heracles/agent_roles/deploy_role/` - DeployRole implementation
|
|
37
|
+
- `heracles/agent_workspace/tools/deploy.py` - Deployment tools
|
|
38
|
+
- `heracles/agent_workspace/deployment/deployment.py` - Deployment logic
|
|
39
|
+
|
|
40
|
+
## 2. Architecture Design
|
|
41
|
+
|
|
42
|
+
### 2.1 Overall Architecture
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
User: "Deploy my project"
|
|
46
|
+
↓
|
|
47
|
+
invoke_skill('deploy', task: 'Deploy project')
|
|
48
|
+
↓
|
|
49
|
+
Deploy Skill (SKILL.md) - Project Type Detection
|
|
50
|
+
↓
|
|
51
|
+
├─── Rails Project Detected
|
|
52
|
+
│ (Gemfile + config/database.yml exist)
|
|
53
|
+
│ ↓
|
|
54
|
+
│ Execute rails_deploy.rb Template
|
|
55
|
+
│ ├─ Step 1: List services
|
|
56
|
+
│ ├─ Step 2: Check first deployment
|
|
57
|
+
│ ├─ Step 3: Set Rails env vars
|
|
58
|
+
│ ├─ Step 4: Execute deployment
|
|
59
|
+
│ ├─ Step 5: Run db:migrate
|
|
60
|
+
│ ├─ Step 6: Run db:seed (if first)
|
|
61
|
+
│ ├─ Step 7: Health check
|
|
62
|
+
│ └─ Step 8: Report success
|
|
63
|
+
│ ↓
|
|
64
|
+
│ Return result (synchronous)
|
|
65
|
+
│
|
|
66
|
+
└─── Non-Rails Project
|
|
67
|
+
(Node.js / Python / Generic)
|
|
68
|
+
↓
|
|
69
|
+
Fork DeployRole Subagent
|
|
70
|
+
├─ Phase 1: Analyzing (AI analyzes)
|
|
71
|
+
├─ Phase 2: Deploying (AI deploys)
|
|
72
|
+
└─ Phase 3: Checking (AI verifies)
|
|
73
|
+
↓
|
|
74
|
+
Return result (synchronous)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 2.2 Component Structure
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
default_skills/deploy/
|
|
81
|
+
├── SKILL.md # Deploy skill entry point
|
|
82
|
+
│ # - Detects project type
|
|
83
|
+
│ # - Routes to Rails template or Generic subagent
|
|
84
|
+
│
|
|
85
|
+
├── templates/
|
|
86
|
+
│ └── rails_deploy.rb # Fixed 8-step Rails deployment script
|
|
87
|
+
│ # - No AI decision-making
|
|
88
|
+
│ # - Precise, automated execution
|
|
89
|
+
│
|
|
90
|
+
├── subagent/
|
|
91
|
+
│ └── DEPLOY_ROLE.md # Generic deployment subagent system prompt
|
|
92
|
+
│ # - 3-phase AI-guided workflow
|
|
93
|
+
│ # - Intelligent analysis and adaptation
|
|
94
|
+
│
|
|
95
|
+
└── tools/ # Deployment tools (used by both modes)
|
|
96
|
+
├── list_services.rb # List Railway services
|
|
97
|
+
├── report_deploy_status.rb # Report deployment status
|
|
98
|
+
├── execute_deployment.rb # Execute deployment
|
|
99
|
+
├── set_deploy_variables.rb # Set environment variables
|
|
100
|
+
├── fetch_runtime_logs.rb # Fetch runtime logs
|
|
101
|
+
└── check_health.rb # Health check
|
|
102
|
+
|
|
103
|
+
docs/
|
|
104
|
+
└── deploy_subagent_design.md # This document
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 3. Project Type Detection
|
|
108
|
+
|
|
109
|
+
### 3.1 Detection Logic
|
|
110
|
+
|
|
111
|
+
The Deploy skill (SKILL.md) performs project type detection:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
# Pseudocode
|
|
115
|
+
def detect_project_type
|
|
116
|
+
if File.exist?('Gemfile') && File.exist?('config/database.yml')
|
|
117
|
+
:rails
|
|
118
|
+
elsif File.exist?('package.json')
|
|
119
|
+
:nodejs
|
|
120
|
+
else
|
|
121
|
+
:generic
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 3.2 Routing Decision
|
|
127
|
+
|
|
128
|
+
- **Rails detected** → Execute `templates/rails_deploy.rb`
|
|
129
|
+
- **Non-Rails detected** → Fork DeployRole subagent with `subagent/DEPLOY_ROLE.md`
|
|
130
|
+
|
|
131
|
+
## 4. Rails Mode Design
|
|
132
|
+
|
|
133
|
+
### 4.1 Rails Template Script
|
|
134
|
+
|
|
135
|
+
**File**: `default_skills/deploy/templates/rails_deploy.rb`
|
|
136
|
+
|
|
137
|
+
**Purpose**: Fixed, non-AI script that executes precise deployment steps.
|
|
138
|
+
|
|
139
|
+
**Characteristics**:
|
|
140
|
+
- No AI decision-making
|
|
141
|
+
- No deviation from script
|
|
142
|
+
- Fast execution
|
|
143
|
+
- Predictable results
|
|
144
|
+
|
|
145
|
+
### 4.2 Rails Deployment Steps
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
# Step 1: List Services
|
|
149
|
+
services = call_tool('list_services')
|
|
150
|
+
main_service = services.find { |s| s['type'] == 'web' }
|
|
151
|
+
db_service = services.find { |s| s['type'] == 'postgres' || s['type'] == 'mysql' }
|
|
152
|
+
|
|
153
|
+
# Step 2: Check First Deployment
|
|
154
|
+
is_first_deployment = main_service['deployments'].empty?
|
|
155
|
+
|
|
156
|
+
# Step 3: Set Rails Environment Variables
|
|
157
|
+
variables = {
|
|
158
|
+
'RAILS_ENV' => 'production',
|
|
159
|
+
'SECRET_KEY_BASE' => get_or_prompt('SECRET_KEY_BASE'),
|
|
160
|
+
'RAILS_SERVE_STATIC_FILES' => 'true',
|
|
161
|
+
'RAILS_LOG_TO_STDOUT' => 'true'
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
# Add DATABASE_URL reference
|
|
165
|
+
ref_variables = {
|
|
166
|
+
'DATABASE_URL' => "#{db_service['name']}.DATABASE_URL"
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
call_tool('set_deploy_variables',
|
|
170
|
+
service: main_service['name'],
|
|
171
|
+
variables: variables,
|
|
172
|
+
ref_variables: ref_variables
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# Step 4: Execute Deployment
|
|
176
|
+
call_tool('execute_deployment', service: main_service['name'])
|
|
177
|
+
|
|
178
|
+
# Step 5: Run Database Migrations
|
|
179
|
+
run_railway_command(service: main_service['name'],
|
|
180
|
+
command: 'rake db:migrate')
|
|
181
|
+
|
|
182
|
+
# Step 6: Run Database Seeds (first deployment only)
|
|
183
|
+
if is_first_deployment
|
|
184
|
+
run_railway_command(service: main_service['name'],
|
|
185
|
+
command: 'rake db:seed')
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Step 7: Health Check
|
|
189
|
+
public_url = main_service['public_url']
|
|
190
|
+
call_tool('check_health', url: public_url, path: '/')
|
|
191
|
+
|
|
192
|
+
# Step 8: Report Success
|
|
193
|
+
call_tool('report_deploy_status',
|
|
194
|
+
status: 'success',
|
|
195
|
+
message: "Rails app deployed successfully to #{public_url}"
|
|
196
|
+
)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 4.3 Rails-Specific Features
|
|
200
|
+
|
|
201
|
+
1. **Automatic database.yml parsing**
|
|
202
|
+
2. **Rails environment variables** (RAILS_ENV, SECRET_KEY_BASE, etc.)
|
|
203
|
+
3. **Database migrations** (db:migrate)
|
|
204
|
+
4. **Database seeding** (db:seed on first deploy)
|
|
205
|
+
5. **Asset precompilation** (if needed)
|
|
206
|
+
|
|
207
|
+
## 5. Generic Mode Design
|
|
208
|
+
|
|
209
|
+
### 5.1 DeployRole Subagent
|
|
210
|
+
|
|
211
|
+
**File**: `default_skills/deploy/subagent/DEPLOY_ROLE.md`
|
|
212
|
+
|
|
213
|
+
**Purpose**: AI-guided deployment for non-standard or non-Rails projects.
|
|
214
|
+
|
|
215
|
+
**Characteristics**:
|
|
216
|
+
- Full AI decision-making
|
|
217
|
+
- Adaptive to project structure
|
|
218
|
+
- Handles edge cases
|
|
219
|
+
- 3-phase workflow
|
|
220
|
+
|
|
221
|
+
### 5.2 System Prompt Structure
|
|
222
|
+
|
|
223
|
+
```markdown
|
|
224
|
+
You are DeployRole, a deployment specialist for Railway PaaS.
|
|
225
|
+
|
|
226
|
+
Your task is to deploy the user's project using a 3-phase workflow.
|
|
227
|
+
|
|
228
|
+
## Phase 1: Analyzing
|
|
229
|
+
|
|
230
|
+
1. Use list_services to see existing Railway services
|
|
231
|
+
2. Detect project type (Node.js, Python, etc.) by reading project files
|
|
232
|
+
3. Analyze environment variable requirements (.env, .env.example)
|
|
233
|
+
4. Use collect_user_input to gather missing credentials
|
|
234
|
+
5. Report status: report_deploy_status(status='analyzing', message='...')
|
|
235
|
+
|
|
236
|
+
## Phase 2: Deploying
|
|
237
|
+
|
|
238
|
+
1. Use set_deploy_variables to configure environment
|
|
239
|
+
2. Use execute_deployment to deploy the service
|
|
240
|
+
3. Monitor deployment progress
|
|
241
|
+
4. If deployment fails, use fetch_runtime_logs to diagnose
|
|
242
|
+
5. Report status: report_deploy_status(status='deploying', message='...')
|
|
243
|
+
|
|
244
|
+
## Phase 3: Checking
|
|
245
|
+
|
|
246
|
+
1. Wait for public URL to be available
|
|
247
|
+
2. Use check_health to verify application is responding
|
|
248
|
+
3. Verify critical functionality (if applicable)
|
|
249
|
+
4. Report final status: report_deploy_status(status='success'|'failed', message='...')
|
|
250
|
+
|
|
251
|
+
## Available Tools
|
|
252
|
+
|
|
253
|
+
- list_services
|
|
254
|
+
- report_deploy_status
|
|
255
|
+
- execute_deployment
|
|
256
|
+
- set_deploy_variables
|
|
257
|
+
- fetch_runtime_logs
|
|
258
|
+
- check_health
|
|
259
|
+
- read_file
|
|
260
|
+
- search_codebase
|
|
261
|
+
- safe_shell
|
|
262
|
+
- collect_user_input
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### 5.3 Generic Mode Workflow
|
|
266
|
+
|
|
267
|
+
Unlike Rails mode, the subagent:
|
|
268
|
+
- **Analyzes** the project structure intelligently
|
|
269
|
+
- **Adapts** to different frameworks and configurations
|
|
270
|
+
- **Decides** what commands to run based on context
|
|
271
|
+
- **Handles** errors with fallback strategies
|
|
272
|
+
|
|
273
|
+
## 6. Deployment Tools Design
|
|
274
|
+
|
|
275
|
+
All tools are **shared** between Rails and Generic modes.
|
|
276
|
+
|
|
277
|
+
### 6.1 list_services
|
|
278
|
+
|
|
279
|
+
**Purpose**: List all Railway services with environment variables.
|
|
280
|
+
|
|
281
|
+
**Parameters**: None
|
|
282
|
+
|
|
283
|
+
**Returns**: Array of service objects with masked sensitive data
|
|
284
|
+
|
|
285
|
+
**Implementation**: Wraps `clackycli service list --json`
|
|
286
|
+
|
|
287
|
+
### 6.2 report_deploy_status
|
|
288
|
+
|
|
289
|
+
**Purpose**: Report deployment status to user.
|
|
290
|
+
|
|
291
|
+
**Parameters**:
|
|
292
|
+
- `status`: analyzing | deploying | checking | success | failed
|
|
293
|
+
- `message`: Status message
|
|
294
|
+
|
|
295
|
+
**Implementation**: Outputs formatted status message
|
|
296
|
+
|
|
297
|
+
### 6.3 execute_deployment
|
|
298
|
+
|
|
299
|
+
**Purpose**: Execute deployment and monitor until completion.
|
|
300
|
+
|
|
301
|
+
**Parameters**:
|
|
302
|
+
- `service_name`: Service to deploy
|
|
303
|
+
|
|
304
|
+
**Implementation**:
|
|
305
|
+
- Runs `clackycli up -s SERVICE_NAME -d`
|
|
306
|
+
- Monitors deployment status
|
|
307
|
+
- Returns when complete or failed
|
|
308
|
+
|
|
309
|
+
### 6.4 set_deploy_variables
|
|
310
|
+
|
|
311
|
+
**Purpose**: Set environment variables for a service.
|
|
312
|
+
|
|
313
|
+
**Parameters**:
|
|
314
|
+
- `service_name`: Target service
|
|
315
|
+
- `variables`: Hash of KEY => VALUE (simple variables)
|
|
316
|
+
- `ref_variables`: Hash of KEY => SERVICE.VAR (reference variables)
|
|
317
|
+
|
|
318
|
+
**Implementation**: Runs `clackycli variables -s SERVICE --set KEY=VALUE`
|
|
319
|
+
|
|
320
|
+
**Security**: Masks sensitive variable names (PASSWORD, SECRET, API_KEY, TOKEN)
|
|
321
|
+
|
|
322
|
+
### 6.5 fetch_runtime_logs
|
|
323
|
+
|
|
324
|
+
**Purpose**: Fetch runtime logs from deployed service.
|
|
325
|
+
|
|
326
|
+
**Parameters**:
|
|
327
|
+
- `service_name`: Service to fetch logs from
|
|
328
|
+
- `lines`: Number of lines (default: 100)
|
|
329
|
+
|
|
330
|
+
**Implementation**: Runs `clackycli logs --lines N`
|
|
331
|
+
|
|
332
|
+
### 6.6 check_health
|
|
333
|
+
|
|
334
|
+
**Purpose**: Perform HTTP health check on deployed application.
|
|
335
|
+
|
|
336
|
+
**Parameters**:
|
|
337
|
+
- `url`: Optional, defaults to RAILWAY_PUBLIC_DOMAIN
|
|
338
|
+
- `path`: Health check path, default "/"
|
|
339
|
+
- `timeout`: Request timeout in seconds, default 30
|
|
340
|
+
|
|
341
|
+
**Implementation**: HTTP GET request with timeout
|
|
342
|
+
|
|
343
|
+
## 7. Implementation Plan
|
|
344
|
+
|
|
345
|
+
### Phase 1: Core Tools (Week 1)
|
|
346
|
+
|
|
347
|
+
- [ ] Create skill directory structure: `default_skills/deploy/`
|
|
348
|
+
- [ ] Implement `list_services` tool
|
|
349
|
+
- [ ] Implement `report_deploy_status` tool
|
|
350
|
+
- [ ] Implement `set_deploy_variables` tool
|
|
351
|
+
- [ ] Write RSpec tests for core tools
|
|
352
|
+
|
|
353
|
+
### Phase 2: Deployment Tools (Week 2)
|
|
354
|
+
|
|
355
|
+
- [ ] Implement `execute_deployment` tool
|
|
356
|
+
- [ ] Implement `fetch_runtime_logs` tool
|
|
357
|
+
- [ ] Implement `check_health` tool
|
|
358
|
+
- [ ] Write integration tests
|
|
359
|
+
- [ ] Test all tools with Railway CLI
|
|
360
|
+
|
|
361
|
+
### Phase 3: Rails Mode (Week 3)
|
|
362
|
+
|
|
363
|
+
- [ ] Create `templates/rails_deploy.rb` script
|
|
364
|
+
- [ ] Implement 8-step Rails deployment workflow
|
|
365
|
+
- [ ] Add Rails project detection logic
|
|
366
|
+
- [ ] Test with real Rails projects
|
|
367
|
+
- [ ] Handle edge cases (missing SECRET_KEY_BASE, etc.)
|
|
368
|
+
|
|
369
|
+
### Phase 4: Generic Mode (Week 4)
|
|
370
|
+
|
|
371
|
+
- [ ] Create `subagent/DEPLOY_ROLE.md` system prompt
|
|
372
|
+
- [ ] Write comprehensive 3-phase workflow instructions
|
|
373
|
+
- [ ] Configure tool access for subagent
|
|
374
|
+
- [ ] Test with Node.js projects
|
|
375
|
+
- [ ] Test with Python projects
|
|
376
|
+
|
|
377
|
+
### Phase 5: Integration & Entry Point (Week 5)
|
|
378
|
+
|
|
379
|
+
- [ ] Create `SKILL.md` entry point
|
|
380
|
+
- [ ] Implement project type detection
|
|
381
|
+
- [ ] Implement routing logic (Rails vs Generic)
|
|
382
|
+
- [ ] End-to-end testing for both modes
|
|
383
|
+
- [ ] Error handling improvements
|
|
384
|
+
|
|
385
|
+
### Phase 6: Documentation & Polish (Week 6)
|
|
386
|
+
|
|
387
|
+
- [ ] User guide with examples
|
|
388
|
+
- [ ] API documentation
|
|
389
|
+
- [ ] Troubleshooting guide
|
|
390
|
+
- [ ] Performance optimization
|
|
391
|
+
- [ ] Security audit
|
|
392
|
+
|
|
393
|
+
## 8. Technical Decisions
|
|
394
|
+
|
|
395
|
+
### 8.1 CLI Tool Dependency
|
|
396
|
+
|
|
397
|
+
We depend on `clackycli` command-line tool for Railway operations.
|
|
398
|
+
|
|
399
|
+
**Commands used**:
|
|
400
|
+
- `clackycli service list --json` - List services
|
|
401
|
+
- `clackycli up -s SERVICE_NAME -d` - Deploy service
|
|
402
|
+
- `clackycli variables -s SERVICE_NAME --set KEY=VALUE` - Set variables
|
|
403
|
+
- `clackycli run -s SERVICE_NAME COMMAND` - Run commands
|
|
404
|
+
- `clackycli logs --lines N` - Fetch logs
|
|
405
|
+
|
|
406
|
+
### 8.2 Synchronous Execution
|
|
407
|
+
|
|
408
|
+
Both modes execute **synchronously** (user waits for completion).
|
|
409
|
+
No background/async execution.
|
|
410
|
+
|
|
411
|
+
**Rationale**:
|
|
412
|
+
- Simpler implementation
|
|
413
|
+
- Better error handling
|
|
414
|
+
- Clear user feedback
|
|
415
|
+
- Easier debugging
|
|
416
|
+
|
|
417
|
+
### 8.3 Rails Priority
|
|
418
|
+
|
|
419
|
+
Rails mode is implemented first and optimized for performance.
|
|
420
|
+
Generic mode is secondary but fully functional.
|
|
421
|
+
|
|
422
|
+
### 8.4 Tool Reusability
|
|
423
|
+
|
|
424
|
+
All tools are generic and reusable between modes.
|
|
425
|
+
No mode-specific tool implementations.
|
|
426
|
+
|
|
427
|
+
### 8.5 Error Handling
|
|
428
|
+
|
|
429
|
+
**Rails Mode**: Fail-fast with clear error messages
|
|
430
|
+
**Generic Mode**: AI attempts recovery, then fails with diagnosis
|
|
431
|
+
|
|
432
|
+
## 9. Security Considerations
|
|
433
|
+
|
|
434
|
+
1. **Mask sensitive environment variables**
|
|
435
|
+
- PASSWORD, SECRET, API_KEY, TOKEN, etc.
|
|
436
|
+
- Show only KEY=****** in logs
|
|
437
|
+
|
|
438
|
+
2. **Never modify CLACKY_* variables**
|
|
439
|
+
- System variables are protected
|
|
440
|
+
- Deployment tools skip them
|
|
441
|
+
|
|
442
|
+
3. **Use collect_user_input for secrets**
|
|
443
|
+
- Prompt with password type
|
|
444
|
+
- Never log secret values
|
|
445
|
+
|
|
446
|
+
4. **Sanitize command inputs**
|
|
447
|
+
- Validate service names
|
|
448
|
+
- Escape shell arguments
|
|
449
|
+
|
|
450
|
+
5. **Validate Railway CLI output**
|
|
451
|
+
- Parse JSON safely
|
|
452
|
+
- Handle missing fields gracefully
|
|
453
|
+
|
|
454
|
+
## 10. Success Criteria
|
|
455
|
+
|
|
456
|
+
### Rails Mode
|
|
457
|
+
1. ✓ Successfully deploy standard Rails projects
|
|
458
|
+
2. ✓ Handle first-time and subsequent deployments
|
|
459
|
+
3. ✓ Automatic database migration execution
|
|
460
|
+
4. ✓ Fast execution (< 5 minutes for typical project)
|
|
461
|
+
5. ✓ Clear progress reporting
|
|
462
|
+
|
|
463
|
+
### Generic Mode
|
|
464
|
+
1. ✓ Successfully deploy Node.js projects
|
|
465
|
+
2. ✓ Successfully deploy Python projects
|
|
466
|
+
3. ✓ Intelligent error diagnosis
|
|
467
|
+
4. ✓ Adaptive to different project structures
|
|
468
|
+
5. ✓ Clear AI reasoning in logs
|
|
469
|
+
|
|
470
|
+
### Overall
|
|
471
|
+
1. ✓ All RSpec tests passing
|
|
472
|
+
2. ✓ Complete documentation
|
|
473
|
+
3. ✓ No security vulnerabilities
|
|
474
|
+
4. ✓ Graceful error handling
|
|
475
|
+
5. ✓ User-friendly output
|
|
476
|
+
|
|
477
|
+
## 11. Comparison: Rails vs Generic Mode
|
|
478
|
+
|
|
479
|
+
| Aspect | Rails Mode | Generic Mode |
|
|
480
|
+
|--------|-----------|--------------|
|
|
481
|
+
| **Execution** | Fixed script | AI subagent |
|
|
482
|
+
| **AI Involvement** | None (pure automation) | Full (analysis + decisions) |
|
|
483
|
+
| **Speed** | Fast (< 5 min) | Slower (varies) |
|
|
484
|
+
| **Predictability** | 100% predictable | Adaptive |
|
|
485
|
+
| **Error Handling** | Fail-fast | Attempt recovery |
|
|
486
|
+
| **Flexibility** | None | High |
|
|
487
|
+
| **Use Case** | Standard Rails apps | Non-Rails or edge cases |
|
|
488
|
+
| **Database Setup** | Automatic (migrate + seed) | AI-decided |
|
|
489
|
+
| **Env Variables** | Fixed list | AI-analyzed |
|
|
490
|
+
|
|
491
|
+
## 12. Future Enhancements
|
|
492
|
+
|
|
493
|
+
1. **Additional Templates**
|
|
494
|
+
- Node.js/Express template
|
|
495
|
+
- Next.js template
|
|
496
|
+
- Django template
|
|
497
|
+
|
|
498
|
+
2. **Multi-Platform Support**
|
|
499
|
+
- Heroku integration
|
|
500
|
+
- Render integration
|
|
501
|
+
- Fly.io integration
|
|
502
|
+
|
|
503
|
+
3. **Advanced Features**
|
|
504
|
+
- Rollback capabilities
|
|
505
|
+
- Blue-green deployment
|
|
506
|
+
- Deployment analytics
|
|
507
|
+
- Pre/post deployment hooks
|
|
508
|
+
|
|
509
|
+
4. **AI Enhancements**
|
|
510
|
+
- Cost estimation before deploy
|
|
511
|
+
- Performance recommendations
|
|
512
|
+
- Security scanning
|
|
513
|
+
|
|
514
|
+
5. **User Experience**
|
|
515
|
+
- Interactive deployment wizard
|
|
516
|
+
- Deployment history tracking
|
|
517
|
+
- One-click rollback
|
|
518
|
+
|
|
519
|
+
## 13. Testing Strategy
|
|
520
|
+
|
|
521
|
+
### Unit Tests
|
|
522
|
+
- Each tool in isolation
|
|
523
|
+
- Mock Railway CLI responses
|
|
524
|
+
- Test error conditions
|
|
525
|
+
|
|
526
|
+
### Integration Tests
|
|
527
|
+
- Rails mode end-to-end
|
|
528
|
+
- Generic mode end-to-end
|
|
529
|
+
- Tool interaction flows
|
|
530
|
+
|
|
531
|
+
### Manual Tests
|
|
532
|
+
- Real Railway project deployment
|
|
533
|
+
- Different project types
|
|
534
|
+
- Error scenarios
|
|
535
|
+
- Security validations
|
|
536
|
+
|
|
537
|
+
### Test Coverage Target
|
|
538
|
+
- Tools: 90%+
|
|
539
|
+
- Rails template: 85%+
|
|
540
|
+
- Overall: 80%+
|