Repository navigation
Skills Phase 2: install from GitHub via codeload zip + native zip extract - #56
Conversation
…ract `pasclaw skills install owner/repo[/sub/path][@ref]` now downloads a zip snapshot from codeload.github.com, extracts it through the bundled zip library on each toolchain (no tar dependency), locates the requested SKILL.md, validates it through ParseSkillMD, and copies the containing directory tree under workspace/skills/. This closes the gap with picoclaw and nanobot, whose users install skills the same way today. New units in src/pkg/skills/: PasClaw.Skills.Zip Cross-toolchain extractor exposing one function: ExtractZipToDir(ZipPath, DestDir, out ErrMsg): Boolean {$IFDEF FPC} Zipper.TUnZipper (fcl-base; bundled with FPC) {$ELSE} System.Zip.TZipFile (RTL since Delphi XE2) No tar — Delphi has native zip; making FPC do tar just to share one format would have been the wrong direction. PasClaw.Skills.GitHub InstallFromGitHub(Target, DestRoot, out InstalledName, out ErrMsg) Pipeline: 1. Parse Target into (Owner, Repo, SubPath, Ref). Ref is the part after '@' if any; '@' cannot appear in GitHub repo names so the split is unambiguous. 2. Refuse if the destination directory already exists. No --force flag yet — `pasclaw skills remove <name>` first. 3. Download a zip snapshot to a unique temp directory. codeload.github.com/<owner>/<repo>/zip/refs/heads/<ref> redirects to S3; Indy follows redirects so it is one Get. If no ref was specified, try `main` then fall back to `master`. 64 MiB cap on the download. 4. Extract via PasClaw.Skills.Zip. 5. GitHub zips wrap entries in `<repo>-<ref>/`; locate that wrapper, descend into SubPath, copy the resulting tree into the destination. 6. Validate by re-parsing the installed SKILL.md. Reject malformed skills here rather than letting them land on disk and surface as warnings in `pasclaw skills list`. 7. Clean up the temp directory always; remove the partial destination on any failure path. PasClaw.Providers.HTTP grows one helper: GetURLToStream(URL, Stream, Headers, Timeout): THTTPResult Mirrors PostJSON's shape but for binary GETs — zip downloads, embedding fetches, etc. Uses the existing NewClient + OpenSSL probe path so it picks up Indy's TLS configuration without duplication. TStringStream's UTF-8 decoding would corrupt binary payloads; this is the necessary alternative. Cmd.Skills changes: install dispatches on the target shape via IsGitHubTarget — a string containing '/' that does not begin with '.', '/', '\', or a Windows drive letter is treated as owner/repo[/path]. Anything else falls through to the legacy "record name in config.json" flow so existing workflows do not regress. remove now deletes the workspace directory and the legacy <name>.json file alongside clearing the config.json entry. The CLI gives green ✓ / yellow notice depending on whether anything was actually on disk to remove. Help text updated. README updated with the new install forms and a short paragraph explaining the pipeline + the ZIP-not-tar rationale. Cross-toolchain detail: temp-dir + tick helpers used in the installer are factored as PlatformTempDir + UniqueSuffix so we avoid GetTickCount (Windows-only) and the GetTempDir signature mismatch between FPC and Delphi. UniqueSuffix uses milliseconds since epoch + Random(1<<30) which is fine for an interactive CLI; collisions across two concurrent installs in the same millisecond are vanishingly unlikely and the random tail covers it. Not in this PR (Phase 3 + 4 of the roadmap): - ClawHub registry — slug-based search + install via clawhub.ai; needs a small JSON HTTP client + their API surface. Sequenced next. - scripts/ (callable helpers) + references/ (lazy-loaded context) runtime support — leverages the directory layout this PR + #55 enabled. - Local-path install (skills install ./path) — currently still falls through to the legacy "record in config.json" form; will grow a real "copy local directory into workspace" handler. - --force overwrite of existing installs. - Multi-skill installs from a single repo (some repos ship 5+ skills in subdirectories). https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06c170bc44
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| function CodeloadURL(const Owner, Repo, Ref: string): string; | ||
| begin | ||
| Result := Format('https://codeload.github.com/%s/%s/zip/refs/heads/%s', |
There was a problem hiding this comment.
Support non-branch refs in codeload URLs
The help and parser advertise owner/repo[/path]@ref for branches, tags, and commits, but this URL builder always prefixes the ref with refs/heads/. When a user pins a released skill such as owner/repo/[email protected] or a commit SHA, the installer requests a branch by that name and fails with 404 even though the tag/SHA archive exists. The URL construction needs to handle tags/SHAs (or use a codeload endpoint that accepts arbitrary refs) instead of hard-coding branch refs.
Useful? React with 👍 / 👎.
| if DirectoryExists(JoinPath(WorkspaceDir, Argv[1])) then | ||
| begin | ||
| RemoveSkillDir(JoinPath(WorkspaceDir, Argv[1])); |
There was a problem hiding this comment.
Keep removals inside the skills directory
This uses the raw CLI argument as a path component before recursively deleting it; JoinPath only concatenates, so a name like ../memory resolves outside workspace/skills and pasclaw skills remove ../memory can delete another workspace directory. Since this commit adds on-disk deletion for remove <name>, validate that the requested skill name is a single safe path segment (or canonicalize and check it remains under the skills root) before calling RemoveSkillDir.
Useful? React with 👍 / 👎.
…ame on remove Two P2 findings from the chatgpt-codex review on PR #56, both legit. 1. Non-branch refs 404'd CodeloadURL hardcoded `refs/heads/<ref>` which only resolves branches. `pasclaw skills install owner/repo/[email protected]` (tag) or `@<sha>` (commit) silently failed with "not found" even though the codeload archive exists under a different URL shape. Fix: split the URL builder. CodeloadBranchURL(Owner, Repo, Branch) Same `refs/heads/<branch>` form — used for the implicit main->master fallback so a tag/PR-branch with the same name as a default branch never wins by accident. CodeloadAnyRefURL(Owner, Repo, Ref) Short codeload form `/zip/<ref>` — accepts branches, tags, and commit SHAs uniformly. Used for the explicit `@ref` pin. The install pipeline now chooses based on whether the user supplied a ref. Explicit refs make one attempt against the short form (404 = ref does not exist; trying main/master would be wrong); implicit refs try main then master against the branch-specific form. 2. Path traversal in `pasclaw skills remove <name>` This commit's `remove` newly deletes from disk, not just config. RemoveSkillDir(JoinPath(WorkspaceDir, Argv[1])) passes Argv[1] through without canonicalisation, so `pasclaw skills remove ../memory` would resolve to `<home>/workspace/memory` and recursively delete it. Same shape as the classic CVE pattern. Fix: IsSafeSkillName rejects '/', '\', ':', NUL..ctrl chars, the literal '.' and '..' names, and any name containing the '..' substring. Refuses on the remove path with a clear error message. Skills installed via InstallFromGitHub get their names from URL path segments — none of the rejected characters can appear there — so legitimate installs are unaffected. (Install side is safe: InstalledName is derived from a known subpath, and the destination existence check would catch any weird name before it landed on disk.) https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Phase 2 of the 4-PR skills roadmap. After #55 landed the SKILL.md format, this PR makes it usable end-to-end —
pasclaw skills install owner/repo[/path][@ref]downloads a zip, extracts it natively, validates the SKILL.md, and drops the result underworkspace/skills/. Same UX picoclaw and nanobot ship for the GitHub registry.New surface
Pipeline (
PasClaw.Skills.GitHub)(Owner, Repo, SubPath, Ref).@cannot appear in GitHub repo names → unambiguous split.--forceyet;pasclaw skills remove <name>first if you need to reinstall.codeload.github.com/<owner>/<repo>/zip/refs/heads/<ref>(it 302s to S3, Indy follows redirects). No@ref→ trymainthen fall back tomaster. 64 MiB cap.PasClaw.Skills.Zip:{$IFDEF FPC}→Zipper.TUnZipper(fcl-base, bundled with FPC){$ELSE}→System.Zip.TZipFile(RTL since Delphi XE2)<repo>-<ref>/), descend into the requested SubPath.ParseSkillMD— refuses malformed skills here instead of letting them surface as warnings inpasclaw skills list.workspace/skills/<InstalledName>/. Cleans up the temp directory always; removes the partial destination on any failure.New helper
PasClaw.Providers.HTTP.GetURLToStream(URL, Stream, Headers, Timeout)— natural binary counterpart toPostJSON. ReusesNewClient+ the existing OpenSSL probe so it picks up Indy's TLS config without duplication.CLI changes (
Cmd.Skills)installnow dispatches on target shape viaIsGitHubTarget(string contains/, doesn't start with.///\/X:). Anything else falls through to the legacy "record name in config.json" path so existing workflows don't regress.removenow deletes the workspace directory and legacy<name>.jsonalongside clearing the config entry.Cross-toolchain details
PlatformTempDir—GetTempDir(FPC) vsTPath.GetTempPath(Delphi)UniqueSuffix—MilliSecondsBetween(Now, EncodeDate(1970,1,1)) + Random(1 shl 30)to avoid the Windows-onlyGetTickCount. Collisions vanishingly unlikely for interactive CLI use; the random tail covers concurrent installs in the same millisecond.Not in this PR (sequenced next)
pasclaw skills install code-review→ resolve via clawhub.ai → install via Skills Phase 2: install from GitHub via codeload zip + native zip extract #56's pipeline).scripts/+references/runtime support (callable helpers; lazy-loaded context).--forceoverwrite../pathcurrently falls through to the legacy config-only flow).owner/reporepos that ship N skills in subdirectories).Test plan
make) + Delphi.dprojbuild cleanlypasclaw skills install anthropics/anthropic-quickstarts/agents/skills/file_io(or any public skill repo that ships SKILL.md at a subpath) — succeeds;pasclaw skills listshows the new entry with pathpasclaw skills install does-not-exist/nope— fails withdownload failed: not found, no temp files left over (ls /tmp/pasclaw-skill-*after)pasclaw skills install someone/repo-with-no-skill— fails with the "no SKILL.md at the root" hint pointing at subpath syntaxpasclaw skills install owner/repothenpasclaw skills install owner/repoagain — second call refuses with "already exists" and a hint toskills removefirstpasclaw skills remove <name>— deletes the workspace directory AND clears the config entry (green ✓); for a name that doesn't exist anywhere, yellow noticepasclaw agentafter install — the new skill appears in the system prompt's SKILLS section with the full SKILL.md path; model canfs_readitpasclaw skills install owner/[email protected]works against a real tag,@nonexistent-reffails cleanlypasclaw skills install my-skill(no slash) still records in config.json as before — no regressionhttps://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code