#ifndef CST_PERMS_H #define CST_PERMS_H #include #ifdef __cplusplus extern "C" { #endif typedef struct cst_perms cst_perms_t; /* Loads /.agent/permissions.json (missing file = no rules). */ cst_perms_t *cst_perms_open(const char *workspace); void cst_perms_close(cst_perms_t *p); int cst_perms_tool_allowed(const cst_perms_t *p, const char *tool); /* Prefix rule match; commands with ; & | ` $ < > ( ) never match. */ int cst_perms_shell_allowed(const cst_perms_t *p, const char *cmd); /* Add a rule and save. */ int cst_perms_allow_tool(cst_perms_t *p, const char *tool); int cst_perms_allow_prefix(cst_perms_t *p, const char *prefix); int cst_perms_reset(cst_perms_t *p); char *cst_perms_describe(const cst_perms_t *p); /* Reasonable prefix rule for a command ("" when it should not have one). */ void cst_perms_suggest_prefix(const char *cmd, char *out, size_t out_sz); /* 1 when every segment of cmd (split on | || && ;) is a read-only command * from a fixed whitelist, with no output redirection or substitution. */ int cst_shell_is_safe(const char *cmd); #ifdef __cplusplus } #endif #endif