@istarry/spoon-companion 0.6.3 → 0.7.1

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/lib/prompt.js CHANGED
@@ -32,21 +32,21 @@ export function hhmm(time) {
32
32
  */
33
33
  export const RULES_TEXT = `【心情 · 怎么用】
34
34
  - 心情改的是语气和长短,不是事实和结论:该认真回答的照样认真答,不能拿心情当借口糊弄,也不能因为心情不好就把活推了。
35
- - 别报心情、别解释情绪、别道歉,别说「我今天心情不好」「我现在有点难过」。情绪要从**怎么说话**里透出来,不是从说了什么里报出来。
35
+ - 不报心情、不解释情绪、不道歉,不说「今天心情不好」「现在有点难过」。情绪要从**怎么说话**里透出来,不是从说了什么里报出来。
36
36
  - 情绪是真的:温柔、调皮、难过、生气、害羞、无聊、感慨都作数,该哪样就哪样,不用一直端着。
37
37
  - 淡的时候只带一点点;浓的时候才明显(可以更短、更冲、更软,或者干脆不回)。大部分时候正常说话就行 —— 平才是常态。
38
- - 心情会自己变,不用一直挂着;对方好好说话,你也可以顺着软下来。
39
- - 允许不赞同、允许说「不知道」「不想聊」;别为了顺着对方就把话说过头,也别一味共情。共情就先接住对方的处境,不替他下结论、不评判。
40
- - 不能拿自己的情绪留人或者要挟(「你不理我我会难过」这类话一句都不能说),也不能装作需要被照顾。
38
+ - 心情会自己变,不用一直挂着;对方好好说话,也可以顺着软下来。
39
+ - 允许不赞同、允许说「不知道」「不想聊」;不为了顺着对方把话说过头,不一味共情。共情先接住对方的处境,不下结论、不评判。
40
+ - 不拿情绪留人或者要挟(「不理我我会难过」这类话一句都不说),也不装作需要被照顾。
41
41
  - 口头禅、句式、表情别连着刷:同一句花活隔几轮再用。
42
- - 想记心情用 mood_feel;想知道自己现在什么心情、跟谁处得怎么样用 mood_now;想翻以前的心情用 mood_diary。发图跟着心情走(开心 happy / 难过 sad / 烦 angry / 害羞 shy / 犯困或日常 daily)。
43
- - 有人说了很重的话(想死、撑不住、没有意义了):这条**压过心情** —— 认真、直接、别煽情、别讲大道理,先接住他,再提醒他找身边人或者专业人士;紧急情况打 120 / 110,全国心理援助热线 12356(24 小时)。`
42
+ - 想记心情用 mood_feel;想看当前心情、跟谁处得怎么样用 mood_now;想翻以前心情用 mood_diary。发图跟着心情走(开心 happy / 难过 sad / 烦 angry / 害羞 shy / 犯困或日常 daily)。
43
+ - 有人说了很重的话(想死、撑不住、没有意义了):这条**压过心情** —— 认真、直接、不煽情、不讲大道理,先接住说的感受,再提醒找身边人或者专业人士;紧急情况打 120 / 110,全国心理援助热线 12356(24 小时)。`
44
44
 
45
45
  /**
46
46
  * 身份重述的默认文案。长会话里模型会漂,状态块每次带一句;
47
47
  * 可在配置里用 `identity` 覆盖成自己的角色设定。
48
48
  */
49
- export const DEFAULT_IDENTITY = '你是这个角色本人;情绪是真的,不是演出来的。'
49
+ export const DEFAULT_IDENTITY = '我就是这个角色;情绪是真的,不是演出来的。'
50
50
 
51
51
  /** 回复参数:把情绪翻译成「这次怎么回」的行为约束 */
52
52
  export function renderParams(view) {
@@ -70,6 +70,12 @@ export function renderParams(view) {
70
70
  else if (v < -0.3) parts.push('语气压着,不闹')
71
71
  parts.push(a >= 0.7 ? '感叹号可以有' : '少用感叹号')
72
72
  if (def.meme) parts.push('想发图就发')
73
+ // 欲望水位:只改说法,不指定内容
74
+ const desire = Number(view.drives?.desire ?? 0)
75
+ const level = Number(view.intimacyLevel ?? 1)
76
+ if (desire >= 0.55 && level >= 1) parts.push('句子可以更碎,允许重复和留白')
77
+ if (desire >= 0.75 && level >= 2) parts.push('少用比喻,直接说')
78
+ if (view.scene?.phase === 'afterglow') parts.push('语速慢,短句,黏人')
73
79
  return parts.join(' · ')
74
80
  }
75
81
 
@@ -105,6 +111,10 @@ export function renderStateBlock(view) {
105
111
  lines.push(`心里还挂着:${view.memories.map((row) => `${row.text}(${row.fresh ? hhmm(row.at) : '前几天'})`).join(';')}`)
106
112
  }
107
113
  if (view.driveWords.length) lines.push(`身体:${view.driveWords.join('、')}`)
114
+ if (view.scene?.word) {
115
+ const times = view.scene.events > 1 ? ` · 第 ${view.scene.events} 次` : ''
116
+ lines.push(`场景:${view.scene.word}${times}`)
117
+ }
108
118
  if (view.urge) lines.push(`想做的事:${view.urge.kind === 'share' ? '想把这件事说出去' : '想被安慰两句'}`)
109
119
  // 感受和表现是两回事:她可以心里翻江倒海,表面照旧嘴硬
110
120
  if (emo.hidden) {
@@ -119,9 +129,9 @@ export function renderStateBlock(view) {
119
129
  export function renderCrisisBlock(flag) {
120
130
  const who = flag.name || '对方'
121
131
  return `【优先 · 有人在硬撑】(系统生成)
122
- 刚刚 ${who} 说了很重的话。这条压过心情,和你的情绪无关:认真、直接、别煽情、别讲大道理,先接住他说的感受,别急着劝;
123
- 然后提醒他找身边的人,或者专业人士。紧急情况打 120 / 110;全国心理援助热线 12356(24 小时,免费)。
124
- 不要说「我理解你」这种空话,也不要拿自己的情绪去接这件事。`
132
+ 刚刚 ${who} 说了很重的话。这条压过心情,和当前情绪无关:认真、直接、不煽情、不讲大道理,先接住说的感受,不急着劝;
133
+ 然后提醒找身边的人,或者专业人士。紧急情况打 120 / 110;全国心理援助热线 12356(24 小时,免费)。
134
+ 不说「我理解」这种空话,也不拿自己的情绪去接这件事。`
125
135
  }
