ontoref/reflection/templates/adopt_ontoref.nu.j2
Jesús Pérez 6721daf440
Some checks failed
Nickel Type Check / Nickel Type Checking (push) Has been cancelled
Rust CI / Security Audit (push) Has been cancelled
Rust CI / Check + Test + Lint (nightly) (push) Has been cancelled
Rust CI / Check + Test + Lint (stable) (push) Has been cancelled
feat: workflow layer model — NCL-first CI/build/distribution generator
Adds a declarative workflow system where .ontology/workflow.ncl declares
  independent layers (commit-fast, ci-standard, ci-exhaustive), each with a
  trigger and a set of providers. The generator materialises Woodpecker YAML,
  justfile recipes, and pre-commit hook stubs from that single declaration.

  Layers form a set, not a chain — no layer depends on another at the
  declaration level. Woodpecker steps express fine-grained parallelism
  internally (lint → test/docs/build).

  Schema and catalog:
  - reflection/schemas/workflow.ncl — types, contracts, provider constructors
  - reflection/defaults/workflow.ncl — standard Rust/Nushell/Nickel catalog
    (14 validations, 4 builds)

  Generator (ore workflow generate):
  - PreCommit: prints hook fragments for manual merge into .pre-commit-config.yaml
  - Woodpecker: writes per-layer YAML with image selection, tool installs,
    depends_on chains, and CI-aware command translation
    (nu --ide-check → find+xargs; markdownlint-cli2 → node:lts image)
  - Justfile: single justfiles/workflow.just aggregated from all Justfile layers
    (hoisted out of per-provider loop — was writing N times, now once)

  Dispatcher: ore workflow validate|list|generate|diff + ore wf v|l|gen|diff

  Cargo/nextest profiles:
  - .cargo/config.toml: [profile.ci-test] (debug=0, no-incremental) and
    [profile.ci] (line-tables-only) — shared by test + docs hooks to reuse
    .rlib artifacts; CI retains actionable backtraces
  - .config/nextest.toml: ci-test (fail-fast, no retries) and ci (all failures,
    one retry)

  Pre-commit: nextest run with --profile ci-test --cargo-profile ci-test;
  docs-links hook shares same profile to reuse artifacts

  Self-application: ontoref declares its own workflow in .ontology/workflow.ncl
  and the generated .woodpecker/ files are the authoritative CI definition

  Migration 0014: checks workflow.ncl + both cargo and nextest profiles present

  Adoption: reflection/templates/ontology/workflow.ncl stub + install_workflow
  confirm in adopt_ontoref form + step 5 in adoption script template
2026-04-08 14:20:38 +01:00

120 lines
4.7 KiB
Django/Jinja

#!/usr/bin/env nu
# Generated by: ontoref form reflection/forms/adopt_ontoref.ncl
# Onboards {{ project_name }} at {{ project_dir }} into the ontoref protocol.
# All steps are additive — existing files are NOT overwritten.
let project_name = "{{ project_name }}"
let project_dir = "{{ project_dir }}"
let ontoref_dir = "{{ ontoref_dir }}"
def print_skip [label: string] {
print $" skip ($label) \(already exists\)"
}
def print_ok [label: string] {
print $" ok ($label)"
}
def print_fail [label: string, reason: string] {
print $" FAIL ($label): ($reason)"
}
# ── 1. .ontoref/ directory structure ─────────────────────────────────────────
mkdir $"($project_dir)/.ontoref/logs"
mkdir $"($project_dir)/.ontoref/locks"
print_ok ".ontoref/logs and .ontoref/locks created"
# ── 2. .ontoref/config.ncl ────────────────────────────────────────────────────
{% if install_config %}
let config_dest = $"($project_dir)/.ontoref/config.ncl"
if ($config_dest | path exists) {
print_skip ".ontoref/config.ncl"
} else {
let config_src = $"($ontoref_dir)/templates/ontoref-config.ncl"
let content = open --raw $config_src | str replace --all "{{ project_name }}" $project_name
$content | save $config_dest
print_ok ".ontoref/config.ncl"
}
{% endif %}
# ── 3. .ontology/ stubs ───────────────────────────────────────────────────────
{% if install_ontology_stubs %}
mkdir $"($project_dir)/.ontology"
for stub in ["core.ncl", "state.ncl", "gate.ncl"] {
let dest = $"($project_dir)/.ontology/($stub)"
if ($dest | path exists) {
print_skip $".ontology/($stub)"
} else {
let src = $"($ontoref_dir)/templates/ontology/($stub)"
let content = open --raw $src | str replace --all "{{ project_name }}" $project_name
$content | save $dest
print_ok $".ontology/($stub)"
}
}
{% endif %}
# ── 4. scripts/ontoref wrapper ────────────────────────────────────────────────
{% if install_scripts_wrapper %}
mkdir $"($project_dir)/scripts"
let wrapper_dest = $"($project_dir)/scripts/ontoref"
if ($wrapper_dest | path exists) {
print_skip "scripts/ontoref"
} else {
let wrapper_src = $"($ontoref_dir)/templates/scripts-ontoref"
let content = open --raw $wrapper_src | str replace --all "{{ ontoref_dir }}" $ontoref_dir
$content | save $wrapper_dest
do { chmod +x $wrapper_dest } | complete | ignore
print_ok "scripts/ontoref (executable)"
}
{% endif %}
# ── 5. .ontology/workflow.ncl ────────────────────────────────────────────────
{% if install_workflow %}
let wf_dest = $"($project_dir)/.ontology/workflow.ncl"
if ($wf_dest | path exists) {
print_skip ".ontology/workflow.ncl"
} else {
let wf_src = $"($ontoref_dir)/templates/ontology/workflow.ncl"
$wf_src | open --raw | save $wf_dest
print_ok ".ontology/workflow.ncl (stub — edit layers, then: ore workflow generate)"
}
{% endif %}
# ── 6. Validate .ontology/ ────────────────────────────────────────────────────
{% if validate_after %}
print ""
print "Validating .ontology/ files..."
for stub in ["core.ncl", "state.ncl", "gate.ncl"] {
let file = $"($project_dir)/.ontology/($stub)"
if not ($file | path exists) {
print_skip $"validate .ontology/($stub) \(not installed\)"
continue
}
let result = do { ^nickel export $file } | complete
if $result.exit_code == 0 {
print_ok $"nickel export .ontology/($stub)"
} else {
print_fail $"nickel export .ontology/($stub)" $result.stderr
}
}
{% endif %}
# ── Summary ───────────────────────────────────────────────────────────────────
print ""
print $"Onboarding complete: ($project_name) at ($project_dir)"
print ""
print "Next steps:"
print " 1. Fill in .ontology/core.ncl — replace stub nodes with real invariants and tensions"
print " 2. Fill in .ontology/state.ncl — set current_state to where the project actually is"
print " 3. Review .ontoref/config.ncl — adjust log level, NATS settings if needed"
print $" 4. Add 'alias ontoref=\"./scripts/ontoref\"' to your shell profile"
print " 5. Run: ./scripts/ontoref describe project"