Skip to content

feat(skills): /skill-builder — author and persist a skill from chat - #104

Closed
mlubbad wants to merge 2 commits into
mainfrom
feat/skill-builder
Closed

mlubbad wants to merge 2 commits into
mainfrom
feat/skill-builder

Conversation

@mlubbad

@mlubbad mlubbad commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Problem

create_artifact can render a skill-shaped document, but an artifact is not a skill — nothing writes it into SKILLS_DIR. And /skill-builder was not a command, so it fell through commands.parse and reached the model as an ordinary prompt.

The user-visible result: "build me a skill" produced a markdown artifact whose only affordances were Download / Print, with no way to install it. The skill could never be invoked again.

Change

  • ocd_core/skill_tools.py (new) — a save_skill tool + an authoring system-prompt section, wired the same way as artifact_tools. The brief tells the model to verify identifiers before writing them into a skill, write the body as a procedure, and save rather than emit an artifact.
  • skills.save_skill() — create-or-replace keyed on the skill name, distinct from import_skill (which always lands a new file and uniquifies the stem — right for uploads, wrong for authoring).
  • commands.py — /skill-builder registered as a prefix command; bare form is valid and builds from the conversation so far.
  • app/routes/agent.py — turns the command into a skill-building turn.

Contracts worth reviewing

  • Gating. run_turn(skill_builder=True) is set only by the route when commands.parse sees /skill-builder on the user's own message. A saved skill is instructions every later turn obeys, so an ambient tool would let injected tool output plant a persistent backdoor. Unattended paths (Cowork, scheduler) never pass the flag — consistent with the existing "Unattended tool posture" rule in CLAUDE.md.
  • Command beats skill. The route parses the command before resolve_skill, so a user-saved skill named skill-builder cannot shadow the built-in.
  • No duplicate shadowing. Re-saving the same name rewrites the file the previous save wrote. resolve_skill returns the FIRST name match, so without this, iterating ("fix the trigger and save again") would leave files that silently shadow each other. Only paths recorded in .imported.json are rewritten, so a bundled skill is refused rather than clobbered.
  • Frontmatter safety. Frontmatter is line-oriented and triggers is comma-split by the loader, so a stray newline or comma from the model would corrupt every field after it; single-line fields are flattened before writing.

Tests

backend/tests/test_skill_builder.py (22): command parsing, markdown round-trip through the real loader, sanitization, name slugification, fence handling, validation, idempotence, bundled-skill refusal, tool dispatch, gating on/off, route wiring, and an end-to-end turn where a model calls save_skill and the skill then resolves in a later chat both as /name and by trigger.

ruff check . clean.

Full backend suite: 4 failures — test_alembic, test_providers_route::test_set_and_delete_key, and two in test_workspace. Verified identical on an untouched origin/main worktree, so they are environmental to my machine, not from this change. test_anthropic_native.py cannot be collected locally (anthropic not installed); CI covers it.

Not included

desktop/src/state/slashCommands.ts suggests skills only, so /skill-builder works when typed but does not appear in the composer's / menu. Adding a built-ins list needs the desktop verification loop (npm run typecheck && test && build) and node_modules was not installed locally, so I left it out rather than ship an unverified desktop change. Noted in CLAUDE.md as a known gap.

🤖 Generated with Claude Code

mlubbad and others added 2 commits July 25, 2026 16:22
The model could already emit a skill-shaped document via create_artifact, but
an artifact is not a skill: nothing wrote it into SKILLS_DIR, so "build me a
skill" ended at a download button with no way to install the result. And
/skill-builder was not a command, so it fell through commands.parse and was
sent to the model as an ordinary prompt.

Adds ocd_core/skill_tools.py (a save_skill tool + an authoring system-prompt
section, wired like artifact_tools) and skills.save_skill(), a create-or-
replace write keyed on the skill name.

- Gated: run_turn(skill_builder=True) is set only by the route when
  commands.parse sees /skill-builder on the user's own message. A saved skill
  is instructions later turns obey, so an ambient tool would let injected tool
  output plant a persistent backdoor; unattended runs never pass the flag.
- The route checks the command before resolve_skill, so a user-saved skill
  named skill-builder cannot shadow the built-in.
- Re-saving the same name rewrites the file the previous save wrote instead of
  leaving duplicates that shadow each other in resolve_skill (first match
  wins). Only files in the .imported.json manifest are ever rewritten, so a
  bundled skill is refused rather than clobbered.
- Frontmatter is line-oriented and triggers is comma-split, so single-line
  fields are flattened before writing.

Not surfaced yet: desktop slashCommands.ts suggests skills only, so the
command works when typed but does not appear in the composer's / menu.

Tests: backend/tests/test_skill_builder.py (22) — command parsing, markdown
round-trip through the loader, sanitization, idempotence, bundled-skill
refusal, tool dispatch, gating on/off, route wiring, and an end-to-end turn
where a model calls save_skill and the skill resolves in the next chat.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
/skill-builder worked only if you already knew to type it — slashSuggestions
fed on skills + MCP prompts, and a built-in command is neither.

Adds BUILTIN_COMMANDS + withBuiltins() to slashCommands.ts: built-ins are
prepended to the suggestion list, and a skill whose name shadows one is
dropped. The drop mirrors the backend — the route parses the command before
resolve_skill, so a skill named "skill-builder" can never run and listing it
would be a dead entry.

The list holds only commands a route actually consumes. The rest of
ocd_core/commands.py (/projects, /skills, /reload-skills, /set-instructions,
/learn-finding, /lint-knowledge, /refresh-catalog) is still parsed but no
route acts on it — leftovers from the retired Chainlit client — so suggesting
one would just send its literal text to the model.

accept() widens to SlashItem | SkillInfo; a built-in has no `sid`, so it takes
the plain applySlash path and lands "/skill-builder " ready for its argument.

Tests: 4 added to slashCommands.test.ts (exposure, filtering, shadow-drop
ordering, no-op on unrelated skills). typecheck + 408 vitest tests + build
all pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mlubbad mlubbad closed this Sep 8, 2026
@mlubbad mlubbad reopened this Sep 8, 2026
@mlubbad

mlubbad commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

Merged and shipped as part of the clean-slate VersoWork v0.1.0 open-source release.

@mlubbad mlubbad closed this Nov 21, 2026
@mlubbad
mlubbad deleted the feat/skill-builder branch November 21, 2026 20:26
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.

1 participant