spooling 0.2.15__tar.gz → 0.2.17__tar.gz

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 (82) hide show
  1. {spooling-0.2.15/spooling.egg-info → spooling-0.2.17}/PKG-INFO +47 -7
  2. {spooling-0.2.15 → spooling-0.2.17}/README.md +46 -6
  3. {spooling-0.2.15 → spooling-0.2.17}/pyproject.toml +1 -1
  4. {spooling-0.2.15 → spooling-0.2.17}/spooling/cli.py +163 -3
  5. {spooling-0.2.15 → spooling-0.2.17}/spooling/cloud.py +14 -6
  6. {spooling-0.2.15 → spooling-0.2.17}/spooling/db.py +16 -0
  7. spooling-0.2.17/spooling/device_login.py +88 -0
  8. {spooling-0.2.15 → spooling-0.2.17}/spooling/ingest.py +7 -4
  9. {spooling-0.2.15 → spooling-0.2.17}/spooling/parser.py +12 -0
  10. {spooling-0.2.15 → spooling-0.2.17}/spooling/schema.py +3 -1
  11. spooling-0.2.17/spooling/summarize.py +365 -0
  12. {spooling-0.2.15 → spooling-0.2.17/spooling.egg-info}/PKG-INFO +47 -7
  13. {spooling-0.2.15 → spooling-0.2.17}/spooling.egg-info/SOURCES.txt +4 -0
  14. spooling-0.2.17/tests/test_device_login.py +155 -0
  15. {spooling-0.2.15 → spooling-0.2.17}/tests/test_docs.py +11 -0
  16. spooling-0.2.17/tests/test_summarize.py +470 -0
  17. {spooling-0.2.15 → spooling-0.2.17}/LICENSE +0 -0
  18. {spooling-0.2.15 → spooling-0.2.17}/setup.cfg +0 -0
  19. {spooling-0.2.15 → spooling-0.2.17}/spooling/__init__.py +0 -0
  20. {spooling-0.2.15 → spooling-0.2.17}/spooling/agent.py +0 -0
  21. {spooling-0.2.15 → spooling-0.2.17}/spooling/classifiers.py +0 -0
  22. {spooling-0.2.15 → spooling-0.2.17}/spooling/config.py +0 -0
  23. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/__init__.py +0 -0
  24. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/base.py +0 -0
  25. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/bigquery.py +0 -0
  26. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/clickhouse.py +0 -0
  27. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/factory.py +0 -0
  28. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/mongodb.py +0 -0
  29. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/mysql.py +0 -0
  30. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/postgresql.py +0 -0
  31. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/rest/__init__.py +0 -0
  32. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/rest/base.py +0 -0
  33. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/rest/shopify_connectors.py +0 -0
  34. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/snowflake.py +0 -0
  35. {spooling-0.2.15 → spooling-0.2.17}/spooling/connectors/types.py +0 -0
  36. {spooling-0.2.15 → spooling-0.2.17}/spooling/embeddings.py +0 -0
  37. {spooling-0.2.15 → spooling-0.2.17}/spooling/evals.py +0 -0
  38. {spooling-0.2.15 → spooling-0.2.17}/spooling/experiments.py +0 -0
  39. {spooling-0.2.15 → spooling-0.2.17}/spooling/insights.py +0 -0
  40. {spooling-0.2.15 → spooling-0.2.17}/spooling/mcp_server.py +0 -0
  41. {spooling-0.2.15 → spooling-0.2.17}/spooling/optimize.py +0 -0
  42. {spooling-0.2.15 → spooling-0.2.17}/spooling/pricing.py +0 -0
  43. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/__init__.py +0 -0
  44. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/antigravity.py +0 -0
  45. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/base.py +0 -0
  46. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/claude_code.py +0 -0
  47. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/codex.py +0 -0
  48. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/copilot.py +0 -0
  49. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/cortex_code.py +0 -0
  50. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/cursor.py +0 -0
  51. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/gemini.py +0 -0
  52. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/github.py +0 -0
  53. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/gitlab.py +0 -0
  54. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/kiro.py +0 -0
  55. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/opencode.py +0 -0
  56. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/session_file.py +0 -0
  57. {spooling-0.2.15 → spooling-0.2.17}/spooling/providers/windsurf.py +0 -0
  58. {spooling-0.2.15 → spooling-0.2.17}/spooling/redact.py +0 -0
  59. {spooling-0.2.15 → spooling-0.2.17}/spooling/remote_otel.py +0 -0
  60. {spooling-0.2.15 → spooling-0.2.17}/spooling/sdk.py +0 -0
  61. {spooling-0.2.15 → spooling-0.2.17}/spooling/search.py +0 -0
  62. {spooling-0.2.15 → spooling-0.2.17}/spooling/server.py +0 -0
  63. {spooling-0.2.15 → spooling-0.2.17}/spooling/sessions.py +0 -0
  64. {spooling-0.2.15 → spooling-0.2.17}/spooling/stats.py +0 -0
  65. {spooling-0.2.15 → spooling-0.2.17}/spooling/subscription_pricing.py +0 -0
  66. {spooling-0.2.15 → spooling-0.2.17}/spooling/tracing.py +0 -0
  67. {spooling-0.2.15 → spooling-0.2.17}/spooling/tunnel.py +0 -0
  68. {spooling-0.2.15 → spooling-0.2.17}/spooling/tunnel_auth.py +0 -0
  69. {spooling-0.2.15 → spooling-0.2.17}/spooling/watcher.py +0 -0
  70. {spooling-0.2.15 → spooling-0.2.17}/spooling.egg-info/dependency_links.txt +0 -0
  71. {spooling-0.2.15 → spooling-0.2.17}/spooling.egg-info/entry_points.txt +0 -0
  72. {spooling-0.2.15 → spooling-0.2.17}/spooling.egg-info/requires.txt +0 -0
  73. {spooling-0.2.15 → spooling-0.2.17}/spooling.egg-info/top_level.txt +0 -0
  74. {spooling-0.2.15 → spooling-0.2.17}/tests/test_agent_spans.py +0 -0
  75. {spooling-0.2.15 → spooling-0.2.17}/tests/test_claude_code_provider.py +0 -0
  76. {spooling-0.2.15 → spooling-0.2.17}/tests/test_cloud_errors.py +0 -0
  77. {spooling-0.2.15 → spooling-0.2.17}/tests/test_cloud_teams.py +0 -0
  78. {spooling-0.2.15 → spooling-0.2.17}/tests/test_insights.py +0 -0
  79. {spooling-0.2.15 → spooling-0.2.17}/tests/test_mcp_auth_middleware.py +0 -0
  80. {spooling-0.2.15 → spooling-0.2.17}/tests/test_session_ids.py +0 -0
  81. {spooling-0.2.15 → spooling-0.2.17}/tests/test_storage_optimizations.py +0 -0
  82. {spooling-0.2.15 → spooling-0.2.17}/tests/test_tunnel_auth.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spooling
3
- Version: 0.2.15
3
+ Version: 0.2.17
4
4
  Summary: Local session tracker and semantic search for AI coding assistants
5
5
  Author: Parsed Analytics, Inc.
6
6
  License: MIT
@@ -224,10 +224,47 @@ spooling session list --project myproject --cwd ~/code
224
224
  spooling session show ses_e6310bd1 # summary: model, tokens, cost, tools used
225
225
  spooling session show ses_e6310bd1 -m # plus the full conversation text
226
226
  spooling session show ses_e6310bd1 -m --max-chars 300 # truncate each message
227
+ spooling session list --summaries # show each session's summary instead of its title
227
228
  ```
228
229
 
229
230
  `spooling session <id> -m` is shorthand for `spooling session show <id> -m`. `session show` accepts a full session id or any unique prefix. If a prefix matches several sessions, it lists them and exits so you can pick one.
230
231
 
232
+ ### `spooling summarize`
233
+
234
+ Write a short summary for sessions that don't have one. Summaries show up in `session show`, `session list --summaries`, and the MCP `get_session` tool. They are local-only; `spooling push` does not send them.
235
+
236
+ Some providers already supply a summary (Claude Code writes `summary` records). Those are used as-is and never overwritten unless you pass `--force`. For everything else, `summarize` calls a model you choose. Transcripts are secret-redacted before they are sent.
237
+
238
+ | Backend | Use it for | Credentials |
239
+ | --- | --- | --- |
240
+ | `openai` (default) | Any OpenAI-compatible endpoint: local [Ollama](https://ollama.com), OpenAI, OpenRouter, vLLM, LiteLLM | none for local; `SPOOLING_SUMMARY_API_KEY` for hosted |
241
+ | `anthropic` | The Anthropic API | `ANTHROPIC_API_KEY` |
242
+ | `bedrock` | AWS Bedrock (Converse API). Uses `boto3`, which Spooling already installs | `AWS_BEARER_TOKEN_BEDROCK` (Bedrock API key; needs a recent `boto3`) or any normal AWS credentials, plus `AWS_REGION` |
243
+
244
+ The default is a local Ollama daemon, so nothing leaves your machine. Any other backend sends redacted transcripts to a third party, so Spooling asks for confirmation first (skip with `--yes`).
245
+
246
+ ```bash
247
+ spooling summarize --dry-run # see what would be summarized; calls no model
248
+ spooling summarize -n 10 --days 7 # the 10 newest sessions from the last week
249
+ spooling summarize ses_e6310bd1 --force # (re)summarize one session
250
+
251
+ spooling summarize --base-url https://api.openai.com/v1 --model gpt-4o-mini
252
+ spooling summarize --backend anthropic # defaults to claude-haiku-4-5
253
+ spooling summarize --backend bedrock --region us-east-2 \
254
+ --model us.anthropic.claude-haiku-4-5-20251001-v1:0
255
+ ```
256
+
257
+ - `-p, --project`, `--provider`, `-d, --days`, `-n, --limit` - choose which sessions
258
+ - `--min-messages` - skip very short sessions (default 4)
259
+ - `--backend` - `openai`, `anthropic` or `bedrock` (or set `SPOOLING_SUMMARY_BACKEND`)
260
+ - `--model` - model name or id (or set `SPOOLING_SUMMARY_MODEL`). Defaults to `qwen2.5:7b` for `openai` and `claude-haiku-4-5` for `anthropic`; `bedrock` requires one, because Bedrock ids differ by region and account (use an inference profile id such as `us.anthropic.claude-haiku-4-5-20251001-v1:0`)
261
+ - `--base-url` - endpoint for the `openai` backend (or `SPOOLING_SUMMARY_BASE_URL`; default `http://localhost:11434/v1`)
262
+ - `--region` - AWS region for `bedrock` (default `AWS_REGION`)
263
+ - `--force` - regenerate even if a summary exists
264
+ - `-y, --yes` - don't ask before sending text to a non-local endpoint
265
+
266
+ The run stops early on errors that would repeat for every session (bad credentials, an unreachable server, an unknown model). A summary Spooling generated is refreshed on the next run once the session has grown; `session show` tells you when that is the case.
267
+
231
268
  ### `spooling optimize`
