@sockulags/agent-os 0.11.0 → 0.12.0
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/README.md +155 -127
- package/cli/index.mjs +1022 -735
- package/cli/index.test.mjs +574 -300
- package/hooks/hooks.json +17 -0
- package/package.json +34 -32
- package/policy.md +47 -45
- package/skills/batch-work/SKILL.md +43 -43
- package/skills/batch-work/agents/openai.yaml +2 -2
- package/skills/batch-work/references/manifest.md +100 -100
- package/skills/batch-work/scripts/manifest-hash.mjs +263 -263
- package/skills/batch-work/scripts/test-manifest-hash.mjs +132 -132
- package/skills/chart-work/SKILL.md +37 -37
- package/skills/chart-work/references/elicitation.md +25 -25
- package/skills/chart-work/references/map.md +84 -84
- package/skills/chart-work/references/prototypes.md +21 -21
- package/skills/check-work/SKILL.md +61 -0
- package/skills/deliver-work/SKILL.md +12 -12
- package/skills/deliver-work/workflow.md +119 -113
- package/skills/diagnose-before-fix/SKILL.md +24 -24
- package/skills/dispatch-next/SKILL.md +28 -28
- package/skills/init-agent-os/SKILL.md +54 -39
- package/skills/init-agent-os/references/repository-init.md +74 -0
- package/skills/init-agent-os/scripts/policy-block.ps1 +87 -87
- package/skills/list-skills/SKILL.md +43 -42
- package/skills/list-skills/agents/openai.yaml +2 -2
- package/skills/plain-voice/SKILL.md +39 -0
- package/skills/plain-voice/references/tells.md +82 -0
- package/skills/proportional-testing/SKILL.md +30 -30
- package/skills/proportional-testing/references/strategy.md +75 -75
- package/skills/quality-ratchet/SKILL.md +50 -0
- package/skills/quality-ratchet/scripts/quality-delta.mjs +752 -0
- package/skills/quality-ratchet/scripts/quality-delta.test.mjs +514 -0
- package/skills/scope-guard/SKILL.md +21 -21
- package/skills/shape-work/SKILL.md +39 -39
- package/skills/shape-work/references/implementation-issues.md +69 -69
- package/skills/shape-work/references/mockups.md +23 -23
- package/skills/simplifier/SKILL.md +34 -34
- package/skills/simplifier/agents/openai.yaml +2 -2
- package/skills/simplifier-audit/SKILL.md +28 -28
- package/skills/simplifier-audit/agents/openai.yaml +2 -2
- package/skills/simplifier-review/SKILL.md +36 -29
- package/skills/verify-before-done/SKILL.md +29 -29
- package/skills/writing-skills/SKILL.md +68 -68
package/cli/index.test.mjs
CHANGED
|
@@ -1,300 +1,574 @@
|
|
|
1
|
-
import assert from 'node:assert/strict'
|
|
2
|
-
import fs from 'node:fs'
|
|
3
|
-
import os from 'node:os'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import test, { after } from 'node:test'
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
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
|
-
scope
|
|
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
|
-
assert.
|
|
134
|
-
assert.equal(
|
|
135
|
-
assert.equal(
|
|
136
|
-
assert.equal(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
const
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
fs.
|
|
185
|
-
fs.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
)
|
|
262
|
-
assert.
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import os from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import test, { after } from 'node:test'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import {
|
|
8
|
+
buildManagedHookCommand,
|
|
9
|
+
buildPlan,
|
|
10
|
+
executeInstall,
|
|
11
|
+
hookConfigPath,
|
|
12
|
+
INSTALL_MANIFEST,
|
|
13
|
+
PACKAGE_NAME,
|
|
14
|
+
parseArgs,
|
|
15
|
+
planManagedHookConfig,
|
|
16
|
+
planPolicyUpdate,
|
|
17
|
+
resolveOptions,
|
|
18
|
+
run,
|
|
19
|
+
targetSkillRoot,
|
|
20
|
+
VERSION
|
|
21
|
+
} from './index.mjs'
|
|
22
|
+
|
|
23
|
+
const temporaryRoots = []
|
|
24
|
+
|
|
25
|
+
function temporaryRoot() {
|
|
26
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-cli-'))
|
|
27
|
+
temporaryRoots.push(root)
|
|
28
|
+
return root
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function silentOutput() {
|
|
32
|
+
return { write() {} }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function packageRootForTest() {
|
|
36
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
after(() => {
|
|
40
|
+
for (const root of temporaryRoots) fs.rmSync(root, { recursive: true, force: true })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('defaults to guided direct install', () => {
|
|
44
|
+
assert.deepEqual(parseArgs([]), {
|
|
45
|
+
command: 'install',
|
|
46
|
+
platform: null,
|
|
47
|
+
method: null,
|
|
48
|
+
scope: null,
|
|
49
|
+
policy: null,
|
|
50
|
+
yes: false,
|
|
51
|
+
dryRun: false,
|
|
52
|
+
help: false,
|
|
53
|
+
version: false
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('parses non-interactive direct update flags', () => {
|
|
58
|
+
assert.deepEqual(parseArgs([
|
|
59
|
+
'update',
|
|
60
|
+
'--platform=both',
|
|
61
|
+
'--method',
|
|
62
|
+
'direct',
|
|
63
|
+
'--scope',
|
|
64
|
+
'project',
|
|
65
|
+
'--no-policy',
|
|
66
|
+
'--yes'
|
|
67
|
+
]), {
|
|
68
|
+
command: 'update',
|
|
69
|
+
platform: 'both',
|
|
70
|
+
method: 'direct',
|
|
71
|
+
scope: 'project',
|
|
72
|
+
policy: false,
|
|
73
|
+
yes: true,
|
|
74
|
+
dryRun: false,
|
|
75
|
+
help: false,
|
|
76
|
+
version: false
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('supports Claude Code as a platform alias and upgrade as update', () => {
|
|
81
|
+
assert.deepEqual(parseArgs(['upgrade', '--platform', 'claude-code', '--yes']), {
|
|
82
|
+
command: 'update',
|
|
83
|
+
platform: 'claude',
|
|
84
|
+
method: null,
|
|
85
|
+
scope: null,
|
|
86
|
+
policy: null,
|
|
87
|
+
yes: true,
|
|
88
|
+
dryRun: false,
|
|
89
|
+
help: false,
|
|
90
|
+
version: false
|
|
91
|
+
})
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('prints scoped npm commands and explains the direct default', async () => {
|
|
95
|
+
const chunks = []
|
|
96
|
+
await run(['--help'], { output: { write: (chunk) => chunks.push(chunk) } })
|
|
97
|
+
const help = chunks.join('')
|
|
98
|
+
assert.match(help, /npx @sockulags\/agent-os install/)
|
|
99
|
+
assert.match(help, /does not require Codex or Claude Code CLI/)
|
|
100
|
+
assert.match(help, /--method <name>\s+direct \(default\) or plugin/)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
test('rejects conflicting policy flags and direct local scope', async () => {
|
|
104
|
+
assert.throws(() => parseArgs(['install', '--policy', '--no-policy']), /one of --policy and --no-policy/)
|
|
105
|
+
await assert.rejects(
|
|
106
|
+
resolveOptions(parseArgs([
|
|
107
|
+
'install', '--platform', 'codex', '--method', 'direct', '--scope', 'local', '--yes'
|
|
108
|
+
]), { input: { isTTY: false }, output: { isTTY: false } }),
|
|
109
|
+
/Local scope is available only with --method plugin/
|
|
110
|
+
)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('requires explicit non-interactive choices', async () => {
|
|
114
|
+
await assert.rejects(
|
|
115
|
+
resolveOptions(parseArgs(['install']), {
|
|
116
|
+
input: { isTTY: false },
|
|
117
|
+
output: { isTTY: false }
|
|
118
|
+
}),
|
|
119
|
+
/--yes with explicit options/
|
|
120
|
+
)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('builds direct filesystem plans without marketplace commands', () => {
|
|
124
|
+
const root = temporaryRoot()
|
|
125
|
+
const plan = buildPlan({
|
|
126
|
+
command: 'install',
|
|
127
|
+
platform: 'both',
|
|
128
|
+
method: 'direct',
|
|
129
|
+
scope: 'user',
|
|
130
|
+
policy: false
|
|
131
|
+
}, { homeDir: root, cwd: root })
|
|
132
|
+
assert.deepEqual(plan.map((step) => step.kind), ['install-skills', 'install-hooks', 'install-skills', 'install-hooks'])
|
|
133
|
+
assert.deepEqual(plan.map((step) => step.command), ['filesystem', 'filesystem', 'filesystem', 'filesystem'])
|
|
134
|
+
assert.equal(plan[0].args[0], path.join(root, '.claude', 'skills'))
|
|
135
|
+
assert.equal(plan[1].args[0], path.join(root, '.claude', 'settings.json'))
|
|
136
|
+
assert.equal(plan[2].args[0], path.join(root, '.codex', 'skills'))
|
|
137
|
+
assert.equal(plan[3].args[0], path.join(root, '.codex', 'hooks.json'))
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('maps project and user targets for both hosts', () => {
|
|
141
|
+
const root = temporaryRoot()
|
|
142
|
+
const project = path.join(root, 'project')
|
|
143
|
+
assert.equal(targetSkillRoot('codex', 'user', { homeDir: root, cwd: project }), path.join(root, '.codex', 'skills'))
|
|
144
|
+
assert.equal(targetSkillRoot('claude', 'user', { homeDir: root, cwd: project }), path.join(root, '.claude', 'skills'))
|
|
145
|
+
assert.equal(targetSkillRoot('codex', 'project', { homeDir: root, cwd: project }), path.join(project, '.agents', 'skills'))
|
|
146
|
+
assert.equal(targetSkillRoot('claude', 'project', { homeDir: root, cwd: project }), path.join(project, '.claude', 'skills'))
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test('installs both hosts and policy without either host CLI', async () => {
|
|
150
|
+
const root = temporaryRoot()
|
|
151
|
+
const homeDir = path.join(root, 'home')
|
|
152
|
+
const cwd = path.join(root, 'project')
|
|
153
|
+
await executeInstall({
|
|
154
|
+
command: 'install',
|
|
155
|
+
platform: 'both',
|
|
156
|
+
method: 'direct',
|
|
157
|
+
scope: 'user',
|
|
158
|
+
policy: true
|
|
159
|
+
}, {
|
|
160
|
+
output: silentOutput(),
|
|
161
|
+
homeDir,
|
|
162
|
+
cwd,
|
|
163
|
+
exists: () => { throw new Error('host CLI lookup must not run') },
|
|
164
|
+
execute: () => { throw new Error('external command must not run') }
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
for (const agent of ['.claude', '.codex']) {
|
|
168
|
+
const skillsRoot = path.join(homeDir, agent, 'skills')
|
|
169
|
+
assert.equal(fs.existsSync(path.join(skillsRoot, 'shape-work', 'SKILL.md')), true)
|
|
170
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(skillsRoot, INSTALL_MANIFEST), 'utf8'))
|
|
171
|
+
assert.equal(manifest.package, PACKAGE_NAME)
|
|
172
|
+
assert.equal(manifest.version, VERSION)
|
|
173
|
+
assert.equal(manifest.schemaVersion, 2)
|
|
174
|
+
assert.ok(manifest.skills.includes('shape-work'))
|
|
175
|
+
assert.equal(manifest.integrations.hooks.event, 'Stop')
|
|
176
|
+
const hookFile = path.join(homeDir, agent, agent === '.claude' ? 'settings.json' : 'hooks.json')
|
|
177
|
+
assert.equal(fs.existsSync(hookFile), true)
|
|
178
|
+
const hookConfig = JSON.parse(fs.readFileSync(hookFile, 'utf8'))
|
|
179
|
+
const command = hookConfig.hooks.Stop.find((group) =>
|
|
180
|
+
JSON.stringify(group).includes('--agent-os-hook=quality-ratchet')).hooks[0].command
|
|
181
|
+
assert.equal(command.includes(path.join(skillsRoot, 'quality-ratchet', 'scripts', 'quality-delta.mjs')), true)
|
|
182
|
+
assert.equal(command.includes(packageRootForTest()), false)
|
|
183
|
+
}
|
|
184
|
+
assert.match(fs.readFileSync(path.join(homeDir, '.claude', 'CLAUDE.md'), 'utf8'), /BEGIN AGENT OS/)
|
|
185
|
+
assert.match(fs.readFileSync(path.join(homeDir, '.codex', 'AGENTS.md'), 'utf8'), /BEGIN AGENT OS/)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test('maps direct hook configuration paths for user and project scopes', () => {
|
|
189
|
+
const root = temporaryRoot()
|
|
190
|
+
const project = path.join(root, 'project')
|
|
191
|
+
assert.equal(hookConfigPath('claude', 'user', { homeDir: root, cwd: project }), path.join(root, '.claude', 'settings.json'))
|
|
192
|
+
assert.equal(hookConfigPath('codex', 'user', { homeDir: root, cwd: project }), path.join(root, '.codex', 'hooks.json'))
|
|
193
|
+
assert.equal(hookConfigPath('claude', 'project', { homeDir: root, cwd: project }), path.join(project, '.claude', 'settings.json'))
|
|
194
|
+
assert.equal(hookConfigPath('codex', 'project', { homeDir: root, cwd: project }), path.join(project, '.codex', 'hooks.json'))
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('direct project install configures both hosts without replacing unrelated hooks', async () => {
|
|
198
|
+
const root = temporaryRoot()
|
|
199
|
+
const project = path.join(root, 'project')
|
|
200
|
+
const claudeConfig = path.join(project, '.claude', 'settings.json')
|
|
201
|
+
const codexConfig = path.join(project, '.codex', 'hooks.json')
|
|
202
|
+
fs.mkdirSync(path.dirname(claudeConfig), { recursive: true })
|
|
203
|
+
fs.mkdirSync(path.dirname(codexConfig), { recursive: true })
|
|
204
|
+
const unrelated = {
|
|
205
|
+
permissions: { allow: ['Read'] },
|
|
206
|
+
hooks: {
|
|
207
|
+
PreToolUse: [{ hooks: [{ type: 'command', command: 'developer-preflight' }] }],
|
|
208
|
+
Stop: [{ hooks: [{ type: 'command', command: 'developer-stop' }] }]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
fs.writeFileSync(claudeConfig, JSON.stringify(unrelated, null, 2) + '\n')
|
|
212
|
+
fs.writeFileSync(codexConfig, JSON.stringify(unrelated, null, 2) + '\n')
|
|
213
|
+
await executeInstall({
|
|
214
|
+
command: 'install', platform: 'both', method: 'direct', scope: 'project', policy: false
|
|
215
|
+
}, { output: silentOutput(), homeDir: root, cwd: project })
|
|
216
|
+
|
|
217
|
+
for (const [file, skillsRoot] of [
|
|
218
|
+
[claudeConfig, path.join(project, '.claude', 'skills')],
|
|
219
|
+
[codexConfig, path.join(project, '.agents', 'skills')]
|
|
220
|
+
]) {
|
|
221
|
+
const config = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
222
|
+
assert.deepEqual(config.permissions, unrelated.permissions)
|
|
223
|
+
assert.deepEqual(config.hooks.PreToolUse, unrelated.hooks.PreToolUse)
|
|
224
|
+
assert.deepEqual(config.hooks.Stop[0], unrelated.hooks.Stop[0])
|
|
225
|
+
assert.equal(config.hooks.Stop.filter((group) => JSON.stringify(group).includes('--agent-os-hook=quality-ratchet')).length, 1)
|
|
226
|
+
const command = config.hooks.Stop.find((group) =>
|
|
227
|
+
JSON.stringify(group).includes('--agent-os-hook=quality-ratchet')).hooks[0].command
|
|
228
|
+
assert.equal(command.includes(path.join(skillsRoot, 'quality-ratchet', 'scripts', 'quality-delta.mjs')), true)
|
|
229
|
+
assert.equal(command.includes(packageRootForTest()), false)
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test('managed hook updates replace only the exact Agent OS entry', () => {
|
|
234
|
+
const durableScript = path.join(temporaryRoot(), '.codex', 'skills', 'quality-ratchet', 'scripts', 'quality-delta.mjs')
|
|
235
|
+
const managedCommand = buildManagedHookCommand(durableScript)
|
|
236
|
+
const oldCommand = '"old-node" "old-quality-delta.mjs" hook --agent-os-hook=quality-ratchet'
|
|
237
|
+
const original = JSON.stringify({
|
|
238
|
+
unrelated: true,
|
|
239
|
+
hooks: {
|
|
240
|
+
Stop: [
|
|
241
|
+
{ hooks: [{ type: 'command', command: 'keep-me' }] },
|
|
242
|
+
{ hooks: [{ type: 'command', command: oldCommand, timeout: 1 }] }
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
}, null, 2) + '\n'
|
|
246
|
+
const planned = planManagedHookConfig(original, managedCommand, 'test hooks.json')
|
|
247
|
+
assert.equal(planned.status, 'UPDATED')
|
|
248
|
+
const config = JSON.parse(planned.content)
|
|
249
|
+
assert.equal(config.unrelated, true)
|
|
250
|
+
assert.equal(config.hooks.Stop[0].hooks[0].command, 'keep-me')
|
|
251
|
+
assert.equal(config.hooks.Stop[1].hooks[0].command, managedCommand)
|
|
252
|
+
assert.equal(config.hooks.Stop[1].hooks[0].timeout, 10)
|
|
253
|
+
assert.equal(config.hooks.Stop[1].hooks[0].command.includes(durableScript), true)
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test('malformed or ambiguous managed hook config aborts before direct skill mutation', async () => {
|
|
257
|
+
const root = temporaryRoot()
|
|
258
|
+
const homeDir = path.join(root, 'home')
|
|
259
|
+
const hookFile = path.join(homeDir, '.codex', 'hooks.json')
|
|
260
|
+
fs.mkdirSync(path.dirname(hookFile), { recursive: true })
|
|
261
|
+
fs.writeFileSync(hookFile, '{ malformed')
|
|
262
|
+
await assert.rejects(
|
|
263
|
+
executeInstall({ command: 'install', platform: 'codex', method: 'direct', scope: 'user', policy: false }, {
|
|
264
|
+
output: silentOutput(), homeDir, cwd: root
|
|
265
|
+
}),
|
|
266
|
+
/Cannot read.*hooks.json.*no files were changed/
|
|
267
|
+
)
|
|
268
|
+
assert.equal(fs.existsSync(path.join(homeDir, '.codex', 'skills')), false)
|
|
269
|
+
|
|
270
|
+
fs.writeFileSync(hookFile, JSON.stringify({ hooks: { Stop: [
|
|
271
|
+
{ hooks: [{ type: 'command', command: 'one --agent-os-hook=quality-ratchet' }] },
|
|
272
|
+
{ hooks: [{ type: 'command', command: 'two --agent-os-hook=quality-ratchet' }] }
|
|
273
|
+
] } }))
|
|
274
|
+
await assert.rejects(
|
|
275
|
+
executeInstall({ command: 'install', platform: 'codex', method: 'direct', scope: 'user', policy: false }, {
|
|
276
|
+
output: silentOutput(), homeDir, cwd: root
|
|
277
|
+
}),
|
|
278
|
+
/multiple Agent OS hook entries.*no files were changed/
|
|
279
|
+
)
|
|
280
|
+
assert.equal(fs.existsSync(path.join(homeDir, '.codex', 'skills')), false)
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
test('hook write failure restores both direct skill installs and preserves host configs byte-for-byte', async () => {
|
|
284
|
+
const root = temporaryRoot()
|
|
285
|
+
const homeDir = path.join(root, 'home')
|
|
286
|
+
const claudeConfig = path.join(homeDir, '.claude', 'settings.json')
|
|
287
|
+
const codexConfig = path.join(homeDir, '.codex', 'hooks.json')
|
|
288
|
+
const claudeText = '{\n "theme": "dark",\n "hooks": { "Stop": [] }\n}\n'
|
|
289
|
+
const codexText = '{\n "custom": true,\n "hooks": { "Stop": [] }\n}\n'
|
|
290
|
+
for (const [file, content] of [[claudeConfig, claudeText], [codexConfig, codexText]]) {
|
|
291
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
292
|
+
fs.writeFileSync(file, content)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const skillRoots = [
|
|
296
|
+
path.join(homeDir, '.claude', 'skills'),
|
|
297
|
+
path.join(homeDir, '.codex', 'skills')
|
|
298
|
+
]
|
|
299
|
+
for (const skillsRoot of skillRoots) {
|
|
300
|
+
const privateFile = path.join(skillsRoot, 'private-skill', 'SKILL.md')
|
|
301
|
+
fs.mkdirSync(path.dirname(privateFile), { recursive: true })
|
|
302
|
+
fs.writeFileSync(privateFile, 'developer-owned\n')
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const failingFs = Object.create(fs)
|
|
306
|
+
let injected = false
|
|
307
|
+
failingFs.writeFileSync = (target, ...args) => {
|
|
308
|
+
const isCodexHookTemporary = path.dirname(target) === path.dirname(codexConfig) &&
|
|
309
|
+
path.basename(target).startsWith('.hooks.json.agent-os-')
|
|
310
|
+
if (!injected && isCodexHookTemporary) {
|
|
311
|
+
injected = true
|
|
312
|
+
throw new Error('injected hook write failure')
|
|
313
|
+
}
|
|
314
|
+
return fs.writeFileSync(target, ...args)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
await assert.rejects(
|
|
318
|
+
executeInstall({ command: 'install', platform: 'both', method: 'direct', scope: 'user', policy: false }, {
|
|
319
|
+
output: silentOutput(), homeDir, cwd: root, fsImpl: failingFs
|
|
320
|
+
}),
|
|
321
|
+
/injected hook write failure/
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
assert.equal(injected, true)
|
|
325
|
+
assert.equal(fs.readFileSync(claudeConfig, 'utf8'), claudeText)
|
|
326
|
+
assert.equal(fs.readFileSync(codexConfig, 'utf8'), codexText)
|
|
327
|
+
for (const skillsRoot of skillRoots) {
|
|
328
|
+
assert.equal(fs.readFileSync(path.join(skillsRoot, 'private-skill', 'SKILL.md'), 'utf8'), 'developer-owned\n')
|
|
329
|
+
assert.equal(fs.existsSync(path.join(skillsRoot, INSTALL_MANIFEST)), false)
|
|
330
|
+
assert.equal(fs.existsSync(path.join(skillsRoot, 'shape-work')), false)
|
|
331
|
+
assert.equal(fs.existsSync(path.join(skillsRoot, 'quality-ratchet')), false)
|
|
332
|
+
assert.deepEqual(fs.readdirSync(skillsRoot).filter((name) => name.startsWith('.agent-os-transaction-')), [])
|
|
333
|
+
}
|
|
334
|
+
for (const file of [claudeConfig, codexConfig]) {
|
|
335
|
+
assert.deepEqual(fs.readdirSync(path.dirname(file)).filter((name) => name.endsWith('.tmp')), [])
|
|
336
|
+
}
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
test('post-commit backup cleanup failure never rolls back installed skills or hooks', async () => {
|
|
340
|
+
const root = temporaryRoot()
|
|
341
|
+
const homeDir = path.join(root, 'home')
|
|
342
|
+
const options = {
|
|
343
|
+
command: 'install', platform: 'both', method: 'direct', scope: 'user', policy: false
|
|
344
|
+
}
|
|
345
|
+
await executeInstall(options, { output: silentOutput(), homeDir, cwd: root })
|
|
346
|
+
|
|
347
|
+
const skillRoots = [
|
|
348
|
+
path.join(homeDir, '.claude', 'skills'),
|
|
349
|
+
path.join(homeDir, '.codex', 'skills')
|
|
350
|
+
]
|
|
351
|
+
const failingFs = Object.create(fs)
|
|
352
|
+
let firstBackupRemoved = false
|
|
353
|
+
let injected = false
|
|
354
|
+
let rollbackAttempted = false
|
|
355
|
+
failingFs.rmSync = (target, rmOptions) => {
|
|
356
|
+
const isTransactionBackup = path.basename(target).startsWith('.agent-os-transaction-')
|
|
357
|
+
if (isTransactionBackup && path.dirname(target) === skillRoots[0]) {
|
|
358
|
+
firstBackupRemoved = true
|
|
359
|
+
} else if (!injected && firstBackupRemoved && isTransactionBackup &&
|
|
360
|
+
path.dirname(target) === skillRoots[1]) {
|
|
361
|
+
injected = true
|
|
362
|
+
throw new Error('injected post-commit cleanup failure')
|
|
363
|
+
} else if (injected && skillRoots.some((skillsRoot) => path.dirname(target) === skillsRoot)) {
|
|
364
|
+
rollbackAttempted = true
|
|
365
|
+
}
|
|
366
|
+
return fs.rmSync(target, rmOptions)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
await assert.rejects(
|
|
370
|
+
executeInstall({ ...options, command: 'update' }, {
|
|
371
|
+
output: silentOutput(), homeDir, cwd: root, fsImpl: failingFs
|
|
372
|
+
}),
|
|
373
|
+
/direct install committed, but failed to clean transaction backups: injected post-commit cleanup failure.*not rolled back/
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
assert.equal(firstBackupRemoved, true)
|
|
377
|
+
assert.equal(injected, true)
|
|
378
|
+
assert.equal(rollbackAttempted, false)
|
|
379
|
+
for (const [index, skillsRoot] of skillRoots.entries()) {
|
|
380
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(skillsRoot, INSTALL_MANIFEST), 'utf8'))
|
|
381
|
+
assert.equal(manifest.schemaVersion, 2)
|
|
382
|
+
assert.equal(manifest.skills.includes('quality-ratchet'), true)
|
|
383
|
+
for (const name of manifest.skills) assert.equal(fs.existsSync(path.join(skillsRoot, name)), true)
|
|
384
|
+
|
|
385
|
+
const hookFile = index === 0
|
|
386
|
+
? path.join(homeDir, '.claude', 'settings.json')
|
|
387
|
+
: path.join(homeDir, '.codex', 'hooks.json')
|
|
388
|
+
const hookConfig = JSON.parse(fs.readFileSync(hookFile, 'utf8'))
|
|
389
|
+
const managedHooks = hookConfig.hooks.Stop.filter((group) =>
|
|
390
|
+
JSON.stringify(group).includes('--agent-os-hook=quality-ratchet'))
|
|
391
|
+
assert.equal(managedHooks.length, 1)
|
|
392
|
+
assert.equal(managedHooks[0].hooks[0].command.includes(
|
|
393
|
+
path.join(skillsRoot, 'quality-ratchet', 'scripts', 'quality-delta.mjs')), true)
|
|
394
|
+
}
|
|
395
|
+
assert.deepEqual(fs.readdirSync(skillRoots[0]).filter((name) =>
|
|
396
|
+
name.startsWith('.agent-os-transaction-')), [])
|
|
397
|
+
assert.equal(fs.readdirSync(skillRoots[1]).filter((name) =>
|
|
398
|
+
name.startsWith('.agent-os-transaction-')).length, 1)
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
test('upgrades a schema 1 direct manifest while retaining managed integration state', async () => {
|
|
402
|
+
const root = temporaryRoot()
|
|
403
|
+
const homeDir = path.join(root, 'home')
|
|
404
|
+
const options = { command: 'install', platform: 'codex', method: 'direct', scope: 'user', policy: false }
|
|
405
|
+
await executeInstall(options, { output: silentOutput(), homeDir, cwd: root })
|
|
406
|
+
const skillsRoot = path.join(homeDir, '.codex', 'skills')
|
|
407
|
+
const manifestPath = path.join(skillsRoot, INSTALL_MANIFEST)
|
|
408
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
|
|
409
|
+
delete manifest.integrations
|
|
410
|
+
manifest.schemaVersion = 1
|
|
411
|
+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n')
|
|
412
|
+
await executeInstall({ ...options, command: 'update' }, { output: silentOutput(), homeDir, cwd: root })
|
|
413
|
+
const upgraded = JSON.parse(fs.readFileSync(manifestPath, 'utf8'))
|
|
414
|
+
assert.equal(upgraded.schemaVersion, 2)
|
|
415
|
+
assert.equal(upgraded.integrations.hooks.marker, '--agent-os-hook=quality-ratchet')
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
test('packaged hook asset and direct command use the stable runner marker', () => {
|
|
419
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(packageRootForTest(), 'package.json'), 'utf8'))
|
|
420
|
+
const hooks = JSON.parse(fs.readFileSync(path.join(packageRootForTest(), 'hooks', 'hooks.json'), 'utf8'))
|
|
421
|
+
const durableScript = path.join(temporaryRoot(), '.claude', 'skills', 'quality-ratchet', 'scripts', 'quality-delta.mjs')
|
|
422
|
+
const command = buildManagedHookCommand(durableScript)
|
|
423
|
+
const nativeHook = hooks.hooks.Stop[0].hooks[0]
|
|
424
|
+
assert.ok(packageJson.files.includes('hooks/'))
|
|
425
|
+
assert.equal(hooks.description.includes('quality-ratchet'), true)
|
|
426
|
+
assert.match(nativeHook.command, /\$\{CLAUDE_PLUGIN_ROOT\}/)
|
|
427
|
+
assert.equal(typeof nativeHook.commandWindows, 'string')
|
|
428
|
+
assert.equal(nativeHook.commandWindows.includes('"'), false)
|
|
429
|
+
const windowsMatch =
|
|
430
|
+
/^powershell\.exe -NoProfile -NonInteractive -EncodedCommand ([A-Za-z0-9+/]+={0,2})$/.exec(
|
|
431
|
+
nativeHook.commandWindows
|
|
432
|
+
)
|
|
433
|
+
assert.ok(windowsMatch)
|
|
434
|
+
const decodedWindowsCommand = Buffer.from(windowsMatch[1], 'base64').toString('utf16le')
|
|
435
|
+
assert.equal(decodedWindowsCommand,
|
|
436
|
+
"$runner = Join-Path $env:PLUGIN_ROOT 'skills\\quality-ratchet\\scripts\\quality-delta.mjs'; " +
|
|
437
|
+
'node $runner hook --agent-os-hook=quality-ratchet')
|
|
438
|
+
assert.equal(command.startsWith('"' + process.execPath + '"'), true)
|
|
439
|
+
assert.equal(path.isAbsolute(durableScript), true)
|
|
440
|
+
assert.match(command, /--agent-os-hook=quality-ratchet/)
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
test('updates only managed skills and preserves unrelated skills', async () => {
|
|
444
|
+
const root = temporaryRoot()
|
|
445
|
+
const homeDir = path.join(root, 'home')
|
|
446
|
+
const options = {
|
|
447
|
+
command: 'install',
|
|
448
|
+
platform: 'codex',
|
|
449
|
+
method: 'direct',
|
|
450
|
+
scope: 'user',
|
|
451
|
+
policy: false
|
|
452
|
+
}
|
|
453
|
+
await executeInstall(options, { output: silentOutput(), homeDir, cwd: root })
|
|
454
|
+
|
|
455
|
+
const skillsRoot = path.join(homeDir, '.codex', 'skills')
|
|
456
|
+
const managedFile = path.join(skillsRoot, 'shape-work', 'SKILL.md')
|
|
457
|
+
const foreignFile = path.join(skillsRoot, 'my-private-skill', 'SKILL.md')
|
|
458
|
+
fs.writeFileSync(managedFile, 'stale managed content\n')
|
|
459
|
+
fs.mkdirSync(path.dirname(foreignFile), { recursive: true })
|
|
460
|
+
fs.writeFileSync(foreignFile, 'private content\n')
|
|
461
|
+
|
|
462
|
+
await executeInstall({ ...options, command: 'update' }, { output: silentOutput(), homeDir, cwd: root })
|
|
463
|
+
assert.notEqual(fs.readFileSync(managedFile, 'utf8'), 'stale managed content\n')
|
|
464
|
+
assert.equal(fs.readFileSync(foreignFile, 'utf8'), 'private content\n')
|
|
465
|
+
})
|
|
466
|
+
|
|
467
|
+
test('refuses to overwrite a same-name skill without an Agent OS manifest', async () => {
|
|
468
|
+
const root = temporaryRoot()
|
|
469
|
+
const homeDir = path.join(root, 'home')
|
|
470
|
+
const collision = path.join(homeDir, '.codex', 'skills', 'shape-work', 'SKILL.md')
|
|
471
|
+
fs.mkdirSync(path.dirname(collision), { recursive: true })
|
|
472
|
+
fs.writeFileSync(collision, 'developer-owned\n')
|
|
473
|
+
|
|
474
|
+
await assert.rejects(
|
|
475
|
+
executeInstall({
|
|
476
|
+
command: 'install',
|
|
477
|
+
platform: 'codex',
|
|
478
|
+
method: 'direct',
|
|
479
|
+
scope: 'user',
|
|
480
|
+
policy: false
|
|
481
|
+
}, { output: silentOutput(), homeDir, cwd: root }),
|
|
482
|
+
/Refusing to overwrite unmanaged skills.*shape-work/
|
|
483
|
+
)
|
|
484
|
+
assert.equal(fs.readFileSync(collision, 'utf8'), 'developer-owned\n')
|
|
485
|
+
assert.equal(fs.existsSync(path.join(homeDir, '.codex', 'skills', INSTALL_MANIFEST)), false)
|
|
486
|
+
})
|
|
487
|
+
|
|
488
|
+
test('policy planning preserves surrounding text and rejects malformed markers', () => {
|
|
489
|
+
const policy = '# Policy\n'
|
|
490
|
+
const original = 'before\n\n<!-- BEGIN AGENT OS -->\nold\n<!-- END AGENT OS -->\nafter\n'
|
|
491
|
+
const updated = planPolicyUpdate(original, policy)
|
|
492
|
+
assert.equal(updated.status, 'UPDATED')
|
|
493
|
+
assert.equal(updated.content, 'before\n\n<!-- BEGIN AGENT OS -->\n# Policy\n<!-- END AGENT OS -->\nafter\n')
|
|
494
|
+
assert.throws(
|
|
495
|
+
() => planPolicyUpdate('<!-- BEGIN AGENT OS -->\nbroken\n', policy),
|
|
496
|
+
/Malformed Agent OS policy markers/
|
|
497
|
+
)
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
test('malformed policy markers abort before direct skill installation', async () => {
|
|
501
|
+
const root = temporaryRoot()
|
|
502
|
+
const homeDir = path.join(root, 'home')
|
|
503
|
+
const target = path.join(homeDir, '.codex', 'AGENTS.md')
|
|
504
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
505
|
+
fs.writeFileSync(target, '<!-- BEGIN AGENT OS -->\nbroken\n')
|
|
506
|
+
|
|
507
|
+
await assert.rejects(
|
|
508
|
+
executeInstall({
|
|
509
|
+
command: 'install',
|
|
510
|
+
platform: 'codex',
|
|
511
|
+
method: 'direct',
|
|
512
|
+
scope: 'user',
|
|
513
|
+
policy: true
|
|
514
|
+
}, { output: silentOutput(), homeDir, cwd: root }),
|
|
515
|
+
/Malformed Agent OS policy markers/
|
|
516
|
+
)
|
|
517
|
+
assert.equal(fs.existsSync(path.join(homeDir, '.codex', 'skills')), false)
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
test('plugin mode still requires only the selected host CLI', async () => {
|
|
521
|
+
const calls = []
|
|
522
|
+
await assert.rejects(
|
|
523
|
+
executeInstall({
|
|
524
|
+
command: 'install',
|
|
525
|
+
platform: 'codex',
|
|
526
|
+
method: 'plugin',
|
|
527
|
+
scope: 'user',
|
|
528
|
+
policy: false
|
|
529
|
+
}, {
|
|
530
|
+
output: silentOutput(),
|
|
531
|
+
exists: () => false,
|
|
532
|
+
execute: (...args) => calls.push(args)
|
|
533
|
+
}),
|
|
534
|
+
/Native plugin mode requires the selected host CLIs.*Codex/s
|
|
535
|
+
)
|
|
536
|
+
assert.deepEqual(calls, [])
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
test('plugin update skips Git refresh for a registered local Codex marketplace', async () => {
|
|
540
|
+
const calls = []
|
|
541
|
+
await executeInstall({
|
|
542
|
+
command: 'update',
|
|
543
|
+
platform: 'codex',
|
|
544
|
+
method: 'plugin',
|
|
545
|
+
scope: 'user',
|
|
546
|
+
policy: false
|
|
547
|
+
}, {
|
|
548
|
+
output: silentOutput(),
|
|
549
|
+
exists: () => true,
|
|
550
|
+
execute: (command, args) => {
|
|
551
|
+
calls.push([command, args])
|
|
552
|
+
if (args.join(' ') === 'plugin marketplace list --json') {
|
|
553
|
+
return { status: 0, stdout: JSON.stringify({ marketplaces: [{ name: 'agent-os' }] }), stderr: '' }
|
|
554
|
+
}
|
|
555
|
+
if (args.join(' ') === 'plugin list --json') {
|
|
556
|
+
return {
|
|
557
|
+
status: 0,
|
|
558
|
+
stdout: JSON.stringify({ installed: [{
|
|
559
|
+
marketplaceName: 'agent-os',
|
|
560
|
+
marketplaceSource: { sourceType: 'local' }
|
|
561
|
+
}] }),
|
|
562
|
+
stderr: ''
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return { status: 0, stdout: '', stderr: '' }
|
|
566
|
+
}
|
|
567
|
+
})
|
|
568
|
+
|
|
569
|
+
assert.deepEqual(calls.map((call) => call[1]), [
|
|
570
|
+
['plugin', 'marketplace', 'list', '--json'],
|
|
571
|
+
['plugin', 'list', '--json'],
|
|
572
|
+
['plugin', 'add', 'agent-os@agent-os']
|
|
573
|
+
])
|
|
574
|
+
})
|