opencrabs 0.3.12

The autonomous, self-improving AI agent. Single Rust binary. Every channel. Install with: cargo install opencrabs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/// Sentinel value stored in api_key_input when a key was loaded from config.
/// The actual key is never held in memory — this just signals "key exists".
pub use crate::tui::provider_selector::EXISTING_KEY_SENTINEL;

/// STT provider selection in onboarding voice screen.
/// Replaces magic numbers with named variants.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum SttProvider {
    #[default]
    Off,
    Groq,
    Local,
    OpenAiCompatible,
    Voicebox,
}

impl SttProvider {
    /// All variants in radio-button order
    pub const ALL: [SttProvider; 5] = [
        SttProvider::Off,
        SttProvider::Groq,
        SttProvider::Local,
        SttProvider::OpenAiCompatible,
        SttProvider::Voicebox,
    ];

    /// Variants available when local STT is compiled in
    pub fn available(is_local_available: bool) -> &'static [SttProvider] {
        if is_local_available {
            &Self::ALL
        } else {
            &[
                Self::Off,
                Self::Groq,
                Self::OpenAiCompatible,
                Self::Voicebox,
            ]
        }
    }

    /// Radio button label shown in the TUI
    pub fn label(&self) -> &'static str {
        match self {
            Self::Off => "Off",
            Self::Groq => "API (Groq Whisper)",
            Self::Local => "Local (Whisper — runs on device)",
            Self::OpenAiCompatible => "OpenAI-compatible (custom endpoint)",
            Self::Voicebox => "Voicebox",
        }
    }

    /// Cycle to the next variant (wraps around)
    pub fn next(self, available: &[SttProvider]) -> Self {
        available
            .iter()
            .cycle()
            .skip_while(|&&v| v != self)
            .nth(1)
            .copied()
            .unwrap_or(Self::Off)
    }

    /// Cycle to the previous variant (wraps around)
    pub fn prev(self, available: &[SttProvider]) -> Self {
        available
            .iter()
            .rev()
            .cycle()
            .skip_while(|&&v| v != self)
            .nth(1)
            .copied()
            .unwrap_or(Self::Off)
    }
}

/// TTS provider selection in onboarding voice screen.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TtsProvider {
    #[default]
    Off,
    OpenAi,
    Local,
    OpenAiCompatible,
    Voicebox,
}

impl TtsProvider {
    /// All variants in radio-button order
    pub const ALL: [TtsProvider; 5] = [
        TtsProvider::Off,
        TtsProvider::OpenAi,
        TtsProvider::Local,
        TtsProvider::OpenAiCompatible,
        TtsProvider::Voicebox,
    ];

    /// Variants available when local TTS is compiled in
    pub fn available(is_local_available: bool) -> &'static [TtsProvider] {
        if is_local_available {
            &Self::ALL
        } else {
            &[
                Self::Off,
                TtsProvider::OpenAi,
                TtsProvider::OpenAiCompatible,
                TtsProvider::Voicebox,
            ]
        }
    }

    /// Radio button label shown in the TUI
    pub fn label(&self) -> &'static str {
        match self {
            Self::Off => "Off",
            Self::OpenAi => "API (OpenAI TTS — uses OpenAI key)",
            Self::Local => "Local (Piper — runs on device, free)",
            Self::OpenAiCompatible => "OpenAI-compatible (custom endpoint)",
            Self::Voicebox => "Voicebox",
        }
    }

    /// Cycle to the next variant (wraps around)
    pub fn next(self, available: &[TtsProvider]) -> Self {
        available
            .iter()
            .cycle()
            .skip_while(|&&v| v != self)
            .nth(1)
            .copied()
            .unwrap_or(Self::Off)
    }

    /// Cycle to the previous variant (wraps around)
    pub fn prev(self, available: &[TtsProvider]) -> Self {
        available
            .iter()
            .rev()
            .cycle()
            .skip_while(|&&v| v != self)
            .nth(1)
            .copied()
            .unwrap_or(Self::Off)
    }
}

