find-infinite-loops
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "find-infinite-loops":https://skillpi.com/zh/skills/deepskill-e07b535f50b78c3ff5900730db40712700d4571b7e7e6bfae488d216a99ea0cd。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
检测 PHP 代码中的无限循环风险。查找缺失的跳出条件、错误的循环变量、无界递归和循环引用等问题。
介绍来源: third_party · dykyi-roman · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 输入和输出
- 减记
- 实测状态
- 未测试
文件浏览
Frontmatter
name: find-infinite-loops
description: Detects infinite loop risks in PHP code. Finds missing break conditions, incorrect loop variables, unbounded recursion, circular references.Infinite Loop Detection
Analyze PHP code for potential infinite loops and unbounded execution.
Detection Patterns
1. Missing Break Conditions
// BUG: No exit condition
while (true) {
$item = $queue->pop();
process($item);
// No break when queue is empty
}
// BUG: Condition never changes
$running = true;
while ($running) {
doWork();
// $running never set to false
}
// BUG: Break inside nested condition
while ($items) {
foreach ($items as $item) {
if ($item->isDone()) {
break; // Only breaks inner loop
}
}
}
2. Incorrect Loop Variable Modification
// BUG: Wrong variable incremented
for ($i = 0; $i < count($items); $j++) { // Should be $i++
process($items[$i]);
}
// BUG: Variable modified in wrong direction
for ($i = 10; $i > 0; $i++) { // Should be $i--
process($i);
}
// BUG: Loop variable reset
$i = 0;
while ($i < 10) {
if ($condition) {
$i = 0; // Resets counter
}
$i++;
}
3. Unbounded Recursion
// BUG: No base case
function factorial(int $n): int
{
return $n * factorial($n - 1); // Never stops
}
// BUG: Base case unreachable
function traverse(Node $node): void
{
$this->traverse($node->getNext()); // What if getNext returns self?
// Missing: if ($node === null) return;
}
// BUG: Mutual recursion
function a($n) { return b($n); }
function b($n) { return a($n); } // Infinite cycle
4. Circular References
// BUG: Circular linked list traversal
while ($node !== null) {
$node = $node->next; // What if list is circular?
}
// BUG: Object graph cycle
function serialize($obj, $visited = []): string
{
foreach ($obj->getRelations() as $rel) {
$result .= serialize($rel); // May revisit objects
}
}
// FIXED:
function serialize($obj, array &$visited = []): string
{
if (in_array($obj, $visited, true)) {
return '[circular]';
}
$visited[] = $obj;
// ...
}
5. Event/Listener Loops
// BUG: Event triggers itself
class UserUpdatedListener
{
public function handle(UserUpdated $event): void
{
$user = $event->getUser();
$user->touch(); // Triggers another UserUpdated event
}
}
// BUG: Message queue requeue loop
public function handle(Message $message): void
{
try {
$this->process($message);
} catch (Exception $e) {
$this->queue->publish($message); // Requeues failed message infinitely
}
}
6. Retry Without Limit
// BUG: Infinite retry
function fetch(string $url): string
{
while (true) {
try {
return $this->httpClient->get($url);
} catch (Exception $e) {
sleep(1);
// No max retries, infinite loop on persistent failure
}
}
}
// FIXED:
function fetch(string $url, int $maxRetries = 3): string
{
$attempts = 0;
while ($attempts < $maxRetries) {
try {
return $this->httpClient->get($url);
} catch (Exception $e) {
$attempts++;
if ($attempts >= $maxRetries) {
throw $e;
}
sleep(1);
}
}
}
7. Generator Infinite Yield
// BUG: Generator never ends
function allNumbers(): Generator
{
$i = 0;
while (true) {
yield $i++;
// Fine for generators, but consuming code may not limit
}
}
// Usage BUG:
foreach (allNumbers() as $n) {
echo $n; // Infinite loop
}
8. Database Pagination Without Limit
// BUG: Potentially infinite
$offset = 0;
while (true) {
$batch = $repository->findBy([], null, 100, $offset);
if (empty($batch)) {
break;
}
process($batch);
// Missing: $offset += 100;
}
Grep Patterns
# while(true) without break
Grep: "while\s*\(\s*true\s*\)" --glob "**/*.php"
# Recursion
Grep: "function\s+(\w+)\([^)]*\)[^{]*\{[^}]*\1\s*\(" --glob "**/*.php"
# for loop with wrong increment
Grep: "for\s*\([^;]+;\s*\$\w+\s*[<>]\s*[^;]+;\s*\$(?!\1)" --glob "**/*.php"
# while without modification
Grep: "while\s*\(\s*\$\w+\s*\)" --glob "**/*.php"
Severity Classification
| Pattern | Severity |
|---|---|
| Infinite retry without limit | 🔴 Critical |
| Missing recursion base case | 🔴 Critical |
| Wrong loop variable | 🔴 Critical |
| Circular reference traversal | 🟠 Major |
| Event self-triggering | 🟠 Major |
| while(true) without clear exit | 🟠 Major |
Prevention Patterns
Always Use Limits
const MAX_ITERATIONS = 1000;
$iterations = 0;
while ($condition && $iterations < self::MAX_ITERATIONS) {
// ...
$iterations++;
}
if ($iterations >= self::MAX_ITERATIONS) {
throw new RuntimeException('Max iterations exceeded');
}
Track Visited Nodes
function traverse($node, array &$visited = []): void
{
$id = spl_object_id($node);
if (isset($visited[$id])) {
return;
}
$visited[$id] = true;
// ...
}
Recursion Depth Limit
function process($data, int $depth = 0): mixed
{
if ($depth > 100) {
throw new RuntimeException('Max recursion depth');
}
return process($child, $depth + 1);
}
Output Format
### Infinite Loop Risk: [Description]
**Severity:** 🔴/🟠/🟡
**Location:** `file.php:line`
**Type:** [Missing Break|Wrong Variable|Unbounded Recursion|...]
**Issue:**
[Description of how infinite loop can occur]
**Code:**
```php
// Problematic code
Fix:
// With proper termination
Trigger Condition: [When this infinite loop would occur]
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供了 PHP 代码中无限循环风险的全面检测能力,涵盖多种常见场景。
- 提供了具体的检测模式、grep 模式、严重性分类和预防模式,实用性强。
亮点
- description 字段提供了清晰的触发描述,涵盖了核心功能。
- 触发词精准完整,边界清晰。
亮点
- Skill 结构清晰,分为多个部分,每个部分都有详细的说明和代码示例。
- frontmatter 完整,单文件未超过 500 行。
亮点
- 提供了具体的检测模式和 grep 模式,逻辑清晰,覆盖了主要的异常情况。
- Skill 提供的指导具有高度的可靠性。
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。