Skip to content
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
420f96b
fix(messaging): bind OpenClaw WeChat credentials
prekshivyas Aug 29, 2026
2294f33
fix(messaging): refresh sealed WeChat credentials
prekshivyas Aug 29, 2026
57a6c47
Merge branch 'main' into codex/fix-10079-openclaw-wechat-binding
prekshivyas Aug 29, 2026
c6bcc2a
fix(messaging): detect active WeChat accounts
prekshivyas Aug 29, 2026
1f9b57c
fix(messaging): preflight WeChat placeholder refresh
prekshivyas Aug 29, 2026
d0d8334
refactor(messaging): simplify WeChat refresh dispatch
prekshivyas Aug 29, 2026
66429a7
fix(messaging): order WeChat refresh before config writes
prekshivyas Aug 29, 2026
9ac6b97
test(messaging): prove WeChat runtime credential binding
prekshivyas Aug 29, 2026
ece29d1
merge(main): refresh PR validation base
prekshivyas Aug 29, 2026
89d5814
docs(messaging): clarify WeChat placeholder invariant
prekshivyas Aug 29, 2026
c827152
test(e2e): register WeChat runtime proof helpers
prekshivyas Aug 29, 2026
f9918d3
fix(messaging): clear OpenClaw WeChat account state
prekshivyas Aug 29, 2026
0b63a1d
fix(messaging): fail closed on WeChat removal
prekshivyas Aug 29, 2026
a6804dc
test(messaging): execute WeChat refresh boundary
prekshivyas Aug 29, 2026
043dd5a
test(e2e): remove WeChat source-shape assertion
prekshivyas Aug 29, 2026
0756a17
fix(messaging): recover failed WeChat removal
prekshivyas Aug 29, 2026
0f3bf90
fix(messaging): verify offline WeChat state mount
prekshivyas Aug 29, 2026
c95da08
fix(messaging): isolate offline WeChat volume
prekshivyas Aug 29, 2026
4a8b1d9
merge(main): refresh PR validation base
prekshivyas Aug 29, 2026
38efd25
test(messaging): stage WeChat refresh helper
prekshivyas Aug 30, 2026
633f3a1
merge(main): refresh PR validation base
prekshivyas Aug 30, 2026
66bfee3
fix(messaging): tighten WeChat lifecycle boundaries
prekshivyas Aug 30, 2026
11aeecf
test(messaging): pin WeChat cleanup paths
prekshivyas Aug 30, 2026
6c03dc3
refactor(messaging): centralize WeChat cleanup paths
prekshivyas Aug 30, 2026
60307cd
fix(messaging): diagnose stopped WeChat cleanup
prekshivyas Aug 30, 2026
57a2131
refactor(sandbox): invert channel cleanup dependency
prekshivyas Aug 30, 2026
46ffead
test(e2e): route WeChat fixture changes
prekshivyas Aug 30, 2026
38899ef
refactor(messaging): own WeChat cleanup state in manifest
prekshivyas Aug 30, 2026
9f88d07
merge(main): refresh PR validation base
prekshivyas Aug 30, 2026
cfaa17c
chore(runtime): refresh managed startup bundle
prekshivyas Aug 30, 2026
66d8c0f
fix(messaging): gate channel state cleanup by agent
prekshivyas Aug 30, 2026
4412ad9
test(messaging): remove source-shape import assertion
prekshivyas Aug 30, 2026
8595b03
fix(messaging): harden runtime credential refresh
prekshivyas Aug 30, 2026
377778f
merge(main): refresh PR validation base
prekshivyas Aug 30, 2026
0f02e4f
test(runtime): refresh reviewed bundle digest
prekshivyas Aug 30, 2026
fd43fdd
test(messaging): use Hermes credential boundary
prekshivyas Aug 30, 2026
398168b
docs(messaging): clarify stopped cleanup condition
prekshivyas Aug 30, 2026
425c003
test(e2e): bind Google Chat fixture at channel boundary
prekshivyas Aug 30, 2026
6adf351
test(e2e): cover Google Chat rebuild provider boundary
prekshivyas Aug 30, 2026
8dfe6f1
test(e2e): bind Google Chat fixture to startup registration
prekshivyas Aug 30, 2026
a3da32d
test(e2e): unify Google Chat startup boundary
prekshivyas Aug 30, 2026
c41151e
test(e2e): use named Google Chat fixture imports
prekshivyas Aug 30, 2026
6db670e
test(e2e): bind rebuild to Google Chat fixture
prekshivyas Aug 30, 2026
c66efc5
test(e2e): keep messaging fixtures behavior-focused
prekshivyas Aug 30, 2026
d49ed2a
test(cli): move onboarding import outside timeout
prekshivyas Aug 30, 2026
55f9bd7
merge(main): refresh PR validation base
prekshivyas Aug 30, 2026
aeeae73
docs(onboard): clarify policy sync fallback
prekshivyas Aug 30, 2026
47488fa
merge: resolve conflicts with main
github-actions[bot] Aug 30, 2026
07a5b9e
fix(wechat): harden runtime credential cleanup
senthilr-nv Aug 31, 2026
65cbc28
chore(runtime): refresh reviewed startup bundle
senthilr-nv Aug 31, 2026
6dd9805
fix(wechat): clarify cleanup recovery
senthilr-nv Aug 31, 2026
86a7a80
test(runtime): use explicit cleanup image oracle
senthilr-nv Aug 31, 2026
2825fbb
fix(wechat): improve cleanup recovery guidance
senthilr-nv Aug 31, 2026
d26ac5e
docs(wechat): explain stopped cleanup recovery
senthilr-nv Aug 31, 2026
653f269
fix(installer): admit wechat preload files
senthilr-nv Aug 31, 2026
9f6cc4c
fix(wechat): roll back partial account refresh
senthilr-nv Aug 31, 2026
58d904d
docs(wechat): qualify stopped cleanup fallback
senthilr-nv Aug 31, 2026
c3b5f1c
fix(wechat): narrow refresh abort handling
senthilr-nv Aug 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@
COPY scripts/lib/openclaw_device_approval_policy.py /usr/local/lib/nemoclaw/openclaw_device_approval_policy.py
COPY scripts/lib/clean_runtime_shell_env_shim.py /usr/local/lib/nemoclaw/clean_runtime_shell_env_shim.py
COPY scripts/lib/normalize_mutable_config_perms.py /usr/local/lib/nemoclaw/normalize_mutable_config_perms.py
COPY scripts/lib/refresh-openclaw-wechat-placeholder.py /usr/local/lib/nemoclaw/refresh-openclaw-wechat-placeholder.py
COPY scripts/state-dir-guard.py /usr/local/lib/nemoclaw/state-dir-guard.py
COPY agents/openclaw/state-lock-plan.json /usr/local/share/nemoclaw/state-lock-plan.json
COPY scripts/openclaw-config-guard.py /usr/local/lib/nemoclaw/openclaw-config-guard.py
Expand Down Expand Up @@ -1584,10 +1585,10 @@
# CHAT_UI_URL is a non-loopback address (Brev Launchable, remote deployments)
# since terminal-based pairing is impossible in those contexts.
# Default: "0" (device auth enabled for local deployments — secure by default).
ARG NEMOCLAW_DISABLE_DEVICE_AUTH=0

