diff --git a/src/agent/create_record.c b/src/agent/create_record.c index 32c7bd4..c798605 100644 --- a/src/agent/create_record.c +++ b/src/agent/create_record.c @@ -111,9 +111,8 @@ wf_status wf_agent_create_record(wf_agent *agent, const char *collection, } wf_status status = wf_agent_create_record_internal(agent, collection, record, out); - if (status != WF_OK) { - cJSON_Delete(record); - } + /* Internal always takes ownership of `record` (it adopts it into the + * request root or frees it on every exit path), so never free it here. */ return status; } diff --git a/src/cli/cli_chat.c b/src/cli/cli_chat.c index 94fc128..f333d5c 100644 --- a/src/cli/cli_chat.c +++ b/src/cli/cli_chat.c @@ -208,7 +208,10 @@ int cmd_groups(int argc, char **argv) { wf_response res = {0}; wf_status s = wf_agent_chat_edit_group(agent, convo_id, name, &res); - return finish_agent_response(agent, s, &res); + if (g_json) { + return finish_agent_response(agent, s, &res); + } + wf_response_free(&res); if (s != WF_OK) { fprintf(stderr, "error: editGroup failed (status %d)\n", (int)s); wf_agent_free(agent); @@ -254,7 +257,10 @@ int cmd_groups(int argc, char **argv) { else s = wf_agent_chat_remove_members(agent, convo_id, members, n_members, &res); - return finish_agent_response(agent, s, &res); + if (g_json) { + return finish_agent_response(agent, s, &res); + } + wf_response_free(&res); if (s != WF_OK) { fprintf(stderr, "error: %s failed (status %d)\n", strcmp(sub, "add-members") == 0 ? "addMembers" diff --git a/src/cli/cli_graph.c b/src/cli/cli_graph.c index e86537e..7be71cc 100644 --- a/src/cli/cli_graph.c +++ b/src/cli/cli_graph.c @@ -5,6 +5,7 @@ #include "wolfram/graph_typed.h" #include "wolfram/graph_social_typed.h" #include "wolfram/graph_write.h" +#include "wolfram/repo_typed.h" #include "wolfram/unspecced_typed.h" #include @@ -114,6 +115,28 @@ int cmd_mutes(int argc, char **argv) { } int cmd_list(int argc, char **argv) { + if (argc < 2) { + usage_stream(stderr); + return 0; + } + + const char *sub = argv[1]; + if (strcmp(sub, "create") == 0) { + return cmd_list_create(argc - 1, argv + 1); + } + if (strcmp(sub, "update") == 0) { + return cmd_list_update(argc - 1, argv + 1); + } + if (strcmp(sub, "delete") == 0) { + return cmd_list_delete(argc - 1, argv + 1); + } + if (strcmp(sub, "add-item") == 0) { + return cmd_list_add_item(argc - 1, argv + 1); + } + if (strcmp(sub, "remove-item") == 0) { + return cmd_list_remove_item(argc - 1, argv + 1); + } + if (argc < 3) { usage_stream(stderr); return 0; @@ -168,11 +191,18 @@ int cmd_list_create(int argc, char **argv) { wf_agent *agent = agent_login_or_err(pos[0], pos[1], pos[2]); if (!agent) return 1; - const char *purpose_str = purpose ? purpose : "app.bsky.graph.defs#curatelist"; + const char *purpose_str = + purpose ? purpose : "app.bsky.graph.defs#curatelist"; + if (purpose && strcmp(purpose, "modlist") == 0) + purpose_str = "app.bsky.graph.defs#modlist"; + else if (purpose && strcmp(purpose, "curatelist") == 0) + purpose_str = "app.bsky.graph.defs#curatelist"; + else if (purpose && strcmp(purpose, "referencelist") == 0) + purpose_str = "app.bsky.graph.defs#referencelist"; wf_agent_post_result out = {0}; - wf_status s = wf_agent_graph_create_list(agent, purpose_str, name, - description, &out); + wf_status s = + wf_agent_graph_create_list(agent, purpose_str, name, description, &out); if (s != WF_OK) { fprintf(stderr, "error: createList failed (status %d)\n", (int)s); wf_agent_post_result_free(&out); @@ -218,27 +248,76 @@ int cmd_list_update(int argc, char **argv) { } rkey++; - char *record_json = NULL; - cJSON *rec = cJSON_CreateObject(); - if (name) - cJSON_AddStringToObject(rec, "name", name); - if (description) - cJSON_AddStringToObject(rec, "description", description); - record_json = cJSON_PrintUnformatted(rec); - cJSON_Delete(rec); + wf_session_data sd = {0}; + wf_agent_get_session_data(agent, &sd); + const char *repo = sd.did ? sd.did : pos[1]; - wf_agent_post_result out = {0}; - wf_status s = wf_agent_graph_update_list(agent, rkey, record_json, - &out); + /* putRecord replaces the whole record, so fetch it first and merge the + * requested fields into the existing value ($type/createdAt/purpose + * must be preserved). */ + wf_repo_record rec = {0}; + wf_status s = wf_agent_get_record_typed(agent, repo, "app.bsky.graph.list", + rkey, NULL, &rec); + if (s != WF_OK) { + fprintf(stderr, "error: getRecord failed (status %d)\n", (int)s); + wf_agent_session_data_free(&sd); + wf_agent_free(agent); + return 1; + } + if (!rec.value) { + fprintf(stderr, "error: record has no value\n"); + wf_repo_record_free(&rec); + wf_agent_session_data_free(&sd); + wf_agent_free(agent); + return 1; + } + + if (name) { + cJSON_DeleteItemFromObject(rec.value, "name"); + if (!cJSON_AddStringToObject(rec.value, "name", name)) { + fprintf(stderr, "error: allocation failure\n"); + wf_repo_record_free(&rec); + wf_agent_session_data_free(&sd); + wf_agent_free(agent); + return 1; + } + } + if (description) { + cJSON_DeleteItemFromObject(rec.value, "description"); + if (!cJSON_AddStringToObject(rec.value, "description", description)) { + fprintf(stderr, "error: allocation failure\n"); + wf_repo_record_free(&rec); + wf_agent_session_data_free(&sd); + wf_agent_free(agent); + return 1; + } + } + + char *record_json = cJSON_PrintUnformatted(rec.value); + if (!record_json) { + fprintf(stderr, "error: allocation failure\n"); + wf_repo_record_free(&rec); + wf_agent_session_data_free(&sd); + wf_agent_free(agent); + return 1; + } + + wf_repo_write_record_result out = {0}; + s = wf_agent_put_record_typed(agent, repo, "app.bsky.graph.list", rkey, -1, + record_json, NULL, NULL, &out); free(record_json); if (s != WF_OK) { fprintf(stderr, "error: updateList failed (status %d)\n", (int)s); - wf_agent_post_result_free(&out); + wf_repo_write_record_result_free(&out); + wf_repo_record_free(&rec); + wf_agent_session_data_free(&sd); wf_agent_free(agent); return 1; } printf("updated list %s\n", list_uri); - wf_agent_post_result_free(&out); + wf_repo_write_record_result_free(&out); + wf_repo_record_free(&rec); + wf_agent_session_data_free(&sd); wf_agent_free(agent); return 0; } @@ -602,10 +681,9 @@ int cmd_starter_pack(int argc, char **argv) { return 1; } - wf_response res = {0}; - wf_status s = wf_agent_get_starter_packs_with_membership(agent, actor, - limit, NULL, - &res); + wf_response res = {0}; + wf_status s = wf_agent_get_starter_packs_with_membership( + agent, actor, limit, NULL, &res); return finish_agent_response(agent, s, &res); } diff --git a/src/cli/cli_ozone.c b/src/cli/cli_ozone.c index f4fb572..39eae40 100644 --- a/src/cli/cli_ozone.c +++ b/src/cli/cli_ozone.c @@ -16,15 +16,13 @@ static void print_subject_status( size_t idx) { printf("status %zu: id=%" PRId64 " review_state=%s subject_repo_handle=%s " "created_at=%s updated_at=%s\n", - idx, st->id, - st->review_state ? st->review_state : "?", + idx, st->id, st->review_state ? st->review_state : "?", st->subject_repo_handle ? st->subject_repo_handle : "?", st->created_at ? st->created_at : "?", st->updated_at ? st->updated_at : "?"); if (st->has_priority_score) printf(" priority_score: %" PRId64 "\n", st->priority_score); - if (st->has_comment && st->comment) - printf(" comment: %s\n", st->comment); + if (st->has_comment && st->comment) printf(" comment: %s\n", st->comment); if (st->has_takendown) printf(" takendown: %s\n", st->takendown ? "true" : "false"); if (st->has_appealed) @@ -51,66 +49,59 @@ static void print_subject_status( printf(" age_assurance_state: %s\n", st->age_assurance_state); } -static void print_team_member( - const wf_lex_tools_ozone_team_defs_member *m, size_t idx) { +static void print_team_member(const wf_lex_tools_ozone_team_defs_member *m, + size_t idx) { printf("member %zu: did=%s role=%s disabled=%s created_at=%s " "updated_at=%s\n", - idx, m->did ? m->did : "?", - m->role ? m->role : "?", + idx, m->did ? m->did : "?", m->role ? m->role : "?", m->has_disabled ? (m->disabled ? "true" : "false") : "?", m->created_at ? m->created_at : "?", m->updated_at ? m->updated_at : "?"); if (m->has_profile) { printf(" profile_handle: %s\n", - m->profile->handle ? m->profile->handle : "?"); + m->profile->handle ? m->profile->handle : "?"); } if (m->last_updated_by) printf(" last_updated_by: %s\n", m->last_updated_by); } -static void print_template( - const wf_lex_tools_ozone_communication_defs_template_view *t, - size_t idx) { +static void +print_template(const wf_lex_tools_ozone_communication_defs_template_view *t, + size_t idx) { printf("template %zu: id=%s name=%s disabled=%s lang=%s " "created_at=%s updated_at=%s\n", - idx, t->id ? t->id : "?", - t->name ? t->name : "?", + idx, t->id ? t->id : "?", t->name ? t->name : "?", t->disabled ? "true" : "false", t->has_lang && t->lang ? t->lang : "?", t->created_at ? t->created_at : "?", t->updated_at ? t->updated_at : "?"); - if (t->has_subject && t->subject) - printf(" subject: %s\n", t->subject); + if (t->has_subject && t->subject) printf(" subject: %s\n", t->subject); if (t->content_markdown) printf(" content_markdown: %s\n", t->content_markdown); if (t->last_updated_by) printf(" last_updated_by: %s\n", t->last_updated_by); } -static void print_option( - const wf_lex_tools_ozone_setting_defs_option *o, size_t idx) { +static void print_option(const wf_lex_tools_ozone_setting_defs_option *o, + size_t idx) { printf("option %zu: key=%s scope=%s description=%s created_at=%s " "updated_at=%s\n", - idx, o->key ? o->key : "?", - o->scope ? o->scope : "?", + idx, o->key ? o->key : "?", o->scope ? o->scope : "?", o->has_description && o->description ? o->description : "?", o->has_created_at && o->created_at ? o->created_at : "?", o->has_updated_at && o->updated_at ? o->updated_at : "?"); - if (o->did) - printf(" did: %s\n", o->did); + if (o->did) printf(" did: %s\n", o->did); if (o->has_manager_role && o->manager_role) printf(" manager_role: %s\n", o->manager_role); - if (o->created_by) - printf(" created_by: %s\n", o->created_by); + if (o->created_by) printf(" created_by: %s\n", o->created_by); if (o->last_updated_by) printf(" last_updated_by: %s\n", o->last_updated_by); } -static void print_account( - const wf_lex_com_atproto_admin_defs_account_view *a, size_t idx) { - printf("account %zu: did=%s handle=%s email=%s indexed_at=%s\n", - idx, a->did ? a->did : "?", - a->handle ? a->handle : "?", +static void print_account(const wf_lex_com_atproto_admin_defs_account_view *a, + size_t idx) { + printf("account %zu: did=%s handle=%s email=%s indexed_at=%s\n", idx, + a->did ? a->did : "?", a->handle ? a->handle : "?", a->has_email && a->email ? a->email : "?", a->indexed_at ? a->indexed_at : "?"); if (a->has_invites_disabled) @@ -122,17 +113,15 @@ static void print_account( printf(" email_confirmed_at: %s\n", a->email_confirmed_at); } -static void print_report( - const wf_lex_tools_ozone_report_defs_report_view *r, size_t idx) { +static void print_report(const wf_lex_tools_ozone_report_defs_report_view *r, + size_t idx) { printf("report %zu: id=%" PRId64 " status=%s report_type=%s " "reported_by=%s created_at=%s\n", - idx, r->id, - r->status ? r->status : "?", + idx, r->id, r->status ? r->status : "?", r->report_type ? r->report_type : "?", r->reported_by ? r->reported_by : "?", r->created_at ? r->created_at : "?"); - if (r->has_comment && r->comment) - printf(" comment: %s\n", r->comment); + if (r->has_comment && r->comment) printf(" comment: %s\n", r->comment); if (r->has_updated_at && r->updated_at) printf(" updated_at: %s\n", r->updated_at); if (r->has_related_report_count) @@ -144,13 +133,11 @@ static void print_report( printf(" is_automated: %s\n", r->is_automated ? "true" : "false"); } -static void print_queue( - const wf_lex_tools_ozone_queue_defs_queue_view *q, size_t idx) { +static void print_queue(const wf_lex_tools_ozone_queue_defs_queue_view *q, + size_t idx) { printf("queue %zu: id=%" PRId64 " name=%s enabled=%s " "created_by=%s created_at=%s updated_at=%s\n", - idx, q->id, - q->name ? q->name : "?", - q->enabled ? "true" : "false", + idx, q->id, q->name ? q->name : "?", q->enabled ? "true" : "false", q->created_by ? q->created_by : "?", q->created_at ? q->created_at : "?", q->updated_at ? q->updated_at : "?"); @@ -195,7 +182,8 @@ int cmd_ozone(int argc, char **argv) { const char *group = argv[1]; const char *sub = argv[2]; - /* moderation query-statuses [--limit N] [--cursor C] */ + /* moderation query-statuses [--limit N] + * [--cursor C] */ if (strcmp(group, "moderation") == 0 && strcmp(sub, "query-statuses") == 0) { const char *cursor = NULL; @@ -229,31 +217,28 @@ int cmd_ozone(int argc, char **argv) { } wf_lex_tools_ozone_moderation_query_statuses_main_output *out = NULL; - wf_status s = - wf_ozone_moderation_queryStatuses(agent, ¶ms, &out); + wf_status s = wf_ozone_moderation_queryStatuses(agent, ¶ms, &out); if (s != WF_OK) { - fprintf(stderr, - "error: queryStatuses failed (status %d)\n", (int)s); - wf_lex_tools_ozone_moderation_query_statuses_main_output_free( - out); + fprintf(stderr, "error: queryStatuses failed (status %d)\n", + (int)s); + wf_lex_tools_ozone_moderation_query_statuses_main_output_free(out); wf_agent_free(agent); return 1; } - if (out->has_cursor && out->cursor) - printf("cursor: %s\n", out->cursor); + if (out->has_cursor && out->cursor) printf("cursor: %s\n", out->cursor); printf("count: %zu\n", out->subject_statuses.count); for (size_t i = 0; i < out->subject_statuses.count; ++i) print_subject_status(out->subject_statuses.items[i], i); - if (out->subject_statuses.count == 0) - printf("(no subject statuses)\n"); + if (out->subject_statuses.count == 0) printf("(no subject statuses)\n"); wf_lex_tools_ozone_moderation_query_statuses_main_output_free(out); wf_agent_free(agent); return 0; } - /* moderation get-suggestions [--ignore-subjects uri]... [--limit N] */ + /* moderation get-suggestions + * [--ignore-subjects uri]... [--limit N] */ if (strcmp(group, "moderation") == 0 && strcmp(sub, "get-suggestions") == 0) { const char *ignore_subjects[256]; @@ -287,19 +272,19 @@ int cmd_ozone(int argc, char **argv) { wf_status s = wf_ozone_moderation_get_suggestions( agent, ignore_subjects, ignore_count, limit, cursor, &out_json); if (s != WF_OK) { - fprintf(stderr, - "error: getSuggestions failed (status %d)\n", (int)s); + fprintf(stderr, "error: getSuggestions failed (status %d)\n", + (int)s); wf_agent_free(agent); return 1; } - if (out_json) - printf("%s\n", out_json); + if (out_json) printf("%s\n", out_json); free(out_json); wf_agent_free(agent); return 0; } - /* moderation get-label-definitions [--uri uri]... */ + /* moderation get-label-definitions [--uri + * uri]... */ if (strcmp(group, "moderation") == 0 && strcmp(sub, "get-label-definitions") == 0) { const char *uris[256]; @@ -313,9 +298,10 @@ int cmd_ozone(int argc, char **argv) { pos[pi++] = argv[i]; } if (pi < 3) { - fprintf(stderr, - "error: usage: wolfram ozone moderation get-label-definitions " - " [--uri uri]...\n"); + fprintf( + stderr, + "error: usage: wolfram ozone moderation get-label-definitions " + " [--uri uri]...\n"); return 1; } @@ -326,20 +312,19 @@ int cmd_ozone(int argc, char **argv) { wf_status s = wf_ozone_moderation_get_label_definitions( agent, uris, uri_count, &out_json); if (s != WF_OK) { - fprintf(stderr, - "error: getLabelDefinitions failed (status %d)\n", + fprintf(stderr, "error: getLabelDefinitions failed (status %d)\n", (int)s); wf_agent_free(agent); return 1; } - if (out_json) - printf("%s\n", out_json); + if (out_json) printf("%s\n", out_json); free(out_json); wf_agent_free(agent); return 0; } - /* team list-members [--limit N] [--cursor C] */ + /* team list-members [--limit N] [--cursor C] + */ if (strcmp(group, "team") == 0 && strcmp(sub, "list-members") == 0) { const char *cursor = NULL; int limit = 50; @@ -374,20 +359,17 @@ int cmd_ozone(int argc, char **argv) { wf_lex_tools_ozone_team_list_members_main_output *out = NULL; wf_status s = wf_ozone_team_listMembers(agent, ¶ms, &out); if (s != WF_OK) { - fprintf(stderr, - "error: listMembers failed (status %d)\n", (int)s); + fprintf(stderr, "error: listMembers failed (status %d)\n", (int)s); wf_lex_tools_ozone_team_list_members_main_output_free(out); wf_agent_free(agent); return 1; } - if (out->has_cursor && out->cursor) - printf("cursor: %s\n", out->cursor); + if (out->has_cursor && out->cursor) printf("cursor: %s\n", out->cursor); printf("count: %zu\n", out->members.count); for (size_t i = 0; i < out->members.count; ++i) print_team_member(out->members.items[i], i); - if (out->members.count == 0) - printf("(no team members)\n"); + if (out->members.count == 0) printf("(no team members)\n"); wf_lex_tools_ozone_team_list_members_main_output_free(out); wf_agent_free(agent); @@ -397,9 +379,8 @@ int cmd_ozone(int argc, char **argv) { /* server get-config */ if (strcmp(group, "server") == 0 && strcmp(sub, "get-config") == 0) { if (argc < 6) { - fprintf(stderr, - "error: usage: wolfram ozone server get-config " - " \n"); + fprintf(stderr, "error: usage: wolfram ozone server get-config " + " \n"); return 1; } @@ -409,8 +390,7 @@ int cmd_ozone(int argc, char **argv) { wf_lex_tools_ozone_server_get_config_main_output *out = NULL; wf_status s = wf_ozone_server_getConfig(agent, &out); if (s != WF_OK) { - fprintf(stderr, - "error: getConfig failed (status %d)\n", (int)s); + fprintf(stderr, "error: getConfig failed (status %d)\n", (int)s); wf_lex_tools_ozone_server_get_config_main_output_free(out); wf_agent_free(agent); return 1; @@ -420,7 +400,8 @@ int cmd_ozone(int argc, char **argv) { printf("appview: %s\n", out->appview->url); if (out->has_pds && out->pds && out->pds->has_url) printf("pds: %s\n", out->pds->url); - if (out->has_blob_divert && out->blob_divert && out->blob_divert->has_url) + if (out->has_blob_divert && out->blob_divert && + out->blob_divert->has_url) printf("blob_divert: %s\n", out->blob_divert->url); if (out->has_chat && out->chat && out->chat->has_url) printf("chat: %s\n", out->chat->url); @@ -450,8 +431,8 @@ int cmd_ozone(int argc, char **argv) { wf_lex_tools_ozone_communication_list_templates_main_output *out = NULL; wf_status s = wf_ozone_communication_listTemplates(agent, &out); if (s != WF_OK) { - fprintf(stderr, - "error: listTemplates failed (status %d)\n", (int)s); + fprintf(stderr, "error: listTemplates failed (status %d)\n", + (int)s); wf_lex_tools_ozone_communication_list_templates_main_output_free( out); wf_agent_free(agent); @@ -469,9 +450,9 @@ int cmd_ozone(int argc, char **argv) { return 0; } - /* setting list-options [--key key] [--scope scope] [--limit N] */ - if (strcmp(group, "setting") == 0 && - strcmp(sub, "list-options") == 0) { + /* setting list-options [--key key] [--scope + * scope] [--limit N] */ + if (strcmp(group, "setting") == 0 && strcmp(sub, "list-options") == 0) { const char *keys[256]; size_t key_count = 0; const char *scope = NULL; @@ -522,40 +503,38 @@ int cmd_ozone(int argc, char **argv) { wf_lex_tools_ozone_setting_list_options_main_output *out = NULL; wf_status s = wf_ozone_setting_listOptions(agent, ¶ms, &out); if (s != WF_OK) { - fprintf(stderr, - "error: listOptions failed (status %d)\n", (int)s); + fprintf(stderr, "error: listOptions failed (status %d)\n", (int)s); wf_lex_tools_ozone_setting_list_options_main_output_free(out); wf_agent_free(agent); return 1; } - if (out->has_cursor && out->cursor) - printf("cursor: %s\n", out->cursor); + if (out->has_cursor && out->cursor) printf("cursor: %s\n", out->cursor); printf("count: %zu\n", out->options.count); for (size_t i = 0; i < out->options.count; ++i) print_option(out->options.items[i], i); - if (out->options.count == 0) - printf("(no settings options)\n"); + if (out->options.count == 0) printf("(no settings options)\n"); wf_lex_tools_ozone_setting_list_options_main_output_free(out); wf_agent_free(agent); return 0; } - /* signature search-accounts [--limit N] */ + /* signature search-accounts [--limit N] + */ if (strcmp(group, "signature") == 0 && strcmp(sub, "search-accounts") == 0) { - if (argc < 6) { + if (argc < 7) { fprintf(stderr, "error: usage: wolfram ozone signature search-accounts " " [--limit N]\n"); return 1; } - const char *did = argv[3]; - const char *service = argv[4]; - const char *handle = argv[5]; - const char *password = argv[6]; + const char *service = argv[3]; + const char *handle = argv[4]; + const char *password = argv[5]; + const char *did = argv[6]; int limit = 50; const char *cursor = NULL; for (int i = 7; i < argc; ++i) { @@ -580,33 +559,29 @@ int cmd_ozone(int argc, char **argv) { } wf_lex_tools_ozone_signature_search_accounts_main_output *out = NULL; - wf_status s = - wf_ozone_signature_searchAccounts(agent, ¶ms, &out); + wf_status s = wf_ozone_signature_searchAccounts(agent, ¶ms, &out); if (s != WF_OK) { - fprintf(stderr, - "error: searchAccounts failed (status %d)\n", (int)s); - wf_lex_tools_ozone_signature_search_accounts_main_output_free( - out); + fprintf(stderr, "error: searchAccounts failed (status %d)\n", + (int)s); + wf_lex_tools_ozone_signature_search_accounts_main_output_free(out); wf_agent_free(agent); return 1; } - if (out->has_cursor && out->cursor) - printf("cursor: %s\n", out->cursor); + if (out->has_cursor && out->cursor) printf("cursor: %s\n", out->cursor); printf("count: %zu\n", out->accounts.count); for (size_t i = 0; i < out->accounts.count; ++i) print_account(out->accounts.items[i], i); - if (out->accounts.count == 0) - printf("(no accounts)\n"); + if (out->accounts.count == 0) printf("(no accounts)\n"); wf_lex_tools_ozone_signature_search_accounts_main_output_free(out); wf_agent_free(agent); return 0; } - /* report query-reports [--limit N] [--cursor C] */ - if (strcmp(group, "report") == 0 && - strcmp(sub, "query-reports") == 0) { + /* report query-reports [--limit N] [--cursor + * C] */ + if (strcmp(group, "report") == 0 && strcmp(sub, "query-reports") == 0) { const char *cursor = NULL; int limit = 50; const char *pos[3]; @@ -640,29 +615,26 @@ int cmd_ozone(int argc, char **argv) { wf_lex_tools_ozone_report_query_reports_main_output *out = NULL; wf_status s = wf_ozone_report_queryReports(agent, ¶ms, &out); if (s != WF_OK) { - fprintf(stderr, - "error: queryReports failed (status %d)\n", (int)s); + fprintf(stderr, "error: queryReports failed (status %d)\n", (int)s); wf_lex_tools_ozone_report_query_reports_main_output_free(out); wf_agent_free(agent); return 1; } - if (out->has_cursor && out->cursor) - printf("cursor: %s\n", out->cursor); + if (out->has_cursor && out->cursor) printf("cursor: %s\n", out->cursor); printf("count: %zu\n", out->reports.count); for (size_t i = 0; i < out->reports.count; ++i) print_report(out->reports.items[i], i); - if (out->reports.count == 0) - printf("(no reports)\n"); + if (out->reports.count == 0) printf("(no reports)\n"); wf_lex_tools_ozone_report_query_reports_main_output_free(out); wf_agent_free(agent); return 0; } - /* queue list-queues [--limit N] [--cursor C] */ - if (strcmp(group, "queue") == 0 && - strcmp(sub, "list-queues") == 0) { + /* queue list-queues [--limit N] [--cursor C] + */ + if (strcmp(group, "queue") == 0 && strcmp(sub, "list-queues") == 0) { const char *cursor = NULL; int limit = 50; const char *pos[3]; @@ -696,20 +668,17 @@ int cmd_ozone(int argc, char **argv) { wf_lex_tools_ozone_queue_list_queues_main_output *out = NULL; wf_status s = wf_ozone_queue_listQueues(agent, ¶ms, &out); if (s != WF_OK) { - fprintf(stderr, - "error: listQueues failed (status %d)\n", (int)s); + fprintf(stderr, "error: listQueues failed (status %d)\n", (int)s); wf_lex_tools_ozone_queue_list_queues_main_output_free(out); wf_agent_free(agent); return 1; } - if (out->has_cursor && out->cursor) - printf("cursor: %s\n", out->cursor); + if (out->has_cursor && out->cursor) printf("cursor: %s\n", out->cursor); printf("count: %zu\n", out->queues.count); for (size_t i = 0; i < out->queues.count; ++i) print_queue(out->queues.items[i], i); - if (out->queues.count == 0) - printf("(no queues)\n"); + if (out->queues.count == 0) printf("(no queues)\n"); wf_lex_tools_ozone_queue_list_queues_main_output_free(out); wf_agent_free(agent); diff --git a/src/cli/cli_prefs.c b/src/cli/cli_prefs.c index 87ffd9e..92b5c2a 100644 --- a/src/cli/cli_prefs.c +++ b/src/cli/cli_prefs.c @@ -61,13 +61,13 @@ int cmd_preferences(int argc, char **argv) { if (!agent) return 1; wf_response res = {0}; - wf_status s = - wf_agent_put_preferences(agent, prefs_json_str, &res); + wf_status s = wf_agent_put_preferences(agent, prefs_json_str, &res); return finish_agent_response(agent, s, &res); } - fprintf(stderr, "error: unknown preferences subcommand '%s' (try " - "get/put)\n", + fprintf(stderr, + "error: unknown preferences subcommand '%s' (try " + "get/put)\n", sub); return 1; } @@ -198,8 +198,8 @@ int cmd_put_actor_status(int argc, char **argv) { if (!agent) return 1; wf_agent_post_result out = {0}; - wf_status s = wf_agent_put_actor_status(agent, status, duration, - embed_json, &out); + wf_status s = + wf_agent_put_actor_status(agent, status, duration, embed_json, &out); if (s != WF_OK) { fprintf(stderr, "error: putActorStatus failed (status %d)\n", (int)s); wf_agent_post_result_free(&out); @@ -231,9 +231,7 @@ int cmd_upload_blob(int argc, char **argv) { return 1; } - char *data = read_text_file(pos[2] ? pos[2] : file_path); - /* Re-read the actual file, not the password */ - data = read_text_file(file_path); + char *data = read_text_file(file_path); if (!data) { fprintf(stderr, "error: could not read file '%s'\n", file_path); return 1; @@ -257,8 +255,8 @@ int cmd_upload_blob(int argc, char **argv) { } wf_response res = {0}; - wf_status s = wf_agent_upload_blob(agent, data, (size_t)file_len, - content_type, &res); + wf_status s = + wf_agent_upload_blob(agent, data, (size_t)file_len, content_type, &res); free(data); return finish_agent_response(agent, s, &res); } @@ -360,7 +358,7 @@ int cmd_send_interactions(int argc, char **argv) { if (!agent) return 1; wf_response res = {0}; - wf_status s = wf_agent_send_interactions(agent, feed_uri, - interactions_json, &res); + wf_status s = + wf_agent_send_interactions(agent, feed_uri, interactions_json, &res); return finish_agent_response(agent, s, &res); } diff --git a/src/cli/cli_search.c b/src/cli/cli_search.c index e65aa0c..e68a922 100644 --- a/src/cli/cli_search.c +++ b/src/cli/cli_search.c @@ -97,8 +97,10 @@ int cmd_moderation(int argc, char **argv) { return 1; } - const char *rt = reason_type ? reason_type : reason; - const char *free_reason = reason_type ? reason : NULL; + const char *rt = reason_type + ? reason_type + : "com.atproto.moderation.defs#reasonOther"; + const char *free_reason = reason; wf_agent *agent = agent_login_or_err(pos[0], pos[1], pos[2]); if (!agent) return 1; @@ -198,9 +200,8 @@ int cmd_search(int argc, char **argv) { } wf_response res = {0}; - wf_status s = - wf_agent_search_posts(agent, query, limit, NULL, NULL, NULL, NULL, NULL, - &res); + wf_status s = wf_agent_search_posts(agent, query, limit, NULL, NULL, NULL, + NULL, NULL, &res); return finish_agent_response(agent, s, &res); } @@ -221,8 +222,7 @@ int cmd_search_actors(int argc, char **argv) { } wf_response res = {0}; - wf_status s = - wf_agent_search_actors(agent, query, limit, NULL, &res); + wf_status s = wf_agent_search_actors(agent, query, limit, NULL, &res); return finish_agent_response(agent, s, &res); } @@ -243,8 +243,7 @@ int cmd_search_typeahead(int argc, char **argv) { } wf_response res = {0}; - wf_status s = - wf_agent_search_actors_typeahead(agent, query, limit, &res); + wf_status s = wf_agent_search_actors_typeahead(agent, query, limit, &res); return finish_agent_response(agent, s, &res); } @@ -321,10 +320,14 @@ int cmd_labels(int argc, char **argv) { opts.on_info = label_on_info; opts.on_error = label_on_error; - printf( - "subscribing to label stream at %s (cursor=%s, max %d events, %ds)\n", - service, has_cursor ? argv[2] : "none", CLI_LABEL_MAX_EVENTS, - g_label_seconds); + if (has_cursor) + printf("subscribing to label stream at %s (cursor=%" PRId64 + ", max %d events, %ds)\n", + service, cursor, CLI_LABEL_MAX_EVENTS, g_label_seconds); + else + printf("subscribing to label stream at %s (cursor=none, max %d " + "events, %ds)\n", + service, CLI_LABEL_MAX_EVENTS, g_label_seconds); wf_label_subscribe_handle *handle = NULL; g_label_handle_ptr = &handle; diff --git a/src/cli/main.c b/src/cli/main.c index 381a18d..2ca4204 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -107,6 +107,7 @@ #include "cli_repo.h" #include "cli_video.h" #include "cli_ozone.h" +#include "cli_admin.h" #include "wolfram/thread_typed.h" #include "wolfram/feed_typed.h" #include "wolfram/actor_typed.h" @@ -956,6 +957,15 @@ int main(int argc, char **argv) { if (strcmp(cmd, "search") == 0) { return cmd_search(rest, cargv); } + if (strcmp(cmd, "search-actors") == 0) { + return cmd_search_actors(rest, cargv); + } + if (strcmp(cmd, "search-typeahead") == 0) { + return cmd_search_typeahead(rest, cargv); + } + if (strcmp(cmd, "search-starter-packs") == 0) { + return cmd_search_starter_packs(rest, cargv); + } if (strcmp(cmd, "moderation") == 0) { return cmd_moderation(rest, cargv); } @@ -1045,6 +1055,18 @@ int main(int argc, char **argv) { if (strcmp(cmd, "unread-count") == 0) { return cmd_unread_count(rest, cargv); } + if (strcmp(cmd, "get-actor-status") == 0) { + return cmd_get_actor_status(rest, cargv); + } + if (strcmp(cmd, "get-feed-generators") == 0) { + return cmd_get_feed_generators(rest, cargv); + } + if (strcmp(cmd, "get-suggested-follows-by-actor") == 0) { + return cmd_get_suggested_follows_by_actor(rest, cargv); + } + if (strcmp(cmd, "age-assurance") == 0) { + return cmd_age_assurance(rest, cargv); + } /* --- Graph & list operations --- */ if (strcmp(cmd, "mute-list") == 0) { @@ -1118,6 +1140,9 @@ int main(int argc, char **argv) { if (strcmp(cmd, "request-email-confirmation") == 0) { return cmd_request_email_confirmation(rest, cargv); } + if (strcmp(cmd, "admin") == 0) { + return cmd_admin(rest, cargv); + } /* --- Identity --- */ if (strcmp(cmd, "resolve-did") == 0) {