Upload config-generator.py with huggingface_hub
Browse files- config-generator.py +35 -21
config-generator.py
CHANGED
|
@@ -7,13 +7,13 @@ config-generator.py — 环境变量驱动的 openclaw.json 生成器
|
|
| 7 |
2. 从备份恢复的 openclaw.json
|
| 8 |
3. 环境变量覆盖 (最高优先级)
|
| 9 |
|
| 10 |
-
端口:
|
| 11 |
"""
|
| 12 |
|
| 13 |
import json, os, copy
|
| 14 |
|
| 15 |
STATE_DIR = os.environ.get("OPENCLAW_STATE_DIR", "/root/.openclaw")
|
| 16 |
-
|
| 17 |
|
| 18 |
def deep_merge(base: dict, overlay: dict) -> dict:
|
| 19 |
result = copy.deepcopy(base)
|
|
@@ -42,7 +42,7 @@ def generate() -> dict:
|
|
| 42 |
"gateway": {
|
| 43 |
"mode": "local",
|
| 44 |
"bind": "lan",
|
| 45 |
-
"port":
|
| 46 |
"trustedProxies": ["0.0.0.0/0"],
|
| 47 |
"auth": {
|
| 48 |
"mode": "token",
|
|
@@ -118,19 +118,28 @@ def generate() -> dict:
|
|
| 118 |
"workspace": os.path.join(STATE_DIR, "workspace"),
|
| 119 |
}
|
| 120 |
|
| 121 |
-
# 3c. 5
|
| 122 |
-
default_names = ["开发组-产品经理", "开发组-架构师", "开发组-开发", "开发组-测试", "开发组-项目经理"]
|
| 123 |
-
for i in range(1,
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
agent_def = {
|
| 128 |
-
"id":
|
| 129 |
"name": name,
|
| 130 |
-
"workspace":
|
| 131 |
"model": {"primary": model_override},
|
| 132 |
}
|
| 133 |
|
|
|
|
| 134 |
skills_str = os.environ.get(f"AGENT_{i}_SKILLS", "")
|
| 135 |
if skills_str:
|
| 136 |
agent_def["skills"] = [s.strip() for s in skills_str.split(",")]
|
|
@@ -149,17 +158,20 @@ def generate() -> dict:
|
|
| 149 |
plugins_allow = os.environ.get("PLUGINS_ALLOW", "")
|
| 150 |
if plugins_allow:
|
| 151 |
config["plugins"]["allow"] = [p.strip() for p in plugins_allow.split(",")]
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
return config
|
| 165 |
|
|
@@ -169,4 +181,6 @@ if __name__ == "__main__":
|
|
| 169 |
out = os.path.join(STATE_DIR, "openclaw.json")
|
| 170 |
with open(out, "w") as f:
|
| 171 |
json.dump(config, f, indent=2, ensure_ascii=False)
|
|
|
|
|
|
|
| 172 |
print(f"[config] Generated → {out}")
|
|
|
|
| 7 |
2. 从备份恢复的 openclaw.json
|
| 8 |
3. 环境变量覆盖 (最高优先级)
|
| 9 |
|
| 10 |
+
端口: 18889 (内部端口,由 Caddy 反向代理)
|
| 11 |
"""
|
| 12 |
|
| 13 |
import json, os, copy
|
| 14 |
|
| 15 |
STATE_DIR = os.environ.get("OPENCLAW_STATE_DIR", "/root/.openclaw")
|
| 16 |
+
GATEWAY_PORT = int(os.environ.get("OPENCLAW_GATEWAY_PORT", 18889))
|
| 17 |
|
| 18 |
def deep_merge(base: dict, overlay: dict) -> dict:
|
| 19 |
result = copy.deepcopy(base)
|
|
|
|
| 42 |
"gateway": {
|
| 43 |
"mode": "local",
|
| 44 |
"bind": "lan",
|
| 45 |
+
"port": GATEWAY_PORT,
|
| 46 |
"trustedProxies": ["0.0.0.0/0"],
|
| 47 |
"auth": {
|
| 48 |
"mode": "token",
|
|
|
|
| 118 |
"workspace": os.path.join(STATE_DIR, "workspace"),
|
| 119 |
}
|
| 120 |
|
| 121 |
+
# 3c. Agents: 5 role-based + 1 coordinator
|
| 122 |
+
default_names = ["开发组-产品经理", "开发组-架构师", "开发组-开发", "开发组-测试", "开发组-项目经理", "总协调"]
|
| 123 |
+
for i in range(1, 7): # 1-5 role agents, 6 coordinator
|
| 124 |
+
if i == 6:
|
| 125 |
+
agent_id = "coordinator"
|
| 126 |
+
name = os.environ.get("COORDINATOR_NAME", default_names[5])
|
| 127 |
+
workspace = os.path.join(STATE_DIR, "workspace-coordinator")
|
| 128 |
+
model_override = default_model
|
| 129 |
+
else:
|
| 130 |
+
agent_id = f"agent-{i}"
|
| 131 |
+
name = os.environ.get(f"AGENT_{i}_NAME", default_names[i - 1])
|
| 132 |
+
workspace = os.path.join(STATE_DIR, f"workspace-agent-{i}")
|
| 133 |
+
model_override = os.environ.get(f"AGENT_{i}_MODEL", default_model)
|
| 134 |
|
| 135 |
agent_def = {
|
| 136 |
+
"id": agent_id,
|
| 137 |
"name": name,
|
| 138 |
+
"workspace": workspace,
|
| 139 |
"model": {"primary": model_override},
|
| 140 |
}
|
| 141 |
|
| 142 |
+
# Skills
|
| 143 |
skills_str = os.environ.get(f"AGENT_{i}_SKILLS", "")
|
| 144 |
if skills_str:
|
| 145 |
agent_def["skills"] = [s.strip() for s in skills_str.split(",")]
|
|
|
|
| 158 |
plugins_allow = os.environ.get("PLUGINS_ALLOW", "")
|
| 159 |
if plugins_allow:
|
| 160 |
config["plugins"]["allow"] = [p.strip() for p in plugins_allow.split(",")]
|
| 161 |
+
else:
|
| 162 |
+
# Default plugin set (only bundled skills, not external plugins)
|
| 163 |
+
config["plugins"]["allow"] = [
|
| 164 |
+
"multi-search-cn",
|
| 165 |
+
"github",
|
| 166 |
+
"summarize",
|
| 167 |
+
]
|
| 168 |
+
|
| 169 |
+
# Enable bundled skills (these are in plugins.entries as skills)
|
| 170 |
+
core_skills = ["multi-search-cn", "github", "summarize"]
|
| 171 |
+
for p in core_skills:
|
| 172 |
+
if p not in config["plugins"]["allow"]:
|
| 173 |
+
config["plugins"]["allow"].append(p)
|
| 174 |
+
config["plugins"]["entries"][p] = {"enabled": True}
|
| 175 |
|
| 176 |
return config
|
| 177 |
|
|
|
|
| 181 |
out = os.path.join(STATE_DIR, "openclaw.json")
|
| 182 |
with open(out, "w") as f:
|
| 183 |
json.dump(config, f, indent=2, ensure_ascii=False)
|
| 184 |
+
# Debug: output full config to logs
|
| 185 |
+
print("[config] Full configuration (JSON):\n" + json.dumps(config, indent=2, ensure_ascii=False))
|
| 186 |
print(f"[config] Generated → {out}")
|