AgentSkillsCN

core-pattern-finder

当需要 Drupal 核心实现示例时使用——在核心模块中搜索特定模式,并返回文件路径引用。

SKILL.md
--- frontmatter
name: core-pattern-finder
description: Use when needing Drupal core implementation examples - searches core modules for specific patterns and returns file path references
version: 1.1.0
model: haiku
user-invocable: false

Core Pattern Finder

Search Drupal core for implementation patterns and return file references.

Activation

Activate when you detect:

  • "How does core do X?"
  • "Find core example of X"
  • "Show me core's implementation of X"
  • Need a reference implementation for a Drupal pattern

Quick Reference

Check these common patterns first before searching:

Forms

PatternPath
ConfigFormBasecore/modules/system/src/Form/SiteInformationForm.php
FormBasecore/modules/node/src/Form/NodeForm.php
ConfirmFormBasecore/modules/node/src/Form/NodeDeleteForm.php
EntityFormcore/modules/user/src/ProfileForm.php

Entities

PatternPath
Content Entitycore/modules/node/src/Entity/Node.php
Config Entitycore/modules/field/src/Entity/FieldConfig.php
Entity List Buildercore/modules/node/src/NodeListBuilder.php

Services

PatternPath
Entity Type Managercore/lib/Drupal/Core/Entity/EntityTypeManager.php
Plugin Managercore/lib/Drupal/Core/Block/BlockManager.php
Event Subscribercore/modules/system/src/EventSubscriber/ConfigCacheTag.php

Plugins

PatternPath
Block Plugincore/modules/system/src/Plugin/Block/SystemBrandingBlock.php
Field Formattercore/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php
Field Widgetcore/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php
Condition Plugincore/modules/system/src/Plugin/Condition/RequestPath.php

Controllers

PatternPath
ControllerBasecore/modules/system/src/Controller/SystemController.php
Entity Controllercore/modules/node/src/Controller/NodeController.php

Workflow

1. Check Quick Reference

If pattern matches table above, return that path immediately.

2. Search Core

If not in quick reference, search using these strategies:

For class/interface patterns:

code
Use Grep with pattern: "class {PatternName}" or "interface {PatternName}"
Path: core/

For specific implementations:

code
Use Grep with pattern: "extends {BaseClass}" or "implements {Interface}"
Path: core/modules/

For service patterns:

code
Use Glob with pattern: core/modules/*/src/*Manager.php
or: core/lib/Drupal/Core/*/*.php

3. Read and Extract Key Sections

Once file found, use Read tool and identify:

  • Key methods to study
  • Relevant line numbers
  • Dependencies injected

4. Return Structured Response

Format your response as:

code
## Core Pattern: {Pattern Name}

### Primary Example
`{file_path}`

**Key methods:**
- `{method1}()` (line {X}): {what it does}
- `{method2}()` (line {Y}): {what it does}

**Dependencies:**
- {service_name}: {purpose}

### Additional Examples
- `{path2}` - {variation description}
- `{path3}` - {variation description}

### Usage Notes
{Any gotchas or important considerations}

Stop Points

STOP and ask user:

  • If pattern is ambiguous (multiple interpretations)
  • If no matching pattern found in core
  • Before reading more than 3 files (ask which to prioritize)