@0001-labs/idv1 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,19 +21,20 @@ Every code is six letters and digits, and its shape alone says what it names:
21
21
 
22
22
  | Shape | Pattern | Example | For |
23
23
  |---|---|---|---|
24
- | Account | `LLnnnn` | `Jo4712` | a person |
25
- | Product | `LLLLnn` | `ABCD12` | a thing with a code printed on it |
26
- | List | `nnLLLL` | `12ABCD` | something that holds things |
27
- | Item | `LLnnXX` | `Ab12Cd` | one thing kept |
24
+ | Account | `LLNNNN` | `Jo4712` | a person |
25
+ | Product | `LLLLNN` | `ABCD12` | a thing with a code printed on it |
26
+ | List | `NNLLLL` | `12ABCD` | something that holds things |
27
+ | Item | `LLNNxx` | `Ab12Cd` | one thing kept |
28
+ | Project | `NLLLLL` | `1Syste` | a project, a digit and five letters |
28
29
 
29
- `L` is a letter, `n` a digit, and an item's last two are letters or digits but never both digits, or it would be an account. `codeCandidate(kind)` draws a code at random in a shape. An app can go further and lay a template over a shape, fixing some characters so a code also says which kind of thing in that app it is and which thing it names.
30
+ `L` is a letter, `N` a digit and `x` either, and an item's last two are never both digits, or it would be an account. Every other six letters and digits are left for event codes (`advanced`). `codeCandidate(kind)` draws a code at random in a shape. An app can go further and lay a template over a shape, fixing some characters so a code also says which kind of thing in that app it is and which thing it names.
30
31
 
31
32
  ### Building a template
32
33
 
33
- - **A fixed prefix per kind.** A list's two digits can mark the kind: `01Abcd` for projects, `02Abcd` for one kind, `03Abcd` for another.
34
- - **Letters that read as the name.** The letters come from the thing's name, then vary letter by letter until the code is free: a project called Design system 1 is `01Desi`.
35
- - **An owner's two letters lead an item.** An item starts with its owner's two letters, and the first digit can mark the kind inside that owner: `Ds10Bu` is a component of Design system 1, `Ez20Li` one of an app's tools.
36
- - **People and agents take an account's shape.** Two letters from the name and four digits, `Le0125`, whether the account is a person or an agent.
34
+ - **A fixed prefix per kind.** Fixed characters mark the kind: a project's digit (`1LLLLL`), a list's two digits (`02LLLL`, `03LLLL`), or a small letter that no name starts with, as `aLNNNN` for an agent.
35
+ - **Letters that read as the name.** The letters come from the thing's name, then vary letter by letter until the code is free: a project called Design system 1 is `1Desig`.
36
+ - **An owner's two letters lead an item.** An item starts with its owner's two letters, and the first digit can mark the kind inside that owner: `Ds10Bu` is a component of Design system 1.
37
+ - **People and agents take an account's shape.** A person's two name letters and four digits, `Le0125`; an agent's `a`, its initial and four digits, `aG4008`.
37
38
 
38
39
  A fixed character spends space. A list prefix leaves 26⁴ = 456,976 codes in capitals; an item template with fixed owner letters and a fixed kind digit leaves 10 × 26 × 26 = 6,760 per owner and kind if its last pair is a capital and a small letter. Fix only what a reader needs.
39
40
 
@@ -43,25 +44,31 @@ A fixed character spends space. A list prefix leaves 26⁴ = 456,976 codes in ca
43
44
 
44
45
  | Kind | Template | How |
45
46
  |---|---|---|
46
- | Account | `LLnnnn` | the person's name letters, then four drawn digits |
47
- | Product | `LLLLnn` | drawn, again if the letters or digits are blocked |
48
- | List | `nnLLLL` | drawn, in capitals |
49
- | Item | `LLnnXX` | drawn |
47
+ | Account | `LLNNNN` | the person's name letters, then four drawn digits |
48
+ | Product | `LLLLNN` | drawn, again if the letters or digits are blocked |
49
+ | List | `NNLLLL` | drawn, in capitals |
50
+ | Item | `LLNNxx` | drawn |
50
51
 
51
52
  **System derives.** An inventory of a few hundred named parts wants codes a reader can place on sight, so each kind has a template and the letters come from the name:
52
53
 
53
54
  | Kind | Shape | Template | Example |
54
55
  |---|---|---|---|
55
- | Projects | list | `01Abcd` | `01Desi` |
56
- | Stack | list | `02Abcd` | `02Conv` |
57
- | Integrations | list | `03Abcd` | `03Clou` |
58
- | Components | item | owner, `1n`, name | `Ds10Bu` |
59
- | MCP tools | item | owner, `2n`, name | `Ez20Li` |
60
- | Engineers and agents | account | `Ab1234` | `Le0125` |
61
- | Harnesses | product | `Abcd01` | `Clau01` |
56
+ | Projects | project | `1LLLLL` | `1Desig` |
57
+ | Stack | list | `02LLLL` | `02Conv` |
58
+ | Platforms | list | `03LLLL` | `03Webx` |
59
+ | Connections | list | `04LLLL` | `04Gmai` |
60
+ | Components | item | owner's `LL`, `1N`, `LL` | `Ds10Bu` |
61
+ | Tool calls | product | `tc`, the HTTP verb (`G`, `P`, `U`, `D`), `LNN` | `tcGi02` |
62
+ | Engineers | account | `LLNNNN` | `Le0125` |
63
+ | Agents | account | `aLNNNN` | `aG4008` |
64
+ | Harnesses | product | `hLLLNN` | `hCla01` |
62
65
 
63
66
  An app with many short-lived things should draw; one naming a small catalogue can derive. Either way a code, once given, stays when the name changes.
64
67
 
68
+ ### Junctions
69
+
70
+ Codes joined by a hyphen name the place where things meet, and each part still says what it is: `1Ezoxx-tcGi02` is a tool of a project, `1Systs-Sy10Us-Sy10Fl` a path down a tree, `01Sysm-MJ99ST` an item in a list. `junction(...codes)` joins them and refuses anything that is not a code; `junctionParts(value)` reads one back with each part's kind.
71
+
65
72
  ### Rules every template keeps
66
73
 
67
74
  - **Six characters**, letters `A–Z a–z` and digits only.
@@ -69,4 +76,222 @@ An app with many short-lived things should draw; one naming a small catalogue ca
69
76
  - **No blocked words or digits.** Check all of a code's letters together with `blockedCodeLetters`, and a product's last two digits against `BLOCKED_CODE_DIGITS`, before taking a candidate.
70
77
  - **Never two shapes for one code.** A template sits inside one shape, two templates in one app never make the same code, and a code names one thing: claim it with a unique constraint.
71
78
 
