sessionmemory 0.18.0__tar.gz → 0.20.0__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 (51) hide show
  1. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/PKG-INFO +14 -8
  2. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/README.md +11 -5
  3. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/pyproject.toml +13 -13
  4. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/pyproject.toml.orig +13 -13
  5. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/_common.py +16 -0
  6. sessionmemory-0.20.0/src/sessionmemory/commands/doctor.py +64 -0
  7. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/local.py +6 -3
  8. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/new.py +20 -26
  9. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/reconcile.py +41 -12
  10. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/reindex.py +41 -7
  11. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/backlog.py +135 -15
  12. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/bootstrap.py +3 -2
  13. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/doctor.py +67 -19
  14. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/inject.py +11 -5
  15. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/localmd.py +55 -27
  16. sessionmemory-0.18.0/src/sessionmemory/commands/doctor.py +0 -27
  17. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/__init__.py +0 -0
  18. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/cli.py +0 -0
  19. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/__init__.py +0 -0
  20. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/delete.py +0 -0
  21. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/export.py +0 -0
  22. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/init.py +0 -0
  23. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/inject.py +0 -0
  24. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/log.py +0 -0
  25. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/path.py +0 -0
  26. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/project.py +0 -0
  27. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/commands/search.py +0 -0
  28. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/entry.py +0 -0
  29. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/__init__.py +0 -0
  30. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/atomic.py +0 -0
  31. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/changes.py +0 -0
  32. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/commits.py +0 -0
  33. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/config.py +0 -0
  34. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/embed.py +0 -0
  35. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/export.py +0 -0
  36. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/field.py +0 -0
  37. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/fieldindex.py +0 -0
  38. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/frontmatter.py +0 -0
  39. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/gitinfo.py +0 -0
  40. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/ids.py +0 -0
  41. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/localdeclined.py +0 -0
  42. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/localmanifest.py +0 -0
  43. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/localtree.py +0 -0
  44. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/log.py +0 -0
  45. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/paths.py +0 -0
  46. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/reconcile.py +0 -0
  47. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/registration.py +0 -0
  48. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/registry.py +0 -0
  49. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/resolve.py +0 -0
  50. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/settingsdiff.py +0 -0
  51. {sessionmemory-0.18.0 → sessionmemory-0.20.0}/src/sessionmemory/lib/specs.py +0 -0
@@ -1,15 +1,15 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sessionmemory
3
- Version: 0.18.0
3
+ Version: 0.20.0
4
4
  Summary: Durable memory for coding agents, one folder of searchable pages per project.
5
5
  Author: Nathaniel Landau
6
6
  Author-email: Nathaniel Landau <github@natelandau.com>
7
- Requires-Dist: fastembed>=0.9.0
7
+ Requires-Dist: fastembed>=0.9.1
8
8
  Requires-Dist: nclutils>=4.0.0
9
9
  Requires-Dist: pyyaml>=6.0.3
10
10
  Requires-Dist: sqlite-vec>=0.1.9
11
11
  Requires-Dist: tomli-w>=1.2.0
12
- Requires-Dist: typer>=0.27.3
12
+ Requires-Dist: typer>=0.29.1
13
13
  Requires-Python: >=3.13, <3.15
14
14
  Description-Content-Type: text/markdown
15
15
 
@@ -232,15 +232,21 @@ all for a script.
232
232
  - Past sessions, one page each: `sessionmemory search "<words>" --logs`. Search them
233
233
  for why something was decided, what happened the last time an area changed, or
234
234
  whether a fix was already tried.
235
- - Open work: read `backlog.md`. Any top-level bullet is an open item. Under a
235
+ - Open work: read `backlog.md`. Any top-level bullet is an open item, and the
236
+ indented lines under it are its detail. Under a
236
237
  `## <kind>` heading (feat, fix, refactor, perf, docs, test, build, ci, decide), the
237
238
  full shape is sized S, M, or L: `- [S] <imperative description> - <YYYY-MM-DD> [#topic]`.
238
239
  Add one with
239
240
  `sessionmemory new backlog --kind <kind> --size <S|M|L> --title "..." --topic <topic> --cwd .`,
