musubix 3.3.4 → 3.3.6

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 (92) hide show
  1. package/.github/AGENTS.md +949 -0
  2. package/.github/prompts/sdd-change-apply.prompt.md +283 -0
  3. package/.github/prompts/sdd-change-archive.prompt.md +241 -0
  4. package/.github/prompts/sdd-change-init.prompt.md +269 -0
  5. package/.github/prompts/sdd-design.prompt.md +250 -0
  6. package/.github/prompts/sdd-implement.prompt.md +387 -0
  7. package/.github/prompts/sdd-requirements.prompt.md +193 -0
  8. package/.github/prompts/sdd-review.prompt.md +155 -0
  9. package/.github/prompts/sdd-security.prompt.md +228 -0
  10. package/.github/prompts/sdd-steering.prompt.md +269 -0
  11. package/.github/prompts/sdd-tasks.prompt.md +255 -0
  12. package/.github/prompts/sdd-test.prompt.md +230 -0
  13. package/.github/prompts/sdd-validate.prompt.md +304 -0
  14. package/.github/skills/musubix-adr-generation/SKILL.md +209 -0
  15. package/.github/skills/musubix-best-practices/SKILL.md +315 -0
  16. package/.github/skills/musubix-c4-design/SKILL.md +162 -0
  17. package/.github/skills/musubix-code-generation/SKILL.md +237 -0
  18. package/.github/skills/musubix-domain-inference/SKILL.md +196 -0
  19. package/.github/skills/musubix-ears-validation/SKILL.md +161 -0
  20. package/.github/skills/musubix-sdd-workflow/SKILL.md +217 -0
  21. package/.github/skills/musubix-technical-writing/SKILL.md +444 -0
  22. package/.github/skills/musubix-test-generation/SKILL.md +212 -0
  23. package/.github/skills/musubix-traceability/SKILL.md +141 -0
  24. package/AGENTS.md +1065 -0
  25. package/LICENSE +21 -0
  26. package/README.ja.md +296 -0
  27. package/README.md +305 -50
  28. package/bin/musubix-mcp.js +15 -0
  29. package/bin/musubix.js +9 -1
  30. package/docs/API-REFERENCE.md +1425 -0
  31. package/docs/GITHUB-ACTIONS-NPM-SETUP.md +132 -0
  32. package/docs/INSTALL-GUIDE.ja.md +459 -0
  33. package/docs/INSTALL-GUIDE.md +459 -0
  34. package/docs/MIGRATION-v3.0.md +324 -0
  35. package/docs/MUSUBI-enhancement_roadmap_20260105.md +651 -0
  36. package/docs/MUSUBIX-v3.0-User-Guide.md +1357 -0
  37. package/docs/MUSUBIXv2.2.0-Manual-outline.md +136 -0
  38. package/docs/MUSUBIXv2.2.0-Manual.md +3123 -0
  39. package/docs/MUSUBIXv2.3.5-Refactering.md +1310 -0
  40. package/docs/MUSUBIv1.6.1-enhancement_roadmap_20260105.md +291 -0
  41. package/docs/MUSUBIv2.2.0-USERGUIDE.md +2079 -0
  42. package/docs/ROADMAP-v1.5.md +116 -0
  43. package/docs/SwarmCoding.md +1284 -0
  44. package/docs/Test-prompt.md +105 -0
  45. package/docs/USER-GUIDE-v1.8.0.md +2371 -0
  46. package/docs/USER-GUIDE.ja.md +2147 -0
  47. package/docs/USER-GUIDE.md +3022 -0
  48. package/docs/YATA-GLOBAL-GUIDE.ja.md +750 -0
  49. package/docs/YATA-GLOBAL-GUIDE.md +595 -0
  50. package/docs/YATA-LOCAL-GUIDE.ja.md +989 -0
  51. package/docs/YATA-LOCAL-GUIDE.md +730 -0
  52. package/docs/adr/0001-real-time-pattern-learning-architecture-for-v1-5-0.md +75 -0
  53. package/docs/adr/0002-pattern-sharing-protocol-for-cross-team-collaborat.md +79 -0
  54. package/docs/adr/0003-owl-2-rl-implementation-strategy-for-advanced-infe.md +90 -0
  55. package/docs/enterprise-knowledge-management.md +1737 -0
  56. package/docs/evolution-from-musubi-to-musubix.md +2170 -0
  57. package/docs/getting-started-with-sdd.md +1602 -0
  58. package/docs/moodle-refactering-codegraph-musubix.md +391 -0
  59. package/docs/moodle-refactering-codegraph.md +278 -0
  60. package/docs/overview/MUSUBIX-CodeGraph.md +322 -0
  61. package/docs/overview/MUSUBIX-Core.md +671 -0
  62. package/docs/overview/MUSUBIX-Decisions.md +494 -0
  63. package/docs/overview/MUSUBIX-FormalVerify.md +566 -0
  64. package/docs/overview/MUSUBIX-Knowledge.md +1231 -0
  65. package/docs/overview/MUSUBIX-Learning.md +837 -0
  66. package/docs/overview/MUSUBIX-MCP-Server.md +535 -0
  67. package/docs/overview/MUSUBIX-Overview.md +264 -0
  68. package/docs/overview/MUSUBIX-Phase1-Complete.md +271 -0
  69. package/docs/overview/MUSUBIX-Phase2-Complete.md +310 -0
  70. package/docs/overview/MUSUBIX-Policy.md +477 -0
  71. package/docs/overview/MUSUBIX-Roadmap-v2.md +399 -0
  72. package/docs/overview/MUSUBIX-Security-Plan.md +939 -0
  73. package/docs/overview/MUSUBIX-Security-v2.1.md +668 -0
  74. package/docs/overview/MUSUBIX-Security.md +891 -0
  75. package/docs/overview/MUSUBIX-YATA.md +666 -0
  76. package/docs/overview/MUSUBIX-v2.2.0-Advanced-Learning.md +513 -0
  77. package/docs/overview/Neuro-SymbolicAI.md +159 -0
  78. package/docs/packages/knowledge.md +594 -0
  79. package/docs/qiita-linux-kernel-knowledge-graph.md +596 -0
  80. package/package.json +55 -51
  81. package/scripts/generate-quality-gate-report.ts +106 -0
  82. package/scripts/postinstall.js +94 -0
  83. package/steering/.musubi-version +1 -0
  84. package/steering/product.ja.md +572 -0
  85. package/steering/project.yml +66 -0
  86. package/steering/rules/constitution.md +491 -0
  87. package/steering/structure.ja.md +503 -0
  88. package/steering/tech.ja.md +208 -0
  89. package/dist/index.d.ts +0 -25
  90. package/dist/index.d.ts.map +0 -1
  91. package/dist/index.js +0 -74
  92. package/dist/index.js.map +0 -1
