spooling 0.2.16__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.16/spooling.egg-info → spooling-0.2.17}/PKG-INFO +38 -1
  2. {spooling-0.2.16 → spooling-0.2.17}/README.md +37 -0
  3. {spooling-0.2.16 → spooling-0.2.17}/pyproject.toml +1 -1
  4. {spooling-0.2.16 → spooling-0.2.17}/spooling/cli.py +153 -3
  5. {spooling-0.2.16 → spooling-0.2.17}/spooling/db.py +16 -0
  6. {spooling-0.2.16 → spooling-0.2.17}/spooling/ingest.py +7 -4
  7. {spooling-0.2.16 → spooling-0.2.17}/spooling/parser.py +12 -0
  8. {spooling-0.2.16 → spooling-0.2.17}/spooling/schema.py +3 -1
  9. spooling-0.2.17/spooling/summarize.py +365 -0
  10. {spooling-0.2.16 → spooling-0.2.17/spooling.egg-info}/PKG-INFO +38 -1
  11. {spooling-0.2.16 → spooling-0.2.17}/spooling.egg-info/SOURCES.txt +2 -0
  12. {spooling-0.2.16 → spooling-0.2.17}/tests/test_docs.py +11 -0
  13. spooling-0.2.17/tests/test_summarize.py +470 -0
  14. {spooling-0.2.16 → spooling-0.2.17}/LICENSE +0 -0
  15. {spooling-0.2.16 → spooling-0.2.17}/setup.cfg +0 -0
  16. {spooling-0.2.16 → spooling-0.2.17}/spooling/__init__.py +0 -0
  17. {spooling-0.2.16 → spooling-0.2.17}/spooling/agent.py +0 -0
  18. {spooling-0.2.16 → spooling-0.2.17}/spooling/classifiers.py +0 -0
  19. {spooling-0.2.16 → spooling-0.2.17}/spooling/cloud.py +0 -0
  20. {spooling-0.2.16 → spooling-0.2.17}/spooling/config.py +0 -0
  21. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/__init__.py +0 -0
  22. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/base.py +0 -0
  23. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/bigquery.py +0 -0
  24. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/clickhouse.py +0 -0
  25. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/factory.py +0 -0
  26. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/mongodb.py +0 -0
  27. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/mysql.py +0 -0
  28. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/postgresql.py +0 -0
  29. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/rest/__init__.py +0 -0
  30. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/rest/base.py +0 -0
  31. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/rest/shopify_connectors.py +0 -0
  32. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/snowflake.py +0 -0
  33. {spooling-0.2.16 → spooling-0.2.17}/spooling/connectors/types.py +0 -0
  34. {spooling-0.2.16 → spooling-0.2.17}/spooling/device_login.py +0 -0
  35. {spooling-0.2.16 → spooling-0.2.17}/spooling/embeddings.py +0 -0
  36. {spooling-0.2.16 → spooling-0.2.17}/spooling/evals.py +0 -0
  37. {spooling-0.2.16 → spooling-0.2.17}/spooling/experiments.py +0 -0
  38. {spooling-0.2.16 → spooling-0.2.17}/spooling/insights.py +0 -0
  39. {spooling-0.2.16 → spooling-0.2.17}/spooling/mcp_server.py +0 -0
  40. {spooling-0.2.16 → spooling-0.2.17}/spooling/optimize.py +0 -0
  41. {spooling-0.2.16 → spooling-0.2.17}/spooling/pricing.py +0 -0
  42. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/__init__.py +0 -0
  43. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/antigravity.py +0 -0
  44. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/base.py +0 -0
  45. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/claude_code.py +0 -0
  46. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/codex.py +0 -0
  47. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/copilot.py +0 -0
  48. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/cortex_code.py +0 -0
  49. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/cursor.py +0 -0
  50. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/gemini.py +0 -0
  51. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/github.py +0 -0
  52. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/gitlab.py +0 -0
  53. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/kiro.py +0 -0
  54. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/opencode.py +0 -0
  55. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/session_file.py +0 -0
  56. {spooling-0.2.16 → spooling-0.2.17}/spooling/providers/windsurf.py +0 -0
  57. {spooling-0.2.16 → spooling-0.2.17}/spooling/redact.py +0 -0
  58. {spooling-0.2.16 → spooling-0.2.17}/spooling/remote_otel.py +0 -0
  59. {spooling-0.2.16 → spooling-0.2.17}/spooling/sdk.py +0 -0
  60. {spooling-0.2.16 → spooling-0.2.17}/spooling/search.py +0 -0
  61. {spooling-0.2.16 → spooling-0.2.17}/spooling/server.py +0 -0
  62. {spooling-0.2.16 → spooling-0.2.17}/spooling/sessions.py +0 -0
  63. {spooling-0.2.16 → spooling-0.2.17}/spooling/stats.py +0 -0
  64. {spooling-0.2.16 → spooling-0.2.17}/spooling/subscription_pricing.py +0 -0
  65. {spooling-0.2.16 → spooling-0.2.17}/spooling/tracing.py +0 -0
  66. {spooling-0.2.16 → spooling-0.2.17}/spooling/tunnel.py +0 -0
  67. {spooling-0.2.16 → spooling-0.2.17}/spooling/tunnel_auth.py +0 -0
  68. {spooling-0.2.16 → spooling-0.2.17}/spooling/watcher.py +0 -0
  69. {spooling-0.2.16 → spooling-0.2.17}/spooling.egg-info/dependency_links.txt +0 -0
  70. {spooling-0.2.16 → spooling-0.2.17}/spooling.egg-info/entry_points.txt +0 -0
  71. {spooling-0.2.16 → spooling-0.2.17}/spooling.egg-info/requires.txt +0 -0
  72. {spooling-0.2.16 → spooling-0.2.17}/spooling.egg-info/top_level.txt +0 -0
  73. {spooling-0.2.16 → spooling-0.2.17}/tests/test_agent_spans.py +0 -0
  74. {spooling-0.2.16 → spooling-0.2.17}/tests/test_claude_code_provider.py +0 -0
  75. {spooling-0.2.16 → spooling-0.2.17}/tests/test_cloud_errors.py +0 -0
  76. {spooling-0.2.16 → spooling-0.2.17}/tests/test_cloud_teams.py +0 -0
  77. {spooling-0.2.16 → spooling-0.2.17}/tests/test_device_login.py +0 -0
  78. {spooling-0.2.16 → spooling-0.2.17}/tests/test_insights.py +0 -0
  79. {spooling-0.2.16 → spooling-0.2.17}/tests/test_mcp_auth_middleware.py +0 -0
  80. {spooling-0.2.16 → spooling-0.2.17}/tests/test_session_ids.py +0 -0
  81. {spooling-0.2.16 → spooling-0.2.17}/tests/test_storage_optimizations.py +0 -0
  82. {spooling-0.2.16 → 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.16
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.
@@ -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.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "spooling"
3
- version = "0.2.16"
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." }]
@@ -1175,8 +1175,9 @@ def session():
1175
1175
  @click.option("--cwd", default=None, help="Filter by cwd substring")
1176
1176
  @click.option("--title", default=None, help="Filter by title substring")
1177
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)")
1178
1179
  @click.option("--limit", "-n", default=20, help="Max sessions to return (default: 20)")
