get-available-resources
它能做什么
这个工具可以检查你的电脑中某个特定程序可以使用的资源(比如 CPU、内存和磁盘)。它会生成一份安全、简洁的资源摘要,帮助你做规划。
适用场景
- ✓当你需要规划一个会占用大量资源的程序时。
- ✓在运行一个可能消耗大量内存或算力的任务之前。
- ✓当你想了解某个计算环境的资源上限时。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/get-available-resources/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“帮我检查可用资源,以便规划我的任务。”
每周 5 个新技能,1 分钟读完。
工作原理
该工具会分析程序当前的运行环境,检查 CPU、内存、磁盘以及其他资源的上限。它会生成一份 JSON 格式的数据报告,展示可用的资源,但不会实际测试这些上限。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Get Available Resources
Build a conservative picture of resources available to the current process. Keep host inventory, process affinity, cgroup/container limits, scheduler allocation, and accelerator runtime usability separate.
Safety contract
Follow these rules:
- Run detection when the user requests it or a specific workload needs resource planning. Do not persist a fingerprint for every scientific task.
- Use stdout by default. Persist only when the user chooses an explicit generic local filename.
- Do not run stress tests, benchmarks, large allocations, write probes, device resets, driver installation, or clock/power changes.
- Do not dump the environment. Read only the named Slurm and accelerator variables implemented by the detector.
- Do not report hostnames, absolute paths, cgroup paths, job IDs, device UUIDs, PCI addresses, or raw visibility-variable values.
- Treat a missing observation as unknown. Never convert unknown to unlimited.
- Never infer that a visible host CPU, memory pool, or GPU is usable inside a scheduler allocation or container.
The bundled detector uses only fixed executable/argument tuples, no shell, short timeouts, bounded stdout/stderr, and partial-failure warnings.
Quick start
Run from this skill directory.
Ephemeral stdout snapshot
python scripts/detect_resources.py
The command emits only JSON to stdout. Redirect it only when ordinary shell permissions are acceptable.
Explicit private file
python scripts/detect_resources.py --output resource-snapshot.json
Explicit output is restricted to one .json filename in the current
directory, uses mode 0600 on POSIX, rejects symlinks and path traversal, and
refuses overwrite unless --force is supplied. Forced output also rejects
hard links and non-regular files. Windows privacy additionally depends on the
directory ACL.
Optional psutil enhancement
The standard-library detector works without installation. For broader cross-platform physical-core, affinity, available-memory, swap, and disk coverage:
uv run --no-project --with "psutil==7.2.2" python scripts/detect_resources.py
The import is lazy. Failure to import psutil becomes a warning, not a fatal error.
Skip management-tool probes
python scripts/detect_resources.py --skip-accelerators
Use this when accelerator discovery latency is undesirable. The detector still summarizes the presence and state of allowlisted visibility variables without returning their values.
Required interpretation
CPU
Read these as different facts:
cpu.host.logical: system-visible scheduling units.cpu.host.physical: physical topology, or null; never inferred from logical count.cpu.process.affinity_logical: current affinity-set size when supported.cpu.cgroup_v2.cpuset_logical: effective cgroup cpuset size.cpu.cgroup_v2.quota_cores: finitecpu.maxcapacity, possibly fractional.scheduler.allocation.cpu_per_process: bounded Slurm per-task interpretation when scope is clear.cpu.effective.capacity_cores: minimum positive observed constraint.cpu.effective.worker_ceiling: conservative floor for CPU process workers.
A quota of 1.5 is CPU-time capacity, not 1.5 physical cores. Affinity and cpusets constrain placement; quota constrains bandwidth.
Memory
Keep these separate:
- host total/available memory;
- current cgroup usage, hard
memory.max, and remaining hierarchical capacity; memory.high, which is a pressure/throttle boundary rather than a hard cap;- scheduler memory allocation and its scope; and
- conservative effective hard limit and available estimate.
On Apple silicon, memory.model is unified_cpu_gpu. Do not add integrated GPU
memory to RAM or describe it as separate VRAM.
Accelerators
Each device is a backend candidate:
- NVIDIA GPU → CUDA candidate;
- AMD GPU → ROCm candidate;
- Apple integrated GPU → Metal candidate.
Management-query visibility does not establish:
- scheduler/container permission;
- device-node access;
- driver/runtime compatibility;
- framework package compatibility; or
- operator/data-type support.
Therefore runtime_usable_devices remains null and each device says
runtime_compatibility: not_tested. Visibility/allocation counts constrain
the observed management records, not the number of framework devices. MIG and AMD partition enumeration can differ.
…
常见问题
这里的“资源”是什么意思?
指程序运行时所用的计算机组件,比如处理能力(CPU)、内存(RAM)和磁盘空间。
为什么说这份报告“安全”且“简洁”?
它不会收集敏感或过于详细的信息(比如具体文件名或系统 ID),只关注资源上限,避免系统过载或信息泄露。
资源“规划”是什么意思?
就是根据可用资源的信息,决定如何高效运行任务,确保任务不会因为容量不足而失败,也不会干扰其他程序。
详情
作者的原始描述
Detects host inventory and effective CPU, memory, disk, scheduler, container, and accelerator limits when a user asks for resource-aware planning or before a clearly resource-sensitive local workload. Produces a redacted JSON snapshot and conservative planning helpers without stress tests or assuming visible host hardware is usable.
热度
- GitHub 星标
- 51k
- 排名
- #3471
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …