diff --git a/container/entrypoint.py b/container/entrypoint.py index 24d175c..55931fb 100644 --- a/container/entrypoint.py +++ b/container/entrypoint.py @@ -193,6 +193,25 @@ def move_task_to_bucket(pm_token: str, bucket_id: str) -> None: log.warning("Failed to move task to bucket %s: %s", bucket_id, e) +def post_task_comment(pm_token: str, rc: int) -> None: + """Post a completion comment on the Vikunja task.""" + if rc == 0: + body = f"✅ **{AGENT_ROLE}** agent completed this task and moved it to In Review." + else: + body = f"⚠️ **{AGENT_ROLE}** agent finished with exit code {rc}. Task moved to In Review for manual check." + try: + resp = httpx.put( + f"{VIKUNJA_BASE_URL}/api/v1/tasks/{TASK_ID}/comments", + headers={"Authorization": f"Bearer {pm_token}", "Content-Type": "application/json"}, + json={"comment": body}, + timeout=10, + ) + resp.raise_for_status() + log.info("Posted completion comment on task %s", TASK_ID) + except Exception as e: + log.warning("Failed to post task comment: %s", e) + + def main() -> None: log.info("Agent entrypoint: role=%s task=%s", AGENT_ROLE, TASK_ID) @@ -203,7 +222,7 @@ def main() -> None: write_opencode_config(secrets, AGENT_ROLE) configure_git_identity() - # Fetch pm token for bucket moves (admin operation) + # Fetch pm token for bucket moves and comments (admin operation) pm_token = "" try: pm_token = get_secret(bao_token, "autojanet/pm/vikunja-token", "token") @@ -214,8 +233,9 @@ def main() -> None: prompt = build_prompt(TASK_ID, TASK_TITLE) rc = run_opencode(prompt) - # Move to In Review regardless of exit code — work was attempted + # Always post comment and move bucket regardless of exit code if pm_token: + post_task_comment(pm_token, rc) move_task_to_bucket(pm_token, IN_REVIEW_BUCKET_ID) if rc != 0: