codebee 0.1.61 → 0.1.62

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 (96) hide show
  1. package/CHANGELOG.md +490 -496
  2. package/LICENSE +21 -21
  3. package/README.md +486 -486
  4. package/app/core/aiflavor.py +197 -197
  5. package/app/core/attachments.py +532 -532
  6. package/app/core/automation.py +758 -758
  7. package/app/core/backup.py +470 -470
  8. package/app/core/beekeeper.py +183 -183
  9. package/app/core/board.py +209 -209
  10. package/app/core/bookmeta_catalog.py +180 -180
  11. package/app/core/branching.py +137 -137
  12. package/app/core/builtin_agent.py +1191 -1191
  13. package/app/core/capability.py +144 -144
  14. package/app/core/chaptersafe.py +32 -32
  15. package/app/core/cleanup.py +303 -303
  16. package/app/core/compaction.py +186 -186
  17. package/app/core/covergen.py +356 -356
  18. package/app/core/diagnostics.py +114 -114
  19. package/app/core/dispatch.py +173 -173
  20. package/app/core/dispatch_log.py +113 -113
  21. package/app/core/env_scrub.py +85 -85
  22. package/app/core/error_codes.py +64 -64
  23. package/app/core/errorlog.py +137 -137
  24. package/app/core/flows.py +355 -355
  25. package/app/core/goal_service.py +167 -167
  26. package/app/core/health.py +341 -341
  27. package/app/core/history.py +38 -38
  28. package/app/core/hooks.py +156 -156
  29. package/app/core/jobs.py +1022 -1022
  30. package/app/core/manager.py +1996 -1996
  31. package/app/core/market.py +362 -362
  32. package/app/core/market_remote.py +66 -66
  33. package/app/core/mocks.py +64 -64
  34. package/app/core/modelhub.py +3266 -3266
  35. package/app/core/notify.py +106 -106
  36. package/app/core/paihang.py +109 -109
  37. package/app/core/paths.py +2 -2
  38. package/app/core/pipeline.py +4426 -4384
  39. package/app/core/planner.py +27 -27
  40. package/app/core/portguard.py +111 -111
  41. package/app/core/preview.py +293 -293
  42. package/app/core/publish/__init__.py +7 -7
  43. package/app/core/publish/auto.py +367 -367
  44. package/app/core/publish/browser.py +533 -533
  45. package/app/core/publish/fanqie.py +128 -128
  46. package/app/core/publish/flow.py +406 -406
  47. package/app/core/publish/ledger.py +198 -198
  48. package/app/core/publish/manager.py +590 -590
  49. package/app/core/publish/qimao.py +141 -141
  50. package/app/core/publish/ws.py +139 -139
  51. package/app/core/redact.py +38 -38
  52. package/app/core/repeat_guard.py +124 -124
  53. package/app/core/router.py +307 -307
  54. package/app/core/selfupdate.py +384 -384
  55. package/app/core/session_log.py +161 -161
  56. package/app/core/sessions.py +312 -312
  57. package/app/core/settings.py +149 -149
  58. package/app/core/settings_schema.py +262 -262
  59. package/app/core/share_page.py +114 -114
  60. package/app/core/skill_scan.py +106 -95
  61. package/app/core/skillpacks/fanqie-novel.md +80 -80
  62. package/app/core/skillpacks/market/character-bible.md +66 -66
  63. package/app/core/skillpacks/market/code-risk-checklist.md +58 -58
  64. package/app/core/skillpacks/market/git-workflow.md +57 -57
  65. package/app/core/skillpacks/market/release-notes.md +72 -72
  66. package/app/core/skillpacks/market/weekly-report.md +71 -71
  67. package/app/core/skillpacks/market/worldview-consistency.md +70 -70
  68. package/app/core/step_runner.py +132 -132
  69. package/app/core/task_compile.py +199 -199
  70. package/app/core/telemetry.py +292 -292
  71. package/app/core/tlsctx.py +64 -64
  72. package/app/core/token_meter.py +147 -147
  73. package/app/core/volumes.py +355 -355
  74. package/app/core/wxdigest.py +858 -858
  75. package/app/core/zentao.py +2090 -2090
  76. package/app/main.py +2826 -2826
  77. package/app/pick_dialog.py +110 -110
  78. package/app/ui/app.js +13977 -13977
  79. package/app/ui/board.html +162 -162
  80. package/app/ui/board.js +305 -305
  81. package/app/ui/i18n.js +2711 -2711
  82. package/app/ui/icons/bee.svg +79 -79
  83. package/app/ui/index.html +1 -1
  84. package/app/ui/manifest.json +16 -16
  85. package/app/ui/qrcode.js +2297 -2297
  86. package/app/ui/style.css +6125 -6125
  87. package/bin/tutti.js +147 -147
  88. package/package.json +41 -41
  89. package/tools/wx_reader.py +261 -261
  90. package/app/.playwright-cli/console-2026-09-23T08-26-03-635Z.log +0 -88
  91. package/app/.playwright-cli/page-2026-09-23T08-26-03-845Z.yml +0 -126
  92. package/app/.playwright-cli/page-2026-09-23T08-29-44-203Z.png +0 -0
  93. package/app/.playwright-cli/page-2026-09-23T08-35-42-046Z.yml +0 -210
  94. package/app/.playwright-cli/page-2026-09-23T08-36-52-858Z.png +0 -0
  95. package/app/.playwright-cli/page-2026-09-23T08-37-33-938Z.png +0 -0
  96. package/app/.playwright-cli/run-detail-after.png +0 -0
