tabctl 0.5.3 → 0.6.0-alpha.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 +88 -20
- package/dist/extension/background.js +2 -0
- package/dist/extension/manifest.json +2 -2
- package/package.json +13 -5
- package/dist/cli/lib/args.js +0 -141
- package/dist/cli/lib/client.js +0 -83
- package/dist/cli/lib/commands/doctor.js +0 -134
- package/dist/cli/lib/commands/index.js +0 -51
- package/dist/cli/lib/commands/list.js +0 -159
- package/dist/cli/lib/commands/meta.js +0 -229
- package/dist/cli/lib/commands/params-groups.js +0 -48
- package/dist/cli/lib/commands/params-move.js +0 -44
- package/dist/cli/lib/commands/params.js +0 -314
- package/dist/cli/lib/commands/profile.js +0 -91
- package/dist/cli/lib/commands/setup.js +0 -294
- package/dist/cli/lib/constants.js +0 -30
- package/dist/cli/lib/help.js +0 -205
- package/dist/cli/lib/options-commands.js +0 -274
- package/dist/cli/lib/options-groups.js +0 -41
- package/dist/cli/lib/options.js +0 -125
- package/dist/cli/lib/output.js +0 -147
- package/dist/cli/lib/pagination.js +0 -55
- package/dist/cli/lib/policy-filter.js +0 -202
- package/dist/cli/lib/policy.js +0 -91
- package/dist/cli/lib/report.js +0 -61
- package/dist/cli/lib/response.js +0 -235
- package/dist/cli/lib/scope.js +0 -250
- package/dist/cli/lib/snapshot.js +0 -216
- package/dist/cli/lib/types.js +0 -2
- package/dist/cli/tabctl.js +0 -475
- package/dist/host/host.bundle.js +0 -670
- package/dist/host/host.js +0 -143
- package/dist/host/host.sh +0 -5
- package/dist/host/launcher/go.mod +0 -3
- package/dist/host/launcher/main.go +0 -109
- package/dist/host/lib/handlers.js +0 -327
- package/dist/host/lib/undo.js +0 -60
- package/dist/shared/config.js +0 -134
- package/dist/shared/extension-sync.js +0 -170
- package/dist/shared/profiles.js +0 -78
- package/dist/shared/version.js +0 -8
- package/dist/shared/wrapper-health.js +0 -132
package/dist/cli/lib/scope.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatCliArgValue = formatCliArgValue;
|
|
4
|
-
exports.buildScopeArgs = buildScopeArgs;
|
|
5
|
-
exports.resolveScopeFlags = resolveScopeFlags;
|
|
6
|
-
exports.extractScopeParams = extractScopeParams;
|
|
7
|
-
exports.selectTabsFromSnapshot = selectTabsFromSnapshot;
|
|
8
|
-
exports.resolveWindowIdFromSnapshot = resolveWindowIdFromSnapshot;
|
|
9
|
-
exports.filterGroupsByScope = filterGroupsByScope;
|
|
10
|
-
const output_1 = require("./output");
|
|
11
|
-
const snapshot_1 = require("./snapshot");
|
|
12
|
-
function formatCliArgValue(value) {
|
|
13
|
-
const raw = String(value);
|
|
14
|
-
if (!raw) {
|
|
15
|
-
return raw;
|
|
16
|
-
}
|
|
17
|
-
if (/[\s"]/g.test(raw)) {
|
|
18
|
-
const escaped = raw.replace(/"/g, '\\"');
|
|
19
|
-
return `"${escaped}"`;
|
|
20
|
-
}
|
|
21
|
-
return raw;
|
|
22
|
-
}
|
|
23
|
-
function buildScopeArgs(options, includeAll) {
|
|
24
|
-
const args = [];
|
|
25
|
-
if (includeAll) {
|
|
26
|
-
args.push("--all");
|
|
27
|
-
return args;
|
|
28
|
-
}
|
|
29
|
-
if (options.ungrouped === true) {
|
|
30
|
-
args.push("--ungrouped");
|
|
31
|
-
}
|
|
32
|
-
if (Array.isArray(options.tab)) {
|
|
33
|
-
for (const entry of options.tab) {
|
|
34
|
-
if (typeof entry === "string" && entry.trim()) {
|
|
35
|
-
args.push("--tab", formatCliArgValue(entry.trim()));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (typeof options.group === "string" && options.group.trim()) {
|
|
40
|
-
args.push("--group", formatCliArgValue(options.group.trim()));
|
|
41
|
-
}
|
|
42
|
-
if (options["group-id"] != null && options.ungrouped !== true) {
|
|
43
|
-
args.push("--group-id", formatCliArgValue(options["group-id"]));
|
|
44
|
-
}
|
|
45
|
-
if (options.window != null) {
|
|
46
|
-
const windowValue = normalizeWindowScope(options.window);
|
|
47
|
-
args.push("--window", formatCliArgValue(windowValue));
|
|
48
|
-
}
|
|
49
|
-
return args;
|
|
50
|
-
}
|
|
51
|
-
function resolveScopeFlags(options) {
|
|
52
|
-
const tabIds = Array.isArray(options.tab)
|
|
53
|
-
? options.tab.map(Number).filter(Number.isFinite)
|
|
54
|
-
: [];
|
|
55
|
-
const groupTitle = typeof options.group === "string" ? options.group.trim() : "";
|
|
56
|
-
const ungrouped = options.ungrouped === true;
|
|
57
|
-
const groupId = ungrouped ? -1 : (options["group-id"] != null ? Number(options["group-id"]) : null);
|
|
58
|
-
const normalizedWindow = options.window != null ? normalizeWindowScope(options.window) : null;
|
|
59
|
-
const windowId = normalizedWindow == null
|
|
60
|
-
? null
|
|
61
|
-
: normalizedWindow;
|
|
62
|
-
if (options["group-id"] != null && !Number.isFinite(groupId)) {
|
|
63
|
-
(0, output_1.errorOut)("Invalid --group-id value");
|
|
64
|
-
}
|
|
65
|
-
if (ungrouped && options["group-id"] != null) {
|
|
66
|
-
(0, output_1.errorOut)("--ungrouped cannot be combined with --group-id");
|
|
67
|
-
}
|
|
68
|
-
if (options.window != null && typeof windowId === "number" && !Number.isFinite(windowId)) {
|
|
69
|
-
(0, output_1.errorOut)("Invalid --window value");
|
|
70
|
-
}
|
|
71
|
-
const hasScope = tabIds.length > 0
|
|
72
|
-
|| Boolean(groupTitle)
|
|
73
|
-
|| Number.isFinite(groupId)
|
|
74
|
-
|| (typeof windowId === "number" && Number.isFinite(windowId))
|
|
75
|
-
|| (typeof windowId === "string" && windowId.length > 0);
|
|
76
|
-
return { tabIds, groupTitle, groupId, windowId, hasScope, ungrouped };
|
|
77
|
-
}
|
|
78
|
-
function normalizeWindowScope(value) {
|
|
79
|
-
if (typeof value === "string") {
|
|
80
|
-
const trimmed = value.trim().toLowerCase();
|
|
81
|
-
if (trimmed === "active") {
|
|
82
|
-
return "active";
|
|
83
|
-
}
|
|
84
|
-
if (trimmed === "last-focused" || trimmed === "lastfocused") {
|
|
85
|
-
return "last-focused";
|
|
86
|
-
}
|
|
87
|
-
if (trimmed === "new") {
|
|
88
|
-
(0, output_1.errorOut)("--window new is only supported by open");
|
|
89
|
-
}
|
|
90
|
-
const numeric = Number(trimmed);
|
|
91
|
-
if (Number.isFinite(numeric)) {
|
|
92
|
-
return numeric;
|
|
93
|
-
}
|
|
94
|
-
(0, output_1.errorOut)("Invalid --window value");
|
|
95
|
-
}
|
|
96
|
-
return typeof value === "number" ? value : String(value);
|
|
97
|
-
}
|
|
98
|
-
function extractScopeParams(options) {
|
|
99
|
-
const scope = resolveScopeFlags(options);
|
|
100
|
-
return {
|
|
101
|
-
tabIds: scope.tabIds.length ? scope.tabIds : undefined,
|
|
102
|
-
groupTitle: scope.groupTitle || undefined,
|
|
103
|
-
groupId: scope.groupId != null ? scope.groupId : undefined,
|
|
104
|
-
windowId: scope.windowId != null ? scope.windowId : undefined,
|
|
105
|
-
all: options.all === true,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function selectTabsFromSnapshot(snapshot, params) {
|
|
109
|
-
const windows = snapshot.windows || [];
|
|
110
|
-
const allTabs = windows.flatMap((win) => win.tabs || []);
|
|
111
|
-
if (params.tabIds && params.tabIds.length) {
|
|
112
|
-
const idSet = new Set(params.tabIds.map(Number));
|
|
113
|
-
return { tabs: allTabs.filter((tab) => idSet.has(tab.tabId)) };
|
|
114
|
-
}
|
|
115
|
-
if (params.groupId != null) {
|
|
116
|
-
const groupId = Number(params.groupId);
|
|
117
|
-
return { tabs: allTabs.filter((tab) => tab.groupId === groupId) };
|
|
118
|
-
}
|
|
119
|
-
if (params.groupTitle) {
|
|
120
|
-
const windowLabels = (0, snapshot_1.buildWindowLabelIndex)(snapshot);
|
|
121
|
-
const matches = [];
|
|
122
|
-
for (const win of windows) {
|
|
123
|
-
const groups = win.groups || [];
|
|
124
|
-
for (const group of groups) {
|
|
125
|
-
if (group.title === params.groupTitle) {
|
|
126
|
-
matches.push({
|
|
127
|
-
windowId: win.windowId,
|
|
128
|
-
windowLabel: windowLabels.get(win.windowId) ?? null,
|
|
129
|
-
groupId: group.groupId,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
const availableGroups = (0, snapshot_1.listGroupSummaries)(snapshot, windowLabels);
|
|
135
|
-
if (matches.length === 0) {
|
|
136
|
-
return {
|
|
137
|
-
tabs: [],
|
|
138
|
-
error: {
|
|
139
|
-
message: "No matching group title found",
|
|
140
|
-
hint: "Use tabctl group-list to see existing groups.",
|
|
141
|
-
availableGroups,
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
if (matches.length > 1 && !params.windowId) {
|
|
146
|
-
return {
|
|
147
|
-
tabs: [],
|
|
148
|
-
error: {
|
|
149
|
-
message: "Group title is ambiguous. Provide a windowId.",
|
|
150
|
-
hint: "Use --window to disambiguate group titles.",
|
|
151
|
-
matches,
|
|
152
|
-
availableGroups,
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
const resolvedWindowId = params.windowId != null
|
|
157
|
-
? resolveWindowIdFromSnapshot(snapshot, params.windowId)
|
|
158
|
-
: null;
|
|
159
|
-
const target = resolvedWindowId != null
|
|
160
|
-
? matches.find((match) => match.windowId === resolvedWindowId)
|
|
161
|
-
: matches[0];
|
|
162
|
-
if (!target) {
|
|
163
|
-
return {
|
|
164
|
-
tabs: [],
|
|
165
|
-
error: {
|
|
166
|
-
message: "Group title not found in specified window",
|
|
167
|
-
hint: "Use tabctl group-list to see existing groups.",
|
|
168
|
-
matches,
|
|
169
|
-
availableGroups,
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
return { tabs: allTabs.filter((tab) => tab.groupId === target.groupId && tab.windowId === target.windowId) };
|
|
174
|
-
}
|
|
175
|
-
if (params.windowId != null) {
|
|
176
|
-
const windowId = resolveWindowIdFromSnapshot(snapshot, params.windowId);
|
|
177
|
-
if (!Number.isFinite(windowId)) {
|
|
178
|
-
return { tabs: [] };
|
|
179
|
-
}
|
|
180
|
-
return { tabs: allTabs.filter((tab) => tab.windowId === windowId) };
|
|
181
|
-
}
|
|
182
|
-
if (params.all) {
|
|
183
|
-
return { tabs: allTabs };
|
|
184
|
-
}
|
|
185
|
-
const focused = windows.find((win) => win.focused);
|
|
186
|
-
return { tabs: focused ? (focused.tabs || []) : [] };
|
|
187
|
-
}
|
|
188
|
-
function resolveWindowIdFromSnapshot(snapshot, value) {
|
|
189
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
190
|
-
return value;
|
|
191
|
-
}
|
|
192
|
-
const windows = snapshot.windows || [];
|
|
193
|
-
if (typeof value === "string") {
|
|
194
|
-
const normalized = value.trim().toLowerCase();
|
|
195
|
-
if (normalized === "active") {
|
|
196
|
-
const focused = windows.find((win) => win.focused === true);
|
|
197
|
-
return typeof focused?.windowId === "number" ? focused.windowId : null;
|
|
198
|
-
}
|
|
199
|
-
if (normalized === "last-focused") {
|
|
200
|
-
let bestWindowId = null;
|
|
201
|
-
let bestFocusedAt = -Infinity;
|
|
202
|
-
for (const win of windows) {
|
|
203
|
-
const tabs = win.tabs || [];
|
|
204
|
-
for (const tab of tabs) {
|
|
205
|
-
const focusedAt = Number(tab.lastFocusedAt);
|
|
206
|
-
if (!Number.isFinite(focusedAt)) {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
if (focusedAt > bestFocusedAt) {
|
|
210
|
-
bestFocusedAt = focusedAt;
|
|
211
|
-
bestWindowId = typeof win.windowId === "number" ? win.windowId : null;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return bestWindowId;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return Number.isFinite(Number(value)) ? Number(value) : null;
|
|
219
|
-
}
|
|
220
|
-
function filterGroupsByScope(groups, scope, snapshot, buildTabIndex) {
|
|
221
|
-
let filtered = groups;
|
|
222
|
-
const allScope = !scope.hasScope;
|
|
223
|
-
if (!allScope) {
|
|
224
|
-
if (typeof scope.windowId === "number" && Number.isFinite(scope.windowId)) {
|
|
225
|
-
filtered = filtered.filter((group) => group.windowId === scope.windowId);
|
|
226
|
-
}
|
|
227
|
-
if (Number.isFinite(scope.groupId)) {
|
|
228
|
-
filtered = filtered.filter((group) => group.groupId === scope.groupId);
|
|
229
|
-
}
|
|
230
|
-
if (scope.groupTitle) {
|
|
231
|
-
filtered = filtered.filter((group) => group.title === scope.groupTitle);
|
|
232
|
-
}
|
|
233
|
-
if (scope.tabIds.length > 0 && snapshot) {
|
|
234
|
-
const tabIndex = buildTabIndex(snapshot);
|
|
235
|
-
const groupIds = new Set();
|
|
236
|
-
for (const tabId of scope.tabIds) {
|
|
237
|
-
const tab = tabIndex.get(tabId);
|
|
238
|
-
if (!tab) {
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
const groupId = tab.groupId;
|
|
242
|
-
if (Number.isFinite(groupId) && groupId !== -1) {
|
|
243
|
-
groupIds.add(groupId);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
filtered = filtered.filter((group) => groupIds.has(group.groupId));
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return filtered;
|
|
250
|
-
}
|
package/dist/cli/lib/snapshot.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildTabIndex = buildTabIndex;
|
|
4
|
-
exports.buildWindowTitleIndex = buildWindowTitleIndex;
|
|
5
|
-
exports.buildWindowLabelIndex = buildWindowLabelIndex;
|
|
6
|
-
exports.buildGroupsFromSnapshot = buildGroupsFromSnapshot;
|
|
7
|
-
exports.listGroupSummaries = listGroupSummaries;
|
|
8
|
-
exports.compareTabIndex = compareTabIndex;
|
|
9
|
-
exports.orderTabs = orderTabs;
|
|
10
|
-
exports.buildPagedSnapshot = buildPagedSnapshot;
|
|
11
|
-
exports.filterSnapshotByPolicy = filterSnapshotByPolicy;
|
|
12
|
-
const policy_1 = require("./policy");
|
|
13
|
-
function buildTabIndex(snapshot) {
|
|
14
|
-
const tabIndex = new Map();
|
|
15
|
-
const windows = snapshot.windows || [];
|
|
16
|
-
for (const window of windows) {
|
|
17
|
-
const tabs = window.tabs || [];
|
|
18
|
-
for (const tab of tabs) {
|
|
19
|
-
if (typeof tab.tabId === "number") {
|
|
20
|
-
tabIndex.set(tab.tabId, tab);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return tabIndex;
|
|
25
|
-
}
|
|
26
|
-
function buildWindowTitleIndex(snapshot, policy) {
|
|
27
|
-
const windowTitleIndex = new Map();
|
|
28
|
-
const windows = snapshot.windows || [];
|
|
29
|
-
for (const window of windows) {
|
|
30
|
-
const windowId = window.windowId;
|
|
31
|
-
if (typeof windowId !== "number") {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
const tabs = window.tabs || [];
|
|
35
|
-
const activeTab = tabs.find((tab) => tab.active === true);
|
|
36
|
-
if (!activeTab) {
|
|
37
|
-
windowTitleIndex.set(windowId, null);
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const { eligible } = (0, policy_1.evaluateTab)(activeTab, policy);
|
|
41
|
-
if (!eligible) {
|
|
42
|
-
windowTitleIndex.set(windowId, null);
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
const title = typeof activeTab.title === "string" ? activeTab.title : null;
|
|
46
|
-
windowTitleIndex.set(windowId, title);
|
|
47
|
-
}
|
|
48
|
-
return windowTitleIndex;
|
|
49
|
-
}
|
|
50
|
-
function buildWindowLabelIndex(snapshot) {
|
|
51
|
-
const windowLabels = new Map();
|
|
52
|
-
const windows = snapshot.windows || [];
|
|
53
|
-
windows.forEach((win, index) => {
|
|
54
|
-
const windowId = win.windowId;
|
|
55
|
-
if (typeof windowId === "number") {
|
|
56
|
-
windowLabels.set(windowId, `W${index + 1}`);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
return windowLabels;
|
|
60
|
-
}
|
|
61
|
-
function buildGroupsFromSnapshot(snapshot, windowId) {
|
|
62
|
-
const windows = snapshot.windows || [];
|
|
63
|
-
const windowLabels = buildWindowLabelIndex(snapshot);
|
|
64
|
-
const groups = [];
|
|
65
|
-
for (const win of windows) {
|
|
66
|
-
const winId = win.windowId;
|
|
67
|
-
if (!Number.isFinite(winId)) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (Number.isFinite(windowId) && winId !== windowId) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const counts = new Map();
|
|
74
|
-
const tabs = win.tabs || [];
|
|
75
|
-
for (const tab of tabs) {
|
|
76
|
-
const groupId = tab.groupId;
|
|
77
|
-
if (typeof groupId === "number" && groupId !== -1) {
|
|
78
|
-
counts.set(groupId, (counts.get(groupId) || 0) + 1);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const windowGroups = win.groups || [];
|
|
82
|
-
for (const group of windowGroups) {
|
|
83
|
-
const groupId = group.groupId;
|
|
84
|
-
if (!Number.isFinite(groupId)) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
groups.push({
|
|
88
|
-
windowId: winId,
|
|
89
|
-
windowLabel: windowLabels.get(winId) ?? null,
|
|
90
|
-
groupId,
|
|
91
|
-
title: group.title ?? null,
|
|
92
|
-
color: group.color ?? null,
|
|
93
|
-
collapsed: group.collapsed ?? null,
|
|
94
|
-
tabCount: counts.get(groupId) || 0,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return groups;
|
|
99
|
-
}
|
|
100
|
-
function listGroupSummaries(snapshot, windowLabels) {
|
|
101
|
-
const windows = snapshot.windows || [];
|
|
102
|
-
const summaries = [];
|
|
103
|
-
for (const win of windows) {
|
|
104
|
-
const groups = win.groups || [];
|
|
105
|
-
for (const group of groups) {
|
|
106
|
-
summaries.push({
|
|
107
|
-
windowId: win.windowId,
|
|
108
|
-
windowLabel: windowLabels.get(win.windowId) ?? null,
|
|
109
|
-
groupId: group.groupId,
|
|
110
|
-
title: typeof group.title === "string" ? group.title : null,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return summaries;
|
|
115
|
-
}
|
|
116
|
-
function compareTabIndex(a, b) {
|
|
117
|
-
const aIndex = Number(a.index);
|
|
118
|
-
const bIndex = Number(b.index);
|
|
119
|
-
if (!Number.isFinite(aIndex) && !Number.isFinite(bIndex)) {
|
|
120
|
-
return 0;
|
|
121
|
-
}
|
|
122
|
-
if (!Number.isFinite(aIndex)) {
|
|
123
|
-
return 1;
|
|
124
|
-
}
|
|
125
|
-
if (!Number.isFinite(bIndex)) {
|
|
126
|
-
return -1;
|
|
127
|
-
}
|
|
128
|
-
if (aIndex === bIndex) {
|
|
129
|
-
const aId = Number(a.tabId);
|
|
130
|
-
const bId = Number(b.tabId);
|
|
131
|
-
if (Number.isFinite(aId) && Number.isFinite(bId)) {
|
|
132
|
-
return aId - bId;
|
|
133
|
-
}
|
|
134
|
-
return 0;
|
|
135
|
-
}
|
|
136
|
-
return aIndex - bIndex;
|
|
137
|
-
}
|
|
138
|
-
function orderTabs(snapshot, tabFilter) {
|
|
139
|
-
const windows = snapshot.windows || [];
|
|
140
|
-
const ordered = [];
|
|
141
|
-
for (const win of windows) {
|
|
142
|
-
const tabs = (win.tabs || []).slice().sort(compareTabIndex);
|
|
143
|
-
for (const tab of tabs) {
|
|
144
|
-
const tabId = tab.tabId;
|
|
145
|
-
if (!tabFilter || tabFilter.has(tabId)) {
|
|
146
|
-
ordered.push(tab);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return ordered;
|
|
151
|
-
}
|
|
152
|
-
function buildPagedSnapshot(snapshot, tabs) {
|
|
153
|
-
const tabsByWindow = new Map();
|
|
154
|
-
const groupsByWindow = new Map();
|
|
155
|
-
for (const tab of tabs) {
|
|
156
|
-
const windowId = tab.windowId;
|
|
157
|
-
if (!Number.isFinite(windowId)) {
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (!tabsByWindow.has(windowId)) {
|
|
161
|
-
tabsByWindow.set(windowId, []);
|
|
162
|
-
groupsByWindow.set(windowId, new Set());
|
|
163
|
-
}
|
|
164
|
-
tabsByWindow.get(windowId)?.push(tab);
|
|
165
|
-
const groupId = tab.groupId;
|
|
166
|
-
if (Number.isFinite(groupId) && groupId !== -1) {
|
|
167
|
-
groupsByWindow.get(windowId)?.add(groupId);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const windows = snapshot.windows || [];
|
|
171
|
-
const pagedWindows = [];
|
|
172
|
-
for (const win of windows) {
|
|
173
|
-
const windowId = win.windowId;
|
|
174
|
-
const windowTabs = tabsByWindow.get(windowId) || [];
|
|
175
|
-
if (windowTabs.length === 0) {
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
const allowedGroupIds = groupsByWindow.get(windowId) || new Set();
|
|
179
|
-
const groups = (win.groups || []).filter((group) => allowedGroupIds.has(group.groupId));
|
|
180
|
-
pagedWindows.push({
|
|
181
|
-
...win,
|
|
182
|
-
tabs: windowTabs,
|
|
183
|
-
groups,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
...snapshot,
|
|
188
|
-
windows: pagedWindows,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function filterSnapshotByPolicy(snapshot, policy) {
|
|
192
|
-
if (!policy) {
|
|
193
|
-
return snapshot;
|
|
194
|
-
}
|
|
195
|
-
const windows = snapshot.windows || [];
|
|
196
|
-
const filteredWindows = windows.map((win) => {
|
|
197
|
-
const tabs = win.tabs || [];
|
|
198
|
-
const eligibleTabs = tabs
|
|
199
|
-
.filter((tab) => (0, policy_1.evaluateTab)(tab, policy).eligible)
|
|
200
|
-
.map((tab) => (0, policy_1.annotateEntry)(tab, policy));
|
|
201
|
-
const eligibleGroupIds = new Set(eligibleTabs
|
|
202
|
-
.map((tab) => tab.groupId)
|
|
203
|
-
.filter((groupId) => typeof groupId === "number" && groupId !== -1));
|
|
204
|
-
const groups = win.groups || [];
|
|
205
|
-
const filteredGroups = groups.filter((group) => eligibleGroupIds.has(group.groupId));
|
|
206
|
-
return {
|
|
207
|
-
...win,
|
|
208
|
-
tabs: eligibleTabs,
|
|
209
|
-
groups: filteredGroups,
|
|
210
|
-
};
|
|
211
|
-
}).filter((win) => win.tabs.length > 0);
|
|
212
|
-
return {
|
|
213
|
-
...snapshot,
|
|
214
|
-
windows: filteredWindows,
|
|
215
|
-
};
|
|
216
|
-
}
|
package/dist/cli/lib/types.js
DELETED