core / project_safety.py

Budget enforcement, human-gate postconditions, contradiction detection, and chat→project promotion heuristics.

Functions

FunctionPurpose
check_budget(proj_metadata) -> BudgetDecisionMulti-dimensional budget check — steps · runtime_seconds · tool_calls (line 39).
enforce_human_gate(task) -> Optional[str]Returns the first HUMAN_GATE:-prefixed postcondition, or None (line 114).
detect_contradiction(new_summary, prior_summary) -> Optional[str]Textual conflict detection (true↔false, yes↔no, …) (line 142).
route_contradiction(contradiction_log, new_fact, prior_facts, reason)Append a revision event to the contradiction log (line 162).
should_suggest_promotion(...)Decide whether the in-flight chat warrants becoming a tracked project (line 203).

Budget knobs

Stored in project_metadata:

Promotion thresholds

MIN_TURNS_FOR_SUGGESTION = 8; MIN_PLAN_NODES_FOR_SUGGESTION = 3. Promotion is suggested only when both clear and the conversation isn't already in a project.

Human gate

Any postcondition prefixed with HUMAN_GATE: forces NEEDS_USER regardless of tool output. Used for irreversible actions (delete production data, send-to-customer, etc.).