Skip to content

Commit a083a8e

Browse files
hyperpolymathclaude
andcommitted
docs: replace template placeholders with bespoke Nim metaprogramming content
All files now contain nimiser-specific documentation and type definitions rather than generic {{PROJECT}} placeholders: - README.adoc: Nim template/macro/generic pipeline, pragma-driven C export - ROADMAP.adoc: Phase 0-6 with Nim-specific milestones - TOPOLOGY.md: Module dependency graph and data flow - Idris2 ABI: NimTemplate, NimMacro, CompileTimeAST, CBackend, NimObject, NimGeneric types with Nim calling conventions and layout proofs - Layout.idr: Nim object layout rules ({.packed.}, {.exportc.}, {.align.}) - Foreign.idr: nimiser_compile, nimiser_gen_template, nimiser_gen_macro, nimiser_dump_ast, nimiser_nim_available FFI declarations - Zig FFI: All nimiser_* function implementations with Nim-specific types - Integration tests: Template/macro generation, Nim compiler detection - Machine-readable 6a2: Bespoke STATE, META, ECOSYSTEM, AGENTIC, NEUROSYM, PLAYBOOK with Nim metaprogramming context - 0-AI-MANIFEST.a2ml: Nimiser-specific structure and invariants Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ffe6b1c commit a083a8e

16 files changed

Lines changed: 1377 additions & 343 deletions

File tree

.machine_readable/6a2/AGENTIC.a2ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# SPDX-License-Identifier: PMPL-1.0-or-later
22
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
33
#
4-
# AGENTIC.a2ml — AI agent constraints and capabilities
4+
# AGENTIC.a2ml — AI agent constraints and capabilities for nimiser
55
# Defines what AI agents can and cannot do in this repository.
66

77
[metadata]
88
version = "0.1.0"
9-
last-updated = "{{CURRENT_DATE}}"
9+
last-updated = "2026-03-21"
1010

1111
[agent-permissions]
1212
can-edit-source = true
@@ -22,6 +22,17 @@ can-create-files = true
2222
# - Never use banned languages (TypeScript, Python, Go, etc.)
2323
# - Never place state files in repository root (must be in .machine_readable/)
2424
# - Never use AGPL license (use PMPL-1.0-or-later)
25+
# - Never expose Nim GC internals through the C ABI
26+
# - Never generate Nim code with {.importc.} unless importing from user's existing C code
27+
# - Never use Nim's `cast` or `unsafeAddr` in generated code
28+
29+
[nimiser-specific]
30+
# Nim codegen rules:
31+
# - All exported procs MUST have {.exportc, cdecl.} pragmas
32+
# - All exported types MUST have {.exportc.} pragma
33+
# - Use --gc:arc or --gc:orc for deterministic memory management
34+
# - Never generate code using Nim's default GC (refc) for library output
35+
# - Generated headers must be self-contained (no Nim runtime dependencies)
2536

2637
[maintenance-integrity]
2738
fail-closed = true

.machine_readable/6a2/ECOSYSTEM.a2ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
(version "0.1.0")
77
(name "nimiser")
88
(type "tool")
9-
(purpose "Generate high-performance C libraries via Nim metaprogramming")
9+
(purpose "Generate high-performance C libraries via Nim metaprogramming (templates, macros, generics -> optimised C)")
1010

1111
(position-in-ecosystem
1212
(family "-iser acceleration frameworks")
1313
(meta-framework "iseriser")
1414
(relationship "sibling")
15-
(top-3 ("typedqliser" "chapeliser" "verisimiser")))
15+
(top-3 ("typedqliser" "chapeliser" "verisimiser"))
16+
(unique-value "Nim's compile-time metaprogramming produces zero-overhead C libraries from high-level descriptions — templates for generic abstractions, macros for AST transforms, generics for type specialisation"))
1617

1718
(related-projects
1819
(project "iseriser"
@@ -35,4 +36,7 @@
3536
(description "Shared Idris2 verified library"))
3637
(project "typell"
3738
(relationship "dependency")
38-
(description "Type theory engine"))))
39+
(description "Type theory engine"))
40+
(project "nim-lang"
41+
(relationship "upstream-dependency")
42+
(description "Andreas Rumpf's Nim compiler — the target language whose metaprogramming nimiser exploits"))))

.machine_readable/6a2/META.a2ml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,55 @@
44

55
(meta
66
(version "0.1.0")
7-
(last-updated "2026-03-20")
7+
(last-updated "2026-03-21")
88

99
(architecture-decisions
1010
(adr "001-iser-pattern"
1111
(status "accepted")
12-
(context "Need to make powerful languages accessible without steep learning curves")
13-
(decision "Use manifest-driven code generation: user describes WHAT, tool generates HOW")
14-
(consequences "Users write zero target language code; all complexity in the -iser"))
12+
(context "Need to make Nim's powerful metaprogramming accessible without requiring users to learn Nim")
13+
(decision "Use manifest-driven code generation: user describes library interface in nimiser.toml, tool generates Nim templates/macros/generics that compile to optimised C")
14+
(consequences "Users write zero Nim code; all complexity in nimiser's codegen pipeline"))
1515

1616
(adr "002-abi-ffi-standard"
1717
(status "accepted")
18-
(context "Need verified interop between Rust CLI, target language, and user code")
19-
(decision "Idris2 ABI for formal proofs, Zig FFI for C-ABI bridge")
20-
(consequences "Compile-time correctness guarantees; zero runtime overhead from proofs"))
18+
(context "Need verified interop between Rust CLI, Nim-generated C library, and Zig FFI bridge")
19+
(decision "Idris2 ABI for formal proofs (NimTemplate, NimMacro, CompileTimeAST, CBackend types), Zig FFI for C-ABI bridge (nimiser_* functions)")
20+
(consequences "Compile-time correctness guarantees for the Nim-to-C ABI; zero runtime overhead from proofs"))
2121

22-
(adr "003-rsr-template"
22+
(adr "003-nim-metaprogramming-pipeline"
23+
(status "accepted")
24+
(context "Nim offers three compile-time metaprogramming mechanisms: templates, macros, and generics")
25+
(decision "Generate all three: templates for zero-cost abstractions, macros for AST-level transforms (loop unrolling, pragma injection), generics for monomorphised specialisation")
26+
(consequences "Maximum optimisation through compile-time code specialisation; output C code is as fast as hand-written"))
27+
28+
(adr "004-nim-c-backend"
29+
(status "accepted")
30+
(context "Nim can compile to C, C++, Objective-C, or JavaScript")
31+
(decision "Primary target is C backend (nim c --app:lib), with C++ and JS as secondary backends selectable via manifest")
32+
(consequences "Generated libraries are portable C with clean headers; no Nim runtime dependency in the output"))
33+
34+
(adr "005-rsr-template"
2335
(status "accepted")
2436
(context "Need consistent project structure across 29+ -iser repos")
2537
(decision "All repos cloned from rsr-template-repo with full CI/CD and governance")
2638
(consequences "17 workflows, SECURITY.md, CONTRIBUTING, bot directives from day one")))
2739

2840
(development-practices
29-
(language "Rust" (purpose "CLI and orchestration"))
30-
(language "Idris2" (purpose "ABI formal proofs"))
31-
(language "Zig" (purpose "FFI C-ABI bridge"))
32-
(build-tool "cargo")
41+
(language "Rust" (purpose "CLI orchestration, manifest parsing, codegen pipeline"))
42+
(language "Nim" (purpose "Generated target — templates, macros, generics compiled to C"))
43+
(language "Idris2" (purpose "ABI formal proofs for Nim type/layout/calling-convention correctness"))
44+
(language "Zig" (purpose "FFI C-ABI bridge between Rust CLI and Nim-generated libraries"))
45+
(build-tool "cargo" (purpose "Rust CLI"))
46+
(build-tool "nim c" (purpose "Nim -> C compilation of generated code"))
47+
(build-tool "zig build" (purpose "Zig FFI layer"))
3348
(ci "GitHub Actions (17 workflows)"))
3449

3550
(design-rationale
36-
(principle "Manifest-driven"
37-
(explanation "User intent captured in TOML; all generation is deterministic and reproducible"))
38-
(principle "Formally verified bridges"
39-
(explanation "Idris2 dependent types prove interface correctness at compile time"))
40-
(principle "Zero target language exposure"
41-
(explanation "Users never write Chapel/Julia/Futhark/etc. — the -iser handles everything"))))
51+
(principle "Nim templates for zero-cost abstractions"
52+
(explanation "Templates expand inline at compile time with no function-call overhead; ideal for buffer management, type adapters, and calling convention wrappers"))
53+
(principle "Nim macros for AST-level optimisation"
54+
(explanation "Macros rewrite the Nim AST before compilation, enabling loop unrolling, dead code elimination, and automatic {.exportc.} pragma injection"))
55+
(principle "Nim generics for type specialisation"
56+
(explanation "Generics are monomorphised at compile time, producing specialised code for each concrete type without runtime dispatch"))
57+
(principle "Formally verified C ABI"
58+
(explanation "Idris2 dependent types prove that generated Nim {.exportc.} structs match C struct layout expectations across platforms"))))

.machine_readable/6a2/NEUROSYM.a2ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
# SPDX-License-Identifier: PMPL-1.0-or-later
22
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
33
#
4-
# NEUROSYM.a2ml — Neurosymbolic integration metadata
4+
# NEUROSYM.a2ml — Neurosymbolic integration metadata for nimiser
55
# Configuration for Hypatia scanning and symbolic reasoning.
66

77
[metadata]
88
version = "0.1.0"
9-
last-updated = "{{CURRENT_DATE}}"
9+
last-updated = "2026-03-21"
1010

1111
[hypatia-config]
1212
scan-enabled = true
1313
scan-depth = "standard" # quick | standard | deep
1414
report-format = "logtalk"
1515

1616
[symbolic-rules]
17-
# Custom symbolic rules for this project
17+
# Custom symbolic rules for nimiser:
1818
# - { name = "no-unsafe-ffi", pattern = "believe_me|unsafeCoerce", severity = "critical" }
19+
# - { name = "no-nim-cast", pattern = "cast\\[", severity = "warning", context = "generated Nim code" }
20+
# - { name = "exportc-required", pattern = "proc.*\\*.*=", severity = "info", context = "exported procs must have {.exportc.}" }
21+
# - { name = "no-refc-gc", pattern = "--gc:refc", severity = "critical", context = "library output must use arc/orc" }
1922

2023
[neural-config]
2124
# Neural pattern detection settings
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
# SPDX-License-Identifier: PMPL-1.0-or-later
22
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
33
#
4-
# PLAYBOOK.a2ml — Operational playbook
4+
# PLAYBOOK.a2ml — Operational playbook for nimiser
55
# Runbooks, incident response, deployment procedures.
66

77
[metadata]
88
version = "0.1.0"
9-
last-updated = "{{CURRENT_DATE}}"
9+
last-updated = "2026-03-21"
1010

1111
[deployment]
12-
# method = "gitops" # gitops | manual | ci-triggered
13-
# target = "container" # container | binary | library | wasm
12+
method = "ci-triggered"
13+
target = "binary" # Rust CLI binary + generated Nim C libraries
14+
15+
[nim-compilation]
16+
# The nimiser pipeline:
17+
# 1. Rust CLI parses nimiser.toml manifest
18+
# 2. Codegen emits Nim source (templates, macros, generics)
19+
# 3. Nim compiler (nim c --app:lib --gc:arc) produces C library
20+
# 4. Zig FFI bridge links to the C library
21+
# 5. Output: .a/.so + .h ready for consumption
1422

1523
[incident-response]
16-
# 1. Check .machine_readable/STATE.a2ml for current status
24+
# 1. Check .machine_readable/6a2/STATE.a2ml for current status
1725
# 2. Review recent commits and CI results
1826
# 3. Run `just validate` to check compliance
1927
# 4. Run `just security` to audit for vulnerabilities
28+
# 5. If Nim compilation fails: check `nim --version`, verify PATH
2029

