@staff0rd/assist 0.828.0 → 0.829.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.
@@ -196,7 +196,7 @@ The reviewer left ${i.length} comment${i.length===1?"":"s"} on the preview. Addr
196
196
  `)},r)})}async function Eb(e,t,r={}){console.log("Awaiting your approval in the assist web UI preview pane\u2026");let i;try{i=await Cb(t)}catch(n){console.error(`Error: ${n instanceof Error?n.message:String(n)}`),process.exit(1)}return i.body!==void 0&&r.saveEditedBody?.(i.body),i.decision==="reject"&&!r.rejectIsOutcome&&Sb(e,i,r.rejectionAdvice),i}async function Tb(e,t,r){let i=process.env.ASSIST_SESSION_ID;process.env.ASSIST_SESSION!=="1"||!i||await Eb("PR comment preview",{sessionId:i,requestId:CC(),title:e,body:t,prNumber:r,kind:"pr-comment"})}function EC(e){let t=e.toLowerCase();(t.includes("claude")||t.includes("opus"))&&(console.error('Error: Body must not contain "claude" or "opus"'),process.exit(1))}function Nb(e){(!Number.isInteger(e)||e<1)&&(console.error("Error: Line must be a positive integer"),process.exit(1))}async function Rb(e,t,r,i={}){let{startLine:n,skipPreview:o}=i;EC(r),Nb(t),n!==void 0&&Nb(n);let s=n!==void 0?`${n}-${t}`:`${t}`;o||await Tb(`Comment on ${e}:${s}`,r,null);try{let a=Li();xb({prId:a,body:r,path:e,line:t,startLine:n}),console.log(`Added review comment on ${e}:${s}`)}catch(a){throw ji(a)&&(console.error("Error: GitHub CLI (gh) is not installed."),console.error("Install it from https://cli.github.com/"),process.exit(1)),a}}var Ab="the reviewer";function sr(e){return e.replace(/\bclaude\b/gi,Ab).replace(/\bopus\b/gi,Ab)}function TC(e){let t=[],r=e.severity??"finding";return t.push(`**${r}: ${e.title}**`),e.impact&&t.push("",`Impact: ${e.impact}`),e.recommendation&&t.push("",`Recommendation: ${e.recommendation}`),sr(t.join(`
197
197
  `))}async function zb(e){let t=0,r=0;for(let i of e){let n=TC(i);try{await Rb(i.file,i.line,n,{startLine:i.startLine,skipPreview:!0}),t++}catch(o){r++;let s=o instanceof Error?o.message:String(o);console.error(`Failed to post comment on ${i.file}:${i.line}: ${s}`)}}return{posted:t,failed:r}}function ro(e,t){try{let r=Li();fn(e,{prId:r,body:t}),console.log("Submitted review.")}catch(r){if(ji(r)){console.error("Error: GitHub CLI (gh) is not installed.");return}let i=r instanceof Error?r.message:String(r);console.error(`Failed to submit review: ${i}`)}}var NC="mutation($prId: ID!, $body: String) { addPullRequestReview(input: { pullRequestId: $prId, event: COMMENT, body: $body }) { pullRequestReview { id } } }";function no(e){ro(NC,e)}var RC="mutation($prId: ID!, $body: String) { submitPullRequestReview(input: { pullRequestId: $prId, event: COMMENT, body: $body }) { pullRequestReview { id } } }";function Db(e){ro(RC,e)}function io(e,t){return t?`${e}
198
198
 
199
- ${t}`:e}function jb(e,t,r){return io(sr(Qe(e,t)),r)}function AC(e,t){t>0?Db(e):no(e)}async function zC(e){if(!e.prompt)return e.submit;await $c("waiting");try{return await or("Submit the pending review?",e.submit)}finally{await $c("running")}}async function Lb(e,t,r,i){let n=await zb(e),o=n.failed>0?`, ${n.failed} failed`:"";console.log(`Posted ${n.posted} comment(s)${o}.`);let s=Yt(t);return n.posted===0&&s.length===0?{posted:0,submitted:!1}:await zC(i)?(AC(jb(r,t,i.ciFooter),n.posted),{posted:n.posted,submitted:!0}):(console.log("Leaving the review unsubmitted."),{posted:n.posted,submitted:!1})}function DC(){try{return Ui()}catch(e){return console.error(`Error: could not confirm which PR this tree is on: ${e instanceof Error?e.message:String(e)}`),null}}function Ub(e){let t=DC();return t===e?!0:(console.error(`Error: this tree is now on ${t===null?"a branch with no open PR":`PR #${t}`}, not the reviewed PR #${e}; skipping the post and any chained sessions.`),!1)}function Mb(e,t){let r=sr(`${Qe(e)}
199
+ ${t}`:e}function jb(e,t,r){return io(sr(Qe(e,t)),r)}function AC(e,t){t>0?Db(e):no(e)}async function zC(e){if(!e.prompt)return e.submit;await $c("waiting");try{return await or("Submit the pending review?",e.submit)}finally{await $c("running")}}async function Lb(e,t,r,i){let n=await zb(e),o=n.failed>0?`, ${n.failed} failed`:"";console.log(`Posted ${n.posted} comment(s)${o}.`);let s=Yt(t);return n.posted===0&&s.length===0&&!i.ciFooter?{posted:0,submitted:!1}:await zC(i)?(AC(jb(r,t,i.ciFooter),n.posted),{posted:n.posted,submitted:!0}):(console.log("Leaving the review unsubmitted."),{posted:n.posted,submitted:!1})}function DC(){try{return Ui()}catch(e){return console.error(`Error: could not confirm which PR this tree is on: ${e instanceof Error?e.message:String(e)}`),null}}function Ub(e){let t=DC();return t===e?!0:(console.error(`Error: this tree is now on ${t===null?"a branch with no open PR":`PR #${t}`}, not the reviewed PR #${e}; skipping the post and any chained sessions.`),!1)}function Mb(e,t){let r=sr(`${Qe(e)}
200
200
 
