Agent Harness · VibeGit
Agent Harness Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
agent-harness / tools / design-map.mjs 139 строк · изменён 6 нояб., 03:45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import fs from 'node:fs' ;
import path from 'node:path' ;
import { parseArgs, readJson, writeJsonAtomic, walkFiles, stateDir, appendEvent } from './lib.mjs' ;
const { flags } = parseArgs ( process. argv . slice ( 2 ) ) ;
const cwd = path. resolve ( flags. cwd && flags. cwd !== true ? flags. cwd : process.
path cwd f path
pkg path cwd
deps pkg pkg
name deps deps name
names n
stack
files cwd f
shadcn path cwd
uiDirs path cwd d fs d
uiComponents uiDirs fs d f f
componentFiles files f f f
cssFiles files f
tokens
tailwindMode fs cwd f
file cssFiles
css fs file
css tailwindMode
scope re
block css re
decl block tokens scope decl decl
fonts
f files x path x
src fs f
m src n m fonts
drift r r
f files x
src fs f
r
n src r
n
drift r n
drift r f n
files b a
map
cwd
stack
tailwindMode
shadcn shadcn shadcn baseColor shadcn
uiComponents
componentFiles rel
tokens
fonts
drift k v v v
obj obj
md
outDir cwd
fs outDir
fs path outDir md
path outDir map
cwd uiComponents map k v
flags flags
before path flags
before
process
worse map v before k count
k v map
worse
process worse
flags map
cwd
(
)
)
;
const
rel
=
(
f
)
=>
.
relative
(
,
)
.
split
(
.
sep
)
.
join
(
'/'
)
;
const
=
readJson
(
.
join
(
,
'package.json'
)
,
{
}
)
;
const
=
{
...
.
dependencies
,
...
.
devDependencies
}
;
const
has
=
(
name
)
=>
(
in
?
[
]
:
null
)
;
const
pick
=
(
names
)
=>
.
filter
(
(
n
)
=>
has
(
)
)
.
map
(
(
n
)
=>
` ${ n} @ ${ deps[ n] } `
)
;
const
=
{
framework
:
pick
(
[
'next'
,
'nuxt'
,
'@sveltejs/kit'
,
'astro'
,
'@remix-run/react'
,
'react-router'
,
'vite'
]
)
,
ui
:
pick
(
[
'react'
,
'vue'
,
'svelte'
,
'solid-js'
,
'preact'
]
)
,
styling
:
pick
(
[
'tailwindcss'
,
'@tailwindcss/postcss'
,
'styled-components'
,
'@emotion/react'
,
'sass'
,
'@vanilla-extract/css'
]
)
,
primitives
:
pick
(
[
'@radix-ui/react-dialog'
,
'radix-ui'
,
'@headlessui/react'
,
'@ark-ui/react'
,
'react-aria-components'
,
'@base-ui-components/react'
]
)
,
icons
:
pick
(
[
'lucide-react'
,
'@heroicons/react'
,
'react-icons'
,
'@tabler/icons-react'
,
'@phosphor-icons/react'
,
'@radix-ui/react-icons'
]
)
,
data
:
pick
(
[
'swr'
,
'@tanstack/react-query'
,
'zustand'
,
'jotai'
,
'@reduxjs/toolkit'
]
)
,
forms
:
pick
(
[
'react-hook-form'
,
'zod'
,
'valibot'
,
'@conform-to/react'
]
)
,
motion
:
pick
(
[
'framer-motion'
,
'motion'
,
'gsap'
]
)
,
i18n
:
pick
(
[
'next-intl'
,
'i18next'
,
'react-i18next'
,
'@lingui/core'
]
)
,
tests
:
pick
(
[
'vitest'
,
'jest'
,
'@testing-library/react'
,
'@playwright/test'
,
'@axe-core/playwright'
,
'@lhci/cli'
,
'@storybook/react'
]
)
,
}
;
const
=
walkFiles
(
)
.
filter
(
(
f
)
=>
!
rel
(
)
.
startsWith
(
'.agent-'
)
)
;
const
=
readJson
(
.
join
(
,
'components.json'
)
,
null
)
;
const
=
[
'components/ui'
,
'src/components/ui'
,
'app/components/ui'
]
.
map
(
(
d
)
=>
.
join
(
,
)
)
.
filter
(
(
d
)
=>
.
existsSync
(
)
)
;
const
=
.
flatMap
(
(
d
)
=>
.
readdirSync
(
)
.
filter
(
(
f
)
=>
/ \. ( tsx| jsx| vue| svelte) $ /
.
test
(
)
)
.
map
(
(
f
)
=>
.
replace
(
/ \. \w + $ /
,
''
)
)
)
;
const
=
.
filter
(
(
f
)
=>
/ \/ components\/ /
.
test
(
rel
(
)
)
&&
!
/ \/ components\/ ui\/ /
.
test
(
rel
(
)
)
&&
/ \. ( tsx| jsx| vue| svelte) $ /
.
test
(
)
)
;
const
=
.
filter
(
(
f
)
=>
.
endsWith
(
'.css'
)
)
;
const
=
{
root
:
{
}
,
dark
:
{
}
,
theme
:
{
}
}
;
let
=
.
readdirSync
(
)
.
some
(
(
f
)
=>
/ ^ tailwind\. config\. /
.
test
(
)
)
?
'v3 (tailwind.config)'
:
null
;
for
(
const
of
)
{
const
=
.
readFileSync
(
,
'utf8'
)
;
if
(
/ @import\s + [ "'] tailwindcss[ "'] /
.
test
(
)
)
=
'v4 (@import "tailwindcss" + @theme)'
;
for
(
const
[
,
]
of
[
[
'root'
,
/ :root\s * \{ ( [ ^ }] * ) \} / g
]
,
[
'dark'
,
/ \. dark\s * \{ ( [ ^ }] * ) \} / g
]
,
[
'theme'
,
/ @theme(?: \s + inline) ? \s * \{ ( [ ^ }] * ) \} / g
]
,
]
)
{
for
(
const
of
.
matchAll
(
)
)
{
for
(
const
of
[
1
]
.
matchAll
(
/ ( --[ \w -] + ) \s * :\s * ( [ ^ ;] + ) ;/ g
)
)
[
]
[
[
1
]
]
=
[
2
]
.
trim
(
)
;
}
}
}
const
=
new
Set
(
)
;
for
(
const
of
.
filter
(
(
x
)
=>
/ \. ( tsx| jsx| ts| js) $ /
.
test
(
)
&&
/ layout| _app| root /
.
test
(
.
basename
(
)
)
)
)
{
const
=
.
readFileSync
(
,
'utf8'
)
;
for
(
const
of
.
matchAll
(
/ import\s * \{ ( [ ^ }] + ) \} \s * from\s * [ "'] next\/ font\/ ( google| local) [ "'] / g
)
)
for
(
const
of
[
1
]
.
split
(
','
)
)
.
add
(
` ${ n. trim ( ) } ( ${ m[ 2 ] } ) `
)
;
}
const
DRIFT_RULES
=
[
{
id
:
'hex-color'
,
re
:
/ #[ 0- 9 a- f A- F ] {3,8} \b / g
,
why
:
'raw hex instead of a token'
}
,
{
id
:
'palette-class'
,
re
:
/ \b (?: bg| text| border| ring| fill| stroke| from| to| via) -(?: slate| gray| zinc| neutral| stone| red| orange| amber| yellow| lime| green| emerald| teal| cyan| sky| blue| indigo| violet| purple| fuchsia| pink| rose) -\d {2,3} \b / g
,
why
:
'palette color instead of semantic token'
}
,
{
id
:
'arbitrary-value'
,
re
:
/ \b [ a- z -] + -\[ [ ^ \] \s ] + \] / g
,
why
:
'arbitrary Tailwind value'
}
,
{
id
:
'inline-style'
,
re
:
/ style=\{ \{ / g
,
why
:
'inline style object'
}
,
{
id
:
'white-black'
,
re
:
/ \b (?: bg| text| border) -(?: white| black) \b / g
,
why
:
'white/black instead of background/foreground'
}
,
]
;
const
=
Object
.
fromEntries
(
DRIFT_RULES
.
map
(
(
r
)
=>
[
.
id
,
{
count
:
0
,
why
:
.
why
,
files
:
{
}
}
]
)
)
;
for
(
const
of
.
filter
(
(
x
)
=>
/ \. ( tsx| jsx| vue| svelte) $ /
.
test
(
)
)
)
{
const
=
.
readFileSync
(
,
'utf8'
)
;
for
(
const
of
DRIFT_RULES
)
{
const
=
(
.
match
(
.
re
)
??
[
]
)
.
length
;
if
(
!
)
continue
;
[
.
id
]
.
count
+=
;
[
.
id
]
.
files
[
rel
(
)
]
=
;
}
}
const
topFiles
=
(
files
)
=>
Object
.
entries
(
)
.
sort
(
(
a, b
)
=>
[
1
]
-
[
1
]
)
.
slice
(
0
,
5
)
.
map
(
(
[ f, n]
)
=>
` ${ f} ( ${ n} ) `
)
.
join
(
', '
)
;
const
=
{
generatedAt
:
new
Date
(
)
.
toISOString
(
)
,
,
,
tailwind
:
,
shadcn
:
?
{
style
:
.
style
??
null
,
baseColor
:
.
tailwind
?.
??
null
,
aliases
:
.
aliases
??
null
}
:
null
,
,
featureComponents
:
.
map
(
)
,
,
fonts
:
[
...
]
,
drift
:
Object
.
fromEntries
(
Object
.
entries
(
)
.
map
(
(
[ k, v]
)
=>
[
,
{
count
:
.
count
,
why
:
.
why
,
top
:
topFiles
(
.
files
)
}
]
)
)
,
}
;
const
line
=
(
label, values
)
=>
` - ** ${ label} :** ${ values. length ? values. join ( ', ' ) : '—' } `
;
const
tokenList
=
(
obj
)
=>
Object
.
keys
(
)
.
length
?
Object
.
keys
(
)
.
join
(
' '
)
:
'—'
;
const
=
` # Design map
Generated ${ map. generatedAt } by design-map.mjs. Read before writing UI. Reuse what is here; add a token or primitive only when nothing fits, and say so in the handoff.
## Stack
${ Object . entries ( stack) . map ( ( [ k, v] ) => line ( k, v) ) . join ( '\n' ) }
- **tailwind:** ${ tailwindMode ?? '—' }
- **shadcn:** ${ shadcn ? ` style= ${ map. shadcn . style } , baseColor= ${ map. shadcn . baseColor } ` : '—' }
- **fonts:** ${ map. fonts . join ( ', ' ) || '—' }
## Primitives (reuse, do not duplicate)
${ uiComponents. length ? uiComponents. map ( ( c ) => ` \` ${ c} \` ` ) . join ( ' ' ) : '— (no components/ui)' }
## Feature components
${ map. featureComponents . length ? map. featureComponents . slice ( 0 , 60 ) . map ( ( c ) => ` - ${ c} ` ) . join ( '\n' ) : '—' } ${ map. featureComponents . length > 60 ? ` \n- … ${ map. featureComponents . length - 60 } more ` : '' }
## Tokens
- **:root** ${ tokenList ( tokens. root ) }
- **.dark** ${ tokenList ( tokens. dark ) }
- **@theme** ${ tokenList ( tokens. theme ) }
## Drift (lower is better; a diff must not raise these)
| rule | count | why | top files |
|---|---|---|---|
${ Object . entries ( map. drift ) . map ( ( [ k, v] ) => ` | ${ k} | ${ v. count } | ${ v. why } | ${ v. top || '—' } | ` ) . join ( '\n' ) }
`
;
const
=
stateDir
(
)
;
.
mkdirSync
(
,
{
recursive
:
true
}
)
;
.
writeFileSync
(
.
join
(
,
'design-map.md'
)
,
)
;
writeJsonAtomic
(
.
join
(
,
'design-map.json'
)
,
)
;
appendEvent
(
,
{
type
:
'design-map.generated'
,
primitives
:
.
length
,
drift
:
Object
.
fromEntries
(
Object
.
entries
(
.
drift
)
.
map
(
(
[ k, v]
)
=>
[
,
.
count
]
)
)
}
)
;
if
(
.
compare
&&
.
compare
!==
true
)
{
const
=
readJson
(
.
resolve
(
.
compare
)
,
null
)
;
if
(
!
)
{
console
.
error
(
` Cannot read ${ flags. compare } `
)
;
.
exit
(
1
)
;
}
const
=
Object
.
entries
(
.
drift
)
.
filter
(
(
[ k, v]
)
=>
.
count
>
(
.
drift
?.
[
]
?.
??
0
)
)
;
for
(
const
[
,
]
of
Object
.
entries
(
.
drift
)
)
console
.
log
(
` ${ k. padEnd ( 16 ) } ${ String ( before. drift ?. [ k] ?. count ?? 0 ) . padStart ( 5 ) } -> ${ String ( v. count ) . padStart ( 5 ) } `
)
;
console
.
log
(
.
length
?
` \nDrift increased: ${ worse. map ( ( [ k] ) => k) . join ( ', ' ) } `
:
'\nNo drift increase.'
)
;
.
exit
(
.
length
?
1
:
0
)
;
}
if
(
.
json
)
console
.
log
(
JSON
.
stringify
(
,
null
,
2
)
)
;
else
console
.
log
(
` ${ md} \nSaved: ${ rel ( path. join ( outDir, 'design-map.md' ) ) } `
)
;