@cmach_socket/opencode-qq-bot 0.9.2 → 0.10.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.
Files changed (49) hide show
  1. package/NOTICE +0 -1
  2. package/README.md +43 -20
  3. package/chat-overrides.example.json +3 -3
  4. package/package.json +6 -2
  5. package/src/chat.ts +5 -0
  6. package/src/commands.ts +88 -1
  7. package/src/config/fields.ts +68 -5
  8. package/src/config/live.ts +33 -3
  9. package/src/config/registry.ts +32 -0
  10. package/src/config/store.ts +6 -11
  11. package/src/config/types.ts +29 -1
  12. package/src/config.ts +8 -1
  13. package/src/diary/command.ts +21 -20
  14. package/src/diary/format.ts +18 -1
  15. package/src/diary/scheduler.ts +7 -7
  16. package/src/diary/scope.ts +1 -1
  17. package/src/diary/summary.ts +39 -38
  18. package/src/emoji/collection.ts +33 -1
  19. package/src/fs/atomic.ts +82 -0
  20. package/src/home.ts +6 -2
  21. package/src/index.ts +113 -45
  22. package/src/keepalive.ts +60 -2
  23. package/src/known-secrets.ts +20 -0
  24. package/src/logger.ts +19 -3
  25. package/src/model-view.ts +4 -15
  26. package/src/naplink/history.ts +12 -7
  27. package/src/overrides.ts +268 -51
  28. package/src/panel/api.ts +79 -7
  29. package/src/panel/documents.ts +622 -0
  30. package/src/panel/server.ts +18 -1
  31. package/src/panel/status.ts +10 -3
  32. package/src/restartable.ts +74 -0
  33. package/src/safe-object.ts +48 -0
  34. package/src/sensitive.ts +31 -2
  35. package/src/session/find.ts +3 -2
  36. package/src/session/manager.ts +646 -43
  37. package/src/session/proactive.ts +3 -1
  38. package/src/session/prompt.ts +5 -13
  39. package/src/session/soul-guard.ts +162 -0
  40. package/src/session/soul.ts +78 -13
  41. package/src/state-lock.ts +74 -0
  42. package/src/time-format.ts +45 -0
  43. package/src/tools/policy.ts +65 -24
  44. package/src/tools/qq.ts +20 -12
  45. package/web/dist/assets/index-B-3ZGYMq.js +8 -0
  46. package/web/dist/assets/index-C5lRsdbz.css +1 -0
  47. package/web/dist/index.html +2 -2
  48. package/web/dist/assets/index-7eMQEM7-.css +0 -1
  49. package/web/dist/assets/index-DCkgUY7y.js +0 -15
package/src/tools/qq.ts CHANGED
@@ -4,7 +4,7 @@ import { isTargetAllowed } from "../access"
4
4
  import { delay } from "../async"
5
5
  import { type ChatTarget, targetKey, targetLabel } from "../chat"
6
6
  import type { QQBotConfig } from "../config"
7
- import { dateKey, isDateKey } from "../diary/format"
7
+ import { chatLabel, dateKey, isDateKey } from "../diary/format"
8
8
  import { isDiaryScopeChat } from "../diary/scope"
9
9
  import type { DiaryStore } from "../diary/store"
