Compare commits

...

4 Commits

10 changed files with 93 additions and 52 deletions

View File

@@ -54,11 +54,11 @@ Skills compose by adoption-list order (`10123`) and trigger tags carry runtime e
Didactyl will support local inference, which is very privacy preserving. Remote inference does however have it's advantages, and in those cases Didactyl supports using Bitcoin Lightning and eCash inference providers.
## Current Status — v0.2.31
## Current Status — v0.2.35
**Active build — this project is barely working. Experiment at your own risk.**
> Last release update: v0.2.31Added kind 10050 to genesis.jsonc
> Last release update: v0.2.35Remove top-level dm_protocol from genesis configs and set user-settings kind 30078 dm_protocol to both
- Connects to configured relays with auto-reconnect and relay state transition logging
- Publishes configured startup events per relay as each relay becomes connected

View File

@@ -14,17 +14,13 @@
"pubkey": "npub1REPLACE_WITH_ADMIN_PUBKEY"
},
// ─── DM Protocol ───────────────────────────────────────────────────
// Supported values: "nip04", "nip17", or "both".
"dm_protocol": "nip04",
// ─── Encrypted Startup Config Events ───────────────────────────────
// These are published as NIP-44 encrypted kind 30078 self-events on first run.
"encrypted_events": [
{
"kind": 30078,
"d_tag": "user-settings",
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"openai\",\"api_key\":\"sk-REPLACE_WITH_API_KEY\",\"model\":\"gpt-4o-mini\",\"base_url\":\"https://api.openai.com/v1\",\"max_tokens\":512,\"temperature\":0.7},\"didactyl\":{\"admin_pubkey\":\"npub1REPLACE_WITH_ADMIN_PUBKEY\",\"dm_protocol\":\"nip04\",\"max_turns\":40}}"
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"openai\",\"api_key\":\"sk-REPLACE_WITH_API_KEY\",\"model\":\"gpt-4o-mini\",\"base_url\":\"https://api.openai.com/v1\",\"max_tokens\":512,\"temperature\":0.7},\"didactyl\":{\"admin_pubkey\":\"npub1REPLACE_WITH_ADMIN_PUBKEY\",\"dm_protocol\":\"both\",\"max_turns\":40}}"
}
],

View File

@@ -11,10 +11,6 @@
"pubkey": "npub1rmz9gu6de0m0u4ysrn39crrud099ahvfgs6pvasl4hpjr5ud7yus54xv06"
},
// ─── DM Protocol ──────────────────────────────────────────────────
// Supported values: "nip04", "nip17", or "both".
"dm_protocol": "nip04",
// ─── HTTP Admin API ───────────────────────────────────────────────
// Local API for model/context inspection and runtime controls.
"api": {
@@ -29,7 +25,7 @@
{
"kind": 30078,
"d_tag": "user-settings",
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"ppq\",\"api_key\":\"sk-LshAWvFC0KOFgrUYiP6NmT\",\"model\":\"claude-opus-4.6\",\"base_url\":\"https://api.ppq.ai\",\"max_tokens\":200000,\"temperature\":0.7},\"didactyl\":{\"admin_pubkey\":\"npub1rmz9gu6de0m0u4ysrn39crrud099ahvfgs6pvasl4hpjr5ud7yus54xv06\",\"dm_protocol\":\"nip04\",\"max_turns\":40}}"
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"ppq\",\"api_key\":\"sk-LshAWvFC0KOFgrUYiP6NmT\",\"model\":\"claude-opus-4.6\",\"base_url\":\"https://api.ppq.ai\",\"max_tokens\":200000,\"temperature\":0.7},\"didactyl\":{\"admin_pubkey\":\"npub1rmz9gu6de0m0u4ysrn39crrud099ahvfgs6pvasl4hpjr5ud7yus54xv06\",\"dm_protocol\":\"both\",\"max_turns\":40}}"
}
],

View File

@@ -9,9 +9,6 @@
"admin": {
"pubkey": "npub1rmz9gu6de0m0u4ysrn39crrud099ahvfgs6pvasl4hpjr5ud7yus54xv06"
},
// ─── DM Protocol ──────────────────────────────────────────────────
// Supported values: "nip04", "nip17", or "both".
"dm_protocol": "nip04",
// ─── HTTP Admin API ───────────────────────────────────────────────
// Local API for model/context inspection and runtime controls.
"api": {
@@ -25,7 +22,7 @@
{
"kind": 30078,
"d_tag": "user-settings",
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"ppq\",\"api_key\":\"sk-L9kd0LkZaoeaua0qqosnHy\",\"model\":\"claude-haiku-4.5\",\"base_url\":\"https://api.ppq.ai\",\"max_tokens\":512,\"temperature\":0.7},\"didactyl\":{\"admin_pubkey\":\"npub1rmz9gu6de0m0u4ysrn39crrud099ahvfgs6pvasl4hpjr5ud7yus54xv06\",\"dm_protocol\":\"nip04\",\"max_turns\":40}}"
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"ppq\",\"api_key\":\"sk-L9kd0LkZaoeaua0qqosnHy\",\"model\":\"claude-haiku-4.5\",\"base_url\":\"https://api.ppq.ai\",\"max_tokens\":512,\"temperature\":0.7},\"didactyl\":{\"admin_pubkey\":\"npub1rmz9gu6de0m0u4ysrn39crrud099ahvfgs6pvasl4hpjr5ud7yus54xv06\",\"dm_protocol\":\"both\",\"max_turns\":40}}"
}
],
// ─── Startup Events ───────────────────────────────────────────────

View File

