docs · engine functions

Engine functions reference.

A protocol step’s behaviour isn’t hardcoded — every side effect is a named function listed in the step’s pre_funcs or post_funcs. The engine ships 45 of them across eight families; this page is the catalogue. The list is authoritative and re-callable in any session via protocol_available_funcs().

pre_funcs vs post_funcs

pre_funcs run when a step is entered — detecting the task, loading a baseline, injecting a reminder, or resolving which AI providers to launch. post_funcs run when a step tries to advance — creating files, committing, syncing issues, or enforcing a gate.

A post_func only becomes a hard wall when its step sets post_funcs_stop_on_failure: true — that’s what turns require_spec_review_passed, check_completion_evidence, and verify_tests_pass from advisory reminders into structural gates. (Placement in pre_funcs is cosmetic for gating — the advance only checks post_funcs.)

Eight families

FamilyCountWhat it covers
Task lifecycle & state5Detect, create, and track the task and its state file.
Git & branches5Branch, commit, merge, push, and open the merge request.
Gates & verification5The structural walls — wire as stop-on-failure post_funcs to actually gate.
Issue tracking2Mirror task state to the configured provider.
Completion & cleanup7Wrap the task up — dispatch the finish flow, archive, and reset state.
Refactoring test baseline3Capture a green test baseline as the refactoring safety net.
Optimize loop11The metric-driven autoresearch family — measure, experiment, and gate on gaming.
Knowledge & AI providers7Wiki upkeep and the per-phase parallel-provider launch instructions.
total45across eight families

Complete function reference

Every function, by family. When is where it typically wires — pre (on step entry) or post (on advance).

Task lifecycle & stateWhenWhat it does
auto_detect_taskpreDetect the active task from the current git branch.
verify_branch_and_taskpreCheck the branch matches task state and the task file exists (warns only).
create_task_filepostWrite the task markdown from AI-provided content, validating frontmatter.
set_task_statepostSet current_task.json and rename the pending protocol log to the task.
update_task_status_in_progresspostFlip the task file's status frontmatter to in-progress.
Git & branchesWhenWhat it does
git_setup_branchpostCreate and check out the task branch; can carry uncommitted changes across.
git_commitpostStage and commit the working tree with a task-derived message.
git_merge_mainpostFetch and merge the default branch, reporting any conflicts.
git_pushpostPush the current branch to the remote with upstream tracking.
create_merge_requestpostOpen an MR / PR linked to the task's provider issue.
Gates & verificationWhenWhat it does
require_spec_review_passedpre / postRequire a SPEC_REVIEW: PASSED note in the log before leaving code-review.
check_completion_evidencepostBlock the advance unless the summary carries verification evidence (or the escape hatch).
verify_tests_passpostRun the configured test command; a non-zero exit blocks the advance.
validate_code_review_in_worklogpostConfirm the code-review results were appended to the work log.
validate_no_critical_issues_in_worklogpostFail if the latest review block reports any critical issues.
Issue trackingWhenWhat it does
create_issue_if_enabledpostCreate a provider issue when issue tracking is enabled.
update_issue_statuspostMove the linked issue to completed / closed.
Completion & cleanupWhenWhat it does
present_completion_optionspreWith no issue provider set, offer the merge-local / push-PR / keep / discard menu.
completion_dispatchpostRun the completion chain: archive, commit, merge, push, status, cleanup, checkout.
require_discard_confirmationpostTwo-step typed confirmation before a discard force-deletes the branch.
archive_taskpostMove the finished task file into tasks/done/.
cleanup_task_scoped_statepostRemove the task-scoped state directory.
clear_task_statepostReset current_task.json to the empty state.
checkout_default_branchpostSwitch back to main / master after completion.
Refactoring test baselineWhenWhat it does
capture_test_baselinepostSnapshot the test command and result before any change.
load_test_baselinepreLoad the saved baseline for regression comparison.
cleanup_test_baselinepostRemove the baseline file once refactoring completes.
Optimize loopWhenWhat it does
validate_optimize_setuppostValidate optimize settings before any durable side effects are created.
write_optimize_setuppostPersist the validated optimize settings to state.
capture_metric_baselinepostRun the metric once on HEAD and record the baseline.
validate_metric_scriptpostPre-flight the metric script — run twice, check the parser and stability.
run_metricpre / postRun the metric command N times under a filtered env and aggregate.
log_experiment_resultpostMeasure HEAD and append an experiment row — the engine, not the LLM, owns the value.
check_cost_estimatepostProject the wall-clock cost of the run before experimentation starts.
check_terminationpostAfter each iteration, test the four stop conditions and end when one matches.
update_best_commitpostRecord the best commit + metric in the task frontmatter when a run improves.
batch_checkpointpostPause at each batch boundary for user approval (interactive optimize).
policy_compliance_auditpostHeuristic scan for metric-gaming; flags feed the review prompt (never blocks).
Knowledge & AI providersWhenWhat it does
wiki_update_reminderpreDuring documentation, remind Claude to update the LLM wiki (if enabled).
resolve_ai_providerspreReturn the parallel AI-provider launch instructions for the code-review gate.
resolve_ai_providers_for_investigationpre…for the task investigation phase.
resolve_ai_providers_for_implementationpre…for the implementation planning phase.
resolve_ai_providers_for_brainstormpre…for the brainstorm analysis phase.
resolve_ai_providers_for_explorationpre…for the research exploration phase.
resolve_ai_providers_for_refactoring_planningpre…for the refactoring planning phase.

Discoverable, not hardcoded

Because behaviour lives in these named functions, adding to a step is a JSON edit, not an engine change — wire a function into a step’s pre_funcs / post_funcs and it runs. To build your own workflow, fork a protocol (see customization) and compose the functions above; for the tools that drive the engine itself, see the MCP reference.