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
//! Script names and the IRIs built from them.
//!
//! A script is named by one segment, `urn:script:{name}`, and everything about it hangs
//! below that name: `…:version:{digest}`, `…:compiled`, `…:result`, `…:runs` and
//! `…:run:{id}`. The name is a segment of the IRI rather than an argument so that a
//! capability can bind to it (`urn:cap:script:run:{name}`), which is the same reason
//! `ikigai-ledger` names its ledgers.
//!
//! ```
//! use ikigai_script::name;
//!
//! assert_eq!(name::script_iri("nightly"), "urn:script:nightly");
//! assert_eq!(
//! name::version_iri("nightly", "sha256:ab"),
//! "urn:script:nightly:version:sha256:ab"
//! );
//! assert_eq!(name::run_iri("nightly", 7), "urn:script:nightly:run:7");
//! assert!(name::validate("nightly-report_2").is_ok());
//! assert!(name::validate("Nightly").is_err()); // lowercase only
//! assert!(name::validate("a:b").is_err()); // one segment
//! assert!(name::validate("eval").is_err()); // reserved: `urn:script:eval` is the paste box
//! ```
use ;
/// Every script IRI starts here.
pub const PREFIX: &str = "urn:script:";
/// The ad hoc door: run supplied code under the caller's own authority.
pub const EVAL_IRI: &str = "urn:script:eval";
/// The catalog: what is registered, its state, head version and last run.
///
/// ★ Not `urn:host:scripts`. `urn:host:*` is the HOST's namespace (`urn:host:info`,
/// `urn:host:identity`, `urn:host:arrangement` in ikigai-cli), and a library binding
/// into it would collide with whatever host mounts it. A host that wants the design's
/// `urn:host:scripts` aliases it to this name.
pub const CATALOG_IRI: &str = "urn:script:catalog";
/// Names a script may not take, because a resource already answers there or because
/// the name means something to the capability grammar.
///
/// - `eval` and `catalog` are [`EVAL_IRI`] and [`CATALOG_IRI`].
/// - `public` is the parameter of [`crate::authority::CAP_RUN_PUBLIC`] and
/// [`crate::authority::CAP_READ_PUBLIC`]: a script called `public` would have its
/// per-script grant spelled exactly like the grant a host gives its anonymous
/// principal.
/// - `outcome` and `principal` begin IRIs this crate mints and nothing resolves:
/// [`crate::graph::OUTCOME_OK`] (`urn:script:outcome:ok`) and the principals
/// [`crate::authority::UNSTAMPED`] and [`crate::authority::ANONYMOUS`]
/// (`urn:script:principal:…`). Everything below `urn:script:{name}:` is that script's,
/// so a script called `principal` would own, by the naming rule, an IRI that names
/// who ran it (ledger #1076).
///
/// ⚠ A script already stored under a name reserved later is unreachable, not migrated:
/// every door refuses its name as `InvalidArgument`, [`crate::DirBackend`] leaves it out of
/// the catalog, and its files stay where they were. Rename its entries in the backend to
/// get it back.
///
/// ```
/// use ikigai_script::{authority, graph, name};
///
/// // Every IRI this crate mints directly under `urn:script:` starts with a reserved name,
/// // so no script can be named into one.
/// for minted in [
/// name::EVAL_IRI,
/// name::CATALOG_IRI,
/// graph::OUTCOME_OK,
/// graph::OUTCOME_FAILED,
/// authority::UNSTAMPED,
/// authority::ANONYMOUS,
/// ] {
/// let first = minted[name::PREFIX.len()..].split(':').next().unwrap();
/// assert!(name::RESERVED.contains(&first), "{minted}");
/// assert!(name::validate(first).is_err(), "{minted}");
/// }
/// ```
pub const RESERVED: = ;
/// The longest name.
pub const MAX_NAME: usize = 64;
/// Check a script name: `[a-z0-9][a-z0-9_-]*`, at most [`MAX_NAME`] bytes, not
/// [`RESERVED`].
///
/// One segment and lowercase so that a name is the same string in an IRI, in a
/// capability scope, on a file system that folds case, and in a URL path.
/// `urn:script:{name}`: the script itself (the head).
/// `urn:script:{name}:version:{digest}`: one immutable version.
/// `urn:script:{name}:run:{id}`: one recorded run.
/// `urn:script:{name}:{part}`: `compiled`, `result` or `runs`.
/// The golden thread a host cuts when it changes the ceiling it allows `{name}`
/// (`<config home>/script-authority/{name}`): `urn:script:{name}:authority`.
///
/// Every `…:result` hangs from it, because a cached answer computed under the old
/// ceiling must not outlive the ceiling. The library cannot see the host's file change,
/// so cutting this thread is the host's half of the contract (a watcher on the config
/// home, or `sink urn:kernel:cut urn:script:{name}:authority`).
/// The `name` a grammar captured, checked. Every templated resource here captures it.
pub