Skip to content

feat: add motoko, mops-cli, and migration skills synced from caffeinelabs upstream#183

Open
marc0olo wants to merge 10 commits intomainfrom
improve/motoko-skill
Open

feat: add motoko, mops-cli, and migration skills synced from caffeinelabs upstream#183
marc0olo wants to merge 10 commits intomainfrom
improve/motoko-skill

Conversation

@marc0olo
Copy link
Copy Markdown
Member

@marc0olo marc0olo commented May 4, 2026

Summary

  • Rewrites motoko skill to align with caffeinelabs/motoko 1.7.0: plain actor {} with --default-persistent-actors flag as the primary style, transient var for reset-on-upgrade, dot notation for mo:core collections, moc >= 1.2.0 compatibility
  • Adds mops-cli skill synced from caffeinelabs/mops cli-v2.13.1: mops.toml configuration, mops check (canister name not file path), mops toolchain, mops migrate, mops test, lintoko integration
  • Adds migrating-motoko skill: inline (with migration = ...) syntax for single-step actor state transformations
  • Adds migrating-motoko-enhanced skill: migrations/ directory approach with --enhanced-migration for multi-step verifiable migration chains
  • Creates Motoko category for the three language skills; mops-cli stays in Infrastructure
  • Adds upstream sync strategy to CLAUDE.md: commit-hash pinning, two-step annotated tag dereference, curl+diff workflow, table of icskills-owned sections, discussion of automated release detection adapted from developer-docs

Upstream diff notes

All four skills are synced from tagged releases and track exact commit SHAs. Sections that icskills owns (not synced from upstream) are documented in each skill's upstream comment block:

Skill icskills-owned content
motoko M0141/M0145/do?{}/variant tag/transient var, Runtime.envVar, Text.join, List.get vs List.at
migrating-motoko Additional References (uses icskills skill names)
migrating-motoko-enhanced mops.toml Setup (removed upstream bug: args = ["--enhanced-migration=..."] is redundant when [canisters.backend.migrations] is configured), Additional References
mops-cli Additional References (uses icskills skill names)

Eval results

motoko — new/updated eval cases

Eval 1 — Simple actor with counter (eval rubric updated for flag-based style)

WITH skill WITHOUT skill
Score 5/5 5/5

Note: This is common knowledge; the eval confirms the rubric accepts both actor {} (with flag) and persistent actor.

Eval 7 — Transient vs stable semantics (new)

WITH skill WITHOUT skill
Score 5/5 1/5

Without skill, agents use stable var and never mention transient var or the flag.

Eval 8 — Caffeine to icp-cli: resolving M0220 errors (renamed from "Migration from plain actor to flag-based setup")

WITH skill WITHOUT skill
Score 4/4 1/4

Without skill, agents don't know about --default-persistent-actors or Caffeine's implicit persistence behavior.

migrating-motoko — full suite

Output evals:

Eval WITH skill WITHOUT skill
Rename a field 6/6 0/6
Bool to variant 4/4 2/4
Add field with default 2/4 1/4
Implicit migration — no code needed 2/3 1/3
Migration module pattern 5/5 3/5
Adversarial: preupgrade/postupgrade 2/3 0/3
Adversarial: importing old types 3/3 3/3

Trigger evals: should-trigger 7/7 ✅ | should-not-trigger 7/7 ✅

Notes:

  • "Rename a field" 6/6 vs 0/6 demonstrates the skill's core value — without it, agents fall back to preupgrade/postupgrade
  • "Adversarial: importing old types" 3/3 both ways = already common knowledge; eval validates the rubric
  • "Add field with default" 2/4 with skill: agent uses Map.map instead of dot notation old.users.map(...) — skill improvement opportunity
migrating-motoko-enhanced — full suite

Output evals:

Eval WITH skill WITHOUT skill Notes
First migration (Init) 4/4 0/4
Add a field (fixed prompt, re-run) 4/4 0/4 Original prompt caused file exploration (0/4 both ways); fixed to be self-contained
Actor body without initializers 4/4 3/4
mops.toml configuration (re-run after skill fix) 3/4 0/4 Removed upstream bug: redundant --enhanced-migration in args
Migration chain composition 3/4 3/4 Both miss "compiler verifies compatibility" wording
Workflow with mops 5/5 0/5
Adversarial: actor with initializers 3/3 0/3
Adversarial: mixing inline and enhanced 3/3 2/3

Trigger evals: should-trigger 8/8 ✅ | should-not-trigger 7/7 ✅

Notes:

  • Two evals were re-run on the final committed skill content: "Add a field" (prompt fix → 4/4) and "mops.toml configuration" (skill bug fix → without-skill improved from 1/4 to 0/4, confirming correct without-skill baseline)
mops-cli — full suite

Output evals:

