# Installing programs

A release bundles no programs: everything beyond the built-in tools and applications is installed this way. When a user asks for a program the agent lacks, this page is the procedure to follow.

```
openprogram programs install https://github.com/<owner>/<repo>
openprogram programs install <owner>/<repo>
openprogram programs install ~/work/my-program
openprogram programs install file:///path/to/checkout

openprogram programs list
openprogram programs install <source> --upgrade
openprogram programs uninstall <name>
```

The running worker picks up a clone; a fresh process loads it at start. Installed programs appear under **Abilities → Programs → Applications** as a folder named by its directory, holding its Agent entries.

## What a source can be

| Source | What happens |
| --- | --- |
| Git URL (`https://`, `ssh://`, `git@`, `file://`) | Shallow-cloned into the Programs directory, then inspected |
| GitHub `owner/repo` | Expanded to `https://github.com/owner/repo` and cloned |
| Local application directory (`application.json`) | Recorded in the catalog and loaded in place; nothing is copied |
| Local package repository (`__init__.py` and `.git`) | Cloned like a git URL. Commit first; a directory that is not a Git repository is refused. |
| A package already in the Programs directory | Nothing to install; `openprogram programs check <directory>` makes it callable |

Programs directory: `~/.openprogram/programs/<name>/`, or `~/.openprogram-<profile>/programs/<name>/` under a named profile. Checkouts in the older `openprogram/programs/packages/` or `openprogram/programs/applications/` move there on the worker's first start on a newer version, keeping names and sources.

## What the clone becomes

A repository can be more than one of these. One that is none is reported, loads nothing and never breaks other programs.

