openclacky 1.1.2 โ†’ 1.1.3

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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/.clacky/skills/gem-release/SKILL.md +27 -31
  3. data/CHANGELOG.md +14 -0
  4. data/Dockerfile +28 -0
  5. data/docs/engineering-article.md +343 -0
  6. data/lib/clacky/agent/llm_caller.rb +1 -5
  7. data/lib/clacky/cli.rb +1 -1
  8. data/lib/clacky/message_format/anthropic.rb +17 -1
  9. data/lib/clacky/providers.rb +34 -0
  10. data/lib/clacky/server/channel/adapters/dingtalk/adapter.rb +142 -5
  11. data/lib/clacky/server/channel/adapters/dingtalk/api_client.rb +309 -0
  12. data/lib/clacky/ui2/ui_controller.rb +14 -0
  13. data/lib/clacky/ui_interface.rb +14 -0
  14. data/lib/clacky/utils/model_pricing.rb +96 -25
  15. data/lib/clacky/version.rb +1 -1
  16. data/lib/clacky/web/app.css +8 -0
  17. data/lib/clacky/web/index.html +1 -1
  18. data/lib/clacky/web/onboard.js +6 -0
  19. data/lib/clacky/web/settings.js +17 -5
  20. data/scripts/build/lib/apt.sh +30 -10
  21. data/scripts/build/lib/network.sh +3 -2
  22. data/scripts/install.sh +30 -9
  23. metadata +3 -16
  24. data/docs/HOW-TO-USE-CN.md +0 -96
  25. data/docs/HOW-TO-USE.md +0 -94
  26. data/docs/browser-cdp-native-design.md +0 -195
  27. data/docs/c-end-user-positioning.md +0 -64
  28. data/docs/config.example.yml +0 -27
  29. data/docs/deploy-architecture.md +0 -619
  30. data/docs/deploy_subagent_design.md +0 -540
  31. data/docs/install-script-simplification.md +0 -89
  32. data/docs/memory-architecture.md +0 -343
  33. data/docs/openclacky_cloud_api_reference.md +0 -584
  34. data/docs/security-design.md +0 -109
  35. data/docs/session-management-redesign.md +0 -202
  36. data/docs/system-skill-authoring-guide.md +0 -47
  37. data/docs/why-developer.md +0 -371
  38. data/docs/why-openclacky.md +0 -266
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47f1d9f1ecb4338e0a19ce771dea37724ebfc70d9e0052dc7403e096a25c415d
4
- data.tar.gz: 6887db06529972b393c75c92e17b47da8294abae765ceff7280d71943a160c85
3
+ metadata.gz: ca451cdde2e1cc068bda60f6b56f3d534a0187a7fad0d0b42308ad391c028bdf
4
+ data.tar.gz: e828f029d229e20e4e41edbc6773c2f6e9d0bf66aae3ad5b088f563fa8bf4c51
5
5
  SHA512:
6
- metadata.gz: b49465d66eb2be634790d10813ac5988aca23f54a4d3c36c9690bd40bf0024ea5f7275b3bc1b89247aaa16cc30dbf1c1439733c51bdfc1f5750e02c7efbc8e80
7
- data.tar.gz: f0f4397dd4cca183f199545e7c5db6b4902382c66c237257e8b2a99847e49702881dd8bcf60a78201ee18526ae2b04bd4217bf6def502ccf3ce8a7fb6fb0bdd0
6
+ metadata.gz: 32ee351b327f14a64e66fa6d27926e99c148ee69965a41360528e8e68d69d5ea40e2377cb94f851d4f00bb1d445fed8e35474c35c620cdfe4cd2ae2a924af186
7
+ data.tar.gz: 8a08b30877664568e264f823fd328cab521dc7d3362c10dfb30b50aac76d951bb3c753df23f2d47f4ed631128f490810497c5166378d43c688bf814c81040867
@@ -121,48 +121,44 @@ The script runs all steps sequentially and stops on any failure. Monitor the out
121
121
 
122
122
  ### 4. Present release summary
123
123
 
124
- After the script completes successfully, present this summary:
124
+ After the script completes successfully, present a concise summary. The output will often be read in WeChat, so keep it compact and avoid template-like formatting that triggers message folding.
125
125
 
