openclacky 1.1.2 → 1.1.4

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.clacky/skills/gem-release/SKILL.md +27 -31
  3. data/CHANGELOG.md +30 -0
  4. data/Dockerfile +28 -0
  5. data/README.md +4 -0
  6. data/README_CN.md +198 -0
  7. data/docs/engineering-article.md +343 -0
  8. data/lib/clacky/agent/llm_caller.rb +2 -5
  9. data/lib/clacky/agent/session_serializer.rb +4 -0
  10. data/lib/clacky/agent.rb +22 -1
  11. data/lib/clacky/brand_config.rb +87 -5
  12. data/lib/clacky/cli.rb +1 -1
  13. data/lib/clacky/client.rb +15 -11
  14. data/lib/clacky/message_format/anthropic.rb +30 -2
  15. data/lib/clacky/message_format/bedrock.rb +13 -1
  16. data/lib/clacky/message_format/open_ai.rb +5 -1
  17. data/lib/clacky/providers.rb +34 -0
  18. data/lib/clacky/server/channel/adapters/dingtalk/adapter.rb +142 -5
  19. data/lib/clacky/server/channel/adapters/dingtalk/api_client.rb +309 -0
  20. data/lib/clacky/server/http_server.rb +130 -15
  21. data/lib/clacky/server/session_registry.rb +9 -6
  22. data/lib/clacky/ui2/ui_controller.rb +14 -0
  23. data/lib/clacky/ui_interface.rb +14 -0
  24. data/lib/clacky/utils/model_pricing.rb +96 -25
  25. data/lib/clacky/version.rb +1 -1
  26. data/lib/clacky/web/app.css +1286 -1116
  27. data/lib/clacky/web/brand.js +20 -5
  28. data/lib/clacky/web/i18n.js +42 -0
  29. data/lib/clacky/web/index.html +26 -7
  30. data/lib/clacky/web/onboard.js +6 -0
  31. data/lib/clacky/web/sessions.js +194 -11
  32. data/lib/clacky/web/settings.js +51 -10
  33. data/lib/clacky/web/skills.js +53 -31
  34. data/lib/clacky/web/vendor/hljs/highlight.min.js +1244 -0
  35. data/lib/clacky/web/vendor/hljs/hljs-theme.css +95 -0
  36. data/scripts/build/lib/apt.sh +30 -10
  37. data/scripts/build/lib/network.sh +3 -2
  38. data/scripts/install.sh +30 -9
  39. data/scripts/install_browser.sh +2 -1
  40. data/scripts/install_full.sh +2 -1
  41. data/scripts/install_rails_deps.sh +30 -9
  42. data/scripts/install_system_deps.sh +30 -9
  43. metadata +7 -17
  44. data/docs/HOW-TO-USE-CN.md +0 -96
  45. data/docs/HOW-TO-USE.md +0 -94
  46. data/docs/browser-cdp-native-design.md +0 -195
  47. data/docs/c-end-user-positioning.md +0 -64
  48. data/docs/config.example.yml +0 -27
  49. data/docs/deploy-architecture.md +0 -619
  50. data/docs/deploy_subagent_design.md +0 -540
  51. data/docs/install-script-simplification.md +0 -89
  52. data/docs/memory-architecture.md +0 -343
  53. data/docs/openclacky_cloud_api_reference.md +0 -584
  54. data/docs/security-design.md +0 -109
  55. data/docs/session-management-redesign.md +0 -202
  56. data/docs/system-skill-authoring-guide.md +0 -47
  57. data/docs/why-developer.md +0 -371
  58. data/docs/why-openclacky.md +0 -266