Check warning on line 1588 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "NEMOCLAW_DISABLE_DEVICE_AUTH") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 1588 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "NEMOCLAW_DISABLE_DEVICE_AUTH") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
# Internal audit provenance for the opt-out above. Standard onboarding rewrites
# this to managed-onboard; direct image builders retain operator provenance.
ARG NEMOCLAW_DEVICE_AUTH_OPT_OUT_SOURCE=operator

Check warning on line 1591 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "NEMOCLAW_DEVICE_AUTH_OPT_OUT_SOURCE") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 1591 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "NEMOCLAW_DEVICE_AUTH_OPT_OUT_SOURCE") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
# Compatibility build arg for older custom Dockerfiles and rebuild tooling.
# NemoClaw-managed images intentionally do not consume it; gateway auth tokens
# are generated at container startup and are never baked into image layers.
Expand Down Expand Up @@ -1621,7 +1622,7 @@
# NEMOCLAW_MESSAGING_PLAN_B64 intentionally remains ARG-only: Docker exposes it
# to build RUN processes without retaining the full plan in the final image env.
# Direct ARG interpolation into inline source is a code injection vector (C-2).
ENV NEMOCLAW_MODEL=${NEMOCLAW_MODEL} \

Check warning on line 1625 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "NEMOCLAW_DEVICE_AUTH_OPT_OUT_SOURCE") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 1625 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "NEMOCLAW_DISABLE_DEVICE_AUTH") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 1625 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "NEMOCLAW_DEVICE_AUTH_OPT_OUT_SOURCE") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 1625 in Dockerfile