2130
[release-process]
22-
# 1. Update version in STATE.a2ml, META.a2ml, Justfile
31+
# 1. Update version in STATE.a2ml, META.a2ml, Cargo.toml, Justfile
2332
# 2. Run `just release-preflight` (validate + quality + security + maint-hard-pass)
2433
# 3. Optional local permission hardening: `just perms-snapshot && just perms-lock`
2534
# 4. Tag and push
@@ -33,3 +42,5 @@ last-updated = "{{CURRENT_DATE}}"
3342
# just maint-hard-pass
3443
# Permission audit:
3544
# just perms-audit
45+
# Nim compiler check:
46+
# nim --version

.machine_readable/6a2/STATE.a2ml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,33 @@
55
(state
66
(metadata
77
(version "0.1.0")
8-
(last-updated "2026-03-20")
8+
(last-updated "2026-03-21")
99
(author "Jonathan D.A. Jewell"))
1010

1111
(project-context
1212
(name "nimiser")
13-
(description "Generate high-performance C libraries via Nim metaprogramming")
13+
(description "Generate high-performance C libraries via Nim metaprogramming (templates, macros, generics)")
1414
(status "scaffold")
1515
(priority "—")
1616
(ecosystem "-iser family (https://github.com/hyperpolymath/iseriser)"))
1717

1818
(current-position
19-
(phase "initial-scaffold")
20-
(completion-percentage 5)
21-
(milestone "Architecture defined, CLI scaffolded, RSR template complete"))
19+
(phase "scaffold-complete")
20+
(completion-percentage 10)
21+
(milestone "Architecture defined, CLI scaffolded, Idris2 ABI types bespoke (NimTemplate, NimMacro, CompileTimeAST, CBackend), Zig FFI bridge stubbed with nimiser_* functions, RSR template complete"))
2222

2323
(route-to-mvp
24-
(step 1 "Replace codegen stubs with target-language-specific generation")
25-
(step 2 "Implement Idris2 ABI proofs for core invariants")
26-
(step 3 "Build Zig FFI bridge")
27-
(step 4 "Integration tests with real-world examples")
28-
(step 5 "Documentation and examples"))
24+
(step 1 "Implement Nim template generation: parse nimiser.toml -> emit Nim template source with {.exportc.} pragmas")
25+
(step 2 "Implement Nim macro generation: AST-level transforms for loop unrolling and specialisation")
26+
(step 3 "Implement Nim generic generation: monomorphised type-safe wrappers")
27+
(step 4 "Invoke Nim compiler: nim c --app:lib to produce .a/.so + .h from generated source")
28+
(step 5 "Wire Zig FFI bridge to call Nim-generated C library functions")
29+
(step 6 "End-to-end integration test: nimiser.toml -> Nim -> C library -> Zig -> consumer"))
2930

3031
(blockers-and-issues
31-
(none "Project is in scaffold phase — no blockers yet"))
32+
(none "Project is in scaffold phase — Idris2 ABI and Zig FFI stubs complete, codegen implementation pending"))
3233

3334
(critical-next-actions
34-
(action "Implement codegen for primary use case")
35-
(action "Write first working example end-to-end")))
35+
(action "Implement src/codegen/mod.rs to emit Nim template/macro/generic source code")
36+
(action "Write first nimiser.toml example that generates a working C buffer library")
37+
(action "Add Nim compiler detection and invocation in the Zig FFI layer")))

0-AI-MANIFEST.a2ml

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
# ⚠️ STOP - CRITICAL READING REQUIRED
1+
# SPDX-License-Identifier: PMPL-1.0-or-later
2+
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
3+
4+
# STOP - CRITICAL READING REQUIRED
25

36
**THIS FILE MUST BE READ FIRST BY ALL AI AGENTS**
47

58
## WHAT IS THIS?
69

7-
This is the AI manifest for **[YOUR-REPO-NAME]**. It declares:
10+
This is the AI manifest for **nimiser**. It declares:
811
- Canonical file locations (where things MUST be, and nowhere else)
912
- Critical invariants (rules that must NEVER be violated)
1013
- Repository structure and organization
1114

