dsh-as-aistudio 0.5.17 → 0.5.18

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
@@ -4,6 +4,8 @@
4
4
 
5
5
  ## 中文
6
6
 
7
+ **0.5.18** —— 跟进 dsh-log-trim 0.7.5(裁掉被检查点遮蔽的前缀,窗口数真的降下来)。
8
+
7
9
  **0.5.17** —— 跟进 dsh-log-trim 0.7.4(启动立即扫描、最近日志优先、解锁后补裁)。
8
10
 
9
11
  **0.5.16** —— 跟进 dsh-log-trim 0.7.3(迟到 tool/result 归位,窗口裁剪不再被校验挡住)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-as-aistudio",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "Google-AI-Studio-style turn controls for DeepSeek Harness, in one install: edit a prompt and re-run it, re-run a reply in place, delete a turn from the model context, render sent prompts as Markdown, and trim idle session logs on boot. Self-contained: the plugin list shows this one row, and the five components (four actions + one maintenance) are vendored inside it - installing the studio installs nothing else.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/client.js CHANGED
@@ -9642,7 +9642,7 @@ window.__ModuleLoader__.load({
9642
9642
  const react = require('react')
9643
9643
  const { jsx, jsxs } = require('react/jsx-runtime')
9644
9644
 
9645
- const PLUGIN_VERSION = '0.7.4'
9645
+ const PLUGIN_VERSION = '0.7.5'
9646
9646
  const ROUTE_PREFIX = '/api/dsh-log-trim'
9647
9647
 
9648
9648
  /** The knobs this card edits, in the order they are drawn. */
@@ -10168,7 +10168,7 @@ window.__ModuleLoader__.load({
10168
10168
  const NS = 'dsh-as-aistudio'
10169
10169
 
10170
10170
  /** Keep in sync with package.json and src/components.js. */
10171
- const PLUGIN_VERSION = '0.5.17'
10171
+ const PLUGIN_VERSION = '0.5.18'
10172
10172
 
10173
10173
  /** Presence marker the live verifier reads. */
10174
10174
  const DEBUG_KEY = '__DSH_AS_AISTUDIO__'
package/src/components.js CHANGED
@@ -26,7 +26,7 @@
26
26
  export const STUDIO_ID = 'dsh-as-aistudio'
27
27
 
28
28
  /** Keep in sync with package.json and src/client.js. */
29
- export const STUDIO_VERSION = '0.5.17'
29
+ export const STUDIO_VERSION = '0.5.18'
30
30
 
31
31
  /**
32
32
  * The AI Studio action strip this studio composes, in the order the user meets
@@ -1,6 +1,6 @@
1
1
  // dsh-edit-turn host half (dsh-edit-turn.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-edit-turn/lib/index.js (v0.5.20, sha256 2e006e68f0591665)
3
+ // Source: ../dsh-edit-turn/lib/index.js (v0.5.21, sha256 1502010fdd847526)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -85,7 +85,7 @@ export const PLUGIN_ID = 'dsh-edit-turn'
85
85
  export const name = PLUGIN_ID
86
86
 
87
87
  /** Keep in sync with package.json and lib/client.js. */
88
- export const PLUGIN_VERSION = '0.5.20'
88
+ export const PLUGIN_VERSION = '0.5.21'
89
89
 
90
90
  // A ring of the last few requests, answering "did the browser half even ask, and
91
91
  // what did it get?" without needing its console. Read-only diagnostics: the
@@ -1,6 +1,6 @@
1
1
  // dsh-edit-turn host half (dsh-edit-turn.patch.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-edit-turn/lib/patch.js (v0.5.20, sha256 5e1e8cce1d168f6c)
3
+ // Source: ../dsh-edit-turn/lib/patch.js (v0.5.21, sha256 5e1e8cce1d168f6c)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.flatten.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/flatten.js (v0.7.4, sha256 3aa1fdcbb120ab06)
3
+ // Source: ../dsh-log-trim/lib/flatten.js (v0.7.5, sha256 3aa1fdcbb120ab06)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.goal-repair.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/goal-repair.js (v0.7.4, sha256 0801a28f35667ee7)
3
+ // Source: ../dsh-log-trim/lib/goal-repair.js (v0.7.5, sha256 0801a28f35667ee7)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.host-libs.mjs), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/host-libs.mjs (v0.7.4, sha256 5ebed01988b5bfcf)
3
+ // Source: ../dsh-log-trim/lib/host-libs.mjs (v0.7.5, sha256 5ebed01988b5bfcf)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/index.js (v0.7.4, sha256 3073f59d273e8507)
3
+ // Source: ../dsh-log-trim/lib/index.js (v0.7.5, sha256 a32940b526c93896)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -44,7 +44,7 @@ import { readLedger, recordFor } from './dsh-log-trim.ledger.js'
44
44
 
45
45
  export const name = 'dsh-log-trim'
46
46
  export const PLUGIN_ID = name
47
- export const PLUGIN_VERSION = '0.7.4'
47
+ export const PLUGIN_VERSION = '0.7.5'
48
48
  export const ROUTE_PREFIX = '/api/dsh-log-trim'
49
49
 
50
50
  /**
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.ledger.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/ledger.js (v0.7.4, sha256 5ca2460b42a3a776)
3
+ // Source: ../dsh-log-trim/lib/ledger.js (v0.7.5, sha256 5ca2460b42a3a776)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.lossless.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/lossless.js (v0.7.4, sha256 7e8478a2fd2ec10b)
3
+ // Source: ../dsh-log-trim/lib/lossless.js (v0.7.5, sha256 7e8478a2fd2ec10b)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.roots.js), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/roots.js (v0.7.4, sha256 028d9c12a395aaab)
3
+ // Source: ../dsh-log-trim/lib/roots.js (v0.7.5, sha256 028d9c12a395aaab)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.vendor.compact-session.mjs), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/vendor.compact-session.mjs (v0.7.4, sha256 1b0499e0c4c11122)
3
+ // Source: ../dsh-log-trim/lib/vendor.compact-session.mjs (v0.7.5, sha256 f0c5dcc018253ea4)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -2142,17 +2142,70 @@ export function repairLateToolResults(events) {
2142
2142
  return { events: list, moved, dropped }
2143
2143
  }
2144
2144
 
2145
+
2146
+ /**
2147
+ * 被 checkpoint 的 `replace` 区间盖住的前缀:模型与界面都看不到,留着只是占空间,
2148
+ * 窗口页还会把它算成一窗。
2149
+ *
2150
+ * 不逐行删(会切坏 step/turn 括号),而是把保留区改成「连续尾巴 + frame」:
2151
+ * 从最后一个存活 checkpoint 的 replace 末尾之后、对齐到轮次起点开始保留,
2152
+ * 再加系统提示词与设置事件。这样结构始终是自洽的。
2153
+ *
2154
+ * @param {object[]} events - 候选保留事件(keepLastWindows 的结果)。
2155
+ * @returns {{ events: object[], dropped: number }} 结果。
2156
+ */
2157
+ function dropShadowedPrefix(events) {
2158
+ const checkpoints = events.filter((event) => event.type === 'user/message' && event.data?.source?.kind === 'compact-checkpoint')
2159
+ const last = checkpoints[checkpoints.length - 1]
2160
+ const shadowEnd = last !== undefined && typeof last.surfaceOp?.endSeq === 'number' ? last.surfaceOp.endSeq : null
2161
+ if (shadowEnd === null) return { events, dropped: 0 }
2162
+ const aligned = events.find((event) => event.seq > shadowEnd && event.type === 'turn/start')
2163
+ if (aligned === undefined) return { events, dropped: 0 }
2164
+ const liveStart = aligned.seq
2165
+ const frame = new Set()
2166
+ const visible = foldSurface(events).visible
2167
+ const system = visible.map((seq) => events.find((event) => event.seq === seq)).find((event) => event !== undefined && (event.type === 'system/message' || event.type === 'developer/message'))
2168
+ if (system !== undefined) frame.add(system.seq)
2169
+ for (const type of ['agent-preset/selected', 'permission/preset', 'sandbox/mode', 'approval/policy', 'session/title', 'session/end-seed']) {
2170
+ const hit = events.filter((event) => event.type === type && event.seq < liveStart).pop()
2171
+ if (hit !== undefined) frame.add(hit.seq)
2172
+ }
2173
+ // 结构性事件不受“前缀”限制:compaction 组、seeded 标记、inbox 拼接都是按顺序
2174
+ // 重放的记账,丢掉半组会让整份日志装不上;它们不占模型视图,留着也便宜。
2175
+ const structural = (event) =>
2176
+ String(event.type).startsWith('compaction/') ||
2177
+ String(event.type).startsWith('session/') ||
2178
+ event.type === 'agent/inbox/spliced'
2179
+ const out = events.filter((event) => event.seq >= liveStart || frame.has(event.seq) || structural(event))
2180
+ // compaction 是一组(start / summary / end 同一个 compactionId):end 落在尾巴里而
2181
+ // start/summary 落在被丢的前缀里时,宿主要求「成功的 compaction/end 必须有一条 summary」。
2182
+ // 只要有同组的行留下,就把整组补回来(都是记账行,不影响模型视图)。
2183
+ const compactionIds = new Set()
2184
+ for (const event of out) {
2185
+ if (typeof event.data?.compactionId === 'string') compactionIds.add(event.data.compactionId)
2186
+ }
2187
+ if (compactionIds.size > 0) {
2188
+ for (const event of events) {
2189
+ if (typeof event.data?.compactionId === 'string' && compactionIds.has(event.data.compactionId) && !out.includes(event)) out.push(event)
2190
+ }
2191
+ out.sort((left, right) => left.seq - right.seq)
2192
+ }
2193
+ return { events: out, dropped: events.length - out.length }
2194
+ }
2195
+
2145
2196
  export async function stageTrim(logFile, keep, options = {}) {
2146
2197
  if (isSessionLocked(logFile)) {
2147
2198
  throw new Error('会话正被宿主持有(session.lock 被打开),拒绝改动;请先关掉该会话或重启宿主')
2148
2199
  }
2149
2200
  const original = await readLogAsync(logFile)
2150
2201
  const trimmed = keepLastWindows(original.events, keep)
2151
- if (trimmed.cutSeq === null) throw new Error(`只有 ${trimmed.windows} 个窗口,不需要裁`)
2152
2202
  // 旧回合的流式回放记录:与 data.message.content 逐块重复,留最近几轮就够。
2153
2203
  const streamKeepTurns = options.streamKeepTurns === undefined ? Infinity : options.streamKeepTurns
2154
- const stripped = stripOldStreams(trimmed.events, streamKeepTurns)
2204
+ // 先丢掉被 checkpoint 遮蔽的前缀(连续尾巴 + frame),再清流式回放。
2205
+ const shadowed = options.shadowPrefix === false ? { events: trimmed.events, dropped: 0 } : dropShadowedPrefix(trimmed.events)
2206
+ const stripped = stripOldStreams(shadowed.events, streamKeepTurns)
2155
2207
  assertNoGoalEventsDropped(original.events, stripped.events)
2208
+ if (trimmed.cutSeq === null && shadowed.dropped === 0) throw new Error(`只有 ${trimmed.windows} 个窗口,不需要裁`)
2156
2209
  let renamed = renumber(stripped.events)
2157
2210
  const repaired = repairLateToolResults(renamed.events)
2158
2211
  if (repaired.moved > 0 || repaired.dropped > 0) {
@@ -2186,7 +2239,7 @@ export async function stageTrim(logFile, keep, options = {}) {
2186
2239
  backup,
2187
2240
  before: { events: original.events.length, bytes: original.compressedBytes, windows: trimmed.windows },
2188
2241
  after: { events: renamed.events.length, bytes: (await fs.promises.stat(staging)).size },
2189
- dropped: trimmed.dropped,
2242
+ dropped: trimmed.dropped + shadowed.dropped,
2190
2243
  refsFixed: renamed.refsFixed,
2191
2244
  titlesDropped: renamed.titlesDropped,
2192
2245
  compactionDropped: renamed.compactionDropped,
@@ -2224,7 +2277,7 @@ export async function commitTrim(staged, logFile) {
2224
2277
  * @returns {Promise<object>} 结果摘要。
2225
2278
  */
2226
2279
  export async function applyTrim(logFile, keep, options = {}) {
2227
- const staged = await stageTrim(logFile, keep, options)
2280
+ let staged = await stageTrim(logFile, keep, options)
2228
2281
  if (options.verify !== false) {
2229
2282
  let result
2230
2283
  try {
@@ -2236,6 +2289,20 @@ export async function applyTrim(logFile, keep, options = {}) {
2236
2289
  }
2237
2290
  if (!result.ok) {
2238
2291
  fs.rmSync(staged.staging, { force: true })
2292
+ // 丢掉「被 checkpoint 遮蔽的前缀」是收益、不是前提:这份日志上它可能撞到
2293
+ // compaction / 标题 / inbox 的结构约束。退回不丢前缀的老做法再验一次,
2294
+ // 两次都不过才真的失败。
2295
+ if (options.shadowPrefix !== false) {
2296
+ staged = await stageTrim(logFile, keep, { ...options, shadowPrefix: false })
2297
+ const retried = await (async () => {
2298
+ const { verifyLog } = await import('./dsh-log-trim.verify-session-log.mjs')
2299
+ return verifyLog(staged.staging)
2300
+ })()
2301
+ if (retried.ok) return commitTrim(staged, logFile)
2302
+ fs.rmSync(staged.staging, { force: true })
2303
+ const bad = retried.checks.filter((check) => !check.ok).map((check) => `${check.name} ${check.detail}`).join(';')
2304
+ throw new Error(`裁剪结果没通过宿主校验,未写入:${bad}`)
2305
+ }
2239
2306
  const bad = result.checks.filter((check) => !check.ok).map((check) => `${check.name} ${check.detail}`).join(';')
2240
2307
  throw new Error(`裁剪结果没通过宿主校验,未写入:${bad}`)
2241
2308
  }
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.verify-session-log.mjs), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/verify-session-log.mjs (v0.7.4, sha256 7cf835c053942961)
3
+ // Source: ../dsh-log-trim/lib/verify-session-log.mjs (v0.7.5, sha256 7cf835c053942961)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,6 +1,6 @@
1
1
  // dsh-log-trim host half (dsh-log-trim.worker.mjs), VENDORED by tools/vendor.mjs - DO NOT EDIT.
2
2
  //
3
- // Source: ../dsh-log-trim/lib/worker.mjs (v0.7.4, sha256 675a759a767b7e38)
3
+ // Source: ../dsh-log-trim/lib/worker.mjs (v0.7.5, sha256 675a759a767b7e38)
4
4
  // Regenerate with `npm run vendor`; test/sync.test.js fails when this is stale.
5
5
  //
6
6
  // src/shell.js imports the copy named after the component, which is why the
@@ -1,7 +1,7 @@
1
1
  {
2
- "dsh-edit-turn": "0.5.20",
2
+ "dsh-edit-turn": "0.5.21",
3
3
  "dsh-rerun-turn": "0.2.11",
4
4
  "dsh-delete-turn": "0.2.4",
5
5
  "dsh-markdown-bubble": "0.1.5",
6
- "dsh-log-trim": "0.7.4"
6
+ "dsh-log-trim": "0.7.5"
7
7
  }