Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
TypeScript aiai-agentsai-memoryanthropicartificial-intelligencechromadbclaudeclaude-agent-sdkclaude-agentsclaude-codeclaude-code-pluginclaude-skillsembeddingslong-term-memorymem0memory-engineopenmemoryragsqlitesupermemory
import{h as e,t,u as n}from"./parse-sse-frame-DXl4zDFf.js";import{Dn as r,Ft as i,It as a,Pt as o,Rt as s,gt as c}from"./index-Dknlc6p6.js";s.filter(e=>e!==`savings`);function l(e){return{installationComplete:!0,installConfirmed:!0,installReview:!1,scanReview:!1,branch:`go`,memoryBilling:`existing`,cloudSyncOffer:o,alreadyPro:e,scanComplete:!1,scanSkipped:!1,revealContinued:!1,choiceContinued:!1,checkoutReviewed:!1,finishTools:[],importStatus:`none`,setupComplete:!1}}function u(e){return e.branch===`go`&&!e.alreadyPro}function d(e){return u(e)&&!e.checkoutReviewed?`checkout`:`finish-setup`}function f(e,t=!1){return t||!!e&&e!==`waiting-for-choice`&&e!==`failed`}function p(e,t,n,r){return!t||n&&!f(r)||e.branch===t.branch&&e.memoryBilling===t.memoryBilling&&e.cloudSyncOffer===(t.cloudSyncOffer??`cloud_sync_monthly`)?e:{...e,branch:t.branch,memoryBilling:t.memoryBilling,cloudSyncOffer:t.cloudSyncOffer??`cloud_sync_monthly`}}var m=[`scan`,`reveal`],h=[`finish-setup`,`import`,`launch`,`workspace`],g=e=>e.scanComplete||e.scanSkipped;function _(e,t){return!t.installationComplete||!t.scanComplete?!1:e===`scan`&&!t.scanReview||e===`install`&&!t.installReview}function v(e,t){if(!t.installationComplete)return`install`;if(e===`install`)return t.installReview?`install`:g(t)?`reveal`:`scan`;if(!s.includes(e)||e!==`scan`&&!g(t)&&!t.choiceContinued)return`scan`;if(!m.includes(e)&&!t.revealContinued)return`reveal`;if(![...m,`choice`].includes(e)&&!t.choiceContinued)return`choice`;let n=d(t);return e===`savings`||e===`checkout`&&!u(t)||h.includes(e)&&n!==`finish-setup`?n:e===`import`&&(t.branch!==`go`||t.importStatus!==`running`)||(e===`launch`||e===`workspace`)&&(!t.setupComplete||t.finishTools.length===0)?`finish-setup`:e}var y=[`tools`,`memory`,`plan`,`connect`,`done`],b={tools:`Tools`,memory:`Memory`,plan:`Plan`,connect:`Connect`,done:`Done`},x={install:`tools`,scan:`memory`,reveal:`memory`,choice:`plan`,checkout:`plan`,"finish-setup":`connect`,import:`connect`,launch:`done`,workspace:`done`},S={tools:e=>e.installConfirmed,memory:e=>e.revealContinued,plan:e=>e.choiceContinued&&d(e)===`finish-setup`,connect:e=>e.setupComplete,done:()=>!1};function C(e,t,n){return x[t]===e?`current`:S[e](n)?`done`:`upcoming`}var w={install:()=>null,scan:(e,t)=>t.hasInstallStep?`install`:null,reveal:()=>`scan`,choice:()=>`reveal`,checkout:(e,t)=>t.choiceLocked?null:`choice`,"finish-setup":(e,t)=>u(e)?`checkout`:t.choiceLocked?null:`choice`,import:()=>`finish-setup`,launch:()=>`finish-setup`,workspace:()=>`finish-setup`};function T(e,t,n){return w[e](t,n)}var E={idle:!0,reading:!0,checking:!0,saving:!0,organizing:!0,"awaiting-consent":!1,uploading:!0,done:!1,failed:!1};function D(e){return E[e]}function ee(e,t){return e===`scan`&&D(t)?`scan`:e===`import`?`import`:null}var te=1950,ne=1500;function re(e){return Math.max(te,ne+80*Math.max(0,e-1))}var O=5,k=e=>String(e).padStart(2,`0`);function A(e){if(e==null||e===``)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:`${k(t.getMonth()+1)}-${k(t.getDate())} ${k(t.getHours())}:${k(t.getMinutes())}`}var ie=e=>e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(5):``,ae=e=>e===`claude`?`claude`:e===`codex`?`codex`:e?.startsWith(`gemini`)?`gemini`:`other`,oe=new Set([`on`,`suggested`]);function se(t){let n=t.setup?.extraction??null,r=n?.state===`ok`||n?.state===`failed`,i=e(t,Date.parse(t.generatedAt)),a=i.focusAreas.length?i.focusAreas:r?[]:null,o=t.goals?[...t.goals.areas].sort((e,t)=>(e.rank??1/0)-(t.rank??1/0)).slice(0,O).map((e,t)=>({id:e.id,rank:e.rank??t+1,title:e.title,timesAsked:e.timesAsked??e.evidence.length,latestAt:ie(e.latestAt)})):null,s=t.setup?.work??null,c=s?s.slice(0,O).map(e=>({id:e.groupId,title:e.title,agent:ae(e.platform),lastActiveAt:A(e.lastActiveAt),...e.progressPercent===null?{}:{progressPercent:e.progressPercent}})):null,l=(t.rules??[]).filter(e=>oe.has(e.status)&&e.quotes.length),u=t.story?.story||l.length?[...l].sort((e,t)=>t.timesSeen-e.timesSeen).slice(0,O).map(e=>({id:e.ruleId,text:e.when?`${e.when}: ${e.then}`:e.then,quote:e.quotes[0].quote,quotedAt:A(e.quotes[0].at)})):null;return{goals:o??(r?[]:null),work:c??(r?[]:null),rules:u??(r?[]:null),focusAreas:a,requests:i.requests,requestReadErrorCount:i.requestReadErrors.length}}function ce(e,t){let i=n(e.next);return i.kind===`step`?r(i,t):null}var le=256e3,j={claude:`Claude Code`,codex:`Codex`,"gemini-cli":`Gemini CLI`,"antigravity-cli":`Antigravity CLI`,opencode:`OpenCode`,cursor:`Cursor`,hermes:`Hermes`};function M(e){return e?Object.hasOwn(j,e)?j[e]:e:`Claude-Mem`}var N=e=>e&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):new Date().toISOString().slice(0,10),P=e=>e?e.slice(0,8):`session`,F=(e,t)=>e.length>t?`${e.slice(0,t-1).trimEnd()}…`:e;function ue(e){let t=(e.observations??[]).map(e=>({id:`observation-${e.id}`,title:e.title||F(e.narrative??e.text??`Memory`,80),body:e.narrative||e.text||e.subtitle||``,project:e.project||`claude-mem`,agent:M(e.platform_source),session:P(e.memory_session_id),date:N(e.created_at)})),n=(e.sessions??[]).map(e=>({id:`summary-${e.id}`,title:F(e.request||`Session summary`,120),body:e.learned||e.completed||e.investigated||``,project:e.project||`claude-mem`,agent:M(e.platform_source),session:P(e.memory_session_id),date:N(e.created_at)})),r=(e.prompts??[]).filter(e=>e.prompt_text?.trim()).map(e=>({id:`prompt-${e.id}`,title:F(e.prompt_text.trim().split(`
`)[0],120),body:F(e.prompt_text.trim(),600),project:e.project||`claude-mem`,agent:M(e.platform_source),session:P(e.content_session_id),date:N(e.created_at)}));return[...t,...n,...r]}var de=e=>`/api/search?${new URLSearchParams({query:e,format:`json`,limit:`10`})}`,I=(e,t)=>({title:`Note: ${e.title}`.slice(0,200),text:t,project:e.project}),fe=1719,pe=new TextEncoder,L=e=>pe.encode(JSON.stringify(e)).length-2;function me(e){let{title:t,project:n}=I(e,``);return le-fe-L(t)-2*L(n)}var R=(e,t)=>t>0&&t<e.length&&/[\uD800-\uDBFF]/.test(e[t-1])&&/[\uDC00-\uDFFF]/.test(e[t])?t-1:t;function he(e,t){let n=me(e);if(L(t)<=n)return{text:t,cut:!1};if(n<=0)return{text:``,cut:!0};let r=0,i=t.length;for(;i-r>1;){let e=Math.floor((r+i)/2);L(t.slice(0,R(t,e)))<=n?r=e:i=e}return{text:t.slice(0,R(t,r)),cut:!0}}function z(e){return e.status===`pending`&&!!e.install}function ge(e){return e.reduce((e,t)=>e+t.uploadBytes,0)>a}var B=class extends Error{kind;status;constructor(e,t,n){super(t),this.name=`SetupRequestError`,this.kind=e,this.status=n}};function V(e){return{kind:e instanceof B?e.kind:`page`,detail:e instanceof Error?e.message:String(e)}}var H={connectionError:null,connectionErrorKind:null,choice:null,install:void 0,scan:{agents:[],percent:0,phase:`idle`,done:!1,error:null,improveProduct:!0,uploadedAgents:null},reveal:{goals:null,work:null,rules:null,focusAreas:null,requests:[],requestReadErrorCount:0},extraction:null,recentPrompts:[],checkout:null,installer:null,alreadyPro:!1,detectedTools:[],history:null,historyImport:null,suggestions:[]};function _e(e,t){return e.connectionError===null||t===`scan`&&e.scan.phase===`failed`&&e.scan.error===e.connectionError?null:{kind:e.connectionErrorKind??`page`,detail:e.connectionError}}var U=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=0?e:void 0,ve=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>=100&&e<=599?e:void 0,ye=e=>typeof e==`string`&&e.trim()?e.trim():void 0,be=e=>i.includes(e),W=e=>{if(!e||e.state===`idle`||!be(e.state))return null;let t=e.state===`failed`?ve(e.errorStatus):void 0,n=e.state===`failed`?ye(e.errorMessage):void 0;return{state:e.state,percent:e.percent,imported:e.imported,error:e.state===`failed`?e.error:null,...t===void 0?{}:{errorStatus:t},...n===void 0?{}:{errorMessage:n},...U(e.sent)!==void 0&&U(e.total)?{sent:U(e.sent),total:U(e.total)}:{},...U(e.skipped)===void 0?{}:{skipped:U(e.skipped)},...e.state===`stopped`&&U(e.unconfirmed)?{unconfirmed:U(e.unconfirmed)}:{}}};async function G(e,t){let n;try{n=await fetch(e,{cache:`no-store`,...t})}catch(e){throw new B(`unreachable`,e instanceof Error?e.message:String(e))}let r=null;try{r=await n.json()}catch{}if(!n.ok){let t=r?.error;throw new B(`refused`,typeof t==`string`?t:`The worker answered ${n.status} for ${e}.`,n.status)}return r}var K=(e,t)=>G(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});async function xe(){let e=await fetch(`/api/setup/state`,{cache:`no-store`});return e.ok?z(await e.json()):!1}var Se=e=>({agents:e.agents.map(({id:e,label:t,detected:n,prompts:r,uploadBytes:i})=>({id:e,label:t,detected:n,prompts:r,canRunSetup:null,cannotRunReason:null,uploadBytes:i??0})),percent:e.percent,phase:e.phase,done:e.done,error:e.error,improveProduct:e.improveProduct??!0,uploadedAgents:e.uploadedAgents??null,hostedNotice:e.hostedNotice??null}),Ce=Promise.resolve(),q,J,we=Promise.resolve(),Y=null,X=null,Z=null,Q=null,$=async e=>{Q?await Q(e):await K(e,{})},Te={kind:`local`,subscribe(e){let n=H,r=!1,i=0,a=0,o=0,s;we=new Promise(e=>{s=e});let l=t=>{r||(n={...n,...t},e(n))},u=e=>{i++,J=e.improveProduct??!0,l({scan:Se(e),recentPrompts:e.recentPrompts??[],detectedTools:e.agents.filter(e=>e.detected).map(e=>e.id).filter(e=>c.some(t=>t.id===e))})},d=0,p=async(e=++d)=>{try{let{userCode:t,expiresAt:i}=await G(`/api/setup/checkout/device-code`);if(r||e!==d||n.checkout?.state!==`waiting`)return;l({checkout:{...n.checkout,userCode:t,expiresAt:i}})}catch(t){if(r||e!==d||n.checkout?.state!==`waiting`)return;if(t instanceof B&&t.kind===`refused`&&t.status===404){l({checkout:{...n.checkout,userCode:null,expiresAt:null}});return}if(n.checkout.userCode)return;setTimeout(()=>{p(e)},2e3)}},m=e=>{a++;let t=e.checkout?.state===`waiting`&&e.checkout.deviceCodeWaiting===!0,r=t&&n.checkout?.state===`waiting`?n.checkout:null,i=r?.userCode??null,o=r?.expiresAt??null;t?p():d++,l({connectionError:null,connectionErrorKind:null,choice:e.choice??null,install:e.install??null,alreadyPro:e.alreadyPro,checkout:e.checkout?{state:e.checkout.state,error:e.checkout.error,userCode:i,expiresAt:o}:null,installer:e.installer?{stage:e.installer.stage,error:e.installer.error}:null,history:e.history&&e.history.observations>0?e.history:null,historyImport:W(e.historyImport)}),C()},h=e=>{o++,l({historyImport:W(e)})},g=e=>{let t=e.setup?.extraction??null,n=e.goals?[...e.goals.areas,...e.goals.asks].map(e=>e.title):[];l({reveal:se(e),extraction:t&&{state:t.state,step:t.step},suggestions:[...new Set(n)].slice(0,4)})};e(n);let _=new EventSource(`/api/work-view/events`),v=(e,n,r=()=>!0)=>{t(e.type,e.data,n,r)};_.addEventListener(`setup-scan`,e=>v(e,u,e=>Array.isArray(e.agents))),_.addEventListener(`setup-state`,e=>v(e,m)),_.addEventListener(`setup-import`,e=>v(e,h)),_.addEventListener(`work-view`,e=>v(e,g,e=>Array.isArray(e.humanRequests)&&Array.isArray(e.agents)&&typeof e.source?.connected==`boolean`));let y=async()=>{let e=i,t=await K(`/api/setup/scan`,q===void 0?{}:{improveProduct:q});!r&&i===e&&u(t)},b=async()=>{let e=await K(`/api/setup/scan/continue`,{});r||u(e)},x=!1,S=!1,C=async()=>{if(!(!x||S||r||n.scan.phase!==`idle`||n.choice&&f(n.installer?.stage,!!n.checkout)||n.install===void 0||n.install&&n.install.status!==`ready`)){S=!0;try{await y()}catch(e){let t=V(e);r||l({scan:{...n.scan,phase:`failed`,error:t.detail,errorKind:t.kind}})}finally{S=!1}}},w=()=>{l({connectionError:null,connectionErrorKind:null}),C()};Z=w,Y=y,X=b;let T=async e=>{let t=o,n=await K(e,{});!r&&o===t&&h(n)};Q=T;let E=i,D=a;return(async()=>{let[e,t]=await Promise.all([G(`/api/setup/scan`),G(`/api/setup/state`)]);if(!r){if(a===D&&m(t),i===E&&u(e),x=!0,E=i,z(t))try{await K(`/api/setup/resume`,{})}catch(e){let t=V(e);r||l({connectionError:t.detail,connectionErrorKind:t.kind})}await C()}})().catch(e=>{if(!r&&(i===E||n.scan.phase===`idle`)){let t=V(e);l({connectionError:t.detail,connectionErrorKind:t.kind,scan:{...n.scan,phase:`failed`,error:t.detail,errorKind:t.kind}})}}).finally(s),()=>{r=!0,Y===y&&(Y=null),X===b&&(X=null),Z===w&&(Z=null),Q===T&&(Q=null),_.close(),s()}},async resume(){await K(`/api/setup/resume`,{retry:!0}),Z?.()},async configureInstall(e){await K(`/api/setup/install`,e),Z?.()},async retryScan(){if(!Y)throw new B(`page`,`The setup page is not connected to the worker. Reload it to try again.`);await Y()},async continueScan(){if(!X)throw new B(`page`,`The setup page is not connected to the worker. Reload it to try again.`);await X()},async setImproveProduct(e){q=e;let t=we,n=Ce.then(async()=>{await t,q===e&&J!==e&&(J=(await K(`/api/setup/scan/preferences`,{improveProduct:e})).improveProduct??e)});Ce=n.catch(()=>{}),await n},async confirmUpload(e,t,n){await K(`/api/setup/scan/consent`,{upload:e,...t?{agents:t}:{},...n===void 0?{}:{improveProduct:n}})},async choose(e,t){await K(`/api/setup/choice`,{...e,...t?{openCheckout:!0}:{}})},async checkout(){await K(`/api/setup/checkout`,{})},async complete(e,t){await K(`/api/setup/complete`,{tools:e,...t?.length?{telemetry:t}:{}})},async startHistoryImport(){await $(`/api/setup/import`)},async stopHistoryImport(){await $(`/api/setup/import/stop`)},async search(e){return ue(await G(de(e)))},async keepNote(e,t){let n=await K(`/api/memory/save`,I(e,t));if(n.success!==!0||typeof n.id!=`number`)throw new B(`refused`,`The note was not saved${typeof n.reason==`string`?`: ${n.reason}`:`.`}`);return n.id},async forgetNote(e){await G(`/api/observation/${e}`,{method:`DELETE`})}},Ee={name:`CMEM Pro`,monthlyCents:3e3,cloudSyncCents:1200};function De(e){return e?.selection?[...e.catalog.agents.filter(t=>e.selection.agents.includes(t.id)).map(e=>({id:e.id,name:e.label,kind:`local`,installed:!0})),...c.filter(e=>e.kind===`cloud`)]:c}export{H as EMPTY_SETUP_DATA,Ee as PLAN,B as SetupRequestError,b as a,f as c,_e as connectionFailureAbove,l as d,re as f,_ as g,C as h,x as i,v as l,Te as localSetupSource,T as m,A as n,y as o,d as p,ce as r,ee as s,xe as setupPending,De as setupToolsForInstall,he as t,V as toSetupFailure,p as u,ge as uploadTooLarge};