dsh-wechat-access 0.0.0-stage → 0.0.2

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/LICENSE +675 -0
  3. package/README.md +278 -2
  4. package/cordis.patch.yml +5 -0
  5. package/examples/config.example.json +98 -0
  6. package/index.mjs +123 -0
  7. package/lib/access.mjs +131 -0
  8. package/lib/anysearch.mjs +143 -0
  9. package/lib/capabilities.mjs +312 -0
  10. package/lib/client.js +2532 -0
  11. package/lib/config.mjs +509 -0
  12. package/lib/emotion-store.mjs +352 -0
  13. package/lib/emotion.mjs +428 -0
  14. package/lib/endocrine/LICENSE +21 -0
  15. package/lib/endocrine/README.md +39 -0
  16. package/lib/endocrine/diseases.js +791 -0
  17. package/lib/endocrine/engine.mjs +131 -0
  18. package/lib/endocrine/store.mjs +253 -0
  19. package/lib/endocrine/upstream.mjs +1230 -0
  20. package/lib/group-gate.mjs +305 -0
  21. package/lib/imagegen.mjs +360 -0
  22. package/lib/lock.mjs +204 -0
  23. package/lib/meme-classify.mjs +190 -0
  24. package/lib/memes.mjs +442 -0
  25. package/lib/memory.mjs +437 -0
  26. package/lib/normalize.mjs +230 -0
  27. package/lib/parser.mjs +602 -0
  28. package/lib/reply-settled.mjs +130 -0
  29. package/lib/runtime.mjs +3367 -0
  30. package/lib/startup.mjs +70 -0
  31. package/lib/steam-binding.mjs +144 -0
  32. package/lib/steam.mjs +334 -0
  33. package/lib/store.mjs +259 -0
  34. package/lib/thoughts.mjs +149 -0
  35. package/lib/time-context.mjs +182 -0
  36. package/lib/tools.mjs +583 -0
  37. package/lib/ui.mjs +997 -0
  38. package/lib/util.mjs +489 -0
  39. package/lib/virtual-life-generate.mjs +421 -0
  40. package/lib/virtual-life.mjs +971 -0
  41. package/lib/weather.mjs +172 -0
  42. package/lib/wechat-client.mjs +476 -0
  43. package/lib/wechat-events.mjs +269 -0
  44. package/locale/zh.json +6 -0
  45. package/package.json +77 -4