View workflow job for this annotation

GitHub Actions / PR build and direct managed startup (OpenClaw)

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "NEMOCLAW_DISABLE_DEVICE_AUTH") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/
NEMOCLAW_INFERENCE_PROVIDER_ID=${NEMOCLAW_INFERENCE_PROVIDER_ID} \
NEMOCLAW_UPSTREAM_PROVIDER=${NEMOCLAW_UPSTREAM_PROVIDER} \
NEMOCLAW_PRIMARY_MODEL_REF=${NEMOCLAW_PRIMARY_MODEL_REF} \
Expand Down
266 changes: 266 additions & 0 deletions scripts/lib/refresh-openclaw-wechat-placeholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import json
import os
import re
import secrets
import stat
import sys

config_file = os.path.abspath(sys.argv[1])
openclaw_dir = os.path.dirname(config_file)
env_key = "WECHAT_BOT_TOKEN"
canonical = f"openshell:resolve:env:{env_key}"
scoped_re = re.compile(rf"^openshell:resolve:env:v[0-9]+_{env_key}$")


def fail(message):
print(f"[SECURITY] Refusing WeChat provider placeholder refresh — {message}", file=sys.stderr)
raise SystemExit(1)


def safe_account_id(value):
return (
isinstance(value, str)
and value
and value == value.strip()
and value not in {".", ".."}
and ".." not in value
and "/" not in value
and "\\" not in value
and not any(ord(char) < 32 or ord(char) == 127 for char in value)
)


def temporary_owner_pid(candidate, filename):
prefix = f".{filename}.nemoclaw-"
suffix = ".tmp"
if not candidate.startswith(prefix) or not candidate.endswith(suffix):
return None
identity = candidate[len(prefix) : -len(suffix)]
match = re.fullmatch(r"([1-9][0-9]*)-([0-9a-f]{16})", identity)
if match is None:
return None
pid = int(match.group(1))
return pid if pid <= 2147483647 else None


def process_is_running(pid):
if pid == os.getpid():
return True
try:
os.kill(pid, 0)
except ProcessLookupError:
return False
except OSError:
return True
return True


def cleanup_stale_temporaries(accounts_fd, filename, account_metadata):
try:
directory_metadata = os.fstat(accounts_fd)
except OSError:
fail("the managed account directory cannot be validated")
if (
not stat.S_ISDIR(directory_metadata.st_mode)
or stat.S_IMODE(directory_metadata.st_mode) & 0o002
or directory_metadata.st_uid not in {account_metadata.st_uid, os.geteuid()}
):
fail("the managed account directory is unsafe for temporary-file cleanup")
try:
candidates = os.listdir(accounts_fd)
except OSError:
fail("the managed account directory cannot be checked for stale temporary files")
cleaned = False
for candidate in candidates:
owner_pid = temporary_owner_pid(candidate, filename)
if owner_pid is None or process_is_running(owner_pid):
continue
try:
metadata = os.stat(candidate, dir_fd=accounts_fd, follow_symlinks=False)
except FileNotFoundError:
continue
except OSError:
fail("a stale managed account temporary file is unreadable")
if (
not stat.S_ISREG(metadata.st_mode)
or metadata.st_nlink != 1
or stat.S_IMODE(metadata.st_mode) != 0o600
or metadata.st_uid != account_metadata.st_uid
or metadata.st_gid != account_metadata.st_gid
):
fail("a stale managed account temporary file is unsafe")
try:
os.unlink(candidate, dir_fd=accounts_fd)
except FileNotFoundError:
continue
except OSError:
fail(
"a stale managed account temporary file could not be removed; "
"restore owner write access to the managed account directory and retry startup"
)
cleaned = True
if cleaned:
try:
os.fsync(accounts_fd)
except OSError:
fail("the managed account directory could not persist temporary-file cleanup")


