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.
Files changed (55) hide show
  1. valkyria_cli-0.1.0.dist-info/METADATA +117 -0
  2. valkyria_cli-0.1.0.dist-info/RECORD +55 -0
  3. valkyria_cli-0.1.0.dist-info/WHEEL +4 -0
  4. valkyria_cli-0.1.0.dist-info/entry_points.txt +3 -0
  5. valkyrie/__init__.py +5 -0
  6. valkyrie/auth/__init__.py +21 -0
  7. valkyrie/auth/account.py +245 -0
  8. valkyrie/auth/firebase_config.py +28 -0
  9. valkyrie/auth/login_page.py +177 -0
  10. valkyrie/auth/server.py +145 -0
  11. valkyrie/auth/tokens.py +196 -0
  12. valkyrie/chat/__init__.py +37 -0
  13. valkyrie/chat/clients.py +431 -0
  14. valkyrie/chat/commands.py +229 -0
  15. valkyrie/chat/engine.py +1458 -0
  16. valkyrie/chat/messages.py +108 -0
  17. valkyrie/chat/renderer.py +122 -0
  18. valkyrie/cli/__init__.py +2 -0
  19. valkyrie/cli/auth_commands.py +61 -0
  20. valkyrie/cli/chat_commands.py +139 -0
  21. valkyrie/cli/keys_commands.py +275 -0
  22. valkyrie/cli/main.py +179 -0
  23. valkyrie/cli/model_commands.py +334 -0
  24. valkyrie/cli/rag_commands.py +191 -0
  25. valkyrie/cli/session_commands.py +247 -0
  26. valkyrie/cli/setup_wizard.py +510 -0
  27. valkyrie/core/__init__.py +2 -0
  28. valkyrie/core/cards.py +55 -0
  29. valkyrie/core/config.py +84 -0
  30. valkyrie/core/console.py +122 -0
  31. valkyrie/core/paths.py +68 -0
  32. valkyrie/core/workspace.py +87 -0
  33. valkyrie/providers/__init__.py +23 -0
  34. valkyrie/providers/base.py +78 -0
  35. valkyrie/providers/gemini.py +141 -0
  36. valkyrie/providers/groq.py +102 -0
  37. valkyrie/providers/nvidia.py +95 -0
  38. valkyrie/providers/registry.py +233 -0
  39. valkyrie/rag/__init__.py +32 -0
  40. valkyrie/rag/chunker.py +75 -0
  41. valkyrie/rag/embeddings.py +227 -0
  42. valkyrie/rag/files.py +163 -0
  43. valkyrie/rag/pinecone_store.py +191 -0
  44. valkyrie/rag/pipeline.py +170 -0
  45. valkyrie/sessions/__init__.py +9 -0
  46. valkyrie/sessions/store.py +544 -0
  47. valkyrie/tools/__init__.py +6 -0
  48. valkyrie/tools/local_fs.py +423 -0
  49. valkyrie/tools/registry.py +100 -0
  50. valkyrie/tools/web_search.py +73 -0
  51. valkyrie/vault/__init__.py +26 -0
  52. valkyrie/vault/crypto.py +119 -0
  53. valkyrie/vault/prompt.py +77 -0
  54. valkyrie/vault/store.py +207 -0
  55. valkyrie/vault/sync.py +140 -0
