Skip to content

Skills Phase 1: per-directory SKILL.md format + frontmatter parser - #55

Merged
FMXExpress merged 2 commits into
mainfrom
claude/pr55-skill-md
May 28, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/pr55-skill-md

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

First of four follow-up PRs to bring PasClaw's skill system to wire-parity with picoclaw / nanobot / Anthropic agent-skills / ClawHub. This one ships the format itself; subsequent PRs add the registry/install plumbing.

Roadmap (for reference)

  1. This PR — SKILL.md format + per-directory layout, JSON kept for backwards compat
  2. Phase 2 — pasclaw skills install owner/repo[/path] via GitHub fetch + zip extract (Delphi's System.Zip ↔ FPC's Zipper.TUnZipper; not tar)
  3. Phase 3 — ClawHub search/install client
  4. Phase 4 — scripts/ (callable helpers) + references/ (lazy-loaded context) runtime support

What this PR ships

New on-disk layout

workspace/skills/<name>/SKILL.md   ← preferred
workspace/skills/<name>.json       ← still works for backwards compat

SKILL.md format (matches picoclaw / nanobot / ClawHub byte-for-byte)

---
name: weather_report
description: Fetch weather for a city
kind: shell
shell: curl -s 'https://wttr.in/{{city}}?format=3'
schema: {"type":"object","properties":{"city":{"type":"string"}}}
---

# Weather report

Procedural knowledge the model loads on demand via fs_read.

Parser (ParseSkillMD in PasClaw.Skills.Loader)

  • Locates --- delimiters with tolerance for leading blank lines / BOMs
  • Parses simple key: value entries, strips YAML quote wrappers
  • schema: accepts inline JSON on one line (single-line is enough for the schemas skills actually need)
  • Body = everything after closing ---, trimmed
  • Returns False with ErrMsg set on malformed files so the logger can warn per-file rather than silently dropping skills

TSkillSpec extensions

Field Purpose
Body markdown body (for the SKILL.md path; empty for JSON skills)
Dir skill directory (parent of SKILL.md, or dirname of JSON file)
Source absolute path to SKILL.md / JSON — surfaced in the system prompt so the model knows where to fs_read for the full body

Kind semantics

kind: Behaviour
shell Callable; registers as skill_<name> tool, runs the rendered Shell command. Unchanged.
prompt Callable; registers as skill_<name> tool, returns the rendered Prompt template. Unchanged.
(omitted) Knowledge-only. No tool registered. SKILL.md body advertised in the system prompt's SKILLS section so the model knows to fs_read it. Dominant pattern in picoclaw / nanobot.

Loader resolution order

ScanSkillDirs → ScanJsonSkills. Per-directory entries win on name collisions. Lets users drop a SKILL.md next to an existing JSON, verify it loads, then delete the JSON when ready.

System prompt SKILLS section

## Skills

Skills extend your capabilities. Callable skills register as
`skill_<name>` tools you invoke directly; knowledge-only skills are
markdown bodies — read each one's SKILL.md with `fs_read` when the
matching task comes up.

- `skill_weather_report` — Fetch weather for a city (callable)
- **code-review** — Static review prompt. Read `/home/me/.pasclaw/
  workspace/skills/code-review/SKILL.md` for the full instructions.

Adaptive intro: shows the "callable" line only if at least one callable skill is present, the "knowledge-only" line only if at least one knowledge skill is present, both if both.

CLI

pasclaw skills list updated — shows kind + source path (relative to ~/.pasclaw when possible). Previous two-column shell/prompt view didn't surface where the skill came from; new view does.

Sample

samples/skills/hello/SKILL.md — copy-pasteable starter documenting every frontmatter field and the body conventions.

Docs

README's Skills paragraph rewritten with the new layout + backwards-compat note + roadmap pointer for Phase 2–4.

Test plan

  • FPC build (make) + Delphi .dproj build cleanly
  • pasclaw skills list with no skills installed — prints the "(no skills found)" message + the new mkdir hint
  • cp -r samples/skills/hello ~/.pasclaw/workspace/skills/ — pasclaw skills list shows it as knowledge-only with ~/workspace/skills/hello/SKILL.md as source
  • pasclaw agent "what does the hello skill do?" — model finds the SKILL.md entry in the system prompt, calls fs_read on the path, summarizes from the body
  • Convert the sample to kind: shell with a one-liner — pasclaw skills list shows it as shell, pasclaw agent "run hello" invokes the registered skill_hello tool
  • Drop an existing workspace/skills/legacy.json (old format) — still loads, listed alongside the new dir entries
  • Put a SKILL.md with name: legacy next to legacy.json — JSON gets shadowed (debug log warns); only the SKILL.md entry shows in skills list
  • Malformed SKILL.md (no frontmatter, unterminated frontmatter, missing name:) — logged at WARN, skipped, other skills still load

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

PasClaw's skill scheme was a single .json file with no body — adequate
for "one developer with three pet automations" but not wire-compatible
with the broader ecosystem (picoclaw, nanobot, ClawHub, Anthropic
agent-skills). All four of those projects use the same SKILL.md
layout: a per-skill directory with YAML frontmatter + markdown body,
optionally with scripts/, references/, and assets/ subdirectories.
This commit adds parser support for the SKILL.md format and the
per-directory layout while keeping the existing .json files loadable.

New layout, scanned from $PASCLAW_HOME/workspace/skills/:

  workspace/skills/<name>/SKILL.md   <- preferred
  workspace/skills/<name>.json       <- still works for backwards compat

