Durable graph generators
Surface |
Value |
|---|---|
Package |
|
Host kit |
|
Config |
|
Stability |
evolving (in-process + stdio MCP; CLI/TUI still gap) |
Normative |
Role
Primary host-facing execution façade for long-running, judgment-bearing
graphs. Drivers (frontier MCP client, human CLI/TUI, ScriptedDriver) advance
a durable run through ordered GraphYield envelopes. GraphExecutor remains
the internal walker; MCP is a transport adapter, not core.
One-shot / fire-and-forget harness loops (RunRequest / run(), direct
GraphExecutor.run) remain valid for short work. Prefer the generator when the
run may yield guidance, outlive a process, or be driven from an external
session.
Public types
Type |
Purpose |
|---|---|
|
|
|
Verb-led host session script ( |
|
Ordered immutable yield ( |
|
Typed advice exchange |
|
Diagnostics without advancing |
|
Strict offline replay |
|
Continuation persistence ( |
|
Controller ownership |
Yield kinds
advice_requested, completed, failed, cancelled, optional progress /
running.
Quick start
from mechaharness.host_kit import host_durable_graph_generator
from mechaharness.durable_graph_generator import GuidanceResponse, ScriptedDriver
gen = host_durable_graph_generator()
status = gen.start(
"verify_repair",
{
"guidance": [
{
"question": "Which repair path?",
"choices": [
{"id": "retry", "label": "Retry"},
{"id": "escalate", "label": "Escalate"},
],
}
]
},
controller_id="host",
)
while status.kind not in {"completed", "failed", "cancelled"}:
if status.kind == "advice_requested":
status = gen.resume(
status.run_id,
GuidanceResponse(request_id=status.request_id or "", choice_id="retry"),
expected_sequence=status.sequence,
controller_id="host",
idempotency_key=f"{status.run_id}:{status.sequence}",
)
else:
status = gen.resume(
status.run_id,
expected_sequence=status.sequence,
controller_id="host",
)
Offline regression:
driver = ScriptedDriver(gen)
driver.run(
"verify_repair",
{"guidance": [{"request_id": "r1", "question": "Q?", "choices": [{"id": "a", "label": "A"}]}]},
responses=[{"request_id": "r1", "choice_id": "a"}],
expected_kinds=["advice_requested", "completed"],
)
Intended HTTP / CLI / MCP mapping
Client |
Mapping |
|---|---|
In-process / stories |
|
OpenAPI / HTTP |
Long-run façade methods mirror DG-01 ops (planned; not a second architecture) |
CLI / TUI |
Same instrumentor / soft-point seam (curses optional) — gap |
MCP stdio |
|
Story scenarios |
|
Soft points are the UI seam: story fixtures and a future CLI/TUI bind the same
guidance answers via answer steps; DurableGraphGenerator owns suspension/resume.
The instrumentor is host-facing (not a test harness); pytest only loads YAML and
asserts observations.
MCP example (doctest)
The module docstring on mechaharness.mcp_graph_driver is the blessed end-to-end
example (start → advice_requested → file-store restart → resume → completed,
plus a Cursor-style NDJSON handshake). Run it with::
pytest --doctest-modules src/mechaharness/mcp_graph_driver.py -q
Local Cursor wiring
Point MCP at the project interpreter (editable pip install -e . in this
repo, or the host env where mechaharness is installed). Do not create a
separate MCP-only virtualenv.
Inference endpoints and model id belong on the MCP server env block
(primary). An optional project .env is only a convenience for CLI/pytest.
Project-local agent MCP configs are gitignored (absolute paths and lab endpoints stay machine-local):
Cursor:
.cursor/mcp.jsonCodex:
.codex/config.toml(template:codex-mcp.config.toml.example)
Cursor example::
{
"mcpServers": {
"mechaharness-generator": {
"command": "/ABS/PATH/to/.venv/bin/python",
"args": ["-m", "mechaharness.mcp_graph_driver"],
"cwd": "/ABS/PATH/to/project",
"env": {
"MECHA_MCP_HOST": "project_coding",
"MECHA_WORKSPACE": "/ABS/PATH/to/project",
"MECHA_GENERATOR_STORE": "/ABS/PATH/to/project/.mechaharness/generator-runs.json",
"MECHA_GENERATOR_CONTROLLER": "cursor-agent",
"MECHA_INFERENCE_BACKEND": "openai_local",
"MECHA_BASE_URL": "http://127.0.0.1:8000/v1",
"MECHA_MODEL": "<served-model-id>",
"MECHA_API_KEY": "local",
"PYTHONUNBUFFERED": "1"
}
}
}
}
MECHA_MCP_HOST=project_coding loads
:class:~mechaharness.project_coding.ProjectCodingConfig (workspace coding
tools + guided_coding local-work burst after guidance). Restart the MCP
server after changing env or editing library modules (stdio processes do
not hot-reload).
Recipe guided_coding: start → advice_requested (engineering direction)
→ generator_resume with a short answer → local instruction_todo_plan
burst (oneshot or todo list with acceptance) + audited gate payload on
completed. Mid-plan human refinement: local work may return
request_guidance; the generator yields again and restarts the plan after
answers. See guided coding and
instruction todo plan.
Reviewing a coding handoff
Set MECHA_WORKSPACE to the source checkout. Set MECHA_GENERATOR_STORE to
a durable location outside it when the source tree must stay byte-for-byte
unchanged. The project coding MCP host copies the working tree into a private
directory for each run. In Git repositories it includes tracked edits and
non-ignored untracked files. Nested repositories and outbound symlinks require
a different workspace provider. For a plain directory the host starts a private
Git repository to compute the review diff.
Call
generator_startwithrecipe_id="guided_coding", a goal andinputs.verify_runs, for example[{"path":"tests","pytest":true}].Pass the returned
run_id,sequence(asexpected_sequence) andrequest_idtogenerator_resumewithchoice_id="minimal", the same controller and an idempotency key. Reuse the key if the response is lost.Read
payload.result,checks,already_satisfied,base_revision,base_tree,written_filesandpatch_path. Each check records its spec, pass state and failures. A run with edits and zero checks reportsunverified. A green preflight reportsalready_satisfied=true.From the original working tree, run
git apply --check /path/to/changes.patch. Inspect the diff and apply it when ready. The staged patch is relative to the original dirty tree. The private checkout and patch stay available in the run’s temporary directory for review. Remove that directory after the handoff is finished.
The MCP host runs shell and verification commands with a private home, restricted
filesystem access and networking disabled. macOS uses sandbox-exec; Linux
requires Bubblewrap (bwrap) with namespaces enabled. A missing process
sandbox prevents command execution. Hosts embedding ProjectCodingConfig
directly can supply a trusted workspace. Tool dispatch uses the host’s
AccessControl; push and pull-request operations require both process and
network grants.
MCP progress (stdio keep-alive)
When the client sends _meta.progressToken on tools/call, the driver
emits MCP notifications/progress while work runs. Messages use a recipe
chain path, for example::
guided_coding › plan_tile › work_item 1 › tool_round 2 › write_file
Cursor’s IDE idle timeout resets on these notifications. Progress is optional when the token is absent (offline / ScriptedDriver).
During a Completer round, ConversationalToolLoopRunner watches the
awaitable via mechaharness.inference_progress.await_while_running: it emits
ticks only while the awaitable is still pending, then raises
InferenceTimeoutError if wall time exceeds
MECHA_INFERENCE_TIMEOUT_SECONDS (falls back to
MECHA_HTTP_TIMEOUT_SECONDS, default 180). Tick interval:
MECHA_INFERENCE_PROGRESS_TICK_SECONDS (default 5).