sessionmemory 0.19.0__tar.gz → 0.21.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 (54) hide show
  1. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/PKG-INFO +33 -2
  2. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/README.md +32 -1
  3. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/pyproject.toml +7 -12
  4. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/pyproject.toml.orig +8 -8
  5. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/cli.py +49 -7
  6. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/_common.py +16 -0
  7. sessionmemory-0.21.0/src/sessionmemory/commands/doctor.py +66 -0
  8. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/local.py +6 -3
  9. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/reconcile.py +43 -13
  10. sessionmemory-0.21.0/src/sessionmemory/commands/reindex.py +125 -0
  11. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/search.py +5 -32
  12. sessionmemory-0.21.0/src/sessionmemory/lib/agent_skill.md +212 -0
  13. sessionmemory-0.21.0/src/sessionmemory/lib/agentguide.py +29 -0
  14. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/backlog.py +1 -1
  15. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/commits.py +91 -27
  16. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/doctor.py +84 -17
  17. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/fieldindex.py +181 -71
  18. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/inject.py +5 -1
  19. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/localmd.py +55 -27
  20. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/reconcile.py +65 -27
  21. sessionmemory-0.19.0/src/sessionmemory/commands/doctor.py +0 -27
  22. sessionmemory-0.19.0/src/sessionmemory/commands/reindex.py +0 -64
  23. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/__init__.py +0 -0
  24. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/__init__.py +0 -0
  25. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/delete.py +0 -0
  26. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/export.py +0 -0
  27. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/init.py +0 -0
  28. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/inject.py +0 -0
  29. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/log.py +0 -0
  30. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/new.py +0 -0
  31. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/path.py +0 -0
  32. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/commands/project.py +0 -0
  33. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/entry.py +0 -0
  34. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/__init__.py +0 -0
  35. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/atomic.py +0 -0
  36. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/bootstrap.py +0 -0
  37. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/changes.py +0 -0
  38. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/config.py +0 -0
  39. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/embed.py +0 -0
  40. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/export.py +0 -0
  41. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/field.py +0 -0
  42. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/frontmatter.py +0 -0
  43. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/gitinfo.py +0 -0
  44. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/ids.py +0 -0
  45. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/localdeclined.py +0 -0
  46. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/localmanifest.py +0 -0
  47. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/localtree.py +0 -0
  48. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/log.py +0 -0
  49. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/paths.py +0 -0
  50. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/registration.py +0 -0
  51. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/registry.py +0 -0
  52. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/resolve.py +0 -0
  53. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/settingsdiff.py +0 -0
  54. {sessionmemory-0.19.0 → sessionmemory-0.21.0}/src/sessionmemory/lib/specs.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sessionmemory
3
- Version: 0.19.0
3
+ Version: 0.21.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>
@@ -240,7 +240,11 @@ all for a script.
240
240
  `sessionmemory new backlog --kind <kind> --size <S|M|L> --title "..." --topic <topic> --cwd .`,
241
241
  which writes that shape and creates the file or heading when missing. Keep the
242
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 `$`. Questions for
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
244
248
  the user to answer go under `## decide`. Delete a finished item with its detail,
245
249
  and one that will never be done, directly; never tick or annotate it. Git history is the record of what was finished.
246
250
  - Specs: `specs/` holds one design record per feature, named `<date>-<topic>.md`
@@ -331,6 +335,33 @@ to the same block, so that each session reads the guidance itself:
331
335
  `sessionmemory inject --cwd .` and follow the guidance it prints.
332
336
  ```
333
337
 
338
+ ## Get an agent's help with the vault
339
+
340
+ An AI agent can do the upkeep of the vault for you: fix what `sessionmemory doctor`
341
+ reports, clean up projects whose repository is gone, and keep the private files in step
342
+ with each checkout. To start, print a prompt and paste it into the agent:
343
+
344
+ ```bash
345
+ sessionmemory --prompt
346
+ ```
347
+
348
+ ```
349
+ Help me manage my sessionmemory vault.
350
+
351
+ 1. Run `sessionmemory --skill` and read all of it. It explains how the vault works and how to manage it.
352
+ 2. Run `sessionmemory doctor --json`.
353
+ 3. Give me a brief overview of the vault's state: its projects, and what doctor found in each.
354
+ 4. Ask me what I want help with, and offer a few suggestions based on what you found.
355
+
356
+ Ask me before you delete, move, or overwrite anything.
357
+ ```
358
+
359
+ `sessionmemory --skill` prints the guide that the agent reads. It explains the layout of
360
+ the vault, the registry, the commands, the fix for each `doctor` finding, and the rules
361
+ the agent obeys. One rule is that the agent asks you before it deletes, moves, or
362
+ overwrites a file. The guide covers the whole vault. If the agent starts in a registered
363
+ project, it asks whether to work on that project or on the whole vault.
364
+
334
365
  ## Documentation
335
366
 
336
367
  | Page | What it covers |
@@ -225,7 +225,11 @@ all for a script.
225
225
  `sessionmemory new backlog --kind <kind> --size <S|M|L> --title "..." --topic <topic> --cwd .`,
226
226
  which writes that shape and creates the file or heading when missing. Keep the
227
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 `$`. Questions for
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
229
233
  the user to answer go under `## decide`. Delete a finished item with its detail,
230
234
  and one that will never be done, directly; never tick or annotate it. Git history is the record of what was finished.
231
235
  - Specs: `specs/` holds one design record per feature, named `<date>-<topic>.md`
@@ -316,6 +320,33 @@ to the same block, so that each session reads the guidance itself:
316
320
  `sessionmemory inject --cwd .` and follow the guidance it prints.
317
321
  ```
318
322
 
323
+ ## Get an agent's help with the vault
324
+
325
+ An AI agent can do the upkeep of the vault for you: fix what `sessionmemory doctor`
326
+ reports, clean up projects whose repository is gone, and keep the private files in step
327
+ with each checkout. To start, print a prompt and paste it into the agent:
328
+
329
+ ```bash
330
+ sessionmemory --prompt
331
+ ```
332
+
333
+ ```
334
+ Help me manage my sessionmemory vault.
335
+
336
+ 1. Run `sessionmemory --skill` and read all of it. It explains how the vault works and how to manage it.
337
+ 2. Run `sessionmemory doctor --json`.
338
+ 3. Give me a brief overview of the vault's state: its projects, and what doctor found in each.
339
+ 4. Ask me what I want help with, and offer a few suggestions based on what you found.
340
+
341
+ Ask me before you delete, move, or overwrite anything.
342
+ ```
343
+
344
+ `sessionmemory --skill` prints the guide that the agent reads. It explains the layout of
345
+ the vault, the registry, the commands, the fix for each `doctor` finding, and the rules
346
+ the agent obeys. One rule is that the agent asks you before it deletes, moves, or
347
+ overwrites a file. The guide covers the whole vault. If the agent starts in a registered
348
+ project, it asks whether to work on that project or on the whole vault.
349
+
319
350
  ## Documentation
320
351
 
321
352
  | Page | What it covers |
@@ -11,7 +11,7 @@ description = "Durable memory for coding agents, one folder of searchable pages
11
11
  name = "sessionmemory"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.13,<3.15"
14
- version = "0.19.0"
14
+ version = "0.21.0"
15
15
 
16
16
  [[project.authors]]
17
17
  name = "Nathaniel Landau"
@@ -25,7 +25,7 @@ dev = [
25
25
  "commitizen>=4.19.3",
26
26
  "coverage>=7.17.3",
27
27
  "duty>=1.10.1",
28
- "gate-cache>=0.7.0",
28
+ "gate-cache>=0.9.0",
29
29
  "prek>=0.5.11",
30
30
  "pytest-clarity>=1.0.1",
31
31
  "pytest-cov>=7.1.0",
@@ -36,7 +36,7 @@ dev = [
36
36
  "rich>=15.0.0",
37
37
  "ruff>=0.17.5",
38
38
  "shellcheck-py>=0.11.0.1",
39
- "ty>=0.0.104",
39
+ "ty>=0.0.105",
40
40
  "types-pyyaml>=6.0.12.20261113",
41
41
  "typos>=1.52.2",
42
42
  "yamllint>=1.38.0",
@@ -61,7 +61,7 @@ exclude_lines = [
61
61
  "if TYPE_CHECKING",
62
62
  "pragma: no cover",
63
63
  ]
64
- fail_under = 95
64
+ fail_under = 90
65
65
  show_missing = true
66
66
  skip_covered = true
67
67
  skip_empty = true
@@ -85,19 +85,14 @@ source = [
85
85
  output = ".cache/coverage.xml"
86
86
 
87
87
  [tool.pytest.ini_options]
88
- addopts = "--color=yes --doctest-modules --strict-config --strict-markers -n auto --dist loadfile"
88
+ addopts = "--color=yes -n auto --dist worksteal"
89
89
  cache_dir = ".cache/pytest"
90
90
  cli_runner_patch_result = true
91
91
  columns = 1000
92
- filterwarnings = [
93
- "error",
94
- "ignore:.*Pydantic.*:UserWarning",
95
- "ignore::DeprecationWarning:",
96
- ]
97
- markers = ["serial"]
92
+ filterwarnings = ["error"]
98
93
  set_columns = true
94
+ strict = true
99
95
  testpaths = ["tests"]
100
- xfail_strict = true
101
96
 
102
97
  [tool.ruff]
103
98
  exclude = [
@@ -12,7 +12,7 @@
12
12
  name = "sessionmemory"
13
13
  readme = "README.md"
14
14
  requires-python = ">=3.13,<3.15"
15
- version = "0.19.0"
15
+ version = "0.21.0"
16
16
 
17
17
  [project.scripts]
18
18
  sessionmemory = "sessionmemory.entry:main"
@@ -22,7 +22,7 @@
22
22
  "commitizen>=4.19.3",
23
23
  "coverage>=7.17.3",
24
24
  "duty>=1.10.1",
25
- "gate-cache>=0.7.0",
25
+ "gate-cache>=0.9.0",
26
26
  "prek>=0.5.11",
27
27
  "pytest-clarity>=1.0.1",
28
28
  "pytest-cov>=7.1.0",
@@ -33,7 +33,7 @@
33
33
  "rich>=15.0.0",
34
34
  "ruff>=0.17.5",
35
35
  "shellcheck-py>=0.11.0.1",
36
- "ty>=0.0.104",
36
+ "ty>=0.0.105",
37
37
  "types-pyyaml>=6.0.12.20261113",
38
38
  "typos>=1.52.2",
39
39
  "yamllint>=1.38.0",
@@ -58,7 +58,7 @@
58
58
  'if TYPE_CHECKING',
59
59
  'pragma: no cover',
60
60
  ]
61
- fail_under = 95
61
+ fail_under = 90
62
62
  show_missing = true
63
63
  skip_covered = true
64
64
  skip_empty = true
@@ -82,15 +82,15 @@
82
82
 
83
83
  [tool.pytest.ini_options]
84
84
 
85
- addopts = "--color=yes --doctest-modules --strict-config --strict-markers -n auto --dist loadfile"
85
+ # worksteal rebalances the tail, so one slow file never pins the run to one worker
86
+ addopts = "--color=yes -n auto --dist worksteal"
86
87
  cache_dir = ".cache/pytest"
87
88
  cli_runner_patch_result = true
88
89
  columns = 1000
89
- filterwarnings = ['error', 'ignore:.*Pydantic.*:UserWarning', 'ignore::DeprecationWarning:']
90
- markers = ["serial"]
90
+ filterwarnings = ["error"]
91
91
  set_columns = true
92
+ strict = true
92
93
  testpaths = ["tests"]
93
- xfail_strict = true
94
94
 
95
95
  [tool.ruff] # https://github.com/charliermarsh/ruff
96
96
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from typing import TYPE_CHECKING
6
+
5
7
  import typer
6
8
 
7
9
  from sessionmemory.commands import delete as delete_commands
@@ -19,6 +21,9 @@ from sessionmemory.commands import reindex as reindex_commands
19
21
  from sessionmemory.commands import search as search_commands
20
22
  from sessionmemory.commands._common import VersionedGroup, emit_value
21
23
 
24
+ if TYPE_CHECKING:
25
+ from collections.abc import Callable
26
+
22
27
  app = typer.Typer(
23
28
  cls=VersionedGroup,
24
29
  no_args_is_help=True,
@@ -33,13 +38,36 @@ MAINTENANCE = "Maintenance"
33
38
  PLUGIN = "Plugin internals"
34
39
 
35
40
 
36
- def _print_version(value: bool) -> None: # noqa: FBT001
37
- """Print the installed version bare and exit, for a caller that compares it."""
38
- if value:
39
- import importlib.metadata
41
+ def _version() -> str:
42
+ import importlib.metadata
43
+
44
+ return importlib.metadata.version("sessionmemory")
45
+
46
+
47
+ def _agent_skill() -> str:
48
+ from sessionmemory.lib import agentguide
49
+
50
+ return agentguide.skill()
51
+
52
+
53
+ def _agent_prompt() -> str:
54
+ from sessionmemory.lib import agentguide
55
+
56
+ return agentguide.PROMPT
57
+
40
58
 
41
- emit_value(importlib.metadata.version("sessionmemory"))
42
- raise typer.Exit
59
+ def _print_and_exit(text: Callable[[], str]) -> Callable[[bool], None]:
60
+ """Build an eager root option's callback that prints one bare value and exits.
61
+
62
+ The value is computed only when the flag is given, so an unused flag costs no import.
63
+ """
64
+
65
+ def callback(value: bool) -> None: # noqa: FBT001
66
+ if value:
67
+ emit_value(text())
68
+ raise typer.Exit
69
+
70
+ return callback
43
71
 
44
72
 
45
73
  @app.callback()
@@ -47,10 +75,24 @@ def _root(
47
75
  version: bool = typer.Option( # noqa: FBT001
48
76
  False, # noqa: FBT003
49
77
  "--version",
50
- callback=_print_version,
78
+ callback=_print_and_exit(_version),
51
79
  is_eager=True,
52
80
  help="Print the version and exit.",
53
81
  ),
82
+ skill: bool = typer.Option( # noqa: FBT001
83
+ False, # noqa: FBT003
84
+ "--skill",
85
+ callback=_print_and_exit(_agent_skill),
86
+ is_eager=True,
87
+ help="Print a guide that teaches an AI agent to manage the vault, and exit.",
88
+ ),
89
+ prompt: bool = typer.Option( # noqa: FBT001
90
+ False, # noqa: FBT003
91
+ "--prompt",
92
+ callback=_print_and_exit(_agent_prompt),
93
+ is_eager=True,
94
+ help="Print a prompt to paste into an AI agent for help managing the vault, and exit.",
95
+ ),
54
96
  ) -> None:
55
97
  """Manage a project's memory in a vault of markdown pages."""
56
98
 
@@ -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,66 @@
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
+ AGENT_HINT = "For an AI agent's help, paste the output of: sessionmemory --prompt"
21
+
22
+
23
+ def _print_report(vault: Path, findings: list[doctor.Finding]) -> None:
24
+ """Print findings grouped under a heading per project, each with its message below its path.
25
+
26
+ The message sits on its own line rather than in a column, so a long path never squeezes
27
+ it and nothing is cut at a narrow terminal. Vault findings come first, then projects by
28
+ slug, each keeping the checks' order.
29
+ """
30
+ console = pp.console()
31
+ check_width = max(len(finding.check) for finding in findings)
32
+ ordered = sorted(findings, key=lambda finding: finding.project)
33
+ for project, group in groupby(ordered, key=lambda finding: finding.project):
34
+ grid = Table.grid(padding=(0, 2))
35
+ grid.add_column(style="cyan", no_wrap=True, min_width=check_width)
36
+ grid.add_column(overflow="fold")
37
+ for finding in group:
38
+ path = doctor.short_path(vault, finding)
39
+ cell = (
40
+ Text.assemble((path, "bold"), "\n", finding.message)
41
+ if path
42
+ else Text(finding.message)
43
+ )
44
+ grid.add_row(Text(finding.check), cell)
45
+ console.print(Text(project or VAULT_GROUP, style="bold underline"))
46
+ console.print(Padding(grid, (0, 0, 0, 2), expand=False))
47
+
48
+
49
+ def doctor_command(*, as_json: bool = JSON_OPTION) -> None:
50
+ """Report pages, projects, and indexes worth a look. Always exits 0."""
51
+ vault = require_vault()
52
+ findings = doctor.run(vault, build_embedder())
53
+ if as_json:
54
+ emit_json(
55
+ [
56
+ {"check": f.check, "path": f.path, "message": f.message, "project": f.project}
57
+ for f in findings
58
+ ]
59
+ )
60
+ return
61
+ if not findings:
62
+ pp.success("nothing to report")
63
+ return
64
+ pp.info(f"{len(findings)} suggestion{'s' if len(findings) != 1 else ''}")
65
+ _print_report(vault, findings)
66
+ pp.info(AGENT_HINT)
@@ -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
  ]
@@ -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
 
@@ -57,21 +88,20 @@ def reconcile_command(
57
88
  "dropped": report.dropped,
58
89
  "in_progress": report.in_progress,
59
90
  "unchecked": report.unchecked,
60
- "notes": report.notes,
91
+ "notes": list(report.notes),
92
+ "note_logs": report.notes,
61
93
  }
62
94
  for report in reports
63
95
  ]
64
96
  )
65
97
  return
66
98
 
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)
99
+ pp.console().print(_report(reports))
100
+ verb = "would change" if dry_run else "changed"
101
+ for report in reports:
102
+ if report.changed:
103
+ pp.info(f"{report.name} {verb}", details=[path.name for path in report.changed])
104
+ for note, logs in report.notes.items():
105
+ pp.warning(f"{report.name}: {note}", details=logs)
106
+ if dry_run:
107
+ pp.dryrun("no log was rewritten")
@@ -0,0 +1,125 @@
1
+ """The `reindex` command: rebuild a project's indexes from its pages."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import asdict
6
+ from pathlib import Path # noqa: TC003
7
+
8
+ import typer
9
+ from nclutils import pp
10
+ from rich.table import Table
11
+ from rich.text import Text
12
+
13
+ from sessionmemory.commands._common import (
14
+ CWD_OPTION,
15
+ JSON_OPTION,
16
+ build_embedder,
17
+ count_cell,
18
+ emit_json,
19
+ fail,
20
+ require_project,
21
+ require_vault,
22
+ )
23
+ from sessionmemory.lib import fieldindex, paths
24
+
25
+ ALL = typer.Option(False, "--all", help="Reindex every project in the vault.") # noqa: FBT003
26
+
27
+ COUNT_STYLES = {"added": "green", "updated": "yellow", "removed": "red", "unchanged": ""}
28
+
29
+
30
+ def _changed(counts: fieldindex.Refresh) -> bool:
31
+ """Return whether a refresh added, updated, or removed any page."""
32
+ return bool(counts.added or counts.updated or counts.removed)
33
+
34
+
35
+ def _report(rows: list[tuple[str, str, fieldindex.Refresh]], *, show_project: bool) -> Table:
36
+ """Lay out each field's counts as a grid, with column totals in the footer.
37
+
38
+ Args:
39
+ rows: One `(project, field, counts)` triple per field, in display order.
40
+ show_project: Whether to lead with a project column, naming each project once.
41
+
42
+ Returns:
43
+ The table to print.
44
+ """
45
+ table = Table(box=None, pad_edge=False, header_style="bold", show_footer=True)
46
+ if show_project:
47
+ table.add_column("project", footer="total")
48
+ table.add_column("field", footer="" if show_project else "total")
49
+ for column, style in COUNT_STYLES.items():
50
+ total = sum(getattr(counts, column) for *_, counts in rows)
51
+ table.add_column(column, justify="right", footer=count_cell(total, style))
52
+
53
+ previous = None
54
+ for project, field, counts in rows:
55
+ cells = [count_cell(getattr(counts, c), style) for c, style in COUNT_STYLES.items()]
56
+ lead = [Text(project if project != previous else "")] if show_project else []
57
+ table.add_row(*lead, Text(field), *cells)
58
+ previous = project
59
+ return table
60
+
61
+
62
+ def _print_vault_report(rows: list[tuple[str, str, fieldindex.Refresh]]) -> None:
63
+ """Print the grid for the projects a refresh changed, then count the rest.
64
+
65
+ A large vault's full grid outgrows the terminal, so a project with nothing to refresh
66
+ is only counted.
67
+
68
+ Args:
69
+ rows: One `(project, field, counts)` triple per field, in display order.
70
+ """
71
+ changed = {slug for slug, _, counts in rows if _changed(counts)}
72
+ current = len({slug for slug, *_ in rows} - changed)
73
+ if changed:
74
+ pp.console().print(_report([r for r in rows if r[0] in changed], show_project=True))
75
+ if current:
76
+ noun = "project" if current == 1 else "projects"
77
+ prefix = "all " if not changed and current > 1 else ""
78
+ pp.info(f"{prefix}{current} {noun} already up to date", style="default")
79
+
80
+
81
+ def reindex_command(
82
+ cwd: Path | None = CWD_OPTION, *, all_projects: bool = ALL, as_json: bool = JSON_OPTION
83
+ ) -> None:
84
+ """Bring this project's learnings, logs, and specs indexes up to date, or every project's.
85
+
86
+ Raises:
87
+ Exit: When `--all` is combined with `--cwd`.
88
+ """
89
+ vault = require_vault()
90
+ if all_projects:
91
+ if cwd is not None:
92
+ fail("--all and --cwd are mutually exclusive", ["pass one or the other"])
93
+ fields = [
94
+ (directory.parent.name, directory.name, directory)
95
+ for directory in paths.iter_index_dirs(vault)
96
+ ]
97
+ else:
98
+ slug = require_project(vault, cwd)
99
+ fields = [(slug, directory.name, directory) for directory in paths.index_dirs(vault, slug)]
100
+ embedder = build_embedder()
101
+
102
+ if as_json:
103
+ payload: dict[str, dict] = {}
104
+ for slug, name, directory in fields:
105
+ counts = asdict(fieldindex.refresh(directory, embedder))
106
+ if all_projects:
107
+ payload.setdefault(slug, {})[name] = counts
108
+ else:
109
+ payload[name] = counts
110
+ emit_json(payload)
111
+ return
112
+
113
+ if not fields:
114
+ pp.info("no fields to reindex")
115
+ return
116
+
117
+ rows = []
118
+ with pp.console().status("reindexing") as status:
119
+ for slug, name, directory in fields:
120
+ status.update(Text(f"reindexing {slug}/{name}"))
121
+ rows.append((slug, name, fieldindex.refresh(directory, embedder)))
122
+ if all_projects:
123
+ _print_vault_report(rows)
124
+ else:
125
+ pp.console().print(_report(rows, show_project=False))