openclacky 1.5.22 → 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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +104 -0
  3. data/docs/secretary-prototype.md +286 -0
  4. data/lib/clacky/agent/cost_tracker.rb +55 -36
  5. data/lib/clacky/agent/hook_manager.rb +4 -1
  6. data/lib/clacky/agent/llm_caller.rb +46 -12
  7. data/lib/clacky/agent/memory_injector.rb +209 -0
  8. data/lib/clacky/agent/memory_updater.rb +16 -0
  9. data/lib/clacky/agent/session_serializer.rb +15 -11
  10. data/lib/clacky/agent/skill_manager.rb +30 -8
  11. data/lib/clacky/agent.rb +124 -17
  12. data/lib/clacky/agent_config.rb +7 -3
  13. data/lib/clacky/agent_profile.rb +33 -6
  14. data/lib/clacky/anthropic_stream_aggregator.rb +11 -1
  15. data/lib/clacky/bedrock_stream_aggregator.rb +11 -1
  16. data/lib/clacky/billing/platform_billing.rb +7 -0
  17. data/lib/clacky/cli.rb +4 -3
  18. data/lib/clacky/client.rb +30 -25
  19. data/lib/clacky/default_extensions/advisor/README.md +25 -0
  20. data/lib/clacky/default_extensions/advisor/README.zh.md +25 -0
  21. data/lib/clacky/default_extensions/advisor/ext.yml +1 -1
  22. data/lib/clacky/default_extensions/advisor/icon.svg +14 -0
  23. data/lib/clacky/default_extensions/advisor/panels/advisor/view.js +7 -1
  24. data/lib/clacky/default_extensions/coding/ext.yml +0 -1
  25. data/lib/clacky/default_extensions/computer-use/README.md +48 -0
  26. data/lib/clacky/default_extensions/computer-use/README.zh.md +48 -0
  27. data/lib/clacky/default_extensions/computer-use/ext.yml +1 -1
  28. data/lib/clacky/default_extensions/computer-use/icon.svg +16 -0
  29. data/lib/clacky/default_extensions/ext-studio/ext.yml +0 -1
  30. data/lib/clacky/default_extensions/general/ext.yml +0 -1
  31. data/lib/clacky/default_extensions/git/README.md +41 -0
  32. data/lib/clacky/default_extensions/git/README.zh.md +41 -0
  33. data/lib/clacky/default_extensions/git/ext.yml +1 -1
  34. data/lib/clacky/default_extensions/git/icon.svg +15 -0
  35. data/lib/clacky/default_extensions/git/panels/git/view.js +106 -27
  36. data/lib/clacky/default_extensions/meeting/README.md +46 -0
  37. data/lib/clacky/default_extensions/meeting/README.zh.md +47 -0
  38. data/lib/clacky/default_extensions/meeting/ext.yml +1 -1
  39. data/lib/clacky/default_extensions/meeting/icon.svg +13 -0
  40. data/lib/clacky/default_extensions/preview/README.md +29 -0
  41. data/lib/clacky/default_extensions/preview/README.zh.md +29 -0
  42. data/lib/clacky/default_extensions/preview/ext.yml +1 -1
  43. data/lib/clacky/default_extensions/preview/icon.svg +13 -0
  44. data/lib/clacky/default_extensions/secretary/README.md +69 -0
  45. data/lib/clacky/default_extensions/secretary/README.zh.md +69 -0
  46. data/lib/clacky/default_extensions/secretary/agents/secretary.md +41 -0
  47. data/lib/clacky/default_extensions/secretary/agents/worker.md +35 -0
  48. data/lib/clacky/default_extensions/secretary/api/handler.rb +8 -0
  49. data/lib/clacky/default_extensions/secretary/ext.yml +42 -0
  50. data/lib/clacky/default_extensions/secretary/icon.svg +17 -0
  51. data/lib/clacky/default_extensions/secretary/panels/work/view.js +344 -0
  52. data/lib/clacky/default_extensions/secretary/tools/delegate_work.rb +37 -0
  53. data/lib/clacky/default_extensions/secretary/tools/manage_work.rb +22 -0
  54. data/lib/clacky/default_extensions/secretary/tools/yield_work.rb +35 -0
  55. data/lib/clacky/default_extensions/time_machine/README.md +32 -0
  56. data/lib/clacky/default_extensions/time_machine/README.zh.md +32 -0
  57. data/lib/clacky/default_extensions/time_machine/ext.yml +1 -1
  58. data/lib/clacky/default_extensions/time_machine/icon.svg +14 -0
  59. data/lib/clacky/default_skills/channel-manager/SKILL.md +103 -13
  60. data/lib/clacky/default_skills/channel-manager/dingtalk_setup.rb +4 -2
  61. data/lib/clacky/default_skills/channel-manager/discord_setup.rb +9 -2
  62. data/lib/clacky/default_skills/channel-manager/weixin_setup.rb +10 -1
  63. data/lib/clacky/default_skills/cron-task-creator/SKILL.md +183 -206
  64. data/lib/clacky/default_skills/cron-task-creator/evals/evals.json +45 -0
  65. data/lib/clacky/default_skills/media-gen/SKILL.md +31 -14
  66. data/lib/clacky/default_skills/onboard/SKILL.md +5 -7
  67. data/lib/clacky/default_skills/persist-memory/SKILL.md +15 -1
  68. data/lib/clacky/extension/api_extension.rb +23 -2
  69. data/lib/clacky/extension/loader.rb +2 -0
  70. data/lib/clacky/extension/verifier.rb +2 -2
  71. data/lib/clacky/json_ui_controller.rb +14 -1
  72. data/lib/clacky/locales/en.rb +14 -0
  73. data/lib/clacky/locales/i18n.rb +25 -3
  74. data/lib/clacky/locales/zh.rb +14 -0
  75. data/lib/clacky/message_history.rb +15 -2
  76. data/lib/clacky/openai_responses_stream_aggregator.rb +11 -1
  77. data/lib/clacky/openai_stream_aggregator.rb +11 -1
  78. data/lib/clacky/prompts/base.md +1 -1
  79. data/lib/clacky/providers.rb +32 -17
  80. data/lib/clacky/server/backup_manager.rb +98 -2
  81. data/lib/clacky/server/browser_manager.rb +10 -5
  82. data/lib/clacky/server/channel/adapters/base.rb +18 -0
  83. data/lib/clacky/server/channel/adapters/feishu/message_parser.rb +1 -0
  84. data/lib/clacky/server/channel/adapters/telegram/adapter.rb +1 -0
  85. data/lib/clacky/server/channel/channel_config.rb +185 -48
  86. data/lib/clacky/server/channel/channel_manager.rb +247 -110
  87. data/lib/clacky/server/git_panel.rb +2 -1
  88. data/lib/clacky/server/http_server.rb +517 -175
  89. data/lib/clacky/server/preview.rb +26 -5
  90. data/lib/clacky/server/scheduler.rb +166 -85
  91. data/lib/clacky/server/web_ui_controller.rb +12 -0
  92. data/lib/clacky/session_manager.rb +4 -1
  93. data/lib/clacky/skill.rb +1 -1
  94. data/lib/clacky/tools/base.rb +7 -1
  95. data/lib/clacky/ui_interface.rb +5 -0
  96. data/lib/clacky/utils/file_processor.rb +23 -11
  97. data/lib/clacky/utils/model_pricing.rb +19 -0
  98. data/lib/clacky/version.rb +1 -1
  99. data/lib/clacky/web/app.css +621 -52
  100. data/lib/clacky/web/app.js +103 -9
  101. data/lib/clacky/web/components/code-editor.js +73 -4
  102. data/lib/clacky/web/components/custom-select.js +7 -18
  103. data/lib/clacky/web/components/hint-tip.js +172 -0
  104. data/lib/clacky/web/components/model-picker.js +1 -1
  105. data/lib/clacky/web/components/notify.js +37 -10
  106. data/lib/clacky/web/components/onboard.js +1 -1
  107. data/lib/clacky/web/components/sidebar.js +70 -0
  108. data/lib/clacky/web/features/backup/store.js +64 -27
  109. data/lib/clacky/web/features/backup/view.js +42 -11
  110. data/lib/clacky/web/features/channels/store.js +19 -4
  111. data/lib/clacky/web/features/channels/view.js +94 -33
  112. data/lib/clacky/web/features/extensions/view.js +15 -8
  113. data/lib/clacky/web/features/new-session/view.js +33 -22
  114. data/lib/clacky/web/features/profile/view.js +4 -4
  115. data/lib/clacky/web/features/tasks/store.js +5 -3
  116. data/lib/clacky/web/features/tasks/view.js +99 -26
  117. data/lib/clacky/web/features/trash/view.js +4 -4
  118. data/lib/clacky/web/features/workspace/view.js +193 -57
  119. data/lib/clacky/web/i18n.js +189 -17
  120. data/lib/clacky/web/index.html +165 -53
  121. data/lib/clacky/web/projects.js +15 -2
  122. data/lib/clacky/web/sessions.js +316 -86
  123. data/lib/clacky/web/settings.js +304 -75
  124. data/lib/clacky/web/utils.js +261 -0
  125. data/lib/clacky/web/ws-dispatcher.js +24 -3
  126. data/lib/clacky/web/ws.js +16 -4
  127. data/lib/clacky/work/service.rb +544 -0
  128. data/lib/clacky/work/store.rb +57 -0
  129. data/lib/clacky.rb +1 -0
  130. metadata +35 -1