126
- ```
127
- ๐ŸŽ‰ v{version} released successfully!
128
-
129
- โœจ Highlight: [One sentence โ€” the biggest user-visible change, verb + value phrasing]
126
+ Rules:
127
+ - No emojis
128
+ - No tables (use a compact list if you need to list items)
129
+ - No multi-line code blocks
130
+ - Write as a natural, flowing message โ€” not a structured report
131
+ - Skip "More" / chore items unless they directly affect users
132
+ - Write from the user's perspective โ€” what they can now do, or what problem is fixed
133
+ - Translate technical terms into plain language
134
+ - Keep each item one sentence, action-oriented
130
135
 
131
- ๐Ÿ“ฆ What's new for users:
136
+ Format (flexible โ€” adapt as needed, but roughly):
132
137
 
133
- **New Features**
134
- - [translate each "Added" item into plain user-facing language]
138
+ ```
139
+ v{version} released.
135
140
 
136
- **Improvements**
137
- - [translate each "Improved" item into plain user-facing language]
141
+ [One sentence highlight โ€” the biggest user-visible change.]
138
142
 
139
- **Bug Fixes**
140
- - [translate each "Fixed" item into plain user-facing language]
143
+ Added:
144
+ - [translate each "Added" item]
145
+ - ...
141
146
 
142
- ๐Ÿงช Testing suggestions:
143
- | Feature | How to verify |
144
- |---------|--------------|
145
- | [key new feature] | [concrete steps to test] |
147
+ Improved:
148
+ - [translate each "Improved" item]
149
+ - ...
146
150
 
147
- ๐Ÿ”— Links:
148
- - RubyGems: https://rubygems.org/gems/openclacky/versions/{version}
149
- - GitHub Release: https://github.com/clacky-ai/openclacky/releases/tag/v{version}
151
+ Fixed:
152
+ - [translate each "Fixed" item]
153
+ - ...
150
154
 
151
- โฌ†๏ธ Upgrade:
152
- - In the Clacky UI, click "Upgrade" in the bottom-left โ†’ detect new version โ†’ click upgrade โ†’ done
153
- - Manual upgrade (CLI): gem update openclacky
155
+ Upgrade: click "Upgrade" in Web UI bottom-left, or `gem update openclacky`
156
+ Fresh install: curl -sSL https://raw.githubusercontent.com/clacky-ai/openclacky/main/scripts/install.sh | bash
154
157
 
