codebee 0.1.68 → 0.1.70
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 +580 -543
- package/LICENSE +21 -21
- package/README.md +11 -0
- package/app/browser-final-1440.png +0 -0
- package/app/browser-final-390.png +0 -0
- package/app/browser-google-fallback.png +0 -0
- package/app/browser-google-test.png +0 -0
- package/app/browser-workbench-1440.png +0 -0
- package/app/browser-workbench-390.png +0 -0
- package/app/browser-workspace-google.png +0 -0
- package/app/browser-workspace-smoke.png +0 -0
- package/app/browser-workspace.png +0 -0
- package/app/core/acceptance.py +100 -100
- package/app/core/aiflavor.py +197 -197
- 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 -0
- package/app/core/automation.py +853 -758
- package/app/core/backup.py +470 -470
- package/app/core/beekeeper.py +183 -183
- package/app/core/benchstore.py +95 -0
- package/app/core/board.py +209 -209
- package/app/core/bookmeta.py +935 -930
- package/app/core/bookmeta_catalog.py +180 -180
- package/app/core/branching.py +137 -137
- package/app/core/builtin_agent.py +1673 -1234
- package/app/core/capability.py +144 -144
- package/app/core/catalog.py +7 -1
- package/app/core/chaptersafe.py +32 -32
- package/app/core/cleanup.py +303 -303
- package/app/core/compaction.py +201 -201
- 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.py +190 -173
- package/app/core/dispatch_log.py +128 -128
- package/app/core/env_scrub.py +85 -85
- package/app/core/error_codes.py +33 -24
- package/app/core/errorlog.py +137 -137
- package/app/core/evalbench.py +720 -0
- package/app/core/evaluation.py +174 -174
- package/app/core/failure_notify.py +290 -290
- package/app/core/flows.py +228 -3
- package/app/core/goal_service.py +167 -167
- package/app/core/health.py +374 -374
- package/app/core/history.py +38 -38
- package/app/core/hooks.py +162 -162
- package/app/core/jobs.py +51 -30
- package/app/core/manager.py +2143 -2122
- package/app/core/market.py +362 -362
- package/app/core/market_remote.py +10 -0
- package/app/core/mcp_client.py +287 -0
- package/app/core/mocks.py +64 -64
- package/app/core/modelhub.py +193 -10
- package/app/core/notify.py +201 -106
- package/app/core/novel_quality.py +189 -0
- package/app/core/operations.py +228 -228
- package/app/core/paihang.py +138 -138
- package/app/core/paths.py +6 -2
- package/app/core/pipeline.py +426 -28
- package/app/core/planner.py +243 -22
- package/app/core/plugins.py +525 -0
- package/app/core/portguard.py +111 -111
- package/app/core/preview.py +293 -293
- package/app/core/publish/__init__.py +7 -7
- package/app/core/publish/auto.py +367 -367
- package/app/core/publish/browser.py +655 -539
- package/app/core/publish/fanqie.py +165 -159
- package/app/core/publish/flow.py +589 -440
- package/app/core/publish/flows-fanqie-calibrated.json +336 -332
- package/app/core/publish/ledger.py +229 -203
- package/app/core/publish/manager.py +824 -692
- package/app/core/publish/qimao.py +146 -141
- package/app/core/publish/ws.py +139 -139
- package/app/core/redact.py +38 -38
- package/app/core/remotesync.py +121 -0
- package/app/core/repeat_guard.py +129 -129
- package/app/core/router.py +398 -398
- package/app/core/runner.py +2142 -2067
- 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 +186 -149
- package/app/core/settings_schema.py +270 -262
- package/app/core/share_page.py +114 -114
- package/app/core/skill_scan.py +122 -122
- package/app/core/skillpacks/fanqie-novel.md +80 -80
- 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/store.py +104 -82
- 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/tracing.py +144 -144
- package/app/core/upstream.py +41 -41
- package/app/core/usage.py +1035 -862
- package/app/core/volumes.py +389 -389
- package/app/core/wxdigest.py +858 -858
- package/app/core/zentao.py +2614 -2465
- package/app/current-browser.png +0 -0
- package/app/main.py +3245 -2981
- package/app/mcp_server.py +175 -0
- package/app/pet.py +82 -21
- package/app/pick_dialog.py +110 -110
- package/app/plugins/code-review-helper/.codex-plugin/plugin.json +18 -0
- package/app/plugins/code-review-helper/skills/review.md +16 -0
- package/app/ui/app.js +15706 -14399
- package/app/ui/artdiff.js +74 -74
- package/app/ui/board.html +162 -162
- package/app/ui/board.js +305 -305
- package/app/ui/i18n.js +3012 -2770
- package/app/ui/icons/bee.svg +79 -79
- package/app/ui/index.html +277 -13
- package/app/ui/manifest.json +16 -16
- package/app/ui/qrcode.js +2297 -2297
- package/app/ui/style.css +802 -16
- package/bin/tutti.js +147 -147
- package/package.json +47 -46
- 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
|
@@ -1039,6 +1039,15 @@ def preview_remote(entry_id):
|
|
|
1039
1039
|
_PREVIEW_CACHE[token] = {"entry_id": entry_id, "files": files,
|
|
1040
1040
|
"stripped": stripped, "ts": time.time()}
|
|
1041
1041
|
file_list = sorted(files.items(), key=lambda kv: kv[0])
|
|
1042
|
+
# 内容安检(ClawHavoc 投毒案借鉴):对全部技能文本跑危险模式扫描,
|
|
1043
|
+
# 风险随预览返回——UI 高风险红字确认;发现列表给行号可定位。
|
|
1044
|
+
try:
|
|
1045
|
+
from . import skill_scan
|
|
1046
|
+
risk_findings = skill_scan.scan_text(
|
|
1047
|
+
"\n".join(str(v) for v in files.values()))
|
|
1048
|
+
risk_label = skill_scan.risk_label(risk_findings)
|
|
1049
|
+
except Exception:
|
|
1050
|
+
risk_findings, risk_label = [], ""
|
|
1042
1051
|
return {
|
|
1043
1052
|
"token": token, "id": entry_id, "title": entry["title"],
|
|
1044
1053
|
"source": entry["source_name"], "version": entry["version"],
|
|
@@ -1048,6 +1057,7 @@ def preview_remote(entry_id):
|
|
|
1048
1057
|
"total_chars": sum(len(v) for v in files.values()),
|
|
1049
1058
|
"file_list": [{"path": k, "chars": len(v)} for k, v in file_list[:60]],
|
|
1050
1059
|
"stripped": sorted(stripped)[:40], "stripped_total": len(stripped),
|
|
1060
|
+
"risk_label": risk_label, "risk_findings": risk_findings[:8],
|
|
1051
1061
|
"expires_in": _PREVIEW_TTL,
|
|
1052
1062
|
}, None
|
|
1053
1063
|
except ValueError as e:
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""内置智能体的 MCP 客户端(Model Context Protocol,stdio 形态)。
|
|
3
|
+
|
|
4
|
+
零依赖:JSON-RPC 2.0 走子进程 stdin/stdout(按行分帧——MCP stdio 传输约定)。
|
|
5
|
+
每次工具调用重新拉起服务器进程:没有长驻会话要管,冷启动成本对内置智能体
|
|
6
|
+
的低频工具循环可接受;进程用完即关(finally 杀树),绝不留孤儿。
|
|
7
|
+
|
|
8
|
+
配置(settings.mcp_servers,JSON 数组字符串,≤4 个服务器):
|
|
9
|
+
[{"name": "fs", "command": "npx", "args": ["-y", "@modelcontextprotocol/server-fs", "C:/x"],
|
|
10
|
+
"env": {"KEY": "v"}}]
|
|
11
|
+
name 用于工具名前缀(mcp__<name>__<tool>),必须 [a-z0-9_-]。
|
|
12
|
+
|
|
13
|
+
安全口径:服务器命令是用户在本机自己配置的(与内置智能体 run_command 同一
|
|
14
|
+
自主权级别);本模块只做传输与解析,不校验工具语义。工具清单按服务器缓存
|
|
15
|
+
(TTL 300s)——每次对话请求重建 tools 列表时不能每次都冷启动全量服务器。
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import re
|
|
22
|
+
import subprocess
|
|
23
|
+
import threading
|
|
24
|
+
import time
|
|
25
|
+
|
|
26
|
+
_LOCK = threading.RLock()
|
|
27
|
+
_TOOLS_CACHE = {} # server_key → (ts, tools)
|
|
28
|
+
_TOOLS_TTL = 300.0
|
|
29
|
+
|
|
30
|
+
MAX_SERVERS = 4
|
|
31
|
+
MAX_MCP_TOOLS = 24 # 全部服务器合计注入内置智能体的工具数上限
|
|
32
|
+
_NAME_RE = re.compile(r"^[a-z0-9_-]{1,24}$")
|
|
33
|
+
_INIT_TIMEOUT = 15.0
|
|
34
|
+
_CALL_TIMEOUT = 60.0
|
|
35
|
+
_CALL_TIMEOUT_MAX = 300.0
|
|
36
|
+
|
|
37
|
+
_CLIENT_INFO = {"name": "CodeBee", "version": "1.0"}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def invalidate_tools_cache():
|
|
41
|
+
"""服务器配置变化后丢弃已发现工具(插件启停等场景调用)。"""
|
|
42
|
+
with _LOCK:
|
|
43
|
+
_TOOLS_CACHE.clear()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def parse_servers(text):
|
|
47
|
+
"""settings.mcp_servers 文本 → 校验后的服务器配置列表。返回 (servers, 错误)。"""
|
|
48
|
+
raw = str(text or "").strip()
|
|
49
|
+
if not raw:
|
|
50
|
+
return [], None
|
|
51
|
+
try:
|
|
52
|
+
arr = json.loads(raw)
|
|
53
|
+
except Exception:
|
|
54
|
+
return None, "mcp_servers 不是合法 JSON"
|
|
55
|
+
if not isinstance(arr, list):
|
|
56
|
+
return None, "mcp_servers 必须是数组"
|
|
57
|
+
if len(arr) > MAX_SERVERS:
|
|
58
|
+
return None, "最多 %d 个 MCP 服务器" % MAX_SERVERS
|
|
59
|
+
out = []
|
|
60
|
+
for item in arr:
|
|
61
|
+
if not isinstance(item, dict):
|
|
62
|
+
return None, "MCP 服务器配置必须是对象"
|
|
63
|
+
name = str(item.get("name") or "").strip()
|
|
64
|
+
command = str(item.get("command") or "").strip()
|
|
65
|
+
if not _NAME_RE.match(name):
|
|
66
|
+
return None, "服务器名 %r 只能是小写字母/数字/-/_(≤24 位)" % name[:24]
|
|
67
|
+
if not command:
|
|
68
|
+
return None, "服务器 %s 缺 command" % name
|
|
69
|
+
args = item.get("args") if isinstance(item.get("args"), list) else []
|
|
70
|
+
args = [str(a) for a in args][:16]
|
|
71
|
+
env = item.get("env") if isinstance(item.get("env"), dict) else {}
|
|
72
|
+
env = {str(k): str(v) for k, v in list(env.items())[:16]}
|
|
73
|
+
out.append({"name": name, "command": command, "args": args, "env": env})
|
|
74
|
+
return out, None
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class _Session:
|
|
78
|
+
"""一次性的 MCP 服务器会话:spawn → initialize → (list/call)→ 杀树。"""
|
|
79
|
+
|
|
80
|
+
def __init__(self, server):
|
|
81
|
+
self.server = server
|
|
82
|
+
self.proc = None
|
|
83
|
+
self.lines = None # reader 线程产出的行队列
|
|
84
|
+
self.err = None
|
|
85
|
+
|
|
86
|
+
def _pump_err(self):
|
|
87
|
+
try:
|
|
88
|
+
for _ in self.proc.stderr:
|
|
89
|
+
pass
|
|
90
|
+
except Exception:
|
|
91
|
+
pass
|
|
92
|
+
|
|
93
|
+
def _pump_out(self):
|
|
94
|
+
try:
|
|
95
|
+
for raw in self.proc.stdout:
|
|
96
|
+
self.lines.put(raw.decode("utf-8", errors="replace").rstrip("\r\n"))
|
|
97
|
+
except Exception:
|
|
98
|
+
pass
|
|
99
|
+
finally:
|
|
100
|
+
self.lines.put(None) # EOF 哨兵
|
|
101
|
+
|
|
102
|
+
def __enter__(self):
|
|
103
|
+
try:
|
|
104
|
+
self.proc = subprocess.Popen(
|
|
105
|
+
[self.server["command"]] + list(self.server.get("args") or []),
|
|
106
|
+
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
107
|
+
stderr=subprocess.PIPE, text=False,
|
|
108
|
+
env={**os.environ, **(self.server.get("env") or {})})
|
|
109
|
+
except Exception as e:
|
|
110
|
+
raise RuntimeError("MCP 服务器启动失败: %s" % e)
|
|
111
|
+
import queue as _queue
|
|
112
|
+
self.lines = _queue.Queue()
|
|
113
|
+
threading.Thread(target=self._pump_out, daemon=True).start()
|
|
114
|
+
threading.Thread(target=self._pump_err, daemon=True).start()
|
|
115
|
+
self._request("initialize", {
|
|
116
|
+
"protocolVersion": "2024-11-05", "capabilities": {},
|
|
117
|
+
"clientInfo": _CLIENT_INFO}, timeout=_INIT_TIMEOUT)
|
|
118
|
+
self._notify("notifications/initialized")
|
|
119
|
+
return self
|
|
120
|
+
|
|
121
|
+
def __exit__(self, *exc):
|
|
122
|
+
try:
|
|
123
|
+
if self.proc and self.proc.stdin:
|
|
124
|
+
try:
|
|
125
|
+
self.proc.stdin.close()
|
|
126
|
+
except Exception:
|
|
127
|
+
pass
|
|
128
|
+
finally:
|
|
129
|
+
try:
|
|
130
|
+
if self.proc:
|
|
131
|
+
self.proc.kill()
|
|
132
|
+
except Exception:
|
|
133
|
+
pass
|
|
134
|
+
return False
|
|
135
|
+
|
|
136
|
+
def _send(self, obj):
|
|
137
|
+
data = json.dumps(obj, ensure_ascii=False).encode("utf-8") + b"\n"
|
|
138
|
+
self.proc.stdin.write(data)
|
|
139
|
+
self.proc.stdin.flush()
|
|
140
|
+
|
|
141
|
+
def _notify(self, method, params=None):
|
|
142
|
+
self._send({"jsonrpc": "2.0", "method": method, "params": params or {}})
|
|
143
|
+
|
|
144
|
+
def _request(self, method, params, timeout):
|
|
145
|
+
"""单请求单响应;忽略通知与未知 id 的服务端请求。"""
|
|
146
|
+
rid = id({})
|
|
147
|
+
self._send({"jsonrpc": "2.0", "id": 1 if method == "initialize" else rid,
|
|
148
|
+
"method": method, "params": params or {}})
|
|
149
|
+
deadline = time.time() + max(1.0, timeout)
|
|
150
|
+
while True:
|
|
151
|
+
remain = deadline - time.time()
|
|
152
|
+
if remain <= 0:
|
|
153
|
+
raise RuntimeError("%s 超时(%.0fs)" % (method, timeout))
|
|
154
|
+
try:
|
|
155
|
+
line = self.lines.get(timeout=remain)
|
|
156
|
+
except Exception:
|
|
157
|
+
raise RuntimeError("%s 超时(%.0fs)" % (method, timeout))
|
|
158
|
+
if line is None:
|
|
159
|
+
raise RuntimeError("MCP 服务器提前退出")
|
|
160
|
+
line = line.strip()
|
|
161
|
+
if not line.startswith("{"):
|
|
162
|
+
continue
|
|
163
|
+
try:
|
|
164
|
+
msg = json.loads(line)
|
|
165
|
+
except Exception:
|
|
166
|
+
continue
|
|
167
|
+
if not isinstance(msg, dict) or msg.get("id") is None:
|
|
168
|
+
continue # 通知/服务端请求:不匹配本调用
|
|
169
|
+
if msg.get("id") != (1 if method == "initialize" else rid):
|
|
170
|
+
continue
|
|
171
|
+
if msg.get("error"):
|
|
172
|
+
raise RuntimeError("MCP %s 失败: %s" % (
|
|
173
|
+
method, json.dumps(msg["error"], ensure_ascii=False)[:200]))
|
|
174
|
+
return msg.get("result") or {}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def list_tools(server):
|
|
178
|
+
"""发现服务器工具。返回 {"ok", "tools":[{"name","description","input_schema"}], "error"}。"""
|
|
179
|
+
try:
|
|
180
|
+
with _Session(server) as sess:
|
|
181
|
+
res = sess._request("tools/list", {}, timeout=_INIT_TIMEOUT)
|
|
182
|
+
tools = []
|
|
183
|
+
for t in (res.get("tools") or [])[:16]:
|
|
184
|
+
if isinstance(t, dict) and isinstance(t.get("name"), str) and t["name"]:
|
|
185
|
+
tools.append({"name": t["name"],
|
|
186
|
+
"description": str(t.get("description") or "")[:400],
|
|
187
|
+
"input_schema": t.get("input_schema")
|
|
188
|
+
if isinstance(t.get("input_schema"), dict) else
|
|
189
|
+
{"type": "object", "properties": {}}})
|
|
190
|
+
return {"ok": True, "tools": tools, "error": ""}
|
|
191
|
+
except Exception as e:
|
|
192
|
+
return {"ok": False, "tools": [], "error": str(e)[:200]}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def call_tool(server, tool_name, arguments, timeout_s=_CALL_TIMEOUT):
|
|
196
|
+
"""调用一个工具。返回 {"ok", "text", "error", "is_error"}。"""
|
|
197
|
+
try:
|
|
198
|
+
timeout = min(_CALL_TIMEOUT_MAX, max(5.0, float(timeout_s or _CALL_TIMEOUT)))
|
|
199
|
+
with _Session(server) as sess:
|
|
200
|
+
res = sess._request("tools/call",
|
|
201
|
+
{"name": tool_name,
|
|
202
|
+
"arguments": arguments if isinstance(arguments, dict) else {}},
|
|
203
|
+
timeout=timeout)
|
|
204
|
+
parts = []
|
|
205
|
+
for c in res.get("content") or []:
|
|
206
|
+
if isinstance(c, dict) and c.get("type") == "text" and c.get("text"):
|
|
207
|
+
parts.append(str(c["text"]))
|
|
208
|
+
text = "\n".join(parts)[:20000]
|
|
209
|
+
is_err = bool(res.get("isError"))
|
|
210
|
+
return {"ok": bool(text) and not is_err, "text": text,
|
|
211
|
+
"error": "" if not is_err else (text or "工具返回 isError"),
|
|
212
|
+
"is_error": is_err}
|
|
213
|
+
except Exception as e:
|
|
214
|
+
return {"ok": False, "text": "", "error": str(e)[:200], "is_error": False}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
# ---- 面向 builtin_agent 的合并视图(带缓存) ----
|
|
218
|
+
|
|
219
|
+
def tool_specs_cached(force=False):
|
|
220
|
+
"""全部服务器的工具合并清单:[{server, name(原名), full_name, description,
|
|
221
|
+
input_schema}]。TTL 内走缓存;单个服务器失败跳过(error 挂在条目外不打断)。"""
|
|
222
|
+
with _LOCK:
|
|
223
|
+
if not force:
|
|
224
|
+
hit = True
|
|
225
|
+
for key, (ts, _t) in _TOOLS_CACHE.items():
|
|
226
|
+
if time.time() - ts > _TOOLS_TTL:
|
|
227
|
+
hit = False
|
|
228
|
+
break
|
|
229
|
+
if hit and _TOOLS_CACHE:
|
|
230
|
+
out = []
|
|
231
|
+
for _key, (_ts, tools) in _TOOLS_CACHE.items():
|
|
232
|
+
out.extend(tools)
|
|
233
|
+
return out[:MAX_MCP_TOOLS]
|
|
234
|
+
servers, err = parse_servers(_settings_text())
|
|
235
|
+
if err or not servers:
|
|
236
|
+
return []
|
|
237
|
+
out = []
|
|
238
|
+
with _LOCK:
|
|
239
|
+
_TOOLS_CACHE.clear()
|
|
240
|
+
for srv in servers:
|
|
241
|
+
res = list_tools(srv)
|
|
242
|
+
if not res.get("ok"):
|
|
243
|
+
continue
|
|
244
|
+
specs = []
|
|
245
|
+
for t in res["tools"]:
|
|
246
|
+
specs.append({"server": srv["name"], "name": t["name"],
|
|
247
|
+
"full_name": "mcp__%s__%s" % (srv["name"], t["name"]),
|
|
248
|
+
"description": t["description"],
|
|
249
|
+
"input_schema": t["input_schema"]})
|
|
250
|
+
with _LOCK:
|
|
251
|
+
_TOOLS_CACHE[srv["name"]] = (time.time(), specs)
|
|
252
|
+
out.extend(specs)
|
|
253
|
+
if len(out) >= MAX_MCP_TOOLS:
|
|
254
|
+
break
|
|
255
|
+
return out[:MAX_MCP_TOOLS]
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def dispatch_full_name(full_name, arguments, timeout_s=_CALL_TIMEOUT):
|
|
259
|
+
"""mcp__<server>__<tool> → 找服务器配置并调用。返回 {"ok","text","error"}。"""
|
|
260
|
+
m = re.match(r"^mcp__([a-z0-9_-]{1,24})__(.+)$", str(full_name or ""))
|
|
261
|
+
if not m:
|
|
262
|
+
return {"ok": False, "text": "", "error": "非法 MCP 工具名"}
|
|
263
|
+
sname, tool = m.group(1), m.group(2)
|
|
264
|
+
servers, err = parse_servers(_settings_text())
|
|
265
|
+
if err:
|
|
266
|
+
return {"ok": False, "text": "", "error": err}
|
|
267
|
+
srv = next((s for s in servers if s["name"] == sname), None)
|
|
268
|
+
if not srv:
|
|
269
|
+
return {"ok": False, "text": "", "error": "MCP 服务器 %s 未配置" % sname}
|
|
270
|
+
return call_tool(srv, tool, arguments, timeout_s=timeout_s)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
_SETTINGS_TEXT = None # main.py 启动注入(读 settings.mcp_servers)——本模块
|
|
274
|
+
# 不直接依赖 settings(L0),静态图保持干净(同 set_run_estimator 模式)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def set_settings_text(fn):
|
|
278
|
+
"""注入 MCP 服务器清单读取器;未注入时工具清单为空(MCP 功能关闭)。"""
|
|
279
|
+
global _SETTINGS_TEXT
|
|
280
|
+
_SETTINGS_TEXT = fn if callable(fn) else None
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _settings_text():
|
|
284
|
+
try:
|
|
285
|
+
return str(_SETTINGS_TEXT() or "") if _SETTINGS_TEXT else ""
|
|
286
|
+
except Exception:
|
|
287
|
+
return ""
|
package/app/core/mocks.py
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""内置演示/测试智能体(mock):不消耗任何配额即可跑通全流程。"""
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import hashlib
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def _seed(agent_id):
|
|
9
|
-
return int(hashlib.sha256(agent_id.encode("utf-8")).hexdigest()[:6], 16)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def draft_manuscript(task, round_no):
|
|
13
|
-
"""生成一份示例稿件(mock 起草/修订直接落盘的内容)。"""
|
|
14
|
-
title = task.get("title") or "未命名章节"
|
|
15
|
-
goal = task.get("goal") or ""
|
|
16
|
-
return (
|
|
17
|
-
"# {title}\n\n"
|
|
18
|
-
"这是第 {r} 轮 mock 草稿(演示用,不消耗模型配额)。\n\n"
|
|
19
|
-
"## 任务目标\n{goal}\n\n"
|
|
20
|
-
"## 正文\n"
|
|
21
|
-
"夜色沿着山脊线缓慢退去,主角终于看清了石门上的刻痕——那不是文字,"
|
|
22
|
-
"而是一段被反复涂抹又反复显影的名字。他伸手触碰的瞬间,耳边响起的"
|
|
23
|
-
"却是自己昨夜说过的话。{extra}\n\n"
|
|
24
|
-
"(本轮修订关注:{focus})\n"
|
|
25
|
-
).format(
|
|
26
|
-
title=title, r=round_no, goal=goal,
|
|
27
|
-
extra="这一段在第 2 轮修订中补充了人物动机的伏笔。" if round_no >= 2 else "",
|
|
28
|
-
focus="节奏与悬念铺排" if round_no == 1 else "人物弧光与首尾呼应",
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def implement_note(task):
|
|
33
|
-
return "(mock 实现)已在目标目录写入 mock-impl.txt 作为变更占位。"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def critique(agent_id, round_no, dims, threshold):
|
|
37
|
-
"""确定性评分:第 1 轮略低于阈值,第 2 轮达标,用于验证发布门禁逻辑。"""
|
|
38
|
-
s = _seed(agent_id)
|
|
39
|
-
scores = {}
|
|
40
|
-
for i, d in enumerate(dims):
|
|
41
|
-
jitter = ((s >> i) % 5) * 0.1
|
|
42
|
-
scores[d] = round(min(9.5, 4.8 + 1.2 * round_no + jitter), 1)
|
|
43
|
-
passed = all(v >= threshold for v in scores.values())
|
|
44
|
-
issues = []
|
|
45
|
-
if round_no == 1:
|
|
46
|
-
issues = [
|
|
47
|
-
{"dim": dims[0], "severity": "major", "note": "开篇信息密度偏低,钩子出现太晚(mock 意见)"},
|
|
48
|
-
{"dim": dims[-1], "severity": "minor", "note": "段落长短交替不够,读感偏平(mock 意见)"},
|
|
49
|
-
]
|
|
50
|
-
return {
|
|
51
|
-
"scores": scores,
|
|
52
|
-
"issues": issues,
|
|
53
|
-
"summary": "mock 总评:第 %d 轮稿件%s发布阈值" % (round_no, "已达到" if passed else "尚未达到"),
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def review(task, verify_passed):
|
|
58
|
-
return {
|
|
59
|
-
"pass": bool(verify_passed),
|
|
60
|
-
"scores": {"正确性": 8.0 if verify_passed else 5.0, "可维护性": 8.0, "安全": 8.5},
|
|
61
|
-
"issues": [] if verify_passed else [
|
|
62
|
-
{"severity": "major", "title": "验证命令未通过", "detail": "请检查测试输出(mock 意见)"}],
|
|
63
|
-
"summary": "mock 代码评审:%s" % ("通过" if verify_passed else "未通过"),
|
|
64
|
-
}
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""内置演示/测试智能体(mock):不消耗任何配额即可跑通全流程。"""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _seed(agent_id):
|
|
9
|
+
return int(hashlib.sha256(agent_id.encode("utf-8")).hexdigest()[:6], 16)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def draft_manuscript(task, round_no):
|
|
13
|
+
"""生成一份示例稿件(mock 起草/修订直接落盘的内容)。"""
|
|
14
|
+
title = task.get("title") or "未命名章节"
|
|
15
|
+
goal = task.get("goal") or ""
|
|
16
|
+
return (
|
|
17
|
+
"# {title}\n\n"
|
|
18
|
+
"这是第 {r} 轮 mock 草稿(演示用,不消耗模型配额)。\n\n"
|
|
19
|
+
"## 任务目标\n{goal}\n\n"
|
|
20
|
+
"## 正文\n"
|
|
21
|
+
"夜色沿着山脊线缓慢退去,主角终于看清了石门上的刻痕——那不是文字,"
|
|
22
|
+
"而是一段被反复涂抹又反复显影的名字。他伸手触碰的瞬间,耳边响起的"
|
|
23
|
+
"却是自己昨夜说过的话。{extra}\n\n"
|
|
24
|
+
"(本轮修订关注:{focus})\n"
|
|
25
|
+
).format(
|
|
26
|
+
title=title, r=round_no, goal=goal,
|
|
27
|
+
extra="这一段在第 2 轮修订中补充了人物动机的伏笔。" if round_no >= 2 else "",
|
|
28
|
+
focus="节奏与悬念铺排" if round_no == 1 else "人物弧光与首尾呼应",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def implement_note(task):
|
|
33
|
+
return "(mock 实现)已在目标目录写入 mock-impl.txt 作为变更占位。"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def critique(agent_id, round_no, dims, threshold):
|
|
37
|
+
"""确定性评分:第 1 轮略低于阈值,第 2 轮达标,用于验证发布门禁逻辑。"""
|
|
38
|
+
s = _seed(agent_id)
|
|
39
|
+
scores = {}
|
|
40
|
+
for i, d in enumerate(dims):
|
|
41
|
+
jitter = ((s >> i) % 5) * 0.1
|
|
42
|
+
scores[d] = round(min(9.5, 4.8 + 1.2 * round_no + jitter), 1)
|
|
43
|
+
passed = all(v >= threshold for v in scores.values())
|
|
44
|
+
issues = []
|
|
45
|
+
if round_no == 1:
|
|
46
|
+
issues = [
|
|
47
|
+
{"dim": dims[0], "severity": "major", "note": "开篇信息密度偏低,钩子出现太晚(mock 意见)"},
|
|
48
|
+
{"dim": dims[-1], "severity": "minor", "note": "段落长短交替不够,读感偏平(mock 意见)"},
|
|
49
|
+
]
|
|
50
|
+
return {
|
|
51
|
+
"scores": scores,
|
|
52
|
+
"issues": issues,
|
|
53
|
+
"summary": "mock 总评:第 %d 轮稿件%s发布阈值" % (round_no, "已达到" if passed else "尚未达到"),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def review(task, verify_passed):
|
|
58
|
+
return {
|
|
59
|
+
"pass": bool(verify_passed),
|
|
60
|
+
"scores": {"正确性": 8.0 if verify_passed else 5.0, "可维护性": 8.0, "安全": 8.5},
|
|
61
|
+
"issues": [] if verify_passed else [
|
|
62
|
+
{"severity": "major", "title": "验证命令未通过", "detail": "请检查测试输出(mock 意见)"}],
|
|
63
|
+
"summary": "mock 代码评审:%s" % ("通过" if verify_passed else "未通过"),
|
|
64
|
+
}
|