Skip to content

Skills Phase 3: ClawHub search + slug install - #59

Merged
FMXExpress merged 2 commits into
mainfrom
claude/pr57-skills-clawhub
May 28, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/pr57-skills-clawhub

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Phase 3 of the 4-PR skills roadmap. After #55 (SKILL.md format) and #56 (GitHub install), this PR ships the ClawHub slug-based registry — same one picoclaw and nanobot use. Phase 4 (scripts/ + references/ runtime) stacks next.

New surface

pasclaw skills install code-review            # ClawHub: latest version
pasclaw skills install [email protected]      # ClawHub: pinned version
pasclaw skills search "code review"           # ClawHub: search

Pipeline (PasClaw.Skills.ClawHub)

  1. Validate slug (lowercase alphanumerics + -/_) before any network round-trip
  2. Refuse if destination exists — pasclaw skills remove <slug> first
  3. Best-effort metadata fetch (GET /api/v1/skills/<slug>) for moderation flags + latestVersion:
    • isMalwareBlocked: true → refuse install
    • isSuspicious: true → warn and proceed
    • Metadata fetch failure → advisory, proceed without it (picoclaw does the same)
  4. Resolve version: caller's pin → metadata's latestVersion → latest
  5. Download GET /api/v1/download?slug=<slug>&version=<version> to a temp zip. 64 MiB cap.
  6. Extract via PasClaw.Skills.Zip (Zipper.TUnZipper ↔ System.Zip.TZipFile)
  7. Find SKILL.md: at extraction root, or descend into a single top-level wrapper directory (ClawHub archives are inconsistent here; picoclaw's extractor tolerates both)
  8. Validate by re-parsing the SKILL.md through ParseSkillMD
  9. Copy the tree into workspace/skills/<slug>/. Cleans up temp dir always; removes partial destination on failure

Search (SearchClawHub)

Decodes the {results:[{slug,displayName,summary,version,score}]} envelope into a TClawHubResultArray. Missing fields fall back gracefully. Empty response and an empty result array are distinct from an HTTP error.

CLI dispatch order (Cmd.Skills)

IsGitHubTarget(target)  → InstallFromGitHub    (owner/repo[/path][@ref])
IsClawHubSlug(target)   → InstallFromClawHub   (lowercase slug[@version])
otherwise               → legacy config-only flow

IsClawHubSlug enforces the same character set ClawHub validates server-side so pasclaw skills install Foo (mixed case) falls through to the legacy path with a clear deprecation message rather than 404'ing on ClawHub.

New pasclaw skills search <query> subcommand prints slug / version / displayName / summary in a tabular layout with a pointer at pasclaw skills install <slug> for installation.

Trade-offs

The CopyTree / RemoveTree / DownloadZip helpers are intentionally local to this unit rather than extracted into a Skills.Shared — keeping each registry independent reads better and the duplication is ~80 LOC across two units. If a fourth registry shows up that would tip the balance toward a shared helper.

Not in this PR (Phase 4)

scripts/ (auto-callable helpers; agent invokes via shell_exec in the sandbox) + references/ (path-only in system prompt; loaded into context on demand via fs_read) runtime support. Stacked as the next PR — needs the SKILL.md parser to walk the per-skill directory rather than just parse the file.

Test plan

  • FPC build (make) + Delphi .dproj build cleanly
  • pasclaw skills search code — prints any matching results from the live ClawHub
  • pasclaw skills search asdfasdfnomatch12345 — prints (no matches)
  • pasclaw skills install <real-slug-from-search> — succeeds; pasclaw skills list shows the new entry
  • pasclaw skills install nonexistent-slug — fails with download failed: not found, no temp files left over
  • pasclaw skills install Foo (mixed case) — falls through to the legacy config-only path with the existing deprecation hint
  • pasclaw skills install owner/repo — still routes to the GitHub installer (PR Skills Phase 2: install from GitHub via codeload zip + native zip extract #56 path unchanged)
  • pasclaw skills install code-review@<real-version> — pins version; latest resolution unaffected
  • Existing skills list / skills remove paths unchanged

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

`pasclaw skills install <slug>[@<version>]` now resolves through
ClawHub (https://clawhub.ai), the registry picoclaw and nanobot
standardised on. `pasclaw skills search <query>` queries the same
endpoint and prints result rows so users can discover skills
without leaving the CLI.

New unit src/pkg/skills/PasClaw.Skills.ClawHub:

  SearchClawHub(Query, Limit, out Results, out ErrMsg)
    GET /api/v1/search?q=<query>&limit=<n>
    Decodes the {results:[{slug,displayName,summary,version,
    score}]} envelope into a TClawHubResultArray. Missing fields
    fall back gracefully (DisplayName -> Slug, Summary -> '').
    Empty response and an empty result array are distinct from an
    HTTP error.

  InstallFromClawHub(Slug, Version, DestRoot, out InstalledName,
                     out ErrMsg)
    Pipeline:
      1. Validate the slug (lowercase alphanumerics + '-'/'_') so
         a typo does not turn into a 404 round-trip.
      2. Refuse if the destination directory already exists.
      3. Best-effort metadata fetch (/api/v1/skills/<slug>) for
         moderation flags + latestVersion. Failure here is
         advisory — picoclaw treats it the same way. A
         malware-flagged skill refuses the install outright; a
         suspicious flag logs a warning and proceeds.
      4. Resolve version: caller's pin -> metadata's
         latestVersion -> 'latest' (the endpoint default).
      5. GET /api/v1/download?slug=<slug>&version=<version> into
         a temp zip. 64 MiB cap.
      6. Extract via PasClaw.Skills.Zip.
      7. FindSkillRoot looks for SKILL.md at the extraction root
         first, then descends into a single top-level wrapper
         directory (ClawHub archives sometimes have the wrapper,
         sometimes not — picoclaw's extractor handles both, so
         do we).
      8. Validate by re-parsing the installed SKILL.md.
      9. Copy the tree into workspace/skills/<slug>/. Cleans up
         the temp directory always; removes the partial
         destination on failure.

  Minimal in-unit helpers: UrlEncode (RFC 3986 percent-encoder
  for query-string values), IsValidSlug (matches picoclaw's
  utils.ValidateSkillIdentifier behaviour), PlatformTempDir +
  UniqueSuffix (same shape as the GitHub unit). The CopyTree /
  RemoveTree / DownloadZip helpers are intentionally local to
  this unit rather than extracted into a shared "skills.shared"
  — keeping each registry independent reads better and the
  duplication is ~80 LOC across two units.

Cmd.Skills changes:

  install dispatches in this order:
    IsGitHubTarget(target)  -> InstallFromGitHub
    IsClawHubSlug(target)   -> InstallFromClawHub
    otherwise               -> legacy "record in config.json"

  IsClawHubSlug enforces the same character set ClawHub validates
  server-side so e.g. `pasclaw skills install Foo` (mixed case)
  falls through to the legacy path with a clear deprecation
  message rather than 404'ing on ClawHub. `@<version>` suffix is
  permitted and split out by SplitSlugAtVersion before the
  install call.

  New `pasclaw skills search <query>` subcommand prints
  slug / version / displayName / summary in a tabular layout
  with a one-liner pointing at `pasclaw skills install <slug>`
  for installation.

  Help text refreshed; head-of-file docstring updated to reflect
  the new dispatch order.

README documents the new install + search forms under a "ClawHub
install (Phase 3, this release)" subsection alongside the
existing GitHub install paragraph.

Not in this PR (Phase 4 of the roadmap):

  - scripts/ (auto-callable helpers; agent invokes via shell_exec)
    + references/ (lazy-loaded into context) runtime support.
    Stacked as the next PR.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8fa26d513b

ℹ️ 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".

Comment thread src/cmd/PasClaw.Cmd.Skills.pas Outdated
Comment on lines +210 to +211
else if IsClawHubSlug(Argv[1]) then
Result := DoInstallClawHub(Argv[1])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve legacy installs for slug-shaped names

When the legacy skill name is any lowercase single path segment such as the documented my-skill, this new branch treats it as a ClawHub slug before the legacy path can run. Existing scripts that used pasclaw skills install my-skill to record a config-only skill will now either fail on a ClawHub 404 or install an unrelated registry skill if that slug exists, so the backward-compatible legacy flow is no longer available for common names unless they contain invalid slug characters.

Useful? React with 👍 / 👎.

Comment on lines +244 to +245
Root := TJsonObject.Parse(Body);
if Root = nil then Exit;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle malformed metadata as advisory

For a 200 response from /api/v1/skills/<slug> that is not valid JSON, TJsonObject.Parse raises EPasClawJSON, so the Root = nil fallback is never reached and skills install <slug> aborts before downloading. This contradicts the best-effort metadata behavior described in this function; wrap the parse in try/except and leave the default LatestVersion/Blocked/Suspicious values on parse errors.

Useful? React with 👍 / 👎.

…metadata

Two legit P2 findings from the chatgpt-codex review on PR #59.

1. Slug-shaped legacy installs broke
   `pasclaw skills install my-skill` had been documented for the
   legacy config.json-only flow, and Phase 3's IsClawHubSlug
   matched any lowercase alphanumeric-with-hyphen target — so a
   pre-existing script using the legacy command would suddenly
   either 404 on ClawHub or, worse, silently install an unrelated
   registry skill that happened to share the slug.

   Fix: require an explicit `clawhub:` prefix for the ClawHub
   path. Rename IsClawHubSlug -> IsClawHubTarget which checks
   the prefix, then validates the rest as a slug. Bare
   slug-shaped names fall through to the legacy path
   unchanged, preserving backwards compat.

   The dispatcher now checks ClawHub before GitHub so a
   pathological `clawhub:owner/repo` would hit the ClawHub
   validator (which rejects the slash) and fall through to
   legacy, rather than GitHub eating the slash and trying to
   fetch `clawhub:owner/repo` as a real codeload URL.

   README, help text, and the unit-header docstring all
   updated to the new `clawhub:<slug>[@<version>]` form.

2. Malformed metadata JSON aborted the install
   FetchMetadata was documented as best-effort but
   TJsonObject.Parse raises EPasClawJSON on bad JSON rather
   than returning nil — so a 200 response with garbage in the
   body bypassed the `Root = nil` fallback and propagated up
   to Cmd.Skills as an unhandled exception, refusing the
   install before download.

   Fix: wrap TJsonObject.Parse in try/except in FetchMetadata
   (proceed with default Latest/Blocked/Suspicious values on
   parse error, matching the documented "metadata is
   advisory" contract). Same wrapper added to SearchClawHub,
   but there a parse failure IS a search error so it surfaces
   through ErrMsg instead of being silently swallowed.

   Both wrappers initialize Root to nil before the try so the
   outer Root.Free in the finally block is safe on the parse
   failure path.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants