openclacky 1.5.21 → 1.5.23

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +119 -0
  3. data/docs/secretary-prototype.md +286 -0
  4. data/lib/clacky/agent/session_serializer.rb +15 -11
  5. data/lib/clacky/agent.rb +58 -15
  6. data/lib/clacky/agent_config.rb +3 -1
  7. data/lib/clacky/agent_profile.rb +33 -6
  8. data/lib/clacky/billing/platform_billing.rb +9 -0
  9. data/lib/clacky/default_extensions/advisor/README.md +25 -0
  10. data/lib/clacky/default_extensions/advisor/README.zh.md +25 -0
  11. data/lib/clacky/default_extensions/advisor/ext.yml +1 -1
  12. data/lib/clacky/default_extensions/advisor/icon.svg +14 -0
  13. data/lib/clacky/default_extensions/coding/ext.yml +0 -1
  14. data/lib/clacky/default_extensions/computer-use/README.md +48 -0
  15. data/lib/clacky/default_extensions/computer-use/README.zh.md +48 -0
  16. data/lib/clacky/default_extensions/computer-use/ext.yml +1 -1
  17. data/lib/clacky/default_extensions/computer-use/icon.svg +16 -0
  18. data/lib/clacky/default_extensions/ext-studio/ext.yml +0 -1
  19. data/lib/clacky/default_extensions/general/ext.yml +0 -1
  20. data/lib/clacky/default_extensions/git/README.md +41 -0
  21. data/lib/clacky/default_extensions/git/README.zh.md +41 -0
  22. data/lib/clacky/default_extensions/git/ext.yml +1 -1
  23. data/lib/clacky/default_extensions/git/icon.svg +15 -0
  24. data/lib/clacky/default_extensions/git/panels/git/view.js +1960 -399
  25. data/lib/clacky/default_extensions/meeting/README.md +46 -0
  26. data/lib/clacky/default_extensions/meeting/README.zh.md +47 -0
  27. data/lib/clacky/default_extensions/meeting/ext.yml +1 -1
  28. data/lib/clacky/default_extensions/meeting/icon.svg +13 -0
  29. data/lib/clacky/default_extensions/preview/README.md +29 -0
  30. data/lib/clacky/default_extensions/preview/README.zh.md +29 -0
  31. data/lib/clacky/default_extensions/preview/ext.yml +1 -1
  32. data/lib/clacky/default_extensions/preview/icon.svg +13 -0
  33. data/lib/clacky/default_extensions/preview/panels/preview/view.js +199 -34
  34. data/lib/clacky/default_extensions/secretary/agents/secretary.md +41 -0
  35. data/lib/clacky/default_extensions/secretary/agents/worker.md +35 -0
  36. data/lib/clacky/default_extensions/secretary/api/handler.rb +8 -0
  37. data/lib/clacky/default_extensions/secretary/ext.yml +39 -0
  38. data/lib/clacky/default_extensions/secretary/panels/work/view.js +344 -0
  39. data/lib/clacky/default_extensions/secretary/tools/delegate_work.rb +37 -0
  40. data/lib/clacky/default_extensions/secretary/tools/manage_work.rb +22 -0
  41. data/lib/clacky/default_extensions/secretary/tools/yield_work.rb +35 -0
  42. data/lib/clacky/default_extensions/time_machine/README.md +32 -0
  43. data/lib/clacky/default_extensions/time_machine/README.zh.md +32 -0
  44. data/lib/clacky/default_extensions/time_machine/ext.yml +1 -1
  45. data/lib/clacky/default_extensions/time_machine/icon.svg +14 -0
  46. data/lib/clacky/default_skills/channel-manager/SKILL.md +79 -8
  47. data/lib/clacky/default_skills/channel-manager/discord_setup.rb +5 -1
  48. data/lib/clacky/default_skills/channel-manager/weixin_setup.rb +8 -1
  49. data/lib/clacky/default_skills/cron-task-creator/SKILL.md +183 -206
  50. data/lib/clacky/default_skills/cron-task-creator/evals/evals.json +45 -0
  51. data/lib/clacky/default_skills/media-gen/SKILL.md +17 -8
  52. data/lib/clacky/extension/api_extension.rb +10 -2
  53. data/lib/clacky/extension/loader.rb +2 -0
  54. data/lib/clacky/extension/verifier.rb +2 -2
  55. data/lib/clacky/locales/en.rb +14 -0
  56. data/lib/clacky/locales/zh.rb +14 -0
  57. data/lib/clacky/prompts/base.md +1 -1
  58. data/lib/clacky/providers.rb +68 -31
  59. data/lib/clacky/search_config.rb +33 -11
  60. data/lib/clacky/server/channel/adapters/base.rb +18 -0
  61. data/lib/clacky/server/channel/adapters/feishu/message_parser.rb +1 -0
  62. data/lib/clacky/server/channel/adapters/telegram/adapter.rb +1 -0
  63. data/lib/clacky/server/channel/channel_config.rb +185 -48
  64. data/lib/clacky/server/channel/channel_manager.rb +179 -66
  65. data/lib/clacky/server/git_panel.rb +362 -35
  66. data/lib/clacky/server/http_server.rb +530 -181
  67. data/lib/clacky/server/preview.rb +118 -17
  68. data/lib/clacky/server/scheduler.rb +211 -51
  69. data/lib/clacky/server/web_ui_controller.rb +35 -27
  70. data/lib/clacky/session_manager.rb +56 -6
  71. data/lib/clacky/tools/base.rb +7 -1
  72. data/lib/clacky/utils/file_processor.rb +20 -10
  73. data/lib/clacky/utils/mac_app_detector.rb +8 -7
  74. data/lib/clacky/utils/model_pricing.rb +60 -2
  75. data/lib/clacky/utils/windows_app_detector.rb +3 -1
  76. data/lib/clacky/version.rb +1 -1
  77. data/lib/clacky/web/app.css +1114 -205
  78. data/lib/clacky/web/app.js +143 -8
  79. data/lib/clacky/web/auth.js +1 -1
  80. data/lib/clacky/web/components/code-editor.js +73 -4
  81. data/lib/clacky/web/components/composer.js +107 -8
  82. data/lib/clacky/web/components/image-zoom.js +165 -0
  83. data/lib/clacky/web/components/model-picker.js +7 -5
  84. data/lib/clacky/web/components/notify.js +39 -12
  85. data/lib/clacky/web/components/onboard.js +1 -1
  86. data/lib/clacky/web/core/aside.js +60 -3
  87. data/lib/clacky/web/features/billing/view.js +2 -2
  88. data/lib/clacky/web/features/channels/store.js +19 -4
  89. data/lib/clacky/web/features/channels/view.js +92 -28
  90. data/lib/clacky/web/features/extensions/view.js +17 -10
  91. data/lib/clacky/web/features/new-session/store.js +79 -2
  92. data/lib/clacky/web/features/new-session/view.js +516 -75
  93. data/lib/clacky/web/features/skills/store.js +1 -1
  94. data/lib/clacky/web/features/tasks/store.js +5 -3
  95. data/lib/clacky/web/features/tasks/view.js +249 -66
  96. data/lib/clacky/web/features/workspace/store.js +13 -6
  97. data/lib/clacky/web/features/workspace/view.js +340 -214
  98. data/lib/clacky/web/i18n.js +366 -68
  99. data/lib/clacky/web/index.html +196 -165
  100. data/lib/clacky/web/projects.js +37 -4
  101. data/lib/clacky/web/sessions.js +263 -146
  102. data/lib/clacky/web/settings.js +241 -53
  103. data/lib/clacky/web/skills.js +2 -2
  104. data/lib/clacky/web/theme.js +17 -2
  105. data/lib/clacky/web/utils.js +234 -2
  106. data/lib/clacky/web/weixin-qr.html +2 -1
  107. data/lib/clacky/web/ws-dispatcher.js +14 -31
  108. data/lib/clacky/work/service.rb +542 -0
  109. data/lib/clacky/work/store.rb +57 -0
  110. metadata +31 -1
