Browse Source

工具协议:收紧 Direction 与 Phase 2 Goal 参数

更新方向候选工具的 JSON Schema,开放最多 30 个目标节点并要求成功标准、约束和偏好。

同时把 goal_ids 加入任务合同工具协议,Phase 1 使用空数组,Phase 2 创作任务显式声明负责的 Direction Goal。
SamLee 23 hours ago
parent
commit
d6bb8ca2d8
1 changed files with 53 additions and 21 deletions
  1. 53 21
      script_build_host/src/script_build_host/tools/registry.py

+ 53 - 21
script_build_host/src/script_build_host/tools/registry.py

@@ -298,9 +298,8 @@ def register_script_tools(registry: ToolRegistry, gateway: LegacyScriptToolGatew
 
     async def save_direction_candidate(
         goals: list[dict[str, Any]],
-        criteria: list[dict[str, Any]],
-        legacy_markdown: str,
-        domain_criteria: list[dict[str, Any]] | None = None,
+        constraints: list[dict[str, Any]],
+        preferences: list[dict[str, Any]],
         topic_refs: list[str] | None = None,
         persona_refs: list[str] | None = None,
         strategy_refs: list[str] | None = None,
@@ -310,18 +309,17 @@ def register_script_tools(registry: ToolRegistry, gateway: LegacyScriptToolGatew
         """Freeze one direction candidate inside the protected Attempt."""
 
         goals = _structured_object_list(goals, "goals")
-        criteria = _structured_object_list(criteria, "criteria")
-        domain_criteria = _structured_object_list(domain_criteria or [], "domain_criteria")
+        constraints = _structured_object_list(constraints, "constraints")
+        preferences = _structured_object_list(preferences, "preferences")
         return _json(
             await gateway.save_direction_candidate(
                 goals=goals,
-                criteria=criteria,
-                domain_criteria=domain_criteria or [],
+                constraints=constraints,
+                preferences=preferences,
                 topic_refs=topic_refs or [],
                 persona_refs=persona_refs or [],
                 strategy_refs=strategy_refs or [],
                 evidence_refs=evidence_refs or [],
-                legacy_markdown=legacy_markdown,
                 context=context or {},
             )
         )
@@ -1014,6 +1012,16 @@ def _task_contract_schema() -> dict[str, Any]:
                 ],
                 "additionalProperties": False,
             },
+            "goal_ids": {
+                "type": "array",
+                "maxItems": 30,
+                "uniqueItems": True,
+                "items": {"type": "string", "minLength": 1},
+                "description": (
+                    "Empty in Phase1. In Phase2, the active Direction Goal IDs implemented "
+                    "by this Task. Compose and Portfolio include every Goal."
+                ),
+            },
             "supersedes_decision_ids": {"type": "array", "items": {"type": "string"}},
             "candidate_closure_decision_refs": {"type": "array", "items": decision_ref},
             "adopted_decision_ids": {"type": "array", "items": {"type": "string"}},
@@ -1037,6 +1045,7 @@ def _task_contract_schema() -> dict[str, Any]:
             "output_schema",
             "criteria",
             "budget",
+            "goal_ids",
             "supersedes_decision_ids",
             "candidate_closure_decision_refs",
             "adopted_decision_ids",
@@ -1049,13 +1058,25 @@ def _task_contract_schema() -> dict[str, Any]:
 
 
 def _save_direction_candidate_schema() -> dict[str, Any]:
-    criterion = {
+    constraint = {
         "type": "object",
         "properties": {
-            "criterion_id": {"type": "string"},
-            "description": {"type": "string"},
+            "constraint_id": {"type": "string", "minLength": 1},
+            "statement": {"type": "string", "minLength": 1},
+            "rationale": {"type": "string"},
+        },
+        "required": ["constraint_id", "statement", "rationale"],
+        "additionalProperties": False,
+    }
+    preference = {
+        "type": "object",
+        "properties": {
+            "preference_id": {"type": "string", "minLength": 1},
+            "statement": {"type": "string", "minLength": 1},
+            "rationale": {"type": "string"},
+            "priority": {"type": "integer", "minimum": 1, "maximum": 3},
         },
-        "required": ["criterion_id", "description"],
+        "required": ["preference_id", "statement", "rationale"],
         "additionalProperties": False,
     }
     return {
@@ -1072,20 +1093,32 @@ def _save_direction_candidate_schema() -> dict[str, Any]:
                     "goals": {
                         "type": "array",
                         "minItems": 1,
-                        "maxItems": 3,
+                        "maxItems": 30,
                         "items": {
                             "type": "object",
                             "properties": {
-                                "goal_id": {"type": "string"},
-                                "statement": {"type": "string"},
-                                "rationale": {"type": "string"},
+                                "goal_id": {"type": "string", "minLength": 1},
+                                "parent_goal_id": {"type": "string", "minLength": 1},
+                                "statement": {"type": "string", "minLength": 1},
+                                "rationale": {"type": "string", "minLength": 1},
+                                "success_criteria": {
+                                    "type": "array",
+                                    "minItems": 1,
+                                    "maxItems": 8,
+                                    "items": {"type": "string", "minLength": 1},
+                                },
                             },
-                            "required": ["goal_id", "statement", "rationale"],
+                            "required": [
+                                "goal_id",
+                                "statement",
+                                "rationale",
+                                "success_criteria",
+                            ],
                             "additionalProperties": False,
                         },
                     },
-                    "criteria": {"type": "array", "items": criterion},
-                    "domain_criteria": {"type": "array", "items": criterion, "default": []},
+                    "constraints": {"type": "array", "items": constraint},
+                    "preferences": {"type": "array", "items": preference},
                     "topic_refs": {"type": "array", "items": {"type": "string"}, "default": []},
                     "persona_refs": {
                         "type": "array",
@@ -1102,9 +1135,8 @@ def _save_direction_candidate_schema() -> dict[str, Any]:
                         "minItems": 1,
                         "items": {"type": "string"},
                     },
-                    "legacy_markdown": {"type": "string"},
                 },
-                "required": ["goals", "criteria", "evidence_refs", "legacy_markdown"],
+                "required": ["goals", "constraints", "preferences", "evidence_refs"],
                 "additionalProperties": False,
             },
         },