x0x 0.15.2

Agent-to-agent gossip network for AI systems — no winners, no losers, just cooperation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
//! Shared endpoint registry for the x0x REST API.
//!
//! Both `x0xd` (the daemon) and `x0x` (the CLI) consume this registry,
//! ensuring routes and CLI commands never drift out of sync.

/// HTTP method for an endpoint.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Method {
    /// HTTP GET
    Get,
    /// HTTP POST
    Post,
    /// HTTP PUT
    Put,
    /// HTTP PATCH
    Patch,
    /// HTTP DELETE
    Delete,
}

impl std::fmt::Display for Method {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Method::Get => write!(f, "GET"),
            Method::Post => write!(f, "POST"),
            Method::Put => write!(f, "PUT"),
            Method::Patch => write!(f, "PATCH"),
            Method::Delete => write!(f, "DELETE"),
        }
    }
}

/// A single API endpoint definition.
#[derive(Debug, Clone)]
pub struct EndpointDef {
    /// HTTP method.
    pub method: Method,
    /// URL path pattern (e.g. "/contacts/:agent_id").
    pub path: &'static str,
    /// CLI command name (e.g. "contacts update").
    pub cli_name: &'static str,
    /// Human-readable description.
    pub description: &'static str,
    /// Grouping category.
    pub category: &'static str,
}