155
- ๐Ÿ†• Fresh install:
156
- /bin/bash -c "$(curl -sSL https://raw.githubusercontent.com/clacky-ai/openclacky/main/scripts/install.sh)"
158
+ RubyGems: https://rubygems.org/gems/openclacky/versions/{version}
159
+ GitHub: https://github.com/clacky-ai/openclacky/releases/tag/v{version}
157
160
  ```
158
161
 
159
- Summary writing rules:
160
- - Write from the user's perspective โ€” what they can now do, or what problem is fixed
161
- - Avoid technical jargon; explain what things mean
162
- - Skip "More" / chore items unless they directly affect users
163
- - Keep each bullet to one sentence, action-oriented
164
- - Testing suggestions: 3โ€“8 items with concrete, actionable verification steps
165
-
166
162
  ## Pre-Release Caveats
167
163
 
168
164
  When releasing a pre-release version, inform the user of these behaviors:
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.3] - 2026-05-20
9
+
10
+ ### Added
11
+ - Qwen3.6 (qwen3.6) model provider
12
+ - Provider dropdown auto-focuses when opening model config in onboarding and settings
13
+ - Dockerfile for containerized deployment
14
+ - Debian apt mirror support for CN users, with refactored mirror configuration
15
+
16
+ ### Fixed
17
+ - History file parsing incorrectly handles certain message formats
18
+ - DeepSeek model pricing and token counting
19
+ - Compression progress bar display during message compression
20
+ - DingTalk: markdown message rendering, file/image delivery failures, and inbound file message type handling
21
+
8
22
  ## [1.1.2] - 2026-05-20
9
23
 
10
24
  ### Added
data/Dockerfile ADDED
@@ -0,0 +1,28 @@
1
+ FROM ruby:3.4.4-slim AS builder
2
+
3
+ RUN apt-get update && apt-get install -y \
4
+ build-essential \
5
+ curl \
6
+ && rm -rf /var/lib/apt/lists/*
7
+
8
+ RUN gem install openclacky --no-document
9
+
10
+ FROM ruby:3.4.4-slim
11
+
12
+ RUN apt-get update && apt-get install -y \
13
+ git \
14
+ curl \
15
+ python3 \
16
+ && rm -rf /var/lib/apt/lists/*
17
+
18
+ COPY --from=builder /usr/local/bundle /usr/local/bundle
19
+
20
+ RUN curl https://mise.run | sh
21
+ ENV PATH="/root/.local/bin:$PATH"
22
+
23
+ VOLUME ["/root/.clacky"]
24
+
25
+ EXPOSE 7070
26
+
27
+ ENTRYPOINT ["openclacky"]
28
+ CMD ["server", "--host", "0.0.0.0"]
@@ -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)
@@ -763,11 +763,7 @@ module Clacky
763
763
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
764
764
  return if now - last_emit_at < min_interval && output_tokens > 0
765
765
  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
- )
766
+ @ui.stream_thinking_progress(input_tokens: input_tokens, output_tokens: output_tokens)
771
767
  }
772
768
  end
773
769
  end
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 โ•‘
@@ -182,7 +182,23 @@ module Clacky
182
182
  func = tc[:function] || tc
183
183
  name = func[:name] || tc[:name]
184
184
  raw_args = func[:arguments] || tc[:arguments]
185
- input = raw_args.is_a?(String) ? JSON.parse(raw_args) : raw_args
185
+ input =
186
+ if raw_args.is_a?(String)
187
+ begin
188
+ JSON.parse(raw_args)
189
+ rescue JSON::ParserError => e
190
+ Clacky::Logger.warn("message_format.anthropic.tool_args_parse_failed",
191
+ tool_name: name.to_s,
192
+ tool_call_id: tc[:id].to_s,
193
+ args_len: raw_args.length,
194
+ args_head: raw_args[0, 120],
195
+ error: e.message
196
+ ) if defined?(Clacky::Logger)
197
+ {}
198
+ end
199
+ else
200
+ raw_args
201
+ end
186
202
  blocks << { type: "tool_use", id: tc[:id], name: name, input: input || {} }
187
203
  end
188
204
 
@@ -329,6 +329,40 @@ module Clacky
329
329
  "gpt-5.4" => "gpt-5.4-mini"
330
330
  },
331
331
  "website_url" => "https://platform.openai.com/api-keys"
332
+ }.freeze,
333
+
334
+ "qwen" => {
335
+ "name" => "Qwen (Alibaba)",
336
+ "base_url" => "https://dashscope.aliyuncs.com/compatible-mode/v1",
337
+ "api" => "openai-completions",
338
+ "default_model" => "qwen3.6-plus",
339
+ "models" => [
340
+ "qwen3.6-plus",
341
+ "qwen3.6-max",
342
+ "qwen3.6-27b",
343
+ "qwen3.6-flash",
344
+ "qwen-plus-latest",
345
+ "qwen-vl-plus",
346
+ "qwen-vl-max"
347
+ ],
348
+ "endpoint_variants" => [
349
+ { "label" => "Mainland China", "label_key" => "settings.models.baseurl.variant.mainland_cn", "base_url" => "https://dashscope.aliyuncs.com/compatible-mode/v1", "region" => "cn" }.freeze,
350
+ { "label" => "Singapore", "label_key" => "settings.models.baseurl.variant.international", "base_url" => "https://dashscope-intl.aliyuncs.com/compatible-mode/v1", "region" => "intl" }.freeze,
351
+ { "label" => "US (Virginia)", "label_key" => "settings.models.baseurl.variant.us", "base_url" => "https://dashscope-us.aliyuncs.com/compatible-mode/v1", "region" => "us" }.freeze
352
+ ].freeze,
353
+ "capabilities" => { "vision" => false }.freeze,
354
+ "model_capabilities" => {
355
+ "qwen3.6-27b" => { "vision" => true }.freeze,
356
+ "qwen-vl-plus" => { "vision" => true }.freeze,
357
+ "qwen-vl-max" => { "vision" => true }.freeze
358
+ }.freeze,
359
+ "lite_models" => {
360
+ "qwen3.6-plus" => "qwen3.6-flash",
361
+ "qwen3.6-max" => "qwen3.6-flash",
362
+ "qwen3.6-27b" => "qwen3.6-flash",
363
+ "qwen-plus-latest" => "qwen3.6-flash"
364
+ },
365
+ "website_url" => "https://bailian.console.aliyun.com/?apiKey=1"
332
366
  }.freeze
333
367
 
334
368
  }.freeze