@@ -0,0 +1,117 @@
1
+ Metadata-Version: 2.5
2
+ Name: valkyria-cli
3
+ Version: 0.1.0
4
+ Summary: Terminal-first, multi-model AI agent with local retrieval, controlled system access, and durable sessions
5
+ Author: Anupam
6
+ License: MIT
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: argon2-cffi>=25.1.0
9
+ Requires-Dist: click>=8.1
10
+ Requires-Dist: cryptography>=50.0.2
11
+ Requires-Dist: ddgs>=9.16.1
12
+ Requires-Dist: httpx>=0.27
13
+ Requires-Dist: langchain-community>=0.4.2
14
+ Requires-Dist: langchain-core>=1.8.4
15
+ Requires-Dist: pinecone>=10.3.0
16
+ Requires-Dist: prompt-toolkit>=3.0
17
+ Requires-Dist: pydantic>=2.0
18
+ Requires-Dist: python-dotenv>=1.2.4
19
+ Requires-Dist: rich>=13.0
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Valkyrie CLI — Product and Engineering Specification
23
+
24
+ **Status:** Design specification
25
+ **Version:** 1.0 draft
26
+ **Date:** 25 November 2026
27
+ **Product:** Terminal-first, multi-model AI agent with local retrieval, controlled system access, and durable sessions
28
+
29
+ ---
30
+
31
+ ## 1. Product intent
32
+
33
+ Valkyrie CLI is an AI workspace that runs in a terminal. It answers questions, helps write and edit code, searches local material, creates plans, and carries out approved tasks. Users bring API keys for Groq, Gemini, and NVIDIA. They choose the exact model used for each kind of work. The product keeps its retrieval index and execution history on the user's machine, while making every transfer to a hosted provider visible.
34
+
35
+ The defining experience is **a precise, fast terminal tool with an editorial voice**: concise, confident, occasionally sassy, and always useful. Its interface should feel designed by people who build developer tools, not like a generic AI chat screen. The personality belongs in microcopy and rhythm, never in permission prompts, errors that need diagnosis, or safety decisions.
36
+
37
+ ### 1.1 Product promises
38
+
39
+ 1. A user can enter one or more provider keys, see the models available to those keys, and assign models to tasks.
40
+ 2. A user can understand what the agent is doing, what data leaves the machine, and what action requires approval.
41
+ 3. A session survives process restarts and can be resumed, forked, searched, renamed, compacted, or deleted.
42
+ 4. Local documents can be indexed and searched without a cloud vector database.
43
+ 5. Files and commands are controlled by scoped permissions, previews, snapshots, limits, and an audit trail.
44
+ 6. The CLI remains useful in narrow terminals, over SSH, and without full TUI support.
45
+
46
+ ### 1.2 Primary users
47
+
48
+ | User | Main job | Need |
49
+ |---|---|---|
50
+ | Developer | Understand and change a codebase | Fast context, diffs, command transparency, undo |
51
+ | Technical researcher | Search documents and compare evidence | Source citations, local indexing, clear provenance |
52
+ | Power user | Inspect and automate a workstation | Explicit scopes, dry runs, reliable approvals |
53
+ | Multi-model user | Assign the right model to each task | Live catalog, capabilities, cost visibility where available |
54
+
55
+ ### 1.3 Non-goals for initial release
56
+
57
+ - A desktop GUI or web chat product.
58
+ - Autonomous operation without a user-visible approval boundary.
59
+ - Cloud hosting of document indexes or raw local files.
60
+ - Team administration, shared workspaces, or billing aggregation.
61
+ - Running hosted provider models offline.
62
+ - Guaranteeing an undo of arbitrary shell commands or external side effects.
63
+
64
+ ## 2. Scope and release definitions
65
+
66
+ **MVP:** Login, local key vault, provider model discovery, model assignments, chat, sessions, context accounting, read-only local file access, basic local RAG, and a polished terminal interface.
67
+
68
+ **Beta:** Plan/build, previewed file edits, scoped approvals, snapshots and undo, safe command execution, package management in isolated environments, hybrid search, session sync, and audit export.
69
+
70
+ **V1:** Vision, web search, robust offline behavior, advanced ingestion, security hardening, accessibility and cross-platform certification.
71
+
72
+ Feature flags must prevent unfinished tools from appearing as executable commands. Help may show a clearly marked upcoming feature only in development builds.
73
+
74
+ ## 3. Experience principles
75
+
76
+ 1. **The prompt stays the center.** One active input line; information appears only when relevant.
77
+ 2. **Show the receipt.** Before a consequential action, show target, scope, exact operation, expected effect, and recovery option.
78
+ 3. **Disclose model and data path.** The active model is always visible; any hosted request involving local content is clear.
79
+ 4. **Never make confidence decorative.** Unknown capability, token limit, or cost is shown as unknown.
80
+ 5. **Speed is visual.** Immediate input response, streamed output, stable layout, and no theatrical loading animation.
81
+ 6. **Voice is earned.** Personality can sharpen a success message; critical prompts remain neutral and exact.
82
+
83
+ ## 4. User journeys
84
+
85
+ ### 4.1 First run
86
+
87
+ 1. `valkyrie` starts and checks local configuration.
88
+ 2. If signed out, show `valkyrie login` with a short explanation of the browser handoff.
89
+ 3. After login, ask which providers to connect. At least one hosted model provider is required for chat; the user may return later to add more.
90
+ 4. Read each API key with masked, no-echo input. Never put a key in a command-line argument or shell history.
91
+ 5. Validate credentials and fetch the provider catalog. Show accessible models, grouped by capability. A list result alone does not guarantee invocation rights; a low-cost probe validates the selected model when feasible.
92
+ 6. Ask for the user's preferred name, profession, and expertise level. All are optional; **do not ask for known languages or tone**.
93
+ 7. Assign models to chat, code, planner, vision, and summarization. Embeddings are configured separately because they have a different data-transfer implication. Only show models that support the role; allow `unassigned` for optional roles.
94
+ 8. Display a review screen: providers, role assignments, local/hosted embedding mode, sync setting, and a plain-language privacy summary. Save only after confirmation.
95
+ 9. Open a new session and show one sample action, not a long tutorial.
96
+
97
+ ### 4.2 Daily use
98
+
99
+ 1. Launch in the current directory; that directory is the suggested workspace root.
100
+ 2. Resume the last session unless the user requests `--new` or a specific session.
101
+ 3. Type a question or use a slash command. `/` lists commands; a partial command filters them. `@` suggests accessible workspace paths.
102
+ 4. The assistant streams output. Tool actions appear as compact cards with status and expandable details.
103
+ 5. Approvals pause the agent and accept an explicit choice. The agent resumes from a durable checkpoint.
104
+
105
+ ### 4.3 Model change
106
+
107
+ 1. `/model` shows current session model and role assignments.
108
+ 2. `/model list` shows the models available under configured keys, with provider, capability, status, and known limits.
109
+ 3. `/model refresh` refetches catalogs. `/model set code <provider>/<model>` changes an assignment. `/model use <provider>/<model>` overrides the current session's chat model.
110
+ 4. Before switching, recalculate context budget. If the existing context will not fit, offer compaction or a new session.
111
+ 5. If a selected model is retired, inaccessible, or incompatible, explain the exact failure and offer compatible choices. Never silently substitute a model for a paid or privacy-sensitive request.
112
+
113
+ ## 5. Interface design specification
114
+
115
+ ### 5.1 Visual direction
116
+
117
+ The visual language is **editorial terminal**: a restrained grid, strong type hierarchy, sharp rules, meaningful whitespace, and one vivid functional accent. It should feel like an excellent developer instrument rather than a dashboard rendered in monospace. No gradients, glass effects, decorative stars, robot imagery, fake code rain, or generic glowing chat bubbles. Do not add emojis or decorative icons. Use text, rules, spacing, and color to convey structure. ASCII or Unicode box characters are allowed when they improve clarity, with a plain-text fallback.
@@ -0,0 +1,55 @@
1
+ valkyrie/__init__.py,sha256=k_DATx75dOMxqEedc0j8mEcZU3Bg9-JxfTYL_1jWHxg,111
2
+ valkyrie/auth/__init__.py,sha256=vseQFG55asMEOK5YxNZpAvczO4rjVBmkt2qGMJdNeC0,358
3
+ valkyrie/auth/account.py,sha256=jpCvpyEsa0t3I2-wGc28Um5QbwePdLjinAbvZirGhPA,7944
4
+ valkyrie/auth/firebase_config.py,sha256=CBjsF3HUWaHr3Wy1SfqNT26QbrJAvEEOhwiE-fCqeAk,1015
5
+ valkyrie/auth/login_page.py,sha256=penTGSgxz7INakNmHJkrWUc5bDmSgcaph9BrKnxL5lQ,6320
6
+ valkyrie/auth/server.py,sha256=yrK4XtMa5gWowyRkWozc-PgmYATTBC25l8f-jpCLP6Q,4562
7
+ valkyrie/auth/tokens.py,sha256=GT_6JLK5BAHRGOE6XHtjx5vveoquIwZxjDDy8MVtYOY,5575
8
+ valkyrie/chat/__init__.py,sha256=UxFrLVR6AzIV3EY69tAPFIRauKV0SrgHevDAQXuozIw,928
9
+ valkyrie/chat/clients.py,sha256=mlPD-umGFTOESNHS18lcAmQ9AZVV0YToOJBjK2M1mIE,14959
10
+ valkyrie/chat/commands.py,sha256=Rn9gaE363VkmIHgPqmsiYjGteWJoEBpPZPYbKkXwFew,8458
11
+ valkyrie/chat/engine.py,sha256=ys5WGVQ6xMYt6ZIEbKjcByzTnbKzjfqInX-V65CyMOk,53961
12
+ valkyrie/chat/messages.py,sha256=tWLn59hK7BdBZdwHL90hMZDTUiRwo516M05RkJmdp24,3230
13
+ valkyrie/chat/renderer.py,sha256=-rAa1bIBgeBh2TgGKmnjn7ULZT-Lt4VRRijUkM_Wk-8,3911
14
+ valkyrie/cli/__init__.py,sha256=Ru6FLXCh5sa8zldP5Vs_93-fWpotQ0v3DbVvnZlSt24,42
15
+ valkyrie/cli/auth_commands.py,sha256=UrDxjukWCfpfOYmCtNljrClKhTEojvmPGAqCkzaoImc,1390
16
+ valkyrie/cli/chat_commands.py,sha256=P16IEGzWAm8Z-sJEXef9vlteWUtPcSndKzcMBgz8fgY,4789
17
+ valkyrie/cli/keys_commands.py,sha256=0kF4UcV6WxVnYPw49hamnv7241ikz4i6XnFVTDqDeZg,7967
18
+ valkyrie/cli/main.py,sha256=msFa0iw2hRGDarYl6Q5ZsIg8QdSNaivgPhInseHa_JA,5479
19
+ valkyrie/cli/model_commands.py,sha256=OGxoLT5jYLvMy1EEbCfrtrVqcixC2CCqZenl46uHUK8,10779
20
+ valkyrie/cli/rag_commands.py,sha256=yRUT6sdGRgMDPQA56gCsanO5J-XzqmcJGdTKa6bsrbk,5700
21
+ valkyrie/cli/session_commands.py,sha256=DeEgp1Wx3EXD59_L0OXm67zKc3CEnXZxNa1dF0T6xfo,7781
22
+ valkyrie/cli/setup_wizard.py,sha256=w9TohoKFXauY7NvbrHwtI4aVVAxqTphBQg8Y2Yucn7c,17772
23
+ valkyrie/core/__init__.py,sha256=R5MC2OeSHPd6P1YEKGjplNW_HB2UMI1Swuex17TAje4,70
24
+ valkyrie/core/cards.py,sha256=Xxhs74MJSfS9x9EFhtdBC0JA9NqBc6wSmkvKnaBrBxA,1607
25
+ valkyrie/core/config.py,sha256=A2iw7fPrcw6W_J-mPfBlPnDyiWTlyodL2xRMB7hGjHk,2323
26
+ valkyrie/core/console.py,sha256=pRiNJfrUce8U-CydwgC51vB0burHCoKwpGa-uXj4EbI,4005
27
+ valkyrie/core/paths.py,sha256=KSrBzIG2yH186e1sfOhfchwOXRBpJek4S_y3QpW5nR4,1877
28
+ valkyrie/core/workspace.py,sha256=6OoEJzlGkMqKyWIwucpDxDs9DLEVXCl6iJGy3-pGNvc,2386
29
+ valkyrie/providers/__init__.py,sha256=q7MFHbpQa6-pCW6ZrE9ULYXy6pX7WVk2GB8ruA14jSU,441
30
+ valkyrie/providers/base.py,sha256=mAhBLw5j6Mjqq7_NQOjK9PoI9u9KWMaIGEpTEwrHP1M,2319
31
+ valkyrie/providers/gemini.py,sha256=PcZr4j2u2kl31MH4J4p6tEe4jyZt0Lm0xaaG9O-PejU,4010
32
+ valkyrie/providers/groq.py,sha256=29rejoy5I3CuNsuqzamQuameOkAVDGiQopPJmXLnFv0,3050
33
+ valkyrie/providers/nvidia.py,sha256=7ANk8G57mjJc7EMSP89Y5kO3U6DlnbTmXf1rILkebvE,2769
34
+ valkyrie/providers/registry.py,sha256=lRrhu8xYNOMmDDe__whilwTULdI3uVvO1u16lKafPWc,8248
35
+ valkyrie/rag/__init__.py,sha256=rDh34ORqmwWBGVe-4U0ejop0W6OwrKtdyfMenE2Vn4k,987
36
+ valkyrie/rag/chunker.py,sha256=8iust05lg95-IH-qHXg8DGlngSgYWx9gGoSY6IL2UGc,1728
37
+ valkyrie/rag/embeddings.py,sha256=mrLu2XhTpesuLrLhmPtuznSQc09jXthIYwHPEFbjKAM,7589
38
+ valkyrie/rag/files.py,sha256=J9FWvcmuwR-GSo8Fk_KxuJ7c-vfb2EO_nAsqvE4eVck,4366
39
+ valkyrie/rag/pinecone_store.py,sha256=EbwUaQixi5kKQnGQKWipDP2Xs9YUChclM19qwGUeN7M,6340
40
+ valkyrie/rag/pipeline.py,sha256=f9Kgh4V5FHIl6tJMtpwvyeegVAFq-zOt5v6AKEt8vBU,5153
41
+ valkyrie/sessions/__init__.py,sha256=kCeJdYXfwEHhfQHG_m__B6FfkRCVMC7rL-XaDY1BEAg,256
42
+ valkyrie/sessions/store.py,sha256=IAMi5FImvHKArLBYYE_Bp0UCt5o3__WU2tSyoX4ekvo,19960
43
+ valkyrie/tools/__init__.py,sha256=STP-wyLTcaU0XjEoIvB3FIvEo58rvOyw0Nq4ZODe5II,240
44
+ valkyrie/tools/local_fs.py,sha256=Q2FivSnWMMuZgYkelNr7QRGCDKKdFCnAWU8Qcj3HXk0,13878
45
+ valkyrie/tools/registry.py,sha256=7HbwK3QWYUnLcgn7UR1HuJAnpwu0evIfCeeZPR8fqEE,3808
46
+ valkyrie/tools/web_search.py,sha256=xyyCiAXHhAIPRL3H3zfUVt45AMlWKRbHkhoqF9WeypY,2369
47
+ valkyrie/vault/__init__.py,sha256=-qEGSp-VFpdqkYHE4KL7fRhURTMX3oj_OFxM-7P-KKE,497
48
+ valkyrie/vault/crypto.py,sha256=F066Su5Z8HnddEBjwETXRQGO_J9F_yKeq8_HK7zRNIo,3466
49
+ valkyrie/vault/prompt.py,sha256=GOb1hULoy2YjgVGWXaR_8uXiLRXRsQeccuaSUcbFgiI,2146
50
+ valkyrie/vault/store.py,sha256=9BJGbnX6kyEXm6Fx87uX1N9xkQgtpAnTHIem_Q1T1bI,5514
51
+ valkyrie/vault/sync.py,sha256=ER6CRjN8f2DahGOotkWGynWlOO1ZgXdB7drQmh-Ljpg,3653
52
+ valkyria_cli-0.1.0.dist-info/METADATA,sha256=Cg2uUEpkepcLtRU_0aOCx1WG2igD2IHiOBCJJgj8CqM,7868
53
+ valkyria_cli-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
54
+ valkyria_cli-0.1.0.dist-info/entry_points.txt,sha256=kyMcuqBUO3uIpouKkUkBGwsCGbBPy5frjxhb8aSXf50,78
55
+ valkyria_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ valkyrie = valkyrie.cli.main:cli
3
+ vk = valkyrie.cli.main:cli
valkyrie/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Valkyrie CLI — Terminal-first, multi-model AI agent."""
2
+
3
+ __version__ = "0.1.0"
4
+ __app_name__ = "valkyrie"
5
+
@@ -0,0 +1,21 @@
1
+ """
2
+ Auth module — Firebase Google OAuth for Valkyrie CLI.
3
+
4
+ Provides login (browser handoff), logout, token storage, and refresh.
5
+ """
6
+
7
+ from valkyrie.auth.tokens import (
8
+ AuthUser,
9
+ clear_auth,
10
+ get_valid_user,
11
+ load_auth,
12
+ save_auth,
13
+ )
14
+
15
+ __all__ = [
16
+ "AuthUser",
17
+ "clear_auth",
18
+ "get_valid_user",
19
+ "load_auth",
20
+ "save_auth",
21
+ ]
@@ -0,0 +1,245 @@
1
+ """
2
+ Shared account lifecycle operations — login, switch, logout, status, and deletion.
3
+
4
+ Used by both the `valkyrie auth` CLI commands and the in-chat `/account` slash command.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import time
10
+ import webbrowser
11
+
12
+ import click
13
+
14
+ from valkyrie.auth.firebase_config import OAUTH_CALLBACK_HOST, OAUTH_CALLBACK_PORT
15
+ from valkyrie.auth.server import run_auth_server
16
+ from valkyrie.auth.tokens import (
17
+ AuthUser,
18
+ clear_auth,
19
+ delete_firebase_account,
20
+ get_valid_user,
21
+ load_auth,
22
+ save_auth,
23
+ )
24
+ from valkyrie.core.config import ValkyrieConfig
25
+ from valkyrie.core.console import (
26
+ console,
27
+ print_error,
28
+ print_info,
29
+ print_kv,
30
+ print_rule,
31
+ print_success,
32
+ print_warning,
33
+ )
34
+ from valkyrie.core.paths import get_vault_path
35
+ from valkyrie.vault.store import save_vault_blob, vault_exists
36
+ from valkyrie.vault.sync import delete_remote_vault, pull_vault
37
+
38
+
39
+ def _run_browser_oauth(*, select_account: bool = False) -> AuthUser | None:
40
+ """Open the browser OAuth flow, wait for callback, and persist tokens."""
41
+ login_url = f"http://{OAUTH_CALLBACK_HOST}:{OAUTH_CALLBACK_PORT}/"
42
+ print_info("Opening your browser for Google sign-in.")
43
+ print_info(f"If it doesn't open, visit: [accent]{login_url}[/accent]")
44
+ print_info("[dim]Waiting for authentication...[/dim]")
45
+ console.print()
46
+
47
+ webbrowser.open(login_url)
48
+ result = run_auth_server(timeout=300.0, select_account=select_account)
49
+ if result is None:
50
+ print_error("Authentication timed out or was cancelled.")
51
+ return None
52
+
53
+ user = AuthUser.from_oauth_callback(result)
54
+ save_auth(user)
55
+ return user
56
+
57
+
58
+ def login_account(*, select_account: bool = False) -> AuthUser | None:
59
+ """Sign in via browser OAuth if not already signed in."""
60
+ existing = get_valid_user()
61
+ if existing is not None:
62
+ console.print()
63
+ print_info(f"Already signed in as [bold]{existing.email}[/bold].")
64
+ print_info(
65
+ "Run [bold]/account switch[/bold] or [bold]valkyrie auth switch[/bold] "
66
+ "to change accounts."
67
+ )
68
+ console.print()
69
+ return existing
70
+
71
+ console.print()
72
+ print_rule("Sign In")
73
+ console.print()
74
+ user = _run_browser_oauth(select_account=select_account)
75
+ if user is None:
76
+ return None
77
+
78
+ print_success(f"Signed in as [bold]{user.email}[/bold]")
79
+ if user.display_name:
80
+ print_info(f"Welcome, {user.display_name}.")
81
+ console.print()
82
+ return user
83
+
84
+
85
+ def switch_account(*, interactive: bool = True) -> AuthUser | None:
86
+ """
87
+ Switch to a different Google account via Firebase OAuth account chooser.
88
+
89
+ Preserves the currently signed-in session if the browser flow is cancelled.
90
+ """
91
+ previous = load_auth()
92
+ console.print()
93
+ print_rule("Switch Account")
94
+ console.print()
95
+ if previous is not None:
96
+ print_info(f"Currently signed in as [bold]{previous.email}[/bold].")
97
+ else:
98
+ print_info("Not currently signed in — opening account selector.")
99
+
100
+ new_user = _run_browser_oauth(select_account=True)
101
+ if new_user is None:
102
+ if previous is not None:
103
+ print_info(f"Kept existing session ([bold]{previous.email}[/bold]).")
104
+ console.print()
105
+ return None
106
+
107
+ print_success(f"Switched account -> [bold]{new_user.email}[/bold]")
108
+ if new_user.display_name:
109
+ print_info(f"Signed in as {new_user.display_name} ([dim]{new_user.uid}[/dim]).")
110
+
111
+ remote_blob = pull_vault(new_user.id_token, new_user.uid)
112
+ if remote_blob is not None:
113
+ should_pull = True if not interactive else click.confirm(
114
+ f" Synced vault found for {new_user.email}. Replace local vault with synced vault?",
115
+ default=False,
116
+ )
117
+ if should_pull:
118
+ save_vault_blob(remote_blob)
119
+ cfg = ValkyrieConfig.load()
120
+ cfg.sync_enabled = True
121
+ cfg.save()
122
+ print_success("Pulled encrypted vault for switched account.")
123
+ else:
124
+ print_info("Kept current local vault.")
125
+ console.print()
126
+ return new_user
127
+
128
+
129
+ def logout_account() -> bool:
130
+ """Sign out locally and clear ~/.valkyrie/auth.json."""
131
+ user = load_auth()
132
+ if user is None:
133
+ console.print()
134
+ print_info("Not signed in.")
135
+ console.print()
136
+ return False
137
+
138
+ email = user.email
139
+ clear_auth()
140
+ console.print()
141
+ print_success(f"Signed out from [bold]{email}[/bold].")
142
+ print_info("Local credentials cleared.")
143
+ console.print()
144
+ return True
145
+
146
+
147
+ def delete_account(*, assume_yes: bool = False, purge_local: bool = False) -> bool:
148
+ """
149
+ Permanently delete the signed-in Firebase account and its remote Firestore vault.
150
+
151
+ Clears local auth credentials and optionally deletes the local encrypted vault.
152
+ """
153
+ user = get_valid_user()
154
+ if user is None:
155
+ stale = load_auth()
156
+ console.print()
157
+ if stale is not None:
158
+ print_error(
159
+ "Stored authentication token expired and could not be refreshed. "
160
+ "Run '/account switch' (or 'valkyrie auth switch') to re-authenticate first."
161
+ )
162
+ else:
163
+ print_info("Not signed in. No account to delete.")
164
+ console.print()
165
+ return False
166
+
167
+ console.print()
168
+ print_rule("Delete Account")
169
+ console.print()
170
+ print_warning(
171
+ f"This permanently deletes Firebase account [bold]{user.email}[/bold] "
172
+ f"([dim]{user.uid}[/dim]) and any synced remote vault."
173
+ )
174
+
175
+ if not assume_yes and not click.confirm(
176
+ f" Permanently delete account '{user.email}'?",
177
+ default=False,
178
+ ):
179
+ print_info("Account deletion cancelled.")
180
+ console.print()
181
+ return False
182
+
183
+ remote_ok = delete_remote_vault(user.id_token, user.uid)
184
+ if not remote_ok:
185
+ print_warning("Could not verify remote vault deletion (continuing with account removal).")
186
+
187
+ ok, detail = delete_firebase_account(user.id_token)
188
+ if not ok:
189
+ print_error(detail)
190
+ console.print()
191
+ return False
192
+
193
+ clear_auth()
194
+ cfg = ValkyrieConfig.load()
195
+ cfg.sync_enabled = False
196
+ cfg.save()
197
+
198
+ vault_path = get_vault_path()
199
+ should_purge = purge_local
200
+ if not should_purge and not assume_yes and vault_exists():
201
+ should_purge = click.confirm(
202
+ f" Also delete local encrypted key vault ({vault_path})?",
203
+ default=False,
204
+ )
205
+ if should_purge and vault_path.exists():
206
+ vault_path.unlink()
207
+ print_info("Local encrypted vault removed.")
208
+
209
+ print_success(f"Deleted account [bold]{user.email}[/bold] and cleared local credentials.")
210
+ console.print()
211
+ return True
212
+
213
+
214
+ def show_account_status() -> None:
215
+ """Display active signed-in account, token status, and vault sync state."""
216
+ user = load_auth()
217
+ cfg = ValkyrieConfig.load()
218
+
219
+ console.print()
220
+ print_rule("Authentication")
221
+ console.print()
222
+
223
+ if user is None:
224
+ print_kv("Status", "[yellow]not signed in[/yellow]")
225
+ print_kv("Sync", "disabled (local-only mode)")
226
+ print_info(
227
+ "Run [bold]/account login[/bold] or [bold]valkyrie auth login[/bold] to sign in."
228
+ )
229
+ else:
230
+ expired = user.is_expired
231
+ status_str = "[red]token expired[/red]" if expired else "[green]active[/green]"
232
+ print_kv("Status", status_str)
233
+ print_kv("Email", f"[bold]{user.email}[/bold]")
234
+ if user.display_name:
235
+ print_kv("Name", user.display_name)
236
+ print_kv("UID", f"[dim]{user.uid}[/dim]")
237
+ print_kv("Cloud sync", "enabled" if cfg.sync_enabled else "disabled")
238
+ if not expired:
239
+ remaining = int(user.expires_at - time.time())
240
+ minutes = remaining // 60
241
+ print_kv("Token", f"expires in {minutes} min")
242
+ else:
243
+ print_info("Token will refresh automatically on next use.")
244
+
245
+ console.print()
@@ -0,0 +1,28 @@
1
+ """
2
+ Firebase project configuration for Valkyrie CLI.
3
+
4
+ These are public-facing Firebase config values (safe to commit).
5
+ The Web API Key is NOT a secret — it identifies the Firebase project
6
+ for client-side auth calls, same as it would in a web app's HTML.
7
+ """
8
+
9
+ # ── Firebase project: valkyria CLI (filum-708c0) ───────────────────────────
10
+
11
+ FIREBASE_CONFIG = {
12
+ "apiKey": "AIzaSyD86AEgIKfPP_PXRS4q1BIKEpG77oFUUbg",
13
+ "authDomain": "filum-708c0.firebaseapp.com",
14
+ "projectId": "filum-708c0",
15
+ "storageBucket": "filum-708c0.firebasestorage.app",
16
+ "messagingSenderId": "496089235861",
17
+ "appId": "1:496089235861:web:f709d081fc867d9f3ab69c",
18
+ }
19
+
20
+ # Firebase Auth REST API (Identity Toolkit v1)
21
+ FIREBASE_AUTH_BASE = "https://identitytoolkit.googleapis.com/v1"
22
+ FIREBASE_TOKEN_BASE = "https://securetoken.googleapis.com/v1"
23
+
24
+ # Local OAuth callback server
25
+ OAUTH_CALLBACK_HOST = "127.0.0.1"
26
+ OAUTH_CALLBACK_PORT = 8085
27
+ OAUTH_CALLBACK_PATH = "/callback"
28
+
@@ -0,0 +1,177 @@
1
+ """
2
+ OAuth login page — served locally for Firebase Google sign-in.
3
+
4
+ This HTML page uses the Firebase JS SDK to trigger a Google popup sign-in,
5
+ then POSTs the resulting tokens back to the local callback server.
6
+ """
7
+
8
+ from valkyrie.auth.firebase_config import (
9
+ FIREBASE_CONFIG,
10
+ OAUTH_CALLBACK_HOST,
11
+ OAUTH_CALLBACK_PATH,
12
+ OAUTH_CALLBACK_PORT,
13
+ )
14
+
15
+
16
+ def get_login_page_html(*, select_account: bool = False) -> str:
17
+ """Return the HTML page that handles Google sign-in via Firebase JS SDK."""
18
+ callback_url = (
19
+ f"http://{OAUTH_CALLBACK_HOST}:{OAUTH_CALLBACK_PORT}{OAUTH_CALLBACK_PATH}"
20
+ )
21
+ subtitle_prompt = (
22
+ "Choose a Google account to switch your workspace"
23
+ if select_account
24
+ else "Sign in to connect your workspace"
25
+ )
26
+ button_label = "CHOOSE GOOGLE ACCOUNT" if select_account else "SIGN IN WITH GOOGLE"
27
+ custom_params_js = (
28
+ "provider.setCustomParameters({ prompt: 'select_account' });"
29
+ if select_account
30
+ else ""
31
+ )
32
+
33
+ return f"""<!DOCTYPE html>
34
+ <html lang="en">
35
+ <head>
36
+ <meta charset="utf-8">
37
+ <meta name="viewport" content="width=device-width, initial-scale=1">
38
+ <title>Valkyrie — Sign In</title>
39
+ <style>
40
+ * {{ margin: 0; padding: 0; box-sizing: border-box; }}
41
+ body {{
42
+ font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;
43
+ background: #0a0a0a;
44
+ color: #e0e0e0;
45
+ display: flex;
46
+ align-items: center;
47
+ justify-content: center;
48
+ min-height: 100vh;
49
+ }}
50
+ .container {{
51
+ text-align: center;
52
+ max-width: 420px;
53
+ padding: 48px 32px;
54
+ }}
55
+ .title {{
56
+ font-size: 28px;
57
+ font-weight: 700;
58
+ letter-spacing: 4px;
59
+ color: #fff;
60
+ margin-bottom: 8px;
61
+ }}
62
+ .subtitle {{
63
+ font-size: 13px;
64
+ color: #666;
65
+ margin-bottom: 48px;
66
+ }}
67
+ .status {{
68
+ font-size: 14px;
69
+ color: #888;
70
+ margin-bottom: 32px;
71
+ min-height: 24px;
72
+ }}
73
+ .status.error {{ color: #e55; }}
74
+ .status.success {{ color: #5e5; }}
75
+ button {{
76
+ font-family: inherit;
77
+ font-size: 14px;
78
+ font-weight: 600;
79
+ padding: 14px 32px;
80
+ border: 1px solid #333;
81
+ border-radius: 6px;
82
+ background: #111;
83
+ color: #fff;
84
+ cursor: pointer;
85
+ transition: all 0.15s ease;
86
+ letter-spacing: 1px;
87
+ }}
88
+ button:hover {{ background: #1a1a1a; border-color: #0ff; color: #0ff; }}
89
+ button:disabled {{ opacity: 0.4; cursor: not-allowed; }}
90
+ .footer {{
91
+ margin-top: 48px;
92
+ font-size: 11px;
93
+ color: #444;
94
+ }}
95
+ </style>
96
+ </head>
97
+ <body>
98
+ <div class="container">
99
+ <div class="title">VALKYRIE</div>
100
+ <div class="subtitle">Terminal-first AI workspace</div>
101
+ <div class="status" id="status">{subtitle_prompt}</div>
102
+ <button id="signin-btn" onclick="signIn()">{button_label}</button>
103
+ <div class="footer">
104
+ Authentication is handled by Firebase.<br>No passwords are stored locally.
105
+ </div>
106
+ </div>
107
+
108
+ <script type="module">
109
+ import {{ initializeApp }} from 'https://www.gstatic.com/firebasejs/11.8.1/firebase-app.js';
110
+ import {{ getAuth, signInWithPopup, GoogleAuthProvider }} from 'https://www.gstatic.com/firebasejs/11.8.1/firebase-auth.js';
111
+
112
+ const firebaseConfig = {{
113
+ apiKey: "{FIREBASE_CONFIG['apiKey']}",
114
+ authDomain: "{FIREBASE_CONFIG['authDomain']}",
115
+ projectId: "{FIREBASE_CONFIG['projectId']}",
116
+ storageBucket: "{FIREBASE_CONFIG['storageBucket']}",
117
+ messagingSenderId: "{FIREBASE_CONFIG['messagingSenderId']}",
118
+ appId: "{FIREBASE_CONFIG['appId']}"
119
+ }};
120
+
121
+ const app = initializeApp(firebaseConfig);
122
+ const auth = getAuth(app);
123
+ const provider = new GoogleAuthProvider();
124
+ {custom_params_js}
125
+
126
+ window.signIn = async function() {{
127
+ const btn = document.getElementById('signin-btn');
128
+ const status = document.getElementById('status');
129
+
130
+ btn.disabled = true;
131
+ status.className = 'status';
132
+ status.textContent = 'Opening Google sign-in...';
133
+
134
+ try {{
135
+ const result = await signInWithPopup(auth, provider);
136
+ const user = result.user;
137
+ const idToken = await user.getIdToken();
138
+
139
+ status.className = 'status success';
140
+ status.textContent = 'Authenticated. Sending credentials to CLI...';
141
+
142
+ const response = await fetch("{callback_url}", {{
143
+ method: "POST",
144
+ headers: {{ "Content-Type": "application/json" }},
145
+ body: JSON.stringify({{
146
+ idToken: idToken,
147
+ refreshToken: user.refreshToken,
148
+ uid: user.uid,
149
+ email: user.email,
150
+ displayName: user.displayName,
151
+ photoURL: user.photoURL,
152
+ }})
153
+ }});
154
+
155
+ if (response.ok) {{
156
+ status.textContent = 'Signed in as ' + user.email + '. You can close this tab.';
157
+ btn.style.display = 'none';
158
+ setTimeout(() => window.close(), 2000);
159
+ }} else {{
160
+ throw new Error('CLI callback failed');
161
+ }}
162
+ }} catch (error) {{
163
+ status.className = 'status error';
164
+ if (error.code === 'auth/popup-closed-by-user') {{
165
+ status.textContent = 'Sign-in cancelled. Try again.';
166
+ }} else if (error.code === 'auth/popup-blocked') {{
167
+ status.textContent = 'Popup blocked. Please allow popups and try again.';
168
+ }} else {{
169
+ status.textContent = 'Error: ' + (error.message || error.code || 'unknown');
170
+ }}
171
+ btn.disabled = false;
172
+ }}
173
+ }};
174
+ </script>
175
+ </body>
176
+ </html>"""
177
+