@@ -0,0 +1,730 @@
1
+ # YATA Local User Guide
2
+
3
+ > **YATA Local** - SQLite-based Local Knowledge Graph Storage
4
+
5
+ ## 📖 Overview
6
+
7
+ YATA Local (`@nahisaho/yata-local`) is a local knowledge graph storage system for AI coding assistants. Using SQLite as a backend, it efficiently manages code structures, relationships, and patterns.
8
+
9
+ ### Key Features
10
+
11
+ | Feature | Description |
12
+ |---------|-------------|
13
+ | **Entity Management** | Store code elements like classes, functions, interfaces |
14
+ | **Relationship Tracking** | Record inheritance, calls, dependencies |
15
+ | **Reasoning Engine** | Rule-based inference and constraint validation |
16
+ | **Query Engine** | Pattern matching, path finding, subgraph extraction |
17
+ | **Import/Export** | JSON, RDF, GraphML format support |
18
+ | **KGPR** | Knowledge Graph Pull Request for knowledge sharing |
19
+ | **Wake-Sleep Learning** | Pattern learning and consolidation |
20
+
21
+ ---
22
+
23
+ ## 🚀 Installation
24
+
25
+ ```bash
26
+ npm install @nahisaho/yata-local
27
+ ```
28
+
29
+ ### Prerequisites
30
+
31
+ - Node.js >= 20.0.0
32
+ - npm >= 10.0.0
33
+
34
+ ---
35
+
36
+ ## 📘 Basic Usage
37
+
38
+ ### Initialization and Connection
39
+
40
+ ```typescript
41
+ import { createYataLocal } from '@nahisaho/yata-local';
42
+
43
+ // Create instance
44
+ const yata = createYataLocal({
45
+ path: './.yata/knowledge.db', // Database file path
46
+ walMode: true, // WAL mode (recommended)
47
+ cacheSize: 64 * 1024, // Cache size (KB)
48
+ });
49
+
50
+ // Open database
51
+ await yata.open();
52
+
53
+ // ... operations ...
54
+
55
+ // Close on exit
56
+ await yata.close();
57
+ ```
58
+
59
+ ### Configuration Options
60
+
61
+ ```typescript
62
+ interface DatabaseConfig {
63
+ path: string; // Database file path (default: '.yata/knowledge.db')
64
+ walMode: boolean; // Enable WAL mode (default: true)
65
+ mmapSize: number; // Memory mapping size (default: 256MB)
66
+ cacheSize: number; // Cache size (default: 64MB)
67
+ foreignKeys: boolean; // Foreign key constraints (default: true)
68
+ encryption?: { // Encryption settings (optional)
69
+ enabled: boolean;
70
+ key: string;
71
+ };
72
+ }
73
+ ```
74
+
75
+ ---
76
+
77
+ ## 📦 Entity Operations
78
+
79
+ ### Adding Entities
80
+
81
+ ```typescript
82
+ // Add single entity
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: 'User management service',
90
+ metadata: {
91
+ entityKind: 'service',
92
+ isExported: true,
93
+ },
94
+ });
95
+
96
+ console.log('Created entity:', entityId);
97
+ ```
98
+
99
+ ### Batch Addition
100
+
101
+ ```typescript
102
+ // Add multiple entities at once
103
+ const ids = await yata.addEntities([
104
+ {
105
+ type: 'interface',
106
+ name: 'IUserRepository',
107
+ namespace: 'app.repositories',
108
+ filePath: 'src/repositories/user.ts',
109
+ },
110
+ {
111
+ type: 'function',
112
+ name: 'createUser',
113
+ namespace: 'app.services.user',
114
+ filePath: 'src/services/user.ts',
115
+ },
116
+ ]);
117
+ ```
118
+
119
+ ### Retrieving Entities
120
+
121
+ ```typescript
122
+ // Get by ID
123
+ const entity = await yata.getEntity(entityId);
124
+
125
+ // Get by name
126
+ const userService = await yata.getEntityByName('UserService', 'app.services');
127
+
128
+ // Get by type
129
+ const classes = await yata.getEntitiesByType('class');
130
+
131
+ // Get by namespace
132
+ const serviceEntities = await yata.getEntitiesByNamespace('app.services');
133
+
134
+ // Get by metadata entityKind
135
+ const services = await yata.getEntitiesByKind('service');
136
+ ```
137
+
138
+ ### Updating Entities
139
+
140
+ ```typescript
141
+ // Update
142
+ await yata.updateEntity(entityId, {
143
+ description: 'Updated description',
144
+ metadata: { version: '2.0.0' },
145
+ });
146
+
147
+ // Upsert (update if exists, add if not)
148
+ const result = await yata.upsertEntity({
149
+ type: 'class',
150
+ name: 'UserService',
151
+ namespace: 'app.services',
152
+ filePath: 'src/services/user.ts',
153
+ metadata: { version: '3.0.0' },
154
+ }, 'name-namespace'); // Match criteria: name + namespace
155
+
156
+ console.log(result);
157
+ // => { id: '...', created: false } // If updated
158
+ // => { id: '...', created: true } // If newly created
159
+ ```
160
+
161
+ ### Deleting Entities
162
+
163
+ ```typescript
164
+ // Delete by ID
165
+ await yata.deleteEntity(entityId);
166
+
167
+ // Bulk delete by file path
168
+ const deletedCount = await yata.deleteEntitiesByFile('src/services/user.ts');
169
+ console.log(`Deleted ${deletedCount} entities`);
170
+ ```
171
+
172
+ ---
173
+
174
+ ## 🔗 Relationship Operations
175
+
176
+ ### Entity Types
177
+
178
+ ```typescript
179
+ type EntityType =
180
+ | 'class' // Class
181
+ | 'interface' // Interface
182
+ | 'function' // Function
183
+ | 'method' // Method
184
+ | 'variable' // Variable
185
+ | 'constant' // Constant
186
+ | 'type' // Type definition
187
+ | 'enum' // Enumeration
188
+ | 'module' // Module
189
+ | 'package' // Package
190
+ | 'file' // File
191
+ | 'parameter' // Parameter
192
+ | 'property' // Property
193
+ | 'import' // Import
194
+ | 'export' // Export
195
+ | 'unknown'; // Unknown
196
+ ```
197
+
198
+ ### Relationship Types
199
+
200
+ ```typescript
201
+ type RelationType =
202
+ | 'calls' // Calls
203
+ | 'imports' // Imports
204
+ | 'exports' // Exports
205
+ | 'extends' // Extends
206
+ | 'inherits' // Inherits
207
+ | 'implements' // Implements
208
+ | 'contains' // Contains
209
+ | 'uses' // Uses
210
+ | 'defines' // Defines
211
+ | 'references' // References
212
+ | 'depends-on' // Depends on
213
+ | 'transitively-depends-on' // Transitive dependency
214
+ | 'type-compatible' // Type compatible
215
+ | 'has-method' // Has method
216
+ | 'overrides' // Overrides
217
+ | 'returns' // Returns
218
+ | 'parameter_of' // Parameter of
219
+ | 'member_of' // Member of
220
+ | 'related-to' // Related to
221
+ | 'defined-in-same-file' // Defined in same file
222
+ | 'unknown'; // Unknown
223
+ ```
224
+
225
+ ### Adding and Getting Relationships
226
+
227
+ ```typescript
228
+ // Add relationship
229
+ const relId = await yata.addRelationship(
230
+ classId, // Source entity ID
231
+ interfaceId, // Target entity ID
232
+ 'implements', // Relationship type
233
+ { isRequired: true } // Metadata
234
+ );
235
+
236
+ // Get relationships
237
+ const outgoing = await yata.getRelationships(classId, 'out'); // Outgoing
238
+ const incoming = await yata.getRelationships(classId, 'in'); // Incoming
239
+ const all = await yata.getRelationships(classId, 'both'); // Both directions
240
+
241
+ // Delete relationship
242
+ await yata.deleteRelationship(relId);
243
+ ```
244
+
245
+ ---
246
+
247
+ ## 🔍 Query Operations
248
+
249
+ ### Basic Query
250
+
251
+ ```typescript
252
+ const result = await yata.query({
253
+ entityFilters: {
254
+ types: ['class', 'interface'],
255
+ namespaces: ['app.services'],
256
+ },
257
+ textSearch: 'User',
258
+ relationshipFilters: {
259
+ types: ['implements', 'extends'],
260
+ },
261
+ }, {
262
+ limit: 100,
263
+ offset: 0,
264
+ sortBy: 'name',
265
+ sortOrder: 'asc',
266
+ });
267
+
268
+ console.log(`Found ${result.entities.length} entities`);
269
+ ```
270
+
271
+ ### Full-text Search
272
+
273
+ ```typescript
274
+ const entities = await yata.search('UserService', 50);
275
+ ```
276
+
277
+ ### Path Finding
278
+
279
+ ```typescript
280
+ // Find path between two entities
281
+ const path = await yata.findPath(startId, endId, {
282
+ maxDepth: 5,
283
+ relationshipTypes: ['calls', 'imports'],
284
+ direction: 'forward',
285
+ });
286
+
287
+ if (path) {
288
+ console.log('Path found:', path.entities.map(e => e.name).join(' -> '));
289
+ }
290
+ ```
291
+
292
+ ### Subgraph Extraction
293
+
294
+ ```typescript
295
+ // Extract subgraph around an entity
296
+ const subgraph = await yata.extractSubgraph(rootId, {
297
+ depth: 3,
298
+ entityTypes: ['class', 'interface', 'function'],
299
+ relationshipTypes: ['calls', 'implements'],
300
+ direction: 'both',
301
+ });
302
+
303
+ console.log(`Subgraph: ${subgraph.entities.length} entities, ${subgraph.relationships.length} relationships`);
304
+ ```
305
+
306
+ ### Pattern Matching
307
+
308
+ ```typescript
309
+ // Match graph patterns
310
+ const matches = await yata.matchPattern({
311
+ nodes: [
312
+ { id: 'service', type: 'class', namePattern: /.*Service$/ },
313
+ { id: 'repository', type: 'interface', namePattern: /.*Repository$/ },
314
+ ],
315
+ edges: [
316
+ { sourceId: 'service', targetId: 'repository', type: 'uses' },
317
+ ],
318
+ });
319
+
320
+ for (const match of matches) {
321
+ console.log('Match:', match.bindings);
322
+ }
323
+ ```
324
+
325
+ ---
326
+
327
+ ## 💬 Natural Language Query (v2.4.1 NEW!)
328
+
329
+ YATA Local supports natural language queries in both English and Japanese. Ask questions about code structure using natural language.
330
+
331
+ ### Basic Usage
332
+
333
+ ```typescript
334
+ // Use the ask() method
335
+ const result = await yata.ask('What functions call UserService?');
336
+
337
+ console.log('Intent:', result.parsedQuery.intent);
338
+ // => Intent: find_callers
339
+
340
+ console.log('Results:');
341
+ for (const entity of result.entities) {
342
+ console.log(` - ${entity.name} (${entity.type})`);
343
+ }
344
+
345
+ console.log('Explanation:', result.explanation);
346
+ // => Found 3 function(s) calling "UserService"
347
+ ```
348
+
349
+ ### Natural Language → API Command Mapping
350
+
351
+ Natural language queries are internally converted to appropriate API method calls.
352
+
353
+ #### Find Callers
354
+
355
+ | Natural Language Query | Equivalent API Command |
356
+ |----------------------|------------------------|
357
+ | `What functions call UserService?` | `yata.getRelationships(userServiceId, 'in', { types: ['calls'] })` |
358
+ | `What calls authenticate?` | `yata.query({ relationshipFilters: { types: ['calls'], targetId: authId } })` |
359
+ | `Which methods invoke processOrder?` | `yata.traverse(processOrderId, ['calls'], 'backward', 1)` |
360
+
361
+ ```typescript
362
+ // Natural language
363
+ const result = await yata.ask('What functions call UserService?');
364
+
365
+ // Equivalent API call
366
+ const entity = await yata.getEntityByName('UserService');
367
+ const callers = await yata.getRelationships(entity.id, 'in');
368
+ const callerEntities = callers
369
+ .filter(r => r.type === 'calls')
370
+ .map(r => yata.getEntity(r.sourceId));
371
+ ```
372
+
373
+ #### Find Callees
374
+
375
+ | Natural Language Query | Equivalent API Command |
376
+ |----------------------|------------------------|
377
+ | `What does UserService call?` | `yata.getRelationships(userServiceId, 'out', { types: ['calls'] })` |
378
+ | `List functions called by processOrder` | `yata.traverse(processOrderId, ['calls'], 'forward', 1)` |
379
+
380
+ ```typescript
381
+ // Natural language
382
+ const result = await yata.ask('What does UserService call?');
383
+
384
+ // Equivalent API call
385
+ const entity = await yata.getEntityByName('UserService');
386
+ const callees = await yata.getRelationships(entity.id, 'out');
387
+ const calleeEntities = callees
388
+ .filter(r => r.type === 'calls')
389
+ .map(r => yata.getEntity(r.targetId));
390
+ ```
391
+
392
+ #### Find Implementations
393
+
394
+ | Natural Language Query | Equivalent API Command |
395
+ |----------------------|------------------------|
396
+ | `Show implementations of Repository` | `yata.getRelationships(repositoryId, 'in', { types: ['implements'] })` |
397
+ | `What implements UserInterface?` | `yata.query({ relationshipFilters: { types: ['implements'], targetId: interfaceId } })` |
398
+ | `List classes implementing Service` | `yata.matchPattern({ edges: [{ targetId: 'interface', type: 'implements' }] })` |
399
+
400
+ ```typescript
401
+ // Natural language
402
+ const result = await yata.ask('Show implementations of Repository');
403
+
404
+ // Equivalent API call
405
+ const iface = await yata.getEntityByName('Repository');
406
+ const implementations = await yata.getRelationships(iface.id, 'in');
407
+ const implEntities = implementations
408
+ .filter(r => r.type === 'implements')
409
+ .map(r => yata.getEntity(r.sourceId));
410
+ ```
411
+
412
+ #### Find Dependencies
413
+
414
+ | Natural Language Query | Equivalent API Command |
415
+ |----------------------|------------------------|
416
+ | `What does UserService depend on?` | `yata.getRelationships(userServiceId, 'out', { types: ['depends-on', 'imports', 'uses'] })` |
417
+ | `Show dependencies of OrderProcessor` | `yata.traverse(processorId, ['depends-on', 'imports'], 'forward', 1)` |
418
+
419
+ ```typescript
420
+ // Natural language
421
+ const result = await yata.ask('What does UserService depend on?');
422
+
423
+ // Equivalent API call
424
+ const entity = await yata.getEntityByName('UserService');
425
+ const deps = await yata.getRelationships(entity.id, 'out');
426
+ const dependencies = deps
427
+ .filter(r => ['depends-on', 'imports', 'uses'].includes(r.type))
428
+ .map(r => yata.getEntity(r.targetId));
429
+ ```
430
+
431
+ #### Find Entity
432
+
433
+ | Natural Language Query | Equivalent API Command |
434
+ |----------------------|------------------------|
435
+ | `Find UserService` | `yata.search('UserService')` |
436
+ | `Where is ConfigManager defined?` | `yata.getEntityByName('ConfigManager')` |
437
+ | `Locate the login method` | `yata.query({ textSearch: 'login' })` |
438
+
439
+ ```typescript
440
+ // Natural language
441
+ const result = await yata.ask('Find UserService');
442
+
443
+ // Equivalent API call
444
+ const entities = await yata.search('UserService', 10);
445
+ // or
446
+ const entity = await yata.getEntityByName('UserService');
447
+ ```
448
+
449
+ #### Find by Namespace
450
+
451
+ | Natural Language Query | Equivalent API Command |
452
+ |----------------------|------------------------|
453
+ | `Classes in app.services` | `yata.query({ entityFilters: { namespaces: ['app.services'], types: ['class'] } })` |
454
+ | `Show all classes in utils` | `yata.getEntitiesByNamespace('utils')` |
455
+
456
+ ```typescript
457
+ // Natural language
458
+ const result = await yata.ask('Classes in app.services');
459
+
460
+ // Equivalent API call
461
+ const queryResult = await yata.query({
462
+ entityFilters: {
463
+ namespaces: ['app.services'],
464
+ types: ['class'],
465
+ },
466
+ });
467
+ ```
468
+
469
+ #### Find Related
470
+
471
+ | Natural Language Query | Equivalent API Command |
472
+ |----------------------|------------------------|
473
+ | `Related to UserService` | `yata.getNeighbors(userServiceId, { direction: 'both' })` |
474
+ | `Entities related to Repository` | `yata.extractSubgraph(repositoryId, { depth: 1 })` |
475
+
476
+ ```typescript
477
+ // Natural language
478
+ const result = await yata.ask('Related to UserService');
479
+
480
+ // Equivalent API call
481
+ const entity = await yata.getEntityByName('UserService');
482
+ const neighbors = await yata.getNeighbors(entity.id, { direction: 'both' });
483
+ ```
484
+
485
+ #### Explain Relationship
486
+
487
+ | Natural Language Query | Equivalent API Command |
488
+ |----------------------|------------------------|
489
+ | `Relationship between UserService and Repository` | `yata.findPath(userServiceId, repositoryId)` |
490
+ | `How is A related to B?` | `yata.findPath(aId, bId, { direction: 'both' })` |
491
+
492
+ ```typescript
493
+ // Natural language
494
+ const result = await yata.ask('Relationship between UserService and Repository');
495
+
496
+ // Equivalent API call
497
+ const entityA = await yata.getEntityByName('UserService');
498
+ const entityB = await yata.getEntityByName('Repository');
499
+ const path = await yata.findPath(entityA.id, entityB.id, {
500
+ maxDepth: 5,
501
+ direction: 'both',
502
+ });
503
+ ```
504
+
505
+ ### Advanced Usage
506
+
507
+ ```typescript
508
+ // Query with configuration options
509
+ const result = await yata.ask('dependencies of UserService', {
510
+ language: 'en', // Explicit language
511
+ fuzzyMatching: true, // Enable fuzzy matching
512
+ minConfidence: 0.7, // Minimum confidence threshold
513
+ maxResults: 50, // Maximum results
514
+ includeInferred: true, // Include inferred relationships
515
+ });
516
+
517
+ // Result details
518
+ console.log('Query:', result.parsedQuery.originalQuery);
519
+ console.log('Intent:', result.parsedQuery.intent);
520
+ console.log('Subject:', result.parsedQuery.subject);
521
+ console.log('Confidence:', result.parsedQuery.confidence);
522
+ console.log('Entities:', result.entities.length);
523
+ console.log('Execution time:', result.executionTimeMs, 'ms');
524
+ ```
525
+
526
+ ### MCP Tool Integration
527
+
528
+ Natural language queries can also be used via the MCP server:
529
+
530
+ ```json
531
+ // Query via MCP (sdd_ask_knowledge tool)
532
+ // Input:
533
+ {
534
+ "question": "What functions call UserService?",
535
+ "maxResults": 20
536
+ }
537
+ ```
538
+
539
+ ### Supported Intents
540
+
541
+ | Intent | Description | Example | Internal API |
542
+ |--------|-------------|---------|--------------|
543
+ | `find_entity` | Search for entity | "Find UserService" | `search()`, `getEntityByName()` |
544
+ | `find_callers` | Find callers | "What calls X?" | `getRelationships(id, 'in')` |
545
+ | `find_callees` | Find callees | "What does X call?" | `getRelationships(id, 'out')` |
546
+ | `find_implementations` | Find implementations | "Implementations of X" | `getRelationships(id, 'in', {types: ['implements']})` |
547
+ | `find_dependencies` | Find dependencies | "What does X depend on?" | `traverse(id, ['depends-on'], 'forward')` |
548
+ | `find_dependents` | Find dependents | "What depends on X?" | `traverse(id, ['depends-on'], 'backward')` |
549
+ | `find_related` | Find related entities | "Related to X" | `getNeighbors(id, {direction: 'both'})` |
550
+ | `find_by_type` | Search by type | "Show all classes" | `query({entityFilters: {types: [...]}})` |
551
+ | `find_by_namespace` | Search by namespace | "Classes in app.services" | `query({entityFilters: {namespaces: [...]}})` |
552
+ | `explain_relationship` | Explain relationship | "Relationship between A and B" | `findPath(idA, idB)` |
553
+ | `general_search` | General search | Fallback for unmatched | `search(keywords)` |
554
+
555
+ ---
556
+
557
+ ## 🧠 Reasoning Engine
558
+
559
+ ### Running Inference
560
+
561
+ ```typescript
562
+ // Apply inference rules
563
+ const inferenceResult = await yata.infer({
564
+ rules: ['transitivity', 'type-compatibility'],
565
+ maxIterations: 100,
566
+ });
567
+
568
+ console.log(`Inferred ${inferenceResult.inferredRelationships.length} new relationships`);
569
+ ```
570
+
571
+ ### Custom Inference Rules
572
+
573
+ ```typescript
574
+ // Add custom rule
575
+ yata.addInferenceRule({
576
+ id: 'service-uses-repository',
577
+ name: 'Service Uses Repository',
578
+ description: 'Services typically use repositories',
579
+ condition: (source, target) =>
580
+ source.type === 'class' &&
581
+ source.name.endsWith('Service') &&
582
+ target.type === 'interface' &&
583
+ target.name.endsWith('Repository'),
584
+ consequent: {
585
+ type: 'uses',
586
+ weight: 0.8,
587
+ },
588
+ });
589
+ ```
590
+
591
+ ### Constraint Validation
592
+
593
+ ```typescript
594
+ // Validate graph constraints
595
+ const validation = await yata.validate({
596
+ constraints: ['no-circular-dependencies', 'single-inheritance'],
597
+ });
598
+
599
+ if (!validation.isValid) {
600
+ console.log('Violations:', validation.violations);
601
+ }
602
+ ```
603
+
604
+ ---
605
+
606
+ ## 📤 Import/Export
607
+
608
+ ### JSON Format
609
+
610
+ ```typescript
611
+ // Export
612
+ const jsonExport = await yata.exportJson('./backup.json');
613
+ console.log(`Exported ${jsonExport.entities.length} entities`);
614
+
615
+ // Import
616
+ const mergeResult = await yata.importJson('./backup.json', {
617
+ merge: true,
618
+ dryRun: false,
619
+ });
620
+
621
+ console.log(`Imported: ${mergeResult.entitiesAdded} added, ${mergeResult.entitiesUpdated} updated`);
622
+ ```
623
+
624
+ ### Unified Export API
625
+
626
+ ```typescript
627
+ // Export with multiple formats
628
+ const exportResult = await yata.export({
629
+ format: 'json', // 'json' | 'rdf' | 'graphml'
630
+ namespace: 'app.services',
631
+ outputPath: './export/services.json',
632
+ });
633
+
634
+ // Incremental export (changes only)
635
+ const incrementalExport = await yata.exportIncremental(
636
+ new Date('2024-01-01'),
637
+ { format: 'json' }
638
+ );
639
+ ```
640
+
641
+ ---
642
+
643
+ ## 🔄 KGPR (Knowledge Graph Pull Request)
644
+
645
+ KGPR is a workflow for sharing local knowledge graph changes with YATA Global.
646
+
647
+ ### Creating KGPR
648
+
649
+ ```typescript
650
+ import { createLocalKGPRManager } from '@nahisaho/yata-local';
651
+
652
+ const kgprManager = createLocalKGPRManager(yata.getDb());
653
+
654
+ const kgpr = await kgprManager.createKGPR({
655
+ title: 'Share UserService patterns',
656
+ description: 'Patterns learned from user authentication flow',
657
+ namespace: 'app.services',
658
+ entityTypes: ['class', 'interface'],
659
+ privacyLevel: 'strict', // 'strict' | 'moderate' | 'none'
660
+ author: 'developer@example.com',
661
+ });
662
+
663
+ console.log('KGPR created:', kgpr.id);
664
+ ```
665
+
666
+ ### Privacy Levels
667
+
668
+ | Level | Description |
669
+ |-------|-------------|
670
+ | `strict` | Remove file paths, line numbers, sensitive metadata |
671
+ | `moderate` | Relativize file paths, keep line numbers, remove sensitive metadata |
672
+ | `none` | No filtering |
673
+
674
+ ---
675
+
676
+ ## 🌙 Wake-Sleep Learning
677
+
678
+ Wake-Sleep is a continuous learning cycle for learning and consolidating patterns from code.
679
+
680
+ ```typescript
681
+ import { createLocalWakeSleepCycle } from '@nahisaho/yata-local';
682
+
683
+ const wakeSleep = createLocalWakeSleepCycle(yata.getDb(), {
684
+ wakeObserveLimit: 1000,
685
+ sleepMinClusterSize: 3,
686
+ sleepSimilarityThreshold: 0.7,
687
+ compressMinOccurrences: 5,
688
+ });
689
+
690
+ // Wake phase: observe code and extract patterns
691
+ const wakeResult = await wakeSleep.wake({
692
+ namespace: 'app.services',
693
+ entityTypes: ['class', 'function'],
694
+ });
695
+
696
+ // Sleep phase: consolidate and compress patterns
697
+ const sleepResult = await wakeSleep.sleep();
698
+
699
+ // Complete cycle
700
+ const cycleResult = await wakeSleep.runCycle({
701
+ namespace: 'app',
702
+ });
703
+ ```
704
+
705
+ ---
706
+
707
+ ## 📊 Statistics
708
+
709
+ ```typescript
710
+ const stats = await yata.getStats();
711
+
712
+ console.log('Graph Statistics:');
713
+ console.log(` Total entities: ${stats.totalEntities}`);
714
+ console.log(` Total relationships: ${stats.totalRelationships}`);
715
+ console.log(` Entities by type:`, stats.entitiesByType);
716
+ console.log(` Relationships by type:`, stats.relationshipsByType);
717
+ ```
718
+
719
+ ---
720
+
721
+ ## 📚 Related Documentation
722
+
723
+ - [YATA Global User Guide](./YATA-GLOBAL-GUIDE.md)
724
+ - [API Reference](./API-REFERENCE.md)
725
+ - [MUSUBIX User Guide](./USER-GUIDE.md)
726
+
727
+ ---
728
+
729
+ **Last Updated**: 2026-01-11
730
+ **Package**: `@nahisaho/yata-local`