🐛 [Bug]: kit GitHub loader 编码处理不规范,导致请求截断与路径匹配失败
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 74/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- github, typescript
Línea de trabajo
Start in packages/kit/src/skills/loader/github.ts, especially the contents URL construction, normalizeRepoPath, and toSkillRelativePath; read packages/kit/src/skills/loader/definition.ts to understand the entry-file lookup. Run the existing GitHub loader tests, then cover encoded paths and #/? paths, including recursive entries. Done means requests preserve encoded path segments, path handling is explicit, and out-of-root paths produce a locating error without breaking the existing weather case.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Tiny Robot Version
0.5.1(@opentiny/tiny-robot-kit),develop 分支 ab3999df3
Vue Version
不涉及,kit 包与 Vue 无关;两个问题都在 loader 的路径处理上
Link to minimal reproduction
问题一:contents 请求 URL 未编码(目录名含 # / ?)
const sourcePath = 'skills/a#b' // 仓库中真实存在的目录名
const url = new URL(`https://api.github.com/repos/o/r/contents/${sourcePath}`)
url.searchParams.set('ref', 'main')
console.log(url.pathname) // /repos/o/r/contents/skills/a ← #b 被当成 fragment 丢弃
console.log(url.hash) // #b
问题二:路径比较未按编码规范化(目录名含空格 / 中文)
import { loadSkillWithDetails } from '@opentiny/tiny-robot-kit'
// 路径来自 URL 片段,仍是百分号编码形态
await loadSkillWithDetails({ source: 'github', repo: 'owner/repo', ref: 'main', path: 'my%20skill' })
// 抛出:Skill entry file "SKILL.md" is missing.
// 同一个目录用解码后的路径调用则完全正常
await loadSkillWithDetails({ source: 'github', repo: 'owner/repo', ref: 'main', path: 'my skill' }) // OK
Steps to reproduce
问题一:
- 在 GitHub 仓库准备目录名包含
#或?的 Skill,例如skills/a#b/SKILL.md。 - 调用
loadSkillWithDetails({ source: 'github', repo, ref, path: 'skills/a#b' })。 - 观察实际发出的 contents 请求路径。
问题二:
- 在 GitHub 仓库准备
my skill/SKILL.md(中文目录同样适用)。 - 用编码形态的路径
my%20skill调用loadSkillWithDetails。 - 观察抛出的错误信息。
What is expected
contents请求路径完整保留目录名,#、?等字符按 URL 规范编码为%23、%3F;递归遍历子目录时同样保持编码。- loader 对“仓库路径”这一入参给出明确契约,并对编码形态做规范化(或直接拒绝)。
- 路径不在 skill root 下时抛出可定位的错误,而不是退化成无关的入口文件错误。
What is actually happening
- 问题一:字符串模板拼接导致
#之后被解析为 fragment、?之后被解析为 query,请求实际指向父目录;若父目录存在会静默遍历错误的目录(可能导入到另一个 Skill),不存在则返回 404,错误信息与真实原因无关。 - 问题二:抛出的是
Skill entry file "SKILL.md" is missing.(组件侧再映射为「Skill 包必须包含 SKILL.md 文件」),但目录里明明有SKILL.md,排查方向被完全带偏。
What is your project name
TinyRobot(组件库 Skill 导入流程,PR #429 评审过程中发现)
Any additional comments (optional)
问题一:contents URL 拼接未编码
根因:packages/kit/src/skills/loader/github.ts:29 用字符串模板拼接 contents/${sourcePath}。sourcePath 既可能来自调用方传入的 options.path,也可能来自第 44 行递归时的 entry.path(GitHub API 返回的是未编码真实路径)。空格会被 URL 自动编码(my skill → my%20skill),但 #、? 不会,会被当作 fragment / query 分隔符。
影响:目录名或文件名含这些字符的 Skill 无法导入;更严重的是可能静默读取到错误目录内容,调用方与用户都无法察觉。
建议修复:构造 contents URL 时逐段编码。
const contentsUrl = (repo: string, path: string) => {
const url = new URL(`https://api.github.com/repos/${repo}/contents/`)
url.pathname += path.split('/').map(encodeURIComponent).join('/')
return url
}
entry.download_url 来自 API,是可直接使用的完整 URL,无需额外处理。
问题二:路径比较未按编码规范化并静默降级
根因链路:
normalizeRepoPath(github.ts:180)只做反斜杠替换与首尾斜杠清理,不处理百分号编码,skillRoot保持my%20skill。- 请求 URL 中的
%20会被 GitHub 正常解码,目录列表能取到,但返回的每项path是解码后的my skill/SKILL.md。 toSkillRelativePath(github.ts:187)用${skillRoot}/做字面前缀比较,不匹配后走到github.ts:195的兜底分支,把整个仓库路径当成相对路径返回。createSkillDefinition(packages/kit/src/skills/loader/definition.ts:25)按path === 'SKILL.md'查找入口文件,找不到,抛出 “entry file ... is missing”。
影响:任何把 URL 片段直接当作 path 传入的调用方都会踩到。组件库已在 PR #429(提交 068ed65e)先对路径做 decodeURIComponent 规避,但 loadSkillWithDetails 是 kit 的公开 API,CLI / 宿主应用仍可能传入编码路径。
建议修复:比较前对 skillRoot 与 entry.path 做统一规范化(例如按段 decodeURIComponent);不在 skill root 下时不再静默降级,直接抛出明确错误(如 Skill file "x" is outside skill root "y");在 GithubSkillLoadOptions.path 的文档注释中明确必须是未编码的仓库内路径。
修复清单
- 问题一:构造 contents URL 时逐段
encodeURIComponent,递归路径同样处理 - 问题二:路径比较前做编码规范化,且不在 skill root 下时抛出明确错误
- 回归测试:
entry.path含#/?时请求pathname包含%23/%3F - 回归测试:
my%20skill/ 中文编码路径的行为(规范化成功,或抛出明确的路径错误) - 保留现有
contents/skills/weather(未编码、无空格)用例,避免回归
关联
- 原 #431(路径比较未规范化)已并入本 issue。
- 来源:PR #429 的评审讨论 https://github.com/opentiny/tiny-robot/pull/429#discussion_r4092616799
- Lenguaje dominante
- TypeScript
- Estrellas
- 109
- Forks
- 19
- Merge medio
- 1 d 21 h
- PR fusionados (30 d)
- 25
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de opentiny/tiny-robot
-
优化文档的outline展示Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
opentiny/tiny-robot#512 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
opentiny/tiny-robot#403 ·
Los mantenedores suelen responder en 1 día
-
docs: 整理 Skill 导入与编辑文档的阅读路径和示例闭环Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
opentiny/tiny-robot#515 ·
Los mantenedores suelen responder en 1 día
-
docs: 为所有组件 API 名称补充示例锚点跳转Abierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 38/100
opentiny/tiny-robot#474 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
opentiny/tiny-robot#470 ·
Los mantenedores suelen responder en 1 día
Todos los issues de opentiny/tiny-robot
Issues similares
-
MCP tool results drop structuredContent when text is only a summaryPosiblemente ocupada @Pankaj-bit361 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
n8n-io/nod#1474 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Clean-up indicator: two polish points from the dev look (kit clock spacing, row description)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
inblockio/siwx-oidc-matrix-server#101 ·
Los mantenedores suelen responder en 1 día
-
status:needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
pingdotgg/t3code#42253 · 1 comentario ·
Los mantenedores suelen responder en 1 día