@istarry/spoon-companion 0.9.2 → 0.9.4

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/state.js CHANGED
@@ -301,7 +301,9 @@ function tickDrives(state, now) {
301
301
  const { missed, hour } = mealState(now)
302
302
  const base = circadian(new Date(now))
303
303
  const awake = !(hour >= SLEEP.from && hour < SLEEP.to)
304
- const idle = (now - (drives.lastSocialAt || now)) / HOUR
304
+ // 从没记过"上次说话"时,不能当成"刚刚才说过" —— 那会让独处加成永远不触发。
305
+ const lastSocialAt = Number(drives.lastSocialAt) || 0
306
+ const idle = lastSocialAt > 0 ? (now - lastSocialAt) / HOUR : 24
305
307
 
306
308
  if (awake) {
307
309
  // 馋:只在下午茶和夜宵两个口子上来一点,其他时候几乎不动
@@ -310,9 +312,9 @@ function tickDrives(state, now) {
310
312
  // 饿只是嘴馋的子项:涨得慢、封顶 0.85,不会再顶满一整天
311
313
  drives.hunger = clamp01(Math.min(0.85, (drives.hunger ?? 0.1) + dt * (0.02 + missed * 0.015)))
312
314
  }
313
- // 困:按作息涨,睡一觉就重置
315
+ // 困:醒着按作息涨,睡着了是真的在恢复(不是继续涨)
314
316
  if (awake) drives.fatigue = clamp01(drives.fatigue + dt * (0.05 + base.sleepy * 0.12))
315
- else drives.fatigue = clamp01(drives.fatigue + dt * 0.02)
317
+ else drives.fatigue = clamp01(drives.fatigue - dt * 0.14)
316
318
 
317
319
  // 黏:清醒时慢慢涨,六个小时没消息就涨得更快
318
320
  if (awake) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@istarry/spoon-companion",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "让对话角色有自己的内心和声音:心情情绪随时间和对话自己演,回复一条一条发出来,能念出声(DeepSeek / 小米 MiMo),也能听得见——点麦克风说话,本地识别后直接发送。四块都能单独关。",
5
5
  "type": "module",
6
6
  "main": "plugin.js",
package/plugin.js CHANGED
@@ -33,7 +33,7 @@ import {
33
33
  nightlyReview, pruneState, remember, saveState, screenHook, snapshot,
34
34
  } from './lib/state.js'
35
35
  import { channelOfSession, lastSpeaker, readUserMessages, reactToMessages, sessionEventsOf } from './lib/react.js'
36
- import { RULES_TEXT, renderDiary, renderMoodReport, renderMoodSection } from './lib/prompt.js'
36
+ import { RULES_TEXT, renderDiary, renderMoodReport, renderMoodSection, shortTitle } from './lib/prompt.js'
37
37
 
38
38
  export const name = 'fish-mood'
39
39
  /** tools 是硬依赖:没有工具注册表这个插件没有任何意义 */
@@ -551,6 +551,56 @@ export function apply(ctx, config = {}) {
551
551
  }
552
552
  }, 'spoon-companion: call route')
553
553
 
554
+ /**
555
+ * 开一个新窗口说一句。
556
+ * 不自己拼 session/agent —— 走官方 schedule:建一条一次性任务,target=new,立刻触发。
557
+ * 新会话的创建、投递、持久化都交给 DSH,插件只负责"想说什么"。
558
+ */
559
+ /** 给她一句"情境":走过去看到了什么,想凑过去说一句 */
560
+ const speakPrompt = (hook, title) => {
561
+ const where = shortTitle(title) || '屏幕亮着'
562
+ return `(刚走过去看了一眼屏幕:${where}。${hook}。想凑过去说一句 —— 不解释为什么,也不用问"怎么了",直接开口就是。)`
563
+ }
564
+
565
+ const speakNow = async (text) => {
566
+ const schedule = (() => {
567
+ try { return ctx.get?.('schedule') ?? ctx.schedule } catch { return undefined }
568
+ })()
569
+ if (!schedule || typeof schedule.create !== 'function') return { ok: false, error: 'schedule 服务不可用' }
570
+ const prompt = String(text ?? '').trim()
571
+ if (!prompt) return { ok: false, error: '没有要说的话' }
572
+ const stamp = new Date(Date.now() + 60_000).toISOString().replace(/\.\d{3}Z$/, 'Z')
573
+ const rule = `DTSTART:${stamp}\nRRULE:FREQ=DAILY;COUNT=1`
574
+ const target = { kind: 'new' }
575
+ const title = '她突然想说一句'
576
+ const tries = [
577
+ { title, prompt, target, timing: { kind: 'once', at: stamp } },
578
+ { title, prompt, target, timing: { kind: 'rrule', rrule: rule } },
579
+ { title, prompt, target, timing: { kind: 'at', at: stamp } },
580
+ { title, prompt, target, timing: { kind: 'date', at: stamp } },
581
+ { prompt, target, timing: { kind: 'once', at: stamp } },
582
+ ]
583
+ const errors = []
584
+ for (const input of tries) {
585
+ try {
586
+ const task = await schedule.create(input)
587
+ const id = task?.id ?? task?.value?.id ?? task?.taskId
588
+ if (id && typeof schedule.run === 'function') {
589
+ try {
590
+ await schedule.run({ id })
591
+ } catch (error) {
592
+ errors.push(`run: ${String(error?.message ?? error).slice(0, 120)}`)
593
+ }
594
+ }
595
+ audit({ kind: 'speak-now', id, prompt: prompt.slice(0, 60) })
596
+ return { ok: true, id, shape: Object.keys(input).join(',') }
597
+ } catch (error) {
598
+ errors.push(String(error?.message ?? error).slice(0, 160))
599
+ }
600
+ }
601
+ return { ok: false, error: errors.join(' | ') }
602
+ }
603
+
554
604
  /** 看屏幕:设置页读这个拿配置和状态,写完立刻生效,不用重启 */
555
605
  ctx.effect(() => {
556
606
  const webServer = ctx.webServer ?? ctx.get('webServer')
@@ -1241,8 +1291,13 @@ export function apply(ctx, config = {}) {
1241
1291
  sc.talkAt = now
1242
1292
  sc.talkToday = (Number(sc.talkToday) || 0) + 1
1243
1293
  sc.hook = hook
1244
- state.urges = { kind: 'share', until: now + 15 * 60_000, note: hook }
1245
1294
  audit({ kind: 'screen-worthy', hook, title: String(shot.title ?? '').slice(0, 60) })
1295
+ if (settings.screen.speak === 'always') {
1296
+ const said = await speakNow(speakPrompt(hook, shot.title))
1297
+ audit({ kind: 'screen-speak', ok: said.ok, error: said.error })
1298
+ } else {
1299
+ state.urges = { kind: 'share', until: now + 15 * 60_000, note: hook }
1300
+ }
1246
1301
  }
1247
1302
  }
1248
1303
  audit({ kind: 'screen-look', auto: true, title: String(shot.title ?? '').slice(0, 60) })