feat: add governed fast work-record sync
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a053ff-1d6f-7fe2-ac1c-a6eb40a42a0c
This commit is contained in:
parent
7ea7690dfc
commit
58414404d6
10 changed files with 1280 additions and 32 deletions
|
|
@ -12,14 +12,15 @@ from typing import Any
|
|||
|
||||
from repo_manager import dual_run, idempotency
|
||||
from repo_manager.gitops import GitError, commit_paths, head_sha, push_ff
|
||||
from repo_manager.identifiers import derive_work_record_uuid, load_fleet_namespace
|
||||
from repo_manager.index_store import append_event, default_index_path, save_index
|
||||
from repo_manager.observe import observe_repository
|
||||
from repo_manager.record_identity import classify_record_id
|
||||
from repo_manager.time import utc_today
|
||||
|
||||
VALID_WORKPLAN_STATUSES = frozenset(
|
||||
{"proposed", "ready", "active", "blocked", "backlog", "finished", "archived"}
|
||||
)
|
||||
_WORKPLAN_ID_RE = re.compile(r"^[A-Z][A-Z0-9]*-WP-[0-9]{4,}$")
|
||||
_FRONTMATTER_RE = re.compile(r"\A---\r?\n(?P<meta>.*?)\r?\n---(?P<body>\r?\n.*)?\Z", re.DOTALL)
|
||||
|
||||
|
||||
|
|
@ -123,6 +124,7 @@ def _create_text(
|
|||
topic_slug: str,
|
||||
) -> str:
|
||||
today = _today().isoformat()
|
||||
workplan_uuid = derive_work_record_uuid(load_fleet_namespace(), workplan_id)
|
||||
return (
|
||||
"---\n"
|
||||
f"id: {workplan_id}\n"
|
||||
|
|
@ -135,6 +137,7 @@ def _create_text(
|
|||
f"topic_slug: {topic_slug}\n"
|
||||
f"created: {_quoted(today)}\n"
|
||||
f"updated: {_quoted(today)}\n"
|
||||
f"state_hub_workstream_id: {_quoted(str(workplan_uuid))}\n"
|
||||
"---\n\n"
|
||||
f"# {title}\n\n"
|
||||
"## Goal\n\n"
|
||||
|
|
@ -241,7 +244,7 @@ def mutate_workplan(
|
|||
changes: dict[str, Any]
|
||||
|
||||
if operation == "create":
|
||||
if not _WORKPLAN_ID_RE.fullmatch(workplan_id):
|
||||
if classify_record_id("workplan", workplan_id) != "canonical":
|
||||
return _rejected(
|
||||
command,
|
||||
correlation_id,
|
||||
|
|
@ -265,8 +268,23 @@ def mutate_workplan(
|
|||
"validation_error",
|
||||
f"invalid workplan status {create_status!r}",
|
||||
)
|
||||
name = filename or f"{workplan_id}-{_slugify(title)}.md"
|
||||
if Path(name).name != name or not name.endswith(".md") or not name.startswith(f"{workplan_id}-"):
|
||||
is_adhoc = "-WP-ADHOC-" in workplan_id
|
||||
adhoc_date = workplan_id.rsplit("-WP-ADHOC-", 1)[-1]
|
||||
name = filename or (
|
||||
f"ADHOC-{adhoc_date}.md"
|
||||
if is_adhoc
|
||||
else f"{workplan_id}-{_slugify(title)}.md"
|
||||
)
|
||||
expected_adhoc_name = f"ADHOC-{adhoc_date}.md"
|
||||
safe_name = (
|
||||
Path(name).name == name
|
||||
and name.endswith(".md")
|
||||
and (
|
||||
name.startswith(f"{workplan_id}-")
|
||||
or (is_adhoc and name == expected_adhoc_name)
|
||||
)
|
||||
)
|
||||
if not safe_name:
|
||||
return _rejected(command, correlation_id, "validation_error", "unsafe workplan filename")
|
||||
path = repo_root / "workplans" / name
|
||||
if path.exists():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue