@moondeck/station 1.0.2 → 1.0.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.
@@ -373,7 +373,7 @@ git rev-parse --show-toplevel
373
373
  export const SETUP_SCRIPT = `set -u
374
374
  IFS= read -r nonce || nonce=""
375
375
  case "$nonce" in *[!0-9a-f]*|"") echo "uai: setup needs its nonce" >&2; exit 64 ;; esac
376
- mark() { printf 'uai-setup-%s %s %s\\n' "$nonce" "$1" "$2"; }
376
+ mark() { [ "$1" != invalid-runtime ] || runtime_invalid=1; printf 'uai-setup-%s %s %s\\n' "$nonce" "$1" "$2"; }
377
377
  quiet() { "$@" </dev/null 1>&2; }
378
378
  # The effective requirements: this folder's .tool-versions (the repository's,
379
379
  # or the project's fallback Prepare seeded, as at start), parsed and checked
@@ -411,6 +411,7 @@ check_runtime() {
411
411
  ;;
412
412
  esac
413
413
  case "/$version/" in *"/../"*|*"/./"*|*"//"*) mark invalid-runtime "$tool $version (unsafe version path)"; return 0 ;; esac
414
+ case "$tool" in nodejs|python|golang|ruby|rust|bun) ;; *) return 0 ;; esac
414
415
  if ! command -v asdf >/dev/null 2>&1; then
415
416
  mark missing-runtime "$tool $version (no asdf to check it)"
416
417
  elif ! asdf where "$tool" "$version" </dev/null >/dev/null 2>&1; then
@@ -423,17 +424,24 @@ elif [ -f .tool-versions ]; then
423
424
  if LC_ALL=C grep -q '[[:cntrl:]]' .tool-versions; then
424
425
  mark invalid-runtime ".tool-versions (control characters; a start would refuse it)"
425
426
  else
427
+ declare -A seen_tools=()
426
428
  while IFS= read -r line || [ -n "$line" ]; do
427
429
  line=\${line%%#*}
428
430
  read -r -a fields <<< "$line" || true
429
431
  [ "\${#fields[@]}" -gt 0 ] || continue
430
432
  tool=\${fields[0]}
433
+ runtime_invalid=0
431
434
  if [ "\${#fields[@]}" -lt 2 ] || [[ ! "$tool" =~ ^[a-z0-9][a-z0-9_-]*$ ]]; then
432
435
  mark invalid-runtime "$line (a start would refuse this line)"
433
436
  continue
434
437
  fi
438
+ if [ -n "\${seen_tools[$tool]:-}" ]; then
439
+ mark invalid-runtime "$tool (duplicate tool)"
440
+ continue
441
+ fi
442
+ seen_tools[$tool]=1
435
443
  case "$tool" in
436
- nodejs|python|golang|ruby|rust)
444
+ nodejs|python|golang|ruby|rust|bun)
437
445
  for version in "\${fields[@]:1}"; do check_runtime "$tool" "$version"; done
438
446
  ;;
439
447
  pnpm|yarn)
@@ -442,7 +450,16 @@ elif [ -f .tool-versions ]; then
442
450
  mark invalid-runtime "$tool \${fields[*]:1} (must pin one exact version)"
443
451
  fi
444
452
  ;;
445
- *) mark invalid-runtime "$tool (not a runtime a task can install)" ;;
453
+ *)
454
+ for version in "\${fields[@]:1}"; do check_runtime "$tool" "$version"; done
455
+ if [ "$runtime_invalid" -eq 0 ]; then
456
+ case "$tool" in
457
+ node) mark skipped-runtime "$tool (did you mean nodejs?)" ;;
458
+ go) mark skipped-runtime "$tool (did you mean golang?)" ;;
459
+ *) mark skipped-runtime "$tool" ;;
460
+ esac
461
+ fi
462
+ ;;
446
463
  esac
447
464
  done < .tool-versions
448
465
  fi
@@ -495,10 +512,11 @@ export function boundWarning(value: string): string {
495
512
  export function parseSetupResult(
496
513
  stdout: string,
497
514
  nonce: string,
498
- ): { missing: string[]; invalid: string[]; failed: string[] } {
515
+ ): { missing: string[]; invalid: string[]; failed: string[]; skipped: string[] } {
499
516
  const missing: string[] = [];
500
517
  const invalid: string[] = [];
501
518
  const failed: string[] = [];
519
+ const skipped: string[] = [];
502
520
  const prefix = `uai-setup-${nonce} `;
503
521
  for (const raw of stdout.split("\n")) {
504
522
  if (!raw.startsWith(prefix)) continue;
@@ -510,9 +528,10 @@ export function parseSetupResult(
510
528
  if (!item) continue;
511
529
  if (kind === "missing-runtime" && missing.length < 20) missing.push(item);
512
530
  if (kind === "invalid-runtime" && invalid.length < 20) invalid.push(item);
531
+ if (kind === "skipped-runtime" && skipped.length < 20) skipped.push(item);
513
532
  if (kind === "failed-step" && failed.length < 20) failed.push(item);
514
533
  }
515
- return { missing, invalid, failed };
534
+ return { missing, invalid, failed, skipped };
516
535
  }
517
536
 
518
537
  export type TaskProjectEnvironment = Pick<TaskEnvironmentHandle, "exec" | "descriptor">;
@@ -955,12 +974,15 @@ export class TaskProjectOps {
955
974
  if ("error" in setup) {
956
975
  warnings.push(`dependency setup could not run: ${String((setup as { error: unknown }).error)}`);
957
976
  } else {
958
- const { missing, invalid, failed } = parseSetupResult(text(setup.stdout), nonce);
977
+ const { missing, invalid, failed, skipped } = parseSetupResult(text(setup.stdout), nonce);
959
978
  if (invalid.length > 0) {
960
979
  warnings.push(
961
980
  `the repository's .tool-versions has entries a task start would refuse (${invalid.join(", ")}); fix them before the task restarts`,
