@indykish/oracle 0.9.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/LICENSE +21 -0
- package/README.md +215 -0
- package/assets-oracle-icon.png +0 -0
- package/dist/bin/oracle-cli.js +1252 -0
- package/dist/bin/oracle-mcp.js +6 -0
- package/dist/scripts/agent-send.js +147 -0
- package/dist/scripts/browser-tools.js +536 -0
- package/dist/scripts/check.js +21 -0
- package/dist/scripts/debug/extract-chatgpt-response.js +53 -0
- package/dist/scripts/docs-list.js +110 -0
- package/dist/scripts/git-policy.js +125 -0
- package/dist/scripts/run-cli.js +14 -0
- package/dist/scripts/runner.js +1378 -0
- package/dist/scripts/test-browser.js +103 -0
- package/dist/scripts/test-remote-chrome.js +68 -0
- package/dist/src/bridge/connection.js +103 -0
- package/dist/src/bridge/userConfigFile.js +28 -0
- package/dist/src/browser/actions/assistantResponse.js +1067 -0
- package/dist/src/browser/actions/attachmentDataTransfer.js +138 -0
- package/dist/src/browser/actions/attachments.js +1910 -0
- package/dist/src/browser/actions/domEvents.js +19 -0
- package/dist/src/browser/actions/modelSelection.js +485 -0
- package/dist/src/browser/actions/navigation.js +445 -0
- package/dist/src/browser/actions/promptComposer.js +485 -0
- package/dist/src/browser/actions/remoteFileTransfer.js +37 -0
- package/dist/src/browser/actions/thinkingTime.js +206 -0
- package/dist/src/browser/chromeLifecycle.js +344 -0
- package/dist/src/browser/config.js +103 -0
- package/dist/src/browser/constants.js +71 -0
- package/dist/src/browser/cookies.js +191 -0
- package/dist/src/browser/detect.js +164 -0
- package/dist/src/browser/domDebug.js +36 -0
- package/dist/src/browser/index.js +1741 -0
- package/dist/src/browser/modelStrategy.js +13 -0
- package/dist/src/browser/pageActions.js +5 -0
- package/dist/src/browser/policies.js +43 -0
- package/dist/src/browser/profileState.js +280 -0
- package/dist/src/browser/prompt.js +152 -0
- package/dist/src/browser/promptSummary.js +20 -0
- package/dist/src/browser/reattach.js +186 -0
- package/dist/src/browser/reattachHelpers.js +382 -0
- package/dist/src/browser/sessionRunner.js +119 -0
- package/dist/src/browser/types.js +1 -0
- package/dist/src/browser/utils.js +122 -0
- package/dist/src/browserMode.js +1 -0
- package/dist/src/cli/bridge/claudeConfig.js +54 -0
- package/dist/src/cli/bridge/client.js +73 -0
- package/dist/src/cli/bridge/codexConfig.js +43 -0
- package/dist/src/cli/bridge/doctor.js +107 -0
- package/dist/src/cli/bridge/host.js +259 -0
- package/dist/src/cli/browserConfig.js +278 -0
- package/dist/src/cli/browserDefaults.js +81 -0
- package/dist/src/cli/bundleWarnings.js +9 -0
- package/dist/src/cli/clipboard.js +10 -0
- package/dist/src/cli/detach.js +11 -0
- package/dist/src/cli/dryRun.js +105 -0
- package/dist/src/cli/duplicatePromptGuard.js +14 -0
- package/dist/src/cli/engine.js +41 -0
- package/dist/src/cli/errorUtils.js +9 -0
- package/dist/src/cli/format.js +13 -0
- package/dist/src/cli/help.js +77 -0
- package/dist/src/cli/hiddenAliases.js +22 -0
- package/dist/src/cli/markdownBundle.js +17 -0
- package/dist/src/cli/markdownRenderer.js +97 -0
- package/dist/src/cli/notifier.js +306 -0
- package/dist/src/cli/options.js +281 -0
- package/dist/src/cli/oscUtils.js +2 -0
- package/dist/src/cli/promptRequirement.js +17 -0
- package/dist/src/cli/renderFlags.js +9 -0
- package/dist/src/cli/renderOutput.js +26 -0
- package/dist/src/cli/rootAlias.js +30 -0
- package/dist/src/cli/runOptions.js +78 -0
- package/dist/src/cli/sessionCommand.js +111 -0
- package/dist/src/cli/sessionDisplay.js +567 -0
- package/dist/src/cli/sessionRunner.js +602 -0
- package/dist/src/cli/sessionTable.js +92 -0
- package/dist/src/cli/tagline.js +258 -0
- package/dist/src/cli/tui/index.js +486 -0
- package/dist/src/cli/writeOutputPath.js +21 -0
- package/dist/src/config.js +26 -0
- package/dist/src/gemini-web/client.js +328 -0
- package/dist/src/gemini-web/executor.js +285 -0
- package/dist/src/gemini-web/index.js +1 -0
- package/dist/src/gemini-web/types.js +1 -0
- package/dist/src/heartbeat.js +43 -0
- package/dist/src/mcp/server.js +40 -0
- package/dist/src/mcp/tools/consult.js +290 -0
- package/dist/src/mcp/tools/sessionResources.js +75 -0
- package/dist/src/mcp/tools/sessions.js +105 -0
- package/dist/src/mcp/types.js +22 -0
- package/dist/src/mcp/utils.js +37 -0
- package/dist/src/oracle/background.js +141 -0
- package/dist/src/oracle/claude.js +101 -0
- package/dist/src/oracle/client.js +197 -0
- package/dist/src/oracle/config.js +227 -0
- package/dist/src/oracle/errors.js +132 -0
- package/dist/src/oracle/files.js +378 -0
- package/dist/src/oracle/finishLine.js +32 -0
- package/dist/src/oracle/format.js +30 -0
- package/dist/src/oracle/fsAdapter.js +10 -0
- package/dist/src/oracle/gemini.js +195 -0
- package/dist/src/oracle/logging.js +36 -0
- package/dist/src/oracle/markdown.js +46 -0
- package/dist/src/oracle/modelResolver.js +183 -0
- package/dist/src/oracle/multiModelRunner.js +153 -0
- package/dist/src/oracle/oscProgress.js +24 -0
- package/dist/src/oracle/promptAssembly.js +13 -0
- package/dist/src/oracle/request.js +50 -0
- package/dist/src/oracle/run.js +596 -0
- package/dist/src/oracle/runUtils.js +31 -0
- package/dist/src/oracle/tokenEstimate.js +37 -0
- package/dist/src/oracle/tokenStats.js +39 -0
- package/dist/src/oracle/tokenStringifier.js +24 -0
- package/dist/src/oracle/types.js +1 -0
- package/dist/src/oracle.js +12 -0
- package/dist/src/oracleHome.js +13 -0
- package/dist/src/remote/client.js +129 -0
- package/dist/src/remote/health.js +113 -0
- package/dist/src/remote/remoteServiceConfig.js +31 -0
- package/dist/src/remote/server.js +533 -0
- package/dist/src/remote/types.js +1 -0
- package/dist/src/sessionManager.js +637 -0
- package/dist/src/sessionStore.js +56 -0
- package/dist/src/version.js +39 -0
- package/dist/vendor/oracle-notifier/OracleNotifier.swift +45 -0
- package/dist/vendor/oracle-notifier/README.md +24 -0
- package/dist/vendor/oracle-notifier/build-notifier.sh +93 -0
- package/package.json +115 -0
- package/vendor/oracle-notifier/OracleNotifier.swift +45 -0
- package/vendor/oracle-notifier/README.md +24 -0
- package/vendor/oracle-notifier/build-notifier.sh +93 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import CDP from 'chrome-remote-interface';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { mkdtemp, mkdir, rm } from 'node:fs/promises';
|
|
5
|
+
import { waitForAssistantResponse, captureAssistantMarkdown, navigateToChatGPT, ensureNotBlocked, ensureLoggedIn, ensurePromptReady, } from './pageActions.js';
|
|
6
|
+
import { launchChrome, connectToChrome, hideChromeWindow } from './chromeLifecycle.js';
|
|
7
|
+
import { resolveBrowserConfig } from './config.js';
|
|
8
|
+
import { syncCookies } from './cookies.js';
|
|
9
|
+
import { CHATGPT_URL } from './constants.js';
|
|
10
|
+
import { cleanupStaleProfileState } from './profileState.js';
|
|
11
|
+
import { pickTarget, extractConversationIdFromUrl, buildConversationUrl, withTimeout, openConversationFromSidebar, openConversationFromSidebarWithRetry, waitForLocationChange, readConversationTurnIndex, buildPromptEchoMatcher, recoverPromptEcho, alignPromptEchoMarkdown, } from './reattachHelpers.js';
|
|
12
|
+
export async function resumeBrowserSession(runtime, config, logger, deps = {}) {
|
|
13
|
+
const recoverSession = deps.recoverSession ??
|
|
14
|
+
(async (runtimeMeta, configMeta) => resumeBrowserSessionViaNewChrome(runtimeMeta, configMeta, logger, deps));
|
|
15
|
+
if (!runtime.chromePort) {
|
|
16
|
+
logger('No running Chrome detected; reopening browser to locate the session.');
|
|
17
|
+
return recoverSession(runtime, config);
|
|
18
|
+
}
|
|
19
|
+
const host = runtime.chromeHost ?? '127.0.0.1';
|
|
20
|
+
try {
|
|
21
|
+
const listTargets = deps.listTargets ??
|
|
22
|
+
(async () => {
|
|
23
|
+
const targets = await CDP.List({ host, port: runtime.chromePort });
|
|
24
|
+
return targets;
|
|
25
|
+
});
|
|
26
|
+
const connect = deps.connect ?? ((options) => CDP(options));
|
|
27
|
+
const targetList = (await listTargets());
|
|
28
|
+
const target = pickTarget(targetList, runtime);
|
|
29
|
+
const client = (await connect({
|
|
30
|
+
host,
|
|
31
|
+
port: runtime.chromePort,
|
|
32
|
+
target: target?.targetId,
|
|
33
|
+
}));
|
|
34
|
+
const { Runtime, DOM } = client;
|
|
35
|
+
if (Runtime?.enable) {
|
|
36
|
+
await Runtime.enable();
|
|
37
|
+
}
|
|
38
|
+
if (DOM && typeof DOM.enable === 'function') {
|
|
39
|
+
await DOM.enable();
|
|
40
|
+
}
|
|
41
|
+
const ensureConversationOpen = async () => {
|
|
42
|
+
const { result } = await Runtime.evaluate({ expression: 'location.href', returnByValue: true });
|
|
43
|
+
const href = typeof result?.value === 'string' ? result.value : '';
|
|
44
|
+
if (href.includes('/c/')) {
|
|
45
|
+
const currentId = extractConversationIdFromUrl(href);
|
|
46
|
+
if (!runtime.conversationId || (currentId && currentId === runtime.conversationId)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const opened = await openConversationFromSidebarWithRetry(Runtime, {
|
|
51
|
+
conversationId: runtime.conversationId ?? extractConversationIdFromUrl(runtime.tabUrl ?? ''),
|
|
52
|
+
preferProjects: true,
|
|
53
|
+
promptPreview: deps.promptPreview,
|
|
54
|
+
}, 15_000);
|
|
55
|
+
if (!opened) {
|
|
56
|
+
throw new Error('Unable to locate prior ChatGPT conversation in sidebar.');
|
|
57
|
+
}
|
|
58
|
+
await waitForLocationChange(Runtime, 15_000);
|
|
59
|
+
};
|
|
60
|
+
const waitForResponse = deps.waitForAssistantResponse ?? waitForAssistantResponse;
|
|
61
|
+
const captureMarkdown = deps.captureAssistantMarkdown ?? captureAssistantMarkdown;
|
|
62
|
+
const timeoutMs = config?.timeoutMs ?? 120_000;
|
|
63
|
+
const pingTimeoutMs = Math.min(5_000, Math.max(1_500, Math.floor(timeoutMs * 0.05)));
|
|
64
|
+
await withTimeout(Runtime.evaluate({ expression: '1+1', returnByValue: true }), pingTimeoutMs, 'Reattach target did not respond');
|
|
65
|
+
await ensureConversationOpen();
|
|
66
|
+
const minTurnIndex = await readConversationTurnIndex(Runtime, logger);
|
|
67
|
+
const promptEcho = buildPromptEchoMatcher(deps.promptPreview);
|
|
68
|
+
const answer = await withTimeout(waitForResponse(Runtime, timeoutMs, logger, minTurnIndex ?? undefined), timeoutMs + 5_000, 'Reattach response timed out');
|
|
69
|
+
const recovered = await recoverPromptEcho(Runtime, answer, promptEcho, logger, minTurnIndex, timeoutMs);
|
|
70
|
+
const markdown = (await withTimeout(captureMarkdown(Runtime, recovered.meta, logger), 15_000, 'Reattach markdown capture timed out')) ?? recovered.text;
|
|
71
|
+
const aligned = alignPromptEchoMarkdown(recovered.text, markdown, promptEcho, logger);
|
|
72
|
+
if (client && typeof client.close === 'function') {
|
|
73
|
+
try {
|
|
74
|
+
await client.close();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// ignore
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return { answerText: aligned.answerText, answerMarkdown: aligned.answerMarkdown };
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
84
|
+
logger(`Existing Chrome reattach failed (${message}); reopening browser to locate the session.`);
|
|
85
|
+
return recoverSession(runtime, config);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function resumeBrowserSessionViaNewChrome(runtime, config, logger, deps) {
|
|
89
|
+
const resolved = resolveBrowserConfig(config ?? {});
|
|
90
|
+
const manualLogin = Boolean(resolved.manualLogin);
|
|
91
|
+
const userDataDir = manualLogin
|
|
92
|
+
? resolved.manualLoginProfileDir ?? path.join(os.homedir(), '.oracle', 'browser-profile')
|
|
93
|
+
: await mkdtemp(path.join(os.tmpdir(), 'oracle-reattach-'));
|
|
94
|
+
if (manualLogin) {
|
|
95
|
+
await mkdir(userDataDir, { recursive: true });
|
|
96
|
+
}
|
|
97
|
+
const chrome = await launchChrome(resolved, userDataDir, logger);
|
|
98
|
+
const chromeHost = chrome.host ?? '127.0.0.1';
|
|
99
|
+
const client = await connectToChrome(chrome.port, logger, chromeHost);
|
|
100
|
+
const { Network, Page, Runtime, DOM } = client;
|
|
101
|
+
if (Runtime?.enable) {
|
|
102
|
+
await Runtime.enable();
|
|
103
|
+
}
|
|
104
|
+
if (DOM && typeof DOM.enable === 'function') {
|
|
105
|
+
await DOM.enable();
|
|
106
|
+
}
|
|
107
|
+
if (!resolved.headless && resolved.hideWindow) {
|
|
108
|
+
await hideChromeWindow(chrome, logger);
|
|
109
|
+
}
|
|
110
|
+
let appliedCookies = 0;
|
|
111
|
+
if (!manualLogin && resolved.cookieSync) {
|
|
112
|
+
appliedCookies = await syncCookies(Network, resolved.url, resolved.chromeProfile, logger, {
|
|
113
|
+
allowErrors: resolved.allowCookieErrors,
|
|
114
|
+
filterNames: resolved.cookieNames ?? undefined,
|
|
115
|
+
inlineCookies: resolved.inlineCookies ?? undefined,
|
|
116
|
+
cookiePath: resolved.chromeCookiePath ?? undefined,
|
|
117
|
+
waitMs: resolved.cookieSyncWaitMs ?? 0,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
await navigateToChatGPT(Page, Runtime, CHATGPT_URL, logger);
|
|
121
|
+
await ensureNotBlocked(Runtime, resolved.headless, logger);
|
|
122
|
+
await ensureLoggedIn(Runtime, logger, { appliedCookies });
|
|
123
|
+
if (resolved.url !== CHATGPT_URL) {
|
|
124
|
+
await navigateToChatGPT(Page, Runtime, resolved.url, logger);
|
|
125
|
+
await ensureNotBlocked(Runtime, resolved.headless, logger);
|
|
126
|
+
}
|
|
127
|
+
await ensurePromptReady(Runtime, resolved.inputTimeoutMs, logger);
|
|
128
|
+
const conversationUrl = buildConversationUrl(runtime, resolved.url);
|
|
129
|
+
if (conversationUrl) {
|
|
130
|
+
logger(`Reopening conversation at ${conversationUrl}`);
|
|
131
|
+
await navigateToChatGPT(Page, Runtime, conversationUrl, logger);
|
|
132
|
+
await ensureNotBlocked(Runtime, resolved.headless, logger);
|
|
133
|
+
await ensurePromptReady(Runtime, resolved.inputTimeoutMs, logger);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const opened = await openConversationFromSidebarWithRetry(Runtime, {
|
|
137
|
+
conversationId: runtime.conversationId ?? extractConversationIdFromUrl(runtime.tabUrl ?? ''),
|
|
138
|
+
preferProjects: resolved.url !== CHATGPT_URL ||
|
|
139
|
+
Boolean(runtime.tabUrl && (/\/g\//.test(runtime.tabUrl) || runtime.tabUrl.includes('/project'))),
|
|
140
|
+
promptPreview: deps.promptPreview,
|
|
141
|
+
}, 15_000);
|
|
142
|
+
if (!opened) {
|
|
143
|
+
throw new Error('Unable to locate prior ChatGPT conversation in sidebar.');
|
|
144
|
+
}
|
|
145
|
+
await waitForLocationChange(Runtime, 15_000);
|
|
146
|
+
}
|
|
147
|
+
const waitForResponse = deps.waitForAssistantResponse ?? waitForAssistantResponse;
|
|
148
|
+
const captureMarkdown = deps.captureAssistantMarkdown ?? captureAssistantMarkdown;
|
|
149
|
+
const timeoutMs = resolved.timeoutMs ?? 120_000;
|
|
150
|
+
const minTurnIndex = await readConversationTurnIndex(Runtime, logger);
|
|
151
|
+
const promptEcho = buildPromptEchoMatcher(deps.promptPreview);
|
|
152
|
+
const answer = await waitForResponse(Runtime, timeoutMs, logger, minTurnIndex ?? undefined);
|
|
153
|
+
const recovered = await recoverPromptEcho(Runtime, answer, promptEcho, logger, minTurnIndex, timeoutMs);
|
|
154
|
+
const markdown = (await captureMarkdown(Runtime, recovered.meta, logger)) ?? recovered.text;
|
|
155
|
+
const aligned = alignPromptEchoMarkdown(recovered.text, markdown, promptEcho, logger);
|
|
156
|
+
if (client && typeof client.close === 'function') {
|
|
157
|
+
try {
|
|
158
|
+
await client.close();
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// ignore
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!resolved.keepBrowser) {
|
|
165
|
+
try {
|
|
166
|
+
await chrome.kill();
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// ignore
|
|
170
|
+
}
|
|
171
|
+
if (manualLogin) {
|
|
172
|
+
await cleanupStaleProfileState(userDataDir, logger, { lockRemovalMode: 'never' }).catch(() => undefined);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
await rm(userDataDir, { recursive: true, force: true }).catch(() => undefined);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { answerText: aligned.answerText, answerMarkdown: aligned.answerMarkdown };
|
|
179
|
+
}
|
|
180
|
+
// biome-ignore lint/style/useNamingConvention: test-only export used in vitest suite
|
|
181
|
+
export const __test__ = {
|
|
182
|
+
pickTarget,
|
|
183
|
+
extractConversationIdFromUrl,
|
|
184
|
+
buildConversationUrl,
|
|
185
|
+
openConversationFromSidebar,
|
|
186
|
+
};
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { CONVERSATION_TURN_SELECTOR } from './constants.js';
|
|
2
|
+
import { delay } from './utils.js';
|
|
3
|
+
import { readAssistantSnapshot } from './pageActions.js';
|
|
4
|
+
export function pickTarget(targets, runtime) {
|
|
5
|
+
if (!Array.isArray(targets) || targets.length === 0) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (runtime.chromeTargetId) {
|
|
9
|
+
const byId = targets.find((t) => t.targetId === runtime.chromeTargetId);
|
|
10
|
+
if (byId)
|
|
11
|
+
return byId;
|
|
12
|
+
}
|
|
13
|
+
if (runtime.tabUrl) {
|
|
14
|
+
const byUrl = targets.find((t) => t.url?.startsWith(runtime.tabUrl)) ||
|
|
15
|
+
targets.find((t) => runtime.tabUrl.startsWith(t.url || ''));
|
|
16
|
+
if (byUrl)
|
|
17
|
+
return byUrl;
|
|
18
|
+
}
|
|
19
|
+
return targets.find((t) => t.type === 'page') ?? targets[0];
|
|
20
|
+
}
|
|
21
|
+
export function extractConversationIdFromUrl(url) {
|
|
22
|
+
if (!url)
|
|
23
|
+
return undefined;
|
|
24
|
+
const match = url.match(/\/c\/([a-zA-Z0-9-]+)/);
|
|
25
|
+
return match?.[1];
|
|
26
|
+
}
|
|
27
|
+
export function buildConversationUrl(runtime, baseUrl) {
|
|
28
|
+
if (runtime.tabUrl) {
|
|
29
|
+
if (runtime.tabUrl.includes('/c/')) {
|
|
30
|
+
return runtime.tabUrl;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const conversationId = runtime.conversationId;
|
|
35
|
+
if (!conversationId) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const base = new URL(baseUrl);
|
|
40
|
+
const pathRoot = base.pathname.replace(/\/$/, '');
|
|
41
|
+
const prefix = pathRoot === '/' ? '' : pathRoot;
|
|
42
|
+
return `${base.origin}${prefix}/c/${conversationId}`;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function withTimeout(task, ms, label) {
|
|
49
|
+
let timeoutId;
|
|
50
|
+
const timeout = new Promise((_, reject) => {
|
|
51
|
+
timeoutId = setTimeout(() => reject(new Error(label)), ms);
|
|
52
|
+
});
|
|
53
|
+
return Promise.race([task, timeout]).finally(() => {
|
|
54
|
+
if (timeoutId) {
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export async function openConversationFromSidebar(Runtime, options, attempt = 0) {
|
|
60
|
+
const response = await Runtime.evaluate({
|
|
61
|
+
expression: `(() => {
|
|
62
|
+
const conversationId = ${JSON.stringify(options.conversationId ?? null)};
|
|
63
|
+
const preferProjects = ${JSON.stringify(Boolean(options.preferProjects))};
|
|
64
|
+
const promptPreview = ${JSON.stringify(options.promptPreview ?? null)};
|
|
65
|
+
const attemptIndex = ${Math.max(0, attempt)};
|
|
66
|
+
const promptNeedleFull = promptPreview ? promptPreview.trim().toLowerCase().slice(0, 100) : '';
|
|
67
|
+
const promptNeedleShort = promptNeedleFull.replace(/\\s*\\d{4,}\\s*$/, '').trim();
|
|
68
|
+
const promptNeedles = Array.from(new Set([promptNeedleFull, promptNeedleShort].filter(Boolean)));
|
|
69
|
+
const nav = document.querySelector('nav') || document.querySelector('aside') || document.body;
|
|
70
|
+
if (preferProjects) {
|
|
71
|
+
const projectLink = Array.from(nav.querySelectorAll('a,button'))
|
|
72
|
+
.find((el) => (el.textContent || '').trim().toLowerCase() === 'projects');
|
|
73
|
+
if (projectLink) {
|
|
74
|
+
projectLink.click();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const allElements = Array.from(
|
|
78
|
+
document.querySelectorAll(
|
|
79
|
+
'a,button,[role="link"],[role="button"],[data-href],[data-url],[data-conversation-id],[data-testid*="conversation"],[data-testid*="history"]',
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
const getHref = (el) =>
|
|
83
|
+
el.getAttribute('href') ||
|
|
84
|
+
el.getAttribute('data-href') ||
|
|
85
|
+
el.getAttribute('data-url') ||
|
|
86
|
+
el.dataset?.href ||
|
|
87
|
+
el.dataset?.url ||
|
|
88
|
+
'';
|
|
89
|
+
const toCandidate = (el) => {
|
|
90
|
+
const clickable = el.closest('a,button,[role="link"],[role="button"]') || el;
|
|
91
|
+
const rawText = (el.textContent || clickable.textContent || '').trim();
|
|
92
|
+
return {
|
|
93
|
+
el,
|
|
94
|
+
clickable,
|
|
95
|
+
href: getHref(clickable) || getHref(el),
|
|
96
|
+
conversationId:
|
|
97
|
+
clickable.getAttribute('data-conversation-id') ||
|
|
98
|
+
el.getAttribute('data-conversation-id') ||
|
|
99
|
+
clickable.dataset?.conversationId ||
|
|
100
|
+
el.dataset?.conversationId ||
|
|
101
|
+
'',
|
|
102
|
+
testId: clickable.getAttribute('data-testid') || el.getAttribute('data-testid') || '',
|
|
103
|
+
text: rawText.replace(/\\s+/g, ' ').slice(0, 400),
|
|
104
|
+
inNav: Boolean(clickable.closest('nav,aside')),
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const candidates = allElements.map(toCandidate);
|
|
108
|
+
const mainCandidates = candidates.filter((item) => !item.inNav);
|
|
109
|
+
const navCandidates = candidates.filter((item) => item.inNav);
|
|
110
|
+
const visible = (item) => {
|
|
111
|
+
const rect = item.clickable.getBoundingClientRect();
|
|
112
|
+
return rect.width > 0 && rect.height > 0;
|
|
113
|
+
};
|
|
114
|
+
const pick = (items) => (items.find(visible) || items[0] || null);
|
|
115
|
+
const pickWithAttempt = (items) => {
|
|
116
|
+
if (!items.length) return null;
|
|
117
|
+
const visibleItems = items.filter(visible);
|
|
118
|
+
const pool = visibleItems.length > 0 ? visibleItems : items;
|
|
119
|
+
const index = Math.min(attemptIndex, pool.length - 1);
|
|
120
|
+
return pool[index] ?? null;
|
|
121
|
+
};
|
|
122
|
+
let target = null;
|
|
123
|
+
if (conversationId) {
|
|
124
|
+
const byId = (item) =>
|
|
125
|
+
(item.href && item.href.includes('/c/' + conversationId)) ||
|
|
126
|
+
(item.conversationId && item.conversationId === conversationId);
|
|
127
|
+
target = pick(mainCandidates.filter(byId)) || pick(navCandidates.filter(byId));
|
|
128
|
+
}
|
|
129
|
+
if (!target && promptNeedles.length > 0) {
|
|
130
|
+
const byPrompt = (item) => promptNeedles.some((needle) => item.text && item.text.toLowerCase().includes(needle));
|
|
131
|
+
const sortBySpecificity = (items) =>
|
|
132
|
+
items
|
|
133
|
+
.filter(byPrompt)
|
|
134
|
+
.sort((a, b) => (a.text?.length ?? 0) - (b.text?.length ?? 0));
|
|
135
|
+
target = pickWithAttempt(sortBySpecificity(mainCandidates)) || pickWithAttempt(sortBySpecificity(navCandidates));
|
|
136
|
+
}
|
|
137
|
+
if (!target) {
|
|
138
|
+
const byHref = (item) => item.href && item.href.includes('/c/');
|
|
139
|
+
target = pickWithAttempt(mainCandidates.filter(byHref)) || pickWithAttempt(navCandidates.filter(byHref));
|
|
140
|
+
}
|
|
141
|
+
if (!target) {
|
|
142
|
+
const byTestId = (item) => /conversation|history/i.test(item.testId || '');
|
|
143
|
+
target = pickWithAttempt(mainCandidates.filter(byTestId)) || pickWithAttempt(navCandidates.filter(byTestId));
|
|
144
|
+
}
|
|
145
|
+
if (target) {
|
|
146
|
+
target.clickable.scrollIntoView({ block: 'center' });
|
|
147
|
+
target.clickable.dispatchEvent(
|
|
148
|
+
new MouseEvent('click', { bubbles: true, cancelable: true, view: window }),
|
|
149
|
+
);
|
|
150
|
+
// Fallback: some project-sidebar items don't navigate on click, force the URL.
|
|
151
|
+
if (target.href && target.href.includes('/c/')) {
|
|
152
|
+
const targetUrl = target.href.startsWith('http')
|
|
153
|
+
? target.href
|
|
154
|
+
: new URL(target.href, location.origin).toString();
|
|
155
|
+
if (targetUrl && targetUrl !== location.href) {
|
|
156
|
+
location.href = targetUrl;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
ok: true,
|
|
161
|
+
href: target.href || '',
|
|
162
|
+
count: candidates.length,
|
|
163
|
+
scope: target.inNav ? 'nav' : 'main',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return { ok: false, count: candidates.length };
|
|
167
|
+
})()`,
|
|
168
|
+
returnByValue: true,
|
|
169
|
+
});
|
|
170
|
+
return Boolean(response.result?.value?.ok);
|
|
171
|
+
}
|
|
172
|
+
export async function openConversationFromSidebarWithRetry(Runtime, options, timeoutMs) {
|
|
173
|
+
const start = Date.now();
|
|
174
|
+
let attempt = 0;
|
|
175
|
+
while (Date.now() - start < timeoutMs) {
|
|
176
|
+
// Retry because project list can hydrate after initial navigation.
|
|
177
|
+
const opened = await openConversationFromSidebar(Runtime, options, attempt);
|
|
178
|
+
if (opened) {
|
|
179
|
+
if (options.promptPreview) {
|
|
180
|
+
const matched = await waitForPromptPreview(Runtime, options.promptPreview, 10_000);
|
|
181
|
+
if (matched) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
attempt += 1;
|
|
190
|
+
await delay(attempt < 5 ? 250 : 500);
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
export async function waitForPromptPreview(Runtime, promptPreview, timeoutMs) {
|
|
195
|
+
const needleFull = promptPreview.trim().toLowerCase().slice(0, 120);
|
|
196
|
+
const needleShort = needleFull.replace(/\\s*\\d{4,}\\s*$/, '').trim();
|
|
197
|
+
const needles = Array.from(new Set([needleFull, needleShort].filter(Boolean)));
|
|
198
|
+
if (needles.length === 0)
|
|
199
|
+
return false;
|
|
200
|
+
const selectorLiteral = JSON.stringify(CONVERSATION_TURN_SELECTOR);
|
|
201
|
+
const expression = `(() => {
|
|
202
|
+
const needles = ${JSON.stringify(needles)};
|
|
203
|
+
const root =
|
|
204
|
+
document.querySelector('section[data-testid="screen-threadFlyOut"]') ||
|
|
205
|
+
document.querySelector('[data-testid="chat-thread"]') ||
|
|
206
|
+
document.querySelector('main') ||
|
|
207
|
+
document.querySelector('[role="main"]');
|
|
208
|
+
if (!root) return false;
|
|
209
|
+
const userTurns = Array.from(root.querySelectorAll('[data-message-author-role="user"], [data-turn="user"]'));
|
|
210
|
+
const collectText = (nodes) =>
|
|
211
|
+
nodes
|
|
212
|
+
.map((node) => (node.innerText || node.textContent || ''))
|
|
213
|
+
.join(' ')
|
|
214
|
+
.toLowerCase();
|
|
215
|
+
let text = collectText(userTurns);
|
|
216
|
+
let hasTurns = userTurns.length > 0;
|
|
217
|
+
if (!text) {
|
|
218
|
+
const turns = Array.from(root.querySelectorAll(${selectorLiteral}));
|
|
219
|
+
hasTurns = hasTurns || turns.length > 0;
|
|
220
|
+
text = collectText(turns);
|
|
221
|
+
}
|
|
222
|
+
if (!text) {
|
|
223
|
+
text = (root.innerText || root.textContent || '').toLowerCase();
|
|
224
|
+
}
|
|
225
|
+
return needles.some((needle) => text.includes(needle));
|
|
226
|
+
})()`;
|
|
227
|
+
const start = Date.now();
|
|
228
|
+
while (Date.now() - start < timeoutMs) {
|
|
229
|
+
try {
|
|
230
|
+
const { result } = await Runtime.evaluate({ expression, returnByValue: true });
|
|
231
|
+
if (result?.value === true) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// ignore
|
|
237
|
+
}
|
|
238
|
+
await delay(300);
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
export async function waitForLocationChange(Runtime, timeoutMs) {
|
|
243
|
+
const start = Date.now();
|
|
244
|
+
let lastHref = '';
|
|
245
|
+
while (Date.now() - start < timeoutMs) {
|
|
246
|
+
const { result } = await Runtime.evaluate({ expression: 'location.href', returnByValue: true });
|
|
247
|
+
const href = typeof result?.value === 'string' ? result.value : '';
|
|
248
|
+
if (lastHref && href !== lastHref) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
lastHref = href;
|
|
252
|
+
await delay(200);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
export async function readConversationTurnIndex(Runtime, logger) {
|
|
256
|
+
const selectorLiteral = JSON.stringify(CONVERSATION_TURN_SELECTOR);
|
|
257
|
+
try {
|
|
258
|
+
const { result } = await Runtime.evaluate({
|
|
259
|
+
expression: `document.querySelectorAll(${selectorLiteral}).length`,
|
|
260
|
+
returnByValue: true,
|
|
261
|
+
});
|
|
262
|
+
const raw = typeof result?.value === 'number' ? result.value : Number(result?.value);
|
|
263
|
+
if (!Number.isFinite(raw)) {
|
|
264
|
+
throw new Error('Turn count not numeric');
|
|
265
|
+
}
|
|
266
|
+
return Math.max(0, Math.floor(raw) - 1);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
if (logger?.verbose) {
|
|
270
|
+
logger(`Failed to read conversation turn index: ${error instanceof Error ? error.message : String(error)}`);
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
function normalizeForComparison(text) {
|
|
276
|
+
return String(text || '').toLowerCase().replace(/\\s+/g, ' ').trim();
|
|
277
|
+
}
|
|
278
|
+
export function buildPromptEchoMatcher(promptPreview) {
|
|
279
|
+
const normalizedPrompt = normalizeForComparison(promptPreview ?? '');
|
|
280
|
+
if (!normalizedPrompt) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
const promptPrefix = normalizedPrompt.length >= 80 ? normalizedPrompt.slice(0, Math.min(200, normalizedPrompt.length)) : '';
|
|
284
|
+
const minFragment = Math.min(40, normalizedPrompt.length);
|
|
285
|
+
return {
|
|
286
|
+
isEcho: (text) => {
|
|
287
|
+
const normalized = normalizeForComparison(text);
|
|
288
|
+
if (!normalized)
|
|
289
|
+
return false;
|
|
290
|
+
if (normalized === normalizedPrompt)
|
|
291
|
+
return true;
|
|
292
|
+
if (promptPrefix.length > 0 && normalized.startsWith(promptPrefix))
|
|
293
|
+
return true;
|
|
294
|
+
if (normalized.length >= minFragment && normalizedPrompt.startsWith(normalized)) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
if (normalized.includes('…') || normalized.includes('...')) {
|
|
298
|
+
const marker = normalized.includes('…') ? '…' : '...';
|
|
299
|
+
const [prefixRaw, suffixRaw] = normalized.split(marker);
|
|
300
|
+
const prefix = prefixRaw?.trim() ?? '';
|
|
301
|
+
const suffix = suffixRaw?.trim() ?? '';
|
|
302
|
+
if (!prefix && !suffix)
|
|
303
|
+
return false;
|
|
304
|
+
if (prefix && !normalizedPrompt.includes(prefix))
|
|
305
|
+
return false;
|
|
306
|
+
if (suffix && !normalizedPrompt.includes(suffix))
|
|
307
|
+
return false;
|
|
308
|
+
const fragmentLength = prefix.length + suffix.length;
|
|
309
|
+
return fragmentLength >= minFragment;
|
|
310
|
+
}
|
|
311
|
+
return false;
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
export async function recoverPromptEcho(Runtime, answer, matcher, logger, minTurnIndex, timeoutMs) {
|
|
316
|
+
if (!matcher || !matcher.isEcho(answer.text)) {
|
|
317
|
+
return answer;
|
|
318
|
+
}
|
|
319
|
+
logger('Detected prompt echo while reattaching; waiting for assistant response...');
|
|
320
|
+
const deadline = Date.now() + Math.min(timeoutMs, 15_000);
|
|
321
|
+
let bestText = null;
|
|
322
|
+
let stableCount = 0;
|
|
323
|
+
while (Date.now() < deadline) {
|
|
324
|
+
const snapshot = await readAssistantSnapshot(Runtime, minTurnIndex ?? undefined).catch(() => null);
|
|
325
|
+
const text = typeof snapshot?.text === 'string' ? snapshot.text.trim() : '';
|
|
326
|
+
if (!text || matcher.isEcho(text)) {
|
|
327
|
+
await delay(300);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (!bestText || text.length > bestText.length) {
|
|
331
|
+
bestText = text;
|
|
332
|
+
stableCount = 0;
|
|
333
|
+
}
|
|
334
|
+
else if (text === bestText) {
|
|
335
|
+
stableCount += 1;
|
|
336
|
+
}
|
|
337
|
+
if (stableCount >= 2) {
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
await delay(300);
|
|
341
|
+
}
|
|
342
|
+
if (bestText) {
|
|
343
|
+
logger('Recovered assistant response after prompt echo during reattach');
|
|
344
|
+
return { ...answer, text: bestText };
|
|
345
|
+
}
|
|
346
|
+
return answer;
|
|
347
|
+
}
|
|
348
|
+
export function alignPromptEchoPair(answerText, answerMarkdown, matcher, logger, messages) {
|
|
349
|
+
if (!matcher) {
|
|
350
|
+
return { answerText, answerMarkdown, textEcho: false, markdownEcho: false, isEcho: false };
|
|
351
|
+
}
|
|
352
|
+
let textEcho = matcher.isEcho(answerText);
|
|
353
|
+
let markdownEcho = matcher.isEcho(answerMarkdown);
|
|
354
|
+
if (textEcho && !markdownEcho && answerMarkdown) {
|
|
355
|
+
if (logger && messages?.text) {
|
|
356
|
+
logger(messages.text);
|
|
357
|
+
}
|
|
358
|
+
answerText = answerMarkdown;
|
|
359
|
+
textEcho = false;
|
|
360
|
+
}
|
|
361
|
+
if (markdownEcho && !textEcho && answerText) {
|
|
362
|
+
if (logger && messages?.markdown) {
|
|
363
|
+
logger(messages.markdown);
|
|
364
|
+
}
|
|
365
|
+
answerMarkdown = answerText;
|
|
366
|
+
markdownEcho = false;
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
answerText,
|
|
370
|
+
answerMarkdown,
|
|
371
|
+
textEcho,
|
|
372
|
+
markdownEcho,
|
|
373
|
+
isEcho: textEcho || markdownEcho,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
export function alignPromptEchoMarkdown(answerText, answerMarkdown, matcher, logger) {
|
|
377
|
+
const aligned = alignPromptEchoPair(answerText, answerMarkdown, matcher, logger, {
|
|
378
|
+
text: 'Aligned prompt-echo text to copied markdown during reattach',
|
|
379
|
+
markdown: 'Aligned prompt-echo markdown to response text during reattach',
|
|
380
|
+
});
|
|
381
|
+
return { answerText: aligned.answerText, answerMarkdown: aligned.answerMarkdown };
|
|
382
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { formatTokenCount } from '../oracle/runUtils.js';
|
|
3
|
+
import { formatFinishLine } from '../oracle/finishLine.js';
|
|
4
|
+
import { runBrowserMode } from '../browserMode.js';
|
|
5
|
+
import { assembleBrowserPrompt } from './prompt.js';
|
|
6
|
+
import { BrowserAutomationError } from '../oracle/errors.js';
|
|
7
|
+
export async function runBrowserSessionExecution({ runOptions, browserConfig, cwd, log }, deps = {}) {
|
|
8
|
+
const assemblePrompt = deps.assemblePrompt ?? assembleBrowserPrompt;
|
|
9
|
+
const executeBrowser = deps.executeBrowser ?? runBrowserMode;
|
|
10
|
+
const promptArtifacts = await assemblePrompt(runOptions, { cwd });
|
|
11
|
+
if (runOptions.verbose) {
|
|
12
|
+
log(chalk.dim(`[verbose] Browser config: ${JSON.stringify({
|
|
13
|
+
...browserConfig,
|
|
14
|
+
})}`));
|
|
15
|
+
log(chalk.dim(`[verbose] Browser prompt length: ${promptArtifacts.composerText.length} chars`));
|
|
16
|
+
if (promptArtifacts.attachments.length > 0) {
|
|
17
|
+
const attachmentList = promptArtifacts.attachments.map((attachment) => attachment.displayPath).join(', ');
|
|
18
|
+
log(chalk.dim(`[verbose] Browser attachments: ${attachmentList}`));
|
|
19
|
+
if (promptArtifacts.bundled) {
|
|
20
|
+
log(chalk.yellow(`[browser] Bundled ${promptArtifacts.bundled.originalCount} files into ${promptArtifacts.bundled.bundlePath}.`));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else if (runOptions.file && runOptions.file.length > 0 && promptArtifacts.attachmentMode === 'inline') {
|
|
24
|
+
log(chalk.dim('[verbose] Browser will paste file contents inline (no uploads).'));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (promptArtifacts.bundled) {
|
|
28
|
+
log(chalk.dim(`Packed ${promptArtifacts.bundled.originalCount} files into 1 bundle (contents counted in token estimate).`));
|
|
29
|
+
}
|
|
30
|
+
const headerLine = `Launching browser mode (${runOptions.model}) with ~${promptArtifacts.estimatedInputTokens.toLocaleString()} tokens.`;
|
|
31
|
+
const automationLogger = ((message) => {
|
|
32
|
+
if (typeof message !== 'string')
|
|
33
|
+
return;
|
|
34
|
+
const shouldAlwaysPrint = message.startsWith('[browser] ') && /fallback|retry/i.test(message);
|
|
35
|
+
if (!runOptions.verbose && !shouldAlwaysPrint)
|
|
36
|
+
return;
|
|
37
|
+
log(message);
|
|
38
|
+
});
|
|
39
|
+
automationLogger.verbose = Boolean(runOptions.verbose);
|
|
40
|
+
automationLogger.sessionLog = runOptions.verbose ? log : (() => { });
|
|
41
|
+
log(headerLine);
|
|
42
|
+
log(chalk.dim('This run can take up to an hour (usually ~10 minutes).'));
|
|
43
|
+
if (runOptions.verbose) {
|
|
44
|
+
log(chalk.dim('Chrome automation does not stream output; this may take a minute...'));
|
|
45
|
+
}
|
|
46
|
+
const persistRuntimeHint = deps.persistRuntimeHint ?? (() => { });
|
|
47
|
+
let browserResult;
|
|
48
|
+
try {
|
|
49
|
+
browserResult = await executeBrowser({
|
|
50
|
+
prompt: promptArtifacts.composerText,
|
|
51
|
+
attachments: promptArtifacts.attachments,
|
|
52
|
+
fallbackSubmission: promptArtifacts.fallback
|
|
53
|
+
? { prompt: promptArtifacts.fallback.composerText, attachments: promptArtifacts.fallback.attachments }
|
|
54
|
+
: undefined,
|
|
55
|
+
config: browserConfig,
|
|
56
|
+
log: automationLogger,
|
|
57
|
+
heartbeatIntervalMs: runOptions.heartbeatIntervalMs,
|
|
58
|
+
verbose: runOptions.verbose,
|
|
59
|
+
runtimeHintCb: async (runtime) => {
|
|
60
|
+
await persistRuntimeHint({ ...runtime, controllerPid: runtime.controllerPid ?? process.pid });
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof BrowserAutomationError) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
const message = error instanceof Error ? error.message : 'Browser automation failed.';
|
|
69
|
+
throw new BrowserAutomationError(message, { stage: 'execute-browser' }, error);
|
|
70
|
+
}
|
|
71
|
+
if (!runOptions.silent) {
|
|
72
|
+
log(chalk.bold('Answer:'));
|
|
73
|
+
log(browserResult.answerMarkdown || browserResult.answerText || chalk.dim('(no text output)'));
|
|
74
|
+
log('');
|
|
75
|
+
}
|
|
76
|
+
const answerText = browserResult.answerMarkdown || browserResult.answerText || '';
|
|
77
|
+
const usage = {
|
|
78
|
+
inputTokens: promptArtifacts.estimatedInputTokens,
|
|
79
|
+
outputTokens: browserResult.answerTokens,
|
|
80
|
+
reasoningTokens: 0,
|
|
81
|
+
totalTokens: promptArtifacts.estimatedInputTokens + browserResult.answerTokens,
|
|
82
|
+
};
|
|
83
|
+
const tokensDisplay = [
|
|
84
|
+
usage.inputTokens,
|
|
85
|
+
usage.outputTokens,
|
|
86
|
+
usage.reasoningTokens,
|
|
87
|
+
usage.totalTokens,
|
|
88
|
+
]
|
|
89
|
+
.map((value) => formatTokenCount(value))
|
|
90
|
+
.join('/');
|
|
91
|
+
const tokensPart = (() => {
|
|
92
|
+
const parts = tokensDisplay.split('/');
|
|
93
|
+
if (parts.length !== 4)
|
|
94
|
+
return tokensDisplay;
|
|
95
|
+
return `↑${parts[0]} ↓${parts[1]} ↻${parts[2]} Δ${parts[3]}`;
|
|
96
|
+
})();
|
|
97
|
+
const { line1, line2 } = formatFinishLine({
|
|
98
|
+
elapsedMs: browserResult.tookMs,
|
|
99
|
+
model: `${runOptions.model}[browser]`,
|
|
100
|
+
tokensPart,
|
|
101
|
+
detailParts: [runOptions.file && runOptions.file.length > 0 ? `files=${runOptions.file.length}` : null],
|
|
102
|
+
});
|
|
103
|
+
log(chalk.blue(line1));
|
|
104
|
+
if (line2) {
|
|
105
|
+
log(chalk.dim(line2));
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
usage,
|
|
109
|
+
elapsedMs: browserResult.tookMs,
|
|
110
|
+
runtime: {
|
|
111
|
+
chromePid: browserResult.chromePid,
|
|
112
|
+
chromePort: browserResult.chromePort,
|
|
113
|
+
chromeHost: browserResult.chromeHost,
|
|
114
|
+
userDataDir: browserResult.userDataDir,
|
|
115
|
+
controllerPid: browserResult.controllerPid ?? process.pid,
|
|
116
|
+
},
|
|
117
|
+
answerText,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|