Artifact b722f1b68d303d39a64adf51ff7bc1a4cf7d8a2cb604302fdb591179a61bc698:
- File
src/tree.c
— part of check-in
[adeb66a371]
at
2026-11-19 18:13:50
on branch slash
— The rest of Pi's slash commands (ticket 03abef634d)
The terminal gains /settings, /scoped-models (Ctrl+P then cycles only those), /thinking and Shift+Tab (the levels the model supports), /tree (continue from any branch point), /reload, /trust, /import of a Pi v3 JSONL conversation (text only), /export to a self-contained web page, /changelog, /share (a secret gist through gh, after a yes) and /bug (a local report in picu_bug; nothing is sent). /login and /logout say they are not available yet. State lives in pic.sqlite. New subcommands back them: pic tree, export --html, import, trust, scoped-models and bug. (user: dmestas, size: 2609) [annotate] [blame] [check-ins using] [more...]
/* The conversation tree (Pi's /tree): the requests of every branch that * shares a root with SESSION, one JSON line each, in tree order. Forks share * entries, so a branch point is a request with several follow-ups. */ #include <stdio.h> #include "pic.h" /* seq: the request's user entry; end: its last entry (where a branch from it * continues); parent: the request before it; indent: how many branch points * lie above; active: on SESSION's path; sessions: ids whose head is in it. */ int pic_tree_json(pic_store *s, const char *session, FILE *out) { sqlite3_stmt *q = NULL; char id[64]; if (pic_session_resolve(s, session, id, sizeof id) != 0) { return -1; } if (sqlite3_prepare_v2( s->db, "WITH RECURSIVE cur(seq) AS (SELECT head_seq FROM pic_session WHERE id = ?1" " UNION ALL SELECT e.parent_seq FROM pic_entry e JOIN cur ON e.seq = cur.seq WHERE e.parent_seq IS NOT NULL)," " turn(seq, parent, path, indent) AS (" " SELECT seq, NULL, printf('%09d', seq), 0 FROM pic_entry WHERE kind = 'user' AND seq = (SELECT min(seq) FROM cur)" " UNION ALL" " SELECT c.seq, t.seq, t.path || printf('%09d', c.seq)," " t.indent + ((SELECT count(*) FROM pic_entry k WHERE k.kind = 'user' AND k.parent_seq IN" " (SELECT seq FROM pic_entry WHERE submission_id = (SELECT submission_id FROM pic_entry WHERE seq = t.seq))) > 1)" " FROM turn t JOIN pic_entry c ON c.kind = 'user' AND c.parent_seq IN" " (SELECT seq FROM pic_entry WHERE submission_id = (SELECT submission_id FROM pic_entry WHERE seq = t.seq)))" " SELECT json_object('seq', t.seq, 'parent', t.parent," " 'end', (SELECT max(x.seq) FROM pic_entry x WHERE x.submission_id = e.submission_id)," " 'indent', t.indent, 'active', json(iif(t.seq IN (SELECT seq FROM cur), 'true', 'false'))," " 'text', e.body," " 'sessions', (SELECT group_concat(s2.id, ',') FROM pic_session s2 WHERE s2.head_seq IN" " (SELECT seq FROM pic_entry WHERE submission_id = e.submission_id)))" " FROM turn t JOIN pic_entry e ON e.seq = t.seq ORDER BY t.path", -1, &q, NULL) != SQLITE_OK) { (void)snprintf(s->err, sizeof s->err, "sql: %s", sqlite3_errmsg(s->db)); return -1; } sqlite3_bind_text(q, 1, id, -1, SQLITE_STATIC); while (sqlite3_step(q) == SQLITE_ROW) { fprintf(out, "%s\n", (const char *)sqlite3_column_text(q, 0)); } sqlite3_finalize(q); return 0; }