@@ -0,0 +1,343 @@
1
+ # Every AI Agent Feature Is a Cache Invalidation Surface
2
+
3
+ *May 19, 2026 · Yafei Lee / Founder of OpenClacky*
4
+
5
+ ---
6
+
7
+ I'm Yafei Lee, founder of [OpenClacky](https://github.com/clacky-ai/openclacky), an open-source AI Agent written in Ruby. We wanted an agent with skills, memory, sub-agents, browser automation, dynamic model switching, and long-running sessions. Each of those features made prompt caching worse in a different way.
8
+
9
+ That was the real architecture problem. Not how to call an LLM, not how to add another tool, not how to orchestrate more agents — how to keep the cache prefix stable while the product keeps changing.
10
+
11
+ **Every agent feature is also a cache invalidation surface.** Skills load new system context. Peer-agent workflows fork the prefix. Browser automation adds volatile tool output. Compression rewrites history. Model switching can fragment the cache namespace unless model-specific state stays out of the system prompt. If you're building a capable agent and your cache hit rate is much lower than expected, this is probably why.
12
+
13
+ Over two years and three architecture generations (the first two failed), we converged on seven engineering decisions that let us hit 90%+ cache rates across real tasks — while keeping all those features intact. What follows is the complete story: what broke, what we tried, and what actually worked.
14
+
15
+ ---
16
+
17
+ ## Generation 1: RAG Everything (2024 – early 2025)
18
+
19
+ Our first agent was a textbook RAG system. We embedded the user's codebase, docs, and conversation history into a vector store. Every query went through hybrid retrieval, re-ranking, and query rewriting before the LLM saw anything.
20
+
21
+ It sounded right. It wasn't.
22
+
23
+ The index was always behind the repo. Every codebase update required re-embedding, and real-time sync was unreliable enough that we kept paying to search context that was sometimes stale.
24
+
25
+ The bigger problem was recall. 90% sounds high until an agent chains multiple steps. A wrong file in step 2 becomes a wrong edit in step 3 and a wasted retry in step 4. We guessed that something closer to 97% recall might be the minimum for an agent to be net-positive, and we were not close.
26
+
27
+ For coding agents working over local repos, we killed RAG entirely. No embeddings, no vector store, no retrieval pipeline. If the agent needs context, it reads files directly or searches with `grep`. If your documentation needs to be accessible to an agent, make it readable on a website. Don't shred it into embeddings.
28
+
29
+ ---
30
+
31
+ ## Generation 2: Multi-Agent Orchestration (mid-2025)
32
+
33
+ The next idea came from the SWEBench leaderboard playbook: a Planner agent, a Coder agent, a Reviewer agent, and a Tester agent, coordinated through a message bus with role-specific prompts.
34
+
35
+ We got decent SWEBench scores. The product was terrible.
36
+
37
+ Every handoff was a cache miss. Each agent had its own system prompt and cache namespace, and passing context between agents meant serializing rich state into a smaller message. Useful context was lost at the boundary, and the receiving agent had to rebuild its own prefix.
38
+
39
+ The overhead was not subtle. A task that one agent could finish in 4 minutes took 14 minutes with four. Cost was roughly 6× higher. Agents waited for each other, re-read context the previous agent had already processed, and sometimes contradicted each other. When the final output was wrong, tracing the failure through Planner → Coder → Reviewer took longer than debugging a single conversation.
40
+
41
+ SWEBench scores didn't predict user satisfaction. The failures that annoyed real users — slow iteration, lost context across handoffs, inconsistent code style — were not what the benchmark measured.
42
+
43
+ We killed role-based multi-agent orchestration. One main agent, one conversation, one cache namespace. Sub-agents survived only as isolated skill execution contexts, invoked through a single stable tool.
44
+
45
+ Two generations, same conclusion: the model is already smart enough. What it needs isn't more models, it's a better harness.
46
+
47
+ ---
48
+
49
+ ## The Seven Decisions
50
+
51
+ Generation 3 started from a question: *what if we optimized everything around a single agent's cache hit rate?* Not as a cost hack, but as an architectural principle. High cache hits mean the model sees consistent context, responds faster, and costs less. Every decision below serves that goal.
52
+
53
+ (The code is open source. Links to the exact files implementing each decision are at the end of this post.)
54
+
55
+ ---
56
+
57
+ ### Decision 1: History Growth Breaks Prefix Matching → Double Cache Markers
58
+
59
+ Prompt caching works by prefix matching. The LLM provider stores a hash of the message prefix; if your next request shares that prefix, you get the cached rate (depending on the provider, cached tokens are priced at a fraction of normal input tokens). The way you tell the provider where to cache is by placing `cache_control` markers on specific messages.
60
+
61
+ The naive approach is one marker on the last message. It breaks in three ways:
62
+
63
+ 1. **History grows monotonically.** You mark message N. Next turn, message N+1 is appended. The content at the position of your old marker has changed, so it's a cache miss on the entire history.
64
+ 2. **Tool call retries.** The model's last tool call errors out, or the user hits Ctrl-C. The "last message" gets discarded, and your marker vanishes with it.
65
+ 3. **Mid-session model switches.** The user switches from Sonnet to Opus. You want to share as much prefix as possible across models. Any unnecessary marker movement becomes a cache miss event.
66
+
67
+ We hit problem (1) first. The fix progression is visible in our git log:
68
+
69
+ ```
70
+ 8ff66cc fix: cache
71
+ 6ea99fe fix: prompt cache
72
+ e9a3602 feat: prompt cache works fine
73
+ 7734c97 feat: try 2 point cache
74
+ ```
75
+
76
+ The first three commits were incremental patches. The last one was the structural fix: **two markers instead of one.**
77
+
78
+ #### How double markers work
79
+
80
+ Every turn, we mark **two** consecutive messages, not one:
81
+
82
+ ```
83
+ Turn N: [..., msg_A, msg_B(*), msg_C(*)]
84
+ ↑ ↑
85
+ marker 1 marker 2
86
+
87
+ Turn N+1: [..., msg_A, msg_B(*), msg_C(*), msg_D(*)]
88
+ ↑ ↑ ↑
89
+ (still there) (still there) new marker
90
+ ```
91
+
92
+ On turn N+1, the provider tries to match the marker on `msg_C` and hits everything before it (system prompt + tools + full history minus the last message). We place a new marker on `msg_D` for the next turn.
93
+
94
+ This is a **rolling double buffer**: at any moment we hold two breakpoints — one being "read" (from the previous turn) and one being "written" (at the current tail). Next turn, the old "write" becomes the new "read," and we write a fresh one at the new tail. There's never a moment where both buffers are invalid simultaneously.
95
+
96
+ #### Why exactly 2, not 3 or 4
97
+
98
+ Each additional marker costs a cache write at write-tier pricing. The only failure boundary we need to cover is the "old tail / new tail" edge, and two markers is exactly the minimum for that. A third marker lands further back in the prefix, writing a segment that will never be read independently. 2 covers the boundary. 3 is redundant.
99
+
100
+ #### Surviving tool call retries
101
+
102
+ This is the second benefit, and the actual motivation behind commit `7734c97`. When the model retries a tool call (error, Ctrl-C, broken stream), the last message gets discarded. With a single marker, that's an immediate cache miss. With double markers, the second-to-last marker usually survives, so single-step rollback still hits cache. Three markers would survive two-step rollbacks, but the cost doesn't justify the edge case.
103
+
104
+ #### Messages that must never be marked
105
+
106
+ Our marker selection logic has one hard rule: skip any message tagged `system_injected: true`. These are ephemeral messages (session context blocks, compression instructions) that won't exist in the same form next turn. A marker on them is a write that will never be read back. The selector walks backward from the tail, skips `system_injected` messages, and stops when it has two real conversation messages.
107
+
108
+ ---
109
+
110
+ ### Decision 2: Dynamic Session State Breaks System Prompts → Frozen System Prompt
111
+
112
+ Engineering discipline: our agent's system prompt is built once at session start, then byte-frozen. Any requirement to put dynamic information in the system prompt gets redirected elsewhere.
113
+
114
+ This is the foundation of the entire cache strategy. If the system prompt changes, every subsequent cache entry is invalidated. There is no partial fix.
115
+
116
+ But at least four kinds of information naturally "want" to live in the system prompt:
117
+
118
+ 1. **Current date, working directory, OS** — the model needs these for correct commands.
119
+ 2. **Current model ID** — helpful for self-adaptive behavior.
120
+ 3. **Newly installed skills** — the model needs to see skill names to invoke them.
121
+ 4. **Updated user preferences** (USER.md / SOUL.md) — the agent's personality and user context.
122
+
123
+ All four can change mid-session. If any of them is in the system prompt, a single change invalidates everything.
124
+
125
+ #### The [session context] block
126
+
127
+ Instead of the system prompt, we inject this information as a regular `user` message in the conversation history:
128
+
129
+ ```
130
+ [Session context: Today is 2026-05-13, Tuesday. Current model: claude-sonnet-4-6.
131
+ OS: macOS. Working directory: /Users/.../project]
132
+ ```
133
+
134
+ This message is tagged `system_injected: true`. It won't be selected by cache markers (Decision 1), won't count as a real user turn, and gets discarded during compression. Injection is date-gated: one per day, plus one on model switch. Most sessions see exactly one.
135
+
136
+ #### A bug that took a day to find
137
+
138
+ Our first implementation of `inject_session_context` was eager. It fired during agent construction, before the system prompt was built. This meant `@history.empty?` returned `false`, so `run()` skipped system prompt construction entirely. The agent sent its first request with a "today is Tuesday" message but no system prompt. Behavior was subtly broken for a day before we traced it.
139
+
140
+ The fix was one line: inject after the system prompt is built. The code comment that survived:
141
+
142
+ ```ruby
143
+ # IMPORTANT: Skip injection when the system prompt hasn't been built yet.
144
+ # Otherwise, appending a user message to an empty history makes
145
+ # @history.empty? false, which causes run() to skip building the
146
+ # system prompt entirely.
147
+ ```
148
+
149
+ Assembly order matters more than content. You can spend weeks designing each piece of the prefix, but if the assembly sequence is wrong by one step, the entire cache strategy is void.
150
+
151
+ #### How skill discovery works without touching the system prompt
152
+
153
+ Skills are rendered into the system prompt at session start, then frozen. A skill installed mid-session won't appear until the next session. We accept this friction. Re-rendering the system prompt on every skill install would invalidate the cache for all users on all sessions on every turn. Skill installation is low-frequency; cache hits are per-turn. The tradeoff is clear.
154
+
155
+ That said, `invoke_skill` reads each SKILL.md at call time, not at session start. So if a user explicitly asks for a newly installed skill, the system can still find and execute it, though it won't auto-discover it from the skill listing.
156
+
157
+ ---
158
+
159
+ ### Decision 3: Skills and Sub-Agents Bloat History → One Meta-Tool
160
+
161
+ `invoke_skill` is one of our 16 tools and does more work than any other. It provides skill hot-loading, sub-agent architecture, memory recall, and skill self-evolution, all in under 200 tokens of system prompt.
162
+
163
+ It spawns a sub-agent with its own conversation history but the same 16 tools. When the sub-agent finishes, the main agent only sees `invoke_skill → result`. All intermediate steps stay in the sub-agent's isolated session.
164
+
165
+ This matters for caching: a code review skill might read dozens of files and produce a long analysis. Without isolation, all that intermediate work would inflate the main agent's history, triggering compression earlier and costing more. With `invoke_skill`, the main agent's history stays clean.
166
+
167
+ And for extensibility: need a new capability? Drop a SKILL.md in `~/.clacky/skills/`. The `invoke_skill` tool is always present in the schema; it doesn't need to know about specific skills at compile time. The SKILL.md is read at invocation time. This one tool replaces what would otherwise be ~20 specialized tools, each bloating the schema and increasing the cache invalidation surface.
168
+
169
+ ---
170
+
171
+ ### Decision 4: Tool Growth Destabilizes Schema → Exactly 16 Tools
172
+
173
+ Tool schemas sit right after the system prompt in the cache prefix. If the schema changes, everything after it is invalidated. Every additional tool isn't just extra schema tokens; it's extra risk surface for cache invalidation the next time you change any tool.
174
+
175
+ But too few tools also cost money. If the model has to take three steps for something that one well-designed tool could handle in one step, you're paying for extra turns.
176
+
177
+ Our answer after months of iteration: 16 tools. File I/O (3), search (2), execution (1), browser (1), web (2), task management (4), interaction (1), extension (1), safety (1).
178
+
179
+ The design principles are simple: minimize parameters per tool (fewer ways for the model to get it wrong), no overlap between tools, and heavy RSpec coverage on every tool. A tool bug cascades: wrong observation → wrong decision → wasted retries.
180
+
181
+ If we ever need a 17th tool, we'll add it. Four months in, we haven't. The capabilities that didn't become tools became skills instead: code analysis, memory, scheduling, sub-agent orchestration. Each routed through `invoke_skill`, invisible to the tool schema.
182
+
183
+ ---
184
+
185
+ ### Decision 5: Long Sessions Exceed Context Limits → Insert-Then-Compress
186
+
187
+ Context windows are finite. Long tasks will fill them. Compression is the single biggest threat to cache hit rates: replacing old messages with a summary changes the prefix, guaranteeing a cache miss. So the question is how to minimize the damage.
188
+
189
+ #### Don't use a separate model for compression
190
+
191
+ Many agents compress by spawning an independent LLM call with a cheap/fast model and a "you are a summarization assistant" system prompt.
192
+
193
+ The problems:
194
+
195
+ - The compression call's system prompt doesn't match the main session. It has zero shared prefix with the main cache, so it's a 100% miss on the compression call itself.
196
+ - After compression, the main session's history has changed (old messages replaced by summary), so the main session's cache is also invalidated. You're running cold for the next 4-5 turns.
197
+
198
+ You pay twice for every compression event: once for the compression call's miss, and once for the main session's cold-to-warm recovery.
199
+
200
+ Our approach: **Insert-then-Compress.** Instead of a separate call, we insert the compression instruction as a `system_injected` message at the end of the current conversation, then send a normal request.
201
+
202
+ The effect:
203
+
204
+ - The compression call hits the existing cache. Same system prompt, same tools, same history prefix. Only the tail instruction (~500 tokens) is cold.
205
+ - After compression, we rebuild history as `[system_prompt, summary, last_N_messages]`. This does miss once, but only once. From the second turn onward, double markers take over again.
206
+
207
+ | | Separate model | Insert-then-Compress |
208
+ |---|---|---|
209
+ | Compression call cache hit | 0% | **~95%** |
210
+ | Cold tokens during compression | ~50,000 | **~500** |
211
+ | Main session cold turns after | 4–5 | **1** |
212
+
213
+ *Comparison for a 50K-token session compression event.*
214
+
215
+ #### The sweet spot: 200K–300K tokens
216
+
217
+ We tested multiple thresholds. 200K–300K tokens is where quality and cost balance. The model still effectively uses the context, with enough headroom to complete compression itself. After compression, history is always reduced to under 10K tokens, controlling the baseline cost of every subsequent turn.
218
+
219
+ #### Compress at idle, not at the next message
220
+
221
+ LLM providers expire prompt caches after ~5 minutes of inactivity. Once expired, the next turn is fully cold: 10× the cached price.
222
+
223
+ We run an idle timer (`idle_compression_timer.rb`): when the user stops typing for 90 seconds and history is approaching the threshold, we compress immediately, while the cache is still warm. The new short history establishes a fresh cache breakpoint before TTL expiry.
224
+
225
+ When the user comes back after a few minutes of thinking, the session is already compressed and warm. Without this, they'd face a cache-expired 300K-token history at full price. This single behavior saves roughly 10× on long-pause sessions.
226
+
227
+ #### The million-token context trap
228
+
229
+ "Million-token context" sounds impressive, but the model re-reads the entire context every turn. 1M tokens of input, even at 100% cache hit (0.1× price), costs the equivalent of 100K full-price tokens per turn. One cache miss and you pay for 1M tokens at full rate. Add the well-documented attention degradation in ultra-long contexts, and the math is clear.
230
+
231
+ Our strategy is the opposite of "fill up the context window": compress aggressively, keep history short. 10K tokens of compressed history at 95% cache hit is cheaper and more effective than 1M tokens of raw history at 99% cache hit.
232
+
233
+ ---
234
+
235
+ ### Decision 6: File Parsing Wants More Tools → Self-Maintained Scripts
236
+
237
+ PDF, Excel, Word, and PowerPoint parsing are common agent needs. Built-in tools would bloat the schema (violates Decision 4) and require C extensions (breaks zero-dependency install). Requiring users to install skills first is bad UX.
238
+
239
+ Our third path: on first install, copy a set of Python parsing scripts to `~/.clacky/scripts/`, then let the agent maintain them.
240
+
241
+ When the agent needs to read a PDF, it runs `python3 ~/.clacky/scripts/read_pdf.py <file>` via the `terminal` tool. The tool list doesn't grow. If a script fails (missing dependency, format edge case), the agent can fix the script and `pip install` whatever's needed. The capability isn't hard-coded in the gem. It lives in user-space scripts that the agent itself maintains and improves over time.
242
+
243
+ Why Python for scripts when the agent is Ruby? Pragmatism. Python's document processing ecosystem (`pdfplumber`, `openpyxl`, `python-docx`) is the most mature. We use the best tool for each layer.
244
+
245
+ ---
246
+
247
+ ### Decision 7: Browser Automation Wants Many MCP Tools → One Stable Browser Tool
248
+
249
+ Browser automation matters for agents, but the mainstream approaches have problems. Headless browsers (Puppeteer/Playwright) are invisible to the user, frequently blocked by anti-bot detection, and can't access existing login sessions. External MCP services require separate installation and may expose dozens of fine-grained tools that bloat the schema.
250
+
251
+ We take over the user's actual Chrome/Edge instead. The user enables Remote Debugging once (guided by a setup skill), and our built-in MCP client connects via stdio JSON-RPC. The agent operates on the browser the user can see — same cookies, same login sessions, same page state. When the agent clicks a button, the user watches it happen.
252
+
253
+ To the model, `browser` is one tool out of 16 with a stable schema. The complexity of daemon lifecycle management (startup, heartbeat, crash recovery) lives in `browser_manager.rb`, invisible to the cache layer.
254
+
255
+ This comes with obvious safety concerns. We keep the browser visible at all times, require explicit user-initiated setup, and treat browser automation as a high-trust local capability rather than a background cloud service. It is powerful precisely because it runs in the user's real session, so it should be used with the same caution as giving an assistant access to your logged-in browser.
256
+
257
+ ---
258
+
259
+ ## Why Ruby? (Yes, Really)
260
+
261
+ If you've read this far you might have noticed: this entire agent is written in Ruby. Not Python. Not TypeScript. Ruby.
262
+
263
+ On GitHub, there are about 4,700 repositories tagged "ai-agent" in Python, 2,800 in TypeScript, and **5 in Ruby.** Ruby is almost absent from the current AI agent ecosystem, which made this choice worth explaining.
264
+
265
+ We didn't choose Ruby to be contrarian. We chose it because the things an agent harness actually does — orchestrating API calls, managing cache boundaries, dynamically loading skills, maintaining tool registries — are things Ruby happens to be very good at.
266
+
267
+ Metaprogramming is a genuine advantage here. `method_missing`, `define_method`, `class_eval` — when your agent modifies its own helper scripts at runtime, when skills load dynamically without restart, when tool registration happens through introspection rather than config files, Ruby's metaprogramming pays real dividends.
268
+
269
+ Distribution is frictionless. `gem install openclacky` — done. Version management, dependency resolution, executable registration (`clacky` command), all out of the box. No virtual environments, no `node_modules`, no build step.
270
+
271
+ **Zero C extension dependencies.** This took significant engineering effort. Look at our gemspec:
272
+
273
+ ```
274
+ faraday, thor, tty-prompt, tty-spinner, diffy, pastel,
275
+ tty-screen, tty-markdown, base64, logger, websocket,
276
+ webrick, artii, rubyzip, rouge, chunky_png
277
+ ```
278
+
279
+ Every dependency is pure Ruby. No `brew install libxml2`, no `apt-get install libffi-dev`, no Xcode Command Line Tools.
280
+
281
+ To achieve this, we made unusual choices: pure-Ruby `websocket` gem instead of `websocket-driver` (which needs a C extension for UTF-8 validation); LLM streaming and tool_use protocol handling from scratch with raw `faraday` HTTP — because we needed direct control over `cache_control` field injection for Decision 1; terminal UI built with ANSI escape codes instead of `curses`.
282
+
283
+ These "build from scratch" decisions would have been impractical a few years ago. But the agent is itself an AI coding agent — we used it to write itself. A bootstrapping loop: the product made itself better.
284
+
285
+ ---
286
+
287
+ ## A Small Sanity Check, Not a Benchmark
288
+
289
+ A note on methodology: **this is not a rigorous benchmark.** We ran three real tasks (a slide deck, a marketing strategy, a social content pipeline) through four agents (ours, Claude Code, OpenClaw, Hermes) under controlled conditions — same prompt, same underlying model (claude-opus-4-7), same skills, same time window. All cost data comes from OpenRouter's per-request CSV billing, not estimates. Single run per agent, no cherry-picking.
290
+
291
+ We did this to get a feel for where we stand, not to make definitive claims. Take the numbers as directional.
292
+
293
+ | Agent | Cost | Requests | Cache Hit Rate |
294
+ |---|---|---|---|
295
+ | **Ours** | $5.10 | 51 | 90.6% |
296
+ | Claude Code | $5.49 | 70 | 95.2% |
297
+ | OpenClaw | $15.70 | 81 | 88.7% |
298
+ | Hermes | $30.14 | 218 | 60.3% |
299
+
300
+ *Total cost across 3 tasks. Data from OpenRouter per-request CSV billing.*
301
+
302
+ The cost difference isn't about unit price; prompt token pricing is roughly the same across agents using the same model. The difference is fewer requests × higher cache hit rate. 51 requests at 90.6% cache hit versus 218 requests at 60.3% cache hit — that's where the 6× gap comes from.
303
+
304
+ Claude Code's cache hit rate is actually higher than ours (95.2% vs 90.6%). They achieve this partly by having fewer features that conflict with caching. Our agent supports skills, sub-agents, browser automation, dynamic model switching, and idle compression — all things that structurally threaten cache coherence. Getting to 90.6% while supporting all of that is the engineering challenge this post describes.
305
+
306
+ Full results, per-task breakdowns, and the actual deliverables from each agent are at [openclacky.com/benchmark](https://www.openclacky.com/benchmark).
307
+
308
+ ---
309
+
310
+ ## Reproducibility
311
+
312
+ Everything needed to verify or re-run this comparison is public:
313
+
314
+ - **Runner script** — [`benchmark/runner.rb`](https://github.com/clacky-ai/openclacky/blob/main/benchmark/runner.rb)
315
+ - **OpenRouter CSV billing data** — [`benchmark/results/`](https://github.com/clacky-ai/openclacky/tree/main/benchmark/results) (per-request cost, cache hit/miss, token counts)
316
+ - **Task prompts and fixtures** — [`benchmark/fixtures/`](https://github.com/clacky-ai/openclacky/tree/main/benchmark/fixtures)
317
+ - **Evaluation report** — [`benchmark/results/EVALUATION_REPORT.md`](https://github.com/clacky-ai/openclacky/blob/main/benchmark/results/EVALUATION_REPORT.md)
318
+
319
+ We did not cherry-pick runs, post-process outputs, or re-run until numbers looked good. One run per agent, published as-is. This still does not make it a benchmark; it just makes the sanity check auditable. If you find errors in the data, open an issue.
320
+
321
+ ---
322
+
323
+ ## What We Actually Believe
324
+
325
+ These seven decisions share one conviction: spend your engineering budget on the harness, save your intelligence budget for the model.
326
+
327
+ We ripped out RAG because the model can read files directly. We killed multi-agent workflows because one main agent with good context management was faster, cheaper, and easier to debug. We still use sub-agents, but only behind invoke_skill, where they act as isolated execution sandboxes rather than peer collaborators. We kept the tool list small because the capabilities that didn't earn their place as tools became skills instead, routed through a single meta-tool.
328
+
329
+ These aren't universal truths. If you need real-time retrieval from a billion documents, or you're coordinating physical robots, your tradeoffs will differ. But for agents that help individual humans with coding and writing and automation, we think single-agent-with-great-caching has a lot of room to run.
330
+
331
+ Models get better fast. The things that *won't* be obsoleted by better models are the things we've invested in: cache geometry, tool stability, compression strategy, install experience. Harness-layer infrastructure that stays useful regardless of which model you plug in.
332
+
333
+ ---
334
+
335
+ OpenClacky is fully open-source under the MIT license. The code behind every decision in this post:
336
+
337
+ - Cache marker logic — [`lib/clacky/client.rb`](https://github.com/clacky-ai/openclacky/blob/main/lib/clacky/client.rb)
338
+ - Insert-then-Compress — [`lib/clacky/agent/message_compressor.rb`](https://github.com/clacky-ai/openclacky/blob/main/lib/clacky/agent/message_compressor.rb)
339
+ - Session context injection — [`lib/clacky/agent.rb`](https://github.com/clacky-ai/openclacky/blob/main/lib/clacky/agent.rb)
340
+ - Idle compression timer — [`lib/clacky/idle_compression_timer.rb`](https://github.com/clacky-ai/openclacky/blob/main/lib/clacky/idle_compression_timer.rb)
341
+ - Browser tool — [`lib/clacky/tools/browser.rb`](https://github.com/clacky-ai/openclacky/blob/main/lib/clacky/tools/browser.rb)
342
+
343
+ → [github.com/clacky-ai/openclacky](https://github.com/clacky-ai/openclacky)
@@ -104,6 +104,7 @@ module Clacky
104
104
  tools: tools_to_send,
105
105
  max_tokens: @config.max_tokens,
106
106
  enable_caching: @config.enable_prompt_caching,
107
+ reasoning_effort: @reasoning_effort,
107
108
  on_chunk: build_progress_on_chunk
108
109
  )
109
110
 
@@ -763,11 +764,7 @@ module Clacky
763
764
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
764
765
  return if now - last_emit_at < min_interval && output_tokens > 0
765
766
  last_emit_at = now
766
- @ui.show_progress(
767
- progress_type: "thinking",
768
- phase: "active",
769
- metadata: { input_tokens: input_tokens, output_tokens: output_tokens }
770
- )
767
+ @ui.stream_thinking_progress(input_tokens: input_tokens, output_tokens: output_tokens)
771
768
  }
772
769
  end
773
770
  end
@@ -63,6 +63,9 @@ module Clacky
63
63
  @pending_error_rollback = true
64
64
  end
65
65
 
66
+ saved_reasoning = session_data.dig(:config, :reasoning_effort)
67
+ self.reasoning_effort = saved_reasoning if saved_reasoning
68
+
66
69
  # Restore the session's original model if it still exists in the current
67
70
  # config. This prevents all sessions from silently switching to the new
68
71
  # default model when the user changes it and restarts. Falls back to the
@@ -128,6 +131,7 @@ module Clacky
128
131
  enable_prompt_caching: @config.enable_prompt_caching,
129
132
  max_tokens: @config.max_tokens,
130
133
  verbose: @config.verbose,
134
+ reasoning_effort: @reasoning_effort,
131
135
  # Persist the current model identity so the session can restore its
132
136
  # original model on restart. model_name + model_base_url form a
133
137
  # composite key to avoid matching a different provider's model of
data/lib/clacky/agent.rb CHANGED
@@ -43,13 +43,30 @@ module Clacky
43
43
  attr_reader :session_id, :name, :history, :iterations, :total_cost, :working_dir, :created_at, :total_tasks, :todos,
44
44
  :cache_stats, :cost_source, :ui, :skill_loader, :agent_profile,
45
45
  :status, :error, :updated_at, :source,
46
- :latest_latency # Hash of latency metrics from the most recent LLM call (see Client#send_messages_with_tools)
46
+ :latest_latency, # Hash of latency metrics from the most recent LLM call (see Client#send_messages_with_tools)
47
+ :reasoning_effort
47
48
  attr_accessor :pinned
48
49
 
50
+ REASONING_EFFORTS = %w[low medium high].freeze
51
+
49
52
  def permission_mode
50
53
  @config&.permission_mode&.to_s || ""
51
54
  end
52
55
 
56
+ def reasoning_effort=(value)
57
+ @reasoning_effort = normalize_reasoning_effort(value)
58
+ end
59
+
60
+ private def normalize_reasoning_effort(value)
61
+ return nil if value.nil?
62
+ str = value.to_s.strip.downcase
63
+ return nil if str.empty? || str == "off" || str == "none"
64
+ return str if REASONING_EFFORTS.include?(str)
65
+ nil
66
+ end
67
+
68
+ public
69
+
53
70
  def initialize(client, config, working_dir:, ui:, profile:, session_id:, source:)
54
71
  @client = client # Client for current model
55
72
  @config = config.is_a?(AgentConfig) ? config : AgentConfig.new(config)
@@ -79,6 +96,7 @@ module Clacky
79
96
  @task_cost_source = :estimated # Track cost source for current task
80
97
  @previous_total_tokens = 0 # Track tokens from previous iteration for delta calculation
81
98
  @latest_latency = nil # Most recent LLM call's latency metrics (see Client#send_messages_with_tools)
99
+ @reasoning_effort = nil # Per-session reasoning effort override; nil = provider default
82
100
  @ui = ui # UIController for direct UI interaction
83
101
  @debug_logs = [] # Debug logs for troubleshooting
84
102
  @pending_injections = [] # Pending inline skill injections to flush after observe()
@@ -102,6 +120,9 @@ module Clacky
102
120
  # Background sync: compare remote skill versions and download updates quietly.
103
121
  # Runs in a daemon thread so Agent startup is never blocked.
104
122
  @brand_config.sync_brand_skills_async!
123
+ # Free-mode counterpart: branded but not activated → fetch unencrypted skills
124
+ # via the public endpoint so users get a working install with no serial number.
125
+ @brand_config.sync_free_skills_async!
105
126
 
106
127
  # Initialize Time Machine
107
128
  init_time_machine
@@ -410,6 +410,86 @@ module Clacky
410
410
  end
411
411
  end
412
412
 
413
+ # Fetch the list of free (unencrypted, published) skills available for the
414
+ # configured package_name. Anonymous endpoint — no license key required.
415
+ # This is what powers the "no serial number" free mode: a branded install
416
+ # that is not activated still gets the creator's free skills automatically.
417
+ #
418
+ # Returns { success: bool, skills: [], error: }. Each skill in the returned
419
+ # array carries the same shape as fetch_brand_skills! (name, latest_version,
420
+ # description, etc.) so install_brand_skill! can consume it directly.
421
+ def fetch_free_skills!
422
+ return { success: false, error: "Not branded", skills: [] } unless branded?
423
+ if @package_name.nil? || @package_name.strip.empty?
424
+ return { success: false, error: "package_name not configured", skills: [] }
425
+ end
426
+
427
+ encoded_pkg = URI.encode_www_form_component(@package_name.strip)
428
+ response = platform_client.get("/api/v1/distributions/free_skills?package_name=#{encoded_pkg}")
429
+
430
+ if response[:success] && response[:data].is_a?(Hash)
431
+ installed = installed_brand_skills
432
+ skills = (response[:data]["skills"] || []).map do |skill|
433
+ normalized = skill["name"].to_s.downcase.gsub(/[\s_]+/, "-").gsub(/[^a-z0-9-]/, "").gsub(/-+/, "-")
434
+ name = installed.keys.find { |k| k == normalized } || normalized
435
+ local = installed[name]
436
+ latest_ver = (skill["latest_version"] || {})["version"] || skill["version"]
437
+ needs_update = local ? version_older?(local["version"], latest_ver) : false
438
+ skill.merge(
439
+ "name" => name,
440
+ "installed_version" => local ? local["version"] : nil,
441
+ "needs_update" => needs_update
442
+ )
443
+ end
444
+ { success: true, skills: skills, paid_skills_count: response[:data]["paid_skills_count"].to_i }
445
+ else
446
+ { success: false, error: response[:error] || "Failed to fetch free skills", skills: [], paid_skills_count: 0 }
447
+ end
448
+ end
449
+
450
+ # Install a single free (unencrypted) skill. Thin wrapper around
451
+ # install_brand_skill! that records the skill as encrypted: false so the
452
+ # loader reads SKILL.md directly without attempting decryption.
453
+ def install_free_skill!(skill_info)
454
+ install_brand_skill!(skill_info, encrypted: false)
455
+ end
456
+
457
+ # Synchronise free skills in the background for unactivated branded installs.
458
+ #
459
+ # Mirrors sync_brand_skills_async! but uses the public free_skills endpoint
460
+ # so no license is required. Only runs when the install is branded and NOT
461
+ # activated — once a license is activated the regular brand-skill sync
462
+ # takes over (and may include additional encrypted skills).
463
+ #
464
+ # @return [Thread, nil]
465
+ def sync_free_skills_async!(on_complete: nil)
466
+ return nil unless branded?
467
+ return nil if activated?
468
+ return nil if ENV["CLACKY_TEST"] == "1"
469
+
470
+ Thread.new do
471
+ Thread.current.abort_on_exception = false
472
+
473
+ begin
474
+ result = fetch_free_skills!
475
+ next unless result[:success]
476
+
477
+ remote_skill_names = result[:skills].map { |s| s["name"] }
478
+ installed_brand_skills.each_key do |local_name|
479
+ send(:delete_brand_skill!, local_name) unless remote_skill_names.include?(local_name)
480
+ end
481
+
482
+ installed = installed_brand_skills
483
+ to_install = result[:skills].select { |s| installed[s["name"]].nil? || s["needs_update"] }
484
+ results = to_install.map { |skill_info| install_free_skill!(skill_info) }
485
+
486
+ on_complete&.call(results)
487
+ rescue StandardError
488
+ # Background sync failures are intentionally swallowed.
489
+ end
490
+ end
491
+ end
492
+
413
493
  # Upload (publish) a custom skill ZIP to the OpenClacky Cloud API.
414
494
  # Calls POST /api/v1/client/skills (system-license endpoint).
415
495
  # zip_data is the raw binary content of the ZIP file.
@@ -629,7 +709,9 @@ module Clacky
629
709
 
630
710
  # Install (or update) a single brand skill by downloading and extracting its zip.
631
711
  # skill_info: a hash from fetch_brand_skills! with at least name + latest_version.download_url + version
632
- def install_brand_skill!(skill_info)
712
+ # encrypted: whether the ZIP contains AES-encrypted .enc files + MANIFEST.enc.json (true)
713
+ # or plaintext SKILL.md and supporting files (false, used by free-mode).
714
+ def install_brand_skill!(skill_info, encrypted: true)
633
715
  require "net/http"
634
716
  require "uri"
635
717
 
@@ -698,10 +780,10 @@ module Clacky
698
780
 
699
781
  FileUtils.rm_f(tmp_zip)
700
782
 
701
- # Record installed version in brand_skills.json (including description for
702
- # offline display when the remote API is unreachable).
703
- # encrypted: true because the ZIP contains MANIFEST.enc.json + AES-256-GCM encrypted files.
704
- record_installed_skill(slug, version, skill_info["description"], encrypted: true, description_zh: skill_info["description_zh"], name_zh: skill_info["name_zh"])
783
+ record_installed_skill(slug, version, skill_info["description"],
784
+ encrypted: encrypted,
785
+ description_zh: skill_info["description_zh"],
786
+ name_zh: skill_info["name_zh"])
705
787
 
706
788
  { success: true, name: slug, version: version }
707
789
  rescue StandardError, ScriptError => e
data/lib/clacky/cli.rb CHANGED
@@ -965,7 +965,7 @@ module Clacky
965
965
  # ── Security gate ──────────────────────────────────────────────────────
966
966
  # Binding to 0.0.0.0 exposes the server to the public network.
967
967
  # Refuse to start unless CLACKY_ACCESS_KEY env var is set.
968
- if options[:host] == "0.0.0.0" && ENV.fetch("CLACKY_ACCESS_KEY", "").strip.empty?
968
+ if options[:host] == "0.0.0.0" && !ENV.key?("CLACKY_ACCESS_KEY")
969
969
  puts <<~MSG
970
970
  ╔══════════════════════════════════════════════════════════════╗
971
971
  ║ ⚠️ Security Warning: Refusing to start ║
data/lib/clacky/client.rb CHANGED
@@ -125,7 +125,7 @@ module Clacky
125
125
  # path. When given but streaming is not yet wired for the active provider,
126
126
  # a single synthetic invocation is fired after the response is received,
127
127
  # so UI plumbing can be exercised end-to-end without the proxy work.
128
- def send_messages_with_tools(messages, model:, tools:, max_tokens:, enable_caching: false, on_chunk: nil)
128
+ def send_messages_with_tools(messages, model:, tools:, max_tokens:, enable_caching: false, reasoning_effort: nil, on_chunk: nil)
129
129
  caching_enabled = enable_caching && supports_prompt_caching?(model)
130
130
  cloned = deep_clone(messages)
131
131
 
@@ -140,13 +140,13 @@ module Clacky
140
140
  response =
141
141
  if bedrock?
142
142
  streaming_used = !on_chunk.nil?
143
- send_bedrock_request(cloned, model, tools, max_tokens, caching_enabled, on_chunk: wrapped_on_chunk)
143
+ send_bedrock_request(cloned, model, tools, max_tokens, caching_enabled, reasoning_effort: reasoning_effort, on_chunk: wrapped_on_chunk)
144
144
  elsif anthropic_format?
145
145
  streaming_used = !on_chunk.nil?
146
- send_anthropic_request(cloned, model, tools, max_tokens, caching_enabled, on_chunk: wrapped_on_chunk)
146
+ send_anthropic_request(cloned, model, tools, max_tokens, caching_enabled, reasoning_effort: reasoning_effort, on_chunk: wrapped_on_chunk)
147
147
  else
148
148
  streaming_used = !on_chunk.nil?
149
- send_openai_request(cloned, model, tools, max_tokens, caching_enabled, on_chunk: wrapped_on_chunk)
149
+ send_openai_request(cloned, model, tools, max_tokens, caching_enabled, reasoning_effort: reasoning_effort, on_chunk: wrapped_on_chunk)
150
150
  end
151
151
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
152
152
 
@@ -217,8 +217,8 @@ module Clacky
217
217
 
218
218
  # ── Bedrock Converse request / response ───────────────────────────────────
219
219
 
220
- def send_bedrock_request(messages, model, tools, max_tokens, caching_enabled, on_chunk: nil)
221
- body = MessageFormat::Bedrock.build_request_body(messages, model, tools, max_tokens, caching_enabled)
220
+ def send_bedrock_request(messages, model, tools, max_tokens, caching_enabled, reasoning_effort: nil, on_chunk: nil)
221
+ body = MessageFormat::Bedrock.build_request_body(messages, model, tools, max_tokens, caching_enabled, reasoning_effort: reasoning_effort)
222
222
  return send_bedrock_stream_request(body, model, on_chunk) if on_chunk
223
223
 
224
224
  response = bedrock_connection.post(bedrock_endpoint(model)) { |r| r.body = body.to_json }
@@ -248,7 +248,10 @@ module Clacky
248
248
  end
249
249
  end
250
250
 
251
- raise_error(response) unless response.status == 200
251
+ unless response.status == 200
252
+ response.env.body = sse_buf if response.body.to_s.empty?
253
+ raise_error(response)
254
+ end
252
255
  MessageFormat::Bedrock.parse_response(aggregator.to_h)
253
256
  end
254
257
 
@@ -263,11 +266,11 @@ module Clacky
263
266
 
264
267
  # ── Anthropic request / response ──────────────────────────────────────────
265
268
 
266
- def send_anthropic_request(messages, model, tools, max_tokens, caching_enabled, on_chunk: nil)
269
+ def send_anthropic_request(messages, model, tools, max_tokens, caching_enabled, reasoning_effort: nil, on_chunk: nil)
267
270
  # Apply cache_control to the message that marks the cache breakpoint
268
271
  messages = apply_message_caching(messages) if caching_enabled
269
272
 
270
- body = MessageFormat::Anthropic.build_request_body(messages, model, tools, max_tokens, caching_enabled)
273
+ body = MessageFormat::Anthropic.build_request_body(messages, model, tools, max_tokens, caching_enabled, reasoning_effort: reasoning_effort)
271
274
  return send_anthropic_stream_request(body, on_chunk) if on_chunk
272
275
 
273
276
  response = anthropic_connection.post(anthropic_messages_path) { |r| r.body = body.to_json }
@@ -304,14 +307,15 @@ module Clacky
304
307
 
305
308
  # ── OpenAI request / response ─────────────────────────────────────────────
306
309
 
307
- def send_openai_request(messages, model, tools, max_tokens, caching_enabled, on_chunk: nil)
310
+ def send_openai_request(messages, model, tools, max_tokens, caching_enabled, reasoning_effort: nil, on_chunk: nil)
308
311
  # Apply cache_control markers to messages when caching is enabled.
309
312
  # OpenRouter proxies Claude with the same cache_control field convention as Anthropic direct.
310
313
  messages = apply_message_caching(messages) if caching_enabled
311
314
 
312
315
  body = MessageFormat::OpenAI.build_request_body(
313
316
  messages, model, tools, max_tokens, caching_enabled,
314
- vision_supported: @vision_supported
317
+ vision_supported: @vision_supported,
318
+ reasoning_effort: reasoning_effort
315
319
  )
316
320
  return send_openai_stream_request(body, on_chunk) if on_chunk
317
321