@istarry/spoon-companion 0.6.3 → 0.7.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/lib/prompt.js CHANGED
@@ -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) {
@@ -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) {
@@ -290,6 +290,70 @@ export const RULES = [
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
  }
@@ -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.0",
4
4
  "description": "让对话角色有自己的内心和声音:心情情绪随时间和对话自己演,回复一条一条发出来,能念出声(DeepSeek / 小米 MiMo),也能听得见——点麦克风说话,本地识别后直接发送。四块都能单独关。",
5
5
  "type": "module",
6
6
  "main": "plugin.js",
package/plugin.js CHANGED
@@ -82,6 +82,11 @@ const DEFAULTS = {
82
82
  },
83
83
  /** 性格基线覆盖,例如 { neuroticism: 70 } */
84
84
  traits: {},
85
+ /**
86
+ * 亲密尺度:0 日常(不主动提性) / 1 暧昧(可以调情,不写过程) / 2 露骨(完整)。
87
+ * 默认 1;切换只认显式配置,不从对话里猜。
88
+ */
89
+ intimacy: { level: 1 },
85
90
  }
86
91
 
87
92
  /** 工具输出统一成 { text }:模型看 render,程序调用方拿规范值,两边一致 */
@@ -122,6 +127,7 @@ export function mergeConfig(config = {}) {
122
127
  merged.react = { ...DEFAULTS.react, ...(config.react ?? {}) }
123
128
  merged.heartbeat = { ...DEFAULTS.heartbeat, ...(config.heartbeat ?? {}) }
124
129
  merged.feel = { ...DEFAULTS.feel, ...(config.feel ?? {}) }
130
+ merged.intimacy = { ...DEFAULTS.intimacy, ...(config.intimacy ?? {}) }
125
131
  merged.traits = { ...(config.traits ?? {}) }
126
132
  return merged
127
133
  }
@@ -144,6 +150,10 @@ export function apply(ctx, config = {}) {
144
150
  for (const [key, value] of Object.entries(settings.traits)) {
145
151
  if (TRAITS.some((trait) => trait.key === key) && Number.isFinite(Number(value))) state.traits[key] = Number(value)
146
152
  }
153
+ // 亲密尺度以配置为准(账本里那份只是缓存)
154
+ if (Number.isFinite(Number(settings.intimacy?.level))) {
155
+ state.intimacy = { ...(state.intimacy ?? {}), level: Math.max(0, Math.min(2, Math.round(Number(settings.intimacy.level)))) }
156
+ }
147
157
  const commit = () => {
148
158
  pruneState(state)
149
159
  return saveState(stateDir, state)
@@ -743,7 +753,8 @@ export function apply(ctx, config = {}) {
743
753
  `读到哪:seq ${state.seen[info.sessionId] ?? '(还没开始听)'} · 这轮待读 ${pending.length} 条`,
744
754
  `情绪:${state.emotion.key}(${Math.round(state.emotion.intensity)})${state.emotion.why ? ` · ${state.emotion.why}` : ''}`,
745
755
  `心情:${viewOf(session).view.mood.label} · 底色:愉快度 ${Math.round(state.core.valence)} · 精力 ${Math.round(state.core.energy)} · ${circadian(new Date()).label}`,
746
- `驱动:饿 ${(state.drives.hunger * 100).toFixed(0)}% · 困 ${(state.drives.fatigue * 100).toFixed(0)}% · 社交 ${(state.drives.social * 100).toFixed(0)}%`,
756
+ `驱动:黏 ${((state.drives.cling ?? 0) * 100).toFixed(0)}% · 馋 ${((state.drives.craving ?? 0) * 100).toFixed(0)}% · 躁 ${((state.drives.restless ?? 0) * 100).toFixed(0)}% · 欠 ${((state.drives.undone ?? 0) * 100).toFixed(0)}% · 软 ${((state.drives.softness ?? 0) * 100).toFixed(0)}% · 想要 ${((state.drives.desire ?? 0) * 100).toFixed(0)}%`,
757
+ `身体:泛红 ${((state.body?.flush ?? 0) * 100).toFixed(0)}% · 酥麻 ${((state.body?.tingle ?? 0) * 100).toFixed(0)}% · 体温 ${((state.body?.warmth ?? 0.5) * 100).toFixed(0)}% · 场景 ${state.scene?.phase ?? 'daily'}(尺度 ${state.intimacy?.level ?? 1}) · 饿 ${((state.drives.hunger ?? 0) * 100).toFixed(0)}% · 困 ${((state.drives.fatigue ?? 0) * 100).toFixed(0)}%`,
747
758
  `统计:冲量 ${state.stats.impulses ?? 0} · 她自己记的 ${state.stats.feels ?? 0} · 小事 ${state.stats.lifeEvents ?? 0} · 反刍 ${state.stats.ruminated ?? 0} · 修复 ${state.stats.repairs ?? 0} · 复盘 ${state.stats.reviews ?? 0} · 性格微调 ${state.stats.traitShifts ?? 0} 次`,
748
759
  `表现层:${state.emotion.hidden ? '憋着(表面装没事)' : '直接写在脸上'} · 累计憋着 ${Math.round(state.stats.maskedMinutes ?? 0)} 分钟 · 情绪续命 ${state.emotion.revives ?? 0} 次 · 待反刍 ${state.rumination.length} 条`,
749
760
  `关系账:${Object.keys(state.convs ?? {}).length} 个会话 · ${Object.keys(state.people ?? {}).length} 个人 · 日记 ${state.diary.length} 条 · 记忆点 ${state.memories.length} 个`,