Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
feat(skill): optional GitHub publishing for generated skills (#102)
Anton Novoselov430729883e5b
diff --git a/README.md b/README.mdindex d0c232e..544126d 100644--- a/README.md+++ b/README.md@@ -113,7 +113,7 @@ Two halves: a deterministic Python **extractor** (document → clean text + meta## 🚀 Usage-`/book-to-skill <path|folder|glob> [skill-name]` — plus analyze-only, generate-from-analysis, and update/fold-in modes.+`/book-to-skill <path|folder|glob> [skill-name]` — plus analyze-only, generate-from-analysis, and update/fold-in modes. After a conversion, the converter can publish the skill to GitHub (private by default) so any host installs it with `npx skills add`.▶️ **All modes and examples → [docs/usage.md](docs/usage.md)**diff --git a/SKILL.md b/SKILL.mdindex 7ffd49c..aa02644 100644--- a/SKILL.md+++ b/SKILL.md@@ -580,12 +580,65 @@ Reload (if your agent doesn't auto-detect new skills):Claude Code: restart the sessionAmp: restart the session-Share this skill (Copilot ecosystem, optional):- gh skill publish $SKILLS_HOME/<skill_name>+Share this skill (optional):+ GitHub repo, installable on any host (Step 11): say "publish"+ Copilot ecosystem: gh skill publish $SKILLS_HOME/<skill_name>```---+## Step 11 — Publish the generated skill to GitHub (optional)++After the Step 10 report, offer once — and only if the Step 9.5 scan passed:++> "Want me to publish this skill to GitHub so any Agent Skills host can install it with `npx skills add`? (yes / skip)"++If the user declines, stop here. Requirements: the `gh` CLI, authenticated (check `gh auth status`). If `gh` is missing or unauthenticated, offer to set it up (`brew install gh` or https://cli.github.com, then `gh auth login`) — or use the no-`gh` path: the user creates an empty repo of the chosen visibility in the GitHub web UI, then you run the `git init`/`add`/`commit` commands below followed by `git remote add origin <repo-url> && git push -u origin main`. The visibility rule below applies to the web-created repo exactly the same.++**Visibility is a separate closed question — never inferred, never read out of an earlier answer.** Once the user accepts, ask it on its own and require a one-word reply:++> "Private or public repository? Reply with one word: `private` or `public`."++**The reply must *be* `public`, not merely contain it — a hard rule, not a suggestion.** Run `gh repo create` with `--private` in every case except one: the answer to the visibility question is the bare word `public`. Substring matching is forbidden, because a sentence about **the source's licence is not a visibility answer** — "it's public domain", "the book is public domain", "it's publicly available" all describe the material, not the repository, and all resolve to `--private`. A paraphrase, a sentence, an ambiguous answer, silence, or your own inference is NOT consent: re-ask once, and if the reply is still not the bare word, use `--private` and say so in the report. A private repo can be flipped public later; a public push of book-derived content cannot be un-published.++**Copyright gate — always apply before creating the repo:** chapter files are synthesized summaries, not raw text, but they still derive from the source material. Per the README's Copyright & fair use policy, skills generated from **third-party copyrighted books must stay private**; offer public only when the source is the user's own writing, openly licensed content, or material the user explicitly confirms they are authorized to redistribute publicly — and state which case applies. Having access to internal company material is not permission to disclose it: skills from internal docs stay **private** unless the user states they hold publication rights.++If accepted:++1. Add a repo `README.md` inside `$SKILLS_HOME/<skill_name>/` (never overwrite an existing file) — the skill title, a one-paragraph description ("Agent skill generated from *<Title>* by <Author> with [book-to-skill](https://github.com/virgiliojr94/book-to-skill)"), the install command from step 3 below, the file inventory, and a note that the content is synthesized summaries, not the book text.+2. Initialize the skill folder as a git repository and create the remote (default repo name `<skill_name>`; let the user override — some prefer a `<skill_name>-skill` suffix). **Nested-repo guard:** first check whether the skill folder already sits inside a git repository (`git -C "$SKILLS_HOME/<skill_name>" rev-parse --show-toplevel` — always the case for project-local roots like `.claude/skills/`). If it does, do NOT `git init` in place: the outer repository would record the folder as an embedded repo (gitlink, mode 160000) without `.gitmodules`, and fresh clones of the outer project would silently omit the skill. Instead, copy the skill folder to a scratch directory, run the commands below from the copy, and tell the user the published repo — not the project-local folder — is the remote's working copy.++```bash+cd "$SKILLS_HOME/<skill_name>"+git init -b main+git add -A+git commit -m "Add <skill_name> skill"+gh repo create <repo_name> --private --source . --push+# --private is the default; substitute --public ONLY under the visibility rule above+# (the visibility answer WAS the bare word "public" AND the copyright gate allows it)+```++3. Report the repo URL and the cross-host install command:++```+✅ Published: https://github.com/<owner>/<repo_name> (<private|public>)++Install on any Agent Skills host:+ npx skills add https://github.com/<owner>/<repo_name> --skill <skill_name>+```++ When the nested-repo guard fired and the repo was published from a scratch copy, add one line — that local folder never gains a remote, so the Update/Fold-in push offer will never appear for it:++```+⚠️ Published from a copy: <skill folder> sits inside another git repository, so it has+ no remote of its own. To publish a later update, re-run Step 11, or clone+ https://github.com/<owner>/<repo_name> and fold new material into the clone.+```++The root-level `SKILL.md` layout is exactly what the `skills` CLI detects, so the repo is installable as-is — no restructuring needed. Outside the nested-repo case the local folder stays the live install for this machine and is the remote's working copy, so later Update/Fold-in runs can commit and push their changes to the same remote.++---+## Update / Fold-in WorkflowWhen performing an Update/Fold-in operation on an existing skill at `$SKILLS_HOME/<skill_name>/`:@@ -631,7 +684,7 @@ Update the master skill file `$SKILLS_HOME/<skill_name>/SKILL.md`:- **Topic Index**: Merge the new topics alphabetically. If an existing topic is also covered in the new chapters, append the new chapter links to its line (e.g. `- **Topic** → ch05, ch13`).### 6. Scan, Cleanup, and Report-Once the files are successfully written and merged, run **Step 9.5**, then proceed to **Step 10** to perform cleanup and print a custom update report summarizing the newly added chapters, merged glossary terms, and updated indices.+Once the files are successfully written and merged, run **Step 9.5**, then proceed to **Step 10** to perform cleanup and print a custom update report summarizing the newly added chapters, merged glossary terms, and updated indices. If the skill folder is a git repository with a remote (published via **Step 11**), offer to commit the update and push it.---diff --git a/docs/usage.md b/docs/usage.mdindex 1d6d236..11ce07e 100644--- a/docs/usage.md+++ b/docs/usage.md@@ -48,6 +48,15 @@ Both accounts, and how to add yours, are in [book-to-skill-use-cases](https://gi---+## 📤 Publish your generated skill (optional)++After a conversion, the converter offers to push the skill to GitHub as its own repository. Visibility is asked as its own question and the `gh repo create` command defaults to **`--private`**; a public repo is created only when your answer is the bare word `public`. A sentence about the source's licence is not a visibility answer - "it's public domain" describes the book, not the repository, and still gets you a private repo. Chapter files are synthesized from the source material, and skills generated from third-party copyrighted books must stay private (see [Copyright & fair use](../README.md#%EF%B8%8F-copyright--fair-use)). A published skill installs on any Agent Skills host in one command:++```bash+npx skills add https://github.com/<you>/<your-book-slug> --skill <your-book-slug>+```++Requires the [`gh` CLI](https://cli.github.com), authenticated. The generated repo ships with a README, and the skill folder becomes the git working copy, so later fold-in updates can push to the same remote.---diff --git a/tests/test_publish_visibility_gate.py b/tests/test_publish_visibility_gate.pynew file mode 100644index 0000000..5df0846--- /dev/null+++ b/tests/test_publish_visibility_gate.py@@ -0,0 +1,134 @@+"""Regression tests for the Step 11 publish visibility gate in SKILL.md.++Step 11 creates a GitHub repository from book-derived content. Its safety+property is that `gh repo create` runs with `--private` unless the user gives a+bare-word `public` answer to a question asked solely about repository+visibility. A regression here is invisible in review and only surfaces as a+public repository that should not exist, so the rule is asserted two ways:++1. the prose in SKILL.md still states the rule the model is meant to follow;+2. a reference implementation of that rule rejects the inputs a naive+ substring check would wrongly accept.++Test 2 does not execute anything from SKILL.md - nothing in this project does.+It pins the intended semantics next to the prose, so that a future edit+loosening the wording fails test 1 while test 2 still shows what the wording+was supposed to mean.+"""++from pathlib import Path++import pytest+++REPO_ROOT = Path(__file__).resolve().parent.parent+SKILL_MD = REPO_ROOT / "SKILL.md"+++def _step_11() -> str:+ """The Step 11 section of SKILL.md, up to the next top-level heading."""+ if not SKILL_MD.is_file():+ pytest.skip("SKILL.md not present (e.g. installed sdist)")+ text = SKILL_MD.read_text(encoding="utf-8")+ marker = "## Step 11"+ start = text.find(marker)+ assert start != -1, "SKILL.md no longer has a Step 11 section"+ end = text.find("\n## ", start + len(marker))+ return text[start:] if end == -1 else text[start:end]+++def _is_public_answer(reply: str) -> bool:+ """The visibility gate as specified: the reply must *be* `public`.++ Normalization is deliberately minimal - surrounding whitespace, casing, and+ trailing punctuation only. Anything that leaves more than the single word+ is a sentence, and a sentence is not a visibility answer.+ """+ return reply.strip().strip(".!?,;:").strip().casefold() == "public"+++def test_repo_create_command_defaults_to_private():+ """The literal command in SKILL.md must carry --private.++ The maintainer's requirement is that the *command default* be private, so a+ model misreading the surrounding prose still cannot create a public repo.+ """+ section = _step_11()+ create_lines = [ln for ln in section.splitlines() if "gh repo create" in ln]+ assert create_lines, "Step 11 no longer contains a `gh repo create` command"+ command = next((ln for ln in create_lines if ln.strip().startswith("gh repo create")), None)+ assert command is not None, "no runnable `gh repo create` line in Step 11"+ assert "--private" in command, f"`gh repo create` lost its --private default: {command!r}"+ assert "--public" not in command, f"`gh repo create` hardcodes --public: {command!r}"+++def test_visibility_is_asked_as_its_own_closed_question():+ """Visibility must not be inferred from the publish offer or earlier turns."""+ section = _step_11().casefold()+ assert "separate closed question" in section, (+ "Step 11 no longer states that visibility is asked as its own closed question"+ )+ assert "reply with one word" in section, (+ "Step 11 no longer requires a one-word visibility answer"+ )+++def test_gate_forbids_substring_matching_and_names_the_licence_trap():+ """`public` must be the whole answer, and a licence statement must not count.++ "public domain" is ordinary vocabulary in this project - Moby-Dick is a+ benchmark book and the copyright gate actively asks users about the+ source's licence - so a user answering that question could otherwise+ satisfy the visibility gate without ever choosing to publish publicly.+ """+ section = _step_11().casefold()+ assert "substring matching is forbidden" in section, (+ "Step 11 no longer forbids substring matching on the visibility answer"+ )+ assert "public domain" in section, (+ "Step 11 no longer names the 'public domain' licence sentence as a non-answer"+ )+ assert "not a visibility answer" in section, (+ "Step 11 no longer states that a licence sentence is not a visibility answer"+ )+++ "reply",+ [+ "public",+ "Public",+ " public ",+ "public.",+ "PUBLIC!",+ ],+)+def test_bare_word_public_opens_the_gate(reply):+ assert _is_public_answer(reply) is True+++ "reply",+ [+ # The Step 10 trigger word that enters Step 11 at all.+ "publish",+ "publish it",+ # Statements about the source's licence, not the repository.+ "it is public domain",+ "the book is in the public domain",+ "it's publicly available",+ "public domain",+ # Paraphrase, ambiguity, silence, and the safe answer.+ "make it public",+ "public is fine i guess",+ "",+ " ",+ "yes",+ "private",+ ],+)+def test_everything_else_stays_private(reply):+ assert _is_public_answer(reply) is False, (+ f"{reply!r} must not satisfy the visibility gate - it would create a public "+ "repository from book-derived content"+ )