# For AI agents

This site is built to be read by an agent without scraping HTML. Every page has a Markdown
source, a stable URL and a description. The rules below are the ones that most often decide
whether a generated package installs or is rejected.

## Reading order

1. [`/llms.txt`](https://plugins.nextdev.fun/llms.txt) — the index and the hard constraints.
2. [`/raw/authoring-checklist.md`](https://github.com/gitwelk/NextGram/blob/main/docs/plugins/raw/authoring-checklist.md) — the non-negotiable rules.
3. [`/raw/package-format.md`](https://github.com/gitwelk/NextGram/blob/main/docs/plugins/raw/package-format.md) — the manifest and the verifier.
4. The one capability page the task needs, for example `/raw/screens.md` or
   `/raw/capabilities.md`.
5. [`/raw/build-sign.md`](https://github.com/gitwelk/NextGram/blob/main/docs/plugins/raw/build-sign.md) before producing an artifact.

Do not read the whole site by default. Fetch `llms.txt`, then the page that matches the
task. Use `llms-full.txt` only when a question spans several pages.

## Machine endpoints

| Endpoint | Contents |
| --- | --- |
| `/llms.txt` | Curated index, reading order and required facts |
| `/llms-full.txt` | Every page concatenated with page markers |
| `/ai.json` | Page titles, descriptions, groups, URLs and Markdown paths |
| `/search-index.json` | Section-level search records |
| `/raw/<slug>.md` | The clean Markdown source of one page |
| `/sitemap.xml` | Canonical page URLs |

Each rendered page also declares its Markdown source:

```html
<link rel="alternate" type="text/markdown" href="/raw/package-format.md">
```

## Canonical facts

| Fact | Value |
| --- | --- |
| Manifest format | `format: "ngp"`, `formatVersion: 1`, `api: 1` |
| Package kinds | `ts` (`script`), `java` (`code`), `hybrid` |
| Removed kind | `theme` is rejected with `E_UNSUPPORTED_KIND`; use `ui.appearance` |
| TypeScript payload | `script/main.js`, one IIFE, max 8 MB |
| Java payload | `android/dex/classes.dex`, exactly one file, max 32 MB |
| Package limits | 64 MB file, 192 MB uncompressed, 4096 entries, 200:1 per entry |
| Manifest size | `plugin.json` max 256 KB |
| Signature | JAR signing, SHA-256, RSA ≥ 2048 or EC ≥ P-256, self-signed certificate |
| Update identity | Same plugin id and same signing key, strictly higher `versionCode` |
| UI limits | 10,000 nodes, depth 64, 10,000 characters per string, 10,000 canvas ops |
| Minimum host | `minHost` is required for `ts`, `hybrid` and every new capability |

## Rules that prevent rejection

- Use an immutable lowercase reverse-DNS `id` with at least two segments. `app.nextgram.*`
  is reserved and an external package with that prefix is rejected.
- Keep `format`, `formatVersion` and `api` exactly at the values above. Do not invent fields.
- Use semver `version`; use a positive integer `versionCode` that increases on every release.
- A `ts`/`script` package must not contain `android/`. A `java`/`code` package must not
  contain `script/`. Only `hybrid` contains both.
- Do not bundle `dev.nextgram.plugin.v1.*` classes; the SDK is `compileOnly` and the host
  provides it at runtime.
- Do not define classes in `java.*`, `javax.*`, `android.*`, `dalvik.*`, `org.telegram.*`,
  `dev.nextgram.plugin.*` or `dev.nextgram.builtin.*`.
- Do not declare Android components or use Android resources and `R.*`. Bundle assets as
  files under `assets/`.
- TypeScript bundles must not use `require`, `module.exports`, runtime ESM imports,
  dynamic imports, `node:*` or bare Node built-ins. The output must assign
  `globalThis.__ngp_plugin__`.
- Declare the minimum permissions. Unknown permissions reject the package. `ui.screens`
  is high risk and off at install.
- `internal.access` and the internal facade are trusted-memory access. Do not request them
  unless the task explicitly requires native internals.

## Validation loop

Run these before handing a package to a person:

```bash
nextgram-plugin build
nextgram-plugin pack --key key.pem --cert cert.pem
nextgram-plugin verify build/*.ngp
```

For Java and hybrid packages, from `NextGram-android/`:

```bash
./gradlew :nextgram-plugin-sdk:compileJava :nextgram-plugin-sdk-android:assembleDebug
docs/plugins/tools/build-ngp.sh <plugin-dir> <output.ngp>
jarsigner -verify <output.ngp>
```

`verify` mirrors the host checks: allowed roots, manifest fields, package and entry limits,
prohibited extensions, nested archives, icon dimensions, DEX magic and signature coverage.
A package that fails `verify` will fail the installer.

## When information is missing

The site describes the shipped API 1 surface. If a symbol, permission or field is not on
this site, do not guess it. Check the SDK sources under
`NextGram-android/nextgram-plugin-sdk`, `nextgram-plugin-sdk-android` and
`nextgram-plugin-ts/packages/plugin/src`. Ask for the missing contract instead of emitting
a plausible-looking API that the host does not implement.

## Reporting a result

When an agent finishes a plugin, report:

- the plugin id and version;
- the package kind and payload paths;
- the exact permissions;
- the signing fingerprint or the fact that the package is unsigned for developer mode;
- the commands that produced and verified the artifact;
- any host contract that could not be verified from the sources.
