@crewx/sdk 0.9.0-rc.8 → 0.9.0-rc.80

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 (168) hide show
  1. package/README.md +1 -1
  2. package/dist/activity-log/builder.d.ts +55 -6
  3. package/dist/config/canonicalize-agent-options.d.ts +17 -0
  4. package/dist/config/global-settings.d.ts +33 -0
  5. package/dist/config/migrate-grok-mode.d.ts +6 -0
  6. package/dist/config/model-compat.d.ts +31 -0
  7. package/dist/config/models.generated.d.ts +33 -0
  8. package/dist/config/models.remote.d.ts +1 -0
  9. package/dist/config/overdrive.d.ts +7 -0
  10. package/dist/config/pricing.d.ts +8 -5
  11. package/dist/config/pricing.generated.d.ts +4 -0
  12. package/dist/config/pricing.types.d.ts +4 -10
  13. package/dist/config/timeout.config.d.ts +3 -0
  14. package/dist/config/wi-boards.d.ts +19 -0
  15. package/dist/context-budget/continuity.d.ts +61 -0
  16. package/dist/context-budget/index.d.ts +140 -0
  17. package/dist/conversation/index.d.ts +1 -1
  18. package/dist/conversation/sqlite-provider.d.ts +5 -1
  19. package/dist/conversation/to-template-messages.d.ts +7 -0
  20. package/dist/conversation/types.d.ts +43 -0
  21. package/dist/desktop/command-runner.d.ts +4 -0
  22. package/dist/desktop/default-adapters.d.ts +4 -0
  23. package/dist/desktop/global-install.d.ts +19 -0
  24. package/dist/desktop/index.d.ts +2 -0
  25. package/dist/desktop/index.js +3 -0
  26. package/dist/desktop/install.d.ts +5 -0
  27. package/dist/desktop/lnk.d.ts +22 -0
  28. package/dist/desktop/manifest.d.ts +21 -0
  29. package/dist/desktop/types.d.ts +67 -0
  30. package/dist/desktop/version.d.ts +1 -0
  31. package/dist/desktop/windows-paths.d.ts +21 -0
  32. package/dist/desktop/wrapper.d.ts +18 -0
  33. package/dist/esm/desktop/index.js +3 -0
  34. package/dist/esm/index.js +345 -96
  35. package/dist/esm/plugins/index.js +187 -93
  36. package/dist/esm/publish/index.js +1 -0
  37. package/dist/esm/repository/index.js +203 -94
  38. package/dist/esm/testing/index.js +1 -1
  39. package/dist/events/types.d.ts +4 -0
  40. package/dist/facade/Crewx.d.ts +38 -2
  41. package/dist/highlight/thread-highlight-prompt.d.ts +2 -0
  42. package/dist/highlight/thread-highlighter.d.ts +326 -0
  43. package/dist/index.browser.d.ts +9 -1
  44. package/dist/index.browser.js +6 -2
  45. package/dist/index.d.ts +57 -8
  46. package/dist/index.js +345 -96
  47. package/dist/internal/windows-spawn.d.ts +10 -0
  48. package/dist/layout/types.d.ts +17 -1
  49. package/dist/local-server/base-url.d.ts +18 -0
  50. package/dist/local-server/index.d.ts +8 -0
  51. package/dist/local-server/opencode.d.ts +8 -0
  52. package/dist/local-server/probe.d.ts +3 -0
  53. package/dist/local-server/runtime.d.ts +26 -0
  54. package/dist/local-server/types.d.ts +43 -0
  55. package/dist/migrations/0008_careful_black_bird.sql +17 -0
  56. package/dist/migrations/0009_hot_dark_phoenix.sql +1 -0
  57. package/dist/migrations/0010_analyze_stats.sql +6 -0
  58. package/dist/migrations/0011_far_black_tarantula.sql +1 -0
  59. package/dist/migrations/0012_blue_turbo.sql +23 -0
  60. package/dist/migrations/0013_hesitant_adam_destine.sql +15 -0
  61. package/dist/migrations/0014_organic_mongu.sql +73 -0
  62. package/dist/migrations/0015_panoramic_gorilla_man.sql +71 -0
  63. package/dist/migrations/0016_fuzzy_hemingway.sql +14 -0
  64. package/dist/migrations/0017_project_stage_sdk_migration.sql +29 -0
  65. package/dist/migrations/0018_bored_jackal.sql +33 -0
  66. package/dist/migrations/0019_backfill_task_thread_ids.sql +74 -0
  67. package/dist/migrations/0020_useful_iron_lad.sql +55 -0
  68. package/dist/migrations/0021_dashing_peter_quill.sql +51 -0
  69. package/dist/migrations/meta/0008_snapshot.json +1327 -0
  70. package/dist/migrations/meta/0009_snapshot.json +1335 -0
  71. package/dist/migrations/meta/0010_snapshot.json +1335 -0
  72. package/dist/migrations/meta/0011_snapshot.json +1342 -0
  73. package/dist/migrations/meta/0012_snapshot.json +1494 -0
  74. package/dist/migrations/meta/0013_snapshot.json +1592 -0
  75. package/dist/migrations/meta/0014_snapshot.json +1975 -0
  76. package/dist/migrations/meta/0015_snapshot.json +2315 -0
  77. package/dist/migrations/meta/0016_snapshot.json +2419 -0
  78. package/dist/migrations/meta/0017_snapshot.json +2419 -0
  79. package/dist/migrations/meta/0018_snapshot.json +2570 -0
  80. package/dist/migrations/meta/0020_snapshot.json +2895 -0
  81. package/dist/migrations/meta/0021_snapshot.json +3031 -0
  82. package/dist/migrations/meta/_journal.json +98 -0
  83. package/dist/paths.d.ts +1 -0
  84. package/dist/plugin/types.d.ts +1 -0
  85. package/dist/plugins/index.js +187 -93
  86. package/dist/plugins/sqlite-tracing.d.ts +22 -0
  87. package/dist/provider/acp/connection.d.ts +4 -0
  88. package/dist/provider/acp/meta.d.ts +11 -0
  89. package/dist/provider/bridge.d.ts +6 -0
  90. package/dist/provider/classify-task-error.d.ts +2 -0
  91. package/dist/provider/cli/adapter.types.d.ts +6 -0
  92. package/dist/provider/cli/adapters/cli-knob.util.d.ts +7 -0
  93. package/dist/provider/cli/adapters/grok.d.ts +2 -0
  94. package/dist/provider/cli/adapters/index.d.ts +1 -0
  95. package/dist/provider/cli/index.d.ts +1 -1
  96. package/dist/provider/cli/meta.d.ts +5 -0
  97. package/dist/provider/errors.d.ts +1 -0
  98. package/dist/provider/idle-watchdog.d.ts +19 -0
  99. package/dist/provider/models.d.ts +17 -12
  100. package/dist/provider/order.d.ts +1 -1
  101. package/dist/provider/parse-usage.d.ts +6 -0
  102. package/dist/provider/provider-selection.d.ts +8 -0
  103. package/dist/provider/redact-technical-message.d.ts +1 -0
  104. package/dist/provider/task-error.types.d.ts +16 -0
  105. package/dist/publish/auth-boundary.d.ts +22 -0
  106. package/dist/publish/auth-json.d.ts +11 -0
  107. package/dist/publish/constants.d.ts +6 -0
  108. package/dist/publish/index.d.ts +30 -0
  109. package/dist/publish/index.js +1 -0
  110. package/dist/publish/manifest.d.ts +17 -0
  111. package/dist/publish/marketplace-api.constants.d.ts +1 -0
  112. package/dist/publish/pack.d.ts +2 -0
  113. package/dist/publish/scan.d.ts +9 -0
  114. package/dist/publish/secrets.d.ts +6 -0
  115. package/dist/publish/upload.d.ts +18 -0
  116. package/dist/repository/agent-suggestion.repository.d.ts +34 -0
  117. package/dist/repository/common-code.repository.d.ts +39 -0
  118. package/dist/repository/db.d.ts +8 -0
  119. package/dist/repository/index.d.ts +28 -4
  120. package/dist/repository/index.js +203 -94
  121. package/dist/repository/notification.repository.d.ts +58 -0
  122. package/dist/repository/project.repository.d.ts +90 -0
  123. package/dist/repository/request-log.repository.d.ts +1 -0
  124. package/dist/repository/task-log-migration.d.ts +74 -0
  125. package/dist/repository/task-log.repository.d.ts +44 -0
  126. package/dist/repository/task.repository.d.ts +119 -0
  127. package/dist/repository/thread-history.repository.d.ts +193 -0
  128. package/dist/repository/thread-title-common-code-migration.d.ts +13 -0
  129. package/dist/repository/thread-title.types.d.ts +29 -0
  130. package/dist/repository/thread.repository.d.ts +21 -2
  131. package/dist/repository/usage-report.repository.d.ts +27 -0
  132. package/dist/schema/agent-suggestions.d.ts +199 -0
  133. package/dist/schema/common-codes.d.ts +216 -0
  134. package/dist/schema/index.d.ts +9 -0
  135. package/dist/schema/notifications.d.ts +303 -0
  136. package/dist/schema/projects.d.ts +610 -0
  137. package/dist/schema/task-log-events.d.ts +119 -0
  138. package/dist/schema/tasks.d.ts +53 -0
  139. package/dist/schema/thread-history.d.ts +734 -0
  140. package/dist/schema/threads.d.ts +2 -0
  141. package/dist/schema/ui-action-receipts.d.ts +303 -0
  142. package/dist/schema/ui-instances.d.ts +267 -0
  143. package/dist/schema/usage-reports.d.ts +252 -0
  144. package/dist/testing/index.js +1 -1
  145. package/dist/types/index.d.ts +1536 -3
  146. package/dist/ui-card/index.d.ts +2 -0
  147. package/dist/ui-card/legacy-card-parser.d.ts +11 -0
  148. package/dist/ui-instance/definition.d.ts +6 -0
  149. package/dist/ui-instance/errors.d.ts +17 -0
  150. package/dist/ui-instance/index.d.ts +6 -0
  151. package/dist/ui-instance/json.d.ts +5 -0
  152. package/dist/ui-instance/runtime.d.ts +13 -0
  153. package/dist/ui-instance/store.d.ts +65 -0
  154. package/dist/ui-instance/types.d.ts +200 -0
  155. package/dist/ui-plugin/index.d.ts +3 -0
  156. package/dist/ui-plugin/manifest.d.ts +3 -0
  157. package/dist/ui-plugin/types.d.ts +76 -0
  158. package/dist/ui-plugin/validator.d.ts +9 -0
  159. package/dist/utils/crewx-home.d.ts +1 -0
  160. package/dist/utils/id.d.ts +1 -1
  161. package/dist/utils/timestamp.d.ts +1 -0
  162. package/dist/wi/create.d.ts +48 -0
  163. package/dist/wi/select.d.ts +20 -0
  164. package/package.json +18 -2
  165. package/templates/agents/default.yaml +240 -116
  166. package/templates/documents/crewx-manual.md +138 -138
  167. package/templates/workflows/wi-default-flow.yaml +65 -0
  168. package/templates/workflows/wi-plan-flow.yaml +140 -0
