@iderouter/index-mcp 0.2.0-beta.1

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 (69) hide show
  1. package/README.md +93 -0
  2. package/package.json +26 -0
  3. package/scripts/benchmark-all.mjs +177 -0
  4. package/scripts/benchmark-auto-continuation.mjs +188 -0
  5. package/scripts/benchmark-background-fine-resume.mjs +245 -0
  6. package/scripts/benchmark-background-fine-wait.mjs +76 -0
  7. package/scripts/benchmark-background-fine.mjs +132 -0
  8. package/scripts/benchmark-clean-snapshot.mjs +83 -0
  9. package/scripts/benchmark-coarse-ready-search.mjs +161 -0
  10. package/scripts/benchmark-deferred.mjs +62 -0
  11. package/scripts/benchmark-first-semantic-visible.mjs +151 -0
  12. package/scripts/benchmark-gate.mjs +107 -0
  13. package/scripts/benchmark-generic-resumed-single-chunk-embed.mjs +104 -0
  14. package/scripts/benchmark-noop.mjs +24 -0
  15. package/scripts/benchmark-priority-ready-search.mjs +165 -0
  16. package/scripts/benchmark-repeat-search.mjs +148 -0
  17. package/scripts/benchmark-resumed-retry-burst.mjs +187 -0
  18. package/scripts/benchmark-resumed-single-chunk-success.mjs +154 -0
  19. package/scripts/benchmark-resumed-single-chunk.mjs +146 -0
  20. package/scripts/benchmark-single-priority-chunk-embed.mjs +145 -0
  21. package/scripts/benchmark-small-change.mjs +146 -0
  22. package/scripts/benchmark-stage-summary.mjs +88 -0
  23. package/scripts/lib/auto-continuation-state.mjs +34 -0
  24. package/scripts/lib/benchmark-query-packs.mjs +123 -0
  25. package/scripts/lib/benchmark-snapshot.mjs +109 -0
  26. package/scripts/lib/mcp-bench.mjs +455 -0
  27. package/src/architecture-query-fallback.js +50 -0
  28. package/src/background-definition-chunks.js +199 -0
  29. package/src/background-embedding-profile.js +64 -0
  30. package/src/background-fine-budget.js +18 -0
  31. package/src/background-fine-runtime.js +179 -0
  32. package/src/background-fine-selection.js +332 -0
  33. package/src/checkpoint-policy.js +16 -0
  34. package/src/conflict-policy.js +17 -0
  35. package/src/deferred-retry-delay.js +14 -0
  36. package/src/deferred-retry-status.js +10 -0
  37. package/src/embedding-attempt-ordinal.js +17 -0
  38. package/src/embedding-failure-penalty.js +60 -0
  39. package/src/embedding-failure-policy.js +52 -0
  40. package/src/embedding-flush-timeout.js +33 -0
  41. package/src/embedding-inflight-status.js +18 -0
  42. package/src/embedding-model-policy.js +44 -0
  43. package/src/embedding-next-switch.js +18 -0
  44. package/src/embedding-request-status-detail.js +25 -0
  45. package/src/embedding-request-status.js +22 -0
  46. package/src/embedding-selection-order.js +23 -0
  47. package/src/fine-run-queue.js +14 -0
  48. package/src/index.js +7970 -0
  49. package/src/job-supersession.js +25 -0
  50. package/src/priority-progress.js +20 -0
  51. package/src/priority-ready-anchor-coverage-normalize.js +18 -0
  52. package/src/priority-ready-anchor-coverage.js +23 -0
  53. package/src/priority-ready-hotspots.js +344 -0
  54. package/src/priority-ready-status.js +30 -0
  55. package/src/priority-ready-targets.js +45 -0
  56. package/src/priority-usable-attempt-plan.js +44 -0
  57. package/src/priority-usable-attempt-timeout.js +18 -0
  58. package/src/priority-usable-fast-path.js +11 -0
  59. package/src/priority-usable-probe-order.js +34 -0
  60. package/src/remote-strategy-failure-cache.js +55 -0
  61. package/src/resume-seed.js +9 -0
  62. package/src/semantic-first-checkpoint.js +8 -0
  63. package/src/semantic-slow-path.js +10 -0
  64. package/src/single-chunk-attempt-timeout.js +13 -0
  65. package/src/single-chunk-embedding-content.js +26 -0
  66. package/src/single-chunk-embedding-policy.js +18 -0
  67. package/src/single-chunk-provider-order.js +12 -0
  68. package/src/single-chunk-provider-policy.js +63 -0
  69. package/src/worker-lock-retry.js +24 -0
