"""The one way a tool reads or writes a project's plan: through the store its config names. The config's `plan` setting names the backend. A path names a markdown file, todo.md, which `todo_md` keeps. `jira:` and an epic's address name a Jira epic, whose open child issues are the plan: `jira_epic` reads them, and files an item as a new child issue. An agent reads and changes the plan with `todo-item`, which works through the same store. A tool that reads what a past commit held, such as `score-outcomes`, still parses that commit's todo.md itself, with `plan.todo_table`: only the markdown backend has commits, and todo.md's items 365, 366 and 368 port those tools to the other backends.""" import pathlib from failure import Failure from git_cli.git_repo import file_at, git, Git from plan_store.todo_md import FilePlan, plan_of from record_store.stores import goals_store, store as record_store from plan_store.jira_epic import JiraPlan from plan_store.plans import Plan, PlanStore from project_config.settings import ProjectConfig from plan_store.scoring import StatedScoring def store(config: ProjectConfig) -> PlanStore: """The store config names for the plan.""" if config.epic is None: return file_plan(config) # load refuses a config that names an epic and no env-file. assert config.env_file is not None # load refuses a config that names an epic and no formula or bar. assert config.jira_scoring is not None scoring = StatedScoring(config.jira_scoring, goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), config.readability_floor) return JiraPlan(config.epic, config.env_file, finish_by=config.jira_finish, scoring=scoring) def file_plan(config: ProjectConfig, path: pathlib.Path | None = None) -> FilePlan: """The markdown file config names as its plan, for a tool that works on the file itself, as ranking does. path stands in for the configured one where given.""" return FilePlan(path or config.paths["plan"], config.tracked("plan"), goals_store(config), record_store(config, "decisions"), record_store(config, "comprehension-history"), config.readability_floor) def held_at(revision: str, plan: PlanStore, cwd: str, run: Git = git) -> Plan | Failure: """plan at revision, read in the checkout at cwd, where its commits hold the plan; else as it stands. A NoItemsTable where there is no plan.""" if plan.tracked is None: return plan.read() text = file_at(revision, plan.tracked, cwd, run) return text if isinstance(text, Failure) else plan_of(text)