@sockulags/agent-os 0.9.0 → 0.9.1

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.
Files changed (40) hide show
  1. package/README.md +23 -16
  2. package/cli/index.mjs +375 -52
  3. package/cli/index.test.mjs +196 -38
  4. package/package.json +2 -2
  5. package/policy.md +6 -6
  6. package/skills/batch-work/SKILL.md +43 -0
  7. package/skills/batch-work/agents/openai.yaml +2 -0
  8. package/skills/batch-work/references/manifest.md +100 -0
  9. package/skills/batch-work/scripts/manifest-hash.mjs +263 -0
  10. package/skills/batch-work/scripts/test-manifest-hash.mjs +132 -0
  11. package/skills/chart-work/SKILL.md +37 -0
  12. package/skills/chart-work/agents/openai.yaml +2 -0
  13. package/skills/chart-work/references/elicitation.md +25 -0
  14. package/skills/chart-work/references/map.md +84 -0
  15. package/skills/chart-work/references/prototypes.md +21 -0
  16. package/skills/deliver-work/SKILL.md +12 -0
  17. package/skills/deliver-work/agents/openai.yaml +2 -0
  18. package/skills/deliver-work/workflow.md +109 -0
  19. package/skills/diagnose-before-fix/SKILL.md +24 -0
  20. package/skills/dispatch-next/SKILL.md +28 -0
  21. package/skills/dispatch-next/agents/openai.yaml +2 -0
  22. package/skills/explain-work/SKILL.md +27 -0
  23. package/skills/explain-work/agents/openai.yaml +2 -0
  24. package/skills/guide-me/SKILL.md +36 -0
  25. package/skills/guide-me/agents/openai.yaml +2 -0
  26. package/skills/init-agent-os/SKILL.md +39 -0
  27. package/skills/init-agent-os/agents/openai.yaml +2 -0
  28. package/skills/notice-lesson/SKILL.md +20 -0
  29. package/skills/record-lesson/SKILL.md +31 -0
  30. package/skills/record-lesson/agents/openai.yaml +2 -0
  31. package/skills/scope-guard/SKILL.md +21 -0
  32. package/skills/shape-work/SKILL.md +39 -0
  33. package/skills/shape-work/agents/openai.yaml +2 -0
  34. package/skills/shape-work/references/implementation-issues.md +69 -0
  35. package/skills/shape-work/references/mockups.md +23 -0
  36. package/skills/understand-work/SKILL.md +31 -0
  37. package/skills/understand-work/agents/openai.yaml +2 -0
  38. package/skills/verify-before-done/SKILL.md +29 -0
  39. package/skills/writing-skills/SKILL.md +68 -0
  40. package/skills/writing-skills/agents/openai.yaml +2 -0
