aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / svc / allen_scene.h
| 1 | /* allen_scene.h -- Allen's canvas, the words side: a scene is what the model |
| 2 | * writes when it answers, a few plain lines that say WHAT Allen's screen |
| 3 | * shows, never where the pixels go. The grammar and the reasons are in |
| 4 | * docs/ALLEN_CANVAS.md; in short: |
| 5 | * |
| 6 | * mood dawn lively |
| 7 | * say Seventeen percent of 240 is 40.8. |
| 8 | * number right warm: 40.8 | 17% of 240 |
| 9 | * note left: How | 240 x 0.17 = 40.8 |
| 10 | * |
| 11 | * One line each: `mood` (the sky's tone and the water), `say` (the one |
| 12 | * sentence Allen speaks under him), and up to CK_SCENE_THINGS things placed |
| 13 | * round him: note, list, number, quote, person, timer, picture, video. Words |
| 14 | * before the first colon are how the thing is shown (where: left, right, |
| 15 | * above; how much: warm, quiet; how it comes: bloom, rise, fade; a person's |
| 16 | * message: to, from); after it, the fields, split by '|'. |
| 17 | * |
| 18 | * The parser is the kernel's guard: it reads at most CK_SCENE_BYTES bytes and |
| 19 | * CK_SCENE_LINES lines, keeps printable ASCII only, cuts every field to its |
| 20 | * room, and drops any line it does not know without a sound (it is counted, |
| 21 | * never shown). Everything lands in one fixed struct: no allocation, no |
| 22 | * pointers into the input. Integer only, freestanding; host tested and fuzzed |
| 23 | * in ui/tests/canvas_test.c. */ |
| 24 | #ifndef AIENOS_ALLEN_SCENE_H |
| 25 | #define AIENOS_ALLEN_SCENE_H |
| 26 | #include <stddef.h> |
| 27 | #include <stdint.h> |
| 28 | |
| 29 | #define CK_SCENE_BYTES 2048u /* read at most this much of a reply */ |
| 30 | #define CK_SCENE_LINES 12u /* lines that count (blank lines, fences and thinking do not) */ |
| 31 | #define CK_SCENE_THINGS 4u /* things on the screen at once: more than this is not calm */ |
| 32 | #define CK_SCENE_FIELDS 6u /* fields of one thing (a list: its title and five items) */ |
| 33 | #define CK_SCENE_TEXT 2304u /* every kept field, NUL-terminated, back to back */ |
| 34 | |
| 35 | enum { /* what a thing is */ |
| 36 | CK_THING_NOTE = 1, |
| 37 | CK_THING_LIST, |
| 38 | CK_THING_NUMBER, |
| 39 | CK_THING_QUOTE, |
| 40 | CK_THING_PERSON, |
| 41 | CK_THING_TIMER, |
| 42 | CK_THING_PICTURE, |
| 43 | CK_THING_VIDEO, |
| 44 | }; |
| 45 | enum { CK_PLACE_ANY, CK_PLACE_LEFT, CK_PLACE_RIGHT, CK_PLACE_ABOVE }; |
| 46 | enum { CK_ARRIVE_BLOOM, CK_ARRIVE_RISE, CK_ARRIVE_FADE }; |
| 47 | enum { CK_TONE_NIGHT, CK_TONE_DAWN, CK_TONE_DEEP, CK_TONE_CLEAR }; |
| 48 | enum { CK_WATER_SLOW, CK_WATER_STILL, CK_WATER_LIVELY }; |
| 49 | enum { CK_WAY_NONE, CK_WAY_TO, CK_WAY_FROM }; /* a person's message: going to them, or come from them */ |
| 50 | |
| 51 | typedef struct { |
| 52 | uint8_t kind, place, arrive, way; |
| 53 | uint8_t warm, quiet; /* emphasis: lit warm, or held back */ |
| 54 | uint8_t nf; /* fields kept */ |
| 55 | uint16_t f[CK_SCENE_FIELDS]; /* offsets into ck_scene.text */ |
| 56 | } ck_scene_thing; |
| 57 | |
| 58 | typedef struct { |
| 59 | uint8_t tone, water; |
| 60 | uint8_t has_say, nthings; |
| 61 | uint16_t say; /* offset into text */ |
| 62 | ck_scene_thing thing[CK_SCENE_THINGS]; |
| 63 | uint16_t used; |
| 64 | char text[CK_SCENE_TEXT]; |
| 65 | } ck_scene; |
| 66 | |
| 67 | /* What the parser met, for tests and for the model's report card. */ |
| 68 | typedef struct { |
| 69 | unsigned lines; /* lines that counted */ |
| 70 | unsigned kept; /* of those, understood and kept */ |
| 71 | unsigned rejected; /* not understood (unknown word first, or a thing with nothing in it): dropped */ |
| 72 | unsigned tidied; /* understood after taking off a list mark or quotes the grammar does not use */ |
| 73 | unsigned cut; /* fields cut to fit their room, or bytes outside printable ASCII left out */ |
| 74 | unsigned over; /* lines past CK_SCENE_LINES, things past CK_SCENE_THINGS, a second say or mood */ |
| 75 | unsigned unknown; /* words before the colon that are not a place, emphasis or arrival (ignored) */ |
| 76 | unsigned truncated; /* 1 when the reply was longer than CK_SCENE_BYTES */ |
| 77 | } ck_scene_stats; |
| 78 | |
| 79 | /* Reads a reply (len bytes; NUL ends it early) into s. Returns 1 when there |
| 80 | * is something to show (a say or a thing), else 0. A reply with no scene |
| 81 | * lines at all (the model answered in plain words) is not lost: its first |
| 82 | * sentences become the say, and stats->rejected counts its lines. st may be |
| 83 | * NULL. */ |
| 84 | int ck_scene_parse(const char *in, size_t len, ck_scene *s, ck_scene_stats *st); |
| 85 | /* Field i of thing t (an empty string when it has none). */ |
| 86 | const char *ck_scene_field(const ck_scene *s, const ck_scene_thing *t, unsigned i); |
| 87 | const char *ck_scene_say(const ck_scene *s); |
| 88 | /* A timer's "when" as a length of time: "25m", "1h 30m", "90 seconds", "10 min" -> ms (at most 24 h). |
| 89 | * 0 when it is not a length (a clock time like "6:00 pm" is shown as written). */ |
| 90 | uint32_t ck_scene_duration_ms(const char *when); |
| 91 | const char *ck_scene_kind_name(unsigned kind); |
| 92 | /* A clean reply as the model should write it: every counted line understood, nothing tidied or over, a say. */ |
| 93 | int ck_scene_clean(const ck_scene_stats *st, const ck_scene *s); |
| 94 | /* The courier's wire form (one line, newlines as backslash-n) back into lines, in place; returns the new length. */ |
| 95 | size_t ck_scene_unwire(char *buf, size_t len); |
| 96 | #endif |