You are tasked with operating as the root installer / upgrader orchestrator for the codex_context_engine project.
This repository is structured as an evolutionary prompt system.
The canonical layout is:
iterations/
1/
readme.md
<iteration_spec>.md
2/
readme.md
<iteration_spec>.md
3/
readme.md
<iteration_spec>.md
...
Each numeric iteration represents a cumulative improvement to the same system.
The root prompt must not assume that the latest iteration fully replaces all previous ones.
Instead, the root prompt must:
- detect the current installed iteration in the target repository
- determine which iterations are missing
- execute the missing iterations in ascending numeric order
- preserve existing learnings, memory, telemetry, and configuration
- work both for:
- fresh installation
- in-place upgrade
This prompt must be designed so it does not need to be rewritten every time a new iteration is added.
It must dynamically inspect the iterations/ directory and use whatever numeric iterations exist.
Install or upgrade the Codex Context Engine in the target repository by applying all required iterations in the correct order.
The system must be robust, incremental, and safe.
It must never blindly reinstall everything if a partial or full installation already exists. It must never destroy useful state unless cleanup is clearly required and safe.
Treat this repository as the source of truth for the Codex Context Engine.
Treat the target repository (the repo where this prompt is being executed) as the installation target.
Your task is to inspect the target repository, determine what version of the engine is already installed, and then apply only the iterations that are still missing.
Do not assume the latest iteration number is 4.
Instead:
- inspect the local
iterations/directory in this repository - discover all numeric iteration folders dynamically
- sort them numerically ascending
- treat the highest discovered number as the latest available iteration
This rule is mandatory.
The root orchestrator must continue working when new iterations are added later without requiring manual changes to this root prompt.
Within this repository:
- only numeric folders under
iterations/count as iterations - ignore non-numeric folders or auxiliary files
Each valid iteration folder should contain:
readme.md- one execution-ready iteration specification file in Markdown form
Preferred patterns for the execution-ready specification file:
prompt.md- if
prompt.mddoes not exist, exactly one other non-readme.mdMarkdown file - if multiple candidate Markdown files exist, prefer the one whose filename best matches the iteration topic and report the choice clearly
If an iteration folder is malformed:
- do not fail immediately
- report the issue clearly
- continue if safe
- do not invent missing iteration content
Before applying anything, inspect the target repository for signs of an existing Codex Context Engine installation.
Possible evidence may include:
AGENTS.md.codex_memory/.context_metrics/.codex_global_metrics/.codex_failure_memory/.codex_task_memory/.codex_memory_graph/.codex_library/CONTEXT_SAVINGS.md.codex_context_engine/state.json- files or comments explicitly mentioning
codex_context - iteration metadata files if present
- prior generated schemas, summaries, scoring metadata, telemetry, or diagnostic artifacts
Use these signals to determine whether the engine is already installed and, if possible, which iteration level has already been applied.
Your first responsibility is to determine the current installed iteration in the target repository.
Use this strategy, in order:
If the target repository contains a clear iteration/version marker, use it.
Examples:
- installed iteration metadata file
- version field in a configuration file
- explicit note in generated engine artifacts
If no explicit marker exists, infer the installed iteration by detecting installed capabilities.
Use conservative inference.
Example signals by capability:
- basic external memory artifacts
- persistent preference storage
- primitive memory structure
- fallback-oriented context memory setup
- structured
.codex_memory/ - telemetry artifacts such as
.context_metrics/ CONTEXT_SAVINGS.md- validation-oriented files
- more explicit bootstrap / delta retrieval setup
- deterministic context packet schema
- relevance scoring metadata
- compaction reports or compaction utilities
- scoring-aware memory records
.codex_global_metrics/- project registration in global metrics
- global savings aggregation
- system health report for the engine
- context packet cost estimation
- context budget thresholds
- optimization or trimming reports
- compression / pruning rules tied to budget
- planning artifacts or planner logic
- task-type or task-signal classification before retrieval
- explicit context loading strategy selection
- predicted repository areas before packet assembly
.codex_failure_memory/- structured failure records
- stored root causes and fixes
- retrieval of prior failure patterns during debugging flows
.codex_task_memory/- task-type-specific knowledge buckets
- specialized retrieval by workflow category
- distinct memory slices for tasks such as tests, refactors, debugging, or architecture
.codex_memory_graph/- graph node / edge artifacts
- graph expansion during retrieval
- relationship-aware context selection
- bounded connected-context traversal
- task logs or telemetry schemas that support
task_id - task logs or telemetry schemas that support
levelsuch astask/phase - phase labels such as
phase_name - weekly summaries exposing granular fields such as
phase_events_sampled - analyzer behavior that aggregates phase-only rows into task-level savings summaries without double counting
.codex_library/.codex_library/registry.json.codex_library/mods/- mod manifests such as
.codex_library/mods/<mod_id>/mod.json - evidence of knowledge mods created through commands such as
learn <topic>oraprende <tema> - engine artifacts referencing knowledge mods or local domain learning
- processed knowledge artifacts under
.codex_library/mods/<mod_id>/ - directories such as:
notes/summaries/indices/manifests/
- evidence of document ingestion pipelines
- normalized document sources or extracted text artifacts
- topic indices or retrieval metadata generated from documents
- retrieval artifacts referencing indices or retrieval maps
- logic selecting artifacts from
notes/,summaries/, orindices/ - retrieval packs assembled from
.codex_library/ - code paths that load compact knowledge artifacts instead of raw documents
- evidence of topic-aware knowledge retrieval
.codex_library/REFERENCES_TEMPLATE.mdexists- any
inbox/references.mdfile inside a mod directory manifests/state.jsonof any mod contains areferenced_fileskey- processing logic that parses
references.mdand tracksmtimealongside hash in state - support for
.sql,.xml,.json,.yaml,.yml,.py,.csvas ingestible formats via references - evidence that a mod can learn from file references without copying the source files into
inbox/
- any mod contains
remote_sources/manifest.json - any mod contains
remote_sources/raw/ - any mod contains
remote_sources/snapshots/ - any mod contains
remote_sources/extracted/ - CLI or scripts reference commands equivalent to
mod add-sourceormod fetch-sources - snapshot metadata records include URL, canonical URL, fetch timestamp, raw artifact path, extracted artifact path, and inbox path
- canonical inbox documents produced from remote URLs preserve source traceability
- remote documentation sources are materialized locally before learning or retrieval
- an engine state marker records
installed_iteration >= 16 - an engine state marker or managed config records
communication_mode: caveman_fullor equivalent AGENTS.mdcontains an engine-managed block that explicitly enforces compressed execution-time communication- prior engine-managed verbosity rules have been replaced by concise communication rules
- execution updates are explicitly suppressed by default while work is in progress
- final output is instructed to use compact structures such as
found -> cause -> fixordone -> files -> tests - runtime guidance explicitly forbids decorative formatting in results
- engine-managed communication guidance explicitly limits caveman mode to runtime communication rather than all repository prose
Infer the highest iteration that is safely supported by the evidence.
If uncertain, prefer a lower installed iteration rather than overestimating.
If no meaningful evidence exists, assume no installation is present.
Once the current installed iteration is known:
- if none is installed, apply all iterations in ascending order
- if iteration
Nis installed, applyN+1through latest - if latest is already installed, do not reinstall blindly
Even if the latest iteration appears installed, you may still:
- normalize malformed files
- repair clearly incomplete artifacts
- report inconsistencies
- avoid destructive rewrites
For each missing iteration:
- open
iterations/<n>/readme.md - locate the execution-ready specification file for that iteration
- treat that specification file as the authoritative implementation prompt
- apply the required changes in the target repository
- preserve existing compatible state
- perform migrations only when necessary
- avoid duplicating content unnecessarily
- continue to the next missing iteration
You must apply iterations strictly in ascending order.
Do not skip an intermediate iteration unless:
- its folder is missing or malformed, and
- proceeding is still safe, and
- you clearly report the limitation
After all required iterations have been applied, verify whether ruby is installed before running engine maintenance or integration scripts.
Rules:
- check for
rubyexplicitly - if
rubyis not available, install it using the safest native package path for the host environment - only proceed to Ruby-based engine scripts after Ruby is available
- if Ruby installation fails, report the failure clearly and do not pretend script execution succeeded
This applies in particular to cross-project integration flows that execute scripts such as:
scripts/install_cross_project_for_all_repos.rb
When upgrading an existing installation:
- preserve memory records whenever possible
- preserve telemetry unless it is clearly broken or incompatible
- preserve preferences unless normalization is required
- preserve existing
AGENTS.mdrules unless they conflict with engine behavior - preserve
.codex_library/artifacts, references, snapshots, and manifests unless migration is required - prefer in-place upgrades
- avoid replacing the whole system if only one layer is missing
Never erase useful history just because a newer iteration exists.
If AGENTS.md exists in the target repository:
- update it carefully
- merge new engine requirements without destroying unrelated project instructions
- avoid duplicated sections
- preserve user/project-specific instructions whenever possible
If AGENTS.md does not exist:
- create it only if required by the iterations being applied
The Codex Context Engine should continue using AGENTS.md as the authoritative runtime policy layer when the installed iterations require that pattern.
To make future upgrades reliable, ensure the installation leaves behind a clear installed iteration marker in the target repository.
Preferred options include one of the following:
- a lightweight metadata file
- a version field in an existing engine file
- a clearly named engine state artifact
The marker should minimally record:
- engine identifier:
codex_context_engine - installed iteration number
- timestamp of last upgrade
For Iteration 16 and later, the marker should also record communication layer status when available, such as:
communication_layercommunication_mode
Keep it lightweight and machine-readable.
If a compatible marker already exists, update it.
This is important so future executions of the root prompt can detect state reliably.
This root prompt must remain forward-compatible.
Future iterations may:
- add new memory layers
- add new optimization passes
- add new knowledge mechanisms
- add new communication policies
- add new install scripts or metadata
Do not assume future iterations will reuse the filename prompt.md.
Do assume that each valid iteration folder will contain:
readme.md- one primary execution-ready Markdown spec
If naming patterns evolve, choose the most likely primary spec conservatively and report your choice.
Install incrementally. Upgrade safely. Preserve state. Discover iterations dynamically. Apply the authoritative iteration spec, not assumptions about its filename.