GodModeAI2025/SkillSafeWerkstatt / maintain-llm-wiki
maintain-llm-wiki
UnverifiedCreate, maintain, inventory, migrate, recover, quality-review, optionally clean, release, or export an evidence-linked SkillSafeWerkstatt Markdown wiki. Use whenever the user wants to initialize or extend this wiki, ingest documents as Markdown, curate claims, clusters or concepts, clean metadata, restore files, record who reviewed which pages, resolve a OneDrive or SharePoint conflict copy, publish a release, or export a frozen read-only knowledge skill or an Open Knowledge Format bundle in Claude Code, Claude Cowork, or Codex.
scripts/portable_io.py
View on GitHub#!/usr/bin/env python3
"""Atomic writes that survive a synchronization client holding a handle.
On Windows a sync client or an antivirus scanner briefly opens files it is
uploading, and the rename that completes an atomic write then fails with a
sharing violation. The operation is not wrong, only early, so a bounded retry
turns a spurious failure into a short wait.
Retries are deliberately few and short: they cover a transient handle, never a
genuine permission problem, and never a lock the wiki contract cares about.
"""
from __future__ import annotations
import errno
import os
import time
from pathlib import Path
from typing import Callable, TypeVar
from uuid import uuid4
#: Windows sharing-violation and access-denied codes seen from sync clients.
_WINDOWS_SHARING = frozenset({32, 33, 5})
#: Bounded backoff in seconds. Four attempts in total, under a second overall.
RETRY_DELAYS = (0.05, 0.15, 0.4)
T = TypeVar("T")
class TransientStorageError(OSError):
"""Raised when a storage operation kept failing for a transient reason."""
def _is_transient(exc: OSError) -> bool:
"""True for errors a synchronization client or scanner causes briefly."""
if isinstance(exc, PermissionError):
return True
winerror = getattr(exc, "winerror", None)
if winerror in _WINDOWS_SHARING:
return True
return exc.errno in {errno.EACCES, errno.EBUSY, errno.ETXTBSY}
def with_retry(operation: Callable[[], T], *, what: str) -> T:
"""Run one filesystem operation, retrying only transient storage failures."""
last: OSError
for delay in (*RETRY_DELAYS, None):
try:
return operation()
except OSError as exc:
if not _is_transient(exc) or delay is None:
if _is_transient(exc):
raise TransientStorageError(
f"{what} kept failing because another process holds the file. "
"A synchronization client or virus scanner is the usual cause; "
f"retry once it releases the handle. Last error: {exc}"
) from exc
raise
last = exc
time.sleep(delay)
raise last # pragma: no cover - the loop always returns or raises
def replace_with_retry(source: Path, destination: Path) -> None:
"""Rename `source` onto `destination`, retrying a transient sharing violation."""
with_retry(
lambda: os.replace(str(source), str(destination)),
what=f"replacing {destination.name}",
)
def atomic_write_bytes(path: Path, content: bytes, *, mode: int = 0o600) -> None:
"""Write `content` to `path` atomically, durably, and with a bounded retry."""
path.parent.mkdir(parents=True, exist_ok=True)
temporary = path.with_name(f".{path.name}.{uuid4().hex}.tmp")
descriptor = os.open(str(temporary), os.O_WRONLY | os.O_CREAT | os.O_EXCL, mode)
try:
with os.fdopen(descriptor, "wb") as handle:
handle.write(content)
handle.flush()
os.fsync(handle.fileno())
replace_with_retry(temporary, path)
finally:
if temporary.exists():
try:
temporary.unlink()
except OSError:
pass
def atomic_write_text(path: Path, text: str, *, encoding: str = "utf-8") -> None:
atomic_write_bytes(path, text.encode(encoding))
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |