Artifact 4bd004804609827b4e05503717dba4f20c89fc43d3fb356881a54aa61342cb54:
- File
src/platform.c
— part of check-in
[bb88ac58ac]
at
2026-11-19 20:35:01
on branch templates
— Prompt templates, as Pi's
Markdown files in ~/.pic/prompts/ and, once the workspace is trusted, WORKSPACE/.pic/prompts/ become /name commands: Pi's frontmatter (description, argument-hint), shell-like arguments and substitutions ($1, $@, $ARGUMENTS, ${1:-default}, ${@:N}, ${@:N:L}). They expand where text becomes a request, so ask, chat and the terminal agree; the slash menu lists them, built-in commands win a name clash, and /reload re-reads them. pic prompts [--json] lists them. Files are read through the platform's input reader, which gains a directory listing. Fixes a pollfd array one entry too small when a catalog refresh runs during a reply. (user: dmestas, size: 1392) [annotate] [blame] [check-ins using] [more...]
/* The host platform (see platform.h). */ #include <errno.h> #include <fcntl.h> #include <sys/file.h> #include <time.h> #include <unistd.h> #include <sys/random.h> #include "platform.h" static int64_t host_wall_ns(void) { struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts) != 0) { return -1; } return (int64_t)ts.tv_sec * 1000000000 + ts.tv_nsec; } static uint64_t host_mono_ns(void) { struct timespec ts; (void)clock_gettime(CLOCK_MONOTONIC, &ts); return (uint64_t)ts.tv_sec * 1000000000u + (uint64_t)ts.tv_nsec; } static int host_entropy(void *buf, size_t n) { return getentropy(buf, n); } static int host_lock(const char *path) { int fd = open(path, O_RDWR | O_CREAT | O_CLOEXEC, 0600); if (fd < 0) { return -1; } if (flock(fd, LOCK_EX | LOCK_NB) != 0) { int e = errno; close(fd); errno = e; return -2; } return fd; } static void host_unlock(int handle) { close(handle); } static const pic_platform host = { host_wall_ns, host_mono_ns, host_entropy, host_lock, host_unlock, pic_input_read_host, pic_input_list_host, NULL, }; static const pic_platform *current = &host; const pic_platform *pic_platform_host(void) { return &host; } const pic_platform *pic_platform_get(void) { return current; } void pic_platform_set(const pic_platform *p) { current = p ? p : &host; }