docs: rewrite README and fix injector formatting

This commit is contained in:
Youzini-afk
2026-03-23 16:09:31 +08:00
parent 28fdc6d7ea
commit 2ca5106767
3 changed files with 761 additions and 248 deletions

931
README.md

File diff suppressed because it is too large Load Diff

View File

@@ -60,11 +60,11 @@ export function formatInjection(retrievalResult, schema) {
),
};
appendBucket(parts, "当前状态记忆", buckets.state, schema);
appendBucket(parts, "情景事件记忆", buckets.episodic, schema);
appendBucket(parts, "反思与长期锚点", buckets.reflective, schema);
appendBucket(parts, "规则与约束", buckets.rule, schema);
appendBucket(parts, "其他关联记忆", buckets.other, schema);
appendBucket(parts, "当前状态记忆", buckets.state, schema, appended);
appendBucket(parts, "情景事件记忆", buckets.episodic, schema, appended);
appendBucket(parts, "反思与长期锚点", buckets.reflective, schema, appended);
appendBucket(parts, "规则与约束", buckets.rule, schema, appended);
appendBucket(parts, "其他关联记忆", buckets.other, schema, appended);
}
return parts.join("\n");
@@ -82,7 +82,7 @@ function groupByType(nodes) {
return map;
}
function appendBucket(parts, title, nodes, schema) {
function appendBucket(parts, title, nodes, schema, appended) {
if (!nodes || nodes.length === 0) return;
parts.push(`## ${title}`);

58
tests/injector-format.mjs Normal file
View File

@@ -0,0 +1,58 @@
import assert from "node:assert/strict";
import { formatInjection } from "../injector.js";
import { DEFAULT_NODE_SCHEMA } from "../schema.js";
const coreEvent = {
id: "event-1",
type: "event",
fields: {
summary: "艾琳在钟楼发现了地下入口",
participants: "艾琳",
status: "resolved",
},
};
const recalledCharacter = {
id: "char-1",
type: "character",
fields: {
name: "艾琳",
state: "警觉并准备进入地下室",
goal: "调查钟楼秘密",
},
};
const recalledReflection = {
id: "reflection-1",
type: "reflection",
fields: {
insight: "地下入口意味着先前的失踪案与钟楼存在长期关联",
trigger: "钟楼发现暗门",
suggestion: "后续优先追查地下通道与失踪人口名单",
},
};
const text = formatInjection(
{
coreNodes: [coreEvent],
recallNodes: [recalledCharacter, recalledReflection],
groupedRecallNodes: {
state: [recalledCharacter],
episodic: [],
reflective: [recalledReflection],
rule: [],
other: [],
},
},
DEFAULT_NODE_SCHEMA,
);
assert.match(text, /\[Memory - Core\]/);
assert.match(text, /event_table:/);
assert.match(text, /\[Memory - Recalled\]/);
assert.match(text, /## 当前状态记忆/);
assert.match(text, /## 反思与长期锚点/);
assert.match(text, /character_table:/);
assert.match(text, /reflection_table:/);
console.log("injector-format tests passed");