@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,160 @@
1
+ export const SCHEMA_V1_STATEMENTS = [
2
+ `CREATE TABLE IF NOT EXISTS artifacts (
3
+ artifact_id TEXT PRIMARY KEY,
4
+ origin TEXT NOT NULL,
5
+ coordinate TEXT,
6
+ binary_jar_path TEXT,
7
+ source_jar_path TEXT,
8
+ repo_url TEXT,
9
+ is_decompiled INTEGER NOT NULL CHECK (is_decompiled IN (0,1)),
10
+ artifact_signature TEXT,
11
+ version TEXT,
12
+ requested_mapping TEXT,
13
+ mapping_applied TEXT,
14
+ provenance_json TEXT,
15
+ quality_flags_json TEXT,
16
+ created_at TEXT NOT NULL,
17
+ updated_at TEXT NOT NULL
18
+ )`,
19
+ `CREATE TABLE IF NOT EXISTS files (
20
+ artifact_id TEXT NOT NULL,
21
+ file_path TEXT NOT NULL,
22
+ content TEXT NOT NULL,
23
+ content_bytes INTEGER NOT NULL,
24
+ content_hash TEXT NOT NULL,
25
+ PRIMARY KEY (artifact_id, file_path),
26
+ FOREIGN KEY (artifact_id) REFERENCES artifacts(artifact_id) ON DELETE CASCADE
27
+ )`,
28
+ `CREATE VIRTUAL TABLE IF NOT EXISTS files_fts USING fts5(
29
+ artifact_id UNINDEXED,
30
+ file_path,
31
+ content,
32
+ tokenize = 'unicode61 separators ''._$'''
33
+ )`,
34
+ `CREATE TABLE IF NOT EXISTS symbols (
35
+ artifact_id TEXT NOT NULL,
36
+ file_path TEXT NOT NULL,
37
+ symbol_kind TEXT NOT NULL,
38
+ symbol_name TEXT NOT NULL,
39
+ qualified_name TEXT,
40
+ line INTEGER NOT NULL,
41
+ PRIMARY KEY (artifact_id, file_path, symbol_kind, symbol_name, line),
42
+ FOREIGN KEY (artifact_id, file_path) REFERENCES files(artifact_id, file_path) ON DELETE CASCADE
43
+ )`,
44
+ `CREATE TABLE IF NOT EXISTS artifact_index_meta (
45
+ artifact_id TEXT PRIMARY KEY,
46
+ artifact_signature TEXT NOT NULL,
47
+ index_schema_version INTEGER NOT NULL,
48
+ files_count INTEGER NOT NULL,
49
+ symbols_count INTEGER NOT NULL,
50
+ fts_rows_count INTEGER NOT NULL,
51
+ indexed_at TEXT NOT NULL,
52
+ index_duration_ms INTEGER NOT NULL,
53
+ last_error TEXT,
54
+ FOREIGN KEY (artifact_id) REFERENCES artifacts(artifact_id) ON DELETE CASCADE
55
+ )`,
56
+ `CREATE TABLE IF NOT EXISTS artifact_content_bytes (
57
+ artifact_id TEXT PRIMARY KEY,
58
+ total_content_bytes INTEGER NOT NULL CHECK (total_content_bytes >= 0),
59
+ FOREIGN KEY (artifact_id) REFERENCES artifacts(artifact_id) ON DELETE CASCADE
60
+ )`,
61
+ `CREATE INDEX IF NOT EXISTS idx_files_artifact ON files(artifact_id)`,
62
+ `CREATE INDEX IF NOT EXISTS idx_files_path ON files(artifact_id, file_path)`,
63
+ `CREATE INDEX IF NOT EXISTS idx_symbols_lookup ON symbols(artifact_id, symbol_kind, symbol_name)`,
64
+ `CREATE INDEX IF NOT EXISTS idx_symbols_qname ON symbols(artifact_id, qualified_name)`,
65
+ `CREATE INDEX IF NOT EXISTS idx_artifacts_updated_at ON artifacts(updated_at)`,
66
+ `CREATE INDEX IF NOT EXISTS idx_index_meta_indexed_at ON artifact_index_meta(indexed_at)`,
67
+ `CREATE INDEX IF NOT EXISTS idx_symbols_name_lower ON symbols(artifact_id, lower(symbol_name))`,
68
+ `CREATE INDEX IF NOT EXISTS idx_symbols_file_line ON symbols(artifact_id, file_path, line)`,
69
+ `CREATE INDEX IF NOT EXISTS idx_symbols_kind_file ON symbols(artifact_id, symbol_kind, file_path)`,
70
+ `CREATE INDEX IF NOT EXISTS idx_artifact_content_bytes_total ON artifact_content_bytes(total_content_bytes)`,
71
+ `CREATE INDEX IF NOT EXISTS idx_symbols_scoped_lookup
72
+ ON symbols(artifact_id, symbol_kind, lower(symbol_name), file_path, line)`,
73
+ `CREATE INDEX IF NOT EXISTS idx_symbols_scoped_lookup_no_kind
74
+ ON symbols(artifact_id, lower(symbol_name), file_path, line)`,
75
+ `INSERT INTO artifact_content_bytes (artifact_id, total_content_bytes)
76
+ SELECT
77
+ artifacts.artifact_id,
78
+ COALESCE(
79
+ SUM(
80
+ CASE
81
+ WHEN files.content_bytes > 0 THEN files.content_bytes
82
+ ELSE 0
83
+ END
84
+ ),
85
+ 0
86
+ ) AS total_content_bytes
87
+ FROM artifacts
88
+ LEFT JOIN files ON files.artifact_id = artifacts.artifact_id
89
+ GROUP BY artifacts.artifact_id
90
+ ON CONFLICT(artifact_id) DO UPDATE SET
91
+ total_content_bytes = excluded.total_content_bytes`,
92
+ `DELETE FROM artifact_content_bytes
93
+ WHERE artifact_id NOT IN (SELECT artifact_id FROM artifacts)`,
94
+ `CREATE TRIGGER IF NOT EXISTS trg_files_content_bytes_insert
95
+ AFTER INSERT ON files
96
+ BEGIN
97
+ INSERT INTO artifact_content_bytes (artifact_id, total_content_bytes)
98
+ VALUES (
99
+ NEW.artifact_id,
100
+ CASE
101
+ WHEN NEW.content_bytes > 0 THEN NEW.content_bytes
102
+ ELSE 0
103
+ END
104
+ )
105
+ ON CONFLICT(artifact_id) DO UPDATE SET
106
+ total_content_bytes = artifact_content_bytes.total_content_bytes + (
107
+ CASE
108
+ WHEN NEW.content_bytes > 0 THEN NEW.content_bytes
109
+ ELSE 0
110
+ END
111
+ );
112
+ END`,
113
+ `CREATE TRIGGER IF NOT EXISTS trg_files_content_bytes_delete
114
+ AFTER DELETE ON files
115
+ BEGIN
116
+ UPDATE artifact_content_bytes
117
+ SET total_content_bytes = MAX(
118
+ 0,
119
+ total_content_bytes - (
120
+ CASE
121
+ WHEN OLD.content_bytes > 0 THEN OLD.content_bytes
122
+ ELSE 0
123
+ END
124
+ )
125
+ )
126
+ WHERE artifact_id = OLD.artifact_id;
127
+ END`,
128
+ `CREATE TRIGGER IF NOT EXISTS trg_files_content_bytes_update
129
+ AFTER UPDATE OF artifact_id, content_bytes ON files
130
+ BEGIN
131
+ UPDATE artifact_content_bytes
132
+ SET total_content_bytes = MAX(
133
+ 0,
134
+ total_content_bytes - (
135
+ CASE
136
+ WHEN OLD.content_bytes > 0 THEN OLD.content_bytes
137
+ ELSE 0
138
+ END
139
+ )
140
+ )
141
+ WHERE artifact_id = OLD.artifact_id;
142
+
143
+ INSERT INTO artifact_content_bytes (artifact_id, total_content_bytes)
144
+ VALUES (
145
+ NEW.artifact_id,
146
+ CASE
147
+ WHEN NEW.content_bytes > 0 THEN NEW.content_bytes
148
+ ELSE 0
149
+ END
150
+ )
151
+ ON CONFLICT(artifact_id) DO UPDATE SET
152
+ total_content_bytes = artifact_content_bytes.total_content_bytes + (
153
+ CASE
154
+ WHEN NEW.content_bytes > 0 THEN NEW.content_bytes
155
+ ELSE 0
156
+ END
157
+ );
158
+ END`
159
+ ];
160
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1,20 @@
1
+ import { type StatementSync } from "node:sqlite";
2
+ export declare class Statement<T = unknown> {
3
+ private readonly stmt;
4
+ constructor(stmt: StatementSync);
5
+ run(...params: unknown[]): unknown;
6
+ get(...params: unknown[]): T | undefined;
7
+ all(...params: unknown[]): T[];
8
+ iterate(...params: unknown[]): Iterable<T>;
9
+ private invoke;
10
+ }
11
+ export default class Database {
12
+ private readonly inner;
13
+ private transactionDepth;
14
+ constructor(path: string);
15
+ pragma(pragma: string): unknown;
16
+ prepare<T = Record<string, unknown>>(sql: string): Statement<T>;
17
+ transaction<T>(fn: () => T): () => T;
18
+ close(): void;
19
+ private runInTransaction;
20
+ }
@@ -0,0 +1,111 @@
1
+ import { DatabaseSync } from "node:sqlite";
2
+ function isPlainObject(value) {
3
+ if (value === null || typeof value !== "object" || Array.isArray(value) || ArrayBuffer.isView(value)) {
4
+ return false;
5
+ }
6
+ const prototype = Object.getPrototypeOf(value);
7
+ return prototype === Object.prototype || prototype === null;
8
+ }
9
+ function normalizeParameters(args) {
10
+ if (args.length === 1) {
11
+ const [single] = args;
12
+ if (Array.isArray(single)) {
13
+ return { positional: single };
14
+ }
15
+ if (isPlainObject(single)) {
16
+ return { named: single };
17
+ }
18
+ }
19
+ return { positional: args };
20
+ }
21
+ export class Statement {
22
+ stmt;
23
+ constructor(stmt) {
24
+ this.stmt = stmt;
25
+ }
26
+ run(...params) {
27
+ return this.invoke("run", params);
28
+ }
29
+ get(...params) {
30
+ return this.invoke("get", params);
31
+ }
32
+ all(...params) {
33
+ return this.invoke("all", params);
34
+ }
35
+ iterate(...params) {
36
+ return this.invoke("iterate", params);
37
+ }
38
+ invoke(method, params) {
39
+ const normalized = normalizeParameters(params);
40
+ const target = this.stmt[method];
41
+ if (normalized.named !== undefined) {
42
+ return target.call(this.stmt, normalized.named);
43
+ }
44
+ return target.call(this.stmt, ...(normalized.positional ?? []));
45
+ }
46
+ }
47
+ let transactionSerial = 0;
48
+ export default class Database {
49
+ inner;
50
+ transactionDepth = 0;
51
+ constructor(path) {
52
+ this.inner = new DatabaseSync(path);
53
+ }
54
+ pragma(pragma) {
55
+ const sql = `PRAGMA ${pragma}`;
56
+ if (pragma.includes("=")) {
57
+ this.inner.exec(sql);
58
+ return undefined;
59
+ }
60
+ return this.inner.prepare(sql).all();
61
+ }
62
+ prepare(sql) {
63
+ return new Statement(this.inner.prepare(sql));
64
+ }
65
+ transaction(fn) {
66
+ return () => this.runInTransaction(fn);
67
+ }
68
+ close() {
69
+ this.inner.close();
70
+ }
71
+ runInTransaction(fn) {
72
+ const initialDepth = this.transactionDepth;
73
+ const isOutermost = initialDepth === 0;
74
+ const savepoint = `sp_${++transactionSerial}`;
75
+ try {
76
+ if (isOutermost) {
77
+ this.inner.exec("BEGIN");
78
+ }
79
+ else {
80
+ this.inner.exec(`SAVEPOINT ${savepoint}`);
81
+ }
82
+ this.transactionDepth = initialDepth + 1;
83
+ const result = fn();
84
+ this.transactionDepth = initialDepth;
85
+ if (isOutermost) {
86
+ this.inner.exec("COMMIT");
87
+ }
88
+ else {
89
+ this.inner.exec(`RELEASE SAVEPOINT ${savepoint}`);
90
+ }
91
+ return result;
92
+ }
93
+ catch (error) {
94
+ this.transactionDepth = initialDepth;
95
+ try {
96
+ if (isOutermost) {
97
+ this.inner.exec("ROLLBACK");
98
+ }
99
+ else {
100
+ this.inner.exec(`ROLLBACK TO SAVEPOINT ${savepoint}`);
101
+ this.inner.exec(`RELEASE SAVEPOINT ${savepoint}`);
102
+ }
103
+ }
104
+ catch {
105
+ // best-effort rollback cleanup
106
+ }
107
+ throw error;
108
+ }
109
+ }
110
+ }
111
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1,63 @@
1
+ import Database from "./sqlite.js";
2
+ import type { PagedResult, SymbolRow } from "../types.js";
3
+ type SqliteDatabase = InstanceType<typeof Database>;
4
+ export interface IndexedSymbol {
5
+ filePath: string;
6
+ symbolKind: string;
7
+ symbolName: string;
8
+ qualifiedName: string | undefined;
9
+ line: number;
10
+ }
11
+ export interface FindSymbolsOptions {
12
+ artifactId: string;
13
+ symbolKind?: string;
14
+ symbolNamePrefix?: string;
15
+ exact?: boolean;
16
+ limit: number;
17
+ cursor?: string;
18
+ }
19
+ type ScopedSymbolMatch = "exact" | "prefix" | "contains";
20
+ export interface FindScopedSymbolsOptions {
21
+ artifactId: string;
22
+ query: string;
23
+ match: ScopedSymbolMatch;
24
+ symbolKind?: string;
25
+ packagePrefix?: string;
26
+ filePathLike?: string;
27
+ limit?: number;
28
+ cursor?: {
29
+ symbolName: string;
30
+ filePath: string;
31
+ line: number;
32
+ };
33
+ }
34
+ export declare class SymbolsRepo {
35
+ private readonly db;
36
+ private readonly deleteStmt;
37
+ private readonly insertStmt;
38
+ private readonly searchStmt;
39
+ private readonly searchExactStmt;
40
+ private readonly listByArtifactStmt;
41
+ private readonly listByArtifactKindStmt;
42
+ private readonly listByFileStmt;
43
+ constructor(db: SqliteDatabase);
44
+ clearSymbolsForArtifact(artifactId: string): void;
45
+ insertSymbolsForArtifact(artifactId: string, symbols: IndexedSymbol[]): void;
46
+ replaceSymbolsForArtifact(artifactId: string, symbols: IndexedSymbol[]): void;
47
+ findSymbols(options: FindSymbolsOptions): PagedResult<SymbolRow>;
48
+ listSymbolsForArtifact(artifactId: string, symbolKind?: string): SymbolRow[];
49
+ listSymbolsForFile(artifactId: string, filePath: string): SymbolRow[];
50
+ listSymbolsForFiles(artifactId: string, filePaths: string[], symbolKind?: string): Map<string, SymbolRow[]>;
51
+ findBySymbolNames(artifactId: string, symbolNames: string[]): SymbolRow[];
52
+ findScopedSymbols(options: FindScopedSymbolsOptions): PagedResult<SymbolRow>;
53
+ countScopedSymbols(options: {
54
+ artifactId: string;
55
+ query: string;
56
+ match: ScopedSymbolMatch;
57
+ symbolKind?: string;
58
+ packagePrefix?: string;
59
+ }): number;
60
+ listDistinctFilePathsByKind(artifactId: string, symbolKind: string): string[];
61
+ findBestClassFilePath(artifactId: string, className: string, simpleName: string): string | undefined;
62
+ }
63
+ export {};