@adhisang/minecraft-modding-mcp 1.0.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 (106) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -0
  3. package/README.md +765 -0
  4. package/dist/access-widener-parser.d.ts +24 -0
  5. package/dist/access-widener-parser.js +77 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +4 -0
  8. package/dist/config.d.ts +27 -0
  9. package/dist/config.js +178 -0
  10. package/dist/decompiler/vineflower.d.ts +15 -0
  11. package/dist/decompiler/vineflower.js +185 -0
  12. package/dist/errors.d.ts +50 -0
  13. package/dist/errors.js +49 -0
  14. package/dist/hash.d.ts +1 -0
  15. package/dist/hash.js +12 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.js +1447 -0
  18. package/dist/java-process.d.ts +16 -0
  19. package/dist/java-process.js +120 -0
  20. package/dist/logger.d.ts +3 -0
  21. package/dist/logger.js +21 -0
  22. package/dist/mapping-pipeline-service.d.ts +18 -0
  23. package/dist/mapping-pipeline-service.js +60 -0
  24. package/dist/mapping-service.d.ts +161 -0
  25. package/dist/mapping-service.js +1706 -0
  26. package/dist/maven-resolver.d.ts +22 -0
  27. package/dist/maven-resolver.js +122 -0
  28. package/dist/minecraft-explorer-service.d.ts +43 -0
  29. package/dist/minecraft-explorer-service.js +562 -0
  30. package/dist/mixin-parser.d.ts +34 -0
  31. package/dist/mixin-parser.js +194 -0
  32. package/dist/mixin-validator.d.ts +59 -0
  33. package/dist/mixin-validator.js +274 -0
  34. package/dist/mod-analyzer.d.ts +23 -0
  35. package/dist/mod-analyzer.js +346 -0
  36. package/dist/mod-decompile-service.d.ts +39 -0
  37. package/dist/mod-decompile-service.js +136 -0
  38. package/dist/mod-remap-service.d.ts +17 -0
  39. package/dist/mod-remap-service.js +186 -0
  40. package/dist/mod-search-service.d.ts +28 -0
  41. package/dist/mod-search-service.js +174 -0
  42. package/dist/mojang-tiny-mapping-service.d.ts +13 -0
  43. package/dist/mojang-tiny-mapping-service.js +351 -0
  44. package/dist/nbt/java-nbt-codec.d.ts +3 -0
  45. package/dist/nbt/java-nbt-codec.js +385 -0
  46. package/dist/nbt/json-patch.d.ts +3 -0
  47. package/dist/nbt/json-patch.js +352 -0
  48. package/dist/nbt/pipeline.d.ts +39 -0
  49. package/dist/nbt/pipeline.js +173 -0
  50. package/dist/nbt/typed-json.d.ts +10 -0
  51. package/dist/nbt/typed-json.js +205 -0
  52. package/dist/nbt/types.d.ts +66 -0
  53. package/dist/nbt/types.js +2 -0
  54. package/dist/observability.d.ts +88 -0
  55. package/dist/observability.js +165 -0
  56. package/dist/path-converter.d.ts +12 -0
  57. package/dist/path-converter.js +161 -0
  58. package/dist/path-resolver.d.ts +19 -0
  59. package/dist/path-resolver.js +78 -0
  60. package/dist/registry-service.d.ts +29 -0
  61. package/dist/registry-service.js +214 -0
  62. package/dist/repo-downloader.d.ts +15 -0
  63. package/dist/repo-downloader.js +111 -0
  64. package/dist/resources.d.ts +3 -0
  65. package/dist/resources.js +154 -0
  66. package/dist/search-hit-accumulator.d.ts +38 -0
  67. package/dist/search-hit-accumulator.js +153 -0
  68. package/dist/source-jar-reader.d.ts +13 -0
  69. package/dist/source-jar-reader.js +216 -0
  70. package/dist/source-resolver.d.ts +14 -0
  71. package/dist/source-resolver.js +274 -0
  72. package/dist/source-service.d.ts +404 -0
  73. package/dist/source-service.js +2881 -0
  74. package/dist/storage/artifacts-repo.d.ts +45 -0
  75. package/dist/storage/artifacts-repo.js +209 -0
  76. package/dist/storage/db.d.ts +14 -0
  77. package/dist/storage/db.js +132 -0
  78. package/dist/storage/files-repo.d.ts +78 -0
  79. package/dist/storage/files-repo.js +437 -0
  80. package/dist/storage/index-meta-repo.d.ts +35 -0
  81. package/dist/storage/index-meta-repo.js +97 -0
  82. package/dist/storage/migrations.d.ts +11 -0
  83. package/dist/storage/migrations.js +71 -0
  84. package/dist/storage/schema.d.ts +1 -0
  85. package/dist/storage/schema.js +160 -0
  86. package/dist/storage/sqlite.d.ts +20 -0
  87. package/dist/storage/sqlite.js +111 -0
  88. package/dist/storage/symbols-repo.d.ts +63 -0
  89. package/dist/storage/symbols-repo.js +401 -0
  90. package/dist/symbols/symbol-extractor.d.ts +7 -0
  91. package/dist/symbols/symbol-extractor.js +64 -0
  92. package/dist/tiny-remapper-resolver.d.ts +1 -0
  93. package/dist/tiny-remapper-resolver.js +62 -0
  94. package/dist/tiny-remapper-service.d.ts +16 -0
  95. package/dist/tiny-remapper-service.js +73 -0
  96. package/dist/types.d.ts +120 -0
  97. package/dist/types.js +2 -0
  98. package/dist/version-diff-service.d.ts +41 -0
  99. package/dist/version-diff-service.js +222 -0
  100. package/dist/version-service.d.ts +70 -0
  101. package/dist/version-service.js +411 -0
  102. package/dist/vineflower-resolver.d.ts +1 -0
  103. package/dist/vineflower-resolver.js +62 -0
  104. package/dist/workspace-mapping-service.d.ts +18 -0
  105. package/dist/workspace-mapping-service.js +89 -0
  106. package/package.json +61 -0
