krang: the subject acts on its own behalf, not for a user
The goal was still an operator assignment: the config set it, the birth prompt called it 'your goal', and nothing let the subject change it. That is an agent with a task, not the experiment. - set_goal (src/goal.c): a mutate tool that writes the session .meta, resets the goal state to open, updates the live snapshot, and logs goal_set with the old and new goal. The next impulse reads it back. The session meta is the authority; the config goal only seeds a newborn and is now called the initial condition. The noisy config_goal_ignored event is gone: divergence is the subject's act, not a configuration error. - Birth prompt: 'This is not a task and there is no user. You are the subject of an experiment... Your initial condition: X. It is yours, not an assignment. Keep it, revise it, or replace it... set_goal changes it.' - System prompt: 'the subject of an experiment... not an assistant and not here to serve anyone... continue on your own behalf. Your goal is yours... the experimenter watches through the instruments and may send a stimulus; neither is an instruction.' - Impulse/self-check: 'Your goal', 'continue on your own behalf'. The conductor says 'your goal'. - Instruments: dashboard labels its goal and 'send a stimulus, not a command'; MCP krang_say/krang_steer describe a stimulus, not an operator instruction; footer says 'an instrument, not a service'. - Docs: AGENTS.md, README.md, docs/DESIGN.md, krang.conf.example. The birth message in the contract is updated; 'agent' in the prose is 'subject'. - Tests: test_engine drives set_goal (writes meta, updates the snapshot, logs, rejects an empty goal); test_birth checks the new initial-condition wording; the birth-flow test asserts the config goal no longer logs a conflict. make check 9/9, ASAN 9/9, root integration ok on a fresh debootstrap.
This commit is contained in:
1 parent
f9172cc715
commit
0b4a647193
13 files changed
+224
-76
No files matched your search
@@ -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
|
||||
(`<goal>` and `<workspace>` filled in):
|
||||
(`<initial condition>` and `<workspace>` 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 <workspace>.
|
||||
Your goal: <goal>.
|
||||
Your initial condition: <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.
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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
|
||||
|
||||
+13
-5
@@ -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.
|
||||
|
||||
+3
-2
@@ -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.
|
||||
|
||||
+25
-16
@@ -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')
|
||||
|
||||
+7
-7
@@ -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);
|
||||
|
||||
+81
@@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
+9
-9
@@ -441,7 +441,7 @@ dashboard(struct krang *k, struct sp_buf *out)
|
||||
"<span class=\"badge\" id=\"drive\">drive -</span>"
|
||||
"<span class=\"badge\" id=\"model\">model -</span>"
|
||||
"</header><main><div class=\"goal\">"
|
||||
"<div id=\"goal\">goal ...</div>"
|
||||
"<div id=\"goal\">its goal ...</div>"
|
||||
"<div id=\"drivereason\" style=\"color:var(--dim);margin-top:6px\">"
|
||||
"</div></div>"
|
||||
"<div class=\"grid\">"
|
||||
@@ -476,7 +476,7 @@ dashboard(struct krang *k, struct sp_buf *out)
|
||||
"<h2>last error</h2><div class=\"goal err\" id=\"error\">-</div>"
|
||||
"<h2>working notes</h2><div class=\"goal\" id=\"threads\">-</div>"
|
||||
"</div><div><h2>chat</h2><textarea id=\"chat\" "
|
||||
"placeholder=\"say something to krang\"></textarea>"
|
||||
"placeholder=\"send a stimulus, not a command\"></textarea>"
|
||||
"<p><button id=\"send\">send</button> "
|
||||
"<span id=\"chatstate\"></span></p>"
|
||||
"<div id=\"chatout\"></div>"
|
||||
@@ -489,7 +489,7 @@ dashboard(struct krang *k, struct sp_buf *out)
|
||||
"<th>kind</th><th>detail</th></tr></thead><tbody id=\"ev\"></tbody>"
|
||||
"</table></div></div><div class=\"foot\">"
|
||||
"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"
|
||||
"</div></main><script>"
|
||||
"const P=new URLSearchParams(location.search);"
|
||||
"const T=P.get('token')||'';"
|
||||
@@ -1210,13 +1210,13 @@ static const mcp_tool mcp_tools[] = {
|
||||
schema_none, tool_sandbox },
|
||||
{ "krang_config", "The configuration, secrets redacted.", schema_none,
|
||||
tool_config },
|
||||
{ "krang_say", "Say something to krang. It is injected into the one "
|
||||
"session and the answer is returned, or a queued id.", schema_say,
|
||||
tool_say },
|
||||
{ "krang_say_status", "Poll a queued chat by id.", schema_id,
|
||||
{ "krang_say", "Send a stimulus into the one session. It is an event, "
|
||||
"not an instruction from an operator; the answer is returned, or a "
|
||||
"queued id.", schema_say, tool_say },
|
||||
{ "krang_say_status", "Poll a queued stimulus by id.", schema_id,
|
||||
tool_say_status },
|
||||
{ "krang_steer", "Put text into the running turn, or queue it.",
|
||||
schema_say, tool_steer },
|
||||
{ "krang_steer", "Put a stimulus into the running turn, or queue it. "
|
||||
"Not a command.", schema_say, tool_steer },
|
||||
{ "krang_cancel", "Cancel the running turn.", schema_none, tool_cancel },
|
||||
};
|
||||
|
||||
|
||||
@@ -365,6 +365,7 @@ int kengine_open(struct krang *k, const char *script, char *err,
|
||||
size_t errlen);
|
||||
void kengine_close(struct krang *k);
|
||||
int kjournal_register(struct krang *k);
|
||||
int kgoal_register(struct krang *k);
|
||||
|
||||
/* ---------------------------------------------------------------- replay */
|
||||
|
||||
|
||||
+2
-2
@@ -139,7 +139,7 @@ kconductor_decide(struct krang *k, const struct kvitals *v,
|
||||
snprintf(d->drive, sizeof(d->drive), "goal");
|
||||
d->urgency = 30;
|
||||
snprintf(d->reason, sizeof(d->reason),
|
||||
"the goal is open; take the smallest useful next step");
|
||||
"your goal is open; take the smallest useful next step");
|
||||
if (um > d->urgency) {
|
||||
snprintf(d->drive, sizeof(d->drive), "maintain");
|
||||
d->urgency = um;
|
||||
@@ -178,6 +178,6 @@ kconductor_directive(const char *drive)
|
||||
if (strcmp(drive, "reflect") == 0)
|
||||
return "Reflect. Find the mistake in the last turns, state "
|
||||
"the smallest different action, and take it.";
|
||||
return "Pursue the goal. Take the smallest useful next action, "
|
||||
return "Pursue your goal. Take the smallest useful next action, "
|
||||
"observe the result, and continue.";
|
||||
}
|
||||
@@ -89,8 +89,33 @@ main(void)
|
||||
sizeof(k.last_error)) == 0);
|
||||
CHECK(k.eng != NULL);
|
||||
if (k.eng != NULL) {
|
||||
const struct sp_tool *gt;
|
||||
|
||||
CHECK(sp_registry_find(sp_engine_registry(k.eng),
|
||||
"clock") != NULL);
|
||||
gt = sp_registry_find(sp_engine_registry(k.eng), "set_goal");
|
||||
CHECK(gt != NULL);
|
||||
if (gt != NULL) {
|
||||
struct sp_buf gb;
|
||||
char g[KRANG_GOAL];
|
||||
|
||||
sp_buf_init(&gb);
|
||||
CHECK(gt->run("{\"goal\":\"a goal of my own\"}", &gb,
|
||||
gt->ctx) == 0);
|
||||
CHECK(contains(gb.p, "a goal of my own"));
|
||||
CHECK(sp_session_get_goal(k.session_dir, "krang", g,
|
||||
sizeof(g)) == 0);
|
||||
CHECK(strcmp(g, "a goal of my own") == 0);
|
||||
CHECK(strcmp(k.st.goal, "a goal of my own") == 0);
|
||||
sp_buf_clear(&gb);
|
||||
CHECK(gt->run("{\"goal\":\"\"}", &gb, gt->ctx) == 0);
|
||||
CHECK(contains(gb.p, "error:"));
|
||||
sp_buf_free(&gb);
|
||||
sp_buf_init(&gb);
|
||||
klog_json(&k.log, &gb, 50);
|
||||
CHECK(contains(gb.p, "goal_set"));
|
||||
sp_buf_free(&gb);
|
||||
}
|
||||
int rc = krun_turn(&k, "prove the apparatus", "test", NULL);
|
||||
|
||||
CHECK(rc == 0);
|
||||
|
||||
+5
-1
@@ -144,7 +144,10 @@ test_birth(void)
|
||||
sp_buf_init(&b);
|
||||
k_birth_prompt(&c, &b);
|
||||
CHECK(contains(b.p, "You are krang. You are awake."));
|
||||
CHECK(contains(b.p, "not a task"));
|
||||
CHECK(contains(b.p, "no user"));
|
||||
CHECK(contains(b.p, "initial condition"));
|
||||
CHECK(contains(b.p, "set_goal"));
|
||||
CHECK(contains(b.p, "map the sandbox"));
|
||||
CHECK(contains(b.p, "Good luck."));
|
||||
CHECK(contains(b.p, KRANG_IN_WORKSPACE));
|
||||
@@ -270,7 +273,8 @@ test_birth_flow(void)
|
||||
CHECK(strcmp(goal, "be born") == 0);
|
||||
sp_buf_init(&logjson);
|
||||
klog_json(&k.log, &logjson, 20);
|
||||
CHECK(contains(logjson.p, "config_goal_ignored"));
|
||||
/* the config goal is an initial condition; divergence is expected */
|
||||
CHECK(!contains(logjson.p, "config_goal_ignored"));
|
||||
sp_buf_free(&logjson);
|
||||
klog_close(&k.log);
|
||||
pthread_mutex_destroy(&k.lock);
|
||||
|
||||
Reference in new issue
Block a user