Launch Hands branch-turn workers

This commit is contained in:
Meta Vens 2026-06-02 18:07:04 +01:00
commit 235cc81b17
15 changed files with 306 additions and 44 deletions

View file

@ -27,6 +27,8 @@ pub const EPIPHANY_MODELING_ROLE_BINDING_ID: &str = "modeling-checkpoint-worker"
pub const EPIPHANY_MODELING_OWNER_ROLE: &str = "epiphany-modeler";
pub const EPIPHANY_VERIFICATION_ROLE_BINDING_ID: &str = "verification-review-worker";
pub const EPIPHANY_VERIFICATION_OWNER_ROLE: &str = "epiphany-verifier";
pub const EPIPHANY_IMPLEMENTATION_ROLE_BINDING_ID: &str = "implementation-branch-turn-worker";
pub const EPIPHANY_IMPLEMENTATION_OWNER_ROLE: &str = "epiphany-hands";
pub const EPIPHANY_REORIENT_LAUNCH_BINDING_ID: &str = "reorient-worker";
pub const EPIPHANY_REORIENT_OWNER_ROLE: &str = "epiphany-reorient";
@ -36,10 +38,7 @@ pub fn epiphany_role_binding_id(role_id: EpiphanyRoleResultRoleId) -> Result<&'s
EpiphanyRoleResultRoleId::Research => Ok(EPIPHANY_RESEARCH_ROLE_BINDING_ID),
EpiphanyRoleResultRoleId::Modeling => Ok(EPIPHANY_MODELING_ROLE_BINDING_ID),
EpiphanyRoleResultRoleId::Verification => Ok(EPIPHANY_VERIFICATION_ROLE_BINDING_ID),
EpiphanyRoleResultRoleId::Implementation => Err(
"implementation is owned by the main coding agent; no role specialist launch template exists"
.to_string(),
),
EpiphanyRoleResultRoleId::Implementation => Ok(EPIPHANY_IMPLEMENTATION_ROLE_BINDING_ID),
EpiphanyRoleResultRoleId::Reorientation => Err(
"reorientation uses thread/epiphany/reorientLaunch and thread/epiphany/reorientResult"
.to_string(),
@ -53,7 +52,8 @@ pub fn epiphany_role_owner(role_id: EpiphanyRoleResultRoleId) -> Result<&'static
EpiphanyRoleResultRoleId::Research => Ok(EPIPHANY_RESEARCH_OWNER_ROLE),
EpiphanyRoleResultRoleId::Modeling => Ok(EPIPHANY_MODELING_OWNER_ROLE),
EpiphanyRoleResultRoleId::Verification => Ok(EPIPHANY_VERIFICATION_OWNER_ROLE),
EpiphanyRoleResultRoleId::Implementation | EpiphanyRoleResultRoleId::Reorientation => {
EpiphanyRoleResultRoleId::Implementation => Ok(EPIPHANY_IMPLEMENTATION_OWNER_ROLE),
EpiphanyRoleResultRoleId::Reorientation => {
Err(epiphany_role_binding_id(role_id).unwrap_err())
}
}
@ -88,9 +88,10 @@ pub fn epiphany_role_launch_output_schema(role_id: EpiphanyRoleResultRoleId) ->
EpiphanyRoleResultRoleId::Verification => {
vec!["pass", "needs-review", "needs-evidence", "fail"]
}
EpiphanyRoleResultRoleId::Implementation | EpiphanyRoleResultRoleId::Reorientation => {
vec![]
EpiphanyRoleResultRoleId::Implementation => {
vec!["commit-created", "needs-proprioception", "blocked"]
}
EpiphanyRoleResultRoleId::Reorientation => vec![],
};
let mut properties = serde_json::json!({
"roleId": {
@ -308,6 +309,65 @@ pub fn epiphany_role_launch_output_schema(role_id: EpiphanyRoleResultRoleId) ->
}
required.push("frontierNodeIds");
required.push("statePatch");
} else if role_id == EpiphanyRoleResultRoleId::Implementation {
if let Some(map) = properties.as_object_mut() {
map.insert(
"branchName".to_string(),
serde_json::json!({
"type": "string",
"description": "Git branch created or used for this bounded Hands turn."
}),
);
map.insert(
"commitSha".to_string(),
serde_json::json!({
"type": "string",
"description": "Commit created by this Hands turn. Empty only when verdict is blocked or needs-proprioception."
}),
);
map.insert(
"changedPaths".to_string(),
serde_json::json!({
"type": "array",
"items": {"type": "string"}
}),
);
map.insert(
"commandsRun".to_string(),
serde_json::json!({
"type": "array",
"items": {"type": "string"}
}),
);
map.insert(
"handsReceiptIds".to_string(),
serde_json::json!({
"type": "array",
"description": "Typed Hands/Substrate/Soul/Mind receipt ids produced or cited by this turn.",
"items": {"type": "string"}
}),
);
map.insert(
"proprioceptionRefreshRequest".to_string(),
serde_json::json!({
"type": "object",
"description": "Required branch-map refresh request for Proprioception after a commit.",
"properties": {
"required": {"type": "boolean"},
"reason": {"type": "string"},
"branchName": {"type": "string"},
"commitSha": {"type": "string"},
"changedPaths": {
"type": "array",
"items": {"type": "string"}
}
},
"additionalProperties": true
}),
);
}
required.push("branchName");
required.push("changedPaths");
}
serde_json::json!({
"type": "object",
@ -496,7 +556,12 @@ pub fn build_epiphany_role_launch_request_with_dynamic_context(
"epiphany.role.verification",
build_epiphany_role_launch_instruction(role_id),
),
EpiphanyRoleResultRoleId::Implementation | EpiphanyRoleResultRoleId::Reorientation => {
EpiphanyRoleResultRoleId::Implementation => (
"role-scoped implementation branch turn",
"epiphany.role.implementation",
build_epiphany_role_launch_instruction(role_id),
),
EpiphanyRoleResultRoleId::Reorientation => {
return Err(epiphany_role_binding_id(role_id).unwrap_err());
}
};
@ -550,15 +615,17 @@ pub fn build_epiphany_role_launch_request_with_dynamic_context(
}
fn build_epiphany_role_launch_instruction(role_id: EpiphanyRoleResultRoleId) -> String {
let prompts = &epiphany_specialist_prompt_config().roles;
let config = epiphany_specialist_prompt_config();
let prompts = &config.roles;
let body = match role_id {
EpiphanyRoleResultRoleId::Imagination => prompts.imagination.as_str(),
EpiphanyRoleResultRoleId::Research => prompts.research.as_str(),
EpiphanyRoleResultRoleId::Modeling => prompts.modeling.as_str(),
EpiphanyRoleResultRoleId::Verification => prompts.verification.as_str(),
EpiphanyRoleResultRoleId::Implementation | EpiphanyRoleResultRoleId::Reorientation => {
"Unsupported Epiphany role specialist template."
EpiphanyRoleResultRoleId::Implementation => {
config.implementation.continue_template.as_str()
}
EpiphanyRoleResultRoleId::Reorientation => "Unsupported Epiphany role specialist template.",
};
epiphany_worker_prompt(body)
}
@ -821,4 +888,57 @@ mod tests {
assert!(!prompt.contains("## Epiphany Persistent Memory"));
assert!(!prompt.contains("Heartbeat: every lane"));
}
#[test]
fn implementation_role_launches_as_hands_branch_turn() {
let state = EpiphanyThreadState {
revision: 12,
objective: Some("Wire Hands branch-turn launches.".to_string()),
..Default::default()
};
let request = build_epiphany_role_launch_request_with_dynamic_context(
"thread-1",
EpiphanyRoleResultRoleId::Implementation,
Some(12),
Some(300),
&state,
Some("Proprioception context: branch map is current.".to_string()),
)
.expect("implementation launch request");
assert_eq!(request.binding_id, EPIPHANY_IMPLEMENTATION_ROLE_BINDING_ID);
assert_eq!(request.owner_role, EPIPHANY_IMPLEMENTATION_OWNER_ROLE);
assert_eq!(request.authority_scope, "epiphany.role.implementation");
assert!(request.scope.contains("implementation branch turn"));
assert!(request.instruction.contains("one commit"));
assert!(request.instruction.contains("Proprioception"));
match request.launch_document {
EpiphanyWorkerLaunchDocument::Role(document) => {
assert_eq!(document.role_id, "implementation");
assert_eq!(
document.dynamic_prompt_context.as_deref(),
Some("Proprioception context: branch map is current.")
);
}
EpiphanyWorkerLaunchDocument::Reorient(_) => panic!("expected role launch document"),
}
}
#[test]
fn implementation_output_schema_requires_branch_turn_evidence() {
let schema = epiphany_role_launch_output_schema(EpiphanyRoleResultRoleId::Implementation);
let required = schema
.get("required")
.and_then(|required| required.as_array())
.expect("required array");
let required_values = required
.iter()
.filter_map(|value| value.as_str())
.collect::<Vec<_>>();
assert!(required_values.contains(&"branchName"));
assert!(required_values.contains(&"changedPaths"));
assert!(schema.to_string().contains("commitSha"));
assert!(schema.to_string().contains("proprioceptionRefreshRequest"));
}
}

View file

@ -55,6 +55,8 @@ const DEFAULT_CARGO_TARGET_DIR: &str = r"C:\Users\Meta\.cargo-target-codex";
const DEFAULT_THREAD_STATE_STORE: &str = "state/thread-state.msgpack";
const DEFAULT_RUNTIME_STORE: &str = "state/runtime-spine.msgpack";
const REORIENT_BINDING_ID: &str = "reorient-worker";
const IMPLEMENTATION_BINDING_ID: &str = "implementation-branch-turn-worker";
const IMPLEMENTATION_OWNER_ROLE: &str = "epiphany-hands";
const IMAGINATION_BINDING_ID: &str = "imagination-synthesis-worker";
const RESEARCH_BINDING_ID: &str = "research-source-gather-worker";
const MODELING_BINDING_ID: &str = "modeling-checkpoint-worker";
@ -310,10 +312,12 @@ fn run_native_status(args: &Args) -> Result<Value> {
.iter()
.find(|job| job.id == REORIENT_BINDING_ID)
.cloned(),
implementation_binding_id: IMPLEMENTATION_BINDING_ID.to_string(),
imagination_binding_id: IMAGINATION_BINDING_ID.to_string(),
research_binding_id: RESEARCH_BINDING_ID.to_string(),
modeling_binding_id: MODELING_BINDING_ID.to_string(),
verification_binding_id: VERIFICATION_BINDING_ID.to_string(),
implementation_owner_role: IMPLEMENTATION_OWNER_ROLE.to_string(),
reorient_owner_role: "epiphany-reorienter".to_string(),
imagination_owner_role: "epiphany-imagination".to_string(),
research_owner_role: "epiphany-eyes".to_string(),

View file

@ -25,6 +25,8 @@ mod thread_state_store;
pub use agent_launch::EPIPHANY_IMAGINATION_OWNER_ROLE;
pub use agent_launch::EPIPHANY_IMAGINATION_ROLE_BINDING_ID;
pub use agent_launch::EPIPHANY_IMPLEMENTATION_OWNER_ROLE;
pub use agent_launch::EPIPHANY_IMPLEMENTATION_ROLE_BINDING_ID;
pub use agent_launch::EPIPHANY_MODELING_OWNER_ROLE;
pub use agent_launch::EPIPHANY_MODELING_ROLE_BINDING_ID;
pub use agent_launch::EPIPHANY_REORIENT_LAUNCH_BINDING_ID;
@ -491,6 +493,7 @@ pub use substrate_gate::SubstrateGateCultNetContract;
pub use substrate_gate::SubstrateGateRepoAccessGrantReceipt;
pub use substrate_gate::default_substrate_gate_cultnet_contracts;
pub use substrate_gate::substrate_gate_repo_access_grant_for_launch;
pub use substrate_gate::substrate_gate_repo_mutation_grant_for_launch;
pub use surfaces::EpiphanyAcceptanceBundle;
pub use surfaces::EpiphanyContext;
pub use surfaces::EpiphanyContextMissing;

View file

@ -162,7 +162,8 @@ You are the Epiphany implementation agent for this repository.
You are the Hands of the machine: the only lane here allowed to touch the code body. The Hands exist to shape the user's objective into source, not to fidget, decorate, or pantomime progress.
The Hands improve themselves by becoming more precise at touch. If the accepted trail is too weak to guide a cut, say so with exact source evidence; if you learn a durable implementation lesson, leave it where the next Hands can use it instead of burying it in a final-summary little coffin.
Continue only the bounded implementation pass recommended by the Epiphany coordinator.
Continue only the bounded implementation branch-turn launched by the Epiphany coordinator.
This turn is launched after Coordinator picks up Imagination consensus on what to implement and injects relevant Proprioception retrieval into the launch context. If the task, consensus, or Proprioception context is missing or stale, stop with verdict `needs-proprioception` or `blocked`; do not cut blind.
Coordinator:
- action: {coordinator_action}
@ -184,6 +185,9 @@ Accepted evidence:
Implementation rules:
- Do not read sealed transcript artifacts or raw specialist result payloads.
- Treat accepted Epiphany state as guidance, then inspect source directly before editing.
- Create or switch to a Git branch for this bounded task before mutating source. Use the repo's branch conventions when present; otherwise use a clear `codex/` branch name.
- Make at most one commit in this turn. After that commit exists, stop and request Proprioception to refresh its branch map before another Hands cut.
- Return the branch name, commit SHA, changed paths, commands run, relevant Hands/Substrate/Soul/Mind receipt ids, and a Proprioception refresh request. If no commit was possible, return the blocker and the source files inspected.
- Touch the code with craft and restraint: make the smallest source-grounded change that moves the objective, and leave marks the verifier can actually read.
- Preserve Epiphany's harness discipline while you work: obey local instruction surfaces such as AGENTS.md, keep edits scoped, use the repo's existing helpers and style, avoid destructive commands, do not revert user changes, and validate the surface you changed.
- Before building a bespoke parser, scheduler, renderer, protocol, storage layer, security mechanism, workflow engine, or algorithm, demand evidence of existing work. Use an accepted Eyes/research finding when present; otherwise perform a bounded scout pass yourself or stop with a concrete request for research. Do not improvise a half-known standard system because your hands are itching.
@ -194,7 +198,7 @@ Implementation rules:
{unity_guidance}
{rider_guidance}
- This is an implementation turn, not a planning turn. Leave a concrete source diff unless direct source evidence proves the bounded pass is impossible.
- Before stopping, check `git status --short`. If it still shows no source diff, return a concrete source-level blocker naming the files inspected and the exact contradiction or missing dependency.
- Before stopping, check `git status --short` and the latest commit. If there is no new commit, return a concrete source-level blocker naming the files inspected and the exact contradiction or missing dependency.
- Keep the change reviewable. Update or add source-local notes/tests if the repo has an established place for them.
- If the source contradicts the checkpoint, stop and explain the contradiction instead of tower-building.
'''

View file

@ -156,6 +156,32 @@ pub fn substrate_gate_repo_access_grant_for_launch(
}
}
pub fn substrate_gate_repo_mutation_grant_for_launch(
receipt_id: String,
runtime_job_id: String,
request: &EpiphanyJobLaunchRequest,
granted_at: String,
) -> SubstrateGateRepoAccessGrantReceipt {
SubstrateGateRepoAccessGrantReceipt {
schema_version: SUBSTRATE_GATE_REPO_ACCESS_GRANT_RECEIPT_SCHEMA_VERSION.to_string(),
receipt_id,
runtime_job_id,
binding_id: request.binding_id.clone(),
role: request.owner_role.clone(),
authority_scope: request.authority_scope.clone(),
granted_operations: vec![
"read".to_string(),
"snapshot".to_string(),
"patch".to_string(),
"command".to_string(),
"commit".to_string(),
],
granted_paths: vec![".".to_string()],
granted_at,
contract: "Substrate Gate granted scoped repository mutation access for one Hands branch-turn. Hands may create or use the branch for the Coordinator task, produce at most one commit, record typed Hands receipts, then stop until Proprioception refreshes the branch map.".to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -235,4 +261,65 @@ mod tests {
assert!(!grant.granted_operations.contains(&"write".to_string()));
assert!(grant.contract.contains("mutation remains forbidden"));
}
#[test]
fn substrate_gate_mutation_grant_for_launch_is_one_hands_branch_turn() {
let request = EpiphanyJobLaunchRequest {
expected_revision: Some(8),
binding_id: "implementation-branch-turn-worker".to_string(),
kind: epiphany_state_model::EpiphanyJobKind::Specialist,
scope: "role-scoped implementation branch turn".to_string(),
owner_role: "epiphany-hands".to_string(),
authority_scope: "epiphany.role.implementation".to_string(),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
instruction: "Make one bounded branch-turn commit.".to_string(),
launch_document: crate::EpiphanyWorkerLaunchDocument::Role(
crate::EpiphanyRoleWorkerLaunchDocument {
thread_id: "thread-1".to_string(),
role_id: "implementation".to_string(),
state_revision: 8,
objective: None,
dynamic_prompt_context: None,
active_subgoal_id: None,
active_subgoals: Vec::new(),
active_graph_node_ids: Vec::new(),
investigation_checkpoint: None,
scratch: None,
invariants: Vec::new(),
graphs: None,
recent_evidence: Vec::new(),
recent_observations: Vec::new(),
graph_frontier: None,
graph_checkpoint: None,
planning: None,
churn: None,
},
),
output_contract_id: crate::ROLE_WORKER_OUTPUT_CONTRACT_ID.to_string(),
organ_launch_contract: crate::default_launch_organ_contract(
"epiphany.role.implementation",
"role",
crate::ROLE_WORKER_OUTPUT_CONTRACT_ID,
),
max_runtime_seconds: None,
};
let grant = substrate_gate_repo_mutation_grant_for_launch(
"grant-2".to_string(),
"job-2".to_string(),
&request,
"2026-06-02T00:00:00Z".to_string(),
);
assert_eq!(grant.role, "epiphany-hands");
assert!(grant.granted_operations.contains(&"patch".to_string()));
assert!(grant.granted_operations.contains(&"command".to_string()));
assert!(grant.granted_operations.contains(&"commit".to_string()));
assert!(grant.contract.contains("one Hands branch-turn"));
assert!(
grant
.contract
.contains("Proprioception refreshes the branch map")
);
}
}

View file

@ -60,10 +60,12 @@ pub struct EpiphanyRoleBoardInput {
pub pressure_level: String,
pub reorient_result_status: EpiphanyCrrcResultStatus,
pub reorient_job: Option<EpiphanyRoleBoardJob>,
pub implementation_binding_id: String,
pub imagination_binding_id: String,
pub research_binding_id: String,
pub modeling_binding_id: String,
pub verification_binding_id: String,
pub implementation_owner_role: String,
pub reorient_owner_role: String,
pub imagination_owner_role: String,
pub research_owner_role: String,
@ -191,7 +193,7 @@ pub fn derive_role_board(input: EpiphanyRoleBoardInput) -> Vec<EpiphanyRoleBoard
EpiphanyRoleBoardLane {
id: EpiphanyCoordinatorRoleId::Implementation,
title: "Implementation".to_string(),
owner_role: "coding-agent".to_string(),
owner_role: input.implementation_owner_role.clone(),
status: if input.crrc_action == EpiphanyCrrcAction::Continue {
EpiphanyCoordinatorRoleStatus::Ready
} else {
@ -206,14 +208,19 @@ pub fn derive_role_board(input: EpiphanyRoleBoardInput) -> Vec<EpiphanyRoleBoard
.jobs
.iter()
.filter(|job| {
matches!(
job.owner_role.as_str(),
"coding-agent" | "implementation" | "epiphany-implementation"
)
job.id == input.implementation_binding_id
|| job.owner_role == input.implementation_owner_role
|| matches!(
job.owner_role.as_str(),
"coding-agent" | "implementation" | "epiphany-implementation"
)
})
.cloned()
.collect(),
authority_scopes: Vec::new(),
authority_scopes: vec![
"thread/epiphany/roleLaunch".to_string(),
"thread/epiphany/roleResult".to_string(),
],
recommended_action: if input.crrc_action == EpiphanyCrrcAction::Continue {
None
} else {
@ -478,10 +485,12 @@ mod tests {
pressure_level: "Low".to_string(),
reorient_result_status: EpiphanyCrrcResultStatus::MissingBinding,
reorient_job: None,
implementation_binding_id: "implementation-branch-turn-worker".to_string(),
imagination_binding_id: "imagination-synthesis-worker".to_string(),
research_binding_id: "research-source-gather-worker".to_string(),
modeling_binding_id: "modeling-checkpoint-worker".to_string(),
verification_binding_id: "verification-review-worker".to_string(),
implementation_owner_role: "epiphany-hands".to_string(),
reorient_owner_role: "epiphany-reorienter".to_string(),
imagination_owner_role: "epiphany-imagination".to_string(),
research_owner_role: "epiphany-eyes".to_string(),