feat: companion 加入工作事件反應,並讓主動頻率依個性調整

- 測試指令失敗後轉通過、有用工具的回合結束時,以 toast 反應並提升心情
- 反應越常說越容易疲乏,冷卻拉長到暫停,休息後恢復
- 主動頻率與每日上限依屬性與外向性調整;待辦到期與額度警告不受影響
- core.json 可用 freq 覆寫各觸發倍率

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
root
2026-10-12 16:15:03 +08:00
co-authored by Claude Sonnet 5.5
parent fb6fb4f61f
commit 134e708d8a
8 changed files with 433 additions and 17 deletions
+6 -1
View File
@@ -6,6 +6,7 @@ import { engineFs } from './companion/engine-fs'
let companion: ReturnType<typeof createCompanion> | undefined
let replying = false
let usedTools = false
let typedAt = 0
let timer: { cancel(): void } | undefined
@@ -61,18 +62,22 @@ export const register: Register = on => {
on('turn.start', async ($, e, next) => {
replying = true
usedTools = false
return next(e)
})
on('turn.complete', async ($, e, next) => {
replying = false
// 只有主迴圈正常答完、且這輪用過工具,才算做完一件事
if (e.reason === 'answer' && !e.agentId) companion?.onTurnComplete(usedTools).catch(() => {})
return next(e)
})
// 連續工具失敗會觸發關心,並影響心情
on('tool.call', async ($, e, next) => {
const r = await next(e)
companion?.onToolResult(!r.isError).catch(() => {})
if (!e.agentId) usedTools = true
companion?.onToolResult(!r.isError, { command: e.tool === 'Bash' ? e.command : undefined }).catch(() => {})
return r
})