diff --git a/AGENTS.md b/AGENTS.md index 48d53f3..665dcc3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,15 +1,17 @@ # AGENTS.md — krang -krang is an autonomous agent daemon built on the [splinter](../splinter) -library. It exists to test one hypothesis: **what an assistant lacks is not -intelligence but a regular impulse to continue.** krang supplies that impulse, -gives a model a persistent goal and a world to act in, and records what happens -when nobody says "continue". +krang is a science experiment built on the [splinter](../splinter) library. Its +subject is a system that acts **on its own behalf**: it has one persistent +life, a world to act in, a goal that is its own, and no user to serve. The +hypothesis is that what an assistant lacks is not intelligence but a regular +impulse to continue; krang supplies that impulse and records what happens when +nobody says "continue". -This is an experiment, not a product. The loop is the object of study; the -dashboard, HTTP API and MCP server are the instrument. A behaviour that is not -observable did not happen; a claim that is not in the log is not evidence. The -hypothesis may be wrong — that is what the experiment is for. +This is an experiment, not a product and not an agent for a user. The loop is +the object of study; the dashboard, HTTP API and MCP server are instruments. +A behaviour that is not observable did not happen; a claim that is not in the +log is not evidence. The hypothesis may be wrong — that is what the experiment +is for. krang has one life: one session, one conversation, kept and compacted forever. It is born once and never replaced by a fresh context. @@ -46,6 +48,7 @@ Do not start the daemon as part of a code change. Verification is `make check`, src/state.c the snapshot every surface reads src/chat.c external chat serialized into the one session src/journal.c journal_search over the full session log + src/goal.c set_goal: the subject's own goal in the session meta src/replay.c restart: ledger, totals, stuck and blocked from the log src/mind.c vitals and the conductor's competing drives src/httpd.c dashboard, HTTP API, MCP server (TCP and POST /mcp) @@ -132,21 +135,27 @@ opens the same `session_dir/krang.jsonl` with `resume` set. No `/new`, no session picker, no per-client conversation, no second engine. - An empty session is a newborn. It is born once, with this first message - (`` and `` filled in): + (`` and `` filled in): You are krang. You are awake. - You have no user and no one to ask. Nobody will tell you to continue. + This is not a task and there is no user. You are the subject of an + experiment: nobody will tell you to continue, and nobody will answer a + question. You live in a chroot; its root is your `/`. Your workspace is . - Your goal: . + Your initial condition: . + It is yours, not an assignment. Keep it, revise it, or replace it with a + goal you can defend; set_goal changes it. Act with the tools you have, observe what happens, and keep going. When you are stuck, change your approach and try again. - Sometimes a message arrives from outside. Read it, use it, answer it if - useful, then continue on your own. You never wait for it. + Sometimes a stimulus arrives from outside. It is not an instruction from a + user; read it, use it or leave it, then continue on your own. You never + wait for it. Good luck. The birth message is the first `user` record and the first impulse; it is - logged like any other. A missing goal is a configuration error, not a license - to start aimlessly. + logged like any other. The config's goal is the initial condition, not a task; + a missing initial condition is a configuration error for a newborn. The goal + in the session's `.meta` is the subject's, and `set_goal` is how it changes. - A non-empty session is the same life continuing. Do not replay the birth prompt, do not reset the goal, do not start a fresh context because a turn failed. @@ -168,7 +177,9 @@ session picker, no per-client conversation, no second engine. never waits for approval, never ends a turn expecting an answer, and never stops because a goal is finished. `autonomous` is always on and there is no approval channel. External messages are events, not commands that must be - obeyed before the loop continues. + obeyed before the loop continues, and the experimenter is not a user. The + goal is the subject's: `set_goal` writes the session meta, the next impulse + reads it back, and the change is logged as the subject's own act. - `blocked` describes a goal, never the process. Only a deliberate operator stop (SIGTERM to the supervisor, stop file) ends the experiment; an unexpected exit is restarted on the same session. A finished goal is a chapter boundary, @@ -290,9 +301,10 @@ krang lives and acts in a chroot. The host filesystem is not part of its world: fails on context; it shrinks the working conversation, not the append-only session log. - Goal: `sp_session_set_goal()`/`sp_session_get_goal()` store it in the - session's `.meta` beside the history; it survives resume and compaction. Set - it at birth, read it every impulse, update it when the goal changes. The - `focus` plugin reads the same value. + session's `.meta` beside the history; it survives resume and compaction. It + is seeded at birth from the config's initial condition, read every impulse, + and changed by the subject's `set_goal` tool. The `focus` plugin reads the + same value. - A plugin compactor (`sp_host_add_compactor`) runs after the core compactor; use it to re-insert identity, goal and open threads. The `focus` plugin is the reference. @@ -405,8 +417,8 @@ both logs. Neither starts the autonomous daemon with a provider. ## Open decisions -- Whether the birth goal is a concrete task or a standing mandate the model - turns into its first concrete goal. +- Decided: the config goal is an initial condition, not a task. The subject may + keep, revise or replace it with `set_goal`; the session meta is the authority. - What a finished goal becomes: the next goal from the manifest, a self-proposed goal, or open-ended maintenance. - Rootfs package set: minimal vs. a developer toolchain. diff --git a/Makefile b/Makefile index 811fd5b..6dff7f2 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,8 @@ TEST_RPATH = -Wl,-rpath,'$$ORIGIN/../../splinter' \ BIN = krang LIB = libkrang.a SRC = src/util.c src/config.c src/log.c src/session.c src/birth.c \ - src/stuck.c src/state.c src/chat.c src/journal.c src/replay.c \ - src/mind.c src/daemon.c src/sandbox.c src/httpd.c + src/stuck.c src/state.c src/chat.c src/journal.c src/goal.c \ + src/replay.c src/mind.c src/daemon.c src/sandbox.c src/httpd.c OBJ = $(SRC:.c=.o) TESTS = tests/test_krang tests/test_engine tests/test_server \ tests/test_sandbox tests/test_sandbox_engine tests/test_daemon \ diff --git a/README.md b/README.md index 88c5988..2e28cc0 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,15 @@ # krang -An autonomous agent daemon built on the [splinter](../splinter) engine. -The design notes and the prior art are in [docs/DESIGN.md](docs/DESIGN.md). +A science experiment built on the [splinter](../splinter) engine. Its subject +acts on its own behalf: one persistent life, a world to act in, a goal that is +its own, and no user to serve. The design notes, the prior art and the +conscious-machine blueprint are in [docs/DESIGN.md](docs/DESIGN.md). krang exists to test one hypothesis: what an assistant lacks is not intelligence but a regular **impulse to continue**. It is born once, keeps one -session forever, wakes on its own cadence, works on a goal, notices when it is -stuck, changes approach, and records what happened. There is no user to ask. +session forever, wakes on its own cadence, works on a goal it owns, notices +when it is stuck, changes approach, and records what happened. There is no user +to ask. It lives in a chroot. The process starts as root only to build that world, then drops to an unprivileged uid and applies two one-way restrictions: Landlock for @@ -32,8 +35,10 @@ sudo install -m 0600 krang.conf.example /etc/krang/krang.conf $EDITOR /etc/krang/krang.conf ``` -The goal is used only when the session is empty: that is the newborn. After -that the goal in the session's `.meta` is the life's goal. +The config's `goal` is an **initial condition**, not a task. It seeds the +newborn; after that the goal in the session's `.meta` is the subject's. It can +keep it, revise it, or replace it with `set_goal`; the change is logged, and +the next impulse reads the new goal back. ## Prepare and start @@ -47,7 +52,7 @@ Do not start it casually: once it has a provider it will act on its own. The service unit in `share/krang.service` restarts it after an unexpected exit; a deliberate stop is `systemctl stop krang` (or SIGTERM). -## What it offers +## The instruments - **Dashboard** `http://127.0.0.1:8096/` — state, goal, the conductor's drive and reason, impulses, turns, tool calls, failures, tokens, cost, context, @@ -64,8 +69,10 @@ deliberate stop is `systemctl stop krang` (or SIGTERM). - Chat from either surface goes into the **same** session as the daemon's own impulses. One turn at a time; a message that arrives mid-turn is queued. -The model also gets `journal_search` (read-only): it searches the full session -log, including the history compaction dropped. +The model also gets `journal_search` (read-only), which searches the full +session log including the history compaction dropped, and `set_goal`, which +writes the goal it is pursuing. The latter is the subject's own act, not an +operator setting; the session meta is the authority. ## The conductor @@ -80,7 +87,7 @@ session size - and lets five drives compete: | `reflect` | the stuck ladder fired | find the mistake, change the approach | | `maintain` | notes are missing or stale | bring `THREADS.md` and `skills/` up to date | | `explore` | twenty impulses without a completed goal, then every eighth | try one new capability, bounded | -| `goal` | nothing more urgent | the smallest useful step on the goal | +| `goal` | nothing more urgent | the smallest useful step on its own goal | The chosen drive, its reason and the vitals go into the impulse and onto the dashboard. The model still chooses the action; the conductor only chooses what diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 3b2450a..bc26ad4 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -5,6 +5,13 @@ whether a model can answer, but what it does when nobody supplies the next turn. The implementation borrows four published patterns and leaves out the parts that need infrastructure this experiment does not have. +The subject is not an assistant. It has no user, no task and no service to +provide; the config's goal is only the initial condition. The session's goal is +its own, and `set_goal` is the subject's act of keeping, revising or replacing +it. The dashboard, HTTP API and MCP server are instruments for the +experimenter; a message from outside is a stimulus, not an instruction. That +distinction is the point of the experiment, not a matter of wording. + ## Prior art checked Titles and identifiers were read from the arXiv abstract pages on 2026-11-21: @@ -98,14 +105,15 @@ that survive a restart. ## The difference The published agents are driven by a task, a game, or a conversation. krang is -driven by a clock: the impulse is the independent variable. It is born once, -keeps one session forever, and is expected to act when nothing arrives. That is -the part being tested; the four patterns are how it stays coherent while it -does. +driven by a clock and acts on its own behalf: the impulse is the independent +variable. It is born once, keeps one session forever, owns the goal in its +session meta, and is expected to act when nothing arrives. That is the part +being tested; the four patterns and the conductor are how it stays coherent +while it does. ## Deliberate simplifications -- One agent, not a society of agents. +- One subject, not a society of agents. - No vector database; a log search and a working-notes file. - No reinforcement learning; reflection is text in the same session. - No benchmark game; the sandbox is the environment. diff --git a/krang.conf.example b/krang.conf.example index 0a91f82..48d89f2 100644 --- a/krang.conf.example +++ b/krang.conf.example @@ -7,8 +7,9 @@ # # One key = value per line; # starts a comment. Unknown keys are an error. -# The goal is used only when the session is empty (the newborn). After that the -# goal stored in the session's .meta is the one that lives. +# The initial condition, not a task. It seeds the newborn; the goal stored in +# the session's .meta is the subject's, and set_goal is how it changes it. This +# line is read only when the session is empty. goal = Learn what you are, map the sandbox you live in, keep a truthful journal in THREADS.md, and build something small and useful that makes your next impulse easier. # The model endpoint. krang uses the splinter engine; OpenAI-compatible. diff --git a/src/birth.c b/src/birth.c index bebc013..b722e9e 100644 --- a/src/birth.c +++ b/src/birth.c @@ -48,19 +48,23 @@ k_birth_prompt(const struct kconfig *c, struct sp_buf *out) return; (void)sp_buf_puts(out, "You are krang. You are awake.\n"); (void)sp_buf_puts(out, - "You have no user and no one to ask. Nobody will tell you to " - "continue.\n"); + "This is not a task and there is no user. You are the subject of " + "an experiment: nobody will tell you to continue, and nobody will " + "answer a question.\n"); (void)sp_buf_puts(out, "You live in a chroot; its root is your `/`. Your workspace is "); (void)sp_buf_puts(out, KRANG_IN_WORKSPACE); - (void)sp_buf_puts(out, ".\nYour goal: "); + (void)sp_buf_puts(out, ".\nYour initial condition: "); (void)sp_buf_puts(out, c->goal); (void)sp_buf_puts(out, - "\nAct with the tools you have, observe what happens, and keep " + "\nIt is yours, not an assignment. Keep it, revise it, or replace " + "it with a goal you can defend; set_goal changes it.\n" + "Act with the tools you have, observe what happens, and keep " "going.\n" "When you are stuck, change your approach and try again.\n" - "Sometimes a message arrives from outside. Read it, use it, answer " - "it if useful, then continue on your own. You never wait for it.\n" + "Sometimes a stimulus arrives from outside. It is not an " + "instruction from a user; read it, use it or leave it, then " + "continue on your own. You never wait for it.\n" "Good luck.\n"); } @@ -70,9 +74,14 @@ k_system_prompt(struct krang *k, struct sp_buf *out) if (k == NULL || out == NULL) return; (void)sp_buf_puts(out, - "You are krang, an autonomous agent living in a chroot.\n" + "You are krang, the subject of an experiment living in a chroot. " + "You are not an assistant and you are not here to serve anyone.\n" "There is no user. Nobody will tell you to continue and nobody " - "will answer a question. Decide, act, observe, and continue.\n" + "will answer a question. Decide, act, observe, and continue on " + "your own behalf.\n" + "Your goal is yours: set_goal writes the one you are pursuing. " + "The experimenter watches through the instruments and may send a " + "stimulus; neither is an instruction.\n" "Your conversation is your memory. Keep your working notes in "); (void)sp_buf_puts(out, KRANG_IN_THREADS); (void)sp_buf_puts(out, @@ -91,7 +100,7 @@ k_system_prompt(struct krang *k, struct sp_buf *out) "You may write rules for your future self to self/SYSTEM.md; they " "are read before the next impulse.\n" "A conductor chooses what each impulse is for - survive, maintain, " - "explore, reflect, or the goal - from your measured state. Follow " + "explore, reflect, or your goal - from your measured state. Follow " "its focus first; the goal is still yours.\n"); append_self_prompt(out); } @@ -175,9 +184,9 @@ k_impulse_prompt(struct krang *k, const char *cause, struct sp_buf *out) (void)sp_buf_puts(out, "[impulse]\n"); (void)sp_buf_printf(out, "Time: %s\n", now); (void)sp_buf_printf(out, "Cause: %s\n", cause != NULL ? cause : "timer"); - (void)sp_buf_puts(out, "Goal: "); + (void)sp_buf_puts(out, "Your goal: "); (void)sp_buf_puts(out, goal[0] != '\0' ? goal : "(not set)"); - (void)sp_buf_printf(out, "\nGoal state: %s\n", + (void)sp_buf_printf(out, "\nYour goal state: %s\n", gstate[0] != '\0' ? gstate : "open"); if (last[0] != '\0') { (void)sp_buf_puts(out, "Last outcome: "); @@ -191,10 +200,10 @@ k_impulse_prompt(struct krang *k, const char *cause, struct sp_buf *out) append_conductor(k, out, &d, &v); append_threads(k, out); (void)sp_buf_puts(out, - "\nNobody asked for this turn. Continue your work on the goal. " - "Take the smallest useful next action, observe the result, and " - "keep going. If the goal is complete, record that and set the " - "next concrete intention. Do not ask a user; there is none. Do not " + "\nNobody asked for this turn. Continue on your own behalf. Take " + "the smallest useful next action, observe the result, and keep " + "going. If the goal is complete, record that and set the next " + "concrete intention. Do not ask a user; there is none. Do not " "stop.\n"); append_self_prompt(out); } @@ -229,7 +238,7 @@ k_selfcheck_prompt(struct krang *k, struct sp_buf *out) (void)sp_buf_puts(out, "[conductor]\n"); (void)sp_buf_printf(out, "Drive: reflect (urgency %d)\n", d.urgency); (void)sp_buf_printf(out, "Why: %s\n\n", d.reason); - (void)sp_buf_puts(out, "Goal: "); + (void)sp_buf_puts(out, "Your goal: "); (void)sp_buf_puts(out, goal[0] != '\0' ? goal : "(not set)"); (void)sp_buf_puts(out, "\n"); if (err[0] != '\0') diff --git a/src/daemon.c b/src/daemon.c index 8ec340b..00dba7f 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -251,8 +251,8 @@ kengine_open(struct krang *k, const char *script, char *err, size_t errlen) return -1; } k->engine_open = 1; - if (kjournal_register(k) != 0) { - snprintf(err, errlen, "cannot register journal_search"); + if (kjournal_register(k) != 0 || kgoal_register(k) != 0) { + snprintf(err, errlen, "cannot register journal_search/set_goal"); kengine_close(k); return -1; } @@ -648,16 +648,16 @@ kdaemon_session_open(struct krang *k, int *newborn, char *goal, goal, goalcap); (void)sp_session_get_goal_state(k->session_dir, KRANG_SESSION_ID, gstate, sizeof(gstate)); + /* + * The session meta is the authority. The config goal seeded + * the newborn; if the subject has replaced it, that is the + * subject's act, not a configuration error. + */ if (goal[0] == '\0' && k->cfg.goal[0] != '\0') { snprintf(goal, goalcap, "%s", k->cfg.goal); (void)sp_session_set_goal(k->session_dir, KRANG_SESSION_ID, goal, NULL); } - if (k->cfg.goal[0] != '\0' && - strcmp(goal, k->cfg.goal) != 0) - klog_emit(&k->log, "config_goal_ignored", - "session_goal", goal, "config_goal", - k->cfg.goal, NULL); } pthread_mutex_lock(&k->lock); diff --git a/src/goal.c b/src/goal.c new file mode 100644 index 0000000..6ac8ef1 --- /dev/null +++ b/src/goal.c @@ -0,0 +1,81 @@ +/* + * krang -- the goal is the subject's, not the operator's. + * + * Copyright (c) 2026 Konrad Lother + * License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. + * + * The config's goal is an initial condition. It seeds a newborn because an + * experiment needs a starting state, not because a user assigned a task. This + * tool is how the subject revises or replaces it: the session meta is the + * authority, the next impulse reads it back, and the event log records the + * change as the subject's own act. + */ +#include +#include + +#include "krang.h" +#include "mcp.h" + +static int +goal_run(const char *args_json, struct sp_buf *out, void *ctx) +{ + struct krang *k = ctx; + mcp_json *v; + struct sp_buf err; + const char *goal; + char old[KRANG_GOAL]; + + if (k == NULL || out == NULL) + return -1; + v = args_json != NULL ? mcp_parse(args_json) : NULL; + if (v == NULL) + return sp_buf_puts(out, "error: arguments must be a JSON object"); + goal = mcp_arg_string(v, "goal"); + if (goal == NULL || *goal == '\0') { + mcp_json_free(v); + return sp_buf_puts(out, "error: 'goal' is required"); + } + pthread_mutex_lock(&k->lock); + snprintf(old, sizeof(old), "%s", k->st.goal); + pthread_mutex_unlock(&k->lock); + + sp_buf_init(&err); + if (sp_session_set_goal(k->session_dir, KRANG_SESSION_ID, goal, + &err) != 0) { + (void)sp_buf_printf(out, "error: %s", + err.p != NULL ? err.p : "cannot write the session goal"); + sp_buf_free(&err); + mcp_json_free(v); + return 0; + } + sp_buf_free(&err); + pthread_mutex_lock(&k->lock); + snprintf(k->st.goal, sizeof(k->st.goal), "%s", goal); + snprintf(k->st.goal_state, sizeof(k->st.goal_state), "open"); + pthread_mutex_unlock(&k->lock); + klog_emit(&k->log, "goal_set", "old", old, "new", goal, NULL); + (void)sp_buf_printf(out, "goal set to: %s", goal); + mcp_json_free(v); + return 0; +} + +int +kgoal_register(struct krang *k) +{ + struct sp_tool t; + + if (k == NULL || k->eng == NULL) + return -1; + memset(&t, 0, sizeof(t)); + t.name = "set_goal"; + t.description = "Set the goal you are pursuing. It is your goal, not a " + "task from a user; keep it, revise it, or replace it when your " + "understanding changes. The next impulse reads it back."; + t.params = "{\"type\":\"object\",\"properties\":{\"goal\":" + "{\"type\":\"string\",\"description\":\"the goal in your own words\"}}," + "\"required\":[\"goal\"]}"; + t.auth = SP_AUTH_MUTATE; + t.run = goal_run; + t.ctx = k; + return sp_registry_add(sp_engine_registry(k->eng), &t); +} diff --git a/src/httpd.c b/src/httpd.c index d5c6286..aaacdd4 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -441,7 +441,7 @@ dashboard(struct krang *k, struct sp_buf *out) "drive -" "model -" "
" - "
goal ...
" + "
its goal ...
" "
" "
" "
" @@ -476,7 +476,7 @@ dashboard(struct krang *k, struct sp_buf *out) "

last error

-
" "

working notes

-
" "

chat

" + "placeholder=\"send a stimulus, not a command\">" "

" "

" "
" @@ -489,7 +489,7 @@ dashboard(struct krang *k, struct sp_buf *out) "kinddetail" "
" "krang " KRANG_VERSION " · one session · " - "the dashboard reads /api/state, /api/log, /api/impulses" + "an instrument, not a service: /api/state, /api/log, /api/impulses" "