✨ [Feature]: kit 提供 GitHub Skill URL 解析(含斜杠分支名消歧)

Aperta
#434 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
github, typescript

Direzione di ricerca

Start by reading packages/components/src/skill-import-form/validation.ts and the existing resolveGithubRef entry point, then compare the two proposed API directions. Done means slash-containing branch names resolve against repository refs, errors distinguish invalid URLs, missing refs, and missing directories, the resolved ref and path are returned, and the specified split cases are covered by tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
What problem does this feature solve

GitHub 的 tree URL 中,分支名与目录名之间没有分隔符,字符串本身存在歧义:

https://github.com/opentiny/tiny-robot/tree/feature/demo/skills/example

既可能是「分支 feature + 目录 demo/skills/example」,也可能是「分支 feature/demo + 目录 skills/example」。GitHub 网页端会用仓库真实 refs 解析这个边界,而客户端只能猜。

当前状态:

  • 组件库 packages/components/src/skill-import-form/validation.ts 固定取 tree 后第一段作为 ref,导致含 / 的分支名导入失败并返回 404;
  • PR #429 已经在该组件内做了缓解(提交 068ed65e):枚举所有 ref/目录拆分,默认 resolver 仅在 404 时回退到下一个候选;
  • 但这只是客户端逐次试探,不是按仓库真实 refs 判定:如果两个拆分都真实存在且都含合法 SKILL.md,仍会优先采用短 ref 的解释;调用方使用自定义 resolver 时也拿不到候选信息。

期望:由 kit 提供基于仓库真实 refs 的消歧能力,让所有调用方都能正确解析这类 URL。

What does the proposed API look like

方向一(推荐):让 kit 在缺少确定 ref 时基于 GET /repos/{owner}/{repo}/git/matching-refs/heads/{prefix} 匹配最长分支前缀:

await loadSkillWithDetails({
  source: 'github',
  repo: 'owner/repo',
  path: 'skills/example',
  // ref 省略时按默认分支;提供 refPrefix 时按仓库 refs 消歧
  refPrefix: 'feature/demo',
})

方向二:接受候选列表,由 loader 依次尝试并在成功后返回实际使用的 ref:

await loadSkillWithDetails({
  source: 'github',
  repo: 'owner/repo',
  pathCandidates: [
    { ref: 'feature', path: 'demo/skills/example' },
    { ref: 'feature/demo', path: 'skills/example' },
  ],
})

无论采用哪种方式,都建议在结果中回传实际解析到的 ref 与 path,便于调用方展示与调试。

What is your project name

TinyRobot(组件库 Skill 导入流程,PR #429 评审过程中提出)

Any additional comments (optional)

归属说明

本 issue 是设计取舍项,不是严格意义上的 loader 缺陷:loader 接收的是已经拆分好的 { repo, ref, path },看不到原始 URL,因此无法自行发现歧义。但 loader 具备 repo 上下文与网络能力(resolveGithubRef 已经在缺省 ref 时请求 /repos/{repo}),是本能力更合适的落点。

验收标准

  • 含 / 的分支名可以正确导入;
  • 消歧失败时给出可区分的错误(URL 无效 / ref 不存在 / 目录不存在);
  • 结果或回调中可获取实际使用的 ref 与 path;
  • 测试覆盖:短 ref 优先命中、长 ref 命中、两个拆分都不存在;
  • 若无网络请求的消歧方案被否决,需要在文档注释中明确「不支持含 / 的分支名」,让调用方在同一层做补偿。
Lingua principale
TypeScript
Stelle
109
Fork
19
Merge medio
1g 21h
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di opentiny/tiny-robot

Tutte le issue di opentiny/tiny-robot

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.