Skip to content
pi-c Artifact [774fe4226f]
Login

Artifact [774fe4226f]

Artifact 774fe4226f04624141a2c50566508aa77a58600577e6582deaaae0354760be8f:


/* pic attach (attach.c): a read-only view of a conversation another
 * process runs, rebuilt from the journal's committed rows as Pi's JSON
 * events (or a short text form), caught up from a seq and then followed.
 * With -i, each line of stdin goes to the conversation's inbox (inbox.h)
 * while a request runs, and starts one (in a pic ask child) when none does.
 * It opens the journal narrowly, takes no lease and writes nothing itself
 * but inbox rows. Streamed text is not journaled, so it shows only committed
 * messages. */
#ifndef PIC_ATTACH_H
#define PIC_ATTACH_H
#include <stddef.h>
#include "pic.h"

typedef struct {
    const char *db;      /* the journal */
    const char *session; /* an id, a unique prefix, or "latest" */
    long long from;      /* entries after this seq; -1: from the latest request's start */
    int text;            /* --format text: lines for a person */
    int interactive;     /* -i: stdin lines become steers (follow-ups when idle) */
    int follow;          /* 0 (--no-follow): what is committed, then exit */
    /* -i, nothing running: a line starts a request in a child, SELF --db DB
     * --workspace WORKSPACE [--model MODEL] [--thinking THINKING] ask
     * --session ID TEXT, which takes the lease; NULL model or thinking:
     * ask's own default. */
    const char *self, *workspace, *model, *thinking;
    /* The model such a request runs on: when its key is sealed, the passphrase is asked once on
     * this terminal and the key handed to each child (cred.h, pic_cred_handoff). NULL: none. */
    const char *key_model;
} pic_attach_options;

/* The process's exit status: 0, or 1 with a message on stderr. */
int pic_attach_main(const pic_attach_options *o);

/* The same pass for another sink (pic remote, docs/design/remote-protocol.md): follows the
 * conversation SESSION (an id) of the journal S, which the caller opened narrowly and keeps, from
 * after FROM (-1: the latest request's start). NULL with err. */
typedef struct pic_follow pic_follow;
pic_follow *pic_follow_new(pic_store *s, const char *session, long long from, char *err, size_t cap);
/* One pass over what was committed since the last, in one read transaction; once it has ended,
 * EMIT gets each event in order with the seq of the entry it came from (nonzero stops). *LAST is
 * the highest seq the pass read and *RUNNING whether a request was running. 0, or -1. */
int pic_follow_pass(pic_follow *f, int (*emit)(void *ctx, long long seq, const char *event), void *ctx, long long *last,
                    int *running);
void pic_follow_free(pic_follow *f);

#endif