@jmanuelcorral/bond-app 0.3.1 → 0.3.3

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.
@@ -399,21 +399,29 @@ export default class BondSettings extends View {
399
399
 
400
400
  /** `bond-app update` in a space of its own on this computer: bond-app, bond, mods and service. */
401
401
  runUpdate() {
402
+ this.runInSpace("bond-app update", updateCommand(), "Actualizando bond-app: al terminar, el orquestador se reinicia.");
403
+ }
404
+
405
+ /**
406
+ * A bond-app command in a space of its own on this computer. Ajustes closes first: the space
407
+ * would open behind the dialog (and `diagnose --issue` asks there before sending anything).
408
+ */
409
+ runInSpace(name, argv, message) {
410
+ const overlay = props()?.overlay;
402
411
  try {
403
- run("space.new", { name: "bond-app update", machine: "", argv: updateCommand() });
404
- notify({ title: "Actualizando bond-app", body: "Mira el espacio «bond-app update»: al terminar, el orquestador se reinicia.", level: "info" });
412
+ if (overlay) closeOverlay(overlay);
413
+ run("space.new", { name, machine: "", argv, focus: true });
414
+ notify({ title: name, body: message, level: "info" });
405
415
  } catch (e) {
406
- this.error = `Actualizar: ${String(e?.message ?? e)}`;
416
+ notify({ title: `No se pudo abrir «${name}»`, body: String(e?.message ?? e), level: "error" });
407
417
  }
408
418
  }
409
419
 
410
420
  /** «Exportar diagnóstico» / «Abrir issue»: bond-app diagnose in a space of its own (works with the orchestrator down). */
411
421
  runDiagnose(issue) {
412
- try {
413
- run("space.new", { name: issue ? "bond-app issue" : "bond-app diagnose", machine: "", argv: diagnoseCommand(issue) });
414
- } catch (e) {
415
- this.error = `Diagnóstico: ${String(e?.message ?? e)}`;
416
- }
422
+ this.runInSpace(issue ? "bond-app issue" : "bond-app diagnose", diagnoseCommand(issue), issue
423
+ ? "Revisa lo que se va a enviar y contesta en ese espacio si abre la issue."
424
+ : "El zip queda en la carpeta de datos de bond-app; la ruta sale en ese espacio.");
417
425
  }
418
426
 
419
427
  diagnoseBlock() {
@@ -873,6 +881,7 @@ export default class BondSettings extends View {
873
881
 
874
882
  /** Opens the credential or login dialog of an agent on top of this one. */
875
883
  openCredential(agent) {
884
+ if (LOGIN_TEXT[agent] && this.imageMissing()) return;
876
885
  const c = (this.creds ?? []).find((x) => x.agent === agent);
877
886
  openOverlay({
878
887
  mod: "bond-settings", kind: "dialog", modal: true, width: 480, height: 0.92,
@@ -1082,7 +1091,20 @@ export default class BondSettings extends View {
1082
1091
 
1083
1092
  // ---- Issue #4 (P1): the Azure session for the runs ---------------------------------------
1084
1093
 
1094
+ /**
1095
+ * The logins (claude, codex, copilot, agy, Azure) run in the runner image: before it is built
1096
+ * there is nothing to run them in. Say so and go to Imagen instead of a Docker pull error.
1097
+ */
1098
+ imageMissing() {
1099
+ if (this.setup?.image?.present !== false) return false;
1100
+ notify({ title: "Primero, la imagen del runner", body: "Los logins de los agentes se hacen dentro de ella. Constrúyela en Imagen (tarda unos minutos) y vuelve a iniciar sesión.", level: "warning" });
1101
+ if (this.view === "wizard") this.step = WIZARD_STEPS.indexOf("image") + 1;
1102
+ else this.section = "image";
1103
+ return true;
1104
+ }
1105
+
1085
1106
  openAzureLogin() {
1107
+ if (this.imageMissing()) return;
1086
1108
  openOverlay({ mod: "bond-settings", kind: "dialog", modal: true, width: 480, height: 0.92, props: { view: "agy-login", agent: "azure" } });
1087
1109
  }
1088
1110
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jmanuelcorral/bond-app",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Local orchestrator and hub-container runner for multi-agent tickets",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
package/runner/Dockerfile CHANGED
@@ -15,10 +15,13 @@ FROM node:22-bookworm-slim@sha256:5ec23b7c622b00547753bc6ffd78085dd868a68aeb41c8
15
15
  # also pass the matching HC_SHA256 (releases.herdr.dev/core/<version>/manifest.json).
16
16
  ARG HC_VERSION=0.1.17
17
17
  ARG HC_SHA256=82ec44043f6894bfdb716b979b87cda43fd7fa46b0104e7b7bd93e64d1a9b877
18
+ # The same release for arm64 (an image built on a Mac with Apple Silicon); same manifest.
19
+ ARG HC_SHA256_ARM64=3a37a454ec63494cf4306db26481fe9db96673d888723701d24f8a992ae8ab8c
18
20
  # herdr: pinned release binary, verified by checksum (as in P0). A rebuild that changes
19
21
  # HERDR_VERSION must also pass the matching HERDR_SHA256.
20
22
  ARG HERDR_VERSION=v0.9.3
21
23
  ARG HERDR_SHA256=18a8dc65f1c2fa485884344356dea1cfd911c6f06cf46fa78e193f4087f4dba7
24
+ ARG HERDR_SHA256_ARM64=4de7aa3e25678812e92960de64f7c2aaa1bca1f0f80a3c5e559837e231e1f5c0
22
25
  # P4 (image plan): bond comes from setup.sh --with-bond with the BOND_VERSION pin in
23
26
  # versions.env (1.16.4+: `bond tui` exists; runner/SPIKE-BOND.md). Non-empty here
24
27
  # overrides the pin file, like PI_VERSION below.
@@ -45,18 +48,23 @@ RUN apt-get update \
45
48
  && apt-get install -y --no-install-recommends git ca-certificates procps curl \
46
49
  && rm -rf /var/lib/apt/lists/*
47
50
 
48
- RUN curl -fsSL -o /tmp/hc.tar.gz \
49
- "https://releases.herdr.dev/core/${HC_VERSION}/herdr-core-linux-x86_64.tar.gz" \
50
- && echo "${HC_SHA256} /tmp/hc.tar.gz" | sha256sum -c - \
51
+ # The image's own architecture (x86_64, or aarch64 on Apple Silicon): its binary and checksum.
52
+ RUN arch="$(uname -m)" \
53
+ && case "$arch" in x86_64) sum="${HC_SHA256}" ;; aarch64) sum="${HC_SHA256_ARM64}" ;; *) echo "unsupported architecture $arch" >&2; exit 1 ;; esac \
54
+ && curl -fsSL -o /tmp/hc.tar.gz \
55
+ "https://releases.herdr.dev/core/${HC_VERSION}/herdr-core-linux-${arch}.tar.gz" \
56
+ && echo "${sum} /tmp/hc.tar.gz" | sha256sum -c - \
51
57
  && mkdir -p /tmp/hc && tar -xzf /tmp/hc.tar.gz -C /tmp/hc \
52
58
  && install -m 0755 /tmp/hc/herdr-core /usr/local/bin/herdr-core \
53
59
  && ln -s herdr-core /usr/local/bin/hc \
54
60
  && rm -rf /tmp/hc /tmp/hc.tar.gz \
55
61
  && hc --version
56
62
 
57
- RUN curl -fsSL -o /usr/local/bin/herdr \
58
- "https://github.com/herdrdev/herdr/releases/download/${HERDR_VERSION}/herdr-linux-x86_64" \
59
- && echo "${HERDR_SHA256} /usr/local/bin/herdr" | sha256sum -c - \
63
+ RUN arch="$(uname -m)" \
64
+ && case "$arch" in x86_64) sum="${HERDR_SHA256}" ;; aarch64) sum="${HERDR_SHA256_ARM64}" ;; *) echo "unsupported architecture $arch" >&2; exit 1 ;; esac \
65
+ && curl -fsSL -o /usr/local/bin/herdr \
66
+ "https://github.com/herdrdev/herdr/releases/download/${HERDR_VERSION}/herdr-linux-${arch}" \
67
+ && echo "${sum} /usr/local/bin/herdr" | sha256sum -c - \
60
68
  && chmod 0755 /usr/local/bin/herdr && herdr --version
61
69
 
62
70
  # The agent CLIs, supi and bond no longer come from here: setup.sh installs them with
package/runner/setup.sh CHANGED
@@ -496,6 +496,13 @@ tool_apt_packages() {
496
496
  esac
497
497
  }
498
498
 
499
+ # La arquitectura de la imagen (amd64 o arm64: un Mac con Apple Silicon construye arm64).
500
+ # Cada descarga elige su fichero y su sha256 con ella; una arquitectura sin sumas se rechaza.
501
+ IMAGE_ARCH="$(dpkg --print-architecture 2>/dev/null || echo amd64)"
502
+ case "$IMAGE_ARCH" in amd64|arm64) ;; *) die "arquitectura no soportada para las herramientas: $IMAGE_ARCH (solo amd64 y arm64)" ;; esac
503
+ # arch_pick <valor amd64> <valor arm64>
504
+ arch_pick() { if [ "$IMAGE_ARCH" = arm64 ]; then printf '%s' "$2"; else printf '%s' "$1"; fi; }
505
+
499
506
  # Descarga $1 en $2 y comprueba su sha256 ($3); nunca deja un fichero sin verificar.
500
507
  fetch_verified() {
501
508
  local url="$1" dest="$2" sum="$3"
@@ -516,9 +523,9 @@ clone_pinned() {
516
523
  install_tool_shell() {
517
524
  ln -sf /usr/bin/batcat /usr/local/bin/bat
518
525
  local tmp; tmp="$(mktemp -d)"
519
- fetch_verified "https://github.com/dandavison/delta/releases/download/${DELTA_VERSION}/git-delta_${DELTA_VERSION}_amd64.deb" "$tmp/delta.deb" "$DELTA_SHA256"
526
+ fetch_verified "https://github.com/dandavison/delta/releases/download/${DELTA_VERSION}/git-delta_${DELTA_VERSION}_${IMAGE_ARCH}.deb" "$tmp/delta.deb" "$(arch_pick "$DELTA_SHA256" "$DELTA_SHA256_ARM64")"
520
527
  dpkg -i "$tmp/delta.deb" >/dev/null
521
- fetch_verified "https://github.com/starship/starship/releases/download/${STARSHIP_VERSION}/starship-x86_64-unknown-linux-musl.tar.gz" "$tmp/starship.tgz" "$STARSHIP_SHA256"
528
+ fetch_verified "https://github.com/starship/starship/releases/download/${STARSHIP_VERSION}/starship-$(arch_pick x86_64 aarch64)-unknown-linux-musl.tar.gz" "$tmp/starship.tgz" "$(arch_pick "$STARSHIP_SHA256" "$STARSHIP_SHA256_ARM64")"
522
529
  tar -xzf "$tmp/starship.tgz" -C /usr/local/bin starship
523
530
  rm -rf "$tmp"
524
531
  # oh-my-zsh compartido y de solo lectura en /opt; cada usuario lo carga desde su .zshrc.
@@ -555,7 +562,7 @@ ZSHRC
555
562
 
556
563
  install_tool_rust() {
557
564
  local tmp; tmp="$(mktemp -d)"
558
- fetch_verified "https://static.rust-lang.org/rustup/archive/${RUSTUP_VERSION}/x86_64-unknown-linux-gnu/rustup-init" "$tmp/rustup-init" "$RUSTUP_SHA256"
565
+ fetch_verified "https://static.rust-lang.org/rustup/archive/${RUSTUP_VERSION}/$(arch_pick x86_64 aarch64)-unknown-linux-gnu/rustup-init" "$tmp/rustup-init" "$(arch_pick "$RUSTUP_SHA256" "$RUSTUP_SHA256_ARM64")"
559
566
  chmod 0755 "$tmp/rustup-init"
560
567
  chown_if_runner "$tmp" "$tmp/rustup-init"
561
568
  # En el home de runner (cargo install escribe ahí); los proxies van al PATH del sistema.
@@ -583,7 +590,7 @@ install_tool_dotnet() {
583
590
  chmod go+r "$keyring"
584
591
  # shellcheck disable=SC1091
585
592
  . /etc/os-release
586
- echo "deb [arch=amd64 signed-by=$keyring] https://packages.microsoft.com/debian/${VERSION_ID}/prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft-prod.list
593
+ echo "deb [arch=${IMAGE_ARCH} signed-by=$keyring] https://packages.microsoft.com/debian/${VERSION_ID}/prod ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/microsoft-prod.list
587
594
  apt-get update -qq && apt-get install -y -qq --no-install-recommends dotnet-sdk-8.0 >/dev/null
588
595
  }
589
596
 
@@ -612,7 +619,7 @@ install_tool_group() {
612
619
  case "$1" in
613
620
  esenciales)
614
621
  ln -sf /usr/bin/fdfind /usr/local/bin/fd
615
- fetch_verified "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" /usr/local/bin/yq "$YQ_SHA256"
622
+ fetch_verified "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${IMAGE_ARCH}" /usr/local/bin/yq "$(arch_pick "$YQ_SHA256" "$YQ_SHA256_ARM64")"
616
623
  chmod 0755 /usr/local/bin/yq ;;
617
624
  busqueda)
618
625
  command -v npm >/dev/null 2>&1 || die "ast-grep se instala con npm y npm no está en el PATH"
@@ -621,13 +628,14 @@ install_tool_group() {
621
628
  shell) install_tool_shell ;;
622
629
  python)
623
630
  tmp="$(mktemp -d)"
624
- fetch_verified "https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-x86_64-unknown-linux-gnu.tar.gz" "$tmp/uv.tgz" "$UV_SHA256"
631
+ local uv_triple; uv_triple="$(arch_pick x86_64 aarch64)-unknown-linux-gnu"
632
+ fetch_verified "https://github.com/astral-sh/uv/releases/download/${UV_VERSION}/uv-${uv_triple}.tar.gz" "$tmp/uv.tgz" "$(arch_pick "$UV_SHA256" "$UV_SHA256_ARM64")"
625
633
  tar -xzf "$tmp/uv.tgz" -C "$tmp"
626
- install -m 0755 "$tmp"/uv-x86_64-unknown-linux-gnu/uv "$tmp"/uv-x86_64-unknown-linux-gnu/uvx /usr/local/bin/
634
+ install -m 0755 "$tmp/uv-${uv_triple}/uv" "$tmp/uv-${uv_triple}/uvx" /usr/local/bin/
627
635
  rm -rf "$tmp" ;;
628
636
  go)
629
637
  tmp="$(mktemp -d)"
630
- fetch_verified "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" "$tmp/go.tgz" "$GO_SHA256"
638
+ fetch_verified "https://go.dev/dl/go${GO_VERSION}.linux-${IMAGE_ARCH}.tar.gz" "$tmp/go.tgz" "$(arch_pick "$GO_SHA256" "$GO_SHA256_ARM64")"
631
639
  rm -rf /usr/local/go && tar -xzf "$tmp/go.tgz" -C /usr/local
632
640
  ln -sf /usr/local/go/bin/go /usr/local/bin/go
633
641
  ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt
@@ -641,18 +649,19 @@ install_tool_group() {
641
649
  # descargarlos la primera vez y un agente se quedaría esperando esa respuesta.
642
650
  as_runner env COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack install -g "pnpm@$PNPM_VERSION" "yarn@$YARN_VERSION" >/dev/null
643
651
  tmp="$(mktemp -d)"
644
- fetch_verified "https://github.com/oven-sh/bun/releases/download/bun-v${BUN_VERSION}/bun-linux-x64.zip" "$tmp/bun.zip" "$BUN_SHA256"
652
+ local bun_dir; bun_dir="bun-linux-$(arch_pick x64 aarch64)"
653
+ fetch_verified "https://github.com/oven-sh/bun/releases/download/bun-v${BUN_VERSION}/${bun_dir}.zip" "$tmp/bun.zip" "$(arch_pick "$BUN_SHA256" "$BUN_SHA256_ARM64")"
645
654
  unzip -q "$tmp/bun.zip" -d "$tmp"
646
- install -m 0755 "$tmp/bun-linux-x64/bun" /usr/local/bin/bun
655
+ install -m 0755 "$tmp/${bun_dir}/bun" /usr/local/bin/bun
647
656
  ln -sf /usr/local/bin/bun /usr/local/bin/bunx
648
657
  rm -rf "$tmp" ;;
649
658
  db) ;;
650
659
  docker) install_tool_docker ;;
651
660
  cloud)
652
- fetch_verified "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" /usr/local/bin/kubectl "$KUBECTL_SHA256"
661
+ fetch_verified "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/linux/${IMAGE_ARCH}/kubectl" /usr/local/bin/kubectl "$(arch_pick "$KUBECTL_SHA256" "$KUBECTL_SHA256_ARM64")"
653
662
  chmod 0755 /usr/local/bin/kubectl
654
663
  tmp="$(mktemp -d)"
655
- fetch_verified "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip" "$tmp/tf.zip" "$TERRAFORM_SHA256"
664
+ fetch_verified "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${IMAGE_ARCH}.zip" "$tmp/tf.zip" "$(arch_pick "$TERRAFORM_SHA256" "$TERRAFORM_SHA256_ARM64")"
656
665
  unzip -q "$tmp/tf.zip" -d "$tmp" && install -m 0755 "$tmp/terraform" /usr/local/bin/terraform
657
666
  rm -rf "$tmp" ;;
658
667
  esac
@@ -35,29 +35,39 @@ AZURE_CLI_VERSION=
35
35
  # Lo que sale de apt (Debian bookworm) va sin pin: lo fija la base de la imagen. Lo que se
36
36
  # descarga lleva versión y sha256 (de los ficheros de checksums oficiales de cada proyecto,
37
37
  # salvo delta, que no los publica: sha256 tomado al fijar la versión). Cambiar una versión
38
- # exige su checksum. oh-my-zsh y sus plugins se clonan en un commit fijado (git lo verifica).
38
+ # exige su checksum. Cada fichero lleva también la suma de su versión arm64 (_ARM64: imágenes
39
+ # construidas en un Mac con Apple Silicon), de la misma fuente oficial. oh-my-zsh y sus plugins se clonan en un commit fijado (git lo verifica).
39
40
  YQ_VERSION=v4.54.3
40
41
  YQ_SHA256=129534601871538efe0ba4c5e62a34fb1d5f469bcb975c4fddeb467d82974973
42
+ YQ_SHA256_ARM64=89f69310b61b68d1245065a1241d1fc843f7a36cd6103ffd77ad987613bd1b67
41
43
  AST_GREP_VERSION=0.51.3
42
44
  DELTA_VERSION=0.22.0
43
45
  DELTA_SHA256=109eac8927a80a7801e025901dcee8d56aa50a8de1805a111d98b5d6dbe5d647
46
+ DELTA_SHA256_ARM64=968964e9eb8a2e0b83b3aa27e29ce2ce61ace9ab51d4c37726f73d5559153fa2
44
47
  STARSHIP_VERSION=v1.27.0
45
48
  STARSHIP_SHA256=10c8eb4cb3b761d9bf59ea828444c2dab36c900b7d69a69e08814b286969df89
49
+ STARSHIP_SHA256_ARM64=341f5cbf24699fa0b27ec88965ad25f862ea09e15d35a543fd6ffdff1d2aa00d
46
50
  OHMYZSH_COMMIT=6c31a91a3e82b4055b36cc088c2f27f81119ba60
47
51
  ZSH_AUTOSUGGESTIONS_COMMIT=e52ee8ca55bcc56a17c828767a3f98f22a68d4eb
48
52
  ZSH_SYNTAX_HIGHLIGHTING_COMMIT=db085e4661f6aafd24e5acb5b2e17e4dd5dddf3e
49
53
  UV_VERSION=0.13.9
50
54
  UV_SHA256=a7fbaff2b9a271d85c1bdb540941090fd1ce011797b4abeb48e4dcd39c2471d5
55
+ UV_SHA256_ARM64=0797542018e541a9288855df555c8077eed06f7a47d206362030480e8ecc9f3d
51
56
  GO_VERSION=1.27.4
52
57
  GO_SHA256=7226736c2339719cda28fbf3a54d71aa63bcefe376e98cef00034268dab24840
58
+ GO_SHA256_ARM64=3392582988a273a87ab5043ee1b2c9c17a2c3c00580bf9326c47a2e0aaaeac92
53
59
  RUSTUP_VERSION=1.29.3
54
60
  RUSTUP_SHA256=b1c8cb14e30889e7e2999e6b69e62d9e9b9ffc0f4df8180564d306d9680e6c55
61
+ RUSTUP_SHA256_ARM64=9f608c142e0e38a78957d0661ba1dfaf0b6fb37184cfaa4b9a0aa57af6184282
55
62
  PNPM_VERSION=12.23.0
56
63
  YARN_VERSION=4.19.0
57
64
  BUN_VERSION=1.4.5
58
65
  BUN_SHA256=94559b3b528995a49452f9f2404cec74f2efd7d06e0a000a8cd214b02c3666eb
66
+ BUN_SHA256_ARM64=18656a3bf0ea5641f5796ae4213b75255579a70a0fded2f337933785568cdf84
59
67
  KUBECTL_VERSION=v1.37.2
60
68
  KUBECTL_SHA256=c04487523e7aa7d1493f7808174c899db93d7a9cf57531420cd76b9bd415f8f4
69
+ KUBECTL_SHA256_ARM64=fcc16f63186659d9722014b7e02d5fdd2d4e669cb8c0ab66365d7d3b8ba03509
61
70
  DEVCONTAINERS_CLI_VERSION=0.91.0
62
71
  TERRAFORM_VERSION=1.17.2
63
72
  TERRAFORM_SHA256=e6f16b2f0b137ee5729caa8c4e79a3bae4ee261acd198a1fcfa8584a6296605b
73
+ TERRAFORM_SHA256_ARM64=858e08c181a76b6b223e8c767a8e983922eebe2d062db949a2de66ce040c368c
package/src/cli.ts CHANGED
@@ -278,9 +278,15 @@ export async function handleStart(
278
278
  setupDeps?: SetupDeps
279
279
  ): Promise<number> {
280
280
  const overrides: Record<string, any> = {};
281
+ // Started by the user service itself (its unit/plist/task passes --as-service; launchd also
282
+ // names the job in XPC_SERVICE_NAME, for plists from before the flag): the service being
283
+ // «active» is this very process, not another one on the port (issue #5).
284
+ let asService = /(^|\.)bond-app\./.test(process.env.XPC_SERVICE_NAME ?? '');
281
285
  for (let i = 0; i < args.length; i++) {
282
286
  const arg = args[i];
283
- if (arg === '--port') {
287
+ if (arg === '--as-service') {
288
+ asService = true;
289
+ } else if (arg === '--port') {
284
290
  const v = args[++i];
285
291
  if (!v || v.startsWith('--')) throw new Error('--port requires a value');
286
292
  overrides.port = parseInt(v, 10);
@@ -326,7 +332,7 @@ export async function handleStart(
326
332
  dataDir: startDataDir,
327
333
  deps: setupDeps?.serviceDeps,
328
334
  });
329
- if (svcStatus.active) {
335
+ if (svcStatus.active && !asService) {
330
336
  console.error(
331
337
  `bond-app: port ${startPort} is already in use by the bond-app user service (${svcStatus.serviceName}).`
332
338
  );
@@ -974,6 +980,7 @@ Options:
974
980
  --port <port> HTTP port to listen on (default: 3000 or $BOND_APP_PORT)
975
981
  --host <host> Loopback interface to bind to (default: 127.0.0.1 or $BOND_APP_HOST)
976
982
  --data-dir <path> Data directory for database and token (default: ~/.bond-app or $BOND_APP_DATA_DIR)
983
+ --as-service Started by the user service itself (its unit, plist or task passes it)
977
984
  -h, --help Show this help
978
985
  `);
979
986
  }
@@ -26,9 +26,18 @@ export interface AgyLoginDriver {
26
26
 
27
27
  export class DefaultAgyLoginDriver implements AgyLoginDriver {
28
28
  async spawnContainer(containerName: string, image: string): Promise<void> {
29
+ // The runner image is built on this machine (Ajustes → Imagen), never pulled: without it,
30
+ // `docker run` went to Docker Hub and failed with «pull access denied».
31
+ try {
32
+ await execFileAsync('docker', ['image', 'inspect', image]);
33
+ } catch {
34
+ throw new Error(`${RUNNER_IMAGE_MISSING} (${image})`);
35
+ }
29
36
  await execFileAsync('docker', [
30
37
  'run',
31
38
  '-d',
39
+ '--pull',
40
+ 'never',
32
41
  '--name',
33
42
  containerName,
34
43
  '--label',
@@ -127,6 +136,9 @@ export class DefaultAgyLoginDriver implements AgyLoginDriver {
127
136
  }
128
137
  }
129
138
 
139
+ /** The logins run the agent's CLI in the runner image: it has to be built first. */
140
+ export const RUNNER_IMAGE_MISSING = 'Falta la imagen del runner: los logins de los agentes se hacen dentro de ella. Constrúyela en Ajustes → Imagen (tarda unos minutos) y vuelve a iniciar sesión';
141
+
130
142
  /** What a login is, per agent: the same container + tmux pilot, different CLI and result. */
131
143
  /** What a spec may do in the login container besides reading its screen. */
132
144
  export interface LoginContext {
@@ -59,7 +59,7 @@ function winQuote(arg: string): string {
59
59
  export function buildTaskCommand(opts: WindowsServiceOptions = {}): string {
60
60
  const nodePath = opts.nodePath ?? process.execPath;
61
61
  const binPath = path.resolve(opts.binPath ?? path.join(repoRoot, 'bin', 'bond-app.js'));
62
- const parts = [winQuote(nodePath), winQuote(binPath), 'start'];
62
+ const parts = [winQuote(nodePath), winQuote(binPath), 'start', '--as-service'];
63
63
  if (opts.port !== undefined) {
64
64
  parts.push('--port', String(opts.port));
65
65
  }
@@ -191,6 +191,7 @@ export function renderSystemdUnit(params: {
191
191
  quoteSystemdArg(params.nodePath),
192
192
  quoteSystemdArg(params.binPath),
193
193
  'start',
194
+ '--as-service',
194
195
  '--port',
195
196
  String(params.port),
196
197
  '--data-dir',
@@ -253,6 +254,7 @@ export function renderLaunchdPlist(params: {
253
254
  params.nodePath,
254
255
  params.binPath,
255
256
  'start',
257
+ '--as-service',
256
258
  '--port',
257
259
  String(params.port),
258
260
  '--data-dir',
@@ -88,6 +88,8 @@ export interface SetupOptions {
88
88
  export interface SetupDeps {
89
89
  fetch?: FetchLike;
90
90
  runCommand?: (cmd: string, args: string[], timeoutMs?: number) => Promise<CommandOutput>;
91
+ /** Where the installed bond comes from (npm, Homebrew, its own binary); tests fake it. */
92
+ bondOrigin?: (runCommand: (cmd: string, args: string[], timeoutMs?: number) => Promise<CommandOutput>, platform: NodeJS.Platform) => Promise<BondOrigin>;
91
93
  homeDir?: string;
92
94
  dataDir?: string;
93
95
  herdrAppHome?: string;
@@ -757,13 +759,16 @@ export async function runSetup(options: SetupOptions = {}): Promise<SetupResult>
757
759
  steps.push({ id: 'bond', ok: true, skipped: true, detail });
758
760
  bondVersion = targetBondVersion;
759
761
  } else {
760
- const npmRes = await runCommand(
761
- 'npm',
762
- ['install', '-g', `@jmanuelcorral/bond@${targetBondVersion}`, NPM_PUBLIC_REGISTRY_ARG],
763
- 180_000
764
- );
762
+ // An old bond from Homebrew or its own binary is upgraded that way: npm would hit EEXIST.
763
+ const origin = bondRes.ok ? await (deps.bondOrigin ?? detectBondOrigin)(runCommand, platform) : { kind: 'none' as const, path: null };
764
+ const [bin, binArgs]: [string, string[]] = origin.kind === 'brew'
765
+ ? ['brew', ['upgrade', BOND_BREW_FORMULA]]
766
+ : origin.kind === 'binary'
767
+ ? ['bond', ['update']]
768
+ : ['npm', ['install', '-g', `@jmanuelcorral/bond@${targetBondVersion}`, NPM_PUBLIC_REGISTRY_ARG]];
769
+ const npmRes = await runCommand(bin, binArgs, 180_000);
765
770
  if (!npmRes.ok) {
766
- const fix = `npm install -g @jmanuelcorral/bond@${targetBondVersion} ${NPM_PUBLIC_REGISTRY_ARG}`;
771
+ const fix = `${bin} ${binArgs.join(' ')}`;
767
772
  logStep('✗', 'bond CLI', npmRes.stderr.trim() || npmRes.error || 'npm install failed', fix);
768
773
  steps.push({ id: 'bond', ok: false, detail: 'npm install failed' });
769
774
  return { ok: false, dryRun, steps, record: null };
@@ -1099,29 +1104,34 @@ export async function runUpdate(options: UpdateOptions = {}): Promise<UpdateResu
1099
1104
 
1100
1105
  log(`bond-app update (${normPlatform}${dryRun ? ', dry-run' : ''})`);
1101
1106
 
1102
- // 1. Update @jmanuelcorral/bond via npm (public registry). bond goes first: up to 1.16.8 it
1103
- // shipped its own `bond-app` bin, and npm would refuse to install bond-app over it (EEXIST).
1107
+ // 1. Update bond the way it was installed, first: up to 1.16.8 it shipped its own `bond-app`
1108
+ // bin, and npm would refuse to install bond-app over it (EEXIST). A bond from Homebrew
1109
+ // (jmanuelcorral/tap/bond) or bond's own binary is not npm's: `npm install -g` hits EEXIST
1110
+ // on its file. A failure here warns and goes on: bond-app still gets updated.
1111
+ const bondOrigin = await (deps.bondOrigin ?? detectBondOrigin)(runCommand, platform);
1112
+ const bondUpdate: [string, string[]] = bondOrigin.kind === 'brew'
1113
+ ? ['brew', ['upgrade', BOND_BREW_FORMULA]]
1114
+ : bondOrigin.kind === 'binary'
1115
+ ? ['bond', ['update']]
1116
+ : ['npm', ['install', '-g', '@jmanuelcorral/bond@latest', NPM_PUBLIC_REGISTRY_ARG]];
1117
+ const via = bondOrigin.kind === 'brew' ? 'Homebrew' : bondOrigin.kind === 'binary' ? `its own binary (${bondOrigin.path})` : 'npm';
1104
1118
  if (dryRun) {
1105
- const detail = `would run: npm install -g @jmanuelcorral/bond@latest ${NPM_PUBLIC_REGISTRY_ARG}`;
1119
+ const detail = `would run: ${bondUpdate[0]} ${bondUpdate[1].join(' ')} (bond from ${via})`;
1106
1120
  logStep('✓', 'bond CLI', detail);
1107
1121
  steps.push({ id: 'bond', ok: true, skipped: true, detail });
1108
1122
  } else {
1109
- const npmRes = await runCommand(
1110
- 'npm',
1111
- ['install', '-g', '@jmanuelcorral/bond@latest', NPM_PUBLIC_REGISTRY_ARG],
1112
- 180_000
1113
- );
1114
- if (!npmRes.ok) {
1115
- const fix = `npm install -g @jmanuelcorral/bond@latest ${NPM_PUBLIC_REGISTRY_ARG}`;
1116
- logStep('✗', 'bond CLI', npmRes.stderr.trim() || npmRes.error || 'npm install failed', fix);
1117
- steps.push({ id: 'bond', ok: false, detail: 'npm install failed' });
1118
- return { ok: false, dryRun, steps, imageOutdated: false };
1123
+ const res = await runCommand(bondUpdate[0], bondUpdate[1], 180_000);
1124
+ if (!res.ok) {
1125
+ const fix = `${bondUpdate[0]} ${bondUpdate[1].join(' ')}`;
1126
+ logStep('!', 'bond CLI', `not updated (bond from ${via}): ${(res.stderr.trim() || res.error || 'failed').split('\n').slice(-3).join(' ')}`, fix);
1127
+ steps.push({ id: 'bond', ok: true, skipped: true, detail: `not updated (${via})` });
1128
+ } else {
1129
+ const verRes = await runCommand('bond', ['--version'], 10_000);
1130
+ const ver = verRes.ok ? extractSemver(verRes.stdout) : null;
1131
+ const detail = `${ver ? `updated to ${ver}` : 'updated'} (${via})`;
1132
+ logStep('✓', 'bond CLI', detail);
1133
+ steps.push({ id: 'bond', ok: true, detail });
1119
1134
  }
1120
- const verRes = await runCommand('bond', ['--version'], 10_000);
1121
- const ver = verRes.ok ? extractSemver(verRes.stdout) : null;
1122
- const detail = ver ? `updated to ${ver}` : 'updated';
1123
- logStep('✓', 'bond CLI', detail);
1124
- steps.push({ id: 'bond', ok: true, detail });
1125
1135
  }
1126
1136
 
1127
1137
  // 2. Update @jmanuelcorral/bond-app via npm (public registry)
@@ -1402,3 +1412,48 @@ export async function runUninstall(options: UninstallOptions = {}): Promise<Unin
1402
1412
  log(' Note: herdr-app, hc and bond were not uninstalled (they may be used by other projects).');
1403
1413
  return { ok: allOk, dryRun, purged, steps };
1404
1414
  }
1415
+
1416
+ /** The Homebrew formula of bond (the jmanuelcorral tap). */
1417
+ export const BOND_BREW_FORMULA = 'jmanuelcorral/tap/bond';
1418
+
1419
+ export interface BondOrigin {
1420
+ kind: 'npm' | 'brew' | 'binary' | 'none';
1421
+ path: string | null;
1422
+ }
1423
+
1424
+ /**
1425
+ * Where the `bond` on PATH comes from, by its real path: Homebrew's Cellar, npm's global
1426
+ * node_modules, or bond's own binary (install.sh); none when there is no bond.
1427
+ */
1428
+ export async function detectBondOrigin(
1429
+ runCommand: (cmd: string, args: string[], timeoutMs?: number) => Promise<CommandOutput>,
1430
+ platform: NodeJS.Platform
1431
+ ): Promise<BondOrigin> {
1432
+ const exe = platform === 'win32' ? ['bond.cmd', 'bond.exe', 'bond'] : ['bond'];
1433
+ let found: string | null = null;
1434
+ for (const dir of String(process.env.PATH ?? '').split(path.delimiter)) {
1435
+ for (const name of exe) {
1436
+ const p = path.join(dir, name);
1437
+ if (dir && fs.existsSync(p)) {
1438
+ found = p;
1439
+ break;
1440
+ }
1441
+ }
1442
+ if (found) break;
1443
+ }
1444
+ if (!found) return { kind: 'none', path: null };
1445
+ let real = found;
1446
+ try {
1447
+ real = fs.realpathSync(found);
1448
+ } catch {}
1449
+ return { kind: classifyBondPath(real, (await runCommand('npm', ['root', '-g'], 15_000)).stdout.trim()), path: real };
1450
+ }
1451
+
1452
+ /** brew when it lives in a Homebrew Cellar, npm when under npm's global root (or an npm package), else binary. */
1453
+ export function classifyBondPath(real: string, npmRoot: string): BondOrigin['kind'] {
1454
+ const r = real.replace(/\\/g, '/');
1455
+ if (/\/Cellar\/bond\//.test(r) || /\/homebrew\/Cellar\//i.test(r)) return 'brew';
1456
+ const root = npmRoot.replace(/\\/g, '/');
1457
+ if ((root && r.startsWith(`${root}/`)) || /\/node_modules\/@jmanuelcorral\/bond\//.test(r)) return 'npm';
1458
+ return 'binary';
1459
+ }