Skip to content

skills: self-improving / agent-authored skills (Hermes-style) - #288

Merged
FMXExpress merged 2 commits into
mainfrom
claude/self-improving-skills
Jun 16, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/self-improving-skills

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Ports the self-improving / agent-authored skills capability from Nous Research's hermes-agent. The agent can create, edit, and refine skills on disk; a post-turn distiller can capture reusable workflows autonomously; and a progressive-disclosure path keeps the system prompt small as skills accrue.

Everything is opt-in under a new self_improving_skills config block. A default config.json behaves exactly as before — no new tools registered, prompt unchanged.

"self_improving_skills": {
  "self_manage": true,
  "progressive_disclosure": true,
  "auto_approve": false,
  "guard_deny": ["my-forbidden-command"],
  "distiller": { "enabled": true, "min_tool_calls": 5, "model": "claude-haiku-4-5" }
}

The four stages

Stage A — skill_manage tool (PasClaw.Skills.Manage)

create / edit / patch / remove actions the model calls mid-turn. Writes stage under workspace/skills/.pending/<id>/ for operator approval, or commit straight to workspace/skills/<name>/ when auto_approve is on. Like a hub install, a committed skill is picked up on the next agent start (the registry is built once at boot — no mid-session mutation). Guards before staging: path confinement to the skills tree, a dangerous-pattern denylist (rm -rf, curl | sh, fork bombs, mkfs, …) plus operator guard_deny terms, and a PasClaw.Promptware injection scan.

Stage B — progressive disclosure (PasClaw.Skills.Disclosure)

skills_list + skill_view read-only tools. When progressive_disclosure is on, the prompt's SKILLS section collapses to a one-line pointer instead of inlining every skill. skill_view confines reads to the skill's own directory.

Stage C — autonomous distiller (PasClaw.Agent.SkillDistiller)

After a turn that dispatched ≥ min_tool_calls tool calls, one small LLM call decides whether to draft a SKILL.md. Runs after the user-facing reply (zero added latency), de-dupes against existing skills via Jaccard similarity, and routes the draft through the same guard + staging path. Wired into the CLI single-turn path and TPasClawAgent.ChatHistory.

