@copylee/dsh-computer-use 0.15.0 → 0.16.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/helper/Input.cs CHANGED
@@ -230,19 +230,17 @@ namespace DshComputerUse
230
230
  int x1 = Args.Int(r, "x1", 0), y1 = Args.Int(r, "y1", 0), x2 = Args.Int(r, "x2", 0), y2 = Args.Int(r, "y2", 0);
231
231
  uint down, up; Flags(Args.Str(r, "button", "left"), out down, out up);
232
232
  Overlay.Dodge(x1, y1); Overlay.Dodge(x2, y2);
233
- Move(x1, y1);
234
233
  if (Overlay.ShowClickTarget) Overlay.MarkPointer(x1, y1, "拖动", 1200);
234
+ Move(x1, y1);
235
235
  Thread.Sleep(40);
236
236
  Send(new List<Native.INPUT> { Mouse(down, 0) });
237
237
  try
238
238
  {
239
239
  Thread.Sleep(60);
240
- int steps = Math.Max(8, Math.Min(40, (int)(Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 20)));
241
- for (int i = 1; i <= steps; i++)
242
- {
243
- Move(x1 + (x2 - x1) * i / steps, y1 + (y2 - y1) * i / steps);
244
- Thread.Sleep(12);
245
- }
240
+ double dist = Math.Sqrt((double)(x2 - x1) * (x2 - x1) + (double)(y2 - y1) * (y2 - y1));
241
+ // Frame-paced, eased path; every step is a real move so the app sees the drag.
242
+ Overlay.AnimatePointer(x1, y1, x2, y2, Math.Max(240.0, Overlay.GlideDurationMs(dist) * 1.4), delegate(int ix, int iy) { Move(ix, iy); });
243
+ Move(x2, y2);
246
244
  Thread.Sleep(60);
247
245
  }
248
246
  finally { Send(new List<Native.INPUT> { Mouse(up, 0) }); }
@@ -254,9 +252,18 @@ namespace DshComputerUse
254
252
  {
255
253
  int sx = 0, sy = 0;
256
254
  bool hasPos = Args.Has(r, "x");
257
- if (hasPos) { sx = Args.Int(r, "x", 0); sy = Args.Int(r, "y", 0); Overlay.Dodge(sx, sy); Move(sx, sy); Thread.Sleep(30); }
258
- else { Native.POINT p; if (Native.GetCursorPos(out p)) { sx = p.X; sy = p.Y; } }
259
- if (Overlay.ShowClickTarget) Overlay.MarkPointer(sx, sy, "滚动", 900);
255
+ if (hasPos)
256
+ {
257
+ sx = Args.Int(r, "x", 0); sy = Args.Int(r, "y", 0); Overlay.Dodge(sx, sy);
258
+ // Glide first (the badge travels with the pointer), then the real move apps react to.
259
+ if (Overlay.ShowClickTarget) Overlay.MarkPointer(sx, sy, "滚动", 900);
260
+ Move(sx, sy); Thread.Sleep(30);
261
+ }
262
+ else
263
+ {
264
+ Native.POINT p; if (Native.GetCursorPos(out p)) { sx = p.X; sy = p.Y; }
265
+ if (Overlay.ShowClickTarget) Overlay.MarkPointer(sx, sy, "滚动", 900);
266
+ }
260
267
  int dx = Args.Int(r, "dx", 0), dy = Args.Int(r, "dy", 0);
261
268
  var mods = Args.Ints(r, "modifiers");
262
269
  Modifiers(mods, false);
package/helper/Native.cs CHANGED
@@ -53,6 +53,8 @@ namespace DshComputerUse
53
53
  [DllImport("user32.dll", SetLastError = true)] public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, out bool pvParam, uint fWinIni);
54
54
  [DllImport("winmm.dll")] public static extern uint timeBeginPeriod(uint uPeriod);
55
55
  [DllImport("winmm.dll")] public static extern uint timeEndPeriod(uint uPeriod);
56
+ /** Blocks until the next DWM composition (vblank-locked frame pacing). */
57
+ [DllImport("dwmapi.dll")] public static extern int DwmFlush();
56
58
  [StructLayout(LayoutKind.Sequential)]
57
59
  public struct BITMAPINFOHEADER { public uint biSize; public int biWidth; public int biHeight; public ushort biPlanes; public ushort biBitCount; public uint biCompression; public uint biSizeImage; public int biXPelsPerMeter; public int biYPelsPerMeter; public uint biClrUsed; public uint biClrImportant; }
58
60
  [DllImport("gdi32.dll")] public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFOHEADER pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
package/helper/Overlay.cs CHANGED
@@ -1111,7 +1111,12 @@ namespace DshComputerUse
1111
1111
  PlaceMarkOnUi(latestMouseX, latestMouseY, cursorBadge, Accent, 0, false, false, true);
1112
1112
  }
1113
1113
 
1114
- /** Smooth true-120Hz EaseOutCubic glide (~140ms) moving OS cursor and cached DSH badge in lockstep. */
1114
+ /**
1115
+ * Glide the OS cursor and the DSH badge to (x, y) together. Frames are
1116
+ * locked to the display's refresh (DwmFlush), positions follow a
1117
+ * minimum-jerk curve sampled from a stopwatch, and the duration grows
1118
+ * with the distance, so the pointer moves like a hand, not in steps.
1119
+ */
1115
1120
  public static void GlideMark(int x, int y, string text, Color color, int holdMs, bool capturable, bool ripple)
1116
1121
  {
1117
1122
  int startX, startY;
@@ -1119,35 +1124,68 @@ namespace DshComputerUse
1119
1124
  if (Native.GetCursorPos(out cur)) { startX = cur.X; startY = cur.Y; }
1120
1125
  else if (hasLastMark) { startX = lastMarkX; startY = lastMarkY; }
1121
1126
  else { startX = x; startY = y; }
1122
- double dist = Math.Sqrt((double)(x - startX) * (x - startX) + (double)(y - startY) * (y - startY));
1123
- if (dist >= 24.0)
1127
+ AnimatePointer(startX, startY, x, y, 0, delegate(int ix, int iy)
1124
1128
  {
1125
- double durationMs = Math.Max(95.0, Math.Min(190.0, 85.0 + dist * 0.085));
1126
- bool highRes = false;
1127
- try
1129
+ try { Native.SetCursorPos(ix, iy); } catch (Exception) { }
1130
+ Mark(ix, iy, text, color, holdMs, false, false);
1131
+ });
1132
+ try { Native.SetCursorPos(x, y); } catch (Exception) { }
1133
+ Mark(x, y, text, color, holdMs, false, false);
1134
+ }
1135
+
1136
+ /** Glide duration for a move of `dist` pixels: short hops stay quick, long sweeps stay readable. */
1137
+ public static double GlideDurationMs(double dist)
1138
+ {
1139
+ return Math.Max(150.0, Math.Min(420.0, 110.0 + Math.Sqrt(dist) * 9.5));
1140
+ }
1141
+
1142
+ /** Minimum-jerk position profile (10t^3 - 15t^4 + 6t^5): zero velocity and acceleration at both ends. */
1143
+ public static double MinimumJerk(double t)
1144
+ {
1145
+ if (t <= 0) return 0;
1146
+ if (t >= 1) return 1;
1147
+ return t * t * t * (10.0 + t * (-15.0 + 6.0 * t));
1148
+ }
1149
+
1150
+ /**
1151
+ * Drive `step` once per displayed frame from (x0, y0) to (x1, y1), stopping
1152
+ * just before the end (callers place the final point themselves).
1153
+ * durationMs <= 0 picks GlideDurationMs. Moves under 10 px are not animated.
1154
+ */
1155
+ public static void AnimatePointer(int x0, int y0, int x1, int y1, double durationMs, Action<int, int> step)
1156
+ {
1157
+ double dist = Math.Sqrt((double)(x1 - x0) * (x1 - x0) + (double)(y1 - y0) * (y1 - y0));
1158
+ if (dist < 10.0) return;
1159
+ if (durationMs <= 0) durationMs = GlideDurationMs(dist);
1160
+ bool highRes = false;
1161
+ bool vsync = true;
1162
+ int lastX = x0, lastY = y0;
1163
+ try
1164
+ {
1165
+ highRes = Native.timeBeginPeriod(1) == 0;
1166
+ var sw = Stopwatch.StartNew();
1167
+ while (true)
1128
1168
  {
1129
- highRes = Native.timeBeginPeriod(1) == 0;
1130
- var sw = Stopwatch.StartNew();
1131
- while (true)
1169
+ // Wait for the next composed frame first, then place the pointer for that frame's time.
1170
+ if (vsync)
1132
1171
  {
1133
- double elapsed = sw.Elapsed.TotalMilliseconds;
1134
- if (elapsed >= durationMs) break;
1135
- double t = elapsed / durationMs;
1136
- double ease = 1.0 - Math.Pow(1.0 - t, 3.0); // EaseOutCubic
1137
- int ix = startX + (int)Math.Round((x - startX) * ease);
1138
- int iy = startY + (int)Math.Round((y - startY) * ease);
1139
- try { Native.SetCursorPos(ix, iy); } catch (Exception) { }
1140
- Mark(ix, iy, text, color, holdMs, false, false);
1141
- Thread.Sleep(7);
1172
+ try { vsync = Native.DwmFlush() == 0; } catch (Exception) { vsync = false; }
1142
1173
  }
1143
- }
1144
- finally
1145
- {
1146
- if (highRes) { try { Native.timeEndPeriod(1); } catch (Exception) { } }
1174
+ if (!vsync) Thread.Sleep(4);
1175
+ double elapsed = sw.Elapsed.TotalMilliseconds;
1176
+ if (elapsed >= durationMs) break;
1177
+ double e = MinimumJerk(elapsed / durationMs);
1178
+ int ix = x0 + (int)Math.Round((x1 - x0) * e);
1179
+ int iy = y0 + (int)Math.Round((y1 - y0) * e);
1180
+ if (ix == lastX && iy == lastY) continue;
1181
+ lastX = ix; lastY = iy;
1182
+ step(ix, iy);
1147
1183
  }
1148
1184
  }
1149
- try { Native.SetCursorPos(x, y); } catch (Exception) { }
1150
- Mark(x, y, text, color, holdMs, false, false);
1185
+ finally
1186
+ {
1187
+ if (highRes) { try { Native.timeEndPeriod(1); } catch (Exception) { } }
1188
+ }
1151
1189
  }
1152
1190
 
1153
1191
  static void ShowRestingMarkOnUi(int x, int y)
package/helper/Program.cs CHANGED
@@ -179,8 +179,8 @@ namespace DshComputerUse
179
179
  {
180
180
  int mx = Args.Int(r, "x", 0), my = Args.Int(r, "y", 0);
181
181
  Overlay.Dodge(mx, my);
182
- Input.Move(mx, my);
183
182
  if (Overlay.ShowClickTarget) Overlay.MarkPointer(mx, my, "DSH", 900);
183
+ Input.Move(mx, my);
184
184
  }
185
185
  return null;
186
186
  case "click":
package/lib/client.js CHANGED
@@ -80,6 +80,7 @@ window.__ModuleLoader__.load({
80
80
  maxLongEdge: 1366,
81
81
  maxPixels: 115e4,
82
82
  jpegQuality: 70,
83
+ keepScreenshots: 2,
83
84
  blockedApps: [],
84
85
  pauseOnUserInput: true,
85
86
  reportUserActions: true,
@@ -122,6 +123,7 @@ window.__ModuleLoader__.load({
122
123
  maxLongEdge: num("maxLongEdge", 640, 3840),
123
124
  maxPixels: num("maxPixels", 3e5, 8e6),
124
125
  jpegQuality: num("jpegQuality", 30, 100),
126
+ keepScreenshots: num("keepScreenshots", 0, 20),
125
127
  pauseOnUserInput: bool("pauseOnUserInput"),
126
128
  reportUserActions: bool("reportUserActions"),
127
129
  userIdleMs: num("userIdleMs", 300, 1e4),
@@ -140,17 +142,20 @@ window.__ModuleLoader__.load({
140
142
  //#endregion
141
143
  //#region lib/types/client/accent.js
142
144
  /**
143
- * The accent colour shared by the copylee DSH plugins (docs/ui-spec.md).
145
+ * This plugin's own accent colour (settings page, composer pill).
144
146
  *
145
- * One choice — terracotta orange by default, blue or black — is kept in the
146
- * browser under a key every plugin reads, and painted as two CSS variables on
147
- * `<body>`, where the Host keeps its own theme variables. A plugin's styles
148
- * only ever write `var(--cl-accent)` / `var(--cl-accent-ink)`, so changing the
149
- * colour in any plugin's settings recolours all of them at once.
150
- *
151
- * This file is identical in every plugin; change it in all of them together.
147
+ * One choice — black by default, terracotta orange or blue — is kept in the
148
+ * browser under a key only this plugin reads, and painted as two CSS
149
+ * variables on `<body>` that only this plugin's styles use
150
+ * (`var(--dshcu-accent)` / `var(--dshcu-accent-ink)`). Changing it here does
151
+ * not recolour the other copylee plugins, and theirs does not recolour this one.
152
152
  */
153
153
  const ACCENTS = {
154
+ black: {
155
+ name: "黑色",
156
+ accent: "var(--dsw-alias-label-primary, #1F1E1D)",
157
+ ink: "var(--dsw-alias-bg-base, #FFFFFF)"
158
+ },
154
159
  orange: {
155
160
  name: "陶土橙",
156
161
  accent: "#D97757",
@@ -160,20 +165,15 @@ window.__ModuleLoader__.load({
160
165
  name: "蓝色",
161
166
  accent: "#3D63E6",
162
167
  ink: "#FFFFFF"
163
- },
164
- black: {
165
- name: "黑色",
166
- accent: "var(--dsw-alias-label-primary, #1F1E1D)",
167
- ink: "var(--dsw-alias-bg-base, #FFFFFF)"
168
168
  }
169
169
  };
170
170
  const ACCENT_IDS = Object.keys(ACCENTS);
171
- const DEFAULT_ACCENT = "orange";
171
+ const DEFAULT_ACCENT = "black";
172
172
  /** Use these in styles; the fallbacks cover the moment before the first paint. */
173
- const ACCENT = `var(--cl-accent, ${ACCENTS[DEFAULT_ACCENT].accent})`;
174
- const ACCENT_INK = `var(--cl-accent-ink, ${ACCENTS[DEFAULT_ACCENT].ink})`;
175
- const KEY = "copylee.dsh.accent";
176
- const EVENT = "copylee-dsh-accent";
173
+ const ACCENT = `var(--dshcu-accent, ${ACCENTS[DEFAULT_ACCENT].accent})`;
174
+ const ACCENT_INK = `var(--dshcu-accent-ink, ${ACCENTS[DEFAULT_ACCENT].ink})`;
175
+ const KEY = "copylee.dsh.computer-use.accent";
176
+ const EVENT = "dsh-computer-use-accent";
177
177
  function isAccent(value) {
178
178
  return typeof value === "string" && Object.hasOwn(ACCENTS, value);
179
179
  }
@@ -187,14 +187,14 @@ window.__ModuleLoader__.load({
187
187
  }
188
188
  }
189
189
  function readAccent() {
190
- return storedAccent() ?? "orange";
190
+ return storedAccent() ?? "black";
191
191
  }
192
192
  function paint() {
193
193
  const colors = ACCENTS[readAccent()];
194
- document.body?.style.setProperty("--cl-accent", colors.accent);
195
- document.body?.style.setProperty("--cl-accent-ink", colors.ink);
194
+ document.body?.style.setProperty("--dshcu-accent", colors.accent);
195
+ document.body?.style.setProperty("--dshcu-accent-ink", colors.ink);
196
196
  }
197
- /** Choose the accent for every plugin. */
197
+ /** Choose this plugin's accent. */
198
198
  function writeAccent(accent) {
199
199
  try {
200
200
  localStorage.setItem(KEY, accent);
@@ -207,11 +207,16 @@ window.__ModuleLoader__.load({
207
207
  if (typeof document === "undefined") return () => {};
208
208
  paint();
209
209
  if (document.body === null) document.addEventListener("DOMContentLoaded", paint, { once: true });
210
+ const onStorage = (event) => {
211
+ if (event.key === null || event.key === KEY) paint();
212
+ };
210
213
  window.addEventListener(EVENT, paint);
211
- window.addEventListener("storage", paint);
214
+ window.addEventListener("storage", onStorage);
212
215
  return () => {
216
+ document.body?.style.removeProperty("--dshcu-accent");
217
+ document.body?.style.removeProperty("--dshcu-accent-ink");
213
218
  window.removeEventListener(EVENT, paint);
214
- window.removeEventListener("storage", paint);
219
+ window.removeEventListener("storage", onStorage);
215
220
  };
216
221
  }
217
222
  function useAccent() {
@@ -527,14 +532,14 @@ window.__ModuleLoader__.load({
527
532
  const selectCss = `
528
533
  @keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}
529
534
  .dshcu-select{box-sizing:border-box;width:100%;height:36px;padding:0 12px;display:flex;align-items:center;gap:8px;text-align:left;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}
530
- .dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--cl-accent,#D97757) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}
531
- .dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--cl-accent,#D97757);box-shadow:0 0 0 3px color-mix(in srgb,var(--cl-accent,#D97757) 20%,transparent)}
535
+ .dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}
536
+ .dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--dshcu-accent,#1F1E1D);box-shadow:0 0 0 3px color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 20%,transparent)}
532
537
  .dshcu-select:disabled{opacity:.48;cursor:default}
533
538
  .dshcu-select svg{flex:none;transition:transform .2s cubic-bezier(.22,1,.36,1)}
534
539
  .dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:5px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18));background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-1,#fff));color:var(--dsw-alias-label-primary,#222);backdrop-filter:var(--dsw-menu-backdrop-filter,none);box-shadow:var(--dsw-elevation-prominent,0 12px 32px rgba(0,0,0,.16),0 2px 6px rgba(0,0,0,.06));animation:dshcu-menu-in .14s cubic-bezier(.22,1,.36,1)}
535
540
  .dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 10px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none;transition:background-color .12s ease,color .12s ease}
536
541
  .dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.11))}
537
- .dshcu-option[aria-selected=true]{font-weight:500;color:var(--cl-accent,#D97757)}
542
+ .dshcu-option[aria-selected=true]{font-weight:500;color:var(--dshcu-accent,#1F1E1D)}
538
543
  `;
539
544
  function Select({ options, value, disabled, label, onChange }) {
540
545
  const id = react.useId();
@@ -705,7 +710,7 @@ window.__ModuleLoader__.load({
705
710
  .dshcu-skill-row:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.07));border-color:var(--dsw-alias-border-l2,rgba(127,127,127,.18))}
706
711
  .dshcu-chip-tab{padding:4px 10px;border-radius:999px;font-size:12px;cursor:pointer;border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-secondary,#666);transition:background .15s ease,color .15s ease,border-color .15s ease}
707
712
  .dshcu-chip-tab:hover{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.08))}
708
- .dshcu-chip-tab[data-active="true"]{background:var(--dshcu-accent-soft,rgba(217,119,87,.14));color:var(--dshcu-accent,#d97757);border-color:var(--dshcu-accent,#d97757);font-weight:600}
713
+ .dshcu-chip-tab[data-active="true"]{background:color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 12%,transparent);color:var(--dshcu-accent,#1F1E1D);border-color:var(--dshcu-accent,#1F1E1D);font-weight:600}
709
714
  .dshcu-modal-backdrop{position:fixed;inset:0;z-index:9999;background:rgba(15,15,18,.48);backdrop-filter:blur(4px);display:flex;align-items:center;justify-content:center;padding:20px;animation:dshcu-backdrop-in .16s ease}
710
715
  .dshcu-modal{width:min(640px,100%);max-height:min(86vh,720px);display:flex;flex-direction:column;border-radius:16px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,inherit);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));box-shadow:0 24px 64px rgba(0,0,0,.28);overflow:hidden;animation:dshcu-modal-in .18s cubic-bezier(.16,1,.3,1)}
711
716
  `;
@@ -1254,6 +1259,7 @@ window.__ModuleLoader__.load({
1254
1259
  maxLongEdge: String(s.maxLongEdge),
1255
1260
  maxMegapixels: String(Math.round(s.maxPixels / 1e4) / 100),
1256
1261
  jpegQuality: String(s.jpegQuality),
1262
+ keepScreenshots: String(s.keepScreenshots),
1257
1263
  elementFirstClick: s.elementFirstClick,
1258
1264
  restorePointer: s.restorePointer,
1259
1265
  protectPasswords: s.protectPasswords,
@@ -1274,6 +1280,7 @@ window.__ModuleLoader__.load({
1274
1280
  check("maxLongEdge", 640, 3840);
1275
1281
  check("maxMegapixels", .3, 8);
1276
1282
  check("jpegQuality", 30, 100);
1283
+ check("keepScreenshots", 0, 20);
1277
1284
  check("cdpPort", 0, 65535);
1278
1285
  return errors;
1279
1286
  }
@@ -1299,6 +1306,7 @@ window.__ModuleLoader__.load({
1299
1306
  maxLongEdge: Math.round(Number(d.maxLongEdge)),
1300
1307
  maxPixels: Math.round(Number(d.maxMegapixels) * 1e6),
1301
1308
  jpegQuality: Math.round(Number(d.jpegQuality)),
1309
+ keepScreenshots: Math.round(Number(d.keepScreenshots)),
1302
1310
  elementFirstClick: d.elementFirstClick,
1303
1311
  restorePointer: d.restorePointer,
1304
1312
  protectPasswords: d.protectPasswords,
@@ -2052,14 +2060,21 @@ window.__ModuleLoader__.load({
2052
2060
  error: errors.jpegQuality,
2053
2061
  disabled,
2054
2062
  onChange: (value) => edit("jpegQuality", value)
2055
- })), liveShot ? h("div", { className: "dshcu-metric-bar" }, h("strong", null, `主屏实际输出 ${liveShot.width}×${liveShot.height}`), h("span", { style: S.hint }, `${liveShot.megapixels} MP · ${limitLabel(liveShot.limitedBy)}${liveCompactShot ? ` | 紧凑档 ${liveCompactShot.width}×${liveCompactShot.height}(${liveCompactShot.megapixels} MP)` : ""}`)) : h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。最长边与总像素上限同时生效,取更紧的一项。")), h(SkillsCard, { S }), h("section", { className: "dshcu-card" }, h("div", { style: S.cardHeader }, h("h3", { style: S.cardTitle }, "截图缓存")), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})所属会话已删除,可以安全清理。`), h("p", { style: S.hint }, "仍在会话中的截图不会被删除。已删除会话留下的截图会在启动几分钟后及每 12 小时自动清理,也可以在此立即清理。"), h("div", { style: S.actions }, h("button", {
2063
+ })), liveShot ? h("div", { className: "dshcu-metric-bar" }, h("strong", null, `主屏实际输出 ${liveShot.width}×${liveShot.height}`), h("span", { style: S.hint }, `${liveShot.megapixels} MP · ${limitLabel(liveShot.limitedBy)}${liveCompactShot ? ` | 紧凑档 ${liveCompactShot.width}×${liveCompactShot.height}(${liveCompactShot.megapixels} MP)` : ""}`)) : h("p", { style: S.hint }, "截图越大越清晰、点得越准,但每张图消耗的 token 也越多。最长边与总像素上限同时生效,取更紧的一项。")), h(SkillsCard, { S }), h("section", { className: "dshcu-card" }, h("div", { style: S.cardHeader }, h("h3", { style: S.cardTitle }, "截图缓存")), h("p", { style: S.hint }, cache === null ? cacheBusy ? "正在统计…" : "无法统计截图缓存。" : !cache.ok ? `统计失败:${cache.error ?? ""}` : `本插件的截图共 ${cache.count} 张,占用 ${mb(cache.bytes)};其中 ${cache.orphans} 张(${mb(cache.orphanBytes)})已不再需要(已被新截图替换或所属会话已删除),可以安全清理。`), h("div", { style: S.grid2 }, h(NumberField, {
2064
+ label: "对话里保留的截图",
2065
+ unit: "张(0 = 全部保留)",
2066
+ value: draft.keepScreenshots,
2067
+ error: errors.keepScreenshots,
2068
+ disabled,
2069
+ onChange: (value) => edit("keepScreenshots", value)
2070
+ })), h("p", { style: S.hint }, "模型每次请求都会重发对话里所有截图。这里只保留最近几张,更早的换成一行文字占位(省 token),文件在几分钟后自动删除;已删除会话的截图在启动后及每 12 小时清理。"), h("div", { style: S.actions }, h("button", {
2056
2071
  type: "button",
2057
2072
  className: "dshcu-btn",
2058
2073
  disabled: cacheBusy || !cache?.orphans,
2059
2074
  onClick: () => {
2060
2075
  cleanCache();
2061
2076
  }
2062
- }, "清理已删除会话的截图"), h("button", {
2077
+ }, "立即清理不再需要的截图"), h("button", {
2063
2078
  type: "button",
2064
2079
  className: "dshcu-btn",
2065
2080
  disabled: cacheBusy,
package/lib/index.js CHANGED
@@ -4131,6 +4131,7 @@ const DEFAULTS = {
4131
4131
  maxLongEdge: 1366,
4132
4132
  maxPixels: 115e4,
4133
4133
  jpegQuality: 70,
4134
+ keepScreenshots: 2,
4134
4135
  blockedApps: [],
4135
4136
  pauseOnUserInput: true,
4136
4137
  reportUserActions: true,
@@ -4173,6 +4174,7 @@ function resolveConfig(raw) {
4173
4174
  maxLongEdge: num("maxLongEdge", 640, 3840),
4174
4175
  maxPixels: num("maxPixels", 3e5, 8e6),
4175
4176
  jpegQuality: num("jpegQuality", 30, 100),
4177
+ keepScreenshots: num("keepScreenshots", 0, 20),
4176
4178
  pauseOnUserInput: bool("pauseOnUserInput"),
4177
4179
  reportUserActions: bool("reportUserActions"),
4178
4180
  userIdleMs: num("userIdleMs", 300, 1e4),
@@ -4648,13 +4650,17 @@ function windowsRoute(helper) {
4648
4650
  * DeepSeek Harness's content-addressed store (<DSH_HOME>/attachments/v1/objects/<2>/<sha256>),
4649
4651
  * which has no retention policy yet. Attachments still referenced by a session
4650
4652
  * must stay byte-for-byte (DSH verifies their hash, and a missing one fails the
4651
- * whole turn), so only orphans are removed: screenshots this plugin made that
4652
- * no session, archive or plugin store references any more (e.g. the session
4653
- * was deleted).
4653
+ * whole turn), so only screenshots no request can need any more are removed:
4654
+ * ones this plugin made that no session, archive or plugin store references
4655
+ * (e.g. the session was deleted), and ones whose every occurrence in the
4656
+ * session logs was offloaded (`image/offload`, see retention.ts): an offloaded
4657
+ * image is sent as a text placeholder, so its bytes are never read again.
4654
4658
  */
4655
4659
  const HEX = /^[0-9a-f]{64}$/;
4656
4660
  /** Newly saved screenshots may not be in a session log yet. */
4657
4661
  const GRACE_MS = 864e5;
4662
+ /** A screenshot seen offloaded is still left alone this long after it was (last) saved. */
4663
+ const OFFLOADED_MIN_AGE_MS = 12e4;
4658
4664
  /** Places outside the session logs that can reference attachments. */
4659
4665
  const OTHER_REFERENCE_DIRS = [
4660
4666
  "storages",
@@ -4670,6 +4676,9 @@ var ScreenshotCache = class {
4670
4676
  index;
4671
4677
  saving = Promise.resolve();
4672
4678
  busy = Promise.resolve();
4679
+ /** Parsed session logs keyed by path, reused while their size and mtime stay the same. */
4680
+ files = /* @__PURE__ */ new Map();
4681
+ soon;
4673
4682
  constructor(dshHome = process.env.DSH_HOME || join(homedir(), ".dsh"), indexFile = join(process.env.LOCALAPPDATA || join(homedir(), "AppData", "Local"), "dsh-computer-use", "screenshots.json"), log = () => {}) {
4674
4683
  this.dshHome = dshHome;
4675
4684
  this.indexFile = indexFile;
@@ -4713,7 +4722,20 @@ var ScreenshotCache = class {
4713
4722
  };
4714
4723
  });
4715
4724
  }
4716
- /** Delete orphaned screenshots. */
4725
+ /** Run `clean()` once, `delayMs` after the last call (screenshots were just offloaded). */
4726
+ cleanSoon(delayMs = 18e4) {
4727
+ if (this.soon) clearTimeout(this.soon);
4728
+ this.soon = setTimeout(() => {
4729
+ this.soon = void 0;
4730
+ this.clean().catch((error) => this.log(`screenshot cleanup skipped: ${String(error)}`));
4731
+ }, delayMs);
4732
+ this.soon.unref?.();
4733
+ }
4734
+ dispose() {
4735
+ if (this.soon) clearTimeout(this.soon);
4736
+ this.soon = void 0;
4737
+ }
4738
+ /** Delete screenshots no request can need any more. */
4717
4739
  async clean() {
4718
4740
  return this.exclusive(async () => {
4719
4741
  const { orphans } = await this.classify();
@@ -4735,7 +4757,7 @@ var ScreenshotCache = class {
4735
4757
  }
4736
4758
  this.persist();
4737
4759
  await this.saving;
4738
- if (removed > 0) this.log(`screenshot cleanup: removed ${removed} orphaned screenshots (${(bytes / 1048576).toFixed(1)} MB)`);
4760
+ if (removed > 0) this.log(`screenshot cleanup: removed ${removed} screenshots (${(bytes / 1048576).toFixed(1)} MB)`);
4739
4761
  return {
4740
4762
  removed,
4741
4763
  bytes
@@ -4756,7 +4778,7 @@ var ScreenshotCache = class {
4756
4778
  const orphans = /* @__PURE__ */ new Set();
4757
4779
  for (const [hex, savedAt] of index) {
4758
4780
  if (scan.referenced.has(hex)) continue;
4759
- if (savedAt > 0 && now - savedAt < GRACE_MS) continue;
4781
+ if ((savedAt > 0 ? now - savedAt : Infinity) < (scan.offloaded.has(hex) ? OFFLOADED_MIN_AGE_MS : GRACE_MS)) continue;
4760
4782
  orphans.add(hex);
4761
4783
  }
4762
4784
  return {
@@ -4770,19 +4792,52 @@ var ScreenshotCache = class {
4770
4792
  if (typeof zstd !== "function") throw new Error("This runtime cannot read DeepSeek Harness session logs (no zstd); cleanup skipped.");
4771
4793
  const referenced = /* @__PURE__ */ new Set();
4772
4794
  const ours = /* @__PURE__ */ new Set();
4795
+ const offloaded = /* @__PURE__ */ new Set();
4796
+ const seen = /* @__PURE__ */ new Set();
4797
+ const merge = (part) => {
4798
+ for (const hex of part.referenced) referenced.add(hex);
4799
+ for (const hex of part.ours) ours.add(hex);
4800
+ for (const hex of part.offloaded) offloaded.add(hex);
4801
+ };
4773
4802
  const sessions = join(this.dshHome, "sessions");
4774
4803
  for (const file of await walk(sessions)) {
4804
+ seen.add(file);
4805
+ let info;
4806
+ try {
4807
+ info = await stat(file);
4808
+ } catch {
4809
+ continue;
4810
+ }
4811
+ const cached = this.files.get(file);
4812
+ if (cached && cached.mtimeMs === info.mtimeMs && cached.size === info.size) {
4813
+ merge(cached);
4814
+ continue;
4815
+ }
4775
4816
  const text = await readText(file, zstd);
4776
4817
  if (text === void 0) throw new Error(`Could not read ${file}; cleanup skipped to stay safe.`);
4777
- collect(text, referenced, ours);
4818
+ const part = {
4819
+ referenced: /* @__PURE__ */ new Set(),
4820
+ ours: /* @__PURE__ */ new Set(),
4821
+ offloaded: /* @__PURE__ */ new Set()
4822
+ };
4823
+ collectLog(text, part.referenced, part.ours, part.offloaded);
4824
+ this.files.set(file, {
4825
+ ...part,
4826
+ mtimeMs: info.mtimeMs,
4827
+ size: info.size
4828
+ });
4829
+ merge(part);
4778
4830
  }
4831
+ for (const file of this.files.keys()) if (!seen.has(file)) this.files.delete(file);
4779
4832
  for (const dir of OTHER_REFERENCE_DIRS) for (const file of await walk(join(this.dshHome, dir))) {
4780
4833
  const text = await readText(file, zstd);
4781
4834
  if (text !== void 0) collect(text, referenced, ours);
4782
4835
  }
4836
+ for (const hex of referenced) offloaded.delete(hex);
4783
4837
  return {
4784
4838
  referenced,
4785
- ours
4839
+ ours,
4840
+ offloaded
4786
4841
  };
4787
4842
  }
4788
4843
  async size(hex) {
@@ -4829,6 +4884,72 @@ function collect(text, referenced, ours) {
4829
4884
  for (const match of line.matchAll(/"attachmentId":"sha256:([0-9a-f]{64})"[^{}]*?"name":"screenshot\.jpg"/g)) ours.add(match[1]);
4830
4885
  }
4831
4886
  }
4887
+ const SHA = /sha256:([0-9a-f]{64})/g;
4888
+ function contentOf(event) {
4889
+ const data = event.data;
4890
+ const content = event.type === "tool/result" ? data?.message?.content : event.type === "user/message" ? data?.content : void 0;
4891
+ return Array.isArray(content) ? content : void 0;
4892
+ }
4893
+ /**
4894
+ * Read one session log. An image occurrence (message seq, top-level image
4895
+ * index) named by an `image/offload` event is offloaded; every other mention
4896
+ * of an attachment, in any event, keeps it referenced. Lines that do not parse
4897
+ * keep everything they mention.
4898
+ */
4899
+ function collectLog(text, referenced, ours, offloaded) {
4900
+ const occurrences = /* @__PURE__ */ new Map();
4901
+ const marks = /* @__PURE__ */ new Set();
4902
+ for (const line of text.split("\n")) {
4903
+ const mentionsAttachment = line.includes("sha256:");
4904
+ if (!mentionsAttachment && !line.includes("\"image/offload\"")) continue;
4905
+ let event;
4906
+ try {
4907
+ event = JSON.parse(line);
4908
+ } catch {
4909
+ for (const match of line.matchAll(SHA)) referenced.add(match[1]);
4910
+ continue;
4911
+ }
4912
+ if (event.type === "image/offload") {
4913
+ const targets = event.data?.targets;
4914
+ if (Array.isArray(targets)) for (const target of targets) {
4915
+ if (typeof target?.seq !== "number" || !Array.isArray(target.imageIndexes)) continue;
4916
+ for (const index of target.imageIndexes) if (typeof index === "number") marks.add(`${target.seq}:${index}`);
4917
+ }
4918
+ for (const match of line.matchAll(SHA)) referenced.add(match[1]);
4919
+ continue;
4920
+ }
4921
+ if (!mentionsAttachment) continue;
4922
+ const content = contentOf(event);
4923
+ const images = [];
4924
+ const counted = /* @__PURE__ */ new Map();
4925
+ if (content !== void 0) {
4926
+ const addressable = typeof event.seq === "number";
4927
+ for (const block of content) {
4928
+ if (block?.type !== "image") continue;
4929
+ const id = String(block.attachment?.attachmentId ?? "");
4930
+ const hex = id.startsWith("sha256:") ? id.slice(7) : "";
4931
+ if (!HEX.test(hex)) {
4932
+ images.push("");
4933
+ continue;
4934
+ }
4935
+ if (event.type === "tool/result" && block.attachment?.name === "screenshot.jpg") ours.add(hex);
4936
+ if (!addressable) continue;
4937
+ images.push(block.offloaded === true ? "" : hex);
4938
+ if (block.offloaded === true) offloaded.add(hex);
4939
+ counted.set(hex, (counted.get(hex) ?? 0) + 1);
4940
+ }
4941
+ if (addressable) occurrences.set(event.seq, images);
4942
+ }
4943
+ const mentions = /* @__PURE__ */ new Map();
4944
+ for (const match of line.matchAll(SHA)) mentions.set(match[1], (mentions.get(match[1]) ?? 0) + 1);
4945
+ for (const [hex, n] of mentions) if (n > (counted.get(hex) ?? 0)) referenced.add(hex);
4946
+ }
4947
+ for (const [seq, images] of occurrences) images.forEach((hex, index) => {
4948
+ if (!HEX.test(hex)) return;
4949
+ if (marks.has(`${seq}:${index}`)) offloaded.add(hex);
4950
+ else referenced.add(hex);
4951
+ });
4952
+ }
4832
4953
  async function walk(dir) {
4833
4954
  const out = [];
4834
4955
  let entries;
@@ -4881,6 +5002,87 @@ function decodeFrames(data, zstd) {
4881
5002
  }
4882
5003
  return Buffer.concat(parts).toString("utf8");
4883
5004
  }
5005
+ /** Raw content of a tool result event, read without deriving (cheap pre-filter). */
5006
+ function rawContent(event) {
5007
+ const message = event.data?.message;
5008
+ return Array.isArray(message?.content) ? message.content : void 0;
5009
+ }
5010
+ function isOurs(block) {
5011
+ return block.type === "image" && block.attachment?.name === "screenshot.jpg" && typeof block.attachment.attachmentId === "string";
5012
+ }
5013
+ /**
5014
+ * The image/offload targets that leave only the newest `keep` of this plugin's
5015
+ * retained screenshots. Image indexes count every top-level image block of the
5016
+ * message, offloaded ones included, exactly as the Host's projection does.
5017
+ */
5018
+ function planOffload(session, keep) {
5019
+ const none = {
5020
+ targets: [],
5021
+ attachmentIds: []
5022
+ };
5023
+ if (keep <= 0 || typeof session.eventAt !== "function" || typeof session.deriveEventMessage !== "function") return none;
5024
+ const nodes = session.surface?.nodes;
5025
+ if (nodes === void 0) return none;
5026
+ const retained = [];
5027
+ for (const seq of nodes) {
5028
+ let event;
5029
+ try {
5030
+ event = session.eventAt(seq);
5031
+ } catch {
5032
+ continue;
5033
+ }
5034
+ if (event?.type !== "tool/result") continue;
5035
+ if (!rawContent(event)?.some(isOurs)) continue;
5036
+ let content;
5037
+ try {
5038
+ content = session.deriveEventMessage(event).content;
5039
+ } catch {
5040
+ continue;
5041
+ }
5042
+ if (!Array.isArray(content)) continue;
5043
+ let index = 0;
5044
+ for (const block of content) {
5045
+ if (block?.type !== "image") continue;
5046
+ if (block.offloaded !== true && isOurs(block)) retained.push({
5047
+ seq,
5048
+ index,
5049
+ attachmentId: String(block.attachment.attachmentId)
5050
+ });
5051
+ index++;
5052
+ }
5053
+ }
5054
+ const drop = retained.slice(0, Math.max(0, retained.length - keep));
5055
+ if (drop.length === 0) return none;
5056
+ const bySeq = /* @__PURE__ */ new Map();
5057
+ for (const item of drop) {
5058
+ let list = bySeq.get(item.seq);
5059
+ if (!list) bySeq.set(item.seq, list = []);
5060
+ list.push(item.index);
5061
+ }
5062
+ return {
5063
+ targets: [...bySeq].map(([seq, imageIndexes]) => ({
5064
+ seq,
5065
+ imageIndexes: imageIndexes.sort((a, b) => a - b)
5066
+ })),
5067
+ attachmentIds: drop.map((item) => item.attachmentId)
5068
+ };
5069
+ }
5070
+ /**
5071
+ * Offload this plugin's screenshots older than the newest `keep` in `session`.
5072
+ * Returns the attachment ids offloaded (empty when nothing changed). Never throws.
5073
+ */
5074
+ function offloadOldScreenshots(session, keep, log = () => {}) {
5075
+ if (!session || typeof session.append !== "function") return [];
5076
+ try {
5077
+ const plan = planOffload(session, keep);
5078
+ if (plan.targets.length === 0) return [];
5079
+ session.append("image/offload", { targets: plan.targets });
5080
+ return plan.attachmentIds;
5081
+ } catch (error) {
5082
+ log(`screenshot offload skipped: ${String(error)}`);
5083
+ return [];
5084
+ }
5085
+ }
4884
5086
  //#endregion
4885
5087
  //#region lib/types/sessions.js
4886
5088
  /**
@@ -12056,6 +12258,10 @@ const Config = z.object({
12056
12258
  "zh-CN": { $description: "截图 JPEG 质量" },
12057
12259
  "en-US": { $description: "Screenshot JPEG quality" }
12058
12260
  }),
12261
+ keepScreenshots: z.natural().min(0).max(20).default(2).volatile().i18n({
12262
+ "zh-CN": { $description: "对话里保留几张截图给模型看(含最新一张)。更早的截图换成一行文字占位,不再随每次请求重发,几分钟后从磁盘删除。0 = 全部保留(旧行为)" },
12263
+ "en-US": { $description: "Screenshots kept as images in a conversation (including the latest). Older ones become a one-line text placeholder, are no longer resent with every request, and are deleted from disk a few minutes later. 0 keeps all (old behaviour)" }
12264
+ }),
12059
12265
  pauseOnUserInput: z.boolean().default(true).volatile().i18n({
12060
12266
  "zh-CN": { $description: "检测到你在操作时让出控制:你用键盘打字或点击鼠标/滚轮时暂停、停手后继续;你切换或打开了新窗口时,AI 重新看屏幕再决定(纯鼠标移动不会触发)" },
12061
12267
  "en-US": { $description: "Yield to you: pause while you type or click/scroll physically, and re-check the screen when you switch windows (pure mouse movement is ignored)" }
@@ -12165,6 +12371,7 @@ function apply(ctx, config = {}) {
12165
12371
  return () => {
12166
12372
  clearTimeout(first);
12167
12373
  clearInterval(every);
12374
+ screenshots.dispose();
12168
12375
  };
12169
12376
  }, "computer-use: screenshot cleanup");
12170
12377
  const skills = new SkillStore(helperAssetPath("skills"));
@@ -12281,6 +12488,10 @@ function apply(ctx, config = {}) {
12281
12488
  });
12282
12489
  ctx.on("agent/pre-step", ({ agent }, next) => {
12283
12490
  syncAgent(agent);
12491
+ const keep = settings().keepScreenshots;
12492
+ if (keep > 0) {
12493
+ if (offloadOldScreenshots(agent.session, keep, log).length > 0) screenshots.cleanSoon();
12494
+ }
12284
12495
  return next();
12285
12496
  });
12286
12497
  ctx.on("loader/volatile-update", (() => syncAllAgents()));
@@ -1,13 +1,11 @@
1
1
  /**
2
- * The accent colour shared by the copylee DSH plugins (docs/ui-spec.md).
2
+ * This plugin's own accent colour (settings page, composer pill).
3
3
  *
4
- * One choice — terracotta orange by default, blue or black — is kept in the
5
- * browser under a key every plugin reads, and painted as two CSS variables on
6
- * `<body>`, where the Host keeps its own theme variables. A plugin's styles
7
- * only ever write `var(--cl-accent)` / `var(--cl-accent-ink)`, so changing the
8
- * colour in any plugin's settings recolours all of them at once.
9
- *
10
- * This file is identical in every plugin; change it in all of them together.
4
+ * One choice — black by default, terracotta orange or blue — is kept in the
5
+ * browser under a key only this plugin reads, and painted as two CSS
6
+ * variables on `<body>` that only this plugin's styles use
7
+ * (`var(--dshcu-accent)` / `var(--dshcu-accent-ink)`). Changing it here does
8
+ * not recolour the other copylee plugins, and theirs does not recolour this one.
11
9
  */
12
10
  import * as React from 'react';
13
11
  export type Accent = 'orange' | 'blue' | 'black';
@@ -21,11 +19,12 @@ export declare const DEFAULT_ACCENT: Accent;
21
19
  /** Use these in styles; the fallbacks cover the moment before the first paint. */
22
20
  export declare const ACCENT: string;
23
21
  export declare const ACCENT_INK: string;
22
+ export declare const ACCENT_KEY = "copylee.dsh.computer-use.accent";
24
23
  export declare function isAccent(value: unknown): value is Accent;
25
24
  /** The choice made in this browser, or null while none has been made. */
26
25
  export declare function storedAccent(): Accent | null;
27
26
  export declare function readAccent(): Accent;
28
- /** Choose the accent for every plugin. */
27
+ /** Choose this plugin's accent. */
29
28
  export declare function writeAccent(accent: Accent): void;
30
29
  /** Paint the current accent and keep it current. Returns the undo for plugin disposal. */
31
30
  export declare function installAccent(): () => void;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  /** Menu appearance and fixed-position behavior follow dsh-free-search / dsh-proxy. */
3
- export declare const selectCss = "\n@keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}\n.dshcu-select{box-sizing:border-box;width:100%;height:36px;padding:0 12px;display:flex;align-items:center;gap:8px;text-align:left;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}\n.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--cl-accent,#D97757) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}\n.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--cl-accent,#D97757);box-shadow:0 0 0 3px color-mix(in srgb,var(--cl-accent,#D97757) 20%,transparent)}\n.dshcu-select:disabled{opacity:.48;cursor:default}\n.dshcu-select svg{flex:none;transition:transform .2s cubic-bezier(.22,1,.36,1)}\n.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:5px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18));background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-1,#fff));color:var(--dsw-alias-label-primary,#222);backdrop-filter:var(--dsw-menu-backdrop-filter,none);box-shadow:var(--dsw-elevation-prominent,0 12px 32px rgba(0,0,0,.16),0 2px 6px rgba(0,0,0,.06));animation:dshcu-menu-in .14s cubic-bezier(.22,1,.36,1)}\n.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 10px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none;transition:background-color .12s ease,color .12s ease}\n.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.11))}\n.dshcu-option[aria-selected=true]{font-weight:500;color:var(--cl-accent,#D97757)}\n";
3
+ export declare const selectCss = "\n@keyframes dshcu-menu-in{from{opacity:0;transform:translateY(-4px) scale(.985)}to{opacity:1;transform:translateY(0) scale(1)}}\n.dshcu-select{box-sizing:border-box;width:100%;height:36px;padding:0 12px;display:flex;align-items:center;gap:8px;text-align:left;border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.28));border-radius:var(--dsw-radius-md,9px);background:var(--dsw-alias-bg-layer-3,transparent);color:inherit;font:inherit;font-size:13px;cursor:pointer;transition:border-color .16s ease,background-color .16s ease,box-shadow .16s ease}\n.dshcu-select:hover:not(:disabled){border-color:color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 55%,var(--dsw-alias-border-l3,#888));background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.05))}\n.dshcu-select:focus-visible,.dshcu-select[aria-expanded=true]{outline:none;border-color:var(--dshcu-accent,#1F1E1D);box-shadow:0 0 0 3px color-mix(in srgb,var(--dshcu-accent,#1F1E1D) 20%,transparent)}\n.dshcu-select:disabled{opacity:.48;cursor:default}\n.dshcu-select svg{flex:none;transition:transform .2s cubic-bezier(.22,1,.36,1)}\n.dshcu-menu{position:fixed;z-index:1100;box-sizing:border-box;padding:5px;overflow-y:auto;overscroll-behavior:contain;border-radius:var(--dsw-radius-lg,12px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.18));background:var(--dsw-menu-surface-fill,var(--dsw-alias-bg-layer-1,#fff));color:var(--dsw-alias-label-primary,#222);backdrop-filter:var(--dsw-menu-backdrop-filter,none);box-shadow:var(--dsw-elevation-prominent,0 12px 32px rgba(0,0,0,.16),0 2px 6px rgba(0,0,0,.06));animation:dshcu-menu-in .14s cubic-bezier(.22,1,.36,1)}\n.dshcu-option{display:flex;align-items:center;gap:8px;min-height:34px;padding:6px 10px;box-sizing:border-box;border-radius:var(--dsw-radius-md,8px);font-size:13px;line-height:20px;cursor:pointer;user-select:none;transition:background-color .12s ease,color .12s ease}\n.dshcu-option[data-active=true]{background:var(--dsw-alias-interactive-bg-hover,rgba(127,127,127,.11))}\n.dshcu-option[aria-selected=true]{font-weight:500;color:var(--dshcu-accent,#1F1E1D)}\n";
4
4
  export declare function Select<V extends string>({ options, value, disabled, label, onChange }: {
5
5
  options: {
6
6
  value: V;
@@ -27,6 +27,8 @@ export interface Settings {
27
27
  maxLongEdge: number;
28
28
  maxPixels: number;
29
29
  jpegQuality: number;
30
+ /** Screenshots kept as images in a conversation; older ones become text placeholders and their files are cleaned up. 0 keeps all. */
31
+ keepScreenshots: number;
30
32
  autoScreenshot: boolean;
31
33
  /** Detail tier for automatic post-action screenshots: standard or compact (smaller/cheaper). */
32
34
  autoScreenshotDetail: AutoScreenshotDetail;
@@ -29,6 +29,7 @@ export interface Config {
29
29
  maxLongEdge?: number;
30
30
  maxPixels?: number;
31
31
  jpegQuality?: number;
32
+ keepScreenshots?: number;
32
33
  blockedApps?: string[];
33
34
  pauseOnUserInput?: boolean;
34
35
  reportUserActions?: boolean;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Screenshot retention inside a conversation.
3
+ *
4
+ * DeepSeek Harness resends every image still in the history with each model
5
+ * request (up to its per-request budget), so a long computer-use task pays for
6
+ * dozens of stale screenshots on every step, and none of their files can ever
7
+ * be deleted. The Host's own image offload (`@deepseek-ai/dsh-compaction-image-offload`)
8
+ * only kicks in once a request is rejected as over budget.
9
+ *
10
+ * Before each step this plugin records the same durable `image/offload`
11
+ * decision for its own screenshots older than the newest `keep`: the model
12
+ * then sees a one-line placeholder in their place, provider caching restarts
13
+ * only at that (recent) point, and the screenshot files are no longer read
14
+ * for requests, so `ScreenshotCache` may delete them. User images and images
15
+ * from other tools are never touched.
16
+ */
17
+ /** The attachment name every screenshot of this plugin carries. */
18
+ export declare const SCREENSHOT_NAME = "screenshot.jpg";
19
+ interface BlockLike {
20
+ type?: unknown;
21
+ offloaded?: unknown;
22
+ attachment?: {
23
+ attachmentId?: unknown;
24
+ name?: unknown;
25
+ };
26
+ }
27
+ interface EventLike {
28
+ type?: unknown;
29
+ data?: unknown;
30
+ }
31
+ /** The parts of a Host Session this module uses (all optional: older hosts lack some). */
32
+ export interface RetentionSession {
33
+ surface?: {
34
+ nodes?: Iterable<number>;
35
+ };
36
+ eventAt?(seq: number): EventLike;
37
+ deriveEventMessage?(event: EventLike): {
38
+ content?: readonly BlockLike[];
39
+ };
40
+ append?(type: string, data: unknown): unknown;
41
+ }
42
+ export interface OffloadTarget {
43
+ seq: number;
44
+ imageIndexes: number[];
45
+ }
46
+ /**
47
+ * The image/offload targets that leave only the newest `keep` of this plugin's
48
+ * retained screenshots. Image indexes count every top-level image block of the
49
+ * message, offloaded ones included, exactly as the Host's projection does.
50
+ */
51
+ export declare function planOffload(session: RetentionSession, keep: number): {
52
+ targets: OffloadTarget[];
53
+ attachmentIds: string[];
54
+ };
55
+ /**
56
+ * Offload this plugin's screenshots older than the newest `keep` in `session`.
57
+ * Returns the attachment ids offloaded (empty when nothing changed). Never throws.
58
+ */
59
+ export declare function offloadOldScreenshots(session: RetentionSession | undefined, keep: number, log?: (message: string) => void): string[];
60
+ export {};
@@ -18,13 +18,19 @@ export declare class ScreenshotCache {
18
18
  private index;
19
19
  private saving;
20
20
  private busy;
21
+ /** Parsed session logs keyed by path, reused while their size and mtime stay the same. */
22
+ private files;
23
+ private soon;
21
24
  constructor(dshHome?: string, indexFile?: string, log?: (message: string) => void);
22
25
  private get objects();
23
26
  private path;
24
27
  /** Remember a screenshot attachment ("sha256:<hex>") this plugin saved. */
25
28
  record(attachmentId: string): void;
26
29
  stats(): Promise<ScreenshotStats>;
27
- /** Delete orphaned screenshots. */
30
+ /** Run `clean()` once, `delayMs` after the last call (screenshots were just offloaded). */
31
+ cleanSoon(delayMs?: number): void;
32
+ dispose(): void;
33
+ /** Delete screenshots no request can need any more. */
28
34
  clean(): Promise<CleanResult>;
29
35
  private classify;
30
36
  /** Every attachment id referenced anywhere DSH keeps conversation state. */
@@ -36,6 +42,13 @@ export declare class ScreenshotCache {
36
42
  }
37
43
  /** Ids in `text`; ids of our own screenshots (tool results named screenshot.jpg) also go to `ours`. */
38
44
  export declare function collect(text: string, referenced: Set<string>, ours: Set<string>): void;
45
+ /**
46
+ * Read one session log. An image occurrence (message seq, top-level image
47
+ * index) named by an `image/offload` event is offloaded; every other mention
48
+ * of an attachment, in any event, keeps it referenced. Lines that do not parse
49
+ * keep everything they mention.
50
+ */
51
+ export declare function collectLog(text: string, referenced: Set<string>, ours: Set<string>, offloaded: Set<string>): void;
39
52
  /** Split at frame magics; when a split falls inside a frame, merge with the next piece and retry. */
40
53
  export declare function decodeFrames(data: Buffer, zstd: ZstdDecompress): string | undefined;
41
54
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copylee/dsh-computer-use",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "DeepSeek Harness Computer Use 插件(Windows):让 AI 看屏幕、点鼠标、敲键盘操控电脑;控制时屏幕泛起橙色光晕并显示“DeepSeek Harness 正在操控你的电脑”,按 Esc 暂停 / 继续。",
5
5
  "icon": "assets/icon.svg",
6
6
  "type": "module",