cortico-world-rssnews 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0
4
+
5
+ - **低消耗模式**(`worlds.rss.lowCost`,默认关):事件与 `rss_fetch` / `rss_index` 只给编号、来源、时间、标题,
6
+ 不附正文与链接,省上下文。
7
+ - **消息编号**:每条进存档的消息拿到一个稳定递增的 `#n`,事件、工具回执、索引命中与消息页签用的是同一个号;
8
+ 老存档载入时按时间自动补号,清档不回收旧号。
9
+ - **新工具 `rss_read`**:`{"ids":["#12","13"]}` 按编号读完整正文(一次最多 10 条,纯读存档不走网络);
10
+ 编号认不出 / 不在存档 / 被上限挤掉都给明确回执与当前编号范围。
11
+ - 消息页签每行显示编号,和模型手里的对得上;环境提示词补充编号与低消耗模式的用法。
12
+
3
13
  ## 0.1.0
4
14
 
5
15
  首个版本。
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  | 页签 | 内容 |
11
11
  |---|---|
12
12
  | **Rss/Atom 管理** | 订阅源清单与增删改:地址、名称、间隔、定时时刻、超时、一次最多几条、是否启用、允不允许模型拉取;每行还能立即拉取、停用、删除。 |
13
- | **Rss/Atom 源的消息** | 已经拉到的条目,从新到旧;可按源筛、按关键词搜、翻页,点标题看正文与原文链接。 |
13
+ | **Rss/Atom 源的消息** | 已经拉到的条目,从新到旧,每行带模型用的同一个编号;可按源筛、按关键词搜、翻页,点标题看正文与原文链接。 |
14
14
 
15
15
  ## 每个源自己的设置
16
16
 
@@ -27,10 +27,27 @@
27
27
 
28
28
  新加订阅源时的默认值来自配置组(`worlds.rss.default*`),加完可以逐个改。
29
29
 
30
+ ## 低消耗模式
31
+
32
+ 配置组里的 `worlds.rss.lowCost`(默认关)。开着的时候,事件与两个工具**只给编号、来源、时间、标题**,
33
+ 正文和链接都不给——要读哪条,她自己拿编号调 `rss_read`。这是为了不把一大段新闻正文塞进每一轮上下文。
34
+
35
+ ```
36
+ [RSS] 央视新闻 world 有 3 条新消息
37
+ · 新 · #12 · 2026-11-24 15:57 · 英伟达发布新一代芯片
38
+ · 新 · #11 · 2026-11-24 14:10 · 韩国加码高考作弊举报悬赏
39
+ ```
40
+
41
+ 她接着说 `rss_read {"ids":["#12"]}` 就能拿到那条的全文。编号是**存档里稳定递增**的:同一条消息在事件、
42
+ `rss_fetch`、`rss_index` 里用的是同一个号,下一轮对话也还是它;编号只增不减,清档也不回收,
43
+ 所以旧号不会指到别的消息上。消息页签每一行也显示同一个编号,你在界面上能对得上。
44
+
45
+ 开关关着时行为不变(正文按「递给模型的正文长度」截断,照旧带链接)。`rss_read` 两种模式下都能用。
46
+
30
47
  ## 她那边看到什么
31
48
 
32
- **事件** `rss.new_items`:某个源到点拉到新消息时推一条,正文是标题、时间、摘要和链接。是事实,不是命令;
33
- 要不要开口由她决定。默认攒到下次活动再给(`debounce`),打开「新消息叫醒她」后立即投递(`flush`)。
49
+ **事件** `rss.new_items`:某个源到点拉到新消息时推一条,正文是编号、标题、时间(不省上下文时还带摘要和链接)。
50
+ 是事实,不是命令;要不要开口由她决定。默认攒到下次活动再给(`debounce`),打开「新消息叫醒她」后立即投递(`flush`)。
34
51
 
35
52
  **工具**
36
53
 
@@ -39,20 +56,24 @@
39
56
  同一个源 12 秒内连着调用会复用上一次的结果。
40
57
  2. `rss_index` —— 关键词索引。`feeds`(至少一个)+ `keywords`(至少一个,分别匹配标题、正文、时间;默认命中任一,
41
58
  `mode: "all"` 要求全中)+ `page`。每个源翻最新 50 条,命中结果按时间从新到旧排,一页最多 5 条,回执末尾说还有几条。
59
+ 3. `rss_read` —— 按编号读全文。`{"ids": ["#12", 13]}`,一次最多 10 条,纯读存档不走网络。
60
+ 编号认不出、不在存档里、被上限挤掉,都会在回执里说明并给出当前编号范围。
42
61
 
43
62
  索引只读:它拉到的条目进消息存档,但不记为「已推送」,所以定时推送照样会把它们递过来。
44
63
 
45
64
  ## 安装
46
65
 
47
- 先拿到这个包(仓库里带着构建好的 `dist/webui.js`,clone 下来就是可用的):
66
+ 先拿到这个包,两种来源任选:
48
67
 
49
68
  ```bash
50
- git clone https://github.com/bluemika111/cortico-world-rssnews
69
+ npm i cortico-world-rssnews # 已发布到 npm(包页:https://www.npmjs.com/package/cortico-world-rssnews)
70
+ git clone https://github.com/bluemika111/cortico-world-rssnews # 仓库里带着构建好的 dist/webui.js,clone 即可用
51
71
  ```
52
72
 
53
- Coopanion 的扩展装在部署的 `extensions/` 里。两种方式:
73
+ Coopanion 的扩展装在部署的 `extensions/` 里。三种方式:
54
74
 
55
- **A. 用界面装(推荐)**:Coopanion → 扩展 →「从本机目录安装」→ 选 clone 下来的目录。
75
+ **A. 用界面装(推荐)**:Coopanion → 扩展 →「从本机目录安装」→ 选 clone 下来的目录;
76
+ npm 上审核通过后也可以直接在扩展页「从 npm 安装」搜 `cortico-world-rssnews`。
56
77
  Coopanion 会自己把它登记进扩展目录并装好依赖,不需要在它的软件目录里手动跑安装脚本。
57
78
 
58
79
  **B. 手工登记**(本地开发就这么用):
@@ -62,7 +83,7 @@ Coopanion 会自己把它登记进扩展目录并装好依赖,不需要在它
62
83
  {
63
84
  "dependencies": {
64
85
  "cortico-world-rssnews": "link:<clone 下来的目录>" // 本地开发
65
- // "cortico-world-rssnews": "^0.1.0" // 发布到 npm 之后
86
+ // "cortico-world-rssnews": "^0.1.0" // 从 npm 装
66
87
  }
67
88
  }
68
89
  ```
package/describe.json CHANGED
@@ -73,14 +73,45 @@
73
73
  "zh": "按关键词翻订阅源,每页最多 5 条,可翻页。",
74
74
  "en": "Searches the feeds by keyword, at most 5 matches per page, with paging."
75
75
  }
76
+ },
77
+ {
78
+ "name": "rss_read",
79
+ "description": "Read the full text of messages by their number. Every message handed over by rss_fetch, rss_index or an rss.new_items event carries a number like \"#12\"; pass those numbers here to get the whole body, the source feed, the time and the link. Read-only, no network. In low-cost mode this is the only way to see the body.",
80
+ "parameters": {
81
+ "type": "object",
82
+ "additionalProperties": false,
83
+ "properties": {
84
+ "ids": {
85
+ "type": "array",
86
+ "items": {
87
+ "type": [
88
+ "string",
89
+ "number"
90
+ ]
91
+ },
92
+ "minItems": 1,
93
+ "description": "Message numbers, e.g. [\"#12\", \"13\", 14]."
94
+ }
95
+ },
96
+ "required": [
97
+ "ids"
98
+ ]
99
+ },
100
+ "tags": [
101
+ "read"
102
+ ],
103
+ "summary": {
104
+ "zh": "按编号读某几条消息的完整正文。",
105
+ "en": "Reads the full text of the messages behind their numbers."
106
+ }
76
107
  }
77
108
  ],
78
109
  "events": [
79
110
  {
80
111
  "type": "rss.new_items",
81
112
  "description": {
82
- "zh": "某个订阅源到了拉取时间、抓到了新消息;正文里有标题、时间、摘要和链接,每个源一次最多给几条是它自己的设置。",
83
- "en": "A feed came round and had new items; the text carries titles, times, summaries and links, up to that feed's own per-pull limit."
113
+ "zh": "某个订阅源到了拉取时间、抓到了新消息;正文带每条消息的编号、来源、时间、标题(不省上下文时还带摘要与链接),每个源一次最多给几条是它自己的设置。",
114
+ "en": "A feed came round and had new items; the text carries each item's number, feed, time and title (plus summary and link when low-cost mode is off), up to that feed's own per-pull limit."
84
115
  }
85
116
  }
86
117
  ],
@@ -89,7 +120,7 @@
89
120
  "key": "worlds.rss.envPrompt",
90
121
  "title": "RSS / Atom 订阅 · 环境提示词",
91
122
  "role": "envPrompt",
92
- "content": "你的世界里有一份 RSS / Atom 订阅,它和你正在过的这一段对话是分开的两件事:源自己更新,按各自的时间表被拉下来;拉到的消息或者以事件递到你面前,或者等你主动去取。\n\n现在的订阅源(id 后面括号里是它的 id,工具里可以拿 id、名字或网址指它):\n\n{{rss.feeds}}\n\n整体状态:{{rss.state}}\n消息存档:{{rss.archive}}\n\n来源给的时间按 {{rss.timezone}} 显示。正文是网页正文去标签后的纯文本,可能被截断,原始地址在每条消息末尾。\n\n两种消息到达的方式:\n\n- **事件**:某个源到了拉取时间,抓到新消息,就把最近几条写成一条 `rss.new_items` 事件递给你。正文里带标题、时间、一段摘要和链接;「一次最多递几条」是每个源自己的设置,超出的那些不会追着补发。事件是事实,不是请求:要不要因为一条新闻开口、用什么样的语气,由你按自己的人设和你们此刻的关系决定,也可以什么都不做。\n- **工具**:你需要的时候自己去取。\n\n`rss_fetch` 是立即拉取。不带参数就拉所有「启用且允许模型拉取」的源;参数 `feeds` 给一个名字/id/网址的数组就只拉这几个。每个源给你它「一次最多递几条」那么多条(新消息优先;这一轮没有新的就给你最近的几条,并标明已读过)。它走的是真网络,慢的源要十几秒,所以不要连着调它催更新;刚拉过的源在十几秒内会直接复用上次结果。\n\n`rss_index` 是按关键词翻订阅源。参数是 `feeds`(必填,至少一个源)、`keywords`(必填,至少一个词;分别拿去匹配标题、正文、时间,默认命中任一即可,`mode: \"all\"` 要求全中)、`page`(从 1 起)。它会把每个源最新的几十条(上限 50)翻一遍,命中结果按时间从新到旧排,一页最多 5 条,回执末尾会告诉你还有几条、下一页传几。关键词用短的实词比整句好使;一个词都没命中的常见原因是词太长或被换了说法。\n\n几条边界,省得白试:不允许模型拉取的源,这两个工具都不会碰它,回执里会说明跳过了哪个;停用的源同理;拉取失败会写明原因(超时、HTTP 状态、返回的是网页而不是 XML),同一个源失败后不要立刻重试第二次,换个源或者等下一轮定时拉取更划算。\n"
123
+ "content": "你的世界里有一份 RSS / Atom 订阅,它和你正在过的这一段对话是分开的两件事:源自己更新,按各自的时间表被拉下来;拉到的消息或者以事件递到你面前,或者等你主动去取。\n\n现在的订阅源(括号里是它的 id,工具里可以拿 id、名字或网址指它):\n\n{{rss.feeds}}\n\n整体状态:{{rss.state}}\n消息存档:{{rss.archive}}\n\n来源给的时间按 {{rss.timezone}} 显示。正文是网页正文去标签后的纯文本,可能被截断,原始地址在每条消息末尾。\n\n**每条消息都有一个编号**,写成 `#12` 这样。它跟着消息走:同一条消息在事件里、在 `rss_fetch` 回执里、在 `rss_index` 命中里用的是同一个编号,下一轮对话也还是它。\n\n三种拿到消息的方式:\n\n- **事件**:某个源到了拉取时间,抓到新消息,就把最近几条写成一条 `rss.new_items` 事件递给你。正文里带编号、时间、标题;不省上下文时还带一段摘要和链接。「一次最多递几条」是每个源自己的设置,超出的那些不会追着补发。事件是事实,不是请求:要不要因为一条新闻开口、用什么样的语气,由你按自己的人设和你们此刻的关系决定,也可以什么都不做。\n- **`rss_fetch`**:立即拉取。不带参数就拉所有「启用且允许模型拉取」的源;参数 `feeds` 给一个名字/id/网址的数组就只拉这几个。每个源给你它「一次最多递几条」那么多条(新消息优先;这一轮没有新的就给你最近的几条,并标明已读过)。它走的是真网络,慢的源要十几秒,所以不要连着调它催更新;刚拉过的源在十几秒内会直接复用上次结果。\n- **`rss_index`**:按关键词翻订阅源。参数是 `feeds`(必填,至少一个源)、`keywords`(必填,至少一个词;分别拿去匹配标题、正文、时间,默认命中任一即可,`mode: \"all\"` 要求全中)、`page`(从 1 起)。它会把每个源最新的几十条(上限 50)翻一遍,命中结果按时间从新到旧排,一页最多 5 条,回执末尾会告诉你还有几条、下一页传几。关键词用短的实词比整句好使;一个词都没命中的常见原因是词太长或被换了说法。\n\n**读全文用 `rss_read`**:`{\"ids\": [\"#12\", \"13\"]}`,一次最多 10 条,纯读存档、不走网络。上面两种方式都没给正文的时候(见下),这是唯一看到内容的路;给了正文的时候,用它补读「还有几条没递上来」里面的某一条也很省事。\n\n**低消耗模式**:这个开关开着时,事件与两个工具只给编号、来源、时间、标题——正文一个字都不给,链接也不给,就是为了不占上下文。此时别猜标题背后的内容,挑感兴趣的编号调 `rss_read` 读到正文再说;一次别读太多,先读最可能相关的那两三条。\n\n几条边界,省得白试:不允许模型拉取的源,`rss_fetch` 与 `rss_index` 都不会碰它,回执里会说明跳过了哪个;停用的源同理;编号只认得存档里还在的那部分,被存档上限挤掉的老消息会在回执里告诉你现有编号范围;拉取失败会写明原因(超时、HTTP 状态、返回的是网页而不是 XML),同一个源失败后不要立刻重试第二次,换个源或者等下一轮定时拉取更划算。\n"
93
124
  }
94
125
  ]
95
126
  }
package/dist/webui.js CHANGED
@@ -382,12 +382,13 @@ var messagesPanel = {
382
382
  const titleLine = list.append(row.title, "plain");
383
383
  titleLine.style.cursor = "pointer";
384
384
  titleLine.title = S.readMore;
385
- list.append(`${row.timeText} \xB7 ${row.feedTitle}`, "dim");
385
+ const tag = typeof row.seq === "number" ? `#${row.seq} \xB7 ` : "";
386
+ list.append(`${tag}${row.timeText} \xB7 ${row.feedTitle}`, "dim");
386
387
  if (row.summary && row.summary !== row.title) list.append(row.summary, "plain");
387
388
  list.append("", "dim");
388
389
  const open = () => {
389
390
  const body = ui.h("div");
390
- body.append(ui.msgline(`${row.feedTitle} \xB7 ${row.timeText}`));
391
+ body.append(ui.msgline(`${typeof row.seq === "number" ? `#${row.seq} \xB7 ` : ""}${row.feedTitle} \xB7 ${row.timeText}`));
391
392
  const text = ui.h("div");
392
393
  text.textContent = row.body || row.summary || S.emptyBody;
393
394
  text.style.whiteSpace = "pre-wrap";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-rssnews",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Cortico World: subscribe to RSS/Atom feeds, pull them on a per-feed schedule, and hand new items to Coo",
6
6
  "license": "MIT",
package/src/ENV_PROMPT.md CHANGED
@@ -1,6 +1,6 @@
1
1
  你的世界里有一份 RSS / Atom 订阅,它和你正在过的这一段对话是分开的两件事:源自己更新,按各自的时间表被拉下来;拉到的消息或者以事件递到你面前,或者等你主动去取。
2
2
 
3
- 现在的订阅源(id 后面括号里是它的 id,工具里可以拿 id、名字或网址指它):
3
+ 现在的订阅源(括号里是它的 id,工具里可以拿 id、名字或网址指它):
4
4
 
5
5
  {{rss.feeds}}
6
6
 
@@ -9,13 +9,16 @@
9
9
 
10
10
  来源给的时间按 {{rss.timezone}} 显示。正文是网页正文去标签后的纯文本,可能被截断,原始地址在每条消息末尾。
11
11
 
12
- 两种消息到达的方式:
12
+ **每条消息都有一个编号**,写成 `#12` 这样。它跟着消息走:同一条消息在事件里、在 `rss_fetch` 回执里、在 `rss_index` 命中里用的是同一个编号,下一轮对话也还是它。
13
13
 
14
- - **事件**:某个源到了拉取时间,抓到新消息,就把最近几条写成一条 `rss.new_items` 事件递给你。正文里带标题、时间、一段摘要和链接;「一次最多递几条」是每个源自己的设置,超出的那些不会追着补发。事件是事实,不是请求:要不要因为一条新闻开口、用什么样的语气,由你按自己的人设和你们此刻的关系决定,也可以什么都不做。
15
- - **工具**:你需要的时候自己去取。
14
+ 三种拿到消息的方式:
16
15
 
17
- `rss_fetch` 是立即拉取。不带参数就拉所有「启用且允许模型拉取」的源;参数 `feeds` 给一个名字/id/网址的数组就只拉这几个。每个源给你它「一次最多递几条」那么多条(新消息优先;这一轮没有新的就给你最近的几条,并标明已读过)。它走的是真网络,慢的源要十几秒,所以不要连着调它催更新;刚拉过的源在十几秒内会直接复用上次结果。
16
+ - **事件**:某个源到了拉取时间,抓到新消息,就把最近几条写成一条 `rss.new_items` 事件递给你。正文里带编号、时间、标题;不省上下文时还带一段摘要和链接。「一次最多递几条」是每个源自己的设置,超出的那些不会追着补发。事件是事实,不是请求:要不要因为一条新闻开口、用什么样的语气,由你按自己的人设和你们此刻的关系决定,也可以什么都不做。
17
+ - **`rss_fetch`**:立即拉取。不带参数就拉所有「启用且允许模型拉取」的源;参数 `feeds` 给一个名字/id/网址的数组就只拉这几个。每个源给你它「一次最多递几条」那么多条(新消息优先;这一轮没有新的就给你最近的几条,并标明已读过)。它走的是真网络,慢的源要十几秒,所以不要连着调它催更新;刚拉过的源在十几秒内会直接复用上次结果。
18
+ - **`rss_index`**:按关键词翻订阅源。参数是 `feeds`(必填,至少一个源)、`keywords`(必填,至少一个词;分别拿去匹配标题、正文、时间,默认命中任一即可,`mode: "all"` 要求全中)、`page`(从 1 起)。它会把每个源最新的几十条(上限 50)翻一遍,命中结果按时间从新到旧排,一页最多 5 条,回执末尾会告诉你还有几条、下一页传几。关键词用短的实词比整句好使;一个词都没命中的常见原因是词太长或被换了说法。
18
19
 
19
- `rss_index` 是按关键词翻订阅源。参数是 `feeds`(必填,至少一个源)、`keywords`(必填,至少一个词;分别拿去匹配标题、正文、时间,默认命中任一即可,`mode: "all"` 要求全中)、`page`(从 1 起)。它会把每个源最新的几十条(上限 50)翻一遍,命中结果按时间从新到旧排,一页最多 5 条,回执末尾会告诉你还有几条、下一页传几。关键词用短的实词比整句好使;一个词都没命中的常见原因是词太长或被换了说法。
20
+ **读全文用 `rss_read`**:`{"ids": ["#12", "13"]}`,一次最多 10 条,纯读存档、不走网络。上面两种方式都没给正文的时候(见下),这是唯一看到内容的路;给了正文的时候,用它补读「还有几条没递上来」里面的某一条也很省事。
20
21
 
21
- 几条边界,省得白试:不允许模型拉取的源,这两个工具都不会碰它,回执里会说明跳过了哪个;停用的源同理;拉取失败会写明原因(超时、HTTP 状态、返回的是网页而不是 XML),同一个源失败后不要立刻重试第二次,换个源或者等下一轮定时拉取更划算。
22
+ **低消耗模式**:这个开关开着时,事件与两个工具只给编号、来源、时间、标题——正文一个字都不给,链接也不给,就是为了不占上下文。此时别猜标题背后的内容,挑感兴趣的编号调 `rss_read` 读到正文再说;一次别读太多,先读最可能相关的那两三条。
23
+
24
+ 几条边界,省得白试:不允许模型拉取的源,`rss_fetch` 与 `rss_index` 都不会碰它,回执里会说明跳过了哪个;停用的源同理;编号只认得存档里还在的那部分,被存档上限挤掉的老消息会在回执里告诉你现有编号范围;拉取失败会写明原因(超时、HTTP 状态、返回的是网页而不是 XML),同一个源失败后不要立刻重试第二次,换个源或者等下一轮定时拉取更划算。
package/src/config.ts CHANGED
@@ -3,6 +3,8 @@ import type { ConfigGroup } from 'cortico/core/types.ts';
3
3
  /** config.json 的 worlds.rss 段;键扁平,WebUI 的配置接口写不了对象。 */
4
4
  export interface RssConfigSection {
5
5
  enabled: boolean;
6
+ /** 低消耗模式:只递编号、来源、时间、标题,正文用 rss_read 按编号去读。 */
7
+ lowCost: boolean;
6
8
  /** 新消息到达时叫醒她(true)还是只排队等她下次活动(false)。 */
7
9
  wakeOnNewItems: boolean;
8
10
  /** 递给模型的正文最多多少字;0 表示只给标题与时间。 */
@@ -25,6 +27,7 @@ export interface RssConfigSection {
25
27
 
26
28
  export const RSS_DEFAULTS: RssConfigSection = {
27
29
  enabled: false,
30
+ lowCost: false,
28
31
  wakeOnNewItems: false,
29
32
  maxBodyChars: 240,
30
33
  defaultIntervalMinutes: 30,
@@ -44,6 +47,12 @@ export function rssConfigGroup(): ConfigGroup {
44
47
  type: 'object',
45
48
  title: 'RSS / Atom 订阅',
46
49
  properties: {
50
+ 'worlds.rss.lowCost': {
51
+ type: 'boolean',
52
+ title: '低消耗模式',
53
+ description: '开着时,事件与工具回执只给编号、来源、时间、标题,不附正文;她自己用 rss_read 按编号读全文。省上下文,代价是多一次工具调用。',
54
+ 'x-hot': true,
55
+ },
47
56
  'worlds.rss.wakeOnNewItems': {
48
57
  type: 'boolean',
49
58
  title: '新消息叫醒她',
package/src/definition.ts CHANGED
@@ -23,13 +23,17 @@ export const RSS: WorldDefinition<RssConfigSection> = {
23
23
  zh: '按关键词翻订阅源,每页最多 5 条,可翻页。',
24
24
  en: 'Searches the feeds by keyword, at most 5 matches per page, with paging.',
25
25
  },
26
+ rss_read: {
27
+ zh: '按编号读某几条消息的完整正文。',
28
+ en: 'Reads the full text of the messages behind their numbers.',
29
+ },
26
30
  }),
27
31
  events: [
28
32
  {
29
33
  type: 'rss.new_items',
30
34
  description: {
31
- zh: '某个订阅源到了拉取时间、抓到了新消息;正文里有标题、时间、摘要和链接,每个源一次最多给几条是它自己的设置。',
32
- en: 'A feed came round and had new items; the text carries titles, times, summaries and links, up to that feed\'s own per-pull limit.',
35
+ zh: '某个订阅源到了拉取时间、抓到了新消息;正文带每条消息的编号、来源、时间、标题(不省上下文时还带摘要与链接),每个源一次最多给几条是它自己的设置。',
36
+ en: 'A feed came round and had new items; the text carries each item\'s number, feed, time and title (plus summary and link when low-cost mode is off), up to that feed\'s own per-pull limit.',
33
37
  },
34
38
  },
35
39
  ],
package/src/model-text.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  import type { FeedRecord } from './types.ts';
6
6
 
7
7
  export interface ItemView {
8
+ /** 存档编号,展示成 `#12`;低消耗模式下模型靠它点名要读全文。 */
9
+ seq?: number;
8
10
  title: string;
9
11
  link: string;
10
12
  body: string;
@@ -13,6 +15,11 @@ export interface ItemView {
13
15
  isNew?: boolean;
14
16
  }
15
17
 
18
+ /** `#12`。没有编号时返回空串,调用方会退化成分行列表。 */
19
+ export function seqTag(seq: number | undefined): string {
20
+ return typeof seq === 'number' && Number.isFinite(seq) ? `#${seq}` : '';
21
+ }
22
+
16
23
  export interface FetchResultView {
17
24
  feed: FeedRecord;
18
25
  error?: string;
@@ -59,11 +66,19 @@ function bodyOf(item: ItemView, maxChars: number): string {
59
66
  return `${text.slice(0, Math.max(0, maxChars - 1)).trimEnd()}…`;
60
67
  }
61
68
 
62
- /** 一条消息写成两三行:时间 + 标题,正文一段,链接一行。 */
63
- export function renderItem(item: ItemView, opts: { timezone: string; maxChars: number; marker?: string }): string {
69
+ /**
70
+ * 一条消息写成两三行:时间 + 标题,正文一段,链接一行。
71
+ * `compact`(低消耗模式)时只留 `#编号 · 时间 · 标题`,正文与链接都不给——要读正文用 rss_read。
72
+ */
73
+ export function renderItem(
74
+ item: ItemView,
75
+ opts: { timezone: string; maxChars: number; marker?: string; compact?: boolean },
76
+ ): string {
64
77
  const when = fmtLocal(item.publishedAt, opts.timezone);
65
- const head = [opts.marker, when, item.title].filter((part) => !!part).join(' · ');
78
+ const tag = seqTag(item.seq);
79
+ const head = [opts.marker, tag, when, item.title].filter((part) => !!part).join(' · ');
66
80
  const lines = [`· ${head}`];
81
+ if (opts.compact) return lines.join('\n');
67
82
  const body = bodyOf(item, opts.maxChars);
68
83
  if (body) lines.push(...body.split('\n').map((line) => ` ${line}`));
69
84
  if (item.link) lines.push(` ${item.link}`);
@@ -88,20 +103,34 @@ export function renderFeedList(feeds: readonly FeedRecord[]): string {
88
103
  }
89
104
 
90
105
  /** 定时拉取抓到新消息时推出的事件正文。 */
91
- export function renderNewItemsEvent(result: FetchResultView, timezone: string, maxChars: number): string {
106
+ export function renderNewItemsEvent(
107
+ result: FetchResultView,
108
+ timezone: string,
109
+ maxChars: number,
110
+ lowCost = false,
111
+ ): string {
92
112
  const { feed, items } = result;
93
113
  const count = result.newCount;
94
114
  const head = `[RSS] ${feed.title} 有 ${count} 条新消息`;
95
115
  const lines: string[] = [head];
96
116
  for (const item of items) {
97
- lines.push(renderItem(item, { timezone, maxChars, marker: item.isNew === false ? '此前' : '新' }));
117
+ lines.push(renderItem(item, {
118
+ timezone,
119
+ maxChars,
120
+ marker: item.isNew === false ? '此前' : '新',
121
+ compact: lowCost,
122
+ }));
98
123
  }
99
124
  if (result.skipped > 0) {
100
125
  lines.push(`(还有 ${result.skipped} 条更新的没一并递上:这个源一次最多给 ${feed.maxNewItems} 条)`);
101
126
  }
102
127
  lines.push('');
103
128
  lines.push(
104
- `要更多或者要按关键词翻,用 rss_index(这个源的 id 是 ${feed.id});想马上再拉一次用 rss_fetch。`,
129
+ lowCost
130
+ ? `低消耗模式:上面只有编号、来源、时间、标题。要读哪条的全文,把它的编号交给 rss_read(比如 rss_read {"ids":["${
131
+ seqTag(items[0]?.seq) || '#1'
132
+ }"]})。要更多或者按关键词翻用 rss_index,想马上再拉一次用 rss_fetch(这个源的 id 是 ${feed.id})。`
133
+ : `要更多或者要按关键词翻,用 rss_index(这个源的 id 是 ${feed.id});想马上再拉一次用 rss_fetch。`,
105
134
  );
106
135
  return lines.join('\n');
107
136
  }
@@ -110,6 +139,8 @@ export interface FetchDigestOptions {
110
139
  timezone: string;
111
140
  maxChars: number;
112
141
  notes?: readonly string[];
142
+ /** 低消耗模式:只列编号、时间、标题。 */
143
+ lowCost?: boolean;
113
144
  }
114
145
 
115
146
  /** `rss_fetch` 的回执:每个源一段。 */
@@ -138,16 +169,26 @@ export function renderFetchDigest(results: readonly FetchResultView[], opts: Fet
138
169
  }
139
170
  if (result.newCount === 0) lines.push(' 没有新消息;下面是最近的几条:');
140
171
  result.items.forEach((item, index) => {
141
- lines.push(renderItem(item, { timezone: opts.timezone, maxChars: opts.maxChars, marker: `${index + 1}.${item.isNew === false ? '(已读过)' : ''}` }));
172
+ lines.push(renderItem(item, {
173
+ timezone: opts.timezone,
174
+ maxChars: opts.maxChars,
175
+ marker: `${index + 1}.${item.isNew === false ? '(已读过)' : ''}`,
176
+ compact: opts.lowCost === true,
177
+ }));
142
178
  });
143
179
  if (result.skipped > 0) {
144
180
  lines.push(` (另有 ${result.skipped} 条更新的没递上来:这个源一次最多给 ${result.feed.maxNewItems} 条;要看全用 rss_index)`);
145
181
  }
146
182
  }
183
+ if (opts.lowCost) {
184
+ lines.push('');
185
+ lines.push('低消耗模式:只有编号、来源、时间、标题。要读全文就把编号交给 rss_read。');
186
+ }
147
187
  return lines.join('\n');
148
188
  }
149
189
 
150
190
  export interface IndexHit {
191
+ seq?: number;
151
192
  feed: FeedRecord;
152
193
  title: string;
153
194
  link: string;
@@ -170,6 +211,8 @@ export interface IndexDigestOptions {
170
211
  feedCount: number;
171
212
  truncated: number;
172
213
  hits: readonly IndexHit[];
214
+ /** 低消耗模式:命中只列编号与标题,不附正文。 */
215
+ lowCost?: boolean;
173
216
  }
174
217
 
175
218
  /** `rss_index` 的回执:命中几条、这一页是哪几条、下一页怎么取。 */
@@ -197,7 +240,14 @@ export function renderIndexDigest(opts: IndexDigestOptions): string {
197
240
  opts.hits.forEach((hit, index) => {
198
241
  const when = fmtLocal(hit.publishedAt, opts.timezone);
199
242
  const number = (opts.page - 1) * opts.pageSize + index + 1;
200
- lines.push(`${number}. 「${hit.feed.title}」${when ? `${when} · ` : ''}${hit.title}`);
243
+ const tag = seqTag(hit.seq);
244
+ lines.push(`${number}. ${tag ? `${tag} · ` : ''}「${hit.feed.title}」${when ? `${when} · ` : ''}${hit.title}`);
245
+ if (opts.lowCost) {
246
+ if (hit.matched.length && hit.matched.length < opts.keywords.length) {
247
+ lines.push(` 命中:${hit.matched.join('、')}`);
248
+ }
249
+ return;
250
+ }
201
251
  const body = bodyOf({ title: hit.title, link: hit.link, body: hit.body, summary: hit.summary }, opts.maxChars);
202
252
  if (body) lines.push(...body.split('\n').map((line) => ` ${line}`));
203
253
  if (hit.link) lines.push(` ${hit.link}`);
@@ -212,5 +262,68 @@ export function renderIndexDigest(opts: IndexDigestOptions): string {
212
262
  lines.push('');
213
263
  lines.push(`还有 ${rest} 条:把 page 传 ${next} 再调一次。`);
214
264
  }
265
+ if (opts.lowCost) {
266
+ lines.push('');
267
+ lines.push('低消耗模式:只给了编号与标题。要读哪条的全文,把编号交给 rss_read。');
268
+ }
269
+ return lines.join('\n');
270
+ }
271
+
272
+ /** `rss_read` 的回执:把点名的几条完整正文摊开。 */
273
+ export interface ReadResultOptions {
274
+ timezone: string;
275
+ /** 每条最长多少字;0 表示不截断(存档本来就有限长)。 */
276
+ maxChars: number;
277
+ entries: readonly ReadEntry[];
278
+ /** 点到的编号不存在,或已经不在存档里。 */
279
+ missing: readonly number[];
280
+ /** 编号格式认不出来的原始输入。 */
281
+ unparsed: readonly string[];
282
+ /** 存档里现有编号的范围。 */
283
+ range: { min: number; max: number } | null;
284
+ }
285
+
286
+ export interface ReadEntry {
287
+ seq: number;
288
+ feedTitle: string;
289
+ title: string;
290
+ link: string;
291
+ body: string;
292
+ summary: string;
293
+ publishedAt?: string;
294
+ fetchedAt?: string;
295
+ }
296
+
297
+ export function renderReadResult(opts: ReadResultOptions): string {
298
+ const lines: string[] = [];
299
+ if (!opts.entries.length) {
300
+ lines.push('没有读到任何消息。');
301
+ if (opts.missing.length) lines.push(`这几个编号不在存档里:${opts.missing.map((seq) => `#${seq}`).join('、')}。`);
302
+ if (opts.unparsed.length) lines.push(`这几个认不出编号:${opts.unparsed.join('、')}(要的是 #12 或 12 这种)。`);
303
+ if (opts.range) {
304
+ lines.push(`现在存档里的编号从 #${opts.range.min} 到 #${opts.range.max};越老的越可能已经被存档上限挤掉了。`);
305
+ } else {
306
+ lines.push('存档现在是空的:消息页签拉一次就有了。');
307
+ }
308
+ return lines.join('\n');
309
+ }
310
+
311
+ lines.push(`读了 ${opts.entries.length} 条:`);
312
+ opts.entries.forEach((entry, index) => {
313
+ const when = fmtLocal(entry.publishedAt ?? entry.fetchedAt, opts.timezone);
314
+ lines.push('');
315
+ lines.push(`${index + 1}. #${entry.seq} · 「${entry.feedTitle}」${when ? `${when} · ` : ''}${entry.title}`);
316
+ const text = opts.maxChars > 0 ? bodyOf({ title: entry.title, link: entry.link, body: entry.body, summary: entry.summary }, opts.maxChars) : (entry.body || entry.summary).trim();
317
+ if (text) lines.push(...text.split('\n').map((line) => ` ${line}`));
318
+ if (entry.link) lines.push(` ${entry.link}`);
319
+ });
320
+
321
+ const problems: string[] = [];
322
+ if (opts.missing.length) problems.push(`不在存档里:${opts.missing.map((seq) => `#${seq}`).join('、')}`);
323
+ if (opts.unparsed.length) problems.push(`认不出:${opts.unparsed.join('、')}`);
324
+ if (problems.length) {
325
+ lines.push('');
326
+ lines.push(`(${problems.join(';')}${opts.range ? `;现有编号 #${opts.range.min}–#${opts.range.max}` : ''})`);
327
+ }
215
328
  return lines.join('\n');
216
329
  }
package/src/store.ts CHANGED
@@ -57,6 +57,8 @@ function isHttpUrl(value: string): boolean {
57
57
  export class FeedStore {
58
58
  private feeds: FeedRecord[] = [];
59
59
  private archiveEntries: ArchiveEntry[] = [];
60
+ /** 下一条消息的编号;编号只增不减,删档也不回收,免得旧编号指到别的消息。 */
61
+ private nextSeq = 0;
60
62
  private loaded = false;
61
63
  private readonly dir: string | null;
62
64
 
@@ -105,12 +107,41 @@ export class FeedStore {
105
107
  .filter((feed): feed is FeedRecord => !!feed && typeof feed === 'object' && typeof feed.url === 'string')
106
108
  .map((feed) => this.normalizeLoaded(feed));
107
109
  }
108
- const archive = this.readJson<{ version?: number; entries?: ArchiveEntry[] }>(ARCHIVE_FILE);
110
+ const archive = this.readJson<{ version?: number; nextSeq?: number; entries?: ArchiveEntry[] }>(ARCHIVE_FILE);
109
111
  if (archive?.entries && Array.isArray(archive.entries)) {
110
112
  this.archiveEntries = archive.entries.filter((entry): entry is ArchiveEntry => !!entry && typeof entry === 'object');
113
+ this.assignMissingSeq(typeof archive.nextSeq === 'number' ? archive.nextSeq : 0);
111
114
  }
112
115
  }
113
116
 
117
+ /**
118
+ * 老版本存档没有 `seq`:按「谁更旧谁号小」补齐,保证模型手里的编号在下一次读取后还是同一条。
119
+ * 文件里已经记着 `nextSeq` 时直接用它,避免重号。
120
+ */
121
+ private assignMissingSeq(nextSeqFromFile: number): void {
122
+ const missing = this.archiveEntries.filter((entry) => typeof entry.seq !== 'number' || !Number.isFinite(entry.seq));
123
+ let next = Math.max(
124
+ nextSeqFromFile,
125
+ ...this.archiveEntries.map((entry) => (typeof entry.seq === 'number' && Number.isFinite(entry.seq) ? entry.seq : 0)),
126
+ );
127
+ if (!missing.length) {
128
+ this.nextSeq = next;
129
+ return;
130
+ }
131
+ // 存档是「新的在前」,倒着走就是时间顺序。
132
+ const ordered = [...missing].sort((a, b) => {
133
+ const ak = a.publishedAt ?? a.fetchedAt ?? '';
134
+ const bk = b.publishedAt ?? b.fetchedAt ?? '';
135
+ return ak.localeCompare(bk);
136
+ });
137
+ for (const entry of ordered) {
138
+ next += 1;
139
+ entry.seq = next;
140
+ }
141
+ this.nextSeq = next;
142
+ this.persistArchive();
143
+ }
144
+
114
145
  /** 老版本/手改的文件可能有缺字段,补上能用的默认值。 */
115
146
  private normalizeLoaded(feed: FeedRecord): FeedRecord {
116
147
  return {
@@ -132,7 +163,7 @@ export class FeedStore {
132
163
  }
133
164
 
134
165
  private persistArchive(): void {
135
- this.writeJson(ARCHIVE_FILE, { version: ARCHIVE_VERSION, entries: this.archiveEntries });
166
+ this.writeJson(ARCHIVE_FILE, { version: ARCHIVE_VERSION, nextSeq: this.nextSeq, entries: this.archiveEntries });
136
167
  }
137
168
 
138
169
  // ── 订阅 ────────────────────────────────────────────────────────────
@@ -267,18 +298,40 @@ export class FeedStore {
267
298
  return this.archiveEntries;
268
299
  }
269
300
 
270
- /** 新消息放最前面;同一个源的同一条只留一份。 */
271
- pushArchive(entries: readonly ArchiveEntry[]): void {
301
+ /**
302
+ * 新消息放最前面;同一个源的同一条只留一份。
303
+ * 返回**这次真正写进存档的那些条目**(已经带好 `seq`),调用方拿它去拼给模型的编号。
304
+ */
305
+ pushArchive(entries: readonly (Omit<ArchiveEntry, 'seq'> & { seq?: number })[]): ArchiveEntry[] {
272
306
  this.load();
273
- if (!entries.length) return;
307
+ if (!entries.length) return [];
274
308
  const fresh = entries.filter((entry) => !this.archiveEntries.some(
275
309
  (existing) => existing.feedId === entry.feedId && existing.entryId === entry.entryId,
276
310
  ));
277
- if (!fresh.length) return;
278
- this.archiveEntries = [...fresh, ...this.archiveEntries]
311
+ if (!fresh.length) return [];
312
+ const stored: ArchiveEntry[] = fresh.map((entry) => {
313
+ this.nextSeq += 1;
314
+ return { ...entry, seq: this.nextSeq };
315
+ });
316
+ this.archiveEntries = [...stored, ...this.archiveEntries]
279
317
  .sort((a, b) => (b.publishedAt ?? b.fetchedAt).localeCompare(a.publishedAt ?? a.fetchedAt))
280
318
  .slice(0, Math.max(20, this.opts.archiveLimit()));
281
319
  this.persistArchive();
320
+ return stored;
321
+ }
322
+
323
+ /** 按编号取条目;认不出返回 undefined。 */
324
+ bySeq(seq: number): ArchiveEntry | undefined {
325
+ this.load();
326
+ return this.archiveEntries.find((entry) => entry.seq === seq);
327
+ }
328
+
329
+ /** 存档里现有的编号范围,给「编号写错了」这类回执用。 */
330
+ seqRange(): { min: number; max: number } | null {
331
+ this.load();
332
+ if (!this.archiveEntries.length) return null;
333
+ const seqs = this.archiveEntries.map((entry) => entry.seq);
334
+ return { min: Math.min(...seqs), max: Math.max(...seqs) };
282
335
  }
283
336
 
284
337
  clearArchive(feedId?: string): number {
package/src/types.ts CHANGED
@@ -32,8 +32,10 @@ export interface FeedRecord {
32
32
  seen: string[];
33
33
  }
34
34
 
35
- /** 给人看的一条消息(消息页签与索引工具共用)。 */
35
+ /** 给人看的一条消息(消息页签、索引工具与 rss_read 共用)。 */
36
36
  export interface ArchiveEntry {
37
+ /** 全局递增的短编号,展示成 `#12`;模型用它来点名要读哪一条。 */
38
+ seq: number;
37
39
  feedId: string;
38
40
  entryId: string;
39
41
  title: string;
@@ -32,6 +32,8 @@ interface FeedsState {
32
32
  }
33
33
 
34
34
  interface MessageRow {
35
+ /** 消息编号,展示成 `#12`,和模型手里的是同一个。 */
36
+ seq?: number;
35
37
  feedId: string;
36
38
  feedTitle: string;
37
39
  title: string;
@@ -487,13 +489,14 @@ const messagesPanel: WebUiPanel = {
487
489
  const titleLine = list.append(row.title, 'plain');
488
490
  titleLine.style.cursor = 'pointer';
489
491
  titleLine.title = S.readMore;
490
- list.append(`${row.timeText} · ${row.feedTitle}`, 'dim');
492
+ const tag = typeof row.seq === 'number' ? `#${row.seq} · ` : '';
493
+ list.append(`${tag}${row.timeText} · ${row.feedTitle}`, 'dim');
491
494
  if (row.summary && row.summary !== row.title) list.append(row.summary, 'plain');
492
495
  list.append('', 'dim');
493
496
 
494
497
  const open = () => {
495
498
  const body = ui.h('div');
496
- body.append(ui.msgline(`${row.feedTitle} · ${row.timeText}`));
499
+ body.append(ui.msgline(`${typeof row.seq === 'number' ? `#${row.seq} · ` : ''}${row.feedTitle} · ${row.timeText}`));
497
500
  const text = ui.h('div');
498
501
  text.textContent = row.body || row.summary || S.emptyBody;
499
502
  text.style.whiteSpace = 'pre-wrap';
package/src/world.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * RSS / Atom 订阅:每个源按自己的节奏被拉下来,新消息写成事件递给她。
3
- * 两个工具给她主动权:`rss_fetch` 立即拉取,`rss_index` 按关键词翻订阅源。
3
+ * 三个工具给她主动权:`rss_fetch` 立即拉取,`rss_index` 按关键词翻订阅源,
4
+ * `rss_read` 按编号读某条的全文(低消耗模式下这就是唯一看正文的入口)。
4
5
  *
5
6
  * 这个文件只管「什么时候拉、拉回来算新还是旧、递给谁」;解析、网络、落盘、文案各有自己的模块。
6
7
  */
@@ -20,9 +21,11 @@ import {
20
21
  renderFetchDigest,
21
22
  renderIndexDigest,
22
23
  renderNewItemsEvent,
24
+ renderReadResult,
23
25
  type FetchResultView,
24
26
  type IndexHit,
25
27
  type ItemView,
28
+ type ReadEntry,
26
29
  } from './model-text.ts';
27
30
  import { clampInt, dueReason, localTimeParts, nextRunAt } from './schedule.ts';
28
31
  import { haystackOf, normalizeKeywords, paginate, type MatchMode } from './search.ts';
@@ -41,6 +44,8 @@ const INDEX_CACHE_MS = 45_000;
41
44
  const ARCHIVE_PER_FETCH = 30;
42
45
  /** 索引工具一页最多几条。 */
43
46
  const INDEX_PAGE_MAX = 5;
47
+ /** `rss_read` 一次最多读几条全文。 */
48
+ const READ_LIMIT = 10;
44
49
 
45
50
  export const PANEL_FEEDS = 'feeds';
46
51
  export const PANEL_MESSAGES = 'messages';
@@ -133,12 +138,32 @@ export const RSS_TOOL_DECLS: ReadonlyArray<Omit<ToolDef, 'handler'>> = [
133
138
  required: ['feeds', 'keywords'],
134
139
  },
135
140
  },
141
+ {
142
+ name: 'rss_read',
143
+ description:
144
+ 'Read the full text of messages by their number. Every message handed over by rss_fetch, rss_index or an rss.new_items event carries a number like "#12"; pass those numbers here to get the whole body, the source feed, the time and the link. Read-only, no network. In low-cost mode this is the only way to see the body.',
145
+ tags: ['read'],
146
+ parameters: {
147
+ type: 'object',
148
+ additionalProperties: false,
149
+ properties: {
150
+ ids: {
151
+ type: 'array',
152
+ items: { type: ['string', 'number'] },
153
+ minItems: 1,
154
+ description: 'Message numbers, e.g. ["#12", "13", 14].',
155
+ },
156
+ },
157
+ required: ['ids'],
158
+ },
159
+ },
136
160
  ];
137
161
 
138
162
  /** 索引时每个源翻到的条目与失败原因。 */
139
163
  interface IndexFeedResult {
140
164
  feed: FeedRecord;
141
- entries: FeedEntry[];
165
+ /** 带存档编号的条目;编号在写档时分配。 */
166
+ entries: Array<FeedEntry & { seq?: number }>;
142
167
  /** 源里条目多于上限时被略过的数量。 */
143
168
  truncated: number;
144
169
  error?: string;
@@ -199,11 +224,15 @@ export class RssWorld implements World { readonly id = 'rss';
199
224
  .sort()
200
225
  .pop();
201
226
  const archive = this.store.archive().length;
227
+ const lowCost = this.lowCost();
202
228
  return {
203
229
  'rss.feeds': renderFeedList(feeds),
204
- 'rss.state': feeds.length
205
- ? `${feeds.length} 个源(${enabled.length} 个启用);${lastSuccess ? `最近一次成功拉取在 ${fmtLocal(lastSuccess, this.timezone())}` : '还没成功拉取过'}`
206
- : '还没有订阅任何源。',
230
+ 'rss.state': [
231
+ feeds.length
232
+ ? `${feeds.length} 个源(${enabled.length} 个启用);${lastSuccess ? `最近一次成功拉取在 ${fmtLocal(lastSuccess, this.timezone())}` : '还没成功拉取过'}`
233
+ : '还没有订阅任何源。',
234
+ lowCost ? '低消耗模式开着:消息只给编号与标题,正文要用 rss_read 按编号读。' : '',
235
+ ].filter(Boolean).join(' '),
207
236
  'rss.archive': `${archive} 条`,
208
237
  'rss.timezone': this.timezone(),
209
238
  };
@@ -219,6 +248,10 @@ export class RssWorld implements World { readonly id = 'rss';
219
248
  ...RSS_TOOL_DECLS[1],
220
249
  handler: (args, ctx) => this.indexTool(args, ctx.signal),
221
250
  },
251
+ {
252
+ ...RSS_TOOL_DECLS[2],
253
+ handler: async (args) => this.readTool(args),
254
+ },
222
255
  ];
223
256
  }
224
257
 
@@ -433,15 +466,24 @@ export class RssWorld implements World { readonly id = 'rss';
433
466
  this.store.update(feed.id, patch as Parameters<FeedStore['update']>[1]);
434
467
  if (fresh.length) this.store.markSeen(feed.id, fresh.map((entry) => entry.id));
435
468
 
469
+ // 先写存档:编号在那里分配,回头递给模型的每一条才带得上 #n。
470
+ const seqOf = new Map<string, number>();
436
471
  if (entries.length) {
437
- this.store.pushArchive(
472
+ const stored = this.store.pushArchive(
438
473
  entries.slice(0, ARCHIVE_PER_FETCH).map((entry) => this.toArchive(feed, entry, stamp)),
439
474
  );
475
+ for (const row of stored) seqOf.set(row.entryId, row.seq);
440
476
  }
441
477
 
478
+ // 存档里已经有这条(比如上一轮写过)时也要拿到原编号。
479
+ const seqFor = (entryId: string): number | undefined => {
480
+ if (seqOf.has(entryId)) return seqOf.get(entryId);
481
+ return this.store.archive().find((row) => row.feedId === feed.id && row.entryId === entryId)?.seq;
482
+ };
483
+
442
484
  const handedOver = fresh.length
443
- ? fresh.slice(0, feed.maxNewItems).map((entry) => this.toView(entry, true))
444
- : entries.slice(0, feed.maxNewItems).map((entry) => this.toView(entry, false));
485
+ ? fresh.slice(0, feed.maxNewItems).map((entry) => this.toView(entry, true, seqFor(entry.id)))
486
+ : entries.slice(0, feed.maxNewItems).map((entry) => this.toView(entry, false, seqFor(entry.id)));
445
487
 
446
488
  const result: FetchResultView = {
447
489
  feed,
@@ -451,7 +493,7 @@ export class RssWorld implements World { readonly id = 'rss';
451
493
  };
452
494
 
453
495
  if (fresh.length && feed.enabled) {
454
- const text = renderNewItemsEvent(result, this.timezone(), this.clampBody());
496
+ const text = renderNewItemsEvent(result, this.timezone(), this.clampBody(), this.lowCost());
455
497
  this.pushEvent(feed, text).catch((error: unknown) => {
456
498
  this.log.warn('新消息事件投递失败', { error: String(error) });
457
499
  });
@@ -464,8 +506,9 @@ export class RssWorld implements World { readonly id = 'rss';
464
506
  return result;
465
507
  }
466
508
 
467
- private toView(entry: FeedEntry, isNew: boolean): ItemView {
509
+ private toView(entry: FeedEntry, isNew: boolean, seq?: number): ItemView {
468
510
  return {
511
+ ...(typeof seq === 'number' ? { seq } : {}),
469
512
  title: entry.title,
470
513
  link: entry.link,
471
514
  body: entry.body,
@@ -475,7 +518,8 @@ export class RssWorld implements World { readonly id = 'rss';
475
518
  };
476
519
  }
477
520
 
478
- private toArchive(feed: FeedRecord, entry: FeedEntry, fetchedAt: string): ArchiveEntry {
521
+ /** 存档行;编号由 `pushArchive` 分配,这里不带。 */
522
+ private toArchive(feed: FeedRecord, entry: FeedEntry, fetchedAt: string): Omit<ArchiveEntry, 'seq'> {
479
523
  return {
480
524
  feedId: feed.id,
481
525
  entryId: entry.id,
@@ -495,6 +539,7 @@ export class RssWorld implements World { readonly id = 'rss';
495
539
  .filter((entry) => entry.feedId === feedId)
496
540
  .slice(0, Math.max(1, limit))
497
541
  .map((entry) => ({
542
+ seq: entry.seq,
498
543
  title: entry.title,
499
544
  link: entry.link,
500
545
  body: entry.body,
@@ -508,6 +553,11 @@ export class RssWorld implements World { readonly id = 'rss';
508
553
  return Math.min(2000, Math.max(0, this.cfg().maxBodyChars ?? RSS_DEFAULTS.maxBodyChars));
509
554
  }
510
555
 
556
+ /** 低消耗模式:只给编号、来源、时间、标题;正文留给 rss_read。 */
557
+ private lowCost(): boolean {
558
+ return this.cfg().lowCost === true;
559
+ }
560
+
511
561
  private async pushEvent(feed: FeedRecord, text: string): Promise<void> {
512
562
  const host = this.host;
513
563
  if (!host) return;
@@ -579,6 +629,7 @@ export class RssWorld implements World { readonly id = 'rss';
579
629
  timezone: this.timezone(),
580
630
  maxChars: this.clampBody(),
581
631
  notes,
632
+ lowCost: this.lowCost(),
582
633
  });
583
634
  }
584
635
 
@@ -645,6 +696,7 @@ export class RssWorld implements World { readonly id = 'rss';
645
696
  const matched = keywords.filter((keyword) => haystack.includes(keyword.toLowerCase()));
646
697
  if (mode === 'all' ? matched.length !== keywords.length : matched.length === 0) continue;
647
698
  hits.push({
699
+ ...(typeof entry.seq === 'number' ? { seq: entry.seq } : {}),
648
700
  feed: result.feed,
649
701
  title: entry.title,
650
702
  link: entry.link,
@@ -673,6 +725,7 @@ export class RssWorld implements World { readonly id = 'rss';
673
725
  feedCount: fetched.filter((result) => !result.error).length,
674
726
  truncated,
675
727
  hits: paged.rows,
728
+ lowCost: this.lowCost(),
676
729
  });
677
730
 
678
731
  return notes.length ? `${digest}\n\n${notes.join('\n')}` : digest;
@@ -695,15 +748,22 @@ export class RssWorld implements World { readonly id = 'rss';
695
748
  }
696
749
  const parsed = parseFeed(response.text);
697
750
  const entries = sortNewestFirst(parsed.entries);
751
+ const limited = entries.slice(0, limit);
752
+ const stamp = new Date(this.nowMs()).toISOString();
753
+ // 索引命中的条目也要有编号,低消耗模式下模型才能用 rss_read 读全文。
754
+ const seqOf = new Map<string, number>();
755
+ if (limited.length) {
756
+ const stored = this.store.pushArchive(limited.map((entry) => this.toArchive(feed, entry, stamp)));
757
+ for (const row of stored) seqOf.set(row.entryId, row.seq);
758
+ }
698
759
  const result: IndexFeedResult = {
699
760
  feed,
700
- entries: entries.slice(0, limit),
761
+ entries: limited.map((entry) => {
762
+ const seq = seqOf.get(entry.id) ?? this.archiveSeq(feed.id, entry.id);
763
+ return typeof seq === 'number' ? { ...entry, seq } : entry;
764
+ }),
701
765
  truncated: Math.max(0, entries.length - limit),
702
766
  };
703
- const stamp = new Date(this.nowMs()).toISOString();
704
- if (result.entries.length) {
705
- this.store.pushArchive(result.entries.map((entry) => this.toArchive(feed, entry, stamp)));
706
- }
707
767
  this.recentIndex.set(feed.id, { at: this.nowMs(), result });
708
768
  return result;
709
769
  } catch (error) {
@@ -716,6 +776,70 @@ export class RssWorld implements World { readonly id = 'rss';
716
776
  }
717
777
  }
718
778
 
779
+ /** 存档里这条消息的编号(之前写过就有)。 */
780
+ private archiveSeq(feedId: string, entryId: string): number | undefined {
781
+ return this.store.archive().find((row) => row.feedId === feedId && row.entryId === entryId)?.seq;
782
+ }
783
+
784
+ // ── 工具:按编号读全文 ──────────────────────────────────────────────
785
+
786
+ /**
787
+ * `rss_read`:模型拿着 `#12` 这样的编号来要正文。纯读存档,不发网络请求。
788
+ * 编号认不出、越界、已被存档上限挤掉,都写进回执,不当作失败——它只是想知道那条讲了什么。
789
+ */
790
+ private readTool(args: Record<string, unknown>): string | ToolOutcome {
791
+ const raw = Array.isArray(args.ids) ? args.ids : args.ids === undefined ? [] : [args.ids];
792
+ const wanted: number[] = [];
793
+ const unparsed: string[] = [];
794
+ for (const item of raw) {
795
+ const parsed = parseSeq(item);
796
+ if (parsed === null) {
797
+ unparsed.push(String(item ?? ''));
798
+ continue;
799
+ }
800
+ if (!wanted.includes(parsed)) wanted.push(parsed);
801
+ }
802
+ if (!wanted.length && !unparsed.length) {
803
+ return { text: 'rss_read 需要至少一个编号,比如 {"ids":["#12","13"]}。', failed: true };
804
+ }
805
+
806
+ const titles = new Map(this.store.list().map((feed) => [feed.id, feed.title]));
807
+ const entries: ReadEntry[] = [];
808
+ const missing: number[] = [];
809
+ // 一次最多读 10 条:再多就该用 rss_index 缩小范围,而不是把整档塞进上下文。
810
+ for (const seq of wanted.slice(0, READ_LIMIT)) {
811
+ const row = this.store.bySeq(seq);
812
+ if (!row) {
813
+ missing.push(seq);
814
+ continue;
815
+ }
816
+ entries.push({
817
+ seq: row.seq,
818
+ feedTitle: titles.get(row.feedId) ?? row.feedId,
819
+ title: row.title,
820
+ link: row.link,
821
+ body: row.body,
822
+ summary: row.summary,
823
+ ...(row.publishedAt ? { publishedAt: row.publishedAt } : {}),
824
+ fetchedAt: row.fetchedAt,
825
+ });
826
+ }
827
+ const overflow = wanted.slice(READ_LIMIT);
828
+
829
+ const text = renderReadResult({
830
+ timezone: this.timezone(),
831
+ maxChars: this.clampBody(),
832
+ entries,
833
+ missing,
834
+ unparsed,
835
+ range: this.store.seqRange(),
836
+ });
837
+ const suffix = overflow.length
838
+ ? `\n\n(这次只要前 ${READ_LIMIT} 条:#${overflow.join('、#')} 没读。分两次调。)`
839
+ : '';
840
+ return entries.length ? `${text}${suffix}` : { text: `${text}${suffix}`, failed: true };
841
+ }
842
+
719
843
  // ── WebUI ───────────────────────────────────────────────────────────
720
844
 
721
845
  private async invoke(panel: string, method: string, args: unknown[]): Promise<unknown> {
@@ -844,6 +968,7 @@ export class RssWorld implements World { readonly id = 'rss';
844
968
  rows: page.rows.map((entry) => ({
845
969
  feedId: entry.feedId,
846
970
  feedTitle: titles.get(entry.feedId) ?? entry.feedId,
971
+ seq: entry.seq,
847
972
  title: entry.title,
848
973
  link: entry.link,
849
974
  summary: entry.summary,
@@ -900,6 +1025,19 @@ function hostOf(url: string): string {
900
1025
  }
901
1026
  }
902
1027
 
1028
+ /**
1029
+ * 编号解析:接受 `#12`、`12`、`#12`、`" 12 "`,也接受数字本身。
1030
+ * 认不出返回 null(交给调用方写进「认不出」那一栏)。
1031
+ */
1032
+ export function parseSeq(value: unknown): number | null {
1033
+ if (typeof value === 'number') return Number.isInteger(value) && value > 0 ? value : null;
1034
+ if (typeof value !== 'string') return null;
1035
+ const text = value.trim().replace(/^[##\s]+/, '');
1036
+ if (!/^\d+$/.test(text)) return null;
1037
+ const parsed = Number.parseInt(text, 10);
1038
+ return parsed > 0 ? parsed : null;
1039
+ }
1040
+
903
1041
  /** 界面来的参数什么形状都可能有,这里只挑认识的键。 */
904
1042
  function asFeedInput(raw: unknown): FeedInput {
905
1043
  const value = (raw ?? {}) as Record<string, unknown>;