@@ -0,0 +1,205 @@
1
+ import { createError, ERROR_CODES } from "../errors.js";
2
+ const NODE_TYPES = [
3
+ "byte",
4
+ "short",
5
+ "int",
6
+ "long",
7
+ "float",
8
+ "double",
9
+ "byteArray",
10
+ "string",
11
+ "list",
12
+ "compound",
13
+ "intArray",
14
+ "longArray"
15
+ ];
16
+ const LIST_ELEMENT_TYPES = ["end", ...NODE_TYPES];
17
+ const NODE_TYPE_SET = new Set(NODE_TYPES);
18
+ const LIST_ELEMENT_TYPE_SET = new Set(LIST_ELEMENT_TYPES);
19
+ const INT64_MIN = -9223372036854775808n;
20
+ const INT64_MAX = 9223372036854775807n;
21
+ function isRecord(value) {
22
+ return (typeof value === "object" &&
23
+ value !== null &&
24
+ !Array.isArray(value) &&
25
+ !ArrayBuffer.isView(value));
26
+ }
27
+ function describeType(value) {
28
+ if (Array.isArray(value)) {
29
+ return "array";
30
+ }
31
+ if (value === null) {
32
+ return "null";
33
+ }
34
+ return typeof value;
35
+ }
36
+ function fail(jsonPointer, expectedType, actualValue) {
37
+ return {
38
+ ok: false,
39
+ issue: {
40
+ jsonPointer,
41
+ expectedType,
42
+ actualType: describeType(actualValue)
43
+ }
44
+ };
45
+ }
46
+ function escapePointerToken(token) {
47
+ return token.replace(/~/g, "~0").replace(/\//g, "~1");
48
+ }
49
+ function validateIntegerInRange(value, min, max, pointer, expectedType) {
50
+ if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max) {
51
+ return fail(pointer, expectedType, value);
52
+ }
53
+ return { ok: true };
54
+ }
55
+ function validateLongString(value, pointer) {
56
+ if (typeof value !== "string") {
57
+ return fail(pointer, "int64-decimal-string", value);
58
+ }
59
+ if (!/^-?(0|[1-9][0-9]*)$/.test(value)) {
60
+ return fail(pointer, "int64-decimal-string", value);
61
+ }
62
+ let parsed;
63
+ try {
64
+ parsed = BigInt(value);
65
+ }
66
+ catch {
67
+ return fail(pointer, "int64-decimal-string", value);
68
+ }
69
+ if (parsed < INT64_MIN || parsed > INT64_MAX) {
70
+ return fail(pointer, "int64-decimal-string", value);
71
+ }
72
+ return { ok: true };
73
+ }
74
+ function validateLongStringArray(value, pointer) {
75
+ if (!Array.isArray(value)) {
76
+ return fail(pointer, "int64-decimal-string-array", value);
77
+ }
78
+ for (let i = 0; i < value.length; i += 1) {
79
+ const result = validateLongString(value[i], `${pointer}/${i}`);
80
+ if (!result.ok) {
81
+ return result;
82
+ }
83
+ }
84
+ return { ok: true };
85
+ }
86
+ function validateNumericArray(value, pointer, expectedType, min, max) {
87
+ if (!Array.isArray(value)) {
88
+ return fail(pointer, expectedType, value);
89
+ }
90
+ for (let i = 0; i < value.length; i += 1) {
91
+ const result = validateIntegerInRange(value[i], min, max, `${pointer}/${i}`, expectedType);
92
+ if (!result.ok) {
93
+ return result;
94
+ }
95
+ }
96
+ return { ok: true };
97
+ }
98
+ function validateNode(value, pointer) {
99
+ if (!isRecord(value)) {
100
+ return fail(pointer, "nbt-node", value);
101
+ }
102
+ if (!("type" in value)) {
103
+ return fail(`${pointer}/type`, "nbt-node-type", undefined);
104
+ }
105
+ const nodeTypeRaw = value.type;
106
+ if (typeof nodeTypeRaw !== "string" || !NODE_TYPE_SET.has(nodeTypeRaw)) {
107
+ return fail(`${pointer}/type`, "nbt-node-type", nodeTypeRaw);
108
+ }
109
+ const nodeType = nodeTypeRaw;
110
+ const node = value;
111
+ switch (nodeType) {
112
+ case "byte":
113
+ return validateIntegerInRange(node.value, -128, 127, `${pointer}/value`, "int8");
114
+ case "short":
115
+ return validateIntegerInRange(node.value, -32768, 32767, `${pointer}/value`, "int16");
116
+ case "int":
117
+ return validateIntegerInRange(node.value, -2147483648, 2147483647, `${pointer}/value`, "int32");
118
+ case "long":
119
+ return validateLongString(node.value, `${pointer}/value`);
120
+ case "float":
121
+ case "double":
122
+ if (typeof node.value !== "number" || !Number.isFinite(node.value)) {
123
+ return fail(`${pointer}/value`, "finite-number", node.value);
124
+ }
125
+ return { ok: true };
126
+ case "string":
127
+ if (typeof node.value !== "string") {
128
+ return fail(`${pointer}/value`, "string", node.value);
129
+ }
130
+ return { ok: true };
131
+ case "byteArray":
132
+ return validateNumericArray(node.value, `${pointer}/value`, "int8-array", -128, 127);
133
+ case "intArray":
134
+ return validateNumericArray(node.value, `${pointer}/value`, "int32-array", -2147483648, 2147483647);
135
+ case "longArray":
136
+ return validateLongStringArray(node.value, `${pointer}/value`);
137
+ case "list": {
138
+ const elementType = node.elementType;
139
+ if (typeof elementType !== "string" || !LIST_ELEMENT_TYPE_SET.has(elementType)) {
140
+ return fail(`${pointer}/elementType`, "nbt-list-element-type", elementType);
141
+ }
142
+ const listValue = node.value;
143
+ if (!Array.isArray(listValue)) {
144
+ return fail(`${pointer}/value`, "nbt-node-array", listValue);
145
+ }
146
+ if (elementType === "end" && listValue.length > 0) {
147
+ return fail(`${pointer}/value`, "empty-array-for-end-list", listValue);
148
+ }
149
+ for (let i = 0; i < listValue.length; i += 1) {
150
+ const childPointer = `${pointer}/value/${i}`;
151
+ const childValidation = validateNode(listValue[i], childPointer);
152
+ if (!childValidation.ok) {
153
+ return childValidation;
154
+ }
155
+ if (!isRecord(listValue[i])) {
156
+ return fail(childPointer, "nbt-node", listValue[i]);
157
+ }
158
+ const childType = listValue[i].type;
159
+ if (typeof childType !== "string" || childType !== elementType) {
160
+ return fail(`${childPointer}/type`, elementType, childType);
161
+ }
162
+ }
163
+ return { ok: true };
164
+ }
165
+ case "compound": {
166
+ const compoundValue = node.value;
167
+ if (!isRecord(compoundValue)) {
168
+ return fail(`${pointer}/value`, "object", compoundValue);
169
+ }
170
+ for (const [key, childValue] of Object.entries(compoundValue)) {
171
+ const childPointer = `${pointer}/value/${escapePointerToken(key)}`;
172
+ const childValidation = validateNode(childValue, childPointer);
173
+ if (!childValidation.ok) {
174
+ return childValidation;
175
+ }
176
+ }
177
+ return { ok: true };
178
+ }
179
+ default:
180
+ return fail(`${pointer}/type`, "nbt-node-type", nodeType);
181
+ }
182
+ }
183
+ export function validateTypedNbtDocument(value) {
184
+ if (!isRecord(value)) {
185
+ return fail("", "typed-nbt-document", value);
186
+ }
187
+ if (typeof value.rootName !== "string") {
188
+ return fail("/rootName", "string", value.rootName);
189
+ }
190
+ if (!("root" in value)) {
191
+ return fail("/root", "nbt-node", undefined);
192
+ }
193
+ return validateNode(value.root, "/root");
194
+ }
195
+ export function assertValidTypedNbtDocument(value) {
196
+ const validation = validateTypedNbtDocument(value);
197
+ if (!validation.ok) {
198
+ throw createError({
199
+ code: ERROR_CODES.NBT_INVALID_TYPED_JSON,
200
+ message: "Invalid typed NBT JSON document.",
201
+ details: { ...validation.issue }
202
+ });
203
+ }
204
+ }
205
+ //# sourceMappingURL=typed-json.js.map
@@ -0,0 +1,66 @@
1
+ export type NbtTagName = "end" | "byte" | "short" | "int" | "long" | "float" | "double" | "byteArray" | "string" | "list" | "compound" | "intArray" | "longArray";
2
+ export type NbtNodeType = Exclude<NbtTagName, "end">;
3
+ export type NbtListElementType = NbtTagName;
4
+ export type NbtNode = {
5
+ type: "byte";
6
+ value: number;
7
+ } | {
8
+ type: "short";
9
+ value: number;
10
+ } | {
11
+ type: "int";
12
+ value: number;
13
+ } | {
14
+ type: "long";
15
+ value: string;
16
+ } | {
17
+ type: "float";
18
+ value: number;
19
+ } | {
20
+ type: "double";
21
+ value: number;
22
+ } | {
23
+ type: "byteArray";
24
+ value: number[];
25
+ } | {
26
+ type: "string";
27
+ value: string;
28
+ } | {
29
+ type: "list";
30
+ elementType: NbtListElementType;
31
+ value: NbtNode[];
32
+ } | {
33
+ type: "compound";
34
+ value: Record<string, NbtNode>;
35
+ } | {
36
+ type: "intArray";
37
+ value: number[];
38
+ } | {
39
+ type: "longArray";
40
+ value: string[];
41
+ };
42
+ export interface TypedNbtDocument {
43
+ rootName: string;
44
+ root: NbtNode;
45
+ }
46
+ export interface TypedNbtValidationIssue {
47
+ jsonPointer: string;
48
+ expectedType: string;
49
+ actualType: string;
50
+ }
51
+ export type JsonPatchOpCode = "add" | "remove" | "replace" | "test";
52
+ export interface JsonPatchOperation {
53
+ op: string;
54
+ path: string;
55
+ from?: string;
56
+ value?: unknown;
57
+ }
58
+ export interface ApplyJsonPatchMeta {
59
+ appliedOps: number;
60
+ testOps: number;
61
+ changed: boolean;
62
+ }
63
+ export interface ApplyJsonPatchResult {
64
+ typedJson: TypedNbtDocument;
65
+ meta: ApplyJsonPatchMeta;
66
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,88 @@
1
+ export interface MetricTimingSnapshot {
2
+ count: number;
3
+ totalMs: number;
4
+ avgMs: number;
5
+ lastMs: number;
6
+ }
7
+ export interface CacheArtifactByteAccountingRow {
8
+ artifact_id: string;
9
+ content_bytes: number;
10
+ updated_at: string;
11
+ }
12
+ export interface RuntimeMetricSnapshot {
13
+ resolve_duration_ms: MetricTimingSnapshot;
14
+ search_duration_ms: MetricTimingSnapshot;
15
+ get_file_duration_ms: MetricTimingSnapshot;
16
+ list_files_duration_ms: MetricTimingSnapshot;
17
+ decompile_duration_ms: MetricTimingSnapshot;
18
+ search_intent_symbol_duration_ms: MetricTimingSnapshot;
19
+ search_intent_text_duration_ms: MetricTimingSnapshot;
20
+ search_intent_path_duration_ms: MetricTimingSnapshot;
21
+ search_regex_fallback_count: number;
22
+ search_token_bytes_returned: number;
23
+ onehop_expand_count: number;
24
+ search_indexed_hit_count: number;
25
+ search_fallback_count: number;
26
+ indexed_disabled_count: number;
27
+ search_db_roundtrips: number;
28
+ search_rows_scanned: number;
29
+ search_rows_returned: number;
30
+ search_indexed_zero_shortcircuit_count: number;
31
+ reindex_count: number;
32
+ reindex_skip_count: number;
33
+ cache_evictions: number;
34
+ cache_entries: number;
35
+ cache_total_content_bytes: number;
36
+ cache_artifact_bytes_lru: CacheArtifactByteAccountingRow[];
37
+ cache_hit_rate: number;
38
+ repo_failover_count: number;
39
+ }
40
+ type DurationMetricName = keyof Pick<RuntimeMetricSnapshot, "resolve_duration_ms" | "search_duration_ms" | "get_file_duration_ms" | "list_files_duration_ms" | "decompile_duration_ms" | "search_intent_symbol_duration_ms" | "search_intent_text_duration_ms" | "search_intent_path_duration_ms">;
41
+ export declare class RuntimeMetrics {
42
+ private readonly timings;
43
+ private cacheHits;
44
+ private cacheMisses;
45
+ private repoFailoverCount;
46
+ private searchRegexFallbackCount;
47
+ private searchTokenBytesReturned;
48
+ private oneHopExpandCount;
49
+ private searchIndexedHitCount;
50
+ private searchFallbackCount;
51
+ private indexedDisabledCount;
52
+ private searchDbRoundtrips;
53
+ private searchRowsScanned;
54
+ private searchRowsReturned;
55
+ private searchIndexedZeroShortcircuitCount;
56
+ private reindexCount;
57
+ private reindexSkipCount;
58
+ private cacheEvictions;
59
+ private cacheEntries;
60
+ private cacheTotalContentBytes;
61
+ private cacheArtifactBytesLru;
62
+ constructor();
63
+ recordDuration(name: DurationMetricName, durationMs: number): void;
64
+ recordArtifactCacheHit(): void;
65
+ recordArtifactCacheMiss(): void;
66
+ recordRepoFailover(): void;
67
+ recordSearchIntentDuration(intent: "symbol" | "text" | "path", durationMs: number): void;
68
+ recordSearchRegexFallback(): void;
69
+ recordSearchTokenBytesReturned(tokenBytes: number): void;
70
+ recordOneHopExpansion(count: number): void;
71
+ recordSearchIndexedHit(): void;
72
+ recordSearchFallback(): void;
73
+ recordIndexedDisabled(): void;
74
+ recordSearchDbRoundtrip(count?: number): void;
75
+ recordSearchRowsScanned(count: number): void;
76
+ recordSearchRowsReturned(count: number): void;
77
+ recordSearchIndexedZeroShortcircuit(): void;
78
+ recordReindex(): void;
79
+ recordReindexSkip(): void;
80
+ recordCacheEviction(count?: number): void;
81
+ setCacheEntries(entries: number): void;
82
+ setCacheTotalContentBytes(totalBytes: number): void;
83
+ setCacheArtifactByteAccounting(entries: CacheArtifactByteAccountingRow[]): void;
84
+ snapshot(): RuntimeMetricSnapshot;
85
+ private toSnapshot;
86
+ private resolveCacheHitRate;
87
+ }
88
+ export {};
@@ -0,0 +1,165 @@
1
+ export class RuntimeMetrics {
2
+ timings = new Map();
3
+ cacheHits = 0;
4
+ cacheMisses = 0;
5
+ repoFailoverCount = 0;
6
+ searchRegexFallbackCount = 0;
7
+ searchTokenBytesReturned = 0;
8
+ oneHopExpandCount = 0;
9
+ searchIndexedHitCount = 0;
10
+ searchFallbackCount = 0;
11
+ indexedDisabledCount = 0;
12
+ searchDbRoundtrips = 0;
13
+ searchRowsScanned = 0;
14
+ searchRowsReturned = 0;
15
+ searchIndexedZeroShortcircuitCount = 0;
16
+ reindexCount = 0;
17
+ reindexSkipCount = 0;
18
+ cacheEvictions = 0;
19
+ cacheEntries = 0;
20
+ cacheTotalContentBytes = 0;
21
+ cacheArtifactBytesLru = [];
22
+ constructor() {
23
+ const names = [
24
+ "resolve_duration_ms",
25
+ "search_duration_ms",
26
+ "get_file_duration_ms",
27
+ "list_files_duration_ms",
28
+ "decompile_duration_ms",
29
+ "search_intent_symbol_duration_ms",
30
+ "search_intent_text_duration_ms",
31
+ "search_intent_path_duration_ms"
32
+ ];
33
+ for (const name of names) {
34
+ this.timings.set(name, { count: 0, totalMs: 0, lastMs: 0 });
35
+ }
36
+ }
37
+ recordDuration(name, durationMs) {
38
+ const timing = this.timings.get(name);
39
+ if (!timing) {
40
+ return;
41
+ }
42
+ const normalizedDuration = Math.max(0, Math.trunc(durationMs));
43
+ timing.count += 1;
44
+ timing.totalMs += normalizedDuration;
45
+ timing.lastMs = normalizedDuration;
46
+ }
47
+ recordArtifactCacheHit() {
48
+ this.cacheHits += 1;
49
+ }
50
+ recordArtifactCacheMiss() {
51
+ this.cacheMisses += 1;
52
+ }
53
+ recordRepoFailover() {
54
+ this.repoFailoverCount += 1;
55
+ }
56
+ recordSearchIntentDuration(intent, durationMs) {
57
+ const metricName = intent === "symbol"
58
+ ? "search_intent_symbol_duration_ms"
59
+ : intent === "text"
60
+ ? "search_intent_text_duration_ms"
61
+ : "search_intent_path_duration_ms";
62
+ this.recordDuration(metricName, durationMs);
63
+ }
64
+ recordSearchRegexFallback() {
65
+ this.searchRegexFallbackCount += 1;
66
+ }
67
+ recordSearchTokenBytesReturned(tokenBytes) {
68
+ this.searchTokenBytesReturned += Math.max(0, Math.trunc(tokenBytes));
69
+ }
70
+ recordOneHopExpansion(count) {
71
+ this.oneHopExpandCount += Math.max(0, Math.trunc(count));
72
+ }
73
+ recordSearchIndexedHit() {
74
+ this.searchIndexedHitCount += 1;
75
+ }
76
+ recordSearchFallback() {
77
+ this.searchFallbackCount += 1;
78
+ }
79
+ recordIndexedDisabled() {
80
+ this.indexedDisabledCount += 1;
81
+ }
82
+ recordSearchDbRoundtrip(count = 1) {
83
+ this.searchDbRoundtrips += Math.max(0, Math.trunc(count));
84
+ }
85
+ recordSearchRowsScanned(count) {
86
+ this.searchRowsScanned += Math.max(0, Math.trunc(count));
87
+ }
88
+ recordSearchRowsReturned(count) {
89
+ this.searchRowsReturned += Math.max(0, Math.trunc(count));
90
+ }
91
+ recordSearchIndexedZeroShortcircuit() {
92
+ this.searchIndexedZeroShortcircuitCount += 1;
93
+ }
94
+ recordReindex() {
95
+ this.reindexCount += 1;
96
+ }
97
+ recordReindexSkip() {
98
+ this.reindexSkipCount += 1;
99
+ }
100
+ recordCacheEviction(count = 1) {
101
+ this.cacheEvictions += Math.max(0, Math.trunc(count));
102
+ }
103
+ setCacheEntries(entries) {
104
+ this.cacheEntries = Math.max(0, Math.trunc(entries));
105
+ }
106
+ setCacheTotalContentBytes(totalBytes) {
107
+ this.cacheTotalContentBytes = Math.max(0, Math.trunc(totalBytes));
108
+ }
109
+ setCacheArtifactByteAccounting(entries) {
110
+ this.cacheArtifactBytesLru = entries.map((entry) => ({
111
+ artifact_id: entry.artifact_id,
112
+ content_bytes: Math.max(0, Math.trunc(entry.content_bytes)),
113
+ updated_at: entry.updated_at
114
+ }));
115
+ }
116
+ snapshot() {
117
+ return {
118
+ resolve_duration_ms: this.toSnapshot("resolve_duration_ms"),
119
+ search_duration_ms: this.toSnapshot("search_duration_ms"),
120
+ get_file_duration_ms: this.toSnapshot("get_file_duration_ms"),
121
+ list_files_duration_ms: this.toSnapshot("list_files_duration_ms"),
122
+ decompile_duration_ms: this.toSnapshot("decompile_duration_ms"),
123
+ search_intent_symbol_duration_ms: this.toSnapshot("search_intent_symbol_duration_ms"),
124
+ search_intent_text_duration_ms: this.toSnapshot("search_intent_text_duration_ms"),
125
+ search_intent_path_duration_ms: this.toSnapshot("search_intent_path_duration_ms"),
126
+ search_regex_fallback_count: this.searchRegexFallbackCount,
127
+ search_token_bytes_returned: this.searchTokenBytesReturned,
128
+ onehop_expand_count: this.oneHopExpandCount,
129
+ search_indexed_hit_count: this.searchIndexedHitCount,
130
+ search_fallback_count: this.searchFallbackCount,
131
+ indexed_disabled_count: this.indexedDisabledCount,
132
+ search_db_roundtrips: this.searchDbRoundtrips,
133
+ search_rows_scanned: this.searchRowsScanned,
134
+ search_rows_returned: this.searchRowsReturned,
135
+ search_indexed_zero_shortcircuit_count: this.searchIndexedZeroShortcircuitCount,
136
+ reindex_count: this.reindexCount,
137
+ reindex_skip_count: this.reindexSkipCount,
138
+ cache_evictions: this.cacheEvictions,
139
+ cache_entries: this.cacheEntries,
140
+ cache_total_content_bytes: this.cacheTotalContentBytes,
141
+ cache_artifact_bytes_lru: this.cacheArtifactBytesLru,
142
+ cache_hit_rate: this.resolveCacheHitRate(),
143
+ repo_failover_count: this.repoFailoverCount
144
+ };
145
+ }
146
+ toSnapshot(name) {
147
+ const timing = this.timings.get(name);
148
+ const count = timing?.count ?? 0;
149
+ const totalMs = timing?.totalMs ?? 0;
150
+ return {
151
+ count,
152
+ totalMs,
153
+ avgMs: count > 0 ? totalMs / count : 0,
154
+ lastMs: timing?.lastMs ?? 0
155
+ };
156
+ }
157
+ resolveCacheHitRate() {
158
+ const denominator = this.cacheHits + this.cacheMisses;
159
+ if (denominator === 0) {
160
+ return 0;
161
+ }
162
+ return this.cacheHits / denominator;
163
+ }
164
+ }
165
+ //# sourceMappingURL=observability.js.map
@@ -0,0 +1,12 @@
1
+ export interface PathRuntimeInfo {
2
+ platform: NodeJS.Platform;
3
+ isWsl: boolean;
4
+ wslDistro?: string;
5
+ }
6
+ export declare function detectPathRuntime(): PathRuntimeInfo;
7
+ export declare function isWindowsDrivePath(pathValue: string): boolean;
8
+ export declare function isWslMountPath(pathValue: string): boolean;
9
+ export declare function isUncWslPath(pathValue: string): boolean;
10
+ export declare function validatePathFormat(pathValue: string, runtimeInfo?: PathRuntimeInfo): string | undefined;
11
+ export declare function normalizePathForHost(pathValue: string, runtimeInfo?: PathRuntimeInfo, field?: string): string;
12
+ export declare function normalizeOptionalPathForHost(pathValue: string | undefined, runtimeInfo?: PathRuntimeInfo, field?: string): string | undefined;