Artifact ec9bc5dc243c198a4b05fd51986c0fa1484da27a81eca49a39c8df990623d025:
- File
src/userdb.h
— part of check-in
[da4167d308]
at
2026-11-23 14:34:25
on branch rc-screen
— /rc: one step to the phone, like Claude Code's /remote-control
With a phone paired, /rc turns remote control on and shows a short panel: whether it is on and connected, this conversation's link for the phone page (/#s=JOURNAL/SESSION, &c=PHONE when one phone is paired) and a QR code of it, and the paired phones; c copies the link, s turns it off or on, p pairs another. With no phone paired, /rc goes straight to pairing; Esc there returns to the conversation. remote.invite is named only when pairing fails without it.
ssh leaves the main screen: /rc ssh and pic rc --ssh show the ssh command and its checks as text, with no QR code. pic rc prints the phone's link and its QR code, pic rc --link the link alone.
The footer says "remote on" while pic remote is connected (checked every 10 s), as Claude Code shows "/rc active".
Fixes: pic remote marks its stream connected on the relay's 200 (http.c's new on_head callback) rather than on the first body byte, so /rc no longer says "connecting" for up to 15 s; after pairing /rc no longer tells you to run pic remote when it already runs.
Tests: test/tui/rc.sh (fake relay and phone: unpaired pairing screen, invite, paired link and QR, connected at once with a quiet relay, footer marker, s, pic rc, pic rc --ssh, /rc ssh); http's on_head; tui.sh, grapevine.sh and remote.sh updated for the new screens. (user: dmestas, size: 4695) [annotate] [blame] [check-ins using] [more...]
/* pic's user database, ~/.pic/pic.sqlite (userdb.c): every piece of * user-level state pic keeps, in picu_ tables, shared by every pic process * (WAL, a busy timeout). The legacy ~/.pic/settings.json and * ~/.pic/models-store.json are imported on first open, then deleted. */ #ifndef PIC_USERDB_H #define PIC_USERDB_H #include <stddef.h> #include "sqlite3.h" /* The process's connection (opened on first use, schema and migration * done; sqlar functions registered), or NULL with err when there is no * home directory or the database cannot be opened. */ sqlite3 *pic_userdb(char *err, size_t errcap); /* The path pic_userdb opens (~/.pic/pic.sqlite): 0, or -1 without a home. */ int pic_userdb_path(char *out, size_t cap); void pic_userdb_close(void); /* How long a writer waits for another's write lock before giving up. */ #define PIC_USERDB_BUSY_MS 5000 /* The settings every opener of ~/.pic/pic.sqlite applies (pic_userdb does): * synchronous=FULL, fullfsync on macOS, foreign_keys off (libfossil's host * tables need it), and a fair busy handler, which waits in short jittered * sleeps up to PIC_USERDB_BUSY_MS (it replaces sqlite3_busy_timeout, so * PRAGMA busy_timeout reads 0). 0 or -1. */ int pic_userdb_settings(sqlite3 *db); /* The fair busy handler alone, with a deadline of MS from the first * refusal: for the workspace journal (store.c), which several pic processes * write. 0 or -1. */ int pic_busy_wait(sqlite3 *db, long ms); /* A project held in the store (picu_project). cred is NULL when none. */ typedef struct { const char *name, *prefix, *remote, *cred, *kind, *state; long long created_ms; } pic_project; /* Calls fn for each project, by name, until it returns nonzero. 0 or -1. */ int pic_projects_each(int (*fn)(void *ctx, const pic_project *p), void *ctx); /* A setting's value (malloc'd), or NULL when unset. */ char *pic_setting(const char *key); /* Sets KEY (VALUE NULL removes it). 0 or -1. */ int pic_setting_set(const char *key, const char *value); /* Sets PATH ("$.enabled") inside KEY's JSON object to the JSON value JSON, * as Pi writes one field of a nested setting (compaction.enabled); a value * that is not an object becomes one. 0 or -1. */ int pic_setting_set_json(const char *key, const char *path, const char *json); /* Calls fn for each setting, by key. */ int pic_settings_each(int (*fn)(void *ctx, const char *key, const char *value), void *ctx); /* This installation's id: a random UUID (lowercase, 36 characters) made * the first time it is asked for and kept in picu_meta. Sign-in flows that * name the installation use it. 0, or -1. */ int pic_install_id(char out[37]); /* Records that WORKSPACE uses the journal at JOURNAL (now). */ int pic_workspace_touch(const char *workspace, const char *journal); /* How many phones are paired for remote control (picu_remote_device rows, counted unopened). */ int pic_remote_phones(void); /* Ctrl+P's scope (picu_scoped_model): model patterns ("provider/model", or * with * and ?), in cycling order. Replaces the whole list; N 0 clears it. */ int pic_scoped_set(const char *const *patterns, size_t n); int pic_scoped_each(int (*fn)(void *ctx, const char *pattern), void *ctx); /* Whether PATH (a real path) is trusted (picu_trust): 1, 0, or -1 undecided. */ int pic_trust_get(const char *path); int pic_trust_set(const char *path, int trusted); /* A bug report kept in picu_bug; nothing is sent anywhere. Returns its id, or -1. */ long long pic_bug_add(const char *workspace, const char *conversation, const char *model, const char *description); int pic_bugs_each(int (*fn)(void *ctx, long long id, long long ms, const char *workspace, const char *description), void *ctx); /* A process pic started (picu_proc). ended_ms 0: still running as far as the * row says; exit_code -1: not known; signal 0: none. Text may be NULL. */ typedef struct { long long id; const char *kind, *command, *workspace, *conversation; long long pid, pgid, owner_pid, start_token, started_ms, ended_ms; int exit_code, signal; } pic_proc; /* Adds a row (id, owner_pid and started_ms as given; started_ms 0: now); its * id, or -1. Short, and without a full sync. */ long long pic_proc_add(const pic_proc *p); /* Marks a row ended now (once: a row already ended is left as it was). 0 or -1. */ int pic_proc_finish(long long id, int exit_code, int sig); /* Calls fn for each row by id (ALL: finished ones too) until it returns nonzero. 0 or -1. */ int pic_procs_each(int all, int (*fn)(void *ctx, const pic_proc *p), void *ctx); /* Deletes rows that ended (or, never ended, started) before BEFORE_MS. */ int pic_procs_prune(long long before_ms); #endif