Rank, check and edit the plan at the paths the project's config names
This commit is contained in:
@@ -14,14 +14,26 @@ SETTINGS = ("plan", "working-rules", "decisions", "score-anchors", "comprehensio
|
||||
# They also picked a prefix over bare relative paths: each line says its own place, and a relative path with no prefix fails instead of landing somewhere by default.
|
||||
SPELLING = '"checkout:<path>" for a path in the checkout, "folder:<path>" for one in the config\'s folder, or a path that starts with / or ~/'
|
||||
|
||||
# Where a project keeps a file, for a tool that reads it at a commit: a path from the checkout's top, as git names it; or, outside the checkout, the file itself, which the tool reads as it stands, since git holds no version of it.
|
||||
Place = str | pathlib.Path
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class ProjectConfig:
|
||||
"""folder is `~/.claude-projects/<key>`, and paths holds each of SETTINGS as an absolute path."""
|
||||
"""folder is `~/.claude-projects/<key>`, top is the worktree that asked, and paths holds each of SETTINGS as an absolute path."""
|
||||
key: str
|
||||
folder: pathlib.Path
|
||||
top: pathlib.Path
|
||||
paths: dict[str, pathlib.Path]
|
||||
|
||||
def tracked(self, setting: str) -> str | None:
|
||||
"""setting's path from top, as git names a file in a commit; None where the config puts it outside the checkout, where git holds no version of it."""
|
||||
path = self.paths[setting]
|
||||
return path.relative_to(self.top).as_posix() if path.is_relative_to(self.top) else None
|
||||
|
||||
def place(self, setting: str) -> Place:
|
||||
return self.tracked(setting) or self.paths[setting]
|
||||
|
||||
|
||||
def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure:
|
||||
"""The config that names main, the project's main checkout.
|
||||
@@ -49,7 +61,7 @@ def load(top: pathlib.Path, main: pathlib.Path, home: pathlib.Path) -> ProjectCo
|
||||
]
|
||||
if faults:
|
||||
return Failure(f"{file}: {'; '.join(faults)}. The settings are {', '.join(SETTINGS)}.")
|
||||
return ProjectConfig(file.parent.name, file.parent, {name: path for name, path in paths.items() if path})
|
||||
return ProjectConfig(file.parent.name, file.parent, top, {name: path for name, path in paths.items() if path})
|
||||
|
||||
|
||||
def read(file: pathlib.Path, home: pathlib.Path) -> tuple[pathlib.Path, dict[str, object]] | Failure:
|
||||
|
||||
@@ -88,6 +88,15 @@ class LoadTest(ConfigCase):
|
||||
assert isinstance(found, ProjectConfig), found
|
||||
self.assertEqual(found.paths["changelog"], worktree / "CHANGELOG.md")
|
||||
|
||||
def test_names_a_file_in_the_checkout_as_git_does_and_none_outside_it(self) -> None:
|
||||
self.write("acme", CLIENT.replace("folder:docs/decisions.md", "checkout:project/decisions.md"))
|
||||
worktree = self.home / "code" / "acme-billing-item-3"
|
||||
found = load(worktree, self.checkout, self.home)
|
||||
assert isinstance(found, ProjectConfig), found
|
||||
self.assertEqual(found.tracked("changelog"), "CHANGELOG.md")
|
||||
self.assertEqual(found.tracked("decisions"), "project/decisions.md")
|
||||
self.assertIsNone(found.tracked("plan"), "the config's folder is outside the checkout")
|
||||
|
||||
def test_an_absolute_checkout_and_path_are_taken_as_written(self) -> None:
|
||||
self.write("acme", CLIENT.replace("~/code/acme-billing", str(self.checkout)).replace("~/.claude/principles", "/srv/principles"))
|
||||
found = load(self.checkout, self.checkout, self.home)
|
||||
|
||||
Reference in New Issue
Block a user