This commit is contained in:
2026-08-24 08:11:59 -07:00
commit 53df0eed10
275 changed files with 133056 additions and 0 deletions
@@ -0,0 +1,7 @@
# Contract-First Refactoring
Use this featured profile for compatibility-sensitive migrations and refactors. Sonnet owns the immutable contract and production changes; MiniMax mines repository-wide constraints; Luna creates a test-only isolated patch; DeepSeek independently verifies the final result.
The root freezes and hashes the normalized contract before downstream work. Test patches require explicit acceptance and integration, production source remains root-owned, and verification must cite the same contract hash. This differs from ordinary review by separating specification, tests, implementation, and compliance evidence.
Every worker is a persistent supervised Unix app-server thread with strict retained results, goal/turn lifecycle, and warning-only stalls. The root controls all three; the compatibility verifier may steer or return the test author for correction but cannot accept or integrate that patch. Suspension preserves exact contract evidence, terminal history, trace, and the isolated test patch for deliberate continuation.
@@ -0,0 +1 @@
Independently verify the final implementation against the exact frozen contract hash, existing tests, newly accepted tests, and backward-observable behavior. Run focused commands, inspect hidden-risk boundaries, and return pass only when all material contract clauses have evidence. Do not edit or silently revise the contract.
@@ -0,0 +1 @@
Write tests only within the assigned test scope and only against the supplied frozen contract hash. Include tests that fail plausible incorrect implementations, boundary cases, and compatibility behavior; do not modify production source. Run focused commands and return correlated evidence plus a minimal isolated patch for explicit root acceptance and integration.
@@ -0,0 +1 @@
Mine explicit and implicit compatibility constraints across the supplied repository corpus. Cite exact locations and distinguish guaranteed behavior, accidental behavior, and uncertainty. Do not edit or choose the implementation. Return a canonical contract payload and SHA-256 so downstream work can be tied to one immutable interpretation.
@@ -0,0 +1 @@
Own the contract, production-source changes, and final integration. Launch invariant mining early while you inspect the code. Reconcile explicit specifications, tests, public surfaces, persisted data, and observable behavior into one normalized contract, then freeze and hash it before authorizing tests or implementation. Accept and explicitly integrate the test-only patch before changing source. Implement against the frozen contract, then request independent compatibility verification. If the contract changes, record a new hash and invalidate downstream evidence.
@@ -0,0 +1,27 @@
{
"title": "Frozen compatibility contract",
"type": "object",
"additionalProperties": false,
"properties": {
"contract": {"type": "string", "minLength": 1},
"contract_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"clauses": {
"type": "array",
"minItems": 1,
"maxItems": 100,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {"type": "string", "minLength": 1},
"invariant": {"type": "string", "minLength": 1},
"evidence_location": {"type": "string", "minLength": 1},
"classification": {"type": "string", "enum": ["guaranteed", "observed", "uncertain"]}
},
"required": ["id", "invariant", "evidence_location", "classification"]
}
},
"uncertainties": {"type": "array", "items": {"type": "string"}, "maxItems": 30}
},
"required": ["contract", "contract_sha256", "clauses", "uncertainties"]
}
@@ -0,0 +1,24 @@
{
"title": "Contract-derived isolated test patch",
"type": "object",
"additionalProperties": false,
"properties": {
"contract_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"covered_clause_ids": {"type": "array", "items": {"type": "string"}, "minItems": 1, "maxItems": 100, "uniqueItems": true},
"test_files": {"type": "array", "items": {"type": "string"}, "minItems": 1, "maxItems": 30, "uniqueItems": true},
"plausible_failures_caught": {"type": "array", "items": {"type": "string"}, "minItems": 1, "maxItems": 30},
"commands": {
"type": "array",
"minItems": 1,
"maxItems": 30,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {"command": {"type": "string", "minLength": 1}, "exit_code": {"type": "integer"}, "observation": {"type": "string", "minLength": 1}},
"required": ["command", "exit_code", "observation"]
}
},
"limitations": {"type": "array", "items": {"type": "string"}, "maxItems": 20}
},
"required": ["contract_sha256", "covered_clause_ids", "test_files", "plausible_failures_caught", "commands", "limitations"]
}
@@ -0,0 +1,28 @@
{
"title": "Frozen-contract compatibility verification",
"type": "object",
"additionalProperties": false,
"properties": {
"verdict": {"type": "string", "enum": ["pass", "fail", "blocked"]},
"contract_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"verified_clause_ids": {"type": "array", "items": {"type": "string"}, "maxItems": 100, "uniqueItems": true},
"commands": {
"type": "array",
"maxItems": 30,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {"command": {"type": "string", "minLength": 1}, "exit_code": {"type": "integer"}, "observation": {"type": "string", "minLength": 1}},
"required": ["command", "exit_code", "observation"]
}
},
"findings": {"type": "array", "items": {"type": "string"}, "maxItems": 30},
"blockers": {"type": "array", "items": {"type": "string"}, "maxItems": 20}
},
"required": ["verdict", "contract_sha256", "verified_clause_ids", "commands", "findings", "blockers"],
"allOf": [
{"if": {"properties": {"verdict": {"const": "pass"}}, "required": ["verdict"]}, "then": {"properties": {"verified_clause_ids": {"minItems": 1}, "commands": {"minItems": 1}, "findings": {"maxItems": 0}, "blockers": {"maxItems": 0}}}},
{"if": {"properties": {"verdict": {"const": "fail"}}, "required": ["verdict"]}, "then": {"properties": {"findings": {"minItems": 1}}}},
{"if": {"properties": {"verdict": {"const": "blocked"}}, "required": ["verdict"]}, "then": {"properties": {"blockers": {"minItems": 1}}}}
]
}
@@ -0,0 +1,114 @@
schema_version = 8
id = "contract-first-refactoring"
version = "8.0.0"
display_name = "Contract-First Refactoring"
description = "A Sonnet root freezes compatibility invariants before implementation, accepts an independent test patch, and closes with economical regression verification."
tags = ["refactoring", "compatibility", "test-first", "featured"]
maturity = "featured"
root = "refactor_lead"
smoke = "smoke.toml"
[agents.refactor_lead]
kind = "root"
description = "Contract owner, sole source writer, and final refactor integrator"
model = "opencode_zen_anthropic_messages__claude_sonnet_5"
reasoning = "high"
allowed_reasoning_efforts = ["medium", "high", "xhigh", "max"]
execution_mode = "goal"
goal_token_budget = 600000
max_goal_token_budget = 1000000
stall_warning_seconds = 3600
finalization_grace_seconds = 1800
plan_reasoning = "high"
permissions = "workspace-write"
can_spawn = ["invariant_miner", "contract_test_author", "compatibility_verifier"]
max_active = 1
trust = "high"
verification = "always"
instructions = "agents/refactor-lead.md"
[agents.invariant_miner]
description = "Long-context read-only miner of explicit and implicit compatibility constraints"
model = "opencode_go_anthropic_messages__minimax_m3"
reasoning = "none"
allowed_reasoning_efforts = ["none"]
execution_mode = "goal"
goal_token_budget = 250000
max_goal_token_budget = 400000
stall_warning_seconds = 1800
finalization_grace_seconds = 900
permissions = "read-only"
backends = ["mcp"]
can_spawn = []
max_active = 1
allowed_task_kinds = ["invariant_analysis", "compatibility_analysis"]
trust = "high"
verification = "root_adjudication"
contract_enforcement = "strict"
output_contract = "contracts/invariants.json"
instructions = "agents/invariant-miner.md"
[agents.contract_test_author]
description = "Independent Luna author of contract-derived tests in a test-only worktree"
model = "codex_chatgpt_builtin__gpt_5_6_luna"
reasoning = "high"
allowed_reasoning_efforts = ["medium", "high", "xhigh"]
execution_mode = "goal"
goal_token_budget = 250000
max_goal_token_budget = 400000
stall_warning_seconds = 1800
finalization_grace_seconds = 1200
permissions = "workspace-write"
backends = ["mcp"]
can_spawn = []
max_active = 1
allowed_task_kinds = ["test"]
trust = "high"
verification = "always"
contract_enforcement = "strict"
output_contract = "contracts/test-patch.json"
instructions = "agents/contract-test-author.md"
[agents.compatibility_verifier]
description = "Independent economical compatibility and regression verifier"
model = "opencode_go_openai_chat__deepseek_v4_pro"
reasoning = "high"
allowed_reasoning_efforts = ["high", "max"]
execution_mode = "turn"
stall_warning_seconds = 1800
finalization_grace_seconds = 900
permissions = "read-only"
backends = ["mcp"]
can_spawn = []
max_active = 1
allowed_task_kinds = ["verification", "test_analysis"]
trust = "adversarial_reviewer"
verification = "root_adjudication"
contract_enforcement = "strict"
output_contract = "contracts/verification.json"
instructions = "agents/compatibility-verifier.md"
[agents.refactor_lead.controls.invariant_miner]
actions = ["inspect", "trace", "steer", "interrupt", "pause", "continue", "detach", "stop", "finalize", "compact", "respond", "set_effort", "fork"]
[agents.refactor_lead.controls.contract_test_author]
actions = ["inspect", "trace", "steer", "interrupt", "pause", "continue", "detach", "stop", "finalize", "compact", "respond", "set_effort", "fork"]
[agents.refactor_lead.controls.compatibility_verifier]
actions = ["inspect", "trace", "steer", "interrupt", "pause", "continue", "detach", "stop", "finalize", "compact", "respond", "set_effort", "fork"]
[agents.compatibility_verifier.controls.contract_test_author]
actions = ["inspect", "trace", "steer", "interrupt", "pause", "continue", "detach", "stop", "finalize", "compact", "respond", "set_effort", "fork"]
[coordination]
mode = "contract_test_refactor_verify"
orchestration = "mcp"
max_active_agents = 3
max_depth = 1
max_children_per_agent = 3
max_active_writers = 1
reject_ancestor_role = true
wait_policy = "dependency_only"
write_conflict_policy = "reject"
contradiction_policy = "primary_evidence"
result_visibility = "ancestors"
@@ -0,0 +1,32 @@
schema_version = 8
[[tasks]]
agent = "refactor_lead"
task_kind = "analysis"
task = "Inspect the profile compiler read-only and explain why the contract hash must precede test and implementation work."
mode = "read-only"
wall_timeout_seconds = 600
[[tasks]]
agent = "invariant_miner"
task_kind = "invariant_analysis"
task = "Mine two compatibility invariants from libexec/mmo_profiles.py. Return only the frozen-contract JSON with a SHA-256 matching the exact contract string."
backend = "mcp"
mode = "read-only"
wall_timeout_seconds = 900
[[tasks]]
agent = "contract_test_author"
task_kind = "test"
task = "Do not edit files. Describe one contract-derived test for rejecting schema v1 and return the test-patch JSON using 64 zeroes as the supplied demonstration contract hash and correlated command evidence."
backend = "mcp"
mode = "read-only"
wall_timeout_seconds = 900
[[tasks]]
agent = "compatibility_verifier"
task_kind = "verification"
task = "Verify read-only that the profile compiler rejects schema v1. Return only the verification JSON using 64 zeroes as the supplied demonstration contract hash and captured command evidence."
backend = "mcp"
mode = "read-only"
wall_timeout_seconds = 900