Skip to content
pi-c Artifact [f0911e6be6]
Login

Artifact [f0911e6be6]

Artifact f0911e6be65a96d03529e2533a12ff4987b2fe8b37fdaae5c71d8f4f3d5b729f:


/* Compaction planning, Pi's algorithm over the journal (compact.c). */
#ifndef PIC_COMPACT_H
#define PIC_COMPACT_H

#include "pic.h"

#define PIC_RESERVE_TOKENS 16384     /* compact when the context passes the window minus this */
#define PIC_KEEP_RECENT_TOKENS 20000 /* about this much recent context is kept verbatim */

extern const char pic_summary_system_prompt[];

/* A planned compaction. The summary is the history prompt's reply (or the
 * previous summary, or "No prior history." when only a split turn is cut),
 * joined to the prefix prompt's reply for a split turn as Pi joins them, then
 * files appended. details are the file lists as JSON, kept for the next one. */
typedef struct {
    sqlite3_int64 first_kept_seq, tokens_before;
    int split;
    char *history_prompt;   /* NULL when only a split turn's start is summarized */
    char *prefix_prompt;    /* split turns only */
    char *previous_summary; /* NULL when this is the first */
    char *files, *details;
} pic_compaction;

/* 0 with a plan; 1 when there is nothing to summarize; -1 on error. */
int pic_compaction_plan(sqlite3 *db, int64_t submission, const char *instructions, pic_compaction *c);
void pic_compaction_free(pic_compaction *c);
/* Pi's estimate of the context the submission's next request sends. */
int pic_context_tokens(sqlite3 *db, int64_t submission, long *tokens);

#endif