Agent Harness · VibeGitAgent Harness
Публичная копия обвязки агентной разработки: гейты, journeys, скиллы и шаблоны. Без ключей и личных данных.
183 строк · изменён 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import fs from 'node:fs';
import path from 'node:path';
import { HARNESS_ROOT, homeDir, parseArgs, list, walkFiles, sha256, writeJsonAtomic, fail } from './lib.mjs';
import { loadManifest, validateSkillsDir, parity } from './skills.mjs';
const { flags } = parseArgs(process.argv.slice(2));
const dryRun = Boolean(flags[
home
manifest
stamp
backupRoot pathhome stamp
p home
log
universal manifest
known universal
detected universal
cfg cfg fsp
name
requested flags
targets requested
known
requested
requested
detected
customSkillDirs flags
t targets knownt
preflight
path manifest
path manifest
manifest
i
preflight
i preflight
fsdest
src dest
logdest
backup pathbackupRoot pathhome dest
dryRun
fspathbackup
fsdest backup
logdest
dryRun
fspathdest
fssrc dest
logdest
src path srcRel
fssrc
file src file pathdestTilde pathsrc file
dest destTilde
blocker dest alsoBlockedByexpand fsp
blocker
log
path srcRel dest
targets
cfg manifest
manifest cfg
manifest cfg
manifest cfg
src dest cfg src dest
targets
cfg manifest
manifest cfg
manifest cfg
manifest cfg
src dest cfg src dest
fsdest fsdest content
logdest
fsdest force
dryRun fs content
log
fsdest
backup pathbackupRoot pathhome dest
dryRun
fspathbackup
fsdest backup
logdest
dryRun
fspathdest
fsdest content
logdest
raw fsfile
match raw
match raw
keep match line
keep line keep
instructionsImport
name targets universalt
cfg universalname
manifest cfg
cfg
src path manifest
file src
file pathcfg pathsrc file
cfg manifest cfg
cfg
dest cfg
force flags
cfg instructionsImport dest force
fspath cfg dest force
dir customSkillDirs manifest dir
runtime manifest
manifest pathruntime
f path f pathruntime f
pathruntime
manifest pathruntime
path pathruntime
path pathruntime
agentsTarget pathhome
agentsSrc path
fsagentsTarget agentsSrc agentsTarget
agentsSrc agentsTarget logagentsTarget
flags agentsSrc agentsTarget
dryRun fsagentsSrc
log
dryRun
pathruntime
manifest
targets
loglog fsf f f
log backupRoot
log
s log
'dry-run'
]
)
;
const
=
homeDir
(
)
;
const
=
loadManifest
(
)
;
const
=
new
Date
(
)
.
toISOString
(
)
.
replace
(
/[:.]/g
,
'-'
)
;
const
=
.
join
(
,
'.agent-harness'
,
'backups'
,
)
;
const
expand
=
(
p
)
=>
.
replace
(
/^~(?=$|\/)/
,
)
;
const
=
{
written
:
[
]
,
unchanged
:
[
]
,
backedUp
:
[
]
,
skipped
:
[
]
}
;
const
=
.
install
.
universal
??
{
}
;
const
=
[
'pi'
,
'opencode'
,
...
Object
.
keys
(
)
]
;
const
=
Object
.
entries
(
)
.
filter
(
(
[, cfg]
)
=>
!
.
detect
.
length
||
.
detect
.
some
(
(
p
)
=>
.
existsSync
(
expand
(
)
)
)
)
.
map
(
(
[name]
)
=>
)
;
const
=
list
(
.
target
)
;
const
=
.
includes
(
'all'
)
?
:
.
length
?
:
[
'pi'
,
'opencode'
,
...
]
;
const
=
list
(
[
'skills-dir'
]
)
;
for
(
const
of
)
if
(
!
.
includes
(
)
)
fail
(
`Unknown target ${t}. Known: ${known.join(', ')}, all`
)
;
const
=
[
...
validateSkillsDir
(
.
join
(
HARNESS_ROOT
,
.
paths
.
piSkills
)
)
,
...
validateSkillsDir
(
.
join
(
HARNESS_ROOT
,
.
paths
.
opencodeSkills
)
)
,
...
parity
(
)
,
]
.
filter
(
(
i
)
=>
.
level
===
'error'
)
;
if
(
.
length
)
{
for
(
const
of
)
console
.
error
(
`ERROR ${i.where}: ${i.message}`
)
;
fail
(
'Harness is inconsistent; fix it before installing (node tools/skills.mjs validate).'
)
;
}
function
place
(
src, dest
)
{
if
(
.
existsSync
(
)
)
{
if
(
sha256
(
)
===
sha256
(
)
)
{
.
unchanged
.
push
(
)
;
return
;
}
const
=
.
join
(
,
.
relative
(
,
)
)
;
if
(
!
)
{
.
mkdirSync
(
.
dirname
(
)
,
{
recursive
:
true
}
)
;
.
copyFileSync
(
,
)
;
}
.
backedUp
.
push
(
)
;
}
if
(
!
)
{
.
mkdirSync
(
.
dirname
(
)
,
{
recursive
:
true
}
)
;
.
copyFileSync
(
,
)
;
}
.
written
.
push
(
)
;
}
function
placeTree
(
srcRel, destTilde
)
{
const
=
.
join
(
HARNESS_ROOT
,
)
;
if
(
!
.
existsSync
(
)
)
return
;
for
(
const
of
walkFiles
(
,
{
skip
:
[
]
}
)
)
place
(
,
.
join
(
expand
(
)
,
.
relative
(
,
)
)
)
;
}
function
placeIfMissing
(
srcRel, destTilde, alsoBlockedBy = []
)
{
const
=
expand
(
)
;
const
=
[
,
...
.
map
(
)
]
.
find
(
(
p
)
=>
.
existsSync
(
)
)
;
if
(
)
{
.
skipped
.
push
(
`${blocker} (exists, not touched)`
)
;
return
;
}
place
(
.
join
(
HARNESS_ROOT
,
)
,
)
;
}
if
(
.
includes
(
'pi'
)
)
{
const
=
.
install
.
pi
;
placeTree
(
.
paths
.
piSkills
,
.
skills
)
;
placeTree
(
.
paths
.
piAgents
,
.
agents
)
;
placeTree
(
.
paths
.
opencodeCommands
,
.
prompts
)
;
for
(
const
[
,
]
of
Object
.
entries
(
.
configExamples
)
)
placeIfMissing
(
,
)
;
}
if
(
.
includes
(
'opencode'
)
)
{
const
=
.
install
.
opencode
;
placeTree
(
.
paths
.
opencodeSkills
,
.
skills
)
;
placeTree
(
.
paths
.
opencodeAgents
,
.
agents
)
;
placeTree
(
.
paths
.
opencodeCommands
,
.
commands
)
;
for
(
const
[
,
]
of
Object
.
entries
(
.
configExamples
)
)
placeIfMissing
(
,
,
[
'~/.config/opencode/opencode.json'
]
)
;
}
function
writeGenerated
(
content, dest, { force = false } = {}
)
{
if
(
.
existsSync
(
)
&&
.
readFileSync
(
,
'utf8'
)
===
)
{
.
unchanged
.
push
(
)
;
return
;
}
if
(
.
existsSync
(
)
&&
!
)
{
if
(
!
)
.
writeFileSync
(
`${dest}.harness-new`
,
)
;
.
skipped
.
push
(
`${dest} differs: new version saved as ${path.basename(dest)}.harness-new (merge by hand or rerun with --force-agents)`
)
;
return
;
}
if
(
.
existsSync
(
)
)
{
const
=
.
join
(
,
.
relative
(
,
)
)
;
if
(
!
)
{
.
mkdirSync
(
.
dirname
(
)
,
{
recursive
:
true
}
)
;
.
copyFileSync
(
,
)
;
}
.
backedUp
.
push
(
)
;
}
if
(
!
)
{
.
mkdirSync
(
.
dirname
(
)
,
{
recursive
:
true
}
)
;
.
writeFileSync
(
,
)
;
}
.
written
.
push
(
)
;
}
function
portableAgent
(
file
)
{
const
=
.
readFileSync
(
,
'utf8'
)
;
const
=
.
match
(
/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/
)
;
if
(
!
)
return
;
const
=
[
1
]
.
split
(
'\n'
)
.
filter
(
(
line
)
=>
/^(name|description):/
.
test
(
)
)
;
if
(
!
.
some
(
(
line
)
=>
.
startsWith
(
'name:'
)
)
)
.
unshift
(
`name: ${path.basename(file, '.md')}`
)
;
return
`---\n${keep.join('\n')}\n---\n${match[2]}`
;
}
const
=
'# Harness\n\n@~/AGENTS.md\n@~/AGENTS-SUMMARY.md\n'
;
for
(
const
of
.
filter
(
(
t
)
=>
[
]
)
)
{
const
=
[
]
;
placeTree
(
.
paths
.
opencodeSkills
,
.
skills
)
;
if
(
.
agents
)
{
const
=
.
join
(
HARNESS_ROOT
,
.
paths
.
opencodeAgents
)
;
for
(
const
of
walkFiles
(
,
{
skip
:
[
]
}
)
)
{
writeGenerated
(
portableAgent
(
)
,
.
join
(
expand
(
.
agents
)
,
.
relative
(
,
)
)
)
;
}
}
if
(
.
commands
)
placeTree
(
.
paths
.
opencodeCommands
,
.
commands
)
;
if
(
.
instructions
)
{
const
=
expand
(
.
instructions
)
;
const
=
Boolean
(
[
'force-agents'
]
)
;
if
(
.
instructionsMode
===
'import'
)
writeGenerated
(
,
,
{
}
)
;
else
writeGenerated
(
.
readFileSync
(
.
join
(
HARNESS_ROOT
,
.
instructionsSource
??
'AGENTS.md'
)
,
'utf8'
)
,
,
{
}
)
;
}
}
for
(
const
of
)
placeTree
(
.
paths
.
opencodeSkills
,
)
;
const
=
expand
(
.
install
.
runtime
)
;
placeTree
(
.
paths
.
tools
,
.
join
(
,
'tools'
)
)
;
for
(
const
of
[
'harness.json'
,
'.agent-gates.json'
,
'.release-policy.json'
,
'VERSION.md'
]
)
place
(
.
join
(
HARNESS_ROOT
,
)
,
.
join
(
,
)
)
;
placeTree
(
'bench'
,
.
join
(
,
'bench'
)
)
;
placeTree
(
.
paths
.
templates
??
'templates'
,
.
join
(
,
'templates'
)
)
;
place
(
.
join
(
HARNESS_ROOT
,
'opencode'
,
'opencode.official.jsonc.example'
)
,
.
join
(
,
'examples'
,
'opencode.official.jsonc.example'
)
)
;
place
(
.
join
(
HARNESS_ROOT
,
'zcode'
,
'mcp.example.json'
)
,
.
join
(
,
'zcode'
,
'mcp.example.json'
)
)
;
const
=
.
join
(
,
'AGENTS.md'
)
;
const
=
.
join
(
HARNESS_ROOT
,
'AGENTS.md'
)
;
if
(
!
.
existsSync
(
)
)
place
(
,
)
;
else
if
(
sha256
(
)
===
sha256
(
)
)
.
unchanged
.
push
(
)
;
else
if
(
[
'force-agents'
]
)
place
(
,
)
;
else
{
if
(
!
)
.
copyFileSync
(
,
`${agentsTarget}.harness-new`
)
;
.
skipped
.
push
(
`${agentsTarget} differs: new version saved as AGENTS.md.harness-new (merge by hand or rerun with --force-agents)`
)
;
}
if
(
!
)
{
writeJsonAtomic
(
.
join
(
,
'installed.json'
)
,
{
version
:
.
version
,
at
:
new
Date
(
)
.
toISOString
(
)
,
,
files
:
.
written
.
concat
(
.
unchanged
)
.
filter
(
(
f
)
=>
.
existsSync
(
)
)
.
map
(
(
f
)
=>
(
{
path
:
,
sha256
:
sha256
(
)
}
)
)
,
backups
:
.
backedUp
.
length
?
:
null
,
}
)
;
}
console
.
log
(
`${dryRun ? '[dry-run] ' : ''}aggg-harness ${manifest.version} -> ${targets.join(', ')}`
)
;
console
.
log
(
` written: ${log.written.length}`
)
;
console
.
log
(
` unchanged: ${log.unchanged.length}`
)
;
if
(
.
backedUp
.
length
)
console
.
log
(
` backed up: ${log.backedUp.length} -> ${backupRoot}`
)
;
for
(
const
of
.
skipped
)
console
.
log
(
` skipped: ${s}`
)
;
console
.
log
(
`\nNext: node "${path.join(runtime, 'tools', 'doctor.mjs')}"`
)
;