/// Provider definitions
pub const PROVIDERS: &[ProviderInfo] = &[
    ProviderInfo {
        id: "anthropic",
        name: "Anthropic Claude",
        models: &[], // Fetched from API
        key_label: "Setup Token",
        help_lines: &[
            "Claude Max / Code: run 'claude setup-token'",
            "Or paste API key from console.anthropic.com",
        ],
    },
    ProviderInfo {
        id: "openai",
        name: "OpenAI",
        models: &[],
        key_label: "API Key",
        help_lines: &["Get key from platform.openai.com"],
    },
    ProviderInfo {
        id: "github",
        name: "GitHub Copilot",
        models: &[],
        key_label: "OAuth",
        help_lines: &["Sign in with GitHub to use your Copilot subscription"],
    },
    ProviderInfo {
        id: "gemini",
        name: "Google Gemini",
        models: &[],
        key_label: "API Key",
        help_lines: &["Get key from aistudio.google.com"],
    },
    ProviderInfo {
        id: "openrouter",
        name: "OpenRouter",
        models: &[],
        key_label: "API Key",
        help_lines: &["Get key from openrouter.ai/keys"],
    },
    ProviderInfo {
        id: "minimax",
        name: "Minimax",
        models: &[], // Loaded from config.toml at runtime
        key_label: "API Key",
        help_lines: &["Get key from platform.minimax.io"],
    },
    ProviderInfo {
        id: "zhipu",
        name: "z.ai GLM",
        models: &[], // Fetched from API
        key_label: "API Key",
        help_lines: &["Get key from open.bigmodel.cn"],
    },
    ProviderInfo {
        id: "claude-cli",
        name: "Claude CLI",
        models: &["sonnet", "opus", "haiku"],
        key_label: "",
        help_lines: &[
            "Uses local 'claude' CLI subprocess — no API key needed",
            "Requires: npm install -g @anthropic-ai/claude-code",
        ],
    },
    ProviderInfo {
        id: "opencode-cli",
        name: "OpenCode CLI",
        models: &[],
        key_label: "",
        help_lines: &[
            "Uses local 'opencode' CLI subprocess — free models, no API key needed",
            "Requires: curl -fsSL https://opencode.ai/install | bash",
        ],
    },
    ProviderInfo {
        id: "qwen",
        name: "Qwen",
        models: &[
            "qwen3.6-plus",
            "qwen3-max",
            "qwen3-coder-plus",
            "qwen3.5-plus",
            "qwen-max",
            "qwen-plus",
            "qwen-flash",
        ],
        key_label: "API Key",
        help_lines: &[
            "DashScope OpenAI-compatible API (Alibaba Cloud Model Studio)",
            "Get key from bailian.console.aliyun.com or qwen.ai/apiplatform",
        ],
    },
    ProviderInfo {
        id: "", // dynamic — custom providers use runtime names
        name: "Custom OpenAI-Compatible",
        models: &[],
        key_label: "API Key",
        help_lines: &["Enter your own API endpoint"],
    },
];

pub struct ProviderInfo {
    /// Canonical provider id matching `KNOWN_PROVIDERS` (e.g. "anthropic", "claude-cli")
    /// Empty string for "Custom OpenAI-Compatible" (last entry) which is dynamic.
    pub id: &'static str,
    pub name: &'static str,
    pub models: &'static [&'static str],
    pub key_label: &'static str,
    pub help_lines: &'static [&'static str],
}

/// Channel definitions for the unified Channels step.
/// Index mapping: 0=Telegram, 1=Discord, 2=WhatsApp, 3=Slack, 4=Trello
pub const CHANNEL_NAMES: &[(&str, &str)] = &[
    ("Telegram", "Bot token (via @BotFather)"),
    ("Discord", "Bot token (via Developer Portal)"),
    ("WhatsApp", "QR code pairing"),
    ("Slack", "Socket Mode (bot + app tokens)"),
    ("Trello", "API Key + Token from trello.com/power-ups/admin"),
];

/// Template files to seed in the workspace
pub const TEMPLATE_FILES: &[(&str, &str)] = &[
    (
        "SOUL.md",
        include_str!("../../docs/reference/templates/SOUL.md"),
    ),
    (
        "IDENTITY.md",
        include_str!("../../docs/reference/templates/IDENTITY.md"),
    ),
    (
        "USER.md",
        include_str!("../../docs/reference/templates/USER.md"),
    ),
    (
        "AGENTS.md",
        include_str!("../../docs/reference/templates/AGENTS.md"),
    ),
    (
        "TOOLS.md",
        include_str!("../../docs/reference/templates/TOOLS.md"),
    ),
    (
        "MEMORY.md",
        include_str!("../../docs/reference/templates/MEMORY.md"),
    ),
    (
        "CODE.md",
        include_str!("../../docs/reference/templates/CODE.md"),
    ),
    (
        "SECURITY.md",
        include_str!("../../docs/reference/templates/SECURITY.md"),
    ),
];

/// Current step in the onboarding wizard
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OnboardingStep {
    ModeSelect,
    Workspace,
    ProviderAuth,
    Channels,
    TelegramSetup,
    DiscordSetup,
    WhatsAppSetup,
    SlackSetup,
    TrelloSetup,
    VoiceSetup,
    ImageSetup,
    Daemon,
    HealthCheck,
    BrainSetup,
    Complete,
}

impl OnboardingStep {
    /// Step number (1-based)
    pub fn number(&self) -> usize {
        match self {
            Self::ModeSelect => 1,
            Self::Workspace => 2,
            Self::ProviderAuth => 3,
            Self::Channels => 4,
            Self::TelegramSetup => 4, // sub-step of Channels
            Self::DiscordSetup => 4,  // sub-step of Channels
            Self::WhatsAppSetup => 4, // sub-step of Channels
            Self::SlackSetup => 4,    // sub-step of Channels
            Self::TrelloSetup => 4,   // sub-step of Channels
            Self::VoiceSetup => 5,
            Self::ImageSetup => 6,
            Self::Daemon => 7,
            Self::HealthCheck => 8,
            Self::BrainSetup => 9,
            Self::Complete => 10,
        }
    }

    /// Total number of steps (excluding Complete)
    pub fn total() -> usize {
        9
    }

    /// Step title
    pub fn title(&self) -> &'static str {
        match self {
            Self::ModeSelect => "Pick Your Vibe",
            Self::Workspace => "Home Base",
            Self::ProviderAuth => "Brain Fuel",
            Self::Channels => "Chat Me Anywhere",
            Self::TelegramSetup => "Telegram Bot",
            Self::DiscordSetup => "Discord Bot",
            Self::WhatsAppSetup => "WhatsApp",
            Self::SlackSetup => "Slack Bot",
            Self::TrelloSetup => "Trello",
            Self::VoiceSetup => "Voice Superpowers",
            Self::ImageSetup => "Image Handling",
            Self::Daemon => "Always On",
            Self::HealthCheck => "Vibe Check",
            Self::BrainSetup => "Make It Yours",
            Self::Complete => "Let's Go!",
        }
    }

    /// Step subtitle
    pub fn subtitle(&self) -> &'static str {
        match self {
            Self::ModeSelect => "Quick and easy or full control — your call",
            Self::Workspace => "Where my brain lives on disk",
            Self::ProviderAuth => "Pick your AI model and drop your key",
            Self::Channels => "Chat with me from your phone — Telegram, WhatsApp, whatever",
            Self::TelegramSetup => "Hook up your Telegram bot token",
            Self::DiscordSetup => "Hook up your Discord bot token",
            Self::WhatsAppSetup => "Scan the QR code with your phone",
            Self::SlackSetup => "Hook up your Slack bot and app tokens",
            Self::TrelloSetup => "Hook up your Trello API Key and Token",
            Self::VoiceSetup => "Talk to me, literally",
            Self::ImageSetup => "Vision and image generation via Google Gemini",
            Self::Daemon => "Keep me running in the background",
            Self::HealthCheck => "Making sure everything's wired up right",
            Self::BrainSetup => "Make me yours, drop some context so I actually get you",
            Self::Complete => "You're all set — let's build something cool",
        }
    }
}