@@ -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
@@ -250,6 +263,10 @@ module Clacky
250
263
  self.class.meta["config"] || {}
251
264
  end
252
265
 
266
+ def work_service
267
+ @http_server&.work_service
268
+ end
269
+
253
270
  def session_manager
254
271
  @http_server&.instance_variable_get(:@session_manager)
255
272
  end
@@ -329,11 +346,13 @@ module Clacky
329
346
  end
330
347
 
331
348
  # Submit a prompt to an existing session for execution.
349
+ # prompt is model input; display_message overrides its visible text; reference_contexts
350
+ # supply both UI badges and model reference context.
332
351
  # Returns the session_id on success.
333
352
  # Raises Halt (409) if the session is already running and `interrupt: false`.
334
353
  # When `interrupt: true`, supersedes the current turn (raises AgentInterrupted
335
354
  # on the running thread, waits up to 2s for it to exit) then runs the new task.
336
- def submit_task(session_id, prompt, display_message: nil, interrupt: false)
355
+ def submit_task(session_id, prompt, display_message: nil, interrupt: false, reference_contexts: nil)
337
356
  reg = registry
338
357
  error!("server not ready", status: 503) unless reg
339
358
 
@@ -351,7 +370,9 @@ module Clacky
351
370
  old_thread&.join(2)
352
371
  end
353
372
 
354
- @http_server.send(:run_session_task, session_id, prompt, display_message: display_message)
373
+ options = { display_message: display_message }
374
+ options[:reference_contexts] = reference_contexts if reference_contexts
375
+ @http_server.send(:run_session_task, session_id, prompt, **options)
355
376
  session_id
356
377
  end
357
378
 
@@ -502,6 +502,8 @@ module Clacky
502
502
  "title_zh" => spec["title_zh"].to_s,
503
503
  "prompt" => spec["prompt"],
504
504
  "prompt_abs" => prompt_abs,
505
+ "base_agent" => spec["base_agent"],
506
+ "work_agent" => spec["work_agent"],
505
507
  "avatar" => avatar_rel,
506
508
  "avatar_abs" => avatar_abs,
507
509
  "description" => spec["description"].to_s,
@@ -16,13 +16,13 @@ module Clacky
16
16
  module ExtensionVerifier
17
17
  Issue = Struct.new(:ext, :unit, :level, :code, :message, :file, :hint, keyword_init: true)
18
18
 
19
- KNOWN_TOP_KEYS = %w[id name name_zh display_name display_name_zh title description description_zh emoji version origin author homepage license public license_required keywords enabled_by_default config contributes].freeze
19
+ KNOWN_TOP_KEYS = %w[id name name_zh display_name display_name_zh title description description_zh emoji icon version origin author homepage license public license_required keywords enabled_by_default config contributes].freeze
20
20
  KNOWN_CONTRIBUTES = %w[panels api skills agents channels patches hooks tools].freeze
21
21
 
22
22
  PANEL_KEYS = %w[id title title_zh description description_zh view order attach entry_points].freeze
23
23
  API_KEYS = %w[id handler].freeze
24
24
  SKILL_KEYS = %w[id dir protected].freeze
25
- AGENT_KEYS = %w[id title title_zh description description_zh order prompt panels skills disabled_skills avatar hidden tools].freeze
25
+ AGENT_KEYS = %w[id base_agent work_agent title title_zh description description_zh order prompt panels skills disabled_skills avatar hidden tools].freeze
26
26
  CHANNEL_KEYS = %w[id platform adapter].freeze
27
27
  PATCH_KEYS = %w[target file fingerprint on_mismatch].freeze
