Knaph

Knowledge and Helpers30 of 37

Build the Skill Index

For readers who know a little Python. In the lesson Skills in Your Agent, mini builds its skill index with read_skill and skill_index. They work on good files, and stop with an error on a bad one: a SKILL.md without a description: line raises a KeyError before mini has even started. Here you write a version that never crashes, and says which file is wrong and why. The input. Several SKILL.md files, one after another. Each starts with a line === and its path, for example === skills/report/SKILL.md, followed by the file itself. The code that splits the input into (path, text) pairs is already written (read_files, at the bottom). You write two functions. parse_skill(text) reads one file's header. - The header is the lines between a first line of --- and the next line of ---. Blank lines before the first --- don't count. A file that doesn't start with ---, or never closes its header, has the error no header. - Each header line is key: value. Split it at the first colon only, so a description like Use when: the user says "ship it" keeps its colon, and trim the spaces around both parts. Ignore lines with no colon, and keys you don't need, like tools:. - Return (name, description, None), or (None, None, error) with no name or no description, checked in that order. An empty value (name: with nothing after it) counts as missing. - Only the header matters: a --- line further down, in the body, is just part of the body. build_index(files) returns the lines to print. - If there is at least one good skill: the line Skills you can load with load_skill when a task matches:, then - name: description for each good skill, sorted by name. If there are none: the single line no skills. - Then, in input order, error <path>: <error> for each bad file. If a good skill has the same name as an earlier good skill, keep the first and report the second as another skill is already called <name>. An example. For a file skills/report/SKILL.md with name: report and description: Writes the monthly report., and a file skills/charts/SKILL.md whose header has only name: charts, the output is three lines: Skills you can load with load_skill when a task matches: - report: Writes the monthly report. error skills/charts/SKILL.md: no description A hint. Split the text into lines after dropping blank lines at the start (text.strip("\n")). Check that the first line is ---, then find the next --- line among the lines after it: the header is everything in between. Why it matters. The index is all the model sees of your skills until it loads one. A skill with a missing description never appears in it, so it is never used, and nobody notices. A loader that reports bad files out loud turns that silent failure into a line you can fix.

Sign in to try this exercise.