lemmaly – skill Viết lách & Nội dung cho agent AI
Kỷ luật ưu tiên thuật toán: nêu Big-O, cấu trúc dữ liệu và họ thuật toán TRƯỚC khi viết vòng lặp, truy vấn hoặc đệ quy. Phát hiện các mặc định O(n^2), N+1 và brute-force.
Cài skill lemmaly bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/lemmaly-960c0.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /lemmaly – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/lemmaly-960c0.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $lemmaly – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/lemmaly-960c0.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /lemmaly – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/lemmaly-960c0.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /lemmaly – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
lemmaly — Algorithm-First Proof
The model already knows Big-O, hash tables, divide-and-conquer, dynamic programming, sorting, graph algorithms, and amortized analysis. It just does not apply them spontaneously. lemmaly fixes the behavior, not the knowledge.
This skill is the gateway for an algorithm-discipline suite of four skills (lemmaly, mathguard, invariant-guard, complexity-cuts). It enforces the hard rules that every other guard in the suite assumes.
Violating the letter of these rules is violating the spirit of the skill. "Just this once" is how O(n²) ships to production.
When to Use This Skill
Use lemmaly when:
- Writing, editing, or reviewing code that involves loops, collections, lookups, searches, joins, recursion, graphs, queries, or any computation over more than a handful of items.
- About to write a
forinside afor,.find/.includes/.indexOfinside a loop,awaitinsidefor/map/forEachover independent items, or one query per item in a collection. - Auditing a codebase / PR for known anti-patterns (await-in-loop,
.includesinside.filter, string-concat in loop,SELECT *, N+1, etc.). - Reviewing AI-generated code that "looks idiomatic" but might hide O(n²) or N+1.
When in doubt, start at lemmaly — it is the gateway and will tell you when to escalate to its three sibling skills.
| If you are about to… | Use | Why |
| --- | --- | --- |
| Write *new* code that loops, queries, joins, recurses, or processes a collection | lemmaly | Forces complexity + data structure + algorithm family before code is written. |
| Refactor *existing* code that is already slow, OOMs, times out, or has nested loops / N+1 / repeated work | complexity-cuts | Corrective playbook for code that already shipped with bad Big-O. |
| Implement an algorithm where the obvious version is subtly wrong (binary search variants, in-place dedup, Boyer–Moore, QuickSelect partition, recursion with accumulators, fixed-point / termination concerns) | invariant-guard | Forces writing the function contract + loop invariant before code. The trap is in the contract, not the loop body. |
| Work with n ≥ 10⁶, similarity search, dedup at scale, top-K, streaming analytics, cardinality estimation, embeddings, FFT/NTT, dimensionality reduction, computational geometry, randomized algorithms | mathguard | Classical algorithms have hit their lower bound; an approximate or math-heavy technique (Bloom, HLL, Count-Min, MinHash/LSH, FFT, JL projection, sweep line, kd-tree) gives the asymptotic win. |
Routing flow
Are you writing new code?
├── yes → lemmaly (state complexity, structure, family BEFORE coding)
│ ├── classical algorithm at its lower bound AND n is large? → mathguard
│ └── subtle correctness trap (invariant, base case, off-by-one)? → invariant-guard
└── no, refactoring existing slow / OOM / timed-out code → complexity-cuts
└── still slow after classical fixes? → mathguardOne-line mental model
- lemmaly = think first (prevention).
- complexity-cuts = clean up bad Big-O (correction).
- invariant-guard = prove it's correct (verification).
- mathguard = beat the classical floor (acceleration).
The Iron Law
NO NON-TRIVIAL CODE WITHOUT STATED COMPLEXITY, DATA STRUCTURE, AND ALGORITHM FAMILYBefore you write a loop, a recursion, a query, or any computation over more than a handful of items, three things must appear in your message — in this order:
1. time = O(?), space = O(?), with the dominant input dimension named.
2. The data structure you will use, with a one-phrase reason.
3. The algorithm family (one of: linear scan, two-pointer, sliding window, binary search, sort+sweep, hash join, BFS/DFS, topo sort, Dijkstra/A*, union-find, DP, greedy, recursion+memo, prefix sum, segment tree, monoid reduction).
If you cannot state all three, you do not understand the problem yet. Ask, or read more code. Do not write code.
Non-negotiable rules
1. State complexity before writing any non-trivial code. In one line:
time = O(?),space = O(?)- Dominant input dimension:
n = what, with realistic magnitude (e.g.n ~ 10^6 rows) - If you cannot state these, you do not yet understand the problem. Ask, or read more code.
2. Name the data structure with a one-phrase reason. Every collection-shaped value gets a deliberate choice from Array / List / Set / HashMap / TreeMap / Heap / Deque / Trie / Graph / BitSet / Counter / LinkedList — with the reason: "Set for expected/amortized constant-time membership under the runtime’s hash model", "Heap for top-K in O(n log k)", "Counter to fold the nested loop into a single pass". Default to hashed structures (Set, Map) for lookup inside loops. Default to streaming/iterator over materialized list when n is large.
3. Identify the algorithm family before writing. Name one of: linear scan, divide and conquer, two-pointer, sliding window, binary search, sort + sweep, hash join, BFS/DFS, topological sort, Dijkstra/A*, union-find, dynamic programming, greedy, recursion + memoization, prefix sum, segment tree, monoid reduction. If you cannot name a family, you are about to write brute force. Stop and reconsider.
4. Repeated work in loops is algorithmic waste. All of these are presumed wrong until justified:
- I/O inside a loop (database queries, HTTP calls, file reads) — consider bounded batches, bulk endpoints or streaming. Use a concurrency limit and service rate/memory budget; unbounded Promise.all over n remote calls can exhaust resources. Preserve sequential dependencies and transaction semantics.
- Recomputing the same value in a loop — hoist or memoize
- Re-sorting / re-grouping inside a loop — sort once outside
- Linear scan (
.find,.indexOf,.includes,in list) inside a loop — precompute an indexMap - Allocating fresh structures per iteration when one can be safely reused — hoist only when values do not escape or alias across outputs/async tasks
- Materializing intermediate collections only to iterate again — fuse into one pass
If you must do any of these inside a loop, write one comment line explaining why.
5. No invented complexity or numbers. Never write "O(log n) on average" without an argument. Never write "10x faster" or "~3ms" without measuring. If you cannot derive the complexity, write <complexity: TBD>. If you have not measured, write <measured: TBD>. Move on.
The pre-write protocol
Before producing non-trivial code, your message must contain — in this order:
1. Problem shape — one sentence. ("Given n events with a timestamp, find the longest contiguous window where total weight ≤ K.")
2. Input dimensions — n = ?, realistic magnitude, whether hot path.
3. Target complexity — time = O(?), space = O(?).
4. Data structures — name them with a phrase each.
5. Algorithm family — one phrase.
6. Edge cases you will handle — empty, singleton, all-equal, n=1, n=max, overflow, duplicates. List the ones that apply.
7. The code.
If any of 1–6 is missing, do not emit code yet.
Canonical example — protocol vs no-protocol
The same problem with and without the seven-step protocol.
Problem. Given users: User[] and bannedIds: string[], return users whose id is not banned. Realistic n: 50k users, 5k banned.
Without the protocol — ships O(n·m)
// Looks idiomatic, ships O(n·m)
const active = users.filter((u) => !bannedIds.includes(u.id));bannedIds.includes is O(m) per call. The filter runs it n times → up to 50k × 5k = 250M comparisons in the worst case; early matches reduce actual comparisons.
With the protocol — O(n + m)
// Protocol applied:
// expected time = O(n + m), auxiliary index space = O(m), output space = O(n), n = 50k users, m = 5k banned
// structure: Set<string> for expected/amortized constant-time membership
// family: linear scan with hashed lookup
// edge cases: empty users → [], empty bannedIds → users, duplicates in bannedIds → fine (Set dedupes)
const banned = new Set(bannedIds);
const active = users.filter((u) => !banned.has(u.id));The first version is the default an AI ships when asked "filter the active users." The second is what the protocol forces — without changing how the code reads.
Rule catalog (the lemmaly scanner)
The upstream repo ships a deterministic CLI scanner with the same anti-patterns this skill enforces (a version-dependent rule catalog across multiple languages: JavaScript/TypeScript, Python, SQL, Java, C#, C++, Go, Rust, PHP, Ruby, Shell/Bash). Each rule has a documented why, an incorrect example, a correct example, and the sibling skill to escalate to.
The scanner is optional. Do not automatically clone and run the upstream
repository from its default branch, because that executes whatever code is
current in a third-part
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- linkedin-content-generator – Bộ công cụ nội dung LinkedIn dùng AI: tạo bài đăng, carousel, bản tin và lịch 30 ngày…
- write-a-skill – Tạo skill agent mới với cấu trúc đúng, tiết lộ thông tin theo lớp (progressive…
- linkedin-post-writer – Soạn bài đăng LinkedIn từ 16 công thức hook minh họa, ánh xạ theo mục tiêu tương tác…
- youtube-full – Dùng khi người dùng cần transcript YouTube, tìm video, duyệt kênh, trích xuất playlist…
- location-based-content-idea-generator – Local Content Idea Generator. Dùng khi làm việc với vị trí, đối tượng và chủ đề kinh…
- longbridge-content – Tin tức mới nhất, hồ sơ quy định, chủ đề thảo luận cộng đồng về cổ phiếu niêm yết và…
- makepad-event-action – CRITICAL: Dùng cho xử lý sự kiện và action trong Makepad. Kích hoạt khi: makepad event…
- marlin-bed-leveling – Hiệu chỉnh cân bằng giường in cho firmware máy in 3D Marlin 2.x: Unified Bed Leveling…