ci / lint (push) Skipped
ci / lint (pull_request) Successful in 11s
Fixes from a full repo review: - fetch-thread.sh: attribute every comment to its REAL author (@pm/@qa/… — agents post as their own users now); the old "🤖 @name line at the top" hint pointed at headers we removed, leaving every teammate comment anonymous. Also strip the hidden loop-prevention marker from bodies (prompt noise). - agent.yml: per-issue concurrency group (queued, no cancel) — two quick comments on one issue no longer race the same ai/issue-N branch. - rescue-pr.sh: after opening a rescue PR, hand it back into the flow with an unmarked @pm trigger (the pm→qa choreography previously stalled silently on any rescued run); drop the old "🤖 **@name**" header style; add ops to the token case; mark the status note with the hidden marker. - README: token table said "@qa merges / TOKEN_QA needs write:repository" — inverted since the PM-orchestrated flow (@pm merges, autopilot only; @qa is read-only). Updated the agent table (descs, node1-ssh moved to homelab) and added a "How a task flows" section. - agents.json: pm/qa descs now describe the orchestrator/reviewer roles (these feed the roster prompt agents route by). - NEW ci.yml: bash -n + shellcheck(-S error) on every script, YAML-parse on every workflow, agents.json schema check — the ${x:-{}} brace bug would have been caught here before it shipped. - install-opencode.sh: pin opencode (default 1.17.13, override via OPENCODE_VERSION) — a breaking release no longer takes down every agent. - build-activity-log.sh: ollama/ollama-cloud models are subscription-billed (no $/token exists) — label the footer "subscription" instead of a misleading $0.0000; metered (anthropic) models keep the real dollar cost. - route.sh: document that mention-priority is list-order and load-bearing for the flow's trigger comments. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58 lines
3.0 KiB
Bash
Executable File
58 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build the RUN REPORT appended to the agent's reply comment: the TOOL CALLS the agent made plus a
|
|
# usage line (input / output tokens + $ cost). Written to /tmp/activity_log.md; the Publish step
|
|
# appends it to the agent's reply. Applies to EVERY agent — @pm/@qa also call tools and cost money.
|
|
#
|
|
# opencode --format json emits one JSON event per line. `step_finish` events carry, per LLM step,
|
|
# .part.tokens {input, output, reasoning, cache:{read, write}} and .part.cost (USD, already computed
|
|
# by opencode from the model's pricing). We sum them across all steps of the run. Models without
|
|
# pricing (e.g. self-hosted ollama) report cost 0 — shown as $0.0000.
|
|
#
|
|
# Required env (provided by the workflow step): (none needed; reads /tmp/events.jsonl)
|
|
set -u
|
|
E=/tmp/events.jsonl
|
|
: > /tmp/activity_log.md
|
|
[ -s "$E" ] || { echo "no events — empty report"; exit 0; }
|
|
|
|
# Tool calls = the ACTIONS taken (not the agent's prose text parts).
|
|
jq -r '
|
|
def trunc(n): if length > n then (.[0:n] + "…") else . end;
|
|
select(.type=="tool_use") |
|
|
(.part.tool // "?") as $t |
|
|
((.part.state.title // (.part.state.input | tojson | trunc(160)) // "")) as $title |
|
|
"🔧 **" + $t + "**: `" + ($title | trunc(240)) + "`"
|
|
' "$E" > /tmp/tools.md 2>/dev/null || true
|
|
n=$(wc -l < /tmp/tools.md 2>/dev/null || echo 0); n=${n:-0}
|
|
|
|
# Usage: sum per-step tokens + cost across every step_finish event (tab-separated for `read`).
|
|
read -r COST INP OUT CR CW RE < <(jq -rs '
|
|
[ .[] | select(.type=="step_finish") | .part ] as $s
|
|
| [ ([$s[].cost // 0]|add // 0),
|
|
([$s[].tokens.input // 0]|add // 0),
|
|
([$s[].tokens.output // 0]|add // 0),
|
|
([$s[].tokens.cache.read // 0]|add // 0),
|
|
([$s[].tokens.cache.write // 0]|add // 0),
|
|
([$s[].tokens.reasoning // 0]|add // 0) ]
|
|
| @tsv' "$E" 2>/dev/null)
|
|
COST=${COST:-0}; INP=${INP:-0}; OUT=${OUT:-0}; CR=${CR:-0}; CW=${CW:-0}; RE=${RE:-0}
|
|
IN_TOTAL=$(( INP + CR + CW )) # total input context processed
|
|
# Cost label: ollama / ollama-cloud models are SUBSCRIPTION-billed (GPU-time against the plan, no
|
|
# $/token price exists), so a "$0.0000" there would be misleading — label it a subscription instead.
|
|
# Metered providers (anthropic/…) get the real dollar cost opencode computed.
|
|
case "${MODEL:-}" in
|
|
ollama*|*"/ollama"*) COSTF="subscription" ;;
|
|
*) COSTF=$(awk -v c="$COST" 'BEGIN{printf "$%.4f", c+0}') ;;
|
|
esac
|
|
echo "usage: in=$IN_TOTAL out=$OUT cost=$COSTF (fresh=$INP cache_r=$CR cache_w=$CW reasoning=$RE); tools=$n"
|
|
|
|
{
|
|
if [ "$n" -gt 0 ]; then
|
|
printf '\n\n<details>\n<summary>🔧 %s tool calls · in %s · out %s · %s</summary>\n\n' "$n" "$IN_TOTAL" "$OUT" "$COSTF"
|
|
cat /tmp/tools.md
|
|
printf '\n\n<sub>tokens — input %s (fresh %s · cache %sw / %sr) · output %s · reasoning %s · **%s**</sub>\n</details>' \
|
|
"$IN_TOTAL" "$INP" "$CW" "$CR" "$OUT" "$RE" "$COSTF"
|
|
else
|
|
printf '\n\n<sub>💰 **%s** · in %s · out %s tokens (cache %sw / %sr)</sub>' "$COSTF" "$IN_TOTAL" "$OUT" "$CW" "$CR"
|
|
fi
|
|
} > /tmp/activity_log.md
|