Konrad, 24.11.: "v1 geht durch ohne irgendwas. ich will auch keine approvals generell. ich will nur das der user mit ask nach sachen gefragt werden kann." Removed the whole approval apparatus, not just the prompt: - agent.c: the decision point (sp_host_gate/approve callbacks), the pause/resume path (has_pending, pending_from, sp_agent_resume), ack_approval, ask_operator and the ack stdin thread are gone. A tool runs; its exit status is the observation. sp_tool_policy (allow/deny per profile) stays - that is the operator's own configuration, not a question to the operator. - engine.c: SP_EV_APPROVAL, sp_engine_approve, the approve_pending condition variable and the `approval`/`approve` protocol commands are gone. - openai_server.c: the v1 endpoint runs gw_* tools without a gate; the autonomous flag is no longer part of sp_gateway_opts. - a2aserver.c: INPUT_REQUIRED and the resume-by-taskId path are gone; CancelTask stays. An A2A caller has no operator sitting in front of a prompt. - mcpserver.c: --autonomous no longer gates mutating tools; the flag and the config key are accepted for compatibility and documented as changing nothing. - telegram.c: tg_approve and the approval callback are gone; ask is the only dialog, and /cancel inside it still ends the turn. - front ends: protocol.c, curses.c, ui_local.c, ui_remote.c, client.c lose the approval event and the waiting flag. - ack.c stays: it is a plugin API (plugins/kids asks its parent through it), not splinter's own gate. --ack is documented as such. Tests: test_pause.c guarded the pause and now guards the opposite (a mutate and a destructive tool run, nothing is asked). test_a2a_input.sh, test_protocol.sh, test_ui.sh, test_agents_ui.sh, test_gateway.sh, test_gateway_openai.sh, test_agent.c and test_mcpsession.sh were rewritten the same way; splinter_approve must now be absent from the MCP tool list. Every rewritten test was run red against the old behaviour where that was possible. make check: all tests passed (428 s) make check-asan: all 47 test binaries clean make check-tsan: all 47 test binaries free of data races
135 lines
4.9 KiB
C
135 lines
4.9 KiB
C
/*
|
|
* splinter -- what the curses front end needs from a backend.
|
|
*
|
|
* Copyright (c) 2026 Konrad Lother
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*
|
|
* The screen does not know whether the engine runs in this process or behind
|
|
* a socket. It calls these operations, and two implementations fill them in:
|
|
*
|
|
* sp_ui_backend_engine() the engine linked into this binary (--chat)
|
|
* sp_ui_backend_remote() a `splinter --serve` reached over a Unix socket
|
|
* (--attach), speaking docs/PROTOCOL.md
|
|
*
|
|
* The split exists so `--attach` proves the socket protocol is complete: a
|
|
* front end that works locally must work remotely, or the protocol is missing
|
|
* something.
|
|
*/
|
|
#ifndef SPLINTER_UI_BACKEND_H
|
|
#define SPLINTER_UI_BACKEND_H
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "splinter.h"
|
|
#include "splinter_engine.h"
|
|
|
|
struct sp_buf;
|
|
struct sp_conv;
|
|
struct sp_host;
|
|
struct swarm;
|
|
|
|
struct ui_backend {
|
|
void *ctx;
|
|
|
|
/* the operator's line: SP_INPUT_PROMPT/HANDLED/SUBMIT + the reply */
|
|
int (*input)(void *ctx, const char *line, struct sp_buf *out);
|
|
|
|
/* turns */
|
|
int (*submit)(void *ctx, const char *text);
|
|
int (*busy)(void *ctx);
|
|
int (*wait)(void *ctx);
|
|
int (*cancel)(void *ctx);
|
|
int (*steer)(void *ctx, const char *text);
|
|
/* a steer that arrived after the turn's last step boundary */
|
|
int (*take_steer)(void *ctx, struct sp_buf *out);
|
|
|
|
/*
|
|
* The question the `ask` tool is parked on: the text and its options,
|
|
* and the answer the front end gives back. A backend without a dialog
|
|
* asks the same text as a line; the answer is free text either way.
|
|
*/
|
|
int (*ask)(void *ctx, char *text, size_t textlen,
|
|
char (*opts)[SP_ASK_OPT_LEN], size_t max, size_t *nopts);
|
|
int (*answer)(void *ctx, const char *text);
|
|
|
|
/* the event queue */
|
|
int (*poll)(void *ctx, struct sp_event *out);
|
|
void (*event_free)(void *ctx, struct sp_event *ev);
|
|
|
|
/* state and profiles */
|
|
int (*state)(void *ctx, struct sp_engine_state *out);
|
|
int (*agents)(void *ctx);
|
|
const char *(*agent_name)(void *ctx, int idx);
|
|
int (*agent_cur)(void *ctx);
|
|
int (*agent_switch)(void *ctx, int idx);
|
|
int (*command_names)(void *ctx, char (*names)[64], int max);
|
|
/* the choices /model takes; cb per entry: selector, label, current */
|
|
int (*models)(void *ctx,
|
|
void (*cb)(void *cbctx, const char *sel, const char *label,
|
|
int current), void *cbctx);
|
|
/*
|
|
* The same for the models the serving endpoint reports it has. Network;
|
|
* NULL when the backend cannot ask (then the picker stays config-only).
|
|
*/
|
|
int (*served)(void *ctx,
|
|
void (*cb)(void *cbctx, const char *sel, const char *label,
|
|
int current), void *cbctx);
|
|
/* the sessions in this backend's directory; cb per entry */
|
|
int (*sessions)(void *ctx,
|
|
void (*cb)(void *cbctx, const char *id, const char *title,
|
|
int current, long mtime), void *cbctx);
|
|
/*
|
|
* The sources the picker offers: the backend's own sessions plus every
|
|
* foreign store that has some. cb gets a name ("splinter", "claude", ...)
|
|
* and the number of sessions in it.
|
|
*/
|
|
int (*sources)(void *ctx,
|
|
void (*cb)(void *cbctx, const char *name, int count),
|
|
void *cbctx);
|
|
/*
|
|
* The sessions of one source, for the second stage of the picker. A
|
|
* row from a foreign source has an id of the form "claude:<id>", which
|
|
* open_session imports and continues; a plain id is this backend's own.
|
|
*/
|
|
int (*source_sessions)(void *ctx, const char *source,
|
|
void (*cb)(void *cbctx, const char *id, const char *title,
|
|
int current, long mtime), void *cbctx);
|
|
/* switch to another session; the backend replaces its engine */
|
|
int (*open_session)(void *ctx, const char *id, struct sp_buf *err);
|
|
/* the transcript so far, one callback per message (no system prompt) */
|
|
int (*history)(void *ctx,
|
|
void (*cb)(void *cbctx, const char *role, const char *text),
|
|
void *cbctx);
|
|
struct sp_host *(*host)(void *ctx);
|
|
struct swarm *(*swarm)(void *ctx);
|
|
struct sp_config *(*config)(void *ctx);
|
|
const char *(*session_id)(void *ctx);
|
|
const char *(*state_dir)(void *ctx);
|
|
void (*set_theme)(void *ctx, const char *theme);
|
|
int (*quit)(void *ctx);
|
|
|
|
/* 1 when the engine is this process's (history files are local, then) */
|
|
int (*local)(void *ctx);
|
|
|
|
void (*close)(void *ctx);
|
|
};
|
|
|
|
/*
|
|
* The in-process backend. `eng` is a pointer to the caller's engine: a session
|
|
* switch replaces the engine behind it. `opts` is the template a switched-to
|
|
* engine is built from and must outlive the backend. The caller still owns the
|
|
* engine and closes it; close is a no-op.
|
|
*/
|
|
const struct ui_backend *sp_ui_backend_engine(struct sp_engine **eng,
|
|
const struct sp_engine_opts *opts);
|
|
|
|
/*
|
|
* Connect to a served engine and read the greeting. NULL with `err` filled
|
|
* when the socket is not there or answers garbage. The caller must call
|
|
* sp_ui_run() and that closes the backend.
|
|
*/
|
|
const struct ui_backend *sp_ui_backend_remote(const char *socket_path,
|
|
struct sp_buf *err);
|
|
|
|
#endif /* SPLINTER_UI_BACKEND_H */
|