15+
Nimiser generates **high-performance C libraries** from high-level interface
16+
descriptions using Nim's compile-time metaprogramming system (templates,
17+
macros, generics). The user writes zero Nim code.
18+
1219
## CANONICAL LOCATIONS (UNIVERSAL RULE)
1320

1421
### Machine-Readable Metadata: `.machine_readable/` ONLY
@@ -80,42 +87,44 @@ Policy enforcement contracts (k9, dust, lust, must, trust).
8087
6. **Container images** - MUST use Chainguard base (`cgr.dev/chainguard/wolfi-base:latest` or `cgr.dev/chainguard/static:latest`)
8188
7. **Container runtime** - Podman, never Docker. Files are `Containerfile`, never `Dockerfile`
8289
8. **Container orchestration** - `selur-compose`, never `docker-compose`
90+
9. **Nim-specific** - Generated Nim code uses `{.exportc.}` for C ABI; never expose Nim GC internals
8391

8492
## REPOSITORY STRUCTURE
8593

8694
This repo follows the **Dual-Track** architecture:
8795

8896
```
89-
[YOUR-REPO-NAME]/
97+
nimiser/
9098
├── 0-AI-MANIFEST.a2ml # THIS FILE (start here)
91-
├── README.adoc # High-level orientation (Rich Human)
92-
├── ROADMAP.adoc # Future direction
99+
├── README.adoc # Nim metaprogramming pipeline overview
100+
├── ROADMAP.adoc # Phase 0-6 with Nim-specific milestones
101+
├── TOPOLOGY.md # Module dependency graph
93102
├── CONTRIBUTING.adoc # Human contribution guide
94-
├── GOVERNANCE.adoc # Decision-making model
95103
├── Justfile # Task runner
104+
├── Cargo.toml # Rust CLI build
96105
├── Containerfile # OCI build
97-
├── LICENSE # Primary license
106+
├── LICENSE # PMPL-1.0-or-later
98107
├── src/ # Source code
108+
│ ├── main.rs # CLI entry point
109+
│ ├── lib.rs # Library API
110+
│ ├── manifest/ # nimiser.toml parser
111+
│ ├── codegen/ # Nim template/macro/generic generation
112+
│ ├── abi/ # Rust-side ABI types
99113
│ └── interface/ # Verified Interface Seams
100-
│ ├── abi/ # Idris2 ABI (The Spec)
101-
│ ├── ffi/ # Zig FFI (The Bridge)
102-
│ └── generated/ # C Headers (The Result)
114+
│ ├── abi/ # Idris2 ABI (NimTemplate, NimMacro, CompileTimeAST, CBackend)
115+
│ ├── ffi/ # Zig FFI (nimiser_* C functions)
116+
│ └── generated/ # C Headers (auto-generated)
103117
├── container/ # Stapeln container ecosystem
104-
├── docs/ # Technical depths
105-
│ ├── attribution/ # Citations, owners, maintainers (adoc)
106-
│ ├── architecture/ # Topology, diagrams
107-
│ ├── theory/ # Domain theory
108-
│ └── practice/ # Manuals
109-
├── docs/legal/ # Legal exhibits and full texts
118+
├── docs/ # Technical documentation
110119
└── .machine_readable/ # ALL machine-readable metadata
111120
```
112121

113122
## SESSION STARTUP CHECKLIST
114123

115-
Read THIS file (0-AI-MANIFEST.a2ml) first
116-
Understand canonical location: `.machine_readable/`
117-
State understanding of canonical locations
124+
Read THIS file (0-AI-MANIFEST.a2ml) first
125+
Understand canonical location: `.machine_readable/`
126+
State understanding of canonical locations
118127

119128
## ATTESTATION PROOF
120129

121-
**"I have read the AI manifest. All machine-readable content (state files, anchors, policies, bot directives, contractiles, AI guides) is located in `.machine_readable/` ONLY, and community metadata is in `.github/`. I will not create duplicate files in the root directory."**
130+
**"I have read the AI manifest for nimiser. All machine-readable content (state files, anchors, policies, bot directives, contractiles, AI guides) is located in `.machine_readable/` ONLY, and community metadata is in `.github/`. I will not create duplicate files in the root directory."**

0 commit comments

Comments
 (0)