spooling 0.2.16__tar.gz → 0.2.18__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.18}/PKG-INFO +54 -1
  2. {spooling-0.2.16 → spooling-0.2.18}/README.md +53 -0
  3. {spooling-0.2.16 → spooling-0.2.18}/pyproject.toml +1 -1
  4. {spooling-0.2.16 → spooling-0.2.18}/spooling/cli.py +172 -3
  5. {spooling-0.2.16 → spooling-0.2.18}/spooling/db.py +16 -0
  6. {spooling-0.2.16 → spooling-0.2.18}/spooling/ingest.py +7 -4
  7. {spooling-0.2.16 → spooling-0.2.18}/spooling/parser.py +12 -0
  8. {spooling-0.2.16 → spooling-0.2.18}/spooling/schema.py +3 -1
  9. spooling-0.2.18/spooling/summarize.py +506 -0
  10. {spooling-0.2.16 → spooling-0.2.18/spooling.egg-info}/PKG-INFO +54 -1
  11. {spooling-0.2.16 → spooling-0.2.18}/spooling.egg-info/SOURCES.txt +2 -0
  12. {spooling-0.2.16 → spooling-0.2.18}/tests/test_docs.py +11 -0
  13. spooling-0.2.18/tests/test_summarize.py +640 -0
  14. {spooling-0.2.16 → spooling-0.2.18}/LICENSE +0 -0
  15. {spooling-0.2.16 → spooling-0.2.18}/setup.cfg +0 -0
  16. {spooling-0.2.16 → spooling-0.2.18}/spooling/__init__.py +0 -0
  17. {spooling-0.2.16 → spooling-0.2.18}/spooling/agent.py +0 -0
  18. {spooling-0.2.16 → spooling-0.2.18}/spooling/classifiers.py +0 -0
  19. {spooling-0.2.16 → spooling-0.2.18}/spooling/cloud.py +0 -0
  20. {spooling-0.2.16 → spooling-0.2.18}/spooling/config.py +0 -0
  21. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/__init__.py +0 -0
  22. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/base.py +0 -0
  23. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/bigquery.py +0 -0
  24. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/clickhouse.py +0 -0
  25. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/factory.py +0 -0
  26. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/mongodb.py +0 -0
  27. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/mysql.py +0 -0
  28. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/postgresql.py +0 -0
  29. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/rest/__init__.py +0 -0
  30. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/rest/base.py +0 -0
  31. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/rest/shopify_connectors.py +0 -0
  32. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/snowflake.py +0 -0
  33. {spooling-0.2.16 → spooling-0.2.18}/spooling/connectors/types.py +0 -0
  34. {spooling-0.2.16 → spooling-0.2.18}/spooling/device_login.py +0 -0
  35. {spooling-0.2.16 → spooling-0.2.18}/spooling/embeddings.py +0 -0
  36. {spooling-0.2.16 → spooling-0.2.18}/spooling/evals.py +0 -0
  37. {spooling-0.2.16 → spooling-0.2.18}/spooling/experiments.py +0 -0
  38. {spooling-0.2.16 → spooling-0.2.18}/spooling/insights.py +0 -0
  39. {spooling-0.2.16 → spooling-0.2.18}/spooling/mcp_server.py +0 -0
  40. {spooling-0.2.16 → spooling-0.2.18}/spooling/optimize.py +0 -0
  41. {spooling-0.2.16 → spooling-0.2.18}/spooling/pricing.py +0 -0
  42. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/__init__.py +0 -0
  43. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/antigravity.py +0 -0
  44. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/base.py +0 -0
  45. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/claude_code.py +0 -0
  46. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/codex.py +0 -0
  47. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/copilot.py +0 -0
  48. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/cortex_code.py +0 -0
  49. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/cursor.py +0 -0
  50. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/gemini.py +0 -0
  51. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/github.py +0 -0
  52. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/gitlab.py +0 -0
  53. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/kiro.py +0 -0
  54. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/opencode.py +0 -0
  55. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/session_file.py +0 -0
  56. {spooling-0.2.16 → spooling-0.2.18}/spooling/providers/windsurf.py +0 -0
  57. {spooling-0.2.16 → spooling-0.2.18}/spooling/redact.py +0 -0
  58. {spooling-0.2.16 → spooling-0.2.18}/spooling/remote_otel.py +0 -0
  59. {spooling-0.2.16 → spooling-0.2.18}/spooling/sdk.py +0 -0
  60. {spooling-0.2.16 → spooling-0.2.18}/spooling/search.py +0 -0
  61. {spooling-0.2.16 → spooling-0.2.18}/spooling/server.py +0 -0
  62. {spooling-0.2.16 → spooling-0.2.18}/spooling/sessions.py +0 -0
  63. {spooling-0.2.16 → spooling-0.2.18}/spooling/stats.py +0 -0
  64. {spooling-0.2.16 → spooling-0.2.18}/spooling/subscription_pricing.py +0 -0
  65. {spooling-0.2.16 → spooling-0.2.18}/spooling/tracing.py +0 -0
  66. {spooling-0.2.16 → spooling-0.2.18}/spooling/tunnel.py +0 -0
  67. {spooling-0.2.16 → spooling-0.2.18}/spooling/tunnel_auth.py +0 -0
  68. {spooling-0.2.16 → spooling-0.2.18}/spooling/watcher.py +0 -0
  69. {spooling-0.2.16 → spooling-0.2.18}/spooling.egg-info/dependency_links.txt +0 -0
  70. {spooling-0.2.16 → spooling-0.2.18}/spooling.egg-info/entry_points.txt +0 -0
  71. {spooling-0.2.16 → spooling-0.2.18}/spooling.egg-info/requires.txt +0 -0
  72. {spooling-0.2.16 → spooling-0.2.18}/spooling.egg-info/top_level.txt +0 -0
  73. {spooling-0.2.16 → spooling-0.2.18}/tests/test_agent_spans.py +0 -0
  74. {spooling-0.2.16 → spooling-0.2.18}/tests/test_claude_code_provider.py +0 -0
  75. {spooling-0.2.16 → spooling-0.2.18}/tests/test_cloud_errors.py +0 -0
  76. {spooling-0.2.16 → spooling-0.2.18}/tests/test_cloud_teams.py +0 -0
  77. {spooling-0.2.16 → spooling-0.2.18}/tests/test_device_login.py +0 -0
  78. {spooling-0.2.16 → spooling-0.2.18}/tests/test_insights.py +0 -0
  79. {spooling-0.2.16 → spooling-0.2.18}/tests/test_mcp_auth_middleware.py +0 -0
  80. {spooling-0.2.16 → spooling-0.2.18}/tests/test_session_ids.py +0 -0
  81. {spooling-0.2.16 → spooling-0.2.18}/tests/test_storage_optimizations.py +0 -0
  82. {spooling-0.2.16 → spooling-0.2.18}/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.18
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,63 @@ 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
+ | `claude-code` | Reuse your Claude Code login (runs `claude -p`), here or on another machine with `--ssh` | whatever Claude Code is signed in with |
244
+ | `opencode` | Reuse opencode's providers (runs `opencode run`), here or over `--ssh` | whatever opencode is configured with |
245
+
246
+ 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`).
247
+
248
+ ```bash
249
+ spooling summarize --dry-run # see what would be summarized; calls no model
250
+ spooling summarize -n 10 --days 7 # the 10 newest sessions from the last week
251
+ spooling summarize ses_e6310bd1 --force # (re)summarize one session
252
+
253
+ spooling summarize --base-url https://api.openai.com/v1 --model gpt-4o-mini
254
+ spooling summarize --backend anthropic # defaults to claude-haiku-4-5
255
+ spooling summarize --backend bedrock --region us-east-2 \
256
+ --model us.anthropic.claude-haiku-4-5-20251001-v1:0
257
+
258
+ spooling summarize --backend claude-code # uses your Claude Code login
259
+ spooling summarize --backend claude-code --ssh my-other-mac
260
+ spooling summarize --backend opencode --model amazon-bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0
261
+ ```
262
+
263
+ - `-p, --project`, `--provider`, `-d, --days`, `-n, --limit` - choose which sessions
264
+ - `--min-messages` - skip very short sessions (default 4)
265
+ - `--backend` - `openai`, `anthropic`, `bedrock`, `claude-code` or `opencode` (or set `SPOOLING_SUMMARY_BACKEND`)
266
+ - `--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`)
267
+ - `--base-url` - endpoint for the `openai` backend (or `SPOOLING_SUMMARY_BASE_URL`; default `http://localhost:11434/v1`)
268
+ - `--region` - AWS region for `bedrock` (default `AWS_REGION`)
269
+ - `--ssh HOST` - run the `claude-code` or `opencode` backend on another machine over SSH (for example a Mac where Claude Code is signed in). Needs key-based SSH login; the redacted transcript is piped over the connection
270
+ - `--cli-cmd` - the command to run if it isn't on `PATH`, such as `~/.local/bin/claude`. With `--ssh`, this is the path on the remote machine
271
+ - `--force` - regenerate even if a summary exists
272
+ - `-y, --yes` - don't ask before sending text to a non-local endpoint
273
+
274
+ #### Using Claude Code or opencode
275
+
276
+ The `claude-code` and `opencode` backends run the agent's headless mode and send the prompt on stdin, so there is no API key to set up: they use whatever login the agent already has. Both send the redacted transcript to that agent's provider, so Spooling asks for confirmation first.
277
+
278
+ - Leave `--model` off to use the agent's default model. For opencode, the model is `provider/model`, and your configured default may be an old model id, so pass one explicitly if you see an error.
279
+ - With `--ssh`, the agent runs from `/tmp` on the remote machine, so it doesn't pick up a project's rules. SSH runs non-interactively and often skips your shell profile, so if you get "not found", use `--cli-cmd` with the full path.
280
+ - `claude -p` records each run as a session in that machine's Claude Code history. They are tagged with a `spooling-summary:` prefix, and `spooling summarize` skips them. The opencode backend deletes its run's session automatically.
281
+
282
+ 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.
283
+
231
284
  ### `spooling optimize`
