xonecas.io
7814
Ta

tiny-c-agent / files

tiny-c-agent / src / tui / commands.h

2.4 KB
1// tiny TUI commands: slash commands the editor submits.
2
3#ifndef TINY_TUI_COMMANDS_H
4#define TINY_TUI_COMMANDS_H
5
6#include <stddef.h>
7
8#include "config.h"
9#include "util.h"
10
11// The option sets a command asks the TUI to present.
12typedef enum {
13    TINY_CHOOSE_PROVIDER,
14    TINY_CHOOSE_MODEL,
15    TINY_CHOOSE_EFFORT,
16} tiny_choose;
17
18// A chooser's options: `ids` are the values applied, `labels` are shown. The
19// two lists run parallel and have equal length. Free with bl_choice_free.
20typedef struct {
21    tiny_strv ids;
22    tiny_strv labels;
23} tiny_choice;
24
25void tiny_choice_free(tiny_choice *c);
26
27// What a command may reach. The TUI provides the callbacks.
28typedef struct {
29    void *user;                              // opaque, the TUI
30    void (*write)(void *user, char *line);   // commits a styled line, taking ownership
31    void (*new_session)(void *user);         // starts a fresh session
32    // Presents `what` as a numbered list; the TUI routes the next submitted
33    // line back as the choice.
34    void (*choose)(void *user, tiny_choose what);
35    const tiny_config *cfg;                  // the live config, for listing
36    // Applies a provider/model/effort change to the running session and
37    // persists it. A NULL argument leaves that field unchanged. Returns 0, or
38    // -1 with *err set.
39    int (*apply)(void *user, const char *provider, const char *model,
40                 const char *effort, char **err);
41} tiny_command_ctx;
42
43// Builds the options a chooser presents. `provider` overrides
44// cfg->provider for TINY_CHOOSE_MODEL. Returns an empty choice when there is
45// nothing to offer.
46tiny_choice tiny_choose_list(const tiny_config *cfg, tiny_choose what,
47                             const char *provider);
48
49// The one-line heading above a chooser's options, malloc'd. `provider`
50// overrides cfg->provider for TINY_CHOOSE_MODEL, naming the provider chosen.
51char *tiny_choose_title(const tiny_config *cfg, tiny_choose what,
52                        const char *provider);
53
54typedef struct {
55    const char *name;         // no leading slash, lowercase
56    const char *description;  // one line, shown by /help
57    void (*run)(tiny_command_ctx *ctx, const char *args);
58} tiny_command;
59
60// `/name` for a known name, else NULL. `*args` receives the text after it.
61const tiny_command *tiny_find_command(const char *text, const char **args);
62
63// Tab completion for a half-typed command name; NULL leaves the draft alone.
64char *tiny_complete_command(const char *draft);
65
66#endif