context-vault 3.4.2 → 3.4.4

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 (33) hide show
  1. package/dist/server.js +127 -27
  2. package/dist/server.js.map +1 -1
  3. package/dist/tools/get-context.d.ts +2 -1
  4. package/dist/tools/get-context.d.ts.map +1 -1
  5. package/dist/tools/get-context.js +22 -2
  6. package/dist/tools/get-context.js.map +1 -1
  7. package/dist/tools/save-context.d.ts +2 -1
  8. package/dist/tools/save-context.d.ts.map +1 -1
  9. package/dist/tools/save-context.js +63 -2
  10. package/dist/tools/save-context.js.map +1 -1
  11. package/node_modules/@context-vault/core/dist/context.d.ts +34 -0
  12. package/node_modules/@context-vault/core/dist/context.d.ts.map +1 -0
  13. package/node_modules/@context-vault/core/dist/context.js +55 -0
  14. package/node_modules/@context-vault/core/dist/context.js.map +1 -0
  15. package/node_modules/@context-vault/core/dist/db.d.ts +3 -1
  16. package/node_modules/@context-vault/core/dist/db.d.ts.map +1 -1
  17. package/node_modules/@context-vault/core/dist/db.js +29 -2
  18. package/node_modules/@context-vault/core/dist/db.js.map +1 -1
  19. package/node_modules/@context-vault/core/dist/search.d.ts +1 -0
  20. package/node_modules/@context-vault/core/dist/search.d.ts.map +1 -1
  21. package/node_modules/@context-vault/core/dist/search.js +57 -3
  22. package/node_modules/@context-vault/core/dist/search.js.map +1 -1
  23. package/node_modules/@context-vault/core/dist/types.d.ts +6 -0
  24. package/node_modules/@context-vault/core/dist/types.d.ts.map +1 -1
  25. package/node_modules/@context-vault/core/package.json +5 -1
  26. package/node_modules/@context-vault/core/src/context.ts +65 -0
  27. package/node_modules/@context-vault/core/src/db.ts +29 -2
  28. package/node_modules/@context-vault/core/src/search.ts +54 -2
  29. package/node_modules/@context-vault/core/src/types.ts +6 -0
  30. package/package.json +2 -2
  31. package/src/server.ts +133 -27
  32. package/src/tools/get-context.ts +25 -1
  33. package/src/tools/save-context.ts +62 -1
@@ -3,6 +3,7 @@ import { captureAndIndex, updateEntryFile } from '@context-vault/core/capture';
3
3
  import { indexEntry } from '@context-vault/core/index';
4
4
  import { categoryFor, defaultTierFor } from '@context-vault/core/categories';
5
5
  import { normalizeKind } from '@context-vault/core/files';
6
+ import { parseContextParam } from '@context-vault/core/context';
6
7
  import { ok, err, errWithHint, ensureVaultExists, ensureValidKind } from '../helpers.js';
7
8
  import { maybeShowFeedbackPrompt } from '../telemetry.js';
8
9
  import { validateRelatedTo } from '../linking.js';
@@ -310,6 +311,12 @@ export const inputSchema = {
310
311
  .describe(
311
312
  'Conflict resolution mode. "suggest" (default): when similar entries are found, return structured conflict_candidates with suggested_action (ADD/UPDATE/SKIP) and reasoning_context for the calling agent to decide. Thresholds: score > 0.95 → SKIP (near-duplicate), score > 0.85 → UPDATE (very similar), score < 0.85 → ADD (distinct enough). "off": flag similar entries only (legacy behavior).'
312
313
  ),
314
+ encoding_context: z
315
+ .any()
316
+ .optional()
317
+ .describe(
318
+ 'Encoding context for contextual reinstatement. Captures the situation when this entry was created, enabling context-aware retrieval boosting. Pass a structured object (e.g. { project: "myapp", arc: "auth-rewrite", task: "implementing JWT" }) or a free-text string describing the current context.'
319
+ ),
313
320
  };
314
321
 