/// Wizard mode
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WizardMode {
    QuickStart,
    Advanced,
}

/// Health check status for individual checks
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum HealthStatus {
    Pending,
    Running,
    Pass,
    Fail(String),
}

/// Which field is being actively edited in ProviderAuth step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AuthField {
    Provider,
    ApiKey,
    Model,
    CustomName,
    CustomBaseUrl,
    CustomApiKey,
    CustomModel,
    CustomContextWindow,
    ZhipuEndpointType,
}

/// Which field is focused in DiscordSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiscordField {
    BotToken,
    ChannelID,
    AllowedList,
    RespondTo,
}

/// Which field is focused in SlackSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SlackField {
    BotToken,
    AppToken,
    ChannelID,
    AllowedList,
    RespondTo,
}

/// Which field is focused in TelegramSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TelegramField {
    BotToken,
    UserID,
    RespondTo,
}

/// Which field is focused in WhatsAppSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WhatsAppField {
    Connection,
    PhoneAllowlist,
}

/// Which field is focused in TrelloSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TrelloField {
    ApiKey,
    ApiToken,
    BoardId,
    AllowedUsers,
}

/// Channel test connection status
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChannelTestStatus {
    Idle,
    Testing,
    Success,
    Failed(String),
}

/// Which field is focused in VoiceSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum VoiceField {
    SttModeSelect,
    GroqApiKey,
    LocalModelSelect,
    // OpenAI-compatible STT
    SttOpenaiCompatSelect,
    SttOpenaiCompatUrl,
    SttOpenaiCompatModel,
    SttOpenaiCompatKey,
    // Voicebox STT
    SttVoiceboxSelect,
    SttVoiceboxUrl,
    // TTS mode
    TtsModeSelect,
    TtsLocalVoiceSelect,
    // OpenAI-compatible TTS
    TtsOpenaiCompatSelect,
    TtsOpenaiCompatUrl,
    TtsOpenaiCompatModel,
    TtsOpenaiCompatVoice,
    TtsOpenaiCompatKey,
    // Voicebox TTS
    TtsVoiceboxSelect,
    TtsVoiceboxUrl,
    TtsVoiceboxProfileId,
    // Navigation
    Continue,
}

/// Which field is focused in ImageSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ImageField {
    VisionToggle,
    GenerationToggle,
    ApiKey,
}

/// GitHub Copilot device flow status
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GitHubDeviceFlowStatus {
    /// Not started
    Idle,
    /// Waiting for user to enter code at github.com/login/device
    WaitingForUser,
    /// User authorized, token obtained
    Complete,
    /// Flow failed
    Failed(String),
}

/// Which text area is focused in BrainSetup step
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BrainField {
    AboutMe,
    AboutAgent,
}

/// What the app should do after handling a wizard key event
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WizardAction {
    /// Nothing special
    None,
    /// User cancelled the wizard (Esc from step 1)
    Cancel,
    /// Wizard completed successfully
    Complete,
    /// Trigger async AI generation of brain files
    GenerateBrain,
    /// Trigger async model list fetch from provider API
    FetchModels,
    /// Trigger async WhatsApp QR code pairing
    WhatsAppConnect,
    /// Trigger async Telegram test message
    TestTelegram,
    /// Trigger async Discord test message
    TestDiscord,
    /// Trigger async Slack test message
    TestSlack,
    /// Trigger async WhatsApp test message
    TestWhatsApp,
    /// Trigger async Trello connection test
    TestTrello,
    /// Trigger async whisper model download
    DownloadWhisperModel,
    /// Trigger async Piper voice model download
    DownloadPiperVoice,
    /// Trigger GitHub Copilot OAuth device flow
    GitHubDeviceFlow,
    /// Quick-jump step completed — save config and close wizard
    QuickJumpDone,
}