craig-cli 0.8.3 → 0.8.4

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/dist/cli.js +1 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  var Vl=Object.defineProperty;var Lt=(e,t)=>{for(var r in t)Vl(e,r,{get:t[r],enumerable:!0})};import{readFile as Ql}from"node:fs/promises";import{randomUUID as Kl}from"node:crypto";import{open as Hl,readFile as tg,rename as Gl,rm as zl}from"node:fs/promises";import xr from"node:path";async function N(e,t){let r=xr.dirname(e),n=xr.join(r,`.${xr.basename(e)}.${process.pid}.${Date.now()}.${Kl()}.tmp`),s=await Hl(n,"w");try{let o=`${JSON.stringify(t,null,2)}
3
3
  `;await s.writeFile(o,"utf8"),await s.sync(),await s.close(),await Gl(n,e)}catch(o){throw await s.close().catch(()=>{}),await zl(n,{force:!0}).catch(()=>{}),o}}async function _e(e){try{let t=await Ql(e.uiStateFile,"utf8"),r=JSON.parse(t);return Yl(r,e.uiStateFile)}catch(t){if(Xl(t))return null;throw t}}async function Te(e,t){await N(e.uiStateFile,{...t,updatedAt:new Date().toISOString()})}function jt(){return{version:1,selectedRepoId:null,selectedWorkspaceId:null,selectedTaskId:null,selectedPtyTabId:null,inputMode:"control",focusedRegion:"tasks",activeTab:"agent",inspectorSection:"task",inspectionMode:"files",openInspectionKind:null,selectedFileTreePath:null,selectedFilePath:null,selectedDiffPath:null,collapsedFileTreePaths:[],selectedActionId:"commit",updatedAt:new Date().toISOString()}}function Yl(e,t){if(typeof e!="object"||e===null||e.version!==1||!(e.selectedRepoId===null||typeof e.selectedRepoId=="string")||!(e.selectedWorkspaceId===null||typeof e.selectedWorkspaceId=="string")||!(e.selectedTaskId===null||typeof e.selectedTaskId=="string")||!(e.selectedPtyTabId===void 0||e.selectedPtyTabId===null||typeof e.selectedPtyTabId=="string")||!We(e,"inputMode")||!We(e,"focusedRegion")||!We(e,"activeTab")||!We(e,"inspectorSection")||!We(e,"inspectionMode")||!Ot(e,"openInspectionKind")||!Ot(e,"selectedFileTreePath")||!Ot(e,"selectedFilePath")||!Ot(e,"selectedDiffPath")||!Jl(e,"collapsedFileTreePaths")||!We(e,"selectedActionId")||typeof e.updatedAt!="string")throw new Error(`Craig UI state at ${t} is invalid. Remove or repair the file before rerunning Craig.`);return e}function We(e,t){return typeof e=="object"&&e!==null&&(!(t in e)||typeof e[t]=="string")}function Ot(e,t){return typeof e=="object"&&e!==null&&(!(t in e)||e[t]===null||typeof e[t]=="string")}function Jl(e,t){return typeof e=="object"&&e!==null&&(!(t in e)||Array.isArray(e[t])&&e[t].every(r=>typeof r=="string"))}function Xl(e){return typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="string"&&e.code==="ENOENT"}var Dr={};Lt(Dr,{RUNNER_IDS:()=>$,assertEnabled:()=>$s,buildCommand:()=>Os,getConfiguredProfile:()=>Ft,getDefault:()=>Ds,getDisplayName:()=>Ls,getEnabled:()=>Nt,getProfile:()=>Ue,isRunnerType:()=>Wt,parse:()=>Ms,setRunnerEnabled:()=>js,setRunnerPath:()=>Fs});var $=["codex","cursor","claude"];var xs={codex:{id:"codex",displayName:"Codex",executable:"codex",defaultAgentTitle:"Codex"},cursor:{id:"cursor",displayName:"Cursor",executable:"cursor-agent",defaultAgentTitle:"Cursor"},claude:{id:"claude",displayName:"Claude",executable:"claude",defaultAgentTitle:"Claude"}};var Ue=e=>xs[e];var Ft=(e,t={})=>{let r=Ue(e),n=t.runners?.[e]?.path?.trim();return{...r,executable:n&&n.length>0?n:r.executable}};var Nt=(e={})=>$.filter(t=>e.runners?.[t]?.enabled!==!1);var Ds=(e={})=>{let t=Nt(e);if(t.length===0)throw new Error("No runners are enabled. Enable at least one runner in .craig/config.json.");return t.includes("codex")?"codex":t[0]};var $s=(e,t={})=>{if(t.runners?.[e]?.enabled===!1)throw new Error(`Runner "${e}" is disabled in .craig/config.json.`)};var Wt=e=>$.includes(e);var Ms=e=>{if(!e||e.length===0)return"codex";if(!Wt(e))throw new Error(`Unsupported runner "${e}". Expected one of: ${$.join(", ")}.`);return e};var Ls=e=>Ue(e).displayName;var Os=(e,t,r={})=>{let n=[Ft(e,r).executable];return t&&t.length>0&&n.push(t),n};var js=(e,t,r)=>({...e,runners:{...e.runners??{},[t]:{...e.runners?.[t]??{},enabled:r}}});var Fs=(e,t,r)=>{let n=e.runners?.[t]??{},{path:s,...o}=n;return{...e,runners:{...e.runners??{},[t]:r!=null?{...n,path:r}:o}}};var $r={};Lt($r,{PREVIEW_FEATURE_IDS:()=>se,isEnabled:()=>Ns,setEnabled:()=>Ws});var se=["incrementalCenterPane"];function Ns(e,t){return e.previews?.[t]===!0}function Ws(e,t,r){return{...e,previews:{...e.previews,[t]:r}}}import{mkdir as Zl,readFile as ec,writeFile as tc}from"node:fs/promises";import rc from"node:path";var nc=e=>typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="string"&&e.code==="ENOENT",_s=async e=>{try{return await ec(e,"utf8")}catch(t){if(nc(t))return null;throw t}},Us=async(e,t)=>{await Zl(rc.dirname(e),{recursive:!0}),await tc(e,t,"utf8")};var _t=(e,t)=>{if(typeof e!="object"||e===null)throw new Error(`Craig config at ${t} is invalid. Expected a JSON object.`);let r=e;if(r.runners!==void 0){if(typeof r.runners!="object"||r.runners===null||Array.isArray(r.runners))throw new Error(`Craig config at ${t} is invalid. "runners" must be an object.`);for(let[n,s]of Object.entries(r.runners)){if(!$.includes(n))throw new Error(`Craig config at ${t} is invalid. "runners.${n}" is not supported. Expected one of: ${$.join(", ")}.`);if(typeof s!="object"||s===null||Array.isArray(s))throw new Error(`Craig config at ${t} is invalid. "runners.${n}" must be an object.`);let o=s;if(o.enabled!==void 0&&typeof o.enabled!="boolean")throw new Error(`Craig config at ${t} is invalid. "runners.${n}.enabled" must be a boolean.`);if(o.path!==void 0&&(typeof o.path!="string"||o.path.trim().length===0))throw new Error(`Craig config at ${t} is invalid. "runners.${n}.path" must be a non-empty string.`)}}if(r.checks!==void 0&&(typeof r.checks!="object"||r.checks===null||!Array.isArray(r.checks.commands)||!r.checks.commands.every(n=>typeof n=="string")))throw new Error(`Craig config at ${t} is invalid. "checks.commands" must be an array of strings.`);if(r.open!==void 0&&(typeof r.open!="object"||r.open===null||!Array.isArray(r.open.command)||!r.open.command.every(n=>typeof n=="string")))throw new Error(`Craig config at ${t} is invalid. "open.command" must be an array of strings.`);if(r.github!==void 0){if(typeof r.github!="object"||r.github===null)throw new Error(`Craig config at ${t} is invalid. "github" must be an object.`);if(r.github.mergeMethod!==void 0&&r.github.mergeMethod!=="merge"&&r.github.mergeMethod!=="rebase"&&r.github.mergeMethod!=="squash")throw new Error(`Craig config at ${t} is invalid. "github.mergeMethod" must be "merge", "rebase", or "squash".`);if(r.github.watchIntervalSeconds!==void 0&&(!Number.isInteger(r.github.watchIntervalSeconds)||r.github.watchIntervalSeconds<=0))throw new Error(`Craig config at ${t} is invalid. "github.watchIntervalSeconds" must be a positive integer.`)}if(r.previews!==void 0){if(typeof r.previews!="object"||r.previews===null||Array.isArray(r.previews))throw new Error(`Craig config at ${t} is invalid. "previews" must be an object.`);for(let[n,s]of Object.entries(r.previews)){if(!se.includes(n))throw new Error(`Craig config at ${t} is invalid. "previews.${n}" is not supported. Expected one of: ${se.join(", ")}.`);if(typeof s!="boolean")throw new Error(`Craig config at ${t} is invalid. "previews.${n}" must be a boolean.`)}}return r};var Mr=async(e,t={readConfigFile:_s})=>{let r=await t.readConfigFile(e.configFile);if(!r)return{};if(r.trimStart()[0]!=="{")throw new Error(`Craig config at ${e.configFile} is malformed. Remove or repair the file before rerunning Craig.`);let n;try{n=JSON.parse(r)}catch{throw new Error(`Craig config at ${e.configFile} is malformed. Remove or repair the file before rerunning Craig.`)}return _t(n,e.configFile)};var Lr=async(e,t,r={writeConfigFile:Us})=>{_t(t,e.configFile),await r.writeConfigFile(e.configFile,`${JSON.stringify(t,null,2)}
4
- `)};var Or={};Lt(Or,{checkForUpdate:()=>qs,getCurrent:()=>Ut});var Ut=()=>{try{return"0.8.3"}catch{return"unknown"}};var sc="https://registry.npmjs.org/craig-cli/latest",oc=3600*1e3,ic={value:null},ac=(e,t)=>{let r=c=>c.split(".").map(Number),[n=0,s=0,o=0]=r(e),[i=0,a=0,l=0]=r(t);return n!==i?n>i:s!==a?s>a:o>l},qs=async(e={fetch:globalThis.fetch,getCurrent:Ut,cache:ic})=>{let t=e.getCurrent(),r=Date.now();if(e.cache.value&&r-e.cache.value.cachedAt<oc)return e.cache.value.result;let n=null;try{let o=await e.fetch(sc,{signal:AbortSignal.timeout(5e3)});o.ok&&(n=(await o.json()).version??null)}catch{}let s={current:t,latest:n,updateAvailable:n!==null&&n!==t&&ac(n,t)};return e.cache.value={result:s,cachedAt:r},s};var h={load:Mr,save:Lr,previews:$r,runners:Dr,version:Or};function Bs(e){let t=[...e];for(;t[0]==="--";)t.shift();if(t.length===0)return{mode:"interactive"};if(t.length>=3&&t[0]==="repo"&&t[1]==="add"){let r=t.slice(2).join(" ").trim();if(r.length===0)throw new Error(`Repo path cannot be empty.
4
+ `)};var Or={};Lt(Or,{checkForUpdate:()=>qs,getCurrent:()=>Ut});var Ut=()=>{try{return"0.8.4"}catch{return"unknown"}};var sc="https://registry.npmjs.org/craig-cli/latest",oc=3600*1e3,ic={value:null},ac=(e,t)=>{let r=c=>c.split(".").map(Number),[n=0,s=0,o=0]=r(e),[i=0,a=0,l=0]=r(t);return n!==i?n>i:s!==a?s>a:o>l},qs=async(e={fetch:globalThis.fetch,getCurrent:Ut,cache:ic})=>{let t=e.getCurrent(),r=Date.now();if(e.cache.value&&r-e.cache.value.cachedAt<oc)return e.cache.value.result;let n=null;try{let o=await e.fetch(sc,{signal:AbortSignal.timeout(5e3)});o.ok&&(n=(await o.json()).version??null)}catch{}let s={current:t,latest:n,updateAvailable:n!==null&&n!==t&&ac(n,t)};return e.cache.value={result:s,cachedAt:r},s};var h={load:Mr,save:Lr,previews:$r,runners:Dr,version:Or};function Bs(e){let t=[...e];for(;t[0]==="--";)t.shift();if(t.length===0)return{mode:"interactive"};if(t.length>=3&&t[0]==="repo"&&t[1]==="add"){let r=t.slice(2).join(" ").trim();if(r.length===0)throw new Error(`Repo path cannot be empty.
5
5
 
6
6
  `+H());return{mode:"command",command:{kind:"addRepo",path:r}}}if(t.length>=3&&t[0]==="workspace"&&t[1]==="add"){let r=t.slice(2).join(" ").trim();if(r.length===0)throw new Error(`Workspace path cannot be empty.
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craig-cli",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Craig local control plane CLI",
5
5
  "license": "MIT",
6
6
  "keywords": [