@@ -1,186 +1,186 @@
1
- # -*- coding: utf-8 -*-
2
- """三段式上下文压缩:工具结果剪枝 → LLM 摘要 → surface replace。
3
-
4
- 设计稿:docs/migration/02-context-compaction.md §1B。
5
- 参考 dsh:
6
- packages/compaction/compaction-basic/src/region.ts:117-155(selectCompactableRange:
7
- 跳过 system 头、保留尾预算、不切断 tool call/result 配对)
8
- packages/compaction/compaction-tool-result-pruner/src/index.ts:83-122(头尾剪枝)
9
- packages/compaction/compaction-basic/src/region.ts:173-275(压缩事务四件事件:
10
- compaction/start → summary → user/message(replace) → end;失败仍写 end 保证日志可见)
11
-
12
- 触发:maybe_compact() 检查 token_meter 压力比 ≥ 阈值才动手。
13
- """
14
- from __future__ import annotations
15
-
16
- import logging
17
-
18
- from .token_meter import token_meter, DEFAULT_PRESSURE_THRESHOLD
19
-
20
- log = logging.getLogger(__name__)
21
-
22
- # 工具结果剪枝参数(字符数;dsh 默认 8192/4096,单行 marker)
23
- PRUNE_HEAD = 8192
24
- PRUNE_TAIL = 4096
25
- PRUNE_MARKER = "\n…[中间内容已剪枝,原文见会话日志]…\n"
26
-
27
- # 尾部保留预算(估算 token)
28
- RETAIN_TAIL_TOKENS = 8000
29
- # 单次压缩区域上限(事件数,防一次吞太多)
30
- MAX_REGION_EVENTS = 50
31
-
32
-
33
- def estimate_tokens(text: str) -> int:
34
- """极简估算:4 字符/token(中文偏低估,偏保守触发)。"""
35
- return max(1, len(text or "") // 4)
36
-
37
-
38
- def _ev_text(ev) -> str:
39
- return str(ev.data.get("content") or ev.data.get("stdout") or "")
40
-
41
-
42
- def prune_text(text: str, *, head=PRUNE_HEAD, tail=PRUNE_TAIL, marker=PRUNE_MARKER) -> str:
43
- """超长文本头尾剪枝(纯无 LLM 调用)。"""
44
- if text is None:
45
- return ""
46
- if len(text) <= head + tail + len(marker):
47
- return text
48
- return text[:head] + marker + text[-tail:]
49
-
50
-
51
- def select_range(session, *, retain_tail_tokens=RETAIN_TAIL_TOKENS,
52
- max_region_events=MAX_REGION_EVENTS):
53
- """选可压缩区域 [start_seq, end_seq](闭区间)。
54
-
55
- 规则(仿 dsh selectCompactableRange):
56
- 1. 跳过 system 头节点(从第一条 user_message 起);
57
- 2. 尾部保留 retain_tail_tokens 预算不参与压缩(retain<=0 表示尾部不保留);
58
- 3. 全部内容都在尾预算内 → 无可压缩区域,返回 (0, 0);
59
- 4. 区域末端不能落在 tool 配对中间(回退到配对完成处);
60
- 5. 区域不超过 max_region_events 个事件。
61
- 返回 (start_seq, end_seq);无可压缩区域返回 (0, 0)。
62
- """
63
- events = session.events()
64
- surface_events = [e for e in events if e.type in
65
- ("system_message", "user_message", "assistant_message")]
66
- if not surface_events:
67
- return 0, 0
68
- first_user_seq = next((e.seq for e in surface_events
69
- if e.type == "user_message"), 0)
70
- if not first_user_seq:
71
- return 0, 0
72
- # 尾部保留:倒推预算。tail_start_seq = 保留尾段的第一个 seq。
73
- last_seq = surface_events[-1].seq
74
- if retain_tail_tokens <= 0:
75
- tail_start_seq = last_seq + 1 # 尾部不保留:全部可压
76
- else:
77
- tail_budget = 0
78
- tail_start_seq = 0 # 0 表示"全部都在预算内"(无区域)
79
- for ev in reversed(surface_events):
80
- tail_budget += estimate_tokens(_ev_text(ev))
81
- if tail_budget >= retain_tail_tokens:
82
- tail_start_seq = ev.seq
83
- break
84
- if not tail_start_seq:
85
- return 0, 0 # 预算从未被突破 → 无可压缩区域
86
- # 候选区域 = [first_user_seq, tail_start_seq)
87
- all_events = session.events()
88
- by_seq = {e.seq: e for e in all_events}
89
- end_seq = tail_start_seq - 1
90
- # 不切断 tool 配对:末端若是 tool_call/tool_result,回退到最近的非 tool 事件
91
- while end_seq >= first_user_seq:
92
- ev = by_seq.get(end_seq)
93
- if ev is None or ev.type not in ("tool_call", "tool_result"):
94
- break
95
- end_seq -= 1
96
- # 区域事件数上限
97
- region_events = [e for e in all_events
98
- if first_user_seq <= e.seq <= end_seq]
99
- if len(region_events) > max_region_events:
100
- end_seq = region_events[max_region_events - 1].seq
101
- # 再做一次配对回退
102
- while end_seq >= first_user_seq:
103
- ev = by_seq.get(end_seq)
104
- if ev is None or ev.type not in ("tool_call", "tool_result"):
105
- break
106
- end_seq -= 1
107
- if end_seq < first_user_seq:
108
- return 0, 0
109
- return first_user_seq, end_seq
110
-
111
-
112
- _SUMMARY_SYSTEM = (
113
- "你是会话压缩器。把以下对话历史压缩成简洁摘要,必须保留:\n"
114
- "1. 关键决策与结论;2. 涉及的文件路径与命令;3. 未完成事项;\n"
115
- "4. 错误信息原文。直接输出摘要正文,不要客套。"
116
- )
117
-
118
-
119
- def compact_region(session, start_seq: int, end_seq: int, llm_caller,
120
- *, reason: str = "pressure"):
121
- """执行一次压缩事务(四件事件,失败仍写 compaction_end 保证日志可见)。
122
-
123
- llm_caller(messages: list[dict]) -> str:一次 LLM 调用,返回摘要文本。
124
- """
125
- tx = session.append("compaction_start",
126
- {"start_seq": start_seq, "end_seq": end_seq, "reason": reason},
127
- surface_op="shadow")
128
- summary = ""
129
- error = ""
130
- try:
131
- region_events = [e for e in session.events()
132
- if start_seq <= e.seq <= end_seq]
133
- # 第一段:工具结果先剪枝(省摘要调用的输入 token)
134
- parts = []
135
- for ev in region_events:
136
- text = _ev_text(ev)
137
- if ev.type == "tool_result":
138
- text = prune_text(text)
139
- if text.strip():
140
- parts.append(f"[{ev.type}#{ev.seq}] {text}")
141
- region_text = "\n\n".join(parts)
142
- raw_tokens = estimate_tokens(region_text)
143
- summary = llm_caller([
144
- {"role": "system", "content": _SUMMARY_SYSTEM},
145
- {"role": "user", "content": region_text},
146
- ])
147
- session.append("compaction_summary",
148
- {"raw_tokens": raw_tokens,
149
- "summary_tokens": estimate_tokens(summary),
150
- "start_seq": start_seq, "end_seq": end_seq},
151
- surface_op="shadow")
152
- # surface replace:把区域折叠为一条 user 摘要消息
153
- session.append("user_message", {
154
- "content": f"[系统压缩摘要 {start_seq}-{end_seq},原因 {reason}]\n{summary}",
155
- }, surface_op={"op": "replace", "start_seq": start_seq, "end_seq": end_seq})
156
- except Exception as e:
157
- error = repr(e)
158
- log.warning("compact_region failed: %s", error)
159
- session.append("compaction_summary", {"error": error}, surface_op="shadow")
160
- finally:
161
- session.append("compaction_end",
162
- {"tx_seq": tx.seq, "error": error},
163
- surface_op="shadow")
164
- return not error
165
-
166
-
167
- def maybe_compact(session, *, model: str = "", llm_caller=None,
168
- threshold: float = DEFAULT_PRESSURE_THRESHOLD,
169
- run_id: str = None,
170
- retain_tail_tokens: int = RETAIN_TAIL_TOKENS) -> bool:
171
- """压力比 ≥ 阈值时触发一次压缩。返回是否执行了压缩。
172
-
173
- llm_caller 缺省直接跳过(没有摘要能力就不压)。
174
- """
175
- if llm_caller is None:
176
- return False
177
- rid = run_id or session.run_id
178
- ratio = token_meter.pressure_ratio(rid, model=model)
179
- if ratio < threshold:
180
- return False
181
- start, end = select_range(session, retain_tail_tokens=retain_tail_tokens)
182
- if not start:
183
- return False
184
- log.info("compaction triggered run=%s ratio=%.2f region=[%d,%d]",
185
- rid, ratio, start, end)
186
- return compact_region(session, start, end, llm_caller, reason=f"pressure={ratio:.2f}")
1
+ # -*- coding: utf-8 -*-
2
+ """三段式上下文压缩:工具结果剪枝 → LLM 摘要 → surface replace。
3
+
4
+ 设计稿:docs/migration/02-context-compaction.md §1B。
5
+ 参考 dsh:
6
+ packages/compaction/compaction-basic/src/region.ts:117-155(selectCompactableRange:
7
+ 跳过 system 头、保留尾预算、不切断 tool call/result 配对)
8
+ packages/compaction/compaction-tool-result-pruner/src/index.ts:83-122(头尾剪枝)
9
+ packages/compaction/compaction-basic/src/region.ts:173-275(压缩事务四件事件:
10
+ compaction/start → summary → user/message(replace) → end;失败仍写 end 保证日志可见)
11
+
12
+ 触发:maybe_compact() 检查 token_meter 压力比 ≥ 阈值才动手。
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import logging
17
+
18
+ from .token_meter import token_meter, DEFAULT_PRESSURE_THRESHOLD
19
+
20
+ log = logging.getLogger(__name__)
21
+
22
+ # 工具结果剪枝参数(字符数;dsh 默认 8192/4096,单行 marker)
23
+ PRUNE_HEAD = 8192
24
+ PRUNE_TAIL = 4096
25
+ PRUNE_MARKER = "\n…[中间内容已剪枝,原文见会话日志]…\n"
26
+
27
+ # 尾部保留预算(估算 token)
28
+ RETAIN_TAIL_TOKENS = 8000
29
+ # 单次压缩区域上限(事件数,防一次吞太多)
30
+ MAX_REGION_EVENTS = 50
31
+
32
+
33
+ def estimate_tokens(text: str) -> int:
34
+ """极简估算:4 字符/token(中文偏低估,偏保守触发)。"""
35
+ return max(1, len(text or "") // 4)
36
+
37
+
38
+ def _ev_text(ev) -> str:
39
+ return str(ev.data.get("content") or ev.data.get("stdout") or "")
40
+
41
+
42
+ def prune_text(text: str, *, head=PRUNE_HEAD, tail=PRUNE_TAIL, marker=PRUNE_MARKER) -> str:
43
+ """超长文本头尾剪枝(纯无 LLM 调用)。"""
44
+ if text is None:
45
+ return ""
46
+ if len(text) <= head + tail + len(marker):
47
+ return text
48
+ return text[:head] + marker + text[-tail:]
49
+
50
+
51
+ def select_range(session, *, retain_tail_tokens=RETAIN_TAIL_TOKENS,
52
+ max_region_events=MAX_REGION_EVENTS):
53
+ """选可压缩区域 [start_seq, end_seq](闭区间)。
54
+
55
+ 规则(仿 dsh selectCompactableRange):
56
+ 1. 跳过 system 头节点(从第一条 user_message 起);
57
+ 2. 尾部保留 retain_tail_tokens 预算不参与压缩(retain<=0 表示尾部不保留);
58
+ 3. 全部内容都在尾预算内 → 无可压缩区域,返回 (0, 0);
59
+ 4. 区域末端不能落在 tool 配对中间(回退到配对完成处);
60
+ 5. 区域不超过 max_region_events 个事件。
61
+ 返回 (start_seq, end_seq);无可压缩区域返回 (0, 0)。
62
+ """
63
+ events = session.events()
64
+ surface_events = [e for e in events if e.type in
65
+ ("system_message", "user_message", "assistant_message")]
66
+ if not surface_events:
67
+ return 0, 0
68
+ first_user_seq = next((e.seq for e in surface_events
69
+ if e.type == "user_message"), 0)
70
+ if not first_user_seq:
71
+ return 0, 0
72
+ # 尾部保留:倒推预算。tail_start_seq = 保留尾段的第一个 seq。
73
+ last_seq = surface_events[-1].seq
74
+ if retain_tail_tokens <= 0:
75
+ tail_start_seq = last_seq + 1 # 尾部不保留:全部可压
76
+ else:
77
+ tail_budget = 0
78
+ tail_start_seq = 0 # 0 表示"全部都在预算内"(无区域)
79
+ for ev in reversed(surface_events):
80
+ tail_budget += estimate_tokens(_ev_text(ev))
81
+ if tail_budget >= retain_tail_tokens:
82
+ tail_start_seq = ev.seq
83
+ break
84
+ if not tail_start_seq:
85
+ return 0, 0 # 预算从未被突破 → 无可压缩区域
86
+ # 候选区域 = [first_user_seq, tail_start_seq)
87
+ all_events = session.events()
88
+ by_seq = {e.seq: e for e in all_events}
89
+ end_seq = tail_start_seq - 1
90
+ # 不切断 tool 配对:末端若是 tool_call/tool_result,回退到最近的非 tool 事件
91
+ while end_seq >= first_user_seq:
92
+ ev = by_seq.get(end_seq)
93
+ if ev is None or ev.type not in ("tool_call", "tool_result"):
94
+ break
95
+ end_seq -= 1
96
+ # 区域事件数上限
97
+ region_events = [e for e in all_events
98
+ if first_user_seq <= e.seq <= end_seq]
99
+ if len(region_events) > max_region_events:
100
+ end_seq = region_events[max_region_events - 1].seq
101
+ # 再做一次配对回退
102
+ while end_seq >= first_user_seq:
103
+ ev = by_seq.get(end_seq)
104
+ if ev is None or ev.type not in ("tool_call", "tool_result"):
105
+ break
106
+ end_seq -= 1
107
+ if end_seq < first_user_seq:
108
+ return 0, 0
109
+ return first_user_seq, end_seq
110
+
111
+
112
+ _SUMMARY_SYSTEM = (
113
+ "你是会话压缩器。把以下对话历史压缩成简洁摘要,必须保留:\n"
114
+ "1. 关键决策与结论;2. 涉及的文件路径与命令;3. 未完成事项;\n"
115
+ "4. 错误信息原文。直接输出摘要正文,不要客套。"
116
+ )
117
+
118
+
119
+ def compact_region(session, start_seq: int, end_seq: int, llm_caller,
120
+ *, reason: str = "pressure"):
121
+ """执行一次压缩事务(四件事件,失败仍写 compaction_end 保证日志可见)。
122
+
123
+ llm_caller(messages: list[dict]) -> str:一次 LLM 调用,返回摘要文本。
124
+ """
125
+ tx = session.append("compaction_start",
126
+ {"start_seq": start_seq, "end_seq": end_seq, "reason": reason},
127
+ surface_op="shadow")
128
+ summary = ""
129
+ error = ""
130
+ try:
131
+ region_events = [e for e in session.events()
132
+ if start_seq <= e.seq <= end_seq]
133
+ # 第一段:工具结果先剪枝(省摘要调用的输入 token)
134
+ parts = []
135
+ for ev in region_events:
136
+ text = _ev_text(ev)
137
+ if ev.type == "tool_result":
138
+ text = prune_text(text)
139
+ if text.strip():
140
+ parts.append(f"[{ev.type}#{ev.seq}] {text}")
141
+ region_text = "\n\n".join(parts)
142
+ raw_tokens = estimate_tokens(region_text)
143
+ summary = llm_caller([
144
+ {"role": "system", "content": _SUMMARY_SYSTEM},
145
+ {"role": "user", "content": region_text},
146
+ ])
147
+ session.append("compaction_summary",
148
+ {"raw_tokens": raw_tokens,
149
+ "summary_tokens": estimate_tokens(summary),
150
+ "start_seq": start_seq, "end_seq": end_seq},
151
+ surface_op="shadow")
152
+ # surface replace:把区域折叠为一条 user 摘要消息
153
+ session.append("user_message", {
154
+ "content": f"[系统压缩摘要 {start_seq}-{end_seq},原因 {reason}]\n{summary}",
155
+ }, surface_op={"op": "replace", "start_seq": start_seq, "end_seq": end_seq})
156
+ except Exception as e:
157
+ error = repr(e)
158
+ log.warning("compact_region failed: %s", error)
159
+ session.append("compaction_summary", {"error": error}, surface_op="shadow")
160
+ finally:
161
+ session.append("compaction_end",
162
+ {"tx_seq": tx.seq, "error": error},
163
+ surface_op="shadow")
164
+ return not error
165
+
166
+
167
+ def maybe_compact(session, *, model: str = "", llm_caller=None,
168
+ threshold: float = DEFAULT_PRESSURE_THRESHOLD,
169
+ run_id: str = None,
170
+ retain_tail_tokens: int = RETAIN_TAIL_TOKENS) -> bool:
171
+ """压力比 ≥ 阈值时触发一次压缩。返回是否执行了压缩。
172
+
173
+ llm_caller 缺省直接跳过(没有摘要能力就不压)。
174
+ """
175
+ if llm_caller is None:
176
+ return False
177
+ rid = run_id or session.run_id
178
+ ratio = token_meter.pressure_ratio(rid, model=model)
179
+ if ratio < threshold:
180
+ return False
181
+ start, end = select_range(session, retain_tail_tokens=retain_tail_tokens)
182
+ if not start:
183
+ return False
184
+ log.info("compaction triggered run=%s ratio=%.2f region=[%d,%d]",
185
+ rid, ratio, start, end)
186
+ return compact_region(session, start, end, llm_caller, reason=f"pressure={ratio:.2f}")