Skip to content

OpenSenseNova/SenseNova-Skills / skills/sn-ppt-tools

sn-ppt-tools

Verified

Use when another PPT Skill needs web search, image search or download, or image generation and the host Agent's equivalent native capability is absent or has failed.

scripts/env_config.py

View on GitHub
"""Load persistent PPT tool settings without evaluating shell code."""

from __future__ import annotations

import os
import re
import shlex
from dataclasses import asdict, dataclass
from pathlib import Path


_ENV_NAME = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")


@dataclass(frozen=True)
class EnvLoadResult:
    path: str
    source: str
    exists: bool
    loaded_keys: tuple[str, ...] = ()
    preserved_process_keys: tuple[str, ...] = ()
    invalid_lines: tuple[int, ...] = ()
    error: str | None = None

    def to_dict(self) -> dict[str, object]:
        return asdict(self)


def resolve_env_path() -> tuple[Path, str]:
    explicit = os.environ.get("SN_PPT_ENV_FILE", "").strip()
    if explicit:
        return Path(explicit).expanduser().resolve(), "SN_PPT_ENV_FILE"
    if os.environ.get("OPENCLAW_SHELL", "").strip():
        return (Path.home() / ".openclaw" / ".env").resolve(), "openclaw"
    return (Path.home() / ".hermes" / ".env").resolve(), "hermes"


def _parse_value(raw: str) -> str:
    lexer = shlex.shlex(raw, posix=True)
    lexer.whitespace_split = True
    lexer.commenters = "#"
    return " ".join(lexer)


def load_ppt_env() -> EnvLoadResult:
    path, source = resolve_env_path()
    if not path.is_file():
        return EnvLoadResult(path=str(path), source=source, exists=False)

    loaded: list[str] = []
    preserved: list[str] = []
    invalid: list[int] = []
    try:
        lines = path.read_text(encoding="utf-8").splitlines()
    except OSError as exc:
        return EnvLoadResult(
            path=str(path),
            source=source,
            exists=True,
            error=f"{type(exc).__name__}: {exc}",
        )

    for line_number, raw_line in enumerate(lines, start=1):
        line = raw_line.strip()
        if not line or line.startswith("#"):
            continue
        if line.startswith("export "):
            line = line[7:].lstrip()
        name, separator, raw_value = line.partition("=")
        name = name.strip()
        if not separator or not _ENV_NAME.fullmatch(name):
            invalid.append(line_number)
            continue
        try:
            value = _parse_value(raw_value.strip())
        except ValueError:
            invalid.append(line_number)
            continue
        if name in os.environ:
            preserved.append(name)
            continue
        os.environ[name] = value
        loaded.append(name)

    return EnvLoadResult(
        path=str(path),
        source=source,
        exists=True,
        loaded_keys=tuple(sorted(loaded)),
        preserved_process_keys=tuple(sorted(preserved)),
        invalid_lines=tuple(invalid),
    )
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: 472kUpdated Claude CodeCodexVerifiedInstall
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: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
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 availableStars: 322kUpdated Claude CodeCodexVerifiedInstall