232
285
 
233
286
  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,63 @@ 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
+ | `claude-code` | Reuse your Claude Code login (runs `claude -p`), here or on another machine with `--ssh` | whatever Claude Code is signed in with |
208
+ | `opencode` | Reuse opencode's providers (runs `opencode run`), here or over `--ssh` | whatever opencode is configured with |
209
+
210
+ 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`).
211
+
212
+ ```bash
213
+ spooling summarize --dry-run # see what would be summarized; calls no model
214
+ spooling summarize -n 10 --days 7 # the 10 newest sessions from the last week
215
+ spooling summarize ses_e6310bd1 --force # (re)summarize one session
216
+
217
+ spooling summarize --base-url https://api.openai.com/v1 --model gpt-4o-mini
218
+ spooling summarize --backend anthropic # defaults to claude-haiku-4-5
219
+ spooling summarize --backend bedrock --region us-east-2 \
220
+ --model us.anthropic.claude-haiku-4-5-20251001-v1:0
221
+
222
+ spooling summarize --backend claude-code # uses your Claude Code login
223
+ spooling summarize --backend claude-code --ssh my-other-mac
224
+ spooling summarize --backend opencode --model amazon-bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0
225
+ ```
226
+
227
+ - `-p, --project`, `--provider`, `-d, --days`, `-n, --limit` - choose which sessions
228
+ - `--min-messages` - skip very short sessions (default 4)
229
+ - `--backend` - `openai`, `anthropic`, `bedrock`, `claude-code` or `opencode` (or set `SPOOLING_SUMMARY_BACKEND`)
230
+ - `--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`)
231
+ - `--base-url` - endpoint for the `openai` backend (or `SPOOLING_SUMMARY_BASE_URL`; default `http://localhost:11434/v1`)
232
+ - `--region` - AWS region for `bedrock` (default `AWS_REGION`)
233
+ - `--ssh HOST` - run the `claude-code` or `opencode` backend on another machine over SSH (for example a Mac where Claude Code is signed in). Needs key-based SSH login; the redacted transcript is piped over the connection
234
+ - `--cli-cmd` - the command to run if it isn't on `PATH`, such as `~/.local/bin/claude`. With `--ssh`, this is the path on the remote machine
235
+ - `--force` - regenerate even if a summary exists
236
+ - `-y, --yes` - don't ask before sending text to a non-local endpoint
237
+
238
+ #### Using Claude Code or opencode
239
+
240
+ The `claude-code` and `opencode` backends run the agent's headless mode and send the prompt on stdin, so there is no API key to set up: they use whatever login the agent already has. Both send the redacted transcript to that agent's provider, so Spooling asks for confirmation first.
241
+
242
+ - Leave `--model` off to use the agent's default model. For opencode, the model is `provider/model`, and your configured default may be an old model id, so pass one explicitly if you see an error.
243
+ - With `--ssh`, the agent runs from `/tmp` on the remote machine, so it doesn't pick up a project's rules. SSH runs non-interactively and often skips your shell profile, so if you get "not found", use `--cli-cmd` with the full path.
244
+ - `claude -p` records each run as a session in that machine's Claude Code history. They are tagged with a `spooling-summary:` prefix, and `spooling summarize` skips them. The opencode backend deletes its run's session automatically.
245
+
246
+ 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.
247
+
195
248
  ### `spooling optimize`