10
10
  import {
@@ -192,11 +192,13 @@ function sanitizeDiaryBody(body: string): string {
192
192
  return neutralizeStructureTags(lines.join("\n"))
193
193
  }
194
194
 
195
- /** 组装给模型看的日记正文:标题加正文,超长时按自然边界截断。 */
196
- function formatDiaryBody(date: string, title: string, body: string): string {
195
+ /** 组装给模型看的日记正文:带聊天标识的标题加正文,超长时按自然边界截断。 */
196
+ function formatDiaryBody(date: string, chat: string, title: string, body: string): string {
197
197
  const plain = sanitizeDiaryBody(body)
198
198
  const clipped = softTruncate(plain, DIARY_READ_MAX_CHARS)
199
- return [`${date} 的日记:${sanitizeUntrustedText(title)}`, "", clipped].join("\n")
199
+ return [`${chatLabel(chat)} ${date} 的日记:${sanitizeUntrustedText(title)}`, "", clipped].join(
200
+ "\n",
201
+ )
200
202
  }
201
203
 
202
204
  /** 按目标类型把消息投递出去:群聊与私聊走不同的 API。 */
@@ -1105,7 +1107,7 @@ export async function registerTools(deps: ToolDeps): Promise<{ dispose(): Promis
1105
1107
  const diaryMissing = async (chat: string, date: string): Promise<string> => {
1106
1108
  const available = (await diaryStore.list(chat, 10)).map((item) => item.date)
1107
1109
  const hint = available.length > 0 ? `(可用的日期:${available.join("、")})` : ""
1108
- return `error: 没有找到 ${date} 的日记${hint}`
1110
+ return `error: 没有找到 ${chatLabel(chat)} ${date} 的日记${hint}`
1109
1111
  }
1110
1112
 
1111
1113
  editor.add({
@@ -1136,7 +1138,7 @@ export async function registerTools(deps: ToolDeps): Promise<{ dispose(): Promis
1136
1138
  body: content,
1137
1139
  source: "model",
1138
1140
  })
1139
- return text(`已写入 ${date} 的日记:${entry.title}`)
1141
+ return text(`已写入 ${chatLabel(targetKey(target))} ${date} 的日记:${entry.title}`)
1140
1142
  },
1141
1143
  })
1142
1144
 
@@ -1160,13 +1162,13 @@ export async function registerTools(deps: ToolDeps): Promise<{ dispose(): Promis
1160
1162
  const date = input.date?.trim()
1161
1163
  if (!date) {
1162
1164
  const latest = await diaryStore.latest(chat)
1163
- if (!latest) return text("error: 这个聊天还没有日记")
1164
- return text(formatDiaryBody(latest.date, latest.title, latest.body))
1165
+ if (!latest) return text(`error: ${chatLabel(chat)} 还没有日记`)
1166
+ return text(formatDiaryBody(latest.date, chat, latest.title, latest.body))
1165
1167
  }
1166
1168
  if (!isDateKey(date)) return text(`error: 日期格式不对:${date},请用 YYYY-MM-DD`)
1167
1169
  const entry = await diaryStore.read(chat, date)
1168
1170
  if (!entry) return text(await diaryMissing(chat, date))
1169
- return text(formatDiaryBody(entry.date, entry.title, entry.body))
1171
+ return text(formatDiaryBody(entry.date, chat, entry.title, entry.body))
1170
1172
  },
1171
1173
  })
1172
1174
 
@@ -1187,9 +1189,15 @@ export async function registerTools(deps: ToolDeps): Promise<{ dispose(): Promis
1187
1189
  const target = diaryTarget(context.sessionID)
1188
1190
  if (!target) return text("error: 日记只在 owner 自己的私聊里可用")
1189
1191
  const days = Number.isInteger(input.days) && (input.days ?? 0) > 0 ? (input.days ?? 7) : 7
1190
- const entries = await diaryStore.list(targetKey(target), days)
1191
- if (entries.length === 0) return text("这个聊天还没有日记。")
1192
- return text(entries.map((entry) => `${entry.date} ${entry.title}`).join("\n"))
1192
+ const chat = targetKey(target)
1193
+ const entries = await diaryStore.list(chat, days)
1194
+ if (entries.length === 0) return text(`${chatLabel(chat)} 还没有日记。`)
1195
+ return text(
1196
+ [
1197
+ `${chatLabel(chat)} 最近的日记`,
1198
+ ...entries.map((entry) => `${entry.date} ${entry.title}`),
1199
+ ].join("\n"),
1200
+ )
1193
1201
  },
1194
1202
  })
1195
1203
  }