@lovek4d/kickflip 0.10.1 → 0.11.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 +1 @@
1
- var R=Object.defineProperty;var o=(t,r)=>R(t,"name",{value:r,configurable:!0});import _ from"node:fs";import N from"node:path";import{appendEvent as D,listBoards as H}from"./boards.mjs";import{savedSlack as M,slackStatus as x,refusalUnpushed as j,markRefusalPushed as P,missingScope as k,setHearing as y,hearingUnpushed as T,markHearingPushed as B,slackUserId as I}from"./slack.mjs";import{deliver as $}from"./push.mjs";import{reviewDue as U,postLink as q,recordReaction as A,postDigest as E,openDayThread as W,heardThreads as C,markHeard as F,boardPosts as J,ANSWER_MARK as K}from"../board/store.mjs";const v=o(t=>t.status===400&&t.message==="Slack refused the token.","refusedToken");async function L(t,r,p){const n=await U(t.dir,{now:p});if(n.waiting)return{sent:[],failed:[]};const d=[],c=[],a=o(async(e,s)=>{try{await s(),d.push(e)}catch(w){if(v(w))throw w;c.push(`${t.route}: ${e}: ${w.message}`)}},"attempt");for(const e of(n.digest?.reviewers||[]).filter(s=>s.owed))await a(`digest to ${e.name}`,async()=>{await E(t.dir,n.digest.date,e,{channel:e.sent?.channel||await r.openDM(e.slack_user),header:o(s=>`${t.title} digest: ${s} PR${s===1?"":"s"} pending your review`,"header"),post:o(s=>r.post(s),"post")})});const h=new Map,i=o((e,s)=>(h.has(e)||h.set(e,(async()=>W(t.dir,n.date,e,{channel:await s(),header:`${t.title} reviews`,post:o(w=>r.post(w),"post")}))()),h.get(e)),"dayThread");for(const e of n.links)await a(`link to ${e.reviewer} on ${e.pr}`,async()=>{const s=await i(e.reviewer,()=>r.openDM(e.slack_user));await q(t.dir,e,s,()=>r.post({channel:s.channel,thread_ts:s.ts,text:e.text}))});for(const e of n.reactions)await a(`${e.emoji} for ${e.reviewer} on ${e.pr}`,async()=>{await r.react({channel:e.channel,ts:e.ts,name:e.emoji}),await A(t.dir,e)});return{sent:d,failed:c}}o(L,"sendBoard");const O=o(t=>{try{return(JSON.parse(_.readFileSync(N.join(t.dir,"board.json"),"utf8")).reviewers||[]).length>0}catch{return!1}},"hasReviewers");async function z(t,r){return!j()||!t.some(O)?[]:(await $({title:"Slack refused Hub\u2019s token",body:"Reviewer links, reactions and digests wait until a working token is saved in Hub \u203A Integrations \u203A Slack.",url:"/_hub/settings#slack",tag:"slack-token"},{kind:"fault",immediate:!0,at:r}),P(),["pushed that Slack refused the token"])}o(z,"pushRefusal");async function G(t,r,p){const n=[],d=[],c=I(),a=new Map;for(const i of t)try{for(const e of await C(i.dir,p))a.set(e.channel,[...a.get(e.channel)||[],{board:i,thread:e}])}catch(e){d.push(`${i.route}: reading its day threads: ${e.message}`)}const h=o(async(i,e)=>{try{await e()}catch(s){if(k(s))throw s;d.push(`${i}: ${s.message}`)}},"attempt");for(const[i,e]of a)await h(`hearing DM ${i}`,async()=>{const s=e.map(u=>u.thread.ts).sort((u,f)=>Number(u)-Number(f))[0],w=new Map((await r.history({channel:i,oldest:s})).map(u=>[u.ts,u.latest_reply]));y(!0);for(const{board:u,thread:f}of e){const m=f.heard||f.ts;Number(w.get(f.ts))>Number(m)&&await h(`${u.route}: hearing ${f.reviewer}'s ${f.date} thread`,async()=>{const b=(await r.replies({channel:i,ts:f.ts,oldest:m})).filter(l=>Number(l.ts)>Number(m)),S=await J(u.dir);for(const l of b){if(!l.subtype&&!l.bot_id&&!S.has(l.ts)&&!(l.user===c&&l.text?.startsWith(K))){const g=l.user===c?"owner":"reviewer";await D(u,"slack-question",{reviewer:f.reviewer,channel:i,thread_ts:f.ts,ts:l.ts,from:g,answer:g==="reviewer"||/@kickflip\b/i.test(l.text||"")}),n.push(`${u.route}: slack-question from ${g==="owner"?"the owner":f.reviewer}`)}await F(u.dir,f,l.ts)}})}});return{sent:n,failed:d}}o(G,"hearBoards");async function Q(t,r,p){try{return await G(t,r,p)}catch(n){return k(n)?(y(!1),T()?(await $({title:"Slack can\u2019t read the review threads",body:"Reviewers\u2019 messages to the board wait unheard until Hub\u2019s Slack app has im:history: add it, reinstall the app and paste its new token in Hub \u203A Integrations \u203A Slack. Sends go on.",url:"/_hub/settings#slack",tag:"slack-unheard"},{kind:"fault",at:p}),B(),{sent:["pushed that Slack can't read the review threads"],failed:[]}):{sent:[],failed:[]}):{sent:[],failed:[`hearing the day threads: ${n.message}`]}}}o(Q,"hear");async function ae({boards:t=H(),fetch:r,now:p=new Date}={}){const n=M({fetch:r}),d=[],c=[];if(!n)return{sent:d,failed:c};for(const a of t)try{const h=await L(a,n,p);d.push(...h.sent.map(i=>`${a.route}: ${i}`)),c.push(...h.failed)}catch(h){if(c.push(`${a.route}: ${h.message}`),v(h))break}if(!x().refused)try{const a=await Q(t,n,p);d.push(...a.sent),c.push(...a.failed)}catch(a){c.push(`unheard push: ${a.message}`)}try{d.push(...await z(t,p))}catch(a){c.push(`refused-token push: ${a.message}`)}return{sent:d,failed:c}}o(ae,"sendReviews");export{ae as sendReviews};
1
+ var R=Object.defineProperty;var o=(t,r)=>R(t,"name",{value:r,configurable:!0});import _ from"node:fs";import D from"node:path";import{appendEvent as H,listBoards as N}from"./boards.mjs";import{savedSlack as M,slackStatus as x,refusalUnpushed as j,markRefusalPushed as P,missingScope as k,setHearing as y,hearingUnpushed as T,markHearingPushed as B,slackUserId as I,isSignedOff as U}from"./slack.mjs";import{deliver as $}from"./push.mjs";import{reviewDue as q,postLink as O,recordReaction as C,postDigest as E,openDayThread as F,heardThreads as J,markHeard as L,boardPosts as z}from"../board/store.mjs";const v=o(t=>t.status===400&&t.message==="Slack refused the token.","refusedToken");async function A(t,r,p){const n=await q(t.dir,{now:p});if(n.waiting)return{sent:[],failed:[]};const d=[],c=[],a=o(async(e,s)=>{try{await s(),d.push(e)}catch(w){if(v(w))throw w;c.push(`${t.route}: ${e}: ${w.message}`)}},"attempt");for(const e of(n.digest?.reviewers||[]).filter(s=>s.owed))await a(`digest to ${e.name}`,async()=>{await E(t.dir,n.digest.date,e,{channel:e.sent?.channel||await r.openDM(e.slack_user),header:o(s=>`${t.title} digest: ${s} PR${s===1?"":"s"} pending your review`,"header"),post:o(s=>r.post(s),"post")})});const u=new Map,i=o((e,s)=>(u.has(e)||u.set(e,(async()=>F(t.dir,n.date,e,{channel:await s(),header:`${t.title} reviews`,post:o(w=>r.post(w),"post")}))()),u.get(e)),"dayThread");for(const e of n.links)await a(`link to ${e.reviewer} on ${e.pr}`,async()=>{const s=await i(e.reviewer,()=>r.openDM(e.slack_user));await O(t.dir,e,s,()=>r.post({channel:s.channel,thread_ts:s.ts,text:e.text}))});for(const e of n.reactions)await a(`${e.emoji} for ${e.reviewer} on ${e.pr}`,async()=>{await r.react({channel:e.channel,ts:e.ts,name:e.emoji}),await C(t.dir,e)});return{sent:d,failed:c}}o(A,"sendBoard");const G=o(t=>{try{return(JSON.parse(_.readFileSync(D.join(t.dir,"board.json"),"utf8")).reviewers||[]).length>0}catch{return!1}},"hasReviewers");async function K(t,r){return!j()||!t.some(G)?[]:(await $({title:"Slack refused Hub\u2019s token",body:"Reviewer links, reactions and digests wait until a working token is saved in Hub \u203A Integrations \u203A Slack.",url:"/_hub/settings#slack",tag:"slack-token"},{kind:"fault",immediate:!0,at:r}),P(),["pushed that Slack refused the token"])}o(K,"pushRefusal");async function Q(t,r,p){const n=[],d=[],c=I(),a=new Map;for(const i of t)try{for(const e of await J(i.dir,p))a.set(e.channel,[...a.get(e.channel)||[],{board:i,thread:e}])}catch(e){d.push(`${i.route}: reading its day threads: ${e.message}`)}const u=o(async(i,e)=>{try{await e()}catch(s){if(k(s))throw s;d.push(`${i}: ${s.message}`)}},"attempt");for(const[i,e]of a)await u(`hearing DM ${i}`,async()=>{const s=e.map(h=>h.thread.ts).sort((h,f)=>Number(h)-Number(f))[0],w=new Map((await r.history({channel:i,oldest:s})).map(h=>[h.ts,h.latest_reply]));y(!0);for(const{board:h,thread:f}of e){const m=f.heard||f.ts;Number(w.get(f.ts))>Number(m)&&await u(`${h.route}: hearing ${f.reviewer}'s ${f.date} thread`,async()=>{const b=(await r.replies({channel:i,ts:f.ts,oldest:m})).filter(l=>Number(l.ts)>Number(m)),S=await z(h.dir);for(const l of b){if(!l.subtype&&!l.bot_id&&!S.has(l.ts)&&!(l.user===c&&U(l.text))){const g=l.user===c?"owner":"reviewer";await H(h,"slack-question",{reviewer:f.reviewer,channel:i,thread_ts:f.ts,ts:l.ts,from:g,answer:g==="reviewer"||/@kickflip\b/i.test(l.text||"")}),n.push(`${h.route}: slack-question from ${g==="owner"?"the owner":f.reviewer}`)}await L(h.dir,f,l.ts)}})}});return{sent:n,failed:d}}o(Q,"hearBoards");async function V(t,r,p){try{return await Q(t,r,p)}catch(n){return k(n)?(y(!1),T()?(await $({title:"Slack can\u2019t read the review threads",body:"Reviewers\u2019 messages to the board wait unheard until Hub\u2019s Slack app has im:history: add it, reinstall the app and paste its new token in Hub \u203A Integrations \u203A Slack. Sends go on.",url:"/_hub/settings#slack",tag:"slack-unheard"},{kind:"fault",at:p}),B(),{sent:["pushed that Slack can't read the review threads"],failed:[]}):{sent:[],failed:[]}):{sent:[],failed:[`hearing the day threads: ${n.message}`]}}}o(V,"hear");async function ae({boards:t=N(),fetch:r,now:p=new Date}={}){const n=M({fetch:r}),d=[],c=[];if(!n)return{sent:d,failed:c};for(const a of t)try{const u=await A(a,n,p);d.push(...u.sent.map(i=>`${a.route}: ${i}`)),c.push(...u.failed)}catch(u){if(c.push(`${a.route}: ${u.message}`),v(u))break}if(!x().refused)try{const a=await V(t,n,p);d.push(...a.sent),c.push(...a.failed)}catch(a){c.push(`unheard push: ${a.message}`)}try{d.push(...await K(t,p))}catch(a){c.push(`refused-token push: ${a.message}`)}return{sent:d,failed:c}}o(ae,"sendReviews");export{ae as sendReviews};
package/hub/slack.mjs CHANGED
@@ -1,2 +1,4 @@
1
- var O=Object.defineProperty;var n=(e,t)=>O(e,"name",{value:t,configurable:!0});import m from"node:fs";import p from"node:path";import w from"node:os";import{withFileLock as $}from"./locks.mjs";import{readSecret as D,writeSecret as d}from"./secrets.mjs";const f=["self_dm","owner_slack_user","slack_domain","timezone"],k=n(()=>p.join(w.homedir(),".claude","kickflip","slack.json"),"fileOf"),S=n(e=>{try{return JSON.parse(m.readFileSync(e,"utf8"))||{}}catch{return{}}},"read"),y=n(e=>Object.fromEntries(f.map(t=>[t,typeof e?.[t]=="string"?e[t]:""])),"identityOf");function g(e){const t=k();m.mkdirSync(p.dirname(t),{recursive:!0});const r=`${t}.${process.pid}.tmp`;return m.writeFileSync(r,JSON.stringify(e,null,2)+`
2
- `,{mode:384}),m.chmodSync(r,384),m.renameSync(r,t),e}n(g,"save");function x(){const e=y(S(k()));if(f.some(r=>e[r]))return e;const t=y(S(p.join(w.homedir(),".claude","slack-bridge","state.json")).config);return f.some(r=>t[r])?g(t):e}n(x,"readSlack");async function N(e){for(const[t,r]of Object.entries(e)){if(!f.includes(t)||typeof r!="string")throw new Error(`Unknown Slack setting ${t}`);if(t==="self_dm"&&r&&!/^D[A-Z0-9]+$/.test(r))throw new Error("self-dm must be a DM channel id");if(t==="owner_slack_user"&&r&&!/^U[A-Z0-9]+$/.test(r))throw new Error("user must be a Slack user id");if(t==="slack_domain"&&r&&!/^[a-z0-9][a-z0-9-]*$/.test(r))throw new Error("domain must be a Slack workspace domain");if(t==="timezone"&&r)try{new Intl.DateTimeFormat("en",{timeZone:r})}catch{throw new Error("timezone must be an IANA timezone such as Area/City")}}return $(k(),()=>g({...x(),...e}))}n(N,"setSlack");function B(e=new Date){const t=x().timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,r=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",weekday:"short",hour:"2-digit",hourCycle:"h23"}).formatToParts(e).map(({type:c,value:u})=>[c,u]));return{date:`${r.year}-${r.month}-${r.day}`,open:!["Sat","Sun"].includes(r.weekday)&&Number(r.hour)>=9&&Number(r.hour)<17}}n(B,"slackDay");class h extends Error{static{n(this,"SlackError")}constructor(t,r=502){super(t),this.status=r}}const E=n(()=>process.env.KICKFLIP_SLACK_URL||"https://slack.com/api","api"),I=["invalid_auth","not_authed","token_revoked","token_expired","account_inactive"];function v(e,{fetch:t=globalThis.fetch,checked:r=n(()=>{},"checked")}={}){async function c(a,i={}){let s;try{const o=await t(`${E()}/${a}`,{method:"POST",headers:{"content-type":"application/json; charset=utf-8",authorization:`Bearer ${e}`},body:JSON.stringify(i),signal:AbortSignal.timeout(15e3)});if(s=await o.json().catch(()=>null),!s)throw new Error(`Slack answered ${o.status}`)}catch(o){throw new h(`Could not reach Slack: ${o.message}`)}if(I.includes(s.error))throw r(!1),new h("Slack refused the token.",400);if(r(!0),!s.ok)throw new h(`Slack: ${s.error}`);return s}return n(c,"call"),{async who(){const{team:a,team_id:i,user:s,user_id:o}=await c("auth.test");return{team:a,team_id:i,user:s,user_id:o}},async people(){const a=[];let i="";do{const s=await c("users.list",{limit:200,...i?{cursor:i}:{}});for(const o of s.members)!o.deleted&&!o.is_bot&&o.id!=="USLACKBOT"&&a.push({id:o.id,name:o.profile?.real_name||o.real_name||o.name});i=s.response_metadata?.next_cursor||""}while(i);return a.sort((s,o)=>s.name.localeCompare(o.name))},openDM:n(async a=>(await c("conversations.open",{users:a})).channel.id,"openDM"),post:n(async({channel:a,text:i,thread_ts:s})=>(await c("chat.postMessage",{channel:a,text:i,unfurl_links:!1,...s?{thread_ts:s}:{}})).ts,"post"),async react({channel:a,ts:i,name:s}){try{await c("reactions.add",{channel:a,timestamp:i,name:s})}catch(o){if(o.message!=="Slack: already_reacted")throw o}},history:n(({channel:a,oldest:i})=>u("conversations.history",{channel:a,oldest:i,inclusive:!0}),"history"),replies:n(({channel:a,ts:i,oldest:s})=>u("conversations.replies",{channel:a,ts:i,...s?{oldest:s}:{}}),"replies")};async function u(a,i){const s=[];let o="";do{const _=await c(a,{...i,limit:200,...o?{cursor:o}:{}});s.push(..._.messages),o=_.response_metadata?.next_cursor||""}while(o);return s}n(u,"pages")}n(v,"slackClient");const K=n(e=>e.message==="Slack: missing_scope","missingScope"),l=n(e=>{const t=D("slack",e);return typeof t?.token=="string"&&t.token?t:null},"savedToken");function b(e){const t=l(e);return t?{set:!0,...t.refused_at?{refused:!0}:{},...t.unheard_at?{unheard:!0}:{},...t.team?{team:t.team,user:t.user}:{}}:{set:!1}}n(b,"slackStatus");const L=n(()=>l()?.user_id,"slackUserId"),P="Slack needs Hub\u2019s Slack token; add it in Hub \u203A Integrations \u203A Slack first.";async function Z(e,{fetch:t}={}){const r=typeof e=="string"?e.trim():"";if(!/^xoxp-[\w-]{10,250}$/.test(r))throw new h("Paste a Slack user token, which starts with xoxp-.",400);const c=new Date().toISOString();let u=!1;const a=await v(r,{fetch:t,checked:n(i=>{u=!i},"checked")}).who().catch(i=>{if(!u)throw i;return null});return d("slack",a?{token:r,...a,saved_at:c}:{token:r,saved_at:c,refused_at:c}),b()}n(Z,"saveSlackToken");function H(){return d("slack",null),b()}n(H,"removeSlackToken");function T(e,t){const r=l();if(r?.token!==e||!!r.refused_at==!t)return;const{refused_at:c,refusal_pushed_at:u,...a}=r;d("slack",t?a:{...a,refused_at:new Date().toISOString()})}n(T,"markChecked");const J=n(()=>{const e=l();return!!(e?.refused_at&&!e.refusal_pushed_at)},"refusalUnpushed");function M(){const e=l();e?.refused_at&&d("slack",{...e,refusal_pushed_at:new Date().toISOString()})}n(M,"markRefusalPushed");function R(e){const t=l();if(!t||!!t.unheard_at==!e)return;const{unheard_at:r,unheard_pushed_at:c,...u}=t;d("slack",e?u:{...u,unheard_at:new Date().toISOString()})}n(R,"setHearing");const q=n(()=>{const e=l();return!!(e?.unheard_at&&!e.unheard_pushed_at)},"hearingUnpushed");function G(){const e=l();e?.unheard_at&&d("slack",{...e,unheard_pushed_at:new Date().toISOString()})}n(G,"markHearingPushed");function Q({fetch:e}={}){const t=l();return t?v(t.token,{fetch:e,checked:n(r=>T(t.token,r),"checked")}):null}n(Q,"savedSlack");export{P as SLACK_NEEDS_TOKEN,h as SlackError,q as hearingUnpushed,G as markHearingPushed,M as markRefusalPushed,K as missingScope,x as readSlack,J as refusalUnpushed,H as removeSlackToken,Z as saveSlackToken,Q as savedSlack,R as setHearing,N as setSlack,v as slackClient,B as slackDay,b as slackStatus,L as slackUserId};
1
+ var I=Object.defineProperty;var r=(e,t)=>I(e,"name",{value:t,configurable:!0});import h from"node:fs";import k from"node:path";import y from"node:os";import{withFileLock as F}from"./locks.mjs";import{readSecret as j,writeSecret as m}from"./secrets.mjs";const p=["self_dm","owner_slack_user","slack_domain","timezone"],w=r(()=>k.join(y.homedir(),".claude","kickflip","slack.json"),"fileOf"),x=r(e=>{try{return JSON.parse(h.readFileSync(e,"utf8"))||{}}catch{return{}}},"read"),v=r(e=>Object.fromEntries(p.map(t=>[t,typeof e?.[t]=="string"?e[t]:""])),"identityOf");function O(e){const t=w();h.mkdirSync(k.dirname(t),{recursive:!0});const n=`${t}.${process.pid}.tmp`;return h.writeFileSync(n,JSON.stringify(e,null,2)+`
2
+ `,{mode:384}),h.chmodSync(n,384),h.renameSync(n,t),e}r(O,"save");function b(){const e=v(x(w()));if(p.some(n=>e[n]))return e;const t=v(x(k.join(y.homedir(),".claude","slack-bridge","state.json")).config);return p.some(n=>t[n])?O(t):e}r(b,"readSlack");async function P(e){for(const[t,n]of Object.entries(e)){if(!p.includes(t)||typeof n!="string")throw new Error(`Unknown Slack setting ${t}`);if(t==="self_dm"&&n&&!/^D[A-Z0-9]+$/.test(n))throw new Error("self-dm must be a DM channel id");if(t==="owner_slack_user"&&n&&!/^U[A-Z0-9]+$/.test(n))throw new Error("user must be a Slack user id");if(t==="slack_domain"&&n&&!/^[a-z0-9][a-z0-9-]*$/.test(n))throw new Error("domain must be a Slack workspace domain");if(t==="timezone"&&n)try{new Intl.DateTimeFormat("en",{timeZone:n})}catch{throw new Error("timezone must be an IANA timezone such as Area/City")}}return F(w(),()=>O({...b(),...e}))}r(P,"setSlack");function Z(e=new Date){const t=b().timezone||Intl.DateTimeFormat().resolvedOptions().timeZone,n=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",weekday:"short",hour:"2-digit",hourCycle:"h23"}).formatToParts(e).map(({type:c,value:u})=>[c,u]));return{date:`${n.year}-${n.month}-${n.day}`,open:!["Sat","Sun"].includes(n.weekday)&&Number(n.hour)>=9&&Number(n.hour)<17}}r(Z,"slackDay");class _ extends Error{static{r(this,"SlackError")}constructor(t,n=502){super(t),this.status=n}}const A=r(()=>process.env.KICKFLIP_SLACK_URL||"https://slack.com/api","api"),C=["invalid_auth","not_authed","token_revoked","token_expired","account_inactive"],$="- :claude_kickflip:",S="- :robot_face:",H=r(e=>[$,S].includes(String(e||"").split(`
3
+ `).at(-1)),"isSignedOff");function D(e,{fetch:t=globalThis.fetch,checked:n=r(()=>{},"checked")}={}){async function c(i,o={}){let s;try{const a=await t(`${A()}/${i}`,{method:"POST",headers:{"content-type":"application/json; charset=utf-8",authorization:`Bearer ${e}`},body:JSON.stringify(o),signal:AbortSignal.timeout(15e3)});if(s=await a.json().catch(()=>null),!s)throw new Error(`Slack answered ${a.status}`)}catch(a){throw new _(`Could not reach Slack: ${a.message}`)}if(C.includes(s.error))throw n(!1),new _("Slack refused the token.",400);if(n(!0),!s.ok)throw new _(`Slack: ${s.error}`);return s}r(c,"call");let u;const d=r(i=>(u??=c("emoji.list").then(o=>o.emoji?.claude_kickflip?$:S,()=>S),u.then(o=>`${i}
4
+ ${o}`)),"signedOff");return{async who(){const{team:i,team_id:o,user:s,user_id:a}=await c("auth.test");return{team:i,team_id:o,user:s,user_id:a}},async people(){const i=[];let o="";do{const s=await c("users.list",{limit:200,...o?{cursor:o}:{}});for(const a of s.members)!a.deleted&&!a.is_bot&&a.id!=="USLACKBOT"&&i.push({id:a.id,name:a.profile?.real_name||a.real_name||a.name});o=s.response_metadata?.next_cursor||""}while(o);return i.sort((s,a)=>s.name.localeCompare(a.name))},openDM:r(async i=>(await c("conversations.open",{users:i})).channel.id,"openDM"),post:r(async({channel:i,text:o,thread_ts:s})=>(await c("chat.postMessage",{channel:i,text:await d(o),unfurl_links:!1,...s?{thread_ts:s}:{}})).ts,"post"),async react({channel:i,ts:o,name:s}){try{await c("reactions.add",{channel:i,timestamp:o,name:s})}catch(a){if(a.message!=="Slack: already_reacted")throw a}},history:r(({channel:i,oldest:o})=>f("conversations.history",{channel:i,oldest:o,inclusive:!0}),"history"),replies:r(({channel:i,ts:o,oldest:s})=>f("conversations.replies",{channel:i,ts:o,...s?{oldest:s}:{}}),"replies")};async function f(i,o){const s=[];let a="";do{const g=await c(i,{...o,limit:200,...a?{cursor:a}:{}});s.push(...g.messages),a=g.response_metadata?.next_cursor||""}while(a);return s}}r(D,"slackClient");const J=r(e=>e.message==="Slack: missing_scope","missingScope"),l=r(e=>{const t=j("slack",e);return typeof t?.token=="string"&&t.token?t:null},"savedToken");function E(e){const t=l(e);return t?{set:!0,...t.refused_at?{refused:!0}:{},...t.unheard_at?{unheard:!0}:{},...t.team?{team:t.team,user:t.user}:{}}:{set:!1}}r(E,"slackStatus");const M=r(()=>l()?.user_id,"slackUserId"),R="Slack needs Hub\u2019s Slack token; add it in Hub \u203A Integrations \u203A Slack first.";async function G(e,{fetch:t}={}){const n=typeof e=="string"?e.trim():"";if(!/^xoxp-[\w-]{10,250}$/.test(n))throw new _("Paste a Slack user token, which starts with xoxp-.",400);const c=new Date().toISOString();let u=!1;const d=await D(n,{fetch:t,checked:r(f=>{u=!f},"checked")}).who().catch(f=>{if(!u)throw f;return null});return m("slack",d?{token:n,...d,saved_at:c}:{token:n,saved_at:c,refused_at:c}),E()}r(G,"saveSlackToken");function q(){return m("slack",null),E()}r(q,"removeSlackToken");function T(e,t){const n=l();if(n?.token!==e||!!n.refused_at==!t)return;const{refused_at:c,refusal_pushed_at:u,...d}=n;m("slack",t?d:{...d,refused_at:new Date().toISOString()})}r(T,"markChecked");const Q=r(()=>{const e=l();return!!(e?.refused_at&&!e.refusal_pushed_at)},"refusalUnpushed");function V(){const e=l();e?.refused_at&&m("slack",{...e,refusal_pushed_at:new Date().toISOString()})}r(V,"markRefusalPushed");function W(e){const t=l();if(!t||!!t.unheard_at==!e)return;const{unheard_at:n,unheard_pushed_at:c,...u}=t;m("slack",e?u:{...u,unheard_at:new Date().toISOString()})}r(W,"setHearing");const X=r(()=>{const e=l();return!!(e?.unheard_at&&!e.unheard_pushed_at)},"hearingUnpushed");function Y(){const e=l();e?.unheard_at&&m("slack",{...e,unheard_pushed_at:new Date().toISOString()})}r(Y,"markHearingPushed");function ee({fetch:e}={}){const t=l();return t?D(t.token,{fetch:e,checked:r(n=>T(t.token,n),"checked")}):null}r(ee,"savedSlack");export{R as SLACK_NEEDS_TOKEN,_ as SlackError,X as hearingUnpushed,H as isSignedOff,Y as markHearingPushed,V as markRefusalPushed,J as missingScope,b as readSlack,Q as refusalUnpushed,q as removeSlackToken,G as saveSlackToken,ee as savedSlack,W as setHearing,P as setSlack,D as slackClient,Z as slackDay,E as slackStatus,M as slackUserId};
package/hub/views.mjs CHANGED
@@ -1 +1 @@
1
- var D=Object.defineProperty;var i=(e,t)=>D(e,"name",{value:t,configurable:!0});import{clock as c,holdLine as v,snoozeEnd as m}from"./schedule.mjs";import{CHOICES as L,FOREVER as w,durationEnd as V,endOf as K}from"./duration.mjs";import{siteIcon as F}from"./icons.mjs";import{codexStatus as M}from"../shared/codex.mjs";const ue=i(e=>e.charAt(0).toUpperCase()+e.slice(1),"capital"),H=i((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural"),p=i(e=>{const[t,n]=e.split(":").map(Number),o=new Date;return o.setHours(t,n,0,0),c(o,o)},"timeOfDay"),E=i((e,t)=>e.hold?v(e.hold,t):"pushes go out after each check","deviceLine"),W=i(e=>`${p(e.quiet.start)} \u2013 ${p(e.quiet.end)}${e.quiet.hold?" \xB7 pushes held":""}`,"quietSummary"),B="checks every minute while you're here, every 5 when away";function Z(e,t){const n={port:"down \xB7 not answering",files:"down \xB7 folder missing"}[e.serves]||"down \xB7 restarting";if(e.state!=="up")return{tone:e.state==="down"?"down":"wait",word:e.state==="down"?n:e.state,lines:[]};if(!t)return{tone:"ok",word:"up",lines:[]};const o=t.filter(u=>!u.ok),l=o.filter(u=>u.state==="broken"),r=t.find(u=>u.link==="events"),a=r?.listen==="asleep"||r?.listen==="waking"?r.listen:r?.ok?"listening":"not listening",d=l.length?`degraded \xB7 ${a}`:o.length?`up \xB7 ${a} \xB7 ${o.length} settling`:`up \xB7 ${a} \xB7 every link passes`;return{tone:o.length?"wait":"ok",word:d,lines:o.map(u=>({link:u.link,detail:`${u.state==="broken"?"":"settling: "}${u.detail}`}))}}i(Z,"siteHealth");const x=[{value:"always",label:"Always on",description:i(()=>"Codex implements and reviews. Work pauses when it runs out.","description")},{value:"auto",label:"Auto",description:i(e=>`Codex implements and reviews, and ${e} takes over while it's out.`,"description")},{value:"off",label:"Off",description:i(e=>`${e} implements and reviews.`,"description")}],j=i((e,t,n)=>({usable:t.usable,tag:t.usable?null:t.reason,share:e,choices:x.map(({value:o,label:l})=>({value:o,label:l,on:o===e})),description:t.usable?x.find(o=>o.value===e).description(A[n]):t.words,fix:t.fix}),"codexView"),A={opus:"Opus",sonnet:"Sonnet",auto:"Claude"},q=[{value:"opus",label:"Opus",description:"Always Opus. Auto would give small cards to Sonnet."},{value:"auto",label:"Auto",description:"Auto: small cards get Sonnet, the rest get Opus."},{value:"sonnet",label:"Sonnet",description:"Always Sonnet. Auto would give large cards to Opus."}],J=i(e=>({model:e,builder:A[e],choices:q.map(({value:t,label:n})=>({value:t,label:n,on:t===e})),description:q.find(t=>t.value===e).description}),"claudeView");function re({now:e,st:t,sidebar:n,rows:o,links:l=new Map,code:r={},host:a="",version:d,rules:u=[],remembered:y=new Map,integrations:f=[],codexShare:h="off",claudeModel:S="auto",codex:I=M({installed:!1}),awake:T={on:!1,unsupported:null}}){const g=new Set(n.sites.filter(s=>s.board).map(s=>s.route)),O=!!(r.running&&r.running===r.onDisk),P=O?` \xB7 runs the code in its files (${r.onDisk})`:"",z=i(s=>({route:s.route,title:s.title,icon:F(s.route,s),href:`/${encodeURIComponent(s.route)}/`,...Z(s,l.get(s.route)),remembered:y.get(s.route)||[],restart:g.has(s.route)&&s.restart===!0}),"site"),R=[["Boards",o.filter(s=>g.has(s.route))],["Pages",o.filter(s=>!g.has(s.route))]].filter(([,s])=>s.length).map(([s,U])=>({label:s,sites:U.map(z)}));return{hub:{tone:n.hub.tone,word:n.hub.word,detail:`${n.hub.detail}${P}`,restart:!O},awake:T,groups:R,integrations:f,usage:n.usage,pause:n.pause,codex:j(h,I,S),claude:J(S),empty:o.length===0,notifications:{on:t.settings.notifications.on,text:n.notifications.text,device:E(t,e)},hold:t.hold&&t.hold.why!=="off"?{text:`Notifications ${v(t.hold,e)}`,end:t.hold.why==="snoozed"}:null,rules:u.length?H(u.length,"rule"):"None yet",host:a,version:d,total:n.total}}i(re,"hubView");const ae="That snooze ends in the past or more than 30 days on. Pick another time.",C="until you end it",N="until you resume",$=i((e,t,n)=>e===w?n:`until ${c(e,t)}`,"untilWords"),_=i((e,t)=>L.map(([n,o])=>({value:n,label:o,until:$(V(e,n),e,t)})),"durationChoices"),Q=i((e,t)=>e.on?K(e.snoozed_until,t):null,"snoozedUntil");function le({now:e,st:t,rules:n=[],linear:o={set:!1},slack:l={set:!1},pausedUntil:r=null}){const a=t.settings,d=a.notifications,u=Q(d,e),y=t.count?` The ${t.count} queued push${t.count===1?" is":"es are"} dropped now.`:"",f=u&&`Snoozed ${$(u,e,C)}`,h=r&&`Paused ${$(r,e,N)}`;return{pause:{on:r?{title:h}:null,summary:r===w?"Paused \xB7 forever":h||"Off",choices:r?null:_(e,N)},snoozed:u?{title:f,summary:u===w?"Snoozed \xB7 forever":f}:null,device:E(t,e),on:{on:d.on,sub:d.on?"On. Turn off to drop every push, urgent ones too.":"Off. Every push is dropped, urgent ones too. Needs you and the badge still update.",confirm:`Turn off notifications? Every push is dropped until you turn them back on, urgent ones too.${y} Needs you and the badge still update.`},snooze:d.on&&!u?{choices:_(e,C)}:null,weekends:{on:d.weekends_off,sub:`Pushes wait from Friday ${p(a.quiet.start)} until Monday ${p(a.quiet.end)}. Urgent ones still go.`},quiet:ee(a,e),rules:n,linear:G(o),slack:Y(l)}}i(le,"settingsView");const X={display_information:{name:"Kickflip"},oauth_config:{scopes:{user:["chat:write","im:history","im:write","reactions:write","users:read"]}}},b={url:`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(JSON.stringify(X))}`,label:"a new Slack app"};function Y(e){const t=e.team?`${e.team} workspace`:"",n=`Make ${b.label}, install it to your workspace, then paste its User OAuth Token (xoxp-\u2026) here.`;return e.set?e.refused?{set:!0,refused:!0,title:t||"Slack token",down:"doesn\u2019t work",sub:`Slack refused the token. ${n}`,keys:b,summary:t?`Token doesn\u2019t work \xB7 ${t}`:"Token doesn\u2019t work"}:{set:!0,title:t,sub:`Token \u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 \xB7 sends as ${e.user}`,summary:`Token set \xB7 ${t}`}:{set:!1,title:"No token",sub:n,keys:b,summary:"No token"}}i(Y,"slackWords");const k={url:"https://linear.app/settings/account/security",label:"Linear \u203A Settings \u203A Security & access \u203A Personal API keys"};function G(e){const t=e.workspace?`${e.workspace} workspace`:"";return e.set?e.refused?{set:!0,refused:!0,title:t||"Linear key",down:"doesn\u2019t work",sub:`Linear refused the key. Make a new one in ${k.label} and paste it here.`,keys:k,summary:t?`Key doesn\u2019t work \xB7 ${t}`:"Key doesn\u2019t work"}:{set:!0,title:t,sub:"Key \u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",summary:`Key set \xB7 ${t}`}:{set:!1,title:"No key",sub:`Make a personal API key in ${k.label}, then paste it here.`,keys:k,summary:"No key"}}i(G,"linearWords");function ee(e,t){const n=e.quiet,[o,l]=[p(n.start),p(n.end)],r=m(t,"tonight",e),a=[["Snooze tonight",`Until ${c(r,t)}${n.hold?`, then quiet hours hold pushes until ${c(m(r,"morning",e),t)}`:""}.`],["Snooze morning",`Until ${c(m(t,"morning",e),t)}.`],["Snooze monday",`Until ${c(m(t,"monday",e),t)}.`],["Off on weekends",e.notifications.weekends_off?`Pushes wait from Friday ${o} until Monday ${l}.`:"Off."],["Daily wake",`Every board wakes once at ${l}, when quiet hours end.`]];return{start:n.start,end:n.end,summary:W(e),hint:B,hold:{on:n.hold,sub:n.hold?`Pushes queued after ${o} wait until ${l}. Urgent ones still go.`:"Off. Pushes go out all night."},reads:a.map(([d,u])=>({title:d,sub:u}))}}i(ee,"quietView");function de(e){return e?e.ok?{sent:e.sent,count:e.count,ok:!0,message:`Sent ${e.count} queued push${e.count===1?"":"es"}.`}:{sent:e.sent,count:e.count,ok:!1,message:"Could not send the queue. It stays queued for the next check."}:{sent:0,count:0,ok:!0,message:"Nothing was queued."}}i(de,"flushView");export{B as QUIET_HINT,ae as SNOOZE_REFUSED,ue as capital,_ as durationChoices,de as flushView,re as hubView,H as plural,W as quietSummary,le as settingsView,Z as siteHealth};
1
+ var D=Object.defineProperty;var i=(e,t)=>D(e,"name",{value:t,configurable:!0});import{clock as c,holdLine as v,snoozeEnd as m}from"./schedule.mjs";import{CHOICES as L,FOREVER as w,durationEnd as V,endOf as K}from"./duration.mjs";import{siteIcon as F}from"./icons.mjs";import{codexStatus as M}from"../shared/codex.mjs";const ue=i(e=>e.charAt(0).toUpperCase()+e.slice(1),"capital"),H=i((e,t)=>`${e} ${t}${e===1?"":"s"}`,"plural"),p=i(e=>{const[t,n]=e.split(":").map(Number),o=new Date;return o.setHours(t,n,0,0),c(o,o)},"timeOfDay"),E=i((e,t)=>e.hold?v(e.hold,t):"pushes go out after each check","deviceLine"),W=i(e=>`${p(e.quiet.start)} \u2013 ${p(e.quiet.end)}${e.quiet.hold?" \xB7 pushes held":""}`,"quietSummary"),B="checks every minute while you're here, every 5 when away";function j(e,t){const n={port:"down \xB7 not answering",files:"down \xB7 folder missing"}[e.serves]||"down \xB7 restarting";if(e.state!=="up")return{tone:e.state==="down"?"down":"wait",word:e.state==="down"?n:e.state,lines:[]};if(!t)return{tone:"ok",word:"up",lines:[]};const o=t.filter(u=>!u.ok),l=o.filter(u=>u.state==="broken"),r=t.find(u=>u.link==="events"),a=r?.listen==="asleep"||r?.listen==="waking"?r.listen:r?.ok?"listening":"not listening",d=l.length?`degraded \xB7 ${a}`:o.length?`up \xB7 ${a} \xB7 ${o.length} settling`:`up \xB7 ${a} \xB7 every link passes`;return{tone:o.length?"wait":"ok",word:d,lines:o.map(u=>({link:u.link,detail:`${u.state==="broken"?"":"settling: "}${u.detail}`}))}}i(j,"siteHealth");const x=[{value:"always",label:"Always on",description:i(()=>"Codex implements and reviews. Work pauses when it runs out.","description")},{value:"auto",label:"Auto",description:i(e=>`Codex implements and reviews, and ${e} takes over while it's out.`,"description")},{value:"off",label:"Off",description:i(e=>`${e} implements and reviews.`,"description")}],Z=i((e,t,n)=>({usable:t.usable,tag:t.usable?null:t.reason,share:e,choices:x.map(({value:o,label:l})=>({value:o,label:l,on:o===e})),description:t.usable?x.find(o=>o.value===e).description(A[n]):t.words,fix:t.fix}),"codexView"),A={opus:"Opus",sonnet:"Sonnet",auto:"Claude"},q=[{value:"opus",label:"Opus",description:"Always Opus. Auto would give small cards to Sonnet."},{value:"auto",label:"Auto",description:"Auto: small cards get Sonnet, the rest get Opus."},{value:"sonnet",label:"Sonnet",description:"Always Sonnet. Auto would give large cards to Opus."}],J=i(e=>({model:e,builder:A[e],choices:q.map(({value:t,label:n})=>({value:t,label:n,on:t===e})),description:q.find(t=>t.value===e).description}),"claudeView");function re({now:e,st:t,sidebar:n,rows:o,links:l=new Map,code:r={},host:a="",version:d,rules:u=[],remembered:y=new Map,integrations:f=[],codexShare:h="off",claudeModel:S="auto",codex:I=M({installed:!1}),awake:T={on:!1,unsupported:null}}){const g=new Set(n.sites.filter(s=>s.board).map(s=>s.route)),O=!!(r.running&&r.running===r.onDisk),P=O?` \xB7 runs the code in its files (${r.onDisk})`:"",z=i(s=>({route:s.route,title:s.title,icon:F(s.route,s),href:`/${encodeURIComponent(s.route)}/`,...j(s,l.get(s.route)),remembered:y.get(s.route)||[],restart:g.has(s.route)&&s.restart===!0}),"site"),R=[["Boards",o.filter(s=>g.has(s.route))],["Pages",o.filter(s=>!g.has(s.route))]].filter(([,s])=>s.length).map(([s,U])=>({label:s,sites:U.map(z)}));return{hub:{tone:n.hub.tone,word:n.hub.word,detail:`${n.hub.detail}${P}`,restart:!O},awake:T,groups:R,integrations:f,usage:n.usage,pause:n.pause,codex:Z(h,I,S),claude:J(S),empty:o.length===0,notifications:{on:t.settings.notifications.on,text:n.notifications.text,device:E(t,e)},hold:t.hold&&t.hold.why!=="off"?{text:`Notifications ${v(t.hold,e)}`,end:t.hold.why==="snoozed"}:null,rules:u.length?H(u.length,"rule"):"None yet",host:a,version:d,total:n.total}}i(re,"hubView");const ae="That snooze ends in the past or more than 30 days on. Pick another time.",C="until you end it",N="until you resume",$=i((e,t,n)=>e===w?n:`until ${c(e,t)}`,"untilWords"),_=i((e,t)=>L.map(([n,o])=>({value:n,label:o,until:$(V(e,n),e,t)})),"durationChoices"),Q=i((e,t)=>e.on?K(e.snoozed_until,t):null,"snoozedUntil");function le({now:e,st:t,rules:n=[],linear:o={set:!1},slack:l={set:!1},pausedUntil:r=null}){const a=t.settings,d=a.notifications,u=Q(d,e),y=t.count?` The ${t.count} queued push${t.count===1?" is":"es are"} dropped now.`:"",f=u&&`Snoozed ${$(u,e,C)}`,h=r&&`Paused ${$(r,e,N)}`;return{pause:{on:r?{title:h}:null,summary:r===w?"Paused \xB7 forever":h||"Off",choices:r?null:_(e,N)},snoozed:u?{title:f,summary:u===w?"Snoozed \xB7 forever":f}:null,device:E(t,e),on:{on:d.on,sub:d.on?"On. Turn off to drop every push, urgent ones too.":"Off. Every push is dropped, urgent ones too. Needs you and the badge still update.",confirm:`Turn off notifications? Every push is dropped until you turn them back on, urgent ones too.${y} Needs you and the badge still update.`},snooze:d.on&&!u?{choices:_(e,C)}:null,weekends:{on:d.weekends_off,sub:`Pushes wait from Friday ${p(a.quiet.start)} until Monday ${p(a.quiet.end)}. Urgent ones still go.`},quiet:ee(a,e),rules:n,linear:G(o),slack:Y(l)}}i(le,"settingsView");const X={display_information:{name:"Kickflip"},oauth_config:{scopes:{user:["chat:write","emoji:read","im:history","im:write","reactions:write","users:read"]}}},b={url:`https://api.slack.com/apps?new_app=1&manifest_json=${encodeURIComponent(JSON.stringify(X))}`,label:"a new Slack app"};function Y(e){const t=e.team?`${e.team} workspace`:"",n=`Make ${b.label}, install it to your workspace, then paste its User OAuth Token (xoxp-\u2026) here.`;return e.set?e.refused?{set:!0,refused:!0,title:t||"Slack token",down:"doesn\u2019t work",sub:`Slack refused the token. ${n}`,keys:b,summary:t?`Token doesn\u2019t work \xB7 ${t}`:"Token doesn\u2019t work"}:{set:!0,title:t,sub:`Token \u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 \xB7 sends as ${e.user}`,summary:`Token set \xB7 ${t}`}:{set:!1,title:"No token",sub:n,keys:b,summary:"No token"}}i(Y,"slackWords");const k={url:"https://linear.app/settings/account/security",label:"Linear \u203A Settings \u203A Security & access \u203A Personal API keys"};function G(e){const t=e.workspace?`${e.workspace} workspace`:"";return e.set?e.refused?{set:!0,refused:!0,title:t||"Linear key",down:"doesn\u2019t work",sub:`Linear refused the key. Make a new one in ${k.label} and paste it here.`,keys:k,summary:t?`Key doesn\u2019t work \xB7 ${t}`:"Key doesn\u2019t work"}:{set:!0,title:t,sub:"Key \u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",summary:`Key set \xB7 ${t}`}:{set:!1,title:"No key",sub:`Make a personal API key in ${k.label}, then paste it here.`,keys:k,summary:"No key"}}i(G,"linearWords");function ee(e,t){const n=e.quiet,[o,l]=[p(n.start),p(n.end)],r=m(t,"tonight",e),a=[["Snooze tonight",`Until ${c(r,t)}${n.hold?`, then quiet hours hold pushes until ${c(m(r,"morning",e),t)}`:""}.`],["Snooze morning",`Until ${c(m(t,"morning",e),t)}.`],["Snooze monday",`Until ${c(m(t,"monday",e),t)}.`],["Off on weekends",e.notifications.weekends_off?`Pushes wait from Friday ${o} until Monday ${l}.`:"Off."],["Daily wake",`Every board wakes once at ${l}, when quiet hours end.`]];return{start:n.start,end:n.end,summary:W(e),hint:B,hold:{on:n.hold,sub:n.hold?`Pushes queued after ${o} wait until ${l}. Urgent ones still go.`:"Off. Pushes go out all night."},reads:a.map(([d,u])=>({title:d,sub:u}))}}i(ee,"quietView");function de(e){return e?e.ok?{sent:e.sent,count:e.count,ok:!0,message:`Sent ${e.count} queued push${e.count===1?"":"es"}.`}:{sent:e.sent,count:e.count,ok:!1,message:"Could not send the queue. It stays queued for the next check."}:{sent:0,count:0,ok:!0,message:"Nothing was queued."}}i(de,"flushView");export{B as QUIET_HINT,ae as SNOOZE_REFUSED,ue as capital,_ as durationChoices,de as flushView,re as hubView,H as plural,W as quietSummary,le as settingsView,j as siteHealth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovek4d/kickflip",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Follow and steer Claude Code sessions from your phone.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {