Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions kits/profile-dev-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,28 @@ A baseline-red Gate is advisory; only a green command that becomes red blocks.
```text
beddel run -i ... workflows/implement-story.yaml
```

## Delivery: verify-and-fix stage

`verify-and-fix-story` takes `repo_path`, `story_key`, `spec_path`, `branch`,
`base_ref`, `change_id` and `inventory_version`. It invokes `verify-change.yaml` unchanged through the core nested
`call-agent` primitive, reads its Report through `profile_read_report`, and
records one Stage outcome. The stage never writes a Change, binding, Impact,
VerificationAttempt, Gate, Review, Evidence, Report or Verdict.

A `consistent` Report succeeds. A `has pendency` Report starts a fix round only
when it contains a `finding_blocking` or `finding_unclassified` Pendency. The
Coding agent receives only those recorded Findings and the union of the spec
unit paths. Kit checks run again before `profile_fix_settle` creates one commit
with `Story-Key` and `Fix-Round` trailers. At most two rounds invoke `verify-change` at the new commit so it opens a fresh
VerificationAttempt. Earlier Evidence is never copied. Other Pendencies stop with `pendency.no_fixes`; the bound stops with
`fix.bound_reached`. Stage refs contain identifiers, digests, counts and paths
only.

Owner-ratified Review classes:
Blind Hunter, Edge Case Hunter, Verification Gap and Acceptance Auditor. Agents
never ratify or write inventory versions.

```text
beddel run -i ... workflows/verify-and-fix-story.yaml
```
15 changes: 15 additions & 0 deletions kits/profile-dev-kit/kit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ tools:
target: "beddel_profile_dev.tools.implement:profile_implement_settle"
description: "Review and commit one implementation unit"
category: profile
- name: profile_fix_reconcile
target: "beddel_profile_dev.tools.fix:profile_fix_reconcile"
description: "Reconcile one bounded verification fix round"
category: profile
- name: profile_fix_settle
target: "beddel_profile_dev.tools.fix:profile_fix_settle"
description: "Validate and commit one verification fix round"
category: profile

workflows:
- name: verify-change
Expand Down Expand Up @@ -146,6 +154,9 @@ workflows:
- name: implement-story
path: workflows/implement-story.yaml
description: Implements one unit of one spec through a Coding agent and commits only its declared paths; never pushes, verifies or integrates.
- name: verify-and-fix-story
path: workflows/verify-and-fix-story.yaml
description: Runs verify-change unchanged and applies at most two bounded fix rounds with fresh verification attempts; never approves, ratifies, pushes or integrates.
- name: plan-story
path: workflows/plan-story.yaml
description: Plans one selected story into one implementation spec through a Coding agent; never implements, verifies or commits.
Expand Down Expand Up @@ -198,6 +209,10 @@ targets:
target: "beddel_profile_dev.tools.implement:profile_implement_prepare"
- name: profile_implement_settle
target: "beddel_profile_dev.tools.implement:profile_implement_settle"
- name: profile_fix_reconcile
target: "beddel_profile_dev.tools.fix:profile_fix_reconcile"
- name: profile_fix_settle
target: "beddel_profile_dev.tools.fix:profile_fix_settle"
typescript:
status: unavailable
unavailable_reason: >
Expand Down
83 changes: 83 additions & 0 deletions kits/profile-dev-kit/python/beddel_profile_dev/fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Pure fix contracts."""

# fmt: off
from __future__ import annotations

import re
from collections.abc import Iterable, Mapping
from typing import Any

from beddel_profile_dev.implement import STORY_TRAILER, Unit

FIX_TRAILER = "Fix-Round"
MAX_FIX_ROUNDS = 2
MAX_FINDINGS_BYTES = 32768
FIXABLE_REASONS = frozenset({"finding_blocking", "finding_unclassified"})
_ROUND = re.compile(r"[1-2]")


def fix_message(story_key: str, round_: int) -> tuple[str, str]:
"""Return the subject and trailers for a fix commit."""
return (f"fix: apply verification fixes (round {round_})", f"{STORY_TRAILER}: {story_key}\n{FIX_TRAILER}: {round_}")


def trailer_round(message: str, story_key: str) -> int | None:
"""Return the valid fix-round trailer in a commit message."""
if not isinstance(message, str):
return None
lines = message.splitlines()
story = [line for line in lines if line == f"{STORY_TRAILER}: {story_key}"]
rounds = [line for line in lines if line.startswith(f"{FIX_TRAILER}: ")]
if len(story) != 1 or len(rounds) != 1:
return None
value = rounds[0][len(f"{FIX_TRAILER}: ") :]
return int(value) if _ROUND.fullmatch(value) else None


def report_at(history: object, head: str) -> dict[str, Any] | None:
"""Return the last report recorded at ``head``."""
selected: dict[str, Any] | None = None
if not isinstance(history, Iterable) or isinstance(history, (str, bytes)):
return None
for entry in history:
content = entry.get("content") if isinstance(entry, Mapping) else None
if isinstance(content, Mapping) and content.get("revision") == head:
selected = dict(content)
return selected


def fix_findings(report: object) -> list[dict[str, Any]]:
"""Return Findings named by fixable Pendencies in index order."""
if not isinstance(report, Mapping) or not isinstance(report.get("items"), Mapping):
return []
items = report["items"]
divergences, pendencies = items.get("divergences"), items.get("pendencies")
if not isinstance(divergences, Mapping) or not isinstance(pendencies, Mapping):
return []
values, pending = divergences.get("value"), pendencies.get("value")
if divergences.get("status") != "present" or pendencies.get("status") != "present" or not isinstance(values, list) or not isinstance(pending, list):
return []
indexes = {item["finding_index"] for item in pending if isinstance(item, Mapping) and item.get("reason") in FIXABLE_REASONS and type(item.get("finding_index")) is int and item["finding_index"] >= 0}
keys = ("source", "association", "class", "affected_point", "criterion", "kind", "between", "detail")
return [{key: values[index].get(key) for key in keys} for index in sorted(indexes) if index < len(values) and isinstance(values[index], Mapping)]


def decision(report: object, rounds: int, max_rounds: int) -> tuple[str | None, str | None]:
"""Return the stage decision for one Report."""
if not isinstance(report, Mapping):
return "failed", "report.unreadable"
verdict = report.get("verdict")
if verdict == "consistent":
return "succeeded", "verdict.consistent"
if verdict != "has pendency":
return "failed", "report.unreadable"
if not fix_findings(report):
return "stopped", "pendency.no_fixes"
if rounds >= max_rounds:
return "stopped", "fix.bound_reached"
return None, None


def scope_paths(units: Iterable[Unit]) -> tuple[str, ...]:
return tuple(sorted({path for unit in units for path in unit.paths}))
# fmt: on
Loading
Loading