Stage D — approval surface

  • CLI: pasclaw skills pending | diff <id> | approve <id> | reject <id>
  • Gateway: GET /v1/skills/pending, POST /v1/skills/pending/{approve,reject} (bearer-gated like every /v1/* route)
  • Web UI: a "Pending approval" block in the Skills tab with a SKILL.md preview + Approve/Reject buttons

The operator is the quality judge — there is no automated utility evaluator, by design.

Supporting changes

  • PasClaw.Config: TSelfImprovingSkillsConfig + TSkillDistillerConfig, round-tripped under "self_improving_skills" (emitted only when non-default, same posture as auto_router).
  • PasClaw.Skills.Loader: factor a string-based ParseSkillMDText out of ParseSkillMD so candidate content is validated in-memory (no temp file).
  • Registration wired into every tool-registry builder (agent component, CLI agent, gateway, serve, TUI); all self-gate on the config flags.

Test plan

  • make test-self-improving-skills — new test (src/tests/self_improving_skills_tests.pas) covers the name/guard checks, staging, pending list/diff/approve/reject, the dangerous-shell refusal, auto-approve commit, and the config round-trip. Wired into the aggregate test target.
  • make clean && make — full FPC 3.2.2 build clean.
  • Regression: test-config-secret-merge, test-config-env-subst, test-skills-install, test-promptware all green.
  • Live CLI: staged a pending skill, then skills pending → diff → approve committed it and skills list shows it; .pending/<id> removed.
  • Live gateway: GET /v1/skills/pending returned the staged skill + inlined SKILL.md; POST /v1/skills/pending/approve committed it and the pending list went empty.

Docs

docs/skills.md gains a "Self-improving skills" section: config, the skill_manage actions, progressive disclosure, the distiller, the approval workflow (CLI + gateway), and the safety model.

Notes for review

  • Single cohesive feature commit (the four stages share the config record and the PasClaw.Skills.Manage core, and the registration sites reference both the manage and disclosure tools — splitting into 4 PRs would mean broken intermediate builds).
  • Comments containing ${VAR} / {id} were written with (* *) or reworded to avoid the dcc64 early-comment-close trap that's bitten this repo before.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

Port the "self-improving skills" capability from Nous Research's
hermes-agent. The model can create, edit, and refine skills on disk;
a post-turn distiller can capture reusable workflows autonomously; and
a progressive-disclosure path keeps the prompt small as skills accrue.
Every part is opt-in under a new `self_improving_skills` config block --
default behaviour is unchanged.

Four stages, all gated:

Stage A -- skill_manage tool (PasClaw.Skills.Manage)
  create / edit / patch / remove actions. Writes are staged under
  workspace/skills/.pending/<id>/ for operator approval, or committed
  straight to workspace/skills/<name>/ when auto_approve is on. Like a
  hub install, a committed skill is picked up on the next agent start.
  Guards: path confinement to the skills tree, a dangerous-pattern
  denylist (rm -rf, curl|sh, fork bombs, ...) plus operator guard_deny
  terms, and a PasClaw.Promptware injection scan -- all before staging.

Stage B -- progressive disclosure (PasClaw.Skills.Disclosure)
  skills_list / skill_view tools; the system prompt's SKILLS section
  collapses to a one-line pointer when progressive_disclosure is on.
  skill_view confines reads to the skill's own directory.

Stage C -- autonomous distiller (PasClaw.Agent.SkillDistiller)
  After a turn that dispatched >= min_tool_calls tool calls, one small
  LLM call decides whether to draft a SKILL.md. Runs after the
  user-facing reply (no added latency); de-dupes against existing
  skills via Jaccard similarity; routes the draft through the same
  guard + staging path. Wired into the CLI single-turn path and
  TPasClawAgent.ChatHistory.

Stage D -- approval surface
  CLI: pasclaw skills pending | diff <id> | approve <id> | reject <id>
  Gateway: GET /v1/skills/pending, POST /v1/skills/pending/{approve,
  reject} (bearer-gated). Web UI: a "Pending approval" block in the
  Skills tab with SKILL.md preview + Approve/Reject.

Supporting changes:
  - PasClaw.Config: TSelfImprovingSkillsConfig + TSkillDistillerConfig,
    round-tripped under "self_improving_skills" (emitted only when
    non-default, same posture as auto_router).
  - PasClaw.Skills.Loader: factor a string-based ParseSkillMDText out of
    ParseSkillMD so candidate content can be validated without a temp
    file.
  - Registration wired into every tool-registry builder (agent, CLI
    agent, gateway, serve, TUI); all self-gate on the config flags.

Tests: src/tests/self_improving_skills_tests.pas covers the guards,
staging, pending list/diff/approve/reject, auto-approve commit, and the
config round-trip. Wired as `make test-self-improving-skills` and into
the aggregate `test` target.

Docs: docs/skills.md gains a "Self-improving skills" section covering
config, the tool actions, the approval workflow, and the safety model.

@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: b513b32f4d

ℹ️ 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 +186 to +188
Dest := SkillDir(HomeDir, P.Name);
if DirectoryExists(Dest) then
if not DeleteTree(Dest) then

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate pending remove names before deleting

In the remove branch, P.Name comes directly from .pending/<id>/meta.json and is used to build the directory passed to DeleteTree without the IsSafeSkillName check used elsewhere. If a pending entry is hand-edited or crafted with a name containing ../, approving it can delete directories outside workspace/skills, breaking the path-confinement guarantee for the approval surface. Please reject unsafe pending metadata names before building Dest.

Useful? React with 👍 / 👎.

Exit;
end;

Dest := SkillDir(HomeDir, Spec.Name);

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 Verify edit targets before approving

For staged edit/patch approvals, the destination is derived from the name: inside the staged SKILL.md and only create checks for an existing destination. If the original skill was removed before approval, or the pending SKILL.md was renamed while staged, approval silently creates or overwrites a different skill instead of applying the staged action to P.Name. For non-create actions, require Spec.Name = P.Name and that the target skill directory still exists before writing.

Useful? React with 👍 / 👎.

Comment on lines +175 to +178
T.Name := 'skill_view'; T.Description := SkillViewDesc;
T.Schema := SkillViewSchema; T.Handler := SkillViewHandler;
T.HandlerObj := nil; T.IsCore := False; T.Category := tcReadOnly;
Reg.Register(T);

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 Avoid shadowing user skill tools

Callable skills are registered as skill_ + skill name, and TToolRegistry.Register replaces duplicate tool names. Since this new tool is also named skill_view and is registered after existing skills, enabling progressive disclosure silently disables any valid user skill named view (the same namespace collision applies to skill_manage vs a manage skill). Use a name outside the user-skill namespace or reserve/reject these skill names explicitly.

Useful? React with 👍 / 👎.

Three Codex findings, all legit.

P1 (Pending.pas) -- ApprovePending's remove branch built Dest from
P.Name straight out of meta.json without IsSafeSkillName. A hand-edited
meta with `"name": "../../etc"` would let DeleteTree recurse out of the
skills tree, defeating the path-confinement guarantee. Validate the
metadata name BEFORE constructing any path, on every action.

P2 (Pending.pas) -- For staged edit/patch, the destination was derived
from Spec.Name inside the staged SKILL.md and only `create` checked the
destination. A staged file renamed while pending would silently target
the wrong skill; a stage-then-delete sequence would silently resurrect
a removed skill via "edit". Pin non-create approvals to P.Name and
require the target skill directory to still exist before writing.

P2 (Disclosure.pas + Manage.pas) -- skill_view and skill_manage shared
the `skill_<name>` namespace user callable skills register under, so
enabling progressive disclosure silently shadowed a user skill named
`view` or `manage`. Move the feature tools to `skills_` (plural):
skills_manage, skills_view (skills_list was already plural). Documented
the convention in both unit headers and docs/skills.md.

Tests:
  - TestApprovePendingRejectsUnsafeMetaName covers the P1 escape attempt.
  - TestApprovePendingEditNameMismatch covers both halves of P2:
    rename-via-edit and edit-of-missing-target.

Verified live: gateway /v1/tools now exposes skills_manage / skills_list /
skills_view (no skill_* shadowing), and POSTing approve on an unsafe
meta name returns a clean 400 instead of leaking outside the tree.
@FMXExpress
FMXExpress merged commit 5617331 into main Jun 16, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
The PR-FMXExpress#288 audit found six loop-affecting config knobs without an
onboarding question. Now every loop-shaping knob is a visible Y/N in
`pasclaw onboard`, and pressing Enter all the way through lands the
documented defaults.

New prompts in PasClaw.Cmd.Onboard:
  PromptWebFetch              [Y/n]  -- web_fetch / memory_fetch
  PromptPromptware            [Y/n]  -- injection-warning banners
  PromptCondenseReversible    [y/N]  -- structural-view-with-handle
  PromptToolOutputCap         [y/N]  -- byte cap + tool_output_get
  PromptOrientTaskAware       [y/N]  -- task-vs-section MEMORY slicing
  PromptSelfImprovingSkills   [y/N]  -- four nested questions for the
                                       skills_manage / disclosure /
                                       distiller / auto-approve toggles
                                       (PR FMXExpress#288)

Default flips (TConfig.Create) -- bringing the no-onboarding default
in line with what `pasclaw onboard` press-Enter-through writes:
  VaultToolsEnabled    False -> True
  WebFetchEnabled      False -> True
  CondenseReversible   True  -> False  <-- the one that motivated this PR;
                                          a fresh deploy no longer silently
                                          rewrites ls/grep output into a
                                          structural view behind the
                                          operator's back.

Serialisation rules in ToJSON updated for the three flipped defaults so
a fresh config stays tidy (omits the now-default values) AND an
explicit opt-out persists across SaveConfig / LoadConfig -- same posture
render_markdown / vector_search_enabled already use. Verified that:
  - fresh defaults round-trip with the loop-shaping keys absent
  - explicit-off persists as PutBool('vault_tools_enabled', false) etc.
  - opt-in to a now-default-off knob (condense_reversible / orient /
    tool_output_cap) likewise emits the explicit-on form

Tests: src/tests/loop_shaping_defaults_tests.pas covers fresh defaults,
the tidy-emission rules, and a full round-trip with every loop-shaping
field flipped from its default. Wired as `make test-loop-shaping-defaults`
and into the aggregate `test` target.

Docs: docs/configuration.md updated for the three flipped fields and
the new onboarding behaviour; docs/getting-started.md lists every knob
the wizard now walks through.
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
…ngs)

Live error on a max-build deploy talking to Gemini:

  gemini error 400: GenerateContentRequest.tools[0].function_declarations
  [15].parameters.properties[kind].enum[0]: cannot be empty

Gemini's GenerateContent endpoint validates every tool's JSON schema
and refuses any "enum": [...] that contains an empty string. PR FMXExpress#288's
skills_manage schema used "" as the sentinel for "knowledge-only
skill" (no callable shell / prompt registered), which works on
Anthropic / OpenAI / Mistral but trips Gemini's stricter validator on
the FIRST tool call -- so any operator who enabled
self_improving_skills.self_manage (max-build profile flips it on)
AND points at a Gemini model gets a 400 on every chat request.

Drop "" from the enum so it's just ["shell","prompt"]. The handler
already treats absent / missing `kind` as knowledge-only (the
SKILL.md assembler at line ~336 skips writing the `kind:` frontmatter
line when GetStr('kind','') returns empty), so this is a schema
cleanup, not a behaviour change. The description string now spells
out the "omit for knowledge-only" semantic so the model knows the
contract from the tool spec without needing to see the prompt
section.

Audited the rest of src/pkg/ for other "enum":[""...] / enum:['',...]
patterns -- none. This was the only one.
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