sessionmemory 0.17.0__tar.gz → 0.18.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 (50) hide show
  1. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/PKG-INFO +1 -1
  2. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/pyproject.toml +1 -1
  3. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/pyproject.toml.orig +1 -1
  4. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/local.py +13 -5
  5. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/doctor.py +11 -8
  6. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/gitinfo.py +2 -2
  7. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/localmd.py +225 -55
  8. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/registry.py +23 -0
  9. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/resolve.py +9 -2
  10. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/README.md +0 -0
  11. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/__init__.py +0 -0
  12. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/cli.py +0 -0
  13. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/__init__.py +0 -0
  14. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/_common.py +0 -0
  15. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/delete.py +0 -0
  16. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/doctor.py +0 -0
  17. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/export.py +0 -0
  18. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/init.py +0 -0
  19. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/inject.py +0 -0
  20. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/log.py +0 -0
  21. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/new.py +0 -0
  22. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/path.py +0 -0
  23. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/project.py +0 -0
  24. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/reconcile.py +0 -0
  25. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/reindex.py +0 -0
  26. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/search.py +0 -0
  27. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/entry.py +0 -0
  28. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/__init__.py +0 -0
  29. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/atomic.py +0 -0
  30. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/backlog.py +0 -0
  31. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/bootstrap.py +0 -0
  32. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/changes.py +0 -0
  33. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/commits.py +0 -0
  34. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/config.py +0 -0
  35. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/embed.py +0 -0
  36. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/export.py +0 -0
  37. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/field.py +0 -0
  38. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/fieldindex.py +0 -0
  39. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/frontmatter.py +0 -0
  40. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/ids.py +0 -0
  41. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/inject.py +0 -0
  42. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/localdeclined.py +0 -0
  43. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/localmanifest.py +0 -0
  44. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/localtree.py +0 -0
  45. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/log.py +0 -0
  46. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/paths.py +0 -0
  47. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/reconcile.py +0 -0
  48. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/registration.py +0 -0
  49. {sessionmemory-0.17.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/settingsdiff.py +0 -0
  50. {sessionmemory-0.17.0 → sessionmemory-0.18.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.17.0
3
+ Version: 0.18.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>
@@ -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.17.0"
14
+ version = "0.18.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.17.0"
15
+ version = "0.18.0"
16
16
 
17
17
  [project.scripts]
18
18
  sessionmemory = "sessionmemory.entry:main"
@@ -69,12 +69,18 @@ def _checkout(cwd: Path | None) -> localmd.Checkout:
69
69
  """
70
70
  vault = require_vault()
71
71
  slug, resolved = require_registered(vault=vault, cwd=cwd)
72
+ project = resolved.project
73
+ # Only a match by path, which resolution allows only outside any repository, may root
74
+ # the checkout at the registered folder.
75
+ by_path = resolved.matched_by == "path" and project is not None and project.root
76
+ registered_root = Path(project.root) if by_path else None
72
77
  try:
73
78
  return localmd.checkout(
74
79
  vault=vault,
75
80
  slug=slug,
76
81
  cwd=_common.target_dir(cwd),
77
82
  worktree=resolved.worktree_root,
83
+ registered_root=registered_root,
78
84
  )
79
85
  except localmd.LocalMdError as err:
80
86
  fail(err.message, details=err.details)
@@ -86,14 +92,14 @@ def _or_fail(co: localmd.Checkout, doing: str) -> Generator[None]:
86
92
 
87
93
  Args:
88
94
  co (localmd.Checkout): The checkout being worked on.
89
- doing (str): What failed, as in "could not <doing> the entries of <worktree>".
95
+ doing (str): What failed, as in "could not <doing> the entries of <root>".
90
96
  """
91
97
  try:
92
98
  yield
93
99
  except localmd.LocalMdError as err:
94
100
  fail(err.message, details=err.details)
95
101
  except OSError as err:
96
- fail(f"could not {doing} the entries of {co.worktree}: {err}")
102
+ fail(f"could not {doing} the entries of {co.root}: {err}")
97
103
 
98
104
 
99
105
  def _migrate(co: localmd.Checkout) -> None:
@@ -161,7 +167,7 @@ def _waiting(co: localmd.Checkout, tracked: set[str]) -> tuple[list[localmd.Entr
161
167
  except localmd.LocalMdError as err:
162
168
  pp.error(err.message, details=err.details)
163
169
  except OSError as err:
164
- pp.error(f"could not read the entries of {co.worktree}: {err}")
170
+ pp.error(f"could not read the entries of {co.root}: {err}")
165
171
  return [], False
166
172
 
167
173
 
@@ -808,7 +814,7 @@ def _declinable(co: localmd.Checkout, raw: str, cwd: Path, present: list[str]) -
808
814
  except localmd.LocalMdError as err:
809
815
  pp.error(err.message, details=err.details)
810
816
  except OSError as err:
811
- pp.error(f"could not read {raw} in {co.worktree}: {err}")
817
+ pp.error(f"could not read {raw} in {co.root}: {err}")
812
818
  return None
813
819
 
814
820
 
@@ -904,7 +910,9 @@ def status_command(cwd: Path | None = CWD_OPTION, as_json: bool = JSON_OPTION) -
904
910
  asked = {item.name for item in askable}
905
911
 
906
912
  def is_ignored(item: localmd.Entry) -> bool | None:
907
- return item.name in ignored if item.name in asked else None
913
+ if ignored is None or item.name not in asked:
914
+ return None
915
+ return item.name in ignored
908
916
 
909
917
  rows = [
910
918
  _status_row(
@@ -36,7 +36,7 @@ from sessionmemory.lib.frontmatter import (
36
36
  )
37
37
 
38
38
  if TYPE_CHECKING:
39
- from collections.abc import Callable
39
+ from collections.abc import Callable, Mapping
40
40
 
41
41
  from sessionmemory.lib.embed import Embedder
42
42
 
@@ -516,16 +516,20 @@ def _declined_findings(co: localmd.Checkout, *, checked: bool) -> list[Finding]:
516
516
  return findings
517
517
 
518
518
 
519
- def _project_local_findings(vault: Path, slug: str, root: Path | None) -> list[Finding]:
519
+ def _project_local_findings(
520
+ vault: Path, slug: str, root: Path | None, projects: Mapping[str, registry.Project]
521
+ ) -> list[Finding]:
520
522
  """Report one project's local entries, checking the checkout only when `root` exists."""
521
523
  findings = []
522
524
  legacy = _legacy_finding(vault, slug)
523
525
  if legacy is not None:
524
526
  findings.append(legacy)
525
- # With no registered root nothing below reaches git, so the vault is a harmless stand-in.
526
- co = localmd.Checkout(
527
- worktree=root or vault, vault=vault, slug=slug, local=paths.local_dir(vault, slug)
528
- )
527
+ if root is not None and root.is_dir():
528
+ checked = True
529
+ co = localmd.checkout_at(vault=vault, slug=slug, root=root, projects=projects)
530
+ else:
531
+ checked = False
532
+ co = localmd.vault_stand_in(vault=vault, slug=slug)
529
533
  findings.extend(_manifest_findings(co))
530
534
  try:
531
535
  items = localmd.vault_entries(co)
@@ -544,7 +548,6 @@ def _project_local_findings(vault: Path, slug: str, root: Path | None) -> list[F
544
548
  for item in items:
545
549
  findings.extend(_import_findings(item))
546
550
  findings.extend(_repository_findings(item))
547
- checked = root is not None and root.is_dir()
548
551
  findings.extend(_declined_findings(co, checked=checked))
549
552
  if not checked:
550
553
  return findings
@@ -588,7 +591,7 @@ def local_instructions(vault: Path, _embedder: Embedder) -> list[Finding]:
588
591
  for slug in paths.iter_project_slugs(vault):
589
592
  project = projects.get(slug)
590
593
  root = Path(project.root) if project and project.root else None
591
- findings.extend(_project_local_findings(vault, slug, root))
594
+ findings.extend(_project_local_findings(vault, slug, root, projects))
592
595
  return findings
593
596
 
594
597
 
@@ -31,7 +31,7 @@ GIT_TIMEOUT_SECONDS = 10
31
31
 
32
32
  # The one git failure that is an answer rather than an outage. Every other non-zero exit,
33
33
  # such as a `safe.directory` refusal or a held index lock, leaves the question open.
34
- _NOT_A_REPOSITORY = "not a git repository"
34
+ NOT_A_REPOSITORY = "not a git repository"
35
35
 
36
36
 
37
37
  @dataclass(frozen=True)
@@ -118,7 +118,7 @@ def _git(cwd: Path, *args: str) -> _GitAnswer:
118
118
  if completed is None:
119
119
  return _GitAnswer(stdout=None, answered=False)
120
120
  if completed.returncode != 0:
121
- return _GitAnswer(stdout=None, answered=_NOT_A_REPOSITORY in completed.stderr.lower())
121
+ return _GitAnswer(stdout=None, answered=NOT_A_REPOSITORY in completed.stderr.lower())
122
122
  return _GitAnswer(stdout=completed.stdout.strip() or None, answered=True)
123
123
 
124
124
 
@@ -18,12 +18,15 @@ an entry, so a `.DS_Store` or a set-aside folder left by a crash is skipped.
18
18
 
19
19
  A link is absolute. The vault's root differs from machine to machine and a linked
20
20
  worktree sits at a different depth from the main checkout, so no relative path is
21
- correct for both. Paths are taken from the git work tree's top level, which is where
22
- Claude Code looks for them, rather than from the registered root or the working directory.
23
-
24
- The ignore entry goes in `info/exclude`, never in a `.gitignore`, because a
25
- `.gitignore` is a committed file and linking must not leave a change to commit. Git
26
- reads `info/exclude` from the shared git directory, so one entry covers every linked
21
+ correct for both. Paths are taken from the checkout's root: the git work tree's top
22
+ level, which is where Claude Code looks for them, rather than the registered root or the
23
+ working directory. A project folder outside git has no work tree, so its registered root
24
+ is the root, and with no history to keep a link out of, nothing there is tracked or
25
+ ignored.
26
+
27
+ In a git work tree the ignore entry goes in `info/exclude`, never in a `.gitignore`,
28
+ because a `.gitignore` is a committed file and linking must not leave a change to commit.
29
+ Git reads `info/exclude` from the shared git directory, so one entry covers every linked
27
30
  worktree of a repository.
28
31
  """
29
32
 
@@ -48,12 +51,13 @@ from sessionmemory.lib import (
48
51
  localmanifest,
49
52
  localtree,
50
53
  paths,
54
+ registry,
51
55
  settingsdiff,
52
56
  )
53
57
 
54
58
  if TYPE_CHECKING:
55
59
  import subprocess
56
- from collections.abc import Iterable
60
+ from collections.abc import Iterable, Mapping
57
61
 
58
62
  Kind = Literal["local-md", "skill", "rule", "path", "settings"]
59
63
  Mode = Literal["link", "copy"]
@@ -174,12 +178,19 @@ def _git(cwd: Path, *args: str, input_text: str | None = None) -> subprocess.Com
174
178
 
175
179
  @dataclass(frozen=True)
176
180
  class Checkout:
177
- """One git work tree, and the vault root, slug, and `local/` folder of its project."""
181
+ """The folder entries are linked into, and its project's vault root, slug, and `local/`.
182
+
183
+ `root` is the resolved git work tree's top level, or the resolved registered root of a
184
+ project folder outside git, where `in_git` is false. `child_roots` are the resolved
185
+ roots of other registered projects inside it.
186
+ """
178
187
 
179
- worktree: Path
188
+ root: Path
189
+ in_git: bool
180
190
  vault: Path
181
191
  slug: str
182
192
  local: Path
193
+ child_roots: tuple[Path, ...] = ()
183
194
 
184
195
 
185
196
  @dataclass(frozen=True)
@@ -198,14 +209,21 @@ class Entry:
198
209
 
199
210
  @property
200
211
  def relpath(self) -> str:
201
- """The link path relative to the work tree's top level, as git names it."""
212
+ """The link path relative to the checkout's root, as git names it."""
202
213
  if self.kind in {"local-md", "path"}:
203
214
  return self.name
204
215
  return f"{_CHECKOUT_CLAUDE}/{self.name}"
205
216
 
206
217
 
207
- def checkout(vault: Path, slug: str, cwd: Path, worktree: Path | None = None) -> Checkout:
208
- """Locate the work tree holding `cwd` and the vault's `local/` folder for `slug`.
218
+ def checkout(
219
+ vault: Path,
220
+ slug: str,
221
+ cwd: Path,
222
+ worktree: Path | None = None,
223
+ registered_root: Path | None = None,
224
+ projects: Mapping[str, registry.Project] | None = None,
225
+ ) -> Checkout:
226
+ """Locate the root holding `cwd` and the vault's `local/` folder for `slug`.
209
227
 
210
228
  Args:
211
229
  vault (Path): The vault root.
@@ -214,34 +232,150 @@ def checkout(vault: Path, slug: str, cwd: Path, worktree: Path | None = None) ->
214
232
  worktree (Path | None): The work tree's top level when the caller already asked
215
233
  git for it, so git is not asked again. Ignored while a `GIT_` variable is set,
216
234
  since the caller's answer was not given under `_git_safe_env`.
235
+ registered_root (Path | None): The project's registered root, used as the root
236
+ when git says `cwd` is not inside a repository. Pass it only when resolution
237
+ matched the project by path.
238
+ projects (Mapping[str, registry.Project] | None): The loaded registry, or None to
239
+ read it, for finding the child projects inside the root.
217
240
 
218
241
  Returns:
219
- Checkout: The work tree's top level and the project it belongs to.
242
+ Checkout: The root and the project it belongs to.
220
243
 
221
244
  Raises:
222
- LocalMdError: When `cwd` is not inside a git work tree.
245
+ LocalMdError: When `cwd` is not inside a git work tree and no registered root
246
+ was given, or when git refuses to say whether it is.
247
+ """
248
+ if worktree is not None and not any(key.startswith("GIT_") for key in os.environ):
249
+ return _build_checkout(
250
+ vault=vault, slug=slug, root=worktree, in_git=True, projects=projects
251
+ )
252
+ done = _git(cwd, "rev-parse", "--show-toplevel")
253
+ toplevel = done.stdout.strip()
254
+ if done.returncode == 0 and toplevel:
255
+ return _build_checkout(
256
+ vault=vault, slug=slug, root=Path(toplevel), in_git=True, projects=projects
257
+ )
258
+ if registered_root is None:
259
+ msg = f"{cwd} is not inside a git work tree"
260
+ raise LocalMdError(msg)
261
+ stderr = done.stderr.strip()
262
+ # Any other refusal, such as `safe.directory`, may hide a repository whose links must
263
+ # stay ignored, so only git's own verdict lets a folder count as outside git.
264
+ if done.returncode != 0 and gitinfo.NOT_A_REPOSITORY not in stderr.lower():
265
+ msg = f"git could not say whether {cwd} is inside a work tree"
266
+ raise LocalMdError(msg, [stderr] if stderr else [])
267
+ return _build_checkout(
268
+ vault=vault, slug=slug, root=registered_root, in_git=False, projects=projects
269
+ )
270
+
271
+
272
+ def checkout_at(
273
+ vault: Path,
274
+ slug: str,
275
+ root: Path,
276
+ projects: Mapping[str, registry.Project] | None = None,
277
+ ) -> Checkout:
278
+ """Build the checkout for a project's registered root, asking git whether it is a repo.
279
+
280
+ For callers such as `doctor` that start from the registry rather than a working
281
+ directory. A root inside a repository is checked at the work tree's top level, where
282
+ sync links. When git cannot run or will not answer, the root is taken as a work tree,
283
+ so the git-only checks raise and the caller reports that git could not be asked.
284
+
285
+ Args:
286
+ vault (Path): The vault root.
287
+ slug (str): The project's slug.
288
+ root (Path): The project's registered root, an existing directory.
289
+ projects (Mapping[str, registry.Project] | None): The loaded registry, or None to
290
+ read it.
291
+
292
+ Returns:
293
+ Checkout: The checkout for the project.
223
294
  """
224
- if worktree is None or any(key.startswith("GIT_") for key in os.environ):
225
- done = _git(cwd, "rev-parse", "--show-toplevel")
226
- toplevel = done.stdout.strip()
227
- if done.returncode != 0 or not toplevel:
228
- msg = f"{cwd} is not inside a git work tree"
229
- raise LocalMdError(msg)
230
- worktree = Path(toplevel).resolve()
295
+ try:
296
+ return checkout(vault=vault, slug=slug, cwd=root, registered_root=root, projects=projects)
297
+ except LocalMdError:
298
+ return _build_checkout(vault=vault, slug=slug, root=root, in_git=True, projects=projects)
299
+
300
+
301
+ def vault_stand_in(vault: Path, slug: str) -> Checkout:
302
+ """Build a checkout with no folder to link into, for checks of the vault side only.
303
+
304
+ Args:
305
+ vault (Path): The vault root.
306
+ slug (str): The project's slug.
307
+
308
+ Returns:
309
+ Checkout: A checkout rooted at the vault, outside git, with no child projects.
310
+ """
311
+ return Checkout(
312
+ root=vault, in_git=False, vault=vault, slug=slug, local=paths.local_dir(vault, slug)
313
+ )
314
+
315
+
316
+ def _build_checkout(
317
+ vault: Path,
318
+ slug: str,
319
+ root: Path,
320
+ *,
321
+ in_git: bool,
322
+ projects: Mapping[str, registry.Project] | None,
323
+ ) -> Checkout:
324
+ top = root.resolve()
325
+ try:
326
+ known = registry.load(vault) if projects is None else projects
327
+ children = registry.find_under_root(known, str(top), exclude=slug)
328
+ except registry.RegistryError:
329
+ # Resolution and doctor report an unreadable registry; here it only means no
330
+ # child is known.
331
+ children = ()
231
332
  return Checkout(
232
- worktree=worktree,
333
+ root=top,
334
+ in_git=in_git,
233
335
  vault=vault,
234
336
  slug=slug,
235
337
  local=paths.local_dir(vault, slug),
338
+ child_roots=children,
236
339
  )
237
340
 
238
341
 
342
+ def child_project(co: Checkout, relpath: str) -> Path | None:
343
+ """Name the child folder that is its own project and holds, or is, `relpath`.
344
+
345
+ A registered child owns its files, and a nested repository could commit a link
346
+ placed in it, so neither may receive an entry of the project around it. The path is
347
+ read as written, never through a symlink, so a linked entry is judged where it sits.
348
+
349
+ Args:
350
+ co (Checkout): The checkout the path is relative to.
351
+ relpath (str): A path relative to the checkout's root.
352
+
353
+ Returns:
354
+ Path | None: The child project's folder under `co.root`, or None when the path
355
+ belongs to this project or the checkout is a vault stand-in.
356
+ """
357
+ if co.root == co.vault:
358
+ return None
359
+ parts = Path(relpath).parts
360
+ for depth in range(1, len(parts) + 1):
361
+ folder = co.root.joinpath(*parts[:depth])
362
+ if folder in co.child_roots:
363
+ return folder
364
+ # A linked entry's folder is the vault copy, whose contents say nothing here.
365
+ if folder.is_symlink():
366
+ return None
367
+ marker = folder / ".git"
368
+ if marker.is_symlink() or marker.exists():
369
+ return folder
370
+ return None
371
+
372
+
239
373
  def path_entry(co: Checkout, relpath: str) -> Entry:
240
374
  """Build the entry for a path adopted by name, without judging the path.
241
375
 
242
376
  Args:
243
377
  co (Checkout): The checkout the entry belongs to.
244
- relpath (str): The path relative to the work tree's top level.
378
+ relpath (str): The path relative to the checkout's root.
245
379
 
246
380
  Returns:
247
381
  Entry: The entry, linked at the path and kept at its mirror under `local/`.
@@ -249,7 +383,7 @@ def path_entry(co: Checkout, relpath: str) -> Entry:
249
383
  return Entry(
250
384
  kind="path",
251
385
  name=relpath,
252
- link=co.worktree / relpath,
386
+ link=co.root / relpath,
253
387
  target=co.local / localmanifest.vault_relpath(relpath),
254
388
  )
255
389
 
@@ -261,9 +395,30 @@ def manifest(co: Checkout) -> localmanifest.Manifest:
261
395
  co (Checkout): The checkout whose project's `local/` folder holds the list.
262
396
 
263
397
  Returns:
264
- localmanifest.Manifest: The usable paths and any problems in the file.
398
+ localmanifest.Manifest: The usable paths and any problems in the file. A listed
399
+ path inside a child project is a problem rather than a usable path, so it is
400
+ reported and never linked.
265
401
  """
266
- return localmanifest.read(co.local)
402
+ found = localmanifest.read(co.local)
403
+ kept: list[str] = []
404
+ moved: list[str] = []
405
+ for relpath in found.paths:
406
+ folder = child_project(co, relpath)
407
+ if folder is None:
408
+ kept.append(relpath)
409
+ else:
410
+ link = co.root / relpath
411
+ # A link placed before the folder became a project is still the vault copy,
412
+ # so deleting it loses nothing and keeps the child from committing it.
413
+ remedy = (
414
+ f"delete the link at {link} and remove the line from entries.toml"
415
+ if link.is_symlink()
416
+ else "remove the line from entries.toml"
417
+ )
418
+ moved.append(f"{relpath} is inside {folder}, which is its own project; {remedy}")
419
+ if not moved:
420
+ return found
421
+ return localmanifest.Manifest(paths=tuple(kept), problems=(*found.problems, *moved))
267
422
 
268
423
 
269
424
  def declined(co: Checkout) -> localdeclined.Declined:
@@ -302,7 +457,7 @@ def declinable(co: Checkout, raw: str, cwd: Path, present: list[str]) -> str:
302
457
  offered = state(item) is State.DIVERGED and identical(item)
303
458
  in_vault = item.target.is_symlink() or item.target.exists()
304
459
  except OSError as err:
305
- msg = f"could not read {raw} in {co.worktree}: {err}"
460
+ msg = f"could not read {raw} in {co.root}: {err}"
306
461
  raise LocalMdError(msg) from err
307
462
  # candidates() compares names exactly, so a case-only spelling would silence nothing.
308
463
  other = localmanifest.same_but_case(item.name, present)
@@ -351,12 +506,12 @@ def entry(co: Checkout, name: str) -> Entry:
351
506
  LocalMdError: When `name` is not a valid entry name.
352
507
  """
353
508
  if name == paths.LOCAL_MD_FILE:
354
- return Entry(kind="local-md", name=name, link=co.worktree / name, target=co.local / name)
509
+ return Entry(kind="local-md", name=name, link=co.root / name, target=co.local / name)
355
510
  if name == SETTINGS_NAME:
356
511
  return Entry(
357
512
  kind="settings",
358
513
  name=name,
359
- link=co.worktree / _CHECKOUT_CLAUDE / name,
514
+ link=co.root / _CHECKOUT_CLAUDE / name,
360
515
  target=co.local / _VAULT_CLAUDE / name,
361
516
  )
362
517
  prefix, sep, child = name.partition("/")
@@ -376,7 +531,7 @@ def entry(co: Checkout, name: str) -> Entry:
376
531
  return Entry(
377
532
  kind=kind,
378
533
  name=name,
379
- link=co.worktree / _CHECKOUT_CLAUDE / prefix / child,
534
+ link=co.root / _CHECKOUT_CLAUDE / prefix / child,
380
535
  target=co.local / _VAULT_CLAUDE / prefix / child,
381
536
  )
382
537
 
@@ -394,7 +549,7 @@ def _lexical(path: Path) -> Path:
394
549
 
395
550
 
396
551
  def _work_tree_path(co: Checkout, raw: str, cwd: Path) -> str:
397
- """Turn a typed path into its path from the work tree's top level.
552
+ """Turn a typed path into its path from the checkout's root.
398
553
 
399
554
  Raises:
400
555
  LocalMdError: When the path is outside the checkout or is the checkout itself.
@@ -403,14 +558,14 @@ def _work_tree_path(co: Checkout, raw: str, cwd: Path) -> str:
403
558
  resolved = _lexical(typed)
404
559
  # Read lexically first, so a path inside a linked folder is judged where it was typed
405
560
  # rather than in the vault. Resolving catches a checkout reached through a symlink.
406
- if not resolved.is_relative_to(co.worktree):
561
+ if not resolved.is_relative_to(co.root):
407
562
  resolved = typed.parent.resolve() / typed.name if typed.name else typed.resolve()
408
563
  if resolved.name in {"", ".", ".."}:
409
564
  resolved = resolved.resolve()
410
565
  try:
411
- relpath = resolved.relative_to(co.worktree).as_posix()
566
+ relpath = resolved.relative_to(co.root).as_posix()
412
567
  except ValueError:
413
- msg = f"{raw} is outside the checkout at {co.worktree}"
568
+ msg = f"{raw} is outside the checkout at {co.root}"
414
569
  raise LocalMdError(msg) from None
415
570
  if relpath == ".":
416
571
  msg = f"{raw} is the checkout itself"
@@ -435,7 +590,8 @@ def resolve_adopt(co: Checkout, raw: str, cwd: Path) -> Entry:
435
590
 
436
591
  Raises:
437
592
  LocalMdError: When the path is outside the checkout, the checkout itself, the
438
- settings file, a path adopt refuses, or overlaps a path already adopted.
593
+ settings file, a path adopt refuses, inside a child project, or overlaps a path
594
+ already adopted.
439
595
  """
440
596
  if localmanifest.is_kind_name(raw):
441
597
  return entry(co, raw)
@@ -455,6 +611,10 @@ def resolve_adopt(co: Checkout, raw: str, cwd: Path) -> Entry:
455
611
  if reason is not None:
456
612
  msg = f"{relpath} cannot be adopted"
457
613
  raise LocalMdError(msg, [reason])
614
+ folder = child_project(co, relpath)
615
+ if folder is not None:
616
+ msg = f"{relpath} belongs to the project at {folder}"
617
+ raise LocalMdError(msg, ["Adopt it from inside that project."])
458
618
  listed = manifest(co).paths
459
619
  other = localmanifest.same_but_case(relpath, listed)
460
620
  if other is not None:
@@ -528,7 +688,7 @@ def _checkout_names(co: Checkout, listed: list[Entry]) -> set[str]:
528
688
  """
529
689
  found = {
530
690
  name
531
- for name, (kind, path) in _names_in(co.worktree, _CHECKOUT_CLAUDE).items()
691
+ for name, (kind, path) in _names_in(co.root, _CHECKOUT_CLAUDE).items()
532
692
  if path.is_symlink() or _present(path, kind)
533
693
  }
534
694
  found.update(
@@ -670,7 +830,7 @@ def identical(item: Entry) -> bool:
670
830
 
671
831
 
672
832
  def _kind_folder(co: Checkout, kind: Kind) -> Path:
673
- return co.worktree / _CHECKOUT_CLAUDE / _KIND_DIRS[kind]
833
+ return co.root / _CHECKOUT_CLAUDE / _KIND_DIRS[kind]
674
834
 
675
835
 
676
836
  def _blocked_folders(co: Checkout, kind: Kind) -> bool:
@@ -689,7 +849,7 @@ def _blocked_folders(co: Checkout, kind: Kind) -> bool:
689
849
 
690
850
  def _blocked_ancestor(co: Checkout, item: Entry) -> Path | None:
691
851
  """Return the first folder above a path entry that is a symlink or not a folder."""
692
- current = co.worktree
852
+ current = co.root
693
853
  for part in Path(item.relpath).parts[:-1]:
694
854
  current /= part
695
855
  if current.is_symlink() or (current.exists() and not current.is_dir()):
@@ -712,7 +872,7 @@ def blocking_folder(co: Checkout, item: Entry) -> Path:
712
872
  return _blocked_ancestor(co, item) or item.link.parent
713
873
  if item.kind in _KIND_DIRS:
714
874
  return _kind_folder(co, item.kind)
715
- return co.worktree / _CHECKOUT_CLAUDE
875
+ return co.root / _CHECKOUT_CLAUDE
716
876
 
717
877
 
718
878
  def blocked(co: Checkout, item: Entry) -> bool:
@@ -731,7 +891,7 @@ def blocked(co: Checkout, item: Entry) -> bool:
731
891
  if item.kind == "local-md":
732
892
  return False
733
893
  if item.kind == "settings":
734
- claude = co.worktree / _CHECKOUT_CLAUDE
894
+ claude = co.root / _CHECKOUT_CLAUDE
735
895
  return claude.is_symlink() or (claude.exists() and not claude.is_dir())
736
896
  if item.kind == "path":
737
897
  return _blocked_ancestor(co, item) is not None
@@ -748,18 +908,21 @@ def tracked_names(co: Checkout, items: list[Entry]) -> set[str]:
748
908
  Returns:
749
909
  set[str]: The names of entries whose path, or any file under it, git tracks.
750
910
  An entry under a symlinked or non-folder `.claude/` path is never reported,
751
- since git cannot be asked about it.
911
+ since git cannot be asked about it. Empty outside git, where nothing is
912
+ tracked.
752
913
 
753
914
  Raises:
754
915
  LocalMdError: When git cannot list the index.
755
916
  """
917
+ if not co.in_git:
918
+ return set()
756
919
  by_path = {item.relpath: item.name for item in items if not blocked(co, item)}
757
920
  if not by_path:
758
921
  return set()
759
922
  # Literal, so a name holding `*` or `?` matches only itself.
760
- done = _git(co.worktree, "--literal-pathspecs", "ls-files", "-z", "--", *by_path)
923
+ done = _git(co.root, "--literal-pathspecs", "ls-files", "-z", "--", *by_path)
761
924
  if done.returncode != 0:
762
- msg = f"git ls-files failed in {co.worktree}"
925
+ msg = f"git ls-files failed in {co.root}"
763
926
  raise LocalMdError(msg, [done.stderr.strip()] if done.stderr.strip() else [])
764
927
  found: set[str] = set()
765
928
  for listed in filter(None, done.stdout.split("\0")):
@@ -777,20 +940,23 @@ def ignored(co: Checkout, item: Entry) -> bool:
777
940
  item (Entry): The entry to check.
778
941
 
779
942
  Returns:
780
- bool: True when `git check-ignore` matches the link path.
943
+ bool: True when `git check-ignore` matches the link path. True outside git,
944
+ where there is no history to hide a link from.
781
945
 
782
946
  Raises:
783
947
  LocalMdError: When git fails for any reason other than "not ignored", such as
784
948
  a directory that is not a repository.
785
949
  """
786
- done = _git(co.worktree, "check-ignore", "-q", "--", item.relpath)
950
+ if not co.in_git:
951
+ return True
952
+ done = _git(co.root, "check-ignore", "-q", "--", item.relpath)
787
953
  if done.returncode not in (0, 1):
788
- msg = f"git check-ignore failed in {co.worktree}"
954
+ msg = f"git check-ignore failed in {co.root}"
789
955
  raise LocalMdError(msg, [done.stderr.strip()] if done.stderr.strip() else [])
790
956
  return done.returncode == 0
791
957
 
792
958
 
793
- def ignored_names(co: Checkout, items: list[Entry]) -> set[str]:
959
+ def ignored_names(co: Checkout, items: list[Entry]) -> set[str] | None:
794
960
  """Name the entries whose link path git already ignores, in one git call.
795
961
 
796
962
  Args:
@@ -798,19 +964,22 @@ def ignored_names(co: Checkout, items: list[Entry]) -> set[str]:
798
964
  items (list[Entry]): The entries to check, none behind a blocked `.claude/`.
799
965
 
800
966
  Returns:
801
- set[str]: The names of entries `git check-ignore` matches.
967
+ set[str] | None: The names of entries `git check-ignore` matches, or None
968
+ outside git, where ignoring does not apply.
802
969
 
803
970
  Raises:
804
971
  LocalMdError: When git fails for any reason other than "none ignored".
805
972
  """
973
+ if not co.in_git:
974
+ return None
806
975
  by_path = {item.relpath: item.name for item in items}
807
976
  if not by_path:
808
977
  return set()
809
978
  done = _git(
810
- co.worktree, "check-ignore", "--stdin", "-z", input_text="".join(f"{p}\0" for p in by_path)
979
+ co.root, "check-ignore", "--stdin", "-z", input_text="".join(f"{p}\0" for p in by_path)
811
980
  )
812
981
  if done.returncode not in (0, 1):
813
- msg = f"git check-ignore failed in {co.worktree}"
982
+ msg = f"git check-ignore failed in {co.root}"
814
983
  raise LocalMdError(msg, [done.stderr.strip()] if done.stderr.strip() else [])
815
984
  return {by_path[path] for path in done.stdout.split("\0") if path in by_path}
816
985
 
@@ -844,7 +1013,8 @@ def ensure_ignored(co: Checkout, item: Entry) -> bool:
844
1013
  item (Entry): The entry to hide.
845
1014
 
846
1015
  Returns:
847
- bool: True when it wrote an entry, False when git already ignored the path.
1016
+ bool: True when it wrote an entry, False when the path is already hidden,
1017
+ which `ignored` reports for every path outside git.
848
1018
 
849
1019
  Raises:
850
1020
  LocalMdError: When git cannot name its exclude file.
@@ -852,12 +1022,12 @@ def ensure_ignored(co: Checkout, item: Entry) -> bool:
852
1022
  if ignored(co, item):
853
1023
  return False
854
1024
 
855
- done = _git(co.worktree, "rev-parse", "--git-path", "info/exclude")
1025
+ done = _git(co.root, "rev-parse", "--git-path", "info/exclude")
856
1026
  if done.returncode != 0 or not done.stdout.strip():
857
1027
  msg = "git did not name its exclude file"
858
1028
  raise LocalMdError(msg, [done.stderr.strip()] if done.stderr.strip() else [])
859
1029
 
860
- exclude = co.worktree / done.stdout.strip()
1030
+ exclude = co.root / done.stdout.strip()
861
1031
  exclude.parent.mkdir(parents=True, exist_ok=True)
862
1032
  existing = exclude.read_text(encoding="utf-8", errors="replace") if exclude.exists() else ""
863
1033
  line = _exclude_line(item)
@@ -1398,7 +1568,7 @@ def _refuse_adopt(co: Checkout, item: Entry, current: State, *, tracked: bool) -
1398
1568
  msg = f"{blocking_folder(co, item)} or its parent is a symlink or not a folder"
1399
1569
  raise LocalMdError(msg, [f"{item.name} cannot be adopted through it."])
1400
1570
  if tracked:
1401
- msg = f"{item.name} is tracked by git in {co.worktree}"
1571
+ msg = f"{item.name} is tracked by git in {co.root}"
1402
1572
  raise LocalMdError(msg, ["Remove it from the index before adopting it."])
1403
1573
  if target_misshapen(item):
1404
1574
  raise LocalMdError(
@@ -1408,7 +1578,7 @@ def _refuse_adopt(co: Checkout, item: Entry, current: State, *, tracked: bool) -
1408
1578
  msg = f"{item.link} is a symlink to {item.link.resolve()}, not to the vault copy"
1409
1579
  raise LocalMdError(msg)
1410
1580
  if current in {State.NONE, State.NOT_LINKED, State.DANGLING}:
1411
- msg = f"no {item.name} in {co.worktree}"
1581
+ msg = f"no {item.name} in {co.root}"
1412
1582
  raise LocalMdError(msg)
1413
1583
  _check_shape(item)
1414
1584
  if item.link.is_dir():
@@ -340,3 +340,26 @@ def find_by_path_prefix(projects: Mapping[str, Project], path: str) -> Project |
340
340
  best = project
341
341
  best_depth = depth
342
342
  return best
343
+
344
+
345
+ def find_under_root(projects: Mapping[str, Project], root: str, exclude: str) -> tuple[Path, ...]:
346
+ """Return the roots of other projects strictly inside `root`, each its own project.
347
+
348
+ The reverse of `find_by_path_prefix`, with the same rules: both sides are resolved,
349
+ and a stored root that is not absolute is skipped.
350
+
351
+ Args:
352
+ projects (Mapping[str, Project]): The loaded registry.
353
+ root (str): An absolute directory.
354
+ exclude (str): The slug of the project registered at `root`.
355
+
356
+ Returns:
357
+ tuple[Path, ...]: The resolved roots, sorted, none equal to `root`.
358
+ """
359
+ top = Path(root).resolve()
360
+ found = {
361
+ Path(project.root).resolve()
362
+ for slug, project in projects.items()
363
+ if slug != exclude and project.root and Path(project.root).is_absolute()
364
+ }
365
+ return tuple(sorted(child for child in found if child != top and child.is_relative_to(top)))
@@ -19,7 +19,7 @@ A worktree always resolves to its parent project, because the repository root co
19
19
  from __future__ import annotations
20
20
 
21
21
  from dataclasses import dataclass
22
- from typing import TYPE_CHECKING
22
+ from typing import TYPE_CHECKING, Literal
23
23
 
24
24
  from sessionmemory.lib import registry
25
25
  from sessionmemory.lib.gitinfo import git_context
@@ -27,10 +27,12 @@ from sessionmemory.lib.gitinfo import git_context
27
27
  if TYPE_CHECKING:
28
28
  from pathlib import Path
29
29
 
30
+ MatchKey = Literal["remote", "root", "path"]
31
+
30
32
 
31
33
  @dataclass(frozen=True)
32
34
  class Resolution:
33
- """Which project a working directory belongs to."""
35
+ """Which project a working directory belongs to, and which key matched it, if any."""
34
36
 
35
37
  slug: str | None
36
38
  registered: bool
@@ -38,6 +40,7 @@ class Resolution:
38
40
  repo_root: Path | None
39
41
  worktree_root: Path | None
40
42
  is_worktree: bool
43
+ matched_by: MatchKey | None = None
41
44
 
42
45
 
43
46
  def resolve(vault: Path, cwd: Path) -> Resolution:
@@ -54,12 +57,15 @@ def resolve(vault: Path, cwd: Path) -> Resolution:
54
57
  projects = registry.load(vault)
55
58
 
56
59
  found = registry.find_by_remote(projects, context.remotes)
60
+ matched_by: MatchKey | None = "remote" if found is not None else None
57
61
 
58
62
  if found is None and context.repo_root is not None:
59
63
  found = registry.find_by_root(projects, str(context.repo_root))
64
+ matched_by = "root" if found is not None else None
60
65
 
61
66
  if found is None and context.repo_root is None and context.git_answered and not context.is_bare:
62
67
  found = registry.find_by_path_prefix(projects, str(cwd.resolve()))
68
+ matched_by = "path" if found is not None else None
63
69
 
64
70
  if found is None:
65
71
  return Resolution(
@@ -78,4 +84,5 @@ def resolve(vault: Path, cwd: Path) -> Resolution:
78
84
  repo_root=context.repo_root,
79
85
  worktree_root=context.worktree_root,
80
86
  is_worktree=context.is_worktree,
87
+ matched_by=matched_by,
81
88
  )
File without changes