CtrlK
BlogDocsLog inGet started
Tessl Logo

jbaruch/speaker-toolkit

Seven-skill presentation system: ingest talks into a rhetoric vault, run interactive clarification, generate a speaker profile, create presentations that match your documented patterns, produce the deck illustrations + thumbnail visual layer, create and publish talk-content Agent Skills with talk pages to a Jekyll shownotes site, and verify a recorded screencast against its storyboard. Includes a 113-entry Presentation Patterns taxonomy (83 observable: 64 patterns + 19 antipatterns; 30 unobservable: 21 patterns + 9 antipatterns) for scoring, brainstorming, and go-live preparation.

75

Quality

94%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files

local_media_process.pyskills/vault-ingress/scripts/

"""Bounded subprocess pipes for use *inside* an authenticated media worker.

The outer artifact supervisor owns wall, process-tree and memory limits. This
helper adds strict retained-output and streamed-file byte limits without ever
collecting a media download in memory. A failed stream is never a usable file.
"""

from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
import subprocess
import threading
import time
from typing import BinaryIO, cast

from artifact_supervisor import (
    DiagnosticReceipt,
    _PipeDrainer,
    classify_cleanup_failure,
)
from local_media_contract import LocalMediaError, refuse


CHUNK_BYTES = 64 * 1024
PIPE_JOIN_SECONDS = 1.0
POLL_SECONDS = 0.01


@dataclass(frozen=True)
class MediaToolResult:
    returncode: int
    stdout: bytes
    streamed_bytes: int
    diagnostics: DiagnosticReceipt


class _FileSink:
    """Stop before the first byte that would exceed the on-disk ceiling."""

    def __init__(self, source: BinaryIO, target: BinaryIO, limit: int) -> None:
        self.source, self.target, self.limit = source, target, limit
        self.byte_count = 0
        self.overflowed = False
        self.failed = False
        self.complete = False
        self.thread = threading.Thread(target=self._run, daemon=True)

    @property
    def alive(self) -> bool:
        return self.thread.is_alive()

    def start(self) -> None:
        self.thread.start()

    def join(self, seconds: float) -> None:
        self.thread.join(seconds)

    def close(self) -> None:
        try:
            self.source.close()
        except OSError:
            self.failed = True

    def _run(self) -> None:
        try:
            while chunk := self.source.read(CHUNK_BYTES):
                if self.byte_count + len(chunk) > self.limit:
                    self.overflowed = True
                    return
                if self.target.write(chunk) != len(chunk):
                    self.failed = True
                    return
                self.byte_count += len(chunk)
            self.target.flush()
            self.complete = True
        except (OSError, ValueError):
            self.failed = True


def _stop(process: subprocess.Popen[bytes]) -> None:
    try:
        if process.poll() is None:
            try:
                process.terminate()
            except ProcessLookupError:
                pass
            try:
                process.wait(timeout=PIPE_JOIN_SECONDS)
            except subprocess.TimeoutExpired:
                process.kill()
                process.wait(timeout=PIPE_JOIN_SECONDS)
    except (OSError, subprocess.SubprocessError) as exc:
        # Name what failed. This site never reached the supervisor, so it was
        # still emitting a bare code after the supervisor's own cleanup
        # failures learned to carry one (#438).
        raise LocalMediaError(
            "media_cleanup_failed", classify_cleanup_failure(exc)
        ) from exc


def run_media_tool(
    command: list[str],
    *,
    stdout_limit: int,
    stderr_limit: int,
    output: Path | None = None,
    cwd: Path | None = None,
) -> MediaToolResult:
    """Capture bounded metadata or stream one literal exclusive-create output."""
    destination = None
    try:
        if output is not None:
            destination = output.open("xb", buffering=0)
        return _run(command, stdout_limit, stderr_limit, destination, cwd)
    except OSError as exc:
        raise LocalMediaError("media_pipe_failed") from exc
    finally:
        if destination is not None:
            destination.close()


def _run(
    command: list[str],
    stdout_limit: int,
    stderr_limit: int,
    destination: BinaryIO | None,
    cwd: Path | None,
) -> MediaToolResult:
    try:
        process = subprocess.Popen(
            command,
            stdin=subprocess.DEVNULL,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            bufsize=0,
            close_fds=True,
            cwd=cwd,
        )
    except (OSError, ValueError, subprocess.SubprocessError) as exc:
        raise LocalMediaError("media_dependency_unavailable") from exc
    if process.stdout is None or process.stderr is None:
        try:
            _stop(process)
        finally:
            for pipe in (process.stdout, process.stderr):
                if pipe is not None:
                    pipe.close()
        refuse("media_pipe_failed")
    stdout = (
        _FileSink(cast(BinaryIO, process.stdout), destination, stdout_limit)
        if destination is not None
        else _PipeDrainer(cast(BinaryIO, process.stdout), stdout_limit)
    )
    stderr = _PipeDrainer(cast(BinaryIO, process.stderr), stderr_limit)
    try:
        try:
            stdout.start()
            stderr.start()
        except RuntimeError as exc:
            raise LocalMediaError("media_pipe_failed") from exc
        while process.poll() is None:
            if stdout.overflowed or stderr.overflowed or stdout.failed or stderr.failed:
                _stop(process)
                break
            time.sleep(POLL_SECONDS)
        returncode = process.wait()
        stdout.join(PIPE_JOIN_SECONDS)
        stderr.join(PIPE_JOIN_SECONDS)
        if stdout.overflowed:
            refuse("media_tool_stdout_limit")
        if stderr.overflowed:
            refuse("media_tool_stderr_limit")
        if (
            stdout.alive
            or stderr.alive
            or stdout.failed
            or stderr.failed
            or (isinstance(stdout, _FileSink) and not stdout.complete)
        ):
            refuse("media_pipe_failed")
        return MediaToolResult(
            returncode,
            stdout.data if isinstance(stdout, _PipeDrainer) else b"",
            stdout.byte_count if isinstance(stdout, _FileSink) else 0,
            stderr.receipt,
        )
    finally:
        try:
            _stop(process)
        finally:
            stdout.close()
            stderr.close()

skills

vault-ingress

scripts

adherence_baseline.py

aggregate-catalog-feedback.py

apply-source-repairs.py

artifact_locator.py

artifact_metadata.py

artifact_supervisor.py

audit-pattern-catalog.py

audit-persisted-pattern-observations.py

audit-source-identities.py

batch-download-videos.py

build-contact-sheet.py

build-crop-reviewer.py

build-score-basis.py

catalog_dimension_registry.py

catalog_io.py

catalog_normalization.py

check-runtime.py

classify-pptx-evidence.py

cloud_artifacts.py

cooperative_lock.py

crop_frames.py

crop-reviewer-shell.html

crop-reviewer-shell.html.txt

crop-reviewer.js

crop-reviewer.js.txt

establish-date-provenance.py

failure_diagnostics.py

fetch-transcript.py

ingress_contract.py

local_media_contract.py

local_media_download.py

local_media_evidence.py

local_media_process.py

local_media_sampling.py

local_media_transcription.py

local_media_words.py

markdown_deck.py

migrate-tracking-database.py

mutate-tracking-database.py

pattern_evidence.py

pdf_evidence.py

persist-results.py

persisted_pattern_observations.py

pptx_catalog_selection.py

pptx_deck_facts.py

pptx_discovery_contract.py

pptx_evidence.py

pptx_talk_identity.py

pptx-extraction.py

preflight-vault.py

queue_claim_contract.py

queue-state.py

read-tracking-database.py

render-markdown-deck.py

render-vault-status.py

retained_stage.py

return_validation.py

run-obligations.py

scan-shownotes.py

source_alias_contract.py

source_identity_matching.py

summary_lock.py

sweep-pptx-talk-identity.py

tracking_database_io.py

tracking_database.py

transcript_quality.py

transcript_timing.py

validate-returns.py

vault_root_authority.py

video_evidence.py

video_integrity.py

video-slide-extraction.py

vtt-cleanup.py

write-analysis.py

ytdlp_runtime.py

SKILL.md

README.md

tile.json