-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_skill_management_support.py
More file actions
165 lines (154 loc) · 5.17 KB
/
Copy path_skill_management_support.py
File metadata and controls
165 lines (154 loc) · 5.17 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
"""Skill manager: read-only inspection, hash-confirmed mutation, and rollback."""
from __future__ import annotations
import json
import os
import shutil
import subprocess
import sys
import unittest
from contextlib import nullcontext
from pathlib import Path
from unittest import mock
REPO_ROOT = Path(__file__).resolve().parents[1]
SCRIPT = REPO_ROOT / "support_scripts" / "skill_manager.py"
sys.path.insert(0, str(REPO_ROOT))
import support_scripts.skill_management.links as link_module # noqa: E402
import support_scripts.skill_management.policy as policy_module # noqa: E402
from tests._fixture_isolation import temp_test_root # noqa: E402
from support_scripts.skill_management import ( # noqa: E402
SkillManagementError,
apply_index_plan,
apply_link_plan,
apply_policy_plan,
apply_store_index_plan,
build_index_plan,
build_link_plan,
build_policy_plan,
build_policy_restore_plan,
build_store_index_plan,
discover_skills,
index_status,
package_sha256,
policy_status,
restore_policy,
validate_skill_package,
validation_status,
)
def write_leaf(root: Path, name: str, keywords: list[str] | None = None) -> Path:
skill = root / name
(skill / "references").mkdir(parents=True)
(skill / "evals").mkdir()
(skill / "SKILL.md").write_text(
"\n".join(
[
"---",
f"name: {name}",
f"description: Use when working with {name} fixtures and validation tests.",
"---",
"",
f"# {name}",
"",
"## Workflow",
"",
"Read the relevant reference before acting.",
"",
"## References",
"",
"Start with [the index](references/INDEX.md).",
"",
"## Gotchas",
"",
"See [evals/GOTCHA.md](evals/GOTCHA.md).",
"",
"## Verification",
"",
"Run the package validator.",
"",
]
),
encoding="utf-8",
newline="\n",
)
(skill / "references" / "topic.md").write_text("# Topic\n\nVerified guidance.\n", encoding="utf-8")
(skill / "references" / "INDEX.md").write_text(
"# References\n\n- [Topic](topic.md)\n", encoding="utf-8"
)
(skill / "references" / "topics.json").write_text(
json.dumps(
{
"topics": [
{
"topic": "Topic",
"summary": "Verified topic guidance.",
"keywords": keywords or [name, "shared-entity"],
"file": "references/topic.md",
}
]
},
indent=2,
)
+ "\n",
encoding="utf-8",
)
(skill / "evals" / "GOTCHA.md").write_text("# Gotchas\n\n- Verify first.\n", encoding="utf-8")
return skill
def write_router(root: Path, name: str, child_name: str = "child") -> tuple[Path, Path]:
router = root / name
(router / "evals").mkdir(parents=True)
child = write_leaf(router, child_name)
(router / "SKILL.md").write_text(
"\n".join(
[
"---",
f"name: {name}",
f"description: Use when routing {name} work to a product subskill.",
"---",
"",
f"# {name}",
"",
"## Workflow",
"",
f"Open [{child_name}]({child_name}/SKILL.md).",
"",
"## References",
"",
"Each child owns its references.",
"",
"## Gotchas",
"",
"See [evals/GOTCHA.md](evals/GOTCHA.md).",
"",
"## Verification",
"",
"Validate the complete router package.",
"",
]
),
encoding="utf-8",
)
(router / "evals" / "GOTCHA.md").write_text("# Gotchas\n\n- Route deliberately.\n", encoding="utf-8")
return router, child
def create_directory_link(path: Path, target: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
if os.name == "nt":
proc = subprocess.run(
["cmd.exe", "/d", "/c", "mklink", "/J", str(path), str(target)],
capture_output=True,
text=True,
encoding="utf-8",
)
if proc.returncode != 0:
raise OSError(proc.stderr or proc.stdout)
else:
os.symlink(target, path, target_is_directory=True)
def create_file_link(path: Path, target: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
os.symlink(target, path, target_is_directory=False)
class ScratchTest(unittest.TestCase):
def setUp(self) -> None:
self.root = self.enterContext(temp_test_root(prefix="skill_management-"))
self.project = self.root / "project"
self.store = self.root / "store"
self.project.mkdir()
self.store.mkdir()
__all__ = tuple(name for name in globals() if not name.startswith('__'))