Skip to the content.

Repository Documentation Standards (Human & Agent Co-Optimized)

To keep this codebase manageable for both human software engineers and AI coding agents (such as LLMs), the documentation follows a strict modular, JIT-retrieved, and structured layout model.


1. Modularization over Monoliths

A massive documentation file is hard for humans to scan and extremely expensive for AI agents to load. A 200KB markdown file consumes upwards of 50,000 context tokens, causing “lost in the middle” context degradation where agents ignore critical details.

Standard:


2. YAML Frontmatter (Metadata Schema) for Design Docs

To allow AI agents to map target files to design rules in microseconds without parsing full pages of prose, all design and roadmap documents should contain a YAML frontmatter header.

Frontmatter Schema:

---
title: "Title of the Document"
scope: "enforcer | profiler | ffi | cicd"
critical_syscalls: ["sys_a", "sys_b"]
target_files: ["path/to/affected/File.kt"]
keywords: ["key1", "key2"]
---

Agent Integration:

Before modifying a system component, an agent can perform a high-speed grep search (e.g. grep_search looking for target_files or scope: "enforcer") to discover which files contain the relevant design constraints, loading them only when needed.


3. Just-In-Time (JIT) Context Loading (.agents/)

The workspace .agents/ directory is the entry point for AI agent rules. Placing raw design details or backlog logs inside the global .agents/AGENTS.md leads to prompt bloat and dilutes compiler guidelines.

Standard:


4. Architecture-as-Code (Interactive Knowledge Graph)

To maintain a clear relationship graph of how JVM code coordinates with native systems, the repository maintains an interactive component map at designs/core/architectural-map.md.

Standard:


5. File Structure Inspection Tool

To avoid reading hundreds of lines of code just to understand the API surface or method layout of a source file, the repository provides a lightweight outline/structure tool.

Usage:

Run the Kotlin script passing the path to any file:

# Kotlin files: outlines classes, objects, functions, properties
kotlin scripts/file_structure.main.kts enforcer/src/main/kotlin/io/mazewall/enforcer/ContainedExecutors.kt

# Markdown: outlines heading hierarchy
kotlin scripts/file_structure.main.kts docs/internals/designs/enforcer/containment-design.md

# YAML/YML: outlines top-level and second-level keys
kotlin scripts/file_structure.main.kts .github/workflows/ci.yml

# XML: outlines top-level element tags
kotlin scripts/file_structure.main.kts config/seccomp-profile.xml

# JSON: outlines top-level keys
kotlin scripts/file_structure.main.kts sbob.json

This returns a clean, hierarchical tree allowing both human developers and agents to immediately grasp the file’s structure without reading its full contents.


6. Code-to-Docs Back-Reference Convention (@ref)

To create bidirectional navigation between source code and design documents, critical code sites should include structured @ref comments. This allows agents and developers to jump directly from a function to the authoritative design document — without having to search.

Standard Format:

// @ref: docs/internals/designs/enforcer/containment-design.md — Description of what the link covers
// @issue: docs/internals/backlog/issue-042-tsync-race.md — Known issue affecting this code

Rules:

Example:

// @ref: docs/internals/designs/enforcer/containment-design.md — BPF linear scan and 8-bit jump limit
// @ref: docs/internals/research/jvm-syscall-floor-research.md — JVM floor syscall requirements
internal fun installFilter(arch: Arch, prog: MemorySegment, useTsync: Boolean) {
    ...
}