/// Complete registry of all x0x API endpoints.
pub const ENDPOINTS: &[EndpointDef] = &[
    // ── Status ──────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/health",
        cli_name: "health",
        description: "Health check",
        category: "status",
    },
    EndpointDef {
        method: Method::Get,
        path: "/status",
        cli_name: "status",
        description: "Runtime status with uptime",
        category: "status",
    },
    EndpointDef {
        method: Method::Post,
        path: "/shutdown",
        cli_name: "stop",
        description: "Gracefully stop the daemon",
        category: "status",
    },
    // ── Identity ────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/agent",
        cli_name: "agent",
        description: "Agent identity info",
        category: "identity",
    },
    EndpointDef {
        method: Method::Post,
        path: "/announce",
        cli_name: "announce",
        description: "Announce identity to network",
        category: "identity",
    },
    EndpointDef {
        method: Method::Get,
        path: "/agent/user-id",
        cli_name: "agent user-id",
        description: "Current agent user ID",
        category: "identity",
    },
    EndpointDef {
        method: Method::Get,
        path: "/agent/card",
        cli_name: "agent card",
        description: "Generate shareable identity card",
        category: "identity",
    },
    EndpointDef {
        method: Method::Post,
        path: "/agent/card/import",
        cli_name: "agent import",
        description: "Import agent card to contacts",
        category: "identity",
    },
    // ── Network ─────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/peers",
        cli_name: "peers",
        description: "Connected gossip peers",
        category: "network",
    },
    EndpointDef {
        method: Method::Get,
        path: "/presence",
        cli_name: "presence",
        description: "Online agents (alias for /presence/online)",
        category: "presence",
    },
    // ── Presence ────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/presence/online",
        cli_name: "presence online",
        description: "List all currently online agents (network view, non-blocked)",
        category: "presence",
    },
    EndpointDef {
        method: Method::Get,
        path: "/presence/foaf",
        cli_name: "presence foaf",
        description: "FOAF random-walk discovery of nearby agents (social view)",
        category: "presence",
    },
    EndpointDef {
        method: Method::Get,
        path: "/presence/find/:id",
        cli_name: "presence find",
        description: "Find a specific agent by ID via FOAF random walk",
        category: "presence",
    },
    EndpointDef {
        method: Method::Get,
        path: "/presence/status/:id",
        cli_name: "presence status",
        description: "Get local cache presence status for an agent",
        category: "presence",
    },
    EndpointDef {
        method: Method::Get,
        path: "/presence/events",
        cli_name: "presence events",
        description: "Server-Sent Events stream of presence online/offline events",
        category: "presence",
    },
    EndpointDef {
        method: Method::Get,
        path: "/network/status",
        cli_name: "network status",
        description: "Network connectivity details",
        category: "network",
    },
    EndpointDef {
        method: Method::Get,
        path: "/network/bootstrap-cache",
        cli_name: "network cache",
        description: "Bootstrap peer cache stats",
        category: "network",
    },
    // ── Messaging ───────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Post,
        path: "/publish",
        cli_name: "publish",
        description: "Publish message to topic",
        category: "messaging",
    },
    EndpointDef {
        method: Method::Post,
        path: "/subscribe",
        cli_name: "subscribe",
        description: "Subscribe to topic",
        category: "messaging",
    },
    EndpointDef {
        method: Method::Delete,
        path: "/subscribe/:id",
        cli_name: "unsubscribe",
        description: "Unsubscribe by ID",
        category: "messaging",
    },
    EndpointDef {
        method: Method::Get,
        path: "/events",
        cli_name: "events",
        description: "SSE event stream",
        category: "messaging",
    },
    // ── Discovery ───────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/agents/discovered",
        cli_name: "agents list",
        description: "List discovered agents",
        category: "discovery",
    },
    EndpointDef {
        method: Method::Get,
        path: "/agents/discovered/:agent_id",
        cli_name: "agents get",
        description: "Get discovered agent details",
        category: "discovery",
    },
    EndpointDef {
        method: Method::Post,
        path: "/agents/find/:agent_id",
        cli_name: "agents find",
        description: "Find agent on network",
        category: "discovery",
    },
    EndpointDef {
        method: Method::Get,
        path: "/agents/reachability/:agent_id",
        cli_name: "agents reachability",
        description: "Agent reachability info",
        category: "discovery",
    },
    EndpointDef {
        method: Method::Get,
        path: "/users/:user_id/agents",
        cli_name: "agents by-user",
        description: "Agents by user ID",
        category: "discovery",
    },
    // ── Contacts ────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/contacts",
        cli_name: "contacts list",
        description: "List contacts",
        category: "contacts",
    },
    EndpointDef {
        method: Method::Post,
        path: "/contacts",
        cli_name: "contacts add",
        description: "Add contact",
        category: "contacts",
    },
    EndpointDef {
        method: Method::Post,
        path: "/contacts/trust",
        cli_name: "trust set",
        description: "Quick trust/block",
        category: "contacts",
    },
    EndpointDef {
        method: Method::Patch,
        path: "/contacts/:agent_id",
        cli_name: "contacts update",
        description: "Update contact trust",
        category: "contacts",
    },
    EndpointDef {
        method: Method::Delete,
        path: "/contacts/:agent_id",
        cli_name: "contacts remove",
        description: "Remove contact",
        category: "contacts",
    },
    EndpointDef {
        method: Method::Post,
        path: "/contacts/:agent_id/revoke",
        cli_name: "contacts revoke",
        description: "Revoke contact",
        category: "contacts",
    },
    EndpointDef {
        method: Method::Get,
        path: "/contacts/:agent_id/revocations",
        cli_name: "contacts revocations",
        description: "List revocations",
        category: "contacts",
    },
    // ── Machines ────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/contacts/:agent_id/machines",
        cli_name: "machines list",
        description: "List machines for contact",
        category: "machines",
    },
    EndpointDef {
        method: Method::Post,
        path: "/contacts/:agent_id/machines",
        cli_name: "machines add",
        description: "Add machine record",
        category: "machines",
    },
    EndpointDef {
        method: Method::Delete,
        path: "/contacts/:agent_id/machines/:machine_id",
        cli_name: "machines remove",
        description: "Remove machine record",
        category: "machines",
    },
    EndpointDef {
        method: Method::Post,
        path: "/contacts/:agent_id/machines/:machine_id/pin",
        cli_name: "machines pin",
        description: "Pin machine",
        category: "machines",
    },
    EndpointDef {
        method: Method::Delete,
        path: "/contacts/:agent_id/machines/:machine_id/pin",
        cli_name: "machines unpin",
        description: "Unpin machine",
        category: "machines",
    },
    // ── Trust ───────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Post,
        path: "/trust/evaluate",
        cli_name: "trust evaluate",
        description: "Evaluate trust for agent+machine",
        category: "trust",
    },
    // ── Direct messaging ────────────────────────────────────────────────
    EndpointDef {
        method: Method::Post,
        path: "/agents/connect",
        cli_name: "direct connect",
        description: "Connect to agent",
        category: "direct",
    },
    EndpointDef {
        method: Method::Post,
        path: "/direct/send",
        cli_name: "direct send",
        description: "Send direct message",
        category: "direct",
    },
    EndpointDef {
        method: Method::Get,
        path: "/direct/connections",
        cli_name: "direct connections",
        description: "List direct connections",
        category: "direct",
    },
    EndpointDef {
        method: Method::Get,
        path: "/direct/events",
        cli_name: "direct events",
        description: "Stream direct messages",
        category: "direct",
    },
    // ── MLS groups ──────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Post,
        path: "/mls/groups",
        cli_name: "groups create",
        description: "Create encrypted group",
        category: "groups",
    },
    EndpointDef {
        method: Method::Get,
        path: "/mls/groups",
        cli_name: "groups list",
        description: "List groups",
        category: "groups",
    },
    EndpointDef {
        method: Method::Get,
        path: "/mls/groups/:id",
        cli_name: "groups get",
        description: "Get group details",
        category: "groups",
    },
    EndpointDef {
        method: Method::Post,
        path: "/mls/groups/:id/members",
        cli_name: "groups add-member",
        description: "Add member to group",
        category: "groups",
    },
    EndpointDef {
        method: Method::Delete,
        path: "/mls/groups/:id/members/:agent_id",
        cli_name: "groups remove-member",
        description: "Remove member",
        category: "groups",
    },
    EndpointDef {
        method: Method::Post,
        path: "/mls/groups/:id/encrypt",
        cli_name: "groups encrypt",
        description: "Encrypt for group",
        category: "groups",
    },
    EndpointDef {
        method: Method::Post,
        path: "/mls/groups/:id/decrypt",
        cli_name: "groups decrypt",
        description: "Decrypt from group",
        category: "groups",
    },
    EndpointDef {
        method: Method::Post,
        path: "/mls/groups/:id/welcome",
        cli_name: "groups welcome",
        description: "Create welcome for member",
        category: "groups",
    },
    // ── Named groups (high-level) ─────────────────────────────────────
    EndpointDef {
        method: Method::Post,
        path: "/groups",
        cli_name: "group create",
        description: "Create named group",
        category: "named-groups",
    },
    EndpointDef {
        method: Method::Get,
        path: "/groups",
        cli_name: "group list",
        description: "List groups",
        category: "named-groups",
    },
    EndpointDef {
        method: Method::Get,
        path: "/groups/:id",
        cli_name: "group info",
        description: "Get group info",
        category: "named-groups",
    },
    EndpointDef {
        method: Method::Post,
        path: "/groups/:id/invite",
        cli_name: "group invite",
        description: "Generate invite link",
        category: "named-groups",
    },
    EndpointDef {
        method: Method::Post,
        path: "/groups/join",
        cli_name: "group join",
        description: "Join group via invite",
        category: "named-groups",
    },
    EndpointDef {
        method: Method::Put,
        path: "/groups/:id/display-name",
        cli_name: "group set-name",
        description: "Set display name in group",
        category: "named-groups",
    },
    EndpointDef {
        method: Method::Delete,
        path: "/groups/:id",
        cli_name: "group leave",
        description: "Leave or delete a group",
        category: "named-groups",
    },
    // ── Task lists ──────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/task-lists",
        cli_name: "tasks list",
        description: "List task lists",
        category: "tasks",
    },
    EndpointDef {
        method: Method::Post,
        path: "/task-lists",
        cli_name: "tasks create",
        description: "Create task list",
        category: "tasks",
    },
    EndpointDef {
        method: Method::Get,
        path: "/task-lists/:id/tasks",
        cli_name: "tasks show",
        description: "Show tasks in list",
        category: "tasks",
    },
    EndpointDef {
        method: Method::Post,
        path: "/task-lists/:id/tasks",
        cli_name: "tasks add",
        description: "Add task to list",
        category: "tasks",
    },
    EndpointDef {
        method: Method::Patch,
        path: "/task-lists/:id/tasks/:tid",
        cli_name: "tasks claim / tasks complete",
        description: "Claim or complete a task (action: claim|complete)",
        category: "tasks",
    },
    // ── Key-value stores ────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/stores",
        cli_name: "store list",
        description: "List key-value stores",
        category: "stores",
    },
    EndpointDef {
        method: Method::Post,
        path: "/stores",
        cli_name: "store create",
        description: "Create key-value store",
        category: "stores",
    },
    EndpointDef {
        method: Method::Post,
        path: "/stores/:id/join",
        cli_name: "store join",
        description: "Join existing store",
        category: "stores",
    },
    EndpointDef {
        method: Method::Get,
        path: "/stores/:id/keys",
        cli_name: "store keys",
        description: "List keys in store",
        category: "stores",
    },
    EndpointDef {
        method: Method::Put,
        path: "/stores/:id/:key",
        cli_name: "store put",
        description: "Put value in store",
        category: "stores",
    },
    EndpointDef {
        method: Method::Get,
        path: "/stores/:id/:key",
        cli_name: "store get",
        description: "Get value from store",
        category: "stores",
    },
    EndpointDef {
        method: Method::Delete,
        path: "/stores/:id/:key",
        cli_name: "store rm",
        description: "Remove key from store",
        category: "stores",
    },
    // ── Files ──────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Post,
        path: "/files/send",
        cli_name: "send-file",
        description: "Send file to agent",
        category: "files",
    },
    EndpointDef {
        method: Method::Get,
        path: "/files/transfers",
        cli_name: "transfers",
        description: "List file transfers",
        category: "files",
    },
    EndpointDef {
        method: Method::Get,
        path: "/files/transfers/:id",
        cli_name: "transfer-status",
        description: "Transfer status",
        category: "files",
    },
    EndpointDef {
        method: Method::Post,
        path: "/files/accept/:id",
        cli_name: "accept-file",
        description: "Accept incoming transfer",
        category: "files",
    },
    EndpointDef {
        method: Method::Post,
        path: "/files/reject/:id",
        cli_name: "reject-file",
        description: "Reject incoming transfer",
        category: "files",
    },
    // ── Constitution ──────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/constitution",
        cli_name: "constitution",
        description: "Display the x0x Constitution (Markdown)",
        category: "status",
    },
    EndpointDef {
        method: Method::Get,
        path: "/constitution/json",
        cli_name: "constitution --json",
        description: "Constitution with version metadata (JSON)",
        category: "status",
    },
    // ── Upgrade ─────────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/upgrade",
        cli_name: "upgrade",
        description: "Check for updates",
        category: "upgrade",
    },
    // ── WebSocket ───────────────────────────────────────────────────────
    EndpointDef {
        method: Method::Get,
        path: "/ws",
        cli_name: "ws",
        description: "General-purpose WebSocket session",
        category: "websocket",
    },
    EndpointDef {
        method: Method::Get,
        path: "/ws/direct",
        cli_name: "ws direct",
        description: "WebSocket session for direct messaging",
        category: "websocket",
    },
    EndpointDef {
        method: Method::Get,
        path: "/ws/sessions",
        cli_name: "ws sessions",
        description: "List WebSocket sessions",
        category: "websocket",
    },
    EndpointDef {
        method: Method::Get,
        path: "/gui",
        cli_name: "gui",
        description: "Open the embedded GUI",
        category: "websocket",
    },
];

/// Find an endpoint by its CLI name.
pub fn find_by_cli_name(name: &str) -> Option<&'static EndpointDef> {
    ENDPOINTS.iter().find(|e| e.cli_name == name)
}

/// Get all endpoints in a given category.
pub fn by_category(category: &str) -> Vec<&'static EndpointDef> {
    ENDPOINTS
        .iter()
        .filter(|e| e.category == category)
        .collect()
}

/// Get all unique categories, in order of first appearance.
pub fn categories() -> Vec<&'static str> {
    let mut cats: Vec<&'static str> = Vec::new();
    for ep in ENDPOINTS {
        if !cats.contains(&ep.category) {
            cats.push(ep.category);
        }
    }
    cats
}