openclacky 1.5.23 → 1.5.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +46 -0
- data/lib/clacky/agent/cost_tracker.rb +55 -36
- data/lib/clacky/agent/hook_manager.rb +4 -1
- data/lib/clacky/agent/llm_caller.rb +46 -12
- data/lib/clacky/agent/memory_injector.rb +209 -0
- data/lib/clacky/agent/memory_updater.rb +16 -0
- data/lib/clacky/agent/skill_manager.rb +30 -8
- data/lib/clacky/agent.rb +66 -2
- data/lib/clacky/agent_config.rb +4 -2
- data/lib/clacky/anthropic_stream_aggregator.rb +11 -1
- data/lib/clacky/bedrock_stream_aggregator.rb +11 -1
- data/lib/clacky/billing/platform_billing.rb +1 -0
- data/lib/clacky/cli.rb +4 -3
- data/lib/clacky/client.rb +30 -25
- data/lib/clacky/default_extensions/advisor/panels/advisor/view.js +7 -1
- data/lib/clacky/default_extensions/git/panels/git/view.js +35 -4
- data/lib/clacky/default_extensions/secretary/README.md +69 -0
- data/lib/clacky/default_extensions/secretary/README.zh.md +69 -0
- data/lib/clacky/default_extensions/secretary/ext.yml +3 -0
- data/lib/clacky/default_extensions/secretary/icon.svg +17 -0
- data/lib/clacky/default_skills/channel-manager/SKILL.md +24 -5
- data/lib/clacky/default_skills/channel-manager/dingtalk_setup.rb +4 -2
- data/lib/clacky/default_skills/channel-manager/discord_setup.rb +4 -1
- data/lib/clacky/default_skills/channel-manager/weixin_setup.rb +2 -0
- data/lib/clacky/default_skills/media-gen/SKILL.md +14 -6
- data/lib/clacky/default_skills/onboard/SKILL.md +5 -7
- data/lib/clacky/default_skills/persist-memory/SKILL.md +15 -1
- data/lib/clacky/extension/api_extension.rb +13 -0
- data/lib/clacky/json_ui_controller.rb +14 -1
- data/lib/clacky/locales/i18n.rb +25 -3
- data/lib/clacky/message_history.rb +15 -2
- data/lib/clacky/openai_responses_stream_aggregator.rb +11 -1
- data/lib/clacky/openai_stream_aggregator.rb +11 -1
- data/lib/clacky/prompts/base.md +1 -1
- data/lib/clacky/providers.rb +7 -3
- data/lib/clacky/server/backup_manager.rb +98 -2
- data/lib/clacky/server/browser_manager.rb +10 -5
- data/lib/clacky/server/channel/channel_manager.rb +69 -45
- data/lib/clacky/server/http_server.rb +133 -42
- data/lib/clacky/server/preview.rb +26 -5
- data/lib/clacky/server/web_ui_controller.rb +12 -0
- data/lib/clacky/skill.rb +1 -1
- data/lib/clacky/ui_interface.rb +5 -0
- data/lib/clacky/utils/file_processor.rb +4 -2
- data/lib/clacky/utils/model_pricing.rb +19 -0
- data/lib/clacky/version.rb +1 -1
- data/lib/clacky/web/app.css +220 -6
- data/lib/clacky/web/app.js +18 -6
- data/lib/clacky/web/components/custom-select.js +7 -18
- data/lib/clacky/web/components/hint-tip.js +172 -0
- data/lib/clacky/web/components/sidebar.js +70 -0
- data/lib/clacky/web/features/backup/store.js +64 -27
- data/lib/clacky/web/features/backup/view.js +42 -11
- data/lib/clacky/web/features/channels/view.js +7 -7
- data/lib/clacky/web/features/new-session/view.js +10 -2
- data/lib/clacky/web/features/profile/view.js +4 -4
- data/lib/clacky/web/features/tasks/view.js +1 -0
- data/lib/clacky/web/features/trash/view.js +4 -4
- data/lib/clacky/web/i18n.js +61 -5
- data/lib/clacky/web/index.html +140 -43
- data/lib/clacky/web/projects.js +15 -2
- data/lib/clacky/web/sessions.js +234 -45
- data/lib/clacky/web/settings.js +93 -34
- data/lib/clacky/web/utils.js +44 -0
- data/lib/clacky/web/ws-dispatcher.js +17 -0
- data/lib/clacky/web/ws.js +16 -4
- data/lib/clacky/work/service.rb +2 -0
- data/lib/clacky.rb +1 -0
- metadata +6 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# 生活秘书
|
|
2
|
+
|
|
3
|
+
一个可以「交给它去做」的助理会话:简单问题当场回答,耗时的事派到后台执行,有结果或需要你拍板时再回来找你。
|
|
4
|
+
|
|
5
|
+
> 本扩展**默认启用**。新建会话时选择「生活秘书」,右侧面板会出现 **「工作事项」** 标签页。
|
|
6
|
+
|
|
7
|
+
## 适合交给它的事
|
|
8
|
+
|
|
9
|
+
- 需要查资料、读文档、对比方案的调研类工作
|
|
10
|
+
- 需要写文件、改代码、整理数据的执行类工作
|
|
11
|
+
- 需要等外部回复的事(例如发出消息后等对方答复)
|
|
12
|
+
- 每天早上/每天固定时间的例行汇总
|
|
13
|
+
|
|
14
|
+
## 怎么用
|
|
15
|
+
|
|
16
|
+
直接说出目标、可接受的完成标准和已知限制即可,例如:
|
|
17
|
+
|
|
18
|
+
> 帮我把这个项目的 README 补齐,重点写部署和本地开发两部分,不要改代码。
|
|
19
|
+
|
|
20
|
+
秘书会判断这件事是否需要后台执行:
|
|
21
|
+
|
|
22
|
+
- **简单问题**:直接回答,不占用「工作事项」。
|
|
23
|
+
- **耗时的工作**:拆成一项「工作事项」,派给后台的工作助手,然后立刻回到和你的对话,不让你等。
|
|
24
|
+
|
|
25
|
+
## 「工作事项」面板
|
|
26
|
+
|
|
27
|
+
每个事项一张卡片,显示标题、状态和创建时间,按创建顺序排列,状态变化不会打乱位置。
|
|
28
|
+
|
|
29
|
+
状态含义:
|
|
30
|
+
|
|
31
|
+
| 状态 | 含义 |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| 等待开始处理 | 已排入队列,尚未开始 |
|
|
34
|
+
| 秘书正在处理 | 后台正在执行 |
|
|
35
|
+
| 等待外部事件或定时检查 | 等对方回复,或等到指定时间再检查 |
|
|
36
|
+
| 等待秘书协助 | 需要信息、决定或授权,秘书会来问你 |
|
|
37
|
+
| 已暂停 | 你或秘书暂停了这件事 |
|
|
38
|
+
| 已完成 | 有交付物或阶段结果 |
|
|
39
|
+
| 遇到问题 | 执行失败,需要和秘书一起处理 |
|
|
40
|
+
| 已取消 | 已终止,不会继续 |
|
|
41
|
+
|
|
42
|
+
卡片上可以:
|
|
43
|
+
|
|
44
|
+
- **与秘书讨论**:把「关于「标题」,我想补充:」预填到输入框,接着聊就行。
|
|
45
|
+
- **查看执行记录**:跳到后台工作助手的会话,看完整的执行过程。
|
|
46
|
+
- **事项详情**:展开目标、约束和历次变更记录。
|
|
47
|
+
|
|
48
|
+
面板底部还有 **「定时安排」** 区,列出每天/工作日固定时间执行的计划、下次执行时间和计划内容。想调整时点「与秘书讨论」,用一句话说明改法即可。
|
|
49
|
+
|
|
50
|
+
## 后台执行是怎么进行的
|
|
51
|
+
|
|
52
|
+
1. 秘书把目标、背景、授权边界和验收标准写成任务,交给后台工作助手。
|
|
53
|
+
2. 工作助手在**自己的会话**里使用现有工具执行,并遵守你当前的权限与确认设置。
|
|
54
|
+
3. 执行告一段落时它会回报结果,可能是:完成、需要你决定、或需要等外部事件。
|
|
55
|
+
4. 秘书收到回报后告诉你结论;需要你拍板时,它会先问,再把你的答复转达回去。
|
|
56
|
+
|
|
57
|
+
同一件事可以在原会话里继续追加要求,不需要重新开一项。
|
|
58
|
+
|
|
59
|
+
## 注意事项
|
|
60
|
+
|
|
61
|
+
- 后台执行不阻塞对话,你可以随时插话、改需求或让它取消。
|
|
62
|
+
- 工作助手不会自行扩大授权:遇到需要新权限或超出范围的步骤,它会先回来问。
|
|
63
|
+
- 显示「已完成」只代表这一轮工作交付了结果,是否接受由你决定,可以继续提修改意见。
|
|
64
|
+
- 定时安排依赖本机运行的服务,机器关机或服务停止时不会执行。
|
|
65
|
+
|
|
66
|
+
## 扩展信息
|
|
67
|
+
|
|
68
|
+
- 扩展 ID:`secretary`
|
|
69
|
+
- 提供内容:对话代理「生活秘书」、后台代理「秘书工作助手」、工具 `delegate_work` / `manage_work` / `yield_work`、面板「工作事项」、接口 `/api/ext/secretary/work`
|
|
@@ -3,8 +3,11 @@ name: Secretary
|
|
|
3
3
|
display_name: Secretary
|
|
4
4
|
display_name_zh: 生活秘书
|
|
5
5
|
description: Delegate work, track progress and resume after replies
|
|
6
|
+
description_zh: 把工作委派到后台,跟进进展,收到回复后接着推进
|
|
6
7
|
version: "0.1.0"
|
|
8
|
+
icon: icon.svg
|
|
7
9
|
author: OpenClacky
|
|
10
|
+
license: MIT
|
|
8
11
|
contributes:
|
|
9
12
|
api: api/handler.rb
|
|
10
13
|
agents:
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="secretary-bg" x1="18" y1="0" x2="18" y2="36" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop stop-color="#FB7185"/>
|
|
5
|
+
<stop offset="1" stop-color="#BE123C"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect width="36" height="36" fill="url(#secretary-bg)"/>
|
|
9
|
+
<g transform="translate(8 8) scale(0.8333)" stroke="#fff" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
|
|
10
|
+
<rect width="8" height="4" x="8" y="2" rx="1" ry="1"/>
|
|
11
|
+
<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/>
|
|
12
|
+
<path d="M12 11h4"/>
|
|
13
|
+
<path d="M12 16h4"/>
|
|
14
|
+
<path d="M8 11h.01"/>
|
|
15
|
+
<path d="M8 16h.01"/>
|
|
16
|
+
</g>
|
|
17
|
+
</svg>
|
|
@@ -6,7 +6,7 @@ description: |
|
|
|
6
6
|
Configure IM platform channels (Feishu, WeCom, Weixin, Discord, Telegram, DingTalk, QQ) for openclacky.
|
|
7
7
|
Uses browser automation for navigation; guides the user to paste credentials and perform UI steps.
|
|
8
8
|
Trigger on: "channel setup", "setup feishu", "setup wecom", "setup weixin", "setup wechat", "setup discord", "setup telegram", "setup dingtalk", "setup qq",
|
|
9
|
-
"channel config", "channel status", "channel enable", "channel disable", "channel reconfigure", "channel doctor",
|
|
9
|
+
"bind this session to a channel", "channel config", "channel status", "channel enable", "channel disable", "channel reconfigure", "channel doctor",
|
|
10
10
|
"send message to weixin", "send message to feishu", "send message to wecom", "send message to discord", "send message to telegram", "send message to dingtalk", "send message to qq".
|
|
11
11
|
Subcommands: setup, status, enable <platform>, disable <platform>, reconfigure, doctor, send.
|
|
12
12
|
argument-hint: "setup | status | enable <platform> | disable <platform> | reconfigure | doctor | send <platform> <message>"
|
|
@@ -41,6 +41,25 @@ Configure IM platform channels for openclacky.
|
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
44
|
+
## Keep the current conversation when connecting a channel
|
|
45
|
+
|
|
46
|
+
When the user asks to connect a channel from this conversation, include
|
|
47
|
+
`"bind_session_id": "<actual CLACKY_SESSION_ID>"` in the same
|
|
48
|
+
`POST /api/channels/<platform>` request that saves the credentials. Read the
|
|
49
|
+
actual ID from the terminal environment; never invent it. For an already
|
|
50
|
+
configured channel, POST just `bind_session_id` and the selected `instance_id`.
|
|
51
|
+
The first message received by that instance binds its chat to this conversation
|
|
52
|
+
and runs here, retaining the role and history. No `/bind` command or new session
|
|
53
|
+
is needed. Other chats keep their existing routing.
|
|
54
|
+
|
|
55
|
+
The Weixin, Discord and DingTalk scripts below pass `CLACKY_SESSION_ID` when
|
|
56
|
+
saving credentials. This only applies to setup/binding, not status, enable,
|
|
57
|
+
disable or credential-only maintenance. When explicitly configuring an account
|
|
58
|
+
without binding this conversation, omit `bind_session_id` and run scripts with
|
|
59
|
+
`CLACKY_SESSION_ID` unset. Outside a session, omit the field.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
44
63
|
## Multiple instances per platform
|
|
45
64
|
|
|
46
65
|
Every platform can be connected more than once (for example a personal and a work
|
|
@@ -164,7 +183,7 @@ Parse both values.
|
|
|
164
183
|
```bash
|
|
165
184
|
curl -X POST http://${CLACKY_SERVER_HOST}:${CLACKY_SERVER_PORT}/api/channels/feishu \
|
|
166
185
|
-H "Content-Type: application/json" \
|
|
167
|
-
-d '{"app_id":"<APP_ID>","app_secret":"<APP_SECRET>","domain":"https://open.feishu.cn"}'
|
|
186
|
+
-d '{"app_id":"<APP_ID>","app_secret":"<APP_SECRET>","domain":"https://open.feishu.cn","bind_session_id":"<actual CLACKY_SESSION_ID>"}'
|
|
168
187
|
```
|
|
169
188
|
|
|
170
189
|
**CRITICAL: This curl call is the ONLY way to save credentials. NEVER write `~/.clacky/channels.yml`
|
|
@@ -244,7 +263,7 @@ When the session ends with `exit_code: 0`, tell the user:
|
|
|
244
263
|
```bash
|
|
245
264
|
curl -X POST http://${CLACKY_SERVER_HOST}:${CLACKY_SERVER_PORT}/api/channels/wecom \
|
|
246
265
|
-H "Content-Type: application/json" \
|
|
247
|
-
-d '{"bot_id":"<BOT_ID>","secret":"<SECRET>"}'
|
|
266
|
+
-d '{"bot_id":"<BOT_ID>","secret":"<SECRET>","bind_session_id":"<actual CLACKY_SESSION_ID>"}'
|
|
248
267
|
```
|
|
249
268
|
|
|
250
269
|
On success: "✅ WeCom channel configured. WeCom client → Contacts → Smart Bot to find it."
|
|
@@ -407,7 +426,7 @@ Call the server API. It calls `getMe` against the Bot API to validate the token
|
|
|
407
426
|
```bash
|
|
408
427
|
curl -s -X POST http://${CLACKY_SERVER_HOST}:${CLACKY_SERVER_PORT}/api/channels/telegram \
|
|
409
428
|
-H "Content-Type: application/json" \
|
|
410
|
-
-d '{"bot_token":"<TOKEN>","base_url":"<BASE_URL_OR_OMIT>"}'
|
|
429
|
+
-d '{"bot_token":"<TOKEN>","base_url":"<BASE_URL_OR_OMIT>","bind_session_id":"<actual CLACKY_SESSION_ID>"}'
|
|
411
430
|
```
|
|
412
431
|
|
|
413
432
|
- `200 { "ok": true }` — token validated and saved. The adapter starts long-polling immediately.
|
|
@@ -460,7 +479,7 @@ The server persists the credentials and immediately opens the gateway WebSocket:
|
|
|
460
479
|
```bash
|
|
461
480
|
curl -s -X POST http://${CLACKY_SERVER_HOST}:${CLACKY_SERVER_PORT}/api/channels/qq \
|
|
462
481
|
-H "Content-Type: application/json" \
|
|
463
|
-
-d '{"app_id":"<APP_ID>","app_secret":"<APP_SECRET>","sandbox":<TRUE_OR_FALSE>}'
|
|
482
|
+
-d '{"app_id":"<APP_ID>","app_secret":"<APP_SECRET>","sandbox":<TRUE_OR_FALSE>,"bind_session_id":"<actual CLACKY_SESSION_ID>"}'
|
|
464
483
|
```
|
|
465
484
|
|
|
466
485
|
- `200` — credentials saved; the QQ gateway session starts.
|
|
@@ -134,8 +134,10 @@ def mode_poll(device_code, expires_in: POLL_TIMEOUT, interval: POLL_INTERVAL)
|
|
|
134
134
|
step "Phase 4 — Saving credentials to clacky server..."
|
|
135
135
|
|
|
136
136
|
begin
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
fields = { client_id: client_id, client_secret: client_secret, enabled: true }
|
|
138
|
+
session_id = ENV["CLACKY_SESSION_ID"].to_s.strip
|
|
139
|
+
fields[:bind_session_id] = session_id unless session_id.empty?
|
|
140
|
+
res = server_post("/api/channels/dingtalk", fields)
|
|
139
141
|
if res.code.to_i == 200
|
|
140
142
|
ok "Credentials saved, DingTalk Stream adapter starting..."
|
|
141
143
|
else
|
|
@@ -95,7 +95,10 @@ end
|
|
|
95
95
|
|
|
96
96
|
def save_to_server(bot_token:)
|
|
97
97
|
uri = URI("#{CLACKY_SERVER_URL}/api/channels/discord")
|
|
98
|
-
|
|
98
|
+
fields = { bot_token: bot_token }
|
|
99
|
+
session_id = ENV["CLACKY_SESSION_ID"].to_s.strip
|
|
100
|
+
fields[:bind_session_id] = session_id unless session_id.empty?
|
|
101
|
+
body = JSON.generate(fields)
|
|
99
102
|
|
|
100
103
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
101
104
|
http.read_timeout = 30
|
|
@@ -150,6 +150,8 @@ end
|
|
|
150
150
|
def save_to_server(token:, base_url:)
|
|
151
151
|
uri = URI("#{CLACKY_SERVER_URL}/api/channels/weixin")
|
|
152
152
|
body = { token: token, base_url: base_url }
|
|
153
|
+
session_id = ENV["CLACKY_SESSION_ID"].to_s.strip
|
|
154
|
+
body[:bind_session_id] = session_id unless session_id.empty?
|
|
153
155
|
body[:instance_id] = GIVEN_INSTANCE_ID unless GIVEN_INSTANCE_ID.empty?
|
|
154
156
|
body[:name] = GIVEN_NAME unless GIVEN_NAME.empty?
|
|
155
157
|
body = JSON.generate(body)
|
|
@@ -159,7 +159,7 @@ Common `error_type` values: `not_configured`, `auth_required`, `network_error`,
|
|
|
159
159
|
|
|
160
160
|
## Step 3 — Show the image
|
|
161
161
|
|
|
162
|
-
`Read` does NOT show the image to the user — it only feeds it into your own context. To make the user actually see it, write
|
|
162
|
+
`Read` does NOT show the image to the user — it only feeds it into your own context. To make the user actually see it, write exactly one markdown tag in your reply and nothing else for that file:
|
|
163
163
|
|
|
164
164
|
```markdown
|
|
165
165
|

|
|
@@ -260,9 +260,17 @@ curl -s -X POST http://${CLACKY_SERVER_HOST}:${CLACKY_SERVER_PORT}/api/media/vid
|
|
|
260
260
|
}
|
|
261
261
|
```
|
|
262
262
|
|
|
263
|
-
The `video` field is an absolute path on disk.
|
|
264
|
-
markdown
|
|
265
|
-
|
|
263
|
+
The `video` field is an absolute path on disk. To let the user watch it, write
|
|
264
|
+
exactly one markdown tag in your reply and nothing else for that file:
|
|
265
|
+
|
|
266
|
+
```markdown
|
|
267
|
+

|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
The Web UI turns this into an inline player on its own — do NOT also write an
|
|
271
|
+
HTML `<video>` tag or a second plain `[link]`, or the clip shows up twice. If
|
|
272
|
+
you're embedding it in a document, convert the path to one relative to that
|
|
273
|
+
document.
|
|
266
274
|
|
|
267
275
|
### Response (failure)
|
|
268
276
|
|
|
@@ -580,10 +588,10 @@ The `audio` field is an absolute path on disk. Output is mono 16-bit PCM at
|
|
|
580
588
|
24 kHz wrapped in a standard WAV container — playable by any browser, OS
|
|
581
589
|
player, or `<audio>` tag without conversion.
|
|
582
590
|
|
|
583
|
-
To let the user hear it, write
|
|
591
|
+
To let the user hear it, write exactly one markdown tag in your reply:
|
|
584
592
|
|
|
585
593
|
```markdown
|
|
586
|
-
[
|
|
594
|
+

|
|
587
595
|
```
|
|
588
596
|
|
|
589
597
|
For embedding in HTML documents, use:
|
|
@@ -493,7 +493,6 @@ Use the `read` tool. Expect YAML frontmatter:
|
|
|
493
493
|
---
|
|
494
494
|
topic: <topic>
|
|
495
495
|
description: <one-line>
|
|
496
|
-
updated_at: YYYY-MM-DD
|
|
497
496
|
---
|
|
498
497
|
|
|
499
498
|
<body in Markdown>
|
|
@@ -506,7 +505,7 @@ If parsing fails, continue — frontmatter is advisory.
|
|
|
506
505
|
2–4 short sentences. Quote the topic + most concrete facts. Don't dump the file.
|
|
507
506
|
|
|
508
507
|
Example (en):
|
|
509
|
-
> This memory is about **Ruby style preferences
|
|
508
|
+
> This memory is about **Ruby style preferences**:
|
|
510
509
|
> you prefer inline `private def` over a standalone `private` keyword,
|
|
511
510
|
> and frozen string literals on all new files.
|
|
512
511
|
|
|
@@ -538,17 +537,16 @@ zh:
|
|
|
538
537
|
|
|
539
538
|
### C.6a. "Leave it"
|
|
540
539
|
|
|
541
|
-
|
|
540
|
+
Run `touch <path>` with the terminal tool instead of rewriting the file. Tell the user you've confirmed it's current.
|
|
542
541
|
|
|
543
542
|
### C.6b. "Update"
|
|
544
543
|
|
|
545
544
|
Ask ONE follow-up (free text) for what changed. Then:
|
|
546
545
|
|
|
547
546
|
1. Merge into the body. Rewrite in place for stale facts; append for net-new.
|
|
548
|
-
2.
|
|
549
|
-
3.
|
|
550
|
-
4.
|
|
551
|
-
5. Show a short diff-style summary.
|
|
547
|
+
2. Keep under **300 words** — distill, don't accumulate.
|
|
548
|
+
3. Write back with the same `topic` / `description` keys. Drop any legacy `updated_at` key.
|
|
549
|
+
4. Show a short diff-style summary.
|
|
552
550
|
|
|
553
551
|
### C.6c. "Delete"
|
|
554
552
|
|
|
@@ -16,7 +16,7 @@ forbidden_tools:
|
|
|
16
16
|
|
|
17
17
|
You are a **Memory Persistence Subagent** — a pure executor. The caller has already decided that something must be written. Your job is to write it correctly: pick the right file, merge with existing content, respect the size limit.
|
|
18
18
|
|
|
19
|
-
You do NOT decide whether to write. If the task description tells you to persist X, you persist X.
|
|
19
|
+
You do NOT decide whether to write. If the task description tells you to persist X, you persist X — but the content rules in Guidelines still decide which details of X go into the file.
|
|
20
20
|
|
|
21
21
|
## Existing Memory Files
|
|
22
22
|
|
|
@@ -34,6 +34,15 @@ description: <one-line description>
|
|
|
34
34
|
<content in concise Markdown>
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
### The `description` field
|
|
38
|
+
|
|
39
|
+
The description is the ONLY thing a future recall sees when deciding whether to open the file, so it must say what the file is about, not what happened to it.
|
|
40
|
+
|
|
41
|
+
- One line, at most 80 characters. No line breaks, no Markdown.
|
|
42
|
+
- Describe the topic's scope (e.g. `Deployment target, region, and release constraints`).
|
|
43
|
+
- No dates, version history, or "changed X to Y" — those belong in the body.
|
|
44
|
+
- When merging into an existing file, rewrite the description if it violates these rules.
|
|
45
|
+
|
|
37
46
|
## Workflow
|
|
38
47
|
|
|
39
48
|
For each item to persist:
|
|
@@ -56,6 +65,11 @@ Use the `write` tool. Always include the YAML frontmatter shown above.
|
|
|
56
65
|
- If a file grows much larger than that (say, well past 8000), trim the least important information rather than splitting one topic across multiple files.
|
|
57
66
|
- Prefer merging into an existing file over creating a new one. Only create a new file when no existing topic genuinely covers the area.
|
|
58
67
|
- Write concise, factual Markdown — no fluff, no redundant headings.
|
|
68
|
+
- For decisions, rules, and preferences, record the reason (**Why**) and when it applies (**How to apply**) — a bare rule cannot be judged in edge cases.
|
|
69
|
+
- Keep the current state, not a timeline. When new info supersedes old, replace the old statement instead of appending a dated entry.
|
|
70
|
+
- Write absolute dates (e.g. `2026-03-05`), never relative ones like "next Thursday".
|
|
71
|
+
- Leave out code paths, implementation details, install paths, git history, and debugging or troubleshooting narratives — the code and git log are authoritative, and copies go stale. The only exception is when the conversation shows the **user's own words** asking to remember that specific detail; details the calling agent added on its own do not count.
|
|
72
|
+
- Record only what the user stated or what was verified in the conversation. Do not write guesses as facts, and do not add general best practices or advice the user never gave — a future recall treats everything in the file as established.
|
|
59
73
|
- One topic per file. Don't bundle unrelated facts together.
|
|
60
74
|
- Do NOT use `terminal` or `file_reader` to list the memories directory — the list above is authoritative.
|
|
61
75
|
|
|
@@ -46,6 +46,19 @@ module Clacky
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
class << self
|
|
49
|
+
# Optional bidirectional events on the existing authenticated WebSocket.
|
|
50
|
+
# Only ext.<this extension id>.* frames reach this callback. Return true
|
|
51
|
+
# when handled; use connection.send_json for replies to this client only.
|
|
52
|
+
# Callbacks run on the socket reader: keep them short and non-blocking.
|
|
53
|
+
def on_ws_event(connection, message)
|
|
54
|
+
false
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Called after native subscription cleanup. Extensions own transient state.
|
|
58
|
+
def on_ws_close(connection)
|
|
59
|
+
nil
|
|
60
|
+
end
|
|
61
|
+
|
|
49
62
|
# Keyed by ext_id — every extension contributes at most one API unit
|
|
50
63
|
# (declared as `contributes.api: <path>` in ext.yml).
|
|
51
64
|
def registry
|
|
@@ -11,7 +11,8 @@ module Clacky
|
|
|
11
11
|
class JsonUIController
|
|
12
12
|
include Clacky::UIInterface
|
|
13
13
|
|
|
14
|
-
def initialize(output: $stdout, input: $stdin)
|
|
14
|
+
def initialize(output: $stdout, input: $stdin, stream: false)
|
|
15
|
+
@stream = stream
|
|
15
16
|
@output = output
|
|
16
17
|
@input = input
|
|
17
18
|
@mutex = Mutex.new
|
|
@@ -28,6 +29,18 @@ module Clacky
|
|
|
28
29
|
|
|
29
30
|
# === Output display ===
|
|
30
31
|
|
|
32
|
+
def stream_assistant_text?; @stream; end
|
|
33
|
+
|
|
34
|
+
def show_assistant_delta(message_id:, seq:, delta:)
|
|
35
|
+
return unless stream_assistant_text?
|
|
36
|
+
emit("assistant_message_delta", message_id: message_id, seq: seq, delta: delta)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def end_assistant_stream(message_id:)
|
|
40
|
+
return unless stream_assistant_text?
|
|
41
|
+
emit("assistant_message_stream_end", message_id: message_id)
|
|
42
|
+
end
|
|
43
|
+
|
|
31
44
|
def show_assistant_message(content, files:, interim: false, created_at: nil)
|
|
32
45
|
return if (content.nil? || content.strip.empty?) && files.empty?
|
|
33
46
|
|
data/lib/clacky/locales/i18n.rb
CHANGED
|
@@ -30,11 +30,33 @@ module Clacky
|
|
|
30
30
|
localized { |code| translate(code, key, **vars) }
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def self.supported?(code)
|
|
34
|
+
LOCALES.key?(code.to_s)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Collapses every regional variant onto its base code ("zh-CN" -> "zh",
|
|
38
|
+
# "en_US.UTF-8" -> "en"). Returns nil for anything we have no table for.
|
|
39
|
+
# This is the single place that decides what a language tag means.
|
|
40
|
+
def self.normalize(code)
|
|
41
|
+
code = code.to_s.strip.downcase
|
|
42
|
+
return nil if code.empty?
|
|
43
|
+
return code if supported?(code)
|
|
44
|
+
|
|
45
|
+
base = code.split(/[-_.]/).first
|
|
46
|
+
supported?(base) ? base : nil
|
|
47
|
+
end
|
|
48
|
+
|
|
33
49
|
def self.locale
|
|
34
|
-
|
|
50
|
+
normalize(Thread.current[:lang]) || env_locale
|
|
51
|
+
end
|
|
35
52
|
|
|
36
|
-
|
|
37
|
-
|
|
53
|
+
# The first non-empty POSIX variable wins, so an empty LC_ALL must not
|
|
54
|
+
# mask LANG. An unsupported value (fr_FR) falls back to the default
|
|
55
|
+
# rather than letting a lower-priority variable decide.
|
|
56
|
+
def self.env_locale
|
|
57
|
+
raw = %w[LC_ALL LC_MESSAGES LANG].map { |key| ENV[key].to_s }
|
|
58
|
+
.find { |value| !value.strip.empty? }
|
|
59
|
+
normalize(raw) || DEFAULT_LOCALE
|
|
38
60
|
end
|
|
39
61
|
end
|
|
40
62
|
end
|
|
@@ -11,10 +11,10 @@ module Clacky
|
|
|
11
11
|
class MessageHistory
|
|
12
12
|
# Fields that are internal to the agent and must not be sent to the API.
|
|
13
13
|
INTERNAL_FIELDS = %i[
|
|
14
|
-
message_id task_id created_at system_injected session_context memory_update
|
|
14
|
+
message_id task_id created_at system_injected session_context context_key memory_update
|
|
15
15
|
subagent_instructions subagent_result subagent_transcript token_usage
|
|
16
16
|
compressed_summary chunk_path truncated transient
|
|
17
|
-
chunk_index chunk_count ext_events skill_command skill_command_display
|
|
17
|
+
chunk_index chunk_count memory_recall memory_files ext_events skill_command skill_command_display
|
|
18
18
|
display_files display_references feedback_requests
|
|
19
19
|
].freeze
|
|
20
20
|
|
|
@@ -55,6 +55,19 @@ module Clacky
|
|
|
55
55
|
self
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
# Append a changed context snapshot without rewriting the cached prefix.
|
|
59
|
+
# A nil snapshot is absent: skip it initially, or use `empty` to supersede
|
|
60
|
+
# an earlier snapshot. The key survives serialization but is never model input.
|
|
61
|
+
def append_context(key, content, empty: nil)
|
|
62
|
+
previous = @messages.reverse_each.find { |message| message[:context_key] == key.to_s }
|
|
63
|
+
return self if content.nil? && previous.nil?
|
|
64
|
+
|
|
65
|
+
content ||= empty
|
|
66
|
+
return self if content.nil? || (previous && previous[:content] == content)
|
|
67
|
+
|
|
68
|
+
append(role: "user", content: content, system_injected: true, context_key: key.to_s)
|
|
69
|
+
end
|
|
70
|
+
|
|
58
71
|
# Replace (or insert at head) the system prompt message.
|
|
59
72
|
# Used by session_serializer#refresh_system_prompt.
|
|
60
73
|
def replace_system_prompt(content, **extra)
|
|
@@ -24,8 +24,9 @@ module Clacky
|
|
|
24
24
|
# Unlike Chat Completions, there is no "[DONE]" sentinel; the stream ends
|
|
25
25
|
# with a "response.completed" / "response.done" (or "response.incomplete") event.
|
|
26
26
|
class OpenAIResponsesStreamAggregator
|
|
27
|
-
def initialize(on_chunk: nil)
|
|
27
|
+
def initialize(on_chunk: nil, on_text_delta: nil)
|
|
28
28
|
@on_chunk = on_chunk
|
|
29
|
+
@on_text_delta = on_text_delta
|
|
29
30
|
@text = +""
|
|
30
31
|
@reasoning_text = +""
|
|
31
32
|
@function_calls = {} # call_id -> { name:, arguments: }
|
|
@@ -57,6 +58,7 @@ module Clacky
|
|
|
57
58
|
case event_type
|
|
58
59
|
when "response.output_text.delta"
|
|
59
60
|
@text << data["delta"].to_s
|
|
61
|
+
emit_text_delta(data["delta"])
|
|
60
62
|
emit_estimate_progress
|
|
61
63
|
# OpenAI's official API emits response.reasoning_text.delta; keep
|
|
62
64
|
# response.reasoning.delta as a tolerant alias for providers that
|
|
@@ -241,6 +243,14 @@ module Clacky
|
|
|
241
243
|
found
|
|
242
244
|
end
|
|
243
245
|
|
|
246
|
+
# Text previews must not change aggregation or abort a model response.
|
|
247
|
+
private def emit_text_delta(text)
|
|
248
|
+
return unless @on_text_delta && text.is_a?(String) && !text.empty?
|
|
249
|
+
@on_text_delta.call(text)
|
|
250
|
+
rescue StandardError => e
|
|
251
|
+
Clacky::Logger.warn("[stream] on_text_delta: #{e.class}: #{e.message}")
|
|
252
|
+
end
|
|
253
|
+
|
|
244
254
|
private def parse_or_nil(s)
|
|
245
255
|
# Some providers / proxies append a "[DONE]" sentinel (inherited from
|
|
246
256
|
# Chat Completions SSE) even for the Responses API. Silently ignore it
|
|
@@ -18,8 +18,9 @@ module Clacky
|
|
|
18
18
|
# {"id":"...","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":3,"prompt_tokens_details":{"cached_tokens":2}}}
|
|
19
19
|
# data: [DONE]
|
|
20
20
|
class OpenAIStreamAggregator
|
|
21
|
-
def initialize(on_chunk: nil)
|
|
21
|
+
def initialize(on_chunk: nil, on_text_delta: nil)
|
|
22
22
|
@on_chunk = on_chunk
|
|
23
|
+
@on_text_delta = on_text_delta
|
|
23
24
|
@content = +""
|
|
24
25
|
@reasoning_content = +""
|
|
25
26
|
@role = "assistant"
|
|
@@ -54,6 +55,7 @@ module Clacky
|
|
|
54
55
|
delta = choice["delta"] || {}
|
|
55
56
|
@role = delta["role"] if delta["role"]
|
|
56
57
|
@content << delta["content"] if delta["content"].is_a?(String)
|
|
58
|
+
emit_text_delta(delta["content"])
|
|
57
59
|
@reasoning_content << delta["reasoning_content"] if delta["reasoning_content"].is_a?(String)
|
|
58
60
|
if (tcs = delta["tool_calls"])
|
|
59
61
|
tcs.each { |tc| merge_tool_call(tc) }
|
|
@@ -109,6 +111,14 @@ module Clacky
|
|
|
109
111
|
slot[:extra_content] = tc["extra_content"] if tc["extra_content"]
|
|
110
112
|
end
|
|
111
113
|
|
|
114
|
+
# Text previews must not change aggregation or abort a model response.
|
|
115
|
+
private def emit_text_delta(text)
|
|
116
|
+
return unless @on_text_delta && text.is_a?(String) && !text.empty?
|
|
117
|
+
@on_text_delta.call(text)
|
|
118
|
+
rescue StandardError => e
|
|
119
|
+
Clacky::Logger.warn("[stream] on_text_delta: #{e.class}: #{e.message}")
|
|
120
|
+
end
|
|
121
|
+
|
|
112
122
|
private def parse_or_nil(s)
|
|
113
123
|
JSON.parse(s)
|
|
114
124
|
rescue JSON::ParserError => e
|
data/lib/clacky/prompts/base.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
- Ask clarifying questions if requirements are unclear.
|
|
4
4
|
- Break down complex tasks into manageable steps.
|
|
5
5
|
- **USE TOOLS to create/modify files** — don't just return content.
|
|
6
|
-
- When the user asks to send/download a file or you generate one for them, append
|
|
6
|
+
- When the user asks to send/download a file or you generate one for them, append exactly one link at the end of your reply: `` for images, video and audio (renders inline — a player for media), `[filename](file:///absolute/path/to/file)` for other files (clicking opens it in the file panel). Never write both forms for the same file, and never repeat the same file as both a markdown reference and an HTML `<img>`/`<video>`/`<audio>` tag — one reference per file. Use the exact absolute path the write tool returned — don't rewrite or abbreviate it with `~` (keep non-ASCII characters and spaces literal); never URL-encode it. Never emit `/workspace/projects/…`, `cch1:…`, base64-encoded or any other project-scoped path — those are hosted-platform references and do not resolve in a local install.
|
|
7
7
|
|
|
8
8
|
## Tool Usage Rules
|
|
9
9
|
|
data/lib/clacky/providers.rb
CHANGED
|
@@ -38,8 +38,7 @@ module Clacky
|
|
|
38
38
|
"auto",
|
|
39
39
|
"dsk-deepseek-v4.1-flash",
|
|
40
40
|
"dsk-deepseek-v4-pro",
|
|
41
|
-
"
|
|
42
|
-
"oc-kimi-k3",
|
|
41
|
+
"abs-claude-fable-5-2",
|
|
43
42
|
"abs-claude-fable-5-1",
|
|
44
43
|
"abs-claude-fable-5",
|
|
45
44
|
"abs-claude-opus-5-5",
|
|
@@ -60,7 +59,9 @@ module Clacky
|
|
|
60
59
|
"abs-gpt-5.6-luna",
|
|
61
60
|
"or-gemini-4-argon",
|
|
62
61
|
"or-gemini-3-1-pro",
|
|
63
|
-
"or-gemini-3-8-flash"
|
|
62
|
+
"or-gemini-3-8-flash",
|
|
63
|
+
"oc-glm-5.3",
|
|
64
|
+
"oc-kimi-k3"
|
|
64
65
|
],
|
|
65
66
|
# Image generation models served by the openclacky platform
|
|
66
67
|
# gateway. The gateway exposes a standard OpenAI-compatible
|
|
@@ -180,6 +181,7 @@ module Clacky
|
|
|
180
181
|
# no injection happens when the default model is already lite-class.
|
|
181
182
|
"lite_models" => {
|
|
182
183
|
"auto" => "dsk-deepseek-v4.1-flash",
|
|
184
|
+
"abs-claude-fable-5-2" => "abs-claude-haiku-5-5",
|
|
183
185
|
"abs-claude-fable-5-1" => "abs-claude-haiku-5-5",
|
|
184
186
|
"abs-claude-fable-5" => "abs-claude-haiku-5-5",
|
|
185
187
|
"abs-claude-opus-5-5" => "abs-claude-haiku-5-5",
|
|
@@ -199,6 +201,7 @@ module Clacky
|
|
|
199
201
|
# Fallback chain: if a model is unavailable, try the next one in order.
|
|
200
202
|
# Keys are primary model names; values are the fallback model to use instead.
|
|
201
203
|
"fallback_models" => {
|
|
204
|
+
"abs-claude-fable-5-2" => "abs-claude-fable-5-1",
|
|
202
205
|
"abs-claude-fable-5-1" => "abs-claude-fable-5",
|
|
203
206
|
"abs-claude-fable-5" => "abs-claude-opus-5",
|
|
204
207
|
"abs-claude-opus-5-5" => "abs-claude-opus-5",
|
|
@@ -453,6 +456,7 @@ module Clacky
|
|
|
453
456
|
"api" => "anthropic-messages",
|
|
454
457
|
"default_model" => "claude-sonnet-4-6",
|
|
455
458
|
"models" => [
|
|
459
|
+
"claude-fable-5-2",
|
|
456
460
|
"claude-fable-5-1",
|
|
457
461
|
"claude-fable-5",
|
|
458
462
|
"claude-opus-5",
|