196
249
 
197
250
  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.18"
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,161 @@ 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", "claude-code", "opencode"]), 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("--ssh", default=None, metavar="HOST",
1345
+ help="Run --backend claude-code or opencode on this SSH host (e.g. another Mac where it is signed in)")
1346
+ @click.option("--cli-cmd", default=None,
1347
+ help="Command for claude-code / opencode if it isn't on PATH (e.g. ~/.local/bin/claude); runs on --ssh HOST if set")
1348
+ @click.option("--base-url", default=None,
1349
+ help="Endpoint for --backend openai (default: $SPOOLING_SUMMARY_BASE_URL or local Ollama)")
1350
+ @click.option("--force", is_flag=True, help="Regenerate even if a summary exists (replaces provider summaries too)")
1351
+ @click.option("--dry-run", is_flag=True, help="List what would be summarized; call no model")
1352
+ @click.option("--yes", "-y", is_flag=True, help="Don't ask before sending text to a non-local endpoint")
1353
+ def summarize(session_ids, project, provider, days, limit, min_messages, backend, model, region, ssh, cli_cmd, base_url, force, dry_run, yes):
1354
+ """Generate short summaries for sessions that don't have one.
1355
+
1356
+ Uses a model you configure; the default is a local Ollama daemon, so
1357
+ nothing leaves your machine. Transcripts are secret-redacted before they
1358
+ are sent. Sessions whose summary came from the provider are left alone
1359
+ unless --force is given; summaries we generated are refreshed when the
1360
+ session has grown since.
1361
+
1362
+ \b
1363
+ Examples:
1364
+ spooling summarize --dry-run
1365
+ spooling summarize -n 10 --days 7
1366
+ spooling summarize ses_e6310bd1 --force
1367
+ spooling summarize --base-url https://api.openai.com/v1 --model gpt-4o-mini
1368
+ spooling summarize --backend anthropic
1369
+ spooling summarize --backend claude-code # reuse your Claude Code login
1370
+ spooling summarize --backend claude-code --ssh my-other-mac
1371
+ spooling summarize --backend opencode --model amazon-bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0
1372
+ spooling summarize --backend bedrock --model us.anthropic.claude-haiku-4-5-20251001-v1:0
1373
+ """
1374
+ from spooling.db import get_connection
1375
+ from spooling import summarize as sm
1376
+ from spooling.sessions import resolve_session_ids
1377
+
1378
+ backend = backend or sm.DEFAULT_BACKEND
1379
+ if backend not in sm.BACKENDS:
1380
+ console.print(f"[red]Unknown backend {backend!r}; choose from {', '.join(sm.BACKENDS)}.[/red]")
1381
+ raise SystemExit(1)
1382
+ base_url = base_url or sm.DEFAULT_BASE_URL
1383
+ try:
1384
+ model = sm.resolve_model(backend, model)
1385
+ except ValueError as e:
1386
+ console.print(f"[red]{e}[/red]")
1387
+ raise SystemExit(1)
1388
+ if (ssh or cli_cmd) and backend not in sm.CLI_BACKENDS:
1389
+ console.print("[red]--ssh and --cli-cmd only apply to --backend claude-code or opencode.[/red]")
1390
+ raise SystemExit(1)
1391
+ if backend == "openai":
1392
+ where = base_url
1393
+ elif backend in sm.CLI_BACKENDS:
1394
+ where = backend + (f" on {ssh}" if ssh else "")
1395
+ else:
1396
+ where = backend + (f" ({region})" if region else "")
1397
+
1398
+ resolved: list[str] = []
1399
+ for ref in session_ids:
1400
+ matches = resolve_session_ids(ref)
1401
+ if not matches:
1402
+ console.print(f"[red]Session not found:[/red] {ref}")
1403
+ raise SystemExit(1)
1404
+ if len(matches) > 1:
1405
+ console.print(f"[yellow]'{ref}' is ambiguous; matches:[/yellow]")
1406
+ for m in matches:
1407
+ console.print(f" {m}")
1408
+ raise SystemExit(1)
1409
+ resolved.append(matches[0])
1410
+
1411
+ conn = get_connection()
1412
+ try:
1413
+ targets = sm.select_sessions(
1414
+ conn, session_ids=resolved or None, project=project, provider=provider,
1415
+ days=days, min_messages=min_messages, force=force, limit=limit,
1416
+ )
1417
+ if not targets:
1418
+ console.print("[green]Nothing to summarize.[/green]")
1419
+ if resolved and not force:
1420
+ console.print("[dim]Named sessions that already have a summary need --force.[/dim]")
1421
+ return
1422
+
1423
+ if dry_run:
1424
+ table = Table(title=f"Would summarize {len(targets)} session(s)", show_lines=False)
1425
+ table.add_column("Session ID", style="cyan", no_wrap=True)
1426
+ table.add_column("Project")
1427
+ table.add_column("Msgs", justify="right")
1428
+ table.add_column("Title")
1429
+ table.add_column("Existing summary", style="dim")
1430
+ for t in targets:
1431
+ table.add_row(
1432
+ t["id"], _clean_project(t["project"] or ""), str(t["message_count"] or 0),
1433
+ (t["title"] or "")[:40], "yes" if t["summary"] else "",
1434
+ )
1435
+ console.print(table)
1436
+ console.print(f"[dim]Model: {model} via {where}[/dim]")
1437
+ return
1438
+
1439
+ if not sm.is_local_backend(backend, base_url) and not yes:
1440
+ console.print(
1441
+ f"[yellow]{where} is not local.[/yellow] Redacted transcripts of "
1442
+ f"{len(targets)} session(s) will be sent to it."
1443
+ )
1444
+ if not click.confirm("Continue?", default=False):
1445
+ raise SystemExit(1)
1446
+
1447
+ ok = failed = 0
1448
+ for t in targets:
1449
+ label = f"{t['id'][:16]} {(t['title'] or '')[:40]}"
1450
+ transcript = sm.build_transcript(conn, t["id"])
1451
+ if not transcript:
1452
+ console.print(f"[dim]skip[/dim] {label} (no message text)")
1453
+ continue
1454
+ if transcript.startswith(f"[user] {sm.RUN_MARKER}"):
1455
+ console.print(f"[dim]skip[/dim] {label} (a summarizer run, not real work)")
1456
+ continue
1457
+ try:
1458
+ text = sm.generate_summary(
1459
+ transcript, model=model, base_url=base_url, backend=backend, region=region,
1460
+ ssh=ssh, cli_cmd=cli_cmd,
1461
+ )
1462
+ except Exception as e:
1463
+ failed += 1
1464
+ from rich.markup import escape
1465
+ console.print(f"[red]fail[/red] {escape(label)}: {escape(str(e))}", highlight=False)
1466
+ # Bad credentials or an unreachable server fail every session the same way.
1467
+ if sm.is_fatal_error(e):
1468
+ console.print(f"[dim]Stopping: this will fail for every session. Check the endpoint, model and credentials for {escape(where)}.[/dim]")
1469
+ break
1470
+ continue
1471
+ sm.store_summary(conn, t["id"], text, t["message_count"] or 0)
1472
+ ok += 1
1473
+ console.print(f"[green]ok[/green] {label}")
1474
+ console.print(f" {text}", markup=False, highlight=False, style="dim")
1475
+ console.print(f"\nSummarized {ok}, failed {failed}.")
1476
+ if failed and not ok:
1477
+ raise SystemExit(1)
1478
+ finally:
1479
+ conn.close()
1480
+
1481
+
1482
+
1314
1483
  # ---------------------------------------------------------------------------
1315
1484
  # Stats providers subcommand
1316
1485
  # ---------------------------------------------------------------------------
@@ -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);