@yeaft/webchat-agent 1.0.396 → 1.0.397

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.
@@ -1 +1 @@
1
- {"version":"1.0.396"}
1
+ {"version":"1.0.397"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "1.0.396",
3
+ "version": "1.0.397",
4
4
  "description": "Remote worker agent for Yeaft Web Code Agent — connects the native Yeaft engine, CLI providers, and workbench tools",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -73,11 +73,12 @@ export async function extractAndWriteMemorySegments(opts) {
73
73
  errors.push({ scope, error: err.message, rawSnippet: err.rawSnippet || '' });
74
74
  }
75
75
 
76
+ // Session memory must contain extracted facts and reusable experience, not a
77
+ // serialized transcript tail. Raw message ids, roles, and tool payloads are
78
+ // execution history; copying them into canonical Dream content makes that
79
+ // history re-enter later provider requests as system-prompt prose.
76
80
  const recent = scope === `sessions/${opts.sessionId}`
77
- ? [
78
- buildRecentSegment({ scope, messages, now }),
79
- buildRecentExperienceSegment({ scope, extracted, now }),
80
- ].filter(Boolean)
81
+ ? [buildRecentExperienceSegment({ scope, extracted, now })].filter(Boolean)
81
82
  : [];
82
83
  if (extracted.length === 0 && recent.length === 0) continue;
83
84
 
@@ -200,23 +201,6 @@ function normalizeSourceMessageIds(value) {
200
201
  return ids;
201
202
  }
202
203
 
203
- function buildRecentSegment({ scope, messages, now }) {
204
- const recentMessages = messages.slice(-RECENT_MESSAGE_COUNT);
205
- const body = [
206
- 'Recent session details from the latest Dream pass:',
207
- ...recentMessages.map(m => `- ${m.id} ${m.role}${m.vpId ? `/${m.vpId}` : ''}: ${oneLine(m.body)}`),
208
- ].join('\n');
209
- return makeSegment({
210
- scope,
211
- kind: 'context',
212
- tags: ['recent', 'current'],
213
- sourceMessages: recentMessages.map(m => m.id),
214
- createdAt: now,
215
- updatedAt: now,
216
- body,
217
- });
218
- }
219
-
220
204
  function buildRecentExperienceSegment({ scope, extracted, now }) {
221
205
  const experienceSegments = extracted
222
206
  .filter(isExperienceSegment)
@@ -7,6 +7,8 @@
7
7
  */
8
8
 
9
9
  const DREAM_STATE_BLOCK_RE = /<!--\s*dream-state\s*-->[\s\S]*?<!--\s*\/dream-state\s*-->/gi;
10
+ const DREAM_RECENT_TRANSCRIPT_HEADER_RE = /^\s*Recent session details from the latest Dream pass:\s*$/i;
11
+ const DREAM_TRANSCRIPT_LINE_RE = /^\s*[-*]\s+\S+\s+(?:user|assistant|tool)(?:\/[^:\s]+)?:\s*/i;
10
12
 
11
13
  const TRANSIENT_MEMORY_RE = /\b(work\s*item|current\s+(?:state|work|task)|in[_ -]?progress|todo|next\s+step|blocker|blocked|pr\s*#?\d+|pull\s+request|review|merge\s+commit|release\s+tag|tag\s+v\d|v\d+\.\d+\.\d+)\b|(?:工作项|当前(?:状态|任务|工作)|正在|待办|下一步|阻塞|评审|合并|发布|标签|已推|已合并|已完成)/i;
12
14
  const ASCII_WORD_RE = /[a-z0-9_]{3,}/gi;
@@ -39,12 +41,27 @@ export function stripDreamStateBlocks(text) {
39
41
  * @returns {string}
40
42
  */
41
43
  export function cleanMemoryPromptText(text) {
42
- return stripDreamStateBlocks(text)
44
+ return stripGeneratedDreamTranscript(stripDreamStateBlocks(text))
43
45
  .replace(/[ \t]+\n/g, '\n')
44
46
  .replace(/\n{3,}/g, '\n\n')
45
47
  .trim();
46
48
  }
47
49
 
50
+ function stripGeneratedDreamTranscript(text) {
51
+ const kept = [];
52
+ let generatedTranscript = false;
53
+ for (const line of String(text || '').split(/\r?\n/)) {
54
+ if (DREAM_RECENT_TRANSCRIPT_HEADER_RE.test(line)) {
55
+ generatedTranscript = true;
56
+ continue;
57
+ }
58
+ if (generatedTranscript && DREAM_TRANSCRIPT_LINE_RE.test(line)) continue;
59
+ generatedTranscript = false;
60
+ kept.push(line);
61
+ }
62
+ return kept.join('\n');
63
+ }
64
+
48
65
  /**
49
66
  * Whether a memory item describes short-lived execution state rather than a
50
67
  * stable preference / project fact. Transient memory is still valid on disk, but