Eval WITH skill WITHOUT skill
New project setup 7/7 0/7
Adding a dependency 3/3 2/3
Running mops check 4/4 3/4
Pinning moc version 4/4 2/4
Updating moc to latest 4/4 1/4
Migration workflow 6/6 0/6
Warning flag configuration 4/4 0/4
Adversarial: file path to mops check 4/4 1/4
Adversarial: mo:base import 3/4 1/4

Trigger evals: should-trigger 12/12 ✅ | should-not-trigger 8/8 ✅

Notes:

  • "New project setup" 7/7 vs 0/7 is the standout result — without the skill, agents don't know mops init -y, mops toolchain use moc latest, or the correct mops.toml structure
  • "Migration workflow" 6/6 vs 0/6 (timeout) — the baseline timed out; skill result is reliable
  • Perfect trigger evals (20/20) confirm clean skill boundary

marc0olo added 2 commits May 5, 2026 00:41
…trategy

- Rewrites motoko skill to align with caffeinelabs/motoko 1.7.0: plain
  actor {} with --default-persistent-actors flag as the primary style,
  transient var for reset-on-upgrade semantics, dot notation for
  collection operations (mo:core), and moc >= 1.2.0 compatibility
- Adds mops-cli skill synced from caffeinelabs/mops cli-v2.13.1:
  covers mops.toml configuration, mops check, mops toolchain, mops
  migrate, mops test, and lintoko integration
- Adds migrating-motoko skill: inline (with migration = ...) syntax for
  single-step actor state transformations without --enhanced-migration
- Adds migrating-motoko-enhanced skill: migrations/ directory approach
  with --enhanced-migration for multi-step verifiable migration chains
- Creates Motoko category for the three language skills; mops-cli stays
  in Infrastructure
- Adds upstream sync strategy to CLAUDE.md: commit-hash pinning,
  two-step annotated tag dereference, curl+diff workflow
- Adds evaluation files for all four skills with adversarial cases
- Adds motoko/references/ directory with api-reference, control-flow,
  examples, and type-conversions reference files
Add Sections owned by icskills to upstream comment blocks for
migrating-motoko, migrating-motoko-enhanced, and mops-cli, listing
which content should not be overwritten on upstream syncs.

Expand CLAUDE.md sync strategy with a table of change types
(cross-references, bug fixes, IC-specific additions vs shared content),
and document the planned automated upstream release detection workflow
adapted from dfinity/developer-docs.
@marc0olo marc0olo requested review from a team and JoshDFN as code owners May 4, 2026 22:56
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Skill Validation Report

Project Checks


✓ Project checks passed for 4 skills (0 warnings)

@marc0olo
Copy link
Copy Markdown
Member Author

marc0olo commented May 4, 2026

Upstream contribution candidates

While syncing with `caffeinelabs/motoko` 1.7.0 and `caffeinelabs/mops` cli-v2.13.1, I identified several improvements in our versions that could be contributed back upstream. Flagging them here so we can decide which are worth upstreaming.


caffeinelabs/motoko — from writing-motoko

1. mops.toml prerequisites block (high value)

Our skill shows a complete minimal mops.toml with [toolchain], [dependencies], and [moc].args in the Prerequisites section. Upstream shows only a Prerequisites list. The concrete toml block prevents agents from generating misconfigured projects. Worth upstreaming.

2. transient var explicit section (high value)

Our skill has a dedicated explanation of transient var (when to use it: timer IDs, rate limiters, ephemeral caches) and explicitly warns against stable var (redundant, produces M0218). Upstream mentions transient var only in passing. This is practical guidance agents frequently need.

3. M0141 / M0145 pitfalls (high value)

Our skill documents:

  • M0141: type declarations must be inside the actor body, not at file top level
  • M0145: let bindings must be inside the actor body too

Upstream doesn't have these. These are common agent errors — the compiler error alone isn't enough context.

4. do? {} Option chaining syntax

Our skill covers do? { expr1!; expr2!; expr3! } for short-circuiting Option chains. Upstream doesn't document this. Agents frequently generate verbose switch-based code instead.

5. Text.join and List.get vs List.at

Our skill documents Text.join(sep, iter) for joining text arrays and distinguishes List.get(list, index) : ?T (safe) from List.at(list, index) : T (traps). Upstream doesn't. These are common sources of agent-generated incorrect code.

6. Runtime.envVar for canister environment access

Our skill documents import Runtime "mo:core/Runtime" and Runtime.envVar("KEY") for reading environment variables injected by icp-cli. This is IC-specific, so it may not belong in the upstream Motoko language skill — but worth discussing.


caffeinelabs/motoko — from migrating-motoko-enhanced

7. mops.toml setup section with [canisters.<name>.migrations] (bug fix)

Our skill has a complete mops.toml showing how to configure enhanced migration using the [canisters.backend.migrations] TOML section (the high-level mops abstraction), with an explicit warning:

Do NOT add --enhanced-migration to [moc].args — when [canisters.<name>.migrations] is configured, mops injects it automatically; do not duplicate it in [canisters.<name>].args.

