useakit 0.2.0-dev.89 → 0.2.0-dev.90
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/README.md +1 -1
- package/dist/index.mjs +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ a-kit telemetry import --dry-run # what it would send, sending nothing
|
|
|
116
116
|
a-kit telemetry import # send it
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
The same rules as live telemetry apply: only a session in a repository of your organizations' is sent, and nothing of the others leaves the machine; no prompt, response, command, file path or tool output is ever sent. A session keeps its id, so importing twice changes nothing, and a session live telemetry already sent is left as it is. A bot logged in with `a-kit login --token` imports its own sessions as itself. `a-kit telemetry show <session-id>` shows what was sent for an imported session, like a live one.
|
|
119
|
+
The same rules as live telemetry apply: only a session in a repository of your organizations' is sent, and nothing of the others leaves the machine; a session whose folder is gone (a worktree removed since) is in the repository its own output names, when it names one only: the pull request and issue URLs its `gh` commands printed, the remote its `git push` printed, or the pull requests Claude Code tied it to; no prompt, response, command, file path or tool output is ever sent. A session keeps its id, so importing twice changes nothing, and a session live telemetry already sent is left as it is. A bot logged in with `a-kit login --token` imports its own sessions as itself. `a-kit telemetry show <session-id>` shows what was sent for an imported session, like a live one.
|
|
120
120
|
|
|
121
121
|
## Heartbeat
|
|
122
122
|
|
package/dist/index.mjs
CHANGED
|
@@ -71,7 +71,7 @@ ${r(`gray`,P)}`:``}`}default:{let a=i?`${r(`cyan`,P)} `:``,o=c.split(`
|
|
|
71
71
|
`),u=s.length+1;return`${c}${a}${Rt({output:e.output,cursor:this.cursor,options:this.options,maxItems:e.maxItems,columnPadding:a.length,rowPadding:o+u,style:(e,n)=>t(e,e.disabled?`disabled`:n?`active`:`inactive`)}).join(`
|
|
72
72
|
${a}`)}
|
|
73
73
|
${l}
|
|
74
|
-
`}}}}).prompt()};`${r(`gray`,P)}`;const Zt=[`stable`,`beta`],Qt=[`latest`,...Zt],$t=e=>Zt.includes(e),en=e=>Qt.includes(e);function tn(e,t,n){if(n===`latest`)return{version:t,fellBack:!1};let r=e[n];return r===null?{version:t,fellBack:!0}:{version:r,fellBack:!1}}var nn=`0.2.0-dev.
|
|
74
|
+
`}}}}).prompt()};`${r(`gray`,P)}`;const Zt=[`stable`,`beta`],Qt=[`latest`,...Zt],$t=e=>Zt.includes(e),en=e=>Qt.includes(e);function tn(e,t,n){if(n===`latest`)return{version:t,fellBack:!1};let r=e[n];return r===null?{version:t,fellBack:!0}:{version:r,fellBack:!1}}var nn=`0.2.0-dev.90`;const rn=[{id:`claude-code`,name:`Claude Code`,projectDir:`.claude/skills`,globalDir:`.claude/skills`,marker:`.claude`},{id:`codex`,name:`Codex`,projectDir:`.agents/skills`,globalDir:`.agents/skills`,marker:`.codex`},{id:`cursor`,name:`Cursor`,projectDir:`.agents/skills`,globalDir:`.cursor/skills`,marker:`.cursor`},{id:`gemini-cli`,name:`Gemini CLI`,projectDir:`.agents/skills`,globalDir:`.gemini/skills`,marker:`.gemini`}],an=e=>e===`global`?C():process.cwd();function on(e=C()){return rn.filter(t=>f(_(e,t.marker)))}function sn(e){return rn.find(t=>t.id===e)}function cn(e,t,n=an(t)){let r=e.map(e=>b(n,t===`global`?e.globalDir:e.projectDir));return[...new Set(r)]}const ln={maxNameLength:100,maxPromptBytes:20480,maxChecks:20,maxHiddenFiles:20,maxHiddenBytes:1048576,maxSetupLength:4096,maxCheckTextLength:10240,minTrials:1,maxTrials:5,maxAttemptsPerRun:50,maxModelsPerRun:4,maxFinalTextBytes:20480,maxJudgedDiffBytes:102400,maxCheckOutputBytes:8192,maxSandboxesPerOrganization:5};function un(e){return e===null||e===0?`—`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(e<1?3:2)}`}ln.maxPromptBytes;function dn(e){return e<1e3?String(e):e<1e6?`${pn(e/1e3)}k`:`${pn(e/1e6)}M`}const fn=e=>`${dn(e.inputTokens+e.outputTokens)} tok · ${un(e.costUsd)}`,pn=e=>e>=100?Math.round(e):Number(e.toFixed(1));function mn(e){switch(e){case`refusal`:return`Claude declined to answer this.`;case`max_tokens`:return`The answer was cut off at the token limit.`;case`tool_use`:return`Stopped after too many skill loads in one turn.`;default:return null}}function hn(e){let t=e.split(`
|
|
75
75
|
`),n=t.pop()??``,r=[];for(let e of t)if(e.trim()!==``)try{r.push(JSON.parse(e))}catch{r.push({type:`error`,message:`The answer came back garbled.`})}return{events:r,rest:n}}function gn(){return process.env.npm_command===`exec`||/[\\/]_npx[\\/]/.test(process.argv[1]??``)?nn.includes(`-dev`)?`npx useakit@next`:`npx useakit`:`a-kit`}const L=e=>`\`${gn()} ${e}\``;var R=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};function z(e,t,n=fetch){async function r(r,i={}){let a;try{a=await n(`${e}${r}`,{...i,headers:{"User-Agent":`a-kit/${nn}`,...i.body?{"Content-Type":`application/json`}:{},...t?{Authorization:`Bearer ${t}`}:{},...i.headers}})}catch{throw new R(0,`NETWORK`,`Couldn't reach ${e}.`)}if(!a.ok){let e=await a.json().catch(()=>null);throw a.status===401?new R(401,`UNAUTHORIZED`,`You're not logged in. Run ${L(`login`)}.`):new R(a.status,e?.code??`HTTP_ERROR`,e?.message??`${i.method??`GET`} ${r} failed (${a.status})`)}return a}let i=async(e,t)=>await(await r(e,t)).json();return{me:()=>i(`/me`),logout:()=>r(`/auth/logout`,{method:`POST`}),startLogin:()=>i(`/auth/cli`,{method:`POST`}),pollLogin:e=>i(`/auth/cli/token`,{method:`POST`,body:JSON.stringify({deviceCode:e})}),listSkills:async()=>{let[e,t]=await Promise.all([i(`/skills`),i(`/orgs`)]),n=new Map(t.map(e=>[e.id,e]));return e.map(e=>({...e,organizationName:n.get(e.organizationId)?.name??``,organizationSlug:n.get(e.organizationId)?.slug??null,showOrganization:t.length>1}))},listKits:async()=>{let[e,t]=await Promise.all([i(`/kits`),i(`/orgs`)]),n=new Map(t.map(e=>[e.id,e.name]));return e.map(e=>({...e,organizationName:n.get(e.organizationId)??``,showOrganization:t.length>1}))},getKit:e=>i(`/kits/${e}`),listOrganizations:e=>i(`/orgs`,{signal:e}),listSkillSummaries:e=>i(`/skills`,{signal:e}),listProjects:(e,t)=>i(`/orgs/${e}/projects`,{signal:t}),listRoles:(e,t)=>i(`/orgs/${e}/roles`,{signal:t}),getRepository:(e,t)=>i(`/orgs/${e}/repository`,{signal:t}),reportActivations:(e,t)=>i(`/activations`,{method:`POST`,body:JSON.stringify({activations:e}),signal:t}),reportSessionEvents:(e,t)=>i(`/agent-sessions/events`,{method:`POST`,body:JSON.stringify({events:e}),signal:t}),reportSessionUsage:(e,t)=>i(`/agent-sessions/usage`,{method:`POST`,body:JSON.stringify({sessions:e}),signal:t}),fingerprint:(e,t)=>i(`/fingerprint`,{method:`POST`,body:JSON.stringify(e),signal:t}),sendHeartbeat:(e,t)=>i(`/machines/heartbeat`,{method:`POST`,body:JSON.stringify(e),signal:t}),machineName:e=>i(`/machines/${encodeURIComponent(e)}/name`),nameMachine:(e,t)=>i(`/machines/${encodeURIComponent(e)}/name`,{method:`PUT`,body:JSON.stringify({name:t})}),search:e=>i(`/search?q=${encodeURIComponent(e)}`),getSkill:(e,t=`latest`)=>i(`/skills/${e}${t===`latest`?``:`?channel=${t}`}`),getVersion:(e,t)=>i(`/skills/${e}/versions/${t}`),getSkillHealth:e=>i(`/skills/${e}/health`),createReport:(e,t)=>i(`/orgs/${e}/reports`,{method:`POST`,body:JSON.stringify(t)}),playground:async(e,t,n)=>{let i=await r(`/skills/${e}/playground`,{method:`POST`,body:JSON.stringify(t)}),a=``,o=new TextDecoder;for await(let e of i.body??[]){let t=hn(a+o.decode(e,{stream:!0}));a=t.rest,t.events.forEach(n)}hn(`${a}${o.decode()}\n`).events.forEach(n)},getBlob:async(e,t)=>new Uint8Array(await(await r(`/skills/${e}/blobs/${t}`)).arrayBuffer()),getPublicSkill:e=>i(`/public/skills/${_n(e)}`),getPublicBlob:async(e,t)=>new Uint8Array(await(await r(`/public/skills/${_n(e)}/blobs/${t}`)).arrayBuffer()),countInstall:e=>r(`/public/skills/${_n(e)}/installs`,{method:`POST`})}}const _n=e=>e.split(`/`).map(encodeURIComponent).join(`/`),vn=()=>!!(process.stdin.isTTY&&process.stdout.isTTY)&&!process.env.CI;function yn(e){return rt(e)&&(Ut(`Cancelled.`),process.exit(130)),e}async function bn(e,t){if(e.length>0)return e.map(e=>{let t=sn(e);if(!t)throw Error(`Unknown agent "${e}". Use one of: ${rn.map(e=>e.id).join(`, `)}.`);return t});let n=on(),r=n.length>0?n:[sn(`claude-code`)];return!t||!vn()?r:yn(await Ht({message:`Which agents should get the skills?`,options:rn.map(e=>({value:e.id,label:e.name,hint:n.includes(e)?`detected`:void 0})),initialValues:r.map(e=>e.id),required:!0})).map(e=>sn(e))}async function xn(e,t){return e?`global`:!t||!vn()?`project`:yn(await Xt({message:`Where should they go?`,options:[{value:`project`,label:`This project`,hint:process.cwd()},{value:`global`,label:`Everywhere`,hint:`your home folder`}],initialValue:`project`}))}const Sn=`kit/`;function Cn(e){let t=[],n=[];for(let r of e)r.startsWith(`kit/`)?n.push(r.slice(4)):t.push(r);return{skills:t,kits:n}}async function wn(e,t,n){if(t.length>0)return En(e,t,n,`skill`);if(!n||!vn())throw Error(`Name the skills to add, like ${L(`add my-skill`)}.`);let r=yn(await Ht({message:`Which skills?`,options:e.map(e=>({value:e.id,label:Nn(e),hint:e.description.length>60?`${e.description.slice(0,57)}…`:e.description})),required:!0}));return e.filter(e=>r.includes(e.id))}const Tn=(e,t,n)=>En(e,t,n,`kit`);async function En(e,t,n,r){let i=[];for(let a of t){let t=An(e,a,r),o=t.length===1?t[0]:await jn(t,n,r);i.includes(o)||i.push(o)}return i}const Dn=(e,t)=>An(e,t,`skill`);function On(e,t){let n=t.lastIndexOf(`/`),r=t.slice(n+1),i=n===-1?null:t.slice(0,n).trim().toLowerCase();return e.filter(e=>e.name===r&&(i===null||e.organizationName.toLowerCase()===i||e.organizationSlug!=null&&e.organizationSlug===i))}const kn=(e,t)=>On(e,t);function An(e,t,n){let r=t.lastIndexOf(`/`),i=t.slice(r+1),a=On(e,t);if(a.length===0)throw Error(r===-1?`There's no ${n} named "${i}" in your agent kit. See them with ${L(`list`)}.`:`There's no ${n} named "${i}" in an organization called "${t.slice(0,r)}". See them with ${L(`list`)}.`);return a}async function jn(e,t,n){let r=e[0].name,i=n===`kit`?Sn:``;if(!t||!vn()){let t=e.map(e=>{let t=i+Mn(e);return L(`add ${/\s/.test(t)?`"${t}"`:t}`)});throw Error(`More than one of your organizations has a ${n} named "${r}". Say which one: ${t.join(` or `)}.`)}let a=yn(await Xt({message:`More than one of your organizations has ${n===`kit`?`kit/${r}`:`"${r}"`}. Which one?`,options:e.map(e=>({value:e.id,label:Mn(e)}))}));return e.find(e=>e.id===a)}const Mn=e=>`${e.organizationName}/${e.name}`,Nn=e=>e.showOrganization?`${e.name} (${e.organizationName})`:e.name;function B(){return(process.env.AGENT_KIT_API_URL??`https://api-dev.useagentkit.dev`??`http://localhost:8787`).replace(/\/+$/,``)}function Pn(e){let t=new URL(e);return t.hostname===`localhost`&&t.port===`8787`?`http://localhost:5173`:(t.hostname=t.hostname.replace(/^api(?:-([^.]+))?\./,(e,t)=>t?`${t}.`:``),t.origin)}function V(){return process.env.AGENT_KIT_CONFIG_DIR?process.env.AGENT_KIT_CONFIG_DIR:process.platform===`win32`&&process.env.APPDATA?_(process.env.APPDATA,`agent-kit`):_(process.env.XDG_CONFIG_HOME??_(C(),`.config`),`agent-kit`)}const Fn=()=>_(V(),`credentials.json`);async function In(){try{return JSON.parse(await O(Fn(),`utf8`))}catch{return{}}}async function H(){return(await In())[B()]??null}async function Ln(e){let t=await In();e?t[B()]=e:delete t[B()];let n=Fn();await D(g(n),{recursive:!0,mode:448}),await k(n,JSON.stringify(t,null,2)+`
|
|
76
76
|
`,{mode:384}),await re(n,384)}const Rn=()=>_(V(),`settings.json`);async function zn(){try{return JSON.parse(await O(Rn(),`utf8`))}catch{return{}}}async function Bn(e){let t={...await zn(),...e};await D(V(),{recursive:!0,mode:448}),await k(Rn(),JSON.stringify(t,null,2)+`
|
|
77
77
|
`)}function Vn(e=process.env){let t=e=>e!==void 0&&[`0`,`false`,`off`,`no`].includes(e.toLowerCase());return(e=>e!==void 0&&e!==``&&!t(e))(e.DO_NOT_TRACK)||t(e.AGENT_KIT_TELEMETRY)}function U(e){let t=y(process.cwd(),e);return t&&!t.startsWith(`..`)?t:e}const Hn=/* @__PURE__ */ new Set([`.DS_Store`,`Thumbs.db`,`desktop.ini`,`.git`,`.idea`,`.vscode`,`node_modules`,`__pycache__`,`4913`]);function Un(e){return e.split(`/`).some(e=>Hn.has(e)||/^\..*\.sw[a-p]$/.test(e)||e.endsWith(`~`)||/^#.*#$/.test(e)||e.startsWith(`.#`)||e.endsWith(`.tmp`))}const Wn=e=>he(`sha256`).update(e).digest(`hex`);async function Gn(e){let t=await ce(e,{recursive:!0,withFileTypes:!0}),n=[];for(let r of t){if(!r.isFile())continue;let t=y(e,_(r.parentPath,r.name)).split(x).join(`/`);if(Un(t))continue;let i=new Uint8Array(await O(_(e,t)));n.push({path:t,size:i.byteLength,sha256:Wn(i),bytes:i})}return n.sort((e,t)=>e.path<t.path?-1:+(e.path>t.path))}function Kn(e,t){let n=new Map(t.filter(e=>!Un(e.path)).map(e=>[e.path,e.sha256])),r=new Set(e.map(e=>e.path)),i=e.filter(e=>n.get(e.path)!==e.sha256),a=[...n.keys()].filter(e=>!r.has(e));return{upserts:i,deletes:a,paths:[...i.map(e=>e.path),...a].sort()}}function qn(e){return e.length===0?`nothing`:e.length>3?`${e.length} files`:e.length===1?e[0]:`${e.slice(0,-1).join(`, `)} and ${e.at(-1)}`}async function Jn(e,t){for(let n of e){if(!f(n))continue;let{paths:e}=Kn(await Gn(n),t);if(e.length>0)return{folder:n,paths:e}}return null}async function Yn(e,t,n,r){let i=await e.getVersion(n.id,n.version).catch(()=>null);return i?Jn(r.map(e=>_(e,t)),i.files):null}async function Xn(e){try{if(!(await oe(e)).isSymbolicLink())return null}catch{return null}return b(g(e),await le(e))}async function Zn(e,t){for(let n of e){let e=await Xn(_(n,t));if(e)return e}return null}async function Qn(e,t){await de(e,{recursive:!0,force:!0}),await D(g(e),{recursive:!0}),await pe(t,e,process.platform===`win32`?`junction`:`dir`)}const W=`SKILL.md`,$n={maxFiles:200,maxFileBytes:1048576,maxSkillBytes:10485760,maxPathLength:255},er=/[\u0000-\u001f\u007f\\:]/;function tr(e){if(e.trim()===``)return`The path is empty.`;if(e.length>$n.maxPathLength)return`Paths can be at most ${$n.maxPathLength} characters.`;if(e.startsWith(`/`))return`Use a relative path, without a leading /.`;if(er.test(e))return`Paths can't contain \\, : or control characters.`;for(let t of e.split(`/`)){if(t===``)return`The path has an empty folder name (//).`;if(t===`.`||t===`..`)return`The path can't contain . or .. folders.`;if(t!==t.trim())return`Names can't start or end with a space.`}return null}function nr(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function rr(e){return e.slice(e.lastIndexOf(`/`)+1)}function ir(e,t){let n=nr(e)?nr(e).split(`/`):[];for(let e of t.split(`/`))if(e!==``&&e!==`.`){if(e===`..`){if(n.length===0)return null;n.pop()}else n.push(e)}return n.join(`/`)}var G=/* @__PURE__ */ A((e=>{let t=Symbol.for(`yaml.alias`),n=Symbol.for(`yaml.document`),r=Symbol.for(`yaml.map`),i=Symbol.for(`yaml.pair`),a=Symbol.for(`yaml.scalar`),o=Symbol.for(`yaml.seq`),s=Symbol.for(`yaml.node.type`),c=e=>!!e&&typeof e==`object`&&e[s]===t,l=e=>!!e&&typeof e==`object`&&e[s]===n,u=e=>!!e&&typeof e==`object`&&e[s]===r,d=e=>!!e&&typeof e==`object`&&e[s]===i,f=e=>!!e&&typeof e==`object`&&e[s]===a,p=e=>!!e&&typeof e==`object`&&e[s]===o;function m(e){if(e&&typeof e==`object`)switch(e[s]){case r:case o:return!0}return!1}function h(e){if(e&&typeof e==`object`)switch(e[s]){case t:case r:case a:case o:return!0}return!1}e.ALIAS=t,e.DOC=n,e.MAP=r,e.NODE_TYPE=s,e.PAIR=i,e.SCALAR=a,e.SEQ=o,e.hasAnchor=e=>(f(e)||m(e))&&!!e.anchor,e.isAlias=c,e.isCollection=m,e.isDocument=l,e.isMap=u,e.isNode=h,e.isPair=d,e.isScalar=f,e.isSeq=p})),ar=/* @__PURE__ */ A((e=>{var t=G();let n=Symbol(`break visit`),r=Symbol(`skip children`),i=Symbol(`remove node`);function a(e,n){let r=l(n);t.isDocument(e)?o(null,e.contents,r,Object.freeze([e]))===i&&(e.contents=null):o(null,e,r,Object.freeze([]))}a.BREAK=n,a.SKIP=r,a.REMOVE=i;function o(e,r,a,s){let c=u(e,r,a,s);if(t.isNode(c)||t.isPair(c))return d(e,s,c),o(e,c,a,s);if(typeof c!=`symbol`){if(t.isCollection(r)){s=Object.freeze(s.concat(r));for(let e=0;e<r.items.length;++e){let t=o(e,r.items[e],a,s);if(typeof t==`number`)e=t-1;else if(t===n)return n;else t===i&&(r.items.splice(e,1),--e)}}else if(t.isPair(r)){s=Object.freeze(s.concat(r));let e=o(`key`,r.key,a,s);if(e===n)return n;e===i&&(r.key=null);let t=o(`value`,r.value,a,s);if(t===n)return n;t===i&&(r.value=null)}}return c}async function s(e,n){let r=l(n);t.isDocument(e)?await c(null,e.contents,r,Object.freeze([e]))===i&&(e.contents=null):await c(null,e,r,Object.freeze([]))}s.BREAK=n,s.SKIP=r,s.REMOVE=i;async function c(e,r,a,o){let s=await u(e,r,a,o);if(t.isNode(s)||t.isPair(s))return d(e,o,s),c(e,s,a,o);if(typeof s!=`symbol`){if(t.isCollection(r)){o=Object.freeze(o.concat(r));for(let e=0;e<r.items.length;++e){let t=await c(e,r.items[e],a,o);if(typeof t==`number`)e=t-1;else if(t===n)return n;else t===i&&(r.items.splice(e,1),--e)}}else if(t.isPair(r)){o=Object.freeze(o.concat(r));let e=await c(`key`,r.key,a,o);if(e===n)return n;e===i&&(r.key=null);let t=await c(`value`,r.value,a,o);if(t===n)return n;t===i&&(r.value=null)}}return s}function l(e){return typeof e==`object`&&(e.Collection||e.Node||e.Value)?Object.assign({Alias:e.Node,Map:e.Node,Scalar:e.Node,Seq:e.Node},e.Value&&{Map:e.Value,Scalar:e.Value,Seq:e.Value},e.Collection&&{Map:e.Collection,Seq:e.Collection},e):e}function u(e,n,r,i){if(typeof r==`function`)return r(e,n,i);if(t.isMap(n))return r.Map?.(e,n,i);if(t.isSeq(n))return r.Seq?.(e,n,i);if(t.isPair(n))return r.Pair?.(e,n,i);if(t.isScalar(n))return r.Scalar?.(e,n,i);if(t.isAlias(n))return r.Alias?.(e,n,i)}function d(e,n,r){let i=n[n.length-1];if(t.isCollection(i))i.items[e]=r;else if(t.isPair(i))e===`key`?i.key=r:i.value=r;else if(t.isDocument(i))i.contents=r;else{let e=t.isAlias(i)?`alias`:`scalar`;throw Error(`Cannot replace node with ${e} parent`)}}e.visit=a,e.visitAsync=s})),or=/* @__PURE__ */ A((e=>{var t=G(),n=ar();let r={"!":`%21`,",":`%2C`,"[":`%5B`,"]":`%5D`,"{":`%7B`,"}":`%7D`},i=e=>e.replace(/[!,[\]{}]/g,e=>r[e]);var a=class e{constructor(t,n){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},e.defaultYaml,t),this.tags=Object.assign({},e.defaultTags,n)}clone(){let t=new e(this.yaml,this.tags);return t.docStart=this.docStart,t}atDocument(){let t=new e(this.yaml,this.tags);switch(this.yaml.version){case`1.1`:this.atNextDocument=!0;break;case`1.2`:this.atNextDocument=!1,this.yaml={explicit:e.defaultYaml.explicit,version:`1.2`},this.tags=Object.assign({},e.defaultTags)}return t}add(t,n){this.atNextDocument&&=(this.yaml={explicit:e.defaultYaml.explicit,version:`1.1`},this.tags=Object.assign({},e.defaultTags),!1);let r=t.trim().split(/[ \t]+/),i=r.shift();switch(i){case`%TAG`:{if(r.length!==2&&(n(0,`%TAG directive should contain exactly two parts`),r.length<2))return!1;let[e,t]=r;return this.tags[e]=t,!0}case`%YAML`:{if(this.yaml.explicit=!0,r.length!==1)return n(0,`%YAML directive should contain exactly one part`),!1;let[e]=r;if(e===`1.1`||e===`1.2`)return this.yaml.version=e,!0;{let t=/^\d+\.\d+$/.test(e);return n(6,`Unsupported YAML version ${e}`,t),!1}}default:return n(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e===`!`)return`!`;if(e[0]!==`!`)return t(`Not a valid tag: ${e}`),null;if(e[1]===`<`){let n=e.slice(2,-1);return n===`!`||n===`!!`?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==`>`&&t(`Verbatim tags must end with a >`),n)}let[,n,r]=e.match(/^(.*!)([^!]*)$/s);r||t(`The ${e} tag has no suffix`);let i=this.tags[n];if(i)try{return i+decodeURIComponent(r)}catch(e){return t(String(e)),null}return n===`!`?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+i(e.substring(n.length));return e[0]===`!`?e:`!<${e}>`}toString(e){let r=this.yaml.explicit?[`%YAML ${this.yaml.version||`1.2`}`]:[],i=Object.entries(this.tags),a;if(e&&i.length>0&&t.isNode(e.contents)){let r={};n.visit(e.contents,(e,n)=>{t.isNode(n)&&n.tag&&(r[n.tag]=!0)}),a=Object.keys(r)}else a=[];for(let[t,n]of i)t===`!!`&&n===`tag:yaml.org,2002:`||e&&!a.some(e=>e.startsWith(n))||r.push(`%TAG ${t} ${n}`);return r.join(`
|
|
@@ -306,11 +306,11 @@ Every 5 minutes, a system timer tells agent kit this machine's name, the CLI's v
|
|
|
306
306
|
`):``}function af(e){if(typeof e!=`string`)return e??{};try{return JSON.parse(e)}catch{return{arguments:e}}}function of(e){if(typeof e==`string`){try{let t=JSON.parse(e);if(typeof t?.output==`string`)return t.output}catch{}return e}if(Array.isArray(e))return rf(e);if(typeof e==`object`&&e){let{content:t,output:n}=e;if(typeof n==`string`)return n;if(t!==void 0)return of(t)}return JSON.stringify(e??``)}const sf=()=>process.env.CLAUDE_CONFIG_DIR??_(C(),`.claude`),cf=()=>process.env.CODEX_HOME??_(C(),`.codex`),lf=(e,t=sf())=>_(t,`projects`,e.replace(/[^A-Za-z0-9]/g,`-`));async function uf(e,t,n=process.cwd()){if(t&&f(t))return b(t);let r=e===`claude-code`?await pf(t,n):await mf(t,n);if(r)return r.file;throw Error(t?`No ${ff(e)} session "${t}" on this machine.`:`No ${ff(e)} session for ${n}. Run this from the folder the session runs in, or pass --session <id or path>.`)}async function df(e=process.cwd()){if(process.env.CLAUDECODE===`1`)return`claude-code`;if(Object.keys(process.env).some(e=>e.startsWith(`CODEX_`)))return`codex`;let[t,n]=await Promise.all([pf(void 0,e),mf(void 0,e)]);if(t&&(!n||t.mtime>=n.mtime))return`claude-code`;if(n)return`codex`;throw Error(`No Claude Code or Codex session for ${e}. Pass --agent and --session.`)}const ff=e=>e===`claude-code`?`Claude Code`:`Codex`;async function pf(e,t){if(e){let t=_(sf(),`projects`),n=await yf(t);for(let r of n){let n=_(t,r,`${e}.jsonl`);if(f(n))return{file:n,mtime:0}}return null}for(let e of bf(t)){let t=lf(e),n=(await yf(t)).filter(e=>e.endsWith(`.jsonl`));if(n.length>0)return vf(n.map(e=>_(t,e)))}return null}async function mf(e,t){let n=_(cf(),`sessions`),r=[],i=0;outer:for(let e of hf(await yf(n)))for(let t of hf(await yf(_(n,e))))for(let a of hf(await yf(_(n,e,t)))){let o=_(n,e,t,a);for(let e of await yf(o))e.startsWith(`rollout-`)&&e.endsWith(`.jsonl`)&&r.push(_(o,e));if(r.length>=300||++i>=14)break outer}return gf(r,e,t)}const hf=e=>e.sort().reverse();async function gf(e,t,n){if(t){let n=e.find(e=>m(e).includes(t));return n?{file:n,mtime:0}:null}let r=bf(n),i=/* @__PURE__ */ new Map;for(let t of e){let e=await _f(t);e&&r.includes(e)&&i.set(e,[...i.get(e)??[],t])}for(let e of r){let t=i.get(e);if(t)return vf(t)}return null}async function _f(e){let t=await se(e,`r`);try{let e=Buffer.alloc(262144),{bytesRead:n}=await t.read(e,0,e.length,0),r=e.subarray(0,n).toString(`utf8`),i=r.indexOf(`
|
|
307
307
|
`);return tf(i===-1?r:r.slice(0,i))??(JSON.parse(`"${r.match(/"cwd":"((?:[^"\\]|\\.)*)"/)?.[1]??``}"`)||null)}finally{await t.close()}}async function vf(e){let t=null;for(let n of e){let{mtimeMs:e}=await fe(n);(!t||e>t.mtime)&&(t={file:n,mtime:e})}return t}async function yf(e){try{return await ce(e)}catch{return[]}}function bf(e){let t=[b(e)];for(;g(t.at(-1))!==t.at(-1);)t.push(g(t.at(-1)));return t}const xf=2e3;function Sf(e){let t=[...e.map],n=Tf(()=>ee().username);n&&n.length>=3&&t.push({find:n,replace:`user`});let r=Tf(()=>w());r&&r.length>=3&&r!==`localhost`&&t.push({find:r,replace:`host`});let i=Cf();if(i){t.push({find:i,replace:`acme/app`});let e=i.split(`/`)[0];e.length>=3&&t.push({find:e,replace:`acme`})}let a=Tf(()=>be(`git`,[`rev-parse`,`--show-toplevel`],{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim());return{replacements:t,paths:[...[...new Set([...e.cwds,a].filter(Boolean))].map(e=>({path:e,as:`<repo>`})),{path:C(),as:`~`}],maxToolText:e.fullOutputs?null:xf}}function Cf(){return Tf(()=>be(`git`,[`remote`,`get-url`,`origin`],{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim())?.match(/[:/]([^/:]+\/[^/]+?)(?:\.git)?$/)?.[1]??null}function wf(e){let t;try{t=JSON.parse(e)}catch{throw Error(`--map isn't valid JSON.`)}let n=Array.isArray(t)?t.map(e=>[e?.find,e?.replace]):typeof t==`object`&&t?Object.entries(t):null;if(!n||!n.every(([e,t])=>typeof e==`string`&&typeof t==`string`))throw Error(`--map must be an object of words to replace, like {"Acme Corp": "Example Inc"}.`);return n.map(([e,t])=>({find:e,replace:t}))}function Tf(e){try{return e()}catch{return null}}function Ef(e,t,n){let r=new Set(t),i=/* @__PURE__ */ new Map;for(let t of n)for(let[n,a]of Object.entries(t.skills))Of(a.agents,e)&&(i.has(n)||i.set(n,{name:n,skillId:a.id,version:a.version,triggered:r.has(n)}));for(let e of t)e===`report-session-issue`||i.has(e)||i.set(e,{name:e,skillId:null,version:null,triggered:!0});return i.delete(Pi),[...i.values()]}const Df=[`codex`,`cursor`,`gemini-cli`],Of=(e,t)=>e.length===0||e.includes(t)||Df.includes(t)&&e.some(e=>Df.includes(e));async function kf(e){Wt(`agent kit report`);let t=await Af(e.agent[0]),n=await uf(t,e.session||void 0),r=await O(n,`utf8`),i=Ri(t===`claude-code`?Xd(r):ef(r));if(i.events.length<2)throw Error(`${n} has no conversation to report.`);let a=Jd(Sf({map:e.map?wf(await jf(e.map)):[],cwds:i.cwd?[i.cwd]:[],fullOutputs:e.fullOutputs})),o=a.text(Nf(e.title,`--title`,`a short title`)),s=a.text(Nf(e.note,`--note`,`what went wrong`)),c=e.expected?a.text(e.expected):null,l=Yd(a.events(i.events)),u=await Promise.all([Y(J(`project`)),Y(J(`global`))]),d=Ef(t,i.loaded,u),f={title:o,note:s,expected:c,agent:t,agentVersion:i.agentVersion,model:i.model,skills:d,transcript:l},p=_(E(),`a-kit-report-${Date.now()}.jsonl`);if(await k(p,l),F.info([`${ff(t)} session: ${n}`,`Model: ${i.model??`unknown`}, ${i.events.length-1} messages`,`Skills: ${Ff(d)}`,`Taken out: ${If(a.counts)}`,`Scrubbed transcript: ${p}`].join(`
|
|
308
308
|
`)),Buffer.byteLength(l)>Vd.maxTranscriptBytes)throw Error(`The transcript is over ${Vd.maxTranscriptBytes/1024/1024} MB.${e.fullOutputs?` Leave out --full-outputs.`:``}`);if(e.dryRun){I(`Nothing was sent. Check the file above, then run it again without --dry-run.`);return}if(!e.yes){if(!vn())throw Error(`Check the scrubbed transcript, then pass --yes to send it.`);if(!yn(await zt({message:`Send this report to agent kit?`}))){I(`Not sent.`);return}}let{api:m,credentials:h}=await no(),[g,v]=await Promise.all([m.listOrganizations(),m.listSkills()]),y=Pf(e.org,g,v,d),b=await m.createReport(y.id,f);I(`Reported: ${h.webUrl}/app/orgs/${y.id}/reports/${b.id}`)}async function Af(e){if(e===void 0)return df();if(e===`claude-code`||e===`codex`)return e;throw Error(`a-kit report reads Claude Code and Codex sessions; --agent must be claude-code or codex.`)}const jf=e=>e===`-`?Mf():O(e,`utf8`);async function Mf(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString(`utf8`)}function Nf(e,t,n){if(!e?.trim())throw Error(`Pass ${t} with ${n}.`);return e}function Pf(e,t,n,r){let i=()=>t.map(e=>`${e.name} (${e.id})`).join(`, `);if(e){let n=t.filter(t=>t.id===e||t.name===e);if(n.length===1)return n[0];throw Error(`--org: none of your organizations is "${e}". Yours: ${i()}`)}let a=new Set(r.map(e=>e.skillId).filter(Boolean)),o=new Set(n.filter(e=>a.has(e.id)).map(e=>e.organizationId));if(o.size===1){let e=t.find(e=>o.has(e.id));if(e)return e}if(t.length===1)return t[0];throw Error(`Which organization is it for? Pass --org with one of: ${i()}`)}function Ff(e){return e.length===0?`none`:e.map(e=>`${e.name}${e.version?` v${e.version}`:``}${e.triggered?` (loaded)`:``}`).join(`, `)}function If(e){let t=Object.entries(e);return t.length===0?`nothing`:t.map(([e,t])=>e===`cut`?`${t} tool outputs cut to ${xf} characters`:`${e} ×${t}`).join(`, `)}function Lf(e){return e&&e.total>0?e.passed/e.total:null}async function Rf(e){let{api:t,credentials:n}=await no(),[r,i]=await Promise.all([t.search(e.join(` `)),t.listOrganizations()]);console.log(zf(r,n.webUrl,i.length>1))}function zf({skills:e,runs:t},n,r){if(e.length===0&&t.length===0)return`Nothing matches.`;let i=[];if(e.length>0){let t=e.map(e=>Nn({...e,showOrganization:r})),n=Math.max(...t.map(e=>e.length));i.push(`Skills`),e.forEach((e,r)=>{i.push(` ${t[r].padEnd(n)} v${e.version} a-kit add ${e.name}`)})}if(t.length>0){i.length>0&&i.push(``);let e=t.map(e=>`${e.skillName} v${e.version}`),r=Math.max(...e.map(e=>e.length));i.push(`Runs`),t.forEach((t,a)=>{let o=Lf(t.withSkill),s=o===null?`—`:`${Math.round(o*100)}%`;i.push(` ${e[a].padEnd(r)} ${s.padStart(4)} ${t.status.padEnd(9)} ${n}/app/skills/${t.skillId}?tab=runs&run=${t.id}`)})}return i.join(`
|
|
309
|
-
`)}const Bf={inputTokens:X.inputTokens,outputTokens:X.outputTokens,cacheReadInputTokens:X.cacheReadTokens,cacheCreationInputTokens:X.cacheCreationTokens,costUSD:X.costUsd},Vf={input_tokens:X.inputTokens,output_tokens:X.outputTokens,cache_read_input_tokens:X.cacheReadTokens,cache_creation_input_tokens:X.cacheCreationTokens},Hf=/^\{"type":"(api-request|atis-latch|queue-operation)/;function Uf(e){let t={sessionId:e,cwd:null,startedAt:null,endedAt:null,branches:[],skills:[],commands:[],prompts:0,runs:[],replies:{},
|
|
310
|
-
`):``}function
|
|
311
|
-
`):null}function Jf(e){if(e.isMeta||e.isSidechain||e.isCompactSummary||e.promptSource===`system`||e.origin)return!1;let t=qf(e);return t!==null&&!/^\s*(<(local-command-|task-notification|bash-|system-reminder)|\[Request interrupted)/.test(t)}function Yf(e){let t=qf(e);if(!t)return null;let n=/<command-name>\s*\/?([^\s<]+)\s*<\/command-name>/.exec(t)?.[1];if(n){let e=/<command-args>([\s\S]*?)<\/command-args>/.exec(t)?.[1];return`/${n}${e?.trim()?` ${e.trim()}`:``}`}return/^\s*\/[^\s]/.test(t)?t.trimStart():null}async function Xf(e,t){let n=l({input:d(e,{encoding:`utf8`}),crlfDelay:1/0});for await(let e of n)t(e)}async function Zf(e,t){let n=Uf(t);await Xf(e,e=>n.take(e));let r=n.result();if(r.runs.length>0)return r;let i=_(e.replace(/\.jsonl$/,``),`subagents`),a=[];try{a=(await ce(i)).filter(e=>e.endsWith(`.jsonl`))}catch{return r}for(let e of a)await Xf(_(i,e),e=>n.take(e,{subagent:!0}));return n.result()}const Qf=`claude-code`,$f={outside:`not in a repository of your organizations'`,gone:`its folder is gone, and nothing says which repository it was`,empty:`nothing in it says when it was`,old:`older than ${il.maxAgeDays} days, which agent kit doesn't take`,live:`already sent by live telemetry, left as they were`},ep=(e=C())=>_(process.env.CLAUDE_CONFIG_DIR??_(e,`.claude`),`projects`);async function tp(e){let t;try{t=await ce(e)}catch{return[]}let n=[];for(let r of t){let t;try{t=await ce(_(e,r))}catch{continue}for(let i of t){let t=i.replace(/\.jsonl$/,``);if(t===i||!Tc.test(t))continue;let a=_(e,r,i),{mtimeMs:o,isFile:s}=await fe(a).then(e=>({mtimeMs:e.mtimeMs,isFile:e.isFile()}),()=>({mtimeMs:0,isFile:!1}));s&&n.push({file:a,sessionId:t,at:o})}}return n.sort((e,t)=>e.at-t.at)}async function np(e){let t=e.now??/* @__PURE__ */ new Date,n={sessions:[],skipped:{}},r=e=>{n.skipped[e]=(n.skipped[e]??0)+1};for(let{file:i,sessionId:a}of await tp(e.projectsDir)){let o=await rp(await Zf(i,a),e,t);typeof o==`string`?r(o):n.sessions.push(o)}return n.sessions.sort((e,t)=>e.startedAt.localeCompare(t.startedAt)),n}async function rp(e,t,n=t.now??/* @__PURE__ */ new Date){if(e.startedAt===null||e.endedAt===null||!e.cwd)return`empty`;if(e.endedAt<n.getTime()-il.maxAgeDays*864e5)return`old`;let r=t.home??C(),i=e.cwd,a=await ip(e,i,r,t.known);if(!a.audience||!a.repository)return f(i)||xa(i,r)?`outside`:`gone`;if(await Ol(e.sessionId))return`live`;let o=a.repository,s={sessionId:e.sessionId,agent:Qf,machineId:t.machineId,machineName:t.machineName,imported:!0},c=[],l=(e,t)=>{let n=t.filter(e=>e!==null);n.length>0&&c.push({at:e,links:n})};l(e.startedAt,[Z(`repository`,o)]);for(let{branch:t,at:n}of e.branches)await Rc(i,t)||l(n,[Z(`branch`,`${o}#${t}`)]);for(let t of e.skills)t.command&&l(t.at,ml(t.command,o));for(let{command:t,stdout:n,at:r}of e.commands)l(r,hl(t,n,o));c.sort((e,t)=>e.at-t.at);let u=/* @__PURE__ */ new Set,d=[],p=(e,t,n)=>{for(let r=0;r===0||r<n.length;){let i=n.slice(r,r+il.maxLinks);d.push({...s,type:e,occurredAt:sp(t),links:i}),r+=Math.max(i.length,1)}},m=e=>e.filter(e=>{let t=kl(e);return!u.has(t)&&(u.add(t),!0)}),h=m(c.filter(t=>t.at<=e.startedAt).flatMap(e=>e.links));p(`start`,e.startedAt,h);for(let{at:t,links:n}of c){if(t<=e.startedAt)continue;let r=m(n);r.length>0&&p(`seen`,t,r)}p(`end`,e.endedAt,[]);let g=[];for(let[n,o]of e.skills.entries()){let c=await ba(o.name,Qf,i,r);c&&g.push({...s,...Ic({...a,branch:ap(e,o.at)},t.known.skills[c.id]??null),id:cp(`${e.sessionId}\n${n}\n${o.at}\n${o.name}`),skillId:c.id,version:c.version,trigger:o.trigger,occurredAt:sp(o.at),sessionId:e.sessionId})}let _=await t.organizationOf({sessionId:e.sessionId,agent:Qf,cwd:i,projectLock:xa(i,r),repository:o,branch:e.branches[0]?.branch??null,registeredAt:sp(e.startedAt)});if(_===`unknown`)throw Error(`Couldn't ask agent kit which organization a session's repository is. Try again in a moment.`);let v=_?{...s,organizationId:_.organizationId,occurredAt:sp(e.endedAt),usage:op(e)}:null;return{sessionId:e.sessionId,repository:o,startedAt:sp(e.startedAt),events:d,activations:g,usage:v}}async function ip(e,t,n,r){let i=await Fc(e.sessionId,t,n,r);if(i.repository||f(t))return i;for(let t of e.pullRequestRepositories){let n=`github.com/${t.toLowerCase()}`,i=r.repositories[n];if(i)return{sessionId:e.sessionId,repository:n,branch:null,audience:{organizationId:i}}}return i}function ap(e,t){let n=null;for(let r of e.branches)r.at<=t&&(n=r.branch);return n??e.branches[0]?.branch??null}function op(e){let t=[],n=e.runs.length>0?e.runs:[{start:e.startedAt,models:e.replies}];e.prompts>0&&t.push({metric:X.prompts,model:null,skillId:null,start:sp(n[0]?.start??e.startedAt),value:e.prompts});for(let e of n)for(let[n,r]of Object.entries(e.models))for(let[i,a]of Object.entries(r))a>0&&t.push({metric:i,model:n,skillId:null,start:sp(e.start),value:a});return t.slice(0,nl.maxEntries)}const sp=e=>new Date(e).toISOString();function cp(e){let t=he(`sha256`).update(e).digest(`hex`),n=(parseInt(t[16],16)&3|8).toString(16);return`${t.slice(0,8)}-${t.slice(8,12)}-5${t.slice(13,16)}-${n}${t.slice(17,20)}-${t.slice(20,32)}`}const lp=il.maxPerRequest;async function up(e,t){let n=/* @__PURE__ */ new Set,r=t.sessions.flatMap(e=>e.events);for(let t=0;t<r.length;t+=lp){let i=await e.reportSessionEvents(r.slice(t,t+lp));for(let e of i.live??[])n.add(e)}let i=t.sessions.filter(e=>!n.has(e.sessionId)),a=i.flatMap(e=>e.activations);for(let t=0;t<a.length;t+=100)await e.reportActivations(a.slice(t,t+100));let o=[],s=0;for(let t of i.flatMap(e=>e.usage?[e.usage]:[])){let n=JSON.stringify(t).length;o.length>0&&(o.length>=nl.maxPerRequest||s+n>409600)&&(await e.reportSessionUsage(o),o=[],s=0),o.push(t),s+=n}return o.length>0&&await e.reportSessionUsage(o),{sent:i,live:[...n]}}async function dp({dryRun:e}){let t=await H();if(!t)throw Error("Log in first with `a-kit login`.");if(!e&&(Vn()||(await zn()).telemetry===!1))throw Error("Telemetry is off, so nothing is sent. Turn it on with `a-kit telemetry on`, or see what would be sent with `--dry-run`.");let n=z(B(),t.token),r=t.user.id,i=await ps(n,r,await us(r),/* @__PURE__ */ new Date);if(!i)throw Error(`Couldn't ask agent kit which repositories are your organizations'. Try again in a moment.`);let a=Fl(async()=>({api:n,userId:r})),o=ep(),s=await np({projectsDir:o,known:i,organizationOf:e=>a.of(e),machineId:await Sa(),machineName:ha()});if(e){for(let e of s.sessions)console.log(mp(e));console.log(`\nWould send ${fp(s.sessions.length)} from ${o}. Nothing was sent.`),pp(s.skipped,`Would skip`),s.sessions.length>0&&console.log(`agent kit leaves a session live telemetry already sent as it is.`);return}let c=await up({reportSessionEvents:e=>n.reportSessionEvents(e),reportActivations:e=>n.reportActivations(e),reportSessionUsage:e=>n.reportSessionUsage(e)},s);for(let e of c.sent)await Dl(e.sessionId,e.events.flatMap(e=>e.links)),e.usage&&await $l(e.usage,`sent`);F.success(`Sent ${fp(c.sent.length)} from ${o} to agent kit.`),pp({...s.skipped,...c.live.length>0&&{live:(s.skipped.live??0)+c.live.length}},`Skipped`),console.log("Claude Code keeps about 30 days of sessions. `a-kit telemetry show <session-id>` shows what was sent for one.")}const fp=e=>`${e} session${e===1?``:`s`}`;function pp(e,t){let n=Object.entries(e),r=n.reduce((e,[,t])=>e+t,0);if(r!==0){console.log(`${t} ${fp(r)}:`);for(let[e,t]of n)console.log(` ${t} ${$f[e]}`)}}function mp(e){let t=new Set(e.events.flatMap(e=>e.links.map(kl))),n=e=>[...t].filter(t=>t.startsWith(`${e} `)).length,r=e.usage?.usage.filter(e=>e.metric===X.costUsd).reduce((e,t)=>e+t.value,0),i=[`${n(`branch`)} branches`,`${n(`pull_request`)} pull requests`,`${n(`issue`)} issues`,`${e.activations.length} skills loaded`,e.usage?r?`$${r.toFixed(2)}`:`usage`:`no usage (no organization of yours is its)`];return`${e.sessionId} ${e.startedAt} ${e.repository} ${i.join(`, `)}`}const hp={collector:`sends its OpenTelemetry to the collector`,elsewhere:"exports its telemetry elsewhere; the collector gets nothing (see `env` in ~/.claude/settings.json)",off:`doesn't send its OpenTelemetry to the collector`};async function gp(e,t,{port:n,dryRun:r=!1}={}){switch(e){case`on`:{n!==void 0&&await uo(Number(n)),await Bn({telemetry:!0});let e=await Po();if(e.status===`skipped`){F.warn(`Couldn't add the Claude Code hook: ${e.reason}.`);return}F.success(`Telemetry is on: Claude Code reports its sessions, what they used and the skills it loads.`),e.exportsElsewhere&&F.warn("Claude Code exports its telemetry elsewhere (`env` in ~/.claude/settings.json), so the collector gets nothing.");return}case`off`:await Bn({telemetry:!1}),await Po(),await fd({send:!1}),F.success("Telemetry is off: Claude Code doesn't report its sessions or the skills it loads, and the collector stopped. Turn it back on with `a-kit telemetry on`.");return;case`show`:return vp(t);case`import`:return dp({dryRun:r});case void 0:case`status`:{let e=await zn(),t=(await Lo()).includes(`telemetry`),n=e.telemetry===!1?`off`:Vn()?`off in this environment (DO_NOT_TRACK or AGENT_KIT_TELEMETRY)`:`on`,{port:r}=await lo(),i=await ld(),a=i===`taken`?`another user's collector has the port`:i?`running (process ${i.pid})`:`not running`;console.log(`Telemetry is ${n}.`),console.log(`Claude Code: ${t?`reports its sessions and the skills it loads`:`no hook installed`}; ${hp[await Io()]}.`),console.log(`Collector: port ${r}, ${a}.`),console.log("\nWhen an agent loads a skill installed from agent kit, it reports the skill, its version, the agent, its session, this machine and when, so your organization sees which skills get used. It also reports when each session starts and ends. In a repo that installs skills from agent kit, it reports the repository and the branch too, the issue a skill was started for (`/implement 12`), the pull requests and issues a `gh` command opened or changed, and where the session came from (`AGENT_KIT_FROM`).\n\nClaude Code also sends its OpenTelemetry to a collector on this machine, which sends your organization what each session used: tokens and cost by model and by skill, how long you and the agent were each at work, and how many prompts, commits and pull requests it made. Only for a session in a repository of your organization's (one of its projects, or one that installs its skills); nothing of the others. Never what you or the agent wrote: no prompt, response, command or file path leaves the machine. `a-kit telemetry show` shows what was sent.\nTurn it off with `a-kit telemetry off`.");return}default:throw Error(`Unknown telemetry action "${e}". Use on, off, status, show or import.`)}}const _p={sent:`sent`,waiting:`waiting to be sent`,refused:`refused by agent kit, not sent again`};async function vp(e){if(e){let[t,n]=await Promise.all([eu(e),El(e)]);if(!t&&n.length===0)throw Error(`Nothing was sent for session ${e}.`);console.log(n.length>0?`Its session told agent kit of:\n${n.map(e=>` ${e}`).join(`
|
|
312
|
-
`)}`:`Its session told agent kit of no repository or branch.`),console.log(t?`\nWhat it used, ${
|
|
313
|
-
Nothing of what it used was sent.`);return}let t=await tu();if(t.length===0)console.log(`Nothing was sent for a session yet.`);else{for(let{at:e,status:n,record:r}of t)console.log(`${r.sessionId} ${r.organizationId} ${e} ${
|
|
309
|
+
`)}const Bf={inputTokens:X.inputTokens,outputTokens:X.outputTokens,cacheReadInputTokens:X.cacheReadTokens,cacheCreationInputTokens:X.cacheCreationTokens,costUSD:X.costUsd},Vf={input_tokens:X.inputTokens,output_tokens:X.outputTokens,cache_read_input_tokens:X.cacheReadTokens,cache_creation_input_tokens:X.cacheCreationTokens},Hf=/^\{"type":"(api-request|atis-latch|queue-operation)/;function Uf(e){let t={sessionId:e,cwd:null,startedAt:null,endedAt:null,branches:[],skills:[],commands:[],prompts:0,runs:[],replies:{},namedRepositories:[]},n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Map,a=e=>{let n=e.toLowerCase();t.namedRepositories.includes(n)||t.namedRepositories.push(n)},o=e=>{let n=e.message,i=typeof n?.id==`string`?n.id:null,a=typeof n?.model==`string`?n.model:null,o=n?.usage;if(!i||!a||a.startsWith(`<`)||r.has(i)||typeof o!=`object`||!o)return;r.add(i);let s=t.replies[a]??={};for(let[e,t]of Object.entries(Vf)){let n=o[e];typeof n==`number`&&n>0&&(s[t]=(s[t]??0)+n)}};return{take(r,{subagent:s=!1}={}){if(!r||Hf.test(r))return;let c;try{c=JSON.parse(r)}catch{return}if(typeof c!=`object`||!c)return;if(s){c.type===`assistant`&&o(c);return}if(typeof c.sessionId==`string`&&c.sessionId!==e)return;c.type===`assistant`&&o(c);let l=typeof c.timestamp==`string`?Date.parse(c.timestamp):NaN;Number.isNaN(l)||(t.startedAt=Math.min(t.startedAt??l,l),t.endedAt=Math.max(t.endedAt??l,l)),t.cwd===null&&typeof c.cwd==`string`&&c.cwd&&(t.cwd=c.cwd);let u=c.gitBranch;switch(typeof u==`string`&&u&&u!==`HEAD`&&!Number.isNaN(l)&&!t.branches.some(e=>e.branch===u)&&t.branches.push({branch:u,at:l}),c.type){case`cost-state`:Yf(c,n);return;case`pr-link`:typeof c.prRepository==`string`&&Kf.test(c.prRepository)&&a(c.prRepository);return;case`assistant`:if(Number.isNaN(l))return;for(let e of Xf(c)){if(e.type!==`tool_use`||typeof e.input!=`object`)continue;let n=e.input??{};if(e.name===`Skill`&&typeof n.skill==`string`){let e=n.skill.replace(/^\//,``),r=typeof n.args==`string`?n.args:null;t.skills.push({name:e,command:r===null?null:`/${e} ${r}`,trigger:`model`,at:l})}if(e.name!==`Bash`||typeof n.command!=`string`||typeof e.id!=`string`)continue;let r=Wf.test(n.command),a=Gf.test(n.command);(r||a)&&i.set(e.id,{command:n.command,at:l,gh:r,push:a})}return;case`user`:{for(let e of Xf(c)){if(e.type!==`tool_result`||typeof e.tool_use_id!=`string`)continue;let n=i.get(e.tool_use_id);if(!n)continue;i.delete(e.tool_use_id);let r=Zf(c,e);if(n.gh){for(let e of r.matchAll(qf))a(e[1]);t.commands.push({command:n.command,stdout:r,at:Number.isNaN(l)?n.at:l})}if(n.push){let e=`${r}\n${Qf(c)}`;for(let t of e.matchAll(Jf))a(t[1])}}if(Number.isNaN(l)||!ep(c))return;t.prompts++;let e=tp(c),n=e?.match(/^\/([^\s]+)/)?.[1];e&&n&&t.skills.push({name:n,command:e,trigger:`user`,at:l});return}}},result(){for(let{command:e,at:n,gh:r}of i.values())r&&t.commands.push({command:e,at:n,stdout:``});return i.clear(),t.commands.sort((e,t)=>e.at-t.at),t.runs=[...n.values()].sort((e,t)=>e.start-t.start),t}}}const Wf=/(^|[\s;&|(])gh\s/,Gf=/(^|[\s;&|(])git\s(?:[^;&|\n]*\s)?push\b/,Kf=/^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/,qf=/https:\/\/github\.com\/([A-Za-z0-9-]+\/[A-Za-z0-9._-]+)\/(?:pull|issues)\/\d+/g,Jf=/^To (?:https:\/\/(?:[^@\s/]+@)?github\.com\/|(?:ssh:\/\/)?git@github\.com[:/]|github\.com:)([A-Za-z0-9-]+\/[A-Za-z0-9._-]+?)(?:\.git)?\/?\s*$/gm;function Yf(e,t){let n=e.startTime,r=e.modelUsage;if(typeof n!=`number`||typeof r!=`object`||!r)return;let i=t.get(n);i||t.set(n,i={start:n,models:{}});for(let[e,t]of Object.entries(r)){if(typeof t!=`object`||!t)continue;let n=i.models[e]??={};for(let[e,r]of Object.entries(Bf)){let i=t[e];typeof i==`number`&&i>(n[r]??0)&&(n[r]=i)}}}function Xf(e){let t=e.message?.content;return Array.isArray(t)?t.filter(e=>typeof e==`object`&&!!e):[]}function Zf(e,t){let n=e.toolUseResult;if(typeof n==`object`&&n){let e=n.stdout;if(typeof e==`string`)return e}return typeof t.content==`string`?t.content:Array.isArray(t.content)?t.content.map(e=>typeof e==`object`&&e&&typeof e.text==`string`?e.text:``).join(`
|
|
310
|
+
`):``}function Qf(e){let t=e.toolUseResult;if(typeof t!=`object`||!t)return``;let n=t.stderr;return typeof n==`string`?n:``}function $f(e){let t=e.message?.content;if(typeof t==`string`)return t;let n=Xf(e);if(n.some(e=>e.type===`tool_result`))return null;let r=n.filter(e=>e.type===`text`);return r.length>0?r.map(e=>typeof e.text==`string`?e.text:``).join(`
|
|
311
|
+
`):null}function ep(e){if(e.isMeta||e.isSidechain||e.isCompactSummary||e.promptSource===`system`||e.origin)return!1;let t=$f(e);return t!==null&&!/^\s*(<(local-command-|task-notification|bash-|system-reminder)|\[Request interrupted)/.test(t)}function tp(e){let t=$f(e);if(!t)return null;let n=/<command-name>\s*\/?([^\s<]+)\s*<\/command-name>/.exec(t)?.[1];if(n){let e=/<command-args>([\s\S]*?)<\/command-args>/.exec(t)?.[1];return`/${n}${e?.trim()?` ${e.trim()}`:``}`}return/^\s*\/[^\s]/.test(t)?t.trimStart():null}async function np(e,t){let n=l({input:d(e,{encoding:`utf8`}),crlfDelay:1/0});for await(let e of n)t(e)}async function rp(e,t){let n=Uf(t);await np(e,e=>n.take(e));let r=n.result();if(r.runs.length>0)return r;let i=_(e.replace(/\.jsonl$/,``),`subagents`),a=[];try{a=(await ce(i)).filter(e=>e.endsWith(`.jsonl`))}catch{return r}for(let e of a)await np(_(i,e),e=>n.take(e,{subagent:!0}));return n.result()}const ip=`claude-code`,ap={outside:`not in a repository of your organizations'`,gone:`its folder is gone, and nothing it printed says which repository it was`,several:`its folder is gone, and what it printed names more than one repository`,empty:`nothing in it says when it was`,old:`older than ${il.maxAgeDays} days, which agent kit doesn't take`,live:`already sent by live telemetry, left as they were`},op=(e=C())=>_(process.env.CLAUDE_CONFIG_DIR??_(e,`.claude`),`projects`);async function sp(e){let t;try{t=await ce(e)}catch{return[]}let n=[];for(let r of t){let t;try{t=await ce(_(e,r))}catch{continue}for(let i of t){let t=i.replace(/\.jsonl$/,``);if(t===i||!Tc.test(t))continue;let a=_(e,r,i),{mtimeMs:o,isFile:s}=await fe(a).then(e=>({mtimeMs:e.mtimeMs,isFile:e.isFile()}),()=>({mtimeMs:0,isFile:!1}));s&&n.push({file:a,sessionId:t,at:o})}}return n.sort((e,t)=>e.at-t.at)}async function cp(e){let t=e.now??/* @__PURE__ */ new Date,n={sessions:[],skipped:{}},r=e=>{n.skipped[e]=(n.skipped[e]??0)+1};for(let{file:i,sessionId:a}of await sp(e.projectsDir)){let o=await lp(await rp(i,a),e,t);typeof o==`string`?r(o):n.sessions.push(o)}return n.sessions.sort((e,t)=>e.startedAt.localeCompare(t.startedAt)),n}async function lp(e,t,n=t.now??/* @__PURE__ */ new Date){if(e.startedAt===null||e.endedAt===null||!e.cwd)return`empty`;if(e.endedAt<n.getTime()-il.maxAgeDays*864e5)return`old`;let r=t.home??C(),i=e.cwd,a=await up(e,i,r,t.known);if(typeof a==`string`)return a;let{place:o}=a,s=o.repository;if(await Ol(e.sessionId))return`live`;let c={sessionId:e.sessionId,agent:ip,machineId:t.machineId,machineName:t.machineName,imported:!0},l=[],u=(e,t)=>{let n=t.filter(e=>e!==null);n.length>0&&l.push({at:e,links:n})};u(e.startedAt,[Z(`repository`,s)]);for(let{branch:t,at:n}of e.branches)await Rc(i,t)||u(n,[Z(`branch`,`${s}#${t}`)]);for(let t of e.skills)t.command&&u(t.at,ml(t.command,s));for(let{command:t,stdout:n,at:r}of e.commands)u(r,hl(t,n,s));l.sort((e,t)=>e.at-t.at);let d=/* @__PURE__ */ new Set,f=[],p=(e,t,n)=>{for(let r=0;r===0||r<n.length;){let i=n.slice(r,r+il.maxLinks);f.push({...c,type:e,occurredAt:pp(t),links:i}),r+=Math.max(i.length,1)}},m=e=>e.filter(e=>{let t=kl(e);return!d.has(t)&&(d.add(t),!0)}),h=m(l.filter(t=>t.at<=e.startedAt).flatMap(e=>e.links));p(`start`,e.startedAt,h);for(let{at:t,links:n}of l){if(t<=e.startedAt)continue;let r=m(n);r.length>0&&p(`seen`,t,r)}p(`end`,e.endedAt,[]);let g=[];for(let[n,a]of e.skills.entries()){let s=await ba(a.name,ip,i,r);s&&g.push({...c,...Ic({...o,branch:dp(e,a.at)},t.known.skills[s.id]??null),id:mp(`${e.sessionId}\n${n}\n${a.at}\n${a.name}`),skillId:s.id,version:s.version,trigger:a.trigger,occurredAt:pp(a.at),sessionId:e.sessionId})}let _=await t.organizationOf({sessionId:e.sessionId,agent:ip,cwd:i,projectLock:xa(i,r),repository:s,branch:e.branches[0]?.branch??null,registeredAt:pp(e.startedAt)});if(_===`unknown`)throw Error(`Couldn't ask agent kit which organization a session's repository is. Try again in a moment.`);let v=_?{...c,organizationId:_.organizationId,occurredAt:pp(e.endedAt),usage:fp(e)}:null;return{sessionId:e.sessionId,repository:s,placedByOutput:a.byOutput,startedAt:pp(e.startedAt),events:f,activations:g,usage:v}}async function up(e,t,n,r){let i=await Fc(e.sessionId,t,n,r);if(i.audience&&i.repository)return{place:{...i,repository:i.repository},byOutput:!1};if(f(t))return`outside`;let[a,...o]=e.namedRepositories;if(!a)return xa(t,n)?`outside`:`gone`;if(o.length>0)return`several`;let s=`github.com/${a}`,c=r.repositories[s];return c?{place:{sessionId:e.sessionId,repository:s,branch:null,audience:{organizationId:c}},byOutput:!0}:`outside`}function dp(e,t){let n=null;for(let r of e.branches)r.at<=t&&(n=r.branch);return n??e.branches[0]?.branch??null}function fp(e){let t=[],n=e.runs.length>0?e.runs:[{start:e.startedAt,models:e.replies}];e.prompts>0&&t.push({metric:X.prompts,model:null,skillId:null,start:pp(n[0]?.start??e.startedAt),value:e.prompts});for(let e of n)for(let[n,r]of Object.entries(e.models))for(let[i,a]of Object.entries(r))a>0&&t.push({metric:i,model:n,skillId:null,start:pp(e.start),value:a});return t.slice(0,nl.maxEntries)}const pp=e=>new Date(e).toISOString();function mp(e){let t=he(`sha256`).update(e).digest(`hex`),n=(parseInt(t[16],16)&3|8).toString(16);return`${t.slice(0,8)}-${t.slice(8,12)}-5${t.slice(13,16)}-${n}${t.slice(17,20)}-${t.slice(20,32)}`}const hp=il.maxPerRequest;async function gp(e,t){let n=/* @__PURE__ */ new Set,r=t.sessions.flatMap(e=>e.events);for(let t=0;t<r.length;t+=hp){let i=await e.reportSessionEvents(r.slice(t,t+hp));for(let e of i.live??[])n.add(e)}let i=t.sessions.filter(e=>!n.has(e.sessionId)),a=i.flatMap(e=>e.activations);for(let t=0;t<a.length;t+=100)await e.reportActivations(a.slice(t,t+100));let o=[],s=0;for(let t of i.flatMap(e=>e.usage?[e.usage]:[])){let n=JSON.stringify(t).length;o.length>0&&(o.length>=nl.maxPerRequest||s+n>409600)&&(await e.reportSessionUsage(o),o=[],s=0),o.push(t),s+=n}return o.length>0&&await e.reportSessionUsage(o),{sent:i,live:[...n]}}async function _p({dryRun:e}){let t=await H();if(!t)throw Error("Log in first with `a-kit login`.");if(!e&&(Vn()||(await zn()).telemetry===!1))throw Error("Telemetry is off, so nothing is sent. Turn it on with `a-kit telemetry on`, or see what would be sent with `--dry-run`.");let n=z(B(),t.token),r=t.user.id,i=await ps(n,r,await us(r),/* @__PURE__ */ new Date);if(!i)throw Error(`Couldn't ask agent kit which repositories are your organizations'. Try again in a moment.`);let a=Fl(async()=>({api:n,userId:r})),o=op(),s=await cp({projectsDir:o,known:i,organizationOf:e=>a.of(e),machineId:await Sa(),machineName:ha()});if(e){for(let e of s.sessions)console.log(xp(e));console.log(`\nWould send ${vp(s.sessions.length)} from ${o}. Nothing was sent.`),yp(s.sessions),bp(s.skipped,`Would skip`),s.sessions.length>0&&console.log(`agent kit leaves a session live telemetry already sent as it is.`);return}let c=await gp({reportSessionEvents:e=>n.reportSessionEvents(e),reportActivations:e=>n.reportActivations(e),reportSessionUsage:e=>n.reportSessionUsage(e)},s);for(let e of c.sent)await Dl(e.sessionId,e.events.flatMap(e=>e.links)),e.usage&&await $l(e.usage,`sent`);F.success(`Sent ${vp(c.sent.length)} from ${o} to agent kit.`),yp(c.sent),bp({...s.skipped,...c.live.length>0&&{live:(s.skipped.live??0)+c.live.length}},`Skipped`),console.log("Claude Code keeps about 30 days of sessions. `a-kit telemetry show <session-id>` shows what was sent for one.")}const vp=e=>`${e} session${e===1?``:`s`}`;function yp(e){let t=e.filter(e=>e.placedByOutput).length;t!==0&&console.log(t===1?`1 was placed by the one repository it named itself (its pull requests, gh output or git push), its folder being gone.`:`${t} were placed by the one repository each named itself (its pull requests, gh output or git push), their folder being gone.`)}function bp(e,t){let n=Object.entries(e),r=n.reduce((e,[,t])=>e+t,0);if(r!==0){console.log(`${t} ${vp(r)}:`);for(let[e,t]of n)console.log(` ${t} ${ap[e]}`)}}function xp(e){let t=new Set(e.events.flatMap(e=>e.links.map(kl))),n=e=>[...t].filter(t=>t.startsWith(`${e} `)).length,r=e.usage?.usage.filter(e=>e.metric===X.costUsd).reduce((e,t)=>e+t.value,0),i=[`${n(`branch`)} branches`,`${n(`pull_request`)} pull requests`,`${n(`issue`)} issues`,`${e.activations.length} skills loaded`,e.usage?r?`$${r.toFixed(2)}`:`usage`:`no usage (no organization of yours is its)`];return`${e.sessionId} ${e.startedAt} ${e.repository} ${i.join(`, `)}`}const Sp={collector:`sends its OpenTelemetry to the collector`,elsewhere:"exports its telemetry elsewhere; the collector gets nothing (see `env` in ~/.claude/settings.json)",off:`doesn't send its OpenTelemetry to the collector`};async function Cp(e,t,{port:n,dryRun:r=!1}={}){switch(e){case`on`:{n!==void 0&&await uo(Number(n)),await Bn({telemetry:!0});let e=await Po();if(e.status===`skipped`){F.warn(`Couldn't add the Claude Code hook: ${e.reason}.`);return}F.success(`Telemetry is on: Claude Code reports its sessions, what they used and the skills it loads.`),e.exportsElsewhere&&F.warn("Claude Code exports its telemetry elsewhere (`env` in ~/.claude/settings.json), so the collector gets nothing.");return}case`off`:await Bn({telemetry:!1}),await Po(),await fd({send:!1}),F.success("Telemetry is off: Claude Code doesn't report its sessions or the skills it loads, and the collector stopped. Turn it back on with `a-kit telemetry on`.");return;case`show`:return Tp(t);case`import`:return _p({dryRun:r});case void 0:case`status`:{let e=await zn(),t=(await Lo()).includes(`telemetry`),n=e.telemetry===!1?`off`:Vn()?`off in this environment (DO_NOT_TRACK or AGENT_KIT_TELEMETRY)`:`on`,{port:r}=await lo(),i=await ld(),a=i===`taken`?`another user's collector has the port`:i?`running (process ${i.pid})`:`not running`;console.log(`Telemetry is ${n}.`),console.log(`Claude Code: ${t?`reports its sessions and the skills it loads`:`no hook installed`}; ${Sp[await Io()]}.`),console.log(`Collector: port ${r}, ${a}.`),console.log("\nWhen an agent loads a skill installed from agent kit, it reports the skill, its version, the agent, its session, this machine and when, so your organization sees which skills get used. It also reports when each session starts and ends. In a repo that installs skills from agent kit, it reports the repository and the branch too, the issue a skill was started for (`/implement 12`), the pull requests and issues a `gh` command opened or changed, and where the session came from (`AGENT_KIT_FROM`).\n\nClaude Code also sends its OpenTelemetry to a collector on this machine, which sends your organization what each session used: tokens and cost by model and by skill, how long you and the agent were each at work, and how many prompts, commits and pull requests it made. Only for a session in a repository of your organization's (one of its projects, or one that installs its skills); nothing of the others. Never what you or the agent wrote: no prompt, response, command or file path leaves the machine. `a-kit telemetry show` shows what was sent.\nTurn it off with `a-kit telemetry off`.");return}default:throw Error(`Unknown telemetry action "${e}". Use on, off, status, show or import.`)}}const wp={sent:`sent`,waiting:`waiting to be sent`,refused:`refused by agent kit, not sent again`};async function Tp(e){if(e){let[t,n]=await Promise.all([eu(e),El(e)]);if(!t&&n.length===0)throw Error(`Nothing was sent for session ${e}.`);console.log(n.length>0?`Its session told agent kit of:\n${n.map(e=>` ${e}`).join(`
|
|
312
|
+
`)}`:`Its session told agent kit of no repository or branch.`),console.log(t?`\nWhat it used, ${wp[t.status]} (${t.at}):\n${JSON.stringify(t.record,null,2)}`:`
|
|
313
|
+
Nothing of what it used was sent.`);return}let t=await tu();if(t.length===0)console.log(`Nothing was sent for a session yet.`);else{for(let{at:e,status:n,record:r}of t)console.log(`${r.sessionId} ${r.organizationId} ${e} ${wp[n]}`);console.log("\n`a-kit telemetry show <session-id>` shows what was sent for one.")}}async function Ep(e,t){let[n,...r]=e;if(!n)throw Error(`Name a skill and a prompt: a-kit try <skill> "<prompt>"`);let i=r.length>0?r.join(` `):await jp();if(!i.trim())throw Error(`Write the prompt after the skill, or pipe it in: a-kit try <skill> "<prompt>"`);let a=Ap(t.skillVersion),o=t.model??`claude-sonnet-5-5`,{api:s}=await no(),c=Dn(await s.listSkills(),n);if(c.length>1)throw Error(`More than one of your organizations has a skill named "${n}". Say which one: ${c.map(e=>`${e.organizationName}/${e.name}`).join(` or `)}.`);let l=c[0],u=e=>console.log(`\n${e.toUpperCase()} · ${o}\n`),d=(e,t)=>Dp(s,l.id,{model:o,version:a,withSkill:e,prompt:i},t),f=[],p=d(!1,e=>f.push(e));p.catch(()=>{});let m=!1;kp(await d(!0,e=>{m||u(`With ${Nn(l)} v${a??l.version}`),m=!0,Op(e,l.name)})),u(`Without`);let h=await p;for(let e of f)Op(e,l.name);kp(h)}async function Dp(e,t,n,r){let i=`The answer ended before it finished.`;try{await e.playground(t,{model:n.model,version:n.version,withSkill:n.withSkill,messages:[{role:`user`,content:n.prompt}]},e=>{e.type===`done`&&(i=e),e.type===`error`&&(i=e.message),r(e)})}catch(e){if(e instanceof R)throw e;i=e instanceof Error?e.message:String(e)}return i}function Op(e,t){if(e.type===`text`&&process.stdout.write(e.text),e.type===`tool`){let n=e.tool===`load_skill`?`Loaded ${e.skill}`:`Read ${e.skill}/${e.path??``}`;process.stdout.write(`${e.skill===t?`■`:`□`} ${n}\n\n`)}}function kp(e){if(typeof e==`string`){console.log(`\n\n${e}`);return}let t=mn(e.stopReason);t&&console.log(`\n\n${t}`),console.log(`\n\n${fn(e.usage)}`)}function Ap(e){if(e===void 0)return;let t=Number(e.replace(/^v/,``));if(!Number.isInteger(t)||t<1)throw Error(`"${e}" isn't a version number, like 3.`);return t}async function jp(){if(process.stdin.isTTY)return``;let e=``;for await(let t of process.stdin)e+=t;return e}const Mp=`a-kit ${nn}: your agent kit skills, in your agents.
|
|
314
314
|
|
|
315
315
|
Usage
|
|
316
316
|
a-kit init Log in and pick skills to install
|
|
@@ -373,4 +373,4 @@ Report options (the report-session-issue skill passes them for you)
|
|
|
373
373
|
--org <id|name> The organization, when it can't tell
|
|
374
374
|
--full-outputs Keep tool outputs whole (they're cut to 2,000 characters)
|
|
375
375
|
--dry-run Scrub and show what would be sent, without sending
|
|
376
|
-
`;async function
|
|
376
|
+
`;async function Np(){let e=t({allowPositionals:!0,strict:!1}).positionals[0];if(e&&Rd.has(e))return zd(e);let{values:n,positionals:r}=t({allowPositionals:!0,options:{global:{type:`boolean`,short:`g`,default:!1},agent:{type:`string`,short:`a`,multiple:!0,default:[]},yes:{type:`boolean`,short:`y`,default:!1},channel:{type:`string`,default:`latest`},help:{type:`boolean`,short:`h`,default:!1},version:{type:`boolean`,short:`v`,default:!1},session:{type:`string`},title:{type:`string`},note:{type:`string`},expected:{type:`string`},map:{type:`string`},org:{type:`string`},"full-outputs":{type:`boolean`,default:!1},"dry-run":{type:`boolean`,default:!1},model:{type:`string`},"skill-version":{type:`string`},token:{type:`boolean`,default:!1},api:{type:`string`},port:{type:`string`}}});if(n.version)return console.log(nn);let[i,...a]=r;if(n.help||!i)return console.log(Mp);if(!en(n.channel))throw Error(`Unknown channel "${n.channel}". Use one of: ${Qt.join(`, `)}.`);let o={global:n.global,agent:n.agent.flatMap(e=>e.split(`,`)).filter(Boolean),yes:n.yes,channel:n.channel};switch(i){case`init`:return ad(o);case`add`:case`install`:return qo(a,o);case`update`:return hs(o);case`list`:case`ls`:return wd();case`search`:if(a.length===0)throw Error("What should it look for? Like `a-kit search pdf`.");return Rf(a);case`health`:return id(a);case`check`:return tl(a);case`link`:return vd(a,o);case`login`:return n.token?Nd():Md();case`logout`:return Id();case`whoami`:return Ld();case`try`:return Ep(a,{model:n.model,skillVersion:n[`skill-version`]});case`report`:return kf({...o,session:n.session,title:n.title,note:n.note,expected:n.expected,map:n.map,org:n.org,fullOutputs:n[`full-outputs`],dryRun:n[`dry-run`]});case`telemetry`:return Cp(a[0],a[1],{port:n.port,dryRun:n[`dry-run`]});case`auto-update`:return vs(a[0]);case`heartbeat`:return od(a[0],n.api);case`org`:return jd(a[0],a.slice(1).join(` `)||n.org);case`machine`:return kd(a[0],a.length>1?a.slice(1).join(` `):void 0);case`hook`:return md(a[0],n.api,a[1]);case`collector`:return _u(n.api);default:throw Error(`Unknown command "${i}". Run \`a-kit --help\`.`)}}Np().catch(e=>{let t=e instanceof Error?e.message:String(e);F.error(t),process.exitCode=1});export{};
|