magatama-core 0.5.0__tar.gz

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 (109) hide show
  1. magatama_core-0.5.0/.gitignore +120 -0
  2. magatama_core-0.5.0/PKG-INFO +192 -0
  3. magatama_core-0.5.0/README.md +126 -0
  4. magatama_core-0.5.0/pyproject.toml +92 -0
  5. magatama_core-0.5.0/src/magatama_core/__init__.py +41 -0
  6. magatama_core-0.5.0/src/magatama_core/application/__init__.py +17 -0
  7. magatama_core-0.5.0/src/magatama_core/application/services/__init__.py +29 -0
  8. magatama_core-0.5.0/src/magatama_core/application/services/benchmark.py +391 -0
  9. magatama_core-0.5.0/src/magatama_core/application/services/graph_validator.py +252 -0
  10. magatama_core-0.5.0/src/magatama_core/application/usecases/__init__.py +113 -0
  11. magatama_core-0.5.0/src/magatama_core/application/usecases/comp_usecase.py +81 -0
  12. magatama_core-0.5.0/src/magatama_core/application/usecases/framework_usecase.py +3806 -0
  13. magatama_core-0.5.0/src/magatama_core/application/usecases/parse_usecase.py +448 -0
  14. magatama_core-0.5.0/src/magatama_core/domain/__init__.py +9 -0
  15. magatama_core-0.5.0/src/magatama_core/domain/entities/__init__.py +39 -0
  16. magatama_core-0.5.0/src/magatama_core/domain/entities/base.py +73 -0
  17. magatama_core-0.5.0/src/magatama_core/domain/entities/code_entities.py +191 -0
  18. magatama_core-0.5.0/src/magatama_core/domain/entities/relationships.py +84 -0
  19. magatama_core-0.5.0/src/magatama_core/domain/errors.py +211 -0
  20. magatama_core-0.5.0/src/magatama_core/domain/repositories/__init__.py +17 -0
  21. magatama_core-0.5.0/src/magatama_core/domain/repositories/entity_repository.py +119 -0
  22. magatama_core-0.5.0/src/magatama_core/domain/repositories/knowledge_graph_repository.py +170 -0
  23. magatama_core-0.5.0/src/magatama_core/domain/repositories/relationship_repository.py +100 -0
  24. magatama_core-0.5.0/src/magatama_core/domain/value_objects/__init__.py +17 -0
  25. magatama_core-0.5.0/src/magatama_core/domain/value_objects/ids.py +101 -0
  26. magatama_core-0.5.0/src/magatama_core/domain/value_objects/location.py +53 -0
  27. magatama_core-0.5.0/src/magatama_core/domain/value_objects/version.py +129 -0
  28. magatama_core-0.5.0/src/magatama_core/infrastructure/__init__.py +44 -0
  29. magatama_core-0.5.0/src/magatama_core/infrastructure/config.py +164 -0
  30. magatama_core-0.5.0/src/magatama_core/infrastructure/github/__init__.py +6 -0
  31. magatama_core-0.5.0/src/magatama_core/infrastructure/logging.py +258 -0
  32. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/__init__.py +60 -0
  33. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/c_parser.py +287 -0
  34. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/cpp_parser.py +313 -0
  35. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/csharp_parser.py +983 -0
  36. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/dart_parser.py +408 -0
  37. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/elixir_parser.py +282 -0
  38. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/go_parser.py +607 -0
  39. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/groovy_parser.py +347 -0
  40. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/haskell_parser.py +246 -0
  41. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/java_parser.py +713 -0
  42. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/javascript_parser.py +566 -0
  43. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/julia_parser.py +339 -0
  44. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/kotlin_parser.py +363 -0
  45. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/lua_parser.py +180 -0
  46. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/objc_parser.py +320 -0
  47. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/parse_result.py +35 -0
  48. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/php_parser.py +383 -0
  49. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/python_parser.py +583 -0
  50. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/ruby_parser.py +540 -0
  51. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/rust_parser.py +730 -0
  52. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/scala_parser.py +327 -0
  53. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/sql_parser.py +353 -0
  54. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/swift_parser.py +364 -0
  55. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/typescript_parser.py +659 -0
  56. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/yaml_parser.py +195 -0
  57. magatama_core-0.5.0/src/magatama_core/infrastructure/parsers/zig_parser.py +272 -0
  58. magatama_core-0.5.0/src/magatama_core/infrastructure/storage/__init__.py +36 -0
  59. magatama_core-0.5.0/src/magatama_core/infrastructure/storage/comp_index_reader.py +223 -0
  60. magatama_core-0.5.0/src/magatama_core/infrastructure/storage/in_memory_repository.py +130 -0
  61. magatama_core-0.5.0/src/magatama_core/infrastructure/storage/networkx_graph.py +385 -0
  62. magatama_core-0.5.0/src/magatama_core/infrastructure/storage/sqlite_storage.py +936 -0
  63. magatama_core-0.5.0/tests/__init__.py +7 -0
  64. magatama_core-0.5.0/tests/application/__init__.py +1 -0
  65. magatama_core-0.5.0/tests/application/test_benchmark.py +220 -0
  66. magatama_core-0.5.0/tests/application/test_comp_usecase.py +152 -0
  67. magatama_core-0.5.0/tests/application/test_framework_usecase.py +970 -0
  68. magatama_core-0.5.0/tests/application/test_graph_validator.py +274 -0
  69. magatama_core-0.5.0/tests/application/test_parse_usecase.py +464 -0
  70. magatama_core-0.5.0/tests/application/test_performance.py +686 -0
  71. magatama_core-0.5.0/tests/application/test_phase1_usecases.py +606 -0
  72. magatama_core-0.5.0/tests/application/test_phase2_usecases.py +566 -0
  73. magatama_core-0.5.0/tests/application/test_phase3_usecases.py +696 -0
  74. magatama_core-0.5.0/tests/domain/__init__.py +3 -0
  75. magatama_core-0.5.0/tests/domain/test_entities.py +260 -0
  76. magatama_core-0.5.0/tests/domain/test_errors.py +137 -0
  77. magatama_core-0.5.0/tests/domain/test_repositories.py +177 -0
  78. magatama_core-0.5.0/tests/domain/test_value_objects.py +189 -0
  79. magatama_core-0.5.0/tests/infrastructure/__init__.py +5 -0
  80. magatama_core-0.5.0/tests/infrastructure/test_c_parser.py +151 -0
  81. magatama_core-0.5.0/tests/infrastructure/test_comp_index_reader.py +281 -0
  82. magatama_core-0.5.0/tests/infrastructure/test_config.py +122 -0
  83. magatama_core-0.5.0/tests/infrastructure/test_cpp_parser.py +109 -0
  84. magatama_core-0.5.0/tests/infrastructure/test_csharp_parser.py +410 -0
  85. magatama_core-0.5.0/tests/infrastructure/test_dart_parser.py +213 -0
  86. magatama_core-0.5.0/tests/infrastructure/test_elixir_parser.py +272 -0
  87. magatama_core-0.5.0/tests/infrastructure/test_go_parser.py +241 -0
  88. magatama_core-0.5.0/tests/infrastructure/test_groovy_parser.py +266 -0
  89. magatama_core-0.5.0/tests/infrastructure/test_haskell_parser.py +93 -0
  90. magatama_core-0.5.0/tests/infrastructure/test_in_memory_repository.py +314 -0
  91. magatama_core-0.5.0/tests/infrastructure/test_java_parser.py +290 -0
  92. magatama_core-0.5.0/tests/infrastructure/test_javascript_parser.py +352 -0
  93. magatama_core-0.5.0/tests/infrastructure/test_julia_parser.py +216 -0
  94. magatama_core-0.5.0/tests/infrastructure/test_kotlin_parser.py +215 -0
  95. magatama_core-0.5.0/tests/infrastructure/test_logging.py +179 -0
  96. magatama_core-0.5.0/tests/infrastructure/test_lua_parser.py +95 -0
  97. magatama_core-0.5.0/tests/infrastructure/test_networkx_graph.py +175 -0
  98. magatama_core-0.5.0/tests/infrastructure/test_objc_parser.py +209 -0
  99. magatama_core-0.5.0/tests/infrastructure/test_php_parser.py +108 -0
  100. magatama_core-0.5.0/tests/infrastructure/test_python_parser.py +470 -0
  101. magatama_core-0.5.0/tests/infrastructure/test_ruby_parser.py +228 -0
  102. magatama_core-0.5.0/tests/infrastructure/test_rust_parser.py +214 -0
  103. magatama_core-0.5.0/tests/infrastructure/test_scala_parser.py +104 -0
  104. magatama_core-0.5.0/tests/infrastructure/test_sql_parser.py +226 -0
  105. magatama_core-0.5.0/tests/infrastructure/test_sqlite_storage.py +729 -0
  106. magatama_core-0.5.0/tests/infrastructure/test_swift_parser.py +252 -0
  107. magatama_core-0.5.0/tests/infrastructure/test_typescript_parser.py +287 -0
  108. magatama_core-0.5.0/tests/infrastructure/test_yaml_parser.py +168 -0
  109. magatama_core-0.5.0/tests/infrastructure/test_zig_parser.py +248 -0
@@ -0,0 +1,120 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ *.py,cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+ cover/
51
+
52
+ # Translations
53
+ *.mo
54
+ *.pot
55
+
56
+ # Environments
57
+ .env
58
+ .venv
59
+ env/
60
+ venv/
61
+ ENV/
62
+ env.bak/
63
+ venv.bak/
64
+
65
+ # Spyder project settings
66
+ .spyderproject
67
+ .spyproject
68
+
69
+ # Rope project settings
70
+ .ropeproject
71
+
72
+ # mkdocs documentation
73
+ /site
74
+
75
+ # mypy
76
+ .mypy_cache/
77
+ .dmypy.json
78
+ dmypy.json
79
+
80
+ # Pyre type checker
81
+ .pyre/
82
+
83
+ # pytype static type analyzer
84
+ .pytype/
85
+
86
+ # Cython debug symbols
87
+ cython_debug/
88
+
89
+ # IDE
90
+ .idea/
91
+ .vscode/
92
+ *.swp
93
+ *.swo
94
+ *~
95
+
96
+ # OS
97
+ .DS_Store
98
+ Thumbs.db
99
+
100
+ # Project specific
101
+ *.db
102
+ *.sqlite
103
+ *.sqlite3
104
+ .yata/
105
+ storage/archive/*
106
+ storage/changes/*
107
+ !storage/archive/.gitkeep
108
+ !storage/changes/.gitkeep
109
+
110
+ # Framework knowledge repositories (cloned for analysis)
111
+ frameworks/*
112
+ !frameworks/.gitkeep
113
+
114
+ # UV
115
+ .uv/
116
+ uv.lock
117
+
118
+ # comP
119
+ .comp/
120
+ plan.md
@@ -0,0 +1,192 @@
1
+ Metadata-Version: 2.4
2
+ Name: magatama-core
3
+ Version: 0.5.0
4
+ Summary: MAGATAMA Core - Knowledge Graph Engine for Code Analysis
5
+ Project-URL: Homepage, https://github.com/tsucky230/MAGATAMA
6
+ Project-URL: Repository, https://github.com/tsucky230/MAGATAMA
7
+ Project-URL: Documentation, https://github.com/tsucky230/MAGATAMA#readme
8
+ Project-URL: Issues, https://github.com/tsucky230/MAGATAMA/issues
9
+ Author: MAGATAMA Team
10
+ License: MIT
11
+ Keywords: ast-parser,code-analysis,knowledge-graph,tree-sitter
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Code Generators
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: networkx>=3.2.0
21
+ Requires-Dist: pydantic-settings>=2.1.0
22
+ Requires-Dist: pydantic>=2.5.0
23
+ Requires-Dist: structlog>=24.0.0
24
+ Requires-Dist: tomli>=2.0.0; python_version < '3.11'
25
+ Requires-Dist: tree-sitter-c-sharp>=0.23.0
26
+ Requires-Dist: tree-sitter-c>=0.24.0
27
+ Requires-Dist: tree-sitter-cpp>=0.23.0
28
+ Requires-Dist: tree-sitter-elixir>=0.3.0
29
+ Requires-Dist: tree-sitter-go>=0.25.0
30
+ Requires-Dist: tree-sitter-groovy>=0.1.0
31
+ Requires-Dist: tree-sitter-haskell>=0.23.0
32
+ Requires-Dist: tree-sitter-java>=0.23.0
33
+ Requires-Dist: tree-sitter-javascript>=0.24.0
34
+ Requires-Dist: tree-sitter-julia>=0.23.0
35
+ Requires-Dist: tree-sitter-kotlin>=1.1.0
36
+ Requires-Dist: tree-sitter-lua>=0.2.0
37
+ Requires-Dist: tree-sitter-objc>=3.0.0
38
+ Requires-Dist: tree-sitter-php>=0.24.0
39
+ Requires-Dist: tree-sitter-python>=0.24.0
40
+ Requires-Dist: tree-sitter-ruby>=0.23.0
41
+ Requires-Dist: tree-sitter-rust>=0.24.0
42
+ Requires-Dist: tree-sitter-scala>=0.24.0
43
+ Requires-Dist: tree-sitter-sql>=0.3.0
44
+ Requires-Dist: tree-sitter-swift>=0.0.1
45
+ Requires-Dist: tree-sitter-typescript>=0.23.0
46
+ Requires-Dist: tree-sitter-yaml>=0.7.0
47
+ Requires-Dist: tree-sitter-zig>=1.0.0
48
+ Requires-Dist: tree-sitter>=0.24.0
49
+ Provides-Extra: all-languages
50
+ Requires-Dist: tree-sitter-c-sharp>=0.23.0; extra == 'all-languages'
51
+ Requires-Dist: tree-sitter-java>=0.23.0; extra == 'all-languages'
52
+ Requires-Dist: tree-sitter-ruby>=0.23.0; extra == 'all-languages'
53
+ Provides-Extra: csharp
54
+ Requires-Dist: tree-sitter-c-sharp>=0.23.0; extra == 'csharp'
55
+ Provides-Extra: dev
56
+ Requires-Dist: mypy>=1.9.0; extra == 'dev'
57
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
58
+ Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
59
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
60
+ Requires-Dist: ruff>=0.4.0; extra == 'dev'
61
+ Provides-Extra: java
62
+ Requires-Dist: tree-sitter-java>=0.23.0; extra == 'java'
63
+ Provides-Extra: ruby
64
+ Requires-Dist: tree-sitter-ruby>=0.23.0; extra == 'ruby'
65
+ Description-Content-Type: text/markdown
66
+
67
+ # magatama-core - Knowledge Graph Engine
68
+
69
+ [![PyPI version](https://badge.fury.io/py/magatama-core.svg)](https://badge.fury.io/py/magatama-core)
70
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
71
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
72
+
73
+ > [MAGATAMA](https://github.com/tsucky230/MAGATAMA)([YATA](https://github.com/nahisaho/YATA) のフォーク)の
74
+ > コアライブラリパッケージです(パッケージ名 `magatama-core` / import 名 `magatama_core`)。
75
+
76
+ 独立したライブラリとして、コード解析と知識グラフ構築機能を提供します。
77
+
78
+ ## 特徴
79
+
80
+ - 🔍 **マルチ言語解析**: Python, TypeScript, JavaScript, Rust, Go
81
+ - 🕸️ **知識グラフ**: NetworkX によるエンティティ・関係性グラフ
82
+ - 🔗 **関係性検出**: CALLS, IMPORTS, CONTAINS, INHERITS
83
+ - 💾 **永続化**: JSON / SQLite ストレージ
84
+
85
+ ## インストール
86
+
87
+ ```bash
88
+ pip install magatama-core
89
+ ```
90
+
91
+ ### オプション言語サポート
92
+
93
+ ```bash
94
+ # Rust サポート
95
+ pip install magatama-core[rust]
96
+
97
+ # Go サポート
98
+ pip install magatama-core[go]
99
+
100
+ # 全言語サポート
101
+ pip install magatama-core[all-languages]
102
+ ```
103
+
104
+ ## 使用方法
105
+
106
+ ### 基本的な使い方
107
+
108
+ ```python
109
+ from magatama_core.infrastructure.parsers import PythonParser
110
+ from magatama_core.infrastructure.storage import NetworkXKnowledgeGraph
111
+ from magatama_core.application.usecases import ParseFileUseCase
112
+
113
+ # パーサーとグラフを作成
114
+ parser = PythonParser()
115
+ graph = NetworkXKnowledgeGraph()
116
+
117
+ # ユースケースを設定
118
+ parse_file = ParseFileUseCase(
119
+ parsers={".py": parser},
120
+ knowledge_graph=graph,
121
+ )
122
+
123
+ # ファイルを解析
124
+ from pathlib import Path
125
+ result = parse_file.execute(Path("your_file.py"))
126
+
127
+ print(f"Entities: {result.entity_count}")
128
+ print(f"Relationships: {result.relationship_count}")
129
+ ```
130
+
131
+ ### エンティティの検索
132
+
133
+ ```python
134
+ from magatama_core.domain.entities import EntityType
135
+
136
+ # 関数をすべて取得
137
+ functions = list(graph.entities.get_by_type(EntityType.FUNCTION))
138
+
139
+ # 名前で検索
140
+ all_entities = list(graph.entities.all())
141
+ matches = [e for e in all_entities if "process" in e.name.lower()]
142
+ ```
143
+
144
+ ### グラフの永続化
145
+
146
+ ```python
147
+ from magatama_core.infrastructure.storage import JSONGraphSerializer
148
+
149
+ serializer = JSONGraphSerializer()
150
+
151
+ # 保存
152
+ serializer.save(graph, Path("graph.json"))
153
+
154
+ # 読み込み
155
+ loaded_graph = serializer.load(Path("graph.json"))
156
+ ```
157
+
158
+ ## アーキテクチャ
159
+
160
+ magatama-core は Clean Architecture に基づいて設計されています:
161
+
162
+ ```
163
+ magatama_core/
164
+ ├── domain/ # ドメイン層
165
+ │ ├── entities/ # FunctionEntity, ClassEntity, etc.
166
+ │ ├── value_objects/ # EntityId, Location
167
+ │ └── repositories/ # インターフェース
168
+ ├── application/ # アプリケーション層
169
+ │ ├── usecases/ # ParseFileUseCase, etc.
170
+ │ └── services/ # Benchmark, etc.
171
+ └── infrastructure/ # インフラ層
172
+ ├── parsers/ # PythonParser, TypeScriptParser, etc.
173
+ └── storage/ # NetworkXKnowledgeGraph, SQLiteKnowledgeGraph
174
+ ```
175
+
176
+ ## 対応言語
177
+
178
+ | 言語 | 拡張子 | パーサー |
179
+ |------|--------|----------|
180
+ | Python | `.py` | `PythonParser` |
181
+ | TypeScript | `.ts`, `.tsx` | `TypeScriptParser` |
182
+ | JavaScript | `.js`, `.jsx` | `JavaScriptParser` |
183
+ | Rust | `.rs` | `RustParser` |
184
+ | Go | `.go` | `GoParser` |
185
+
186
+ ## ライセンス
187
+
188
+ MIT License - 詳細は [LICENSE](../../LICENSE) を参照してください。
189
+
190
+ ## 関連プロジェクト
191
+
192
+ - [magatama-mcp](https://github.com/tsucky230/MAGATAMA/tree/main/packages/magatama-mcp) - MCP Server
@@ -0,0 +1,126 @@
1
+ # magatama-core - Knowledge Graph Engine
2
+
3
+ [![PyPI version](https://badge.fury.io/py/magatama-core.svg)](https://badge.fury.io/py/magatama-core)
4
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ > [MAGATAMA](https://github.com/tsucky230/MAGATAMA)([YATA](https://github.com/nahisaho/YATA) のフォーク)の
8
+ > コアライブラリパッケージです(パッケージ名 `magatama-core` / import 名 `magatama_core`)。
9
+
10
+ 独立したライブラリとして、コード解析と知識グラフ構築機能を提供します。
11
+
12
+ ## 特徴
13
+
14
+ - 🔍 **マルチ言語解析**: Python, TypeScript, JavaScript, Rust, Go
15
+ - 🕸️ **知識グラフ**: NetworkX によるエンティティ・関係性グラフ
16
+ - 🔗 **関係性検出**: CALLS, IMPORTS, CONTAINS, INHERITS
17
+ - 💾 **永続化**: JSON / SQLite ストレージ
18
+
19
+ ## インストール
20
+
21
+ ```bash
22
+ pip install magatama-core
23
+ ```
24
+
25
+ ### オプション言語サポート
26
+
27
+ ```bash
28
+ # Rust サポート
29
+ pip install magatama-core[rust]
30
+
31
+ # Go サポート
32
+ pip install magatama-core[go]
33
+
34
+ # 全言語サポート
35
+ pip install magatama-core[all-languages]
36
+ ```
37
+
38
+ ## 使用方法
39
+
40
+ ### 基本的な使い方
41
+
42
+ ```python
43
+ from magatama_core.infrastructure.parsers import PythonParser
44
+ from magatama_core.infrastructure.storage import NetworkXKnowledgeGraph
45
+ from magatama_core.application.usecases import ParseFileUseCase
46
+
47
+ # パーサーとグラフを作成
48
+ parser = PythonParser()
49
+ graph = NetworkXKnowledgeGraph()
50
+
51
+ # ユースケースを設定
52
+ parse_file = ParseFileUseCase(
53
+ parsers={".py": parser},
54
+ knowledge_graph=graph,
55
+ )
56
+
57
+ # ファイルを解析
58
+ from pathlib import Path
59
+ result = parse_file.execute(Path("your_file.py"))
60
+
61
+ print(f"Entities: {result.entity_count}")
62
+ print(f"Relationships: {result.relationship_count}")
63
+ ```
64
+
65
+ ### エンティティの検索
66
+
67
+ ```python
68
+ from magatama_core.domain.entities import EntityType
69
+
70
+ # 関数をすべて取得
71
+ functions = list(graph.entities.get_by_type(EntityType.FUNCTION))
72
+
73
+ # 名前で検索
74
+ all_entities = list(graph.entities.all())
75
+ matches = [e for e in all_entities if "process" in e.name.lower()]
76
+ ```
77
+
78
+ ### グラフの永続化
79
+
80
+ ```python
81
+ from magatama_core.infrastructure.storage import JSONGraphSerializer
82
+
83
+ serializer = JSONGraphSerializer()
84
+
85
+ # 保存
86
+ serializer.save(graph, Path("graph.json"))
87
+
88
+ # 読み込み
89
+ loaded_graph = serializer.load(Path("graph.json"))
90
+ ```
91
+
92
+ ## アーキテクチャ
93
+
94
+ magatama-core は Clean Architecture に基づいて設計されています:
95
+
96
+ ```
97
+ magatama_core/
98
+ ├── domain/ # ドメイン層
99
+ │ ├── entities/ # FunctionEntity, ClassEntity, etc.
100
+ │ ├── value_objects/ # EntityId, Location
101
+ │ └── repositories/ # インターフェース
102
+ ├── application/ # アプリケーション層
103
+ │ ├── usecases/ # ParseFileUseCase, etc.
104
+ │ └── services/ # Benchmark, etc.
105
+ └── infrastructure/ # インフラ層
106
+ ├── parsers/ # PythonParser, TypeScriptParser, etc.
107
+ └── storage/ # NetworkXKnowledgeGraph, SQLiteKnowledgeGraph
108
+ ```
109
+
110
+ ## 対応言語
111
+
112
+ | 言語 | 拡張子 | パーサー |
113
+ |------|--------|----------|
114
+ | Python | `.py` | `PythonParser` |
115
+ | TypeScript | `.ts`, `.tsx` | `TypeScriptParser` |
116
+ | JavaScript | `.js`, `.jsx` | `JavaScriptParser` |
117
+ | Rust | `.rs` | `RustParser` |
118
+ | Go | `.go` | `GoParser` |
119
+
120
+ ## ライセンス
121
+
122
+ MIT License - 詳細は [LICENSE](../../LICENSE) を参照してください。
123
+
124
+ ## 関連プロジェクト
125
+
126
+ - [magatama-mcp](https://github.com/tsucky230/MAGATAMA/tree/main/packages/magatama-mcp) - MCP Server
@@ -0,0 +1,92 @@
1
+ # MAGATAMA Core - Knowledge Graph Engine Library
2
+ # Article I: Library-First Principle - Independent, reusable library
3
+ # Article II: CLI Interface Mandate - Exposes CLI
4
+
5
+ [project]
6
+ name = "magatama-core"
7
+ version = "0.5.0"
8
+ description = "MAGATAMA Core - Knowledge Graph Engine for Code Analysis"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.11"
12
+ authors = [{ name = "MAGATAMA Team" }]
13
+ keywords = ["knowledge-graph", "ast-parser", "code-analysis", "tree-sitter"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Topic :: Software Development :: Libraries :: Python Modules",
21
+ "Topic :: Software Development :: Code Generators",
22
+ ]
23
+ dependencies = [
24
+ # AST Parsing (ADR-003)
25
+ "tree-sitter>=0.24.0",
26
+ # Tree-sitter language parsers (24 languages)
27
+ "tree-sitter-python>=0.24.0",
28
+ "tree-sitter-javascript>=0.24.0",
29
+ "tree-sitter-typescript>=0.23.0",
30
+ "tree-sitter-rust>=0.24.0",
31
+ "tree-sitter-go>=0.25.0",
32
+ "tree-sitter-ruby>=0.23.0",
33
+ "tree-sitter-java>=0.23.0",
34
+ "tree-sitter-c-sharp>=0.23.0",
35
+ "tree-sitter-cpp>=0.23.0",
36
+ "tree-sitter-objc>=3.0.0",
37
+ "tree-sitter-php>=0.24.0",
38
+ "tree-sitter-swift>=0.0.1",
39
+ "tree-sitter-kotlin>=1.1.0",
40
+ "tree-sitter-scala>=0.24.0",
41
+ "tree-sitter-lua>=0.2.0",
42
+ "tree-sitter-haskell>=0.23.0",
43
+ "tree-sitter-elixir>=0.3.0",
44
+ "tree-sitter-julia>=0.23.0",
45
+ "tree-sitter-sql>=0.3.0",
46
+ "tree-sitter-groovy>=0.1.0",
47
+ "tree-sitter-c>=0.24.0",
48
+ "tree-sitter-zig>=1.0.0",
49
+ "tree-sitter-yaml>=0.7.0",
50
+ # Graph Storage (ADR-004)
51
+ "networkx>=3.2.0",
52
+ # Data Validation
53
+ "pydantic>=2.5.0",
54
+ "pydantic-settings>=2.1.0",
55
+ # Utilities
56
+ "structlog>=24.0.0",
57
+ "tomli>=2.0.0;python_version<'3.11'",
58
+ ]
59
+
60
+ [project.urls]
61
+ Homepage = "https://github.com/tsucky230/MAGATAMA"
62
+ Repository = "https://github.com/tsucky230/MAGATAMA"
63
+ Documentation = "https://github.com/tsucky230/MAGATAMA#readme"
64
+ Issues = "https://github.com/tsucky230/MAGATAMA/issues"
65
+
66
+ [project.optional-dependencies]
67
+ ruby = ["tree-sitter-ruby>=0.23.0"]
68
+ java = ["tree-sitter-java>=0.23.0"]
69
+ csharp = ["tree-sitter-c-sharp>=0.23.0"]
70
+ all-languages = [
71
+ "tree-sitter-ruby>=0.23.0",
72
+ "tree-sitter-java>=0.23.0",
73
+ "tree-sitter-c-sharp>=0.23.0",
74
+ ]
75
+ dev = [
76
+ "pytest>=8.0.0",
77
+ "pytest-cov>=4.1.0",
78
+ "pytest-asyncio>=0.23.0",
79
+ "ruff>=0.4.0",
80
+ "mypy>=1.9.0",
81
+ ]
82
+
83
+ [project.scripts]
84
+ # Article II: CLI Interface Mandate
85
+ magatama-core = "magatama_core.cli:main"
86
+
87
+ [build-system]
88
+ requires = ["hatchling"]
89
+ build-backend = "hatchling.build"
90
+
91
+ [tool.hatch.build.targets.wheel]
92
+ packages = ["src/magatama_core"]
@@ -0,0 +1,41 @@
1
+ """
2
+ MAGATAMA Core - Knowledge Graph Engine Library
3
+
4
+ MAGATAMA (勾玉) is a knowledge graph engine for code analysis,
5
+ providing AST parsing and graph-based code understanding.
6
+
7
+ Article I Compliance: This is an independent library.
8
+ """
9
+
10
+ from magatama_core.domain.entities import (
11
+ ClassEntity,
12
+ Entity,
13
+ EntityType,
14
+ FunctionEntity,
15
+ MethodEntity,
16
+ ModuleEntity,
17
+ Relationship,
18
+ RelationshipType,
19
+ TypeEntity,
20
+ )
21
+ from magatama_core.domain.value_objects import EntityId, LibraryId, Location, Version
22
+
23
+ __version__ = "0.1.0"
24
+ __all__ = [
25
+ # Entities
26
+ "Entity",
27
+ "EntityType",
28
+ "ClassEntity",
29
+ "FunctionEntity",
30
+ "MethodEntity",
31
+ "ModuleEntity",
32
+ "TypeEntity",
33
+ # Relationships
34
+ "Relationship",
35
+ "RelationshipType",
36
+ # Value Objects
37
+ "EntityId",
38
+ "LibraryId",
39
+ "Location",
40
+ "Version",
41
+ ]
@@ -0,0 +1,17 @@
1
+ """
2
+ Application Layer - Use cases and application services.
3
+
4
+ This layer orchestrates domain objects to fulfill use cases.
5
+ """
6
+
7
+ from magatama_core.application.usecases.parse_usecase import (
8
+ ParseDirectoryUseCase,
9
+ ParseFileUseCase,
10
+ ParseResult,
11
+ )
12
+
13
+ __all__ = [
14
+ "ParseDirectoryUseCase",
15
+ "ParseFileUseCase",
16
+ "ParseResult",
17
+ ]
@@ -0,0 +1,29 @@
1
+ """
2
+ Application Services - Use case implementations.
3
+ """
4
+
5
+ from magatama_core.application.services.benchmark import (
6
+ Benchmark,
7
+ BenchmarkResult,
8
+ PerformanceProfiler,
9
+ measure_indexing_performance,
10
+ measure_query_performance,
11
+ )
12
+ from magatama_core.application.services.graph_validator import (
13
+ GraphValidator,
14
+ RepairResult,
15
+ ValidationIssue,
16
+ ValidationResult,
17
+ )
18
+
19
+ __all__ = [
20
+ "Benchmark",
21
+ "BenchmarkResult",
22
+ "GraphValidator",
23
+ "PerformanceProfiler",
24
+ "RepairResult",
25
+ "ValidationIssue",
26
+ "ValidationResult",
27
+ "measure_indexing_performance",
28
+ "measure_query_performance",
29
+ ]