@causyne/agent 1.20.70 → 1.20.72

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.70",
3
+ "version": "1.20.72",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
Binary file
@@ -7,7 +7,9 @@
7
7
  */
8
8
  import http from 'node:http';
9
9
  import crypto from 'node:crypto';
10
- import { URL } from 'node:url';
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+ import { fileURLToPath, URL } from 'node:url';
11
13
  import { loadConfig, saveConfig } from '../config.js';
12
14
  import { openWithNativeOS } from '../tools/desktopOpen.js';
13
15
  export const OPENROUTER_AUTH_URL = 'https://openrouter.ai/auth';
@@ -91,6 +93,180 @@ export async function exchangeCodeForApiKey(code, codeVerifier, fetchFn = fetch)
91
93
  }
92
94
  return apiKey;
93
95
  }
96
+ /**
97
+ * Retrieve the Causyne Agent emblem logo as a binary buffer if available.
98
+ */
99
+ export function getLogoBuffer() {
100
+ try {
101
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
102
+ const assetPath = path.resolve(currentDir, '../assets/logo.png');
103
+ if (fs.existsSync(assetPath)) {
104
+ return fs.readFileSync(assetPath);
105
+ }
106
+ }
107
+ catch {
108
+ // Ignore read errors
109
+ }
110
+ return null;
111
+ }
112
+ /**
113
+ * Retrieve the Causyne Agent emblem logo encoded as Base64.
114
+ */
115
+ export function getLogoBase64() {
116
+ const buf = getLogoBuffer();
117
+ return buf ? buf.toString('base64') : '';
118
+ }
119
+ /**
120
+ * Render a professional branded HTML response page for OpenRouter OAuth callbacks.
121
+ */
122
+ export function renderAuthPage(options) {
123
+ const isSuccess = options.status === 'success';
124
+ const base64Logo = getLogoBase64();
125
+ const logoSrc = base64Logo ? `data:image/png;base64,${base64Logo}` : '/logo.png';
126
+ const badgeHtml = isSuccess
127
+ ? '<div style="display:inline-flex;align-items:center;gap:8px;' +
128
+ 'background:rgba(46,160,67,0.15);border:1px solid #2ea043;color:#3fb950;' +
129
+ 'padding:6px 18px;border-radius:24px;font-size:13px;font-weight:600;margin-bottom:20px;">' +
130
+ '✓ Connected Successfully</div>'
131
+ : '<div style="display:inline-flex;align-items:center;gap:8px;' +
132
+ 'background:rgba(239,68,68,0.15);border:1px solid #ef4444;color:#f87171;' +
133
+ 'padding:6px 18px;border-radius:24px;font-size:13px;font-weight:600;margin-bottom:20px;">' +
134
+ '✕ Authorization Failed</div>';
135
+ const title = options.title || (isSuccess ? 'OpenRouter Account Authorized' : 'Authorization Error');
136
+ const defaultMsg = isSuccess
137
+ ? 'Your OpenRouter account has been connected to Causyne Agent. You can now close this tab and return to your terminal.'
138
+ : 'The authorization flow could not be completed.';
139
+ const message = options.message || defaultMsg;
140
+ const contentBox = isSuccess
141
+ ? '<div style="background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.08);' +
142
+ 'border-radius:10px;padding:14px 18px;margin-bottom:28px;text-align:left;font-family:monospace;' +
143
+ 'font-size:13px;color:#cbd5e1;">' +
144
+ '<div style="display:flex;justify-content:space-between;margin-bottom:8px;">' +
145
+ '<span style="color:#64748b;">Active Model</span>' +
146
+ `<span style="color:#9df028;font-weight:600;">${options.model || OPENROUTER_FREE_MODEL}</span>` +
147
+ '</div>' +
148
+ '<div style="display:flex;justify-content:space-between;">' +
149
+ '<span style="color:#64748b;">Privacy Guard</span>' +
150
+ '<span style="color:#38bdf8;">provider.data_collection = &quot;deny&quot;</span>' +
151
+ '</div>' +
152
+ '</div>'
153
+ : '<div style="background:rgba(239,68,68,0.08);border:1px solid rgba(239,68,68,0.25);' +
154
+ 'border-radius:10px;padding:14px;color:#fca5a5;font-size:13px;line-height:1.5;margin-bottom:20px;' +
155
+ `text-align:left;">${options.errorDetail || 'An unexpected error occurred during authorization.'}</div>` +
156
+ '<div style="background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.08);' +
157
+ 'border-radius:10px;padding:16px;margin-bottom:24px;text-align:left;">' +
158
+ '<div style="color:#ffffff;font-size:13px;font-weight:600;margin-bottom:8px;">Recommended Solutions:</div>' +
159
+ '<ol style="color:#94a3b8;font-size:13px;line-height:1.6;margin:0;padding-left:18px;">' +
160
+ '<li>Return to your terminal and select OpenRouter in the FREE tab again to retry.</li>' +
161
+ '<li>Or create a free API key at <a href="https://openrouter.ai/keys" target="_blank" ' +
162
+ 'style="color:#38bdf8;text-decoration:none;">openrouter.ai/keys</a> and configure it via:</li>' +
163
+ '</ol>' +
164
+ '<pre style="background:#05070a;color:#9df028;padding:10px 14px;border-radius:6px;font-family:monospace;' +
165
+ 'font-size:12px;margin-top:10px;overflow-x:auto;">causyne config set providerKeys.openrouter &lt;your-key&gt;</pre>' +
166
+ '</div>';
167
+ const actionButton = isSuccess
168
+ ? '<button onclick="window.close()" style="background:#9df028;color:#080b11;border:none;' +
169
+ 'padding:12px 28px;border-radius:8px;font-size:14px;font-weight:700;cursor:pointer;font-family:inherit;">' +
170
+ 'Return to Terminal</button>' +
171
+ '<div style="font-size:12px;color:#64748b;margin-top:14px;">You can safely close this browser window.</div>'
172
+ : '<button onclick="window.close()" style="background:#334155;color:#f8fafc;border:none;' +
173
+ 'padding:10px 24px;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer;font-family:inherit;">' +
174
+ 'Close Window</button>';
175
+ return `<!DOCTYPE html>
176
+ <html lang="en">
177
+ <head>
178
+ <meta charset="utf-8">
179
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
180
+ <title>Causyne Agent Connected Successfully</title>
181
+ <style>
182
+ * { box-sizing: border-box; margin: 0; padding: 0; }
183
+ body {
184
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
185
+ background: #080b11 radial-gradient(circle at 50% 20%, #152238 0%, #080b11 75%);
186
+ color: #c9d1d9;
187
+ min-height: 100vh;
188
+ display: flex;
189
+ align-items: center;
190
+ justify-content: center;
191
+ padding: 24px;
192
+ }
193
+ .container {
194
+ max-width: 540px;
195
+ width: 100%;
196
+ text-align: center;
197
+ }
198
+ .header {
199
+ display: flex;
200
+ align-items: center;
201
+ justify-content: center;
202
+ gap: 16px;
203
+ margin-bottom: 28px;
204
+ }
205
+ .logo {
206
+ width: 52px;
207
+ height: 52px;
208
+ object-fit: contain;
209
+ border-radius: 12px;
210
+ filter: drop-shadow(0 4px 16px rgba(157, 240, 40, 0.3));
211
+ }
212
+ .brand-title {
213
+ font-family: "JetBrains Mono", SFMono-Regular, Menlo, Consolas, monospace;
214
+ font-size: 24px;
215
+ font-weight: 800;
216
+ letter-spacing: 1.5px;
217
+ color: #ffffff;
218
+ line-height: 1.2;
219
+ }
220
+ .brand-subtitle {
221
+ font-size: 11px;
222
+ color: #8a99a8;
223
+ letter-spacing: 1px;
224
+ text-transform: uppercase;
225
+ margin-top: 2px;
226
+ text-align: left;
227
+ }
228
+ .card {
229
+ background: rgba(18, 25, 38, 0.95);
230
+ border: 1px solid rgba(157, 240, 40, 0.22);
231
+ border-radius: 16px;
232
+ padding: 36px 32px;
233
+ box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
234
+ backdrop-filter: blur(16px);
235
+ }
236
+ h1 {
237
+ color: #ffffff;
238
+ font-size: 21px;
239
+ font-weight: 700;
240
+ margin-bottom: 12px;
241
+ }
242
+ p {
243
+ color: #94a3b8;
244
+ font-size: 14px;
245
+ line-height: 1.6;
246
+ margin-bottom: 24px;
247
+ }
248
+ </style>
249
+ </head>
250
+ <body>
251
+ <div class="container">
252
+ <div class="header">
253
+ <img src="${logoSrc}" alt="Causyne Agent Logo" class="logo" />
254
+ <div>
255
+ <div class="brand-title">CAUSYNE <span style="color:#9df028;">AGENT</span></div>
256
+ <div class="brand-subtitle">Autonomous AI Harness</div>
257
+ </div>
258
+ </div>
259
+ <div class="card">
260
+ ${badgeHtml}
261
+ <h1>${title}</h1>
262
+ <p>${message}</p>
263
+ ${contentBox}
264
+ ${actionButton}
265
+ </div>
266
+ </div>
267
+ </body>
268
+ </html>`;
269
+ }
94
270
  /**
95
271
  * Start loopback HTTP server on 127.0.0.1 to receive the OAuth redirect code.
96
272
  */
