@orquentra/codebuddy 2.6.2 → 2.7.0

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 (104) hide show
  1. package/dist/{chunk-IBLJOHJL.js → chunk-3QGW53GD.js} +2 -2
  2. package/dist/{chunk-NERKZSSE.js → chunk-5EDGAZQN.js} +438 -68
  3. package/dist/chunk-5EDGAZQN.js.map +1 -0
  4. package/dist/{chunk-JFDRBPYF.js → chunk-6JCKMIQY.js} +2 -2
  5. package/dist/{chunk-2XDPKFUW.js → chunk-AK2UAE32.js} +46 -20
  6. package/dist/chunk-AK2UAE32.js.map +1 -0
  7. package/dist/{chunk-GDJH7XJC.js → chunk-AL6VBTNA.js} +77 -3
  8. package/dist/chunk-AL6VBTNA.js.map +1 -0
  9. package/dist/{chunk-QBDJXGG5.js → chunk-AQHPEJR6.js} +93 -22
  10. package/dist/chunk-AQHPEJR6.js.map +1 -0
  11. package/dist/{chunk-OWWCDRXW.js → chunk-BQM7FJ7D.js} +6 -6
  12. package/dist/chunk-BQM7FJ7D.js.map +1 -0
  13. package/dist/{chunk-XBJQKCLU.js → chunk-CAEPHLHC.js} +13 -9
  14. package/dist/chunk-CAEPHLHC.js.map +1 -0
  15. package/dist/chunk-CG5B3LYG.js +66 -0
  16. package/dist/chunk-CG5B3LYG.js.map +1 -0
  17. package/dist/{chunk-IHQM2ZDV.js → chunk-DFV2SK6C.js} +1 -1
  18. package/dist/{chunk-IHQM2ZDV.js.map → chunk-DFV2SK6C.js.map} +1 -1
  19. package/dist/{chunk-IMFUYEZA.js → chunk-EEUFU7KV.js} +81 -54
  20. package/dist/chunk-EEUFU7KV.js.map +1 -0
  21. package/dist/{chunk-5MQOE4J6.js → chunk-ESZXCZIN.js} +3 -3
  22. package/dist/{chunk-J2EAZ4MA.js → chunk-GKNYMNFM.js} +22 -25
  23. package/dist/chunk-GKNYMNFM.js.map +1 -0
  24. package/dist/{chunk-JPHJBCZB.js → chunk-HPOR6YXA.js} +3 -2
  25. package/dist/chunk-HPOR6YXA.js.map +1 -0
  26. package/dist/{chunk-S6VEG4S2.js → chunk-JUAFCLRB.js} +28 -5
  27. package/dist/chunk-JUAFCLRB.js.map +1 -0
  28. package/dist/{chunk-5KZY6OTG.js → chunk-KNR2P2UY.js} +33 -83
  29. package/dist/chunk-KNR2P2UY.js.map +1 -0
  30. package/dist/{chunk-B6CO63SQ.js → chunk-LCSBL5TT.js} +21 -9
  31. package/dist/chunk-LCSBL5TT.js.map +1 -0
  32. package/dist/{chunk-5FW3PMNP.js → chunk-MSUAVR3R.js} +76 -11
  33. package/dist/chunk-MSUAVR3R.js.map +1 -0
  34. package/dist/{chunk-RAJJSCIP.js → chunk-SFMIMLXR.js} +2 -2
  35. package/dist/chunk-TGFTKWOR.js +16 -0
  36. package/dist/chunk-TGFTKWOR.js.map +1 -0
  37. package/dist/chunk-TUR6YKEE.js +55 -0
  38. package/dist/chunk-TUR6YKEE.js.map +1 -0
  39. package/dist/chunk-Y7D7PUBE.js +321 -0
  40. package/dist/chunk-Y7D7PUBE.js.map +1 -0
  41. package/dist/{chunk-R7CD6EXS.js → chunk-YJIA2MFL.js} +572 -377
  42. package/dist/chunk-YJIA2MFL.js.map +1 -0
  43. package/dist/cli/index.js +5 -5
  44. package/dist/cli/index.js.map +1 -1
  45. package/dist/{cloud-7WM3YLI4.js → cloud-LXZUR3U2.js} +3 -3
  46. package/dist/{codebuddy-B_pCaQrV.d.ts → codebuddy-DO7ZhoWn.d.ts} +15 -1
  47. package/dist/config-GEZFLXK6.js +12 -0
  48. package/dist/index.d.ts +46 -3
  49. package/dist/index.js +22 -19
  50. package/dist/langgraph/index.d.ts +1 -1
  51. package/dist/lean-command-CWJAVQ5G.js +18 -0
  52. package/dist/{local-5MZURLCZ.js → local-ST4WMRCG.js} +3 -3
  53. package/dist/{main-MTBQZGJV.js → main-AHNGHC4L.js} +213 -183
  54. package/dist/main-AHNGHC4L.js.map +1 -0
  55. package/dist/{memory-KIC5FJVW.js → memory-TGHVTBME.js} +9 -8
  56. package/dist/memory-TGHVTBME.js.map +1 -0
  57. package/dist/operations-7BTAAUHF.js +26 -0
  58. package/dist/pretool-command-3SXQSMAO.js +13 -0
  59. package/dist/{rerank-5QZ3PNUW.js → rerank-IQAEWLQR.js} +6 -5
  60. package/dist/rerank-IQAEWLQR.js.map +1 -0
  61. package/dist/{runtime-CUBOOPZO.js → runtime-E7JQZ2BZ.js} +14 -11
  62. package/dist/summaries-XV3JGGCC.js +20 -0
  63. package/dist/{zvec-MSRKT7IV.js → zvec-KP4KNB7Y.js} +10 -3
  64. package/package.json +1 -1
  65. package/src/db/migrations/0006_fact_idempotency_key.sql +2 -0
  66. package/src/db/migrations/meta/0006_snapshot.json +1258 -0
  67. package/src/db/migrations/meta/_journal.json +7 -0
  68. package/dist/chunk-2XDPKFUW.js.map +0 -1
  69. package/dist/chunk-5FW3PMNP.js.map +0 -1
  70. package/dist/chunk-5KZY6OTG.js.map +0 -1
  71. package/dist/chunk-B6CO63SQ.js.map +0 -1
  72. package/dist/chunk-GDJH7XJC.js.map +0 -1
  73. package/dist/chunk-IMFUYEZA.js.map +0 -1
  74. package/dist/chunk-J2EAZ4MA.js.map +0 -1
  75. package/dist/chunk-JPHJBCZB.js.map +0 -1
  76. package/dist/chunk-NERKZSSE.js.map +0 -1
  77. package/dist/chunk-OWWCDRXW.js.map +0 -1
  78. package/dist/chunk-PQK3GKZH.js +0 -98
  79. package/dist/chunk-PQK3GKZH.js.map +0 -1
  80. package/dist/chunk-QBDJXGG5.js.map +0 -1
  81. package/dist/chunk-R7CD6EXS.js.map +0 -1
  82. package/dist/chunk-S6VEG4S2.js.map +0 -1
  83. package/dist/chunk-XBJQKCLU.js.map +0 -1
  84. package/dist/config-DEVHUDIU.js +0 -11
  85. package/dist/lean-command-HTQCPH76.js +0 -15
  86. package/dist/main-MTBQZGJV.js.map +0 -1
  87. package/dist/memory-KIC5FJVW.js.map +0 -1
  88. package/dist/operations-POCHY3WR.js +0 -25
  89. package/dist/pretool-command-AX6JXP25.js +0 -10
  90. package/dist/rerank-5QZ3PNUW.js.map +0 -1
  91. package/dist/summaries-SB5L2TSW.js +0 -18
  92. /package/dist/{chunk-IBLJOHJL.js.map → chunk-3QGW53GD.js.map} +0 -0
  93. /package/dist/{chunk-JFDRBPYF.js.map → chunk-6JCKMIQY.js.map} +0 -0
  94. /package/dist/{chunk-5MQOE4J6.js.map → chunk-ESZXCZIN.js.map} +0 -0
  95. /package/dist/{chunk-RAJJSCIP.js.map → chunk-SFMIMLXR.js.map} +0 -0
  96. /package/dist/{cloud-7WM3YLI4.js.map → cloud-LXZUR3U2.js.map} +0 -0
  97. /package/dist/{config-DEVHUDIU.js.map → config-GEZFLXK6.js.map} +0 -0
  98. /package/dist/{lean-command-HTQCPH76.js.map → lean-command-CWJAVQ5G.js.map} +0 -0
  99. /package/dist/{local-5MZURLCZ.js.map → local-ST4WMRCG.js.map} +0 -0
  100. /package/dist/{operations-POCHY3WR.js.map → operations-7BTAAUHF.js.map} +0 -0
  101. /package/dist/{pretool-command-AX6JXP25.js.map → pretool-command-3SXQSMAO.js.map} +0 -0
  102. /package/dist/{runtime-CUBOOPZO.js.map → runtime-E7JQZ2BZ.js.map} +0 -0
  103. /package/dist/{summaries-SB5L2TSW.js.map → summaries-XV3JGGCC.js.map} +0 -0
  104. /package/dist/{zvec-MSRKT7IV.js.map → zvec-KP4KNB7Y.js.map} +0 -0