@@ -741,8 +741,13 @@ static int fetch_self_config_plaintext(const didactyl_config_t* cfg, const char*
return 0;
}
static int apply_recalled_user_settings(didactyl_config_t* cfg, const char* plaintext) {
static int apply_recalled_user_settings(didactyl_config_t* cfg,
const char* plaintext,
int* out_backfill_needed) {
if (!cfg || !plaintext) return -1;
if (out_backfill_needed) {
*out_backfill_needed = 0;
}
cJSON* root = cJSON_Parse(plaintext);
if (!root || !cJSON_IsObject(root)) {
@@ -752,7 +757,7 @@ static int apply_recalled_user_settings(didactyl_config_t* cfg, const char* plai
cJSON* global_llm = cJSON_GetObjectItemCaseSensitive(root, "global_llm");
cJSON* didactyl = cJSON_GetObjectItemCaseSensitive(root, "didactyl");
if (!global_llm || !cJSON_IsObject(global_llm) || !didactyl || !cJSON_IsObject(didactyl)) {
if (!global_llm || !cJSON_IsObject(global_llm)) {
cJSON_Delete(root);
return -1;
}
@@ -764,15 +769,20 @@ static int apply_recalled_user_settings(didactyl_config_t* cfg, const char* plai
cJSON* max_tokens = cJSON_GetObjectItemCaseSensitive(global_llm, "max_tokens");
cJSON* temperature = cJSON_GetObjectItemCaseSensitive(global_llm, "temperature");
cJSON* admin_pubkey = cJSON_GetObjectItemCaseSensitive(didactyl, "admin_pubkey");
cJSON* dm_protocol = cJSON_GetObjectItemCaseSensitive(didactyl, "dm_protocol");
cJSON* max_turns = cJSON_GetObjectItemCaseSensitive(didactyl, "max_turns");
cJSON* admin_pubkey = NULL;
cJSON* dm_protocol = NULL;
cJSON* max_turns = NULL;
if (didactyl && cJSON_IsObject(didactyl)) {
admin_pubkey = cJSON_GetObjectItemCaseSensitive(didactyl, "admin_pubkey");
dm_protocol = cJSON_GetObjectItemCaseSensitive(didactyl, "dm_protocol");
max_turns = cJSON_GetObjectItemCaseSensitive(didactyl, "max_turns");
} else if (out_backfill_needed) {
*out_backfill_needed = 1;
}
if (!api_key || !cJSON_IsString(api_key) || !api_key->valuestring || api_key->valuestring[0] == '\0' ||
!model || !cJSON_IsString(model) || !model->valuestring || model->valuestring[0] == '\0' ||
!base_url || !cJSON_IsString(base_url) || !base_url->valuestring || base_url->valuestring[0] == '\0' ||
!admin_pubkey || !cJSON_IsString(admin_pubkey) || !admin_pubkey->valuestring || admin_pubkey->valuestring[0] == '\0' ||
!dm_protocol || !cJSON_IsString(dm_protocol) || !dm_protocol->valuestring || dm_protocol->valuestring[0] == '\0') {
!base_url || !cJSON_IsString(base_url) || !base_url->valuestring || base_url->valuestring[0] == '\0') {
cJSON_Delete(root);
return -1;
}
@@ -793,16 +803,22 @@ static int apply_recalled_user_settings(didactyl_config_t* cfg, const char* plai
cfg->llm.temperature = temperature->valuedouble;
}
{
if (admin_pubkey && cJSON_IsString(admin_pubkey) && admin_pubkey->valuestring && admin_pubkey->valuestring[0] != '\0') {
char decoded[65] = {0};
if (decode_pubkey_hex_or_npub_local(admin_pubkey->valuestring, decoded) != 0) {
cJSON_Delete(root);
return -1;
}
snprintf(cfg->admin.pubkey, sizeof(cfg->admin.pubkey), "%s", decoded);
} else if (out_backfill_needed) {
*out_backfill_needed = 1;
}
dm_protocol_from_string(dm_protocol->valuestring, cfg);
if (dm_protocol && cJSON_IsString(dm_protocol) && dm_protocol->valuestring && dm_protocol->valuestring[0] != '\0') {
dm_protocol_from_string(dm_protocol->valuestring, cfg);
} else if (out_backfill_needed) {
*out_backfill_needed = 1;
}
if (max_turns && cJSON_IsNumber(max_turns)) {
int parsed = (int)max_turns->valuedouble;
@@ -903,10 +919,13 @@ static int persist_runtime_config_to_nostr(const didactyl_config_t* cfg, int per
return rc;
}
static int recover_missing_runtime_config_from_nostr(didactyl_config_t* cfg) {
static int recover_missing_runtime_config_from_nostr(didactyl_config_t* cfg, int* out_backfill_needed) {
if (!cfg) {
return 0;
}
if (out_backfill_needed) {
*out_backfill_needed = 0;
}
char* settings_plaintext = NULL;
if (fetch_self_config_plaintext(cfg, "user-settings", &settings_plaintext) != 0 || !settings_plaintext) {
@@ -915,14 +934,22 @@ static int recover_missing_runtime_config_from_nostr(didactyl_config_t* cfg) {
return 0;
}
if (apply_recalled_user_settings(cfg, settings_plaintext) != 0) {
int backfill_needed = 0;
if (apply_recalled_user_settings(cfg, settings_plaintext, &backfill_needed) != 0) {
DEBUG_WARN("[didactyl] startup phase: failed to parse/decrypt recalled user-settings");
free(settings_plaintext);
return 0;
}
free(settings_plaintext);
DEBUG_INFO("[didactyl] startup phase: recovered user-settings from Nostr");
if (out_backfill_needed) {
*out_backfill_needed = backfill_needed;
}
if (backfill_needed) {
DEBUG_INFO("[didactyl] startup phase: recovered user-settings from Nostr (missing didactyl fields will be backfilled)");
} else {
DEBUG_INFO("[didactyl] startup phase: recovered user-settings from Nostr");
}
return 1;
}
@@ -1203,8 +1230,13 @@ int main(int argc, char** argv) {
}
startup_step_begin(2, "Recover runtime config from Nostr");
int llm_recalled_from_nostr = recover_missing_runtime_config_from_nostr(&cfg);
startup_step_ok(2, "Recover runtime config from Nostr", llm_recalled_from_nostr ? "user-settings recalled" : NULL);
int user_settings_backfill_needed = 0;
int llm_recalled_from_nostr = recover_missing_runtime_config_from_nostr(&cfg, &user_settings_backfill_needed);
startup_step_ok(2,
"Recover runtime config from Nostr",
llm_recalled_from_nostr
? (user_settings_backfill_needed ? "user-settings recalled (backfill required)" : "user-settings recalled")
: NULL);
startup_step_begin(3, "Validate LLM config");
if (!llm_config_is_complete(&cfg.llm)) {
@@ -1265,8 +1297,9 @@ int main(int argc, char** argv) {
DEBUG_INFO("[didactyl] startup phase: existing-agent mode; skipping startup-event reconcile on subsequent run");
}
if (bootstrap_mode || first_run) {
if (persist_runtime_config_to_nostr(&cfg, llm_recalled_from_nostr ? 0 : 1) != 0) {
if (bootstrap_mode || first_run || user_settings_backfill_needed) {
if (persist_runtime_config_to_nostr(&cfg,
(llm_recalled_from_nostr && !user_settings_backfill_needed) ? 0 : 1) != 0) {
DEBUG_WARN("[didactyl] startup phase: failed to persist encrypted runtime config to Nostr");
} else {
DEBUG_INFO("[didactyl] startup phase: persisted encrypted runtime config to Nostr");

View File

@@ -12,8 +12,8 @@
// Using DIDACTYL_ prefix to avoid conflicts with nostr_core_lib VERSION macros
#define DIDACTYL_VERSION_MAJOR 0
#define DIDACTYL_VERSION_MINOR 2
#define DIDACTYL_VERSION_PATCH 31
#define DIDACTYL_VERSION "v0.2.31"
#define DIDACTYL_VERSION_PATCH 35
#define DIDACTYL_VERSION "v0.2.35"
// Agent metadata
#define DIDACTYL_NAME "Didactyl"

View File

@@ -2848,6 +2848,9 @@ int nostr_handler_subscribe_dms(dm_callback_t callback, void* user_data) {
const int need_kind4 = (g_cfg->dm_protocol == DM_PROTOCOL_NIP04 || g_cfg->dm_protocol == DM_PROTOCOL_BOTH) ? 1 : 0;
const int need_kind1059 = (g_cfg->dm_protocol == DM_PROTOCOL_NIP17 || g_cfg->dm_protocol == DM_PROTOCOL_BOTH) ? 1 : 0;
DEBUG_INFO("[didactyl] DM subscribe: dm_protocol=%d need_kind4=%d need_kind1059=%d g_start_time=%ld",
(int)g_cfg->dm_protocol, need_kind4, need_kind1059, (long)g_start_time);
if (!need_kind4 && !need_kind1059) {
DEBUG_WARN("[didactyl] DM subscription skipped: no protocol selected");
return -1;
@@ -2898,7 +2901,6 @@ int nostr_handler_subscribe_dms(dm_callback_t callback, void* user_data) {
cJSON_AddItemToObject(filter1059, "kinds", kinds1059);
cJSON_AddItemToArray(p_values1059, cJSON_CreateString(g_cfg->keys.public_key_hex));
cJSON_AddItemToObject(filter1059, "#p", p_values1059);
cJSON_AddNumberToObject(filter1059, "since", (double)g_start_time);
cJSON_AddNumberToObject(filter1059, "limit", 400);
}

View File

@@ -1019,7 +1019,7 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
cJSON* global_llm = cJSON_GetObjectItemCaseSensitive(root, "global_llm");
cJSON* didactyl = cJSON_GetObjectItemCaseSensitive(root, "didactyl");
if (!global_llm || !cJSON_IsObject(global_llm) || !didactyl || !cJSON_IsObject(didactyl)) {
if (!global_llm || !cJSON_IsObject(global_llm)) {
cJSON_Delete(root);
return -1;
}
@@ -1031,15 +1031,18 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
cJSON* max_tokens = cJSON_GetObjectItemCaseSensitive(global_llm, "max_tokens");
cJSON* temperature = cJSON_GetObjectItemCaseSensitive(global_llm, "temperature");
cJSON* admin_pubkey = cJSON_GetObjectItemCaseSensitive(didactyl, "admin_pubkey");
cJSON* dm_protocol = cJSON_GetObjectItemCaseSensitive(didactyl, "dm_protocol");
cJSON* max_turns = cJSON_GetObjectItemCaseSensitive(didactyl, "max_turns");
cJSON* admin_pubkey = NULL;
cJSON* dm_protocol = NULL;
cJSON* max_turns = NULL;
if (didactyl && cJSON_IsObject(didactyl)) {
admin_pubkey = cJSON_GetObjectItemCaseSensitive(didactyl, "admin_pubkey");
dm_protocol = cJSON_GetObjectItemCaseSensitive(didactyl, "dm_protocol");
max_turns = cJSON_GetObjectItemCaseSensitive(didactyl, "max_turns");
}
if (!api_key || !cJSON_IsString(api_key) || !api_key->valuestring || api_key->valuestring[0] == '\0' ||
!model || !cJSON_IsString(model) || !model->valuestring || model->valuestring[0] == '\0' ||
!base_url || !cJSON_IsString(base_url) || !base_url->valuestring || base_url->valuestring[0] == '\0' ||
!admin_pubkey || !cJSON_IsString(admin_pubkey) || !admin_pubkey->valuestring || admin_pubkey->valuestring[0] == '\0' ||
!dm_protocol || !cJSON_IsString(dm_protocol) || !dm_protocol->valuestring || dm_protocol->valuestring[0] == '\0') {
!base_url || !cJSON_IsString(base_url) || !base_url->valuestring || base_url->valuestring[0] == '\0') {
cJSON_Delete(root);
return -1;
}
@@ -1060,7 +1063,7 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
cfg->llm.temperature = temperature->valuedouble;
}
{
if (admin_pubkey && cJSON_IsString(admin_pubkey) && admin_pubkey->valuestring && admin_pubkey->valuestring[0] != '\0') {
char decoded[65] = {0};
if (decode_pubkey_hex_or_npub_local(admin_pubkey->valuestring, decoded) != 0) {
cJSON_Delete(root);
@@ -1069,12 +1072,14 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
snprintf(cfg->admin.pubkey, sizeof(cfg->admin.pubkey), "%s", decoded);
}
if (strcmp(dm_protocol->valuestring, "nip17") == 0) {
cfg->dm_protocol = DM_PROTOCOL_NIP17;
} else if (strcmp(dm_protocol->valuestring, "both") == 0) {
cfg->dm_protocol = DM_PROTOCOL_BOTH;
} else {
cfg->dm_protocol = DM_PROTOCOL_NIP04;
if (dm_protocol && cJSON_IsString(dm_protocol) && dm_protocol->valuestring && dm_protocol->valuestring[0] != '\0') {
if (strcmp(dm_protocol->valuestring, "nip17") == 0) {
cfg->dm_protocol = DM_PROTOCOL_NIP17;
} else if (strcmp(dm_protocol->valuestring, "both") == 0) {
cfg->dm_protocol = DM_PROTOCOL_BOTH;
} else {
cfg->dm_protocol = DM_PROTOCOL_NIP04;
}
}
if (max_turns && cJSON_IsNumber(max_turns)) {

View File

@@ -7,7 +7,6 @@
"admin": {
"pubkey": "npub1REPLACE_WITH_TEST_ADMIN_PUBKEY"
},
"dm_protocol": "nip04",
"llm": {
"provider": "https://api.ppq.ai",
"api_key": "sk-SBI2Pga0J6n8jpPorHbRHC",
@@ -21,6 +20,13 @@
"port": 8485,
"bind_address": "127.0.0.1"
},
"encrypted_events": [
{
"kind": 30078,
"d_tag": "user-settings",
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"https://api.ppq.ai\",\"api_key\":\"sk-SBI2Pga0J6n8jpPorHbRHC\",\"model\":\"claude-haiku-4.5\",\"base_url\":\"https://api.ppq.ai\",\"max_tokens\":10000,\"temperature\":0.7},\"didactyl\":{\"admin_pubkey\":\"npub1REPLACE_WITH_TEST_ADMIN_PUBKEY\",\"dm_protocol\":\"both\",\"max_turns\":40}}"
}
],
"startup_events": [
{
"kind": 0,

View File

@@ -8,7 +8,6 @@
"admin": {
"pubkey": "npub1REPLACE_WITH_TEST_ADMIN_PUBKEY"
},
"dm_protocol": "nip04",
"llm": {
"provider": "openai",
"api_key": "sk-REPLACE_WITH_API_KEY",
@@ -22,6 +21,13 @@
"port": 8485,
"bind_address": "127.0.0.1"
},
"encrypted_events": [
{
"kind": 30078,
"d_tag": "user-settings",
"content": "{\"v\":2,\"updatedAt\":0,\"global_llm\":{\"provider\":\"openai\",\"api_key\":\"sk-REPLACE_WITH_API_KEY\",\"model\":\"claude-haiku-4.5\",\"base_url\":\"https://api.anthropic.com/v1\",\"max_tokens\":512,\"temperature\":0.3},\"didactyl\":{\"admin_pubkey\":\"npub1REPLACE_WITH_TEST_ADMIN_PUBKEY\",\"dm_protocol\":\"both\",\"max_turns\":40}}"
}
],
"startup_events": [
{
"kind": 0,