@@ -1,19 +1,16 @@
1import { COLORS, isColor, type GroupColor } from "../shared/colors";
1import { COLORS, isColor, type GroupColor } from "../shared/colors";
2−import { labelOf, repairLabel, safeEmoji, stripTitle, titleKey } from "../shared/label";
2+import { labelOf, repairLabel, safeEmoji, stripTitle } from "../shared/label";
3import { colorFor, isInternalUrl, promptAddress, provisionalTitle } from "../shared/url";
3import { colorFor, isInternalUrl, promptAddress, provisionalTitle } from "../shared/url";
4import { pathKey } from "./engine";
4import { pathKey } from "./engine";
5−import { membersHash, memberUrls, settled, toItems, type Member, type NameItem } from "./naming";
5+import { membersHash, memberUrls, toItems, type Member, type NameItem } from "./naming";
6import { addToGroup, createManagedGroup, groupExists, ungroup, type Runtime } from "./runtime";
6import { addToGroup, createManagedGroup, groupExists, ungroup, type Runtime } from "./runtime";
7−import type { HostReply } from "./host";
8−import { markDirty, type GroupRecord, type HostError, type HostErrorCode, type State, type TabRecord } from "./state";
7+import { markDirty, type State } from "./state";
10/** Section 3/9: "Organize all tabs" — cluster ungrouped tabs in batches sized to the model's window. */
9/** Section 3/9: "Organize all tabs" — cluster ungrouped tabs in batches sized to the model's window. */
12export const ORGANIZE_ITEM_CAP = 36;
11export const ORGANIZE_ITEM_CAP = 36;
13export const EXISTING_GROUPS_CAP = 12;
12export const EXISTING_GROUPS_CAP = 12;
14−// About the host's 7,000-token budget in English characters. Chinese and Japanese cost about twice the tokens
15−// per character, so their characters count double (weightedLength); the host measures exactly and shortens.
16−export const CHAR_BUDGET = 24_000;
13+export const CHAR_BUDGET = 24_000; // matches the host's budget for fm's ~8k-token context
17export const INSTRUCTION_CHARS = 1_400; // ~320 tokens of rules, emoji and colour lists
14export const INSTRUCTION_CHARS = 1_400; // ~320 tokens of rules, emoji and colour lists
18export const EXISTING_GROUP_CHARS = 90;
15export const EXISTING_GROUP_CHARS = 90;
19export const UNDO_WINDOW_MS = 3_600_000;
16export const UNDO_WINDOW_MS = 3_600_000;
@@ -27,8 +24,6 @@ export interface ExistingGroup {
27export interface OrganizePayload {
24export interface OrganizePayload {
28 items: NameItem[];
25 items: NameItem[];
29 existingGroups: ExistingGroup[];
26 existingGroups: ExistingGroup[];
30− /** Every group label in the window: a new group the host names must not repeat one. */
31− siblingTitles?: string[];
32 allowNew: boolean;
27 allowNew: boolean;
33 maxGroups: number;
28 maxGroups: number;
34 minGroupSize: number;
29 minGroupSize: number;
@@ -58,12 +53,9 @@ export const maxGroupsFor = (n: number): number => Math.min(8, Math.ceil(n / 3))
58export const organizable = (t: { groupId?: number; pinned?: boolean; url?: string; incognito?: boolean }): boolean =>
53export const organizable = (t: { groupId?: number; pinned?: boolean; url?: string; incognito?: boolean }): boolean =>
59 (t.groupId ?? -1) === -1 && !t.pinned && !t.incognito && !isInternalUrl(t.url);
54 (t.groupId ?? -1) === -1 && !t.pinned && !t.incognito && !isInternalUrl(t.url);
61−const CJK = /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uac00-\ud7af\uf900-\ufaff]/g;
62−export const weightedLength = (s: string): number => s.length + (s.match(CJK)?.length ?? 0);
64/** Rough rendered size of one item line, the unit the character budget is spent in. */
56/** Rough rendered size of one item line, the unit the character budget is spent in. */
65export const itemChars = (m: Pick<Member, "title" | "url" | "description">): number =>
57export const itemChars = (m: Pick<Member, "title" | "url" | "description">): number =>
66− weightedLength(m.title.slice(0, 120)) + promptAddress(m.url).length + weightedLength((m.description ?? " ").slice(0, 500)) + 12;
58+ Math.min(120, m.title.length) + promptAddress(m.url).length + Math.min(500, m.description?.length ?? 1) + 12;
68/** Split tabs (in strip order) into batches of ≤ cap items that also fit the character budget. */
60/** Split tabs (in strip order) into batches of ≤ cap items that also fit the character budget. */
69export function makeBatches<T extends Pick<Member, "title" | "url" | "description">>(
61export function makeBatches<T extends Pick<Member, "title" | "url" | "description">>(
@@ -154,198 +146,88 @@ export interface OrganizeReport {
154 error?: string;
146 error?: string;
157−/** Existing groups a batch may add tabs to: Diagonal's topic groups in this window, the ones in use first. */
149+/** Existing groups a batch may add tabs to: extension-managed topic groups in this window. */
158export function existingGroupsFor(state: State, windowId: number, extraIds: number[] = []): { ids: number[]; list: ExistingGroup[] } {
150export function existingGroupsFor(state: State, windowId: number, extraIds: number[] = []): { ids: number[]; list: ExistingGroup[] } {
159− const members = new Map<number, TabRecord[]>();
160− for (const t of Object.values(state.tabs)) if (t.groupId !== -1) members.set(t.groupId, [...(members.get(t.groupId) ?? []), t]);
161− const inUse = (g: GroupRecord): number =>
162− Math.max(g.dirtyAt ?? 0, g.lastNamedAt ?? 0, ...(members.get(g.id) ?? []).map((t) => t.lastActivatedAt ?? 0));
163 const groups = Object.values(state.groups)
151 const groups = Object.values(state.groups)
164− .filter((g) => g.windowId === windowId && g.managed && g.origin !== "tidy" && !g.restored && (g.stripTitle || g.title))
152+ .filter((g) => g.windowId === windowId && g.managed && g.origin !== "tidy" && (g.stripTitle || g.title))
165− .map((g) => ({ g, first: extraIds.includes(g.id), at: inUse(g) }))
166− .sort((a, b) => Number(b.first) - Number(a.first) || b.at - a.at)
153+ .sort((a, b) => Number(extraIds.includes(b.id)) - Number(extraIds.includes(a.id)))
167− .slice(0, EXISTING_GROUPS_CAP)
154+ .slice(0, EXISTING_GROUPS_CAP);
169 const list = groups.map((g, i) => ({
155 const list = groups.map((g, i) => ({
171 title: labelOf(g.stripTitle || g.title),
157 title: labelOf(g.stripTitle || g.title),
158+ samples: Object.values(state.tabs)
159+ .filter((t) => t.groupId === g.id)
172− samples: (members.get(g.id) ?? []).slice(0, 2).map((t) => t.title.slice(0, 60)),
161+ .map((t) => t.title.slice(0, 60)),
174 return { ids: groups.map((g) => g.id), list };
163 return { ids: groups.map((g) => g.id), list };
177−/** Errors about what was sent rather than about the host: a smaller or plainer request may go through. */
178−const CONTENT_ERRORS = new Set<HostErrorCode>(["OVER_BUDGET", "GUARDRAIL", "BAD_MODEL_OUTPUT"]);
179−const MAX_TIMEOUT_SPLITS = 1;
181−/** One organize call, with the retries that can rescue the same tabs: strict output, then no page text. */
182−async function askOrganize(rt: Runtime, part: Member[], windowId: number, existingGroups: ExistingGroup[], withDescriptions: boolean): Promise<HostReply<OrganizeResult>> {
183− const settings = rt.settings();
184− const s = rt.state();
185− const payload: OrganizePayload = {
186− items: toItems(part, settings, withDescriptions),
188− siblingTitles: Object.values(s.groups)
189− .filter((g) => g.windowId === windowId && g.origin !== "tidy")
190− .map((g) => labelOf(g.stripTitle || g.title))
193− allowNew: part.length >= 2,
194− maxGroups: maxGroupsFor(part.length),
195− minGroupSize: settings.organizeMinGroupSize,
197− let reply = await rt.host<OrganizeResult>("organize", payload);
198− if (!reply.ok && reply.error.code === "BAD_MODEL_OUTPUT") reply = await rt.host<OrganizeResult>("organize", payload, { strict: true });
199− if (!reply.ok && reply.error.code === "GUARDRAIL" && payload.items.some((i) => i.description)) {
200− // What a page says is the likeliest thing to trip Apple's filter; its title and address rarely do.
201− payload.items = toItems(part, settings, false);
202− reply = await rt.host<OrganizeResult>("organize", payload);
207−/** One organize run over a window: what it made, what it moved, and whether the host stopped it. */
208−export interface SortRun {
210− createdIds: number[];
211− previous: Record<number, number>;
214− timeoutSplits: number;
215− /** Auto-organize: remember what was looked at, so the same tabs are not sent again unchanged. */
217− stopped?: HostError;
220−export const newRun = (windowId: number, stamp: boolean): SortRun => ({ windowId, createdIds: [], previous: {}, grouped: 0, left: 0, timeoutSplits: 0, stamp });
223− * Sort one part of a window. A reply about the tabs themselves (too long, refused by Apple's filter, not
224− * valid output) splits the part in halves, so one page the model won't handle leaves the others sorted; a
225− * tab that fails alone is set aside until its page or title changes. Tabs that changed while the model was
226− * thinking are left out of its answer.
228−export async function sortPart(rt: Runtime, part: Member[], run: SortRun, probe = false): Promise<void> {
229− if (!part.length || run.stopped) return;
230− const { ids: existingIds, list: existingGroups } = existingGroupsFor(rt.state(), run.windowId, run.createdIds);
231− if (part.length < 2 && !existingIds.length && !probe) {
232− run.left += part.length;
233− return; // one tab and nothing to join: no call can place it (a probe still learns whether the model takes it)
235− const reply = await askOrganize(rt, part, run.windowId, existingGroups, true);
237− const e = reply.error;
238− const timedOut = e.code === "TIMEOUT" && part.length > 4 && run.timeoutSplits < MAX_TIMEOUT_SPLITS;
239− if (part.length > 1 && (CONTENT_ERRORS.has(e.code) || timedOut)) {
240− if (timedOut) run.timeoutSplits++;
241− const half = Math.ceil(part.length / 2);
242− await sortPart(rt, part.slice(0, half), run, true);
243− await sortPart(rt, part.slice(half), run, true);
246− if (CONTENT_ERRORS.has(e.code)) {
247− const rec = rt.state().tabs[part[0].id];
248− if (rec) rec.organizeRefused = organizedKeyOf(part[0]);
249− rt.log("organize: set aside a tab the model would not sort", e.code);
256− const settings = rt.settings();
257− const plan = planFromResult(reply.result, part.map((m) => m.id), existingIds, settings.organizeMinGroupSize, maxGroupsFor(part.length), (ids) =>
258− colorFor(part.find((m) => m.id === ids[0])?.url ?? ""),
260− const unchanged = await stillAsSent(rt, part, run.windowId);
261− const trimmed = trimPlan(rt.state(), plan, unchanged, settings.organizeMinGroupSize);
262− const failed = await applyPlan(rt, trimmed, run.windowId, part, run.previous, run.createdIds);
263− const placed = [...trimmed.joins, ...trimmed.creates].reduce((n, x) => n + x.tabIds.filter((id) => !failed.has(id)).length, 0);
264− run.grouped += placed;
265− run.left += part.length - placed;
267− const s = rt.state();
268− for (const m of part) {
269− const rec = s.tabs[m.id];
270− if (rec && unchanged.has(m.id) && !failed.has(m.id)) rec.organizedKey = organizedKeyOf(m);
275−/** The tabs of a part that are still loose, in this window, on the page and title the model saw. */
276−async function stillAsSent(rt: Runtime, part: Member[], windowId: number): Promise<Set<number>> {
277− const live = new Map((await chrome.tabs.query({ windowId }).catch(() => [])).map((t) => [t.id!, t]));
278− const s = rt.state();
282− const t = live.get(m.id);
283− return !!t && organizable(t) && !s.tabs[m.id]?.keepLoose && organizedKeyOf(t) === organizedKeyOf(m);
289−/** A plan with the tabs that moved on taken out: a new group left too small is not made, a join into a group gone is dropped. */
290−export function trimPlan(state: State, plan: Plan, keep: Set<number>, minGroupSize: number): Plan {
291− const out: Plan = { joins: [], creates: [], leftovers: plan.leftovers.filter((id) => keep.has(id)) };
292− for (const j of plan.joins) {
293− const tabIds = j.tabIds.filter((id) => keep.has(id));
294− const g = state.groups[j.groupId];
295− if (tabIds.length && g?.managed && !g.restored) out.joins.push({ ...j, tabIds });
296− else out.leftovers.push(...tabIds);
298− for (const c of plan.creates) {
299− const tabIds = c.tabIds.filter((id) => keep.has(id));
300− if (tabIds.length >= Math.max(2, minGroupSize)) out.creates.push({ ...c, tabIds });
301− else out.leftovers.push(...tabIds);
306export async function organizeWindow(rt: Runtime, windowId: number): Promise<OrganizeReport> {
166export async function organizeWindow(rt: Runtime, windowId: number): Promise<OrganizeReport> {
307− const s0 = rt.state();
167+ const settings = rt.settings();
308 const tabs = (await chrome.tabs.query({ windowId })).filter((t) => organizable(t)).sort((a, b) => a.index - b.index);
168 const tabs = (await chrome.tabs.query({ windowId })).filter((t) => organizable(t)).sort((a, b) => a.index - b.index);
309 const report: OrganizeReport = { grouped: 0, groups: 0, left: 0 };
169 const report: OrganizeReport = { grouped: 0, groups: 0, left: 0 };
310− // A tab the model already would not sort, on the same page, is not sent again.
311− const sendable = tabs.filter((t) => s0.tabs[t.id!]?.organizeRefused !== organizedKeyOf(t));
312− if (sendable.length < 2) {
170+ if (tabs.length < 2) {
313 report.left = tabs.length;
171 report.left = tabs.length;
314 return report;
172 return report;
316− const run = newRun(windowId, true); // auto-organize need not send the same tabs again right after
174+ const members: Member[] = tabs.map((t) => ({
178+ title: t.title ?? "",
180+ description: rt.state().tabs[t.id!]?.description,
181+ lastActive: t.lastAccessed ?? 0,
183+ const previous: Record<number, number> = {};
184+ const createdIds: number[] = [];
185+ const queue = makeBatches(members);
317 rt.state().inFlight = { groupId: -1, startedAt: rt.now() };
186 rt.state().inFlight = { groupId: -1, startedAt: rt.now() };
318 rt.refreshBadge();
187 rt.refreshBadge();
320− for (const batch of makeBatches(sendable.map((t) => toMember(rt.state(), t)))) {
189+ while (queue.length) {
321− await sortPart(rt, batch, run);
190+ const batch = queue.shift()!;
191+ const { ids: existingIds, list: existingGroups } = existingGroupsFor(rt.state(), windowId, createdIds);
192+ const maxGroups = maxGroupsFor(batch.length);
193+ const payload: OrganizePayload = {
194+ items: toItems(batch, settings),
198+ minGroupSize: settings.organizeMinGroupSize,
200+ let reply = await rt.host<OrganizeResult>("organize", payload);
201+ if (!reply.ok && reply.error.code === "OVER_BUDGET" && batch.length > 1) {
202+ const half = Math.ceil(batch.length / 2);
203+ queue.unshift(batch.slice(0, half), batch.slice(half));
206+ if (!reply.ok && reply.error.code === "BAD_MODEL_OUTPUT") reply = await rt.host<OrganizeResult>("organize", payload, { strict: true });
208+ report.error = `${reply.error.code}: ${reply.error.message}`;
209+ report.left += batch.length + queue.flat().length;
322− if (run.stopped) break;
210+ break;
212+ const batchIds = batch.map((m) => m.id);
213+ const plan = planFromResult(reply.result, batchIds, existingIds, settings.organizeMinGroupSize, maxGroups, (ids) =>
214+ colorFor(members.find((m) => m.id === ids[0])?.url ?? ""),
216+ await applyPlan(rt, plan, windowId, members, previous, createdIds);
217+ report.grouped += plan.joins.reduce((n, j) => n + j.tabIds.length, 0) + plan.creates.reduce((n, c) => n + c.tabIds.length, 0);
218+ report.left += plan.leftovers.length;
324 } finally {
220 } finally {
325 const s = rt.state();
221 const s = rt.state();
326 if (s.inFlight?.groupId === -1) s.inFlight = undefined;
222 if (s.inFlight?.groupId === -1) s.inFlight = undefined;
327− report.grouped = run.grouped;
328− report.groups = run.createdIds.length;
223+ report.groups = createdIds.length;
329− report.left = tabs.length - run.grouped;
330− if (run.stopped) report.error = `${run.stopped.code}: ${run.stopped.message}`;
331− if (Object.keys(run.previous).length) s.lastOrganize = { at: rt.now(), previous: run.previous };
224+ if (Object.keys(previous).length) s.lastOrganize = { at: rt.now(), previous };
332 rt.commit();
225 rt.commit();
333 rt.refreshBadge();
226 rt.refreshBadge();
335 return report;
228 return report;
338−const toMember = (s: State, t: chrome.tabs.Tab): Member => ({
342− title: t.title ?? "",
344− description: s.tabs[t.id!]?.description,
345− lastActive: t.lastAccessed ?? 0,
348−/** Carry out a plan; returns the tabs whose move failed, which stay as they were. */
349export async function applyPlan(
231export async function applyPlan(
350 rt: Runtime,
232 rt: Runtime,
351 plan: Plan,
233 plan: Plan,
@@ -353,15 +235,11 @@ export async function applyPlan(
353 members: Member[],
235 members: Member[],
354 previous: Record<number, number>,
236 previous: Record<number, number>,
355 createdIds: number[],
237 createdIds: number[],
356−): Promise<Set<number>> {
238+): Promise<void> {
357 const settings = rt.settings();
239 const settings = rt.settings();
358 const byId = new Map(members.map((m) => [m.id, m]));
240 const byId = new Map(members.map((m) => [m.id, m]));
359− const failed = new Set<number>();
360 for (const j of plan.joins) {
241 for (const j of plan.joins) {
361− if (!(await addToGroup(rt, j.tabIds, j.groupId))) {
242+ if (!(await addToGroup(rt, j.tabIds, j.groupId))) continue;
362− for (const id of j.tabIds) failed.add(id);
365 for (const id of j.tabIds) previous[id] = -1;
243 for (const id of j.tabIds) previous[id] = -1;
366 const g = rt.state().groups[j.groupId];
244 const g = rt.state().groups[j.groupId];
@@ -382,10 +260,7 @@ export async function applyPlan(
382 lastNamedAt: named ? rt.now() : undefined,
260 lastNamedAt: named ? rt.now() : undefined,
383 dirty: false,
261 dirty: false,
385− if (groupId === undefined) {
263+ if (groupId === undefined) continue;
386− for (const id of c.tabIds) failed.add(id);
389 createdIds.push(groupId);
264 createdIds.push(groupId);
390 for (const id of c.tabIds) previous[id] = -1;
265 for (const id of c.tabIds) previous[id] = -1;
391 const g = rt.state().groups[groupId];
266 const g = rt.state().groups[groupId];
@@ -394,7 +269,6 @@ export async function applyPlan(
394 rt.naming.touch(groupId);
269 rt.naming.touch(groupId);
400/** Undo within the hour: every tab goes back to the group it was in (organize only takes loose tabs). */
274/** Undo within the hour: every tab goes back to the group it was in (organize only takes loose tabs). */
@@ -422,7 +296,7 @@ export async function undoOrganize(rt: Runtime): Promise<number> {
424/** What auto-organize remembers about a tab: it looks again only when the page or title changes. */
298/** What auto-organize remembers about a tab: it looks again only when the page or title changes. */
425−export const organizedKeyOf = (t: { url?: string; title?: string }): string => `${pathKey(t.url)}\n${titleKey(t.title)}`;
299+export const organizedKeyOf = (t: { url?: string; title?: string }): string => `${pathKey(t.url)}\n${t.title ?? ""}`;
427export const AUTO_RETRY_MS = 300_000;
301export const AUTO_RETRY_MS = 300_000;
428export const AUTO_CONTINUE_MS = 1_500;
302export const AUTO_CONTINUE_MS = 1_500;
@@ -498,27 +372,60 @@ export class AutoOrganizer {
498 if (pausedUntil && pausedUntil > rt.now()) return; // the host-retry ping sweeps again when it recovers
372 if (pausedUntil && pausedUntil > rt.now()) return; // the host-retry ping sweeps again when it recovers
499 const tabs = (await chrome.tabs.query({ windowId }).catch(() => [])).sort((a, b) => a.index - b.index);
373 const tabs = (await chrome.tabs.query({ windowId }).catch(() => [])).sort((a, b) => a.index - b.index);
500 const s = rt.state();
374 const s = rt.state();
501− // Still-loading tabs are skipped here; finishing the load touches the window again. Discarded tabs keep
375+ // Still-loading tabs are skipped here; finishing the load touches the window again.
502− // their title and address, so they're sorted like loaded ones.
503− const loose = tabs.filter((t) => {
376+ const loose = tabs.filter((t) => organizable(t) && t.status === "complete" && !s.tabs[t.id!]?.keepLoose);
504− const rec = s.tabs[t.id!];
505− return organizable(t) && settled(t) && !rec?.keepLoose && rec?.organizeRefused !== organizedKeyOf(t);
507 const fresh = loose.filter((t) => s.tabs[t.id!]?.organizedKey !== organizedKeyOf(t));
377 const fresh = loose.filter((t) => s.tabs[t.id!]?.organizedKey !== organizedKeyOf(t));
508 if (!fresh.length) return;
378 if (!fresh.length) return;
379+ const { ids: existingIds, list: existingGroups } = existingGroupsFor(s, windowId);
509− if (loose.length < 2 && !existingGroupsFor(s, windowId).ids.length) return; // one loose tab and nothing to join: wait for company
380+ if (loose.length < 2 && !existingIds.length) return; // one loose tab and nothing to join: wait for company
381+ const toMember = (t: chrome.tabs.Tab): Member => ({
385+ title: t.title ?? "",
387+ description: s.tabs[t.id!]?.description,
388+ lastActive: t.lastAccessed ?? 0,
510− const ordered = [...fresh, ...loose.filter((t) => !fresh.includes(t))].map((t) => toMember(s, t));
390+ const ordered = [...fresh, ...loose.filter((t) => !fresh.includes(t))].map(toMember);
511 const batch = makeBatches(ordered)[0];
391 const batch = makeBatches(ordered)[0];
512− const run = newRun(windowId, true);
392+ const maxGroups = maxGroupsFor(batch.length);
513− await sortPart(rt, batch, run);
393+ const payload: OrganizePayload = {
514− rt.commit();
394+ items: toItems(batch, settings),
515− if (run.stopped) {
395+ existingGroups,
396+ allowNew: batch.length >= 2,
398+ minGroupSize: settings.organizeMinGroupSize,
400+ let reply = await rt.host<OrganizeResult>("organize", payload);
401+ if (!reply.ok && reply.error.code === "OVER_BUDGET" && batch.length > 1) {
402+ // Rare with the budgeted batch; try once with half, the rest follows on the next run.
403+ const half = batch.slice(0, Math.ceil(batch.length / 2));
404+ payload.items = toItems(half, settings);
405+ payload.maxGroups = maxGroupsFor(half.length);
406+ payload.allowNew = half.length >= 2;
407+ batch.length = half.length;
408+ reply = await rt.host<OrganizeResult>("organize", payload);
410+ if (!reply.ok && reply.error.code === "BAD_MODEL_OUTPUT") reply = await rt.host<OrganizeResult>("organize", payload, { strict: true });
516− rt.log("auto-organize", run.stopped.code);
412+ rt.log("auto-organize", reply.error.code);
517 this.deps.scheduleFallback(rt.now() + AUTO_RETRY_MS);
413 this.deps.scheduleFallback(rt.now() + AUTO_RETRY_MS);
520− const sent = new Set(batch.map((m) => m.id));
416+ const batchIds = batch.map((m) => m.id);
417+ const plan = planFromResult(reply.result, batchIds, existingIds, settings.organizeMinGroupSize, payload.maxGroups, (ids) =>
418+ colorFor(batch.find((m) => m.id === ids[0])?.url ?? ""),
420+ await applyPlan(rt, plan, windowId, batch, {}, []);
421+ const live = rt.state();
422+ for (const m of batch) {
423+ const rec = live.tabs[m.id];
424+ if (rec) rec.organizedKey = organizedKeyOf(m);
427+ const remaining = fresh.filter((t) => !batchIds.includes(t.id!));
521− if (fresh.some((t) => !sent.has(t.id!))) this.touch(windowId, AUTO_CONTINUE_MS);
428+ if (remaining.length) this.touch(windowId, AUTO_CONTINUE_MS);