@0001-labs/idv1 4.0.1 → 4.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
@@ -74,3 +74,5 @@ The [specification](https://idv1.0001.dev/docs/spec) owns the code design. [MIT
74
74
  ## Release 4
75
75
 
76
76
  The five masks are `LLNNNN`, `LLNNLL`, `LLLLNN`, `LLLLLL` and the remaining `XXXXXX` codes. Taxonomy always starts at position zero. Namespace is external context, never inferred from letters inside a code. Upgrading requires reminting affected records and their references; existing applications stay on their pinned release until migrated. Total structural capacity remains 62⁶; a pool can reset and reissue short handles when exhausted. Keep durable record keys and allocation context separate from those handles.
77
+
78
+ `overviewHtml({ directory, records, namespaceIds })` from `@0001-labs/idv1/overview` renders separate Shapes, Taxonomies and Namespaces tables. Import `@0001-labs/idv1/overview.css` for the base layout; hosts supply theme variables. Namespace labels contain no dashes. Capacities come from the package; record counts come from the supplied catalogue.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0001-labs/idv1",
3
- "version": "4.0.1",
3
+ "version": "4.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": {
@@ -22,7 +22,9 @@
22
22
  ".": "./src/directory.ts",
23
23
  "./register": "./register.mjs",
24
24
  "./explorer": "./src/util/explorer.ts",
25
- "./explorer.css": "./src/util/explorer.css"
25
+ "./explorer.css": "./src/util/explorer.css",
26
+ "./overview": "./src/util/overview.ts",
27
+ "./overview.css": "./src/util/overview.css"
26
28
  },
27
29
  "engines": {
28
30
  "node": ">=22.18"
@@ -14,3 +14,17 @@ export function idUsage(shape: IdCapacityShape, used: number): { used: number; c
14
14
  if (!Number.isSafeInteger(used) || used < 0) throw new RangeError('Usage must be a nonnegative safe integer.')
15
15
  return { used, capacity, left: Math.max(0, capacity - used), percent: (used / capacity) * 100 }
16
16
  }
17
+
18
+ export function patternCapacity(pattern: string): number {
19
+ const slots = pattern.replace(/\s/g, '')
20
+ if (!/^[A-Za-z0-9]{6}$/.test(slots)) return 0
21
+ const choices = (slot: string, kind: string) => {
22
+ if (slot === 'X') return kind === 'L' ? 52 : kind === 'N' ? 10 : 62
23
+ if (slot === 'L' || slot === 'O' || slot === 'P') return kind === 'N' ? 0 : slot === 'L' ? 52 : 26
24
+ if (slot === 'N') return kind === 'L' ? 0 : 10
25
+ return kind === 'X' || (/[A-Za-z]/.test(slot) ? kind === 'L' : kind === 'N') ? 1 : 0
26
+ }
27
+ const count = (mask: string) => [...slots].reduce((total, slot, at) => total * choices(slot, mask[at]), 1)
28
+ const total = count('XXXXXX')
29
+ return slots.includes('X') ? total - ['LLNNNN', 'LLNNLL', 'LLLLNN', 'LLLLLL'].reduce((sum, mask) => sum + count(mask), 0) : total
30
+ }
@@ -0,0 +1 @@
1
+ .idv1-vocabulary{--id-row:var(--ds-unit,20px);display:grid;gap:var(--id-row)}.idv1-vocabulary h3{margin:0 0 var(--id-row);font:inherit;font-weight:500}.idv1-vocabulary .idv1-scroll{overflow:auto}.idv1-vocabulary table{width:100%;border-collapse:collapse}.idv1-vocabulary :is(th,td){text-align:left;vertical-align:top;padding:0;min-width:calc(4 * var(--id-row));height:var(--id-row);border-bottom:1px solid var(--ds-border-color,currentColor)}.idv1-vocabulary th{font-weight:400}.idv1-vocabulary .idv1-chip{display:inline-flex;font-family:var(--ds-typeface-mono,monospace);white-space:nowrap}.idv1-vocabulary .idv1-chip>span{min-width:calc(1.4 * var(--id-row));text-align:center}.idv1-vocabulary .idv1-literal{background:var(--ds-fill,transparent);font-weight:500}
@@ -0,0 +1,20 @@
1
+ import { parseCode } from '../identifier'
2
+ import { type CodeRecord, type Directory } from '../idv1'
3
+ import { ID_CAPACITY, patternCapacity } from './capacity'
4
+ import { taxonomyOf } from '../taxonomy'
5
+
6
+ export type OverviewInput = { directory: Directory; records?: CodeRecord[]; namespaceIds?: Record<string, string> }
7
+ const escape = (value: unknown) => String(value ?? '').replace(/[&<>"']/g, char => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[char]!)
8
+ const number = (value: number) => value.toLocaleString('en-US')
9
+ const code = (value: string, taxonomy = '') => `<span class="idv1-chip">${value.match(/.{1,2}/g)?.map((pair, index) => `<span${index === 0 && taxonomy ? ` class="idv1-literal" data-taxonomy="${escape(taxonomy)}"` : ''}>${escape(pair)}</span>`).join('') ?? ''}</span>`
10
+ const table = (title: string, headings: string[], rows: string[][]) => `<section><h3>${title}</h3><div class="idv1-scroll"><table class="ds-table"><thead><tr>${headings.map(heading => `<th scope="col">${heading}</th>`).join('')}</tr></thead><tbody>${rows.map(row => `<tr>${row.map(cell => `<td>${cell}</td>`).join('')}</tr>`).join('')}</tbody></table></div></section>`
11
+
12
+ export function overviewHtml({ directory, records = [], namespaceIds = {} }: OverviewInput): string {
13
+ const shapes = Object.entries(ID_CAPACITY).map(([shape, capacity]) => [code(shape), escape(directory.shapes[shape as keyof typeof ID_CAPACITY] ?? ''), number(capacity), number(records.filter(record => parseCode(record.code)?.shape === shape).length)])
14
+ const taxonomies = directory.taxonomies.map(taxonomy => {
15
+ const matching = records.filter(record => taxonomyOf(directory, record.code)?.shorthand === taxonomy.shorthand)
16
+ return [escape(taxonomy.name), code(taxonomy.pattern, taxonomy.shorthand), code(taxonomy.shape), number(patternCapacity(taxonomy.pattern)), number(matching.length), matching[0] ? code(matching[0].code, taxonomy.shorthand) : '']
17
+ })
18
+ const namespaces = directory.namespaces.map(namespace => [escape(namespace.shorthand), escape(namespace.name), namespaceIds[namespace.shorthand] ? code(namespaceIds[namespace.shorthand]) : '', number(records.filter(record => record.namespace === namespace.shorthand).length)])
19
+ return `<div class="idv1-vocabulary">${table('Shapes', ['Pattern', 'Name', 'Capacity', 'Used'], shapes)}${table('Taxonomies', ['Name', 'Pattern', 'Shape', 'Capacity', 'Used', 'Example'], taxonomies)}${table('Namespaces', ['Namespace', 'Name', 'ID', 'Used'], namespaces)}</div>`
20
+ }