Repository navigation
Expand file tree
/
Copy pathinterview.py
More file actions
139 lines (122 loc) · 4.95 KB
/
Copy pathinterview.py
File metadata and controls
139 lines (122 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""Guide a user through selecting and applying a skills installation."""
from __future__ import annotations
# Standard Library
import pathlib
# local repo modules
import install_lib.install_target_data
import install_lib.installer
#============================================
def prompt_default(label: str, default: str) -> str:
"""Prompt for text and use the displayed default for an empty answer."""
answer = input(f"{label} [{default}]: ").strip()
value = answer if answer else default
return value
#============================================
def prompt_yes_no(label: str) -> bool:
"""Prompt until the user gives an explicit yes or no answer."""
while True:
answer = input(f"{label} [y/N]: ").strip().lower()
if answer in {"y", "yes"}:
return True
if answer in {"", "n", "no"}:
return False
print("Please answer y or n.")
#============================================
def parse_platform_selection(answer: str, targets: dict) -> list[str]:
"""Return unique comma-separated platform identifiers in user order."""
# ASVS 2.2.1: allow only identifiers from the loaded target declarations.
platforms = []
for value in answer.split(","):
platform = value.strip().lower()
if platform and platform not in platforms:
platforms.append(platform)
if not platforms:
raise ValueError("Select at least one platform")
unknown = [platform for platform in platforms if platform not in targets]
if unknown:
raise ValueError(f"Unknown platform selection: {', '.join(unknown)}")
return platforms
#============================================
def interview_platforms(
targets: dict[str, install_lib.install_target_data.InstallTarget],
home_root: pathlib.Path,
) -> list[str]:
"""Offer existing skill destinations as the default platform selection."""
print("\nAvailable platforms:")
primary = []
detected = []
for target_id, target in targets.items():
skills_path = target.destinations["skills"]
agents_path = target.destinations.get("agents", "none")
# ASVS 5.3.2: detect directories only at validated destinations beneath the home root.
try:
skills_root = install_lib.install_target_data.resolve_target_destination(
home_root, target, "skills"
)
has_skills_directory = skills_root.is_dir()
except (OSError, RuntimeError, ValueError):
has_skills_directory = False
if has_skills_directory:
detected.append(target_id)
detection = " (found)" if has_skills_directory else ""
print(f" {target_id}: {target.support_tier}")
print(f" skills -> {skills_path}{detection}; agents -> {agents_path}")
if target.support_tier == "primary":
primary.append(target_id)
default = ",".join(detected or primary)
while True:
answer = prompt_default("Platforms, comma separated", default)
try:
platforms = parse_platform_selection(answer, targets)
except ValueError as error:
print(error)
continue
return platforms
#============================================
def print_plan_summary(plan: dict) -> None:
"""Print selected destinations and item counts before installation."""
print("\nInstallation summary")
print(f" Installation root: {plan['home_root']}")
for target_plan in plan["plans"]:
target = target_plan["target"]
skill_count = sum(item.kind == "skills" for item in target_plan["items"])
agent_link_count = sum(
item.kind == "agents" and item.source is not None for item in target_plan["items"]
)
generated_agent_count = sum(
item.kind == "agents" and item.source is None for item in target_plan["items"]
)
print(f" {target.target_id} ({target.support_tier})")
print(f" Skills: {target.destinations['skills']} ({skill_count} links)")
# skills_only targets declare no agents destination.
if "agents" not in target.destinations:
print(" Agents: none")
continue
print(
f" Agents: {target.destinations['agents']} "
f"({agent_link_count} links, {generated_agent_count} generated files)"
)
#============================================
def print_completion(plan: dict, result: dict) -> None:
"""Print a concise completion summary."""
change_count = len(result["changes"])
print(f"\nInstallation complete: {change_count} changes.")
for target_plan in plan["plans"]:
print(f" {target_plan['target'].target_id}")
#============================================
def run(repo_root: pathlib.Path) -> int:
"""Conduct the installation interview and apply the confirmed plan."""
print("Vosslab Skills installer")
print("This interview installs or updates skills and generated agents.")
# ASVS 5.3.2: use the trusted OS home instead of accepting a filesystem path.
home_root = pathlib.Path.home()
targets = install_lib.install_target_data.load_targets(repo_root / "install_targets")
platforms = interview_platforms(targets, home_root)
plan = install_lib.installer.build_plan(repo_root, home_root, platforms)
print_plan_summary(plan)
if not prompt_yes_no("Apply this installation"):
print("No changes made.")
return 0
result = install_lib.installer.apply_plan(plan)
print_completion(plan, result)
return 0