@yeaft/webchat-agent 1.0.52 → 1.0.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "1.0.52",
3
+ "version": "1.0.53",
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",
package/yeaft/prompts.js CHANGED
@@ -26,7 +26,6 @@ import { readFileSync, existsSync } from 'fs';
26
26
  import { join, dirname } from 'path';
27
27
  import { fileURLToPath } from 'url';
28
28
  import { getRuntimePlatformInfo, renderRuntimePlatformPrompt } from './runtime-platform.js';
29
- import { DEFAULT_VPS } from './vp/seed-defaults.js';
30
29
 
31
30
  // ─── Template Loading (one-time at startup) ──────────────────────
32
31
 
@@ -463,50 +462,17 @@ function selectVpPersonaName(vpPersona, effectiveLang) {
463
462
  return typeof vpPersona.displayName === 'string' ? vpPersona.displayName.trim() : '';
464
463
  }
465
464
 
466
- function normalizePersonaBodyForMatch(value) {
467
- return typeof value === 'string' ? value.trim() : '';
468
- }
469
-
470
- function selectMigratedStockPersonaBody(vpPersona, body, effectiveLang) {
471
- const vpId = typeof vpPersona?.vpId === 'string' ? vpPersona.vpId.trim() : '';
472
- const persistedBody = normalizePersonaBodyForMatch(body);
473
- if (!vpId || !persistedBody) return null;
474
-
475
- const stock = DEFAULT_VPS.find(vp => vp.vpId === vpId);
476
- if (!stock) return null;
477
-
478
- const acceptedBodies = [
479
- stock.legacyPersonaEn,
480
- stock.legacyPersona,
481
- stock.personaEn,
482
- ...(Array.isArray(stock.legacyPersonas) ? stock.legacyPersonas : []),
483
- ]
484
- .map(normalizePersonaBodyForMatch)
485
- .filter(Boolean);
486
-
487
- if (!acceptedBodies.includes(persistedBody)) return null;
488
- const selected = effectiveLang === 'zh' ? stock.personaZh : stock.personaEn;
489
- return normalizePersonaBodyForMatch(selected) || null;
490
- }
491
-
492
465
  function selectVpPersonaBody(vpPersona, effectiveLang) {
493
466
  const body = typeof vpPersona.persona === 'string' ? vpPersona.persona.trim() : '';
494
467
 
495
- // role.md persona is the canonical soul. Exact stock legacy bodies are mapped
496
- // to the current authored source so old seeded role.md files do not leak
497
- // bilingual/English souls into localized system prompts before top-up runs.
498
- if (body) {
499
- const migratedStockBody = selectMigratedStockPersonaBody(vpPersona, body, effectiveLang);
500
- if (migratedStockBody) return migratedStockBody;
501
-
502
- if (body.includes('<!-- lang:')) {
503
- const selected = extractExactLangSection(body, effectiveLang);
504
- return selected !== null ? selected : body;
505
- }
506
- return body;
468
+ // role.md is the canonical soul source. Stock legacy migration belongs in
469
+ // seed-topup, not in prompt rendering; prompt rendering should only select
470
+ // authored language sections when they are present.
471
+ if (body && body.includes('<!-- lang:')) {
472
+ const selected = extractExactLangSection(body, effectiveLang);
473
+ return selected !== null ? selected : body;
507
474
  }
508
-
509
- return '';
475
+ return body;
510
476
  }
511
477
 
512
478
 
@@ -9,24 +9,30 @@
9
9
  * (b) a forced overwrite that would clobber their hand edits.
10
10
  *
11
11
  * This module runs on every agent start alongside `seedDefaultVps` and does
12
- * two minimal, additive things:
12
+ * three safe stock-maintenance things:
13
13
  *
14
14
  * 1. **Top-up missing stock VPs**. If a vpId from `DEFAULT_VPS` is not
15
15
  * on disk, `createVp()` it. This keeps product-owned defaults such as
16
16
  * Omni and the expanded role roster visible in session/member pickers.
17
17
  *
18
- * 2. **Backfill the `area` frontmatter line** on existing seeded VPs whose
19
- * role.md predates the area field. The body is left BYTE-IDENTICAL —
20
- * we splice a single `area: <bucket>` line into the YAML frontmatter
21
- * and write nothing else. If the user has authored their own `area`,
22
- * we keep theirs.
18
+ * 2. **Backfill missing stock frontmatter** (`area`, `nameZh`, `roleZh`) on
19
+ * existing seeded VPs whose role.md predates those fields. The persona body
20
+ * is left BYTE-IDENTICAL for these metadata backfills. If the user has
21
+ * authored their own value, we keep theirs.
22
+ *
23
+ * 3. **Migrate exact historical stock bodies to canonical localized bodies**.
24
+ * This is intentionally a write-time migration, not a prompt-rendering
25
+ * fallback: once top-up sees an old shipped Omni/Linus/etc. body, role.md is
26
+ * rewritten to the current `<!-- lang:en -->` / `<!-- lang:zh -->` stock
27
+ * persona. User-edited bodies are not touched.
23
28
  *
24
29
  * Hard rules:
25
- * - **Never** overwrite a VP that is on disk. The user might have edited
26
- * persona/role/traits; that is their truth, not ours.
27
- * - **Keep stock defaults available.** If a shipped stock VP is missing,
28
- * recreate it, but never overwrite an on-disk VP. The session/member picker
29
- * depends on these product-owned defaults being present.
30
+ * - **Never** overwrite a user-edited VP. A persona body is only rewritten when
31
+ * it exactly matches a historical body shipped by us.
32
+ * - **Keep stock defaults canonical and available.** If a shipped stock VP is
33
+ * missing, recreate it. If it exists with an old exact stock body, rewrite
34
+ * that body to the current canonical localized body. The session/member
35
+ * picker depends on these product-owned defaults being present and current.
30
36
  * - Best-effort: any failure is logged, never thrown.
31
37
  *
32
38
  * Pre-ledger deletion caveat: on the very first top-up against an existing
@@ -47,8 +53,9 @@
47
53
  * }
