musubix 1.7.0 → 1.8.5

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.
@@ -21,10 +21,15 @@
21
21
  13. [YATA Global](#yata-global) *(v1.6.3)*
22
22
  14. [KGPR - Knowledge Graph Pull Request](#kgpr---knowledge-graph-pull-request) *(v1.6.4)*
23
23
  15. [YATA Platform Enhancements](#yata-platform-enhancements) *(v1.7.0)*
24
- 16. [MCP Server Integration](#mcp-server-integration)
25
- 17. [YATA Integration](#yata-integration)
26
- 18. [Best Practices](#best-practices)
27
- 19. [Troubleshooting](#troubleshooting)
24
+ 16. [Formal Verification](#formal-verification) *(v1.7.5)*
25
+ 17. [Security Analysis](#security-analysis) *(v1.8.0)*
26
+ 18. [DFG/CFG Extraction](#dfgcfg-extraction) *(v2.0.0-alpha.1)*
27
+ 19. [Lean 4 Integration](#lean-4-integration) *(v2.0.0-alpha.1)*
28
+ 20. [YATA Scale](#yata-scale) *(v2.0.0-alpha.1)*
29
+ 21. [MCP Server Integration](#mcp-server-integration)
30
+ 22. [YATA Integration](#yata-integration)
31
+ 23. [Best Practices](#best-practices)
32
+ 24. [Troubleshooting](#troubleshooting)
28
33
 
29
34
  ---
30
35
 
@@ -1093,6 +1098,596 @@ console.log(`UI available at ${server.getUrl()}`);
1093
1098
 
1094
1099
  ---
1095
1100
 
1101
+ ## Formal Verification
1102
+
1103
+ *(v1.7.5)*
1104
+
1105
+ The `@nahisaho/musubix-formal-verify` package provides formal verification capabilities using the Z3 SMT solver.
1106
+
1107
+ ### Installation
1108
+
1109
+ ```bash
1110
+ npm install @nahisaho/musubix-formal-verify
1111
+ # Optional: Install z3-solver for WebAssembly support
1112
+ npm install z3-solver
1113
+ ```
1114
+
1115
+ ### Z3 SMT Solver Integration
1116
+
1117
+ ```typescript
1118
+ import { Z3Adapter, PreconditionVerifier, PostconditionVerifier } from '@nahisaho/musubix-formal-verify';
1119
+
1120
+ // Create Z3 adapter (auto-selects backend)
1121
+ const z3 = await Z3Adapter.create();
1122
+
1123
+ // Precondition verification
1124
+ const preVerifier = new PreconditionVerifier(z3);
1125
+ const result = await preVerifier.verify({
1126
+ condition: { expression: 'amount > 0 && balance >= amount', format: 'javascript' },
1127
+ variables: [
1128
+ { name: 'amount', type: 'Int' },
1129
+ { name: 'balance', type: 'Int' },
1130
+ ],
1131
+ });
1132
+
1133
+ console.log(result.status); // 'valid' | 'invalid' | 'unknown' | 'error'
1134
+ ```
1135
+
1136
+ ### Hoare Triple Verification
1137
+
1138
+ ```typescript
1139
+ // Verify {P} C {Q}
1140
+ const postVerifier = new PostconditionVerifier(z3);
1141
+ const hoareResult = await postVerifier.verify({
1142
+ precondition: { expression: 'balance >= amount', format: 'javascript' },
1143
+ postcondition: { expression: 'balance_new == balance - amount', format: 'javascript' },
1144
+ preVariables: [{ name: 'balance', type: 'Int' }, { name: 'amount', type: 'Int' }],
1145
+ postVariables: [{ name: 'balance_new', type: 'Int' }],
1146
+ transition: 'balance_new == balance - amount',
1147
+ });
1148
+ ```
1149
+
1150
+ ### EARS to SMT Conversion
1151
+
1152
+ ```typescript
1153
+ import { EarsToSmtConverter } from '@nahisaho/musubix-formal-verify';
1154
+
1155
+ const converter = new EarsToSmtConverter();
1156
+
1157
+ // Convert EARS requirements to SMT-LIB2
1158
+ const results = converter.convertMultiple([
1159
+ 'THE system SHALL validate inputs', // ubiquitous
1160
+ 'WHEN error, THE system SHALL notify user', // event-driven
1161
+ 'WHILE busy, THE system SHALL queue requests', // state-driven
1162
+ 'THE system SHALL NOT expose secrets', // unwanted
1163
+ 'IF admin, THEN THE system SHALL allow edit', // optional
1164
+ ]);
1165
+
1166
+ results.forEach(r => {
1167
+ console.log(`Pattern: ${r.formula?.metadata.earsPattern.type}`);
1168
+ console.log(`SMT: ${r.formula?.smtLib2}`);
1169
+ });
1170
+ ```
1171
+
1172
+ ### Traceability Database
1173
+
1174
+ ```typescript
1175
+ import { TraceabilityDB, ImpactAnalyzer } from '@nahisaho/musubix-formal-verify';
1176
+
1177
+ // Create SQLite-based traceability database
1178
+ const db = new TraceabilityDB('./trace.db');
1179
+
1180
+ // Add nodes
1181
+ await db.addNode({ id: 'REQ-001', type: 'requirement', title: 'User Auth' });
1182
+ await db.addNode({ id: 'DES-001', type: 'design', title: 'AuthService' });
1183
+ await db.addNode({ id: 'CODE-001', type: 'code', title: 'auth.ts' });
1184
+
1185
+ // Add traceability links
1186
+ await db.addLink({ source: 'DES-001', target: 'REQ-001', type: 'satisfies' });
1187
+ await db.addLink({ source: 'CODE-001', target: 'DES-001', type: 'implements' });
1188
+
1189
+ // Impact analysis
1190
+ const analyzer = new ImpactAnalyzer(db);
1191
+ const impact = await analyzer.analyze('REQ-001');
1192
+ console.log(`Impacted nodes: ${impact.totalImpacted}`);
1193
+ ```
1194
+
1195
+ ### v1.7.5 Package Summary
1196
+
1197
+ | Package | Description |
1198
+ |---------|-------------|
1199
+ | `@nahisaho/musubix-formal-verify` | Z3 integration, Hoare verification, EARS→SMT, TraceabilityDB |
1200
+
1201
+ ### Supported Variable Types
1202
+
1203
+ | Type | Description |
1204
+ |------|-------------|
1205
+ | `Int` | Integer values |
1206
+ | `Real` | Real numbers |
1207
+ | `Bool` | Boolean values |
1208
+ | `String` | String values |
1209
+ | `Array` | Array types |
1210
+ | `BitVec` | Bit vectors |
1211
+
1212
+ ---
1213
+
1214
+ ## Security Analysis
1215
+
1216
+ *(v1.8.0)*
1217
+
1218
+ The `@nahisaho/musubix-security` package provides comprehensive security analysis capabilities for TypeScript/JavaScript projects.
1219
+
1220
+ ### Installation
1221
+
1222
+ ```bash
1223
+ npm install @nahisaho/musubix-security
1224
+ ```
1225
+
1226
+ ### Vulnerability Scanning
1227
+
1228
+ Detects OWASP Top 10 and CWE Top 25 vulnerabilities using AST analysis:
1229
+
1230
+ ```typescript
1231
+ import { VulnerabilityScanner, createSecurityService } from '@nahisaho/musubix-security';
1232
+
1233
+ // Scan a single file
1234
+ const scanner = new VulnerabilityScanner();
1235
+ const vulnerabilities = scanner.scanFile('src/api.ts');
1236
+
1237
+ // Scan a directory
1238
+ const result = await scanner.scanDirectory('./src');
1239
+ console.log(`Found ${result.vulnerabilities.length} vulnerabilities`);
1240
+ console.log(`Scanned ${result.scannedFiles} files`);
1241
+ ```
1242
+
1243
+ ### Detected Vulnerabilities
1244
+
1245
+ | Category | CWE | Severity |
1246
+ |----------|-----|----------|
1247
+ | SQL Injection | CWE-89 | Critical |
1248
+ | Command Injection | CWE-78 | Critical |
1249
+ | XSS | CWE-79 | High |
1250
+ | Path Traversal | CWE-22 | High |
1251
+ | Code Injection | CWE-94 | Critical |
1252
+ | NoSQL Injection | CWE-943 | High |
1253
+
1254
+ ### Secret Detection
1255
+
1256
+ Detects hardcoded credentials and sensitive information:
1257
+
1258
+ ```typescript
1259
+ import { SecretDetector } from '@nahisaho/musubix-security';
1260
+
1261
+ const detector = new SecretDetector();
1262
+ const secrets = detector.scanContent(content, 'config.ts');
1263
+ const result = await detector.scan('./src');
1264
+
1265
+ console.log(`Found ${result.summary.total} secrets`);
1266
+ ```
1267
+
1268
+ ### Detected Secret Types
1269
+
1270
+ | Type | Pattern |
1271
+ |------|--------|
1272
+ | AWS Access Key | `AKIA...` |
1273
+ | AWS Secret Key | 40-char base64 |
1274
+ | GitHub Token | `ghp_*`, `gho_*`, `ghu_*` |
1275
+ | Private Key | PEM format |
1276
+ | Database URL | `postgres://`, `mongodb://` |
1277
+ | JWT Secret | JWT signing secrets |
1278
+ | Stripe Key | `sk_live_*`, `sk_test_*` |
1279
+
1280
+ ### Taint Analysis
1281
+
1282
+ Tracks data flow from user input (sources) to dangerous functions (sinks):
1283
+
1284
+ ```typescript
1285
+ import { TaintAnalyzer } from '@nahisaho/musubix-security';
1286
+
1287
+ const analyzer = new TaintAnalyzer();
1288
+ const result = analyzer.analyze('./src');
1289
+
1290
+ console.log(`Sources: ${result.sources.length}`);
1291
+ console.log(`Sinks: ${result.sinks.length}`);
1292
+ console.log(`Taint paths: ${result.paths.length}`);
1293
+ ```
1294
+
1295
+ ### Dependency Auditing
1296
+
1297
+ Integrates with npm audit to detect vulnerable dependencies:
1298
+
1299
+ ```typescript
1300
+ import { DependencyAuditor } from '@nahisaho/musubix-security';
1301
+
1302
+ const auditor = new DependencyAuditor();
1303
+ const result = await auditor.audit('./project');
1304
+
1305
+ console.log(`Critical: ${result.summary.critical}`);
1306
+ console.log(`High: ${result.summary.high}`);
1307
+ ```
1308
+
1309
+ ### Integrated Security Service
1310
+
1311
+ Combines all security analysis features:
1312
+
1313
+ ```typescript
1314
+ import { createSecurityService } from '@nahisaho/musubix-security';
1315
+
1316
+ const service = createSecurityService();
1317
+
1318
+ // Full security scan
1319
+ const result = await service.scan({
1320
+ target: './src',
1321
+ vulnerabilities: true,
1322
+ taint: true,
1323
+ secrets: true,
1324
+ dependencies: true,
1325
+ generateFixes: true,
1326
+ });
1327
+
1328
+ console.log(`Total vulnerabilities: ${result.summary.totalVulnerabilities}`);
1329
+ console.log(`Total secrets: ${result.summary.totalSecrets}`);
1330
+ console.log(`Fixes generated: ${result.summary.fixesGenerated}`);
1331
+ ```
1332
+
1333
+ ### Report Generation
1334
+
1335
+ Generate reports in multiple formats:
1336
+
1337
+ ```typescript
1338
+ // SARIF format (GitHub Code Scanning compatible)
1339
+ const sarifReport = await service.generateReport(result, 'sarif');
1340
+
1341
+ // Markdown format
1342
+ const mdReport = await service.generateReport(result, 'markdown');
1343
+
1344
+ // HTML format
1345
+ const htmlReport = await service.generateReport(result, 'html');
1346
+ ```
1347
+
1348
+ ### CLI Usage
1349
+
1350
+ ```bash
1351
+ # Full security scan
1352
+ npx musubix-security scan ./src
1353
+
1354
+ # Vulnerability scan only
1355
+ npx musubix-security scan ./src --vulnerabilities-only
1356
+
1357
+ # Secret detection
1358
+ npx musubix-security secrets ./src
1359
+
1360
+ # Taint analysis
1361
+ npx musubix-security taint ./src
1362
+
1363
+ # Dependency audit
1364
+ npx musubix-security audit ./project
1365
+
1366
+ # Generate SARIF report
1367
+ npx musubix-security scan ./src --format sarif --output report.sarif
1368
+ ```
1369
+
1370
+ ### v1.8.0 Package Summary
1371
+
1372
+ | Package | Description |
1373
+ |---------|-------------|
1374
+ | `@nahisaho/musubix-security` | Vulnerability scanning, secret detection, taint analysis, dependency auditing |
1375
+
1376
+ ---
1377
+
1378
+ ## DFG/CFG Extraction
1379
+
1380
+ *(v2.0.0-alpha.1)*
1381
+
1382
+ The `@nahisaho/musubix-dfg` package provides Data Flow Graph (DFG) and Control Flow Graph (CFG) extraction for TypeScript and JavaScript code analysis.
1383
+
1384
+ ### Installation
1385
+
1386
+ ```bash
1387
+ npm install @nahisaho/musubix-dfg
1388
+ ```
1389
+
1390
+ ### DFG Extraction
1391
+
1392
+ Extract data flow graphs from source code:
1393
+
1394
+ ```typescript
1395
+ import { extractDFG, DFGExtractor } from '@nahisaho/musubix-dfg';
1396
+
1397
+ // Simple extraction
1398
+ const dfg = extractDFG(sourceCode, 'typescript');
1399
+
1400
+ // With configuration
1401
+ const extractor = new DFGExtractor({
1402
+ includeImplicitFlows: true,
1403
+ trackConstants: true,
1404
+ });
1405
+ const result = extractor.extract(sourceCode);
1406
+
1407
+ console.log(`Nodes: ${result.nodes.length}`);
1408
+ console.log(`Edges: ${result.edges.length}`);
1409
+ ```
1410
+
1411
+ ### CFG Extraction
1412
+
1413
+ Extract control flow graphs:
1414
+
1415
+ ```typescript
1416
+ import { extractCFG, CFGExtractor } from '@nahisaho/musubix-dfg';
1417
+
1418
+ const cfg = extractCFG(sourceCode);
1419
+
1420
+ // Traverse CFG
1421
+ for (const block of cfg.blocks) {
1422
+ console.log(`Block ${block.id}: ${block.statements.length} statements`);
1423
+ console.log(`Successors: ${block.successors.join(', ')}`);
1424
+ }
1425
+ ```
1426
+
1427
+ ### Def-Use Chain Analysis
1428
+
1429
+ Build definition-use chains for variable tracking:
1430
+
1431
+ ```typescript
1432
+ import { analyzeDefUse } from '@nahisaho/musubix-dfg';
1433
+
1434
+ const chains = analyzeDefUse(dfg);
1435
+
1436
+ for (const chain of chains) {
1437
+ console.log(`Variable: ${chain.variable}`);
1438
+ console.log(`Defined at: line ${chain.definition.line}`);
1439
+ console.log(`Used at: ${chain.uses.map(u => u.line).join(', ')}`);
1440
+ }
1441
+ ```
1442
+
1443
+ ### Data Dependency Analysis
1444
+
1445
+ Analyze data dependencies between statements:
1446
+
1447
+ ```typescript
1448
+ import { analyzeDataDependencies } from '@nahisaho/musubix-dfg';
1449
+
1450
+ const deps = analyzeDataDependencies(dfg);
1451
+
1452
+ for (const dep of deps) {
1453
+ console.log(`${dep.from} -> ${dep.to}: ${dep.type}`);
1454
+ }
1455
+ ```
1456
+
1457
+ ---
1458
+
1459
+ ## Lean 4 Integration
1460
+
1461
+ *(v2.0.0-alpha.1)*
1462
+
1463
+ The `@nahisaho/musubix-lean` package provides integration with the Lean 4 theorem prover for formal verification of requirements.
1464
+
1465
+ ### Installation
1466
+
1467
+ ```bash
1468
+ npm install @nahisaho/musubix-lean
1469
+ ```
1470
+
1471
+ ### EARS to Lean Conversion
1472
+
1473
+ Convert EARS requirements to Lean 4 theorems:
1474
+
1475
+ ```typescript
1476
+ import { EarsToLeanConverter } from '@nahisaho/musubix-lean';
1477
+
1478
+ const converter = new EarsToLeanConverter();
1479
+
1480
+ // Convert EARS requirement
1481
+ const earsRequirement = {
1482
+ id: 'REQ-001',
1483
+ type: 'event-driven',
1484
+ trigger: 'user clicks submit',
1485
+ response: 'system saves form data',
1486
+ };
1487
+
1488
+ const theorem = converter.convert(earsRequirement);
1489
+ console.log(theorem.leanCode);
1490
+ // theorem REQ_001 : ∀ (s : State),
1491
+ // user_clicks_submit s → saves_form_data (next s)
1492
+ ```
1493
+
1494
+ ### Lean AST Parsing
1495
+
1496
+ Parse and manipulate Lean 4 code:
1497
+
1498
+ ```typescript
1499
+ import { LeanParser, LeanAST } from '@nahisaho/musubix-lean';
1500
+
1501
+ const parser = new LeanParser();
1502
+ const ast = parser.parse(leanCode);
1503
+
1504
+ // Traverse AST
1505
+ for (const decl of ast.declarations) {
1506
+ if (decl.type === 'theorem') {
1507
+ console.log(`Theorem: ${decl.name}`);
1508
+ console.log(`Statement: ${decl.statement}`);
1509
+ }
1510
+ }
1511
+ ```
1512
+
1513
+ ### Proof Engine
1514
+
1515
+ Execute proofs using Lean 4:
1516
+
1517
+ ```typescript
1518
+ import { LeanProofEngine } from '@nahisaho/musubix-lean';
1519
+
1520
+ const engine = new LeanProofEngine({
1521
+ leanPath: '/usr/bin/lean',
1522
+ timeout: 30000,
1523
+ });
1524
+
1525
+ const result = await engine.prove(theorem);
1526
+
1527
+ if (result.success) {
1528
+ console.log('Proof verified!');
1529
+ console.log(`Proof: ${result.proof}`);
1530
+ } else {
1531
+ console.log(`Failed: ${result.error}`);
1532
+ }
1533
+ ```
1534
+
1535
+ ### ReProver Integration
1536
+
1537
+ Use ReProver for automated proof search:
1538
+
1539
+ ```typescript
1540
+ import { ReProverClient } from '@nahisaho/musubix-lean';
1541
+
1542
+ const reprover = new ReProverClient({
1543
+ endpoint: 'http://localhost:8080',
1544
+ maxDepth: 10,
1545
+ });
1546
+
1547
+ const proof = await reprover.searchProof(theorem);
1548
+
1549
+ if (proof.found) {
1550
+ console.log('Proof found!');
1551
+ console.log(proof.tactics);
1552
+ }
1553
+ ```
1554
+
1555
+ ---
1556
+
1557
+ ## YATA Scale
1558
+
1559
+ *(v2.0.0-alpha.1)*
1560
+
1561
+ The `@nahisaho/yata-scale` package provides distributed knowledge graph capabilities with sharding, caching, and synchronization.
1562
+
1563
+ ### Installation
1564
+
1565
+ ```bash
1566
+ npm install @nahisaho/yata-scale
1567
+ ```
1568
+
1569
+ ### High-Level API
1570
+
1571
+ Use `YataScaleManager` for simplified access:
1572
+
1573
+ ```typescript
1574
+ import { YataScaleManager } from '@nahisaho/yata-scale';
1575
+
1576
+ const yata = new YataScaleManager({
1577
+ shards: 16,
1578
+ cacheConfig: {
1579
+ l1MaxSize: 1000,
1580
+ l2MaxSize: 10000,
1581
+ l3Path: './cache',
1582
+ },
1583
+ });
1584
+
1585
+ // Store entity
1586
+ await yata.putEntity({
1587
+ id: 'entity-1',
1588
+ type: 'Document',
1589
+ properties: { title: 'Example' },
1590
+ });
1591
+
1592
+ // Query
1593
+ const results = await yata.query('SELECT ?s WHERE { ?s rdf:type Document }');
1594
+ ```
1595
+
1596
+ ### Sharding
1597
+
1598
+ Distribute data across shards using consistent hashing:
1599
+
1600
+ ```typescript
1601
+ import { ShardManager, HashPartitionStrategy } from '@nahisaho/yata-scale';
1602
+
1603
+ const shardManager = new ShardManager({
1604
+ shardCount: 16,
1605
+ virtualNodes: 150,
1606
+ strategy: new HashPartitionStrategy(),
1607
+ });
1608
+
1609
+ // Get shard for entity
1610
+ const shard = shardManager.getShardForEntity('entity-id');
1611
+ console.log(`Entity assigned to shard ${shard.id}`);
1612
+
1613
+ // Rebalance on node changes
1614
+ await shardManager.addNode('node-5');
1615
+ ```
1616
+
1617
+ ### Multi-Tier Caching
1618
+
1619
+ Three-tier caching for optimal performance:
1620
+
1621
+ ```typescript
1622
+ import { CacheManager, L1Cache, L2Cache, L3Cache } from '@nahisaho/yata-scale';
1623
+
1624
+ const cache = new CacheManager({
1625
+ l1: new L1Cache({ maxSize: 1000 }), // LRU cache
1626
+ l2: new L2Cache({ maxSize: 10000 }), // LFU cache
1627
+ l3: new L3Cache({ path: './cache' }), // Disk cache
1628
+ });
1629
+
1630
+ // Cache operations
1631
+ await cache.set('key', value, { ttl: 3600 });
1632
+ const result = await cache.get('key');
1633
+
1634
+ // Invalidation
1635
+ await cache.invalidate('key');
1636
+ await cache.invalidatePattern('user:*');
1637
+ ```
1638
+
1639
+ ### Index Management
1640
+
1641
+ Multiple index types for efficient queries:
1642
+
1643
+ ```typescript
1644
+ import { IndexManager, BPlusTreeIndex, FullTextIndex, GraphIndex } from '@nahisaho/yata-scale';
1645
+
1646
+ const indexManager = new IndexManager();
1647
+
1648
+ // B+ Tree for range queries
1649
+ indexManager.addIndex('timestamp', new BPlusTreeIndex());
1650
+
1651
+ // Full-text for search
1652
+ indexManager.addIndex('content', new FullTextIndex());
1653
+
1654
+ // Graph for traversal
1655
+ indexManager.addIndex('relationships', new GraphIndex());
1656
+ ```
1657
+
1658
+ ### Vector Clock Synchronization
1659
+
1660
+ Distributed synchronization with conflict resolution:
1661
+
1662
+ ```typescript
1663
+ import { SyncController, VectorClock, ConflictResolver } from '@nahisaho/yata-scale';
1664
+
1665
+ const sync = new SyncController({
1666
+ nodeId: 'node-1',
1667
+ conflictStrategy: 'last-write-wins',
1668
+ });
1669
+
1670
+ // Synchronize with peers
1671
+ await sync.synchronize();
1672
+
1673
+ // Manual conflict resolution
1674
+ sync.onConflict((conflict) => {
1675
+ console.log(`Conflict on ${conflict.key}`);
1676
+ return conflict.local; // or conflict.remote
1677
+ });
1678
+ ```
1679
+
1680
+ ### v2.0.0-alpha.1 Package Summary
1681
+
1682
+ | Package | Tests | Description |
1683
+ |---------|-------|-------------|
1684
+ | `@nahisaho/musubix-dfg` | 30 | DFG/CFG extraction, Def-Use analysis |
1685
+ | `@nahisaho/musubix-lean` | 151 | Lean 4 theorem proving, EARS conversion |
1686
+ | `@nahisaho/yata-scale` | 57 | Distributed sharding, caching, sync |
1687
+ | **Total** | **238** | **Phase 1: Deep Symbolic Integration** |
1688
+
1689
+ ---
1690
+
1096
1691
  ## MCP Server Integration
1097
1692
 
1098
1693
  ### CLI Startup
@@ -1703,6 +2298,6 @@ const client = createYATAClient({
1703
2298
 
1704
2299
  ---
1705
2300
 
1706
- **Version**: 1.6.0
1707
- **Last Updated**: 2026-01-06
2301
+ **Version**: 1.8.5
2302
+ **Last Updated**: 2026-01-08
1708
2303
  **MUSUBIX Project**