valkyria-cli 0.1.0__py3-none-any.whl
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.
- valkyria_cli-0.1.0.dist-info/METADATA +117 -0
- valkyria_cli-0.1.0.dist-info/RECORD +55 -0
- valkyria_cli-0.1.0.dist-info/WHEEL +4 -0
- valkyria_cli-0.1.0.dist-info/entry_points.txt +3 -0
- valkyrie/__init__.py +5 -0
- valkyrie/auth/__init__.py +21 -0
- valkyrie/auth/account.py +245 -0
- valkyrie/auth/firebase_config.py +28 -0
- valkyrie/auth/login_page.py +177 -0
- valkyrie/auth/server.py +145 -0
- valkyrie/auth/tokens.py +196 -0
- valkyrie/chat/__init__.py +37 -0
- valkyrie/chat/clients.py +431 -0
- valkyrie/chat/commands.py +229 -0
- valkyrie/chat/engine.py +1458 -0
- valkyrie/chat/messages.py +108 -0
- valkyrie/chat/renderer.py +122 -0
- valkyrie/cli/__init__.py +2 -0
- valkyrie/cli/auth_commands.py +61 -0
- valkyrie/cli/chat_commands.py +139 -0
- valkyrie/cli/keys_commands.py +275 -0
- valkyrie/cli/main.py +179 -0
- valkyrie/cli/model_commands.py +334 -0
- valkyrie/cli/rag_commands.py +191 -0
- valkyrie/cli/session_commands.py +247 -0
- valkyrie/cli/setup_wizard.py +510 -0
- valkyrie/core/__init__.py +2 -0
- valkyrie/core/cards.py +55 -0
- valkyrie/core/config.py +84 -0
- valkyrie/core/console.py +122 -0
- valkyrie/core/paths.py +68 -0
- valkyrie/core/workspace.py +87 -0
- valkyrie/providers/__init__.py +23 -0
- valkyrie/providers/base.py +78 -0
- valkyrie/providers/gemini.py +141 -0
- valkyrie/providers/groq.py +102 -0
- valkyrie/providers/nvidia.py +95 -0
- valkyrie/providers/registry.py +233 -0
- valkyrie/rag/__init__.py +32 -0
- valkyrie/rag/chunker.py +75 -0
- valkyrie/rag/embeddings.py +227 -0
- valkyrie/rag/files.py +163 -0
- valkyrie/rag/pinecone_store.py +191 -0
- valkyrie/rag/pipeline.py +170 -0
- valkyrie/sessions/__init__.py +9 -0
- valkyrie/sessions/store.py +544 -0
- valkyrie/tools/__init__.py +6 -0
- valkyrie/tools/local_fs.py +423 -0
- valkyrie/tools/registry.py +100 -0
- valkyrie/tools/web_search.py +73 -0
- valkyrie/vault/__init__.py +26 -0
- valkyrie/vault/crypto.py +119 -0
- valkyrie/vault/prompt.py +77 -0
- valkyrie/vault/store.py +207 -0
- valkyrie/vault/sync.py +140 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
"""
|
|
2
|
+
First-run setup wizard — interactive onboarding matching §4.1 of the spec.
|
|
3
|
+
|
|
4
|
+
Guides the user through:
|
|
5
|
+
1. Optional Firebase Google OAuth browser handoff (or local-only mode)
|
|
6
|
+
2. Encrypted vault setup / remote sync pull & provider API key entry
|
|
7
|
+
3. Live credential validation and model catalog discovery
|
|
8
|
+
4. Optional user profile (name, profession, expertise — never languages/tone)
|
|
9
|
+
5. Role-based model assignments + separate embeddings mode
|
|
10
|
+
6. Review screen with privacy summary -> save only after confirmation
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
|
|
17
|
+
import click
|
|
18
|
+
from rich.panel import Panel
|
|
19
|
+
from rich.table import Table
|
|
20
|
+
|
|
21
|
+
from valkyrie.auth.tokens import AuthUser, get_valid_user
|
|
22
|
+
from valkyrie.core.config import (
|
|
23
|
+
ModelAssignment,
|
|
24
|
+
ProviderConfig,
|
|
25
|
+
UserProfile,
|
|
26
|
+
ValkyrieConfig,
|
|
27
|
+
)
|
|
28
|
+
from valkyrie.core.console import (
|
|
29
|
+
console,
|
|
30
|
+
print_banner,
|
|
31
|
+
print_error,
|
|
32
|
+
print_info,
|
|
33
|
+
print_kv,
|
|
34
|
+
print_rule,
|
|
35
|
+
print_success,
|
|
36
|
+
print_warning,
|
|
37
|
+
)
|
|
38
|
+
from valkyrie.providers.base import ModelCapability, ModelInfo
|
|
39
|
+
from valkyrie.providers.registry import ModelRegistry, get_provider
|
|
40
|
+
from valkyrie.vault.prompt import prompt_master_password, verify_and_prompt
|
|
41
|
+
from valkyrie.vault.store import (
|
|
42
|
+
SUPPORTED_PROVIDERS,
|
|
43
|
+
add_key,
|
|
44
|
+
get_key,
|
|
45
|
+
get_vault_blob,
|
|
46
|
+
save_vault_blob,
|
|
47
|
+
vault_exists,
|
|
48
|
+
)
|
|
49
|
+
from valkyrie.vault.sync import pull_vault, push_vault
|
|
50
|
+
|
|
51
|
+
_CORE_ROLES = ["chat", "code", "planner", "vision", "summarization"]
|
|
52
|
+
_EXPERTISE_CHOICES = ["beginner", "intermediate", "advanced", "skip"]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _step_auth() -> AuthUser | None:
|
|
56
|
+
"""Step 1: Check Firebase auth and explain browser handoff if signed out."""
|
|
57
|
+
print_rule("Step 1 of 5 · Account")
|
|
58
|
+
console.print()
|
|
59
|
+
|
|
60
|
+
user = get_valid_user()
|
|
61
|
+
if user is not None:
|
|
62
|
+
print_success(f"Signed in as [bold]{user.email}[/bold]")
|
|
63
|
+
console.print()
|
|
64
|
+
return user
|
|
65
|
+
|
|
66
|
+
print_info(
|
|
67
|
+
"Valkyrie uses Firebase Google sign-in (via a local browser handoff) "
|
|
68
|
+
"to back up your encrypted key vault."
|
|
69
|
+
)
|
|
70
|
+
print_info("You can also run locally without signing in and log in later.")
|
|
71
|
+
console.print()
|
|
72
|
+
|
|
73
|
+
if click.confirm(" Sign in with Google now?", default=False):
|
|
74
|
+
from valkyrie.cli.auth_commands import login
|
|
75
|
+
|
|
76
|
+
ctx = click.get_current_context(silent=True)
|
|
77
|
+
if ctx is not None:
|
|
78
|
+
ctx.invoke(login)
|
|
79
|
+
else:
|
|
80
|
+
login.callback() # type: ignore[misc]
|
|
81
|
+
user = get_valid_user()
|
|
82
|
+
else:
|
|
83
|
+
print_info("Skipping sign-in. Continuing in local-only mode.")
|
|
84
|
+
|
|
85
|
+
console.print()
|
|
86
|
+
return user
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _maybe_pull_remote_vault(user: AuthUser | None) -> None:
|
|
90
|
+
"""If signed in and no local vault exists, offer to pull from Firebase."""
|
|
91
|
+
if user is None or vault_exists():
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
print_info("Checking Firebase for an existing encrypted vault...")
|
|
95
|
+
blob = pull_vault(user.id_token, user.uid)
|
|
96
|
+
if blob is None:
|
|
97
|
+
return
|
|
98
|
+
|
|
99
|
+
if click.confirm(" Found a synced vault in Firebase. Download it?", default=True):
|
|
100
|
+
save_vault_blob(blob)
|
|
101
|
+
print_success("Remote vault downloaded. You'll unlock it with your master password.")
|
|
102
|
+
console.print()
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _unlock_or_create_password() -> str | None:
|
|
106
|
+
"""Unlock an existing vault or create a new master password."""
|
|
107
|
+
if vault_exists():
|
|
108
|
+
return verify_and_prompt(action="unlock your key vault")
|
|
109
|
+
return prompt_master_password(confirm_new=True)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _collect_provider_keys(password: str) -> dict[str, str]:
|
|
113
|
+
"""Prompt for provider selection and masked API keys, validating live."""
|
|
114
|
+
existing_keys: dict[str, str] = {}
|
|
115
|
+
for pkey in SUPPORTED_PROVIDERS:
|
|
116
|
+
found = get_key(password, pkey)
|
|
117
|
+
if found:
|
|
118
|
+
existing_keys[pkey] = found
|
|
119
|
+
|
|
120
|
+
if existing_keys:
|
|
121
|
+
names = ", ".join(SUPPORTED_PROVIDERS[p]["name"] for p in existing_keys)
|
|
122
|
+
print_info(f"Existing keys found in vault: [bold]{names}[/bold]")
|
|
123
|
+
if not click.confirm(" Add or update another provider key?", default=False):
|
|
124
|
+
return existing_keys
|
|
125
|
+
|
|
126
|
+
print_info("Available hosted providers:")
|
|
127
|
+
console.print()
|
|
128
|
+
for pid, pinfo in SUPPORTED_PROVIDERS.items():
|
|
129
|
+
status = "[green]configured[/green]" if pid in existing_keys else "[dim]not set[/dim]"
|
|
130
|
+
console.print(f" [accent]{pid:<10}[/accent] {pinfo['description']:<32} {status}")
|
|
131
|
+
console.print()
|
|
132
|
+
|
|
133
|
+
while True:
|
|
134
|
+
choice = click.prompt(
|
|
135
|
+
" Select provider to configure (or 'done')",
|
|
136
|
+
type=click.Choice([*SUPPORTED_PROVIDERS.keys(), "done"], case_sensitive=False),
|
|
137
|
+
default="done" if existing_keys else "groq",
|
|
138
|
+
).lower()
|
|
139
|
+
|
|
140
|
+
if choice == "done":
|
|
141
|
+
if not existing_keys:
|
|
142
|
+
print_warning("At least one hosted provider is required for chat.")
|
|
143
|
+
continue
|
|
144
|
+
break
|
|
145
|
+
|
|
146
|
+
pinfo = SUPPORTED_PROVIDERS[choice]
|
|
147
|
+
print_info(f"Get your {pinfo['name']} key at: [dim]{pinfo['url']}[/dim]")
|
|
148
|
+
raw_key = click.prompt(
|
|
149
|
+
f" {pinfo['name']} API key",
|
|
150
|
+
hide_input=True,
|
|
151
|
+
prompt_suffix=": ",
|
|
152
|
+
).strip()
|
|
153
|
+
|
|
154
|
+
if not raw_key:
|
|
155
|
+
print_error("API key cannot be empty.")
|
|
156
|
+
continue
|
|
157
|
+
|
|
158
|
+
provider = get_provider(choice)
|
|
159
|
+
if provider is not None:
|
|
160
|
+
print_info(f"Validating {pinfo['name']} credentials...")
|
|
161
|
+
valid = asyncio.run(provider.validate_key(raw_key))
|
|
162
|
+
if not valid:
|
|
163
|
+
print_error(f"{pinfo['name']} rejected this key or was unreachable.")
|
|
164
|
+
if not click.confirm(" Save anyway?", default=False):
|
|
165
|
+
continue
|
|
166
|
+
|
|
167
|
+
add_key(password, choice, raw_key)
|
|
168
|
+
existing_keys[choice] = raw_key
|
|
169
|
+
print_success(f"{pinfo['name']} key stored in encrypted vault.")
|
|
170
|
+
console.print()
|
|
171
|
+
|
|
172
|
+
if not click.confirm(" Connect another provider?", default=False):
|
|
173
|
+
break
|
|
174
|
+
|
|
175
|
+
return existing_keys
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _step_providers_and_discovery(
|
|
179
|
+
user: AuthUser | None,
|
|
180
|
+
) -> tuple[str | None, dict[str, str], ModelRegistry]:
|
|
181
|
+
"""Step 2: Vault unlock/creation, key entry, and model catalog discovery."""
|
|
182
|
+
print_rule("Step 2 of 5 · Providers & Models")
|
|
183
|
+
console.print()
|
|
184
|
+
|
|
185
|
+
_maybe_pull_remote_vault(user)
|
|
186
|
+
|
|
187
|
+
password = _unlock_or_create_password()
|
|
188
|
+
if password is None:
|
|
189
|
+
return None, {}, ModelRegistry.load_cache()
|
|
190
|
+
|
|
191
|
+
api_keys = _collect_provider_keys(password)
|
|
192
|
+
if not api_keys:
|
|
193
|
+
return password, {}, ModelRegistry.load_cache()
|
|
194
|
+
|
|
195
|
+
print_info("Fetching model catalogs...")
|
|
196
|
+
registry = ModelRegistry.load_cache()
|
|
197
|
+
summary = asyncio.run(registry.refresh(api_keys))
|
|
198
|
+
|
|
199
|
+
console.print()
|
|
200
|
+
for pkey, (valid, count) in summary.items():
|
|
201
|
+
pname = SUPPORTED_PROVIDERS[pkey]["name"]
|
|
202
|
+
if valid:
|
|
203
|
+
print_success(f"{pname:<15} {count} models available")
|
|
204
|
+
else:
|
|
205
|
+
print_warning(f"{pname:<15} could not fetch catalog (cached data preserved)")
|
|
206
|
+
|
|
207
|
+
_print_capability_summary(registry)
|
|
208
|
+
console.print()
|
|
209
|
+
return password, api_keys, registry
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _print_capability_summary(registry: ModelRegistry) -> None:
|
|
213
|
+
"""Group discovered models by capability and show counts."""
|
|
214
|
+
if not registry.models:
|
|
215
|
+
return
|
|
216
|
+
|
|
217
|
+
console.print()
|
|
218
|
+
for cap in ModelCapability:
|
|
219
|
+
matches = registry.list_models(capability=cap)
|
|
220
|
+
if matches:
|
|
221
|
+
sample = ", ".join(m.qualified_id for m in matches[:3])
|
|
222
|
+
suffix = f" (+{len(matches) - 3} more)" if len(matches) > 3 else ""
|
|
223
|
+
print_kv(cap.value, f"[dim]{sample}{suffix}[/dim]")
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _step_profile(user: AuthUser | None, existing: UserProfile) -> UserProfile:
|
|
227
|
+
"""Step 3: Optional user profile (never asks for languages or tone)."""
|
|
228
|
+
print_rule("Step 3 of 5 · Profile (Optional)")
|
|
229
|
+
console.print()
|
|
230
|
+
print_info("All fields are optional. Press Enter to skip any question.")
|
|
231
|
+
console.print()
|
|
232
|
+
|
|
233
|
+
default_name = existing.name or (user.display_name if user else None) or ""
|
|
234
|
+
name = click.prompt(" Preferred name", default=default_name, show_default=bool(default_name))
|
|
235
|
+
profession = click.prompt(
|
|
236
|
+
" Profession",
|
|
237
|
+
default=existing.profession or "",
|
|
238
|
+
show_default=bool(existing.profession),
|
|
239
|
+
)
|
|
240
|
+
expertise = click.prompt(
|
|
241
|
+
" Expertise level",
|
|
242
|
+
type=click.Choice(_EXPERTISE_CHOICES, case_sensitive=False),
|
|
243
|
+
default=existing.expertise or "skip",
|
|
244
|
+
).lower()
|
|
245
|
+
|
|
246
|
+
console.print()
|
|
247
|
+
return UserProfile(
|
|
248
|
+
name=name.strip() or None,
|
|
249
|
+
profession=profession.strip() or None,
|
|
250
|
+
expertise=None if expertise == "skip" else expertise,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _prompt_role_model(
|
|
255
|
+
role: str,
|
|
256
|
+
candidates: list[ModelInfo],
|
|
257
|
+
current: str | None,
|
|
258
|
+
*,
|
|
259
|
+
required: bool = False,
|
|
260
|
+
) -> str | None:
|
|
261
|
+
"""Prompt user to pick a compatible model for a role, with provider filtering."""
|
|
262
|
+
if not candidates:
|
|
263
|
+
print_info(f"Role [bold]{role}[/bold]: no compatible models discovered -> unassigned")
|
|
264
|
+
return None
|
|
265
|
+
|
|
266
|
+
active_filter: str | None = None
|
|
267
|
+
while True:
|
|
268
|
+
visible = (
|
|
269
|
+
[m for m in candidates if m.provider == active_filter]
|
|
270
|
+
if active_filter
|
|
271
|
+
else candidates
|
|
272
|
+
)
|
|
273
|
+
shown = visible[:10]
|
|
274
|
+
filter_label = f" · filter={active_filter}" if active_filter else ""
|
|
275
|
+
console.print(
|
|
276
|
+
f" [heading]{role.upper()}[/heading] "
|
|
277
|
+
f"[muted]({len(visible)} compatible{filter_label})[/muted]"
|
|
278
|
+
)
|
|
279
|
+
for idx, m in enumerate(shown, start=1):
|
|
280
|
+
ctx = f"{m.context_window // 1000}k" if m.context_window else "unknown ctx"
|
|
281
|
+
console.print(
|
|
282
|
+
f" [accent]{idx:>2}[/accent] [model]{m.qualified_id}[/model] [dim]({ctx})[/dim]"
|
|
283
|
+
)
|
|
284
|
+
if len(visible) > len(shown):
|
|
285
|
+
more = len(visible) - len(shown)
|
|
286
|
+
console.print(
|
|
287
|
+
f" [dim]... +{more} more. Type a provider name (groq/gemini/nvidia) "
|
|
288
|
+
"to filter, or enter <provider>/<model>.[/dim]"
|
|
289
|
+
)
|
|
290
|
+
if not required:
|
|
291
|
+
console.print(" [accent]0[/accent] [muted]unassigned[/muted]")
|
|
292
|
+
|
|
293
|
+
default_val = "1" if (required or current is None) else current
|
|
294
|
+
raw = click.prompt(f" Select {role} model", default=default_val).strip()
|
|
295
|
+
lower_raw = raw.lower()
|
|
296
|
+
if lower_raw in ("all", "*"):
|
|
297
|
+
active_filter = None
|
|
298
|
+
console.print()
|
|
299
|
+
continue
|
|
300
|
+
if lower_raw in {m.provider for m in candidates}:
|
|
301
|
+
active_filter = lower_raw
|
|
302
|
+
console.print()
|
|
303
|
+
continue
|
|
304
|
+
if raw == "0" or lower_raw == "unassigned":
|
|
305
|
+
if required:
|
|
306
|
+
print_warning(f"Role '{role}' requires a model.")
|
|
307
|
+
continue
|
|
308
|
+
return None
|
|
309
|
+
if raw.isdigit():
|
|
310
|
+
pos = int(raw) - 1
|
|
311
|
+
if 0 <= pos < len(shown):
|
|
312
|
+
return shown[pos].qualified_id
|
|
313
|
+
match = next((m for m in candidates if m.qualified_id == raw), None)
|
|
314
|
+
if match is not None:
|
|
315
|
+
return match.qualified_id
|
|
316
|
+
print_error(
|
|
317
|
+
"Invalid selection. Enter a number, provider name to filter, or provider/model."
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _step_assignments(
|
|
322
|
+
registry: ModelRegistry,
|
|
323
|
+
existing_models: ModelAssignment,
|
|
324
|
+
existing_embedding_mode: str,
|
|
325
|
+
) -> tuple[ModelAssignment, str]:
|
|
326
|
+
"""Step 4: Assign compatible models to roles and configure Pinecone embeddings."""
|
|
327
|
+
print_rule("Step 4 of 5 · Role Assignments")
|
|
328
|
+
console.print()
|
|
329
|
+
|
|
330
|
+
assignments = ModelAssignment()
|
|
331
|
+
for role in _CORE_ROLES:
|
|
332
|
+
candidates = registry.list_models(role=role)
|
|
333
|
+
current = getattr(existing_models, role, None)
|
|
334
|
+
selected = _prompt_role_model(
|
|
335
|
+
role,
|
|
336
|
+
candidates,
|
|
337
|
+
current,
|
|
338
|
+
required=(role == "chat" and bool(candidates)),
|
|
339
|
+
)
|
|
340
|
+
setattr(assignments, role, selected)
|
|
341
|
+
console.print()
|
|
342
|
+
|
|
343
|
+
print_info("RAG vectors & chunks are stored exclusively in Pinecone DB (never locally).")
|
|
344
|
+
print_info(
|
|
345
|
+
"[dim]pinecone[/dim] uses Pinecone Inference / hash vectors; "
|
|
346
|
+
"[dim]hosted[/dim] uses an explicit provider embedding model."
|
|
347
|
+
)
|
|
348
|
+
embed_candidates = registry.list_models(role="embeddings")
|
|
349
|
+
choices = ["pinecone", "unassigned"]
|
|
350
|
+
if embed_candidates:
|
|
351
|
+
choices.insert(1, "hosted")
|
|
352
|
+
|
|
353
|
+
embedding_mode = click.prompt(
|
|
354
|
+
" Embeddings mode",
|
|
355
|
+
type=click.Choice(choices, case_sensitive=False),
|
|
356
|
+
default=existing_embedding_mode if existing_embedding_mode in choices else "pinecone",
|
|
357
|
+
).lower()
|
|
358
|
+
|
|
359
|
+
if embedding_mode == "hosted":
|
|
360
|
+
assignments.embeddings = _prompt_role_model(
|
|
361
|
+
"embeddings",
|
|
362
|
+
embed_candidates,
|
|
363
|
+
existing_models.embeddings,
|
|
364
|
+
required=True,
|
|
365
|
+
)
|
|
366
|
+
else:
|
|
367
|
+
assignments.embeddings = None
|
|
368
|
+
|
|
369
|
+
console.print()
|
|
370
|
+
return assignments, embedding_mode
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def _step_review_and_save(
|
|
374
|
+
config: ValkyrieConfig,
|
|
375
|
+
user: AuthUser | None,
|
|
376
|
+
password: str | None,
|
|
377
|
+
) -> bool:
|
|
378
|
+
"""Step 5: Show review screen with privacy summary; save only after confirmation."""
|
|
379
|
+
print_rule("Step 5 of 5 · Review & Confirm")
|
|
380
|
+
console.print()
|
|
381
|
+
|
|
382
|
+
table = Table(border_style="rule", show_header=False, pad_edge=False)
|
|
383
|
+
table.add_column("Setting", style="key", width=20)
|
|
384
|
+
table.add_column("Value", style="value")
|
|
385
|
+
|
|
386
|
+
auth_str = user.email if user else "local-only (not signed in)"
|
|
387
|
+
providers_str = ", ".join(config.providers.keys()) or "none"
|
|
388
|
+
table.add_row("Account", auth_str)
|
|
389
|
+
table.add_row("Providers", providers_str)
|
|
390
|
+
table.add_row("Chat model", config.models.chat or "unassigned")
|
|
391
|
+
table.add_row("Code model", config.models.code or "unassigned")
|
|
392
|
+
table.add_row("Planner model", config.models.planner or "unassigned")
|
|
393
|
+
table.add_row("Vision model", config.models.vision or "unassigned")
|
|
394
|
+
table.add_row("Summarization", config.models.summarization or "unassigned")
|
|
395
|
+
embed_display = (
|
|
396
|
+
f"hosted ({config.models.embeddings})"
|
|
397
|
+
if config.embedding_mode == "hosted" and config.models.embeddings
|
|
398
|
+
else config.embedding_mode
|
|
399
|
+
)
|
|
400
|
+
table.add_row("Embeddings", embed_display)
|
|
401
|
+
table.add_row("Vault sync", "enabled" if config.sync_enabled else "disabled")
|
|
402
|
+
console.print(table)
|
|
403
|
+
console.print()
|
|
404
|
+
|
|
405
|
+
privacy_lines = [
|
|
406
|
+
"• Prompts and attached context are sent only to the hosted provider you invoke.",
|
|
407
|
+
"• API keys remain encrypted locally with AES-256-GCM (master password never stored).",
|
|
408
|
+
]
|
|
409
|
+
if config.embedding_mode == "hosted" and config.models.embeddings:
|
|
410
|
+
privacy_lines.append(
|
|
411
|
+
f"• RAG Storage: Pinecone DB ({config.pinecone.index_name}) "
|
|
412
|
+
f"with hosted embeddings ({config.models.embeddings})."
|
|
413
|
+
)
|
|
414
|
+
elif config.embedding_mode == "unassigned":
|
|
415
|
+
privacy_lines.append("• RAG indexing is unassigned (Pinecone not enabled).")
|
|
416
|
+
else:
|
|
417
|
+
privacy_lines.append(
|
|
418
|
+
f"• RAG Storage: Pinecone DB only ({config.pinecone.index_name}) "
|
|
419
|
+
"— zero local vector storage."
|
|
420
|
+
)
|
|
421
|
+
if config.sync_enabled:
|
|
422
|
+
privacy_lines.append(
|
|
423
|
+
"• Sync enabled: only your opaque encrypted vault blob is uploaded to Firebase."
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
console.print(
|
|
427
|
+
Panel(
|
|
428
|
+
"\n".join(privacy_lines),
|
|
429
|
+
title="[heading]Privacy Summary[/heading]",
|
|
430
|
+
border_style="rule",
|
|
431
|
+
)
|
|
432
|
+
)
|
|
433
|
+
console.print()
|
|
434
|
+
|
|
435
|
+
if not click.confirm(" Save this configuration?", default=True):
|
|
436
|
+
print_warning("Setup cancelled. Nothing was saved.")
|
|
437
|
+
console.print()
|
|
438
|
+
return False
|
|
439
|
+
|
|
440
|
+
config.first_run_complete = True
|
|
441
|
+
saved_path = config.save()
|
|
442
|
+
print_success(f"Configuration saved to [dim]{saved_path}[/dim]")
|
|
443
|
+
|
|
444
|
+
if config.sync_enabled and user is not None and password is not None:
|
|
445
|
+
blob = get_vault_blob()
|
|
446
|
+
if blob and push_vault(user.id_token, user.uid, blob):
|
|
447
|
+
print_success("Encrypted vault synced to Firebase.")
|
|
448
|
+
else:
|
|
449
|
+
print_warning(
|
|
450
|
+
"Vault sync could not complete right now. Run 'valkyrie keys sync' later."
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
console.print()
|
|
454
|
+
print_info("Ready. Try inspecting your catalog: [bold]valkyrie model list[/bold]")
|
|
455
|
+
console.print()
|
|
456
|
+
return True
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def run_setup_wizard() -> bool:
|
|
460
|
+
"""Run the complete first-run setup flow. Returns True if configuration was saved."""
|
|
461
|
+
print_banner()
|
|
462
|
+
console.print()
|
|
463
|
+
|
|
464
|
+
existing = ValkyrieConfig.load()
|
|
465
|
+
user = _step_auth()
|
|
466
|
+
password, api_keys, registry = _step_providers_and_discovery(user)
|
|
467
|
+
if password is None:
|
|
468
|
+
print_error("Setup requires unlocking or creating your vault.")
|
|
469
|
+
console.print()
|
|
470
|
+
return False
|
|
471
|
+
|
|
472
|
+
profile = _step_profile(user, existing.profile)
|
|
473
|
+
models, embedding_mode = _step_assignments(
|
|
474
|
+
registry,
|
|
475
|
+
existing.models,
|
|
476
|
+
existing.embedding_mode,
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
sync_enabled = False
|
|
480
|
+
if user is not None:
|
|
481
|
+
sync_enabled = click.confirm(
|
|
482
|
+
" Automatically sync encrypted key vault to Firebase?",
|
|
483
|
+
default=existing.sync_enabled or True,
|
|
484
|
+
)
|
|
485
|
+
console.print()
|
|
486
|
+
|
|
487
|
+
providers_cfg = {
|
|
488
|
+
pkey: ProviderConfig(name=SUPPORTED_PROVIDERS[pkey]["name"], enabled=True)
|
|
489
|
+
for pkey in api_keys
|
|
490
|
+
if pkey in SUPPORTED_PROVIDERS
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
new_config = ValkyrieConfig(
|
|
494
|
+
version=existing.version,
|
|
495
|
+
first_run_complete=True,
|
|
496
|
+
profile=profile,
|
|
497
|
+
models=models,
|
|
498
|
+
providers=providers_cfg,
|
|
499
|
+
embedding_mode=embedding_mode,
|
|
500
|
+
sync_enabled=sync_enabled,
|
|
501
|
+
feature_flags=existing.feature_flags,
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
return _step_review_and_save(new_config, user, password)
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
@click.command()
|
|
508
|
+
def setup() -> None:
|
|
509
|
+
"""Run the interactive setup wizard."""
|
|
510
|
+
run_setup_wizard()
|
valkyrie/core/cards.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Compact tool action cards — left-accented Rich panels for workspace & provider clarity.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from rich import box
|
|
8
|
+
from rich.panel import Panel
|
|
9
|
+
from rich.text import Text
|
|
10
|
+
|
|
11
|
+
from valkyrie.core.console import console
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def render_tool_card(
|
|
15
|
+
*,
|
|
16
|
+
tool: str,
|
|
17
|
+
status: str,
|
|
18
|
+
target: str,
|
|
19
|
+
summary: str,
|
|
20
|
+
details: str | None = None,
|
|
21
|
+
) -> None:
|
|
22
|
+
"""
|
|
23
|
+
Render a sharp editorial action card with semantic left border accents.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
tool: Tool label (e.g. 'read', 'index', 'search', 'rag', 'provider')
|
|
27
|
+
status: 'ok', 'blocked', or 'error'
|
|
28
|
+
target: Target file path, directory, model, or query
|
|
29
|
+
summary: Single-line summary of operation/effect
|
|
30
|
+
details: Optional multi-line snippet or citation details
|
|
31
|
+
"""
|
|
32
|
+
status_style, border_style, badge = {
|
|
33
|
+
"ok": ("bold bright_green", "cyan", "OK"),
|
|
34
|
+
"blocked": ("bold bright_yellow", "yellow", "BLOCKED"),
|
|
35
|
+
"error": ("bold bright_red", "red", "ERROR"),
|
|
36
|
+
}.get(status, ("bold bright_cyan", "cyan", status.upper()))
|
|
37
|
+
|
|
38
|
+
body = Text()
|
|
39
|
+
body.append(f" {badge} ", style=f"{status_style} reverse")
|
|
40
|
+
body.append(" ")
|
|
41
|
+
body.append(target, style="bold bright_white")
|
|
42
|
+
body.append(f"\n{summary}", style="grey70")
|
|
43
|
+
if details:
|
|
44
|
+
body.append(f"\n\n{details}", style="white")
|
|
45
|
+
|
|
46
|
+
console.print(
|
|
47
|
+
Panel(
|
|
48
|
+
body,
|
|
49
|
+
box=box.ROUNDED,
|
|
50
|
+
title=f"[heading]◆ {tool.upper()}[/heading]",
|
|
51
|
+
title_align="left",
|
|
52
|
+
border_style=border_style,
|
|
53
|
+
padding=(0, 1),
|
|
54
|
+
)
|
|
55
|
+
)
|
valkyrie/core/config.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Configuration management — load, save, and validate user config.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import json
|
|
8
|
+
from typing import TYPE_CHECKING, Any
|
|
9
|
+
|
|
10
|
+
from pydantic import BaseModel, Field
|
|
11
|
+
|
|
12
|
+
from valkyrie.core.paths import get_config_path
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class UserProfile(BaseModel):
|
|
19
|
+
"""Optional user profile information."""
|
|
20
|
+
|
|
21
|
+
name: str | None = None
|
|
22
|
+
profession: str | None = None
|
|
23
|
+
expertise: str | None = None # "beginner", "intermediate", "advanced"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ModelAssignment(BaseModel):
|
|
27
|
+
"""Model-to-role mapping."""
|
|
28
|
+
|
|
29
|
+
chat: str | None = None # "provider/model"
|
|
30
|
+
code: str | None = None
|
|
31
|
+
planner: str | None = None
|
|
32
|
+
vision: str | None = None
|
|
33
|
+
summarization: str | None = None
|
|
34
|
+
embeddings: str | None = None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ProviderConfig(BaseModel):
|
|
38
|
+
"""Configuration for a single provider."""
|
|
39
|
+
|
|
40
|
+
name: str
|
|
41
|
+
enabled: bool = True
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class PineconeConfig(BaseModel):
|
|
45
|
+
"""Configuration for Pinecone vector DB (RAG)."""
|
|
46
|
+
|
|
47
|
+
index_name: str = "valkyrie-rag"
|
|
48
|
+
cloud: str = "aws"
|
|
49
|
+
region: str = "us-east-1"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ValkyrieConfig(BaseModel):
|
|
53
|
+
"""Root configuration schema."""
|
|
54
|
+
|
|
55
|
+
version: int = 1
|
|
56
|
+
first_run_complete: bool = False
|
|
57
|
+
profile: UserProfile = Field(default_factory=UserProfile)
|
|
58
|
+
models: ModelAssignment = Field(default_factory=ModelAssignment)
|
|
59
|
+
providers: dict[str, ProviderConfig] = Field(default_factory=dict)
|
|
60
|
+
pinecone: PineconeConfig = Field(default_factory=PineconeConfig)
|
|
61
|
+
embedding_mode: str = "pinecone" # "pinecone", "hosted", or "unassigned"
|
|
62
|
+
sync_enabled: bool = False
|
|
63
|
+
feature_flags: dict[str, bool] = Field(default_factory=dict)
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def load(cls) -> ValkyrieConfig:
|
|
67
|
+
"""Load config from disk, or return defaults if not found."""
|
|
68
|
+
path = get_config_path()
|
|
69
|
+
if path.exists():
|
|
70
|
+
data: dict[str, Any] = json.loads(path.read_text())
|
|
71
|
+
return cls.model_validate(data)
|
|
72
|
+
return cls()
|
|
73
|
+
|
|
74
|
+
def save(self) -> Path:
|
|
75
|
+
"""Save config to disk and return the path."""
|
|
76
|
+
path = get_config_path()
|
|
77
|
+
path.write_text(self.model_dump_json(indent=2) + "\n")
|
|
78
|
+
return path
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def is_first_run(self) -> bool:
|
|
82
|
+
"""Check if this is the first run."""
|
|
83
|
+
return not self.first_run_complete
|
|
84
|
+
|