openclacky 0.9.28 → 0.9.30

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/docs/deploy-architecture.md +619 -0
  4. data/lib/clacky/agent/llm_caller.rb +14 -2
  5. data/lib/clacky/agent/message_compressor.rb +24 -6
  6. data/lib/clacky/agent/message_compressor_helper.rb +17 -10
  7. data/lib/clacky/agent/session_serializer.rb +69 -0
  8. data/lib/clacky/agent/skill_manager.rb +2 -2
  9. data/lib/clacky/agent.rb +3 -0
  10. data/lib/clacky/brand_config.rb +29 -3
  11. data/lib/clacky/clacky_auth_client.rb +152 -0
  12. data/lib/clacky/clacky_cloud_config.rb +123 -0
  13. data/lib/clacky/cli.rb +13 -0
  14. data/lib/clacky/client.rb +21 -7
  15. data/lib/clacky/cloud_project_client.rb +169 -0
  16. data/lib/clacky/default_agents/base_prompt.md +1 -0
  17. data/lib/clacky/default_parsers/doc_parser.rb +9 -9
  18. data/lib/clacky/default_skills/browser-setup/SKILL.md +9 -0
  19. data/lib/clacky/default_skills/channel-setup/SKILL.md +21 -4
  20. data/lib/clacky/default_skills/channel-setup/feishu_setup.rb +8 -2
  21. data/lib/clacky/default_skills/deploy/SKILL.md +96 -5
  22. data/lib/clacky/default_skills/deploy/scripts/rails_deploy.rb +1268 -274
  23. data/lib/clacky/default_skills/deploy/tools/create_database_service.rb +341 -0
  24. data/lib/clacky/default_skills/deploy/tools/execute_deployment.rb +72 -147
  25. data/lib/clacky/default_skills/deploy/tools/fetch_runtime_logs.rb +60 -50
  26. data/lib/clacky/default_skills/deploy/tools/list_services.rb +47 -60
  27. data/lib/clacky/default_skills/deploy/tools/set_deploy_variables.rb +147 -96
  28. data/lib/clacky/default_skills/new/SKILL.md +117 -5
  29. data/lib/clacky/default_skills/new/scripts/cloud_project_init.sh +74 -0
  30. data/lib/clacky/default_skills/new/scripts/create_rails_project.sh +32 -0
  31. data/lib/clacky/deploy_api_client.rb +484 -0
  32. data/lib/clacky/json_ui_controller.rb +16 -10
  33. data/lib/clacky/message_format/bedrock.rb +3 -2
  34. data/lib/clacky/message_history.rb +8 -0
  35. data/lib/clacky/plain_ui_controller.rb +1 -6
  36. data/lib/clacky/providers.rb +23 -4
  37. data/lib/clacky/server/browser_manager.rb +3 -1
  38. data/lib/clacky/server/channel/adapters/feishu/ws_client.rb +2 -1
  39. data/lib/clacky/server/channel/adapters/wecom/ws_client.rb +3 -1
  40. data/lib/clacky/server/channel/adapters/weixin/adapter.rb +5 -5
  41. data/lib/clacky/server/http_server.rb +12 -2
  42. data/lib/clacky/server/server_master.rb +43 -7
  43. data/lib/clacky/server/web_ui_controller.rb +17 -9
  44. data/lib/clacky/skill.rb +6 -2
  45. data/lib/clacky/tools/run_project.rb +4 -1
  46. data/lib/clacky/tools/shell.rb +7 -1
  47. data/lib/clacky/ui2/ui_controller.rb +1 -5
  48. data/lib/clacky/ui_interface.rb +5 -7
  49. data/lib/clacky/utils/arguments_parser.rb +22 -5
  50. data/lib/clacky/version.rb +1 -1
  51. data/lib/clacky/web/app.css +45 -5
  52. data/lib/clacky/web/app.js +126 -19
  53. data/lib/clacky/web/i18n.js +57 -0
  54. data/lib/clacky/web/sessions.js +108 -39
  55. data/lib/clacky/web/skills.js +8 -2
  56. data/lib/clacky.rb +3 -0
  57. metadata +8 -1
@@ -43,9 +43,10 @@ Before running the setup script, check if current directory is empty:
43
43
  - If user declines, abort and suggest creating project in an empty directory
44
44
 
45
45
  ### 2. Run Setup Script
46
- Execute the create_rails_project.sh script in current directory:
46
+ Execute the `create_rails_project.sh` script (see Supporting Files below) in current directory.
47
+ Use the exact absolute path shown in the Supporting Files section:
47
48
  ```bash
48
- <clacky_skills_path>/new/scripts/create_rails_project.sh
49
+ <absolute path to create_rails_project.sh from Supporting Files>
49
50
  ```
50
51
 
51
52
  The script will automatically:
@@ -74,7 +75,114 @@ The script will automatically:
74
75
  - Script completes successfully
75
76
  - Project is ready to run
76
77
 
77
- ### 3. Start Development Server
78
+ ### 3. Cloud Project Init
79
+ After the setup script completes, initialize the cloud project binding.
80
+
81
+ **Goal**: Create a cloud project on the Clacky platform, then inject the returned
82
+ `categorized_config` (auth/email/llm/stripe credentials) into the local development
83
+ environment so the app can use platform services out of the box.
84
+
85
+ #### 3.1 Check existing binding
86
+ Check if `.clacky/openclacky.yml` already exists:
87
+ ```bash
88
+ ls .clacky/openclacky.yml 2>/dev/null && cat .clacky/openclacky.yml || echo "NOT_FOUND"
89
+ ```
90
+
91
+ If it exists, ask the user:
92
+ ```
93
+ A cloud project binding already exists:
94
+ Project: <project_name> (<project_id>)
95
+
96
+ Do you want to reuse this binding? (y/n)
97
+ ```
98
+ - **Yes** → skip to step 3.5 (files already written, no need to re-create)
99
+ - **No** → continue to 3.2
100
+
101
+ #### 3.2 Run the cloud project init script
102
+ Use the `cloud_project_init.sh` script from Supporting Files.
103
+ Run it with safe_shell from the project directory (no arguments needed — it auto-reads `~/.clacky/clacky_cloud.yml`):
104
+
105
+ ```bash
106
+ bash <absolute_path_to_cloud_project_init.sh>
107
+ ```
108
+
109
+ The script outputs a single JSON line. Capture the full output.
110
+
111
+ **If the output contains `"success":false`** → soft-fail:
112
+ ```
113
+ ⚠️ Cloud project creation failed: <error value from JSON>
114
+ Skipping cloud init. You can link a project later with /deploy.
115
+ ```
116
+ Then skip to Step 4.
117
+
118
+ **If the output contains `"success":true`** → parse the JSON and extract:
119
+ - `project_id` — the cloud project UUID
120
+ - `project_name` — the project name
121
+ - `categorized_config` — nested object with auth/email/llm/stripe keys
122
+
123
+ The `categorized_config` looks like:
124
+ ```json
125
+ {
126
+ "auth": { "CLACKY_AUTH_CLIENT_ID": "...", "CLACKY_AUTH_CLIENT_SECRET": "...", "CLACKY_AUTH_HOST": "..." },
127
+ "email": { "CLACKY_EMAIL_API_KEY": "...", "CLACKY_EMAIL_SMTP_ADDRESS": "...", "CLACKY_EMAIL_SMTP_DOMAIN": "...", "CLACKY_EMAIL_SMTP_PORT": 25, "CLACKY_EMAIL_SMTP_USERNAME": "..." },
128
+ "llm": { "CLACKY_LLM_API_KEY": "...", "CLACKY_LLM_BASE_URL": "..." },
129
+ "stripe": { "CLACKY_STRIPE_PUBLISHABLE_KEY": "...", "CLACKY_STRIPE_SECRET_KEY": "...", "CLACKY_STRIPE_WEBHOOK_SECRET": "..." }
130
+ }
131
+ ```
132
+
133
+ #### 3.3 Write `.clacky/openclacky.yml`
134
+ Create the directory and write the binding file (no sensitive data — safe to commit):
135
+ ```bash
136
+ mkdir -p .clacky
137
+ ```
138
+ Then use the `write` tool to create `.clacky/openclacky.yml`:
139
+ ```yaml
140
+ # .clacky/openclacky.yml
141
+ # Committed to git. No sensitive data. Shared across team.
142
+ project_id: "<project_id from JSON>"
143
+ project_name: "<project_name from JSON>"
144
+ ```
145
+
146
+ #### 3.4 Update `config/application.yml`
147
+ Read the current `config/application.yml` first, then **prepend** a clearly-marked block at the very top of the file.
148
+ Use the `write` tool to rewrite the file with the cloud config block inserted before the existing content:
149
+ ```yaml
150
+ # --- Auto-generated by clacky /new (Cloud project: <project_name>) ---
151
+ CLACKY_AUTH_CLIENT_ID: "<value>"
152
+ CLACKY_AUTH_CLIENT_SECRET: "<value>"
153
+ CLACKY_AUTH_HOST: "<value>"
154
+ CLACKY_EMAIL_API_KEY: "<value>"
155
+ CLACKY_EMAIL_SMTP_ADDRESS: "<value>"
156
+ CLACKY_EMAIL_SMTP_DOMAIN: "<value>"
157
+ CLACKY_EMAIL_SMTP_PORT: "<value>"
158
+ CLACKY_EMAIL_SMTP_USERNAME: "<value>"
159
+ CLACKY_LLM_API_KEY: "<value>"
160
+ CLACKY_LLM_BASE_URL: "<value>"
161
+ CLACKY_STRIPE_PUBLISHABLE_KEY: "<value>"
162
+ CLACKY_STRIPE_SECRET_KEY: "<value>"
163
+ CLACKY_STRIPE_WEBHOOK_SECRET: "<value>"
164
+
165
+ # --- (original content below) ---
166
+ <original file content>
167
+ ```
168
+ Only include keys present in the JSON response.
169
+
170
+ #### 3.5 Git commit
171
+ Commit the cloud project binding file.
172
+ Note: `config/application.yml` is gitignored (it contains secrets) — do NOT try to add it.
173
+ ```bash
174
+ git add .clacky/openclacky.yml
175
+ git commit -m "Initialize cloud project binding"
176
+ ```
177
+
178
+ Print a success summary:
179
+ ```
180
+ ✅ Cloud project initialized!
181
+ Project: <project_name> (<project_id>)
182
+ Config written to: config/application.yml
183
+ ```
184
+
185
+ ### 4. Start Development Server
78
186
  After the script completes, use the run_project tool to start the server:
79
187
  ```
80
188
  run_project(action: "start")
@@ -100,6 +208,8 @@ What would you like to develop next?
100
208
  - Node.js < 22 → Script installs automatically (macOS/Ubuntu)
101
209
  - PostgreSQL missing → Script installs automatically (macOS/Ubuntu)
102
210
  - bin/setup fails → Show error, suggest running `./bin/setup` manually
211
+ - Cloud project creation fails → Soft-fail with warning, continue to start server
212
+ - workspace_key missing → Ask user interactively; skip cloud init if user declines
103
213
  - run_project fails → Check logs with `run_project(action: "output")` and verify database status
104
214
 
105
215
  ## Example Interaction
@@ -112,5 +222,7 @@ Response:
112
222
  4. Checking environment dependencies...
113
223
  5. Installing project dependencies...
114
224
  6. Project setup complete!
115
- 7. Starting development server with run_project...
116
- 8. Server running! Visit http://localhost:3000
225
+ 7. Initializing cloud project binding...
226
+ 8. Cloud project created and config injected into config/application.yml!
227
+ 9. Starting development server with run_project...
228
+ 10. ✨ Server running! Visit http://localhost:3000
@@ -0,0 +1,74 @@
1
+ #!/bin/bash
2
+ # Cloud Project Init Script
3
+ # Connects the local Rails project to the Clacky cloud platform.
4
+ #
5
+ # Usage: cloud_project_init.sh [project_name] [workspace_key] [base_url]
6
+ # - project_name: defaults to current directory name
7
+ # - workspace_key: defaults to value in ~/.clacky/clacky_cloud.yml
8
+ # - base_url: defaults to https://api.clacky.ai
9
+ #
10
+ # Outputs a JSON result on stdout:
11
+ # { "success": true, "project_id": "...", "project_name": "..." }
12
+ # { "success": false, "error": "..." }
13
+
14
+ set -e
15
+
16
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
17
+ GEM_LIB_DIR="$( cd "$SCRIPT_DIR/../../../.." && pwd )"
18
+
19
+ PROJECT_NAME="${1:-$(basename "$PWD")}"
20
+ WORKSPACE_KEY="${2:-}"
21
+ BASE_URL="${3:-}"
22
+
23
+ # --- Load workspace_key from clacky_cloud.yml if not provided ---
24
+ if [ -z "$WORKSPACE_KEY" ]; then
25
+ PLATFORM_YML="$HOME/.clacky/clacky_cloud.yml"
26
+ if [ -f "$PLATFORM_YML" ]; then
27
+ WORKSPACE_KEY=$(ruby -e "require 'yaml'; y = YAML.safe_load(File.read('$PLATFORM_YML')); print y['workspace_key'].to_s.strip" 2>/dev/null || true)
28
+ fi
29
+ fi
30
+
31
+ if [ -z "$BASE_URL" ]; then
32
+ PLATFORM_YML="$HOME/.clacky/clacky_cloud.yml"
33
+ if [ -f "$PLATFORM_YML" ]; then
34
+ BASE_URL=$(ruby -e "require 'yaml'; y = YAML.safe_load(File.read('$PLATFORM_YML')); print y['base_url'].to_s.strip" 2>/dev/null || true)
35
+ fi
36
+ BASE_URL="${BASE_URL:-https://api.clacky.ai}"
37
+ fi
38
+
39
+ if [ -z "$WORKSPACE_KEY" ]; then
40
+ echo '{"success":false,"error":"No workspace_key found. Please set it in ~/.clacky/clacky_cloud.yml or pass as argument."}'
41
+ exit 0
42
+ fi
43
+
44
+ # --- Call the API via Ruby one-liner using the gem's CloudProjectClient ---
45
+ RUBY_SCRIPT=$(cat <<'RUBY'
46
+ require_relative ENV['GEM_LIB_DIR'] + '/clacky/cloud_project_client'
47
+ require 'json'
48
+
49
+ workspace_key = ENV['WORKSPACE_KEY']
50
+ base_url = ENV['BASE_URL']
51
+ project_name = ENV['PROJECT_NAME']
52
+
53
+ client = Clacky::CloudProjectClient.new(workspace_key, base_url: base_url)
54
+ result = client.create_project(name: project_name)
55
+
56
+ if result[:success]
57
+ project = result[:project]
58
+ puts JSON.generate({
59
+ success: true,
60
+ project_id: project['id'],
61
+ project_name: project['name'],
62
+ categorized_config: project['categorized_config'] || {}
63
+ })
64
+ else
65
+ puts JSON.generate({ success: false, error: result[:error] })
66
+ end
67
+ RUBY
68
+ )
69
+
70
+ GEM_LIB_DIR="$GEM_LIB_DIR" \
71
+ WORKSPACE_KEY="$WORKSPACE_KEY" \
72
+ BASE_URL="$BASE_URL" \
73
+ PROJECT_NAME="$PROJECT_NAME" \
74
+ ruby -e "$RUBY_SCRIPT"
@@ -85,6 +85,35 @@ clone_template() {
85
85
  print_success "Git repository initialized"
86
86
  }
87
87
 
88
+ # Add x86_64-linux platform to Gemfile.lock for Railway deployment
89
+ # Railway always builds on x86_64-linux; local dev (macOS/Windows) may not include it.
90
+ prepare_linux_platform() {
91
+ print_step "Preparing Gemfile.lock for Linux deployment (Railway)..."
92
+
93
+ if [ ! -f "Gemfile.lock" ]; then
94
+ print_warning "Gemfile.lock not found yet — skipping platform prep (will be handled at deploy time)"
95
+ return 0
96
+ fi
97
+
98
+ # Idempotent: skip if already present
99
+ if grep -q "x86_64-linux" Gemfile.lock; then
100
+ print_success "x86_64-linux platform already present in Gemfile.lock"
101
+ return 0
102
+ fi
103
+
104
+ if command -v bundle > /dev/null 2>&1; then
105
+ if bundle lock --add-platform x86_64-linux > /dev/null 2>&1; then
106
+ git add Gemfile.lock > /dev/null 2>&1
107
+ git commit -m "chore: add x86_64-linux platform for Railway deployment" > /dev/null 2>&1
108
+ print_success "Added x86_64-linux platform to Gemfile.lock"
109
+ else
110
+ print_warning "Could not add Linux platform to Gemfile.lock (will be handled at deploy time)"
111
+ fi
112
+ else
113
+ print_warning "bundler not found — skipping platform prep (will be handled at deploy time)"
114
+ fi
115
+ }
116
+
88
117
  # Check and install environment dependencies
89
118
  check_environment() {
90
119
  print_step "Checking environment dependencies..."
@@ -157,6 +186,9 @@ main() {
157
186
  exit 1
158
187
  fi
159
188
 
189
+ # Prepare Gemfile.lock for Railway Linux deployment (idempotent)
190
+ prepare_linux_platform
191
+
160
192
  # Project is ready
161
193
  echo ""
162
194
  echo "╔═══════════════════════════════════════════════════════════╗"