useakit 0.2.0-dev.80 → 0.2.0-dev.82
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 +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -296,7 +296,7 @@ description:
|
|
|
296
296
|
`)}async function Bu(e){let[t]=e;if(e.length>1)throw Error("Name one skill or folder, like `a-kit health pdf-forms`.");let n=v(t??`.`);if(await Lu(n)){let e=await Ru(n),r=t===void 0?`This folder`:U(n);F.info(`${r}: checked from its files; evals aren't.`),console.log(zu(e));return}if(t===void 0)throw Error("There's no SKILL.md here. Name one of your skills, like `a-kit health pdf-forms`, or a skill's folder.");let{api:r}=await Xa(),i=Tn(await r.listSkills(),t);if(i.length>1)throw Error(`More than one organization has a skill named "${t}". Name it with its organization: ${i.map(e=>`"${e.organizationName}/${e.name}"`).join(`, `)}.`);let a=i[0],o=await r.getSkillHealth(a.id);F.info(`${jn(a)} v${a.version}`),console.log(zu(o))}async function Vu(e){Ht(`agent kit`);let t=await Ya();t?F.success(`Logged in as ${Za(t.user)}`):t=await Ja();let n=z(B(),t.token),r=await n.listSkills();if(r.length===0){I(Qa(t.webUrl));return}let i=!e.yes;if(i&&!gn())throw Error("`a-kit init` asks questions. Pass --yes to install every skill, or use `a-kit add <skill>`.");let a=await yn(e.global,i),o=await vn(e.agent,i),s=i?_n(await Bt({message:`Which skills?`,options:r.map(e=>({value:e.id,label:jn(e)})),initialValues:r.map(e=>e.id),required:!0})):r.map(e=>e.id),{dirs:c}=await zo(n,r.filter(e=>s.includes(e.id)),o,a,e.channel,{catalog:r,ask:i});I(`Installed in ${c.map(U).join(`, `)}`)}async function Hu(e,t){switch(e){case`send`:t&&(process.env.AGENT_KIT_API_URL=t),await Ga();return;case`on`:{if(await Rn({heartbeat:!0}),!await H()){F.warn("Heartbeats are on; they start once you run `a-kit login`.");return}if(!ca()){F.warn(`Run it from the published CLI to install the timer.`);return}await Ka();let e=await za(B()),t=(await Wa())?.ok??!1;e?F.success(`Heartbeats are on${t?`; this machine is on your Machines page`:``}.`):F.warn(`Heartbeats are on, but this system has no timer agent kit can use (only Linux with systemd and macOS). It still reports when you install, update, or start Claude Code.`);return}case`off`:await Rn({heartbeat:!1}),await Ra(B()),F.success("Heartbeats are off: this machine stops reporting. It stays on the Machines page until someone forgets it there. Turn them back on with `a-kit heartbeat on`.");return;case void 0:case`status`:{let e=(await Ln()).heartbeat!==!1,t=await za(B()),n=await Wa();console.log(`Heartbeats are ${e?`on`:`off`}.`),console.log(`Timer: ${t?Pa(B()).join(`, `):`not installed`}.`),n&&console.log(`Last heartbeat: ${new Date(n.sentAt).toLocaleString()}${n.ok?``:` (it didn't go through)`}.`),n?.organization&&console.log(`Shows up on: ${n.organization.name}'s Machines page (change it with \`a-kit org use\`).`),console.log(`
|
|
297
297
|
Every 5 minutes, a system timer tells agent kit this machine's name, the CLI's version, the agents on it and their versions, and the skills installed everywhere (-g), so your organization's Machines page shows whether it's on and up to date. Logging in, installing and updating send it too.`);return}default:throw Error(`Unknown heartbeat action "${e}". Use on, off or status.`)}}const Uu=2e3;async function Wu(e,t={},n=300){let{port:r,secret:i}=await ro();try{return await fetch(`http://127.0.0.1:${r}${e}`,{...t,headers:{[$a]:i,...t.body?{"content-type":`application/json`}:{}},signal:AbortSignal.timeout(n)})}catch{return null}}async function Gu(){let e=await Wu(`/health`);return e?e.status===401?`taken`:e.ok?await e.json().catch(()=>null)??null:null:null}async function Ku(e,t,n=Ho){let r=await Gu();return r===`taken`?`taken`:r?.api===t?`running`:(r&&await Ju(),u(e)?(n(e,[`collector`,`--api`,t]),`started`):`missing`)}async function qu(e){return(await Wu(`/report`,{method:`POST`,body:JSON.stringify(e)},Uu))?.status===202}async function Ju({send:e=!0}={}){return(await Wu(e?`/stop`:`/stop?send=false`,{method:`POST`},Uu))?.ok??!1}const Yu=5e3;async function Xu(e,t,n){try{if(t&&(process.env.AGENT_KIT_API_URL=t),e!==`claude-code`||process.stdin.isTTY)return;let r=JSON.parse(await $u()),i=/* @__PURE__ */ new Date,a=n===`session`?n:void 0;if(r.hook_event_name===`SessionStart`&&!a){await Yo(ca()??sa()),await za(B())||await Ga();return}if(zn()||(await Ln()).telemetry===!1)return;let o=await H();if(!o)return;let s=typeof r.cwd==`string`?r.cwd:process.cwd(),c=r.hook_event_name===`SessionEnd`,l=await is(o.user.id),u=c?{...Uc,sessionId:Wc(r.session_id)}:await Gc(r.session_id,s,void 0,l),d=z(B(),o.token),f=r.hook_event_name===`SessionStart`&&a===`session`;f&&u.sessionId&&await Qu(e,u.sessionId,s),(f||r.hook_event_name===`UserPromptSubmit`)&&await Ku(ca()??sa(),B());let p=await ll(e,r,a,s,u,{now:i}),m=To(r),h=m&&await ma(m.name,e,s),g=m&&h&&await _a(h,e,m.trigger,Kc(u,l?.skills[h.id]??null),i);await Promise.all([!c&&os(l,i,h?h.id:null)&&ss(d,o.user.id,l,i),(p||g)&&Zu(d,p,g)])}catch{}}async function Zu(e,t,n){await qu({activations:n?[n]:[],sessionEvents:t?[t]:[]})||await Promise.all([t&&ul(async t=>{await e.reportSessionEvents(t,AbortSignal.timeout(Yu))},t),n&&ya(async t=>{await e.reportActivations(t,AbortSignal.timeout(Yu))},n)])}async function Qu(e,t,n){let{repository:r,branch:i}=await qc(n),a=ha(n,x());(r||a)&&await Ml({sessionId:t,agent:e,cwd:n,projectLock:a,repository:r,branch:i,registeredAt:(/* @__PURE__ */ new Date()).toISOString()})}async function $u(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString(`utf8`)}async function ed(e,t){if(e.length!==1)throw Error(`Name the skill's folder, like ${L(`link skills/release`)}.`);Ht(`agent kit`);let n=v(e[0]);if(!u(h(n,`SKILL.md`)))throw Error(`${U(n)} has no ${W}, so it isn't a skill.`);let r=f(n);if(!/^[a-z0-9-]+$/.test(r)||r===`report-session-issue`)throw Error(`"${r}" can't be a skill's folder name.`);let i=t.global?`global`:`project`,a=await vn(t.agent,!t.yes),o=on(a,i),s=o.map(e=>h(e,r));if(s.includes(n))throw Error(`${U(n)} is already where your agents read it.`);let c=(await Y(J(i))).skills[r];for(let e of s)if(u(e)&&!await Jn(e)&&!c)throw Error(`${U(e)} is a skill agent kit didn't install. Move it somewhere else first.`);if(c){let e=await qn(z(B(),(await H())?.token),r,c,o);if(e&&!await Jn(e.folder))throw Error(`${U(e.folder)} has edits that aren't in agent kit (${Gn(e.paths)}). Copy them to ${U(n)} and delete them there first.`)}for(let e of s)await Xn(e,n);F.success(`${r}: ${s.map(U).join(`, `)} → ${U(n)}`);let l=i===`project`?await td(on(a,`global`),r,n):[];l.length>0&&F.warn(`You also have ${r} in ${l.map(U).join(`, `)}, and your agents use that copy over this project's. Run ${L(`link ${e[0]} -g`)} to try yours everywhere instead.`),await nd(n,r),I(`${l.length>0?`This project's agents would use`:`Your agents use`} ${U(n)} as it is, edits included (a new session sees an edit an open one missed). ${L(`add ${r}`)} goes back to agent kit's version.`)}async function td(e,t,n){let r=[];for(let i of e){let e=h(i,t);u(e)&&await Jn(e)!==n&&r.push(e)}return r}async function nd(e,t){let n;try{n=gc(e)}catch{return}if(v(n,`skills`,t)!==e)return;let r=xc((await vc(n)).problems,[t]);r.some(e=>e.severity===`error`)&&F.warn([`agent kit won't make a version of ${t} as it is:`,...hs(r)].join(`
|
|
298
298
|
`))}function rd(e,t,n){let r=e.map(e=>{let r=t.skills[e.name],i=n.skills[e.name],a=e.contextCost,o=e=>a?su(e,a.source):`—`;return{skill:e,installed:r!==void 0||i!==void 0,cells:[jn(e),id(e),o(a?.description??0),o(a?.body??0),o(a?.files??0),[ad(`project`,r,e),ad(`global`,i,e)].filter(Boolean).join(`, `)]}}),i=[`SKILL`,`VERSION`,`DESC`,`BODY`,`FILES`,`INSTALLED`],a=i.map((e,t)=>Math.max(e.length,...r.map(e=>e.cells[t].length))),o=e=>e.map((t,n)=>n===e.length-1?t:t.padEnd(a[n])).join(` `).trimEnd(),s=r.filter(e=>e.installed),c=au(s.map(e=>e.skill.contextCost)),l=c.estimated?`~`:``,u=[o(i),...r.map(e=>o(e.cells))];return u.push(s.length===0?`${`TOTAL`.padEnd(a[0])} nothing installed here`:`${`TOTAL`.padEnd(a[0])} ${l}${ou(c.always)} always · ${l}${ou(c.max)} max (${s.length} installed${c.missing?`, ${c.missing} not counted yet`:``})`),r.some(e=>e.skill.contextCost?.source===`estimate`)&&u.push(`~ estimated locally: add a Claude API key to the organization to count exactly.`),u}function id(e){return[`v${e.version}`,...Yt.filter(t=>e.channels[t]!==null).map(t=>`${t} v${e.channels[t]}`)].join(` · `)}function ad(e,t,n){if(!t)return null;let r=Ji(t),{version:i}=$t(n.channels,n.version,r),a=`in ${e}${r===`latest`?``:` on ${r}`}`;return t.version===i?a:`${a} at v${t.version}, run a-kit update${e===`global`?` -g`:``}`}async function od(){let{api:e,credentials:t}=await Xa(),[n,r]=await Promise.all([e.listSkills(),e.listKits()]);if(n.length===0){console.log(Qa(t.webUrl));return}let i=await Y(J(`project`)),a=await Y(J(`global`));for(let e of rd(n,i,a))console.log(e);if(r.length===0)return;console.log(``);let o=Math.max(...r.map(e=>sd(e).length));for(let e of r){let t=[cd(i,e)&&`in project`,cd(a,e)&&`in global`].filter(Boolean);console.log(`${sd(e).padEnd(o)} ${ld(e)}`+(t.length?` (${t.join(`, `)})`:``))}}const sd=e=>`${bn}${jn(e)}`,cd=(e,t)=>Object.values(e.kits).some(e=>e.id===t.id);function ld(e){let t=e.skills.length;if(t===0)return`no skills`;let n=e.skills.slice(0,3).map(e=>e.name);return`${t} skill${t===1?``:`s`}: ${n.join(`, `)}${t>3?`, …`:``}`}async function ud(e,t){switch(e){case void 0:case`status`:{let e=(await Wa())?.organization;console.log(e?`This machine shows up on ${e.name}'s Machines page.`:`This machine hasn't shown up on a Machines page yet.`),console.log(`Move it to another organization with ${L(`org use`)}.`);return}case`use`:{let{api:e,credentials:n}=await Xa(),r=await Da(e,n,t);if(!r)throw Error(`Which organization? Name it, like ${L(`org use acme`)}.`);if((await Ln()).heartbeat===!1){F.warn(`This machine goes to ${r.name}, but its heartbeats are off. Turn them on with ${L(`heartbeat on`)}.`);return}await Ga()?F.success(`This machine now shows up on ${r.name}'s Machines page.`):F.warn(`This machine goes to ${r.name}; it shows up there with its next heartbeat.`);return}default:throw Error(`Unknown org action "${e}". Use status or use.`)}}async function dd(){Ht(`agent kit`);let e=await Ya().catch(()=>null);if(e){let t=Za(e.user);if(!gn()){I(`Already logged in as ${t}.`);return}if(!_n(await Lt({message:`You're logged in as ${t}. Log in with another account?`,initialValue:!1}))){I(`Still logged in as ${t}.`);return}}let t=await Ja();e&&await z(B(),e.token).logout().catch(()=>{}),I(await md(t.token,t.webUrl))}async function fd(e=process.stdin){Ht(`agent kit`);let t=await pd(e);if(!t)throw Error(`Give it the bot's token on stdin, like ${L(`login --token`)} < bot-token.`);let n;try{n=await z(B(),t).me()}catch(e){throw e instanceof R&&e.status===401?Error(`This token doesn't work: it's wrong, or the bot was revoked.`):e}let r=await H();await Fn({token:t,user:n,webUrl:Mn(B())}),r&&r.token!==t&&await z(B(),r.token).logout().catch(()=>{}),await Ka(),I(`Logged in as ${Za(n)}.`)}async function pd(e){if(e.isTTY)return _n(await Ut({message:`The bot's token`})).trim();let t=``;for await(let n of e)t+=String(n);return t.trim()}async function md(e,t){return(await z(B(),e).listSkills().catch(()=>null))?.length===0?`You're in. ${Qa(t)}`:`You're in. Install your skills with ${L(`init`)}.`}async function hd(){let e=await H();e?(await z(B(),e.token).logout().catch(()=>{}),await Fn(null),console.log(`Logged out ${Za(e.user)}.`)):console.log(`You're not logged in.`)}async function gd(){let e=await Ya();e?console.log(Za(e.user)):(console.log(`You're not logged in. Run ${L(`login`)}.`),process.exitCode=1)}const _d=/* @__PURE__ */ new Set([`push`,`pull`,`dev`,`propose`]);async function vd(e){let t=await yd(),n=t.length>0?t.map(e=>`gh repo clone ${e}`).join(` or `):`Clone your organization's skills repository from GitHub.`,r=[`\`${mn()} ${e}\` is gone: skills are changed in your organization's GitHub repository now, and merging a pull request there makes the new version.`,` 1. ${n}`,` 2. Change skills/<skill>/ and check it: ${L(`check <skill>`)}`,` 3. Try it in your agent: ${L(`link <clone>/skills/<skill>`)}`,e===`propose`?` 4. Commit it on a branch and open a pull request; that's the proposal, reviewed on GitHub.`:` 4. Commit it on a branch and open a pull request.`];throw e===`pull`&&r.push(`To get a skill's latest version instead, ${L(`add <skill>`)} or ${L(`update`)}.`),Error(r.join(`
|
|
299
|
-
`))}async function yd(){let e=(await H())?.token;if(!e)return[];let t=z(B(),e),n=async()=>{let e=await t.listOrganizations(),n=await Promise.all(e.map(e=>t.getRepository(e.id).then(e=>e.
|
|
299
|
+
`))}async function yd(){let e=(await H())?.token;if(!e)return[];let t=z(B(),e),n=async()=>{let e=await t.listOrganizations(),n=await Promise.all(e.map(e=>t.getRepository(e.id).then(e=>e.repositories?.map(e=>e.fullName)??(e.repository?[e.repository.fullName]:[])).catch(()=>[])));return[...new Set(n.flat())]},r=new Promise(e=>setTimeout(()=>e([]),3e3).unref());return Promise.race([n().catch(()=>[]),r])}const bd={maxTitleLength:120,maxNoteLength:4e3,maxSkills:50,maxTranscriptBytes:8388608},xd=[{kind:`private-key`,pattern:/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,strict:!0},{kind:`anthropic-key`,pattern:/\bsk-ant-[A-Za-z0-9_-]{20,}/g,strict:!0},{kind:`openai-key`,pattern:/\bsk-(?:proj-|svcacct-)?[A-Za-z0-9_-]{32,}/g,strict:!0},{kind:`github-token`,pattern:/\b(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{40,})/g,strict:!0},{kind:`aws-key`,pattern:/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,strict:!0},{kind:`slack-token`,pattern:/\bxox[abprs]-[A-Za-z0-9-]{10,}/g,strict:!0},{kind:`stripe-key`,pattern:/\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}/g,strict:!0},{kind:`google-key`,pattern:/\bAIza[0-9A-Za-z_-]{35}\b/g,strict:!0},{kind:`jwt`,pattern:/\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,strict:!0},{kind:`url-credentials`,pattern:/\b([a-z][a-z0-9+.-]*:\/\/)[^\s:/@]+:[^\s@/]+@/gi,keep:(e,t)=>`${t}<secret>@`,strict:!1},{kind:`bearer`,pattern:/\b(Bearer\s+)[A-Za-z0-9._~+/-]{20,}=*/g,keep:(e,t)=>`${t}<secret>`,strict:!1},{kind:`assignment`,pattern:/\b([A-Za-z0-9_]*(?:secret|token|password|passwd|api_?key|private_?key|access_?key)[A-Za-z0-9_]*["']?\s*[=:]\s*)(["']?)(?!<secret)[^\s"'`,;]{8,}\2/gi,keep:(e,t,n)=>`${t}${n}<secret>${n}`,strict:!1}],Sd=/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}\b/g,Cd=/\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g,wd=/* @__PURE__ */ new Set([`127.0.0.1`,`0.0.0.0`]),Td=/@(?:example\.(?:com|org|net)|anthropic\.com)$/i,Ed=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function Dd(e){let t={},n=(e,n=1)=>{t[e]=(t[e]??0)+n},r=e.paths.filter(e=>e.path.length>1).sort((e,t)=>t.path.length-e.path.length).map(e=>({...e,pattern:new RegExp(Ed(e.path),`g`)})),i=e.replacements.filter(e=>e.find.trim().length>1).sort((e,t)=>t.find.length-e.find.length).map(e=>({...e,pattern:new RegExp(e.find.length<4?`(?<![\\p{L}\\p{N}_])${Ed(e.find)}(?![\\p{L}\\p{N}_])`:Ed(e.find),`giu`)}));function a(e){let t=e;for(let e of xd)t=t.replace(e.pattern,(t,...r)=>(n(`secret:${e.kind}`),e.keep?e.keep(t,...r):`<secret>`));for(let e of r)t=t.replace(e.pattern,()=>(n(`path:${e.as}`),e.as));for(let e of i)t=t.replace(e.pattern,()=>(n(`term:${e.find}`),e.replace));return t=t.replace(Sd,e=>Td.test(e)?e:(n(`email`),`user@example.com`)),t=t.replace(Cd,e=>wd.has(e)?e:(n(`ip`),`192.0.2.1`)),t}function o(t){let r=e.maxToolText;return r===null||t.length<=r?t:(n(`cut`),`${t.slice(0,r)}\n… [${t.length-r} more characters left out by a-kit report]`)}function s(e){return typeof e==`string`?o(a(e)):Array.isArray(e)?e.map(s):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,s(t)])):e}function c(e){return e.type===`text`?{...e,text:a(e.text)}:e.type===`tool_use`?{...e,input:s(e.input)}:{...e,content:o(a(e.content))}}function l(e){return e.map(e=>e.type===`system`?e:{...e,message:{content:e.message.content.map(c)}})}return{text:a,events:l,counts:t}}const Od=e=>e.map(e=>JSON.stringify(e)).join(`
|
|
300
300
|
`)+`
|
|
301
301
|
`;function kd(e){let t=[],n=null,r=null,i=null;for(let a of e.split(`
|
|
302
302
|
`)){if(!a.trim())continue;let e;try{e=JSON.parse(a)}catch{continue}if(e.type!==`user`&&e.type!==`assistant`||e.isSidechain||e.isMeta)continue;r=e.version??r,i=e.cwd??i,e.type===`assistant`&&e.message?.model&&(e.message.model.startsWith(`<`)||(n=e.message.model));let o=Ad(e.message?.content);o.length>0&&t.push({type:e.type,message:{content:o}})}return{agent:`claude-code`,agentVersion:r,model:n,cwd:i,events:[{type:`system`,subtype:`init`,agent:`Claude Code`,agent_version:r,model:n},...t],loaded:[...new Set(t.flatMap(Ri))]}}function Ad(e){if(typeof e==`string`)return e.trim()?[{type:`text`,text:e}]:[];if(!Array.isArray(e))return[];let t=[];for(let n of e)n.type===`text`&&typeof n.text==`string`&&n.text.trim()?t.push({type:`text`,text:n.text}):n.type===`tool_use`?t.push({type:`tool_use`,id:String(n.id??``),name:String(n.name??``),input:n.input??{}}):n.type===`tool_result`&&t.push({type:`tool_result`,tool_use_id:String(n.tool_use_id??``),content:jd(n.content),...n.is_error===!0?{is_error:!0}:{}});return t}function jd(e){return typeof e==`string`?e:Array.isArray(e)?e.map(e=>e.type===`text`&&typeof e.text==`string`?e.text:e.type===`image`?`[image]`:``).filter(Boolean).join(`
|