@causyne/agent 1.20.72 → 1.20.74

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.
@@ -129,14 +129,22 @@ export async function exchangeCodeForApiKey(
129
129
  }
130
130
 
131
131
  /**
132
- * Retrieve the Causyne Agent emblem logo as a binary buffer if available.
132
+ * Retrieve the Causyne Agent emblem logo encoded as Base64.
133
133
  */
134
134
  export function getLogoBuffer(): Buffer | null {
135
135
  try {
136
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);
137
+ const candidates = [
138
+ path.resolve(currentDir, '../assets/logo.png'),
139
+ path.resolve(currentDir, '../../assets/logo.png'),
140
+ path.resolve(currentDir, '../../src/assets/logo.png'),
141
+ path.resolve(process.cwd(), 'src/assets/logo.png'),
142
+ path.resolve(process.cwd(), 'assets/logo.png')
143
+ ];
144
+ for (const candidate of candidates) {
145
+ if (fs.existsSync(candidate)) {
146
+ return fs.readFileSync(candidate);
147
+ }
140
148
  }
141
149
  } catch {
142
150
  // Ignore read errors
@@ -160,65 +168,140 @@ export interface RenderAuthPageOptions {
160
168
  model?: string | undefined;
161
169
  }
162
170
 
171
+ const CAUSYNE_LOGO_SVG = [
172
+ '<svg class="brand-logo" viewBox="312 272 628 695" width="34" height="34" role="img" aria-label="Causyne Logo">',
173
+ '<title>Causyne</title>',
174
+ '<path fill="#fff" fill-rule="evenodd" d="M619 957C596 952 563 933 555 919C549 90',
175
+ '8 543 905 530 905C526 905 520 905 517 905C511 905 498 902 492 899C487 896 433 86',
176
+ '3 396 841C345 811 332 798 325 767C321 752 321 713 325 708C332 699 333 688 328 67',
177
+ '6C321 661 322 662 322 574C322 494 322 494 325 485C332 464 351 444 367 442C380 44',
178
+ '1 387 433 391 418C394 401 403 390 422 380C427 377 453 362 479 348C505 334 540 31',
179
+ '4 558 304C575 295 591 286 593 286C609 280 623 280 637 283C657 288 691 310 696 32',
180
+ '2C702 334 716 339 730 335C739 332 754 335 766 342C775 347 834 382 866 401C905 42',
181
+ '4 918 438 925 465C929 478 929 566 925 570C919 579 919 589 925 602C932 617 932 61',
182
+ '8 932 689C932 752 932 752 930 761C923 787 902 807 881 808C869 808 861 815 857 82',
183
+ '7C851 845 846 850 815 867C805 873 781 886 762 897C657 956 657 956 643 958C634 95',
184
+ '9 627 959 619 957ZM651 945C658 942 676 932 756 887C776 876 800 863 810 857C832 8',
185
+ '45 835 843 839 838C845 831 849 818 847 813C843 796 865 783 879 794C890 802 913 7',
186
+ '82 919 758C921 751 921 747 921 689C921 613 921 613 908 596C898 584 901 566 914 5',
187
+ '63C917 563 917 563 917 518C916 464 915 459 900 440C891 428 891 428 800 374C744 3',
188
+ '42 739 340 720 350C701 360 687 352 687 330C687 324 679 316 660 305C640 294 636 2',
189
+ '93 620 293C603 292 600 294 563 314C545 324 510 344 484 358C458 372 432 387 427 3',
190
+ '90C405 402 399 413 403 432C406 447 393 459 378 455C367 452 361 454 350 464C332 4',
191
+ '83 332 481 332 575C332 668 332 664 345 682C354 696 350 712 337 715L333 715L333 7',
192
+ '36C334 764 337 775 347 790C358 806 356 805 462 867C512 897 516 899 534 891C545 8',
193
+ '86 553 887 560 893C564 897 567 905 565 910C564 916 571 923 590 934C615 948 632 9',
194
+ '51 651 945Z"/>',
195
+ '<g fill="#fff" stroke="#fff" stroke-width="9.0" stroke-linejoin="round">',
196
+ '<path fill-rule="evenodd" d="M620 949C599 944 566 924 563 915C562 908 564 904 61',
197
+ '2 859C656 816 657 815 684 786C712 754 715 750 725 723C740 681 745 670 751 659C75',
198
+ '4 652 757 646 758 646C760 646 768 659 788 696C795 708 808 731 818 748C848 801 85',
199
+ '1 809 849 821C846 837 841 842 811 859C801 865 777 878 758 889C677 934 659 944 65',
200
+ '2 947C643 950 628 951 620 949ZM510 895C500 893 504 895 400 833C351 804 340 793 3',
201
+ '33 765C331 756 330 716 332 714C332 713 337 715 345 718C371 728 400 735 468 747C5',
202
+ '09 754 516 754 602 754C666 754 678 754 678 755C678 758 661 775 575 859C538 895 5',
203
+ '29 900 510 895ZM881 798C877 796 870 788 865 779C856 764 822 704 797 660C784 638 ',
204
+ '769 612 763 601C721 531 710 510 711 510C712 509 727 511 734 513C742 516 812 541 ',
205
+ '830 547C886 569 916 592 922 619C924 631 924 749 921 759C916 781 893 803 881 798Z',
206
+ 'M462 720C392 706 390 706 374 700C348 691 337 681 332 661C329 648 330 498 333 487',
207
+ 'C340 468 358 451 371 451C376 451 385 459 392 471C394 475 407 498 422 522C436 547',
208
+ ' 454 578 462 592C471 607 488 637 502 659C539 723 543 729 543 730C543 734 529 732',
209
+ ' 462 720ZM488 585C479 571 477 568 428 484C422 472 415 460 412 456C392 422 396 40',
210
+ '4 426 388C431 385 457 370 483 356C509 342 544 322 562 312C599 291 602 290 620 29',
211
+ '1C637 291 641 292 661 303C691 320 695 328 682 344C676 352 671 356 612 418C592 43',
212
+ '8 568 463 559 473C551 484 541 495 538 499C530 507 526 516 520 536C511 567 499 59',
213
+ '7 496 597C496 597 492 592 488 585Z"/>',
214
+ '<path d="M908 559C885 543 853 528 797 508C741 489 744 489 650 489C589 489 580 48',
215
+ '9 580 488C580 486 642 422 687 376C720 343 728 339 749 345C756 347 775 357 861 40',
216
+ '8C898 430 908 441 916 466C919 474 920 565 918 565C917 565 913 562 908 559Z"/>',
217
+ '</g>',
218
+ '<path fill="#3a3f47" fill-rule="evenodd" d="M620 949C599 944 566 924 563 915C562',
219
+ ' 908 564 904 612 859C656 816 657 815 684 786C712 754 715 750 725 723C740 681 745',
220
+ ' 670 751 659C754 652 757 646 758 646C760 646 768 659 788 696C795 708 808 731 818',
221
+ ' 748C848 801 851 809 849 821C846 837 841 842 811 859C801 865 777 878 758 889C677',
222
+ ' 934 659 944 652 947C643 950 628 951 620 949ZM510 895C500 893 504 895 400 833C35',
223
+ '1 804 340 793 333 765C331 756 330 716 332 714C332 713 337 715 345 718C371 728 40',
224
+ '0 735 468 747C509 754 516 754 602 754C666 754 678 754 678 755C678 758 661 775 57',
225
+ '5 859C538 895 529 900 510 895ZM881 798C877 796 870 788 865 779C856 764 822 704 7',
226
+ '97 660C784 638 769 612 763 601C721 531 710 510 711 510C712 509 727 511 734 513C7',
227
+ '42 516 812 541 830 547C886 569 916 592 922 619C924 631 924 749 921 759C916 781 8',
228
+ '93 803 881 798ZM462 720C392 706 390 706 374 700C348 691 337 681 332 661C329 648 ',
229
+ '330 498 333 487C340 468 358 451 371 451C376 451 385 459 392 471C394 475 407 498 ',
230
+ '422 522C436 547 454 578 462 592C471 607 488 637 502 659C539 723 543 729 543 730C',
231
+ '543 734 529 732 462 720ZM488 585C479 571 477 568 428 484C422 472 415 460 412 456',
232
+ 'C392 422 396 404 426 388C431 385 457 370 483 356C509 342 544 322 562 312C599 291',
233
+ ' 602 290 620 291C637 291 641 292 661 303C691 320 695 328 682 344C676 352 671 356',
234
+ ' 612 418C592 438 568 463 559 473C551 484 541 495 538 499C530 507 526 516 520 536',
235
+ 'C511 567 499 597 496 597C496 597 492 592 488 585Z"/>',
236
+ '<path fill="#b6e06f" d="M908 559C885 543 853 528 797 508C741 489 744 489 650 489',
237
+ 'C589 489 580 489 580 488C580 486 642 422 687 376C720 343 728 339 749 345C756 347',
238
+ ' 775 357 861 408C898 430 908 441 916 466C919 474 920 565 918 565C917 565 913 562',
239
+ ' 908 559Z"/>',
240
+ '</svg>'
241
+ ].join('\n');
242
+
163
243
  /**
164
- * Render a professional branded HTML response page for OpenRouter OAuth callbacks.
244
+ * Render a professional branded HTML response page for OpenRouter OAuth callbacks
245
+ * following the exact visual style, typography, and design language of causyne.com.
165
246
  */
166
247
  export function renderAuthPage(options: RenderAuthPageOptions): string {
167
248
  const isSuccess = options.status === 'success';
168
- const base64Logo = getLogoBase64();
169
- const logoSrc = base64Logo ? `data:image/png;base64,${base64Logo}` : '/logo.png';
170
249
 
171
250
  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>';
251
+ ? '<div class="panel-badge success">' +
252
+ '<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"/></svg>' +
253
+ '<span>Connected Successfully</span></div>'
254
+ : '<div class="panel-badge error">' +
255
+ '<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"/></svg>' +
256
+ '<span>Authorization Failed</span></div>';
180
257
 
181
258
  const title = options.title || (isSuccess ? 'OpenRouter Account Authorized' : 'Authorization Error');
182
259
  const defaultMsg = isSuccess
183
- ? 'Your OpenRouter account has been connected to Causyne Agent. You can now close this tab and return to your terminal.'
260
+ ? 'Your OpenRouter account is now authorized and connected to Causyne Agent. You can close this window and return to your terminal.'
184
261
  : 'The authorization flow could not be completed.';
185
262
  const message = options.message || defaultMsg;
186
263
 
187
264
  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>` +
265
+ ? '<div class="meta-box">' +
266
+ '<div class="meta-row" style="margin-bottom:8px;">' +
267
+ '<span class="meta-label">Provider</span>' +
268
+ '<span class="meta-val">OpenRouter</span>' +
194
269
  '</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>' +
270
+ '<div class="meta-row" style="margin-bottom:8px;">' +
271
+ '<span class="meta-label">Active Model</span>' +
272
+ `<span class="meta-val lime">${options.model || OPENROUTER_FREE_MODEL}</span>` +
273
+ '</div>' +
274
+ '<div class="meta-row" style="margin-bottom:8px;">' +
275
+ '<span class="meta-label">Privacy Guard</span>' +
276
+ '<span class="meta-val" style="color:#9da697;">provider.data_collection = &quot;deny&quot;</span>' +
277
+ '</div>' +
278
+ '<div class="meta-row">' +
279
+ '<span class="meta-label">Protocol</span>' +
280
+ '<span class="meta-val" style="color:#9da697;">OAuth 2.0 PKCE (S256)</span>' +
198
281
  '</div>' +
199
282
  '</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>' +
283
+ : '<div style="background:#191c19;border:1px solid rgba(239,83,80,0.25);' +
284
+ 'border-radius:6px;padding:14px;color:#fca5a5;font-size:13px;line-height:1.6;margin-bottom:20px;' +
285
+ `text-align:left;font-family:\'SF Mono\',Menlo,monospace;">${options.errorDetail || 'An unexpected error occurred during authorization.'}</div>` +
286
+ '<div style="background:#191c19;border:1px solid rgba(255,255,255,0.07);' +
287
+ 'border-radius:6px;padding:16px;margin-bottom:24px;text-align:left;font-size:13px;">' +
288
+ '<div style="color:#e4e8e0;font-weight:600;margin-bottom:8px;">Recommended Solutions:</div>' +
289
+ '<ol style="color:#9da697;line-height:1.6;margin:0;padding-left:18px;">' +
290
+ '<li>Return to your terminal and select OpenRouter in the FREE tab to retry.</li>' +
291
+ '<li>Or obtain a free API key at <a href="https://openrouter.ai/keys" target="_blank" ' +
292
+ 'style="color:#9df028;text-decoration:none;">openrouter.ai/keys</a> and connect directly via:</li>' +
210
293
  '</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>' +
294
+ '<pre style="background:#141714;color:#9df028;padding:10px 14px;border-radius:4px;font-family:\'SF Mono\',Menlo,monospace;' +
295
+ 'font-size:12px;margin-top:10px;border:1px solid rgba(255,255,255,0.07);overflow-x:auto;">causyne config set providerKeys.openrouter &lt;your-key&gt;</pre>' +
213
296
  '</div>';
214
297
 
215
298
  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;">' +
299
+ ? '<button id="return-btn" class="btn-primary" onclick="returnToTerminal()">' +
218
300
  '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;">' +
301
+ '<div id="return-hint" class="return-hint">' +
302
+ 'Authentication complete. You can close this browser tab (⌘W / Ctrl+W) and switch back to your terminal.' +
303
+ '</div>'
304
+ : '<button class="btn-secondary" onclick="window.close()">' +
222
305
  'Close Window</button>';
223
306
 
224
307
  return `<!DOCTYPE html>
@@ -227,91 +310,338 @@ export function renderAuthPage(options: RenderAuthPageOptions): string {
227
310
  <meta charset="utf-8">
228
311
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
229
312
  <title>Causyne Agent Connected Successfully</title>
313
+ <link rel="preconnect" href="https://fonts.googleapis.com">
314
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
315
+ <link href="https://fonts.googleapis.com/css2?family=Exo+2:ital,wght@0,400;0,600;0,700;0,800;1,400&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
230
316
  <style>
231
- * { box-sizing: border-box; margin: 0; padding: 0; }
317
+ :root {
318
+ --bg: #141714;
319
+ --bg-subtle: #191c19;
320
+ --charcoal: #202421;
321
+ --lime: #B5D66A;
322
+ --lime-bright: #9df028;
323
+ --text-primary: #e4e8e0;
324
+ --text-secondary: #9da697;
325
+ --text-dim: #60685b;
326
+ --border: rgba(255, 255, 255, 0.07);
327
+ --font-display: 'Exo 2', system-ui, -apple-system, sans-serif;
328
+ --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Monaco, Consolas, monospace;
329
+ --max-w: 1100px;
330
+ }
331
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
232
332
  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;
333
+ background-color: var(--bg);
334
+ color: var(--text-primary);
335
+ font-family: var(--font-mono);
236
336
  min-height: 100vh;
237
337
  display: flex;
238
- align-items: center;
239
- justify-content: center;
240
- padding: 24px;
338
+ flex-direction: column;
339
+ justify-content: space-between;
340
+ padding: 0 32px;
341
+ -webkit-font-smoothing: antialiased;
241
342
  }
242
- .container {
243
- max-width: 540px;
343
+ .page {
344
+ max-width: var(--max-w);
244
345
  width: 100%;
245
- text-align: center;
346
+ margin: 0 auto;
246
347
  }
247
- .header {
348
+ .site-header {
349
+ padding: 40px 0 32px;
248
350
  display: flex;
249
351
  align-items: center;
250
- justify-content: center;
251
- gap: 16px;
252
- margin-bottom: 28px;
352
+ justify-content: space-between;
353
+ border-bottom: 1px solid var(--border);
253
354
  }
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;
355
+ .brand {
356
+ display: inline-flex;
357
+ align-items: center;
358
+ gap: 14px;
359
+ text-decoration: none;
360
+ }
361
+ .brand-logo {
362
+ width: 36px;
363
+ height: 36px;
364
+ flex-shrink: 0;
365
+ }
366
+ .brand-wordmark {
367
+ font-family: var(--font-display);
368
+ font-size: 1.15rem;
369
+ font-weight: 700;
370
+ letter-spacing: 0.16em;
273
371
  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;
372
+ color: var(--text-primary);
373
+ }
374
+ .site-nav {
375
+ display: inline-flex;
376
+ align-items: center;
377
+ gap: 10px;
378
+ }
379
+ .nav-link {
380
+ display: inline-flex;
381
+ align-items: center;
382
+ gap: 8px;
383
+ padding: 7px 14px;
384
+ font-family: var(--font-mono);
385
+ font-size: 0.82rem;
386
+ font-weight: 500;
387
+ color: var(--text-secondary);
388
+ background: rgba(255, 255, 255, 0.02);
389
+ border: 1px solid var(--border);
390
+ border-radius: 4px;
391
+ text-decoration: none;
392
+ transition: all 0.18s ease;
393
+ line-height: 1;
394
+ }
395
+ .nav-link:hover {
396
+ color: var(--text-primary);
397
+ border-color: rgba(255, 255, 255, 0.22);
398
+ background: rgba(255, 255, 255, 0.06);
399
+ }
400
+ .nav-icon { display: block; }
401
+ .nav-icon.github-icon { color: var(--text-primary); }
402
+ .nav-icon.npm-icon { color: #ea2039; }
403
+
404
+ .content {
405
+ padding: 60px 0 72px;
406
+ }
407
+ .hero-grid {
408
+ display: grid;
409
+ grid-template-columns: 1.1fr 1fr;
410
+ gap: 56px;
411
+ align-items: start;
412
+ }
413
+ @media (max-width: 860px) {
414
+ .hero-grid { grid-template-columns: 1fr; gap: 36px; }
415
+ body { padding: 0 20px; }
416
+ }
417
+ .hero-title {
418
+ font-family: var(--font-display);
419
+ font-size: 2.35rem;
288
420
  font-weight: 700;
289
- margin-bottom: 12px;
421
+ line-height: 1.18;
422
+ letter-spacing: -0.02em;
423
+ color: var(--text-primary);
424
+ margin-bottom: 20px;
290
425
  }
291
- p {
292
- color: #94a3b8;
293
- font-size: 14px;
294
- line-height: 1.6;
426
+ .hero-lead {
427
+ font-family: var(--font-mono);
428
+ font-size: 0.95rem;
429
+ line-height: 1.76;
430
+ color: var(--text-secondary);
431
+ margin-bottom: 28px;
432
+ }
433
+ .hero-slogan {
434
+ font-family: var(--font-mono);
435
+ font-size: 0.82rem;
436
+ color: var(--text-dim);
437
+ display: flex;
438
+ align-items: center;
439
+ gap: 8px;
440
+ }
441
+ .hero-slogan::before {
442
+ content: '';
443
+ display: inline-block;
444
+ width: 7px;
445
+ height: 7px;
446
+ border-radius: 50%;
447
+ background: var(--lime);
448
+ }
449
+
450
+ .autonomy-panel {
451
+ background: var(--charcoal);
452
+ border: 1px solid var(--border);
453
+ border-radius: 8px;
454
+ padding: 32px 28px;
455
+ }
456
+ .panel-badge {
457
+ display: inline-flex;
458
+ align-items: center;
459
+ gap: 8px;
460
+ padding: 6px 14px;
461
+ border-radius: 4px;
462
+ font-family: var(--font-mono);
463
+ font-size: 12px;
464
+ font-weight: 600;
465
+ margin-bottom: 20px;
466
+ }
467
+ .panel-badge.success {
468
+ background: rgba(157, 240, 40, 0.12);
469
+ border: 1px solid rgba(157, 240, 40, 0.35);
470
+ color: #9df028;
471
+ }
472
+ .panel-badge.error {
473
+ background: rgba(239, 83, 80, 0.12);
474
+ border: 1px solid rgba(239, 83, 80, 0.35);
475
+ color: #ef5350;
476
+ }
477
+ .panel-heading {
478
+ font-family: var(--font-display);
479
+ font-size: 1.25rem;
480
+ font-weight: 700;
481
+ color: var(--text-primary);
482
+ margin-bottom: 10px;
483
+ letter-spacing: -0.01em;
484
+ }
485
+ .panel-message {
486
+ font-family: var(--font-mono);
487
+ font-size: 0.85rem;
488
+ line-height: 1.68;
489
+ color: var(--text-secondary);
490
+ margin-bottom: 22px;
491
+ }
492
+ .meta-box {
493
+ background: var(--bg-subtle);
494
+ border: 1px solid var(--border);
495
+ border-radius: 6px;
496
+ padding: 16px 18px;
295
497
  margin-bottom: 24px;
498
+ font-family: var(--font-mono);
499
+ font-size: 12px;
500
+ line-height: 1.8;
501
+ color: var(--text-primary);
502
+ }
503
+ .meta-row {
504
+ display: flex;
505
+ justify-content: space-between;
506
+ align-items: center;
507
+ }
508
+ .meta-label { color: var(--text-secondary); }
509
+ .meta-val { color: var(--text-primary); font-weight: 500; }
510
+ .meta-val.lime { color: var(--lime-bright); font-weight: 600; }
511
+
512
+ .btn-primary {
513
+ display: inline-flex;
514
+ align-items: center;
515
+ justify-content: center;
516
+ width: 100%;
517
+ background: var(--lime-bright);
518
+ color: #141714;
519
+ border: none;
520
+ padding: 13px 24px;
521
+ border-radius: 4px;
522
+ font-size: 13px;
523
+ font-weight: 700;
524
+ font-family: var(--font-mono);
525
+ letter-spacing: 0.5px;
526
+ cursor: pointer;
527
+ transition: background 0.15s ease;
528
+ }
529
+ .btn-primary:hover {
530
+ background: #c8e682;
531
+ }
532
+ .btn-secondary {
533
+ display: inline-flex;
534
+ align-items: center;
535
+ justify-content: center;
536
+ width: 100%;
537
+ background: var(--charcoal);
538
+ color: var(--text-primary);
539
+ border: 1px solid rgba(255, 255, 255, 0.15);
540
+ padding: 12px 22px;
541
+ border-radius: 4px;
542
+ font-size: 13px;
543
+ font-weight: 600;
544
+ font-family: var(--font-mono);
545
+ cursor: pointer;
546
+ }
547
+ .btn-secondary:hover {
548
+ border-color: rgba(255, 255, 255, 0.3);
549
+ }
550
+ .return-hint {
551
+ font-family: var(--font-mono);
552
+ font-size: 11.5px;
553
+ color: var(--text-dim);
554
+ margin-top: 14px;
555
+ line-height: 1.6;
556
+ text-align: center;
557
+ }
558
+
559
+ .site-footer {
560
+ padding: 28px 0 36px;
561
+ border-top: 1px solid var(--border);
562
+ font-family: var(--font-mono);
563
+ font-size: 0.8rem;
564
+ color: var(--text-dim);
565
+ display: flex;
566
+ justify-content: space-between;
567
+ align-items: center;
568
+ }
569
+ .site-footer a {
570
+ color: var(--text-dim);
571
+ text-decoration: none;
572
+ }
573
+ .site-footer a:hover {
574
+ color: var(--lime);
296
575
  }
297
576
  </style>
577
+ <script>
578
+ function returnToTerminal() {
579
+ try {
580
+ window.open('', '_self', '');
581
+ window.close();
582
+ } catch (e) {}
583
+ var btn = document.getElementById('return-btn');
584
+ if (btn) {
585
+ btn.textContent = '✓ Ready! Switch to Terminal';
586
+ btn.style.background = '#8ea954';
587
+ }
588
+ var hint = document.getElementById('return-hint');
589
+ if (hint) {
590
+ hint.innerHTML = '<span style="color:#B5D66A;font-weight:600;">Authentication complete!</span> Switch back to your terminal window (Cmd+Tab / Alt+Tab). You can close this tab (Cmd+W / Ctrl+W).';
591
+ }
592
+ }
593
+ </script>
298
594
  </head>
299
595
  <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>
596
+ <div class="page">
597
+ <header class="site-header">
598
+ <div class="brand">
599
+ ${CAUSYNE_LOGO_SVG}
600
+ <span class="brand-wordmark">CAUSYNE <span style="color:#9df028;">AGENT</span></span>
306
601
  </div>
307
- </div>
308
- <div class="card">
309
- ${badgeHtml}
310
- <h1>${title}</h1>
311
- <p>${message}</p>
312
- ${contentBox}
313
- ${actionButton}
314
- </div>
602
+ <nav class="site-nav" aria-label="Project links">
603
+ <a href="https://github.com/ikbal-causyne/causyne-agent" class="nav-link" target="_blank" rel="noopener noreferrer" title="Causyne Agent on GitHub">
604
+ <svg class="nav-icon github-icon" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
605
+ <path fill="currentColor" d="M8 0C3.58 0 0 3.64 0 8.13c0 3.59 2.29 6.64 5.47 7.71.4.08.55-.18.55-.39 0-.19-.01-.83-.01-1.5-2.01.38-2.53-.5-2.69-.96-.09-.23-.48-.96-.82-1.15-.28-.15-.68-.53-.01-.54.63-.01 1.08.59 1.23.83.72 1.23 1.87.88 2.33.67.07-.53.28-.88.51-1.08-1.78-.21-3.64-.91-3.64-4.02 0-.89.31-1.62.82-2.19-.08-.2-.36-1.04.08-2.16 0 0 .67-.22 2.2.84A7.44 7.44 0 0 1 8 3.88c.68 0 1.36.09 2 .28 1.53-1.06 2.2-.84 2.2-.84.44 1.12.16 1.96.08 2.16.51.57.82 1.3.82 2.19 0 3.12-1.87 3.81-3.65 4.02.29.25.54.74.54 1.51 0 1.09-.01 1.97-.01 2.25 0 .21.15.47.55.39A8.09 8.09 0 0 0 16 8.13C16 3.64 12.42 0 8 0Z"/>
606
+ </svg>
607
+ <span>GitHub</span>
608
+ </a>
609
+ <a href="https://www.npmjs.com/package/@causyne/agent" class="nav-link" target="_blank" rel="noopener noreferrer" title="Causyne Agent on npm">
610
+ <svg class="nav-icon npm-icon" viewBox="0 0 780 250" width="34" height="11" aria-hidden="true">
611
+ <path fill="currentColor" d="M240,250h100v-50h100V0H240V250z M340,50h50v100h-50V50z M480,0v200h100V50h50v150h50V50h50v150h50V0H480z M0,200h100V50h50v150h50V0H0V200z"/>
612
+ </svg>
613
+ </a>
614
+ </nav>
615
+ </header>
616
+
617
+ <main class="content">
618
+ <div class="hero-grid">
619
+ <div>
620
+ <h1 class="hero-title">${isSuccess ? 'Account connected.' : 'Authorization error.'}</h1>
621
+ <p class="hero-lead">
622
+ ${isSuccess
623
+ ? 'OpenRouter Free inference endpoint is now authorized for Causyne Agent. You can close this browser tab and return to your terminal session.'
624
+ : (options.message || 'The authorization flow could not be completed.')}
625
+ </p>
626
+ <div class="hero-slogan">
627
+ <span>Causyne Agent · Agentic AI Harness · From intention to meaningful progress.</span>
628
+ </div>
629
+ </div>
630
+
631
+ <aside class="autonomy-panel" aria-label="Authorization details">
632
+ ${badgeHtml}
633
+ <div class="panel-heading">${title}</div>
634
+ <p class="panel-message">${message}</p>
635
+ ${contentBox}
636
+ ${actionButton}
637
+ </aside>
638
+ </div>
639
+ </main>
640
+
641
+ <footer class="site-footer">
642
+ <span>Causyne Agent is in development.</span>
643
+ <a href="https://causyne.com" target="_blank" rel="noopener noreferrer">causyne.com</a>
644
+ </footer>
315
645
  </div>
316
646
  </body>
317
647
  </html>`;
@@ -411,22 +741,35 @@ export async function startLoopbackAuth(options: {
411
741
  return;
412
742
  }
413
743
 
414
- // Send friendly HTML response to user's browser
415
- res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
416
- res.end(
417
- renderAuthPage({
418
- status: 'success',
419
- model: OPENROUTER_FREE_MODEL
420
- })
421
- );
422
-
423
- // Perform token exchange
424
- const apiKey = await exchangeCodeForApiKey(code, pkce.codeVerifier, fetchFn);
425
-
426
- if (!resolved) {
427
- resolved = true;
428
- setTimeout(cleanup, 1200);
429
- resolve({ apiKey });
744
+ // Perform token exchange first before confirming success to the browser
745
+ try {
746
+ const apiKey = await exchangeCodeForApiKey(code, pkce.codeVerifier, fetchFn);
747
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
748
+ res.end(
749
+ renderAuthPage({
750
+ status: 'success',
751
+ model: OPENROUTER_FREE_MODEL
752
+ })
753
+ );
754
+ if (!resolved) {
755
+ resolved = true;
756
+ setTimeout(cleanup, 1200);
757
+ resolve({ apiKey });
758
+ }
759
+ } catch (exchangeErr: any) {
760
+ res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' });
761
+ res.end(
762
+ renderAuthPage({
763
+ status: 'error',
764
+ title: 'OpenRouter Token Exchange Failed',
765
+ errorDetail: exchangeErr?.message || 'Could not complete token exchange with OpenRouter.'
766
+ })
767
+ );
768
+ if (!resolved) {
769
+ resolved = true;
770
+ cleanup();
771
+ reject(exchangeErr);
772
+ }
430
773
  }
431
774
  } catch (err: any) {
432
775
  if (!resolved) {