99from pathlib import Path
1010from typing import Any
1111
12+ from .cognition import get_cognition_obligation
1213from .runtime import ExecutionResult
1314
1415
@@ -44,6 +45,7 @@ def write_bundle(
4445 result_payload = result .to_dict ()
4546 contract_metadata = self ._contract_metadata (result )
4647 contract_counts = self ._contract_counts (contract_metadata )
48+ kernel_handoff_payload = self ._kernel_handoff_payload (contract_metadata )
4749
4850 artifact_files = [
4951 "summary.json" ,
@@ -57,6 +59,7 @@ def write_bundle(
5759 "obligations.json" ,
5860 "falsification-gates.json" ,
5961 "claim-boundaries.json" ,
62+ "kernel-handoff.json" ,
6063 "outputs.txt" ,
6164 "replies.txt" ,
6265 "assurance-claims.md" ,
@@ -104,6 +107,9 @@ def write_bundle(
104107 "contract_falsification_gates" : contract_counts [
105108 "falsification_gates"
106109 ],
110+ "kernel_handoff_packages" : len (
111+ kernel_handoff_payload ["packages" ]
112+ ),
107113 },
108114 "variables" : result_payload ["variables" ],
109115 "memory" : result_payload ["memory" ],
@@ -137,6 +143,12 @@ def write_bundle(
137143 self ._claim_boundaries_payload (contract_metadata ),
138144 )
139145 )
146+ files .append (
147+ self ._write_json (
148+ output_dir / "kernel-handoff.json" ,
149+ kernel_handoff_payload ,
150+ )
151+ )
140152 files .append (self ._write_text (output_dir / "outputs.txt" , "\n " .join (result .outputs ) + "\n " ))
141153 files .append (self ._write_text (output_dir / "replies.txt" , "\n " .join (result .replies ) + "\n " ))
142154 files .append (self ._write_text (output_dir / "assurance-claims.md" , self ._claims_text (result )))
@@ -233,6 +245,66 @@ def _claim_boundaries_payload(self, metadata: dict[str, Any]) -> dict[str, Any]:
233245 "attempts" : attempts ,
234246 }
235247
248+ def _kernel_handoff_payload (self , metadata : dict [str , Any ]) -> dict [str , Any ]:
249+ packages : list [dict [str , Any ]] = []
250+
251+ for attempt in self ._attempts (metadata ):
252+ attempt_name = str (attempt .get ("name" , "" ))
253+ target_handoffs = [
254+ handoff
255+ for handoff in self ._handoff_contracts (attempt )
256+ if handoff .get ("target" ) == "IX-CognitionKernel"
257+ ]
258+
259+ for handoff in target_handoffs :
260+ packages .append (
261+ {
262+ "attempt" : attempt_name ,
263+ "target" : "IX-CognitionKernel" ,
264+ "schema" : handoff .get ("schema" ),
265+ "source" : handoff .get ("source" ),
266+ "runtime_semantics" : metadata .get ("runtime_semantics" ),
267+ "execution_authority" : "none" ,
268+ "self_certification_allowed" : False ,
269+ "human_authority_required" : bool (
270+ attempt .get ("human_approval_required" , [])
271+ ),
272+ "purpose" : list (attempt .get ("purpose" , [])),
273+ "non_goals" : list (attempt .get ("non_goals" , [])),
274+ "claim_boundaries" : list (attempt .get ("claim_boundaries" , [])),
275+ "human_approval_required" : list (
276+ attempt .get ("human_approval_required" , [])
277+ ),
278+ "obligations" : [
279+ self ._kernel_obligation_payload (obligation )
280+ for obligation in self ._obligations (attempt )
281+ ],
282+ }
283+ )
284+
285+ return {
286+ "schema_version" : "1.0" ,
287+ "handoff_type" : "ix.cognitionkernel.handoff" ,
288+ "runtime_semantics" : metadata .get ("runtime_semantics" ),
289+ "packages" : packages ,
290+ }
291+
292+ def _kernel_obligation_payload (self , obligation : dict [str , Any ]) -> dict [str , Any ]:
293+ obligation_id = str (obligation .get ("id" , "" ))
294+ definition = get_cognition_obligation (obligation_id )
295+ payload : dict [str , Any ] = {
296+ "id" : obligation_id ,
297+ "source" : obligation .get ("source" ),
298+ "canonical" : definition is not None ,
299+ "evidence_required" : list (obligation .get ("evidence_required" , [])),
300+ "falsify_if" : list (obligation .get ("falsify_if" , [])),
301+ }
302+
303+ if definition is not None :
304+ payload ["canonical_definition" ] = definition .to_dict ()
305+
306+ return payload
307+
236308 def _attempts (self , metadata : dict [str , Any ]) -> list [dict [str , Any ]]:
237309 attempts = metadata .get ("attempts" , [])
238310 if not isinstance (attempts , list ):
@@ -245,6 +317,16 @@ def _obligations(self, attempt: dict[str, Any]) -> list[dict[str, Any]]:
245317 return []
246318 return [obligation for obligation in obligations if isinstance (obligation , dict )]
247319
320+ def _handoff_contracts (self , attempt : dict [str , Any ]) -> list [dict [str , Any ]]:
321+ handoff_contracts = attempt .get ("handoff_contracts" , [])
322+ if not isinstance (handoff_contracts , list ):
323+ return []
324+ return [
325+ handoff
326+ for handoff in handoff_contracts
327+ if isinstance (handoff , dict )
328+ ]
329+
248330 def _write_json (self , path : Path , payload : Any ) -> Path :
249331 path .write_text (json .dumps (payload , indent = 2 , sort_keys = True ) + "\n " , encoding = "utf-8" )
250332 return path
@@ -263,6 +345,7 @@ def _sha256_file(self, path: Path) -> str:
263345 def _claims_text (self , result : ExecutionResult ) -> str :
264346 contract_metadata = self ._contract_metadata (result )
265347 contract_counts = self ._contract_counts (contract_metadata )
348+ kernel_handoff_payload = self ._kernel_handoff_payload (contract_metadata )
266349 return (
267350 "# IX Assurance Claims\n \n "
268351 "This evidence bundle supports only bounded, runtime-observed claims.\n \n "
@@ -275,12 +358,15 @@ def _claims_text(self, result: ExecutionResult) -> str:
275358 f"- Conditional branches captured: { len (result .branches )} .\n "
276359 f"- Human approval requirements captured: { len (result .approvals_required )} .\n "
277360 f"- Cognition attempt contracts captured: { contract_counts ['attempts' ]} .\n "
278- f"- Cognition obligations captured: { contract_counts ['obligations' ]} .\n \n "
361+ f"- Cognition obligations captured: { contract_counts ['obligations' ]} .\n "
362+ f"- IX-CognitionKernel handoff packages captured: "
363+ f"{ len (kernel_handoff_payload ['packages' ])} .\n \n "
279364 "## Not claimed\n \n "
280365 "- This bundle does not certify the script as safe, complete, lawful, or production-ready.\n "
281366 "- This bundle does not prove external system behavior beyond the deterministic IX runtime output.\n "
282367 "- This bundle does not execute or certify cognition-contract obligations.\n "
283368 "- This bundle does not certify AGI, AGI-candidate status, or deployment readiness.\n "
369+ "- This bundle does not grant IX-CognitionKernel execution authority.\n "
284370 "- This bundle does not replace human review.\n "
285371 )
286372
@@ -297,5 +383,8 @@ def _limitations_text(self) -> str:
297383 "Cognition-contract artifacts are declarative metadata. They record the contract, "
298384 "obligations, claim boundaries, and falsification gates that a downstream cognition "
299385 "system may later attempt. They do not execute cognition, prove learning, prove "
300- "transfer, certify AGI, or authorize self-approval.\n "
386+ "transfer, certify AGI, or authorize self-approval.\n \n "
387+ "IX-CognitionKernel handoff packages are reviewable contract packages only. They do "
388+ "not grant execution authority, deployment authority, self-modification authority, "
389+ "or AGI-certification authority.\n "
301390 )
0 commit comments