@steipete/oracle 0.17.2 → 0.17.3
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/bin/oracle-cli.js +0 -0
- package/dist/bin/oracle-mcp.js +0 -0
- package/dist/bin/oracle.js +683 -0
- package/dist/docs-site/bridge.html +1 -17
- package/dist/docs-site/browser-mode.html +18 -26
- package/dist/docs-site/cli-reference.html +6 -6
- package/dist/docs-site/configuration.html +7 -33
- package/dist/docs-site/followup.html +9 -16
- package/dist/docs-site/gemini.html +6 -10
- package/dist/docs-site/index.html +7 -7
- package/dist/docs-site/install.html +1 -1
- package/dist/docs-site/manual-tests.html +2 -4
- package/dist/docs-site/mcp.html +5 -28
- package/dist/docs-site/mythical-pro-agents.html +10 -10
- package/dist/docs-site/openai-endpoints.html +1 -24
- package/dist/docs-site/quickstart.html +1 -1
- package/dist/docs-site/sessions.html +5 -6
- package/dist/docs-site/spec.html +1 -1
- package/dist/docs-site/windows-work.html +1 -2
- package/dist/docs-site/windows.html +1 -1
- package/dist/markdansi/types/index.js +4 -0
- package/dist/oracle/bin/oracle-cli.js +472 -0
- package/dist/oracle/src/browser/actions/assistantResponse.js +471 -0
- package/dist/oracle/src/browser/actions/attachments.js +82 -0
- package/dist/oracle/src/browser/actions/modelSelection.js +190 -0
- package/dist/oracle/src/browser/actions/navigation.js +75 -0
- package/dist/oracle/src/browser/actions/promptComposer.js +167 -0
- package/dist/oracle/src/browser/chromeLifecycle.js +104 -0
- package/dist/oracle/src/browser/config.js +33 -0
- package/dist/oracle/src/browser/constants.js +40 -0
- package/dist/oracle/src/browser/cookies.js +210 -0
- package/dist/oracle/src/browser/domDebug.js +36 -0
- package/dist/oracle/src/browser/index.js +331 -0
- package/dist/oracle/src/browser/pageActions.js +5 -0
- package/dist/oracle/src/browser/prompt.js +88 -0
- package/dist/oracle/src/browser/promptSummary.js +20 -0
- package/dist/oracle/src/browser/sessionRunner.js +80 -0
- package/dist/oracle/src/browser/types.js +1 -0
- package/dist/oracle/src/browser/utils.js +62 -0
- package/dist/oracle/src/browserMode.js +1 -0
- package/dist/oracle/src/cli/browserConfig.js +44 -0
- package/dist/oracle/src/cli/dryRun.js +59 -0
- package/dist/oracle/src/cli/engine.js +17 -0
- package/dist/oracle/src/cli/errorUtils.js +9 -0
- package/dist/oracle/src/cli/help.js +70 -0
- package/dist/oracle/src/cli/markdownRenderer.js +15 -0
- package/dist/oracle/src/cli/options.js +103 -0
- package/dist/oracle/src/cli/promptRequirement.js +14 -0
- package/dist/oracle/src/cli/rootAlias.js +30 -0
- package/dist/oracle/src/cli/sessionCommand.js +77 -0
- package/dist/oracle/src/cli/sessionDisplay.js +270 -0
- package/dist/oracle/src/cli/sessionRunner.js +94 -0
- package/dist/oracle/src/heartbeat.js +43 -0
- package/dist/oracle/src/oracle/client.js +48 -0
- package/dist/oracle/src/oracle/config.js +29 -0
- package/dist/oracle/src/oracle/errors.js +101 -0
- package/dist/oracle/src/oracle/files.js +220 -0
- package/dist/oracle/src/oracle/format.js +33 -0
- package/dist/oracle/src/oracle/fsAdapter.js +7 -0
- package/dist/oracle/src/oracle/oscProgress.js +60 -0
- package/dist/oracle/src/oracle/request.js +48 -0
- package/dist/oracle/src/oracle/run.js +444 -0
- package/dist/oracle/src/oracle/tokenStats.js +39 -0
- package/dist/oracle/src/oracle/types.js +1 -0
- package/dist/oracle/src/oracle.js +9 -0
- package/dist/oracle/src/sessionManager.js +205 -0
- package/dist/oracle/src/version.js +39 -0
- package/dist/scripts/chrome/browser-tools.js +295 -0
- package/dist/src/browser/actions/assistantResponse.js +71 -23
- package/dist/src/browser/actions/thinkingTime.js +16 -9
- package/dist/src/browser/chromeCookies.js +312 -0
- package/dist/src/browser/index.js +5 -1
- package/dist/src/browser/keytarShim.js +56 -0
- package/dist/src/browser/policies.js +4 -0
- package/dist/src/browser/profileSync.js +141 -0
- package/dist/src/browser/projectSourcesRunner.js +2 -2
- package/dist/src/browser/reattach.js +47 -35
- package/dist/src/browser/windowsCookies.js +219 -0
- package/dist/src/cli/browserConfig.js +8 -2
- package/dist/src/cli/browserDefaults.js +6 -1
- package/dist/src/cli/projectSources.js +8 -1
- package/dist/src/mcp/tools/consult.js +1 -1
- package/dist/vendor/oracle-notifier/OracleNotifier.app/Contents/CodeResources +0 -0
- package/dist/vendor/oracle-notifier/OracleNotifier.app/Contents/Info.plist +20 -0
- package/dist/vendor/oracle-notifier/OracleNotifier.app/Contents/MacOS/OracleNotifier +0 -0
- package/dist/vendor/oracle-notifier/OracleNotifier.app/Contents/Resources/OracleIcon.icns +0 -0
- package/dist/vendor/oracle-notifier/OracleNotifier.app/Contents/_CodeSignature/CodeResources +128 -0
- package/package.json +8 -8
- package/vendor/oracle-notifier/OracleNotifier.app/Contents/CodeResources +0 -0
- package/vendor/oracle-notifier/OracleNotifier.app/Contents/Info.plist +20 -0
- package/vendor/oracle-notifier/OracleNotifier.app/Contents/MacOS/OracleNotifier +0 -0
- package/vendor/oracle-notifier/OracleNotifier.app/Contents/Resources/OracleIcon.icns +0 -0
- package/vendor/oracle-notifier/OracleNotifier.app/Contents/_CodeSignature/CodeResources +128 -0
|
@@ -147,12 +147,12 @@ function buildThinkingTimeExpression(level, desiredModel) {
|
|
|
147
147
|
const TARGET_MODEL_KIND = ${targetModelKindLiteral};
|
|
148
148
|
const TARGET_IS_GPT56_MODEL = ${targetIsGpt56ModelLiteral};
|
|
149
149
|
|
|
150
|
-
// Multilingual matchers: English level token + observed German/Chinese variants.
|
|
150
|
+
// Multilingual matchers: English level token + observed German/Japanese/Chinese variants.
|
|
151
151
|
const LEVEL_TOKENS = {
|
|
152
|
-
light: ['light', 'instant', 'sofort', 'leicht', '轻', '极速'],
|
|
153
|
-
standard: ['standard', 'medium', 'mittel', '标准', '中'],
|
|
154
|
-
extended: ['extended', 'high', 'hoch', 'erweitert', '扩展', '深度', '加强', '高'],
|
|
155
|
-
'extra-high': ['extra high', 'sehr hoch', '极高'],
|
|
152
|
+
light: ['light', 'instant', 'sofort', 'leicht', '最速', '轻', '极速'],
|
|
153
|
+
standard: ['standard', 'medium', 'mittel', '中程度', '标准', '中'],
|
|
154
|
+
extended: ['extended', 'high', 'hoch', 'erweitert', '高い', '扩展', '深度', '加强', '高'],
|
|
155
|
+
'extra-high': ['extra high', 'sehr hoch', '非常に高い', '极高'],
|
|
156
156
|
heavy: ['heavy', 'schwer', '重度', '加重'],
|
|
157
157
|
};
|
|
158
158
|
// Pro is a tier you can request, but it is also a MODEL name, so it must never
|
|
@@ -171,7 +171,8 @@ function buildThinkingTimeExpression(level, desiredModel) {
|
|
|
171
171
|
const INTELLIGENCE_WAIT_MS = 2500;
|
|
172
172
|
|
|
173
173
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
174
|
-
// Keep CJK characters
|
|
174
|
+
// Keep CJK characters, including Japanese kana, so localized labels survive
|
|
175
|
+
// normalization before being matched against LEVEL_TOKENS and picker controls.
|
|
175
176
|
const normalize = (value) => (value || '')
|
|
176
177
|
// Compose first so NFD umlauts fold too, then map them onto ASCII before
|
|
177
178
|
// the strip below would drop them (and split the token in half).
|
|
@@ -181,7 +182,7 @@ function buildThinkingTimeExpression(level, desiredModel) {
|
|
|
181
182
|
.replace(/ö/g, 'o')
|
|
182
183
|
.replace(/ü/g, 'u')
|
|
183
184
|
.replace(/ß/g, 'ss')
|
|
184
|
-
.replace(/[^a-z0-9\\u4e00-\\
|
|
185
|
+
.replace(/[^a-z0-9\\u3040-\\u30ff\\u4e00-\\u9fff]+/g, ' ')
|
|
185
186
|
.replace(/\\s+/g, ' ')
|
|
186
187
|
.trim();
|
|
187
188
|
const hasToken = (text, token) => normalize(text).split(' ').includes(token);
|
|
@@ -210,6 +211,9 @@ function buildThinkingTimeExpression(level, desiredModel) {
|
|
|
210
211
|
if (token === 'extra high') return hasPhrase(t, 'extra high');
|
|
211
212
|
if (token === 'hoch') return hasPhrase(t, 'hoch') && !hasPhrase(t, 'sehr hoch');
|
|
212
213
|
if (token === 'sehr hoch') return hasPhrase(t, 'sehr hoch');
|
|
214
|
+
if (token === '高い' || token === '非常に高い') {
|
|
215
|
+
return t === token || hasToken(t, token);
|
|
216
|
+
}
|
|
213
217
|
if (token === '极速') {
|
|
214
218
|
const suffix = t.slice(token.length);
|
|
215
219
|
return t === token || hasToken(t, token) || /^[0-9]/.test(suffix);
|
|
@@ -688,9 +692,12 @@ function buildThinkingTimeExpression(level, desiredModel) {
|
|
|
688
692
|
// Row labels in this menu concatenate without separators ("EffortHigh"), so
|
|
689
693
|
// token matching cannot be used here — substring is deliberate, as in
|
|
690
694
|
// countEffortLevels above.
|
|
691
|
-
const ADVANCED_WORDS = [
|
|
695
|
+
const ADVANCED_WORDS = [
|
|
696
|
+
'advanced', 'erweitert', '高级', '詳細設定', '詳細表示',
|
|
697
|
+
'avanzado', 'avancado', 'avance',
|
|
698
|
+
];
|
|
692
699
|
const EFFORT_WORDS = [
|
|
693
|
-
'effort', 'aufwand', '强度', '努力',
|
|
700
|
+
'effort', 'aufwand', '强度', '努力', '推論レベル',
|
|
694
701
|
'esfuerzo', 'esforco', 'sforzo', 'inspanning', 'wysilek',
|
|
695
702
|
];
|
|
696
703
|
const containsAny = (label, words) => words.some((word) => label.includes(word));
|
|
@@ -0,0 +1,312 @@
|
|
|
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
|
+
};
|
|
@@ -32,6 +32,7 @@ import { captureBrowserDiagnostics } from "./domDebug.js";
|
|
|
32
32
|
import { archiveChatGptConversation, resolveBrowserArchiveDecision, } from "./actions/archiveConversation.js";
|
|
33
33
|
import { assertManualLoginProfileReadyForRun, defaultManualLoginProfileDir, formatManualLoginSetupCommand, isManualLoginProfileInitialized, resolveManualLoginWaitMs, } from "./manualLoginProfile.js";
|
|
34
34
|
import { describeBrowserControlPlan, formatBrowserControlPlan } from "./controlPlan.js";
|
|
35
|
+
import { shouldSyncBrowserCookies } from "./policies.js";
|
|
35
36
|
import { createConversationUrlMonitor, } from "./conversationUrlMonitor.js";
|
|
36
37
|
import { extractStableConversationIdFromUrl as extractConversationIdFromUrl, isStableConversationUrl as isConversationUrl, } from "./conversationUrl.js";
|
|
37
38
|
export { CHATGPT_URL, DEFAULT_MODEL_STRATEGY, DEFAULT_MODEL_TARGET } from "./constants.js";
|
|
@@ -864,7 +865,10 @@ export async function runBrowserMode(options) {
|
|
|
864
865
|
await Network.clearBrowserCookies();
|
|
865
866
|
}
|
|
866
867
|
const manualLoginCookieSync = manualLogin && Boolean(config.manualLoginCookieSync);
|
|
867
|
-
const cookieSyncEnabled = config
|
|
868
|
+
const cookieSyncEnabled = shouldSyncBrowserCookies(config, {
|
|
869
|
+
manualLogin,
|
|
870
|
+
profileIsPreSigned,
|
|
871
|
+
});
|
|
868
872
|
if (cookieSyncEnabled) {
|
|
869
873
|
if (manualLoginCookieSync) {
|
|
870
874
|
logger("Manual login mode: seeding persistent profile with cookies from your Chrome profile.");
|
|
@@ -0,0 +1,56 @@
|
|
|
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;
|
|
@@ -24,6 +24,10 @@ export function buildAttachmentPlan(sections, { inlineFiles, bundleRequested, ma
|
|
|
24
24
|
shouldBundle,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
+
export function shouldSyncBrowserCookies(config, { manualLogin, profileIsPreSigned = manualLogin, }) {
|
|
28
|
+
const explicitManualLoginSync = manualLogin && config.manualLoginCookieSync === true;
|
|
29
|
+
return config.cookieSync && (!profileIsPreSigned || explicitManualLoginSync);
|
|
30
|
+
}
|
|
27
31
|
export function buildCookiePlan(config) {
|
|
28
32
|
if (config?.inlineCookies && config.inlineCookies.length > 0) {
|
|
29
33
|
const source = config.inlineCookiesSource ?? "inline";
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
}
|
|
@@ -13,6 +13,7 @@ import { assertManualLoginProfileReadyForRun, defaultManualLoginProfileDir, form
|
|
|
13
13
|
import { openProjectSourcesTab, uploadProjectSources, waitForProjectSourcesReady, waitForProjectSourcesListSettled, } from "./actions/projectSources.js";
|
|
14
14
|
import { normalizeProjectSourcesUrl } from "../projectSources/url.js";
|
|
15
15
|
import { buildProjectSourcesUploadPlan, diffAddedProjectSources } from "../projectSources/plan.js";
|
|
16
|
+
import { shouldSyncBrowserCookies } from "./policies.js";
|
|
16
17
|
export async function runBrowserProjectSources(request) {
|
|
17
18
|
const startedAt = Date.now();
|
|
18
19
|
const logger = ((message) => request.log?.(message));
|
|
@@ -248,8 +249,7 @@ export async function runBrowserProjectSources(request) {
|
|
|
248
249
|
}
|
|
249
250
|
}
|
|
250
251
|
async function applyProjectSourcesCookies({ config, network, manualLogin, logger, }) {
|
|
251
|
-
const
|
|
252
|
-
const cookieSyncEnabled = config.cookieSync && (!manualLogin || manualLoginCookieSync);
|
|
252
|
+
const cookieSyncEnabled = shouldSyncBrowserCookies(config, { manualLogin });
|
|
253
253
|
if (!cookieSyncEnabled) {
|
|
254
254
|
logger(manualLogin
|
|
255
255
|
? "Skipping Chrome cookie sync (--browser-manual-login enabled); reuse the opened profile after signing in."
|