SKILL.md is YAML frontmatter (between `---` markers) + markdown:

  ---
  name: weather_report
  description: Fetch weather for a city
  kind: shell
  shell: curl -s 'https://wttr.in/{{city}}?format=3'
  schema: {"type":"object","properties":{"city":{"type":"string"}}}
  ---

  # Weather report

  Procedural knowledge the model loads on demand via fs_read.

Implementation:

  ParseSkillMD(FilePath, out Spec, out ErrMsg): Boolean
    - Locates frontmatter delimiters (`---` lines) with tolerance for
      leading blank lines / BOMs.
    - Parses simple key:value entries; strips surrounding single or
      double quotes from values to accept YAML-quoted strings.
    - Schema field accepts inline JSON on one line (the only realistic
      need — skill schemas are small "object with these properties"
      blobs); multi-line schemas can come later if a real skill needs
      them.
    - Body = everything after the closing `---`, with surrounding
      whitespace trimmed.
    - Returns False with ErrMsg set on malformed frontmatter so the
      logger can warn per-file instead of silently dropping skills.

  ScanSkillDirs / ScanJsonSkills replace the old single-flat scan.
  Per-directory entries are loaded first and shadow same-named JSON
  entries by name. Lets users drop a SKILL.md next to an existing
  JSON, verify it loads, then delete the JSON when ready.

  TSkillSpec gains three fields:
    Body   - markdown body (for the SKILL.md path; empty for JSON skills)
    Dir    - skill directory (parent of SKILL.md, or dirname of JSON file)
    Source - absolute path to SKILL.md or the JSON file. Surfaces in
             the system prompt so the model knows where to fs_read for
             the full body.

  Kind semantics:
    shell      - callable; registers as `skill_<name>` tool, runs the
                 rendered Shell command. Unchanged.
    prompt     - callable; registers as `skill_<name>` tool, returns the
                 rendered Prompt template. Unchanged.
    (omitted)  - knowledge-only; NO tool registered. SKILL.md body is
                 advertised in the system prompt's SKILLS section so
                 the model knows to fs_read it. This is the dominant
                 pattern picoclaw and nanobot ship.

System prompt's SKILLS section (PasClaw.Agent.Prompt) updated to
distinguish callable from knowledge-only skills:

  ## Skills

  Skills extend your capabilities. Callable skills register as
  `skill_<name>` tools you invoke directly; knowledge-only skills are
  markdown bodies — read each one's SKILL.md with `fs_read` when the
  matching task comes up.

  - `skill_weather_report` — Fetch weather for a city (callable)
  - **code-review** — Static review prompt. Read `/home/me/.pasclaw/
    workspace/skills/code-review/SKILL.md` for the full instructions.

`pasclaw skills list` updated to show kind + path (relative to
~/.pasclaw when possible) instead of the old two-column shell/prompt
view that did not surface the source file.

samples/skills/hello/SKILL.md ships as a copy-pasteable starter
documenting every frontmatter field and the body conventions.

README's skills paragraph rewritten to document the new layout with
a backwards-compat note for the JSON form.

Not in this PR (Phase 2 → 4 of the roadmap discussed in the prior
turn):

  - `pasclaw skills install owner/repo[/path]` GitHub fetch + zip
    extract (Delphi's System.Zip is the cross-target story; FPC has
    Zipper.TUnZipper).
  - ClawHub search/install client.
  - scripts/ + references/ runtime support (scripts as callable
    helpers; references lazily loaded into context).

Roadmap noted in the README so future contributors can pick it up.

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: f8f9b8f1e7

ℹ️ 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 on lines +326 to +328
Line := Trim(Lines[i]);
if Line = '' then Continue;
if Line = '---' then begin StartIdx := i; Break; end;

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 Strip UTF-8 BOM before checking frontmatter

When a SKILL.md is saved with a UTF-8 BOM, ReadFileText preserves that character at the start of the first line, and Trim does not remove it, so Line becomes BOM+--- and this equality check fails. In that case the loader reports “no YAML frontmatter” and skips an otherwise valid skill, despite this parser explicitly intending to tolerate BOM-prefixed files. Strip the BOM from the first non-empty line before comparing the delimiter.

Useful? React with 👍 / 👎.

ParseSkillMD's comment claimed BOM tolerance but Trim only handles
ASCII whitespace, so a SKILL.md saved by a Windows editor with the
UTF-8 BOM (EF BB BF) prepended would have its first line read as
"<BOM>---", fail the `Line = '---'` equality check, and the parser
reported `no YAML frontmatter` — silently dropping an otherwise
valid skill.

Strip the BOM explicitly on the first line. Cross-toolchain detail
is that ReadFileText returns different shapes on each:

  FPC:    AnsiString-UTF8 — the BOM lives as three bytes EF BB BF at
          positions 1..3 of the string.
  Delphi: UnicodeString — TEncoding.UTF8.GetString decodes those
          three UTF-8 bytes into a single Char #$FEFF (zero-width
          no-break space; the Unicode BOM codepoint). It does NOT
          silently strip the BOM, contrary to what one might assume.

Handle both via {$IFDEF FPC}. Test plan: save samples/skills/hello/
SKILL.md with `iconv -f UTF-8 -t UTF-8-BOM > with-bom/SKILL.md`,
`pasclaw skills list` should pick it up under both compilers.

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