diff --git a/Cargo.toml b/Cargo.toml index da7991ee..4f7c6291 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,10 +97,6 @@ path = "epiphany-core/src/bin/epiphany-persona-discord-permit.rs" name = "epiphany-mvp-coordinator" path = "epiphany-core/src/bin/epiphany-mvp-coordinator.rs" -[[bin]] -name = "epiphany-hands-action" -path = "epiphany-core/src/bin/epiphany-hands-action.rs" - [[bin]] name = "epiphany-model-runtime" path = "epiphany-openai-runtime/src/bin/epiphany-model-runtime.rs" diff --git a/epiphany-core/src/bin/epiphany-hands-action.rs b/epiphany-core/src/bin/epiphany-hands-action.rs deleted file mode 100644 index 27e36e9c..00000000 --- a/epiphany-core/src/bin/epiphany-hands-action.rs +++ /dev/null @@ -1,879 +0,0 @@ -use anyhow::Context; -use anyhow::Result; -use anyhow::anyhow; -use chrono::SecondsFormat; -use epiphany_core::HandsActionIntent; -use epiphany_core::HandsActionReview; -use epiphany_core::hands_command_receipt_for_review; -use epiphany_core::hands_commit_receipt_for_review; -use epiphany_core::hands_patch_receipt_for_review; -use epiphany_core::put_hands_command_receipt; -use epiphany_core::put_hands_commit_receipt; -use epiphany_core::put_hands_patch_receipt; -use epiphany_core::relinquish_repo_frontier_hands_route; -use epiphany_core::runtime_hands_action_intent; -use epiphany_core::runtime_hands_action_review; -use serde_json::json; -use std::env; -use std::path::PathBuf; - -const DEFAULT_STORE: &str = "state/runtime-spine.msgpack"; - -fn main() -> Result<()> { - let args = Args::parse()?; - let output = match args.command { - Command::RecordPatch(command) => record_patch(&args.store, command)?, - Command::RecordCommand(command) => record_command(&args.store, command)?, - Command::RecordCommit(command) => record_commit(&args.store, command)?, - Command::RecordPass(command) => record_pass(&args.store, command)?, - Command::RecordRefusal(command) => record_refusal(&args.store, command)?, - }; - println!("{}", serde_json::to_string_pretty(&output)?); - Ok(()) -} - -#[derive(Debug)] -struct Args { - store: PathBuf, - command: Command, -} - -#[derive(Debug)] -enum Command { - RecordPatch(RecordPatchArgs), - RecordCommand(RecordCommandArgs), - RecordCommit(RecordCommitArgs), - RecordPass(RecordPassArgs), - RecordRefusal(RecordRefusalArgs), -} - -#[derive(Debug, Clone)] -struct GateArgs { - intent_id: String, - review_id: String, - receipt_id: Option, - summary: String, -} - -#[derive(Debug)] -struct RecordPatchArgs { - gate: GateArgs, - changed_paths: Vec, -} - -#[derive(Debug)] -struct RecordCommandArgs { - gate: GateArgs, - command: String, - exit_code: String, - stdout_artifact: String, - stderr_artifact: String, -} - -#[derive(Debug)] -struct RecordCommitArgs { - gate: GateArgs, - commit_sha: String, - branch: String, - changed_paths: Vec, - validate_commit_sha: bool, -} - -#[derive(Debug)] -struct RecordPassArgs { - gate: GateArgs, - command: String, - exit_code: String, - stdout_artifact: String, - stderr_artifact: String, - commit_sha: String, - branch: String, - changed_paths: Vec, - validate_commit_sha: bool, -} - -#[derive(Debug)] -struct RecordRefusalArgs { - gate: GateArgs, - missing_required_paths: Vec, -} - -impl Args { - fn parse() -> Result { - let mut tokens = env::args().skip(1).peekable(); - let mut store = PathBuf::from(DEFAULT_STORE); - while matches!(tokens.peek().map(String::as_str), Some("--store")) { - tokens.next(); - store = PathBuf::from(take_value(&mut tokens, "--store")?); - } - let command_name = tokens.next().ok_or_else(|| anyhow!("{}", usage()))?; - let command = match command_name.as_str() { - "record-patch" => Command::RecordPatch(parse_record_patch(tokens)?), - "record-command" => Command::RecordCommand(parse_record_command(tokens)?), - "record-commit" => Command::RecordCommit(parse_record_commit(tokens)?), - "record-pass" => Command::RecordPass(parse_record_pass(tokens)?), - "record-refusal" => Command::RecordRefusal(parse_record_refusal(tokens)?), - _ => return Err(anyhow!("unknown command {command_name}\n{}", usage())), - }; - Ok(Self { store, command }) - } -} - -fn parse_record_refusal(tokens: impl Iterator) -> Result { - let mut options = ParsedOptions::parse(tokens)?; - let gate = options.take_gate()?; - let missing_required_paths = options.take_many("--missing-required-path"); - options.finish()?; - if missing_required_paths.is_empty() { - return Err(anyhow!( - "record-refusal requires at least one --missing-required-path" - )); - } - Ok(RecordRefusalArgs { - gate, - missing_required_paths, - }) -} - -fn parse_record_patch(tokens: impl Iterator) -> Result { - let mut options = ParsedOptions::parse(tokens)?; - let gate = options.take_gate()?; - let changed_paths = options.take_many("--changed-path"); - options.finish()?; - if changed_paths.is_empty() { - return Err(anyhow!("record-patch requires at least one --changed-path")); - } - Ok(RecordPatchArgs { - gate, - changed_paths, - }) -} - -fn parse_record_command(tokens: impl Iterator) -> Result { - let mut options = ParsedOptions::parse(tokens)?; - let gate = options.take_gate()?; - let command = options.take_required("--command")?; - let exit_code = options.take_required("--exit-code")?; - let stdout_artifact = options.take_required("--stdout-artifact")?; - let stderr_artifact = options.take_required("--stderr-artifact")?; - options.finish()?; - Ok(RecordCommandArgs { - gate, - command, - exit_code, - stdout_artifact, - stderr_artifact, - }) -} - -fn parse_record_commit(tokens: impl Iterator) -> Result { - let mut options = ParsedOptions::parse(tokens)?; - let gate = options.take_gate()?; - let commit_sha = options.take_required("--commit-sha")?; - let branch = options.take_required("--branch")?; - let changed_paths = options.take_many("--changed-path"); - options.finish()?; - if changed_paths.is_empty() { - return Err(anyhow!( - "record-commit requires at least one --changed-path" - )); - } - Ok(RecordCommitArgs { - gate, - commit_sha, - branch, - changed_paths, - validate_commit_sha: true, - }) -} - -fn parse_record_pass(tokens: impl Iterator) -> Result { - let mut options = ParsedOptions::parse(tokens)?; - let gate = options.take_gate()?; - let command = options.take_required("--command")?; - let exit_code = options.take_required("--exit-code")?; - let stdout_artifact = options.take_required("--stdout-artifact")?; - let stderr_artifact = options.take_required("--stderr-artifact")?; - let commit_sha = options.take_required("--commit-sha")?; - let branch = options.take_required("--branch")?; - let changed_paths = options.take_many("--changed-path"); - options.finish()?; - if changed_paths.is_empty() { - return Err(anyhow!("record-pass requires at least one --changed-path")); - } - Ok(RecordPassArgs { - gate, - command, - exit_code, - stdout_artifact, - stderr_artifact, - commit_sha, - branch, - changed_paths, - validate_commit_sha: true, - }) -} - -#[derive(Debug, Default)] -struct ParsedOptions { - values: Vec<(String, String)>, -} - -impl ParsedOptions { - fn parse(tokens: impl Iterator) -> Result { - let mut values = Vec::new(); - let mut tokens = tokens.peekable(); - while let Some(name) = tokens.next() { - if !name.starts_with("--") { - return Err(anyhow!("unexpected positional argument {name}")); - } - let value = take_value(&mut tokens, &name)?; - values.push((name, value)); - } - Ok(Self { values }) - } - - fn take_gate(&mut self) -> Result { - Ok(GateArgs { - intent_id: self.take_required("--intent-id")?, - review_id: self.take_required("--review-id")?, - receipt_id: self.take_optional("--receipt-id"), - summary: self.take_required("--summary")?, - }) - } - - fn take_required(&mut self, name: &str) -> Result { - self.take_optional(name) - .ok_or_else(|| anyhow!("{name} is required")) - } - - fn take_optional(&mut self, name: &str) -> Option { - let index = self - .values - .iter() - .position(|(candidate, _)| candidate == name)?; - Some(self.values.remove(index).1) - } - - fn take_many(&mut self, name: &str) -> Vec { - let mut taken = Vec::new(); - let mut index = 0; - while index < self.values.len() { - if self.values[index].0 == name { - taken.push(self.values.remove(index).1); - } else { - index += 1; - } - } - taken - } - - fn finish(self) -> Result<()> { - if self.values.is_empty() { - return Ok(()); - } - let names: Vec<_> = self.values.into_iter().map(|(name, _)| name).collect(); - Err(anyhow!("unsupported arguments: {}", names.join(", "))) - } -} - -fn record_patch(store: &PathBuf, args: RecordPatchArgs) -> Result { - let (intent, review) = load_gate(store, &args.gate, "patch")?; - validate_paths_within_gate(&intent, &args.changed_paths)?; - let receipt_id = args - .gate - .receipt_id - .unwrap_or_else(|| generated_receipt_id("hands-patch")); - let receipt = hands_patch_receipt_for_review( - receipt_id, - &intent, - &review, - normalize_paths(args.changed_paths), - args.gate.summary, - now(), - ); - put_hands_patch_receipt(store, &receipt)?; - Ok(json!({ - "status": "ok", - "type": "epiphany.hands.patch_receipt", - "receiptId": receipt.receipt_id, - "intentId": receipt.intent_id, - "reviewId": receipt.review_id, - "changedPaths": receipt.changed_paths, - "store": store, - })) -} - -fn record_command(store: &PathBuf, args: RecordCommandArgs) -> Result { - let (intent, review) = load_gate(store, &args.gate, "command")?; - let receipt_id = args - .gate - .receipt_id - .unwrap_or_else(|| generated_receipt_id("hands-command")); - let receipt = hands_command_receipt_for_review( - receipt_id, - &intent, - &review, - args.command, - args.exit_code, - normalize_path(&args.stdout_artifact), - normalize_path(&args.stderr_artifact), - args.gate.summary, - now(), - ); - put_hands_command_receipt(store, &receipt)?; - Ok(json!({ - "status": "ok", - "type": "epiphany.hands.command_receipt", - "receiptId": receipt.receipt_id, - "intentId": receipt.intent_id, - "reviewId": receipt.review_id, - "command": receipt.command, - "exitCode": receipt.exit_code, - "stdoutArtifact": receipt.stdout_artifact, - "stderrArtifact": receipt.stderr_artifact, - "store": store, - })) -} - -fn record_commit(store: &PathBuf, args: RecordCommitArgs) -> Result { - let (intent, review) = load_gate(store, &args.gate, "commit")?; - validate_paths_within_gate(&intent, &args.changed_paths)?; - let commit_sha = if args.validate_commit_sha { - resolve_git_commit_sha(&args.commit_sha)? - } else { - args.commit_sha - }; - let receipt_id = args - .gate - .receipt_id - .unwrap_or_else(|| generated_receipt_id("hands-commit")); - let receipt = hands_commit_receipt_for_review( - receipt_id, - &intent, - &review, - commit_sha, - args.branch, - normalize_paths(args.changed_paths), - args.gate.summary, - now(), - ); - put_hands_commit_receipt(store, &receipt)?; - Ok(json!({ - "status": "ok", - "type": "epiphany.hands.commit_receipt", - "receiptId": receipt.receipt_id, - "intentId": receipt.intent_id, - "reviewId": receipt.review_id, - "commitSha": receipt.commit_sha, - "branch": receipt.branch, - "changedPaths": receipt.changed_paths, - "store": store, - })) -} - -fn record_pass(store: &PathBuf, args: RecordPassArgs) -> Result { - let patch = record_patch( - store, - RecordPatchArgs { - gate: pass_gate(&args.gate, "patch"), - changed_paths: args.changed_paths.clone(), - }, - )?; - let command = record_command( - store, - RecordCommandArgs { - gate: pass_gate(&args.gate, "command"), - command: args.command, - exit_code: args.exit_code, - stdout_artifact: args.stdout_artifact, - stderr_artifact: args.stderr_artifact, - }, - )?; - let commit = record_commit( - store, - RecordCommitArgs { - gate: pass_gate(&args.gate, "commit"), - commit_sha: args.commit_sha, - branch: args.branch, - changed_paths: args.changed_paths, - validate_commit_sha: args.validate_commit_sha, - }, - )?; - Ok(json!({ - "status": "ok", - "type": "epiphany.hands.action_pass_receipts", - "patch": patch, - "command": command, - "commit": commit, - })) -} - -fn record_refusal(store: &PathBuf, args: RecordRefusalArgs) -> Result { - let receipt_id = args - .gate - .receipt_id - .unwrap_or_else(|| generated_receipt_id("hands-refusal")); - let receipt = relinquish_repo_frontier_hands_route( - store, - &args.gate.intent_id, - &args.gate.review_id, - &receipt_id, - normalize_paths(args.missing_required_paths), - args.gate.summary, - now(), - )?; - Ok(json!({ - "status": "ok", - "type": "epiphany.mind.repo_frontier_relinquishment_receipt", - "receiptId": receipt.receipt_id, - "handsRefusalReceiptId": receipt.hands_refusal_receipt_id, - "routeId": receipt.route_id, - "frontierItemId": receipt.frontier_item_id, - "previousModelProjectionDigest": receipt.previous_model_projection_digest, - "previousModelSourceDocuments": receipt.previous_model_source_documents, - "admittedModelProjectionDigest": receipt.admitted_model_projection_digest, - "admittedModelSourceDocuments": receipt.admitted_model_source_documents, - "store": store, - })) -} - -fn pass_gate(gate: &GateArgs, operation: &str) -> GateArgs { - let mut gate = gate.clone(); - gate.receipt_id = None; - gate.summary = format!("{} ({operation})", gate.summary); - gate -} - -fn load_gate( - store: &PathBuf, - gate: &GateArgs, - operation: &str, -) -> Result<(HandsActionIntent, HandsActionReview)> { - let intent = runtime_hands_action_intent(store, &gate.intent_id) - .with_context(|| format!("failed to load Hands intent {}", gate.intent_id))? - .ok_or_else(|| anyhow!("Hands intent {} was not found", gate.intent_id))?; - let review = runtime_hands_action_review(store, &gate.review_id) - .with_context(|| format!("failed to load Hands review {}", gate.review_id))? - .ok_or_else(|| anyhow!("Hands review {} was not found", gate.review_id))?; - if review.intent_id != intent.intent_id { - return Err(anyhow!( - "Hands review {} belongs to intent {}, not {}", - review.review_id, - review.intent_id, - intent.intent_id - )); - } - if review.decision != "approved" { - return Err(anyhow!( - "Hands review {} decision is {}, not approved", - review.review_id, - review.decision - )); - } - if !review - .allowed_operations - .iter() - .any(|allowed| allowed == operation) - { - return Err(anyhow!( - "Hands review {} does not allow {operation}", - review.review_id - )); - } - Ok((intent, review)) -} - -fn validate_paths_within_gate(intent: &HandsActionIntent, paths: &[String]) -> Result<()> { - let requested = normalize_paths(intent.requested_paths.clone()); - if requested.iter().any(|path| path == ".") { - return Ok(()); - } - for path in normalize_paths(paths.to_vec()) { - if !requested - .iter() - .any(|allowed| path == *allowed || path.starts_with(&format!("{allowed}/"))) - { - return Err(anyhow!( - "changed path {path} is outside Hands requested paths: {}", - requested.join(", ") - )); - } - } - Ok(()) -} - -fn normalize_paths(paths: Vec) -> Vec { - let mut normalized: Vec<_> = paths - .into_iter() - .map(|path| normalize_path(&path)) - .filter(|path| !path.is_empty()) - .collect(); - normalized.sort(); - normalized.dedup(); - normalized -} - -fn normalize_path(path: &str) -> String { - path.trim().replace('\\', "/") -} - -fn resolve_git_commit_sha(commit_sha: &str) -> Result { - let output = std::process::Command::new("git") - .arg("rev-parse") - .arg("--verify") - .arg(format!("{commit_sha}^{{commit}}")) - .output() - .map_err(|err| anyhow!("failed to start git rev-parse for Hands commit receipt: {err}"))?; - if !output.status.success() { - let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string(); - return Err(anyhow!( - "Hands commit receipt references non-existent commit {commit_sha:?}: {stderr}" - )); - } - let resolved = String::from_utf8(output.stdout) - .map_err(|err| anyhow!("git rev-parse returned non-UTF8 commit sha: {err}"))? - .trim() - .to_string(); - if resolved.is_empty() { - return Err(anyhow!( - "git rev-parse returned an empty commit sha for {commit_sha:?}" - )); - } - Ok(resolved) -} - -fn generated_receipt_id(prefix: &str) -> String { - format!("{prefix}-{}", uuid::Uuid::new_v4()) -} - -fn now() -> String { - chrono::Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true) -} - -fn take_value(tokens: &mut impl Iterator, name: &str) -> Result { - tokens - .next() - .ok_or_else(|| anyhow!("{name} requires a value")) -} - -fn usage() -> &'static str { - "usage: epiphany-hands-action [--store path] --intent-id id --review-id id --summary text ..." -} - -#[cfg(test)] -mod tests { - use super::*; - use epiphany_core::EpiphanyRepoModelSeed; - use epiphany_core::EpiphanyRepoModelSeedDocuments; - use epiphany_core::HANDS_ACTION_INTENT_SCHEMA_VERSION; - use epiphany_core::RepoFrontierHandsAuthority; - use epiphany_core::RuntimeSpineInitOptions; - use epiphany_core::bind_repository_body; - use epiphany_core::bind_runtime_to_swarm; - use epiphany_core::hands_action_review_for_intent; - use epiphany_core::initialize_keyed_repo_model; - use epiphany_core::initialize_runtime_spine; - use epiphany_core::observe_runtime_repository_body_basis; - use epiphany_core::put_hands_action_intent; - use epiphany_core::put_hands_action_review; - use epiphany_core::put_repo_frontier_hands_authority; - use epiphany_core::runtime_hands_command_receipt; - use epiphany_core::runtime_hands_commit_receipt; - use epiphany_core::runtime_hands_patch_receipt; - use epiphany_core::select_and_commit_repo_frontier_route; - use epiphany_state_model::EpiphanyMemoryDomain; - use epiphany_state_model::EpiphanyMemoryLifecycle; - use epiphany_state_model::EpiphanyMemoryNode; - use epiphany_state_model::EpiphanyMemoryNodeKind; - use epiphany_state_model::RepoFrontierAdoptedPlan; - use epiphany_state_model::RepoFrontierItem; - use epiphany_state_model::RepoFrontierStatus; - use std::process::Command as ProcessCommand; - - #[test] - fn records_patch_command_and_commit_receipts_against_approved_gate() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("runtime-spine.msgpack"); - seed_gate(&store, vec!["src".to_string()])?; - - record_patch( - &store, - RecordPatchArgs { - gate: gate_args("hands-patch-test"), - changed_paths: vec!["src/lib.rs".to_string()], - }, - )?; - record_command( - &store, - RecordCommandArgs { - gate: gate_args("hands-command-test"), - command: "cargo test".to_string(), - exit_code: "0".to_string(), - stdout_artifact: ".epiphany/stdout.log".to_string(), - stderr_artifact: ".epiphany/stderr.log".to_string(), - }, - )?; - record_commit( - &store, - RecordCommitArgs { - gate: gate_args("hands-commit-test"), - commit_sha: "abc123".to_string(), - branch: "codex/test".to_string(), - changed_paths: vec!["src/lib.rs".to_string()], - validate_commit_sha: false, - }, - )?; - - assert!(runtime_hands_patch_receipt(&store, "hands-patch-test")?.is_some()); - assert!(runtime_hands_command_receipt(&store, "hands-command-test")?.is_some()); - assert!(runtime_hands_commit_receipt(&store, "hands-commit-test")?.is_some()); - Ok(()) - } - - #[test] - fn refuses_commit_receipt_for_unknown_git_sha() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("runtime-spine.msgpack"); - seed_gate(&store, vec!["src".to_string()])?; - - let result = record_commit( - &store, - RecordCommitArgs { - gate: gate_args("hands-commit-test"), - commit_sha: "0000000000000000000000000000000000000000".to_string(), - branch: "codex/test".to_string(), - changed_paths: vec!["src/lib.rs".to_string()], - validate_commit_sha: true, - }, - ); - - assert!(result.is_err()); - assert!(runtime_hands_commit_receipt(&store, "hands-commit-test")?.is_none()); - Ok(()) - } - - #[test] - fn refuses_patch_receipt_outside_requested_paths() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("runtime-spine.msgpack"); - seed_gate(&store, vec!["src".to_string()])?; - - let result = record_patch( - &store, - RecordPatchArgs { - gate: gate_args("hands-patch-test"), - changed_paths: vec!["notes/other.md".to_string()], - }, - ); - - assert!(result.is_err()); - Ok(()) - } - - #[test] - fn refuses_command_when_review_does_not_allow_operation() -> Result<()> { - let temp = tempfile::tempdir()?; - let store = temp.path().join("runtime-spine.msgpack"); - seed_gate_with_operations(&store, vec!["src".to_string()], vec!["patch".to_string()])?; - - let result = record_command( - &store, - RecordCommandArgs { - gate: gate_args("hands-command-test"), - command: "cargo test".to_string(), - exit_code: "0".to_string(), - stdout_artifact: ".epiphany/stdout.log".to_string(), - stderr_artifact: ".epiphany/stderr.log".to_string(), - }, - ); - - assert!(result.is_err()); - Ok(()) - } - - fn seed_gate(store: &PathBuf, requested_paths: Vec) -> Result<()> { - seed_gate_with_operations( - store, - requested_paths, - vec![ - "patch".to_string(), - "command".to_string(), - "commit".to_string(), - ], - ) - } - - fn seed_gate_with_operations( - store: &PathBuf, - requested_paths: Vec, - operations: Vec, - ) -> Result<()> { - initialize_runtime_spine( - store, - RuntimeSpineInitOptions { - runtime_id: "epiphany-hands-action-test".to_string(), - display_name: "Epiphany Hands Action Test".to_string(), - created_at: "2026-06-02T00:00:00Z".to_string(), - }, - )?; - let fixture_root = store - .parent() - .ok_or_else(|| anyhow!("Hands test store has no fixture root"))?; - let body_store = fixture_root.join("body.cc"); - let repo = fixture_root.join("workspace"); - std::fs::create_dir_all(repo.join("src"))?; - std::fs::write(repo.join("src/lib.rs"), "pub fn fixture() {}\n")?; - let git = ProcessCommand::new("git") - .args(["init", "-q"]) - .current_dir(&repo) - .status()?; - if !git.success() { - return Err(anyhow!("Hands test fixture could not initialize Git Body")); - } - bind_runtime_to_swarm(store, "hands-action-test-swarm", "2026-06-02T00:00:00.100Z")?; - bind_repository_body(&repo, &body_store, store, "hands-action-test-workspace")?; - let body = observe_runtime_repository_body_basis(store)?; - let domain = EpiphanyMemoryDomain { - id: "hands-action-domain".into(), - title: "Hands action fixture".into(), - lifecycle: EpiphanyMemoryLifecycle::Accepted, - ..Default::default() - }; - let node = EpiphanyMemoryNode { - id: "hands-action-node".into(), - domain_id: domain.id.clone(), - kind: EpiphanyMemoryNodeKind::Module, - title: "Hands action CLI".into(), - claim: "Hands consequences require exact frontier authority.".into(), - question: "Can the CLI record the adopted consequence?".into(), - action_implication: "Exercise the exact typed route.".into(), - source_hashes: vec!["anchor:missing".into()], - lifecycle: EpiphanyMemoryLifecycle::Accepted, - ..Default::default() - }; - let planned_action = if operations == ["patch"] { - "patch" - } else { - "continueImplementation" - }; - let frontier = RepoFrontierItem { - id: "hands-action-frontier".into(), - migration_body: "repo".into(), - question: "Can Hands record the approved consequence?".into(), - gap: "The CLI path needs its exact adopted route.".into(), - target_claim_ids: vec![node.id.clone()], - repository_scope: requested_paths.clone(), - recommended_next_organ: "Hands".into(), - adopted_plan: Some(RepoFrontierAdoptedPlan { - planning_request_id: "hands-action-planning-request".into(), - result_id: "hands-action-plan-result".into(), - job_id: "hands-action-plan-job".into(), - candidate_id: "hands-action-plan-candidate".into(), - candidate_sha256: - "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".into(), - safe_paths: requested_paths.clone(), - action: planned_action.into(), - command: "cargo test".into(), - checks: vec!["cargo test".into()], - stop_conditions: vec!["A check fails.".into()], - rollback_steps: vec!["Revert the fixture change.".into()], - commit_message: "Exercise exact Hands authority".into(), - }), - status: RepoFrontierStatus::Active, - ..Default::default() - }; - initialize_keyed_repo_model( - store, - &EpiphanyRepoModelSeed::new( - "hands-action-model-seed", - "hands-action-graph", - "hands-action-test-swarm", - "hands-action-test-workspace", - body.body_binding_sha256, - EpiphanyRepoModelSeedDocuments { - domains: vec![domain], - nodes: vec![node], - edges: Vec::new(), - frontier: vec![frontier], - }, - )?, - "2026-06-02T00:00:00.900Z", - )?; - let route = select_and_commit_repo_frontier_route(store, "2026-06-02T00:00:00.950Z")?; - let grant = epiphany_core::substrate_gate_coordinator_implementation_grant( - "substrate-grant-test".to_string(), - "hands-job-test".to_string(), - requested_paths.clone(), - "2026-06-02T00:00:00Z".to_string(), - ); - epiphany_core::put_substrate_gate_repo_access_grant_receipt(store, &grant)?; - let requested_action = if operations == ["patch"] { - "patch" - } else { - "continueImplementation" - }; - let intent = HandsActionIntent { - schema_version: HANDS_ACTION_INTENT_SCHEMA_VERSION.to_string(), - intent_id: "hands-intent-test".to_string(), - runtime_job_id: "hands-job-test".to_string(), - binding_id: "implementation-worker".to_string(), - role: "epiphany-hands".to_string(), - authority_scope: "epiphany.role.implementation".to_string(), - requested_action: requested_action.to_string(), - requested_paths, - substrate_gate_grant_receipt_id: "substrate-grant-test".to_string(), - requested_at: "2026-06-02T00:00:01Z".to_string(), - contract: "Test Hands intent.".to_string(), - frontier_route_id: route.route_id.clone(), - plan_candidate_sha256: route - .adopted_plan - .as_ref() - .map(|plan| plan.candidate_sha256.clone()) - .unwrap_or_default(), - plan_action: route - .adopted_plan - .as_ref() - .map(|plan| plan.effective_action().to_string()) - .unwrap_or_default(), - }; - put_hands_action_intent(store, &intent)?; - let review = hands_action_review_for_intent( - "hands-review-test".to_string(), - &intent, - "approved".to_string(), - operations, - vec!["test gate".to_string()], - "2026-06-02T00:00:02Z".to_string(), - ); - put_hands_action_review(store, &review)?; - put_repo_frontier_hands_authority( - store, - &RepoFrontierHandsAuthority { - schema_version: epiphany_core::REPO_FRONTIER_HANDS_AUTHORITY_SCHEMA_VERSION.into(), - authority_id: "repo-frontier-hands-authority-test".into(), - route_id: route.route_id, - model_projection_digest: route.model_projection_digest, - model_source_documents: route.model_source_documents, - frontier_item_id: route.frontier_item_id, - frontier_item_hash: route.frontier_item_hash, - hands_intent_id: intent.intent_id, - hands_review_id: review.review_id, - substrate_grant_receipt_id: grant.receipt_id, - requested_paths: route.authorized_paths, - granted_at: review.reviewed_at, - contract: epiphany_core::REPO_FRONTIER_HANDS_AUTHORITY_CONTRACT.into(), - }, - )?; - Ok(()) - } - - fn gate_args(receipt_id: &str) -> GateArgs { - GateArgs { - intent_id: "hands-intent-test".to_string(), - review_id: "hands-review-test".to_string(), - receipt_id: Some(receipt_id.to_string()), - summary: "test receipt".to_string(), - } - } -} diff --git a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs index 9a44ae8a..621753ec 100644 --- a/epiphany-core/src/bin/epiphany-mvp-coordinator.rs +++ b/epiphany-core/src/bin/epiphany-mvp-coordinator.rs @@ -1681,7 +1681,7 @@ fn record_hands_implementation_gate( put_repo_frontier_hands_authority(runtime_store, &authority)?; Ok(json!({ - "status": "ready", + "status": "awaitingHandsExecutor", "runtimeJobId": runtime_job_id, "substrateGateGrantReceiptId": grant_id, "intentId": intent.intent_id, @@ -1700,54 +1700,10 @@ fn record_hands_implementation_gate( "plannedStopConditions": route.adopted_plan.as_ref().map(|plan| plan.stop_conditions.as_slice()), "plannedRollbackSteps": route.adopted_plan.as_ref().map(|plan| plan.rollback_steps.as_slice()), "plannedCommitMessage": route.adopted_plan.as_ref().map(|plan| plan.commit_message.as_str()), - "recordPassCommand": hands_record_pass_command( - runtime_store, - &intent.intent_id, - &review.review_id, - route.adopted_plan.as_ref(), - ), "store": runtime_store, })) } -fn hands_record_pass_command( - runtime_store: &Path, - intent_id: &str, - review_id: &str, - adopted_plan: Option<&epiphany_core::RepoFrontierAdoptedPlan>, -) -> Value { - json!({ - "executable": "epiphany-hands-action", - "args": [ - "--store", - runtime_store, - "record-pass", - "--intent-id", - intent_id, - "--review-id", - review_id, - "--summary", - "", - "--changed-path", - "", - "--command", - adopted_plan - .map(|plan| plan.effective_command()) - .unwrap_or(""), - "--exit-code", - "", - "--stdout-artifact", - "", - "--stderr-artifact", - "", - "--commit-sha", - "", - "--branch", - "" - ], - }) -} - fn accept_reorient(runtime_store: &Path) -> Result { let work = epiphany_core::project_current_work(runtime_store)? .reorientation diff --git a/epiphany-release-construction/src/lib.rs b/epiphany-release-construction/src/lib.rs index b8ca0891..90dee423 100644 --- a/epiphany-release-construction/src/lib.rs +++ b/epiphany-release-construction/src/lib.rs @@ -92,7 +92,6 @@ pub fn required_packaged_release_binaries(target_triple: &str) -> Vec<(&'static file_name("epiphany-persona-discord-permit"), ), ("coordinator", file_name("epiphany-mvp-coordinator")), - ("hands-action", file_name("epiphany-hands-action")), ("model-runtime", file_name("epiphany-model-runtime")), ("tool-mcp-runtime", file_name("epiphany-tool-mcp-runtime")), ] diff --git a/notes/hands-cultnet-contracts.md b/notes/hands-cultnet-contracts.md index 7c7a8ccd..2eb01938 100644 --- a/notes/hands-cultnet-contracts.md +++ b/notes/hands-cultnet-contracts.md @@ -47,7 +47,7 @@ Pull-request or other remote publication is not an Epiphany-owned Hands receipt. The remote provider/Bifrost crossing owns its exact publication evidence; Epiphany may consume that provider-owned receipt after the local commit exists. -## Executable Slice +## Admission Slice The first runtime-spine proof chain now exists: @@ -64,14 +64,16 @@ HandsActionIntent command, and commit receipts from the runtime-spine CultCache store. The launch organ contract's repo-action proof profile now requires the full Hands chain, not only the final patch receipt. -`epiphany-mvp-coordinator` now turns `continueImplementation` into a persisted -Substrate Gate grant plus Hands intent/review gate and exposes the receipt ids in -the operator step. -`epiphany-hands-action` is the first native consequence recorder for that gate: -`record-patch`, `record-command`, and `record-commit` load the stored -intent/review, reject mismatches, require an approved review, enforce allowed -operations, and keep patch/commit changed paths inside the requested scope. -Focused `epiphany-hands-action` tests prove that the live packaged recorder -refuses wrong authority, scope escape, and substituted consequence cargo. The -separate main-only smoke executables were deleted; they were compiled by Cargo -but did not participate in the Rust test harness. +`epiphany-mvp-coordinator` turns `continueImplementation` into a persisted +Substrate Gate grant plus Hands intent/review gate and exposes the exact receipt +identities required by downstream Verification. + +Epiphany currently has no admitted repository actuator. The former +`epiphany-hands-action` executable only accepted operator-authored descriptions +of consequences that had already happened; it executed no patch, command, or +commit and had no runtime caller. It was deleted rather than allow receipt +recording to impersonate Hands. A future actuator must execute the approved +operation itself and atomically emit the exact typed receipts from what it +actually observed. Until then, the coordinator reports +`awaitingHandsExecutor`, and no local implementation consequence can be +terminalized by this slice.