@staff0rd/assist 0.831.1 → 0.833.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.
|
@@ -192,7 +192,7 @@ ${i}
|
|
|
192
192
|
Comment: ${t.note}
|
|
193
193
|
`})}function Sb(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 _b(i))console.error(n)}r&&console.error(r),process.exit(1)}function kb(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 Ib(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=PC(o);return[{id:r,ticked:i===!0,...typeof n=="string"&&n!==""?{comment:n}:{},...s.length>0?{notes:s}:{}}]})}function PC(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 OC(e){let t=e;if(!(typeof t?.topLeft!="string"||typeof t.bottomRight!="string"))return{topLeft:t.topLeft,bottomRight:t.bottomRight}}function Pb(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:kb(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:OC(e.selection),checklist:Ib(e.checklist)}}function Ob(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=Pb(r);return i?{kind:"decision",decision:i}:null}catch{return null}}function Cb(e){return new Promise((t,r)=>{nt().then(i=>{let n=!1,o=(s,a)=>{n||(n=!0,i.destroy(),s?r(s):t(a))};tr(i,s=>{let a=Ob(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 _b(i))console.error(n)}r&&console.error(r),process.exit(1)}function kb(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 Ib(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=PC(o);return[{id:r,ticked:i===!0,...typeof n=="string"&&n!==""?{comment:n}:{},...s.length>0?{notes:s}:{}}]})}function PC(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 OC(e){let t=e;if(!(typeof t?.topLeft!="string"||typeof t.bottomRight!="string"))return{topLeft:t.topLeft,bottomRight:t.bottomRight}}function Pb(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:kb(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:OC(e.selection),checklist:Ib(e.checklist),dismissed:e.dismissed===!0}}function Ob(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=Pb(r);return i?{kind:"decision",decision:i}:null}catch{return null}}function Cb(e){return new Promise((t,r)=>{nt().then(i=>{let n=!1,o=(s,a)=>{n||(n=!0,i.destroy(),s?r(s):t(a))};tr(i,s=>{let a=Ob(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 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
|
|