astern 0.0.6__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 (43) hide show
  1. astern-0.0.6/.github/workflows/ci.yml +24 -0
  2. astern-0.0.6/.gitignore +132 -0
  3. astern-0.0.6/LICENSE +21 -0
  4. astern-0.0.6/PKG-INFO +147 -0
  5. astern-0.0.6/README.md +115 -0
  6. astern-0.0.6/astern/__init__.py +26 -0
  7. astern-0.0.6/astern/__main__.py +13 -0
  8. astern-0.0.6/astern/data/.gitkeep +0 -0
  9. astern-0.0.6/astern/data/skills/astern-recall/SKILL.md +115 -0
  10. astern-0.0.6/astern/estimate.py +375 -0
  11. astern-0.0.6/astern/judge.py +376 -0
  12. astern-0.0.6/astern/ledger.py +118 -0
  13. astern-0.0.6/astern/lenses/__init__.py +121 -0
  14. astern-0.0.6/astern/lenses/commands.py +224 -0
  15. astern-0.0.6/astern/lenses/cost.py +45 -0
  16. astern-0.0.6/astern/lenses/friction.py +289 -0
  17. astern-0.0.6/astern/lenses/hygiene.py +68 -0
  18. astern-0.0.6/astern/lenses/stats.py +81 -0
  19. astern-0.0.6/astern/lenses/synopsis.py +298 -0
  20. astern-0.0.6/astern/lenses/timeline.py +62 -0
  21. astern-0.0.6/astern/lenses/tooling.py +60 -0
  22. astern-0.0.6/astern/recall.py +676 -0
  23. astern-0.0.6/astern/report.py +431 -0
  24. astern-0.0.6/astern/skills.py +163 -0
  25. astern-0.0.6/astern/sources.py +188 -0
  26. astern-0.0.6/astern/store.py +126 -0
  27. astern-0.0.6/astern/tools.py +848 -0
  28. astern-0.0.6/astern/turns.py +385 -0
  29. astern-0.0.6/astern/views.py +269 -0
  30. astern-0.0.6/pyproject.toml +69 -0
  31. astern-0.0.6/tests/conftest.py +53 -0
  32. astern-0.0.6/tests/fixtures.py +343 -0
  33. astern-0.0.6/tests/fixtures_lenses.py +241 -0
  34. astern-0.0.6/tests/test_cli.py +56 -0
  35. astern-0.0.6/tests/test_judge.py +190 -0
  36. astern-0.0.6/tests/test_judge_synopsis.py +362 -0
  37. astern-0.0.6/tests/test_ledger.py +158 -0
  38. astern-0.0.6/tests/test_lenses_h.py +268 -0
  39. astern-0.0.6/tests/test_recall.py +423 -0
  40. astern-0.0.6/tests/test_sources.py +202 -0
  41. astern-0.0.6/tests/test_store.py +121 -0
  42. astern-0.0.6/tests/test_tools.py +325 -0
  43. astern-0.0.6/tests/test_turns.py +278 -0
