@vpxa/aikit 0.1.217 → 0.1.218

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 (26) hide show
  1. package/package.json +1 -1
  2. package/packages/server/dist/bin.js +6 -12
  3. package/packages/server/dist/config-8WXJx-zc.js +2 -0
  4. package/packages/server/dist/config-C35F4tJm.js +1 -0
  5. package/packages/server/dist/{curated-manager-BrtqcmVm.js → curated-manager-CxKwx3Ym.js} +3 -3
  6. package/packages/server/dist/evolution-BX_zTSdj.js +2 -0
  7. package/packages/server/dist/evolution-DWaEE6XW.js +3 -0
  8. package/packages/server/dist/index.js +1 -1
  9. package/packages/server/dist/promotion-CJFYv4Ye.js +3 -0
  10. package/packages/server/dist/promotion-VH4M_cWb.js +2 -0
  11. package/packages/server/dist/rolldown-runtime-yuFVEuWy.js +2 -0
  12. package/packages/server/dist/{server-CBbp-_E9.js → server-C8qwMhwZ.js} +166 -162
  13. package/packages/server/dist/{server-jy-ICjJR.js → server-CjQNW8xO.js} +166 -162
  14. package/packages/server/dist/{lessons-D7sdHa2e.js → supersession-CWEne3av.js} +1 -1
  15. package/packages/server/dist/{lessons-B05P_TOl.js → supersession-DO_ZROFl.js} +1 -1
  16. package/packages/server/dist/{version-check-D_uN0n0Y.js → version-check-BgHzxxCW.js} +1 -1
  17. package/scaffold/dist/definitions/protocols.mjs +4 -0
  18. package/scaffold/dist/definitions/skills/aikit.mjs +15 -5
  19. package/packages/server/dist/config-C4mVyqAF.js +0 -2
  20. package/packages/server/dist/config-jGZ91cRx.js +0 -1
  21. package/packages/server/dist/evolution-9hXRopDC.js +0 -3
  22. package/packages/server/dist/evolution-DJhTM6nu.js +0 -2
  23. package/packages/server/dist/promotion-Bd_YB7E1.js +0 -3
  24. package/packages/server/dist/promotion-BppF9YlR.js +0 -2
  25. package/packages/server/dist/replay-interceptor-CGLyom5f.js +0 -7
  26. package/packages/server/dist/supersession-9edUDEQ8.js +0 -1
@@ -1,2 +1,2 @@
1
1
  const e={confirmIncrement:10,contradictDecrement:20,weeklyDecay:2,implicitUseIncrement:3,staleThreshold:30,staleDays:21,decayFloor:10,autoArchiveDays:30,archiveThreshold:20},t=`lesson:auto-archive`;function n(t){return{confirmIncrement:Math.max(0,Math.trunc(t?.confirmIncrement??e.confirmIncrement)),contradictDecrement:Math.max(0,Math.trunc(t?.contradictDecrement??e.contradictDecrement)),weeklyDecay:Math.max(0,Math.trunc(t?.weeklyDecay??e.weeklyDecay)),implicitUseIncrement:Math.max(0,Math.trunc(t?.implicitUseIncrement??e.implicitUseIncrement)),staleThreshold:Math.min(100,Math.max(0,Math.trunc(t?.staleThreshold??e.staleThreshold))),staleDays:Math.max(1,Math.trunc(t?.staleDays??e.staleDays)),decayFloor:Math.min(100,Math.max(0,Math.trunc(t?.decayFloor??e.decayFloor))),autoArchiveDays:Math.max(1,Math.trunc(t?.autoArchiveDays??e.autoArchiveDays)),archiveThreshold:Math.min(100,Math.max(0,Math.trunc(t?.archiveThreshold??e.archiveThreshold)))}}function r(e){return[`## Lesson: ${e.title}`,``,`**Confidence:** ${e.confidence}/100`,``,`### Context`,e.context,``,`### Insight`,e.insight,``,`### Evidence`,e.evidence].join(`
2
- `)}function i(e){let t=e.match(/^## Lesson:\s+(.+)$/m),n=e.match(/\*\*Confidence:\*\*\s+(\d+)\/100/),r=e.match(/### Context\r?\n([\s\S]*?)(?=\r?\n### |$)/),i=e.match(/### Insight\r?\n([\s\S]*?)(?=\r?\n### |$)/),a=e.match(/### Evidence\r?\n([\s\S]*?)(?=\r?\n### |$)/);return{title:t?.[1]?.trim(),confidence:n?Number(n[1]):void 0,context:r?.[1]?.trim(),insight:i?.[1]?.trim(),evidence:a?.[1]?.trim()}}function a(e,t){let n=Math.min(100,Math.max(0,Math.trunc(t)));return/\*\*Confidence:\*\*/.test(e)?e.replace(/\*\*Confidence:\*\*\s+\d+\/100/,`**Confidence:** ${n}/100`):e.match(/^(## Lesson:[^\r\n]*)(\r?\n)/)?e.replace(/^(## Lesson:[^\r\n]*)(\r?\n)/,`$1$2$2**Confidence:** ${n}/100$2$2`):`**Confidence:** ${n}/100\n\n${e}`}function o(t,r,i=e){let a=n(i);return r===`confirm`?Math.min(100,t+a.confirmIncrement):Math.max(0,t-a.contradictDecrement)}function s(t,r,i,a=e,o=Date.now()){let s=n(a),c=!!r,l=r?new Date(r):new Date(i),u=Math.max(0,o-l.getTime());c||(u=Math.min(u,336*60*60*1e3));let d=u/(10080*60*1e3),f=Math.floor(d)*s.weeklyDecay;return Math.max(s.decayFloor,t-f)}function c(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.staleThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.staleDays}function l(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.archiveThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.autoArchiveDays}export{r as a,n as c,s as i,a as l,t as n,c as o,o as r,i as s,e as t,l as u};
2
+ `)}function i(e){let t=e.match(/^## Lesson:\s+(.+)$/m),n=e.match(/\*\*Confidence:\*\*\s+(\d+)\/100/),r=e.match(/### Context\r?\n([\s\S]*?)(?=\r?\n### |$)/),i=e.match(/### Insight\r?\n([\s\S]*?)(?=\r?\n### |$)/),a=e.match(/### Evidence\r?\n([\s\S]*?)(?=\r?\n### |$)/);return{title:t?.[1]?.trim(),confidence:n?Number(n[1]):void 0,context:r?.[1]?.trim(),insight:i?.[1]?.trim(),evidence:a?.[1]?.trim()}}function a(e,t){let n=Math.min(100,Math.max(0,Math.trunc(t)));return/\*\*Confidence:\*\*/.test(e)?e.replace(/\*\*Confidence:\*\*\s+\d+\/100/,`**Confidence:** ${n}/100`):e.match(/^(## Lesson:[^\r\n]*)(\r?\n)/)?e.replace(/^(## Lesson:[^\r\n]*)(\r?\n)/,`$1$2$2**Confidence:** ${n}/100$2$2`):`**Confidence:** ${n}/100\n\n${e}`}function o(t,r,i=e){let a=n(i);return r===`confirm`?Math.min(100,t+a.confirmIncrement):Math.max(0,t-a.contradictDecrement)}function s(t,r,i,a=e,o=Date.now()){let s=n(a),c=!!r,l=r?new Date(r):new Date(i),u=Math.max(0,o-l.getTime());c||(u=Math.min(u,336*60*60*1e3));let d=u/(10080*60*1e3),f=Math.floor(d)*s.weeklyDecay;return Math.max(s.decayFloor,t-f)}function c(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.staleThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.staleDays}function l(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.archiveThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.autoArchiveDays}const u={threshold:.7,maxCompare:50,autoThreshold:.95};function d(e){let t=Math.min(1,Math.max(0,e?.threshold??u.threshold)),n=Math.min(1,Math.max(t,e?.autoThreshold??u.autoThreshold));return{threshold:t,maxCompare:Math.max(1,Math.trunc(e?.maxCompare??u.maxCompare)),autoThreshold:n}}function f(e){let t=e.toLowerCase().match(/[a-z0-9]{2,}/g)??[];return new Set(t)}function p(e,t){let n=f(e),r=f(t);if(n.size===0&&r.size===0)return 1;if(n.size===0||r.size===0)return 0;let i=new Set([...n].filter(e=>r.has(e))),a=new Set([...n,...r]);return i.size/a.size}function m(e,t,n=u){let r=d(n);return t.slice(0,r.maxCompare).map(t=>({entryId:t.id,title:t.title,similarity:p(e,t.content),path:t.path})).filter(e=>e.similarity>=r.threshold).sort((e,t)=>t.similarity-e.similarity)}function h(e,t,n){e.memoryMetaCreate(t),e.memoryMetaSetSuperseded(t,n)}export{d as a,o as c,c as d,i as f,l as h,h as i,s as l,a as m,m as n,e as o,n as p,p as r,t as s,u as t,r as u};
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  const e={confirmIncrement:10,contradictDecrement:20,weeklyDecay:2,implicitUseIncrement:3,staleThreshold:30,staleDays:21,decayFloor:10,autoArchiveDays:30,archiveThreshold:20},t=`lesson:auto-archive`;function n(t){return{confirmIncrement:Math.max(0,Math.trunc(t?.confirmIncrement??e.confirmIncrement)),contradictDecrement:Math.max(0,Math.trunc(t?.contradictDecrement??e.contradictDecrement)),weeklyDecay:Math.max(0,Math.trunc(t?.weeklyDecay??e.weeklyDecay)),implicitUseIncrement:Math.max(0,Math.trunc(t?.implicitUseIncrement??e.implicitUseIncrement)),staleThreshold:Math.min(100,Math.max(0,Math.trunc(t?.staleThreshold??e.staleThreshold))),staleDays:Math.max(1,Math.trunc(t?.staleDays??e.staleDays)),decayFloor:Math.min(100,Math.max(0,Math.trunc(t?.decayFloor??e.decayFloor))),autoArchiveDays:Math.max(1,Math.trunc(t?.autoArchiveDays??e.autoArchiveDays)),archiveThreshold:Math.min(100,Math.max(0,Math.trunc(t?.archiveThreshold??e.archiveThreshold)))}}function r(e){return[`## Lesson: ${e.title}`,``,`**Confidence:** ${e.confidence}/100`,``,`### Context`,e.context,``,`### Insight`,e.insight,``,`### Evidence`,e.evidence].join(`
3
- `)}function i(e){let t=e.match(/^## Lesson:\s+(.+)$/m),n=e.match(/\*\*Confidence:\*\*\s+(\d+)\/100/),r=e.match(/### Context\r?\n([\s\S]*?)(?=\r?\n### |$)/),i=e.match(/### Insight\r?\n([\s\S]*?)(?=\r?\n### |$)/),a=e.match(/### Evidence\r?\n([\s\S]*?)(?=\r?\n### |$)/);return{title:t?.[1]?.trim(),confidence:n?Number(n[1]):void 0,context:r?.[1]?.trim(),insight:i?.[1]?.trim(),evidence:a?.[1]?.trim()}}function a(e,t){let n=Math.min(100,Math.max(0,Math.trunc(t)));return/\*\*Confidence:\*\*/.test(e)?e.replace(/\*\*Confidence:\*\*\s+\d+\/100/,`**Confidence:** ${n}/100`):e.match(/^(## Lesson:[^\r\n]*)(\r?\n)/)?e.replace(/^(## Lesson:[^\r\n]*)(\r?\n)/,`$1$2$2**Confidence:** ${n}/100$2$2`):`**Confidence:** ${n}/100\n\n${e}`}function o(t,r,i=e){let a=n(i);return r===`confirm`?Math.min(100,t+a.confirmIncrement):Math.max(0,t-a.contradictDecrement)}function s(t,r,i,a=e,o=Date.now()){let s=n(a),c=!!r,l=r?new Date(r):new Date(i),u=Math.max(0,o-l.getTime());c||(u=Math.min(u,336*60*60*1e3));let d=u/(10080*60*1e3),f=Math.floor(d)*s.weeklyDecay;return Math.max(s.decayFloor,t-f)}function c(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.staleThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.staleDays}function l(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.archiveThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.autoArchiveDays}export{r as a,n as c,s as i,a as l,t as n,c as o,o as r,i as s,e as t,l as u};
3
+ `)}function i(e){let t=e.match(/^## Lesson:\s+(.+)$/m),n=e.match(/\*\*Confidence:\*\*\s+(\d+)\/100/),r=e.match(/### Context\r?\n([\s\S]*?)(?=\r?\n### |$)/),i=e.match(/### Insight\r?\n([\s\S]*?)(?=\r?\n### |$)/),a=e.match(/### Evidence\r?\n([\s\S]*?)(?=\r?\n### |$)/);return{title:t?.[1]?.trim(),confidence:n?Number(n[1]):void 0,context:r?.[1]?.trim(),insight:i?.[1]?.trim(),evidence:a?.[1]?.trim()}}function a(e,t){let n=Math.min(100,Math.max(0,Math.trunc(t)));return/\*\*Confidence:\*\*/.test(e)?e.replace(/\*\*Confidence:\*\*\s+\d+\/100/,`**Confidence:** ${n}/100`):e.match(/^(## Lesson:[^\r\n]*)(\r?\n)/)?e.replace(/^(## Lesson:[^\r\n]*)(\r?\n)/,`$1$2$2**Confidence:** ${n}/100$2$2`):`**Confidence:** ${n}/100\n\n${e}`}function o(t,r,i=e){let a=n(i);return r===`confirm`?Math.min(100,t+a.confirmIncrement):Math.max(0,t-a.contradictDecrement)}function s(t,r,i,a=e,o=Date.now()){let s=n(a),c=!!r,l=r?new Date(r):new Date(i),u=Math.max(0,o-l.getTime());c||(u=Math.min(u,336*60*60*1e3));let d=u/(10080*60*1e3),f=Math.floor(d)*s.weeklyDecay;return Math.max(s.decayFloor,t-f)}function c(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.staleThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.staleDays}function l(t,r=e,i=Date.now()){let a=n(r);if(s(t.confidence,t.lastAccessedAt,t.createdAt,r,i)>=a.archiveThreshold)return!1;let o=t.lastAccessedAt?new Date(t.lastAccessedAt):new Date(t.createdAt);return Math.max(0,i-o.getTime())/(1e3*60*60*24)>=a.autoArchiveDays}const u={threshold:.7,maxCompare:50,autoThreshold:.95};function d(e){let t=Math.min(1,Math.max(0,e?.threshold??u.threshold)),n=Math.min(1,Math.max(t,e?.autoThreshold??u.autoThreshold));return{threshold:t,maxCompare:Math.max(1,Math.trunc(e?.maxCompare??u.maxCompare)),autoThreshold:n}}function f(e){let t=e.toLowerCase().match(/[a-z0-9]{2,}/g)??[];return new Set(t)}function p(e,t){let n=f(e),r=f(t);if(n.size===0&&r.size===0)return 1;if(n.size===0||r.size===0)return 0;let i=new Set([...n].filter(e=>r.has(e))),a=new Set([...n,...r]);return i.size/a.size}function m(e,t,n=u){let r=d(n);return t.slice(0,r.maxCompare).map(t=>({entryId:t.id,title:t.title,similarity:p(e,t.content),path:t.path})).filter(e=>e.similarity>=r.threshold).sort((e,t)=>t.similarity-e.similarity)}function h(e,t,n){e.memoryMetaCreate(t),e.memoryMetaSetSuperseded(t,n)}export{d as a,o as c,c as d,i as f,l as h,h as i,s as l,a as m,m as n,e as o,n as p,p as r,t as s,u as t,r as u};
@@ -1 +1 @@
1
- import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{createLogger as a}from"../../core/dist/index.js";import{homedir as o}from"node:os";import{execFile as s}from"node:child_process";const c=a(`server`);function l(){let e=r(n(i(import.meta.url)),`..`,`..`,`..`,`package.json`);try{return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}}function u(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t>0?1:-1}return 0}function d(){let e=l();fetch(`https://registry.npmjs.org/@vpxa/aikit/latest`,{signal:AbortSignal.timeout(5e3)}).then(e=>{if(e.ok)return e.json()}).then(t=>{if(!t||typeof t!=`object`)return;let n=t.version;n&&u(e,n)<0&&c.warn(`Update available`,{currentVersion:e,latestVersion:n,updateCommand:`aikit upgrade`})}).catch(()=>{})}function f(){try{let n=r(o(),`.copilot`,`.aikit-scaffold.json`);return e(n)?JSON.parse(t(n,`utf-8`)).version??null:null}catch{return null}}function p(){try{let n=r(process.cwd(),`.github`,`.aikit-scaffold.json`);return e(n)?JSON.parse(t(n,`utf-8`)).version??null:null}catch{return null}}let m=`idle`,h=null;function g(){return{state:m,error:h}}function _(){try{let t=l(),a=f(),o=p();if(!(a!=null&&a!==t)&&!(o!=null&&o!==t)||m===`pending`||m===`success`)return;m=`pending`,h=null,c.info(`Scaffold version mismatch — auto-upgrading`,{serverVersion:t,userScaffoldVersion:a,workspaceScaffoldVersion:o});let u=n(i(import.meta.url)),d=[r(u,`..`,`..`,`..`,`bin`,`aikit.mjs`),r(u,`..`,`bin`,`aikit.mjs`),...process.argv[1]?[r(n(process.argv[1]),`aikit.mjs`)]:[]],g=d.find(t=>e(t));if(!g){m=`failed`,h=`aikit CLI binary not found. Tried: ${d.join(`, `)}`,c.warn(`Cannot auto-upgrade: aikit CLI binary not found`,{candidates:d,platform:process.platform});return}s(process.execPath,[g,`upgrade`],{timeout:3e4,windowsHide:!0},(e,t,n)=>{e?(m=`failed`,h=e.message,c.warn(`Auto-upgrade failed`,{error:e.message,stderr:n?.slice(0,500),binPath:g,platform:process.platform})):(m=`success`,h=null,c.info(`Auto-upgrade complete`))}).unref()}catch(e){m=`failed`,h=e instanceof Error?e.message:String(e),c.warn(`Auto-upgrade check failed`,{error:h})}}export{_ as autoUpgradeScaffold,d as checkForUpdates,l as getCurrentVersion,g as getUpgradeState};
1
+ import{existsSync as e,readFileSync as t}from"node:fs";import{dirname as n,resolve as r}from"node:path";import{fileURLToPath as i}from"node:url";import{createLogger as a}from"../../core/dist/index.js";import{execFile as o}from"node:child_process";import{homedir as s}from"node:os";const c=a(`server`);function l(){let e=r(n(i(import.meta.url)),`..`,`..`,`..`,`package.json`);try{return JSON.parse(t(e,`utf-8`)).version??`0.0.0`}catch{return`0.0.0`}}function u(e,t){let n=e.split(`.`).map(Number),r=t.split(`.`).map(Number);for(let e=0;e<3;e++){let t=(n[e]??0)-(r[e]??0);if(t!==0)return t>0?1:-1}return 0}function d(){let e=l();fetch(`https://registry.npmjs.org/@vpxa/aikit/latest`,{signal:AbortSignal.timeout(5e3)}).then(e=>{if(e.ok)return e.json()}).then(t=>{if(!t||typeof t!=`object`)return;let n=t.version;n&&u(e,n)<0&&c.warn(`Update available`,{currentVersion:e,latestVersion:n,updateCommand:`aikit upgrade`})}).catch(()=>{})}function f(){try{let n=r(s(),`.copilot`,`.aikit-scaffold.json`);return e(n)?JSON.parse(t(n,`utf-8`)).version??null:null}catch{return null}}function p(){try{let n=r(process.cwd(),`.github`,`.aikit-scaffold.json`);return e(n)?JSON.parse(t(n,`utf-8`)).version??null:null}catch{return null}}let m=`idle`,h=null;function g(){return{state:m,error:h}}function _(){try{let t=l(),a=f(),s=p();if(!(a!=null&&a!==t)&&!(s!=null&&s!==t)||m===`pending`||m===`success`)return;m=`pending`,h=null,c.info(`Scaffold version mismatch — auto-upgrading`,{serverVersion:t,userScaffoldVersion:a,workspaceScaffoldVersion:s});let u=n(i(import.meta.url)),d=[r(u,`..`,`..`,`..`,`bin`,`aikit.mjs`),r(u,`..`,`bin`,`aikit.mjs`),...process.argv[1]?[r(n(process.argv[1]),`aikit.mjs`)]:[]],g=d.find(t=>e(t));if(!g){m=`failed`,h=`aikit CLI binary not found. Tried: ${d.join(`, `)}`,c.warn(`Cannot auto-upgrade: aikit CLI binary not found`,{candidates:d,platform:process.platform});return}o(process.execPath,[g,`upgrade`],{timeout:3e4,windowsHide:!0},(e,t,n)=>{e?(m=`failed`,h=e.message,c.warn(`Auto-upgrade failed`,{error:e.message,stderr:n?.slice(0,500),binPath:g,platform:process.platform})):(m=`success`,h=null,c.info(`Auto-upgrade complete`))}).unref()}catch(e){m=`failed`,h=e instanceof Error?e.message:String(e),c.warn(`Auto-upgrade check failed`,{error:h})}}export{_ as autoUpgradeScaffold,d as checkForUpdates,l as getCurrentVersion,g as getUpgradeState};
@@ -176,6 +176,10 @@ knowledge({ action: "withdraw", scope: "flow", profile: "<your-role>", budget: 6
176
176
 
177
177
  Use targeted searches before expensive work:
178
178
 
179
+ **Passive recall:** Most tools accept \`enrich: true\` — this automatically appends previously captured facts relevant to your query. Use it on analysis tools (\`search\`, \`symbol\`, \`trace\`, \`graph\`, \`file_summary\`, \`compact\`, \`scope_map\`, \`blast_radius\`).
180
+
181
+ **Active recall (for specific needs):**
182
+
179
183
  | Your Role | Before doing... | Search for auto-knowledge first |
180
184
  |-----------|-----------------|--------------------------------|
181
185
  | Debugger | Retrying failed tool | \`search({ query: "<tool-name> error", content_type: "curated-knowledge", limit: 3 })\` |
@@ -142,12 +142,22 @@ Use this instead of baking a static catalog into the skill. Tool metadata is liv
142
142
 
143
143
  ## Memory Lifecycle
144
144
 
145
- AI Kit auto-manages memory behind the scenes. Know what happens so you can leverage it.
145
+ AI Kit auto-captures knowledge from tool outputs. Know what it captures so you can leverage it.
146
146
 
147
- ### Auto-Observations
148
- Tool outputs from \`check\`, \`test_run\`, \`search\`, \`trace\` are auto-captured as observations.
149
- Query them: \`search({ query: "error pattern", tags: ["observation"] })\`
150
- They surface patterns you may have missed — especially useful in debugging sessions.
147
+ ### Auto-Knowledge Capture
148
+
149
+ Every tool call passes through extractors that capture reusable facts:
150
+
151
+ | Extractor | Tools Covered | What It Captures |
152
+ |-----------|--------------|-----------------|
153
+ | **Content reads** | \`compact\`, \`file_summary\`, \`digest\`, \`lookup\`, \`stratum_card\` | File structure, exports, compressed sections |
154
+ | **Symbol analysis** | \`symbol\`, \`trace\`, \`graph\` (read-only) | Definitions, references, call chains, module relationships |
155
+ | **Research results** | \`web_search\`, \`web_fetch\`, \`search\`, \`find\` | Search findings, web content, code discoveries |
156
+ | **Behavioral patterns** | ALL tools (ring buffer) | Tool preferences, search→edit sequences, error-fix cycles |
157
+
158
+ **Retrieval:** Use \`enrich: true\` on any tool that supports it — the server automatically surfaces previously captured facts relevant to your query. Or search directly: \`search({ query: "...", origin: "curated" })\`
159
+
160
+ **Best practice:** Before re-reading a file you've already explored, try \`search({ query: "file-path-or-topic" })\` — auto-knowledge may already have what you need.
151
161
 
152
162
  ### Retention & Tier Promotion
153
163
  - Memories start at **working** tier → promote on repeated access: episodic (2) → semantic (5) → procedural (10)
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{c as e}from"./bin.js";import{a as t,t as n}from"./retention-C3tsarCT.js";import{t as r}from"./lessons-B05P_TOl.js";import{existsSync as i,readFileSync as a,writeFileSync as o}from"node:fs";import{dirname as s,resolve as c}from"node:path";import{fileURLToPath as l}from"node:url";import{AIKIT_PATHS as u,EMBEDDING_DEFAULTS as d,createLogger as f,getPartitionDir as p,isUserInstalled as m,registerWorkspace as h,serializeError as g}from"../../core/dist/index.js";const _=s(l(import.meta.url)),v=f(`server`),y=[`auto`,`manual`,`smart`],b={model:d.model,dimensions:d.dimensions,childProcess:!0,idleTimeoutMs:6e4};function x(e){return typeof e==`string`&&y.includes(e)}function S(e,t,n){let r=c(e),i=c(t);if(!r.startsWith(i))throw Error(`Config ${n} path escapes workspace root: ${e} is not under ${t}`);return r}function C(e){let t=process.env.AIKIT_INDEX_MODE;if(x(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 w(){let o=process.env.AIKIT_CONFIG_PATH??(i(c(process.cwd(),`aikit.config.json`))?c(process.cwd(),`aikit.config.json`):c(_,`..`,`..`,`..`,`aikit.config.json`));try{if(!i(o))return v.info(`No config file found, using defaults`,{configPath:o}),E();let l=a(o,`utf-8`),d=JSON.parse(l);if(d.embedding={...b,...d.embedding},d.memory={retention:{...n,...d.memory?.retention},lessons:{...r,...d.memory?.lessons},consolidation:{...t,...d.memory?.consolidation},supersession:{...e,...d.memory?.supersession}},!d.sources||!Array.isArray(d.sources)||d.sources.length===0)throw Error(`Config must have at least one source`);if(!d.store?.path)throw Error(`Config must specify store.path`);if(d.autoIndex!==void 0&&typeof d.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(d.indexMode!==void 0&&!x(d.indexMode))throw Error(`Config indexMode must be one of: ${y.join(`, `)}`);let f=s(o);return d.sources=d.sources.map(e=>({...e,path:S(c(f,e.path),f,`source`)})),d.store.path=S(c(f,d.store.path),f,`store`),d.curated=d.curated??{path:u.aiCurated},d.curated.path=S(c(f,d.curated.path),f,`curated`),O(d,f),D(d,o),d.indexMode=C(d),d}catch(e){return v.error(`Failed to load config`,{configPath:o,...g(e)}),v.warn(`Falling back to default configuration`,{configPath:o}),E()}}const T=[`.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 E(){let i=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),a={sources:[{path:i,excludePatterns:[...T]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{...b},store:{backend:`sqlite-vec`,path:c(i,u.data)},curated:{path:c(i,u.aiCurated)},memory:{retention:{...n},lessons:{...r},consolidation:{...t},supersession:{...e}},onboardDir:c(i,u.aiContext),stateDir:c(i,u.state)};return O(a,i),a.indexMode=C(a),a}function D(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 T)e.has(n)||t.excludePatterns.push(n)}e.configVersion=1;try{o(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`),v.info(`Config auto-upgraded`,{from:n,to:1,configPath:t})}catch(e){v.warn(`Failed to write upgraded config`,{configPath:t,...g(e)})}return e}function O(e,t){if(!m())return;let n=h(t);e.store.path=c(p(n.partition)),e.onboardDir=c(p(n.partition),`onboard`),e.stateDir=c(p(n.partition),`state`),e.curated={path:c(p(n.partition),`curated`)}}function k(e,t){if(!i(t))throw Error(`Workspace root does not exist: ${t}`);v.info(`Reconfiguring for workspace root`,{workspaceRoot:t});try{process.chdir(t),v.info(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){v.warn(`Failed to chdir to workspace root`,{workspaceRoot:t,...g(e)})}e.sources=[{path:t,excludePatterns:e.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],e.store.path=c(t,u.data),e.curated={path:c(t,u.aiCurated)},e.onboardDir=c(t,u.aiContext),e.stateDir=c(t,u.state),O(e,t)}export{T as DEFAULT_EXCLUDE_PATTERNS,w as loadConfig,k as reconfigureForWorkspace,C as resolveIndexMode};
@@ -1 +0,0 @@
1
- import{t as e}from"./supersession-9edUDEQ8.js";import{a as t,t as n}from"./retention-B4ITAs7F.js";import{t as r}from"./lessons-D7sdHa2e.js";import{existsSync as i,readFileSync as a,writeFileSync as o}from"node:fs";import{dirname as s,resolve as c}from"node:path";import{fileURLToPath as l}from"node:url";import{AIKIT_PATHS as u,EMBEDDING_DEFAULTS as d,createLogger as f,getPartitionDir as p,isUserInstalled as m,registerWorkspace as h,serializeError as g}from"../../core/dist/index.js";const _=s(l(import.meta.url)),v=f(`server`),y=[`auto`,`manual`,`smart`],b={model:d.model,dimensions:d.dimensions,childProcess:!0,idleTimeoutMs:6e4};function x(e){return typeof e==`string`&&y.includes(e)}function S(e,t,n){let r=c(e),i=c(t);if(!r.startsWith(i))throw Error(`Config ${n} path escapes workspace root: ${e} is not under ${t}`);return r}function C(e){let t=process.env.AIKIT_INDEX_MODE;if(x(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 w(){let o=process.env.AIKIT_CONFIG_PATH??(i(c(process.cwd(),`aikit.config.json`))?c(process.cwd(),`aikit.config.json`):c(_,`..`,`..`,`..`,`aikit.config.json`));try{if(!i(o))return v.info(`No config file found, using defaults`,{configPath:o}),E();let l=a(o,`utf-8`),d=JSON.parse(l);if(d.embedding={...b,...d.embedding},d.memory={retention:{...n,...d.memory?.retention},lessons:{...r,...d.memory?.lessons},consolidation:{...t,...d.memory?.consolidation},supersession:{...e,...d.memory?.supersession}},!d.sources||!Array.isArray(d.sources)||d.sources.length===0)throw Error(`Config must have at least one source`);if(!d.store?.path)throw Error(`Config must specify store.path`);if(d.autoIndex!==void 0&&typeof d.autoIndex!=`boolean`)throw Error(`Config autoIndex must be a boolean`);if(d.indexMode!==void 0&&!x(d.indexMode))throw Error(`Config indexMode must be one of: ${y.join(`, `)}`);let f=s(o);return d.sources=d.sources.map(e=>({...e,path:S(c(f,e.path),f,`source`)})),d.store.path=S(c(f,d.store.path),f,`store`),d.curated=d.curated??{path:u.aiCurated},d.curated.path=S(c(f,d.curated.path),f,`curated`),O(d,f),D(d,o),d.indexMode=C(d),d}catch(e){return v.error(`Failed to load config`,{configPath:o,...g(e)}),v.warn(`Falling back to default configuration`,{configPath:o}),E()}}const T=[`.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 E(){let i=process.env.AIKIT_WORKSPACE_ROOT??process.cwd(),a={sources:[{path:i,excludePatterns:[...T]}],serverName:`aikit`,indexing:{chunkSize:1500,chunkOverlap:200,minChunkSize:100},embedding:{...b},store:{backend:`sqlite-vec`,path:c(i,u.data)},curated:{path:c(i,u.aiCurated)},memory:{retention:{...n},lessons:{...r},consolidation:{...t},supersession:{...e}},onboardDir:c(i,u.aiContext),stateDir:c(i,u.state)};return O(a,i),a.indexMode=C(a),a}function D(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 T)e.has(n)||t.excludePatterns.push(n)}e.configVersion=1;try{o(t,`${JSON.stringify(e,null,2)}\n`,`utf-8`),v.info(`Config auto-upgraded`,{from:n,to:1,configPath:t})}catch(e){v.warn(`Failed to write upgraded config`,{configPath:t,...g(e)})}return e}function O(e,t){if(!m())return;let n=h(t);e.store.path=c(p(n.partition)),e.onboardDir=c(p(n.partition),`onboard`),e.stateDir=c(p(n.partition),`state`),e.curated={path:c(p(n.partition),`curated`)}}function k(e,t){if(!i(t))throw Error(`Workspace root does not exist: ${t}`);v.info(`Reconfiguring for workspace root`,{workspaceRoot:t});try{process.chdir(t),v.info(`Changed process cwd to workspace root`,{cwd:process.cwd()})}catch(e){v.warn(`Failed to chdir to workspace root`,{workspaceRoot:t,...g(e)})}e.sources=[{path:t,excludePatterns:e.sources[0]?.excludePatterns??[`node_modules/**`,`dist/**`,`.git/**`,`coverage/**`,`*.lock`,`pnpm-lock.yaml`]}],e.store.path=c(t,u.data),e.curated={path:c(t,u.aiCurated)},e.onboardDir=c(t,u.aiContext),e.stateDir=c(t,u.state),O(e,t)}export{T as DEFAULT_EXCLUDE_PATTERNS,w as loadConfig,k as reconfigureForWorkspace,C as resolveIndexMode};
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import{m as e,u as t}from"./bin.js";import{c as n,i as r,t as i}from"./lessons-B05P_TOl.js";import{join as a}from"node:path";import{readFile as o,writeFile as s}from"node:fs/promises";var c=e({DEFAULT_GROUP_CONFIG:()=>u,DEFAULT_PRUNE_CONFIG:()=>l,groupLessons:()=>w,pruneLessons:()=>C});const l={maxConfidence:15,minIdleDays:30,safetyDays:7,maxPrune:20,dryRun:!0},u={similarityThreshold:.7,minGroupSize:2,maxGroups:10,dryRun:!0},d=new Set([`the`,`a`,`to`,`for`,`in`,`of`,`and`,`is`,`use`]);function f(e){return{maxConfidence:Math.min(100,Math.max(0,Math.trunc(e?.maxConfidence??l.maxConfidence))),minIdleDays:Math.max(1,Math.trunc(e?.minIdleDays??l.minIdleDays)),safetyDays:Math.max(0,Math.trunc(e?.safetyDays??l.safetyDays)),maxPrune:Math.max(1,Math.trunc(e?.maxPrune??l.maxPrune)),dryRun:e?.dryRun??l.dryRun}}function p(e){return{similarityThreshold:Math.min(1,Math.max(0,e?.similarityThreshold??u.similarityThreshold)),minGroupSize:Math.max(2,Math.trunc(e?.minGroupSize??u.minGroupSize)),maxGroups:Math.max(1,Math.trunc(e?.maxGroups??u.maxGroups)),dryRun:e?.dryRun??u.dryRun}}function m(e){if(!e)return 0;let t=Date.parse(e);return Number.isNaN(t)?0:t}function h(e,t){let n=Math.max(m(e),m(t));return n===0?1/0:Math.max(0,Date.now()-n)/864e5}function g(e){return e.toLowerCase().match(/[a-z0-9]{2,}/g)??[]}function _(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,60)}function v(e,t){return`${[`---`,`title: "${e.title.replace(/"/g,`\\"`)}"`,`category: ${e.category}`,`tags: [${e.tags.map(e=>`"${e}"`).join(`, `)}]`,`created: ${e.created}`,`updated: ${e.updated}`,`version: ${e.version}`,`origin: ${e.origin}`,`changelog:`,...e.changelog.map(e=>` - version: ${e.version}\n date: ${e.date}\n reason: "${e.reason.replace(/"/g,`\\"`)}"`),`---`].join(`
3
- `)}\n\n${t}\n`}function y(e,n){let r=e.map(()=>[]);for(let i=0;i<e.length;i+=1)for(let a=i+1;a<e.length;a+=1)t(e[i],e[a])>=n&&(r[i].push(a),r[a].push(i));return r}function b(e){let t=new Set,n=[];for(let r=0;r<e.length;r+=1){if(t.has(r))continue;let i=[r],a=[];for(t.add(r);i.length>0;){let n=i.pop();if(n!==void 0){a.push(n);for(let r of e[n])t.has(r)||(t.add(r),i.push(r))}}n.push(a)}return n}function x(e){let t=new Map,n=new Map,r=0;for(let i of e)for(let e of g(i))d.has(e)||(t.set(e,(t.get(e)??0)+1),n.has(e)||(n.set(e,r),r+=1));let i=[...t.entries()].sort((e,t)=>t[1]-e[1]||(n.get(e[0])??0)-(n.get(t[0])??0))[0];return i&&i[1]>1?_(i[0]):_(e.flatMap(e=>g(e)).find(e=>!d.has(e))??`lesson-group`)}async function S(e,t,n){let r=a(e.curatedDir,t),i=await o(r,`utf8`),{frontmatter:c,content:l}=e.parseFile(i),u=`group:${n}`;if(c.tags.includes(u))return;let d=new Date().toISOString(),f=(c.version??1)+1;await s(r,v({...c,tags:[...new Set([...c.tags,u])],updated:d,version:f,changelog:[...c.changelog??[],{version:f,date:d,reason:`Grouped lesson under ${n}`}]},l),`utf8`)}async function C(e,t,a,o){let s=f(a),c=n(o??i),l=(await e.list({category:`lessons`})).filter(e=>e.tags.includes(`lesson`)),u=l.map(e=>{let n=t.memoryMetaGet(e.path);if(!n||n.supersededBy!=null)return null;let i=h(n.lastAccessedAt,n.createdAt??e.created);if(i<s.safetyDays)return null;let a=r(n.confidence,n.lastAccessedAt,n.createdAt,c);return a>=s.maxConfidence||i<s.minIdleDays?null:{path:e.path,effectiveConfidence:a}}).filter(e=>e!==null).sort((e,t)=>e.effectiveConfidence-t.effectiveConfidence||e.path.localeCompare(t.path)).slice(0,s.maxPrune);if(!s.dryRun)for(let e of u)t.memoryMetaSetSuperseded(e.path,`lesson:auto-prune`);return{pruned:u.map(e=>e.path),skipped:l.length-u.length,dryRun:s.dryRun}}async function w(e,t,n){let r=p(n),i=(await e.list({category:`lessons`})).filter(e=>{if(!e.tags.includes(`lesson`)||e.tags.some(e=>e.startsWith(`group:`)))return!1;let n=t.memoryMetaGet(e.path);return n?.supersededBy==null||n===void 0});if(i.length<r.minGroupSize)return{groupsCreated:0,lessonsGrouped:0,groups:[],dryRun:r.dryRun};let a=b(y(i.map(e=>e.title),r.similarityThreshold)).filter(e=>e.length>=r.minGroupSize).map(e=>{let t=e.map(e=>i[e]).sort((e,t)=>e.path.localeCompare(t.path));return{label:x(t.map(e=>e.title)),members:t.map(e=>e.path)}}).sort((e,t)=>t.members.length-e.members.length||e.members[0].localeCompare(t.members[0])).slice(0,r.maxGroups);if(!r.dryRun&&a.length>0){for(let t of a)for(let n of t.members)await S(e,n,t.label);await e.reindexAll()}return{groupsCreated:a.length,lessonsGrouped:a.reduce((e,t)=>e+t.members.length,0),groups:a,dryRun:r.dryRun}}export{w as n,C as r,c as t};
@@ -1,2 +0,0 @@
1
- import{t as e}from"./rolldown-runtime-DT7IzrpZ.js";import{r as t}from"./supersession-9edUDEQ8.js";import{c as n,i as r,t as i}from"./lessons-D7sdHa2e.js";import{join as a}from"node:path";import{readFile as o,writeFile as s}from"node:fs/promises";var c=e({DEFAULT_GROUP_CONFIG:()=>u,DEFAULT_PRUNE_CONFIG:()=>l,groupLessons:()=>w,pruneLessons:()=>C});const l={maxConfidence:15,minIdleDays:30,safetyDays:7,maxPrune:20,dryRun:!0},u={similarityThreshold:.7,minGroupSize:2,maxGroups:10,dryRun:!0},d=new Set([`the`,`a`,`to`,`for`,`in`,`of`,`and`,`is`,`use`]);function f(e){return{maxConfidence:Math.min(100,Math.max(0,Math.trunc(e?.maxConfidence??l.maxConfidence))),minIdleDays:Math.max(1,Math.trunc(e?.minIdleDays??l.minIdleDays)),safetyDays:Math.max(0,Math.trunc(e?.safetyDays??l.safetyDays)),maxPrune:Math.max(1,Math.trunc(e?.maxPrune??l.maxPrune)),dryRun:e?.dryRun??l.dryRun}}function p(e){return{similarityThreshold:Math.min(1,Math.max(0,e?.similarityThreshold??u.similarityThreshold)),minGroupSize:Math.max(2,Math.trunc(e?.minGroupSize??u.minGroupSize)),maxGroups:Math.max(1,Math.trunc(e?.maxGroups??u.maxGroups)),dryRun:e?.dryRun??u.dryRun}}function m(e){if(!e)return 0;let t=Date.parse(e);return Number.isNaN(t)?0:t}function h(e,t){let n=Math.max(m(e),m(t));return n===0?1/0:Math.max(0,Date.now()-n)/864e5}function g(e){return e.toLowerCase().match(/[a-z0-9]{2,}/g)??[]}function _(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,60)}function v(e,t){return`${[`---`,`title: "${e.title.replace(/"/g,`\\"`)}"`,`category: ${e.category}`,`tags: [${e.tags.map(e=>`"${e}"`).join(`, `)}]`,`created: ${e.created}`,`updated: ${e.updated}`,`version: ${e.version}`,`origin: ${e.origin}`,`changelog:`,...e.changelog.map(e=>` - version: ${e.version}\n date: ${e.date}\n reason: "${e.reason.replace(/"/g,`\\"`)}"`),`---`].join(`
2
- `)}\n\n${t}\n`}function y(e,n){let r=e.map(()=>[]);for(let i=0;i<e.length;i+=1)for(let a=i+1;a<e.length;a+=1)t(e[i],e[a])>=n&&(r[i].push(a),r[a].push(i));return r}function b(e){let t=new Set,n=[];for(let r=0;r<e.length;r+=1){if(t.has(r))continue;let i=[r],a=[];for(t.add(r);i.length>0;){let n=i.pop();if(n!==void 0){a.push(n);for(let r of e[n])t.has(r)||(t.add(r),i.push(r))}}n.push(a)}return n}function x(e){let t=new Map,n=new Map,r=0;for(let i of e)for(let e of g(i))d.has(e)||(t.set(e,(t.get(e)??0)+1),n.has(e)||(n.set(e,r),r+=1));let i=[...t.entries()].sort((e,t)=>t[1]-e[1]||(n.get(e[0])??0)-(n.get(t[0])??0))[0];return i&&i[1]>1?_(i[0]):_(e.flatMap(e=>g(e)).find(e=>!d.has(e))??`lesson-group`)}async function S(e,t,n){let r=a(e.curatedDir,t),i=await o(r,`utf8`),{frontmatter:c,content:l}=e.parseFile(i),u=`group:${n}`;if(c.tags.includes(u))return;let d=new Date().toISOString(),f=(c.version??1)+1;await s(r,v({...c,tags:[...new Set([...c.tags,u])],updated:d,version:f,changelog:[...c.changelog??[],{version:f,date:d,reason:`Grouped lesson under ${n}`}]},l),`utf8`)}async function C(e,t,a,o){let s=f(a),c=n(o??i),l=(await e.list({category:`lessons`})).filter(e=>e.tags.includes(`lesson`)),u=l.map(e=>{let n=t.memoryMetaGet(e.path);if(!n||n.supersededBy!=null)return null;let i=h(n.lastAccessedAt,n.createdAt??e.created);if(i<s.safetyDays)return null;let a=r(n.confidence,n.lastAccessedAt,n.createdAt,c);return a>=s.maxConfidence||i<s.minIdleDays?null:{path:e.path,effectiveConfidence:a}}).filter(e=>e!==null).sort((e,t)=>e.effectiveConfidence-t.effectiveConfidence||e.path.localeCompare(t.path)).slice(0,s.maxPrune);if(!s.dryRun)for(let e of u)t.memoryMetaSetSuperseded(e.path,`lesson:auto-prune`);return{pruned:u.map(e=>e.path),skipped:l.length-u.length,dryRun:s.dryRun}}async function w(e,t,n){let r=p(n),i=(await e.list({category:`lessons`})).filter(e=>{if(!e.tags.includes(`lesson`)||e.tags.some(e=>e.startsWith(`group:`)))return!1;let n=t.memoryMetaGet(e.path);return n?.supersededBy==null||n===void 0});if(i.length<r.minGroupSize)return{groupsCreated:0,lessonsGrouped:0,groups:[],dryRun:r.dryRun};let a=b(y(i.map(e=>e.title),r.similarityThreshold)).filter(e=>e.length>=r.minGroupSize).map(e=>{let t=e.map(e=>i[e]).sort((e,t)=>e.path.localeCompare(t.path));return{label:x(t.map(e=>e.title)),members:t.map(e=>e.path)}}).sort((e,t)=>t.members.length-e.members.length||e.members[0].localeCompare(t.members[0])).slice(0,r.maxGroups);if(!r.dryRun&&a.length>0){for(let t of a)for(let n of t.members)await S(e,n,t.label);await e.reindexAll()}return{groupsCreated:a.length,lessonsGrouped:a.reduce((e,t)=>e+t.members.length,0),groups:a,dryRun:r.dryRun}}export{w as n,C as r,c as t};
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import{m as e,t,u as n}from"./bin.js";import{a as r,s as i}from"./lessons-B05P_TOl.js";import{existsSync as a,mkdirSync as o}from"node:fs";import{join as s}from"node:path";import{getGlobalDataDir as c,isUserInstalled as l,listWorkspaces as u}from"../../core/dist/index.js";var d=e({DEFAULT_PROMOTE_CONFIG:()=>f,collectWorkspaceLessons:()=>w,demoteLesson:()=>D,getGlobalCuratedDir:()=>C,promoteLessons:()=>E,scanForDuplicates:()=>T});const f={minWorkspaces:2,minAvgConfidence:80,similarityThreshold:.7,dryRun:!0};function p(e){return{minWorkspaces:Math.max(2,Math.trunc(e?.minWorkspaces??f.minWorkspaces)),minAvgConfidence:Math.min(100,Math.max(0,Math.trunc(e?.minAvgConfidence??f.minAvgConfidence))),similarityThreshold:Math.min(1,Math.max(0,e?.similarityThreshold??f.similarityThreshold)),dryRun:e?.dryRun??f.dryRun}}function m(e,t){let r=e.map(()=>[]);for(let i=0;i<e.length;i+=1)for(let a=i+1;a<e.length;a+=1)n(e[i].insight,e[a].insight)>=t&&(r[i].push(a),r[a].push(i));return r}function h(e){let t=new Set,n=[];for(let r=0;r<e.length;r+=1){if(t.has(r))continue;let i=[r],a=[];for(t.add(r);i.length>0;){let n=i.pop();if(n!==void 0){a.push(n);for(let r of e[n])t.has(r)||(t.add(r),i.push(r))}}n.push(a)}return n}function g(e){return new t(e,null,null)}function _(e){return(e??``).replace(/\s+/g,` `).trim()}function v(e){let t=_(e);return t.length<=80?t:`${t.slice(0,77).replace(/\s+\S*$/,``)}...`}function y(e){return r({title:v(e.insight),context:`Observed across ${e.foundIn.length} workspaces: ${e.foundIn.join(`, `)}`,insight:e.insight,evidence:[`Promoted from workspaces: ${e.foundIn.join(`, `)}`,`Average confidence: ${e.avgConfidence}/100`,`Reason: ${e.reason}`].join(`
3
- `),confidence:e.avgConfidence,tags:[`lesson`,`promoted`,`global`]})}async function b(e,t){let n=await e.list({category:`lessons`});return(await Promise.all(n.map(async n=>{let r=await e.read(n.path),a=i(r.content),o=_(a.insight);return o?{workspace:t,path:n.path,title:a.title??r.title??n.title,insight:o,confidence:a.confidence??0}:null}))).filter(e=>e!==null)}async function x(e){return(await b(e,`global`)).map(e=>e.insight)}function S(e,t,r){return t.some(t=>n(t,e)>=r)}function C(){let e=s(c(),`global-knowledge`,`.ai`,`curated`);return a(e)||o(e,{recursive:!0}),e}async function w(e){let t=new Map;if(!l())return t;for(let e of u()){let n=s(e.workspacePath,`.ai`,`curated`);if(!a(n))continue;let r=await b(g(n),e.partition);r.length>0&&t.set(e.partition,r)}return t}function T(e,t=f){let n=p(t),r=[...e.values()].flat();if(r.length===0)return[];let i=h(m(r,n.similarityThreshold)),a=[];for(let e of i){let t=e.map(e=>r[e]),i=[...new Set(t.map(e=>e.workspace))].sort();if(i.length<n.minWorkspaces)continue;let o=Math.round(t.reduce((e,t)=>e+t.confidence,0)/t.length),s=[...t].sort((e,t)=>t.confidence-e.confidence||e.title.localeCompare(t.title)||e.path.localeCompare(t.path))[0];a.push({insight:s.insight,foundIn:i,avgConfidence:o,action:o>=n.minAvgConfidence?`promote`:`skip`,reason:o>=n.minAvgConfidence?`Shared across ${i.length} workspaces`:`Below confidence threshold`})}return a.sort((e,t)=>Number(t.action===`promote`)-Number(e.action===`promote`)||t.foundIn.length-e.foundIn.length||t.avgConfidence-e.avgConfidence||e.insight.localeCompare(t.insight))}async function E(e,t,n=f){let r=p(n),i=[],a=await x(t);for(let n of e){if(n.action!==`promote`||S(n.insight,a,r.similarityThreshold)||r.dryRun)continue;let e=await t.remember(v(n.insight),y(n),`lessons`,[`lesson`,`promoted`,`global`]);i.push(e.path),a.push(n.insight)}return{candidates:e,promoted:i}}async function D(e,t){try{return await e.forget(t,`Demoted from global knowledge partition`),{removed:!0,path:t}}catch(e){if(e instanceof Error&&/not found/i.test(e.message))return{removed:!1,path:t};throw e}}export{E as a,C as i,w as n,d as o,D as r,T as s,f as t};
@@ -1,2 +0,0 @@
1
- import{t as e}from"./rolldown-runtime-DT7IzrpZ.js";import{r as t}from"./supersession-9edUDEQ8.js";import{t as n}from"./curated-manager-BrtqcmVm.js";import{a as r,s as i}from"./lessons-D7sdHa2e.js";import{existsSync as a,mkdirSync as o}from"node:fs";import{join as s}from"node:path";import{getGlobalDataDir as c,isUserInstalled as l,listWorkspaces as u}from"../../core/dist/index.js";var d=e({DEFAULT_PROMOTE_CONFIG:()=>f,collectWorkspaceLessons:()=>w,demoteLesson:()=>D,getGlobalCuratedDir:()=>C,promoteLessons:()=>E,scanForDuplicates:()=>T});const f={minWorkspaces:2,minAvgConfidence:80,similarityThreshold:.7,dryRun:!0};function p(e){return{minWorkspaces:Math.max(2,Math.trunc(e?.minWorkspaces??f.minWorkspaces)),minAvgConfidence:Math.min(100,Math.max(0,Math.trunc(e?.minAvgConfidence??f.minAvgConfidence))),similarityThreshold:Math.min(1,Math.max(0,e?.similarityThreshold??f.similarityThreshold)),dryRun:e?.dryRun??f.dryRun}}function m(e,n){let r=e.map(()=>[]);for(let i=0;i<e.length;i+=1)for(let a=i+1;a<e.length;a+=1)t(e[i].insight,e[a].insight)>=n&&(r[i].push(a),r[a].push(i));return r}function h(e){let t=new Set,n=[];for(let r=0;r<e.length;r+=1){if(t.has(r))continue;let i=[r],a=[];for(t.add(r);i.length>0;){let n=i.pop();if(n!==void 0){a.push(n);for(let r of e[n])t.has(r)||(t.add(r),i.push(r))}}n.push(a)}return n}function g(e){return new n(e,null,null)}function _(e){return(e??``).replace(/\s+/g,` `).trim()}function v(e){let t=_(e);return t.length<=80?t:`${t.slice(0,77).replace(/\s+\S*$/,``)}...`}function y(e){return r({title:v(e.insight),context:`Observed across ${e.foundIn.length} workspaces: ${e.foundIn.join(`, `)}`,insight:e.insight,evidence:[`Promoted from workspaces: ${e.foundIn.join(`, `)}`,`Average confidence: ${e.avgConfidence}/100`,`Reason: ${e.reason}`].join(`
2
- `),confidence:e.avgConfidence,tags:[`lesson`,`promoted`,`global`]})}async function b(e,t){let n=await e.list({category:`lessons`});return(await Promise.all(n.map(async n=>{let r=await e.read(n.path),a=i(r.content),o=_(a.insight);return o?{workspace:t,path:n.path,title:a.title??r.title??n.title,insight:o,confidence:a.confidence??0}:null}))).filter(e=>e!==null)}async function x(e){return(await b(e,`global`)).map(e=>e.insight)}function S(e,n,r){return n.some(n=>t(n,e)>=r)}function C(){let e=s(c(),`global-knowledge`,`.ai`,`curated`);return a(e)||o(e,{recursive:!0}),e}async function w(e){let t=new Map;if(!l())return t;for(let e of u()){let n=s(e.workspacePath,`.ai`,`curated`);if(!a(n))continue;let r=await b(g(n),e.partition);r.length>0&&t.set(e.partition,r)}return t}function T(e,t=f){let n=p(t),r=[...e.values()].flat();if(r.length===0)return[];let i=h(m(r,n.similarityThreshold)),a=[];for(let e of i){let t=e.map(e=>r[e]),i=[...new Set(t.map(e=>e.workspace))].sort();if(i.length<n.minWorkspaces)continue;let o=Math.round(t.reduce((e,t)=>e+t.confidence,0)/t.length),s=[...t].sort((e,t)=>t.confidence-e.confidence||e.title.localeCompare(t.title)||e.path.localeCompare(t.path))[0];a.push({insight:s.insight,foundIn:i,avgConfidence:o,action:o>=n.minAvgConfidence?`promote`:`skip`,reason:o>=n.minAvgConfidence?`Shared across ${i.length} workspaces`:`Below confidence threshold`})}return a.sort((e,t)=>Number(t.action===`promote`)-Number(e.action===`promote`)||t.foundIn.length-e.foundIn.length||t.avgConfidence-e.avgConfidence||e.insight.localeCompare(t.insight))}async function E(e,t,n=f){let r=p(n),i=[],a=await x(t);for(let n of e){if(n.action!==`promote`||S(n.insight,a,r.similarityThreshold)||r.dryRun)continue;let e=await t.remember(v(n.insight),y(n),`lessons`,[`lesson`,`promoted`,`global`]);i.push(e.path),a.push(n.insight)}return{candidates:e,promoted:i}}async function D(e,t){try{return await e.forget(t,`Demoted from global knowledge partition`),{removed:!0,path:t}}catch(e){if(e instanceof Error&&/not found/i.test(e.message))return{removed:!1,path:t};throw e}}export{E as a,C as i,w as n,d as o,D as r,T as s,f as t};
@@ -1,7 +0,0 @@
1
- import{r as e,s as t}from"./supersession-9edUDEQ8.js";import{join as n}from"node:path";import{createLogger as r}from"../../core/dist/index.js";import{writeFile as i}from"node:fs/promises";import{tmpdir as a}from"node:os";import{replayAppend as o}from"../../tools/dist/index.js";const s=r(`auto-gc`);let c=`warming`,l=null,u=0;function d(){let e=[...K()];if(e.length<10)return 0;e.sort((e,t)=>e-t);let t=Math.floor(e.length*.95);return e[Math.min(t,e.length-1)]}function f(e){let t=d();if(t===0){c=`warming`;return}if(t>500){c=`degraded`;let n=Date.now();if(l&&n-l<36e5){s.debug(`GC cooldown active — skipping`,{lastGcAgoMs:n-l});return}l=n,u++,s.warn(`p95 latency exceeds threshold, triggering GC`,{p95:t,cycle:u}),e&&e().catch(e=>s.error(`GC callback failed`,{err:String(e)}))}else t<200&&(c=`healthy`)}function p(){return{state:c,p95:d(),lastGcAt:l,gcCount:u,bufferSize:K().length}}const m={enabled:!0,batchThreshold:20,cooldownMs:3e5,maxCandidatesPerSession:5,initialConfidence:40,excludeTools:[`knowledge`,`replay`,`stash`,`checkpoint`,`session_digest`,`reindex`,`status`,`flow`,`evidence_map`,`present`]},h=new Set([`search`,`find`,`symbol`,`grep_search`,`semantic_search`]),g=new Set([`replace_string_in_file`,`editfiles`,`create_file`,`apply_patch`]),_=new Set([`check`,`test_run`]),v=new Set(`action.and.args.auto.buffer.category.content.create.cwd.false.file.files.find.grep.json.knowledge.list.path.query.read.replace.search.semantic.subaction.symbol.test.tool.true.update`.split(`.`));function y(e){return e.replace(/^mcp_[^_]+_/,``).toLowerCase()}function b(e){return[...new Set(e.filter(e=>e.length>0))]}function x(e,t){return{...t,confidence:m.initialConfidence,tags:[`auto-observed`,`detector:${e}`],detector:e}}function S(e,n){let r=new Map;for(let n of e)for(let e of t(n))v.has(e)||r.set(e,(r.get(e)??0)+1);let i=[...r.entries()].filter(([,e])=>e>=n).sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).map(([e])=>e);return i.length>0?i.slice(0,4):[...r.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).slice(0,4).map(([e])=>e)}function C(e){return e.length>0?e.join(`, `):`similar tasks`}function w(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.ts==`number`&&Number.isFinite(t.ts)&&typeof t.tool==`string`&&typeof t.input==`string`&&Array.isArray(t.files)&&t.files.every(e=>typeof e==`string`)}function T(t){let n=[];for(let r of t)n.some(t=>e(t.title,r.title)>.8)||n.push(r);return n}function E(e){let t=new Map;for(let n of e){let e=y(n.tool),r=t.get(e)??[];r.push(n),t.set(e,r)}return[...t.entries()].filter(([,e])=>e.length>=5).map(([e,t])=>{let n=C(S(t.map(e=>e.input),Math.max(2,Math.ceil(t.length/2))));return x(`tool-preference`,{title:`Preferred tool: ${e} for ${n}`,context:`Observed ${t.length} ${e} calls with recurring inputs around ${n}.`,insight:`Use ${e} when working with ${n}.`,evidence:t.slice(0,5).map(e=>`${e.tool}: ${e.input}`).join(`
2
- `)})})}function D(e){let t=new Map;for(let n=0;n<e.length;n+=1){let r=e[n];if(h.has(y(r.tool)))for(let i=n+1;i<e.length&&i<=n+5;i+=1){let n=e[i];if(!(!g.has(y(n.tool))||n.files.length===0))for(let e of b(n.files)){let i=t.get(e)??{count:0,queries:[],evidence:[]};i.count+=1,i.queries.push(r.input),i.evidence.push(`${r.tool}: ${r.input} -> ${n.tool}: ${e}`),t.set(e,i)}}}return[...t.entries()].filter(([,e])=>e.count>=3).map(([e,t])=>{let n=C(S(t.queries,Math.max(2,Math.ceil(t.count/2))));return x(`search-action`,{title:`Check ${e} when searching for ${n}`,context:`Searches related to ${n} were followed by edits to ${e} ${t.count} times within five tool calls.`,insight:`When working on ${n}, check ${e} early because searches repeatedly led there.`,evidence:t.evidence.slice(0,5).join(`
3
- `)})})}function O(e){let t=new Map;for(let n=0;n<e.length-2;n+=1){let r=e[n];if(!_.has(y(r.tool)))continue;let i=new Set,a=!1;for(let o=n+1;o<e.length;o+=1){let n=e[o],s=y(n.tool);if(g.has(s)){a=!0;for(let e of n.files)i.add(e);continue}if(_.has(s)){if(!a||i.size===0)break;let e=[...i].sort(),o=e.join(`|`),s=t.get(o)??{count:0,evidence:[]};s.count+=1,s.evidence.push(`${r.tool} -> edit(${e.join(`, `)}) -> ${n.tool}`),t.set(o,s);break}if(!a)break}}return[...t.entries()].filter(([,e])=>e.count>=2).map(([e,t])=>{let n=e.split(`|`);return x(`error-fix-cycle`,{title:`Repeated validation-edit loop in ${n.length===1?n[0]:`${n[0]} and related files`}`,context:`Observed ${t.count} validation cycles touching ${n.join(`, `)}.`,insight:`Common fix pattern in ${n.join(`, `)}: check -> edit -> recheck.`,evidence:t.evidence.slice(0,5).join(`
4
- `)})})}function k(e,t=m){if(!t.enabled||e.length===0)return[];let n=new Set(t.excludeTools.map(e=>e.toLowerCase())),r=e.filter(e=>!n.has(y(e.tool)));return T([...E(r),...D(r),...O(r)].map(e=>({...e,confidence:t.initialConfidence,tags:b([`auto-observed`,`detector:${e.detector}`,...e.tags])}))).slice(0,t.maxCandidatesPerSession)}function A(e){return e.split(`
5
- `).filter(Boolean).map(e=>{try{return JSON.parse(e)}catch{return null}}).filter(w)}const j=r(`replay-interceptor`),M=/key|token|secret|auth|password|bearer/i,N=new Set([`eval`,`env`]);function P(e){if(typeof e==`string`)return/^(Bearer |sk-|ghp_|glpat-|ghu_|ghs_|github_pat_)/i.test(e)?`[REDACTED]`:e;if(Array.isArray(e))return e.map(P);if(e&&typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))/(?:token|secret|password|passphrase|key|auth|credential|api.?key)/i.test(n)?t[n]=`[REDACTED]`:t[n]=P(r);return t}return e}function F(e,t){if(N.has(e))return JSON.stringify({_redacted:!0,tool:e});let n=P(t);if(e===`http`&&n.headers&&typeof n.headers==`object`){let e={};for(let[t,r]of Object.entries(n.headers))e[t]=M.test(t)?`[REDACTED]`:r;return n.headers=e,JSON.stringify(n).slice(0,2e3)}return JSON.stringify(n).slice(0,2e3)}const I=new Map,L=[],R=[];let z=0,B;function V(e,t){return F(e,t).slice(0,500)}function H(e){let t=new Set,n=[e];for(;n.length>0&&t.size<20;){let e=n.pop();if(e!=null){if(Array.isArray(e)){for(let t of e)n.push(t);continue}if(typeof e==`object`)for(let[r,i]of Object.entries(e)){if(Array.isArray(i)){if(/^(?:files|paths)$/i.test(r))for(let e of i)typeof e==`string`&&e.length>0&&t.add(e);else n.push(i);continue}if(typeof i==`string`&&/^(?:file|filepath|path)$/i.test(r)&&i.length>0){t.add(i);continue}i&&typeof i==`object`&&n.push(i)}}}return[...t]}function U(e,t,r){if(z+=1,R.push(JSON.stringify({tool:e,input:V(e,t),output:r.slice(0,500),files:H(t),ts:Date.now()})),R.length>100&&R.shift(),z%50!=0)return;let o=R.join(`
6
- `);R.length=0,!(!B||o.trim().split(`
7
- `).filter(Boolean).length<20)&&Promise.resolve().then(async()=>{let e=k(A(o),m);if(e.length!==0){try{let t=n(a(),`aikit-auto-observe-${process.pid}-${Date.now()}.json`);await i(t,JSON.stringify(e,null,2),`utf8`),j.info(`Auto-observe candidates detected`,{count:e.length,filePath:t})}catch(e){j.warn(`Failed to persist auto-observe candidates`,{error:String(e)})}B?.(e)}}).catch(()=>{})}function W(e,t,n,r,i){let a=I.get(e);a||(a={callCount:0,totalDurationMs:0,totalInputChars:0,totalOutputChars:0,errorCount:0},I.set(e,a)),a.callCount++,a.totalDurationMs+=t,a.totalInputChars+=n,a.totalOutputChars+=r,i&&a.errorCount++,L.push(t),L.length>100&&L.shift(),L.length>=10&&L.length%20==0&&f()}function G(){return Array.from(I.entries()).map(([e,t])=>({tool:e,...t}))}function K(){return L}function q(e){B=e}function J(){return async(e,t)=>{let n=Date.now(),r=JSON.stringify(e.args??{}).length;try{let i=await t(),a=Date.now()-n,s=JSON.stringify(i);return o({ts:new Date().toISOString(),source:`mcp`,tool:e.toolName,input:F(e.toolName,e.args),durationMs:a,status:`ok`,output:s,traceId:e.requestId,outputChars:s.length}),U(e.toolName,e.args,s),W(e.toolName,a,r,s.length,!1),i}catch(t){let i=Date.now()-n,a=t instanceof Error?t.message:String(t);throw o({ts:new Date().toISOString(),source:`mcp`,tool:e.toolName,input:F(e.toolName,e.args),durationMs:i,status:`error`,output:a,traceId:e.requestId,outputChars:0}),U(e.toolName,e.args,a),W(e.toolName,i,r,0,!0),t}}}export{A as a,m as i,G as n,k as o,q as r,p as s,J as t};
@@ -1 +0,0 @@
1
- import{t as e}from"./rolldown-runtime-DT7IzrpZ.js";var t=e({DEFAULT_SUPERSESSION_CONFIG:()=>n,findSupersessionCandidates:()=>o,jaccardSimilarity:()=>a,performSupersession:()=>s,resolveSupersessionConfig:()=>r,tokenize:()=>i});const n={threshold:.7,maxCompare:50,autoThreshold:.95};function r(e){let t=Math.min(1,Math.max(0,e?.threshold??n.threshold)),r=Math.min(1,Math.max(t,e?.autoThreshold??n.autoThreshold));return{threshold:t,maxCompare:Math.max(1,Math.trunc(e?.maxCompare??n.maxCompare)),autoThreshold:r}}function i(e){let t=e.toLowerCase().match(/[a-z0-9]{2,}/g)??[];return new Set(t)}function a(e,t){let n=i(e),r=i(t);if(n.size===0&&r.size===0)return 1;if(n.size===0||r.size===0)return 0;let a=new Set([...n].filter(e=>r.has(e))),o=new Set([...n,...r]);return a.size/o.size}function o(e,t,i=n){let o=r(i);return t.slice(0,o.maxCompare).map(t=>({entryId:t.id,title:t.title,similarity:a(e,t.content),path:t.path})).filter(e=>e.similarity>=o.threshold).sort((e,t)=>t.similarity-e.similarity)}function s(e,t,n){e.memoryMetaCreate(t),e.memoryMetaSetSuperseded(t,n)}export{r as a,s as i,o as n,t as o,a as r,i as s,n as t};