okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7b06ea51b
main
1/** 2* Which saved skills an answer used, for the line under the answer ("Used 2 skills: Weekly report, Brand voice"). 3* 4* The agent loads a skill with its `skill` tool (the name is the folder name the app wrote, see skill-files.mjs). Each skill that was loaded 5* successfully during the turn is reported once, in a `skills-used` frame that carries the whole list so far (the page replaces its copy), with the 6* name the person gave it and its one-line description from the skill's own file. A skill the app does not know by file (a folder the agent 7* found elsewhere) is named from its folder name. Pure apart from reading `<dir>/<name>/SKILL.md`. 8*/ 9import { readFileSync } from 'node:fs' ; 10import { join } from 'node:path' ; 11import { parseSkillFile } from '../skill-files.mjs' ; 12 13/** "weekly-report" -> "Weekly report" */ 14export const skillLabel = slug => { 15const text = String ( slug ?? '' ). replace ( / [ -_ ] +/ g , ' ' ). trim (); 16return text ?text [ 0 ]. toUpperCase () + text . slice ( 1 ) :'' ; 17}; 18 19/** A function from the skill's folder name to `{ name, description }`, read from the app's skills folder. */ 20export function skillInfoFrom ( dir ) { 21return slug => { 22const safe = / ^ [ A - Za - z0 - 9 ][ A - Za - z0 - 9._- ]{ 0 , 80 } $ / . test ( String ( slug )) ?String ( slug ) :null ; 23let parsed = null ; 24if ( safe && dir ) { try { parsed = parseSkillFile ( readFileSync ( join ( dir , safe , 'SKILL.md' ), 'utf8' )); } catch { /* not a file of ours */ } } 25const name = ( parsed ?. title || skillLabel ( slug )). slice ( 0 , 80 ); 26// the app writes "<name>. <description>" into the file so the agent's catalog names the skill: the line shows only the description 27let description = String ( parsed ?. description ?? '' ). replace ( / \s +/ g , ' ' ). trim (); 28if ( description . toLowerCase (). startsWith ( ` ${ name . toLowerCase ()} . ` )) description = description . slice ( name . length + 2 ); 29return { name, description :description . slice ( 0 , 200 ) }; 30}; 31} 32 33export class SkillsUsed { 34constructor ({ emit, info= slug => ({ name :skillLabel ( slug ), description :'' }) }) { this . emit = emit ; this . info = info ; this . used = new Map (); } 35/** A tool card frame (every state change). Counts a `skill` call once, when it has worked. */ 36card ( tool ) { 37if ( ! tool || tool . name !== 'skill' || tool . state !== 'done' ) return ; 38const slug = String ( tool . args ?. name ?? tool . args ?. skill ?? '' ). trim (); 39if ( ! slug || this . used . has ( slug )) return ; 40this . used . set ( slug , this . info ( slug )); 41this . emit ({ type :'skills-used' , skills :[ ...this . used . values ()] }); 42} 43}