summaryrefslogtreecommitdiffstats
path: root/src/goal.h
blob: 6ef823d75a09034d20223868273aba275400b4bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef LLSH_GOAL_H
#define LLSH_GOAL_H

#include "util.h"

/* Pure helpers for the /goal goal-based loop (mirrors goal.rs): parse the
 * command, build each attempt's prompt, parse the evaluator's verdict.
 * Side-effect free; the evaluator's model call lives in the session and the
 * iteration loop in main. */

#define GOAL_DEFAULT_MAX_TRIES 5UL

/* Parsed /goal command: success criteria + attempt cap. */
typedef struct {
    char *criteria; /* owned */
    unsigned long max_tries;
} goal_spec;

/* Evaluator's judgment of a single attempt. reason is owned. */
typedef struct {
    bool met;
    char *reason;
} goal_verdict;

/* Summary of a finished /goal run. criteria is owned. */
typedef struct {
    char *criteria;
    unsigned long max_tries;
    unsigned long turns_done;
    unsigned long long tokens_used;
    bool met;
} goal_report;

void goal_spec_free(goal_spec *s);
void goal_report_free(goal_report *r);

/* System preamble for the tool-less goal evaluator. */
const char *goal_evaluator_preamble(void);

/* Parse "<criteria>[, stop after <N> tries]".
 * Returns 1 on success (fills *out), 0 on failure (*err set, caller frees). */
int goal_parse(const char *input, goal_spec *out, char **err);

/* Prompt for a goal attempt (attempt starts at 1; feedback may be NULL).
 * Caller frees. */
char *goal_prompt(const goal_spec *spec, unsigned long attempt,
                  const char *feedback);

/* Parse the evaluator's reply into a verdict (conservative: met only when
 * MET appears and NOT MET does not). Caller frees out->reason. */
void goal_parse_verdict(const char *reply, goal_verdict *out);

#endif