[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6P7PV61FSYVBN095DJ8Z95Y":3,"skill-same:01M6P7PV61FSYVBN095DJ8Z95Y":73},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":37,"linkOnly":38,"markdownContent":39,"markdownBody":40,"frontMatter":41,"refName":23,"commitSha":54,"skillDirectory":55,"forksCount":13,"repositoryHtmlUrl":56,"repositoryHomepageUrl":6,"ownerHtmlUrl":57,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":58,"install":59,"resources":72},"01M6P7PV61FSYVBN095DJ8Z95Y","lemmaly",null,"Algorithm-first discipline: state Big-O, data structure, and algorithm family BEFORE writing loops, queries, or recursion. Catches O(n^2), N+1, and brute-force defaults.","duc-duy-1612\u002FOnline-Delivery-Systems-Web","duc-duy-1612","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F192231384?v=4","01M6NSDKQQDKVTHZ8DZMZ1VYY6","01M6NSDKW8DDVTQHBT1HBDDJPT",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Flemmaly\u002FSKILL.md",[],[5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36],"data","loops","algorithms","structure","family","main","community","complexity","discipline","writing","gateway","license","code-review","code","performance","gemini","safe","cli","review","2026-11-10 10:12:30",false,"---\nname: lemmaly\ndescription: \"Algorithm-first discipline: state Big-O, data structure, and algorithm family BEFORE writing loops, queries, or recursion. Catches O(n^2), N+1, and brute-force defaults.\"\nrisk: safe\nsource: community\nsource_repo: morsechimwai\u002Flemmaly\nsource_type: community\ndate_added: \"2026-05-26\"\nauthor: morsechimwai\ntags: [algorithms, big-o, performance, code-review, complexity, gateway]\ntools: [claude-code, antigravity, cursor, gemini-cli, codex-cli]\nlicense: \"Apache-2.0\"\nlicense_source: \"https:\u002F\u002Fgithub.com\u002Fmorsechimwai\u002Flemmaly\u002Fblob\u002Fmain\u002FLICENSE\"\n---\n\n# lemmaly — Algorithm-First Proof\n\nThe 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.\n\nThis 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.\n\n**Violating the letter of these rules is violating the spirit of the skill.** \"Just this once\" is how O(n²) ships to production.\n\n## When to Use This Skill\n\nUse **lemmaly** when:\n\n- 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.\n- About to write a `for` inside a `for`, `.find` \u002F `.includes` \u002F `.indexOf` inside a loop, `await` inside `for` \u002F `map` \u002F `forEach` over independent items, or one query per item in a collection.\n- Auditing a codebase \u002F PR for known anti-patterns (await-in-loop, `.includes` inside `.filter`, string-concat in loop, `SELECT *`, N+1, etc.).\n- Reviewing AI-generated code that \"looks idiomatic\" but might hide O(n²) or N+1.\n\nWhen in doubt, **start at lemmaly** — it is the gateway and will tell you when to escalate to its three sibling skills.\n\n| If you are about to… | Use | Why |\n| --- | --- | --- |\n| Write *new* code that loops, queries, joins, recurses, or processes a collection | **lemmaly** | Forces complexity + data structure + algorithm family **before** code is written. |\n| Refactor *existing* code that is already slow, OOMs, times out, or has nested loops \u002F N+1 \u002F repeated work | **complexity-cuts** | Corrective playbook for code that already shipped with bad Big-O. |\n| 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 \u002F termination concerns) | **invariant-guard** | Forces writing the function contract + loop invariant before code. The trap is in the contract, not the loop body. |\n| Work with n ≥ 10⁶, similarity search, dedup at scale, top-K, streaming analytics, cardinality estimation, embeddings, FFT\u002FNTT, 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\u002FLSH, FFT, JL projection, sweep line, kd-tree) gives the asymptotic win. |\n\n### Routing flow\n\n```text\nAre you writing new code?\n├── yes → lemmaly (state complexity, structure, family BEFORE coding)\n│         ├── classical algorithm at its lower bound AND n is large? → mathguard\n│         └── subtle correctness trap (invariant, base case, off-by-one)? → invariant-guard\n└── no, refactoring existing slow \u002F OOM \u002F timed-out code → complexity-cuts\n          └── still slow after classical fixes? → mathguard\n```\n\n### One-line mental model\n\n- **lemmaly** = think first (prevention).\n- **complexity-cuts** = clean up bad Big-O (correction).\n- **invariant-guard** = prove it's correct (verification).\n- **mathguard** = beat the classical floor (acceleration).\n\n## The Iron Law\n\n```text\nNO NON-TRIVIAL CODE WITHOUT STATED COMPLEXITY, DATA STRUCTURE, AND ALGORITHM FAMILY\n```\n\nBefore 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:\n\n1. `time = O(?)`, `space = O(?)`, with the dominant input dimension named.\n2. The data structure you will use, with a one-phrase reason.\n3. The algorithm family (one of: linear scan, two-pointer, sliding window, binary search, sort+sweep, hash join, BFS\u002FDFS, topo sort, Dijkstra\u002FA*, union-find, DP, greedy, recursion+memo, prefix sum, segment tree, monoid reduction).\n\nIf you cannot state all three, you do not understand the problem yet. Ask, or read more code. Do not write code.\n\n## Non-negotiable rules\n\n1. **State complexity before writing any non-trivial code.** In one line:\n   - `time = O(?)`, `space = O(?)`\n   - Dominant input dimension: `n = what`, with realistic magnitude (e.g. `n ~ 10^6 rows`)\n   - If you cannot state these, you do not yet understand the problem. Ask, or read more code.\n\n2. **Name the data structure with a one-phrase reason.** Every collection-shaped value gets a deliberate choice from `Array \u002F List \u002F Set \u002F HashMap \u002F TreeMap \u002F Heap \u002F Deque \u002F Trie \u002F Graph \u002F BitSet \u002F Counter \u002F LinkedList` — with the reason: \"Set for O(1) membership inside the loop\", \"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\u002Fiterator over materialized list when n is large.\n\n3. **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\u002FDFS`, `topological sort`, `Dijkstra\u002FA*`, `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.\n\n4. **Repeated work in loops is algorithmic waste.** All of these are presumed wrong until justified:\n   - I\u002FO inside a loop (database queries, HTTP calls, file reads) — batch with `IN (...)`, `Promise.all`, bulk endpoints, streaming\n   - Recomputing the same value in a loop — hoist or memoize\n   - Re-sorting \u002F re-grouping inside a loop — sort once outside\n   - Linear scan (`.find`, `.indexOf`, `.includes`, `in list`) inside a loop — precompute an index `Map`\n   - Allocating fresh structures per iteration when one can be reused — hoist allocation\n   - Materializing intermediate collections only to iterate again — fuse into one pass\n\n   If you must do any of these inside a loop, write one comment line explaining why.\n\n5. **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 `\u003Ccomplexity: TBD>`. If you have not measured, write `\u003Cmeasured: TBD>`. Move on.\n\n## The pre-write protocol\n\nBefore producing non-trivial code, your message must contain — in this order:\n\n1. **Problem shape** — one sentence. (\"Given n events with a timestamp, find the longest contiguous window where total weight ≤ K.\")\n2. **Input dimensions** — `n = ?`, realistic magnitude, whether hot path.\n3. **Target complexity** — `time = O(?)`, `space = O(?)`.\n4. **Data structures** — name them with a phrase each.\n5. **Algorithm family** — one phrase.\n6. **Edge cases you will handle** — empty, singleton, all-equal, n=1, n=max, overflow, duplicates. List the ones that apply.\n7. **The code.**\n\nIf any of 1–6 is missing, do not emit code yet.\n\n## Canonical example — protocol vs no-protocol\n\nThe same problem with and without the seven-step protocol.\n\n**Problem.** Given `users: User[]` and `bannedIds: string[]`, return users whose `id` is not banned. Realistic n: 50k users, 5k banned.\n\n### Without the protocol — ships O(n·m)\n\n```ts\n\u002F\u002F Looks idiomatic, ships O(n·m)\nconst active = users.filter((u) => !bannedIds.includes(u.id));\n```\n\n`bannedIds.includes` is O(m) per call. The filter runs it n times → 50k × 5k = 250M comparisons.\n\n### With the protocol — O(n + m)\n\n```ts\n\u002F\u002F Protocol applied:\n\u002F\u002F   time = O(n + m), space = O(m), n = 50k users, m = 5k banned\n\u002F\u002F   structure: Set\u003Cstring> for O(1) membership inside the loop\n\u002F\u002F   family: linear scan with hashed lookup\n\u002F\u002F   edge cases: empty users → [], empty bannedIds → users, duplicates in bannedIds → fine (Set dedupes)\nconst banned = new Set(bannedIds);\nconst active = users.filter((u) => !banned.has(u.id));\n```\n\nThe 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.\n\n## Rule catalog (the lemmaly scanner)\n\nThe upstream repo ships a deterministic CLI scanner with the same anti-patterns this skill enforces (**59 rules across 11 languages**: JavaScript\u002FTypeScript, Python, SQL, Java, C#, C++, Go, Rust, PHP, Ruby, Shell\u002FBash). Each rule has a documented why, an incorrect example, a correct example, and the sibling skill to escalate to.\n\nThe scanner is optional. Do not automatically clone and run the upstream\nrepository from its default branch, because that executes whatever code is\ncurrent in a third-party repository. If the user explicitly wants the scanner,\npin the source to a reviewed release tag or commit, use a throwaway directory,\nand show the resolved commit before running it:\n\n```bash\n# Replace \u003Creviewed-tag-or-commit> after reviewing the upstream release.\ntmpdir=\"$(mktemp -d)\"\ngit clone --filter=blob:none https:\u002F\u002Fgithub.com\u002Fmorsechimwai\u002Flemmaly.git \"$tmpdir\u002Flemmaly\"\ngit -C \"$tmpdir\u002Flemmaly\" checkout --detach \u003Creviewed-tag-or-commit>\ngit -C \"$tmpdir\u002Flemmaly\" rev-parse HEAD\nnode \"$tmpdir\u002Flemmaly\u002Fcli\u002Flemmaly.js\" scan \u003Cpath>\nnode \"$tmpdir\u002Flemmaly\u002Fcli\u002Flemmaly.js\" rules\n```\n\nWhen the scan is done, remove the throwaway directory only after verifying that\n`$tmpdir` points to the directory created by `mktemp -d`.\n\n**CRITICAL severity (error in CI):**\n\n- `js-await-in-for-loop` — N+1 over network\n- `js-async-in-foreach` — dropped promises\n- `py-mutable-default-arg` — shared default state\n- `sql-update-no-where` — touches every row\n- `java-arraylist-remove-in-for-i` — index shifts; ConcurrentModification\n- `cs-async-void` — exceptions unobserved; crashes the process\n- `go-loop-var-capture` — pre-1.22 race on the last value\n- `php-query-in-loop` — N+1 against the database\n\n**HIGH severity (warning in CI):** `js-deep-clone-via-json`, `js-useeffect-missing-deps`, `js-inline-object-jsx-prop`, `js-anonymous-handler-jsx`, `js-spread-in-reduce`, `js-unique-via-indexof`, `js-helper-call-in-iterator`, `py-string-concat-in-loop`, `py-django-loop-without-eager`, `py-bare-except`, `sql-select-star`, `sql-leading-wildcard-like`, `sql-not-in-subquery`, `java-string-concat-in-loop`, `java-list-contains-in-loop`, `java-bare-catch-exception`, `cs-string-concat-in-loop`, `cs-list-contains-in-loop`, `cs-disposable-no-using`, `go-string-concat-in-loop`, `go-defer-in-loop`, `go-err-not-checked`, `rs-unwrap-in-prod`, `cpp-string-concat-in-loop`, `cpp-raw-new`, `php-count-in-for-condition`, `php-in-array-in-loop`, `rb-include-in-iterator`, `rb-n-plus-one-activerecord`, `rb-bare-rescue`, `sh-set-e-no-pipefail`, `sh-unquoted-var`, `sh-for-ls`.\n\n**MEDIUM severity (info in CI):** `js-nested-for-loops`, `js-includes-in-iterator`, `js-array-key-index`, `py-range-len`, `py-in-list-literal`, `py-open-without-with`, `sql-select-no-limit`, `sql-or-in-where`, `go-slice-append-no-cap`, `rs-clone-in-loop`, `rs-vec-push-no-capacity`, `rs-string-push-no-capacity`, `cpp-vector-push-no-reserve`, `cpp-range-loop-copy`, `cpp-map-double-lookup`, `php-loose-equality`, `rb-string-concat-in-loop`, `sh-useless-cat-pipe`.\n\n## When to escalate to sibling skills\n\nlemmaly handles classical, day-to-day algorithmic discipline. Escalate when:\n\n- **Math-level optimization** (probabilistic data structures, FFT, dimensionality reduction, approximation algorithms, computational geometry) — load **mathguard**.\n- **Algorithm correctness** (loop invariants, termination, recursion base cases, edge cases that tests miss) — load **invariant-guard**.\n- **Existing code with bad complexity that already shipped** — load **complexity-cuts** for the corrective transformation playbook.\n\n## Rationalizations to watch for\n\nThese are real verbatim thoughts captured from controlled tests where the model shipped O(n·m) code that the seven-step protocol would have prevented:\n\n| Excuse | Reality |\n| --- | --- |\n| \"`.filter` then `.reduce` is the idiomatic way, ship it.\" | Idiomatic ≠ correct asymptotic. Idiom-driven coding is how O(n²) ships. |\n| \"It's fine for now, we can optimize later.\" | Later is a different engineer with no context. State the complexity now. |\n| \"I'll just use `Array.find` here, it's just one lookup.\" | One lookup inside a loop over `n` items is `O(n)` lookups. Make the `Map` outside. |\n| \"The data is small in dev — I'll worry about scale when we ship.\" | Production data is never the size of dev data. The seven-step protocol takes 30 seconds. |\n| \"I already understand the problem, the protocol is overhead.\" | The cases the protocol \"wastes time on\" are the cases that break in prod. |\n\nIf any of these sound familiar mid-thought: stop, write the seven steps.\n\n## Red flags — STOP and restart the protocol\n\n- About to write a `for` inside a `for` without first stating it is the intended O(n·m).\n- About to call `.find` \u002F `.includes` \u002F `.indexOf` inside a loop body.\n- About to `await` inside `for` \u002F `map` \u002F `forEach` over independent items.\n- About to issue one query per item in a collection.\n- About to recurse without stating the base case or memoization plan.\n- About to write code without having stated complexity.\n- About to claim \"this is fast\" \u002F \"this is efficient\" \u002F \"this scales\" without a derivation.\n- About to copy a brute-force solution from memory because it \"should work for now\".\n\nAll of these mean: stop, restart the seven-step protocol, choose a better algorithm or explicitly accept the brute force with a written justification.\n\n## Verification checklist\n\nBefore claiming the implementation is done:\n\n- [ ] Stated `time = O(?)` and `space = O(?)` appear in the message or PR description.\n- [ ] Dominant input dimension is named with a realistic magnitude.\n- [ ] Every collection-shaped value has a deliberate data-structure choice with a one-phrase reason.\n- [ ] The algorithm family is named (not \"a loop\").\n- [ ] No I\u002FO, `.find` \u002F `.includes` \u002F `.indexOf`, regex compile, sort, or independent `await` sits inside a loop without a one-line justification.\n- [ ] The shipped code matches the complexity that was claimed (re-derive if uncertain).\n- [ ] Edge cases listed in the pre-write protocol each have a corresponding code path or test.\n- [ ] Any \"fast\" \u002F \"efficient\" \u002F \"scales\" claims have either a derivation or a measurement — `\u003Cmeasured: TBD>` is acceptable; an unsupported claim is not.\n\nCannot check every box? You did not run the protocol. Restart from step 1.\n\n## Limitations\n\n- **Not a substitute for profiling.** lemmaly forces asymptotic reasoning, not measurement. For constant-factor wins, latency tails, or I\u002FO bottlenecks you still need a profiler.\n- **Reasoning gate, not a code generator.** This skill changes how the model thinks before writing; it does not auto-rewrite existing code (use `complexity-cuts` for that).\n- **English-language enforcement.** The rule catalog and prompts are English-only.\n- **n \u003C ~10 is exempt.** The protocol explicitly accepts trivial collections and one-shot setup code; do not waste time stating complexity for `for i in range(3)`.\n- **Cannot prevent intentional brute force.** If the author writes a one-line justification (\"n ≤ 100 in practice; readability matters more\"), brute force ships. The skill only requires the justification, not its absence.\n- **CLI scanner is separate.** The 59 rules are enforced by `lemmaly scan` in the upstream repo, not by this SKILL.md alone.\n\n## The thesis, in one line\n\n> **AI ships algorithmically lazy code by default. lemmaly makes it think first.**\n\n## Related Skills\n\n- `mathguard` — escalation for n ≥ 10⁶ where classical O(n log n) is the floor and probabilistic \u002F math-heavy techniques win.\n- `invariant-guard` — correctness layer for algorithms whose obvious version is subtly wrong.\n- `complexity-cuts` — corrective playbook for code that already shipped with bad Big-O.\n","# lemmaly — Algorithm-First Proof\n\nThe 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.\n\nThis 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.\n\n**Violating the letter of these rules is violating the spirit of the skill.** \"Just this once\" is how O(n²) ships to production.\n\n## When to Use This Skill\n\nUse **lemmaly** when:\n\n- 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.\n- About to write a `for` inside a `for`, `.find` \u002F `.includes` \u002F `.indexOf` inside a loop, `await` inside `for` \u002F `map` \u002F `forEach` over independent items, or one query per item in a collection.\n- Auditing a codebase \u002F PR for known anti-patterns (await-in-loop, `.includes` inside `.filter`, string-concat in loop, `SELECT *`, N+1, etc.).\n- Reviewing AI-generated code that \"looks idiomatic\" but might hide O(n²) or N+1.\n\nWhen in doubt, **start at lemmaly** — it is the gateway and will tell you when to escalate to its three sibling skills.\n\n| If you are about to… | Use | Why |\n| --- | --- | --- |\n| Write *new* code that loops, queries, joins, recurses, or processes a collection | **lemmaly** | Forces complexity + data structure + algorithm family **before** code is written. |\n| Refactor *existing* code that is already slow, OOMs, times out, or has nested loops \u002F N+1 \u002F repeated work | **complexity-cuts** | Corrective playbook for code that already shipped with bad Big-O. |\n| 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 \u002F termination concerns) | **invariant-guard** | Forces writing the function contract + loop invariant before code. The trap is in the contract, not the loop body. |\n| Work with n ≥ 10⁶, similarity search, dedup at scale, top-K, streaming analytics, cardinality estimation, embeddings, FFT\u002FNTT, 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\u002FLSH, FFT, JL projection, sweep line, kd-tree) gives the asymptotic win. |\n\n### Routing flow\n\n```text\nAre you writing new code?\n├── yes → lemmaly (state complexity, structure, family BEFORE coding)\n│         ├── classical algorithm at its lower bound AND n is large? → mathguard\n│         └── subtle correctness trap (invariant, base case, off-by-one)? → invariant-guard\n└── no, refactoring existing slow \u002F OOM \u002F timed-out code → complexity-cuts\n          └── still slow after classical fixes? → mathguard\n```\n\n### One-line mental model\n\n- **lemmaly** = think first (prevention).\n- **complexity-cuts** = clean up bad Big-O (correction).\n- **invariant-guard** = prove it's correct (verification).\n- **mathguard** = beat the classical floor (acceleration).\n\n## The Iron Law\n\n```text\nNO NON-TRIVIAL CODE WITHOUT STATED COMPLEXITY, DATA STRUCTURE, AND ALGORITHM FAMILY\n```\n\nBefore 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:\n\n1. `time = O(?)`, `space = O(?)`, with the dominant input dimension named.\n2. The data structure you will use, with a one-phrase reason.\n3. The algorithm family (one of: linear scan, two-pointer, sliding window, binary search, sort+sweep, hash join, BFS\u002FDFS, topo sort, Dijkstra\u002FA*, union-find, DP, greedy, recursion+memo, prefix sum, segment tree, monoid reduction).\n\nIf you cannot state all three, you do not understand the problem yet. Ask, or read more code. Do not write code.\n\n## Non-negotiable rules\n\n1. **State complexity before writing any non-trivial code.** In one line:\n   - `time = O(?)`, `space = O(?)`\n   - Dominant input dimension: `n = what`, with realistic magnitude (e.g. `n ~ 10^6 rows`)\n   - If you cannot state these, you do not yet understand the problem. Ask, or read more code.\n\n2. **Name the data structure with a one-phrase reason.** Every collection-shaped value gets a deliberate choice from `Array \u002F List \u002F Set \u002F HashMap \u002F TreeMap \u002F Heap \u002F Deque \u002F Trie \u002F Graph \u002F BitSet \u002F Counter \u002F LinkedList` — with the reason: \"Set for O(1) membership inside the loop\", \"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\u002Fiterator over materialized list when n is large.\n\n3. **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\u002FDFS`, `topological sort`, `Dijkstra\u002FA*`, `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.\n\n4. **Repeated work in loops is algorithmic waste.** All of these are presumed wrong until justified:\n   - I\u002FO inside a loop (database queries, HTTP calls, file reads) — batch with `IN (...)`, `Promise.all`, bulk endpoints, streaming\n   - Recomputing the same value in a loop — hoist or memoize\n   - Re-sorting \u002F re-grouping inside a loop — sort once outside\n   - Linear scan (`.find`, `.indexOf`, `.includes`, `in list`) inside a loop — precompute an index `Map`\n   - Allocating fresh structures per iteration when one can be reused — hoist allocation\n   - Materializing intermediate collections only to iterate again — fuse into one pass\n\n   If you must do any of these inside a loop, write one comment line explaining why.\n\n5. **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 `\u003Ccomplexity: TBD>`. If you have not measured, write `\u003Cmeasured: TBD>`. Move on.\n\n## The pre-write protocol\n\nBefore producing non-trivial code, your message must contain — in this order:\n\n1. **Problem shape** — one sentence. (\"Given n events with a timestamp, find the longest contiguous window where total weight ≤ K.\")\n2. **Input dimensions** — `n = ?`, realistic magnitude, whether hot path.\n3. **Target complexity** — `time = O(?)`, `space = O(?)`.\n4. **Data structures** — name them with a phrase each.\n5. **Algorithm family** — one phrase.\n6. **Edge cases you will handle** — empty, singleton, all-equal, n=1, n=max, overflow, duplicates. List the ones that apply.\n7. **The code.**\n\nIf any of 1–6 is missing, do not emit code yet.\n\n## Canonical example — protocol vs no-protocol\n\nThe same problem with and without the seven-step protocol.\n\n**Problem.** Given `users: User[]` and `bannedIds: string[]`, return users whose `id` is not banned. Realistic n: 50k users, 5k banned.\n\n### Without the protocol — ships O(n·m)\n\n```ts\n\u002F\u002F Looks idiomatic, ships O(n·m)\nconst active = users.filter((u) => !bannedIds.includes(u.id));\n```\n\n`bannedIds.includes` is O(m) per call. The filter runs it n times → 50k × 5k = 250M comparisons.\n\n### With the protocol — O(n + m)\n\n```ts\n\u002F\u002F Protocol applied:\n\u002F\u002F   time = O(n + m), space = O(m), n = 50k users, m = 5k banned\n\u002F\u002F   structure: Set\u003Cstring> for O(1) membership inside the loop\n\u002F\u002F   family: linear scan with hashed lookup\n\u002F\u002F   edge cases: empty users → [], empty bannedIds → users, duplicates in bannedIds → fine (Set dedupes)\nconst banned = new Set(bannedIds);\nconst active = users.filter((u) => !banned.has(u.id));\n```\n\nThe 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.\n\n## Rule catalog (the lemmaly scanner)\n\nThe upstream repo ships a deterministic CLI scanner with the same anti-patterns this skill enforces (**59 rules across 11 languages**: JavaScript\u002FTypeScript, Python, SQL, Java, C#, C++, Go, Rust, PHP, Ruby, Shell\u002FBash). Each rule has a documented why, an incorrect example, a correct example, and the sibling skill to escalate to.\n\nThe scanner is optional. Do not automatically clone and run the upstream\nrepository from its default branch, because that executes whatever code is\ncurrent in a third-party repository. If the user explicitly wants the scanner,\npin the source to a reviewed release tag or commit, use a throwaway directory,\nand show the resolved commit before running it:\n\n```bash\n# Replace \u003Creviewed-tag-or-commit> after reviewing the upstream release.\ntmpdir=\"$(mktemp -d)\"\ngit clone --filter=blob:none https:\u002F\u002Fgithub.com\u002Fmorsechimwai\u002Flemmaly.git \"$tmpdir\u002Flemmaly\"\ngit -C \"$tmpdir\u002Flemmaly\" checkout --detach \u003Creviewed-tag-or-commit>\ngit -C \"$tmpdir\u002Flemmaly\" rev-parse HEAD\nnode \"$tmpdir\u002Flemmaly\u002Fcli\u002Flemmaly.js\" scan \u003Cpath>\nnode \"$tmpdir\u002Flemmaly\u002Fcli\u002Flemmaly.js\" rules\n```\n\nWhen the scan is done, remove the throwaway directory only after verifying that\n`$tmpdir` points to the directory created by `mktemp -d`.\n\n**CRITICAL severity (error in CI):**\n\n- `js-await-in-for-loop` — N+1 over network\n- `js-async-in-foreach` — dropped promises\n- `py-mutable-default-arg` — shared default state\n- `sql-update-no-where` — touches every row\n- `java-arraylist-remove-in-for-i` — index shifts; ConcurrentModification\n- `cs-async-void` — exceptions unobserved; crashes the process\n- `go-loop-var-capture` — pre-1.22 race on the last value\n- `php-query-in-loop` — N+1 against the database\n\n**HIGH severity (warning in CI):** `js-deep-clone-via-json`, `js-useeffect-missing-deps`, `js-inline-object-jsx-prop`, `js-anonymous-handler-jsx`, `js-spread-in-reduce`, `js-unique-via-indexof`, `js-helper-call-in-iterator`, `py-string-concat-in-loop`, `py-django-loop-without-eager`, `py-bare-except`, `sql-select-star`, `sql-leading-wildcard-like`, `sql-not-in-subquery`, `java-string-concat-in-loop`, `java-list-contains-in-loop`, `java-bare-catch-exception`, `cs-string-concat-in-loop`, `cs-list-contains-in-loop`, `cs-disposable-no-using`, `go-string-concat-in-loop`, `go-defer-in-loop`, `go-err-not-checked`, `rs-unwrap-in-prod`, `cpp-string-concat-in-loop`, `cpp-raw-new`, `php-count-in-for-condition`, `php-in-array-in-loop`, `rb-include-in-iterator`, `rb-n-plus-one-activerecord`, `rb-bare-rescue`, `sh-set-e-no-pipefail`, `sh-unquoted-var`, `sh-for-ls`.\n\n**MEDIUM severity (info in CI):** `js-nested-for-loops`, `js-includes-in-iterator`, `js-array-key-index`, `py-range-len`, `py-in-list-literal`, `py-open-without-with`, `sql-select-no-limit`, `sql-or-in-where`, `go-slice-append-no-cap`, `rs-clone-in-loop`, `rs-vec-push-no-capacity`, `rs-string-push-no-capacity`, `cpp-vector-push-no-reserve`, `cpp-range-loop-copy`, `cpp-map-double-lookup`, `php-loose-equality`, `rb-string-concat-in-loop`, `sh-useless-cat-pipe`.\n\n## When to escalate to sibling skills\n\nlemmaly handles classical, day-to-day algorithmic discipline. Escalate when:\n\n- **Math-level optimization** (probabilistic data structures, FFT, dimensionality reduction, approximation algorithms, computational geometry) — load **mathguard**.\n- **Algorithm correctness** (loop invariants, termination, recursion base cases, edge cases that tests miss) — load **invariant-guard**.\n- **Existing code with bad complexity that already shipped** — load **complexity-cuts** for the corrective transformation playbook.\n\n## Rationalizations to watch for\n\nThese are real verbatim thoughts captured from controlled tests where the model shipped O(n·m) code that the seven-step protocol would have prevented:\n\n| Excuse | Reality |\n| --- | --- |\n| \"`.filter` then `.reduce` is the idiomatic way, ship it.\" | Idiomatic ≠ correct asymptotic. Idiom-driven coding is how O(n²) ships. |\n| \"It's fine for now, we can optimize later.\" | Later is a different engineer with no context. State the complexity now. |\n| \"I'll just use `Array.find` here, it's just one lookup.\" | One lookup inside a loop over `n` items is `O(n)` lookups. Make the `Map` outside. |\n| \"The data is small in dev — I'll worry about scale when we ship.\" | Production data is never the size of dev data. The seven-step protocol takes 30 seconds. |\n| \"I already understand the problem, the protocol is overhead.\" | The cases the protocol \"wastes time on\" are the cases that break in prod. |\n\nIf any of these sound familiar mid-thought: stop, write the seven steps.\n\n## Red flags — STOP and restart the protocol\n\n- About to write a `for` inside a `for` without first stating it is the intended O(n·m).\n- About to call `.find` \u002F `.includes` \u002F `.indexOf` inside a loop body.\n- About to `await` inside `for` \u002F `map` \u002F `forEach` over independent items.\n- About to issue one query per item in a collection.\n- About to recurse without stating the base case or memoization plan.\n- About to write code without having stated complexity.\n- About to claim \"this is fast\" \u002F \"this is efficient\" \u002F \"this scales\" without a derivation.\n- About to copy a brute-force solution from memory because it \"should work for now\".\n\nAll of these mean: stop, restart the seven-step protocol, choose a better algorithm or explicitly accept the brute force with a written justification.\n\n## Verification checklist\n\nBefore claiming the implementation is done:\n\n- [ ] Stated `time = O(?)` and `space = O(?)` appear in the message or PR description.\n- [ ] Dominant input dimension is named with a realistic magnitude.\n- [ ] Every collection-shaped value has a deliberate data-structure choice with a one-phrase reason.\n- [ ] The algorithm family is named (not \"a loop\").\n- [ ] No I\u002FO, `.find` \u002F `.includes` \u002F `.indexOf`, regex compile, sort, or independent `await` sits inside a loop without a one-line justification.\n- [ ] The shipped code matches the complexity that was claimed (re-derive if uncertain).\n- [ ] Edge cases listed in the pre-write protocol each have a corresponding code path or test.\n- [ ] Any \"fast\" \u002F \"efficient\" \u002F \"scales\" claims have either a derivation or a measurement — `\u003Cmeasured: TBD>` is acceptable; an unsupported claim is not.\n\nCannot check every box? You did not run the protocol. Restart from step 1.\n\n## Limitations\n\n- **Not a substitute for profiling.** lemmaly forces asymptotic reasoning, not measurement. For constant-factor wins, latency tails, or I\u002FO bottlenecks you still need a profiler.\n- **Reasoning gate, not a code generator.** This skill changes how the model thinks before writing; it does not auto-rewrite existing code (use `complexity-cuts` for that).\n- **English-language enforcement.** The rule catalog and prompts are English-only.\n- **n \u003C ~10 is exempt.** The protocol explicitly accepts trivial collections and one-shot setup code; do not waste time stating complexity for `for i in range(3)`.\n- **Cannot prevent intentional brute force.** If the author writes a one-line justification (\"n ≤ 100 in practice; readability matters more\"), brute force ships. The skill only requires the justification, not its absence.\n- **CLI scanner is separate.** The 59 rules are enforced by `lemmaly scan` in the upstream repo, not by this SKILL.md alone.\n\n## The thesis, in one line\n\n> **AI ships algorithmically lazy code by default. lemmaly makes it think first.**\n\n## Related Skills\n\n- `mathguard` — escalation for n ≥ 10⁶ where classical O(n log n) is the floor and probabilistic \u002F math-heavy techniques win.\n- `invariant-guard` — correctness layer for algorithms whose obvious version is subtly wrong.\n- `complexity-cuts` — corrective playbook for code that already shipped with bad Big-O.\n",{"name":5,"risk":34,"tags":42,"tools":44,"author":50,"source":24,"license":14,"date_added":51,"description":7,"source_repo":52,"source_type":24,"license_source":53},[20,43,32,30,25,28],"big-o",[45,46,47,48,49],"claude-code","antigravity","cursor","gemini-cli","codex-cli","morsechimwai","2026-05-26","morsechimwai\u002Flemmaly","https:\u002F\u002Fgithub.com\u002Fmorsechimwai\u002Flemmaly\u002Fblob\u002Fmain\u002FLICENSE","f3312ba749561b6159f477dbfc9313c875d40a56",".agents\u002Fskills_archive\u002Flemmaly","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612","2026-10-25 23:50:58",{"source":8,"skillName":5,"commands":60,"prompt":70,"zipAvailable":71},[61,64,67],{"tool":62,"command":63},"npx","npx skills add duc-duy-1612\u002FOnline-Delivery-Systems-Web --skill lemmaly",{"tool":65,"command":66},"bunx","bunx skills add duc-duy-1612\u002FOnline-Delivery-Systems-Web --skill lemmaly",{"tool":68,"command":69},"pnpm","pnpm dlx skills add duc-duy-1612\u002FOnline-Delivery-Systems-Web --skill lemmaly","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Flemmaly\u002FSKILL.md",true,[],[74,104,126,149,176,199],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":78,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":86,"publishedAt":37},"01M6Q0FA5FZ410Z33Z3TFQ4DBA","zero-trust","Implement zero-trust network architecture. Configure identity-based access, micro-segmentation, and continuous verification. Use when implementing modern security architectures.","MIT","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fzero-trust\u002FSKILL.md",[81],{"categoryNo":82,"categoryName":83,"taxonomyType":84,"taxonomyTypeDesc":85},"01JBSEEDCAT000000000000011","运维与部署","SCENARIO","使用场景",[87,88,89,90,91,92,76,93,94,95,96,97,24,23,98,99,100,101,102,103],"ZeRO","trust","zero trust","architecture","assessment","verification","segmentation","devops-security","access","configure","only","active","critical","scope","scripts","relevant","implementing",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":78,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":37},"01M6Q0F1YZJW3KX5FBKEVZ8CV4","zcode-delegate","Delegate coding tasks to the Z.AI ZCode CLI only when the user explicitly requests it, while the orchestrator retains review and landing responsibility.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fzcode-delegate\u002FSKILL.md",[],[111,112,113,36,35,114,115,116,117,118,119,120,121,97,122,24,123,124,99,125],"delegate","zcode","zcode delegate","orchestration","tasks","run","Bash","model","node","read","orchestrator","files","desktop app","app","agent-orchestration",{"skillNo":127,"name":128,"nameZh":6,"description":129,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":78,"licenseFileUrl":6,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":37},"01M6Q0ETK41VGNMYEXW0T00AJN","youtube-transcript","Fetch YouTube transcripts through DeepAPI or local fallback tooling and save clean text output.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-transcript\u002FSKILL.md",[],[133,134,135,34,136,137,138,29,139,140,141,142,143,24,23,144,145,146,147,148],"transcript","youtube transcript","youtube","github","codex","research","https","text","fetch","tooling","clean","local","output","deepapi","youtube transcripts","blob",{"skillNo":150,"name":151,"nameZh":6,"description":152,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":78,"licenseFileUrl":6,"sourceHtmlUrl":153,"categories":154,"keywords":166,"publishedAt":37},"01M6Q0EPPH2PVMDW40017F8WX0","youtube-transcript-skills","Fetch YouTube video transcripts, search videos\u002Fchannels, browse channels, and extract playlists via the getyoutubetranscript.com API - free tier, no card required.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-transcript-skills\u002FSKILL.md",[155,158,161],{"categoryNo":156,"categoryName":157,"taxonomyType":84,"taxonomyTypeDesc":85},"01JBSEEDCAT000000000000010","后端与接口",{"categoryNo":159,"categoryName":160,"taxonomyType":84,"taxonomyTypeDesc":85},"01JBSEEDCAT000000000000016","图像与多媒体",{"categoryNo":162,"categoryName":163,"taxonomyType":164,"taxonomyTypeDesc":165},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[133,134,135,167,34,33,136,137,29,168,169,170,171,141,172,24,23,173,174,175],"youtube transcript skills","search","api","Video","browse","api-integration","free","card","channels",{"skillNo":177,"name":178,"nameZh":6,"description":179,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":78,"licenseFileUrl":6,"sourceHtmlUrl":180,"categories":181,"keywords":186,"publishedAt":37},"01M6Q0EAB96PX83W5PTE8A0R8D","youtube-notetaker","Turn YouTube talks into local study notes with slides, transcripts, editable annotations, and a markdown-backed viewer.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-notetaker\u002FSKILL.md",[182,185],{"categoryNo":183,"categoryName":184,"taxonomyType":84,"taxonomyTypeDesc":85},"01JBSEEDCAT000000000000003","演示文稿",{"categoryNo":159,"categoryName":160,"taxonomyType":84,"taxonomyTypeDesc":85},[135,187,188,35,34,189,190,191,31,29,170,192,193,194,195,23,196,144,197,198],"youtube notetaker","notetaker","workflow","official","notes","markdown","slides","annotations","README","study","dair-academy","viewer",{"skillNo":200,"name":201,"nameZh":6,"description":202,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":78,"licenseFileUrl":6,"sourceHtmlUrl":203,"categories":204,"keywords":206,"publishedAt":37},"01M6Q0E55F0GW5MX48V8HXS8B5","youtube-full","Fetch YouTube transcripts, search videos, browse channels, and extract playlists via TranscriptAPI — no yt-dlp, no Google API key, works from any cloud server.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-full\u002FSKILL.md",[205],{"categoryNo":156,"categoryName":157,"taxonomyType":84,"taxonomyTypeDesc":85},[207,135,208,209,34,33,168,210,211,169,170,171,141,212,172,24,23,173,213,147],"youtube full","full","google","server","dlp","credits","automatic"]