← 返回 Skills 市场
gchapim

Elixir Dev

作者 gchapim · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
1907
总下载
1
收藏
2
当前安装
1
版本数
在 OpenClaw 中安装
/install elixir-dev
功能描述
Elixir/Phoenix development companion. Run and interpret mix test, mix credo, mix dialyzer, mix format. Generate modules following OTP conventions: contexts, schemas, GenServers, supervisors, tasks. Debug compilation errors and warnings. Help with Ecto migrations, queries, changesets, and associations. Use for any Elixir or Phoenix development task including writing modules, fixing tests, refactoring code, or understanding OTP patterns.
使用说明 (SKILL.md)

Elixir Dev

Running Mix Commands

See references/mix-commands.md for full command reference.

Test

# Run all tests
mix test

# Specific file or line
mix test test/my_app/accounts_test.exs:42

# By tag
mix test --only integration

# Failed only (requires --failed flag from prior run)
mix test --failed

# With coverage
mix test --cover

Interpreting failures:

  • ** (MatchError) — Pattern match failed; check return value shape.
  • ** (Ecto.NoResultsError)Repo.get! with non-existent ID; use Repo.get or seed data.
  • ** (DBConnection.OwnershipError) — Missing async: true or sandbox setup.
  • no function clause matching — Wrong arity or unexpected arg type.

Credo

mix credo --strict
mix credo suggest --format json
mix credo explain MyApp.Module  # Explain issues for specific module

Common Credo fixes:

  • Credo.Check.Readability.ModuleDoc — Add @moduledoc.
  • Credo.Check.Refactor.CyclomaticComplexity — Extract helper functions.
  • Credo.Check.Design.TagTODO — Address or remove TODO comments.

Dialyzer

mix dialyzer
mix dialyzer --format short

Common Dialyzer warnings:

  • The pattern can never match — Dead code or wrong type in pattern.
  • Function has no local return — Crashes on all paths; check internal calls.
  • The call will never return — Calling a function that always raises.
  • Fix: Add @spec annotations; use @dialyzer {:nowarn_function, func: arity} as last resort.

Format

mix format
mix format --check-formatted  # CI mode — exit 1 if unformatted

Module Generation

Always include @moduledoc, @doc, and @spec on public functions.

Context Module

defmodule MyApp.Notifications do
  @moduledoc """
  Manages notification delivery and preferences.
  """
  import Ecto.Query
  alias MyApp.Repo
  alias MyApp.Notifications.Notification

  @doc "List notifications for a user, most recent first."
  @spec list_notifications(String.t(), keyword()) :: [Notification.t()]
  def list_notifications(user_id, opts \\ []) do
    limit = Keyword.get(opts, :limit, 50)

    Notification
    |> where(user_id: ^user_id)
    |> order_by(desc: :inserted_at)
    |> limit(^limit)
    |> Repo.all()
  end
end

Schema Module

defmodule MyApp.Notifications.Notification do
  @moduledoc """
  Schema for push/email/sms notifications.
  """
  use Ecto.Schema
  import Ecto.Changeset

  @type t :: %__MODULE__{}

  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id
  @timestamps_opts [type: :utc_datetime_usec]

  schema "notifications" do
    field :channel, Ecto.Enum, values: [:push, :email, :sms]
    field :title, :string
    field :body, :string
    field :delivered_at, :utc_datetime_usec
    field :user_id, :binary_id

    timestamps()
  end

  @required ~w(channel title body user_id)a

  @doc false
  def changeset(notification, attrs) do
    notification
    |> cast(attrs, @required ++ [:delivered_at])
    |> validate_required(@required)
    |> validate_length(:title, max: 255)
  end
end

OTP Patterns

See references/otp-patterns.md for GenServer, Supervisor, Agent, Task patterns.

When to Use What

Pattern Use When
GenServer Stateful process with sync/async calls (cache, rate limiter, connection pool)
Agent Simple state wrapper with no complex logic
Task One-off async work, fire-and-forget or awaited
Task.Supervisor Supervised fire-and-forget tasks
Supervisor Managing child process lifecycles
Registry Process lookup by name/key
DynamicSupervisor Starting children at runtime

GenServer Template

defmodule MyApp.RateLimiter do
  @moduledoc "Token bucket rate limiter."
  use GenServer

  # Client API
  def start_link(opts) do
    name = Keyword.get(opts, :name, __MODULE__)
    GenServer.start_link(__MODULE__, opts, name: name)
  end

  @spec check_rate(String.t()) :: :ok | {:error, :rate_limited}
  def check_rate(key), do: GenServer.call(__MODULE__, {:check, key})

  # Server callbacks
  @impl true
  def init(opts) do
    {:ok, %{limit: Keyword.get(opts, :limit, 100), window_ms: 60_000, buckets: %{}}}
  end

  @impl true
  def handle_call({:check, key}, _from, state) do
    now = System.monotonic_time(:millisecond)
    {count, state} = increment(state, key, now)
    if count \x3C= state.limit, do: {:reply, :ok, state}, else: {:reply, {:error, :rate_limited}, state}
  end

  defp increment(state, key, now) do
    # Implementation
  end
end

Common Compilation Errors

Error Cause Fix
module X is not available Missing dep or typo Check mix.exs deps, verify module name
undefined function X/N Not imported/aliased Add import, alias, or full module path
(CompileError) redefining module Duplicate module name Rename one of them
protocol not implemented Missing protocol impl Add defimpl for your struct
cannot use ^x outside of match Pin in wrong position Move to pattern match context

Ecto Query Patterns

Dynamic Filters

def list(filters) do
  Enum.reduce(filters, base_query(), fn
    {:status, val}, q -> where(q, [r], r.status == ^val)
    {:since, dt}, q -> where(q, [r], r.inserted_at >= ^dt)
    {:search, term}, q -> where(q, [r], ilike(r.name, ^"%#{term}%"))
    _, q -> q
  end)
  |> Repo.all()
end

Preloading

# Query-time preload (single query with join)
from(p in Post, join: a in assoc(p, :author), preload: [author: a])

# Separate query preload
Post |> Repo.all() |> Repo.preload(:author)

# Nested
Repo.preload(posts, [comments: :author])

Aggregates

from(o in Order,
  where: o.tenant_id == ^tenant_id,
  group_by: o.status,
  select: {o.status, count(o.id), sum(o.amount)}
)
|> Repo.all()

Phoenix LiveView Basics

Mount + Handle Events

defmodule MyAppWeb.DashboardLive do
  use MyAppWeb, :live_view

  @impl true
  def mount(_params, _session, socket) do
    {:ok, assign(socket, items: [], loading: true)}
  end

  @impl true
  def handle_event("delete", %{"id" => id}, socket) do
    MyApp.Items.delete_item!(id)
    {:noreply, assign(socket, items: MyApp.Items.list_items())}
  end

  @impl true
  def render(assigns) do
    ~H"""
    \x3Cdiv :for={item \x3C- @items}>
      \x3Cspan>\x3C%= item.name %>\x3C/span>
      \x3Cbutton phx-click="delete" phx-value-id={item.id}>Delete\x3C/button>
    \x3C/div>
    """
  end
end

PubSub for Real-time

# Subscribe in mount
def mount(_, _, socket) do
  if connected?(socket), do: Phoenix.PubSub.subscribe(MyApp.PubSub, "items")
  {:ok, assign(socket, items: list_items())}
end

# Broadcast from context
def create_item(attrs) do
  with {:ok, item} \x3C- %Item{} |> Item.changeset(attrs) |> Repo.insert() do
    Phoenix.PubSub.broadcast(MyApp.PubSub, "items", {:item_created, item})
    {:ok, item}
  end
end

# Handle in LiveView
def handle_info({:item_created, item}, socket) do
  {:noreply, update(socket, :items, &[item | &1])}
end
安全使用建议
This skill appears coherent and is just documentation and command suggestions for Elixir/Phoenix development. Before using it: (1) review any recommended commands the agent wants to run — some are destructive (mix ecto.drop, mix ecto.reset) or start services; never run them on production data; (2) run commands in a safe environment (MIX_ENV=test, isolated container, or a backup copy of the DB); (3) confirm your project’s DATABASE_URL and credentials are correct and that you intend the side effects (migrations, drops, server start); and (4) note the skill source/homepage is unknown — if you need stronger assurance, prefer skills with a known repository or run the agent in a sandbox before granting it the ability to execute commands.
功能分析
Type: OpenClaw Skill Name: elixir-dev Version: 1.0.0 The skill bundle provides extensive documentation and code examples for Elixir/Phoenix development tasks, including running mix commands, generating modules, understanding OTP patterns, and debugging. All content is aligned with the stated purpose of being an 'Elixir/Phoenix development companion'. There is no evidence of data exfiltration, malicious execution, persistence mechanisms, prompt injection attempts against the agent, or obfuscation. While some documented commands like `mix ecto.drop` can be destructive, they are standard development tools and are presented as part of a normal development workflow, not with malicious intent.
能力评估
Purpose & Capability
Name/description match the provided instructions and reference docs: mix commands, credo/dialyzer/format, OTP templates, Ecto patterns. There are no unexpected environment variables, binaries, or installs required.
Instruction Scope
The SKILL.md contains explicit runtime commands (mix test, mix ecto.migrate/rollback/drop, mix phx.server, etc.) and many code templates. This is appropriate for a dev companion, but some commands are destructive (e.g., mix ecto.drop, mix ecto.reset) or start servers; the agent may suggest running them — review and run in a safe environment (MIX_ENV=test or a container) before executing.
Install Mechanism
No install spec and no code files to write to disk; instruction-only skills are lowest-risk for installation. The regex scanner had no code to analyze.
Credentials
The skill declares no required environment variables or credentials. The docs include examples referencing common env vars (MIX_ENV, DATABASE_URL) which are normal examples for Elixir projects but are not requested by the skill itself.
Persistence & Privilege
always:false and no special privileges requested. The skill does not modify other skills or system-wide configs and does not request permanent presence.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install elixir-dev
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /elixir-dev 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of elixir-dev: a comprehensive Elixir/Phoenix development companion. - Run and interpret `mix` commands: test, credo, dialyzer, format. - Generate modules with OTP conventions—contexts, schemas, GenServers, supervisors, and tasks. - Debug compilation errors and warnings; get quick explanations and fixes. - Get help with Ecto migrations, queries, changesets, and associations. - Reference practical templates and patterns for OTP, Ecto, and Phoenix LiveView tasks.
元数据
Slug elixir-dev
版本 1.0.0
许可证
累计安装 2
当前安装数 2
历史版本数 1
常见问题

Elixir Dev 是什么?

Elixir/Phoenix development companion. Run and interpret mix test, mix credo, mix dialyzer, mix format. Generate modules following OTP conventions: contexts, schemas, GenServers, supervisors, tasks. Debug compilation errors and warnings. Help with Ecto migrations, queries, changesets, and associations. Use for any Elixir or Phoenix development task including writing modules, fixing tests, refactoring code, or understanding OTP patterns. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1907 次。

如何安装 Elixir Dev?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install elixir-dev」即可一键安装,无需额外配置。

Elixir Dev 是免费的吗?

是的,Elixir Dev 完全免费(开源免费),可自由下载、安装和使用。

Elixir Dev 支持哪些平台?

Elixir Dev 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Elixir Dev?

由 gchapim(@gchapim)开发并维护,当前版本 v1.0.0。

💬 留言讨论