diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 56be208c..e82705fc 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -44,7 +44,7 @@ which is precisely why the map is now generated rather than typed. **When reporting**: -Use the [bug report template](.github/ISSUE_TEMPLATE/bug_report.md) and include: +Use the [bug report template](ISSUE_TEMPLATE/bug_report.yml) and include: - Clear, descriptive title - Environment details (OS, versions, toolchain) @@ -61,7 +61,7 @@ Use the [bug report template](.github/ISSUE_TEMPLATE/bug_report.md) and include: **When suggesting**: -Use the [feature request template](.github/ISSUE_TEMPLATE/feature_request.md) and include: +Use the [feature request template](ISSUE_TEMPLATE/feature_request.yml) and include: - Problem statement (what pain point does this solve?) - Proposed solution diff --git a/.github/workflows/dogfood-gate.yml b/.github/workflows/dogfood-gate.yml index 1db90e56..2bd55129 100644 --- a/.github/workflows/dogfood-gate.yml +++ b/.github/workflows/dogfood-gate.yml @@ -587,12 +587,14 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: hyperpolymath/hypatia - ref: be98f74ce93df200752f3798efa1305bfa3e0e10 + # Pinned to a Hypatia commit that contains hypatia#1062 (the PinSites miscompile + # fix, merged as 37b8d01). The earlier pin be98f74 lacks it. + ref: 51539abf3d2472b955da9b051a68c5971f6cfa22 path: _hypatia persist-credentials: false # OTP 28.x (28.1 to 28.5.0.8) crashes this step with SIGSEGV in # sweep_off_heap, called from the JIT's bs_init_bits, on trees whose - # workflow content trips it (Apodeixis.jl#333). OTP 27.3 scored all + # workflow content trips it (rsr-template-repo#333). OTP 27.3 scored all # of them cleanly. Do not move to 28.x until a pinned 28.x build scores # the #333 trees (af8665c, a55669e, 6ad5378) with no crash. - name: Setup Elixir 1.19.4 / OTP 27.3.4.19 for Hypatia oracle @@ -608,7 +610,7 @@ jobs: _hypatia/_build ~/.hex ~/.mix - key: hypatia-oracle-${{ runner.os }}-otp27.3.4.19-elx1194-be98f74ce93df200752f3798efa1305bfa3e0e10 + key: hypatia-oracle-${{ runner.os }}-otp27.3.4.19-elx1194-51539abf3d2472b955da9b051a68c5971f6cfa22 - name: Compile the oracle working-directory: _hypatia run: mix local.hex --force && mix local.rebar --force && mix deps.get && mix compile diff --git a/Apodeixis.jl_chora.deed b/Apodeixis.jl_chora.deed index b6d0338d..2a1e09bd 100644 --- a/Apodeixis.jl_chora.deed +++ b/Apodeixis.jl_chora.deed @@ -225,7 +225,9 @@ (directory :id "automation-unit-forge" :ply 3 :path ".machine_readable/scripts/forge" :description "Internal automation logic for project forge.") (directory :id "automation-unit-lifecycle" :ply 3 :path ".machine_readable/scripts/lifecycle" :description "Internal automation logic for project lifecycle.") (directory :id "automation-unit-verification" :ply 3 :path ".machine_readable/scripts/verification" :description "Internal automation logic for project verification."))) - (directory :id "container-templates" :ply 1 :path "build/container" :version "1.0.0" :description "Container templates for the stapeln container ecosystem. This directory\nprovides Podman-Chainguard-stapeln templates that are customised via\n`just container-init` or `just repo-init` during project bootstrap.\n\nAll files use {{PLACEHOLDER}} tokens that are substituted with project-\nspecific values during initialisation." :purpose "Provide a complete, security-first container deployment story for any\nRSR-compliant repository. The templates cover the full lifecycle:\nbuild, sign, verify, deploy, monitor, and govern." :overview "The stapeln container ecosystem comprises six tools:\n\nselur — Container orchestration with zero-copy IPC. Reads compose.toml.\ncerro-torre — Verified container packaging (.ctp bundles), Ed25519 signing.\nsvalinn — Policy-driven edge gateway (auth, rate limits, CORS, trust).\nvordr — Runtime monitoring (health, crashes, resources, logs).\nrokur — Secrets management (runtime injection, no baked secrets).\nk9-svc — Nickel deployment components (Kennel/Yard/Hunt trust levels)." + (directory :id "container-templates" :ply 1 :path "build/container" :version "1.0.0" :description "Container templates for the stapeln container ecosystem. This directory\nprovides Podman-Chainguard-stapeln templates that are customised via\n`just container-init` or `just repo-init` during project bootstrap.\n\nAll files use {{PLACEHOLDER}} tokens that are substituted with project-\nspecific values during initialisation." + :purpose "Provide a complete, security-first container deployment story for any\nRSR-compliant repository. The templates cover the full lifecycle:\nbuild, sign, verify, deploy, monitor, and govern." + :overview "The stapeln container ecosystem comprises six tools:\n\nselur — Container orchestration with zero-copy IPC. Reads compose.toml.\ncerro-torre — Verified container packaging (.ctp bundles), Ed25519 signing.\nsvalinn — Policy-driven edge gateway (auth, rate limits, CORS, trust).\nvordr — Runtime monitoring (health, crashes, resources, logs).\nrokur — Secrets management (runtime injection, no baked secrets).\nk9-svc — Nickel deployment components (Kennel/Yard/Hunt trust levels)." :context ("https://stapeln.dev/ns/v1") (canonical-locations :build_pipeline "build/container/stapeln/ct-build.sh" :compose "build/container/stapeln/compose.toml" :compose_example "build/container/stapeln/compose.example.toml" :compose_portable "build/container/compose.yaml" :compose_portable_example "build/container/compose.example.yaml" :containerfile "build/container/Containerfile" :containerignore "build/container/.containerignore" :deployment "build/container/stapeln/deploy.k9.ncl" :entrypoint "build/container/entrypoint.sh" :gatekeeper "build/container/stapeln/.gatekeeper.yaml" :just_module "build/just/container.just" :manifest "build/container/stapeln/manifest.toml" :monitoring "build/container/stapeln/vordr.toml" :secrets_gate "build/container/stapeln/rokur.toml") :invariants ("Base images MUST be cgr.dev/chainguard/wolfi-base or cgr.dev/chainguard/static" "Container runtime is Podman — never Docker" "Containerfile — never Dockerfile" "All images run as non-root (appuser or project-specific user)" ".ctp bundles are signed with Ed25519 via cerro-torre" "Health endpoints (/health, /ready) must always be public (no auth)") diff --git a/LICENSE.adoc b/LICENSE.adoc new file mode 100644 index 00000000..af089d45 --- /dev/null +++ b/LICENSE.adoc @@ -0,0 +1,2 @@ +SPDX-License-Identifier: MPL-2.0 AND CC-BY-SA-4.0 +Code: MPL-2.0. Prose: CC-BY-SA-4.0. diff --git a/build/container/Containerfile b/build/container/Containerfile deleted file mode 100644 index 691ec193..00000000 --- a/build/container/Containerfile +++ /dev/null @@ -1,152 +0,0 @@ -# SPDX-License-Identifier: MPL-2.0 -# Apodeixis.jl Container Image -# -# Multi-stage build template for Chainguard Wolfi base images. -# Customise the builder stage for your language and copy the -# resulting binary/release into the minimal runtime stage. -# -# This is the Tier-A artifact: a plain OCI image, buildable by ANY -# OCI-compliant engine — podman (recommended), nerdctl, or docker. -# It carries no hard dependency on the stapeln tier; the cerro-torre / -# svalinn files under build/container/stapeln/ are referenced only as labels. -# -# Build (engine-agnostic — substitute podman | nerdctl | docker): -# podman build -t apodeixis.jl:latest -f build/container/Containerfile . -# -# Run: -# podman run -p 8080:8080 apodeixis.jl:latest -# -# Run with persistent volume: -# podman run -p 8080:8080 -v apodeixis.jl-data:/data apodeixis.jl:latest -# -# Via the Justfile (auto-detects engine, prefers cerro-torre when present): -# just container-build - -# ============================================================================ -# Stage 1: Builder -# ============================================================================ -# -# Install build tools and compile the application. -# This stage is discarded after the build — only the compiled output -# is copied into the runtime stage. -# -# Language-specific examples (uncomment the one you need): -# -# --- Rust --- -# RUN apk add --no-cache rust pkgconf build-base -# COPY Cargo.toml Cargo.lock ./ -# COPY src/ ./src/ -# RUN cargo build --release -# # Output: /build/target/release/apodeixis.jl -# -# --- Elixir --- -# RUN apk add --no-cache erl27-elixir-1.18 erlang-27 erlang-27-dev git build-base -# COPY mix.exs mix.lock ./ -# COPY lib/ ./lib/ -# COPY config/ ./config/ -# ENV MIX_ENV=prod -# RUN mix local.hex --force && mix local.rebar --force && \ -# mix deps.get --only prod && mix compile && mix release -# # Output: /build/_build/prod/rel/apodeixis.jl/ -# -# --- Zig --- -# RUN apk add --no-cache zig build-base -# COPY build.zig build.zig.zon ./ -# COPY src/ ./src/ -# RUN zig build -Doptimize=ReleaseFast -# # Output: /build/zig-out/bin/apodeixis.jl -# -# Base image: `:latest` is right for a template scaffold (Chainguard rebuilds -# Wolfi daily). For PRODUCTION builds, pin by digest for reproducibility/supply- -# chain integrity, e.g.: -# FROM cgr.dev/chainguard/wolfi-base:latest@sha256: AS builder -# (cerro-torre's .ctp signing in build/container/stapeln/ records the resolved digest.) -FROM cgr.dev/chainguard/wolfi-base:latest AS builder - -# TODO: Install your language toolchain -RUN apk add --no-cache build-base - -WORKDIR /build - -# TODO: Copy source files and build -COPY . . -# RUN - -# ============================================================================ -# Stage 2: Runtime -# ============================================================================ -# -# Minimal production image. Only the compiled binary/release and runtime -# dependencies are included. No compilers, no source code, no build tools. -# -FROM cgr.dev/chainguard/wolfi-base:latest - -# OCI image labels (compatible with cerro-torre .ctp bundle metadata) -LABEL org.opencontainers.image.title="Apodeixis.jl" \ - org.opencontainers.image.description="Research-stage Julia verification toolchain for contracts, compiler analysis, numeric semantics, and verified FFI with independently checked proof targets." \ - org.opencontainers.image.url="https://github.com/hyperpolymath/Apodeixis.jl" \ - org.opencontainers.image.source="https://github.com/hyperpolymath/Apodeixis.jl" \ - org.opencontainers.image.vendor="hyperpolymath" \ - org.opencontainers.image.licenses="MPL-2.0" \ - org.opencontainers.image.authors="Jonathan D.A. Jewell " \ - dev.cerrotorre.manifest="build/container/stapeln/manifest.toml" \ - dev.cerrotorre.gatekeeper="build/container/stapeln/.gatekeeper.yaml" \ - dev.stapeln.compose="build/container/stapeln/compose.toml" - -# Install minimal runtime dependencies. -# Adjust this list for your application: -# - ca-certificates: TLS root certificates -# - curl: health check probe -# - libstdc++: C++ standard library (if needed by native deps) -# - ncurses: terminal UI (if needed, e.g. Elixir IEx) -RUN apk add --no-cache ca-certificates curl - -# Create non-root user for the application. -# Running as root inside containers is a security anti-pattern. -RUN addgroup -S appuser && adduser -S appuser -G appuser - -WORKDIR /app - -# TODO: Copy compiled binary/release from builder stage. -# Examples: -# COPY --from=builder /build/target/release/apodeixis.jl /app/apodeixis.jl -# COPY --from=builder /build/_build/prod/rel/apodeixis.jl /app/release/ -# COPY --from=builder /build/zig-out/bin/apodeixis.jl /app/apodeixis.jl - -# Copy entrypoint script -COPY build/container/entrypoint.sh /app/entrypoint.sh -RUN chmod +x /app/entrypoint.sh - -# OPTIONAL (Tier C — stapeln). A pure OCI image does NOT need these baked in: -# svalinn reads .gatekeeper.yaml from a mounted volume (see stapeln/compose.toml), -# and cerro-torre reads manifest.toml at pack time. Uncomment only if you want -# the policy/manifest embedded in the image itself. -# COPY build/container/stapeln/.gatekeeper.yaml /etc/svalinn/gatekeeper.yaml -# COPY build/container/stapeln/manifest.toml /app/manifest.toml - -# Create data directory for persistent storage (mountable volume) -RUN mkdir -p /data && chown appuser:appuser /data - -# Set ownership of the application directory -RUN chown -R appuser:appuser /app - -# Environment variables — customise for your application -ENV APP_HOST=[::] -ENV APP_PORT=8080 -ENV APP_LOG_FORMAT=json -ENV APP_DATA_DIR=/data - -# Declare /data as a volume for persistent storage -VOLUME ["/data"] - -# Run as non-root -USER appuser - -# Expose the application port -EXPOSE 8080 - -# Health check — the application must respond 2xx at /health -HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ - CMD curl -sf http://localhost:${APP_PORT}/health || exit 1 - -ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/docs/architecture/REPOSITORY-MAP.adoc b/docs/architecture/REPOSITORY-MAP.adoc index 90b9fbd7..f8bab496 100644 --- a/docs/architecture/REPOSITORY-MAP.adoc +++ b/docs/architecture/REPOSITORY-MAP.adoc @@ -113,6 +113,10 @@ predecessors did. | optional | forge-facing copy of LICENSES/MPL-2.0.txt. Optional, not required: +| `LICENSE.adoc` +| yes +| the licence (MPL-2.0); renamed from LICENSE to the estate AsciiDoc format 2026-10-26 + | `LICENSES/` | yes | REUSE licence texts, dual-licence model (code MPL-2.0 / docs CC-BY-SA-4.0) diff --git a/docs/troubleshooting.adoc b/docs/troubleshooting.adoc index 402fdffe..27abf651 100644 --- a/docs/troubleshooting.adoc +++ b/docs/troubleshooting.adoc @@ -48,7 +48,7 @@ just log-tail # last N lines of logs and the symptom in plain English. . Linked from the issue: the relevant ADR(s) and any related issues. . For *security*-relevant findings, see - link:./../SECURITY.md[SECURITY.md] — do **not** file public issues. + link:./../.github/SECURITY.md[SECURITY.md] — do **not** file public issues. == Where to look for more help diff --git a/src/interface/ffi/src/main.zig b/src/interface/ffi/src/main.zig index 6f4db637..9b8177d6 100644 --- a/src/interface/ffi/src/main.zig +++ b/src/interface/ffi/src/main.zig @@ -25,6 +25,16 @@ fn clearError() void { last_error = null; } +/// Duplicate a byte slice as a NUL-terminated buffer across Zig 0.15/0.16/0.17 +/// (`Allocator.dupeZ` was removed in Zig 0.17). +/// The caller owns the returned slice and must free it with `allocator`. +/// Propagates allocation failure. +fn dupeZ(allocator: std.mem.Allocator, bytes: []const u8) ![:0]u8 { + const buf = try allocator.allocSentinel(u8, bytes.len, 0); + @memcpy(buf[0..bytes.len], bytes); + return buf; +} + //============================================================================== // Core Types (must match src/abi/Types.idr) //============================================================================== @@ -110,7 +120,9 @@ export fn apodeixis_jl_process(handle: ?*Handle, input: u32) Result { //============================================================================== /// Get a string result (example) -/// Caller must free the returned string +/// Return a NUL-terminated "Example result" owned by the caller; free it with +/// `apodeixis_jl_free_string`. Return null and set the thread-local error for a +/// null or uninitialized handle, or allocation failure. Clear the error on success. export fn apodeixis_jl_get_string(handle: ?*Handle) ?[*:0]const u8 { const h = handle orelse { setError("Null handle"); @@ -123,7 +135,7 @@ export fn apodeixis_jl_get_string(handle: ?*Handle) ?[*:0]const u8 { } // Example: allocate and return a string - const result = h.allocator.dupeZ(u8, "Example result") catch { + const result = dupeZ(h.allocator, "Example result") catch { setError("Failed to allocate string"); return null; }; @@ -180,14 +192,15 @@ export fn apodeixis_jl_process_array( // Error Handling //============================================================================== -/// Get the last error message -/// Returns null if no error +/// Get the last error message. +/// Return an allocated NUL-terminated copy of the current thread's error, or +/// null if no error is set or allocation fails. Leave the stored error unchanged. +/// Caller must free a non-null returned string with `apodeixis_jl_free_string`. export fn apodeixis_jl_last_error() ?[*:0]const u8 { const err = last_error orelse return null; - // Return C string (static storage, no need to free) const allocator = std.heap.c_allocator; - const c_str = allocator.dupeZ(u8, err) catch return null; + const c_str = dupeZ(allocator, err) catch return null; return c_str.ptr; } @@ -258,6 +271,10 @@ test "lifecycle" { defer apodeixis_jl_free(handle); try std.testing.expect(apodeixis_jl_is_initialized(handle) == 1); + + const str = apodeixis_jl_get_string(handle) orelse return error.StringFailed; + defer apodeixis_jl_free_string(str); + try std.testing.expectEqualStrings("Example result", std.mem.span(str)); } test "error handling" { @@ -265,6 +282,7 @@ test "error handling" { try std.testing.expectEqual(Result.null_pointer, result); const err = apodeixis_jl_last_error(); + defer apodeixis_jl_free_string(err); try std.testing.expect(err != null); }