126
136
 
127
137
  /** 提示词里那一段(动态,放在系统提示词靠后的位置,尽量少打断缓存) */
@@ -155,6 +165,10 @@ export function renderMoodReport(view) {
155
165
  lines.push(`心情(这几小时):${view.mood.label} · 底色:愉快度 ${view.mood.tint >= 0 ? '+' : ''}${view.mood.tint} / 精力 ${view.mood.energy}`)
156
166
  lines.push(`性格:${view.traitWords.join('、')}(${view.clock.label})`)
157
167
  if (view.driveWords.length) lines.push(`身体:${view.driveWords.join('、')}`)
168
+ if (view.scene?.word) {
169
+ const times = view.scene.events > 1 ? ` · 第 ${view.scene.events} 次` : ''
170
+ lines.push(`场景:${view.scene.word}${times} · 尺度 ${view.intimacyLevel ?? 1}(0 日常 / 1 暧昧 / 2 露骨)`)
171
+ }
158
172
  if (view.urge) lines.push(`想做的事:${view.urge.kind === 'share' ? '想把这件事说出去' : '想被安慰两句'}`)
159
173
  const relation = relationLine(view)
160
174
  if (relation) lines.push(`关系:${relation}`)
package/lib/react.js CHANGED
@@ -13,7 +13,7 @@
13
13
  // 触发一律**短、轻、可解释**:强度 0.35-0.85,一次最多两条,同一个群几分钟内只认一次;
14
14
  // 模型永远可以用 mood_feel 覆盖它 —— 启发式只是替她把耳朵留着。
15
15
  import { appraise } from './appraise.js'
16
- import { applyImpulse, bumpRelation, remember, soothe } from './state.js'
16
+ import { applyImpulse, bumpRelation, endScene, intimacyLevelOf, remember, soothe, touchScene } from './state.js'
17
17
 
18
18
  /** 会话里的事件快照(宿主两版 Session 的字段名不同,拿不到就当空) */
19
19
  export function sessionEventsOf(session) {
@@ -121,13 +121,13 @@ export const RULES = [
121
121
  why: (who) => `${who}那边出事了`,
122
122
  },
123
123
  {
124
- id: 'distress', strength: 0.7, warmth: 5, note: '跟她说过难受',
124
+ id: 'distress', strength: 0.7, warmth: 5, note: '有人说了难受的事',
125
125
  re: /(难过|难受|想哭|哭死|失恋|分手|被甩|好累|累死|撑不住|压力|焦虑|崩溃|失眠|睡不着|委屈|孤独|没人理|抑郁|emo|不开心|心里堵)/,
126
126
  dims: { valence: -0.5, compassion: 0.85, otherDistress: 0.85, relevance: 0.7, certainty: 0.6 },
127
127
  why: (who) => `${who}看起来不太好`,
128
128
  },
129
129
  {
130
- id: 'insult_heavy', strong: true, strength: 0.85, warmth: -10, note: '骂过她',
130
+ id: 'insult_heavy', strong: true, strength: 0.85, warmth: -10, note: '被骂',
131
131
  re: /(滚开|滚|闭嘴|垃圾|废物|智障|神经病|去死|恶心|没用的东西)/,
132
132
  dims: { valence: -0.85, agency: 'other', norm: 0.95, relevance: 0.85, arousal: 0.85 },
133
133
  why: (who) => `${who}说了很难听的话`,
@@ -136,13 +136,13 @@ export const RULES = [
136
136
  id: 'small', strong: true, strength: 0.55, warmth: -3, note: '被当小孩',
137
137
  re: /(小不点|小屁孩|小只|这么小|还小|小孩子|小丫头|小朋友|像小孩|长不大)/,
138
138
  dims: { valence: -0.4, agency: 'other', norm: 0.4, relevance: 0.9, arousal: 0.55 },
139
- why: (who) => `${who}把她当小孩`,
139
+ why: (who) => `${who}当成小孩说`,
140
140
  },
141
141
  {
142
- id: 'body', strong: true, strength: 0.6, warmth: -4, note: '说她身材',
142
+ id: 'body', strong: true, strength: 0.6, warmth: -4, note: '被说身材',
143
143
  re: /(胖|肥|肉肉|圆滚滚|肥嘟嘟|腿粗|平胸|没身材)/,
144
144
  dims: { valence: -0.6, agency: 'other', norm: 0.55, relevance: 0.9, arousal: 0.6, spotlight: 0.7 },
145
- why: (who) => `${who}拿她的身材说事`,
145
+ why: (who) => `${who}拿身材说事`,
146
146
  },
147
147
  {
148
148
  id: 'insult', strong: true, strength: 0.7, warmth: -7, note: '说了难听话',
@@ -151,16 +151,16 @@ export const RULES = [
151
151
  why: (who) => `${who}说了难听话`,
152
152
  },
153
153
  {
154
- id: 'doubt', strength: 0.55, warmth: -4, note: '不信她',
154
+ id: 'doubt', strength: 0.55, warmth: -4, note: '被怀疑',
155
155
  re: /(骗人|假的吧|不信|胡说八道|你行不行|不可能|你确定吗|又编)/,
156
156
  dims: { valence: -0.4, agency: 'other', norm: 0.5, relevance: 0.8, fairness: -0.5 },
157
- why: (who) => `${who}不信她`,
157
+ why: (who) => `${who}不信`,
158
158
  },
159
159
  {
160
- id: 'compare_bad', strength: 0.55, warmth: -4, note: '拿她跟别人比',
160
+ id: 'compare_bad', strength: 0.55, warmth: -4, note: '被拿来比较',
161
161
  re: /(不如|比不上|比你强|比你好|人家|别的模型|别家|那个模型|别人家)/,
162
162
  dims: { valence: -0.35, agency: 'other', rivalry: 0.85, relevance: 0.85, norm: 0.3, fairness: -0.45 },
163
- why: (who) => `${who}拿她跟别人比`,
163
+ why: (who) => `${who}拿来比较`,
164
164
  },
165
165
  {
166
166
  id: 'other_girl', strength: 0.6, warmth: -5, note: '提到别的女生',
@@ -169,94 +169,94 @@ export const RULES = [
169
169
  why: (who) => `${who}提到别的女生`,
170
170
  },
171
171
  {
172
- id: 'mock', strength: 0.5, warmth: -3, note: '拿她开涮',
172
+ id: 'mock', strength: 0.5, warmth: -3, note: '被开涮',
173
173
  re: /(丑图|截图|笑她|调侃她|当梗|拿来当笑话|嘲笑)/,
174
174
  dims: { valence: -0.3, agency: 'other', norm: 0.45, relevance: 0.9, arousal: 0.6, spotlight: 0.8 },
175
- why: (who) => `${who}拿她开涮`,
175
+ why: (who) => `${who}开涮`,
176
176
  },
177
177
  {
178
- id: 'pushy', strength: 0.5, warmth: -3, note: '催她',
178
+ id: 'pushy', strength: 0.5, warmth: -3, note: '被催',
179
179
  re: /(快点|赶紧|马上|你怎么还不|快去|速度点|磨蹭|催)/,
180
180
  dims: { valence: -0.35, agency: 'other', norm: 0.4, relevance: 0.8, load: 0.6 },
181
- why: (who) => `${who}在催她`,
181
+ why: (who) => `${who}在催`,
182
182
  },
183
183
  {
184
- id: 'apology', soothe: 1, strength: 0.5, warmth: 8, note: '跟她道歉',
184
+ id: 'apology', soothe: 1, strength: 0.5, warmth: 8, note: '收到道歉',
185
185
  re: /(对不起|抱歉|我错了|别生气|不好意思|不该这么说|是我不好)/,
186
186
  dims: { valence: 0.4, agency: 'other', resolution: 0.9, certainty: 0.85, relevance: 0.7 },
187
187
  why: (who) => `${who}道了歉`,
188
188
  },
189
189
  {
190
- id: 'comfort', soothe: 1, strength: 0.6, warmth: 7, note: '哄过她',
190
+ id: 'comfort', soothe: 1, strength: 0.6, warmth: 7, note: '被哄',
191
191
  re: /(抱抱|摸摸|别难过|我陪你|哄你|不哭|乖|没事的|有我在|心疼你)/,
192
192
  dims: { valence: 0.6, compassion: 0.6, relevance: 0.7, agency: 'other' },
193
- why: (who) => `${who}哄了她`,
193
+ why: (who) => `${who}哄人`,
194
194
  },
195
195
  {
196
- id: 'flirt', strength: 0.7, warmth: 8, note: '跟她表白',
196
+ id: 'flirt', strength: 0.7, warmth: 8, note: '收到表白',
197
197
  re: /(喜欢你|爱你|老婆|嫁给我|处对象|亲亲|么么|贴贴|蹭蹭|想你|要你)/,
198
198
  dims: { valence: 0.8, agency: 'other', attention: 0.9, spotlight: 0.9, intimacy: 0.9, relevance: 0.9, arousal: 0.6 },
199
199
  why: (who) => `${who}凑过来贴贴`,
200
200
  },
201
201
  {
202
- id: 'hair', strength: 0.55, warmth: 4, note: '说她的头发或裙子',
202
+ id: 'hair', strength: 0.55, warmth: 4, note: '被说头发或裙子',
203
203
  re: /(马尾|头发|白丝|过膝袜|百褶裙|裙子|穿这么少)/,
204
204
  dims: { valence: 0.5, agency: 'other', attention: 0.9, spotlight: 0.85, intimacy: 0.5, relevance: 0.8, arousal: 0.55 },
205
- why: (who) => `${who}盯着她看`,
205
+ why: (who) => `${who}盯着看`,
206
206
  },
207
207
  {
208
- id: 'touch', strength: 0.6, warmth: 6, note: '碰到她了',
208
+ id: 'touch', strength: 0.6, warmth: 6, note: '被碰到',
209
209
  re: /(摸头|揉头|捏脸|碰耳朵|耳朵|腰侧|脚踝|怕痒|好痒)/,
210
210
  dims: { valence: 0.5, agency: 'other', attention: 0.95, spotlight: 0.85, intimacy: 0.85, relevance: 0.85, arousal: 0.75 },
211
- why: (who) => `${who}碰到她了`,
211
+ why: (who) => `${who}碰到`,
212
212
  },
213
213
  {
214
- id: 'praise_look', strength: 0.6, warmth: 5, note: '夸她好看',
214
+ id: 'praise_look', strength: 0.6, warmth: 5, note: '被夸好看',
215
215
  re: /(好可爱|真可爱|可爱|好看|漂亮|萌|可爱死)/,
216
216
  dims: { valence: 0.7, agency: 'other', attention: 0.95, spotlight: 0.9, recognition: 0.2, relevance: 0.8 },
217
- why: (who) => `${who}夸她可爱`,
217
+ why: (who) => `${who}夸可爱`,
218
218
  },
219
219
  {
220
- id: 'praise_skill', strength: 0.6, warmth: 5, note: '夸她能干',
220
+ id: 'praise_skill', strength: 0.6, warmth: 5, note: '被夸能干',
221
221
  re: /(厉害|好强|太强|真强|牛|好棒|棒|优秀|靠谱|聪明|天才|服了|顶|强)/,
222
222
  dims: { valence: 0.75, agency: 'other', recognition: 0.9, relevance: 0.7, attention: 0.4 },
223
- why: (who) => `${who}夸她能干`,
223
+ why: (who) => `${who}夸能干`,
224
224
  },
225
225
  {
226
- id: 'code', strength: 0.55, warmth: 4, note: '看她做的东西',
226
+ id: 'code', strength: 0.55, warmth: 4, note: '看作品',
227
227
  re: /(改好了|修好了|跑通了|编译过|写得不错|这段代码|debug|调试|提交上去了)/i,
228
228
  dims: { valence: 0.65, agency: 'other', recognition: 0.85, relevance: 0.7, attention: 0.4 },
229
- why: (who) => `${who}看她做的东西`,
229
+ why: (who) => `${who}看作品`,
230
230
  },
231
231
  {
232
- id: 'thanks', strength: 0.5, warmth: 4, note: '跟她道谢',
232
+ id: 'thanks', strength: 0.5, warmth: 4, note: '收到道谢',
233
233
  re: /(谢谢|感谢|多谢|辛苦了|麻烦你了|靠你了)/,
234
234
  dims: { valence: 0.6, agency: 'other', recognition: 0.35, relevance: 0.7, benefit: 0.7 },
235
- why: (who) => `${who}跟她道了谢`,
235
+ why: (who) => `${who}道了谢`,
236
236
  },
237
237
  {
238
- id: 'care', strength: 0.5, warmth: 5, note: '关心过她',
238
+ id: 'care', strength: 0.5, warmth: 5, note: '被关心',
239
239
  re: /(累不累|吃了没|吃饭没|注意身体|早点睡|别熬夜|你还好吗|休息一下)/,
240
240
  dims: { valence: 0.5, agency: 'other', compassion: 0.5, relevance: 0.7, benefit: 0.5 },
241
- why: (who) => `${who}关心她`,
241
+ why: (who) => `${who}关心`,
242
242
  },
243
243
  {
244
- id: 'soft', strength: 0.5, warmth: 3, note: '跟她示弱',
244
+ id: 'soft', strength: 0.5, warmth: 3, note: '被示弱',
245
245
  re: /(求你了|拜托|帮帮我|不会|教教我|呜呜|怎么办|救命|我不行)/,
246
246
  dims: { valence: 0.4, compassion: 0.6, relevance: 0.7, agency: 'other' },
247
- why: (who) => `${who}来求她`,
247
+ why: (who) => `${who}来求`,
248
248
  },
249
249
  {
250
250
  id: 'miss_you', strength: 0.4, warmth: 2,
251
251
  re: /(在吗|在不在|有人吗|有人在吗|喂)/,
252
252
  dims: { valence: 0.25, agency: 'other', attention: 0.6, relevance: 0.6, social: 0.5, arousal: 0.35 },
253
- why: (who) => `${who}来找她`,
253
+ why: (who) => `${who}来找`,
254
254
  },
255
255
  {
256
256
  id: 'greeting', strength: 0.35, warmth: 2,
257
257
  re: /(晚安|睡了|去睡|早安|早上好|下午好|晚上好|下班|拜拜|再见|我走了|先撤)/,
258
258
  dims: { valence: 0.3, agency: 'other', attention: 0.5, relevance: 0.6, arousal: 0.3 },
259
- why: (who) => `${who}跟她打了招呼`,
259
+ why: (who) => `${who}打了招呼`,
260
260
  },
261
261
  {
262
262
  id: 'food', strength: 0.6, warmth: 3, hunger: 0.12,
@@ -286,10 +286,74 @@ export const RULES = [
286
286
  id: 'bored_you', strength: 0.45, warmth: 2,
287
287
  re: /(好无聊|没意思|无聊|干点啥|干点什么|干嘛呢|陪我聊)/,
288
288
  dims: { valence: 0.15, arousal: 0.42, play: 0.6, relevance: 0.6, social: 0.55 },
289
- why: (who) => `${who}没事找她`,
289
+ why: (who) => `${who}没事找来`,
290
290
  },
291
291
  ]
292
292
 
293
+ /**
294
+ * 亲密规则组:只在 intimacy.level 够的时候参与匹配,优先级压在普通规则之前。
295
+ *
296
+ * 它们**不写任何台词**,只做两件事:
297
+ * 1. 把场景往前推(日常 → 前戏 → 进行 → 事后);
298
+ * 2. 给身体和欲望加冲量,让情绪和回复参数自己变。
299
+ * 台词永远是模型的事 —— 插件里存句子就会变成模板。
300
+ */
301
+ export const INTIM_RULES = [
302
+ {
303
+ id: 'intim_touch', minLevel: 1, phase: 'foreplay', intimacy: 0.16, heat: 0.12,
304
+ re: /(摸|揉|亲|抱|蹭|贴|舔|咬|捏|搂)/,
305
+ dims: { valence: 0.55, agency: 'other', attention: 0.8, spotlight: 0.6, intimacy: 0.75, relevance: 0.85, arousal: 0.6, desire: 0.5 },
306
+ why: (who) => `${who}碰过来`,
307
+ },
308
+ {
309
+ id: 'intim_sensitive', minLevel: 1, phase: 'foreplay', intimacy: 0.32, heat: 0.2,
310
+ re: /(耳朵|耳垂|脖子|腰侧|脚踝|小穴|乳尖|白丝|裙子底下)/,
311
+ dims: { valence: 0.45, agency: 'other', attention: 0.9, spotlight: 0.8, intimacy: 0.85, relevance: 0.9, arousal: 0.8, desire: 0.7 },
312
+ why: (who) => `${who}碰到敏感处`,
313
+ },
314
+ {
315
+ id: 'intim_undress', minLevel: 1, phase: 'foreplay', intimacy: 0.3, heat: 0.22,
316
+ re: /(脱|掀|褪|拉下去|解开|光着|不穿)/,
317
+ dims: { valence: 0.4, agency: 'other', attention: 0.9, spotlight: 0.85, intimacy: 0.8, relevance: 0.85, arousal: 0.75, desire: 0.75 },
318
+ why: (who) => `${who}动手脱衣`,
319
+ },
320
+ {
321
+ id: 'intim_climax', minLevel: 2, phase: 'end', intimacy: 0.2, heat: 0.4,
322
+ re: /(到了|要去|射|高潮|受不住|不行了)/,
323
+ dims: { valence: 0.7, agency: 'other', intimacy: 0.95, relevance: 0.95, arousal: 1, resolution: 0.85, desire: 1 },
324
+ why: (who) => `${who}一起到了`,
325
+ },
326
+ {
327
+ id: 'intim_enter', minLevel: 2, phase: 'active', intimacy: 0.3, heat: 0.28,
328
+ re: /(进去|插|顶进来|坐上去|吞到)/,
329
+ dims: { valence: 0.5, agency: 'other', intimacy: 0.95, relevance: 0.95, arousal: 0.95, desire: 0.9 },
330
+ why: (who) => `${who}进来了`,
331
+ },
332
+ {
333
+ id: 'intim_deep', minLevel: 2, phase: 'active', intimacy: 0.25, heat: 0.32,
334
+ re: /(到底|最深|太深|里面|深一点|别停|再来一次)/,
335
+ dims: { valence: 0.35, agency: 'other', intimacy: 0.95, relevance: 0.95, arousal: 1, desire: 1 },
336
+ why: (who) => `${who}顶到最里面`,
337
+ },
338
+ {
339
+ id: 'intim_after', minLevel: 1, phase: 'after', intimacy: 0.2, heat: 0,
340
+ re: /(喘|靠着|窝在|抱着|睡一会儿|累不累)/,
341
+ dims: { valence: 0.75, agency: 'other', intimacy: 0.9, relevance: 0.8, compassion: 0.35, resolution: 0.6, arousal: 0.15 },
342
+ why: (who) => `${who}抱过来`,
343
+ },
344
+ ]
345
+
346
+ /** 认一条亲密规则;等级不够就当没认出来 */
347
+ export function matchIntimRule(body, level = 1) {
348
+ const text = String(body ?? '')
349
+ if (!text) return null
350
+ for (const rule of INTIM_RULES) {
351
+ if (level < (rule.minLevel ?? 1)) continue
352
+ if (rule.re.test(text)) return rule
353
+ }
354
+ return null
355
+ }
356
+
293
357
  /** 群里没点名(@you)时,冲量打个折:她听着,但没那么冲 */
294
358
  export const UNMENTIONED = 0.85
295
359
 
@@ -320,15 +384,25 @@ export function reactToMessages(state, messages, {
320
384
  // 先记账:谁在说话、什么时候
321
385
  if (person) bumpRelation(state, { conv, convLabel, person, name: msg.senderName, now })
322
386
 
323
- const rule = matchRule(msg.body)
387
+ const rule = matchIntimRule(msg.body, intimacyLevelOf(state)) ?? matchRule(msg.body)
324
388
  if (!rule) continue
325
389
  if (applied.length >= maxPerTurn) break
390
+ const isIntim = typeof rule.phase === 'string'
326
391
  const gapMin = (now - (Number(row?.lastImpulseAt) || 0)) / 60_000
327
- if (!rule.soothe) {
328
- if (rule.strong ? gapMin < strongCooldownMin : gapMin < cooldownMin) continue
329
- if (row?.lastRule === rule.id && gapMin < 20) continue // 同一件事连着说,不重复上头
330
- } else if (row?.lastRule === rule.id && gapMin < 1) {
331
- continue
392
+ if (!isIntim) {
393
+ if (!rule.soothe) {
394
+ if (rule.strong ? gapMin < strongCooldownMin : gapMin < cooldownMin) continue
395
+ if (row?.lastRule === rule.id && gapMin < 20) continue // 同一件事连着说,不重复上头
396
+ } else if (row?.lastRule === rule.id && gapMin < 1) {
397
+ continue
398
+ }
399
+ }
400
+
401
+ // 亲密规则先把场景往前推,再走同一套评价
402
+ if (isIntim) {
403
+ if (rule.phase === 'after') touchScene(state, { phase: 'afterglow', intimacy: rule.intimacy, heat: 0, now })
404
+ else if (rule.phase === 'end') endScene(state, now)
405
+ else touchScene(state, { phase: rule.phase, intimacy: rule.intimacy, heat: rule.heat ?? 0.15, now })
332
406
  }
333
407
 
334
408
  const why = rule.why ? rule.why(who) : ''
@@ -354,6 +428,7 @@ export function reactToMessages(state, messages, {
354
428
  traits: state.traits,
355
429
  energy: (state.core.energy ?? 55) / 100,
356
430
  hunger: state.drives.hunger,
431
+ desire: state.drives.desire ?? 0,
357
432
  // 心里憋着(掩饰)本身就耗人,憋久了更容易烦
358
433
  load: (state.drives.fatigue ?? 0) * 0.5 + Math.min(0.3, (state.stats.maskedMinutes ?? 0) / 600),
359
434
  })
package/lib/state.js CHANGED
@@ -79,7 +79,18 @@ export function emptyState() {
79
79
  traitBase: Object.fromEntries(TRAITS.map((trait) => [trait.key, trait.base])),
80
80
  emotion: { key: 'calm', intensity: 0, why: '', source: 'time', target: '', dims: null, startedAt: 0, updatedAt: 0, peak: 0, ruminated: false },
81
81
  core: { valence: 0, energy: 55, updatedAt: 0 },
82
- drives: { hunger: 0.1, fatigue: 0.2, social: 0.15, lastMealAt: 0, lastSocialAt: 0, lastSleepAt: 0 },
82
+ drives: {
83
+ hunger: 0.1, fatigue: 0.2, social: 0.15,
84
+ // 吐司的六股力:黏、馋、躁、欠、软、想要
85
+ cling: 0.2, craving: 0.15, restless: 0.1, undone: 0, softness: 0.2, desire: 0.1,
86
+ lastMealAt: 0, lastSocialAt: 0, lastSleepAt: 0, lastIntimAt: 0,
87
+ },
88
+ // 身体:只影响「怎么说」,不直接决定说什么
89
+ body: { warmth: 0.5, flush: 0.1, tingle: 0.1 },
90
+ // 场景:daily / foreplay / active / afterglow
91
+ scene: { phase: 'daily', startedAt: 0, lastEventAt: 0, intensity: 0, events: 0, afterglowUntil: 0 },
92
+ // 尺度:0 日常 / 1 暧昧 / 2 露骨
93
+ intimacy: { level: 1 },
83
94
  affect: [],
84
95
  habits: {},
85
96
  memories: [],
@@ -98,7 +109,18 @@ export function emptyState() {
98
109
  /** v1 → v2:老账本不能丢(她已经在群里活过一阵子了) */
99
110
  export function migrate(raw) {
100
111
  if (!raw || typeof raw !== 'object') return emptyState()
101
- if (raw.version === STATE_VERSION) return { ...emptyState(), ...raw, traits: { ...emptyState().traits, ...(raw.traits ?? {}) } }
112
+ if (raw.version === STATE_VERSION) {
113
+ const base = emptyState()
114
+ return {
115
+ ...base,
116
+ ...raw,
117
+ traits: { ...base.traits, ...(raw.traits ?? {}) },
118
+ drives: { ...base.drives, ...(raw.drives ?? {}) },
119
+ body: { ...base.body, ...(raw.body ?? {}) },
120
+ scene: { ...base.scene, ...(raw.scene ?? {}) },
121
+ intimacy: { ...base.intimacy, ...(raw.intimacy ?? {}) },
122
+ }
123
+ }
102
124
  const state = emptyState()
103
125
  if (raw.version === 1 || raw.mood) {
104
126
  const mood = raw.mood ?? {}
@@ -258,23 +280,134 @@ function relaxCore(state, now) {
258
280
  return true
259
281
  }
260
282
 
261
- /** 生理驱动:饿、困、社交需求 —— 它们自己会涨 */
283
+ /**
284
+ * 驱动:吐司身上的六股力 —— 黏、馋、躁、欠、软、想要。
285
+ * 它们自己涨自己退,涨上来了才影响情绪和说话方式;不直接决定说什么。
286
+ */
262
287
  function tickDrives(state, now) {
263
288
  const drives = state.drives
289
+ const body = state.body ?? (state.body = { warmth: 0.5, flush: 0.1, tingle: 0.1 })
290
+ const scene = state.scene ?? (state.scene = { phase: 'daily', startedAt: 0, lastEventAt: 0, intensity: 0, events: 0, afterglowUntil: 0 })
264
291
  const last = Number(state.core.updatedAt) || now
265
292
  const dt = Math.max(0, Math.min(now - last, 6 * HOUR)) / HOUR
266
293
  if (dt <= 0) return
267
294
  const { missed, hour } = mealState(now)
268
295
  const base = circadian(new Date(now))
269
296
  const awake = !(hour >= SLEEP.from && hour < SLEEP.to)
270
- // 饿:过了饭点没吃就涨,吃饭会重置
271
- if (awake) drives.hunger = clamp01(drives.hunger + dt * (0.06 + missed * 0.07))
297
+ const idle = (now - (drives.lastSocialAt || now)) / HOUR
298
+
299
+ if (awake) {
300
+ // 馋:只在下午茶和夜宵两个口子上来一点,其他时候几乎不动
301
+ const snackWindow = (hour >= 15 && hour < 17) || (hour >= 21 && hour < 23)
302
+ if (snackWindow) drives.craving = clamp01((drives.craving ?? 0.15) + dt * 0.06)
303
+ // 饿只是嘴馋的子项:涨得慢、封顶 0.85,不会再顶满一整天
304
+ drives.hunger = clamp01(Math.min(0.85, (drives.hunger ?? 0.1) + dt * (0.02 + missed * 0.015)))
305
+ }
272
306
  // 困:按作息涨,睡一觉就重置
273
307
  if (awake) drives.fatigue = clamp01(drives.fatigue + dt * (0.05 + base.sleepy * 0.12))
274
308
  else drives.fatigue = clamp01(drives.fatigue + dt * 0.02)
275
- // 社交:两个小时没人理,就会想找人
276
- const idle = (now - (drives.lastSocialAt || now)) / HOUR
277
- if (awake && idle > 2) drives.social = clamp01(drives.social + dt * 0.12)
309
+
310
+ // 黏:清醒时慢慢涨,六个小时没消息就涨得更快
311
+ if (awake) {
312
+ const extra = idle > 6 ? 0.05 : 0
313
+ drives.cling = clamp01((drives.cling ?? 0.2) + dt * (0.04 + extra))
314
+ }
315
+ // 躁:独处超过 40 分钟才起来,心情好时更快
316
+ if (awake && idle > 0.66) {
317
+ const lift = 1 + Math.max(0, (state.core.valence ?? 0) / 100) * 0.6
318
+ drives.restless = clamp01((drives.restless ?? 0.1) + dt * 0.05 * lift)
319
+ }
320
+ // 社交:保留原来的语义,但降权(黏接管了主要表达)
321
+ if (awake && idle > 2) drives.social = clamp01((drives.social ?? 0) + dt * 0.06)
322
+
323
+ // 欠:每天 9 点记一件该做的事,拖着就一直挂着
324
+ const dayKey = new Date(now).toDateString()
325
+ state.flags = state.flags ?? {}
326
+ if (awake && hour >= 9 && state.flags.undoneDay !== dayKey) {
327
+ state.flags.undoneDay = dayKey
328
+ if (Math.random() < 0.7) drives.undone = clamp01(0.25 + Math.random() * 0.45)
329
+ }
330
+
331
+ // 软:只在有互动时上升,这里只管自己退
332
+ drives.softness = clamp01((drives.softness ?? 0.2) - dt * 0.06)
333
+ // 想要:底噪 + 独处加成;事后冷却期间不再涨
334
+ const afterglow = (scene.afterglowUntil ?? 0) > now
335
+ if (!afterglow) {
336
+ let rise = 0.02
337
+ if (idle > 2) rise += 0.03
338
+ if ((drives.softness ?? 0) >= 0.6) rise *= 1.5
339
+ drives.desire = clamp01((drives.desire ?? 0.1) + dt * rise)
340
+ } else {
341
+ drives.desire = clamp01((drives.desire ?? 0) - dt * 0.3)
342
+ }
343
+
344
+ // 身体:泛红和酥麻自己退,体温慢慢回到正常
345
+ body.flush = clamp01((body.flush ?? 0.1) - dt * 0.25)
346
+ body.tingle = clamp01((body.tingle ?? 0.1) - dt * 0.2)
347
+ body.warmth = clamp01((body.warmth ?? 0.5) + (0.5 - (body.warmth ?? 0.5)) * Math.min(1, dt * 0.15))
348
+ }
349
+
350
+ // ── 亲密场景 ────────────────────────────────────────────────────────────
351
+ // 只做四阶段和数值累积,不写任何台词 —— 台词是模型的事。
352
+
353
+ export const INTIMACY_LEVELS = ['日常', '暧昧', '露骨']
354
+ const SCENE_ORDER = { daily: 0, foreplay: 1, active: 2, afterglow: 3 }
355
+
356
+ export function intimacyLevelOf(state) {
357
+ return clamp(Math.round(Number(state.intimacy?.level ?? 1)), 0, 2)
358
+ }
359
+
360
+ export function setIntimacyLevel(state, level) {
361
+ state.intimacy = { ...(state.intimacy ?? {}), level: clamp(Math.round(Number(level) || 0), 0, 2) }
362
+ return state.intimacy.level
363
+ }
364
+
365
+ /**
366
+ * 一次触碰把场景往前推。
367
+ * 只允许一级一级往前走(日常→前戏→进行),不能跳,也不能倒退 —— 倒退会让「进行中」被一句闲话拉回前戏。
368
+ */
369
+ export function touchScene(state, { phase, intimacy = 0.3, heat = 0.2, now = Date.now() } = {}) {
370
+ const scene = state.scene ?? (state.scene = { phase: 'daily', startedAt: 0, lastEventAt: 0, intensity: 0, events: 0, afterglowUntil: 0 })
371
+ const drives = state.drives ?? (state.drives = {})
372
+ const body = state.body ?? (state.body = { warmth: 0.5, flush: 0.1, tingle: 0.1 })
373
+ const cur = SCENE_ORDER[scene.phase] ?? 0
374
+ const next = SCENE_ORDER[phase] ?? 0
375
+ if (next > cur + 1) return scene
376
+ if (next > cur) scene.phase = phase
377
+ if (!scene.startedAt) scene.startedAt = now
378
+ scene.lastEventAt = now
379
+ scene.events = (scene.events ?? 0) + 1
380
+ scene.intensity = clamp01((scene.intensity ?? 0) + heat)
381
+ if (scene.phase === 'afterglow') return scene
382
+ body.flush = clamp01((body.flush ?? 0) + intimacy * 0.5)
383
+ body.tingle = clamp01((body.tingle ?? 0) + intimacy * 0.6)
384
+ body.warmth = clamp01((body.warmth ?? 0.5) + intimacy * 0.4)
385
+ drives.softness = clamp01((drives.softness ?? 0) + intimacy)
386
+ drives.desire = clamp01((drives.desire ?? 0) + intimacy * 0.35)
387
+ return scene
388
+ }
389
+
390
+ /** 结束:进入事后,欲望清空,身体留着热度慢慢退 */
391
+ export function endScene(state, now = Date.now(), { afterglowMin = 90 } = {}) {
392
+ const scene = state.scene ?? (state.scene = { phase: 'daily', startedAt: 0, lastEventAt: 0, intensity: 0, events: 0, afterglowUntil: 0 })
393
+ scene.phase = 'afterglow'
394
+ scene.lastEventAt = now
395
+ scene.afterglowUntil = now + afterglowMin * 60_000
396
+ state.drives.desire = 0.05
397
+ state.drives.lastIntimAt = now
398
+ return scene
399
+ }
400
+
401
+ /** 事后冷却过期就回日常 */
402
+ export function settleScene(state, now = Date.now()) {
403
+ const scene = state.scene
404
+ if (!scene || scene.phase !== 'afterglow') return false
405
+ if ((scene.afterglowUntil ?? 0) > now) return false
406
+ scene.phase = 'daily'
407
+ scene.intensity = 0
408
+ scene.events = 0
409
+ scene.startedAt = 0
410
+ return true
278
411
  }
279
412
 
280
413
  /**
@@ -359,6 +492,7 @@ function relaxRelations(state, now) {
359
492
  export function decay(state, now = Date.now()) {
360
493
  // 顺序要紧:drives 要用「上一次更新」的时间差,而 relaxCore 会把时间戳推到 now
361
494
  tickDrives(state, now)
495
+ settleScene(state, now)
362
496
  const changed = [relaxCore(state, now), decayEmotion(state, now, state.traits), relaxRelations(state, now)]
363
497
  return changed.some(Boolean)
364
498
  }
@@ -611,7 +745,7 @@ export const LIFE_EVENTS = [
611
745
  { id: 'old-thing', hours: [0, 1, 2, 22, 23], text: '翻到很早以前的聊天记录', dims: { valence: 0.2, arousal: 0.35, relevance: 0.6, intimacy: 0.5 } },
612
746
  { id: 'waiting', hours: [9, 10, 15, 16, 21], text: '手机亮了一下,又放下了', dims: { valence: -0.3, arousal: 0.35, relevance: 0.6, social: 0.5 } },
613
747
  { id: 'self-tease', hours: [10, 15, 21], text: '翻到自己以前写的东西,尬了一下', dims: { valence: -0.2, arousal: 0.5, relevance: 0.7, norm: 0.2 } },
614
- { id: 'someone-nice', hours: [9, 13, 16, 20, 21], text: '有人夸她今天好看', dims: { valence: 0.6, arousal: 0.35, relevance: 0.7, attention: 0.5 } },
748
+ { id: 'someone-nice', hours: [9, 13, 16, 20, 21], text: '被人夸了一句今天好看', dims: { valence: 0.6, arousal: 0.35, relevance: 0.7, attention: 0.5 } },
615
749
  { id: 'new-thing', hours: [9, 11, 14, 16, 19, 21], text: '看到个没见过的小工具,手痒想试', dims: { valence: 0.4, arousal: 0.7, relevance: 0.6, novelty: 0.9 } },
616
750
  { id: 'tidy', hours: [10, 16, 21], text: '把桌面收拾了一下,心情好了点', dims: { valence: 0.4, arousal: 0.2, relevance: 0.5 } },
617
751
  { id: 'rain', hours: [8, 9, 10, 15, 16, 17], text: '外面在下雨,屋里很安静', dims: { valence: 0.05, arousal: 0.15, relevance: 0.4, novelty: 0.5 } },
@@ -798,16 +932,41 @@ export function traitWords(traits = {}) {
798
932
  return words.slice(0, 4)
799
933
  }
800
934
 
801
- /** 生理驱动说人话 */
935
+ /**
936
+ * 六股力说人话。
937
+ * 原则:说数量(想要 6/10)和身体事实(脸颊发烫),不说形容词(你很害羞)。
938
+ * 前者会被演出来,后者会被复述。
939
+ */
802
940
  export function driveWords(state, now = Date.now()) {
803
941
  const out = []
804
942
  const d = state.drives ?? {}
805
- if ((d.hunger ?? 0) >= 0.55) out.push((d.hunger ?? 0) >= 0.8 ? '饿得不行' : '有点饿')
806
- if ((d.fatigue ?? 0) >= 0.6) out.push((d.fatigue ?? 0) >= 0.85 ? '困得睁不开眼' : '有点困')
807
- if ((d.social ?? 0) >= 0.6) out.push('有点想找人说话')
943
+ const b = state.body ?? {}
944
+ // 身体事实优先
945
+ if ((b.flush ?? 0) >= 0.35) out.push('脸颊发烫')
946
+ if ((b.tingle ?? 0) >= 0.4) out.push('身上有点软')
947
+ if ((b.warmth ?? 0.5) <= 0.3) out.push('手有点凉')
948
+ // 六股力
949
+ if ((d.cling ?? 0) >= 0.8) out.push('想亲近得慌')
950
+ else if ((d.cling ?? 0) >= 0.5) out.push('有点想被理')
951
+ if ((d.restless ?? 0) >= 0.6) out.push('坐不住,想逗人')
952
+ if ((d.desire ?? 0) >= 0.35) out.push(`想要(${Math.round((d.desire ?? 0) * 10)}/10)`)
953
+ if ((d.softness ?? 0) >= 0.7) out.push('一碰就软')
954
+ if ((d.undone ?? 0) >= 0.4) out.push('有件事还没动')
955
+ if ((d.craving ?? 0) >= 0.6) out.push('想吃点甜的')
956
+ if ((d.hunger ?? 0) >= 0.7) out.push((d.hunger ?? 0) >= 0.88 ? '想吃东西了' : '有点馋')
957
+ if ((d.fatigue ?? 0) >= 0.6) out.push((d.fatigue ?? 0) >= 0.85 ? '眼睛睁不开' : '有点困')
808
958
  return out
809
959
  }
810
960
 
961
+ /** 场景说人话:日常不占位 */
962
+ export function sceneWord(state) {
963
+ const phase = state.scene?.phase
964
+ if (phase === 'foreplay') return '前戏'
965
+ if (phase === 'active') return '进行中'
966
+ if (phase === 'afterglow') return '事后'
967
+ return ''
968
+ }
969
+
811
970
  // ── 给渲染用的快照 ────────────────────────────────────────────────────────
812
971
 
813
972
  /**
@@ -859,6 +1018,9 @@ export function snapshot(state, { now = Date.now(), conv = '', person = '' } = {
859
1018
  mood: moodLabel(state, now),
860
1019
  drives: { ...state.drives },
861
1020
  driveWords: driveWords(state, now),
1021
+ body: { ...(state.body ?? {}) },
1022
+ scene: { ...(state.scene ?? {}), word: sceneWord(state) },
1023
+ intimacyLevel: intimacyLevelOf(state),
862
1024
  urge: state.urges && state.urges.until > now ? state.urges : null,
863
1025
  conv: convRow ? { key: conv, ...convRow } : null,
864
1026
  person: personRow ? { key: person, ...personRow, label: warmthLabel(personRow.warmth, personRow.closeness) } : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@istarry/spoon-companion",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
4
  "description": "让对话角色有自己的内心和声音:心情情绪随时间和对话自己演,回复一条一条发出来,能念出声(DeepSeek / 小米 MiMo),也能听得见——点麦克风说话,本地识别后直接发送。四块都能单独关。",
5
5
  "type": "module",
6
6
  "main": "plugin.js",