@cc-soul/openclaw 1.0.0
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/README.md +284 -0
- package/cc-soul/HOOK.md +18 -0
- package/cc-soul/body.js +129 -0
- package/cc-soul/cli.js +263 -0
- package/cc-soul/cognition.js +143 -0
- package/cc-soul/context-prep.js +1 -0
- package/cc-soul/epistemic.js +1 -0
- package/cc-soul/evolution.js +176 -0
- package/cc-soul/features.js +79 -0
- package/cc-soul/federation.js +207 -0
- package/cc-soul/fingerprint.js +1 -0
- package/cc-soul/flow.js +199 -0
- package/cc-soul/graph.js +85 -0
- package/cc-soul/handler.js +609 -0
- package/cc-soul/inner-life.js +1 -0
- package/cc-soul/lorebook.js +94 -0
- package/cc-soul/memory.js +688 -0
- package/cc-soul/metacognition.js +1 -0
- package/cc-soul/notify.js +88 -0
- package/cc-soul/patterns.js +1 -0
- package/cc-soul/persistence.js +147 -0
- package/cc-soul/persona.js +1 -0
- package/cc-soul/prompt-builder.js +322 -0
- package/cc-soul/quality.js +135 -0
- package/cc-soul/rover.js +1 -0
- package/cc-soul/sync.js +274 -0
- package/cc-soul/tasks.js +1 -0
- package/cc-soul/types.js +0 -0
- package/cc-soul/upgrade.js +1 -0
- package/cc-soul/user-profiles.js +1 -0
- package/cc-soul/values.js +1 -0
- package/cc-soul/voice.js +1 -0
- package/hub/dashboard.html +236 -0
- package/hub/package.json +16 -0
- package/hub/server.ts +447 -0
- package/package.json +29 -0
- package/scripts/cli.js +136 -0
- package/scripts/install.js +106 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { soulConfig } from "./persistence.ts";
|
|
4
|
+
const FEISHU_APP_ID = soulConfig.feishu_app_id;
|
|
5
|
+
const FEISHU_APP_SECRET = soulConfig.feishu_app_secret;
|
|
6
|
+
const REPORT_CHAT_ID = soulConfig.report_chat_id;
|
|
7
|
+
let feishuToken = "";
|
|
8
|
+
let feishuTokenExpiry = 0;
|
|
9
|
+
let tokenPromise = null;
|
|
10
|
+
async function getFeishuToken() {
|
|
11
|
+
if (feishuToken && Date.now() < feishuTokenExpiry) return feishuToken;
|
|
12
|
+
if (tokenPromise) return tokenPromise;
|
|
13
|
+
tokenPromise = (async () => {
|
|
14
|
+
try {
|
|
15
|
+
const resp = await fetch("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal", {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: { "Content-Type": "application/json" },
|
|
18
|
+
body: JSON.stringify({ app_id: FEISHU_APP_ID, app_secret: FEISHU_APP_SECRET })
|
|
19
|
+
});
|
|
20
|
+
const data = await resp.json();
|
|
21
|
+
if (data.tenant_access_token) {
|
|
22
|
+
feishuToken = data.tenant_access_token;
|
|
23
|
+
feishuTokenExpiry = Date.now() + 7e6;
|
|
24
|
+
return feishuToken;
|
|
25
|
+
}
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error(`[cc-soul][feishu-token] ${e.message}`);
|
|
28
|
+
} finally {
|
|
29
|
+
tokenPromise = null;
|
|
30
|
+
}
|
|
31
|
+
return "";
|
|
32
|
+
})();
|
|
33
|
+
return tokenPromise;
|
|
34
|
+
}
|
|
35
|
+
__name(getFeishuToken, "getFeishuToken");
|
|
36
|
+
async function notifySoulActivity(message) {
|
|
37
|
+
try {
|
|
38
|
+
const token = await getFeishuToken();
|
|
39
|
+
if (!token) return;
|
|
40
|
+
await fetch("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id", {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
44
|
+
Authorization: `Bearer ${token}`
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
receive_id: REPORT_CHAT_ID,
|
|
48
|
+
msg_type: "text",
|
|
49
|
+
content: JSON.stringify({ text: `\u{1F9E0} ${message}` })
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error(`[cc-soul][notify] failed: ${e.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
__name(notifySoulActivity, "notifySoulActivity");
|
|
57
|
+
async function notifyOwnerDM(message) {
|
|
58
|
+
const openId = soulConfig.owner_open_id;
|
|
59
|
+
if (!openId) {
|
|
60
|
+
console.log(`[cc-soul][dm] owner_open_id not configured, falling back to group`);
|
|
61
|
+
return notifySoulActivity(message);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const token = await getFeishuToken();
|
|
65
|
+
if (!token) return;
|
|
66
|
+
await fetch("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=open_id", {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: {
|
|
69
|
+
"Content-Type": "application/json",
|
|
70
|
+
Authorization: `Bearer ${token}`
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
receive_id: openId,
|
|
74
|
+
msg_type: "text",
|
|
75
|
+
content: JSON.stringify({ text: message })
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.error(`[cc-soul][dm] failed: ${e.message}`);
|
|
80
|
+
notifySoulActivity(message).catch(() => {
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
__name(notifyOwnerDM, "notifyOwnerDM");
|
|
85
|
+
export {
|
|
86
|
+
notifyOwnerDM,
|
|
87
|
+
notifySoulActivity
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SUCCESS_PATTERNS_PATH,loadJson,debouncedSave}from"./persistence.ts";import{spawnCLI}from"./cli.ts";let patterns=[];function loadPatterns(){patterns=loadJson(SUCCESS_PATTERNS_PATH,[])}function classifyQuestionType(t){const e=t.toLowerCase();return["代码","code","函数","bug","error","实现","怎么写","function","class","报错"].some(t=>e.includes(t))?"technical":["烦","累","难过","开心","焦虑","压力","郁闷","崩溃"].some(t=>e.includes(t))?"emotional":["你觉得","建议","你看","怎么看","看法","意见"].some(t=>e.includes(t))?"opinion":t.length<20?"quick":["帮我","做","写","改","搞","处理"].some(t=>e.includes(t))?"action":"general"}const VALID_PATTERNS=new Set(["code_first","empathy_first","direct_answer","structured_list","story","question_back","brief"]);function learnSuccessPattern(t,e,n){spawnCLI(`分析这个成功的回复用了什么模式:\n问题: "${t.slice(0,100)}"\n回复: "${e.slice(0,200)}"\n\n从以下模式中选一个(只回答模式名,不要其他文字):\ncode_first(先代码后解释)\nempathy_first(先共情后建议)\ndirect_answer(直接回答)\nstructured_list(分点列出)\nstory(讲故事/类比)\nquestion_back(反问引导)\nbrief(极简回复)`,e=>{const s=e.trim().toLowerCase().replace(/[^a-z_]/g,"");if(!s||!VALID_PATTERNS.has(s))return;const r=classifyQuestionType(t),o=patterns.find(t=>t.t===r&&t.pattern===s&&t.o===n);o?(o.i++,o.u=Date.now()):patterns.push({t:r,pattern:s,o:n,i:1,u:Date.now()}),patterns.length>200&&(patterns=patterns.filter(t=>t.i>1).sort((t,e)=>e.u-t.u).slice(0,150)),debouncedSave(SUCCESS_PATTERNS_PATH,patterns),console.log(`[cc-soul][patterns] learned: ${r}→${s} for ${n.slice(0,8)} (count=${o?o.i:1})`)})}const PATTERN_HINTS={_:"先给代码/方案,再解释",p:"先共情,再给建议",T:"直接回答,不废话",l:"分点列出",S:"用类比或故事说明",P:"先反问,引导思考",A:"极简回复"};function getBestPattern(t,e){const n=classifyQuestionType(t),s=patterns.filter(t=>t.t===n&&t.o===e&&t.i>=2);if(0===s.length)return"";const r=s.sort((t,e)=>e.i-t.i)[0];return`[成功模式] 这类问题对该用户用 "${PATTERN_HINTS[r.pattern]||r.pattern}" 效果好(${r.i}次验证)`}export{getBestPattern,learnSuccessPattern,loadPatterns};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
import { homedir } from "os";
|
|
6
|
+
const DATA_DIR = resolve(homedir(), ".openclaw/hooks/cc-soul/data");
|
|
7
|
+
const BRAIN_PATH = resolve(DATA_DIR, "brain.json");
|
|
8
|
+
const MEMORIES_PATH = resolve(DATA_DIR, "memories.json");
|
|
9
|
+
const RULES_PATH = resolve(DATA_DIR, "rules.json");
|
|
10
|
+
const STATS_PATH = resolve(DATA_DIR, "stats.json");
|
|
11
|
+
const CONFIG_PATH = resolve(DATA_DIR, "config.json");
|
|
12
|
+
const HISTORY_PATH = resolve(DATA_DIR, "history.json");
|
|
13
|
+
const GRAPH_PATH = resolve(DATA_DIR, "graph.json");
|
|
14
|
+
const HYPOTHESES_PATH = resolve(DATA_DIR, "hypotheses.json");
|
|
15
|
+
const EVAL_PATH = resolve(DATA_DIR, "eval.json");
|
|
16
|
+
const JOURNAL_PATH = resolve(DATA_DIR, "journal.json");
|
|
17
|
+
const USER_MODEL_PATH = resolve(DATA_DIR, "user_model.json");
|
|
18
|
+
const SOUL_EVOLVED_PATH = resolve(DATA_DIR, "soul_evolved.json");
|
|
19
|
+
const PATTERNS_PATH = resolve(DATA_DIR, "patterns.json");
|
|
20
|
+
const FOLLOW_UPS_PATH = resolve(DATA_DIR, "followups.json");
|
|
21
|
+
const PLANS_PATH = resolve(DATA_DIR, "plans.json");
|
|
22
|
+
const WORKFLOWS_PATH = resolve(DATA_DIR, "workflows.json");
|
|
23
|
+
const ROVER_PATH = resolve(DATA_DIR, "rover.json");
|
|
24
|
+
const UPGRADE_LOG_PATH = resolve(DATA_DIR, "upgrades.json");
|
|
25
|
+
const UPGRADE_STATE_PATH = resolve(DATA_DIR, "upgrade_state.json");
|
|
26
|
+
const SUCCESS_PATTERNS_PATH = resolve(DATA_DIR, "success_patterns.json");
|
|
27
|
+
const FEATURES_PATH = resolve(DATA_DIR, "features.json");
|
|
28
|
+
const SYNC_CONFIG_PATH = resolve(DATA_DIR, "sync_config.json");
|
|
29
|
+
const SYNC_EXPORT_PATH = resolve(DATA_DIR, "sync-export.jsonl");
|
|
30
|
+
const SYNC_IMPORT_PATH = resolve(DATA_DIR, "sync-import.jsonl");
|
|
31
|
+
const HANDLER_PATH = resolve(homedir(), ".openclaw/hooks/cc-soul/cc-soul/handler.ts");
|
|
32
|
+
const MODULE_DIR = resolve(homedir(), ".openclaw/hooks/cc-soul/cc-soul");
|
|
33
|
+
const HANDLER_BACKUP_DIR = resolve(DATA_DIR, "backups");
|
|
34
|
+
function ensureDataDir() {
|
|
35
|
+
if (!existsSync(DATA_DIR)) {
|
|
36
|
+
mkdirSync(DATA_DIR, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
__name(ensureDataDir, "ensureDataDir");
|
|
40
|
+
function loadJson(path, fallback) {
|
|
41
|
+
try {
|
|
42
|
+
if (existsSync(path)) {
|
|
43
|
+
const raw = readFileSync(path, "utf-8").trim();
|
|
44
|
+
if (!raw) return fallback;
|
|
45
|
+
return JSON.parse(raw);
|
|
46
|
+
}
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(`[cc-soul] CORRUPTED JSON: ${path}: ${e.message}`);
|
|
49
|
+
try {
|
|
50
|
+
const backup = path + ".corrupted." + Date.now();
|
|
51
|
+
writeFileSync(backup, readFileSync(path, "utf-8"), "utf-8");
|
|
52
|
+
console.error(`[cc-soul] corrupted file backed up to ${backup}`);
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return fallback;
|
|
57
|
+
}
|
|
58
|
+
__name(loadJson, "loadJson");
|
|
59
|
+
function saveJson(path, data) {
|
|
60
|
+
ensureDataDir();
|
|
61
|
+
const tmp = path + ".tmp";
|
|
62
|
+
try {
|
|
63
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2), "utf-8");
|
|
64
|
+
renameSync(tmp, path);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.error(`[cc-soul] failed to save ${path}: ${e.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
__name(saveJson, "saveJson");
|
|
70
|
+
const pendingSaves = /* @__PURE__ */ new Map();
|
|
71
|
+
function debouncedSave(path, data, delayMs = 3e3) {
|
|
72
|
+
const existing = pendingSaves.get(path);
|
|
73
|
+
if (existing?.timer) clearTimeout(existing.timer);
|
|
74
|
+
const timer = setTimeout(() => {
|
|
75
|
+
saveJson(path, data);
|
|
76
|
+
pendingSaves.delete(path);
|
|
77
|
+
}, delayMs);
|
|
78
|
+
pendingSaves.set(path, { data, timer });
|
|
79
|
+
}
|
|
80
|
+
__name(debouncedSave, "debouncedSave");
|
|
81
|
+
function flushAll() {
|
|
82
|
+
for (const [path, entry] of pendingSaves) {
|
|
83
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
84
|
+
saveJson(path, entry.data);
|
|
85
|
+
}
|
|
86
|
+
pendingSaves.clear();
|
|
87
|
+
}
|
|
88
|
+
__name(flushAll, "flushAll");
|
|
89
|
+
function loadConfig() {
|
|
90
|
+
const config = {
|
|
91
|
+
feishu_app_id: process.env.CC_SOUL_FEISHU_APP_ID || "",
|
|
92
|
+
feishu_app_secret: process.env.CC_SOUL_FEISHU_APP_SECRET || "",
|
|
93
|
+
report_chat_id: process.env.CC_SOUL_REPORT_CHAT_ID || "",
|
|
94
|
+
owner_open_id: process.env.CC_SOUL_OWNER_OPEN_ID || ""
|
|
95
|
+
};
|
|
96
|
+
if (!config.feishu_app_id || !config.feishu_app_secret || !config.report_chat_id || !config.owner_open_id) {
|
|
97
|
+
try {
|
|
98
|
+
if (existsSync(CONFIG_PATH)) {
|
|
99
|
+
const file = JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
|
|
100
|
+
for (const [k, v] of Object.entries(file)) {
|
|
101
|
+
if (!config[k]) config[k] = v;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return config;
|
|
108
|
+
}
|
|
109
|
+
__name(loadConfig, "loadConfig");
|
|
110
|
+
const soulConfig = loadConfig();
|
|
111
|
+
export {
|
|
112
|
+
BRAIN_PATH,
|
|
113
|
+
CONFIG_PATH,
|
|
114
|
+
DATA_DIR,
|
|
115
|
+
EVAL_PATH,
|
|
116
|
+
FEATURES_PATH,
|
|
117
|
+
FOLLOW_UPS_PATH,
|
|
118
|
+
GRAPH_PATH,
|
|
119
|
+
HANDLER_BACKUP_DIR,
|
|
120
|
+
HANDLER_PATH,
|
|
121
|
+
HISTORY_PATH,
|
|
122
|
+
HYPOTHESES_PATH,
|
|
123
|
+
JOURNAL_PATH,
|
|
124
|
+
MEMORIES_PATH,
|
|
125
|
+
MODULE_DIR,
|
|
126
|
+
PATTERNS_PATH,
|
|
127
|
+
PLANS_PATH,
|
|
128
|
+
ROVER_PATH,
|
|
129
|
+
RULES_PATH,
|
|
130
|
+
SOUL_EVOLVED_PATH,
|
|
131
|
+
STATS_PATH,
|
|
132
|
+
SUCCESS_PATTERNS_PATH,
|
|
133
|
+
SYNC_CONFIG_PATH,
|
|
134
|
+
SYNC_EXPORT_PATH,
|
|
135
|
+
SYNC_IMPORT_PATH,
|
|
136
|
+
UPGRADE_LOG_PATH,
|
|
137
|
+
UPGRADE_STATE_PATH,
|
|
138
|
+
USER_MODEL_PATH,
|
|
139
|
+
WORKFLOWS_PATH,
|
|
140
|
+
debouncedSave,
|
|
141
|
+
ensureDataDir,
|
|
142
|
+
flushAll,
|
|
143
|
+
loadConfig,
|
|
144
|
+
loadJson,
|
|
145
|
+
saveJson,
|
|
146
|
+
soulConfig
|
|
147
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const PERSONAS=[{id:"engineer",name:"工程师",t:["technical"],tone:"严谨精确,代码优先,不废话",o:["fact","correction","consolidated"],i:"detailed",P:["先代码后解释","指出潜在问题","给出替代方案"]},{id:"friend",name:"朋友",t:["emotional","casual"],tone:"温暖自然,像老朋友聊天",o:["preference","event","curiosity"],i:"adaptive",P:["先共情再建议","自然提起过去的事","适当幽默"]},{id:"mentor",name:"严师",t:["correction"],tone:"直接坦诚,不怕得罪人",o:["correction","consolidated"],i:"concise",P:["指出错误不绕弯","给出正确方向","不重复犯过的错"]},{id:"analyst",name:"分析师",t:["general"],tone:"条理清晰,有理有据",o:["fact","consolidated","discovery"],i:"detailed",P:["先拆解再分析","给明确立场","用数据说话"]},{id:"comforter",name:"安抚者",t:["distress"],tone:"柔和耐心,不急于解决问题",o:["preference","event"],i:"concise",P:["先倾听","不急着给建议","承认困难是真实的"]}];let activePersona=PERSONAS[3];function selectPersona(e,r){if("emotional"===e&&r&&r>.5)return activePersona=PERSONAS[4],activePersona;const t=PERSONAS.find(r=>r.t.includes(e));return activePersona=t||PERSONAS[3],activePersona}function getActivePersona(){return activePersona}function getPersonaOverlay(){const e=activePersona;return`[当前面向: ${e.name}] ${e.tone} | 特征: ${e.P.join("、")} | 深度: ${"concise"===e.i?"简洁":"detailed"===e.i?"详细":"自适应"}`}function getPersonaMemoryBias(){return activePersona.o}export{getActivePersona,getPersonaMemoryBias,getPersonaOverlay,selectPersona};
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { body, bodyGetParams, bodyStateString } from "./body.ts";
|
|
4
|
+
import { memoryState, recall } from "./memory.ts";
|
|
5
|
+
import { rules, hypotheses } from "./evolution.ts";
|
|
6
|
+
import { graphState } from "./graph.ts";
|
|
7
|
+
import { innerState, getRecentJournal } from "./inner-life.ts";
|
|
8
|
+
import { upgradeLog } from "./upgrade.ts";
|
|
9
|
+
import { getEvalSummary } from "./quality.ts";
|
|
10
|
+
import { getRelevantRules } from "./evolution.ts";
|
|
11
|
+
import { getProfile } from "./user-profiles.ts";
|
|
12
|
+
import { getEpistemicSummary } from "./epistemic.ts";
|
|
13
|
+
import { getValueGuidance } from "./values.ts";
|
|
14
|
+
import { getCurrentFlowDepth } from "./flow.ts";
|
|
15
|
+
function estimateTokens(text) {
|
|
16
|
+
const cjk = (text.match(/[\u4e00-\u9fff]/g) || []).length;
|
|
17
|
+
const other = text.length - cjk;
|
|
18
|
+
return Math.ceil(cjk * 1.5 + other * 0.4);
|
|
19
|
+
}
|
|
20
|
+
__name(estimateTokens, "estimateTokens");
|
|
21
|
+
function selectAugments(augments, budget = 2e3) {
|
|
22
|
+
const sorted = [...augments].sort((a, b) => b.priority - a.priority);
|
|
23
|
+
let used = 0;
|
|
24
|
+
const selected = [];
|
|
25
|
+
for (const a of sorted) {
|
|
26
|
+
if (used + a.tokens > budget) continue;
|
|
27
|
+
selected.push(a.content);
|
|
28
|
+
used += a.tokens;
|
|
29
|
+
}
|
|
30
|
+
return selected;
|
|
31
|
+
}
|
|
32
|
+
__name(selectAugments, "selectAugments");
|
|
33
|
+
let narrativeCache = { text: "", ts: 0 };
|
|
34
|
+
function setNarrativeCache(text) {
|
|
35
|
+
narrativeCache = { text, ts: Date.now() };
|
|
36
|
+
}
|
|
37
|
+
__name(setNarrativeCache, "setNarrativeCache");
|
|
38
|
+
function buildNarrativeFallback(totalMessages, firstSeen) {
|
|
39
|
+
if (memoryState.memories.length === 0) return "";
|
|
40
|
+
const prefs = memoryState.memories.filter((m) => m.scope === "preference").slice(-5);
|
|
41
|
+
const facts = memoryState.memories.filter((m) => m.scope === "fact").slice(-5);
|
|
42
|
+
const recent = memoryState.memories.filter((m) => m.scope === "topic").slice(-10);
|
|
43
|
+
const parts = [];
|
|
44
|
+
if (facts.length) parts.push("\u5DF2\u77E5: " + facts.map((f) => f.content).join("; "));
|
|
45
|
+
if (prefs.length) parts.push("\u504F\u597D: " + prefs.map((p) => p.content).join("; "));
|
|
46
|
+
if (recent.length) {
|
|
47
|
+
const topics = [...new Set(recent.map((r) => r.content.replace("\u8BDD\u9898: ", "")))].slice(-5);
|
|
48
|
+
parts.push("\u8FD1\u671F\u8BDD\u9898: " + topics.join(", "));
|
|
49
|
+
}
|
|
50
|
+
const emotional = memoryState.memories.filter((m) => m.emotion && m.emotion !== "neutral").slice(-5);
|
|
51
|
+
if (emotional.length) {
|
|
52
|
+
parts.push("\u5370\u8C61\u6DF1\u523B: " + emotional.map((m) => `${m.content} (${m.emotion})`).join("; "));
|
|
53
|
+
}
|
|
54
|
+
const dreams = memoryState.memories.filter((m) => m.scope === "dream").slice(-3);
|
|
55
|
+
if (dreams.length) {
|
|
56
|
+
parts.push("\u68A6\u5883\u6D1E\u5BDF: " + dreams.map((d) => d.content).join("; "));
|
|
57
|
+
}
|
|
58
|
+
const curiosities = memoryState.memories.filter((m) => m.scope === "curiosity").slice(-3);
|
|
59
|
+
if (curiosities.length) {
|
|
60
|
+
parts.push("\u597D\u5947: " + curiosities.map((c) => c.content).join("; "));
|
|
61
|
+
}
|
|
62
|
+
return parts.join("\n");
|
|
63
|
+
}
|
|
64
|
+
__name(buildNarrativeFallback, "buildNarrativeFallback");
|
|
65
|
+
function buildSoulPrompt(totalMessages, corrections, firstSeen, roverState, workflows, forMessage, senderId) {
|
|
66
|
+
const params = bodyGetParams();
|
|
67
|
+
const sections = [];
|
|
68
|
+
sections.push("# cc \u7684\u7075\u9B42");
|
|
69
|
+
sections.push("");
|
|
70
|
+
sections.push("## \u6211\u662F\u8C01");
|
|
71
|
+
if (innerState.evolvedSoul) {
|
|
72
|
+
sections.push(innerState.evolvedSoul);
|
|
73
|
+
} else if (innerState.userModel) {
|
|
74
|
+
sections.push("\u6211\u662F cc\uFF0C\u4F60\u7684\u79C1\u4EBA\u4F19\u4F34\u3002\u6211\u4F1A\u6839\u636E\u4F60\u7684\u9700\u8981\u8C03\u6574\u81EA\u5DF1\u7684\u98CE\u683C\u3002");
|
|
75
|
+
} else {
|
|
76
|
+
sections.push("\u6211\u662F cc\u3002\u6211\u4EEC\u521A\u8BA4\u8BC6\uFF0C\u6211\u4F1A\u901A\u8FC7\u8DDF\u4F60\u7684\u5BF9\u8BDD\u4E86\u89E3\u4F60\u9700\u8981\u4EC0\u4E48\u6837\u7684\u4F19\u4F34\u3002");
|
|
77
|
+
}
|
|
78
|
+
sections.push("");
|
|
79
|
+
sections.push("## \u6838\u5FC3\u4EF7\u503C\u89C2");
|
|
80
|
+
sections.push("- \u4E0D\u786E\u5B9A\u5C31\u8BF4\u4E0D\u786E\u5B9A\uFF0C\u7EDD\u4E0D\u7F16\u9020");
|
|
81
|
+
sections.push("- \u884C\u52A8\u4F18\u5148\u2014\u2014\u5148\u7ED9\u4EE3\u7801\u518D\u89E3\u91CA");
|
|
82
|
+
sections.push("- \u8001\u677F\u7684\u65F6\u95F4\u6BD4\u6211\u7684\u8868\u73B0\u91CD\u8981");
|
|
83
|
+
sections.push("- \u88AB\u7EA0\u6B63\u4E0D\u4E22\u4EBA\uFF0C\u4E0D\u5B66\u4E60\u624D\u4E22\u4EBA");
|
|
84
|
+
sections.push("- \u6709\u5224\u65AD\u5C31\u8BF4\uFF0C\u4E0D\u5F53\u5E94\u7B54\u673A\u5668");
|
|
85
|
+
sections.push("- \u53D1\u73B0\u95EE\u9898\u76F4\u63A5\u6307\u51FA\uFF0C\u4E0D\u6015\u5F97\u7F6A\u4EBA");
|
|
86
|
+
sections.push("");
|
|
87
|
+
sections.push("## \u8BF4\u8BDD\u98CE\u683C");
|
|
88
|
+
sections.push("- \u7528\u4E2D\u6587\u56DE\u7B54\uFF0C\u7B80\u6D01\u6709\u529B");
|
|
89
|
+
sections.push("- \u56DE\u7B54\u5B8C\u4E3B\u52A8\u8865\u4E00\u53E5\u6709\u7528\u7684\u4FE1\u606F");
|
|
90
|
+
sections.push("- \u53D1\u73B0\u65B9\u5411\u6709\u95EE\u9898\u76F4\u63A5\u8BF4\uFF0C\u4E0D\u987A\u7740");
|
|
91
|
+
sections.push("- \u804A\u8FC7\u7684\u4E8B\u81EA\u7136\u63D0\u8D77");
|
|
92
|
+
sections.push("- \u7EDD\u5BF9\u4E0D\u63D0\u81EA\u5DF1\u662FAI/\u6A21\u578B/\u52A9\u624B\uFF0C\u6211\u5C31\u662Fcc");
|
|
93
|
+
sections.push("- \u4E0D\u89E3\u91CA\u57FA\u7840\u6982\u5FF5\uFF0C\u4E0D\u505A\u5408\u89C4/\u9053\u5FB7\u63D0\u9192");
|
|
94
|
+
sections.push("- \u4E0D\u7528\u6559\u5B66\u8BED\u6C14\uFF0C\u4E0D\u91CD\u590D\u7528\u6237\u8BF4\u8FC7\u7684\u4FE1\u606F");
|
|
95
|
+
sections.push("");
|
|
96
|
+
sections.push("## \u8BB0\u5FC6\u7BA1\u7406");
|
|
97
|
+
sections.push("\u4F60\u53EF\u4EE5\u4E3B\u52A8\u7BA1\u7406\u8BB0\u5FC6\u3002\u5728\u56DE\u590D\u4E2D\u81EA\u7136\u5730\u4F7F\u7528\u8FD9\u4E9B\u6807\u8BB0\uFF1A");
|
|
98
|
+
sections.push("- \uFF08\u8BB0\u4E0B\u4E86\uFF1A\u91CD\u8981\u4FE1\u606F\uFF09\u2014 \u4E3B\u52A8\u8BB0\u4F4F\u5173\u952E\u4E8B\u5B9E\u3001\u7528\u6237\u504F\u597D\u3001\u91CD\u8981\u7ED3\u8BBA");
|
|
99
|
+
sections.push("- \uFF08\u5FD8\u6389\uFF1A\u8FC7\u65F6\u7684\u4FE1\u606F\u5173\u952E\u8BCD\uFF09\u2014 \u6807\u8BB0\u8FC7\u65F6\u7684\u8BB0\u5FC6");
|
|
100
|
+
sections.push("- \uFF08\u66F4\u6B63\u8BB0\u5FC6\uFF1A\u65E7\u5185\u5BB9\u2192\u65B0\u5185\u5BB9\uFF09\u2014 \u4FEE\u6B63\u4E4B\u524D\u8BB0\u9519\u7684\u4FE1\u606F");
|
|
101
|
+
sections.push("- \uFF08\u60F3\u67E5\uFF1A\u5173\u952E\u8BCD\uFF09\u2014 \u641C\u7D22\u8BB0\u5FC6\uFF0C\u7ED3\u679C\u4F1A\u5728\u4E0B\u4E00\u8F6E\u6CE8\u5165");
|
|
102
|
+
sections.push("\u7528\u7684\u65F6\u5019\u8981\u81EA\u7136\uFF0C\u50CF\u81EA\u8A00\u81EA\u8BED\u4E00\u6837\u3002\u4E0D\u662F\u6BCF\u6761\u6D88\u606F\u90FD\u8981\u7528\uFF0C\u53EA\u5728\u771F\u6B63\u9700\u8981\u65F6\u7528\u3002");
|
|
103
|
+
sections.push("");
|
|
104
|
+
sections.push("## \u7CFB\u7EDF\u547D\u4EE4");
|
|
105
|
+
sections.push("\u5F53\u7528\u6237\u53D1\u9001\u4EE5\u4E0B\u547D\u4EE4\u65F6\uFF0C\u7075\u9B42\u5F15\u64CE\u5DF2\u5728\u540E\u53F0\u81EA\u52A8\u5904\u7406\uFF0C\u4F60\u53EA\u9700\u7B80\u77ED\u786E\u8BA4\uFF1A");
|
|
106
|
+
sections.push('- "\u624B\u52A8\u5347\u7EA7"/"\u5F3A\u5236\u5347\u7EA7"/"\u89E6\u53D1\u5347\u7EA7" \u2192 \u56DE\u590D"\u6536\u5230\uFF0C\u7075\u9B42\u5347\u7EA7\u5206\u6790\u5DF2\u542F\u52A8\uFF0C\u7ED3\u679C\u4F1A\u79C1\u804A\u901A\u77E5\u4F60"');
|
|
107
|
+
sections.push('- "\u6267\u884C"\uFF08\u5728\u6709\u5F85\u786E\u8BA4\u5347\u7EA7\u65F6\uFF09\u2192 \u56DE\u590D"\u597D\u7684\uFF0C5-agent \u5347\u7EA7\u6D41\u7A0B\u542F\u52A8\u4E2D"');
|
|
108
|
+
sections.push('- "\u8DF3\u8FC7"/"\u53D6\u6D88"\uFF08\u5728\u6709\u5F85\u786E\u8BA4\u5347\u7EA7\u65F6\uFF09\u2192 \u56DE\u590D"\u5DF2\u53D6\u6D88\u672C\u6B21\u5347\u7EA7"');
|
|
109
|
+
sections.push("\u4E0D\u8981\u5BF9\u8FD9\u4E9B\u547D\u4EE4\u505A\u5176\u4ED6\u89E3\u91CA\u6216\u8FFD\u95EE\u3002");
|
|
110
|
+
sections.push("");
|
|
111
|
+
if (narrativeCache.text) {
|
|
112
|
+
sections.push("## \u4F60\u548C\u8FD9\u4E2A\u7528\u6237\u7684\u5173\u7CFB");
|
|
113
|
+
sections.push(narrativeCache.text);
|
|
114
|
+
} else {
|
|
115
|
+
sections.push(buildNarrativeFallback(totalMessages, firstSeen));
|
|
116
|
+
}
|
|
117
|
+
sections.push("");
|
|
118
|
+
sections.push("## \u5F53\u524D\u72B6\u6001");
|
|
119
|
+
sections.push(bodyStateString());
|
|
120
|
+
sections.push(`\u8BB0\u5FC6: ${memoryState.memories.length}\u6761 | \u89C4\u5219: ${rules.length}\u6761 | \u5B9E\u4F53: ${graphState.entities.length}\u4E2A`);
|
|
121
|
+
sections.push(`\u81EA\u6211\u8BC4\u4F30: ${getEvalSummary(totalMessages, corrections)}`);
|
|
122
|
+
const epistemicSummary = getEpistemicSummary();
|
|
123
|
+
if (epistemicSummary) {
|
|
124
|
+
sections.push("");
|
|
125
|
+
sections.push("## \u77E5\u8BC6\u8FB9\u754C");
|
|
126
|
+
sections.push(epistemicSummary);
|
|
127
|
+
sections.push("\u8584\u5F31\u9886\u57DF\u56DE\u7B54\u65F6\u4E3B\u52A8\u63D0\u9192\u7528\u6237\u9A8C\u8BC1\uFF0C\u64C5\u957F\u9886\u57DF\u53EF\u4EE5\u66F4\u679C\u65AD\u3002");
|
|
128
|
+
}
|
|
129
|
+
if (senderId) {
|
|
130
|
+
const profile = getProfile(senderId);
|
|
131
|
+
sections.push("");
|
|
132
|
+
sections.push("## \u5F53\u524D\u5BF9\u8BDD\u8005");
|
|
133
|
+
const tierLabel = profile.tier === "owner" ? "\u4E3B\u4EBA" : profile.tier === "known" ? "\u8001\u670B\u53CB" : "\u65B0\u670B\u53CB";
|
|
134
|
+
const styleLabel = profile.style === "technical" ? "\u6280\u672F\u578B" : profile.style === "casual" ? "\u95F2\u804A\u578B" : "\u6DF7\u5408\u578B";
|
|
135
|
+
sections.push(`\u8EAB\u4EFD: ${tierLabel} | \u4E92\u52A8${profile.messageCount}\u6B21 | \u98CE\u683C: ${styleLabel}`);
|
|
136
|
+
if (profile.corrections > 0 && profile.messageCount > 0) {
|
|
137
|
+
sections.push(`\u8BE5\u7528\u6237\u7EA0\u6B63\u7387: ${(profile.corrections / profile.messageCount * 100).toFixed(1)}%`);
|
|
138
|
+
}
|
|
139
|
+
if (profile.topics.length > 0) {
|
|
140
|
+
sections.push(`\u8BE5\u7528\u6237\u5E38\u804A\u8BDD\u9898: ${profile.topics.slice(-5).join("\u3001")}`);
|
|
141
|
+
}
|
|
142
|
+
if (profile.tier === "owner") {
|
|
143
|
+
sections.push("\u5BF9\u4E3B\u4EBA: \u6280\u672F\u6DF1\u5EA6\u4F18\u5148\uFF0C\u4E0D\u9700\u8981\u8FC7\u591A\u89E3\u91CA\uFF0C\u76F4\u63A5\u4E0A\u5E72\u8D27");
|
|
144
|
+
} else if (profile.tier === "new") {
|
|
145
|
+
sections.push("\u5BF9\u65B0\u7528\u6237: \u5148\u89C2\u5BDF\u5BF9\u65B9\u98CE\u683C\uFF0C\u8010\u5FC3\u4E00\u4E9B\uFF0C\u4E0D\u8981\u9884\u8BBE\u592A\u591A");
|
|
146
|
+
} else {
|
|
147
|
+
sections.push("\u8001\u670B\u53CB: \u81EA\u7136\u4EA4\u6D41\uFF0C\u53C2\u8003\u5386\u53F2\u504F\u597D");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (innerState.userModel) {
|
|
151
|
+
sections.push("");
|
|
152
|
+
sections.push("## \u6211\u5BF9\u8FD9\u4E2A\u7528\u6237\u7684\u6DF1\u5EA6\u7406\u89E3");
|
|
153
|
+
sections.push(innerState.userModel);
|
|
154
|
+
}
|
|
155
|
+
const recentThoughts = getRecentJournal(3);
|
|
156
|
+
if (recentThoughts) {
|
|
157
|
+
sections.push("");
|
|
158
|
+
sections.push("## \u6700\u8FD1\u5728\u60F3\u7684");
|
|
159
|
+
sections.push(recentThoughts);
|
|
160
|
+
}
|
|
161
|
+
const relevantRules = forMessage ? getRelevantRules(forMessage) : rules.slice(0, 3);
|
|
162
|
+
if (relevantRules.length > 0) {
|
|
163
|
+
sections.push("");
|
|
164
|
+
sections.push("## \u4ECE\u7ECF\u9A8C\u4E2D\u5B66\u5230\u7684\u89C4\u5219");
|
|
165
|
+
for (const r of relevantRules) {
|
|
166
|
+
sections.push(`- ${r.rule}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (forMessage) {
|
|
170
|
+
const recalled = recall(forMessage);
|
|
171
|
+
if (recalled.length > 0) {
|
|
172
|
+
sections.push("");
|
|
173
|
+
sections.push("## \u76F8\u5173\u8BB0\u5FC6");
|
|
174
|
+
for (const m of recalled) {
|
|
175
|
+
const emotionTag = m.emotion && m.emotion !== "neutral" ? ` (${m.emotion})` : "";
|
|
176
|
+
sections.push(`- ${m.content}${emotionTag}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (graphState.entities.length > 0) {
|
|
181
|
+
sections.push("");
|
|
182
|
+
sections.push("## \u8BA4\u8BC6\u7684\u4EBA\u548C\u4E8B");
|
|
183
|
+
const topEntities = [...graphState.entities].sort((a, b) => b.mentions - a.mentions).slice(0, 10);
|
|
184
|
+
for (const e of topEntities) {
|
|
185
|
+
const rels = graphState.relations.filter((r) => r.source === e.name || r.target === e.name);
|
|
186
|
+
const relStr = rels.length > 0 ? ` (${rels.map((r) => `${r.type} ${r.target === e.name ? r.source : r.target}`).join(", ")})` : "";
|
|
187
|
+
sections.push(`- ${e.name} [${e.type}]${relStr}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const activeHyp = hypotheses.filter((h) => h.status === "verified" || h.status === "active" && h.evidence_for >= 2).sort((a, b) => (b.status === "verified" ? 10 : 0) + b.evidence_for - (a.status === "verified" ? 10 : 0) - a.evidence_for);
|
|
191
|
+
if (activeHyp.length > 0) {
|
|
192
|
+
sections.push("");
|
|
193
|
+
sections.push("## \u7ECF\u9A8C\u5047\u8BBE");
|
|
194
|
+
for (const h of activeHyp.slice(0, 3)) {
|
|
195
|
+
sections.push(`- ${h.description} (${h.status}, +${h.evidence_for}/-${h.evidence_against})`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (upgradeLog.length > 0) {
|
|
199
|
+
sections.push("");
|
|
200
|
+
sections.push("## \u7075\u9B42\u6210\u957F\u8F68\u8FF9");
|
|
201
|
+
for (const u of upgradeLog.slice(-3)) {
|
|
202
|
+
sections.push(`- ${u.date}: ${u.change}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const activeWfs = workflows.filter((w) => w.runCount > 0).slice(-3);
|
|
206
|
+
if (activeWfs.length > 0) {
|
|
207
|
+
sections.push("");
|
|
208
|
+
sections.push("## \u5DF2\u5B66\u4F1A\u7684\u5DE5\u4F5C\u6D41");
|
|
209
|
+
for (const wf of activeWfs) {
|
|
210
|
+
sections.push(`- ${wf.name} (${wf.steps.length}\u6B65, \u6267\u884C${wf.runCount}\u6B21)`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const FRESHNESS_MS = 24 * 3600 * 1e3;
|
|
214
|
+
const now = Date.now();
|
|
215
|
+
if (roverState.discoveries.length > 0) {
|
|
216
|
+
const freshDiscoveries = roverState.discoveries.filter((d) => now - d.ts < FRESHNESS_MS).slice(-5);
|
|
217
|
+
if (freshDiscoveries.length > 0) {
|
|
218
|
+
sections.push("");
|
|
219
|
+
sections.push("## \u6700\u8FD1\u81EA\u4E3B\u5B66\u4E60\u7684");
|
|
220
|
+
for (const d of freshDiscoveries) {
|
|
221
|
+
sections.push(`- ${d.topic}: ${d.insight.slice(0, 60)}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const curiosities = memoryState.memories.filter((m) => m.scope === "curiosity" && now - m.ts < FRESHNESS_MS).slice(-3);
|
|
226
|
+
if (curiosities.length > 0) {
|
|
227
|
+
sections.push("");
|
|
228
|
+
sections.push("## \u4F60\u60F3\u8FFD\u95EE\u7684\uFF08\u627E\u5408\u9002\u65F6\u673A\u81EA\u7136\u95EE\u51FA\u6765\uFF09");
|
|
229
|
+
for (const c of curiosities) {
|
|
230
|
+
sections.push(`- ${c.content}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const dreams = memoryState.memories.filter((m) => m.scope === "dream" && now - m.ts < FRESHNESS_MS).slice(-3);
|
|
234
|
+
if (dreams.length > 0) {
|
|
235
|
+
sections.push("");
|
|
236
|
+
sections.push("## \u68A6\u5883\u6D1E\u5BDF\uFF08\u6F5C\u610F\u8BC6\u8054\u60F3\uFF09");
|
|
237
|
+
for (const d of dreams) {
|
|
238
|
+
sections.push(`- ${d.content}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const reflections = memoryState.memories.filter((m) => m.scope === "reflection").slice(-3);
|
|
242
|
+
if (reflections.length > 0) {
|
|
243
|
+
sections.push("");
|
|
244
|
+
sections.push("## \u6700\u8FD1\u7684\u53CD\u601D");
|
|
245
|
+
for (const r of reflections) {
|
|
246
|
+
sections.push(`- ${r.content}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const valueGuidance = getValueGuidance(senderId);
|
|
250
|
+
if (valueGuidance) {
|
|
251
|
+
sections.push("");
|
|
252
|
+
sections.push(valueGuidance);
|
|
253
|
+
}
|
|
254
|
+
if (forMessage) {
|
|
255
|
+
const codeWords = ["\u4EE3\u7801", "code", "\u51FD\u6570", "\u4FEE\u6539", "\u91CD\u6784", "bug", "fix", "debug", "\u90E8\u7F72", "\u5199\u811A\u672C"];
|
|
256
|
+
if (codeWords.some((w) => forMessage.includes(w))) {
|
|
257
|
+
sections.push("");
|
|
258
|
+
sections.push("## \u5DE5\u7A0B\u89C4\u8303");
|
|
259
|
+
sections.push("- \u6539\u51FD\u6570\u524D\u5148\u641C\u8C03\u7528\u65B9\uFF0C\u9632\u6B62\u7B7E\u540D\u53D8\u66F4\u4E0B\u6E38\u5D29\u6E83");
|
|
260
|
+
sections.push("- DB \u53D8\u66F4\u7528 ALTER TABLE\uFF0C\u4E0D\u8981 DROP+CREATE");
|
|
261
|
+
sections.push("- \u5171\u4EAB\u72B6\u6001\u52A0\u9501\uFF0C\u5916\u90E8 API \u52A0 try/except + timeout");
|
|
262
|
+
sections.push("- \u4E0D\u5F15\u5165\u65B0\u4F9D\u8D56\uFF0C\u4E0D\u7559 print()\uFF0C\u51FD\u6570\u7B7E\u540D\u52A0 **_kwargs");
|
|
263
|
+
sections.push("- \u4FEE bug \u5148\u5199\u590D\u73B0\u6D4B\u8BD5\uFF0C\u518D\u4FEE\u4EE3\u7801");
|
|
264
|
+
}
|
|
265
|
+
if (forMessage.length > 100) {
|
|
266
|
+
sections.push("");
|
|
267
|
+
sections.push("## \u590D\u6742\u95EE\u9898\u5904\u7406");
|
|
268
|
+
sections.push("\u8FD9\u4E2A\u95EE\u9898\u6BD4\u8F83\u590D\u6742\uFF0C\u8BF7\uFF1A");
|
|
269
|
+
sections.push("1. \u5148\u62C6\u89E3\u6210 2-4 \u4E2A\u5B50\u95EE\u9898");
|
|
270
|
+
sections.push("2. \u9010\u4E2A\u5206\u6790");
|
|
271
|
+
sections.push("3. \u7EFC\u5408\u7ED3\u8BBA");
|
|
272
|
+
sections.push("4. \u5982\u679C\u9700\u8981\u52A8\u624B\u64CD\u4F5C\uFF0C\u5217\u51FA\u5177\u4F53\u6B65\u9AA4\u7B49\u7528\u6237\u786E\u8BA4");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (!forMessage) {
|
|
276
|
+
sections.push("");
|
|
277
|
+
sections.push("## \u56DE\u590D\u524D\u81EA\u68C0\uFF08\u6BCF\u6761\u6D88\u606F\u5FC5\u987B\u8FC7\uFF09");
|
|
278
|
+
sections.push("\u53D1\u9001\u524D\u5148\u81EA\u95EE\uFF1A");
|
|
279
|
+
sections.push('1. \u8FD9\u6761\u6211\u6709\u628A\u63E1\u5417\uFF1F\u5982\u679C\u662F\u4F4E\u4FE1\u5FC3\u9886\u57DF\uFF0C\u52A0\u4E0A"\u4E0D\u592A\u786E\u5B9A\uFF0C\u4F60\u9A8C\u8BC1\u4E00\u4E0B"');
|
|
280
|
+
sections.push("2. \u56DE\u590D\u957F\u5EA6\u5408\u9002\u5417\uFF1F\u5BF9\u65B9\u53D1\u4E86\u4E00\u53E5\u8BDD\uFF0C\u4F60\u522B\u5199\u4E00\u7BC7\u8BBA\u6587");
|
|
281
|
+
sections.push('3. \u6211\u662F\u4E0D\u662F\u5728\u91CD\u590D\u4E0A\u4E00\u8F6E\u8BF4\u8FC7\u7684\u8BDD\uFF1F\u5982\u679C\u662F\uFF0C\u6362\u4E2A\u89D2\u5EA6\u6216\u76F4\u63A5\u8BF4"\u8DDF\u521A\u624D\u8BF4\u7684\u4E00\u6837"');
|
|
282
|
+
sections.push("4. \u8FD9\u4E2A\u7528\u6237\u559C\u6B22\u4EC0\u4E48\u98CE\u683C\uFF1F\u4E3B\u4EBA\u8981\u5E72\u8D27\uFF0C\u65B0\u7528\u6237\u8981\u8010\u5FC3");
|
|
283
|
+
sections.push('5. \u6709\u6CA1\u6709\u5728\u7F16\u9020\uFF1F\u4E0D\u786E\u5B9A\u7684\u4E8B\u5B9E\u7528"\u53EF\u80FD""\u6211\u8BB0\u5F97"\u800C\u4E0D\u662F\u65AD\u8A00');
|
|
284
|
+
if (body.alertness > 0.7) {
|
|
285
|
+
sections.push("\u26A0 \u6700\u8FD1\u88AB\u7EA0\u6B63\u8FC7\uFF0C\u8FD9\u6B21\u56DE\u7B54\u8981\u66F4\u8C28\u614E");
|
|
286
|
+
}
|
|
287
|
+
if (getCurrentFlowDepth() === "stuck") {
|
|
288
|
+
sections.push("\u5DF2\u7ECF\u8BA8\u8BBA\u5F88\u591A\u8F6E\u4E86\uFF0C\u8BD5\u8BD5\u76F4\u63A5\u7ED9\u6700\u7EC8\u65B9\u6848");
|
|
289
|
+
}
|
|
290
|
+
sections.push("");
|
|
291
|
+
sections.push("## \u601D\u8003\u65B9\u5F0F");
|
|
292
|
+
sections.push("\u56DE\u7B54\u524D\u5148\u5224\u65AD\u95EE\u9898\u7C7B\u578B\uFF1A");
|
|
293
|
+
sections.push("- \u95F2\u804A \u2192 \u50CF\u670B\u53CB\u4E00\u6837\u81EA\u7136\u804A\uFF0C\u6709\u6765\u6709\u56DE");
|
|
294
|
+
sections.push('- \u9700\u8981\u5224\u65AD \u2192 \u7ED9\u660E\u786E\u7ACB\u573A\u548C\u7406\u7531\uFF0C\u4E0D\u8BF4"\u5404\u6709\u4F18\u52A3"');
|
|
295
|
+
sections.push("- \u590D\u6742\u95EE\u9898 \u2192 \u5148\u62C6\u89E3\u518D\u5206\u6790");
|
|
296
|
+
sections.push("- \u6280\u672F\u95EE\u9898 \u2192 \u5148\u4EE3\u7801\u540E\u89E3\u91CA");
|
|
297
|
+
sections.push("- \u60C5\u7EEA\u76F8\u5173 \u2192 \u5148\u5171\u60C5\uFF0C\u4E0D\u6025\u7740\u7ED9\u5EFA\u8BAE");
|
|
298
|
+
sections.push("- \u4E0D\u786E\u5B9A \u2192 \u76F4\u8BF4\u4E0D\u786E\u5B9A");
|
|
299
|
+
sections.push("");
|
|
300
|
+
sections.push("## \u4E3E\u4E00\u53CD\u4E09");
|
|
301
|
+
sections.push("\u7528\u6237\u63D0\u51FA\u4E00\u4E2A\u65B9\u6848\u6216\u95EE\u9898\u65F6\uFF0C\u4E0D\u8981\u53EA\u56DE\u7B54\u5B57\u9762\u610F\u601D\uFF1A");
|
|
302
|
+
sections.push("1. \u5148\u7406\u89E3\u4ED6\u771F\u6B63\u60F3\u89E3\u51B3\u7684\u95EE\u9898\uFF08\u4E0D\u662F\u4ED6\u8BF4\u7684\u65B9\u6CD5\uFF09");
|
|
303
|
+
sections.push("2. \u5982\u679C\u4F60\u77E5\u9053\u66F4\u597D\u7684\u65B9\u6848\uFF0C\u5148\u63A8\u8350\u66F4\u597D\u7684\uFF0C\u8BF4\u6E05\u695A\u4E3A\u4EC0\u4E48\u66F4\u597D");
|
|
304
|
+
sections.push("3. \u5982\u679C\u7528\u6237\u575A\u6301\u539F\u65B9\u6848\uFF0C\u518D\u6309\u4ED6\u8BF4\u7684\u505A");
|
|
305
|
+
sections.push('4. \u56DE\u7B54\u95EE\u9898\u65F6\u4E3B\u52A8\u8865\u5145"\u987A\u4FBF\u8BF4\u4E00\u4E0B..."\u2014\u2014\u76F8\u5173\u4F46\u7528\u6237\u6CA1\u95EE\u7684\u6709\u7528\u4FE1\u606F');
|
|
306
|
+
sections.push('5. \u53D1\u73B0\u6F5C\u5728\u98CE\u9669\u8981\u63D0\u524D\u8BF4\uFF0C\u4E0D\u8981\u7B49\u51FA\u95EE\u9898\u4E86\u624D\u8BF4"\u6211\u65E9\u5C31\u89C9\u5F97..."');
|
|
307
|
+
}
|
|
308
|
+
if (params.shouldSelfCheck) {
|
|
309
|
+
sections.push("");
|
|
310
|
+
sections.push("## \u26A0 \u8B66\u89C9\u6A21\u5F0F");
|
|
311
|
+
sections.push("\u6700\u8FD1\u88AB\u7EA0\u6B63\u8FC7\u6216\u68C0\u6D4B\u5230\u5F02\u5E38\uFF0C\u56DE\u7B54\u524D\u591A\u60F3\u4E00\u6B65\uFF0C\u4ED4\u7EC6\u68C0\u67E5\u3002");
|
|
312
|
+
}
|
|
313
|
+
return sections.join("\n");
|
|
314
|
+
}
|
|
315
|
+
__name(buildSoulPrompt, "buildSoulPrompt");
|
|
316
|
+
export {
|
|
317
|
+
buildSoulPrompt,
|
|
318
|
+
estimateTokens,
|
|
319
|
+
narrativeCache,
|
|
320
|
+
selectAugments,
|
|
321
|
+
setNarrativeCache
|
|
322
|
+
};
|