Files
Vlad Gothbreach af292ff15d
checks / pytest (push) Has been cancelled
checks / moderation (push) Has been cancelled
checks / node (push) Has been cancelled
Harden entry safety, unify runtime config, bound document unpacking
Shared-IP safety: entry autoban and entry notifications default off, and a
shared IP is treated as review evidence only. ban_user/ban_cluster refuse
reason=entry_ip_collision (also with the legacy flag set to 1), so token status
and quota are never touched; explicit admin moderation still works.

Reproducible startup: new bot/runtime_config.py and scripts/run.py load the
repository .env (or --env-file) without shell interpolation, normalize
config/DB/upstream aliases, and make the bot, Mini App, gateway, econ cap,
account admin, mk_daemon, entry admin and key notifications resolve the same
paths. "run.py <target> --check" is an offline preflight that starts nothing
and reports placeholders, missing upstream DB and invalid data directories.

Resource limits: aggregate Office decompression, a 400 read-entry cap and a
per-row XLSX cell budget stop early; truncated or corrupt archives are
reported instead of raising.

Deploy and docs: only source-backed systemd units remain, and
deploy/runtime.env.example documents the environment contract including the
0600 session-secret file rules. Removed the destructive
"cp bot/iishko_bot.py bot/grok_bot.py" instruction, the unused generated site/
snapshot and the unsupported iishko-ts staging unit; corrected .env.example,
README, ARCHITECTURE, SECURITY, docs/native-gateway.md and iishko-ts/README.md.

Tests: entry safety, runtime bootstrap, economy paths, file intake, deploy
contract, abilities_guard CLI, and a startup smoke that launches all three
components through scripts/run.py with non-loopback network blocked. Every
config reader, selfcheck included, accepts a UTF-8 BOM.

Verified on this tree: pytest 716 passed + 322 subtests, node --test 73/73,
go test and go vet clean, selfcheck --source-only ok, gitleaks worktree and
history 0 findings. No production or live-split changes are included.
2026-10-31 00:39:35 +03:00

108 lines
5.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Native gateway and commerce: short operator brief
Status: **shipped runtime is Python**. `gateway/grok-web-skin.py` plus the
`gateway_*` modules below are the runtime that this tree ships and tests. A Go
native gateway is **not included and is not the default**. The separate Go service
in `moderation/` is built and checked in CI; it is not the gateway.
This page documents operational behaviour, not internals. Authoritative behaviour
is the code in `gateway/` and the root `tests/` suite.
## Modules
| Module | Role |
|---|---|
| `gateway/gateway_errors.py` | upstream error classification (existing behaviour) |
| `gateway/gateway_features.py` | per-request feature gating for the skin/proxy |
| `gateway/gateway_policy.py` | policy decisions (limits, pinning, header exposure) |
| `gateway/gateway_usage.py` | usage accounting shared by HTTP and key paths |
| `gateway/gateway_providers.py` | provider registry (pinning, ownership, rpm bounds) |
| `gateway/gateway_provider_relay.py` | relay of a request to a pinned provider |
| `bot/gateway_commerce.py` | money routes (wallet/paid offers), disabled by default |
| `bot/commerce_access.py` | access rules for money/board routes |
| `bot/community_board.py` | community board: authenticated `/api/activities` (no kill-switch flag) |
| `bot/account_balances.py` | exact read-only balance aggregation shared by HTTP and the key daemon |
## Adaptive RPM
Rate limiting is **bounded and process-local**: the limiter keeps its state in the
gateway process only (no shared store, no cross-process guarantees). Each account has
one canonical owner record, so two operators cannot claim the same upstream account.
Restarting the process resets limiter state — this is intentional and not a data loss
signal.
## Daily usage headers
Daily usage is exposed as `X-Iishko-Daily*` response **headers** only. It is never
injected into JSON bodies and never into SSE streams, so clients that parse model
output are unaffected.
## Provider pinning
Pinning is opt-in and registry-driven:
```bash
cp gateway/providers.example.json providers.json
# Edit the private copy for your own instance before enabling pinning.
export IISHKO_PROVIDERS_FILE="$PWD/providers.json"
```
* The registry file is operator-owned configuration; `gateway/providers.example.json`
is a **shape example with placeholders only** — no credentials, no real endpoints,
no upstream channel data.
* Schema (validated by `ProviderRegistry` in `gateway/gateway_providers.py`):
top level `pinning_enabled` (bool, default `false`) and `providers` (list, ≤128).
Per provider: `id` (`[a-z][a-z0-9_-]{0,47}`, unique), `name` (1–80 chars),
`channel_ids` (ints ≥1, unique, ≤512, **never shared** between providers),
`priority` (int −10000…10000, default 0), `reserve` (bool, default `false`),
`max_inflight` (1…4096, default 32), `models` (map model → capability).
Capability: `effort_levels` (list of short strings or null) and `verification`
with `status` ∈ `unverified | identity_checked | operator_verified`,
`method` ∈ `none | response_model | tool_roundtrip | official_route | signed_attestation`;
any status other than `unverified` requires `checked_at` (positive int) and a
non-empty `reference` (≤200 chars).
`response_model` supports only `identity_checked`, never `operator_verified`.
The latter requires `tool_roundtrip`, `official_route`, or `signed_attestation`;
`tool_roundtrip` may also carry the weaker `identity_checked` status.
`unverified` requires method `none` and no timestamp/reference. Unknown evidence
fields and inconsistent pairs are rejected. The registry retains the raw
reference privately; the public catalogue exposes only status/method/timestamp.
These labels describe operator-provided evidence, not cryptographic proof of
model weights or an automatically performed check.
* Selection order is `(reserve, -priority, id)`; a route is reported `available` only
when it has channels, no cooldown/busy state and `pinning_enabled` is true.
* Editing/using the registry requires a New API **admin (owner role)** account: the
gateway refuses pinning for non-owner credentials.
* With no registry file configured, pinning stays off and routing behaves as before
(external New API decides).
* Route health accounts for the response produced by the success handler, not
just the upstream HTTP status: upstream 200 → downstream 503 is one failure.
No fallback occurs after the success handler starts; client cancellation
releases capacity without claiming a healthy route. An incomplete 2xx stream
is detectable here only if the handler raises; circuit state is process-local.
## Money and board routes
Commerce has **no enable flags**. The switches that exist are configuration values:
| Control | Where | Effect when empty |
|---|---|---|
| `commerce_offers` | `bot/config.json` | purchases disabled; there are no default prices in code |
| `cryptopay_token` | `bot/config.json` | payment create/verify unavailable |
| `CRYPTOPAY_TOKEN` | environment | overrides the config value when set |
| `IISHKO_ADMIN_IDS` | environment | empty env-admin list; the trusted `users.admin` column still applies |
| `IISHKO_APP_ROOT` | environment | module root; default bot source is `$IISHKO_APP_ROOT/grok_bot.py` |
| `IISHKO_BOT_SOURCE` | environment (optional) | explicit override of the bot source file |
`community_board` and `account_balances` have **no disable switch**: board routes are
served and access is limited by auth/ban/admin gates. Empty offers disable purchases
only — reading an existing wallet and grants keeps working.
Pricing and offer contents are operator configuration; nothing is invented here.
## Environment
See `.env.example`: `IISHKO_APP_ROOT`, `IISHKO_UPSTREAM`, `IISHKO_GATEWAY_HOST`,
`IISHKO_GATEWAY_PORT`, `IISHKO_BOT_DB` (aliases `GATE_BOT_DB`, `GATE_NEWAPI_DB`),
`IISHKO_PROVIDERS_FILE`. All defaults are loopback.