codebee 0.1.76 → 0.1.77

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +628 -624
  2. package/LICENSE +21 -21
  3. package/README.md +507 -509
  4. package/app/.playwright-cli/console-2026-09-23T08-26-03-635Z.log +88 -0
  5. package/app/.playwright-cli/page-2026-09-23T08-26-03-845Z.yml +126 -0
  6. package/app/.playwright-cli/page-2026-09-23T08-29-44-203Z.png +0 -0
  7. package/app/.playwright-cli/page-2026-09-23T08-35-42-046Z.yml +210 -0
  8. package/app/.playwright-cli/page-2026-09-23T08-36-52-858Z.png +0 -0
  9. package/app/.playwright-cli/page-2026-09-23T08-37-33-938Z.png +0 -0
  10. package/app/.playwright-cli/run-detail-after.png +0 -0
  11. package/app/core/acceptance.py +100 -100
  12. package/app/core/aiflavor.py +197 -197
  13. package/app/core/analytics.py +38 -38
  14. package/app/core/artifacts.py +148 -148
  15. package/app/core/assets.py +110 -110
  16. package/app/core/attachments.py +623 -623
  17. package/app/core/audit.py +30 -30
  18. package/app/core/backup.py +470 -470
  19. package/app/core/beekeeper.py +183 -183
  20. package/app/core/benchstore.py +95 -95
  21. package/app/core/board.py +209 -209
  22. package/app/core/bookmeta.py +1036 -1036
  23. package/app/core/bookmeta_catalog.py +180 -180
  24. package/app/core/branching.py +137 -137
  25. package/app/core/builtin_agent.py +1680 -1680
  26. package/app/core/capability.py +144 -144
  27. package/app/core/chaptersafe.py +32 -32
  28. package/app/core/cleanup.py +303 -303
  29. package/app/core/compaction.py +201 -201
  30. package/app/core/contracts.py +255 -255
  31. package/app/core/covergen.py +356 -356
  32. package/app/core/defectretro.py +43 -43
  33. package/app/core/diagnostics.py +114 -114
  34. package/app/core/dispatch.py +190 -190
  35. package/app/core/dispatch_log.py +128 -128
  36. package/app/core/env_scrub.py +85 -85
  37. package/app/core/errorlog.py +137 -137
  38. package/app/core/evaluation.py +174 -174
  39. package/app/core/failure_notify.py +290 -290
  40. package/app/core/goal_service.py +167 -167
  41. package/app/core/health.py +389 -389
  42. package/app/core/history.py +38 -38
  43. package/app/core/hooks.py +162 -162
  44. package/app/core/manager.py +2232 -2232
  45. package/app/core/mocks.py +64 -64
  46. package/app/core/notify.py +201 -201
  47. package/app/core/novel_quality.py +189 -189
  48. package/app/core/openapi.py +154 -154
  49. package/app/core/operations.py +228 -228
  50. package/app/core/paihang.py +145 -145
  51. package/app/core/pipeline.py +20 -0
  52. package/app/core/planner.py +88 -0
  53. package/app/core/portguard.py +111 -111
  54. package/app/core/presence.py +77 -77
  55. package/app/core/preview.py +293 -293
  56. package/app/core/prompt_guard.py +78 -78
  57. package/app/core/publish/__init__.py +7 -7
  58. package/app/core/publish/browser.py +655 -655
  59. package/app/core/publish/fanqie.py +165 -165
  60. package/app/core/publish/flow.py +640 -640
  61. package/app/core/publish/flows-fanqie-calibrated.json +336 -336
  62. package/app/core/publish/manager.py +1118 -1118
  63. package/app/core/publish/qimao.py +176 -176
  64. package/app/core/publish/ws.py +139 -139
  65. package/app/core/quality_gate.py +194 -194
  66. package/app/core/redact.py +38 -38
  67. package/app/core/repeat_guard.py +129 -129
  68. package/app/core/retrieval.py +137 -137
  69. package/app/core/router.py +398 -398
  70. package/app/core/runner.py +2238 -2238
  71. package/app/core/selfupdate.py +384 -384
  72. package/app/core/session_log.py +161 -161
  73. package/app/core/sessions.py +312 -312
  74. package/app/core/settings_schema.py +270 -270
  75. package/app/core/share_page.py +114 -114
  76. package/app/core/skill_scan.py +139 -139
  77. package/app/core/skillpacks/market/character-bible.md +66 -66
  78. package/app/core/skillpacks/market/code-risk-checklist.md +58 -58
  79. package/app/core/skillpacks/market/git-workflow.md +57 -57
  80. package/app/core/skillpacks/market/release-notes.md +72 -72
  81. package/app/core/skillpacks/market/weekly-report.md +71 -71
  82. package/app/core/skillpacks/market/worldview-consistency.md +70 -70
  83. package/app/core/skills.py +1 -1
  84. package/app/core/step_runner.py +132 -132
  85. package/app/core/story_tracking.py +275 -275
  86. package/app/core/task_compile.py +199 -199
  87. package/app/core/telemetry.py +292 -292
  88. package/app/core/tlsctx.py +64 -64
  89. package/app/core/token_meter.py +147 -147
  90. package/app/core/tracing.py +144 -144
  91. package/app/core/upstream.py +41 -41
  92. package/app/core/usage.py +1035 -1035
  93. package/app/core/volumes.py +389 -389
  94. package/app/core/wxdigest.py +858 -858
  95. package/app/core/zentao.py +2692 -2692
  96. package/app/mcp_server.py +244 -244
  97. package/app/output/_createbook_body.json +1 -0
  98. package/app/output/_probe_fq_click.py +50 -0
  99. package/app/output/_probe_fq_form.py +42 -0
  100. package/app/output/_probe_fq_modal.py +55 -0
  101. package/app/output/_probe_fq_points.py +71 -0
  102. package/app/output/_probe_fq_submit.py +34 -0
  103. package/app/output/_probe_fq_watch.py +62 -0
  104. package/app/pick_dialog.py +110 -110
  105. package/app/ui/artdiff.js +74 -74
  106. package/app/ui/board.html +162 -162
  107. package/app/ui/board.js +305 -305
  108. package/app/ui/icons/bee.svg +79 -79
  109. package/app/ui/manifest.json +16 -16
  110. package/app/ui/qrcode.js +2297 -2297
  111. package/app/ui/style.css +7086 -7086
  112. package/bin/tutti.js +147 -147
  113. package/package.json +48 -48
  114. package/tools/wx_reader.py +261 -261
