@0001-labs/idv1 1.0.3 → 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/bin/idv1.mjs +1 -1
- package/package.json +2 -2
- package/src/architecture.ts +7 -24
- package/src/{index.ts → idv1.ts} +3 -1
- package/src/junction.ts +1 -1
- package/src/namespace.ts +17 -0
- package/src/scanCode.ts +71 -3
- package/src/taxonomy.ts +23 -0
- package/src/scanCodeDrawing.ts +0 -72
- /package/src/{shapes.ts → identifier.ts} +0 -0
package/bin/idv1.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { existsSync, readFileSync } from 'node:fs'
|
|
3
3
|
import { dirname, join, resolve } from 'node:path'
|
|
4
4
|
import '../register.mjs'
|
|
5
|
-
const { runArchitectureCommand } = await import('../src/
|
|
5
|
+
const { runArchitectureCommand } = await import('../src/idv1.ts')
|
|
6
6
|
|
|
7
7
|
const [command, ...args] = process.argv.slice(2)
|
|
8
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.
|
|
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": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
|
-
".": "./src/
|
|
22
|
+
".": "./src/idv1.ts",
|
|
23
23
|
"./register": "./register.mjs"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
package/src/architecture.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { parseCode, type CodeKind } from './
|
|
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
|
|
6
|
-
export
|
|
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
|
-
|
|
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
|
|
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
|
})
|
package/src/{index.ts → idv1.ts}
RENAMED
package/src/junction.ts
CHANGED
package/src/namespace.ts
ADDED
|
@@ -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 './
|
|
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 {
|
package/src/taxonomy.ts
ADDED
|
@@ -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
|
+
}
|
package/src/scanCodeDrawing.ts
DELETED
|
@@ -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
|