# Plugin Platform Release Notes

This note describes the plugin platform as it ships in the NextGram Android build based
on Telegram 13.4.3. It is the changelog and the verification checklist for the release.

## Features

- Maximum-capability v1 slice: TypeScript is the primary plugin language with a QuickJS
  runtime, a JavaScript bridge and live enable/disable; `java`/`code` and `hybrid`
  packages keep trusted native access.
- TypeScript SDK and CLI (`@nextgram/plugin`, `@nextgram/cli`) with templates and
  examples for screens, slots, admin, automation and resources.
- Declarative UI trees, Canvas display lists, 23 node types, 14 screen keys and 13 slot
  keys with host-owned accessibility, RTL, density, font scale and lifecycle.
- Resource overrides for fonts, sounds, wallpaper, icons, allowlisted strings, haptics,
  motion and chrome colors, with an atomic provider stack and reset.
- Message send, edit, delete, forward, reaction, typing, draft and mark-read; chat
  members, join/leave, group/channel creation and the full chat-admin surface.
- Automation rules with message/member/schedule triggers, bounded wildcard filters,
  actions, rate limits, audit, flood-wait handling and destructive confirmation.
- HTTPS-only HTTP client, media picker and sending, notification list/cancel/update,
  and outgoing/notification interceptors.
- `internal.access` and the unstable typed facade for trusted Java and hybrid packages.
- Install consent and the plugin manager show the new kinds, risks, automation and
  internal-access switches and the global reset actions.
- Signed `.ngp` packages for Kotlin/Java code plugins, TypeScript plugins and hybrid
  packages. The same package verifier, signature rules and limits apply to every kind.
- Code-plugin appearance through `ui.appearance`: `AppearanceTheme` with `LIGHT`,
  `DARK` and `AMOLED` bases, the semantic `AppearancePalette` tokens, raw upstream
  `Theme.key_*` colors and plugin-scoped custom colors. Apply, reset, persistence,
  previous-theme restore and safe mode are included.
- Screen replacement through `ui.screens` for `CHAT_LIST`, `CHAT`, `SETTINGS`,
  `PROFILE` and `MAIN_NAVIGATION`. The host owns an opaque overlay, lifecycle,
  navigation, insets, back handling and the protected-surface resolver.
- `CHAT_LIST_HEADER` and `SETTINGS_HEADER` slots, ordered by `SlotSpec.order`, plus
  plugin-owned full-screen views through `AndroidHost.openScreen` and
  `ui.custom_screens`.
- New permissions `ui.screens` (high risk) and `ui.custom_screens` (low risk).
  `ui.screens` is off by default at install; `ui.custom_screens` is a low-risk UI
  permission.
- The kernel-owned **Allow screen replacement plugins** switch, default on, disables all
  overlays and slots without uninstalling plugins.
- Protected surfaces never receive plugin views or screen contexts: login, passcode,
  payments, secret chats, installer, consent, safe mode, plugin manager, calls and
  inactive accounts. `SharedConfig.appLocked` also resolves to stock.
- The plugin manager has an **Appearance** section with the active provider (or
  **Stock theme**) and the kernel-owned **Reset appearance** action. There is no theme
  catalog, preview or Themes section.
- Atomic install, update and uninstall with rollback. Updates keep the same signing key,
  must increase `versionCode` and cannot downgrade.
- Permission consent with a permission diff on update. Declining added permissions keeps
  the installed version.
- Declarative settings, message actions, chat toolbar actions and header slots. Plugin
  Manager and Community are built-in plugins.
- Lifecycle, account, chat, theme and message events with secret-chat filtering and a
  first-frame safe mode.
- Read API v1 for accounts, chats and messages with permission checks, secret-chat
  filtering and bounded limits.
- Signed GitHub repository browser: strict index parsing, ECDSA P-256 verification,
  ETag cache, search, categories, details, verified download and install.
- Update checks with permission diff, opt-in daily checks and changelog display.
- Signed revocations with critical disable, warning overrides and startup enforcement.
  A critical entry takes precedence over a warning entry for the same version.
- Install extracts only from a staged copy whose size and SHA-256 are re-checked, so a
  file swapped after preview cannot change the installed payload.

## Hard break and migration

This is a pre-release hard break. `formatVersion` and `api` remain `1`.

Removed:

- `PluginKind.THEME` and `kind: "theme"`;
- the `theme/theme.json` payload root and the `theme` manifest field;
- theme package parsing, preview, apply/revert, the Themes section and `E_THEME`;
- theme wallpaper, font and icon fields.

A `kind: "theme"` package fails with `E_UNSUPPORTED_KIND` and the message:

> Theme packages are no longer supported. Ship a code plugin with the ui.appearance permission.

Migration:

1. Convert the palette to a normal code plugin with `"permissions": ["ui.appearance"]`.
2. Build the theme with `AppearanceTheme.builder(...)`: semantic `AppearancePalette`
   tokens, optional raw `Theme.key_*` values, optional custom colors.
3. Call `context.require(AppearanceHost.class).applyTheme(...)` from `onStart` or a
   settings action.
4. Rebuild against the current SDK if the source referenced `PluginKind.THEME` or the
   `theme` manifest field.

Compatibility:

