@sockulags/agent-os 0.15.0 → 0.17.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 +105 -59
- package/cli/doctor.mjs +351 -0
- package/cli/index.mjs +328 -151
- package/cli/index.test.mjs +436 -9
- package/package.json +5 -6
- package/plugins/agent-os-core/.claude-plugin/plugin.json +18 -0
- package/plugins/agent-os-core/.codex-plugin/plugin.json +24 -0
- package/plugins/agent-os-core/skills/capture-intent/SKILL.md +68 -0
- package/plugins/agent-os-core/skills/capture-intent/references/intent-template.md +47 -0
- package/plugins/agent-os-core/skills/explain-work/SKILL.md +42 -0
- package/{skills → plugins/agent-os-core/skills}/list-skills/SKILL.md +16 -7
- package/{skills → plugins/agent-os-core/skills}/plain-voice/SKILL.md +7 -4
- package/plugins/agent-os-core/skills/plan-work/SKILL.md +151 -0
- package/{skills → plugins/agent-os-core/skills}/plan-work/references/elicitation.md +7 -3
- package/plugins/agent-os-core/skills/plan-work/references/spec-template.md +65 -0
- package/plugins/agent-os-core/skills/record-lesson/SKILL.md +47 -0
- package/{skills → plugins/agent-os-core/skills}/scope-guard/SKILL.md +11 -6
- package/{skills → plugins/agent-os-core/skills}/verify-before-done/SKILL.md +6 -2
- package/plugins/agent-os-dev/.claude-plugin/plugin.json +18 -0
- package/plugins/agent-os-dev/.codex-plugin/plugin.json +24 -0
- package/plugins/agent-os-dev/hooks/hooks.json +42 -0
- package/{skills → plugins/agent-os-dev/skills}/batch-work/SKILL.md +6 -2
- package/{skills → plugins/agent-os-dev/skills}/check-work/SKILL.md +33 -14
- package/{skills/deliver-work/workflow.md → plugins/agent-os-dev/skills/deliver-work/SKILL.md} +126 -57
- package/plugins/agent-os-dev/skills/deliver-work/references/work-records.md +20 -0
- package/plugins/agent-os-dev/skills/design-work/SKILL.md +160 -0
- package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.mjs +233 -0
- package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.test.mjs +73 -0
- package/plugins/agent-os-dev/skills/diagnose-before-fix/SKILL.md +29 -0
- package/{skills → plugins/agent-os-dev/skills}/dispatch-next/SKILL.md +11 -3
- package/plugins/agent-os-dev/skills/init-agent-os/SKILL.md +131 -0
- package/plugins/agent-os-dev/skills/init-agent-os/policy.md +91 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/guards.md +40 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/repository-init.md +115 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/review-template.md +35 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/workflow-template.md +80 -0
- package/plugins/agent-os-dev/skills/init-agent-os/scripts/policy-block.mjs +187 -0
- package/plugins/agent-os-dev/skills/init-agent-os/templates/agent-review.yml +59 -0
- package/plugins/agent-os-dev/skills/init-agent-os/templates/lint-intents.yml +30 -0
- package/{skills → plugins/agent-os-dev/skills}/proportional-testing/SKILL.md +1 -1
- package/plugins/agent-os-dev/skills/quality-ratchet/SKILL.md +104 -0
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/project-controls.md +31 -3
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.mjs +145 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.test.mjs +158 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.mjs +372 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.test.mjs +138 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.mjs +322 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.test.mjs +177 -0
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.mjs +59 -8
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.test.mjs +134 -8
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.mjs +296 -22
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.test.mjs +114 -6
- package/plugins/agent-os-dev/skills/shape-work/SKILL.md +135 -0
- package/plugins/agent-os-dev/skills/shape-work/references/implementation-issues.md +163 -0
- package/{skills/plan-work → plugins/agent-os-dev/skills/shape-work}/references/prototypes.md +9 -10
- package/plugins/agent-os-dev/skills/simplify/SKILL.md +91 -0
- package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.mjs +166 -0
- package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.test.mjs +49 -0
- package/policy.md +57 -30
- package/hooks/hooks.json +0 -17
- package/skills/deliver-work/SKILL.md +0 -12
- package/skills/diagnose-before-fix/SKILL.md +0 -24
- package/skills/explain-work/SKILL.md +0 -28
- package/skills/init-agent-os/SKILL.md +0 -55
- package/skills/init-agent-os/references/repository-init.md +0 -75
- package/skills/init-agent-os/scripts/policy-block.ps1 +0 -87
- package/skills/notice-lesson/SKILL.md +0 -20
- package/skills/plan-work/SKILL.md +0 -100
- package/skills/quality-ratchet/SKILL.md +0 -72
- package/skills/record-lesson/SKILL.md +0 -31
- package/skills/shape-work/SKILL.md +0 -71
- package/skills/shape-work/references/implementation-issues.md +0 -90
- package/skills/shape-work/references/mockups.md +0 -23
- package/skills/simplifier/SKILL.md +0 -35
- package/skills/simplifier-audit/SKILL.md +0 -30
- package/skills/simplifier-review/SKILL.md +0 -40
- package/skills/understand-work/SKILL.md +0 -32
- package/skills/understand-work/agents/openai.yaml +0 -2
- package/skills/writing-skills/SKILL.md +0 -68
- package/skills/writing-skills/agents/openai.yaml +0 -2
- /package/{skills/batch-work → plugins/agent-os-core/skills/capture-intent}/agents/openai.yaml +0 -0
- /package/{skills/deliver-work → plugins/agent-os-core/skills/explain-work}/agents/openai.yaml +0 -0
- /package/{skills/dispatch-next → plugins/agent-os-core/skills/list-skills}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-core/skills}/plain-voice/references/tells.md +0 -0
- /package/{skills/explain-work → plugins/agent-os-core/skills/plan-work}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-core/skills}/plan-work/references/map.md +0 -0
- /package/{skills/init-agent-os → plugins/agent-os-dev/skills/batch-work}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/references/manifest.md +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/manifest-hash.mjs +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/test-manifest-hash.mjs +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/check-work/references/findings.md +0 -0
- /package/{skills/list-skills → plugins/agent-os-dev/skills/deliver-work}/agents/openai.yaml +0 -0
- /package/{skills/plan-work → plugins/agent-os-dev/skills/design-work}/agents/openai.yaml +0 -0
- /package/{skills/record-lesson → plugins/agent-os-dev/skills/dispatch-next}/agents/openai.yaml +0 -0
- /package/{skills/shape-work → plugins/agent-os-dev/skills/init-agent-os}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/proportional-testing/references/strategy.md +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/structure.md +0 -0
- /package/{skills/simplifier-audit → plugins/agent-os-dev/skills/shape-work}/agents/openai.yaml +0 -0
- /package/{skills/simplifier → plugins/agent-os-dev/skills/simplify}/agents/openai.yaml +0 -0
package/cli/index.mjs
CHANGED
|
@@ -10,7 +10,18 @@ import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
|
10
10
|
import {
|
|
11
11
|
HOOK_TIMEOUT_SECONDS,
|
|
12
12
|
QUALITY_HOOK_MARKER
|
|
13
|
-
} from '../skills/quality-ratchet/scripts/quality-delta.mjs'
|
|
13
|
+
} from '../plugins/agent-os-dev/skills/quality-ratchet/scripts/quality-delta.mjs'
|
|
14
|
+
import { GUARDS_HOOK_MARKER } from '../plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.mjs'
|
|
15
|
+
import { lintIntents } from '../plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.mjs'
|
|
16
|
+
import {
|
|
17
|
+
composePolicy,
|
|
18
|
+
planPolicyUpdate,
|
|
19
|
+
policyBlockVersion,
|
|
20
|
+
policyTargets
|
|
21
|
+
} from '../plugins/agent-os-dev/skills/init-agent-os/scripts/policy-block.mjs'
|
|
22
|
+
import { collectDoctorReport, formatDoctorReport, latestPublishedVersion } from './doctor.mjs'
|
|
23
|
+
|
|
24
|
+
export { planPolicyUpdate, policyBlockVersion }
|
|
14
25
|
|
|
15
26
|
const packageRoot = fileURLToPath(new URL('../', import.meta.url))
|
|
16
27
|
const packagePath = path.join(packageRoot, 'package.json')
|
|
@@ -21,12 +32,38 @@ export const PACKAGE_NAME = packageJson.name
|
|
|
21
32
|
export const MARKETPLACE_SOURCE = 'sockulags/agent-os'
|
|
22
33
|
export const INSTALL_MANIFEST = '.agent-os-install.json'
|
|
23
34
|
export const QUALITY_HOOK_EVENT = 'Stop'
|
|
35
|
+
// Codex records hook trust against each hook's hash and skips new or changed hooks until trusted.
|
|
36
|
+
export const CODEX_HOOK_TRUST_NOTICE = 'Codex skips new or changed hooks until you trust them: open Codex, run /hooks, and trust the Agent OS quality-ratchet and guard hooks.'
|
|
24
37
|
|
|
25
|
-
const BEGIN_MARKER = '<!-- BEGIN AGENT OS -->'
|
|
26
|
-
const END_MARKER = '<!-- END AGENT OS -->'
|
|
27
38
|
const PLATFORM_VALUES = ['claude', 'codex', 'both']
|
|
28
39
|
const METHOD_VALUES = ['direct', 'plugin']
|
|
29
40
|
const SCOPE_VALUES = ['user', 'project', 'local']
|
|
41
|
+
const PACKAGE_VALUES = ['core', 'all']
|
|
42
|
+
|
|
43
|
+
// Each package is a plugin root in this repository; a direct install copies their skills side by side.
|
|
44
|
+
export const PACKAGES = Object.freeze({
|
|
45
|
+
core: Object.freeze({ plugin: 'agent-os-core', skills: path.join('plugins', 'agent-os-core', 'skills') }),
|
|
46
|
+
dev: Object.freeze({ plugin: 'agent-os-dev', skills: path.join('plugins', 'agent-os-dev', 'skills') })
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
export function selectedPackages(value = 'all') {
|
|
50
|
+
return value === 'core' ? ['core'] : ['core', 'dev']
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Managed hook entries, one per marker. The dev package owns all of them.
|
|
54
|
+
export const PRE_TOOL_USE_MATCHER = 'Edit|Write|MultiEdit|NotebookEdit|Bash|apply_patch|shell|exec_command|local_shell'
|
|
55
|
+
export function managedHookEntries(skillsRoot, nodePath = process.execPath) {
|
|
56
|
+
const scripts = path.join(skillsRoot, 'quality-ratchet', 'scripts')
|
|
57
|
+
const guards = buildManagedHookCommand(path.join(scripts, 'guards.mjs'), nodePath, GUARDS_HOOK_MARKER)
|
|
58
|
+
return [
|
|
59
|
+
{ event: 'Stop', marker: QUALITY_HOOK_MARKER, command: buildManagedHookCommand(path.join(scripts, 'quality-delta.mjs'), nodePath) },
|
|
60
|
+
{ event: 'SessionStart', marker: GUARDS_HOOK_MARKER, command: guards },
|
|
61
|
+
{ event: 'PreToolUse', marker: GUARDS_HOOK_MARKER, command: guards, matcher: PRE_TOOL_USE_MATCHER }
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const pluginInstall = (packages, marketplace, extra = []) =>
|
|
66
|
+
packages.map((name) => ['plugin', 'install', PACKAGES[name].plugin + '@' + marketplace, ...extra])
|
|
30
67
|
|
|
31
68
|
export const PLATFORM_CONFIG = Object.freeze({
|
|
32
69
|
claude: Object.freeze({
|
|
@@ -35,7 +72,7 @@ export const PLATFORM_CONFIG = Object.freeze({
|
|
|
35
72
|
marketplace: 'agent-os-marketplace',
|
|
36
73
|
installArgs: ['plugin', 'marketplace', 'add', MARKETPLACE_SOURCE],
|
|
37
74
|
refreshArgs: ['plugin', 'marketplace', 'update', 'agent-os-marketplace'],
|
|
38
|
-
pluginArgs: (scope
|
|
75
|
+
pluginArgs: (scope, packages = ['core', 'dev']) => pluginInstall(packages, 'agent-os-marketplace', ['--scope', scope]),
|
|
39
76
|
nextStep: 'Restart Claude Code or run /reload-plugins.'
|
|
40
77
|
}),
|
|
41
78
|
codex: Object.freeze({
|
|
@@ -44,11 +81,21 @@ export const PLATFORM_CONFIG = Object.freeze({
|
|
|
44
81
|
marketplace: 'agent-os',
|
|
45
82
|
installArgs: ['plugin', 'marketplace', 'add', MARKETPLACE_SOURCE],
|
|
46
83
|
refreshArgs: ['plugin', 'marketplace', 'upgrade', 'agent-os'],
|
|
47
|
-
pluginArgs: (
|
|
48
|
-
|
|
84
|
+
pluginArgs: (scope, packages = ['core', 'dev']) =>
|
|
85
|
+
packages.map((name) => ['plugin', 'add', PACKAGES[name].plugin + '@agent-os']),
|
|
86
|
+
nextStep: 'Start a new Codex session so the refreshed plugins are loaded. ' + CODEX_HOOK_TRUST_NOTICE
|
|
49
87
|
})
|
|
50
88
|
})
|
|
51
89
|
|
|
90
|
+
// init-agent-os ships in agent-os-dev, so a core-only install has no setup step to point at.
|
|
91
|
+
function setupNextStep(platform, method, command, packages) {
|
|
92
|
+
if (!packages.includes('dev')) return ''
|
|
93
|
+
const invoke = platform === 'codex' ? '$init-agent-os' : method === 'plugin' ? '/agent-os-dev:init-agent-os' : '/init-agent-os'
|
|
94
|
+
return command === 'update'
|
|
95
|
+
? 'To see what is new for a repository, run ' + invoke + ' in it.\n'
|
|
96
|
+
: 'Next: run ' + invoke + ' global once for your personal preferences, then ' + invoke + ' in each repository you work in.\n'
|
|
97
|
+
}
|
|
98
|
+
|
|
52
99
|
export class CliError extends Error {}
|
|
53
100
|
|
|
54
101
|
function valueAfter(args, index, flag) {
|
|
@@ -82,12 +129,20 @@ function normalizeScope(value) {
|
|
|
82
129
|
return normalized
|
|
83
130
|
}
|
|
84
131
|
|
|
132
|
+
function normalizePackage(value) {
|
|
133
|
+
const normalized = value.toLowerCase()
|
|
134
|
+
if (!PACKAGE_VALUES.includes(normalized)) {
|
|
135
|
+
throw new CliError('Package must be core or all.')
|
|
136
|
+
}
|
|
137
|
+
return normalized
|
|
138
|
+
}
|
|
139
|
+
|
|
85
140
|
function quoteCommandArg(value) {
|
|
86
141
|
return '"' + String(value).replaceAll('"', '\\"') + '"'
|
|
87
142
|
}
|
|
88
143
|
|
|
89
|
-
export function buildManagedHookCommand(scriptPath, nodePath = process.execPath) {
|
|
90
|
-
return [quoteCommandArg(nodePath), quoteCommandArg(scriptPath), 'hook',
|
|
144
|
+
export function buildManagedHookCommand(scriptPath, nodePath = process.execPath, marker = QUALITY_HOOK_MARKER) {
|
|
145
|
+
return [quoteCommandArg(nodePath), quoteCommandArg(scriptPath), 'hook', marker].join(' ')
|
|
91
146
|
}
|
|
92
147
|
|
|
93
148
|
export function parseArgs(argv) {
|
|
@@ -96,11 +151,13 @@ export function parseArgs(argv) {
|
|
|
96
151
|
platform: null,
|
|
97
152
|
method: null,
|
|
98
153
|
scope: null,
|
|
154
|
+
package: null,
|
|
99
155
|
policy: null,
|
|
100
156
|
yes: false,
|
|
101
157
|
dryRun: false,
|
|
102
158
|
help: false,
|
|
103
|
-
version: false
|
|
159
|
+
version: false,
|
|
160
|
+
offline: false
|
|
104
161
|
}
|
|
105
162
|
|
|
106
163
|
let index = 0
|
|
@@ -110,8 +167,8 @@ export function parseArgs(argv) {
|
|
|
110
167
|
}
|
|
111
168
|
|
|
112
169
|
if (result.command === 'upgrade') result.command = 'update'
|
|
113
|
-
if (!['install', 'update', 'help'].includes(result.command)) {
|
|
114
|
-
throw new CliError('Unknown command "' + result.command + '". Use install or
|
|
170
|
+
if (!['install', 'update', 'doctor', 'help'].includes(result.command)) {
|
|
171
|
+
throw new CliError('Unknown command "' + result.command + '". Use install, update, doctor, or lint-intents.')
|
|
115
172
|
}
|
|
116
173
|
|
|
117
174
|
while (index < argv.length) {
|
|
@@ -122,6 +179,8 @@ export function parseArgs(argv) {
|
|
|
122
179
|
result.version = true
|
|
123
180
|
} else if (argument === '--yes' || argument === '-y') {
|
|
124
181
|
result.yes = true
|
|
182
|
+
} else if (argument === '--offline') {
|
|
183
|
+
result.offline = true
|
|
125
184
|
} else if (argument === '--dry-run') {
|
|
126
185
|
result.dryRun = true
|
|
127
186
|
} else if (argument === '--policy') {
|
|
@@ -145,6 +204,11 @@ export function parseArgs(argv) {
|
|
|
145
204
|
index += 1
|
|
146
205
|
} else if (argument.startsWith('--scope=')) {
|
|
147
206
|
result.scope = normalizeScope(argument.slice('--scope='.length))
|
|
207
|
+
} else if (argument === '--package') {
|
|
208
|
+
result.package = normalizePackage(valueAfter(argv, index, argument))
|
|
209
|
+
index += 1
|
|
210
|
+
} else if (argument.startsWith('--package=')) {
|
|
211
|
+
result.package = normalizePackage(argument.slice('--package='.length))
|
|
148
212
|
} else {
|
|
149
213
|
throw new CliError('Unknown option "' + argument + '". Use --help for usage.')
|
|
150
214
|
}
|
|
@@ -195,6 +259,7 @@ export function hookConfigPath(platform, scope, {
|
|
|
195
259
|
|
|
196
260
|
export function buildPlan(options, pathOptions = {}) {
|
|
197
261
|
const { command, platform, method = 'direct', scope = 'user', policy = true } = options
|
|
262
|
+
const packages = selectedPackages(options.package ?? 'all')
|
|
198
263
|
const steps = []
|
|
199
264
|
for (const name of selectedPlatforms(platform)) {
|
|
200
265
|
const config = PLATFORM_CONFIG[name]
|
|
@@ -206,14 +271,16 @@ export function buildPlan(options, pathOptions = {}) {
|
|
|
206
271
|
command: 'filesystem',
|
|
207
272
|
args: [root],
|
|
208
273
|
description: (command === 'update' ? 'Update' : 'Install') +
|
|
209
|
-
' Agent OS managed skills for ' + config.label + '.'
|
|
274
|
+
' Agent OS managed skills (' + packages.map((key) => PACKAGES[key].plugin).join(', ') + ') for ' + config.label + '.'
|
|
210
275
|
})
|
|
211
276
|
steps.push({
|
|
212
277
|
platform: name,
|
|
213
278
|
kind: 'install-hooks',
|
|
214
279
|
command: 'filesystem',
|
|
215
280
|
args: [hookConfigPath(name, scope, pathOptions)],
|
|
216
|
-
description:
|
|
281
|
+
description: packages.includes('dev')
|
|
282
|
+
? 'Merge the Agent OS Stop, SessionStart, and PreToolUse hooks into the ' + config.label + ' configuration.'
|
|
283
|
+
: 'Remove any Agent OS hooks from the ' + config.label + ' configuration; agent-os-core has none.'
|
|
217
284
|
})
|
|
218
285
|
continue
|
|
219
286
|
}
|
|
@@ -241,15 +308,17 @@ export function buildPlan(options, pathOptions = {}) {
|
|
|
241
308
|
description: 'Refresh the Agent OS Git marketplace when applicable.'
|
|
242
309
|
})
|
|
243
310
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
311
|
+
for (const args of config.pluginArgs(scope, packages)) {
|
|
312
|
+
steps.push({
|
|
313
|
+
platform: name,
|
|
314
|
+
kind: 'install-plugin',
|
|
315
|
+
command: config.command,
|
|
316
|
+
args,
|
|
317
|
+
description: command === 'update'
|
|
318
|
+
? 'Install the current Agent OS plugin snapshot.'
|
|
319
|
+
: 'Install the Agent OS plugin.'
|
|
320
|
+
})
|
|
321
|
+
}
|
|
253
322
|
}
|
|
254
323
|
if (policy) {
|
|
255
324
|
steps.push({
|
|
@@ -405,52 +474,74 @@ export async function resolveOptions(parsed, {
|
|
|
405
474
|
: true
|
|
406
475
|
}
|
|
407
476
|
|
|
408
|
-
|
|
409
|
-
|
|
477
|
+
let pkg = parsed.package
|
|
478
|
+
// An update keeps the packages already installed; executeInstall reads them from the manifest.
|
|
479
|
+
if (!pkg && parsed.command !== 'update') {
|
|
480
|
+
pkg = interactive && !parsed.yes
|
|
481
|
+
? await choose('Which Agent OS packages should be installed?', [
|
|
482
|
+
{ value: 'all', label: 'Core and dev (recommended for software work)' },
|
|
483
|
+
{ value: 'core', label: 'Core only (intent, planning, and evidence disciplines without code delivery)' }
|
|
484
|
+
], dependencies)
|
|
485
|
+
: 'all'
|
|
486
|
+
}
|
|
410
487
|
|
|
411
|
-
|
|
412
|
-
return path.join(packageRoot, 'skills')
|
|
488
|
+
return { ...parsed, platform, method, scope, policy, package: pkg }
|
|
413
489
|
}
|
|
414
490
|
|
|
415
491
|
function packagedPolicyPath() {
|
|
416
492
|
return path.join(packageRoot, 'policy.md')
|
|
417
493
|
}
|
|
418
494
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
495
|
+
// Returns [{ name, dir, package }] for the selected packages, sorted by skill name.
|
|
496
|
+
export function listPackagedSkills(packages = ['core', 'dev'], fsImpl = fs, root = packageRoot) {
|
|
497
|
+
const skills = []
|
|
498
|
+
for (const key of packages) {
|
|
499
|
+
const sourceRoot = path.join(root, PACKAGES[key].skills)
|
|
500
|
+
if (!fsImpl.existsSync(sourceRoot)) {
|
|
501
|
+
throw new CliError('Packaged skills directory is missing: ' + sourceRoot)
|
|
502
|
+
}
|
|
503
|
+
for (const entry of fsImpl.readdirSync(sourceRoot, { withFileTypes: true })) {
|
|
504
|
+
if (entry.isDirectory() && fsImpl.existsSync(path.join(sourceRoot, entry.name, 'SKILL.md'))) {
|
|
505
|
+
skills.push({ name: entry.name, dir: path.join(sourceRoot, entry.name), package: key })
|
|
506
|
+
}
|
|
507
|
+
}
|
|
422
508
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
.map((entry) => entry.name)
|
|
426
|
-
.sort()
|
|
427
|
-
if (entries.length === 0) throw new CliError('No packaged skills were found in ' + sourceRoot)
|
|
428
|
-
return entries
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function containsHookMarker(value) {
|
|
432
|
-
if (typeof value === 'string') return value.includes(QUALITY_HOOK_MARKER)
|
|
433
|
-
if (Array.isArray(value)) return value.some(containsHookMarker)
|
|
434
|
-
if (value && typeof value === 'object') return Object.values(value).some(containsHookMarker)
|
|
435
|
-
return false
|
|
509
|
+
if (skills.length === 0) throw new CliError('No packaged skills were found in ' + root)
|
|
510
|
+
return skills.sort((left, right) => left.name.localeCompare(right.name))
|
|
436
511
|
}
|
|
437
512
|
|
|
438
|
-
function managedCommandHooks(value, matches = []) {
|
|
513
|
+
function managedCommandHooks(value, marker, matches = []) {
|
|
439
514
|
if (Array.isArray(value)) {
|
|
440
|
-
value.forEach((item) => managedCommandHooks(item, matches))
|
|
515
|
+
value.forEach((item) => managedCommandHooks(item, marker, matches))
|
|
441
516
|
return matches
|
|
442
517
|
}
|
|
443
518
|
if (!value || typeof value !== 'object') return matches
|
|
444
|
-
if (typeof value.command === 'string' && value.command.includes(
|
|
519
|
+
if (typeof value.command === 'string' && value.command.includes(marker)) {
|
|
445
520
|
matches.push(value)
|
|
446
521
|
}
|
|
447
522
|
Object.entries(value).forEach(([key, item]) => {
|
|
448
|
-
if (key !== 'command') managedCommandHooks(item, matches)
|
|
523
|
+
if (key !== 'command') managedCommandHooks(item, marker, matches)
|
|
449
524
|
})
|
|
450
525
|
return matches
|
|
451
526
|
}
|
|
452
527
|
|
|
453
|
-
|
|
528
|
+
function containsMarker(value, marker) {
|
|
529
|
+
if (typeof value === 'string') return value.includes(marker)
|
|
530
|
+
if (Array.isArray(value)) return value.some((item) => containsMarker(item, marker))
|
|
531
|
+
if (value && typeof value === 'object') return Object.values(value).some((item) => containsMarker(item, marker))
|
|
532
|
+
return false
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function removeManagedHook(groups, entry) {
|
|
536
|
+
for (const group of groups) {
|
|
537
|
+
if (Array.isArray(group?.hooks)) group.hooks = group.hooks.filter((hook) => hook !== entry)
|
|
538
|
+
}
|
|
539
|
+
return groups.filter((group) => !Array.isArray(group?.hooks) || group.hooks.length > 0)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// entries: [{ event, marker, command, matcher?, remove? }]. Each marker owns exactly one command hook
|
|
543
|
+
// per event; unrelated hooks and settings are preserved byte-for-byte in meaning.
|
|
544
|
+
export function planManagedHooks(content, entries, target = 'Agent OS hook configuration') {
|
|
454
545
|
let config
|
|
455
546
|
if (!content.trim()) {
|
|
456
547
|
config = {}
|
|
@@ -464,55 +555,79 @@ export function planManagedHookConfig(content, command, target = 'Agent OS hook
|
|
|
464
555
|
if (!config || typeof config !== 'object' || Array.isArray(config)) {
|
|
465
556
|
throw new CliError('Refusing to merge the Agent OS hook into malformed ' + target + '; no files were changed.')
|
|
466
557
|
}
|
|
558
|
+
const hadHooks = config.hooks !== undefined
|
|
467
559
|
if (config.hooks === undefined) config.hooks = {}
|
|
468
560
|
if (!config.hooks || typeof config.hooks !== 'object' || Array.isArray(config.hooks)) {
|
|
469
561
|
throw new CliError('Refusing to merge the Agent OS hook into malformed ' + target + '.hooks; no files were changed.')
|
|
470
562
|
}
|
|
471
|
-
if (config.hooks[QUALITY_HOOK_EVENT] === undefined) config.hooks[QUALITY_HOOK_EVENT] = []
|
|
472
|
-
if (!Array.isArray(config.hooks[QUALITY_HOOK_EVENT])) {
|
|
473
|
-
throw new CliError('Refusing to merge the Agent OS hook into malformed ' + target + '.hooks.Stop; no files were changed.')
|
|
474
|
-
}
|
|
475
563
|
|
|
476
|
-
const
|
|
477
|
-
for (const
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
564
|
+
const markers = [...new Set(entries.map((entry) => entry.marker))]
|
|
565
|
+
for (const marker of markers) {
|
|
566
|
+
const events = entries.filter((entry) => entry.marker === marker).map((entry) => entry.event)
|
|
567
|
+
let found = 0
|
|
568
|
+
for (const [event, value] of Object.entries(config.hooks)) {
|
|
569
|
+
const matches = managedCommandHooks(value, marker)
|
|
570
|
+
if (matches.length && !events.includes(event)) {
|
|
571
|
+
throw new CliError('Refusing to update an Agent OS hook outside hooks.' + events.join('/hooks.') + ' in ' + target + '; no files were changed.')
|
|
572
|
+
}
|
|
573
|
+
found += matches.length
|
|
574
|
+
}
|
|
575
|
+
if (containsMarker(config, marker) && found === 0) {
|
|
576
|
+
throw new CliError('Refusing to update an ambiguous Agent OS hook marker in ' + target + '; no files were changed.')
|
|
481
577
|
}
|
|
482
|
-
managed.push(...matches)
|
|
483
|
-
}
|
|
484
|
-
if (containsHookMarker(config) && managed.length === 0) {
|
|
485
|
-
throw new CliError('Refusing to update an ambiguous Agent OS hook marker in ' + target + '; no files were changed.')
|
|
486
|
-
}
|
|
487
|
-
if (managed.length > 1) {
|
|
488
|
-
throw new CliError('Refusing to update multiple Agent OS hook entries in ' + target + '; no files were changed.')
|
|
489
578
|
}
|
|
490
579
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
580
|
+
let changed = false
|
|
581
|
+
let added = false
|
|
582
|
+
for (const entry of entries) {
|
|
583
|
+
if (config.hooks[entry.event] === undefined) {
|
|
584
|
+
if (entry.remove) continue
|
|
585
|
+
config.hooks[entry.event] = []
|
|
586
|
+
}
|
|
587
|
+
if (!Array.isArray(config.hooks[entry.event])) {
|
|
588
|
+
throw new CliError('Refusing to merge the Agent OS hook into malformed ' + target + '.hooks.' + entry.event + '; no files were changed.')
|
|
589
|
+
}
|
|
590
|
+
const managed = managedCommandHooks(config.hooks[entry.event], entry.marker)
|
|
591
|
+
if (managed.length > 1) {
|
|
592
|
+
throw new CliError('Refusing to update multiple Agent OS hook entries in ' + target + '; no files were changed.')
|
|
593
|
+
}
|
|
594
|
+
if (managed.length === 1 && managed[0].type !== 'command') {
|
|
494
595
|
throw new CliError('Refusing to update a malformed Agent OS command hook in ' + target + '; no files were changed.')
|
|
495
596
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
597
|
+
if (entry.remove) {
|
|
598
|
+
if (managed.length === 1) {
|
|
599
|
+
config.hooks[entry.event] = removeManagedHook(config.hooks[entry.event], managed[0])
|
|
600
|
+
if (config.hooks[entry.event].length === 0) delete config.hooks[entry.event]
|
|
601
|
+
changed = true
|
|
602
|
+
}
|
|
603
|
+
continue
|
|
604
|
+
}
|
|
605
|
+
if (managed.length === 1) {
|
|
606
|
+
const hook = managed[0]
|
|
607
|
+
if (hook.command !== entry.command || hook.timeout !== HOOK_TIMEOUT_SECONDS) {
|
|
608
|
+
hook.command = entry.command
|
|
609
|
+
hook.timeout = HOOK_TIMEOUT_SECONDS
|
|
610
|
+
changed = true
|
|
611
|
+
}
|
|
612
|
+
const group = config.hooks[entry.event].find((item) => Array.isArray(item?.hooks) && item.hooks.includes(hook))
|
|
613
|
+
if (entry.matcher && group && group.matcher !== entry.matcher) {
|
|
614
|
+
group.matcher = entry.matcher
|
|
615
|
+
changed = true
|
|
616
|
+
}
|
|
617
|
+
continue
|
|
503
618
|
}
|
|
619
|
+
config.hooks[entry.event].push({
|
|
620
|
+
...(entry.matcher ? { matcher: entry.matcher } : {}),
|
|
621
|
+
hooks: [{ type: 'command', command: entry.command, timeout: HOOK_TIMEOUT_SECONDS }]
|
|
622
|
+
})
|
|
623
|
+
changed = true
|
|
624
|
+
added = true
|
|
504
625
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
hooks: [{
|
|
508
|
-
type: 'command',
|
|
509
|
-
command,
|
|
510
|
-
timeout: HOOK_TIMEOUT_SECONDS
|
|
511
|
-
}]
|
|
512
|
-
})
|
|
626
|
+
if (!hadHooks && Object.keys(config.hooks).length === 0) delete config.hooks
|
|
627
|
+
if (!changed) return { changed: false, status: 'OK', content }
|
|
513
628
|
return {
|
|
514
629
|
changed: true,
|
|
515
|
-
status: 'ADDED',
|
|
630
|
+
status: added ? 'ADDED' : 'UPDATED',
|
|
516
631
|
content: JSON.stringify(config, null, 2) + '\n'
|
|
517
632
|
}
|
|
518
633
|
}
|
|
@@ -543,16 +658,16 @@ function directTargets(options, { homeDir, cwd }) {
|
|
|
543
658
|
}
|
|
544
659
|
|
|
545
660
|
function prepareHookPlans(options, { homeDir, cwd, fsImpl = fs }) {
|
|
661
|
+
const dev = selectedPackages(options.package ?? 'all').includes('dev')
|
|
546
662
|
return directTargets(options, { homeDir, cwd }).map((target) => {
|
|
547
|
-
const
|
|
548
|
-
const command = buildManagedHookCommand(scriptPath)
|
|
663
|
+
const entries = managedHookEntries(target.root).map((entry) => (dev ? entry : { ...entry, remove: true }))
|
|
549
664
|
const current = fsImpl.existsSync(target.hookPath)
|
|
550
665
|
? fsImpl.readFileSync(target.hookPath, 'utf8')
|
|
551
666
|
: ''
|
|
552
667
|
return {
|
|
553
668
|
...target,
|
|
554
|
-
command,
|
|
555
|
-
...
|
|
669
|
+
command: entries[0].command,
|
|
670
|
+
...planManagedHooks(current, entries, target.hookPath)
|
|
556
671
|
}
|
|
557
672
|
})
|
|
558
673
|
}
|
|
@@ -585,6 +700,7 @@ function applyHookPlans(plans, { output, fsImpl = fs }) {
|
|
|
585
700
|
}
|
|
586
701
|
output.write(plan.status.padEnd(7) + plan.hookPath + '\n')
|
|
587
702
|
}
|
|
703
|
+
if (plans.some((plan) => plan.changed && plan.platform === 'codex')) output.write(CODEX_HOOK_TRUST_NOTICE + '\n')
|
|
588
704
|
} catch (cause) {
|
|
589
705
|
let rollbackFailure = null
|
|
590
706
|
for (const plan of applied.reverse()) {
|
|
@@ -616,7 +732,7 @@ function preflightDirectTarget(target, skillNames, fsImpl = fs) {
|
|
|
616
732
|
return manifest
|
|
617
733
|
}
|
|
618
734
|
|
|
619
|
-
function replaceManagedSkills(target,
|
|
735
|
+
function replaceManagedSkills(target, sources, skillNames, previousManifest, fsImpl = fs, packages = ['core', 'dev']) {
|
|
620
736
|
fsImpl.mkdirSync(target.root, { recursive: true })
|
|
621
737
|
const token = randomUUID()
|
|
622
738
|
const stageRoot = path.join(target.root, '.agent-os-stage-' + token)
|
|
@@ -634,7 +750,12 @@ function replaceManagedSkills(target, sourceRoot, skillNames, previousManifest,
|
|
|
634
750
|
try {
|
|
635
751
|
fsImpl.mkdirSync(stageRoot, { recursive: true })
|
|
636
752
|
for (const name of skillNames) {
|
|
637
|
-
fsImpl.cpSync(
|
|
753
|
+
fsImpl.cpSync(sources[name], path.join(stageRoot, name), { recursive: true })
|
|
754
|
+
}
|
|
755
|
+
// The init-agent-os policy script needs the policy source outside a checkout or plugin root.
|
|
756
|
+
const policySource = packagedPolicyPath()
|
|
757
|
+
if (skillNames.includes('init-agent-os') && fsImpl.existsSync(policySource)) {
|
|
758
|
+
fsImpl.copyFileSync(policySource, path.join(stageRoot, 'init-agent-os', 'policy.md'))
|
|
638
759
|
}
|
|
639
760
|
|
|
640
761
|
if (namesToBackup.length > 0) fsImpl.mkdirSync(backupRoot, { recursive: true })
|
|
@@ -655,13 +776,17 @@ function replaceManagedSkills(target, sourceRoot, skillNames, previousManifest,
|
|
|
655
776
|
platform: target.platform,
|
|
656
777
|
scope: target.scope,
|
|
657
778
|
skills: skillNames,
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
779
|
+
packages: packages.map((key) => PACKAGES[key].plugin),
|
|
780
|
+
integrations: packages.includes('dev')
|
|
781
|
+
? {
|
|
782
|
+
hooks: {
|
|
783
|
+
configPath: target.hookPath,
|
|
784
|
+
event: QUALITY_HOOK_EVENT,
|
|
785
|
+
marker: QUALITY_HOOK_MARKER,
|
|
786
|
+
guards: { events: ['SessionStart', 'PreToolUse'], marker: GUARDS_HOOK_MARKER }
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
: {}
|
|
665
790
|
}
|
|
666
791
|
writeFileAtomic(manifestPath, JSON.stringify(manifest, null, 2) + '\n', fsImpl)
|
|
667
792
|
} catch (error) {
|
|
@@ -691,10 +816,13 @@ function prepareDirectInstall(options, {
|
|
|
691
816
|
cwd,
|
|
692
817
|
sourceRoot
|
|
693
818
|
}) {
|
|
694
|
-
const
|
|
819
|
+
const packages = selectedPackages(options.package ?? 'all')
|
|
820
|
+
const skills = listPackagedSkills(packages, fsImpl, sourceRoot)
|
|
821
|
+
const skillNames = skills.map((skill) => skill.name)
|
|
822
|
+
const sources = Object.fromEntries(skills.map((skill) => [skill.name, skill.dir]))
|
|
695
823
|
const targets = directTargets(options, { homeDir, cwd })
|
|
696
824
|
const manifests = targets.map((target) => preflightDirectTarget(target, skillNames, fsImpl))
|
|
697
|
-
return { skillNames, targets, manifests,
|
|
825
|
+
return { skillNames, targets, manifests, sources, packages }
|
|
698
826
|
}
|
|
699
827
|
|
|
700
828
|
function prepareManagedSkillRollback(plan, fsImpl = fs) {
|
|
@@ -770,8 +898,9 @@ function applyDirectInstall(options, plan, {
|
|
|
770
898
|
output.write('\n[' + config.label + ']\n')
|
|
771
899
|
output.write((options.command === 'update' ? 'Updating' : 'Installing') +
|
|
772
900
|
' ' + plan.skillNames.length + ' managed skills in ' + target.root + '...\n')
|
|
773
|
-
replaceManagedSkills(target, plan.
|
|
901
|
+
replaceManagedSkills(target, plan.sources, plan.skillNames, plan.manifests[index], fsImpl, plan.packages)
|
|
774
902
|
output.write('Done. Start a new ' + config.label + ' session to load the skills.\n')
|
|
903
|
+
output.write(setupNextStep(target.platform, 'direct', options.command, plan.packages))
|
|
775
904
|
})
|
|
776
905
|
}
|
|
777
906
|
|
|
@@ -812,6 +941,22 @@ function executePlugin(options, { output, execute, exists }) {
|
|
|
812
941
|
output.write('Agent OS marketplace is already registered.\n')
|
|
813
942
|
}
|
|
814
943
|
|
|
944
|
+
const packages = selectedPackages(options.package ?? 'all')
|
|
945
|
+
if (name === 'claude') {
|
|
946
|
+
// The single agent-os plugin from before the split, and agent-os-dev for a core-only choice.
|
|
947
|
+
const stale = [
|
|
948
|
+
...(options.command === 'update' ? ['agent-os'] : []),
|
|
949
|
+
...(packages.includes('dev') ? [] : [PACKAGES.dev.plugin])
|
|
950
|
+
]
|
|
951
|
+
for (const plugin of stale) {
|
|
952
|
+
const args = ['plugin', 'uninstall', plugin + '@' + config.marketplace, '--scope', options.scope]
|
|
953
|
+
if (execute(config.command, args, { capture: true }).status === 0) output.write('Removed ' + plugin + '.\n')
|
|
954
|
+
}
|
|
955
|
+
} else if (options.command === 'update' || !packages.includes('dev')) {
|
|
956
|
+
output.write('If the single agent-os plugin from before the split' +
|
|
957
|
+
(packages.includes('dev') ? '' : ', or agent-os-dev,') + ' is still installed, remove it in /plugins.\n')
|
|
958
|
+
}
|
|
959
|
+
|
|
815
960
|
if (options.command === 'update') {
|
|
816
961
|
let sourceType = null
|
|
817
962
|
if (name === 'codex' && registered) {
|
|
@@ -837,57 +982,21 @@ function executePlugin(options, { output, execute, exists }) {
|
|
|
837
982
|
}
|
|
838
983
|
}
|
|
839
984
|
|
|
840
|
-
const pluginArgs
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
985
|
+
for (const pluginArgs of config.pluginArgs(options.scope, selectedPackages(options.package ?? 'all'))) {
|
|
986
|
+
output.write((options.command === 'update' ? 'Installing the current snapshot of ' : 'Installing ') +
|
|
987
|
+
pluginArgs[2] + '...\n')
|
|
988
|
+
assertSuccess(execute(config.command, pluginArgs), config.command, pluginArgs)
|
|
989
|
+
}
|
|
845
990
|
output.write('Done. ' + config.nextStep + '\n')
|
|
991
|
+
output.write(setupNextStep(name, 'plugin', options.command, packages))
|
|
846
992
|
}
|
|
847
993
|
}
|
|
848
994
|
|
|
849
|
-
function
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
export function planPolicyUpdate(content, policy) {
|
|
854
|
-
const normalizedPolicy = policy.trimEnd()
|
|
855
|
-
const block = BEGIN_MARKER + '\n' + normalizedPolicy + '\n' + END_MARKER
|
|
856
|
-
const beginCount = countOccurrences(content, BEGIN_MARKER)
|
|
857
|
-
const endCount = countOccurrences(content, END_MARKER)
|
|
858
|
-
|
|
859
|
-
if (beginCount === 0 && endCount === 0) {
|
|
860
|
-
const separator = content.length === 0 ? '' : content.endsWith('\n') ? '\n' : '\n\n'
|
|
861
|
-
return { changed: true, status: 'ADDED', content: content + separator + block + '\n' }
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
const start = content.indexOf(BEGIN_MARKER)
|
|
865
|
-
const endStart = content.indexOf(END_MARKER)
|
|
866
|
-
if (beginCount !== 1 || endCount !== 1 || start >= endStart) {
|
|
867
|
-
throw new CliError(
|
|
868
|
-
'Malformed Agent OS policy markers (begin=' + beginCount + ' end=' + endCount + '); no files were changed.'
|
|
869
|
-
)
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
const end = endStart + END_MARKER.length
|
|
873
|
-
const current = content.slice(start, end)
|
|
874
|
-
if (current === block) return { changed: false, status: 'OK', content }
|
|
875
|
-
return {
|
|
876
|
-
changed: true,
|
|
877
|
-
status: 'UPDATED',
|
|
878
|
-
content: content.slice(0, start) + block + content.slice(end)
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
function preparePolicyPlans({ fsImpl, homeDir, policyFile }) {
|
|
883
|
-
const policy = fsImpl.readFileSync(policyFile, 'utf8')
|
|
884
|
-
const targets = [
|
|
885
|
-
path.join(homeDir, '.claude', 'CLAUDE.md'),
|
|
886
|
-
path.join(homeDir, '.codex', 'AGENTS.md')
|
|
887
|
-
]
|
|
888
|
-
return targets.map((target) => {
|
|
995
|
+
function preparePolicyPlans({ fsImpl, homeDir, policyFile, platform, dev = true }) {
|
|
996
|
+
const policy = composePolicy(fsImpl.readFileSync(policyFile, 'utf8'), { dev })
|
|
997
|
+
return policyTargets(selectedPlatforms(platform), homeDir).map((target) => {
|
|
889
998
|
const content = fsImpl.existsSync(target) ? fsImpl.readFileSync(target, 'utf8') : ''
|
|
890
|
-
return { target, ...planPolicyUpdate(content, policy) }
|
|
999
|
+
return { target, ...planPolicyUpdate(content, policy, VERSION) }
|
|
891
1000
|
})
|
|
892
1001
|
}
|
|
893
1002
|
|
|
@@ -901,6 +1010,18 @@ function applyPolicyPlans(plans, { output, fsImpl }) {
|
|
|
901
1010
|
}
|
|
902
1011
|
}
|
|
903
1012
|
|
|
1013
|
+
// The package choice of an earlier direct install: core when any selected target recorded only core.
|
|
1014
|
+
export function installedPackage(options, { homeDir, cwd, fsImpl = fs }) {
|
|
1015
|
+
if (options.method === 'plugin') return 'all'
|
|
1016
|
+
for (const target of directTargets(options, { homeDir, cwd })) {
|
|
1017
|
+
const manifest = readInstallManifest(target.root, fsImpl)
|
|
1018
|
+
if (Array.isArray(manifest?.packages) && manifest.packages.length && !manifest.packages.includes(PACKAGES.dev.plugin)) {
|
|
1019
|
+
return 'core'
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return 'all'
|
|
1023
|
+
}
|
|
1024
|
+
|
|
904
1025
|
export async function executeInstall(options, {
|
|
905
1026
|
output = process.stdout,
|
|
906
1027
|
spawn = spawnSync,
|
|
@@ -909,11 +1030,17 @@ export async function executeInstall(options, {
|
|
|
909
1030
|
fsImpl = fs,
|
|
910
1031
|
homeDir = os.homedir(),
|
|
911
1032
|
cwd = process.cwd(),
|
|
912
|
-
sourceRoot =
|
|
1033
|
+
sourceRoot = packageRoot,
|
|
913
1034
|
policyFile = packagedPolicyPath()
|
|
914
1035
|
} = {}) {
|
|
1036
|
+
if (!options.package) {
|
|
1037
|
+
options = { ...options, package: installedPackage(options, { homeDir, cwd, fsImpl }) }
|
|
1038
|
+
}
|
|
915
1039
|
const policyPlans = options.policy
|
|
916
|
-
? preparePolicyPlans({
|
|
1040
|
+
? preparePolicyPlans({
|
|
1041
|
+
fsImpl, homeDir, policyFile, platform: options.platform,
|
|
1042
|
+
dev: selectedPackages(options.package ?? 'all').includes('dev')
|
|
1043
|
+
})
|
|
917
1044
|
: null
|
|
918
1045
|
const directPlan = options.method === 'plugin'
|
|
919
1046
|
? null
|
|
@@ -928,7 +1055,7 @@ export async function executeInstall(options, {
|
|
|
928
1055
|
const rollback = prepareManagedSkillRollback(directPlan, fsImpl)
|
|
929
1056
|
try {
|
|
930
1057
|
applyDirectInstall(options, directPlan, { output, fsImpl })
|
|
931
|
-
output.write('\n[
|
|
1058
|
+
output.write('\n[Agent OS hooks]\n')
|
|
932
1059
|
applyHookPlans(hookPlans, { output, fsImpl })
|
|
933
1060
|
} catch (cause) {
|
|
934
1061
|
try {
|
|
@@ -947,7 +1074,7 @@ export async function executeInstall(options, {
|
|
|
947
1074
|
}
|
|
948
1075
|
|
|
949
1076
|
if (options.policy) {
|
|
950
|
-
output.write('\n[Shared policy]\nSyncing the global
|
|
1077
|
+
output.write('\n[Shared policy]\nSyncing the global policy for the selected platforms...\n')
|
|
951
1078
|
applyPolicyPlans(policyPlans, { output, fsImpl })
|
|
952
1079
|
}
|
|
953
1080
|
}
|
|
@@ -957,17 +1084,24 @@ export function printHelp(output = process.stdout) {
|
|
|
957
1084
|
'Agent OS installer ' + VERSION + '\n\n' +
|
|
958
1085
|
'Usage:\n' +
|
|
959
1086
|
' npx ' + PACKAGE_NAME + ' install\n' +
|
|
960
|
-
' npx ' + PACKAGE_NAME + ' update\n
|
|
1087
|
+
' npx ' + PACKAGE_NAME + ' update\n' +
|
|
1088
|
+
' npx ' + PACKAGE_NAME + '@latest doctor Report installed versions, drift, and fixes (read-only)\n' +
|
|
1089
|
+
' npx ' + PACKAGE_NAME + ' lint-intents Check intents/<id>/ intent, spec, and plan files\n\n' +
|
|
961
1090
|
'Direct installation is the default and does not require Codex or Claude Code CLI.\n\n' +
|
|
962
|
-
'
|
|
1091
|
+
'Agent OS ships two packages: agent-os-core (intent, planning, and evidence disciplines) and\n' +
|
|
1092
|
+
'agent-os-dev (delivery, review, and guard hooks for code). Both are installed unless you choose core.\n' +
|
|
1093
|
+
'With agent-os-dev, direct installation merges its Stop, SessionStart, and PreToolUse hooks without\n' +
|
|
1094
|
+
'replacing unrelated hooks.\n\n' +
|
|
963
1095
|
'Options:\n' +
|
|
964
1096
|
' -p, --platform <name> claude, codex, or both\n' +
|
|
965
1097
|
' -m, --method <name> direct (default) or plugin\n' +
|
|
966
1098
|
' -s, --scope <name> user or project; plugin mode also supports local\n' +
|
|
967
|
-
' --
|
|
1099
|
+
' --package <name> all (default: core and dev) or core\n' +
|
|
1100
|
+
' --policy Sync the global policy file of each selected platform\n' +
|
|
968
1101
|
' --no-policy Leave global policy files unchanged\n' +
|
|
969
1102
|
' -y, --yes Accept defaults; useful in scripts\n' +
|
|
970
1103
|
' --dry-run Show the planned flow without running commands\n' +
|
|
1104
|
+
' --offline doctor: skip the npm lookup of the latest version\n' +
|
|
971
1105
|
' -h, --help Show this help\n' +
|
|
972
1106
|
' -v, --version Show the CLI version\n\n' +
|
|
973
1107
|
'Examples:\n' +
|
|
@@ -987,7 +1121,30 @@ export function printPlan(options, output = process.stdout, pathOptions = {}) {
|
|
|
987
1121
|
}
|
|
988
1122
|
}
|
|
989
1123
|
|
|
1124
|
+
export function runLintIntents(argv, { output = process.stdout, cwd = process.cwd() } = {}) {
|
|
1125
|
+
const options = { root: cwd, dir: 'intents', base: null, allowUnchangedRev: false, strict: false }
|
|
1126
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
1127
|
+
const argument = argv[index]
|
|
1128
|
+
if (argument === '--allow-unchanged-rev') options.allowUnchangedRev = true
|
|
1129
|
+
else if (argument === '--strict') options.strict = true
|
|
1130
|
+
else if (['--base', '--root', '--dir'].includes(argument)) {
|
|
1131
|
+
options[argument.slice(2)] = valueAfter(argv, index, argument)
|
|
1132
|
+
index += 1
|
|
1133
|
+
} else throw new CliError('Unknown lint-intents option "' + argument + '". Use --base <ref>, --allow-unchanged-rev, --strict, --root <dir>, or --dir <dir>.')
|
|
1134
|
+
}
|
|
1135
|
+
const problems = lintIntents(path.resolve(options.root), options)
|
|
1136
|
+
for (const problem of problems) {
|
|
1137
|
+
output.write((problem.level === 'error' ? 'ERROR ' : 'WARN ') + problem.file + ': ' + problem.message + '\n')
|
|
1138
|
+
}
|
|
1139
|
+
const failing = problems.filter((problem) => problem.level === 'error' || options.strict)
|
|
1140
|
+
output.write(failing.length
|
|
1141
|
+
? 'lint-intents: ' + failing.length + ' problem(s) must be fixed.\n'
|
|
1142
|
+
: 'lint-intents: intent files are consistent' + (problems.length ? ' (' + problems.length + ' warning(s))' : '') + '.\n')
|
|
1143
|
+
return failing.length ? 1 : 0
|
|
1144
|
+
}
|
|
1145
|
+
|
|
990
1146
|
export async function run(argv = process.argv.slice(2), dependencies = {}) {
|
|
1147
|
+
if (argv[0] === 'lint-intents') return runLintIntents(argv.slice(1), dependencies)
|
|
991
1148
|
const parsed = parseArgs(argv)
|
|
992
1149
|
if (parsed.help || parsed.command === 'help') {
|
|
993
1150
|
printHelp(dependencies.output || process.stdout)
|
|
@@ -997,6 +1154,26 @@ export async function run(argv = process.argv.slice(2), dependencies = {}) {
|
|
|
997
1154
|
(dependencies.output || process.stdout).write(VERSION + '\n')
|
|
998
1155
|
return 0
|
|
999
1156
|
}
|
|
1157
|
+
if (parsed.command === 'doctor') {
|
|
1158
|
+
const fsImpl = dependencies.fsImpl || fs
|
|
1159
|
+
const latest = parsed.offline
|
|
1160
|
+
? null
|
|
1161
|
+
: (dependencies.latestVersion || ((name) => latestPublishedVersion(name)))(PACKAGE_NAME)
|
|
1162
|
+
const result = collectDoctorReport({
|
|
1163
|
+
version: VERSION,
|
|
1164
|
+
packageName: PACKAGE_NAME,
|
|
1165
|
+
packagedSkills: listPackagedSkills(['core', 'dev'], fsImpl).map((skill) => skill.name),
|
|
1166
|
+
packageSkills: Object.fromEntries(Object.keys(PACKAGES).map((key) =>
|
|
1167
|
+
[PACKAGES[key].plugin, listPackagedSkills([key], fsImpl).map((skill) => skill.name)])),
|
|
1168
|
+
policy: fsImpl.readFileSync(packagedPolicyPath(), 'utf8'),
|
|
1169
|
+
homeDir: dependencies.homeDir,
|
|
1170
|
+
cwd: dependencies.cwd,
|
|
1171
|
+
fsImpl,
|
|
1172
|
+
latest
|
|
1173
|
+
})
|
|
1174
|
+
;(dependencies.output || process.stdout).write(formatDoctorReport(result))
|
|
1175
|
+
return result.drift ? 1 : 0
|
|
1176
|
+
}
|
|
1000
1177
|
const options = await resolveOptions(parsed, dependencies)
|
|
1001
1178
|
if (options.dryRun) {
|
|
1002
1179
|
printPlan(options, dependencies.output || process.stdout, {
|