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,247 @@
1
+ """
2
+ Session CLI commands — list, create, inspect, rename, fork, search, compact, delete.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import click
8
+ from rich.table import Table
9
+
10
+ from valkyrie.chat.engine import build_system_prompt
11
+ from valkyrie.chat.messages import ChatMessage, MessageRole
12
+ from valkyrie.core.config import ValkyrieConfig
13
+ from valkyrie.core.console import (
14
+ console,
15
+ print_error,
16
+ print_info,
17
+ print_kv,
18
+ print_rule,
19
+ print_success,
20
+ print_warning,
21
+ )
22
+ from valkyrie.core.workspace import detect_workspace_root
23
+ from valkyrie.sessions.store import SessionStore
24
+
25
+
26
+ def _build_extractive_summary(messages: list[ChatMessage], keep_last: int) -> str:
27
+ """Create a deterministic local summary of older turns when no LLM is invoked."""
28
+ non_system = [m for m in messages if m.role != MessageRole.SYSTEM]
29
+ older = non_system[:-keep_last] if keep_last > 0 else non_system
30
+ bullets: list[str] = []
31
+ for msg in older:
32
+ snippet = " ".join(msg.content.split())
33
+ if len(snippet) > 120:
34
+ snippet = snippet[:117] + "..."
35
+ bullets.append(f"- {msg.role.value}: {snippet}")
36
+ return "\n".join(bullets)
37
+
38
+
39
+ @click.group()
40
+ def session() -> None:
41
+ """Manage durable conversation sessions."""
42
+ pass
43
+
44
+
45
+ @session.command(name="list")
46
+ @click.option("--all", "show_all", is_flag=True, help="List sessions across all workspaces.")
47
+ def list_cmd(show_all: bool) -> None:
48
+ """List saved sessions."""
49
+ store = SessionStore()
50
+ ws = None if show_all else str(detect_workspace_root())
51
+ sessions = store.list_sessions(workspace_root=ws)
52
+
53
+ console.print()
54
+ print_rule("Sessions")
55
+ console.print()
56
+
57
+ if not sessions:
58
+ print_info("No sessions found. Start one with [bold]valkyrie chat[/bold].")
59
+ console.print()
60
+ return
61
+
62
+ table = Table(border_style="rule", header_style="bold white", pad_edge=False)
63
+ table.add_column("ID", style="accent", no_wrap=True)
64
+ table.add_column("Title", style="body")
65
+ table.add_column("Model", style="model")
66
+ table.add_column("Msgs", justify="right", style="dim")
67
+ table.add_column("Updated", style="dim", no_wrap=True)
68
+
69
+ for s in sessions:
70
+ table.add_row(
71
+ s.id,
72
+ s.title[:40],
73
+ s.active_model,
74
+ str(s.message_count),
75
+ s.updated_at[:16].replace("T", " "),
76
+ )
77
+
78
+ console.print(table)
79
+ console.print()
80
+
81
+
82
+ @session.command()
83
+ @click.option("--title", default=None, help="Optional session title.")
84
+ @click.option("--model", "model_id", default=None, help="Override chat model for this session.")
85
+ def new(title: str | None, model_id: str | None) -> None:
86
+ """Create a new persistent session."""
87
+ config = ValkyrieConfig.load()
88
+ selected = model_id or config.models.chat or "unassigned"
89
+ store = SessionStore()
90
+ sys_msg = ChatMessage(role=MessageRole.SYSTEM, content=build_system_prompt(config))
91
+ created = store.create_session(
92
+ active_model=selected,
93
+ workspace_root=str(detect_workspace_root()),
94
+ title=title,
95
+ initial_messages=[sys_msg],
96
+ )
97
+
98
+ console.print()
99
+ print_success(f"Created session [bold]{created.title}[/bold] ([dim]{created.id}[/dim])")
100
+ print_info(f"Resume with: [bold]valkyrie chat --session {created.id}[/bold]")
101
+ console.print()
102
+
103
+
104
+ @session.command()
105
+ @click.argument("session_id")
106
+ def show(session_id: str) -> None:
107
+ """Show metadata and recent messages for a session."""
108
+ store = SessionStore()
109
+ sess = store.get_session(session_id)
110
+
111
+ console.print()
112
+ if sess is None:
113
+ print_error(f"Session '{session_id}' not found.")
114
+ console.print()
115
+ raise SystemExit(1)
116
+
117
+ print_rule(f"Session · {sess.id}")
118
+ console.print()
119
+ print_kv("Title", sess.title)
120
+ print_kv("Workspace", sess.workspace_root)
121
+ print_kv("Model", f"[model]{sess.active_model}[/model]")
122
+ print_kv("Messages", str(sess.message_count))
123
+ print_kv(
124
+ "Tokens",
125
+ f"{sess.total_prompt_tokens:,} in · {sess.total_completion_tokens:,} out",
126
+ )
127
+ if sess.last_checkpoint_id:
128
+ print_kv("Checkpoint", sess.last_checkpoint_id)
129
+ console.print()
130
+
131
+ msgs = [m for m in store.load_messages(sess.id) if m.role != MessageRole.SYSTEM]
132
+ for msg in msgs[-10:]:
133
+ snippet = msg.content if len(msg.content) <= 200 else msg.content[:197] + "..."
134
+ console.print(f" [accent]{msg.role.value:<10}[/accent] {snippet}")
135
+ if msgs:
136
+ console.print()
137
+
138
+
139
+ @session.command()
140
+ @click.argument("session_id")
141
+ @click.argument("title")
142
+ def rename(session_id: str, title: str) -> None:
143
+ """Rename a saved session."""
144
+ store = SessionStore()
145
+ console.print()
146
+ if store.rename_session(session_id, title):
147
+ print_success(f"Renamed session to [bold]{title}[/bold].")
148
+ else:
149
+ print_error(f"Session '{session_id}' not found.")
150
+ console.print()
151
+ raise SystemExit(1)
152
+ console.print()
153
+
154
+
155
+ @session.command()
156
+ @click.argument("session_id")
157
+ @click.option("--title", default=None, help="Title for the forked session.")
158
+ def fork(session_id: str, title: str | None) -> None:
159
+ """Fork an existing session into a new branch."""
160
+ store = SessionStore()
161
+ forked = store.fork_session(session_id, title=title)
162
+ console.print()
163
+ if forked is None:
164
+ print_error(f"Session '{session_id}' not found.")
165
+ console.print()
166
+ raise SystemExit(1)
167
+ print_success(f"Forked into [bold]{forked.title}[/bold] ([dim]{forked.id}[/dim])")
168
+ console.print()
169
+
170
+
171
+ @session.command()
172
+ @click.argument("query")
173
+ def search(query: str) -> None:
174
+ """Search sessions by title or message content."""
175
+ store = SessionStore()
176
+ matches = store.search_sessions(query)
177
+ console.print()
178
+ print_rule(f"Search · {query}")
179
+ console.print()
180
+
181
+ if not matches:
182
+ print_info("No matching sessions found.")
183
+ console.print()
184
+ return
185
+
186
+ for s in matches:
187
+ console.print(
188
+ f" [accent]{s.id}[/accent] [bold]{s.title}[/bold] "
189
+ f"[dim]({s.message_count} msgs · {s.active_model})[/dim]"
190
+ )
191
+ console.print()
192
+
193
+
194
+ @session.command()
195
+ @click.argument("session_id")
196
+ @click.option(
197
+ "--keep",
198
+ default=4,
199
+ show_default=True,
200
+ help="Number of recent messages to keep verbatim.",
201
+ )
202
+ def compact(session_id: str, keep: int) -> None:
203
+ """Compact older messages in a session into a summary."""
204
+ store = SessionStore()
205
+ sess = store.get_session(session_id)
206
+ console.print()
207
+ if sess is None:
208
+ print_error(f"Session '{session_id}' not found.")
209
+ console.print()
210
+ raise SystemExit(1)
211
+
212
+ messages = store.load_messages(sess.id)
213
+ summary = _build_extractive_summary(messages, keep)
214
+ ok, before_cnt, after_cnt = store.compact_session(sess.id, summary, keep_last=keep)
215
+
216
+ if ok:
217
+ print_success(
218
+ f"Compacted session [dim]{sess.id}[/dim]: {before_cnt} -> {after_cnt} messages."
219
+ )
220
+ else:
221
+ print_warning("Session has too few messages to compact.")
222
+ console.print()
223
+
224
+
225
+ @session.command()
226
+ @click.argument("session_id")
227
+ @click.option("--yes", is_flag=True, help="Skip confirmation prompt.")
228
+ def delete(session_id: str, yes: bool) -> None:
229
+ """Delete a saved session."""
230
+ store = SessionStore()
231
+ sess = store.get_session(session_id)
232
+ console.print()
233
+ if sess is None:
234
+ print_error(f"Session '{session_id}' not found.")
235
+ console.print()
236
+ raise SystemExit(1)
237
+
238
+ if not yes and not click.confirm(
239
+ f" Delete session '{sess.title}' ({sess.id})?", default=False
240
+ ):
241
+ print_info("Cancelled.")
242
+ console.print()
243
+ return
244
+
245
+ store.delete_session(sess.id)
246
+ print_success(f"Deleted session [dim]{sess.id}[/dim].")
247
+ console.print()