/* 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. It takes at most the
* skillBudget setting's characters, by default 1% of WINDOW tokens (the model's
* context window; 0: not known) at 4 characters a token. Over it, descriptions
* past 1536 characters are cut at a word, then the least used skills (see
* pic_skills_note_read) are listed by name and location only until it fits; a
* skill is never dropped. When WARNING is not NULL, *WARNING is a one-line
* message naming what the budget cut (malloc'd), or NULL when everything fits. */
char *pic_skills_prompt(const pic_skills *s, long window, char **warning);
/* Counts a use of the skill at PATH when it is a skill's file (the tools'
* read of it; /skill:NAME counts in pic_skills_expand). Ranking is
* uses x max(0.5^(days since last use / 7), 0.1), kept in picu_skill_use;
* recording is best effort. */
void pic_skills_note_read(const char *path);
/* 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