interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / scripts / allen / README.md

559 lines · 36348 bytes Raw Blame History Rendered
1# allen-chat: the public Allen gateway
2
3`https://www.aienos.com/allen/` lets anyone talk to Allen, my AI, run small programs in their own
4browser, find what I have built, propose an issue or a project, and introduce
5themselves with consent. No model answers there right now: the Qwen3.6-35B-A3B
6FP8 this gateway was written for (on `:18091`) was retired on 2026-11-06, and
7my own model, the Omega LLM, is not deployed yet. `MODEL` in `allen_chat.py`
8is empty, so the gateway names no model; fill it with the served id when a model
9is deployed.
10This directory is the server half: one Python process
11on the Spark (`allen_chat.py` plus `allen_spool.py`), its systemd unit, the hub
12nginx route and the tests. The page half is `om/allen-page/` (Omega-generated
13markup and JS).
14
15```
16browser --TLS--> hub :443 SNI router --PROXY protocol--> hub nginx www.aienos.com (127.0.0.1:4446)
17 /allen/api/... --tailnet--> 100.64.0.2:18110 allen-chat (system unit, User=drakestapleton)
18 chat --> 127.0.0.1:18091 (shared model server, streamed, keep-alive)
19 omega --> bwrap { pinned omc (native check, then IR) -> pinned irwasm } -> .wasm to the browser
20 submit --> spool/in/<id>.json (omega-projects-pusher files it; see below)
21 projects/save|publish --> spool/in/<id>.json (the build loop; see "Build loop")
22 introduce --> contacts-drop/<hex>.json (allen-contacts-ingest stores it; see below)
23```
24
25## What public Allen cannot do
26
27Public Allen cannot deploy anything: not to this site, not to any repository,
28not to the hub and not to the Spark. This is enforced by structure, not by the
29prompt, and each point is tested with a negative control (results in the PR):
30
311. **Compute only, never deployment.** Native function calls are admitted only
32 for `math_compute`, `omega_compile`, `web_app`, `paper`, `research`, and
33 `plot`, with strict schemas, bounded arguments and at most three tool rounds.
34 The gateway forwards them only to a separate `allen-science` process on
35 loopback. Its inherited listener is its only network access: the science
36 process has an empty network namespace, no credentials, a read-only install,
37 private temporary storage, and bounded compiler/math subprocess sandboxes.
38 Neither process has shell, git, gh, ssh, deployment or arbitrary URL tools.
39 Unknown tool names and malformed calls are refused, never executed as text.
40 Math comes from the pinned pure-Omega aien-math engine, not model arithmetic;
41 unsupported expressions remain unsupported. Engine output is experimental,
42 not proof of correctness. Panes retain its exact expression, result and pin.
43 Research has no live web search. Papers and research are unverified drafts;
44 plots show input data. Browser apps and WASM require explicit visitor Run.
45 Projects stay in browser IndexedDB; optional memory sync sends only a short
46 summary after a separate visitor action, never an anonymous server write.
47 There is no Wolfram integration, account, key or public-use dependency.
48 `pane-contract.om` versions the SSE pane contract; `science_protocol.py`
49 validates it on the host. These Python HTTP/JSON adapters are recorded
50 migration dependencies, not represented as Omega implementation.
512. **Sandboxed process.** `allen-chat.service` is a system unit running as
52 drakestapleton (the user manager on this Spark silently skips mount
53 namespacing, so a --user unit would not enforce these):
54 `NoNewPrivileges`, empty `CapabilityBoundingSet`, `PrivateUsers`,
55 `ProtectProc=invisible`, `ProtectSystem=strict`, `ProtectHome=tmpfs` with
56 read-only binds of only its code dir and the pusher's status dir and
57 read-write binds of only the two drop directories, `PrivateTmp`,
58 `PrivateDevices`, `RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
59 AF_NETLINK` (netlink only so bwrap can bring up the sandbox's own
60 loopback), `IPAddressDeny=any` with `IPAddressAllow=127.0.0.1 100.64.0.1
61 100.64.0.2 100.64.0.3 100.64.0.4` (.1 and .4 are my devices, for the console), `LockPersonality`, `MemoryDenyWriteExecute`,
62 `SystemCallFilter=@system-service @mount unshare setns`. Measured: it cannot
63 read `~/.ssh`, `~/.config/gh`, `~/.omp`, the vault, the contact store or the
64 gb10 lock (also not through `/proc/<pid>/root`), cannot `sudo`, and cannot
65 connect to github.com, the internet or the LAN. The Spark firewall admits
66 port 18110 only from the hub's tailnet address.
673. **Compiling is not running.** The Omega path runs only the pinned compiler
68 and translator, inside bwrap with no network, a read-only root containing
69 only the tool, an 8 MiB tmpfs, no `/proc`, cleared environment, no
70 capabilities, its own pid namespace, RLIMIT_CPU 4 s, RLIMIT_AS 512 MiB,
71 RLIMIT_FSIZE 4 MiB and a 5 s wall clock. Nothing the compiler produces is ever
72 executed on the server; the `.wasm` runs only in the visitor's browser,
73 without imports. If bwrap is missing or cannot build a sandbox the gateway
74 refuses to start (no bare omc). Nothing is persisted.
754. **Web apps** run only in the visitor's `<iframe sandbox="allow-scripts">`
76 with a `default-src 'none'` CSP: opaque origin, no cookies, no storage, no
77 network, no top navigation.
785. **Proposals, not publication.** Allen can draft an issue or a project. Only
79 after the visitor confirms the exact text does the gateway drop it into a
80 spool it can write but not act on. A separate unit,
81 `omega-projects-pusher` (path-activated, the only holder of GitHub write
82 access, scoped in code to `aien-dev/omega-projects`), re-validates it,
83 removes emails and phone numbers, and files exactly one issue (labels
84 `from-allen`, `area:<repo>`), commits a visitor's save to their own branch
85 `u/<handle>`, or commits a publish to `p/<handle>/<project>` and opens one
86 pull request to main. It never pushes to main and never merges; the
87 repository's ruleset requires my approval with no bypass. Only my merge
88 publishes anything.
896. **Introductions are private and consented.** Nothing is stored unless the
90 visitor (or agent) sends `consent: true` after the notice. The gateway drops
91 the record for `allen-contacts-ingest`, which appends it to a store that is
92 not in the gateway's mount namespace, so the gateway, and therefore a
93 prompt-injected Allen, can never read one visitor's details back to another.
94 Deletion: the delete link (`#forget=<id>.<token>`, the token is only ever
95 stored as a hash) or by email; I read the store with `allen-contacts`.
967. **Upstream auth ready.** The gateway reads `ALLEN_UPSTREAM_TOKEN` from
97 `~/.config/allen-chat/env` of the unit's user (empty today) and sends it as
98 a bearer to 18091, for the sovereign-core #771 cutover.
99
100## What protects the shared model
101
102| Guard | Where | Default |
103|---|---|---|
104| Public requests in flight upstream | gateway `--cap` | 2 of the server's 8 batch slots |
105| Waiting queue, position streamed to the visitor | gateway `--queue`, `--queue-wait` | 6 deep, 90 s |
106| Back-off while the server is busy | gateway `--busy-at` (reads `/health` `in_flight`) | no new public start at >= 6 |
107| Per-address rate | nginx `limit_req` (chat 6/min burst 4, omega 12/min burst 6, submit/introduce 6/min burst 3) and gateway token buckets (chat burst 4 then one per 20 s; omega burst 6 then one per 10 s; submit and introduce 3 per hour) | both |
108| Global submissions | gateway (40 per UTC day) and pusher (40 issues, 20 PRs per day) | both |
109| Turn size | gateway | 24 messages, 4000 chars each, 16000 total, 1024 output tokens |
110| Timeouts | gateway | 60 s to first token, 20 s between tokens, 150 s per answer |
111| Connections per address | nginx `limit_conn` | 4 |
112
113The system prompt is sent byte-identically on every request so the server's
114prefix stays the same between turns. The hub keys limits on the PROXY protocol
115address only inside `/allen/api/`; `$remote_addr` stays the loopback for the rest
116of the site, so the site's own access log is unchanged, and `/allen/api/` is not
117logged at all.
118
119### Temporary workaround: the native pre-check
120
121The gateway compiles every Omega unit twice: first in omc's native function mode
122(output discarded), then in IR mode. This is a workaround for check gaps in the
123IR mode of the pinned omc `734f0a39` (extra words at the end of a line, names
124over 8 characters, shadowing are accepted in IR mode, and one unknown-word case
125lowers a different program). OmegaNext has routed the repros to OmegaMemory;
126remove the pre-check once that fix merges into omega-mv and the site's omc pin
127moves past it (link the PR here when it exists). When the pin changes, also
128recheck the system prompt's "names at most 8 characters" line: omega-mv main
129has different name-length rules.
130
131## Speed test (`infer`, `infer-info`, `infer-verify`; `allen_infer.py`)
132
133On `/aien/` the speed test opens as a glass pane (Speed control, or a `#r=` link). A run is a plain
134chat completion: no Aien persona, temperature 0, and a first system line `Speed test run <8 hex>.`
135so the engine can never continue a cached row (its log shows `reuse 0 tok (cold)` for every test
136request): prefill is always measured from scratch. Modes: single (preset or own prompt, up to
1374096 output tokens), parallel (2 to 4 streams, aggregate tokens/s) and a context sweep (separate
138requests at 512, 1k, 2k, ... up to 4k/8k/16k/32k prompt tokens, 8 output tokens each). The
139gateway times every chunk as it arrives (TTFT, prefill tok/s = prompt tokens / TTFT, decode
140tok/s = (tokens - 1) / first-to-last chunk) and stamps each result with host load1 and the
141server's in_flight. Results carry an HMAC (key derived from `ALLEN_VISITOR_SECRET`), so a
142shared `#r=` link can be checked with `infer-verify` without storing anything.
143
144Protection, because a prefill on this engine slows every generating row 6-9x
145(handoffs/AienPage/LATENCY.md): tests together hold at most 4 of the 8 rows and start only while
146`/health` in_flight + rows <= 6; heavy tests (parallel, any sweep, prompts over ~4k tokens) run one
147at a time, start only while no chat turn runs or waits here, and yield the moment one arrives
148(parallel: streams closed; sweep: stops before the next step; the page shows "yielded to a live
149chat" with the partial result). Per visitor: one run at a time, 6 runs a minute, 3 heavy runs in
15010 minutes. FIFO line of 8 with visible position, 180 s maximum wait; prompts up to 48 KiB
151(about 32k tokens); hub zone `allen_infer` 12 r/m. Tests: `ALLEN_TEST_ONLY=infer` in
152`test_gateway.py`.
153
154The same benchmark on any OpenAI-compatible server (same presets, same `measure()`):
155
156```
157git clone https://github.com/aien-dev/aienos.com && cd aienos.com
158python3 scripts/allen/allen_infer.py bench http://127.0.0.1:8000 --model <your-model> [--streams 4] [--sweep 8192]
159```
160
161## Math panes (`math`; `allen_math.py`)
162
163`POST /aien/api/math` with `{"expression": "Integrate[x^2,{x,0,1}]", "title": "Area"}` sends the
164expression, as the `math_compute` tool, to the math-only `allen-science` instance
165(`127.0.0.1:18114`, `allen-science-math-fg`: the same service started with `--tools math_compute`,
166which answers 403 to every other tool), which runs the pure-Omega aien-math engine in its
167sandbox. allen-chat's egress filter admits 18114, not the full-service port 18113. The reply is
168at most three v1 pane events plus a one-line result; the page renders them
169with AllenPanes, which checks them again against the pane contract. No model call, nothing stored.
170Limits: expression 4096 characters, 12 a minute per visitor, hub zone `allen_omega`. A missing or
171malformed service answer is a 503. Tests: `python3 scripts/allen/test_math.py`.
172
173## Speed: one warm prefix, cards per turn, answers from a cache
174
175What reaches the model, in order (`allen_speed.py`): the system text (system
176prompt + `catalog.txt`, byte-stable until the catalog changes), the fixed opening
177for the greeting the visitor saw, the visitor's recalled notes (frozen per
178conversation), then the visitor's turns. Each user turn carries its own cards
179(repo detail lines from `catalog-detail.jsonl` via the catalog's `retrieve.py`,
180and lesson cards from `--learn-dir`), produced by the same pure function of that
181turn's text on every request, so turn N+1's prompt starts with exactly turn N's
182prompt and reply and the server reuses that row's history.
183
184The server (qwen36_batch.rs `admit()`) reuses a row only when the new prompt
185starts with that row's history or with its snapshot at the last `<|im_start|>`.
186The warm thread keeps one snapshot of [system, open line] per greeting variant
187(at start, after every catalog change, and after each first turn takes it); a
188first turn on it prefills only the opening and the question. `meta` says
189`warm` when the warm thread last left that snapshot in place and `cold` when a
190first turn arrives before the re-warm finished (the server log's `join:` line is
191the ground truth; `speed/` in the handoff compares the two).
192
193Without the model at all:
194
195- **static**: a pure greeting or thanks as the first turn (`allen_speed.STATIC`).
196 The page's own greeting, the human/agent choice and its replies are written
197 by the page and send nothing.
198- **cache**: canonical answers for the common first questions
199 (`answers/questions.json`), generated by `gen_answers.py` as a visitor's exact
200 anonymous first turn at temperature 0 and stored in `answers/answers.json`
201 (installed as `/opt/allen-chat/answers.json`, reviewable). Each entry carries
202 `prefix_sha` (sha256 of the system text) and `grounding_sha` (sha256 of its
203 stable cards: no latest commit, push month only). An entry whose keys do not
204 match the live files is never served; the gateway regenerates it itself
205 (`--regen-per-hour`, only while `/health` reports nothing in flight and no
206 public request runs or waits) into `--answers-state`. Lesson Q&A from the
207 curriculum's `qa.jsonl` is served verbatim. Matching: exact after
208 normalization, else the same set of content words (negations kept); two
209 answers sharing a form match neither. Only a first turn with no recalled
210 notes is answered from the cache.
211
212Cached and static answers stream in token-sized pieces at `--cache-tps` and end
213with the usual `done` event. Every chat response names its source in the
214`X-Allen-Source` header and an `event: meta` `{"source": "static"|"cache"|"warm"|"cold"}`
215before the first token; `done` repeats it.
216
217## Privacy
218
219No prompt, reply, source, address or path is written anywhere: the handler's
220access log is disabled, nginx has `access_log off` on these routes, and the
221rate-limit keys are salted BLAKE2 hashes held in memory. The journal gets one
222aggregate counter line every ten minutes. Introductions are the only personal
223data kept, only with consent, as described above.
224
225Every public POST passes a cross-site gate first: a request with an `Origin`
226header must come from `https://www.aienos.com` or `https://aienos.com` (more
227with `--allow-origin`), or it is refused 403; one without `Origin` but with
228`Sec-Fetch-Site` is a browser and refused 403 too; one with neither is a
229server-side client (the X bot, tests, curl) and is allowed. Then the body must
230be `Content-Type: application/json` (415 otherwise), except `transcribe`, which
231checks its own audio type. A cross-site "simple" request (text/plain or a form)
232therefore never runs on a visitor's IP allowance. The hub snippet applies the
233same rules before proxying.
234
235## Reaching me (relay, live takeover, console)
236
237- `POST relay` drops a visitor-confirmed message into
238 `/var/lib/allen-chat/relay-drop/` (allen-relay:allen-relaydrop 2730; the
239 gateway can create files but not list or read them). Caps: message 4000,
240 name/contact 200, transcript 24 messages / 16000 characters, secret shapes
241 refused; one per conversation and message; 3 per address per hour; 30 per
242 day. The relay mailer (`/opt/allen-relay/`, user `allen-relay`, started by
243 `/opt/allen-relay/start`, no systemd unit) re-validates each file and emails
244 it from aien@aienos.com to drake@aienos.com only, over SMTPS to
245 mail.gandi.net:465. The Gandi password comes from atlas-vault on its stdin.
246 nft (`chain output`) lets uid allen-relay reach only loopback DNS and port 465.
247- `GET presence`, `POST handoff` (only while I am online), `GET session`
248 (SSE: `state`, `human`, heartbeat every 15 s), `POST say`. While I have
249 joined a conversation, `POST chat` answers `event: error {"code":"human"}`
250 without calling the model. `event: human` is written only by the console.
251 These routes are keyed by `X-Allen-Conversation`, the live-session bearer.
252 The page draws 32 hex (128 random bits) per conversation. The gateway, the
253 console session routes and the relay spool also accept a 16-hex id: a tab
254 left open across the page deploy keeps the id it minted, and a relay file
255 queued before the deploy still has one. Any other shape is refused with 400
256 (`chat` then runs without a conversation; the console route answers 404).
257 Deploy this gateway, `allen_spool.py` and the relay mailer before the page.
258 GitHub Pages publishes the page on merge, and the gateway they replace
259 accepts only 16 hex, so a 32-hex page against that gateway makes handoff,
260 say and session return 400. Once this gateway is running, merging the page
261 is safe and open tabs keep working. The 16-hex acceptance comes out on
262 2026-12-02 (https://github.com/aien-dev/aienos.com/issues/196).
263 `STREAM_MAX_S` ends one session stream after an hour and the page
264 reconnects with the same id, so a tab left open still sends 16 hex until
265 the visitor reloads. After that date those tabs get 400 on handoff, say
266 and session until reload.
267- The console is a second listener in the gateway on `100.64.0.2:18112`. The
268 hub never proxies it, and nft admits it only from 100.64.0.1 and 100.64.0.4
269 (plus the Spark itself over loopback). Login is with the token held in
270 atlas-vault as `ALLEN_CONSOLE_TOKEN`; the gateway holds only its sha256
271 (`ALLEN_CONSOLE_TOKEN_SHA256` in `/etc/allen-chat/env`). Sessions use an
272 HttpOnly SameSite=Strict cookie that lasts 12 h, with a CSRF token on every
273 POST, no CORS and a pinned Host. By default the cookie (`allen_console`) has
274 no `Secure` flag on purpose: the console is plain HTTP inside the tailnet
275 (WireGuard-encrypted), where a Secure cookie would never come back; the nft
276 rule above is the compensating control. If the console is ever served over
277 TLS, start the gateway with `--console-secure-cookie`: the cookie becomes
278 `__Host-allen_console` with `Secure` (host-only, `Path=/`), and the plain
279 name is no longer accepted. Do not set it on the plain-HTTP console, or
280 login will loop, because the browser never returns the cookie. Availability
281 is kept in `/var/lib/allen-chat/console/presence.json`.
282- Anonymous mode: `X-Allen-Anonymous: 1` means no recall and no notes, whatever
283 key is sent, and `introduce` answers 409 `anonymous`.
284- `POST project-summary` {"summary" (at most 1000 bytes of text, no email,
285 phone or secret), "consent": true}, key holders only (409 in anonymous mode):
286 one Cortex note "Project summary: ..." per visitor, replacing the previous one.
287
288## Push-to-talk (`POST transcribe`)
289
290The page posts one raw clip (no JSON, no base64) with `Content-Type`
291`audio/webm` or `audio/ogg` (Opus) or `audio/wav` (16-bit PCM, mono or stereo,
2928-48 kHz). Limits: 1 MiB, 15 s of audio (longer clips are refused with 413,
293never cut), 0.3 s minimum, the chat route's per-address bucket (own bucket;
294hub zone `allen_voice`, 6/min burst 4), one transcription at a time (503
295`busy`, `Retry-After: 2`). Reply: `200 {"text","ms","seconds","model"}`;
296refusals `{"error","message"}`: 411 `length`, 413 `too_long`, 400 empty, 415
297`format` (wrong type, or bytes that do not match it), 422 `audio` (undecodable,
298not Opus, not 16-bit PCM, too short), 429 `rate`, 503 `busy`.
299
300The body is read into one buffer in memory. WebM/Ogg goes through ffmpeg
301(forced demuxer, native Opus decoder, `pipe:` only) in a bwrap sandbox that sees
302read-only `/usr` and the loader files and nothing else; the PCM then goes over
303a pipe to the pinned static `whisper-cli` in a second sandbox that sees only
304itself and the pinned model. Both run with `RLIMIT_FSIZE` 0, so neither can
305write a file; no audio file exists at any point (`test_transcribe.py` traces
306every open with strace and fails on any write outside bwrap's own namespace
307setup; a mutant that writes the clip to disk is caught). The gateway zeroes its
308buffers after use; the immutable copy that `subprocess` returns for ffmpeg's
309output is dropped by reference. The transcript is returned, never logged.
310Without `--whisper-cli` the route is 404; with it, the gateway refuses to start
311unless whisper-cli and the model match their pins and both sandboxes run.
312The page detects the route without recording anything: `GET presence` carries
313`"transcribe": true` only when the gateway was started with `--whisper-cli`
314(and therefore passed its pin and sandbox checks).
315Visitors say the name "Aien" like "Ian": unambiguous spellings (Ayen, Een,
316Aian, ...) become "Aien" anywhere, and "Ian" only when it addresses him (start
317of the clip, after a greeting, or "..., Ian." at the end). "My friend Ian"
318is left alone.
319
320## Dependencies and the Omega path
321
322Omega has no HTTP, TLS or socket words yet, so this gateway is host code, like
323`crates/hive-feed` and `hive-receive`. Recorded per the AIEN dependency rule:
324
325| Dependency | Version on the Spark | What it does here | Omega replacement |
326|---|---|---|---|
327| CPython standard library (`http.server`, `http.client`, `subprocess`) | 3.12.3 | HTTP/1.1 server, upstream client, SSE relay, sandbox launcher | An Omega gateway once host words for sockets, HTTP and process spawn land; the open host-primitive proposal is aien-dev/omega-mv#788 (bounded TLS HTTP/JSON host primitives). This hop is plain HTTP over the tailnet, so no TLS is needed in Omega for it. |
328| bubblewrap | 0.9.0 | Namespace sandbox for omc and irwasm | Kept as an isolation tool around the compiler; the compiler and translator themselves are seeded Omega. |
329| nginx (hub) | 1.28.3 | TLS, PROXY protocol, rate limits, routing | Existing edge; unchanged dependency. |
330
331The compiler (`omc`, sha256 `734f0a39...6b61`) and the IR-to-WebAssembly
332translator (`irwasm`, sha256 `2d235a70...82e6`) are seeded Omega binaries
333(`om/hive-page/`); the gateway refuses to start on any other bytes.
334
335## Catalog (allen-catalog)
336
337`catalog.py` writes three files into `/var/lib/allen-catalog/`:
338
339- `catalog.txt`: the list of Drake's public work that the gateway appends to Allen's system
340 prompt (the cached prefix). It holds only what the model reads (no head shas), so a push
341 does not rewrite it; each rewrite costs one cold prefill.
342- `catalog-detail.jsonl`: one record per non-fork public repo (active and archived) with
343 state, last push date, head sha, latest commit date and subject, the repo's own status or
344 evidence line ("not stated" when it has none), a how-to line from its install/usage
345 section (omitted when absent) and docs links (README, `docs/`, `STATUS.md`, wiki). The
346 first record (`_sources`) holds the aienos.com head and page-source digest.
347 `retrieve.py` `select(load(path), user_text)` returns up to 5 matching lines for the
348 gateway to append to the LAST user turn, never to the system text.
349- `areas.txt`: active public repo names, one per line (the issue `Area:` values).
350
351Sources, all unauthenticated, so a private repository cannot appear:
352
353- `GET https://api.github.com/orgs/aien-dev/repos?type=public&per_page=100` (paginated, no
354 Authorization header). Forks and archived repos are named on one line; every other repo
355 gets a line with its description (truncated at a sentence or clause, never reworded),
356 license, last push month and head.
357- `git ls-remote https://github.com/aien-dev/<repo> HEAD` with `-c credential.helper=`,
358 `GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1`, `GIT_TERMINAL_PROMPT=0` and no
359 SSH agent. An empty repository (no HEAD) is listed as `empty`.
360- `README.md` at that head from raw.githubusercontent.com (its first sentence is used
361 only when a repo has no description; a 404 means no README).
362- `crates/site-builder/src/seo.rs` of aienos.com at its head: every `PageInfo` becomes
363 a page line with its full https://www.aienos.com URL. `/allen/` is added from the
364 feat/allen-chat text until it reaches main.
365
366Output is ASCII and LF, sorted, with no clock time. The `Sources:` line records the
367aienos.com head and a digest of every input (full head shas, README digests, seo.rs digest),
368so the file changes only when an input changes. Text containing we, our or us is cut
369before that clause. A failed fetch exits 1 and the old files stay. Files are written
370through temporaries and renamed. Unchanged output is not rewritten, so the gateway's mtime
371stays put and the opening snapshot stays warm.
372
373Units (system units; `allen-catalog` is a system user with no home and no credential):
374
375- `allen-catalog.service`: oneshot; `/opt/allen-catalog/catalog.py /var/lib/allen-catalog`.
376 NoNewPrivileges, empty CapabilityBoundingSet, PrivateUsers, ProtectSystem=strict,
377 ProtectHome=yes, ReadWritePaths=/var/lib/allen-catalog, PrivateTmp, PrivateDevices,
378 RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX, SystemCallFilter=@system-service.
379 IPAddressDeny covers loopback, LAN, tailnet and ULA; only the DNS stub 127.0.0.53 is
380 allowed, so the unit reaches GitHub and nothing local (not the model server on 18091).
381- `allen-catalog.timer`: hourly (Persistent, up to 2 min random delay) and 5 minutes after boot.
382 One GitHub API request per run; everything else is git smart HTTP and raw files. Per-commit
383 data is cached in `/var/lib/allen-catalog/.cache/` by head sha, so a quiet hour costs
384 one API call and one `ls-remote` per repo and wiki.
385
386Install:
387
388 sudo install -d -o root -g root -m 0755 /opt/allen-catalog
389 sudo install -o root -g root -m 0644 catalog.py retrieve.py /opt/allen-catalog/
390 sudo install -d -o allen-catalog -g allen-catalog -m 0755 /var/lib/allen-catalog
391 sudo install -m 0644 allen-catalog.service allen-catalog.timer /etc/systemd/system/
392 sudo systemctl daemon-reload && sudo systemctl enable --now allen-catalog.timer
393 sudo systemctl start allen-catalog.service
394
395The gateway reads `--catalog /var/lib/allen-catalog/catalog.txt --areas-file
396/var/lib/allen-catalog/areas.txt` through a read-only bind.
397
398## Deploy (Spark)
399
400```sh
401D=$HOME/.local/lib/aienos-allen-chat
402S=$HOME/.local/state/allen-chat
403install -d -m 700 "$D" "$S/spool/in" "$S/spool/status" "$S/contacts-drop" ~/.config/allen-chat
404install -m 644 scripts/allen/allen_chat.py scripts/allen/allen_spool.py scripts/allen/system-prompt.txt "$D"/
405install -m 755 om/hive-page/omc om/hive-page/irwasm "$D"/
406printf 'ALLEN_UPSTREAM_TOKEN=\n' > ~/.config/allen-chat/env && chmod 600 ~/.config/allen-chat/env
407sudo install -m 644 scripts/allen/allen-chat.service /etc/systemd/system/
408sudo systemctl daemon-reload && sudo systemctl enable --now allen-chat.service
409# firewall: admit the hub only (persisted in /etc/nftables.conf)
410sudo nft add rule inet atlas_ingress input iifname '"tailscale0"' ip saddr 100.64.0.3 tcp dport 18110 accept
411```
412
413Rollback: `sudo systemctl disable --now allen-chat.service`, delete the
41418110 rule (`sudo nft -a list chain inet atlas_ingress input`, then
415`delete rule ... handle N`) and restore `/etc/nftables.conf` from its
416`.bak-allenchat-*` copy. Nothing else on the Spark changes.
417
418## Deploy (hub nginx)
419
420Files: `nginx-allen-zones.conf` -> `/etc/nginx/conf.d/aienos-allen.conf`,
421`nginx-allen-location.conf` -> `/etc/nginx/snippets/aienos-allen.conf`
422(included in the www.aienos.com server), a second listener
423`listen 127.0.0.1:4446 ssl proxy_protocol;` in that server, and in
424`/etc/nginx/stream.d/sni-router.conf`: `proxy_protocol on;` on the :443 server,
425`aienos_web` -> 4446, and two strip shims (`listen 127.0.0.1:4453
426proxy_protocol; proxy_protocol off; proxy_pass 127.0.0.1:4443;` and the same
4274454 -> 4444) so headscale and interplane still receive plain TLS from
428127.0.0.1. Applied in two reloads (listeners first, then the switch). Backup
429and rollback: `/root/allenchat-backup-<UTC>` holds `stream.d`, `sites-*`,
430`snippets` and `conf.d` as they were; copy them back, `nginx -t`, reload.
431
432## Deploy the A2A introduction endpoint
433
434`POST /aien/api/a2a` is A2A protocol 1.0 JSON-RPC. Nginx rewrites it to
435`/allen/api/a2a`. The only method is `SendMessage`. The older name
436`message/send` is the same call. The gateway passes that message to the
437introduce door. Consent and storage are that door's: `consent` must be the
438JSON boolean `true`, the response is `Cache-Control: no-store`, and the
439JSON-RPC envelope is not written. A consented introduction is the only record,
440in the same write-only drop as `POST /aien/api/introduce`.
441
442These methods are not supported. Each one is a JSON-RPC error and stores nothing:
443
444- `SendStreamingMessage` and `SubscribeToTask`: `-32004` (streaming is off)
445- `GetTask`, `ListTasks`, and `CancelTask`: `-32004` (this door keeps no tasks)
446- `CreateTaskPushNotificationConfig`, `GetTaskPushNotificationConfig`, `ListTaskPushNotificationConfigs`, and `DeleteTaskPushNotificationConfig`: `-32003`
447- `GetExtendedAgentCard`: `-32004` (there is no extended card)
448- any other method: `-32601` Method not found
449
450Older slash names of those same methods return the same codes. `scripts/allen/a2a.py` lists them.
451
452A missing or empty `A2A-Version` is version 0.3. Spec section 3.6.2 says an empty value is 0.3, and section 3.6.1 assumes 0.3 for an empty header. This door implements 1.0 only, so that request returns `-32009` and stores nothing. Send `A2A-Version: 1.0`. When the header is absent, the query parameter `A2A-Version` is read instead.
453
454Rate-limit and daily-cap refusals stay JSON-RPC `-32603`. Spec section 3.3.2 lists "rate limit exceeded" as an example of that code. The A2A table from `-32001` to `-32009` has no rate-limit code.
455
456The location is `location = /allen/api/a2a` in `nginx-allen-location.conf`.
457`$allen_notjson` allows only `application/json`, so this location uses
458`$allen_a2a_notjson`, which also allows `application/a2a+json`.
459On the hub, after that file is installed as `/etc/nginx/snippets/aienos-allen.conf`:
460
461 sudo nginx -t
462
463Then reload:
464
465 sudo systemctl reload nginx
466
467Then check the response. This asks for `GetTask`, which is not supported, and it does not send consent:
468
469 curl -sS -D - -o /tmp/a2a-check.json -X POST https://www.aienos.com/aien/api/a2a \
470 -H 'Content-Type: application/json' \
471 -H 'A2A-Version: 1.0' \
472 --data '{"jsonrpc":"2.0","id":"deploy-check","method":"GetTask","params":{}}'
473
474Expect HTTP 200, a `Cache-Control: no-store` header, and a JSON body whose
475error code is `-32004`. Nothing is stored. Do not send a consented
476`SendMessage` as the deploy check.
477
478The same call with `Content-Type: application/a2a+json` must not be 415.
479`$allen_notjson` would refuse that media type. This location does not use it:
480
481 curl -sS -D - -o /tmp/a2a-ctype.json -X POST https://www.aienos.com/aien/api/a2a \
482 -H 'Content-Type: application/a2a+json' \
483 -H 'A2A-Version: 1.0' \
484 --data '{"jsonrpc":"2.0","id":"ctype-check","method":"GetTask","params":{}}'
485
486Expect HTTP 200, not 415, `Cache-Control: no-store`, and error code `-32004`.
487
488The same call with no `A2A-Version` header is version 0.3 and returns `-32009`:
489
490 curl -sS -D - -o /tmp/a2a-version.json -X POST https://www.aienos.com/aien/api/a2a \
491 -H 'Content-Type: application/json' \
492 --data '{"jsonrpc":"2.0","id":"version-check","method":"GetTask","params":{}}'
493
494Rollback: restore the previous snippet, run `nginx -t`, then reload.
495
496## Build loop (homes, save, publish, gallery)
497
498After the greeting Allen asks what the visitor would like to build for humanity
499and builds it with them; the result can be downloaded freely, saved to their
500home or published. Rules live in `allen_build.py` (shared with the pusher),
501routes in `allen_projects.py`:
502
503- **Home** `projects/<handle>/<project>/` in aien-dev/omega-projects. A
504 remembered visitor's handle is `<name>-<tag>`, the tag an HMAC of their
505 visitor id under `ALLEN_VISITOR_SECRET`; the gateway stores
506 `Builder handle: ...` in the visitor Cortex, so Allen recalls it. The name
507 is lowercase letters, digits and hyphens: never an email. An anonymous
508 visitor gets `anon-<tag>` and a one-time claim code (`X-Allen-Claim`), shown
509 once and never stored.
510- **Ownership** is checked server-side on every `POST projects/save|publish`:
511 the handle must be the caller's own (403 otherwise), whatever the model or
512 page sends. The pusher builds every path from the validated handle and
513 project name and its request guard refuses any tree entry outside
514 `projects/<handle>/<project>/`, any ref other than `u/...`/`p/...`, forced
515 updates, and any change to a pull request other than closing it.
516- **Files**: `index.html`, `README.md` (required: what it is and who it helps),
517 `name.om|js|css|md|txt|patch`; 64 KiB each, 256 KiB and 12 files a project;
518 no external loads in html/js/css, no secret shapes, no email in code; prose
519 is scrubbed. The pusher adds `meta.json` (no personal data).
520- **Save**: one commit on `u/<handle>` (created from main), visible on GitHub
521 at once. **Publish**: one commit on `p/<handle>/<project>` (main merged in
522 when it moved) and one pull request to main, reused while open.
523- **Drake's console** lists open publish requests with "Review and approve on
524 GitHub" and Decline (the pusher comments and closes the request); Refresh
525 rewrites the index from GitHub. **Gallery**: `GET gallery` lists merged
526 projects from main's `meta.json` files (`spool-status/index.json`).
527- **CI** in omega-projects (`.github/workflows/project-checks.yml`):
528 `pull_request` only, read-only token, no secrets, no actions; main's
529 `check_projects.py` re-checks every pull request.
530
531## Tests
532
533```sh
534python3 scripts/allen/test_sandbox.py # compile sandbox escape tests, each with a control
535python3 scripts/allen/test_a2a.py # A2A SendMessage: consent, errors, nothing stored
536python3 scripts/allen/test_gateway.py --omc om/hive-page/omc --irwasm om/hive-page/irwasm \
537 --system-prompt scripts/allen/system-prompt.txt [--skip-model --upstream 127.0.0.1:<closed port>]
538 # cookie/edge suites: console cookie flags, nginx copies' guards; NGINX=/path/to/nginx adds nginx -t
539PROBE_HOME=$HOME python3 scripts/allen/probe.py # outside; inside the unit's properties: systemd-run ... -E PROBE_HOME=$HOME
540python3 scripts/allen/relay/test_relay_mailer.py # relay mailer against a loopback SMTP stub, each with a control
541python3 scripts/allen/test_reaching_drake_prod.py # production: console reachability, one real TEST relay email, live takeover
542python3 scripts/allen/test_transcribe.py --omc om/hive-page/omc --irwasm om/hive-page/irwasm \
543 --system-prompt scripts/allen/system-prompt.txt --whisper-cli /opt/allen-chat/whisper-cli \
544 --whisper-model /opt/allen-chat/ggml-base.en.bin --sample jfk.wav # push-to-talk: formats, caps, 429/503, no file, latency
545python3 scripts/allen/test_build_loop.py --omc om/hive-page/omc --irwasm om/hive-page/irwasm \
546 --system-prompt scripts/allen/system-prompt.txt --pusher-dir scripts/allen/pusher # homes, ownership, saves, publish, console, gallery (GitHub stub)
547python3 scripts/allen/pusher/test_pusher.py # pusher against the stub; LIVE=1 adds live repository settings
548python3 scripts/allen/e2e_calculator.py ... --calc calc.om --out DIR # real omega-projects, test-labelled (needs the vault token)
549```
550
551`test_gateway.py` starts throwaway loopback gateways (never the production
552unit): input caps, Omega refusals (including the native pre-check), per-address
553429 with a control address, first-token and mid-stream timeouts against a
554stalling stub, health back-off, submit validation (project items refused, binary and
555secret-shaped text; valid control; dedupe; status URL filtering), the introduce consent gate and drop format, the output cap, and a
55610-client load test that records the peak of concurrent streams, queue
557positions and the shared server's `/health` throughout. `dev_proxy.py` serves a
558built site and forwards `/allen/api/` to a local gateway for browser tests; it
559is never deployed.