sessionmemory 0.14.0__tar.gz → 0.15.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 (49) hide show
  1. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/PKG-INFO +4 -4
  2. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/README.md +3 -3
  3. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/pyproject.toml +1 -1
  4. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/pyproject.toml.orig +1 -1
  5. sessionmemory-0.15.0/src/sessionmemory/cli.py +101 -0
  6. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/_common.py +3 -1
  7. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/export.py +9 -5
  8. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/inject.py +10 -3
  9. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/local.py +129 -65
  10. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/log.py +3 -3
  11. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/new.py +19 -9
  12. sessionmemory-0.15.0/src/sessionmemory/commands/path.py +66 -0
  13. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/project.py +76 -32
  14. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/reconcile.py +8 -3
  15. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/reindex.py +2 -2
  16. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/search.py +12 -7
  17. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/doctor.py +81 -1
  18. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/field.py +12 -2
  19. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/inject.py +2 -2
  20. sessionmemory-0.15.0/src/sessionmemory/lib/localmanifest.py +267 -0
  21. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/localmd.py +277 -33
  22. sessionmemory-0.14.0/src/sessionmemory/cli.py +0 -87
  23. sessionmemory-0.14.0/src/sessionmemory/commands/path.py +0 -44
  24. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/__init__.py +0 -0
  25. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/__init__.py +0 -0
  26. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/delete.py +0 -0
  27. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/doctor.py +0 -0
  28. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/commands/init.py +0 -0
  29. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/__init__.py +0 -0
  30. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/atomic.py +0 -0
  31. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/backlog.py +0 -0
  32. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/bootstrap.py +0 -0
  33. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/changes.py +0 -0
  34. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/commits.py +0 -0
  35. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/config.py +0 -0
  36. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/embed.py +0 -0
  37. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/export.py +0 -0
  38. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/fieldindex.py +0 -0
  39. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/frontmatter.py +0 -0
  40. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/gitinfo.py +0 -0
  41. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/ids.py +0 -0
  42. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/localtree.py +0 -0
  43. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/log.py +0 -0
  44. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/paths.py +0 -0
  45. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/reconcile.py +0 -0
  46. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/registry.py +0 -0
  47. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/resolve.py +0 -0
  48. {sessionmemory-0.14.0 → sessionmemory-0.15.0}/src/sessionmemory/lib/settingsdiff.py +0 -0
  49. {sessionmemory-0.14.0 → sessionmemory-0.15.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.14.0
3
+ Version: 0.15.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>
@@ -145,7 +145,7 @@ yourself, run the command once:
145
145
 
146
146
  ```bash
147
147
  cd ~/repos/invoice-api
148
- sessionmemory project --register --cwd .
148
+ sessionmemory project register --cwd .
149
149
  ```
150
150
 
151
151
  ```
@@ -221,8 +221,8 @@ loaded for you: the titles are what the vault holds, and each is one `sessionmem
221
221
  away. The project's folder has `learnings/` and `logs/`, searched by meaning, beside
222
222
  `specs/`, `runbooks/`, `reference/`, and `backlog.md`, which are ordinary files you Read
223
223
  and Edit. `sessionmemory path <kind>` prints one path, where kind is project, learnings,
224
- logs, specs, runbooks, reference, or backlog; `sessionmemory project --json` prints
225
- them all for a script.
224
+ logs, specs, runbooks, reference, or backlog; `sessionmemory path --json` prints them
225
+ all for a script.
226
226
 
227
227
  - Before assuming nothing was written down, search: `sessionmemory search "<words>"`
228
228
  prints each hit's path, title, and summary, and `--read` prints every hit's whole
@@ -130,7 +130,7 @@ yourself, run the command once:
130
130
 
131
131
  ```bash
132
132
  cd ~/repos/invoice-api
133
- sessionmemory project --register --cwd .
133
+ sessionmemory project register --cwd .
134
134
  ```
135
135
 
136
136
  ```
@@ -206,8 +206,8 @@ loaded for you: the titles are what the vault holds, and each is one `sessionmem
206
206
  away. The project's folder has `learnings/` and `logs/`, searched by meaning, beside
207
207
  `specs/`, `runbooks/`, `reference/`, and `backlog.md`, which are ordinary files you Read
208
208
  and Edit. `sessionmemory path <kind>` prints one path, where kind is project, learnings,
209
- logs, specs, runbooks, reference, or backlog; `sessionmemory project --json` prints
210
- them all for a script.
209
+ logs, specs, runbooks, reference, or backlog; `sessionmemory path --json` prints them
210
+ all for a script.
211
211
 
212
212
  - Before assuming nothing was written down, search: `sessionmemory search "<words>"`
213
213
  prints each hit's path, title, and summary, and `--read` prints every hit's whole
@@ -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.14.0"
14
+ version = "0.15.0"
15
15
 
16
16
  [[project.authors]]
17
17
  name = "Nathaniel Landau"
@@ -12,7 +12,7 @@
12
12
  name = "sessionmemory"
13
13
  readme = "README.md"
14
14
  requires-python = ">=3.13,<3.15"
15
- version = "0.14.0"
15
+ version = "0.15.0"
16
16
 
17
17
  [project.scripts]
18
18
  sessionmemory = "sessionmemory.cli:main"
@@ -0,0 +1,101 @@
1
+ """Session memory CLI invoked as `sessionmemory` by a user."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import importlib.metadata
6
+
7
+ import typer
8
+
9
+ from sessionmemory.commands import delete as delete_commands
10
+ from sessionmemory.commands import doctor as doctor_commands
11
+ from sessionmemory.commands import export as export_commands
12
+ from sessionmemory.commands import init as init_commands
13
+ from sessionmemory.commands import inject as inject_commands
14
+ from sessionmemory.commands import local as local_commands
15
+ from sessionmemory.commands import log as log_commands
16
+ from sessionmemory.commands import new as new_commands
17
+ from sessionmemory.commands import path as path_commands
18
+ from sessionmemory.commands import project
19
+ from sessionmemory.commands import reconcile as reconcile_commands
20
+ from sessionmemory.commands import reindex as reindex_commands
21
+ from sessionmemory.commands import search as search_commands
22
+ from sessionmemory.commands._common import VersionedGroup, emit_value
23
+
24
+ app = typer.Typer(
25
+ cls=VersionedGroup,
26
+ no_args_is_help=True,
27
+ context_settings={"help_option_names": ["-h", "--help"]},
28
+ )
29
+
30
+ # Panels order the top-level help by who runs a command, so a newcomer reads the
31
+ # everyday commands first and the plugin's plumbing last.
32
+ EVERYDAY = "Everyday"
33
+ SETUP = "Setup"
34
+ MAINTENANCE = "Maintenance"
35
+ PLUGIN = "Plugin internals"
36
+
37
+
38
+ def _print_version(value: bool) -> None: # noqa: FBT001
39
+ """Print the installed version bare and exit, for a caller that compares it."""
40
+ if value:
41
+ emit_value(importlib.metadata.version("sessionmemory"))
42
+ raise typer.Exit
43
+
44
+
45
+ @app.callback()
46
+ def _root(
47
+ version: bool = typer.Option( # noqa: FBT001
48
+ False, # noqa: FBT003
49
+ "--version",
50
+ callback=_print_version,
51
+ is_eager=True,
52
+ help="Print the version and exit.",
53
+ ),
54
+ ) -> None:
55
+ """Manage a project's memory in a vault of markdown pages."""
56
+
57
+
58
+ app.command(
59
+ "search", help="Search learnings by meaning, or logs or specs.", rich_help_panel=EVERYDAY
60
+ )(search_commands.search_command)
61
+ app.add_typer(new_commands.app, name="new", rich_help_panel=EVERYDAY)
62
+ app.command("path", help="Print this project's vault paths.", rich_help_panel=EVERYDAY)(
63
+ path_commands.path_command
64
+ )
65
+ app.command("delete", help="Delete files from the vault permanently.", rich_help_panel=EVERYDAY)(
66
+ delete_commands.delete_command
67
+ )
68
+ app.command("init", help="Create the files a new vault needs.", rich_help_panel=SETUP)(
69
+ init_commands.init
70
+ )
71
+ app.add_typer(project.app, name="project", rich_help_panel=SETUP)
72
+ app.add_typer(local_commands.app, name="local", rich_help_panel=SETUP)
73
+ app.command(
74
+ "doctor", help="Report pages, projects, and indexes worth a look.", rich_help_panel=MAINTENANCE
75
+ )(doctor_commands.doctor_command)
76
+ app.command(
77
+ "reindex",
78
+ help="Rebuild this project's search indexes, or every project's.",
79
+ rich_help_panel=MAINTENANCE,
80
+ )(reindex_commands.reindex_command)
81
+ app.command(
82
+ "reconcile",
83
+ help="Update this project's session logs to match the commits on its default branch.",
84
+ rich_help_panel=MAINTENANCE,
85
+ )(reconcile_commands.reconcile_command)
86
+ app.command(
87
+ "export",
88
+ help="Write this project's learnings or logs as a .memoryfield.zip.",
89
+ rich_help_panel=MAINTENANCE,
90
+ )(export_commands.export_command)
91
+ app.command("inject", help="Print the block a session starts with.", rich_help_panel=PLUGIN)(
92
+ inject_commands.inject_command
93
+ )
94
+ app.command(
95
+ "log", help="Write this session's log page, replacing its body.", rich_help_panel=PLUGIN
96
+ )(log_commands.log_command)
97
+
98
+
99
+ def main() -> None:
100
+ """Run the CLI. This is the console script entry point."""
101
+ app()
@@ -33,6 +33,8 @@ if TYPE_CHECKING:
33
33
 
34
34
  EMBEDDER_ENV_VAR = "SESSIONMEMORY_EMBEDDER"
35
35
 
36
+ CWD_OPTION = typer.Option(None, "--cwd", "-C", help="Directory to resolve the project from.")
37
+
36
38
 
37
39
  # The two ways to name the vault, offered together whenever neither is set.
38
40
  VAULT_FIX = [
@@ -257,7 +259,7 @@ def require_project(vault: Path, cwd: Path | None = None) -> str:
257
259
  if not result.registered or result.slug is None:
258
260
  pp.error(
259
261
  "this directory is not a registered project",
260
- details=["run: sessionmemory project --register"],
262
+ details=["run: sessionmemory project register"],
261
263
  )
262
264
  raise typer.Exit(1)
263
265
  return result.slug
@@ -1,4 +1,4 @@
1
- """The `export` command: write a project's field as a .memoryfield.zip."""
1
+ """The `export` command: write a project's learnings or logs as a .memoryfield.zip."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -8,6 +8,7 @@ import typer
8
8
  from nclutils import pp
9
9
 
10
10
  from sessionmemory.commands._common import (
11
+ CWD_OPTION,
11
12
  build_embedder,
12
13
  emit_json,
13
14
  fail,
@@ -16,24 +17,27 @@ from sessionmemory.commands._common import (
16
17
  )
17
18
  from sessionmemory.lib import export, field, paths
18
19
 
19
- CWD = typer.Option(None, "--cwd", help="Directory to resolve the project from.")
20
20
  LOGS = typer.Option(False, "--logs", help="Export the logs field instead of learnings.") # noqa: FBT003
21
21
  OUTPUT = typer.Option(
22
22
  None,
23
23
  "--output",
24
- help="Where to write the zip. Defaults to <slug>.memoryfield.zip in the current directory.",
24
+ "-o",
25
+ help=(
26
+ "Where to write the zip. Defaults to <slug>.memoryfield.zip in the current "
27
+ "directory, which is usually the checkout."
28
+ ),
25
29
  )
26
30
  JSON = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
27
31
 
28
32
 
29
33
  def export_command(
30
- cwd: Path | None = CWD,
34
+ cwd: Path | None = CWD_OPTION,
31
35
  *,
32
36
  logs: bool = LOGS,
33
37
  output: Path | None = OUTPUT,
34
38
  as_json: bool = JSON,
35
39
  ) -> None:
36
- """Write this project's field as a .memoryfield.zip."""
40
+ """Write this project's learnings, or its logs, as a .memoryfield.zip."""
37
41
  vault = require_vault()
38
42
  slug = require_project(vault, cwd)
39
43
  embedder = build_embedder()
@@ -6,15 +6,22 @@ from pathlib import Path # noqa: TC003
6
6
 
7
7
  import typer
8
8
 
9
- from sessionmemory.commands._common import emit_json, emit_value, require_project, require_vault
9
+ from sessionmemory.commands._common import (
10
+ CWD_OPTION,
11
+ emit_json,
12
+ emit_value,
13
+ require_project,
14
+ require_vault,
15
+ )
10
16
  from sessionmemory.lib import inject
11
17
 
12
- CWD = typer.Option(None, "--cwd", help="Directory to resolve the project from.")
13
18
  COMMAND = typer.Option("sessionmemory", "--command", help="How the guidance names this CLI.")
14
19
  JSON = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
15
20
 
16
21
 
17
- def inject_command(cwd: Path | None = CWD, command: str = COMMAND, *, as_json: bool = JSON) -> None:
22
+ def inject_command(
23
+ cwd: Path | None = CWD_OPTION, command: str = COMMAND, *, as_json: bool = JSON
24
+ ) -> None:
18
25
  """Print what this project's session should start with."""
19
26
  vault = require_vault()
20
27
  slug = require_project(vault, cwd)
@@ -12,6 +12,7 @@ import typer
12
12
  from nclutils import ask, pp
13
13
 
14
14
  from sessionmemory.commands._common import (
15
+ CWD_OPTION,
15
16
  VersionedGroup,
16
17
  emit_json,
17
18
  emit_value,
@@ -19,23 +20,22 @@ from sessionmemory.commands._common import (
19
20
  require_project,
20
21
  require_vault,
21
22
  )
22
- from sessionmemory.lib import localmd, paths
23
+ from sessionmemory.lib import localmanifest, localmd, paths
23
24
 
24
25
  app = typer.Typer(
25
26
  cls=VersionedGroup,
26
27
  no_args_is_help=True,
27
- help=(
28
- "Keep this project's CLAUDE.local.md, private skills and rules, and "
29
- "settings.local.json in the vault and sync them with checkouts."
30
- ),
28
+ help="Keep private files such as CLAUDE.local.md in the vault and sync them to checkouts.",
31
29
  )
32
30
 
33
- CWD = typer.Option(None, "--cwd", help="Directory to resolve the project from.")
34
31
  JSON = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
35
32
  ADOPT = typer.Option(
36
33
  None,
37
34
  "--adopt",
38
- help="Adopt an entry: CLAUDE.local.md, skills/<name>, or rules/<name>. Repeatable.",
35
+ help=(
36
+ "Adopt an entry: CLAUDE.local.md, skills/<name>, rules/<name>, or a path to any "
37
+ "file or folder in this checkout. Repeatable."
38
+ ),
39
39
  show_default=False,
40
40
  )
41
41
  KEEP_SETTINGS = typer.Option(
@@ -98,7 +98,6 @@ class _Plan:
98
98
 
99
99
  adopt: list[str] = field(default_factory=list)
100
100
  keep: Side | None = None
101
- refused: bool = False
102
101
 
103
102
 
104
103
  def _pending_settings(
@@ -137,45 +136,71 @@ def _waiting(co: localmd.Checkout, tracked: set[str]) -> tuple[list[localmd.Entr
137
136
  return [], False
138
137
 
139
138
 
140
- def _settings_rows(pending: localmd.SettingsPending) -> list[tuple[str, tuple[str, str]]]:
141
- """Offer one row per side that holds a copy, so a missing side is never chosen."""
142
- rows = []
143
- for side, mtime in (("checkout", pending.checkout_mtime), ("vault", pending.vault_mtime)):
144
- if mtime is not None:
145
- rows.append((f"keep the {side}'s settings.local.json ({mtime})", ("keep", side)))
146
- return rows
139
+ _LEAVE = "No, leave it alone"
147
140
 
148
141
 
149
- def _checklist(waiting: list[localmd.Entry], pending: localmd.SettingsPending | None) -> _Plan:
150
- """Ask the person which pending items to act on, refusing both settings copies at once."""
151
- rows: list[tuple[str, tuple[str, str]]] = [
152
- (f"adopt {item.name}", ("adopt", item.name)) for item in waiting
153
- ]
154
- if pending is not None:
155
- if pending.summary:
156
- pp.info(
157
- "settings.local.json differs from the vault copy", details=list(pending.summary)
158
- )
159
- rows.extend(_settings_rows(pending))
160
- if not rows:
161
- return _Plan()
162
- chosen = (
163
- ask.choose_multiple_from_list(
164
- choices=rows, message="Choose what to adopt or which settings copy to keep"
142
+ def _confirm(question: str, yes: str) -> bool:
143
+ """Ask one yes-or-no question whose answers say what each choice does.
144
+
145
+ Returns:
146
+ bool: True only when the person chose yes; cancelling counts as no.
147
+ """
148
+ return ask.choose_one_from_list(choices=[(yes, "yes"), (_LEAVE, "no")], message=question) == (
149
+ "yes"
150
+ )
151
+
152
+
153
+ def _ask_settings(pending: localmd.SettingsPending) -> Side | None:
154
+ """Ask the one question that fits the settings state, naming what each answer writes.
155
+
156
+ Returns:
157
+ Side | None: The copy to keep, or None to leave both copies alone.
158
+ """
159
+ if pending.state is localmd.CopyState.CHECKOUT_ONLY:
160
+ question = f"Copy {pending.relpath} into the vault?"
161
+ yes = "Yes, copy it into the vault (this checkout keeps its copy)"
162
+ return "checkout" if _confirm(question=question, yes=yes) else None
163
+ if pending.state is localmd.CopyState.VAULT_ONLY:
164
+ question = (
165
+ f"The vault has a {pending.relpath} for this project, but this checkout has none. "
166
+ "Copy it into this checkout?"
167
+ )
168
+ return "vault" if _confirm(question=question, yes="Yes, copy it here") else None
169
+ if pending.summary:
170
+ pp.info(
171
+ f"What each copy of {pending.relpath} has that the other lacks:",
172
+ details=list(pending.summary),
165
173
  )
166
- or []
174
+ choices: list[tuple[str, Side | Literal["neither"]]] = [
175
+ (
176
+ f"This checkout's (modified {pending.checkout_mtime}): copy it over the vault's",
177
+ "checkout",
178
+ ),
179
+ (f"The vault's (modified {pending.vault_mtime}): copy it over this checkout's", "vault"),
180
+ ("Neither: leave both as they are", "neither"),
181
+ ]
182
+ side = ask.choose_one_from_list(
183
+ choices=choices,
184
+ message=f"{pending.relpath} differs between this checkout and the vault. Which copy wins?",
167
185
  )
168
- plan = _Plan(adopt=[name for action, name in chosen if action == "adopt"])
169
- sides = [side for action, side in chosen if action == "keep"]
170
- if len(sides) > 1:
171
- pp.error("both settings copies were chosen, so neither was kept")
172
- plan.refused = True
173
- elif sides:
174
- plan.keep = "checkout" if sides[0] == "checkout" else "vault"
175
- return plan
186
+ return side if side in {"checkout", "vault"} else None
187
+
188
+
189
+ def _ask(waiting: list[localmd.Entry], pending: localmd.SettingsPending | None) -> _Plan:
190
+ """Ask the person about each pending item in turn, one plain question per item."""
191
+ adopt = [
192
+ item.name
193
+ for item in waiting
194
+ if _confirm(
195
+ question=f"Adopt {item.relpath} into the vault?",
196
+ yes="Yes, move it into the vault and link it back here",
197
+ )
198
+ ]
199
+ keep = _ask_settings(pending) if pending is not None else None
200
+ return _Plan(adopt=adopt, keep=keep)
176
201
 
177
202
 
178
- def _entries(co: localmd.Checkout, names: list[str]) -> tuple[list[localmd.Entry], bool]:
203
+ def _entries(co: localmd.Checkout, names: list[str], cwd: Path) -> tuple[list[localmd.Entry], bool]:
179
204
  """Build the link entries a person named, reporting each name that is not one.
180
205
 
181
206
  Returns:
@@ -185,7 +210,7 @@ def _entries(co: localmd.Checkout, names: list[str]) -> tuple[list[localmd.Entry
185
210
  failed = False
186
211
  for name in names:
187
212
  try:
188
- item = localmd.entry(co=co, name=name)
213
+ item = localmd.resolve_adopt(co=co, raw=name, cwd=cwd)
189
214
  except localmd.LocalMdError as err:
190
215
  pp.error(err.message, details=err.details)
191
216
  failed = True
@@ -225,16 +250,24 @@ def _adopt_one(
225
250
 
226
251
 
227
252
  def _adopt_all(
228
- co: localmd.Checkout, names: list[str], tracked: set[str]
253
+ co: localmd.Checkout, names: list[str], tracked: set[str], cwd: Path
229
254
  ) -> tuple[list[localmd.AdoptResult], bool]:
230
255
  """Adopt each named entry, warning once about rule approval.
231
256
 
232
257
  Returns:
233
258
  tuple[list[localmd.AdoptResult], bool]: The adopted entries, and whether any failed.
234
259
  """
235
- items, failed = _entries(co=co, names=names)
260
+ items, failed = _entries(co=co, names=names, cwd=cwd)
236
261
  if not items:
237
262
  return [], failed
263
+ # A path named for the first time is in no listing git was asked about yet.
264
+ try:
265
+ tracked = tracked | localmd.tracked_names(
266
+ co=co, items=[item for item in items if item.kind == "path"]
267
+ )
268
+ except localmd.LocalMdError as err:
269
+ pp.error(err.message, details=err.details)
270
+ return [], True
238
271
  adopted: list[localmd.AdoptResult] = []
239
272
  for item in items:
240
273
  result = _adopt_one(co=co, item=item, tracked=item.name in tracked)
@@ -306,20 +339,31 @@ def _report_pending(waiting: list[localmd.Entry], pending: localmd.SettingsPendi
306
339
  if waiting:
307
340
  adopt = " ".join(f"--adopt {shlex.quote(item.name)}" for item in waiting)
308
341
  pp.warning(
309
- f"not in the vault yet: {', '.join(item.name for item in waiting)}",
310
- details=[f"Adopt them with: sessionmemory local sync {adopt} --cwd ."],
342
+ f"not tracked in the vault yet: {', '.join(item.relpath for item in waiting)}",
343
+ details=[f"Adopt them into the vault with: sessionmemory local sync {adopt} --cwd ."],
311
344
  )
312
- if pending is not None:
313
- details = [*pending.summary]
314
- details.extend(
315
- f"Keep the {side}'s copy with: sessionmemory local sync --keep-settings {side} --cwd ."
316
- for side, mtime in (
317
- ("checkout", pending.checkout_mtime),
318
- ("vault", pending.vault_mtime),
319
- )
320
- if mtime is not None
345
+ if pending is None:
346
+ return
347
+ keep = "sessionmemory local sync --keep-settings {side} --cwd ."
348
+ if pending.state is localmd.CopyState.CHECKOUT_ONLY:
349
+ pp.warning(
350
+ f"{pending.relpath} is not tracked in the vault yet",
351
+ details=[f"Copy it into the vault with: {keep.format(side='checkout')}"],
352
+ )
353
+ elif pending.state is localmd.CopyState.VAULT_ONLY:
354
+ pp.warning(
355
+ f"the vault has a {pending.relpath} that this checkout lacks",
356
+ details=[f"Copy it into this checkout with: {keep.format(side='vault')}"],
357
+ )
358
+ else:
359
+ pp.warning(
360
+ f"{pending.relpath} differs between this checkout and the vault",
361
+ details=[
362
+ *pending.summary,
363
+ f"Copy this checkout's over the vault's with: {keep.format(side='checkout')}",
364
+ f"Copy the vault's over this checkout's with: {keep.format(side='vault')}",
365
+ ],
321
366
  )
322
- pp.warning(f"settings.local.json: {pending.state}", details=details)
323
367
 
324
368
 
325
369
  def _settings_payload(pending: localmd.SettingsPending | None) -> dict[str, object] | None:
@@ -357,6 +401,7 @@ class _Report:
357
401
  kept: Path | None
358
402
  waiting: list[localmd.Entry]
359
403
  pending: localmd.SettingsPending | None
404
+ manifest_problems: tuple[str, ...] = ()
360
405
 
361
406
  def payload(self, plan: _Plan) -> dict[str, object]:
362
407
  """Build the `--json` payload; `adopted` and `settings` only for flags that ran."""
@@ -366,6 +411,7 @@ class _Report:
366
411
  "adopt": [item.name for item in self.waiting],
367
412
  "settings": _settings_payload(self.pending),
368
413
  },
414
+ "manifest_problems": list(self.manifest_problems),
369
415
  }
370
416
  if plan.adopt:
371
417
  payload["adopted"] = [
@@ -391,14 +437,14 @@ class _Report:
391
437
  "sync",
392
438
  help=(
393
439
  "Link the vault's entries into this checkout, then adopt entries and keep a settings "
394
- "copy as asked. With no flags on a terminal, choose from a checklist."
440
+ "copy as asked. With no flags on a terminal, answer one question per pending item."
395
441
  ),
396
442
  )
397
443
  def sync_command(
398
444
  adopt: list[str] | None = ADOPT,
399
445
  keep_settings: Side | None = KEEP_SETTINGS,
400
446
  as_json: bool = JSON, # noqa: FBT001
401
- cwd: Path | None = CWD,
447
+ cwd: Path | None = CWD_OPTION,
402
448
  ) -> None:
403
449
  """Link the vault's entries into this checkout, then adopt and keep settings as asked.
404
450
 
@@ -415,22 +461,31 @@ def sync_command(
415
461
  except OSError as err:
416
462
  fail(f"could not link the entries of {co.worktree}: {err}")
417
463
 
464
+ problems = localmd.manifest(co).problems
465
+ if problems:
466
+ pp.error(
467
+ f"{co.local / localmanifest.MANIFEST_NAME} lists paths that cannot be linked",
468
+ details=[*problems, "Fix the file, then run local sync."],
469
+ )
470
+
418
471
  plan = _Plan(adopt=list(adopt or []), keep=keep_settings)
419
472
  flagged = bool(plan.adopt) or plan.keep is not None
420
473
  waiting, listed = _waiting(co, tracked) if not flagged else ([], True)
421
474
  pending, compared = _pending_settings(co, tracked) if not flagged else (None, True)
422
475
  if not flagged and not as_json and _interactive():
423
- plan = _checklist(waiting=waiting, pending=pending)
476
+ plan = _ask(waiting=waiting, pending=pending)
424
477
 
425
478
  adopted, failed = (
426
- _adopt_all(co=co, names=plan.adopt, tracked=tracked) if plan.adopt else ([], False)
479
+ _adopt_all(co=co, names=plan.adopt, tracked=tracked, cwd=Path.cwd())
480
+ if plan.adopt
481
+ else ([], False)
427
482
  )
428
483
  kept, changed = _keep(co=co, side=plan.keep, tracked=tracked) if plan.keep else (None, False)
429
484
  if any(not result.already_linked for result in adopted) or (
430
485
  changed and plan.keep == "checkout"
431
486
  ):
432
487
  pp.warning("the hooks commit the vault copy to the vault's git remote")
433
- failed = failed or plan.refused or (plan.keep is not None and kept is None)
488
+ failed = failed or (plan.keep is not None and kept is None)
434
489
  # Linking runs first, so an entry adopted by this run was in its way.
435
490
  done = {result.entry.name for result in adopted}
436
491
  results = [r for r in results if not (r.status == "conflict" and r.entry.name in done)]
@@ -438,9 +493,16 @@ def sync_command(
438
493
  if plan.adopt or plan.keep is not None:
439
494
  waiting, listed = _waiting(co, tracked)
440
495
  pending, compared = _pending_settings(co, tracked)
441
- failed = failed or not (listed and compared)
442
-
443
- report = _Report(results=results, adopted=adopted, kept=kept, waiting=waiting, pending=pending)
496
+ failed = failed or not (listed and compared) or bool(problems)
497
+
498
+ report = _Report(
499
+ results=results,
500
+ adopted=adopted,
501
+ kept=kept,
502
+ waiting=waiting,
503
+ pending=pending,
504
+ manifest_problems=problems,
505
+ )
444
506
  if as_json:
445
507
  emit_json(report.payload(plan))
446
508
  else:
@@ -508,7 +570,7 @@ def _settings_row(
508
570
 
509
571
 
510
572
  @app.command("status", help="Report how each of this checkout's entries relates to the vault.")
511
- def status_command(cwd: Path | None = CWD, as_json: bool = JSON) -> None: # noqa: FBT001
573
+ def status_command(cwd: Path | None = CWD_OPTION, as_json: bool = JSON) -> None: # noqa: FBT001
512
574
  """Report how each of this checkout's entries relates to the vault.
513
575
 
514
576
  Raises:
@@ -533,6 +595,8 @@ def status_command(cwd: Path | None = CWD, as_json: bool = JSON) -> None: # noq
533
595
  emit_json({"local": str(co.local), "entries": rows})
534
596
  return
535
597
 
598
+ if not rows:
599
+ emit_value("no local entries in this checkout or the vault")
536
600
  for row in rows:
537
601
  flags = _flags(row)
538
602
  suffix = f" ({', '.join(flags)})" if flags else ""
@@ -1,4 +1,4 @@
1
- """The `log` command: record this session's work in one upserted page."""
1
+ """The `log` command: write this session's one log page, replacing its body."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -8,6 +8,7 @@ from pathlib import Path # noqa: TC003
8
8
  import typer
9
9
 
10
10
  from sessionmemory.commands._common import (
11
+ CWD_OPTION,
11
12
  emit_json,
12
13
  emit_value,
13
14
  fail,
@@ -29,7 +30,6 @@ BODY = typer.Option("", "--body", help="Markdown body. Replaces what is there.")
29
30
  BODY_FILE = typer.Option(None, "--body-file", help="Read the body from a file, or stdin for '-'.")
30
31
  TRANSCRIPT = typer.Option("", "--transcript", help="Path to this session's transcript on disk.")
31
32
  URL = typer.Option("", "--url", help="Where this session can be opened online.")
32
- CWD = typer.Option(None, "--cwd", help="Directory to resolve the project from.")
33
33
  JSON = typer.Option(
34
34
  False, # noqa: FBT003
35
35
  "--json",
@@ -45,7 +45,7 @@ def log_command( # noqa: PLR0913, PLR0917
45
45
  body_file: Path | None = BODY_FILE,
46
46
  transcript: str = TRANSCRIPT,
47
47
  url: str = URL,
48
- cwd: Path | None = CWD,
48
+ cwd: Path | None = CWD_OPTION,
49
49
  *,
50
50
  as_json: bool = JSON,
51
51
  ) -> None: