@data-matters.io/agent-harness 0.1.5 → 0.1.6

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-matters.io/agent-harness",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Spec-Driven Development with Claude Code: gates, task loop and standards installed into a product repository",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -28,7 +28,7 @@ harness_load_env() {
28
28
  # the session's environment: only notify.sh needs them, and it reads the env file
29
29
  # itself. TELEGRAM_STATE_DIR from the env file is kept.
30
30
  # shellcheck disable=SC2034 # used by the scripts that source this file
31
- HARNESS_CLAUDE=(env -u HARNESS_TELEGRAM_BOT_TOKEN -u HARNESS_TELEGRAM_CHAT_ID -u HARNESS_ANTHROPIC_API_KEY claude)
31
+ HARNESS_CLAUDE=(env -u HARNESS_TELEGRAM_BOT_TOKEN -u HARNESS_TELEGRAM_CHAT_ID -u HARNESS_ANTHROPIC_API_KEY -u HARNESS_ANTHROPIC_BASE_URL claude)
32
32
 
33
33
  # ------------------------------------------- optional API key (ADR 0020) --
34
34
  # harness_api_refused <session.json>: the session ended on an error that says
@@ -54,8 +54,12 @@ harness_api_refused() {
54
54
  # arguments or a log); when the API refuses it (harness_api_refused), the SAME
55
55
  # attempt repeats on the plan login. Which one produced the output is written to
56
56
  # <session.json>.source (api|plan), which the usage ledger reads.
57
+ # HARNESS_ANTHROPIC_BASE_URL is the optional base URL of that key (a gateway):
58
+ # it reaches the API run only, as ANTHROPIC_BASE_URL, and the plan run never
59
+ # sees it. A key from a gateway without its base URL would be sent to the
60
+ # Anthropic API and refused.
57
61
  harness_claude_session() {
58
- local secs="$1" out="$2" key="${HARNESS_ANTHROPIC_API_KEY:-}" rc=0 prompt
62
+ local secs="$1" out="$2" key="${HARNESS_ANTHROPIC_API_KEY:-}" base="${HARNESS_ANTHROPIC_BASE_URL:-}" rc=0 prompt
59
63
  shift 2
60
64
  rm -f "$out.source"
61
65
  if [[ -z "$key" ]]; then
@@ -64,14 +68,22 @@ harness_claude_session() {
64
68
  fi
65
69
  prompt="$(mktemp)"
66
70
  cat >"$prompt"
67
- ANTHROPIC_API_KEY="$key" timeout "$secs" "${HARNESS_CLAUDE[@]}" "$@" <"$prompt" >"$out" 2>&1 || rc=$?
71
+ if [[ -n "$base" ]]; then
72
+ ANTHROPIC_API_KEY="$key" ANTHROPIC_BASE_URL="$base" timeout "$secs" "${HARNESS_CLAUDE[@]}" "$@" <"$prompt" >"$out" 2>&1 || rc=$?
73
+ else
74
+ ANTHROPIC_API_KEY="$key" timeout "$secs" "${HARNESS_CLAUDE[@]}" "$@" <"$prompt" >"$out" 2>&1 || rc=$?
75
+ fi
68
76
  # Whatever the session printed, the key itself never stays in the log.
69
77
  K="$key" node -e 'const fs = require("fs"); const f = process.argv[1];
70
78
  try { const s = fs.readFileSync(f, "utf8"); if (s.includes(process.env.K)) fs.writeFileSync(f, s.split(process.env.K).join("[redacted]")); } catch {}' "$out" 2>/dev/null || true
71
79
  if (( rc != 124 )) && harness_api_refused "$out"; then
72
80
  echo "harness: the API key was refused; repeating the session on the plan login" >&2
73
81
  rc=0
74
- timeout "$secs" env -u ANTHROPIC_API_KEY "${HARNESS_CLAUDE[@]}" "$@" <"$prompt" >"$out" 2>&1 || rc=$?
82
+ if [[ -n "$base" ]]; then
83
+ timeout "$secs" env -u ANTHROPIC_API_KEY -u ANTHROPIC_BASE_URL "${HARNESS_CLAUDE[@]}" "$@" <"$prompt" >"$out" 2>&1 || rc=$?
84
+ else
85
+ timeout "$secs" env -u ANTHROPIC_API_KEY "${HARNESS_CLAUDE[@]}" "$@" <"$prompt" >"$out" 2>&1 || rc=$?
86
+ fi
75
87
  echo plan >"$out.source"
76
88
  else
77
89
  echo api >"$out.source"