Procházet zdrojové kódy

工作台标识:统一语义句柄并隔离物理存储身份

为 Input、Strategy、Paragraph 和 Element 生成稳定语义 handle,保留原始 Snapshot ordinal 以支持重排后的精确读取。集中清除 URI、digest、数据库主键和物理引用,同时保留 Goal、Decision、Task 等业务判断需要的语义身份。
SamLee před 22 hodinami
rodič
revize
9c2af1d01b

+ 35 - 2
script_build_host/src/script_build_host/domain/workbench.py

@@ -31,6 +31,11 @@ class PlannerState:
     latest_failures: tuple[Mapping[str, Any], ...]
     retired_task_count: int
     changes: tuple[Mapping[str, Any], ...] = ()
+    active_total: int = 0
+    active_has_more: bool = False
+    accepted_total: int = 0
+    accepted_has_more: bool = False
+    context_bundle: Mapping[str, Any] = field(default_factory=dict)
 
     def to_payload(self) -> dict[str, Any]:
         return asdict(self)
@@ -42,9 +47,9 @@ class WorkerState:
     task: Mapping[str, Any]
     input_summary: Mapping[str, Any]
     accepted_inputs: tuple[Mapping[str, Any], ...]
-    source_handles: tuple[Mapping[str, Any], ...]
     paragraph_targets: tuple[Mapping[str, Any], ...]
     workspace_summary: Mapping[str, Any]
+    context_bundle: Mapping[str, Any] = field(default_factory=dict)
     latest_failure: Mapping[str, Any] | None = None
 
     def to_payload(self) -> dict[str, Any]:
@@ -58,6 +63,8 @@ class ValidatorState:
     artifact: Mapping[str, Any]
     evidence_handles: tuple[Mapping[str, Any], ...]
     accepted_closure: tuple[Mapping[str, Any], ...]
+    required_handles: tuple[str, ...] = ()
+    context_bundle: Mapping[str, Any] = field(default_factory=dict)
 
     def to_payload(self) -> dict[str, Any]:
         return asdict(self)
@@ -90,7 +97,7 @@ def strategy_handle(snapshot_id: str, index: int, value: Mapping[str, Any]) -> s
         or value.get("sha256")
         or json.dumps(value, sort_keys=True, default=str)
     )
-    return semantic_handle("strategy", snapshot_id, identity, immutable)
+    return semantic_handle("strategy", snapshot_id, index, identity, immutable)
 
 
 def strategy_ref(snapshot_id: str, index: int, value: Mapping[str, Any]) -> str:
@@ -165,6 +172,32 @@ def protect_model_value(value: Any, *, namespace: str) -> Any:
                         )
                         for identity in item
                     ]
+                elif lowered in {
+                    "uri",
+                    "url",
+                    "source_uri",
+                    "artifact_uri",
+                    "raw_artifact_ref",
+                }:
+                    output[f"{name}_handle"] = reference_handle(item)
+                elif lowered in {
+                    "account_id",
+                    "branch_id",
+                    "evidence_id",
+                    "execution_id",
+                    "script_build_id",
+                    "artifact_version_id",
+                    "input_snapshot_id",
+                    "record_id",
+                    "run_id",
+                    "source_id",
+                    "strategy_id",
+                    "topic_build_id",
+                    "topic_id",
+                }:
+                    output[f"{name.removesuffix('_id')}_handle"] = semantic_handle(
+                        name.removesuffix("_id"), namespace, item
+                    )
                 elif name in {"scope_ref", "write_scope"}:
                     output["scope_selector"] = scope_selector(item)
                 elif lowered.endswith("_ref"):