232
269
 
233
270
  Compact the local database. Removes duplicated tool-call rows left by older versions (before 0.2.6), truncates oversized previews, embeds any messages missing from search, and runs `VACUUM`. A backup is written next to the database first, and it is safe to re-run. `spooling sync` prints a hint when it finds duplicates.
@@ -390,16 +427,19 @@ the CLI ships with a `spooling cloud` subcommand.
390
427
 
391
428
  ### One-time setup
392
429
 
393
- 1. Mint an API key in the GUI at `app.spooling.ai/settings/api-keys`
394
- (looks like `sk_live_...`).
395
- 2. Save it locally:
430
+ 1. Sign in from the terminal:
396
431
 
397
432
  ```bash
398
- spooling cloud login --key sk_live_...
433
+ spooling login
399
434
  ```
400
435
 
401
- The key is stored at `~/.config/spooling/cloud.json` with `0600` perms.
402
- You can override the API base with `--api-url` or the
436
+ This opens your browser with a short code (for example `BCDF-GHJK`). Check the code, pick the workspace the
437
+ sessions should go to, and click Approve. The API key is generated on your machine and only its hash is sent to
438
+ Spooling, so there is nothing to copy and paste. It is stored at `~/.config/spooling/cloud.json` with `0600`
439
+ perms. Use `--no-browser` to just print the link (SSH sessions, containers).
440
+
441
+ Prefer to manage keys yourself? Mint one at `app.spooling.ai/settings` and run
442
+ `spooling cloud login --key sk_live_...`. You can override the API base with `--api-url` or the
403
443
  `SPOOLING_CLOUD_URL` env var (default: `https://api.spooling.ai`).
404
444
 
405
445
  ### Push once
@@ -188,10 +188,47 @@ spooling session list --project myproject --cwd ~/code
188
188
  spooling session show ses_e6310bd1 # summary: model, tokens, cost, tools used
189
189
  spooling session show ses_e6310bd1 -m # plus the full conversation text
190
190
  spooling session show ses_e6310bd1 -m --max-chars 300 # truncate each message
191
+ spooling session list --summaries # show each session's summary instead of its title
191
192
  ```
192
193
 
193
194
  `spooling session <id> -m` is shorthand for `spooling session show <id> -m`. `session show` accepts a full session id or any unique prefix. If a prefix matches several sessions, it lists them and exits so you can pick one.
194
195
 
196
+ ### `spooling summarize`
197
+
198
+ Write a short summary for sessions that don't have one. Summaries show up in `session show`, `session list --summaries`, and the MCP `get_session` tool. They are local-only; `spooling push` does not send them.
199
+
200
+ Some providers already supply a summary (Claude Code writes `summary` records). Those are used as-is and never overwritten unless you pass `--force`. For everything else, `summarize` calls a model you choose. Transcripts are secret-redacted before they are sent.
201
+
202
+ | Backend | Use it for | Credentials |
203
+ | --- | --- | --- |
204
+ | `openai` (default) | Any OpenAI-compatible endpoint: local [Ollama](https://ollama.com), OpenAI, OpenRouter, vLLM, LiteLLM | none for local; `SPOOLING_SUMMARY_API_KEY` for hosted |
205
+ | `anthropic` | The Anthropic API | `ANTHROPIC_API_KEY` |
206
+ | `bedrock` | AWS Bedrock (Converse API). Uses `boto3`, which Spooling already installs | `AWS_BEARER_TOKEN_BEDROCK` (Bedrock API key; needs a recent `boto3`) or any normal AWS credentials, plus `AWS_REGION` |
207
+
208
+ The default is a local Ollama daemon, so nothing leaves your machine. Any other backend sends redacted transcripts to a third party, so Spooling asks for confirmation first (skip with `--yes`).
209
+
210
+ ```bash
211
+ spooling summarize --dry-run # see what would be summarized; calls no model
212
+ spooling summarize -n 10 --days 7 # the 10 newest sessions from the last week
213
+ spooling summarize ses_e6310bd1 --force # (re)summarize one session
214
+
215
+ spooling summarize --base-url https://api.openai.com/v1 --model gpt-4o-mini
216
+ spooling summarize --backend anthropic # defaults to claude-haiku-4-5
217
+ spooling summarize --backend bedrock --region us-east-2 \
218
+ --model us.anthropic.claude-haiku-4-5-20251001-v1:0
219
+ ```
220
+
221
+ - `-p, --project`, `--provider`, `-d, --days`, `-n, --limit` - choose which sessions
222
+ - `--min-messages` - skip very short sessions (default 4)
223
+ - `--backend` - `openai`, `anthropic` or `bedrock` (or set `SPOOLING_SUMMARY_BACKEND`)
224
+ - `--model` - model name or id (or set `SPOOLING_SUMMARY_MODEL`). Defaults to `qwen2.5:7b` for `openai` and `claude-haiku-4-5` for `anthropic`; `bedrock` requires one, because Bedrock ids differ by region and account (use an inference profile id such as `us.anthropic.claude-haiku-4-5-20251001-v1:0`)
225
+ - `--base-url` - endpoint for the `openai` backend (or `SPOOLING_SUMMARY_BASE_URL`; default `http://localhost:11434/v1`)
226
+ - `--region` - AWS region for `bedrock` (default `AWS_REGION`)
227
+ - `--force` - regenerate even if a summary exists
228
+ - `-y, --yes` - don't ask before sending text to a non-local endpoint
229
+
230
+ The run stops early on errors that would repeat for every session (bad credentials, an unreachable server, an unknown model). A summary Spooling generated is refreshed on the next run once the session has grown; `session show` tells you when that is the case.
231
+
195
232
  ### `spooling optimize`
196
233
 
197
234
  Compact the local database. Removes duplicated tool-call rows left by older versions (before 0.2.6), truncates oversized previews, embeds any messages missing from search, and runs `VACUUM`. A backup is written next to the database first, and it is safe to re-run. `spooling sync` prints a hint when it finds duplicates.
@@ -354,16 +391,19 @@ the CLI ships with a `spooling cloud` subcommand.
354
391
 
355
392
  ### One-time setup
356
393
 
357
- 1. Mint an API key in the GUI at `app.spooling.ai/settings/api-keys`
358
- (looks like `sk_live_...`).
359
- 2. Save it locally:
394
+ 1. Sign in from the terminal:
360
395
 
361
396
  ```bash
362
- spooling cloud login --key sk_live_...
397
+ spooling login
363
398
  ```
364
399
 
365
- The key is stored at `~/.config/spooling/cloud.json` with `0600` perms.
366
- You can override the API base with `--api-url` or the
400
+ This opens your browser with a short code (for example `BCDF-GHJK`). Check the code, pick the workspace the
401
+ sessions should go to, and click Approve. The API key is generated on your machine and only its hash is sent to
402
+ Spooling, so there is nothing to copy and paste. It is stored at `~/.config/spooling/cloud.json` with `0600`
403
+ perms. Use `--no-browser` to just print the link (SSH sessions, containers).
404
+
405
+ Prefer to manage keys yourself? Mint one at `app.spooling.ai/settings` and run
406
+ `spooling cloud login --key sk_live_...`. You can override the API base with `--api-url` or the
367
407
  `SPOOLING_CLOUD_URL` env var (default: `https://api.spooling.ai`).
368
408
 
369
409
  ### Push once
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "spooling"
3
- version = "0.2.15"
3
+ version = "0.2.17"
4
4
  description = "Local session tracker and semantic search for AI coding assistants"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Parsed Analytics, Inc." }]
@@ -107,6 +107,16 @@ def watch():
107
107
  do_watch()
108
108
 
109
109
 
110
+ @cli.command("login")
111
+ @click.option("--no-browser", is_flag=True, help="Print the approval link instead of opening it")
112
+ @click.option("--api-url", default=None, help="Override the Spooling Cloud API base")
113
+ @click.pass_context
114
+ def login(ctx, no_browser, api_url):
115
+ """Sign in to Spooling Cloud through your browser (shortcut for `spooling cloud login`)."""
116
+ from spooling.cloud import cloud_login
117
+ ctx.invoke(cloud_login, key=None, api_url=api_url, no_browser=no_browser)
118
+
119
+
110
120
  @cli.command()
111
121
  @click.argument("query")
112
122
  @click.option("-n", "--limit", default=10, help="Number of results")
@@ -1165,8 +1175,9 @@ def session():
1165
1175
  @click.option("--cwd", default=None, help="Filter by cwd substring")
1166
1176
  @click.option("--title", default=None, help="Filter by title substring")
1167
1177
  @click.option("--id", "id_part", default=None, help="Filter by session id substring")
1178
+ @click.option("--summaries", "-s", is_flag=True, help="Show each session's summary instead of its title (falls back to the title)")
1168
1179
  @click.option("--limit", "-n", default=20, help="Max sessions to return (default: 20)")
1169
- def session_list(project, cwd, title, id_part, limit):
1180
+ def session_list(project, cwd, title, id_part, limit, summaries):
1170
1181
  """List local sessions with optional filters."""
1171
1182
  from spooling.db import get_connection
1172
1183
  from datetime import datetime as _dt
@@ -1191,6 +1202,7 @@ def session_list(project, cwd, title, id_part, limit):
1191
1202
 
1192
1203
  rows = conn.execute(
1193
1204
  f"""SELECT id, provider_id, project, title, started_at,
1205
+ summary,
1194
1206
  message_count, tool_call_count, estimated_cost_usd
1195
1207
  FROM sessions {where_clause}
1196
1208
  ORDER BY started_at DESC NULLS LAST LIMIT ?""",
@@ -1206,7 +1218,7 @@ def session_list(project, cwd, title, id_part, limit):
1206
1218
  table.add_column("Session ID", style="cyan", no_wrap=True)
1207
1219
  table.add_column("Provider")
1208
1220
  table.add_column("Project")
1209
- table.add_column("Title")
1221
+ table.add_column("Summary" if summaries else "Title")
1210
1222
  table.add_column("Started", style="dim")
1211
1223
  table.add_column("Msgs", justify="right")
1212
1224
  table.add_column("Tools", justify="right")
@@ -1224,7 +1236,7 @@ def session_list(project, cwd, title, id_part, limit):
1224
1236
  r["id"] or "",
1225
1237
  r["provider_id"] or "",
1226
1238
  _clean_project(r["project"] or ""),
1227
- (r["title"] or "")[:45],
1239
+ ((r["summary"] or r["title"] or "")[:90] if summaries else (r["title"] or "")[:45]),
1228
1240
  ts,
1229
1241
  str(r["message_count"] or 0),
1230
1242
  str(r["tool_call_count"] or 0),
@@ -1277,6 +1289,18 @@ def session_show(session_id, messages, max_chars):
1277
1289
  style="blue",
1278
1290
  ))
1279
1291
 
1292
+ if s.get("summary"):
1293
+ console.print("[bold]Summary[/bold]")
1294
+ console.print(s["summary"], markup=False, highlight=False)
1295
+ generated_at = s.get("summary_message_count")
1296
+ if generated_at is not None and (s.get("message_count") or 0) > generated_at:
1297
+ console.print(
1298
+ f"(session has grown since this was written; refresh with "
1299
+ f"'spooling summarize {s['id']}')",
1300
+ style="dim", markup=False, highlight=False,
1301
+ )
1302
+ console.print()
1303
+
1280
1304
  if detail["tool_summary"]:
1281
1305
  table = Table(title="Tool Usage", show_lines=False)
1282
1306
  table.add_column("Tool", style="magenta")
@@ -1301,6 +1325,142 @@ def session_show(session_id, messages, max_chars):
1301
1325
  console.print(f"[dim]{len(detail['messages'])} messages — pass --messages to print the session text[/dim]")
1302
1326
 
1303
1327
 