28
28
  HOOK_KEYS = %w[event file].freeze
@@ -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
 
@@ -3,6 +3,20 @@
3
3
  module Clacky
4
4
  module Locales
5
5
  EN = {
6
+ "work.delegating" => "Delegate: %<title>s",
7
+ "work.delegated" => "Created work item “%<title>s”, waiting to start. Follow its progress in the Work panel.",
8
+ "work.queued" => "Waiting to start",
9
+ "work.cancelled" => "Cancelled by you",
10
+ "work.paused" => "Paused; add instructions to continue",
11
+ "work.interrupted" => "Interrupted by a server restart. Review progress and add instructions to continue.",
12
+ "work.running" => "In progress",
13
+ "work.started" => "Starting: %<title>s",
14
+ "work.missing_result" => "Execution ended without a yield_work result. Review the execution history.",
15
+ "work.completed" => "Work completed: %<title>s",
16
+ "work.needs_user" => "Your decision needed: %<title>s",
17
+ "work.failed" => "Work needs attention: %<title>s",
18
+ "work.reply_received" => "Reply received; waiting to resume",
19
+
6
20
  "phase.skill_evolution" => "Reflecting on this task",
7
21
  "phase.memory_update" => "Updating long-term memory",
8
22
  "llm.error.insufficient_credit" => "Insufficient credit, please top up your account to continue",
@@ -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
- return Thread.current[:lang] if Thread.current[:lang]
50
+ normalize(Thread.current[:lang]) || env_locale
51
+ end
35
52
 
36
- lang = ENV["LC_ALL"] || ENV["LC_MESSAGES"] || ENV["LANG"] || ""
37
- lang.match?(/\Azh/i) ? "zh" : "en"
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
@@ -3,6 +3,20 @@
3
3
  module Clacky
4
4
  module Locales
5
5
  ZH = {
6
+ "work.delegating" => "委派:%<title>s",
7
+ "work.delegated" => "已创建工作事项「%<title>s」,等待执行。可在工作事项面板跟进。",
8
+ "work.queued" => "等待执行",
9
+ "work.cancelled" => "用户已取消",
10
+ "work.paused" => "用户已暂停,补充要求后可继续",
11
+ "work.interrupted" => "执行因服务重启中断,请核实进展后补充要求以继续。",
12
+ "work.running" => "执行中",
13
+ "work.started" => "开始处理:%<title>s",
14
+ "work.missing_result" => "执行结束但没有调用 yield_work 交回结果,请检查执行记录。",
15
+ "work.completed" => "工作已完成:%<title>s",
16
+ "work.needs_user" => "需要你确认:%<title>s",
17
+ "work.failed" => "工作需要处理:%<title>s",
18
+ "work.reply_received" => "收到回复,等待继续执行",
19
+
6
20
  "phase.skill_evolution" => "正在复盘本次任务",
7
21
  "phase.memory_update" => "正在更新长期记忆",
8
22
  "llm.error.insufficient_credit" => "API Key 账户余额不足,请前往控制台充值后继续使用",
@@ -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
@@ -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 `[filename](file:///absolute/path/to/file)` at the end of your reply. 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.
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: `![filename](file:///absolute/path/to/file)` 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
 
@@ -38,8 +38,7 @@ module Clacky
38
38
  "auto",
39
39
  "dsk-deepseek-v4.1-flash",
40
40
  "dsk-deepseek-v4-pro",
41
- "oc-glm-5.3",
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
@@ -69,32 +70,43 @@ module Clacky
69
70
  # only — the platform may dispatch to OpenRouter or Vertex AI
70
71
  # (Gemini Nano Banana family) depending on the model.
71
72
  "image_models" => [
73
+ "or-gemini-nano-banana-2-1",
72
74
  "or-gemini-3-pro-image",
73
75
  "or-gemini-3-1-flash-image",
76
+ "or-gemini-3-1-flash-lite-image",
77
+ "or-gpt-image-2-5",
78
+ "or-gpt-image-2-5-flare",
74
79
  "or-gpt-image-2"
75
80
  ],
76
81
  "image_model_aliases" => {
77
- "or-gemini-3-pro-image" => "Nano Banana Pro",
78
- "or-gemini-3-1-flash-image" => "Nano Banana 2",
79
- "or-gpt-image-2" => "GPT Image 2"
82
+ "or-gemini-nano-banana-2-1" => "Nano Banana 2.1",
83
+ "or-gemini-3-pro-image" => "Nano Banana Pro",
84
+ "or-gemini-3-1-flash-image" => "Nano Banana 2",
85
+ "or-gemini-3-1-flash-lite-image" => "Nano Banana 2 Lite",
86
+ "or-gpt-image-2-5" => "GPT Image 2.5",
87
+ "or-gpt-image-2-5-flare" => "GPT Image 2.5 Flare",
88
+ "or-gpt-image-2" => "GPT Image 2"
80
89
  },
81
- "default_image_model" => "or-gemini-3-1-flash-image",
82
- # Video generation models served by the openclacky gateway, which
83
- # routes them to Vertex AI Veo (async predictLongRunning under the
84
- # hood; the gateway hides the polling and returns the MP4 inline).
90
+ "default_image_model" => "or-gemini-nano-banana-2-1",
91
+ # Video generation models served by the openclacky gateway. Gemini
92
+ # Omni Flash rides Vertex's Interactions API (token-billed, 3–15s);
93
+ # the Veo 3.1 family uses async predictLongRunning (per-second, 4–8s).
94
+ # The gateway hides the polling and returns the MP4 inline for both.
95
+ # Veo 3 / Veo 3 Fast are still routable server-side for old configs
96
+ # but no longer offered: same price as 3.1 with older quality.
85
97
  "video_models" => [
98
+ "or-gemini-omni-flash",
86
99
  "or-veo-3-1",
87
100
  "or-veo-3-1-fast",
88
- "or-veo-3",
89
- "or-veo-3-fast"
101
+ "or-veo-3-1-lite"
90
102
  ],
91
103
  "video_model_aliases" => {
92
- "or-veo-3-1" => "Veo 3.1",
93
- "or-veo-3-1-fast" => "Veo 3.1 Fast",
94
- "or-veo-3" => "Veo 3",
95
- "or-veo-3-fast" => "Veo 3 Fast"
104
+ "or-gemini-omni-flash" => "Gemini Omni Flash",
105
+ "or-veo-3-1" => "Veo 3.1",
106
+ "or-veo-3-1-fast" => "Veo 3.1 Fast",
107
+ "or-veo-3-1-lite" => "Veo 3.1 Lite"
96
108
  },
97
- "default_video_model" => "or-veo-3-1",
109
+ "default_video_model" => "or-gemini-omni-flash",
98
110
  # Text-to-speech models served by the openclacky gateway, which
99
111
  # routes them to Vertex AI Gemini 2.5 (responseModalities=["AUDIO"]).
100
112
  # The gateway returns WAV inline as base64.
@@ -169,6 +181,7 @@ module Clacky
169
181
  # no injection happens when the default model is already lite-class.
170
182
  "lite_models" => {
171
183
  "auto" => "dsk-deepseek-v4.1-flash",
184
+ "abs-claude-fable-5-2" => "abs-claude-haiku-5-5",
172
185
  "abs-claude-fable-5-1" => "abs-claude-haiku-5-5",
173
186
  "abs-claude-fable-5" => "abs-claude-haiku-5-5",
174
187
  "abs-claude-opus-5-5" => "abs-claude-haiku-5-5",
@@ -188,6 +201,7 @@ module Clacky
188
201
  # Fallback chain: if a model is unavailable, try the next one in order.
189
202
  # Keys are primary model names; values are the fallback model to use instead.
190
203
  "fallback_models" => {
204
+ "abs-claude-fable-5-2" => "abs-claude-fable-5-1",
191
205
  "abs-claude-fable-5-1" => "abs-claude-fable-5",
192
206
  "abs-claude-fable-5" => "abs-claude-opus-5",
193
207
  "abs-claude-opus-5-5" => "abs-claude-opus-5",
@@ -442,6 +456,7 @@ module Clacky
442
456
  "api" => "anthropic-messages",
443
457
  "default_model" => "claude-sonnet-4-6",
444
458
  "models" => [
459
+ "claude-fable-5-2",
445
460
  "claude-fable-5-1",
446
461
  "claude-fable-5",
447
462
  "claude-opus-5",
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fileutils"
4
+ require "find"
5
+ require "open3"
4
6
  require "tmpdir"
5
7
  require "yaml"
6
8
  require "time"
9
+ require "zlib"
7
10
 
8
11
  module Clacky
9
12
  module Server
@@ -21,6 +24,35 @@ module Clacky
21
24
  CLACKY_DIR = File.expand_path("~/.clacky")
22
25
  CONFIG_FILE = File.join(CLACKY_DIR, "backup.yml")
23
26
 
27
+ # Minimal gzip writer over the raw deflate stream.
28
+ #
29
+ # Two reasons not to use Zlib::GzipWriter: it raises Zlib::BufError once
30
+ # a stream reaches a few MB, and Z_NO_FLUSH intermittently reports "no
31
+ # progress" (also surfaced as BufError). Flushing every chunk costs ~0.3%
32
+ # in size on real backups and keeps the stream well-behaved.
33
+ module GzipStream
34
+ HEADER = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03".b
35
+
36
+ def self.write(io)
37
+ io.write(HEADER)
38
+ deflate = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, -Zlib::MAX_WBITS)
39
+ crc = 0
40
+ size = 0
41
+
42
+ yield lambda { |chunk|
43
+ io.write(deflate.deflate(chunk, Zlib::SYNC_FLUSH))
44
+ crc = Zlib.crc32(chunk, crc)
45
+ size += chunk.bytesize
46
+ }
47
+
48
+ io.write(deflate.finish)
49
+ io.write([crc, size & 0xffffffff].pack("V2"))
50
+ ensure
51
+ deflate.close if deflate && !deflate.closed?
52
+ end
53
+ end
54
+ private_constant :GzipStream
55
+
24
56
  # Always excluded — regenerable or disposable.
25
57
  ALWAYS_EXCLUDE = %w[
26
58
  ocr_cache parsers parsers-1 logger safety_logs trash .DS_Store backup.yml
@@ -161,10 +193,74 @@ module Clacky
161
193
  end
162
194
 
163
195
  private def build_archive(archive, excludes)
164
- args = ["tar", "-czf", archive, "-C", CLACKY_DIR]
196
+ total = source_bytes(excludes)
197
+ done = 0
198
+ report_progress(done, total)
199
+ last_report = Time.now
200
+
201
+ args = ["tar", "-c", "-C", CLACKY_DIR]
165
202
  excludes.each { |e| args << "--exclude=./#{e}" }
166
203
  args << "."
167
- system(*args)
204
+
205
+ ok = false
206
+ File.open(archive, "wb") do |out|
207
+ GzipStream.write(out) do |sink|
208
+ Open3.popen2(*args) do |stdin, stdout, wait|
209
+ stdin.close
210
+ stdout.binmode
211
+ while (chunk = stdout.read(64 * 1024))
212
+ sink.call(chunk)
213
+ done += chunk.bytesize
214
+ # Throttled: one update per 100ms is plenty for a 500ms
215
+ # poll and keeps the mutex out of the copy loop.
216
+ if Time.now - last_report >= 0.1
217
+ report_progress(done, total)
218
+ last_report = Time.now
219
+ end
220
+ end
221
+ ok = wait.value.success?
222
+ end
223
+ end
224
+ end
225
+ ok
226
+ ensure
227
+ report_progress(nil, nil)
228
+ end
229
+
230
+ # Source bytes the archive will read, so the UI can show a real
231
+ # percentage instead of a spinner. `tar` itself reports nothing.
232
+ private def source_bytes(excludes)
233
+ total = 0
234
+ Find.find(CLACKY_DIR) do |path|
235
+ next if path == CLACKY_DIR
236
+
237
+ rel = path[(CLACKY_DIR.length + 1)..-1]
238
+ if excludes.include?(rel.to_s.split("/", 2).first)
239
+ Find.prune if File.lstat(path).directory?
240
+ next
241
+ end
242
+
243
+ stat = File.lstat(path)
244
+ total += stat.size if stat.file?
245
+ rescue SystemCallError
246
+ next
247
+ end
248
+ total
249
+ end
250
+
251
+ # { done:, total: } while packing, nil otherwise. Polled by the UI.
252
+ def progress
253
+ progress_mutex.synchronize { @progress && @progress.dup }
254
+ end
255
+
256
+ private def report_progress(done, total)
257
+ progress_mutex.synchronize do
258
+ @progress = done.nil? ? nil : { done: done, total: total }
259
+ end
260
+ end
261
+
262
+ private def progress_mutex
263
+ @progress_mutex ||= Mutex.new
168
264
  end
169
265
 
170
266
  private def prune(dest, keep)
@@ -111,12 +111,17 @@ module Clacky
111
111
 
112
112
  # Returns a status hash with real daemon liveness.
113
113
  # Uses wait_thr.alive? for a lightweight check — no ping, no mutex needed.
114
- # @return [Hash] { enabled: bool, daemon_running: bool, chrome_version: String|nil }
114
+ # `configured` tells "browser.yml was never written" apart from "set up but
115
+ # switched off"; `enabled` alone cannot, because it is just false in both.
116
+ # @return [Hash] { configured: bool, enabled: bool, daemon_running: bool,
117
+ # chrome_version: String|nil }
115
118
  def status
116
- cfg = load_config
117
- enabled = cfg["enabled"] == true
119
+ cfg = load_config
120
+ configured = File.exist?(BROWSER_CONFIG_PATH)
121
+ enabled = cfg["enabled"] == true
118
122
  running = @process && @process[:wait_thr]&.alive?
119
123
  {
124
+ configured: configured,
120
125
  enabled: enabled,
121
126
  daemon_running: !!running,
122
127
  chrome_version: cfg["chrome_version"],
@@ -146,7 +151,7 @@ module Clacky
146
151
  # @param max_base64_bytes [Integer, nil] screenshot size ceiling in bytes
147
152
  # @return [Hash] the effective settings after the update
148
153
  def update_screenshot_settings(max_base64_bytes: nil)
149
- raise "Browser not configured. Run /browser-setup first." unless File.exist?(BROWSER_CONFIG_PATH)
154
+ raise Clacky::BrowserNotConfiguredError, "Browser not configured. Run /browser-setup first." unless File.exist?(BROWSER_CONFIG_PATH)
150
155
 
151
156
  if !max_base64_bytes.nil? && !(max_base64_bytes.is_a?(Integer) && max_base64_bytes.positive?)
152
157
  raise ArgumentError, "screenshot_max_base64_bytes must be a positive integer"
@@ -164,7 +169,7 @@ module Clacky
164
169
  # Raises if browser.yml doesn't exist (not yet set up).
165
170
  # @return [Boolean] new enabled state
166
171
  def toggle
167
- raise "Browser not configured. Run /browser-setup first." unless File.exist?(BROWSER_CONFIG_PATH)
172
+ raise Clacky::BrowserNotConfiguredError, "Browser not configured. Run /browser-setup first." unless File.exist?(BROWSER_CONFIG_PATH)
168
173
 
169
174
  cfg = load_config
170
175
  new_enabled = !(cfg["enabled"] == true)
@@ -26,6 +26,24 @@ module Clacky
26
26
  # Base adapter interface for IM platforms.
27
27
  # Subclasses must implement every abstract method below.
28
28
  class Base
29
+ DEFAULT_INSTANCE_ID = "default"
30
+
31
+ attr_writer :instance_id, :instance_name
32
+
33
+ # Identifier of the configured instance this adapter serves. The first
34
+ # instance of a platform keeps the historical id "default".
35
+ # @return [String]
36
+ def instance_id
37
+ id = @instance_id.to_s
38
+ id.empty? ? DEFAULT_INSTANCE_ID : id
39
+ end
40
+
41
+ # Human-readable name of this instance (e.g. "Company Feishu").
42
+ # @return [String]
43
+ def instance_name
44
+ @instance_name.to_s
45
+ end
46
+
29
47
  # @return [Symbol] e.g. :feishu, :wecom
30
48
  def self.platform_id
31
49
  raise NotImplementedError, "#{self} must implement .platform_id"
@@ -112,6 +112,7 @@ module Clacky
112
112
  file_attachments: file_attachments,
113
113
  doc_urls: extract_doc_urls(text),
114
114
  message_id: message_id,
115
+ reply_to: message["parent_id"],
115
116
  timestamp: timestamp,
116
117
  chat_type: chat_type,
117
118
  mentioned_open_ids: Array(message["mentions"]).filter_map { |m| m.dig("id", "open_id") },
@@ -276,6 +276,7 @@ module Clacky
276
276
  text: text.strip,
277
277
  files: files,
278
278
  message_id: msg["message_id"].to_s,
279
+ reply_to: msg.dig("reply_to_message", "message_id")&.to_s,
279
280
  timestamp: msg["date"] ? Time.at(msg["date"]) : Time.now,
280
281
  chat_type: is_group ? :group : :direct,
281
282
  raw: msg