Metadata-Version: 2.4
Name: pyskills
Version: 0.0.46
Summary: Python-native skills system
Author-email: Jeremy Howard <github@jhoward.fastmail.fm>
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/AnswerDotAI/pyskills
Project-URL: Documentation, https://AnswerDotAI.github.io/pyskills/
Keywords: nbdev
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastaudit
Requires-Dist: fastcore>=2.3.8
Provides-Extra: dev
Requires-Dist: httpx; extra == "dev"
Provides-Extra: ast
Requires-Dist: remold; extra == "ast"
Dynamic: license-file

# pyskills

Python-native pyskills system

pyskills is a plugin system that lets Python packages register "skills" (units of LLM-usable functionality) via standard [entry points](https://packaging.python.org/en/latest/specifications/entry-points/). An LLM harness (e.g. solveit) discovers available pyskills without importing them, reads lightweight descriptions via AST inspection, and selectively loads chosen pyskills into context using standard imports.

It includes [`list_pyskills()`](https://AnswerDotAI.github.io/pyskills/core.html#list_pyskills) for discovery, [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc) for rendering module/class/function documentation in LLM-friendly format, [`xdir()`](https://AnswerDotAI.github.io/pyskills/core.html#xdir) for listing a module or class's public symbols, and an [`allow()`](https://AnswerDotAI.github.io/pyskills/core.html#allow) system for registering safe callable access in sandboxed environments. Skills can be installed as regular packages with entry points, or dropped into an XDG data directory for quick local use.

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

pyskills follows the progressive disclosure approach of the [Agent Skills](https://agentskills.io/specification) specification. Both keep a short description for discovery apart from the full instructions loaded on demand. Agent Skills stores a skill as files: a `SKILL.md` with YAML frontmatter, plus `scripts/` and `references/` directories. A pyskill is a regular Python module instead. A standard entry point registers it, its docstrings document it, and `import` loads it. Because it's ordinary Python, a host can use the same module to:

- run its functions directly
- read the structured documentation that [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc) generates
- run it in a sandbox, where the callables it registers with [`allow()`](https://AnswerDotAI.github.io/pyskills/core.html#allow) may perform operations the sandbox otherwise denies
- generate `llms.txt` and companion `llms-*.txt` reference files for web-based agents from the same `pkg/skill.py` source

## Usage

### Installation

Install the latest from [pypi](https://pypi.org/project/pyskills/)

```sh
$ pip install pyskills
```

### How to use

```python
from pyskills import *
```

Discover what pyskills are available. This works without importing any pyskill modules:

```python
list_pyskills()
```

```output
aai_coding.harness_docs: Official docs for the tool you are running in (Claude Code or codex): read before answering questions about its behaviour, config, or features.
aai_pyskills.coding_patterns: Jeremy's coding style and conventions: read before writing, reviewing, or assessing any code.
aai_pyskills.nbreview: Review and improve fastship notebooks using chkstyle findings. Read before a notebook style review. Start with `chkstyle --fix path/to/notebook.ipynb` on notebooks without substantial intentionally formatted code, such as aligned matrices or tables. Inspect the notebook and existing changes before applying it.
aai_pyskills.understand: Read and follow when asked to use the understanding or theory skill, asked for "the Theory of X", framing an open-ended design problem, or stuck at a design impasse. Build a minimal Theory (Naur) held in a mind, separating real constraints from inherited assumptions, and testing against breaking cases, before proposing, changing, or reviewing.
aai_pyskills.vision: Describe and transcribe images and PDFs using vision models, keeping visual content out of the caller's context.
aai_pyskills.write_docs: How to write reference prose. Read this before writing docstrings, READMEs, API docs, PR descriptions, or commit messages. Use write-prose for messages to users or colleagues.
aai_pyskills.write_llms: How to write docs an LLM reads: read before writing or revising `llms.txt`, pyskill docstrings, skill.md files, `SETUP.md`, prompts etc.
aai_pyskills.write_prose: How to write narrative prose that reads as though a person wrote it: read before writing messages to users or colleagues, blog posts, essays, announcements, tutorials and explanatory guides, or anything else with the author's voice. write-docs covers reference prose.
aai_pyskills.write_summary: How to write summaries that stand alone: read before summarizing a conversation, meeting, PR, paper, or repo change for a human reader.
aidialog.dlgskill: Read, search, and edit notebook and dialog content through aidialog's `Dialog` and `Message` APIs (cell sources, stored outputs, prompt/reply pairs, structural ops).
answerui.skill: Build and customise FastHTML and npm/Svelte interfaces with AnswerUI's shared CSS, native HTML, utilities and browser behavior.
clikernel.skill: Use `clikernel` MCP as the default persistent Python workspace for file/notebook reads and edits, exploration, library checks, data reshaping and debugging. Read before writing, running or debugging Python with `clikernel` connected.
cordslite.skill: Minimal async Discord library: REST API (`DiscordClient`), WebSocket gateway (`GatewayClient`), command-routing `Bot`, and voice recording/playback.
dialoghelper.solveitskill: Read, search, edit, and manage Solveit dialogs using dialoghelper.core, including dialog/message addressing, line-numbered inspection, targeted message edits, add/update/delete/copy/paste workflows, and safe editing patterns.
exhash.skill: Read, navigate and precisely edit files and notebook cells using hash-verified addresses; transfer text between files/cells, read large files, and navigate Markdown, code, notebook and linked-document hierarchies.
fastanki.skill: Anki flashcard tools for spaced repetition. Direct sqlite and AnkiWeb sync, with no Anki app needed.
fastasyncpg.skill: Use fastasyncpg's API idiomatically. Always read before using the lib.
fastcdp.skill: Work with Chrome through the DevTools Protocol: inspect pages, interact with controls, and diagnose browser applications.
fastcflare.skill: Cloudflare REST (`CloudflareApi`) and GraphQL Analytics (`CfGql`) access from Python: zones, DNS records, R2 buckets and S3 tokens, caching, Workers, and analytics. Use this instead of hand-built httpx calls against api.cloudflare.com.
fastcore.editskill: Text, file, cell, and notebook editing from `fastcore.tools` and `fastcore.nbio`, plus conventions shared across the fastai editing toolkit. Read before using editing tools in any package that shares them.
fastcore.skill: Write idiomatic Python with `fastcore`: `L`, `@patch`, `store_attr`, `@delegates`, `call_parse` CLIs, async/sync bridging, and concise IO/testing helpers.
fastdecisions.skill: Offload bulk filtering, triage, classification, rubric scoring, yes/no checks, and image bounding-box localization over text, JSON, conversations, or media to fast zero-output-token decision models (Jev, Gemini, OpenAI) instead of reading large inputs into your own context.
fastgws.skill: Use fastgws to read and work with Google Workspace and Google APIs from Python, including Workspace user administration. Use it when the task needs access to Gmail, Calendar, Drive, Docs, Sheets, Places, or another Google API published through Google's discovery documents.
fasthtml.skill: Write and review idiomatic FastHTML apps (HTMX 4, `<hx-partial>`-first server-rendered hypermedia on Starlette, Uvicorn, and fastcore `FT` FastTags).
fastmux.skill: Work with tmux sessions, windows, and panes from Python, plus named background sessions keyed by sid. Use this when code needs to read what is on a terminal, send input to a TUI or other rich terminal app, build pane layouts, search text across terminals, or keep a terminal open that you and the user can both see. For plain line-oriented programs (REPLs, shells, ssh) use `ptymini.skill`'s bgterm sessions instead. They share this module's wait parameters (`wait_ms`, `until=`, `settle_ms`). tmux is for when the terminal itself matters.
fastship.skill: Build, test, document, and ship Python (notebooks or `.py`), Rust/maturin, Rust crate, Zig, npm, and web/blog projects fast.
gclientid.skill: Create personal Google Cloud projects and OAuth clients, navigate Google Cloud Console, and load or authorize refreshable Google API tokens.
ghapi.skill: GitHub REST (`GhApi`) and GraphQL (`GhGql`), plus local git via `fastgit` (`Git`). Read before working with GitHub issues, PRs, CI, releases, branches, or gists, or any repo-local git operations.
jph: Jeremy's tools, which for now is just his notes system. Use if Jeremy says 'create a note', or 'check my notes' or similar.
llmsurgery.skill: Read and work with Claude Code, Codex, and Antigravity session transcripts.
nbdev.skill: Write, read and review nbdev notebooks as source, documentation, examples and tests. You MUST read this before any work on a project with notebooks.
octavo.migrate: Convert Quarto sources and settings for Octavo
octavo.skill: Build static sites, Python API docs, and `llms.txt` from Markdown, `.qmd`, notebooks, and `.py` modules; run literate `.py` tests; configure GitHub Pages.
ptymini.skill: Drive line-oriented interactive programs in the background: REPLs, shells, ssh, debuggers. Start a pty session once, send input later, wait a bounded time for the reply, and read what arrived since your last look. Use this for CLI work. Use `fastmux` for TUIs, rich terminal apps, and terminals shared with the user.
pyskills.skill: Python packages register tool modules as pyskills. `list_pyskills()` lists installed skills and one-line descriptions without imports. Import normally, then read `doc(module)`.
remold: Structural search and rewrite for Python source: declarative ast-grep pattern rules, LibCST matcher transforms for everything patterns can't express, and tree-based symbol queries. Use this to edit code by structure (rename calls, move methods, rewrite APIs) where regexes break and `ast` loses comments.
rgapi.skill: Find files, search text, and search notebook cell sources from Python with ripgrep semantics and structured results. Use for fd-style discovery, regex searches, and notebook searches returning stable cell IDs rather than escaped JSON.
tracefunc.skill: See what a Python function did, line by line: how many times each line ran and what the variables held. Use when working out why code takes a branch, loops, recurses, or computes a wrong value, without changing that code or stepping through a debugger.
```

### The [`doc`](https://AnswerDotAI.github.io/pyskills/core.html#doc) and [`xdir`](https://AnswerDotAI.github.io/pyskills/core.html#xdir) functions

Once you've found a pyskill you want to use, import its module using standard python syntax:

```python
import pyskills.skill
```

Use [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc) to read its full documentation. [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc) works on modules, classes, and functions, rendering LLM-friendly output in each case.

For a **module**, [`doc`](https://AnswerDotAI.github.io/pyskills/core.html#doc) shows its docstring, public classes and functions with signatures and first docstring line, submodules, and any `__docs__` cross-references. Calling `doc(pkg)` on a package renders its docstring, module summaries (even without `skill.py`), and a `LLM docs: doc('pkg.skill')` pointer when `pkg/skill.py` exists without importing it, while `doc(pkg.skill)` renders the compact LLM guide and its module/doc cross-references:

```python
print(doc(pyskills.skill)[-500:])
```

```output
print()`    /keeps custom display; reads better reformatted: fix repr or tell user
- summarize docs/results unless user needs all
"""

## docs:
### Docs
- `doc(pyskills.core)`: Skill discovery, LLM-friendly doc rendering, the allow registry, and pyskill registration
### API
- `doc(pyskills.cli)`: Command-line access to pyskills documentation.

## submodules:
  pyskills.createskill: ...  # How to create pyskill modules (`pkg.skill`, `pkg.guidance`, named skills) and generate `llms.txt` from them.
```

For a **function**, [`doc`](https://AnswerDotAI.github.io/pyskills/core.html#doc) renders the full signature with parameter comments (docments):

```python
from pyskills._demo import skill_test_func, SkillTestClass
```

```python
doc(skill_test_func)
```

```output
def skill_test_func(
    x:int=0, # the input
)->str: # the output"""A test function"""
```

For a class, [`doc`](https://AnswerDotAI.github.io/pyskills/core.html#doc) shows its hierarchy, docstring, full constructor documentation, and a method overview. Read a selected bound method separately for its full docments and usage notes. For dynamic APIs, use `doc(instance)` and `xdir(instance)` to discover the generated or session-bound surface:

```python
doc(SkillTestClass)
```

```output
class SkillTestClass(str):
    """Some class.
    More info about it."""
    def __init__():
    def f(self, x: int = 0) -> str: ...  # A test method…
    @property
    def g(self) -> str: ...  # A test prop

Inherited members: `doc(str)`.

Overview only. Read `doc(Class.member)` for entries marked …; use an instance for dynamically bound members.
```

### Command line

`pyskills-doc` renders the same LLM-friendly documentation in a fresh process, importing the dotted symbol before displaying it:

```bash
pyskills-doc fastcore.script
pyskills-doc fastcore.script.call_parse
pyskills-doc --all aidialog.dlgskill
```

Run `pyskills-doc --help` for the complete command syntax.

### The [`allow`](https://AnswerDotAI.github.io/pyskills/core.html#allow) system

When pyskills run in a sandboxed environment like [safepyrun](https://github.com/AnswerDotAI/safepyrun), they need to declare which callables are trusted to perform otherwise-denied operations (filesystem writes, subprocesses, network access). safepyrun uses [fastaudit](https://github.com/AnswerDotAI/fastaudit) to deny those effects unless they happen inside a callable registered in the `__pytools__` registry. The [`allow()`](https://AnswerDotAI.github.io/pyskills/core.html#allow) function is how pyskills register their trusted callables.

You can allow individual functions, methods, all public methods of a type, or one specific callable instance:

```python
# Allow specific methods on a type
allow({str: ['zfill']})

# Allow all public methods on a type
allow({list: ...})

# Allow a function
allow(list_pyskills)

# Allow one specific callable instance (e.g. a dynamically-generated client op)
allow(client.images.create_image)
```

An object can also define `__allow__`, returning a list of items to register in its place; [`allow`](https://AnswerDotAI.github.io/pyskills/core.html#allow) recurses into the result, so a container (such as a fastspec client or op group) can register all its callables at once.

Skill modules typically call [`allow()`](https://AnswerDotAI.github.io/pyskills/core.html#allow) at module level, so permissions are registered automatically when the pyskill is imported. When `safepyrun`'s `RunPython` executes LLM-generated code, pure computation just runs; an operation with side effects is only permitted when it happens inside a registered callable.

The `pyskills.skill` module used in the examples above is itself registered as a pyskill entry point. It ships with pyskills both as a working sample and as a self-documenting pyskill that explains the system itself. Its docstring's "Creating pyskills" section cross-references `pyskills.createskill`, a companion module (not registered as an entry point, so not shown in [`list_pyskills()`](https://AnswerDotAI.github.io/pyskills/core.html#list_pyskills)) that documents how to build your own pyskills:

```python
from pyskills import createskill
```

```python
print(doc(createskill)[:300])
```

```output
# module pyskills.createskill:

"""How to create pyskill modules (`pkg.skill`, `pkg.guidance`, named skills) and generate `llms.txt` from them.

notation: /why

## Human vs LLM docs

Audience|Web|Python|Source
-|-|-|-
Human|`README.md`, `index.html`|`doc(pkg)`|`ship/index.ipynb` (fastship) or `pkg/_
```

## Creating pyskills

pyskills keeps human and LLM documentation separate:

| Audience | Web | Python | Source |
|--- |--- |--- |--- |
| Human | `README.md`, `index.html` | `doc(pkg)` | `ship/index.ipynb` (fastship) or `pkg/__init__.py` |
| LLM | `llms.txt` | `doc(pkg.skill)` | plain `pkg/skill.py` (never notebook-generated) |

Three module roles cover most packages:

- **`pkg.skill`**: the package's main LLM guide and cross-reference index, serving as the single source for both `doc(pkg.skill)` and `llms.txt`.
- **`pkg.guidance`**: an optional companion docstring module for domain principles, judgement, or agent conduct (for example flashcard-design rules in `fastanki.guidance` or read-only Discord conduct in `cordslite.guidance`). Give it no entry point so it does not clutter [`list_pyskills()`](https://AnswerDotAI.github.io/pyskills/core.html#list_pyskills), and direct agents to it from `pkg.skill`; `doc(pkg.skill)` and `llms.txt` automatically promote `pkg.guidance` into `Docs` (`llms-guidance.txt`).
- **Named skills** (such as `fastcore.editskill`, `dialoghelper.solveitskill`, or `pyskills.createskill`): subsystem tools, host-harness prompts, or secondary guides that stay separate from `pkg.skill` and `llms.txt`.

A `pkg/skill.py` module uses:

- **A docstring**: the first paragraph is both the [`list_pyskills()`](https://AnswerDotAI.github.io/pyskills/core.html#list_pyskills) catalog description (read via AST before import) and the `llms.txt` summary blockquote; the remaining body is the compact guide using `###`\+ headings so `# pkg` and `## Section` stay reserved for `llms.txt` and [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc).
- **Published catalog, optional `__docs__`, and `__base_url__`**: when a package publishes `pkg._modidx.docs`, both `doc(pkg)` and `doc(pkg.skill)` consume that catalog as final without appending unlisted modules. Standalone skills without `_modidx.docs` can declare `__docs__` (mixing module names like `'mypkg.core'` and `(title, href, desc)` tuples), with unlisted `pkg.guidance` and public modules auto-discovered under `Docs` and `API`. Prefix internal modules with `_` so [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc), [`xdir()`](https://AnswerDotAI.github.io/pyskills/core.html#xdir), and `llms.txt` skip them uniformly. `__base_url__` overrides the base URL (otherwise read from `[project.urls].Documentation` in [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc)).
- **Optional `__all__` and [`allow()`](https://AnswerDotAI.github.io/pyskills/core.html#allow)**: `__all__` curates the public API for `import *`; [`allow()`](https://AnswerDotAI.github.io/pyskills/core.html#allow) declares trusted callables for sandboxed hosts and is never emitted to `llms.txt`.

Here's a minimal example:

```python
r'''Short description for `list_pyskills()` and `llms.txt`.

Compact guide read by the LLM via `doc(mypkg.skill)` and `llms.txt`.
When creating X for a user, read `doc(mypkg.guidance)`.'''

from pyskills.core import allow

__docs__ = {'Docs': ['mypkg.core', ('Quickstart', 'start.md', 'First steps')]}
__all__ = ['my_func', 'MyClass']

def my_func(x: int) -> str:
    "Does something useful"
    ...

class MyClass:
    "A useful class"
    def method(self) -> str:
        "Does something"
        ...

allow(my_func, {MyClass: ...})
```

To register your module as a discoverable pyskill, add an entry point in your `pyproject.toml`:

```toml
[project.entry-points.pyskills]
my_skill = "mypkg.skill"
```

The key is an arbitrary name; the value is the module path. After installing the package, [`list_pyskills()`](https://AnswerDotAI.github.io/pyskills/core.html#list_pyskills) will include your pyskill automatically.

For full details on creating pyskills, including allow policies for write-guarded operations, see `doc(createskill)` after importing it as shown above.

### Generating `llms.txt`

`fastship.llms` (`project_llms`, `pkg_llms`, and the `ship-llms` CLI) builds `llms.txt` from `pkg/skill.py` purely via AST without importing the package.

The generated file starts with `# <pkg>`, `> <first paragraph>`, and a normalized `Base URL: https://.../` line so readers (`llms_txt` and `exhash.open_doc`) resolve relative links whether opened from the docs site, raw GitHub, or local disk. Modules in the site catalog link to their relative `.md` pages; pure-docstring companions without a web page (such as `pkg.guidance` or `pyskills.createskill`) emit `llms-*.txt` files (`llms-guidance.txt`, `llms-createskill.txt`) served verbatim by fastship.

`ship-docs` writes `llms.txt` and companion `llms-*.txt` files directly into `_docs/` (copying an authored `ship/llms.txt` verbatim when present), `ship-export` persists the same catalog into `pkg/_modidx.py` for installed [`doc()`](https://AnswerDotAI.github.io/pyskills/core.html#doc), and `ship-llms` prints `llms.txt` to stdout or writes it with `--out`.

### Folder-local skills

Hosts call `enable_local_skills(opening_folder)` once to expose public modules and packages from ancestor `_pyskills/` directories. Local skills need a module docstring but no install or entry-point declaration. The standard entry-point API discovers them, and ordinary Python imports load them. The nearest local folder wins; conflicts with existing importable names raise an error. The scope stays fixed across cwd changes. Solveit's dialoghelper bootstrap activates this automatically.

### User-wide skills without packaging

The entry point approach above requires installing a package. But sometimes you want to create pyskills quickly without a full package: personal utility pyskills, or pyskills shared across multiple projects that each use isolated environments (like [uv](https://docs.astral.sh/uv/) venvs).

pyskills provides an [XDG](https://specifications.freedesktop.org/basedir-spec/latest/)-based pyskills directory for this. When you first `import pyskills`, it creates a directory at your platform's XDG data home (typically `~/.local/share/pyskills/`) and writes a `.pth` file into `site-packages`. This `.pth` file tells Python to add the pyskills directory to `sys.path` on startup, so any modules placed there are importable as standard Python modules without any special import machinery. This works across all Python environments on your system, even separate uv projects with isolated venvs.

You can check where this directory is (although you can use the functions below without needing to know):

```python
pyskills_dir()
```

```output
Path('/Users/jhoward/.local/share/pyskills')
```

You can drop pyskill modules directly into this directory, or use [`register_pyskill`](https://AnswerDotAI.github.io/pyskills/core.html#register_pyskill) to create one programmatically:

```python
register_pyskill('my_local.skill', docstr='A quick local pyskill.', code='''
from pyskills.core import allow

__all__ = ['hello']

def hello(name: str) -> str:
    "Greet someone"
    return f"Hello, {name}!"

allow(hello)
''')
```

This writes the module file into the XDG pyskills directory and creates a minimal entry point, so the pyskill immediately appears in [`list_pyskills()`](https://AnswerDotAI.github.io/pyskills/core.html#list_pyskills).

You can also manage pyskills with [`enable_pyskill`](https://AnswerDotAI.github.io/pyskills/core.html#enable_pyskill) and [`disable_pyskill`](https://AnswerDotAI.github.io/pyskills/core.html#disable_pyskill) to toggle their visibility without deleting files, or use [`delete_pyskill`](https://AnswerDotAI.github.io/pyskills/core.html#delete_pyskill) to remove one entirely.
