crewx 0.9.0-rc.236 → 0.9.0-rc.238

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 (112) hide show
  1. package/bin/crewx-dispatch.js +3 -0
  2. package/bin/crewx-memory-runtime.js +7 -0
  3. package/bin/crewx.js +13 -2
  4. package/dist/assets/{DocSyncTextDiff-B0zWoWaM.js → DocSyncTextDiff-J1cEZfvG.js} +1 -1
  5. package/dist/assets/{GitDiffEditor-C6r96EgB.js → GitDiffEditor-B7cdAJ7W.js} +1 -1
  6. package/dist/assets/{MarketPage-DvMW4zkl.js → MarketPage-DjjZCS8d.js} +1 -1
  7. package/dist/assets/{MonacoDiffSurface-CcuWl3pT.js → MonacoDiffSurface-Gs0WyFXL.js} +7 -7
  8. package/dist/assets/{PromptTab-Chkwq-kt.js → PromptTab-DZdNMc19.js} +1 -1
  9. package/dist/assets/{abnfDiagram-VCTEODGH-tUUoiXwr.js → abnfDiagram-VCTEODGH-X5HbZxTM.js} +1 -1
  10. package/dist/assets/{arc-C0oqd3Uj.js → arc-Ct3vRsL-.js} +1 -1
  11. package/dist/assets/{architectureDiagram-5GKGNRK7-BRAtjzKS.js → architectureDiagram-5GKGNRK7-DwM2gdry.js} +1 -1
  12. package/dist/assets/{blockDiagram-I7D4REHJ-D7RWoAqi.js → blockDiagram-I7D4REHJ-CaxkONqQ.js} +1 -1
  13. package/dist/assets/{c4Diagram-7LVT6UL2-Bj76QJjY.js → c4Diagram-7LVT6UL2-sGcF_W47.js} +1 -1
  14. package/dist/assets/channel-CWWdmQVT.js +1 -0
  15. package/dist/assets/{chunk-2Q5K7J3B-j0V_VdQw.js → chunk-2Q5K7J3B-B1kI0qxp.js} +1 -1
  16. package/dist/assets/{chunk-5VM5RSS4-fOSRSJmV.js → chunk-5VM5RSS4-CnVV3UMX.js} +1 -1
  17. package/dist/assets/{chunk-F27PBJKO-BaxbnoID.js → chunk-F27PBJKO-Bvu6rnDn.js} +1 -1
  18. package/dist/assets/{chunk-IMKFNOWR-fl61P9Tc.js → chunk-IMKFNOWR-BWhA2P3C.js} +1 -1
  19. package/dist/assets/{chunk-JWPE2WC7-CDpqVHgQ.js → chunk-JWPE2WC7-CVTDsrje.js} +1 -1
  20. package/dist/assets/{chunk-POPQ4Y6H-D4YOBf_D.js → chunk-POPQ4Y6H-olHx95Jx.js} +1 -1
  21. package/dist/assets/{chunk-SVP7TREG-vPT0i-EI.js → chunk-SVP7TREG-CvhT8vjm.js} +1 -1
  22. package/dist/assets/{chunk-TICWLB2K-BUtVrpk2.js → chunk-TICWLB2K-BvbmH3fg.js} +1 -1
  23. package/dist/assets/{chunk-XXDRQBXY-iGZOebSf.js → chunk-XXDRQBXY-CrNQlN2X.js} +1 -1
  24. package/dist/assets/classDiagram-ZZMXUADV-BEHZXrFc.js +1 -0
  25. package/dist/assets/classDiagram-v2-VYDZK3BY-BEHZXrFc.js +1 -0
  26. package/dist/assets/{cose-bilkent-JH36ORCC-DwcYUvwx.js → cose-bilkent-JH36ORCC-D0fIGbXq.js} +1 -1
  27. package/dist/assets/{cssMode-CK5KFKmc.js → cssMode-DoSVMJfZ.js} +1 -1
  28. package/dist/assets/{cynefin-OW5HDTMX-DH7KzyEF.js → cynefin-OW5HDTMX-DExI3DBm.js} +1 -1
  29. package/dist/assets/{cynefinDiagram-5FMLGOSQ-DGo3pGRC.js → cynefinDiagram-5FMLGOSQ-Bqchsgx2.js} +1 -1
  30. package/dist/assets/{dagre-GXQ25YYZ-DGJqrJB1.js → dagre-GXQ25YYZ-DKRj9SbG.js} +1 -1
  31. package/dist/assets/{diagram-S7CK7UJ4-Oly-CyMa.js → diagram-S7CK7UJ4-aQDMFQoY.js} +1 -1
  32. package/dist/assets/{diagram-UQ7AKVKN-BYvF10fq.js → diagram-UQ7AKVKN-CQVDukiW.js} +1 -1
  33. package/dist/assets/{diagram-VSXAHHWV-B6jwfyNC.js → diagram-VSXAHHWV-K1MNBeLA.js} +1 -1
  34. package/dist/assets/{diagram-VX7I27RA-82Vv2WFM.js → diagram-VX7I27RA-DhQSfD3K.js} +1 -1
  35. package/dist/assets/{diagram-Z3DM3KII-D9vstyCx.js → diagram-Z3DM3KII-CjGJqvQf.js} +1 -1
  36. package/dist/assets/{ebnfDiagram-PWID7BFC-10Sb84-p.js → ebnfDiagram-PWID7BFC-SQnem0qi.js} +1 -1
  37. package/dist/assets/{erDiagram-RLTQ6QDP-CodsXbAu.js → erDiagram-RLTQ6QDP-CqFUXukX.js} +1 -1
  38. package/dist/assets/{flowDiagram-HODETNUW-D-gyQUZj.js → flowDiagram-HODETNUW-SpmzRY61.js} +1 -1
  39. package/dist/assets/{freemarker2-DFXIHVpq.js → freemarker2-BFl61qIr.js} +1 -1
  40. package/dist/assets/{ganttDiagram-EL5Y4UJY-DQhc5nzj.js → ganttDiagram-EL5Y4UJY-ByEQTPyc.js} +1 -1
  41. package/dist/assets/{gitGraphDiagram-WWUBYQGX-C_B3K1nG.js → gitGraphDiagram-WWUBYQGX-CfJ4hQPX.js} +1 -1
  42. package/dist/assets/{handlebars-DRz6_o-1.js → handlebars-CsonD4io.js} +1 -1
  43. package/dist/assets/{html-0AroVg0k.js → html-Bdk84Te4.js} +1 -1
  44. package/dist/assets/{htmlMode-WqiYz4uS.js → htmlMode-6vHtznEG.js} +1 -1
  45. package/dist/assets/{infoDiagram-27XIBGKW-Bfqf1hAA.js → infoDiagram-27XIBGKW-UMZeZX-k.js} +1 -1
  46. package/dist/assets/{ishikawaDiagram-5VMMS53U-D72eANQ3.js → ishikawaDiagram-5VMMS53U-eKPVkKJ-.js} +1 -1
  47. package/dist/assets/{javascript-08BvfeSf.js → javascript-d96FO6jl.js} +1 -1
  48. package/dist/assets/{journeyDiagram-3NMN7TZE-C8pcSvaQ.js → journeyDiagram-3NMN7TZE-DIBD-w04.js} +1 -1
  49. package/dist/assets/{jsonMode-BOclzYeq.js → jsonMode-CTveyt4X.js} +1 -1
  50. package/dist/assets/{kanban-definition-UXKFOSKX-Daj8tFz8.js → kanban-definition-UXKFOSKX-CutHc6E7.js} +1 -1
  51. package/dist/assets/{layout-CkShUHHC.js → layout-DJcRZhNQ.js} +1 -1
  52. package/dist/assets/{linear-CS-J-pMn.js → linear-DvvuhzAM.js} +1 -1
  53. package/dist/assets/{liquid-DOCkF1CT.js → liquid-N_KqwWu3.js} +1 -1
  54. package/dist/assets/main-BbFtintH.css +10 -0
  55. package/dist/assets/{main-2eGGGkuY.js → main-d7ppwPBl.js} +534 -534
  56. package/dist/assets/{mdx-Bn7yhsi9.js → mdx-1IhdOiY4.js} +1 -1
  57. package/dist/assets/{mindmap-definition-YA3MSWOX-CvT_scs3.js → mindmap-definition-YA3MSWOX-DjLQAFmX.js} +1 -1
  58. package/dist/assets/{pegDiagram-XKGWAZYB-TNZBouoU.js → pegDiagram-XKGWAZYB-CTo3_kUg.js} +1 -1
  59. package/dist/assets/{pieDiagram-E7YTZNPT-CmOh31X5.js → pieDiagram-E7YTZNPT-CaRbExMp.js} +1 -1
  60. package/dist/assets/{python-XjpQ2Kxn.js → python-BBNKQOf0.js} +1 -1
  61. package/dist/assets/{quadrantDiagram-AXDQQJYC-CrXRwN-0.js → quadrantDiagram-AXDQQJYC-CnMnxVz2.js} +1 -1
  62. package/dist/assets/{railroadDiagram-O6MQD6OU-DOK2g689.js → railroadDiagram-O6MQD6OU-T3CDdFay.js} +1 -1
  63. package/dist/assets/{razor-BlLc3yHt.js → razor-CSKI0BR8.js} +1 -1
  64. package/dist/assets/{requirementDiagram-BXWQKSXE-GCMJH4eT.js → requirementDiagram-BXWQKSXE-Bm1DPFEM.js} +1 -1
  65. package/dist/assets/{sankeyDiagram-P5KCCOFB-BitjJ8lr.js → sankeyDiagram-P5KCCOFB-Db6D9GE8.js} +1 -1
  66. package/dist/assets/{sequenceDiagram-WJ2MYXX4-CaytphRd.js → sequenceDiagram-WJ2MYXX4-DLxzW9XS.js} +1 -1
  67. package/dist/assets/{sizeCapture-INFHLROL-5qjMSVHu.js → sizeCapture-INFHLROL-fAGSVd0_.js} +1 -1
  68. package/dist/assets/{stateDiagram-D77RDMKH-WHxK6iEk.js → stateDiagram-D77RDMKH-9o-5WKLi.js} +1 -1
  69. package/dist/assets/stateDiagram-v2-MP3YSRHH-DXfhBM43.js +1 -0
  70. package/dist/assets/{swimlanes-42K2YHIH-DdZbY4mz.js → swimlanes-42K2YHIH-9Ed3i3tt.js} +1 -1
  71. package/dist/assets/swimlanesDiagram-VR7AAH4N-DKPIePR6.js +8 -0
  72. package/dist/assets/{timeline-definition-24CTP7MA-Bjt5woFt.js → timeline-definition-24CTP7MA-DX-6XLrk.js} +1 -1
  73. package/dist/assets/{transformers.web-D7He0GzP.js → transformers.web-Mo-sbH11.js} +1 -1
  74. package/dist/assets/{tsMode-Bvakw5Jw.js → tsMode-xRb4Q_R_.js} +1 -1
  75. package/dist/assets/{typescript-CXjer9-F.js → typescript-DlZdS9JW.js} +1 -1
  76. package/dist/assets/{vennDiagram-4TSXK5OY-97Z3XNRi.js → vennDiagram-4TSXK5OY-CXRmx4hH.js} +1 -1
  77. package/dist/assets/{wardleyDiagram-VM6X3IG4-upq2PGUx.js → wardleyDiagram-VM6X3IG4-JaP9VmDL.js} +1 -1
  78. package/dist/assets/{xml-BFH9EkR1.js → xml-BLt-z2aW.js} +1 -1
  79. package/dist/assets/{xychartDiagram-S5SC5T6Z-Dd_nWl_6.js → xychartDiagram-S5SC5T6Z-ziPu3ANR.js} +1 -1
  80. package/dist/assets/{yaml-v6PfVEzx.js → yaml-D6VYrUED.js} +1 -1
  81. package/dist/index.html +3 -3
  82. package/dist/ui-build.json +1 -1
  83. package/dist-server/domain/doc-control/doc-sync-control.service.js +2 -2
  84. package/dist-server/domain/doc-control/doc-sync.error.js +1 -1
  85. package/dist-server/domain/doc-sync/contract/sowonai-doc.constants.js +1 -1
  86. package/dist-server/domain/doc-sync/contract/sowonai-doc.schemas.js +1 -1
  87. package/dist-server/domain/doc-sync/doc-sync.app-config.js +1 -1
  88. package/dist-server/domain/doc-sync/doc-sync.app-control.host.js +1 -1
  89. package/dist-server/domain/doc-sync/doc-sync.app-document.port.js +1 -1
  90. package/dist-server/domain/doc-sync/doc-sync.app-remote.js +1 -1
  91. package/dist-server/domain/doc-sync/doc-sync.client.js +1 -1
  92. package/dist-server/domain/doc-sync/doc-sync.host.js +2 -1
  93. package/dist-server/domain/doc-sync/dto/app-sync.dto.js +1 -1
  94. package/dist-server/domain/doc-sync/sowonai-doc.client.js +3 -1
  95. package/dist-server/domain/doc-sync/testing/fake-sowonai.js +1 -1
  96. package/dist-server/domain/git/git.service.js +1 -1
  97. package/dist-server/domain/task/task.service.js +2 -2
  98. package/dist-server/domain/terminal/dto/terminal-ticket.dto.js +1 -0
  99. package/dist-server/domain/terminal/terminal-access-policy.js +1 -1
  100. package/dist-server/domain/terminal/terminal-confirmation.service.js +1 -0
  101. package/dist-server/domain/terminal/terminal.controller.js +1 -1
  102. package/dist-server/domain/terminal/terminal.module.js +1 -1
  103. package/dist-server/domain/workflow/workflow.service.js +2 -2
  104. package/dist-server/repository/task.repository.js +2 -2
  105. package/package.json +32 -21
  106. package/packages/cli/package.json +1 -1
  107. package/dist/assets/channel-B1Bt2AsP.js +0 -1
  108. package/dist/assets/classDiagram-ZZMXUADV-BUWEHyMk.js +0 -1
  109. package/dist/assets/classDiagram-v2-VYDZK3BY-BUWEHyMk.js +0 -1
  110. package/dist/assets/main-CBefalnL.css +0 -10
  111. package/dist/assets/stateDiagram-v2-MP3YSRHH-CcJ28KsF.js +0 -1
  112. package/dist/assets/swimlanesDiagram-VR7AAH4N-C2O1s3dD.js +0 -8
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import{spawn as m}from"child_process";import{existsSync as O,readFileSync as A,realpathSync as R}from"fs";import{fileURLToPath as N}from"url";import{dirname as h,join as l,resolve as P}from"path";import{homedir as k,tmpdir as X}from"os";import{createRequire as y}from"module";import{defineCommand as x,runCommand as E,renderUsage as g}from"citty";import{setupSignalForwarding as _,resolveRoute as I,ensureCrewxDirs as U,readPairingCredential as W,resolvePairEndpoint as $}from"./crewx-lib.js";const L=N(import.meta.url);const f=h(L);if(process.versions.electron&&process.env.CREWX_ACTIVE_SNAPSHOT_ROOT&&process.env.CREWX_APP_UPDATE_CHANNEL_DIRECTORY){const e=y(import.meta.url);const r=R(P(h(h(f))));const o=R(P(process.env.CREWX_ACTIVE_SNAPSHOT_ROOT));if(o!==r){throw new Error("CrewX CLI entrypoint does not match its selected app snapshot")}const t=process.env.CREWX_FIXED_SHELL_RETENTION_MODULE;if(!t||!t.endsWith(l("dist-shell","retention.cjs"))&&!t.endsWith(l("fixed-shell","retention.cjs"))){throw new Error("CrewX fixed shell pin module is unavailable")}const{acquireSnapshotPin:i}=e(t);const n=i(process.env.CREWX_APP_UPDATE_CHANNEL_DIRECTORY,process.env.CREWX_ACTIVE_SNAPSHOT_ROOT);if(!n){if(process.env.CREWX_APP_SNAPSHOT_SLOT!=="baseline"||h(r).split(/[/\\]/).pop()!=="resources"||r.split(/[/\\]/).pop()!=="baseline-app"){throw new Error("CrewX cannot pin its verified app snapshot")}}else{process.env.CREWX_SNAPSHOT_PIN_ID=n.id;process.once("exit",()=>n.release())}}function D(){const e={...process.env};delete e.ELECTRON_RUN_AS_NODE;e.NODE_ENV="production";return e}function j(e,r=[]){const o=y(import.meta.url);let t;try{t=o("electron")}catch{return false}const i=m(String(t),[e,...r],{stdio:"inherit",env:D(),detached:true});_(i,{escalateKill:true,detached:true});i.on("exit",n=>process.exit(n??0));i.on("error",n=>{console.error("Failed to launch Electron:",n);process.exit(1)});return true}function H({port:e,token:r,tokenFile:o,open:t,https:i,trust:n}={}){const s=l(f,"..","server.js");const c={...process.env,NODE_ENV:"production"};if(i){c.CREWX_HTTPS="true"}if(n){c.CREWX_TRUST_CA="true"}if(e){c.PORT=String(e)}if(r){c.MCP_BEARER_TOKEN=r;process.stderr.write("\u2139\uFE0F Tip: use --token-file to avoid exposing token in shell history.\n")}else if(o){let a;try{a=A(o,"utf8").trim()}catch(b){console.error(`\u274C --token-file not readable: ${o}`);console.error(` ${b.message}`);process.exit(1)}if(!a){console.error(`\u274C --token-file is empty: ${o}`);process.exit(1)}c.MCP_BEARER_TOKEN=a}const C=l(k(),".crewx","tls","cert.pem");if(O(C)){c.NODE_EXTRA_CA_CERTS=C}if(i){console.log("\u{1F512} HTTPS enabled with SowonLabs CA");if(!n){console.log("\u26A0\uFE0F Browser may show a certificate warning.");console.log(" To remove warning: npx crewx serve --https --trust")}}if(t){c.CREWX_OPEN_BROWSER="1";c.CREWX_OPEN_BROWSER_ONCE_FILE=l(X(),`crewx-open-browser-${process.pid}-${Date.now()}`)}const w=m(process.execPath,["--disable-sigusr1",s],{stdio:"inherit",env:c});_(w);w.on("exit",a=>process.exit(a??0));w.on("error",a=>{console.error("Failed to start web server:",a);process.exit(1)})}function q(e){const r=Number(e);if(!Number.isInteger(r)||r<1||r>65535){console.error("\u274C Invalid port number. Use 1-65535.");process.exit(1)}return r}function F(e){if(typeof e!=="string"||e.length===0)return false;try{const r=new URL(e);return(r.protocol==="http:"||r.protocol==="https:")&&r.search===""&&/^#pair=.{1,}$/.test(r.hash)}catch{return false}}async function B(e,r){let o;try{o=await fetch(`${e}/api/v1/auth/local/code`,{method:"POST",headers:{Accept:"application/json",Authorization:`Bearer ${r}`}})}catch{throw new Error(`Could not reach the CrewX server at ${e}.`)}if(!o.ok){throw new Error(`Pairing code request failed (HTTP ${o.status}).`)}let t;try{t=await o.json()}catch{throw new Error("Pairing code response was not valid JSON.")}if(!F(t?.url)){throw new Error("Pairing code response did not contain a valid pairing URL.")}return t.url}const S=x({meta:{name:"pair",description:"Request a one-time local browser pairing link"},args:{port:{type:"string",description:"Port of the CrewX web server"},open:{type:"boolean",description:"Open the pairing link in a browser",default:false},help:{type:"boolean",alias:"h",description:"Show this help"}},async run({args:e}){if(e.help){const s=await g(S);process.stdout.write(s+"\n");process.exit(0)}const r=new Set(["_","port","open","help","h"]);for(const s of Object.keys(e)){if(!r.has(s)){console.error(`\u274C Unknown option for "crewx pair": --${s}`);console.error(" Run `crewx pair --help` for usage.");process.exit(2)}}const o=e.port===void 0?void 0:q(e.port);let t;let i;try{t=$({port:o});i=W()}catch(s){console.error(`\u274C ${s instanceof Error?s.message:"Unable to read pairing credential."}`);process.exit(1)}let n;try{n=await B(t,i)}catch(s){console.error(`\u274C ${s instanceof Error?s.message:"Unable to request pairing link."}`);process.exit(1)}process.stdout.write(`${n}
3
+ `);if(e.open){try{const s=(await import("open")).default;await s(n)}catch{console.error("\u274C Could not open the pairing link automatically.");process.exit(1)}}}});const v=x({meta:{name:"serve",description:"Launch CrewX web server"},args:{port:{type:"string",description:"Port to listen on"},token:{type:"string",description:"MCP bearer token"},"token-file":{type:"string",description:"Read token from file"},https:{type:"boolean",description:"Enable HTTPS with auto-generated certificate"},trust:{type:"boolean",description:"Install CA to system trust store (requires --https)"},open:{type:"boolean",description:"Auto-open browser",default:true},help:{type:"boolean",alias:"h",description:"Show this help"}},async run({args:e}){if(e.help){const t=await g(v);process.stdout.write(t+"\n");process.exit(0)}const r=new Set(["_","port","token","token-file","tokenFile","https","trust","open","help","h"]);for(const t of Object.keys(e)){if(!r.has(t)){console.error(`\u274C Unknown option for "crewx serve": --${t}`);console.error(" Run `crewx serve --help` for usage.");process.exit(2)}}if(e.trust&&!e.https){console.error("\u274C --trust requires --https");process.exit(1)}const o=e.port?Number(e.port):void 0;if(e.port&&(!o||o<1||o>65535)){console.error("\u274C Invalid port number. Use 1-65535.");process.exit(1)}H({port:o,token:e.token,tokenFile:e["token-file"],open:e.open,https:e.https,trust:e.trust})}});function V(e){const r=l(f,"..","server.js");const o=m(process.execPath,[r,"cli",...e],{stdio:"inherit",env:{...process.env,NODE_ENV:"production"}});_(o);o.on("exit",t=>process.exit(t??0));o.on("error",t=>{console.error("Failed to run CLI subcommand:",t);process.exit(1)})}const u=process.argv.slice(2);const T=u.length===3&&u[0]==="ai-account"&&u[1]==="capabilities"&&u[2]==="--json";if(!T)U();const{route:p,routeArgs:d,error:M}=T?{route:"cli",routeArgs:u}:I(u);if(p==="serve"){E(v,{rawArgs:d})}else if(p==="pair"){E(S,{rawArgs:d})}else if(p==="electron"){const e=d.includes("--overlay");const r=l(f,"..","dist-electron",e?"overlay.js":"main.js");const o=j(r,e?[]:[]);if(!o){console.error("");console.error(" \u274C Electron is not installed.");console.error("");console.error(" This command requires Electron. Install it:");console.error("");console.error(" npm install -g electron");console.error(" # or in this project:");console.error(" npm install --save-dev electron");console.error("");console.error(" Alternatively, use: crewx serve (web mode)");console.error("");process.exit(1)}}else if(p==="cli"){V(d)}else if(p==="web-default"){E(v,{rawArgs:["--open",...d]})}else if(p==="error"){console.error(`\u274C ${M}`);process.exit(2)}else{console.error(`\u274C Internal routing error: unknown route "${p}"`);process.exit(1)}
@@ -0,0 +1,7 @@
1
+ import{createHash as P}from"node:crypto";import{createRequire as V}from"node:module";import{spawn as $}from"node:child_process";import{chmodSync as X,copyFileSync as D,existsSync as I,lstatSync as R,mkdtempSync as H,readFileSync as E,rmSync as W}from"node:fs";import{tmpdir as F}from"node:os";import{fileURLToPath as T,pathToFileURL as G}from"node:url";import{basename as j,dirname as v,isAbsolute as q,join as y,relative as J,resolve as _,sep as K}from"node:path";const C=4;const x="memory.read.basic.v1";const A="memory.read.ordinary.v1";const z="memory.graph.v1";const ve="memory.api.v1";const O="memory.write.crud.v2";const L="memory.summary.v1";const Q="memory.write.crud.v1";const S=["SIGINT","SIGTERM","SIGHUP"];const B=new Set([1,2,3,C]);const xe=V(import.meta.url);const Z=new Set(["help","force","verbose","full","important","no-important","json","all","version"]);const ee={darwin:"darwin",linux:"linux",win32:"windows"};const te={arm64:"arm64",x64:"amd64"};function we(e=process.env){const o=e.CREWX_MEMORY_RUNTIME===void 0?"auto":e.CREWX_MEMORY_RUNTIME;if(!["auto","go","node"].includes(o)){throw new Error("CREWX_MEMORY_RUNTIME must be auto, go, or node.")}return o}function Ee(e){if(!Array.isArray(e)||e[0]!=="memory")return null;const{positional:o,options:s}=b(e.slice(1));if(s.help||s.version)return null;const[t,n,...r]=o;if(!n||k(n))return null;const i={read:"get",ls:"recent"}[t]??t;const c=[i,n];let f=A;let u;switch(i){case"index":{const a=["full","recent"];const m=a.some(l=>Boolean(s[l]));f=m?A:x;if(m)Y(c,s,a);break}case"get":case"find":if(!r[0]||k(r[0]))return null;u=r[0];c.push(u);f=x;break;case"list":Y(c,s,["category","tag","json"]);break;case"recent":if(r[0]!==void 0){u=r[0];c.push(u)}break;case"stats":break;case"tags":if(r[0]){u=r[0];c.push(u)}break;default:return null}return{command:i,agentId:n,argument:u,capability:f,nativeArgs:c}}function be(e){if(!Array.isArray(e)||e[0]!=="memory")return null;const{positional:o,options:s}=b(e.slice(1));if(s.help||s.version)return null;const[t,n,...r]=o;if(!n||k(n))return null;const i={rm:"delete"}[t]??t;if(!["save","update","delete","merge"].includes(i))return null;if(i==="save"&&!r[0])return null;if((i==="update"||i==="delete")&&!r[0])return null;if(i==="merge"&&(!r[0]||!r[1]))return null;return{command:i,agentId:n,capability:O,nativeArgs:e.slice(1)}}function ke(e){if(!Array.isArray(e)||e[0]!=="memory")return null;const{positional:o}=b(e.slice(1));const[s,t]=o;if(s!=="mindmap"&&s!=="graph")return null;if(t==="open")return null;return{command:"mindmap",capability:z,nativeArgs:e.slice(1)}}function Re(e){if(!Array.isArray(e)||e[0]!=="memory")return null;const{positional:o,options:s}=b(e.slice(1));if(s.help||s.version)return null;const[t,n,...r]=o;if(t==="summarize-dirty"){return{command:t,agentId:void 0,capability:L,nativeArgs:e.slice(1)}}if(t==="summarize"){if(!n||k(n))return null;return{command:t,agentId:n,capability:L,nativeArgs:e.slice(1)}}if(t==="search"){if(!n||k(n)||!r[0]||k(r[0]))return null;return{command:t,agentId:n,capability:L,nativeArgs:e.slice(1)}}return null}function _e(e){if(!Array.isArray(e)||e[0]!=="memory")return null;const{positional:o,options:s}=b(e.slice(1));if(s.version||o.length>0&&o[0]==="--version"){return{command:"version",capability:x,nativeArgs:["--version"]}}if(s.help||o.length>0&&(o[0]==="help"||o[0]==="usage")||o.length===0){return{command:"usage",capability:x,nativeArgs:["usage"]}}return null}function re(e){if(e.command!=="save")return false;const{positional:o,options:s}=b(e.nativeArgs);const t=o.slice(2);return!s.body&&!t[2]}async function oe(e,o=process.stdin,s=100){if(!re(e)||o.isTTY===true)return null;const t=[];return new Promise((n,r)=>{let i=false;let c;const f=()=>{if(c)clearTimeout(c);o.removeListener("data",a);o.removeListener("end",m);o.removeListener("error",l);o.pause?.();if(typeof o.unref==="function")o.unref()};const u=(h,p)=>{if(i)return;i=true;f();h(p)};const a=h=>t.push(Buffer.from(h));const m=()=>{const h=Buffer.concat(t);try{const p=new TextDecoder("utf-8",{fatal:true}).decode(h).trim();u(n,p||null)}catch{u(r,new Error("memory save stdin body is not valid UTF-8"))}};const l=h=>u(r,h);o.on("data",a);o.once("end",m);o.once("error",l);c=setTimeout(()=>u(n,null),s);o.resume?.()})}function b(e){const o=[];const s=Object.create(null);for(let t=0;t<e.length;t++){const n=e[t];if(n==="-h"){s.help=true}else if(n.startsWith("--")){const r=n.indexOf("=");if(r!==-1){s[n.slice(2,r)]=n.slice(r+1)}else{const i=n.slice(2);if(!Z.has(i)){const c=e[t+1];if(c!==void 0&&!c.startsWith("--")&&c!=="-h"){s[i]=c;t++}else{s[i]=true}}else{s[i]=true}}}else{o.push(n)}}return{positional:o,options:s}}function Y(e,o,s){for(const t of s){if(!Object.hasOwn(o,t))continue;const n=o[t];e.push(n===true?`--${t}`:`--${t}=${String(n)}`)}}function k(e){return e==="-h"||e.startsWith("--")}function Ae(){return"CREWX_MEMORY_RUNTIME=go does not support this memory command. Use CREWX_MEMORY_RUNTIME=node for writes, AI-backed commands, help, and other unsupported memory operations."}function Se(e){return`Native memory support is unavailable (${e}). Use CREWX_MEMORY_RUNTIME=node to roll back to the existing implementation.`}function ne(){return"CREWX_MEMORY_RUNTIME=go does not support this memory write on the current platform or native artifact. Use CREWX_MEMORY_RUNTIME=node for the existing implementation."}function Me(e=process.env,o=process.resourcesPath,s=v(v(T(import.meta.url)))){const t=[];if(typeof e.CREWX_SHELL_NATIVE_DIR==="string"&&e.CREWX_SHELL_NATIVE_DIR!==""){t.push(y(e.CREWX_SHELL_NATIVE_DIR,"@crewx","memory"))}if(typeof o==="string"&&o!==""){t.push(y(o,"shell-native","node_modules","@crewx","memory"))}for(const n of t){if(I(y(n,"go","native-manifest.json"))&&I(y(n,"package.json"))){return _(n)}}return ie(s)}const se="CREWX_MEMORY_HOST_REQUEST";async function Ie(e,o=process.env,s=v(v(T(import.meta.url)))){const t=[y(s,"node_modules","@crewx","memory","dist","src","native-host.js"),y(v(s),"@crewx","memory","dist","src","native-host.js"),y(e,"dist","src","native-host.js")];const n=t.find(c=>I(c));if(!n)throw new Error("installed @crewx/memory host module is unavailable");const r=await import(G(n).href);const i=r.prepareCliHostRequest(o);return{...i.env,[se]:JSON.stringify(i.request)}}function ie(e=v(v(T(import.meta.url))),o=process.env){const s=[];if(o?.CREWX_SHELL_NATIVE_DIR){s.push(y(o.CREWX_SHELL_NATIVE_DIR,"@crewx","memory"),y(o.CREWX_SHELL_NATIVE_DIR,"node_modules","@crewx","memory"))}if(typeof process!=="undefined"&&process.resourcesPath){s.push(y(process.resourcesPath,"shell-native","node_modules","@crewx","memory"))}s.push(y(e,"node_modules","@crewx","memory"),y(v(e),"@crewx","memory"),y(e,"packages","built-in","memory"));for(const t of s){try{const n=y(t,"package.json");const r=R(n);if(!r.isFile()||r.isSymbolicLink())continue;const i=JSON.parse(E(n,"utf8"));if(i.name==="@crewx/memory"&&typeof i.version==="string")return _(t)}catch{}}throw new Error("installed @crewx/memory package was not found beside CrewX")}function ae(e=process.platform,o=process.arch){const s=ee[e];const t=te[o];if(!s||!t)return null;return`${s}-${t}`}function Te(e=process.platform){return e==="darwin"||e==="linux"||e==="win32"}function Ce(e,o=process.platform,s=process.arch){const t=ae(o,s);if(!t)return{ok:false,reason:`unsupported platform ${o}/${s}`};try{const n=_(e);const r=y(n,"package.json");const i=y(n,"go","native-manifest.json");const c=R(r);const f=R(i);if(!c.isFile()||c.isSymbolicLink()||!f.isFile()||f.isSymbolicLink()){return{ok:false,reason:"package metadata is not a regular installed-package file"}}const u=JSON.parse(E(r,"utf8"));const a=JSON.parse(E(i,"utf8"));if(u.name!=="@crewx/memory"||typeof u.version!=="string"){return{ok:false,reason:"installed memory package identity is invalid"}}if(a.formatVersion!==1||!B.has(a.protocol)){return{ok:false,reason:`unsupported manifest/protocol (supported protocols: ${[...B].join(", ")})`}}if(a.packageVersion!==u.version){return{ok:false,reason:`manifest version ${a.packageVersion??"(missing)"} does not match package ${u.version}`}}let m;if(a.protocol===1){m=[x]}else if([2,3,4].includes(a.protocol)&&Array.isArray(a.capabilities)&&a.capabilities.every(M=>typeof M==="string")&&a.capabilities.includes(x)&&a.capabilities.includes(A)&&new Set(a.capabilities).size===a.capabilities.length){m=[...a.capabilities]}else{return{ok:false,reason:`native manifest does not declare the required read capabilities for protocol ${a.protocol}`}}const l=a.targets?.[t];if(!l||typeof l.file!=="string"||typeof l.sha256!=="string"){return{ok:false,reason:`no packaged native executable for ${t}`}}if(a.protocol>=3&&l.capabilities!==void 0){if(!Array.isArray(l.capabilities)||!l.capabilities.every(M=>typeof M==="string")||new Set(l.capabilities).size!==l.capabilities.length||!l.capabilities.includes(x)||!l.capabilities.includes(A)){return{ok:false,reason:`native target ${t} does not declare valid protocol-${a.protocol} read capabilities`}}m=[...l.capabilities]}if(a.protocol===C&&l.capabilities!==void 0&&l.capabilities.includes(Q)){return{ok:false,reason:`native target ${t} declares a protocol-3 write capability in a protocol-4 manifest`}}const h=t.startsWith("windows-")?".exe":"";const p=`go/bin/crewx-memory-${t}${h}`;if(l.file!==p||q(l.file)||l.file.split(/[\\/]/u).includes("..")){return{ok:false,reason:"native manifest contains an untrusted executable path"}}if(!/^[0-9a-f]{64}$/u.test(l.sha256)){return{ok:false,reason:"native executable hash is invalid"}}const d=_(n,l.file);const g=J(n,d);if(!g||g.startsWith(`..${K}`)||g===".."){return{ok:false,reason:"native executable escaped its installed package"}}const w=R(d);if(!w.isFile()||w.isSymbolicLink()){return{ok:false,reason:"native executable is not a regular packaged file"}}const N=P("sha256").update(E(d)).digest("hex");if(N!==l.sha256){return{ok:false,reason:"native executable hash does not match its protected manifest"}}return{ok:true,artifact:{executablePath:d,packageVersion:u.version,protocol:a.protocol,capabilities:m,sha256:N,executable:o==="win32"||(w.mode&73)!==0,skillVersion:ce(n)}}}catch(n){return{ok:false,reason:n instanceof Error?n.message:String(n)}}}function Oe(e,o=process.platform){if(o==="win32"||e.executable){return{ok:true,executablePath:e.executablePath,cleanup:()=>{}}}let s;try{s=H(y(F(),"crewx-memory-native-"));const t=y(s,j(e.executablePath));D(e.executablePath,t);X(t,448);const n=P("sha256").update(E(t)).digest("hex");if(n!==e.sha256)throw new Error("staged native executable hash does not match its installed package artifact");return{ok:true,executablePath:t,temporaryExecutablePath:t,cleanup:()=>W(s,{recursive:true,force:true})}}catch(t){if(s)W(s,{recursive:true,force:true});return{ok:false,reason:t instanceof Error?t.message:String(t),cleanup:()=>{}}}}function ce(e){const o=E(y(e,"SKILL.md"),"utf8");const s=o.match(/^---\r?\n([\s\S]*?)\r?\n---/u)?.[1];const t=s?.match(/^\s*version:\s*(.+?)\s*$/mu);if(!t)return null;return t[1].replace(/^['"]|['"]$/gu,"")}async function Le(e,o,s=process.env){try{const{loadCrewxEnvFiles:t}=await import("@crewx/sdk/account");if(typeof t!=="function"){return{ok:false,reason:"the shared CrewX environment loader is unavailable"}}t();if(s.CREWX_NO_TRACE==="1")return{ok:true,handle:null};const n=await import("@crewx/shared/skill-tracer");if(typeof n.trace!=="function"){return{ok:false,reason:"the shared skill activity tracer is unavailable"}}const r=typeof n.getOwnSkillVersion==="function"?n.getOwnSkillVersion(e):null;const i=n.trace("crewx/memory",o.join(" "),{agentId:s.CREWX_AGENT_ID,skillVersion:r});if(!i||i._skipped){return{ok:false,reason:"activity tracing is unavailable because the existing trace database or schema could not be opened. Use CREWX_NO_TRACE=1 to explicitly disable tracing."}}return{ok:true,handle:i}}catch(t){return{ok:false,reason:`activity tracing could not start: ${t instanceof Error?t.message:String(t)}`}}}async function Ne(e,o,s=process.env,t=null){const n=[`--crewx-memory-protocol=${e.protocol}`,`--crewx-memory-version=${e.packageVersion}`,...o.nativeArgs];let r;let i;try{r=await ue(e.executablePath,n,s)}catch(a){i=a;r={code:127,signal:null,stdout:Buffer.alloc(0),stderr:Buffer.alloc(0)}}const c=r.stdout.toString("utf8");const f=r.stderr.toString("utf8");let u;if(t){try{if(!i&&r.code===0&&!r.signal){t.ok(c||null,{stderr:f||void 0})}else{const a=f.trim()||i?.message||`native memory exited with code ${r.code??r.signal}`;t.fail(a,{stderr:f||void 0})}}catch(a){u=a}}if(r.stdout.length>0)process.stdout.write(r.stdout);if(r.stderr.length>0)process.stderr.write(r.stderr);if(u){process.stderr.write(`[memory] Activity trace update failed after the native read; the read was not retried: ${u.message}
2
+ `);return{exitCode:1}}if(i){process.stderr.write(`Native memory process could not be started: ${i.message}
3
+ `);return{exitCode:127}}return{exitCode:r.signal?U(r.signal):r.code??1}}async function Pe(e,o,s=process.env,t=null,n={}){if(e?.protocol!==C||!Array.isArray(e.capabilities)||!e.capabilities.includes(O)){process.stderr.write(`${ne()}
4
+ `);return{exitCode:2}}let r;let i;try{const a=await oe(o,n.stdin??process.stdin,n.stdinTimeoutMs??100);const m={version:1,protocol:e.protocol,capabilities:[O],args:o.nativeArgs,...a===null?{}:{stdinBody:a}};const l=Buffer.from(`${JSON.stringify(m)}
5
+ `,"utf8");const h=[`--crewx-memory-protocol=${e.protocol}`,`--crewx-memory-version=${e.packageVersion}`,...o.nativeArgs];r=await(n.spawnProcess??le)(e.executablePath,h,s,l)}catch(a){i=a;r={code:127,signal:null,stdout:Buffer.alloc(0),stderr:Buffer.alloc(0)}}const c=r.stdout.toString("utf8");const f=r.stderr.toString("utf8");let u;if(t){try{if(!i&&r.code===0&&!r.signal){t.ok(c||null,{stderr:f||void 0})}else{const a=f.trim()||i?.message||`native memory exited with code ${r.code??r.signal}`;t.fail(a,{stderr:f||void 0})}}catch(a){u=a}}if(r.stdout.length>0){if(n.writeStdout)n.writeStdout(r.stdout);else process.stdout.write(r.stdout)}if(r.stderr.length>0)process.stderr.write(r.stderr);if(u){process.stderr.write(`[memory] Activity trace update failed after the native write; the write was not retried: ${u.message}
6
+ `);return{exitCode:1}}if(i){process.stderr.write(`Native memory process could not be started: ${i.message}
7
+ `);return{exitCode:i.code==="ERR_INVALID_ARG_VALUE"?1:127}}return{exitCode:r.signal?U(r.signal):r.code??1}}function le(e,o,s=process.env,t,n=process){return new Promise((r,i)=>{let c;try{c=$(e,o,{cwd:process.cwd(),env:s,stdio:["pipe","pipe","pipe"],windowsHide:true})}catch(d){i(d);return}const f=[];const u=[];let a;let m;let l;const h=new Map;const p=d=>{if(m)return;m=d;try{c.kill(d)}catch{}l=setTimeout(()=>{if(c.exitCode===null&&c.signalCode===null)c.kill("SIGKILL")},5e3);l.unref?.()};for(const d of S){const g=p.bind(null,d);h.set(d,g);n.once(d,g)}c.stdin.on("error",()=>{});c.stdout.on("data",d=>f.push(Buffer.from(d)));c.stderr.on("data",d=>u.push(Buffer.from(d)));c.once("error",d=>{a=d});c.once("close",(d,g)=>{for(const w of S)n.removeListener(w,h.get(w));if(l)clearTimeout(l);if(a){i(a);return}r({code:d,signal:g??m??null,stdout:Buffer.concat(f),stderr:Buffer.concat(u)})});c.stdin.write(t)})}function ue(e,o,s=process.env,t=process){return new Promise((n,r)=>{let i;try{i=$(e,o,{cwd:process.cwd(),env:s,stdio:["pipe","pipe","pipe"],windowsHide:true})}catch(p){r(p);return}const c=[];const f=[];let u;let a;let m;const l=new Map;const h=p=>{if(a)return;a=p;try{i.kill(p)}catch{}m=setTimeout(()=>{if(i.exitCode===null&&i.signalCode===null)i.kill("SIGKILL")},5e3);m.unref?.()};for(const p of S){const d=h.bind(null,p);l.set(p,d);t.once(p,d)}i.stdin.on("error",()=>{});i.stdout.on("data",p=>c.push(Buffer.from(p)));i.stderr.on("data",p=>f.push(Buffer.from(p)));i.once("error",p=>{u=p});i.once("close",(p,d)=>{for(const g of S)t.removeListener(g,l.get(g));if(m)clearTimeout(m);if(u){r(u);return}n({code:p,signal:d??a??null,stdout:Buffer.concat(c),stderr:Buffer.concat(f)})})})}function U(e){if(e==="SIGINT")return 130;if(e==="SIGTERM")return 143;if(e==="SIGHUP")return 129;return 1}export{ve as MEMORY_API_CAPABILITY,z as MEMORY_GRAPH_CAPABILITY,se as MEMORY_HOST_REQUEST_ENV,C as MEMORY_PROTOCOL,x as MEMORY_READ_BASIC_CAPABILITY,A as MEMORY_READ_ORDINARY_CAPABILITY,L as MEMORY_SUMMARY_CAPABILITY,O as MEMORY_WRITE_CRUD_CAPABILITY,we as getRuntimeMode,Te as nativeMemoryWritePlatformSupported,ae as nativeTargetKey,Se as nativeUnavailableMessage,re as nativeWriteNeedsStdinBody,ke as parseSupportedMemoryGraph,_e as parseSupportedMemoryMeta,Ee as parseSupportedMemoryRead,Re as parseSupportedMemorySummary,be as parseSupportedMemoryWrite,Oe as prepareNativeExecutable,Ie as prepareNativeHostEnvironment,Le as prepareNativeTrace,oe as readNativeWriteBody,ie as resolveInstalledMemoryPackageRoot,Ce as resolveNativeArtifact,Me as resolveNativeMemoryPackageRoot,ue as runForegroundProcess,le as runForegroundWriteProcess,Ne as runNativeMemoryRead,Pe as runNativeMemoryWrite,Ae as unsupportedNativeReadMessage,ne as unsupportedNativeWriteMessage};
package/bin/crewx.js CHANGED
@@ -1,3 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import{spawn as m}from"child_process";import{existsSync as O,readFileSync as A,realpathSync as R}from"fs";import{fileURLToPath as N}from"url";import{dirname as h,join as l,resolve as P}from"path";import{homedir as k,tmpdir as X}from"os";import{createRequire as y}from"module";import{defineCommand as x,runCommand as E,renderUsage as g}from"citty";import{setupSignalForwarding as _,resolveRoute as I,ensureCrewxDirs as U,readPairingCredential as W,resolvePairEndpoint as $}from"./crewx-lib.js";const L=N(import.meta.url);const f=h(L);if(process.versions.electron&&process.env.CREWX_ACTIVE_SNAPSHOT_ROOT&&process.env.CREWX_APP_UPDATE_CHANNEL_DIRECTORY){const e=y(import.meta.url);const r=R(P(h(h(f))));const o=R(P(process.env.CREWX_ACTIVE_SNAPSHOT_ROOT));if(o!==r){throw new Error("CrewX CLI entrypoint does not match its selected app snapshot")}const t=process.env.CREWX_FIXED_SHELL_RETENTION_MODULE;if(!t||!t.endsWith(l("dist-shell","retention.cjs"))&&!t.endsWith(l("fixed-shell","retention.cjs"))){throw new Error("CrewX fixed shell pin module is unavailable")}const{acquireSnapshotPin:i}=e(t);const n=i(process.env.CREWX_APP_UPDATE_CHANNEL_DIRECTORY,process.env.CREWX_ACTIVE_SNAPSHOT_ROOT);if(!n){if(process.env.CREWX_APP_SNAPSHOT_SLOT!=="baseline"||h(r).split(/[/\\]/).pop()!=="resources"||r.split(/[/\\]/).pop()!=="baseline-app"){throw new Error("CrewX cannot pin its verified app snapshot")}}else{process.env.CREWX_SNAPSHOT_PIN_ID=n.id;process.once("exit",()=>n.release())}}function D(){const e={...process.env};delete e.ELECTRON_RUN_AS_NODE;e.NODE_ENV="production";return e}function j(e,r=[]){const o=y(import.meta.url);let t;try{t=o("electron")}catch{return false}const i=m(String(t),[e,...r],{stdio:"inherit",env:D(),detached:true});_(i,{escalateKill:true,detached:true});i.on("exit",n=>process.exit(n??0));i.on("error",n=>{console.error("Failed to launch Electron:",n);process.exit(1)});return true}function H({port:e,token:r,tokenFile:o,open:t,https:i,trust:n}={}){const s=l(f,"..","server.js");const c={...process.env,NODE_ENV:"production"};if(i){c.CREWX_HTTPS="true"}if(n){c.CREWX_TRUST_CA="true"}if(e){c.PORT=String(e)}if(r){c.MCP_BEARER_TOKEN=r;process.stderr.write("\u2139\uFE0F Tip: use --token-file to avoid exposing token in shell history.\n")}else if(o){let a;try{a=A(o,"utf8").trim()}catch(b){console.error(`\u274C --token-file not readable: ${o}`);console.error(` ${b.message}`);process.exit(1)}if(!a){console.error(`\u274C --token-file is empty: ${o}`);process.exit(1)}c.MCP_BEARER_TOKEN=a}const C=l(k(),".crewx","tls","cert.pem");if(O(C)){c.NODE_EXTRA_CA_CERTS=C}if(i){console.log("\u{1F512} HTTPS enabled with SowonLabs CA");if(!n){console.log("\u26A0\uFE0F Browser may show a certificate warning.");console.log(" To remove warning: npx crewx serve --https --trust")}}if(t){c.CREWX_OPEN_BROWSER="1";c.CREWX_OPEN_BROWSER_ONCE_FILE=l(X(),`crewx-open-browser-${process.pid}-${Date.now()}`)}const w=m(process.execPath,["--disable-sigusr1",s],{stdio:"inherit",env:c});_(w);w.on("exit",a=>process.exit(a??0));w.on("error",a=>{console.error("Failed to start web server:",a);process.exit(1)})}function q(e){const r=Number(e);if(!Number.isInteger(r)||r<1||r>65535){console.error("\u274C Invalid port number. Use 1-65535.");process.exit(1)}return r}function F(e){if(typeof e!=="string"||e.length===0)return false;try{const r=new URL(e);return(r.protocol==="http:"||r.protocol==="https:")&&r.search===""&&/^#pair=.{1,}$/.test(r.hash)}catch{return false}}async function B(e,r){let o;try{o=await fetch(`${e}/api/v1/auth/local/code`,{method:"POST",headers:{Accept:"application/json",Authorization:`Bearer ${r}`}})}catch{throw new Error(`Could not reach the CrewX server at ${e}.`)}if(!o.ok){throw new Error(`Pairing code request failed (HTTP ${o.status}).`)}let t;try{t=await o.json()}catch{throw new Error("Pairing code response was not valid JSON.")}if(!F(t?.url)){throw new Error("Pairing code response did not contain a valid pairing URL.")}return t.url}const S=x({meta:{name:"pair",description:"Request a one-time local browser pairing link"},args:{port:{type:"string",description:"Port of the CrewX web server"},open:{type:"boolean",description:"Open the pairing link in a browser",default:false},help:{type:"boolean",alias:"h",description:"Show this help"}},async run({args:e}){if(e.help){const s=await g(S);process.stdout.write(s+"\n");process.exit(0)}const r=new Set(["_","port","open","help","h"]);for(const s of Object.keys(e)){if(!r.has(s)){console.error(`\u274C Unknown option for "crewx pair": --${s}`);console.error(" Run `crewx pair --help` for usage.");process.exit(2)}}const o=e.port===void 0?void 0:q(e.port);let t;let i;try{t=$({port:o});i=W()}catch(s){console.error(`\u274C ${s instanceof Error?s.message:"Unable to read pairing credential."}`);process.exit(1)}let n;try{n=await B(t,i)}catch(s){console.error(`\u274C ${s instanceof Error?s.message:"Unable to request pairing link."}`);process.exit(1)}process.stdout.write(`${n}
3
- `);if(e.open){try{const s=(await import("open")).default;await s(n)}catch{console.error("\u274C Could not open the pairing link automatically.");process.exit(1)}}}});const v=x({meta:{name:"serve",description:"Launch CrewX web server"},args:{port:{type:"string",description:"Port to listen on"},token:{type:"string",description:"MCP bearer token"},"token-file":{type:"string",description:"Read token from file"},https:{type:"boolean",description:"Enable HTTPS with auto-generated certificate"},trust:{type:"boolean",description:"Install CA to system trust store (requires --https)"},open:{type:"boolean",description:"Auto-open browser",default:true},help:{type:"boolean",alias:"h",description:"Show this help"}},async run({args:e}){if(e.help){const t=await g(v);process.stdout.write(t+"\n");process.exit(0)}const r=new Set(["_","port","token","token-file","tokenFile","https","trust","open","help","h"]);for(const t of Object.keys(e)){if(!r.has(t)){console.error(`\u274C Unknown option for "crewx serve": --${t}`);console.error(" Run `crewx serve --help` for usage.");process.exit(2)}}if(e.trust&&!e.https){console.error("\u274C --trust requires --https");process.exit(1)}const o=e.port?Number(e.port):void 0;if(e.port&&(!o||o<1||o>65535)){console.error("\u274C Invalid port number. Use 1-65535.");process.exit(1)}H({port:o,token:e.token,tokenFile:e["token-file"],open:e.open,https:e.https,trust:e.trust})}});function V(e){const r=l(f,"..","server.js");const o=m(process.execPath,[r,"cli",...e],{stdio:"inherit",env:{...process.env,NODE_ENV:"production"}});_(o);o.on("exit",t=>process.exit(t??0));o.on("error",t=>{console.error("Failed to run CLI subcommand:",t);process.exit(1)})}const u=process.argv.slice(2);const T=u.length===3&&u[0]==="ai-account"&&u[1]==="capabilities"&&u[2]==="--json";if(!T)U();const{route:p,routeArgs:d,error:M}=T?{route:"cli",routeArgs:u}:I(u);if(p==="serve"){E(v,{rawArgs:d})}else if(p==="pair"){E(S,{rawArgs:d})}else if(p==="electron"){const e=d.includes("--overlay");const r=l(f,"..","dist-electron",e?"overlay.js":"main.js");const o=j(r,e?[]:[]);if(!o){console.error("");console.error(" \u274C Electron is not installed.");console.error("");console.error(" This command requires Electron. Install it:");console.error("");console.error(" npm install -g electron");console.error(" # or in this project:");console.error(" npm install --save-dev electron");console.error("");console.error(" Alternatively, use: crewx serve (web mode)");console.error("");process.exit(1)}}else if(p==="cli"){V(d)}else if(p==="web-default"){E(v,{rawArgs:["--open",...d]})}else if(p==="error"){console.error(`\u274C ${M}`);process.exit(2)}else{console.error(`\u274C Internal routing error: unknown route "${p}"`);process.exit(1)}
2
+ async function g(){const r=process.argv.slice(2);if(r[0]!=="memory"){await import("./crewx-dispatch.js");return}const e=await import("./crewx-memory-runtime.js");let s;try{s=e.getRuntimeMode(process.env)}catch(t){process.stderr.write(`${t.message}
3
+ `);process.exitCode=2;return}if(s==="node"){await import("./crewx-dispatch.js");return}const d=e.parseSupportedMemoryRead(r);const p=e.parseSupportedMemoryWrite(r);const l=e.parseSupportedMemoryGraph(r);const u=e.parseSupportedMemorySummary(r);const m=e.parseSupportedMemoryMeta(r);const c=d??p??l??u??m;if(!c){if(s==="go"){const t=r[1]==="save"||r[1]==="update"||r[1]==="delete"||r[1]==="rm"||r[1]==="merge"?e.unsupportedNativeWriteMessage():e.unsupportedNativeReadMessage();process.stderr.write(`${t}
4
+ `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}if(p&&!e.nativeMemoryWritePlatformSupported()){if(s==="go"){process.stderr.write(`${e.unsupportedNativeWriteMessage()}
5
+ `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}let o;try{o=e.resolveNativeMemoryPackageRoot()}catch(t){if(process.versions.electron){process.stderr.write(`Native memory executable is unavailable in this CrewX Desktop shell. Please update CrewX Desktop.
6
+ `);process.exitCode=2;return}if(s==="go"){process.stderr.write(`${e.nativeUnavailableMessage(t.message)}
7
+ `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}const a=e.resolveNativeArtifact(o);if(!a.ok){if(process.versions.electron){process.stderr.write(`Native memory executable is unavailable in this CrewX Desktop shell: ${a.reason}. Please update CrewX Desktop.
8
+ `);process.exitCode=2;return}if(s==="go"){process.stderr.write(`${e.nativeUnavailableMessage(a.reason)}
9
+ `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}if(!a.artifact.capabilities.includes(c.capability)){const t=`packaged native memory artifact lacks ${c.capability}`;if(s==="go"){process.stderr.write(`${e.nativeUnavailableMessage(t)}
10
+ `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}const i=e.prepareNativeExecutable(a.artifact);if(!i.ok){if(s==="go"){process.stderr.write(`${e.nativeUnavailableMessage(i.reason)}
11
+ `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}const n=await e.prepareNativeTrace(o,r,process.env);if(!n.ok){i.cleanup();if(s==="go"){process.stderr.write(`${n.reason}
12
+ `);process.exitCode=2;return}process.stderr.write(`[memory] Native memory operation is unavailable: ${n.reason} Falling back to Node.
13
+ `);await import("./crewx-dispatch.js");return}try{const t={...a.artifact,executablePath:i.executablePath};if(p){const f=await e.runNativeMemoryWrite(t,p,process.env,n.handle,{packageRoot:o});process.exitCode=f.exitCode;return}const v=u?await e.prepareNativeHostEnvironment(o,process.env):process.env;const w=await e.runNativeMemoryRead(t,c,v,n.handle);process.exitCode=w.exitCode}finally{i.cleanup()}}g().catch(r=>{process.stderr.write(`crewx: ${r instanceof Error?r.message:String(r)}
14
+ `);process.exitCode=1});
@@ -1 +1 @@
1
- import{aC as w,aD as e,aE as g}from"./main-2eGGGkuY.js";import{M as j}from"./MonacoDiffSurface-CcuWl3pT.js";function p(n){const t=/^---\r?\n[\s\S]*?\r?\n---(?=\r?\n|$)/.exec(n);if(!t)return null;const r=t[0].split(/\r?\n/);return{text:t[0],endLine:r.length,summary:r[1]??r[0]}}function b(n,t){const r=n.split(/\r?\n/),a=Math.max(0,Math.min(r.length-1,t-1));let s=null,i=null;for(let l=a;l>=0&&(!s||!i);l-=1){const c=r[l].trimEnd();!s&&/^##\s+/.test(c)&&(s=c),!i&&/^-\s+/.test(c)&&(i=c)}return{heading:s,listItem:i}}function L(n,t,r){var i,l;const a=new Set,s=[];for(const c of r){const h=[b(n,c.originalStartLineNumber),b(t,c.modifiedStartLineNumber)],u=((i=h.find(f=>f.heading))==null?void 0:i.heading)??null,x=((l=h.find(f=>f.listItem))==null?void 0:l.listItem)??null;if(!u&&!x)continue;const m=JSON.stringify([u,x]);a.has(m)||(a.add(m),s.push({heading:u,listItem:x}))}return s}function v(n){if(!n)return null;const t=new Date(n);return Number.isNaN(t.getTime())?n:t.toISOString()}function y({side:n,label:t,fileVersion:r}){const{t:a}=w(),s=v(n.modifiedAt),i=n.revision===null?null:String(n.revision);return e.jsxs("section",{className:"min-w-0 rounded-md border border-gray-200 bg-gray-50 px-3 py-2","aria-label":t,children:[e.jsx("h3",{className:"truncate text-sm font-semibold text-gray-900",children:t}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-1 text-xs text-gray-600",children:[s?e.jsxs("span",{children:[a("threadAppWorkspace.resultShare.docSync.modifiedAt")," ",e.jsx("time",{dateTime:s,children:s})]}):null,i?e.jsxs("span",{children:[a("threadAppWorkspace.resultShare.docSync.version")," ",i]}):null]}),e.jsx("code",{className:"mt-1 block max-w-full break-all text-[11px] text-gray-500","data-testid":"doc-sync-file-version",children:r??n.hash})]})}function D({filepath:n,original:t,modified:r,originalLabel:a,modifiedLabel:s,originalVersion:i}){const[l,c]=g.useState([]),h=g.useRef(null),u=p(t.text),x=p(r.text),m=(u==null?void 0:u.text)===(x==null?void 0:x.text)?u:null,f=g.useMemo(()=>L(t.text,r.text,l),[l,r.text,t.text]);return e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(y,{side:t,label:a,fileVersion:i}),e.jsx(y,{side:r,label:s})]}),f.length>0?e.jsx("div",{className:"flex min-w-0 flex-col gap-1","aria-label":a,children:f.map((d,o)=>e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-x-2 rounded-md bg-blue-50 px-3 py-1.5 text-xs text-blue-900",children:[d.heading?e.jsx("span",{className:"break-words font-semibold",children:d.heading}):null,d.listItem?e.jsx("span",{className:"break-words",children:d.listItem}):null]},`${d.heading??""}:${d.listItem??""}:${o}`))}):null,m?e.jsxs("details",{className:"min-w-0 rounded-md border border-gray-200 bg-gray-50 text-xs text-gray-600","data-testid":"doc-sync-frontmatter",children:[e.jsx("summary",{className:"cursor-pointer truncate px-3 py-2",children:m.summary}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap break-words border-t border-gray-200 px-3 py-2 font-mono text-[11px] leading-relaxed text-gray-700","data-testid":"doc-sync-frontmatter-text",children:m.text})]}):null,e.jsx("div",{className:"h-[min(45vh,24rem)] min-h-64 min-w-0 shrink-0 overflow-hidden rounded-md border border-gray-200 bg-white",children:e.jsx(j,{filepath:n,original:t.text,modified:r.text,language:"plaintext",theme:"vs",renderSideBySide:!1,options:{automaticLayout:!0,readOnly:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:"on",hideUnchangedRegions:{enabled:!1}},onDiffChange:d=>{c(d.map(o=>({originalStartLineNumber:o.originalStartLineNumber,originalEndLineNumber:o.originalEndLineNumber,modifiedStartLineNumber:o.modifiedStartLineNumber,modifiedEndLineNumber:o.modifiedEndLineNumber}))),window.requestAnimationFrame(()=>{const o=h.current;if(!o)return;const N=m&&m.endLine>2?[{startLineNumber:2,startColumn:1,endLineNumber:m.endLine,endColumn:1}]:[];for(const S of[o.getOriginalEditor(),o.getModifiedEditor()])S.setHiddenAreas(N)})},onEditorReady:d=>{h.current=d}})})]})}export{y as DocSyncSideMetadata,D as DocSyncTextDiff,L as buildDocSyncHunkContexts};
1
+ import{aC as w,aD as e,aE as g}from"./main-d7ppwPBl.js";import{M as j}from"./MonacoDiffSurface-Gs0WyFXL.js";function p(n){const t=/^---\r?\n[\s\S]*?\r?\n---(?=\r?\n|$)/.exec(n);if(!t)return null;const r=t[0].split(/\r?\n/);return{text:t[0],endLine:r.length,summary:r[1]??r[0]}}function b(n,t){const r=n.split(/\r?\n/),a=Math.max(0,Math.min(r.length-1,t-1));let s=null,i=null;for(let l=a;l>=0&&(!s||!i);l-=1){const c=r[l].trimEnd();!s&&/^##\s+/.test(c)&&(s=c),!i&&/^-\s+/.test(c)&&(i=c)}return{heading:s,listItem:i}}function L(n,t,r){var i,l;const a=new Set,s=[];for(const c of r){const h=[b(n,c.originalStartLineNumber),b(t,c.modifiedStartLineNumber)],u=((i=h.find(f=>f.heading))==null?void 0:i.heading)??null,x=((l=h.find(f=>f.listItem))==null?void 0:l.listItem)??null;if(!u&&!x)continue;const m=JSON.stringify([u,x]);a.has(m)||(a.add(m),s.push({heading:u,listItem:x}))}return s}function v(n){if(!n)return null;const t=new Date(n);return Number.isNaN(t.getTime())?n:t.toISOString()}function y({side:n,label:t,fileVersion:r}){const{t:a}=w(),s=v(n.modifiedAt),i=n.revision===null?null:String(n.revision);return e.jsxs("section",{className:"min-w-0 rounded-md border border-gray-200 bg-gray-50 px-3 py-2","aria-label":t,children:[e.jsx("h3",{className:"truncate text-sm font-semibold text-gray-900",children:t}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-1 text-xs text-gray-600",children:[s?e.jsxs("span",{children:[a("threadAppWorkspace.resultShare.docSync.modifiedAt")," ",e.jsx("time",{dateTime:s,children:s})]}):null,i?e.jsxs("span",{children:[a("threadAppWorkspace.resultShare.docSync.version")," ",i]}):null]}),e.jsx("code",{className:"mt-1 block max-w-full break-all text-[11px] text-gray-500","data-testid":"doc-sync-file-version",children:r??n.hash})]})}function D({filepath:n,original:t,modified:r,originalLabel:a,modifiedLabel:s,originalVersion:i}){const[l,c]=g.useState([]),h=g.useRef(null),u=p(t.text),x=p(r.text),m=(u==null?void 0:u.text)===(x==null?void 0:x.text)?u:null,f=g.useMemo(()=>L(t.text,r.text,l),[l,r.text,t.text]);return e.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[e.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-2 sm:grid-cols-2",children:[e.jsx(y,{side:t,label:a,fileVersion:i}),e.jsx(y,{side:r,label:s})]}),f.length>0?e.jsx("div",{className:"flex min-w-0 flex-col gap-1","aria-label":a,children:f.map((d,o)=>e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-x-2 rounded-md bg-blue-50 px-3 py-1.5 text-xs text-blue-900",children:[d.heading?e.jsx("span",{className:"break-words font-semibold",children:d.heading}):null,d.listItem?e.jsx("span",{className:"break-words",children:d.listItem}):null]},`${d.heading??""}:${d.listItem??""}:${o}`))}):null,m?e.jsxs("details",{className:"min-w-0 rounded-md border border-gray-200 bg-gray-50 text-xs text-gray-600","data-testid":"doc-sync-frontmatter",children:[e.jsx("summary",{className:"cursor-pointer truncate px-3 py-2",children:m.summary}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap break-words border-t border-gray-200 px-3 py-2 font-mono text-[11px] leading-relaxed text-gray-700","data-testid":"doc-sync-frontmatter-text",children:m.text})]}):null,e.jsx("div",{className:"h-[min(45vh,24rem)] min-h-64 min-w-0 shrink-0 overflow-hidden rounded-md border border-gray-200 bg-white",children:e.jsx(j,{filepath:n,original:t.text,modified:r.text,language:"plaintext",theme:"vs",renderSideBySide:!1,options:{automaticLayout:!0,readOnly:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:"on",hideUnchangedRegions:{enabled:!1}},onDiffChange:d=>{c(d.map(o=>({originalStartLineNumber:o.originalStartLineNumber,originalEndLineNumber:o.originalEndLineNumber,modifiedStartLineNumber:o.modifiedStartLineNumber,modifiedEndLineNumber:o.modifiedEndLineNumber}))),window.requestAnimationFrame(()=>{const o=h.current;if(!o)return;const N=m&&m.endLine>2?[{startLineNumber:2,startColumn:1,endLineNumber:m.endLine,endColumn:1}]:[];for(const S of[o.getOriginalEditor(),o.getModifiedEditor()])S.setHiddenAreas(N)})},onEditorReady:d=>{h.current=d}})})]})}export{y as DocSyncSideMetadata,D as DocSyncTextDiff,L as buildDocSyncHunkContexts};
@@ -1,4 +1,4 @@
1
- import{bd as z,be as R,aE as a,aC as L,bf as O,bg as A,aD as c,bh as C}from"./main-2eGGGkuY.js";import{l as b,M as B}from"./MonacoDiffSurface-CcuWl3pT.js";/**
1
+ import{bd as z,be as R,aE as a,aC as L,bf as O,bg as A,aD as c,bh as C}from"./main-d7ppwPBl.js";import{l as b,M as B}from"./MonacoDiffSurface-Gs0WyFXL.js";/**
2
2
  * @license lucide-react v0.563.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{bd as H,bi as K,aC as T,bj as Ie,bk as D,aE as l,bl as At,bm as we,bn as B,bo as Ze,bp as P,bq as zt,br as Mt,bs as _t,aD as e,bt as O,bh as me,bu as Dt,bv as Le,bw as Pt,bx as et,by as Ot,bz as Tt,bA as qe,bB as Ft,bC as We,bD as Ut,bE as $t,bF as Vt,bG as Ce,bH as se,bI as Ke,bJ as Bt,bK as tt,bL as Ht,bM as qt,bN as Wt,bO as Kt,bP as st,bQ as rt,bR as at,bS as Se,bT as re,bU as Gt,bV as nt,bW as it,bX as lt,bY as Qt,bZ as Yt,b_ as Jt}from"./main-2eGGGkuY.js";import{b$ as zs}from"./main-2eGGGkuY.js";/**
1
+ import{bd as H,bi as K,aC as T,bj as Ie,bk as D,aE as l,bl as At,bm as we,bn as B,bo as Ze,bp as P,bq as zt,br as Mt,bs as _t,aD as e,bt as O,bh as me,bu as Dt,bv as Le,bw as Pt,bx as et,by as Ot,bz as Tt,bA as qe,bB as Ft,bC as We,bD as Ut,bE as $t,bF as Vt,bG as Ce,bH as se,bI as Ke,bJ as Bt,bK as tt,bL as Ht,bM as qt,bN as Wt,bO as Kt,bP as st,bQ as rt,bR as at,bS as Se,bT as re,bU as Gt,bV as nt,bW as it,bX as lt,bY as Qt,bZ as Yt,b_ as Jt}from"./main-d7ppwPBl.js";import{b$ as zs}from"./main-d7ppwPBl.js";/**
2
2
  * @license lucide-react v0.563.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.