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
// @generated by idiolect-codegen. do not edit.
// source: dev.idiolect.adapter
//! A subprocess or HTTP-endpoint wrapper for a framework's tooling, authored by incentive-aligned parties. Adapters are how idiolect glues existing frameworks (Hasura, Prisma, Datomic, FHIR, Coq, Meilisearch, ...) without forking them.
#![allow(
missing_docs,
clippy::doc_markdown,
clippy::struct_excessive_bools,
clippy::derive_partial_eq_without_eq,
clippy::large_enum_variant
)]
use serde::{Deserialize, Serialize};
/// Declaration that a specific tool version can be invoked via a specific protocol under named isolation requirements. Orchestrators and observers use adapters to run third-party tools in a known, reproducible way.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Adapter {
/// DID of the adapter author. Not an endorsement; users judge.
pub author: idiolect_records::Did,
/// Canonical framework name, e.g. 'hasura', 'prisma', 'datomic', 'fhir-validator', 'coq', 'meilisearch'.
pub framework: String,
/// How the adapter is invoked.
pub invocation_protocol: AdapterInvocationProtocol,
/// Sandboxing requirements the orchestrator must honour.
pub isolation: AdapterIsolation,
pub occurred_at: idiolect_records::Datetime,
/// Optional verification record demonstrating the adapter's conformance.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub verification: Option<idiolect_records::AtUri>,
/// Semver range the adapter supports.
pub version_range: String,
}
impl crate::Record for Adapter {
const NSID: &'static str = "dev.idiolect.adapter";
}
/// How the adapter is invoked.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AdapterInvocationProtocol {
/// Binary name (subprocess), URL (http), or wasm module reference.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub entry_point: Option<String>,
/// Schema of the adapter's input.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub input_schema: Option<crate::generated::dev::idiolect::defs::SchemaRef>,
/// Open-enum transport protocol slug. Resolved against `kindVocab` when present, otherwise against the canonical idiolect invocation-protocols vocabulary.
pub kind: AdapterInvocationProtocolKind,
/// Vocabulary the `kind` slug resolves against. Omit to use the canonical idiolect default.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub kind_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
/// Schema of the adapter's output.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub output_schema: Option<crate::generated::dev::idiolect::defs::SchemaRef>,
}
/// AdapterInvocationProtocolKind. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AdapterInvocationProtocolKind {
Subprocess,
Http,
Wasm,
/// Community-extended slug not present in the lexicon's
/// `knownValues`. Resolves through the sibling
/// `*Vocab` field on the containing record.
Other(String),
}
impl AdapterInvocationProtocolKind {
/// Wire-form slug for this value. Known variants render
/// kebab-case; the fallback variant passes through verbatim.
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::Subprocess => "subprocess",
Self::Http => "http",
Self::Wasm => "wasm",
Self::Other(s) => s.as_str(),
}
}
/// Whether this slug is subsumed by `ancestor` under the
/// `subsumed_by` relation in the supplied vocab. Reflexive:
/// every slug is subsumed by itself.
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
/// Whether this slug satisfies a requirement of `target`
/// under the named `relation` in the supplied vocab.
/// Generalises `is_subsumed_by` to any directed relation
/// (e.g. `stronger_than`, `provides_at_least`,
/// `equivalent_to`). Reflexive: a slug satisfies itself.
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
/// Translate this slug across vocabularies via
/// `equivalent_to` edges. Returns the translated slug as
/// a target enum value when a translation exists, `None`
/// when no path is found (callers fall back to passing
/// the slug through verbatim, which is wire-compatible).
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for AdapterInvocationProtocolKind {
fn from(s: String) -> Self {
match s.as_str() {
"subprocess" => Self::Subprocess,
"http" => Self::Http,
"wasm" => Self::Wasm,
_ => Self::Other(s),
}
}
}
impl From<&str> for AdapterInvocationProtocolKind {
fn from(s: &str) -> Self {
match s {
"subprocess" => Self::Subprocess,
"http" => Self::Http,
"wasm" => Self::Wasm,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for AdapterInvocationProtocolKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for AdapterInvocationProtocolKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
/// Sandboxing requirements the orchestrator must honour.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AdapterIsolation {
/// Open-enum filesystem-access policy. Resolved against `filesystemPolicyVocab` when present.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub filesystem_policy: Option<AdapterIsolationFilesystemPolicy>,
/// Vocabulary the `filesystemPolicy` slug resolves against.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub filesystem_policy_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
/// Open-enum isolation kind. Resolved against `kindVocab` when present.
pub kind: AdapterIsolationKind,
/// Vocabulary the `kind` slug resolves against.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub kind_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
/// Open-enum network-access policy. Resolved against `networkPolicyVocab` when present.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub network_policy: Option<AdapterIsolationNetworkPolicy>,
/// Vocabulary the `networkPolicy` slug resolves against.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub network_policy_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub resource_limits: Option<AdapterIsolationResourceLimits>,
}
/// AdapterIsolationFilesystemPolicy. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AdapterIsolationFilesystemPolicy {
Readonly,
Scratch,
WritableSubtree,
Full,
/// Community-extended slug not present in the lexicon's
/// `knownValues`. Resolves through the sibling
/// `*Vocab` field on the containing record.
Other(String),
}
impl AdapterIsolationFilesystemPolicy {
/// Wire-form slug for this value. Known variants render
/// kebab-case; the fallback variant passes through verbatim.
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::Readonly => "readonly",
Self::Scratch => "scratch",
Self::WritableSubtree => "writable-subtree",
Self::Full => "full",
Self::Other(s) => s.as_str(),
}
}
/// Whether this slug is subsumed by `ancestor` under the
/// `subsumed_by` relation in the supplied vocab. Reflexive:
/// every slug is subsumed by itself.
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
/// Whether this slug satisfies a requirement of `target`
/// under the named `relation` in the supplied vocab.
/// Generalises `is_subsumed_by` to any directed relation
/// (e.g. `stronger_than`, `provides_at_least`,
/// `equivalent_to`). Reflexive: a slug satisfies itself.
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
/// Translate this slug across vocabularies via
/// `equivalent_to` edges. Returns the translated slug as
/// a target enum value when a translation exists, `None`
/// when no path is found (callers fall back to passing
/// the slug through verbatim, which is wire-compatible).
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for AdapterIsolationFilesystemPolicy {
fn from(s: String) -> Self {
match s.as_str() {
"readonly" => Self::Readonly,
"scratch" => Self::Scratch,
"writable-subtree" => Self::WritableSubtree,
"full" => Self::Full,
_ => Self::Other(s),
}
}
}
impl From<&str> for AdapterIsolationFilesystemPolicy {
fn from(s: &str) -> Self {
match s {
"readonly" => Self::Readonly,
"scratch" => Self::Scratch,
"writable-subtree" => Self::WritableSubtree,
"full" => Self::Full,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for AdapterIsolationFilesystemPolicy {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for AdapterIsolationFilesystemPolicy {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
/// AdapterIsolationKind. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AdapterIsolationKind {
None,
Process,
Container,
Vm,
WasmSandbox,
/// Community-extended slug not present in the lexicon's
/// `knownValues`. Resolves through the sibling
/// `*Vocab` field on the containing record.
Other(String),
}
impl AdapterIsolationKind {
/// Wire-form slug for this value. Known variants render
/// kebab-case; the fallback variant passes through verbatim.
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::None => "none",
Self::Process => "process",
Self::Container => "container",
Self::Vm => "vm",
Self::WasmSandbox => "wasm-sandbox",
Self::Other(s) => s.as_str(),
}
}
/// Whether this slug is subsumed by `ancestor` under the
/// `subsumed_by` relation in the supplied vocab. Reflexive:
/// every slug is subsumed by itself.
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
/// Whether this slug satisfies a requirement of `target`
/// under the named `relation` in the supplied vocab.
/// Generalises `is_subsumed_by` to any directed relation
/// (e.g. `stronger_than`, `provides_at_least`,
/// `equivalent_to`). Reflexive: a slug satisfies itself.
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
/// Translate this slug across vocabularies via
/// `equivalent_to` edges. Returns the translated slug as
/// a target enum value when a translation exists, `None`
/// when no path is found (callers fall back to passing
/// the slug through verbatim, which is wire-compatible).
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for AdapterIsolationKind {
fn from(s: String) -> Self {
match s.as_str() {
"none" => Self::None,
"process" => Self::Process,
"container" => Self::Container,
"vm" => Self::Vm,
"wasm-sandbox" => Self::WasmSandbox,
_ => Self::Other(s),
}
}
}
impl From<&str> for AdapterIsolationKind {
fn from(s: &str) -> Self {
match s {
"none" => Self::None,
"process" => Self::Process,
"container" => Self::Container,
"vm" => Self::Vm,
"wasm-sandbox" => Self::WasmSandbox,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for AdapterIsolationKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for AdapterIsolationKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
/// AdapterIsolationNetworkPolicy. Open-enum slug; known values are kebab-cased; community-extended values pass through as `Other(String)`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AdapterIsolationNetworkPolicy {
None,
EgressDenylist,
EgressAllowlist,
Full,
/// Community-extended slug not present in the lexicon's
/// `knownValues`. Resolves through the sibling
/// `*Vocab` field on the containing record.
Other(String),
}
impl AdapterIsolationNetworkPolicy {
/// Wire-form slug for this value. Known variants render
/// kebab-case; the fallback variant passes through verbatim.
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::None => "none",
Self::EgressDenylist => "egress-denylist",
Self::EgressAllowlist => "egress-allowlist",
Self::Full => "full",
Self::Other(s) => s.as_str(),
}
}
/// Whether this slug is subsumed by `ancestor` under the
/// `subsumed_by` relation in the supplied vocab. Reflexive:
/// every slug is subsumed by itself.
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
/// Whether this slug satisfies a requirement of `target`
/// under the named `relation` in the supplied vocab.
/// Generalises `is_subsumed_by` to any directed relation
/// (e.g. `stronger_than`, `provides_at_least`,
/// `equivalent_to`). Reflexive: a slug satisfies itself.
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
/// Translate this slug across vocabularies via
/// `equivalent_to` edges. Returns the translated slug as
/// a target enum value when a translation exists, `None`
/// when no path is found (callers fall back to passing
/// the slug through verbatim, which is wire-compatible).
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for AdapterIsolationNetworkPolicy {
fn from(s: String) -> Self {
match s.as_str() {
"none" => Self::None,
"egress-denylist" => Self::EgressDenylist,
"egress-allowlist" => Self::EgressAllowlist,
"full" => Self::Full,
_ => Self::Other(s),
}
}
}
impl From<&str> for AdapterIsolationNetworkPolicy {
fn from(s: &str) -> Self {
match s {
"none" => Self::None,
"egress-denylist" => Self::EgressDenylist,
"egress-allowlist" => Self::EgressAllowlist,
"full" => Self::Full,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for AdapterIsolationNetworkPolicy {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for AdapterIsolationNetworkPolicy {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AdapterIsolationResourceLimits {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_cpu_seconds: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_memory_bytes: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_wall_seconds: Option<i64>,
}