@@ -0,0 +1,39 @@
1
+ id: secretary
2
+ name: Secretary
3
+ display_name: Secretary
4
+ display_name_zh: 生活秘书
5
+ description: Delegate work, track progress and resume after replies
6
+ version: "0.1.0"
7
+ author: OpenClacky
8
+ contributes:
9
+ api: api/handler.rb
10
+ agents:
11
+ - id: secretary
12
+ title: Secretary
13
+ title_zh: 生活秘书
14
+ description: Your main conversation, with background work and follow-up
15
+ description_zh: 与你交流,委派后台工作,跟进结果与待办
16
+ order: 2
17
+ prompt: agents/secretary.md
18
+ work_agent: secretary-worker
19
+ tools: [delegate_work, manage_work]
20
+ panels: [work]
21
+ - id: secretary-worker
22
+ title: Secretary Worker
23
+ title_zh: 秘书工作助手
24
+ description: Delegated worker with durable handoff
25
+ hidden: true
26
+ prompt: agents/worker.md
27
+ tools: [yield_work]
28
+ tools:
29
+ - id: delegate_work
30
+ file: tools/delegate_work.rb
31
+ - id: manage_work
32
+ file: tools/manage_work.rb
33
+ - id: yield_work
34
+ file: tools/yield_work.rb
35
+ panels:
36
+ - id: work
37
+ title: Work
38
+ title_zh: 工作事项
39
+ view: panels/work/view.js
@@ -0,0 +1,344 @@
1
+ (function () {
2
+ // Extension-owned dictionary, following the advisor panel convention.
3
+ const DICT = {
4
+ "en": {
5
+ "created": "Created: ",
6
+ "paused": "Paused",
7
+ "queued": "Waiting to start",
8
+ "running": "Your secretary is working on this",
9
+ "waiting_event": "Waiting for an event or checkpoint",
10
+ "needs_input": "Needs input from your secretary",
11
+ "completed": "Completed",
12
+ "failed": "Something needs attention; review with your secretary",
13
+ "cancelled": "Cancelled",
14
+ "error": "Progress is temporarily unavailable",
15
+ "draft": "About “{title}”, I would like to add:",
16
+ "activeCount": "Working in background: {count}",
17
+ "waitingCount": "Waiting for events: {count}",
18
+ "needsCount": "Needs input: {count}",
19
+ "pausedCount": "Paused: {count}",
20
+ "done": "Work is up to date",
21
+ "empty": "Nothing to follow up on yet. Tell your secretary what you need.",
22
+ "needsSection": "Your decisions",
23
+ "failedSection": "Needs attention",
24
+ "runningSection": "In progress",
25
+ "waitingSection": "Waiting",
26
+ "pausedSection": "Paused",
27
+ "completedSection": "Recently completed",
28
+ "cancelledSection": "Cancelled",
29
+ "moreCompleted": "Earlier completed work ({count})",
30
+ "requirements": "Details",
31
+ "constraints": "Constraints: ",
32
+ "check": "Check again: ",
33
+ "confirm": "Reply",
34
+ "review": "Discuss",
35
+ "discuss": "Discuss with secretary",
36
+ "history": "Open execution history",
37
+ "technical": "Execution details",
38
+ "plans": "Recurring plans",
39
+ "nextRun": "Next run: ",
40
+ "scheduled": "Scheduled",
41
+ "daily": "Daily at {time}",
42
+ "weekdays": "Weekdays at {time}",
43
+ "planDraft": "I would like to change the plan “{title}”: ",
44
+ "title": "Work"
45
+ },
46
+ "zh": {
47
+ "created": "创建于:",
48
+ "paused": "已暂停",
49
+ "queued": "等待开始处理",
50
+ "running": "秘书正在处理",
51
+ "waiting_event": "等待外部事件或定时检查",
52
+ "needs_input": "等待秘书协助",
53
+ "completed": "已完成",
54
+ "failed": "遇到问题,需要和秘书一起处理",
55
+ "cancelled": "已取消",
56
+ "error": "暂时无法读取工作进展",
57
+ "draft": "关于「{title}」,我想补充:",
58
+ "activeCount": "后台处理中 · {count} 件事",
59
+ "waitingCount": "{count} 件等待事件或定时检查",
60
+ "needsCount": "{count} 件需要协助",
61
+ "pausedCount": "有 {count} 件事项已暂停",
62
+ "done": "工作已告一段落",
63
+ "empty": "暂时没有需要跟进的事,可以直接告诉秘书你的安排。",
64
+ "needsSection": "需要你决定",
65
+ "failedSection": "需要处理",
66
+ "runningSection": "正在推进",
67
+ "waitingSection": "等待中",
68
+ "pausedSection": "已暂停",
69
+ "completedSection": "最近完成",
70
+ "cancelledSection": "已取消",
71
+ "moreCompleted": "更早完成的事项({count})",
72
+ "requirements": "事项详情",
73
+ "constraints": "约束:",
74
+ "check": "再次检查:",
75
+ "confirm": "去回复",
76
+ "review": "去讨论",
77
+ "discuss": "与秘书讨论",
78
+ "history": "查看执行记录",
79
+ "technical": "执行详情",
80
+ "plans": "定时安排",
81
+ "nextRun": "下次执行:",
82
+ "scheduled": "已安排",
83
+ "daily": "每天 {time}",
84
+ "weekdays": "工作日 {time}",
85
+ "planDraft": "我想调整「{title}」这个定时安排:",
86
+ "title": "工作事项"
87
+ }
88
+ };
89
+ const locale = () => typeof I18n !== "undefined" && I18n.lang ? I18n.lang() : "en";
90
+ const t = (key, vars = {}) => {
91
+ const text = (DICT[locale()] || DICT.en)[key] || DICT.en[key] || key;
92
+ return text.replace(/\{(\w+)\}/g, (_, name) => vars[name] ?? "");
93
+ };
94
+ const attention = card => ['needs_input', 'failed'].includes(card.status);
95
+ const el = (tag, text, cls) => {
96
+ const node = document.createElement(tag);
97
+ if (text) node.textContent = text;
98
+ if (cls) node.className = cls;
99
+ return node;
100
+ };
101
+
102
+ // Per-session data source shared by the aside and composer slots. Events only
103
+ // invalidate it; mount/reconnect fetch the persisted authoritative snapshot.
104
+ const stores = new Map();
105
+ function acquire(sessionId) {
106
+ let store = stores.get(sessionId);
107
+ if (!store) {
108
+ store = { cards: [], schedules: [], error: '', listeners: new Set(), refs: 0, loading: false, dirty: false, disposed: false };
109
+ store.refresh = async () => {
110
+ if (store.disposed) return;
111
+ if (store.loading) { store.dirty = true; return; }
112
+ store.loading = true;
113
+ try {
114
+ const response = await fetch('/api/ext/secretary/work?session_id=' + encodeURIComponent(sessionId));
115
+ const data = await response.json();
116
+ if (!response.ok) throw new Error('Unable to load work');
117
+ if (store.disposed) return;
118
+ store.cards = data.work || [];
119
+ store.schedules = data.schedules || [];
120
+ store.error = '';
121
+ } catch (error) {
122
+ if (!store.disposed) store.error = true;
123
+ } finally {
124
+ store.loading = false;
125
+ if (!store.disposed) store.listeners.forEach(listener => listener());
126
+ if (store.dirty && !store.disposed) { store.dirty = false; store.refresh(); }
127
+ }
128
+ };
129
+ stores.set(sessionId, store);
130
+ store.refresh();
131
+ }
132
+ store.refs++;
133
+ return store;
134
+ }
135
+ function release(sessionId, store, render) {
136
+ store.listeners.delete(render);
137
+ if (--store.refs === 0) { store.disposed = true; stores.delete(sessionId); }
138
+ }
139
+ function refreshSession(event) {
140
+ stores.get(event.sessionId || event.session_id)?.refresh();
141
+ }
142
+ Clacky.ext.subscribe('ext.work.changed', refreshSession);
143
+ Clacky.ext.subscribe('session:subscribed', refreshSession);
144
+
145
+ // Existing Composer API supplies a normal conversation draft and reference.
146
+ // Never mutate work or send a message from the panel, and preserve user drafts.
147
+ function discuss(card, ownerId) {
148
+ if (Clacky.ext.context.sessionId !== ownerId) return;
149
+ const input = document.getElementById('user-input');
150
+ const composer = Clacky.Composer;
151
+ if (!input || !composer) return;
152
+ if (!composer.hasContent(input)) composer.setText(input, t('draft', { title: card.title }));
153
+ if (!composer.chips(input).some(chip => chip.type === 'session' && chip.session_id === card.session_id)) {
154
+ composer.insertChip(input, { type: 'session', name: card.title, sessionId: card.session_id });
155
+ }
156
+ composer.focusEnd(input);
157
+ }
158
+ // Prefer the worker's user-facing sentence. Legacy short questions remain
159
+ // readable; long reports stay in the worker conversation instead of being cut off.
160
+ function brief(card) {
161
+ const concise = String(card.display_summary || '').trim();
162
+ if (concise && concise.length <= 100) return concise;
163
+ const text = String(card.progress || '').trim();
164
+ if (['needs_input', 'waiting_event'].includes(card.status) && text.length <= 100 &&
165
+ !/[\n\r`#]|https?:\/\//.test(text) && text) return text;
166
+ return t(card.status);
167
+ }
168
+ function dateText(value) {
169
+ if (!value) return '';
170
+ const date = new Date(value);
171
+ return Number.isNaN(date.getTime()) ? '' : date.toLocaleString(locale());
172
+ }
173
+ function cadence(plan) {
174
+ const fields = String(plan.cron || '').trim().split(/\s+/);
175
+ if (fields.length === 5 && /^\d+$/.test(fields[0]) && /^\d+$/.test(fields[1]) &&
176
+ Number(fields[0]) < 60 && Number(fields[1]) < 24 && fields[2] === '*' && fields[3] === '*') {
177
+ const time = fields[1].padStart(2, '0') + ':' + fields[0].padStart(2, '0');
178
+ if (fields[4] === '*') return t('daily', { time });
179
+ if (fields[4] === '1-5') return t('weekdays', { time });
180
+ }
181
+ const next = dateText(plan.next_run);
182
+ return next ? t('nextRun') + next : t('scheduled');
183
+ }
184
+ function styles() {
185
+ return el('style', `
186
+ .secretary-work { color:var(--color-text-primary); font-size:13px; line-height:1.55; }
187
+ .secretary-work-aside { padding:18px 16px; overflow:auto; height:100%; box-sizing:border-box; }
188
+ .secretary-work-muted { color:var(--color-text-secondary); font-size:12px; }
189
+ .secretary-work-group { margin-bottom:24px; }
190
+ .secretary-work-heading { margin:0 0 8px; font-size:12px; font-weight:600; color:var(--color-text-secondary); }
191
+ .secretary-work-card { padding:10px 0; border-bottom:1px solid var(--color-border-primary); }
192
+ .secretary-work-card:last-child { border-bottom:0; }
193
+ .secretary-work summary { cursor:pointer; }
194
+ .secretary-work summary:focus-visible, .secretary-work button:focus-visible { outline:2px solid var(--color-text-secondary); outline-offset:3px; }
195
+ .secretary-work-main > summary { list-style:none; position:relative; padding-right:18px; }
196
+ .secretary-work-main > summary::-webkit-details-marker { display:none; }
197
+ .secretary-work-main > summary::after { content:'›'; position:absolute; right:0; top:0; color:var(--color-text-tertiary); }
198
+ .secretary-work-main[open] > summary::after { transform:rotate(90deg); }
199
+ .secretary-work-title { display:block; font-weight:500; overflow-wrap:anywhere; }
200
+ .secretary-work-brief { display:block; margin-top:3px; color:var(--color-text-secondary); overflow-wrap:anywhere; }
201
+ .secretary-work-content { white-space:pre-wrap; overflow-wrap:anywhere; margin:10px 0; }
202
+ .secretary-work-meta { display:flex; flex-wrap:wrap; gap:2px 10px; margin-top:3px; }
203
+ .secretary-work-actions { margin-top:10px; display:flex; align-items:center; gap:14px; }
204
+ .secretary-work-actions a { font-size:12px; color:var(--color-text-secondary); text-decoration:none; }
205
+ .secretary-work-actions a:hover { text-decoration:underline; }
206
+ .secretary-work-details { margin-top:10px; color:var(--color-text-secondary); font-size:12px; }
207
+ .secretary-work-details > summary { list-style:none; }
208
+ .secretary-work-details > summary::-webkit-details-marker { display:none; }
209
+ .secretary-work-details > summary::after { content:" +"; }
210
+ .secretary-work-details[open] > summary::after { content:" −"; }
211
+ .secretary-work button { cursor:pointer; border:1px solid var(--color-border-primary); border-radius:var(--radius-sm, 6px); background:var(--color-bg-secondary); color:inherit; padding:4px 10px; font:inherit; }
212
+ .secretary-work-nested { margin-top:10px; font-size:12px; }
213
+ .secretary-work-status { display:flex; flex-wrap:wrap; gap:8px; align-items:center; padding:6px 0; }
214
+ .secretary-work-status-title { color:var(--color-text-secondary); }
215
+ .secretary-work-error { color:var(--color-error); margin-bottom:12px; }
216
+ `);
217
+ }
218
+ function mountRuntime(ctx, compact) {
219
+ const store = acquire(ctx.sessionId);
220
+ const expanded = new Set();
221
+ const root = el('div', null, 'secretary-work' + (compact ? '' : ' secretary-work-aside'));
222
+ const body = el('div');
223
+ root.append(styles(), body);
224
+ function disclosure(key, summary, cls) {
225
+ const details = el('details', null, cls);
226
+ details.open = expanded.has(key);
227
+ details.ontoggle = () => { if (details.open) expanded.add(key); else expanded.delete(key); };
228
+ details.append(summary);
229
+ return details;
230
+ }
231
+ function button(label, action) {
232
+ const node = el('button', label);
233
+ node.type = 'button';
234
+ node.onclick = action;
235
+ return node;
236
+ }
237
+ function workRow(card) {
238
+ const row = el('article', null, 'secretary-work-card');
239
+ row.append(el('strong', card.title, 'secretary-work-title'));
240
+ const meta = el('div', null, 'secretary-work-meta secretary-work-muted');
241
+ meta.append(el('span', brief(card)));
242
+ const created = dateText(card.created_at);
243
+ if (created) {
244
+ const time = el('time', t('created') + created);
245
+ time.dateTime = card.created_at;
246
+ meta.append(time);
247
+ }
248
+ row.append(meta);
249
+ const check = dateText(card.waiting?.check_at);
250
+ if (card.status === 'waiting_event' && check) row.append(el('small', t('check') + check, 'secretary-work-muted'));
251
+ const actions = el('div', null, 'secretary-work-actions');
252
+ actions.append(button(t('discuss'), () => discuss(card, ctx.sessionId)));
253
+ const link = el('a', t('history'));
254
+ link.href = '#session/' + encodeURIComponent(card.session_id);
255
+ actions.append(link);
256
+ row.append(actions);
257
+ if (card.instruction || card.constraints || card.updates?.length) {
258
+ const details = disclosure('work:' + card.id, el('summary', t('requirements')), 'secretary-work-details');
259
+ if (card.instruction) details.append(el('div', card.instruction, 'secretary-work-content'));
260
+ if (card.constraints) details.append(el('div', t('constraints') + card.constraints, 'secretary-work-content'));
261
+ (card.updates || []).forEach(update => details.append(el('div', update.text, 'secretary-work-content')));
262
+ row.append(details);
263
+ }
264
+ return row;
265
+ }
266
+ function render() {
267
+ body.replaceChildren();
268
+ const cards = store.cards;
269
+ const active = cards.filter(card => !['completed', 'cancelled'].includes(card.status));
270
+ const needs = cards.filter(attention);
271
+ const running = cards.filter(card => ['queued', 'running'].includes(card.status));
272
+ const waiting = cards.filter(card => card.status === 'waiting_event');
273
+ const paused = cards.filter(card => card.status === 'paused');
274
+ if (ctx.setBadge) ctx.setBadge(needs.length || null);
275
+ if (store.error) body.append(el('div', t('error'), 'secretary-work-error'));
276
+ if (compact) {
277
+ root.hidden = !cards.length && !store.error;
278
+ if (!cards.length) return;
279
+ const running = cards.filter(card => ['queued', 'running'].includes(card.status));
280
+ const waiting = cards.filter(card => card.status === 'waiting_event');
281
+ const parts = [];
282
+ if (running.length) parts.push(t('activeCount', { count: running.length }));
283
+ if (waiting.length) parts.push(t('waitingCount', { count: waiting.length }));
284
+ if (needs.length) parts.push(t('needsCount', { count: needs.length }));
285
+ if (!parts.length) parts.push(active.length ? t('pausedCount', { count: active.length }) : t('done'));
286
+ const row = el('div', null, 'secretary-work-status');
287
+ row.append(el('span', parts.join(' · '), 'secretary-work-status-title'));
288
+ const focus = needs.length ? needs : active;
289
+ focus.slice(0, 3).forEach(card => {
290
+ const button = el('button', card.title);
291
+ button.type = 'button';
292
+ button.onclick = () => discuss(card, ctx.sessionId);
293
+ row.append(button);
294
+ });
295
+ body.append(row);
296
+ return;
297
+ }
298
+ // A stable chronological list: status changes never move a work item.
299
+ [...cards].sort((a, b) => (Date.parse(b.created_at) || 0) - (Date.parse(a.created_at) || 0))
300
+ .forEach(card => body.append(workRow(card)));
301
+ if (store.schedules.length) {
302
+ const plans = el('section', null, 'secretary-work-group');
303
+ plans.append(el('h3', t('plans'), 'secretary-work-heading'));
304
+ store.schedules.forEach(plan => {
305
+ const title = plan.target?.title || plan.name;
306
+ const summary = el('summary');
307
+ summary.append(el('strong', title, 'secretary-work-title'), el('span',
308
+ cadence(plan) + (plan.enabled === false ? ' · ' + t('paused') : ''), 'secretary-work-brief'));
309
+ const details = disclosure('plan:' + plan.name, summary, 'secretary-work-main');
310
+ const next = dateText(plan.next_run);
311
+ if (plan.enabled !== false && next) details.append(el('p', t('nextRun') + next, 'secretary-work-muted'));
312
+ if (plan.content) details.append(el('div', plan.content, 'secretary-work-content'));
313
+ details.append(button(t('discuss'), () => {
314
+ if (Clacky.ext.context.sessionId !== ctx.sessionId) return;
315
+ const input = document.getElementById('user-input');
316
+ if (!input || !Clacky.Composer) return;
317
+ if (!Clacky.Composer.hasContent(input)) Clacky.Composer.setText(input, t('planDraft', { title }));
318
+ Clacky.Composer.focusEnd(input);
319
+ }));
320
+ const row = el('article', null, 'secretary-work-card');
321
+ row.append(details);
322
+ plans.append(row);
323
+ });
324
+ body.append(plans);
325
+ }
326
+ if (!cards.length && !store.schedules.length && !store.error) body.append(el('p', t('empty'), 'secretary-work-muted'));
327
+ }
328
+ store.listeners.add(render);
329
+ render();
330
+ return { root, dispose() { release(ctx.sessionId, store, render); } };
331
+ }
332
+ document.addEventListener('langchange', () => {
333
+ stores.forEach(store => store.listeners.forEach(render => render()));
334
+ if (typeof Clacky.ext.refreshSlots === 'function') Clacky.ext.refreshSlots();
335
+ });
336
+ Clacky.ext.ui.mount('session.aside', {
337
+ create(ctx) { return mountRuntime(ctx, false); },
338
+ render(container, ctx, runtime) { container.appendChild(runtime.root); }
339
+ }, { order: 20, tab: { id: 'secretary-work', label: () => t('title') } });
340
+ Clacky.ext.ui.mount('session.composer', {
341
+ create(ctx) { return mountRuntime(ctx, true); },
342
+ render(container, ctx, runtime) { container.appendChild(runtime.root); }
343
+ }, { order: 100 });
344
+ })();
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ module Clacky
3
+ module Tools
4
+ class DelegateWork < Base
5
+ self.tool_name = "delegate_work"
6
+ self.tool_description = "Delegate work to the configured worker and return its ID immediately. Include the objective, authorization boundaries and acceptance criteria."
7
+ self.tool_parameters = {
8
+ type: "object", properties: {
9
+ title: { type: "string", description: "Short work title" },
10
+ task: { type: "string", description: "Objective, necessary background and completion criteria" },
11
+ constraints: { type: "string", description: "Confirmed constraints, permissions and unknowns" }
12
+ }, required: %w[title task]
13
+ }
14
+ def format_call(args)
15
+ Clacky::I18n.t("work.delegating", title: args[:title] || args["title"])
16
+ end
17
+
18
+ def format_result(result)
19
+ return super unless result.is_a?(Hash) && (result[:id] || result["id"])
20
+ Clacky::I18n.translate(result[:locale] || result["locale"] || Clacky::I18n.locale,
21
+ "work.delegated", title: result[:title] || result["title"])
22
+ end
23
+
24
+ # Reuse the same tool-result presentation as worker reports. Replay can
25
+ # reconstruct this from old persisted cards without rewriting history.
26
+ def ui_result(result)
27
+ return nil unless result.is_a?(Hash) && (result[:id] || result["id"]) && (result[:session_id] || result["session_id"])
28
+ { type: "markdown", content: format_result(result) }
29
+ end
30
+
31
+ def execute(title:, task:, constraints: "", **)
32
+ raise "Delegation requires the OpenClacky web server" unless agent&.work_service
33
+ agent.work_service.delegate(agent, title: title, task: task, constraints: constraints).merge(notify_user: false)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module Clacky
3
+ module Tools
4
+ class ManageWork < Base
5
+ self.tool_name = "manage_work"
6
+ self.tool_description = "List/get your work; update requirements, relay a reply/decision, pause, cancel, or resume paused/failed work in its existing session. For continuing interrupted work, use resume with its work_id rather than creating a new delegation. Completed work accepts reply/update for further feedback in the same session; cancelled work stays stopped. Use expected_revision when editing a previously read card."
7
+ self.tool_parameters = {
8
+ type: "object", properties: {
9
+ action: { type: "string", enum: %w[list get update reply pause cancel resume] },
10
+ work_id: { type: "string" }, instruction: { type: "string" },
11
+ expected_revision: { type: "integer" }
12
+ }, required: %w[action]
13
+ }
14
+ def execute(action:, work_id: nil, instruction: nil, expected_revision: nil, **)
15
+ raise "Work management requires the OpenClacky web server" unless agent&.work_service
16
+ result = agent.work_service.manage(agent.session_id, action: action, work_id: work_id,
17
+ instruction: instruction, expected_revision: expected_revision)
18
+ %w[reply update resume].include?(action) ? result.merge(notify_user: false) : result
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ module Clacky
3
+ module Tools
4
+ class YieldWork < Base
5
+ self.tool_name = "yield_work"
6
+ self.tool_description = "End this execution: complete with evidence, request a user decision, or wait. Channel matching requires genuine channel/chat/sent-message IDs; otherwise accept a relayed reply in the panel."
7
+ self.tool_parameters = {
8
+ type: "object", properties: {
9
+ reason: { type: "string", enum: %w[waiting_event needs_input completed], description: "needs_input asks the main agent for help or a decision; waiting_event awaits an external reply or timed checkpoint" },
10
+ summary: { type: "string", description: "Result with evidence, concrete question, or what you are waiting for" },
11
+ display_summary: { type: "string", description: "User-facing progress in one short sentence (max 100 characters): result, question or what is awaited. No internal IDs, channel metadata or execution narration." },
12
+ check_at: { type: "string", description: "Optional future ISO8601 timestamp including timezone" },
13
+ channel: { type: "string" }, conversation_id: { type: "string" }, reply_to: { type: "string" }
14
+ }, required: %w[reason summary]
15
+ }
16
+ def format_call(args)
17
+ concise = (args[:display_summary] || args["display_summary"]).to_s.strip
18
+ return concise if !concise.empty? && concise.length <= 100
19
+ "yield_work(#{args[:reason] || args['reason']})"
20
+ end
21
+
22
+ # Both live rendering and history replay use the host's tool UI contract.
23
+ def ui_result(result)
24
+ return nil unless result[:work_yielded] && !result[:message].to_s.empty?
25
+ { type: "markdown", content: result[:message] }
26
+ end
27
+
28
+ def execute(reason:, summary:, display_summary: nil, check_at: nil, channel: nil, conversation_id: nil, reply_to: nil, **)
29
+ raise "Yield requires a delegated server work session" unless agent&.work_service
30
+ agent.work_service.yield_work(agent, reason: reason, summary: summary, display_summary: display_summary, check_at: check_at,
31
+ channel: channel, conversation_id: conversation_id, reply_to: reply_to)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ # Time Machine
2
+
3
+ Every time the AI finishes a step, your workspace is snapshotted automatically. Broke something? Jump back to any earlier step.
4
+
5
+ ## Opening it
6
+
7
+ Switch to the **History** tab in the session's side panel to see a timeline of tasks.
8
+
9
+ - The step marked **Current** is the version your workspace is on right now.
10
+ - Each step shows how many files changed and when it finished.
11
+
12
+ ## Seeing what a step changed
13
+
14
+ 1. Click a step on the timeline to expand it and see its main changed files.
15
+ 2. Click **View details** for a two-pane view: file list on the left, line-by-line diff on the right.
16
+ 3. Tags next to each file show the kind of change: **Added / Created / Modified / Deleted**.
17
+ 4. Click **Back** to return to the timeline.
18
+
19
+ ## Going back to an earlier step
20
+
21
+ 1. Expand the target step and click **Go back here**.
22
+ 2. The panel first lists the files that will be affected so you can check them.
23
+ 3. Click **Confirm** and the workspace files are restored to how they were at that step.
24
+
25
+ > ⚠️ Going back overwrites the current changes in those files. Review the list before confirming.
26
+
27
+ If you keep working after going back, the new work grows as a **Branch** — the original history is kept and you can still switch back to it.
28
+
29
+ ## Tips
30
+
31
+ - Snapshots are automatic: no manual saving, and no Git required.
32
+ - To review changes from a Git perspective — by commit or branch — use the **Git** extension.
@@ -0,0 +1,32 @@
1
+ # 时光机
2
+
3
+ AI 每完成一步任务,都会自动给工作区存一个档。改坏了?随时回到之前任意一步。
4
+
5
+ ## 怎么打开
6
+
7
+ 在会话右侧面板切换到 **「时光机」** 标签页,会看到一条按时间排列的任务时间轴。
8
+
9
+ - 标有 **「当前」** 的是工作区现在所处的版本。
10
+ - 每一步显示改动了几个文件以及完成时间。
11
+
12
+ ## 查看某一步改了什么
13
+
14
+ 1. 点击时间轴上的某一步,展开卡片,可以看到主要改动的文件。
15
+ 2. 点击 **「查看详情」**,进入双栏视图:左边是文件列表,右边是逐行差异。
16
+ 3. 文件旁的标签说明改动类型:**新增 / 新建 / 修改 / 删除**。
17
+ 4. 点击 **「返回」** 回到时间轴。
18
+
19
+ ## 回到之前的某一步
20
+
21
+ 1. 展开目标步骤,点击 **「回到这里」**。
22
+ 2. 面板会先列出将受影响的文件,供你确认。
23
+ 3. 点击 **「确认回到这里」**,工作区文件会恢复到那一步完成时的状态。
24
+
25
+ > ⚠️ 回到某一步会覆盖当前工作区中对应文件的修改,请先确认列出的文件。
26
+
27
+ 回到过去的某一步后继续让 AI 工作,会从那里长出新的 **「分支」**,原来的记录不会丢失,之后仍可以切换回去。
28
+
29
+ ## 小贴士
30
+
31
+ - 存档是自动的,不需要手动保存,也不依赖 Git。
32
+ - 想以 Git 的视角审阅改动、按提交或分支对比,可以使用「Git 管理」扩展。
@@ -5,8 +5,8 @@ display_name_zh: 时光机
5
5
  description: Vertical timeline of session tasks with per-task diff and one-click restore
6
6
  description_zh: 会话任务时间轴,支持按任务查看差异并一键还原
7
7
  version: "0.1.0"
8
+ icon: icon.svg
8
9
  author: OpenClacky
9
- homepage: https://www.openclacky.com
10
10
  license: MIT
11
11
  contributes:
12
12
  panels:
@@ -0,0 +1,14 @@
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="timemachine-bg" x1="18" y1="0" x2="18" y2="36" gradientUnits="userSpaceOnUse">
4
+ <stop stop-color="#14B8A6"/>
5
+ <stop offset="1" stop-color="#0D9488"/>
6
+ </linearGradient>
7
+ </defs>
8
+ <rect width="36" height="36" fill="url(#timemachine-bg)"/>
9
+ <g transform="translate(8 8) scale(0.8333)" stroke="#fff" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
10
+ <path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
11
+ <path d="M3 3v5h5"/>
12
+ <path d="M12 7v5l4 2"/>
13
+ </g>
14
+ </svg>