Skip to content

Packs

A pack is a zip that adds at most one platform to AutoMiner, plus the services it needs, without a new AutoMiner release. This page says how to write one and what a pack cannot do. The terms are in the glossary, and the design behind packs is in Packs: the architecture.

A pack cannot be installed yet. AutoMiner reads an uploaded pack, checks it and answers with what it would install, but nothing installs, imports or runs pack code. Installing, pausing, upgrading and uninstalling are #1507’s second half. Until then, the way to add a platform is to write it into AutoMiner’s code as a built-in platform: see Writing a platform.

A pack is a zip with manifest.json at its root and the pack’s Python code beside it:

gsm.zip
├── manifest.json
├── platform.py
├── routes.py
├── bridge.py
└── mark.svg

AutoMiner reads manifest.json and every .py file as data before any of the pack’s code runs. It refuses the zip if any of these holds:

  • The zip is larger than 8 MB, or its files add up to more than 32 MB.
  • A file name is absolute, contains .. or a :, or the file is a symbolic link.
  • There is no manifest.json at the root.
  • The bytes do not start like a zip, or the zip cannot be read.

This is the Game Sentence Miner pack’s manifest. It names a platform, its routes and a service of its own, and declares three settings:

{
"id": "gsm",
"name": "Game Sentence Miner",
"version": "1.0.0",
"author": "GSM contributors",
"interface": 1,
"platform": "platform:make",
"routes": "routes:make",
"mark": "mark.svg",
"needs": ["anki", "yomitan"],
"services": [
{
"id": "gsm_bridge",
"version": "1.0.0",
"interface": "gsm_bridge@1",
"entry": "bridge:make",
"settings": [
{"key": "gsm_bridge.max_piece_s", "label": "Longest piece (seconds)", "type": "int",
"default": 120, "advanced": true,
"help": "A piece is cut at the first line boundary after this long."}
],
"programs": []
}
],
"programs": [],
"settings": [
{"key": "gsm.lines_per_piece", "label": "Lines per piece", "type": "int", "default": 8,
"help": "How many lines GSM sends before AutoMiner mines them."},
{"key": "gsm.token", "label": "GSM token", "type": "str", "secret": true, "required": true,
"help": "Paste the token GSM shows under Settings > AutoMiner."}
]
}

The manifest is strict. A key that is not listed below is refused by name, so a typo fails at upload instead of being ignored. Every problem is reported at once.

