@yeaft/webchat-agent 0.1.45 → 0.1.47

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.
package/crew/control.js CHANGED
@@ -8,6 +8,8 @@ import { sendCrewMessage, sendCrewOutput, sendStatusUpdate, endRoleStreaming } f
8
8
  import { saveRoleSessionId, clearRoleSessionId, createRoleQuery } from './role-query.js';
9
9
  import { saveSessionMeta, cleanupMessageShards } from './persistence.js';
10
10
  import { executeRoute, dispatchToRole } from './routing.js';
11
+ import { saveRoleWorkSummary } from './task-files.js';
12
+ import { getMessages } from '../crew-i18n.js';
11
13
  import { cleanupWorktrees } from './worktree.js';
12
14
  import { upsertCrewIndex } from './persistence.js';
13
15
  import { processHumanQueue } from './human-interaction.js';
@@ -65,6 +67,12 @@ async function clearSingleRole(session, roleName) {
65
67
  const roleState = session.roleStates.get(roleName);
66
68
 
67
69
  if (roleState) {
70
+ // 保存工作摘要到 task file(与 context_exceeded clear 一致)
71
+ if (roleState.accumulatedText) {
72
+ await saveRoleWorkSummary(session, roleName, roleState.accumulatedText).catch(e =>
73
+ console.warn(`[Crew] Failed to save work summary for ${roleName}:`, e.message));
74
+ }
75
+
68
76
  if (roleState.abortController) {
69
77
  roleState.abortController.abort();
70
78
  }
@@ -95,6 +103,19 @@ async function clearSingleRole(session, roleName) {
95
103
  });
96
104
  sendStatusUpdate(session);
97
105
  console.log(`[Crew] Role ${roleName} cleared`);
106
+
107
+ // 从 messageHistory 提取该角色最近 5 条相关消息,构造记忆恢复 prompt
108
+ const roleMessages = session.messageHistory
109
+ .filter(m => m.from === roleName || m.to === roleName)
110
+ .slice(-5);
111
+ if (roleMessages.length > 0) {
112
+ const m = getMessages(session.language || 'zh-CN');
113
+ const summary = roleMessages
114
+ .map(msg => `[${msg.from} → ${msg.to}${msg.taskId ? ` (${msg.taskId})` : ''}] ${msg.content}`)
115
+ .join('\n');
116
+ const restorePrompt = `${m.memoryRestorePrompt}\n\n${summary}`;
117
+ await dispatchToRole(session, roleName, restorePrompt, 'system');
118
+ }
98
119
  }
99
120
 
100
121
  /**
package/crew/routing.js CHANGED
@@ -168,6 +168,18 @@ export async function dispatchToRole(session, roleName, content, fromSource, tas
168
168
  }
169
169
  }
170
170
 
171
+ // 最近路由消息注入(帮助 clear 后的角色恢复上下文)
172
+ if (typeof content === 'string' && session.messageHistory.length > 0) {
173
+ const recentRoutes = session.messageHistory
174
+ .filter(m => m.from !== 'system')
175
+ .slice(-5)
176
+ .map(m => `[${m.from} → ${m.to}${m.taskId ? ` (${m.taskId})` : ''}] ${m.content}`)
177
+ .join('\n');
178
+ if (recentRoutes) {
179
+ content = `${content}\n\n---\n<recent-routes>\n${recentRoutes}\n</recent-routes>`;
180
+ }
181
+ }
182
+
171
183
  // 记录消息历史
172
184
  session.messageHistory.push({
173
185
  from: fromSource,
package/crew-i18n.js CHANGED
@@ -200,6 +200,9 @@ ${isDevTeam ? '3' : '2'}. **任务完成** - 所有任务已完成,给出完
200
200
  kanbanStatusTest: '🧪 测试中',
201
201
  kanbanStatusDecision: '⏳ 待决策',
202
202
  kanbanAutoSave: '自动保存 - context 超限前',
203
+
204
+ // clearSingleRole — memory restore prompt
205
+ memoryRestorePrompt: '你的对话上下文刚被清空(clear)。下面是你之前的一些对话记录,请恢复记忆并继续工作。如果有正在进行的任务,请继续完成。',
203
206
  },
204
207
 
205
208
  'en': {
@@ -396,6 +399,9 @@ Roles don't need to manually create or update these files.`,
396
399
  kanbanStatusTest: '🧪 Testing',
397
400
  kanbanStatusDecision: '⏳ Pending Decision',
398
401
  kanbanAutoSave: 'Auto-save — before context limit',
402
+
403
+ // clearSingleRole — memory restore prompt
404
+ memoryRestorePrompt: 'This session was continued from a previous conversation that was cleared. Below are your recent records and conversation history to help restore your memory. If there are tasks in progress, please continue working on them.',
399
405
  }
400
406
  };
401
407
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.1.45",
3
+ "version": "0.1.47",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",