@@ -0,0 +1,428 @@
1
+ /**
2
+ * Emotional state and relationship progression.
3
+ *
4
+ * Distilled from asakiyoshi/EmotionAI-Pro (v4.0.0), which fuses EmotionAI's
5
+ * 8-dimension emotion model with FavourPro's favor/intimacy pair. The parts kept
6
+ * here are the ones that change what she SAYS; the parts dropped are the ones that
7
+ * only exist to serve a command interface (/好感排行, /缓存统计, /备份数据 …),
8
+ * because this plugin has no command surface — the panel and tools replace it.
9
+ *
10
+ * Three mechanisms carry almost all of the value, and each replaces a specific
11
+ * way a "好感度" feature usually goes wrong:
12
+ *
13
+ * - LAG BANDS on stage transitions. A raw threshold makes the stage flicker when
14
+ * the score sits on the boundary ("深化期→初识期→深化期" within three
15
+ * messages). Rising uses the nominal threshold, falling uses threshold−5, so a
16
+ * stage once reached needs a real drop to be lost.
17
+ *
18
+ * - TRANSITION PROTECTION. When a stage is newly reached the composite score is
19
+ * pinned to at least the previous peak, and intimacy gains are multiplied
20
+ * (×4.0 in 初识期 … ×1.0 in 共生期). Without this the score visibly jumps
21
+ * backwards right after advancing, which reads as the relationship resetting.
22
+ *
23
+ * - NEGATIVE FAVOR IS A SEPARATE REGIME, not a low positive one. Below zero the
24
+ * intimacy weight collapses to 0 and the stage names switch to 冷淡/反感/敌对.
25
+ * Averaging a hostile relationship into the same four-stage ladder would let
26
+ * intimacy keep it alive after favor has gone.
27
+ *
28
+ * Everything here is pure arithmetic over a plain state object: no timers, no I/O,
29
+ * no model calls. Persistence and the model-facing text live in emotion-store.mjs
30
+ * and the runtime.
31
+ */
32
+
33
+ export const EMOTION_DIMENSIONS = [
34
+ 'joy', 'trust', 'fear', 'surprise', 'sadness', 'disgust', 'anger', 'anticipation',
35
+ ];
36
+
37
+ export const EMOTION_LABELS = {
38
+ joy: '喜悦', trust: '信任', fear: '恐惧', surprise: '惊讶',
39
+ sadness: '悲伤', disgust: '厌恶', anger: '愤怒', anticipation: '期待',
40
+ };
41
+
42
+ export const FAVOR_MIN = -100;
43
+ export const FAVOR_MAX = 100;
44
+ export const INTIMACY_MIN = 0;
45
+ export const INTIMACY_MAX = 100;
46
+ export const EMOTION_MIN = 0;
47
+ export const EMOTION_MAX = 100;
48
+
49
+ /** Per-turn change caps. Favor/intimacy move slower than single emotions. */
50
+ export const MAX_DELTA_RELATION = 5;
51
+ export const MAX_DELTA_EMOTION = 3;
52
+
53
+ /**
54
+ * Stage ladder. `key` is stable for storage; `name` is what the panel shows.
55
+ * `compositeThreshold` is the rising threshold; falling uses threshold − LAG.
56
+ */
57
+ export const STAGES = [
58
+ {
59
+ key: 'INITIAL',
60
+ name: '初识期',
61
+ description: '好感驱动,建立吸引',
62
+ favorWeight: 0.7,
63
+ intimacyWeight: 0.3,
64
+ compositeThreshold: 25,
65
+ transitionBuffer: 3,
66
+ intimacyBoostFactor: 4.0,
67
+ advice: '多展示个人魅力,建立良好第一印象。通过有趣的话题和积极的互动提升好感度。',
68
+ },
69
+ {
70
+ key: 'DEEPENING',
71
+ name: '深化期',
72
+ description: '互动平衡,共同成长',
73
+ favorWeight: 0.5,
74
+ intimacyWeight: 0.5,
75
+ compositeThreshold: 55,
76
+ transitionBuffer: 5,
77
+ intimacyBoostFactor: 3.6,
78
+ advice: '分享更多个人经历和情感,建立信任基础。共同经历和深度交流是关键。',
79
+ },
80
+ {
81
+ key: 'COMMITMENT',
82
+ name: '承诺期',
83
+ description: '亲密主导,根基稳固',
84
+ favorWeight: 0.3,
85
+ intimacyWeight: 0.7,
86
+ compositeThreshold: 80,
87
+ transitionBuffer: 7,
88
+ intimacyBoostFactor: 3.0,
89
+ advice: '巩固信任和默契,在困难时刻相互支持。关系的深度比广度更重要。',
90
+ },
91
+ {
92
+ key: 'SYMBIOSIS',
93
+ name: '共生期',
94
+ description: '完全融合,不分彼此',
95
+ favorWeight: 0.5,
96
+ intimacyWeight: 0.5,
97
+ compositeThreshold: 95,
98
+ transitionBuffer: 10,
99
+ intimacyBoostFactor: 1.0,
100
+ advice: '维持情感的深度连接,共同成长和创造美好回忆。',
101
+ },
102
+ ];
103
+
104
+ const STAGE_BY_KEY = new Map(STAGES.map((s) => [s.key, s]));
105
+ const STAGE_INDEX = new Map(STAGES.map((s, i) => [s.key, i]));
106
+
107
+ /** How far the score may fall below a threshold before the stage is lost. */
108
+ export const STAGE_LAG = 5;
109
+
110
+ /** Negative-favor regimes, checked in order from mildest. */
111
+ export const NEGATIVE_REGIMES = [
112
+ { key: 'COLD', name: '冷淡期', min: -30, description: '关系冷淡,需要修复', advice: '需要真诚道歉和积极行动来修复关系,避免进一步恶化。' },
113
+ { key: 'AVERSE', name: '反感期', min: -70, description: '存在反感情绪', advice: '需要时间和耐心来缓解负面情绪,避免直接冲突。' },
114
+ { key: 'HOSTILE', name: '敌对期', min: -100, description: '关系敌对', advice: '关系极度紧张,需要保持距离或寻求第三方调解。' },
115
+ ];
116
+
117
+ /** A brand-new acquaintance. Favor 0 / intimacy 0 lands in 初识期. */
118
+ export function createEmotionState(userKey = '') {
119
+ const emotions = {};
120
+ for (const dimension of EMOTION_DIMENSIONS) emotions[dimension] = 0;
121
+ return {
122
+ version: 1,
123
+ userKey: String(userKey ?? ''),
124
+ favor: 0,
125
+ intimacy: 0,
126
+ emotions,
127
+ // Free-text labels the model writes and later reads back.
128
+ attitude: '中立',
129
+ relationship: '陌生人',
130
+ // Bookkeeping used by the stage maths.
131
+ stage: 'INITIAL',
132
+ previousComposite: 0,
133
+ transitionPeak: 0,
134
+ totalTurns: 0,
135
+ positiveTurns: 0,
136
+ negativeTurns: 0,
137
+ lastInteractionAt: 0,
138
+ lastUpdatedAt: 0,
139
+ // Important moments, newest last. Bounded.
140
+ memories: [],
141
+ };
142
+ }
143
+
144
+ export function clamp(value, min, max) {
145
+ const n = Number(value);
146
+ if (!Number.isFinite(n)) return min;
147
+ return Math.min(max, Math.max(min, n));
148
+ }
149
+
150
+ /** Coerce a possibly-corrupt persisted state into a valid one. */
151
+ export function normalizeEmotionState(raw, userKey = '') {
152
+ const base = createEmotionState(userKey);
153
+ if (!raw || typeof raw !== 'object') return base;
154
+ const state = {
155
+ ...base,
156
+ ...raw,
157
+ userKey: String(raw.userKey ?? userKey ?? ''),
158
+ favor: Math.round(clamp(raw.favor ?? 0, FAVOR_MIN, FAVOR_MAX)),
159
+ intimacy: Math.round(clamp(raw.intimacy ?? 0, INTIMACY_MIN, INTIMACY_MAX)),
160
+ emotions: { ...base.emotions },
161
+ memories: Array.isArray(raw.memories) ? raw.memories.slice(-40) : [],
162
+ totalTurns: Math.max(0, Math.round(Number(raw.totalTurns) || 0)),
163
+ positiveTurns: Math.max(0, Math.round(Number(raw.positiveTurns) || 0)),
164
+ negativeTurns: Math.max(0, Math.round(Number(raw.negativeTurns) || 0)),
165
+ };
166
+ for (const dimension of EMOTION_DIMENSIONS) {
167
+ state.emotions[dimension] = Math.round(clamp(raw.emotions?.[dimension] ?? 0, EMOTION_MIN, EMOTION_MAX));
168
+ }
169
+ state.attitude = String(raw.attitude ?? '中立').slice(0, 40) || '中立';
170
+ state.relationship = String(raw.relationship ?? '陌生人').slice(0, 60) || '陌生人';
171
+ state.stage = STAGE_BY_KEY.has(raw.stage) ? raw.stage : 'INITIAL';
172
+ state.previousComposite = Number.isFinite(Number(raw.previousComposite)) ? Number(raw.previousComposite) : 0;
173
+ state.transitionPeak = Number.isFinite(Number(raw.transitionPeak)) ? Number(raw.transitionPeak) : 0;
174
+ state.lastInteractionAt = Number(raw.lastInteractionAt) || 0;
175
+ state.lastUpdatedAt = Number(raw.lastUpdatedAt) || 0;
176
+ return state;
177
+ }
178
+
179
+ /** Weighted favor/intimacy score for the CURRENT stage. */
180
+ export function rawComposite(state, stageKey = state.stage) {
181
+ if (state.favor < 0) return state.favor;
182
+ const config = STAGE_BY_KEY.get(stageKey) ?? STAGES[0];
183
+ return state.favor * config.favorWeight + state.intimacy * config.intimacyWeight;
184
+ }
185
+
186
+ /**
187
+ * Stage for a score, with the lag band applied.
188
+ *
189
+ * `previousKey` decides which threshold is used: advancing needs the nominal
190
+ * value, falling needs nominal − LAG. That asymmetry is the whole point — a stage
191
+ * that was just reached should not be lost to a rounding error.
192
+ */
193
+ export function stageForScore(score, previousKey = 'INITIAL') {
194
+ if (score < 0) return previousKey;
195
+ let rawTarget = 'INITIAL';
196
+ for (const stage of STAGES) if (score >= stage.compositeThreshold) rawTarget = stage.key;
197
+ const targetIndex = STAGE_INDEX.get(rawTarget) ?? 0;
198
+ const previousIndex = STAGE_INDEX.get(previousKey) ?? 0;
199
+
200
+ // Advancing needs the target's full threshold.
201
+ if (targetIndex > previousIndex) return rawTarget;
202
+
203
+ // Staying or falling uses the PREVIOUS stage's threshold minus the lag band.
204
+ //
205
+ // The subtlety: the band must be anchored on the stage being left, not on the
206
+ // raw target. Anchoring on the target means that after reaching 深化期 (55) a
207
+ // score of 54 computes target=INITIAL (whose threshold is 25), 25-5=20, so 54
208
+ // passes and the stage is lost immediately — the lag band silently does nothing.
209
+ // Anchored on 深化期 it needs to fall below 55-5=50 before dropping.
210
+ if (previousIndex > 0) {
211
+ const holdThreshold = STAGE_BY_KEY.get(previousKey).compositeThreshold - STAGE_LAG;
212
+ if (score >= holdThreshold) return previousKey;
213
+ }
214
+ return rawTarget;
215
+ }
216
+
217
+ /**
218
+ * Full stage evaluation: the stage, the protected composite, and whether a
219
+ * transition is in progress.
220
+ *
221
+ * Returns a NEW state object rather than mutating, so a caller that decides not to
222
+ * keep the turn (e.g. an aborted reply) can simply drop it.
223
+ */
224
+ export function evaluateStage(state) {
225
+ const next = { ...state, emotions: { ...state.emotions } };
226
+ if (next.favor < 0) {
227
+ // Negative regime: intimacy no longer participates at all.
228
+ const regime = NEGATIVE_REGIMES.find((r) => next.favor >= r.min) ?? NEGATIVE_REGIMES.at(-1);
229
+ return {
230
+ state: { ...next, stage: 'INITIAL', previousComposite: next.favor, transitionPeak: 0 },
231
+ stageKey: null,
232
+ stageName: regime.name,
233
+ description: regime.description,
234
+ advice: regime.advice,
235
+ composite: next.favor,
236
+ favorWeight: 1,
237
+ intimacyWeight: 0,
238
+ isTransitioning: false,
239
+ transitionProgress: 0,
240
+ intimacyBoostActive: false,
241
+ neededIntimacy: 0,
242
+ progressToNext: regime.key === 'COLD'
243
+ ? Math.max(0, ((next.favor + 30) / 30) * 100)
244
+ : regime.key === 'AVERSE'
245
+ ? Math.max(0, ((next.favor + 70) / 40) * 100)
246
+ : 0,
247
+ negative: true,
248
+ regime: regime.key,
249
+ };
250
+ }
251
+
252
+ const composite = rawComposite(next, next.stage);
253
+ const targetKey = stageForScore(composite, next.stage);
254
+ const target = STAGE_BY_KEY.get(targetKey);
255
+ const advanced = (STAGE_INDEX.get(targetKey) ?? 0) > (STAGE_INDEX.get(next.stage) ?? 0);
256
+ const dropped = (STAGE_INDEX.get(targetKey) ?? 0) < (STAGE_INDEX.get(next.stage) ?? 0);
257
+
258
+ // Protection: never let the visible score fall below the peak reached in the
259
+ // current stage, so advancing does not look like a setback.
260
+ const peak = Math.max(Number(next.transitionPeak) || 0, composite, Number(next.previousComposite) || 0);
261
+ const protectedComposite = advanced ? Math.max(composite, next.transitionPeak || 0) : composite;
262
+
263
+ // Intimacy still needed to make the protected score honest under the new weights.
264
+ let neededIntimacy = 0;
265
+ if (advanced && target.intimacyWeight > 0) {
266
+ const required = (protectedComposite - next.favor * target.favorWeight) / target.intimacyWeight;
267
+ neededIntimacy = Math.max(0, Math.min(100, Math.round(required)) - next.intimacy);
268
+ }
269
+ const transitionProgress = neededIntimacy <= 0
270
+ ? 100
271
+ : Math.min(100, (next.intimacy / (next.intimacy + neededIntimacy)) * 100);
272
+
273
+ // Weights during a transition lean on intimacy, which is what the boost is for.
274
+ let favorWeight = target.favorWeight;
275
+ let intimacyWeight = target.intimacyWeight;
276
+ const boostActive = advanced && neededIntimacy > 0;
277
+ if (boostActive) {
278
+ const boosted = target.intimacyWeight * target.intimacyBoostFactor;
279
+ const total = target.favorWeight + boosted;
280
+ favorWeight = target.favorWeight / total;
281
+ intimacyWeight = boosted / total;
282
+ }
283
+
284
+ const progressToNext = Math.max(0, Math.min(100, (protectedComposite / target.compositeThreshold) * 100));
285
+
286
+ const updated = {
287
+ ...next,
288
+ stage: targetKey,
289
+ previousComposite: protectedComposite,
290
+ transitionPeak: dropped ? composite : peak,
291
+ // Persist the boost decision. `applyDeltas` needs it on the NEXT turn, when
292
+ // re-evaluating would no longer see a transition (the stage already moved).
293
+ intimacyBoost: boostActive ? target.intimacyBoostFactor : 0,
294
+ };
295
+
296
+ return {
297
+ state: updated,
298
+ stageKey: targetKey,
299
+ stageName: target.name,
300
+ description: target.description,
301
+ advice: target.advice,
302
+ composite: protectedComposite,
303
+ favorWeight,
304
+ intimacyWeight,
305
+ isTransitioning: advanced,
306
+ transitionProgress,
307
+ intimacyBoostActive: boostActive,
308
+ neededIntimacy,
309
+ progressToNext,
310
+ negative: false,
311
+ regime: null,
312
+ };
313
+ }
314
+
315
+ /**
316
+ * Apply per-turn deltas.
317
+ *
318
+ * Favor and intimacy are capped per turn; the eight emotions are capped tighter
319
+ * because a single sentence should not max out an emotion. The intimacy boost is
320
+ * applied here (not in the stage maths) so the stored value reflects it.
321
+ */
322
+ export function applyDeltas(state, deltas = {}) {
323
+ const next = { ...state, emotions: { ...state.emotions } };
324
+ // Evaluate the state as it stands BEFORE the deltas, so a stage that was just
325
+ // reached on the previous turn keeps its boost. Reading the raw `state` here
326
+ // would miss the transition (its `stage` field is still the old one) and the
327
+ // multiplier would silently never apply.
328
+ const stage = evaluateStage(next);
329
+ // Prefer the persisted factor: a transition is a one-turn event, so recomputing
330
+ // it here would miss every turn after the stage already advanced.
331
+ const persistedBoost = Number(next.intimacyBoost) || 0;
332
+ const boost = persistedBoost > 0
333
+ ? persistedBoost
334
+ : (stage.intimacyBoostActive ? (STAGE_BY_KEY.get(stage.stageKey)?.intimacyBoostFactor ?? 1) : 1);
335
+
336
+ next.favor = Math.round(clamp(next.favor + clamp(deltas.favor ?? 0, -MAX_DELTA_RELATION, MAX_DELTA_RELATION), FAVOR_MIN, FAVOR_MAX));
337
+ const intimacyDelta = clamp(deltas.intimacy ?? 0, -MAX_DELTA_RELATION, MAX_DELTA_RELATION);
338
+ // Only amplify positive intimacy; a boost must never make a slight worse.
339
+ const boosted = intimacyDelta > 0 ? Math.round(intimacyDelta * boost) : intimacyDelta;
340
+ next.intimacy = Math.round(clamp(next.intimacy + boosted, INTIMACY_MIN, INTIMACY_MAX));
341
+
342
+ for (const dimension of EMOTION_DIMENSIONS) {
343
+ const delta = clamp(deltas[dimension] ?? 0, -MAX_DELTA_EMOTION, MAX_DELTA_EMOTION);
344
+ next.emotions[dimension] = Math.round(clamp(next.emotions[dimension] + delta, EMOTION_MIN, EMOTION_MAX));
345
+ }
346
+ return next;
347
+ }
348
+
349
+ /** The strongest emotion, or null when everything is flat. */
350
+ export function dominantEmotion(state) {
351
+ let best = null;
352
+ for (const dimension of EMOTION_DIMENSIONS) {
353
+ const value = state.emotions?.[dimension] ?? 0;
354
+ if (!best || value > best.value) best = { dimension, value };
355
+ }
356
+ if (!best || best.value <= 0) return null;
357
+ return { ...best, label: EMOTION_LABELS[best.dimension] };
358
+ }
359
+
360
+ /**
361
+ * How she should behave, derived from favor/intimacy.
362
+ *
363
+ * Mirrors AttitudeRelationshipManager.BEHAVIOR_STYLES. Kept as text fragments
364
+ * rather than finished sentences so the model still writes in her own voice.
365
+ */
366
+ export function behaviorStyle(state) {
367
+ const composite = state.favor * 0.6 + state.intimacy * 0.4;
368
+ if (state.favor < -50) return { key: 'hostile', text: '极其简短、尖锐,可以拒绝回应' };
369
+ if (state.favor < -10) return { key: 'cold', text: '冷淡、简洁、不耐烦' };
370
+ if (composite >= 75) return { key: 'intimate', text: '热情、主动、富有情感,可以用亲昵的称呼' };
371
+ if (composite >= 40) return { key: 'friendly', text: '积极、乐于回应、带一点正面情绪' };
372
+ return { key: 'neutral', text: '自然、保持一点距离、不过分热情' };
373
+ }
374
+
375
+ /** Tone fragment for the dominant emotion, above a threshold. */
376
+ export const TONE_INSTRUCTIONS = {
377
+ joy: '语气轻快、有活力,愿意多聊两句',
378
+ trust: '语气平和、真诚、让人安心',
379
+ fear: '语气有点谨慎、不安,会犹豫',
380
+ surprise: '语气里带着意外和好奇',
381
+ sadness: '语气低落,句子偏短,有点无力',
382
+ disgust: '语气里带着抗拒,想回避',
383
+ anger: '语气急躁,句子短,不太耐烦',
384
+ anticipation: '语气里带着期待,关注接下来会怎样',
385
+ };
386
+
387
+ export function toneInstruction(state, threshold = 30) {
388
+ const dominant = dominantEmotion(state);
389
+ if (dominant && dominant.value > threshold) {
390
+ return { emotion: dominant.dimension, label: dominant.label, text: TONE_INSTRUCTIONS[dominant.dimension] };
391
+ }
392
+ if (state.favor >= 40) return { emotion: null, label: null, text: '友好积极的语气' };
393
+ if (state.favor >= -10) return { emotion: null, label: null, text: '中立、自然的语气' };
394
+ return { emotion: null, label: null, text: '简洁、冷淡的语气' };
395
+ }
396
+
397
+ /**
398
+ * Whether this turn is significant enough to remember.
399
+ *
400
+ * The threshold is on the ABSOLUTE size of the change, so a big fight and a big
401
+ * confession are both remembered while ordinary small talk is not.
402
+ */
403
+ export function isSignificant(deltas = {}, threshold = 5) {
404
+ let magnitude = 0;
405
+ for (const key of ['favor', 'intimacy', ...EMOTION_DIMENSIONS]) {
406
+ magnitude += Math.abs(Number(deltas[key]) || 0);
407
+ }
408
+ return magnitude >= threshold;
409
+ }
410
+
411
+ /** A short human-readable summary of the relationship, for prompts. */
412
+ export function describeState(state, { privacyLevel = 1 } = {}) {
413
+ if (privacyLevel === 0) return '';
414
+ const stage = evaluateStage(state);
415
+ const lines = [];
416
+ lines.push(`关系阶段:${stage.stageName}(${stage.description})`);
417
+ if (privacyLevel >= 2) {
418
+ lines.push(`好感度 ${state.favor}(-100..100),亲密度 ${state.intimacy}(0..100)。`);
419
+ const dominant = dominantEmotion(state);
420
+ if (dominant) lines.push(`此刻最明显的情绪是${dominant.label}(${dominant.value}/100)。`);
421
+ if (stage.isTransitioning) {
422
+ lines.push(`正在向新阶段过渡,还需要 ${stage.neededIntimacy} 点亲密度,进度 ${Math.round(stage.transitionProgress)}%。`);
423
+ }
424
+ }
425
+ if (state.relationship && state.relationship !== '陌生人') lines.push(`你们的关系:${state.relationship}`);
426
+ if (state.attitude && state.attitude !== '中立') lines.push(`你对他的态度:${state.attitude}`);
427
+ return lines.join('\n');
428
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-fatfish-endocrine contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # 内分泌模块
2
+
3
+ 这是 `dsh-qq-access` 内置的身体状态模块。
4
+
5
+ ## 来源
6
+
7
+ 核心激素引擎、17 个疾病数据和药物/场景表取自:
8
+
9
+ - https://github.com/shiliman/dsh-fatfish-endocrine
10
+ - MIT License,见同目录 `LICENSE`
11
+
12
+ 本目录的 `upstream.mjs` 保留上游实现,额外增加了:
13
+
14
+ - 状态恢复 `createEngine({ state })`
15
+ - `serialize()` 持久化快照
16
+ - 可注入随机源和 `autoFlare` 开关
17
+
18
+ ## 提示词边界
19
+
20
+ `engine.mjs` 的 `bodyCue()` 是 QQ 专用适配层,刻意不直接复用上游的
21
+ `renderStateText()`:
22
+
23
+ - 只输出主观感受,不输出激素名称、数值、疾病名或精神标签
24
+ - 群聊只输出粗粒度精力,不暴露周期和疾病
25
+ - 不参与人格、关系、权限、拒绝和不可逆动作的判定
26
+ - 不诊断对方,不提供药物、剂量或治疗建议
27
+
28
+ `dsh-qq-access` 在 QQ agent 的 `systemPrompt` 中以 `order: 490` 注入,
29
+ 低于 persona 的 500,确保人格和关系规则优先。
30
+
31
+ ## 持久化
32
+
33
+ 状态保存在:
34
+
35
+ ```text
36
+ <dataDir>/endocrine/state.json
37
+ ```
38
+
39
+ 损坏文件会重命名为 `.corrupt-<timestamp>`,然后按空状态重建。