@@ -0,0 +1,24 @@
1
+ # wads CI — calls the reusable workflow hosted in i2mint/wads.
2
+ #
3
+ # All configuration comes from this repo's pyproject.toml [tool.wads.ci.*].
4
+ # To customize the workflow itself (rare), replace this file with the
5
+ # full inline template `wads/data/github_ci_uv.yml` from i2mint/wads.
6
+ #
7
+ # Permissions: the reusable workflow needs `contents: write` (version-bump
8
+ # push-back, gh-pages branch push) and `pages: write` (Pages REST config).
9
+ # Both default to read-only on personal-account callers, so they are granted
10
+ # explicitly here.
11
+ name: Continuous Integration
12
+ on: [push, pull_request]
13
+ jobs:
14
+ ci:
15
+ uses: i2mint/wads/.github/workflows/uv-ci.yml@master
16
+ permissions:
17
+ contents: write
18
+ pages: write
19
+ # Explicit pass-through (not `secrets: inherit`, which does not reliably
20
+ # propagate caller-repo secrets to a reusable workflow owned by a different
21
+ # account). astern reads local files and only ever runs the local `claude` CLI, so
22
+ # PYPI_PASSWORD is the only secret it needs.
23
+ secrets:
24
+ PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
@@ -0,0 +1,132 @@
1
+ docs/_build/
2
+ wads_configs.json
3
+ data/wads_configs.json
4
+ wads/data/wads_configs.json
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+
12
+ .DS_Store
13
+ # C extensions
14
+ *.so
15
+
16
+ # Distribution / packaging
17
+ .Python
18
+ build/
19
+ develop-eggs/
20
+ dist/
21
+ downloads/
22
+ eggs/
23
+ .eggs/
24
+ lib/
25
+ lib64/
26
+ parts/
27
+ sdist/
28
+ var/
29
+ wheels/
30
+ *.egg-info/
31
+ .installed.cfg
32
+ *.egg
33
+ MANIFEST
34
+ _build
35
+
36
+ # PyInstaller
37
+ # Usually these files are written by a python script from a template
38
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
39
+ *.manifest
40
+ *.spec
41
+
42
+ # Installer logs
43
+ pip-log.txt
44
+ pip-delete-this-directory.txt
45
+
46
+ # Unit test / coverage reports
47
+ htmlcov/
48
+ .tox/
49
+ .coverage
50
+ .coverage.*
51
+ .cache
52
+ nosetests.xml
53
+ coverage.xml
54
+ *.cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ target/
79
+
80
+ # Jupyter Notebook
81
+ .ipynb_checkpoints
82
+
83
+ # pyenv
84
+ .python-version
85
+
86
+ # celery beat schedule file
87
+ celerybeat-schedule
88
+
89
+ # SageMath parsed files
90
+ *.sage.py
91
+
92
+ # Environments
93
+ .env
94
+ .venv
95
+ env/
96
+ venv/
97
+ ENV/
98
+ env.bak/
99
+ venv.bak/
100
+
101
+ # Spyder project settings
102
+ .spyderproject
103
+ .spyproject
104
+
105
+ # Rope project settings
106
+ .ropeproject
107
+
108
+ # mkdocs documentation
109
+ /site
110
+
111
+ # mypy
112
+ .mypy_cache/
113
+
114
+ # PyCharm
115
+ .idea
116
+
117
+ # Ruff
118
+ .ruff_cache/
119
+
120
+ # VS Code
121
+ .vscode/
122
+
123
+ # Temporary test outputs
124
+ batch_results.json
125
+ *.tmp
126
+ tmp/
127
+ temp/
128
+ # Local session handoffs (not for commit)
129
+ .claude/handoffs/
130
+
131
+ # Session worktrees created by `claude --worktree` (not for commit)
132
+ .claude/worktrees/
astern-0.0.6/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thor Whalen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
astern-0.0.6/PKG-INFO ADDED
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.5
2
+ Name: astern
3
+ Version: 0.0.6
4
+ Summary: Look astern: mine your past Claude Code sessions for recurring problems, friction, rewritten code, and the vocabulary gap between you and your agents
5
+ Project-URL: Homepage, https://github.com/thorwhalen/astern
6
+ Project-URL: Repository, https://github.com/thorwhalen/astern
7
+ Project-URL: Issues, https://github.com/thorwhalen/astern/issues
8
+ Author: Thor Whalen
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,claude-code,mining,retrospective,sessions,transcripts
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Utilities
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: cw<0.2,>=0.1.1
22
+ Requires-Dist: dol>=0.3
23
+ Requires-Dist: openloops>=0.1.9
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0; extra == 'dev'
26
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
27
+ Provides-Extra: recall
28
+ Requires-Dist: ir>=0.1.31; extra == 'recall'
29
+ Provides-Extra: similar
30
+ Requires-Dist: ir; extra == 'similar'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # astern
34
+
35
+ `crowsnest` watches the sessions running right now; `astern` looks back at the wake they left — the transcripts Claude Code already keeps under `~/.claude/projects/`. It mines them for what problems recur, where agents get stuck, what one-off code keeps being rewritten, and which words you and your agents don't share, without spending a token twice.
36
+
37
+ ## Start here
38
+
39
+ ```bash
40
+ pip install astern
41
+
42
+ astern sync # read new or changed transcripts, run the free (heuristic) lenses
43
+ astern sessions # what's synced, newest first
44
+ astern show <sid-prefix> # one session: meta, ledger state, last turns, findings
45
+ astern report friction # (in progress) a lens's findings as a markdown report
46
+ astern judge # (in progress) run the LLM-judged lenses over what's synced
47
+ astern estimate # (in progress) token/cost estimate before a judge batch runs
48
+
49
+ pip install "astern[recall]" # + ir, for searching what past sessions already know
50
+ astern index # index the store into ir corpora (idempotent)
51
+ astern recall "what did we decide about the ledger" # ...and ask it
52
+ astern install-skills # link the shipped skills into ~/.claude/skills
53
+ ```
54
+
55
+ `sync`, `sessions` and `show` are shipped today. `report`, `judge` and `estimate` are being built out by other agents against the same store and ledger; once they land, the one-command loop is `astern sync && astern judge && astern report friction`.
56
+
57
+ ## What it extracts
58
+
59
+ Each **lens** asks one question of a session and returns typed, evidence-backed findings — every finding points back at the turn it came from. Method: **H** = deterministic heuristic, zero tokens; **L** = LLM-judged, spends subscription tokens via the local `claude` CLI; **H→L** = a heuristic shortlist that only the survivors get judged on.
60
+
61
+ | Lens | Question | Method |
62
+ |---|---|---|
63
+ | `stats` | The shape of a session in numbers — the cost model's own features | H |
64
+ | `problems` | What problem was each session solving, and how was it solved? | L |
65
+ | `recurring` | Which problems recur, and would a skill or subagent pay for itself? | H over L |
66
+ | `rewrites` | What one-off code keeps being rewritten? | H→L |
67
+ | `friction` | Where do agents get stuck, and what would remove the obstacle? | H→L |
68
+ | `jargon-in` | Which of my phrasings point to an established term I don't use? | L |
69
+ | `jargon-out` | Which terms do agents use that I don't? | H→L |
70
+ | `corrections` | What did I correct or re-affirm, and which corrections repeat? | H→L |
71
+ | `prompt-quality` | Which prompt shapes lead to clean turns, which to flailing ones? | H→L |
72
+ | `cost` | Where do the tokens and hours go, by project / task / model? | H |
73
+ | `timeline` | What did I work on this week, and what landed? | H→L |
74
+ | `decisions` | Which decisions were made, and why? | L |
75
+ | `claims` | Where did an agent claim "done" and a later turn show otherwise? | H→L |
76
+ | `questions` | What do agents keep asking me, and what did I answer? | H→L |
77
+ | `tooling` | Which skills/subagents/MCP tools are used, unused, or missing? | H |
78
+ | `memory-candidates` | Which restated facts should become memory, and where does memory drift? | H→L |
79
+ | `evals` | Which (prompt, outcome) pairs make a regression test for a skill? | H |
80
+ | `hygiene` | Do agents read before they edit, and does that change over time? | H |
81
+ | `regression` | Did the harness or model change behaviour? | H |
82
+ | `adherence` | Which CLAUDE.md/skill rules are followed, ignored, or fought? | L |
83
+ | `subagents` | Which subagent / `Workflow` spawns paid for themselves? | H |
84
+ | `effect` | Did an adopted rule, skill or function reduce the pattern it targeted? | H |
85
+
86
+ Session handoffs (`Q`) are deliberately not a lens here — that's `openloops`, linked rather than re-derived. The full catalogue, with the signal each lens reads and the sink it feeds, is plan §2 (see "The seams" below).
87
+
88
+ ## Recall — what past sessions already know
89
+
90
+ `astern recall "<query>"` answers *what did we already think, try and decide about X* without re-reading a transcript. astern is only the **record source** here: `ir` owns the indexing and the search, and the multi-hop search loop belongs to `raglab`. Install the extra (`pip install "astern[recall]"`), run `astern index` after a `sync`, and ask.
91
+
92
+ Two grains, indexed as two `ir` corpora because they answer different questions:
93
+
94
+ | Corpus | One record is | Best for |
95
+ |---|---|---|
96
+ | `session_synopses` | a whole session as the `synopsis` lens distilled it — goal, problems and solutions, decisions, corrections | **what was decided** |
97
+ | `session_turns` | one turn: the prompt and the assistant's closing text | **what was actually tried** |
98
+
99
+ Unfiltered, a recall also reaches the `skills` and `reports` corpora when this machine has them (weighted below the sessions, so they inform rather than crowd out). `--project X` and `--since-days N` are hard metadata filters; a project is resolved *through the store* into its session ids, because a session about a project often runs from a group dir or a worktree whose name says nothing about it.
100
+
101
+ Embedding is local and offline: ir's `all-MiniLM-L6-v2` by default — **no API key, no per-query cost** — with `--embedder light` (numpy-only hashing) for a build with no model download. Each hit carries a `pointer`, the `astern show` command that fetches the full record: a hit is an address, not an answer. The shipped `astern-recall` skill drives the whole loop, ending in a briefing written to the repo the question was about.
102
+
103
+ `episodes` — a third grain, consecutive turns on one topic — is deliberately not built yet (issue #7).
104
+
105
+ ## Never spending a token twice
106
+
107
+ Every lens run goes through the **ledger**: one entry per session, keyed on the transcript file's fingerprint (size + mtime) and, per lens, its version and the last turn index it has seen. From that, `ledger.plan()` picks one of three actions:
108
+
109
+ - **skip** — this lens version already covered every turn that exists in the transcript.
110
+ - **incremental** — the session grew (it was resumed); only lenses that declare `incremental=True` get handed just the new turns (`from_index` onward) plus their own prior findings, and extend rather than redo.
111
+ - **full** — never analyzed, or analyzed by an older lens version; everything is reprocessed.
112
+
113
+ A heuristic lens (`kind='H'`) costs nothing, so paying for `full` on every source change is fine. The ledger earns its keep on the LLM lenses (`kind='L'`): a resumed session must not pay again for turns it already paid for, and `astern sync` never re-reads a transcript whose size and mtime it already has on file.
114
+
115
+ ## Where things live
116
+
117
+ The store is `dol`-backed JSON files under `~/.local/share/astern/` (`sessions`, `turns`, `findings`, `ledger`, `judgments`) — override with `$ASTERN_DATA_DIR` to keep an experiment out of the real store. The transcripts it reads come from `~/.claude` by default — override with `$ASTERN_HOME` to point at a second account or a synced copy of another machine's home. Both are seams: any `MutableMapping` serves as a store, and `homes()` takes a single dir, an iterable of dirs, or `None`.
118
+
119
+ ## The seams
120
+
121
+ Five things in astern are deliberately swappable, each with a strong out-of-the-box default and a named replacement:
122
+
123
+ | Seam | v1 default | Replacement |
124
+ |---|---|---|
125
+ | `home=` — which `~/.claude`-shaped dirs to read | the one `~/.claude` | a second account, or the server's home over a sync |
126
+ | `store=` — where records and findings live | `dol` JSON files under `~/.local/share/astern/` | any `MutableMapping` — S3, SQLite, a dict for tests |
127
+ | `judge=` — the LLM callable for `L` lenses | the local `claude` CLI, headless, no session persisted | `aix.prompt_func` for API billing; a recorded-replay judge for tests |
128
+ | `similar=` — how findings group across sessions | normalized-string near match | `ir` corpus + embeddings, for real semantic clustering |
129
+ | `turns=` — the transcript-to-turns fetcher | astern's own `openloops`-backed iterator | `priv.claude_transcripts.turn_pair_records` by injection |
130
+ | `embedder=` — how `astern index` embeds | `ir`'s local `all-MiniLM-L6-v2` (offline, no key) | `light` (numpy-only), or any embedder spec `ir` understands |
131
+
132
+ What's deliberately **not** a seam: the lens registry (a module-level dict), report templates, the finding dict shape, and the `openloops.egress` scrub step on every sink — none of these are meant to vary.
133
+
134
+ ## Not in astern
135
+
136
+ - **Live sessions** — that's `crowsnest`'s axis (*this minute*), not astern's (*the wake*).
137
+ - **Obligation tracking** — what's owed, blocked, or open — that's `openloops`.
138
+ - **Transcript viewers, full-text search, cost dashboards** — `claude-code-log`, `cc-transcript`, `episodic-memory` and `ccusage` already do these well; install them alongside astern rather than rebuilding them here.
139
+ - **Writing into `CLAUDE.md`, skills, or memory.** Every lens emits *candidates* — mined skill/rule/function/memory suggestions — for a human to accept through `skill`, `opsward`, `coact`, or `ge.memory`. Nothing here writes automatically; that's the same "report, never repair" invariant `priv upkeep` carries.
140
+
141
+ ## Development
142
+
143
+ ```bash
144
+ pip install -e ".[dev]"
145
+ pytest -q # the test suite
146
+ pytest --doctest-modules astern # every module's own doctest
147
+ ```
astern-0.0.6/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # astern
2
+
3
+ `crowsnest` watches the sessions running right now; `astern` looks back at the wake they left — the transcripts Claude Code already keeps under `~/.claude/projects/`. It mines them for what problems recur, where agents get stuck, what one-off code keeps being rewritten, and which words you and your agents don't share, without spending a token twice.
4
+
5
+ ## Start here
6
+
7
+ ```bash
8
+ pip install astern
9
+
10
+ astern sync # read new or changed transcripts, run the free (heuristic) lenses
11
+ astern sessions # what's synced, newest first
12
+ astern show <sid-prefix> # one session: meta, ledger state, last turns, findings
13
+ astern report friction # (in progress) a lens's findings as a markdown report
14
+ astern judge # (in progress) run the LLM-judged lenses over what's synced
15
+ astern estimate # (in progress) token/cost estimate before a judge batch runs
16
+
17
+ pip install "astern[recall]" # + ir, for searching what past sessions already know
18
+ astern index # index the store into ir corpora (idempotent)
19
+ astern recall "what did we decide about the ledger" # ...and ask it
20
+ astern install-skills # link the shipped skills into ~/.claude/skills
21
+ ```
22
+
23
+ `sync`, `sessions` and `show` are shipped today. `report`, `judge` and `estimate` are being built out by other agents against the same store and ledger; once they land, the one-command loop is `astern sync && astern judge && astern report friction`.
24
+
25
+ ## What it extracts
26
+
27
+ Each **lens** asks one question of a session and returns typed, evidence-backed findings — every finding points back at the turn it came from. Method: **H** = deterministic heuristic, zero tokens; **L** = LLM-judged, spends subscription tokens via the local `claude` CLI; **H→L** = a heuristic shortlist that only the survivors get judged on.
28
+
29
+ | Lens | Question | Method |
30
+ |---|---|---|
31
+ | `stats` | The shape of a session in numbers — the cost model's own features | H |
32
+ | `problems` | What problem was each session solving, and how was it solved? | L |
33
+ | `recurring` | Which problems recur, and would a skill or subagent pay for itself? | H over L |
34
+ | `rewrites` | What one-off code keeps being rewritten? | H→L |
35
+ | `friction` | Where do agents get stuck, and what would remove the obstacle? | H→L |
36
+ | `jargon-in` | Which of my phrasings point to an established term I don't use? | L |
37
+ | `jargon-out` | Which terms do agents use that I don't? | H→L |
38
+ | `corrections` | What did I correct or re-affirm, and which corrections repeat? | H→L |
39
+ | `prompt-quality` | Which prompt shapes lead to clean turns, which to flailing ones? | H→L |
40
+ | `cost` | Where do the tokens and hours go, by project / task / model? | H |
41
+ | `timeline` | What did I work on this week, and what landed? | H→L |
42
+ | `decisions` | Which decisions were made, and why? | L |
43
+ | `claims` | Where did an agent claim "done" and a later turn show otherwise? | H→L |
44
+ | `questions` | What do agents keep asking me, and what did I answer? | H→L |
45
+ | `tooling` | Which skills/subagents/MCP tools are used, unused, or missing? | H |
46
+ | `memory-candidates` | Which restated facts should become memory, and where does memory drift? | H→L |
47
+ | `evals` | Which (prompt, outcome) pairs make a regression test for a skill? | H |
48
+ | `hygiene` | Do agents read before they edit, and does that change over time? | H |
49
+ | `regression` | Did the harness or model change behaviour? | H |
50
+ | `adherence` | Which CLAUDE.md/skill rules are followed, ignored, or fought? | L |
51
+ | `subagents` | Which subagent / `Workflow` spawns paid for themselves? | H |
52
+ | `effect` | Did an adopted rule, skill or function reduce the pattern it targeted? | H |
53
+
54
+ Session handoffs (`Q`) are deliberately not a lens here — that's `openloops`, linked rather than re-derived. The full catalogue, with the signal each lens reads and the sink it feeds, is plan §2 (see "The seams" below).
55
+
56
+ ## Recall — what past sessions already know
57
+
58
+ `astern recall "<query>"` answers *what did we already think, try and decide about X* without re-reading a transcript. astern is only the **record source** here: `ir` owns the indexing and the search, and the multi-hop search loop belongs to `raglab`. Install the extra (`pip install "astern[recall]"`), run `astern index` after a `sync`, and ask.
59
+
60
+ Two grains, indexed as two `ir` corpora because they answer different questions:
61
+
62
+ | Corpus | One record is | Best for |
63
+ |---|---|---|
64
+ | `session_synopses` | a whole session as the `synopsis` lens distilled it — goal, problems and solutions, decisions, corrections | **what was decided** |
65
+ | `session_turns` | one turn: the prompt and the assistant's closing text | **what was actually tried** |
66
+
67
+ Unfiltered, a recall also reaches the `skills` and `reports` corpora when this machine has them (weighted below the sessions, so they inform rather than crowd out). `--project X` and `--since-days N` are hard metadata filters; a project is resolved *through the store* into its session ids, because a session about a project often runs from a group dir or a worktree whose name says nothing about it.
68
+
69
+ Embedding is local and offline: ir's `all-MiniLM-L6-v2` by default — **no API key, no per-query cost** — with `--embedder light` (numpy-only hashing) for a build with no model download. Each hit carries a `pointer`, the `astern show` command that fetches the full record: a hit is an address, not an answer. The shipped `astern-recall` skill drives the whole loop, ending in a briefing written to the repo the question was about.
70
+
71
+ `episodes` — a third grain, consecutive turns on one topic — is deliberately not built yet (issue #7).
72
+
73
+ ## Never spending a token twice
74
+
75
+ Every lens run goes through the **ledger**: one entry per session, keyed on the transcript file's fingerprint (size + mtime) and, per lens, its version and the last turn index it has seen. From that, `ledger.plan()` picks one of three actions:
76
+
77
+ - **skip** — this lens version already covered every turn that exists in the transcript.
78
+ - **incremental** — the session grew (it was resumed); only lenses that declare `incremental=True` get handed just the new turns (`from_index` onward) plus their own prior findings, and extend rather than redo.
79
+ - **full** — never analyzed, or analyzed by an older lens version; everything is reprocessed.
80
+
81
+ A heuristic lens (`kind='H'`) costs nothing, so paying for `full` on every source change is fine. The ledger earns its keep on the LLM lenses (`kind='L'`): a resumed session must not pay again for turns it already paid for, and `astern sync` never re-reads a transcript whose size and mtime it already has on file.
82
+
83
+ ## Where things live
84
+
85
+ The store is `dol`-backed JSON files under `~/.local/share/astern/` (`sessions`, `turns`, `findings`, `ledger`, `judgments`) — override with `$ASTERN_DATA_DIR` to keep an experiment out of the real store. The transcripts it reads come from `~/.claude` by default — override with `$ASTERN_HOME` to point at a second account or a synced copy of another machine's home. Both are seams: any `MutableMapping` serves as a store, and `homes()` takes a single dir, an iterable of dirs, or `None`.
86
+
87
+ ## The seams
88
+
89
+ Five things in astern are deliberately swappable, each with a strong out-of-the-box default and a named replacement:
90
+
91
+ | Seam | v1 default | Replacement |
92
+ |---|---|---|
93
+ | `home=` — which `~/.claude`-shaped dirs to read | the one `~/.claude` | a second account, or the server's home over a sync |
94
+ | `store=` — where records and findings live | `dol` JSON files under `~/.local/share/astern/` | any `MutableMapping` — S3, SQLite, a dict for tests |
95
+ | `judge=` — the LLM callable for `L` lenses | the local `claude` CLI, headless, no session persisted | `aix.prompt_func` for API billing; a recorded-replay judge for tests |
96
+ | `similar=` — how findings group across sessions | normalized-string near match | `ir` corpus + embeddings, for real semantic clustering |
97
+ | `turns=` — the transcript-to-turns fetcher | astern's own `openloops`-backed iterator | `priv.claude_transcripts.turn_pair_records` by injection |
98
+ | `embedder=` — how `astern index` embeds | `ir`'s local `all-MiniLM-L6-v2` (offline, no key) | `light` (numpy-only), or any embedder spec `ir` understands |
99
+
100
+ What's deliberately **not** a seam: the lens registry (a module-level dict), report templates, the finding dict shape, and the `openloops.egress` scrub step on every sink — none of these are meant to vary.
101
+
102
+ ## Not in astern
103
+
104
+ - **Live sessions** — that's `crowsnest`'s axis (*this minute*), not astern's (*the wake*).
105
+ - **Obligation tracking** — what's owed, blocked, or open — that's `openloops`.
106
+ - **Transcript viewers, full-text search, cost dashboards** — `claude-code-log`, `cc-transcript`, `episodic-memory` and `ccusage` already do these well; install them alongside astern rather than rebuilding them here.
107
+ - **Writing into `CLAUDE.md`, skills, or memory.** Every lens emits *candidates* — mined skill/rule/function/memory suggestions — for a human to accept through `skill`, `opsward`, `coact`, or `ge.memory`. Nothing here writes automatically; that's the same "report, never repair" invariant `priv upkeep` carries.
108
+
109
+ ## Development
110
+
111
+ ```bash
112
+ pip install -e ".[dev]"
113
+ pytest -q # the test suite
114
+ pytest --doctest-modules astern # every module's own doctest
115
+ ```
@@ -0,0 +1,26 @@
1
+ """astern — look astern: mine your past Claude Code sessions.
2
+
3
+ The crow's nest (``crowsnest``) watches the sessions that are running now; astern
4
+ looks back at the wake they left. It reads the transcripts Claude Code already writes,
5
+ keeps its own store of turns and findings, and answers, without spending tokens twice:
6
+ what problems recur, where agents get stuck, what one-off code keeps being rewritten,
7
+ what words you and your agents do not share.
8
+
9
+ Core contract: :mod:`astern.tools` (plain functions, JSON in, JSON out) over
10
+ :mod:`astern.sources` → :mod:`astern.turns` → :mod:`astern.store` with
11
+ :mod:`astern.ledger` deciding what still needs analyzing, :mod:`astern.lenses`
12
+ answering the questions, and :mod:`astern.judge` the one LLM seam.
13
+ """
14
+
15
+ from astern.judge import Judgment, claude_judge, replay_judge # noqa: F401
16
+ from astern.lenses import LENSES, finding, lens # noqa: F401
17
+ from astern.store import MemoryStore, Store, mk_store # noqa: F401
18
+ from astern.tools import install_skills, lenses, sessions, show, sync # noqa: F401
19
+
20
+ # `recall` and `index` are deliberately NOT re-exported here: binding them on the
21
+ # package would shadow the :mod:`astern.recall` module, and `import astern.recall
22
+ # as r` would then hand back a *function* — a trap that fails much later than it
23
+ # is made. Reach them as `from astern.recall import recall, index` (or through
24
+ # :mod:`astern.tools`, which is what the CLI dispatches).
25
+
26
+ __version__ = "0.0.1"
@@ -0,0 +1,13 @@
1
+ """``astern`` command line: ``cw`` over the functions :mod:`astern.tools` exposes."""
2
+
3
+ import cw
4
+
5
+ from astern.tools import _dispatch_funcs
6
+
7
+
8
+ def main():
9
+ raise SystemExit(cw.dispatch(_dispatch_funcs))
10
+
11
+
12
+ if __name__ == "__main__":
13
+ main()
File without changes
@@ -0,0 +1,115 @@
1
+ ---
2
+ name: astern-recall
3
+ description: >-
4
+ Search past Claude Code sessions for what was already thought, tried and
5
+ decided about a topic, and write the answer up as a briefing. Use when the
6
+ user asks "what did we decide about X", "what did I already try for X", "did
7
+ we ever look at X", "why did we do X that way", "catch me up on project X",
8
+ "what happened last time I worked on X", or "before I start on X, what do past
9
+ sessions say" — and use it proactively at the start of work on a project the
10
+ user has not touched in weeks, before re-deriving a decision that a past
11
+ session already made. Runs astern's mined session store (sync → index →
12
+ recall) through the `ir` retrieval substrate; reads the few hits that matter
13
+ with `astern show`; writes `docs/briefings/<date>-<slug>.md` in the repo the
14
+ question is about. Read-only with respect to the sessions themselves.
15
+ metadata:
16
+ audience: developers
17
+ ---
18
+
19
+ # astern recall — what past sessions already know
20
+
21
+ Transcripts are the only honest record of why a project is the way it is, and nobody re-reads them. `astern` mines them into a store; this skill turns that store into an answer.
22
+
23
+ **What it is not**: a chat log search. A hit is an *address*, not an answer — the procedure below ends with you reading the top hits and writing a briefing, because the value is in the synthesis, not in the ranked list.
24
+
25
+ ## Prerequisites (check once, cheap)
26
+
27
+ ```bash
28
+ astern sessions --limit 3 # is anything synced at all?
29
+ ```
30
+
31
+ If that errors on an import, the retrieval extra is missing: `pip install "astern[recall]"` (it pulls `ir`, `ef`, `vd`). No API key is needed — the default embedder is local and offline.
32
+
33
+ ## Procedure
34
+
35
+ ### 1. Sync and index (both idempotent — run them, don't ask)
36
+
37
+ ```bash
38
+ astern sync # read new/changed transcripts into the store
39
+ astern index # build the ir corpora (only what changed is embedded)
40
+ ```
41
+
42
+ `sync` reads only transcripts whose size/mtime changed; `index` embeds only records whose content hash changed. Running both costs seconds when nothing moved. Do not skip `index` after a `sync`: an index built yesterday answers confidently about a corpus that no longer matches.
43
+
44
+ ### 2. Recall
45
+
46
+ ```bash
47
+ astern recall "how do we keep the miner from re-judging a resumed session"
48
+ astern recall "what did we decide about the judge and json schema retries" --project astern
49
+ astern recall "vector store backend choice" --project vd --since-days 120 --k 12
50
+ ```
51
+
52
+ Flags: `--project` (matched against the session's project/cwd), `--since-days`, `--k` (how many hits), `--grains session_synopses|session_turns` (default both), `--mode dense|lexical|hybrid` (default hybrid).
53
+
54
+ Two grains answer different questions, and it is worth naming which you want:
55
+
56
+ | Grain | One record is | Best for |
57
+ |---|---|---|
58
+ | `session_synopses` | a whole session, LLM-distilled: goal, problems and their solutions, decisions, corrections | **what was decided**, what the session was for |
59
+ | `session_turns` | one turn: the prompt and the assistant's closing text | **what was actually tried**, the specific error, the exact command |
60
+
61
+ Unfiltered, recall also reaches the `skills` and `reports` corpora when this machine has them — often the fastest route to an existing skill or a written-up report. A `--project` or `--since-days` filter deliberately excludes those two (they carry no project or timestamp metadata); the result's `notes` says so.
62
+
63
+ If `abstained` is true or the hits look unrelated, **reformulate rather than reporting nothing**: try the vocabulary a session would have used (an error message, a file name, a command) and `--mode lexical` for identifier-heavy queries. Two or three query shapes is normal; that loop is your job, not the tool's.
64
+
65
+ ### 3. Read the hits that matter
66
+
67
+ Every hit carries a `pointer` — run it:
68
+
69
+ ```bash
70
+ astern show <session_id> # the session's meta + its last turns
71
+ astern show <session_id> --turns 40 # more of the turn history
72
+ ```
73
+
74
+ Read the top 3–6. A synopsis hit tells you a decision was made; the turns tell you what it actually was and whether it stuck. Where they disagree, the turns win — a synopsis is a summary, and later turns may have reversed it.
75
+
76
+ ### 4. Write the briefing
77
+
78
+ Write to **the repo the question is about** (not astern's), at `docs/briefings/<YYYY-MM-DD>-<slug>.md`. Create the directory if it does not exist. Then tell the user the path.
79
+
80
+ Rules for the file:
81
+
82
+ - **No hard-wrapped prose.** One line per paragraph or list item — newlines only where markdown is structural.
83
+ - **Cite every claim**: the session id (first 8 chars is enough) and the date. A briefing whose claims cannot be traced back is a rumour.
84
+ - **Separate what was DECIDED from what was merely TRIED.** This is the whole point. A decision is something the user stated or ratified; an experiment an agent ran and abandoned is not a decision, however confidently the transcript reads.
85
+ - **Say what you did not find.** An absence ("no session discusses the S3 backend") is a finding, and it is what stops the reader from assuming you looked and hid it.
86
+
87
+ Shape:
88
+
89
+ ```markdown
90
+ # <Topic> — what past sessions say
91
+
92
+ _Briefing written <date> from N sessions between <first> and <last>. Sources: astern session ids, cited inline._
93
+
94
+ ## Decided
95
+
96
+ - <the decision>, stated in `a1b2c3d4` (2026-07-14) and unchanged since.
97
+
98
+ ## Tried, not settled
99
+
100
+ - <the approach>, attempted in `e5f6a7b8` (2026-08-02); abandoned after <what happened>.
101
+
102
+ ## Open questions
103
+
104
+ - <what nobody answered>
105
+
106
+ ## Not found
107
+
108
+ - <what you searched for and did not find, with the queries you used>
109
+ ```
110
+
111
+ ## Notes
112
+
113
+ - **Never paste real transcript content into a public artifact** (an issue, a PR, a committed doc that leaves the machine) without checking it for secrets and absolute home paths. A briefing is a local doc; keep it that way unless the user says otherwise.
114
+ - The store is per-machine. A second Claude home (`~/.claude-*`) is just another source to `astern sync`; a session that lives only on another machine is invisible here, and "not found" means "not found on this machine".
115
+ - `episodes` — a third grain, consecutive turns on one topic — does not exist yet (thorwhalen/astern#7). Until it does, a topic that spans many turns is best reached through `session_synopses` first, then read in full with `astern show`.