Skip to main content
Glama
DEVELOPMENT.mdβ€’15.7 kB
# ZigNet Development Guide ## πŸ› οΈ Configurazione Ambiente ### Prerequisiti - Node.js >= 18.0.0 - pnpm (o npm) ### Installazione ```bash pnpm install ``` ## πŸ“œ Script Disponibili ### Build ```bash pnpm build # Compila TypeScript β†’ JavaScript pnpm build:watch # Watch mode per sviluppo pnpm clean # Pulisce la directory dist/ ``` ### Testing ```bash pnpm test # Esegue tutti i test pnpm test:watch # Watch mode per i test pnpm test:coverage # Test con coverage report # E2E Tests (27 tests) pnpm test tests/e2e/mcp-integration.test.ts # Solo test deterministici (no LLM richiesto) SKIP_LLM_TESTS=1 pnpm test tests/e2e # Test specifici pnpm test -- lexer # Test lexer pnpm test -- parser # Test parser pnpm test -- type-checker # Test type-checker ``` ### Linting & Formatting ```bash pnpm lint # Controlla errori ESLint pnpm lint:fix # Corregge errori ESLint automaticamente pnpm format # Formatta il codice con Prettier pnpm format:check # Verifica formattazione senza modificare pnpm typecheck # Controlla i tipi TypeScript senza compilare ``` ## πŸ“ Struttura del Progetto ``` zignet/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ lexer.ts βœ… Lexer completo (100% coverage) β”‚ β”œβ”€β”€ parser.ts βœ… Parser completo (AST generation) β”‚ β”œβ”€β”€ type-checker.ts βœ… Type checker completo β”‚ β”œβ”€β”€ codegen.ts βœ… Code generator completo β”‚ β”œβ”€β”€ config.ts βœ… Sistema di configurazione β”‚ β”œβ”€β”€ mcp-server.ts βœ… MCP server completo β”‚ β”œβ”€β”€ zig/ β”‚ β”‚ β”œβ”€β”€ manager.ts βœ… Multi-version Zig manager β”‚ β”‚ └── executor.ts βœ… zig ast-check + fmt wrapper β”‚ β”œβ”€β”€ llm/ β”‚ β”‚ β”œβ”€β”€ model-downloader.ts βœ… Auto-download GGUF β”‚ β”‚ └── session.ts βœ… node-llama-cpp integration β”‚ └── tools/ β”‚ β”œβ”€β”€ analyze.ts βœ… analyze_zig tool β”‚ β”œβ”€β”€ compile.ts βœ… compile_zig tool β”‚ β”œβ”€β”€ docs.ts βœ… get_zig_docs tool β”‚ └── suggest.ts βœ… suggest_fix tool β”œβ”€β”€ tests/ β”‚ β”œβ”€β”€ lexer.test.ts βœ… 33 test passati β”‚ β”œβ”€β”€ parser.test.ts βœ… Test completi β”‚ β”œβ”€β”€ type-checker.test.ts βœ… Test completi β”‚ β”œβ”€β”€ codegen.test.ts βœ… Test completi β”‚ └── e2e/ β”‚ β”œβ”€β”€ mcp-integration.test.ts βœ… 27 E2E tests β”‚ └── README.md βœ… Testing guide β”œβ”€β”€ dist/ # Output compilato (gitignored) β”œβ”€β”€ coverage/ # Report coverage (gitignored) └── docs/ β”œβ”€β”€ AGENTS.md βœ… Project specification β”œβ”€β”€ ARCHITECTURE.md βœ… Technical details β”œβ”€β”€ DEVELOPMENT.md πŸ“„ This file └── TESTING.md βœ… Testing documentation ``` ## πŸ“Š Test Coverage ### Unit Tests - **Lexer**: 100% Stmts | 99.02% Branch | 100% Funcs | 100% Lines (33 tests) - **Parser**: Complete coverage (AST generation, error handling) - **Type Checker**: Complete coverage (type validation, semantic analysis) - **Code Generator**: Complete coverage (code emission, formatting) ### E2E Tests (27 total) See [tests/e2e/README.md](../tests/e2e/README.md) for detailed testing guide. **Test Categories:** - βœ… **Tool 1 (analyze_zig)**: 4 tests - Zig compiler validation - βœ… **Tool 2 (compile_zig)**: 3 tests - Zig formatter - βœ… **Tool 3 (get_zig_docs)**: 5 tests - LLM documentation lookup - βœ… **Tool 4 (suggest_fix)**: 5 tests - LLM error fix suggestions - βœ… **Integration**: 3 tests - Combined tool workflows - βœ… **Performance**: 3 tests - Resource management, concurrency - βœ… **Edge Cases**: 4 tests - Empty code, long code, invalid input **Execution Time:** - Without LLM model: 8.7 seconds (deterministic tests only) - With LLM model: 60-120 seconds (includes model loading + inference) **Test Behavior:** - Deterministic tests (12): Always run, use Zig compiler directly - LLM tests (15): Auto-skip if model not found, graceful degradation - CI/CD ready: Runs on GitHub Actions without GPU requirements ### Coverage Reports ```bash | File | % Stmts | % Branch | % Funcs | % Lines | | -------- | ------- | -------- | ------- | ------- | | lexer.ts | 100 | 99.02 | 100 | 100 | ``` ## πŸ”§ Configurazione ### TypeScript (`tsconfig.json`) - Target: ES2022 - Strict mode abilitato - Output: `dist/` - Source maps: βœ… ### ESLint (`eslint.config.js`) - Parser: `@typescript-eslint/parser` - Regole: TypeScript + Prettier - Type-aware linting: βœ… ### Prettier (`.prettierrc.json`) - Single quotes: βœ… - Semicolons: βœ… - Print width: 100 - Tab width: 2 spazi ### Jest (`jest.config.js`) - Preset: ts-jest - Coverage: lcov + html - Test match: `**/*.test.ts`, `**/*.spec.ts` ## πŸš€ Workflow di Sviluppo ### 1. Sviluppo con Watch Mode ```bash # Terminal 1: Build automatico pnpm build:watch # Terminal 2: Test automatici pnpm test:watch ``` ### 2. Prima di Committare ```bash pnpm typecheck # Controlla tipi pnpm lint:fix # Corregge linting pnpm format # Formatta codice pnpm test # Esegue test ``` ### 3. Workflow Completo ```bash pnpm clean && pnpm build && pnpm lint && pnpm test:coverage ``` ## πŸ“Š Test Metrics ### Lexer Tests (33 total) - βœ… Keywords (2 tests) - βœ… Types (1 test) - βœ… Literals (7 tests) - βœ… Operators (6 tests) - βœ… Punctuation (3 tests) - βœ… Comments (2 tests) - βœ… Complex Code (3 tests) - βœ… Line/Column Tracking (2 tests) - βœ… Error Handling (2 tests) - βœ… Edge Cases (3 tests) - βœ… Token toString (1 test) --- ## πŸ§ͺ E2E Testing Guide ### Overview ZigNet uses a comprehensive E2E test suite to validate all MCP tools in realistic scenarios. Tests are designed to run both with and without the LLM model, enabling flexible CI/CD integration. ### Test Architecture **Conditional LLM Testing:** ```typescript let hasLLM = false; beforeAll(async () => { const modelPath = path.join(os.homedir(), ".zignet/models/zignet-qwen-7b-q4km.gguf"); hasLLM = fs.existsSync(modelPath); if (!hasLLM) { console.log("⚠️ LLM model not found, skipping LLM tests"); return; } // Dynamically import LLM modules only if model exists const { getLlama } = await import("node-llama-cpp"); // ... initialize LLM }, 120000); ``` **Test Pattern:** ```typescript it("should use LLM feature", async () => { if (!hasLLM) return; // Graceful skip const result = await getZigDocs({ topic: "comptime" }); expect(result.content).toContain("compile-time"); }, 30000); ``` ### Running E2E Tests ```bash # All E2E tests (27 tests) pnpm test tests/e2e/mcp-integration.test.ts # Deterministic tests only (12 tests, no LLM required) SKIP_LLM_TESTS=1 pnpm test tests/e2e # With verbose output pnpm test tests/e2e/mcp-integration.test.ts --verbose # Watch mode for development pnpm test:watch tests/e2e ``` ### Environment Variables | Variable | Default | Description | | ---------------------------- | ------------------------------------------- | --------------------------------- | | `ZIGNET_MODEL_PATH` | `~/.zignet/models/zignet-qwen-7b-q4km.gguf` | Path to GGUF model | | `ZIGNET_MODEL_AUTO_DOWNLOAD` | `false` | Auto-download model if missing | | `ZIGNET_GPU_LAYERS` | `35` | GPU offload layers (0 = CPU only) | | `ZIG_SUPPORTED` | `0.13.0,0.14.1,0.15.2` | Supported Zig versions | | `ZIG_DEFAULT` | `0.15.2` | Default Zig version | | `SKIP_LLM_TESTS` | `false` | Force skip LLM tests | ### Test Categories Breakdown #### 1. Tool 1: analyze_zig (4 tests) - Deterministic - βœ… Validates correct Zig code - βœ… Detects syntax errors - βœ… Detects type mismatches - βœ… Handles comptime expressions **Example:** ```typescript const result = await analyzeZig({ code: "fn add(a: i32, b: i32) i32 { return a + b; }", }); expect(result.errors).toHaveLength(0); expect(result.content[0].text).toContain("Analysis successful"); ``` #### 2. Tool 2: compile_zig (3 tests) - Deterministic - βœ… Formats simple functions - βœ… Preserves semantics after formatting - βœ… Handles struct definitions **Example:** ```typescript const result = await compileZig({ code: "fn add(a:i32,b:i32)i32{return a+b;}", }); expect(result.content[0].text).toContain("fn add(a: i32, b: i32) i32"); ``` #### 3. Tool 3: get_zig_docs (5 tests) - LLM-powered - βœ… Retrieves basic topic documentation - βœ… Retrieves intermediate topic documentation - βœ… Retrieves advanced topic documentation - βœ… Handles memory management topics - βœ… Handles generics topics **Example:** ```typescript if (!hasLLM) return; const result = await getZigDocs({ topic: "comptime", detail_level: "advanced", }); expect(result.content[0].text).toContain("comptime"); ``` #### 4. Tool 4: suggest_fix (5 tests) - LLM-powered - βœ… Suggests fixes for type errors - βœ… Suggests fixes for syntax errors - βœ… Suggests fixes for undefined variables - βœ… Suggests fixes for error set issues - βœ… Provides multiple fix suggestions **Example:** ```typescript if (!hasLLM) return; const result = await suggestFix({ error_message: "Type mismatch: cannot assign string to i32", code_context: 'var x: i32 = "hello";', error_type: "type_mismatch", }); expect(result.content[0].text).toContain("i32"); ``` #### 5. Integration Tests (3 tests) - Mixed - βœ… Analyze error β†’ Suggest fix workflow - βœ… Validate fix β†’ Format workflow - βœ… Get docs β†’ Validate comptime workflow **Example:** ```typescript // Step 1: Analyze code with error const analysis = await analyzeZig({ code: badCode }); expect(analysis.errors.length).toBeGreaterThan(0); // Step 2: Get fix suggestion if (hasLLM) { const fix = await suggestFix({ error_message: analysis.errors[0].message, code_context: badCode, }); expect(fix.content[0].text).toContain("suggestion"); } ``` #### 6. Performance Tests (3 tests) - Stress Tests - βœ… Multiple sequential LLM queries - βœ… Clean up LLM resources properly - βœ… Handle concurrent analyze operations **Example:** ```typescript const promises = Array(5) .fill(null) .map(() => analyzeZig({ code: validCode })); const results = await Promise.all(promises); results.forEach((r) => expect(r.errors).toHaveLength(0)); ``` #### 7. Edge Cases (4 tests) - Error Paths - βœ… Handles empty code gracefully - βœ… Handles very long code (100+ functions) - βœ… Handles invalid LLM topics gracefully - βœ… Handles malformed error messages **Example:** ```typescript const result = await analyzeZig({ code: "" }); expect(result.errors.length).toBeGreaterThan(0); expect(result.content[0].text).toContain("empty"); ``` ### CI/CD Integration **GitHub Actions Example:** ```yaml name: E2E Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "20" - name: Install dependencies run: pnpm install - name: Run deterministic tests only run: SKIP_LLM_TESTS=1 pnpm test tests/e2e env: NODE_ENV: test ``` **With LLM Model (optional):** ```yaml - name: Download LLM model run: | mkdir -p ~/.zignet/models wget -O ~/.zignet/models/zignet-qwen-7b-q4km.gguf \ https://huggingface.co/fulgidus/zignet-qwen2.5-coder-7b/resolve/main/gguf/zignet-qwen-7b-q4km.gguf - name: Run all E2E tests (including LLM) run: pnpm test tests/e2e env: ZIGNET_GPU_LAYERS: 0 # CPU-only for GitHub Actions ``` ### Adding New Tests **Pattern for deterministic tests:** ```typescript it("should test new feature", async () => { const result = await analyzeZig({ code: testCode }); expect(result.errors).toHaveLength(0); }); ``` **Pattern for LLM tests:** ```typescript it("should test LLM feature", async () => { if (!hasLLM) return; // Always add this guard const result = await getZigDocs({ topic: "new_topic" }); expect(result.content[0].text).toContain("expected_content"); }, 30000); // Timeout for LLM operations ``` ### Troubleshooting **Model not found:** ```bash # Check model path ls -lh ~/.zignet/models/zignet-qwen-7b-q4km.gguf # Download manually mkdir -p ~/.zignet/models wget -O ~/.zignet/models/zignet-qwen-7b-q4km.gguf \ https://huggingface.co/fulgidus/zignet-qwen2.5-coder-7b/resolve/main/gguf/zignet-qwen-7b-q4km.gguf ``` **Tests timeout:** ```bash # Increase Jest timeout (default: 120s for LLM) pnpm test tests/e2e -- --testTimeout=180000 ``` **Zig version mismatch:** ```bash # Check installed Zig version zig version # Install specific version ZIG_DEFAULT=0.15.2 pnpm test tests/e2e ``` ### Performance Benchmarks | Test Category | Tests | Avg Time | Notes | | ------------- | ------ | --------- | ---------------------------- | | analyze_zig | 4 | 400ms | Deterministic, fast | | compile_zig | 3 | 550ms | Deterministic, fast | | get_zig_docs | 5 | 8s | LLM-powered, model-dependent | | suggest_fix | 5 | 10s | LLM-powered, model-dependent | | Integration | 3 | 5s | Mixed (LLM + deterministic) | | Performance | 3 | 2s | Concurrent operations | | Edge Cases | 4 | 580ms | Error handling paths | | **TOTAL** | **27** | **323ms** | **8.7s (without LLM)** | **With LLM model (GPU-accelerated):** - First run: ~60s (model loading + inference) - Subsequent runs: ~30s (model cached in VRAM) For complete testing documentation, see [tests/e2e/README.md](../tests/e2e/README.md) --- ## 🎯 Stato Attuale e Prossimi Passi ### βœ… Completato (Phase 1-4) - βœ… Lexer completo (100% coverage) - βœ… Parser completo (AST generation) - βœ… Type Checker completo (semantic analysis) - βœ… Code Generator completo (code emission) - βœ… MCP Server completo (4 tools) - βœ… Zig Compiler integration (ast-check + fmt) - βœ… LLM fine-tuning (Qwen2.5-Coder-7B, 13,756 examples) - βœ… GGUF conversion (Q4_K_M, 4.4GB) - βœ… E2E test suite (27 tests, 100% pass rate) - βœ… Comprehensive documentation ### ⏳ Prossimi Passi (Phase 5: Deployment) - [ ] Pubblicare su npm (`@fulgidus/zignet`) - [ ] Creare release GitHub (v1.0.0) - [ ] Testare integrazione Claude Desktop - [ ] Testare integrazione VS Code + GitHub Copilot - [ ] Creare video demo/tutorial - [ ] Pubblicare su Hacker News / Reddit - [ ] Community feedback e iterazione ### 🎯 Future Enhancements - [ ] Support for more Zig versions (0.16.0+) - [ ] Incremental re-training pipeline - [ ] Plugin system for custom analyzers - [ ] LSP (Language Server Protocol) integration - [ ] Web-based playground ## πŸ“š Risorse - [TypeScript Handbook](https://www.typescriptlang.org/docs/) - [Jest Documentation](https://jestjs.io/) - [ESLint Rules](https://eslint.org/docs/rules/) - [Zig Language Reference](https://ziglang.org/documentation/master/) ## πŸ› Troubleshooting ### Jest non trova i moduli ```bash pnpm clean pnpm install pnpm build ``` ### ESLint errori strani ```bash rm -rf node_modules/.cache pnpm lint:fix ``` ### TypeScript errori di tipo ```bash pnpm typecheck ``` --- **Status**: βœ… Phase 4 Complete - All core features implemented, 27/27 E2E tests passing **Last Updated**: 2025-10-26

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fulgidus/zignet'

If you have feedback or need assistance with the MCP directory API, please join our Discord server