Token导航 LogoToken导航TokenDH.com
研究检索external-servicegithub未标认证来源可访问许可证需确认审计提醒

ln-654-resource-lifecycle-auditorln 654 资源生命周期审核员

Agent Skill

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。

总安装

3,802

周安装

160

GitHub Stars

441

下载量

1,331
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ln-654-resource-lifecycle-auditor(ln 654 资源生命周期审核员)
来源仓库:https://github.com/levnikolaevich/claude-code-skills
仓库路径:skills/ln-654-resource-lifecycle-auditor
安装命令:
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-654-resource-lifecycle-auditor
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-654-resource-lifecycle-auditor

简介

用于辅助安全审计、权限检查和常见漏洞排查。

  • 适合梳理敏感配置、检查依赖风险或分析鉴权逻辑。
  • 使用时不能直接采信工具输出,需结合最小权限和脱敏要求确认操作边界。
  • 涉及密钥或生产系统时,应先评估权限范围和影响范围。
  • 建议配合人工复核生成安全复核清单。ln-654-resource-lifecycle-auditor 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Paths: File paths (shared/, references/, ../ln-*) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root. If shared/ is missing, fetch files via WebFetch from https://raw.githubusercontent.com/levnikolaevich/claude-code-skills/master/skills/{path}.

Resource Lifecycle Auditor (L3 Worker)

Type: L3 Worker

Specialized worker auditing resource acquisition/release patterns, scope mismatches, and connection pool hygiene.

Purpose & Scope

  • Audit resource lifecycle (Priority: HIGH)
  • Check session/connection scope mismatch, streaming endpoint resource holding, cleanup patterns, pool config
  • Write structured findings to file with severity, location, effort, recommendations
  • Calculate compliance score (X/10) for Resource Lifecycle category

Inputs

MANDATORY READ: Load shared/references/audit_worker_core_contract.md. MANDATORY READ: Load shared/references/mcp_tool_preferences.md and shared/references/mcp_integration_patterns.md

Receives contextStore with: tech_stack, best_practices, db_config (database type, ORM settings, pool config, session factory), codebase_root, output_dir.

Domain-aware: Supports domain_mode + current_domain.

Use hex-graph first when reference chains or call paths materially improve lifecycle findings. Use hex-line first for local code/config reads when available. If MCP is unavailable, unsupported, or not indexed, continue with built-in Read/Grep/Glob/Bash and state the fallback in the report.

Workflow

MANDATORY READ: Load shared/references/two_layer_detection.md for detection methodology.

  1. Parse context from contextStore

- Extract tech_stack, best_practices, db_config, output_dir - Determine scan_path

  1. Detect DI framework

- FastAPI Depends(), Django middleware, Spring @Autowired/@PersistenceContext, Express middleware, Go wire/fx

  1. Discover resource infrastructure

- Find session/connection factory patterns (sessionmaker, create_engine, DataSource, pool creation) - Find DI registration (Depends(), @Inject, providers, middleware mounting) - Find streaming endpoints (SSE, WebSocket, long-poll, streaming response) - Map: which endpoints receive which resources via DI

  1. Scan codebase for violations (6 checks)

- Trace resource injection -> usage -> release across endpoint lifetime - Analyze streaming endpoints for held resources - Check error paths for cleanup

  1. Collect findings with severity, location, effort, recommendation
  2. Calculate score using penalty algorithm
  3. Write Report: Build full markdown report in memory per shared/templates/audit_worker_report_template.md, write to {output_dir}/ln-654--global.md in single Write call
  4. Return Summary: Return minimal summary to coordinator (see Output Format)

Audit Rules (Priority: HIGH)

1. Resource Scope Mismatch

What: Resource injected via DI lives for entire request/connection scope but is used for only a fraction of it.

Detection (Python/FastAPI):

  • Step 1 - Find endpoints with DB session dependency:

