@vpxa/aikit 0.1.302 → 0.1.303

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.
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{o as e,t}from"./supersession-DO_ZROFl.js";import{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{dirname as o,isAbsolute as s,relative as c,resolve as l}from"node:path";import{fileURLToPath as u}from"node:url";import{AIKIT_RUNTIME_PATHS as d,EMBEDDING_DEFAULTS as f,computePartitionKey as p,createLogger as m,getPartitionDir as h,migrateLegacyWorkspaceLayout as g,serializeError as _}from"../../core/dist/index.js";const v={workingToEpisodicAccesses:2,episodicToSemanticReferences:3,semanticToProceduralVerifications:5},y={working:1,episodic:2,semantic:4,procedural:12};function b(e,t=v){switch(e.tier){case`working`:if(e.accessCount>=t.workingToEpisodicAccesses)return`episodic`;break;case`episodic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences)return`semantic`;break;case`semantic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences+t.semanticToProceduralVerifications)return`procedural`;break;case`procedural`:break;default:break}}function x(e,t,n){e.memoryMetaUpdateTier(t,n)}const S={stabilityHours:168,accessMultiplier:1.5,flagThreshold:.1,maxStabilityHours:8760};function C(e){return{...S,...e}}function w(e,t){if(!e)return t;let n=Date.parse(e);return Number.isNaN(n)?t:n}function T(e){return e&&e in y?e:`working`}function E(e,t,n,r=S,i){let a=typeof r==`string`?T(r):`working`,o=C(typeof r==`string`?i:r),s=w(e,w(n,Date.now())),c=Math.max(0,Date.now()-s)/(1e3*60*60),l=Math.min(o.stabilityHours*y[a]*o.accessMultiplier**Math.max(0,t),o.maxStabilityHours);return Math.exp(-c/l)}function D(e,t,n){let r=e.memoryMetaGet(t);if(!r)return;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return r.retentionScore!==i&&e.memoryMetaUpdateScore(t,i),e.memoryMetaGet(t)??{...r,retentionScore:i}}function O(e,t,n){e.memoryMetaGet(t)||e.memoryMetaCreate(t),e.memoryMetaTouch(t);let r=e.memoryMetaGet(t);if(!r)return 1;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return e.memoryMetaUpdateScore(t,i),i}function k(e,t){let n=C(t);return e.memoryMetaList().map(t=>D(e,t.entryId,n)??t).filter(e=>e.retentionScore<n.flagThreshold).sort((e,t)=>e.retentionScore-t.retentionScore)}const A=o(u(import.meta.url)),j=m(`server`),M=[`auto`,`manual`,`smart`],N={model:f.model,dimensions:f.dimensions,childProcess:!0,idleTimeoutMs:0};function P(e){return typeof e==`string`&&M.includes(e)}function F(e,t,n){let r=l(e),i=c(l(t),r);if(i.startsWith(`..`)||s(i))throw Error(`Config ${n} path escapes allowed root: ${e} is not under ${t}`);return r}function I(e,t){let n=l(e),r=c(l(t),n);return!(r.startsWith(`..`)||s(r))}function L(e){return h(p(e))}function R(e,t,n,r,i){let a=r?l(t,r):t;if(!n)return F(a,t,i);let o=l(e,n);return I(o,t)?r&&l(o)===l(t)?F(a,t,i):F(o,t,i):F(a,t,i)}function z(e){let t=[e.store?.path,e.curated?.path,e.onboardDir,e.stateDir];for(let e of t)e&&r(e,{recursive:!0})}function B(e,t){g(t);let n=L(t);e.store={...e.store,path:R(t,n,e.store?.path,d.data,`store`)},e.curated={...e.curated,path:R(t,n,e.curated?.path,d.curated,`curated`)},e.onboardDir=R(t,n,e.onboardDir,d.onboard,`onboard`),e.stateDir=R(t,n,e.stateDir,d.state,`state`)}function V(e){let t=process.env.AIKIT_INDEX_MODE;if(P(t))return t;if(e.indexMode)return e.indexMode;let n=process.env.AIKIT_AUTO_INDEX;return n===void 0?e.autoIndex===void 0?`smart`:e.autoIndex?`auto`:`manual`:n===`true`?`auto`:`manual`}function H(){let r=process.env.AIKIT_CONFIG_PATH??(n(l(process.cwd(),`aikit.config.json`))?l(process.cwd(),`aikit.config.json`):l(A,`..`,`..`,`..`,`aikit.config.json`));try{if(!n(r))return j.info(`No config file found, using defaults`,{configPath:r}),W();let a=i(r,`utf-8`),s=JSON.parse(a),c={...N,...s.embedding};if(s.embedding=c,s.memory={retention:{...S,...s.memory?.retention},lessons:{...e,...s.memory?.lessons},consolidation:{...v,...s.memory?.consolidation},supersession:{...t,...s.memory?.supersession}},s.logging?.errorDetails!==void 0&&typeof s.logging.errorDetails!=`boolean`)throw Error(`Config logging.errorDetails must be a boolean`);if(s.logging={errorDetails:s.logging?.errorDetails===!0},!s.sources||!Array.isArray(s.sources)||s.sources.length===0)throw Error(`Config must have at least one source`);if(!s.store?.path)throw Error(`Config must specify store.path`);if(s.autoIndex!==void 0&&typeof s.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(s.indexMode!==void 0&&!P(s.indexMode))throw Error(`Config indexMode must be one of: ${M.join(`, `)}`);if(typeof c.model!=`string`||c.model.trim()===``)throw Error(`Config embedding.model must be a non-empty string`);if(c.nativeDim!==void 0&&(!Number.isInteger(c.nativeDim)||c.nativeDim<=0))throw Error(`Config embedding.nativeDim must be a positive integer`);if(c.dimensions!==void 0&&(!Number.isInteger(c.dimensions)||c.dimensions<=0))throw Error(`Config embedding.dimensions must be a positive integer`);if(c.dimensions!==void 0&&c.nativeDim!==void 0&&c.dimensions>c.nativeDim)throw Error(`Config embedding.dimensions must not exceed embedding.nativeDim`);if(c.queryPrefix!==void 0&&typeof c.queryPrefix!=`string`)throw Error(`Config embedding.queryPrefix must be a string`);let u=o(r);return s.sources=s.sources.map(e=>({...e,path:F(l(u,e.path),u,`source`)})),G(s,r),B(s,u),s.indexMode=V(s),s}catch(e){let t=`Failed to load config from ${r}. ${e instanceof Error?e.message:String(e)}`;console.error(`\n ⚠ CONFIG ERROR — ${t}\n Check that the file exists, is valid JSON, and all required fields are present.\n`),j.error(`Failed to load config`,{configPath:r,..._(e)}),j.warn(`Falling back to default configuration`,{configPath:r});let n=W();return n.configError=t,n}}const U=[`.git/**`,`**/node_modules/**`,`*.lock`,`pnpm-lock.yaml`,`package-lock.json`,`**/dist/**`,`**/build/**`,`**/out/**`,`**/.output/**`,`**/cdk.out/**`,`**/.next/**`,`**/.nuxt/**`,`**/.vercel/**`,`**/.serverless/**`,`**/.turbo/**`,`**/.cache/**`,`**/.parcel-cache/**`,`**/coverage/**`,`**/.terraform/**`,`**/__pycache__/**`,`**/.venv/**`,`**/.docusaurus/**`,`**/.temp/**`,`**/tmp/**`];function W(){let n=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),r=L(n),i={sources:[{path:n,excludePatterns:[...U]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{...N},store:{backend:`sqlite-vec`,path:l(r,d.data)},curated:{path:l(r,d.curated)},memory:{retention:{...S},lessons:{...e},consolidation:{...v},supersession:{...t}},logging:{errorDetails:!1},onboardDir:l(r,d.onboard),stateDir:l(r,d.state)};return i.indexMode=V(i),i}function G(e,t){let n=e.configVersion??0;if(n>=1)return e;if(n<1)for(let t of e.sources){t.excludePatterns=t.excludePatterns??[];let e=new Set(t.excludePatterns);for(let n of U)e.has(n)||t.excludePatterns.push(n)}e.configVersion=1;try{a(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`),j.info(`Config auto-upgraded`,{from:n,to:1,configPath:t})}catch(e){j.warn(`Failed to write upgraded config`,{configPath:t,..._(e)})}return e}function K(e,t){if(!n(t))throw Error(`Workspace root does not exist: ${t}`);g(t),j.debug(`Reconfiguring for workspace root`,{workspaceRoot:t});try{process.chdir(t),j.debug(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){j.warn(`Failed to chdir to workspace root`,{workspaceRoot:t,..._(e)})}e.sources=[{path:t,excludePatterns:e.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],B(e,t),z(e)}export{U as DEFAULT_EXCLUDE_PATTERNS,b as a,v as i,H as loadConfig,D as n,x as o,O as r,K as reconfigureForWorkspace,V as resolveIndexMode,k as t};
@@ -1 +0,0 @@
1
- import{o as e,t}from"./supersession-CWEne3av.js";import{existsSync as n,mkdirSync as r,readFileSync as i,writeFileSync as a}from"node:fs";import{dirname as o,isAbsolute as s,relative as c,resolve as l}from"node:path";import{fileURLToPath as u}from"node:url";import{AIKIT_RUNTIME_PATHS as d,EMBEDDING_DEFAULTS as f,computePartitionKey as p,createLogger as m,getPartitionDir as h,migrateLegacyWorkspaceLayout as g,serializeError as _}from"../../core/dist/index.js";const v={workingToEpisodicAccesses:2,episodicToSemanticReferences:3,semanticToProceduralVerifications:5},y={working:1,episodic:2,semantic:4,procedural:12};function b(e,t=v){switch(e.tier){case`working`:if(e.accessCount>=t.workingToEpisodicAccesses)return`episodic`;break;case`episodic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences)return`semantic`;break;case`semantic`:if(e.accessCount>=t.workingToEpisodicAccesses+t.episodicToSemanticReferences+t.semanticToProceduralVerifications)return`procedural`;break;case`procedural`:break;default:break}}function x(e,t,n){e.memoryMetaUpdateTier(t,n)}const S={stabilityHours:168,accessMultiplier:1.5,flagThreshold:.1,maxStabilityHours:8760};function C(e){return{...S,...e}}function w(e,t){if(!e)return t;let n=Date.parse(e);return Number.isNaN(n)?t:n}function T(e){return e&&e in y?e:`working`}function E(e,t,n,r=S,i){let a=typeof r==`string`?T(r):`working`,o=C(typeof r==`string`?i:r),s=w(e,w(n,Date.now())),c=Math.max(0,Date.now()-s)/(1e3*60*60),l=Math.min(o.stabilityHours*y[a]*o.accessMultiplier**Math.max(0,t),o.maxStabilityHours);return Math.exp(-c/l)}function D(e,t,n){let r=e.memoryMetaGet(t);if(!r)return;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return r.retentionScore!==i&&e.memoryMetaUpdateScore(t,i),e.memoryMetaGet(t)??{...r,retentionScore:i}}function O(e,t,n){e.memoryMetaGet(t)||e.memoryMetaCreate(t),e.memoryMetaTouch(t);let r=e.memoryMetaGet(t);if(!r)return 1;let i=E(r.lastAccessedAt,r.accessCount,r.createdAt,r.tier,n);return e.memoryMetaUpdateScore(t,i),i}function k(e,t){let n=C(t);return e.memoryMetaList().map(t=>D(e,t.entryId,n)??t).filter(e=>e.retentionScore<n.flagThreshold).sort((e,t)=>e.retentionScore-t.retentionScore)}const A=o(u(import.meta.url)),j=m(`server`),M=[`auto`,`manual`,`smart`],N={model:f.model,dimensions:f.dimensions,childProcess:!0,idleTimeoutMs:0};function P(e){return typeof e==`string`&&M.includes(e)}function F(e,t,n){let r=l(e),i=c(l(t),r);if(i.startsWith(`..`)||s(i))throw Error(`Config ${n} path escapes allowed root: ${e} is not under ${t}`);return r}function I(e,t){let n=l(e),r=c(l(t),n);return!(r.startsWith(`..`)||s(r))}function L(e){return h(p(e))}function R(e,t,n,r,i){let a=r?l(t,r):t;if(!n)return F(a,t,i);let o=l(e,n);return I(o,t)?r&&l(o)===l(t)?F(a,t,i):F(o,t,i):F(a,t,i)}function z(e){let t=[e.store?.path,e.curated?.path,e.onboardDir,e.stateDir];for(let e of t)e&&r(e,{recursive:!0})}function B(e,t){g(t);let n=L(t);e.store={...e.store,path:R(t,n,e.store?.path,d.data,`store`)},e.curated={...e.curated,path:R(t,n,e.curated?.path,d.curated,`curated`)},e.onboardDir=R(t,n,e.onboardDir,d.onboard,`onboard`),e.stateDir=R(t,n,e.stateDir,d.state,`state`)}function V(e){let t=process.env.AIKIT_INDEX_MODE;if(P(t))return t;if(e.indexMode)return e.indexMode;let n=process.env.AIKIT_AUTO_INDEX;return n===void 0?e.autoIndex===void 0?`smart`:e.autoIndex?`auto`:`manual`:n===`true`?`auto`:`manual`}function H(){let r=process.env.AIKIT_CONFIG_PATH??(n(l(process.cwd(),`aikit.config.json`))?l(process.cwd(),`aikit.config.json`):l(A,`..`,`..`,`..`,`aikit.config.json`));try{if(!n(r))return j.info(`No config file found, using defaults`,{configPath:r}),W();let a=i(r,`utf-8`),s=JSON.parse(a),c={...N,...s.embedding};if(s.embedding=c,s.memory={retention:{...S,...s.memory?.retention},lessons:{...e,...s.memory?.lessons},consolidation:{...v,...s.memory?.consolidation},supersession:{...t,...s.memory?.supersession}},s.logging?.errorDetails!==void 0&&typeof s.logging.errorDetails!=`boolean`)throw Error(`Config logging.errorDetails must be a boolean`);if(s.logging={errorDetails:s.logging?.errorDetails===!0},!s.sources||!Array.isArray(s.sources)||s.sources.length===0)throw Error(`Config must have at least one source`);if(!s.store?.path)throw Error(`Config must specify store.path`);if(s.autoIndex!==void 0&&typeof s.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(s.indexMode!==void 0&&!P(s.indexMode))throw Error(`Config indexMode must be one of: ${M.join(`, `)}`);if(typeof c.model!=`string`||c.model.trim()===``)throw Error(`Config embedding.model must be a non-empty string`);if(c.nativeDim!==void 0&&(!Number.isInteger(c.nativeDim)||c.nativeDim<=0))throw Error(`Config embedding.nativeDim must be a positive integer`);if(c.dimensions!==void 0&&(!Number.isInteger(c.dimensions)||c.dimensions<=0))throw Error(`Config embedding.dimensions must be a positive integer`);if(c.dimensions!==void 0&&c.nativeDim!==void 0&&c.dimensions>c.nativeDim)throw Error(`Config embedding.dimensions must not exceed embedding.nativeDim`);if(c.queryPrefix!==void 0&&typeof c.queryPrefix!=`string`)throw Error(`Config embedding.queryPrefix must be a string`);let u=o(r);return s.sources=s.sources.map(e=>({...e,path:F(l(u,e.path),u,`source`)})),G(s,r),B(s,u),s.indexMode=V(s),s}catch(e){let t=`Failed to load config from ${r}. ${e instanceof Error?e.message:String(e)}`;console.error(`\n ⚠ CONFIG ERROR — ${t}\n Check that the file exists, is valid JSON, and all required fields are present.\n`),j.error(`Failed to load config`,{configPath:r,..._(e)}),j.warn(`Falling back to default configuration`,{configPath:r});let n=W();return n.configError=t,n}}const U=[`.git/**`,`**/node_modules/**`,`*.lock`,`pnpm-lock.yaml`,`package-lock.json`,`**/dist/**`,`**/build/**`,`**/out/**`,`**/.output/**`,`**/cdk.out/**`,`**/.next/**`,`**/.nuxt/**`,`**/.vercel/**`,`**/.serverless/**`,`**/.turbo/**`,`**/.cache/**`,`**/.parcel-cache/**`,`**/coverage/**`,`**/.terraform/**`,`**/__pycache__/**`,`**/.venv/**`,`**/.docusaurus/**`,`**/.temp/**`,`**/tmp/**`];function W(){let n=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),r=L(n),i={sources:[{path:n,excludePatterns:[...U]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{...N},store:{backend:`sqlite-vec`,path:l(r,d.data)},curated:{path:l(r,d.curated)},memory:{retention:{...S},lessons:{...e},consolidation:{...v},supersession:{...t}},logging:{errorDetails:!1},onboardDir:l(r,d.onboard),stateDir:l(r,d.state)};return i.indexMode=V(i),i}function G(e,t){let n=e.configVersion??0;if(n>=1)return e;if(n<1)for(let t of e.sources){t.excludePatterns=t.excludePatterns??[];let e=new Set(t.excludePatterns);for(let n of U)e.has(n)||t.excludePatterns.push(n)}e.configVersion=1;try{a(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`),j.info(`Config auto-upgraded`,{from:n,to:1,configPath:t})}catch(e){j.warn(`Failed to write upgraded config`,{configPath:t,..._(e)})}return e}function K(e,t){if(!n(t))throw Error(`Workspace root does not exist: ${t}`);g(t),j.debug(`Reconfiguring for workspace root`,{workspaceRoot:t});try{process.chdir(t),j.debug(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){j.warn(`Failed to chdir to workspace root`,{workspaceRoot:t,..._(e)})}e.sources=[{path:t,excludePatterns:e.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],B(e,t),z(e)}export{U as DEFAULT_EXCLUDE_PATTERNS,b as a,v as i,H as loadConfig,D as n,x as o,O as r,K as reconfigureForWorkspace,V as resolveIndexMode,k as t};