240
- which writes that shape and creates the file or heading when missing. Questions
241
- for the user to answer go under `## decide`. Delete a finished line, and one
242
- that will never be done, directly; never tick or annotate it. Git history is the
243
- record of what was finished.
241
+ which writes that shape and creates the file or heading when missing. Keep the
242
+ title to one short sentence and pass context (why, where, what was tried) with
243
+ `--detail "..."`, in single quotes when it holds a backtick or `$`. Write the item
244
+ for the user reading it weeks later, who knows the product but not the code and
245
+ never saw this session: say what changes in the product's words, not this
246
+ session's terms or the code's names, and put files and approach in the detail,
247
+ with the reason when it is not obvious. Questions for
248
+ the user to answer go under `## decide`. Delete a finished item with its detail,
249
+ and one that will never be done, directly; never tick or annotate it. Git history is the record of what was finished.
244
250
  - Specs: `specs/` holds one design record per feature, named `<date>-<topic>.md`
245
251
  and kept after the work ships. Before designing or changing a feature, search
246
252
  them: `sessionmemory search "<words>" --specs` (listing the directory works too), so a
@@ -217,15 +217,21 @@ all for a script.
217
217
  - Past sessions, one page each: `sessionmemory search "<words>" --logs`. Search them
218
218
  for why something was decided, what happened the last time an area changed, or
219
219
  whether a fix was already tried.
220
- - Open work: read `backlog.md`. Any top-level bullet is an open item. Under a
220
+ - Open work: read `backlog.md`. Any top-level bullet is an open item, and the
221
+ indented lines under it are its detail. Under a
221
222
  `## <kind>` heading (feat, fix, refactor, perf, docs, test, build, ci, decide), the
222
223
  full shape is sized S, M, or L: `- [S] <imperative description> - <YYYY-MM-DD> [#topic]`.
223
224
  Add one with
224
225
  `sessionmemory new backlog --kind <kind> --size <S|M|L> --title "..." --topic <topic> --cwd .`,
225
- which writes that shape and creates the file or heading when missing. Questions
226
- for the user to answer go under `## decide`. Delete a finished line, and one
227
- that will never be done, directly; never tick or annotate it. Git history is the
228
- record of what was finished.
226
+ which writes that shape and creates the file or heading when missing. Keep the
227
+ title to one short sentence and pass context (why, where, what was tried) with
228
+ `--detail "..."`, in single quotes when it holds a backtick or `$`. Write the item
229
+ for the user reading it weeks later, who knows the product but not the code and
230
+ never saw this session: say what changes in the product's words, not this
231
+ session's terms or the code's names, and put files and approach in the detail,
232
+ with the reason when it is not obvious. Questions for
233
+ the user to answer go under `## decide`. Delete a finished item with its detail,
234
+ and one that will never be done, directly; never tick or annotate it. Git history is the record of what was finished.
229
235
  - Specs: `specs/` holds one design record per feature, named `<date>-<topic>.md`
230
236
  and kept after the work ships. Before designing or changing a feature, search
231
237
  them: `sessionmemory search "<words>" --specs` (listing the directory works too), so a
@@ -1,17 +1,17 @@
1
1
  [project]
2
2
  dependencies = [
3
- "fastembed>=0.9.0",
3
+ "fastembed>=0.9.1",
4
4
  "nclutils>=4.0.0",
5
5
  "pyyaml>=6.0.3",
6
6
  "sqlite-vec>=0.1.9",
7
7
  "tomli-w>=1.2.0",
8
- "typer>=0.27.3",
8
+ "typer>=0.29.1",
9
9
  ]
10
10
  description = "Durable memory for coding agents, one folder of searchable pages per project."
11
11
  name = "sessionmemory"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.13,<3.15"
14
- version = "0.18.0"
14
+ version = "0.20.0"
15
15
 
16
16
  [[project.authors]]
17
17
  name = "Nathaniel Landau"
@@ -22,23 +22,23 @@ sessionmemory = "sessionmemory.entry:main"
22
22
 
23
23
  [dependency-groups]
24
24
  dev = [
25
- "commitizen>=4.19.2",
26
- "coverage>=7.16.2",
25
+ "commitizen>=4.19.3",
26
+ "coverage>=7.17.3",
27
27
  "duty>=1.10.1",
28
- "gate-cache>=0.6.0",
29
- "prek>=0.5.5",
28
+ "gate-cache>=0.8.0",
29
+ "prek>=0.5.11",
30
30
  "pytest-clarity>=1.0.1",
31
31
  "pytest-cov>=7.1.0",
32
32
  "pytest-devtools>=1.3.0",
33
- "pytest-mock>=3.16.0",
33
+ "pytest-mock>=3.17.0",
34
34
  "pytest-xdist>=3.8.0",
35
- "pytest>=9.1.1",
35
+ "pytest>=9.2.0",
36
36
  "rich>=15.0.0",
37
- "ruff>=0.17.0",
37
+ "ruff>=0.17.5",
38
38
  "shellcheck-py>=0.11.0.1",
39
- "ty>=0.0.86",
40
- "types-pyyaml>=6.0.12.20260906",
41
- "typos>=1.51.1",
39
+ "ty>=0.0.105",
40
+ "types-pyyaml>=6.0.12.20261113",
41
+ "typos>=1.52.2",
42
42
  "yamllint>=1.38.0",
43
43
  ]
44
44
 
@@ -1,41 +1,41 @@
1
1
  [project]
2
2
  authors = [{ name = "Nathaniel Landau", email = "github@natelandau.com" }]
3
3
  dependencies = [
4
- "fastembed>=0.9.0",
4
+ "fastembed>=0.9.1",
5
5
  "nclutils>=4.0.0",
6
6
  "pyyaml>=6.0.3",
7
7
  "sqlite-vec>=0.1.9",
8
8
  "tomli-w>=1.2.0",
9
- "typer>=0.27.3",
9
+ "typer>=0.29.1",
10
10
  ]
11
11
  description = "Durable memory for coding agents, one folder of searchable pages per project."
12
12
  name = "sessionmemory"
13
13
  readme = "README.md"
14
14
  requires-python = ">=3.13,<3.15"
15
- version = "0.18.0"
15
+ version = "0.20.0"
16
16
 
17
17
  [project.scripts]
18
18
  sessionmemory = "sessionmemory.entry:main"
19
19
 
20
20
  [dependency-groups]
21
21
  dev = [
22
- "commitizen>=4.19.2",
23
- "coverage>=7.16.2",
22
+ "commitizen>=4.19.3",
23
+ "coverage>=7.17.3",
24
24
  "duty>=1.10.1",
25
- "gate-cache>=0.6.0",
26
- "prek>=0.5.5",
25
+ "gate-cache>=0.8.0",
26
+ "prek>=0.5.11",
27
27
  "pytest-clarity>=1.0.1",
28
28
  "pytest-cov>=7.1.0",
29
29
  "pytest-devtools>=1.3.0",
30
- "pytest-mock>=3.16.0",
30
+ "pytest-mock>=3.17.0",
31
31
  "pytest-xdist>=3.8.0",
32
- "pytest>=9.1.1",
32
+ "pytest>=9.2.0",
33
33
  "rich>=15.0.0",
34
- "ruff>=0.17.0",
34
+ "ruff>=0.17.5",
35
35
  "shellcheck-py>=0.11.0.1",
36
- "ty>=0.0.86",
37
- "types-pyyaml>=6.0.12.20260906",
38
- "typos>=1.51.1",
36
+ "ty>=0.0.105",
37
+ "types-pyyaml>=6.0.12.20261113",
38
+ "typos>=1.52.2",
39
39
  "yamllint>=1.38.0",
40
40
  ]
41
41
 
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING, NoReturn
11
11
  import typer
12
12
  import typer.core
13
13
  from nclutils import pp
14
+ from rich.text import Text
14
15
 
15
16
  # Typer vendors Click, so the `click` package's classes never match its errors.
16
17
  from typer._click import core as click_core
@@ -415,3 +416,18 @@ def require_project(vault: Path, cwd: Path | None = None) -> str:
415
416
  str: The resolved project slug.