- Grep: async def\s+\w+\(.*Depends\(get_db\)|Depends\(get_session\)|db:\s*AsyncSession|session:\s*AsyncSession

  • Step 2 - Measure session usage span within endpoint body:

- Count lines between first and last session\.|db\.|await.*repo usage - Count total lines in endpoint function body

  • Step 3 - Flag if usage_lines / total_lines < 0.2 (session used in <20% of function body)

- Especially: session used only at function start (auth check, initial load) but function continues with non-DB work

Detection (Node.js/Express):

  • Middleware injects req.db or req.knex at request start
  • Grep: app\.use.*pool|app\.use.*knex|app\.use.*prisma (middleware injection)
  • Route handler uses req.db only in first 20% of function body

Detection (Java/Spring):

  • @Transactional on method with long non-DB processing
  • EntityManager injected but used only briefly
  • Grep: @Autowired.*EntityManager|@PersistenceContext + method body analysis

Detection (Go):

  • sql.DB or *gorm.DB passed to handler, used once, then long processing
  • Grep: func.*Handler.*\*sql\.DB|func.*Handler.*\*gorm\.DB

Severity:

  • CRITICAL: Session scope mismatch in streaming endpoint (SSE, WebSocket) - session held for minutes/hours
  • HIGH: Session scope mismatch in endpoint with external API calls (session held during network latency)
  • MEDIUM: Session scope mismatch in endpoint with >50 lines of non-DB processing

Recommendation: Extract DB operations into scoped function; acquire session only for the duration needed; use async with get_session() as session: block instead of endpoint-level DI injection.

Effort: M (refactor DI to scoped acquisition)

2. Streaming Endpoint Resource Holding

What: SSE, WebSocket, or long-poll endpoint holds DB session/connection for stream duration.

Detection (Python/FastAPI):

  • Step 1 - Find streaming endpoints:

- Grep: StreamingResponse|EventSourceResponse|SSE|async def.*websocket|@app\.websocket - Grep: yield\s+.*event|yield\s+.*data:|async for.*yield (SSE generator pattern)

  • Step 2 - Check if streaming function/generator has DB session in scope:

- Session from Depends() in endpoint signature -> held for entire stream - Session from context manager inside generator -> scoped (OK)

  • Step 3 - Analyze session usage inside generator:

- If session used once at start (auth/permission check) then stream loops without DB -> scope mismatch

Detection (Node.js):

  • Grep: res\.write\(|res\.flush\(|Server-Sent Events|new WebSocket|ws\.on\(
  • Check if connection/pool client acquired before stream loop and not released

Detection (Java/Spring):

  • Grep: SseEmitter|WebSocketHandler|StreamingResponseBody
  • Check if @Transactional wraps streaming method

Detection (Go):

  • Grep: Flusher|http\.Flusher|websocket\.Conn
  • Check if *sql.DB or transaction held during flush loop

Severity:

  • CRITICAL: DB session/connection held for entire SSE/WebSocket stream duration (pool exhaustion under load)
  • HIGH: DB connection held during long-poll (>30s timeout)

Recommendation: Move auth/permission check BEFORE stream: acquire session, check auth, release session, THEN start streaming. Use separate scoped session for any mid-stream DB access.

Effort: M (restructure endpoint to release session before streaming)

3. Missing Resource Cleanup Patterns

What: Resource acquired without guaranteed cleanup (no try/finally, no context manager, no close()).

Detection (Python):

  • Grep: session\s*=\s*Session\(\)|session\s*=\s*sessionmaker|engine\.connect\(\) NOT inside with or async with
  • Grep: connection\s*=\s*pool\.acquire\(\)|conn\s*=\s*await.*connect\(\) NOT followed by try:.*finally:.*close\(\)
  • Pattern: bare session = get_session() without context manager
  • Safe patterns to exclude: async with session_factory() as session:, with engine.connect() as conn:

Detection (Node.js):

  • Grep: pool\.connect\(\)|knex\.client\.acquireConnection|\.getConnection\(\) without corresponding .release() or .end() in same function
  • Grep: createConnection\(\) without .destroy() in try/finally

Detection (Java):

  • Grep: getConnection\(\)|dataSource\.getConnection\(\) without try-with-resources
  • Pattern: Connection conn = ds.getConnection() without try (Connection conn =...) syntax

Detection (Go):

  • Grep: sql\.Open\(|db\.Begin\(\) without defer.*Close\(\)|defer.*Rollback\(\)
  • Pattern: tx, err:= db.Begin() without defer tx.Rollback()

Severity:

  • HIGH: Session/connection acquired without cleanup guarantee (leak on exception)
  • MEDIUM: File handle or cursor without cleanup in non-critical path

Exception: Session acquired and released before streaming/long-poll begins -> skip. NullPool / pool_size config documented as serverless design -> skip.

Recommendation: Ensure resources are cleaned up on all exit paths (context managers, try-finally, or framework-managed lifecycle).

Effort: S (wrap in context manager or add defer)

4. Connection Pool Configuration Gaps

What: Missing pool health monitoring, no pre-ping, no recycle, no overflow limits.

Detection (Python/SQLAlchemy):

  • Grep for create_engine\(|create_async_engine\(:

- Missing pool_pre_ping=True -> stale connections not detected - Missing pool_recycle -> connections kept beyond DB server timeout (default: MySQL 8h, PG unlimited) - Missing pool_size -> uses default 5 (may be too small for production) - Missing max_overflow -> unbounded overflow under load - pool_size=0 or NullPool in web service -> no pooling (anti-pattern)

  • Grep for pool event listeners:

- Missing @event.listens_for(engine, "invalidate") -> no visibility into connection invalidation - Missing @event.listens_for(engine, "checkout") -> no connection checkout monitoring - Missing @event.listens_for(engine, "checkin") -> no connection return monitoring

Detection (Node.js):

  • Grep for createPool\(|new Pool\(:

- Missing min/max configuration - Missing idleTimeoutMillis or reapIntervalMillis - Missing connection validation (validateConnection, testOnBorrow)

Detection (Java/Spring):

  • Grep: DataSource|HikariConfig|HikariDataSource:

- Missing leakDetectionThreshold - Missing maximumPoolSize (defaults to 10) - Missing connectionTestQuery or connectionInitSql

Detection (Go):

  • Grep: sql\.Open\(:

- Missing db.SetMaxOpenConns() - Missing db.SetMaxIdleConns() - Missing db.SetConnMaxLifetime()

Severity:

  • HIGH: No pool_pre_ping AND no pool_recycle (stale connections served silently)
  • HIGH: No max_overflow limit in web service (unbounded connection creation under load)
  • MEDIUM: Missing pool event listeners (no visibility into pool health)
  • MEDIUM: Missing leak detection threshold (Java/HikariCP)
  • LOW: Pool size at default value (may be adequate for small services)

Context-dependent exceptions:

  • NullPool is valid for serverless/Lambda
  • pool_size=5 may be fine for low-traffic services

Recommendation: Configure pool_pre_ping=True, pool_recycle < DB server timeout, appropriate pool_size for expected concurrency, add pool event listeners for monitoring.

Effort: S (add config parameters), M (add event listeners/monitoring)

5. Unclosed Resources in Error Paths

What: Exception/error handling paths that skip resource cleanup.

Detection (Python):

  • Find except blocks containing raise or return without prior session.close(), conn.close(), or cursor.close()
  • Pattern: except Exception: logger.error(...); raise (re-raise without cleanup)
  • Find generator functions with DB session where GeneratorExit is not handled:

- Grep: async def.*yield.*session|def.*yield.*session without try:.*finally:.*close\(\)

Detection (Node.js):

  • Grep: catch\s*\( blocks that throw or return without releasing connection
  • Pattern: pool.connect().then(client => {...}) without .finally(() => client.release())
  • Promise chains without .finally() for cleanup

Detection (Java):

  • Grep: catch\s*\( blocks without finally {conn.close()} when connection opened in try
  • Not using try-with-resources for AutoCloseable resources

Detection (Go):

  • Grep: if err!= nil \{.*return before defer statement for resource cleanup
  • Pattern: error check between Open() and defer Close() that returns without closing

Severity:

  • CRITICAL: Session/connection leak in high-frequency endpoint error path (pool exhaustion)
  • HIGH: Resource leak in error path of API handler
  • MEDIUM: Resource leak in error path of background task

Recommendation: Use context managers/try-with-resources/defer BEFORE any code that can fail; for generators, add try/finally around yield.

Effort: S (restructure acquisition to before-error-path)

6. Resource Factory vs Injection Anti-pattern

What: Using framework DI to inject short-lived resources into long-lived contexts instead of using factory pattern.

Detection (Python/FastAPI):

  • Step 1 - Find DI-injected sessions in endpoint signatures:

- Grep: Depends\(get_db\)|Depends\(get_session\)|Depends\(get_async_session\)

  • Step 2 - Classify endpoint lifetime:

- Short-lived: regular REST endpoint (request/response) -> DI injection OK - Long-lived: SSE (StreamingResponse, EventSourceResponse), WebSocket (@app.websocket), background task (BackgroundTasks.add_task)

  • Step 3 - Flag DI injection in long-lived endpoints:

- Long-lived endpoint should use factory pattern: async with session_factory() as session: at point of need - NOT session: AsyncSession = Depends(get_session) at endpoint level

Detection (Node.js/Express):

  • Middleware-injected pool connection (req.db) used in WebSocket handler or SSE route
  • Should use: const conn = await pool.connect(); try {...} finally {conn.release()} at point of need

Detection (Java/Spring):

  • @Autowired EntityManager in @Controller with SSE endpoint (SseEmitter)
  • Should use: programmatic EntityManager creation from EntityManagerFactory

Detection (Go):

  • *sql.DB injected at handler construction time but *sql.Conn should be acquired per-operation

Severity:

  • CRITICAL: DI-injected session in SSE/WebSocket endpoint (session outlives intended scope by orders of magnitude)
  • HIGH: DI-injected session passed to background task (task outlives request)

Recommendation: Use factory pattern for long-lived contexts; inject the factory (sessionmaker, pool), not the session/connection itself.

Effort: M (change DI from session to session factory, add scoped acquisition)

Scoring Algorithm

MANDATORY READ: Load shared/references/audit_worker_core_contract.md and shared/references/audit_scoring.md.

Output Format

MANDATORY READ: Load shared/references/audit_worker_core_contract.md and shared/templates/audit_worker_report_template.md.

Write JSON summary per shared/references/audit_summary_contract.md. In managed mode the caller passes both runId and summaryArtifactPath; in standalone mode the worker generates its own run-scoped artifact path per shared contract.

Write report to {output_dir}/ln-654--global.md with category: "Resource Lifecycle" and checks: resource_scope_mismatch, streaming_resource_holding, missing_cleanup, pool_configuration, error_path_leak, factory_vs_injection.

Return summary per shared/references/audit_summary_contract.md.

When summaryArtifactPath is absent, write the standalone runtime summary under .hex-skills/runtime-artifacts/runs/{run_id}/evaluation-worker/{worker}--{identifier}.json and optionally echo the same summary in structured output.

Report written: .hex-skills/runtime-artifacts/runs/{run_id}/audit-report/ln-654--global.md
Score: X.X/10 | Issues: N (C:N H:N M:N L:N)

Critical Rules

MANDATORY READ: Load shared/references/audit_worker_core_contract.md.

  • Do not auto-fix: Report only
  • DI-aware: Understand framework dependency injection lifetime scopes (request, singleton, transient)
  • Framework detection first: Identify DI framework before checking injection patterns
  • Streaming detection first: Find all streaming/long-lived endpoints before scope analysis
  • Exclude tests: Do not flag test fixtures, test session setup, mock sessions
  • Exclude CLI/scripts: DI scope mismatch is not relevant for single-run scripts
  • Effort realism: S = <1h, M = 1-4h, L = >4h
  • Pool config is context-dependent: NullPool is valid for serverless/Lambda; pool_size=5 may be fine for low-traffic services
  • Safe pattern awareness: Do not flag resources inside async with, with, try-with-resources, defer (already managed)

Definition of Done

MANDATORY READ: Load shared/references/audit_worker_core_contract.md.

  • contextStore parsed successfully (including output_dir, db_config)
  • scan_path determined
  • DI framework detected (FastAPI Depends, Django middleware, Spring @Autowired, Express middleware, Go wire)
  • Streaming endpoints inventoried
  • All 6 checks completed:

- resource scope mismatch, streaming resource holding, missing cleanup, pool configuration, error path leak, factory vs injection

  • Findings collected with severity, location, effort, recommendation
  • Score calculated using penalty algorithm
  • Report written to {output_dir}/ln-654--global.md (atomic single Write call)
  • Summary written per contract

Reference Files

  • Audit output schema: shared/references/audit_output_schema.md

Version: 1.0.0 Last Updated: 2026-03-03

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.6%
按下载量换算500

Claude

31.23%
按下载量换算416

Cursor

17.74%
按下载量换算236

Gemini CLI

8.85%
按下载量换算118

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills