feat(plane): unified status-comment format with duration line (ORCH-016) (#34)
This commit was merged in pull request #34.
This commit is contained in:
@@ -507,11 +507,15 @@ class AgentLauncher:
|
||||
from ..notifications import send_telegram
|
||||
send_telegram(f"\u26a0\ufe0f {_wid}: Agent {agent} failed (exit_code={exit_code}). Check logs: /app/data/runs/{run_id}.log")
|
||||
|
||||
# Feature 4: post the per-agent usage comment under that agent's bot, and
|
||||
# — for the deployer finishing the task — the per-task usage summary.
|
||||
# Feature 4 + ORCH-016: post the unified per-agent status comment under
|
||||
# that agent's bot, threading the wall-clock duration we just measured
|
||||
# straight through (ADR-001 §6: explicit param wins over DB fallback).
|
||||
# The deployer finishing the task also posts the per-task usage summary.
|
||||
if exit_code == 0:
|
||||
try:
|
||||
self._post_usage_comments(run_id, agent, repo, branch, _usage)
|
||||
self._post_usage_comments(
|
||||
run_id, agent, repo, branch, _usage, duration_s=_duration_s
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"run_id={run_id}: usage comment failed: {e}")
|
||||
|
||||
@@ -679,42 +683,67 @@ class AgentLauncher:
|
||||
logger.error(f"Auto-advance failed for run_id={run_id}: {e}")
|
||||
|
||||
|
||||
def _post_usage_comments(self, run_id, agent, repo, branch, usage):
|
||||
"""Feature 4: post the per-agent usage comment (and Deployer summary).
|
||||
def _post_usage_comments(self, run_id, agent, repo, branch, usage, duration_s=None):
|
||||
"""Feature 4 + ORCH-016: post the unified per-agent status comment.
|
||||
|
||||
- Always (on success, with a work_item_id): a per-agent finish comment
|
||||
with token/cost, authored by the finishing agent's Plane bot.
|
||||
via ``usage.build_status_comment(...)``, authored by the finishing
|
||||
agent's Plane bot. The comment carries:
|
||||
* single-line header (icon + role + per-stage description),
|
||||
* machine verdict line for reviewer / tester / deployer (when the
|
||||
relevant frontmatter is present in the worktree),
|
||||
* the agent's wall-clock duration (``duration_s`` is the measured
|
||||
value in _monitor_agent; DB fallback is unused on this path),
|
||||
* an HTML <ul> of artifact links scoped per agent,
|
||||
* a ``<sub>`` token/cost tail.
|
||||
- When the deployer finishes: also a per-task summary (SUM over
|
||||
agent_runs GROUP BY agent), authored by the deployer.
|
||||
|
||||
The deployer's `stage=` is resolved from the task row so the helper can
|
||||
pick between 14-deploy-log.md (prod) and 15-staging-log.md (staging).
|
||||
"""
|
||||
from ..usage import usage_comment, task_summary_comment
|
||||
from ..usage import build_status_comment, task_summary_comment
|
||||
from ..git_worktree import get_worktree_path
|
||||
conn = get_db()
|
||||
row = conn.execute(
|
||||
"SELECT id, work_item_id FROM tasks WHERE repo=? AND branch=?",
|
||||
"SELECT id, work_item_id, stage FROM tasks WHERE repo=? AND branch=?",
|
||||
(repo, branch),
|
||||
).fetchone()
|
||||
conn.close()
|
||||
if not row:
|
||||
return
|
||||
task_id, work_item_id = row[0], row[1]
|
||||
task_id, work_item_id, stage = row[0], row[1], row[2]
|
||||
if not work_item_id:
|
||||
return
|
||||
# Observability: every agent's finish comment links its artifact(s)
|
||||
# (reviewer->12-review, tester->13-test-report, deployer->14-deploy-log,
|
||||
# (reviewer->12-review, tester->13-test-report, deployer->14- or 15-,
|
||||
# architect->ADR, developer->PR/branch). For the developer we resolve the
|
||||
# open PR number so the link points straight at it.
|
||||
pr_number = None
|
||||
if agent == "developer":
|
||||
pr_number = self._open_pr_number(repo, branch)
|
||||
|
||||
# Best-effort worktree path — drives AC-8 (skip missing artifacts) and
|
||||
# the verdict frontmatter read. Falls back to None on lookup error so
|
||||
# the comment still goes out without the verdict line / file probe.
|
||||
try:
|
||||
worktree_root = get_worktree_path(repo, branch)
|
||||
except Exception:
|
||||
worktree_root = None
|
||||
|
||||
plane_add_comment(
|
||||
work_item_id,
|
||||
usage_comment(
|
||||
build_status_comment(
|
||||
agent,
|
||||
usage,
|
||||
repo=repo,
|
||||
branch=branch,
|
||||
work_item_id=work_item_id,
|
||||
pr_number=pr_number,
|
||||
stage=stage,
|
||||
usage=usage,
|
||||
duration_s=duration_s,
|
||||
task_id=task_id,
|
||||
worktree_root=worktree_root,
|
||||
),
|
||||
author=agent,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user