agent-afk 3.81.1 → 3.82.0
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: gather
|
|
3
3
|
description: "Parallel context-gathering for a code area. Use when you need to understand a module, feature, or subsystem and would otherwise read 3+ files sequentially — dispatches two agents in parallel to map structure and test coverage in one wave."
|
|
4
|
+
context: load
|
|
4
5
|
---
|
|
5
6
|
|
|
6
7
|
## Dispatch protocol
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: parallelize
|
|
3
3
|
description: "When finished creating the plan in plan mode, run /parallelize so Claude dispatches one planning agent to transform the current approach into a plan to orchestrate waves of parallel sub-agents."
|
|
4
|
+
context: load
|
|
4
5
|
---
|
|
5
6
|
|
|
6
7
|
## Sub-agent contract
|
package/dist/cli.mjs
CHANGED
|
@@ -1877,7 +1877,7 @@ ${E}`})}return{fileBlocks:a,warnings:l}}async function aE(e,t,n,r,o="summary",s,
|
|
|
1877
1877
|
`))!==-1;){let u=n.slice(0,c);n=n.slice(c+1),this.opts.writeLine(u)}},s={command:t,mode:"foreground",onChunk:c=>{r||(n+=c.toString("utf8"),o())}},i=this.opts.getCwd();i!==void 0&&(s.cwd=i);let{job:a,handle:l}=this.registry.start(s);this.activeFgJobId=a.id;try{let c=await l.promise;r=!0,n.length>0&&(this.opts.writeLine(n),n=""),this.opts.writeLine(KW(a,c)),this.queueInjection({command:t,mode:"foreground",result:c})}finally{this.activeFgJobId=null}}startBackground(t){let n={command:t,mode:"background"},r=this.opts.getCwd();r!==void 0&&(n.cwd=r);let{job:o}=this.registry.start(n);this.opts.writeLine(m.dim(` [${o.id}] background: `)+t)}queueInjection(t){this.pendingInjections.push(t),this.pendingInjections.length>e.MAX_PENDING_INJECTIONS&&this.pendingInjections.shift()}};function zW(e,t){if(e!==void 0){let n=e.toLowerCase();return!(n==="0"||n==="false"||n==="off"||n==="no")}return typeof t=="boolean"?t:!0}async function qW(e,t){if(e.firstTurnHook&&e.stats.totalTurns===0){let n=e.firstTurnHook;e.firstTurnHook=void 0;try{await n(t)}catch(r){e.completionWriter.fn(m.warning("\u26A0 ")+"first-turn hook failed: "+(r instanceof Error?r.message:String(r)))}}}function Lc(e,t){let n=m.brand("afk")+m.dim(` (${e})`),r=t?m.warning(" \u25CF plan"):"";return n+r+m.dim(" \u203A ")}async function gE(e,t,n,r){let o=null,s=[];e.session.current.waitForInitialization().then(async S=>{Ue()&&(o=gl(S)),await lc(e.session.current),Ue()&&(s=sx())}).catch(()=>{});let i=await Yx(),a=new Oc({rl:e.rl,history:i,statusLine:e.statusLine}),l,c,u,d,p,f,g,h=!1,b=!1,y=gv({onError:S=>Y("[afk suggest] Tier-2 completion failed:",S)}),w=zW(T.AFK_SUGGEST_GHOST,e.suggestGhostConfig);try{await a.armCompositor({promptFn:()=>Lc(e.stats.model,e.stats.planMode),onCancel:r,onShiftTab:()=>{let C=e.slashCtx;C.stats.planMode&&C.stats.pendingPlanExit?(C.stats.pendingPlanExit=!1,Et(C,!1,{closureSummarySkipped:!0}).catch(()=>{})):Et(C).catch(()=>{}),e.statusLine.rearm()},scrollRegion:e.statusLine,...e.preArmAnchorRow!==void 0?{anchorRow:e.preArmAnchorRow}:{},...w?{suggest:{engine:y,getContext:()=>({model:e.stats.model,apiKey:e.suggestApiKey,baseUrl:e.suggestBaseUrl,cwd:e.stats.cwd??process.cwd(),getHistory:()=>{let C=a.history;return C.getEntries?[...C.getEntries()]:[]},getDropdownTopCandidate:C=>{let D=a.autocompleteState.candidates[0];return D&&D.value.startsWith(C)&&D.value.length>C.length?D.value:null},getTranscriptTail:()=>"",getRecentCommands:()=>[],llmEnabled:()=>/^(1|true|yes|on)$/i.test(T.AFK_SUGGEST_ENABLED??"")})}}:{}});let S=a.getCompositor();Ft.install(dl({readLine:C=>a.readLine({promptFn:()=>C}).then(L=>L.text),writer:{line:(C="")=>{let L=a.getCompositor();L?L.commitAbove(C):process.stdout.write(C+`
|
|
1878
1878
|
`)}},pendingCount:()=>Ft.pendingCount(),...S?{pickFromList:C=>eE(S,C),readTextOverlay:C=>tE(S,C)}:{}})),e.replRenderer.setCompositor(a.getCompositor()),e.slashCtx.getCompositor=()=>a.getCompositor();let E=a.getCompositor();if(E){let C=L=>E.commitAbove(L);e.completionWriter.fn=C,e.completionWriter.idleFn=C}e.slashCtx.setSoftStopHandler=C=>a.setSoftStopHandler(C),e.inputSurfaceRef&&(e.inputSurfaceRef.current=a),c=lE(),g=cE(),e.clearVerdictLedger=()=>g?.reset(),u=new vl,Ik(u),Bk(u),Hk(u),Uk(e.backgroundRegistry);let k=0,R=0,_=1,A=()=>e.statusLine.setExtraRows(_+k+R);g.setRowCountChangeHandler(C=>{R=C,A(),d?.redraw(),p?.redraw()}),d=new $c(u,e.backgroundRegistry,{getAdjacentRows:()=>R}),d.setRowCountChangeHandler(C=>{k=C,A()}),p=new Gl({getExtraRows:()=>e.statusLine.getExtraRows()}),p.setRowCountChangeHandler(C=>{A()}),e.statusLine.setAfterScrollRestore(()=>{g?.repaint(),d?.redraw(),p?.redraw()}),d.start(),p.start(),g.start({stream:process.stdout});let P=50,I=[];for(u.on("complete",C=>{I.length>=P&&I.shift(),I.push(C)}),f=new Dc({writeLine:C=>e.replRenderer.writeLine(C),getCwd:()=>e.stats.cwd}),Fk(f),n.tryAbortShellForeground=()=>f.abortActiveForeground();;){if(o&&(e.replRenderer.writeLine(o),e.replRenderer.writeLine(""),o=null),s.length>0){for(let x of s)e.replRenderer.writeLine(x);e.replRenderer.writeLine(""),s=[]}for(;I.length>0;){let x=I.shift(),O=x.status==="succeeded"?"\u2713":"\u2717",B=[];if(x.resultText){let H=x.resultText.trim().split(`
|
|
1879
1879
|
`)[0]?.slice(0,80)??"";H&&B.push(H)}x.error&&B.push(x.error.message);let J=[x.stats.toolUses>0?`${x.stats.toolUses} tools`:"",x.stats.tokens>0?`${Math.round(x.stats.tokens/1e3)}k tok`:"",x.stats.durationMs>0?`${Math.round(x.stats.durationMs/1e3)}s`:""].filter(Boolean).join(" \xB7 ");J&&B.push(J),e.replRenderer.writeLine(xn({kind:x.status==="succeeded"?"checkpoint":"diagnosis",title:`${O} ${x.id} ${x.label}`,body:B})),e.replRenderer.writeLine("")}let C=f.drainNotifications();for(let{job:x,result:O}of C){let B=O.errorReason===void 0?"\u2713":"\u2717",J=O.errorReason==="abort"?"killed":O.errorReason==="timeout"?"timed out":O.errorReason==="signal-killed"?"killed by signal":`exit ${O.exitCode??0}`,H=Math.max(0,Math.round(O.durationMs/100)/10);e.replRenderer.writeLine(m.dim(` ${B} [${x.id}] ${J} \xB7 ${H}s \xB7 `)+x.command)}let L=c.renderIfChanged(e.stats.sessionId);if(L.length>0){for(let x of L)e.replRenderer.writeLine(x);e.replRenderer.writeLine("")}let D,j;if(l!==void 0){let x=l;l=void 0;let O=Lc(e.stats.model,e.stats.planMode),B=br({buffer:x.text,promptText:O,isTTY:!!process.stdout.isTTY,attachmentSummary:Bo([...x.attachments])});e.replRenderer.writeLine(B),D=x.text.trim(),j=x.attachments}else{let x=await a.readLine({promptFn:()=>Lc(e.stats.model,e.stats.planMode),onSigint:r,onShiftTab:()=>{let O=e.slashCtx;O.stats.planMode&&O.stats.pendingPlanExit?(O.stats.pendingPlanExit=!1,Et(O,!1,{closureSummarySkipped:!0}).catch(()=>{})):Et(O).catch(()=>{}),e.statusLine.rearm()}});D=x.text.trim(),j=x.attachments}if(!D&&j.length===0)continue;if(D.startsWith("!")){let x=/^(0|false|off|no)$/i.test(T.AFK_SHELL_PASSTHROUGH??"");if(e.options.shellPassthrough!==!1&&!x&&(h||(h=!0,e.replRenderer.writeLine(m.dim(" \u2139 ! prefix shells out. Pass --no-shell-passthrough (or set AFK_SHELL_PASSTHROUGH=0) to send ! text to the model instead."))),await f.dispatch(D))){e.statusLine.rearm();continue}}let N=!1;if(D.startsWith("/")){let x=await GS(D,e.slashCtx,j);if(x.handled){if(x.result==="exit"){e.rl.close();return}if((D==="/clear"||D.startsWith("/clear "))&&(await t.rotateOnClear(),e.replRenderer.writeLine(m.dim(` transcript: ${t.path()}`)),g.reset()),x.result!==null&&typeof x.result=="object"&&"kind"in x.result&&x.result.kind==="submit"){l={text:x.result.message,attachments:j??[]},e.statusLine.rearm();continue}e.statusLine.rearm();continue}N=!0}i.push(D),await qW(e,D);let W=D;if(N){let x=mp(D);if(x){let O=x.name.replace(/^\//,"").split(":").pop()??"";if(O&&gm(O)){let B={skillName:O,rawArgs:x.args,source:"plugin",capabilities:{compose:!0,subagents:!0}},J=e.session.current.sessionId,H=Cr(J),F=Date.now();Y(`[afk trace] preflight.start commandName=${O}`);let V=!1,ye=await Ar(B,{cwd:e.stats.cwd??process.cwd(),artifactDir:H},Ne=>{Ue()&&e.replRenderer.writeLine(m.warning(`\u26A0 preflight(${O}) failed: `)+(Ne instanceof Error?Ne.message:String(Ne)))});V=ye!==null,Y(`[afk trace] preflight.end commandName=${O} durationMs=${Date.now()-F} success=${V}`),W=bm(ye?.manifestBlock,D)}}}let M=f.drainInjections();M.length>0&&(W=M+W),await aE({text:W,attachments:j},e.session.current,e.stats,{setInFlight(x){n.turnInFlight=x},async onTurnComplete(x,O){if(await t.appendTurn(x,O),e.stats.sessionId)try{Ht(e.stats)}catch(B){b||(b=!0,e.replRenderer.writeLine(m.warning("\u26A0 ")+"session autosave failed \u2014 this conversation may not be resumable: "+(B instanceof Error?B.message:String(B))))}},async onAfterTurn(){await e.contextSampler.onTurn(e.stats.totalTurns),await sk(e.slashCtx),e.statusLine.rearm(),p?.repaint("observing")},rearmStatus:()=>e.statusLine.rearm(),onTerminalState:x=>g?.push(x),setActiveCompositor:x=>{n.activeCompositor=x},setInterruptNotifier:x=>{n.notifyInterrupting=x},scrollRegion:e.statusLine,getCompositor:()=>a.getCompositor(),setBackgroundHandler:x=>a.setBackgroundHandler(x),setSoftStopHandler:x=>a.setSoftStopHandler(x),async onContextProgress(){await e.contextSampler.refresh(),e.statusLine.repaint(yr(e.stats,e.contextSampler))},...p?{onStageChange:x=>p.repaint(x)}:{}},e.options.thinkingUi,e.completionWriter,u,a.toRunTurnRefs(Lc(e.stats.model,e.stats.planMode)))}}finally{if(u!==void 0)for(let E of u.running())u.cancel(E.id);n.tryAbortShellForeground=null,f?.drainOnExit(),p?.stop(),d?.stop(),g?.stop(),c?.dispose();let S=E=>console.log(E);e.completionWriter.fn=S,e.completionWriter.idleFn=S,await a.dispose(),e.inputSurfaceRef&&(e.inputSurfaceRef.current=null)}}import{execFile as JW}from"node:child_process";import{dirname as YW,isAbsolute as VW,resolve as XW}from"node:path";import{promisify as ZW}from"node:util";var hE=ZW(JW),QW=3e3,eK=new Set(["empty","orphaned-dir","orphaned-registration","dead-owner"]);async function tK(){let t=(await hE("git",["rev-parse","--git-common-dir"])).stdout.trim();if(!t)throw new Error("Not in a git repository.");let n=VW(t)?t:XW(process.cwd(),t);return YW(n)}async function yE(e){if(e?.disabled)return{ran:!1,removedCount:0,skippedReason:"disabled"};let t;try{t=await tK()}catch{return{ran:!1,removedCount:0,skippedReason:"not-in-repo"}}let n,r=new Promise(o=>{n=setTimeout(()=>o("timeout"),QW)});try{let o=zt({execFile:hE,repoRoot:t,dryRun:!1,scope:"interactive",bypassSoftLaunch:!0}),s=await Promise.race([o,r]);if(s==="timeout")return{ran:!1,removedCount:0,skippedReason:"timeout"};let i=s;return i.warnings.some(c=>c.toLowerCase().includes("contested"))?{ran:!1,removedCount:0,skippedReason:"lock-contested"}:{ran:!0,removedCount:i.candidates.filter(c=>eK.has(c.verdict)&&i.removed.includes(c.path)).length}}catch{return{ran:!1,removedCount:0,skippedReason:"error"}}finally{n&&clearTimeout(n)}}import{promises as nK}from"node:fs";import{dirname as rK,join as SE}from"node:path";import{randomBytes as oK}from"node:crypto";var sK=["Generate a 2-4 word kebab-case slug describing this work request.","Rules:","- ASCII lowercase letters and digits only, separated by single hyphens","- 2 to 4 hyphen-separated words","- Maximum 30 characters total","- No prefix, no quotes, no punctuation other than hyphens","- Output ONLY the slug \u2014 no explanation, no preamble","Examples: fix-cleanup-race, add-telegram-allowlist, refactor-prompt-loader, debug-flaky-test"].join(`
|
|
1880
|
-
`),bE=/^[a-z0-9]+(-[a-z0-9]+){1,3}$/,Wm=30,iK=1024,aK=8e3,lK="haiku";async function cK(e,t){let n=e.trim();if(n.length===0)return t.onSkip?.("empty-message"),null;if(n.startsWith("/"))return t.onSkip?.("slash-command"),null;let r=mK(n,iK),o=new AbortController,s=setTimeout(()=>o.abort(),t.timeoutMs??aK),i=t.signal?fK([t.signal,o.signal]):o.signal,a;try{t.slugGenerator?a=await t.slugGenerator(r,i):a=await Zr({token:t.token,model:t.model??lK,system:sK,user:r,maxTokens:32,signal:i})}catch(d){let p=d instanceof Error?d.message:String(d);return t.onSkip?.("slug-generator-error",p.slice(0,200)),null}finally{clearTimeout(s)}let l=uK(a);if(l===null)return t.onSkip?.("invalid-slug-output",a.slice(0,60)),null;let c=rK(t.worktreePath);return await dK(l,c)}function uK(e){let t=e.trim().toLowerCase();if(t.length===0)return null;if(bE.test(t)&&t.length<=Wm)return t;let n=t.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(n.length===0)return null;let r=n.split("-").filter(s=>s.length>0).slice(0,4);if(r.length<2)return null;let o=r[0];for(let s=1;s<r.length;s++){let i=`${o}-${r[s]}`;if(i.length>Wm)break;o=i}return bE.test(o)?o:null}async function dK(e,t){if(!await pK(SE(t,e)))return e;let n=oK(2).toString("hex");return`${e.split("-").slice(0,3).join("-").slice(0,Wm-5)}-${n}`}async function pK(e){try{return await nK.access(e),!0}catch{return!1}}function mK(e,t){let n=Buffer.from(e,"utf8");if(n.length<=t)return e;let r=t;for(;r>0&&n[r]!==void 0&&(n[r]&192)===128;)r--;return n.slice(0,r).toString("utf8")}function fK(e){let t=AbortSignal.any;if(typeof t=="function")return t.call(AbortSignal,e);let n=new AbortController;for(let r of e){if(r.aborted)return n.abort(r.reason),n.signal;r.addEventListener("abort",()=>n.abort(r.reason),{once:!0})}return n.signal}async function kE(e){let t,n,r=SE(e.deferred.repoRoot,".afk-worktrees","unnamed"),o=await cK(e.message,{token:e.token,...e.model!==void 0?{model:e.model}:{},...e.timeoutMs!==void 0?{timeoutMs:e.timeoutMs}:{},worktreePath:r,...e.signal!==void 0?{signal:e.signal}:{},...e.slugGenerator!==void 0?{slugGenerator:e.slugGenerator}:{},onSkip:(a,l)=>{t=a,n=l}}),s=t??"unknown",i=n;if(o!==null){let l=`${Ba(e.branchPrefix)}${o}`;try{let c=await e.deferred.create(l);return wE(e.session,c.path),{status:"created",path:c.path,branch:c.branch,slug:o}}catch(c){s="create-failed",i=(c instanceof Error?c.message:String(c)).slice(0,200)}}try{let a=await e.deferred.create(!0);return wE(e.session,a.path),{status:"created-fallback",path:a.path,branch:a.branch,reason:s,...i!==void 0?{detail:i}:{}}}catch(a){return{status:"failed",reason:a instanceof Error?a.message:String(a)}}}function wE(e,t){e&&e.setCwd(t),gK(t)}function gK(e){try{process.chdir(e)}catch{}}K();import{spawn as vE}from"child_process";import{existsSync as SK,mkdirSync as kK,readFileSync as TE,unlinkSync as vK,writeFileSync as TK}from"fs";import{get as xK}from"https";import{join as xE}from"path";import{readFileSync as hK}from"fs";import{dirname as yK,join as bK}from"path";import{fileURLToPath as wK}from"url";function yn(){try{return"3.
|
|
1880
|
+
`),bE=/^[a-z0-9]+(-[a-z0-9]+){1,3}$/,Wm=30,iK=1024,aK=8e3,lK="haiku";async function cK(e,t){let n=e.trim();if(n.length===0)return t.onSkip?.("empty-message"),null;if(n.startsWith("/"))return t.onSkip?.("slash-command"),null;let r=mK(n,iK),o=new AbortController,s=setTimeout(()=>o.abort(),t.timeoutMs??aK),i=t.signal?fK([t.signal,o.signal]):o.signal,a;try{t.slugGenerator?a=await t.slugGenerator(r,i):a=await Zr({token:t.token,model:t.model??lK,system:sK,user:r,maxTokens:32,signal:i})}catch(d){let p=d instanceof Error?d.message:String(d);return t.onSkip?.("slug-generator-error",p.slice(0,200)),null}finally{clearTimeout(s)}let l=uK(a);if(l===null)return t.onSkip?.("invalid-slug-output",a.slice(0,60)),null;let c=rK(t.worktreePath);return await dK(l,c)}function uK(e){let t=e.trim().toLowerCase();if(t.length===0)return null;if(bE.test(t)&&t.length<=Wm)return t;let n=t.replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");if(n.length===0)return null;let r=n.split("-").filter(s=>s.length>0).slice(0,4);if(r.length<2)return null;let o=r[0];for(let s=1;s<r.length;s++){let i=`${o}-${r[s]}`;if(i.length>Wm)break;o=i}return bE.test(o)?o:null}async function dK(e,t){if(!await pK(SE(t,e)))return e;let n=oK(2).toString("hex");return`${e.split("-").slice(0,3).join("-").slice(0,Wm-5)}-${n}`}async function pK(e){try{return await nK.access(e),!0}catch{return!1}}function mK(e,t){let n=Buffer.from(e,"utf8");if(n.length<=t)return e;let r=t;for(;r>0&&n[r]!==void 0&&(n[r]&192)===128;)r--;return n.slice(0,r).toString("utf8")}function fK(e){let t=AbortSignal.any;if(typeof t=="function")return t.call(AbortSignal,e);let n=new AbortController;for(let r of e){if(r.aborted)return n.abort(r.reason),n.signal;r.addEventListener("abort",()=>n.abort(r.reason),{once:!0})}return n.signal}async function kE(e){let t,n,r=SE(e.deferred.repoRoot,".afk-worktrees","unnamed"),o=await cK(e.message,{token:e.token,...e.model!==void 0?{model:e.model}:{},...e.timeoutMs!==void 0?{timeoutMs:e.timeoutMs}:{},worktreePath:r,...e.signal!==void 0?{signal:e.signal}:{},...e.slugGenerator!==void 0?{slugGenerator:e.slugGenerator}:{},onSkip:(a,l)=>{t=a,n=l}}),s=t??"unknown",i=n;if(o!==null){let l=`${Ba(e.branchPrefix)}${o}`;try{let c=await e.deferred.create(l);return wE(e.session,c.path),{status:"created",path:c.path,branch:c.branch,slug:o}}catch(c){s="create-failed",i=(c instanceof Error?c.message:String(c)).slice(0,200)}}try{let a=await e.deferred.create(!0);return wE(e.session,a.path),{status:"created-fallback",path:a.path,branch:a.branch,reason:s,...i!==void 0?{detail:i}:{}}}catch(a){return{status:"failed",reason:a instanceof Error?a.message:String(a)}}}function wE(e,t){e&&e.setCwd(t),gK(t)}function gK(e){try{process.chdir(e)}catch{}}K();import{spawn as vE}from"child_process";import{existsSync as SK,mkdirSync as kK,readFileSync as TE,unlinkSync as vK,writeFileSync as TK}from"fs";import{get as xK}from"https";import{join as xE}from"path";import{readFileSync as hK}from"fs";import{dirname as yK,join as bK}from"path";import{fileURLToPath as wK}from"url";function yn(){try{return"3.82.0"}catch{}try{let e=yK(wK(import.meta.url));for(let t of["../../package.json","../package.json"])try{let n=JSON.parse(hK(bK(e,t),"utf-8"));if(typeof n.version=="string")return n.version}catch{}}catch{}return"0.0.0-unknown"}z();var EK=64*1024,RK=1440*60*1e3,AK="update-check.json",CK="pending-update.json";function EE(){return xE(Hi(),AK)}function Km(){return xE(Hi(),CK)}function RE(){let e=Hi();SK(e)||kK(e,{recursive:!0})}function _K(e,t){let n=e.split(".").map(Number),r=t.split(".").map(Number),o=Math.max(n.length,r.length);for(let s=0;s<o;s++){let i=n[s]??0,a=r[s]??0;if(a>i)return!0;if(a<i)return!1}return!1}function IK(){try{let e=TE(EE(),"utf-8"),t=JSON.parse(e);if(typeof t.latestVersion=="string"&&typeof t.checkedAt=="number")return t}catch{}return null}function PK(){try{RE();let e=`
|
|
1881
1881
|
const https = require('https');
|
|
1882
1882
|
const fs = require('fs');
|
|
1883
1883
|
const url = 'https://registry.npmjs.org/agent-afk/latest';
|