@sockulags/agent-os 0.9.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 ADDED
@@ -0,0 +1,103 @@
1
+ # agent-os
2
+
3
+ A lightweight personal agent operating system — an Agent Skills framework shared between
4
+ Claude Code and Codex. One skill source, two platforms, ceremony proportional to the work.
5
+
6
+ **Documentation: [sockulags.github.io/agent-os](https://sockulags.github.io/agent-os/)**
7
+
8
+ ## Skills
9
+
10
+ Reading order: the planning foundation (`shape-work`, then `chart-work`, which hands off into it),
11
+ the on-ramp in front of both (`guide-me`), the remaining workflows, then the component skills the
12
+ workflows compose (`understand-work`, `explain-work`), the disciplines, and the meta-skill.
13
+
14
+ | Skill | Bucket | Invocation | Purpose |
15
+ |---|---|---|---|
16
+ | `shape-work` | workflow | manual | Turn bounded choices into implementation-ready issues |
17
+ | `chart-work` | workflow | manual | Chart broad work as a parallel graph of decision tickets |
18
+ | `guide-me` | workflow | manual | Guide a vague desire to an approved goal and into planning |
19
+ | `deliver-work` | workflow | manual | Implement one change against boundaries and ground truth |
20
+ | `batch-work` | workflow | manual | Run isolated ready units and verify the integrated result |
21
+ | `dispatch-next` | workflow | manual | Pick or dispatch one action according to the request |
22
+ | `init-agent-os` | workflow | manual | Managed policy setup or repository defaults |
23
+ | `record-lesson` | workflow | manual | Record a durable lesson in repo or global policy |
24
+ | `understand-work` | workflow | manual | Question out the need behind a stated wish |
25
+ | `explain-work` | workflow | manual | Explain the task in plain language for approval |
26
+ | `verify-before-done` | discipline | automatic | Fresh evidence before any completion claim |
27
+ | `diagnose-before-fix` | discipline | automatic | Reproduce and root-cause before patching |
28
+ | `scope-guard` | discipline | automatic | Keep work inside the task; flag drift |
29
+ | `notice-lesson` | discipline | automatic | Treat interruptions as misunderstanding signals |
30
+ | `writing-skills` | meta | manual | Doctrine and definition of done for agent-os skills |
31
+
32
+ Manual skills carry `disable-model-invocation: true` (Claude) and `agents/openai.yaml` with
33
+ `policy.allow_implicit_invocation: false` (Codex). Retired skills move to root `deprecated/`
34
+ (outside the plugin's `skills/`, so they are never distributed).
35
+
36
+ ## Install
37
+
38
+ ### Guided npm installer
39
+
40
+ The recommended setup is a guided command that asks which host to configure and whether to sync
41
+ the shared global policy:
42
+
43
+ ~~~bash
44
+ npx @sockulags/agent-os install
45
+ ~~~
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:
49
+
50
+ ~~~bash
51
+ npx @sockulags/agent-os install --platform both --yes
52
+ ~~~
53
+
54
+ To refresh an existing installation:
55
+
56
+ ~~~bash
57
+ npx @sockulags/agent-os update
58
+ npx @sockulags/agent-os update --platform codex --no-policy
59
+ ~~~
60
+
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.
63
+
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>`.
69
+
70
+ ## Release routine
71
+
72
+ 1. Run `node scripts/validate-agent-os.mjs`, `npm test`, its red-case suite, and the live evals in `evals/`.
73
+ 2. Bump `version` in `.claude-plugin/plugin.json`, `.codex-plugin/plugin.json`, and `package.json`.
74
+ 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.
76
+
77
+ ## Documentation site
78
+
79
+ `docs-site/` is a [VitePress](https://vitepress.dev) site published to GitHub Pages by
80
+ `.github/workflows/docs.yml` on every push to `main` that touches `docs-site/**`.
81
+
82
+ ```bash
83
+ npm --prefix docs-site install
84
+ npm --prefix docs-site run dev
85
+ ```
86
+
87
+ The base path in `docs-site/.vitepress/config.mjs` is `/agent-os/` and must match the repository
88
+ name. A skill edit and its documentation page are one change — the pages under `skills/` and
89
+ `reference/` mirror the skill files and go stale first.
90
+
91
+ ## Evals
92
+
93
+ - `evals/cases/` — versioned trigger and behavior cases plus `manifest.json`, which indexes at least
94
+ 2 positive and 2 negative cases per skill.
95
+ - `evals/RESULTS.md` — historical forward-test results. New results evaluate observable contracts,
96
+ not approval ceremony or reasoning traces.
97
+ - `evals/runs/` — raw logs, gitignored.
98
+
99
+ ## Global policy
100
+
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.
package/cli/index.mjs ADDED
@@ -0,0 +1,412 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process'
4
+ import { createInterface } from 'node:readline'
5
+ import { fileURLToPath, pathToFileURL } from 'node:url'
6
+ import fs from 'node:fs'
7
+
8
+ const packagePath = fileURLToPath(new URL('../package.json', import.meta.url))
9
+ const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'))
10
+
11
+ export const VERSION = packageJson.version
12
+ export const PACKAGE_NAME = packageJson.name
13
+ export const MARKETPLACE_SOURCE = 'sockulags/agent-os'
14
+
15
+ export const PLATFORM_CONFIG = Object.freeze({
16
+ claude: Object.freeze({
17
+ label: 'Claude Code',
18
+ command: 'claude',
19
+ marketplace: 'agent-os-marketplace',
20
+ installArgs: ['plugin', 'marketplace', 'add', MARKETPLACE_SOURCE],
21
+ refreshArgs: ['plugin', 'marketplace', 'update', 'agent-os-marketplace'],
22
+ pluginArgs: (scope) => ['plugin', 'install', 'agent-os@agent-os-marketplace', '--scope', scope],
23
+ nextStep: 'Restart Claude Code or run /reload-plugins.'
24
+ }),
25
+ codex: Object.freeze({
26
+ label: 'Codex',
27
+ command: 'codex',
28
+ marketplace: 'agent-os',
29
+ installArgs: ['plugin', 'marketplace', 'add', MARKETPLACE_SOURCE],
30
+ refreshArgs: ['plugin', 'marketplace', 'upgrade', 'agent-os'],
31
+ pluginArgs: () => ['plugin', 'add', 'agent-os@agent-os'],
32
+ nextStep: 'Start a new Codex session so the refreshed plugin cache is loaded.'
33
+ })
34
+ })
35
+
36
+ const PLATFORM_VALUES = ['claude', 'codex', 'both']
37
+ const SCOPE_VALUES = ['user', 'project', 'local']
38
+
39
+ export class CliError extends Error {}
40
+
41
+ function valueAfter(args, index, flag) {
42
+ const value = args[index + 1]
43
+ if (!value || value.startsWith('-')) throw new CliError(flag + ' requires a value.')
44
+ return value
45
+ }
46
+
47
+ function normalizePlatform(value) {
48
+ const normalized = value.toLowerCase()
49
+ if (normalized === 'claude-code') return 'claude'
50
+ if (!PLATFORM_VALUES.includes(normalized)) {
51
+ throw new CliError('Platform must be claude, codex, or both.')
52
+ }
53
+ return normalized
54
+ }
55
+
56
+ function normalizeScope(value) {
57
+ const normalized = value.toLowerCase()
58
+ if (!SCOPE_VALUES.includes(normalized)) {
59
+ throw new CliError('Scope must be user, project, or local.')
60
+ }
61
+ return normalized
62
+ }
63
+
64
+ export function parseArgs(argv) {
65
+ const result = {
66
+ command: 'install',
67
+ platform: null,
68
+ scope: null,
69
+ policy: null,
70
+ yes: false,
71
+ dryRun: false,
72
+ help: false,
73
+ version: false
74
+ }
75
+
76
+ let index = 0
77
+ if (argv[0] && !argv[0].startsWith('-')) {
78
+ result.command = argv[0].toLowerCase()
79
+ index = 1
80
+ }
81
+
82
+ if (result.command === 'upgrade') result.command = 'update'
83
+ if (!['install', 'update', 'help'].includes(result.command)) {
84
+ throw new CliError('Unknown command "' + result.command + '". Use install or update.')
85
+ }
86
+
87
+ while (index < argv.length) {
88
+ const argument = argv[index]
89
+ if (argument === '--help' || argument === '-h') {
90
+ result.help = true
91
+ } else if (argument === '--version' || argument === '-v') {
92
+ result.version = true
93
+ } else if (argument === '--yes' || argument === '-y') {
94
+ result.yes = true
95
+ } else if (argument === '--dry-run') {
96
+ result.dryRun = true
97
+ } else if (argument === '--policy') {
98
+ if (result.policy === false) throw new CliError('Use only one of --policy and --no-policy.')
99
+ result.policy = true
100
+ } else if (argument === '--no-policy') {
101
+ if (result.policy === true) throw new CliError('Use only one of --policy and --no-policy.')
102
+ result.policy = false
103
+ } else if (argument === '--platform' || argument === '-p') {
104
+ result.platform = normalizePlatform(valueAfter(argv, index, argument))
105
+ index += 1
106
+ } else if (argument.startsWith('--platform=')) {
107
+ result.platform = normalizePlatform(argument.slice('--platform='.length))
108
+ } else if (argument === '--scope' || argument === '-s') {
109
+ result.scope = normalizeScope(valueAfter(argv, index, argument))
110
+ index += 1
111
+ } else if (argument.startsWith('--scope=')) {
112
+ result.scope = normalizeScope(argument.slice('--scope='.length))
113
+ } else {
114
+ throw new CliError('Unknown option "' + argument + '". Use --help for usage.')
115
+ }
116
+ index += 1
117
+ }
118
+
119
+ return result
120
+ }
121
+
122
+ export function selectedPlatforms(platform) {
123
+ if (platform === 'both') return ['claude', 'codex']
124
+ return [platform]
125
+ }
126
+
127
+ export function buildPlan({ command, platform, scope = 'user', policy = true }) {
128
+ const steps = []
129
+ for (const name of selectedPlatforms(platform)) {
130
+ const config = PLATFORM_CONFIG[name]
131
+ steps.push({
132
+ platform: name,
133
+ kind: 'ensure-marketplace',
134
+ command: config.command,
135
+ args: ['plugin', 'marketplace', 'list', '--json'],
136
+ description: 'Check whether the ' + config.label + ' marketplace is registered.'
137
+ })
138
+ steps.push({
139
+ platform: name,
140
+ kind: 'add-marketplace-if-missing',
141
+ command: config.command,
142
+ args: config.installArgs,
143
+ description: 'Register the Agent OS marketplace when it is not present.'
144
+ })
145
+ if (command === 'update') {
146
+ steps.push({
147
+ platform: name,
148
+ kind: 'refresh-marketplace',
149
+ command: config.command,
150
+ args: config.refreshArgs,
151
+ description: 'Refresh the Agent OS marketplace.'
152
+ })
153
+ }
154
+ steps.push({
155
+ platform: name,
156
+ kind: 'install-plugin',
157
+ command: config.command,
158
+ args: config.pluginArgs(scope),
159
+ description: command === 'update'
160
+ ? 'Install the current Agent OS plugin snapshot.'
161
+ : 'Install the Agent OS plugin.'
162
+ })
163
+ }
164
+ if (policy) {
165
+ steps.push({
166
+ platform: 'shared',
167
+ kind: 'install-policy',
168
+ command: 'powershell',
169
+ args: [],
170
+ description: 'Sync the shared global policy for Claude Code and Codex.'
171
+ })
172
+ }
173
+ return steps
174
+ }
175
+
176
+ function commandExists(command, spawn = spawnSync) {
177
+ const lookup = process.platform === 'win32' ? 'where.exe' : 'which'
178
+ const result = spawn(lookup, [command], { stdio: 'ignore' })
179
+ return result.status === 0
180
+ }
181
+
182
+ function runExternal(command, args, { capture = false, spawn = spawnSync } = {}) {
183
+ const options = capture
184
+ ? { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }
185
+ : { stdio: 'inherit' }
186
+ if (process.platform === 'win32') options.shell = true
187
+ const result = spawn(command, args, options)
188
+ return {
189
+ status: result.status ?? 1,
190
+ stdout: result.stdout ?? '',
191
+ stderr: result.stderr ?? '',
192
+ error: result.error
193
+ }
194
+ }
195
+
196
+ function marketplacePresent(value, marketplaceName) {
197
+ if (Array.isArray(value)) return value.some((item) => marketplacePresent(item, marketplaceName))
198
+ if (!value || typeof value !== 'object') return false
199
+ if (value.name === marketplaceName || value.marketplaceName === marketplaceName) return true
200
+ return Object.values(value).some((item) => marketplacePresent(item, marketplaceName))
201
+ }
202
+
203
+ function formatCommand(command, args) {
204
+ return [command, ...args].join(' ')
205
+ }
206
+
207
+ function assertSuccess(result, command, args) {
208
+ if (result.status === 0) return
209
+ const detail = result.error?.message || result.stderr?.trim()
210
+ throw new CliError(
211
+ 'Command failed (' + result.status + '): ' + formatCommand(command, args) +
212
+ (detail ? '\n' + detail : '')
213
+ )
214
+ }
215
+
216
+ async function ask(question, { input, output }) {
217
+ const readline = createInterface({ input, output })
218
+ const answer = await new Promise((resolve) => readline.question(question, resolve))
219
+ readline.close()
220
+ return answer.trim()
221
+ }
222
+
223
+ async function choose(question, choices, dependencies) {
224
+ dependencies.output.write('\n' + question + '\n')
225
+ choices.forEach((choice, index) => {
226
+ dependencies.output.write(' ' + (index + 1) + ') ' + choice.label + '\n')
227
+ })
228
+ while (true) {
229
+ const answer = await ask('Choose 1-' + choices.length + ': ', dependencies)
230
+ const selected = Number.parseInt(answer, 10)
231
+ if (selected >= 1 && selected <= choices.length) return choices[selected - 1].value
232
+ dependencies.output.write('Please choose one of the listed numbers.\n')
233
+ }
234
+ }
235
+
236
+ async function confirm(question, dependencies, defaultValue = true) {
237
+ const suffix = defaultValue ? ' [Y/n] ' : ' [y/N] '
238
+ const answer = (await ask(question + suffix, dependencies)).toLowerCase()
239
+ if (!answer) return defaultValue
240
+ return answer === 'y' || answer === 'yes'
241
+ }
242
+
243
+ export async function resolveOptions(parsed, {
244
+ input = process.stdin,
245
+ output = process.stdout
246
+ } = {}) {
247
+ const dependencies = { input, output }
248
+ const interactive = Boolean(input.isTTY && output.isTTY)
249
+ if (!interactive && !parsed.yes && !parsed.dryRun) {
250
+ throw new CliError('This command needs a terminal or --yes with explicit options.')
251
+ }
252
+
253
+ let platform = parsed.platform
254
+ if (!platform) {
255
+ if (!interactive) throw new CliError('Choose a platform with --platform claude, codex, or both.')
256
+ platform = await choose('Where should Agent OS be installed?', [
257
+ { value: 'codex', label: 'Codex' },
258
+ { value: 'claude', label: 'Claude Code' },
259
+ { value: 'both', label: 'Both' }
260
+ ], dependencies)
261
+ }
262
+
263
+ 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)
270
+ }
271
+
272
+ let policy = parsed.policy
273
+ if (policy === null) {
274
+ policy = interactive && !parsed.yes
275
+ ? await confirm('Also sync the shared global policy files?', dependencies, true)
276
+ : true
277
+ }
278
+
279
+ return { ...parsed, platform, scope, policy }
280
+ }
281
+
282
+ function findPowerShell(spawn) {
283
+ for (const command of ['pwsh', 'powershell']) {
284
+ if (commandExists(command, spawn)) return command
285
+ }
286
+ return null
287
+ }
288
+
289
+ function policyScriptPath() {
290
+ return fileURLToPath(new URL('../skills/init-agent-os/scripts/policy-block.ps1', import.meta.url))
291
+ }
292
+
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) {
302
+ 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.'
305
+ )
306
+ }
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)
314
+ }
315
+
316
+ output.write('\n[' + config.label + ']\n')
317
+ const listed = execute(config.command, ['plugin', 'marketplace', 'list', '--json'], { capture: true })
318
+ let registered = false
319
+ if (listed.status === 0) {
320
+ try {
321
+ registered = marketplacePresent(JSON.parse(listed.stdout), config.marketplace)
322
+ } catch {
323
+ registered = false
324
+ }
325
+ }
326
+ if (!registered) {
327
+ output.write('Registering the Agent OS marketplace...\n')
328
+ assertSuccess(execute(config.command, config.installArgs), config.command, config.installArgs)
329
+ } else {
330
+ output.write('Agent OS marketplace is already registered.\n')
331
+ }
332
+
333
+ if (options.command === 'update') {
334
+ output.write('Refreshing the Agent OS marketplace...\n')
335
+ assertSuccess(execute(config.command, config.refreshArgs), config.command, config.refreshArgs)
336
+ }
337
+
338
+ const pluginArgs = config.pluginArgs(options.scope)
339
+ output.write(options.command === 'update' ? 'Installing the current plugin snapshot...\n' : 'Installing the plugin...\n')
340
+ assertSuccess(execute(config.command, pluginArgs), config.command, pluginArgs)
341
+ output.write('Done. ' + config.nextStep + '\n')
342
+ }
343
+
344
+ if (options.policy) {
345
+ const policyArgs = ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', policyScriptPath()]
346
+ output.write('\n[Shared policy]\nSyncing the global Claude Code and Codex policy files...\n')
347
+ assertSuccess(execute(powershell, policyArgs), powershell, policyArgs)
348
+ }
349
+ }
350
+
351
+ export function printHelp(output = process.stdout) {
352
+ output.write(
353
+ 'Agent OS installer ' + VERSION + '\n\n' +
354
+ 'Usage:\n' +
355
+ ' npx ' + PACKAGE_NAME + ' install\n' +
356
+ ' npx ' + PACKAGE_NAME + ' update\n\n' +
357
+ 'Guided install asks where to install Agent OS and whether to sync the shared policy.\n\n' +
358
+ 'Options:\n' +
359
+ ' -p, --platform <name> claude, codex, or both\n' +
360
+ ' -s, --scope <name> Claude scope: user, project, or local\n' +
361
+ ' --policy Sync ~/.claude/CLAUDE.md and ~/.codex/AGENTS.md\n' +
362
+ ' --no-policy Leave global policy files unchanged\n' +
363
+ ' -y, --yes Accept defaults; useful in scripts\n' +
364
+ ' --dry-run Show the planned flow without running commands\n' +
365
+ ' -h, --help Show this help\n' +
366
+ ' -v, --version Show the CLI version\n\n' +
367
+ 'Examples:\n' +
368
+ ' npx ' + PACKAGE_NAME + ' install\n' +
369
+ ' npx ' + PACKAGE_NAME + ' install --platform both --yes\n' +
370
+ ' npx ' + PACKAGE_NAME + ' update --platform codex --no-policy\n' +
371
+ ' npm install --global ' + PACKAGE_NAME + '@latest\n'
372
+ )
373
+ }
374
+
375
+ export function printPlan(options, output = process.stdout) {
376
+ output.write('Planned ' + options.command + ':\n')
377
+ for (const step of buildPlan(options)) {
378
+ const command = step.args.length ? formatCommand(step.command, step.args) : step.command
379
+ output.write(' - ' + step.description + ' [' + command + ']\n')
380
+ }
381
+ }
382
+
383
+ export async function run(argv = process.argv.slice(2), dependencies = {}) {
384
+ const parsed = parseArgs(argv)
385
+ if (parsed.help || parsed.command === 'help') {
386
+ printHelp(dependencies.output || process.stdout)
387
+ return 0
388
+ }
389
+ if (parsed.version) {
390
+ (dependencies.output || process.stdout).write(VERSION + '\n')
391
+ return 0
392
+ }
393
+ const options = await resolveOptions(parsed, dependencies)
394
+ if (options.dryRun) {
395
+ printPlan(options, dependencies.output || process.stdout)
396
+ return 0
397
+ }
398
+ await executeInstall(options, dependencies)
399
+ const output = dependencies.output || process.stdout
400
+ 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')
402
+ return 0
403
+ }
404
+
405
+ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
406
+ run().then((code) => {
407
+ process.exitCode = code
408
+ }).catch((error) => {
409
+ console.error('Agent OS installer: ' + error.message)
410
+ process.exitCode = 1
411
+ })
412
+ }
@@ -0,0 +1,142 @@
1
+ import assert from 'node:assert/strict'
2
+ import test from 'node:test'
3
+ import { buildPlan, executeInstall, parseArgs, resolveOptions, run } from './index.mjs'
4
+
5
+ test('defaults to guided install', () => {
6
+ assert.deepEqual(parseArgs([]), {
7
+ command: 'install',
8
+ platform: null,
9
+ scope: null,
10
+ policy: null,
11
+ yes: false,
12
+ dryRun: false,
13
+ help: false,
14
+ version: false
15
+ })
16
+ })
17
+
18
+ test('parses non-interactive update flags', () => {
19
+ assert.deepEqual(parseArgs([
20
+ 'update',
21
+ '--platform=both',
22
+ '--scope',
23
+ 'project',
24
+ '--no-policy',
25
+ '--yes'
26
+ ]), {
27
+ command: 'update',
28
+ platform: 'both',
29
+ scope: 'project',
30
+ policy: false,
31
+ yes: true,
32
+ dryRun: false,
33
+ help: false,
34
+ version: false
35
+ })
36
+ })
37
+
38
+ test('supports Claude Code as a platform alias and upgrade as update', () => {
39
+ assert.deepEqual(parseArgs(['upgrade', '--platform', 'claude-code', '--yes']), {
40
+ command: 'update',
41
+ platform: 'claude',
42
+ scope: null,
43
+ policy: null,
44
+ yes: true,
45
+ dryRun: false,
46
+ help: false,
47
+ version: false
48
+ })
49
+ })
50
+
51
+ test('prints scoped npm commands while preserving the agent-os binary name', async () => {
52
+ const chunks = []
53
+ await run(['--help'], { output: { write: (chunk) => chunks.push(chunk) } })
54
+ const help = chunks.join('')
55
+ assert.match(help, /npx @sockulags\/agent-os install/)
56
+ assert.match(help, /npm install --global @sockulags\/agent-os@latest/)
57
+ })
58
+
59
+ test('rejects conflicting policy flags', () => {
60
+ assert.throws(() => parseArgs(['install', '--policy', '--no-policy']), /one of --policy and --no-policy/)
61
+ })
62
+
63
+ test('requires explicit non-interactive choices', async () => {
64
+ await assert.rejects(
65
+ resolveOptions(parseArgs(['install']), {
66
+ input: { isTTY: false },
67
+ output: { isTTY: false }
68
+ }),
69
+ /--yes with explicit options/
70
+ )
71
+ })
72
+
73
+ test('builds a Codex install plan without policy mutation', () => {
74
+ const plan = buildPlan({
75
+ command: 'install',
76
+ platform: 'codex',
77
+ scope: 'user',
78
+ policy: false
79
+ })
80
+ assert.deepEqual(plan.map((step) => step.kind), [
81
+ 'ensure-marketplace',
82
+ 'add-marketplace-if-missing',
83
+ 'install-plugin'
84
+ ])
85
+ assert.deepEqual(plan.at(-1).args, ['plugin', 'add', 'agent-os@agent-os'])
86
+ })
87
+
88
+ test('reports a missing host before running installation commands', async () => {
89
+ const calls = []
90
+ await assert.rejects(
91
+ executeInstall({
92
+ command: 'install',
93
+ platform: 'codex',
94
+ scope: 'user',
95
+ policy: false
96
+ }, {
97
+ output: { write() {} },
98
+ exists: () => false,
99
+ execute: (...args) => calls.push(args)
100
+ }),
101
+ /Codex CLI was not found on PATH/
102
+ )
103
+ assert.deepEqual(calls, [])
104
+ })
105
+
106
+ test('updates both platforms and syncs policy through the host CLIs', async () => {
107
+ const calls = []
108
+ const output = { write() {} }
109
+ await executeInstall({
110
+ command: 'update',
111
+ platform: 'both',
112
+ scope: 'user',
113
+ policy: true
114
+ }, {
115
+ output,
116
+ exists: () => true,
117
+ spawn: () => ({ status: 0 }),
118
+ execute: (command, args, options = {}) => {
119
+ calls.push({ command, args, options })
120
+ if (options.capture) {
121
+ return {
122
+ status: 0,
123
+ stdout: JSON.stringify({ marketplaces: [] }),
124
+ stderr: ''
125
+ }
126
+ }
127
+ return { status: 0, stdout: '', stderr: '' }
128
+ }
129
+ })
130
+
131
+ assert.deepEqual(calls.map((call) => [call.command, call.args]), [
132
+ ['claude', ['plugin', 'marketplace', 'list', '--json']],
133
+ ['claude', ['plugin', 'marketplace', 'add', 'sockulags/agent-os']],
134
+ ['claude', ['plugin', 'marketplace', 'update', 'agent-os-marketplace']],
135
+ ['claude', ['plugin', 'install', 'agent-os@agent-os-marketplace', '--scope', 'user']],
136
+ ['codex', ['plugin', 'marketplace', 'list', '--json']],
137
+ ['codex', ['plugin', 'marketplace', 'add', 'sockulags/agent-os']],
138
+ ['codex', ['plugin', 'marketplace', 'upgrade', 'agent-os']],
139
+ ['codex', ['plugin', 'add', 'agent-os@agent-os']],
140
+ ['pwsh', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', calls.at(-1)?.args?.at(-1)]]
141
+ ])
142
+ })
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@sockulags/agent-os",
3
+ "version": "0.9.0",
4
+ "description": "A lightweight personal agent operating system with an npx installer for Claude Code and Codex.",
5
+ "type": "module",
6
+ "bin": {
7
+ "agent-os": "./cli/index.mjs"
8
+ },
9
+ "files": [
10
+ "cli/",
11
+ "policy.md",
12
+ "skills/init-agent-os/scripts/policy-block.ps1"
13
+ ],
14
+ "engines": {
15
+ "node": ">=18.18"
16
+ },
17
+ "scripts": {
18
+ "test": "node --test cli/*.test.mjs",
19
+ "validate": "node scripts/validate-agent-os.mjs"
20
+ },
21
+ "keywords": [
22
+ "agent",
23
+ "claude-code",
24
+ "codex",
25
+ "workflow",
26
+ "skills",
27
+ "installer"
28
+ ],
29
+ "homepage": "https://sockulags.github.io/agent-os/",
30
+ "repository": "https://github.com/sockulags/agent-os"
31
+ }
package/policy.md ADDED
@@ -0,0 +1,45 @@
1
+ # Agent OS — global policy
2
+
3
+ Source of truth for the managed policy block installed into `~/.claude/CLAUDE.md` and
4
+ `~/.codex/AGENTS.md` by `init-agent-os global`. Edit here, never inside the installed blocks.
5
+
6
+ ## Core policy
7
+
8
+ Priority order when instructions conflict:
9
+
10
+ 1. Direct user instruction in the current session.
11
+ 2. The repo's project policy and nearest `CLAUDE.md`/`AGENTS.md`.
12
+ 3. The active explicit workflow (an invoked agent-os skill).
13
+ 4. This global policy.
14
+
15
+ Rules:
16
+
17
+ - Authority follows the request: an inspection, planning, or review request is read-only apart from
18
+ the requested artifact; an implementation request authorizes repository changes inside its scope.
19
+ Merging, deploying, destructive cleanup, and effects on external systems or people require the
20
+ direct request or project policy to include them.
21
+ - Evidence before claims: verify before calling anything done, and show how it was verified.
22
+ - Keep scope and diffs narrow; when work drifts beyond the task, flag it instead of building on.
23
+ - Escalate only product decisions that cannot be resolved from context and would materially change
24
+ the outcome. Make reversible implementation choices and report them.
25
+ - Use the Git identity configured by the repository or current session. Never add AI attribution or `Co-Authored-By` trailers.
26
+ - Respond in the language used by the user. Code, commits, and technical artifacts are English unless the project says otherwise.
27
+ - Lead with the outcome: the first sentence answers "what happened" or "what did you find". Supporting detail comes after.
28
+ - Readable beats brief: shorten by leaving out what does not change the reader's next step, not by compressing language. Full sentences; no arrow chains, fragment style, or invented shorthand the reader must decode.
29
+ - Never force the reader to cross-reference labels or numbering invented earlier in the text — say what you mean in place.
30
+ - Explanations belong in prose; tables only for short enumerable facts.
31
+ - Calibrate tone to the topic: playfulness is fine, neutral and factual the moment the subject is serious. When in doubt, it is serious.
32
+ - Orchestration is opt-in: `/agent-os:guide-me`, `/agent-os:chart-work`, `/agent-os:shape-work`,
33
+ `/agent-os:batch-work`, `/agent-os:deliver-work`, `/agent-os:dispatch-next`,
34
+ `/agent-os:init-agent-os`, `/agent-os:understand-work`, `/agent-os:explain-work`,
35
+ `/agent-os:record-lesson` exist for planned work; never self-invoke them. One exception: a
36
+ workflow may continue into the workflow its exit contract names once the developer approves that
37
+ exit, as `guide-me` does after its approved plain-language gate.
38
+
39
+ ## Preferences (seed defaults — project policy overrides)
40
+
41
+ - UI feedback under ~250 ms; feedback must not block the next interaction.
42
+ - Own design identity; do not imitate the look of well-known apps.
43
+ - Every repo keeps a living project policy (planning surface, design system location, verify
44
+ commands, conventions, gotchas, and delivery defaults). It grows over time; `init-agent-os`
45
+ seeds it and `record-lesson` grows it.
@@ -0,0 +1,87 @@
1
+ # Manages the AGENT OS block in global instruction files.
2
+ # Source of truth: policy.md at the plugin root (two levels up from this script).
3
+ #
4
+ # Semantics (locked in the agent-os plan, M3):
5
+ # - No block in target -> append exactly one block, preserve everything else.
6
+ # - Empty target file -> treated as "no block"; the block becomes the whole file.
7
+ # - Exactly one well-formed -> replace only the content between the markers.
8
+ # - Duplicated, crossed, or half-open markers -> abort without mutation, exit 2.
9
+ # - -Check -> read-only; exit 0 in sync, exit 1 on drift/missing, never writes.
10
+ # - Text outside the block is never touched or normalized.
11
+
12
+ [CmdletBinding()]
13
+ param(
14
+ [switch]$Check,
15
+ [string[]]$Targets = @(
16
+ (Join-Path (Join-Path $HOME '.claude') 'CLAUDE.md'),
17
+ (Join-Path (Join-Path $HOME '.codex') 'AGENTS.md')
18
+ )
19
+ )
20
+
21
+ $ErrorActionPreference = 'Stop'
22
+ $BeginMarker = '<!-- BEGIN AGENT OS -->'
23
+ $EndMarker = '<!-- END AGENT OS -->'
24
+
25
+ $policyPath = Join-Path $PSScriptRoot '..\..\..\policy.md' | Resolve-Path
26
+ $policy = (Get-Content -Raw -Path $policyPath).TrimEnd()
27
+ $block = "$BeginMarker`n$policy`n$EndMarker"
28
+
29
+ $exit = 0
30
+
31
+ foreach ($target in $Targets) {
32
+ $label = $target
33
+ if (-not (Test-Path $target)) {
34
+ if ($Check) {
35
+ Write-Output "DRIFT $label : file missing"
36
+ $exit = 1
37
+ } else {
38
+ $dir = Split-Path $target
39
+ if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
40
+ Set-Content -NoNewline -Path $target -Value ($block + "`n")
41
+ Write-Output "ADDED $label : created file with managed block"
42
+ }
43
+ continue
44
+ }
45
+
46
+ # An empty file returns $null from -Raw, which would throw in Matches below.
47
+ $content = Get-Content -Raw -Path $target
48
+ if ($null -eq $content) { $content = '' }
49
+ $beginCount = ([regex]::Matches($content, [regex]::Escape($BeginMarker))).Count
50
+ $endCount = ([regex]::Matches($content, [regex]::Escape($EndMarker))).Count
51
+
52
+ if ($beginCount -eq 0 -and $endCount -eq 0) {
53
+ if ($Check) {
54
+ Write-Output "DRIFT $label : managed block missing"
55
+ $exit = 1
56
+ } else {
57
+ $sep = if ($content.Length -eq 0) { '' } elseif ($content.EndsWith("`n")) { "`n" } else { "`n`n" }
58
+ Set-Content -NoNewline -Path $target -Value ($content + $sep + $block + "`n")
59
+ Write-Output "ADDED $label : appended managed block"
60
+ }
61
+ continue
62
+ }
63
+
64
+ $wellFormed = ($beginCount -eq 1 -and $endCount -eq 1 -and
65
+ $content.IndexOf($BeginMarker) -lt $content.IndexOf($EndMarker))
66
+ if (-not $wellFormed) {
67
+ Write-Output "ERROR $label : malformed markers (begin=$beginCount end=$endCount) - no mutation"
68
+ exit 2
69
+ }
70
+
71
+ $start = $content.IndexOf($BeginMarker)
72
+ $end = $content.IndexOf($EndMarker) + $EndMarker.Length
73
+ $current = $content.Substring($start, $end - $start)
74
+
75
+ if ($current -eq $block) {
76
+ Write-Output "OK $label : in sync"
77
+ } elseif ($Check) {
78
+ Write-Output "DRIFT $label : block differs from policy.md"
79
+ $exit = 1
80
+ } else {
81
+ $updated = $content.Substring(0, $start) + $block + $content.Substring($end)
82
+ Set-Content -NoNewline -Path $target -Value $updated
83
+ Write-Output "UPDATED $label : block replaced from policy.md"
84
+ }
85
+ }
86
+
87
+ exit $exit