@crewx/sdk 0.9.0-rc.9 → 0.9.0-rc.91

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 (192) hide show
  1. package/README.md +1 -1
  2. package/dist/account/auth-client.d.ts +61 -0
  3. package/dist/account/auth-json-v2.d.ts +1 -0
  4. package/dist/account/auth-json.d.ts +30 -0
  5. package/dist/account/config.d.ts +8 -0
  6. package/dist/account/errors.d.ts +24 -0
  7. package/dist/account/index.d.ts +10 -0
  8. package/dist/account/index.js +1 -0
  9. package/dist/account/session-manager.d.ts +47 -0
  10. package/dist/activity-log/builder.d.ts +55 -6
  11. package/dist/config/canonicalize-agent-options.d.ts +17 -0
  12. package/dist/config/global-settings.d.ts +33 -0
  13. package/dist/config/migrate-grok-mode.d.ts +6 -0
  14. package/dist/config/model-compat.d.ts +31 -0
  15. package/dist/config/models.generated.d.ts +37 -0
  16. package/dist/config/models.remote.d.ts +1 -0
  17. package/dist/config/overdrive.d.ts +7 -0
  18. package/dist/config/pricing.d.ts +8 -5
  19. package/dist/config/pricing.generated.d.ts +4 -0
  20. package/dist/config/pricing.types.d.ts +4 -10
  21. package/dist/config/timeout.config.d.ts +3 -0
  22. package/dist/config/wi-boards.d.ts +19 -0
  23. package/dist/context-budget/continuity.d.ts +61 -0
  24. package/dist/context-budget/index.d.ts +140 -0
  25. package/dist/conversation/index.d.ts +1 -1
  26. package/dist/conversation/sqlite-provider.d.ts +5 -1
  27. package/dist/conversation/to-template-messages.d.ts +7 -0
  28. package/dist/conversation/types.d.ts +43 -0
  29. package/dist/desktop/command-runner.d.ts +4 -0
  30. package/dist/desktop/default-adapters.d.ts +4 -0
  31. package/dist/desktop/global-install.d.ts +19 -0
  32. package/dist/desktop/index.d.ts +2 -0
  33. package/dist/desktop/index.js +3 -0
  34. package/dist/desktop/install.d.ts +5 -0
  35. package/dist/desktop/lnk.d.ts +22 -0
  36. package/dist/desktop/manifest.d.ts +21 -0
  37. package/dist/desktop/types.d.ts +67 -0
  38. package/dist/desktop/version.d.ts +1 -0
  39. package/dist/desktop/windows-paths.d.ts +21 -0
  40. package/dist/desktop/wrapper.d.ts +18 -0
  41. package/dist/esm/account/index.js +1 -0
  42. package/dist/esm/desktop/index.js +3 -0
  43. package/dist/esm/index.js +354 -99
  44. package/dist/esm/plugins/index.js +213 -103
  45. package/dist/esm/publish/index.js +1 -0
  46. package/dist/esm/repository/index.js +200 -94
  47. package/dist/esm/testing/index.js +1 -1
  48. package/dist/events/types.d.ts +4 -0
  49. package/dist/facade/Crewx.d.ts +40 -2
  50. package/dist/highlight/thread-highlight-prompt.d.ts +2 -0
  51. package/dist/highlight/thread-highlighter.d.ts +326 -0
  52. package/dist/index.browser.d.ts +11 -1
  53. package/dist/index.browser.js +6 -2
  54. package/dist/index.d.ts +73 -11
  55. package/dist/index.js +354 -99
  56. package/dist/internal/console-decoder.d.ts +38 -0
  57. package/dist/internal/windows-spawn.d.ts +10 -0
  58. package/dist/layout/types.d.ts +17 -1
  59. package/dist/local-server/base-url.d.ts +18 -0
  60. package/dist/local-server/index.d.ts +8 -0
  61. package/dist/local-server/opencode.d.ts +8 -0
  62. package/dist/local-server/probe.d.ts +3 -0
  63. package/dist/local-server/runtime.d.ts +26 -0
  64. package/dist/local-server/types.d.ts +43 -0
  65. package/dist/migrations/0008_careful_black_bird.sql +17 -0
  66. package/dist/migrations/0009_hot_dark_phoenix.sql +1 -0
  67. package/dist/migrations/0010_analyze_stats.sql +6 -0
  68. package/dist/migrations/0011_far_black_tarantula.sql +1 -0
  69. package/dist/migrations/0012_blue_turbo.sql +23 -0
  70. package/dist/migrations/0013_hesitant_adam_destine.sql +15 -0
  71. package/dist/migrations/0014_organic_mongu.sql +73 -0
  72. package/dist/migrations/0015_panoramic_gorilla_man.sql +71 -0
  73. package/dist/migrations/0016_fuzzy_hemingway.sql +14 -0
  74. package/dist/migrations/0017_project_stage_sdk_migration.sql +29 -0
  75. package/dist/migrations/0018_bored_jackal.sql +33 -0
  76. package/dist/migrations/0019_backfill_task_thread_ids.sql +74 -0
  77. package/dist/migrations/0020_useful_iron_lad.sql +55 -0
  78. package/dist/migrations/0021_dashing_peter_quill.sql +51 -0
  79. package/dist/migrations/0022_wandering_bucky.sql +1 -0
  80. package/dist/migrations/0023_red_payback.sql +1 -0
  81. package/dist/migrations/meta/0008_snapshot.json +1327 -0
  82. package/dist/migrations/meta/0009_snapshot.json +1335 -0
  83. package/dist/migrations/meta/0010_snapshot.json +1335 -0
  84. package/dist/migrations/meta/0011_snapshot.json +1342 -0
  85. package/dist/migrations/meta/0012_snapshot.json +1494 -0
  86. package/dist/migrations/meta/0013_snapshot.json +1592 -0
  87. package/dist/migrations/meta/0014_snapshot.json +1975 -0
  88. package/dist/migrations/meta/0015_snapshot.json +2315 -0
  89. package/dist/migrations/meta/0016_snapshot.json +2419 -0
  90. package/dist/migrations/meta/0017_snapshot.json +2419 -0
  91. package/dist/migrations/meta/0018_snapshot.json +2570 -0
  92. package/dist/migrations/meta/0020_snapshot.json +2895 -0
  93. package/dist/migrations/meta/0021_snapshot.json +3031 -0
  94. package/dist/migrations/meta/0022_snapshot.json +3039 -0
  95. package/dist/migrations/meta/0023_snapshot.json +3047 -0
  96. package/dist/migrations/meta/_journal.json +112 -0
  97. package/dist/paths.d.ts +1 -0
  98. package/dist/plugin/types.d.ts +1 -0
  99. package/dist/plugins/index.js +213 -103
  100. package/dist/plugins/sqlite-tracing.d.ts +23 -0
  101. package/dist/provider/acp/connection.d.ts +6 -0
  102. package/dist/provider/acp/meta.d.ts +11 -0
  103. package/dist/provider/bridge.d.ts +6 -0
  104. package/dist/provider/classify-task-error.d.ts +2 -0
  105. package/dist/provider/cli/adapter.types.d.ts +8 -1
  106. package/dist/provider/cli/adapters/agent-call.util.d.ts +1 -1
  107. package/dist/provider/cli/adapters/cli-knob.util.d.ts +7 -0
  108. package/dist/provider/cli/adapters/grok.d.ts +2 -0
  109. package/dist/provider/cli/adapters/index.d.ts +1 -0
  110. package/dist/provider/cli/index.d.ts +1 -1
  111. package/dist/provider/cli/meta.d.ts +5 -0
  112. package/dist/provider/cli/protocol-envelope.d.ts +2 -0
  113. package/dist/provider/errors.d.ts +1 -0
  114. package/dist/provider/idle-watchdog.d.ts +19 -0
  115. package/dist/provider/models.d.ts +17 -12
  116. package/dist/provider/order.d.ts +1 -1
  117. package/dist/provider/parse-usage.d.ts +6 -0
  118. package/dist/provider/provider-selection.d.ts +8 -0
  119. package/dist/provider/redact-technical-message.d.ts +1 -0
  120. package/dist/provider/task-error.types.d.ts +16 -0
  121. package/dist/publish/constants.d.ts +6 -0
  122. package/dist/publish/index.d.ts +26 -0
  123. package/dist/publish/index.js +1 -0
  124. package/dist/publish/manifest.d.ts +17 -0
  125. package/dist/publish/marketplace-api.constants.d.ts +1 -0
  126. package/dist/publish/pack.d.ts +2 -0
  127. package/dist/publish/scan.d.ts +9 -0
  128. package/dist/publish/secrets.d.ts +6 -0
  129. package/dist/publish/upload.d.ts +18 -0
  130. package/dist/remote/execution-profile.d.ts +9 -0
  131. package/dist/remote/index.d.ts +1 -0
  132. package/dist/remote/types.d.ts +28 -0
  133. package/dist/repository/agent-suggestion.repository.d.ts +34 -0
  134. package/dist/repository/common-code.repository.d.ts +45 -0
  135. package/dist/repository/db.d.ts +8 -0
  136. package/dist/repository/index.d.ts +28 -4
  137. package/dist/repository/index.js +200 -94
  138. package/dist/repository/notification.repository.d.ts +58 -0
  139. package/dist/repository/project.repository.d.ts +90 -0
  140. package/dist/repository/request-log.repository.d.ts +1 -0
  141. package/dist/repository/task-log-migration.d.ts +74 -0
  142. package/dist/repository/task-log.repository.d.ts +44 -0
  143. package/dist/repository/task.repository.d.ts +120 -0
  144. package/dist/repository/thread-history.repository.d.ts +193 -0
  145. package/dist/repository/thread-title-common-code-migration.d.ts +13 -0
  146. package/dist/repository/thread-title.types.d.ts +29 -0
  147. package/dist/repository/thread.repository.d.ts +21 -2
  148. package/dist/repository/usage-report.repository.d.ts +27 -0
  149. package/dist/repository/workspace.repository.d.ts +3 -0
  150. package/dist/schema/agent-suggestions.d.ts +199 -0
  151. package/dist/schema/common-codes.d.ts +216 -0
  152. package/dist/schema/index.d.ts +9 -0
  153. package/dist/schema/notifications.d.ts +303 -0
  154. package/dist/schema/projects.d.ts +610 -0
  155. package/dist/schema/task-log-events.d.ts +119 -0
  156. package/dist/schema/tasks.d.ts +53 -0
  157. package/dist/schema/thread-history.d.ts +734 -0
  158. package/dist/schema/threads.d.ts +2 -0
  159. package/dist/schema/ui-action-receipts.d.ts +303 -0
  160. package/dist/schema/ui-instances.d.ts +267 -0
  161. package/dist/schema/usage-reports.d.ts +252 -0
  162. package/dist/schema/workspaces.d.ts +17 -0
  163. package/dist/task-log/anchor-child-tasks.d.ts +7 -0
  164. package/dist/task-log/delegation-trailer.d.ts +34 -0
  165. package/dist/testing/index.js +1 -1
  166. package/dist/types/index.d.ts +1536 -3
  167. package/dist/types/task-log.types.d.ts +2 -0
  168. package/dist/ui-card/index.d.ts +2 -0
  169. package/dist/ui-card/legacy-card-parser.d.ts +11 -0
  170. package/dist/ui-instance/definition.d.ts +6 -0
  171. package/dist/ui-instance/errors.d.ts +17 -0
  172. package/dist/ui-instance/index.d.ts +6 -0
  173. package/dist/ui-instance/json.d.ts +5 -0
  174. package/dist/ui-instance/runtime.d.ts +13 -0
  175. package/dist/ui-instance/store.d.ts +65 -0
  176. package/dist/ui-instance/types.d.ts +200 -0
  177. package/dist/ui-plugin/index.d.ts +3 -0
  178. package/dist/ui-plugin/manifest.d.ts +3 -0
  179. package/dist/ui-plugin/types.d.ts +76 -0
  180. package/dist/ui-plugin/validator.d.ts +9 -0
  181. package/dist/utils/crewx-executable.d.ts +54 -0
  182. package/dist/utils/crewx-home.d.ts +1 -0
  183. package/dist/utils/env-defaults.d.ts +2 -0
  184. package/dist/utils/id.d.ts +1 -1
  185. package/dist/utils/timestamp.d.ts +1 -0
  186. package/dist/wi/create.d.ts +48 -0
  187. package/dist/wi/select.d.ts +20 -0
  188. package/package.json +25 -2
  189. package/templates/agents/default.yaml +244 -120
  190. package/templates/documents/crewx-manual.md +138 -138
  191. package/templates/workflows/wi-default-flow.yaml +65 -0
  192. package/templates/workflows/wi-plan-flow.yaml +140 -0
