Artifact 2b6e9aad6a39d37774420ad894f2e6e774a392b70a2688248fc84ff0d4a49da7:
- File
src/skills.h
— part of check-in
[ea7e1fa24c]
at
2026-11-19 21:20:10
on branch skills
— Skills, as Pi's
Each folder with a SKILL.md under ~/.pic/skills/ (and, once the workspace is trusted, WORKSPACE/.pic/skills/) is a skill: Pi's frontmatter, validation and discovery rules, symlinks followed (suit places them as links), nothing ever written there. The system prompt lists them in Pi's wording, frozen with the conversation; /skill:name expands to Pi's skill block where templates expand, so ask, chat and the terminal agree, and the slash menu lists them. pic skills [--json] lists them. The frontmatter parser is now shared with prompt templates. (user: dmestas, size: 2346) [annotate] [blame] [check-ins using] [more...]
/* Skills, as Pi has them (skills.ts): folders holding a SKILL.md in * ~/.pic/skills (user) and WORKSPACE/.pic/skills (project, only when the * workspace is trusted). The folders are filled by another tool with symlinks, * which are followed; pic never writes there. Each skill is listed in the * system prompt, and /skill:NAME ARGS sends its instructions with the * arguments after them. */ #ifndef PIC_SKILLS_H #define PIC_SKILLS_H #include <stddef.h> #include <stdio.h> typedef struct { char *name; /* frontmatter name, else the folder's name */ char *description; char *path; /* the SKILL.md as discovered (symlinks not resolved) */ char *real; /* its resolved path, to drop one file seen twice */ char *dir; /* the folder holding it */ int project; /* 1: WORKSPACE/.pic/skills, 0: ~/.pic/skills */ int hidden; /* disable-model-invocation: not in the prompt, still a command */ } pic_skill; typedef struct { pic_skill *v; size_t n; } pic_skills; /* Loads the user's skills, then the workspace's when PROJECT (the caller has * checked trust). A folder holding SKILL.md is a skill and is not searched * further; otherwise root .md files with a description and subfolders are. * The first of two skills with one name wins (the user's). Warnings (an invalid * name, a missing description, a collision) go to WARN when it is not NULL. * What vanishes meanwhile is skipped quietly. Always 0 or -1 (out of memory). */ int pic_skills_load(pic_skills *s, const char *workspace, int project, FILE *warn); void pic_skills_free(pic_skills *s); const pic_skill *pic_skills_find(const pic_skills *s, const char *name); /* Pi's system prompt section for the skills the model may use (malloc'd, "" * when there are none), or NULL when out of memory. */ char *pic_skills_prompt(const pic_skills *s); /* TEXT as "/skill:NAME ARGS": 1 with *out the expansion (malloc'd), 0 when it * is not a command naming a known skill (the caller keeps TEXT), -1 when the * skill's file is gone or unreadable (a message in ERR). */ int pic_skills_expand(const pic_skills *s, const char *text, char **out, char *err, size_t errcap); /* name, scope, description, path per line (tab separated), or JSON. */ void pic_skills_print(const pic_skills *s, FILE *out, int json); #endif