@@ -0,0 +1,9 @@
1
+ export function shouldTreatAsResumePartialSeed({
2
+ canReuseFileChunks = false,
3
+ existingIndexComplete = null,
4
+ hasResumeSeed = false,
5
+ }) {
6
+ if (!canReuseFileChunks) return false;
7
+ if (Boolean(hasResumeSeed)) return true;
8
+ return existingIndexComplete === false;
9
+ }
@@ -0,0 +1,8 @@
1
+ export function shouldForceFirstSemanticCheckpoint({
2
+ isResumePartialSeed = false,
3
+ previousEmbeddedCount = 0,
4
+ embeddedCount = 0,
5
+ }) {
6
+ if (!isResumePartialSeed) return false;
7
+ return Number(previousEmbeddedCount || 0) === 0 && Number(embeddedCount || 0) > 0;
8
+ }
@@ -0,0 +1,10 @@
1
+ export function shouldMarkSingleSemanticSlowPath({
2
+ jobStatus = "",
3
+ totalChunks = 0,
4
+ embeddedCount = 0,
5
+ currentStep = "",
6
+ }) {
7
+ if (String(jobStatus || "") !== "indexing") return false;
8
+ if (!String(currentStep || "").toLowerCase().includes("embedding batch")) return false;
9
+ return Number(totalChunks || 0) === 1 && Number(embeddedCount || 0) === 0;
10
+ }
@@ -0,0 +1,13 @@
1
+ export function resumedSingleChunkAttemptTimeoutMs({
2
+ source = "",
3
+ attemptTimeoutMs = 0,
4
+ priorityTimeoutMs = 0,
5
+ }) {
6
+ const sourceText = String(source || "");
7
+ const attemptMs = Math.max(0, Number(attemptTimeoutMs || 0));
8
+ const priorityMs = Math.max(0, Number(priorityTimeoutMs || 0));
9
+ if (sourceText.startsWith("previous_failure_fallback_deferred_resume")) {
10
+ return Math.max(attemptMs, Math.min(attemptMs + 1000, 6000));
11
+ }
12
+ return Math.max(attemptMs * 2, priorityMs);
13
+ }
@@ -0,0 +1,26 @@
1
+ export function compactEmbeddingContentForSingleResumeChunk(chunk) {
2
+ const content = String(chunk?.content || "").trim();
3
+ if (!content) return content;
4
+ const lines = content
5
+ .split("\n")
6
+ .map((line) => line.trim())
7
+ .filter(Boolean);
8
+ const signature = lines[0] || "";
9
+ const hintLines = lines
10
+ .slice(1)
11
+ .filter((line) => /stream|safety|obfuscation|billing|expr|price|quota|settle|memory|request|model|handler|relay/i.test(line))
12
+ .slice(0, 2);
13
+ const compact = [signature, ...hintLines].filter(Boolean).join("\n");
14
+ if (compact.length <= 96) return compact;
15
+ return compact.slice(0, 96);
16
+ }
17
+
18
+ export function shouldUseCompactSingleChunkEmbeddingContent({
19
+ source = "",
20
+ chunkCount = 0,
21
+ }) {
22
+ const sourceText = String(source || "");
23
+ if (Number(chunkCount || 0) > 1) return false;
24
+ return sourceText.startsWith("previous_failure_fallback_deferred_resume") ||
25
+ sourceText.startsWith("priority_usable_strategy");
26
+ }
@@ -0,0 +1,18 @@
1
+ export function normalizeSingleChunkEmbeddingRequest({
2
+ source = "",
3
+ chunkCount = 0,
4
+ timeoutMs = 0,
5
+ maxRetries = 0,
6
+ }) {
7
+ const sourceText = String(source || "");
8
+ if (sourceText.startsWith("previous_failure_fallback_deferred_resume") && Number(chunkCount || 0) <= 1) {
9
+ return {
10
+ timeoutMs: Math.max(Number(timeoutMs || 0), 6000),
11
+ maxRetries: Math.min(1, Math.max(Number(maxRetries || 0), 0)),
12
+ };
13
+ }
14
+ return {
15
+ timeoutMs,
16
+ maxRetries,
17
+ };
18
+ }
@@ -0,0 +1,12 @@
1
+ export function preferredSingleChunkResumeModelFromHealth({
2
+ candidates = [],
3
+ cachedHealthModel = "",
4
+ }) {
5
+ const list = Array.isArray(candidates) ? candidates.filter(Boolean) : [];
6
+ const cached = String(cachedHealthModel || "").trim();
7
+ if (cached && list.includes(cached)) {
8
+ return cached;
9
+ }
10
+ const preferred = list.find((candidate) => candidate === "openai/text-embedding-3-small");
11
+ return preferred || list[0] || null;
12
+ }
@@ -0,0 +1,63 @@
1
+ import { preferredSingleChunkResumeModelFromHealth } from "./single-chunk-provider-order.js";
2
+
3
+ export function preferredSingleChunkResumeModel({
4
+ source = "",
5
+ chunkCount = 0,
6
+ candidates = [],
7
+ cachedHealthModel = "",
8
+ preferredModel = "",
9
+ }) {
10
+ const sourceText = String(source || "");
11
+ if (!sourceText.startsWith("previous_failure_fallback_deferred_resume")) return null;
12
+ if (Number(chunkCount || 0) > 1) return null;
13
+ const explicitPreferred = String(preferredModel || "").trim();
14
+ if (explicitPreferred && Array.isArray(candidates) && candidates.includes(explicitPreferred)) {
15
+ return explicitPreferred;
16
+ }
17
+ return preferredSingleChunkResumeModelFromHealth({
18
+ candidates,
19
+ cachedHealthModel,
20
+ });
21
+ }
22
+
23
+ export function buildSingleChunkResumeAttemptPlan({
24
+ source = "",
25
+ chunkCount = 0,
26
+ candidates = [],
27
+ preferredModel = "",
28
+ cachedHealthModel = "",
29
+ cachedHealthOk = true,
30
+ cachedHealthLatencyMs = 0,
31
+ baseTimeoutMs = 0,
32
+ baseMaxRetries = 0,
33
+ }) {
34
+ const sourceText = String(source || "");
35
+ if (!sourceText.startsWith("previous_failure_fallback_deferred_resume")) return [];
36
+ if (Number(chunkCount || 0) > 1) return [];
37
+ const list = Array.isArray(candidates) ? candidates.filter(Boolean) : [];
38
+ if (list.length === 0) return [];
39
+ const primaryModel = preferredModel || list[0];
40
+ const secondaryModel = list.find((candidate) => candidate !== primaryModel) || primaryModel;
41
+ const firstTimeoutMs = Math.min(Math.max(5000, Math.round(Number(baseTimeoutMs || 0) * 0.08)), 5000);
42
+ const secondTimeoutMs = Math.min(Math.max(6000, Math.round(Number(baseTimeoutMs || 0) * 0.1)), 6000);
43
+ const attempts = [
44
+ {
45
+ model: primaryModel,
46
+ timeoutMs: firstTimeoutMs,
47
+ maxRetries: 0,
48
+ },
49
+ ];
50
+ if (
51
+ secondaryModel !== primaryModel &&
52
+ String(cachedHealthModel || "").trim() === secondaryModel &&
53
+ cachedHealthOk !== false &&
54
+ Math.max(0, Number(cachedHealthLatencyMs || 0)) > 0
55
+ ) {
56
+ attempts.push({
57
+ model: secondaryModel,
58
+ timeoutMs: secondTimeoutMs,
59
+ maxRetries: Math.min(1, Math.max(0, Number(baseMaxRetries || 0))),
60
+ });
61
+ }
62
+ return attempts;
63
+ }
@@ -0,0 +1,24 @@
1
+ export function isRetryableIndexLockError(error) {
2
+ const message = error instanceof Error ? error.message : String(error || "");
3
+ return message.includes("Index lock already held for ");
4
+ }
5
+
6
+ export function shouldRetryWorkerIndexLock({
7
+ error,
8
+ retryAttempt = 0,
9
+ maxRetries = 0,
10
+ }) {
11
+ if (!isRetryableIndexLockError(error)) return false;
12
+ return Math.max(0, Number(retryAttempt) || 0) <= Math.max(0, Number(maxRetries) || 0);
13
+ }
14
+
15
+ export function workerLockRetryDelayMs({
16
+ retryAttempt = 1,
17
+ baseMs = 250,
18
+ maxMs = 4000,
19
+ }) {
20
+ const attempt = Math.max(1, Number(retryAttempt) || 1);
21
+ const base = Math.max(1, Number(baseMs) || 1);
22
+ const cap = Math.max(base, Number(maxMs) || base);
23
+ return Math.min(cap, base * (2 ** (attempt - 1)));
24
+ }