memory-eternal 0.22.0 → 0.23.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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/README.md +28 -1
- package/README.zh-CN.md +28 -1
- package/cursor-extension/package.json +1 -1
- package/dsh-tui-plugin/dsh-plugin.json +1 -1
- package/dsh-tui-plugin/package.json +1 -1
- package/index.js +78 -0
- package/lib/api.js +156 -17
- package/lib/client.js +93 -23
- package/lib/news-digest.js +109 -0
- package/lib/news-follows.js +523 -0
- package/lib/vault.js +46 -3
- package/orca-plugin/orca-plugin.json +1 -1
- package/package.json +2 -2
- package/web/app.js +98 -28
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "memory-eternal",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.23.0",
|
|
5
5
|
"description": "记忆核心(Memory Eternal):对话结束后自动沉淀知识卡到本地记忆库(~/.dsh/memory-vault),支持检索 / 召回 / 审核中心。",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "EternalNight996",
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/EternalNight996/memory-eternal/stargazers)
|
|
4
4
|
[](https://www.npmjs.com/package/memory-eternal)
|
|
5
|
-
[](https://github.com/EternalNight996/memory-eternal/releases)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
8
|
**English (default)** · [简体中文](README.zh-CN.md)
|
|
@@ -156,3 +156,30 @@ Not everything should be injected into every session. Core memory is the small,
|
|
|
156
156
|
## 📄 License
|
|
157
157
|
|
|
158
158
|
MIT — use it, self-host it, build on it.
|
|
159
|
+
|
|
160
|
+
## 🖋 Author's Quotes
|
|
161
|
+
|
|
162
|
+
_Verses from 《蛊真人》(Reverend Insanity). Kept in the original Chinese — a translation would lose the meter. Also rotating at the bottom of the panel's left rail._
|
|
163
|
+
|
|
164
|
+
> 落魄谷中寒风吹,春秋蝉鸣少年归。<br>
|
|
165
|
+
> 荡魂山处石人泪,定仙游走魔向北。<br>
|
|
166
|
+
> 逆流河上万仙退,爱情不敌坚持泪。<br>
|
|
167
|
+
> 宿命天成命中败,仙尊悔而我不悔。
|
|
168
|
+
|
|
169
|
+
> 早岁已知世事艰,仍许飞鸿荡云间。
|
|
170
|
+
|
|
171
|
+
> 男儿不展凌云志,空负天生八尺躯。
|
|
172
|
+
|
|
173
|
+
> 千古地仙随风逝,昔日三王归青冢。<br>
|
|
174
|
+
> 阳莽悍陨谁无败?卷土重来再称王。
|
|
175
|
+
|
|
176
|
+
> 天河一挂淘龙鱼,逆天独行顾八荒。<br>
|
|
177
|
+
> 今朝暂且展翼去,明朝飞仙笞凤凰!
|
|
178
|
+
|
|
179
|
+
> 独帜入渊深未知,身似浮萍命难持。<br>
|
|
180
|
+
> 千舟皆朝归海处,一苇青拨戏浪巅。<br>
|
|
181
|
+
> 惊鸿四散鱼逃尽,唯有残帆傲此间。<br>
|
|
182
|
+
> 待到天开云雾散,负手直望笑苍天。
|
|
183
|
+
|
|
184
|
+
<p align="right"><sub>——《蛊真人》· 大爱仙尊</sub></p>
|
|
185
|
+
|
package/README.zh-CN.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/EternalNight996/memory-eternal/stargazers)
|
|
4
4
|
[](https://www.npmjs.com/package/memory-eternal)
|
|
5
|
-
[](https://github.com/EternalNight996/memory-eternal/releases)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
|
|
8
8
|
[English (default)](README.md) · **简体中文(镜像)**
|
|
@@ -156,3 +156,30 @@ npx -y -p memory-eternal dsh-memory tui # 终端里的实时待审队列
|
|
|
156
156
|
## 📄 License
|
|
157
157
|
|
|
158
158
|
MIT —— 随便用、随便自托管、随便二次开发。
|
|
159
|
+
|
|
160
|
+
## 🖋 作者语录
|
|
161
|
+
|
|
162
|
+
_「大爱」二字,是全篇最大的反讽。面板左栏底部同步轮播。_
|
|
163
|
+
|
|
164
|
+
> 落魄谷中寒风吹,春秋蝉鸣少年归。<br>
|
|
165
|
+
> 荡魂山处石人泪,定仙游走魔向北。<br>
|
|
166
|
+
> 逆流河上万仙退,爱情不敌坚持泪。<br>
|
|
167
|
+
> 宿命天成命中败,仙尊悔而我不悔。
|
|
168
|
+
|
|
169
|
+
> 早岁已知世事艰,仍许飞鸿荡云间。
|
|
170
|
+
|
|
171
|
+
> 男儿不展凌云志,空负天生八尺躯。
|
|
172
|
+
|
|
173
|
+
> 千古地仙随风逝,昔日三王归青冢。<br>
|
|
174
|
+
> 阳莽悍陨谁无败?卷土重来再称王。
|
|
175
|
+
|
|
176
|
+
> 天河一挂淘龙鱼,逆天独行顾八荒。<br>
|
|
177
|
+
> 今朝暂且展翼去,明朝飞仙笞凤凰!
|
|
178
|
+
|
|
179
|
+
> 独帜入渊深未知,身似浮萍命难持。<br>
|
|
180
|
+
> 千舟皆朝归海处,一苇青拨戏浪巅。<br>
|
|
181
|
+
> 惊鸿四散鱼逃尽,唯有残帆傲此间。<br>
|
|
182
|
+
> 待到天开云雾散,负手直望笑苍天。
|
|
183
|
+
|
|
184
|
+
<p align="right"><sub>——《蛊真人》· 大爱仙尊</sub></p>
|
|
185
|
+
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "memory-eternal",
|
|
3
3
|
"displayName": "Memory Atlas",
|
|
4
4
|
"description": "Memory-eternal: open the local Memory Atlas library, review queue and knowledge graph in a Cursor/VS Code webview.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.23.0",
|
|
6
6
|
"publisher": "EternalNight996",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "urn:dsh-std:community-draft:dsh-plugin:0.15",
|
|
3
3
|
"id": "memory-eternal-tui",
|
|
4
4
|
"name": "memory-eternal-tui",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.23.0",
|
|
6
6
|
"manifestVersion": "0.15",
|
|
7
7
|
"description": "Open Memory Atlas from dsh-TUI: native /audit scene plus browser launcher.",
|
|
8
8
|
"facets": {
|
package/index.js
CHANGED
|
@@ -58,6 +58,11 @@ export const Config = z.object({
|
|
|
58
58
|
coreMemoryEnabled: z.boolean().default(true),
|
|
59
59
|
coreMemoryLimit: z.number().min(1).max(20).default(6),
|
|
60
60
|
coreMemoryMaxChars: z.number().min(200).max(10000).default(2000),
|
|
61
|
+
// 关注摘要推送:开启后按间隔抓取「新闻关注」,有新内容时注入 systemPrompt,
|
|
62
|
+
// 让 Agent 在下一轮主动告诉用户。**默认关闭** —— 这是会打扰人的功能,必须用户显式开启。
|
|
63
|
+
newsDigestEnabled: z.boolean().default(false),
|
|
64
|
+
newsDigestIntervalMinutes: z.number().min(30).max(10080).default(720),
|
|
65
|
+
newsDigestMaxItems: z.number().min(1).max(10).default(5),
|
|
61
66
|
// 技能卡(kind=skill):从「本机实际安装/可用的技能」生成卡,强制待审。
|
|
62
67
|
// 不由 agent 对话沉淀(见 lib/capture.js AGENT_CARD_KINDS 不含 skill);
|
|
63
68
|
// 默认开:宿主启动 / 技能安装变化时后台同步,新技能自动进审核中心。
|
|
@@ -1082,6 +1087,75 @@ export function apply(ctx, config) {
|
|
|
1082
1087
|
}
|
|
1083
1088
|
}, 'memory-eternal: core memory section')
|
|
1084
1089
|
|
|
1090
|
+
// -- 2c. 关注摘要:默认关闭;开启后按间隔抓取,只把「还没送过」的那一份推一轮 ----
|
|
1091
|
+
// 送达方式与核心记忆一致:systemPrompt 分段。不新增宿主能力,也不往会话里插消息。
|
|
1092
|
+
ctx.effect(() => {
|
|
1093
|
+
let disposeSection = null
|
|
1094
|
+
let timer = null
|
|
1095
|
+
let alive = true
|
|
1096
|
+
let lastText = ''
|
|
1097
|
+
const clearSection = () => {
|
|
1098
|
+
if (!disposeSection) return
|
|
1099
|
+
const dispose = disposeSection
|
|
1100
|
+
disposeSection = null
|
|
1101
|
+
dispose()
|
|
1102
|
+
}
|
|
1103
|
+
const render = async () => {
|
|
1104
|
+
try {
|
|
1105
|
+
const cfg = settings.get() ?? {}
|
|
1106
|
+
if (cfg.enabled === false || cfg.newsDigestEnabled !== true) { clearSection(); lastText = ''; return }
|
|
1107
|
+
const { readDigest, digestPrompt } = await import('./lib/news-digest.js')
|
|
1108
|
+
const d = await readDigest(vaultDir())
|
|
1109
|
+
if (!alive) return
|
|
1110
|
+
// 没有新内容、或这一份已经被某一轮消费过 → 不注入(宁可不提,也不反复念旧闻)
|
|
1111
|
+
if (!d || !Array.isArray(d.items) || !d.items.length || Number(d.consumedAt) >= Number(d.generatedAt)) {
|
|
1112
|
+
clearSection(); lastText = ''
|
|
1113
|
+
return
|
|
1114
|
+
}
|
|
1115
|
+
const text = digestPrompt(d, { maxItems: Number(cfg.newsDigestMaxItems) || 5 })
|
|
1116
|
+
if (!text) { clearSection(); lastText = ''; return }
|
|
1117
|
+
if (text === lastText) return
|
|
1118
|
+
lastText = text
|
|
1119
|
+
clearSection()
|
|
1120
|
+
disposeSection = ctx.systemPrompt.section({ name: 'memory-eternal: news-digest', order: 130, text })
|
|
1121
|
+
} catch { /* 摘要失败绝不能影响正常对话 */ }
|
|
1122
|
+
}
|
|
1123
|
+
const tick = async () => {
|
|
1124
|
+
const cfg = settings.get() ?? {}
|
|
1125
|
+
if (cfg.enabled === false || cfg.newsDigestEnabled !== true) { await render(); return }
|
|
1126
|
+
try {
|
|
1127
|
+
const { readDigest, buildDigest } = await import('./lib/news-digest.js')
|
|
1128
|
+
const d = await readDigest(vaultDir())
|
|
1129
|
+
const intervalMs = Math.max(30, Number(cfg.newsDigestIntervalMinutes) || 720) * 60000
|
|
1130
|
+
if (!d || Date.now() - (Number(d.generatedAt) || 0) >= intervalMs) {
|
|
1131
|
+
await buildDigest(vaultDir(), {
|
|
1132
|
+
windowHours: Math.max(1, Math.round(intervalMs / 3600000)),
|
|
1133
|
+
maxItems: Number(cfg.newsDigestMaxItems) || 5,
|
|
1134
|
+
})
|
|
1135
|
+
}
|
|
1136
|
+
} catch { /* 抓取失败就等下一个周期,不打扰用户 */ }
|
|
1137
|
+
await render()
|
|
1138
|
+
}
|
|
1139
|
+
tick()
|
|
1140
|
+
timer = setInterval(tick, 60000)
|
|
1141
|
+
if (timer && typeof timer.unref === 'function') timer.unref()
|
|
1142
|
+
// 一轮会话开始 = 这份摘要已经进过 systemPrompt,标记消费,下一轮不再重复。
|
|
1143
|
+
const onClaim = async () => {
|
|
1144
|
+
try {
|
|
1145
|
+
const { readDigest, consumeDigest } = await import('./lib/news-digest.js')
|
|
1146
|
+
const d = await readDigest(vaultDir())
|
|
1147
|
+
if (d && Number(d.generatedAt) > Number(d.consumedAt || 0)) await consumeDigest(vaultDir(), d.generatedAt)
|
|
1148
|
+
} catch { /* ignore */ }
|
|
1149
|
+
}
|
|
1150
|
+
if (typeof ctx.on === 'function') ctx.on('agent/inbox/claimed', onClaim)
|
|
1151
|
+
return () => {
|
|
1152
|
+
alive = false
|
|
1153
|
+
if (timer) clearInterval(timer)
|
|
1154
|
+
if (typeof ctx.off === 'function') { try { ctx.off('agent/inbox/claimed', onClaim) } catch { /* 已卸载 */ } }
|
|
1155
|
+
clearSection()
|
|
1156
|
+
}
|
|
1157
|
+
}, 'memory-eternal: news digest section')
|
|
1158
|
+
|
|
1085
1159
|
const tools = ctx.get('tools')
|
|
1086
1160
|
if (tools !== undefined) {
|
|
1087
1161
|
tools.register(defineTool({
|
|
@@ -1360,6 +1434,10 @@ export function apply(ctx, config) {
|
|
|
1360
1434
|
recallEmbedding: cfg.recallEmbedding || '',
|
|
1361
1435
|
sessionBudgetChars: cfg.sessionBudgetChars ?? 80000,
|
|
1362
1436
|
skillCardsAutoSync: cfg.skillCardsAutoSync !== false,
|
|
1437
|
+
// 关注摘要推送(默认关;覆盖测试要求每个 Config 字段都能被 /config 读出)
|
|
1438
|
+
newsDigestEnabled: cfg.newsDigestEnabled === true,
|
|
1439
|
+
newsDigestIntervalMinutes: cfg.newsDigestIntervalMinutes ?? 720,
|
|
1440
|
+
newsDigestMaxItems: cfg.newsDigestMaxItems ?? 5,
|
|
1363
1441
|
}
|
|
1364
1442
|
const descriptor = (ctx.get('settings') ?? {}).describe?.({ redactSecrets: true }) ?? []
|
|
1365
1443
|
const me = descriptor.find((d) => d.ns === 'memory-eternal')
|
package/lib/api.js
CHANGED
|
@@ -17,9 +17,11 @@ import fs, { readFileSync } from 'node:fs'
|
|
|
17
17
|
import path from 'node:path'
|
|
18
18
|
import { fileURLToPath } from 'node:url'
|
|
19
19
|
import { spawn } from 'node:child_process'
|
|
20
|
-
import { listCards, countCards, readCard, search, searchAll, graph, graphAll, graphLevel, LEVEL_ERR_PATH, LEVEL_ERR_STALE, overview, exportCards, deleteCard, writeCard, parseCard, stats, optimizeCandidates, optimizeApply, addFeedback, dailyCounts, mergeCards, ensureVault, auditQueue, recycleList, purgeExpired, setCardStatus, setCardKind, restoreCard, mainStoreBodies, updateCardContent, reviseCard } from './vault.js'
|
|
20
|
+
import { listCards, countCards, readCard, search, searchAll, graph, graphAll, graphLevel, LEVEL_ERR_PATH, LEVEL_ERR_STALE, overview, exportCards, deleteCard, writeCard, parseCard, stats, optimizeCandidates, optimizeApply, addFeedback, dailyCounts, mergeCards, ensureVault, auditQueue, recycleList, purgeExpired, purgeAllRecycle, setCardStatus, setCardKind, restoreCard, mainStoreBodies, updateCardContent, reviseCard } from './vault.js'
|
|
21
21
|
import { compressExcerpt, guessRawKind, DEFAULT_CAPTURE_MAX_TOKENS } from './capture.js'
|
|
22
22
|
import { buildDiagnostics } from './feedback.js'
|
|
23
|
+
import { FOLLOW_DOMAINS, parseFollowIntent, listFollows, saveFollow, removeFollow, refreshFollows, followItems } from './news-follows.js'
|
|
24
|
+
import { buildDigest, readDigest, digestPrompt } from './news-digest.js'
|
|
23
25
|
import { getSetupStatus, runSetup, mcpAgentAction } from './setup.js'
|
|
24
26
|
import { ledgerSummary } from './ledger.js'
|
|
25
27
|
import { backupDb, dbStatus, rebuildGuidance, withDbRetry } from './db.js'
|
|
@@ -199,7 +201,30 @@ export function emptyNumericFields(patch, dict = {}) {
|
|
|
199
201
|
* **真的会写库**的路由(/card、/cards、/search 这些是读,绝不能拦)。
|
|
200
202
|
* 用途:库不可写时短路径失败;撞锁(SQLITE_BUSY)时做应用层异步重试。
|
|
201
203
|
*/
|
|
202
|
-
const DB_WRITE_ROUTES = /^\/(delete|merge|write|import|card\/update|card\/revise|refine-apply|refine-goals-keep|refine-junk-purge|optimize-execute|feedback|skills\/sync|audit\/(approve|reject)|recycle\/(restore|purge|purge-expired)|backup)$/
|
|
204
|
+
const DB_WRITE_ROUTES = /^\/(delete|merge|write|import|card\/update|card\/revise|refine-apply|refine-goals-keep|refine-junk-purge|optimize-execute|feedback|skills\/sync|audit\/(approve|reject)|recycle\/(restore|purge|purge-expired|purge-all)|backup)$/
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 解析回收站保留期参数 `?days=`。
|
|
208
|
+
*
|
|
209
|
+
* issue #57 的根因就藏在一行 `Number(query.get('days')) || 30` 里:`Number('0')` 是 0,
|
|
210
|
+
* 而 `0 || 30` 又变回 30 —— 前端「清空回收站」传的 0 被静默升级成 30 天保留期,
|
|
211
|
+
* 刚删的卡一张都不清,用户看到的就是「点了没反应」。
|
|
212
|
+
*
|
|
213
|
+
* 这里把「没传」与「显式传 0」分开;非法输入交给调用方转 400。
|
|
214
|
+
* @param {string|null|undefined} raw
|
|
215
|
+
* @param {number} fallback 未提供时的默认保留天数
|
|
216
|
+
* @returns {number}
|
|
217
|
+
*/
|
|
218
|
+
export function parseRetentionDays(raw, fallback = 30) {
|
|
219
|
+
if (raw === null || raw === undefined || raw === '') return fallback
|
|
220
|
+
const n = Number(raw)
|
|
221
|
+
if (!Number.isFinite(n) || n < 0) {
|
|
222
|
+
const err = new Error('days 必须是非负数字')
|
|
223
|
+
err.code = 'BAD_DAYS'
|
|
224
|
+
throw err
|
|
225
|
+
}
|
|
226
|
+
return n
|
|
227
|
+
}
|
|
203
228
|
|
|
204
229
|
export function createApi(deps = {}) {
|
|
205
230
|
const vaultDir = deps.vaultDir ?? (() => '')
|
|
@@ -664,26 +689,127 @@ export function createApi(deps = {}) {
|
|
|
664
689
|
}
|
|
665
690
|
case '/news/feed': {
|
|
666
691
|
// 真实 AI 资讯:服务端按固定白名单抓 RSS / HN,缓存 20 分钟;只存摘要与外链。
|
|
692
|
+
// 带 follows=1 时主 feed 允许降级:9 个 RSS 全挂也不该把用户的 GitHub/arXiv 订阅一起吞掉。
|
|
693
|
+
const wantFollows = query.get('follows') === '1'
|
|
667
694
|
try {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
695
|
+
let data
|
|
696
|
+
try {
|
|
697
|
+
data = await getNewsFeed(vaultRoot, {
|
|
698
|
+
period: query.get('period') === 'month' ? 'month' : 'today',
|
|
699
|
+
type: query.get('type') || '',
|
|
700
|
+
q: query.get('q') || '',
|
|
701
|
+
// lang 口径:'' / 'all' = 不过滤(一次请求拿中英全部条目);zh / en 为显式过滤。
|
|
702
|
+
lang: (() => {
|
|
703
|
+
const raw = String(query.get('lang') == null ? '' : query.get('lang')).trim().toLowerCase()
|
|
704
|
+
if (raw === 'en') return 'en'
|
|
705
|
+
if (raw === 'zh') return 'zh'
|
|
706
|
+
return ''
|
|
707
|
+
})(),
|
|
708
|
+
force: query.get('force') === '1',
|
|
709
|
+
})
|
|
710
|
+
} catch (e) {
|
|
711
|
+
if (!wantFollows) throw e
|
|
712
|
+
// 降级:主 feed 拉不到就返回空集合 + 可读错误,但继续给关注结果。
|
|
713
|
+
data = {
|
|
714
|
+
ok: true, period: 'today', lang: '', ranking: false, degraded: true,
|
|
715
|
+
items: [], types: [], counts: {}, fetchedAt: 0, stale: true,
|
|
716
|
+
errors: ['主 feed 暂不可用:' + String((e && e.message) || e)], sources: [],
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
// follows=1:把「关注」命中的条目并进主 feed(同一套 item 形状,前端零改动)。
|
|
720
|
+
// 关注抓取有 30 分钟 TTL,所以这里不会每次都打外网。
|
|
721
|
+
if (wantFollows) {
|
|
722
|
+
const follows = await refreshFollows(vaultRoot)
|
|
723
|
+
const extra = await followItems(vaultRoot, follows)
|
|
724
|
+
const seen = new Set((data.items || []).map((x) => x.url))
|
|
725
|
+
data = {
|
|
726
|
+
...data,
|
|
727
|
+
items: [...extra.filter((x) => x.url && !seen.has(x.url)), ...(data.items || [])].slice(0, 160),
|
|
728
|
+
follows: follows.map((f) => ({
|
|
729
|
+
id: f.id, label: f.label, query: f.query, domains: f.domains,
|
|
730
|
+
count: (f.cache && f.cache.items ? f.cache.items : []).length,
|
|
731
|
+
errors: (f.cache && f.cache.errors) || [],
|
|
732
|
+
fetchedAt: (f.cache && f.cache.fetchedAt) || 0,
|
|
733
|
+
})),
|
|
734
|
+
}
|
|
735
|
+
}
|
|
681
736
|
json(res, 200, data)
|
|
682
737
|
} catch (e) {
|
|
683
738
|
json(res, 502, { ok: false, error: '资讯源暂不可用:' + String((e && e.message) || e) })
|
|
684
739
|
}
|
|
685
740
|
return
|
|
686
741
|
}
|
|
742
|
+
case '/news/follows': {
|
|
743
|
+
// GET 列表;POST 创建;DELETE 删除。创建只接受「已解析好的」结构化入参,
|
|
744
|
+
// 域必须来自白名单枚举(parseFollowIntent 也只产出枚举内的值)。
|
|
745
|
+
if (req.method === 'DELETE') {
|
|
746
|
+
const id = String(query.get('id') || '').trim()
|
|
747
|
+
if (!id) return json(res, 400, { ok: false, error: '缺少 id' })
|
|
748
|
+
const out = await removeFollow(vaultRoot, id)
|
|
749
|
+
return json(res, 200, { ok: true, ...out })
|
|
750
|
+
}
|
|
751
|
+
if (req.method === 'POST') {
|
|
752
|
+
const body = await readBody(req)
|
|
753
|
+
try {
|
|
754
|
+
const out = await saveFollow(vaultRoot, {
|
|
755
|
+
query: body.query, domains: body.domains, label: body.label, sourceIds: body.sourceIds,
|
|
756
|
+
})
|
|
757
|
+
return json(res, 200, { ok: true, ...out, domainsEnum: FOLLOW_DOMAINS })
|
|
758
|
+
} catch (e) {
|
|
759
|
+
return json(res, 400, { ok: false, error: String((e && e.message) || e) })
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
const follows = await listFollows(vaultRoot)
|
|
763
|
+
return json(res, 200, {
|
|
764
|
+
ok: true,
|
|
765
|
+
domains: FOLLOW_DOMAINS,
|
|
766
|
+
follows: follows.map((f) => ({
|
|
767
|
+
id: f.id, label: f.label, query: f.query, domains: f.domains, createdAt: f.createdAt, lastRunAt: f.lastRunAt,
|
|
768
|
+
count: (f.cache && f.cache.items ? f.cache.items : []).length,
|
|
769
|
+
errors: (f.cache && f.cache.errors) || [],
|
|
770
|
+
})),
|
|
771
|
+
})
|
|
772
|
+
}
|
|
773
|
+
case '/news/follows/preview': {
|
|
774
|
+
// 只解析、不落库:用户先看到「我理解成了什么」,再决定要不要订阅。
|
|
775
|
+
if (req.method !== 'POST') return json(res, 405, { ok: false, error: '需 POST' })
|
|
776
|
+
const body = await readBody(req)
|
|
777
|
+
return json(res, 200, { ok: true, parsed: parseFollowIntent(body.text || ''), domainsEnum: FOLLOW_DOMAINS })
|
|
778
|
+
}
|
|
779
|
+
case '/news/follows/refresh': {
|
|
780
|
+
if (req.method !== 'POST') return json(res, 405, { ok: false, error: '需 POST' })
|
|
781
|
+
const body = await readBody(req).catch(() => ({}))
|
|
782
|
+
const follows = await refreshFollows(vaultRoot, { force: body && body.force === true })
|
|
783
|
+
return json(res, 200, {
|
|
784
|
+
ok: true,
|
|
785
|
+
follows: follows.map((f) => ({
|
|
786
|
+
id: f.id, label: f.label, query: f.query, domains: f.domains,
|
|
787
|
+
count: (f.cache && f.cache.items ? f.cache.items : []).length,
|
|
788
|
+
errors: (f.cache && f.cache.errors) || [],
|
|
789
|
+
})),
|
|
790
|
+
})
|
|
791
|
+
}
|
|
792
|
+
case '/news/digest': {
|
|
793
|
+
// GET:读当前快照;POST:现在生成一份(配置页「立即生成」按钮用,也是开启前的预览)。
|
|
794
|
+
if (req.method === 'POST') {
|
|
795
|
+
const body = await readBody(req).catch(() => ({}))
|
|
796
|
+
const cfg = (getSettings && getSettings()) || {}
|
|
797
|
+
const intervalMin = Math.max(30, Number(cfg.newsDigestIntervalMinutes) || 720)
|
|
798
|
+
try {
|
|
799
|
+
const digest = await buildDigest(vaultRoot, {
|
|
800
|
+
windowHours: Number(body.windowHours) || Math.max(1, Math.round(intervalMin / 60)),
|
|
801
|
+
maxItems: Number(body.maxItems) || Number(cfg.newsDigestMaxItems) || 5,
|
|
802
|
+
force: body.force === true,
|
|
803
|
+
})
|
|
804
|
+
return json(res, 200, { ok: true, digest, text: digestPrompt(digest, { maxItems: Number(cfg.newsDigestMaxItems) || 5 }) })
|
|
805
|
+
} catch (e) {
|
|
806
|
+
return json(res, 502, { ok: false, error: '生成摘要失败:' + String((e && e.message) || e) })
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
const digest = await readDigest(vaultRoot)
|
|
810
|
+
const cfgGet = (getSettings && getSettings()) || {}
|
|
811
|
+
return json(res, 200, { ok: true, digest, text: digest ? digestPrompt(digest, { maxItems: Number(cfgGet.newsDigestMaxItems) || 5 }) : '' })
|
|
812
|
+
}
|
|
687
813
|
case '/news/feed/refresh': {
|
|
688
814
|
if (req.method !== 'POST') return json(res, 405, { ok: false, error: '需 POST' })
|
|
689
815
|
try {
|
|
@@ -876,11 +1002,24 @@ export function createApi(deps = {}) {
|
|
|
876
1002
|
return
|
|
877
1003
|
}
|
|
878
1004
|
case '/recycle/purge-expired': {
|
|
879
|
-
|
|
1005
|
+
// issue #57 根因:过去写的是 `Number(query.get('days')) || 30` —— `Number('0')` 是 0,
|
|
1006
|
+
// 而 `0 || 30` 又变回 30,于是前端「清空回收站」传的 days=0 被静默升级成 30 天保留期,
|
|
1007
|
+
// 刚删的卡一个都不清 → 用户看到的就是「点了没反应」。
|
|
1008
|
+
// 现在区分「没传」与「传了 0」:没传才用默认 30。
|
|
1009
|
+
let days
|
|
1010
|
+
try { days = parseRetentionDays(query.get('days')) } catch (e) { return json(res, 400, { ok: false, error: String(e.message) }) }
|
|
880
1011
|
const r = await purgeExpired(vaultRoot, days)
|
|
881
1012
|
json(res, 200, r)
|
|
882
1013
|
return
|
|
883
1014
|
}
|
|
1015
|
+
case '/recycle/purge-all': {
|
|
1016
|
+
// 永久清空回收站(deleted + rejected)。危险操作:只收 POST,且走 DB_WRITE_ROUTES 闸门。
|
|
1017
|
+
if (req.method !== 'POST') return json(res, 405, { ok: false, error: '需要 POST' })
|
|
1018
|
+
const r = await purgeAllRecycle(vaultRoot)
|
|
1019
|
+
broadcast('cards', { reason: 'recycle-purged', purged: r.purged })
|
|
1020
|
+
json(res, 200, r)
|
|
1021
|
+
return
|
|
1022
|
+
}
|
|
884
1023
|
case '/write': {
|
|
885
1024
|
const chunks = []
|
|
886
1025
|
for await (const chunk of req) chunks.push(chunk)
|
|
@@ -1210,7 +1349,7 @@ export function createApi(deps = {}) {
|
|
|
1210
1349
|
vaultProfiles: Array.isArray(cfg.vaultProfiles) ? cfg.vaultProfiles : [], activeVault: cfg.activeVault || '',
|
|
1211
1350
|
enabled: cfg.enabled !== false, vaultDir: cfg.vaultDir || '', captureProvider: cfg.captureProvider || '', captureFollowSession: cfg.captureFollowSession === true, captureFirstOnly: cfg.captureFirstOnly === true, captureTimeoutMs: cfg.captureTimeoutMs ?? 45000,
|
|
1212
1351
|
captureModel: cfg.captureModel || '', recallEmbedding: cfg.recallEmbedding || '', sessionBudgetChars: cfg.sessionBudgetChars ?? 80000,
|
|
1213
|
-
skillCardsAutoSync: cfg.skillCardsAutoSync ?? true,
|
|
1352
|
+
skillCardsAutoSync: cfg.skillCardsAutoSync ?? true, newsDigestEnabled: cfg.newsDigestEnabled === true, newsDigestIntervalMinutes: cfg.newsDigestIntervalMinutes ?? 720, newsDigestMaxItems: cfg.newsDigestMaxItems ?? 5,
|
|
1214
1353
|
webPort: cfg.webPort ?? 7999, webCheckIntervalMs: cfg.webCheckIntervalMs ?? 5000, webMaxRestart: cfg.webMaxRestart ?? 10,
|
|
1215
1354
|
}
|
|
1216
1355
|
const NUM_RANGE = {
|