Field Required Value
id yes The pack’s id: a lower-case letter, then 1 to 31 lower-case letters, digits or _. It is also the platform’s name.
name yes The name the confirm screen shows.
version yes major.minor.patch, such as 1.0.0, with no leading zeros.
author yes Who wrote the pack.
interface yes The pack interface it was written for. It must equal autominer.pack.INTERFACE, which is 1.
platform no The entry that returns the pack’s Platform.
routes no The entry that returns the pack’s routes, served under /v1/packs/<id>/ (#1509).
mark no A file in the zip, the platform’s mark.
needs no Ids of services the pack needs and does not bring, such as anki (#1505).
services no Services the pack brings. See below.
programs no Programs the pack downloads. See below.
settings no The platform’s settings. See below.

Some ids belong to AutoMiner itself, and a pack or service that takes one is refused. They are the built-in platforms’ names, the first part of each core feature’s key (such as anki, judge or yomitan) and the first part of each core job kind (such as mine or sync). AutoMiner derives the list from its own code.

Each service has id, version, interface and entry, and may have settings and programs of its own. interface is name@major, such as gsm_bridge@1. A service’s id follows the same rule as a pack’s, and it must differ from the pack’s id.

A program is a file the pack downloads, pinned by its SHA-256 for each operating system and machine (#1508):

{"id": "ocr", "file": "owocr", "check": ["--version"],
"pins": {"linux-arm64": {"url": "https://example.org/owocr-arm64", "sha256": "…", "size": 1234},
"win32-x86_64": {"url": "https://example.org/owocr.exe", "sha256": "…", "size": 1234}}}
  • file is the plain name the program is saved under, with no folder.
  • Each key of pins is Python’s sys.platform and the machine joined with a dash, such as linux-arm64, linux-x86_64, win32-x86_64 or darwin-arm64.
  • A pin has an https:// url, a sha256 of 64 lower-case hex digits, and an optional size in bytes.
  • check is optional: arguments the program must exit 0 with once downloaded.

Each setting has key, label and type, and may have default, secret, required, help and advanced.

  • key starts with its owner’s id and a dot: gsm. for the pack’s own settings, and the service’s id, such as gsm_bridge., for a service’s. Two owners can never claim the same key, and a key is declared once.
  • type is str, int, float, bool, path or url, and default must be a value of that type.
  • secret marks a value that is stored as a secret and never shown again.
  • required marks a value the learner must fill in before the pack can work. The confirm screen lists these.
  • Values live in AutoMiner’s settings store, never in the pack, so an upgrade or an uninstall keeps them.

Pack code may import only these:

  • autominer.pack, the one AutoMiner module a pack sees;
  • the Python standard library;
  • modules this AutoMiner already has, such as Starlette;
  • the pack’s own modules, through relative imports such as from . import texts.

A pack reaches a service it brings through its context, not by importing the service’s module, so the newest copy of a shared service is the one that runs (#1509).

AutoMiner reads the imports of every .py file in the zip without running it, and refuses any of these:

  • an import of an autominer module other than autominer.pack;
  • an import of a module this AutoMiner does not have, because a pack brings no Python dependencies of its own;
  • an import of one of the pack’s own modules by its bare name;
  • a relative import that reaches above the zip’s root;
  • a .py file that does not parse;
  • a compiled or native module, such as a .pyc, .pyd or .so file.

autominer.pack exports INTERFACE, Platform and its value types (Card, Details, Found, Site, Source, Subtitles), the exceptions NotFetchable, NotInLanguage, RetryLater and SkipJob, and the Piece and Line a pack hands over in pieces (#1510). core/tests/pack_interface.json records each of these, and a test fails when one changes without INTERFACE moving. Adding a field with a default does not move INTERFACE.

Every entry in the manifest names module:function, relative to the zip’s root, so platform:make is the function make in platform.py. A module in a folder is folder.module. The named module must be in the zip. AutoMiner calls each function with one argument, the context it gives the pack.

from autominer.pack import Card, Platform
def make(ctx):
return Platform(name=ctx.owner, title="Game Sentence Miner", audio=True,
subtitle_pool=False, native_label="ゲームのテキスト",
cards=(Card(title="GSM", mono="ws /v1/packs/gsm/v1/session",
help="Start GSM with AutoMiner as its target."),))

The context’s type, PackContext, joins autominer.pack when packs install (#1507). It gives the pack its settings and secrets by the name after the owner’s prefix, so ctx.setting("token") reads gsm.token.

A pack’s code runs inside AutoMiner with full access to the machine (ADR 0001). The limits are the fences AutoMiner holds the pack to, and the confirm screen lists them:

  • setting keys under the pack’s id and its services’ ids;
  • job kinds under <id>.;
  • routes under /v1/packs/<id>/;
  • imports from AutoMiner only of autominer.pack.

A pack also cannot:

  • take an id that belongs to AutoMiner itself;
  • bring Python dependencies of its own, or compiled code;
  • name a different interface version.

POST /v1/settings/packs takes the zip as the multipart field file. The request needs an X-AutoMiner header with any value, so another website’s form cannot send it. A request without the header gets 403 before AutoMiner reads the body, and a request whose Content-Length is over 9 MB gets 413.

The answer is the offer, what the confirm screen shows:

Field Value
sha256 The zip’s SHA-256.
manifest The parsed manifest, or null when it could not be read.
replaces The installed version of the same pack, or null.
older true when the upload is older than the installed version.
limits The fences above, for this pack.
dependencies The modules outside the standard library that the pack’s code imports.
to_fill The keys of the settings marked required.
refusals Every reason the pack cannot be installed. Empty means it can.

A refused pack still gets 200 and an offer, with its reasons in refusals. A pack with no refusals is kept as <sha256>.zip under packs/staged/ in AutoMiner’s home folder, so the same upload twice is one file. A staged zip older than a day is deleted when the next pack is staged.

ADR 0001 records the decision. A pack is plain Python that AutoMiner imports into its own process, with the same platform interface the built-in platforms use. A sandbox, or a process per pack, would make that interface far wider, and community platforms would end up second-class. The safeguards are at the door instead: the upload header, the confirm screen, the strict manifest, the interface version and the import rules above.

AutoMiner has no login of its own. Anyone who can open its web UI, whether through an access proxy, a tailnet or the home network, will be able to install a pack, and so run code on the host. Keep the UI reachable only by people you trust (see Access).

Issue What it adds
#1507 Install, pause, resume, upgrade and uninstall; declared settings and secrets; the Community list and confirm screen.
#1508 Downloading a pack’s pinned programs, verified by checksum.
#1509 Pack routes and websockets under /v1/packs/<id>/, and services shared between packs by id.
#1510 Pieces: a source handed over and mined while it is still going.
#1504, #1505 Services as units with an installed state, and platforms that name the services they need.