agent-afk 3.82.0 → 3.83.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1205,9 +1205,9 @@ Create a ship-ready summary with next steps.`,l=await a.runToResult(c);if(l.stat
1205
1205
  `,4);if(e===-1)return{frontmatter:null,frontmatterFlags:null,body:t};let n=t.slice(4,e),r=t.slice(e+5),o={},s=null,i=n.split(`
1206
1206
  `);for(let a=0;a<i.length;a++){let c=i[a];if(!c||!c.trim()||c.trimStart().startsWith("#"))continue;if(c.startsWith("flags:")){let d=c.slice(6).trim();if(d.startsWith("[")){let u=d.match(/\[(.*?)\]/);if(u?.[1]){let p=u[1].split(",").map(f=>f.trim()).filter(f=>f.length>0);p.length>0&&(s=p.map(Ja).sort())}continue}if(d===""||d==="null"){let u=[];for(let p=a+1;p<i.length;p++){let f=i[p];if(!f||!f.match(/^\s+-\s/))break;let g=f.match(/^\s+-\s+(.+)/);g?.[1]&&u.push(g[1].trim())}u.length>0&&(s=u.map(Ja).sort());continue}}let l=c.match(/^([a-zA-Z][a-zA-Z0-9_-]*):\s*(.*)$/);if(l&&l[1]!==void 0&&l[2]!==void 0){let d=l[2].trim().replace(/^['"]|['"]$/g,"");d.length>0&&(o[l[1]]=d)}}return{frontmatter:o,frontmatterFlags:s,body:r}}function Va(t){let e=Vr(t);return e.frontmatterFlags&&e.frontmatterFlags.length>0?e.frontmatterFlags:Vg(e.body)}function Qg(t,e){return t.length===0||t.length>64?{valid:!1,reason:`name must be 1\u201364 characters, got ${t.length}`}:/^[a-z0-9]+(-[a-z0-9]+)*$/.test(t)?t!==e?{valid:!1,reason:`name field "${t}" does not match parent directory name "${e}"`}:{valid:!0}:{valid:!1,reason:`name "${t}" does not match spec pattern ^[a-z0-9]+(-[a-z0-9]+)*$ (only lowercase a-z0-9 and hyphens, no leading/trailing/consecutive hyphens)`}}var Xa=1024;function Zg(t,e){let n=Vr(t);if(!n.frontmatter)return null;let r=n.frontmatter.name,o=n.frontmatter.description,s=n.body.trim();if(!r||!o||s.length===0)return null;let i=Qg(r,e);if(!i.valid)return process.stderr.write(`[afk] skipping skill ${e}: ${i.reason}
1207
1207
  `),null;if(o.length>Xa)return process.stderr.write(`[afk] skipping skill ${e}: description exceeds ${Xa} characters (got ${o.length})
1208
- `),null;let a=n.frontmatter["argument-hint"]??n.frontmatter.argumentHint,c=Va(t),l={name:r,description:o,body:s,dir:""};return a&&a.length>0&&(l.argumentHint=a),c.length>0&&(l.flags=c),l}function eh(t){return async(e,n,r)=>{let o=typeof e=="string"&&e.length>0?e:`Run the ${t.name} skill now, following the instructions in your system prompt.`,s=new N({parentAbortSignal:n?.abortSignal}),i=r?.callId;return await(await s.forkSubagent({parent:{sessionId:n?.sessionId,getInputStreamRef:n?.getInputStreamRef?.bind(n),abortSignal:n?.abortSignal},config:{model:"sonnet",systemPrompt:t.body,env:{SKILL_ROOT:t.dir},isSkillDispatch:!0},idPrefix:`user-skill-${t.name}`,...i?{parentId:i}:{}})).runToResult(o)}}function th(t,e){try{return ye(t).origin===e?t:`${e}:${t}`}catch{return t}}function En(t,e){let n;try{n=Yg(t,{withFileTypes:!0})}catch(o){let s=o;return s.code!=="ENOENT"&&process.stderr.write(`[afk] skipping skills dir ${t}: ${s.message}
1208
+ `),null;let a=n.frontmatter["argument-hint"]??n.frontmatter.argumentHint,c=Va(t),l={name:r,description:o,body:s,dir:""};a&&a.length>0&&(l.argumentHint=a),c.length>0&&(l.flags=c);let d=n.frontmatter.context;return(d==="inline"||d==="fork"||d==="load")&&(l.context=d),l}function eh(t){return async(e,n,r)=>{let o=typeof e=="string"&&e.length>0?e:`Run the ${t.name} skill now, following the instructions in your system prompt.`,s=new N({parentAbortSignal:n?.abortSignal}),i=r?.callId;return await(await s.forkSubagent({parent:{sessionId:n?.sessionId,getInputStreamRef:n?.getInputStreamRef?.bind(n),abortSignal:n?.abortSignal},config:{model:"sonnet",systemPrompt:t.body,env:{SKILL_ROOT:t.dir},isSkillDispatch:!0},idPrefix:`user-skill-${t.name}`,...i?{parentId:i}:{}})).runToResult(o)}}function th(t,e){try{return ye(t).origin===e?t:`${e}:${t}`}catch{return t}}function En(t,e){let n;try{n=Yg(t,{withFileTypes:!0})}catch(o){let s=o;return s.code!=="ENOENT"&&process.stderr.write(`[afk] skipping skills dir ${t}: ${s.message}
1209
1209
  `),0}let r=0;for(let o of n){if(!o.isDirectory()||o.name.startsWith("_")||o.name.startsWith("."))continue;let s;try{s=Xg(Ya(t,o.name,"SKILL.md"),"utf-8")}catch(l){let d=l;d.code!=="ENOENT"&&process.stderr.write(`[afk] skipping skill ${o.name}: ${d.message}
1210
- `);continue}let i=Zg(s,o.name);if(!i)continue;i.dir=Ya(t,o.name);let c={name:th(i.name,e),description:i.description,handler:eh(i),origin:e};i.argumentHint&&(c.argumentHint=i.argumentHint),i.flags&&i.flags.length>0&&(c.flags=i.flags),te(c),r++}return r}import{existsSync as nh,readdirSync as rh,readFileSync as oh,statSync as sh}from"fs";import{join as ih}from"path";function Yr(t){let e=[];function n(r,o=0){if(o>10||!nh(r))return;let s;try{s=rh(r)}catch{return}for(let i of s){if(i.startsWith("."))continue;let a=ih(r,i),c;try{c=sh(a)}catch{continue}if(c.isFile()&&i==="SKILL.md"){let l=ah(a);l.name&&e.push(l)}else c.isDirectory()&&n(a,o+1)}}return n(t),e}function ah(t){try{let e=oh(t,"utf-8");if(!e.startsWith(`---
1210
+ `);continue}let i=Zg(s,o.name);if(!i)continue;i.dir=Ya(t,o.name);let c={name:th(i.name,e),description:i.description,handler:eh(i),origin:e};i.argumentHint&&(c.argumentHint=i.argumentHint),i.flags&&i.flags.length>0&&(c.flags=i.flags),i.context!=="fork"&&(c.context="load",c.loadBody=i.body.replace(/\$\{?SKILL_ROOT\}?/g,()=>i.dir)),te(c),r++}return r}import{existsSync as nh,readdirSync as rh,readFileSync as oh,statSync as sh}from"fs";import{join as ih}from"path";function Yr(t){let e=[];function n(r,o=0){if(o>10||!nh(r))return;let s;try{s=rh(r)}catch{return}for(let i of s){if(i.startsWith("."))continue;let a=ih(r,i),c;try{c=sh(a)}catch{continue}if(c.isFile()&&i==="SKILL.md"){let l=ah(a);l.name&&e.push(l)}else c.isDirectory()&&n(a,o+1)}}return n(t),e}function ah(t){try{let e=oh(t,"utf-8");if(!e.startsWith(`---
1211
1211
  `))return{};let n=e.slice(4),r=n.indexOf(`
1212
1212
  ---`);if(r===-1)return{};let o=n.slice(0,r),s=n.slice(r+4).trim(),i={},a=o.split(`
1213
1213
  `);for(let c of a){if(!c)continue;let l=c.indexOf(":");if(l===-1)continue;let d=c.slice(0,l).trim(),u=c.slice(l+1).trim();if(d==="name")i.name=u.replace(/^["']|["']$/g,"");else if(d==="description")i.description=u.replace(/^["']|["']$/g,"");else if(d==="argumentHint")i.argumentHint=u.replace(/^["']|["']$/g,"");else if(d==="audience"){let p=u.replace(/^["']|["']$/g,"");(p==="public"||p==="internal")&&(i.audience=p)}else d==="context"&&(i.context=u.replace(/^["']|["']$/g,""))}return s.length>0&&(i.body=s),i}catch{return{}}}U();L();function Qa(t){let e=st(t);if(e.length===0)return"";let n=[];for(let r of e){let o=r.argumentHint?`${r.argumentHint}`:"",s=o?`- \`${r.name} ${o}\`: ${r.description}`:`- ${r.name}: ${r.description}`;n.push(s),r.whenToUse&&n.push(` When to use: ${r.whenToUse}`)}return["Available skills (invoke via the `skill` tool):","","Each skill either dispatches one or more context-isolated subagents (delegation \u2014 preserves the main session's context) or loads its instructions directly into your current context (`load` mode). Calling `skill` is the entry point for both; the executor picks the mode per skill. Prefer a skill over inline investigation when the task shape matches.","",...n].join(`