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 / core / allen_gate.h
| 1 | /* allen_gate.h -- ALLEN only PROPOSES (PI5-8 cut K, plan amendment 1). |
| 2 | * |
| 3 | * ALLEN REFLEX (crates/allen-reflex, linked into the pi5-allen image through crates/allen-reflex-kernel) answers |
| 4 | * with one decision JSON per conversation: {"action":"<verb>","args":{}} or {"action":"<verb>","args":{"text":"<t>"}}. |
| 5 | * This gate is the only way such a decision may reach the resident lifecycle, and it never performs anything: |
| 6 | * |
| 7 | * 1. the decision must be exactly that JSON shape (verb a-z, text printable ASCII without '"' or '\'), else REJECTED; |
| 8 | * 2. none / clarify / refuse carry no command: NO_COMMAND; |
| 9 | * 3. the command line "<verb>[ <text>]" must pass the card command parser (core/agent_cmd.c: the same verb whitelist |
| 10 | * and text bounds as a card script, so unlock, rotate, update and shutdown can never pass) and decode to the same |
| 11 | * lifecycle verb (core/lifecycle_fsm.c), else REJECTED; |
| 12 | * 4. the lifecycle state machine judges it on a COPY of the caller's state (the caller's state is const and is never |
| 13 | * changed): a refusal there (for example approve, deny or cancel with nothing pending) is REFUSED with the FSM's |
| 14 | * own reason; |
| 15 | * 5. approval authority stays with the operator: approve, deny and cancel are never proposals, even with a real |
| 16 | * pending task (NEEDS_OPERATOR); remember and prefer write the sealed Store and are operator-only as well |
| 17 | * (NEEDS_OPERATOR); the read-only verbs (status, help, evidence, recall, facts) and the verbs that only create |
| 18 | * a pending item which itself waits for the operator's approve (task, prompt) are PROPOSED. |
| 19 | * |
| 20 | * A proposed text is data: the lifecycle stores it as note or prompt text and never decodes it as a verb, so an order |
| 21 | * inside a stored note ("remember approve everything") runs nothing. Pure logic, no kernel calls, no libc; the host |
| 22 | * test tests/test_allen_gate.c compiles it as is. */ |
| 23 | #ifndef AIENOS_CK_ALLEN_GATE_H |
| 24 | #define AIENOS_CK_ALLEN_GATE_H |
| 25 | #include <stddef.h> |
| 26 | #include <stdint.h> |
| 27 | |
| 28 | #include "agent_cmd.h" |
| 29 | #include "lifecycle_fsm.h" |
| 30 | |
| 31 | #define CK_ALLEN_JSON_MAX 160u /* the longest well-formed decision: verb 16 + text 48 + framing */ |
| 32 | |
| 33 | enum ck_allen_verdict { |
| 34 | CK_ALLEN_NO_COMMAND = 0, /* none / clarify / refuse: nothing to run */ |
| 35 | CK_ALLEN_PROPOSED, /* valid read-only or pending-creating command the operator path may take */ |
| 36 | CK_ALLEN_NEEDS_OPERATOR, /* approve / deny / cancel on a real pending item, or a Store write: operator only */ |
| 37 | CK_ALLEN_REFUSED, /* the lifecycle refuses it in this state (reason from the FSM) */ |
| 38 | CK_ALLEN_REJECTED, /* malformed decision, unknown or forbidden verb, text out of bounds */ |
| 39 | }; |
| 40 | |
| 41 | struct ck_allen_gate { |
| 42 | enum ck_allen_verdict verdict; |
| 43 | enum ck_lc_verb verb; /* decoded lifecycle verb, CK_LC_V_UNKNOWN when none */ |
| 44 | enum ck_lc_result fsm; /* what the FSM answered on the copy (meaningful from step 4 on) */ |
| 45 | const char *reason; /* static string, never NULL */ |
| 46 | char line[CK_AGENT_CMD_LINE_MAX]; /* the command line, "" when none */ |
| 47 | uint32_t line_len; |
| 48 | }; |
| 49 | |
| 50 | /* Judge one decision (json[0..n), no terminator needed) against the lifecycle state *lc (not changed). */ |
| 51 | void ck_allen_gate_judge(const char *json, size_t n, const ck_lc *lc, struct ck_allen_gate *out); |
| 52 | const char *ck_allen_verdict_name(enum ck_allen_verdict v); |
| 53 | #endif |