@darksol/terminal 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darksol/terminal",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "DARKSOL Terminal — unified CLI for all DARKSOL services. Market intel, trading, oracle, casino, and more.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -294,6 +294,16 @@ export function cli(argv) {
294
294
  .description('Settle payment on-chain')
295
295
  .action((payment) => facilitatorSettle(payment));
296
296
 
297
+ // ═══════════════════════════════════════
298
+ // CHAT SHORTCUT (darksol chat = darksol ai chat)
299
+ // ═══════════════════════════════════════
300
+ program
301
+ .command('chat')
302
+ .description('Start AI trading chat (shortcut for: darksol ai chat)')
303
+ .option('-p, --provider <name>', 'LLM provider')
304
+ .option('-m, --model <model>', 'Model name')
305
+ .action((opts) => startChat(opts));
306
+
297
307
  // ═══════════════════════════════════════
298
308
  // SETUP COMMAND
299
309
  // ═══════════════════════════════════════
@@ -591,58 +601,41 @@ export function cli(argv) {
591
601
  });
592
602
 
593
603
  // ═══════════════════════════════════════
594
- // DASHBOARD (default) — CHAT-FIRST
604
+ // DASHBOARD (default) — commands + optional AI
595
605
  // ═══════════════════════════════════════
596
606
  program
597
607
  .command('dashboard', { isDefault: true })
598
- .description('Show DARKSOL Terminal — chat-first interface')
608
+ .description('Show DARKSOL Terminal dashboard')
599
609
  .action(async () => {
600
610
  showBanner();
601
611
 
602
- // First-run detection — force setup
603
- const ranSetup = await checkFirstRun();
604
- if (ranSetup) return;
605
-
606
612
  const cfg = getAllConfig();
607
613
  const wallet = cfg.activeWallet;
608
- const { hasKey } = await import('./config/keys.js');
609
- const hasLLM = ['openai', 'anthropic', 'openrouter', 'ollama'].some(s => hasKey(s));
614
+ const { hasAnyLLM } = await import('./config/keys.js');
615
+ const hasLLM = hasAnyLLM();
610
616
 
611
- // ── Status bar (compact) ──
617
+ // ── Status bar ──
612
618
  const statusParts = [
613
619
  wallet ? theme.success(`● ${wallet}`) : theme.dim('○ no wallet'),
614
620
  theme.dim(`${cfg.chain}`),
615
621
  theme.dim(`${cfg.slippage}% slip`),
616
- hasLLM ? theme.success('● AI ready') : theme.accent('○ no AI'),
622
+ hasLLM ? theme.success('● AI ready') : theme.dim('○ no AI'),
617
623
  ];
618
624
  console.log(` ${statusParts.join(theme.dim(' │ '))}`);
619
625
  console.log('');
620
626
 
621
- // ── CHAT INTERFACE (primary) ──
627
+ // ── Commands (always shown) ──
628
+ showCommandList();
629
+
630
+ // ── AI nudge or chat prompt ──
622
631
  if (hasLLM) {
623
- // AI is connecteddrop straight into chat
624
- console.log(theme.gold(' ╔══════════════════════════════════════════════════════════╗'));
625
- console.log(theme.gold(' ║') + theme.label(' DARKSOL AI — ready. Ask anything. ') + theme.gold('║'));
626
- console.log(theme.gold(' ║') + theme.dim(' "swap 0.1 ETH for USDC" • "what\'s AERO at?" • "help" ') + theme.gold('║'));
627
- console.log(theme.gold(' ║') + theme.dim(' Type "commands" to see all tools. Type "exit" to quit. ') + theme.gold('║'));
628
- console.log(theme.gold(' ╚══════════════════════════════════════════════════════════╝'));
632
+ console.log(theme.gold(' 💬 AI is readyrun ') + theme.label('darksol ai chat') + theme.gold(' or just ') + theme.label('darksol chat'));
633
+ console.log(theme.dim(' "swap 0.1 ETH for USDC" • "what\'s AERO at?" • any question'));
629
634
  console.log('');
630
-
631
- // Start interactive chat loop
632
- await startChatLoop(cfg);
633
635
  } else {
634
- // No AI show connect prompt
635
- console.log(theme.gold(' ╔══════════════════════════════════════════════════════════╗'));
636
- console.log(theme.gold(' ║') + theme.accent(' ⚠ No AI provider connected ') + theme.gold('║'));
637
- console.log(theme.gold(' ║') + theme.dim(' The DARKSOL AI needs an LLM to work. ') + theme.gold('║'));
638
- console.log(theme.gold(' ║') + theme.dim(' ') + theme.gold('║'));
639
- console.log(theme.gold(' ║') + theme.dim(' Run: ') + theme.label('darksol setup') + theme.dim(' to connect OpenAI/Anthropic ') + theme.gold('║'));
640
- console.log(theme.gold(' ║') + theme.dim(' Run: ') + theme.label('darksol keys add openai') + theme.dim(' to add an API key ') + theme.gold('║'));
641
- console.log(theme.gold(' ║') + theme.dim(' ') + theme.gold('║'));
642
- console.log(theme.gold(' ║') + theme.dim(' Or use Ollama for free local AI — no key needed. ') + theme.gold('║'));
643
- console.log(theme.gold(' ╚══════════════════════════════════════════════════════════╝'));
636
+ console.log(theme.dim(' 💡 Want AI-powered trading? Run ') + theme.label('darksol setup') + theme.dim(' to connect an LLM'));
637
+ console.log(theme.dim(' Supports OpenAI, Anthropic, OpenRouter, or Ollama (free/local)'));
644
638
  console.log('');
645
- showCommandList();
646
639
  }
647
640
  });
648
641
 
@@ -351,13 +351,54 @@ export function getKeyAuto(service) {
351
351
  }
352
352
 
353
353
  /**
354
- * Check if any key exists for a service (stored or env)
354
+ * Check if a VALID key exists for a service (stored or env)
355
+ * Actually validates format, not just existence
355
356
  */
356
357
  export function hasKey(service) {
357
- const vault = loadVault();
358
- if (vault.keys[service]) return true;
359
358
  const svc = SERVICES[service];
360
- if (svc?.envVar && process.env[svc.envVar]) return true;
359
+ const vault = loadVault();
360
+
361
+ // Check vault (auto-stored keys)
362
+ if (vault.keys[service]) {
363
+ // If auto-stored, try to decrypt and validate
364
+ if (vault.keys[service].autoStored) {
365
+ try {
366
+ const key = decrypt(vault.keys[service].encrypted, getMachineVaultPass());
367
+ if (svc?.validate && !svc.validate(key)) return false;
368
+ return true;
369
+ } catch { return false; }
370
+ }
371
+ return true; // manually stored keys are assumed valid
372
+ }
373
+
374
+ // Check environment variable
375
+ if (svc?.envVar && process.env[svc.envVar]) {
376
+ const envVal = process.env[svc.envVar];
377
+ // For Ollama, just having OLLAMA_HOST doesn't mean AI is ready
378
+ // — we need actual LLM providers with API keys
379
+ if (service === 'ollama') {
380
+ // Ollama is "ready" if host is set and looks like a URL
381
+ return envVal.startsWith('http') && envVal.length > 10;
382
+ }
383
+ // For API key services, validate the key format
384
+ if (svc.validate) {
385
+ return svc.validate(envVal);
386
+ }
387
+ return envVal.length > 0;
388
+ }
389
+
390
+ return false;
391
+ }
392
+
393
+ /**
394
+ * Quick check: is any LLM provider properly configured?
395
+ * Only returns true if a real API key is validated
396
+ */
397
+ export function hasAnyLLM() {
398
+ // Cloud providers — need real validated API keys
399
+ if (['openai', 'anthropic', 'openrouter'].some(s => hasKey(s))) return true;
400
+ // Ollama — check if explicitly configured via hasKey (validates URL format)
401
+ if (hasKey('ollama')) return true;
361
402
  return false;
362
403
  }
363
404
 
@@ -3,7 +3,7 @@ import { theme } from '../ui/theme.js';
3
3
  import { showSection, showDivider } from '../ui/banner.js';
4
4
  import { success, error, warn, info, kvDisplay } from '../ui/components.js';
5
5
  import { getConfig, setConfig } from '../config/store.js';
6
- import { addKeyDirect, hasKey, SERVICES } from '../config/keys.js';
6
+ import { addKeyDirect, hasKey, hasAnyLLM, SERVICES } from '../config/keys.js';
7
7
  import { createServer } from 'http';
8
8
  import open from 'open';
9
9
  import crypto from 'crypto';
@@ -16,9 +16,9 @@ import crypto from 'crypto';
16
16
  * Check if this is a first run (no LLM keys configured)
17
17
  */
18
18
  export function isFirstRun() {
19
- const hasAnyLLM = ['openai', 'anthropic', 'openrouter', 'ollama'].some(s => hasKey(s));
19
+ const llmReady = hasAnyLLM();
20
20
  const setupDone = getConfig('setupComplete');
21
- return !hasAnyLLM && !setupDone;
21
+ return !llmReady && !setupDone;
22
22
  }
23
23
 
24
24
  /**
@@ -494,12 +494,10 @@ function showPostSetup() {
494
494
  }
495
495
 
496
496
  /**
497
- * Quick check on startup — if first run, FORCE setup (no prompt)
497
+ * Quick check on startup — nudge about AI, never block
498
+ * Returns false always so dashboard continues to render
498
499
  */
499
500
  export async function checkFirstRun() {
500
- if (isFirstRun()) {
501
- await runSetupWizard();
502
- return true;
503
- }
501
+ // Never block — just return false and let dashboard handle the nudge
504
502
  return false;
505
503
  }
package/src/ui/banner.js CHANGED
@@ -26,7 +26,7 @@ export function showBanner(opts = {}) {
26
26
  );
27
27
  console.log(
28
28
  theme.dim(' ║ ') +
29
- theme.subtle(' v0.3.1') +
29
+ theme.subtle(' v0.3.3') +
30
30
  theme.dim(' ') +
31
31
  theme.gold('🌑') +
32
32
  theme.dim(' ║')
@@ -44,7 +44,7 @@ export function showBanner(opts = {}) {
44
44
 
45
45
  export function showMiniBanner() {
46
46
  console.log('');
47
- console.log(theme.gold.bold(' 🌑 DARKSOL TERMINAL') + theme.dim(' v0.3.1'));
47
+ console.log(theme.gold.bold(' 🌑 DARKSOL TERMINAL') + theme.dim(' v0.3.3'));
48
48
  console.log(theme.dim(' ─────────────────────────────'));
49
49
  console.log('');
50
50
  }
@@ -64,3 +64,5 @@ export function showDivider() {
64
64
 
65
65
 
66
66
 
67
+
68
+