79
+ ## Numeric references in a message
80
+
81
+ Two agents can describe a graph using one line per fact: subject, relation, object. In this proposed text format, all three positions use the same IDv1 dictionary. Each line has three tokens separated by single ASCII spaces. LF separates lines. A final LF is optional.
82
+
83
+ Read left to right from an empty dictionary. On first use, send the literal six-character ID and give it the next number, starting at 1. On every later use, send its number in decimal with no leading zero. A six-character token is always a literal, even if all its characters are digits. A reference has one to five digits and must already have an entry. Start a new message before introducing a 100,000th distinct ID. Each message can then be decoded independently. Agents agree on what each relation means before exchanging messages.
84
+
85
+ ### System architecture
86
+
87
+ System’s Tags and tools directory supplies the entity IDs. The project and its MCP app both carry the short code `SYSM`. Their IDv1s distinguish them: the project is `1Systs` and the MCP app is `1Syste`. The directory gives Review the junction `1Systs-Sy11Re-Sy12Re` (System → Reach → Review) and the tool tagged `get_inventory` the junction `1Syste-tcGi04`. The seven relation IDs below are vocabulary proposed for this example.
88
+
89
+ The first four facts show how a number can move from the object position to the subject position:
90
+
91
+ ```text
92
+ 1Systs rHasPt Sy11Re
93
+ 1 2 Sy10Pr
94
+ 3 2 Sy10Ad
95
+ 3 2 Sy12Re
96
+ ```
97
+
98
+ The first line assigns 1 to System, 2 to “has part” and 3 to Reach. The second adds Projects under System. The third and fourth use 3 as their subject: Reach contains Ads and Review.
99
+
100
+ The snapshot covers the System inventory’s ownership tree, relationships into or out of System, outgoing relationships of its catalogued parts, requirements marked inapplicable, and tools in its MCP catalogue. It describes architectural relationships at the time of capture. Runtime state, permissions and tool arguments belong to other messages.
101
+
102
+ | Example relation | Meaning |
103
+ | --- | --- |
104
+ | `rHasPt` | Contains the object as a direct part |
105
+ | `rNeeds` | Depends on the object |
106
+ | `rShare` | Uses a shared implementation |
107
+ | `rLocal` | Implements the object locally |
108
+ | `rOppor` | Records a potential integration |
109
+ | `rNoApp` | Marks a requirement as inapplicable |
110
+ | `rTools` | Exposes the object as an MCP tool |
111
+
112
+ <details>
113
+ <summary>Full System message — 177 facts, 2,109 ASCII bytes without a trailing LF</summary>
114
+
115
+ ```text
116
+ 1Systs rHasPt Sy11Re
117
+ 1 2 Sy10Pr
118
+ 3 2 Sy10Ad
119
+ 3 2 Sy12Re
120
+ 1 2 Sy10In
121
+ 1 2 Sy10Sy
122
+ Sy10Us 2 Sy10Fl
123
+ 1 2 Sy10Ma
124
+ 1 2 Sy11Ma
125
+ 1 2 Sy11Si
126
+ 4 2 Sy12Co
127
+ 1 2 Sy10Ci
128
+ 1 2 Sy10Is
129
+ Sy12Se 2 Sy10Ap
130
+ 17 2 Sy10Di
131
+ 17 2 Sy10Ya
132
+ 17 2 Sy11Co
133
+ 1 2 9
134
+ 17 2 Sy10Va
135
+ 1 2 17
136
+ 4 2 Sy11Au
137
+ 1 2 Sy10Te
138
+ 1 rNeeds 1Dragx
139
+ 1 25 1Aaxxx
140
+ 1 rShare Sy10De
141
+ 1 28 10
142
+ 1 rLocal 03Webx
143
+ 1 30 03Iosx
144
+ 1 25 Sy10Ne
145
+ 1 25 1DSone
146
+ 1 30 Sy10Au
147
+ 1 28 8
148
+ 1 28 Sy10Ta
149
+ 1 25 02Vite
150
+ 1 25 02Clou
151
+ 1 30 03Clix
152
+ 1 25 1Idvxx
153
+ 1 25 02Litx
154
+ 1 30 Sy10Se
155
+ 10 28 40
156
+ 1 30 03Mcpx
157
+ 1Consc rOppor 1
158
+ 1 30 03Apix
159
+ 1 30 11
160
+ 1 30 12
161
+ 1 30 13
162
+ 1 30 3
163
+ 1 30 14
164
+ 1 30 15
165
+ 1 30 16
166
+ 1 30 18
167
+ 1 30 19
168
+ 1 30 4
169
+ 1 30 20
170
+ 1 30 21
171
+ 1 30 9
172
+ 9 30 10
173
+ 1 30 22
174
+ 1 30 04Gmai
175
+ 1 30 Sy11Se
176
+ 1 30 Sy10Do
177
+ 1 25 7
178
+ 1 25 1Ezoxe
179
+ 1 28 1Linkl
180
+ 1 28 44
181
+ 1 28 Sy10Co
182
+ 7 28 10
183
+ 7 30 43
184
+ 1 30 5
185
+ 1 30 Sy10Ag
186
+ 1 30 23
187
+ 1 30 03Nati
188
+ 7 28 26
189
+ 1 30 24
190
+ 7 25 34
191
+ 1 30 Sy11Ca
192
+ 1 25 02Bomb
193
+ 7 25 44
194
+ 1 rNoApp Sy10Su
195
+ 1 57 Sy10Sh
196
+ 1 57 Sy10Af
197
+ 1 57 Sy10Re
198
+ 1 57 Sy10On
199
+ 1 57 Sy10As
200
+ 1 57 Sy11Su
201
+ 1 57 Sy10Ca
202
+ 1 57 1Priva
203
+ 1 57 Sy10Si
204
+ 1 57 Sy10If
205
+ 1 2 1Syste
206
+ 69 rTools tcUr01
207
+ 69 70 tcDr01
208
+ 69 70 tcUe02
209
+ 69 70 tcUl02
210
+ 69 70 tcUo01
211
+ 69 70 tcUp08
212
+ 69 70 tcUr02
213
+ 69 70 tcPi02
214
+ 69 70 tcPr03
215
+ 69 70 tcUr03
216
+ 69 70 tcDs04
217
+ 69 70 tcGa06
218
+ 69 70 tcGa07
219
+ 69 70 tcGa08
220
+ 69 70 tcGa09
221
+ 69 70 tcGa10
222
+ 69 70 tcGc07
223
+ 69 70 tcGc08
224
+ 69 70 tcGc09
225
+ 69 70 tcGc10
226
+ 69 70 tcGc11
227
+ 69 70 tcGc12
228
+ 69 70 tcGd01
229
+ 69 70 tcGg01
230
+ 69 70 tcGi04
231
+ 69 70 tcGi05
232
+ 69 70 tcGm03
233
+ 69 70 tcGp14
234
+ 69 70 tcGr01
235
+ 69 70 tcGr02
236
+ 69 70 tcGr03
237
+ 69 70 tcGr04
238
+ 69 70 tcGr05
239
+ 69 70 tcGr06
240
+ 69 70 tcGr07
241
+ 69 70 tcGr08
242
+ 69 70 tcGr09
243
+ 69 70 tcGr10
244
+ 69 70 tcGs10
245
+ 69 70 tcGs11
246
+ 69 70 tcGs12
247
+ 69 70 tcGt03
248
+ 69 70 tcGu01
249
+ 69 70 tcGu02
250
+ 69 70 tcGv01
251
+ 69 70 tcGa11
252
+ 69 70 tcGc13
253
+ 69 70 tcGc14
254
+ 69 70 tcGi06
255
+ 69 70 tcGp15
256
+ 69 70 tcGp16
257
+ 69 70 tcGr11
258
+ 69 70 tcGr12
259
+ 69 70 tcGr13
260
+ 69 70 tcGr14
261
+ 69 70 tcGs13
262
+ 69 70 tcGs14
263
+ 69 70 tcUr04
264
+ 69 70 tcUr05
265
+ 69 70 tcGr15
266
+ 69 70 tcPr04
267
+ 69 70 tcPc04
268
+ 69 70 tcPc05
269
+ 69 70 tcPc06
270
+ 69 70 tcPr05
271
+ 69 70 tcGp17
272
+ 69 70 tcGr16
273
+ 69 70 tcDr02
274
+ 69 70 tcPp05
275
+ 69 70 tcPa05
276
+ 69 70 tcPa06
277
+ 69 70 tcPr06
278
+ 69 70 tcPr07
279
+ 69 70 tcPr08
280
+ 69 70 tcPr09
281
+ 69 70 tcPr10
282
+ 69 70 tcPr11
283
+ 69 70 tcPr12
284
+ 69 70 tcPr13
285
+ 69 70 tcPr14
286
+ 69 70 tcPr15
287
+ 69 70 tcPr16
288
+ 69 70 tcGa12
289
+ 69 70 tcGp18
290
+ 69 70 tcGs15
291
+ 69 70 tcUr06
292
+ 69 70 tcUi03
293
+ ```
294
+
295
+ </details>
296
+
72
297
  [MIT license](LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0001-labs/idv1",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "An ID system for short, memorable IDs that are easy to keep unique.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/advanced.ts CHANGED
@@ -43,6 +43,7 @@ export const ADVANCED_SPACE = (() => {
43
43
  letters ** 2 * digits ** 4 +
44
44
  letters ** 4 * digits ** 2 +
45
45
  digits ** 2 * letters ** 4 +
46
- letters ** 2 * digits ** 2 * ((letters + digits) ** 2 - digits ** 2)
46
+ letters ** 2 * digits ** 2 * ((letters + digits) ** 2 - digits ** 2) +
47
+ digits * letters ** 5
47
48
  return { all, shapes, events: all - shapes } as const
48
49
  })()
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './shapes'
2
2
  export * from './space'
3
+ export * from './junction'
3
4
  export * from './words'
4
5
  export * from './scanCode'
@@ -0,0 +1,18 @@
1
+ import { codeKind, type CodeKind } from './shapes'
2
+
3
+ export const JUNCTION_SEPARATOR = '-'
4
+
5
+ export function junction(...codes: string[]): string {
6
+ if (codes.length < 2) throw new Error('A junction joins two codes or more.')
7
+ for (const code of codes) if (!codeKind(code)) throw new Error(`${code} is no IDv1 code.`)
8
+ return codes.join(JUNCTION_SEPARATOR)
9
+ }
10
+
11
+ export function junctionParts(value: string): { code: string; kind: CodeKind }[] | null {
12
+ const codes = value.split(JUNCTION_SEPARATOR)
13
+ if (codes.length < 2) return null
14
+ const parts = codes.map(code => ({ code, kind: codeKind(code) }))
15
+ return parts.every((part): part is { code: string; kind: CodeKind } => part.kind !== null) ? parts : null
16
+ }
17
+
18
+ export const isJunction = (value: string): boolean => junctionParts(value) !== null
package/src/shapes.ts CHANGED
@@ -7,21 +7,24 @@ export const PRODUCT_CODE = /^[A-Za-z]{4}\d{2}$/
7
7
  export const ACCOUNT_CODE = /^(?:[A-Za-z]{2}\d{4}|[A-Za-z]{4}\d{2})$/
8
8
  export const LIST_CODE = /^\d{2}[A-Za-z]{4}$/
9
9
  export const ITEM_CODE = /^[A-Za-z]{2}\d{2}(?:[A-Za-z][A-Za-z0-9]|\d[A-Za-z])$/
10
+ export const PROJECT_CODE = /^\d[A-Za-z]{5}$/
10
11
 
11
- import { blockedProductCode } from './words'
12
+ import { blockedCodeLetters, blockedProductCode } from './words'
12
13
 
13
- export type CodeKind = 'account' | 'product' | 'list' | 'item'
14
+ export type CodeKind = 'account' | 'product' | 'list' | 'item' | 'project'
14
15
 
15
16
  export const isAccountCode = (value: string): boolean => ACCOUNT_CODE.test(value)
16
17
  export const isProductCode = (value: string): boolean => PRODUCT_CODE.test(value)
17
18
  export const isListCode = (value: string): boolean => LIST_CODE.test(value)
18
19
  export const isItemCode = (value: string): boolean => ITEM_CODE.test(value)
20
+ export const isProjectCode = (value: string): boolean => PROJECT_CODE.test(value)
19
21
 
20
22
  export function codeKind(value: string): CodeKind | null {
21
23
  if (NAME_CODE.test(value)) return 'account'
22
24
  if (PRODUCT_CODE.test(value)) return 'product'
23
25
  if (LIST_CODE.test(value)) return 'list'
24
26
  if (ITEM_CODE.test(value)) return 'item'
27
+ if (PROJECT_CODE.test(value)) return 'project'
25
28
  return null
26
29
  }
27
30
 
@@ -58,13 +61,6 @@ export const RESERVED_ACCOUNT_CODES = { owner: 'Jo4712', studio: 'Jo0001', onboa
58
61
 
59
62
  export type ReservedRole = keyof typeof RESERVED_ACCOUNT_CODES
60
63
 
61
- export const RESERVED_ACCOUNT_EMAILS = {
62
- 'jaa90@icloud.com': 'owner',
63
- 'joachim@0001.dev': 'studio',
64
- 'joachim+onboarding@0001.dev': 'onboarding',
65
- 'joachim+test@0001.dev': 'test',
66
- } as const satisfies Record<string, ReservedRole>
67
-
68
64
  export const FORMER_RESERVED_ACCOUNT_CODES = ['On4713'] as const
69
65
 
70
66
  let reserved: Set<string> | undefined
@@ -72,10 +68,6 @@ let reserved: Set<string> | undefined
72
68
  export const isReservedAccountCode = (code: string): boolean =>
73
69
  (reserved ??= new Set([...Object.values(RESERVED_ACCOUNT_CODES), ...FORMER_RESERVED_ACCOUNT_CODES].map(kept => kept.toLowerCase()))).has(code.toLowerCase())
74
70
 
75
- export function reservedAccountCode(email: string | null | undefined): string | null {
76
- const key = email?.trim().toLowerCase() as keyof typeof RESERVED_ACCOUNT_EMAILS | undefined
77
- return key && key in RESERVED_ACCOUNT_EMAILS ? RESERVED_ACCOUNT_CODES[RESERVED_ACCOUNT_EMAILS[key]] : null
78
- }
79
71
 
80
72
  export function productCodeCandidate(random: Random = Math.random): string {
81
73
  for (let attempt = 0; attempt < 1000; attempt++) {
@@ -96,7 +88,18 @@ export function itemCodeCandidate(random: Random = Math.random): string {
96
88
  return start + (/\d/.test(first) && /\d/.test(second) ? pick(LETTERS, random) : first) + second
97
89
  }
98
90
 
99
- export const CODE_PATTERN: Record<CodeKind, RegExp> = { account: ACCOUNT_CODE, product: PRODUCT_CODE, list: LIST_CODE, item: ITEM_CODE }
91
+ export function projectCodeCandidate(letters: string | null = null, random: Random = Math.random): string {
92
+ const named = letters ? latinLetters(letters) : ''
93
+ for (let attempt = 0; attempt < 1000; attempt++) {
94
+ const drawn = (named + Array.from({ length: 5 }, () => pick(CAPITALS, random).toLowerCase()).join('')).slice(0, 5)
95
+ const tail = attempt && named ? named.slice(0, 4) + pick(CAPITALS, random).toLowerCase() : drawn
96
+ const code = pick(DIGITS, random) + tail[0].toUpperCase() + tail.slice(1)
97
+ if (!blockedCodeLetters(code)) return code
98
+ }
99
+ throw new Error('No project code could be drawn.')
100
+ }
101
+
102
+ export const CODE_PATTERN: Record<CodeKind, RegExp> = { account: ACCOUNT_CODE, product: PRODUCT_CODE, list: LIST_CODE, item: ITEM_CODE, project: PROJECT_CODE }
100
103
 
101
104
  export const isCodeOf = (kind: CodeKind, value: string): boolean => CODE_PATTERN[kind].test(value)
102
105
 
@@ -105,6 +108,7 @@ export function codeCandidate(kind: CodeKind, options: { letters?: string | null
105
108
  if (kind === 'account') return accountCodeCandidate(options.letters ?? null, random)
106
109
  if (kind === 'product') return productCodeCandidate(random)
107
110
  if (kind === 'list') return listCodeCandidate(random)
111
+ if (kind === 'project') return projectCodeCandidate(options.letters ?? null, random)
108
112
  return itemCodeCandidate(random)
109
113
  }
110
114
 
package/src/space.ts CHANGED
@@ -7,6 +7,7 @@ export const ID_SPACE = {
7
7
  products: LETTERS ** 4 * DIGITS ** 2,
8
8
  lists: DIGITS ** 2 * CAPITALS ** 4,
9
9
  items: LETTERS ** 2 * DIGITS ** 2 * ((LETTERS + DIGITS) ** 2 - DIGITS ** 2),
10
+ projects: DIGITS * LETTERS ** 5,
10
11
  } as const
11
12
 
12
13
  export type IdSpaceKind = keyof typeof ID_SPACE