@0001-labs/idv1 3.0.0 → 3.0.1

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
@@ -56,7 +56,7 @@ The package ships TypeScript source. Bundlers and `tsx` read it directly. Plain
56
56
 
57
57
  ## Explorer utility
58
58
 
59
- Import `createExplorer` and `mountExplorer` from `@0001-labs/idv1/explorer`, and `@0001-labs/idv1/explorer.css` for the browser view. Supply `ExplorerData`: namespace names, shapes, taxonomies, identifiers, nodes and links. The utility owns drill-down, counts, identifier resolution, taxonomy highlighting, keyboard navigation and URL history.
59
+ Import `createExplorer` and `mountExplorer` from `@0001-labs/idv1/explorer`, and `@0001-labs/idv1/explorer.css` for the browser view. Supply `ExplorerData`: namespace names, shapes, taxonomies, identifiers, nodes and links. The root lists the shapes by their plural names, then namespaces, taxonomies and identifiers. The utility owns drill-down, counts, identifier resolution, taxonomy highlighting, keyboard navigation and URL history.
60
60
 
61
61
  Optional `collections` carry source records and lazy `load` functions. Records may link to host details with `href`. The utility contains no application records or network requests. `createExplorer(data)` returns `entries(path)`, `title(path)`, `stepName(path, depth)` and `load(path)`. `mountExplorer(element, data)` renders it and returns a cleanup function. Theme it with `--idv1-explorer-*` CSS variables; the host owns loading and authorization.
62
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0001-labs/idv1",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
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": {
@@ -5,6 +5,7 @@
5
5
  .explorer-row { display: grid; grid-template-columns: calc(8 * var(--cell)) minmax(0, 1fr) auto calc(4 * var(--cell)); column-gap: calc(var(--unit) / 2); margin: 0; color: inherit; text-decoration: none; }
6
6
  .explorer-step, .explorer-title, .explorer-row > span, p.explorer-row { box-sizing: border-box; display: block; height: var(--unit); padding-top: calc(var(--unit) / 5); line-height: calc(var(--unit) * 4 / 5); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: inherit; text-decoration: none; }
7
7
  .explorer-row > .explorer-mono { font-family: var(--idv1-explorer-mono, monospace); font-variant-numeric: tabular-nums; white-space: pre; text-overflow: clip; letter-spacing: calc(var(--cell) - 1ch); padding-inline-start: calc((var(--cell) - 1ch) / 2); box-shadow: inset 0 0 0 1px var(--rule); background-image: linear-gradient(to right, var(--rule) 2px, transparent 2px), linear-gradient(to right, color-mix(in oklab, var(--ink) 9%, transparent) 1px, transparent 1px); background-size: var(--unit) 100%, var(--cell) 100%; }
8
+ .explorer-gap { margin-block-start: var(--unit); }
8
9
  .explorer-title { margin-inline-start: auto; }
9
10
  .explorer-dim, .explorer-step:not(:last-of-type) { color: color-mix(in oklab, var(--ink) 55%, transparent); }
10
11
  .explorer :is(a:hover, a:focus-visible) { background-color: color-mix(in oklab, var(--ink) 14%, transparent); outline: none; }
@@ -18,7 +18,7 @@ export type ExplorerData = {
18
18
  type Node = ExplorerNode;
19
19
  type Taxonomy = ExplorerTaxonomy;
20
20
  type Identifier = ExplorerIdentifier;
21
- export type ExplorerEntry = { path: string[]; id: string; label: string; kind: string; count: number; href?: string };
21
+ export type ExplorerEntry = { path: string[]; id: string; label: string; kind: string; count: number; href?: string; gap?: true };
22
22
  type Entry = ExplorerEntry;
23
23
 
24
24
  export function createExplorer(data: ExplorerData) {
@@ -56,8 +56,9 @@ export function createExplorer(data: ExplorerData) {
56
56
  const target = entry && 'on' in entry && entry.on ? `-${entry.namespace}-${entry.on}` : id;
57
57
  return [...nodes.values()].filter(node => node.qualifiedId === target);
58
58
  };
59
- const lists: Record<string, string> = { shapes: 'Shapes', namespaces: 'Namespaces', taxonomies: 'Taxonomies', identifiers: 'Identifiers' };
59
+ const lists: Record<string, string> = { namespaces: 'Namespaces', taxonomies: 'Taxonomies', identifiers: 'Identifiers' };
60
60
  const shapeName = (name: string) => shapes.find(kind => kind.name === name)?.label ?? name;
61
+ const plural = (word: string) => word === word.toUpperCase() ? word : word.replace(/([^aeiou])y$/i, '$1ie').replace(/(s|x|ch|sh)$/i, '$1e') + 's';
61
62
  const ofShape = (name: string) => [...nodes.values()].filter(node => node.shape === name);
62
63
  const scope = (path: string[]) => { const at = path.at(-1); return !at || lists[at] ? data.namespace : at.length === 2 ? at : at.includes(':') ? '' : nodes.get(at)?.namespace ?? ''; };
63
64
  const idIn = (id: string, namespace: string) => id.length > 2 && id.slice(1, 3) === namespace ? id.slice(4) : short(id);
@@ -86,8 +87,8 @@ export function createExplorer(data: ExplorerData) {
86
87
  function entries(path: string[]): Entry[] {
87
88
  const at = path.at(-1);
88
89
  if (!at) return [
89
- { path: ['shapes'], id: '', label: 'Shapes', kind: '', count: shapes.length },
90
- { path: ['namespaces'], id: '', label: 'Namespaces', kind: '', count: namespaces().length },
90
+ ...shapes.map(kind => ({ path: [`sh:${kind.name}`], id: kind.pattern, label: plural(kind.label), kind: '', count: ofShape(kind.name).length })),
91
+ { path: ['namespaces'], id: '', label: 'Namespaces', kind: '', count: namespaces().length, gap: true as const },
91
92
  { path: ['taxonomies'], id: '', label: 'Taxonomies', kind: '', count: taxonomy.length },
92
93
  { path: ['identifiers'], id: '', label: 'Identifiers', kind: '', count: identifiers.length },
93
94
  ...recordEntries([], data.collections ?? []),
@@ -96,7 +97,6 @@ export function createExplorer(data: ExplorerData) {
96
97
  if (at === 'namespaces') return namespaces().map(namespace => ({
97
98
  path: [namespace], id: namespace, label: owner(namespace)?.name ?? namespace, kind: 'Namespace', count: topLevel(namespace).length,
98
99
  }));
99
- if (at === 'shapes') return shapes.map(kind => ({ path: [`sh:${kind.name}`], id: kind.pattern, label: kind.label, kind: 'Shape', count: ofShape(kind.name).length }));
100
100
  if (at === 'taxonomies') return taxonomy.map(entry => ({
101
101
  path: [`tx:${entry.tag}`], id: entry.pattern, label: entry.name, kind: shapeName(entry.shape), count: tagged(entry).length,
102
102
  }));
@@ -110,13 +110,13 @@ export function createExplorer(data: ExplorerData) {
110
110
  return rowsOf(path, (children.get(at) ?? []).flatMap(id => nodes.get(id) ?? []));
111
111
  }
112
112
 
113
- const stepName = (path: string[], depth: number) => { const step = path[depth - 1]; return record(path.slice(0, depth))?.label ?? lists[step] ?? (step.startsWith('sh:') ? shapeName(step.slice(3)) : step.startsWith('tx:') ? step.slice(3) : step.startsWith('id:') ? idIn(step.slice(3), scope(path.slice(0, depth - 1))) : idIn(step, scope(path.slice(0, depth - 1)))); };
113
+ const stepName = (path: string[], depth: number) => { const step = path[depth - 1]; return record(path.slice(0, depth))?.label ?? lists[step] ?? (step.startsWith('sh:') ? plural(shapeName(step.slice(3))) : step.startsWith('tx:') ? step.slice(3) : step.startsWith('id:') ? idIn(step.slice(3), scope(path.slice(0, depth - 1))) : idIn(step, scope(path.slice(0, depth - 1)))); };
114
114
  function title(path: string[]) {
115
115
  const at = path.at(-1);
116
116
  if (!at) return data.name;
117
117
  if (lists[at]) return lists[at];
118
118
  if (at.startsWith('rc:')) return record(path)?.label ?? '';
119
- if (at.startsWith('sh:')) return `${shapeName(at.slice(3))} · Shape`;
119
+ if (at.startsWith('sh:')) return plural(shapeName(at.slice(3)));
120
120
  if (at.startsWith('tx:')) return `${taxonomy.find(entry => entry.tag === at.slice(3))?.name ?? at.slice(3)} · Taxonomy`;
121
121
  if (at.startsWith('id:')) return `${identifiers.find(entry => identifierKey(entry) === at.slice(3))?.name ?? at.slice(3)} · Identifier`;
122
122
  if (at.length === 2) return `${owner(at)?.name ?? at} · Namespace`;
@@ -172,7 +172,7 @@ export function mountExplorer(surface: HTMLElement, data: ExplorerData) {
172
172
  pathLine.replaceChildren(...[data.name, ...path].map((step, depth) =>
173
173
  link(path.slice(0, depth), 'explorer-step', [[`${depth ? stepName(path, depth) : step} /`, '']])), corner);
174
174
  const list = entries(path);
175
- rows.replaceChildren(...list.map(entry => link(entry.path, 'explorer-row', [
175
+ rows.replaceChildren(...list.map(entry => link(entry.path, entry.gap ? 'explorer-row explorer-gap' : 'explorer-row', [
176
176
  [entry.id.padEnd(8), 'explorer-mono'],
177
177
  [entry.label, ''],
178
178
  [entry.kind, 'explorer-dim'],