@hfyjq/crannia 1.1.1 → 1.2.0
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/LICENSE +201 -201
- package/NOTICE +48 -45
- package/README.md +1 -1
- package/THIRD-PARTY-FRONTEND.md +5266 -5266
- package/THIRD-PARTY-PYTHON-linux.md +174 -0
- package/THIRD-PARTY-PYTHON.md +176 -162
- package/THIRD-PARTY.md +323 -316
- package/apps/desktop/quotes.txt +56 -56
- package/bus/core.py +677 -671
- package/bus/loaders/channel_loader.py +64 -64
- package/bus/loaders/provider_loader.py +4 -7
- package/bus/loaders/skill_loader.py +46 -27
- package/bus/loaders/skill_md.py +9 -9
- package/bus/mcp_disabled.py +4 -6
- package/bus/quarantine.py +10 -13
- package/bus/registry.py +2315 -2284
- package/bus/skill_state.py +124 -124
- package/channels/cli_channel/handler.py +3 -3
- package/channels/cli_channel/manifest.yaml +5 -5
- package/channels/dingtalk_channel/handler.py +32 -32
- package/channels/dingtalk_channel/manifest.yaml +12 -12
- package/channels/feishu_channel/handler.py +33 -33
- package/channels/feishu_channel/manifest.yaml +12 -12
- package/channels/qq_bot_channel/__init__.py +1 -1
- package/channels/qq_bot_channel/handler.py +24 -24
- package/channels/qq_bot_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/__init__.py +1 -1
- package/channels/telegram_channel/handler.py +21 -21
- package/channels/telegram_channel/manifest.yaml +4 -4
- package/channels/telegram_channel/media.py +231 -231
- package/channels/textfmt.py +58 -58
- package/channels/wechat_channel/__init__.py +1 -1
- package/channels/wechat_channel/converter.py +1 -1
- package/channels/wechat_channel/handler.py +8 -8
- package/channels/wechat_channel/manifest.yaml +5 -5
- package/channels/wechat_channel/media.py +178 -178
- package/core/activity.py +753 -709
- package/core/agent_loop.py +7673 -7523
- package/core/allowlist.py +2 -3
- package/core/approval.py +36 -26
- package/core/approval_timeout.py +256 -228
- package/core/artifacts.py +3 -3
- package/core/attachment_gc.py +21 -0
- package/core/auto_review.py +2 -2
- package/core/browser/cdp.py +5 -2
- package/core/browser/discover.py +55 -19
- package/core/browser/session.py +4 -4
- package/core/cache_break_detector.py +97 -0
- package/core/cache_breakpoints.py +103 -0
- package/core/cache_policies.py +255 -0
- package/core/cancellation.py +3 -3
- package/core/channel_configs.py +3 -3
- package/core/channel_turns.py +13 -13
- package/core/child_approval.py +2 -3
- package/core/code_intel.py +11 -11
- package/core/command_policy.py +13 -7
- package/core/computer/annotate.py +231 -11
- package/core/computer/capture.py +140 -1
- package/core/computer/guard.py +7 -4
- package/core/computer/input.py +452 -26
- package/core/computer/session.py +563 -381
- package/core/computer/tools.py +2170 -928
- package/core/computer/uia.py +100 -1
- package/core/computer/watch.py +1 -1
- package/core/computer/win32.py +302 -7
- package/core/config_requirements.py +205 -205
- package/core/cron/runner.py +4 -4
- package/core/daily_log.py +2 -2
- package/core/dedup.py +2 -2
- package/core/egress_channels.py +326 -0
- package/core/egress_gate.py +96 -8
- package/core/egress_preapproved.py +59 -3
- package/core/endpoint.py +141 -141
- package/core/events.py +17 -8
- package/core/extension.py +2 -2
- package/core/file_history.py +15 -15
- package/core/file_tools.py +3 -3
- package/core/github_config.py +1 -1
- package/core/group_digest.py +3 -4
- package/core/group_minutes.py +5 -5
- package/core/group_reply.py +24 -0
- package/core/groups.py +5 -9
- package/core/hooks.py +15 -15
- package/core/i18n.py +2 -2
- package/core/ice/canary.py +3 -3
- package/core/ice/net_heuristics.py +2 -2
- package/core/im_routing.py +3 -3
- package/core/image_input.py +183 -43
- package/core/inbound.py +3 -3
- package/core/jobs.py +6 -6
- package/core/last_good.py +150 -150
- package/core/leaf_md.py +3 -3
- package/core/llm_errors.py +37 -28
- package/core/mail_config.py +2 -2
- package/core/memory/compressor.py +8 -8
- package/core/memory/manager.py +30 -45
- package/core/memory/session_memory.py +1 -2
- package/core/memory/short_term.py +4 -4
- package/core/memory_extract.py +1 -1
- package/core/memory_organize.py +8 -8
- package/core/memory_store.py +7 -9
- package/core/memory_transfer.py +2 -2
- package/core/model_capabilities.py +2 -2
- package/core/model_configs.py +219 -68
- package/core/model_profiles.py +333 -0
- package/core/modes.py +12 -11
- package/core/net_proxy.py +3 -3
- package/core/pipeline/scheduler.py +48 -43
- package/core/pipeline/stage.py +3 -0
- package/core/pipeline/stages/agent_loop.py +36 -15
- package/core/pipeline/stages/group_reply.py +22 -20
- package/core/pipeline/stages/post_process.py +7 -7
- package/core/pipeline/stages/pre_process.py +369 -77
- package/core/prompt_assembler.py +13 -4
- package/core/recycle.py +227 -16
- package/core/response_language.py +1 -1
- package/core/retention.py +2 -2
- package/core/rg.py +4 -3
- package/core/security.py +26 -8
- package/core/services.py +8 -8
- package/core/session_model.py +3 -5
- package/core/session_pool.py +35 -5
- package/core/session_recap.py +40 -3
- package/core/session_workspace.py +2 -3
- package/core/settings_baseline.py +2 -2
- package/core/settings_transfer.py +25 -1
- package/core/shell.py +52 -20
- package/core/side_call.py +3 -3
- package/core/skill_config.py +164 -0
- package/core/skill_factory.py +2 -2
- package/core/skill_guidance.py +2 -4
- package/core/skill_index.py +3 -4
- package/core/skill_settings.py +1 -1
- package/core/skill_sources.py +7 -7
- package/core/ssh_config.py +129 -0
- package/core/state_registry.py +67 -5
- package/core/subagent.py +28 -5
- package/core/subagent_defs.py +3 -3
- package/core/summarizer.py +4 -5
- package/core/tasks_notify.py +6 -6
- package/core/tiers.py +2 -2
- package/core/todos.py +1 -1
- package/core/token_calibrator.py +1 -4
- package/core/tool_outcome.py +108 -108
- package/core/touched_files.py +1 -1
- package/core/trace.py +12 -3
- package/core/unlock.py +4 -4
- package/core/update_tui.py +184 -158
- package/core/updater.py +5 -3
- package/core/version.py +14 -14
- package/core/vision_budget.py +235 -0
- package/core/web_cache.py +152 -152
- package/core/web_request.py +474 -0
- package/core/window_estimate.py +1 -1
- package/core/workspace.py +56 -26
- package/crannia_tray.py +278 -278
- package/licenses/GPL-3.0.txt +619 -619
- package/licenses/LGPL-2.1.txt +502 -502
- package/licenses/LGPL-3.0.txt +165 -165
- package/licenses/MIT-chat-on-wechat.txt +18 -18
- package/licenses/MIT-deepseek-harness.txt +21 -21
- package/licenses/Molio-LICENSE.txt +44 -44
- package/locales/en.json +1876 -1762
- package/main.py +154 -154
- package/mcpx/client.py +12 -1
- package/mcpx/manager.py +530 -522
- package/mcpx/servers/web_search.py +5 -13
- package/package.json +15 -23
- package/providers/anthropic/client.py +35 -33
- package/providers/base.py +13 -13
- package/providers/cache_policies.json +294 -0
- package/providers/cost_table.json +3779 -3779
- package/providers/lmstudio/client.py +2 -2
- package/providers/model_capabilities.json +6665 -6665
- package/providers/model_profiles.json +629 -0
- package/providers/ollama/client.py +2 -2
- package/providers/openai_compat.py +37 -16
- package/providers/openrouter/client.py +2 -2
- package/providers/qwen/__init__.py +1 -1
- package/providers/qwen/client.py +2 -2
- package/providers/qwen/manifest.yaml +16 -16
- package/providers/rate_limiter.py +2 -2
- package/providers/siliconflow/client.py +2 -2
- package/providers/validation.py +171 -171
- package/providers/vision_profiles.json +89 -0
- package/providers/window_table.json +8909 -8909
- package/requirements.txt +59 -51
- package/sbom-linux-x64.json +4580 -0
- package/sbom.json +4600 -4413
- package/skills/diagram/SKILL.md +47 -0
- package/skills/diagram/__init__.py +1 -0
- package/skills/diagram/handler.py +294 -0
- package/skills/diagram/layout.py +174 -0
- package/skills/diagram/manifest.yaml +106 -0
- package/skills/diagram/mermaid.py +170 -0
- package/skills/diagram/svg.py +223 -0
- package/skills/entertainment/SKILL.md +35 -35
- package/skills/entertainment/__init__.py +1 -1
- package/skills/entertainment/handler.py +91 -91
- package/skills/entertainment/manifest.yaml +26 -26
- package/skills/file_parser/GUIDANCE.md +10 -10
- package/skills/file_parser/handler.py +33 -11
- package/skills/github/SKILL.md +32 -32
- package/skills/github/__init__.py +1 -1
- package/skills/mail_parser/SKILL.md +68 -68
- package/skills/mail_parser/__init__.py +1 -1
- package/skills/mail_parser/handler.py +1 -1
- package/skills/media_gen/GUIDANCE.md +19 -19
- package/skills/media_gen/SKILL.md +43 -43
- package/skills/media_gen/__init__.py +1 -1
- package/skills/media_gen/handler.py +1 -1
- package/skills/media_gen/manifest.yaml +93 -93
- package/skills/netops/SKILL.md +45 -0
- package/skills/netops/__init__.py +1 -0
- package/skills/netops/handler.py +418 -0
- package/skills/netops/manifest.yaml +118 -0
- package/skills/office_parser/_excel_io.py +3 -3
- package/skills/office_parser/handler.py +2 -2
- package/skills/office_parser/ppt_tools.py +1 -1
- package/skills/office_parser/pptx_export/console_encoding.py +27 -27
- package/skills/office_parser/pptx_export/resource_paths.py +88 -88
- package/skills/office_parser/pptx_export/svg_finalize/__init__.py +12 -12
- package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -366
- package/skills/office_parser/pptx_export/svg_finalize/embed_images.py +288 -288
- package/skills/office_parser/pptx_export/svg_finalize/fix_image_aspect.py +388 -388
- package/skills/office_parser/pptx_export/svg_finalize/flatten_tspan.py +818 -818
- package/skills/office_parser/pptx_export/svg_finalize/svg_rect_to_path.py +345 -345
- package/skills/office_parser/pptx_export/svg_to_pptx/__init__.py +14 -14
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/context.py +186 -186
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/converter.py +781 -781
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -429
- package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/utils.py +40 -21
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/__init__.py +1 -1
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/builder.py +1267 -1267
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/dimensions.py +155 -155
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/discovery.py +101 -101
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/narration.py +236 -236
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/notes.py +257 -257
- package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/slide_xml.py +136 -136
- package/skills/office_parser/pptx_export/svg_to_pptx/tspan_flattener.py +44 -44
- package/skills/office_parser/pptx_export/svg_to_pptx/use_expander.py +129 -129
- package/skills/office_parser/references/LICENSE-Office-Word-MCP-Server.txt +20 -20
- package/skills/office_parser/references/LICENSE-excel-mcp-server.txt +21 -21
- package/skills/office_parser/references/layout_library.md +816 -816
- package/skills/office_parser/references/ppt-master/LICENSE +21 -21
- package/skills/office_parser/references/ppt-master/references/executor-base.md +474 -474
- package/skills/office_parser/references/ppt-master/references/shared-standards.md +1002 -1002
- package/skills/office_parser/references/ppt-master/references/strategist.md +880 -880
- package/skills/office_parser/references/ppt-master/references/template-designer.md +402 -402
- package/skills/office_parser/references/ppt-master/references/visual-review.md +240 -240
- package/skills/office_parser/references/ppt-master/references/visual-styles/_index.md +106 -106
- package/skills/office_parser/references/ppt-master/references/visual-styles/blueprint.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/brutalist.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/chalkboard.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/dark-tech.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/data-journalism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/glassmorphism.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-notes.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/ink-wash.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/memphis.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/paper-cut.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/photo-editorial.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/pixel-art.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/sketch-notes.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/soft-rounded.md +37 -37
- package/skills/office_parser/references/ppt-master/references/visual-styles/swiss-minimal.md +38 -38
- package/skills/office_parser/references/ppt-master/references/visual-styles/vintage-poster.md +36 -36
- package/skills/office_parser/references/ppt-master/references/visual-styles/zine.md +37 -37
- package/skills/office_parser/references/spec_lock.md +235 -235
- package/skills/office_parser/soffice.py +68 -68
- package/skills/office_parser/word_tools.py +3 -3
- package/skills/ssh/SKILL.md +81 -0
- package/skills/ssh/__init__.py +1 -0
- package/skills/ssh/handler.py +609 -0
- package/skills/ssh/manifest.yaml +182 -0
- package/tui/crannia.cmd +134 -134
- package/tui/crannia.sh +82 -0
- package/tui/crannia_tui/__init__.py +1 -1
- package/tui/crannia_tui/app.py +240 -17
- package/tui/crannia_tui/app.tcss +21 -0
- package/tui/crannia_tui/clipboard.py +78 -10
- package/tui/crannia_tui/commands.py +37 -0
- package/tui/crannia_tui/events.py +6 -0
- package/tui/crannia_tui/i18n.py +164 -164
- package/tui/crannia_tui/locales/en.json +32 -7
- package/tui/crannia_tui/paths.py +4 -1
- package/tui/crannia_tui/profile.py +178 -169
- package/tui/crannia_tui/settings.py +134 -134
- package/tui/crannia_tui/setup.py +44 -5
- package/tui/crannia_tui/ui.py +156 -16
- package/tui/crannia_tui/update.py +393 -389
- package/vendor/ripgrep/COPYING.txt +3 -3
- package/vendor/ripgrep/LICENSE-MIT.txt +21 -21
- package/vendor/ripgrep/NOTICE-vscode-ripgrep.txt +13 -13
- package/vendor/ripgrep/README.md +30 -14
- package/vendor/ripgrep/UNLICENSE.txt +24 -24
- package/vendor/ripgrep/linux-x64/rg +0 -0
- package/vendor/ripgrep/package-source.json +15 -16
- package/web/__main__.py +12 -15
- package/web/server.py +8481 -8594
- package/web/static/img/channel-telegram.svg +1 -1
- package/web/static/img/channel-wechat.svg +1 -1
- package/web/templates/logs.html +49 -49
- package/web/templates/models.html +46 -46
package/core/session_recap.py
CHANGED
|
@@ -30,12 +30,24 @@
|
|
|
30
30
|
(读不到 ≠ 0,也 ≠ "很久")。
|
|
31
31
|
- 默认关:它是用户打开的功能,不是我们替他打开的。
|
|
32
32
|
关着的时候本模块一行都不做(不开支、不出事件)。
|
|
33
|
+
|
|
34
|
+
## 一次"回来"只说一遍(不只是靠 `last_turn_at` 前进)
|
|
35
|
+
|
|
36
|
+
`last_turn_at` 是「上一轮跑完了」的时刻。若那一轮在跑完之前就失败
|
|
37
|
+
(provider 报错、进程退出),它会停在旧值 —— 之后用户每发一句话,
|
|
38
|
+
`due()` 都判真,回顾就会隔一句出现一次。
|
|
39
|
+
|
|
40
|
+
所以这里另记一格:给出回顾时把它记在 `_LAST_RECAP[session]`。
|
|
41
|
+
下一条消息若仍对着同一个 `last_turn_at`(说明那之后还没有一轮真正跑完),
|
|
42
|
+
直接不说话 —— 不必等到它再老一个间隔。等哪一轮跑完,`last_turn_at` 前进,
|
|
43
|
+
下一个"离开够久"的窗口才重新打开。
|
|
33
44
|
"""
|
|
34
45
|
|
|
35
46
|
from __future__ import annotations
|
|
36
47
|
|
|
37
48
|
import re
|
|
38
|
-
|
|
49
|
+
import time
|
|
50
|
+
from typing import Dict, Optional
|
|
39
51
|
|
|
40
52
|
#: 设置键(`data/settings.json`)。两个键:开关 + 触发时间。
|
|
41
53
|
#: 「可关闭」那一格就落在 `ENABLED_KEY` 上 ——
|
|
@@ -53,6 +65,17 @@ DEFAULT_MINUTES = 30
|
|
|
53
65
|
MIN_MINUTES = 1
|
|
54
66
|
MAX_MINUTES = 1440 # 一天;超过它等于"永远不触发",那就该关开关
|
|
55
67
|
|
|
68
|
+
#: 本会话上一次给出回顾的时刻。键 = session_id,进程内。
|
|
69
|
+
#: 判据见模块 docstring 的「一次"回来"只说一遍」—— 它防的是
|
|
70
|
+
#: 「那一轮没跑完 => `last_turn_at` 不前进 => 每句话都来一段回顾」。
|
|
71
|
+
#: 登记在 `core/state_registry.py`(`/clear` 走 `forget`)。
|
|
72
|
+
_LAST_RECAP: Dict[str, float] = {}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def forget(session_id: str) -> None:
|
|
76
|
+
"""`/clear` 的清理(`state_registry` 的 purge 入口)。"""
|
|
77
|
+
_LAST_RECAP.pop(session_id, None)
|
|
78
|
+
|
|
56
79
|
|
|
57
80
|
def _settings() -> dict:
|
|
58
81
|
"""读 `data/settings.json`。读不到 / 坏文件,空字典(读不到,默认)。"""
|
|
@@ -167,10 +190,21 @@ def recap_for(session_id: str, now: Optional[float] = None) -> Optional[str]:
|
|
|
167
190
|
|
|
168
191
|
顺序是有讲究的:先判 `due`(纯读设置 + 一个钟),
|
|
169
192
|
判过了才去读笔记文件 —— 绝大多数轮在第一道就返回了,不碰磁盘。
|
|
193
|
+
|
|
194
|
+
另有一道「这一次回来已经说过了」:见模块 docstring。判据是
|
|
195
|
+
`_LAST_RECAP[session] >= last_turn_at` —— 说明给出回顾之后
|
|
196
|
+
还没有任何一轮真正跑完(`last_turn_at` 没前进),此时不再重复。
|
|
170
197
|
"""
|
|
171
198
|
from core.memory_extract import last_turn_at
|
|
172
199
|
|
|
173
|
-
|
|
200
|
+
anchor = last_turn_at(session_id)
|
|
201
|
+
if anchor is None:
|
|
202
|
+
return None
|
|
203
|
+
stamp = _LAST_RECAP.get(session_id)
|
|
204
|
+
if stamp is not None and stamp >= float(anchor):
|
|
205
|
+
return None
|
|
206
|
+
t = time.time() if now is None else float(now)
|
|
207
|
+
if not due(anchor, t):
|
|
174
208
|
return None
|
|
175
209
|
from core.memory.session_memory import SessionMemory
|
|
176
210
|
|
|
@@ -178,4 +212,7 @@ def recap_for(session_id: str, now: Optional[float] = None) -> Optional[str]:
|
|
|
178
212
|
note = SessionMemory().load(session_id)
|
|
179
213
|
except Exception: # noqa: BLE001 —— 回顾是**锦上添花**:拿不到就算了,
|
|
180
214
|
return None # 但绝不因此弄挂这一轮(同 `context.state` 那条兜底判据)
|
|
181
|
-
|
|
215
|
+
text = build(note or "")
|
|
216
|
+
if text:
|
|
217
|
+
_LAST_RECAP[session_id] = t
|
|
218
|
+
return text
|
|
@@ -134,8 +134,7 @@ def chosen(storage_key: str) -> str:
|
|
|
134
134
|
# 读不到,当没选过(fail-open,同 `session_model.frozen` 那条)。
|
|
135
135
|
# 方向是掐出来的:读不到就走默认工作区 —— 而"读不到"最可能的时刻
|
|
136
136
|
# 正是库刚建、或换了一台机器;那时"用默认"就是对的答案。
|
|
137
|
-
print(f"[session_workspace]
|
|
138
|
-
f"{type(exc).__name__}: {exc}")
|
|
137
|
+
print(f"[session_workspace] read session workspace failed (treating as unset): {type(exc).__name__}: {exc}")
|
|
139
138
|
return ""
|
|
140
139
|
|
|
141
140
|
|
|
@@ -188,7 +187,7 @@ def use_default(storage_key: str) -> bool:
|
|
|
188
187
|
st.clear_session_workspace(key)
|
|
189
188
|
return existed
|
|
190
189
|
except Exception as exc: # noqa: BLE001
|
|
191
|
-
print(f"[session_workspace]
|
|
190
|
+
print(f"[session_workspace] revert to default workspace failed ({type(exc).__name__}: {exc})")
|
|
192
191
|
return False
|
|
193
192
|
|
|
194
193
|
|
|
@@ -92,12 +92,12 @@ def baseline(path: Optional[Path] = None) -> dict:
|
|
|
92
92
|
except FileNotFoundError:
|
|
93
93
|
if not _warned:
|
|
94
94
|
_warned = True
|
|
95
|
-
print(f"[settings]
|
|
95
|
+
print(f"[settings] factory baseline unreadable ({p}) - restore defaults will become a no-op")
|
|
96
96
|
return {}
|
|
97
97
|
except (OSError, ValueError) as exc:
|
|
98
98
|
if not _warned:
|
|
99
99
|
_warned = True
|
|
100
|
-
print(f"[settings]
|
|
100
|
+
print(f"[settings] factory baseline broken ({p}): {type(exc).__name__}: {exc}")
|
|
101
101
|
return {}
|
|
102
102
|
if not isinstance(raw, dict):
|
|
103
103
|
return {}
|
|
@@ -75,7 +75,9 @@ CRED_FILES: tuple = (
|
|
|
75
75
|
("data/wechat_credentials.json", "wechat_credentials"),
|
|
76
76
|
("data/media_gen_credentials.json", "media_gen_credentials"),
|
|
77
77
|
("data/media_gen_key.txt", "media_gen_key"),
|
|
78
|
-
|
|
78
|
+
#: 模型配置的密钥不在这里 —— 它与账本同一份文件,
|
|
79
|
+
#: 整份搬会把非密字段也塞进加密段、导入时还会覆盖账本。
|
|
80
|
+
#: 走 `collect_credentials` 里那条 `model_config_api`(按 id 取明文)。
|
|
79
81
|
# MCP 服务器的 `env` / `headers` 里通常就是令牌,归凭据,绝不进默认包。
|
|
80
82
|
("data/mcp_servers.json", "mcp_servers"),
|
|
81
83
|
)
|
|
@@ -152,6 +154,19 @@ def collect_credentials(settings: Optional[dict] = None) -> dict:
|
|
|
152
154
|
text = _read_text(path)
|
|
153
155
|
if text:
|
|
154
156
|
out[name] = text
|
|
157
|
+
#: 模型配置的密钥(单文件存储之后与账本同一份文件)——
|
|
158
|
+
#: 按 id 逐条取明文,不整份搬:整份会把非密字段也加密,
|
|
159
|
+
#: 导入时还会覆盖账本(账本那段走 `merge_ledger`,与这条分开)。
|
|
160
|
+
try:
|
|
161
|
+
from core import model_configs as _MC
|
|
162
|
+
apis = {cid: _MC.api_for(cid)
|
|
163
|
+
for cid in (_MC.all_entries().get("configs") or {})}
|
|
164
|
+
apis = {k: v for k, v in apis.items() if v}
|
|
165
|
+
if apis:
|
|
166
|
+
out["model_config_api"] = apis
|
|
167
|
+
except Exception as exc: # noqa: BLE001
|
|
168
|
+
# 收不起来就不带这一段(明确不出声地少一块 = 用户以为包里全了)。
|
|
169
|
+
print(f"[settings_transfer] model config secrets not collected ({type(exc).__name__}: {exc})")
|
|
155
170
|
for k in CRED_SETTINGS:
|
|
156
171
|
if isinstance(settings, dict) and k in settings:
|
|
157
172
|
out[k] = settings[k]
|
|
@@ -489,6 +504,15 @@ def apply_import(bundle, plan: dict, current: Optional[dict] = None, *,
|
|
|
489
504
|
new_settings[k] = payload[k]
|
|
490
505
|
written.append(k)
|
|
491
506
|
n += 1
|
|
507
|
+
#: 模型配置的密钥按 id 并回账本(只认已有 id)。
|
|
508
|
+
apis = payload.get("model_config_api")
|
|
509
|
+
if isinstance(apis, dict) and apis:
|
|
510
|
+
try:
|
|
511
|
+
from core import model_configs as _MC
|
|
512
|
+
n += _MC.import_apis(apis)
|
|
513
|
+
except Exception as exc: # noqa: BLE001
|
|
514
|
+
applied["model_config_api_error"] = "%s: %s" % (
|
|
515
|
+
type(exc).__name__, exc)
|
|
492
516
|
applied["credentials"] = n
|
|
493
517
|
except ValueError as exc:
|
|
494
518
|
applied["credentials_error"] = str(exc)
|
package/core/shell.py
CHANGED
|
@@ -68,6 +68,7 @@ import os
|
|
|
68
68
|
import re
|
|
69
69
|
import shlex
|
|
70
70
|
import shutil
|
|
71
|
+
import signal
|
|
71
72
|
import subprocess
|
|
72
73
|
import sys
|
|
73
74
|
import threading
|
|
@@ -148,7 +149,7 @@ _BASH_CANDIDATES: tuple[str, ...] = (
|
|
|
148
149
|
ENV_WHITELIST: tuple[str, ...] = (
|
|
149
150
|
# ① 进程能起来所必需(缺了 bash 或子进程会直接跑不动)
|
|
150
151
|
"path", "pathext", "systemroot", "windir", "systemdrive",
|
|
151
|
-
"comspec", "temp", "tmp",
|
|
152
|
+
"comspec", "temp", "tmp", "tmpdir",
|
|
152
153
|
# ② `~` 与用户目录(bash 靠 HOME/USERPROFILE 展开 `~`)
|
|
153
154
|
"home", "homedrive", "homepath", "userprofile",
|
|
154
155
|
"appdata", "localappdata", "programdata",
|
|
@@ -248,9 +249,9 @@ def bash_path() -> str:
|
|
|
248
249
|
_bash_cache = found
|
|
249
250
|
_bash_probed = True # 最后写 —— 见 docstring 那段
|
|
250
251
|
if not _bash_cache:
|
|
251
|
-
print("[shell]
|
|
252
|
-
f"
|
|
253
|
-
f"
|
|
252
|
+
print("[shell] bash not found - command execution tool will be unavailable. "
|
|
253
|
+
f"Tried: {', '.join(_BASH_CANDIDATES)} and PATH. "
|
|
254
|
+
f"Install Git for Windows and restart the framework.")
|
|
254
255
|
return _bash_cache
|
|
255
256
|
|
|
256
257
|
|
|
@@ -444,8 +445,8 @@ def ensure_snapshot() -> str:
|
|
|
444
445
|
dest = _SNAPSHOT_DEST.resolve()
|
|
445
446
|
ok, why = _write_snapshot(bash, dest)
|
|
446
447
|
if not ok:
|
|
447
|
-
print("[shell]
|
|
448
|
-
"
|
|
448
|
+
print("[shell] shell snapshot not created (%s) - commands still run, "
|
|
449
|
+
"but without profile functions and aliases." % why)
|
|
449
450
|
return ""
|
|
450
451
|
_snapshot_file = str(dest)
|
|
451
452
|
_snapshot_cache = str(dest)
|
|
@@ -536,6 +537,10 @@ _CWD_MARK = "\x01CRANNIA_CWD\x01"
|
|
|
536
537
|
#: (`subprocess.run` 的 timeout 只杀直接子进程,孙进程会活下来)。
|
|
537
538
|
_CREATE_NEW_PROCESS_GROUP = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
|
|
538
539
|
|
|
540
|
+
#: POSIX 的对应物:子进程自成会话(新进程组),`/stop` 才能 killpg 整棵树。
|
|
541
|
+
#: Windows 上传 True 会被 `subprocess` 拒,所以这一格在 Windows 上必须是 False。
|
|
542
|
+
_START_NEW_SESSION = os.name != "nt"
|
|
543
|
+
|
|
539
544
|
|
|
540
545
|
def _wrap(command: str, snapshot: str = "") -> str:
|
|
541
546
|
"""给命令拼上"回报 cwd + 保留退出码"的尾巴(见模块 docstring 第三节)。
|
|
@@ -671,7 +676,8 @@ def _kill_tree(proc: subprocess.Popen) -> None:
|
|
|
671
676
|
"""杀掉整棵进程树(best-effort)。
|
|
672
677
|
|
|
673
678
|
Windows 上 `proc.kill()` 只结束直接子进程;`taskkill /T` 才带子进程。
|
|
674
|
-
|
|
679
|
+
POSIX 上子进程由 `start_new_session=True` 自成一组,`killpg` 才带子进程。
|
|
680
|
+
拿不到对应的工具就退回 `kill()` —— 降级要出声。
|
|
675
681
|
"""
|
|
676
682
|
if sys.platform == "win32":
|
|
677
683
|
taskkill = shutil.which("taskkill")
|
|
@@ -681,14 +687,38 @@ def _kill_tree(proc: subprocess.Popen) -> None:
|
|
|
681
687
|
capture_output=True, timeout=10)
|
|
682
688
|
return
|
|
683
689
|
except Exception as exc:
|
|
684
|
-
print(f"[shell] taskkill
|
|
685
|
-
|
|
690
|
+
print(f"[shell] taskkill failed ({type(exc).__name__}: {exc}) - falling back to single-process kill, grandchildren may survive")
|
|
691
|
+
else:
|
|
692
|
+
print("[shell] taskkill not found - falling back to single-process kill, grandchildren may survive")
|
|
693
|
+
try:
|
|
694
|
+
proc.kill()
|
|
695
|
+
except Exception as exc:
|
|
696
|
+
print(f"[shell] kill also failed ({type(exc).__name__}: {exc})")
|
|
697
|
+
return
|
|
698
|
+
|
|
699
|
+
# POSIX:先确认它真的自成一组,再杀组 —— 杀错组的代价是把框架自己带走。
|
|
700
|
+
try:
|
|
701
|
+
pgid = os.getpgid(proc.pid)
|
|
702
|
+
except ProcessLookupError:
|
|
703
|
+
return
|
|
704
|
+
except Exception as exc:
|
|
705
|
+
pgid = None
|
|
706
|
+
print(f"[shell] process group lookup failed ({type(exc).__name__}: {exc}) - falling back to single-process kill, grandchildren may survive")
|
|
707
|
+
if pgid is not None:
|
|
708
|
+
if pgid == proc.pid:
|
|
709
|
+
try:
|
|
710
|
+
os.killpg(pgid, signal.SIGKILL)
|
|
711
|
+
return
|
|
712
|
+
except ProcessLookupError:
|
|
713
|
+
return
|
|
714
|
+
except Exception as exc:
|
|
715
|
+
print(f"[shell] killpg failed ({type(exc).__name__}: {exc}) - falling back to single-process kill, grandchildren may survive")
|
|
686
716
|
else:
|
|
687
|
-
print("[shell]
|
|
717
|
+
print("[shell] child process not in its own process group - killing only itself, grandchildren may survive")
|
|
688
718
|
try:
|
|
689
719
|
proc.kill()
|
|
690
720
|
except Exception as exc:
|
|
691
|
-
print(f"[shell] kill
|
|
721
|
+
print(f"[shell] kill also failed ({type(exc).__name__}: {exc})")
|
|
692
722
|
|
|
693
723
|
|
|
694
724
|
def _spill(payload: str) -> str:
|
|
@@ -990,10 +1020,13 @@ def _run(command: str, work_dir: Path, timeout_ms: int, *,
|
|
|
990
1020
|
argv = [powershell_path(), "-NoProfile", "-NoLogo",
|
|
991
1021
|
"-NonInteractive", "-Command", _wrap_ps(command)]
|
|
992
1022
|
else:
|
|
1023
|
+
route = ("Windows 上装 Git for Windows,或确认系统自带的 powershell.exe 在。"
|
|
1024
|
+
if os.name == "nt"
|
|
1025
|
+
else "装一个 bash(Debian / Ubuntu:`apt install bash`)。")
|
|
993
1026
|
return {
|
|
994
1027
|
"success": False,
|
|
995
1028
|
"error": ("找不到可用的 shell(bash 与 PowerShell 都没有),命令没有执行。"
|
|
996
|
-
|
|
1029
|
+
+ route),
|
|
997
1030
|
}
|
|
998
1031
|
|
|
999
1032
|
ms = int(timeout_ms or 0) or DEFAULT_TIMEOUT_MS
|
|
@@ -1009,6 +1042,7 @@ def _run(command: str, work_dir: Path, timeout_ms: int, *,
|
|
|
1009
1042
|
stdout=subprocess.PIPE,
|
|
1010
1043
|
stderr=subprocess.PIPE,
|
|
1011
1044
|
creationflags=_CREATE_NEW_PROCESS_GROUP,
|
|
1045
|
+
start_new_session=_START_NEW_SESSION,
|
|
1012
1046
|
)
|
|
1013
1047
|
except OSError as exc:
|
|
1014
1048
|
return {"success": False,
|
|
@@ -1072,8 +1106,7 @@ def _run(command: str, work_dir: Path, timeout_ms: int, *,
|
|
|
1072
1106
|
)
|
|
1073
1107
|
why = ("用户转后台" if by_user else
|
|
1074
1108
|
("超时转后台" if timed_out_ else "按请求直接转后台"))
|
|
1075
|
-
print(f"[shell] {why}
|
|
1076
|
-
f"{jobs.JOB_MAX_LIFETIME_MS // 60000} 分钟)")
|
|
1109
|
+
print(f"[shell] {why}: {job.id} (limit {jobs.JOB_MAX_LIFETIME_MS // 60000} min)")
|
|
1077
1110
|
# 产生后台任务的这一刻,把 `task` 工具挂进这个会话(按需发现;
|
|
1078
1111
|
# 只追加、不改前缀,`K5`)。回执里点名它,模型不用猜。
|
|
1079
1112
|
if _cancel_key:
|
|
@@ -1275,7 +1308,7 @@ def _note_command_touches(command: str, cwd, wm) -> None:
|
|
|
1275
1308
|
break
|
|
1276
1309
|
except Exception as exc: # noqa: BLE001
|
|
1277
1310
|
# 记账失败绝不许拦住一条要跑的命令(同 `touched_files.note` 的规矩)。
|
|
1278
|
-
print("[touched]
|
|
1311
|
+
print("[touched] command-line change recording failed (does not affect execution): %s: %s"
|
|
1279
1312
|
% (type(exc).__name__, exc))
|
|
1280
1313
|
|
|
1281
1314
|
|
|
@@ -1422,7 +1455,7 @@ def run_command(command: str = "", cwd: str = "", timeout_ms: int = 0,
|
|
|
1422
1455
|
_snap = request_snapshot.get_current()
|
|
1423
1456
|
spec = current_spec(_snap.session_id if _snap is not None else "")
|
|
1424
1457
|
if not offers_command(spec):
|
|
1425
|
-
print(f"[tier]
|
|
1458
|
+
print(f"[tier] run_command refused: tier {spec.level} ({spec.name}) does not allow command execution")
|
|
1426
1459
|
return {
|
|
1427
1460
|
"success": False,
|
|
1428
1461
|
"denied": True,
|
|
@@ -1465,7 +1498,7 @@ def run_command(command: str = "", cwd: str = "", timeout_ms: int = 0,
|
|
|
1465
1498
|
except Exception: # noqa: BLE001
|
|
1466
1499
|
_unlocked = False
|
|
1467
1500
|
if _unlocked:
|
|
1468
|
-
print("[unlock] deny
|
|
1501
|
+
print("[unlock] deny-tier command allowed: %s" % raw[:120])
|
|
1469
1502
|
tier = TIER_ALLOW
|
|
1470
1503
|
else:
|
|
1471
1504
|
return {
|
|
@@ -1592,7 +1625,7 @@ def run_command(command: str = "", cwd: str = "", timeout_ms: int = 0,
|
|
|
1592
1625
|
# 这里只 `print`(进运行日志)。界面上一行是它的自然后继 ——
|
|
1593
1626
|
# 要动事件流(前端加一种事件 = 三处),不顺手做。
|
|
1594
1627
|
if _no_ask:
|
|
1595
|
-
print(f"[command]
|
|
1628
|
+
print(f"[command] allowlist hit, not asking: {subject[:120]} - {_no_ask}")
|
|
1596
1629
|
|
|
1597
1630
|
# 命令里点名的、工作区内的文件先记一笔(列表要它,留档也要它)。
|
|
1598
1631
|
# 放在这里 = 审批过了、真的要跑了 —— 没跑的命令不该出现在"本轮改过"里。
|
|
@@ -1635,8 +1668,7 @@ def run_command(command: str = "", cwd: str = "", timeout_ms: int = 0,
|
|
|
1635
1668
|
("ok" if result.get("success") else "fail"))
|
|
1636
1669
|
except Exception as exc:
|
|
1637
1670
|
# 审计失败不能吞掉:它是这条路径上唯一的留痕。
|
|
1638
|
-
print(f"[audit] run_command
|
|
1639
|
-
f" —— 这条命令执行过但没有记录")
|
|
1671
|
+
print(f"[audit] run_command audit write failed ({type(exc).__name__}: {exc}) - command ran but was not recorded")
|
|
1640
1672
|
|
|
1641
1673
|
# 输出裁剪(保尾 + spill)。在工具里做,不在 agent_loop 里 ——
|
|
1642
1674
|
# 那边那把刀保的是头部,方向正好相反(见 `_OUT_BUDGET` 的注释)。
|
package/core/side_call.py
CHANGED
|
@@ -114,17 +114,17 @@ def run(provider, messages, *, session_id: str, directive: str, header: str,
|
|
|
114
114
|
resp = provider.chat(payload, tools, system=system,
|
|
115
115
|
thinking=thinking_for(session_id))
|
|
116
116
|
except Exception as exc: # noqa: BLE001 —— 不吞错:原样报
|
|
117
|
-
print(f"[{tag}]
|
|
117
|
+
print(f"[{tag}] failed: {type(exc).__name__}: {exc}")
|
|
118
118
|
return f"#{tag}-回复异常"
|
|
119
119
|
|
|
120
120
|
text = (getattr(resp, "content", "") or "").strip()
|
|
121
121
|
if not text:
|
|
122
122
|
# 静默返回"没有回应"的原形就是这个分支 ——
|
|
123
123
|
# 用户看不出是模型没说话还是框架坏了。
|
|
124
|
-
print(f"[{tag}]
|
|
124
|
+
print(f"[{tag}] empty reply (model returned only tool calls or blank)")
|
|
125
125
|
return f"#{tag}-模型没有给出回复,可在主对话重试"
|
|
126
126
|
|
|
127
127
|
if len(text) > MAX_CHARS:
|
|
128
128
|
text = text[:MAX_CHARS].rstrip() + " …(截断)"
|
|
129
|
-
print(f"[{tag}]
|
|
129
|
+
print(f"[{tag}] replied {len(text)} chars")
|
|
130
130
|
return f"{header}\n{text}"
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""`skill_config_write` —— 给模型一个受控的"写技能配置"入口(P3)。
|
|
3
|
+
|
|
4
|
+
## 为什么需要它
|
|
5
|
+
|
|
6
|
+
`ssh` 这类技能的配置里既有普通字段(默认用户名),也有秘密
|
|
7
|
+
(口令 / 密码 / sudo 密码)。用户把私钥路径或密码打在对话里时,
|
|
8
|
+
模型能帮填 —— 但用户不该被迫手改 `data/settings.json`。
|
|
9
|
+
这条入口把"帮填"变成一次有审批的动作。
|
|
10
|
+
|
|
11
|
+
## 四条硬规矩
|
|
12
|
+
|
|
13
|
+
1. 审批:它是 `destructive=True` 且没有自己的审批发射点 ——
|
|
14
|
+
兜底闸在派发前问一次(subject = 工具名)。
|
|
15
|
+
2. 秘密只写不回显:口令 / 密码类字段写进去,回执与审计只出现字段名;
|
|
16
|
+
读回接口里它们仍然是 `x-secret`(设置页那一层负责打码)。
|
|
17
|
+
3. 空值不覆盖:给空串等于"不改这一格" —— 静默把口令清掉是最坏的一种
|
|
18
|
+
"帮了倒忙"。
|
|
19
|
+
4. 字段白名单:每个技能只认它 manifest 里声明过的键。写一个不存在的键
|
|
20
|
+
就是一次拼错,拒掉并列出可写的键。
|
|
21
|
+
|
|
22
|
+
## 它不做什么
|
|
23
|
+
|
|
24
|
+
不改模型/安全档位(那些只能由用户在设置页改),也不删条目。
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import json
|
|
30
|
+
import os
|
|
31
|
+
from pathlib import Path
|
|
32
|
+
|
|
33
|
+
__all__ = ["TOOL_NAME", "SCHEMA", "skill_config_write", "register"]
|
|
34
|
+
|
|
35
|
+
TOOL_NAME = "skill_config_write"
|
|
36
|
+
|
|
37
|
+
_SETTINGS = Path("data/settings.json")
|
|
38
|
+
|
|
39
|
+
#: 技能 -> 可写字段。秘密字段单独一张表(回执只记名字)。
|
|
40
|
+
_FIELDS: dict[str, tuple[str, ...]] = {
|
|
41
|
+
"ssh": ("key_path", "passphrase", "user", "password", "sudo_password"),
|
|
42
|
+
}
|
|
43
|
+
_SECRET_FIELDS: frozenset[str] = frozenset({"passphrase", "password", "sudo_password"})
|
|
44
|
+
|
|
45
|
+
SCHEMA = {
|
|
46
|
+
"description": (
|
|
47
|
+
"写入一个技能的配置条目(目前只支持 ssh)。秘密字段(口令/密码)"
|
|
48
|
+
"只写不回显,回执里只出现字段名;空值表示不修改该字段。"
|
|
49
|
+
"这是改动持久安全配置的动作,会先经过一次审批。"
|
|
50
|
+
),
|
|
51
|
+
"inputSchema": {
|
|
52
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
53
|
+
"type": "object",
|
|
54
|
+
"properties": {
|
|
55
|
+
"skill": {"type": "string", "enum": sorted(_FIELDS)},
|
|
56
|
+
"entry": {"type": "string",
|
|
57
|
+
"description": "条目名(设置页里那一行;新建会直接用这个名字)"},
|
|
58
|
+
"fields": {"type": "object",
|
|
59
|
+
"description": "要写的字段(键 -> 值);空串表示不修改"},
|
|
60
|
+
"active": {"type": "boolean", "default": False,
|
|
61
|
+
"description": "是否把这个条目设为当前使用的那一条"},
|
|
62
|
+
},
|
|
63
|
+
"required": ["skill", "entry", "fields"],
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _err(msg: str) -> dict:
|
|
69
|
+
return {"success": False, "tool": TOOL_NAME, "data": {}, "error": msg}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _load_settings() -> dict:
|
|
73
|
+
try:
|
|
74
|
+
raw = json.loads(_SETTINGS.read_text(encoding="utf-8"))
|
|
75
|
+
except (OSError, ValueError, TypeError):
|
|
76
|
+
return {}
|
|
77
|
+
return raw if isinstance(raw, dict) else {}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _save_settings(data: dict) -> None:
|
|
81
|
+
_SETTINGS.parent.mkdir(parents=True, exist_ok=True)
|
|
82
|
+
tmp = _SETTINGS.with_suffix(".json.tmp")
|
|
83
|
+
tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
84
|
+
os.replace(tmp, _SETTINGS)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def skill_config_write(skill: str, entry: str, fields: dict,
|
|
88
|
+
active: bool = False) -> dict:
|
|
89
|
+
sk = str(skill or "").strip()
|
|
90
|
+
name = str(entry or "").strip()
|
|
91
|
+
if sk not in _FIELDS:
|
|
92
|
+
return _err("这个技能没有配置写入口:%s(可写:%s)"
|
|
93
|
+
% (sk or "(空)", " / ".join(sorted(_FIELDS))))
|
|
94
|
+
if not name:
|
|
95
|
+
return _err("entry 不能为空(它是设置页里那一行的名字)。")
|
|
96
|
+
if not isinstance(fields, dict) or not fields:
|
|
97
|
+
return _err("fields 必须是非空对象(键 -> 值)。")
|
|
98
|
+
|
|
99
|
+
allowed = _FIELDS[sk]
|
|
100
|
+
bad = sorted(k for k in fields if k not in allowed)
|
|
101
|
+
if bad:
|
|
102
|
+
return _err("不认识的字段:%s(这个技能可写:%s)"
|
|
103
|
+
% ("、".join(bad), "、".join(allowed)))
|
|
104
|
+
|
|
105
|
+
data = _load_settings()
|
|
106
|
+
block = data.get("skill_configs")
|
|
107
|
+
if not isinstance(block, dict):
|
|
108
|
+
block = {}
|
|
109
|
+
data["skill_configs"] = block
|
|
110
|
+
section = block.get(sk)
|
|
111
|
+
if not isinstance(section, dict):
|
|
112
|
+
section = {}
|
|
113
|
+
block[sk] = section
|
|
114
|
+
entries = section.get("entries")
|
|
115
|
+
if not isinstance(entries, dict):
|
|
116
|
+
entries = {}
|
|
117
|
+
section["entries"] = entries
|
|
118
|
+
row = entries.get(name)
|
|
119
|
+
if not isinstance(row, dict):
|
|
120
|
+
row = {}
|
|
121
|
+
entries[name] = row
|
|
122
|
+
|
|
123
|
+
written: list[str] = []
|
|
124
|
+
skipped: list[str] = []
|
|
125
|
+
for k in allowed:
|
|
126
|
+
if k not in fields:
|
|
127
|
+
continue
|
|
128
|
+
v = fields.get(k)
|
|
129
|
+
s = str(v if v is not None else "").strip()
|
|
130
|
+
if not s:
|
|
131
|
+
# 空值不覆盖:静默清掉口令是最坏的一种"帮了倒忙"。
|
|
132
|
+
skipped.append(k)
|
|
133
|
+
continue
|
|
134
|
+
row[k] = s
|
|
135
|
+
written.append(k)
|
|
136
|
+
|
|
137
|
+
if not written and not skipped:
|
|
138
|
+
return _err("没有可写的字段。")
|
|
139
|
+
if not written:
|
|
140
|
+
return _err("所有字段都是空值(空值表示不修改);什么都没写。")
|
|
141
|
+
|
|
142
|
+
if active:
|
|
143
|
+
section["active"] = name
|
|
144
|
+
_save_settings(data)
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
"success": True,
|
|
148
|
+
"tool": TOOL_NAME,
|
|
149
|
+
"data": {
|
|
150
|
+
"skill": sk,
|
|
151
|
+
"entry": name,
|
|
152
|
+
"written": written,
|
|
153
|
+
#: 秘密只记名字,不记值。
|
|
154
|
+
"secret_fields": [k for k in written if k in _SECRET_FIELDS],
|
|
155
|
+
"unchanged_empty": skipped,
|
|
156
|
+
"active": bool(active),
|
|
157
|
+
},
|
|
158
|
+
"error": "",
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def register() -> None:
|
|
163
|
+
from bus.registry import register_tool
|
|
164
|
+
register_tool(TOOL_NAME, skill_config_write, SCHEMA)
|
package/core/skill_factory.py
CHANGED
|
@@ -338,8 +338,8 @@ def create_skill(name: str = "", manifest_yaml=None, handler_py=None,
|
|
|
338
338
|
if tmp_dir.exists():
|
|
339
339
|
shutil.rmtree(tmp_dir, ignore_errors=True)
|
|
340
340
|
|
|
341
|
-
print("[skill] create_skill
|
|
342
|
-
% (name, len(tools), ("
|
|
341
|
+
print("[skill] create_skill created draft %s (%d tools)%s"
|
|
342
|
+
% (name, len(tools), (", forced " + "; ".join(forced)) if forced else ""))
|
|
343
343
|
|
|
344
344
|
return {
|
|
345
345
|
"success": True,
|
package/core/skill_guidance.py
CHANGED
|
@@ -230,12 +230,10 @@ def _read_domain(skill: str) -> str:
|
|
|
230
230
|
return ""
|
|
231
231
|
text = path.read_text(encoding="utf-8").strip()
|
|
232
232
|
except Exception as exc: # 判据 4:不静默,但也不阻断对话
|
|
233
|
-
print(f"[skill_guidance]
|
|
234
|
-
f" —— 这个 skill 本轮不带领域片段")
|
|
233
|
+
print(f"[skill_guidance] cannot read {path} ({type(exc).__name__}: {exc}) - this skill gets no domain guidance this turn")
|
|
235
234
|
return ""
|
|
236
235
|
if len(text) > _MAX_DOMAIN_CHARS:
|
|
237
|
-
print(f"[skill_guidance] {path}
|
|
238
|
-
f"{_MAX_DOMAIN_CHARS} —— 已截断(它是按条计费的,请写短些)")
|
|
236
|
+
print(f"[skill_guidance] {path} has {len(text)} chars, exceeds {_MAX_DOMAIN_CHARS} - truncated (billed per request, please write shorter)")
|
|
239
237
|
text = text[:_MAX_DOMAIN_CHARS].rstrip() + "..."
|
|
240
238
|
return text
|
|
241
239
|
|
package/core/skill_index.py
CHANGED
|
@@ -108,16 +108,15 @@ def fit_listing(lines: List[str], budget: int) -> List[str]:
|
|
|
108
108
|
heads = [split_line(x)[0] for x in lines]
|
|
109
109
|
names_only = sum(len(h) for h in heads)
|
|
110
110
|
if budget <= names_only:
|
|
111
|
-
print("[skill_listing]
|
|
111
|
+
print("[skill_listing] over budget (%d lines %d chars > %d) - names only"
|
|
112
112
|
% (len(lines), total, budget))
|
|
113
113
|
return heads
|
|
114
114
|
|
|
115
115
|
per = max(1, (budget - names_only) // max(1, len(lines)))
|
|
116
116
|
per = min(per, SKILL_LISTING_DESC_CAP) # 每个 skill 的描述上限
|
|
117
117
|
out = [h + _cut(x[len(h):], per) for x, h in zip(lines, heads)]
|
|
118
|
-
print("[skill_listing]
|
|
119
|
-
|
|
120
|
-
"`SLASH_COMMAND_TOOL_CHAR_BUDGET`)" % (len(lines), total, budget))
|
|
118
|
+
print("[skill_listing] over budget: %d lines %d chars > %d - descriptions truncated"
|
|
119
|
+
% (len(lines), total, budget))
|
|
121
120
|
return out
|
|
122
121
|
|
|
123
122
|
|
package/core/skill_settings.py
CHANGED
|
@@ -106,7 +106,7 @@ def load(skill_name: str) -> dict:
|
|
|
106
106
|
try:
|
|
107
107
|
data = json.loads(p.read_text(encoding="utf-8"))
|
|
108
108
|
except Exception as exc: # noqa: BLE001
|
|
109
|
-
print("[skill-settings] %s
|
|
109
|
+
print("[skill-settings] %s unreadable: %s: %s" % (p, type(exc).__name__, exc))
|
|
110
110
|
return {}
|
|
111
111
|
return data if isinstance(data, dict) else {}
|
|
112
112
|
|
package/core/skill_sources.py
CHANGED
|
@@ -65,9 +65,9 @@ _REPO_SKILLS_ABS = Path(__file__).resolve().parent.parent / "skills"
|
|
|
65
65
|
#: · `~/.agents/skills` 跨 agent 的共享约定,几个 agent 工具都往这里放
|
|
66
66
|
#: · 项目级 `.agents/skills/` 同族,跟着项目走
|
|
67
67
|
#: · `~/.claude/skills/` 别人的目录;我们只读,不写
|
|
68
|
-
#: · `~/.codex/skills/.system`
|
|
68
|
+
#: · `~/.codex/skills/.system` 该工具的内置技能目录(点开头是根的一部分,
|
|
69
69
|
#: 所以不经过"跳过点开头条目"那条规则)
|
|
70
|
-
#: · `~/.workbuddy/plugins/cache`
|
|
70
|
+
#: · `~/.workbuddy/plugins/cache` 该工具的已安装插件目录
|
|
71
71
|
#: (深度 5:`<市场>/<插件>/<版本>/SKILL.md` 与
|
|
72
72
|
#: `<市场>/<插件>/<版本>/skills/<技能>/SKILL.md` 两种布局都在里面)
|
|
73
73
|
#:
|
|
@@ -120,13 +120,13 @@ def _workspace_plugins_ok() -> bool:
|
|
|
120
120
|
from core.plugin_packages import workspace_plugins_allowed
|
|
121
121
|
ok = workspace_plugins_allowed()
|
|
122
122
|
except Exception as exc: # noqa: BLE001
|
|
123
|
-
print("[skills]
|
|
123
|
+
print("[skills] reading workspace plugin switch failed (treating as off): %s: %s"
|
|
124
124
|
% (type(exc).__name__, exc))
|
|
125
125
|
return False
|
|
126
126
|
if not ok and not _WS_PLUGIN_NOTE_SHOWN:
|
|
127
127
|
_WS_PLUGIN_NOTE_SHOWN = True
|
|
128
|
-
print("[skills]
|
|
129
|
-
"
|
|
128
|
+
print("[skills] skills from workspace plugin packages were not loaded: enable "
|
|
129
|
+
"Settings -> Security -> Workspace Plugins first (same switch as hooks and MCP servers).")
|
|
130
130
|
return ok
|
|
131
131
|
|
|
132
132
|
|
|
@@ -143,8 +143,8 @@ def _workspace_plugins_ok() -> bool:
|
|
|
143
143
|
#: 只列随框架发布的那些。测试夹具(draft、从不装载、不进安装包)不在这张表里 ——
|
|
144
144
|
#: 登记一个包里没有的名字,会让用户自己装的同名技能被标成"内置"而藏起来。
|
|
145
145
|
BUILTIN_SKILLS: frozenset[str] = frozenset({
|
|
146
|
-
"entertainment", "file_parser", "github", "mail_parser",
|
|
147
|
-
"office_parser", "ppt-master",
|
|
146
|
+
"diagram", "entertainment", "file_parser", "github", "mail_parser",
|
|
147
|
+
"media_gen", "netops", "office_parser", "ppt-master", "ssh",
|
|
148
148
|
})
|
|
149
149
|
|
|
150
150
|
|