diff --git a/agents/angela_briefing.py b/agents/angela_briefing.py index afc0715..e636861 100644 --- a/agents/angela_briefing.py +++ b/agents/angela_briefing.py @@ -10,7 +10,8 @@ CONFIG = { "agent_id": "angela-daily-briefing", "instance_id": INSTANCE_ID, "user_id": 3, - "wiki_parent_doc_id": "65966bd6-4ef8-4b79-9b79-e4aa62b94e96", + "wiki_collection_id": "b6efa6b9-44b5-48c1-b82e-2e6efe36e3eb", # Angela's ScratchPad + "wiki_parent_doc_id": "410759a9-4a3b-4881-8ad1-3190cefa760f", # Daily Briefings in Angela's ScratchPad "location": { "name": "Providence", "state": "Utah", diff --git a/agents/daily_briefing.py b/agents/daily_briefing.py index 542595f..982ec22 100644 --- a/agents/daily_briefing.py +++ b/agents/daily_briefing.py @@ -9,7 +9,7 @@ with a config dict specifying location, wiki parent, and agent ID. import sys from datetime import datetime from shared import ( - MT, DASHBOARD_API, WIKI_API, WIKI_COLLECTION_ID, MONTH_NAMES, + MT, DASHBOARD_API, WIKI_API, WIKI_COLLECTION_ID as DEFAULT_WIKI_COLLECTION, MONTH_NAMES, api_request, log_run, wiki_headers, find_child_doc, ensure_child_doc, ) @@ -138,6 +138,7 @@ def compose_briefing(config, sections): def post_to_wiki(config, markdown, date_str): """Post the briefing to wiki under Year/Month hierarchy.""" + wiki_collection = config.get("wiki_collection_id", DEFAULT_WIKI_COLLECTION) wiki_parent_id = config["wiki_parent_doc_id"] now = datetime.now(MT) year_str = str(now.year) @@ -146,14 +147,16 @@ def post_to_wiki(config, markdown, date_str): year_id = ensure_child_doc( wiki_parent_id, year_str, f"Daily briefings for {year_str}.", + collection_id=wiki_collection, ) month_id = ensure_child_doc( year_id, month_str, f"Daily briefings for {month_str} {year_str}.", + collection_id=wiki_collection, ) title = f"Daily Briefing — {date_str}" - doc_id = find_child_doc(month_id, title) + doc_id = find_child_doc(month_id, title, collection_id=wiki_collection) if doc_id: api_request( @@ -169,7 +172,7 @@ def post_to_wiki(config, markdown, date_str): data={ "title": title, "text": markdown, - "collectionId": WIKI_COLLECTION_ID, + "collectionId": wiki_collection, "parentDocumentId": month_id, "publish": True, }, diff --git a/agents/eric_briefing.py b/agents/eric_briefing.py index a7e38e4..5b968e9 100644 --- a/agents/eric_briefing.py +++ b/agents/eric_briefing.py @@ -11,7 +11,8 @@ CONFIG = { "agent_id": "eric-daily-briefing", "instance_id": INSTANCE_ID, "user_id": 2, - "wiki_parent_doc_id": "2a891fe8-579b-450b-a663-de93915896b7", + "wiki_collection_id": "5663a756-babe-4997-9d92-d02b53fce392", # Eric's ScratchPad + "wiki_parent_doc_id": "e61ba5be-057b-48aa-ab5e-6ecc248eb8c4", # Daily Briefings in Eric's ScratchPad "location": { "name": "Providence", "state": "Utah", diff --git a/agents/project_monitor.py b/agents/project_monitor.py index 5bf8f2f..90d83ad 100644 --- a/agents/project_monitor.py +++ b/agents/project_monitor.py @@ -192,41 +192,78 @@ def fetch_url_content(urls_text): def post_report_to_wiki(report_md, project_name, collection_id): - """Post the full report to a wiki collection.""" + """Post the full report to a wiki collection under 'Project Status Reports' parent.""" if not collection_id: return None + from shared import ensure_child_doc, find_child_doc + now = datetime.now(MT) - title = f"Project Status — {project_name} — {now.strftime('%Y-%m-%d')}" 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 + if not reports_parent_id: + try: + result = api_request( + f"{WIKI_API}/documents.create", + data={"title": "Project Status Reports", + "text": "Automated project status reports.", + "collectionId": collection_id, "publish": True}, + headers=headers, method="POST", + ) + reports_parent_id = result["data"]["id"] + except Exception: + reports_parent_id = None + + title = f"Project Status — {project_name} — {now.strftime('%Y-%m-%d')}" + # Check for existing report today try: search = api_request( f"{WIKI_API}/documents.search", data={"query": title, "collectionId": collection_id}, - headers=headers, - method="POST", + headers=headers, method="POST", ) for doc in search.get("data", []): if doc.get("document", {}).get("title") == title: api_request( f"{WIKI_API}/documents.update", data={"id": doc["document"]["id"], "text": report_md, "publish": True}, - headers=headers, - method="POST", + headers=headers, method="POST", ) return doc["document"]["id"] except Exception: pass - # Create new + # Create new under the reports parent try: + create_data = {"title": title, "text": report_md, "collectionId": collection_id, "publish": True} + if reports_parent_id: + create_data["parentDocumentId"] = reports_parent_id result = api_request( f"{WIKI_API}/documents.create", - data={"title": title, "text": report_md, "collectionId": collection_id, "publish": True}, - headers=headers, - method="POST", + data=create_data, headers=headers, method="POST", ) return result["data"]["id"] except Exception as e: diff --git a/agents/shared.py b/agents/shared.py index 2c16cf6..dfd9251 100644 --- a/agents/shared.py +++ b/agents/shared.py @@ -81,11 +81,12 @@ def wiki_headers(): return {"Authorization": f"Bearer {WIKI_TOKEN}"} -def find_child_doc(parent_id, title): +def find_child_doc(parent_id, title, collection_id=None): """Search for a child doc by title under a given parent.""" + coll = collection_id or WIKI_COLLECTION_ID result = api_request( f"{WIKI_API}/documents.search", - data={"query": title, "collectionId": WIKI_COLLECTION_ID}, + data={"query": title, "collectionId": coll}, headers=wiki_headers(), method="POST", ) @@ -96,9 +97,10 @@ def find_child_doc(parent_id, title): return None -def ensure_child_doc(parent_id, title, body): +def ensure_child_doc(parent_id, title, body, collection_id=None): """Find or create a child doc under a parent. Returns doc ID.""" - doc_id = find_child_doc(parent_id, title) + coll = collection_id or WIKI_COLLECTION_ID + doc_id = find_child_doc(parent_id, title, collection_id=coll) if doc_id: return doc_id result = api_request( @@ -106,7 +108,7 @@ def ensure_child_doc(parent_id, title, body): data={ "title": title, "text": body, - "collectionId": WIKI_COLLECTION_ID, + "collectionId": coll, "parentDocumentId": parent_id, "publish": True, },