if not hasattr(os, "O_NOFOLLOW") or not hasattr(os, "O_DIRECTORY"):
fail("the platform cannot enforce no-follow account traversal")

close_on_exec = getattr(os, "O_CLOEXEC", 0)
directory_flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | close_on_exec
file_flags = os.O_RDONLY | os.O_NOFOLLOW | close_on_exec

root_fd = -1
plugin_fd = -1
accounts_fd = -1
try:
try:
root_fd = os.open(openclaw_dir, directory_flags)
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
config_fd = os.open("openclaw.json", file_flags, dir_fd=root_fd)
try:
config_metadata = os.fstat(config_fd)
if not stat.S_ISREG(config_metadata.st_mode) or config_metadata.st_nlink != 1:
fail("openclaw.json is not a single regular file")
with os.fdopen(config_fd, "r", encoding="utf-8") as stream:
config_fd = -1
config = json.load(stream)
finally:
if config_fd >= 0:
os.close(config_fd)
except (OSError, ValueError, json.JSONDecodeError):
fail("openclaw.json is unreadable or unsafe")

channels = config.get("channels") if isinstance(config, dict) else None
channel = channels.get("openclaw-weixin") if isinstance(channels, dict) else None
if not isinstance(channel, dict) or channel.get("enabled") is False:
raise SystemExit(0)

accounts = channel.get("accounts")
if not isinstance(accounts, dict):
raise SystemExit(0)

account_ids = []
for account_id, account in accounts.items():
if not isinstance(account, dict) or account.get("enabled") is False:
continue
if not safe_account_id(account_id):
fail("active WeChat configuration contains an unsafe account id")
account_ids.append(account_id)

if not account_ids:
raise SystemExit(0)

runtime_placeholder = os.environ.get(env_key, "")
if not scoped_re.fullmatch(runtime_placeholder):
if not runtime_placeholder:
fail(f"{env_key} is missing from the runtime environment")
if not runtime_placeholder.startswith("openshell:resolve:env:"):
fail(f"{env_key} is not an OpenShell placeholder; raw credentials stay out of account files")
fail(f"{env_key} is not the required revision-scoped OpenShell placeholder")

try:
plugin_fd = os.open("openclaw-weixin", directory_flags, dir_fd=root_fd)
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
accounts_fd = os.open("accounts", directory_flags, dir_fd=plugin_fd)
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
except OSError:
fail("the managed account directory is missing or unsafe")

pending = []
for account_id in sorted(account_ids):
filename = f"{account_id}.json"
try:
account_fd = os.open(filename, file_flags, dir_fd=accounts_fd)
except OSError:
fail("a managed account file is missing or unsafe")
try:
metadata = os.fstat(account_fd)
if not stat.S_ISREG(metadata.st_mode) or metadata.st_nlink != 1:
fail("a managed account file is not a single regular file")
if stat.S_IMODE(metadata.st_mode) & 0o077:
Comment thread
senthilr-nv marked this conversation as resolved.
Resolved
fail("a managed account file is accessible outside its owner")
cleanup_stale_temporaries(accounts_fd, filename, metadata)
try:
with os.fdopen(os.dup(account_fd), "r", encoding="utf-8") as stream:
account_data = json.load(stream)
except Exception:
fail("a managed account file is unreadable")
finally:
os.close(account_fd)

