@hanhnd/agent-kit 1.0.36 → 1.0.37

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.
package/dist/cli.js CHANGED
@@ -15019,6 +15019,11 @@ import * as os from "os";
15019
15019
  import * as path3 from "path";
15020
15020
 
15021
15021
  // src/services/memory/constants.ts
15022
+ var EMBEDDING_MODEL_DIMENSIONS = {
15023
+ ["tiny" /* TINY */]: 384,
15024
+ ["base" /* BASE */]: 384,
15025
+ ["large" /* LARGE */]: 768
15026
+ };
15022
15027
  var DEFAULT_MEMORY_CONFIG = {
15023
15028
  enabled: false,
15024
15029
  wikiDir: "",
@@ -15026,7 +15031,7 @@ var DEFAULT_MEMORY_CONFIG = {
15026
15031
  chunkSize: 1500,
15027
15032
  overlapLines: 2,
15028
15033
  embeddingModel: "base" /* BASE */,
15029
- vectorDimension: 384
15034
+ vectorDimension: EMBEDDING_MODEL_DIMENSIONS["base" /* BASE */]
15030
15035
  };
15031
15036
  var LOCK_RETRY_MS = 50;
15032
15037
  var LOCK_TIMEOUT_MS = 500;
@@ -15035,13 +15040,20 @@ var RRF_K = 60;
15035
15040
  // src/core/config/index.ts
15036
15041
  function resolveMemoryConfig(settings, workspaceRoot) {
15037
15042
  const override = settings.memory ?? {};
15043
+ const embeddingModel = isEmbeddingModelName(override.embeddingModel) ? override.embeddingModel : DEFAULT_MEMORY_CONFIG.embeddingModel;
15044
+ const vectorDimension = typeof override.vectorDimension === "number" && Number.isFinite(override.vectorDimension) && override.vectorDimension > 0 ? override.vectorDimension : EMBEDDING_MODEL_DIMENSIONS[embeddingModel];
15038
15045
  return {
15039
15046
  ...DEFAULT_MEMORY_CONFIG,
15040
15047
  ...override,
15041
15048
  enabled: override.enabled ?? DEFAULT_MEMORY_CONFIG.enabled,
15049
+ embeddingModel,
15050
+ vectorDimension,
15042
15051
  wikiDir: typeof override.wikiDir === "string" && override.wikiDir.length > 0 ? override.wikiDir : path3.join(workspaceRoot, ".agent-kit", "wiki")
15043
15052
  };
15044
15053
  }
15054
+ function isEmbeddingModelName(value) {
15055
+ return value === "tiny" /* TINY */ || value === "base" /* BASE */ || value === "large" /* LARGE */;
15056
+ }
15045
15057
  function getGlobalSettingsFile() {
15046
15058
  return path3.join(os.homedir(), ".agent-kit", "settings.json");
15047
15059
  }
@@ -15313,7 +15325,7 @@ var import_stopword = __toESM(require_stopword_cjs(), 1);
15313
15325
  import Database from "libsql";
15314
15326
  import * as fs5 from "fs";
15315
15327
  import * as path7 from "path";
15316
- var SCHEMA_VERSION = 3;
15328
+ var SCHEMA_VERSION = 4;
15317
15329
  var LibsqlDatabase = Database;
15318
15330
  var StoreError = class extends Error {
15319
15331
  constructor(message, cause) {
@@ -15356,7 +15368,8 @@ var MemoryStore = class {
15356
15368
  createSchema(db) {
15357
15369
  try {
15358
15370
  const current = this.readUserVersion(db);
15359
- if (current < SCHEMA_VERSION) {
15371
+ const currentVectorDimension = current >= SCHEMA_VERSION ? this.readEmbeddingColumnDimension(db) : void 0;
15372
+ if (current < SCHEMA_VERSION || currentVectorDimension !== void 0 && currentVectorDimension !== this.config.vectorDimension) {
15360
15373
  db.exec(`
15361
15374
  DROP TRIGGER IF EXISTS memory_chunks_ai;
15362
15375
  DROP TRIGGER IF EXISTS memory_chunks_ad;
@@ -15413,6 +15426,22 @@ var MemoryStore = class {
15413
15426
  throw new StoreError("schema migration failed", err);
15414
15427
  }
15415
15428
  }
15429
+ readEmbeddingColumnDimension(db) {
15430
+ try {
15431
+ const rows = db.pragma("table_info(memory_chunks)");
15432
+ if (!Array.isArray(rows)) return void 0;
15433
+ const embeddingColumn = rows.find((row) => {
15434
+ if (!row || typeof row !== "object") return false;
15435
+ const candidate = row;
15436
+ return candidate.name === "embedding" && typeof candidate.type === "string";
15437
+ });
15438
+ const match = /^F32_BLOB\((\d+)\)$/i.exec(embeddingColumn?.type.trim() ?? "");
15439
+ if (!match) return void 0;
15440
+ return Number.parseInt(match[1], 10);
15441
+ } catch {
15442
+ return void 0;
15443
+ }
15444
+ }
15416
15445
  readUserVersion(db) {
15417
15446
  const value = db.pragma("user_version", { simple: true });
15418
15447
  if (typeof value === "number") return value;
@@ -2,7 +2,7 @@
2
2
  * Configuration utilities
3
3
  * Shared configuration constants and loaders
4
4
  */
5
- import type { MemoryConfig } from '../../services/memory/types.js';
5
+ import { type MemoryConfig } from '../../services/memory/types.js';
6
6
  import type { ConversationDigestSettings } from '../../services/digest/types.js';
7
7
  /**
8
8
  * Default file extensions - expanded to support more languages
@@ -5,7 +5,8 @@
5
5
  import * as fs from 'fs';
6
6
  import * as os from 'os';
7
7
  import * as path from 'path';
8
- import { DEFAULT_MEMORY_CONFIG } from '../../services/memory/constants.js';
8
+ import { DEFAULT_MEMORY_CONFIG, EMBEDDING_MODEL_DIMENSIONS } from '../../services/memory/constants.js';
9
+ import { EmbeddingModelName } from '../../services/memory/types.js';
9
10
  import { atomicWriteJsonFile } from '../../utils/files.js';
10
11
  /**
11
12
  * Default file extensions - expanded to support more languages
@@ -40,15 +41,28 @@ export const DEFAULT_EXTENSIONS = [
40
41
  */
41
42
  export function resolveMemoryConfig(settings, workspaceRoot) {
42
43
  const override = settings.memory ?? {};
44
+ const embeddingModel = isEmbeddingModelName(override.embeddingModel)
45
+ ? override.embeddingModel
46
+ : DEFAULT_MEMORY_CONFIG.embeddingModel;
47
+ const vectorDimension = typeof override.vectorDimension === 'number' &&
48
+ Number.isFinite(override.vectorDimension) &&
49
+ override.vectorDimension > 0
50
+ ? override.vectorDimension
51
+ : EMBEDDING_MODEL_DIMENSIONS[embeddingModel];
43
52
  return {
44
53
  ...DEFAULT_MEMORY_CONFIG,
45
54
  ...override,
46
55
  enabled: override.enabled ?? DEFAULT_MEMORY_CONFIG.enabled,
56
+ embeddingModel,
57
+ vectorDimension,
47
58
  wikiDir: typeof override.wikiDir === 'string' && override.wikiDir.length > 0
48
59
  ? override.wikiDir
49
60
  : path.join(workspaceRoot, '.agent-kit', 'wiki'),
50
61
  };
51
62
  }
63
+ function isEmbeddingModelName(value) {
64
+ return value === EmbeddingModelName.TINY || value === EmbeddingModelName.BASE || value === EmbeddingModelName.LARGE;
65
+ }
52
66
  export function loadProjectSettings(projectDir) {
53
67
  const settingsPath = path.join(projectDir, '.agent-kit', 'settings.json');
54
68
  if (fs.existsSync(settingsPath)) {
package/dist/server.js CHANGED
@@ -35903,6 +35903,11 @@ import * as path2 from "path";
35903
35903
  var SOURCE_TYPES = ["digest", "concept", "entity", "preference", "wiki"];
35904
35904
 
35905
35905
  // src/services/memory/constants.ts
35906
+ var EMBEDDING_MODEL_DIMENSIONS = {
35907
+ ["tiny" /* TINY */]: 384,
35908
+ ["base" /* BASE */]: 384,
35909
+ ["large" /* LARGE */]: 768
35910
+ };
35906
35911
  var DEFAULT_MEMORY_CONFIG = {
35907
35912
  enabled: false,
35908
35913
  wikiDir: "",
@@ -35910,7 +35915,7 @@ var DEFAULT_MEMORY_CONFIG = {
35910
35915
  chunkSize: 1500,
35911
35916
  overlapLines: 2,
35912
35917
  embeddingModel: "base" /* BASE */,
35913
- vectorDimension: 384
35918
+ vectorDimension: EMBEDDING_MODEL_DIMENSIONS["base" /* BASE */]
35914
35919
  };
35915
35920
  var LOCK_RETRY_MS = 50;
35916
35921
  var LOCK_TIMEOUT_MS = 500;
@@ -35985,13 +35990,20 @@ function tryAcquireProcessLock(lockPath) {
35985
35990
  // src/core/config/index.ts
35986
35991
  function resolveMemoryConfig(settings, workspaceRoot2) {
35987
35992
  const override = settings.memory ?? {};
35993
+ const embeddingModel = isEmbeddingModelName(override.embeddingModel) ? override.embeddingModel : DEFAULT_MEMORY_CONFIG.embeddingModel;
35994
+ const vectorDimension = typeof override.vectorDimension === "number" && Number.isFinite(override.vectorDimension) && override.vectorDimension > 0 ? override.vectorDimension : EMBEDDING_MODEL_DIMENSIONS[embeddingModel];
35988
35995
  return {
35989
35996
  ...DEFAULT_MEMORY_CONFIG,
35990
35997
  ...override,
35991
35998
  enabled: override.enabled ?? DEFAULT_MEMORY_CONFIG.enabled,
35999
+ embeddingModel,
36000
+ vectorDimension,
35992
36001
  wikiDir: typeof override.wikiDir === "string" && override.wikiDir.length > 0 ? override.wikiDir : path2.join(workspaceRoot2, ".agent-kit", "wiki")
35993
36002
  };
35994
36003
  }
36004
+ function isEmbeddingModelName(value) {
36005
+ return value === "tiny" /* TINY */ || value === "base" /* BASE */ || value === "large" /* LARGE */;
36006
+ }
35995
36007
  function getGlobalSettingsFile() {
35996
36008
  return path2.join(os.homedir(), ".agent-kit", "settings.json");
35997
36009
  }
@@ -37178,7 +37190,7 @@ var import_stopword = __toESM(require_stopword_cjs(), 1);
37178
37190
  import Database from "libsql";
37179
37191
  import * as fs7 from "fs";
37180
37192
  import * as path9 from "path";
37181
- var SCHEMA_VERSION = 3;
37193
+ var SCHEMA_VERSION = 4;
37182
37194
  var LibsqlDatabase = Database;
37183
37195
  var StoreError = class extends Error {
37184
37196
  constructor(message, cause) {
@@ -37221,7 +37233,8 @@ var MemoryStore = class {
37221
37233
  createSchema(db) {
37222
37234
  try {
37223
37235
  const current = this.readUserVersion(db);
37224
- if (current < SCHEMA_VERSION) {
37236
+ const currentVectorDimension = current >= SCHEMA_VERSION ? this.readEmbeddingColumnDimension(db) : void 0;
37237
+ if (current < SCHEMA_VERSION || currentVectorDimension !== void 0 && currentVectorDimension !== this.config.vectorDimension) {
37225
37238
  db.exec(`
37226
37239
  DROP TRIGGER IF EXISTS memory_chunks_ai;
37227
37240
  DROP TRIGGER IF EXISTS memory_chunks_ad;
@@ -37278,6 +37291,22 @@ var MemoryStore = class {
37278
37291
  throw new StoreError("schema migration failed", err);
37279
37292
  }
37280
37293
  }
37294
+ readEmbeddingColumnDimension(db) {
37295
+ try {
37296
+ const rows = db.pragma("table_info(memory_chunks)");
37297
+ if (!Array.isArray(rows)) return void 0;
37298
+ const embeddingColumn = rows.find((row) => {
37299
+ if (!row || typeof row !== "object") return false;
37300
+ const candidate = row;
37301
+ return candidate.name === "embedding" && typeof candidate.type === "string";
37302
+ });
37303
+ const match = /^F32_BLOB\((\d+)\)$/i.exec(embeddingColumn?.type.trim() ?? "");
37304
+ if (!match) return void 0;
37305
+ return Number.parseInt(match[1], 10);
37306
+ } catch {
37307
+ return void 0;
37308
+ }
37309
+ }
37281
37310
  readUserVersion(db) {
37282
37311
  const value = db.pragma("user_version", { simple: true });
37283
37312
  if (typeof value === "number") return value;
@@ -1,4 +1,5 @@
1
- import { type MemoryConfig } from './types.js';
1
+ import { type MemoryConfig, EmbeddingModelName } from './types.js';
2
+ export declare const EMBEDDING_MODEL_DIMENSIONS: Record<EmbeddingModelName, number>;
2
3
  export declare const DEFAULT_MEMORY_CONFIG: MemoryConfig;
3
4
  export declare const LOCK_RETRY_MS = 50;
4
5
  export declare const LOCK_TIMEOUT_MS = 500;
@@ -1,4 +1,9 @@
1
1
  import { EmbeddingModelName } from './types.js';
2
+ export const EMBEDDING_MODEL_DIMENSIONS = {
3
+ [EmbeddingModelName.TINY]: 384,
4
+ [EmbeddingModelName.BASE]: 384,
5
+ [EmbeddingModelName.LARGE]: 768,
6
+ };
2
7
  export const DEFAULT_MEMORY_CONFIG = {
3
8
  enabled: false,
4
9
  wikiDir: '',
@@ -6,7 +11,7 @@ export const DEFAULT_MEMORY_CONFIG = {
6
11
  chunkSize: 1500,
7
12
  overlapLines: 2,
8
13
  embeddingModel: EmbeddingModelName.BASE,
9
- vectorDimension: 384,
14
+ vectorDimension: EMBEDDING_MODEL_DIMENSIONS[EmbeddingModelName.BASE],
10
15
  };
11
16
  export const LOCK_RETRY_MS = 50;
12
17
  export const LOCK_TIMEOUT_MS = 500;
@@ -402,4 +402,14 @@ describe('resolveMemoryConfig', () => {
402
402
  const config = resolveMemoryConfig({ memory: { wikiDir: '/custom/wiki' } }, '/repo');
403
403
  assert.equal(config.wikiDir, '/custom/wiki');
404
404
  });
405
+ test('derives vector dimension from embedding model', () => {
406
+ const config = resolveMemoryConfig({ memory: { embeddingModel: EmbeddingModelName.LARGE } }, '/repo');
407
+ assert.equal(config.embeddingModel, EmbeddingModelName.LARGE);
408
+ assert.equal(config.vectorDimension, 768);
409
+ });
410
+ test('preserves explicit vector dimension override', () => {
411
+ const config = resolveMemoryConfig({ memory: { embeddingModel: EmbeddingModelName.LARGE, vectorDimension: 1024 } }, '/repo');
412
+ assert.equal(config.embeddingModel, EmbeddingModelName.LARGE);
413
+ assert.equal(config.vectorDimension, 1024);
414
+ });
405
415
  });
@@ -1,5 +1,5 @@
1
1
  import type { MemoryChunk, MemoryConfig, RecentSource, SourceType } from './types.js';
2
- export declare const SCHEMA_VERSION = 3;
2
+ export declare const SCHEMA_VERSION = 4;
3
3
  export declare class StoreError extends Error {
4
4
  constructor(message: string, cause?: unknown);
5
5
  }
@@ -9,6 +9,7 @@ export declare class MemoryStore {
9
9
  constructor(dbPath: string, config: MemoryConfig);
10
10
  private openDatabase;
11
11
  private createSchema;
12
+ private readEmbeddingColumnDimension;
12
13
  private readUserVersion;
13
14
  upsert(chunks: MemoryChunk[], embeddings: Float32Array[]): void;
14
15
  private toVectorBinding;
@@ -2,7 +2,7 @@ import Database from 'libsql';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
4
  import { eng, removeStopwords } from 'stopword';
5
- export const SCHEMA_VERSION = 3;
5
+ export const SCHEMA_VERSION = 4;
6
6
  const LibsqlDatabase = Database;
7
7
  export class StoreError extends Error {
8
8
  constructor(message, cause) {
@@ -51,7 +51,9 @@ export class MemoryStore {
51
51
  createSchema(db) {
52
52
  try {
53
53
  const current = this.readUserVersion(db);
54
- if (current < SCHEMA_VERSION) {
54
+ const currentVectorDimension = current >= SCHEMA_VERSION ? this.readEmbeddingColumnDimension(db) : undefined;
55
+ if (current < SCHEMA_VERSION ||
56
+ (currentVectorDimension !== undefined && currentVectorDimension !== this.config.vectorDimension)) {
55
57
  db.exec(`
56
58
  DROP TRIGGER IF EXISTS memory_chunks_ai;
57
59
  DROP TRIGGER IF EXISTS memory_chunks_ad;
@@ -109,6 +111,26 @@ export class MemoryStore {
109
111
  throw new StoreError('schema migration failed', err);
110
112
  }
111
113
  }
114
+ readEmbeddingColumnDimension(db) {
115
+ try {
116
+ const rows = db.pragma('table_info(memory_chunks)');
117
+ if (!Array.isArray(rows))
118
+ return undefined;
119
+ const embeddingColumn = rows.find((row) => {
120
+ if (!row || typeof row !== 'object')
121
+ return false;
122
+ const candidate = row;
123
+ return candidate.name === 'embedding' && typeof candidate.type === 'string';
124
+ });
125
+ const match = /^F32_BLOB\((\d+)\)$/i.exec(embeddingColumn?.type.trim() ?? '');
126
+ if (!match)
127
+ return undefined;
128
+ return Number.parseInt(match[1], 10);
129
+ }
130
+ catch {
131
+ return undefined;
132
+ }
133
+ }
112
134
  readUserVersion(db) {
113
135
  const value = db.pragma('user_version', { simple: true });
114
136
  if (typeof value === 'number')
@@ -387,4 +387,47 @@ describe('MemoryStore', () => {
387
387
  fs.rmSync(migrationDir, { recursive: true, force: true });
388
388
  }
389
389
  });
390
+ test('recreates schema when existing vector dimension differs from config', () => {
391
+ const dimensionDir = fs.mkdtempSync(path.join(os.tmpdir(), 'memory-dimension-migration-'));
392
+ const dimensionDbPath = path.join(dimensionDir, 'index.db');
393
+ const baseStore = new MemoryStore(dimensionDbPath, { ...TEST_CONFIG, wikiDir: dimensionDir });
394
+ try {
395
+ baseStore.upsert([makeChunk({ id: 'old-dimension-row', source: 'dimension.md' })], [makeEmbedding(17)]);
396
+ }
397
+ finally {
398
+ baseStore.close();
399
+ }
400
+ const largeConfig = {
401
+ ...TEST_CONFIG,
402
+ wikiDir: dimensionDir,
403
+ embeddingModel: EmbeddingModelName.LARGE,
404
+ vectorDimension: 768,
405
+ };
406
+ const largeStore = new MemoryStore(dimensionDbPath, largeConfig);
407
+ try {
408
+ const verifyDb = new Database(dimensionDbPath, { readonly: true });
409
+ try {
410
+ const columns = verifyDb.prepare(`PRAGMA table_info(memory_chunks)`).all();
411
+ const embeddingColumn = columns.find((column) => column.name === 'embedding');
412
+ assert.equal(embeddingColumn?.type, 'F32_BLOB(768)');
413
+ const rowCount = verifyDb.prepare(`SELECT COUNT(*) AS count FROM memory_chunks`).get();
414
+ assert.equal(rowCount.count, 0);
415
+ }
416
+ finally {
417
+ verifyDb.close();
418
+ }
419
+ const chunk = makeChunk({
420
+ id: 'new-dimension-row',
421
+ source: 'dimension.md',
422
+ content: 'large dimension vector can be indexed',
423
+ });
424
+ largeStore.upsert([chunk], [makeEmbedding(18, 768)]);
425
+ const results = largeStore.searchBm25('large dimension vector', 5);
426
+ assert.ok(results.some((result) => result.id === 'new-dimension-row'));
427
+ }
428
+ finally {
429
+ largeStore.close();
430
+ fs.rmSync(dimensionDir, { recursive: true, force: true });
431
+ }
432
+ });
390
433
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanhnd/agent-kit",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "description": "Agent Kit MCP server for software development agent workflows",
5
5
  "type": "module",
6
6
  "main": "dist/server.js",