@@ -117,6 +293,21 @@ export async function startLoopbackAuth(options = {}) {
117
293
  const server = http.createServer(async (req, res) => {
118
294
  try {
119
295
  const reqUrl = new URL(req.url || '/', `http://${req.headers.host || '127.0.0.1'}`);
296
+ if (reqUrl.pathname === '/logo.png') {
297
+ const logoBuf = getLogoBuffer();
298
+ if (logoBuf) {
299
+ res.writeHead(200, {
300
+ 'Content-Type': 'image/png',
301
+ 'Content-Length': logoBuf.length,
302
+ 'Cache-Control': 'public, max-age=3600'
303
+ });
304
+ res.end(logoBuf);
305
+ return;
306
+ }
307
+ res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
308
+ res.end('Not Found');
309
+ return;
310
+ }
120
311
  if (reqUrl.pathname !== '/callback') {
121
312
  res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
122
313
  res.end('Not Found');
@@ -126,10 +317,11 @@ export async function startLoopbackAuth(options = {}) {
126
317
  const state = reqUrl.searchParams.get('state');
127
318
  if (!state || state !== pkce.state) {
128
319
  res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });
129
- res.end('<html><body style="font-family:sans-serif;padding:32px;background:#111;color:#eee;">' +
130
- '<h2 style="color:#ef4444;">Authorization Error: State Mismatch</h2>' +
131
- '<p>The received CSRF verification state did not match the session. Please try again.</p>' +
132
- '</body></html>');
320
+ res.end(renderAuthPage({
321
+ status: 'error',
322
+ title: 'Authorization Error: State Mismatch',
323
+ errorDetail: 'The received CSRF verification state did not match the active session. This can happen if the authorization request timed out or was tampered with.'
324
+ }));
133
325
  if (!resolved) {
134
326
  resolved = true;
135
327
  cleanup();
@@ -139,10 +331,11 @@ export async function startLoopbackAuth(options = {}) {
139
331
  }
140
332
  if (!code) {
141
333
  res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });
142
- res.end('<html><body style="font-family:sans-serif;padding:32px;background:#111;color:#eee;">' +
143
- '<h2 style="color:#ef4444;">Authorization Failed</h2>' +
144
- '<p>No authorization code was returned by OpenRouter.</p>' +
145
- '</body></html>');
334
+ res.end(renderAuthPage({
335
+ status: 'error',
336
+ title: 'Authorization Failed',
337
+ errorDetail: 'No authorization code was returned by OpenRouter.'
338
+ }));
146
339
  if (!resolved) {
147
340
  resolved = true;
148
341
  cleanup();
@@ -152,15 +345,15 @@ export async function startLoopbackAuth(options = {}) {
152
345
  }
153
346
  // Send friendly HTML response to user's browser
154
347
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
155
- res.end('<html><body style="font-family:sans-serif;padding:40px;background:#0d1117;color:#c9d1d9;text-align:center;">' +
156
- '<h2 style="color:#2ea043;margin-bottom:12px;">Causyne Agent Connected Successfully</h2>' +
157
- '<p style="font-size:16px;color:#8b949e;">Your OpenRouter account has been authorized. You can close this window and return to your terminal.</p>' +
158
- '</body></html>');
348
+ res.end(renderAuthPage({
349
+ status: 'success',
350
+ model: OPENROUTER_FREE_MODEL
351
+ }));
159
352
  // Perform token exchange
160
353
  const apiKey = await exchangeCodeForApiKey(code, pkce.codeVerifier, fetchFn);
161
354
  if (!resolved) {
162
355
  resolved = true;
163
- cleanup();
356
+ setTimeout(cleanup, 1200);
164
357
  resolve({ apiKey });
165
358
  }
166
359
  }
@@ -256,10 +449,30 @@ export function disconnectOpenRouter(store = { loadConfig, saveConfig }) {
256
449
  };
257
450
  delete providerKeys['openrouter'];
258
451
  currentConfig.providerKeys = providerKeys;
452
+ if (process.env.OPENROUTER_API_KEY) {
453
+ delete process.env.OPENROUTER_API_KEY;
454
+ }
259
455
  if (currentConfig.provider === 'openrouter') {
260
- currentConfig.provider = 'deepseek';
261
- currentConfig.model = 'deepseek-chat';
262
- currentConfig.apiKey = providerKeys['deepseek'] || '';
456
+ if (providerKeys['deepseek']) {
457
+ currentConfig.provider = 'deepseek';
458
+ currentConfig.model = 'deepseek-chat';
459
+ currentConfig.apiKey = providerKeys['deepseek'];
460
+ }
461
+ else if (providerKeys['anthropic']) {
462
+ currentConfig.provider = 'anthropic';
463
+ currentConfig.model = 'claude-3-7-sonnet';
464
+ currentConfig.apiKey = providerKeys['anthropic'];
465
+ }
466
+ else if (providerKeys['openai']) {
467
+ currentConfig.provider = 'openai';
468
+ currentConfig.model = 'gpt-4o';
469
+ currentConfig.apiKey = providerKeys['openai'];
470
+ }
471
+ else {
472
+ currentConfig.provider = 'antigravity';
473
+ currentConfig.model = 'Gemini 3.8 Flash (Low)';
474
+ currentConfig.apiKey = '';
475
+ }
263
476
  }
264
477
  store.saveConfig(currentConfig);
265
478
  return currentConfig;
@@ -8,7 +8,9 @@
8
8
 
9
9
  import http from 'node:http';
10
10
  import crypto from 'node:crypto';
11
- import { URL } from 'node:url';
11
+ import fs from 'node:fs';
12
+ import path from 'node:path';
13
+ import { fileURLToPath, URL } from 'node:url';
12
14
  import { loadConfig, saveConfig } from '../config.js';
13
15
  import { openWithNativeOS } from '../tools/desktopOpen.js';
14
16
 
@@ -126,6 +128,195 @@ export async function exchangeCodeForApiKey(
126
128
  return apiKey;
127
129
  }
128
130
 
131
+ /**
132
+ * Retrieve the Causyne Agent emblem logo as a binary buffer if available.
133
+ */
134
+ export function getLogoBuffer(): Buffer | null {
135
+ try {
136
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
137
+ const assetPath = path.resolve(currentDir, '../assets/logo.png');
138
+ if (fs.existsSync(assetPath)) {
139
+ return fs.readFileSync(assetPath);
140
+ }
141
+ } catch {
142
+ // Ignore read errors
143
+ }
144
+ return null;
145
+ }
146
+
147
+ /**
148
+ * Retrieve the Causyne Agent emblem logo encoded as Base64.
149
+ */
150
+ export function getLogoBase64(): string {
151
+ const buf = getLogoBuffer();
152
+ return buf ? buf.toString('base64') : '';
153
+ }
154
+
155
+ export interface RenderAuthPageOptions {
156
+ status: 'success' | 'error';
157
+ title?: string | undefined;
158
+ message?: string | undefined;
159
+ errorDetail?: string | undefined;
160
+ model?: string | undefined;
161
+ }
162
+
163
+ /**
164
+ * Render a professional branded HTML response page for OpenRouter OAuth callbacks.
165
+ */
166
+ export function renderAuthPage(options: RenderAuthPageOptions): string {
167
+ const isSuccess = options.status === 'success';
168
+ const base64Logo = getLogoBase64();
169
+ const logoSrc = base64Logo ? `data:image/png;base64,${base64Logo}` : '/logo.png';
170
+
171
+ const badgeHtml = isSuccess
172
+ ? '<div style="display:inline-flex;align-items:center;gap:8px;' +
173
+ 'background:rgba(46,160,67,0.15);border:1px solid #2ea043;color:#3fb950;' +
174
+ 'padding:6px 18px;border-radius:24px;font-size:13px;font-weight:600;margin-bottom:20px;">' +
175
+ '✓ Connected Successfully</div>'
176
+ : '<div style="display:inline-flex;align-items:center;gap:8px;' +
177
+ 'background:rgba(239,68,68,0.15);border:1px solid #ef4444;color:#f87171;' +
178
+ 'padding:6px 18px;border-radius:24px;font-size:13px;font-weight:600;margin-bottom:20px;">' +
179
+ '✕ Authorization Failed</div>';
180
+
181
+ const title = options.title || (isSuccess ? 'OpenRouter Account Authorized' : 'Authorization Error');
182
+ const defaultMsg = isSuccess
183
+ ? 'Your OpenRouter account has been connected to Causyne Agent. You can now close this tab and return to your terminal.'
184
+ : 'The authorization flow could not be completed.';
185
+ const message = options.message || defaultMsg;
186
+
187
+ const contentBox = isSuccess
188
+ ? '<div style="background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.08);' +
189
+ 'border-radius:10px;padding:14px 18px;margin-bottom:28px;text-align:left;font-family:monospace;' +
190
+ 'font-size:13px;color:#cbd5e1;">' +
191
+ '<div style="display:flex;justify-content:space-between;margin-bottom:8px;">' +
192
+ '<span style="color:#64748b;">Active Model</span>' +
193
+ `<span style="color:#9df028;font-weight:600;">${options.model || OPENROUTER_FREE_MODEL}</span>` +
194
+ '</div>' +
195
+ '<div style="display:flex;justify-content:space-between;">' +
196
+ '<span style="color:#64748b;">Privacy Guard</span>' +
197
+ '<span style="color:#38bdf8;">provider.data_collection = &quot;deny&quot;</span>' +
198
+ '</div>' +
199
+ '</div>'
200
+ : '<div style="background:rgba(239,68,68,0.08);border:1px solid rgba(239,68,68,0.25);' +
201
+ 'border-radius:10px;padding:14px;color:#fca5a5;font-size:13px;line-height:1.5;margin-bottom:20px;' +
202
+ `text-align:left;">${options.errorDetail || 'An unexpected error occurred during authorization.'}</div>` +
203
+ '<div style="background:rgba(255,255,255,0.03);border:1px solid rgba(255,255,255,0.08);' +
204
+ 'border-radius:10px;padding:16px;margin-bottom:24px;text-align:left;">' +
205
+ '<div style="color:#ffffff;font-size:13px;font-weight:600;margin-bottom:8px;">Recommended Solutions:</div>' +
206
+ '<ol style="color:#94a3b8;font-size:13px;line-height:1.6;margin:0;padding-left:18px;">' +
207
+ '<li>Return to your terminal and select OpenRouter in the FREE tab again to retry.</li>' +
208
+ '<li>Or create a free API key at <a href="https://openrouter.ai/keys" target="_blank" ' +
209
+ 'style="color:#38bdf8;text-decoration:none;">openrouter.ai/keys</a> and configure it via:</li>' +
210
+ '</ol>' +
211
+ '<pre style="background:#05070a;color:#9df028;padding:10px 14px;border-radius:6px;font-family:monospace;' +
212
+ 'font-size:12px;margin-top:10px;overflow-x:auto;">causyne config set providerKeys.openrouter &lt;your-key&gt;</pre>' +
213
+ '</div>';
214
+
215
+ const actionButton = isSuccess
216
+ ? '<button onclick="window.close()" style="background:#9df028;color:#080b11;border:none;' +
217
+ 'padding:12px 28px;border-radius:8px;font-size:14px;font-weight:700;cursor:pointer;font-family:inherit;">' +
218
+ 'Return to Terminal</button>' +
219
+ '<div style="font-size:12px;color:#64748b;margin-top:14px;">You can safely close this browser window.</div>'
220
+ : '<button onclick="window.close()" style="background:#334155;color:#f8fafc;border:none;' +
221
+ 'padding:10px 24px;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer;font-family:inherit;">' +
222
+ 'Close Window</button>';
223
+
224
+ return `<!DOCTYPE html>
225
+ <html lang="en">
226
+ <head>
227
+ <meta charset="utf-8">
228
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
229
+ <title>Causyne Agent Connected Successfully</title>
230
+ <style>
231
+ * { box-sizing: border-box; margin: 0; padding: 0; }
232
+ body {
233
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
234
+ background: #080b11 radial-gradient(circle at 50% 20%, #152238 0%, #080b11 75%);
235
+ color: #c9d1d9;
236
+ min-height: 100vh;
237
+ display: flex;
238
+ align-items: center;
239
+ justify-content: center;
240
+ padding: 24px;
241
+ }
242
+ .container {
243
+ max-width: 540px;
244
+ width: 100%;
245
+ text-align: center;
246
+ }
247
+ .header {
248
+ display: flex;
249
+ align-items: center;
250
+ justify-content: center;
251
+ gap: 16px;
252
+ margin-bottom: 28px;
253
+ }
254
+ .logo {
255
+ width: 52px;
256
+ height: 52px;
257
+ object-fit: contain;
258
+ border-radius: 12px;
259
+ filter: drop-shadow(0 4px 16px rgba(157, 240, 40, 0.3));
260
+ }
261
+ .brand-title {
262
+ font-family: "JetBrains Mono", SFMono-Regular, Menlo, Consolas, monospace;
263
+ font-size: 24px;
264
+ font-weight: 800;
265
+ letter-spacing: 1.5px;
266
+ color: #ffffff;
267
+ line-height: 1.2;
268
+ }
269
+ .brand-subtitle {
270
+ font-size: 11px;
271
+ color: #8a99a8;
272
+ letter-spacing: 1px;
273
+ text-transform: uppercase;
274
+ margin-top: 2px;
275
+ text-align: left;
276
+ }
277
+ .card {
278
+ background: rgba(18, 25, 38, 0.95);
279
+ border: 1px solid rgba(157, 240, 40, 0.22);
280
+ border-radius: 16px;
281
+ padding: 36px 32px;
282
+ box-shadow: 0 24px 48px rgba(0, 0, 0, 0.6);
283
+ backdrop-filter: blur(16px);
284
+ }
285
+ h1 {
286
+ color: #ffffff;
287
+ font-size: 21px;
288
+ font-weight: 700;
289
+ margin-bottom: 12px;
290
+ }
291
+ p {
292
+ color: #94a3b8;
293
+ font-size: 14px;
294
+ line-height: 1.6;
295
+ margin-bottom: 24px;
296
+ }
297
+ </style>
298
+ </head>
299
+ <body>
300
+ <div class="container">
301
+ <div class="header">
302
+ <img src="${logoSrc}" alt="Causyne Agent Logo" class="logo" />
303
+ <div>
304
+ <div class="brand-title">CAUSYNE <span style="color:#9df028;">AGENT</span></div>
305
+ <div class="brand-subtitle">Autonomous AI Harness</div>
306
+ </div>
307
+ </div>
308
+ <div class="card">
309
+ ${badgeHtml}
310
+ <h1>${title}</h1>
311
+ <p>${message}</p>
312
+ ${contentBox}
313
+ ${actionButton}
314
+ </div>
315
+ </div>
316
+ </body>
317
+ </html>`;
318
+ }
319
+
129
320
  /**
130
321
  * Start loopback HTTP server on 127.0.0.1 to receive the OAuth redirect code.
131
322
  */
@@ -160,6 +351,23 @@ export async function startLoopbackAuth(options: {
160
351
  const server = http.createServer(async (req, res) => {
161
352
  try {
162
353
  const reqUrl = new URL(req.url || '/', `http://${req.headers.host || '127.0.0.1'}`);
354
+
355
+ if (reqUrl.pathname === '/logo.png') {
356
+ const logoBuf = getLogoBuffer();
357
+ if (logoBuf) {
358
+ res.writeHead(200, {
359
+ 'Content-Type': 'image/png',
360
+ 'Content-Length': logoBuf.length,
361
+ 'Cache-Control': 'public, max-age=3600'
362
+ });
363
+ res.end(logoBuf);
364
+ return;
365
+ }
366
+ res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
367
+ res.end('Not Found');
368
+ return;
369
+ }
370
+
163
371
  if (reqUrl.pathname !== '/callback') {
164
372
  res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
165
373
  res.end('Not Found');
@@ -172,10 +380,11 @@ export async function startLoopbackAuth(options: {
172
380
  if (!state || state !== pkce.state) {
173
381
  res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });
174
382
  res.end(
175
- '<html><body style="font-family:sans-serif;padding:32px;background:#111;color:#eee;">' +
176
- '<h2 style="color:#ef4444;">Authorization Error: State Mismatch</h2>' +
177
- '<p>The received CSRF verification state did not match the session. Please try again.</p>' +
178
- '</body></html>'
383
+ renderAuthPage({
384
+ status: 'error',
385
+ title: 'Authorization Error: State Mismatch',
386
+ errorDetail: 'The received CSRF verification state did not match the active session. This can happen if the authorization request timed out or was tampered with.'
387
+ })
179
388
  );
180
389
  if (!resolved) {
181
390
  resolved = true;
@@ -188,10 +397,11 @@ export async function startLoopbackAuth(options: {
188
397
  if (!code) {
189
398
  res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });
190
399
  res.end(
191
- '<html><body style="font-family:sans-serif;padding:32px;background:#111;color:#eee;">' +
192
- '<h2 style="color:#ef4444;">Authorization Failed</h2>' +
193
- '<p>No authorization code was returned by OpenRouter.</p>' +
194
- '</body></html>'
400
+ renderAuthPage({
401
+ status: 'error',
402
+ title: 'Authorization Failed',
403
+ errorDetail: 'No authorization code was returned by OpenRouter.'
404
+ })
195
405
  );
196
406
  if (!resolved) {
197
407
  resolved = true;
@@ -204,10 +414,10 @@ export async function startLoopbackAuth(options: {
204
414
  // Send friendly HTML response to user's browser
205
415
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
206
416
  res.end(
207
- '<html><body style="font-family:sans-serif;padding:40px;background:#0d1117;color:#c9d1d9;text-align:center;">' +
208
- '<h2 style="color:#2ea043;margin-bottom:12px;">Causyne Agent Connected Successfully</h2>' +
209
- '<p style="font-size:16px;color:#8b949e;">Your OpenRouter account has been authorized. You can close this window and return to your terminal.</p>' +
210
- '</body></html>'
417
+ renderAuthPage({
418
+ status: 'success',
419
+ model: OPENROUTER_FREE_MODEL
420
+ })
211
421
  );
212
422
 
213
423
  // Perform token exchange
@@ -215,7 +425,7 @@ export async function startLoopbackAuth(options: {
215
425
 
216
426
  if (!resolved) {
217
427
  resolved = true;
218
- cleanup();
428
+ setTimeout(cleanup, 1200);
219
429
  resolve({ apiKey });
220
430
  }
221
431
  } catch (err: any) {
@@ -321,7 +531,9 @@ export function saveOpenRouterKey(
321
531
  /**
322
532
  * Disconnect OpenRouter credentials from local vault.
323
533
  */
324
- export function disconnectOpenRouter(store: { loadConfig(): any; saveConfig(cfg: any): void } = { loadConfig, saveConfig }): Record<string, any> {
534
+ export function disconnectOpenRouter(
535
+ store: { loadConfig(): any; saveConfig(cfg: any): void } = { loadConfig, saveConfig }
536
+ ): Record<string, any> {
325
537
  const currentConfig = store.loadConfig() || {};
326
538
  const providerKeys = {
327
539
  ...(currentConfig.providerKeys && typeof currentConfig.providerKeys === 'object' ? currentConfig.providerKeys : {})
@@ -330,10 +542,28 @@ export function disconnectOpenRouter(store: { loadConfig(): any; saveConfig(cfg:
330
542
  delete providerKeys['openrouter'];
331
543
  currentConfig.providerKeys = providerKeys;
332
544
 
545
+ if (process.env.OPENROUTER_API_KEY) {
546
+ delete process.env.OPENROUTER_API_KEY;
547
+ }
548
+
333
549
  if (currentConfig.provider === 'openrouter') {
334
- currentConfig.provider = 'deepseek';
335
- currentConfig.model = 'deepseek-chat';
336
- currentConfig.apiKey = providerKeys['deepseek'] || '';
550
+ if (providerKeys['deepseek']) {
551
+ currentConfig.provider = 'deepseek';
552
+ currentConfig.model = 'deepseek-chat';
553
+ currentConfig.apiKey = providerKeys['deepseek'];
554
+ } else if (providerKeys['anthropic']) {
555
+ currentConfig.provider = 'anthropic';
556
+ currentConfig.model = 'claude-3-7-sonnet';
557
+ currentConfig.apiKey = providerKeys['anthropic'];
558
+ } else if (providerKeys['openai']) {
559
+ currentConfig.provider = 'openai';
560
+ currentConfig.model = 'gpt-4o';
561
+ currentConfig.apiKey = providerKeys['openai'];
562
+ } else {
563
+ currentConfig.provider = 'antigravity';
564
+ currentConfig.model = 'Gemini 3.8 Flash (Low)';
565
+ currentConfig.apiKey = '';
566
+ }
337
567
  }
338
568
 
339
569
  store.saveConfig(currentConfig);
package/src/commands.js CHANGED
@@ -1633,8 +1633,31 @@ export const COMMANDS = [
1633
1633
  }
1634
1634
 
1635
1635
  if (sub === 'disconnect') {
1636
- disconnectOpenRouter();
1637
- return ok('OpenRouter account disconnected and API key removed from local vault.');
1636
+ const updatedConfig = disconnectOpenRouter();
1637
+ if (ctx.loop) {
1638
+ ctx.loop.config = updatedConfig;
1639
+ if (typeof ctx.loop.updateTierLimits === 'function') {
1640
+ ctx.loop.updateTierLimits();
1641
+ }
1642
+ }
1643
+ if (ctx.prompt) {
1644
+ if (typeof ctx.prompt.updateModel === 'function') {
1645
+ ctx.prompt.updateModel(
1646
+ updatedConfig.provider || 'antigravity',
1647
+ updatedConfig.model || 'Gemini 3.8 Flash (Low)'
1648
+ );
1649
+ } else if (ctx.prompt.renderer?.status) {
1650
+ ctx.prompt.renderer.status.setSession({
1651
+ provider: updatedConfig.provider || 'antigravity',
1652
+ model: updatedConfig.model || 'Gemini 3.8 Flash (Low)'
1653
+ });
1654
+ if (typeof ctx.prompt.scheduleDraw === 'function') ctx.prompt.scheduleDraw();
1655
+ }
1656
+ }
1657
+ return ok(
1658
+ `OpenRouter account disconnected and API key removed from local vault.\n` +
1659
+ `Active model reverted to ${updatedConfig.provider || 'antigravity'} / ${updatedConfig.model || 'Gemini 3.8 Flash (Low)'}.`
1660
+ );
1638
1661
  }
1639
1662
 
1640
1663
  if (sub === 'privacy' || sub === 'data-collection') {