Prompt Library.
← Back to the library

Resource details · Memory experiments

Layered memory: sources, corrections and withdrawal

Follow fixed fictional messages as preferences are recorded, corrected and withdrawn, then inspect their source chain in a layered sphere.

Titles, introductions and guides are translated. Copyable resources, examples and licences retain their original language. Code is displayed only; this page does not execute it or call AI.

Resource details

For readers with some JavaScript experience who want to understand conversation-memory boundaries. This is an offline experimental library with synthetic examples, not a connected WeChat plugin, model, account or real growth system.

Before you start

Platforms
Windows · macOS · Linux
Content updated
  • Prepare Node.js 22 or newer and a text editor. Tested here with v24.19.0; version 22 has not been tested. No npm install, account or API key is needed.
  • Download the complete lab archive and extract it to a normal folder. Keep demo.mjs and both modules together.
node demo.mjs

Run inside the extracted lab folder. The command uses synthetic data only, without networking or reading or writing private files.

Common pitfalls

  • Copying demo.mjs alone is insufficient: it imports radial-memory-core.mjs and typed-extractor.mjs from the same package.
  • State is calculated only within this process. Encrypted storage for this schema, restart recovery and real platform integration are not implemented.
Official setup guide ↗

Complete resource

// 本网站作者原创 · 包子海梦. Deterministic synthetic data only.
import { createHash } from 'node:crypto';
import { pathToFileURL } from 'node:url';
import { extractTypedFacts } from './typed-extractor.mjs';
import { createRadialMemory, applyRadialFacts, recallRadialMemory, projectRadialMemory } from './radial-memory-core.mjs';

export function buildDemoFrames() {
  const scopeHash = createHash('sha256').update('synthetic-public-memory-demo-v1').digest('hex');
  const envelope = { companionId: 'local-deepseek', scopeHash };
  const baseAt = Date.UTC(2026, 9, 28, 0);
  let state = createRadialMemory({ ...envelope, fictionalBackground: ['合成角色:喜欢安静阅读'] });
  const frames = [];
  const addFrame = (id, title, message) => frames.push({ id, title, message,
    projection: projectRadialMemory(state, envelope),
    recall: recallRadialMemory(state, { ...envelope, query: '你记住了什么?', maxChars: 240 }) });
  const applyTyped = segments => {
    const facts = extractTypedFacts(segments);
    const result = applyRadialFacts(state, { ...envelope, facts });
    if (result.results.some(item => item.outcome === 'rejected')) throw Error('synthetic_demo_rejected');
    state = result.state;
  };
  const segment = (id, text, offset) => ({ messageId: `synthetic-demo-${id}`, itemIndex: 0, kind: 'typed', text, at: baseAt + offset });

  addFrame('initial', '初始:设定与真实相处分开', '尚未输入用户偏好;角色设定是合成内容');
  applyTyped([segment('cake-like', '我喜欢草莓蛋糕', 1), segment('coriander-dislike', '我不喜欢香菜', 2)]);
  addFrame('remember', '记住:保存明确偏好与来源', '我喜欢草莓蛋糕 / 我不喜欢香菜');
  applyTyped([segment('cake-correction', '我现在不喜欢草莓蛋糕了', 3)]);
  addFrame('correct', '改口:当前事实替换,来源链保留', '我现在不喜欢草莓蛋糕了');
  applyTyped([segment('coriander-withdrawal', '忘记我不喜欢香菜', 4)]);
  addFrame('retract', '撤回:移除派生详情,保留去重墓碑', '忘记我不喜欢香菜');
  return { schema: 'xiaobu-radial-memory-demo-frames-v1', synthetic: true,
    author: '包子海梦', attribution: '本网站作者原创 · 包子海梦',
    notice: '全部为固定合成演示数据;不是任何真实用户、微信账号或聊天记忆。', frames };
}

if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
  console.log(JSON.stringify(buildDemoFrames(), null, 2));

How to use it

Explore the four-stage sphere, then run the same fixed messages to distinguish fictional background, current preferences and earlier sources.

  1. Download the complete folder

    Use the complete lab download below and retain its modules, demo, tests and LICENSE.txt after extraction. The code shown is the package’s demo.mjs entry, not a standalone file.

  2. Run the fixed synthetic demo

    Open a terminal in that folder and run node demo.mjs. It prints JSON for four fixed stages, without starting a bot or connecting WeChat or a model.

  3. Inspect correction and withdrawal

    First record liking strawberry cake and disliking coriander, then change the cake preference to dislike and withdraw the coriander preference. In the sphere, the earlier cake source is superseded, coriander details are removed and a deduplication tombstone remains.

Save as
demo.mjs
Environment
Node.js 22+; Node built-in modules only, with no additional packages.
Dependencies and costs
No cloud API fees or dedicated GPU are required. You supply the device and electricity.

Command

node demo.mjs

Expected output

initial → remember → correct → retract
{"synthetic":true,"frames":[...]}

Local verification

2026-10-28 · Node.js v24.19.0

Local demonstration and automated checks with fixed synthetic data. See VALIDATION.txt in the lab for the exact scope; this is not production integration or a security audit.

Suitable uses

  • Learn source-linked explicit preferences and corrections
  • Study withdrawal, replay deduplication and bounded recall

Before using it

  • Recognizes a small set of explicit Chinese preference patterns, not arbitrary language or a general memory extractor.
  • Quotes, webpages, images and speech transcripts do not automatically become explicit user preferences. A real application must verify provenance and authorization.
  • Withdrawal removes derived details while retaining a bounded deduplication tombstone. It does not erase external logs, backups or messages already sent.
  • State is calculated only within this process. Encrypted storage for this schema, restart recovery and real platform integration are not implemented.
  • No promise of perfect memory or measured token savings. The sphere illustrates data relationships, not a brain or a model’s internal structure.

Authors and sources

Attribution
Original work by this website’s author · 包子海梦
Authors and sources
包子海梦
Licence checked
2026-10-28

Notices and modifications

An original offline experimental library dated 2026-10-28. The download contains no WeChat integration, models, user data or third-party runtimes.

Complete licence

MIT

MIT License

Copyright (c) 2026 包子海梦

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Verification scope

Offline experimental library · checks included

Provides demonstrations and automated checks with fixed synthetic data. No WeChat, model or real account is connected; encrypted persistence for this schema and real growth are not implemented.

2026-10-28 Node.js v24.19.0

View the verification record →