@emqo/claudebridge 0.3.1 → 0.4.0

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.
@@ -9,10 +9,13 @@ export declare class DiscordAdapter implements Adapter {
9
9
  private locale;
10
10
  private client;
11
11
  private reminderTimer?;
12
+ private autoTimer?;
13
+ private autoRunning;
12
14
  constructor(engine: AgentEngine, store: Store, config: DiscordConfig, locale?: string);
13
15
  private setup;
14
16
  private handlePrompt;
15
17
  start(): Promise<void>;
16
18
  stop(): void;
17
19
  private checkReminders;
20
+ private processAutoTasks;
18
21
  }
@@ -12,6 +12,8 @@ export class DiscordAdapter {
12
12
  locale;
13
13
  client;
14
14
  reminderTimer;
15
+ autoTimer;
16
+ autoRunning = false;
15
17
  constructor(engine, store, config, locale = "en") {
16
18
  this.engine = engine;
17
19
  this.store = store;
@@ -164,10 +166,13 @@ export class DiscordAdapter {
164
166
  await this.client.login(this.config.token);
165
167
  console.log(`[discord] logged in as ${this.client.user?.tag}`);
166
168
  this.reminderTimer = setInterval(() => this.checkReminders(), 30000);
169
+ this.autoTimer = setInterval(() => this.processAutoTasks(), 60000);
167
170
  }
168
171
  stop() {
169
172
  if (this.reminderTimer)
170
173
  clearInterval(this.reminderTimer);
174
+ if (this.autoTimer)
175
+ clearInterval(this.autoTimer);
171
176
  this.client.destroy();
172
177
  }
173
178
  async checkReminders() {
@@ -184,4 +189,42 @@ export class DiscordAdapter {
184
189
  console.error("[discord] reminder error:", e);
185
190
  }
186
191
  }
192
+ async processAutoTasks() {
193
+ if (this.autoRunning)
194
+ return;
195
+ const task = this.store.getNextAutoTask("discord");
196
+ if (!task)
197
+ return;
198
+ this.autoRunning = true;
199
+ this.store.markTaskRunning(task.id);
200
+ try {
201
+ const ch = await this.client.channels.fetch(task.chat_id);
202
+ if (!ch?.isTextBased() || !("send" in ch))
203
+ throw new Error("channel not found");
204
+ const channel = ch;
205
+ await channel.send(t(this.locale, "auto_starting", { id: task.id, desc: task.description }));
206
+ console.log(`[discord] auto-task #${task.id} for ${task.user_id}`);
207
+ const res = await this.engine.runStream(task.user_id, task.description, "discord", task.chat_id);
208
+ this.store.markTaskResult(task.id, "done");
209
+ const maxLen = this.config.chunk_size || 1900;
210
+ const chunks = chunkText(res.text || "(no output)", maxLen);
211
+ await channel.send(t(this.locale, "auto_done", { id: task.id, cost: (res.cost || 0).toFixed(4) }));
212
+ for (const c of chunks)
213
+ await channel.send(c);
214
+ }
215
+ catch (err) {
216
+ this.store.markTaskResult(task.id, "failed");
217
+ console.error(`[discord] auto-task #${task.id} failed:`, err);
218
+ try {
219
+ const ch = await this.client.channels.fetch(task.chat_id);
220
+ if (ch?.isTextBased() && "send" in ch) {
221
+ await ch.send(t(this.locale, "auto_failed", { id: task.id, err: err.message || "unknown" }));
222
+ }
223
+ }
224
+ catch { }
225
+ }
226
+ finally {
227
+ this.autoRunning = false;
228
+ }
229
+ }
187
230
  }
@@ -364,7 +364,7 @@ export class TelegramAdapter {
364
364
  async processAutoTasks() {
365
365
  if (this.autoRunning)
366
366
  return;
367
- const task = this.store.getNextAutoTask();
367
+ const task = this.store.getNextAutoTask("telegram");
368
368
  if (!task)
369
369
  return;
370
370
  this.autoRunning = true;
@@ -46,7 +46,7 @@ export declare class Store {
46
46
  description: string;
47
47
  }[];
48
48
  markReminderSent(taskId: number): void;
49
- getNextAutoTask(): {
49
+ getNextAutoTask(platform?: string): {
50
50
  id: number;
51
51
  user_id: string;
52
52
  platform: string;
@@ -135,7 +135,10 @@ export class Store {
135
135
  markReminderSent(taskId) {
136
136
  this.db.prepare("UPDATE tasks SET reminder_sent = 1 WHERE id = ?").run(taskId);
137
137
  }
138
- getNextAutoTask() {
138
+ getNextAutoTask(platform) {
139
+ if (platform) {
140
+ return this.db.prepare("SELECT id, user_id, platform, chat_id, description FROM tasks WHERE status = 'auto' AND platform = ? ORDER BY created_at ASC LIMIT 1").get(platform) ?? null;
141
+ }
139
142
  return this.db.prepare("SELECT id, user_id, platform, chat_id, description FROM tasks WHERE status = 'auto' ORDER BY created_at ASC LIMIT 1").get() ?? null;
140
143
  }
141
144
  markTaskRunning(taskId) {
@@ -52,6 +52,13 @@ export function generateSkillDoc(ctx) {
52
52
  ` 2. "优化模块A:[具体描述,包含文件路径和修改内容]"`,
53
53
  ` 3. "优化模块B:[具体描述]"`,
54
54
  ` 4. "运行测试验证所有修改,提交代码,生成优化报告"`,
55
+ ``,
56
+ `### 跨任务记忆传递`,
57
+ `- 每个 auto-task 完成关键分析后,用 memory add 保存结论`,
58
+ `- 下一个 auto-task 会自动加载记忆,可以读取前序任务的成果`,
59
+ `- 示例:分析完成后调用 \`${ctl} memory add ${ctx.userId} "模块A优化点:1.重构API 2.添加缓存 3.修复N+1查询"\``,
60
+ `- 最后一个 auto-task 完成后,清理临时工作记忆(可选)`,
61
+ `- 重要:描述中包含"先用 memory list 查看前序任务的分析结果"可确保链式上下文不断`,
55
62
  ].join("\n");
56
63
  }
57
64
  return [
@@ -100,5 +107,12 @@ export function generateSkillDoc(ctx) {
100
107
  ` 2. "Optimize module A: [specific file paths and changes]"`,
101
108
  ` 3. "Optimize module B: [specific description]"`,
102
109
  ` 4. "Run tests, commit changes, generate optimization report"`,
110
+ ``,
111
+ `### Cross-Task Memory Bridging`,
112
+ `- After completing key analysis in an auto-task, save conclusions via memory add`,
113
+ `- The next auto-task automatically loads memories, accessing prior task findings`,
114
+ `- Example: after analysis, call \`${ctl} memory add ${ctx.userId} "Module A needs: 1.refactor API 2.add cache 3.fix N+1 queries"\``,
115
+ `- Optionally clean up temporary work memories after the final auto-task`,
116
+ `- Tip: include "first run memory list to review prior task findings" in descriptions to ensure chain continuity`,
103
117
  ].join("\n");
104
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emqo/claudebridge",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Bridge Claude Code Agent SDK to chat platforms (Telegram, Discord, etc.)",
5
5
  "main": "dist/index.js",
6
6
  "bin": {