@@ -0,0 +1,3 @@
1
+ import*as f from'path';import f__default,{join}from'path';import {fileURLToPath}from'url';import {createHash}from'crypto';import {readFileSync,unlinkSync,mkdirSync,writeFileSync,existsSync,statSync}from'fs';import {homedir}from'os';import {execFile,spawn}from'child_process';import {StringDecoder}from'string_decoder';import {createRequire}from'module';var M=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var z=()=>fileURLToPath(import.meta.url),Fe=()=>f__default.dirname(z()),S=Fe(),P=z();var h=class extends Error{code;constructor(t,n){super(`${t}: ${n}`),this.code=t,this.name="ShortcutError";}};var Y={existsSync:e=>existsSync(e),readFileSync:e=>readFileSync(e,"utf8"),readBinaryFileSync:e=>new Uint8Array(readFileSync(e)),writeFileSync:(e,t)=>writeFileSync(e,t,"utf8"),mkdirSync:e=>{mkdirSync(e,{recursive:true});},unlinkSync:e=>{unlinkSync(e);}},Q=homedir;function O(e){return typeof e!="string"?void 0:e.trim()||void 0}function D(e){return O(e)?.toLowerCase()??""}function k(e){try{return statSync(e).isFile()}catch{return false}}function Xe(e,t){if(e===t)return true;let n=f__default.relative(e,t);return n!==""&&!n.startsWith("..")&&!f__default.isAbsolute(n)}function Ge(e,t){if(f__default.basename(e)!==".bin")return false;let n=f__default.dirname(e);if(f__default.basename(n)!=="node_modules")return false;let r=f__default.dirname(n);return Xe(r,t)}function Z(e,t={}){if(e.includes("/")||e.includes("\\")||f__default.isAbsolute(e))return e;let n=t.platform??process.platform,r=t.env??process.env,i=f__default.resolve(t.cwd??process.cwd()),l=(t.resolution??"global_first")==="global_first",o=r.PATH??r.Path??process.env.PATH??process.env.Path??"",a=n==="win32"?";":":",s=o.split(a).map(u=>u.trim()).filter(Boolean),c=f__default.extname(e).length>0,d=r.PATHEXT??r.Pathext??process.env.PATHEXT??process.env.Pathext??".EXE;.CMD;.BAT;.COM",p=n==="win32"?c?[""]:d.split(";").map(u=>u.trim()).filter(Boolean).map(u=>u.startsWith(".")?u:`.${u}`):[""];for(let u of s){let E=f__default.resolve(i,u);if(!(l&&Ge(E,i)))for(let w of p){let y=D(w),m=w.toUpperCase();for(let g of [w,y,m]){let C=f__default.join(E,`${e}${g}`);if(k(C))return C}}}return e}function Je(e){if(!k(e))return null;try{let t=readFileSync(e,"utf8"),n=f__default.dirname(e),r=[];for(let a of t.matchAll(/"([^"\r\n]*)"/g)){let d=(a[1]??"").match(/%~?dp0%?\s*[\\/]*(.*)$/i)?.[1]?.trim();if(!d)continue;let p=d.replace(/[\\/]+/g,f__default.sep).replace(/^[\\/]+/,""),u=f__default.resolve(n,p);k(u)&&r.push(u);}let i=[],l=new Map;for(let a of t.matchAll(/SET\s+"(\w+)=%~?dp0%?[\\/]?([^"]+)"/gi)){let s=a[1].toUpperCase(),c=a[2].trim().replace(/[\\/]+/g,f__default.sep).replace(/^[\\/]+/,"");l.set(s,f__default.resolve(n,c));}for(let a of t.split(/\r?\n/))if(a.includes("%*"))for(let s of a.matchAll(/"%(\w+)%"/g)){let c=l.get(s[1].toUpperCase());c&&k(c)&&i.push(c);}let o=a=>a.find(s=>{let c=D(f__default.basename(s));return c!=="node.exe"&&c!=="node"})??null;return o(i)??o(r)}catch{return null}}function je(e,t){if(typeof t=="string")return O(t)||null;if(!t||typeof t!="object")return null;if(e){let n=t[e],r=typeof n=="string"?O(n):void 0;if(r)return r}for(let n of Object.values(t)){let r=typeof n=="string"?O(n):void 0;if(r)return r}return null}function Ke(e,t){if(!t)return null;let n=f__default.dirname(e),r=[f__default.resolve(n,"..",t),f__default.resolve(n,"node_modules",t)];for(let i of r){let l=f__default.join(i,"package.json");if(k(l))try{let o=JSON.parse(readFileSync(l,"utf8")),a=je(t,o.bin);if(!a)continue;let s=f__default.resolve(i,a);if(k(s))return s}catch{}}return null}function ze(e){let t=e.platform??process.platform,n=e.env??process.env,r=e.execPath??process.execPath,i=e.cwd,l=e.resolution;if(t!=="win32")return {command:Z(e.command,{cwd:i,env:n,platform:t,resolution:l}),leadingArgv:[],resolution:"direct"};let o=Z(e.command,{cwd:i,env:n,platform:t,resolution:l}),a=D(f__default.extname(o));if(a===".js"||a===".cjs"||a===".mjs")return {command:r,leadingArgv:[o],resolution:"node-entrypoint",windowsHide:true};if(a===".cmd"||a===".bat"){let s=Je(o)??Ke(o,e.packageName);return s?D(f__default.extname(s))===".exe"?{command:s,leadingArgv:[],resolution:"exe-entrypoint",windowsHide:true}:{command:r,leadingArgv:[s],resolution:"node-entrypoint",windowsHide:true}:{command:o,leadingArgv:[],resolution:"unresolved-wrapper"}}return {command:o,leadingArgv:[],resolution:"direct"}}function qe(e){if(e.candidate.resolution!=="unresolved-wrapper")return {command:e.candidate.command,leadingArgv:e.candidate.leadingArgv,resolution:e.candidate.resolution,windowsHide:e.candidate.windowsHide};throw new Error(`${f__default.basename(e.candidate.command)} wrapper resolved, but no executable/Node entrypoint could be resolved without shell execution.`)}function te(e){let t=ze(e);return qe({candidate:t})}function ne(e,t){return {command:e.command,argv:[...e.leadingArgv,...t],resolution:e.resolution,shell:e.shell,windowsHide:e.windowsHide}}var T="\uFFFD",$=8,oe=1e3,Qe=new Map([[437,"ibm437"],[720,"ibm720"],[737,"ibm737"],[775,"ibm775"],[850,"ibm850"],[852,"ibm852"],[855,"ibm855"],[857,"ibm857"],[858,"ibm858"],[862,"ibm862"],[864,"ibm864"],[932,"shift_jis"],[936,"gb18030"],[949,"euc-kr"],[950,"big5"],[866,"ibm866"],[869,"ibm869"],[1250,"windows-1250"],[1251,"windows-1251"],[1252,"windows-1252"],[1253,"windows-1253"],[1254,"windows-1254"],[1255,"windows-1255"],[1256,"windows-1256"],[1257,"windows-1257"],[1258,"windows-1258"]]),A;function V(e){let t=0;for(let n of e)n===T&&(t+=1);return t}function H(e,t){return V(t)<V(e)?t:e}function Ze(e){let t=e.match(/(?:^|[^0-9])([0-9]{1,5})(?![0-9])/);if(!t)return null;let n=Number(t[1]);return Number.isInteger(n)&&n>0&&n<=65535?n:null}function et(e){if(e!==65001)return Qe.get(e)}function tt(e){let t=et(e);if(!t)return null;try{return new TextDecoder(t)}catch{return null}}function nt(){return new Promise(e=>{let t=false,n,r=i=>{t||(t=true,n&&clearTimeout(n),e(i));};n=setTimeout(()=>r(null),oe),n.unref();try{execFile("chcp.com",[],{encoding:"ascii",timeout:oe,windowsHide:!0},(l,o)=>{if(l){r(null);return}r(Ze(String(o)));}).once("error",()=>r(null));}catch{r(null);}})}function ae(){return process.platform!=="win32"?Promise.resolve(null):(A||(A=nt(),A.then(e=>{},()=>{})),A)}function rt(){process.platform==="win32"&&ae();}function se(e,t){if(t.length>=$)return t.subarray(t.length-$);let n=$-t.length,r=e.length>n?e.subarray(e.length-n):e;return Buffer.concat([r,t])}var x=class{platform;detectCodePage;utf8Decoder=new StringDecoder("utf8");codePage;fallbackDecoder;replayTail=Buffer.alloc(0);pendingUtf8="";pendingFallback="";pendingBytes=Buffer.alloc(0);queue=Promise.resolve();ended=false;constructor(t={}){this.platform=t.platform??process.platform,this.detectCodePage=t.detectCodePage??ae,this.codePage=t.codePage;}write(t){let n=Buffer.from(t);return this.enqueue(()=>this.decodeChunk(n))}end(){return this.enqueue(()=>this.finish())}enqueue(t){let n=this.queue.then(t);return this.queue=n.then(()=>{},()=>{}),n}clearPendingCandidate(){this.pendingUtf8="",this.pendingFallback="",this.pendingBytes=Buffer.alloc(0);}async resolveCodePage(){if(this.codePage!==void 0)return this.codePage;try{this.codePage=await this.detectCodePage();}catch{this.codePage=null;}return this.codePage}async getFallbackDecoder(){if(this.fallbackDecoder!==void 0)return this.fallbackDecoder;let t=await this.resolveCodePage();return this.fallbackDecoder=t===null?null:tt(t),this.fallbackDecoder}async decodeChunk(t){if(this.ended)return "";let n=this.utf8Decoder.write(t),r=n.includes(T);if(r&&(this.utf8Decoder=new StringDecoder("utf8")),this.platform!=="win32")return n;if(this.fallbackDecoder){let s=this.fallbackDecoder.decode(t,{stream:true}),c=se(this.pendingBytes,t);if(r){let d=this.pendingUtf8+n,p=this.pendingFallback+s;return this.clearPendingCandidate(),H(d,p)}if(V(s)>0){let d=this.pendingUtf8+n;return this.clearPendingCandidate(),this.fallbackDecoder=void 0,this.replayTail=c,d}if(this.pendingUtf8||this.pendingFallback){if(this.pendingUtf8+=n,this.pendingFallback+=s,this.pendingBytes=c,n.length===0||s.length===0)return "";let d=this.pendingUtf8;return this.clearPendingCandidate(),d}return n.length===0&&s.length>0?(this.pendingUtf8=n,this.pendingFallback=s,this.pendingBytes=c,""):n}let i=this.replayTail;if(this.fallbackDecoder===void 0&&(this.replayTail=se(this.replayTail,t)),!r)return n;let l=this.fallbackDecoder===void 0,o=await this.getFallbackDecoder();if(!o)return this.replayTail=Buffer.alloc(0),n;l&&i.length>0&&o.decode(i,{stream:true}),this.replayTail=Buffer.alloc(0);let a=o.decode(t,{stream:true});return H(n,a)}async finish(){if(this.ended)return "";this.ended=true;let t=this.utf8Decoder.end();if(this.platform!=="win32")return t;if(this.fallbackDecoder===void 0&&t.includes(T)){let l=await this.getFallbackDecoder();l&&this.replayTail.length>0&&(l.decode(this.replayTail,{stream:true}),this.replayTail=Buffer.alloc(0));}let n=this.pendingUtf8+t,r=this.fallbackDecoder?.decode()??"",i=this.pendingFallback+r;return this.clearPendingCandidate(),n.includes(T)?H(n,i):n}};rt();var ce=3e4;function ot(e){if(typeof e.pid!="number"){e.kill();return}if(process.platform==="win32"){spawn("taskkill",["/pid",String(e.pid),"/t","/f"],{windowsHide:true}).on("error",()=>{});return}try{process.kill(-e.pid,"SIGKILL");}catch{e.kill("SIGKILL");}}var ue=(e,t,n={})=>new Promise((r,i)=>{let l=n.env??process.env,o=process.platform,a;try{let g=te({command:e,platform:o,env:l,cwd:n.cwd,allowShellFallback:!1});a=ne(g,t);}catch(g){i(g instanceof Error?g:new Error(String(g)));return}let s=spawn(a.command,a.argv,{cwd:n.cwd,env:l,shell:a.shell,windowsHide:a.windowsHide??true,detached:o!=="win32"}),c="",d="",p=false,u=new x({platform:o}),E=new x({platform:o}),w=Promise.resolve(),y=Promise.resolve(),m=setTimeout(()=>{p||(p=true,ot(s),i(new Error(`Command timed out after ${n.timeoutMs??ce}ms: ${e} ${t.join(" ")}`)));},n.timeoutMs??ce);s.stdout?.on("data",g=>{w=w.then(async()=>{c+=await u.write(g);});}),s.stderr?.on("data",g=>{y=y.then(async()=>{d+=await E.write(g);});}),s.on("error",g=>{p||(p=true,clearTimeout(m),i(g));}),s.on("close",g=>{p||(async()=>{await Promise.all([w,y]);let[C,Ae]=await Promise.all([u.end(),E.end()]);p||(c+=C,d+=Ae,p=true,clearTimeout(m),r({code:g??0,stdout:c,stderr:d}));})().catch(C=>{p||(p=true,clearTimeout(m),i(C instanceof Error?C:new Error(String(C))));});});});function at(){try{return (typeof M=="function"?M:createRequire(P)).resolve("@crewx/sdk/package.json")}catch{return null}}function ct(){let e=[at(),join(S,"../../package.json"),join(S,"../../../package.json")].filter(t=>!!t);for(let t of e)try{let n=JSON.parse(readFileSync(t,"utf8"));if(n.name==="@crewx/sdk"&&n.version)return n.version}catch{}return "0.0.0"}var fe=ct();var v=f.win32;function U(e){return v.join(e,".crewx")}function he(e){return v.join(U(e),"shortcut.json")}function me(e){return v.join(U(e),"launcher.json")}function ge(e){return v.join(U(e),"bin","crewx-launcher.cmd")}function we(e){return v.join(e,"CrewX.lnk")}function X(e,t){return v.normalize(e).toLowerCase()===v.normalize(t).toLowerCase()}var lt="[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Environment]::GetFolderPath('DesktopDirectory')";async function Se(e){try{let n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",lt],{env:e.env}),r=n.stdout.trim();if(n.code===0&&r)return {dir:r,source:"known-folder"}}catch{}let t=e.env.USERPROFILE||e.env.Userprofile||e.homedir();return t?{dir:v.join(t,"Desktop"),source:"fallback"}:null}function G(e,t){let n=v.resolve(t,"node_modules",".bin").toLowerCase();return e.split(";").filter(r=>r?v.resolve(r).toLowerCase()!==n:true).join(";")}function Pe(e){return e?/\\Program Files( \(x86\))?\\/i.test(e)&&/crewx/i.test(e):false}function ut(e,t){let n=s=>{let[c,...d]=s.split("-"),p=d.join("-")||void 0;return {parts:(c??"").split(".").map(E=>Number.parseInt(E,10)||0),pre:p}},r=n(e),i=n(t),l=Math.max(r.parts.length,i.parts.length);for(let s=0;s<l;s++){let c=r.parts[s]??0,d=i.parts[s]??0;if(c!==d)return c<d?-1:1}if(r.pre===i.pre)return 0;if(!r.pre&&i.pre)return 1;if(r.pre&&!i.pre)return -1;let o=Number.parseInt(r.pre.match(/(\d+)$/)?.[1]??"",10),a=Number.parseInt(i.pre.match(/(\d+)$/)?.[1]??"",10);return !Number.isNaN(o)&&!Number.isNaN(a)&&o!==a?o<a?-1:1:r.pre<i.pre?-1:r.pre>i.pre?1:0}function _(e,t){return ut(e,t)<0}var ve=f.win32,ye=1;function Ce(e,t){if(!e.existsSync(t))return null;try{let n=JSON.parse(e.readFileSync(t));return {schema:n.schema??ye,shortcutPath:n.shortcutPath,version:n.version,iconHash:typeof n.iconHash=="string"?n.iconHash:void 0,owned:!!n.owned,declined:!!n.declined,desktopSource:n.desktopSource,updatedAt:n.updatedAt}}catch{return null}}function W(e,t,n){let r={schema:ye,...n,updatedAt:new Date().toISOString()};e.mkdirSync(ve.dirname(t)),e.writeFileSync(t,JSON.stringify(r,null,2));}function F(e,t){if(!e.existsSync(t))return null;try{let n=JSON.parse(e.readFileSync(t));return {schema:n.schema??0,binPath:n.binPath,updatedAt:n.updatedAt}}catch{return null}}function Re(e,t,n){e.mkdirSync(ve.dirname(t)),e.writeFileSync(t,JSON.stringify(n,null,2));}var dt=f.win32,I=1;function ft(e){return e.replace(/%/g,"%%")}function pt(e){return ["@echo off","setlocal DisableDelayedExpansion","chcp 65001 >nul","",'set "CREWX_WORKDIR=%USERPROFILE%\\crewx"','if not exist "%CREWX_WORKDIR%" mkdir "%CREWX_WORKDIR%" >nul 2>nul','cd /d "%CREWX_WORKDIR%"',"",'set "CREWX_PORT_EFFECTIVE=%CREWX_PORT%"','if "%CREWX_PORT_EFFECTIVE%"=="" set "CREWX_PORT_EFFECTIVE=8150"','set "CREWX_HEALTH_URL=http://127.0.0.1:%CREWX_PORT_EFFECTIVE%/api/v1/health"','set "CREWX_ORIGIN_URL=http://127.0.0.1:%CREWX_PORT_EFFECTIVE%/"',"",e.bakedBinPath?`set "CREWX_FALLBACK_BIN=${ft(e.bakedBinPath)}"`:'set "CREWX_FALLBACK_BIN="','set "CREWX_RESOLVED_BIN=%CREWX_BIN%"','if "%CREWX_RESOLVED_BIN%"=="" set "CREWX_RESOLVED_BIN=%CREWX_FALLBACK_BIN%"','if "%CREWX_RESOLVED_BIN%"=="" (',` for /f "delims=" %%I in ('where crewx 2^>nul') do (`,' if not defined CREWX_RESOLVED_BIN set "CREWX_RESOLVED_BIN=%%I"'," )",")","",'powershell -NoProfile -NonInteractive -Command "try { $r = Invoke-WebRequest -Uri $env:CREWX_HEALTH_URL -TimeoutSec 1 -UseBasicParsing; if ($r.StatusCode -eq 200) { exit 0 } else { exit 1 } } catch { exit 1 }"',"if %ERRORLEVEL% EQU 0 (",' start "" "%CREWX_ORIGIN_URL%"'," exit /b 0",")","",'if "%CREWX_RESOLVED_BIN%"=="" ('," echo CrewX executable not found. Please reinstall the desktop shortcut."," pause"," exit /b 1",")","",'start "CrewX" /min "%CREWX_RESOLVED_BIN%"',""].join(`\r
2
+ `)}function ke(e){let t=F(e.fs,e.launcherManifestPath),n=!!t&&t.schema>=I&&e.fs.existsSync(e.wrapperPath),r=n&&!t.binPath&&!!e.bakedBinPath;if(n&&!r)return {wrapperPath:e.wrapperPath,wrote:false,schema:t.schema};let l=pt({bakedBinPath:e.bakedBinPath});try{e.fs.mkdirSync(dt.dirname(e.wrapperPath)),e.fs.writeFileSync(e.wrapperPath,l),Re(e.fs,e.launcherManifestPath,{schema:I,binPath:e.bakedBinPath,updatedAt:new Date().toISOString()});}catch(o){throw o instanceof h?o:new h("WRITE_DENIED",`Could not write launcher wrapper: ${o instanceof Error?o.message:String(o)}`)}return {wrapperPath:e.wrapperPath,wrote:true,schema:I}}var ht=["$ws = New-Object -ComObject WScript.Shell","$sc = $ws.CreateShortcut($env:CREWX_LNK_PATH)","$sc.TargetPath = $env:CREWX_LNK_TARGET","if ($env:CREWX_LNK_WORKDIR) { $sc.WorkingDirectory = $env:CREWX_LNK_WORKDIR }","$sc.WindowStyle = 7","if ($env:CREWX_LNK_ICON) { $sc.IconLocation = $env:CREWX_LNK_ICON }","$sc.Save()"].join("; "),mt=["[Console]::OutputEncoding = [System.Text.Encoding]::UTF8","$ws = New-Object -ComObject WScript.Shell","$sc = $ws.CreateShortcut($env:CREWX_LNK_PATH)","[PSCustomObject]@{ TargetPath = $sc.TargetPath; WorkingDirectory = $sc.WorkingDirectory; IconLocation = $sc.IconLocation } | ConvertTo-Json -Compress"].join("; ");async function xe(e){let t={...e.env,CREWX_LNK_PATH:e.shortcutPath,CREWX_LNK_TARGET:e.targetPath,CREWX_LNK_WORKDIR:e.workingDirectory??"",CREWX_LNK_ICON:e.iconPath??""},n;try{n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",ht],{env:t});}catch(r){throw new h("POWERSHELL_UNAVAILABLE",`Could not run PowerShell: ${r instanceof Error?r.message:String(r)}`)}if(n.code!==0)throw new h("POWERSHELL_UNAVAILABLE",`Failed to create desktop shortcut: ${n.stderr||n.stdout}`)}function _e(e){let t=e.trim(),n=t.lastIndexOf(",");return n!==-1&&/^-?\d+$/.test(t.slice(n+1).trim())&&(t=t.slice(0,n).trim()),t.length>=2&&t.startsWith('"')&&t.endsWith('"')&&(t=t.slice(1,-1).trim()),t}async function Ie(e){try{let t={...e.env,CREWX_LNK_PATH:e.shortcutPath},n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",mt],{env:t});if(n.code!==0||!n.stdout.trim())return null;let r=JSON.parse(n.stdout.trim());return {targetPath:r.TargetPath??"",workingDirectory:r.WorkingDirectory??"",iconLocation:r.IconLocation??""}}catch{return null}}var j=f.win32;async function L(e){let t=G(e.env.PATH??e.env.Path??"",e.cwd),n={...e.env,PATH:t,Path:t},r;try{r=await e.run("npm",["list","-g","crewx","--depth=0","--json"],{env:n});}catch{return {installed:false}}let i;try{i=JSON.parse(r.stdout||"{}");}catch{return {installed:false}}let l=i.dependencies?.crewx;if(!l?.version)return {installed:false};let o;try{let s=await e.run("npm",["prefix","-g"],{env:n});s.code===0&&(o=s.stdout.trim()||void 0);}catch{}let a=o?j.join(o,"crewx.cmd"):void 0;return {installed:true,version:l.version,binPath:a,prefix:o}}var gt=/EACCES|EPERM|EROFS/,wt=/ENOTFOUND|ETIMEDOUT|ECONNREFUSED|network|registry/i,St=/^\d+\.\d+\.\d+/;function Pt(e){return !!e&&e!=="0.0.0"&&St.test(e)}var J=10*6e4;async function Ne(e){if(!Pt(e.targetVersion))throw new h("GLOBAL_INSTALL_FAILED",`RUNNING_VERSION_UNKNOWN: cannot reliably determine the running crewx version to install (got ${JSON.stringify(e.targetVersion)}); refusing to fall back to crewx@latest`);if(e.currentInfo?.installed&&e.currentInfo.version&&!_(e.currentInfo.version,e.targetVersion))return {info:e.currentInfo};let t=G(e.env.PATH??e.env.Path??"",e.cwd),n={...e.env,PATH:t,Path:t},r=`crewx@${e.targetVersion}`;e.onProgress?.({phase:"global-install",message:`Installing crewx globally (npm install -g ${r})`});let i;try{i=await e.run("npm",["install","-g",r,"--no-audit","--no-fund"],{env:n,timeoutMs:J});}catch(o){throw new h("NPM_UNAVAILABLE",`Could not run npm: ${o instanceof Error?o.message:String(o)}`)}if(i.code===0)return {info:await L({env:n,cwd:e.cwd,run:e.run})};let l=`${i.stdout}
3
+ ${i.stderr}`;if(gt.test(l)){e.onProgress?.({phase:"global-install",message:"Permission denied \u2014 retrying with a user-scoped npm prefix"});let o=e.env.LOCALAPPDATA||j.join(e.env.USERPROFILE??"","AppData","Local"),a={...n,npm_config_prefix:j.join(o,"crewx","npm")},s;try{s=await e.run("npm",["install","-g",r,"--no-audit","--no-fund"],{env:a,timeoutMs:J});}catch(c){throw new h("NPM_PERMISSION_DENIED",`Retry with user-scoped prefix failed: ${c instanceof Error?c.message:String(c)}`)}if(s.code===0)return {info:await L({env:a,cwd:e.cwd,run:e.run})};throw new h("NPM_PERMISSION_DENIED",`npm install -g failed after user-scoped prefix retry: ${s.stderr||s.stdout}`)}if(wt.test(l)){if(!e.installRoot)throw new h("OFFLINE_NO_SOURCE","The npm registry is unreachable and no local installRoot was provided for an offline install");e.onProgress?.({phase:"global-install",message:`Registry unreachable \u2014 installing offline from ${e.installRoot}`});let o;try{o=await e.run("npm",["install","-g",e.installRoot,"--offline","--no-audit","--no-fund"],{env:n,timeoutMs:J});}catch(a){throw new h("GLOBAL_INSTALL_FAILED",`Offline install failed: ${a instanceof Error?a.message:String(a)}`)}if(o.code===0)return {info:await L({env:n,cwd:e.cwd,run:e.run})};throw new h("GLOBAL_INSTALL_FAILED",`Offline install failed: ${o.stderr||o.stdout}`)}throw new h("GLOBAL_INSTALL_FAILED",l.trim()||`npm install -g ${r} failed`)}function vt(e){return e.run??ue}function yt(e){return e.fs??Y}async function B(e){let t=e.platform??process.platform,n=e.env??process.env,r=e.homedir??Q,i=vt(e),l=yt(e),o=e.runningVersion??fe,a=e.cwd??process.cwd(),s=r(),c=he(s),d=me(s),p=ge(s),u=null;t==="win32"&&(u=await Se({env:n,homedir:r,run:i}));let E=u?we(u.dir):null;return {platform:t,env:n,homedir:r,run:i,fs:l,runningVersion:o,cwd:a,installRoot:e.installRoot,shortcutManifestPath:c,launcherManifestPath:d,wrapperPath:p,desktop:u,shortcutPath:E}}function Oe(e){return e?f.win32.normalize(e).toLowerCase().endsWith(`${f.win32.sep}bin${f.win32.sep}crewx.ico`):false}function K(e,t){let n=e.readBinaryFileSync;if(n)try{return createHash("sha256").update(n(t)).digest("hex")}catch{return}}async function Ct(e){try{await e.run("ie4uinit.exe",["-show"],{env:e.env});}catch{}}async function R(e){if(e.platform!=="win32")return {supported:false,state:"unsupported",globalCrewx:null,runningVersion:e.runningVersion,errors:[],manifest:null,iconStale:false};let t=[];e.desktop||t.push("NO_DESKTOP_DIR: could not resolve the Windows Desktop directory");let n=Ce(e.fs,e.shortcutManifestPath),r=F(e.fs,e.launcherManifestPath),i=await L({env:e.env,cwd:e.cwd,run:e.run}),l=e.shortcutPath?e.fs.existsSync(e.shortcutPath):false,o,a=false,s,c;if(!l)o=n?.declined?"declined":"not-installed";else {let d=!!n?.owned&&!!e.shortcutPath&&n.shortcutPath===e.shortcutPath,p=false,u=e.shortcutPath?await Ie({run:e.run,env:e.env,shortcutPath:e.shortcutPath}):null;if(d||(u&&X(u.targetPath,e.wrapperPath)?d=true:u&&Pe(u.targetPath)&&(p=true)),p)o="foreign",t.push("NSIS_PRESENT: an NSIS-installed CrewX shortcut was detected");else if(!d)o="foreign";else if(n?.version&&_(e.runningVersion,n.version))o="superseded",t.push(`SUPERSEDED: running version ${e.runningVersion} is older than the installed shortcut's version ${n.version}; refusing to modify it`);else {let E=!r||r.schema<I||!e.fs.existsSync(e.wrapperPath);if(u){let w=_e(u.iconLocation);if(!(!!w&&e.fs.existsSync(w)))a=true;else {s=w;let m=De(i,e.fs);m?X(w,m)?(c=K(e.fs,w),a=!c||n?.iconHash!==c):a=true:Oe(w)?(c=K(e.fs,w),a=!c||n?.iconHash!==c):a=true;}}o=E||a?"stale":"installed";}}return {supported:true,state:o,shortcutPath:e.shortcutPath??void 0,desktopDir:e.desktop?.dir,desktopSource:e.desktop?.source,wrapperPath:e.wrapperPath,wrapperSchema:r?.schema,globalCrewx:i.installed?i:{installed:false},runningVersion:e.runningVersion,errors:t,manifest:n,iconStale:a,iconPath:s,iconHash:c}}function De(e,t){if(!e?.installed||!e.prefix)return;let n=f.win32.join(e.prefix,"node_modules","crewx","bin","crewx.ico");return t.existsSync(n)?n:void 0}function b(e){let{manifest:t,iconStale:n,iconPath:r,iconHash:i,...l}=e;return l}async function Rt(e={}){let t=await B(e),n=await R(t);return b(n)}async function bt(e={}){let t=await B(e);e.onProgress?.({phase:"detect",message:"Checking current shortcut status"});let n=await R(t),r=b(n);if(!r.supported)return {...r,changed:false,installedGlobal:false};if(r.state==="superseded")return {...r,changed:false,installedGlobal:false};if(r.state==="foreign"){if(n.errors.some(m=>m.startsWith("NSIS_PRESENT")))throw new h("NSIS_PRESENT",`An NSIS-installed CrewX shortcut was detected at ${r.shortcutPath}`);if(!e.force)throw new h("FOREIGN_SHORTCUT",`An existing shortcut at ${r.shortcutPath} is not managed by CrewX`)}if(!t.desktop||!t.shortcutPath)throw new h("NO_DESKTOP_DIR","Could not resolve the Windows Desktop directory");let i=false,l=false,o=r.globalCrewx,a=[],s=n.manifest?.iconHash,c=false;if(!!o?.installed&&!!o.version&&_(o.version,t.runningVersion)||!o?.installed&&r.state!=="installed"){let m=await Ne({env:t.env,cwd:t.cwd,run:t.run,targetVersion:t.runningVersion,currentInfo:o??void 0,installRoot:t.installRoot,onProgress:e.onProgress});o=m.info,l=m.info.installed,i=true,l||a.push(`GLOBAL_INSTALL_UNCONFIRMED: npm install -g crewx@${t.runningVersion} exited successfully but a follow-up check could not confirm the global install`);}if(e.onProgress?.({phase:"wrapper",message:"Ensuring launcher wrapper"}),ke({fs:t.fs,wrapperPath:t.wrapperPath,launcherManifestPath:t.launcherManifestPath,bakedBinPath:o?.binPath}).wrote&&(i=true),!((r.state==="installed"||r.state==="stale")&&!n.iconStale)){let m=De(o,t.fs)??(n.iconPath&&Oe(n.iconPath)&&t.fs.existsSync(n.iconPath)?n.iconPath:void 0);if(n.iconStale&&!m)throw new h("ICON_UNAVAILABLE",`Could not locate the global CrewX icon (bin\\crewx.ico) to repair the desktop shortcut at ${t.shortcutPath}; the existing shortcut was left untouched`);e.onProgress?.({phase:"lnk",message:"Creating desktop shortcut"}),await xe({run:t.run,env:t.env,shortcutPath:t.shortcutPath,targetPath:t.wrapperPath,iconPath:m}),i=true,c=n.iconStale;let g=m?K(t.fs,m):void 0;g&&(s=g);}i&&W(t.fs,t.shortcutManifestPath,{shortcutPath:t.shortcutPath,version:t.runningVersion,owned:true,declined:false,desktopSource:t.desktop.source,iconHash:s}),c&&await Ct(t);let w=await R(t),y=b(w);return {...y,errors:[...y.errors,...a],changed:i,installedGlobal:l}}async function kt(e={}){let t=await B(e),n=await R(t),r=b(n);if(!r.supported)return r;if((r.state==="installed"||r.state==="stale")&&t.shortcutPath)try{t.fs.unlinkSync(t.shortcutPath);}catch{}W(t.fs,t.shortcutManifestPath,{shortcutPath:void 0,version:n.manifest?.version,owned:false,declined:true,desktopSource:void 0,iconHash:void 0});let i=await R(t);return b(i)}async function xt(e={}){let t=await B(e),n=await R(t),r=b(n);if(!r.supported)return r;W(t.fs,t.shortcutManifestPath,{shortcutPath:n.manifest?.shortcutPath,version:n.manifest?.version,owned:n.manifest?.owned??false,declined:true,desktopSource:n.manifest?.desktopSource,iconHash:n.manifest?.iconHash});let i=await R(t);return b(i)}export{h as ShortcutError,xt as dismissShortcutNotice,Rt as getShortcutStatus,bt as installShortcut,kt as uninstallShortcut};