1179
- def session_list(project, cwd, title, id_part, limit):
1180
+ def session_list(project, cwd, title, id_part, limit, summaries):
1180
1181
  """List local sessions with optional filters."""
1181
1182
  from spooling.db import get_connection
1182
1183
  from datetime import datetime as _dt
@@ -1201,6 +1202,7 @@ def session_list(project, cwd, title, id_part, limit):
1201
1202
 
1202
1203
  rows = conn.execute(
1203
1204
  f"""SELECT id, provider_id, project, title, started_at,
1205
+ summary,
1204
1206
  message_count, tool_call_count, estimated_cost_usd
1205
1207
  FROM sessions {where_clause}
1206
1208
  ORDER BY started_at DESC NULLS LAST LIMIT ?""",
@@ -1216,7 +1218,7 @@ def session_list(project, cwd, title, id_part, limit):
1216
1218
  table.add_column("Session ID", style="cyan", no_wrap=True)
1217
1219
  table.add_column("Provider")
1218
1220
  table.add_column("Project")
1219
- table.add_column("Title")
1221
+ table.add_column("Summary" if summaries else "Title")
1220
1222
  table.add_column("Started", style="dim")
1221
1223
  table.add_column("Msgs", justify="right")
1222
1224
  table.add_column("Tools", justify="right")
@@ -1234,7 +1236,7 @@ def session_list(project, cwd, title, id_part, limit):
1234
1236
  r["id"] or "",
1235
1237
  r["provider_id"] or "",
1236
1238
  _clean_project(r["project"] or ""),
1237
- (r["title"] or "")[:45],
1239
+ ((r["summary"] or r["title"] or "")[:90] if summaries else (r["title"] or "")[:45]),
1238
1240
  ts,
1239
1241
  str(r["message_count"] or 0),
1240
1242
  str(r["tool_call_count"] or 0),
@@ -1287,6 +1289,18 @@ def session_show(session_id, messages, max_chars):
1287
1289
  style="blue",
1288
1290
  ))
1289
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
+
1290
1304
  if detail["tool_summary"]:
1291
1305
  table = Table(title="Tool Usage", show_lines=False)
1292
1306
  table.add_column("Tool", style="magenta")
@@ -1311,6 +1325,142 @@ def session_show(session_id, messages, max_chars):
1311
1325
  console.print(f"[dim]{len(detail['messages'])} messages — pass --messages to print the session text[/dim]")
1312
1326
 
1313
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
+
1314
1464
  # ---------------------------------------------------------------------------
1315
1465
  # Stats providers subcommand
1316
1466
  # ---------------------------------------------------------------------------
@@ -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
  # ---------------------------------------------------------------------------
@@ -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);