if not isinstance(account_data, dict) or not isinstance(account_data.get("token"), str):
fail("a managed account file has no valid token field")
current = account_data["token"]
if current == runtime_placeholder:
continue
if current != canonical and not scoped_re.fullmatch(current):
fail("a managed account token is neither canonical nor revision-scoped")
account_data["token"] = runtime_placeholder
payload = (json.dumps(account_data, ensure_ascii=False, indent=2) + "\n").encode("utf-8")
pending.append((filename, metadata, payload))

for filename, metadata, payload in pending:
temporary = f".{filename}.nemoclaw-{os.getpid()}-{secrets.token_hex(8)}.tmp"
temporary_created = False
try:
create_flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW
temporary_fd = os.open(temporary, create_flags, 0o600, dir_fd=accounts_fd)
temporary_created = True
try:
os.fchmod(temporary_fd, 0o600)
if os.geteuid() == 0:
os.fchown(temporary_fd, metadata.st_uid, metadata.st_gid)
offset = 0
while offset < len(payload):
offset += os.write(temporary_fd, payload[offset:])
os.fsync(temporary_fd)
finally:
os.close(temporary_fd)

current_metadata = os.stat(filename, dir_fd=accounts_fd, follow_symlinks=False)
before = (metadata.st_dev, metadata.st_ino, metadata.st_mtime_ns, metadata.st_size)
after = (
current_metadata.st_dev,
current_metadata.st_ino,
current_metadata.st_mtime_ns,
current_metadata.st_size,
)
if before != after or current_metadata.st_nlink != 1:
fail("a managed account file changed during refresh")
os.replace(
temporary,
filename,
src_dir_fd=accounts_fd,
dst_dir_fd=accounts_fd,
)
temporary_created = False
os.fsync(accounts_fd)
finally:
if temporary_created:
try:
os.unlink(temporary, dir_fd=accounts_fd)
except OSError:
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
print(
"[SECURITY] WeChat provider placeholder refresh could not remove its "
"temporary account file; restore owner write access to the managed "
"account directory and retry startup",
file=sys.stderr,
)

if pending:
print(
f"[config] Refreshed WeChat account provider placeholder from OpenShell runtime env: {env_key}",
file=sys.stderr,
)
finally:
if accounts_fd >= 0:
os.close(accounts_fd)
if plugin_fd >= 0:
os.close(plugin_fd)
if root_fd >= 0:
os.close(root_fd)
60 changes: 49 additions & 11 deletions scripts/nemoclaw-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1535,16 +1535,35 @@ PYCORS

# OpenShell provider snapshots can expose revision-scoped placeholders such as
# openshell:resolve:env:v11_<ENV_KEY> in the child environment. Refresh
# baked canonical placeholders in openclaw.json after the integrity check so
# token egress keeps working across provider attach/refresh generations without
# ever writing a raw credential to disk.
# baked canonical placeholders after the integrity check so token egress keeps
# working across provider attach/refresh generations without ever writing a raw
# credential to disk.
refresh_openclaw_wechat_account_placeholder() {
Comment thread
senthilr-nv marked this conversation as resolved.
Resolved
local config_file="/sandbox/.openclaw/openclaw.json"
[ -f "$config_file" ] || return 0

# The Tencent WeChat plugin reads its credential from a separate account file.
# Store the revision-scoped OpenShell placeholder in that file through
# descriptor-relative, no-follow operations. Do not write the raw bot token
# to disk.
local helper="/usr/local/lib/nemoclaw/refresh-openclaw-wechat-placeholder.py"
if [ ! -f "$helper" ]; then
helper="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib/refresh-openclaw-wechat-placeholder.py"
fi
python3 -I "$helper" "$config_file"
}

refresh_openclaw_provider_placeholders() {
local config_file="/sandbox/.openclaw/openclaw.json"
local hash_file="/sandbox/.openclaw/.config-hash"
[ -f "$config_file" ] || return 0

# Refresh the separate WeChat account registry before generic provider files
# so an invalid placeholder or unsafe account leaves those files unchanged.
refresh_openclaw_wechat_account_placeholder || return $?

if [ "$(openclaw_config_dir_owner "$(dirname "$config_file")")" = "root" ]; then
printf '[config] Shields are up; preserving sealed provider placeholders unchanged\n' >&2
printf '[config] Shields are up; preserving sealed openclaw.json provider placeholders unchanged\n' >&2
return 0
fi

Expand Down Expand Up @@ -1874,6 +1893,7 @@ PYPLACEHOLDERS

restore_openclaw_config_after_write "$config_file" "$hash_file"
[ "$_write_rc" -eq 0 ] || return "$_write_rc"
return 0
}

# ── Messaging runtime setup from manifest metadata ───────────────
Expand Down Expand Up @@ -1961,15 +1981,31 @@ def clean_env_alias(entry, index):
env_key = clean_string(entry.get("envKey"), f"envAliases[{index}].envKey")
if not ENV_KEY_RE.match(env_key):
fail(f"envAliases[{index}].envKey is not a safe environment key")
target_env_key = entry.get("targetEnvKey")
if target_env_key is None:
target_env_key = env_key
else:
target_env_key = clean_string(target_env_key, f"envAliases[{index}].targetEnvKey")
if not ENV_KEY_RE.match(target_env_key):
fail(f"envAliases[{index}].targetEnvKey is not a safe environment key")
if target_env_key == env_key:
fail(f"envAliases[{index}].targetEnvKey must differ from envKey")
pattern = clean_string(entry.get("match"), f"envAliases[{index}].match")
try:
re.compile(pattern)
except re.error as exc:
fail(f"envAliases[{index}].match is not a valid regex: {exc}")
value = clean_string(entry.get("value"), f"envAliases[{index}].value", allow_empty=True)
if target_env_key != env_key:
if pattern != f"^openshell:resolve:env:v[0-9]+_{env_key}$":
fail(f"envAliases[{index}] cross-key match is not revision-scoped")
if value != f"openshell:resolve:env:{env_key}":
fail(f"envAliases[{index}] cross-key value is not the canonical source placeholder")
return {
"envKey": env_key,
"targetEnvKey": target_env_key,
"match": pattern,
"value": clean_string(entry.get("value"), f"envAliases[{index}].value", allow_empty=True),
"value": value,
"message": clean_message(entry.get("message"), f"envAliases[{index}].message"),
}

Expand Down Expand Up @@ -2072,7 +2108,7 @@ for entry in runtime_setup_entries("nodePreloads"):
node_preloads.append(preload)
for entry in runtime_setup_entries("envAliases"):
alias = clean_env_alias(entry, len(env_aliases))
alias_key = (alias["envKey"], alias["match"], alias["value"])
alias_key = (alias["envKey"], alias["targetEnvKey"], alias["match"], alias["value"])
if alias_key not in seen_aliases:
seen_aliases.add(alias_key)
env_aliases.append(alias)
Expand Down Expand Up @@ -2103,18 +2139,20 @@ for alias in plan.get("envAliases", []):
if not re.search(alias["match"], os.environ.get(alias["envKey"], "")):
continue
print("\t".join([
alias["envKey"],
alias.get("targetEnvKey", alias["envKey"]),
alias["value"],
alias.get("message", ""),
]))
PYMESSAGINGALIASES
)" || return $?
[ -n "$_rows" ] || return 0

local _env_key _value _message
while IFS=$'\t' read -r _env_key _value _message; do
export "$_env_key=$_value"
[ -n "$_message" ] && printf '%s\n' "$_message" >&2
local _target_env_key _value _message
while IFS=$'\t' read -r _target_env_key _value _message; do
export "$_target_env_key=$_value"
if [ -n "$_message" ]; then
printf '%s\n' "$_message" >&2
fi
done <<<"$_rows"
}

Expand Down
Loading
Loading