@steipete/oracle 0.18.0 → 0.19.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/README.md +1 -1
- package/dist/bin/oracle-cli.js +65 -63
- package/dist/bin/oracle-mcp.js +0 -0
- package/dist/src/browser/actions/archiveConversation.js +31 -7
- package/dist/src/browser/actions/assistantResponse.js +43 -1
- package/dist/src/browser/actions/attachmentContext.js +239 -0
- package/dist/src/browser/actions/attachmentDataTransfer.js +19 -1
- package/dist/src/browser/actions/attachmentEvidence.js +78 -0
- package/dist/src/browser/actions/attachmentProgress.js +41 -0
- package/dist/src/browser/actions/attachmentPrompt.js +130 -0
- package/dist/src/browser/actions/attachments.js +306 -355
- package/dist/src/browser/actions/deepResearch.js +2 -1
- package/dist/src/browser/actions/modelSelection.js +13 -3
- package/dist/src/browser/actions/navigation.js +1 -1
- package/dist/src/browser/actions/promptComposer.js +361 -186
- package/dist/src/browser/actions/remoteFileTransfer.js +4 -2
- package/dist/src/browser/actions/thinkingStatus.js +2 -5
- package/dist/src/browser/actions/thinkingTime.js +119 -16
- package/dist/src/browser/attachRunning.js +46 -2
- package/dist/src/browser/attachmentValidation.js +53 -0
- package/dist/src/browser/cancellation.js +105 -0
- package/dist/src/browser/chatgptImages.js +2 -0
- package/dist/src/browser/chatgptThrottle.js +104 -0
- package/dist/src/browser/chromeLifecycle.js +267 -43
- package/dist/src/browser/config.js +13 -0
- package/dist/src/browser/detect.js +1 -1
- package/dist/src/browser/index.js +444 -261
- package/dist/src/browser/modelDisplay.js +9 -0
- package/dist/src/browser/pageActions.js +2 -2
- package/dist/src/browser/profileState.js +114 -9
- package/dist/src/browser/projectSourcesRunner.js +83 -15
- package/dist/src/browser/prompt.js +272 -113
- package/dist/src/browser/providers/chatgptDomProvider.js +2 -0
- package/dist/src/browser/reattach.js +10 -3
- package/dist/src/browser/sessionRunner.js +71 -11
- package/dist/src/browser/tabLeaseRegistry.js +414 -38
- package/dist/src/browser/utils.js +20 -2
- package/dist/src/cli/browserConfig.js +3 -1
- package/dist/src/cli/browserDefaults.js +10 -0
- package/dist/src/cli/browserTabs.js +12 -29
- package/dist/src/cli/detachedSession.js +69 -0
- package/dist/src/cli/dryRun.js +58 -48
- package/dist/src/cli/harvestIntegrity.js +140 -0
- package/dist/src/cli/serveBrowserConfig.js +24 -0
- package/dist/src/cli/sessionDisplay.js +9 -2
- package/dist/src/cli/sessionRunner.js +91 -7
- package/dist/src/config.js +1 -0
- package/dist/src/gemini-web/client.js +67 -21
- package/dist/src/gemini-web/executor.js +4 -0
- package/dist/src/gemini-web/http.js +15 -0
- package/dist/src/gemini-web/models.js +15 -11
- package/dist/src/mcp/server.js +11 -14
- package/dist/src/mcp/tools/chatgptImage.js +4 -4
- package/dist/src/mcp/tools/consult.js +84 -22
- package/dist/src/mcp/tools/projectSources.js +4 -6
- package/dist/src/mcp/tools/sessionResources.js +1 -1
- package/dist/src/mcp/tools/sessions.js +2 -2
- package/dist/src/mcp/tools/wait.js +182 -0
- package/dist/src/mcp/types.js +7 -0
- package/dist/src/oracle/errors.js +11 -0
- package/dist/src/oracle/providerRoutePlan.js +3 -2
- package/dist/src/remote/client.js +70 -6
- package/dist/src/remote/health.js +6 -2
- package/dist/src/remote/runSlots.js +83 -0
- package/dist/src/remote/server.js +345 -71
- package/dist/src/sessionManager.js +36 -1
- package/dist/vendor/oracle-notifier/OracleNotifier.app/Contents/CodeResources +0 -0
- package/dist/vendor/oracle-notifier/OracleNotifier.app/Contents/MacOS/OracleNotifier +0 -0
- package/package.json +25 -23
- package/vendor/oracle-notifier/OracleNotifier.app/Contents/CodeResources +0 -0
- package/vendor/oracle-notifier/OracleNotifier.app/Contents/MacOS/OracleNotifier +0 -0
- package/dist/bin/oracle.js +0 -683
- package/dist/docs-site/.nojekyll +0 -0
- package/dist/docs-site/CNAME +0 -1
- package/dist/docs-site/RELEASING.html +0 -410
- package/dist/docs-site/agents.html +0 -374
- package/dist/docs-site/anthropic.html +0 -368
- package/dist/docs-site/bridge.html +0 -400
- package/dist/docs-site/browser-mode.html +0 -588
- package/dist/docs-site/chromium-forks.html +0 -347
- package/dist/docs-site/cli-reference.html +0 -346
- package/dist/docs-site/configuration.html +0 -436
- package/dist/docs-site/favicon.svg +0 -14
- package/dist/docs-site/followup.html +0 -368
- package/dist/docs-site/gemini.html +0 -379
- package/dist/docs-site/grok.html +0 -325
- package/dist/docs-site/index.html +0 -360
- package/dist/docs-site/install.html +0 -335
- package/dist/docs-site/linux.html +0 -321
- package/dist/docs-site/llms.txt +0 -43
- package/dist/docs-site/manual-tests.html +0 -595
- package/dist/docs-site/mcp.html +0 -368
- package/dist/docs-site/multimodel.html +0 -364
- package/dist/docs-site/mythical-pro-agents.html +0 -360
- package/dist/docs-site/notifier.html +0 -338
- package/dist/docs-site/openai-endpoints.html +0 -387
- package/dist/docs-site/openrouter.html +0 -344
- package/dist/docs-site/quickstart.html +0 -369
- package/dist/docs-site/refactor/ux.html +0 -532
- package/dist/docs-site/sessions.html +0 -388
- package/dist/docs-site/social-card.png +0 -0
- package/dist/docs-site/social-card.svg +0 -79
- package/dist/docs-site/spec.html +0 -363
- package/dist/docs-site/testing.html +0 -320
- package/dist/docs-site/tui-debug.html +0 -326
- package/dist/docs-site/windows-work.html +0 -323
- package/dist/docs-site/windows.html +0 -320
- package/dist/markdansi/types/index.js +0 -4
- package/dist/oracle/bin/oracle-cli.js +0 -472
- package/dist/oracle/src/browser/actions/assistantResponse.js +0 -471
- package/dist/oracle/src/browser/actions/attachments.js +0 -82
- package/dist/oracle/src/browser/actions/modelSelection.js +0 -190
- package/dist/oracle/src/browser/actions/navigation.js +0 -75
- package/dist/oracle/src/browser/actions/promptComposer.js +0 -167
- package/dist/oracle/src/browser/chromeLifecycle.js +0 -104
- package/dist/oracle/src/browser/config.js +0 -33
- package/dist/oracle/src/browser/constants.js +0 -40
- package/dist/oracle/src/browser/cookies.js +0 -210
- package/dist/oracle/src/browser/domDebug.js +0 -36
- package/dist/oracle/src/browser/index.js +0 -331
- package/dist/oracle/src/browser/pageActions.js +0 -5
- package/dist/oracle/src/browser/prompt.js +0 -88
- package/dist/oracle/src/browser/promptSummary.js +0 -20
- package/dist/oracle/src/browser/sessionRunner.js +0 -80
- package/dist/oracle/src/browser/types.js +0 -1
- package/dist/oracle/src/browser/utils.js +0 -62
- package/dist/oracle/src/browserMode.js +0 -1
- package/dist/oracle/src/cli/browserConfig.js +0 -44
- package/dist/oracle/src/cli/dryRun.js +0 -59
- package/dist/oracle/src/cli/engine.js +0 -17
- package/dist/oracle/src/cli/errorUtils.js +0 -9
- package/dist/oracle/src/cli/help.js +0 -70
- package/dist/oracle/src/cli/markdownRenderer.js +0 -15
- package/dist/oracle/src/cli/options.js +0 -103
- package/dist/oracle/src/cli/promptRequirement.js +0 -14
- package/dist/oracle/src/cli/rootAlias.js +0 -30
- package/dist/oracle/src/cli/sessionCommand.js +0 -77
- package/dist/oracle/src/cli/sessionDisplay.js +0 -270
- package/dist/oracle/src/cli/sessionRunner.js +0 -94
- package/dist/oracle/src/heartbeat.js +0 -43
- package/dist/oracle/src/oracle/client.js +0 -48
- package/dist/oracle/src/oracle/config.js +0 -29
- package/dist/oracle/src/oracle/errors.js +0 -101
- package/dist/oracle/src/oracle/files.js +0 -220
- package/dist/oracle/src/oracle/format.js +0 -33
- package/dist/oracle/src/oracle/fsAdapter.js +0 -7
- package/dist/oracle/src/oracle/oscProgress.js +0 -60
- package/dist/oracle/src/oracle/request.js +0 -48
- package/dist/oracle/src/oracle/run.js +0 -444
- package/dist/oracle/src/oracle/tokenStats.js +0 -39
- package/dist/oracle/src/oracle/types.js +0 -1
- package/dist/oracle/src/oracle.js +0 -9
- package/dist/oracle/src/sessionManager.js +0 -205
- package/dist/oracle/src/version.js +0 -39
- package/dist/scripts/chrome/browser-tools.js +0 -295
- package/dist/src/browser/chromeCookies.js +0 -312
- package/dist/src/browser/keytarShim.js +0 -56
- package/dist/src/browser/profileSync.js +0 -141
- package/dist/src/browser/windowsCookies.js +0 -219
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import fs from 'node:fs/promises';
|
|
4
|
-
import { existsSync } from 'node:fs';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
import chromeCookies from 'chrome-cookies-secure';
|
|
7
|
-
import { COOKIE_URLS } from './constants.js';
|
|
8
|
-
import { ensureCookiesDirForFallback } from './windowsCookies.js';
|
|
9
|
-
const COOKIE_READ_TIMEOUT_MS = readDuration('ORACLE_COOKIE_LOAD_TIMEOUT_MS', 5_000);
|
|
10
|
-
const KEYCHAIN_PROBE_TIMEOUT_MS = readDuration('ORACLE_KEYCHAIN_PROBE_TIMEOUT_MS', 3_000);
|
|
11
|
-
const MAC_KEYCHAIN_LABELS = loadKeychainLabels();
|
|
12
|
-
export async function loadChromeCookies({ targetUrl, profile, explicitCookiePath, filterNames, }) {
|
|
13
|
-
if (process.platform === 'win32') {
|
|
14
|
-
throw new Error('Cookie sync is disabled on Windows; use --browser-manual-login (persistent profile) or inline cookies instead.');
|
|
15
|
-
}
|
|
16
|
-
const urlsToCheck = Array.from(new Set([stripQuery(targetUrl), ...COOKIE_URLS]));
|
|
17
|
-
const merged = new Map();
|
|
18
|
-
const cookieFile = await resolveCookieFilePath({ explicitPath: explicitCookiePath, profile });
|
|
19
|
-
const cookiesPath = await materializeCookieFile(cookieFile); // returns the copied file (or source on non-Windows)
|
|
20
|
-
const fallbackDir = await ensureCookiesDirForFallback(cookiesPath);
|
|
21
|
-
if (process.env.ORACLE_DEBUG_COOKIES === '1') {
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
console.log(`[cookies] resolved cookie file: ${cookiesPath}`);
|
|
24
|
-
console.log(`[cookies] fallback dir for chrome-cookies-secure: ${fallbackDir}`);
|
|
25
|
-
}
|
|
26
|
-
await ensureMacKeychainReadable();
|
|
27
|
-
for (const url of urlsToCheck) {
|
|
28
|
-
let raw;
|
|
29
|
-
try {
|
|
30
|
-
const pathForSecure = await adaptPathForChromeCookies(fallbackDir);
|
|
31
|
-
raw = await settleWithTimeout(chromeCookies.getCookiesPromised(url, 'puppeteer', pathForSecure), COOKIE_READ_TIMEOUT_MS, `Timed out reading Chrome cookies from ${pathForSecure} (after ${COOKIE_READ_TIMEOUT_MS} ms)`);
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
35
|
-
throw new Error(`Failed to load Chrome cookies for ${url}: ${message}`);
|
|
36
|
-
}
|
|
37
|
-
if (!Array.isArray(raw))
|
|
38
|
-
continue;
|
|
39
|
-
const fallbackHost = new URL(url).hostname;
|
|
40
|
-
for (const cookie of raw) {
|
|
41
|
-
if (filterNames && filterNames.size > 0 && !filterNames.has(cookie.name))
|
|
42
|
-
continue;
|
|
43
|
-
const normalized = normalizeCookie(cookie, fallbackHost);
|
|
44
|
-
if (!normalized)
|
|
45
|
-
continue;
|
|
46
|
-
const key = `${normalized.domain ?? fallbackHost}:${normalized.name}`;
|
|
47
|
-
if (!merged.has(key)) {
|
|
48
|
-
merged.set(key, normalized);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return Array.from(merged.values());
|
|
53
|
-
}
|
|
54
|
-
async function ensureMacKeychainReadable() {
|
|
55
|
-
if (process.platform === 'win32') {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
// chrome-cookies-secure can hang forever when the platform keyring rejects access (e.g., SSH/no GUI).
|
|
59
|
-
// Probe the keyring ourselves with a timeout so callers fail fast instead of blocking the run.
|
|
60
|
-
let keytar = null;
|
|
61
|
-
let keytarPath = null;
|
|
62
|
-
try {
|
|
63
|
-
const require = createRequire(import.meta.url);
|
|
64
|
-
keytarPath = require.resolve('keytar');
|
|
65
|
-
const keytarModule = await import('keytar');
|
|
66
|
-
keytar = (keytarModule.default ?? keytarModule);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
const base = error instanceof Error ? error.message : String(error);
|
|
70
|
-
const rebuildHint = keytarPath
|
|
71
|
-
? ` You may need to rebuild keytar: PYTHON=/usr/bin/python3 /Users/steipete/Projects/oracle/runner npx node-gyp rebuild (run inside ${path.dirname(keytarPath)}).`
|
|
72
|
-
: '';
|
|
73
|
-
throw new Error(`Failed to load keytar for secure cookie copy (${base}). Install keyring deps (macOS Keychain / libsecret) or rerun with --render --copy to paste into ChatGPT manually.${rebuildHint}`);
|
|
74
|
-
}
|
|
75
|
-
const password = await settleWithTimeout(findKeychainPassword(keytar, MAC_KEYCHAIN_LABELS), KEYCHAIN_PROBE_TIMEOUT_MS, `Timed out reading macOS Keychain while looking up Chrome Safe Storage (after ${KEYCHAIN_PROBE_TIMEOUT_MS} ms). Unlock the login keychain or start oracle serve from a GUI session.`);
|
|
76
|
-
if (!password) {
|
|
77
|
-
throw new Error('macOS Keychain denied access to Chrome cookies. Unlock the login keychain or run oracle serve from a GUI session, then retry.');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async function findKeychainPassword(keytar, labels) {
|
|
81
|
-
let lastError = null;
|
|
82
|
-
for (const label of labels) {
|
|
83
|
-
try {
|
|
84
|
-
const value = await keytar.getPassword(label.service, label.account);
|
|
85
|
-
if (value)
|
|
86
|
-
return value;
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (lastError) {
|
|
93
|
-
throw lastError;
|
|
94
|
-
}
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
function settleWithTimeout(promise, timeoutMs, timeoutMessage) {
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
const timer = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
|
|
100
|
-
timer.unref?.();
|
|
101
|
-
promise.then((value) => {
|
|
102
|
-
clearTimeout(timer);
|
|
103
|
-
resolve(value);
|
|
104
|
-
}, (error) => {
|
|
105
|
-
clearTimeout(timer);
|
|
106
|
-
reject(error);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
function normalizeCookie(cookie, fallbackHost) {
|
|
111
|
-
if (!cookie?.name)
|
|
112
|
-
return null;
|
|
113
|
-
const domain = cookie.domain?.startsWith('.') ? cookie.domain.slice(1) : cookie.domain ?? fallbackHost;
|
|
114
|
-
const expires = normalizeExpiration(cookie.expires);
|
|
115
|
-
const secure = typeof cookie.Secure === 'boolean' ? cookie.Secure : true;
|
|
116
|
-
const httpOnly = typeof cookie.HttpOnly === 'boolean' ? cookie.HttpOnly : false;
|
|
117
|
-
return {
|
|
118
|
-
name: cookie.name,
|
|
119
|
-
value: cleanValue(cookie.value ?? ''),
|
|
120
|
-
domain,
|
|
121
|
-
path: cookie.path ?? '/',
|
|
122
|
-
expires,
|
|
123
|
-
secure,
|
|
124
|
-
httpOnly,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function cleanValue(value) {
|
|
128
|
-
let i = 0;
|
|
129
|
-
while (i < value.length && value.charCodeAt(i) < 0x20)
|
|
130
|
-
i += 1;
|
|
131
|
-
return value.slice(i);
|
|
132
|
-
}
|
|
133
|
-
function normalizeExpiration(expires) {
|
|
134
|
-
if (!expires || Number.isNaN(expires)) {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
const value = Number(expires);
|
|
138
|
-
if (value <= 0)
|
|
139
|
-
return undefined;
|
|
140
|
-
if (value > 1_000_000_000_000) {
|
|
141
|
-
return Math.round(value / 1_000_000 - 11644473600);
|
|
142
|
-
}
|
|
143
|
-
if (value > 1_000_000_000) {
|
|
144
|
-
return Math.round(value / 1000);
|
|
145
|
-
}
|
|
146
|
-
return Math.round(value);
|
|
147
|
-
}
|
|
148
|
-
async function resolveCookieFilePath({ explicitPath, profile, }) {
|
|
149
|
-
if (explicitPath && explicitPath.trim().length > 0) {
|
|
150
|
-
return ensureCookieFile(explicitPath);
|
|
151
|
-
}
|
|
152
|
-
if (profile && looksLikePath(profile)) {
|
|
153
|
-
return ensureCookieFile(profile);
|
|
154
|
-
}
|
|
155
|
-
const profileName = profile && profile.trim().length > 0 ? profile : 'Default';
|
|
156
|
-
const baseDir = await defaultProfileRoot();
|
|
157
|
-
return ensureCookieFile(path.join(baseDir, profileName));
|
|
158
|
-
}
|
|
159
|
-
async function adaptPathForChromeCookies(resolved) {
|
|
160
|
-
const stat = await fs.stat(resolved).catch(() => null);
|
|
161
|
-
if (stat?.isFile()) {
|
|
162
|
-
// chrome-cookies-secure appends "Cookies" when given a directory; if we already have the file, return its directory.
|
|
163
|
-
return path.dirname(resolved);
|
|
164
|
-
}
|
|
165
|
-
return resolved;
|
|
166
|
-
}
|
|
167
|
-
async function ensureCookieFile(inputPath) {
|
|
168
|
-
const expanded = expandPath(inputPath);
|
|
169
|
-
const stat = await fs.stat(expanded).catch(() => null);
|
|
170
|
-
if (!stat) {
|
|
171
|
-
throw new Error(`Unable to locate Chrome cookie DB at ${expanded}`);
|
|
172
|
-
}
|
|
173
|
-
if (stat.isDirectory()) {
|
|
174
|
-
const directFile = path.join(expanded, 'Cookies');
|
|
175
|
-
if (await fileExists(directFile))
|
|
176
|
-
return directFile;
|
|
177
|
-
const networkFile = path.join(expanded, 'Network', 'Cookies');
|
|
178
|
-
if (await fileExists(networkFile))
|
|
179
|
-
return networkFile;
|
|
180
|
-
throw new Error(`No Cookies DB found under ${expanded}`);
|
|
181
|
-
}
|
|
182
|
-
return expanded;
|
|
183
|
-
}
|
|
184
|
-
async function fileExists(candidate) {
|
|
185
|
-
try {
|
|
186
|
-
const stat = await fs.stat(candidate);
|
|
187
|
-
return stat.isFile();
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function expandPath(input) {
|
|
194
|
-
if (input.startsWith('~/')) {
|
|
195
|
-
return path.join(os.homedir(), input.slice(2));
|
|
196
|
-
}
|
|
197
|
-
return path.isAbsolute(input) ? input : path.resolve(process.cwd(), input);
|
|
198
|
-
}
|
|
199
|
-
function looksLikePath(value) {
|
|
200
|
-
return value.includes('/') || value.includes('\\');
|
|
201
|
-
}
|
|
202
|
-
async function materializeCookieFile(sourcePath) {
|
|
203
|
-
if (process.platform !== 'win32')
|
|
204
|
-
return sourcePath;
|
|
205
|
-
// Chrome can keep the Cookies DB locked; copy to a temp file so sqlite can open it reliably.
|
|
206
|
-
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'oracle-cookies-'));
|
|
207
|
-
const tempPath = path.join(tempDir, 'Cookies');
|
|
208
|
-
try {
|
|
209
|
-
await fs.copyFile(sourcePath, tempPath);
|
|
210
|
-
return tempPath;
|
|
211
|
-
}
|
|
212
|
-
catch (_error) {
|
|
213
|
-
// Fall back to the original path if the copy fails; upstream error handling will surface issues.
|
|
214
|
-
return sourcePath;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
async function defaultProfileRoot() {
|
|
218
|
-
const candidates = [];
|
|
219
|
-
if (process.platform === 'darwin') {
|
|
220
|
-
candidates.push(path.join(os.homedir(), 'Library', 'Application Support', 'Google', 'Chrome'), path.join(os.homedir(), 'Library', 'Application Support', 'Microsoft Edge'), path.join(os.homedir(), 'Library', 'Application Support', 'Chromium'));
|
|
221
|
-
}
|
|
222
|
-
else if (process.platform === 'linux') {
|
|
223
|
-
if (isWsl()) {
|
|
224
|
-
const windowsHomes = [process.env.USERPROFILE, process.env.WIN_HOME, process.env.HOME?.replace('/home', '/mnt/c/Users')]
|
|
225
|
-
.filter((p) => Boolean(p))
|
|
226
|
-
.map((p) => p.replace(/\\/g, '/'));
|
|
227
|
-
const wslCandidates = [];
|
|
228
|
-
for (const home of windowsHomes) {
|
|
229
|
-
const normalized = home.startsWith('/mnt/') ? home : `/mnt/c/Users/${path.basename(home)}`;
|
|
230
|
-
wslCandidates.push(path.join(normalized, 'AppData', 'Local', 'Google', 'Chrome', 'User Data'), path.join(normalized, 'AppData', 'Local', 'Microsoft', 'Edge', 'User Data'));
|
|
231
|
-
}
|
|
232
|
-
// Ensure we don't pick a non-user Default profile ahead of real ones.
|
|
233
|
-
for (const candidate of wslCandidates) {
|
|
234
|
-
const hasProfile = existsSync(path.join(candidate, 'Default'));
|
|
235
|
-
if (hasProfile) {
|
|
236
|
-
candidates.push(candidate);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
candidates.push(path.join(os.homedir(), '.config', 'google-chrome'), path.join(os.homedir(), '.config', 'microsoft-edge'), path.join(os.homedir(), '.config', 'chromium'),
|
|
241
|
-
// Snap Chromium profiles
|
|
242
|
-
path.join(os.homedir(), 'snap', 'chromium', 'common', 'chromium'), path.join(os.homedir(), 'snap', 'chromium', 'current', 'chromium'));
|
|
243
|
-
}
|
|
244
|
-
else if (process.platform === 'win32') {
|
|
245
|
-
const localAppData = process.env.LOCALAPPDATA ?? path.join(os.homedir(), 'AppData', 'Local');
|
|
246
|
-
candidates.push(path.join(localAppData, 'Google', 'Chrome', 'User Data'), path.join(localAppData, 'Microsoft', 'Edge', 'User Data'), path.join(localAppData, 'Chromium', 'User Data'));
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
250
|
-
}
|
|
251
|
-
for (const candidate of candidates) {
|
|
252
|
-
if (existsSync(candidate)) {
|
|
253
|
-
return candidate;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// fallback: first candidate even if missing; upstream will throw clearer error
|
|
257
|
-
return candidates[0];
|
|
258
|
-
}
|
|
259
|
-
function stripQuery(url) {
|
|
260
|
-
try {
|
|
261
|
-
const parsed = new URL(url);
|
|
262
|
-
parsed.hash = '';
|
|
263
|
-
parsed.search = '';
|
|
264
|
-
return parsed.toString();
|
|
265
|
-
}
|
|
266
|
-
catch {
|
|
267
|
-
return url;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
function readDuration(envKey, fallback) {
|
|
271
|
-
const raw = process.env[envKey];
|
|
272
|
-
if (!raw)
|
|
273
|
-
return fallback;
|
|
274
|
-
const parsed = Number.parseInt(raw, 10);
|
|
275
|
-
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
276
|
-
}
|
|
277
|
-
function isWsl() {
|
|
278
|
-
if (process.platform !== 'linux')
|
|
279
|
-
return false;
|
|
280
|
-
return Boolean(process.env.WSL_DISTRO_NAME || os.release().toLowerCase().includes('microsoft'));
|
|
281
|
-
}
|
|
282
|
-
function loadKeychainLabels() {
|
|
283
|
-
const defaults = [
|
|
284
|
-
{ service: 'Chrome Safe Storage', account: 'Chrome' },
|
|
285
|
-
{ service: 'Chromium Safe Storage', account: 'Chromium' },
|
|
286
|
-
{ service: 'Microsoft Edge Safe Storage', account: 'Microsoft Edge' },
|
|
287
|
-
{ service: 'Brave Safe Storage', account: 'Brave' },
|
|
288
|
-
{ service: 'Vivaldi Safe Storage', account: 'Vivaldi' },
|
|
289
|
-
];
|
|
290
|
-
const rawEnv = process.env.ORACLE_KEYCHAIN_LABELS;
|
|
291
|
-
if (!rawEnv)
|
|
292
|
-
return defaults;
|
|
293
|
-
try {
|
|
294
|
-
const parsed = JSON.parse(rawEnv);
|
|
295
|
-
if (!Array.isArray(parsed))
|
|
296
|
-
return defaults;
|
|
297
|
-
const envLabels = parsed
|
|
298
|
-
.map((entry) => (entry && typeof entry === 'object' ? entry : null))
|
|
299
|
-
.filter((entry) => Boolean(entry?.service && entry?.account));
|
|
300
|
-
return envLabels.length ? [...envLabels, ...defaults] : defaults;
|
|
301
|
-
}
|
|
302
|
-
catch {
|
|
303
|
-
return defaults;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
// biome-ignore lint/style/useNamingConvention: test-only export used in vitest suite
|
|
307
|
-
export const __test__ = {
|
|
308
|
-
normalizeExpiration,
|
|
309
|
-
cleanValue,
|
|
310
|
-
looksLikePath,
|
|
311
|
-
defaultProfileRoot,
|
|
312
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const defaultLabels = [
|
|
2
|
-
{ service: 'Chrome Safe Storage', account: 'Chrome' },
|
|
3
|
-
{ service: 'Chromium Safe Storage', account: 'Chromium' },
|
|
4
|
-
{ service: 'Microsoft Edge Safe Storage', account: 'Microsoft Edge' },
|
|
5
|
-
{ service: 'Brave Safe Storage', account: 'Brave' },
|
|
6
|
-
{ service: 'Vivaldi Safe Storage', account: 'Vivaldi' },
|
|
7
|
-
];
|
|
8
|
-
function loadEnvLabels() {
|
|
9
|
-
const raw = process.env.ORACLE_KEYCHAIN_LABELS;
|
|
10
|
-
if (!raw)
|
|
11
|
-
return [];
|
|
12
|
-
try {
|
|
13
|
-
const parsed = JSON.parse(raw);
|
|
14
|
-
if (Array.isArray(parsed)) {
|
|
15
|
-
return parsed
|
|
16
|
-
.map((entry) => (entry && typeof entry === 'object' ? entry : null))
|
|
17
|
-
.filter((entry) => Boolean(entry?.service && entry?.account));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// ignore invalid env payload
|
|
22
|
-
}
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
const fallbackLabels = [...loadEnvLabels(), ...defaultLabels];
|
|
26
|
-
const disableKeytar = process.env.ORACLE_DISABLE_KEYTAR === '1' || process.env.CI === 'true';
|
|
27
|
-
let keytar;
|
|
28
|
-
if (disableKeytar) {
|
|
29
|
-
keytar = {
|
|
30
|
-
getPassword: async () => null,
|
|
31
|
-
setPassword: async () => undefined,
|
|
32
|
-
deletePassword: async () => false,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const keytarModule = await import('keytar');
|
|
37
|
-
keytar = (keytarModule.default ?? keytarModule);
|
|
38
|
-
const originalGetPassword = keytar.getPassword.bind(keytar);
|
|
39
|
-
keytar.getPassword = async (service, account) => {
|
|
40
|
-
const primary = await originalGetPassword(service, account);
|
|
41
|
-
if (primary) {
|
|
42
|
-
return primary;
|
|
43
|
-
}
|
|
44
|
-
for (const label of fallbackLabels) {
|
|
45
|
-
if (label.service === service && label.account === account) {
|
|
46
|
-
continue; // already tried
|
|
47
|
-
}
|
|
48
|
-
const value = await originalGetPassword(label.service, label.account);
|
|
49
|
-
if (value) {
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
export default keytar;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { mkdir, rm, cp as copyDir } from 'node:fs/promises';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { spawnSync } from 'node:child_process';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { defaultProfileRoot, expandPath, looksLikePath } from './chromeCookies.js';
|
|
6
|
-
const DIR_EXCLUDES = [
|
|
7
|
-
'Cache',
|
|
8
|
-
'Code Cache',
|
|
9
|
-
'GPUCache',
|
|
10
|
-
'Service Worker',
|
|
11
|
-
'Crashpad',
|
|
12
|
-
'BrowserMetrics*',
|
|
13
|
-
'GrShaderCache',
|
|
14
|
-
'ShaderCache',
|
|
15
|
-
'OptimizationGuide',
|
|
16
|
-
];
|
|
17
|
-
const FILE_EXCLUDES = [
|
|
18
|
-
'SingletonLock',
|
|
19
|
-
'SingletonSocket',
|
|
20
|
-
'SingletonCookie',
|
|
21
|
-
'*.lock',
|
|
22
|
-
'lockfile',
|
|
23
|
-
'Lock',
|
|
24
|
-
'*.tmp',
|
|
25
|
-
'DevToolsActivePort',
|
|
26
|
-
path.join('Default', 'DevToolsActivePort'),
|
|
27
|
-
path.join('Sessions', '*'),
|
|
28
|
-
'Current Session',
|
|
29
|
-
'Current Tabs',
|
|
30
|
-
'Last Session',
|
|
31
|
-
'Last Tabs',
|
|
32
|
-
];
|
|
33
|
-
export async function syncChromeProfile(options) {
|
|
34
|
-
const { targetDir } = options;
|
|
35
|
-
await mkdir(targetDir, { recursive: true });
|
|
36
|
-
const { sourceDir, profileName } = await resolveProfileSource(options.profile, options.explicitPath);
|
|
37
|
-
const logger = options.logger;
|
|
38
|
-
if (!existsSync(sourceDir)) {
|
|
39
|
-
throw new Error(`Chrome profile not found at ${sourceDir}. Log in once in Chrome, then retry.`);
|
|
40
|
-
}
|
|
41
|
-
// Clean any stale DevTools ports/locks in the target before copying.
|
|
42
|
-
await rm(targetDir, { recursive: true, force: true }).catch(() => undefined);
|
|
43
|
-
await mkdir(targetDir, { recursive: true });
|
|
44
|
-
const result = process.platform === 'win32'
|
|
45
|
-
? await copyWithRobocopy(sourceDir, targetDir, logger)
|
|
46
|
-
: await copyWithRsync(sourceDir, targetDir, logger);
|
|
47
|
-
// Remove lock files in the copied profile to avoid "already running" errors.
|
|
48
|
-
await removeLocks(targetDir);
|
|
49
|
-
return {
|
|
50
|
-
source: sourceDir,
|
|
51
|
-
profileName,
|
|
52
|
-
method: result.method,
|
|
53
|
-
status: result.copied ? 'copied' : 'skipped',
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
async function copyWithRsync(sourceDir, targetDir, logger) {
|
|
57
|
-
const rsyncArgs = [
|
|
58
|
-
'-a',
|
|
59
|
-
'--delete',
|
|
60
|
-
...DIR_EXCLUDES.flatMap((entry) => ['--exclude', entry]),
|
|
61
|
-
...FILE_EXCLUDES.flatMap((entry) => ['--exclude', entry]),
|
|
62
|
-
`${sourceDir}/`,
|
|
63
|
-
`${targetDir}/`,
|
|
64
|
-
];
|
|
65
|
-
const attempt = spawnSync('rsync', rsyncArgs, { stdio: 'pipe' });
|
|
66
|
-
if (!attempt.error && (attempt.status ?? 0) === 0) {
|
|
67
|
-
return { copied: true, method: 'rsync' };
|
|
68
|
-
}
|
|
69
|
-
logger?.('rsync unavailable or failed; falling back to Node copy');
|
|
70
|
-
await copyDirWithFilter(sourceDir, targetDir);
|
|
71
|
-
return copyWithNodeFs();
|
|
72
|
-
}
|
|
73
|
-
async function copyWithRobocopy(sourceDir, targetDir, logger) {
|
|
74
|
-
const args = [sourceDir, targetDir, '/MIR', '/NFL', '/NDL', '/NJH', '/NJS', '/NP', '/Z'];
|
|
75
|
-
if (DIR_EXCLUDES.length) {
|
|
76
|
-
args.push('/XD', ...DIR_EXCLUDES);
|
|
77
|
-
}
|
|
78
|
-
if (FILE_EXCLUDES.length) {
|
|
79
|
-
args.push('/XF', ...FILE_EXCLUDES);
|
|
80
|
-
}
|
|
81
|
-
const attempt = spawnSync('robocopy', args, { stdio: 'pipe' });
|
|
82
|
-
const exitCode = attempt.status ?? 0;
|
|
83
|
-
// Robocopy treats 0-7 as success/partial success; >=8 is failure.
|
|
84
|
-
if (!attempt.error && exitCode < 8) {
|
|
85
|
-
return { copied: true, method: 'robocopy' };
|
|
86
|
-
}
|
|
87
|
-
logger?.('robocopy failed; falling back to Node copy');
|
|
88
|
-
await copyDirWithFilter(sourceDir, targetDir);
|
|
89
|
-
return copyWithNodeFs();
|
|
90
|
-
}
|
|
91
|
-
function copyWithNodeFs() {
|
|
92
|
-
return { copied: true, method: 'node' };
|
|
93
|
-
}
|
|
94
|
-
function shouldExclude(relativePath) {
|
|
95
|
-
const normalized = relativePath.replace(/\\/g, '/');
|
|
96
|
-
return DIR_EXCLUDES.some((entry) => normalized === entry || normalized.startsWith(`${entry}/`)) ||
|
|
97
|
-
FILE_EXCLUDES.some((entry) => {
|
|
98
|
-
if (entry.endsWith('*')) {
|
|
99
|
-
return normalized.startsWith(entry.slice(0, -1));
|
|
100
|
-
}
|
|
101
|
-
if (entry.includes('*')) {
|
|
102
|
-
// simple glob support for BrowserMetrics*
|
|
103
|
-
const prefix = entry.replace('*', '');
|
|
104
|
-
return normalized.startsWith(prefix);
|
|
105
|
-
}
|
|
106
|
-
return path.basename(normalized) === entry || normalized.endsWith(`/${entry}`);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async function removeLocks(targetDir) {
|
|
110
|
-
const lockNames = ['SingletonLock', 'SingletonSocket', 'SingletonCookie', 'DevToolsActivePort'];
|
|
111
|
-
for (const lock of lockNames) {
|
|
112
|
-
await rm(path.join(targetDir, lock), { force: true }).catch(() => undefined);
|
|
113
|
-
await rm(path.join(targetDir, 'Default', lock), { force: true }).catch(() => undefined);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async function resolveProfileSource(profile, explicitPath) {
|
|
117
|
-
const profileName = profile?.trim() ? profile.trim() : 'Default';
|
|
118
|
-
if (explicitPath?.trim()) {
|
|
119
|
-
const resolved = expandPath(explicitPath.trim());
|
|
120
|
-
if (resolved.toLowerCase().endsWith('cookies')) {
|
|
121
|
-
return { sourceDir: path.dirname(resolved), profileName };
|
|
122
|
-
}
|
|
123
|
-
return { sourceDir: resolved, profileName };
|
|
124
|
-
}
|
|
125
|
-
if (looksLikePath(profileName)) {
|
|
126
|
-
return { sourceDir: expandPath(profileName), profileName };
|
|
127
|
-
}
|
|
128
|
-
const baseRoot = await defaultProfileRoot();
|
|
129
|
-
return { sourceDir: path.join(baseRoot, profileName), profileName };
|
|
130
|
-
}
|
|
131
|
-
async function copyDirWithFilter(sourceDir, targetDir) {
|
|
132
|
-
await copyDir(sourceDir, targetDir, {
|
|
133
|
-
recursive: true,
|
|
134
|
-
filter: async (source) => {
|
|
135
|
-
const rel = path.relative(sourceDir, source);
|
|
136
|
-
if (!rel)
|
|
137
|
-
return true;
|
|
138
|
-
return !shouldExclude(rel);
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
}
|