Agent Harness · VibeGit
Agent Harness Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
agent-harness / tools / skills.mjs 121 строк · изменён 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
import fs from 'node:fs' ;
import path from 'node:path' ;
import { HARNESS_ROOT , parseArgs, readJson, copyDir, walkFiles, sha256 } from './lib.mjs' ;
const NAME_RE = / ^ [ a- z 0- 9 ] + ( -[ a- z 0- 9 ] + ) * $ / ;
export function
text text
end text
end
lines text text end
data
i i lines i
m lines i
m
key raw m
raw
block
i lines lines i lines i block lines i
data key raw block block
data key raw
data text end
fs root
fs root d d
issues
dir root
file path root dir
where path file file
fs file
issues where
text fs file
fm text
fm
issues where
name description fm
name issues where
name name issues where
name dir issues where
description issues where
description issues where
description issues where
bodyLines fm l
bodyLines issues where
linkable fm
ref linkable
fs path root dir ref issues where
issues
pi path manifest
oc path manifest
issues
a pi
b oc
name a b n issues name
name b a n issues name
name a b n manifest n
fa path pi name path path pi name f
fb path oc name path path oc name f
differs fa fb fa fb rel path pi name rel path oc name rel
differs issues name
issues
pi path manifest
oc path manifest
synced
name pi
manifest name fs path oc name
fs path oc name
path pi name path oc name
synced name
synced
path
process
positional process
manifest
positional
positional positional
issues
path manifest
path manifest
manifest
i issues
errors issues i
errors
process errors
process
parseFrontmatter
(
text
)
{
if
(
!
.
startsWith
(
'---\n'
)
&&
!
.
startsWith
(
'---\r\n'
)
)
return
null
;
const
=
.
indexOf
(
'\n---'
,
4
)
;
if
(
===
-
1
)
return
null
;
const
=
.
slice
(
.
indexOf
(
'\n'
)
+
1
,
)
.
split
(
/ \r ? \n /
)
;
const
=
{
}
;
for
(
let
=
0
;
<
.
length
;
+=
1
)
{
const
=
[
]
.
match
(
/ ^ ( [ A- Z a- z ] [ \w -] * ) :\s * ( . * ) $ /
)
;
if
(
!
)
continue
;
const
[
,
,
]
=
;
if
(
/ ^ [ >|] [ -+] ? $ /
.
test
(
)
)
{
const
=
[
]
;
while
(
+
1
<
.
length
&&
(
/ ^ \s + \S /
.
test
(
[
+
1
]
)
||
[
+
1
]
.
trim
(
)
===
''
)
)
.
push
(
[
(
+=
1
)
]
.
trim
(
)
)
;
[
]
=
.
startsWith
(
'>'
)
?
.
join
(
' '
)
.
replace
(
/ \s + / g
,
' '
)
.
trim
(
)
:
.
join
(
'\n'
)
.
trim
(
)
;
}
else
{
[
]
=
.
replace
(
/ ^ [ "'] | [ "'] $ / g
,
''
)
.
trim
(
)
;
}
}
return
{
,
body
:
.
slice
(
+
4
)
}
;
}
function
skillDirs
(
root
)
{
if
(
!
.
existsSync
(
)
)
return
[
]
;
return
.
readdirSync
(
,
{
withFileTypes
:
true
}
)
.
filter
(
(
d
)
=>
.
isDirectory
(
)
)
.
map
(
(
d
)
=>
.
name
)
.
sort
(
)
;
}
export
function
validateSkillsDir
(
root
)
{
const
=
[
]
;
for
(
const
of
skillDirs
(
)
)
{
const
=
.
join
(
,
,
'SKILL.md'
)
;
const
=
.
relative
(
HARNESS_ROOT
,
)
||
;
if
(
!
.
existsSync
(
)
)
{
.
push
(
{
level
:
'error'
,
,
message
:
'missing SKILL.md'
}
)
;
continue
;
}
const
=
.
readFileSync
(
,
'utf8'
)
;
const
=
parseFrontmatter
(
)
;
if
(
!
)
{
.
push
(
{
level
:
'error'
,
,
message
:
'missing YAML frontmatter (agent will never discover this skill)'
}
)
;
continue
;
}
const
{
,
}
=
.
data
;
if
(
!
)
.
push
(
{
level
:
'error'
,
,
message
:
'frontmatter.name is required'
}
)
;
else
if
(
!
NAME_RE
.
test
(
)
||
.
length
>
64
)
.
push
(
{
level
:
'error'
,
,
message
:
` invalid name " ${ name} " `
}
)
;
else
if
(
!==
)
.
push
(
{
level
:
'error'
,
,
message
:
` name " ${ name} " must match directory " ${ dir} " (OpenCode requirement) `
}
)
;
if
(
!
)
.
push
(
{
level
:
'error'
,
,
message
:
'frontmatter.description is required'
}
)
;
else
if
(
.
length
>
1024
)
.
push
(
{
level
:
'error'
,
,
message
:
` description is ${ description. length } chars (max 1024) `
}
)
;
else
if
(
.
length
<
40
)
.
push
(
{
level
:
'warn'
,
,
message
:
'description is too short for reliable routing'
}
)
;
const
=
.
body
.
split
(
'\n'
)
.
filter
(
(
l
)
=>
.
trim
(
)
)
.
length
;
if
(
<
12
)
.
push
(
{
level
:
'warn'
,
,
message
:
` body has only ${ bodyLines} non-empty lines `
}
)
;
const
=
.
body
.
replace
(
/ ```[ \s \S ] *? ``` / g
,
''
)
.
replace
(
/ `[ ^ `\n ] * ` / g
,
''
)
;
for
(
const
of
.
matchAll
(
/ \] \( (?! https? :| #| mailto:) ( [ ^ )\s ] + \. md) \) / g
)
)
{
if
(
!
.
existsSync
(
.
join
(
,
,
[
1
]
)
)
)
.
push
(
{
level
:
'error'
,
,
message
:
` broken link ${ ref[ 1 ] } `
}
)
;
}
}
return
;
}
export
function
parity
(
manifest
)
{
const
=
.
join
(
HARNESS_ROOT
,
.
paths
.
piSkills
)
;
const
=
.
join
(
HARNESS_ROOT
,
.
paths
.
opencodeSkills
)
;
const
=
[
]
;
const
=
skillDirs
(
)
;
const
=
skillDirs
(
)
;
for
(
const
of
.
filter
(
(
n
)
=>
!
.
includes
(
)
)
)
.
push
(
{
level
:
'error'
,
where
:
,
message
:
'present in Pi, missing in OpenCode (run: node tools/skills.mjs sync)'
}
)
;
for
(
const
of
.
filter
(
(
n
)
=>
!
.
includes
(
)
)
)
.
push
(
{
level
:
'error'
,
where
:
,
message
:
'present in OpenCode, missing in Pi'
}
)
;
for
(
const
of
.
filter
(
(
n
)
=>
.
includes
(
)
&&
!
.
platformSpecificSkills
.
includes
(
)
)
)
{
const
=
walkFiles
(
.
join
(
,
)
,
{
skip
:
[
]
}
)
.
map
(
(
f
)
=>
.
relative
(
.
join
(
,
)
,
)
)
;
const
=
walkFiles
(
.
join
(
,
)
,
{
skip
:
[
]
}
)
.
map
(
(
f
)
=>
.
relative
(
.
join
(
,
)
,
)
)
;
const
=
.
length
!==
.
length
||
.
some
(
(
rel
)
=>
!
.
includes
(
)
||
sha256
(
.
join
(
,
,
)
)
!==
sha256
(
.
join
(
,
,
)
)
)
;
if
(
)
.
push
(
{
level
:
'error'
,
where
:
,
message
:
'Pi and OpenCode copies differ (run: node tools/skills.mjs sync)'
}
)
;
}
return
;
}
function
sync
(
manifest
)
{
const
=
.
join
(
HARNESS_ROOT
,
.
paths
.
piSkills
)
;
const
=
.
join
(
HARNESS_ROOT
,
.
paths
.
opencodeSkills
)
;
const
=
[
]
;
for
(
const
of
skillDirs
(
)
)
{
if
(
.
platformSpecificSkills
.
includes
(
)
&&
.
existsSync
(
.
join
(
,
)
)
)
continue
;
.
rmSync
(
.
join
(
,
)
,
{
recursive
:
true
,
force
:
true
}
)
;
copyDir
(
.
join
(
,
)
,
.
join
(
,
)
)
;
.
push
(
)
;
}
return
;
}
export
function
loadManifest
(
)
{
return
readJson
(
.
join
(
HARNESS_ROOT
,
'harness.json'
)
)
;
}
if
(
.
argv
[
1
]
?.
endsWith
(
'skills.mjs'
)
)
{
const
{
}
=
parseArgs
(
.
argv
.
slice
(
2
)
)
;
const
=
loadManifest
(
)
;
if
(
[
0
]
===
'sync'
)
{
console
.
log
(
` Synced to OpenCode: ${ sync ( manifest) . join ( ', ' ) } `
)
;
console
.
log
(
` Kept platform-specific: ${ manifest. platformSpecificSkills . join ( ', ' ) } `
)
;
}
else
if
(
[
0
]
===
'validate'
||
!
[
0
]
)
{
const
=
[
...
validateSkillsDir
(
.
join
(
HARNESS_ROOT
,
.
paths
.
piSkills
)
)
,
...
validateSkillsDir
(
.
join
(
HARNESS_ROOT
,
.
paths
.
opencodeSkills
)
)
,
...
parity
(
)
,
]
;
for
(
const
of
)
console
.
log
(
` ${ i. level . toUpperCase ( ) . padEnd ( 5 ) } ${ i. where } : ${ i. message } `
)
;
const
=
.
filter
(
(
i
)
=>
.
level
===
'error'
)
.
length
;
console
.
log
(
?
` \n ${ errors} error(s). `
:
` \nSkills OK ( ${ issues. length } warning(s)). `
)
;
.
exit
(
?
1
:
0
)
;
}
else
{
console
.
log
(
'Usage: node skills.mjs [validate|sync]'
)
;
.
exit
(
1
)
;
}
}