| Shape | Detected by | Result |
| --- | --- | --- |
| Package | `__init__.py` at the clone's root | Named after the repository as a valid import name (`My-Tools` → `my_tools`). Loads once `openprogram programs check` has passed. See [Workflow automation](https://fzkuji.github.io/OpenProgram/docs/capabilities/workflows/README.html#self-programming-workflows) for `PROGRAM_ENTRIES` and the check. |
| Application | `application.json` | Recorded in the catalog; see [Applications](https://fzkuji.github.io/OpenProgram/docs/capabilities/applications.html). `--trust` authorizes a reviewed Python backend; `--replace` accepts a changed digest. |
| Harness | `<package>/agentics/__init__.py` | Installs its own declared dependencies from `pyproject.toml`/`setup.py` (preferred) or `requirements.txt` and records an owner-approved source. On the next scan its `PROGRAM_ENTRIES` appear in chat, on the Programs page and in `openprogram programs run`. |

## Upgrade, uninstall, verify

| Command | Effect |
| --- | --- |
| `openprogram programs install <source> --upgrade` | `git pull --ff-only`, re-resolves dependencies |
| `openprogram programs uninstall <name>` | A directory name moves the clone to `~/.openprogram/programs/.removed/`, restorable by hand and never deleted. An application id unregisters it and keeps data, so a compatible reinstall restores it. |
| `openprogram programs list [--json]` | Every Program with its state, harnesses included |
| `OPENPROGRAM_DEBUG_REGISTRY=1 openprogram programs list` | Shows why a broken harness did not load. PowerShell: `$env:OPENPROGRAM_DEBUG_REGISTRY=1; openprogram programs list` |
| `openprogram programs run <fn> -a key=value` | Runs a function; it is also callable in chat |

A dev symlink of the same name: `install` verifies the harness contract and records the link without touching its target. A same-named directory that is not a git clone is refused. `uninstall` on a symlink moves only the link.

**Without GitHub access, or developing a program**

Mirror:

```
git clone <repo-url> /path/to/Program-Name
openprogram programs install file:///path/to/Program-Name
```

The command clones into the Programs directory and records it; only recorded directories meeting the contract load.

Your own checkout: install it, add it as a remote, then `git pull work main`. Pulled commits take effect on the next restart.

```
openprogram programs install file:///path/to/your/Program-Checkout
cd ~/.openprogram/programs/Program-Checkout && git remote add work /path/to/your/Program-Checkout
```

**Platform notes**

- CLI and server releases run on macOS and Linux, and on Windows x64 from v1.2.0, as does the Windows App. Sandboxed commands on Windows use optional WSL2 plus bubblewrap.
- No symlinks are needed: the installer records a real checkout.
- A program can be platform-specific in its own code; check its README and dependencies.
- OpenProgram's tooling is UTF-8 and `os.path`-based; a program should be too.

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| Harness functions missing after restart | Confirm `<pkg>/agentics/__init__.py` exists and exports `PROGRAM_ENTRIES`. Run with `OPENPROGRAM_DEBUG_REGISTRY=1`. |
| `[!] … neither a package (__init__.py), an application (application.json) nor a harness` | The repository holds none of the three shapes |
| `ModuleNotFoundError` for the harness's dependencies | Their install failed. Rerun `openprogram programs install <source> --upgrade` and read its error. |
| `from <pkg>.x import y` fails inside the harness | The package folder name must equal the import name, with an `__init__.py` |
| An existing dev symlink does not load | Run `openprogram programs install <git-source>` once to verify and record it |
| Fails to install or run on Windows | Check the program's README and dependency markers; it may provide only macOS/Linux backends |

## Write an installable harness

```
<Harness-Name>/                repository, any name
├── pyproject.toml             the harness's OWN dependencies only
└── <package>/                 importable package, ascii name
    ├── __init__.py            kept dependency-light
    └── agentics/
        └── __init__.py        PROGRAM_ENTRIES = [...]
```

At startup OpenProgram imports `<package>.agentics` and registers `PROGRAM_ENTRIES`. The root may vendor other packages: discovery finds the one with `agentics/` and puts the root on `sys.path`, so `from <package>.foo import bar` resolves.

```
# <package>/agentics/__init__.py
from openprogram import Agent


class ExampleAgent(Agent):
    method_options = {
        'my_tool': {'tool': True},
    }

    def my_tool(self, text: str = "") -> str:
        "One line: what this does (shown in catalogs)."
        return text.upper()


_example_agent = ExampleAgent()
my_tool = _example_agent.my_tool

PROGRAM_ENTRIES = [my_tool]
```

```
# pyproject.toml
[project]
name = "my-harness"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = []          # the harness's own deps, NEVER openprogram
```

### Two hard rules

1. **Never declare `openprogram` as a dependency**, in `pyproject.toml` or `requirements.txt`. `openprogram @ git+…` would make pip reinstall the host from git over the user's install.
2. **Keep `<package>/__init__.py` dependency-light and guard heavy imports.** Discovery imports `<package>.agentics` on every startup, including machines without your optional dependencies. A top-level `cv2` or `torch` breaks the whole registry load. Import them inside function bodies and guard the entry:

```
# agentics/__init__.py
try:
    from my_package.main import my_tool
    PROGRAM_ENTRIES = [my_tool]
except ImportError:
    PROGRAM_ENTRIES = []
```

### Test and publish

```
cd /path/to/My-Harness && git add -A && git commit -m wip
openprogram programs install file:///path/to/My-Harness
openprogram programs list             # lists My-Harness under Harnesses
OPENPROGRAM_DEBUG_REGISTRY=1 openprogram programs list   # functions present?
openprogram programs run my_tool -a text=hello           # smoke test
openprogram programs uninstall My-Harness                # set it aside
```

- `<package>/agentics/__init__.py` exposes `PROGRAM_ENTRIES`
- No `openprogram` in pyproject or requirements
- `python -c "import <package>.agentics"` succeeds in a bare venv with only OpenProgram installed
- The `file://` round trip above passes

Push to GitHub. Users run `openprogram programs install <owner>/<Harness-Name>`; nothing else to register.