48
54
  * }
49
55
  *
50
- * The hash is reserved for future "the default persona changed; offer the
51
- * user a migration" semantics. We do not auto-upgrade today.
56
+ * The hash tracks the canonical stock persona currently written by top-up. Exact
57
+ * historical stock bodies are auto-migrated to this canonical localized body;
58
+ * user-edited bodies are deliberately left alone.
52
59
  */
53
60
 
54
61
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, writeFileSync } from 'fs';
@@ -231,7 +238,7 @@ function replaceRoleBody(source, body) {
231
238
  return `${match[1]}${String(body || '').trim()}\n`;
232
239
  }
233
240
 
234
- function backfillLocalizedPersonaBody(source, vp) {
241
+ export function backfillLocalizedPersonaBody(source, vp) {
235
242
  const body = roleBodyOf(source).trim();
236
243
  const nextBody = typeof vp.persona === 'string' ? vp.persona.trim() : '';
237
244
  if (!body || !nextBody || body === nextBody) return null;
@@ -301,9 +308,9 @@ export function topUpDefaultVps(libDir = DEFAULT_VP_LIB_DIR) {
301
308
  const inLedger = Object.prototype.hasOwnProperty.call(versions.seeded, vpId);
302
309
 
303
310
  if (onDisk) {
304
- // Already there — never overwrite. Possibly backfill `area` /
305
- // `nameZh`. Each backfill is independent: a role.md with `area`
306
- // already set but no `nameZh` should still get `nameZh`.
311
+ // Already there — preserve user-authored content, but keep shipped stock
312
+ // defaults canonical. Metadata backfills only add missing frontmatter;
313
+ // persona migration only rewrites exact historical stock bodies.
307
314
  skippedExisting.push(vpId);
308
315
  let currentSrc = null;
309
316
  const rolePath = join(libDir, vpId, 'role.md');
@@ -388,6 +395,7 @@ export function topUpDefaultVps(libDir = DEFAULT_VP_LIB_DIR) {
388
395
  if (patched != null && patched !== src) {
389
396
  writeFileSync(rolePath, patched, 'utf-8');
390
397
  currentSrc = patched;
398
+ versions.seeded[vpId] = personaHash(vp.persona);
391
399
  personaBackfilled.push(vpId);
392
400
  }
393
401
  }