z-engine AGENTS.md

Repository instructions for working safely on z-engine, a PHP extension that uses FFI to access the PHP interpreter's internal memory structures.

In plain words
What is it for?
Use it when developing or testing z-engine to match the branch with its intended PHP version, follow its branch model, and regenerate engine definitions correctly.
Why use it?
PHP's internal structures can differ between minor versions, so using the wrong version can cause crashes or silent memory corruption.

Instructions file for CodexOpenCode

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/lisachenko/z-engine/agents-md
Clone the repo
git clone --depth 1 https://github.com/lisachenko/z-engine

Made for: Codex, OpenCode.

Per session 5,224 This file is loaded in full into every session.
When invoked 5,224 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.05224 $0.05224
Opus 5 $0.02612 $0.02612
Sonnet 5 $0.01045 $0.01045
Haiku 4.5 $0.00522 $0.00522

Measured 2d ago against content hash c16a48ded4fe, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

z-engine AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

AGENTS.md · 365 lines

How it starts

The opening of the file, as written. The whole thing — 365 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Working on z-engine

z-engine reaches into the Zend Engine's own memory through PHP FFI. That makes it uniquely powerful and uniquely fragile: a wrong struct offset or a call against the wrong PHP version does not throw — it corrupts memory and segfaults the interpreter. These rules exist to keep that from happening. They apply to human contributors and automated agents alike.

The one rule that is non-negotiable: version matching

Never run z-engine code or tests against a PHP minor version other than the one the current branch targets. The engine's C structures change between every minor version (zend_class_entry alone changed size in 8.1, 8.3 and 8.4). z-engine reads those structures by offset. Run it on a mismatched version and you are reading and writing the wrong memory — the result is a crash, or worse, silent corruption.

  • master targets the newest supported PHP minor (currently 8.5).
  • Branch 8.4 targets PHP 8.4.
  • Branch 8.0 is the frozen legacy line for PHP 8.0.

Core::init() enforces this at runtime and refuses to boot on the wrong minor. Do not try to defeat that guard.

Branch model

Fixes land on the minimum affected version branch and are merged upward, never cherry-picked downward. The succession is declared in .github/branch-flow.json and automated by .github/workflows/merge-up.yml, which opens a merge-up PR when a version branch is pushed.

8.0 (frozen)      8.4  ──►  master (8.5)

So a bug that exists in both 8.4 and 8.5 is fixed on 8.4, and the cascade carries it into master. A bug that only exists on 8.5 is fixed on master directly. When resolving a merge-up conflict inside include/, do not merge the generated headers textually — regenerate them on the target branch (composer gen-headers) instead.

Generated engine definitions — never hand-edit

Everything under include/<minor>/<os>-<arch>-<ts>/ is generated:

File What it is
engine.h FFI header (structs, functions, globals) sliced from the PHP source
constants.php #define/enum/opcode values, the ground truth for the PHP class constants
layouts.json sizeof/offsetof of every dereferenced struct, from the C compiler
probe.c the generated C probe (kept so a probe-only run can reuse it)

Read the full file on GitHub · 365 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 365 lines · 5,224 tokens per session scan A c16a48ded4fe

Subscribe to this mod's changes

z-engine AGENTS.md is an instructions file published in the GitHub repository lisachenko/z-engine (457 stars, last pushed 3d ago), licensed MIT. It adds 5,224 tokens to every session, about $0.0261 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.