@soleur/opencode 3.399.3 → 3.399.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# run-health-emit.sh — upsert a phase entry into run_health.json + snapshot prompt text.
|
|
3
|
+
# Usage:
|
|
4
|
+
# run-health-emit.sh --run-dir <dir> [--run-id <id>] [--issue <N>] [--branch <b>] [--harness <h>]
|
|
5
|
+
# --phase <name> --status <started|completed|failed|budget-capped>
|
|
6
|
+
# [--prompt-file <path>] [--error <msg>] [--reviewed-coverage <v>]
|
|
7
|
+
# Idempotent: re-invoking with the same phase updates the existing entry rather than duplicating.
|
|
8
|
+
# Storage is under .soleur/runs/<run-id>/ (gitignored). Emission failures are non-fatal: the
|
|
9
|
+
# script exits 0 on best-effort write errors after printing a warning to stderr.
|
|
10
|
+
set -u
|
|
11
|
+
|
|
12
|
+
RUN_DIR=""
|
|
13
|
+
RUN_ID=""
|
|
14
|
+
ISSUE=""
|
|
15
|
+
BRANCH=""
|
|
16
|
+
HARNESS="${SOLEUR_HARNESS:-unknown}"
|
|
17
|
+
PHASE=""
|
|
18
|
+
STATUS=""
|
|
19
|
+
PROMPT_FILE=""
|
|
20
|
+
ERROR_MSG=""
|
|
21
|
+
REVIEWED_COVERAGE=""
|
|
22
|
+
|
|
23
|
+
while [[ $# -gt 0 ]]; do
|
|
24
|
+
case "$1" in
|
|
25
|
+
--run-dir) RUN_DIR="$2"; shift 2 ;;
|
|
26
|
+
--run-id) RUN_ID="$2"; shift 2 ;;
|
|
27
|
+
--issue) ISSUE="$2"; shift 2 ;;
|
|
28
|
+
--branch) BRANCH="$2"; shift 2 ;;
|
|
29
|
+
--harness) HARNESS="$2"; shift 2 ;;
|
|
30
|
+
--phase) PHASE="$2"; shift 2 ;;
|
|
31
|
+
--status) STATUS="$2"; shift 2 ;;
|
|
32
|
+
--prompt-file) PROMPT_FILE="$2"; shift 2 ;;
|
|
33
|
+
--error) ERROR_MSG="$2"; shift 2 ;;
|
|
34
|
+
--reviewed-coverage) REVIEWED_COVERAGE="$2"; shift 2 ;;
|
|
35
|
+
*) echo "run-health-emit: unknown arg $1" >&2; shift ;;
|
|
36
|
+
esac
|
|
37
|
+
done
|
|
38
|
+
|
|
39
|
+
if [[ -z "$RUN_DIR" || -z "$PHASE" || -z "$STATUS" ]]; then
|
|
40
|
+
echo "run-health-emit: --run-dir, --phase, --status required" >&2
|
|
41
|
+
exit 0
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
mkdir -p "$RUN_DIR/phase_prompts" 2>/dev/null || { echo "run-health-emit: cannot create $RUN_DIR" >&2; exit 0; }
|
|
45
|
+
|
|
46
|
+
HEALTH="$RUN_DIR/run_health.json"
|
|
47
|
+
NOW="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
48
|
+
|
|
49
|
+
# Resolve run metadata: prefer existing file, then args, then defaults.
|
|
50
|
+
if [[ -z "$RUN_ID" ]]; then
|
|
51
|
+
if [[ -f "$HEALTH" ]]; then
|
|
52
|
+
RUN_ID="$(python3 -c "import json,sys;print(json.load(open('$HEALTH')).get('run_id',''))" 2>/dev/null)"
|
|
53
|
+
fi
|
|
54
|
+
[[ -z "$RUN_ID" ]] && RUN_ID="$(basename "$RUN_DIR")"
|
|
55
|
+
fi
|
|
56
|
+
[[ -z "$BRANCH" ]] && BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)"
|
|
57
|
+
[[ -z "$ISSUE" ]] && ISSUE=""
|
|
58
|
+
|
|
59
|
+
python3 - "$HEALTH" "$RUN_ID" "$ISSUE" "$BRANCH" "$HARNESS" "$PHASE" "$STATUS" "$NOW" "$ERROR_MSG" "$REVIEWED_COVERAGE" "$PROMPT_FILE" "$RUN_DIR" <<'PY' 2>/dev/null || echo "run-health-emit: python write failed (non-fatal)" >&2
|
|
60
|
+
import json, os, sys, shutil
|
|
61
|
+
|
|
62
|
+
(health, run_id, issue, branch, harness, phase, status, now, err, rcov, prompt_file, run_dir) = sys.argv[1:13]
|
|
63
|
+
|
|
64
|
+
data = {}
|
|
65
|
+
if os.path.exists(health):
|
|
66
|
+
try:
|
|
67
|
+
with open(health) as f:
|
|
68
|
+
data = json.load(f)
|
|
69
|
+
except Exception:
|
|
70
|
+
data = {}
|
|
71
|
+
|
|
72
|
+
data.setdefault("run_id", run_id)
|
|
73
|
+
data.setdefault("issue", issue)
|
|
74
|
+
data.setdefault("branch", branch)
|
|
75
|
+
data.setdefault("harness", harness)
|
|
76
|
+
data.setdefault("started_at", now)
|
|
77
|
+
data.setdefault("phases", [])
|
|
78
|
+
data.setdefault("errors", [])
|
|
79
|
+
if rcov:
|
|
80
|
+
data["reviewed_coverage"] = rcov
|
|
81
|
+
|
|
82
|
+
# Find existing phase entry.
|
|
83
|
+
entry = None
|
|
84
|
+
for p in data["phases"]:
|
|
85
|
+
if p.get("phase") == phase:
|
|
86
|
+
entry = p
|
|
87
|
+
break
|
|
88
|
+
if entry is None:
|
|
89
|
+
entry = {"phase": phase, "started_at": now}
|
|
90
|
+
data["phases"].append(entry)
|
|
91
|
+
|
|
92
|
+
entry["status"] = status
|
|
93
|
+
if status in ("completed", "failed", "budget-capped"):
|
|
94
|
+
entry["ended_at"] = now
|
|
95
|
+
elif "started_at" not in entry:
|
|
96
|
+
entry["started_at"] = now
|
|
97
|
+
|
|
98
|
+
if err:
|
|
99
|
+
entry.setdefault("errors", []).append({"at": now, "msg": err})
|
|
100
|
+
data["errors"].append({"phase": phase, "at": now, "msg": err})
|
|
101
|
+
|
|
102
|
+
if status in ("completed", "failed", "budget-capped") and not data.get("completed_at"):
|
|
103
|
+
# only seal completed_at when terminal status on the final phase; leave open otherwise
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
# Seal completed_at only when status is a terminal run status.
|
|
107
|
+
if status in ("completed", "failed", "budget-capped"):
|
|
108
|
+
# heuristic: seal if phase looks like a finalizer name
|
|
109
|
+
if phase.lower() in ("8", "ship", "done", "final", "exit", "terminate"):
|
|
110
|
+
data["completed_at"] = now
|
|
111
|
+
data["status"] = status
|
|
112
|
+
|
|
113
|
+
# Snapshot prompt file (append-only per attempt).
|
|
114
|
+
if prompt_file and os.path.exists(prompt_file):
|
|
115
|
+
pp_dir = os.path.join(run_dir, "phase_prompts")
|
|
116
|
+
os.makedirs(pp_dir, exist_ok=True)
|
|
117
|
+
base = os.path.join(pp_dir, f"{phase}.md")
|
|
118
|
+
if os.path.exists(base):
|
|
119
|
+
# find next attempt number
|
|
120
|
+
n = 2
|
|
121
|
+
while os.path.exists(os.path.join(pp_dir, f"{phase}.attempt-{n}.md")):
|
|
122
|
+
n += 1
|
|
123
|
+
dest = os.path.join(pp_dir, f"{phase}.attempt-{n}.md")
|
|
124
|
+
else:
|
|
125
|
+
dest = base
|
|
126
|
+
shutil.copyfile(prompt_file, dest)
|
|
127
|
+
entry["prompt_snapshot"] = os.path.relpath(dest, run_dir)
|
|
128
|
+
|
|
129
|
+
# Write atomically.
|
|
130
|
+
tmp = health + ".tmp"
|
|
131
|
+
with open(tmp, "w") as f:
|
|
132
|
+
json.dump(data, f, indent=2)
|
|
133
|
+
f.write("\n")
|
|
134
|
+
os.replace(tmp, health)
|
|
135
|
+
PY
|
|
136
|
+
|
|
137
|
+
exit 0
|
|
138
|
+
PY
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Tests for run-health-emit.sh
|
|
3
|
+
|
|
4
|
+
set -uo pipefail
|
|
5
|
+
export TMPDIR="${TMPDIR:-/var/tmp}"
|
|
6
|
+
|
|
7
|
+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
+
SUT="$DIR/run-health-emit.sh"
|
|
9
|
+
|
|
10
|
+
TMP="$(mktemp -d -t runhealth.XXXXXXXX)" || { echo "mktemp failed" >&2; exit 2; }
|
|
11
|
+
trap 'rm -rf "$TMP"' EXIT
|
|
12
|
+
|
|
13
|
+
passes=0; fails=0
|
|
14
|
+
pass() { passes=$((passes + 1)); printf ' ok %s\n' "$1"; }
|
|
15
|
+
fail() { fails=$((fails + 1)); printf ' FAIL %s\n' "$1"; [[ -n "${2:-}" ]] && printf ' %s\n' "$2"; return 0; }
|
|
16
|
+
|
|
17
|
+
# Case 1: creates run_health.json with required fields
|
|
18
|
+
RD="$TMP/run1"
|
|
19
|
+
printf 'prompt text' > "$TMP/p.md"
|
|
20
|
+
bash "$SUT" --run-dir "$RD" --run-id r1 --issue 12573 --branch b --harness opencode --phase 0 --status started --prompt-file "$TMP/p.md"
|
|
21
|
+
if [[ -f "$RD/run_health.json" ]] && python3 -c "import json,sys; d=json.load(open('$RD/run_health.json')); sys.exit(0 if d['run_id']=='r1' and d['issue']=='12573' and len(d['phases'])==1 else 1)"; then
|
|
22
|
+
pass "creates run_health.json with required fields"
|
|
23
|
+
else
|
|
24
|
+
fail "creates run_health.json with required fields"
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
# Case 2: idempotent upsert (same phase updates, no duplicate)
|
|
28
|
+
bash "$SUT" --run-dir "$RD" --phase 0 --status completed
|
|
29
|
+
N=$(python3 -c "import json; print(len(json.load(open('$RD/run_health.json'))['phases']))")
|
|
30
|
+
if [[ "$N" == "1" ]]; then pass "idempotent upsert (no duplicate phase)"; else fail "idempotent upsert" "got $N"; fi
|
|
31
|
+
|
|
32
|
+
# Case 3: prompt snapshot created and not overwritten on retry
|
|
33
|
+
if [[ -f "$RD/phase_prompts/0.md" ]] && grep -q "prompt text" "$RD/phase_prompts/0.md"; then
|
|
34
|
+
pass "prompt snapshot created"
|
|
35
|
+
else
|
|
36
|
+
fail "prompt snapshot created"
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# Case 4: retry creates attempt-2 file, preserves original
|
|
40
|
+
printf 'retry prompt' > "$TMP/p2.md"
|
|
41
|
+
bash "$SUT" --run-dir "$RD" --phase 0 --status started --prompt-file "$TMP/p2.md"
|
|
42
|
+
if [[ -f "$RD/phase_prompts/0.attempt-2.md" ]] && grep -q "retry prompt" "$RD/phase_prompts/0.attempt-2.md" && grep -q "prompt text" "$RD/phase_prompts/0.md"; then
|
|
43
|
+
pass "retry preserves original snapshot"
|
|
44
|
+
else
|
|
45
|
+
fail "retry preserves original snapshot"
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Case 5: missing required args exits 0 (non-fatal)
|
|
49
|
+
bash "$SUT" --run-dir "$RD" 2>/dev/null; rc=$?
|
|
50
|
+
if [[ "$rc" == "0" ]]; then pass "missing args non-fatal"; else fail "missing args non-fatal" "rc=$rc"; fi
|
|
51
|
+
|
|
52
|
+
echo "passes=$passes fails=$fails"
|
|
53
|
+
[[ "$fails" -eq 0 ]]
|
|
@@ -24,6 +24,16 @@ Autonomous test-fix iteration loop. Run the test suite, diagnose failures, apply
|
|
|
24
24
|
- NOT for writing new tests (use `atdd-developer`)
|
|
25
25
|
- NOT for linting, type-checking, or non-test failures
|
|
26
26
|
|
|
27
|
+
## Run Health Emission (Phase 1 prerequisite, #12573)
|
|
28
|
+
|
|
29
|
+
This skill MUST emit a sealed run-health artifact so the degraded-run forensics agent (#12574) can correlate prompts to failures from disk. Contract: `plugins/soleur/skills/one-shot/references/run-health-schema.md` (shared).
|
|
30
|
+
|
|
31
|
+
- Run id: `<branch>-tfl-<utc-timestamp>`; storage: `.soleur/runs/<run-id>/` (gitignored).
|
|
32
|
+
- At Phase 0 (after test command detection), initialize `RUN_DIR` and emit phase `0` status `started` (snapshot the detected command + args).
|
|
33
|
+
- At each iteration's Parse/Cluster/Fix boundaries and at every termination condition, emit the corresponding phase (`iter-N-parse`, `iter-N-fix`, `terminate`) with status.
|
|
34
|
+
- On termination (success or failure), emit phase `exit` with status `completed`/`failed` and record remaining failures via `--error`.
|
|
35
|
+
- Emission is best-effort and never blocks the loop (helper exits 0 on write errors).
|
|
36
|
+
|
|
27
37
|
## Phase 0: Detect and Confirm
|
|
28
38
|
|
|
29
39
|
### Detect Test Runner
|