Added more agent skills
This commit is contained in:
@@ -49,6 +49,12 @@ UI=$(dirs src/blocks src/components)
|
||||
|
||||
echo "ipal-audit — $(pwd)"
|
||||
|
||||
# --- Skill templates must not be compiled as project code ---
|
||||
if [ -d .agents ] && [ -f tsconfig.json ]; then
|
||||
report ERROR "tsconfig.json does not exclude .agents" "skill templates (.ts/.tsx) break tsc / next build — \"exclude\": [\"node_modules\", \".agents\"]" \
|
||||
"$(grep -qE '"exclude"[^]]*\.agents' tsconfig.json || echo tsconfig.json)"
|
||||
fi
|
||||
|
||||
# --- Architecture (AGENT.md §4) ---
|
||||
report ERROR "middleware.ts exists" "§4.1 Next 16 uses proxy.ts only" \
|
||||
"$(ls src/middleware.ts middleware.ts 2>/dev/null)"
|
||||
@@ -93,6 +99,9 @@ if [ -n "$BLOCKS" ]; then
|
||||
report ERROR "raw <a>/<Link> in blocks" "§6.3 links from the panel render via CMSLink" \
|
||||
"$(g '<(a|Link)[ >]' $BLOCKS --include=*.tsx)"
|
||||
|
||||
report ERROR "hardcoded text in blocks" "§2 every visible text comes from the panel (localized field)" \
|
||||
"$(node "$(dirname "$0")/jsx-text.mjs" $BLOCKS 2>/dev/null)"
|
||||
|
||||
report WARNING "inline <svg> in blocks" "§6.10 icons via media upload or Icon map" \
|
||||
"$(g '<svg[ >]' $BLOCKS --include=*.tsx)"
|
||||
|
||||
@@ -103,6 +112,11 @@ if [ -n "$BLOCKS" ]; then
|
||||
"$(g "from '\./Component'|/Component'" $BLOCKS --include=config.ts)"
|
||||
fi
|
||||
|
||||
if [ -d src/components ]; then
|
||||
report WARNING "hardcoded text in components/layout" "§2 texts and a11y labels from the panel — keep only symbols/numbers in code" \
|
||||
"$(node "$(dirname "$0")/jsx-text.mjs" src/components 2>/dev/null)"
|
||||
fi
|
||||
|
||||
if [ -n "$UI" ]; then
|
||||
report ERROR "hex colors in classes" "§6.11 use design tokens (bg-primary…)" \
|
||||
"$(g '(bg|text|border|from|to|via|fill|stroke)-\[#' $UI --include=*.tsx)"
|
||||
@@ -125,6 +139,17 @@ if [ -d src/collections ]; then
|
||||
"$(ls src/collections | grep -viE '^(pages|media|users|user|settings|navigation|nav|footer|header|faq|hero|company|danefirmy)\.ts$')"
|
||||
fi
|
||||
|
||||
# --- Editor panel clarity (§6.5a) ---
|
||||
SCHEMA=$(dirs src/blocks src/collections src/globals src/fields)
|
||||
if [ -n "$SCHEMA" ]; then
|
||||
PANEL=$(node "$(dirname "$0")/panel-check.mjs" $SCHEMA)
|
||||
while IFS= read -r rule; do
|
||||
[ -z "$rule" ] && continue
|
||||
level=${rule%%|*}; rest=${rule#*|}
|
||||
report "$level" "panel: ${rest%%|*}" "§6.5a editor panel" "$(printf '%s\n' "$PANEL" | grep -F "$level|${rest%%|*}|" | cut -d'|' -f3-)"
|
||||
done <<< "$(printf '%s\n' "$PANEL" | cut -d'|' -f1-2 | sort -u)"
|
||||
fi
|
||||
|
||||
# --- Plugin duplicates (§1, §7) ---
|
||||
report ERROR "own block renderer switch" "§7 use RenderBlocks + registry" \
|
||||
"$(g 'switch *\(.*blockType' src --include=*.tsx --include=*.ts)"
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env node
|
||||
// Finds user-visible text hardcoded in JSX (AGENT.md §2: everything visible comes from the panel).
|
||||
// node jsx-text.mjs <dir> [<dir> …] → prints "file:line: text" per finding, exit 0
|
||||
// Detects:
|
||||
// - text between HTML text tags: <h2>Nasze usługi</h2>, <p>\n Lorem…\n</p>, </strong> więcej <
|
||||
// - text attributes with words: alt="Logo firmy", placeholder="Twój e-mail", aria-label="Zamknij"
|
||||
// Ignores comments, {expressions}, digits/punctuation/symbols only (404, →, ☰, ·).
|
||||
import { readFileSync, readdirSync, statSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const TEXT_TAGS =
|
||||
'h1|h2|h3|h4|h5|h6|p|span|a|button|li|label|strong|em|b|i|small|div|section|article|header|footer|main|nav|td|th|dt|dd|figcaption|blockquote|option|legend|summary|caption|q|cite|time|mark'
|
||||
// Opening tags: HTML text tags or Capitalized components (<Link …>), never preceded by an
|
||||
// identifier char — that excludes TS generics like useState<Boolean>( … ).
|
||||
const OPEN_OR_CLOSE = new RegExp(
|
||||
`(?:(?<![\\w.$])<(?:${TEXT_TAGS}|[A-Z][\\w.]*)(?:\\s[^<>]*)?>|</[A-Za-z][\\w.]*>)([^<>{}]*)(?=<|\\{)`,
|
||||
'g',
|
||||
)
|
||||
const ATTR = /\b(alt|title|placeholder|aria-label|label)=("([^"]*)"|'([^']*)')/g
|
||||
const WORD = /\p{L}{2,}/u
|
||||
// Text right after a closing/self-closing tag may be the JS that follows the JSX
|
||||
// expression (`<X /> : null`, `</div>) }`, `</p>\n const id = …`) — not visible text.
|
||||
const JS_CODE = /(^|\s)(return|const|let|var|if|else|export|import|await|typeof)\b|=>|[=;`]|^\s*[:?)\]}]|&&|\|\|/
|
||||
|
||||
const files = []
|
||||
const walk = (p) => {
|
||||
let st
|
||||
try { st = statSync(p) } catch { return }
|
||||
if (st.isDirectory()) for (const n of readdirSync(p)) walk(join(p, n))
|
||||
else if (p.endsWith('.tsx')) files.push(p)
|
||||
}
|
||||
process.argv.slice(2).forEach(walk)
|
||||
|
||||
// Blank out comments but keep line numbers.
|
||||
const stripComments = (src) =>
|
||||
src
|
||||
.replace(/\{\/\*[\s\S]*?\*\/\}/g, (m) => m.replace(/[^\n]/g, ' '))
|
||||
.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' '))
|
||||
.replace(/(^|[^:"'`])\/\/.*$/gm, (m, p) => p + ' '.repeat(m.length - p.length))
|
||||
|
||||
const lineOf = (src, idx) => src.slice(0, idx).split('\n').length
|
||||
|
||||
for (const file of files) {
|
||||
const src = stripComments(readFileSync(file, 'utf8'))
|
||||
for (const m of src.matchAll(OPEN_OR_CLOSE)) {
|
||||
const text = m[1].replace(/\s+/g, ' ').trim()
|
||||
if (!text || !WORD.test(text) || JS_CODE.test(text)) continue
|
||||
if (/&[a-z]+;/.test(text) && !WORD.test(text.replace(/&[a-z]+;/g, ''))) continue
|
||||
console.log(`${file}:${lineOf(src, m.index + m[0].length - m[1].length)}: ${text.slice(0, 80)}`)
|
||||
}
|
||||
for (const m of src.matchAll(ATTR)) {
|
||||
const value = m[3] ?? m[4] ?? ''
|
||||
if (!WORD.test(value)) continue
|
||||
console.log(`${file}:${lineOf(src, m.index)}: ${m[1]}="${value.slice(0, 60)}"`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
// Editor-panel clarity checks (AGENT.md §6.5a): prints "LEVEL|rule|file:line: detail", exit 0.
|
||||
// node panel-check.mjs src/blocks src/collections src/globals src/fields
|
||||
import { readFileSync, readdirSync, statSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
const files = []
|
||||
const walk = (p) => {
|
||||
let st
|
||||
try { st = statSync(p) } catch { return }
|
||||
if (st.isDirectory()) for (const n of readdirSync(p)) walk(join(p, n))
|
||||
else if (/\.ts$/.test(p) && !/Component|\.d\.ts$/.test(p)) files.push(p)
|
||||
}
|
||||
process.argv.slice(2).forEach(walk)
|
||||
|
||||
const POLISH = /[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]/
|
||||
const lineOf = (src, i) => src.slice(0, i).split('\n').length
|
||||
const out = (level, rule, file, src, i, detail) => console.log(`${level}|${rule}|${file}:${lineOf(src, i)}: ${detail}`)
|
||||
const strip = (s) => s.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, ' ')).replace(/(^|[^:])\/\/.*$/gm, (m, p) => p + ' '.repeat(m.length - p.length))
|
||||
|
||||
for (const file of files) {
|
||||
const src = strip(readFileSync(file, 'utf8'))
|
||||
|
||||
// numbered slots: cta1Label, feature2Title, image3, phone2 → array with "+ Add …"
|
||||
for (const m of src.matchAll(/name:\s*['"]([a-zA-Z]+[0-9]+[a-zA-Z0-9]*)['"]/g)) {
|
||||
if (/^(h[1-6]|x[0-9]|[a-z]?2fa)$/i.test(m[1])) continue
|
||||
out('ERROR', 'numbered fields → one array field with labels {singular, plural} ("+ Add …")', file, src, m.index, m[1])
|
||||
}
|
||||
|
||||
// panel text must be English and short
|
||||
for (const m of src.matchAll(/\b(label|description|singular|plural|placeholder)\s*:\s*(['"`])((?:(?!\2).)*)\2/g)) {
|
||||
const text = m[3]
|
||||
if (POLISH.test(text)) out('WARNING', 'panel is English — labels/descriptions in English', file, src, m.index, `${m[1]}: "${text.slice(0, 60)}"`)
|
||||
else if (m[1] === 'description' && text.length > 120) out('WARNING', 'description over 120 chars — one short sentence: what it does / where it shows', file, src, m.index, `${text.length} chars`)
|
||||
}
|
||||
|
||||
// arrays: labels (→ "Add Feature" button) + rowLabel (→ readable rows)
|
||||
for (const m of src.matchAll(/type:\s*['"]array['"]/g)) {
|
||||
const before = src.slice(0, m.index)
|
||||
const start = Math.max(before.lastIndexOf('name:'), before.lastIndexOf('{'))
|
||||
const fieldsAt = src.indexOf('fields:', m.index)
|
||||
const head = src.slice(start < 0 ? m.index : start, fieldsAt < 0 ? m.index + 400 : fieldsAt)
|
||||
const name = head.match(/name:\s*['"](\w+)['"]/)?.[1] ?? '?'
|
||||
if (!/\blabels\s*:/.test(head)) out('WARNING', 'array without labels {singular, plural} — panel shows "Add Row"', file, src, m.index, name)
|
||||
if (!/rowLabel|RowLabel/.test(head)) out('WARNING', 'array without rowLabel() — rows read "Item 01" instead of their content', file, src, m.index, name)
|
||||
}
|
||||
|
||||
// too many fields in one block config → tabs / condition / arrays / variant
|
||||
if (/\/blocks\/[^/]+\/config\.ts$/.test(file)) {
|
||||
const n = (src.match(/name:\s*['"]/g) ?? []).length
|
||||
const hasTabs = /type:\s*['"]tabs['"]/.test(src)
|
||||
if (n > 14 && !hasTabs) out('WARNING', 'block has many fields and no tabs — tabs Content/Media/Settings, admin.condition, arrays', file, src, 0, `${n} fields`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user