🐛 fix(playbook): address reported repo issues
normalize Windows path-like TOML config values, regenerate .agents/index.md on sync, keep the SKILLS.md superpowers section route-only, and ignore generated Python cache dirs. add regression coverage for load_config() and the standards sync behavior touched by these fixes.
This commit is contained in:
+58
-4
@@ -21,6 +21,7 @@ ORDER = [
|
||||
]
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||
PLAYBOOK_ROOT = SCRIPT_DIR.parent
|
||||
PATH_CONFIG_KEYS = {"project_root", "target_dir", "agents_home", "codex_home"}
|
||||
|
||||
|
||||
def usage() -> str:
|
||||
@@ -141,8 +142,63 @@ def loads_toml_minimal(raw: str) -> dict:
|
||||
return data
|
||||
|
||||
|
||||
def normalize_path_config_strings(raw: str) -> str:
|
||||
normalized_lines: list[str] = []
|
||||
for line in raw.splitlines():
|
||||
stripped = line.strip()
|
||||
if not stripped or stripped.startswith("#") or "=" not in line:
|
||||
normalized_lines.append(line)
|
||||
continue
|
||||
|
||||
key_part, value_part = line.split("=", 1)
|
||||
key = key_part.strip()
|
||||
if key not in PATH_CONFIG_KEYS:
|
||||
normalized_lines.append(line)
|
||||
continue
|
||||
|
||||
value = strip_inline_comment(value_part.strip())
|
||||
if len(value) < 2 or value[0] != '"' or value[-1] != '"' or "\\" not in value[1:-1]:
|
||||
normalized_lines.append(line)
|
||||
continue
|
||||
|
||||
inner = value[1:-1]
|
||||
has_lone_backslash = False
|
||||
probe_idx = 0
|
||||
while probe_idx < len(inner):
|
||||
if inner[probe_idx] != "\\":
|
||||
probe_idx += 1
|
||||
continue
|
||||
if probe_idx + 1 < len(inner) and inner[probe_idx + 1] == "\\":
|
||||
probe_idx += 2
|
||||
continue
|
||||
has_lone_backslash = True
|
||||
break
|
||||
if not has_lone_backslash:
|
||||
normalized_lines.append(line)
|
||||
continue
|
||||
|
||||
escaped: list[str] = []
|
||||
idx = 0
|
||||
while idx < len(inner):
|
||||
ch = inner[idx]
|
||||
if ch != "\\":
|
||||
escaped.append(ch)
|
||||
idx += 1
|
||||
continue
|
||||
if idx + 1 < len(inner) and inner[idx + 1] == "\\":
|
||||
escaped.extend(["\\", "\\"])
|
||||
idx += 2
|
||||
continue
|
||||
escaped.extend(["\\", "\\"])
|
||||
idx += 1
|
||||
normalized_lines.append(f'{key_part}= "{"".join(escaped)}"')
|
||||
|
||||
suffix = "\n" if raw.endswith("\n") else ""
|
||||
return "\n".join(normalized_lines) + suffix
|
||||
|
||||
|
||||
def load_config(path: Path) -> dict:
|
||||
raw = path.read_text(encoding="utf-8")
|
||||
raw = normalize_path_config_strings(path.read_text(encoding="utf-8"))
|
||||
if tomllib is not None:
|
||||
return tomllib.loads(raw)
|
||||
return loads_toml_minimal(raw)
|
||||
@@ -830,8 +886,6 @@ def update_agents_block(agents_md: Path, block_lines: list[str]) -> None:
|
||||
|
||||
def create_agents_index(agents_root: Path, langs: list[str], docs_prefix: str | None) -> None:
|
||||
agents_index = agents_root / "index.md"
|
||||
if agents_index.exists():
|
||||
return
|
||||
lines = [
|
||||
"# .agents(多语言)",
|
||||
"",
|
||||
@@ -859,7 +913,7 @@ def create_agents_index(agents_root: Path, langs: list[str], docs_prefix: str |
|
||||
f"- {docs_prefix or 'docs/standards/playbook/docs/'}",
|
||||
]
|
||||
agents_index.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
log("Created .agents/index.md")
|
||||
log("Synced .agents/index.md")
|
||||
|
||||
|
||||
def rewrite_agents_docs_links(agents_dir: Path, docs_prefix: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user