@@ -13,11 +13,7 @@ import {
13
13
  sessionSummaries,
14
14
  shares,
15
15
  validSearchVector
16
- } from "./chunk-S6VEG4S2.js";
17
- import {
18
- REDACTED,
19
- redactPersisted
20
- } from "./chunk-GDJH7XJC.js";
16
+ } from "./chunk-JUAFCLRB.js";
21
17
  import {
22
18
  clampBudgetForCallerModel,
23
19
  computeContentHash,
@@ -25,13 +21,17 @@ import {
25
21
  countTokens,
26
22
  generateEntityId,
27
23
  generateSessionId
28
- } from "./chunk-XBJQKCLU.js";
24
+ } from "./chunk-CAEPHLHC.js";
29
25
  import {
30
26
  OpenRouterEmbeddingProvider
31
- } from "./chunk-JFDRBPYF.js";
27
+ } from "./chunk-6JCKMIQY.js";
32
28
  import {
33
29
  LocalModelProvider
34
- } from "./chunk-IBLJOHJL.js";
30
+ } from "./chunk-3QGW53GD.js";
31
+ import {
32
+ REDACTED,
33
+ redactPersisted
34
+ } from "./chunk-AL6VBTNA.js";
35
35
  import {
36
36
  DEFAULT_CLOUD_EMBEDDING_MODELS,
37
37
  DEFAULT_EMBEDDING_MODELS,
@@ -39,7 +39,7 @@ import {
39
39
  EMBEDDING_DIMENSIONS,
40
40
  assertCompatibleEmbeddingModels,
41
41
  getModelDefinition
42
- } from "./chunk-JPHJBCZB.js";
42
+ } from "./chunk-HPOR6YXA.js";
43
43
  import {
44
44
  MISSING_DATABASE_URL,
45
45
  checkConfigPermissions,
@@ -49,7 +49,7 @@ import {
49
49
  migrateLegacyNamespace,
50
50
  readConfigFile,
51
51
  redactSecrets
52
- } from "./chunk-5KZY6OTG.js";
52
+ } from "./chunk-KNR2P2UY.js";
53
53
 
