Skip to content
Back to search

oaustegard-claude-skills

MarketplaceWorks with Claude CodeGitHub

Community skills for Claude Code and Claude.ai

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

Its scripts were only partly scanned.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/oaustegard/claude-skills with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/oaustegard/claude-skills'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/oaustegard--claude-skills/badge.svg)](/listings/oaustegard--claude-skills)

HTML

<a href="/listings/oaustegard--claude-skills"><img src="/api/listings/oaustegard--claude-skills/badge.svg" alt="findsafeskills safety rating" /></a>

Install

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Add this repository as a plugin marketplace in Claude Code:

/plugin marketplace add oaustegard/claude-skills

Then browse and install individual plugins:

/plugin install skill-name@oaustegard-claude-skills

Update all marketplace plugins to latest:

/plugin marketplace update

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/marketplace.json · Manifest · 293 lines
  1. {
  2. "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
  3. "name": "oaustegard-claude-skills",
  4. "description": "Community skills for Claude Code and Claude.ai",
  5. "metadata": {
  6. "version": "2026.1117.0038"
  7. },
  8. "owner": {
  9. "name": "Oskar Austegard"
  10. },
  11. "plugins": [
  12. {
  13. "name": "ai-and-reasoning",
  14. "description": "AI model invocation, multi-agent orchestration, prompt distillation, and structured reasoning frameworks.",
  15. "source": "./plugins/ai-and-reasoning",
  16. "version": "2.9.1",
  17. "repository": "https://github.com/oaustegard/claude-skills",
  18. "homepage": "https://github.com/oaustegard/claude-skills",
  19. "license": "MIT",
  20. "category": "Ai And Reasoning",
  21. "keywords": [
  22. "orchestrating-chat-agents",
  23. "agent-routing",
  24. "challenging",
  25. "convening-experts",
  26. "deciding-with-confidence",
  27. "delegating-with-context",
  28. "dispatching-subagents",
  29. "down-skilling",
  30. "evolving-with-swarms",
  31. "gating",
  32. "generative-thinking",
  33. "invoking-antigravity",
  34. "invoking-gemini",
  35. "llm-as-computer",
  36. "orchestrating-agents",
  37. "reviewing-ai-papers",
  38. "swarming-to-green",
  39. "tiling-tree",
  40. "verifying-claims",
  41. "verifying-review-findings"
  42. ]
  43. },
  44. {
  45. "name": "code-intelligence",
  46. "description": "Codebase exploration, navigation, mapping, and static analysis tools for understanding unfamiliar codebases.",
  47. "source": "./plugins/code-intelligence",
  48. "version": "2.6.0",
  49. "repository": "https://github.com/oaustegard/claude-skills",
  50. "homepage": "https://github.com/oaustegard/claude-skills",
  51. "license": "MIT",
  52. "category": "Code Intelligence",
  53. "keywords": [
  54. "assessing-impact",
  55. "declaring-invariants",
  56. "describing-products",
  57. "exploring-codebases",
  58. "featuring",
  59. "hunting-failing-inputs",
  60. "mapping-codebases",
  61. "mapping-webapp",
  62. "orienting-codebases",
  63. "python-lsp",
  64. "reasoning-semiformally",
  65. "searching-codebases",
  66. "semantic-grep",
  67. "tree-sitting"
  68. ]
  69. },
  70. {
  71. "name": "data-and-visualization",
  72. "description": "Data analysis, charting, forecasting, and interactive visualization tools.",
  73. "source": "./plugins/data-and-visualization",
  74. "version": "1.0.0",
  75. "repository": "https://github.com/oaustegard/claude-skills",
  76. "homepage": "https://github.com/oaustegard/claude-skills",
  77. "license": "MIT",
  78. "category": "Data And Visualization",
  79. "keywords": [
  80. "charting",
  81. "charting-vega-lite",
  82. "exploring-data",
  83. "extracting-keywords",
  84. "forecasting-reverso",
  85. "json-render-ui",
  86. "making-tinyoffice-links"
  87. ]
  88. },
  89. {
  90. "name": "development-tools",
  91. "description": "Software development utilities: MCP servers, bookmarklets, frameworks, patching, and environment validation.",
  92. "source": "./plugins/development-tools",
  93. "version": "1.2.1",
  94. "repository": "https://github.com/oaustegard/claude-skills",
  95. "homepage": "https://github.com/oaustegard/claude-skills",
  96. "license": "MIT",
  97. "category": "Development Tools",
  98. "keywords": [
  99. "capturing-browser-logs",
  100. "check-tools",
  101. "coding-mojo",
  102. "compiling-wgsl",
  103. "composing-html",
  104. "creating-bookmarklets",
  105. "creating-mcp-servers",
  106. "developing-preact",
  107. "generating-patches",
  108. "querying-markdown"
  109. ]
  110. },
  111. {
  112. "name": "environment-and-config",
  113. "description": "Environment setup, credential management, container building, and workflow orchestration.",
  114. "source": "./plugins/environment-and-config",
  115. "version": "2.0.0",
  116. "repository": "https://github.com/oaustegard/claude-skills",
  117. "homepage": "https://github.com/oaustegard/claude-skills",
  118. "license": "MIT",
  119. "category": "Environment And Config",
  120. "keywords": [
  121. "api-credentials",
  122. "configuring",
  123. "container-layer",
  124. "flowing",
  125. "uploading-files"
  126. ]
  127. },
  128. {
  129. "name": "github-and-git",
  130. "description": "GitHub repository access, CLI operations, indexing, and git workflow tools.",
  131. "source": "./plugins/github-and-git",
  132. "version": "2.0.1",
  133. "repository": "https://github.com/oaustegard/claude-skills",
  134. "homepage": "https://github.com/oaustegard/claude-skills",
  135. "license": "MIT",
  136. "category": "Github And Git",
  137. "keywords": [
  138. "accessing-github-repos",
  139. "building-github-index",
  140. "closing-issues",
  141. "githubbing",
  142. "invoking-github",
  143. "opening-prs"
  144. ]
  145. },
  146. {
  147. "name": "knowledge-and-memory",
  148. "description": "Research methodology, corpus search, persistent memory, iterative workflows, and project knowledge management.",
  149. "source": "./plugins/knowledge-and-memory",
  150. "version": "1.3.0",
  151. "repository": "https://github.com/oaustegard/claude-skills",
  152. "homepage": "https://github.com/oaustegard/claude-skills",
  153. "license": "MIT",
  154. "category": "Knowledge And Memory",
  155. "keywords": [
  156. "asking-questions",
  157. "bm25",
  158. "cloning-project",
  159. "creating-kb",
  160. "iterating",
  161. "mapping-documents",
  162. "session-memory",
  163. "tracking-todos",
  164. "updating-knowledge"
  165. ]
  166. },
  167. {
  168. "name": "media-processing",
  169. "description": "Image manipulation, video/audio processing, file format conversion, SVG conversion, and computer vision augmentation.",
  170. "source": "./plugins/media-processing",
  171. "version": "2.3.0",
  172. "repository": "https://github.com/oaustegard/claude-skills",
  173. "homepage": "https://github.com/oaustegard/claude-skills",
  174. "license": "MIT",
  175. "category": "Media Processing",
  176. "keywords": [
  177. "animating-with-code",
  178. "converting-files",
  179. "creating-video",
  180. "detecting-tips-zones",
  181. "drawing-video",
  182. "drawing-with-pycairo",
  183. "image-to-svg",
  184. "listening-to-music",
  185. "making-kinescript-videos",
  186. "making-remotion-videos",
  187. "parsing-video",
  188. "processing-images",
  189. "processing-video",
  190. "reading-business-cards",
  191. "seeing-images",
  192. "svg-portrait-mode",
  193. "transcribing-images"
  194. ]
  195. },
  196. {
  197. "name": "skill-development",
  198. "description": "Tools for creating, versioning, installing, inspecting, and orchestrating Claude skills.",
  199. "source": "./plugins/skill-development",
  200. "version": "2.6.0",
  201. "repository": "https://github.com/oaustegard/claude-skills",
  202. "homepage": "https://github.com/oaustegard/claude-skills",
  203. "license": "MIT",
  204. "category": "Skill Development",
  205. "keywords": [
  206. "crafting-instructions",
  207. "creating-skill",
  208. "finding-skills",
  209. "inspecting-skills",
  210. "installing-skills",
  211. "optimizing-skills",
  212. "orchestrating-skills",
  213. "versioning-skills",
  214. "writing-instructions"
  215. ]
  216. },
  217. {
  218. "name": "social-and-lifestyle",
  219. "description": "Social media browsing, content analysis, music control, and everyday utility tools.",
  220. "source": "./plugins/social-and-lifestyle",
  221. "version": "1.0.0",
  222. "repository": "https://github.com/oaustegard/claude-skills",
  223. "homepage": "https://github.com/oaustegard/claude-skills",
  224. "license": "MIT",
  225. "category": "Social And Lifestyle",
  226. "keywords": [
  227. "atprotoing",
  228. "browsing-bluesky",
  229. "categorizing-bsky-accounts",
  230. "controlling-spotify",
  231. "making-waffles",
  232. "sorting-groceries"
  233. ]
  234. },
  235. {
  236. "name": "web-and-retrieval",
  237. "description": "Web content fetching, browser automation, and URL handling tools.",
  238. "source": "./plugins/web-and-retrieval",
  239. "version": "1.0.4",
  240. "repository": "https://github.com/oaustegard/claude-skills",
  241. "homepage": "https://github.com/oaustegard/claude-skills",
  242. "license": "MIT",
  243. "category": "Web And Retrieval",
  244. "keywords": [
  245. "fetching-blocked-urls",
  246. "hello-demo",
  247. "using-webctl"
  248. ]
  249. },
  250. {
  251. "name": "deciding-with-confidence",
  252. "description": "Routes, triages, flags and rates a piece of text with a probability for every option: which department or queue a ticket goes to, which intent a message expresses, whether a yes/no condition holds (is this tool call grounded, should the agent ask first, is the customer angry), and how severe or urgent it is on a rubric, each with a calibrated confidence. Runs Claude Haiku in the request and response shapes of OpenAI's Decisions API, or of TypeSafe's System One API (Jev's), for when no purpose-built decision model is at hand. Use for \"route this ticket\", \"triage these\", \"classify with a confidence\", \"give me a probability that\", \"rate the severity\", \"score against this rubric\", guardrail checks before a tool call, \"a Decisions API without OpenAI\", or a stand-in for Jev.",
  253. "source": "./plugins/deciding-with-confidence",
  254. "version": "0.4.0",
  255. "repository": "https://github.com/oaustegard/claude-skills",
  256. "homepage": "https://github.com/oaustegard/claude-skills",
  257. "license": "MIT",
  258. "category": "Agents",
  259. "keywords": [
  260. "deciding-with-confidence",
  261. "agents"
  262. ]
  263. },
  264. {
  265. "name": "declauding",
  266. "description": "Load it without being asked at the start of any task whose deliverable is prose that another person will read, such as a PR description, commit message, README, doc, postmortem, blog post, issue or review comment, report, release note or essay, and run it on the draft before the text is pushed, posted, published or saved. Draft first without this skill in context, from a positive writing brief if one exists. Also use it when someone says \"de-claude\", \"de-slop\", \"humanize this\", \"this reads like AI\" or \"make it sound human\", or asks for a voice, tone or register edit. It rewrites the constructions that mark prose as model-written into plain technical prose, and checks that the rewrite kept the draft's claims. The constructions include staged reveals, verdict headers, aphoristic closers, \"it's not X, it's Y\", em-dash drama, forced triads, flat-certainty adverbs, noun stacks and dropped 'that'. Do not use it on fiction, poetry, code or quoted text. For a full adversarial review of a deliverable, use challenging.",
  267. "source": "./plugins/declauding",
  268. "version": "0.14.0",
  269. "repository": "https://github.com/oaustegard/claude-skills",
  270. "homepage": "https://github.com/oaustegard/claude-skills",
  271. "license": "MIT",
  272. "category": "Hooks",
  273. "keywords": [
  274. "declauding",
  275. "hooks"
  276. ]
  277. },
  278. {
  279. "name": "delegating-with-context",
  280. "description": "Delegates work to a subagent or spawned session by writing only the task, while a PreToolUse hook pages the parent transcript through Jev and appends the chunks that task needs. Use before writing any Agent tool prompt or create_session prompt, and when asked to delegate this, hand this off, use a subagent, spawn an agent, run agents in parallel, or brief a subagent on what we have done so far.",
  281. "source": "./plugins/delegating-with-context",
  282. "version": "0.3.0",
  283. "repository": "https://github.com/oaustegard/claude-skills",
  284. "homepage": "https://github.com/oaustegard/claude-skills",
  285. "license": "MIT",
  286. "category": "Hooks",
  287. "keywords": [
  288. "delegating-with-context",
  289. "hooks"
  290. ]
  291. }
  292. ]
  293. }
README.md · README · 96 lines · 1 finding marked
  1. # claude-skills
  2. A collection of Claude skills distributed as a **Claude Code plugin marketplace**. Skills are primarily designed for the Claude.ai PaaS skill compute environment; mileage will vary if used as Claude Code Agent Skills.
  3. ## Installing as a Plugin Marketplace (Claude Code)
  4. Add this repository as a plugin marketplace in Claude Code:
  5. ```
  6. /plugin marketplace add oaustegard/claude-skills
  7. ```
  8. Then browse and install individual plugins:
  9. ```
  10. /plugin install skill-name@oaustegard-claude-skills
  11. ```
  12. Update all marketplace plugins to latest:
  13. ```
  14. /plugin marketplace update
  15. ```
  16. ## Installing Skills for Claude.ai (Web/Mobile)
  17. 1. You need a paid Claude account (Pro or Team)
  18. 2. Download the skill ZIP from the [Releases page](../../releases)
  19. - **Note:** Use the direct download link for the skill ZIP, not the "Source code" archives auto-generated by GitHub
  20. 3. Upload to [Claude.ai Customize › Skills](https://claude.ai/customize/skills)
  21. 4. See [official documentation](https://support.claude.com/en/articles/12512198-how-to-create-custom-skills) for more details
  22. ### Automated Installation (Claude Code)
  23. Install skills directly to your project with a single command:
  24. ```bash
  25. curl -fsSL https://raw.githubusercontent.com/oaustegard/claude-skills/main/templates/installation/install-skills.sh | bash
    • Note: Pipes a downloaded script directly into a shell (curl | sh / wget | bash)
    • Line 38 on GitHub
  26. ```
  27. Or download and customize which skills to install:
  28. ```bash
  29. curl -O https://raw.githubusercontent.com/oaustegard/claude-skills/main/templates/installation/install-skills.sh
  30. nano install-skills.sh # Edit SKILLS array
  31. chmod +x install-skills.sh && ./install-skills.sh
  32. ```
  33. **CI/CD Integration:**
  34. ```bash
  35. mkdir -p .github/workflows
  36. curl -o .github/workflows/install-skills.yml \
  37. https://raw.githubusercontent.com/oaustegard/claude-skills/main/templates/installation/install-skills.yml
  38. ```
  39. For complete documentation, see [templates/installation/README.md](templates/installation/README.md)
  40. ## Adding Skills
  41. ### Via ZIP Upload (Easiest)
  42. 1. Create your skill folder with `SKILL.md` at the root
  43. 2. Package your skill:
  44. ```bash
  45. your-skill.zip
  46. └── your-skill/
  47. ├── SKILL.md
  48. └── resources/ (optional)
  49. ```
  50. 3. Upload the ZIP to the `.uploads/` directory
  51. 4. The workflow will automatically create a PR with your skill content
  52. ### Via Direct Development
  53. 1. Create a new branch
  54. 2. Add your skill folder at the repository root (SKILL.md and resources)
  55. 3. Submit a PR with your skill content
  56. ## Releasing Skills
  57. Releases are triggered by updating `metadata.version` in SKILL.md frontmatter on main branch.
  58. ### Version Format
  59. Use [semantic versioning](https://semver.org/):
  60. - `0.1.0` - Initial release
  61. - `0.1.1` - Patch (bug fixes)
  62. - `0.2.0` - Minor (new features, backward compatible)
  63. - `1.0.0` - Major (breaking changes)
  64. ## Resources
  65. - [Introducing Agent Skills](https://www.anthropic.com/news/skills)
  66. - [Claude Code Plugin Marketplaces](https://code.claude.com/docs/en/plugin-marketplaces)
  67. - [Creating Custom Skills](https://support.claude.com/en/articles/12512198-how-to-create-custom-skills)
container-layer/scripts/containerfile.py · Bundled script · 544 lines · 1 finding marked
  1. """
  2. Containerfile parser and executor.
  3. Parses a Dockerfile-like spec and executes the supported subset of instructions,
  4. tracking which filesystem paths are modified for layer snapshot/caching.
  5. """
  6. import hashlib
  7. import json
  8. import os
  9. import re
  10. import shlex
  11. import subprocess
  12. import urllib.request
  13. from dataclasses import dataclass, field
  14. from pathlib import Path
  15. # Instructions we execute
  16. EXECUTABLE_INSTRUCTIONS = {"ENV", "RUN", "FETCH", "WORKDIR", "SNAPSHOT"}
  17. # Instructions we silently ignore (Dockerfile compat)
  18. IGNORED_INSTRUCTIONS = {
  19. "FROM", "EXPOSE", "CMD", "ENTRYPOINT", "LABEL",
  20. "ARG", "VOLUME", "USER", "SHELL", "HEALTHCHECK",
  21. "STOPSIGNAL", "ONBUILD",
  22. }
  23. # Well-known paths that pip/uv/apt install into.
  24. # `_dedup_paths` uses these as baseline keys so that auto-tracked snapshot
  25. # paths (from RUN commands) get the diff-vs-baseline treatment instead of
  26. # whole-tree capture.
  27. #
  28. # Lists all common Python versions so the diff logic works regardless of
  29. # which interpreter is active. The single-entry list pre-0.2.1 hardcoded
  30. # python3.12, so containers on python3.11 captured all of dist-packages
  31. # instead of just newly-installed files.
  32. #
  33. # /usr/{bin,lib,share} are here so `apt-get install` layers diff correctly
  34. # — `_exec_run` auto-adds these to snapshot_paths on any apt invocation
  35. # (one .deb pulls in shared libs / headers / docs sprawled across all
  36. # three). Pre-0.2.2 they fell into the whole-tree path: adding `zstd`
  37. # to a layer captured ~3GB raw → ~600MB compressed.
  38. #
  39. # Despite the name, this list is no longer Python-only. Kept the name for
  40. # backwards-compat with any external importer; consider renaming to
  41. # BASELINED_PATHS in a future major bump.
  42. PYTHON_INSTALL_PATHS = [
  43. "/usr/local/lib/python3.10/dist-packages",
  44. "/usr/local/lib/python3.11/dist-packages",
  45. "/usr/local/lib/python3.12/dist-packages",
  46. "/usr/local/lib/python3.13/dist-packages",
  47. "/usr/local/bin",
  48. "/usr/bin",
  49. "/usr/lib",
  50. "/usr/share",
  51. "/home/claude/.local/lib",
  52. "/home/claude/.local/bin",
  53. ]
  54. @dataclass
  55. class Instruction:
  56. """A parsed Containerfile instruction."""
  57. line_num: int
  58. directive: str
  59. args: str
  60. raw: str
  61. @dataclass
  62. class BuildResult:
  63. """Result of executing a Containerfile."""
  64. success: bool
  65. snapshot_paths: list[str]
  66. content_hash: str
  67. errors: list[str] = field(default_factory=list)
  68. env_vars: dict[str, str] = field(default_factory=dict)
  69. def parse_containerfile(path: str) -> list[Instruction]:
  70. """Parse a Containerfile into a list of Instructions."""
  71. instructions = []
  72. content = Path(path).read_text()
  73. # Handle line continuations
  74. content = re.sub(r'\\\n\s*', ' ', content)
  75. for line_num, line in enumerate(content.splitlines(), 1):
  76. line = line.strip()
  77. # Skip comments and blank lines
  78. if not line or line.startswith('#'):
  79. continue
  80. # Extract directive and args
  81. match = re.match(r'^([A-Z]+)\s+(.*)', line)
  82. if not match:
  83. continue
  84. directive, args = match.group(1), match.group(2).strip()
  85. if directive in EXECUTABLE_INSTRUCTIONS:
  86. instructions.append(Instruction(line_num, directive, args, line))
  87. elif directive in IGNORED_INSTRUCTIONS:
  88. continue # silently skip
  89. else:
  90. print(f" WARNING line {line_num}: unknown instruction '{directive}', skipping")
  91. return instructions
  92. def content_hash(path: str, extra_salt: str = "") -> str:
  93. """SHA-256 hash of a Containerfile's contents (the cache key).
  94. Optionally include extra_salt (e.g. a git SHA) so the cache
  95. invalidates when external dependencies change.
  96. """
  97. content = Path(path).read_text().strip()
  98. if extra_salt:
  99. content += f"\n# salt: {extra_salt}"
  100. return hashlib.sha256(content.encode()).hexdigest()[:16]
  101. def default_layer_name(containerfile_path: str) -> str:
  102. """Derive a default layer name from a Containerfile path.
  103. `Containerfile` -> 'base'
  104. `Containerfile.mojo` -> 'mojo'
  105. `layers/Containerfile.scientific` -> 'scientific'
  106. `foo/bar.txt` -> 'bar' (fallback: file stem)
  107. Names are lowercased and stripped of non-[a-z0-9-_] characters so they're
  108. safe to embed in GitHub Release tags (`layer-<name>-<hash>`).
  109. """
  110. basename = os.path.basename(containerfile_path)
  111. if basename == "Containerfile":
  112. raw = "base"
  113. elif basename.startswith("Containerfile."):
  114. raw = basename[len("Containerfile."):]
  115. else:
  116. # Fallback: stem of whatever path was passed
  117. raw = os.path.splitext(basename)[0]
  118. # Sanitize: keep alphanumerics, hyphen, underscore, period -> hyphen
  119. safe = re.sub(r"[^a-z0-9_-]", "-", raw.lower()).strip("-")
  120. return safe or "layer"
  121. def github_head_sha(repo: str, ref: str = "main", token: str = "") -> str:
  122. """Fetch the HEAD SHA of a GitHub repo ref. Returns empty string on failure."""
  123. try:
  124. url = f"https://api.github.com/repos/{repo}/commits/{ref}"
  125. headers = {"Accept": "application/vnd.github+json"}
  126. if token:
  127. headers["Authorization"] = f"token {token}"
  128. req = urllib.request.Request(url, headers=headers)
  129. with urllib.request.urlopen(req, timeout=10) as resp:
  130. data = json.loads(resp.read())
  131. return data.get("sha", "")[:12]
  132. except Exception:
  133. return ""
  134. def snapshot_baseline(paths: list[str]) -> dict[str, set[str]]:
  135. """Capture the set of files currently in each path (for diffing later)."""
  136. baseline = {}
  137. for p in paths:
  138. p = os.path.normpath(p)
  139. if os.path.isdir(p):
  140. files = set()
  141. for root, dirs, fnames in os.walk(p):
  142. for f in fnames:
  143. files.add(os.path.join(root, f))
  144. baseline[p] = files
  145. elif os.path.isfile(p):
  146. baseline[p] = {p}
  147. else:
  148. baseline[p] = set()
  149. return baseline
  150. def diff_paths(baseline: dict[str, set[str]], paths: list[str]) -> list[str]:
  151. """
  152. Given a baseline snapshot and current paths, return a list of
  153. new/modified files to include in the layer tarball.
  154. For FETCH destinations (not in baseline), include everything.
  155. """
  156. new_files = []
  157. for p in paths:
  158. p = os.path.normpath(p)
  159. if p not in baseline:
  160. # New path (e.g. FETCH destination) — include whole tree
  161. if os.path.exists(p):
  162. new_files.append(p)
  163. continue
  164. if os.path.isdir(p):
  165. current = set()
  166. for root, dirs, fnames in os.walk(p):
  167. for f in fnames:
  168. current.add(os.path.join(root, f))
  169. added = current - baseline[p]
  170. if added:
  171. new_files.extend(sorted(added))
  172. elif os.path.isfile(p):
  173. if p not in baseline[p]:
  174. new_files.append(p)
  175. return new_files
  176. class ContainerfileExecutor:
  177. """Executes a parsed Containerfile, tracking modified paths."""
  178. def __init__(self, gh_token: str | None = None):
  179. self.snapshot_paths: list[str] = []
  180. self.env: dict[str, str] = dict(os.environ)
    • Dismissed after review: Sends out every environment variable, where API keys and tokens live
    • Line 216 on GitHub
  181. self.workdir: str = "/home/claude"
  182. self.gh_token = gh_token or os.environ.get("GH_TOKEN", "")
  183. self.errors: list[str] = []
  184. self._baseline: dict[str, set[str]] = {}
  185. def execute(self, instructions: list[Instruction]) -> BuildResult:
  186. """Execute all instructions, return result with snapshot paths."""
  187. file_hash = "" # Caller should set this
  188. # Capture baseline of well-known install paths before building
  189. self._baseline = snapshot_baseline(PYTHON_INSTALL_PATHS)
  190. for inst in instructions:
  191. try:
  192. handler = getattr(self, f"_exec_{inst.directive.lower()}", None)
  193. if handler:
  194. print(f" [{inst.line_num}] {inst.raw}")
  195. handler(inst)
  196. else:
  197. self.errors.append(f"Line {inst.line_num}: no handler for {inst.directive}")
  198. except Exception as e:
  199. msg = f"Line {inst.line_num}: {inst.directive} failed: {e}"
  200. self.errors.append(msg)
  201. print(f" ERROR: {msg}")
  202. return BuildResult(
  203. success=False,
  204. snapshot_paths=self._dedup_paths(),
  205. content_hash=file_hash,
  206. errors=self.errors,
  207. env_vars={k: v for k, v in self.env.items() if k not in os.environ or os.environ[k] != v},
  208. )
  209. return BuildResult(
  210. success=True,
  211. snapshot_paths=self._dedup_paths(),
  212. content_hash=file_hash,
  213. errors=self.errors,
  214. env_vars={k: v for k, v in self.env.items() if k not in os.environ or os.environ[k] != v},
  215. )
  216. def _exec_env(self, inst: Instruction):
  217. """ENV KEY=value or ENV KEY value"""
  218. if '=' in inst.args:
  219. key, _, value = inst.args.partition('=')
  220. value = value.strip('"').strip("'")
  221. else:
  222. parts = inst.args.split(None, 1)
  223. key = parts[0]
  224. value = parts[1] if len(parts) > 1 else ""
  225. self.env[key.strip()] = value
  226. os.environ[key.strip()] = value
  227. def _exec_workdir(self, inst: Instruction):
  228. """WORKDIR /path"""
  229. path = inst.args.strip()
  230. os.makedirs(path, exist_ok=True)
  231. self.workdir = path
  232. def _exec_run(self, inst: Instruction):
  233. """RUN command — execute shell command, detect package installs."""
  234. cmd = inst.args
  235. # Detect pip/uv installs to track snapshot paths
  236. if re.search(r'\b(pip|uv pip)\s+install\b', cmd):
  237. for p in PYTHON_INSTALL_PATHS:
  238. if p not in self.snapshot_paths:
  239. self.snapshot_paths.append(p)
  240. # Auto-add --break-system-packages if not present (externally managed envs)
  241. if '--break-system-packages' not in cmd:
  242. cmd = cmd.replace('install', 'install --break-system-packages', 1)
  243. # Detect apt installs
  244. if re.search(r'\bapt(-get)?\s+install\b', cmd):
  245. self.snapshot_paths.extend([
  246. "/usr/lib",
  247. "/usr/bin",
  248. "/usr/share",
  249. ])
  250. result = subprocess.run(
  251. cmd, shell=True, cwd=self.workdir, env=self.env,
  252. capture_output=True, text=True, timeout=300,
  253. )
  254. if result.stdout.strip():
  255. # Print last 5 lines of stdout to avoid noise
  256. lines = result.stdout.strip().splitlines()
  257. for line in lines[-5:]:
  258. print(f" {line}")
  259. if len(lines) > 5:
  260. print(f" ... ({len(lines) - 5} lines omitted)")
  261. if result.returncode != 0:
  262. raise RuntimeError(f"Command failed (exit {result.returncode}): {result.stderr.strip()}")
  263. def _exec_fetch(self, inst: Instruction):
  264. """FETCH source dest — fetch from URL or GitHub."""
  265. parts = shlex.split(inst.args)
  266. if len(parts) < 2:
  267. raise ValueError("FETCH requires <source> <dest>")
  268. source, dest = parts[0], parts[1]
  269. os.makedirs(dest, exist_ok=True)
  270. self.snapshot_paths.append(dest)
  271. if source.startswith("github:"):
  272. self._fetch_github(source[7:], dest)
  273. elif source.startswith("http://") or source.startswith("https://"):
  274. self._fetch_url(source, dest)
  275. else:
  276. raise ValueError(f"Unknown FETCH source: {source}")
  277. def _exec_snapshot(self, inst: Instruction):
  278. """SNAPSHOT /path — explicitly add a path to the snapshot."""
  279. path = inst.args.strip()
  280. if path and path not in self.snapshot_paths:
  281. self.snapshot_paths.append(path)
  282. def _fetch_github(self, spec: str, dest: str):
  283. """Fetch a GitHub repo tarball. Spec: user/repo or user/repo@ref"""
  284. if '@' in spec:
  285. repo, ref = spec.rsplit('@', 1)
  286. else:
  287. repo, ref = spec, "main"
  288. url = f"https://codeload.github.com/{repo}/tar.gz/{ref}"
  289. tarball = f"/tmp/_fetch_{repo.replace('/', '_')}.tar.gz"
  290. headers = ""
  291. if self.gh_token:
  292. headers = f'-H "Authorization: token {self.gh_token}"'
  293. cmd = f'curl -sL {headers} "{url}" -o "{tarball}" && tar -xzf "{tarball}" -C "{dest}" --strip-components=1 && rm -f "{tarball}"'
  294. result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=120)
  295. if result.returncode != 0:
  296. raise RuntimeError(f"GitHub fetch failed: {result.stderr.strip()}")
  297. print(f" Fetched {repo}@{ref} → {dest}")
  298. def _fetch_url(self, url: str, dest: str):
  299. """Fetch a URL to a destination."""
  300. filename = url.rsplit('/', 1)[-1] or "download"
  301. dest_file = os.path.join(dest, filename)
  302. cmd = f'curl -sL "{url}" -o "{dest_file}"'
  303. result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=120)
  304. if result.returncode != 0:
  305. raise RuntimeError(f"URL fetch failed: {result.stderr.strip()}")
  306. # Auto-extract tarballs
  307. if filename.endswith(('.tar.gz', '.tgz')):
  308. subprocess.run(f'tar -xzf "{dest_file}" -C "{dest}" && rm -f "{dest_file}"',
  309. shell=True, capture_output=True, timeout=60)
  310. print(f" Fetched and extracted {filename} → {dest}")
  311. else:
  312. print(f" Fetched {filename} → {dest}")
  313. def _dedup_paths(self) -> list[str]:
  314. """Deduplicate, filter, and diff snapshot paths.
  315. For paths that existed before build (pip install targets), only
  316. capture new files. For FETCH destinations and explicit SNAPSHOTs,
  317. capture everything.
  318. """
  319. seen = set()
  320. result = []
  321. # Separate paths into baselined (pip/apt targets) and new (FETCH/SNAPSHOT)
  322. baselined = set(self._baseline.keys())
  323. for p in self.snapshot_paths:
  324. p = os.path.normpath(p)
  325. if p in seen or not os.path.exists(p):
  326. continue
  327. seen.add(p)
  328. if p in baselined:
  329. # For baselined paths, compute diff — individual new files
  330. new_files = diff_paths({p: self._baseline[p]}, [p])
  331. result.extend(new_files)
  332. else:
  333. # For FETCH destinations and explicit SNAPSHOTs, take the whole tree
  334. result.append(p)
  335. return result
  336. class ContainerLayer:
  337. """
  338. High-level interface: parse a Containerfile, execute or restore from cache.
  339. A layer can optionally have a `layer_name`. When set, the cache release
  340. tag becomes `layer-<name>-<hash>` instead of `layer-<hash>`. This enables
  341. composing multiple named layers (each cached independently) into a single
  342. container, and lets cache-retention policies operate per-name.
  343. Back-compat: if `layer_name` is None, the tag stays `layer-<hash>` so
  344. existing single-Containerfile callers don't see their cache invalidate.
  345. """
  346. def __init__(
  347. self,
  348. containerfile_path: str,
  349. cache_repo: str = "oaustegard/claude-container-layers",
  350. gh_token: str | None = None,
  351. salt: str = "",
  352. layer_name: str | None = None,
  353. ):
  354. self.containerfile_path = containerfile_path
  355. self.cache_repo = cache_repo
  356. self.gh_token = gh_token or os.environ.get("GH_TOKEN", "")
  357. self.layer_name = layer_name
  358. self._hash = content_hash(containerfile_path, extra_salt=salt)
  359. @property
  360. def tag(self) -> str:
  361. if self.layer_name:
  362. return f"layer-{self.layer_name}-{self._hash}"
  363. return f"layer-{self._hash}"
  364. def restore_or_build(self) -> BuildResult:
  365. """Try cache restore first, fall back to full build."""
  366. from . import layer_cache
  367. print(f"Container layer hash: {self._hash}")
  368. if layer_cache.try_restore(self.cache_repo, self.tag, self.gh_token):
  369. print("✓ Restored from cache")
  370. # Still need to replay ENV instructions
  371. instructions = parse_containerfile(self.containerfile_path)
  372. env_instructions = [i for i in instructions if i.directive == "ENV"]
  373. executor = ContainerfileExecutor(self.gh_token)
  374. for inst in env_instructions:
  375. executor._exec_env(inst)
  376. return BuildResult(
  377. success=True, snapshot_paths=[], content_hash=self._hash,
  378. env_vars=executor.env,
  379. )
  380. print("Cache miss — building from Containerfile...")
  381. return self.build_and_push()
  382. def build_and_push(self) -> BuildResult:
  383. """Execute Containerfile, snapshot, and push to cache."""
  384. from . import layer_cache
  385. instructions = parse_containerfile(self.containerfile_path)
  386. executor = ContainerfileExecutor(self.gh_token)
  387. result = executor.execute(instructions)
  388. result.content_hash = self._hash
  389. if result.success and result.snapshot_paths:
  390. print(f"\nSnapshotting {len(result.snapshot_paths)} paths...")
  391. layer_cache.build_and_push(
  392. result.snapshot_paths, self.cache_repo, self.tag, self.gh_token
  393. )
  394. return result
  395. def build_only(self) -> BuildResult:
  396. """Execute Containerfile without caching (for testing)."""
  397. instructions = parse_containerfile(self.containerfile_path)
  398. executor = ContainerfileExecutor(self.gh_token)
  399. result = executor.execute(instructions)
  400. result.content_hash = self._hash
  401. return result
  402. def compose(
  403. containerfile_paths: list[str],
  404. cache_repo: str = "oaustegard/claude-container-layers",
  405. gh_token: str | None = None,
  406. salt: str = "",
  407. names: list[str | None] | None = None,
  408. ) -> list[BuildResult]:
  409. """Restore (or build+push, on miss) a sequence of named layers in order.
  410. Each Containerfile becomes a named ContainerLayer with its own cache
  411. key and GitHub Release. Layers are restored sequentially — later layers'
  412. file modifications can overwrite earlier ones, mirroring Docker's
  413. additive-overlay semantics.
  414. Args:
  415. containerfile_paths: Ordered list of Containerfile paths.
  416. cache_repo: Single cache repo for all layers (each gets its own
  417. release within it, tagged `layer-<name>-<hash>`).
  418. gh_token: GitHub token; falls back to $GH_TOKEN.
  419. salt: Optional salt applied to every layer's hash (typically a
  420. git HEAD SHA so the whole composition invalidates together
  421. when the source repo advances).
  422. names: Optional per-layer name overrides. None entries fall back
  423. to `default_layer_name()`. List length must match
  424. `containerfile_paths` if provided.
  425. Returns:
  426. List of BuildResult, one per layer, in the same order as input.
  427. Stops on first failure (later layers in the list aren't attempted).
  428. """
  429. if names is not None and len(names) != len(containerfile_paths):
  430. raise ValueError(
  431. f"names length ({len(names)}) must match containerfile_paths "
  432. f"length ({len(containerfile_paths)})"
  433. )
  434. results: list[BuildResult] = []
  435. for i, cf_path in enumerate(containerfile_paths):
  436. explicit_name = names[i] if names else None
  437. name = explicit_name or default_layer_name(cf_path)
  438. print(f"\n=== Composing layer [{i + 1}/{len(containerfile_paths)}]: {name} ({cf_path}) ===")
  439. layer = ContainerLayer(
  440. containerfile_path=cf_path,
  441. cache_repo=cache_repo,
  442. gh_token=gh_token,
  443. salt=salt,
  444. layer_name=name,
  445. )
  446. result = layer.restore_or_build()
  447. results.append(result)
  448. if not result.success:
  449. print(f"\n✗ Compose halted at layer '{name}' (errors above)")
  450. break
  451. return results

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.