416
417
  """
417
418
  return require_registered(vault, cwd)[0]
419
+
420
+
421
+ def count_cell(value: int, style: str) -> Text:
422
+ """Render a count for a report table, styled when non-zero and dimmed when zero.
423
+
424
+ Dimming every zero lets the counts that changed stand out in a wide grid.
425
+
426
+ Args:
427
+ value: The count.
428
+ style: The Rich style for a non-zero count.
429
+
430
+ Returns:
431
+ The styled cell.
432
+ """
433
+ return Text(str(value), style=style if value else "dim")
@@ -0,0 +1,64 @@
1
+ """The `doctor` command: report what is off, never fail over it."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from itertools import groupby
6
+ from typing import TYPE_CHECKING
7
+
8
+ from nclutils import pp
9
+ from rich.padding import Padding
10
+ from rich.table import Table
11
+ from rich.text import Text
12
+
13
+ from sessionmemory.commands._common import JSON_OPTION, build_embedder, emit_json, require_vault
14
+ from sessionmemory.lib import doctor
15
+
16
+ if TYPE_CHECKING:
17
+ from pathlib import Path
18
+
19
+ VAULT_GROUP = "(vault)"
20
+
21
+
22
+ def _print_report(vault: Path, findings: list[doctor.Finding]) -> None:
23
+ """Print findings grouped under a heading per project, each with its message below its path.
24
+
25
+ The message sits on its own line rather than in a column, so a long path never squeezes
26
+ it and nothing is cut at a narrow terminal. Vault findings come first, then projects by
27
+ slug, each keeping the checks' order.
28
+ """
29
+ console = pp.console()
30
+ check_width = max(len(finding.check) for finding in findings)
31
+ ordered = sorted(findings, key=lambda finding: finding.project)
32
+ for project, group in groupby(ordered, key=lambda finding: finding.project):
33
+ grid = Table.grid(padding=(0, 2))
34
+ grid.add_column(style="cyan", no_wrap=True, min_width=check_width)
35
+ grid.add_column(overflow="fold")
36
+ for finding in group:
37
+ path = doctor.short_path(vault, finding)
38
+ cell = (
39
+ Text.assemble((path, "bold"), "\n", finding.message)
40
+ if path
41
+ else Text(finding.message)
42
+ )
43
+ grid.add_row(Text(finding.check), cell)
44
+ console.print(Text(project or VAULT_GROUP, style="bold underline"))
45
+ console.print(Padding(grid, (0, 0, 0, 2), expand=False))
46
+
47
+
48
+ def doctor_command(*, as_json: bool = JSON_OPTION) -> None:
49
+ """Report pages, projects, and indexes worth a look. Always exits 0."""
50
+ vault = require_vault()
51
+ findings = doctor.run(vault, build_embedder())
52
+ if as_json:
53
+ emit_json(
54
+ [
55
+ {"check": f.check, "path": f.path, "message": f.message, "project": f.project}
56
+ for f in findings
57
+ ]
58
+ )
59
+ return
60
+ if not findings:
61
+ pp.success("nothing to report")
62
+ return
63
+ pp.info(f"{len(findings)} suggestion{'s' if len(findings) != 1 else ''}")
64
+ _print_report(vault, findings)
@@ -524,12 +524,14 @@ def _report_links(results: list[localmd.LinkResult]) -> None:
524
524
  elif result.status == "conflict":
525
525
  pp.warning(
526
526
  result.reason or f"{result.entry.name} was not linked",
527
- details=[result.remedy] if result.remedy else [],
527
+ details=[*result.details, *([result.remedy] if result.remedy else [])],
528
528
  )
529
529
  elif result.status == "tracked":
530
- pp.warning(f"{result.entry.link} is tracked by git; the vault copy stays in the vault")
530
+ pp.warning(
531
+ f"{result.entry.relpath} is tracked by git; the vault copy stays in the vault"
532
+ )
531
533
  elif result.status == "removed":
532
- pp.warning(f"removed {result.entry.link}, whose vault entry is gone")
534
+ pp.warning(f"removed {result.entry.relpath}, whose vault entry is gone")
533
535
 
534
536
 
535
537
  def _report_pending(waiting: list[localmd.Entry], pending: localmd.SettingsPending | None) -> None:
@@ -585,6 +587,7 @@ def _link_rows(results: list[localmd.LinkResult]) -> list[dict[str, object]]:
585
587
  "target": str(result.entry.target),
586
588
  "reason": result.reason,
587
589
  "remedy": result.remedy,
590
+ "details": list(result.details),
588
591
  }
589
592
  for result in results
590
593
  ]
@@ -55,6 +55,11 @@ SUPERSEDES = typer.Option(
55
55
  None, "--supersedes", help="The spec this one replaces, by name; it is marked superseded."
56
56
  )
57
57
  TOPIC = typer.Option(None, "--topic", help="A topic tag, without the leading hash.")
58
+ DETAIL = typer.Option(
59
+ None,
60
+ "--detail",
61
+ help="Context written as nested bullets under the item: why, where, what was tried.",
62
+ )
58
63
 
59
64
 
60
65
  def _report(path: Path, title: str, *, as_json: bool, uuid: str | None = None) -> None:
@@ -200,33 +205,13 @@ def new_reference(
200
205
  _new_living_document(paths.reference_dir, title, body, body_file, cwd, as_json=as_json)
201
206
 
202
207
 
203
- def _warn_about_shape(*, in_use: list[str], title: str, topic: str | None) -> None:
204
- """Warn, without blocking the write, about a new topic tag or an overlong description.
205
-
206
- `in_use` is read before the write, since the line just written always carries its own
207
- topic.
208
- """
209
- if topic is not None:
210
- tag = topic.strip().removeprefix("#")
211
- if tag and in_use and tag not in in_use:
212
- pp.warning(
213
- f"#{tag} is a new topic in this backlog",
214
- details=[f"in use: {', '.join(in_use)}"],
215
- )
216
- length = len(title.strip())
217
- if length > backlog.LONG_DESCRIPTION:
218
- pp.warning(
219
- f"the description is {length} characters, over the {backlog.LONG_DESCRIPTION} limit",
220
- details=["keep a line to one sentence and put detail in a spec"],
221
- )
222
-
223
-
224
208
  @app.command("backlog", help="Add one open item to this project's backlog.md.")
225
209
  def new_backlog(
226
210
  kind: Kind = KIND,
227
211
  size: Size = SIZE,
228
212
  title: str = DESCRIPTION,
229
213
  topic: str | None = TOPIC,
214
+ detail: str | None = DETAIL,
230
215
  cwd: Path | None = CWD_OPTION,
231
216
  *,
232
217
  as_json: bool = JSON_OPTION,
@@ -241,13 +226,22 @@ def new_backlog(
241
226
  path = paths.backlog_path(vault, slug)
242
227
  in_use = backlog.topics(path)
243
228
  try:
244
- line = backlog.add_item(
245
- path, kind=kind.value, size=size.value, description=title, topic=topic, today=today()
229
+ block = backlog.add_item(
230
+ path,
231
+ kind=kind.value,
232
+ size=size.value,
233
+ description=title,
234
+ topic=topic,
235
+ today=today(),
236
+ detail=detail,
246
237
  )
247
238
  except backlog.BacklogError as error:
248
239
  fail(str(error))
249
- _warn_about_shape(in_use=in_use, title=title, topic=topic)
240
+ for warning in backlog.shape_warnings(
241
+ in_use=in_use, description=title, topic=topic, detail=detail
242
+ ):
243
+ pp.warning(warning.message, details=[warning.advice])
250
244
  if as_json:
251
- emit_json({"path": str(path), "line": line})
245
+ emit_json({"path": str(path), "line": block[0], "detail": block[1:]})
252
246
  return
253
- emit_value(f"{line}\n{path}")
247
+ emit_value("\n".join([*block, str(path)]))
@@ -2,14 +2,18 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from contextlib import nullcontext
5
6
  from pathlib import Path # noqa: TC003
6
7
 
7
8
  import typer
8
9
  from nclutils import pp
10
+ from rich.table import Table
11
+ from rich.text import Text
9
12
 
10
13
  from sessionmemory.commands._common import (
11
14
  CWD_OPTION,
12
15
  JSON_OPTION,
16
+ count_cell,
13
17
  emit_json,
14
18
  fail,
15
19
  require_registered,
@@ -25,6 +29,30 @@ DRY_RUN = typer.Option(
25
29
  )
26
30
 
27
31
 
32
+ COUNT_STYLES = {
33
+ "replaced": "green",
34
+ "dropped": "red",
35
+ "in_progress": "cyan",
36
+ "unchecked": "yellow",
37
+ }
38
+
39
+
40
+ def _report(reports: list[reconcile.Report]) -> Table:
41
+ """Lay out each reconciler's counts as one row of a grid."""
42
+ table = Table(box=None, pad_edge=False, header_style="bold")
43
+ table.add_column("reconciler")
44
+ table.add_column("logs changed", justify="right")
45
+ for column in COUNT_STYLES:
46
+ table.add_column(column.replace("_", " "), justify="right")
47
+ for report in reports:
48
+ table.add_row(
49
+ Text(report.name),
50
+ count_cell(len(report.changed), "bold"),
51
+ *(count_cell(getattr(report, column), style) for column, style in COUNT_STYLES.items()),
52
+ )
53
+ return table
54
+
55
+
28
56
  def reconcile_command(
29
57
  cwd: Path | None = CWD_OPTION, *, dry_run: bool = DRY_RUN, as_json: bool = JSON_OPTION
30
58
  ) -> None:
@@ -42,8 +70,11 @@ def reconcile_command(
42
70
  )
43
71
  except reconcile.ContextError as error:
44
72
  fail(error.message, error.details)
73
+ # The spinner stays off the --json path so no escape sequence reaches the payload.
74
+ progress = nullcontext() if as_json else pp.console().status("reconciling")
45
75
  try:
46
- reports = reconcile.run(context, dry_run=dry_run)
76
+ with progress:
77
+ reports = reconcile.run(context, dry_run=dry_run)
47
78
  except CommitsError as error:
48
79
  fail("git could not answer for this project", [str(error)])
49
80
 
@@ -64,14 +95,12 @@ def reconcile_command(
64
95
  )
65
96
  return
66
97
 
67
- prefix = "(dry run) " if dry_run else ""
68
- with pp.step(f"{prefix}reconciling") as step:
69
- for report in reports:
70
- count = len(report.changed)
71
- step.sub(
72
- f"{report.name}: {count} log{'s' if count != 1 else ''} changed, {report.replaced} "
73
- f"replaced, {report.dropped} dropped, {report.in_progress} in progress, "
74
- f"{report.unchecked} unchecked"
75
- )
76
- for note in report.notes:
77
- step.sub(note)
98
+ pp.console().print(_report(reports))
99
+ verb = "would change" if dry_run else "changed"
100
+ for report in reports:
101
+ if report.changed:
102
+ pp.info(f"{report.name} {verb}", details=[path.name for path in report.changed])
103
+ for note in report.notes:
104
+ pp.warning(f"{report.name}: {note}")
105
+ if dry_run:
106
+ pp.dryrun("no log was rewritten")
@@ -7,11 +7,14 @@ from pathlib import Path # noqa: TC003
7
7
 
8
8
  import typer
9
9
  from nclutils import pp
10
+ from rich.table import Table
11
+ from rich.text import Text
10
12
 
11
13
  from sessionmemory.commands._common import (
12
14
  CWD_OPTION,
13
15
  JSON_OPTION,
14
16
  build_embedder,
17
+ count_cell,
15
18
  emit_json,
16
19
  fail,
17
20
  require_project,
@@ -21,6 +24,35 @@ from sessionmemory.lib import fieldindex, paths
21
24
 
22
25
  ALL = typer.Option(False, "--all", help="Reindex every project in the vault.") # noqa: FBT003
23
26
 
27
+ COUNT_STYLES = {"added": "green", "updated": "yellow", "removed": "red", "unchanged": ""}
28
+
29
+
30
+ def _report(rows: list[tuple[str, str, fieldindex.Refresh]], *, show_project: bool) -> Table:
31
+ """Lay out each field's counts as a grid, with column totals in the footer.
32
+
33
+ Args:
34
+ rows: One `(project, field, counts)` triple per field, in display order.
35
+ show_project: Whether to lead with a project column, naming each project once.
36
+
37
+ Returns:
38
+ The table to print.
39
+ """
40
+ table = Table(box=None, pad_edge=False, header_style="bold", show_footer=True)
41
+ if show_project:
42
+ table.add_column("project", footer="total")
43
+ table.add_column("field", footer="" if show_project else "total")
44
+ for column, style in COUNT_STYLES.items():
45
+ total = sum(getattr(counts, column) for *_, counts in rows)
46
+ table.add_column(column, justify="right", footer=count_cell(total, style))
47
+
48
+ previous = None
49
+ for project, field, counts in rows:
50
+ cells = [count_cell(getattr(counts, c), style) for c, style in COUNT_STYLES.items()]
51
+ lead = [Text(project if project != previous else "")] if show_project else []
52
+ table.add_row(*lead, Text(field), *cells)
53
+ previous = project
54
+ return table
55
+
24
56
 
25
57
  def reindex_command(
26
58
  cwd: Path | None = CWD_OPTION, *, all_projects: bool = ALL, as_json: bool = JSON_OPTION
@@ -54,11 +86,13 @@ def reindex_command(
54
86
  emit_json(payload)
55
87
  return
56
88
 
57
- with pp.step("reindexing") as step:
89
+ if not fields:
90
+ pp.info("no fields to reindex")
91
+ return
92
+
93
+ rows = []
94
+ with pp.console().status("reindexing") as status:
58
95
  for slug, name, directory in fields:
59
- result = fieldindex.refresh(directory, embedder)
60
- label = f"{slug}/{name}" if all_projects else name
61
- step.sub(
62
- f"{label}: {result.added} added, {result.updated} updated, "
63
- f"{result.removed} removed, {result.unchanged} unchanged"
64
- )
96
+ status.update(Text(f"reindexing {slug}/{name}"))
97
+ rows.append((slug, name, fieldindex.refresh(directory, embedder)))
98
+ pp.console().print(_report(rows, show_project=all_projects))