@vpxa/aikit 0.1.249 → 0.1.251

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.
@@ -93,6 +93,7 @@ Important distinction:
93
93
  - Root `*-viewer.html` files are Vite entry templates
94
94
  - `dist/*.html` files are the final self-contained artifacts
95
95
  - `embed.mjs` reads from `dist/`, not from the root entry templates
96
+ - `package.json` `exports` points at the built viewer HTML assets, which keeps workspace health satisfied without changing the standalone build flow
96
97
 
97
98
  ## Architecture
98
99
 
@@ -149,7 +149,7 @@ import{postTaskLesson as e,preTaskKnowledgeRecall as t}from"./protocols.mjs";con
149
149
  **Subagent prompt template:**
150
150
  1. **Scope** — exact files + boundary
151
151
  2. **Goal** — acceptance criteria, testable
152
- 3. **Arch Context** — pick by \`config.tokenBudget\`: efficient → \`stratum_card({ files: ['<path>'], query: '<what matters>', tier: 'T1' })\`, normal → \`compact({path, query})\`, full → \`digest({ sources: [...], query: '<what matters>' })\`. Default to efficient.
152
+ 3. **Arch Context** — pick by \`config.tokenBudget\`: efficient → \`stratum_card({ files: ['<path>'], query: '<what matters>', tier: 'T1' })\`, normal → \`compact({path, query})\` or \`compact({ref, query?})\`, full → \`digest({ sources: [...], query: '<what matters>' })\`. Default to efficient.
153
153
  4. **Constraints** — patterns, conventions
154
154
  5. **Prior Knowledge** — Fetch topic-scoped knowledge: \`knowledge({ action: "lesson", subAction: "list-lessons", topic: "<2-3 task keywords>", minConfidence: 70 })\` + \`search({ query: "<task area>", category: "conventions", limit: 3 })\`. Include HIGH-confidence results (≥70) under \`## Prior Knowledge\`. Skip if none.
155
155
  6. **Artifacts Path** — the active flow's run directory and artifacts path from \`flow({ action: 'status' })\` (e.g. \`.flows/add-authentication/.spec/\`)
@@ -188,7 +188,7 @@ import{postTaskLesson as e,preTaskKnowledgeRecall as t}from"./protocols.mjs";con
188
188
 
189
189
  ### Context Gathering for Subagent Prompts
190
190
 
191
- Default to \`stratum_card({ files: ['<path>'], query: '<what matters>', tier: 'T1' })\`; upgrade to \`compact\` or \`digest\`; use \`read_file\` only for exact edit lines.
191
+ Default to \`stratum_card({ files: ['<path>'], query: '<what matters>', tier: 'T1' })\`; upgrade to \`compact({ path, query })\`, \`compact({ ref, query? })\`, or \`digest\`; use \`read_file\` only for exact edit lines.
192
192
 
193
193
  **Knowledge injection (MANDATORY for Standard+ tier):** Before any subagent prompt, call:
194
194
  - \`knowledge({ action: "lesson", subAction: "list-lessons", topic: "<task keywords>", minConfidence: 70 })\`
@@ -415,7 +415,7 @@ import{postTaskLesson as e,preTaskKnowledgeRecall as t}from"./protocols.mjs";con
415
415
  ## Pre-Edit Checklist
416
416
 
417
417
  1. **Understand consumers** — \`graph({action:'find_nodes', name_pattern:'<target>'})\` → \`graph({action:'neighbors', node_id, direction:'incoming'})\`
418
- 2. **Compress, don't raw-read** — \`file_summary\` then \`compact({path, query})\`; \`read_file\` only for exact edit lines
418
+ 2. **Compress, don't raw-read** — \`file_summary\` then \`compact({path, query})\` or \`compact({ref, query?})\`; \`read_file\` only for exact edit lines
419
419
  3. **Snapshot risky edits** — \`checkpoint({action:'save', label:'pre-<scope>'})\` before cross-cutting changes
420
420
  4. **Estimate blast radius** — run \`blast_radius\` before and after shared/public symbol changes
421
421
  5. **TDD when tests exist** — failing test first, then minimum code
@@ -530,6 +530,8 @@ ${e()}
530
530
 
531
531
  ### Phase 2: Reproduce
532
532
 
533
+ Tag filters are exact labels, not substring search.
534
+
533
535
  1. \`search({ query: "<error-keywords>", tags: ["observation"] })\`
534
536
  2. \`search({ query: "error patterns" })\`
535
537
  3. \`knowledge({ action: "list", tag: "errors" })\`
@@ -10,7 +10,7 @@ Follow \`multi-agents-development\` dispatch patterns:
10
10
  2. **Subagent Context**:
11
11
  - **Scope**: exact files + do NOT touch boundary
12
12
  - **Goal**: testable acceptance criteria
13
- - **Arch Context**: code via \`compact()\`/\`digest()\`
13
+ - **Arch Context**: code via \`compact()\`/\`digest()\` or a cached ref via \`compact({ ref, query? })\`
14
14
  - **Constraints**: patterns, conventions, anti-patterns
15
15
  - **Self-Review**: checklist before DONE
16
16
 
@@ -52,6 +52,7 @@ Use AI Kit retrieval/compression first. Native tools are fallback only.
52
52
  | \`read_file\` to understand a file | \`file_summary({ path })\` | Structure first |
53
53
  | \`read_file\` to find code | \`compact({ path, query })\` | Focused extract |
54
54
  | Multiple \`read_file\` calls | \`digest({ sources, query: "<task description>" })\` | Compress multi-file context |
55
+ | Cached ref to refocus prior output | \`compact({ ref, query? })\` | Reuse reversible text artifacts |
55
56
  | \`grep_search\` / \`semantic_search\` | \`search({ query })\` | Indexed search |
56
57
  | \`grep_search\` for a symbol | \`symbol({ name })\` | Def + refs |
57
58
  | \`run_in_terminal\` for tsc/lint | \`check({})\` | Narrow validation |
@@ -196,6 +197,7 @@ Use targeted searches before expensive work:
196
197
  | \`symbol({ name })\` | Definition + refs |
197
198
  | \`trace({ start, direction })\` | Call/data flow |
198
199
  | \`compact({ path, query })\` | Read specific section of a file |
200
+ | \`compact({ ref, query? })\` | Reuse cached search/find/knowledge/compact output |
199
201
  | \`read_file\` | **ONLY** when you need exact lines for a pending edit |
200
202
 
201
203
  ### Step 4: Tool Discovery
@@ -155,9 +155,9 @@ Every tool call passes through extractors that capture reusable facts:
155
155
  | **Research results** | \`web_search\`, \`web_fetch\`, \`search\`, \`find\` | Search findings, web content, code discoveries |
156
156
  | **Behavioral patterns** | ALL tools (ring buffer) | Tool preferences, search→edit sequences, error-fix cycles |
157
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" })\`
158
+ **Retrieval:** Use \`enrich: true\` on any tool that supports it — the server automatically surfaces previously captured facts relevant to your query. Search/find/knowledge responses can also emit reusable refs; feed those into \`compact({ ref, query })\` instead of reopening the source.
159
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.
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, or reuse an existing \`ref\` with \`compact({ ref, query })\`.
161
161
 
162
162
  ### Retention & Tier Promotion
163
163
  - Memories start at **working** tier → promote on repeated access: episodic (2) → semantic (5) → procedural (10)
@@ -1 +0,0 @@
1
- import{EMBEDDING_DEFAULTS as e,SEARCH_DEFAULTS as t,STORE_DEFAULTS as n,createLogger as r,serializeError as i,sourceTypeContentTypes as a}from"../../core/dist/index.js";import{Index as o,connect as s}from"@lancedb/lancedb";function c(e){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}const l=/^[\w.\-/ ]+$/,u=r(`store`);function d(e,t){if(!l.test(e))throw Error(`Invalid ${t} filter value: contains disallowed characters`);return e.replace(/'/g,`''`)}var f=class r{db=null;table=null;dbPath;tableName;_draining=!1;_priorityQueue=[];_normalQueue=[];_ftsReady=!1;_ftsRecoveryAttemptAt=0;static FTS_RECOVERY_COOLDOWN_MS=300*1e3;enqueueWrite(e,t=!1){return new Promise((n,r)=>{let i=async()=>{try{n(await e())}catch(e){r(e)}};t?this._priorityQueue.push(i):this._normalQueue.push(i),this._drain()})}async _drain(){if(!this._draining){this._draining=!0;try{for(;this._priorityQueue.length>0||this._normalQueue.length>0;){let e=this._priorityQueue.shift()??this._normalQueue.shift();e&&await e()}}finally{this._draining=!1}}}constructor(e){this.dbPath=e?.path??n.path,this.tableName=e?.tableName??n.tableName}async initialize(){this.db=await s(this.dbPath),(await this.db.tableNames()).includes(this.tableName)&&(this.table=await this.db.openTable(this.tableName),await this.createFtsIndex())}async upsert(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);for(let n=0;n<t.length;n++)if(t[n].length===0)throw Error(`Zero-length vector at index ${n} for record ${e[n].sourcePath}`);return this.enqueueWrite(()=>this._upsertImpl(e,t))}}async upsertInteractive(e,t){if(e.length!==0){if(e.length!==t.length)throw Error(`Record count (${e.length}) does not match vector count (${t.length})`);for(let n=0;n<t.length;n++)if(t[n].length===0)throw Error(`Zero-length vector at index ${n} for record ${e[n].sourcePath}`);return this.enqueueWrite(()=>this._upsertImpl(e,t),!0)}}async _upsertImpl(e,t){let n=e.map((e,n)=>({id:e.id,vector:Array.from(t[n]),content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath??``,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:JSON.stringify(e.tags),category:e.category??``,version:e.version}));if(this.table){let t=[...new Set(e.map(e=>e.sourcePath))];for(let e of t)try{await this.table.delete(`sourcePath = '${d(e,`sourcePath`)}'`)}catch{}await this.table.add(n)}else try{this.table=await this.db?.createTable(this.tableName,n)??null}catch(e){if(String(e).includes(`already exists`)&&this.db)this.table=await this.db.openTable(this.tableName),await this.table.add(n);else throw e}}async search(e,n){if(e.length===0||!this.table)return[];let r=n?.limit??t.maxResults,i=n?.minScore??t.minScore,a=this.table.search(e).limit(r*2),o=this.buildFilterString(n);return o&&(a=a.where(o)),(await a.toArray()).map(e=>({record:this.fromLanceRecord(e),score:1-(e._distance??1)})).filter(e=>e.score>=i).slice(0,r)}async createFtsIndex(){return this.enqueueWrite(()=>this._createFtsIndexImpl())}async _createFtsIndexImpl(){if(this.table)try{await this.table.createIndex(`content`,{config:o.fts({withPosition:!0}),replace:!0}),this._ftsReady=!0,this._ftsRecoveryAttemptAt=0,u.info(`FTS index created/updated`,{column:`content`})}catch(e){u.warn(`FTS index creation failed`,i(e))}}async ftsSearch(e,n){if(!this.table)return[];if(!this._ftsReady){let e=Date.now();if(e-this._ftsRecoveryAttemptAt<r.FTS_RECOVERY_COOLDOWN_MS)return[];this._ftsRecoveryAttemptAt=e;try{await this.createFtsIndex()}catch{return[]}if(!this._ftsReady)return[]}let a=n?.limit??t.maxResults;try{let t=this.table.search(e).limit(a*2),r=this.buildFilterString(n);return r&&(t=t.where(r)),(await t.toArray()).map(e=>({record:this.fromLanceRecord(e),score:e._score??e._relevance_score??0}))}catch(e){return(e instanceof Error?e.message:String(e)).includes(`INVERTED index`)?(u.debug(`FTS search skipped — index not yet available`),this._ftsReady=!1):u.warn(`FTS search failed`,i(e)),[]}}async getById(e){if(!this.table)return null;let t=await this.table.query().where(`id = '${d(e,`id`)}'`).limit(1).toArray();return t.length===0?null:this.fromLanceRecord(t[0])}async deleteBySourcePath(e){return this.enqueueWrite(()=>this._deleteBySourcePathImpl(e))}async _deleteBySourcePathImpl(e){if(!this.table)return 0;let t=await this.getBySourcePath(e);return t.length===0?0:(await this.table.delete(`sourcePath = '${d(e,`sourcePath`)}'`),t.length)}async deleteById(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e))}async deleteByIdInteractive(e){return this.enqueueWrite(()=>this._deleteByIdImpl(e),!0)}async _deleteByIdImpl(e){return!this.table||!await this.getById(e)?!1:(await this.table.delete(`id = '${d(e,`id`)}'`),!0)}async getBySourcePath(e){return this.table?(await this.table.query().where(`sourcePath = '${d(e,`sourcePath`)}'`).limit(1e3).toArray()).map(e=>this.fromLanceRecord(e)):[]}async getStats(){if(!this.table)return{totalRecords:0,totalFiles:0,contentTypeBreakdown:{},lastIndexedAt:null,storeBackend:`lancedb`,embeddingModel:e.model};let t=await this.table.countRows(),n=await this.table.query().select([`sourcePath`,`contentType`,`indexedAt`]).limit(1e5).toArray(),r={},i=new Set,a=null;for(let e of n){let t=e;r[t.contentType]=(r[t.contentType]??0)+1,i.add(t.sourcePath),(!a||t.indexedAt>a)&&(a=t.indexedAt)}return{totalRecords:t,totalFiles:i.size,contentTypeBreakdown:r,lastIndexedAt:a,storeBackend:`lancedb`,embeddingModel:e.model}}async listSourcePaths(){if(!this.table)return[];let e=await this.table.query().select([`sourcePath`]).limit(1e5).toArray();return[...new Set(e.map(e=>e.sourcePath))]}async dropTable(){return this.enqueueWrite(()=>this._dropTableImpl())}async _dropTableImpl(){if(this.db&&(await this.db.tableNames()).includes(this.tableName))for(let e=1;e<=3;e++)try{await this.db.dropTable(this.tableName);break}catch(t){if(e===3)throw t;let n=e*500;u.warn(`dropTable attempt failed, retrying`,{attempt:e,delayMs:n}),await new Promise(e=>setTimeout(e,n))}this.table=null}async close(){try{this.db&&typeof this.db.close==`function`&&await this.db.close()}catch{}this.table=null,this.db=null}buildFilterString(e){let t=[];if(e?.contentType&&t.push(`contentType = '${d(e.contentType,`contentType`)}'`),e?.sourceType){let n=a(e.sourceType);if(n.length>0){let e=n.map(e=>`'${d(e,`sourceType`)}'`).join(`, `);t.push(`contentType IN (${e})`)}}if(e?.origin&&t.push(`origin = '${d(e.origin,`origin`)}'`),e?.category&&t.push(`category = '${d(e.category,`category`)}'`),e?.tags&&e.tags.length>0){let n=e.tags.map(e=>`tags LIKE '%${d(e,`tag`)}%'`);t.push(`(${n.join(` OR `)})`)}return t.length>0?t.join(` AND `):null}fromLanceRecord(e){return{id:e.id,content:e.content,sourcePath:e.sourcePath,contentType:e.contentType,headingPath:e.headingPath||void 0,chunkIndex:e.chunkIndex,totalChunks:e.totalChunks,startLine:e.startLine,endLine:e.endLine,fileHash:e.fileHash,indexedAt:e.indexedAt,origin:e.origin,tags:c(e.tags),category:e.category||void 0,version:e.version}}};export{f as LanceStore};