@0001-labs/idv1 1.0.2 → 1.0.4

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
@@ -32,6 +32,8 @@ npx idv1 resolve co14Ch # one id, a -SH- qualified id or a junction, with i
32
32
 
33
33
  It runs on Node 22.18 or later. The same functions are exported for apps: `readArchitecture`, `architectureHealth`, `resolveCode`, `taxonomyOf`, `describeArchitecture`, `describeStatus` and `runArchitectureCommand`.
34
34
 
35
+ The package ships TypeScript source. Bundlers and `tsx` read it as is; for a plain Node script, import `@0001-labs/idv1/register` first, then load the code that imports the package with `await import()`.
36
+
35
37
  ## Upgrading from 0.3.x to Release 1
36
38
 
37
39
  Release 1 uses five shapes. Here `L` is an ASCII letter and `N` is a digit.
package/bin/idv1.mjs CHANGED
@@ -1,22 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, readFileSync } from 'node:fs'
3
3
  import { dirname, join, resolve } from 'node:path'
4
- import { register } from 'node:module'
5
-
6
- const source = new URL('../src/', import.meta.url).href
7
- register('data:text/javascript,' + encodeURIComponent(`import { readFileSync } from 'node:fs'
8
- import { stripTypeScriptTypes } from 'node:module'
9
- import { fileURLToPath } from 'node:url'
10
- const source = ${JSON.stringify(source)}
11
- export async function resolve(specifier, context, next) {
12
- if (context.parentURL?.startsWith(source) && /^\\.\\.?\\//.test(specifier) && !/\\.[cm]?[jt]s$/.test(specifier)) return next(specifier + '.ts', context)
13
- return next(specifier, context)
14
- }
15
- export async function load(url, context, next) {
16
- if (url.startsWith(source) && url.endsWith('.ts')) return { format: 'module', source: stripTypeScriptTypes(readFileSync(fileURLToPath(url), 'utf8')), shortCircuit: true }
17
- return next(url, context)
18
- }`))
19
- const { runArchitectureCommand } = await import('../src/architecture.ts')
4
+ import '../register.mjs'
5
+ const { runArchitectureCommand } = await import('../src/idv1.ts')
20
6
 
21
7
  const [command, ...args] = process.argv.slice(2)
22
8
  let dir = resolve(process.cwd())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0001-labs/idv1",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
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": {
@@ -13,18 +13,21 @@
13
13
  "files": [
14
14
  "bin/",
15
15
  "src/",
16
+ "register.mjs",
16
17
  "README.md",
17
18
  "LICENSE"
18
19
  ],
19
20
  "type": "module",
20
21
  "exports": {
21
- ".": "./src/index.ts"
22
+ ".": "./src/idv1.ts",
23
+ "./register": "./register.mjs"
22
24
  },
23
25
  "engines": {
24
26
  "node": ">=22.18"
25
27
  },
26
28
  "devDependencies": {
27
29
  "@types/node": "^22.13.1",
30
+ "tsrs": "0.18.0-ts7.1.0-dev.20260929",
28
31
  "typescript": "^6.0.3",
29
32
  "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
30
33
  "vite-plus": "1.3.0"
@@ -42,7 +45,7 @@
42
45
  }
43
46
  },
44
47
  "scripts": {
45
- "check": "vp exec tsc --noEmit",
48
+ "check": "vp exec tsrs --noEmit",
46
49
  "test": "vp test run",
47
50
  "release": "node scripts/release.mjs",
48
51
  "release:pilot": "node scripts/release-pilot.mjs"
package/register.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { registerHooks, stripTypeScriptTypes } from 'node:module'
3
+ import { fileURLToPath } from 'node:url'
4
+
5
+ const source = new URL('./src/', import.meta.url).href
6
+ const warn = process.emitWarning
7
+ process.emitWarning = (warning, ...rest) => String(warning).includes('stripTypeScriptTypes') ? undefined : warn.call(process, warning, ...rest)
8
+ registerHooks({
9
+ resolve: (specifier, context, next) => context.parentURL?.startsWith(source) && /^\.\.?\//.test(specifier) && !/\.[cm]?[jt]s$/.test(specifier) ? next(specifier + '.ts', context) : next(specifier, context),
10
+ load: (url, context, next) => url.startsWith(source) && url.endsWith('.ts') ? { format: 'module', source: stripTypeScriptTypes(readFileSync(fileURLToPath(url), 'utf8')), shortCircuit: true } : next(url, context),
11
+ })
@@ -1,9 +1,11 @@
1
- import { parseCode, type CodeKind } from './shapes'
1
+ import { parseCode, type CodeKind } from './identifier'
2
2
  import { blockedCodeLetters, blockedProjectCode } from './words'
3
3
  import { JUNCTION_SEPARATOR } from './junction'
4
+ import { namespaceHealth, namespaceOf, type Namespace } from './namespace'
5
+ import { taxonomyHealth, taxonomyOf, type Taxonomy } from './taxonomy'
4
6
 
5
- export type Namespace = { shorthand: string; name: string }
6
- export type Taxonomy = { shorthand: string; name: string; shape: CodeKind; pattern: string }
7
+ export type { Namespace } from './namespace'
8
+ export { taxonomyOf, type Taxonomy } from './taxonomy'
7
9
  export type Part = { id: string; shape: CodeKind; name: string; path: string | null }
8
10
  export type Architecture = { namespaces: Namespace[]; taxonomies: Taxonomy[]; parts: Part[]; facts: string[] }
9
11
  export type Resolved = { id: string; shape: CodeKind | null; namespace?: Namespace; taxonomy?: Taxonomy; part?: Part; facts: string[] }
@@ -16,28 +18,10 @@ export function readArchitecture(text: string): Architecture {
16
18
  return { namespaces: list(value.namespaces), taxonomies: list(value.taxonomies), parts: list(value.parts), facts: list(value.facts) }
17
19
  }
18
20
 
19
- export function taxonomyOf(architecture: Architecture, id: string): Taxonomy | undefined {
20
- const shape = parseCode(id)?.kind
21
- return architecture.taxonomies.find(taxonomy => {
22
- const at = taxonomy.pattern.replace(/\s/g, '').indexOf(taxonomy.shorthand)
23
- return taxonomy.shape === shape && at >= 0 && id.slice(at, at + 2) === taxonomy.shorthand
24
- })
25
- }
26
-
27
21
  export function architectureHealth(architecture: Architecture, exists: (path: string) => boolean = () => true): string[] {
28
22
  const problems: string[] = []
29
23
  const seen = (values: string[], what: string) => values.forEach((value, index) => { if (values.indexOf(value) !== index) problems.push(`${what} ${value} is declared twice`) })
30
- for (const { shorthand, name } of architecture.namespaces) {
31
- if (!/^[A-Z]{2}$/.test(shorthand)) problems.push(`Namespace ${shorthand} is not two capitals`)
32
- if (!name) problems.push(`Namespace ${shorthand} has no name`)
33
- }
34
- for (const { shorthand, name, shape, pattern } of architecture.taxonomies) {
35
- if (!/^[a-z]{2}$/.test(shorthand)) problems.push(`Taxonomy ${shorthand} is not two small letters`)
36
- if (!name) problems.push(`Taxonomy ${shorthand} has no name`)
37
- if (!SHAPES.includes(shape)) problems.push(`Taxonomy ${shorthand} has no shape`)
38
- const compact = String(pattern ?? '').replace(/\s/g, '')
39
- if (compact.length !== 6 || !compact.includes(shorthand)) problems.push(`Taxonomy ${shorthand} has no six-character pattern holding ${shorthand}`)
40
- }
24
+ problems.push(...namespaceHealth(architecture.namespaces), ...taxonomyHealth(architecture.taxonomies))
41
25
  seen(architecture.namespaces.map(namespace => namespace.shorthand), 'Namespace')
42
26
  seen(architecture.taxonomies.map(taxonomy => taxonomy.shorthand), 'Taxonomy')
43
27
  seen(architecture.parts.map(part => part.id), 'Id')
@@ -62,8 +46,7 @@ export function resolveCode(architecture: Architecture, value: string): Resolved
62
46
  const ids = (qualified ? qualified[2] : value).split(JUNCTION_SEPARATOR)
63
47
  return ids.map(id => {
64
48
  const shape = parseCode(id)?.kind ?? null
65
- const shorthand = qualified?.[1] ?? (shape === 'project' ? id.slice(0, 2) : undefined)
66
- const namespace = architecture.namespaces.find(namespace => namespace.shorthand === shorthand) ?? (architecture.namespaces.length === 1 ? architecture.namespaces[0] : undefined)
49
+ const namespace = namespaceOf(architecture, id, qualified?.[1])
67
50
  const facts = architecture.facts.filter(fact => { const [subject, , object] = fact.split(' '); return subject === id || object === id })
68
51
  return { id, shape, namespace, taxonomy: shape ? taxonomyOf(architecture, id) : undefined, part: architecture.parts.find(part => part.id === id), facts }
69
52
  })
@@ -1,4 +1,6 @@
1
- export * from './shapes'
1
+ export * from './identifier'
2
+ export type { Namespace } from './namespace'
3
+ export { taxonomyOf, type Taxonomy } from './taxonomy'
2
4
  export * from './space'
3
5
  export * from './junction'
4
6
  export * from './words'
package/src/junction.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { codeKind, type CodeKind } from './shapes'
1
+ import { codeKind, type CodeKind } from './identifier'
2
2
 
3
3
  export const JUNCTION_SEPARATOR = '-'
4
4
 
@@ -0,0 +1,17 @@
1
+ import { parseCode } from './identifier'
2
+
3
+ export type Namespace = { shorthand: string; name: string }
4
+
5
+ export function namespaceOf({ namespaces }: { namespaces: Namespace[] }, id: string, qualified?: string): Namespace | undefined {
6
+ const shorthand = qualified ?? (parseCode(id)?.kind === 'project' ? id.slice(0, 2) : undefined)
7
+ return namespaces.find(namespace => namespace.shorthand === shorthand) ?? (namespaces.length === 1 ? namespaces[0] : undefined)
8
+ }
9
+
10
+ export function namespaceHealth(namespaces: Namespace[]): string[] {
11
+ const problems: string[] = []
12
+ for (const { shorthand, name } of namespaces) {
13
+ if (!/^[A-Z]{2}$/.test(shorthand)) problems.push(`Namespace ${shorthand} is not two capitals`)
14
+ if (!name) problems.push(`Namespace ${shorthand} has no name`)
15
+ }
16
+ return problems
17
+ }
package/src/scanCode.ts CHANGED
@@ -1,8 +1,76 @@
1
- import { ALPHABET, isAccountCode, isListCode, parseCode, type Id } from './shapes'
2
- import { scanCodeChecksum, scanCodeColumns, scanCodeRows } from './scanCodeDrawing'
3
- export { CODE_END_RADIUS, encodeScanCode, scanCodeColumns, scanCodePath, scanCodeRows } from './scanCodeDrawing'
1
+ import { ALPHABET, isAccountCode, isListCode, parseCode, type Id } from './identifier'
4
2
 
5
3
  const alphabet = ALPHABET
4
+ export const scanCodeColumns = 16
5
+ export const scanCodeRows = 4
6
+ export const CODE_END_RADIUS = 0.1
7
+
8
+ function scanCodeChecksum(bytes: readonly number[]): number {
9
+ let crc = 0xffff
10
+ for (const byte of bytes) {
11
+ crc ^= byte << 8
12
+ for (let bit = 0; bit < 8; bit++) crc = ((crc << 1) ^ (crc & 0x8000 ? 0x1021 : 0)) & 0xffff
13
+ }
14
+ return crc
15
+ }
16
+
17
+ export function encodeScanCode(id: string): boolean[] | null {
18
+ if (!parseCode(id)) return null
19
+ let value = 0
20
+ for (const character of id) value = value * 62 + alphabet.indexOf(character)
21
+ const bytes = [3]
22
+ for (let shift = 32; shift >= 0; shift -= 8) bytes.push(Math.floor(value / 2 ** shift) & 255)
23
+ const crc = scanCodeChecksum(bytes)
24
+ bytes.push(crc >> 8, crc & 255)
25
+ return bytes.flatMap(byte => Array.from({ length: 8 }, (_, bit) => !!(byte & (1 << (7 - bit)))))
26
+ }
27
+
28
+ export function scanCodePath(bits: readonly boolean[], { ink = (bit: boolean) => !bit, cell = 1, x = 0, y = 0, radius = 0 }: { ink?: (bit: boolean) => boolean; cell?: number; x?: number; y?: number; radius?: number } = {}): string {
29
+ const round = (value: number) => Math.round(value * 1e4) / 1e4
30
+ const inked = (row: number, column: number) =>
31
+ row >= 0 && row < scanCodeRows && column >= 0 && column < scanCodeColumns && ink(bits[row * scanCodeColumns + column])
32
+ const r = Math.min(Math.max(radius, 0), 0.5) * cell
33
+ let d = ''
34
+ for (let row = 0; row < scanCodeRows; row++) {
35
+ for (let column = 0; column < scanCodeColumns;) {
36
+ if (!inked(row, column)) { column++; continue }
37
+ const start = column
38
+ while (column < scanCodeColumns && inked(row, column)) column++
39
+ const left = x + start * cell, right = x + column * cell, top = y + row * cell, bottom = top + cell
40
+ if (!r) {
41
+ d += `M${round(left)} ${round(top)}h${round(right - left)}v${round(cell)}h${round(left - right)}z`
42
+ continue
43
+ }
44
+ const end = (facing: number, inside: number) => !inked(facing, inside) ? r : 0
45
+ const tl = end(row - 1, start)
46
+ const tr = end(row - 1, column - 1)
47
+ const br = end(row + 1, column - 1)
48
+ const bl = end(row + 1, start)
49
+ const arc = (radius: number, toX: number, toY: number) => radius ? `A${round(radius)} ${round(radius)} 0 0 1 ${round(toX)} ${round(toY)}` : ''
50
+ d += `M${round(left + tl)} ${round(top)}H${round(right - tr)}${arc(tr, right, top + tr)}`
51
+ d += `V${round(bottom - br)}${arc(br, right - br, bottom)}`
52
+ d += `H${round(left + bl)}${arc(bl, left, bottom - bl)}`
53
+ d += `V${round(top + tl)}${arc(tl, left + tl, top)}Z`
54
+ }
55
+ }
56
+ if (!r) return d
57
+ for (let row = 0; row < scanCodeRows; row++) {
58
+ for (let column = 0; column < scanCodeColumns; column++) {
59
+ if (inked(row, column)) continue
60
+ const left = x + column * cell, top = y + row * cell
61
+ for (const [dy, dx] of [[-1, -1], [-1, 1], [1, 1], [1, -1]] as const) {
62
+ if (!inked(row + dy, column) || !inked(row, column + dx) || !inked(row + dy, column + dx)) continue
63
+ const cornerX = left + (dx > 0 ? cell : 0), cornerY = top + (dy > 0 ? cell : 0)
64
+ const alongX = cornerX - dx * r, alongY = cornerY - dy * r
65
+ const sweep = dx * dy > 0 ? 0 : 1
66
+ d += `M${round(cornerX)} ${round(cornerY)}H${round(alongX)}A${round(r)} ${round(r)} 0 0 ${sweep} ${round(cornerX)} ${round(alongY)}Z`
67
+ }
68
+ }
69
+ }
70
+ return d
71
+ }
72
+
73
+
6
74
  const idSpace = 62 ** 6
7
75
 
8
76
  export function decodeScanCode(bits: readonly boolean[]): Id | null {
@@ -0,0 +1,23 @@
1
+ import { CODE_PATTERN, parseCode, type CodeKind } from './identifier'
2
+
3
+ export type Taxonomy = { shorthand: string; name: string; shape: CodeKind; pattern: string }
4
+
5
+ export function taxonomyOf(architecture: { taxonomies: Taxonomy[] }, id: string): Taxonomy | undefined {
6
+ const shape = parseCode(id)?.kind
7
+ return architecture.taxonomies.find(taxonomy => {
8
+ const at = taxonomy.pattern.replace(/\s/g, '').indexOf(taxonomy.shorthand)
9
+ return taxonomy.shape === shape && at >= 0 && id.slice(at, at + 2) === taxonomy.shorthand
10
+ })
11
+ }
12
+
13
+ export function taxonomyHealth(taxonomies: Taxonomy[]): string[] {
14
+ const problems: string[] = []
15
+ for (const { shorthand, name, shape, pattern } of taxonomies) {
16
+ if (!/^[a-z]{2}$/.test(shorthand)) problems.push(`Taxonomy ${shorthand} is not two small letters`)
17
+ if (!name) problems.push(`Taxonomy ${shorthand} has no name`)
18
+ if (!Object.keys(CODE_PATTERN).includes(shape)) problems.push(`Taxonomy ${shorthand} has no shape`)
19
+ const compact = String(pattern ?? '').replace(/\s/g, '')
20
+ if (compact.length !== 6 || !compact.includes(shorthand)) problems.push(`Taxonomy ${shorthand} has no six-character pattern holding ${shorthand}`)
21
+ }
22
+ return problems
23
+ }
@@ -1,72 +0,0 @@
1
- import { ALPHABET, parseCode } from './shapes'
2
- const alphabet = ALPHABET
3
-
4
- export const scanCodeColumns = 16
5
- export const scanCodeRows = 4
6
- export const CODE_END_RADIUS = 0.1
7
-
8
- export function scanCodeChecksum(bytes: readonly number[]): number {
9
- let crc = 0xffff
10
- for (const byte of bytes) {
11
- crc ^= byte << 8
12
- for (let bit = 0; bit < 8; bit++) crc = ((crc << 1) ^ (crc & 0x8000 ? 0x1021 : 0)) & 0xffff
13
- }
14
- return crc
15
- }
16
-
17
- export function encodeScanCode(id: string): boolean[] | null {
18
- if (!parseCode(id)) return null
19
- let value = 0
20
- for (const character of id) value = value * 62 + alphabet.indexOf(character)
21
- const bytes = [3]
22
- for (let shift = 32; shift >= 0; shift -= 8) bytes.push(Math.floor(value / 2 ** shift) & 255)
23
- const crc = scanCodeChecksum(bytes)
24
- bytes.push(crc >> 8, crc & 255)
25
- return bytes.flatMap(byte => Array.from({ length: 8 }, (_, bit) => !!(byte & (1 << (7 - bit)))))
26
- }
27
-
28
- export function scanCodePath(bits: readonly boolean[], { ink = (bit: boolean) => !bit, cell = 1, x = 0, y = 0, radius = 0 }: { ink?: (bit: boolean) => boolean; cell?: number; x?: number; y?: number; radius?: number } = {}): string {
29
- const round = (value: number) => Math.round(value * 1e4) / 1e4
30
- const inked = (row: number, column: number) =>
31
- row >= 0 && row < scanCodeRows && column >= 0 && column < scanCodeColumns && ink(bits[row * scanCodeColumns + column])
32
- const r = Math.min(Math.max(radius, 0), 0.5) * cell
33
- let d = ''
34
- for (let row = 0; row < scanCodeRows; row++) {
35
- for (let column = 0; column < scanCodeColumns;) {
36
- if (!inked(row, column)) { column++; continue }
37
- const start = column
38
- while (column < scanCodeColumns && inked(row, column)) column++
39
- const left = x + start * cell, right = x + column * cell, top = y + row * cell, bottom = top + cell
40
- if (!r) {
41
- d += `M${round(left)} ${round(top)}h${round(right - left)}v${round(cell)}h${round(left - right)}z`
42
- continue
43
- }
44
- const end = (facing: number, inside: number) => !inked(facing, inside) ? r : 0
45
- const tl = end(row - 1, start)
46
- const tr = end(row - 1, column - 1)
47
- const br = end(row + 1, column - 1)
48
- const bl = end(row + 1, start)
49
- const arc = (radius: number, toX: number, toY: number) => radius ? `A${round(radius)} ${round(radius)} 0 0 1 ${round(toX)} ${round(toY)}` : ''
50
- d += `M${round(left + tl)} ${round(top)}H${round(right - tr)}${arc(tr, right, top + tr)}`
51
- d += `V${round(bottom - br)}${arc(br, right - br, bottom)}`
52
- d += `H${round(left + bl)}${arc(bl, left, bottom - bl)}`
53
- d += `V${round(top + tl)}${arc(tl, left + tl, top)}Z`
54
- }
55
- }
56
- if (!r) return d
57
- for (let row = 0; row < scanCodeRows; row++) {
58
- for (let column = 0; column < scanCodeColumns; column++) {
59
- if (inked(row, column)) continue
60
- const left = x + column * cell, top = y + row * cell
61
- for (const [dy, dx] of [[-1, -1], [-1, 1], [1, 1], [1, -1]] as const) {
62
- if (!inked(row + dy, column) || !inked(row, column + dx) || !inked(row + dy, column + dx)) continue
63
- const cornerX = left + (dx > 0 ? cell : 0), cornerY = top + (dy > 0 ? cell : 0)
64
- const alongX = cornerX - dx * r, alongY = cornerY - dy * r
65
- const sweep = dx * dy > 0 ? 0 : 1
66
- d += `M${round(cornerX)} ${round(cornerY)}H${round(alongX)}A${round(r)} ${round(r)} 0 0 ${sweep} ${round(cornerX)} ${round(alongY)}Z`
67
- }
68
- }
69
- }
70
- return d
71
- }
72
-
File without changes