From f39bd13fc63e472f2ecbdbcc34228864f9245ff3 Mon Sep 17 00:00:00 2001 From: Eric Jungbauer Date: Mon, 13 Apr 2026 16:12:27 +0000 Subject: [PATCH] Fix wiki report posting - handle root-level parent doc creation --- agents/project_monitor.py | 47 +++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/agents/project_monitor.py b/agents/project_monitor.py index d3124ae..7e97f41 100644 --- a/agents/project_monitor.py +++ b/agents/project_monitor.py @@ -196,45 +196,38 @@ def post_report_to_wiki(report_md, project_name, collection_id): if not collection_id: return None - from shared import ensure_child_doc, find_child_doc - now = datetime.now(MT) headers = wiki_headers() - # Ensure "Project Status Reports" parent doc exists in this collection - reports_parent_id = ensure_child_doc( - None, "Project Status Reports", - "Automated project status reports generated by the Project Monitor agent.", - collection_id=collection_id, - ) - # ensure_child_doc with parent_id=None won't find via parentDocumentId match. - # Search manually for root-level doc in this collection. - if not reports_parent_id: - try: - search = api_request( - f"{WIKI_API}/documents.search", - data={"query": "Project Status Reports", "collectionId": collection_id}, - headers=headers, method="POST", - ) - for doc in search.get("data", []): - d = doc.get("document", {}) - if d.get("title") == "Project Status Reports" and d.get("collectionId") == collection_id: - reports_parent_id = d["id"] - break - except Exception: - pass + # Find or create "Project Status Reports" parent doc at root of this collection + reports_parent_id = None + try: + search = api_request( + f"{WIKI_API}/documents.search", + data={"query": "Project Status Reports", "collectionId": collection_id}, + headers=headers, method="POST", + ) + for doc in search.get("data", []): + d = doc.get("document", {}) + if d.get("title") == "Project Status Reports" and not d.get("parentDocumentId"): + reports_parent_id = d["id"] + break + except Exception: + pass + if not reports_parent_id: try: result = api_request( f"{WIKI_API}/documents.create", data={"title": "Project Status Reports", - "text": "Automated project status reports.", + "text": "Automated project status reports generated by the Project Monitor agent.", "collectionId": collection_id, "publish": True}, headers=headers, method="POST", ) reports_parent_id = result["data"]["id"] - except Exception: - reports_parent_id = None + print(f" Created Project Status Reports parent: {reports_parent_id}") + except Exception as e: + print(f" Warning: could not create reports parent: {e}", file=sys.stderr) title = f"Project Status — {project_name} — {now.strftime('%Y-%m-%d')}"