howtocode 0.7.61 → 0.7.63
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/dist/assets/LICENSE.txt +23 -0
- package/dist/assets/background.js.txt +468 -0
- package/dist/assets/manifest.json.txt +17 -0
- package/dist/assets/options.html.txt +53 -0
- package/dist/assets/options.js.txt +23 -0
- package/dist/{chunk-YDG6RVDE.js → chunk-7BEPRCLQ.js} +1 -1
- package/dist/chunk-7LAMZWB5.js +1 -0
- package/dist/{chunk-VOZ3J75B.js → chunk-AFDG4PTM.js} +1 -1
- package/dist/{chunk-ACBAN4MH.js → chunk-AYFFSBLE.js} +1 -1
- package/dist/{chunk-WI4YX3JJ.js → chunk-HUWX3NJL.js} +1 -1
- package/dist/{chunk-7JGPX5FL.js → chunk-LXH2ZY6E.js} +1 -1
- package/dist/{chunk-YGC4JVGS.js → chunk-MR6XQ4CA.js} +1 -1
- package/dist/chunk-SVONBXW3.js +3 -0
- package/dist/{chunk-JOWLG77G.js → chunk-SXUB7264.js} +1 -1
- package/dist/{chunk-2CPF7Q35.js → chunk-TU7FNJZL.js} +1 -1
- package/dist/{chunk-5HEL5PJ5.js → chunk-U3T2AS5G.js} +1 -1
- package/dist/{chunk-TREP2ZKD.js → chunk-VFOUA2PJ.js} +1 -1
- package/dist/{chunk-3SMUSANK.js → chunk-WK663ZV5.js} +1 -1
- package/dist/{chunk-HQVNWGN7.js → chunk-X3KLM35N.js} +1 -1
- package/dist/{chunk-L27DI5LJ.js → chunk-Y2MUWQ6M.js} +50 -50
- package/dist/main.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-PVFHAKN6.js +0 -1
- package/dist/chunk-YNMLRZJK.js +0 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mario Zechner
|
|
4
|
+
Copyright (c) 2025-2026 Can Bölük
|
|
5
|
+
Copyright (c) 2026 Stencil Labs, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
// packages/coding-agent/src/tools/browser/relay/protocol.ts
|
|
2
|
+
var EXTENSION_RELOAD_PROTOCOL_VERSION = 1;
|
|
3
|
+
var FOREIGN_FRAME_REFUSAL = /chrome-extension:\/\/ URL of different extension/i;
|
|
4
|
+
var DOWNLOADS_PROTOCOL_VERSION = 1;
|
|
5
|
+
|
|
6
|
+
// packages/browser-relay/extension/debugger-ownership.ts
|
|
7
|
+
async function ownedDebuggerTabs(targets, probe) {
|
|
8
|
+
const owned = await Promise.all(targets.map(async (target) => {
|
|
9
|
+
if (!target.attached || target.tabId === undefined)
|
|
10
|
+
return;
|
|
11
|
+
try {
|
|
12
|
+
await probe(target.tabId);
|
|
13
|
+
return target.tabId;
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
return owned.filter((tabId) => tabId !== undefined);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// packages/browser-relay/extension/download-pairing.ts
|
|
22
|
+
var DOWNLOAD_PAIRING_MS = 5000;
|
|
23
|
+
var DOWNLOAD_LOOKUP_MS = 60000;
|
|
24
|
+
|
|
25
|
+
class DownloadPairing {
|
|
26
|
+
#now;
|
|
27
|
+
#pairs = new Map;
|
|
28
|
+
#reports = [];
|
|
29
|
+
constructor(now = Date.now) {
|
|
30
|
+
this.#now = now;
|
|
31
|
+
}
|
|
32
|
+
report(guid, url) {
|
|
33
|
+
if (this.#pairs.has(guid) || this.#reports.some((report) => report.guid === guid))
|
|
34
|
+
return;
|
|
35
|
+
this.#dropAgedReports();
|
|
36
|
+
this.#reports.push({ guid, url, at: this.#now() });
|
|
37
|
+
}
|
|
38
|
+
created(id, url) {
|
|
39
|
+
this.#dropAgedReports();
|
|
40
|
+
const index = this.#reports.findIndex((report) => report.url === url);
|
|
41
|
+
if (index < 0)
|
|
42
|
+
return;
|
|
43
|
+
this.#pairs.set(this.#reports[index].guid, { id });
|
|
44
|
+
this.#reports.splice(index, 1);
|
|
45
|
+
}
|
|
46
|
+
#dropAgedReports() {
|
|
47
|
+
const oldest = this.#now() - DOWNLOAD_PAIRING_MS;
|
|
48
|
+
while (this.#reports.length > 0 && this.#reports[0].at < oldest)
|
|
49
|
+
this.#reports.shift();
|
|
50
|
+
}
|
|
51
|
+
finished(id, state) {
|
|
52
|
+
const now = this.#now();
|
|
53
|
+
for (const [guid, pair] of this.#pairs) {
|
|
54
|
+
if (pair.id === id) {
|
|
55
|
+
if (state === "interrupted")
|
|
56
|
+
this.#pairs.delete(guid);
|
|
57
|
+
else
|
|
58
|
+
pair.completedAt = now;
|
|
59
|
+
} else if (pair.completedAt !== undefined && pair.completedAt < now - DOWNLOAD_LOOKUP_MS) {
|
|
60
|
+
this.#pairs.delete(guid);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
idFor(guid) {
|
|
65
|
+
return this.#pairs.get(guid)?.id;
|
|
66
|
+
}
|
|
67
|
+
forget(guid) {
|
|
68
|
+
this.#pairs.delete(guid);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// packages/browser-relay/extension/foreign-frames.ts
|
|
73
|
+
var RETRY_DELAYS_MS = [50, 100, 200, 400];
|
|
74
|
+
var sweeps = new Map;
|
|
75
|
+
async function pastForeignFrames(tabId, request) {
|
|
76
|
+
for (let attempt = 0;; attempt++) {
|
|
77
|
+
try {
|
|
78
|
+
return await request();
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (attempt === RETRY_DELAYS_MS.length || !FOREIGN_FRAME_REFUSAL.test(String(error)) || await sweep(tabId) === 0)
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
84
|
+
setTimeout(resolve, RETRY_DELAYS_MS[attempt]);
|
|
85
|
+
await promise;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function sweep(tabId) {
|
|
89
|
+
let pending = sweeps.get(tabId);
|
|
90
|
+
if (!pending) {
|
|
91
|
+
pending = neutralizeForeignFrames(tabId).finally(() => sweeps.delete(tabId));
|
|
92
|
+
sweeps.set(tabId, pending);
|
|
93
|
+
}
|
|
94
|
+
return pending;
|
|
95
|
+
}
|
|
96
|
+
async function neutralizeForeignFrames(tabId) {
|
|
97
|
+
try {
|
|
98
|
+
const results = await chrome.scripting.executeScript({
|
|
99
|
+
target: { tabId, allFrames: true },
|
|
100
|
+
injectImmediately: true,
|
|
101
|
+
args: [chrome.runtime.id],
|
|
102
|
+
func: (self) => {
|
|
103
|
+
let found = 0;
|
|
104
|
+
const visit = (root) => {
|
|
105
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
|
|
106
|
+
for (let element = walker.nextNode();element; element = walker.nextNode()) {
|
|
107
|
+
const tag = element.tagName.toUpperCase();
|
|
108
|
+
if (tag === "IFRAME" || tag === "FRAME") {
|
|
109
|
+
const src = element.getAttribute("src") ?? "";
|
|
110
|
+
if (src.startsWith("chrome-extension://") && !src.startsWith(`chrome-extension://${self}/`)) {
|
|
111
|
+
if (tag === "FRAME")
|
|
112
|
+
element.setAttribute("src", "about:blank");
|
|
113
|
+
else if (element.getAttribute("srcdoc") === null)
|
|
114
|
+
element.setAttribute("srcdoc", "");
|
|
115
|
+
element.style.setProperty("display", "none", "important");
|
|
116
|
+
found++;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const shadow = chrome.dom.openOrClosedShadowRoot(element);
|
|
120
|
+
if (shadow)
|
|
121
|
+
visit(shadow);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
visit(document);
|
|
125
|
+
return found;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return results.reduce((total, frame) => total + (frame.result ?? 0), 0);
|
|
129
|
+
} catch {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// packages/browser-relay/extension/background.ts
|
|
135
|
+
var DEFAULT_PORT = 9224;
|
|
136
|
+
var PING_INTERVAL_MS = 20000;
|
|
137
|
+
var RECONNECT_MIN_MS = 1000;
|
|
138
|
+
var RECONNECT_MAX_MS = 1e4;
|
|
139
|
+
var REMOVE_TAB_ATTEMPTS = 3;
|
|
140
|
+
var REMOVE_TAB_RETRY_MS = 500;
|
|
141
|
+
var ws = null;
|
|
142
|
+
var reconnectDelay = RECONNECT_MIN_MS;
|
|
143
|
+
var pingTimer = null;
|
|
144
|
+
var relayInitiatedDetachTabs = new Set;
|
|
145
|
+
var instanceId = null;
|
|
146
|
+
async function ensureInstanceId() {
|
|
147
|
+
if (instanceId)
|
|
148
|
+
return instanceId;
|
|
149
|
+
const key = "relayInstanceId";
|
|
150
|
+
const stored = await chrome.storage.local.get({ [key]: "" });
|
|
151
|
+
const existing = stored[key];
|
|
152
|
+
instanceId = typeof existing === "string" && existing.length > 0 ? existing : crypto.randomUUID();
|
|
153
|
+
await chrome.storage.local.set({ [key]: instanceId });
|
|
154
|
+
return instanceId;
|
|
155
|
+
}
|
|
156
|
+
var browserSession = null;
|
|
157
|
+
function ensureBrowserSession() {
|
|
158
|
+
browserSession ??= (async () => {
|
|
159
|
+
const key = "relayBrowserSession";
|
|
160
|
+
const stored = await chrome.storage.session.get({ [key]: "" });
|
|
161
|
+
const existing = stored[key];
|
|
162
|
+
if (typeof existing === "string" && existing.length > 0)
|
|
163
|
+
return existing;
|
|
164
|
+
const created = crypto.randomUUID();
|
|
165
|
+
await chrome.storage.session.set({ [key]: created });
|
|
166
|
+
return created;
|
|
167
|
+
})();
|
|
168
|
+
return browserSession;
|
|
169
|
+
}
|
|
170
|
+
async function loadSettings() {
|
|
171
|
+
const stored = await chrome.storage.local.get({ port: DEFAULT_PORT, token: "" });
|
|
172
|
+
const port = Number(stored.port);
|
|
173
|
+
return {
|
|
174
|
+
port: Number.isInteger(port) && port > 0 && port <= 65535 ? port : DEFAULT_PORT,
|
|
175
|
+
token: typeof stored.token === "string" ? stored.token : ""
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function snapshot(tab) {
|
|
179
|
+
if (tab.id === undefined)
|
|
180
|
+
return null;
|
|
181
|
+
return {
|
|
182
|
+
tabId: tab.id,
|
|
183
|
+
url: tab.url ?? tab.pendingUrl ?? "",
|
|
184
|
+
title: tab.title ?? "",
|
|
185
|
+
active: tab.active,
|
|
186
|
+
discarded: tab.discarded === true,
|
|
187
|
+
windowId: tab.windowId,
|
|
188
|
+
pinned: tab.pinned,
|
|
189
|
+
groupId: tab.groupId
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
var ompGroupTitle = null;
|
|
193
|
+
var groupOps = Promise.resolve();
|
|
194
|
+
function enqueueGroupOp(fn) {
|
|
195
|
+
const result = groupOps.then(fn, fn);
|
|
196
|
+
groupOps = result.catch(() => {});
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
async function groupTabs(tabIds, title, color) {
|
|
200
|
+
ompGroupTitle = title;
|
|
201
|
+
chrome.storage.session.set({ ompGroupTitle: title });
|
|
202
|
+
const byWindow = new Map;
|
|
203
|
+
for (const tabId of tabIds) {
|
|
204
|
+
try {
|
|
205
|
+
const tab = await chrome.tabs.get(tabId);
|
|
206
|
+
if (tab.pinned || tab.id === undefined)
|
|
207
|
+
continue;
|
|
208
|
+
const bucket = byWindow.get(tab.windowId) ?? [];
|
|
209
|
+
bucket.push(tab.id);
|
|
210
|
+
byWindow.set(tab.windowId, bucket);
|
|
211
|
+
} catch {}
|
|
212
|
+
}
|
|
213
|
+
const grouped = {};
|
|
214
|
+
for (const [windowId, ids] of byWindow) {
|
|
215
|
+
const existing = await chrome.tabGroups.query({ title, windowId });
|
|
216
|
+
let groupId;
|
|
217
|
+
if (existing[0]) {
|
|
218
|
+
groupId = existing[0].id;
|
|
219
|
+
for (const dupe of existing.slice(1)) {
|
|
220
|
+
const dupeTabs = await chrome.tabs.query({ groupId: dupe.id });
|
|
221
|
+
const dupeIds = dupeTabs.map((tab) => tab.id).filter((id) => id !== undefined);
|
|
222
|
+
if (dupeIds.length > 0)
|
|
223
|
+
await chrome.tabs.group({ tabIds: dupeIds, groupId });
|
|
224
|
+
}
|
|
225
|
+
await chrome.tabs.group({ tabIds: ids, groupId });
|
|
226
|
+
} else {
|
|
227
|
+
groupId = await chrome.tabs.group({ tabIds: ids });
|
|
228
|
+
}
|
|
229
|
+
await chrome.tabGroups.update(groupId, { title, color });
|
|
230
|
+
for (const id of ids)
|
|
231
|
+
grouped[String(id)] = groupId;
|
|
232
|
+
}
|
|
233
|
+
return { grouped };
|
|
234
|
+
}
|
|
235
|
+
async function restoreGroups() {
|
|
236
|
+
if (!ompGroupTitle) {
|
|
237
|
+
const stored = await chrome.storage.session.get({ ompGroupTitle: "" }).catch(() => ({ ompGroupTitle: "" }));
|
|
238
|
+
ompGroupTitle = typeof stored.ompGroupTitle === "string" && stored.ompGroupTitle ? stored.ompGroupTitle : null;
|
|
239
|
+
}
|
|
240
|
+
if (!ompGroupTitle)
|
|
241
|
+
return;
|
|
242
|
+
const groups = await chrome.tabGroups.query({ title: ompGroupTitle }).catch(() => []);
|
|
243
|
+
for (const group of groups) {
|
|
244
|
+
const tabs = await chrome.tabs.query({ groupId: group.id }).catch(() => []);
|
|
245
|
+
const ids = tabs.map((tab) => tab.id).filter((id) => id !== undefined);
|
|
246
|
+
if (ids.length > 0)
|
|
247
|
+
await chrome.tabs.ungroup(ids).catch(() => {});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function post(msg) {
|
|
251
|
+
if (ws?.readyState === WebSocket.OPEN)
|
|
252
|
+
ws.send(JSON.stringify(msg));
|
|
253
|
+
}
|
|
254
|
+
async function removeTab(tabId) {
|
|
255
|
+
for (let attempt = 1;; attempt++) {
|
|
256
|
+
try {
|
|
257
|
+
await chrome.tabs.remove(tabId);
|
|
258
|
+
return;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (/No tab with id/.test(String(error)))
|
|
261
|
+
return;
|
|
262
|
+
if (attempt >= REMOVE_TAB_ATTEMPTS)
|
|
263
|
+
throw error;
|
|
264
|
+
const pause = Promise.withResolvers();
|
|
265
|
+
setTimeout(pause.resolve, REMOVE_TAB_RETRY_MS);
|
|
266
|
+
await pause.promise;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async function setBadge(connected) {
|
|
271
|
+
try {
|
|
272
|
+
await chrome.action.setBadgeText({ text: connected ? "on" : "off" });
|
|
273
|
+
await chrome.action.setBadgeBackgroundColor({ color: connected ? "#1a7f37" : "#8b8b8b" });
|
|
274
|
+
} catch {}
|
|
275
|
+
}
|
|
276
|
+
async function buildHello() {
|
|
277
|
+
const [tabs, targets] = await Promise.all([chrome.tabs.query({}), chrome.debugger.getTargets()]);
|
|
278
|
+
const snapshots = [];
|
|
279
|
+
for (const tab of tabs) {
|
|
280
|
+
const snap = snapshot(tab);
|
|
281
|
+
if (snap)
|
|
282
|
+
snapshots.push(snap);
|
|
283
|
+
}
|
|
284
|
+
const attachedTabIds = await ownedDebuggerTabs(targets, (tabId) => chrome.debugger.sendCommand({ tabId }, "Target.getTargetInfo"));
|
|
285
|
+
const versionMatch = /Chrome\/[\d.]+/.exec(navigator.userAgent);
|
|
286
|
+
return {
|
|
287
|
+
t: "hello",
|
|
288
|
+
instanceId: await ensureInstanceId(),
|
|
289
|
+
browserSession: await ensureBrowserSession(),
|
|
290
|
+
userAgent: navigator.userAgent,
|
|
291
|
+
browserVersion: versionMatch?.[0] ?? "Chrome/unknown",
|
|
292
|
+
discardedTabsProtocol: 1,
|
|
293
|
+
ompVersion: typeof OMP_INSTALL_VERSION === "string" ? OMP_INSTALL_VERSION : undefined,
|
|
294
|
+
reloadProtocol: EXTENSION_RELOAD_PROTOCOL_VERSION,
|
|
295
|
+
downloadsProtocol: DOWNLOADS_PROTOCOL_VERSION,
|
|
296
|
+
tabs: snapshots,
|
|
297
|
+
attachedTabIds
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
async function runRpc(msg, origin) {
|
|
301
|
+
switch (msg.op) {
|
|
302
|
+
case "attach": {
|
|
303
|
+
const attach = () => chrome.debugger.attach({ tabId: msg.tabId }, "1.3");
|
|
304
|
+
await (msg.clearForeignFrames ? pastForeignFrames(msg.tabId, attach) : attach());
|
|
305
|
+
return {};
|
|
306
|
+
}
|
|
307
|
+
case "detach":
|
|
308
|
+
relayInitiatedDetachTabs.add(msg.tabId);
|
|
309
|
+
try {
|
|
310
|
+
await chrome.debugger.detach({ tabId: msg.tabId });
|
|
311
|
+
return {};
|
|
312
|
+
} catch (error) {
|
|
313
|
+
relayInitiatedDetachTabs.delete(msg.tabId);
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
case "send": {
|
|
317
|
+
const send = () => chrome.debugger.sendCommand(msg.sessionId ? { tabId: msg.tabId, sessionId: msg.sessionId } : { tabId: msg.tabId }, msg.method, msg.params);
|
|
318
|
+
return await (msg.clearForeignFrames ? pastForeignFrames(msg.tabId, send) : send());
|
|
319
|
+
}
|
|
320
|
+
case "createTab": {
|
|
321
|
+
const tab = await chrome.tabs.create({ url: msg.url, active: msg.active ?? true });
|
|
322
|
+
const snap = snapshot(tab);
|
|
323
|
+
if (!snap)
|
|
324
|
+
throw new Error("created tab has no id");
|
|
325
|
+
if (origin.readyState !== WebSocket.OPEN)
|
|
326
|
+
removeTab(snap.tabId).catch(() => {});
|
|
327
|
+
return { tab: snap };
|
|
328
|
+
}
|
|
329
|
+
case "removeTab":
|
|
330
|
+
await removeTab(msg.tabId);
|
|
331
|
+
return {};
|
|
332
|
+
case "activateTab": {
|
|
333
|
+
const tab = await chrome.tabs.get(msg.tabId);
|
|
334
|
+
await chrome.windows.update(tab.windowId, { focused: true });
|
|
335
|
+
await chrome.tabs.update(msg.tabId, { active: true });
|
|
336
|
+
return {};
|
|
337
|
+
}
|
|
338
|
+
case "group":
|
|
339
|
+
return await enqueueGroupOp(() => groupTabs(msg.tabIds, msg.title, msg.color));
|
|
340
|
+
case "ungroup":
|
|
341
|
+
await enqueueGroupOp(() => chrome.tabs.ungroup(msg.tabIds).catch(() => {}));
|
|
342
|
+
return {};
|
|
343
|
+
case "findDownload": {
|
|
344
|
+
const id = downloads.idFor(msg.guid);
|
|
345
|
+
const [item] = id === undefined ? [] : await chrome.downloads.search({ id });
|
|
346
|
+
if (item && item.state !== "in_progress")
|
|
347
|
+
downloads.forget(msg.guid);
|
|
348
|
+
const found = item ? { filename: item.filename, state: item.state } : null;
|
|
349
|
+
return found;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function handleRelayMessage(socket, raw) {
|
|
354
|
+
let msg;
|
|
355
|
+
try {
|
|
356
|
+
msg = JSON.parse(raw);
|
|
357
|
+
} catch {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (msg.t === "pong")
|
|
361
|
+
return;
|
|
362
|
+
if (msg.t === "reload") {
|
|
363
|
+
chrome.runtime.reload();
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const answer = (reply) => {
|
|
367
|
+
if (socket.readyState === WebSocket.OPEN)
|
|
368
|
+
socket.send(JSON.stringify(reply));
|
|
369
|
+
};
|
|
370
|
+
runRpc(msg, socket).then((result) => answer({ t: "rpcResult", id: msg.id, ok: true, result })).catch((err) => {
|
|
371
|
+
answer({ t: "rpcResult", id: msg.id, ok: false, error: err instanceof Error ? err.message : String(err) });
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
function scheduleReconnect() {
|
|
375
|
+
const delay = reconnectDelay;
|
|
376
|
+
reconnectDelay = Math.min(reconnectDelay * 2, RECONNECT_MAX_MS);
|
|
377
|
+
setTimeout(() => void connect(), delay);
|
|
378
|
+
}
|
|
379
|
+
async function connect() {
|
|
380
|
+
if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING))
|
|
381
|
+
return;
|
|
382
|
+
const settings = await loadSettings();
|
|
383
|
+
const url = `ws://127.0.0.1:${settings.port}/ext${settings.token ? `?token=${encodeURIComponent(settings.token)}` : ""}`;
|
|
384
|
+
const socket = new WebSocket(url);
|
|
385
|
+
ws = socket;
|
|
386
|
+
socket.onopen = () => {
|
|
387
|
+
reconnectDelay = RECONNECT_MIN_MS;
|
|
388
|
+
setBadge(true);
|
|
389
|
+
buildHello().then((hello) => post(hello));
|
|
390
|
+
clearInterval(pingTimer ?? undefined);
|
|
391
|
+
pingTimer = setInterval(() => post({ t: "ping" }), PING_INTERVAL_MS);
|
|
392
|
+
};
|
|
393
|
+
socket.onmessage = (event) => {
|
|
394
|
+
if (typeof event.data === "string")
|
|
395
|
+
handleRelayMessage(socket, event.data);
|
|
396
|
+
};
|
|
397
|
+
socket.onclose = () => {
|
|
398
|
+
if (ws !== socket)
|
|
399
|
+
return;
|
|
400
|
+
ws = null;
|
|
401
|
+
if (pingTimer !== null) {
|
|
402
|
+
clearInterval(pingTimer);
|
|
403
|
+
pingTimer = null;
|
|
404
|
+
}
|
|
405
|
+
setBadge(false);
|
|
406
|
+
restoreGroups();
|
|
407
|
+
scheduleReconnect();
|
|
408
|
+
};
|
|
409
|
+
socket.onerror = () => {
|
|
410
|
+
socket.close();
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
var downloads = new DownloadPairing;
|
|
414
|
+
chrome.downloads.onCreated.addListener((item) => downloads.created(item.id, item.finalUrl));
|
|
415
|
+
chrome.downloads.onChanged.addListener((delta) => {
|
|
416
|
+
const state = delta.state?.current;
|
|
417
|
+
if (state === "complete" || state === "interrupted")
|
|
418
|
+
downloads.finished(delta.id, state);
|
|
419
|
+
});
|
|
420
|
+
chrome.debugger.onEvent.addListener((source, method, params) => {
|
|
421
|
+
if (source.tabId === undefined)
|
|
422
|
+
return;
|
|
423
|
+
if (method === "Page.downloadWillBegin" && typeof params?.guid === "string" && typeof params.url === "string") {
|
|
424
|
+
downloads.report(params.guid, params.url);
|
|
425
|
+
}
|
|
426
|
+
post({ t: "cdpEvent", tabId: source.tabId, sessionId: source.sessionId, method, params });
|
|
427
|
+
});
|
|
428
|
+
chrome.debugger.onDetach.addListener((source, reason) => {
|
|
429
|
+
if (source.tabId === undefined)
|
|
430
|
+
return;
|
|
431
|
+
const relayInitiated = relayInitiatedDetachTabs.delete(source.tabId);
|
|
432
|
+
post({ t: "detached", tabId: source.tabId, reason, relayInitiated });
|
|
433
|
+
});
|
|
434
|
+
chrome.tabs.onCreated.addListener((tab) => {
|
|
435
|
+
const snap = snapshot(tab);
|
|
436
|
+
if (snap)
|
|
437
|
+
post({ t: "tabCreated", tab: snap });
|
|
438
|
+
});
|
|
439
|
+
chrome.tabs.onUpdated.addListener((_tabId, _changeInfo, tab) => {
|
|
440
|
+
const snap = snapshot(tab);
|
|
441
|
+
if (snap)
|
|
442
|
+
post({ t: "tabUpdated", tab: snap });
|
|
443
|
+
});
|
|
444
|
+
chrome.tabs.onActivated.addListener(({ tabId }) => {
|
|
445
|
+
chrome.tabs.get(tabId).then((tab) => {
|
|
446
|
+
const snap = snapshot(tab);
|
|
447
|
+
if (snap)
|
|
448
|
+
post({ t: "tabUpdated", tab: snap });
|
|
449
|
+
}).catch(() => {});
|
|
450
|
+
});
|
|
451
|
+
chrome.tabs.onRemoved.addListener((tabId) => {
|
|
452
|
+
post({ t: "tabRemoved", tabId });
|
|
453
|
+
});
|
|
454
|
+
chrome.alarms.create("omp-relay-keepalive", { periodInMinutes: 0.5 });
|
|
455
|
+
chrome.alarms.onAlarm.addListener((alarm) => {
|
|
456
|
+
if (alarm.name === "omp-relay-keepalive")
|
|
457
|
+
connect();
|
|
458
|
+
});
|
|
459
|
+
chrome.storage.onChanged.addListener((_changes, areaName) => {
|
|
460
|
+
if (areaName !== "local")
|
|
461
|
+
return;
|
|
462
|
+
ws?.close();
|
|
463
|
+
connect();
|
|
464
|
+
});
|
|
465
|
+
chrome.action.onClicked.addListener(() => void chrome.runtime.openOptionsPage());
|
|
466
|
+
chrome.runtime.onInstalled.addListener(() => void connect());
|
|
467
|
+
chrome.runtime.onStartup.addListener(() => void connect());
|
|
468
|
+
connect();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 3,
|
|
3
|
+
"name": "OMP Browser Relay",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Lets the omp coding agent drive your existing tabs through a local CDP relay.",
|
|
6
|
+
"author": "Stencil Labs, Inc.",
|
|
7
|
+
"homepage_url": "https://omp.sh",
|
|
8
|
+
"permissions": ["debugger", "tabs", "tabGroups", "storage", "alarms", "scripting", "downloads"],
|
|
9
|
+
"host_permissions": ["<all_urls>"],
|
|
10
|
+
"background": {
|
|
11
|
+
"service_worker": "background.js"
|
|
12
|
+
},
|
|
13
|
+
"options_page": "options.html",
|
|
14
|
+
"action": {
|
|
15
|
+
"default_title": "OMP Browser Relay (click for settings)"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>OMP Browser Relay settings</title>
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
font-family: system-ui, sans-serif;
|
|
9
|
+
max-width: 28rem;
|
|
10
|
+
margin: 2rem auto;
|
|
11
|
+
padding: 0 1rem;
|
|
12
|
+
color: #1f2328;
|
|
13
|
+
}
|
|
14
|
+
label {
|
|
15
|
+
display: block;
|
|
16
|
+
margin: 1rem 0 0.25rem;
|
|
17
|
+
font-weight: 600;
|
|
18
|
+
}
|
|
19
|
+
input {
|
|
20
|
+
width: 100%;
|
|
21
|
+
padding: 0.4rem 0.5rem;
|
|
22
|
+
font: inherit;
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
}
|
|
25
|
+
button {
|
|
26
|
+
margin-top: 1.25rem;
|
|
27
|
+
padding: 0.45rem 1.1rem;
|
|
28
|
+
font: inherit;
|
|
29
|
+
}
|
|
30
|
+
#status {
|
|
31
|
+
margin-left: 0.75rem;
|
|
32
|
+
color: #1a7f37;
|
|
33
|
+
}
|
|
34
|
+
p.hint {
|
|
35
|
+
color: #57606a;
|
|
36
|
+
font-size: 0.85rem;
|
|
37
|
+
}
|
|
38
|
+
</style>
|
|
39
|
+
</head>
|
|
40
|
+
<body>
|
|
41
|
+
<h1>OMP Browser Relay</h1>
|
|
42
|
+
<p class="hint">
|
|
43
|
+
The extension connects to a local <code>omp-browser-relay</code> process. Values here must match the flags the
|
|
44
|
+
relay was started with.
|
|
45
|
+
</p>
|
|
46
|
+
<label for="port">Relay port</label>
|
|
47
|
+
<input id="port" type="number" min="1" max="65535" />
|
|
48
|
+
<label for="token">Token (optional)</label>
|
|
49
|
+
<input id="token" type="text" autocomplete="off" />
|
|
50
|
+
<button id="save">Save</button><span id="status"></span>
|
|
51
|
+
<script src="options.js"></script>
|
|
52
|
+
</body>
|
|
53
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Options page for the OMP Browser Relay extension (plain JS: shipped as-is).
|
|
2
|
+
const DEFAULT_PORT = 9224;
|
|
3
|
+
const portInput = document.getElementById("port");
|
|
4
|
+
const tokenInput = document.getElementById("token");
|
|
5
|
+
const status = document.getElementById("status");
|
|
6
|
+
|
|
7
|
+
chrome.storage.local.get({ port: DEFAULT_PORT, token: "" }).then(stored => {
|
|
8
|
+
portInput.value = String(stored.port);
|
|
9
|
+
tokenInput.value = String(stored.token);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
document.getElementById("save").addEventListener("click", async () => {
|
|
13
|
+
const port = Number(portInput.value);
|
|
14
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
15
|
+
status.textContent = "invalid port";
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
await chrome.storage.local.set({ port, token: tokenInput.value });
|
|
19
|
+
status.textContent = "saved";
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
status.textContent = "";
|
|
22
|
+
}, 1500);
|
|
23
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{b as c,d as l}from"./chunk-27TRKD65.js";import{H as s}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import{a as i,b as r}from"./chunk-
|
|
1
|
+
import{b as c,d as l}from"./chunk-27TRKD65.js";import{H as s}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import{a as i,b as r}from"./chunk-X3KLM35N.js";import"./chunk-WOT6VMZA.js";var d=[["/connect","sign in to howtofix.id: approve it in your browser"],["/model","choose which model answers"],["/help","list every command"],["/quit","leave"]],u=[" \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557"," \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D"," \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2557 "," \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u255D "," \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u255D \u2588\u2588\u2557\u2588\u2588\u2551 "," \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D "],g=[" _ _ _____ ","| | | | __ __ | ___|","| |_| | \\ \\/ / | |_ ","| _ | > < | _| ","|_| |_| /_/\\_\\ |_| "];function m(){if(process.platform==="win32")return!1;let e=(process.env.LC_ALL||process.env.LC_CTYPE||process.env.LANG||"").toLowerCase();return e===""||e==="c"||e==="posix"||!e.includes("utf-8")&&!e.includes("utf8")?!1:!/ja|ko|zh|_kr|_jp|_cn|_tw|_hk/.test(e)}function h(){return m()?u:g}var _="https://howtofix.id/cli";function p(e){let n=process.env.HOME??"",t=n!==""&&e.startsWith(n)?`~${e.slice(n.length)}`:e,o=t.split("/").filter(Boolean);return o.length>3?`\u2026/${o.slice(-2).join("/")}`:t}function f(e){let n=e.signedIn?d.filter(([t])=>t!=="/connect"):d;return[...h(),"",`${i} ${r} \u2014 a terminal coding agent. Describe the change you want and it reads, edits and runs the code in front of you.`,"",` working in ${p(e.cwd)}`,...e.note?[` session ${e.note}`]:[],"",...e.signedIn?[" already signed in to howtofix.id",""]:[],...n.map(([t,o])=>` ${t.padEnd(11)}${o}`),"",' Or just start typing. Every message goes to the model; anything beginning with "/" stays local.'].join(`
|
|
2
2
|
`)}function v(){return[{value:"connect",label:"Sign in to howtofix.id",description:"approve the sign-in in your browser"},{value:"ready",label:"I have a key \u2014 just give me the prompt",description:"drops you at the prompt; run /connect whenever you like"},{value:"release",label:"What's in this release",description:`opens the ${r} notes in your browser`}]}async function E(e,n,t){c(s).welcomeSeen||(l(s),t(`welcome to ${i}`,f(e)),!e.signedIn&&await new Promise(o=>{n("First run \u2014 how do you want to begin?",v(),a=>{a==="connect"&&e.runSlash("/connect"),a==="release"&&e.openExternal(_),o()},()=>o())}))}export{E as maybeShowWelcome};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,q as p,r as q,s as r,t as s}from"./chunk-SVONBXW3.js";import"./chunk-UTYFLLSM.js";import"./chunk-WOT6VMZA.js";export{c as APPROVAL_LABELS,b as APPROVAL_MODES,f as MODE_MAX_TIER,e as TIER_RANK,s as createPermissionExtension,h as criticalCommand,p as decideToolCall,q as describeToolCall,r as formatApprovalPrompt,l as getApprovalMode,d as isApprovalMode,n as isDangerousBypass,a as isReadOnlyCommand,j as loadApprovalMode,g as resolveTier,k as saveApprovalMode,i as setApprovalMode,o as setApprovalPrompt,m as setDangerousBypass};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as j}from"./chunk-MCAAX33K.js";import{H as m,N as A}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import{j as R}from"./chunk-MVVEYKN6.js";import{b as M,d as T,f as D}from"./chunk-TUXY64DT.js";import{a as I}from"./chunk-U3GZBLTM.js";import{a as b}from"./chunk-
|
|
1
|
+
import{b as j}from"./chunk-MCAAX33K.js";import{H as m,N as A}from"./chunk-ABDZXFNM.js";import"./chunk-UTYFLLSM.js";import{j as R}from"./chunk-MVVEYKN6.js";import{b as M,d as T,f as D}from"./chunk-TUXY64DT.js";import{a as I}from"./chunk-U3GZBLTM.js";import{a as b}from"./chunk-X3KLM35N.js";import"./chunk-WOT6VMZA.js";import{spawnSync as J}from"node:child_process";import{existsSync as S,readdirSync as E,readFileSync as x,realpathSync as B,statSync as C,writeFileSync as F,unlinkSync as z}from"node:fs";import{dirname as N,join as p}from"node:path";var k=[22,19];async function W(t="https://api.howtofix.id/api/status"){let n=[],[s,e]=process.versions.node.split(".").map(Number),r=s>k[0]||s===k[0]&&e>=k[1];n.push({name:"node",ok:r,detail:`${process.versions.node} (needs >= ${k[0]}.${k[1]})`});let i=J("git",["--version"],{encoding:"utf8"});n.push({name:"git",ok:i.status===0,detail:i.status===0?i.stdout.trim():"not found on PATH"});let o=I();n.push({name:"sandbox",ok:!!o,detail:o??"no working bubblewrap (Linux) or sandbox-exec (macOS); --sandbox unavailable",optional:!0});let l=!1,c=m;try{let d=p(m,`.doctor-${process.pid}`);F(d,"ok"),z(d),l=!0}catch(d){c=`${m} is not writable: ${d instanceof Error?d.message:String(d)}`}n.push({name:"state dir",ok:l,detail:c});let a=p(m,"auth.json"),u="no auth.json \u2014 run `howtocode` and sign in",h=!1;try{let d=JSON.parse(x(a,"utf8")),f=Object.keys(d).length;h=f>0,u=h?`${f} provider credential${f===1?"":"s"}`:u}catch{}n.push({name:"auth",ok:h,detail:u,optional:!0});try{let d=Date.now(),f=await fetch(t,{signal:AbortSignal.timeout(5e3)});n.push({name:"gateway",ok:f.ok,detail:`${t} \u2192 ${f.status} in ${Date.now()-d}ms`,optional:!0})}catch(d){n.push({name:"gateway",ok:!1,detail:`${t} unreachable: ${d instanceof Error?d.message:String(d)}`,optional:!0})}return n.push(G()),n}function G(t=q()){if(t===void 0)return{name:"install",ok:!0,detail:"not an npm install; skipped",optional:!0};if(!S(t))return{name:"install",ok:!0,detail:"no bundled dependencies to check",optional:!0};let n=[],s=0;for(let e of["@netrodev"]){let r=p(t,e);if(S(r))for(let i of E(r)){let o=p(r,i,"dist");if(S(o))for(let l of _(o)){s+=1;let c=x(l,"utf8");for(let a of c.matchAll(/import\("(\.[^"]+)"\)/g)){let u=p(N(l),a[1]);S(u)||n.push(`${e}/${i}: ${u.slice(o.length+1)}`)}}}}return n.length>0?{name:"install",ok:!1,detail:`${n.length} module${n.length===1?"":"s"} missing (${n[0]}); reinstall with \`npm install -g howtocode@latest\``}:{name:"install",ok:!0,detail:`${s} lazy module${s===1?"":"s"} present`}}function q(){try{return p(N(N(B(process.argv[1]??""))),"node_modules")}catch{return}}function _(t,n=[]){let s;try{s=E(t)}catch{return n}for(let e of s){let r=p(t,e);if(e.endsWith(".lazy.js"))n.push(r);else if(!e.includes("."))try{C(r).isDirectory()&&_(r,n)}catch{}}return n}async function ie(){let t=await W(),n=Math.max(...t.map(e=>e.name.length));for(let e of t){let r=e.ok?"ok ":e.optional?"warn":"FAIL";console.log(` ${r} ${e.name.padEnd(n)} ${e.detail}`)}let s=t.filter(e=>!e.ok&&!e.optional);return s.length>0?(console.log(`
|
|
2
2
|
${s.length} problem${s.length===1?"":"s"} must be fixed before a session will work.`),1):0}function ce(t=m){let n=p(t,"models.json"),s;try{s=x(n,"utf8")}catch(a){return a.code==="ENOENT"?console.log(` no models.json at ${n} \u2014 run \`howtocode /connect\` to pull the catalogue`):j(b,"models",a),1}let e;try{e=JSON.parse(s)}catch(a){return console.error(`${b}: models: ${n} is not valid JSON (${a instanceof Error?a.message:String(a)})`),console.error(" fix the file, or delete it and run `howtocode /connect` to write a new one"),1}let r=e.providers??{},i=D(A),o=i?new Set(i.ids):void 0,l=new Set,c=0;for(let[a,u]of Object.entries(r)){let h=u.models??[],d=h.map(f=>f.id).filter(Boolean);for(let f of d)l.add(f);c+=d.length,console.log(` ${a} (${d.length})`);for(let f of h){if(!f.id)continue;let O=T(m).get(f.id),$=M(O??[]),g=$?` ${$}`:"",w=o&&!o.has(f.id)?" \u2014 not on this account":"";console.log(` ${f.id}${g}${w}`)}}if(o){let a=[...l].filter(u=>!o.has(u)).length;console.log(`
|
|
3
3
|
${[...o].filter(u=>l.has(u)).length} of ${c} listed model(s) this account can call${a>0?`; ${a} cannot (kept for other plans)`:""}`)}else console.log("\n which of these this account can call is unknown: run `howtocode` once to record it");return c===0?(console.log(" no models configured"),1):0}function v(t=15,n=m){let s=p(n,"sessions"),e;try{e=E(s)}catch{return[]}let r=[];for(let i of e){let o=p(s,i),l;try{l=E(o)}catch{continue}for(let c of l){if(!c.endsWith(".jsonl"))continue;let a=p(o,c);try{let u=C(a);r.push({file:a,project:i,modified:u.mtimeMs,bytes:u.size})}catch{}}}return r.sort((i,o)=>o.modified-i.modified).slice(0,t)}function le(t){let n=t.indexOf("--search");if(n>=0){let o=t[n+1]?.trim();if(!o)return console.error(`${b}: sessions: --search needs a word or phrase`),2;let l=K(o);if(l.length===0)return console.log(` no session mentions "${o}"`),0;for(let c of l){let a=new Date(c.row.modified).toISOString().replace("T"," ").slice(0,16),u=`${c.matches} hit${c.matches===1?"":"s"}`;console.log(` ${a} ${c.row.project} (${u})`),console.log(` ${c.row.file}`),console.log(` ${c.snippet}`)}return 0}let s=t.indexOf("--limit"),e=s>=0&&Number(t[s+1])||15,r=v(e);if(r.length===0)return console.log(` no saved sessions under ${p(m,"sessions")}`),t.includes("--export")?1:0;let i=t.indexOf("--export");if(i>=0){let o=Number(t[i+1]);if(!Number.isInteger(o)||o<1||o>r.length)return console.error(`${b}: sessions: --export needs a number from the list (1-${r.length})`),2;let l=r[o-1];try{console.log(Q(l.file))}catch(c){return j(b,"sessions",c),1}return 0}return r.forEach((o,l)=>{let c=new Date(o.modified).toISOString().replace("T"," ").slice(0,16),a=Math.round(o.bytes/1024);console.log(` ${String(l+1).padStart(2)} ${c} ${String(a).padStart(6)}k ${o.project}`),console.log(` ${o.file}`)}),0}function H(t){let n=t;try{let s=JSON.parse(t),e=s.message?.content??s.content;if(typeof e=="string"&&e.trim())n=e;else if(Array.isArray(e)){let r=e.map(i=>i&&typeof i=="object"&&"text"in i?String(i.text):"").join(" ");r.trim()&&(n=r)}}catch{}return R(X(n).replace(/\s+/g," ").trim())}function X(t){return t.replace(/\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][^\u0007]*\u0007|\u001b[@-Z\\-_]/g,"")}function Z(t,n,s=80){let e=t.toLowerCase().indexOf(n);if(e<0)return t.slice(0,s*2).trim();let r=Math.max(0,e-s),i=Math.min(t.length,e+n.length+s);return`${r>0?"\u2026":""}${t.slice(r,i).trim()}${i<t.length?"\u2026":""}`}function K(t,n=10,s=m){let e=t.toLowerCase(),r=new RegExp(`\\b${e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i"),i=[];for(let o of v(Number.MAX_SAFE_INTEGER,s)){let l;try{l=x(o.file,"utf8")}catch{continue}let c=0,a=0,u=0,h=0,d=!1,f="";for(let $ of l.split(`
|
|
4
4
|
`)){let g=$.toLowerCase(),w=g.indexOf(e);if(w<0)continue;let y=0;for(;w>=0;)y++,w=g.indexOf(e,w+e.length);c+=y;let L=g.includes('"role":"user"'),P=g.includes('"role":"toolresult"')||g.includes('"role":"tool"');L?a+=y:P?h+=y:u+=y,r.test($)&&(d=!0),f||(f=Z(H($),e))}if(c===0)continue;let O=(a>0?100:0)+(u>0?10:0)+Math.min(h,5)+(d?5:0)+Math.min(c,10)/100;i.push({row:o,matches:c,score:O,snippet:f})}return i.sort((o,l)=>l.score-o.score||l.row.modified-o.row.modified).slice(0,n)}function Q(t){let n=[`# Session ${t.split(/[\\/]/).pop()??t}`,""];for(let s of x(t,"utf8").split(`
|