962
981
  );
963
982
  }
983
+ if (skipped.length > 0) warnings.push(
984
+ `unsupported tools skipped (${skipped.join(", ")}); use mise install <tool>@<version>, then mise exec -- <cmd> (or their vendor installers)`,
985
+ );
964
986
  if (missing.length > 0) {
965
987
  warnings.push(
966
988
  `runtimes this repository asks for are not installed in this task (${missing.join(", ")}). ` +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moondeck/station",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Moondeck Station: runs Moondeck tasks in containers on a machine you control.",
5
5
  "license": "MIT",
6
6
  "author": "Moondeck <team@moondeck.io>",
@@ -43,6 +43,31 @@ ASDF_VOLUME="moondeck-asdf-data"
43
43
  STANDARD_DEFAULT_NODE_VERSION="22.11.0"
44
44
  TASK_NPM_PREFIX="/home/node/.local/share/uai-npm"
45
45
  TASK_NPM_CACHE="/home/node/.cache/uai-npm"
46
+ # Root's npm settings for every root exec (keep in sync with
47
+ # ROOT_NPM_AUTHORITY_ENV in lib/runtime-authority.ts). The TASK_NPM_* paths
48
+ # and node's ~/.npmrc are node-controlled, so a root exec must never inherit
49
+ # them from Compose or managed_exec_env: npm would resolve its cache, logs,
50
+ # prefix (and <prefix>/etc/npmrc) into files node can plant. /root is
51
+ # root-only. userconfig is /dev/null; globalconfig is a never-created file in
52
+ # the root-only state dir (npm exits if both name /dev/null). Both spellings, because npm
53
+ # matches npm_config_* case-insensitively.
54
+ ROOT_NPM_STATE_DIR="/root/.uai-npm"
55
+ root_npm_exec_env=(
56
+ -e "NPM_CONFIG_PREFIX=$ROOT_NPM_STATE_DIR/prefix"
57
+ -e "npm_config_prefix=$ROOT_NPM_STATE_DIR/prefix"
58
+ -e "NPM_CONFIG_CACHE=$ROOT_NPM_STATE_DIR/cache"
59
+ -e "npm_config_cache=$ROOT_NPM_STATE_DIR/cache"
60
+ -e "NPM_CONFIG_LOGS_DIR=$ROOT_NPM_STATE_DIR/cache/_logs"
61
+ -e "npm_config_logs_dir=$ROOT_NPM_STATE_DIR/cache/_logs"
62
+ -e "NPM_CONFIG_USERCONFIG=/dev/null"
63
+ -e "npm_config_userconfig=/dev/null"
64
+ -e "NPM_CONFIG_GLOBALCONFIG=$ROOT_NPM_STATE_DIR/npmrc"
65
+ -e "npm_config_globalconfig=$ROOT_NPM_STATE_DIR/npmrc"
66
+ -e "NPM_CONFIG_REGISTRY=https://registry.npmjs.org/"
67
+ -e "npm_config_registry=https://registry.npmjs.org/"
68
+ -e "NPM_CONFIG_UMASK=0022"
69
+ -e "npm_config_umask=0022"
70
+ )
46
71
  # Host-proved shims and system controls always win. A task-global package with
47
72
  # a new command name remains discoverable at the final path component, while a
48
73
  # package named node/claude/git/sh cannot intercept managed or agent startup.
@@ -2023,6 +2048,7 @@ mv -f "$managed_env_keys_tmp" "$managed_env_keys_file"
2023
2048
  printf ' ASDF_GOLANG_VERSION: ""\n'
2024
2049
  printf ' ASDF_RUBY_VERSION: ""\n'
2025
2050
  printf ' ASDF_RUST_VERSION: ""\n'
2051
+ printf ' ASDF_BUN_VERSION: ""\n'
2026
2052
  printf ' ASDF_SKIP_RESHIM: "1"\n'
2027
2053
  printf ' COREPACK_HOME: "/opt/asdf-data/corepack"\n'
2028
2054
  printf ' COREPACK_DEFAULT_TO_LATEST: "0"\n'
@@ -2488,6 +2514,7 @@ if [ "$TASK_RUNTIME_MODE" = "apple-container" ]; then
2488
2514
  printf 'ASDF_GOLANG_VERSION=\n'
2489
2515
  printf 'ASDF_RUBY_VERSION=\n'
2490
2516
  printf 'ASDF_RUST_VERSION=\n'
2517
+ printf 'ASDF_BUN_VERSION=\n'
2491
2518
  printf 'ASDF_SKIP_RESHIM=1\n'
2492
2519
  printf 'COREPACK_HOME=/opt/asdf-data/corepack\n'
2493
2520
  printf 'COREPACK_DEFAULT_TO_LATEST=0\n'
@@ -2877,7 +2904,7 @@ fi
2877
2904
  if [ "$TASK_RUNTIME_MODE" = "apple-container" ]; then
2878
2905
  step "CONTAINER_INIT_FAILED" "establish task runtime overlay"
2879
2906
  overlay_rc=0
2880
- "$CONTAINER_CLI" exec -u root "$app_container" /bin/sh -c '
2907
+ "$CONTAINER_CLI" exec -u root "${root_npm_exec_env[@]}" "$app_container" /bin/sh -c '
2881
2908
  set -e
2882
2909
  # Apple has no run --sysctl option. This guest has its own kernel and
2883
2910
  # CAP_NET_ADMIN, so set the equivalent before any task process starts.
@@ -2981,7 +3008,8 @@ step "CONTAINER_INIT_FAILED" "uai-init (deps + code-server)"
2981
3008
  # plus absolute command paths so a project value cannot redirect this managed
2982
3009
  # credential operation to workspace code or another config directory.
2983
3010
  managed_gh_config_dir="/home/node/.config/gh"
2984
- managed_exec_env=(
3011
+ # Shared by root and node managed execs; each adds its own npm settings below.
3012
+ managed_common_exec_env=(
2985
3013
  -e "HOME=/home/node"
2986
3014
  -e "GH_CONFIG_DIR=$managed_gh_config_dir"
2987
3015
  -e "PATH=/usr/bin:/bin"
@@ -2997,6 +3025,7 @@ managed_exec_env=(
2997
3025
  -e "ASDF_GOLANG_VERSION="
2998
3026
  -e "ASDF_RUBY_VERSION="
2999
3027
  -e "ASDF_RUST_VERSION="
3028
+ -e "ASDF_BUN_VERSION="
3000
3029
  -e "ASDF_SKIP_RESHIM=1"
3001
3030
  -e "COREPACK_HOME=/opt/asdf-data/corepack"
3002
3031
  -e "COREPACK_DEFAULT_TO_LATEST=0"
@@ -3009,14 +3038,6 @@ managed_exec_env=(
3009
3038
  -e "COREPACK_ENABLE_STRICT=1"
3010
3039
  -e "COREPACK_ENABLE_UNSAFE_CUSTOM_URLS=0"
3011
3040
  -e "COREPACK_INTEGRITY_CHECK=1"
3012
- -e "NPM_CONFIG_PREFIX=$TASK_NPM_PREFIX"
3013
- -e "npm_config_prefix=$TASK_NPM_PREFIX"
3014
- -e "NPM_CONFIG_CACHE=$TASK_NPM_CACHE"
3015
- -e "npm_config_cache=$TASK_NPM_CACHE"
3016
- -e "NPM_CONFIG_LOGS_DIR=$TASK_NPM_CACHE/_logs"
3017
- -e "npm_config_logs_dir=$TASK_NPM_CACHE/_logs"
3018
- -e "NPM_CONFIG_UMASK=0002"
3019
- -e "npm_config_umask=0002"
3020
3041
  -e "LD_PRELOAD="
3021
3042
  -e "LD_AUDIT="
3022
3043
  -e "LD_LIBRARY_PATH="
@@ -3038,6 +3059,24 @@ managed_exec_env=(
3038
3059
  -e "GH_TOKEN="
3039
3060
  -e "GITHUB_TOKEN="
3040
3061
  )
3062
+ # Node managed execs: node's own task-private npm locations, as before.
3063
+ managed_exec_env=(
3064
+ "${managed_common_exec_env[@]}"
3065
+ -e "NPM_CONFIG_PREFIX=$TASK_NPM_PREFIX"
3066
+ -e "npm_config_prefix=$TASK_NPM_PREFIX"
3067
+ -e "NPM_CONFIG_CACHE=$TASK_NPM_CACHE"
3068
+ -e "npm_config_cache=$TASK_NPM_CACHE"
3069
+ -e "NPM_CONFIG_LOGS_DIR=$TASK_NPM_CACHE/_logs"
3070
+ -e "npm_config_logs_dir=$TASK_NPM_CACHE/_logs"
3071
+ -e "NPM_CONFIG_UMASK=0002"
3072
+ -e "npm_config_umask=0002"
3073
+ )
3074
+ # Root managed execs: the same controls with root-only npm settings, so a
3075
+ # root exec never carries an npm path under /home/node.
3076
+ root_exec_env=(
3077
+ "${managed_common_exec_env[@]}"
3078
+ "${root_npm_exec_env[@]}"
3079
+ )
3041
3080
  managed_clean_env=(
3042
3081
  /usr/bin/env -i
3043
3082
  "HOME=/home/node"
@@ -3064,6 +3103,7 @@ task_runtime_exec_env=(
3064
3103
  -e "ASDF_GOLANG_VERSION="
3065
3104
  -e "ASDF_RUBY_VERSION="
3066
3105
  -e "ASDF_RUST_VERSION="
3106
+ -e "ASDF_BUN_VERSION="
3067
3107
  -e "ASDF_SKIP_RESHIM=1"
3068
3108
  -e "COREPACK_HOME=/opt/asdf-data/corepack"
3069
3109
  -e "COREPACK_DEFAULT_TO_LATEST=0"
@@ -3127,7 +3167,7 @@ secrets_proxy_report() {
3127
3167
  }
3128
3168
  if [ "$UAI_PROJECT_ENV_MODE" = "loader" ] && [ -n "$secrets_proxy_dir" ]; then
3129
3169
  if [ -f "$secrets_proxy_dir/ca-install.sh" ] && [ -f "$secrets_proxy_dir/ca-bundle.pem" ] \
3130
- && crt exec -i -u root "${managed_exec_env[@]}" "$app_container" \
3170
+ && crt exec -i -u root "${root_exec_env[@]}" "$app_container" \
3131
3171
  /bin/sh -c "$(cat "$secrets_proxy_dir/ca-install.sh")" \
3132
3172
  < "$secrets_proxy_dir/ca-bundle.pem" >/dev/null; then
3133
3173
  secrets_proxy_trust=installed
@@ -3199,7 +3239,7 @@ ensure_block /etc/zsh/zshrc '[ "${UAI_ENV_HOOK-0}" != 1 ] || { type __uai_env_in
3199
3239
  ensure_block /etc/bash.bashrc '[ "${UAI_ENV_HOOK-0}" != 1 ] || { . /usr/local/share/uai/env-hook.sh; __uai_env_sync; __uai_env_install_bash_preexec; }'
3200
3240
  ensure_block /etc/profile.d/uai-env.sh '[ "${UAI_ENV_HOOK-0}" != 1 ] || { . /usr/local/share/uai/env-hook.sh; if [ -z "${BASH_EXECUTION_STRING-}" ] || [ -z "${BASH_ENV-}" ]; then __uai_env_sync; fi; }'
3201
3241
  UAI_ENV_STUB_INSTALLER
3202
- if ! crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3242
+ if ! crt exec -u root "${root_exec_env[@]}" "$app_container" \
3203
3243
  /bin/bash -c "$env_stub_installer" >/dev/null; then
3204
3244
  emit_err "CONTAINER_INIT_FAILED" \
3205
3245
  "Moondeck could not install the root-owned task env shell hooks. Retry the task; project env remains withheld until this succeeds." \
@@ -3316,7 +3356,7 @@ UAI_TASK_FORWARDER_LAUNCHER
3316
3356
  fi
3317
3357
  if ! printf '%s' "$task_gateway_secret_b64" \
3318
3358
  | base64 "${base64_decode_args[@]}" \
3319
- | crt exec -i -u root "${managed_exec_env[@]}" "$app_container" \
3359
+ | crt exec -i -u root "${root_exec_env[@]}" "$app_container" \
3320
3360
  /bin/bash -c "$task_forwarder_launcher" uai-task-forwarder \
3321
3361
  "$task_id" "$task_gateway_generation" "$task_gateway_host" \
3322
3362
  "$task_gateway_port" "$task_forwarder_node" \
@@ -3344,12 +3384,12 @@ secrets_proxy_chain() {
3344
3384
  else
3345
3385
  set -- docker exec --privileged -u root
3346
3386
  fi
3347
- "$@" "${managed_exec_env[@]}" "$app_container" \
3387
+ "$@" "${root_exec_env[@]}" "$app_container" \
3348
3388
  /bin/sh -c "$(cat "$secrets_proxy_dir/chain.sh")" >/dev/null \
3349
3389
  || { log "warning: could not redirect the secrets proxy's names in ${app_container}"; return 1; }
3350
3390
  }
3351
3391
  secrets_proxy_names() {
3352
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3392
+ crt exec -u root "${root_exec_env[@]}" "$app_container" \
3353
3393
  /bin/sh -c "$(cat "$secrets_proxy_dir/pins.sh")" >/dev/null \
3354
3394
  || { log "warning: could not pin the secrets proxy's names in ${app_container}"; return 1; }
3355
3395
  }
@@ -3382,7 +3422,12 @@ for node_data_phase in repair create repair; do
3382
3422
  node_data_user=root
3383
3423
  node_data_argv=( /usr/bin/python3 -I -c "$NODE_STATE_SETUP_SCRIPT" )
3384
3424
  fi
3385
- if ! crt exec -u "$node_data_user" "${managed_exec_env[@]}" "$app_container" "${node_data_argv[@]}" >/dev/null; then
3425
+ if [ "$node_data_user" = root ]; then
3426
+ node_data_env=( "${root_exec_env[@]}" )
3427
+ else
3428
+ node_data_env=( "${managed_exec_env[@]}" )
3429
+ fi
3430
+ if ! crt exec -u "$node_data_user" "${node_data_env[@]}" "$app_container" "${node_data_argv[@]}" >/dev/null; then
3386
3431
  emit_err "CONTAINER_INIT_FAILED" \
3387
3432
  "Moondeck could not prepare node-owned application data directory metadata." \
3388
3433
  "prepare container application data"
@@ -3495,27 +3540,66 @@ if [ -n "$github_credential_socket" ]; then
3495
3540
  fi
3496
3541
  fi
3497
3542
 
3543
+ # Root never creates, copies, chowns or chmods a path inside /home/node: on a
3544
+ # resumed container node can plant a symlink or hardlink there in advance (or
3545
+ # swap one in mid-run) and redirect root onto a file node does not own. Host
3546
+ # copies therefore stream over stdin to node, which writes its own files
3547
+ # (uai-write-node-data, the same asset lib/node-state.ts sends). Root only hands
3548
+ # entries an older root-run step left root-owned back to node, through pinned
3549
+ # no-follow descriptors (uai-repair-node-data.py): links, hardlinks, foreign
3550
+ # owners and other filesystems are logged and skipped, and it never fails.
3551
+ NODE_DATA_WRITE_SCRIPT=$(cat "$STANDARD_CONTAINER_DIR/uai-write-node-data")
3552
+ node_home_repair() {
3553
+ node_home_repair_log=$(crt exec -u root "${root_exec_env[@]}" "$app_container" \
3554
+ /usr/bin/python3 -I -c "$NODE_STATE_SETUP_SCRIPT" "$@" 2>&1 >/dev/null) \
3555
+ || log "warning: node home metadata repair could not run ($*)"
3556
+ if [ -n "$node_home_repair_log" ]; then
3557
+ printf '%s\n' "$node_home_repair_log" | while IFS= read -r node_home_repair_line; do
3558
+ log "warning: $node_home_repair_line"
3559
+ done
3560
+ fi
3561
+ }
3562
+ # Octal permission bits of a host file (GNU stat, else BSD stat), like the
3563
+ # mode `docker cp` used to preserve.
3564
+ host_file_mode() {
3565
+ host_mode=$(stat -c '%a' "$1" 2>/dev/null) \
3566
+ || host_mode=$(stat -f '%Lp' "$1" 2>/dev/null) || host_mode=600
3567
+ case $host_mode in '' | *[!0-7]*) host_mode=600 ;; esac
3568
+ printf '%s\n' "$host_mode"
3569
+ }
3570
+ # <host-file> <container-dest> [<mode> [<parent-mode>]]: node writes it atomically.
3571
+ node_home_put_file() {
3572
+ node_put_mode=${3:-}
3573
+ [ -n "$node_put_mode" ] || node_put_mode=$(host_file_mode "$1")
3574
+ crt exec -i -u node "${managed_exec_env[@]}" "$app_container" \
3575
+ /bin/sh -c "$NODE_DATA_WRITE_SCRIPT" uai-write-node-data file "$2" \
3576
+ "$node_put_mode" ${4:+"$4"} <"$1" >/dev/null
3577
+ }
3578
+ # <host-dir> <container-dest-dir> <member>: node extracts a host tar of it.
3579
+ node_home_put_tree() {
3580
+ COPYFILE_DISABLE=1 tar -C "$1" -cf - "$3" \
3581
+ | crt exec -i -u node "${managed_exec_env[@]}" "$app_container" \
3582
+ /bin/sh -c "$NODE_DATA_WRITE_SCRIPT" uai-write-node-data tar "$2" >/dev/null
3583
+ }
3584
+ node_home_repair .claude.json:-:- .codex:-:r .kimi-code:-:r .grok:-:r \
3585
+ .ssh:0700:r .ssh/id_ed25519:0600:-
3586
+
3498
3587
  # Copy `.claude.json` into the container instead of bind-mounting it.
3499
3588
  # Single-file bind mounts on Docker Desktop macOS are fragile — claude
3500
3589
  # CLI atomically rewrites the file on every start, which can invalidate
3501
3590
  # the bind mount and leave a stale dentry, after which claude refuses to
3502
- # start. docker cp gives the container its own stable copy. Best-effort.
3591
+ # start. A container-local copy is stable. Best-effort.
3503
3592
  if [ "$uai_on_cloud_credentials" != "1" ] && [ -f "$UAI_OWNER_HOME/.claude.json" ]; then
3504
- crt cp "$UAI_OWNER_HOME/.claude.json" \
3505
- "$app_container":/home/node/.claude.json >/dev/null 2>&1 \
3506
- || log "warning: crt cp of .claude.json failed; claude may need re-login"
3507
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3508
- /usr/bin/chown node:node /home/node/.claude.json >/dev/null 2>&1 || true
3593
+ node_home_put_file "$UAI_OWNER_HOME/.claude.json" /home/node/.claude.json \
3594
+ || log "warning: copy of .claude.json failed; claude may need re-login"
3509
3595
  fi
3510
3596
 
3511
3597
  # Copy Codex credentials/config into a task-private /home/node/.codex.
3512
3598
  # Do not mount the host ~/.codex writable: Codex stores live SQLite state
3513
3599
  # there, and concurrent host/container access can corrupt it.
3514
- # Failures here are REAL errors (the container is running at task-up):
3515
- # docker cp preserves the host uid/gid, so a skipped chown leaves 0600
3516
- # files owned by e.g. macOS 501:20 that the container's node (1000:1000)
3517
- # cannot read — Codex then dies at startup.
3518
- if crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3600
+ # Failures here are REAL errors (the container is running at task-up): node
3601
+ # writes these files, so they are node-owned with the host's modes.
3602
+ if crt exec -u node "${managed_exec_env[@]}" "$app_container" \
3519
3603
  /usr/bin/mkdir -p /home/node/.codex >/dev/null; then
3520
3604
  for codex_item in auth.json config.toml AGENTS.md version.json installation_id rules; do
3521
3605
  [ "$uai_on_cloud_credentials" = "1" ] && continue
@@ -3528,22 +3612,18 @@ if crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3528
3612
  brokered_auth="$(mktemp "${TMPDIR:-/tmp}/uai-codex-auth.XXXXXX")"
3529
3613
  if jq 'if (.tokens|type) == "object" and (.tokens.refresh_token|type) == "string" then .tokens.refresh_token = "uai-broker-managed-no-refresh" else . end' \
3530
3614
  "$UAI_OWNER_HOME/.codex/auth.json" > "$brokered_auth" 2>/dev/null && [ -s "$brokered_auth" ]; then
3531
- crt cp "$brokered_auth" "$app_container":/home/node/.codex/auth.json >/dev/null \
3532
- || log "ERROR: crt cp of brokered .codex/auth.json failed; Codex in this task may not authenticate"
3615
+ node_home_put_file "$brokered_auth" /home/node/.codex/auth.json 600 \
3616
+ || log "ERROR: copy of brokered .codex/auth.json failed; Codex in this task may not authenticate"
3533
3617
  rm -f "$brokered_auth"
3534
3618
  continue
3535
3619
  fi
3536
3620
  rm -f "$brokered_auth"
3537
3621
  log "warning: could not broker .codex/auth.json; copying it verbatim"
3538
3622
  fi
3539
- crt cp "$UAI_OWNER_HOME/.codex/$codex_item" \
3540
- "$app_container":/home/node/.codex/ >/dev/null \
3541
- || log "ERROR: crt cp of .codex/$codex_item failed; Codex in this task may not authenticate"
3623
+ node_home_put_tree "$UAI_OWNER_HOME/.codex" /home/node/.codex "$codex_item" \
3624
+ || log "ERROR: copy of .codex/$codex_item failed; Codex in this task may not authenticate"
3542
3625
  fi
3543
3626
  done
3544
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3545
- /usr/bin/chown -R node:node /home/node/.codex >/dev/null \
3546
- || log "ERROR: chown of /home/node/.codex failed — 0600 credentials remain unreadable by node. Fix (docker mode; use the bundled container CLI on Apple hosts): docker exec -u root -e PATH=/usr/bin:/bin $app_container /usr/bin/chown -R node:node /home/node/.codex"
3547
3627
  else
3548
3628
  log "ERROR: mkdir /home/node/.codex failed in $app_container; Codex credentials were not injected"
3549
3629
  fi
@@ -3552,31 +3632,22 @@ fi
3552
3632
  # The Linux `kimi` binary is baked into the image; here we copy ONLY the
3553
3633
  # arch-independent config + credential (never the host's macOS bin/, nor live
3554
3634
  # session state) so the container's kimi runs on the operator's subscription.
3555
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3635
+ crt exec -u node "${managed_exec_env[@]}" "$app_container" \
3556
3636
  /usr/bin/mkdir -p /home/node/.kimi-code/credentials >/dev/null 2>&1 || true
3557
- if [ "$uai_on_cloud_credentials" != "1" ] && [ -e "$UAI_OWNER_HOME/.kimi-code/config.toml" ]; then
3558
- crt cp "$UAI_OWNER_HOME/.kimi-code/config.toml" \
3559
- "$app_container":/home/node/.kimi-code/config.toml >/dev/null 2>&1 \
3560
- || log "warning: crt cp of .kimi-code/config.toml failed; kimi may need re-login"
3561
- fi
3562
- if [ "$uai_on_cloud_credentials" != "1" ] && [ -e "$UAI_OWNER_HOME/.kimi-code/device_id" ]; then
3563
- crt cp "$UAI_OWNER_HOME/.kimi-code/device_id" \
3564
- "$app_container":/home/node/.kimi-code/device_id >/dev/null 2>&1 || true
3565
- fi
3566
- if [ "$uai_on_cloud_credentials" != "1" ] && [ -e "$UAI_OWNER_HOME/.kimi-code/credentials/kimi-code.json" ]; then
3567
- crt cp "$UAI_OWNER_HOME/.kimi-code/credentials/kimi-code.json" \
3568
- "$app_container":/home/node/.kimi-code/credentials/kimi-code.json >/dev/null 2>&1 \
3569
- || log "warning: crt cp of .kimi-code credential failed; kimi may need re-login"
3570
- fi
3571
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3572
- /usr/bin/chown -R node:node /home/node/.kimi-code >/dev/null 2>&1 || true
3637
+ for kimi_item in config.toml device_id credentials/kimi-code.json; do
3638
+ [ "$uai_on_cloud_credentials" = "1" ] && continue
3639
+ if [ -e "$UAI_OWNER_HOME/.kimi-code/$kimi_item" ]; then
3640
+ node_home_put_file "$UAI_OWNER_HOME/.kimi-code/$kimi_item" "/home/node/.kimi-code/$kimi_item" \
3641
+ || log "warning: copy of .kimi-code/$kimi_item failed; kimi may need re-login"
3642
+ fi
3643
+ done
3573
3644
 
3574
3645
  # Copy Grok subscription/config into a task-private /home/node/.grok. The Linux
3575
3646
  # `grok` binary is baked into the image; here we copy the arch-independent
3576
3647
  # auth + config. auth.json is an OIDC token: the task's copy gets the broker
3577
3648
  # placeholder in every entry's refresh_token (ADR-135) so it can never rotate
3578
3649
  # the family; the host is the only refresher.
3579
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3650
+ crt exec -u node "${managed_exec_env[@]}" "$app_container" \
3580
3651
  /usr/bin/mkdir -p /home/node/.grok >/dev/null 2>&1 || true
3581
3652
  for grok_item in auth.json config.toml models_cache.json agent_id; do
3582
3653
  [ "$uai_on_cloud_credentials" = "1" ] && continue
@@ -3585,21 +3656,18 @@ for grok_item in auth.json config.toml models_cache.json agent_id; do
3585
3656
  brokered_auth="$(mktemp "${TMPDIR:-/tmp}/uai-grok-auth.XXXXXX")"
3586
3657
  if jq 'with_entries(if (.value|type) == "object" and (.value.refresh_token|type) == "string" then .value.refresh_token = "uai-broker-managed-no-refresh" else . end)' \
3587
3658
  "$UAI_OWNER_HOME/.grok/auth.json" > "$brokered_auth" 2>/dev/null && [ -s "$brokered_auth" ]; then
3588
- crt cp "$brokered_auth" "$app_container":/home/node/.grok/auth.json >/dev/null 2>&1 \
3589
- || log "warning: crt cp of brokered .grok/auth.json failed; grok may need re-login"
3659
+ node_home_put_file "$brokered_auth" /home/node/.grok/auth.json 600 \
3660
+ || log "warning: copy of brokered .grok/auth.json failed; grok may need re-login"
3590
3661
  rm -f "$brokered_auth"
3591
3662
  continue
3592
3663
  fi
3593
3664
  rm -f "$brokered_auth"
3594
3665
  log "warning: could not broker .grok/auth.json; copying it verbatim"
3595
3666
  fi
3596
- crt cp "$UAI_OWNER_HOME/.grok/$grok_item" \
3597
- "$app_container":/home/node/.grok/ >/dev/null 2>&1 \
3598
- || log "warning: crt cp of .grok/$grok_item failed; grok may need re-login"
3667
+ node_home_put_tree "$UAI_OWNER_HOME/.grok" /home/node/.grok "$grok_item" \
3668
+ || log "warning: copy of .grok/$grok_item failed; grok may need re-login"
3599
3669
  fi
3600
3670
  done
3601
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3602
- /usr/bin/chown -R node:node /home/node/.grok >/dev/null 2>&1 || true
3603
3671
 
3604
3672
  # Copy OpenCode provider auth into a task-private /home/node/.local/share/opencode
3605
3673
  # (ADR-077), same per-task-writable-copy pattern as Codex. The Linux `opencode`
@@ -3610,12 +3678,12 @@ crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3610
3678
  for oc_item in auth.json config.json; do
3611
3679
  [ "$uai_on_cloud_credentials" = "1" ] && continue
3612
3680
  if [ -e "$UAI_OWNER_HOME/.local/share/opencode/$oc_item" ]; then
3613
- crt cp "$UAI_OWNER_HOME/.local/share/opencode/$oc_item" \
3614
- "$app_container":/home/node/.local/share/opencode/ >/dev/null 2>&1 \
3615
- || log "warning: crt cp of opencode/$oc_item failed; opencode may need re-login"
3681
+ node_home_put_file "$UAI_OWNER_HOME/.local/share/opencode/$oc_item" \
3682
+ "/home/node/.local/share/opencode/$oc_item" 600 \
3683
+ || log "warning: copy of opencode/$oc_item failed; opencode may need re-login"
3616
3684
  fi
3617
3685
  done
3618
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3686
+ crt exec -u root "${root_exec_env[@]}" "$app_container" \
3619
3687
  /usr/bin/python3 -I -c "$NODE_STATE_SETUP_SCRIPT" >/dev/null || log "warning: opencode metadata repair failed"
3620
3688
 
3621
3689
  # Copy the resolved SSH identity into the container for commit/tag signing and
@@ -3624,21 +3692,13 @@ crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3624
3692
  # Best-effort: signing + the SSH fallback stay off if the identity is absent —
3625
3693
  # but every failure is LOGGED (a silent miss here reads as a GitHub
3626
3694
  # permissions problem hours later; live 2026-07-21). The channel-ensure path
3627
- # (ensureTaskSshIdentity) re-asserts all of this on reconnects.
3695
+ # (ensureTaskSshIdentity) re-asserts all of this on reconnects. Node writes
3696
+ # both files and sets ~/.ssh to 0700 itself; the key lands 0600.
3628
3697
  if [ -f "$uai_identity_key" ]; then
3629
- crt exec -u root "${managed_exec_env[@]}" "$app_container" \
3630
- /usr/bin/mkdir -p /home/node/.ssh >/dev/null 2>&1 \
3631
- || log "warning: ssh setup: mkdir ~/.ssh failed in $app_container"
3632
- crt cp "$uai_identity_key" \
3633
- "$app_container":/home/node/.ssh/id_ed25519 >/dev/null 2>&1 \
3698
+ node_home_put_file "$uai_identity_key" /home/node/.ssh/id_ed25519 600 700 \
3634
3699
  || log "warning: ssh setup: key copy failed — signing and SSH fallback unavailable"
3635
- crt cp "${uai_identity_key}.pub" \
3636
- "$app_container":/home/node/.ssh/id_ed25519.pub >/dev/null 2>&1 \
3700
+ node_home_put_file "${uai_identity_key}.pub" /home/node/.ssh/id_ed25519.pub "" 700 \
3637
3701
  || log "warning: ssh setup: pubkey copy failed (signing will be off)"
3638
- crt exec -u root "${managed_exec_env[@]}" "$app_container" /bin/sh -c \
3639
- '/usr/bin/chown -R node:node /home/node/.ssh && /usr/bin/chmod 700 /home/node/.ssh && /usr/bin/chmod 600 /home/node/.ssh/id_ed25519' \
3640
- >/dev/null 2>&1 \
3641
- || log "warning: ssh setup: chown/chmod failed — key may be unreadable by node"
3642
3702
  fi
3643
3703
 
3644
3704
  # uai-init (workspace deps + code-server) is re-runnable, and its death must