315
322
  export async function handler(
@@ -331,6 +338,7 @@ export async function handler(
331
338
  similarity_threshold,
332
339
  tier,
333
340
  conflict_resolution,
341
+ encoding_context,
334
342
  }: Record<string, any>,
335
343
  ctx: LocalCtx,
336
344
  { ensureIndexed }: SharedCtx
@@ -388,13 +396,21 @@ export async function handler(
388
396
  );
389
397
  }
390
398
 
399
+ // Merge encoding context into meta for update path
400
+ const updateParsedCtx = parseContextParam(encoding_context);
401
+ let updateMeta = meta;
402
+ if (updateParsedCtx) {
403
+ updateMeta = { ...(meta || {}) };
404
+ updateMeta.encoding_context = updateParsedCtx.structured || updateParsedCtx.text;
405
+ }
406
+
391
407
  let entry;
392
408
  try {
393
409
  entry = updateEntryFile(ctx, existing, {
394
410
  title,
395
411
  body,
396
412
  tags,
397
- meta,
413
+ meta: updateMeta,
398
414
  source,
399
415
  expires_at,
400
416
  supersedes,
@@ -409,6 +425,24 @@ export async function handler(
409
425
  'context-vault save_context update is failing. Check `cat ~/.context-mcp/error.log | tail -5` and help me debug.'
410
426
  );
411
427
  }
428
+
429
+ // Store context embedding for updated entry
430
+ if (updateParsedCtx?.text) {
431
+ try {
432
+ const ctxEmbed = await ctx.embed(updateParsedCtx.text);
433
+ if (ctxEmbed) {
434
+ const rowidResult = ctx.stmts.getRowid.get(entry.id) as { rowid: number } | undefined;
435
+ if (rowidResult?.rowid) {
436
+ const rowid = Number(rowidResult.rowid);
437
+ try { ctx.deleteCtxVec(rowid); } catch {}
438
+ ctx.insertCtxVec(rowid, ctxEmbed);
439
+ }
440
+ }
441
+ } catch (e) {
442
+ console.warn(`[context-vault] Context embedding update failed: ${(e as Error).message}`);
443
+ }
444
+ }
445
+
412
446
  if (entry.related_to?.length && ctx.stmts.updateRelatedTo) {
413
447
  ctx.stmts.updateRelatedTo.run(JSON.stringify(entry.related_to), entry.id);
414
448
  } else if (entry.related_to === null && ctx.stmts.updateRelatedTo) {
@@ -502,6 +536,15 @@ export async function handler(
502
536
 
503
537
  const mergedMeta = { ...(meta || {}) };
504
538
  if (folder) mergedMeta.folder = folder;
539
+
540
+ // Merge encoding context into meta for persistence
541
+ const parsedCtx = parseContextParam(encoding_context);
542
+ if (parsedCtx?.structured) {
543
+ mergedMeta.encoding_context = parsedCtx.structured;
544
+ } else if (parsedCtx?.text) {
545
+ mergedMeta.encoding_context = parsedCtx.text;
546
+ }
547
+
505
548
  const finalMeta = Object.keys(mergedMeta).length ? mergedMeta : undefined;
506
549
 
507
550
  const effectiveTier = tier ?? defaultTierFor(normalizedKind);
@@ -538,6 +581,24 @@ export async function handler(
538
581
  );
539
582
  }
540
583
 
584
+ // Store context embedding in vault_ctx_vec for contextual reinstatement
585
+ if (parsedCtx?.text && entry) {
586
+ try {
587
+ const ctxEmbedding = await ctx.embed(parsedCtx.text);
588
+ if (ctxEmbedding) {
589
+ const rowidResult = ctx.stmts.getRowid.get(entry.id) as { rowid: number } | undefined;
590
+ if (rowidResult?.rowid) {
591
+ const rowid = Number(rowidResult.rowid);
592
+ try { ctx.deleteCtxVec(rowid); } catch {}
593
+ ctx.insertCtxVec(rowid, ctxEmbedding);
594
+ }
595
+ }
596
+ } catch (e) {
597
+ // Non-fatal: context embedding failure should not block the save
598
+ console.warn(`[context-vault] Context embedding failed: ${(e as Error).message}`);
599
+ }
600
+ }
601
+
541
602
  if (ctx.config?.dataDir) {
542
603
  maybeShowFeedbackPrompt(ctx.config.dataDir);
543
604
  }