@@ -1,144 +1,144 @@
1
- # -*- coding: utf-8 -*-
2
- """能力维度(4D):按任务类型(writing/coding/reasoning/vision)选模型。
3
-
4
- 设计稿:docs/migration/05-model-seams.md §4D(按 CodeBee 实际架构落地:
5
- 不改 modelhub.py——供应商声明可选 `strengths` 字段即可被识别;
6
- 选择逻辑独立成模块,零侵入)。
7
-
8
- 供应商声明示例(data/models.json 的 providers 条目):
9
- {"id": "p1", ..., "strengths": ["writing", "reasoning"]}
10
- 未声明 strengths 的供应商视为无偏好(只做兜底)。
11
- """
12
- from __future__ import annotations
13
-
14
- import re
15
-
16
- from .dispatch import TYPE_DIMENSIONS
17
-
18
- # 能力维度(先固化清单,schema 见设计稿)
19
- DIMS = ("writing", "coding", "reasoning", "vision")
20
-
21
- # 关键词分类表(覆盖 task type / 目标文本;可按需扩充)
22
- _KEYWORDS = {
23
- "writing": ("写", "文案", "大纲", "连载", "章节", "小说", "营销", "总结", "润色",
24
- "novel", "draft", "review"),
25
- "coding": ("代码", "实现", "修复", "重构", "测试", "bug", "code", "fix",
26
- "refactor", "test", "编译", "报错"),
27
- "reasoning": ("推理", "分析", "调研", "对比", "规划", "拆解", "评审",
28
- "reason", "analyze", "plan", "orchestrate"),
29
- "vision": ("图", "图片", "识别", "视觉", "ocr", "image", "vision", "截图"),
30
- }
31
-
32
-
33
- def classify_task_type(task) -> str:
34
- """把任务分类到 DIMS 之一。task 显式带 task_type 时优先。"""
35
- explicit = str((task or {}).get("task_type") or "").strip().lower()
36
- if explicit in DIMS:
37
- return explicit
38
- preset = str((task or {}).get("type") or "").strip().lower()
39
- if preset in TYPE_DIMENSIONS:
40
- return TYPE_DIMENSIONS[preset]
41
- text = "%s %s" % ((task or {}).get("type") or "",
42
- (task or {}).get("goal") or "")
43
- scores = {}
44
- for dim, kws in _KEYWORDS.items():
45
- scores[dim] = sum(1 for kw in kws if kw in text)
46
- best = max(scores, key=lambda d: scores[d])
47
- if scores[best] > 0:
48
- return best
49
- return "coding" # 默认兜底(CodeBee 主场景)
50
-
51
-
52
- def provider_strengths(prov):
53
- """读供应商声明的能力维度(容错:非法值忽略)。"""
54
- raw = (prov or {}).get("strengths")
55
- if not isinstance(raw, list):
56
- return []
57
- return [s for s in raw if s in DIMS]
58
-
59
-
60
- def pick_by_strength(providers, task_type, *, enabled_only=True):
61
- """按能力维度挑供应商。
62
-
63
- 规则:
64
- 1. 声明了该维度的可用供应商优先(保持原有顺序);
65
- 2. 未声明的排后面(兜底);
66
- 3. 都没有声明时返回原顺序(行为同现状)。
67
- 返回 (排序后的供应商列表, 分类依据说明)。
68
- """
69
- task_type = task_type if task_type in DIMS else classify_task_type({"goal": task_type})
70
- pool = list(providers or [])
71
- if enabled_only:
72
- pool = [p for p in pool if p.get("enabled", True)]
73
- strong = [p for p in pool if task_type in provider_strengths(p)]
74
- rest = [p for p in pool if p not in strong]
75
- ranked = strong + rest
76
- reason = "%s:优先 %s" % (
77
- task_type,
78
- "、".join(p.get("id", "?") for p in strong) if strong else "(无声明,按原序兜底)")
79
- return ranked, reason
80
-
81
-
82
- def resolve_binding_by_task(task, providers, bindings):
83
- """任务 → 绑定解析(能力维度优先,回落 default)。
84
-
85
- bindings 形如 modelhub 的 {"writing": {...}, "coding": {...}, "default": {...}};
86
- 对应维度的绑定缺失/为空时回落 default。返回 (binding, task_type)。
87
- """
88
- tt = classify_task_type(task)
89
- b = (bindings or {}).get(tt)
90
- if not b:
91
- b = (bindings or {}).get("default")
92
- return b, tt
93
-
94
-
95
- # ---------------------------------------------------------------- §07 T3.1 级联
96
-
97
- TIER_ORDER = {"budget": 0, "standard": 1, "premium": 2}
98
-
99
-
100
- def cascade_reorder(agent, tier_of, *, providers=None, pricing=None,
101
- difficulty="easy", task_type="", role=""):
102
- """FrugalGPT 式便宜优先:easy 任务把 call_chain 按 tier 升序稳定重排。
103
-
104
- agent 来自 modelhub.bind_agent(可能带 call_chain);tier_of(chain_entry)
105
- 返回该条目的档位串("budget"/"standard"/"premium"或 None=standard)。
106
- 稳定排序保证同档内保持用户配置的原顺序。链长 <2 或非链式原样返回。
107
- """
108
- chain = (agent or {}).get("call_chain") or []
109
- if len(chain) < 2:
110
- return agent
111
- if providers is not None and (task_type or role):
112
- from .dispatch import rank_model_entries
113
- ranked, _decisions = rank_model_entries(
114
- chain, {p.get("id"): p for p in providers or []},
115
- pricing or {}, difficulty, task_type, role)
116
- out = dict(agent)
117
- out["call_chain"] = ranked
118
- return out
119
-
120
- def key(entry):
121
- return TIER_ORDER.get(tier_of(entry) or "standard", 1)
122
-
123
- out = dict(agent)
124
- out["call_chain"] = sorted(chain, key=key)
125
- return out
126
-
127
-
128
- def make_tier_lookup(providers):
129
- """由 providers 列表构造 chain_entry → tier 的查询函数。
130
-
131
- tier 来源(按优先级):链条目 model 在供应商 models[] 里的 tier 字段 →
132
- 供应商级 tier → None(按 standard 兜底)。缺什么都不抛。
133
- """
134
- by_id = {p.get("id"): p for p in (providers or []) if p.get("id")}
135
-
136
- def tier_of(entry):
137
- p = by_id.get((entry or {}).get("provider_id") or "")
138
- if not p:
139
- return None
140
- for m in (p.get("models") or []):
141
- if isinstance(m, dict) and m.get("name") == (entry or {}).get("model"):
142
- return m.get("tier") or p.get("tier")
143
- return p.get("tier")
144
- return tier_of
1
+ # -*- coding: utf-8 -*-
2
+ """能力维度(4D):按任务类型(writing/coding/reasoning/vision)选模型。
3
+
4
+ 设计稿:docs/migration/05-model-seams.md §4D(按 CodeBee 实际架构落地:
5
+ 不改 modelhub.py——供应商声明可选 `strengths` 字段即可被识别;
6
+ 选择逻辑独立成模块,零侵入)。
7
+
8
+ 供应商声明示例(data/models.json 的 providers 条目):
9
+ {"id": "p1", ..., "strengths": ["writing", "reasoning"]}
10
+ 未声明 strengths 的供应商视为无偏好(只做兜底)。
11
+ """
12
+ from __future__ import annotations
13
+
14
+ import re
15
+
16
+ from .dispatch import TYPE_DIMENSIONS
17
+
18
+ # 能力维度(先固化清单,schema 见设计稿)
19
+ DIMS = ("writing", "coding", "reasoning", "vision")
20
+
21
+ # 关键词分类表(覆盖 task type / 目标文本;可按需扩充)
22
+ _KEYWORDS = {
23
+ "writing": ("写", "文案", "大纲", "连载", "章节", "小说", "营销", "总结", "润色",
24
+ "novel", "draft", "review"),
25
+ "coding": ("代码", "实现", "修复", "重构", "测试", "bug", "code", "fix",
26
+ "refactor", "test", "编译", "报错"),
27
+ "reasoning": ("推理", "分析", "调研", "对比", "规划", "拆解", "评审",
28
+ "reason", "analyze", "plan", "orchestrate"),
29
+ "vision": ("图", "图片", "识别", "视觉", "ocr", "image", "vision", "截图"),
30
+ }
31
+
32
+
33
+ def classify_task_type(task) -> str:
34
+ """把任务分类到 DIMS 之一。task 显式带 task_type 时优先。"""
35
+ explicit = str((task or {}).get("task_type") or "").strip().lower()
36
+ if explicit in DIMS:
37
+ return explicit
38
+ preset = str((task or {}).get("type") or "").strip().lower()
39
+ if preset in TYPE_DIMENSIONS:
40
+ return TYPE_DIMENSIONS[preset]
41
+ text = "%s %s" % ((task or {}).get("type") or "",
42
+ (task or {}).get("goal") or "")
43
+ scores = {}
44
+ for dim, kws in _KEYWORDS.items():
45
+ scores[dim] = sum(1 for kw in kws if kw in text)
46
+ best = max(scores, key=lambda d: scores[d])
47
+ if scores[best] > 0:
48
+ return best
49
+ return "coding" # 默认兜底(CodeBee 主场景)
50
+
51
+
52
+ def provider_strengths(prov):
53
+ """读供应商声明的能力维度(容错:非法值忽略)。"""
54
+ raw = (prov or {}).get("strengths")
55
+ if not isinstance(raw, list):
56
+ return []
57
+ return [s for s in raw if s in DIMS]
58
+
59
+
60
+ def pick_by_strength(providers, task_type, *, enabled_only=True):
61
+ """按能力维度挑供应商。
62
+
63
+ 规则:
64
+ 1. 声明了该维度的可用供应商优先(保持原有顺序);
65
+ 2. 未声明的排后面(兜底);
66
+ 3. 都没有声明时返回原顺序(行为同现状)。
67
+ 返回 (排序后的供应商列表, 分类依据说明)。
68
+ """
69
+ task_type = task_type if task_type in DIMS else classify_task_type({"goal": task_type})
70
+ pool = list(providers or [])
71
+ if enabled_only:
72
+ pool = [p for p in pool if p.get("enabled", True)]
73
+ strong = [p for p in pool if task_type in provider_strengths(p)]
74
+ rest = [p for p in pool if p not in strong]
75
+ ranked = strong + rest
76
+ reason = "%s:优先 %s" % (
77
+ task_type,
78
+ "、".join(p.get("id", "?") for p in strong) if strong else "(无声明,按原序兜底)")
79
+ return ranked, reason
80
+
81
+
82
+ def resolve_binding_by_task(task, providers, bindings):
83
+ """任务 → 绑定解析(能力维度优先,回落 default)。
84
+
85
+ bindings 形如 modelhub 的 {"writing": {...}, "coding": {...}, "default": {...}};
86
+ 对应维度的绑定缺失/为空时回落 default。返回 (binding, task_type)。
87
+ """
88
+ tt = classify_task_type(task)
89
+ b = (bindings or {}).get(tt)
90
+ if not b:
91
+ b = (bindings or {}).get("default")
92
+ return b, tt
93
+
94
+
95
+ # ---------------------------------------------------------------- §07 T3.1 级联
96
+
97
+ TIER_ORDER = {"budget": 0, "standard": 1, "premium": 2}
98
+
99
+
100
+ def cascade_reorder(agent, tier_of, *, providers=None, pricing=None,
101
+ difficulty="easy", task_type="", role=""):
102
+ """FrugalGPT 式便宜优先:easy 任务把 call_chain 按 tier 升序稳定重排。
103
+
104
+ agent 来自 modelhub.bind_agent(可能带 call_chain);tier_of(chain_entry)
105
+ 返回该条目的档位串("budget"/"standard"/"premium"或 None=standard)。
106
+ 稳定排序保证同档内保持用户配置的原顺序。链长 <2 或非链式原样返回。
107
+ """
108
+ chain = (agent or {}).get("call_chain") or []
109
+ if len(chain) < 2:
110
+ return agent
111
+ if providers is not None and (task_type or role):
112
+ from .dispatch import rank_model_entries
113
+ ranked, _decisions = rank_model_entries(
114
+ chain, {p.get("id"): p for p in providers or []},
115
+ pricing or {}, difficulty, task_type, role)
116
+ out = dict(agent)
117
+ out["call_chain"] = ranked
118
+ return out
119
+
120
+ def key(entry):
121
+ return TIER_ORDER.get(tier_of(entry) or "standard", 1)
122
+
123
+ out = dict(agent)
124
+ out["call_chain"] = sorted(chain, key=key)
125
+ return out
126
+
127
+
128
+ def make_tier_lookup(providers):
129
+ """由 providers 列表构造 chain_entry → tier 的查询函数。
130
+
131
+ tier 来源(按优先级):链条目 model 在供应商 models[] 里的 tier 字段 →
132
+ 供应商级 tier → None(按 standard 兜底)。缺什么都不抛。
133
+ """
134
+ by_id = {p.get("id"): p for p in (providers or []) if p.get("id")}
135
+
136
+ def tier_of(entry):
137
+ p = by_id.get((entry or {}).get("provider_id") or "")
138
+ if not p:
139
+ return None
140
+ for m in (p.get("models") or []):
141
+ if isinstance(m, dict) and m.get("name") == (entry or {}).get("model"):
142
+ return m.get("tier") or p.get("tier")
143
+ return p.get("tier")
144
+ return tier_of
@@ -1,32 +1,32 @@
1
- # -*- coding: utf-8 -*-
2
- """章节安全落盘(tmp+原子改名,inkos 安全章节工作区借鉴)。
3
-
4
- 写一半崩溃/磁盘满不会留下半章正文冒充成稿——断点续跑按「文件够长」
5
- 判定,半文件会被误当合法稿复用;.tmp 写完 os.replace 原子落位,
6
- 失败清理残渣后原样抛出。路径守卫用 pathlib resolve+parents 惯用法
7
- (同 _ms_io/_inside 口径)。pipeline._write_chapter 委托此函数。"""
8
- from __future__ import annotations
9
-
10
- from pathlib import Path
11
-
12
-
13
- def atomic_write_chapter(workdir, i, text):
14
- """第 i 章安全落盘:tmp 写入 → 原子改名。返回最终路径。"""
15
- root = Path(workdir).resolve()
16
- p = (root / ("chapter-%02d.md" % int(i))).resolve()
17
- # 守卫:目标必须在 workdir 之内且不得是 workdir 本身(".." 作 workdir
18
- # 时 resolve 到父目录,p 仍是其中一章——但那不是调用方的工作目录,
19
- # 一并拒绝:workdir 必须是已存在的目录)
20
- if root not in p.parents or not root.is_dir():
21
- raise ValueError("章节路径越界: chapter-%02d.md" % int(i))
22
- tmp = Path(str(p) + ".tmp")
23
- try:
24
- tmp.write_text(str(text), encoding="utf-8", errors="replace")
25
- tmp.replace(p)
26
- except BaseException:
27
- try:
28
- tmp.unlink(missing_ok=True)
29
- except OSError:
30
- pass
31
- raise
32
- return p
1
+ # -*- coding: utf-8 -*-
2
+ """章节安全落盘(tmp+原子改名,inkos 安全章节工作区借鉴)。
3
+
4
+ 写一半崩溃/磁盘满不会留下半章正文冒充成稿——断点续跑按「文件够长」
5
+ 判定,半文件会被误当合法稿复用;.tmp 写完 os.replace 原子落位,
6
+ 失败清理残渣后原样抛出。路径守卫用 pathlib resolve+parents 惯用法
7
+ (同 _ms_io/_inside 口径)。pipeline._write_chapter 委托此函数。"""
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+
12
+
13
+ def atomic_write_chapter(workdir, i, text):
14
+ """第 i 章安全落盘:tmp 写入 → 原子改名。返回最终路径。"""
15
+ root = Path(workdir).resolve()
16
+ p = (root / ("chapter-%02d.md" % int(i))).resolve()
17
+ # 守卫:目标必须在 workdir 之内且不得是 workdir 本身(".." 作 workdir
18
+ # 时 resolve 到父目录,p 仍是其中一章——但那不是调用方的工作目录,
19
+ # 一并拒绝:workdir 必须是已存在的目录)
20
+ if root not in p.parents or not root.is_dir():
21
+ raise ValueError("章节路径越界: chapter-%02d.md" % int(i))
22
+ tmp = Path(str(p) + ".tmp")
23
+ try:
24
+ tmp.write_text(str(text), encoding="utf-8", errors="replace")
25
+ tmp.replace(p)
26
+ except BaseException:
27
+ try:
28
+ tmp.unlink(missing_ok=True)
29
+ except OSError:
30
+ pass
31
+ raise
32
+ return p