- `dev.nextgram.betterblur` 1.0.1 loads without a rebuild and remains compatible.
  It uses blur controls only.
- `dev.nextgram.md3` and other sources that call `AppearanceHost.applyPalette`,
  `resetPalette` or `hasPalette` keep working; the palette methods are wrappers over the
  new appearance runtime.
- The `.ngp` verifier, signatures, atomic install and update identity are unchanged for
  code packages.

## Not in this release

- Theme packages, theme catalogs, previews and the theme kind.
- Layout overrides beyond the resource catalogue.
- Per-screen or per-chat theme isolation. The applied `.attheme` is global and also
  tints protected surfaces; it does not expose their data.
- Media, calls, payments and secret chats inside plugin screens.
- Custom repositories and share-to-chat.
- Contact and Telegram action APIs.
- Test SDK module and Gradle plugin. The shell packaging tool, the TypeScript CLI and
  both SDK modules are available.

## Build

```bash
./gradlew :TMessagesProj_App:assembleDebug --offline
./gradlew :nextgram-plugin-sdk-android:assembleDebug --offline
./gradlew :TMessagesProj:testDebugUnitTest --offline --tests 'dev.nextgram.plugin.*'
./gradlew :TMessagesProj_App:assembleRelease --offline
```

The release build uses the local release keystore and R8. The hash is build-specific.
Recompute it before publishing:

```bash
sha256sum TMessagesProj_App/build/outputs/apk/afat/release/app.apk
apksigner verify --print-certs TMessagesProj_App/build/outputs/apk/afat/release/app.apk
```

## Package a plugin

```bash
./gradlew :nextgram-plugin-sdk:compileJava :nextgram-plugin-sdk-android:assembleDebug
docs/plugins/tools/build-ngp.sh docs/plugins/examples/hello-plugin hello.ngp
docs/plugins/tools/build-ngp.sh docs/plugins/examples/appearance-plugin appearance.ngp
docs/plugins/tools/build-ngp.sh docs/plugins/examples/screen-plugin screen.ngp
jarsigner -verify hello.ngp
```

The script compiles code packages, produces one DEX at `--min-api 23`, writes the ZIP
layout and signs with JAR signing. It does not build theme packages; theme packages are
removed. Use `--unsigned` only for developer-mode testing. Production packages are signed
with the author key.

Local sample artifacts are development-key builds. Do not publish them. The demo
plugins show the two new capabilities:

| Demo | Permission | Shows |
| --- | --- | --- |
| `appearance-plugin` | `ui.appearance` | semantic, raw and custom colors, apply and reset |
| `screen-plugin` | `ui.screens` | chat-list replacement, header slot, theme-aware colors |

## Publish the catalog

The `nextgram-plugins` repository builds the catalog from entries and release assets.
Its `plugins/` directory starts empty; `templates/entry.json` is the starting point for
a submission. The generated index is published by the `publish-index` workflow:

```bash
python3 tools/build_index.py --repository gitwelk/nextgram-plugins \
  --commit <40-hex-commit> --artifacts <release-assets-dir> --verified
python3 tools/sign_index.py --key keys/index-private.pem \
  --input catalog/index.json --output catalog/index.sig
python3 tools/verify_index.py --public-key keys/index-public.pem \
  --input catalog/index.json --signature catalog/index.sig
```

`INDEX_SIGNING_KEY` in CI must contain the private key. The app pins the matching public
key in `RepositoryTrust.PINNED_PUBLIC_KEY`.

Debug builds expose a developer-only **Repository URL** override in
**Plugins → Security → Developer mode**. It accepts a loopback HTTP catalog for local
testing; release builds require HTTPS and compile the override out.

## Verification before publishing

- `:TMessagesProj_App:assembleDebug` passes.
- `:nextgram-plugin-sdk-android:assembleDebug` passes.
- `:TMessagesProj_App:assembleRelease` passes with R8 and produces a signed APK.
- The plugin JVM suite passes and covers appearance mapping, screen/slot registries,
  protected resolution, archive attacks and performance smoke checks.
- `jarsigner -verify` accepts the demo code packages.
- `NgpVerifier` accepts code packages in non-developer mode and rejects
  `kind: "theme"` with `E_UNSUPPORTED_KIND` and the migration message.
- The Android install preview shows the package identity, hash and signing key, and the
  screen consent copy for `ui.screens`.
- Index build, sign, verify and tamper rejection pass locally.
- The signed release APK installs and launches on an Android 16 (API 36) emulator
  without a crash.
- On-device instrumentation verifies signed code, appearance and screen packages:
  `PluginPackageDeviceTest`.
- On a physical device running Android 16 with an active account: a locally served
  signed catalog, appearance apply/reset/persistence, chat-list replacement with a
  header slot, stock restore on disable, update permission diff, warning revocation with
  override and critical revocation with disable.

Device checks that still need specific hardware or accounts:

- Android 14+ read-only DEX loading on a physical device.
- Chat document, file manager and share sheet install on a production build.
- Secret-chat and protected-surface screen exclusion; plugin log output.
- Rotation, back, multi-window, RTL, 200% font scale and TalkBack on a replaced screen.
- Startup and scroll performance on low-end hardware.
- External security review of the verifier and signature code.