54
54
  // src/db/bootstrap.ts
55
55
  async function enablePgvector(sql2) {
@@ -252,12 +252,20 @@ var PostgresMemoryRepository = class {
252
252
  }
253
253
  async writeFact(input) {
254
254
  return this.db.transaction(async (tx) => {
255
+ const key = input.fact.idempotencyKey;
255
256
  const existing = await tx.select({ id: facts.id }).from(facts).where(
256
257
  and(
257
258
  eq(facts.namespaceId, input.fact.namespaceId),
258
- eq(facts.contentHash, input.fact.contentHash)
259
+ key ? (
260
+ // Rows written before 0006 stored the key as their content hash.
261
+ or(
262
+ eq(facts.idempotencyKey, key),
263
+ eq(facts.contentHash, key),
264
+ eq(facts.contentHash, input.fact.contentHash)
265
+ )
266
+ ) : eq(facts.contentHash, input.fact.contentHash)
259
267
  )
260
- ).limit(1);
268
+ ).orderBy(key ? sql`(${facts.idempotencyKey} = ${key}) desc nulls last` : facts.id).limit(1);
261
269
  const existingRow = existing[0];
262
270
  if (existingRow) {
263
271
  return {
@@ -280,6 +288,7 @@ var PostgresMemoryRepository = class {
280
288
  content: input.fact.content,
281
289
  contentHash: input.fact.contentHash,
282
290
  propositionKey: input.fact.propositionKey ?? null,
291
+ idempotencyKey: input.fact.idempotencyKey ?? null,
283
292
  confidence: String(input.fact.confidence ?? 1),
284
293
  sourceDeleted: input.fact.sourceDeleted ?? false,
285
294
  supersededBy: input.fact.supersededBy ?? null,
@@ -370,6 +379,7 @@ var PostgresMemoryRepository = class {
370
379
  sourceDeleted: fact.sourceDeleted,
371
380
  supersededBy: fact.supersededBy,
372
381
  propositionKey: fact.propositionKey ?? null,
382
+ idempotencyKey: fact.idempotencyKey ?? null,
373
383
  createdByAgent: fact.createdByAgent ?? null,
374
384
  createdAt: fact.createdAt,
375
385
  fileBacked: true
@@ -381,7 +391,7 @@ var PostgresMemoryRepository = class {
381
391
  return { status: "inserted" };
382
392
  }
383
393
  const contentChanged = existing.content !== fact.content;
384
- const metadataChanged = existing.subject !== values.subject || existing.predicate !== values.predicate || existing.object !== values.object || Number(existing.confidence) !== Number(fact.confidence.toFixed(4)) || existing.sourceInteractionId !== values.sourceInteractionId || existing.sourceDeleted !== values.sourceDeleted || existing.supersededBy !== values.supersededBy || existing.propositionKey !== values.propositionKey || existing.createdByAgent !== values.createdByAgent || existing.createdAt.getTime() !== values.createdAt.getTime();
394
+ const metadataChanged = existing.subject !== values.subject || existing.predicate !== values.predicate || existing.object !== values.object || Number(existing.confidence) !== Number(fact.confidence.toFixed(4)) || existing.sourceInteractionId !== values.sourceInteractionId || existing.sourceDeleted !== values.sourceDeleted || existing.supersededBy !== values.supersededBy || existing.propositionKey !== values.propositionKey || existing.idempotencyKey !== values.idempotencyKey || existing.createdByAgent !== values.createdByAgent || existing.createdAt.getTime() !== values.createdAt.getTime();
385
395
  if (contentChanged || metadataChanged || !existing.fileBacked) {
386
396
  await tx.update(facts).set({ ...values, updatedAt: sql`now()` }).where(and(eq(facts.namespaceId, fact.namespaceId), eq(facts.id, fact.id)));
387
397
  }
@@ -1358,8 +1368,10 @@ var DefaultPolicy = class {
1358
1368
  if (!isEligibleMemory(fact)) continue;
1359
1369
  const candidate = factCandidate(fact, useFallback ? fact.score : 0.35 * fact.score);
1360
1370
  const existing = byKey.get(candidate.key);
1361
- if (existing) existing.score = Math.max(existing.score, candidate.score);
1362
- else byKey.set(candidate.key, candidate);
1371
+ if (existing) {
1372
+ existing.score = Math.max(existing.score, candidate.score);
1373
+ existing.lexical = true;
1374
+ } else byKey.set(candidate.key, { ...candidate, lexical: true });
1363
1375
  }
1364
1376
  candidates = [...byKey.values()];
1365
1377
  candidates = this.applyRecencyFloor(candidates, recencyInteractions);
@@ -1379,7 +1391,8 @@ var DefaultPolicy = class {
1379
1391
  itemsSkipped += 1;
1380
1392
  continue;
1381
1393
  }
1382
- if (!candidate.isRecencyFloor && candidate.score < this.minVectorScore && !useFallback) {
1394
+ const floor = candidate.lexical || input.relevanceFloor === void 0 ? this.minVectorScore : Math.max(this.minVectorScore, input.relevanceFloor);
1395
+ if (!candidate.isRecencyFloor && candidate.score < floor && !useFallback) {
1383
1396
  bump(skipReasons, "low_score");
1384
1397
  itemsSkipped += 1;
1385
1398
  continue;
@@ -2049,7 +2062,8 @@ var providerSchema = z.object({
2049
2062
  type: z.enum(["local", "huggingface", "openrouter"]),
2050
2063
  apiKey: z.string().min(1).optional(),
2051
2064
  model: z.string().min(1).optional(),
2052
- relevanceFloor: z.number().min(-1).max(1).optional()
2065
+ relevanceFloor: z.number().min(-1).max(1).optional(),
2066
+ recallFloor: z.number().min(-1).max(1).optional()
2053
2067
  });
2054
2068
  var codeBuddyConfigSchema = z.object({
2055
2069
  postgresUrl: z.string().min(1, "postgresUrl is required"),
@@ -2343,6 +2357,9 @@ var CodeBuddy = class {
2343
2357
  if (!content || content.length === 0) {
2344
2358
  throw new Error("remember: content must not be empty.");
2345
2359
  }
2360
+ if (input.idempotencyKey !== void 0 && (input.idempotencyKey.length === 0 || input.idempotencyKey.length > 200)) {
2361
+ throw new Error("remember: idempotencyKey must be 1\u2013200 characters.");
2362
+ }
2346
2363
  const result = await this.repo.withSessionLock(
2347
2364
  namespaceId,
2348
2365
  sessionId,
@@ -2387,7 +2404,8 @@ var CodeBuddy = class {
2387
2404
  conflictMode: input.conflictMode ?? "all",
2388
2405
  queryEmbedding,
2389
2406
  repository: this.repo,
2390
- ...input.callerModel !== void 0 ? { callerModel: input.callerModel } : {}
2407
+ ...input.callerModel !== void 0 ? { callerModel: input.callerModel } : {},
2408
+ relevanceFloor: this.recallFloor(queryEmbedding?.space.model)
2391
2409
  };
2392
2410
  const planned = await this.tracer.withSpan(
2393
2411
  "codebuddy.recall",
@@ -2406,6 +2424,11 @@ var CodeBuddy = class {
2406
2424
  }
2407
2425
  return planned;
2408
2426
  }
2427
+ /** Cosine floor for an explicit `recall` of the query's embedding model. */
2428
+ recallFloor(model) {
2429
+ const definition = model ? getModelDefinition(model) : void 0;
2430
+ return this.config.provider.recallFloor ?? definition?.recallFloor ?? this.config.provider.relevanceFloor ?? definition?.relevanceFloor;
2431
+ }
2409
2432
  /**
2410
2433
  * Dense evidence for file facts supplied by the context engine: the cosine of
2411
2434
  * each fact whose stored vector clears the embedding model's calibrated
@@ -2763,7 +2786,7 @@ var CodeBuddy = class {
2763
2786
  content: input.content
2764
2787
  });
2765
2788
  const content = input.type === "fact" ? claim.content : input.content;
2766
- const contentHash = input.idempotencyKey ?? (input.type === "fact" ? factContentHash(this.config.namespace, ownerId, content) : computeContentHash(this.config.namespace, input.sessionId, input.content));
2789
+ const contentHash = input.type === "fact" ? factContentHash(this.config.namespace, ownerId, content) : input.idempotencyKey ?? computeContentHash(this.config.namespace, input.sessionId, input.content);
2767
2790
  const tokenCount = estimateTokenCount(content);
2768
2791
  const embeddingId = generateEntityId("emb");
2769
2792
  const embedding = {
@@ -2803,6 +2826,7 @@ var CodeBuddy = class {
2803
2826
  subject: claim.subject,
2804
2827
  predicate: claim.predicate,
2805
2828
  object: claim.object,
2829
+ ...input.idempotencyKey !== void 0 ? { idempotencyKey: input.idempotencyKey } : {},
2806
2830
  ...input.agentId !== void 0 ? { createdByAgent: input.agentId } : {}
2807
2831
  };
2808
2832
  const result2 = await this.repo.writeFact({ fact, embedding, audit });
@@ -2826,6 +2850,7 @@ var CodeBuddy = class {
2826
2850
  createdByAgent: input.agentId ?? null,
2827
2851
  sourceInteractionId: fact.sourceInteractionId ?? null,
2828
2852
  sourceDeleted: false,
2853
+ ...input.idempotencyKey !== void 0 ? { idempotencyKey: input.idempotencyKey } : {},
2829
2854
  content: fact.content
2830
2855
  });
2831
2856
  }
@@ -2890,6 +2915,7 @@ var CodeBuddy = class {
2890
2915
  sourceDeleted: file.sourceDeleted,
2891
2916
  supersededBy: file.supersededBy,
2892
2917
  propositionKey: file.propositionKey ?? null,
2918
+ idempotencyKey: file.idempotencyKey ?? null,
2893
2919
  createdByAgent: file.createdByAgent ?? void 0,
2894
2920
  createdAt: new Date(file.createdAt)
2895
2921
  },
@@ -3294,4 +3320,4 @@ export {
3294
3320
  inspectNamespace,
3295
3321
  runDoctor
3296
3322
  };
3297
- //# sourceMappingURL=chunk-2XDPKFUW.js.map
3323
+ //# sourceMappingURL=chunk-AK2UAE32.js.map