Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(config): 企业版配置目录迁移至 /app/config,config.yaml 弃用 configmap 改为启动时生成

chen huid42837a1ae1a
diff --git a/deploy/enterprise/.env.example b/deploy/enterprise/.env.example
index 2aa8bdbb99..6b6aef0499 100644
--- a/deploy/enterprise/.env.example
+++ b/deploy/enterprise/.env.example
@@ -240,7 +240,7 @@ GATEWAY_CLAW_WS_PING_TIMEOUT="20.0" # WebSocket 心跳无响应超时阈值
JIUWENSWARM_REQUEST_EXT_FORWARD_HEADERS=""
# SessionMap 会话映射策略
-# 仅适用于企业版 Claw 场景(如 feishu_enterprise 等企业通道)
+# 仅适用于企业版 Claw 场景
# 作用:将平台用户身份映射为 Agent 内部会话唯一标识(session_id)
# 可选值:
# per_chat_bot - 默认值,同一聊天窗口+机器人共享会话
@@ -386,6 +386,10 @@ AGENT_RUNTIME_IMAGE=""
# Agent Runtime 副本实例数量,控制部署运行的 Pod 个数
AGENT_RUNTIME_REPLICAS=1
+# Agent Runtime 监听 AgentServer Pod 事件的轮询间隔(秒),默认 10。
+# 值越小感知变更越快,但 CPU/etcd 轮询开销越高。
+AGENT_RUNTIME_WATCH_INTERVAL=10
+
# Agent Runtime 服务的容器最小保证 CPU:500毫核(0.5核),K8s 必须至少分配这么多 CPU 才能启动
RUNTIME_CPU_REQUEST=500m
diff --git a/deploy/enterprise/check_handler.sh b/deploy/enterprise/check_handler.sh
index 581790339b..dc343e4558 100755
--- a/deploy/enterprise/check_handler.sh
+++ b/deploy/enterprise/check_handler.sh
@@ -352,67 +352,24 @@ check_nfs_sc_up_dependency(){
}
check_mysql_up_dependency(){
- local mysql_path="${DEPLOY_VARS["NFS_POD_PATH"]}/${DEPLOY_VARS["MYSQL_NAME"]}"
- local nfs_dname=${DEPLOY_VARS["NFS_NAME"]}
-
- check_if_nfs_up
-
- if [ "${DEPLOY_VARS["RENDER_ONLY"]}" == "true" ]; then
- return
- fi
-
- if [ "${DEPLOY_VARS["ENABLE_EXTERNAL_NFS"]}" == "false" ]; then
- info "Preparing MySQL data directory: ${mysql_path}"
- local nfs_pod=$(kubectl get pods -n default -l app=${nfs_dname} -o jsonpath='{.items[0].metadata.name}')
-
- info "Executing: kubectl exec ${nfs_pod} -- sh -c \"mkdir -p ${mysql_path}\""
- kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${mysql_path}"
- success "MySQL directory created successfully in NFS Pod!"
- fi
+ prepare_nfs_path "${DEPLOY_VARS["MYSQL_NAME"]}"
}
check_postgresql_up_dependency(){
- local pg_path="${DEPLOY_VARS["NFS_POD_PATH"]}/${DEPLOY_VARS["POSTGRESQL_NAME"]}"
- local nfs_dname=${DEPLOY_VARS["NFS_NAME"]}
-
- check_if_nfs_up
-
- if [ "${DEPLOY_VARS["RENDER_ONLY"]}" == "true" ]; then
- return
- fi
-
- if [ "${DEPLOY_VARS["ENABLE_EXTERNAL_NFS"]}" == "false" ]; then
- info "Preparing PostgreSQL data directory: ${pg_path}"
- local nfs_pod=$(kubectl get pods -n default -l app=${nfs_dname} -o jsonpath='{.items[0].metadata.name}')
-
- info "Executing: kubectl exec ${nfs_pod} -- sh -c \"mkdir -p ${pg_path}\""
- kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${pg_path}"
- success "PostgreSQL directory created successfully in NFS Pod!"
- fi
+ prepare_nfs_path "${DEPLOY_VARS["POSTGRESQL_NAME"]}"
}
check_minio_up_dependency(){
- local minio_path="${DEPLOY_VARS["NFS_POD_PATH"]}/${DEPLOY_VARS["MINIO_NAME"]}"
- local nfs_dname=${DEPLOY_VARS["NFS_NAME"]}
-
- check_if_nfs_up
-
- if [ "${DEPLOY_VARS["RENDER_ONLY"]}" == "true" ]; then
- return
- fi
-
- if [ "${DEPLOY_VARS["ENABLE_EXTERNAL_NFS"]}" == "false" ]; then
- info "Preparing Minio data directory: ${minio_path}"
- local nfs_pod=$(kubectl get pods -n default -l app=${nfs_dname} -o jsonpath='{.items[0].metadata.name}')
-
- info "Executing: kubectl exec ${nfs_pod} -- sh -c \"mkdir -p ${minio_path}\""
- kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${minio_path}"
- success "Minio directory created successfully in NFS Pod!"
- fi
+ prepare_nfs_path "${DEPLOY_VARS["MINIO_NAME"]}"
}
check_rabbitmq_up_dependency(){
- local rabbit_path="${DEPLOY_VARS["NFS_POD_PATH"]}/${DEPLOY_VARS["RABBITMQ_NAME"]}"
+ prepare_nfs_path "${DEPLOY_VARS["RABBITMQ_NAME"]}"
+}
+
+prepare_nfs_path() {
+ local name="$1"
+ local path="${DEPLOY_VARS["NFS_POD_PATH"]}/${name}"
local nfs_dname=${DEPLOY_VARS["NFS_NAME"]}
check_if_nfs_up
@@ -421,14 +378,15 @@ check_rabbitmq_up_dependency(){
return
fi
- if [ "${DEPLOY_VARS["ENABLE_EXTERNAL_NFS"]}" == "false" ]; then
- info "Preparing RabbitMQ data directory: ${rabbit_path}"
- local nfs_pod=$(kubectl get pods -n default -l app=${nfs_dname} -o jsonpath='{.items[0].metadata.name}')
-
- info "Executing: kubectl exec ${nfs_pod} -- sh -c \"mkdir -p ${rabbit_path}\""
- kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${rabbit_path}"
- success "RabbitMQ directory created successfully in NFS Pod!"
+ if [ "${DEPLOY_VARS["ENABLE_EXTERNAL_NFS"]}" == "true" ]; then
+ return
fi
+
+ info "Preparing ${name} data directory: ${path}"
+ local nfs_pod=$(kubectl get pods -n default -l app=${nfs_dname} -o jsonpath='{.items[0].metadata.name}')
+ info "Executing: kubectl exec ${nfs_pod} -- sh -c \"mkdir -p ${path} && chmod 777 ${path}\""
+ kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${path} && chmod 777 ${path}"
+ success "${name} directory created successfully in NFS Pod!"
}
check_log_up_dependency(){
@@ -479,18 +437,8 @@ check_manager_up_dependency(){
}
check_runtime_up_dependency(){
- local jiuwenclaw_path="${DEPLOY_VARS["NFS_POD_PATH"]}/jiuwenclaw"
- local nfs_dname=${DEPLOY_VARS["NFS_NAME"]}
-
if [ "${DEPLOY_VARS["CLAW_MOUNT_TYPE"]}" == "nfs" ]; then
- check_if_nfs_up
-
- if [[ "${DEPLOY_VARS["RENDER_ONLY"]}" != "true" && "${DEPLOY_VARS["ENABLE_EXTERNAL_NFS"]}" == "false" ]]; then
- info "Preparing JiuwenClaw data directory: ${jiuwenclaw_path}"
- local nfs_pod=$(kubectl get pods -n default -l app=${nfs_dname} -o jsonpath='{.items[0].metadata.name}')
- kubectl exec ${nfs_pod} -- sh -c "mkdir -p ${jiuwenclaw_path}"
- success "JiuwenClaw directory created successfully in NFS Pod!"
- fi
+ prepare_nfs_path "jiuwenclaw"
elif [ "${DEPLOY_VARS["CLAW_MOUNT_TYPE"]}" == "pvc" ]; then
check_if_nfs_sc_up
fi
diff --git a/deploy/enterprise/gateway_handler.sh b/deploy/enterprise/gateway_handler.sh
index e270978675..abc755f596 100755
--- a/deploy/enterprise/gateway_handler.sh
+++ b/deploy/enterprise/gateway_handler.sh
@@ -24,49 +24,6 @@ gen_gateway_env_file() {
| yq eval 'del(.metadata.creationTimestamp)' > "${yaml_file}"
}
-gen_gateway_config_file() {
- local field_name="feishu"
- local template_file="${CONFIG["GATEWAY_CONFIG_TEMPLATE_FILE"]}"
- local file="${CONFIG["GATEWAY_CONFIG_FILE"]}"
- local yaml_file="${CONFIG["GATEWAY_CONFIG_YAML_FILE"]}"
- local namespace="${DEPLOY_VARS["NAMESPACE"]}"
- local conf_name="${DEPLOY_VARS["GATEWAY_CONFIG_MAP_NAME"]}"
-
- info "GATEWAY_CONFIG_TEMPLATE_FILE: ${template_file}"
- render_config_template "${template_file}" "${file}" "DEPLOY_VARS"
-
- # Clear configuration
- yq eval ".channels.${field_name} = {}" -i "${file}"
-
- # 飞书机器人配置(可选):未配置 FEISHU_BOTS 时跳过,channels.feishu 保持为空
- local feishu_bots="${DEPLOY_VARS["FEISHU_BOTS"]:-}"
- if [ -n "${feishu_bots}" ]; then
- echo "${feishu_bots}" | while read -r line; do
- # Skip empty lines
- [ -z "${line}" ] && continue
-
- # Split by colon
- IFS=':' read -r bot_name app_id app_secret <<< "${line}"
-
- # info "Adding bot: ${bot_name}"
- yq eval ".channels.${field_name}.${bot_name}.app_id = \"${app_id}\"" -i "${file}"
- yq eval ".channels.${field_name}.${bot_name}.app_secret = \"${app_secret}\"" -i "${file}"
- yq eval ".channels.${field_name}.${bot_name}.encrypt_key = \"\"" -i "${file}"
- yq eval ".channels.${field_name}.${bot_name}.verification_token = \"\"" -i "${file}"
- yq eval ".channels.${field_name}.${bot_name}.allow_from = []" -i "${file}"
- yq eval ".channels.${field_name}.${bot_name}.enable_streaming = true" -i "${file}"
- yq eval ".channels.${field_name}.${bot_name}.chat_id = \"\"" -i "${file}"
- yq eval ".channels.${field_name}.${bot_name}.enabled = true" -i "${file}"
- done
- fi
-
- success "Gateway config rendered: ${file}; ConfigMap yaml: ${yaml_file}"
- kubectl create configmap -n "${namespace}" "${conf_name}" \
- --from-file=config.yaml="${file}" \
- --dry-run=client -o yaml \
- | yq eval 'del(.metadata.creationTimestamp)' > "${yaml_file}"
-}
-
gen_gateway_file() {
local mode="${DEPLOY_VARS["MODE"]}"
local template_file="${CONFIG["GATEWAY_TEMPLATE_FILE"]}"
@@ -102,7 +59,6 @@ render_gateway_files() {
render_secret_configmap
gen_gateway_env_file
- gen_gateway_config_file
ensure_available_port "GATEWAY_CONFIG_HTTP_NODE_PORT"
gen_gateway_file
@@ -114,14 +70,12 @@ render_gateway_files() {
deploy_gateway() {
local namespace="${DEPLOY_VARS["NAMESPACE"]}"
local env_yaml_file="${CONFIG["GATEWAY_ENV_YAML_FILE"]}"
- local conf_yaml_file="${CONFIG["GATEWAY_CONFIG_YAML_FILE"]}"
local name="${DEPLOY_VARS["GATEWAY_NAME"]}"
local gateway_file="${CONFIG["GATEWAY_FILE"]}"
ensure_secret_configmap
# 使用 apply 保证重复部署幂等:ConfigMap 已存在时更新内容,不因 create 冲突失败。
exec_cmd kubectl apply -f "${env_yaml_file}"
- exec_cmd kubectl apply -f "${conf_yaml_file}"
exec_cmd kubectl apply -f "${gateway_file}"
wait_k8s_resource_ready "deployment" "${name}" "${namespace}"
@@ -130,11 +84,9 @@ deploy_gateway() {
uninstall_gateway() {
local gateway_file="${CONFIG["GATEWAY_FILE"]}"
local env_yaml_file="${CONFIG["GATEWAY_ENV_YAML_FILE"]}"
- local conf_yaml_file="${CONFIG["GATEWAY_CONFIG_YAML_FILE"]}"
exec_cmd kubectl delete -f "${gateway_file}" --ignore-not-found=true
exec_cmd kubectl delete -f "${env_yaml_file}" --ignore-not-found=true
- exec_cmd kubectl delete -f "${conf_yaml_file}" --ignore-not-found=true
uninstall_secret_configmap
ensure_redis_down
diff --git a/deploy/enterprise/global_vars.sh b/deploy/enterprise/global_vars.sh
index c585335fef..1544e3776d 100755
--- a/deploy/enterprise/global_vars.sh
+++ b/deploy/enterprise/global_vars.sh
@@ -43,10 +43,6 @@ declare -A CONFIG=(
["SECRET_CM_TEMPLATE_FILE"]="${TEMPLATE_DIR}/configmap-secret.template.yaml"
["SECRET_CM_FILE"]="${CONFIG_DIR}/configmap-secret.yaml"
- ["GATEWAY_CONFIG_TEMPLATE_FILE"]="${TEMPLATE_DIR}/gateway-config.template.yaml"
- ["GATEWAY_CONFIG_FILE"]="${CONFIG_DIR}/gateway-config.yaml"
- ["GATEWAY_CONFIG_YAML_FILE"]="${CONFIG_DIR}/gateway-config.configmap.yaml"
-
["GATEWAY_ENV_TEMPLATE_FILE"]="${TEMPLATE_DIR}/gateway.template.env"
["GATEWAY_ENV_FILE"]="${CONFIG_DIR}/gateway.env"
["GATEWAY_ENV_YAML_FILE"]="${CONFIG_DIR}/gateway-env.configmap.yaml"
@@ -137,7 +133,6 @@ declare -A DEPLOY_VARS=(
["TOOL_RESULT_DISPLAY_MAX_CHARS"]="500"
["GATEWAY_NAME"]="jiuwenclaw-gateway"
["GATEWAY_REPLICAS"]="1"
- ["GATEWAY_CONFIG_MAP_NAME"]="jiuwenclaw-gateway-config"
["GATEWAY_DB_MAX_OVERFLOW"]="20"
["GATEWAY_DB_POOL_SIZE"]="2"
["GATEWAY_DB_POOL_TIMEOUT"]="30"
@@ -146,6 +141,7 @@ declare -A DEPLOY_VARS=(
["GATEWAY_SCHED_LABEL_ENABLED"]="false"
["GATEWAY_RUNTIME_MANAGER_URL"]="http://jiuwenclaw-agent-runtime:8091"
["GATEWAY_WEB_SESSION_STORAGE"]="remote"
+ ["GATEWAY_SESSION_MAP_SCOPE"]="per_chat_bot_user"
["LOG_MASK_ENABLED"]="true"
["LOG_TO_FILE_ENABLED"]="true"
["IDENTITY_NAME"]="jiuwenclaw-identity"
@@ -241,6 +237,7 @@ declare -A DEPLOY_VARS=(
["AGENT_RUNTIME_REQUEST_TIMEOUT"]="300"
["AGENT_RUNTIME_SCOPE_FULL_TIMEOUT"]="30"
["AGENT_RUNTIME_LOG_LEVEL"]="INFO"
+ ["AGENT_RUNTIME_WATCH_INTERVAL"]="10"
["WS_ALLOWED_ORIGINS"]=""
["WS_ORIGIN_CHECK_ENABLED"]="false"
["CLAW_HOME"]="/home/app"
@@ -260,6 +257,7 @@ declare -A DEPLOY_VARS=(
["JIUWENBOX_PORT"]="8321"
["APPLY_PATCH"]="false"
["LOGIN_AUTH_SIMULATE"]="false"
+ ["JIUWENSWARM_CONFIG_DIR"]="/app/config"
)
declare -A OYR_COMPONENTS=(
diff --git a/deploy/enterprise/templates/agentserver.template.env b/deploy/enterprise/templates/agentserver.template.env
index e573bd72f2..76e0e04d7d 100644
--- a/deploy/enterprise/templates/agentserver.template.env
+++ b/deploy/enterprise/templates/agentserver.template.env
@@ -11,6 +11,9 @@ HOME=<<CLAW_HOME>>
LOG_ROOT_PATH=<<CLAW_HOME>>
DB_CONNECT_TIMEOUT=<<DB_CONNECT_TIMEOUT>>
JIUWENSWARM_EDITION=enterprise
+JIUWENSWARM_CONFIG_DIR=<<JIUWENSWARM_CONFIG_DIR>>
+AGENT_SERVER_REACT_MAX_ITER=<<AGENT_SERVER_REACT_MAX_ITER>>
+JIUWENBOX_URL=http://127.0.0.1:<<JIUWENBOX_PORT>>
# 企业版工具黑名单(覆盖 config.yaml 中 react.disabled_tools 的 ${DISABLED_TOOLS-...})
DISABLED_TOOLS=search_skill,install_skill,uninstall_skill,code,web_search,fetch_webpage,skill_acceleration_exec,deepresearch_execute,deepresearch_stream,deepresearch_prepare_rewrite,deepresearch_commit_rewrite,deepresearch_generate_rewrite_html,wiki_ingest,wiki_query,wiki_lint,memory_search,audio_transcription,audio_question_answering,prepare_skill_evolution,evolve_review_task,evolve_skill_experiences,list_skill_experiences,read_skill_experiences,simplify_skill_experiences,get_current_goal,submit_goal_report
diff --git a/deploy/enterprise/templates/agentserver.template.json b/deploy/enterprise/templates/agentserver.template.json
index d0a2ce058f..1d7a9aafa5 100644
--- a/deploy/enterprise/templates/agentserver.template.json
+++ b/deploy/enterprise/templates/agentserver.template.json
@@ -66,11 +66,6 @@
{
"name": "data",
"mountPath": "<<CLAW_HOME>>/.jiuwenswarm"
- },
- {
- "name": "agentserver-config",
- "mountPath": "<<CLAW_HOME>>/.jiuwenswarm/config/config.yaml",
- "subPath": "config.yaml"
}
]
},
@@ -185,12 +180,6 @@
"type": "Directory"
}
},
- {
- "name": "agentserver-config",
- "configMap": {
- "name": "<<GATEWAY_CONFIG_MAP_NAME>>"
- }
- },
{
"name": "hp-cgroup",
"hostPath": {
diff --git a/deploy/enterprise/templates/gateway.template.env b/deploy/enterprise/templates/gateway.template.env
index c85e378f47..43636e5d83 100644
--- a/deploy/enterprise/templates/gateway.template.env
+++ b/deploy/enterprise/templates/gateway.template.env
@@ -4,6 +4,7 @@ LOG_ROOT_PATH=<<CLAW_HOME>>/.logs
EXTENSION_DIRS=<<CLAW_POD_CODE_PATH>>/packages/jiuwenclaw-ee/gateway/extensions
NAMESPACE=<<NAMESPACE>>
JIUWENSWARM_EDITION=enterprise
+JIUWENSWARM_CONFIG_DIR=<<JIUWENSWARM_CONFIG_DIR>>
TZ=<<TIMEZONE>>
HTTP_PROXY=<<HTTP_PROXY>>
HTTPS_PROXY=<<HTTPS_PROXY>>
@@ -30,6 +31,7 @@ LOG_MASK_ENABLED=<<LOG_MASK_ENABLED>>
LOG_TO_FILE_ENABLED=<<LOG_TO_FILE_ENABLED>>
SYNC_CONFIG_ON_STARTUP=FALSE
JIUWENSWARM_REQUEST_EXT_FORWARD_HEADERS=<<JIUWENSWARM_REQUEST_EXT_FORWARD_HEADERS>>
+GATEWAY_SESSION_MAP_SCOPE=<<GATEWAY_SESSION_MAP_SCOPE>>
# Websocket Configuration
WEB_HOST=0.0.0.0
diff --git a/deploy/enterprise/templates/gateway.template.yaml b/deploy/enterprise/templates/gateway.template.yaml
index a56985c496..a6174159a2 100644
--- a/deploy/enterprise/templates/gateway.template.yaml
+++ b/deploy/enterprise/templates/gateway.template.yaml
@@ -70,18 +70,6 @@ spec:
name: <<SECRET_CM_NAME>>
- configMapRef:
name: <<GATEWAY_ENV_FILE_CM_NAME>>
- volumeMounts:
- - name: gateway-config
- mountPath: <<CLAW_HOME>>/.jiuwenswarm/config/config.yaml
- subPath: config.yaml
- readOnly: true
- volumes:
- - name: gateway-config
- configMap:
- name: <<GATEWAY_CONFIG_MAP_NAME>>
- items:
- - key: config.yaml
- path: config.yaml
---
# Service:提供稳定 DNS 域名, 供集群内部访问
diff --git a/deploy/enterprise/templates/runtime.template.yaml b/deploy/enterprise/templates/runtime.template.yaml
index 05403ec663..aff35398e8 100644
--- a/deploy/enterprise/templates/runtime.template.yaml
+++ b/deploy/enterprise/templates/runtime.template.yaml
@@ -135,6 +135,8 @@ spec:
fieldPath: metadata.namespace
- name: AGENT_RUNTIME_LOG_LEVEL
value: "<<AGENT_RUNTIME_LOG_LEVEL>>"
+ - name: AGENT_RUNTIME_WATCH_INTERVAL
+ value: "<<AGENT_RUNTIME_WATCH_INTERVAL>>"
- name: JIUWENSWARM_EDITION
value: "enterprise"
- name: TZ
diff --git a/deploy/enterprise/update_conf.sh b/deploy/enterprise/update_conf.sh
index b35b0661de..46fccd6a13 100755
--- a/deploy/enterprise/update_conf.sh
+++ b/deploy/enterprise/update_conf.sh
@@ -9,13 +9,14 @@ cp -f "${SRC_FILE}" "${DEST_FILE}"
yq eval '.gateway.agent_client.type = "jiuwen"' -i "${DEST_FILE}"
yq eval '.gateway.edition = "enterprise"' -i "${DEST_FILE}"
-yq eval '.gateway.session_map_scope = "<<GATEWAY_SESSION_MAP_SCOPE>>"' -i "${DEST_FILE}"
+yq eval '.gateway.session_map_scope = "${GATEWAY_SESSION_MAP_SCOPE:-per_chat_bot}"' -i "${DEST_FILE}"
yq eval '.channels.feishu = {}' -i "${DEST_FILE}"
-yq eval '.react.max_iterations = "<<AGENT_SERVER_REACT_MAX_ITER>>"' -i "${DEST_FILE}"
+yq eval '.react.max_iterations = "${AGENT_SERVER_REACT_MAX_ITER:-100}"' -i "${DEST_FILE}"
yq eval '.react.evolution.enabled = false' -i "${DEST_FILE}"
yq eval '.sandbox.enabled = true' -i "${DEST_FILE}"
yq eval '.sandbox.startup_mode = "external"' -i "${DEST_FILE}"
yq eval '.sandbox.idle_ttl_seconds = 600' -i "${DEST_FILE}"
yq eval '.sandbox.idle_check_interval = 180' -i "${DEST_FILE}"
-yq eval '.sandbox.url = "http://127.0.0.1:<<JIUWENBOX_PORT>>"' -i "${DEST_FILE}"
+yq eval '.sandbox.url = "${JIUWENBOX_URL:-http://127.0.0.1:8321}"' -i "${DEST_FILE}"
yq eval '.sandbox.type = "jiuwenbox"' -i "${DEST_FILE}"
+yq eval '.channels.ssh.host_key_path = "${JIUWENSWARM_CONFIG_DIR:-}/ssh_host_key"' -i "${DEST_FILE}"
diff --git a/docker/Dockerfile.claw b/docker/Dockerfile.claw
index f343e5e64e..59c338e857 100644
--- a/docker/Dockerfile.claw
+++ b/docker/Dockerfile.claw
@@ -10,7 +10,8 @@ ARG PIP_EXTRA_ARGS="-i https://mirrors.aliyun.com/pypi/simple/"
# 会在构建期直接失败(fail fast),避免运行期属主漂移导致 EACCES
RUN groupadd --gid 1000 app \
&& useradd --uid 1000 --gid 1000 --create-home --shell /bin/bash app \
- && mkdir -p /app/jiuwenswarm && chown app:app /app/jiuwenswarm
+ && mkdir -p /app/jiuwenswarm /app/config \
+ && chown -R app:app /app
WORKDIR /app/jiuwenswarm
COPY --chown=app:app . /app/jiuwenswarm/
@@ -35,8 +36,6 @@ RUN mkdir -p /opt/tiktoken-cache \
RUN yq -y -i '.dependencies = {}' jiuwenswarm/extensions/symphony/extension.yaml
-RUN mkdir -p /home/app/.jiuwenswarm/config && chown -R app:app /home/app/.jiuwenswarm
-
USER app
ENV PATH=$PATH:/home/app/.local/bin
diff --git a/docker/start.sh b/docker/start.sh
index 35da1ee771..f7b2f4e3df 100755
--- a/docker/start.sh
+++ b/docker/start.sh
@@ -1,24 +1,30 @@
#!/usr/bin/env bash
-# 容器启动入口:根据 ROLE 环境变量初始化 workspace 并启动对应服务。
-# ROLE=gateway -> jiuwenswarm-init + jiuwenswarm-gateway
-# ROLE=agentserver -> jiuwenswarm-init + jiuwenswarm-agentserver
-# 其他/未设置 -> 打印提示后退出
+# 容器启动入口(仅由 gateway / agentserver 容器调用):
+# 校验 ROLE → 生成企业版配置 → 初始化 workspace → 启动对应服务
+# ROLE=gateway -> jiuwenswarm-gateway
+# ROLE=agentserver -> jiuwenswarm-agentserver
+# JIUWENSWARM_CONFIG_DIR 等环境变量由 k8s envFrom 在进程启动前注入,
+# 到本脚本执行时已就绪。
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "[start.sh] ROLE='${ROLE}', JIUWENSWARM_EDITION='${JIUWENSWARM_EDITION}'"
-case "${ROLE}" in
- gateway)
- echo "[start.sh] initializing workspace"
- jiuwenswarm-init
- echo "[start.sh] starting jiuwenswarm-gateway"
- exec jiuwenswarm-gateway
- ;;
- agentserver)
- echo "[start.sh] initializing workspace"
- jiuwenswarm-init
- echo "[start.sh] starting jiuwenswarm-agentserver"
- exec jiuwenswarm-agentserver
- ;;
- *)
- echo "[start.sh] ROLE not set or unknown ('${ROLE}'), nothing to do."
- exit 0
- ;;
-esac
+
+# 前置校验:ROLE 不合法直接报错退出(不生成配置、不初始化)
+if [ "${ROLE}" != "gateway" ] && [ "${ROLE}" != "agentserver" ]; then
+ echo "[start.sh] ERROR: ROLE must be 'gateway' or 'agentserver', got '${ROLE}'" >&2
+ exit 1
+fi
+
+# 初始化 workspace(先建目录/稀疏配置;企业配置由下一步 update_conf.py 覆盖)
+echo "[start.sh] initializing workspace"
+jiuwenswarm-init
+
+# 生成企业版配置(app 身份执行 → 覆盖上一步稀疏版;失败即退出,不 startup)
+echo "[start.sh] generating config via update_conf.py"
+echo "[start.sh] JIUWENSWARM_CONFIG_DIR='${JIUWENSWARM_CONFIG_DIR}'"
+if ! python3 "${SCRIPT_DIR}/update_conf.py"; then
+ echo "[start.sh] update_conf.py FAILED" >&2
+ exit 1
+fi
+
+echo "[start.sh] starting jiuwenswarm-${ROLE}"
+exec "jiuwenswarm-${ROLE}"
diff --git a/docker/update_conf.py b/docker/update_conf.py
new file mode 100644
index 0000000000..e51fd17cb4
--- /dev/null
+++ b/docker/update_conf.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python3
+"""企业版 config.yaml 生成器
+用法:python3 update_conf.py [config_dir](缺省 = $JIUWENSWARM_CONFIG_DIR;config.yaml 文件名固定)
+"""
+
+from __future__ import annotations
+
+import logging
+import os
+import sys
+from pathlib import Path
+
+from ruamel.yaml import YAML
+
+logger = logging.getLogger("update_conf")
+
+SCRIPT_DIR = Path(__file__).resolve().parent
+REPO_ROOT = SCRIPT_DIR.parent
+SRC_FILE = REPO_ROOT / "jiuwenswarm" / "resources" / "config.yaml"
+DEFAULT_CONFIG_DIR = Path.home() / ".jiuwenswarm" / "config"
+
+
+def config_dir() -> Path:
+ """配置目录:CLI 参数(argv[1])> ``JIUWENSWARM_CONFIG_DIR`` > 默认目录。"""
+ if len(sys.argv) > 1:
+ return Path(sys.argv[1]).expanduser()
+ env = os.getenv("JIUWENSWARM_CONFIG_DIR", "").strip()
+ return Path(env).expanduser() if env else DEFAULT_CONFIG_DIR
+
+
+def setpath(d, dotted_path: str, value) -> None:
+ """等价 yq eval '.a.b.c = value':中间键不存在则创建。"""
+ keys = dotted_path.split(".")
+ cur = d
+ for key in keys[:-1]:
+ node = cur.get(key)
+ if not isinstance(node, dict):
+ node = {}
+ cur[key] = node
+ cur = node
+ cur[keys[-1]] = value
+
+
+def inject_feishu_bots(data) -> None:
+ """原 gen_gateway_config_file 的 FEISHU_BOTS 注入,改由 env 驱动。"""
+ data["channels"]["feishu"] = {}
+ bots = os.getenv("FEISHU_BOTS", "").strip()
+ for line in bots.splitlines():
+ line = line.strip()
+ if not line:
+ continue
+ parts = line.split(":", 2)
+ if len(parts) != 3:
+ logger.warning(
+ "FEISHU_BOTS 行格式非法(应为 bot_name:app_id:app_secret): %r", line
+ )
+ continue
+ bot_name, app_id, app_secret = parts
+ data["channels"]["feishu"][bot_name] = {
+ "app_id": app_id,
+ "app_secret": app_secret,
+ "encrypt_key": "",
+ "verification_token": "",
+ "allow_from": [],
+ "enable_streaming": True,
+ "chat_id": "",
+ "enabled": True,
+ }
+
+
+def main() -> int:
+ logging.basicConfig(level=logging.INFO, format="[update_conf] %(levelname)s %(message)s")
+
+ dest = config_dir() / "config.yaml"
+ if not SRC_FILE.is_file():
+ logger.error("source not found: %s", SRC_FILE)
+ return 1
+
+ parser = YAML()
+ parser.preserve_quotes = True
+ data = parser.load(SRC_FILE)
+
+ # ---- 企业版域修改(与原 yq 版等价;宏改为 ${ENV:-default} 插值占位)----
+ setpath(data, "gateway.agent_client.type", "jiuwen")
+ setpath(data, "gateway.edition", "enterprise")
+ setpath(data, "gateway.session_map_scope", "${GATEWAY_SESSION_MAP_SCOPE:-per_chat_bot}")
+ setpath(data, "react.max_iterations", "${AGENT_SERVER_REACT_MAX_ITER:-100}")
+ setpath(data, "react.evolution.enabled", False)
+ setpath(data, "sandbox.enabled", True)
+ setpath(data, "sandbox.startup_mode", "external")
+ setpath(data, "sandbox.idle_ttl_seconds", 600)
+ setpath(data, "sandbox.idle_check_interval", 180)
+ setpath(data, "sandbox.url", "${JIUWENBOX_URL:-http://127.0.0.1:8321}")
+ setpath(data, "sandbox.type", "jiuwenbox")
+ setpath(data, "channels.ssh.host_key_path", "${JIUWENSWARM_CONFIG_DIR:-}/ssh_host_key")
+
+ inject_feishu_bots(data)
+
+ dest.parent.mkdir(parents=True, exist_ok=True)
+ with open(dest, "w", encoding="utf-8") as f:
+ parser.dump(data, f)
+
+ logger.info("generated %s (from %s)", dest, SRC_FILE)
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/jiuwenswarm/common/secrets/store.py b/jiuwenswarm/common/secrets/store.py
index ccc8062ba1..8efe5fc3db 100644
--- a/jiuwenswarm/common/secrets/store.py
+++ b/jiuwenswarm/common/secrets/store.py
@@ -86,8 +86,10 @@ class SecretStore:
self,
*,
master_key_env: str = "JIUWEN_SECRET_MASTER_KEY",
- master_key_file: str = "~/.jiuwenswarm/config/.master_key",
+ master_key_file: str | None = None,
) -> None:
+ if not master_key_file:
+ master_key_file = str(get_config_dir() / ".master_key")
self._transform.configure_aes256gcm(
master_key_env=master_key_env,
master_key_file=master_key_file,
diff --git a/jiuwenswarm/common/utils.py b/jiuwenswarm/common/utils.py
index 8faef4548b..16f33e1a30 100644
--- a/jiuwenswarm/common/utils.py
+++ b/jiuwenswarm/common/utils.py
@@ -601,7 +601,12 @@ def get_user_workspace_dir() -> Path:
return _workspace_base_dir
-
+def _config_dir_from_env() -> Path | None:
+ """显式覆盖:``JIUWENSWARM_CONFIG_DIR``,未设置返回 None。"""
+ env_config_dir = os.getenv("JIUWENSWARM_CONFIG_DIR", "").strip()
+ if env_config_dir:
+ return Path(env_config_dir).expanduser()
+ return None
# Cache for resolved paths
_config_dir: Path | None = None
@@ -1443,7 +1448,8 @@ def prepare_workspace(
+ ", ".join(str(p) for p in config_yaml_src_candidates)
)
- config_dest_dir = workspace_dir / "config"
+ override = _config_dir_from_env()
+ config_dest_dir = override if override is not None else (workspace_dir / "config")
config_dest_dir.mkdir(parents=True, exist_ok=True)
config_yaml_dest = config_dest_dir / "config.yaml"
@@ -1483,7 +1489,7 @@ def prepare_workspace(
"env template source not found; tried: "
+ ", ".join(str(p) for p in env_template_src_candidates)
)
- env_dest = workspace_dir / "config" / ".env"
+ env_dest = config_dest_dir / ".env"
if overwrite or not env_dest.exists():
with TrackCopyDiff(
dest=env_dest,
@@ -1810,7 +1816,14 @@ def _resolve_paths(force=False) -> None:
def get_config_dir() -> Path:
- """Get the config directory path."""
+ """Get the config directory path.
+
+ ``JIUWENSWARM_CONFIG_DIR`` 优先级最高:设置时绕过缓存,每次按 env 返回;
+ 未设置时走默认缓存解析。
+ """
+ override = _config_dir_from_env()
+ if override is not None:
+ return override
_resolve_paths()
return _config_dir