@gruum/cli 0.1.23 → 0.2.2

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.
Files changed (2) hide show
  1. package/gruum.mjs +6 -6
  2. package/package.json +1 -1
package/gruum.mjs CHANGED
@@ -57,17 +57,17 @@ ${e}
57
57
  `:""}${t.join(`
58
58
  `)}`.slice(0,Mc)}function go(e,t){let n=[...e.keys()].sort(),s=b=>e.has(b),r=new Map,o=(b,S,_,L)=>{let M=`${S}:${b}`,F=r.get(M);if(F){F.note.includes(_)||(F.note+=`; ${_}`);return}r.set(M,{path:b,role:S,note:_,matches:L.count,lines:L.lines})},i=new Set,a=new Set;for(let b of n){if(!we.test(b)||Z.test(b))continue;let S=e.get(b),_=ao(S).filter(O=>t.identifier.test(O)),L=b.split("/").pop()??"",M=new RegExp(t.classKeywords.join("|"),"i").test(L);if(_.length===0&&!M)continue;for(let O of _)i.add(O);a.add(b);let F=_.length?new RegExp(`\\b(?:${_.map(de).join("|")})\\b`,"g"):t.prose;o(b,"implements",_.length?`exports ${_.join(", ")}`:"named for the concept",ge(S,F))}let l=new Set,c=[],u=[],f=new Map,m=b=>io(b,t.classKeywords)||/\.module\.[a-z]+$/i.test(b)&&f.has(b),h=null,w=()=>h??=jc(e),C=b=>{let S=m(b),_=[],L=0;for(let O of ke(e.get(b))){let U=W(O.selector).filter(D=>Ze(D,t,S));if(U.length===0)continue;L+=1;for(let D of O.ownBody.matchAll(Dn))l.add(D[1]);let z=$t(O.ownBody),ae=[...Pc(b,O.ownBody,w(),s),...pe(O.ownBody),...z.filter(D=>D.state==="default"&&D.context==="").flatMap(D=>D.declarations)];for(let D of ae)for(let J of D.value.matchAll(Dn))l.add(J[1]);_.push({block:O,parts:U,declarations:ae,previewContext:Rt(O.context)?"":null,listed:!0});for(let D of z){if(D.state==="default"&&D.context==="")continue;let J=Lc(U.join(", "),D.state),Te=W(J).filter(ci=>Ze(ci,t,S));if(Te.length===0)continue;let li=[O.context,D.context].filter(Boolean).join(" \xB7 ");_.push({block:{...O,selector:J,context:li},parts:Te,declarations:D.declarations,previewContext:Rt(O.context)?D.context:null,listed:!1})}}let M={parts:new Set,controls:new Set};for(let O of f.get(b)??[]){let U=Bc(e.get(O)??"");for(let z of U.parts)M.parts.add(z);for(let z of U.controls)M.controls.add(z)}c.push(...Ur(b,_.map(({block:O,parts:U,declarations:z})=>({selector:U.join(", "),declarations:z,line:O.line,context:O.context})),t,S,M));let F=/\.module\.[a-z]+$/i.test(b)?`${ar(b)} `:"";for(let{parts:O,declarations:U,previewContext:z}of _){if(z===null)continue;let ae=O.flatMap(J=>{let Te=Ze(J,t,S);return Te?[`${F}${Ke(Te.compounds)}`]:[]}),D=U.filter(J=>se(J.property,J.value));if(!(ae.length===0||D.length===0))for(let J of ae)u.push(...Pn(J,D,z))}return{count:L,lines:_.filter(O=>O.listed).slice(0,co).map(({block:O})=>({line:O.line,text:O.selector.replace(/\s+/g," ").slice(0,Nn)}))}},$=new Map;for(let b of a)for(let S of Mn(e.get(b))){let _=ve(b,S,s);if(_&&Xe.test(_)){let L=$.get(_)??[];L.push(b.split("/").pop()??b),$.set(_,L),io(b,t.classKeywords)&&f.set(_,[...f.get(_)??[],b])}}for(let b of n){if(!Xe.test(b))continue;let S=C(b),_=$.get(b);if(S.count===0)continue;let L=[];_&&L.push(`imported by ${_.join(", ")}`),S.count>0&&L.push(`${S.count} matching rule${S.count===1?"":"s"}`),o(b,"styles",L.join("; "),S)}let g=new Set;for(let b of c)for(let S of b.selector.matchAll(/\.((?:\\.|[\w-])+)/g))g.add(S[1].replace(/\\(.)/g,"$1"));let p=new Set(a),d=new RegExp([...t.elements.map(b=>`<${de(b)}\\b`),...t.roles.map(b=>`role=["']${de(b)}["']`)].join("|"));for(let b of n)!we.test(b)||Z.test(b)||d.test(e.get(b)??"")&&p.add(b);for(let b of a)for(let S of Mn(e.get(b))){let _=ve(b,S,s);!_||!we.test(_)||Z.test(_)||eo(_,t.classKeywords)&&p.add(_)}let y=0,k=[],x=[];for(let b of p){let S=Qr(b,e.get(b)??"",t,g,y);y=S.nextId,k.push(...S.recipes),c.push(...S.variants),x.push(...S.inline),u.push(...S.previewRules)}let v=is(x);c.push(...v.variants);let E=Er([...a].map(b=>({path:b,source:e.get(b)??"",names:ao(e.get(b)??"").filter(S=>t.identifier.test(S))})),k,(b,S)=>ve(b,S,s)),j=[];if(l.size>0){let b=new RegExp(`(?:^|[\\s{;])(${[...l].map(de).join("|")})\\s*:`),S=new Map;for(let _ of n){if(!Xe.test(_)&&!oo.test(_))continue;let L=e.get(_),M=ge(L,b);if(M.count!==0){for(let F of L.matchAll(new RegExp(b.source,"gm"))){let O=S.get(F[1])??[];O.includes(_)||O.push(_),S.set(F[1],O)}o(_,"tokens",`defines ${M.count} token${M.count===1?"":"s"} read by ${t.label.toLowerCase()} styles`,M)}}for(let _ of[...l].sort())j.push({name:_,definedIn:S.get(_)??[]})}for(let b of n){if(!oo.test(b))continue;let S=ge(e.get(b),t.prose);S.count>0&&o(b,"tokens","token file mentions the concept",S)}let R=[...i],A=new RegExp([...R.length?[`<(?:${R.map(de).join("|")})\\b`]:[],...t.elements.map(b=>`<${de(b)}\\b`),...t.roles.map(b=>`role=["']${de(b)}["']`)].join("|"));for(let b of n){if(!we.test(b)||a.has(b))continue;let S=e.get(b),_=Z.test(b),L=ge(S,A),M=Mn(S).some(O=>{let U=ve(b,O,s);return U!=null&&a.has(U)});if(L.count===0&&!M)continue;let F=L.count>0?`${L.count} render${L.count===1?"":"s"}`:"imports a button component";o(b,_?"tests":"uses",F,L.count?L:ge(S,t.prose))}for(let b of n){if(!(ro.test(b)||St.test(b)))continue;let _=e.get(b),L=ge(_,t.prose);L.count!==0&&o(b,Z.test(b)?"tests":"describes",St.test(b)?"repo rules / instructions":"documentation",L)}for(let b of n){if(!Z.test(b)||r.has(`tests:${b}`)||!we.test(b))continue;let S=ge(e.get(b),t.prose);S.count>0&&o(b,"tests","mentions the concept",S)}let P=[...r.values()].sort((b,S)=>S.matches-b.matches||b.path.localeCompare(S.path)),N={implements:0,styles:0,tokens:0,uses:0,describes:0,tests:0};for(let b of P)N[b.role]++;let V=Vr(c);On(e,n.filter(b=>so.test(b)&&!Z.test(b)),V,new Set(t.elements),!0,E,(b,S)=>ve(b,S,s)),On(e,n.filter(b=>so.test(b)&&!Z.test(b)),V.flatMap(b=>b.modifiers??[]),new Set(t.elements));for(let[b,S]of v.sites)b.usage=no(e,S,!("alike"in b));let X=Fc(e,n),tt=[];if(i.size>0){let b=new RegExp(t.elements.map(S=>`<${de(S)}\\b`).join("|"),"g");for(let S of n){if(!we.test(S)||Z.test(S)||a.has(S))continue;let _=e.get(S),L=(_.match(b)??[]).length;if(L===0)continue;let M=ge(_,new RegExp(b.source));tt.push({path:S,line:M.lines[0]?.line??1,count:L})}}let ts=[],ns=new Set;for(let b of n){if(!we.test(b)||Z.test(b))continue;let S=e.get(b),_=kt(b,S,E,(L,M)=>ve(L,M,s));for(let L of _)for(let M of L.unknown){let F=[...M.known].sort();if(M.cls!==void 0){if(g.has(M.cls))continue;let z=M.cls.slice(0,M.cls.length-M.value.length),ae=[...g].filter(D=>D.startsWith(z)&&D.length>z.length).map(D=>D.slice(z.length));if(ae.length===0)continue;F=[...new Set([...M.known,...ae])].sort()}if(F.length===0)continue;let O=Rc(S,L.offset),U=`${b}\0${L.component}\0${M.prop}\0${M.value}`;ns.has(U)||(ns.add(U),ts.push({path:b,line:O,component:L.component,prop:M.prop,value:M.value,known:F}))}}let ii=n.filter(b=>(ro.test(b)||St.test(b))&&!Z.test(b)).map(b=>({path:b,kind:Cc(b)}));V.sort((b,S)=>Number(S.base)-Number(b.base)||b.path.localeCompare(S.path)||b.line-S.line);let ss=Mr(e,ii,t,V),ai=Lr([...f.entries()].map(([b,S])=>({sheet:b,sources:S.map(_=>e.get(_)??""),rules:ke(e.get(b)??"").map(_=>({selector:_.selector,declarations:pe(_.ownBody)}))})));return{components:R.sort(),tokens:j,findings:P,variants:V,audit:mr({variants:V,tokens:j,tokenValues:X,hasComponent:i.size>0,nativeUses:tt,unknownProps:ts,guidance:ss,noun:t.label.toLowerCase(),element:t.elements[0]??t.id}),guidance:ss,content:ai,previewCss:Uc(X,u),counts:N}}import{execFileSync as zc}from"node:child_process";import{readdirSync as Wc,readFileSync as Gc,statSync as Hc}from"node:fs";import At from"node:path";function $e(e,t){try{return zc("git",t,{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],maxBuffer:64*1024*1024})}catch{return null}}function Tn(e,t=""){let s=$e(e,["rev-parse","--show-toplevel"])?.trim()||e;return{repoDir:s,root:sn(t),stateDir:At.join(s,".gruum")}}function _t(e){let t=At.join(e.repoDir,e.root),n=new Map,s=new TextDecoder("utf-8",{fatal:!1}),r=0,o=0,i=!1,a=(l,c)=>{if(i)return;let u;try{u=Wc(l).sort()}catch{return}for(let f of u){let m=c?`${c}/${f}`:f,h=At.join(l,f),w;try{w=Hc(h)}catch{continue}if(w.isDirectory()){tn(m)&&a(h,m);continue}if(!w.isFile())continue;if(!nn(m,w.size)){o++;continue}let C=Gc(h);if(Ks(C)){o++;continue}if(r+C.length>4e7){i=!0;return}r+=C.length,n.set(m,s.decode(C))}};return a(t,""),{files:n,truncated:i,skipped:o}}function mo(e,t){let n=$e(e.repoDir,["diff","--cached","--name-status","-z"]);if(n===null)return t;let s=qs(n).map(({path:r,deleted:o})=>({path:r,content:o?null:$e(e.repoDir,["show",`:${r}`])}));return{...t,files:Zs(t.files,s,e.root)}}function ho(e){let t=$e(e.repoDir,["remote","get-url","origin"])?.trim()??"",n=ct(t)??At.basename(e.repoDir),s=$e(e.repoDir,["rev-parse","HEAD"])?.trim()||"working-tree";return{fullName:n,ref:s,rootPath:e.root,htmlUrl:n.includes("/")?`https://github.com/${n}`:""}}function bo(e){let t=$e(e.repoDir,["config","--get","core.hooksPath"])?.trim();return t||$e(e.repoDir,["rev-parse","--git-path","hooks"])?.trim()||null}function It(e,t={}){let n=lo[t.concept??"button"],s=_t(e);return t.staged&&(s=mo(e,s)),{concept:n.id,label:n.label,...go(s.files,n),repo:ho(e),index:{files:s.files.size,truncated:s.truncated,skipped:s.skipped}}}function Ce(e,t,n={}){let s=It(e,{concept:t.concept,...n});return{result:s,baseline:t,items:gs(s,t)}}import{mkdirSync as Kc,readFileSync as Jc,writeFileSync as yo}from"node:fs";import oe from"node:path";function Se(e){try{return Jc(e,"utf8")}catch{return null}}function Et(e){let t=Se(e);if(t===null)return null;try{return JSON.parse(t)}catch{return null}}function me(e,t){Kc(oe.dirname(e),{recursive:!0}),yo(e,t)}function ie(e,t){me(e,`${JSON.stringify(t,null,2)}
59
59
  `),Zc(e)}function Zc(e){let t=e.split(oe.sep),n=t.lastIndexOf(".gruum");if(n<=0)return;let s=oe.join(t.slice(0,n).join(oe.sep),".gitignore"),r=ot(Se(s));r.changed&&(yo(s,r.text),process.stderr.write(`Added .gruum/ to .gitignore.
60
- `))}var Re=e=>oe.join(e.stateDir,"baseline.json"),xo=e=>oe.join(e.stateDir,"drift.json"),Bn=e=>oe.join(e.stateDir,"exceptions.json"),qc=e=>oe.join(e.stateDir,"config.json");function he(e,t){return Ue(Et(t?oe.resolve(t):Re(e)))}function jt(e){return bs(Et(xo(e)),new Date().toISOString())}function Fn(e,t){ie(xo(e),t)}function Xc(e){if(!e||typeof e!="object")return{};let t={};for(let[n,s]of Object.entries(e))(s==="pending"||s==="accepted"||s==="rejected")&&(t[n]=s);return t}function Pt(e){return Xc(Et(Bn(e)))}function Lt(e){let t=Et(qc(e)),{block:n,hooks:s}=ys(t);return{...typeof t?.root=="string"?{root:t.root}:{},block:n,hooks:s}}import{chmodSync as eu,mkdirSync as tu,readFileSync as Fo,writeFileSync as nu}from"node:fs";import{hostname as su,homedir as ru}from"node:os";import Wn from"node:path";import{createInterface as Uo}from"node:readline/promises";function ko(e){return`/v2/projects/${encodeURIComponent(e)}`}function Un(e,t,n,s){return!(!e||e.repo!==t||!e.workspaceId||!e.host&&s||n&&!n.includes(e.id))}function wo(e,t){if(e.length===0)return null;if(e.length===1)return e[0];let n=t.replace(/^\/+|\/+$/g,""),s=e.filter(r=>r.rootPath===n);if(s.length===1)return s[0];if(!n){let r=e.filter(o=>o.rootPath==="");if(r.length===1)return r[0]}return null}function vo(e){if(typeof e!="string")return{error:"Send a URL."};let t=e.trim();if(!t)return{error:"Enter a live URL."};if(!/^https:\/\//i.test(t))return{error:"URL must start with https://"};let n;try{n=new URL(t)}catch{return{error:"That doesn\u2019t look like a URL."}}if(n.protocol!=="https:")return{error:"URL must start with https://"};if(n.username||n.password)return{error:"That doesn\u2019t look like a URL."};let s=n.hostname.toLowerCase().replace(/^www\./,"");return!s||!s.includes(".")?{error:"That doesn\u2019t look like a URL."}:s==="localhost"||s==="127.0.0.1"?{error:"Public hosts only for Live URL (localhost needs the extension later)."}:{value:s}}var $o="http://localhost:3000";function Co(e){return((e.split("/").pop()||e).replace(/\.git$/i,"").split(/[-_]/)[0]??"").toLowerCase().replace(/[^a-z]/g,"")}function So(e,t){if(!/^[a-z]+$/.test(t))return null;let n=new RegExp(`https?://${t}\\.\\w{2,3}(?![\\w.])`,"gi"),s=null;for(let r of e.matchAll(n)){let o=r[0].toLowerCase();if(o.startsWith("https://"))return o;s??=o}return s}function Ro(e){let t=e?`For example: ${$o} or ${e}.`:`For example: ${$o}.`,n=e?`URL (${e}): `:"URL: ";return`
60
+ `))}var Re=e=>oe.join(e.stateDir,"baseline.json"),xo=e=>oe.join(e.stateDir,"drift.json"),Bn=e=>oe.join(e.stateDir,"exceptions.json"),qc=e=>oe.join(e.stateDir,"config.json");function he(e,t){return Ue(Et(t?oe.resolve(t):Re(e)))}function jt(e){return bs(Et(xo(e)),new Date().toISOString())}function Fn(e,t){ie(xo(e),t)}function Xc(e){if(!e||typeof e!="object")return{};let t={};for(let[n,s]of Object.entries(e))(s==="pending"||s==="accepted"||s==="rejected")&&(t[n]=s);return t}function Pt(e){return Xc(Et(Bn(e)))}function Lt(e){let t=Et(qc(e)),{block:n,hooks:s}=ys(t);return{...typeof t?.root=="string"?{root:t.root}:{},block:n,hooks:s}}import{chmodSync as eu,mkdirSync as tu,readFileSync as Fo,writeFileSync as nu}from"node:fs";import{hostname as su,homedir as ru}from"node:os";import Wn from"node:path";import{createInterface as Uo}from"node:readline/promises";function ko(e){return`/v2/projects/${encodeURIComponent(e)}`}function Un(e,t,n,s){return!(!e||e.repo!==t||!e.workspaceId||!e.host&&s||n&&!n.includes(e.id))}function wo(e,t){if(e.length===0)return null;if(e.length===1)return e[0];let n=t.replace(/^\/+|\/+$/g,""),s=e.filter(r=>r.rootPath===n);if(s.length===1)return s[0];if(!n){let r=e.filter(o=>o.rootPath==="");if(r.length===1)return r[0]}return null}function vo(e){if(typeof e!="string")return{error:"Send a URL."};let t=e.trim();if(!t)return{error:"Enter a live URL."};if(!/^https:\/\//i.test(t))return{error:"URL must start with https://"};let n;try{n=new URL(t)}catch{return{error:"That doesn\u2019t look like a URL."}}if(n.protocol!=="https:")return{error:"URL must start with https://"};if(n.username||n.password)return{error:"That doesn\u2019t look like a URL."};let s=n.hostname.toLowerCase().replace(/^www\./,"");return!s||!s.includes(".")?{error:"That doesn\u2019t look like a URL."}:s==="localhost"||s==="127.0.0.1"?{error:"Public hosts only for Live URL (localhost needs the extension later)."}:{value:s}}var $o="http://localhost:3000";function Co(e){return((e.split("/").pop()||e).replace(/\.git$/i,"").split(/[-_]/)[0]??"").toLowerCase().replace(/[^a-z]/g,"")}function So(e,t){if(!/^[a-z]+$/.test(t))return null;let n=new RegExp(`https?://(?:[a-z0-9-]+\\.)*${t}\\.\\w{2,3}(?![\\w.])`,"gi"),s=null;for(let r of e.matchAll(n)){let o=r[0].toLowerCase();if(o.startsWith("https://"))return o;s??=o}return s}function Ro(e){let t=e?`For example: ${$o} or ${e}.`:`For example: ${$o}.`,n=e?`URL (${e}): `:"URL: ";return`
61
61
  Live URL for this repo's website.
62
62
  ${t}
63
63
  You may not use wildcards.
64
64
 
65
- ${n}`}function Yc(e){let t=e.toLowerCase().replace(/:\d+$/,"");return t==="localhost"||t==="127.0.0.1"}function Ao(e){if(typeof e!="string")return{error:"Enter a live URL."};let t=e.trim();if(!t)return{error:"Enter a live URL."};if(t.includes("*"))return{error:"You may not use wildcards."};let n=Qc(t);if(n)return n;let s=/^[a-z][a-z0-9+.-]*:\/\//i.test(t)?t:`https://${t}`;return vo(s)}function Qc(e){let t=/^https?:\/\//i.test(e)?e:`http://${e}`,n;try{n=new URL(t)}catch{return null}let s=n.hostname.toLowerCase();if(s!=="localhost"&&s!=="127.0.0.1")return null;if(n.username||n.password)return{error:"That doesn\u2019t look like a URL."};let r=n.port;return{value:r&&r!=="80"&&r!=="443"?`${s}:${r}`:s}}function _o(e){return Yc(e)?`http://${e}`:`https://${e}`}function Io(e,t){let n=e.filter(r=>r.workspaces.length>0);if(n.length===0)return{step:"none"};if(t){let r=n.find(o=>o.id===t);if(!r)return{step:"none"};if(r.workspaces.length===1){let o=r.workspaces[0];return{step:"use",workspaceId:o.id,orgName:r.name,workspaceName:o.name}}return{step:"workspace",orgId:r.id,orgName:r.name,workspaces:r.workspaces}}if(n.reduce((r,o)=>r+o.workspaces.length,0)===1){let r=n[0],o=r.workspaces[0];return{step:"use",workspaceId:o.id,orgName:r.name,workspaceName:o.name}}if(n.length===1){let r=n[0];return{step:"workspace",orgId:r.id,orgName:r.name,workspaces:r.workspaces}}return{step:"org",orgs:n.map(r=>({id:r.id,name:r.name}))}}var Eo="No project for this repo found. Creating\u2026";function jo(e,t){let n=t.workspaceId;if(n)for(let s of e){let r=s.workspaces.find(o=>o.id===n);if(r)return`${s.name} / ${r.name} / ${t.name}`}return t.name}function Po(e){let t=e.length===1?`Use ${e[0]}, or create a new one.`:"This repo is already in more than one project. Use one, or create a new one.",s=[...e,"Create a new one"].map((r,o)=>` ${o+1} ${r}`);return`
65
+ ${n}`}function Yc(e){let t=e.toLowerCase().replace(/:\d+$/,"");return t==="localhost"||t==="127.0.0.1"}function Ao(e){if(typeof e!="string")return{error:"Enter a live URL."};let t=e.trim();if(!t)return{error:"Enter a live URL."};if(t.includes("*"))return{error:"You may not use wildcards."};let n=Qc(t);if(n)return n;let s=/^[a-z][a-z0-9+.-]*:\/\//i.test(t)?t:`https://${t}`;return vo(s)}function Qc(e){let t=/^https?:\/\//i.test(e)?e:`http://${e}`,n;try{n=new URL(t)}catch{return null}let s=n.hostname.toLowerCase();if(s!=="localhost"&&s!=="127.0.0.1")return null;if(n.username||n.password)return{error:"That doesn\u2019t look like a URL."};let r=n.port;return{value:r&&r!=="80"&&r!=="443"?`${s}:${r}`:s}}function _o(e){return Yc(e)?`http://${e}`:`https://${e}`}function Io(e,t){let n=e.filter(r=>r.workspaces.length>0);if(n.length===0)return{step:"none"};if(t){let r=n.find(o=>o.id===t);if(!r)return{step:"none"};if(r.workspaces.length===1){let o=r.workspaces[0];return{step:"use",workspaceId:o.id,orgName:r.name,workspaceName:o.name}}return{step:"workspace",orgId:r.id,orgName:r.name,workspaces:r.workspaces}}if(n.reduce((r,o)=>r+o.workspaces.length,0)===1){let r=n[0],o=r.workspaces[0];return{step:"use",workspaceId:o.id,orgName:r.name,workspaceName:o.name}}if(n.length===1){let r=n[0];return{step:"workspace",orgId:r.id,orgName:r.name,workspaces:r.workspaces}}return{step:"org",orgs:n.map(r=>({id:r.id,name:r.name}))}}var Eo="No project for this repo found. Creating\u2026";function jo(e,t){let n=t.workspaceId;if(n)for(let s of e){let r=s.workspaces.find(o=>o.id===n);if(r)return`${s.name} / ${r.name} / ${t.name}`}return t.name}function Po(e){let t=e.length===1?`Use ${e[0]}, or create a new one.`:"This repo is already in more than one project. Use one, or create a new one.",s=[...e,"Create a new one"].map((o,i)=>` ${i+1} ${o}`),r=e.length===1?"Which project should this checkout use? (1): ":"Which project should this checkout use? ";return`
66
66
  ${t}
67
67
  ${s.join(`
68
68
  `)}
69
69
 
70
- Which project should this checkout use? `}function Vn(e){return((e.split("/").pop()||e).replace(/\.git$/i,"").replace(/[^a-zA-Z0-9]+/g," ").trim().split(/\s+/).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join(" ")||"New workspace").slice(0,80)}function Lo(e,t){let n=t.trim().toLowerCase();if(!n)return null;let s=e.filter(r=>r.name.trim().toLowerCase()===n);return s.length===1?s[0]:null}function Oo(e,t,n){let s=[` C Create ${n}`,...t.map((r,o)=>` ${o+1} ${r.name}`)];return`
70
+ ${r}`}function Vn(e){return((e.split("/").pop()||e).replace(/\.git$/i,"").replace(/[^a-zA-Z0-9]+/g," ").trim().split(/\s+/).filter(Boolean).map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join(" ")||"New workspace").slice(0,80)}function Lo(e,t){let n=t.trim().toLowerCase();if(!n)return null;let s=e.filter(r=>r.name.trim().toLowerCase()===n);return s.length===1?s[0]:null}function Oo(e,t,n){let s=[` C Create ${n}`,...t.map((r,o)=>` ${o+1} ${r.name}`)];return`
71
71
  Select a workspace in ${e}, or create one.
72
72
  ${s.join(`
73
73
  `)}
@@ -82,7 +82,7 @@ Which ${n} should this project live in? `}function Do(e,t){let n=e.trim().toLowe
82
82
  `:"";process.stderr.write(n?`Created a Gruum project for ${t.repo}${o}.
83
83
  ${i}${r}
84
84
  `:`Gruum project: ${r}
85
- ${i}`)}function cu(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!="object")continue;let s=n;if(typeof s.id!="string"||typeof s.name!="string")continue;let r=Array.isArray(s.workspaces)?s.workspaces.flatMap(o=>{if(!o||typeof o!="object")return[];let i=o;return typeof i.id!="string"||typeof i.name!="string"?[]:[{id:i.id,name:i.name}]}):[];t.push({id:s.id,name:s.name,workspaces:r})}return t}async function Go(e,t,n){let s=Uo({input:process.stdin,output:process.stderr});_e(s);try{for(;;){let r=t(await s.question(e));if(r!=null)return r;process.stderr.write(n)}}finally{s.close()}}async function Ho(e,t){return Go(e,n=>Do(n,t),`gruum: enter one of the numbers.
85
+ ${i}`)}function cu(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!="object")continue;let s=n;if(typeof s.id!="string"||typeof s.name!="string")continue;let r=Array.isArray(s.workspaces)?s.workspaces.flatMap(o=>{if(!o||typeof o!="object")return[];let i=o;return typeof i.id!="string"||typeof i.name!="string"?[]:[{id:i.id,name:i.name}]}):[];t.push({id:s.id,name:s.name,workspaces:r})}return t}async function Go(e,t,n){let s=Uo({input:process.stdin,output:process.stderr});_e(s);try{for(;;){let r=t(await s.question(e));if(r!=null)return r;process.stderr.write(n)}}finally{s.close()}}async function Ho(e,t,n){return Go(e,s=>!s.trim()&&n!=null?n:Do(s,t),`gruum: enter one of the numbers.
86
86
  `)}async function Ko(e){let t=await K(e,"/api/v2/cli/workspaces");if(t.status===401)return process.stderr.write("gruum: sign-in expired. Run `npx @gruum/cli login` again.\n"),null;if(!t.ok)return process.stderr.write(`gruum: couldn't list workspaces (${t.status}).
87
87
  `),null;let n=await t.json();return cu(n.orgs)}async function uu(e,t,n,s){let r=s??await Ko(e);if(!r)return null;let o=null;for(;;){let i=Io(r,o);if(i.step==="none")return{workspaceId:"",label:""};if(i.step==="use")return{workspaceId:i.workspaceId,label:`${i.orgName} / ${i.workspaceName}`};if(i.step==="workspace"){let h=Lo(i.workspaces,Vn(n));if(h)return{workspaceId:h.id,label:`${i.orgName} / ${h.name}`}}if(!t)return process.stderr.write("gruum: this account has more than one workspace. Run `npx @gruum/cli check` in a terminal and choose where the project should live.\n"),null;if(i.step==="org"){let h=await Ho(No("This account has more than one organization.",i.orgs,"organization"),i.orgs);o=i.orgs[h].id;continue}let a=Vn(n),l=await Go(Oo(i.orgName,i.workspaces,a),h=>Mo(h,i.workspaces),`gruum: enter C, or one of the numbers.
88
88
  `);if(l!=="create"){let h=i.workspaces[l];return{workspaceId:h.id,label:`${i.orgName} / ${h.name}`}}let c=await K(e,"/api/v2/cli/workspaces",{method:"POST",body:JSON.stringify({orgId:i.orgId,name:a})}),u=await c.json().catch(()=>({})),f=u.workspace?.id,m=typeof u.workspace?.name=="string"?u.workspace.name:a;if(!c.ok||typeof f!="string"){process.stderr.write(`gruum: ${u.error||`couldn't create that workspace (${c.status})`}
@@ -97,7 +97,7 @@ Waiting for confirmation\u2026
97
97
  `);let r=Date.now()+600*1e3;for(;Date.now()<r;){await new Promise(a=>setTimeout(a,2e3));let o=await K(null,`/api/cli/pair/poll?pairingId=${encodeURIComponent(n.pairingId)}&verifier=${encodeURIComponent(n.verifier)}`);if(!o.ok)continue;let i=await o.json();if(i.status==="expired")return process.stderr.write("gruum: that code expired. Run `npx @gruum/cli login` again.\n"),1;if(i.status==="connected"&&i.token)return iu({token:i.token,apiOrigin:Ne}),process.stdout.write(`Signed in. This CLI can read specs for your projects.
98
98
  `),0}return process.stderr.write("gruum: sign-in timed out. Run `npx @gruum/cli login` again.\n"),1}function zn(e){if(!e||typeof e!="object")return null;let t=e;return typeof t.id!="string"||typeof t.repo!="string"?null:{id:t.id,name:typeof t.name=="string"?t.name:t.repo,repo:t.repo,rootPath:typeof t.rootPath=="string"?t.rootPath:"",host:typeof t.host=="string"&&t.host?t.host:null,workspaceId:typeof t.workspaceId=="string"&&t.workspaceId?t.workspaceId:null}}async function Jn(e,t){let n=au(e.repoDir);if(!n)return process.stderr.write(`gruum: this folder has no GitHub origin, so it can't be matched to a Gruum project.
99
99
  `),null;let s=!!process.stdin.isTTY,r=lu(e),o=Ot(t),i=await K(t,`/api/v2/cli/projects?repo=${encodeURIComponent(n)}`);if(i.status===401)return process.stderr.write("gruum: sign-in expired. Run `npx @gruum/cli login` again.\n"),null;if(!i.ok)return Un(r,n,null,s)?r:null;let a=await i.json(),l=Array.isArray(a.projects)?a.projects.map(zn).filter($=>$!==null):[];if(Un(r,n,l.map($=>$.id),s))return r;if(!!r&&r.repo===n&&!!r.workspaceId&&!!(r.host||!s)&&(process.stderr.write(`gruum: the saved project was not found. Do not edit .gruum/project.json.
100
- `),l.length===0&&!s))return process.stderr.write("gruum: this repo has no project this sign-in can see. Run `npx @gruum/cli check` in a terminal to choose one.\n"),null;let u=!1,f="",m;if(l.length>0&&s){let $=await Ko(t);if(!$)return null;m=$;let g=l.map(y=>jo($,y)),p=[...g.map(y=>({name:y})),{name:"Create a new one"}],d=await Ho(Po(g),p);d===g.length?(l=[],process.stderr.write(`Creating\u2026
100
+ `),l.length===0&&!s))return process.stderr.write("gruum: this repo has no project this sign-in can see. Run `npx @gruum/cli check` in a terminal to choose one.\n"),null;let u=!1,f="",m;if(l.length>0&&s){let $=await Ko(t);if(!$)return null;m=$;let g=l.map(y=>jo($,y)),p=[...g.map(y=>({name:y})),{name:"Create a new one"}],d=await Ho(Po(g),p,g.length===1?0:void 0);d===g.length?(l=[],process.stderr.write(`Creating\u2026
101
101
  `)):l=[l[d]]}if(l.length===0){m||process.stderr.write(`${Eo}
102
102
  `);let $=await uu(t,s,n,m);if(!$)return null;let g=await K(t,"/api/v2/cli/projects",{method:"POST",body:JSON.stringify({repo:n,rootPath:e.root,...$.workspaceId?{workspaceId:$.workspaceId}:{}})}),p=await g.json().catch(()=>({}));typeof p.place?.org=="string"&&typeof p.place.workspace=="string"?f=`${p.place.org} / ${p.place.workspace}`:f=$.label;let d=zn(p.project);if(u=p.created!==!1,!g.ok||!d){let y=typeof p.path=="string"?p.path:"";return process.stderr.write(`gruum: ${p.error||`couldn't create a project (${g.status})`}
103
103
  `),y&&process.stderr.write(`${o}${y}
@@ -119,7 +119,7 @@ ${Kn(Ot(s),r.id)}
119
119
  `)}catch{process.stderr.write(`gruum: couldn't reach Gruum to report this check. The local result still stands.
120
120
  `)}}async function qo(e,t,n){let s=await qn(e);if(!s)return{ok:!1,text:"Sign in with gruum login before requesting an exception."};let r=Mt(e.repoDir);if(!r)return{ok:!1,text:"This folder is not on a named git branch."};try{let o=await K(s.credentials,`/api/v2/cli/projects/${encodeURIComponent(s.project.id)}/drift`,{method:"POST",body:JSON.stringify({action:"request",concept:"button",branch:r,commit:zo(e.repoDir),reason:n,item:t})}),i=await o.json().catch(()=>({}));if(!o.ok){let c=i.error||`Request failed (${o.status}).`;return{ok:!1,text:o.status===404?`${c} Run \`npx @gruum/cli check\` so this folder points at a project that exists. Do not edit .gruum/project.json.`:c}}let a=i.reviewUrl?`${Ot(s.credentials)}${i.reviewUrl}`:"",l=i.created?`Exception request ${i.id} is pending review.`:`An exception for this change is already pending (${i.id}).`;return{ok:!0,text:a?`${l}
121
121
  ${a}`:l}}catch{return{ok:!1,text:"Couldn't reach Gruum to request an exception."}}}async function Xo(e,t){let n=await qn(e);if(!n)return{ok:!1,text:"Sign in with gruum login to see exception status."};let s=Mt(e.repoDir);try{let r=await K(n.credentials,`/api/v2/cli/projects/${encodeURIComponent(n.project.id)}/drift?concept=button&branch=${encodeURIComponent(s)}`);if(!r.ok)return{ok:!1,text:`Couldn't load exceptions (${r.status}).`};let o=await r.json(),i=Array.isArray(o.requests)?o.requests:[],a=t?i.filter(l=>l.id===t):i;return a.length===0?{ok:!0,text:t?`No exception request ${t} on ${s||"this branch"}.`:`No exception requests on ${s||"this branch"}.`}:{ok:!0,text:a.map(l=>`${l.id} ${l.status} ${l.title} (${l.branch})`).join(`
122
- `)}}catch{return{ok:!1,text:"Couldn't reach Gruum to read exception status."}}}var Dt="0.1.23",Yo=`gruum ${Dt}: keep buttons on the Gruum spec
122
+ `)}}catch{return{ok:!1,text:"Couldn't reach Gruum to read exception status."}}}var Dt="0.2.2",Yo=`gruum ${Dt}: keep buttons on the Gruum spec
123
123
 
124
124
  Run it as \`npx @gruum/cli <command>\`.
125
125
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gruum/cli",
3
- "version": "0.1.23",
3
+ "version": "0.2.2",
4
4
  "description": "Keep buttons on the Gruum spec: a local drift check, Cursor hooks, and an MCP server.",
5
5
  "keywords": [
6
6
  "design",