64 lines
1.6 KiB
Python
64 lines
1.6 KiB
Python
"""Inject the project coordination reminder at Codex session start."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def read_payload() -> dict:
|
|
raw = sys.stdin.read()
|
|
if not raw.strip():
|
|
return {}
|
|
try:
|
|
return json.loads(raw)
|
|
except json.JSONDecodeError:
|
|
return {}
|
|
|
|
|
|
def find_repo_root(cwd: str | None) -> Path:
|
|
start = Path(cwd or Path.cwd()).resolve()
|
|
try:
|
|
result = subprocess.run(
|
|
["git", "rev-parse", "--show-toplevel"],
|
|
cwd=start,
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
return Path(result.stdout.strip()).resolve()
|
|
except Exception:
|
|
return start
|
|
|
|
|
|
def main() -> int:
|
|
payload = read_payload()
|
|
root = find_repo_root(payload.get("cwd"))
|
|
required = ["PLAN.md", "PROGRESS.md"]
|
|
missing = [name for name in required if not (root / name).exists()]
|
|
|
|
context = (
|
|
"Before starting work in this repository, read PLAN.md and PROGRESS.md. "
|
|
"Use PROGRESS.md as the factual state, update PLAN.md when sequencing changes, "
|
|
"and keep samples/ out of commits unless the user explicitly requests otherwise."
|
|
)
|
|
|
|
output = {
|
|
"continue": True,
|
|
"hookSpecificOutput": {
|
|
"hookEventName": "SessionStart",
|
|
"additionalContext": context,
|
|
},
|
|
}
|
|
if missing:
|
|
output["systemMessage"] = "Missing project coordination file(s): " + ", ".join(missing)
|
|
|
|
print(json.dumps(output, ensure_ascii=True))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|