AnyBot/docs/restructure/notes/b04e-skills.md

40 lines
3.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# b04e:skills.rs(1,335 行)— 技能包(內建/市場/GitHub 安裝)
## 常數(實讀)
MAX_PACKAGE_FILES=48、MAX_PACKAGE_BYTES=6MB、MAX_RESOURCE_READ_BYTES=256KB、`ALWAYS_ALLOWED = [use_skill, read_result, ask_person, submit_plan, update_plan]`(550,技能限工具時這五個照用)。
## 結構
- `BuiltinSkill{slug,title,summary,default_on,skill_md,files}`(23)——skill_md 與 scripts 都是 **include_str! 編入**(檔在 `skills/` 資料夾根)。
- `RemoteMarketSkill{name,summary,source}`(33)。
- `GitHubSpec{owner,repo,git_ref,path}`(856)。
## BUILTIN_SKILLS(11 個,slug 實讀)
pdf、xlsx、docx、pptx、web-design、deep-research、browser-automation、skill-creator、看報快摘、每日打卡、螢幕報表存檔。前八 default_on=true,後三(看報快摘、每日打卡、螢幕報表存檔)default_on=false(逐條實讀)。pdf 附 scripts/pdf_tool.py、xlsx 附 audit_xlsx.py、docx 附 audit_docx.py(檔名照記)。
## REMOTE_MARKET(5 個)
mcp-builder、webapp-testing、doc-coauthoring、frontend-design、canvas-design——全來自 `https://github.com/anthropics/skills`(**Apache-2.0**,line 32 註記),source 為 tree/main/skills/<name>。
## 安裝與安全闸
- `slug_of(name)`(159)=資料夾安全名(中文 slug 允許)。
- `safe_rel_path(rel)`(173)=包內相對路徑檢查(擋 `..`/絕對路徑)。
- `parse_skill_markdown(text)`(238)=YAML frontmatter(name/description/license/metadata;支援 BOM+CRLF+`>-` 折行 — 1267 測試鎖實讀)。
- `walk_gh(owner, repo, git_ref, path, …)`(921)=GitHub API `repos/{o}/{r}/contents[/{path}]` 遞走,收檔案清單與總 bytes(上限 48 檔/6MB);找不到路徑→中文 Err;**要有 SKILL.md**(1003)。
- `parse_github_source(src)`(869):三种写法 — repo URL、URL 帶 /tree/ref/path、`owner/repo/path` 簡寫;另有任意 http(s) `.md` URL(1132 install_from_source)。
- `package_from_path/package_of/install_package`(1078–1099)=包 JSON 往返;`install_from_source(src)`(1133)。
## 使用面
- `takes_arguments/arguments_after/with_arguments`(412–452)=技能帶參數(空白欄代入)。
- `tool_rules(k)`(521)+`skill_allows(rules, name, args)`(553)=技能限工具:本回合只准名單內+ALWAYS_ALLOWED;超綱要先告知使用者(831 的模型提示字串逐字記)。
- `render_skill_markdown`(579)=包寫回 SKILL.md 格式。
- `discover_resources(dir)`(605)=包內資源清單;`read_resource(k, rel)`(793)=讀資源,上限 256KB。
- `load_folder_skill/load_skills_in_dir`(645/656)=資料夾式包(SKILL.md+檔案);舊單檔 .md 相容在 memory.rs(b04c)。
- `write_skill_package(skill, extra_files)`(689)=落盤成資料夾包。
- `materialize_builtin(b)`(740)→`seed_defaults(skills)`(751)→`install_builtin(slug_or_name)`(768)。
- `resolve_skill_dir(k)`(781);`format_skill_for_model(k, file, arguments)`(824)=餵模型全文(含 allowed_tools 提示段)。
## 副作用
技能資料夾在 <data>/skills/(memory.rs 的 skill_dir 同一處);包=資料夾(SKILL.md+scripts)。
## 迁移
skills.rs → **core::skills**(frontmatter/規則/包邏輯;GitHub 抓取走 net::http);`skills/` 資產目錄 → workspace 資產(b07 掃描 box/skills 時核對 include_str! 路徑)。紅線:include_str! 內容逐字=技能行為本體,動它=改功能非搬家。