Coverage for src / osiris_cli / scenarios.py: 0%

32 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-28 16:44 +0200

1#!/usr/bin/env python3 

2""" 

3Scenario templates for Osiris CLI. 

4 

5These lightweight playbooks help the CLI behave more like agentic CLIs 

6by providing opinionated defaults for common requests (e.g., comprehensive 

7overview reports or quick project audits). 

8""" 

9 

10from __future__ import annotations 

11 

12from dataclasses import dataclass 

13from pathlib import Path 

14from typing import List, Optional 

15 

16 

17@dataclass 

18class ScenarioDefinition: 

19 """Describe a high-level scenario detected from user prompts.""" 

20 

21 id: str 

22 title: str 

23 triggers: List[str] 

24 instructions: str 

25 summary_prompt: str 

26 context_files: List[str] 

27 auto_continue: bool = True 

28 

29 def matches(self, user_input: str) -> bool: 

30 lower_text = user_input.lower() 

31 return any(trigger in lower_text for trigger in self.triggers) 

32 

33 

34SCENARIOS: List[ScenarioDefinition] = [ 

35 ScenarioDefinition( 

36 id="overview", 

37 title="Repository Overview", 

38 triggers=[ 

39 "comprehensive overview", 

40 "overview", 

41 "status report", 

42 "project report", 

43 ], 

44 instructions=( 

45 "You are preparing a comprehensive Osiris CLI project overview. " 

46 "Read the key project documentation (README, CHANGELOG, final summary) " 

47 "and produce a structured report that covers features, architecture, " 

48 "current gaps, and next actions. Avoid referencing any VPS-specific " 

49 "protocols—focus purely on the repository contents." 

50 ), 

51 summary_prompt=( 

52 "Summarize the findings from the repository documents you loaded. " 

53 "Highlight core capabilities, recent changes, and outstanding issues." 

54 ), 

55 context_files=[ 

56 "README.md", 

57 "CHANGELOG.md", 

58 "docs/status/COMPLETE_V4_FINAL_SUMMARY.md", 

59 ], 

60 ), 

61 ScenarioDefinition( 

62 id="test-inspection", 

63 title="Test & Diagnostics", 

64 triggers=[ 

65 "run tests", 

66 "pytest", 

67 "test suite", 

68 "diagnostic report", 

69 ], 

70 instructions=( 

71 "The user wants a diagnostics report for the Osiris CLI repository. " 

72 "Inspect the testing utilities and summarize current test coverage, " 

73 "known failures, and recommended follow-ups. Use the tests/ directory " 

74 "only—do not rely on external scripts." 

75 ), 

76 summary_prompt=( 

77 "Provide a diagnostics summary based on the repository test files " 

78 "you reviewed. Include notable tests, potential failures, and advice." 

79 ), 

80 context_files=[ 

81 "README.md", 

82 "tests/test_config_export_and_masking.py", 

83 "tests/test_context.py", 

84 ], 

85 auto_continue=True, 

86 ), 

87] 

88 

89 

90def detect_scenario(user_input: str) -> Optional[ScenarioDefinition]: 

91 """Return a matching scenario if the prompt contains known triggers.""" 

92 for scenario in SCENARIOS: 

93 if scenario.matches(user_input): 

94 return scenario 

95 return None 

96 

97 

98def resolve_context_files(scenario: ScenarioDefinition) -> List[Path]: 

99 """Return existing context files for the scenario.""" 

100 resolved: List[Path] = [] 

101 cwd = Path.cwd() 

102 for rel_path in scenario.context_files: 

103 path = Path(rel_path) 

104 if not path.is_absolute(): 

105 path = cwd / rel_path 

106 if path.exists() and path.is_file(): 

107 resolved.append(path) 

108 return resolved