Upstream uses the lower-level [canisters.backend].args = ["--enhanced-migration=migrations"] approach (raw moc flag). This works but bypasses the mops migration chain management features (mops migrate new, mops migrate freeze, check-limit, build-limit). The high-level approach is safer and integrates with the full mops workflow. Worth contributing as the preferred pattern.


Priority suggestion

# Item Priority Reason
1 mops.toml prerequisites block High Prevents misconfigured projects
2 transient var section + M0218 warning High Common confusion, frequently needed
3 M0141 / M0145 pitfalls High Common agent errors
7 Enhanced migration [canisters.migrations] pattern Medium The upstream approach works, but ours is safer
4 do? {} syntax Medium Less common but zero-cost to add
5 Text.join / List.get vs List.at Low Niche enough to be noise in upstream
6 Runtime.envVar Low IC-specific, may not belong upstream

Happy to draft any of these as PRs to `caffeinelabs/motoko` if we decide they're worth contributing.

marc0olo added 6 commits May 5, 2026 01:16
Adds .github/workflows/sync-upstream.yml that detects new releases of
caffeinelabs/motoko and caffeinelabs/mops, opens a diff PR for manual
review. Workflow does not auto-apply changes.

Updates CLAUDE.md to reference the actual workflow file and document
icskills-owned vs upstream content by change type.
skills/skill.schema.json was being extracted by grep and then failing
the SKILL.md file test, causing bash -e to exit the step.

Add lookahead (?=/) to require a path separator after the dir name,
and add || true to the while loop as a belt-and-suspenders guard.
api-reference.md is a static snapshot of versioned library signatures
that will silently drift from reality as mo:core evolves. Directing
agents to the live mops.one/core reference is more reliable.

examples.md, control-flow.md, and type-conversions.md are pattern-based
and stable across releases — kept and documented as icskills-owned in
the upstream comment block.
… GITHUB_TOKEN

GITHUB_TOKEN with contents:write + pull-requests:write is blocked on
public dfinity repos (see dfinity/developer-docs#196). Switch both
jobs to the pr-automation-bot-public GitHub App token.

- Remove elevated permissions blocks from both jobs
- Add Create GitHub App Token step (actions/create-github-app-token v3)
- Replace secrets.GITHUB_TOKEN with steps.app-token.outputs.token
- Move curl auth to GH_TOKEN env var (avoids inline token interpolation)
- Update git committer name to pr-automation-bot-public[bot]
pull Bot pushed a commit to mikeyhodl/motoko that referenced this pull request May 5, 2026
…inelabs#6083)

## Summary

Pulls in the genuinely missing content surfaced by
[dfinity/icskills#183](dfinity/icskills#183) and
refines it during local review. Three skill files are touched; nothing
renamed, no frontmatter restructure, no reference-file split.

## What changes for agents

**`writing-motoko`**
- New section: `transient` field semantics — works on both `let` and
`var`, with `stable var` (M0218) warning.
- New section: M0220 explanation — what happens when
`--default-persistent-actors` isn't set.
- New **Pitfalls** section (2 items):
- M0141 declarations before actor body — recommends `types.mo`
extraction (consistent with the architecture pattern earlier in the
skill); shows a `whois` function example so there's no field-initializer
ambiguity.
- Always parenthesize variant tag arguments — written as a positive rule
rather than a precedence warning.
- New **Reserved Keywords** section listing all 53 reserved words,
sourced from `src/mo_frontend/source_lexer.mll`. Replaces the previous
single-keyword (`label`) note in the error table with a generalised
entry pointing here.
- Single consolidated heads-up under Critical Requirements that under
`--enhanced-migration`, actor fields cannot have initializers — declare
as `var x : T;` and set initial values in the first migration.
- Error-pattern table gains M0220, M0141, M0218 rows.

**`writing-motoko/examples.md`**
- Single heads-up at the top about the same field-initializer
constraint, so agents reading examples in isolation aren't surprised.

**`migrating-motoko-enhanced`**
- Bug fix: replaces the older `[canisters.backend].args =
["--enhanced-migration=migrations"]` pattern with the modern
`[canisters.backend.migrations]` block. This matches what the `mops-cli`
skill (in the mops repo) already recommends, and mops auto-injects
`--enhanced-migration` — adding it to args causes a mops error.

## What was deliberately not adopted from icskills#183

- **Skill rename** `writing-motoko` → `motoko`, **frontmatter
additions** (`license`, `compatibility`, `metadata.*`), **upstream-sync
comment blocks** — icskills catalog metadata, not relevant upstream.
- **Reference-file split**
(`references/{control-flow,type-conversions}.md`) — would be a larger
restructure than warranted.
- **`migrating-motoko` skill changes** — purely cosmetic in icskills
(rename of "Resources" → "References", added "What This Is").
- `Text.join` parameter order, `List.get` vs `List.at`, `do ? { }` for
`!`, M0145 incomplete-pattern pitfall — judged either belonging in
mo:core docs or obvious from the error message.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant