// tools/suggest-tooling/platform-tooling-catalog.ts
// SPEC-015a: Tooling suggestions for Smart Contracts and ML projects
// Criteria 14: Smart contract security, gas optimization, testnets
// Criteria 15: ML experiment tracking, data versioning, model serving
// === Smart contract tooling ===
/**
 * Returns true when the project is a smart contract project.
 */
function isSmartContractProject(knowledge) {
    const { projectCategory, framework, stack } = knowledge;
    if (projectCategory === 'smart-contract') {
        return true;
    }
    if (framework !== null && ['hardhat', 'foundry', 'anchor', 'move'].includes(framework)) {
        return true;
    }
    return stack.some((s) => ['solidity', 'hardhat', 'foundry', 'anchor'].includes(s.toLowerCase()));
}
/**
 * Returns true when the project is an ML/AI project.
 */
function isMLProject(knowledge) {
    const { projectCategory, stack } = knowledge;
    if (projectCategory === 'ml') {
        return true;
    }
    const mlIndicators = [
        'pytorch',
        'tensorflow',
        'scikit-learn',
        'sklearn',
        'langchain',
        'transformers',
        'huggingface',
    ];
    return stack.some((s) => mlIndicators.some((ind) => s.toLowerCase().includes(ind)));
}
function buildSmartContractToolingLines(framework) {
    const lines = [
        '## Smart Contract Tooling',
        '',
        '### Security Analysis',
        '',
        '- **Slither** — Static analyzer for Solidity; detects reentrancy, overflow, access control issues',
        '  - Install: `pip install slither-analyzer`',
        '  - Run: `slither . --print human-summary`',
        '- **Mythril** — Symbolic execution security scanner',
        '  - Install: `pip install mythril`',
        '  - Run: `myth analyze src/MyContract.sol`',
        '- **Echidna** — Smart fuzzer for invariant testing',
        '  - Install: `brew install echidna` (macOS)',
        '  - Run: `echidna . --contract MyContract`',
        '- **OpenZeppelin Defender** — Runtime monitoring and automated pausing',
        '',
        '### Gas Optimization',
        '',
        '- **Hardhat Gas Reporter** — Reports gas usage per test/function',
        '  - Install: `npm install --save-dev hardhat-gas-reporter`',
        '  - Config: `gasReporter: { enabled: true, currency: "USD" }`',
        '- **Foundry Gas Snapshots** — `forge snapshot` creates gas baseline',
        '  - Run: `forge snapshot --diff` to detect regressions',
        '- **eth-gas-reporter** — Detailed gas costs in CI output',
        '- **Optimization checklist:**',
        '  - Use `uint256` (not smaller uints unless packed)',
        '  - Pack struct fields to minimize storage slots',
        '  - Cache storage reads in memory inside loops',
        '  - Use `calldata` instead of `memory` for read-only params',
        '',
        '### Testing Frameworks',
        '',
    ];
    if (framework === 'foundry') {
        lines.push('- **Foundry (Forge)** — Fast Rust-based testing (fuzzing + invariant built-in)', '  - Run: `forge test -vvv`', '  - Fuzz: `testFuzz_*` functions get random inputs automatically', '  - Invariant: `invariant_*` functions tested against stateful mutations');
    }
    else {
        lines.push('- **Hardhat** — JavaScript/TypeScript tests with Chai + Waffle', '  - Run: `npx hardhat test`', '  - Coverage: `npx hardhat coverage`', '- **Hardhat-Ignition** — Declarative deployment scripting');
    }
    lines.push('', '### Testnets & Deployment', '', '- **Sepolia** — Ethereum recommended testnet (PoS, mirrors mainnet)', '- **Goerli** — Deprecated (use Sepolia)', '- **Polygon Mumbai** — Low-cost L2 testnet', '- **Alchemy / Infura** — Managed RPC endpoints', '- **Hardhat Network** — Local EVM fork for integration tests', '  - Fork mainnet: `hardhat: { forking: { url: process.env.RPC_URL } }`', '- **Tenderly** — Transaction simulation and real-time monitoring', '- **OpenZeppelin Contracts** — Audited implementations (ERC20, ERC721, AccessControl)', '', '### Audit Checklist', '', '- [ ] Slither scan passes (0 high severity)', '- [ ] Mythril scan passes (no vulnerabilities)', '- [ ] Gas snapshot baseline created and regression-tested in CI', '- [ ] All admin functions have access control', '- [ ] Reentrancy guards on external call functions', '- [ ] No `selfdestruct` or deprecated opcodes', '- [ ] External audit scheduled before mainnet deployment', '');
    return lines;
}
function buildMLToolingLines(stack) {
    const hasLangChain = stack.some((s) => s.includes('langchain'));
    const lines = [
        '## ML/AI Tooling',
        '',
        '### Experiment Tracking',
        '',
        '- **MLflow** — Open-source experiment tracking, model registry, and serving',
        '  - Install: `pip install mlflow`',
        '  - Log: `mlflow.log_metric("accuracy", 0.92)`',
        '  - UI: `mlflow ui` → http://localhost:5000',
        '- **Weights & Biases (W&B)** — Cloud experiment tracking with rich dashboards',
        '  - Install: `pip install wandb`',
        '  - Init: `wandb.init(project="my-project")`',
        '  - Sweep: built-in hyperparameter optimization',
        '- **Comet ML** — Alternative to W&B with similar features',
        '',
        '### Data Versioning',
        '',
        '- **DVC (Data Version Control)** — Git-like versioning for datasets and models',
        '  - Install: `pip install dvc`',
        '  - Track: `dvc add data/dataset.csv`',
        '  - Remote: `dvc remote add myremote s3://bucket/path`',
        '  - Pipeline: `dvc run` for reproducible stages',
        '- **LakeFS** — S3-compatible data lake with Git semantics',
        '- **Delta Lake** — ACID transactions on data lakes (Spark ecosystem)',
        '',
        '### Model Serving',
        '',
        '- **FastAPI + Uvicorn** — Lightweight REST API for model inference',
        '  - Pattern: load model once on startup, serve predictions via POST',
        '- **BentoML** — Model packaging and serving with deployment targets',
        '  - Install: `pip install bentoml`',
        '  - Build: `bentoml build` → container ready to deploy',
        '- **Triton Inference Server** — NVIDIA GPU-optimized serving',
        '- **Ray Serve** — Scalable model serving on distributed Ray cluster',
    ];
    if (hasLangChain) {
        lines.push('', '### LangChain / LLM Tooling', '', '- **LangSmith** — Tracing and evaluation for LangChain applications', '  - Install: `pip install langsmith`', '  - Set: `LANGCHAIN_TRACING_V2=true`', '- **LangServe** — Deploy LangChain runnables as REST APIs', '- **Ragas** — RAG evaluation framework (faithfulness, relevancy, context recall)', '  - Install: `pip install ragas`');
    }
    lines.push('', '### Data Quality & Drift', '', '- **Great Expectations** — Data validation with rich expectation suites', '  - Install: `pip install great-expectations`', '- **Evidently** — Data drift, model performance, and target drift reports', '  - Install: `pip install evidently`', '- **whylogs** — Lightweight statistical profiling for data monitoring', '', '### ML Checklist', '', '- [ ] Experiment tracker configured (MLflow or W&B)', '- [ ] Dataset versioned in DVC with remote storage', '- [ ] Data validation suite written (Great Expectations)', '- [ ] Drift detection configured for production (Evidently)', '- [ ] Model registry with staging/production stages', '- [ ] Inference latency SLA defined and tested', '- [ ] Model explainability documented (SHAP, LIME if needed)', '');
    return lines;
}
// === Public API ===
/**
 * Generate platform-specific tooling lines for smart contracts and ML.
 * Returns empty array if project is not a specialty platform.
 */
export function getPlatformTooling(knowledge) {
    const lines = [];
    const framework = knowledge.framework?.toLowerCase() ?? '';
    const stack = knowledge.stack.map((s) => s.toLowerCase());
    if (isSmartContractProject(knowledge)) {
        lines.push(...buildSmartContractToolingLines(framework));
    }
    if (isMLProject(knowledge)) {
        lines.push(...buildMLToolingLines(stack));
    }
    return lines;
}
//# sourceMappingURL=platform-tooling-catalog.js.map