1"""ll-issues set-scores: Write confidence and dimension scores to issue frontmatter."""

2

3 from __future__ import annotations

4

5 import argparse

6 import sys

7 from typing import TYPE_CHECKING

8

9 if TYPE_CHECKING:

10 from little_loops.config import BRConfig

11

12

13 def cmd_set_scores(config: BRConfig, args: argparse.Namespace) -> int:

14 """Write confidence and outcome scores into an issue's YAML frontmatter.

15

16 Idempotent: calling with the same values has no net effect. Only the

17 flags that are explicitly provided are written; omitted flags leave the

18 corresponding frontmatter field unchanged.

19

20 Args:

21 config: Project configuration

22 args: Parsed arguments with .issue_id and optional score flags

23

24 Returns:

25 Exit code (0 = success, 1 = error)

26 """

27 from little_loops.cli.issues.show import _resolve_issue_id

28 from little_loops.frontmatter import update_frontmatter

29

30 path = _resolve_issue_id(config, args.issue_id)

31 if path is None:

32 print(f"Error: Issue '{args.issue_id}' not found.", file=sys.stderr)

33 return 1

34

35 updates: dict[str, str | int] = {}

36 if args.confidence is not None:

37 updates["confidence_score"] = args.confidence

38 if args.outcome is not None:

39 updates["outcome_confidence"] = args.outcome

40 if args.score_complexity is not None:

41 updates["score_complexity"] = args.score_complexity

42 if args.score_test_coverage is not None:

43 updates["score_test_coverage"] = args.score_test_coverage

44 if args.score_ambiguity is not None:

45 updates["score_ambiguity"] = args.score_ambiguity

46 if args.score_change_surface is not None:

47 updates["score_change_surface"] = args.score_change_surface

48

49 if not updates:

50 print("Warning: no score flags provided; nothing to write.", file=sys.stderr)

51 return 0

52

53 content = path.read_text()

54 new_content = update_frontmatter(content, updates)

55 path.write_text(new_content)

56 return 0