musubix 3.3.9 → 3.4.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.
- package/.github/AGENTS.md +949 -0
- package/.github/prompts/sdd-change-apply.prompt.md +283 -0
- package/.github/prompts/sdd-change-archive.prompt.md +241 -0
- package/.github/prompts/sdd-change-init.prompt.md +269 -0
- package/.github/prompts/sdd-design.prompt.md +250 -0
- package/.github/prompts/sdd-implement.prompt.md +387 -0
- package/.github/prompts/sdd-requirements.prompt.md +193 -0
- package/.github/prompts/sdd-review.prompt.md +155 -0
- package/.github/prompts/sdd-security.prompt.md +228 -0
- package/.github/prompts/sdd-steering.prompt.md +269 -0
- package/.github/prompts/sdd-tasks.prompt.md +255 -0
- package/.github/prompts/sdd-test.prompt.md +230 -0
- package/.github/prompts/sdd-validate.prompt.md +304 -0
- package/.github/skills/musubix-adr-generation/SKILL.md +209 -0
- package/.github/skills/musubix-best-practices/SKILL.md +315 -0
- package/.github/skills/musubix-c4-design/SKILL.md +162 -0
- package/.github/skills/musubix-code-generation/SKILL.md +237 -0
- package/.github/skills/musubix-domain-inference/SKILL.md +196 -0
- package/.github/skills/musubix-ears-validation/SKILL.md +161 -0
- package/.github/skills/musubix-sdd-workflow/SKILL.md +217 -0
- package/.github/skills/musubix-technical-writing/SKILL.md +444 -0
- package/.github/skills/musubix-test-generation/SKILL.md +212 -0
- package/.github/skills/musubix-traceability/SKILL.md +141 -0
- package/AGENTS.md +1134 -0
- package/LICENSE +21 -0
- package/README.ja.md +313 -0
- package/README.md +315 -50
- package/bin/musubix-mcp.js +15 -0
- package/bin/musubix.js +9 -1
- package/docs/API-REFERENCE.md +1425 -0
- package/docs/GITHUB-ACTIONS-NPM-SETUP.md +132 -0
- package/docs/INSTALL-GUIDE.ja.md +459 -0
- package/docs/INSTALL-GUIDE.md +459 -0
- package/docs/MIGRATION-v3.0.md +324 -0
- package/docs/MUSUBI-enhancement_roadmap_20260105.md +651 -0
- package/docs/MUSUBIX-v3.0-User-Guide.md +1357 -0
- package/docs/MUSUBIXv2.2.0-Manual-outline.md +136 -0
- package/docs/MUSUBIXv2.2.0-Manual.md +3123 -0
- package/docs/MUSUBIXv2.3.5-Refactering.md +1310 -0
- package/docs/MUSUBIv1.6.1-enhancement_roadmap_20260105.md +291 -0
- package/docs/MUSUBIv2.2.0-USERGUIDE.md +2079 -0
- package/docs/ROADMAP-v1.5.md +116 -0
- package/docs/SwarmCoding.md +1284 -0
- package/docs/Test-prompt.md +105 -0
- package/docs/USER-GUIDE-v1.8.0.md +2371 -0
- package/docs/USER-GUIDE.ja.md +2147 -0
- package/docs/USER-GUIDE.md +3022 -0
- package/docs/YATA-GLOBAL-GUIDE.ja.md +750 -0
- package/docs/YATA-GLOBAL-GUIDE.md +595 -0
- package/docs/YATA-LOCAL-GUIDE.ja.md +989 -0
- package/docs/YATA-LOCAL-GUIDE.md +730 -0
- package/docs/adr/0001-real-time-pattern-learning-architecture-for-v1-5-0.md +75 -0
- package/docs/adr/0002-pattern-sharing-protocol-for-cross-team-collaborat.md +79 -0
- package/docs/adr/0003-owl-2-rl-implementation-strategy-for-advanced-infe.md +90 -0
- package/docs/adr/ADR-v3.4.0-001-deep-research-architecture.md +217 -0
- package/docs/adr/ADR-v3.4.0-002-search-provider-selection.md +308 -0
- package/docs/adr/ADR-v3.4.0-003-lm-api-integration.md +475 -0
- package/docs/enterprise-knowledge-management.md +1737 -0
- package/docs/evolution-from-musubi-to-musubix.md +2170 -0
- package/docs/getting-started-with-sdd.md +1602 -0
- package/docs/moodle-refactering-codegraph-musubix.md +391 -0
- package/docs/moodle-refactering-codegraph.md +278 -0
- package/docs/overview/MUSUBIX-CodeGraph.md +322 -0
- package/docs/overview/MUSUBIX-Core.md +671 -0
- package/docs/overview/MUSUBIX-Decisions.md +494 -0
- package/docs/overview/MUSUBIX-FormalVerify.md +566 -0
- package/docs/overview/MUSUBIX-Knowledge.md +1231 -0
- package/docs/overview/MUSUBIX-Learning.md +837 -0
- package/docs/overview/MUSUBIX-MCP-Server.md +535 -0
- package/docs/overview/MUSUBIX-Overview.md +264 -0
- package/docs/overview/MUSUBIX-Phase1-Complete.md +271 -0
- package/docs/overview/MUSUBIX-Phase2-Complete.md +310 -0
- package/docs/overview/MUSUBIX-Policy.md +477 -0
- package/docs/overview/MUSUBIX-Roadmap-v2.md +399 -0
- package/docs/overview/MUSUBIX-Security-Plan.md +939 -0
- package/docs/overview/MUSUBIX-Security-v2.1.md +668 -0
- package/docs/overview/MUSUBIX-Security.md +891 -0
- package/docs/overview/MUSUBIX-YATA.md +666 -0
- package/docs/overview/MUSUBIX-v2.2.0-Advanced-Learning.md +513 -0
- package/docs/overview/Neuro-SymbolicAI.md +159 -0
- package/docs/packages/knowledge.md +594 -0
- package/docs/qiita-linux-kernel-knowledge-graph.md +596 -0
- package/package.json +55 -49
- package/scripts/generate-quality-gate-report.ts +106 -0
- package/scripts/postinstall.js +94 -0
- package/steering/.musubi-version +1 -0
- package/steering/product.ja.md +572 -0
- package/steering/project.yml +66 -0
- package/steering/rules/constitution.md +491 -0
- package/steering/structure.ja.md +503 -0
- package/steering/tech.ja.md +208 -0
- package/dist/index.d.ts +0 -25
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -74
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
# YATA Local ユーザーガイド
|
|
2
|
+
|
|
3
|
+
> **YATA Local** - SQLiteベースのローカル知識グラフストレージ
|
|
4
|
+
|
|
5
|
+
## 📖 概要
|
|
6
|
+
|
|
7
|
+
YATA Local (`@nahisaho/yata-local`) は、AIコーディングアシスタント向けのローカル知識グラフストレージです。SQLiteをバックエンドとし、コード構造、関係性、パターンを効率的に管理します。
|
|
8
|
+
|
|
9
|
+
### 主な特徴
|
|
10
|
+
|
|
11
|
+
| 機能 | 説明 |
|
|
12
|
+
|------|------|
|
|
13
|
+
| **エンティティ管理** | クラス、関数、インターフェースなどのコード要素を格納 |
|
|
14
|
+
| **関係性追跡** | 継承、呼び出し、依存関係などを記録 |
|
|
15
|
+
| **推論エンジン** | ルールベースの推論と制約検証 |
|
|
16
|
+
| **クエリエンジン** | パターンマッチ、パス探索、サブグラフ抽出 |
|
|
17
|
+
| **インポート/エクスポート** | JSON、RDF、GraphML形式に対応 |
|
|
18
|
+
| **KGPR** | Knowledge Graph Pull Request(知識共有) |
|
|
19
|
+
| **Wake-Sleep学習** | パターン学習と統合 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🚀 インストール
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @nahisaho/yata-local
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 前提条件
|
|
30
|
+
|
|
31
|
+
- Node.js >= 20.0.0
|
|
32
|
+
- npm >= 10.0.0
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 📘 基本的な使い方
|
|
37
|
+
|
|
38
|
+
### 初期化と接続
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { createYataLocal } from '@nahisaho/yata-local';
|
|
42
|
+
|
|
43
|
+
// インスタンス作成
|
|
44
|
+
const yata = createYataLocal({
|
|
45
|
+
path: './.yata/knowledge.db', // データベースファイルパス
|
|
46
|
+
walMode: true, // WALモード(推奨)
|
|
47
|
+
cacheSize: 64 * 1024, // キャッシュサイズ(KB)
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// データベースを開く
|
|
51
|
+
await yata.open();
|
|
52
|
+
|
|
53
|
+
// ... 操作 ...
|
|
54
|
+
|
|
55
|
+
// 終了時にクローズ
|
|
56
|
+
await yata.close();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 設定オプション
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
interface DatabaseConfig {
|
|
63
|
+
path: string; // データベースファイルパス(デフォルト: '.yata/knowledge.db')
|
|
64
|
+
walMode: boolean; // WALモード有効化(デフォルト: true)
|
|
65
|
+
mmapSize: number; // メモリマッピングサイズ(デフォルト: 256MB)
|
|
66
|
+
cacheSize: number; // キャッシュサイズ(デフォルト: 64MB)
|
|
67
|
+
foreignKeys: boolean; // 外部キー制約(デフォルト: true)
|
|
68
|
+
encryption?: { // 暗号化設定(オプション)
|
|
69
|
+
enabled: boolean;
|
|
70
|
+
key: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 📦 エンティティ操作
|
|
78
|
+
|
|
79
|
+
### エンティティの追加
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// 単一エンティティの追加
|
|
83
|
+
const entityId = await yata.addEntity({
|
|
84
|
+
type: 'class',
|
|
85
|
+
name: 'UserService',
|
|
86
|
+
namespace: 'app.services',
|
|
87
|
+
filePath: 'src/services/user.ts',
|
|
88
|
+
line: 10,
|
|
89
|
+
description: 'ユーザー管理サービス',
|
|
90
|
+
metadata: {
|
|
91
|
+
entityKind: 'service',
|
|
92
|
+
isExported: true,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
console.log('Created entity:', entityId);
|
|
97
|
+
// => Created entity: 550e8400-e29b-41d4-a716-446655440000
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### バッチ追加
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// 複数エンティティの一括追加
|
|
104
|
+
const ids = await yata.addEntities([
|
|
105
|
+
{
|
|
106
|
+
type: 'interface',
|
|
107
|
+
name: 'IUserRepository',
|
|
108
|
+
namespace: 'app.repositories',
|
|
109
|
+
filePath: 'src/repositories/user.ts',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
type: 'function',
|
|
113
|
+
name: 'createUser',
|
|
114
|
+
namespace: 'app.services.user',
|
|
115
|
+
filePath: 'src/services/user.ts',
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
|
|
119
|
+
console.log('Created entities:', ids);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### エンティティの取得
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// IDで取得
|
|
126
|
+
const entity = await yata.getEntity(entityId);
|
|
127
|
+
|
|
128
|
+
// 名前で取得
|
|
129
|
+
const userService = await yata.getEntityByName('UserService', 'app.services');
|
|
130
|
+
|
|
131
|
+
// タイプで取得
|
|
132
|
+
const classes = await yata.getEntitiesByType('class');
|
|
133
|
+
|
|
134
|
+
// 名前空間で取得
|
|
135
|
+
const serviceEntities = await yata.getEntitiesByNamespace('app.services');
|
|
136
|
+
|
|
137
|
+
// メタデータのentityKindで取得
|
|
138
|
+
const services = await yata.getEntitiesByKind('service');
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### エンティティの更新
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// 更新
|
|
145
|
+
await yata.updateEntity(entityId, {
|
|
146
|
+
description: '更新された説明',
|
|
147
|
+
metadata: { version: '2.0.0' },
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// アップサート(存在すれば更新、なければ追加)
|
|
151
|
+
const result = await yata.upsertEntity({
|
|
152
|
+
type: 'class',
|
|
153
|
+
name: 'UserService',
|
|
154
|
+
namespace: 'app.services',
|
|
155
|
+
filePath: 'src/services/user.ts',
|
|
156
|
+
metadata: { version: '3.0.0' },
|
|
157
|
+
}, 'name-namespace'); // マッチ条件: name + namespace
|
|
158
|
+
|
|
159
|
+
console.log(result);
|
|
160
|
+
// => { id: '...', created: false } // 更新された場合
|
|
161
|
+
// => { id: '...', created: true } // 新規作成された場合
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### エンティティの削除
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// IDで削除
|
|
168
|
+
await yata.deleteEntity(entityId);
|
|
169
|
+
|
|
170
|
+
// ファイルパスで一括削除
|
|
171
|
+
const deletedCount = await yata.deleteEntitiesByFile('src/services/user.ts');
|
|
172
|
+
console.log(`Deleted ${deletedCount} entities`);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## 🔗 関係性操作
|
|
178
|
+
|
|
179
|
+
### エンティティタイプ
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
type EntityType =
|
|
183
|
+
| 'class' // クラス
|
|
184
|
+
| 'interface' // インターフェース
|
|
185
|
+
| 'function' // 関数
|
|
186
|
+
| 'method' // メソッド
|
|
187
|
+
| 'variable' // 変数
|
|
188
|
+
| 'constant' // 定数
|
|
189
|
+
| 'type' // 型定義
|
|
190
|
+
| 'enum' // 列挙型
|
|
191
|
+
| 'module' // モジュール
|
|
192
|
+
| 'package' // パッケージ
|
|
193
|
+
| 'file' // ファイル
|
|
194
|
+
| 'parameter' // パラメータ
|
|
195
|
+
| 'property' // プロパティ
|
|
196
|
+
| 'import' // インポート
|
|
197
|
+
| 'export' // エクスポート
|
|
198
|
+
| 'unknown'; // 不明
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 関係性タイプ
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
type RelationType =
|
|
205
|
+
| 'calls' // 呼び出し
|
|
206
|
+
| 'imports' // インポート
|
|
207
|
+
| 'exports' // エクスポート
|
|
208
|
+
| 'extends' // 継承
|
|
209
|
+
| 'inherits' // 継承
|
|
210
|
+
| 'implements' // 実装
|
|
211
|
+
| 'contains' // 包含
|
|
212
|
+
| 'uses' // 使用
|
|
213
|
+
| 'defines' // 定義
|
|
214
|
+
| 'references' // 参照
|
|
215
|
+
| 'depends-on' // 依存
|
|
216
|
+
| 'transitively-depends-on' // 推移的依存
|
|
217
|
+
| 'type-compatible' // 型互換
|
|
218
|
+
| 'has-method' // メソッド保持
|
|
219
|
+
| 'overrides' // オーバーライド
|
|
220
|
+
| 'returns' // 戻り値
|
|
221
|
+
| 'parameter_of' // パラメータ
|
|
222
|
+
| 'member_of' // メンバー
|
|
223
|
+
| 'related-to' // 関連
|
|
224
|
+
| 'defined-in-same-file' // 同一ファイル内定義
|
|
225
|
+
| 'unknown'; // 不明
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 関係性の追加と取得
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
// 関係性の追加
|
|
232
|
+
const relId = await yata.addRelationship(
|
|
233
|
+
classId, // ソースエンティティID
|
|
234
|
+
interfaceId, // ターゲットエンティティID
|
|
235
|
+
'implements', // 関係タイプ
|
|
236
|
+
{ isRequired: true } // メタデータ
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
// 関係性の取得
|
|
240
|
+
const outgoing = await yata.getRelationships(classId, 'out'); // 出力方向
|
|
241
|
+
const incoming = await yata.getRelationships(classId, 'in'); // 入力方向
|
|
242
|
+
const all = await yata.getRelationships(classId, 'both'); // 両方向
|
|
243
|
+
|
|
244
|
+
// 関係性の削除
|
|
245
|
+
await yata.deleteRelationship(relId);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## 🔍 クエリ操作
|
|
251
|
+
|
|
252
|
+
### 基本クエリ
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
const result = await yata.query({
|
|
256
|
+
entityFilters: {
|
|
257
|
+
types: ['class', 'interface'],
|
|
258
|
+
namespaces: ['app.services'],
|
|
259
|
+
},
|
|
260
|
+
textSearch: 'User',
|
|
261
|
+
relationshipFilters: {
|
|
262
|
+
types: ['implements', 'extends'],
|
|
263
|
+
},
|
|
264
|
+
}, {
|
|
265
|
+
limit: 100,
|
|
266
|
+
offset: 0,
|
|
267
|
+
sortBy: 'name',
|
|
268
|
+
sortOrder: 'asc',
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
console.log(`Found ${result.entities.length} entities`);
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### 全文検索
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
const entities = await yata.search('UserService', 50);
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### パス探索
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
// 2つのエンティティ間のパスを探索
|
|
284
|
+
const path = await yata.findPath(startId, endId, {
|
|
285
|
+
maxDepth: 5,
|
|
286
|
+
relationshipTypes: ['calls', 'imports'],
|
|
287
|
+
direction: 'forward',
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
if (path) {
|
|
291
|
+
console.log('Path found:', path.entities.map(e => e.name).join(' -> '));
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### サブグラフ抽出
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
// エンティティ周辺のサブグラフを抽出
|
|
299
|
+
const subgraph = await yata.extractSubgraph(rootId, {
|
|
300
|
+
depth: 3,
|
|
301
|
+
entityTypes: ['class', 'interface', 'function'],
|
|
302
|
+
relationshipTypes: ['calls', 'implements'],
|
|
303
|
+
direction: 'both',
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
console.log(`Subgraph: ${subgraph.entities.length} entities, ${subgraph.relationships.length} relationships`);
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### パターンマッチ
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
// グラフパターンのマッチング
|
|
313
|
+
const matches = await yata.matchPattern({
|
|
314
|
+
nodes: [
|
|
315
|
+
{ id: 'service', type: 'class', namePattern: /.*Service$/ },
|
|
316
|
+
{ id: 'repository', type: 'interface', namePattern: /.*Repository$/ },
|
|
317
|
+
],
|
|
318
|
+
edges: [
|
|
319
|
+
{ sourceId: 'service', targetId: 'repository', type: 'uses' },
|
|
320
|
+
],
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
for (const match of matches) {
|
|
324
|
+
console.log('Match:', match.bindings);
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### トラバーサル
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
// 関係性に沿ってトラバース
|
|
332
|
+
const reachable = await yata.traverse(
|
|
333
|
+
startId,
|
|
334
|
+
['calls', 'imports'], // 関係タイプ
|
|
335
|
+
'forward', // 方向
|
|
336
|
+
10 // 最大ホップ数
|
|
337
|
+
);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### 近傍取得
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
// エンティティの近傍を取得
|
|
344
|
+
const neighbors = await yata.getNeighbors(entityId, {
|
|
345
|
+
direction: 'both',
|
|
346
|
+
relationshipTypes: ['calls'],
|
|
347
|
+
entityTypes: ['function', 'method'],
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
for (const { entity, relationship } of neighbors) {
|
|
351
|
+
console.log(`${relationship.type} -> ${entity.name}`);
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## 💬 自然言語クエリ(v2.4.1 NEW!)
|
|
358
|
+
|
|
359
|
+
YATA Localは、日本語と英語の自然言語によるクエリをサポートしています。コード構造について自然な言葉で質問できます。
|
|
360
|
+
|
|
361
|
+
### 基本的な使い方
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
// ask() メソッドを使用
|
|
365
|
+
const result = await yata.ask('UserServiceを呼び出している関数は?');
|
|
366
|
+
|
|
367
|
+
console.log('Intent:', result.parsedQuery.intent);
|
|
368
|
+
// => Intent: find_callers
|
|
369
|
+
|
|
370
|
+
console.log('Results:');
|
|
371
|
+
for (const entity of result.entities) {
|
|
372
|
+
console.log(` - ${entity.name} (${entity.type})`);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
console.log('Explanation:', result.explanation);
|
|
376
|
+
// => 「UserService」を呼び出している3件の関数が見つかりました
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### 自然言語 → API コマンド対応表
|
|
380
|
+
|
|
381
|
+
自然言語クエリは内部で適切なAPIメソッドに変換されます。
|
|
382
|
+
|
|
383
|
+
#### 呼び出し元を探す(find_callers)
|
|
384
|
+
|
|
385
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
386
|
+
|--------------|------------------|
|
|
387
|
+
| `UserServiceを呼び出している関数は?` | `yata.getRelationships(userServiceId, 'in', { types: ['calls'] })` |
|
|
388
|
+
| `What functions call UserService?` | `yata.query({ relationshipFilters: { types: ['calls'], targetId: userServiceId } })` |
|
|
389
|
+
| `loginの呼び出し元を表示` | `yata.traverse(loginId, ['calls'], 'backward', 1)` |
|
|
390
|
+
|
|
391
|
+
```typescript
|
|
392
|
+
// 自然言語
|
|
393
|
+
const result = await yata.ask('UserServiceを呼び出している関数は?');
|
|
394
|
+
|
|
395
|
+
// 等価なAPI呼び出し
|
|
396
|
+
const entity = await yata.getEntityByName('UserService');
|
|
397
|
+
const callers = await yata.getRelationships(entity.id, 'in');
|
|
398
|
+
const callerEntities = callers
|
|
399
|
+
.filter(r => r.type === 'calls')
|
|
400
|
+
.map(r => yata.getEntity(r.sourceId));
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
#### 呼び出し先を探す(find_callees)
|
|
404
|
+
|
|
405
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
406
|
+
|--------------|------------------|
|
|
407
|
+
| `UserServiceは何を呼び出していますか?` | `yata.getRelationships(userServiceId, 'out', { types: ['calls'] })` |
|
|
408
|
+
| `What does UserService call?` | `yata.traverse(userServiceId, ['calls'], 'forward', 1)` |
|
|
409
|
+
| `processOrderの呼び出し先` | `yata.getNeighbors(processOrderId, { direction: 'out', relationshipTypes: ['calls'] })` |
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
// 自然言語
|
|
413
|
+
const result = await yata.ask('UserServiceは何を呼び出していますか?');
|
|
414
|
+
|
|
415
|
+
// 等価なAPI呼び出し
|
|
416
|
+
const entity = await yata.getEntityByName('UserService');
|
|
417
|
+
const callees = await yata.getRelationships(entity.id, 'out');
|
|
418
|
+
const calleeEntities = callees
|
|
419
|
+
.filter(r => r.type === 'calls')
|
|
420
|
+
.map(r => yata.getEntity(r.targetId));
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
#### 実装を探す(find_implementations)
|
|
424
|
+
|
|
425
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
426
|
+
|--------------|------------------|
|
|
427
|
+
| `Repositoryの実装を表示` | `yata.getRelationships(repositoryId, 'in', { types: ['implements'] })` |
|
|
428
|
+
| `What implements UserInterface?` | `yata.query({ relationshipFilters: { types: ['implements'], targetId: interfaceId } })` |
|
|
429
|
+
| `UserInterfaceを実装しているクラス` | `yata.matchPattern({ edges: [{ targetId: 'interface', type: 'implements' }] })` |
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
// 自然言語
|
|
433
|
+
const result = await yata.ask('Repositoryの実装を表示');
|
|
434
|
+
|
|
435
|
+
// 等価なAPI呼び出し
|
|
436
|
+
const iface = await yata.getEntityByName('Repository');
|
|
437
|
+
const implementations = await yata.getRelationships(iface.id, 'in');
|
|
438
|
+
const implEntities = implementations
|
|
439
|
+
.filter(r => r.type === 'implements')
|
|
440
|
+
.map(r => yata.getEntity(r.sourceId));
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
#### 依存関係を探す(find_dependencies)
|
|
444
|
+
|
|
445
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
446
|
+
|--------------|------------------|
|
|
447
|
+
| `UserServiceの依存関係を表示` | `yata.getRelationships(userServiceId, 'out', { types: ['depends-on', 'imports', 'uses'] })` |
|
|
448
|
+
| `What does UserService depend on?` | `yata.traverse(userServiceId, ['depends-on', 'imports'], 'forward', 1)` |
|
|
449
|
+
| `OrderProcessorは何に依存していますか?` | `yata.extractSubgraph(processorId, { depth: 1, relationshipTypes: ['depends-on'] })` |
|
|
450
|
+
|
|
451
|
+
```typescript
|
|
452
|
+
// 自然言語
|
|
453
|
+
const result = await yata.ask('UserServiceの依存関係を表示');
|
|
454
|
+
|
|
455
|
+
// 等価なAPI呼び出し
|
|
456
|
+
const entity = await yata.getEntityByName('UserService');
|
|
457
|
+
const deps = await yata.getRelationships(entity.id, 'out');
|
|
458
|
+
const dependencies = deps
|
|
459
|
+
.filter(r => ['depends-on', 'imports', 'uses'].includes(r.type))
|
|
460
|
+
.map(r => yata.getEntity(r.targetId));
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
#### エンティティを探す(find_entity)
|
|
464
|
+
|
|
465
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
466
|
+
|--------------|------------------|
|
|
467
|
+
| `UserServiceを探して` | `yata.search('UserService')` |
|
|
468
|
+
| `Find UserService` | `yata.getEntityByName('UserService')` |
|
|
469
|
+
| `ConfigManagerはどこにありますか?` | `yata.query({ textSearch: 'ConfigManager' })` |
|
|
470
|
+
| `Where is ConfigManager defined?` | `yata.search('ConfigManager', 10)` |
|
|
471
|
+
|
|
472
|
+
```typescript
|
|
473
|
+
// 自然言語
|
|
474
|
+
const result = await yata.ask('UserServiceを探して');
|
|
475
|
+
|
|
476
|
+
// 等価なAPI呼び出し
|
|
477
|
+
const entities = await yata.search('UserService', 10);
|
|
478
|
+
// または
|
|
479
|
+
const entity = await yata.getEntityByName('UserService');
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
#### 名前空間で探す(find_by_namespace)
|
|
483
|
+
|
|
484
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
485
|
+
|--------------|------------------|
|
|
486
|
+
| `app.servicesの全てのクラス` | `yata.query({ entityFilters: { namespaces: ['app.services'], types: ['class'] } })` |
|
|
487
|
+
| `Classes in app.services` | `yata.getEntitiesByNamespace('app.services')` |
|
|
488
|
+
| `utilsネームスペースの関数一覧` | `yata.query({ entityFilters: { namespaces: ['utils'], types: ['function'] } })` |
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
// 自然言語
|
|
492
|
+
const result = await yata.ask('app.servicesの全てのクラス');
|
|
493
|
+
|
|
494
|
+
// 等価なAPI呼び出し
|
|
495
|
+
const queryResult = await yata.query({
|
|
496
|
+
entityFilters: {
|
|
497
|
+
namespaces: ['app.services'],
|
|
498
|
+
types: ['class'],
|
|
499
|
+
},
|
|
500
|
+
});
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
#### 関連エンティティを探す(find_related)
|
|
504
|
+
|
|
505
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
506
|
+
|--------------|------------------|
|
|
507
|
+
| `UserServiceに関連するもの` | `yata.getNeighbors(userServiceId, { direction: 'both' })` |
|
|
508
|
+
| `Related to UserService` | `yata.extractSubgraph(userServiceId, { depth: 1 })` |
|
|
509
|
+
|
|
510
|
+
```typescript
|
|
511
|
+
// 自然言語
|
|
512
|
+
const result = await yata.ask('UserServiceに関連するもの');
|
|
513
|
+
|
|
514
|
+
// 等価なAPI呼び出し
|
|
515
|
+
const entity = await yata.getEntityByName('UserService');
|
|
516
|
+
const neighbors = await yata.getNeighbors(entity.id, { direction: 'both' });
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
#### 関係性の説明(explain_relationship)
|
|
520
|
+
|
|
521
|
+
| 自然言語クエリ | 等価なAPIコマンド |
|
|
522
|
+
|--------------|------------------|
|
|
523
|
+
| `UserServiceとRepositoryの関係は?` | `yata.findPath(userServiceId, repositoryId)` |
|
|
524
|
+
| `How is A related to B?` | `yata.findPath(aId, bId, { direction: 'both' })` |
|
|
525
|
+
|
|
526
|
+
```typescript
|
|
527
|
+
// 自然言語
|
|
528
|
+
const result = await yata.ask('UserServiceとRepositoryの関係は?');
|
|
529
|
+
|
|
530
|
+
// 等価なAPI呼び出し
|
|
531
|
+
const entityA = await yata.getEntityByName('UserService');
|
|
532
|
+
const entityB = await yata.getEntityByName('Repository');
|
|
533
|
+
const path = await yata.findPath(entityA.id, entityB.id, {
|
|
534
|
+
maxDepth: 5,
|
|
535
|
+
direction: 'both',
|
|
536
|
+
});
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
### 高度な使い方
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
// 設定オプション付きのクエリ
|
|
543
|
+
const result = await yata.ask('UserServiceの依存関係', {
|
|
544
|
+
language: 'ja', // 言語を明示指定
|
|
545
|
+
fuzzyMatching: true, // ファジーマッチング有効
|
|
546
|
+
minConfidence: 0.7, // 最小信頼度
|
|
547
|
+
maxResults: 50, // 最大結果数
|
|
548
|
+
includeInferred: true, // 推論結果を含む
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
// 結果の詳細
|
|
552
|
+
console.log('Query:', result.parsedQuery.originalQuery);
|
|
553
|
+
console.log('Intent:', result.parsedQuery.intent);
|
|
554
|
+
console.log('Subject:', result.parsedQuery.subject);
|
|
555
|
+
console.log('Confidence:', result.parsedQuery.confidence);
|
|
556
|
+
console.log('Entities:', result.entities.length);
|
|
557
|
+
console.log('Execution time:', result.executionTimeMs, 'ms');
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### MCP ツールとの連携
|
|
561
|
+
|
|
562
|
+
MCPサーバーを通じて自然言語クエリを使用することもできます:
|
|
563
|
+
|
|
564
|
+
```json
|
|
565
|
+
// MCP経由でのクエリ(sdd_ask_knowledge ツール)
|
|
566
|
+
// 入力:
|
|
567
|
+
{
|
|
568
|
+
"question": "UserServiceを呼び出している関数は?",
|
|
569
|
+
"maxResults": 20
|
|
570
|
+
}
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
### 対応インテント一覧
|
|
574
|
+
|
|
575
|
+
| インテント | 説明 | 自然言語例 | 内部API |
|
|
576
|
+
|-----------|------|-----------|---------|
|
|
577
|
+
| `find_entity` | エンティティ検索 | 「UserServiceを探して」 | `search()`, `getEntityByName()` |
|
|
578
|
+
| `find_callers` | 呼び出し元検索 | 「〜を呼び出している関数」 | `getRelationships(id, 'in')` |
|
|
579
|
+
| `find_callees` | 呼び出し先検索 | 「〜は何を呼び出していますか」 | `getRelationships(id, 'out')` |
|
|
580
|
+
| `find_implementations` | 実装検索 | 「〜の実装を表示」 | `getRelationships(id, 'in', {types: ['implements']})` |
|
|
581
|
+
| `find_dependencies` | 依存関係検索 | 「〜の依存関係」 | `traverse(id, ['depends-on'], 'forward')` |
|
|
582
|
+
| `find_dependents` | 依存元検索 | 「〜に依存しているもの」 | `traverse(id, ['depends-on'], 'backward')` |
|
|
583
|
+
| `find_related` | 関連検索 | 「〜に関連するもの」 | `getNeighbors(id, {direction: 'both'})` |
|
|
584
|
+
| `find_by_type` | 型別検索 | 「すべてのクラス」 | `query({entityFilters: {types: [...]}})` |
|
|
585
|
+
| `find_by_namespace` | 名前空間検索 | 「app.services内のクラス」 | `query({entityFilters: {namespaces: [...]}})` |
|
|
586
|
+
| `explain_relationship` | 関係性の説明 | 「〜と〜の関係は?」 | `findPath(idA, idB)` |
|
|
587
|
+
| `general_search` | 一般検索 | パターン未マッチ時 | `search(keywords)` |
|
|
588
|
+
|
|
589
|
+
---
|
|
590
|
+
|
|
591
|
+
## 🧠 推論エンジン
|
|
592
|
+
|
|
593
|
+
### 推論の実行
|
|
594
|
+
|
|
595
|
+
```typescript
|
|
596
|
+
// 推論ルールを適用
|
|
597
|
+
const inferenceResult = await yata.infer({
|
|
598
|
+
rules: ['transitivity', 'type-compatibility'],
|
|
599
|
+
maxIterations: 100,
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
console.log(`Inferred ${inferenceResult.inferredRelationships.length} new relationships`);
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
### カスタム推論ルール
|
|
606
|
+
|
|
607
|
+
```typescript
|
|
608
|
+
// カスタムルールの追加
|
|
609
|
+
yata.addInferenceRule({
|
|
610
|
+
id: 'service-uses-repository',
|
|
611
|
+
name: 'Service Uses Repository',
|
|
612
|
+
description: 'Services typically use repositories',
|
|
613
|
+
condition: (source, target) =>
|
|
614
|
+
source.type === 'class' &&
|
|
615
|
+
source.name.endsWith('Service') &&
|
|
616
|
+
target.type === 'interface' &&
|
|
617
|
+
target.name.endsWith('Repository'),
|
|
618
|
+
consequent: {
|
|
619
|
+
type: 'uses',
|
|
620
|
+
weight: 0.8,
|
|
621
|
+
},
|
|
622
|
+
});
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
### 制約検証
|
|
626
|
+
|
|
627
|
+
```typescript
|
|
628
|
+
// グラフの制約を検証
|
|
629
|
+
const validation = await yata.validate({
|
|
630
|
+
constraints: ['no-circular-dependencies', 'single-inheritance'],
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
if (!validation.isValid) {
|
|
634
|
+
console.log('Violations:', validation.violations);
|
|
635
|
+
}
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
### 信頼度計算
|
|
639
|
+
|
|
640
|
+
```typescript
|
|
641
|
+
// 関係性の信頼度を計算
|
|
642
|
+
const confidence = await yata.computeConfidence(
|
|
643
|
+
sourceId,
|
|
644
|
+
targetId,
|
|
645
|
+
'depends-on'
|
|
646
|
+
);
|
|
647
|
+
|
|
648
|
+
console.log(`Confidence: ${(confidence * 100).toFixed(1)}%`);
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### 関係性提案
|
|
652
|
+
|
|
653
|
+
```typescript
|
|
654
|
+
// 関係性の提案を取得
|
|
655
|
+
const suggestions = await yata.suggestRelationships(entityId, {
|
|
656
|
+
maxSuggestions: 10,
|
|
657
|
+
minConfidence: 0.7,
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
for (const suggestion of suggestions) {
|
|
661
|
+
console.log(`Suggest: ${suggestion.type} -> ${suggestion.targetId} (${(suggestion.confidence * 100).toFixed(1)}%)`);
|
|
662
|
+
console.log(` Reason: ${suggestion.reason}`);
|
|
663
|
+
}
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
---
|
|
667
|
+
|
|
668
|
+
## 📤 インポート/エクスポート
|
|
669
|
+
|
|
670
|
+
### JSON形式
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
// エクスポート
|
|
674
|
+
const jsonExport = await yata.exportJson('./backup.json');
|
|
675
|
+
console.log(`Exported ${jsonExport.entities.length} entities`);
|
|
676
|
+
|
|
677
|
+
// インポート
|
|
678
|
+
const mergeResult = await yata.importJson('./backup.json', {
|
|
679
|
+
merge: true, // 既存データとマージ
|
|
680
|
+
dryRun: false, // 実際に適用
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
console.log(`Imported: ${mergeResult.entitiesAdded} added, ${mergeResult.entitiesUpdated} updated`);
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
### RDF形式
|
|
687
|
+
|
|
688
|
+
```typescript
|
|
689
|
+
// RDFエクスポート
|
|
690
|
+
const rdfContent = await yata.exportRdf('./knowledge.ttl', {
|
|
691
|
+
format: 'turtle',
|
|
692
|
+
baseUri: 'http://example.org/knowledge/',
|
|
693
|
+
});
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
### ユニファイドエクスポート API
|
|
697
|
+
|
|
698
|
+
```typescript
|
|
699
|
+
// 複数フォーマット対応のエクスポート
|
|
700
|
+
const exportResult = await yata.export({
|
|
701
|
+
format: 'json', // 'json' | 'rdf' | 'graphml'
|
|
702
|
+
namespace: 'app.services', // フィルタ
|
|
703
|
+
outputPath: './export/services.json',
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
// 増分エクスポート(変更分のみ)
|
|
707
|
+
const incrementalExport = await yata.exportIncremental(
|
|
708
|
+
new Date('2024-01-01'), // この日時以降の変更
|
|
709
|
+
{ format: 'json' }
|
|
710
|
+
);
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### デルタ計算と適用
|
|
714
|
+
|
|
715
|
+
```typescript
|
|
716
|
+
// 2つの状態間のデルタを計算
|
|
717
|
+
const oldState = await yata.exportJson();
|
|
718
|
+
// ... 変更操作 ...
|
|
719
|
+
const newState = await yata.exportJson();
|
|
720
|
+
|
|
721
|
+
const delta = yata.computeDelta(oldState, newState);
|
|
722
|
+
console.log(`Delta: +${delta.added.length}, ~${delta.updated.length}, -${delta.deleted.length}`);
|
|
723
|
+
|
|
724
|
+
// デルタを別のインスタンスに適用
|
|
725
|
+
await otherYata.applyDelta(delta, { dryRun: false });
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
---
|
|
729
|
+
|
|
730
|
+
## 📊 統計情報
|
|
731
|
+
|
|
732
|
+
```typescript
|
|
733
|
+
const stats = await yata.getStats();
|
|
734
|
+
|
|
735
|
+
console.log('Graph Statistics:');
|
|
736
|
+
console.log(` Total entities: ${stats.totalEntities}`);
|
|
737
|
+
console.log(` Total relationships: ${stats.totalRelationships}`);
|
|
738
|
+
console.log(` Entities by type:`, stats.entitiesByType);
|
|
739
|
+
console.log(` Relationships by type:`, stats.relationshipsByType);
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
---
|
|
743
|
+
|
|
744
|
+
## 🔄 KGPR (Knowledge Graph Pull Request)
|
|
745
|
+
|
|
746
|
+
KGPRは、ローカル知識グラフの変更をYATA Globalに共有するためのワークフローです。
|
|
747
|
+
|
|
748
|
+
### KGPR マネージャーの作成
|
|
749
|
+
|
|
750
|
+
```typescript
|
|
751
|
+
import { createLocalKGPRManager } from '@nahisaho/yata-local';
|
|
752
|
+
|
|
753
|
+
const kgprManager = createLocalKGPRManager(yata.getDb());
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
### KGPR の作成
|
|
757
|
+
|
|
758
|
+
```typescript
|
|
759
|
+
const kgpr = await kgprManager.createKGPR({
|
|
760
|
+
title: 'UserService パターンの共有',
|
|
761
|
+
description: 'ユーザー認証フローから学習したパターン',
|
|
762
|
+
namespace: 'app.services',
|
|
763
|
+
entityTypes: ['class', 'interface'],
|
|
764
|
+
privacyLevel: 'strict', // 'strict' | 'moderate' | 'none'
|
|
765
|
+
author: 'developer@example.com',
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
console.log('KGPR created:', kgpr.id);
|
|
769
|
+
// => KGPR created: KGPR-1704067200000-a1b2c3d4
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
### プライバシーレベル
|
|
773
|
+
|
|
774
|
+
| レベル | 説明 |
|
|
775
|
+
|--------|------|
|
|
776
|
+
| `strict` | ファイルパス、行番号、機密メタデータを除去 |
|
|
777
|
+
| `moderate` | ファイルパスを相対化、機密メタデータを除去 |
|
|
778
|
+
| `none` | フィルタリングなし |
|
|
779
|
+
|
|
780
|
+
### KGPR の操作
|
|
781
|
+
|
|
782
|
+
```typescript
|
|
783
|
+
// 差分プレビュー
|
|
784
|
+
const diff = await kgprManager.previewDiff(kgpr.id);
|
|
785
|
+
console.log(`Changes: +${diff.stats.entitiesAdded}, ~${diff.stats.entitiesUpdated}`);
|
|
786
|
+
|
|
787
|
+
// KGPR一覧
|
|
788
|
+
const kgprs = await kgprManager.listKGPRs({
|
|
789
|
+
status: 'draft',
|
|
790
|
+
namespace: 'app.services',
|
|
791
|
+
limit: 10,
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
// ステータス更新
|
|
795
|
+
await kgprManager.updateKGPRStatus(kgpr.id, 'submitted');
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
---
|
|
799
|
+
|
|
800
|
+
## 🌙 Wake-Sleep 学習
|
|
801
|
+
|
|
802
|
+
Wake-Sleepは、コードからパターンを学習し統合する継続的学習サイクルです。
|
|
803
|
+
|
|
804
|
+
### Wake-Sleep サイクルの作成
|
|
805
|
+
|
|
806
|
+
```typescript
|
|
807
|
+
import { createLocalWakeSleepCycle } from '@nahisaho/yata-local';
|
|
808
|
+
|
|
809
|
+
const wakeSleep = createLocalWakeSleepCycle(yata.getDb(), {
|
|
810
|
+
wakeObserveLimit: 1000,
|
|
811
|
+
sleepMinClusterSize: 3,
|
|
812
|
+
sleepSimilarityThreshold: 0.7,
|
|
813
|
+
compressMinOccurrences: 5,
|
|
814
|
+
});
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
### 学習サイクルの実行
|
|
818
|
+
|
|
819
|
+
```typescript
|
|
820
|
+
// Wakeフェーズ: コードを観察しパターンを抽出
|
|
821
|
+
const wakeResult = await wakeSleep.wake({
|
|
822
|
+
namespace: 'app.services',
|
|
823
|
+
entityTypes: ['class', 'function'],
|
|
824
|
+
});
|
|
825
|
+
console.log(`Wake: Found ${wakeResult.patterns.length} patterns`);
|
|
826
|
+
|
|
827
|
+
// Sleepフェーズ: パターンを統合・圧縮
|
|
828
|
+
const sleepResult = await wakeSleep.sleep();
|
|
829
|
+
console.log(`Sleep: Consolidated ${sleepResult.consolidatedPatterns.length} patterns`);
|
|
830
|
+
|
|
831
|
+
// 完全サイクル
|
|
832
|
+
const cycleResult = await wakeSleep.runCycle({
|
|
833
|
+
namespace: 'app',
|
|
834
|
+
});
|
|
835
|
+
console.log(`Cycle complete: ${cycleResult.status}`);
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
---
|
|
839
|
+
|
|
840
|
+
## 📈 インデックス最適化
|
|
841
|
+
|
|
842
|
+
```typescript
|
|
843
|
+
import { IndexOptimizer } from '@nahisaho/yata-local';
|
|
844
|
+
|
|
845
|
+
const optimizer = new IndexOptimizer(yata.getDb());
|
|
846
|
+
|
|
847
|
+
// 現在のインデックス分析
|
|
848
|
+
const analysis = await optimizer.analyze({
|
|
849
|
+
includeQueryStats: true,
|
|
850
|
+
recommendationLimit: 10,
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
console.log('Current indexes:', analysis.existingIndexes);
|
|
854
|
+
console.log('Recommendations:', analysis.recommendations);
|
|
855
|
+
|
|
856
|
+
// 推奨インデックスの作成
|
|
857
|
+
for (const rec of analysis.recommendations) {
|
|
858
|
+
if (rec.priority === 'high') {
|
|
859
|
+
await optimizer.createIndex(rec);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
---
|
|
865
|
+
|
|
866
|
+
## 🌐 グローバル同期
|
|
867
|
+
|
|
868
|
+
```typescript
|
|
869
|
+
import { createGlobalSyncManager } from '@nahisaho/yata-local';
|
|
870
|
+
|
|
871
|
+
const syncManager = createGlobalSyncManager(yata.getDb(), {
|
|
872
|
+
serverUrl: 'http://localhost:3000',
|
|
873
|
+
autoSync: true,
|
|
874
|
+
syncInterval: 60000, // 1分ごと
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
// 手動同期
|
|
878
|
+
const syncResult = await syncManager.sync();
|
|
879
|
+
console.log(`Synced: ${syncResult.pushed} pushed, ${syncResult.pulled} pulled`);
|
|
880
|
+
|
|
881
|
+
// 同期状態の確認
|
|
882
|
+
const status = syncManager.getStatus();
|
|
883
|
+
console.log('Last sync:', status.lastSyncAt);
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
---
|
|
887
|
+
|
|
888
|
+
## 🛠️ コード解析との統合
|
|
889
|
+
|
|
890
|
+
### KnowledgeGraphUpdater
|
|
891
|
+
|
|
892
|
+
```typescript
|
|
893
|
+
import { createKnowledgeGraphUpdater } from '@nahisaho/yata-local';
|
|
894
|
+
|
|
895
|
+
const updater = createKnowledgeGraphUpdater(yata);
|
|
896
|
+
|
|
897
|
+
// コード解析結果を知識グラフに反映
|
|
898
|
+
const updateResult = await updater.updateFromAnalysis({
|
|
899
|
+
entities: [
|
|
900
|
+
{
|
|
901
|
+
type: 'class',
|
|
902
|
+
name: 'OrderService',
|
|
903
|
+
namespace: 'app.services',
|
|
904
|
+
filePath: 'src/services/order.ts',
|
|
905
|
+
methods: ['createOrder', 'cancelOrder'],
|
|
906
|
+
},
|
|
907
|
+
],
|
|
908
|
+
relationships: [
|
|
909
|
+
{
|
|
910
|
+
sourceType: 'class',
|
|
911
|
+
sourceName: 'OrderService',
|
|
912
|
+
targetType: 'interface',
|
|
913
|
+
targetName: 'IOrderRepository',
|
|
914
|
+
type: 'uses',
|
|
915
|
+
},
|
|
916
|
+
],
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
console.log(`Updated: ${updateResult.entitiesCreated} entities, ${updateResult.relationshipsCreated} relationships`);
|
|
920
|
+
```
|
|
921
|
+
|
|
922
|
+
### YATA Bridge (MCP統合)
|
|
923
|
+
|
|
924
|
+
```typescript
|
|
925
|
+
import { createYataBridge } from '@nahisaho/yata-local';
|
|
926
|
+
|
|
927
|
+
const bridge = createYataBridge({
|
|
928
|
+
yataLocal: yata,
|
|
929
|
+
namespace: 'project.name',
|
|
930
|
+
});
|
|
931
|
+
|
|
932
|
+
// MCPツールからの呼び出しを処理
|
|
933
|
+
const entities = await bridge.queryEntities({
|
|
934
|
+
types: ['class'],
|
|
935
|
+
namePattern: '.*Service',
|
|
936
|
+
});
|
|
937
|
+
```
|
|
938
|
+
|
|
939
|
+
---
|
|
940
|
+
|
|
941
|
+
## 🔧 高度な使用例
|
|
942
|
+
|
|
943
|
+
### 生SQLクエリ
|
|
944
|
+
|
|
945
|
+
```typescript
|
|
946
|
+
// 高度なユースケース向けの生SQLクエリ
|
|
947
|
+
const results = await yata.rawQuery<{ name: string; count: number }>(
|
|
948
|
+
`SELECT type as name, COUNT(*) as count
|
|
949
|
+
FROM entities
|
|
950
|
+
GROUP BY type
|
|
951
|
+
ORDER BY count DESC`,
|
|
952
|
+
[]
|
|
953
|
+
);
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
### 変更追跡
|
|
957
|
+
|
|
958
|
+
```typescript
|
|
959
|
+
// 特定時刻以降の変更を取得
|
|
960
|
+
const changes = await yata.getChangesSince(new Date('2024-01-01'));
|
|
961
|
+
|
|
962
|
+
console.log('Added entities:', changes.entities.added.length);
|
|
963
|
+
console.log('Updated entities:', changes.entities.updated.length);
|
|
964
|
+
console.log('Deleted entities:', changes.entities.deleted.length);
|
|
965
|
+
```
|
|
966
|
+
|
|
967
|
+
---
|
|
968
|
+
|
|
969
|
+
## 📚 関連ドキュメント
|
|
970
|
+
|
|
971
|
+
- [YATA Global ユーザーガイド](./YATA-GLOBAL-GUIDE.ja.md)
|
|
972
|
+
- [API リファレンス](./API-REFERENCE.md)
|
|
973
|
+
- [MUSUBIX ユーザーガイド](./USER-GUIDE.ja.md)
|
|
974
|
+
|
|
975
|
+
---
|
|
976
|
+
|
|
977
|
+
## 📝 バージョン履歴
|
|
978
|
+
|
|
979
|
+
| バージョン | 主な変更 |
|
|
980
|
+
|-----------|---------|
|
|
981
|
+
| v1.7.0 | インデックス最適化、グローバル同期、エクスポートAPI強化 |
|
|
982
|
+
| v1.6.5 | KGPR、Wake-Sleep学習モジュール追加 |
|
|
983
|
+
| v1.5.0 | 推論エンジン強化、パターンマッチング |
|
|
984
|
+
| v1.0.0 | 初期リリース |
|
|
985
|
+
|
|
986
|
+
---
|
|
987
|
+
|
|
988
|
+
**最終更新**: 2026-01-11
|
|
989
|
+
**パッケージ**: `@nahisaho/yata-local`
|