1328
+ # ---------------------------------------------------------------------------
1329
+ # Summaries
1330
+ # ---------------------------------------------------------------------------
1331
+
1332
+ @cli.command()
1333
+ @click.argument("session_ids", nargs=-1)
1334
+ @click.option("--project", "-p", default=None, help="Only sessions in this exact project")
1335
+ @click.option("--provider", default=None, help="Only sessions from this provider id")
1336
+ @click.option("--days", "-d", default=None, type=int, help="Only sessions started in the last N days")
1337
+ @click.option("--limit", "-n", default=20, show_default=True, help="Max sessions to summarize")
1338
+ @click.option("--min-messages", default=4, show_default=True,
1339
+ help="Skip sessions shorter than this (ignored when ids are given)")
1340
+ @click.option("--backend", type=click.Choice(["openai", "anthropic", "bedrock"]), default=None,
1341
+ help="LLM backend (default: $SPOOLING_SUMMARY_BACKEND or openai = any OpenAI-compatible endpoint, e.g. local Ollama)")
1342
+ @click.option("--model", default=None, help="Model name or id (default: $SPOOLING_SUMMARY_MODEL, else qwen2.5:7b for openai, claude-haiku-4-5 for anthropic; required for bedrock)")
1343
+ @click.option("--region", default=None, help="AWS region for --backend bedrock (default: $AWS_REGION)")
1344
+ @click.option("--base-url", default=None,
1345
+ help="Endpoint for --backend openai (default: $SPOOLING_SUMMARY_BASE_URL or local Ollama)")
1346
+ @click.option("--force", is_flag=True, help="Regenerate even if a summary exists (replaces provider summaries too)")
1347
+ @click.option("--dry-run", is_flag=True, help="List what would be summarized; call no model")
1348
+ @click.option("--yes", "-y", is_flag=True, help="Don't ask before sending text to a non-local endpoint")
1349
+ def summarize(session_ids, project, provider, days, limit, min_messages, backend, model, region, base_url, force, dry_run, yes):
1350
+ """Generate short summaries for sessions that don't have one.
1351
+
1352
+ Uses a model you configure; the default is a local Ollama daemon, so
1353
+ nothing leaves your machine. Transcripts are secret-redacted before they
1354
+ are sent. Sessions whose summary came from the provider are left alone
1355
+ unless --force is given; summaries we generated are refreshed when the
1356
+ session has grown since.
1357
+
1358
+ \b
1359
+ Examples:
1360
+ spooling summarize --dry-run
1361
+ spooling summarize -n 10 --days 7
1362
+ spooling summarize ses_e6310bd1 --force
1363
+ spooling summarize --base-url https://api.openai.com/v1 --model gpt-4o-mini
1364
+ spooling summarize --backend anthropic
1365
+ spooling summarize --backend bedrock --model us.anthropic.claude-haiku-4-5-20251001-v1:0
1366
+ """
1367
+ from spooling.db import get_connection
1368
+ from spooling import summarize as sm
1369
+ from spooling.sessions import resolve_session_ids
1370
+
1371
+ backend = backend or sm.DEFAULT_BACKEND
1372
+ if backend not in sm.BACKENDS:
1373
+ console.print(f"[red]Unknown backend {backend!r}; choose from {', '.join(sm.BACKENDS)}.[/red]")
1374
+ raise SystemExit(1)
1375
+ base_url = base_url or sm.DEFAULT_BASE_URL
1376
+ try:
1377
+ model = sm.resolve_model(backend, model)
1378
+ except ValueError as e:
1379
+ console.print(f"[red]{e}[/red]")
1380
+ raise SystemExit(1)
1381
+ where = base_url if backend == "openai" else f"{backend}" + (f" ({region})" if region else "")
1382
+
1383
+ resolved: list[str] = []
1384
+ for ref in session_ids:
1385
+ matches = resolve_session_ids(ref)
1386
+ if not matches:
1387
+ console.print(f"[red]Session not found:[/red] {ref}")
1388
+ raise SystemExit(1)
1389
+ if len(matches) > 1:
1390
+ console.print(f"[yellow]'{ref}' is ambiguous; matches:[/yellow]")
1391
+ for m in matches:
1392
+ console.print(f" {m}")
1393
+ raise SystemExit(1)
1394
+ resolved.append(matches[0])
1395
+
1396
+ conn = get_connection()
1397
+ try:
1398
+ targets = sm.select_sessions(
1399
+ conn, session_ids=resolved or None, project=project, provider=provider,
1400
+ days=days, min_messages=min_messages, force=force, limit=limit,
1401
+ )
1402
+ if not targets:
1403
+ console.print("[green]Nothing to summarize.[/green]")
1404
+ if resolved and not force:
1405
+ console.print("[dim]Named sessions that already have a summary need --force.[/dim]")
1406
+ return
1407
+
1408
+ if dry_run:
1409
+ table = Table(title=f"Would summarize {len(targets)} session(s)", show_lines=False)
1410
+ table.add_column("Session ID", style="cyan", no_wrap=True)
1411
+ table.add_column("Project")
1412
+ table.add_column("Msgs", justify="right")
1413
+ table.add_column("Title")
1414
+ table.add_column("Existing summary", style="dim")
1415
+ for t in targets:
1416
+ table.add_row(
1417
+ t["id"], _clean_project(t["project"] or ""), str(t["message_count"] or 0),
1418
+ (t["title"] or "")[:40], "yes" if t["summary"] else "",
1419
+ )
1420
+ console.print(table)
1421
+ console.print(f"[dim]Model: {model} via {where}[/dim]")
1422
+ return
1423
+
1424
+ if not sm.is_local_backend(backend, base_url) and not yes:
1425
+ console.print(
1426
+ f"[yellow]{where} is not local.[/yellow] Redacted transcripts of "
1427
+ f"{len(targets)} session(s) will be sent to it."
1428
+ )
1429
+ if not click.confirm("Continue?", default=False):
1430
+ raise SystemExit(1)
1431
+
1432
+ ok = failed = 0
1433
+ for t in targets:
1434
+ label = f"{t['id'][:16]} {(t['title'] or '')[:40]}"
1435
+ transcript = sm.build_transcript(conn, t["id"])
1436
+ if not transcript:
1437
+ console.print(f"[dim]skip[/dim] {label} (no message text)")
1438
+ continue
1439
+ try:
1440
+ text = sm.generate_summary(
1441
+ transcript, model=model, base_url=base_url, backend=backend, region=region,
1442
+ )
1443
+ except Exception as e:
1444
+ failed += 1
1445
+ from rich.markup import escape
1446
+ console.print(f"[red]fail[/red] {escape(label)}: {escape(str(e))}", highlight=False)
1447
+ # Bad credentials or an unreachable server fail every session the same way.
1448
+ if sm.is_fatal_error(e):
1449
+ console.print(f"[dim]Stopping: this will fail for every session. Check the endpoint, model and credentials for {escape(where)}.[/dim]")
1450
+ break
1451
+ continue
1452
+ sm.store_summary(conn, t["id"], text, t["message_count"] or 0)
1453
+ ok += 1
1454
+ console.print(f"[green]ok[/green] {label}")
1455
+ console.print(f" {text}", markup=False, highlight=False, style="dim")
1456
+ console.print(f"\nSummarized {ok}, failed {failed}.")
1457
+ if failed and not ok:
1458
+ raise SystemExit(1)
1459
+ finally:
1460
+ conn.close()
1461
+
1462
+
1463
+
1304
1464
  # ---------------------------------------------------------------------------
1305
1465
  # Stats providers subcommand
1306
1466
  # ---------------------------------------------------------------------------
@@ -66,7 +66,7 @@ def _auth_headers() -> dict:
66
66
  cfg = _load_config()
67
67
  key = cfg.get("api_key") or os.environ.get("SPOOLING_CLOUD_API_KEY")
68
68
  if not key:
69
- raise click.ClickException("Not logged in. Run `spooling cloud login --key sk_...` first.")
69
+ raise click.ClickException("Not logged in. Run `spooling login` first.")
70
70
  return {"Authorization": f"Bearer {key}"}
71
71
 
72
72
 
@@ -218,14 +218,22 @@ def cloud():
218
218
 
219
219
 
220
220
  @cloud.command("login")
221
- @click.option("--key", required=True, help="API key minted at app.spooling.ai/settings/api-keys")
221
+ @click.option("--key", default=None, help="Use an API key you already have (skips the browser)")
222
222
  @click.option("--api-url", default=None, help=f"Override API base (default {DEFAULT_API})")
223
- def cloud_login(key: str, api_url: str | None):
224
- """Store a Spooling Cloud API key in ~/.config/spooling/cloud.json."""
223
+ @click.option("--no-browser", is_flag=True, help="Print the approval link instead of opening it")
224
+ def cloud_login(key: str | None, api_url: str | None, no_browser: bool):
225
+ """Sign in to Spooling Cloud (opens your browser), or store a key you already have."""
225
226
  cfg = _load_config()
226
- cfg["api_key"] = key.strip()
227
227
  if api_url:
228
228
  cfg["api_url"] = api_url.rstrip("/")
229
+ if key:
230
+ cfg["api_key"] = key.strip()
231
+ else:
232
+ from spooling.device_login import run_device_login
233
+ base = cfg.get("api_url") or os.environ.get("SPOOLING_CLOUD_URL") or DEFAULT_API
234
+ cfg["api_key"], ws = run_device_login(base, open_browser=not no_browser)
235
+ if ws.get("name"):
236
+ console.print(f"[green]Approved.[/green] Sessions will be pushed to [bold]{ws['name']}[/bold].")
229
237
  _save_config(cfg)
230
238
 
231
239
  base = cfg.get("api_url") or DEFAULT_API
@@ -246,7 +254,7 @@ def cloud_status():
246
254
  """Show current login + cloud stats."""
247
255
  cfg = _load_config()
248
256
  if not cfg.get("api_key"):
249
- console.print("[yellow]Not logged in.[/yellow] Run `spooling cloud login --key sk_...`.")
257
+ console.print("[yellow]Not logged in.[/yellow] Run `spooling login`.")
250
258
  return
251
259
  base = _api_base()
252
260
  try:
@@ -138,9 +138,25 @@ class SpoolingConnection:
138
138
  def _ensure_schema(conn: sqlite3.Connection) -> None:
139
139
  """Create all tables/indexes if they don't exist yet."""
140
140
  conn.executescript(SCHEMA_SQL)
141
+ _migrate_columns(conn)
141
142
  conn.commit()
142
143
 
143
144
 
145
+ # (table, column, DDL type): columns added after the first release.
146
+ # CREATE TABLE IF NOT EXISTS won't add these to a pre-existing table.
147
+ _ADDED_COLUMNS = (
148
+ ("sessions", "summary", "TEXT"),
149
+ ("sessions", "summary_message_count", "INTEGER"),
150
+ )
151
+
152
+
153
+ def _migrate_columns(conn: sqlite3.Connection) -> None:
154
+ for table, column, ddl in _ADDED_COLUMNS:
155
+ existing = {row[1] for row in conn.execute(f"PRAGMA table_info({table})")}
156
+ if column not in existing:
157
+ conn.execute(f"ALTER TABLE {table} ADD COLUMN {column} {ddl}")
158
+
159
+
144
160
  # ---------------------------------------------------------------------------
145
161
  # Public API
146
162
  # ---------------------------------------------------------------------------
@@ -0,0 +1,88 @@
1
+ """Sign the CLI in through the browser: ``spooling login``.
2
+
3
+ The API key is created HERE, on this machine, and only its sha256 is sent to Spooling. You approve the short code in
4
+ your browser (signed in, choosing the workspace), and the server registers that key for you. No secret ever travels
5
+ through the browser, the clipboard, or the server's responses, and there is nothing to copy and paste.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ import platform
12
+ import secrets
13
+ import socket
14
+ import time
15
+ import webbrowser
16
+
17
+ import click
18
+ import httpx
19
+ from rich.console import Console
20
+
21
+ console = Console()
22
+
23
+
24
+ class LoginError(click.ClickException):
25
+ pass
26
+
27
+
28
+ def _new_key() -> str:
29
+ return "sk_" + secrets.token_urlsafe(32)
30
+
31
+
32
+ def _client_name() -> str:
33
+ try:
34
+ host = socket.gethostname().split(".")[0]
35
+ except Exception: # noqa: BLE001
36
+ host = "this computer"
37
+ return f"{host} ({platform.system() or 'unknown OS'})"[:80]
38
+
39
+
40
+ def run_device_login(api_base: str, *, open_browser: bool = True, sleep=time.sleep, now=time.monotonic,
41
+ http=httpx, out=console) -> tuple[str, dict]:
42
+ """Do the whole dance. Returns (api_key, workspace). Raises LoginError with a plain-English reason."""
43
+ api_base = api_base.rstrip("/")
44
+ key = _new_key()
45
+ try:
46
+ r = http.post(f"{api_base}/api/v1/auths/device/code", timeout=15, json={
47
+ "client_name": _client_name(), "key_hash": hashlib.sha256(key.encode()).hexdigest(), "key_prefix": key[:12]})
48
+ except httpx.HTTPError as e:
49
+ raise LoginError(f"Could not reach {api_base}: {e}") from e
50
+ if r.status_code == 429:
51
+ raise LoginError("Too many login attempts from this network. Try again in a while.")
52
+ if r.status_code != 200:
53
+ raise LoginError(f"Spooling refused the login request ({r.status_code}).")
54
+ d = r.json()
55
+
56
+ url = d["verification_uri_complete"]
57
+ out.print()
58
+ out.print(f" Your code: [bold cyan]{d['user_code']}[/bold cyan]")
59
+ out.print(f" Approve it at [underline]{url}[/underline]")
60
+ if open_browser:
61
+ try:
62
+ if webbrowser.open(url):
63
+ out.print(" [dim](opened in your browser)[/dim]")
64
+ except Exception: # noqa: BLE001
65
+ pass
66
+ out.print(" [dim]Waiting for approval... (Ctrl+C to cancel)[/dim]\n")
67
+
68
+ interval = max(int(d.get("interval", 5)), 1)
69
+ deadline = now() + int(d.get("expires_in", 600))
70
+ while now() < deadline:
71
+ sleep(interval)
72
+ try:
73
+ p = http.post(f"{api_base}/api/v1/auths/device/poll", json={"device_code": d["device_code"]}, timeout=15)
74
+ except httpx.HTTPError:
75
+ continue # a blip: keep waiting until the code expires
76
+ if p.status_code != 200:
77
+ continue
78
+ j = p.json()
79
+ status = j.get("status")
80
+ if status == "approved":
81
+ return key, j.get("workspace") or {}
82
+ if status == "denied":
83
+ raise LoginError("The request was denied in the browser.")
84
+ if status == "expired":
85
+ raise LoginError("The code expired before it was approved. Run the command again.")
86
+ if status == "slow_down":
87
+ interval = int(j.get("interval", interval + 5))
88
+ raise LoginError("Timed out waiting for approval. Run the command again.")
@@ -90,8 +90,8 @@ def _store_session(conn, session: ParsedSession):
90
90
  conn.execute(
91
91
  """INSERT INTO sessions (id, provider_id, project, cwd, git_branch, started_at, ended_at,
92
92
  message_count, tool_call_count, estimated_input_tokens, estimated_output_tokens,
93
- estimated_cost_usd, agent_version, model, title)
94
- VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
93
+ estimated_cost_usd, agent_version, model, title, summary)
94
+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
95
95
  ON CONFLICT (id) DO UPDATE SET
96
96
  provider_id = EXCLUDED.provider_id,
97
97
  message_count = EXCLUDED.message_count,
@@ -101,13 +101,16 @@ def _store_session(conn, session: ParsedSession):
101
101
  estimated_cost_usd = EXCLUDED.estimated_cost_usd,
102
102
  ended_at = EXCLUDED.ended_at,
103
103
  model = EXCLUDED.model,
104
- title = EXCLUDED.title""",
104
+ title = EXCLUDED.title,
105
+ summary_message_count = CASE WHEN EXCLUDED.summary IS NOT NULL
106
+ THEN NULL ELSE sessions.summary_message_count END,
107
+ summary = COALESCE(EXCLUDED.summary, sessions.summary)""",
105
108
  (
106
109
  session.session_id, session.provider_id, _scrub(session.project), _scrub(session.cwd),
107
110
  _scrub(session.git_branch), session.started_at, session.ended_at, session.message_count,
108
111
  session.tool_call_count, session.estimated_input_tokens,
109
112
  session.estimated_output_tokens, cost, _scrub(session.agent_version),
110
- _scrub(session.model), _scrub(session.title),
113
+ _scrub(session.model), _scrub(session.title), _scrub(session.summary),
111
114
  ),
112
115
  )
113
116
 
@@ -71,6 +71,9 @@ class ParsedSession:
71
71
  agent_version: str | None = None
72
72
  model: str | None = None
73
73
  title: str | None = None
74
+ # Provider-supplied summary, if the source already has one. Otherwise None
75
+ # and `spooling summarize` can fill it in later.
76
+ summary: str | None = None
74
77
  provider_id: str = "jsonl-session"
75
78
  trace: Optional[Trace] = None
76
79
  # Per-session incremental sync marker. Providers whose "file" holds many
@@ -329,6 +332,7 @@ def parse_session_file(
329
332
  # --- Pass 1: load all records into memory keyed by uuid -------------
330
333
  records: list[dict] = []
331
334
  by_uuid: dict[str, dict] = {}
335
+ summary: str | None = None
332
336
 
333
337
  try:
334
338
  with open(file_path) as f:
@@ -340,6 +344,13 @@ def parse_session_file(
340
344
  record = json.loads(line)
341
345
  except json.JSONDecodeError:
342
346
  continue
347
+ if record.get("type") == "summary":
348
+ # Claude Code writes a one-line summary record when it
349
+ # compacts or resumes a conversation. Last one wins.
350
+ text = record.get("summary")
351
+ if isinstance(text, str) and text.strip():
352
+ summary = text.strip()
353
+ continue
343
354
  if record.get("type") not in ("user", "assistant"):
344
355
  continue
345
356
  records.append(record)
@@ -458,6 +469,7 @@ def parse_session_file(
458
469
  agent_version=agent_version,
459
470
  model=model,
460
471
  title=title,
472
+ summary=summary,
461
473
  provider_id=provider_id,
462
474
  trace=trace,
463
475
  )
@@ -23,7 +23,9 @@ CREATE TABLE IF NOT EXISTS sessions (
23
23
  estimated_cost_usd REAL DEFAULT 0,
24
24
  agent_version TEXT,
25
25
  model TEXT,
26
- title TEXT
26
+ title TEXT,
27
+ summary TEXT,
28
+ summary_message_count INTEGER
27
29
  );
28
30
 
29
31
  CREATE INDEX IF NOT EXISTS idx_sessions_provider ON sessions(provider_id);