@chen_hu_hu/pi-qq 1.6.1 → 1.7.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 +27 -1
- package/README-zh.md +6 -7
- package/README.md +19 -20
- package/doc/archive/delivery.1.6.2.md +196 -0
- package/doc/archive/delivery.1.7.0.md +96 -0
- package/index.ts +0 -16
- package/package.json +1 -1
- package/src/attachments/attachment-download.ts +2 -1
- package/src/attachments/file-attachments.ts +4 -5
- package/src/infra/file-logger.ts +6 -6
- package/src/infra/i18n.ts +4 -196
- package/src/infra/log-message-keys.ts +66 -0
- package/src/infra/power-status.ts +1 -11
- package/src/infra/reply-type.ts +1 -1
- package/src/qq/inbound-attachments.ts +2 -2
- package/src/qq/inbound-command.ts +8 -7
- package/src/qq/media-tool.ts +43 -61
- package/src/qq/msg-seq-send.ts +11 -0
- package/src/qq/qq-bot.ts +1 -1
- package/src/qq/qq-diagnostics.ts +3 -2
- package/src/qq/qq-message-handler.ts +5 -6
- package/src/qq/reply-sender.ts +6 -2
- package/src/qq/status-report.ts +1 -13
- package/src/quota/reply-quota.ts +2 -2
- package/src/relay/bubble-writer.ts +84 -38
- package/src/relay/msg-seq.ts +15 -0
- package/src/relay/reply-policy.ts +0 -13
- package/src/relay/run-stream-relay.ts +129 -202
- package/src/relay/run-timeline.ts +127 -0
- package/src/relay/stream-block-format.ts +1 -1
- package/src/relay/stream-session.ts +28 -10
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.7.0] - 2026-11-11
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Stream and outbound message sends now allocate `msg_seq` monotonically per inbound `msgId` instead of using the SDK's random helper, avoiding duplicate sequences within a message.
|
|
15
|
+
|
|
16
|
+
## [1.6.2] - 2026-11-11
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- While a task is running in `replyType: "full"`, `/last` now pushes the current thinking, tools, and text snapshot to the new message immediately instead of waiting for assistant text. If the stream was dead, the repush opens a new stream and resumes later output. An empty snapshot now replies with a notice instead of staying silent.
|
|
21
|
+
- Log files are now always written in English; the `language` setting only affects UI notifications and replies.
|
|
22
|
+
- Consolidated the 1.6.2 code review and repair notes into `doc/archive/delivery.1.6.2.md`; removed the temporary `doc/repair.md`.
|
|
23
|
+
|
|
24
|
+
### Removed
|
|
25
|
+
|
|
26
|
+
- Removed `replyType: "last"`; the only modes are now `full` and `simple`. Existing `"last"` values fall back to `full` with a validation warning.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- Stream rate-limit retries now advance `index` and recognize QQ `ApiError` HTTP/business codes.
|
|
31
|
+
- A `40054005` duplicate-`msgseq` error now opens a new stream with a fresh sequence and replays the buffered content instead of repeatedly resuming the failed stream.
|
|
32
|
+
- Empty attachment responses are rejected consistently.
|
|
33
|
+
|
|
10
34
|
## [1.6.1] - 2026-11-11
|
|
11
35
|
|
|
12
36
|
### Changed
|
|
@@ -161,7 +185,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
161
185
|
- Added thinking labels, per-tool icons, model-error recovery, and idle-safe session handling.
|
|
162
186
|
- Reorganized modules by bounded context and updated settings and delivery documentation.
|
|
163
187
|
|
|
164
|
-
[Unreleased]: https://github.com/CQ-Developer/pi-qq/compare/v1.
|
|
188
|
+
[Unreleased]: https://github.com/CQ-Developer/pi-qq/compare/v1.7.0...HEAD
|
|
189
|
+
[1.7.0]: https://github.com/CQ-Developer/pi-qq/compare/v1.6.2...v1.7.0
|
|
190
|
+
[1.6.2]: https://github.com/CQ-Developer/pi-qq/compare/v1.6.1...v1.6.2
|
|
165
191
|
[1.6.1]: https://github.com/CQ-Developer/pi-qq/compare/v1.6.0...v1.6.1
|
|
166
192
|
[1.6.0]: https://github.com/CQ-Developer/pi-qq/compare/v1.5.1...v1.6.0
|
|
167
193
|
[1.5.1]: https://github.com/CQ-Developer/pi-qq/compare/v1.5.0...v1.5.1
|
package/README-zh.md
CHANGED
|
@@ -105,7 +105,7 @@ QQ 侧命令:
|
|
|
105
105
|
| `/stop` | 中止当前运行 |
|
|
106
106
|
| `/compact` | 压缩当前上下文 |
|
|
107
107
|
| `/status` | 显示会话和上下文状态 |
|
|
108
|
-
| `/last` |
|
|
108
|
+
| `/last` | 运行中重推当前输出;空闲时重推最近完成的回复 |
|
|
109
109
|
| `/help` | 显示命令帮助 |
|
|
110
110
|
|
|
111
111
|
### 诊断
|
|
@@ -134,10 +134,10 @@ QQ 侧命令:
|
|
|
134
134
|
|
|
135
135
|
| 配置项 | 默认值 | 说明 |
|
|
136
136
|
| ------------- | ---------- | ------------------------------------------------------ |
|
|
137
|
-
| `replyType` | `"full"` | 推送到 QQ 的内容粒度:`full
|
|
137
|
+
| `replyType` | `"full"` | 推送到 QQ 的内容粒度:`full` 或 `simple` |
|
|
138
138
|
| `deliverAs` | `"steer"` | 忙碌时新消息的排队方式:`steer` 或 `followUp` |
|
|
139
139
|
| `fileMaxSize` | `52428800` | QQ 附件下载上限(字节,50MB) |
|
|
140
|
-
| `language` | `"zh-cn"` | UI
|
|
140
|
+
| `language` | `"zh-cn"` | UI 语言:`zh-cn` 或 `en-us`;日志始终为英文 |
|
|
141
141
|
| `logLevel` | `"silent"` | 日志阈值:`silent`、`error`、`warn`、`info` 或 `debug` |
|
|
142
142
|
|
|
143
143
|
配置在扩展加载时读取,并在每条来自已绑定用户的 QQ 消息处理前重新读取。修改后下一条消息即生效,无需重启 pi 或重新登录。未知配置项会被忽略,无效值会回退到默认值并给出提示。
|
|
@@ -150,13 +150,12 @@ QQ 侧命令:
|
|
|
150
150
|
| -------- | ------------------------------------------------------------- |
|
|
151
151
|
| `full` | 思考块、工具调用、工具结果,以及每一条 assistant 消息(默认) |
|
|
152
152
|
| `simple` | 只推 assistant 消息,每条一个气泡 |
|
|
153
|
-
| `last` | 只推 run 中最后一条 assistant 消息,在 run 结束时送出 |
|
|
154
153
|
|
|
155
154
|
- `full` 是默认值,保持 pi-qq 1.5.x 的行为;该模式固定回传思考。
|
|
156
155
|
- `simple` 会实时流出每一条 assistant 消息,一条消息一个气泡。
|
|
157
|
-
- `last` 在任务运行期间不推送任何内容;运行期间执行 `/last` 会回复“任务仍在进行中”。
|
|
158
156
|
- 无论哪种模式,模型错误消息都会立即以普通消息发出。
|
|
159
|
-
- `simple`
|
|
157
|
+
- `simple` 不回传工具输出,但 `qq_send_media` 发送的文件仍然会送达。
|
|
158
|
+
- 任务运行中执行 `/last` 时,`full` 模式会推送当前思考、工具和文本快照;`simple` 模式只推送当前文本。
|
|
160
159
|
|
|
161
160
|
### `deliverAs`
|
|
162
161
|
|
|
@@ -171,7 +170,7 @@ QQ 侧命令:
|
|
|
171
170
|
|
|
172
171
|
### `language`
|
|
173
172
|
|
|
174
|
-
UI
|
|
173
|
+
UI 提示与回复的语言。日志文件始终使用英文,不受该配置影响。
|
|
175
174
|
|
|
176
175
|
- `zh-cn`(默认):简体中文。
|
|
177
176
|
- `en-us`:英文。
|
package/README.md
CHANGED
|
@@ -99,14 +99,14 @@ Run these in the pi terminal:
|
|
|
99
99
|
|
|
100
100
|
QQ-side commands:
|
|
101
101
|
|
|
102
|
-
| Command | Description
|
|
103
|
-
| ---------- |
|
|
104
|
-
| `/new` | Start a new pi session
|
|
105
|
-
| `/stop` | Abort the current run
|
|
106
|
-
| `/compact` | Compact the current context
|
|
107
|
-
| `/status` | Show session and context status
|
|
108
|
-
| `/last` |
|
|
109
|
-
| `/help` | Show command help
|
|
102
|
+
| Command | Description |
|
|
103
|
+
| ---------- | -------------------------------------------------------------------------- |
|
|
104
|
+
| `/new` | Start a new pi session |
|
|
105
|
+
| `/stop` | Abort the current run |
|
|
106
|
+
| `/compact` | Compact the current context |
|
|
107
|
+
| `/status` | Show session and context status |
|
|
108
|
+
| `/last` | Repush current output while running, or the last completed reply when idle |
|
|
109
|
+
| `/help` | Show command help |
|
|
110
110
|
|
|
111
111
|
### Diagnostics
|
|
112
112
|
|
|
@@ -132,13 +132,13 @@ Create `~/.pi/agent/pi-qq.json` to override defaults. It stores settings only; c
|
|
|
132
132
|
}
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
| Key | Default | Description
|
|
136
|
-
| ------------- | ---------- |
|
|
137
|
-
| `replyType` | `"full"` | How much of a run is pushed to QQ: `full
|
|
138
|
-
| `deliverAs` | `"steer"` | Queue new messages while busy: `steer` or `followUp`
|
|
139
|
-
| `fileMaxSize` | `52428800` | QQ attachment download limit in bytes (50MB)
|
|
140
|
-
| `language` | `"zh-cn"` | UI
|
|
141
|
-
| `logLevel` | `"silent"` | Log threshold: `silent`, `error`, `warn`, `info`, or `debug`
|
|
135
|
+
| Key | Default | Description |
|
|
136
|
+
| ------------- | ---------- | ------------------------------------------------------------- |
|
|
137
|
+
| `replyType` | `"full"` | How much of a run is pushed to QQ: `full` or `simple` |
|
|
138
|
+
| `deliverAs` | `"steer"` | Queue new messages while busy: `steer` or `followUp` |
|
|
139
|
+
| `fileMaxSize` | `52428800` | QQ attachment download limit in bytes (50MB) |
|
|
140
|
+
| `language` | `"zh-cn"` | UI language: `zh-cn` or `en-us`; log files are always English |
|
|
141
|
+
| `logLevel` | `"silent"` | Log threshold: `silent`, `error`, `warn`, `info`, or `debug` |
|
|
142
142
|
|
|
143
143
|
Settings are loaded when the extension starts and re-read on every inbound QQ message from the bound user, so edits take effect on the next message without restarting pi or logging in again. Unknown keys are ignored, and invalid values fall back to defaults with a warning.
|
|
144
144
|
|
|
@@ -150,13 +150,12 @@ How much of an agent run is pushed to QQ.
|
|
|
150
150
|
| -------- | -------------------------------------------------------------------------------- |
|
|
151
151
|
| `full` | Thinking blocks, tool calls, tool results, and every assistant message (default) |
|
|
152
152
|
| `simple` | Assistant messages only, one bubble each |
|
|
153
|
-
| `last` | Only the last assistant message of the run, sent when the run ends |
|
|
154
153
|
|
|
155
154
|
- `full` is the default and keeps the behaviour of pi-qq 1.5.x; thinking is always relayed in this mode.
|
|
156
155
|
- `simple` streams every assistant message live, one QQ bubble per message.
|
|
157
|
-
-
|
|
158
|
-
-
|
|
159
|
-
-
|
|
156
|
+
- Model errors are always delivered immediately as a normal message, in either mode.
|
|
157
|
+
- Tool output is not relayed in `simple`, but files sent with `qq_send_media` are still delivered.
|
|
158
|
+
- While a task is running, `/last` pushes the current thinking/tools/text snapshot in `full` mode; in `simple` mode it pushes the current text.
|
|
160
159
|
|
|
161
160
|
### `deliverAs`
|
|
162
161
|
|
|
@@ -171,7 +170,7 @@ Maximum size of an inbound attachment, in bytes (default `52428800`, 50MB). Larg
|
|
|
171
170
|
|
|
172
171
|
### `language`
|
|
173
172
|
|
|
174
|
-
Language of
|
|
173
|
+
Language of UI notifications and replies. Log files are always written in English, regardless of this setting.
|
|
175
174
|
|
|
176
175
|
- `zh-cn` (default): Simplified Chinese.
|
|
177
176
|
- `en-us`: English.
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# pi-qq delivery 1.6.2
|
|
2
|
+
|
|
3
|
+
> **Delivery record.** 1.6.2 makes `/last` repush the current run snapshot, hardens stream recovery, removes `replyType: "last"`, and consolidates the code-review and repair notes. See [README](../../README.md) for current user-facing behavior.
|
|
4
|
+
> Version: 1.6.2
|
|
5
|
+
> Date: 2026-11-11
|
|
6
|
+
> Previous: [delivery.1.6.1.md](./delivery.1.6.1.md).
|
|
7
|
+
> Open work: [doc/todo.md](../todo.md).
|
|
8
|
+
|
|
9
|
+
## 1. Scope
|
|
10
|
+
|
|
11
|
+
Before 1.6.2, `/last` during a run only repushed `run.currentText`. If the run was still producing thinking or tools, the command silently did nothing. A separate long-run defect also stopped all relay output when QQ returned `40054005` (duplicate `msgseq`).
|
|
12
|
+
|
|
13
|
+
1.6.2 covers:
|
|
14
|
+
|
|
15
|
+
- `/last` snapshot repush for `replyType: "full"`;
|
|
16
|
+
- separation of run content state from stream delivery;
|
|
17
|
+
- removal of `replyType: "last"`;
|
|
18
|
+
- rate-limit retry correctness;
|
|
19
|
+
- fresh-stream recovery for duplicate `msgseq`;
|
|
20
|
+
- English-only log messages;
|
|
21
|
+
- dead-code and duplication cleanup from the full code review;
|
|
22
|
+
- direct tests for the new timeline and writer boundaries.
|
|
23
|
+
|
|
24
|
+
Out of scope:
|
|
25
|
+
|
|
26
|
+
- replaying the complete run history;
|
|
27
|
+
- changing model/agent behavior or tool set;
|
|
28
|
+
- adding tool partial-output forwarding;
|
|
29
|
+
- docs packaging changes and optional large refactors listed in section 8.
|
|
30
|
+
|
|
31
|
+
## 2. Observed failure
|
|
32
|
+
|
|
33
|
+
The 2026-11-11 log contained a 26-minute run that reached 221 stream bubbles. At 12:55:19 local time the next stream used a previously used `msg_seq`:
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
40054005 消息被去重,请检查请求msgseq
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The same checkpoint `msgSeq` was retried twice, all retries were rejected, and `BubbleWriter` killed the stream. After that:
|
|
40
|
+
|
|
41
|
+
- 146 subsequent tool starts produced no relay output;
|
|
42
|
+
- `/last` at 13:01:44 and 13:04:21 logged `last repush ignored` with `textLength=0`;
|
|
43
|
+
- the first assistant text appeared at 13:09:56, after both `/last` calls;
|
|
44
|
+
- the final text used the normal plain-message fallback.
|
|
45
|
+
|
|
46
|
+
The `/last` calls did not fail because the text was too old; at that moment there was no `currentText` at all. The run state and the delivery writer were coupled, so `/last` could not use the thinking/tool state.
|
|
47
|
+
|
|
48
|
+
## 3. Final decisions
|
|
49
|
+
|
|
50
|
+
| # | Question | Decision |
|
|
51
|
+
| --- | ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| D1 | What should `/last` push during a full-mode run? | The current thinking, the active/recent tools, and the current text, without waiting for assistant text. |
|
|
53
|
+
| D2 | How much history should `/last` replay? | A bounded state snapshot: current active tool plus the last three finished tools, capped at five. |
|
|
54
|
+
| D3 | Should run state depend on the writer? | No. `RunTimeline` owns content and tool lifecycle; `RunFeedback` decides delivery. |
|
|
55
|
+
| D4 | What should happen on `40054005`? | Open a new stream with a fresh `msgSeq`, replay the failed buffer, and keep the existing recovery cap. |
|
|
56
|
+
| D5 | Should `replyType: "last"` remain? | No. Keep only `full` and `simple`; old `"last"` values fall back to `full` with a validation warning. |
|
|
57
|
+
| D6 | Should log files follow `language`? | No. Log messages are written directly in English; `language` only affects UI notifications and replies. |
|
|
58
|
+
| D7 | Should `/last` fail silently when there is no content? | No. Reply with `commands.last.empty`. |
|
|
59
|
+
|
|
60
|
+
## 4. `/last` snapshot
|
|
61
|
+
|
|
62
|
+
`repushCurrent()` now builds a `RepushResult` instead of returning a bare boolean:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
type RepushResult =
|
|
66
|
+
| { ok: true; thinkingLength: number; toolCount: number; textLength: number }
|
|
67
|
+
| { ok: false; reason: "no-run" | "empty" };
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Full-mode snapshot order:
|
|
71
|
+
|
|
72
|
+
1. current thinking;
|
|
73
|
+
2. current active tool and recent finished tools in start order;
|
|
74
|
+
3. current assistant text.
|
|
75
|
+
|
|
76
|
+
`BubbleWriter.restartSnapshot()` accepts structured blocks and:
|
|
77
|
+
|
|
78
|
+
- closes an open code fence;
|
|
79
|
+
- rotates the old stream;
|
|
80
|
+
- updates the target `openid` / `msgId`;
|
|
81
|
+
- resets `streamDead`, pending resume, block and fence state;
|
|
82
|
+
- pushes thinking/tool/text blocks to the new stream.
|
|
83
|
+
|
|
84
|
+
`simple` mode uses a text-only snapshot. `last` mode no longer exists.
|
|
85
|
+
|
|
86
|
+
After a repush:
|
|
87
|
+
|
|
88
|
+
- `thinkingSentLen` / `resultSentLen` are not reset; they continue tracking processed content;
|
|
89
|
+
- deferred thinking/text are cleared because the snapshot already includes them;
|
|
90
|
+
- an active tool result and subsequent assistant deltas continue on the new stream.
|
|
91
|
+
|
|
92
|
+
## 5. Stream reliability
|
|
93
|
+
|
|
94
|
+
### 5.1 Rate-limit retries
|
|
95
|
+
|
|
96
|
+
`AppendStream.sendWithRetry()` now:
|
|
97
|
+
|
|
98
|
+
- advances `index` before a rate-limit retry, matching `qqbot-nodejs`'s `StreamSession`;
|
|
99
|
+
- recognizes `status`, `httpStatus`, `code`, `err_code`, `bizCode`, and message text for 429/50002.
|
|
100
|
+
|
|
101
|
+
### 5.2 Duplicate `msgseq`
|
|
102
|
+
|
|
103
|
+
`BubbleWriter.handleStreamError()` detects `40054005` / duplicate-`msgseq` messages. Instead of resuming the same checkpoint, it opens a fresh stream with:
|
|
104
|
+
|
|
105
|
+
- no old `msgSeq` (the new stream generates one);
|
|
106
|
+
- `index: 0`;
|
|
107
|
+
- the failed buffer preserved.
|
|
108
|
+
|
|
109
|
+
Other stream errors keep the existing resume semantics. The recovery-attempt cap still applies.
|
|
110
|
+
|
|
111
|
+
## 6. Implementation
|
|
112
|
+
|
|
113
|
+
| File | Change |
|
|
114
|
+
| ------------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `src/relay/run-timeline.ts` (new) | `RunTimeline`, tool state, snapshot selection, diagnostics |
|
|
116
|
+
| `src/relay/run-stream-relay.ts` | Uses `RunTimeline`; `advanceTools()`; `RepushResult`; removes last-mode delivery and fallback |
|
|
117
|
+
| `src/relay/bubble-writer.ts` | `RepushBlock`, `restartSnapshot()`, fresh-stream recovery, options-based push API |
|
|
118
|
+
| `src/relay/stream-session.ts` | Rate-limit index advance, API status fields, optional fresh `msgSeq` resume |
|
|
119
|
+
| `src/relay/reply-policy.ts` | Removes `relayTextLive`, `deliverLastAtEnd`, and last policy |
|
|
120
|
+
| `src/infra/reply-type.ts` | Only `full` and `simple` |
|
|
121
|
+
| `src/qq/inbound-command.ts` | `/last` consumes `InboundPushResult`; empty snapshot notice |
|
|
122
|
+
| `src/qq/media-tool.ts` | Shared send/result helper; removes test-only `isActive` |
|
|
123
|
+
| `src/infra/file-logger.ts` | Writes direct English messages; `msgKey` lookup only |
|
|
124
|
+
| `src/infra/log-message-keys.ts` (new) | Stable English message-to-key map |
|
|
125
|
+
| `src/infra/i18n.ts` | UI strings only; log translations and localization removed |
|
|
126
|
+
|
|
127
|
+
## 7. Verification
|
|
128
|
+
|
|
129
|
+
Automated:
|
|
130
|
+
|
|
131
|
+
- **234 tests** across 22 files.
|
|
132
|
+
- `npm run lint`, `npm run typecheck`, `npm run format:check`, and `npm pack --dry-run` pass.
|
|
133
|
+
- New tests cover:
|
|
134
|
+
- thinking-only and tool-only `/last` snapshots;
|
|
135
|
+
- snapshot ordering and the tool window;
|
|
136
|
+
- writer-dead recovery;
|
|
137
|
+
- continuation of tool results after repush;
|
|
138
|
+
- `40054005` fresh-stream recovery;
|
|
139
|
+
- rate-limit index and `httpStatus` / `bizCode` detection;
|
|
140
|
+
- direct `restartSnapshot()` behavior.
|
|
141
|
+
|
|
142
|
+
Manual QQ smoke test (`pi-qq-2026-11-11.log`, local time 18:11–18:17):
|
|
143
|
+
|
|
144
|
+
- four runs covering `simple` and `full`;
|
|
145
|
+
- `/last` in full mode repushed 366 characters of current thinking and two tools with a new `msgId`;
|
|
146
|
+
- `/status` returned the expected full-mode report;
|
|
147
|
+
- `/stop` ended both active runs;
|
|
148
|
+
- no warnings, stream errors, `40054005`, or rate-limit events.
|
|
149
|
+
|
|
150
|
+
Not manually exercised:
|
|
151
|
+
|
|
152
|
+
- actual rate-limit retry;
|
|
153
|
+
- actual `40054005` recovery;
|
|
154
|
+
- `/last` with a dead writer;
|
|
155
|
+
- `/last` in `simple` mode.
|
|
156
|
+
|
|
157
|
+
These paths are covered by automated tests.
|
|
158
|
+
|
|
159
|
+
## 8. Code review consolidation
|
|
160
|
+
|
|
161
|
+
Fixed from the review:
|
|
162
|
+
|
|
163
|
+
- rate-limit retry index and API error fields;
|
|
164
|
+
- duplicate-`msgseq` recovery;
|
|
165
|
+
- unused relay/command surface and dead translations;
|
|
166
|
+
- duplicated media send/result construction and text-delta handling;
|
|
167
|
+
- command-layer dependency on the relay `RepushResult` type;
|
|
168
|
+
- unnecessary `index` option in attachment saves;
|
|
169
|
+
- empty attachment responses;
|
|
170
|
+
- English-only log messages.
|
|
171
|
+
|
|
172
|
+
Deferred intentionally:
|
|
173
|
+
|
|
174
|
+
- npm package docs policy (`doc/todo.md` and archive docs) is left to the release owner;
|
|
175
|
+
- splitting `index.ts`, `BubbleWriter`, or the large `run-stream-relay` test file further;
|
|
176
|
+
- a broader `ReplyType` policy refactor beyond the two remaining modes.
|
|
177
|
+
|
|
178
|
+
No dependency cycles were found.
|
|
179
|
+
|
|
180
|
+
## 9. Risks and limitations
|
|
181
|
+
|
|
182
|
+
| Risk | Impact | Handling |
|
|
183
|
+
| ------------------------------------------------------------ | -------------------------------------------------- | ----------------------------------------------------------- |
|
|
184
|
+
| Snapshot order differs from the original interleaving | Repush is a state snapshot, not a full transcript | Documented behavior |
|
|
185
|
+
| Tool window is bounded | Older tools are omitted | Active tool + last three finished tools |
|
|
186
|
+
| A duplicate-`msgseq` repush can create a new bubble | The old bubble remains | Only triggered by a stream failure; history is not replayed |
|
|
187
|
+
| `replyType: "last"` removal is breaking for configured users | Values fall back to full with a warning | Documented in the READMEs and changelog |
|
|
188
|
+
| Log language no longer follows `language` | Existing users may expect localized logs | Logs are stable English; UI remains localized |
|
|
189
|
+
| `doc/` contents are still in the current package manifest | Internal notes may ship until packaging is changed | Deferred to the release owner |
|
|
190
|
+
|
|
191
|
+
## 10. References
|
|
192
|
+
|
|
193
|
+
- User-facing behavior: [README.md](../../README.md), [README-zh.md](../../README-zh.md).
|
|
194
|
+
- Previous delivery: [delivery.1.6.1.md](./delivery.1.6.1.md).
|
|
195
|
+
- Manual test log: `/home/chen/project/mine/pi-qq-test/.pi/pi-qq/logs/pi-qq-2026-11-11.log`.
|
|
196
|
+
- This record replaces the temporary `doc/repair.md` and code-review working notes.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# pi-qq delivery 1.7.0
|
|
2
|
+
|
|
3
|
+
> **Delivery record.** 1.7.0 replaces the SDK's random `msg_seq` helper with a monotonic per-`msgId` allocator for every outbound message path. See [README](../../README.md) for current user-facing behavior.
|
|
4
|
+
> Version: 1.7.0
|
|
5
|
+
> Date: 2026-11-11
|
|
6
|
+
> Previous: [delivery.1.6.2.md](./delivery.1.6.2.md).
|
|
7
|
+
> Open work: [doc/todo.md](../todo.md).
|
|
8
|
+
|
|
9
|
+
## 1. Scope
|
|
10
|
+
|
|
11
|
+
1.6.2 added recovery for `40054005` after a duplicate `msgseq`, but kept the SDK's random `getNextMsgSeq()` helper. Random values in the range `0..65535` can collide within one inbound message, especially in long runs with hundreds of stream bubbles.
|
|
12
|
+
|
|
13
|
+
1.7.0 removes the randomness:
|
|
14
|
+
|
|
15
|
+
- allocate `msg_seq` monotonically per inbound `msgId`;
|
|
16
|
+
- use the allocator for custom stream messages;
|
|
17
|
+
- use the allocator for passive text, media, and diagnostic Markdown sends;
|
|
18
|
+
- keep proactive sends unchanged because they have no `msgId`;
|
|
19
|
+
- keep the existing fresh-stream recovery as a defensive fallback.
|
|
20
|
+
|
|
21
|
+
Out of scope:
|
|
22
|
+
|
|
23
|
+
- changing the QQ protocol range or `index` semantics;
|
|
24
|
+
- modifying the SDK package itself;
|
|
25
|
+
- changing proactive message sequencing;
|
|
26
|
+
- changing message formatting or relay behavior.
|
|
27
|
+
|
|
28
|
+
## 2. Final decisions
|
|
29
|
+
|
|
30
|
+
| # | Question | Decision |
|
|
31
|
+
| --- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
32
|
+
| D1 | Where does `msg_seq` come from? | A pi-qq-owned allocator keyed by `msgId`, not the SDK's random helper. |
|
|
33
|
+
| D2 | What values are allocated? | `0, 1, 2, ...` independently for each `msgId`. |
|
|
34
|
+
| D3 | What happens after 65535 allocations for one message? | Throw `msg_seq exhausted for message` instead of wrapping and risking a duplicate. |
|
|
35
|
+
| D4 | Which sends use the allocator? | Custom `stream_messages`, passive text replies, media sends, and diagnostic Markdown. |
|
|
36
|
+
| D5 | Which sends do not? | Proactive sends have no `msgId`; typing has no `msgId` and does not participate in message deduplication. |
|
|
37
|
+
| D6 | Is `40054005` recovery still needed? | Yes, as a fallback for any remaining or future collision source. |
|
|
38
|
+
|
|
39
|
+
## 3. Implementation
|
|
40
|
+
|
|
41
|
+
New module:
|
|
42
|
+
|
|
43
|
+
| File | Responsibility |
|
|
44
|
+
| ------------------------ | ----------------------------------------------------------------------------------------- |
|
|
45
|
+
| `src/relay/msg-seq.ts` | `allocateMsgSeq(msgId)` and test reset; per-`msgId` monotonic counter |
|
|
46
|
+
| `src/qq/msg-seq-send.ts` | `sendWithMsgSeq(bot, options)`; injects an allocated `msg_seq` for targets with a `msgId` |
|
|
47
|
+
|
|
48
|
+
Updated call sites:
|
|
49
|
+
|
|
50
|
+
| File | Change |
|
|
51
|
+
| ----------------------------- | -------------------------------------------------------- |
|
|
52
|
+
| `src/relay/stream-session.ts` | Uses `allocateMsgSeq()` instead of SDK `getNextMsgSeq()` |
|
|
53
|
+
| `src/qq/reply-sender.ts` | Text chunks use `sendWithMsgSeq()` |
|
|
54
|
+
| `src/qq/media-tool.ts` | Media sends use `sendWithMsgSeq()` |
|
|
55
|
+
| `src/qq/qq-diagnostics.ts` | Diagnostic Markdown uses `sendWithMsgSeq()` |
|
|
56
|
+
|
|
57
|
+
The helper calls the SDK's generic `send()` path with `extra.msg_seq`, so message type detection remains unchanged:
|
|
58
|
+
|
|
59
|
+
- `content` → text message;
|
|
60
|
+
- `markdown` → Markdown message;
|
|
61
|
+
- `media` → rich-media message.
|
|
62
|
+
|
|
63
|
+
## 4. Verification
|
|
64
|
+
|
|
65
|
+
Automated:
|
|
66
|
+
|
|
67
|
+
- **238 tests** across 24 files.
|
|
68
|
+
- `npm run lint`, `npm run typecheck`, `npm run format:check`, and `npm pack --dry-run` pass.
|
|
69
|
+
- New tests cover:
|
|
70
|
+
- independent counters for different `msgId` values;
|
|
71
|
+
- reset behavior;
|
|
72
|
+
- unique `msg_seq` for repeated text sends;
|
|
73
|
+
- media sends through `sendWithMsgSeq()`;
|
|
74
|
+
- no direct `sendText`, `sendMarkdown`, `sendMediaMessage`, or `getNextMsgSeq` use in pi-qq.
|
|
75
|
+
|
|
76
|
+
Not covered by a real QQ run in this release:
|
|
77
|
+
|
|
78
|
+
- exhaustion of all 65536 values for one message;
|
|
79
|
+
- a real collision after the allocator change (the automated allocator tests make this deterministic).
|
|
80
|
+
|
|
81
|
+
The 1.6.2 manual test remains the latest real QQ smoke test; it covered `/last`, `/status`, `/stop`, and normal text/stream output.
|
|
82
|
+
|
|
83
|
+
## 5. Risks and limitations
|
|
84
|
+
|
|
85
|
+
| Risk | Impact | Handling |
|
|
86
|
+
| ----------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------ |
|
|
87
|
+
| `msgId -> next` map growth | One number per inbound message for the process lifetime | Small per entry; can be pruned later if needed |
|
|
88
|
+
| Sequence exhaustion | A single message cannot create more than 65536 outbound sends | Explicit error instead of silent reuse |
|
|
89
|
+
| Proactive sends still use SDK sequencing | They have no `msgId` and do not participate in per-message dedupe | Accepted |
|
|
90
|
+
| SDK direct sends remain possible in future code | A new call could bypass the allocator | Code review and grep check for direct SDK send helpers |
|
|
91
|
+
|
|
92
|
+
## 6. References
|
|
93
|
+
|
|
94
|
+
- User-facing behavior: [README.md](../../README.md), [README-zh.md](../../README-zh.md).
|
|
95
|
+
- Previous delivery: [delivery.1.6.2.md](./delivery.1.6.2.md).
|
|
96
|
+
- Message sequence implementation: `src/relay/msg-seq.ts`, `src/qq/msg-seq-send.ts`.
|
package/index.ts
CHANGED
|
@@ -47,20 +47,6 @@ const runFeedback = new RunFeedback({
|
|
|
47
47
|
budget,
|
|
48
48
|
getReplyType: () => activeSettings.replyType,
|
|
49
49
|
onWarn: (msg) => sessionCtx?.ui.notify(`pi-qq ${msg}`, "warning"),
|
|
50
|
-
onFallbackReply: (text) => {
|
|
51
|
-
const bot = running?.bot;
|
|
52
|
-
const bound = getLoginState()?.allowedOpenid;
|
|
53
|
-
if (!bot || !bound) {
|
|
54
|
-
log.warn("pi", "fallback reply skipped: no bot or bound user");
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
log.info("pi", "sending fallback reply", { textLength: text.length });
|
|
58
|
-
void sendReply(bot, markdownToPlain(text), {
|
|
59
|
-
budget,
|
|
60
|
-
boundOpenid: bound,
|
|
61
|
-
onWarn: (msg) => sessionCtx?.ui.notify(`pi-qq ${msg}`, "warning"),
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
50
|
});
|
|
65
51
|
|
|
66
52
|
const eventLoopDelay = monitorEventLoopDelay({ resolution: 100 });
|
|
@@ -146,7 +132,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
146
132
|
|
|
147
133
|
const getAllowedOpenid = () => getLoginState()?.allowedOpenid;
|
|
148
134
|
const getDeliverAs = () => activeSettings.deliverAs;
|
|
149
|
-
const getReplyType = () => activeSettings.replyType;
|
|
150
135
|
|
|
151
136
|
const onWarn = (ctx: ExtensionContext) => (msg: string) => ctx.ui.notify(`pi-qq ${msg}`, "warning");
|
|
152
137
|
|
|
@@ -214,7 +199,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
214
199
|
getAllowedOpenid,
|
|
215
200
|
reloadSettings: () => applyConfig(ctx, { dedupeError: true }),
|
|
216
201
|
getDeliverAs,
|
|
217
|
-
getReplyType,
|
|
218
202
|
getFileMaxSize: () => activeSettings.fileMaxSize,
|
|
219
203
|
getStatusLines,
|
|
220
204
|
getLastMessage: () => runFeedback.getLastMessage(),
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ export interface InboundAttachmentLike {
|
|
|
8
8
|
size?: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
interface DownloadOptions {
|
|
12
12
|
url: string;
|
|
13
13
|
maxSize: number;
|
|
14
14
|
timeoutMs: number;
|
|
@@ -19,6 +19,7 @@ export interface DownloadOptions {
|
|
|
19
19
|
async function readBodyLimited(response: Response, limit: number, kind: string): Promise<Buffer> {
|
|
20
20
|
if (!response.body) {
|
|
21
21
|
const body = Buffer.from(await response.arrayBuffer());
|
|
22
|
+
if (body.byteLength === 0) throw new Error(t("attachments.empty", { kind }));
|
|
22
23
|
if (body.byteLength > limit) {
|
|
23
24
|
throw new Error(
|
|
24
25
|
t("attachments.tooLarge", { kind, size: formatBytes(body.byteLength), limit: formatBytes(limit) }),
|
|
@@ -14,16 +14,15 @@ export interface SavedFile {
|
|
|
14
14
|
path: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
type UploadIndex = Record<string, string>;
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
interface SaveFilesOptions {
|
|
20
20
|
maxSize: number;
|
|
21
21
|
uploadDir: string;
|
|
22
|
-
index?: UploadIndex;
|
|
23
22
|
fetchImpl?: typeof fetch;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
interface SaveFilesResult {
|
|
27
26
|
files: SavedFile[];
|
|
28
27
|
failures: AttachmentFailure[];
|
|
29
28
|
}
|
|
@@ -189,7 +188,7 @@ export async function saveInboundFiles(
|
|
|
189
188
|
const uploadDir = options.uploadDir;
|
|
190
189
|
const limit = Math.max(1, options.maxSize);
|
|
191
190
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
192
|
-
const index =
|
|
191
|
+
const index = await loadUploadIndex(uploadDir);
|
|
193
192
|
const files: SavedFile[] = [];
|
|
194
193
|
const failures: AttachmentFailure[] = [];
|
|
195
194
|
const seenPaths = new Set<string>();
|
package/src/infra/file-logger.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { logMessageKey } from "./log-message-keys";
|
|
4
4
|
|
|
5
5
|
export type LogLevel = "silent" | "error" | "warn" | "info" | "debug";
|
|
6
6
|
type LogFields = Record<string, unknown>;
|
|
@@ -93,13 +93,13 @@ function writeRecord(level: Exclude<LogLevel, "silent">, scope: string, message:
|
|
|
93
93
|
if (!isLevelEnabled(activeLevel, level)) return;
|
|
94
94
|
if (!isLogAllowed()) return;
|
|
95
95
|
|
|
96
|
-
const
|
|
96
|
+
const msgKey = logMessageKey(message);
|
|
97
97
|
const record: LogFields = {
|
|
98
98
|
time: new Date().toISOString(),
|
|
99
99
|
level,
|
|
100
100
|
scope,
|
|
101
|
-
...(
|
|
102
|
-
msg:
|
|
101
|
+
...(msgKey ? { msgKey } : {}),
|
|
102
|
+
msg: message,
|
|
103
103
|
};
|
|
104
104
|
const fields = normalizeData(data);
|
|
105
105
|
if (fields) {
|
|
@@ -122,8 +122,8 @@ function writeRecord(level: Exclude<LogLevel, "silent">, scope: string, message:
|
|
|
122
122
|
time: record.time,
|
|
123
123
|
level,
|
|
124
124
|
scope,
|
|
125
|
-
...(
|
|
126
|
-
msg:
|
|
125
|
+
...(msgKey ? { msgKey } : {}),
|
|
126
|
+
msg: message,
|
|
127
127
|
serializationError: stringifyError(err),
|
|
128
128
|
});
|
|
129
129
|
}
|