agentleFS
z-libsz-libs/Zen-C/.github/copilot-instructions.md

Zen-C

Copilot instructions4.3k starsChanged 9 months agoMITView on GitHub

These instructions are MANDATORY for all code generation and review tasks in the Zen C project.

We split this copilot-instructions.md into the rules it gives an agent

18 rules. About 0 are common, 1 is distinctive, and 17 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 17

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do NOT attempt to free AST nodes or types.

    line 11
  2. Very specific:

    Creation: Use ast_create(NODE_TYPE) to allocate new nodes.

    line 15
  3. Very specific:

    Use Type struct (defined in src/ast/ast.h).

    line 17
  4. Distinctive:

    Do NOT introduce Visitor patterns or callback tables unless consistent with existing code.

    line 22
  5. Very specific:

    Use expect(lexer, TOKEN_TYPE, "error message") for mandatory tokens.

    line 28
  6. Very specific:

    Every error path that returns NULL/an error node must already have emitted a diagnostic.

    line 35
  7. Very specific:

    Symbol Mangling: use the canonical mangle_method_symbol(base, trait, method) (see docs/CONTRIBUTING for the rule).

    line 36
  8. Very specific:

    Fallback: If the mangled struct (e.g.

    line 41
  9. Very specific:

    Use emit_func_signature(ctx, out, node, override_name) to handle modifiers, return types, and arguments correctly.

    line 44
  10. Very specific:

    Output: Use fprintf(out, ...) where out is the FILE*.

    line 45
  11. Very specific:

    When implementing iteration in compiler (C code): Use while (node) { ...

    line 58
  12. Very specific:

    Arrays: Use for val in arr syntax (direct iteration).

    line 61
  13. Very specific:

    Defer: Use defer stmt; to run cleanup at scope exit.

    line 76
  14. Very specific:

    Iteration: Use for val in arr (direct iteration supported).

    line 79
  15. Very specific:

    Use async fn and await keyword.

    line 84
  16. Very specific:

    Import with import "std/io.zc", import "std/vec.zc".

    line 87
  17. Very specific:

    Use println "msg" (shorthand) or printf.

    line 88
  18. Very specific:

    Use test "name" { ... } blocks for unit tests.

    line 90

≈ “Common” is an estimate: at least 1 in 5 of the 3,669 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

Zen C Copilot Instructions

These instructions are MANDATORY for all code generation and review tasks in the Zen C project.

1. Memory Management (Critical)

  • Arena Allocation: The compiler uses a bump-pointer arena allocator.
    • MUST USE: xmalloc, xcalloc, xrealloc, xstrdup (defined in src/utils/utils.c).
    • NEVER USE: Standard malloc, calloc, free (unless interfacing with an external library that strictly requires owned heap memory, like CJSON).
  • Destructors/Freeing:
    • free(ptr) is #defined to ((void)0) in src/zprep.h. It is a no-op.
    • Do NOT attempt to free AST nodes or types. ast_free is a no-op.
    • Memory is reclaimed only when the process exits. Design your data structures accordingly (append-only is fine).

2. AST and Type System

  • Creation: Use ast_create(NODE_TYPE) to allocate new nodes.
  • Type Representation:
    • Use Type struct (defined in src/ast/ast.h).
    • Use type_new(TYPE_KIND) helper.
    • type_to_string(t) and type_to_c_string(t) return arena-allocated strings. Do not worry about freeing them.
  • Traversal:
    • The compiler uses Recursive Descent with Switch Statements on node->kind.
    • Do NOT introduce Visitor patterns or callback tables unless consistent with existing code.

3. Parser Patterns

  • Context: ParserContext *ctx is the god-object. It MUST be passed to almost every function in parsing, analysis, and codegen.
    • Signature Rule: ReturnType func_name(ParserContext *ctx, ...)
  • Token Consumption:
    • Use expect(lexer, TOKEN_TYPE, "error message") for mandatory tokens.
    • For optional tokens, check l->token.kind and assume lexer_next(l) is used to advance (verify specific helper availability).
  • Error Handling:
    • Fatal / syntax: zpanic_at(token, "…"). Exits immediately (or delegates to the LSP handler in fault-tolerant mode). "Expected …" errors use this.
    • Warning: zwarn_at(token, "…").
    • Recoverable (parser): zerror_at(token, "…") — only for conditions parsing can proceed past (e.g. MISRA guidance), not malformed syntax.
    • Semantic (typechecker): tc_error(tc, token, "…").
    • Every error path that returns NULL/an error node must already have emitted a diagnostic.
  • Symbol Mangling: use the canonical mangle_method_symbol(base, trait, method) (see docs/CONTRIBUTING for the rule); never re-implement %s__%s+merge_underscores inline.

4. Code Generation (C Backend)

  • Generic Mangling:
    • Generic structs (e.g., Slice<int>) are mangled to Slice_int IF AND ONLY IF the instantiated struct exists (checked via find_struct_def_codegen).
    • Fallback: If the mangled struct (e.g. Async_int) does not exist, use the base name (Async). This handles opaque types like Async<T> correctly.
    • See emit_c_decl in src/codegen/codegen_utils.c for the canonical implementation.
  • Function Signatures:
    • Use emit_func_signature(ctx, out, node, override_name) to handle modifiers, return types, and arguments correctly.
  • Output: Use fprintf(out, ...) where out is the FILE*.

5. Coding Style & Conventions

  • Formatting:
    • Indentation: 4 spaces.
    • Braces: ALWAYS Use braces {} for control flow (if, while, for), even for single lines.
    • Opening brace on the NEXT line (Allman style).
  • Naming:
    • Structs/Enums: PascalCase.
    • Functions/Variables: snake_case.
    • Macros/Constants: SCREAMING_SNAKE_CASE.
    • Private/Static: No strict prefix, but static keyword is mandatory for internal file-scope functions.
  • Iterators:
    • When implementing iteration in compiler (C code): Use while (node) { ... node = node->next; } for linked lists (ASTNode, StructRef).

6. Standard Library (Zen C Definitions)

  • Arrays: Use for val in arr syntax (direct iteration).
  • Vectors: Vec<T> is a dynamic array.
  • Strings: string in Zen C maps to char* in C. kstring or zstr are higher-level wrappers.

7. Common Pitfalls

  • Unused Variables: The compiler builds with -Wall -Werror (or similar strictness). Cast unused vars to void: (void)var_name;.

8. Zen C Language Rules (For writing .zc files)

  • Syntax:
    • Variables: let x = 10;, let y: const int = 20;.
    • Constants: def MAX = 100; (compile-time).
    • Functions: fn name(arg: type) -> ret { ... }.
    • Structs: struct Point { x: int; y: int; }.
    • Enums: enum Shape { Circle(float), Rect(float, float) }.
  • Memory & Resources:
    • Move Semantics: Structs/Enums are moved by default on assignment/pass-by-value.
    • Defer: Use defer stmt; to run cleanup at scope exit.
    • Drop: Implement impl Drop for T for RAII.
  • Arrays & Slices:
    • Iteration: Use for val in arr (direct iteration supported).
    • Slices: Slice<T> is a view. int[N] auto-converts to slice in loops.
  • Generics:
    • Syntax: struct Box<T> { val: T; }.
  • Concurrency:
    • Use async fn and await keyword.
    • Async<T> is the opaque future type.
  • Standard Library:
    • Import with import "std/io.zc", import "std/vec.zc".
    • Use println "msg" (shorthand) or printf.
  • Testing:
    • Use test "name" { ... } blocks for unit tests.

Download now (ZIP)

Trending

Quiet since March.about the whole repository

Dec 2025: 0 mentionsJan 2026: 14 mentionsFeb 2026: 9 mentionsMar 2026: 8 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the z-libs/Zen-C repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about z-libs/Zen-C

The biggest 5 of 31 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 31

Talked about on GitHub, Bluesky and Hacker News (31 times).

On GitHub · 23

18 more on GitHub

On Bluesky · 7

2 more on Bluesky

On Hacker News · 1

  • Other versions1 project uses a version of this.

    Word for word · 1

    1. zenc-lang/zenc★ 4.3k100% same

    Edited · 0

    None found.

    Wrote their own version · 0

    None found.

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • Where files are headingNew Copilot instructions files have more rules about branches and pull requests, and fewer about code style.

    Of the Copilot instructions files we read, the 2,297 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.