@jmanuelcorral/bond-app 0.1.4 → 0.1.5
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/README.md +41 -1
- package/app/mods/bond-agents/config.js +4 -0
- package/app/mods/bond-agents/main.js +10 -5
- package/app/mods/bond-agents/model.js +47 -2
- package/app/mods/bond-board/config.js +4 -0
- package/app/mods/bond-board/main.js +500 -54
- package/app/mods/bond-board/model.js +47 -0
- package/app/mods/bond-settings/config.js +4 -0
- package/app/mods/bond-settings/main.js +689 -12
- package/app/mods/bond-settings/pi-models.js +144 -0
- package/app/mods/bond-status/config.js +4 -0
- package/app/mods/bond-titlebar/main.js +47 -43
- package/package.json +1 -1
- package/runner/Dockerfile +42 -13
- package/runner/SPIKE-BOND.md +85 -0
- package/runner/build-config/.none +0 -0
- package/runner/build-creds/.none +0 -0
- package/runner/config.example/README.md +27 -0
- package/runner/config.example/pi/models.json +22 -0
- package/runner/credentials.example.env +27 -0
- package/runner/setup.sh +496 -0
- package/runner/versions.env +30 -0
- package/scripts/app-install.ts +4 -0
- package/src/config.ts +8 -0
- package/src/core/hub-session.ts +9 -7
- package/src/core/orchestrator.ts +459 -99
- package/src/core/setup.ts +178 -0
- package/src/db/database.ts +14 -0
- package/src/db/settings-repo.ts +108 -0
- package/src/db/ticket-repo.ts +34 -4
- package/src/runner/docker-client.ts +29 -0
- package/src/runner/github-client.ts +119 -0
- package/src/runner/hc-client.ts +9 -2
- package/src/runner/image-builder.ts +146 -6
- package/src/server/app.ts +211 -7
- package/src/types.ts +40 -0
package/runner/setup.sh
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# runner/setup.sh — instalador de agentes del runner de bond-app (P1).
|
|
3
|
+
#
|
|
4
|
+
# Instala en un Debian bookworm-slim (base de la imagen del runner) los CLIs de los
|
|
5
|
+
# agentes elegidos, más `gh` (repo apt oficial de GitHub) y `azure-cli` + la extensión
|
|
6
|
+
# `azure-devops` (repo apt oficial de Microsoft), y monta en el home del usuario
|
|
7
|
+
# `runner` la config por agente que se le pase con --config y, opcionalmente,
|
|
8
|
+
# credenciales con --credentials.
|
|
9
|
+
#
|
|
10
|
+
# SEGURIDAD
|
|
11
|
+
# - Los valores de las credenciales NUNCA se loguean ni viajan por args de comando.
|
|
12
|
+
# - Una imagen construida con --credentials es un secreto local (D-A): nunca
|
|
13
|
+
# subirla a un registry.
|
|
14
|
+
# - La config horneada no lleva secretos; si hay config horneada y config inyectada
|
|
15
|
+
# por run (D7/D8), la inyectada por stdin sigue teniendo prioridad en el run.
|
|
16
|
+
#
|
|
17
|
+
# MECANISMOS VERIFICADOS (D-C, 2026-11-19):
|
|
18
|
+
# - copilot: npm oficial @github/copilot (Node 22+); autentica por variables de
|
|
19
|
+
# entorno (COPILOT_GITHUB_TOKEN/GH_TOKEN/GITHUB_TOKEN) o por el fallback de `gh`
|
|
20
|
+
# autenticado; sin formato documentado de fichero de token
|
|
21
|
+
# (docs.github.com «Authenticating GitHub Copilot CLI»). Con GH_TOKEN,
|
|
22
|
+
# «gh auth login --with-token» cubre a copilot.
|
|
23
|
+
# - agy (Antigravity CLI): instalador oficial de Google (binario único, sha512
|
|
24
|
+
# verificado, sin pin de versión: siempre la última del manifiesto oficial; la
|
|
25
|
+
# versión real queda en el manifiesto). Config:
|
|
26
|
+
# ~/.gemini/antigravity-cli/settings.json. Credenciales solo por keyring/OAuth o
|
|
27
|
+
# GEMINI_API_KEY en el entorno; sin fichero de credenciales offline
|
|
28
|
+
# (antigravity.google/docs «Authenticate») → sigue con la inyección por stdin.
|
|
29
|
+
# - codex: auth.json con OPENAI_API_KEY en ~/.codex; config en ~/.codex/config.toml.
|
|
30
|
+
# - claude: settings.json en ~/.claude; token de larga duración («claude
|
|
31
|
+
# setup-token») en ~/.claude/.credentials.json con formato claudeAiOauth
|
|
32
|
+
# (en Linux sin keyring es el fichero que usa la propia CLI).
|
|
33
|
+
# - azure-cli: repo apt de packages.microsoft.com soporta bookworm
|
|
34
|
+
# (learn.microsoft.com «Install the Azure CLI on Linux»).
|
|
35
|
+
#
|
|
36
|
+
# Excepciones a la regla «sin credenciales en la imagen» (D8): la horneada con
|
|
37
|
+
# --credentials es la excepción acotada por D-A/D-E; el flujo por defecto (opción A)
|
|
38
|
+
# no la usa.
|
|
39
|
+
#
|
|
40
|
+
# Uso:
|
|
41
|
+
# setup.sh --agents pi,copilot [--config DIR] [--credentials FICHERO]
|
|
42
|
+
# Variables de entorno (para pruebas; en producción se usan los valores por defecto):
|
|
43
|
+
# RUNNER_HOME (=/home/runner) RUNNER_USER (=runner) MANIFEST_PATH (=/opt/runner-agents)
|
|
44
|
+
# VERSIONS_FILE (=junto a este script) SETUP_DRY_RUN (=0; 1: no instala CLIs ni
|
|
45
|
+
# agentes; valida y copia config/credenciales locales igualmente; «gh auth login»
|
|
46
|
+
# solo se ejecuta si gh ya está en el PATH)
|
|
47
|
+
|
|
48
|
+
set -Eeuo pipefail
|
|
49
|
+
|
|
50
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
51
|
+
|
|
52
|
+
SUPPORTED_AGENTS=(pi claude codex copilot agy)
|
|
53
|
+
SUPPORTED_JOINED="${SUPPORTED_AGENTS[0]}"
|
|
54
|
+
for _s in "${SUPPORTED_AGENTS[@]:1}"; do SUPPORTED_JOINED="$SUPPORTED_JOINED, $_s"; done
|
|
55
|
+
RUNNER_HOME="${RUNNER_HOME:-/home/runner}"
|
|
56
|
+
RUNNER_USER="${RUNNER_USER:-runner}"
|
|
57
|
+
MANIFEST_PATH="${MANIFEST_PATH:-/opt/runner-agents}"
|
|
58
|
+
VERSIONS_FILE="${VERSIONS_FILE:-${SCRIPT_DIR}/versions.env}"
|
|
59
|
+
DRY_RUN="${SETUP_DRY_RUN:-0}"
|
|
60
|
+
|
|
61
|
+
log() { printf 'setup.sh: %s\n' "$*"; }
|
|
62
|
+
die() { printf 'setup.sh: ERROR: %s\n' "$*" >&2; exit 1; }
|
|
63
|
+
mask() { printf 'setup.sh: %s (valor no registrado)\n' "$*"; }
|
|
64
|
+
|
|
65
|
+
usage() {
|
|
66
|
+
cat <<'EOF'
|
|
67
|
+
Uso: setup.sh --agents pi,copilot [--config DIR] [--credentials FICHERO] [--skip-gh] [--skip-az] [--with-bond]
|
|
68
|
+
--agents LISTA agentes a instalar, separados por comas (pi, claude, codex, copilot, agy)
|
|
69
|
+
--config DIR config por agente (subcarpeta por agente, un fichero cada una; sin secretos)
|
|
70
|
+
--credentials FICHERO fichero 0600 con GH_TOKEN/CLAUDE_TOKEN/CODEX_TOKEN (opcional; ver credentials.example.env)
|
|
71
|
+
--skip-gh no instalar gh (por defecto, sí se instala)
|
|
72
|
+
--skip-az no instalar azure-cli + extensión azure-devops (por defecto, sí se instala)
|
|
73
|
+
--with-bond instala bond (pin BOND_VERSION de versions.env) y deja su config de
|
|
74
|
+
máquina hecha para el usuario runner (D-H/D-I; ver runner/SPIKE-BOND.md)
|
|
75
|
+
EOF
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# --- Ficheros de config soportados por agente: «fichero|ruta-relativa-al-home|formato»
|
|
79
|
+
config_spec() {
|
|
80
|
+
case "$1" in
|
|
81
|
+
pi) echo "models.json|.pi/agent/models.json|json" ;;
|
|
82
|
+
claude) echo "settings.json|.claude/settings.json|json" ;;
|
|
83
|
+
codex) echo "config.toml|.codex/config.toml|toml" ;;
|
|
84
|
+
copilot) echo "config.json|.copilot/config.json|json" ;;
|
|
85
|
+
agy) echo "settings.json|.gemini/antigravity-cli/settings.json|json" ;;
|
|
86
|
+
*) return 1 ;;
|
|
87
|
+
esac
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# --- Parseo de argumentos -------------------------------------------------------
|
|
91
|
+
AGENTS_RAW=""
|
|
92
|
+
CONFIG_DIR=""
|
|
93
|
+
CRED_FILE=""
|
|
94
|
+
SKIP_GH=0
|
|
95
|
+
SKIP_AZ=0
|
|
96
|
+
WITH_BOND=0
|
|
97
|
+
while [ "$#" -gt 0 ]; do
|
|
98
|
+
case "$1" in
|
|
99
|
+
--agents) [ $# -ge 2 ] || die "--agents necesita un valor (p. ej. --agents pi,copilot)"
|
|
100
|
+
AGENTS_RAW="$2"; shift 2 ;;
|
|
101
|
+
--config) [ $# -ge 2 ] || die "--config necesita un directorio"
|
|
102
|
+
CONFIG_DIR="$2"; shift 2 ;;
|
|
103
|
+
--credentials) [ $# -ge 2 ] || die "--credentials necesita un fichero"
|
|
104
|
+
CRED_FILE="$2"; shift 2 ;;
|
|
105
|
+
--skip-gh) SKIP_GH=1; shift ;;
|
|
106
|
+
--skip-az) SKIP_AZ=1; shift ;;
|
|
107
|
+
--with-bond) WITH_BOND=1; shift ;;
|
|
108
|
+
-h|--help) usage; exit 0 ;;
|
|
109
|
+
*) die "opción desconocida: $1 (usa --help)" ;;
|
|
110
|
+
esac
|
|
111
|
+
done
|
|
112
|
+
|
|
113
|
+
[ -n "$AGENTS_RAW" ] || { usage >&2; die "falta --agents (lista separada por comas)"; }
|
|
114
|
+
|
|
115
|
+
# Lista pedida → AGENTS_ordered (sin duplicados, sin espacios)
|
|
116
|
+
IFS=',' read -r -a REQUESTED <<< "$AGENTS_RAW"
|
|
117
|
+
AGENTS_ordered=()
|
|
118
|
+
for a in "${REQUESTED[@]}"; do
|
|
119
|
+
[ -n "$a" ] || die "lista de agentes vacía o con entradas vacías: '$AGENTS_RAW'"
|
|
120
|
+
known=0
|
|
121
|
+
for s in "${SUPPORTED_AGENTS[@]}"; do [ "$a" = "$s" ] && known=1 && break; done
|
|
122
|
+
[ "$known" -eq 1 ] || die "agente no soportado: '$a' (soportados: $SUPPORTED_JOINED)"
|
|
123
|
+
for p in "${AGENTS_ordered[@]}"; do [ "$p" = "$a" ] && die "agente duplicado en --agents: '$a'"; done
|
|
124
|
+
AGENTS_ordered+=("$a")
|
|
125
|
+
done
|
|
126
|
+
[ "${#AGENTS_ordered[@]}" -gt 0 ] || die "lista de agentes vacía"
|
|
127
|
+
|
|
128
|
+
agent_requested() {
|
|
129
|
+
local want="$1" a
|
|
130
|
+
for a in "${AGENTS_ordered[@]}"; do [ "$a" = "$want" ] && return 0; done
|
|
131
|
+
return 1
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# --- Versiones fijadas ----------------------------------------------------------
|
|
135
|
+
[ -f "$VERSIONS_FILE" ] || die "no encuentro $VERSIONS_FILE"
|
|
136
|
+
# shellcheck source=/dev/null
|
|
137
|
+
. "$VERSIONS_FILE"
|
|
138
|
+
pin_for() {
|
|
139
|
+
case "$1" in
|
|
140
|
+
pi) echo "$PI_VERSION" ;;
|
|
141
|
+
claude) echo "$CLAUDE_VERSION" ;;
|
|
142
|
+
codex) echo "$CODEX_VERSION" ;;
|
|
143
|
+
copilot) echo "$COPILOT_VERSION" ;;
|
|
144
|
+
agy) echo "$AGY_VERSION" ;;
|
|
145
|
+
esac
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
# --- Utilidades ------------------------------------------------------------------
|
|
149
|
+
am_root() { [ "$(id -u)" -eq 0 ]; }
|
|
150
|
+
runner_account_exists() { [ -n "$RUNNER_USER" ] && id -u "$RUNNER_USER" >/dev/null 2>&1; }
|
|
151
|
+
|
|
152
|
+
# Ejecuta una orden como el usuario runner con su HOME (si aplica; si no, tal cual).
|
|
153
|
+
as_runner() {
|
|
154
|
+
if am_root && runner_account_exists && [ "$(id -un)" != "$RUNNER_USER" ]; then
|
|
155
|
+
runuser -u "$RUNNER_USER" -- env HOME="$RUNNER_HOME" "$@"
|
|
156
|
+
else
|
|
157
|
+
"$@"
|
|
158
|
+
fi
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
chown_if_runner() {
|
|
162
|
+
if am_root && runner_account_exists; then
|
|
163
|
+
chown "$RUNNER_USER:$RUNNER_USER" "$@"
|
|
164
|
+
fi
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
ensure_python3() {
|
|
168
|
+
if ! command -v python3 >/dev/null 2>&1; then
|
|
169
|
+
if [ "$DRY_RUN" = "1" ]; then
|
|
170
|
+
die "python3 es necesario para validar config y no está disponible (modo dry-run)"
|
|
171
|
+
fi
|
|
172
|
+
am_root || die "python3 es necesario para validar la config; ejecuta setup.sh como root"
|
|
173
|
+
log "instalando python3 (necesario para validar la config)"
|
|
174
|
+
apt-get update -qq && apt-get install -y -qq --no-install-recommends python3 >/dev/null
|
|
175
|
+
fi
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
validate_json() {
|
|
179
|
+
local f="$1"
|
|
180
|
+
if ! command -v node >/dev/null 2>&1 && ! command -v python3 >/dev/null 2>&1; then
|
|
181
|
+
ensure_python3
|
|
182
|
+
fi
|
|
183
|
+
if command -v node >/dev/null 2>&1; then
|
|
184
|
+
node -e 'JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"))' "$f" \
|
|
185
|
+
|| die "JSON inválido: $f"
|
|
186
|
+
else
|
|
187
|
+
python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$f" \
|
|
188
|
+
|| die "JSON inválido: $f"
|
|
189
|
+
fi
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
validate_toml() {
|
|
193
|
+
local f="$1"
|
|
194
|
+
ensure_python3
|
|
195
|
+
python3 -c 'import sys,tomllib; tomllib.load(open(sys.argv[1],"rb"))' "$f" \
|
|
196
|
+
|| die "TOML inválido: $f"
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
# --- Validación de --config (antes de instalar nada: sin efectos secundarios) -----
|
|
200
|
+
[ -z "$CONFIG_DIR" ] || { [ -d "$CONFIG_DIR" ] || die "--config no es un directorio: $CONFIG_DIR"; }
|
|
201
|
+
|
|
202
|
+
declare -A CONFIG_SRC=() CONFIG_DEST=() CONFIG_HASH=()
|
|
203
|
+
if [ -n "$CONFIG_DIR" ]; then
|
|
204
|
+
for f in "$CONFIG_DIR"/*; do
|
|
205
|
+
[ -e "$f" ] || die "--config está vacía: $CONFIG_DIR"
|
|
206
|
+
# único fichero suelto admitido: la documentación de la plantilla (sin config)
|
|
207
|
+
[ "$(basename "$f")" = "README.md" ] && [ -f "$f" ] && continue
|
|
208
|
+
[ -d "$f" ] || die "--config admite solo subcarpetas por agente; fichero suelto: $f"
|
|
209
|
+
agent="$(basename "$f")"
|
|
210
|
+
spec="$(config_spec "$agent" 2>/dev/null)" || die "--config: agente desconocido: '$agent' (soportados: $SUPPORTED_JOINED)"
|
|
211
|
+
agent_requested "$agent" || die "--config: '$agent' no está en la lista de --agents (sin entrada)"
|
|
212
|
+
src_rel="${spec%%|*}"; rest="${spec#*|}"; dest_rel="${rest%%|*}"; kind="${rest##*|}"
|
|
213
|
+
src="$f/$src_rel"
|
|
214
|
+
[ -f "$src" ] || die "--config/$agent: falta el fichero '$src_rel' (esperado: $src)"
|
|
215
|
+
extra="$(find "$f" -mindepth 1 ! -name "$src_rel" -print -quit)"
|
|
216
|
+
[ -z "$extra" ] || die "--config/$agent: solo se admite '$src_rel' (sorprendente: $extra)"
|
|
217
|
+
case "$kind" in
|
|
218
|
+
json) validate_json "$src" ;;
|
|
219
|
+
toml) validate_toml "$src" ;;
|
|
220
|
+
esac
|
|
221
|
+
CONFIG_SRC[$agent]="$src"
|
|
222
|
+
CONFIG_DEST[$agent]="$RUNNER_HOME/$dest_rel"
|
|
223
|
+
done
|
|
224
|
+
fi
|
|
225
|
+
|
|
226
|
+
# --- Validación de --credentials --------------------------------------------------
|
|
227
|
+
[ -z "$CRED_FILE" ] || {
|
|
228
|
+
[ -f "$CRED_FILE" ] || die "--credentials no es un fichero: $CRED_FILE"
|
|
229
|
+
mode="$(stat -c '%a' "$CRED_FILE")"
|
|
230
|
+
[ "$mode" = "600" ] || die "credenciales deben tener permisos 0600 (tiene $mode): chmod 600 $CRED_FILE"
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# --- Instalación de CLIs de sistema (gh + azure-cli) ------------------------------
|
|
234
|
+
install_system_deps() {
|
|
235
|
+
if [ "$DRY_RUN" = "1" ]; then return 0; fi
|
|
236
|
+
am_root || die "instalar dependencias requiere root"
|
|
237
|
+
apt-get update -qq
|
|
238
|
+
apt-get install -y -qq --no-install-recommends curl ca-certificates gnupg dpkg >/dev/null
|
|
239
|
+
rm -rf /var/lib/apt/lists/*
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
install_gh() {
|
|
243
|
+
if [ "$SKIP_GH" = "1" ]; then GH_STATE="skipped"; log "gh omitido por --skip-gh"; return 0; fi
|
|
244
|
+
GH_STATE="yes"
|
|
245
|
+
if [ "$DRY_RUN" = "1" ]; then log "dry-run: instalaría gh (repo apt oficial de GitHub)"; return 0; fi
|
|
246
|
+
am_root || die "instalar gh requiere root"
|
|
247
|
+
local keyring=/usr/share/keyrings/githubcli-archive-keyring.gpg
|
|
248
|
+
[ -f "$keyring" ] || curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o "$keyring"
|
|
249
|
+
echo "deb [arch=$(dpkg --print-architecture) signed-by=$keyring] https://cli.github.com/packages stable main" \
|
|
250
|
+
> /etc/apt/sources.list.d/github-cli.list
|
|
251
|
+
apt-get update -qq && apt-get install -y -qq gh >/dev/null
|
|
252
|
+
log "gh instalado: $(gh --version | head -n1)"
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
install_az() {
|
|
256
|
+
if [ "$SKIP_AZ" = "1" ]; then AZ_STATE="skipped"; log "azure-cli omitido por --skip-az"; return 0; fi
|
|
257
|
+
AZ_STATE="yes"
|
|
258
|
+
if [ "$DRY_RUN" = "1" ]; then log "dry-run: instalaría azure-cli + extensión azure-devops"; return 0; fi
|
|
259
|
+
am_root || die "instalar azure-cli requiere root"
|
|
260
|
+
local keyring=/etc/apt/keyrings/microsoft.gpg
|
|
261
|
+
mkdir -p /etc/apt/keyrings
|
|
262
|
+
[ -f "$keyring" ] || curl -sLS https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > "$keyring"
|
|
263
|
+
chmod go+r "$keyring"
|
|
264
|
+
# shellcheck disable=SC1091
|
|
265
|
+
. /etc/os-release
|
|
266
|
+
{
|
|
267
|
+
echo "Types: deb"
|
|
268
|
+
echo "URIs: https://packages.microsoft.com/repos/azure-cli/"
|
|
269
|
+
echo "Suites: ${VERSION_CODENAME}"
|
|
270
|
+
echo "Components: main"
|
|
271
|
+
echo "Architectures: $(dpkg --print-architecture)"
|
|
272
|
+
echo "Signed-by: $keyring"
|
|
273
|
+
} > /etc/apt/sources.list.d/azure-cli.sources
|
|
274
|
+
apt-get update -qq
|
|
275
|
+
if [ -n "${AZURE_CLI_VERSION:-}" ]; then
|
|
276
|
+
apt-get install -y -qq "azure-cli=${AZURE_CLI_VERSION}-1~${VERSION_CODENAME}" >/dev/null
|
|
277
|
+
else
|
|
278
|
+
apt-get install -y -qq azure-cli >/dev/null
|
|
279
|
+
fi
|
|
280
|
+
if ! az extension list --query "[].name" -o tsv 2>/dev/null | grep -qx azure-devops; then
|
|
281
|
+
az extension add --name azure-devops >/dev/null
|
|
282
|
+
fi
|
|
283
|
+
log "azure-cli instalado: $(az --version 2>/dev/null | head -n1 || echo '?')"
|
|
284
|
+
az devops -h >/dev/null || die "az devops no responde tras instalar la extensión"
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
# --- Instalación de agentes --------------------------------------------------------
|
|
288
|
+
npm_install_agent() {
|
|
289
|
+
local agent="$1" pkg="$2" ver="$3"
|
|
290
|
+
if [ "$DRY_RUN" = "1" ]; then log "dry-run: instalaría $agent@$ver (npm $pkg@$ver)"; return 0; fi
|
|
291
|
+
command -v npm >/dev/null 2>&1 || die "$agent se instala con npm y npm no está en el PATH"
|
|
292
|
+
npm install -g --registry=https://registry.npmjs.org "$pkg@$ver" >/dev/null
|
|
293
|
+
npm cache clean --force >/dev/null 2>&1 || true
|
|
294
|
+
log "agente instalado: $agent@$ver"
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
install_agents() {
|
|
298
|
+
for a in "${AGENTS_ordered[@]}"; do
|
|
299
|
+
case "$a" in
|
|
300
|
+
pi) npm_install_agent pi '@earendil-works/pi-coding-agent' "$PI_VERSION" ;;
|
|
301
|
+
claude) npm_install_agent claude '@anthropic-ai/claude-code' "$CLAUDE_VERSION" ;;
|
|
302
|
+
codex) npm_install_agent codex '@openai/codex' "$CODEX_VERSION" ;;
|
|
303
|
+
copilot) npm_install_agent copilot '@github/copilot' "$COPILOT_VERSION" ;;
|
|
304
|
+
agy) install_agy ;;
|
|
305
|
+
esac
|
|
306
|
+
done
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
# supi: sugerencias de prompt para pi (D-J del plan de la imagen). Solo con pi en la
|
|
310
|
+
# lista; el supi/config.json que bond-app inyecta por run es inerte sin este paquete.
|
|
311
|
+
install_supi() {
|
|
312
|
+
agent_requested pi || return 0
|
|
313
|
+
if [ "$DRY_RUN" = "1" ]; then log "dry-run: instalaría supi@$SUPI_VERSION (npm @mrclrchtr/supi-prompt-suggestions)"; SUPI_DONE=1; return 0; fi
|
|
314
|
+
command -v npm >/dev/null 2>&1 || die "supi se instala con npm y npm no está en el PATH"
|
|
315
|
+
npm install -g --registry=https://registry.npmjs.org "@mrclrchtr/supi-prompt-suggestions@$SUPI_VERSION" >/dev/null
|
|
316
|
+
npm cache clean --force >/dev/null 2>&1 || true
|
|
317
|
+
SUPI_DONE=1
|
|
318
|
+
log "supi instalado: @$SUPI_VERSION (sugerencias de prompt para pi)"
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
# bond: el harness que lanzará el agente (D-G/D-H). Versión fijada en versions.env
|
|
322
|
+
# (1.16.4: antes no existe `bond tui`). Además de la CLI, deja la config de máquina del
|
|
323
|
+
# usuario runner horneada: `bond setup --yes` (integraciones de Herdr y skills, que son
|
|
324
|
+
# lo que pinta la barra de estado del agente) y [update] auto=false (D-I: nada de
|
|
325
|
+
# actualizaciones sorpresa en un contenedor; el pin lo manda la imagen).
|
|
326
|
+
install_bond() {
|
|
327
|
+
[ "$WITH_BOND" = "1" ] || return 0
|
|
328
|
+
[ -n "${BOND_VERSION:-}" ] || die "--with-bond necesita BOND_VERSION en $VERSIONS_FILE"
|
|
329
|
+
if [ "$DRY_RUN" = "1" ]; then log "dry-run: instalaría bond@$BOND_VERSION (npm @jmanuelcorral/bond) + «bond setup --yes»"; BOND_DONE=1; return 0; fi
|
|
330
|
+
command -v npm >/dev/null 2>&1 || die "bond se instala con npm y npm no está en el PATH"
|
|
331
|
+
local have
|
|
332
|
+
have="$(bond --version 2>/dev/null || true)"
|
|
333
|
+
if [ "$have" = "$BOND_VERSION" ]; then
|
|
334
|
+
log "bond ya presente: $have"
|
|
335
|
+
else
|
|
336
|
+
log "instalando bond@$BOND_VERSION (npm @jmanuelcorral/bond)"
|
|
337
|
+
npm install -g --registry=https://registry.npmjs.org "@jmanuelcorral/bond@$BOND_VERSION" >/dev/null
|
|
338
|
+
npm cache clean --force >/dev/null 2>&1 || true
|
|
339
|
+
[ "$(bond --version 2>/dev/null)" = "$BOND_VERSION" ] || die "bond instalado pero «bond --version» no responde $BOND_VERSION"
|
|
340
|
+
fi
|
|
341
|
+
# Config de máquina no interactiva (escribe en el HOME del usuario runner).
|
|
342
|
+
as_runner bond setup --yes --no-suggestions >/dev/null || die "bond setup --yes falló"
|
|
343
|
+
local conf="$RUNNER_HOME/.bond/config.toml"
|
|
344
|
+
if [ -f "$conf" ] && ! grep -q '^\[update\]' "$conf"; then
|
|
345
|
+
printf '\n[update]\nauto = false\n' >> "$conf"
|
|
346
|
+
fi
|
|
347
|
+
chown_if_runner "$conf"
|
|
348
|
+
BOND_DONE=1
|
|
349
|
+
log "bond instalado: $(bond --version) (config de máquina lista)"
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
install_agy() {
|
|
353
|
+
if [ "$DRY_RUN" = "1" ]; then log "dry-run: instalaría agy (instalador oficial; sin pin de versión)"; return 0; fi
|
|
354
|
+
local bindir=/usr/local/bin
|
|
355
|
+
if [ -x "$bindir/agy" ]; then log "agy ya presente en $bindir/agy"; return 0; fi
|
|
356
|
+
# Instalador oficial de Google: binario único con sha512 verificado contra su
|
|
357
|
+
# manifiesto; siempre la última versión (D-C). El paso final «agy install» solo
|
|
358
|
+
# toca perfiles de shell y no es crítico (|| true del propio script oficial).
|
|
359
|
+
curl -fsSL https://antigravity.google/cli/install.sh | bash -s -- --dir "$bindir" >/dev/null
|
|
360
|
+
log "agy instalado: $(agy --version 2>/dev/null | head -n1 || echo '?')"
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
version_of() {
|
|
364
|
+
local agent="$1" ver
|
|
365
|
+
if [ "$DRY_RUN" = "1" ]; then pin_for "$agent"; return 0; fi
|
|
366
|
+
ver="$("$agent" --version 2>/dev/null | head -n1 | grep -oE '[0-9]+(\.[0-9A-Za-z-]+)+' | head -n1)" || ver=""
|
|
367
|
+
if [ -n "$ver" ]; then echo "$ver"; else pin_for "$agent"; fi
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
# --- Copia de config ---------------------------------------------------------------
|
|
371
|
+
install_config() {
|
|
372
|
+
for agent in "${!CONFIG_SRC[@]}"; do
|
|
373
|
+
local src="${CONFIG_SRC[$agent]}" dest="${CONFIG_DEST[$agent]}"
|
|
374
|
+
install -d -m 0700 "$(dirname "$dest")"
|
|
375
|
+
chown_if_runner "$(dirname "$dest")"
|
|
376
|
+
install -m 0644 "$src" "$dest"
|
|
377
|
+
chown_if_runner "$dest"
|
|
378
|
+
CONFIG_HASH[$agent]="$(sha256sum "$dest" | cut -d' ' -f1)"
|
|
379
|
+
log "config instalada: $agent → $dest"
|
|
380
|
+
done
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
# --- Credenciales -------------------------------------------------------------------
|
|
384
|
+
# Claves admitidas (ver credentials.example.env). Nunca se registran valores.
|
|
385
|
+
CRED_KEYS="GH_TOKEN CLAUDE_TOKEN CODEX_TOKEN"
|
|
386
|
+
CRED_REJECTED_KEYS="COPILOT_TOKEN AGY_TOKEN"
|
|
387
|
+
|
|
388
|
+
guard_cred_agent() {
|
|
389
|
+
agent_requested "$1" || die "el fichero de credenciales trae $2 pero '$1' no está en --agents"
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
read_credentials() {
|
|
393
|
+
GH_TOKEN_V="" CLAUDE_TOKEN_V="" CODEX_TOKEN_V=""
|
|
394
|
+
local line key value
|
|
395
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
396
|
+
line="${line%$'\r'}"
|
|
397
|
+
case "$line" in ''|'#'*) continue ;; esac
|
|
398
|
+
key="${line%%=*}"; value="${line#*=}"
|
|
399
|
+
case " $CRED_REJECTED_KEYS " in
|
|
400
|
+
*" $key "*) die "$key no tiene fichero de credenciales soportado (D-C): usa GH_TOKEN (cubre a copilot vía gh) o la inyección por stdin de bond-app (agy)" ;;
|
|
401
|
+
esac
|
|
402
|
+
case " $CRED_KEYS " in
|
|
403
|
+
*" $key "*) printf -v "${key}_V" '%s' "$value" ;;
|
|
404
|
+
*) die "clave desconocida en el fichero de credenciales: $key" ;;
|
|
405
|
+
esac
|
|
406
|
+
case "$value" in
|
|
407
|
+
*[!A-Za-z0-9._=/+:-]*) die "caracteres no soportados en el valor de $key" ;;
|
|
408
|
+
esac
|
|
409
|
+
done < "$CRED_FILE"
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
write_token_file() {
|
|
413
|
+
# write_token_file <ruta> <contenido> — 0600, del usuario runner.
|
|
414
|
+
local dest="$1" content="$2"
|
|
415
|
+
install -d -m 0700 "$(dirname "$dest")"
|
|
416
|
+
chown_if_runner "$(dirname "$dest")"
|
|
417
|
+
(umask 077 && printf '%s\n' "$content" > "$dest")
|
|
418
|
+
chmod 0600 "$dest"
|
|
419
|
+
chown_if_runner "$dest"
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
install_credentials() {
|
|
423
|
+
CRED_WRITTEN=""
|
|
424
|
+
[ -n "$CRED_FILE" ] || return 0
|
|
425
|
+
read_credentials
|
|
426
|
+
[ -z "$CODEX_TOKEN_V" ] || guard_cred_agent codex CODEX_TOKEN
|
|
427
|
+
[ -z "$CLAUDE_TOKEN_V" ] || guard_cred_agent claude CLAUDE_TOKEN
|
|
428
|
+
if [ -n "$GH_TOKEN_V" ]; then
|
|
429
|
+
mask "autenticando gh con GH_TOKEN"
|
|
430
|
+
if [ "$DRY_RUN" = "1" ] && ! command -v gh >/dev/null 2>&1; then
|
|
431
|
+
log "dry-run: gh no disponible; no se ejecuta «gh auth login --with-token»"
|
|
432
|
+
else
|
|
433
|
+
# El token viaja por stdin de la orden; nunca por args ni se loguea.
|
|
434
|
+
printf '%s' "$GH_TOKEN_V" | as_runner gh auth login --with-token \
|
|
435
|
+
|| die "gh auth login falló"
|
|
436
|
+
fi
|
|
437
|
+
CRED_WRITTEN="$CRED_WRITTEN gh"
|
|
438
|
+
fi
|
|
439
|
+
if [ -n "$CODEX_TOKEN_V" ]; then
|
|
440
|
+
mask "escribiendo credenciales de codex"
|
|
441
|
+
write_token_file "$RUNNER_HOME/.codex/auth.json" "{\"OPENAI_API_KEY\":\"$CODEX_TOKEN_V\"}"
|
|
442
|
+
CRED_WRITTEN="$CRED_WRITTEN codex"
|
|
443
|
+
fi
|
|
444
|
+
if [ -n "$CLAUDE_TOKEN_V" ]; then
|
|
445
|
+
mask "escribiendo credenciales de claude"
|
|
446
|
+
write_token_file "$RUNNER_HOME/.claude/.credentials.json" \
|
|
447
|
+
"{\"claudeAiOauth\":{\"accessToken\":\"$CLAUDE_TOKEN_V\",\"refreshToken\":\"\",\"expiresAt\":253402300799000,\"scopes\":[\"openid\",\"profile\",\"email\"]}}"
|
|
448
|
+
CRED_WRITTEN="$CRED_WRITTEN claude"
|
|
449
|
+
fi
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
# --- Manifiesto -----------------------------------------------------------------------
|
|
453
|
+
# Formato: comentario de cabecera + una línea por agente instalado:
|
|
454
|
+
# agent=<nombre> version=<versión instalada o pin> config_sha256=<sha256|none> credentials=<yes|no>
|
|
455
|
+
# y una línea pkg=<paquete> ... por soporte no-agente instalado (supi); parseRunnerManifest
|
|
456
|
+
# solo lee las líneas agent=.
|
|
457
|
+
# Las líneas tool=<gh|az> installed=<yes|skipped> reflejan si las CLIs de sistema se
|
|
458
|
+
# instalaron u omitieron (--skip-gh/--skip-az).
|
|
459
|
+
write_manifest() {
|
|
460
|
+
local tmp agent has_cred line
|
|
461
|
+
tmp="$(mktemp "${MANIFEST_PATH}.XXXXXX")"
|
|
462
|
+
{
|
|
463
|
+
echo "# runner-agents — generado por runner/setup.sh (no editar)."
|
|
464
|
+
echo "# agent=<nombre> version=<v> config_sha256=<sha256|none> credentials=<yes|no>"
|
|
465
|
+
for agent in "${AGENTS_ordered[@]}"; do
|
|
466
|
+
has_cred=no
|
|
467
|
+
case " $CRED_WRITTEN " in *" $agent "*) has_cred=yes ;; esac
|
|
468
|
+
line="agent=$agent version=$(version_of "$agent") config_sha256=${CONFIG_HASH[$agent]:-none} credentials=$has_cred"
|
|
469
|
+
printf '%s\n' "$line"
|
|
470
|
+
done
|
|
471
|
+
if [ -n "${SUPI_DONE:-}" ]; then
|
|
472
|
+
printf 'pkg=supi version=%s config_sha256=none credentials=no\n' "$SUPI_VERSION"
|
|
473
|
+
fi
|
|
474
|
+
if [ -n "${BOND_DONE:-}" ]; then
|
|
475
|
+
printf 'pkg=bond version=%s config_sha256=none credentials=no\n' "$(bond --version 2>/dev/null || echo "$BOND_VERSION")"
|
|
476
|
+
fi
|
|
477
|
+
printf 'tool=gh installed=%s\n' "${GH_STATE:-yes}"
|
|
478
|
+
printf 'tool=az installed=%s\n' "${AZ_STATE:-yes}"
|
|
479
|
+
} > "$tmp"
|
|
480
|
+
mv "$tmp" "$MANIFEST_PATH"
|
|
481
|
+
chmod 0644 "$MANIFEST_PATH"
|
|
482
|
+
log "manifiesto escrito en $MANIFEST_PATH"
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
# --- Main -----------------------------------------------------------------------------
|
|
486
|
+
log "agentes pedidos: ${AGENTS_ordered[*]} (config: ${CONFIG_DIR:-ninguna}; credenciales: ${CRED_FILE:-ningunas})"
|
|
487
|
+
install_system_deps
|
|
488
|
+
install_gh
|
|
489
|
+
install_az
|
|
490
|
+
install_agents
|
|
491
|
+
install_supi
|
|
492
|
+
install_bond
|
|
493
|
+
install_config
|
|
494
|
+
install_credentials
|
|
495
|
+
write_manifest
|
|
496
|
+
log "listo"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# runner/versions.env — pins por agente para runner/setup.sh (leído vía VERSIONS_FILE).
|
|
2
|
+
# Cambiar un pin aquí cambia lo que setup.sh instala; el manifiesto /opt/runner-agents
|
|
3
|
+
# registra la versión real resultante de la instalación.
|
|
4
|
+
#
|
|
5
|
+
# Los pines de npm se fijan a versiones concretas (D-C). `agy` se instala con el
|
|
6
|
+
# instalador oficial de Google, que siempre sirve la última versión publicada
|
|
7
|
+
# (checksum sha512 verificado); no admite pin: AGY_VERSION es informativo y la
|
|
8
|
+
# versión real queda en el manifiesto. El binario de agy se autoactualiza en
|
|
9
|
+
# cada ejecución (comportamiento oficial del fabricante).
|
|
10
|
+
|
|
11
|
+
PI_VERSION=1.5.1
|
|
12
|
+
CLAUDE_VERSION=2.1.328
|
|
13
|
+
CODEX_VERSION=0.170.0
|
|
14
|
+
COPILOT_VERSION=1.0.114
|
|
15
|
+
AGY_VERSION=latest
|
|
16
|
+
|
|
17
|
+
# supi (sugerencias de prompt para pi): se instala solo cuando pi está en --agents
|
|
18
|
+
# (D-J del plan de la imagen). El config inyectado por run (~/.pi/agent/supi/config.json)
|
|
19
|
+
# es inerte sin este paquete.
|
|
20
|
+
SUPI_VERSION=11.0.1
|
|
21
|
+
|
|
22
|
+
# bond (el harness que lanza el agente, D-G): instalado por setup.sh con --with-bond
|
|
23
|
+
# (D-H: versión fijada; package npm con scope @jmanuelcorral/bond). El pin mínimo es
|
|
24
|
+
# 1.16.4: antes de esa versión bond no tiene comando `tui` (spike runner/SPIKE-BOND.md).
|
|
25
|
+
BOND_VERSION=1.16.4
|
|
26
|
+
|
|
27
|
+
# gh y azure-cli salen de los repos apt oficiales (GitHub y Microsoft); se dejan
|
|
28
|
+
# en «latest» del repo. AZURE_CLI_VERSION admite el pin «2.xx.y» (sufijo ~bookworm
|
|
29
|
+
# añadido por el script); vacío = última del repo.
|
|
30
|
+
AZURE_CLI_VERSION=
|
package/scripts/app-install.ts
CHANGED
|
@@ -129,6 +129,10 @@ function configJs(api: string, tokenFile: string | null): string {
|
|
|
129
129
|
'export const CONFIG = {',
|
|
130
130
|
` api: ${JSON.stringify(api.replace(/\/+$/, ''))},`,
|
|
131
131
|
` tokenFile: ${JSON.stringify(tokenFile)},`,
|
|
132
|
+
' // Gasto/costes fuera por defecto (decisión 2026-11-19): el orquestador sigue',
|
|
133
|
+
' // registrando cost_usd, pero la UI no lo muestra hasta que una configuración',
|
|
134
|
+
' // en Ajustes lo active. Entonces esto será el valor de esa configuración.',
|
|
135
|
+
' costs: false,',
|
|
132
136
|
'};',
|
|
133
137
|
'',
|
|
134
138
|
].join('\n');
|
package/src/config.ts
CHANGED
|
@@ -26,6 +26,13 @@ export interface AppConfig {
|
|
|
26
26
|
* e.g. '["bash"]' for a stub session without a paid agent.
|
|
27
27
|
*/
|
|
28
28
|
agentCommand: string[] | null;
|
|
29
|
+
/**
|
|
30
|
+
* D-G (image plan): how a run launches its agent. `bond` (default): `bond tui --agent X`
|
|
31
|
+
* inside the container - bond is the harness (skills, AGENTS.md, sync, decisions, the
|
|
32
|
+
* status bar). `pi`: the bare agent CLI. A `bond` run falls back to the bare launcher
|
|
33
|
+
* when the image has no usable bond or the repo is not a bond repo.
|
|
34
|
+
*/
|
|
35
|
+
runnerLauncher: 'bond' | 'pi';
|
|
29
36
|
/** P4 criterion 3: verification failures in a row before the run goes to `blocked`. */
|
|
30
37
|
maxVerifyFailures: number;
|
|
31
38
|
/** P4: time limit of each verify command. */
|
|
@@ -133,6 +140,7 @@ export function loadConfig(overrides: Partial<AppConfig> = {}): AppConfig {
|
|
|
133
140
|
memory: process.env.BOND_APP_MEMORY || '2g',
|
|
134
141
|
pidsLimit: parseInt(process.env.BOND_APP_PIDS_LIMIT || '200', 10),
|
|
135
142
|
agentCommand: parseAgentCommand(process.env.BOND_APP_AGENT_COMMAND),
|
|
143
|
+
runnerLauncher: process.env.RUNNER_LAUNCHER === 'pi' ? 'pi' : 'bond',
|
|
136
144
|
maxVerifyFailures: Math.max(1, parseInt(process.env.BOND_APP_MAX_VERIFY_FAILURES || '3', 10) || 3),
|
|
137
145
|
verifyTimeoutMs: 10 * 60 * 1000,
|
|
138
146
|
analysisCommand: parseAnalysisCommand(process.env.BOND_APP_ANALYSIS_COMMAND),
|
package/src/core/hub-session.ts
CHANGED
|
@@ -519,7 +519,7 @@ export class HubSession {
|
|
|
519
519
|
machine: string,
|
|
520
520
|
ticket: Ticket,
|
|
521
521
|
repos: HubAnalysisRepo[],
|
|
522
|
-
opts: { waitMs?: number; pollMs?: number; onTerminal?: (address: string) => void } = {}
|
|
522
|
+
opts: { waitMs?: number; pollMs?: number; onTerminal?: (address: string) => void; defaultModel?: string | null } = {}
|
|
523
523
|
): Promise<string> {
|
|
524
524
|
const waitMs = opts.waitMs ?? 180_000;
|
|
525
525
|
const pollMs = opts.pollMs ?? 1000;
|
|
@@ -595,9 +595,10 @@ export class HubSession {
|
|
|
595
595
|
|
|
596
596
|
const agentCmd = ticket.agent === 'pi' || !ticket.agent ? 'pi' : ticket.agent;
|
|
597
597
|
let modelArg = '';
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
598
|
+
const effectiveModel = ticket.model || (agentCmd === 'pi' ? opts.defaultModel : null);
|
|
599
|
+
if (effectiveModel) {
|
|
600
|
+
if (!MODEL_RE.test(effectiveModel)) throw new HubMountError(`Invalid model '${effectiveModel}'`);
|
|
601
|
+
modelArg = `--model ${shq(effectiveModel)} `;
|
|
601
602
|
}
|
|
602
603
|
const runCmd = `cd ${HUB_DIR} && export BOND_TEAM_NO_TABLE=1 && exec ${agentCmd} ${modelArg}"$(cat ${promptPath})"`;
|
|
603
604
|
const runRes = await this.runner(['herdr', 'pane', 'run', pane, runCmd], 15_000);
|
|
@@ -721,9 +722,10 @@ export class HubSession {
|
|
|
721
722
|
|
|
722
723
|
const agentCmd = ticket.agent === 'pi' || !ticket.agent ? 'pi' : ticket.agent;
|
|
723
724
|
let modelArg = '';
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
725
|
+
const effectiveModel = ticket.model || (agentCmd === 'pi' ? opts.defaultModel : null);
|
|
726
|
+
if (effectiveModel) {
|
|
727
|
+
if (!MODEL_RE.test(effectiveModel)) throw new HubMountError(`Invalid model '${effectiveModel}'`);
|
|
728
|
+
modelArg = `--model ${shq(effectiveModel)} `;
|
|
727
729
|
}
|
|
728
730
|
const leaderShellCmd = `cd ${HUB_DIR} && export BOND_TEAM_ENGINE=hc BOND_TEAM_NO_TABLE=1 BOND_TEAM_LABELS='herdr.space=s1,herdr.tab=t1' && exec ${agentCmd} ${modelArg}"$(cat ${promptPath})"`;
|
|
729
731
|
const terminal = await hc.startTerminal(
|