package/README.md CHANGED
@@ -37,18 +37,19 @@ Manual skills carry `disable-model-invocation: true` (Claude) and `agents/openai
37
37
 
38
38
  ### Guided npm installer
39
39
 
40
- The recommended setup is a guided command that asks which host to configure and whether to sync
41
- the shared global policy:
40
+ The recommended setup is a guided command that asks which host skill directories to configure and
41
+ whether to sync the shared global policy:
42
42
 
43
43
  ~~~bash
44
44
  npx @sockulags/agent-os install
45
45
  ~~~
46
46
 
47
- It supports Codex, Claude Code, or both. The host CLI must already be installed. For a
48
- non-interactive install, make the choices explicit:
47
+ It supports Codex, Claude Code, or both without requiring either host CLI. By default it copies the
48
+ packaged skills into the selected user-level directories (`~/.codex/skills` and/or
49
+ `~/.claude/skills`). For a non-interactive install, make the choices explicit:
49
50
 
50
51
  ~~~bash
51
- npx @sockulags/agent-os install --platform both --yes
52
+ npx @sockulags/agent-os install --platform both --scope user --yes
52
53
  ~~~
53
54
 
54
55
  To refresh an existing installation:
@@ -58,21 +59,27 @@ npx @sockulags/agent-os update
58
59
  npx @sockulags/agent-os update --platform codex --no-policy
59
60
  ~~~
60
61
 
61
- The first command always downloads the current npm CLI. To keep the CLI itself installed locally,
62
- use npm install --global @sockulags/agent-os@latest or run npx @sockulags/agent-os@latest.
62
+ Updates replace only skill directories recorded in `.agent-os-install.json` and preserve unrelated
63
+ skills. Use `--scope project` to install into the current project's skill directories. The first
64
+ command always downloads the current npm CLI; use `npx @sockulags/agent-os@latest update` to force
65
+ the newest published installer.
63
66
 
64
- **Claude Code (development):** from the repository root, run `claude --plugin-dir .`, then reload with `/reload-plugins`.
65
-
66
- **Claude Code (production):** add this repo as a personal marketplace, then install the `agent-os` plugin. Skills appear as `/agent-os:<skill>`.
67
-
68
- **Codex (development & production):** local repo marketplace via `.agents/plugins/marketplace.json`; install copies to the Codex cache — refresh/reinstall and start a new session after changes. Skills appear as `$<skill>`.
67
+ Direct Claude skills appear as `/<skill>` and direct Codex skills as `$<skill>`.
68
+
69
+ Native marketplace installation remains available with `--method plugin`. It requires the selected
70
+ host CLI. Claude plugin skills appear as `/agent-os:<skill>`; Codex plugin skills remain
71
+ `$<skill>`.
72
+
73
+ For development against this clone, Claude can still use `claude --plugin-dir .`, and Codex can
74
+ register the local `.agents/plugins/marketplace.json` marketplace.
69
75
 
70
76
  ## Release routine
71
77
 
72
78
  1. Run `node scripts/validate-agent-os.mjs`, `npm test`, its red-case suite, and the live evals in `evals/`.
73
79
  2. Bump `version` in `.claude-plugin/plugin.json`, `.codex-plugin/plugin.json`, and `package.json`.
74
80
  3. Commit with the Git identity configured by the repository or current session, without AI attribution, and push.
75
- 4. Update the plugin on both platforms; verify the new version loaded.
81
+ 4. Pack the npm artifact and verify a clean direct install for both hosts. Publish it, then verify
82
+ `npx @sockulags/agent-os@latest update`; also smoke-test native plugin mode when it changed.
76
83
 
77
84
  ## Documentation site
78
85
 
@@ -98,6 +105,6 @@ name. A skill edit and its documentation page are one change — the pages under
98
105
 
99
106
  ## Global policy
100
107
 
101
- `policy.md` is the source of truth. `init-agent-os global` installs it as a managed block
102
- (`<!-- BEGIN/END AGENT OS -->`) in `~/.claude/CLAUDE.md` and `~/.codex/AGENTS.md` via
103
- `skills/init-agent-os/scripts/policy-block.ps1`. Edit `policy.md`, never the installed blocks.
108
+ `policy.md` is the source of truth. The npm installer and `init-agent-os global` install it as a
109
+ managed block (`<!-- BEGIN/END AGENT OS -->`) in `~/.claude/CLAUDE.md` and
110
+ `~/.codex/AGENTS.md`. Edit `policy.md`, never the installed blocks.
package/cli/index.mjs CHANGED
@@ -1,16 +1,27 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawnSync } from 'node:child_process'
4
+ import { randomUUID } from 'node:crypto'
5
+ import fs from 'node:fs'
6
+ import os from 'node:os'
7
+ import path from 'node:path'
4
8
  import { createInterface } from 'node:readline'
5
9
  import { fileURLToPath, pathToFileURL } from 'node:url'
6
- import fs from 'node:fs'
7
10
 
8
- const packagePath = fileURLToPath(new URL('../package.json', import.meta.url))
11
+ const packageRoot = fileURLToPath(new URL('../', import.meta.url))
12
+ const packagePath = path.join(packageRoot, 'package.json')
9
13
  const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
10
14
 
11
15
  export const VERSION = packageJson.version
12
16
  export const PACKAGE_NAME = packageJson.name
13
17
  export const MARKETPLACE_SOURCE = 'sockulags/agent-os'
18
+ export const INSTALL_MANIFEST = '.agent-os-install.json'
19
+
20
+ const BEGIN_MARKER = '<!-- BEGIN AGENT OS -->'
21
+ const END_MARKER = '<!-- END AGENT OS -->'
22
+ const PLATFORM_VALUES = ['claude', 'codex', 'both']
23
+ const METHOD_VALUES = ['direct', 'plugin']
24
+ const SCOPE_VALUES = ['user', 'project', 'local']
14
25
 
15
26
  export const PLATFORM_CONFIG = Object.freeze({
16
27
  claude: Object.freeze({
@@ -29,13 +40,10 @@ export const PLATFORM_CONFIG = Object.freeze({
29
40
  installArgs: ['plugin', 'marketplace', 'add', MARKETPLACE_SOURCE],
30
41
  refreshArgs: ['plugin', 'marketplace', 'upgrade', 'agent-os'],
31
42
  pluginArgs: () => ['plugin', 'add', 'agent-os@agent-os'],
32
- nextStep: 'Start a new Codex session so the refreshed plugin cache is loaded.'
43
+ nextStep: 'Start a new Codex session so the refreshed plugin is loaded.'
33
44
  })
34
45
  })
35
46
 
36
- const PLATFORM_VALUES = ['claude', 'codex', 'both']
37
- const SCOPE_VALUES = ['user', 'project', 'local']
38
-
39
47
  export class CliError extends Error {}
40
48
 
41
49
  function valueAfter(args, index, flag) {
@@ -53,6 +61,14 @@ function normalizePlatform(value) {
53
61
  return normalized
54
62
  }
55
63
 
64
+ function normalizeMethod(value) {
65
+ const normalized = value.toLowerCase()
66
+ if (!METHOD_VALUES.includes(normalized)) {
67
+ throw new CliError('Method must be direct or plugin.')
68
+ }
69
+ return normalized
70
+ }
71
+
56
72
  function normalizeScope(value) {
57
73
  const normalized = value.toLowerCase()
58
74
  if (!SCOPE_VALUES.includes(normalized)) {
@@ -65,6 +81,7 @@ export function parseArgs(argv) {
65
81
  const result = {
66
82
  command: 'install',
67
83
  platform: null,
84
+ method: null,
68
85
  scope: null,
69
86
  policy: null,
70
87
  yes: false,
@@ -105,6 +122,11 @@ export function parseArgs(argv) {
105
122
  index += 1
106
123
  } else if (argument.startsWith('--platform=')) {
107
124
  result.platform = normalizePlatform(argument.slice('--platform='.length))
125
+ } else if (argument === '--method' || argument === '-m') {
126
+ result.method = normalizeMethod(valueAfter(argv, index, argument))
127
+ index += 1
128
+ } else if (argument.startsWith('--method=')) {
129
+ result.method = normalizeMethod(argument.slice('--method='.length))
108
130
  } else if (argument === '--scope' || argument === '-s') {
109
131
  result.scope = normalizeScope(valueAfter(argv, index, argument))
110
132
  index += 1
@@ -124,10 +146,41 @@ export function selectedPlatforms(platform) {
124
146
  return [platform]
125
147
  }
126
148
 
127
- export function buildPlan({ command, platform, scope = 'user', policy = true }) {
149
+ export function targetSkillRoot(platform, scope, {
150
+ homeDir = os.homedir(),
151
+ cwd = process.cwd()
152
+ } = {}) {
153
+ if (scope === 'user') {
154
+ return platform === 'codex'
155
+ ? path.join(homeDir, '.codex', 'skills')
156
+ : path.join(homeDir, '.claude', 'skills')
157
+ }
158
+ if (scope === 'project') {
159
+ return platform === 'codex'
160
+ ? path.join(cwd, '.agents', 'skills')
161
+ : path.join(cwd, '.claude', 'skills')
162
+ }
163
+ throw new CliError('Local scope is available only with --method plugin.')
164
+ }
165
+
166
+ export function buildPlan(options, pathOptions = {}) {
167
+ const { command, platform, method = 'direct', scope = 'user', policy = true } = options
128
168
  const steps = []
129
169
  for (const name of selectedPlatforms(platform)) {
130
170
  const config = PLATFORM_CONFIG[name]
171
+ if (method === 'direct') {
172
+ const root = targetSkillRoot(name, scope, pathOptions)
173
+ steps.push({
174
+ platform: name,
175
+ kind: command === 'update' ? 'update-skills' : 'install-skills',
176
+ command: 'filesystem',
177
+ args: [root],
178
+ description: (command === 'update' ? 'Update' : 'Install') +
179
+ ' Agent OS managed skills for ' + config.label + '.'
180
+ })
181
+ continue
182
+ }
183
+
131
184
  steps.push({
132
185
  platform: name,
133
186
  kind: 'ensure-marketplace',
@@ -148,7 +201,7 @@ export function buildPlan({ command, platform, scope = 'user', policy = true })
148
201
  kind: 'refresh-marketplace',
149
202
  command: config.command,
150
203
  args: config.refreshArgs,
151
- description: 'Refresh the Agent OS marketplace.'
204
+ description: 'Refresh the Agent OS Git marketplace when applicable.'
152
205
  })
153
206
  }
154
207
  steps.push({
@@ -165,7 +218,7 @@ export function buildPlan({ command, platform, scope = 'user', policy = true })
165
218
  steps.push({
166
219
  platform: 'shared',
167
220
  kind: 'install-policy',
168
- command: 'powershell',
221
+ command: 'node',
169
222
  args: [],
170
223
  description: 'Sync the shared global policy for Claude Code and Codex.'
171
224
  })
@@ -200,6 +253,25 @@ function marketplacePresent(value, marketplaceName) {
200
253
  return Object.values(value).some((item) => marketplacePresent(item, marketplaceName))
201
254
  }
202
255
 
256
+ function marketplaceSourceType(value, marketplaceName) {
257
+ if (Array.isArray(value)) {
258
+ for (const item of value) {
259
+ const result = marketplaceSourceType(item, marketplaceName)
260
+ if (result) return result
261
+ }
262
+ return null
263
+ }
264
+ if (!value || typeof value !== 'object') return null
265
+ if (value.marketplaceName === marketplaceName && value.marketplaceSource?.sourceType) {
266
+ return value.marketplaceSource.sourceType
267
+ }
268
+ for (const item of Object.values(value)) {
269
+ const result = marketplaceSourceType(item, marketplaceName)
270
+ if (result) return result
271
+ }
272
+ return null
273
+ }
274
+
203
275
  function formatCommand(command, args) {
204
276
  return [command, ...args].join(' ')
205
277
  }
@@ -260,13 +332,33 @@ export async function resolveOptions(parsed, {
260
332
  ], dependencies)
261
333
  }
262
334
 
335
+ let method = parsed.method
336
+ if (!method) {
337
+ method = interactive && !parsed.yes
338
+ ? await choose('How should Agent OS be installed?', [
339
+ { value: 'direct', label: 'Direct skills (recommended; no host CLI required)' },
340
+ { value: 'plugin', label: 'Native plugin marketplace' }
341
+ ], dependencies)
342
+ : 'direct'
343
+ }
344
+
263
345
  let scope = parsed.scope || 'user'
264
- if (platform !== 'codex' && !parsed.scope && interactive && !parsed.yes) {
265
- scope = await choose('What Claude Code installation scope should be used?', [
266
- { value: 'user', label: 'User (recommended; available across projects)' },
267
- { value: 'project', label: 'Project (shared through this repository)' },
268
- { value: 'local', label: 'Local (this repository for you only)' }
269
- ], dependencies)
346
+ if (!parsed.scope && interactive && !parsed.yes) {
347
+ if (method === 'direct') {
348
+ scope = await choose('Where should the skill files live?', [
349
+ { value: 'user', label: 'User (recommended; available across projects)' },
350
+ { value: 'project', label: 'Project (stored in this repository)' }
351
+ ], dependencies)
352
+ } else if (platform !== 'codex') {
353
+ scope = await choose('What Claude Code plugin scope should be used?', [
354
+ { value: 'user', label: 'User (recommended; available across projects)' },
355
+ { value: 'project', label: 'Project (shared through this repository)' },
356
+ { value: 'local', label: 'Local (this repository for you only)' }
357
+ ], dependencies)
358
+ }
359
+ }
360
+ if (method === 'direct' && scope === 'local') {
361
+ throw new CliError('Local scope is available only with --method plugin. Use user or project.')
270
362
  }
271
363
 
272
364
  let policy = parsed.policy
@@ -276,43 +368,171 @@ export async function resolveOptions(parsed, {
276
368
  : true
277
369
  }
278
370
 
279
- return { ...parsed, platform, scope, policy }
371
+ return { ...parsed, platform, method, scope, policy }
372
+ }
373
+
374
+ function packagedSkillsPath() {
375
+ return path.join(packageRoot, 'skills')
280
376
  }
281
377
 
282
- function findPowerShell(spawn) {
283
- for (const command of ['pwsh', 'powershell']) {
284
- if (commandExists(command, spawn)) return command
378
+ function packagedPolicyPath() {
379
+ return path.join(packageRoot, 'policy.md')
380
+ }
381
+
382
+ function listPackagedSkills(sourceRoot, fsImpl = fs) {
383
+ if (!fsImpl.existsSync(sourceRoot)) {
384
+ throw new CliError('Packaged skills directory is missing: ' + sourceRoot)
285
385
  }
286
- return null
386
+ const entries = fsImpl.readdirSync(sourceRoot, { withFileTypes: true })
387
+ .filter((entry) => entry.isDirectory() && fsImpl.existsSync(path.join(sourceRoot, entry.name, 'SKILL.md')))
388
+ .map((entry) => entry.name)
389
+ .sort()
390
+ if (entries.length === 0) throw new CliError('No packaged skills were found in ' + sourceRoot)
391
+ return entries
392
+ }
393
+
394
+ function readInstallManifest(root, fsImpl = fs) {
395
+ const manifestPath = path.join(root, INSTALL_MANIFEST)
396
+ if (!fsImpl.existsSync(manifestPath)) return null
397
+ let manifest
398
+ try {
399
+ manifest = JSON.parse(fsImpl.readFileSync(manifestPath, 'utf8'))
400
+ } catch (error) {
401
+ throw new CliError('Cannot read Agent OS install manifest at ' + manifestPath + ': ' + error.message)
402
+ }
403
+ if (manifest.package !== PACKAGE_NAME || !Array.isArray(manifest.skills)) {
404
+ throw new CliError('Refusing to use an unrecognized install manifest at ' + manifestPath)
405
+ }
406
+ return manifest
287
407
  }
288
408
 
289
- function policyScriptPath() {
290
- return fileURLToPath(new URL('../skills/init-agent-os/scripts/policy-block.ps1', import.meta.url))
409
+ function directTargets(options, { homeDir, cwd }) {
410
+ return selectedPlatforms(options.platform).map((platform) => ({
411
+ platform,
412
+ scope: options.scope,
413
+ root: targetSkillRoot(platform, options.scope, { homeDir, cwd })
414
+ }))
291
415
  }
292
416
 
293
- export async function executeInstall(options, {
294
- output = process.stdout,
295
- spawn = spawnSync,
296
- execute = (command, args, runOptions) => runExternal(command, args, { ...runOptions, spawn }),
297
- exists = (command) => commandExists(command, spawn)
298
- } = {}) {
299
- const names = selectedPlatforms(options.platform)
300
- const powershell = options.policy ? findPowerShell(spawn) : null
301
- if (options.policy && !powershell) {
417
+ function preflightDirectTarget(target, skillNames, fsImpl = fs) {
418
+ const manifest = readInstallManifest(target.root, fsImpl)
419
+ const managed = new Set(manifest?.skills || [])
420
+ const conflicts = skillNames.filter((name) => {
421
+ const destination = path.join(target.root, name)
422
+ return fsImpl.existsSync(destination) && !managed.has(name)
423
+ })
424
+ if (conflicts.length > 0) {
302
425
  throw new CliError(
303
- 'PowerShell was not found, so the shared policy could not be synced. ' +
304
- 'Run the policy script manually or rerun with --no-policy.'
426
+ 'Refusing to overwrite unmanaged skills in ' + target.root + ': ' + conflicts.join(', ') +
427
+ '. Move or remove them, then rerun the installer.'
305
428
  )
306
429
  }
307
- for (const name of names) {
308
- const config = PLATFORM_CONFIG[name]
309
- if (!exists(config.command)) {
310
- const installHint = name === 'claude'
311
- ? 'Install Claude Code first: npm install -g @anthropic-ai/claude-code'
312
- : 'Install Codex first: npm install -g @openai/codex'
313
- throw new CliError(config.label + ' CLI was not found on PATH.\n' + installHint)
430
+ return manifest
431
+ }
432
+
433
+ function replaceManagedSkills(target, sourceRoot, skillNames, previousManifest, fsImpl = fs) {
434
+ fsImpl.mkdirSync(target.root, { recursive: true })
435
+ const token = randomUUID()
436
+ const stageRoot = path.join(target.root, '.agent-os-stage-' + token)
437
+ const backupRoot = path.join(target.root, '.agent-os-backup-' + token)
438
+ const previousNames = previousManifest?.skills || []
439
+ const namesToBackup = [...new Set([...previousNames, ...skillNames])]
440
+ .filter((name) => fsImpl.existsSync(path.join(target.root, name)))
441
+ const installed = []
442
+ const backedUp = []
443
+ const manifestPath = path.join(target.root, INSTALL_MANIFEST)
444
+ const previousManifestText = fsImpl.existsSync(manifestPath)
445
+ ? fsImpl.readFileSync(manifestPath, 'utf8')
446
+ : null
447
+
448
+ try {
449
+ fsImpl.mkdirSync(stageRoot, { recursive: true })
450
+ for (const name of skillNames) {
451
+ fsImpl.cpSync(path.join(sourceRoot, name), path.join(stageRoot, name), { recursive: true })
314
452
  }
315
453
 
454
+ if (namesToBackup.length > 0) fsImpl.mkdirSync(backupRoot, { recursive: true })
455
+ for (const name of namesToBackup) {
456
+ fsImpl.renameSync(path.join(target.root, name), path.join(backupRoot, name))
457
+ backedUp.push(name)
458
+ }
459
+
460
+ for (const name of skillNames) {
461
+ fsImpl.renameSync(path.join(stageRoot, name), path.join(target.root, name))
462
+ installed.push(name)
463
+ }
464
+
465
+ const manifest = {
466
+ schemaVersion: 1,
467
+ package: PACKAGE_NAME,
468
+ version: VERSION,
469
+ platform: target.platform,
470
+ scope: target.scope,
471
+ skills: skillNames
472
+ }
473
+ fsImpl.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n')
474
+ } catch (error) {
475
+ for (const name of installed.reverse()) {
476
+ const destination = path.join(target.root, name)
477
+ if (fsImpl.existsSync(destination)) fsImpl.rmSync(destination, { recursive: true, force: true })
478
+ }
479
+ for (const name of backedUp.reverse()) {
480
+ const backup = path.join(backupRoot, name)
481
+ if (fsImpl.existsSync(backup)) fsImpl.renameSync(backup, path.join(target.root, name))
482
+ }
483
+ if (previousManifestText === null) {
484
+ if (fsImpl.existsSync(manifestPath)) fsImpl.rmSync(manifestPath, { force: true })
485
+ } else {
486
+ fsImpl.writeFileSync(manifestPath, previousManifestText)
487
+ }
488
+ throw new CliError('Failed to update managed skills in ' + target.root + ': ' + error.message)
489
+ } finally {
490
+ if (fsImpl.existsSync(stageRoot)) fsImpl.rmSync(stageRoot, { recursive: true, force: true })
491
+ if (fsImpl.existsSync(backupRoot)) fsImpl.rmSync(backupRoot, { recursive: true, force: true })
492
+ }
493
+ }
494
+
495
+ function executeDirect(options, {
496
+ output,
497
+ fsImpl,
498
+ homeDir,
499
+ cwd,
500
+ sourceRoot
501
+ }) {
502
+ const skillNames = listPackagedSkills(sourceRoot, fsImpl)
503
+ const targets = directTargets(options, { homeDir, cwd })
504
+ const manifests = targets.map((target) => preflightDirectTarget(target, skillNames, fsImpl))
505
+
506
+ targets.forEach((target, index) => {
507
+ const config = PLATFORM_CONFIG[target.platform]
508
+ output.write('\n[' + config.label + ']\n')
509
+ output.write((options.command === 'update' ? 'Updating' : 'Installing') +
510
+ ' ' + skillNames.length + ' managed skills in ' + target.root + '...\n')
511
+ replaceManagedSkills(target, sourceRoot, skillNames, manifests[index], fsImpl)
512
+ output.write('Done. Start a new ' + config.label + ' session to load the skills.\n')
513
+ })
514
+ }
515
+
516
+ function isNotGitMarketplace(result) {
517
+ return result.status !== 0 && /not configured as a Git marketplace/i.test(result.stderr || '')
518
+ }
519
+
520
+ function executePlugin(options, { output, execute, exists }) {
521
+ const names = selectedPlatforms(options.platform)
522
+ const missing = names.filter((name) => !exists(PLATFORM_CONFIG[name].command))
523
+ if (missing.length > 0) {
524
+ const details = missing.map((name) => {
525
+ const config = PLATFORM_CONFIG[name]
526
+ const hint = name === 'claude'
527
+ ? 'npm install -g @anthropic-ai/claude-code'
528
+ : 'npm install -g @openai/codex'
529
+ return config.label + ': ' + hint
530
+ })
531
+ throw new CliError('Native plugin mode requires the selected host CLIs:\n' + details.join('\n'))
532
+ }
533
+
534
+ for (const name of names) {
535
+ const config = PLATFORM_CONFIG[name]
316
536
  output.write('\n[' + config.label + ']\n')
317
537
  const listed = execute(config.command, ['plugin', 'marketplace', 'list', '--json'], { capture: true })
318
538
  let registered = false
@@ -331,20 +551,118 @@ export async function executeInstall(options, {
331
551
  }
332
552
 
333
553
  if (options.command === 'update') {
334
- output.write('Refreshing the Agent OS marketplace...\n')
335
- assertSuccess(execute(config.command, config.refreshArgs), config.command, config.refreshArgs)
554
+ let sourceType = null
555
+ if (name === 'codex' && registered) {
556
+ const plugins = execute(config.command, ['plugin', 'list', '--json'], { capture: true })
557
+ if (plugins.status === 0) {
558
+ try {
559
+ sourceType = marketplaceSourceType(JSON.parse(plugins.stdout), config.marketplace)
560
+ } catch {
561
+ sourceType = null
562
+ }
563
+ }
564
+ }
565
+ if (sourceType === 'local') {
566
+ output.write('Local marketplace detected; skipping Git refresh.\n')
567
+ } else {
568
+ output.write('Refreshing the Agent OS marketplace...\n')
569
+ const refreshed = execute(config.command, config.refreshArgs, { capture: name === 'codex' })
570
+ if (isNotGitMarketplace(refreshed)) {
571
+ output.write('Local marketplace detected; skipping Git refresh.\n')
572
+ } else {
573
+ assertSuccess(refreshed, config.command, config.refreshArgs)
574
+ }
575
+ }
336
576
  }
337
577
 
338
578
  const pluginArgs = config.pluginArgs(options.scope)
339
- output.write(options.command === 'update' ? 'Installing the current plugin snapshot...\n' : 'Installing the plugin...\n')
579
+ output.write(options.command === 'update'
580
+ ? 'Installing the current plugin snapshot...\n'
581
+ : 'Installing the plugin...\n')
340
582
  assertSuccess(execute(config.command, pluginArgs), config.command, pluginArgs)
341
583
  output.write('Done. ' + config.nextStep + '\n')
342
584
  }
585
+ }
586
+
587
+ function countOccurrences(content, value) {
588
+ return content.split(value).length - 1
589
+ }
590
+
591
+ export function planPolicyUpdate(content, policy) {
592
+ const normalizedPolicy = policy.trimEnd()
593
+ const block = BEGIN_MARKER + '\n' + normalizedPolicy + '\n' + END_MARKER
594
+ const beginCount = countOccurrences(content, BEGIN_MARKER)
595
+ const endCount = countOccurrences(content, END_MARKER)
596
+
597
+ if (beginCount === 0 && endCount === 0) {
598
+ const separator = content.length === 0 ? '' : content.endsWith('\n') ? '\n' : '\n\n'
599
+ return { changed: true, status: 'ADDED', content: content + separator + block + '\n' }
600
+ }
601
+
602
+ const start = content.indexOf(BEGIN_MARKER)
603
+ const endStart = content.indexOf(END_MARKER)
604
+ if (beginCount !== 1 || endCount !== 1 || start >= endStart) {
605
+ throw new CliError(
606
+ 'Malformed Agent OS policy markers (begin=' + beginCount + ' end=' + endCount + '); no files were changed.'
607
+ )
608
+ }
609
+
610
+ const end = endStart + END_MARKER.length
611
+ const current = content.slice(start, end)
612
+ if (current === block) return { changed: false, status: 'OK', content }
613
+ return {
614
+ changed: true,
615
+ status: 'UPDATED',
616
+ content: content.slice(0, start) + block + content.slice(end)
617
+ }
618
+ }
619
+
620
+ function preparePolicyPlans({ fsImpl, homeDir, policyFile }) {
621
+ const policy = fsImpl.readFileSync(policyFile, 'utf8')
622
+ const targets = [
623
+ path.join(homeDir, '.claude', 'CLAUDE.md'),
624
+ path.join(homeDir, '.codex', 'AGENTS.md')
625
+ ]
626
+ return targets.map((target) => {
627
+ const content = fsImpl.existsSync(target) ? fsImpl.readFileSync(target, 'utf8') : ''
628
+ return { target, ...planPolicyUpdate(content, policy) }
629
+ })
630
+ }
631
+
632
+ function applyPolicyPlans(plans, { output, fsImpl }) {
633
+ for (const plan of plans) {
634
+ if (plan.changed) {
635
+ fsImpl.mkdirSync(path.dirname(plan.target), { recursive: true })
636
+ fsImpl.writeFileSync(plan.target, plan.content)
637
+ }
638
+ output.write(plan.status.padEnd(7) + plan.target + '\n')
639
+ }
640
+ }
641
+
642
+ export async function executeInstall(options, {
643
+ output = process.stdout,
644
+ spawn = spawnSync,
645
+ execute = (command, args, runOptions) => runExternal(command, args, { ...runOptions, spawn }),
646
+ exists = (command) => commandExists(command, spawn),
647
+ fsImpl = fs,
648
+ homeDir = os.homedir(),
649
+ cwd = process.cwd(),
650
+ sourceRoot = packagedSkillsPath(),
651
+ policyFile = packagedPolicyPath()
652
+ } = {}) {
653
+ const policyPlans = options.policy
654
+ ? preparePolicyPlans({ fsImpl, homeDir, policyFile })
655
+ : null
656
+
657
+ if (options.method === 'plugin') {
658
+ executePlugin(options, { output, execute, exists })
659
+ } else {
660
+ executeDirect(options, { output, fsImpl, homeDir, cwd, sourceRoot })
661
+ }
343
662
 
344
663
  if (options.policy) {
345
- const policyArgs = ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', policyScriptPath()]
346
664
  output.write('\n[Shared policy]\nSyncing the global Claude Code and Codex policy files...\n')
347
- assertSuccess(execute(powershell, policyArgs), powershell, policyArgs)
665
+ applyPolicyPlans(policyPlans, { output, fsImpl })
348
666
  }
349
667
  }
350
668
 
@@ -354,10 +672,11 @@ export function printHelp(output = process.stdout) {
354
672
  'Usage:\n' +
355
673
  ' npx ' + PACKAGE_NAME + ' install\n' +
356
674
  ' npx ' + PACKAGE_NAME + ' update\n\n' +
357
- 'Guided install asks where to install Agent OS and whether to sync the shared policy.\n\n' +
675
+ 'Direct installation is the default and does not require Codex or Claude Code CLI.\n\n' +
358
676
  'Options:\n' +
359
677
  ' -p, --platform <name> claude, codex, or both\n' +
360
- ' -s, --scope <name> Claude scope: user, project, or local\n' +
678
+ ' -m, --method <name> direct (default) or plugin\n' +
679
+ ' -s, --scope <name> user or project; plugin mode also supports local\n' +
361
680
  ' --policy Sync ~/.claude/CLAUDE.md and ~/.codex/AGENTS.md\n' +
362
681
  ' --no-policy Leave global policy files unchanged\n' +
363
682
  ' -y, --yes Accept defaults; useful in scripts\n' +
@@ -368,13 +687,14 @@ export function printHelp(output = process.stdout) {
368
687
  ' npx ' + PACKAGE_NAME + ' install\n' +
369
688
  ' npx ' + PACKAGE_NAME + ' install --platform both --yes\n' +
370
689
  ' npx ' + PACKAGE_NAME + ' update --platform codex --no-policy\n' +
690
+ ' npx ' + PACKAGE_NAME + ' install --platform codex --method plugin\n' +
371
691
  ' npm install --global ' + PACKAGE_NAME + '@latest\n'
372
692
  )
373
693
  }
374
694
 
375
- export function printPlan(options, output = process.stdout) {
695
+ export function printPlan(options, output = process.stdout, pathOptions = {}) {
376
696
  output.write('Planned ' + options.command + ':\n')
377
- for (const step of buildPlan(options)) {
697
+ for (const step of buildPlan(options, pathOptions)) {
378
698
  const command = step.args.length ? formatCommand(step.command, step.args) : step.command
379
699
  output.write(' - ' + step.description + ' [' + command + ']\n')
380
700
  }
@@ -392,17 +712,20 @@ export async function run(argv = process.argv.slice(2), dependencies = {}) {
392
712
  }
393
713
  const options = await resolveOptions(parsed, dependencies)
394
714
  if (options.dryRun) {
395
- printPlan(options, dependencies.output || process.stdout)
715
+ printPlan(options, dependencies.output || process.stdout, {
716
+ homeDir: dependencies.homeDir,
717
+ cwd: dependencies.cwd
718
+ })
396
719
  return 0
397
720
  }
398
721
  await executeInstall(options, dependencies)
399
722
  const output = dependencies.output || process.stdout
400
723
  output.write('\nAgent OS ' + options.command + ' completed.\n')
401
- output.write('To update the CLI itself later, use npx ' + PACKAGE_NAME + '@latest or npm install --global ' + PACKAGE_NAME + '@latest.\n')
724
+ output.write('To update later, use npx ' + PACKAGE_NAME + '@latest update.\n')
402
725
  return 0
403
726
  }
404
727
 
405
- if (import.meta.url === pathToFileURL(process.argv[1]).href) {
728
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
406
729
  run().then((code) => {
407
730
  process.exitCode = code
408
731
  }).catch((error) => {