conda-env-manager · diff
git:20260506.86420c0 to git:20261014.f405841
47 added, 280 removed. Audit A to A.
---
name: conda-env-manager
- description: "Use this skill whenever the user wants to create, activate, list, export, update, clone, remove, or otherwise manage conda environments, or when a deep-learning / model skill requires a clean, isolated conda environment (e.g. 'create conda env for torch 2.3 cuda', 'export current env to yml', 'list all my conda envs', 'update packages in neuroclaw-dl', 'remove old env', 'clone env for reproducibility', 'install pytorch in new env'). Triggers include: 'conda create', 'conda env', 'make new environment', 'export yml', 'activate env', 'conda list envs', 'update conda env', 'clean environment', 'reproduce env', 'conda remove'. This skill is the mandatory gatekeeper for conda operations: it ALWAYS plans first, shows commands + risks + best practices, and waits for explicit user confirmation before executing anything."
- license: MIT License (NeuroClaw custom skill – freely modifiable within the project)
+ description: "Create, inspect, export, update or clone a Conda environment with explicit package targets and execution receipts. Use for environment management, not merely because a task uses Python."
+ license: MIT License (NeuroClaw custom skill)
layer: subagent
skill_type: tool
dependencies:
- dependency-planner
---
- # Conda Environment Manager (Tool Layer)
-
- ## Overview
-
- Conda is the backbone for reproducible, cross-platform environments in NeuroClaw — especially for CUDA-dependent deep learning stacks (PyTorch, TensorFlow, MONAI, nnU-Net), neuroimaging tools (ANTs, FSL wrappers, nipype), and scientific computing packages.
-
- This skill acts as the **interface-layer orchestrator** for all common conda operations, preventing accidental modification of the base environment, reducing version conflicts, and enforcing best practices (isolated environments per project, environment.yml for reproducibility, explicit version pinning, dry-run previews).
-
- **Strict workflow (never skipped):**
- 1. Parse user intent from the request or context (create / export / update / remove / clone / list / activate guidance).
- 2. Detect current conda setup (`conda info`, active environment, disk space, conda version).
- 3. Propose a safe, best-practice plan:
- - Prefer `--name` over `--prefix` for readability
- - Always suggest creating a new environment instead of modifying base or existing ones
- - Recommend `environment.yml` for reproducibility and sharing
- - Use `--yes` only after explicit user confirmation
- - Warn about large downloads (CUDA stacks, large models)
- - Suggest channel priority: conda-forge > pytorch/nvidia > defaults
- 4. Show numbered plan + exact commands + estimated time/size + risks.
- 5. Wait for explicit user confirmation (“YES”, “execute”, “proceed”).
- 6. On approval: execute safely (with logging), capture output, report success/failure, and suggest next steps.
-
- **Core safety & best-practice rules**
- - Never modify the base environment unless explicitly requested (and double-warned)
- - Prefer `conda env export --from-history > environment.yml` for clean, reproducible specs
- - Use `--dry-run` / plan preview by default
- - Integrate with `dependency-planner` for post-creation package installation
- - Log all actions to `./logs/conda_YYYYMMDD_HHMMSS.log`
-
- ## Quick Reference (Common NeuroClaw Tasks)
-
- | Task | Recommended Approach (after user confirmation) |
- |-------------------------------------------|-------------------------------------------------------------------------|
- | Create ML env with specific Python + CUDA | `conda create -n neuroclaw-dl python=3.11` then install via dependency-planner |
- | Export current env for reproducibility | `conda env export --from-history > env-neuroclaw.yml` |
- | Create env from yml file | `conda env create -f environment.yml` |
- | List all environments | `conda env list` or `conda info --envs` |
- | Clone env for testing / branching | `conda create --name neuroclaw-test --clone neuroclaw-dl` |
- | Update packages safely | `conda update --all --dry-run` → confirm → execute |
- | Remove unused env | `conda env remove -n old-env` |
- | Activate / switch env (guidance only) | Print instructions: `conda activate neuroclaw-dl` |
-
- ## Installation
-
- This skill is pure Python orchestration — no external binaries needed beyond a working conda installation.
-
- **Required prerequisites (must exist before activation):**
- - Working conda / mamba / micromamba installation
- - `dependency-planner` (recommended companion for package installation after env creation)
- - Basic subprocess / shell access
-
- To register in NeuroClaw:
- ```bash
- # Place files in: skills/conda-env-manager/
- # Update SOUL.md and/or USER.md with trigger phrases
- ```
-
- ## NeuroClaw recommended wrapper script
-
- ```python
- # conda_env_manager.py
- import subprocess
- import argparse
- import sys
- from pathlib import Path
- from datetime import datetime
-
- def run_conda_cmd(cmd, dry_run=False):
- full_cmd = ["conda"] + cmd
- if dry_run:
- full_cmd.insert(1, "--dry-run")
- print("Would run:", " ".join(full_cmd))
- # In real implementation: subprocess.run(full_cmd, check=True) after confirmation
-
- def get_conda_info():
- try:
- out = subprocess.check_output(["conda", "info", "--json"]).decode()
- return out
- except:
- return "Conda not found or error."
-
- if __name__ == "__main__":
- parser = argparse.ArgumentParser(description="NeuroClaw Conda Environment Manager")
- parser.add_argument("--request", required=True, help="User request (create/export/update/remove...)")
- parser.add_argument("--dry-run", action="store_true", help="Only show plan")
- args = parser.parse_args()
-
- print("Conda snapshot:")
- print(get_conda_info()[:500], "...") # truncated
-
- print("\nRequest:", args.request)
- print("Generating safe conda plan following NeuroClaw best practices...")
- print("Plan preview would appear here.")
- print("Waiting for explicit user confirmation before any real execution.")
- ```
-
- ## Reproducible Environment Specification Standard
-
- All conda environments created/managed by this skill **must** include comprehensive reproducibility metadata following the NeuroClaw standard.
-
- ### Environment Archival Format
-
- After each environment creation or significant update, **conda-env-manager** generates the following audit trail:
-
- **1. Canonical environment file** (`environment-{env_name}-lock.yml`):
- ```yaml
- name: neuroclaw-dl
- channels:
- - pytorch
- - conda-forge
- - defaults
- dependencies:
- - python=3.11.0=h6de4bd8_0_cpython
- - pytorch::pytorch::=2.1.2=py3.11_cuda12.1_cudnn8.9.5_0
- - pytorch::cudatoolkit=12.1=h6de4bd8_0
- - conda-forge::numpy=1.24.3=py311h8315ce3_0
- - conda-forge::scipy=1.11.4=py311hf2f185e_3
- - pip
- - pip::nibabel==5.1.0
- - pip::torch-geometric==2.3.1
- variables:
- CUDA_HOME: /opt/conda/envs/neuroclaw-dl
- platforms:
- - linux-64
- metadata:
- created_at: "2026-04-05T14:22:00Z"
- created_by: "conda-env-manager/NeuroClaw"
- python_version: "3.11.0"
- pytorch_cuda: "12.1"
- system_hash: "sha256:abc123..."
- ```
-
- **2. Machine-portable environment file** (`environment-{env_name}-portable.yml`):
- ```yaml
- name: neuroclaw-dl
- channels:
- - pytorch
- - conda-forge
- - defaults
- dependencies:
- - python=3.11.*
- - pytorch::pytorch=2.1.*
- - pytorch::torchvision
- - conda-forge::numpy>=1.24
- - conda-forge::scipy>=1.11
- - pip
- - pip::nibabel>=5.1.0
- # Use this for cross-platform recreations
- ```
-
- **3. Environment metadata manifest** (`environment-{env_name}-manifest.json`):
- ```json
- {
- "environment_name": "neuroclaw-dl",
- "created_at": "2026-04-05T14:22:00Z",
- "created_by": "conda-env-manager",
- "conda_version": "23.3.1",
- "python_version": "3.11.0",
- "system_info": {
- "os": "Linux",
- "kernel": "5.15.0-106-generic",
- "arch": "x86_64"
- },
- "cuda_config": {
- "cuda_version": "12.1",
- "cudnn_version": "8.9.5",
- "gpu_compute_capability": "8.6"
- },
- "package_count": 42,
- "total_size_mb": 8320,
- "dependencies": {
- "python": {
- "version": "3.11.0",
- "build_string": "h6de4bd8_0_cpython",
- "hash_sha256": "abc123...",
- "channel": "defaults"
- },
- "pytorch": {
- "version": "2.1.2",
- "build_string": "py3.11_cuda12.1_cudnn8.9.5_0",
- "hash_sha256": "def456...",
- "channel": "pytorch"
- }
- },
- "integrity": {
- "manifest_hash": "sha256:xyz789...",
- "lockfile_hash": "sha256:uvw456...",
- "verification_timestamp": "2026-04-05T14:23:00Z"
- },
- "installation_method": "conda_env_create",
- "notes": []
- }
- ```
-
- ### Reproducibility Verification Protocol
-
- When recreating an environment from lock file, **conda-env-manager** automatically:
-
- 1. **Pre-creation validation**:
- - Parse lock file SHA256 hash and verify integrity
- - Check CUDA version compatibility with host system
- - Estimate required disk space and verify availability
-
- 2. **Post-creation verification** (automated after `conda env create`):
- - Run `conda list --json` and compare package versions against lock file
- - Verify all pip packages match with `pip list --format=json`
- - Execute Python import test: `python -c "import torch; print(torch.__version__)"`
- - Compare against stored manifest hash
-
- 3. **Generate verification report** (`environment-{env_name}-verify-report.json`):
- ```json
- {
- "environment_name": "neuroclaw-dl",
- "verified_at": "2026-04-05T14:25:00Z",
- "verification_status": "SUCCESS",
- "package_count": 42,
- "conda_packages_verified": 42,
- "pip_packages_verified": 3,
- "failed_imports": [],
- "warnings": [],
- "reproducibility_score": 1.0,
- "lock_file_match": true
- }
- ```
-
- ### Environment Snapshot at Experiment Checkpoints
-
- Every experiment executed with this conda environment automatically captures:
+ # Conda Environment Manager
- ```
- experiment_20260405_143000_checkpoint/
- ├── environment_locked.yml (exact snapshot at checkpoint time)
- ├── environment_manifest.json
- ├── python_packages_frozenlist.txt
- ├── pip_freeze_output.txt
- ├── cuda_info.json
- │ {
- │ "nvcc_version": "12.1",
- │ "driver_version": "555.42",
- │ "gcc_version": "11.4.0"
- │ }
- └── environment_restoration_guide.md
- # Instructions for reproducing this exact environment on another machine
- ```
+ Honor the requested environment operation and existing authorization. Use the
+ given name/prefix; for a new environment choose an unused name/prefix, and stop
+ on a collision instead of silently reusing it. Keep base unchanged unless the
+ user explicitly selected it. Loading this skill plans methods, not execution.
- ### Environment Branching & Experiment Variants
+ ## Create and run in a known environment
- For ablation studies or variant experiments, **conda-env-manager** supports safe environment cloning:
+ Resolve an actual Conda executable, for example from a valid `CONDA_EXE` or the
+ current PATH, and check `conda info --json`. Capture missing-executable and
+ nonzero-exit errors. For a new isolated prefix:
```bash
- # Clone environment for variant testing
- conda create --name neuroclaw-dl-v2 --clone neuroclaw-dl
-
- # Auto-generates:
- # - environment-neuroclaw-dl-v2-lock.yml (exact clone specification)
- # - environment-neuroclaw-dl-v2-manifest.json
- # - clone-metadata.json (tracks parent environment + clone timestamp)
+ # PREFIX is a new, unused location; PACKAGE is the requested package specification.
+ conda create --prefix "$PREFIX" --channel conda-forge --yes "$PACKAGE"
+ conda run --prefix "$PREFIX" --no-capture-output "$PROGRAM" --version
+ conda list --prefix "$PREFIX" --json
```
- Cloned environments remain **independent** but **traceable** for result comparison and rollback.
-
- ## Important Notes & Limitations
-
- - **User confirmation is mandatory** — no silent destructive actions
- - Prefer `--from-history` exports for minimal, reproducible yml files
- - Large environments / CUDA stacks → warn about disk space and time
- - Windows users are encouraged to use WSL2 for best compatibility
- - If mamba is detected, the skill can suggest the faster `mamba` replacement
- - Rollback support: keep yml backups before major updates
- - Do **not** auto-activate environments — only print instructions (shell session safety)
+ Choose requested channels and versions rather than applying a universal order.
+ Use `--yes` only within the authorized operation; an optional dry-run belongs on
+ the relevant subcommand. Stop if creation or installation fails; do not continue
+ to a system executable and report a successful environment test.
- ## When to Call This Skill
+ An executable name may still resolve outside the selected environment. Record
+ its resolved location inside that environment and confirm it belongs to the
+ prefix, along with package/version metadata. For Python record `sys.executable`
+ and `sys.prefix`; for a program such as htop use the installed prefix's binary
+ and report its version/exit status. Prefer `conda run -p/-n` in scripts to
+ activation in another shell that cannot modify the caller's environment.
+ [Create reference](https://docs.conda.io/projects/conda/en/stable/commands/create.html),
+ [run reference](https://docs.conda.io/projects/conda/en/22.11.x/commands/run.html).
- - Any request containing “conda”, “environment”, “env create”, “yml”, “export env”
- - Before running deep-learning or model skills that require specific package versions
- - When `dependency-planner` detects conflicts best solved by a new environment
- - Reproducibility, sharing, or team collaboration tasks
+ ## Record failures as well as successes
- ## Complementary / Related Skills
+ Initialize the output summary before dispatch. For each actual command retain
+ argv, start/end or elapsed time, return code, stdout and stderr. Catch OS errors
+ such as `FileNotFoundError` in addition to failed commands, serialize the failure
+ summary, and return nonzero. A summary marked successful must follow successful
+ creation/install and the requested tests; printing a command is plan-only.
+ When giving executable code, implement these paths rather than commenting out
+ the execution call or leaving a pseudo-delegate.
- - `dependency-planner` → package installation after environment creation
- - `multi-search-engine` → lookup latest conda channel / solver advice
- - `claw-shell` → execution of conda commands
+ ## Reproducibility matched to the task
- ## Reference
+ Export an existing environment with `conda env export -p "$PREFIX" --from-history`
+ for human-readable intent, or `conda list -p "$PREFIX" --explicit` for a concrete
+ platform-specific package list. Record actual Conda/package/platform versions
+ when available. A history export is not an exact cross-platform lock file.
+ Only report hashes, GPU information, sizes or verification scores actually
+ measured; do not populate plausible demonstration metadata as real observations.
- Custom interface-layer skill for NeuroClaw, addressing environment setup gaps identified in the MedicalClaw / OpenClaw evaluation and aligned with 2025–2026 conda best practices (isolated environments, yml reproducibility, dry-run safety).
+ For clone/update/remove, select the explicit target, preserve useful exports and
+ respect the user's scope. Dependency-planner may help select packages when
+ available, but an unavailable delegate is not required to install an already
+ specified package. No environment archival or checkpoint hook runs merely from
+ reading this document; write it in the actual execution workflow if needed.
- ---
- Created At: 2026-03-19 01:45 HKT
- Last Updated At: 2026-04-05 02:01 HKT
- Author: chengwang96