xonecas.io
7814
Ta

tiny-c-agent / files

tiny-c-agent / src / session.h

937 bytes
1// tiny sessions: append-only JSONL, one record per line, fsynced on write.
2
3#ifndef TINY_SESSION_H
4#define TINY_SESSION_H
5
6#include <yyjson.h>
7
8typedef struct tiny_session tiny_session;
9
10// Creates the session directory and its session.jsonl, then writes the header.
11// The title seeds the directory name. Returns NULL and sets *err (malloc'd,
12// caller frees) on failure.
13tiny_session *tiny_session_open(const char *sessions_dir, const char *cwd,
14                                const char *title, char **err);
15
16// The session directory name.
17const char *tiny_session_id(const tiny_session *s);
18
19// Serializes one record as a line and appends it, then fsyncs. The value must
20// belong to a document that outlives the call. Returns 0, or -1 with *err set.
21// Committed lines are never rewritten or deleted.
22int tiny_session_append(tiny_session *s, yyjson_mut_val *record, char **err);
23
24void tiny_session_close(tiny_session *s);
25
26#endif