@staff0rd/assist 0.812.1 → 0.814.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.
- package/claude/skills/review-ci/scripts/review.mjs +1 -1
- package/dist/commands/sessions/web/bundle.js +470 -434
- package/dist/index.js +178 -78
- package/package.json +1 -1
|
@@ -192,7 +192,7 @@ ${i}
|
|
|
192
192
|
Comment: ${t.note}
|
|
193
193
|
`})}function $b(e,t,r){console.error(`${e} rejected${t.reason?`: ${t.reason}`:"."}`);let i=t.comments??[];if(i.length>0){console.error(`
|
|
194
194
|
The reviewer left ${i.length} comment${i.length===1?"":"s"} on the preview. Address each one, then re-run this command:
|
|
195
|
-
`);for(let n of wb(i))console.error(n)}r&&console.error(r),process.exit(1)}function xb(e){if(Array.isArray(e))return e.flatMap(t=>{let{path:r,alt:i,group:n}=t??{};if(typeof r!="string"||r==="")return[];let o={path:r,alt:typeof i=="string"?i:""};return[typeof n=="string"&&n!==""?{...o,group:n}:o]})}function _b(e){if(Array.isArray(e))return e.flatMap(t=>{let{id:r,ticked:i,comment:n,notes:o}=t??{};if(typeof r!="string")return[];let s=$C(o);return[{id:r,ticked:i===!0,...typeof n=="string"&&n!==""?{comment:n}:{},...s.length>0?{notes:s}:{}}]})}function $C(e){return Array.isArray(e)?e.flatMap(t=>{let{id:r,comment:i}=t??{};return typeof r!="string"||typeof i!="string"||!i?[]:[{id:r,comment:i}]}):[]}function xC(e){let t=e;if(!(typeof t?.topLeft!="string"||typeof t.bottomRight!="string"))return{topLeft:t.topLeft,bottomRight:t.bottomRight}}function Sb(e){return e.decision!=="approve"&&e.decision!=="reject"?null:{decision:e.decision,reason:e.reason,comments:Array.isArray(e.comments)?e.comments:void 0,screenshots:xb(e.screenshots),body:typeof e.body=="string"?e.body:void 0,reviewAfter:e.reviewAfter===!0,announceAfter:e.announceAfter===!0,draft:typeof e.draft=="boolean"?e.draft:void 0,autoMerge:e.autoMerge===!0,selection:xC(e.selection),checklist:_b(e.checklist)}}function kb(e,t){try{let r=JSON.parse(e);if(r.type==="error"&&(r.message??"").includes("pr-preview"))return{kind:"error",message:r.message??"pr-preview failed"};if(r.type!=="pr-decision"||r.requestId!==t)return null;let i=Sb(r);return i?{kind:"decision",decision:i}:null}catch{return null}}function Ib(e){return new Promise((t,r)=>{et().then(i=>{let n=!1,o=(s,a)=>{n||(n=!0,i.destroy(),s?r(s):t(a))};tr(i,s=>{let a=kb(s,e.requestId);a&&(a.kind==="error"?o(new Error(a.message)):o(void 0,a.decision))}),i.on("error",s=>o(s)),i.on("close",()=>o(new Error("daemon closed before a decision was made"))),i.write(`${JSON.stringify({type:"pr-preview",...e})}
|
|
195
|
+
`);for(let n of wb(i))console.error(n)}r&&console.error(r),process.exit(1)}function xb(e){if(Array.isArray(e))return e.flatMap(t=>{let{path:r,alt:i,group:n}=t??{};if(typeof r!="string"||r==="")return[];let o={path:r,alt:typeof i=="string"?i:""};return[typeof n=="string"&&n!==""?{...o,group:n}:o]})}function _b(e){if(Array.isArray(e))return e.flatMap(t=>{let{id:r,ticked:i,comment:n,notes:o}=t??{};if(typeof r!="string")return[];let s=$C(o);return[{id:r,ticked:i===!0,...typeof n=="string"&&n!==""?{comment:n}:{},...s.length>0?{notes:s}:{}}]})}function $C(e){return Array.isArray(e)?e.flatMap(t=>{let{id:r,comment:i}=t??{};return typeof r!="string"||typeof i!="string"||!i?[]:[{id:r,comment:i}]}):[]}function xC(e){let t=e;if(!(typeof t?.topLeft!="string"||typeof t.bottomRight!="string"))return{topLeft:t.topLeft,bottomRight:t.bottomRight}}function Sb(e){return e.decision!=="approve"&&e.decision!=="reject"?null:{decision:e.decision,reason:e.reason,comments:Array.isArray(e.comments)?e.comments:void 0,screenshots:xb(e.screenshots),body:typeof e.body=="string"?e.body:void 0,reviewAfter:e.reviewAfter===!0,announceAfter:e.announceAfter===!0,draft:typeof e.draft=="boolean"?e.draft:void 0,autoMerge:e.autoMerge===!0,autostart:e.autostart===!0,selection:xC(e.selection),checklist:_b(e.checklist)}}function kb(e,t){try{let r=JSON.parse(e);if(r.type==="error"&&(r.message??"").includes("pr-preview"))return{kind:"error",message:r.message??"pr-preview failed"};if(r.type!=="pr-decision"||r.requestId!==t)return null;let i=Sb(r);return i?{kind:"decision",decision:i}:null}catch{return null}}function Ib(e){return new Promise((t,r)=>{et().then(i=>{let n=!1,o=(s,a)=>{n||(n=!0,i.destroy(),s?r(s):t(a))};tr(i,s=>{let a=kb(s,e.requestId);a&&(a.kind==="error"?o(new Error(a.message)):o(void 0,a.decision))}),i.on("error",s=>o(s)),i.on("close",()=>o(new Error("daemon closed before a decision was made"))),i.write(`${JSON.stringify({type:"pr-preview",...e})}
|
|
196
196
|
`)},r)})}async function Pb(e,t,r={}){console.log("Awaiting your approval in the assist web UI preview pane\u2026");let i;try{i=await Ib(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&&$b(e,i,r.rejectionAdvice),i}async function Ob(e,t,r){let i=process.env.ASSIST_SESSION_ID;process.env.ASSIST_SESSION!=="1"||!i||await Pb("PR comment preview",{sessionId:i,requestId:_C(),title:e,body:t,prNumber:r,kind:"pr-comment"})}function SC(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 Cb(e){(!Number.isInteger(e)||e<1)&&(console.error("Error: Line must be a positive integer"),process.exit(1))}async function Eb(e,t,r,i={}){let{startLine:n,skipPreview:o}=i;SC(r),Cb(t),n!==void 0&&Cb(n);let s=n!==void 0?`${n}-${t}`:`${t}`;o||await Ob(`Comment on ${e}:${s}`,r,null);try{let a=ji();bb({prId:a,body:r,path:e,line:t,startLine:n}),console.log(`Added review comment on ${e}:${s}`)}catch(a){throw Di(a)&&(console.error("Error: GitHub CLI (gh) is not installed."),console.error("Install it from https://cli.github.com/"),process.exit(1)),a}}var Tb="the reviewer";function to(e){return e.replace(/\bclaude\b/gi,Tb).replace(/\bopus\b/gi,Tb)}function kC(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}`),to(t.join(`
|
|
197
197
|
`))}async function Nb(e){let t=0,r=0;for(let i of e){let n=kC(i);try{await Eb(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=ji();dn(e,{prId:r,body:t}),console.log("Submitted review.")}catch(r){if(Di(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 IC="mutation($prId: ID!, $body: String) { addPullRequestReview(input: { pullRequestId: $prId, event: COMMENT, body: $body }) { pullRequestReview { id } } }";function Rb(e){ro(IC,e)}var PC="mutation($prId: ID!, $body: String) { submitPullRequestReview(input: { pullRequestId: $prId, event: COMMENT, body: $body }) { pullRequestReview { id } } }";function Ab(e){ro(PC,e)}function OC(e,t){return to(Yt(e,t))}function CC(e,t){t>0?Ab(e):Rb(e)}async function EC(e){if(!e.prompt)return e.submit;await bc("waiting");try{return await or("Submit the pending review?",e.submit)}finally{await bc("running")}}async function zb(e,t,r,i){let n=await Nb(e),o=n.failed>0?`, ${n.failed} failed`:"";console.log(`Posted ${n.posted} comment(s)${o}.`);let s=Ht(t);return n.posted===0&&s.length===0?{posted:0,submitted:!1}:await EC(i)?(CC(OC(r,t),n.posted),{posted:n.posted,submitted:!0}):(console.log("Leaving the review unsubmitted."),{posted:n.posted,submitted:!1})}function TC(){try{return Li()}catch(e){return console.error(`Error: could not confirm which PR this tree is on: ${e instanceof Error?e.message:String(e)}`),null}}function Db(e){let t=TC();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)}var jb={posted:0,submitted:!1};function RC(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 ")}async function AC(e,t,r){return r.prompt?or(`Post ${t} to PR #${e}?`,!1):!0}async function zC(e,t,r){let i=NC(t,"utf8"),{inDiff:n,unanchored:o}=Fi(i,e),s=Ht(o);if(n.length===0&&s.length===0)return jb;let a=RC(n.length,s.length);return console.log(`Found PR #${e.prNumber} with ${a} to post.`),await AC(e.prNumber,a,r)?zb(n,o,i,r):(console.log("Skipped posting."),jb)}async function Lb(e,t,r){if(!Db(t.prNumber))return;let i=await zC(t,e,r);await db(t.prNumber,i,r)}import{mkdirSync as DC,writeFileSync as jC}from"node:fs";import{dirname as LC}from"node:path";var xc="assist sessions set-status";function wc(e){return`${xc} running --source ${e}`}function UC(e){return`${xc} waiting --source ${e}`}function $c(e){return`${xc} waiting --source ${e} --ack`}function Nt(e,t){let r=[{type:"command",command:e}];return[t==null?{hooks:r}:{matcher:t,hooks:r}]}var Ub="AskUserQuestion",MC=`^(?!${Ub}$).*`,qC={hooks:{UserPromptSubmit:Nt(wc("prompt")),PreToolUse:[...Nt(UC("pretool"),Ub),...Nt(wc("pretool"),MC)],PostToolUse:Nt(wc("posttool")),Stop:Nt($c("stop")),Notification:Nt($c("notification")),PermissionRequest:Nt($c("permission"))}};function Mb(){let e=er.hooksSettings;return DC(LC(e),{recursive:!0}),jC(e,JSON.stringify(qC,null,2)),e}import{spawn as FC}from"node:child_process";function qb(e,t,r={}){let{ASSIST_ACTIVITY_ID:i,CLAUDE_CODE_CHILD_SESSION:n,...o}=process.env,s=FC(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 sr(e,t={}){let r=["--settings",Mb(),...ZC(e,t)],i=t.permissionMode??(t.allowEdits?"auto":void 0);return i&&r.push("--permission-mode",i),qb("claude",r)}function ZC(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 BC(e){return`You are helping the user apply fixes for a code review with each finding decided one at a time.
|
|
198
198
|
|