hierarchical-codex
Deterministic MCP control plane for native Codex subagents, providing durable state, policy gates, budgets, artifacts, evidence workflow, and recovery for Sol/Terra/Luna hierarchical agent threads.
README
hierarchical-codex
hierarchical-codex is a deterministic MCP control plane for native Codex
subagents. Codex still creates UI-visible Sol → Terra → Luna threads with
spawn_agent; this project supplies the durable state, policy gates, budgets,
artifacts, evidence workflow, and recovery protocol around those threads.
Status: engineering MVP. The control plane, Codex project integration, hooks, tests, and operating documentation are implemented. Validate model availability and the exact Codex core version on every target App/IDE deployment.
Design choice
The project follows one explicit route:
Model-driven spawning; code-enforced constraints.
Codex native execution plane
spawn_agent / wait_agent / send_message / Subagents UI
|
| task_id in TaskEnvelope
v
TypeScript MCP control plane
SQLite task ledger / leases / budgets / artifacts / evidence / audit
^
|
Codex Skills + Profiles + Hooks
orchestration policy / model-effort routing / spawn veto / stop checks
MCP and hooks do not create native threads. The Sol or Terra model calls native
spawn_agent; code validates and records the surrounding workflow.
Implemented capabilities
- Mission and task ledgers with optimistic versions.
- Direct-parent role policy: Sol director → Terra coordinator → Luna leaf.
- Model/effort matrix:
- Sol:
high,xhigh,max - Terra:
xhigh,max - Luna:
high,xhigh,max
- Sol:
- Dependency-aware readiness and bounded child allocation.
- Expiring worker leases, heartbeats, release, and safe reclamation.
- Hierarchical token, cost, wall-time, tool-call, and child-count budgets.
- Content-addressed artifact storage with bounded reads.
- Candidate → checked → verified → committed evidence gates.
- Producer/reviewer separation.
- Request-hashed idempotent mutations and append-only audit events.
- Recovery snapshots after restart or context compaction.
- Project-scoped Codex Skill, Agent profiles, MCP configuration, and hooks.
Requirements
- Node.js 22.5 or newer. Node 26 is used in development.
- Python 3.10 or newer for Codex lifecycle hooks.
- Codex 0.148.0 or newer is the recommended production baseline, with native multi-agent tools, custom agents, MCP, and hooks.
- A trusted Codex project so
.codex/config.tomland project hooks are loaded.
Quick start
cd "/mnt/tools/others/codes/web project/hierarchical-codex"
npm install
npm run check
npm run doctor
Then:
- Open this repository root in Codex App, Codex CLI, or the Codex VS Code
extension.
npm run doctordoes not install the skill into ChatGPT; the App must use this folder as its workspace. - Trust the project when prompted. Untrusted projects hide
.codexskills. - Start a new root conversation with
gpt-5.6-sol(skills load at startup). - Type
$and selectprism, or invoke$prism <mission>. If the picker is empty,AGENTS.mdstill instructs the root Sol. - Inspect native child activity in the Subagents UI and durable state through the MCP tools.
To use the full stack from other folders in the VS Code Codex extension or
CLI, run npm run install:user after npm run build. See
docs/USER_INSTALL.md. Do not copy this repo's
.codex/config.toml into ~/.codex; that would pin Sol as the default model
and block ordinary subagents.
The project MCP configuration launches node dist/cli.js with the repository
root as its working directory. Run npm run build after source changes.
Development commands
npm run dev # Run the stdio MCP server from TypeScript
npm run doctor # Validate runtime and Codex integration files
npm run test # Unit and integration tests
npm run typecheck # Strict TypeScript checks
npm run lint # ESLint
npm run format # Prettier
npm run build # Compile dist/
npm run check # Full local quality gate
npm run install:user # Install skill, agents, hooks, and MCP into ~/.codex
npm run doctor:user # Verify the user-global install
npm run uninstall:user # Remove the managed user-global files
The MCP server writes protocol messages to stdout. Application logging must use stderr; stdout logging corrupts stdio MCP transport.
Runtime state
By default, state is project-local and ignored by Git:
.hierarchical-codex/
├── control-plane.sqlite
└── artifacts/
└── <sha-prefix>/<sha256>
User-global install (npm run install:user) stores the ledger at
~/.local/share/hierarchical-codex/ so Codex MCP sandboxes can write it.
If that directory is not writable, the server falls back to a temp path and
logs the chosen home on stderr.
Configuration environment variables:
HIERARCHICAL_CODEX_HOMEHIERARCHICAL_CODEX_DBHIERARCHICAL_CODEX_ARTIFACTSHIERARCHICAL_CODEX_MAX_ARTIFACT_BYTESHIERARCHICAL_CODEX_DEFAULT_LEASE_SECONDSHIERARCHICAL_CODEX_MAX_LEASE_SECONDSHIERARCHICAL_CODEX_EVENT_PAGE_SIZE
MCP tools
Mission:
mission_createmission_getmission_close
Task and lease:
task_allocatetask_gettask_claimtask_starttask_heartbeattask_releasetask_blocktask_failtask_canceltask_supersedetask_set_efforttask_commit
Artifacts and evidence:
artifact_putartifact_getresult_submit_candidateresult_checkresult_verify
Accounting and recovery:
budget_reportrecovery_snapshot
See docs/API.md for contracts and docs/PROTOCOL.md for the orchestration sequence.
Repository structure
.agents/skills/ Codex orchestration Skill
.codex/agents/ Sol/Terra/Luna custom profiles
.codex/hooks/ Python policy gates
.codex/config.toml MCP and native agent configuration
src/domain/ State and policy definitions
src/infra/ SQLite repository and artifact storage
src/mcp/ MCP tool registration
tests/ Control-plane, policy, and hook tests
docs/ Architecture, protocol, operations, ADRs, records
Important boundaries
- External MCP code cannot call the internal native
spawn_agentregistry. - Hooks can deny, rewrite, or add context, but
SubagentStartcannot prevent a subagent after creation. - Native UI state is observational; SQLite is the durable workflow source.
- This MVP is single-host. SQLite serializes mutations but is not a distributed consensus system.
- Token usage is reported by agents/hosts; the MCP server cannot independently meter model tokens.
- The repository is currently
UNLICENSED; add an explicit license before external distribution.
Documentation
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。