interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / svc / allen_reply.h

110 lines · 6040 bytes Raw Blame History
1/* allen_reply.h -- Allen's local conversation on the iMac: greetings, small
2 * talk, what it is and where it lives, facts about the machine it runs on,
3 * how long it has been awake, simple arithmetic said in words, and what it
4 * has been taught: your name and short facts ("remember my favorite color is
5 * blue", then "what is my favorite color"). Lines are matched after folding
6 * case, punctuation and spacing; anything else gets an honest "not yet". No
7 * model, no network: every answer comes from the iMac alone. What Allen is
8 * taught lives in ck_allen_memory, which the kernel keeps on the iMac's own
9 * disk (svc/allen_memory.h) so it survives a restart. Pure, host tested in
10 * ui/tests/allen_ui_test.c. */
11#ifndef AIENOS_ALLEN_REPLY_H
12#define AIENOS_ALLEN_REPLY_H
13#include <stddef.h>
14#include <stdint.h>
15#include "allen_notes.h"
16
17/* What Allen knows about the machine (filled by the kernel; 0 = unknown). */
18typedef struct {
19 unsigned cores, sata_disks, nvme_disks;
20 unsigned screen_w, screen_h;
21} ck_allen_facts;
22
23#define CK_ALLEN_NAME_MAX 24u
24#define CK_ALLEN_KEY_MAX 48u
25#define CK_ALLEN_VAL_MAX 64u
26#define CK_ALLEN_FACTS_MAX 32u
27
28/* One taught fact, both halves folded (lowercase letters, digits, single
29 * spaces) and NUL-terminated: "my favorite color" / "is" / "blue". */
30typedef struct {
31 char key[CK_ALLEN_KEY_MAX];
32 char val[CK_ALLEN_VAL_MAX];
33 uint8_t are; /* taught with "are" instead of "is" */
34} ck_allen_fact;
35
36/* Everything Allen keeps across restarts. */
37typedef struct {
38 uint32_t starts; /* times Allen has woken up with this memory */
39 uint32_t lines; /* lines answered, all starts together */
40 char name[CK_ALLEN_NAME_MAX]; /* the person's name once told, "" before */
41 char self[CK_ALLEN_NAME_MAX]; /* the name the person gave Allen, "" until the first meeting names him */
42 uint32_t nfacts;
43 uint32_t nnotes; /* notes saved, deleted ones included (svc/allen_notes.h) */
44 ck_allen_fact fact[CK_ALLEN_FACTS_MAX];
45 /* sky mode (persisted across restarts) */
46 uint8_t sky_mode; /* 0=unset, 1=above_me, 2=somewhere_new */
47 uint8_t sky_region; /* next region index for somewhere_new mode */
48 uint8_t sky_have_loc; /* 1 if sky_lat_udeg/sky_lon_udeg were set */
49 uint8_t sky_pad; /* reserved, must be zero */
50 int32_t sky_lat_udeg; /* latitude, millionths of a degree */
51 int32_t sky_lon_udeg; /* east longitude, millionths of a degree */
52} ck_allen_memory;
53
54/* One conversation: the memory plus what only this session needs. */
55typedef struct {
56 ck_allen_facts facts;
57 ck_allen_memory mem;
58 int lasting; /* 1: the kernel saves mem to disk; 0: it lasts until power off */
59 int changed; /* mem changed in a way worth saving (the kernel saves, then clears) */
60 unsigned turns; /* lines answered this session */
61 int asked_how; /* Allen just asked "how are you?" */
62 int naming; /* Allen just asked "What will you call me?" (a first meeting) */
63 int far; /* 1: a far-off worker is listening (svc/courier.h): it answers first, and the
64 * answers below are only the offline fallback (goodbye, the naming, the greeting) */
65 ck_allen_notes *notes; /* the notes (the kernel loads them), NULL: none */
66 int note_dirty; /* index + 1 of a note to write to disk (the kernel writes, then clears) */
67 int lit; /* index + 1 of the note just saved or handed back, 0: none */
68 int map_changed; /* the notes or the lit one changed: redraw the map */
69 int sky_changed; /* sky_mode, location, or sky_region changed: rebuild the sky view */
70 char out[160]; /* the last composed answer */
71} ck_allen_mind;
72
73void ck_allen_mind_init(ck_allen_mind *m, const ck_allen_facts *facts);
74/* Allen's answer to one typed line (never NULL; valid until the next call).
75 * awake_s: seconds since the machine started. */
76const char *ck_allen_answer(ck_allen_mind *m, const char *line, uint64_t awake_s);
77/* A place given as coordinates ("35 north 90 west", "35.1, -90.0"): 1 and the latitude and
78 * longitude in millionths of a degree (east positive), or 0 when the line is no place. */
79int ck_allen_parse_place(const char *s, int32_t *lat_udeg, int32_t *lon_udeg);
80/* What Allen says first when the window opens: a welcome back by name when
81 * it remembers someone; on a first meeting (nothing remembered, no name of
82 * his own yet) he asks what to call him, and the next single word typed
83 * becomes his name ("call yourself Nova" or "your name is Nova" renames him
84 * any time). Never NULL. */
85const char *ck_allen_welcome(ck_allen_mind *m);
86/* The name Allen goes by: the one he was given, else "Allen". */
87const char *ck_allen_self(const ck_allen_mind *m);
88/* Stateless: the answer of a fresh conversation at 0 s awake. */
89const char *ck_allen_reply(const char *line);
90/* The answer to "goodbye" (and "bye", with or without "allen"); the caller
91 * compares the pointer to end the session. */
92extern const char ck_allen_goodbye[];
93/* What Allen says instead when a save to disk failed. */
94extern const char ck_allen_save_failed[];
95/* The honest "not yet" for a line nothing here can answer; the kernel compares
96 * the pointer to know a far-off worker may be asked (svc/allen_intent.h). */
97extern const char ck_allen_not_yet[];
98/* What Allen says when the far-off worker he was listening to falls silent
99 * mid-answer (the kernel says it after 30 s without a word). */
100extern const char ck_allen_lost_thread[];
101/* Allen keeps a note of an exchange he had through the far-off worker (what
102 * was asked, what he said; cut to fit a note): 0 and the note marked for the
103 * kernel to write (note_dirty, changed), -1 when the notebook is full or the
104 * text is empty. Pure; the kernel writes the disk. */
105int ck_allen_note_exchange(ck_allen_mind *m, const char *asked, const char *said);
106/* Folds a line for matching: lowercase letters and digits, single spaces,
107 * NUL-terminated in out (cap bytes); returns the length. */
108size_t ck_allen_fold(const char *s, char *out, size_t cap);
109
110#endif