@@ -0,0 +1,4 @@
1
+ import { homedir } from 'node:os';
2
+ import type { ShortcutFsLike } from './types';
3
+ export declare const nodeShortcutFs: ShortcutFsLike;
4
+ export declare const osHomedir: typeof homedir;
@@ -0,0 +1,19 @@
1
+ import type { CommandRunner, GlobalCrewxInfo, ShortcutProgressEvent } from './types';
2
+ export interface DetectGlobalCrewxOptions {
3
+ env: NodeJS.ProcessEnv;
4
+ cwd: string;
5
+ run: CommandRunner;
6
+ }
7
+ export declare function detectGlobalCrewx(opts: DetectGlobalCrewxOptions): Promise<GlobalCrewxInfo>;
8
+ export interface EnsureGlobalCrewxOptions {
9
+ env: NodeJS.ProcessEnv;
10
+ cwd: string;
11
+ run: CommandRunner;
12
+ targetVersion: string;
13
+ currentInfo?: GlobalCrewxInfo;
14
+ installRoot?: string;
15
+ onProgress?: (event: ShortcutProgressEvent) => void;
16
+ }
17
+ export declare function ensureGlobalCrewx(opts: EnsureGlobalCrewxOptions): Promise<{
18
+ info: GlobalCrewxInfo;
19
+ }>;
@@ -0,0 +1,2 @@
1
+ export { getShortcutStatus, installShortcut, uninstallShortcut, dismissShortcutNotice, } from './install';
2
+ export { ShortcutError, type ShortcutState, type DesktopSource, type GlobalCrewxInfo, type ShortcutStatus, type ShortcutInstallResult, type ShortcutProgressPhase, type ShortcutProgressEvent, type ShortcutEnvOptions, type InstallShortcutOptions, type ShortcutErrorCode, type CommandResult, type CommandRunner, type CommandRunOptions, type ShortcutFsLike, } from './types';
@@ -0,0 +1,3 @@
1
+ 'use strict';var d=require('path'),crypto=require('crypto'),fs=require('fs'),os=require('os'),child_process=require('child_process'),module$1=require('module');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var d__namespace=/*#__PURE__*/_interopNamespace(d);var D=(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 f=class extends Error{code;constructor(t,n){super(`${t}: ${n}`),this.code=t,this.name="ShortcutError";}};var X={existsSync:e=>fs.existsSync(e),readFileSync:e=>fs.readFileSync(e,"utf8"),readBinaryFileSync:e=>new Uint8Array(fs.readFileSync(e)),writeFileSync:(e,t)=>fs.writeFileSync(e,t,"utf8"),mkdirSync:e=>{fs.mkdirSync(e,{recursive:true});},unlinkSync:e=>{fs.unlinkSync(e);}},G=os.homedir;function _(e){return typeof e!="string"?void 0:e.trim()||void 0}function N(e){return _(e)?.toLowerCase()??""}function v(e){try{return fs.statSync(e).isFile()}catch{return false}}function Le(e,t){if(e===t)return true;let n=d__namespace.default.relative(e,t);return n!==""&&!n.startsWith("..")&&!d__namespace.default.isAbsolute(n)}function ke(e,t){if(d__namespace.default.basename(e)!==".bin")return false;let n=d__namespace.default.dirname(e);if(d__namespace.default.basename(n)!=="node_modules")return false;let r=d__namespace.default.dirname(n);return Le(r,t)}function U(e,t={}){if(e.includes("/")||e.includes("\\")||d__namespace.default.isAbsolute(e))return e;let n=t.platform??process.platform,r=t.env??process.env,i=d__namespace.default.resolve(t.cwd??process.cwd()),l=(t.resolution??"global_first")==="global_first",o=r.PATH??r.Path??process.env.PATH??process.env.Path??"",s=n==="win32"?";":":",a=o.split(s).map(u=>u.trim()).filter(Boolean),c=d__namespace.default.extname(e).length>0,h=r.PATHEXT??r.Pathext??process.env.PATHEXT??process.env.Pathext??".EXE;.CMD;.BAT;.COM",m=n==="win32"?c?[""]:h.split(";").map(u=>u.trim()).filter(Boolean).map(u=>u.startsWith(".")?u:`.${u}`):[""];for(let u of a){let p=d__namespace.default.resolve(i,u);if(!(l&&ke(p,i)))for(let w of m){let y=N(w),g=w.toUpperCase();for(let k of [w,y,g]){let H=d__namespace.default.join(p,`${e}${k}`);if(v(H))return H}}}return e}function _e(e){if(!v(e))return null;try{let t=fs.readFileSync(e,"utf8"),n=d__namespace.default.dirname(e),r=[];for(let s of t.matchAll(/"([^"\r\n]*)"/g)){let h=(s[1]??"").match(/%~?dp0%?\s*[\\/]*(.*)$/i)?.[1]?.trim();if(!h)continue;let m=h.replace(/[\\/]+/g,d__namespace.default.sep).replace(/^[\\/]+/,""),u=d__namespace.default.resolve(n,m);v(u)&&r.push(u);}let i=[],l=new Map;for(let s of t.matchAll(/SET\s+"(\w+)=%~?dp0%?[\\/]?([^"]+)"/gi)){let a=s[1].toUpperCase(),c=s[2].trim().replace(/[\\/]+/g,d__namespace.default.sep).replace(/^[\\/]+/,"");l.set(a,d__namespace.default.resolve(n,c));}for(let s of t.split(/\r?\n/))if(s.includes("%*"))for(let a of s.matchAll(/"%(\w+)%"/g)){let c=l.get(a[1].toUpperCase());c&&v(c)&&i.push(c);}let o=s=>s.find(a=>{let c=N(d__namespace.default.basename(a));return c!=="node.exe"&&c!=="node"})??null;return o(i)??o(r)}catch{return null}}function Ne(e,t){if(typeof t=="string")return _(t)||null;if(!t||typeof t!="object")return null;if(e){let n=t[e],r=typeof n=="string"?_(n):void 0;if(r)return r}for(let n of Object.values(t)){let r=typeof n=="string"?_(n):void 0;if(r)return r}return null}function Oe(e,t){if(!t)return null;let n=d__namespace.default.dirname(e),r=[d__namespace.default.resolve(n,"..",t),d__namespace.default.resolve(n,"node_modules",t)];for(let i of r){let l=d__namespace.default.join(i,"package.json");if(v(l))try{let o=JSON.parse(fs.readFileSync(l,"utf8")),s=Ne(t,o.bin);if(!s)continue;let a=d__namespace.default.resolve(i,s);if(v(a))return a}catch{}}return null}function be(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:U(e.command,{cwd:i,env:n,platform:t,resolution:l}),leadingArgv:[],resolution:"direct"};let o=U(e.command,{cwd:i,env:n,platform:t,resolution:l}),s=N(d__namespace.default.extname(o));if(s===".js"||s===".cjs"||s===".mjs")return {command:r,leadingArgv:[o],resolution:"node-entrypoint",windowsHide:true};if(s===".cmd"||s===".bat"){let a=_e(o)??Oe(o,e.packageName);return a?N(d__namespace.default.extname(a))===".exe"?{command:a,leadingArgv:[],resolution:"exe-entrypoint",windowsHide:true}:{command:r,leadingArgv:[a],resolution:"node-entrypoint",windowsHide:true}:{command:o,leadingArgv:[],resolution:"unresolved-wrapper"}}return {command:o,leadingArgv:[],resolution:"direct"}}function Ae(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(`${d__namespace.default.basename(e.candidate.command)} wrapper resolved, but no executable/Node entrypoint could be resolved without shell execution.`)}function J(e){let t=be(e);return Ae({candidate:t})}function K(e,t){return {command:e.command,argv:[...e.leadingArgv,...t],resolution:e.resolution,shell:e.shell,windowsHide:e.windowsHide}}var z=3e4;function De(e){if(typeof e.pid!="number"){e.kill();return}if(process.platform==="win32"){child_process.spawn("taskkill",["/pid",String(e.pid),"/t","/f"],{windowsHide:true}).on("error",()=>{});return}try{process.kill(-e.pid,"SIGKILL");}catch{e.kill("SIGKILL");}}var Q=(e,t,n={})=>new Promise((r,i)=>{let l=n.env??process.env,o=process.platform,s;try{let p=J({command:e,platform:o,env:l,cwd:n.cwd,allowShellFallback:!1});s=K(p,t);}catch(p){i(p instanceof Error?p:new Error(String(p)));return}let a=child_process.spawn(s.command,s.argv,{cwd:n.cwd,env:l,shell:s.shell,windowsHide:s.windowsHide??true,detached:o!=="win32"}),c="",h="",m=false,u=setTimeout(()=>{m||(m=true,De(a),i(new Error(`Command timed out after ${n.timeoutMs??z}ms: ${e} ${t.join(" ")}`)));},n.timeoutMs??z);a.stdout?.on("data",p=>{c+=p.toString();}),a.stderr?.on("data",p=>{h+=p.toString();}),a.on("error",p=>{m||(m=true,clearTimeout(u),i(p));}),a.on("close",p=>{m||(m=true,clearTimeout(u),r({code:p??0,stdout:c,stderr:h}));});});function Fe(){try{return (typeof D=="function"?D:module$1.createRequire(__filename)).resolve("@crewx/sdk/package.json")}catch{return null}}function Me(){let e=[Fe(),d.join(__dirname,"../../package.json"),d.join(__dirname,"../../../package.json")].filter(t=>!!t);for(let t of e)try{let n=JSON.parse(fs.readFileSync(t,"utf8"));if(n.name==="@crewx/sdk"&&n.version)return n.version}catch{}return "0.0.0"}var Z=Me();var P=d__namespace.win32;function W(e){return P.join(e,".crewx")}function te(e){return P.join(W(e),"shortcut.json")}function ne(e){return P.join(W(e),"launcher.json")}function re(e){return P.join(W(e),"bin","crewx-launcher.cmd")}function oe(e){return P.join(e,"CrewX.lnk")}function T(e,t){return P.normalize(e).toLowerCase()===P.normalize(t).toLowerCase()}var Be="[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Environment]::GetFolderPath('DesktopDirectory')";async function se(e){try{let n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",Be],{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:P.join(t,"Desktop"),source:"fallback"}:null}function F(e,t){let n=P.resolve(t,"node_modules",".bin").toLowerCase();return e.split(";").filter(r=>r?P.resolve(r).toLowerCase()!==n:true).join(";")}function ie(e){return e?/\\Program Files( \(x86\))?\\/i.test(e)&&/crewx/i.test(e):false}function $e(e,t){let n=a=>{let[c,...h]=a.split("-"),m=h.join("-")||void 0;return {parts:(c??"").split(".").map(p=>Number.parseInt(p,10)||0),pre:m}},r=n(e),i=n(t),l=Math.max(r.parts.length,i.parts.length);for(let a=0;a<l;a++){let c=r.parts[a]??0,h=i.parts[a]??0;if(c!==h)return c<h?-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),s=Number.parseInt(i.pre.match(/(\d+)$/)?.[1]??"",10);return !Number.isNaN(o)&&!Number.isNaN(s)&&o!==s?o<s?-1:1:r.pre<i.pre?-1:r.pre>i.pre?1:0}function C(e,t){return $e(e,t)<0}var ce=d__namespace.win32,le=1;function ue(e,t){if(!e.existsSync(t))return null;try{let n=JSON.parse(e.readFileSync(t));return {schema:n.schema??le,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 O(e,t,n){let r={schema:le,...n,updatedAt:new Date().toISOString()};e.mkdirSync(ce.dirname(t)),e.writeFileSync(t,JSON.stringify(r,null,2));}function b(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 de(e,t,n){e.mkdirSync(ce.dirname(t)),e.writeFileSync(t,JSON.stringify(n,null,2));}var He=d__namespace.win32,x=1;function Ve(e){return e.replace(/%/g,"%%")}function Xe(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=${Ve(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 fe(e){let t=b(e.fs,e.launcherManifestPath),n=!!t&&t.schema>=x&&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=Xe({bakedBinPath:e.bakedBinPath});try{e.fs.mkdirSync(He.dirname(e.wrapperPath)),e.fs.writeFileSync(e.wrapperPath,l),de(e.fs,e.launcherManifestPath,{schema:x,binPath:e.bakedBinPath,updatedAt:new Date().toISOString()});}catch(o){throw o instanceof f?o:new f("WRITE_DENIED",`Could not write launcher wrapper: ${o instanceof Error?o.message:String(o)}`)}return {wrapperPath:e.wrapperPath,wrote:true,schema:x}}var Ge=["$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("; "),Ue=["[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 he(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",Ge],{env:t});}catch(r){throw new f("POWERSHELL_UNAVAILABLE",`Could not run PowerShell: ${r instanceof Error?r.message:String(r)}`)}if(n.code!==0)throw new f("POWERSHELL_UNAVAILABLE",`Failed to create desktop shortcut: ${n.stderr||n.stdout}`)}function me(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 ge(e){try{let t={...e.env,CREWX_LNK_PATH:e.shortcutPath},n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",Ue],{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 B=d__namespace.win32;async function I(e){let t=F(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 a=await e.run("npm",["prefix","-g"],{env:n});a.code===0&&(o=a.stdout.trim()||void 0);}catch{}let s=o?B.join(o,"crewx.cmd"):void 0;return {installed:true,version:l.version,binPath:s,prefix:o}}var je=/EACCES|EPERM|EROFS/,Je=/ENOTFOUND|ETIMEDOUT|ECONNREFUSED|network|registry/i,Ke=/^\d+\.\d+\.\d+/;function ze(e){return !!e&&e!=="0.0.0"&&Ke.test(e)}var M=10*6e4;async function Se(e){if(!ze(e.targetVersion))throw new f("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&&!C(e.currentInfo.version,e.targetVersion))return {info:e.currentInfo};let t=F(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:M});}catch(o){throw new f("NPM_UNAVAILABLE",`Could not run npm: ${o instanceof Error?o.message:String(o)}`)}if(i.code===0)return {info:await I({env:n,cwd:e.cwd,run:e.run})};let l=`${i.stdout}
3
+ ${i.stderr}`;if(je.test(l)){e.onProgress?.({phase:"global-install",message:"Permission denied \u2014 retrying with a user-scoped npm prefix"});let o=e.env.LOCALAPPDATA||B.join(e.env.USERPROFILE??"","AppData","Local"),s={...n,npm_config_prefix:B.join(o,"crewx","npm")},a;try{a=await e.run("npm",["install","-g",r,"--no-audit","--no-fund"],{env:s,timeoutMs:M});}catch(c){throw new f("NPM_PERMISSION_DENIED",`Retry with user-scoped prefix failed: ${c instanceof Error?c.message:String(c)}`)}if(a.code===0)return {info:await I({env:s,cwd:e.cwd,run:e.run})};throw new f("NPM_PERMISSION_DENIED",`npm install -g failed after user-scoped prefix retry: ${a.stderr||a.stdout}`)}if(Je.test(l)){if(!e.installRoot)throw new f("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:M});}catch(s){throw new f("GLOBAL_INSTALL_FAILED",`Offline install failed: ${s instanceof Error?s.message:String(s)}`)}if(o.code===0)return {info:await I({env:n,cwd:e.cwd,run:e.run})};throw new f("GLOBAL_INSTALL_FAILED",`Offline install failed: ${o.stderr||o.stdout}`)}throw new f("GLOBAL_INSTALL_FAILED",l.trim()||`npm install -g ${r} failed`)}function Qe(e){return e.run??Q}function Ye(e){return e.fs??X}async function A(e){let t=e.platform??process.platform,n=e.env??process.env,r=e.homedir??G,i=Qe(e),l=Ye(e),o=e.runningVersion??Z,s=e.cwd??process.cwd(),a=r(),c=te(a),h=ne(a),m=re(a),u=null;t==="win32"&&(u=await se({env:n,homedir:r,run:i}));let p=u?oe(u.dir):null;return {platform:t,env:n,homedir:r,run:i,fs:l,runningVersion:o,cwd:s,installRoot:e.installRoot,shortcutManifestPath:c,launcherManifestPath:h,wrapperPath:m,desktop:u,shortcutPath:p}}function Pe(e){return e?d__namespace.win32.normalize(e).toLowerCase().endsWith(`${d__namespace.win32.sep}bin${d__namespace.win32.sep}crewx.ico`):false}function $(e,t){let n=e.readBinaryFileSync;if(n)try{return crypto.createHash("sha256").update(n(t)).digest("hex")}catch{return}}async function Ze(e){try{await e.run("ie4uinit.exe",["-show"],{env:e.env});}catch{}}async function E(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=ue(e.fs,e.shortcutManifestPath),r=b(e.fs,e.launcherManifestPath),i=await I({env:e.env,cwd:e.cwd,run:e.run}),l=e.shortcutPath?e.fs.existsSync(e.shortcutPath):false,o,s=false,a,c;if(!l)o=n?.declined?"declined":"not-installed";else {let h=!!n?.owned&&!!e.shortcutPath&&n.shortcutPath===e.shortcutPath,m=false,u=e.shortcutPath?await ge({run:e.run,env:e.env,shortcutPath:e.shortcutPath}):null;if(h||(u&&T(u.targetPath,e.wrapperPath)?h=true:u&&ie(u.targetPath)&&(m=true)),m)o="foreign",t.push("NSIS_PRESENT: an NSIS-installed CrewX shortcut was detected");else if(!h)o="foreign";else if(n?.version&&C(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 p=!r||r.schema<x||!e.fs.existsSync(e.wrapperPath);if(u){let w=me(u.iconLocation);if(!(!!w&&e.fs.existsSync(w)))s=true;else {a=w;let g=Ee(i,e.fs);g?T(w,g)?(c=$(e.fs,w),s=!c||n?.iconHash!==c):s=true:Pe(w)?(c=$(e.fs,w),s=!c||n?.iconHash!==c):s=true;}}o=p||s?"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:s,iconPath:a,iconHash:c}}function Ee(e,t){if(!e?.installed||!e.prefix)return;let n=d__namespace.win32.join(e.prefix,"node_modules","crewx","bin","crewx.ico");return t.existsSync(n)?n:void 0}function R(e){let{manifest:t,iconStale:n,iconPath:r,iconHash:i,...l}=e;return l}async function et(e={}){let t=await A(e),n=await E(t);return R(n)}async function tt(e={}){let t=await A(e);e.onProgress?.({phase:"detect",message:"Checking current shortcut status"});let n=await E(t),r=R(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(g=>g.startsWith("NSIS_PRESENT")))throw new f("NSIS_PRESENT",`An NSIS-installed CrewX shortcut was detected at ${r.shortcutPath}`);if(!e.force)throw new f("FOREIGN_SHORTCUT",`An existing shortcut at ${r.shortcutPath} is not managed by CrewX`)}if(!t.desktop||!t.shortcutPath)throw new f("NO_DESKTOP_DIR","Could not resolve the Windows Desktop directory");let i=false,l=false,o=r.globalCrewx,s=[],a=n.manifest?.iconHash,c=false;if(!!o?.installed&&!!o.version&&C(o.version,t.runningVersion)||!o?.installed&&r.state!=="installed"){let g=await Se({env:t.env,cwd:t.cwd,run:t.run,targetVersion:t.runningVersion,currentInfo:o??void 0,installRoot:t.installRoot,onProgress:e.onProgress});o=g.info,l=g.info.installed,i=true,l||s.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"}),fe({fs:t.fs,wrapperPath:t.wrapperPath,launcherManifestPath:t.launcherManifestPath,bakedBinPath:o?.binPath}).wrote&&(i=true),!((r.state==="installed"||r.state==="stale")&&!n.iconStale)){let g=Ee(o,t.fs)??(n.iconPath&&Pe(n.iconPath)&&t.fs.existsSync(n.iconPath)?n.iconPath:void 0);if(n.iconStale&&!g)throw new f("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 he({run:t.run,env:t.env,shortcutPath:t.shortcutPath,targetPath:t.wrapperPath,iconPath:g}),i=true,c=n.iconStale;let k=g?$(t.fs,g):void 0;k&&(a=k);}i&&O(t.fs,t.shortcutManifestPath,{shortcutPath:t.shortcutPath,version:t.runningVersion,owned:true,declined:false,desktopSource:t.desktop.source,iconHash:a}),c&&await Ze(t);let w=await E(t),y=R(w);return {...y,errors:[...y.errors,...s],changed:i,installedGlobal:l}}async function nt(e={}){let t=await A(e),n=await E(t),r=R(n);if(!r.supported)return r;if((r.state==="installed"||r.state==="stale")&&t.shortcutPath)try{t.fs.unlinkSync(t.shortcutPath);}catch{}O(t.fs,t.shortcutManifestPath,{shortcutPath:void 0,version:n.manifest?.version,owned:false,declined:true,desktopSource:void 0,iconHash:void 0});let i=await E(t);return R(i)}async function rt(e={}){let t=await A(e),n=await E(t),r=R(n);if(!r.supported)return r;O(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 E(t);return R(i)}exports.ShortcutError=f;exports.dismissShortcutNotice=rt;exports.getShortcutStatus=et;exports.installShortcut=tt;exports.uninstallShortcut=nt;
@@ -0,0 +1,5 @@
1
+ import { type InstallShortcutOptions, type ShortcutEnvOptions, type ShortcutInstallResult, type ShortcutStatus } from './types';
2
+ export declare function getShortcutStatus(options?: ShortcutEnvOptions): Promise<ShortcutStatus>;
3
+ export declare function installShortcut(options?: InstallShortcutOptions): Promise<ShortcutInstallResult>;
4
+ export declare function uninstallShortcut(options?: ShortcutEnvOptions): Promise<ShortcutStatus>;
5
+ export declare function dismissShortcutNotice(options?: ShortcutEnvOptions): Promise<ShortcutStatus>;
@@ -0,0 +1,22 @@
1
+ import type { CommandRunner } from './types';
2
+ export interface WriteLnkOptions {
3
+ run: CommandRunner;
4
+ env: NodeJS.ProcessEnv;
5
+ shortcutPath: string;
6
+ targetPath: string;
7
+ workingDirectory?: string;
8
+ iconPath?: string;
9
+ }
10
+ export declare function writeLnk(opts: WriteLnkOptions): Promise<void>;
11
+ export interface LnkInfo {
12
+ targetPath: string;
13
+ workingDirectory: string;
14
+ iconLocation: string;
15
+ }
16
+ export interface ReadLnkOptions {
17
+ run: CommandRunner;
18
+ env: NodeJS.ProcessEnv;
19
+ shortcutPath: string;
20
+ }
21
+ export declare function normalizeIconLocation(raw: string): string;
22
+ export declare function readLnkTarget(opts: ReadLnkOptions): Promise<LnkInfo | null>;
@@ -0,0 +1,21 @@
1
+ import type { DesktopSource, ShortcutFsLike } from './types';
2
+ export declare const MANIFEST_SCHEMA_VERSION = 1;
3
+ export interface ShortcutManifest {
4
+ schema: number;
5
+ shortcutPath?: string;
6
+ version?: string;
7
+ iconHash?: string;
8
+ owned: boolean;
9
+ declined: boolean;
10
+ desktopSource?: DesktopSource;
11
+ updatedAt?: string;
12
+ }
13
+ export interface LauncherManifest {
14
+ schema: number;
15
+ binPath?: string;
16
+ updatedAt?: string;
17
+ }
18
+ export declare function readShortcutManifest(fs: ShortcutFsLike, manifestPath: string): ShortcutManifest | null;
19
+ export declare function writeShortcutManifest(fs: ShortcutFsLike, manifestPath: string, data: Omit<ShortcutManifest, 'schema' | 'updatedAt'>): void;
20
+ export declare function readLauncherManifest(fs: ShortcutFsLike, manifestPath: string): LauncherManifest | null;
21
+ export declare function writeLauncherManifest(fs: ShortcutFsLike, manifestPath: string, data: LauncherManifest): void;
@@ -0,0 +1,67 @@
1
+ export type ShortcutState = 'unsupported' | 'not-installed' | 'installed' | 'stale' | 'foreign' | 'superseded' | 'declined';
2
+ export type DesktopSource = 'known-folder' | 'fallback';
3
+ export interface GlobalCrewxInfo {
4
+ installed: boolean;
5
+ version?: string;
6
+ binPath?: string;
7
+ prefix?: string;
8
+ }
9
+ export interface ShortcutStatus {
10
+ supported: boolean;
11
+ state: ShortcutState;
12
+ shortcutPath?: string;
13
+ desktopDir?: string;
14
+ desktopSource?: DesktopSource;
15
+ wrapperPath?: string;
16
+ wrapperSchema?: number;
17
+ globalCrewx: GlobalCrewxInfo | null;
18
+ runningVersion: string;
19
+ errors: string[];
20
+ }
21
+ export interface ShortcutInstallResult extends ShortcutStatus {
22
+ changed: boolean;
23
+ installedGlobal: boolean;
24
+ }
25
+ export type ShortcutProgressPhase = 'detect' | 'global-install' | 'wrapper' | 'lnk';
26
+ export interface ShortcutProgressEvent {
27
+ phase: ShortcutProgressPhase;
28
+ message: string;
29
+ }
30
+ export interface CommandResult {
31
+ code: number;
32
+ stdout: string;
33
+ stderr: string;
34
+ }
35
+ export interface CommandRunOptions {
36
+ env?: NodeJS.ProcessEnv;
37
+ cwd?: string;
38
+ timeoutMs?: number;
39
+ }
40
+ export type CommandRunner = (command: string, args: string[], opts?: CommandRunOptions) => Promise<CommandResult>;
41
+ export interface ShortcutFsLike {
42
+ existsSync(path: string): boolean;
43
+ readFileSync(path: string): string;
44
+ readBinaryFileSync?: (path: string) => Uint8Array;
45
+ writeFileSync(path: string, data: string): void;
46
+ mkdirSync(path: string): void;
47
+ unlinkSync(path: string): void;
48
+ }
49
+ export interface ShortcutEnvOptions {
50
+ platform?: NodeJS.Platform;
51
+ env?: NodeJS.ProcessEnv;
52
+ homedir?: () => string;
53
+ run?: CommandRunner;
54
+ fs?: ShortcutFsLike;
55
+ runningVersion?: string;
56
+ cwd?: string;
57
+ }
58
+ export interface InstallShortcutOptions extends ShortcutEnvOptions {
59
+ force?: boolean;
60
+ onProgress?: (event: ShortcutProgressEvent) => void;
61
+ installRoot?: string;
62
+ }
63
+ export type ShortcutErrorCode = 'NOT_WINDOWS' | 'NO_DESKTOP_DIR' | 'NPM_UNAVAILABLE' | 'NPM_PERMISSION_DENIED' | 'OFFLINE_NO_SOURCE' | 'GLOBAL_INSTALL_FAILED' | 'POWERSHELL_UNAVAILABLE' | 'WRITE_DENIED' | 'FOREIGN_SHORTCUT' | 'NSIS_PRESENT' | 'ICON_UNAVAILABLE';
64
+ export declare class ShortcutError extends Error {
65
+ readonly code: ShortcutErrorCode;
66
+ constructor(code: ShortcutErrorCode, message: string);
67
+ }
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION: string;
@@ -0,0 +1,21 @@
1
+ import type { CommandRunner, DesktopSource } from './types';
2
+ export declare function crewxHomeDir(homedir: string): string;
3
+ export declare function shortcutManifestPath(homedir: string): string;
4
+ export declare function launcherManifestPath(homedir: string): string;
5
+ export declare function wrapperPath(homedir: string): string;
6
+ export declare function shortcutLnkPath(desktopDir: string): string;
7
+ export declare function samePath(a: string, b: string): boolean;
8
+ export interface ResolveDesktopDirOptions {
9
+ env: NodeJS.ProcessEnv;
10
+ homedir: () => string;
11
+ run: CommandRunner;
12
+ }
13
+ export interface ResolvedDesktopDir {
14
+ dir: string;
15
+ source: DesktopSource;
16
+ }
17
+ export declare function resolveDesktopDir(opts: ResolveDesktopDirOptions): Promise<ResolvedDesktopDir | null>;
18
+ export declare function filterWorkspaceLocalBin(pathValue: string, cwd: string): string;
19
+ export declare function looksLikeNsisInstall(targetPath: string): boolean;
20
+ export declare function compareVersions(a: string, b: string): -1 | 0 | 1;
21
+ export declare function isOlderVersion(a: string, b: string): boolean;
@@ -0,0 +1,18 @@
1
+ import type { ShortcutFsLike } from './types';
2
+ export declare const WRAPPER_SCHEMA_VERSION = 1;
3
+ export interface BuildWrapperScriptOptions {
4
+ bakedBinPath?: string;
5
+ }
6
+ export declare function buildWrapperScript(opts: BuildWrapperScriptOptions): string;
7
+ export interface EnsureWrapperOptions {
8
+ fs: ShortcutFsLike;
9
+ wrapperPath: string;
10
+ launcherManifestPath: string;
11
+ bakedBinPath?: string;
12
+ }
13
+ export interface EnsureWrapperResult {
14
+ wrapperPath: string;
15
+ wrote: boolean;
16
+ schema: number;
17
+ }
18
+ export declare function ensureWrapper(opts: EnsureWrapperOptions): EnsureWrapperResult;
@@ -0,0 +1,3 @@
1
+ import*as d from'path';import d__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 {spawn}from'child_process';import {createRequire}from'module';var W=(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 X=()=>fileURLToPath(import.meta.url),xe=()=>d__default.dirname(X()),w=xe(),P=X();var f=class extends Error{code;constructor(t,n){super(`${t}: ${n}`),this.code=t,this.name="ShortcutError";}};var U={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);}},j=homedir;function N(e){return typeof e!="string"?void 0:e.trim()||void 0}function O(e){return N(e)?.toLowerCase()??""}function y(e){try{return statSync(e).isFile()}catch{return false}}function be(e,t){if(e===t)return true;let n=d__default.relative(e,t);return n!==""&&!n.startsWith("..")&&!d__default.isAbsolute(n)}function Ae(e,t){if(d__default.basename(e)!==".bin")return false;let n=d__default.dirname(e);if(d__default.basename(n)!=="node_modules")return false;let r=d__default.dirname(n);return be(r,t)}function J(e,t={}){if(e.includes("/")||e.includes("\\")||d__default.isAbsolute(e))return e;let n=t.platform??process.platform,r=t.env??process.env,i=d__default.resolve(t.cwd??process.cwd()),l=(t.resolution??"global_first")==="global_first",o=r.PATH??r.Path??process.env.PATH??process.env.Path??"",s=n==="win32"?";":":",a=o.split(s).map(u=>u.trim()).filter(Boolean),c=d__default.extname(e).length>0,h=r.PATHEXT??r.Pathext??process.env.PATHEXT??process.env.Pathext??".EXE;.CMD;.BAT;.COM",m=n==="win32"?c?[""]:h.split(";").map(u=>u.trim()).filter(Boolean).map(u=>u.startsWith(".")?u:`.${u}`):[""];for(let u of a){let p=d__default.resolve(i,u);if(!(l&&Ae(p,i)))for(let S of m){let C=O(S),g=S.toUpperCase();for(let _ of [S,C,g]){let V=d__default.join(p,`${e}${_}`);if(y(V))return V}}}return e}function De(e){if(!y(e))return null;try{let t=readFileSync(e,"utf8"),n=d__default.dirname(e),r=[];for(let s of t.matchAll(/"([^"\r\n]*)"/g)){let h=(s[1]??"").match(/%~?dp0%?\s*[\\/]*(.*)$/i)?.[1]?.trim();if(!h)continue;let m=h.replace(/[\\/]+/g,d__default.sep).replace(/^[\\/]+/,""),u=d__default.resolve(n,m);y(u)&&r.push(u);}let i=[],l=new Map;for(let s of t.matchAll(/SET\s+"(\w+)=%~?dp0%?[\\/]?([^"]+)"/gi)){let a=s[1].toUpperCase(),c=s[2].trim().replace(/[\\/]+/g,d__default.sep).replace(/^[\\/]+/,"");l.set(a,d__default.resolve(n,c));}for(let s of t.split(/\r?\n/))if(s.includes("%*"))for(let a of s.matchAll(/"%(\w+)%"/g)){let c=l.get(a[1].toUpperCase());c&&y(c)&&i.push(c);}let o=s=>s.find(a=>{let c=O(d__default.basename(a));return c!=="node.exe"&&c!=="node"})??null;return o(i)??o(r)}catch{return null}}function We(e,t){if(typeof t=="string")return N(t)||null;if(!t||typeof t!="object")return null;if(e){let n=t[e],r=typeof n=="string"?N(n):void 0;if(r)return r}for(let n of Object.values(t)){let r=typeof n=="string"?N(n):void 0;if(r)return r}return null}function Te(e,t){if(!t)return null;let n=d__default.dirname(e),r=[d__default.resolve(n,"..",t),d__default.resolve(n,"node_modules",t)];for(let i of r){let l=d__default.join(i,"package.json");if(y(l))try{let o=JSON.parse(readFileSync(l,"utf8")),s=We(t,o.bin);if(!s)continue;let a=d__default.resolve(i,s);if(y(a))return a}catch{}}return null}function Fe(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:J(e.command,{cwd:i,env:n,platform:t,resolution:l}),leadingArgv:[],resolution:"direct"};let o=J(e.command,{cwd:i,env:n,platform:t,resolution:l}),s=O(d__default.extname(o));if(s===".js"||s===".cjs"||s===".mjs")return {command:r,leadingArgv:[o],resolution:"node-entrypoint",windowsHide:true};if(s===".cmd"||s===".bat"){let a=De(o)??Te(o,e.packageName);return a?O(d__default.extname(a))===".exe"?{command:a,leadingArgv:[],resolution:"exe-entrypoint",windowsHide:true}:{command:r,leadingArgv:[a],resolution:"node-entrypoint",windowsHide:true}:{command:o,leadingArgv:[],resolution:"unresolved-wrapper"}}return {command:o,leadingArgv:[],resolution:"direct"}}function Me(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(`${d__default.basename(e.candidate.command)} wrapper resolved, but no executable/Node entrypoint could be resolved without shell execution.`)}function z(e){let t=Fe(e);return Me({candidate:t})}function q(e,t){return {command:e.command,argv:[...e.leadingArgv,...t],resolution:e.resolution,shell:e.shell,windowsHide:e.windowsHide}}var Q=3e4;function Be(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 Z=(e,t,n={})=>new Promise((r,i)=>{let l=n.env??process.env,o=process.platform,s;try{let p=z({command:e,platform:o,env:l,cwd:n.cwd,allowShellFallback:!1});s=q(p,t);}catch(p){i(p instanceof Error?p:new Error(String(p)));return}let a=spawn(s.command,s.argv,{cwd:n.cwd,env:l,shell:s.shell,windowsHide:s.windowsHide??true,detached:o!=="win32"}),c="",h="",m=false,u=setTimeout(()=>{m||(m=true,Be(a),i(new Error(`Command timed out after ${n.timeoutMs??Q}ms: ${e} ${t.join(" ")}`)));},n.timeoutMs??Q);a.stdout?.on("data",p=>{c+=p.toString();}),a.stderr?.on("data",p=>{h+=p.toString();}),a.on("error",p=>{m||(m=true,clearTimeout(u),i(p));}),a.on("close",p=>{m||(m=true,clearTimeout(u),r({code:p??0,stdout:c,stderr:h}));});});function Ve(){try{return (typeof W=="function"?W:createRequire(P)).resolve("@crewx/sdk/package.json")}catch{return null}}function Xe(){let e=[Ve(),join(w,"../../package.json"),join(w,"../../../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 te=Xe();var E=d.win32;function T(e){return E.join(e,".crewx")}function re(e){return E.join(T(e),"shortcut.json")}function oe(e){return E.join(T(e),"launcher.json")}function se(e){return E.join(T(e),"bin","crewx-launcher.cmd")}function ie(e){return E.join(e,"CrewX.lnk")}function F(e,t){return E.normalize(e).toLowerCase()===E.normalize(t).toLowerCase()}var Ge="[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; [Environment]::GetFolderPath('DesktopDirectory')";async function ae(e){try{let n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",Ge],{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:E.join(t,"Desktop"),source:"fallback"}:null}function M(e,t){let n=E.resolve(t,"node_modules",".bin").toLowerCase();return e.split(";").filter(r=>r?E.resolve(r).toLowerCase()!==n:true).join(";")}function ce(e){return e?/\\Program Files( \(x86\))?\\/i.test(e)&&/crewx/i.test(e):false}function Ue(e,t){let n=a=>{let[c,...h]=a.split("-"),m=h.join("-")||void 0;return {parts:(c??"").split(".").map(p=>Number.parseInt(p,10)||0),pre:m}},r=n(e),i=n(t),l=Math.max(r.parts.length,i.parts.length);for(let a=0;a<l;a++){let c=r.parts[a]??0,h=i.parts[a]??0;if(c!==h)return c<h?-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),s=Number.parseInt(i.pre.match(/(\d+)$/)?.[1]??"",10);return !Number.isNaN(o)&&!Number.isNaN(s)&&o!==s?o<s?-1:1:r.pre<i.pre?-1:r.pre>i.pre?1:0}function x(e,t){return Ue(e,t)<0}var ue=d.win32,de=1;function pe(e,t){if(!e.existsSync(t))return null;try{let n=JSON.parse(e.readFileSync(t));return {schema:n.schema??de,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 b(e,t,n){let r={schema:de,...n,updatedAt:new Date().toISOString()};e.mkdirSync(ue.dirname(t)),e.writeFileSync(t,JSON.stringify(r,null,2));}function A(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 fe(e,t,n){e.mkdirSync(ue.dirname(t)),e.writeFileSync(t,JSON.stringify(n,null,2));}var je=d.win32,L=1;function Je(e){return e.replace(/%/g,"%%")}function Ke(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=${Je(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 me(e){let t=A(e.fs,e.launcherManifestPath),n=!!t&&t.schema>=L&&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=Ke({bakedBinPath:e.bakedBinPath});try{e.fs.mkdirSync(je.dirname(e.wrapperPath)),e.fs.writeFileSync(e.wrapperPath,l),fe(e.fs,e.launcherManifestPath,{schema:L,binPath:e.bakedBinPath,updatedAt:new Date().toISOString()});}catch(o){throw o instanceof f?o:new f("WRITE_DENIED",`Could not write launcher wrapper: ${o instanceof Error?o.message:String(o)}`)}return {wrapperPath:e.wrapperPath,wrote:true,schema:L}}var ze=["$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("; "),qe=["[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 ge(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",ze],{env:t});}catch(r){throw new f("POWERSHELL_UNAVAILABLE",`Could not run PowerShell: ${r instanceof Error?r.message:String(r)}`)}if(n.code!==0)throw new f("POWERSHELL_UNAVAILABLE",`Failed to create desktop shortcut: ${n.stderr||n.stdout}`)}function we(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 Se(e){try{let t={...e.env,CREWX_LNK_PATH:e.shortcutPath},n=await e.run("powershell",["-NoProfile","-NonInteractive","-Command",qe],{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 $=d.win32;async function I(e){let t=M(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 a=await e.run("npm",["prefix","-g"],{env:n});a.code===0&&(o=a.stdout.trim()||void 0);}catch{}let s=o?$.join(o,"crewx.cmd"):void 0;return {installed:true,version:l.version,binPath:s,prefix:o}}var Qe=/EACCES|EPERM|EROFS/,Ye=/ENOTFOUND|ETIMEDOUT|ECONNREFUSED|network|registry/i,Ze=/^\d+\.\d+\.\d+/;function et(e){return !!e&&e!=="0.0.0"&&Ze.test(e)}var B=10*6e4;async function Ee(e){if(!et(e.targetVersion))throw new f("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&&!x(e.currentInfo.version,e.targetVersion))return {info:e.currentInfo};let t=M(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:B});}catch(o){throw new f("NPM_UNAVAILABLE",`Could not run npm: ${o instanceof Error?o.message:String(o)}`)}if(i.code===0)return {info:await I({env:n,cwd:e.cwd,run:e.run})};let l=`${i.stdout}
3
+ ${i.stderr}`;if(Qe.test(l)){e.onProgress?.({phase:"global-install",message:"Permission denied \u2014 retrying with a user-scoped npm prefix"});let o=e.env.LOCALAPPDATA||$.join(e.env.USERPROFILE??"","AppData","Local"),s={...n,npm_config_prefix:$.join(o,"crewx","npm")},a;try{a=await e.run("npm",["install","-g",r,"--no-audit","--no-fund"],{env:s,timeoutMs:B});}catch(c){throw new f("NPM_PERMISSION_DENIED",`Retry with user-scoped prefix failed: ${c instanceof Error?c.message:String(c)}`)}if(a.code===0)return {info:await I({env:s,cwd:e.cwd,run:e.run})};throw new f("NPM_PERMISSION_DENIED",`npm install -g failed after user-scoped prefix retry: ${a.stderr||a.stdout}`)}if(Ye.test(l)){if(!e.installRoot)throw new f("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:B});}catch(s){throw new f("GLOBAL_INSTALL_FAILED",`Offline install failed: ${s instanceof Error?s.message:String(s)}`)}if(o.code===0)return {info:await I({env:n,cwd:e.cwd,run:e.run})};throw new f("GLOBAL_INSTALL_FAILED",`Offline install failed: ${o.stderr||o.stdout}`)}throw new f("GLOBAL_INSTALL_FAILED",l.trim()||`npm install -g ${r} failed`)}function nt(e){return e.run??Z}function rt(e){return e.fs??U}async function D(e){let t=e.platform??process.platform,n=e.env??process.env,r=e.homedir??j,i=nt(e),l=rt(e),o=e.runningVersion??te,s=e.cwd??process.cwd(),a=r(),c=re(a),h=oe(a),m=se(a),u=null;t==="win32"&&(u=await ae({env:n,homedir:r,run:i}));let p=u?ie(u.dir):null;return {platform:t,env:n,homedir:r,run:i,fs:l,runningVersion:o,cwd:s,installRoot:e.installRoot,shortcutManifestPath:c,launcherManifestPath:h,wrapperPath:m,desktop:u,shortcutPath:p}}function Re(e){return e?d.win32.normalize(e).toLowerCase().endsWith(`${d.win32.sep}bin${d.win32.sep}crewx.ico`):false}function H(e,t){let n=e.readBinaryFileSync;if(n)try{return createHash("sha256").update(n(t)).digest("hex")}catch{return}}async function ot(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=pe(e.fs,e.shortcutManifestPath),r=A(e.fs,e.launcherManifestPath),i=await I({env:e.env,cwd:e.cwd,run:e.run}),l=e.shortcutPath?e.fs.existsSync(e.shortcutPath):false,o,s=false,a,c;if(!l)o=n?.declined?"declined":"not-installed";else {let h=!!n?.owned&&!!e.shortcutPath&&n.shortcutPath===e.shortcutPath,m=false,u=e.shortcutPath?await Se({run:e.run,env:e.env,shortcutPath:e.shortcutPath}):null;if(h||(u&&F(u.targetPath,e.wrapperPath)?h=true:u&&ce(u.targetPath)&&(m=true)),m)o="foreign",t.push("NSIS_PRESENT: an NSIS-installed CrewX shortcut was detected");else if(!h)o="foreign";else if(n?.version&&x(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 p=!r||r.schema<L||!e.fs.existsSync(e.wrapperPath);if(u){let S=we(u.iconLocation);if(!(!!S&&e.fs.existsSync(S)))s=true;else {a=S;let g=ve(i,e.fs);g?F(S,g)?(c=H(e.fs,S),s=!c||n?.iconHash!==c):s=true:Re(S)?(c=H(e.fs,S),s=!c||n?.iconHash!==c):s=true;}}o=p||s?"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:s,iconPath:a,iconHash:c}}function ve(e,t){if(!e?.installed||!e.prefix)return;let n=d.win32.join(e.prefix,"node_modules","crewx","bin","crewx.ico");return t.existsSync(n)?n:void 0}function v(e){let{manifest:t,iconStale:n,iconPath:r,iconHash:i,...l}=e;return l}async function st(e={}){let t=await D(e),n=await R(t);return v(n)}async function it(e={}){let t=await D(e);e.onProgress?.({phase:"detect",message:"Checking current shortcut status"});let n=await R(t),r=v(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(g=>g.startsWith("NSIS_PRESENT")))throw new f("NSIS_PRESENT",`An NSIS-installed CrewX shortcut was detected at ${r.shortcutPath}`);if(!e.force)throw new f("FOREIGN_SHORTCUT",`An existing shortcut at ${r.shortcutPath} is not managed by CrewX`)}if(!t.desktop||!t.shortcutPath)throw new f("NO_DESKTOP_DIR","Could not resolve the Windows Desktop directory");let i=false,l=false,o=r.globalCrewx,s=[],a=n.manifest?.iconHash,c=false;if(!!o?.installed&&!!o.version&&x(o.version,t.runningVersion)||!o?.installed&&r.state!=="installed"){let g=await Ee({env:t.env,cwd:t.cwd,run:t.run,targetVersion:t.runningVersion,currentInfo:o??void 0,installRoot:t.installRoot,onProgress:e.onProgress});o=g.info,l=g.info.installed,i=true,l||s.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"}),me({fs:t.fs,wrapperPath:t.wrapperPath,launcherManifestPath:t.launcherManifestPath,bakedBinPath:o?.binPath}).wrote&&(i=true),!((r.state==="installed"||r.state==="stale")&&!n.iconStale)){let g=ve(o,t.fs)??(n.iconPath&&Re(n.iconPath)&&t.fs.existsSync(n.iconPath)?n.iconPath:void 0);if(n.iconStale&&!g)throw new f("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 ge({run:t.run,env:t.env,shortcutPath:t.shortcutPath,targetPath:t.wrapperPath,iconPath:g}),i=true,c=n.iconStale;let _=g?H(t.fs,g):void 0;_&&(a=_);}i&&b(t.fs,t.shortcutManifestPath,{shortcutPath:t.shortcutPath,version:t.runningVersion,owned:true,declined:false,desktopSource:t.desktop.source,iconHash:a}),c&&await ot(t);let S=await R(t),C=v(S);return {...C,errors:[...C.errors,...s],changed:i,installedGlobal:l}}async function at(e={}){let t=await D(e),n=await R(t),r=v(n);if(!r.supported)return r;if((r.state==="installed"||r.state==="stale")&&t.shortcutPath)try{t.fs.unlinkSync(t.shortcutPath);}catch{}b(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 v(i)}async function ct(e={}){let t=await D(e),n=await R(t),r=v(n);if(!r.supported)return r;b(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 v(i)}export{f as ShortcutError,ct as dismissShortcutNotice,st as getShortcutStatus,it as installShortcut,at as uninstallShortcut};