ontoref/reflection/modes/adopt_ontoref.ncl

120 lines
5.1 KiB
Plaintext
Raw Normal View History

2026-03-13 00:21:04 +00:00
let s = import "../schema.ncl" in
# Mode: adopt_ontoref
# Onboards an EXISTING project into the ontoref protocol.
# Creates missing pieces without overwriting existing files.
#
# Required params (substituted in cmd via {param}):
# {project_name} — identifier for this project (kebab-case)
# {project_dir} — absolute path to the existing project root
# {ontoref_dir} — absolute path to the ontoref checkout
{
id = "adopt_ontoref",
trigger = "Onboard an existing project into the ontoref protocol",
preconditions = [
"{project_dir} exists and is a directory",
"nickel is available in PATH",
"nu is available in PATH (>= 0.110.0)",
"{ontoref_dir}/templates/ontology/ exists (contains core.ncl, state.ncl, gate.ncl stubs)",
"{ontoref_dir}/templates/ontoref-config.ncl exists",
"{ontoref_dir}/templates/scripts-ontoref exists",
],
steps = [
{
id = "create_ontoref_dir",
action = "create_config_directory",
actor = 'Agent,
cmd = "mkdir -p {project_dir}/.ontoref/logs {project_dir}/.ontoref/locks",
depends_on = [],
on_error = { strategy = 'Stop },
note = "Creates .ontoref/ directory structure. mkdir -p is idempotent.",
},
{
id = "copy_ontoref_config",
action = "copy_config_template",
actor = 'Agent,
cmd = "test -f {project_dir}/.ontoref/config.ncl || sed 's/{{ project_name }}/{project_name}/g' {ontoref_dir}/templates/ontoref-config.ncl > {project_dir}/.ontoref/config.ncl",
depends_on = [{ step = "create_ontoref_dir", kind = 'OnSuccess }],
on_error = { strategy = 'Stop },
note = "Copies config template only if .ontoref/config.ncl does not already exist.",
},
{
id = "create_ontology_dir",
action = "create_ontology_directory",
actor = 'Agent,
cmd = "mkdir -p {project_dir}/.ontology",
depends_on = [{ step = "create_ontoref_dir", kind = 'OnSuccess }],
on_error = { strategy = 'Stop },
note = "Creates .ontology/ directory. Idempotent.",
},
{
id = "copy_ontology_core",
action = "copy_ontology_core_stub",
actor = 'Agent,
cmd = "test -f {project_dir}/.ontology/core.ncl || sed 's/{{ project_name }}/{project_name}/g' {ontoref_dir}/templates/ontology/core.ncl > {project_dir}/.ontology/core.ncl",
depends_on = [{ step = "create_ontology_dir", kind = 'OnSuccess }],
on_error = { strategy = 'Stop },
note = "Copies core.ncl stub. Skipped if file already exists.",
},
{
id = "copy_ontology_state",
action = "copy_ontology_state_stub",
actor = 'Agent,
cmd = "test -f {project_dir}/.ontology/state.ncl || sed 's/{{ project_name }}/{project_name}/g' {ontoref_dir}/templates/ontology/state.ncl > {project_dir}/.ontology/state.ncl",
depends_on = [{ step = "create_ontology_dir", kind = 'OnSuccess }],
on_error = { strategy = 'Stop },
note = "Copies state.ncl stub. Skipped if file already exists.",
},
{
id = "copy_ontology_gate",
action = "copy_ontology_gate_stub",
actor = 'Agent,
cmd = "test -f {project_dir}/.ontology/gate.ncl || sed 's/{{ project_name }}/{project_name}/g' {ontoref_dir}/templates/ontology/gate.ncl > {project_dir}/.ontology/gate.ncl",
depends_on = [{ step = "create_ontology_dir", kind = 'OnSuccess }],
on_error = { strategy = 'Stop },
note = "Copies gate.ncl stub. Skipped if file already exists.",
},
{
id = "install_scripts_wrapper",
action = "install_consumer_entry_point",
actor = 'Agent,
cmd = "mkdir -p {project_dir}/scripts && test -f {project_dir}/scripts/ontoref || (sed 's|{{ ontoref_dir }}|{ontoref_dir}|g' {ontoref_dir}/templates/scripts-ontoref > {project_dir}/scripts/ontoref && chmod +x {project_dir}/scripts/ontoref)",
depends_on = [{ step = "create_ontoref_dir", kind = 'OnSuccess }],
on_error = { strategy = 'Stop },
note = "Installs scripts/ontoref thin wrapper. Skipped if already present.",
},
{
id = "validate_ontology",
action = "nickel_typecheck_ontology",
actor = 'Agent,
cmd = "cd {project_dir} && nickel export .ontology/core.ncl > /dev/null && nickel export .ontology/state.ncl > /dev/null && nickel export .ontology/gate.ncl > /dev/null",
depends_on = [
{ step = "copy_ontology_core", kind = 'OnSuccess },
{ step = "copy_ontology_state", kind = 'OnSuccess },
{ step = "copy_ontology_gate", kind = 'OnSuccess },
],
on_error = { strategy = 'Stop },
note = "Validates all three .ontology/ files parse without errors.",
},
],
postconditions = [
"{project_dir}/.ontoref/config.ncl exists and is valid Nickel",
"{project_dir}/.ontology/core.ncl, state.ncl, gate.ncl exist and parse",
"{project_dir}/scripts/ontoref exists and is executable",
"No existing files were overwritten",
],
} | (s.Mode String)