@0001-labs/idv1 2.0.1 → 2.0.2

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
@@ -29,11 +29,14 @@ const parsed = parseCode(candidate)
29
29
 
30
30
  ## The idv1 command
31
31
 
32
- A codebase keeps a `.id` file: a section name on its own line, then one entry a line, key first. A shape name is a label, not a taxonomy reservation. A taxonomy is written as its pattern, which carries its pair and its shape; an id's shape is read from the id. `readDirectory` still reads the JSON form; `writeDirectory` writes this one.
32
+ A codebase keeps a `.id` file. It may open with five lines naming the shapes in pattern order (`LLNNNN`, `NNLLLL`, `LLLLNN`, `LLNNXX`, `XXXXXX`); a line left as its pattern keeps no name. A shape name is a label, not a taxonomy reservation. Then each section name stands on its own line, followed by one entry a line, key first. A taxonomy is written as its pattern, which carries its pair and its shape; an id's shape is read from the id. `readDirectory` still reads the JSON form; `writeDirectory` writes this one.
33
33
 
34
34
  ```text
35
- shapes
36
- LLNNNN User
35
+ User
36
+ List
37
+ Product
38
+ Item
39
+ Event
37
40
 
38
41
  namespaces
39
42
  SH Shop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0001-labs/idv1",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Six-character IDs for agents: five shapes, taxonomy and namespaces, and a CLI that reads a codebase's .id file.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/idv1.ts CHANGED
@@ -11,7 +11,7 @@ export type Resolved = { id: string; shape: CodeShape | null; namespace?: Namesp
11
11
  const SHAPES: CodeShape[] = ['LLNNNN', 'NNLLLL', 'LLLLNN', 'LLNNXX', 'XXXXXX']
12
12
  const list = <T>(value: unknown): T[] => (Array.isArray(value) ? value : []) as T[]
13
13
 
14
- const SECTIONS = ['shapes', 'namespaces', 'taxonomies', 'ids', 'facts'] as const
14
+ const SECTIONS = ['namespaces', 'taxonomies', 'ids', 'facts'] as const
15
15
  export const patternShape = (pattern: string) => parseCode(pattern.replace(/N/g, '1').replace(/[LXOP]/g, 'a'))?.shape ?? null
16
16
 
17
17
  export function readDirectory(text: string): Directory {
@@ -20,11 +20,11 @@ export function readDirectory(text: string): Directory {
20
20
  return { shapes: value.shapes ?? {}, namespaces: list(value.namespaces), taxonomies: list(value.taxonomies), parts: list(value.parts), facts: list(value.facts) }
21
21
  }
22
22
  const directory: Directory = { shapes: {}, namespaces: [], taxonomies: [], parts: [], facts: [] }
23
- let section = ''
23
+ let section = '', shapeLine = 0
24
24
  for (const line of text.split('\n').map(line => line.trim()).filter(line => line && !line.startsWith('#'))) {
25
25
  if ((SECTIONS as readonly string[]).includes(line)) { section = line; continue }
26
26
  const [key, ...rest] = line.split(' '), name = rest.join(' ')
27
- if (section === 'shapes') directory.shapes![key as CodeShape] = name
27
+ if (!section) { const shape = SHAPES[shapeLine++]; if (shape && line !== shape) directory.shapes![shape] = line }
28
28
  else if (section === 'namespaces') directory.namespaces.push({ shorthand: key, name })
29
29
  else if (section === 'taxonomies') directory.taxonomies.push({ shorthand: key.replace(/[^a-z]/g, ''), name, shape: patternShape(key)!, pattern: key })
30
30
  else if (section === 'ids') { const [label, path] = name.split(' @ '); directory.parts.push({ id: key, shape: parseCode(key)?.shape!, name: label, path: path ?? null }) }
@@ -34,8 +34,8 @@ export function readDirectory(text: string): Directory {
34
34
  }
35
35
 
36
36
  export function writeDirectory(directory: Directory): string {
37
- return [
38
- ['shapes', Object.entries(directory.shapes ?? {}).map(([shape, name]) => `${shape} ${name}`)],
37
+ const shapes = Object.keys(directory.shapes ?? {}).length ? SHAPES.map(shape => directory.shapes?.[shape] ?? shape).join('\n') + '\n\n' : ''
38
+ return shapes + [
39
39
  ['namespaces', directory.namespaces.map(({ shorthand, name }) => `${shorthand} ${name}`)],
40
40
  ['taxonomies', directory.taxonomies.map(({ pattern, name }) => `${pattern.replace(/\s/g, '')} ${name}`)],
41
41
  ['ids', directory.parts.map(({ id, name, path }) => `${id} ${name}${path ? ` @ ${path}` : ''}`)],