Add profile task-bundle remediation loop closure (sprint 243)

This commit is contained in:
Bill
2026-02-26 15:10:41 -07:00
parent ee38182b79
commit 050fee9480
10 changed files with 196 additions and 11 deletions

View File

@@ -21,15 +21,21 @@ def load_native_tasks(run_dir: Path, summary: Dict) -> List[Dict]:
retry_applied = bool(retry.get("applied", False))
retry_path = run_dir / "02aa_generate_taskitems_retry.json"
base_path = run_dir / "02_generate_taskitems.json"
tasks: List[Dict] = []
if retry_applied and retry_path.exists():
data = load_json(retry_path)
if isinstance(data, dict):
return list(data.get("tasks") or [])
if base_path.exists():
tasks = list(data.get("tasks") or [])
elif base_path.exists():
data = load_json(base_path)
if isinstance(data, dict):
return list(data.get("tasks") or [])
return []
tasks = list(data.get("tasks") or [])
# Include explicitly injected extra tasks when present.
extra = summary.get("extra_tasks") or []
if isinstance(extra, list) and extra:
tasks = tasks + extra
return tasks
def load_spec_text(summary: Dict, repo_root: Path) -> str:

View File

@@ -18,11 +18,13 @@ mkdir -p "$OUT_DIR"
BASE_NAME="$(basename "$SPEC_PATH" .md)"
run_pipeline_once() {
local extra_file="$1"
if [[ -n "$extra_file" ]]; then
local extra_req_file="$1"
local extra_task_file="$2"
if [[ -n "$extra_req_file" || -n "$extra_task_file" ]]; then
WSTONE_NATIVE_IMPACT_COVERAGE_GATE=1 \
WSTONE_NATIVE_IMPACT_COVERAGE_ENFORCE=0 \
WSTONE_EXTRA_NORMALIZED_REQUIREMENTS_FILE="$extra_file" \
WSTONE_EXTRA_NORMALIZED_REQUIREMENTS_FILE="$extra_req_file" \
WSTONE_EXTRA_TASKS_FILE="$extra_task_file" \
"$ROOT_DIR/tools/mcp/run_sprint_taskitem_pipeline.sh" "$SPEC_PATH" >/dev/null
else
WSTONE_NATIVE_IMPACT_COVERAGE_GATE=1 \
@@ -32,7 +34,7 @@ run_pipeline_once() {
ls -1dt "$ROOT_DIR/logs/taskitem_runs/${BASE_NAME}_"* | head -n1
}
RUN1_DIR="$(run_pipeline_once "")"
RUN1_DIR="$(run_pipeline_once "" "")"
RUN1_REPORT="$RUN1_DIR/06_native_impact_coverage.json"
if [[ ! -f "$RUN1_REPORT" ]]; then
echo "error: missing first-run coverage report: $RUN1_REPORT" >&2
@@ -40,12 +42,18 @@ if [[ ! -f "$RUN1_REPORT" ]]; then
fi
REQ_FILE="$OUT_DIR/extra_normalized_requirements.json"
TASK_FILE="$OUT_DIR/extra_tasks.json"
python3 "$ROOT_DIR/tools/mcp/synthesize_native_impact_remediation_requirements.py" \
--coverage-report "$RUN1_REPORT" \
--profiles "${WSTONE_NATIVE_IMPACT_COVERAGE_PROFILES:-$ROOT_DIR/tools/mcp/profiles/native_decomposition_impact_profiles.json}" \
--out "$REQ_FILE" >/dev/null
RUN2_DIR="$(run_pipeline_once "$REQ_FILE")"
python3 "$ROOT_DIR/tools/mcp/synthesize_native_impact_remediation_tasks.py" \
--coverage-report "$RUN1_REPORT" \
--profiles "${WSTONE_NATIVE_IMPACT_COVERAGE_PROFILES:-$ROOT_DIR/tools/mcp/profiles/native_decomposition_impact_profiles.json}" \
--out "$TASK_FILE" >/dev/null
RUN2_DIR="$(run_pipeline_once "$REQ_FILE" "$TASK_FILE")"
RUN2_REPORT="$RUN2_DIR/06_native_impact_coverage.json"
if [[ ! -f "$RUN2_REPORT" ]]; then
echo "error: missing second-run coverage report: $RUN2_REPORT" >&2
@@ -56,6 +64,7 @@ jq -n \
--arg run1 "$RUN1_DIR" \
--arg run2 "$RUN2_DIR" \
--arg req_file "$REQ_FILE" \
--arg task_file "$TASK_FILE" \
--argjson first "$(cat "$RUN1_REPORT")" \
--argjson second "$(cat "$RUN2_REPORT")" \
'{
@@ -63,6 +72,7 @@ jq -n \
run1:$run1,
run2:$run2,
remediation_requirements_file:$req_file,
remediation_tasks_file:$task_file,
before:{active_profile_count:$first.active_profile_count,failing_profile_count:$first.failing_profile_count,status:$first.status},
after:{active_profile_count:$second.active_profile_count,failing_profile_count:$second.failing_profile_count,status:$second.status},
delta:{failing_profile_count: (($second.failing_profile_count // 0) - ($first.failing_profile_count // 0))}

View File

@@ -43,6 +43,7 @@ NATIVE_IMPACT_COVERAGE_GATE="${WSTONE_NATIVE_IMPACT_COVERAGE_GATE:-0}"
NATIVE_IMPACT_COVERAGE_ENFORCE="${WSTONE_NATIVE_IMPACT_COVERAGE_ENFORCE:-0}"
NATIVE_IMPACT_COVERAGE_PROFILES="${WSTONE_NATIVE_IMPACT_COVERAGE_PROFILES:-$ROOT_DIR/tools/mcp/profiles/native_decomposition_impact_profiles.json}"
EXTRA_NORMALIZED_REQUIREMENTS_FILE="${WSTONE_EXTRA_NORMALIZED_REQUIREMENTS_FILE:-}"
EXTRA_TASKS_FILE="${WSTONE_EXTRA_TASKS_FILE:-}"
CAPABILITY_SIGNALS_JSON="${WSTONE_CAPABILITY_SIGNALS_JSON:-}"
if [[ -z "$CAPABILITY_SIGNALS_JSON" ]]; then
CAPABILITY_SIGNALS_JSON='{}'
@@ -99,6 +100,7 @@ NATIVE_REASON_ENRICHMENT_JSON='{}'
NATIVE_DECOMP_RETRY_JSON='{}'
NATIVE_IMPACT_COVERAGE_JSON='{}'
EXTRA_NORMALIZED_REQUIREMENTS_JSON='[]'
EXTRA_TASKS_JSON='[]'
if [[ "$SEMANTIC_PLANNING_BRIDGE" == "1" ]]; then
python3 "$ROOT_DIR/tools/mcp/markdown_to_semantic_annotations.py" \
--spec "$INPUT_FILE" \
@@ -360,6 +362,18 @@ else
--argjson target_min_task_count "$NATIVE_DECOMP_TARGET_MIN_TASKS" \
'{attempted:$attempted, applied:$applied, initial_task_count:$initial_task_count, target_min_task_count:$target_min_task_count}')"
fi
if [[ -n "$EXTRA_TASKS_FILE" ]]; then
if [[ ! -f "$EXTRA_TASKS_FILE" ]]; then
echo "error: extra tasks file not found: $EXTRA_TASKS_FILE" >&2
exit 15
fi
if ! jq -e 'type == "array"' "$EXTRA_TASKS_FILE" >/dev/null 2>&1; then
echo "error: extra tasks file must be a JSON array: $EXTRA_TASKS_FILE" >&2
exit 16
fi
EXTRA_TASKS_JSON="$(cat "$EXTRA_TASKS_FILE")"
TASKS="$(jq -nc --argjson base "$TASKS" --argjson extra "$EXTRA_TASKS_JSON" '$base + $extra')"
fi
if [[ "$NATIVE_REASON_ENRICHMENT" == "1" && -f "$OUT_DIR/01c_semantic_injected_requirements.json" ]]; then
TASKS="$(jq -nc \
--argjson tasks "$TASKS" \
@@ -529,6 +543,7 @@ SUMMARY_JSON="$(jq -nc \
--argjson native_reason_enrichment "$NATIVE_REASON_ENRICHMENT_JSON" \
--argjson native_decomposition_retry "$NATIVE_DECOMP_RETRY_JSON" \
--argjson extra_normalized_requirements "$EXTRA_NORMALIZED_REQUIREMENTS_JSON" \
--argjson extra_tasks "$EXTRA_TASKS_JSON" \
--argjson intake "$INTAKE_JSON" \
--argjson generated "$GEN_JSON" \
--argjson queue "$QUEUE_JSON" \
@@ -550,6 +565,7 @@ SUMMARY_JSON="$(jq -nc \
native_reason_enrichment: $native_reason_enrichment,
native_decomposition_retry: $native_decomposition_retry,
extra_normalized_requirements: $extra_normalized_requirements,
extra_tasks: $extra_tasks,
intake: {
success: ($intake.success // false),
normalized_requirement_count: (($intake.normalizedRequirements // [])|length),

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
from typing import Dict, List
def load_json(path: Path) -> Dict:
with path.open("r", encoding="utf-8") as f:
return json.load(f)
def write_json(path: Path, obj) -> None:
with path.open("w", encoding="utf-8") as f:
json.dump(obj, f, indent=2, sort_keys=True)
f.write("\n")
def mk_task(profile: Dict, idx: int) -> Dict:
pid = str(profile.get("id", f"profile_{idx}"))
req_ops = [str(x) for x in (profile.get("required_prerequisite_ops") or [])]
reason_keys = [str(x) for x in (profile.get("required_reason_keywords") or [])]
req_contract = [str(x) for x in (profile.get("required_execution_contract") or [])]
ec = {
"deterministic": True,
"rollbackRequired": True,
"replayValidationRequired": True,
"maxFileTouches": 4,
"maxContextTokens": 6144,
"maxExecutionSteps": 8,
"executionSpecificityScore": 90,
}
for field in req_contract:
ec[field] = True
reasons = [f"impact_profile:{pid}", "native_impact_remediation"] + reason_keys
return {
"taskId": f"impact-remediation-task-{idx+1}",
"title": f"Impact Remediation: {pid}",
"prerequisiteOps": req_ops,
"reasons": reasons,
"confidence": 0.93,
"dependencyTaskIds": ["task-1"],
"resourceLocks": [],
"executionContract": ec,
}
def main() -> int:
p = argparse.ArgumentParser(description="Synthesize remediation tasks from failing native impact checks.")
p.add_argument("--coverage-report", required=True)
p.add_argument("--profiles", required=True)
p.add_argument("--out", required=True)
args = p.parse_args()
coverage = load_json(Path(args.coverage_report))
profiles_doc = load_json(Path(args.profiles))
by_id = {str(x.get("id", "")): x for x in (profiles_doc.get("profiles") or [])}
out: List[Dict] = []
i = 0
for check in coverage.get("checks", []):
if check.get("passed", False):
continue
pid = str(check.get("id", ""))
profile = by_id.get(pid, {"id": pid})
out.append(mk_task(profile, i))
i += 1
write_json(Path(args.out), out)
print(json.dumps({"status": "ok", "count": len(out), "out": args.out}, sort_keys=True))
return 0
if __name__ == "__main__":
raise SystemExit(main())