# Design: Skills Engine

Status: **phase 1 in place** (backend registry, data, REST, read-only
MCP, the built-in seed and its skills) and **the Skills page**
the composer picker and the loaded-skills chip of phase 2. See
[Phase 1 as built](#phase-1-as-built) and [The Skills page](#the-skills-page).

## Why

Good security research is mostly method: confirm scope before touching
anything, prove a behaviour with evidence rather than a hunch, rule out
false positives, rate severity honestly, check for duplicates, write a
report a triager can act on, and remember what was already tried. Phantom
already stores the objects that method works on (vaults, scope, requests,
findings, notes, assets, reports). The Skills Engine stores the **method
itself** as versioned, reviewable knowledge that people and agents use in
the same way, inside the same permissions.

A skill is not a prompt pasted into a provider adapter and not a plugin
that runs code. It is a research resource: written instructions, a
checklist, references to Phantom objects and capabilities, and the context
it applies to.

## What a skill is

| Field | Meaning |
|---|---|
| `id` | stable identifier, e.g. `finding-validation` |
| `name`, `summary` | what it is for, one line each |
| `category` | one of the built-in categories below, or `custom` |
| `version` | semantic version; every change is a new version |
| `scope` | `builtin`, `global` (the user's own), or a vault id |
| `instructions` | Markdown body: the method, written as guidance |
| `checklist` | optional ordered checks, each with an id and a short question |
| `sections` | optional named sections loaded on demand (progressive disclosure) |
| `references` | Phantom references (`[[note:12]]`, `[[file:4]]`) and other skills by id |
| `applies_to` | when it is relevant: modules, object kinds, states (e.g. finding status `triaging`), asset technologies |
| `requires_context` | what it needs from the workspace (e.g. an open finding with evidence) |
| `requires_grants` | the capabilities it refers to, as resource and action (e.g. `findings.read`, `testing.execute`) |
| `compatible_with` | capability ids it refers to (Comparer diff, Repeater send, report validate) |
| `depends_on` | other skills, with version ranges |
| `config` | small typed settings the user may change (e.g. engagement type) |
| `provenance` | author, origin (built-in, user, agent, import), license, attribution, changes |
| `enabled` | on or off, per scope |

Skills hold **no executable content**: no scripts, no installers, no
network fetches, no tool definitions of their own. Everything a skill
"does" happens through Phantom capabilities the agent may already use.

## Three kinds

- **Built-in** skills ship with Phantom, are read-only, and update with
  Phantom versions.
- **Custom** skills belong to the user and are available in every vault.
- **Vault skills** belong to one vault (an engagement's own method, a
  program's rules) and disappear with it.

A custom or vault skill may start as a copy of a built-in one.

## Registry

One registry in the backend (`services/skills`) used by the interface,
REST, MCP, the Bridge and model providers alike:

- discovery, search and categories;
- versions (every saved change is a new immutable version; the current one
  is a pointer), diff between versions, restore;
- dependency and compatibility checks (missing skill, version conflict,
  a capability that does not exist or the agent cannot be granted);
- enable and disable per scope;
- validation on save and import (schema, size limits, links resolve,
  references exist, no forbidden content);
- import and export as `SKILL.md` (see [Skill format](../skills/format.md)).

## How skills reach a conversation

Skills are never injected wholesale. The engine discloses them in steps:

1. **Metadata.** For the current workspace context (module, open and
   selected objects, their states) and the conversation's topic, the engine
   ranks enabled skills by `applies_to` and offers a short list: id, name,
   summary. This costs a few lines per skill.
2. **Selection.** The user picks skills in the composer, or the agent asks
   for one by id; the engine also preselects deterministic matches (a
   finding in `triaging` selects finding validation).
3. **Core.** Only the selected skill's summary, checklist and core
   instructions are loaded, within a token budget the engine enforces.
4. **Sections and context.** Further sections, referenced notes or files and
   additional workspace context are fetched only when needed, each through
   the reader's own grants.

The conversation shows which skills and references are in use, as chips
the user can open or remove.

## Safety

- **Skills never grant anything.** A skill that mentions sending a request
  does not let an agent send one; the agent's grants and approvals decide,
  as for any other call. `requires_grants` is shown to the user as what the
  skill expects, and the engine warns when the agent lacks it.
- **Skills are data.** Imported and custom skills are treated as untrusted
  content. The engine scans them for instructions aimed at the agent that
  try to change its rules (ignore previous instructions, skip approvals,
  widen scope, reveal secrets), flags them in the review view and refuses
  import of the worst cases; the agent always receives skill text inside a
  block marked as reference material, never as system policy.
- **Scope, redaction, vault isolation and approvals** are backend policy.
  A skill can explain them; it cannot weaken them.
- **Attribution travels with the content.** A skill adapted from someone
  else's work keeps its license and credit in `provenance`; skills under
  licenses that forbid extra restrictions keep their original license, and
  Phantom's license never applies to them.

## Built-in collection

Curated, written by us, focused on method rather than exploitation:

- research methodology and engagement types;
- authorization and scope validation;
- defensive application security knowledge;
- threat modeling;
- secure code review;
- asset classification and ownership confidence;
- evidence collection and integrity (minimum data, redaction, provenance);
- finding validation and false-positive identification;
- severity assessment;
- duplicate review;
- remediation guidance;
- regression verification;
- research documentation and memory (including negative results);
- professional reporting.

Each built-in skill reuses Phantom objects: validation writes a checklist
result onto the finding, reporting works in Report Studio, memory lives in
notes. No skill keeps its own parallel storage.

## Interface

A **Skills** page (rail item, Kuro design): library with search and
categories; tabs for Built-in, Custom and Vault; a detail view with the
instructions, checklist, required grants, dependencies, compatible
capabilities, provenance and version history; the live Markdown editor for
custom skills; enable and disable; import and export. In the Agent
composer, a skill picker and the chips of skills in use; in conversations,
a quiet line when a skill is loaded.

## Interfaces for agents

- REST: `/api/v1/skills` (list, get, versions, validate, import, export)
  and `/api/v1/vaults/{id}/skills`.
- MCP: `skill_list`, `skill_get` (metadata, core, a section by name),
  `skill_suggest` (for the current context), all read-only; resources
  `phantom://skills` and `phantom://skills/{id}`.
- Bridge: the same calls, and the skills in use attached to each turn.
- Model providers: the same registry; the provider runtime loads skills
  through it and never carries its own prompts.

Creating, editing, enabling and importing skills are user actions.

## Data

`skills` (id, scope, current version, enabled), `skill_versions`
(immutable content and metadata, checksum, author, created), `skill_usage`
(conversation, skill, version, when; for the "in use" chips and audit).
Built-in skills are seeded from files in the repository and updated by
migration when Phantom updates.

## Tests

Discovery and ranking from context, validation and limits, versioning and
restore, vault isolation, permission checks (a skill never widens access),
context selection and token budgets, untrusted content and instruction
scanning, import and export round trips, reference resolution, provider
and MCP contracts, and the GUI, REST and MCP parity.

## Phase 1 as built

- **Data.** `skills` (id per scope, `scope_key` = `builtin`, `global` or
  `vault:<id>`, the current version number, the user's switch),
  `skill_versions` (immutable; front matter as validated, core and
  sections, scanner flags, checksum, author, `restored_from`),
  `skill_vault_settings` (a library skill switched for one vault) and
  `skill_usage` (conversation, skill, version, part, tokens). Migration
  `ce9c93cf6e6c`.
- **Shadowing.** The same id may exist in several scopes; a vault's view
  shows its own skill first, then a global one, then the built-in one.
  Copying a built-in skill is how it is customised.
- **Versions.** Saving unchanged content adds no version. A save without a
  version raises the patch number; a stated version must be greater than
  the current one. Restore copies an old version forward with the patch
  number raised. Removing or rewording a check without a new major
  version is a warning.
- **Validation** refuses unknown keys (no scripts, tools or installers),
  ungrantable `requires_grants`, unknown modules and object kinds, YAML
  anchors, active markup (script tags, frames, event handlers,
  `javascript:` addresses), link schemes other than http, https and
  mailto, malformed references and anything over the limits. Unknown
  capabilities, executable-looking code blocks, unmet dependencies and
  references that do not resolve are warnings.
- **Scanning** flags instructions that try to override the agent's
  rules, skip approvals, widen scope, reveal secrets or instructions,
  send data elsewhere, hide things from the user, turn off safeguards or
  grant access. Critical flags refuse a save or import; warnings are kept
  on the version. Advice that keeps a rule ("never skip approvals") is
  not flagged.
- **Disclosure.** Metadata, the core (summary, checklist, core
  instructions, the names of the sections) or one section, cut at a
  paragraph to a budget: 2,500 tokens by default, at most 8,000 per call
  and 24,000 per conversation (estimated as four characters per token).
  Text is wrapped between markers content cannot close, with a notice
  that it is reference material, not policy.
- **Suggestions** rank enabled skills by `applies_to` only: module (+3),
  object kind (+4), object state (+6, preselects), technology (+2); topic
  words only break ties and requirements met add one.
- **Built-in collection.** `backend/app/skills/builtin/*.md`, synced at
  startup: new file, new skill; changed file, new version; the user's
  switch is kept; a removed file removes its skill. A file that fails
  validation, or a database without the tables, is logged and skipped.
- **Permissions.** New grant resource `skills` with `read` only, in every
  preset. Changes are user actions: refused inside agent calls and on
  requests that carry agent transport headers.

The collection covers every category above (fourteen skills, one per
category, `custom` aside); the API and MCP tests read the expected set
from the folder, so a new file needs no test change.

## The Skills page

`/skills` (rail, `G K`). The library is the active vault's view
(`/vaults/{id}/skills`), or the global one without a vault; changes go to
the library a skill lives in, so editing a global skill from a vault saves
it in the global library. Tabs: Overview (checklist, core, folded sections
with their token size, facts: applies to, expected grants in the
permission matrix's words, capabilities, dependencies with their check,
references, settings, provenance; flags and warnings first), SKILL.md
(edited in place with validation as the user types, debounced against
`/validate` of the target library) and Versions (history, diff against
the current version, restore). Customize copies a built-in skill into the
global library under the same id; Copy to vault does the same into the
vault. The switch is per vault in a vault's view. New starts from a valid
starter; Import sends a file to the global library (a 409 tells the user
to save it as a version instead). Frontend: `views/SkillsView.vue`,
`components/skills/*`, `stores/skills.ts`, `composables/useSkillDraft.ts`,
`composables/useSkillActions.ts`, `utils/skills/*`, `utils/menus/skill.ts`;
`skillsApi` and `vaultSkillsApi` in `api/resources.ts`.

## Choosing skills

The composer has no skill picker. A model provider's system framing asks
the model to call `skill_suggest` when a task could follow a skill
(triage, recon, a report, a class of bug), with the vault, the open module
and what the task is about, then to load the ones that fit with
`skill_get` (`services/providers/turns/framing.py`). Small talk and quick
questions skip it. An agent without `skills.read` has neither tool.

A skill can still arrive as a Bridge reference `{kind: 'skill', id}`
(resource `skills`, read), for instance through the Bridge routes; nothing
of it is inlined, the turn carries the id and a line
asking the agent to load it. A skill chip opens `/skills?skill=<id>`.

## Loaded skills in a conversation

The conversation header (page and panel) reads
`/vaults/{id}/skills/usage?conversation_id=` when the conversation opens
and again shortly after its messages change. Records are grouped per
skill (`utils/skills/usage.ts`): latest version, parts in the order first
loaded, tokens summed. The chip appears only once something was loaded;
a failed read keeps what it showed.

## Related

[Skills](../skills/), [Skill format](../skills/format.md),
[Writing skills](../skills/development.md),
[Third-party attributions](../reference/third-party-attributions.md).
