@240xu/dsh-message-ops 0.49.0 → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/index.js +29 -2
- package/src/session-file.js +35 -4
- package/src/session-trash.js +35 -8
package/README.md
CHANGED
|
@@ -32,12 +32,12 @@ dsh plugin --profile web add @240xu/dsh-message-ops
|
|
|
32
32
|
|
|
33
33
|
| 贡献者 | 反馈 / 补丁 | 关键线索 | 落地 |
|
|
34
34
|
| --- | --- | --- | --- |
|
|
35
|
-
| [@ooseven-zh2013](https://github.com/ooseven-zh2013) | PR [#11](https://github.com/240xu/dsh-message-ops/pull/11):动作行查找补 hash-agnostic 兜底 | 指出 0.2.2-rc.5 Desktop 的动作行 hash 是 `1KfHza_actions`,并给出「
|
|
36
|
-
| [@M1ch1bata](https://github.com/M1ch1bata) | PR [#6](https://github.com/240xu/dsh-message-ops/pull/6):换哈希后按钮重复注入 | 提出「先复用自家行再按后缀找官方行」,以及
|
|
35
|
+
| [@ooseven-zh2013](https://github.com/ooseven-zh2013) | PR [#11](https://github.com/240xu/dsh-message-ops/pull/11):动作行查找补 hash-agnostic 兜底 | 指出 0.2.2-rc.5 Desktop 的动作行 hash 是 `1KfHza_actions`,并给出「6 位 hash + `_actions` 形状」而非新快照的思路;其整段 class token 比对避免了裸 `[class*="_actions"]` 误命中其它行 | **0.48.1**(采纳该思路,扩到 `userAnchors` / `first` 标记 / 行内编辑 / MO 选择器) |
|
|
36
|
+
| [@M1ch1bata](https://github.com/M1ch1bata) | PR [#6](https://github.com/240xu/dsh-message-ops/pull/6):换哈希后按钮重复注入 | 提出「先复用自家行再按后缀找官方行」,以及 **`apply` 幂等**的防护 | 0.48.1(自建行改为单点创建);其 `apply` 幂等线索在 **0.48.2** 被验证为真问题并修掉(HMR 重新求值后新模块被布尔标记挡死、旧监听器残留) |
|
|
37
37
|
| [@Aqi77su](https://github.com/Aqi77su) | PR [#2](https://github.com/240xu/dsh-message-ops/pull/2):停止哈希变化导致的重复回滚按钮 | 同源定位 + 指出 MutationObserver 选择器也应改成 hash 无关 | 0.48.1(MO_SEL 已加 `[class*="_actions"]`) |
|
|
38
38
|
| [@ZhangLumian](https://github.com/ZhangLumian) | PR [#5](https://github.com/240xu/dsh-message-ops/pull/5):内部节点隐藏回滚/引用 | 指出 tool / thinking / system 节点不应有用户动作;给出按 `role`/`type` 收敛目标的写法 | 当前架构已不复现(按钮只注入用户消息块);其判据被记为未来扩展助手行操作的前置约束 |
|
|
39
39
|
| [@cinast](https://github.com/cinast) | Issue [#1](https://github.com/240xu/dsh-message-ops/issues/1):回滚按钮重复注入 | 首个完整定位:贴出 `div.mopsUserActionsRow` 增殖的 DOM 与「写死 `xzv4MW_actions`」根因 | 0.48.1 |
|
|
40
|
-
| [@allthewayeast](https://github.com/allthewayeast) | Issue [#7](https://github.com/240xu/dsh-message-ops/issues/7):悬停时动作按钮无限复制 | 指出 **mouseover 自触发回环**(插件插入 DOM → 又触发扫描)这一非显而易见的第二层原因 | 0.48.1
|
|
40
|
+
| [@allthewayeast](https://github.com/allthewayeast) | Issue [#7](https://github.com/240xu/dsh-message-ops/issues/7):悬停时动作按钮无限复制 | 指出 **mouseover 自触发回环**(插件插入 DOM → 又触发扫描)这一非显而易见的第二层原因 | 0.48.1(用例锁 20 次悬停 + 10 次滚动);0.48.2 量化确认插件自写入命中 `MO_SEL` 为 **0 条**(自触发 scan = 0) |
|
|
41
41
|
| [@allthewayeast](https://github.com/allthewayeast) | Issue [#8](https://github.com/240xu/dsh-message-ops/issues/8):上下文折叠被当成用户回滚 | 用 303 份日志 / 1664 条 replace 事件给出数据面证据,指出「任何 replace 都算 marker」的错误,并强调幻影行的「恢复」按钮是**会改数据**的入口 | 0.33.0(`looksLikeOwnMarker` 要求正向身份证据;dock 只渲染自有 marker) |
|
|
42
42
|
| [@SeekerDexter](https://github.com/SeekerDexter) | Issue [#10](https://github.com/240xu/dsh-message-ops/issues/10):0.24.0 在 0.2.2-rc.5 上「成排空白消息」 | 定量证据(5 条用户消息 → 440 个 28px 空行)+ **数据面反证**(10410 条消息无空节点)+ 源码级定位 | 0.48.1(并补真机验证:改名后按钮复用宿主行、自建行恒 0) |
|
|
43
43
|
| [@jiechhhhh](https://github.com/jiechhhhh) | Issue [#9](https://github.com/jiechhhhh):聊天中出现大量空白消息 | 逐插件排除法确认归属,并提供截图 | 0.48.1(同 #10 根因) |
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1284,10 +1284,31 @@ async function loadDerived(logPath) {
|
|
|
1284
1284
|
return entry.promise
|
|
1285
1285
|
}
|
|
1286
1286
|
|
|
1287
|
+
/**
|
|
1288
|
+
* 从**派生行**算「首条用户消息」标题(0.49.1,fs 去重)。
|
|
1289
|
+
*
|
|
1290
|
+
* 与 `session-trash.firstUserTitle` 同口径:跳过非 `user/message`、跳过注入行
|
|
1291
|
+
*(`sourceKind !== 'user'`)、跳过恢复重放副本,取 `fullText`(user 行必带)优先、
|
|
1292
|
+
* `snippet` 兜底,折叠空白后取前 40 字符。区别只是**不再读盘** —— opsList 手里
|
|
1293
|
+
* 已有全量派生,旧实现要为此再 `readFileSync` 整份日志(137MB 会话等于为取个标题
|
|
1294
|
+
* 再读 137MB)。
|
|
1295
|
+
* @param {Array} messages 派生消息行
|
|
1296
|
+
* @returns {string|null} 标题候选
|
|
1297
|
+
*/
|
|
1298
|
+
function firstUserTitleFromRows(messages) {
|
|
1299
|
+
for (const m of Array.isArray(messages) ? messages : []) {
|
|
1300
|
+
if (!m || m.type !== 'user/message' || m.sourceKind !== 'user' || m.replayed === true) continue
|
|
1301
|
+
const text = typeof m.fullText === 'string' && m.fullText.trim() ? m.fullText : m.snippet
|
|
1302
|
+
const clean = String(text || '').replace(/\s+/g, ' ').trim()
|
|
1303
|
+
if (clean) return clean.slice(0, 40)
|
|
1304
|
+
}
|
|
1305
|
+
return null
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1287
1308
|
async function opsList(targetCtx, sessionId, opts = {}) {
|
|
1288
1309
|
if (!isSessionId(sessionId)) throw new OpsError('invalid sessionId', 400)
|
|
1289
1310
|
const compact = opts && opts.compact === true
|
|
1290
|
-
const { logPath } = pickSessionDir(sessionId)
|
|
1311
|
+
const { dir, logPath } = pickSessionDir(sessionId)
|
|
1291
1312
|
// 文件派生段(读日志 → 消息 → 遮蔽集 → marker 进度 → turn 边界)走缓存:
|
|
1292
1313
|
// key = logPath、失效看读前 stat 的 mtimeMs+size,见 loadDerived 注释。
|
|
1293
1314
|
const { derived, live, derivedFrom } = await derivedAndLive(targetCtx, sessionId, logPath)
|
|
@@ -1374,7 +1395,13 @@ async function opsList(targetCtx, sessionId, opts = {}) {
|
|
|
1374
1395
|
id: header.id,
|
|
1375
1396
|
createdAt: header.createdAt,
|
|
1376
1397
|
parentSession: header.parentSession ?? null,
|
|
1377
|
-
confirmTitle:
|
|
1398
|
+
confirmTitle:
|
|
1399
|
+
resolveSessionTitle(targetCtx, sessionId, {
|
|
1400
|
+
eventTitle: derived.sessionTitle,
|
|
1401
|
+
dir,
|
|
1402
|
+
logPath,
|
|
1403
|
+
firstUserTitle: firstUserTitleFromRows(derived.messages),
|
|
1404
|
+
}) || header.id,
|
|
1378
1405
|
},
|
|
1379
1406
|
running: isRunning(targetCtx, sessionId),
|
|
1380
1407
|
runningSource: __runningSource,
|
package/src/session-file.js
CHANGED
|
@@ -641,10 +641,41 @@ const yieldToLoop = () => new Promise(resolve => setImmediate(resolve))
|
|
|
641
641
|
* @returns {{header: object|null, events: object[], framesRead: number, truncated: boolean}}
|
|
642
642
|
* events 只含已解压帧里的事件(可能不完整,调用方不得据此算遮蔽/计数)
|
|
643
643
|
*/
|
|
644
|
-
export function readSessionPrefix(file, { maxFrames = 16 } = {}) {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
644
|
+
export function readSessionPrefix(file, { maxFrames = 16, initialBytes = 1 << 20 } = {}) {
|
|
645
|
+
// 0.49.1(内存/IO):旧实现 `readFileSync(整文件)` —— 137MB 会话为了取个标题要读
|
|
646
|
+
// 137MB + 全量帧扫描。现在按需倍增读:先读 1MB,够 maxFrames 帧就停;不够再翻倍,
|
|
647
|
+
// 直到够或读完整文件。最坏总读量 < 2× 文件大小(几何级数),常见会话只读 1MB。
|
|
648
|
+
const st = fs.statSync(file)
|
|
649
|
+
let limit = Math.min(st.size, Math.max(64 * 1024, initialBytes))
|
|
650
|
+
let buf
|
|
651
|
+
let frames = []
|
|
652
|
+
let torn = false
|
|
653
|
+
for (;;) {
|
|
654
|
+
// `readFileSync` 没有长度参数:只读前缀时用 open+read,避免把整文件读进内存。
|
|
655
|
+
if (limit >= st.size) {
|
|
656
|
+
buf = fs.readFileSync(file)
|
|
657
|
+
} else {
|
|
658
|
+
const fd = fs.openSync(file, 'r')
|
|
659
|
+
try {
|
|
660
|
+
const head = Buffer.allocUnsafe(limit)
|
|
661
|
+
const n = fs.readSync(fd, head, 0, limit, 0)
|
|
662
|
+
buf = n === limit ? head : head.subarray(0, n)
|
|
663
|
+
} finally {
|
|
664
|
+
fs.closeSync(fd)
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
const scanned = scanZstdFrames(buf)
|
|
668
|
+
frames = scanned.frames
|
|
669
|
+
torn = scanned.tornStart !== undefined && limit < st.size
|
|
670
|
+
if (frames.length === 0) throw new Error('empty or header-less session log')
|
|
671
|
+
// 部分读时最后一帧可能不完整:丢弃它,再判断是否够用。
|
|
672
|
+
const usable = torn ? frames.slice(0, -1) : frames
|
|
673
|
+
if (usable.length >= maxFrames || limit >= st.size) {
|
|
674
|
+
frames = usable
|
|
675
|
+
break
|
|
676
|
+
}
|
|
677
|
+
limit = Math.min(st.size, limit * 2)
|
|
678
|
+
}
|
|
648
679
|
const events = []
|
|
649
680
|
let header = null
|
|
650
681
|
let framesRead = 0
|
package/src/session-trash.js
CHANGED
|
@@ -109,9 +109,11 @@ function titleOfRow(row) {
|
|
|
109
109
|
return null
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
function headerTitle(dir) {
|
|
112
|
+
function headerTitle(dir, logPath) {
|
|
113
113
|
try {
|
|
114
|
-
|
|
114
|
+
// 0.49.1:已知日志路径时不再读目录探测文件名(opsList 刚扫过一遍)。
|
|
115
|
+
const file = logPath || path.join(dir, fs.readdirSync(dir).find(f => /^session(\.v[34])?\.jsonl\.zstd$/.test(f)) || '')
|
|
116
|
+
const header = readSessionHeader(file)
|
|
115
117
|
for (const key of ['title', 'name', 'displayTitle']) {
|
|
116
118
|
if (header && typeof header[key] === 'string' && header[key].trim()) return header[key].trim()
|
|
117
119
|
}
|
|
@@ -137,13 +139,16 @@ function headerTitle(dir) {
|
|
|
137
139
|
* @param {string} dir 会话目录
|
|
138
140
|
* @returns {string|null} 40 字以内的标题,读不到返回 null
|
|
139
141
|
*/
|
|
140
|
-
function firstUserTitle(dir) {
|
|
142
|
+
function firstUserTitle(dir, logPath) {
|
|
141
143
|
try {
|
|
142
|
-
const name =
|
|
144
|
+
const name = logPath || (() => {
|
|
145
|
+
const found = fs.readdirSync(dir).find(f => /^session(\.v[34])?\.jsonl\.zstd$/.test(f))
|
|
146
|
+
return found ? path.join(dir, found) : null
|
|
147
|
+
})()
|
|
143
148
|
if (!name) return null
|
|
144
149
|
// 0.39.2:只读前缀(逐帧解压、命中即停)—— 全量读 131MB 会话要 +15–35s,
|
|
145
150
|
// 而这个兜底只发生在「未打开过、也没有投影标题」的会话里。
|
|
146
|
-
const { events } = readSessionPrefix(
|
|
151
|
+
const { events } = readSessionPrefix(name)
|
|
147
152
|
for (const m of listMessages(events)) {
|
|
148
153
|
if (m.type !== 'user/message' || m.sourceKind !== 'user' || m.replayed === true) continue
|
|
149
154
|
const text = typeof m.fullText === 'string' && m.fullText.trim() ? m.fullText : m.snippet
|
|
@@ -157,21 +162,43 @@ function firstUserTitle(dir) {
|
|
|
157
162
|
return null
|
|
158
163
|
}
|
|
159
164
|
|
|
165
|
+
/**
|
|
166
|
+
* 解析会话标题:投影行 → header 显式标题 → `session/title` 事件 → 首条用户消息。
|
|
167
|
+
*
|
|
168
|
+
* 0.49.1(fs 去重):`/messages` 调用方已经拿到日志目录/路径与**完整事件派生**
|
|
169
|
+
* (`opsList` 刚读完日志)。旧实现让本函数自己再扫两遍 sessions 根目录、再读一次
|
|
170
|
+
* 完整日志(`firstUserTitle` 的 `readSessionPrefix` 是 `readFileSync(整文件)` ——
|
|
171
|
+
* 137MB 会话等于为「取个标题」再读 137MB)。现在调用方可传:
|
|
172
|
+
* - `dir` / `logPath`:跳过 `findAllSessionDirs` 与目录内文件名探测;
|
|
173
|
+
* - `firstUserTitle`:由派生行直接算出的首条用户消息标题,跳过读盘兜底。
|
|
174
|
+
* 三者缺省时行为与旧实现完全一致(trash 列表等只看磁盘的调用方不受影响)。
|
|
175
|
+
*
|
|
176
|
+
* @param {object} ctx 插件上下文(取投影表)
|
|
177
|
+
* @param {string} sessionId 会话 id
|
|
178
|
+
* @param {{eventTitle?:string|null, dir?:string, logPath?:string, firstUserTitle?:string|null}} [options]
|
|
179
|
+
* eventTitle 事件流折叠出的标题;dir/logPath 已知的日志位置;firstUserTitle 已算好的兜底标题
|
|
180
|
+
* @returns {string|null} 标题(都拿不到时返回 sessionId)
|
|
181
|
+
*/
|
|
160
182
|
export function resolveSessionTitle(ctx, sessionId, options = {}) {
|
|
161
183
|
if (!isSessionId(sessionId)) return null
|
|
162
184
|
const meta = readMetadata(ctx, sessionId)
|
|
163
185
|
const title = titleOfRow(meta.projRow)
|
|
164
186
|
if (title) return title
|
|
165
|
-
|
|
187
|
+
// 已知目录时不再二次扫描(`opsList` 的 `pickSessionDir` 刚扫过一遍)。
|
|
188
|
+
const dirs = typeof options.dir === 'string' && options.dir ? [{ dir: options.dir }] : findAllSessionDirs(sessionId)
|
|
166
189
|
if (dirs.length === 1) {
|
|
167
|
-
const fromHeader = headerTitle(dirs[0].dir)
|
|
190
|
+
const fromHeader = headerTitle(dirs[0].dir, options.logPath)
|
|
168
191
|
if (fromHeader) return fromHeader
|
|
169
192
|
// 0.43.0(srv-audit D24):调用方若已从事件流折叠出 `session/title`(宿主同源),
|
|
170
193
|
// 它优先于「首条用户消息」启发式 —— 标题应与侧栏一致。
|
|
171
194
|
const fromEvents = typeof options.eventTitle === 'string' && options.eventTitle.trim() ? options.eventTitle.trim() : null
|
|
172
195
|
if (fromEvents) return fromEvents
|
|
173
196
|
// 0.37.5:未打开过的会话没有投影行/标题,退回首条用户消息(同宿主语义)
|
|
174
|
-
|
|
197
|
+
// 0.49.1:调用方已从派生行算出时直接用它,避免为取标题重读整份日志。
|
|
198
|
+
const fromFirst =
|
|
199
|
+
typeof options.firstUserTitle === 'string' && options.firstUserTitle.trim()
|
|
200
|
+
? options.firstUserTitle.trim()
|
|
201
|
+
: firstUserTitle(dirs[0].dir, options.logPath)
|
|
175
202
|
if (fromFirst) return fromFirst
|
|
176
203
|
}
|
|
177
204
|
return sessionId
|