crewx 0.9.0-rc.237 → 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 (91) hide show
  1. package/bin/crewx-memory-runtime.js +7 -3
  2. package/bin/crewx.js +12 -8
  3. package/dist/assets/{DocSyncTextDiff-B6Xm9KkT.js → DocSyncTextDiff-J1cEZfvG.js} +1 -1
  4. package/dist/assets/{GitDiffEditor-C-PWr-1s.js → GitDiffEditor-B7cdAJ7W.js} +1 -1
  5. package/dist/assets/{MarketPage-rgKLj_sA.js → MarketPage-DjjZCS8d.js} +1 -1
  6. package/dist/assets/{MonacoDiffSurface-BZmnrlo7.js → MonacoDiffSurface-Gs0WyFXL.js} +7 -7
  7. package/dist/assets/{PromptTab-Bi2btRqZ.js → PromptTab-DZdNMc19.js} +1 -1
  8. package/dist/assets/{abnfDiagram-VCTEODGH-BoyuSq0D.js → abnfDiagram-VCTEODGH-X5HbZxTM.js} +1 -1
  9. package/dist/assets/{arc-E5iEdPfE.js → arc-Ct3vRsL-.js} +1 -1
  10. package/dist/assets/{architectureDiagram-5GKGNRK7-DxkKJxW-.js → architectureDiagram-5GKGNRK7-DwM2gdry.js} +1 -1
  11. package/dist/assets/{blockDiagram-I7D4REHJ--dVaVxm9.js → blockDiagram-I7D4REHJ-CaxkONqQ.js} +1 -1
  12. package/dist/assets/{c4Diagram-7LVT6UL2-CTmTK7FK.js → c4Diagram-7LVT6UL2-sGcF_W47.js} +1 -1
  13. package/dist/assets/channel-CWWdmQVT.js +1 -0
  14. package/dist/assets/{chunk-2Q5K7J3B-mXtBqkPH.js → chunk-2Q5K7J3B-B1kI0qxp.js} +1 -1
  15. package/dist/assets/{chunk-5VM5RSS4-CHNwKeYg.js → chunk-5VM5RSS4-CnVV3UMX.js} +1 -1
  16. package/dist/assets/{chunk-F27PBJKO-C7y5DoIM.js → chunk-F27PBJKO-Bvu6rnDn.js} +1 -1
  17. package/dist/assets/{chunk-IMKFNOWR-Cy0d_9oN.js → chunk-IMKFNOWR-BWhA2P3C.js} +1 -1
  18. package/dist/assets/{chunk-JWPE2WC7-plHyrLqQ.js → chunk-JWPE2WC7-CVTDsrje.js} +1 -1
  19. package/dist/assets/{chunk-POPQ4Y6H-D7RRXLQG.js → chunk-POPQ4Y6H-olHx95Jx.js} +1 -1
  20. package/dist/assets/{chunk-SVP7TREG-Df4HRG0z.js → chunk-SVP7TREG-CvhT8vjm.js} +1 -1
  21. package/dist/assets/{chunk-TICWLB2K-CliZPZEn.js → chunk-TICWLB2K-BvbmH3fg.js} +1 -1
  22. package/dist/assets/{chunk-XXDRQBXY-MNVs1Deh.js → chunk-XXDRQBXY-CrNQlN2X.js} +1 -1
  23. package/dist/assets/classDiagram-ZZMXUADV-BEHZXrFc.js +1 -0
  24. package/dist/assets/classDiagram-v2-VYDZK3BY-BEHZXrFc.js +1 -0
  25. package/dist/assets/{cose-bilkent-JH36ORCC-BvfKJREV.js → cose-bilkent-JH36ORCC-D0fIGbXq.js} +1 -1
  26. package/dist/assets/{cssMode-CnrK9xi1.js → cssMode-DoSVMJfZ.js} +1 -1
  27. package/dist/assets/{cynefin-OW5HDTMX-BtqQvSax.js → cynefin-OW5HDTMX-DExI3DBm.js} +1 -1
  28. package/dist/assets/{cynefinDiagram-5FMLGOSQ-B8IvxJ0y.js → cynefinDiagram-5FMLGOSQ-Bqchsgx2.js} +1 -1
  29. package/dist/assets/{dagre-GXQ25YYZ-FxGcv8M0.js → dagre-GXQ25YYZ-DKRj9SbG.js} +1 -1
  30. package/dist/assets/{diagram-S7CK7UJ4-DohFMUWD.js → diagram-S7CK7UJ4-aQDMFQoY.js} +1 -1
  31. package/dist/assets/{diagram-UQ7AKVKN-DbWV995D.js → diagram-UQ7AKVKN-CQVDukiW.js} +1 -1
  32. package/dist/assets/{diagram-VSXAHHWV-BXPqvVGH.js → diagram-VSXAHHWV-K1MNBeLA.js} +1 -1
  33. package/dist/assets/{diagram-VX7I27RA-CsLgwaku.js → diagram-VX7I27RA-DhQSfD3K.js} +1 -1
  34. package/dist/assets/{diagram-Z3DM3KII-CfQuaoFx.js → diagram-Z3DM3KII-CjGJqvQf.js} +1 -1
  35. package/dist/assets/{ebnfDiagram-PWID7BFC-BPYA-Uu3.js → ebnfDiagram-PWID7BFC-SQnem0qi.js} +1 -1
  36. package/dist/assets/{erDiagram-RLTQ6QDP-DA-9ihpi.js → erDiagram-RLTQ6QDP-CqFUXukX.js} +1 -1
  37. package/dist/assets/{flowDiagram-HODETNUW-NJ2kpyR6.js → flowDiagram-HODETNUW-SpmzRY61.js} +1 -1
  38. package/dist/assets/{freemarker2-D6VRQn3o.js → freemarker2-BFl61qIr.js} +1 -1
  39. package/dist/assets/{ganttDiagram-EL5Y4UJY-CN80a1vb.js → ganttDiagram-EL5Y4UJY-ByEQTPyc.js} +1 -1
  40. package/dist/assets/{gitGraphDiagram-WWUBYQGX-DnkPDwzA.js → gitGraphDiagram-WWUBYQGX-CfJ4hQPX.js} +1 -1
  41. package/dist/assets/{handlebars-CBTdj-E_.js → handlebars-CsonD4io.js} +1 -1
  42. package/dist/assets/{html-CKlYOoZd.js → html-Bdk84Te4.js} +1 -1
  43. package/dist/assets/{htmlMode-CQ1XkBcg.js → htmlMode-6vHtznEG.js} +1 -1
  44. package/dist/assets/{infoDiagram-27XIBGKW-CeoAEYkn.js → infoDiagram-27XIBGKW-UMZeZX-k.js} +1 -1
  45. package/dist/assets/{ishikawaDiagram-5VMMS53U-BH46eDIB.js → ishikawaDiagram-5VMMS53U-eKPVkKJ-.js} +1 -1
  46. package/dist/assets/{javascript-DbgeF7Cx.js → javascript-d96FO6jl.js} +1 -1
  47. package/dist/assets/{journeyDiagram-3NMN7TZE-BOwEcgjc.js → journeyDiagram-3NMN7TZE-DIBD-w04.js} +1 -1
  48. package/dist/assets/{jsonMode-BmbNUVVq.js → jsonMode-CTveyt4X.js} +1 -1
  49. package/dist/assets/{kanban-definition-UXKFOSKX-BkCRxeP3.js → kanban-definition-UXKFOSKX-CutHc6E7.js} +1 -1
  50. package/dist/assets/{layout-DQUmCAbR.js → layout-DJcRZhNQ.js} +1 -1
  51. package/dist/assets/{linear-gHaVu9xJ.js → linear-DvvuhzAM.js} +1 -1
  52. package/dist/assets/{liquid-AgidL2-1.js → liquid-N_KqwWu3.js} +1 -1
  53. package/dist/assets/main-BbFtintH.css +10 -0
  54. package/dist/assets/{main-GYuFvIBu.js → main-d7ppwPBl.js} +475 -475
  55. package/dist/assets/{mdx-BQ4WkIVX.js → mdx-1IhdOiY4.js} +1 -1
  56. package/dist/assets/{mindmap-definition-YA3MSWOX-B9sFUo1T.js → mindmap-definition-YA3MSWOX-DjLQAFmX.js} +1 -1
  57. package/dist/assets/{pegDiagram-XKGWAZYB-CkP54iiU.js → pegDiagram-XKGWAZYB-CTo3_kUg.js} +1 -1
  58. package/dist/assets/{pieDiagram-E7YTZNPT-BarK0Wdr.js → pieDiagram-E7YTZNPT-CaRbExMp.js} +1 -1
  59. package/dist/assets/{python-Bvah5-B6.js → python-BBNKQOf0.js} +1 -1
  60. package/dist/assets/{quadrantDiagram-AXDQQJYC-Bx2yAto_.js → quadrantDiagram-AXDQQJYC-CnMnxVz2.js} +1 -1
  61. package/dist/assets/{railroadDiagram-O6MQD6OU-DKwA_Vtz.js → railroadDiagram-O6MQD6OU-T3CDdFay.js} +1 -1
  62. package/dist/assets/{razor-BArYzMwx.js → razor-CSKI0BR8.js} +1 -1
  63. package/dist/assets/{requirementDiagram-BXWQKSXE-Dl3eZsdu.js → requirementDiagram-BXWQKSXE-Bm1DPFEM.js} +1 -1
  64. package/dist/assets/{sankeyDiagram-P5KCCOFB-BT-EUHg8.js → sankeyDiagram-P5KCCOFB-Db6D9GE8.js} +1 -1
  65. package/dist/assets/{sequenceDiagram-WJ2MYXX4-DFN97HFT.js → sequenceDiagram-WJ2MYXX4-DLxzW9XS.js} +1 -1
  66. package/dist/assets/{sizeCapture-INFHLROL-CFx7FiYM.js → sizeCapture-INFHLROL-fAGSVd0_.js} +1 -1
  67. package/dist/assets/{stateDiagram-D77RDMKH-DpCD-L1t.js → stateDiagram-D77RDMKH-9o-5WKLi.js} +1 -1
  68. package/dist/assets/stateDiagram-v2-MP3YSRHH-DXfhBM43.js +1 -0
  69. package/dist/assets/{swimlanes-42K2YHIH-CXp8IHO4.js → swimlanes-42K2YHIH-9Ed3i3tt.js} +1 -1
  70. package/dist/assets/swimlanesDiagram-VR7AAH4N-DKPIePR6.js +8 -0
  71. package/dist/assets/{timeline-definition-24CTP7MA-DuQyOBST.js → timeline-definition-24CTP7MA-DX-6XLrk.js} +1 -1
  72. package/dist/assets/{transformers.web-QgqVZX_0.js → transformers.web-Mo-sbH11.js} +1 -1
  73. package/dist/assets/{tsMode-6IiKwTYx.js → tsMode-xRb4Q_R_.js} +1 -1
  74. package/dist/assets/{typescript-DzZFI9VE.js → typescript-DlZdS9JW.js} +1 -1
  75. package/dist/assets/{vennDiagram-4TSXK5OY-CjCy0DlF.js → vennDiagram-4TSXK5OY-CXRmx4hH.js} +1 -1
  76. package/dist/assets/{wardleyDiagram-VM6X3IG4-JWvRIdFS.js → wardleyDiagram-VM6X3IG4-JaP9VmDL.js} +1 -1
  77. package/dist/assets/{xml-DbG2NXrB.js → xml-BLt-z2aW.js} +1 -1
  78. package/dist/assets/{xychartDiagram-S5SC5T6Z-DUUFW9vj.js → xychartDiagram-S5SC5T6Z-ziPu3ANR.js} +1 -1
  79. package/dist/assets/{yaml-DtBZLorE.js → yaml-D6VYrUED.js} +1 -1
  80. package/dist/index.html +3 -3
  81. package/dist/ui-build.json +1 -1
  82. package/dist-server/domain/doc-sync/doc-sync.host.js +2 -2
  83. package/dist-server/domain/task/task.service.js +2 -2
  84. package/package.json +20 -17
  85. package/packages/cli/package.json +1 -1
  86. package/dist/assets/channel-2icooOsQ.js +0 -1
  87. package/dist/assets/classDiagram-ZZMXUADV-BWJqEFYO.js +0 -1
  88. package/dist/assets/classDiagram-v2-VYDZK3BY-BWJqEFYO.js +0 -1
  89. package/dist/assets/main-BjOE01kD.css +0 -10
  90. package/dist/assets/stateDiagram-v2-MP3YSRHH-DiycyohT.js +0 -1
  91. package/dist/assets/swimlanesDiagram-VR7AAH4N-CUuFpDm9.js +0 -8
@@ -1,3 +1,7 @@
1
- import{createHash as S}from"node:crypto";import{spawn as T}from"node:child_process";import{chmodSync as _,copyFileSync as C,lstatSync as y,mkdtempSync as N,readFileSync as h,rmSync as R}from"node:fs";import{tmpdir as P}from"node:os";import{fileURLToPath as $}from"node:url";import{basename as O,dirname as w,isAbsolute as A,join as p,relative as L,resolve as v,sep as U}from"node:path";const M=1;const I=["SIGINT","SIGTERM","SIGHUP"];const W={darwin:"darwin",linux:"linux",win32:"windows"};const X={arm64:"arm64",x64:"amd64"};function D(e=process.env){const r=e.CREWX_MEMORY_RUNTIME===void 0?"auto":e.CREWX_MEMORY_RUNTIME;if(!["auto","go","node"].includes(r)){throw new Error("CREWX_MEMORY_RUNTIME must be auto, go, or node.")}return r}function z(e){if(!Array.isArray(e)||e[0]!=="memory")return null;const r=e[1];const n=e[2];if(!n||b(n))return null;if(r==="index"&&e.length===3){return{command:r,agentId:n,argument:void 0}}if(r==="get"&&e.length===4&&e[3]&&!b(e[3])){return{command:r,agentId:n,argument:e[3]}}if(r==="find"&&e.length===4&&e[3]&&!b(e[3])){return{command:r,agentId:n,argument:e[3]}}return null}function b(e){return e==="-h"||e.startsWith("--")}function Q(){return"CREWX_MEMORY_RUNTIME=go supports only `crewx memory index <agent>`, `get <agent> <id>`, and `find <agent> <query>` without options. Use CREWX_MEMORY_RUNTIME=node for other memory commands."}function Z(e){return`Native memory support is unavailable (${e}). Use CREWX_MEMORY_RUNTIME=node to roll back to the existing implementation.`}function ee(e=w(w($(import.meta.url)))){const r=[p(e,"node_modules","@crewx","memory"),p(w(e),"@crewx","memory")];for(const n of r){try{const t=p(n,"package.json");const a=y(t);if(!a.isFile()||a.isSymbolicLink())continue;const o=JSON.parse(h(t,"utf8"));if(o.name==="@crewx/memory"&&typeof o.version==="string")return v(n)}catch{}}throw new Error("installed @crewx/memory package was not found beside CrewX")}function F(e=process.platform,r=process.arch){const n=W[e];const t=X[r];if(!n||!t)return null;return`${n}-${t}`}function te(e,r=process.platform,n=process.arch){const t=F(r,n);if(!t)return{ok:false,reason:`unsupported platform ${r}/${n}`};try{const a=v(e);const o=p(a,"package.json");const s=p(a,"go","native-manifest.json");const m=y(o);const f=y(s);if(!m.isFile()||m.isSymbolicLink()||!f.isFile()||f.isSymbolicLink()){return{ok:false,reason:"package metadata is not a regular installed-package file"}}const u=JSON.parse(h(o,"utf8"));const c=JSON.parse(h(s,"utf8"));if(u.name!=="@crewx/memory"||typeof u.version!=="string"){return{ok:false,reason:"installed memory package identity is invalid"}}if(c.formatVersion!==1||c.protocol!==M){return{ok:false,reason:`unsupported manifest/protocol (expected protocol ${M})`}}if(c.packageVersion!==u.version){return{ok:false,reason:`manifest version ${c.packageVersion??"(missing)"} does not match package ${u.version}`}}const l=c.targets?.[t];if(!l||typeof l.file!=="string"||typeof l.sha256!=="string"){return{ok:false,reason:`no packaged native executable for ${t}`}}const x=t.startsWith("windows-")?".exe":"";const k=`go/bin/crewx-memory-${t}${x}`;if(l.file!==k||A(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 i=v(a,l.file);const d=L(a,i);if(!d||d.startsWith(`..${U}`)||d===".."){return{ok:false,reason:"native executable escaped its installed package"}}const g=y(i);if(!g.isFile()||g.isSymbolicLink()){return{ok:false,reason:"native executable is not a regular packaged file"}}const E=S("sha256").update(h(i)).digest("hex");if(E!==l.sha256){return{ok:false,reason:"native executable hash does not match its protected manifest"}}return{ok:true,artifact:{executablePath:i,packageVersion:u.version,protocol:c.protocol,sha256:E,executable:r==="win32"||(g.mode&73)!==0,skillVersion:V(a)}}}catch(a){return{ok:false,reason:a instanceof Error?a.message:String(a)}}}function re(e,r=process.platform){if(r==="win32"||e.executable){return{ok:true,executablePath:e.executablePath,cleanup:()=>{}}}let n;try{n=N(p(P(),"crewx-memory-native-"));const t=p(n,O(e.executablePath));C(e.executablePath,t);_(t,448);const a=S("sha256").update(h(t)).digest("hex");if(a!==e.sha256)throw new Error("staged native executable hash does not match its installed package artifact");return{ok:true,executablePath:t,temporaryExecutablePath:t,cleanup:()=>R(n,{recursive:true,force:true})}}catch(t){if(n)R(n,{recursive:true,force:true});return{ok:false,reason:t instanceof Error?t.message:String(t),cleanup:()=>{}}}}function V(e){const r=h(p(e,"SKILL.md"),"utf8");const n=r.match(/^---\r?\n([\s\S]*?)\r?\n---/u)?.[1];const t=n?.match(/^\s*version:\s*(.+?)\s*$/mu);if(!t)return null;return t[1].replace(/^['"]|['"]$/gu,"")}async function ne(e,r,n=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(n.CREWX_NO_TRACE==="1")return{ok:true,handle:null};const a=await import("@crewx/shared/skill-tracer");if(typeof a.trace!=="function"){return{ok:false,reason:"the shared skill activity tracer is unavailable"}}const o=typeof a.getOwnSkillVersion==="function"?a.getOwnSkillVersion(e):null;const s=a.trace("crewx/memory",r.join(" "),{agentId:n.CREWX_AGENT_ID,skillVersion:o});if(!s||s._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:s}}catch(t){return{ok:false,reason:`activity tracing could not start: ${t instanceof Error?t.message:String(t)}`}}}async function oe(e,r,n=process.env,t=null){const a=[`--crewx-memory-protocol=${e.protocol}`,`--crewx-memory-version=${e.packageVersion}`,r.command,r.agentId];if(r.argument!==void 0)a.push(r.argument);let o;let s;try{o=await G(e.executablePath,a,n)}catch(c){s=c;o={code:127,signal:null,stdout:Buffer.alloc(0),stderr:Buffer.alloc(0)}}const m=o.stdout.toString("utf8");const f=o.stderr.toString("utf8");let u;if(t){try{if(!s&&o.code===0&&!o.signal){t.ok(m||null,{stderr:f||void 0})}else{const c=f.trim()||s?.message||`native memory exited with code ${o.code??o.signal}`;t.fail(c,{stderr:f||void 0})}}catch(c){u=c}}if(o.stdout.length>0)process.stdout.write(o.stdout);if(o.stderr.length>0)process.stderr.write(o.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(s){process.stderr.write(`Native memory process could not be started: ${s.message}
3
- `);return{exitCode:127}}return{exitCode:o.signal?Y(o.signal):o.code??1}}function G(e,r,n=process.env,t=process){return new Promise((a,o)=>{let s;try{s=T(e,r,{cwd:process.cwd(),env:n,stdio:["pipe","pipe","pipe"],windowsHide:true})}catch(i){o(i);return}const m=[];const f=[];let u;let c;let l;const x=new Map;const k=i=>{if(c)return;c=i;try{s.kill(i)}catch{}l=setTimeout(()=>{if(s.exitCode===null&&s.signalCode===null)s.kill("SIGKILL")},5e3);l.unref?.()};for(const i of I){const d=k.bind(null,i);x.set(i,d);t.once(i,d)}s.stdin.on("error",()=>{});s.stdout.on("data",i=>m.push(Buffer.from(i)));s.stderr.on("data",i=>f.push(Buffer.from(i)));s.once("error",i=>{u=i});s.once("close",(i,d)=>{for(const g of I)t.removeListener(g,x.get(g));if(l)clearTimeout(l);if(u){o(u);return}a({code:i,signal:d??c??null,stdout:Buffer.concat(m),stderr:Buffer.concat(f)})})})}function Y(e){if(e==="SIGINT")return 130;if(e==="SIGTERM")return 143;if(e==="SIGHUP")return 129;return 1}export{M as MEMORY_PROTOCOL,D as getRuntimeMode,F as nativeTargetKey,Z as nativeUnavailableMessage,z as parseSupportedMemoryRead,re as prepareNativeExecutable,ne as prepareNativeTrace,ee as resolveInstalledMemoryPackageRoot,te as resolveNativeArtifact,G as runForegroundProcess,oe as runNativeMemoryRead,Q as unsupportedNativeReadMessage};
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,10 +1,14 @@
1
1
  #!/usr/bin/env node
2
- async function d(){const t=process.argv.slice(2);if(t[0]!=="memory"){await import("./crewx-dispatch.js");return}const e=await import("./crewx-memory-runtime.js");let r;try{r=e.getRuntimeMode(process.env)}catch(s){process.stderr.write(`${s.message}
3
- `);process.exitCode=2;return}if(r==="node"){await import("./crewx-dispatch.js");return}const c=e.parseSupportedMemoryRead(t);if(!c){if(r==="go"){process.stderr.write(`${e.unsupportedNativeReadMessage()}
4
- `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}if(process.versions.electron){if(r==="go"){process.stderr.write("Native memory reads are unavailable in CrewX Desktop. Use CREWX_MEMORY_RUNTIME=node or auto.\n");process.exitCode=2;return}await import("./crewx-dispatch.js");return}let n;try{n=e.resolveInstalledMemoryPackageRoot()}catch(s){if(r==="go"){process.stderr.write(`${e.nativeUnavailableMessage(s.message)}
5
- `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}const o=e.resolveNativeArtifact(n);if(!o.ok){if(r==="go"){process.stderr.write(`${e.nativeUnavailableMessage(o.reason)}
6
- `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}const a=e.prepareNativeExecutable(o.artifact);if(!a.ok){if(r==="go"){process.stderr.write(`${e.nativeUnavailableMessage(a.reason)}
7
- `);process.exitCode=2;return}await import("./crewx-dispatch.js");return}const i=await e.prepareNativeTrace(n,t,process.env);if(!i.ok){a.cleanup();if(r==="go"){process.stderr.write(`${i.reason}
8
- `);process.exitCode=2;return}process.stderr.write(`[memory] Native reads are unavailable: ${i.reason} Falling back to Node.
9
- `);await import("./crewx-dispatch.js");return}try{const s={...o.artifact,executablePath:a.executablePath};const p=await e.runNativeMemoryRead(s,c,process.env,i.handle);process.exitCode=p.exitCode}finally{a.cleanup()}}d().catch(t=>{process.stderr.write(`crewx: ${t instanceof Error?t.message:String(t)}
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)}
10
14
  `);process.exitCode=1});
@@ -1 +1 @@
1
- import{aC as w,aD as e,aE as g}from"./main-GYuFvIBu.js";import{M as j}from"./MonacoDiffSurface-BZmnrlo7.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-GYuFvIBu.js";import{l as b,M as B}from"./MonacoDiffSurface-BZmnrlo7.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-GYuFvIBu.js";import{b$ as zs}from"./main-GYuFvIBu.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.