codebee 0.1.103 → 0.1.104
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.
- package/CHANGELOG.md +4 -0
- package/LICENSE +21 -21
- package/README.md +2 -3
- package/app/core/acceptance.py +100 -100
- package/app/core/acp_client.py +457 -457
- package/app/core/aiflavor.py +197 -197
- package/app/core/analytics.py +38 -38
- package/app/core/artifacts.py +148 -148
- package/app/core/assets.py +110 -110
- package/app/core/attachments.py +623 -623
- package/app/core/audit.py +30 -30
- package/app/core/backend_profiles.py +188 -188
- package/app/core/backup.py +470 -470
- package/app/core/beekeeper.py +183 -183
- package/app/core/benchstore.py +102 -102
- package/app/core/bookmeta.py +1036 -1036
- package/app/core/bookmeta_catalog.py +180 -180
- package/app/core/branching.py +137 -137
- package/app/core/capability.py +144 -144
- package/app/core/chaptersafe.py +32 -32
- package/app/core/cleanup.py +303 -303
- package/app/core/command_auth.py +302 -302
- package/app/core/compaction.py +201 -201
- package/app/core/contracts.py +255 -255
- package/app/core/covergen.py +356 -356
- package/app/core/defectretro.py +43 -43
- package/app/core/diagnostics.py +114 -114
- package/app/core/dispatch_log.py +128 -128
- package/app/core/env_scrub.py +85 -85
- package/app/core/errorlog.py +137 -137
- package/app/core/eval_matrix.py +91 -91
- package/app/core/evaluation.py +174 -174
- package/app/core/failure_notify.py +290 -290
- package/app/core/flow_graph.py +33 -33
- package/app/core/goal_service.py +167 -167
- package/app/core/health.py +389 -389
- package/app/core/history.py +38 -38
- package/app/core/hooks.py +162 -162
- package/app/core/knowledge_pipeline.py +86 -86
- package/app/core/manager.py +2385 -2385
- package/app/core/mocks.py +64 -64
- package/app/core/notify.py +201 -201
- package/app/core/novel_quality.py +285 -181
- package/app/core/openapi.py +217 -217
- package/app/core/operations.py +228 -228
- package/app/core/paihang.py +145 -145
- package/app/core/pipeline.py +55 -3
- package/app/core/planner.py +7 -0
- package/app/core/portguard.py +111 -111
- package/app/core/presence.py +77 -77
- package/app/core/preview.py +293 -293
- package/app/core/project_memory.py +206 -206
- package/app/core/prompt_guard.py +78 -78
- package/app/core/publish/__init__.py +7 -7
- package/app/core/publish/auto.py +659 -659
- package/app/core/publish/chaprows.py +138 -138
- package/app/core/publish/flows-fanqie-calibrated.json +442 -442
- package/app/core/publish/manager.py +1185 -1185
- package/app/core/publish/qimao.py +193 -193
- package/app/core/publish/volumes.py +108 -108
- package/app/core/publish/ws.py +139 -139
- package/app/core/quality_gate.py +201 -201
- package/app/core/redact.py +38 -38
- package/app/core/repeat_guard.py +129 -129
- package/app/core/retrieval.py +137 -137
- package/app/core/sandbox_runtime.py +95 -95
- package/app/core/selfupdate.py +384 -384
- package/app/core/session_log.py +161 -161
- package/app/core/sessions.py +312 -312
- package/app/core/settings.py +215 -215
- package/app/core/settings_schema.py +282 -282
- package/app/core/share_page.py +114 -114
- package/app/core/skill_scan.py +139 -139
- package/app/core/skillpacks/market/character-bible.md +66 -66
- package/app/core/skillpacks/market/code-risk-checklist.md +58 -58
- package/app/core/skillpacks/market/git-workflow.md +57 -57
- package/app/core/skillpacks/market/release-notes.md +72 -72
- package/app/core/skillpacks/market/weekly-report.md +71 -71
- package/app/core/skillpacks/market/worldview-consistency.md +70 -70
- package/app/core/step_runner.py +132 -132
- package/app/core/story_tracking.py +275 -275
- package/app/core/task_compile.py +199 -199
- package/app/core/telemetry.py +292 -292
- package/app/core/tlsctx.py +64 -64
- package/app/core/token_meter.py +147 -147
- package/app/core/tool_outputs.py +107 -107
- package/app/core/tracing.py +207 -207
- package/app/core/upstream.py +41 -41
- package/app/core/usage.py +1038 -1038
- package/app/core/volumes.py +389 -389
- package/app/core/webhooks.py +89 -89
- package/app/core/wxdigest.py +865 -865
- package/app/core/zentao.py +2692 -2692
- package/app/mcp_server.py +244 -244
- package/app/pick_dialog.py +110 -110
- package/app/ui/artdiff.js +74 -74
- package/app/ui/icons/bee.svg +79 -79
- package/app/ui/manifest.json +16 -16
- package/app/ui/qrcode.js +2297 -2297
- package/bin/tutti.js +147 -147
- package/package.json +1 -1
- package/tools/wx_reader.py +261 -261
- package/app/.playwright-cli/console-2026-09-23T08-26-03-635Z.log +0 -88
- package/app/.playwright-cli/page-2026-09-23T08-26-03-845Z.yml +0 -126
- package/app/.playwright-cli/page-2026-09-23T08-29-44-203Z.png +0 -0
- package/app/.playwright-cli/page-2026-09-23T08-35-42-046Z.yml +0 -210
- package/app/.playwright-cli/page-2026-09-23T08-36-52-858Z.png +0 -0
- package/app/.playwright-cli/page-2026-09-23T08-37-33-938Z.png +0 -0
- package/app/.playwright-cli/run-detail-after.png +0 -0
- package/app/output/_createbook_body.json +0 -1
- package/app/output/_probe_fq_click.py +0 -50
- package/app/output/_probe_fq_form.py +0 -42
- package/app/output/_probe_fq_modal.py +0 -55
- package/app/output/_probe_fq_points.py +0 -71
- package/app/output/_probe_fq_submit.py +0 -34
- package/app/output/_probe_fq_watch.py +0 -62
- package/app/output/workbench-clean-preview.jpg +0 -0
- package/app/output/workbench-reference-render.png +0 -0
- package/app/output/workbench-shell.png +0 -0
package/app/core/audit.py
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""轻量审计日志:不可逆操作留痕(当前仅任务删除)。
|
|
3
|
-
|
|
4
|
-
删除任务连运行记录一起物理清除且无回收站,出争议时无据可查
|
|
5
|
-
(2026-09-28 连载根任务被删案:谁删的、何时删的全无线索)。
|
|
6
|
-
这里按月追加 jsonl 到 data/audit/,一行一对象、正序追加,
|
|
7
|
-
与用量台账同款纪律。审计失败绝不拖垮主流程。
|
|
8
|
-
"""
|
|
9
|
-
from __future__ import annotations
|
|
10
|
-
|
|
11
|
-
import json
|
|
12
|
-
import time
|
|
13
|
-
from pathlib import Path
|
|
14
|
-
|
|
15
|
-
from . import paths
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def record(event: str, detail: dict) -> None:
|
|
19
|
-
"""追加一条审计记录(event 即台账名,如 task_delete)。"""
|
|
20
|
-
try:
|
|
21
|
-
day = time.strftime("%Y-%m")
|
|
22
|
-
d = Path(paths.DATA_DIR) / "audit"
|
|
23
|
-
d.mkdir(parents=True, exist_ok=True)
|
|
24
|
-
line = json.dumps(
|
|
25
|
-
{"ts": time.strftime("%Y-%m-%d %H:%M:%S"), "event": event, **detail},
|
|
26
|
-
ensure_ascii=False)
|
|
27
|
-
with open(d / ("%s-%s.jsonl" % (event, day)), "a", encoding="utf-8") as f:
|
|
28
|
-
f.write(line + "\n")
|
|
29
|
-
except Exception:
|
|
30
|
-
pass
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""轻量审计日志:不可逆操作留痕(当前仅任务删除)。
|
|
3
|
+
|
|
4
|
+
删除任务连运行记录一起物理清除且无回收站,出争议时无据可查
|
|
5
|
+
(2026-09-28 连载根任务被删案:谁删的、何时删的全无线索)。
|
|
6
|
+
这里按月追加 jsonl 到 data/audit/,一行一对象、正序追加,
|
|
7
|
+
与用量台账同款纪律。审计失败绝不拖垮主流程。
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import time
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from . import paths
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def record(event: str, detail: dict) -> None:
|
|
19
|
+
"""追加一条审计记录(event 即台账名,如 task_delete)。"""
|
|
20
|
+
try:
|
|
21
|
+
day = time.strftime("%Y-%m")
|
|
22
|
+
d = Path(paths.DATA_DIR) / "audit"
|
|
23
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
24
|
+
line = json.dumps(
|
|
25
|
+
{"ts": time.strftime("%Y-%m-%d %H:%M:%S"), "event": event, **detail},
|
|
26
|
+
ensure_ascii=False)
|
|
27
|
+
with open(d / ("%s-%s.jsonl" % (event, day)), "a", encoding="utf-8") as f:
|
|
28
|
+
f.write(line + "\n")
|
|
29
|
+
except Exception:
|
|
30
|
+
pass
|
|
@@ -1,188 +1,188 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""User-managed ACP agent launch profiles with secret-redacted views."""
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import json
|
|
6
|
-
import os
|
|
7
|
-
import re
|
|
8
|
-
import threading
|
|
9
|
-
import uuid
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
from .redact import scrub_text
|
|
13
|
-
|
|
14
|
-
_LOCK = threading.RLock()
|
|
15
|
-
_FILE = None
|
|
16
|
-
_SECRET_NAME = re.compile(r"(?i)(token|secret|password|passwd|api[_-]?key|credential)")
|
|
17
|
-
_PROFILE_ID = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$")
|
|
18
|
-
_ENV_NAME = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def init(data_dir=None):
|
|
22
|
-
global _FILE
|
|
23
|
-
with _LOCK:
|
|
24
|
-
if data_dir is None:
|
|
25
|
-
from . import paths
|
|
26
|
-
base = paths.DATA_DIR
|
|
27
|
-
else:
|
|
28
|
-
base = Path(data_dir)
|
|
29
|
-
base.mkdir(parents=True, exist_ok=True)
|
|
30
|
-
_FILE = base / "backend-profiles.json"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def _file():
|
|
34
|
-
global _FILE
|
|
35
|
-
if _FILE is None:
|
|
36
|
-
init()
|
|
37
|
-
return _FILE
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _load():
|
|
41
|
-
path = _file()
|
|
42
|
-
try:
|
|
43
|
-
data = json.loads(path.read_text(encoding="utf-8"))
|
|
44
|
-
except FileNotFoundError:
|
|
45
|
-
return []
|
|
46
|
-
except (OSError, ValueError) as exc:
|
|
47
|
-
raise ValueError("ACP 后端配置不可读取,已阻止覆盖") from exc
|
|
48
|
-
profiles = data.get("profiles") if isinstance(data, dict) else None
|
|
49
|
-
if not isinstance(profiles, list):
|
|
50
|
-
raise ValueError("ACP 后端配置格式无效")
|
|
51
|
-
return [row for row in profiles if isinstance(row, dict)][:50]
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _persist(profiles):
|
|
55
|
-
path = _file()
|
|
56
|
-
tmp = path.with_name(path.name + ".tmp")
|
|
57
|
-
tmp.write_text(json.dumps({"profiles": profiles}, ensure_ascii=False, indent=2),
|
|
58
|
-
encoding="utf-8")
|
|
59
|
-
try:
|
|
60
|
-
os.chmod(str(tmp), 0o600)
|
|
61
|
-
except OSError:
|
|
62
|
-
pass
|
|
63
|
-
os.replace(str(tmp), str(path))
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def _valid_workspace_path(value):
|
|
67
|
-
value = str(value or "").strip()
|
|
68
|
-
if not value:
|
|
69
|
-
return ""
|
|
70
|
-
if "\x00" in value or len(value) > 1024:
|
|
71
|
-
raise ValueError("workspace_path 无效")
|
|
72
|
-
if not (value.startswith("/") or value.startswith("\\") or
|
|
73
|
-
re.match(r"^[A-Za-z]:[\\/]", value)):
|
|
74
|
-
raise ValueError("workspace_path 必须是绝对路径")
|
|
75
|
-
return value
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _normalize(payload, existing=None):
|
|
79
|
-
if not isinstance(payload, dict):
|
|
80
|
-
raise ValueError("profile 必须是 JSON 对象")
|
|
81
|
-
old = existing or {}
|
|
82
|
-
profile_id = str(payload.get("id") or old.get("id") or
|
|
83
|
-
("backend-" + uuid.uuid4().hex[:16])).strip()
|
|
84
|
-
if not _PROFILE_ID.fullmatch(profile_id):
|
|
85
|
-
raise ValueError("profile id 格式无效")
|
|
86
|
-
label = str(payload.get("label") or "").strip()
|
|
87
|
-
command = str(payload.get("command") or "").strip()
|
|
88
|
-
if not label or len(label) > 80:
|
|
89
|
-
raise ValueError("label 必填且不能超过 80 个字符")
|
|
90
|
-
if not command or len(command) > 500 or "\x00" in command:
|
|
91
|
-
raise ValueError("command 必填且格式无效")
|
|
92
|
-
raw_args = payload.get("args", old.get("args", []))
|
|
93
|
-
if not isinstance(raw_args, list) or len(raw_args) > 80:
|
|
94
|
-
raise ValueError("args 必须是最多 80 项的列表")
|
|
95
|
-
args = []
|
|
96
|
-
for value in raw_args:
|
|
97
|
-
if not isinstance(value, str) or len(value) > 2048 or "\x00" in value:
|
|
98
|
-
raise ValueError("args 只能包含不超过 2048 字符的文本")
|
|
99
|
-
args.append(value)
|
|
100
|
-
raw_env = payload.get("env", old.get("env", {}))
|
|
101
|
-
if not isinstance(raw_env, dict) or len(raw_env) > 100:
|
|
102
|
-
raise ValueError("env 必须是最多 100 项的对象")
|
|
103
|
-
env = {}
|
|
104
|
-
old_env = old.get("env") or {}
|
|
105
|
-
for name, value in raw_env.items():
|
|
106
|
-
name = str(name)
|
|
107
|
-
if not _ENV_NAME.fullmatch(name) or not isinstance(value, str) \
|
|
108
|
-
or len(value) > 8192 or "\x00" in value:
|
|
109
|
-
raise ValueError("env 变量名或值无效")
|
|
110
|
-
if value == "__REDACTED__" and name in old_env:
|
|
111
|
-
value = old_env[name]
|
|
112
|
-
env[name] = value
|
|
113
|
-
enabled = payload.get("enabled", old.get("enabled", True))
|
|
114
|
-
if not isinstance(enabled, bool):
|
|
115
|
-
raise ValueError("enabled 必须是布尔值")
|
|
116
|
-
return {"id": profile_id, "agent_id": "acp-" + profile_id,
|
|
117
|
-
"label": label, "command": command, "args": args,
|
|
118
|
-
"env": env, "workspace_path": _valid_workspace_path(
|
|
119
|
-
payload.get("workspace_path", old.get("workspace_path", ""))),
|
|
120
|
-
"enabled": enabled}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def _view(profile):
|
|
124
|
-
row = dict(profile)
|
|
125
|
-
row["command"] = scrub_text(profile.get("command") or "", 500)
|
|
126
|
-
row["args"] = [scrub_text(value, 2048) for value in profile.get("args") or []]
|
|
127
|
-
env = {}
|
|
128
|
-
for name, value in (profile.get("env") or {}).items():
|
|
129
|
-
env[name] = "__REDACTED__" if _SECRET_NAME.search(name) and value else value
|
|
130
|
-
row["env"] = env
|
|
131
|
-
return row
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def list_profiles():
|
|
135
|
-
with _LOCK:
|
|
136
|
-
return [_view(row) for row in _load()]
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def runtime_profiles():
|
|
140
|
-
with _LOCK:
|
|
141
|
-
return [dict(row, env=dict(row.get("env") or {})) for row in _load()
|
|
142
|
-
if row.get("enabled", True)]
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def get_runtime(profile_id):
|
|
146
|
-
with _LOCK:
|
|
147
|
-
return next((dict(row, env=dict(row.get("env") or {}))
|
|
148
|
-
for row in _load() if row.get("id") == str(profile_id or "")
|
|
149
|
-
and row.get("enabled", True)), None)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def runtime_agents():
|
|
153
|
-
return [{"id": row["agent_id"], "profile_id": row["id"],
|
|
154
|
-
"label": row["label"], "kind": "acp", "mode": "real",
|
|
155
|
-
"command": row["command"], "args": list(row["args"]),
|
|
156
|
-
"env": {}, "workspace_path": row["workspace_path"],
|
|
157
|
-
"profile_managed": True}
|
|
158
|
-
for row in runtime_profiles()]
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
def save(payload):
|
|
162
|
-
with _LOCK:
|
|
163
|
-
profiles = _load()
|
|
164
|
-
requested_id = str((payload or {}).get("id") or "")
|
|
165
|
-
old = next((row for row in profiles if row.get("id") == requested_id), None)
|
|
166
|
-
if requested_id and old is None:
|
|
167
|
-
raise KeyError("ACP 后端配置不存在")
|
|
168
|
-
profile = _normalize(payload, old)
|
|
169
|
-
if any(row.get("id") == profile["id"] and row is not old for row in profiles):
|
|
170
|
-
raise ValueError("profile id 已存在")
|
|
171
|
-
if old is None and len(profiles) >= 50:
|
|
172
|
-
raise ValueError("ACP 后端最多配置 50 个")
|
|
173
|
-
if old is None:
|
|
174
|
-
profiles.append(profile)
|
|
175
|
-
else:
|
|
176
|
-
profiles[profiles.index(old)] = profile
|
|
177
|
-
_persist(profiles)
|
|
178
|
-
return _view(profile)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
def remove(profile_id):
|
|
182
|
-
with _LOCK:
|
|
183
|
-
profiles = _load()
|
|
184
|
-
remaining = [row for row in profiles if row.get("id") != str(profile_id or "")]
|
|
185
|
-
if len(remaining) == len(profiles):
|
|
186
|
-
raise KeyError("ACP 后端配置不存在")
|
|
187
|
-
_persist(remaining)
|
|
188
|
-
return True
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""User-managed ACP agent launch profiles with secret-redacted views."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import threading
|
|
9
|
+
import uuid
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from .redact import scrub_text
|
|
13
|
+
|
|
14
|
+
_LOCK = threading.RLock()
|
|
15
|
+
_FILE = None
|
|
16
|
+
_SECRET_NAME = re.compile(r"(?i)(token|secret|password|passwd|api[_-]?key|credential)")
|
|
17
|
+
_PROFILE_ID = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$")
|
|
18
|
+
_ENV_NAME = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def init(data_dir=None):
|
|
22
|
+
global _FILE
|
|
23
|
+
with _LOCK:
|
|
24
|
+
if data_dir is None:
|
|
25
|
+
from . import paths
|
|
26
|
+
base = paths.DATA_DIR
|
|
27
|
+
else:
|
|
28
|
+
base = Path(data_dir)
|
|
29
|
+
base.mkdir(parents=True, exist_ok=True)
|
|
30
|
+
_FILE = base / "backend-profiles.json"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _file():
|
|
34
|
+
global _FILE
|
|
35
|
+
if _FILE is None:
|
|
36
|
+
init()
|
|
37
|
+
return _FILE
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _load():
|
|
41
|
+
path = _file()
|
|
42
|
+
try:
|
|
43
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
44
|
+
except FileNotFoundError:
|
|
45
|
+
return []
|
|
46
|
+
except (OSError, ValueError) as exc:
|
|
47
|
+
raise ValueError("ACP 后端配置不可读取,已阻止覆盖") from exc
|
|
48
|
+
profiles = data.get("profiles") if isinstance(data, dict) else None
|
|
49
|
+
if not isinstance(profiles, list):
|
|
50
|
+
raise ValueError("ACP 后端配置格式无效")
|
|
51
|
+
return [row for row in profiles if isinstance(row, dict)][:50]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _persist(profiles):
|
|
55
|
+
path = _file()
|
|
56
|
+
tmp = path.with_name(path.name + ".tmp")
|
|
57
|
+
tmp.write_text(json.dumps({"profiles": profiles}, ensure_ascii=False, indent=2),
|
|
58
|
+
encoding="utf-8")
|
|
59
|
+
try:
|
|
60
|
+
os.chmod(str(tmp), 0o600)
|
|
61
|
+
except OSError:
|
|
62
|
+
pass
|
|
63
|
+
os.replace(str(tmp), str(path))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _valid_workspace_path(value):
|
|
67
|
+
value = str(value or "").strip()
|
|
68
|
+
if not value:
|
|
69
|
+
return ""
|
|
70
|
+
if "\x00" in value or len(value) > 1024:
|
|
71
|
+
raise ValueError("workspace_path 无效")
|
|
72
|
+
if not (value.startswith("/") or value.startswith("\\") or
|
|
73
|
+
re.match(r"^[A-Za-z]:[\\/]", value)):
|
|
74
|
+
raise ValueError("workspace_path 必须是绝对路径")
|
|
75
|
+
return value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _normalize(payload, existing=None):
|
|
79
|
+
if not isinstance(payload, dict):
|
|
80
|
+
raise ValueError("profile 必须是 JSON 对象")
|
|
81
|
+
old = existing or {}
|
|
82
|
+
profile_id = str(payload.get("id") or old.get("id") or
|
|
83
|
+
("backend-" + uuid.uuid4().hex[:16])).strip()
|
|
84
|
+
if not _PROFILE_ID.fullmatch(profile_id):
|
|
85
|
+
raise ValueError("profile id 格式无效")
|
|
86
|
+
label = str(payload.get("label") or "").strip()
|
|
87
|
+
command = str(payload.get("command") or "").strip()
|
|
88
|
+
if not label or len(label) > 80:
|
|
89
|
+
raise ValueError("label 必填且不能超过 80 个字符")
|
|
90
|
+
if not command or len(command) > 500 or "\x00" in command:
|
|
91
|
+
raise ValueError("command 必填且格式无效")
|
|
92
|
+
raw_args = payload.get("args", old.get("args", []))
|
|
93
|
+
if not isinstance(raw_args, list) or len(raw_args) > 80:
|
|
94
|
+
raise ValueError("args 必须是最多 80 项的列表")
|
|
95
|
+
args = []
|
|
96
|
+
for value in raw_args:
|
|
97
|
+
if not isinstance(value, str) or len(value) > 2048 or "\x00" in value:
|
|
98
|
+
raise ValueError("args 只能包含不超过 2048 字符的文本")
|
|
99
|
+
args.append(value)
|
|
100
|
+
raw_env = payload.get("env", old.get("env", {}))
|
|
101
|
+
if not isinstance(raw_env, dict) or len(raw_env) > 100:
|
|
102
|
+
raise ValueError("env 必须是最多 100 项的对象")
|
|
103
|
+
env = {}
|
|
104
|
+
old_env = old.get("env") or {}
|
|
105
|
+
for name, value in raw_env.items():
|
|
106
|
+
name = str(name)
|
|
107
|
+
if not _ENV_NAME.fullmatch(name) or not isinstance(value, str) \
|
|
108
|
+
or len(value) > 8192 or "\x00" in value:
|
|
109
|
+
raise ValueError("env 变量名或值无效")
|
|
110
|
+
if value == "__REDACTED__" and name in old_env:
|
|
111
|
+
value = old_env[name]
|
|
112
|
+
env[name] = value
|
|
113
|
+
enabled = payload.get("enabled", old.get("enabled", True))
|
|
114
|
+
if not isinstance(enabled, bool):
|
|
115
|
+
raise ValueError("enabled 必须是布尔值")
|
|
116
|
+
return {"id": profile_id, "agent_id": "acp-" + profile_id,
|
|
117
|
+
"label": label, "command": command, "args": args,
|
|
118
|
+
"env": env, "workspace_path": _valid_workspace_path(
|
|
119
|
+
payload.get("workspace_path", old.get("workspace_path", ""))),
|
|
120
|
+
"enabled": enabled}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _view(profile):
|
|
124
|
+
row = dict(profile)
|
|
125
|
+
row["command"] = scrub_text(profile.get("command") or "", 500)
|
|
126
|
+
row["args"] = [scrub_text(value, 2048) for value in profile.get("args") or []]
|
|
127
|
+
env = {}
|
|
128
|
+
for name, value in (profile.get("env") or {}).items():
|
|
129
|
+
env[name] = "__REDACTED__" if _SECRET_NAME.search(name) and value else value
|
|
130
|
+
row["env"] = env
|
|
131
|
+
return row
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def list_profiles():
|
|
135
|
+
with _LOCK:
|
|
136
|
+
return [_view(row) for row in _load()]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def runtime_profiles():
|
|
140
|
+
with _LOCK:
|
|
141
|
+
return [dict(row, env=dict(row.get("env") or {})) for row in _load()
|
|
142
|
+
if row.get("enabled", True)]
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def get_runtime(profile_id):
|
|
146
|
+
with _LOCK:
|
|
147
|
+
return next((dict(row, env=dict(row.get("env") or {}))
|
|
148
|
+
for row in _load() if row.get("id") == str(profile_id or "")
|
|
149
|
+
and row.get("enabled", True)), None)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def runtime_agents():
|
|
153
|
+
return [{"id": row["agent_id"], "profile_id": row["id"],
|
|
154
|
+
"label": row["label"], "kind": "acp", "mode": "real",
|
|
155
|
+
"command": row["command"], "args": list(row["args"]),
|
|
156
|
+
"env": {}, "workspace_path": row["workspace_path"],
|
|
157
|
+
"profile_managed": True}
|
|
158
|
+
for row in runtime_profiles()]
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def save(payload):
|
|
162
|
+
with _LOCK:
|
|
163
|
+
profiles = _load()
|
|
164
|
+
requested_id = str((payload or {}).get("id") or "")
|
|
165
|
+
old = next((row for row in profiles if row.get("id") == requested_id), None)
|
|
166
|
+
if requested_id and old is None:
|
|
167
|
+
raise KeyError("ACP 后端配置不存在")
|
|
168
|
+
profile = _normalize(payload, old)
|
|
169
|
+
if any(row.get("id") == profile["id"] and row is not old for row in profiles):
|
|
170
|
+
raise ValueError("profile id 已存在")
|
|
171
|
+
if old is None and len(profiles) >= 50:
|
|
172
|
+
raise ValueError("ACP 后端最多配置 50 个")
|
|
173
|
+
if old is None:
|
|
174
|
+
profiles.append(profile)
|
|
175
|
+
else:
|
|
176
|
+
profiles[profiles.index(old)] = profile
|
|
177
|
+
_persist(profiles)
|
|
178
|
+
return _view(profile)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def remove(profile_id):
|
|
182
|
+
with _LOCK:
|
|
183
|
+
profiles = _load()
|
|
184
|
+
remaining = [row for row in profiles if row.get("id") != str(profile_id or "")]
|
|
185
|
+
if len(remaining) == len(profiles):
|
|
186
|
+
raise KeyError("ACP 后端配置不存在")
|
|
187
|
+
_persist(remaining)
|
|
188
|
+
return True
|