201
201
  No findings were raised.`);no(io(r,t))}function Fb(e,t){let r=[];return e>0&&r.push(`${e} line comment(s)`),t>0&&r.push(`${t} finding(s) in the review body`),r.join(" and ")}var qb={posted:0,submitted:!1};async function LC(e,t,r){return r.prompt?or(`Post ${t} to PR #${e}?`,!1):!0}async function UC(e,t,r){let i=jC(t,"utf8"),{inDiff:n,unanchored:o}=Zi(i,e),s=Yt(o);if(n.length===0&&s.length===0)return r.ciFooter?(Mb(i,r.ciFooter),{posted:0,submitted:!0}):qb;let a=Fb(n.length,s.length);return console.log(`Found PR #${e.prNumber} with ${a} to post.`),await LC(e.prNumber,a,r)?Lb(n,o,i,r):(console.log("Skipped posting."),qb)}async function Zb(e,t,r){if(!Ub(t.prNumber))return;let i=await UC(t,e,r);await mb(t.prNumber,i,r)}import{mkdirSync as MC,writeFileSync as FC}from"node:fs";import{dirname as qC}from"node:path";var Sc="assist sessions set-status";function xc(e){return`${Sc} running --source ${e}`}function ZC(e){return`${Sc} waiting --source ${e}`}function _c(e){return`${Sc} waiting --source ${e} --ack`}function Rt(e,t){let r=[{type:"command",command:e}];return[t==null?{hooks:r}:{matcher:t,hooks:r}]}var Bb="AskUserQuestion",BC=`^(?!${Bb}$).*`,VC={hooks:{UserPromptSubmit:Rt(xc("prompt")),PreToolUse:[...Rt(ZC("pretool"),Bb),...Rt(xc("pretool"),BC)],PostToolUse:Rt(xc("posttool")),Stop:Rt(_c("stop")),Notification:Rt(_c("notification")),PermissionRequest:Rt(_c("permission"))}};function Vb(){let e=er.hooksSettings;return MC(qC(e),{recursive:!0}),FC(e,JSON.stringify(VC,null,2)),e}import{spawn as KC}from"node:child_process";function Kb(e,t,r={}){let{ASSIST_ACTIVITY_ID:i,CLAUDE_CODE_CHILD_SESSION:n,...o}=process.env,s=KC(e,t,{stdio:"inherit",env:{...o,...r.env},cwd:r.cwd}),a=new Promise((l,c)=>{s.on("close",u=>l(u??0)),s.on("error",c)});return{child:s,done:a}}function ar(e,t={}){let r=["--settings",Vb(),...GC(e,t)],i=t.permissionMode??(t.allowEdits?"auto":void 0);return i&&r.push("--permission-mode",i),Kb("claude",r)}function GC(e,t){return t.resumeSessionId?e?["--resume",t.resumeSessionId,e]:["--resume",t.resumeSessionId]:t.sessionId?e?["--session-id",t.sessionId,e]:["--session-id",t.sessionId]:e?[e]:[]}function JC(e){return`You are helping the user apply fixes for a code review with each finding decided one at a time.
202
202
 
@@ -0,0 +1 @@
1
+ "use strict";(()=>{function o(s){let{type:t,url:n}=s??{};return t==="assist-send"&&typeof n=="string"}function r(){return globalThis.browser?.runtime}async function a(s,{url:t,instructions:n}){let e;try{e=await fetch(`${s}/api/sessions/from-github`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t,instructions:n})})}catch{return{ok:!1,message:`assist web server unreachable at ${s}`}}let i=await e.json().catch(()=>({}));return e.ok?{ok:!0,message:`assist session started in ${i.cwd}`}:{ok:!1,message:i.error??`assist web server returned ${e.status}`}}var u="http://localhost:3100";function d(){r()?.onMessage.addListener(s=>{if(o(s))return a(u,s)})}d();})();