@task-handoff/node-agent 0.0.33 → 0.0.35

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.
@@ -1,36 +1,75 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- load_private_config() {
5
- local config_path="/run/task-handoff/instance-private-config.json"
6
- if [ ! -f "${config_path}" ]; then
7
- echo "Managed instance private configuration is missing." >&2
8
- exit 78
9
- fi
10
- while IFS=$'\t' read -r key encoded; do
11
- if [[ ! "${key}" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
12
- echo "Managed instance private configuration contains an invalid environment key." >&2
13
- exit 78
4
+ # The private config is mounted as a per-instance directory. The legacy single
5
+ # file path stays readable so containers created by older node agents keep
6
+ # starting after a node-agent upgrade.
7
+ readonly private_config_default_path="/run/task-handoff/private/private-config.json"
8
+ readonly private_config_legacy_path="/run/task-handoff/instance-private-config.json"
9
+
10
+ resolve_private_config_path() {
11
+ local candidate
12
+ for candidate in "${TASK_HANDOFF_INSTANCE_PRIVATE_CONFIG_PATH:-}" "${private_config_default_path}" "${private_config_legacy_path}"; do
13
+ if [ -n "${candidate}" ] && [ -f "${candidate}" ]; then
14
+ printf '%s' "${candidate}"
15
+ return 0
14
16
  fi
15
- local value
16
- value="$(printf '%s' "${encoded}" | base64 --decode)"
17
- export "${key}=${value}"
18
- done < <(node -e '
17
+ done
18
+ return 1
19
+ }
20
+
21
+ # Only the instance identity is required to start. Model environment, catalog,
22
+ # and Codex settings are an optional startup snapshot that the node agent pushes
23
+ # over the authenticated internal API once the instance is registered.
24
+ decode_private_config() {
25
+ node -e '
19
26
  const fs = require("node:fs");
20
27
  const value = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
21
- if (value.version !== 1 || typeof value.instanceCredential !== "string" || !value.instanceCredential || !value.environment || typeof value.environment !== "object" || Array.isArray(value.environment)) process.exit(78);
22
- const environment = { ...value.environment, TASK_HANDOFF_REGISTRATION_TOKEN: value.instanceCredential, TASK_HANDOFF_PRIVATE_CONFIG_LOADED: "1", TASK_HANDOFF_INSTANCE_PRIVATE_CONFIG_PATH: process.argv[1] };
28
+ if (value.version !== 1 || typeof value.instanceId !== "string" || !value.instanceId || typeof value.instanceCredential !== "string" || !value.instanceCredential) process.exit(78);
29
+ const configured = value.environment === undefined ? {} : value.environment;
30
+ if (!configured || typeof configured !== "object" || Array.isArray(configured)) process.exit(78);
31
+ const environment = { ...configured, TASK_HANDOFF_REGISTRATION_TOKEN: value.instanceCredential, TASK_HANDOFF_PRIVATE_CONFIG_LOADED: "1", TASK_HANDOFF_INSTANCE_PRIVATE_CONFIG_PATH: process.argv[1] };
23
32
  if (value.modelCatalog !== undefined) environment.TASK_HANDOFF_PRIVATE_MODEL_CATALOG_JSON = JSON.stringify(value.modelCatalog);
24
33
  if (value.codexSettings !== undefined) environment.TASK_HANDOFF_PRIVATE_CODEX_SETTINGS_JSON = JSON.stringify(value.codexSettings);
25
34
  for (const [key, item] of Object.entries(environment)) {
26
35
  if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key) || typeof item !== "string") process.exit(78);
27
36
  process.stdout.write(`${key}\t${Buffer.from(item).toString("base64")}\n`);
28
37
  }
29
- ' "${config_path}")
30
- if [ "${TASK_HANDOFF_PRIVATE_CONFIG_LOADED:-}" != "1" ]; then
31
- echo "Managed instance private configuration is invalid." >&2
32
- exit 78
33
- fi
38
+ ' "$1"
39
+ }
40
+
41
+ load_private_config() {
42
+ local attempts="${TASK_HANDOFF_PRIVATE_CONFIG_RETRY_ATTEMPTS:-20}"
43
+ local delay_seconds="${TASK_HANDOFF_PRIVATE_CONFIG_RETRY_DELAY_SECONDS:-1}"
44
+ local attempt=1
45
+ local config_path decoded key encoded value
46
+ while :; do
47
+ if config_path="$(resolve_private_config_path)" && decoded="$(decode_private_config "${config_path}")"; then
48
+ while IFS=$'\t' read -r key encoded; do
49
+ if [ -z "${key}" ]; then
50
+ continue
51
+ fi
52
+ if [[ ! "${key}" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
53
+ echo "Managed instance private configuration contains an invalid environment key." >&2
54
+ exit 78
55
+ fi
56
+ value="$(printf '%s' "${encoded}" | base64 --decode)"
57
+ export "${key}=${value}"
58
+ done <<< "${decoded}"
59
+ if [ "${TASK_HANDOFF_PRIVATE_CONFIG_LOADED:-}" = "1" ]; then
60
+ return 0
61
+ fi
62
+ echo "Managed instance private configuration could not be applied." >&2
63
+ exit 78
64
+ fi
65
+ if [ "${attempt}" -ge "${attempts}" ]; then
66
+ break
67
+ fi
68
+ attempt=$((attempt + 1))
69
+ sleep "${delay_seconds}"
70
+ done
71
+ echo "Managed instance private configuration is missing or invalid after ${attempts} attempts." >&2
72
+ exit 78
34
73
  }
35
74
 
36
75
  start_node_agent_unix_proxy() {
@@ -78,8 +117,15 @@ bootstrap_workspace() {
78
117
  fi
79
118
  local workspace="${TASK_HANDOFF_WORKSPACE:-/workspace}"
80
119
  local mode="${TASK_HANDOFF_WORKSPACE_MODE:-}"
81
- local git_url="${TASK_HANDOFF_GIT_URL:-}"
82
- local git_ref="${TASK_HANDOFF_GIT_REF:-}"
120
+ # Workspace Git environment contract (mirrors @task-handoff/protocol/workspace-git).
121
+ # This script is mounted by the node agent that writes the environment, so the
122
+ # workspace keys are the only input. The legacy keys are never read: images
123
+ # bake TASK_HANDOFF_GIT_COMMIT as their build commit and docker run exposes
124
+ # image environment here.
125
+ local git_url="${TASK_HANDOFF_WORKSPACE_GIT_URL:-}"
126
+ local git_ref="${TASK_HANDOFF_WORKSPACE_GIT_REF:-}"
127
+ local git_depth="${TASK_HANDOFF_WORKSPACE_GIT_DEPTH:-}"
128
+ local git_submodules="${TASK_HANDOFF_WORKSPACE_GIT_SUBMODULES:-false}"
83
129
 
84
130
  if [ "${mode}" != "git-clone" ] || [ -z "${git_url}" ]; then
85
131
  return
@@ -97,10 +143,10 @@ bootstrap_workspace() {
97
143
  fi
98
144
 
99
145
  local clone_args=(clone)
100
- if [ -n "${TASK_HANDOFF_GIT_DEPTH:-}" ]; then
101
- clone_args+=(--depth "${TASK_HANDOFF_GIT_DEPTH}")
146
+ if [ -n "${git_depth}" ]; then
147
+ clone_args+=(--depth "${git_depth}")
102
148
  fi
103
- if [ "${TASK_HANDOFF_GIT_SUBMODULES:-false}" = "true" ]; then
149
+ if [ "${git_submodules}" = "true" ]; then
104
150
  clone_args+=(--recurse-submodules)
105
151
  fi
106
152
  if [ -n "${git_ref}" ]; then
@@ -111,8 +157,8 @@ bootstrap_workspace() {
111
157
  echo "Cloning workspace ${git_url} into ${workspace}."
112
158
  git "${clone_args[@]}"
113
159
 
114
- if [ -n "${TASK_HANDOFF_GIT_COMMIT:-}" ]; then
115
- git -C "${workspace}" checkout "${TASK_HANDOFF_GIT_COMMIT}"
160
+ if [ -n "${TASK_HANDOFF_WORKSPACE_GIT_COMMIT:-}" ]; then
161
+ git -C "${workspace}" checkout "${TASK_HANDOFF_WORKSPACE_GIT_COMMIT}"
116
162
  fi
117
163
  }
118
164
 
@@ -82,11 +82,15 @@ git_config=(
82
82
  -c credential.useHttpPath=true
83
83
  -c core.sshCommand="node /run/task-handoff/bootstrap/git-provisioning-helper.js ssh"
84
84
  )
85
+ # Workspace Git environment contract (mirrors @task-handoff/protocol/workspace-git).
86
+ # Only the TASK_HANDOFF_WORKSPACE_GIT_* keys are provisioning input: released
87
+ # images bake TASK_HANDOFF_GIT_COMMIT as the image build commit and docker run
88
+ # exposes image environment here, so the legacy keys must never be read.
85
89
  clone_args=(clone)
86
90
  # A commit SHA is not guaranteed to be reachable from a shallow default-branch clone.
87
- if [ -n "${TASK_HANDOFF_GIT_DEPTH:-}" ] && [ -z "${TASK_HANDOFF_GIT_COMMIT:-}" ]; then clone_args+=(--depth "${TASK_HANDOFF_GIT_DEPTH}"); fi
88
- if [ -n "${TASK_HANDOFF_GIT_REF:-}" ]; then clone_args+=(--branch "${TASK_HANDOFF_GIT_REF}"); fi
89
- clone_args+=(-- "${TASK_HANDOFF_GIT_URL}" "${checkout}")
91
+ if [ -n "${TASK_HANDOFF_WORKSPACE_GIT_DEPTH:-}" ] && [ -z "${TASK_HANDOFF_WORKSPACE_GIT_COMMIT:-}" ]; then clone_args+=(--depth "${TASK_HANDOFF_WORKSPACE_GIT_DEPTH}"); fi
92
+ if [ -n "${TASK_HANDOFF_WORKSPACE_GIT_REF:-}" ]; then clone_args+=(--branch "${TASK_HANDOFF_WORKSPACE_GIT_REF}"); fi
93
+ clone_args+=(-- "${TASK_HANDOFF_WORKSPACE_GIT_URL}" "${checkout}")
90
94
 
91
95
  mkdir -p /tmp/task-handoff-git-home
92
96
  chown 1000:1000 /tmp/task-handoff-git-home
@@ -99,12 +103,12 @@ if ! runuser -u agent -- env \
99
103
  fail CLONE_FAILED 74
100
104
  fi
101
105
 
102
- if [ -n "${TASK_HANDOFF_GIT_COMMIT:-}" ]; then
103
- if ! runuser -u agent -- git -C "${checkout}" checkout --detach "${TASK_HANDOFF_GIT_COMMIT}"; then
106
+ if [ -n "${TASK_HANDOFF_WORKSPACE_GIT_COMMIT:-}" ]; then
107
+ if ! runuser -u agent -- git -C "${checkout}" checkout --detach "${TASK_HANDOFF_WORKSPACE_GIT_COMMIT}"; then
104
108
  fail REF_NOT_FOUND 75
105
109
  fi
106
110
  fi
107
- if [ "${TASK_HANDOFF_GIT_SUBMODULES:-false}" = "true" ]; then
111
+ if [ "${TASK_HANDOFF_WORKSPACE_GIT_SUBMODULES:-false}" = "true" ]; then
108
112
  if ! runuser -u agent -- env \
109
113
  HOME=/tmp/task-handoff-git-home \
110
114
  GIT_TERMINAL_PROMPT=0 \
@@ -113,7 +117,7 @@ if [ "${TASK_HANDOFF_GIT_SUBMODULES:-false}" = "true" ]; then
113
117
  fail CLONE_FAILED 74
114
118
  fi
115
119
  fi
116
- if [ "${TASK_HANDOFF_GIT_LFS:-false}" = "true" ]; then
120
+ if [ "${TASK_HANDOFF_WORKSPACE_GIT_LFS:-false}" = "true" ]; then
117
121
  if ! runuser -u agent -- env GIT_TERMINAL_PROMPT=0 GIT_SSH_COMMAND="node /run/task-handoff/bootstrap/git-provisioning-helper.js ssh" git "${git_config[@]}" -C "${checkout}" lfs pull; then
118
122
  fail LFS_FAILED 76
119
123
  fi
@@ -24,6 +24,10 @@ if [ ! -L "${current}" ]; then
24
24
  bootstrap_wait
25
25
  fi
26
26
 
27
+ # The launcher can be restarted by a process whose cwd belongs to the previous
28
+ # release. Keep this process and every child on a directory that survives release cleanup.
29
+ cd -- "${runtime_root}"
30
+
27
31
  exec node --input-type=module - "${current}" <<'NODE'
28
32
  import fs from "node:fs";
29
33
  import path from "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@task-handoff/node-agent",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "Prebuilt TaskHandoff node agent runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "commonjs",
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "packageName": "@task-handoff/controlled-instance",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "platform": "linux",
5
5
  "arch": "universal",
6
6
  "formatVersion": 1,
7
7
  "launcherAbi": 1,
8
8
  "entrypoint": "dist/controlled-instance-cli.js",
9
- "sha256": "433e6ee69d3e4b7dd14891386fc5915453aef8f043be1000c77be9eafea85d6a"
9
+ "sha256": "69490fa98a252c90193a3ddc283e222cecee49e70937c8e61b170c53fcaa1e8d"
10
10
  }
@@ -0,0 +1 @@
1
+ 42b280947d5bfbe852efac6b534343146af36c01bc09f64344e13fadeb5846b1 controlled-instance-runtime-0.0.35-linux-universal.tar.gz
@@ -1 +0,0 @@
1
- a10033fa7c4e158f25cf2377682ba302a33839a45f6aaf15a596a09eaeb85d05 controlled-instance-runtime-0.0.33-linux-universal.tar.gz