@@ -72,15 +72,27 @@ def _prepared(record: dict, output_language: str | None = None) -> dict:
7272 )
7373
7474
75- def _verify_sources (record : dict ) -> None :
75+ def _verify_sources (
76+ record : dict ,
77+ * ,
78+ staged_sources : dict [str , bytes ] | None = None ,
79+ ) -> None :
7680 # One byte observation per declared artifact in this verification only.
7781 # Check every digest/excerpt; later calls still read and verify fresh bytes.
82+ staged_sources = staged_sources or {}
7883 artifacts : dict [str , list [dict ]] = {}
7984 for source in record ["input" ]["sources" ]:
8085 artifacts .setdefault (source ["artifact" ], []).append (source )
8186 for artifact , sources in artifacts .items ():
82- path = _source_path (Path (record ["source_root" ]), artifact )
83- data = path .read_bytes ()
87+ if artifact in staged_sources :
88+ relative = PurePosixPath (artifact )
89+ if relative .is_absolute () or ".." in relative .parts or "\\ " in artifact :
90+ raise PackUnavailable ("invalid_source_path" )
91+ Path (record ["source_root" ]).resolve (strict = True )
92+ data = staged_sources [artifact ]
93+ else :
94+ path = _source_path (Path (record ["source_root" ]), artifact )
95+ data = path .read_bytes ()
8496 digest = hashlib .sha256 (data ).hexdigest ()
8597 lines = None
8698 for source in sources :
@@ -391,17 +403,38 @@ def register_pack(
391403 include_tool_context : bool = False ,
392404 loopx_input_json : str | None = None ,
393405 native_outcomes_json : str | None = None ,
406+ loopx_human_attention_start : str | None = None ,
407+ loopx_human_attention_end : str | None = None ,
394408 base_pack_id : str | None = None ,
395409 case_study_json : Path | None = None ,
396410 select_default : bool = True ,
397411) -> dict :
398412 """Trusted operator only; no HTTP/renderer path-registration endpoint."""
399413 if not title .strip ():
400414 raise ValueError ("A case/window title is required" )
415+ input_value = json .loads (input_path .read_text (encoding = "utf-8" ))
416+ if (loopx_human_attention_start is None ) != (loopx_human_attention_end is None ):
417+ raise ValueError (
418+ "LoopX human attention start and end must be supplied together"
419+ )
420+ if loopx_human_attention_start is not None :
421+ from .trajectory_human_attention_capture import (
422+ prepare_verified_loopx_human_attention ,
423+ )
424+
425+ input_value , staged_attention = prepare_verified_loopx_human_attention (
426+ runtime_root = runtime_root ,
427+ input_value = input_value ,
428+ source_root = source_root ,
429+ start = loopx_human_attention_start ,
430+ end = loopx_human_attention_end ,
431+ )
432+ else :
433+ staged_attention = {}
401434 prepared = effect_runtime_result (
402435 "benchmark.trajectory.prepare" ,
403436 {
404- "input" : json . loads ( input_path . read_text ( encoding = "utf-8" )) ,
437+ "input" : input_value ,
405438 "config" : config or DEFAULT_CONFIG ,
406439 "generation_defaults" : not config ,
407440 ** ({"case_study" : json .loads (case_study_json .read_text (encoding = "utf-8" ))}
@@ -417,7 +450,13 @@ def register_pack(
417450 for k in ("input" , "config" , "analysis_key" , "method_version" )
418451 },
419452 }
420- _verify_sources (record )
453+ _verify_sources (
454+ record ,
455+ staged_sources = {
456+ artifact : text .encode ("utf-8" )
457+ for artifact , text in staged_attention .items ()
458+ },
459+ )
421460 if "human_attention" in prepared :
422461 record ["human_attention" ] = prepared ["human_attention" ]
423462 if "case_study" in prepared :
@@ -463,6 +502,15 @@ def register_pack(
463502 (owner / "packs" ).mkdir (parents = True , exist_ok = True , mode = 0o700 )
464503 pack_id = _pack_id (owner_goal_id , record )
465504 with exclusive_file_lock (owner / "packs.lock" ):
505+ if staged_attention :
506+ from .trajectory_human_attention_capture import (
507+ publish_verified_loopx_human_attention ,
508+ )
509+
510+ publish_verified_loopx_human_attention (
511+ source_root = source_root ,
512+ artifacts = staged_attention ,
513+ )
466514 index = _index (owner )
467515 path = owner / "packs" / f"{ pack_id } .json"
468516 if path .exists ():
0 commit comments