@sockulags/agent-os 0.14.0 → 0.16.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.
Files changed (101) hide show
  1. package/README.md +102 -49
  2. package/cli/doctor.mjs +307 -0
  3. package/cli/index.mjs +328 -151
  4. package/cli/index.test.mjs +406 -9
  5. package/package.json +5 -6
  6. package/plugins/agent-os-core/.claude-plugin/plugin.json +18 -0
  7. package/plugins/agent-os-core/.codex-plugin/plugin.json +24 -0
  8. package/plugins/agent-os-core/skills/capture-intent/SKILL.md +65 -0
  9. package/plugins/agent-os-core/skills/capture-intent/references/intent-template.md +47 -0
  10. package/plugins/agent-os-core/skills/explain-work/SKILL.md +42 -0
  11. package/{skills → plugins/agent-os-core/skills}/list-skills/SKILL.md +13 -6
  12. package/{skills → plugins/agent-os-core/skills}/plain-voice/SKILL.md +7 -4
  13. package/plugins/agent-os-core/skills/plan-work/SKILL.md +133 -0
  14. package/plugins/agent-os-core/skills/plan-work/references/elicitation.md +32 -0
  15. package/plugins/agent-os-core/skills/plan-work/references/map.md +108 -0
  16. package/plugins/agent-os-core/skills/plan-work/references/spec-template.md +64 -0
  17. package/plugins/agent-os-core/skills/record-lesson/SKILL.md +47 -0
  18. package/plugins/agent-os-core/skills/scope-guard/SKILL.md +53 -0
  19. package/{skills → plugins/agent-os-core/skills}/verify-before-done/SKILL.md +6 -2
  20. package/plugins/agent-os-dev/.claude-plugin/plugin.json +18 -0
  21. package/plugins/agent-os-dev/.codex-plugin/plugin.json +24 -0
  22. package/plugins/agent-os-dev/hooks/hooks.json +42 -0
  23. package/{skills → plugins/agent-os-dev/skills}/batch-work/SKILL.md +9 -4
  24. package/{skills → plugins/agent-os-dev/skills}/batch-work/references/manifest.md +8 -0
  25. package/{skills → plugins/agent-os-dev/skills}/check-work/SKILL.md +31 -14
  26. package/{skills/deliver-work/workflow.md → plugins/agent-os-dev/skills/deliver-work/SKILL.md} +85 -17
  27. package/plugins/agent-os-dev/skills/design-work/SKILL.md +145 -0
  28. package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.mjs +233 -0
  29. package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.test.mjs +73 -0
  30. package/plugins/agent-os-dev/skills/diagnose-before-fix/SKILL.md +29 -0
  31. package/{skills → plugins/agent-os-dev/skills}/dispatch-next/SKILL.md +10 -4
  32. package/plugins/agent-os-dev/skills/init-agent-os/SKILL.md +121 -0
  33. package/plugins/agent-os-dev/skills/init-agent-os/policy.md +88 -0
  34. package/plugins/agent-os-dev/skills/init-agent-os/references/guards.md +39 -0
  35. package/{skills → plugins/agent-os-dev/skills}/init-agent-os/references/repository-init.md +41 -9
  36. package/plugins/agent-os-dev/skills/init-agent-os/references/review-template.md +35 -0
  37. package/plugins/agent-os-dev/skills/init-agent-os/scripts/policy-block.mjs +187 -0
  38. package/plugins/agent-os-dev/skills/init-agent-os/templates/agent-review.yml +59 -0
  39. package/plugins/agent-os-dev/skills/init-agent-os/templates/lint-intents.yml +30 -0
  40. package/{skills → plugins/agent-os-dev/skills}/proportional-testing/SKILL.md +1 -1
  41. package/plugins/agent-os-dev/skills/quality-ratchet/SKILL.md +103 -0
  42. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/project-controls.md +31 -3
  43. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.mjs +145 -0
  44. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.test.mjs +158 -0
  45. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.mjs +372 -0
  46. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.test.mjs +138 -0
  47. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.mjs +322 -0
  48. package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.test.mjs +172 -0
  49. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.mjs +59 -8
  50. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.test.mjs +134 -8
  51. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.mjs +296 -22
  52. package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.test.mjs +114 -6
  53. package/plugins/agent-os-dev/skills/shape-work/SKILL.md +124 -0
  54. package/plugins/agent-os-dev/skills/shape-work/references/implementation-issues.md +143 -0
  55. package/{skills/chart-work → plugins/agent-os-dev/skills/shape-work}/references/prototypes.md +11 -13
  56. package/plugins/agent-os-dev/skills/simplify/SKILL.md +91 -0
  57. package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.mjs +166 -0
  58. package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.test.mjs +49 -0
  59. package/policy.md +53 -20
  60. package/hooks/hooks.json +0 -17
  61. package/skills/chart-work/SKILL.md +0 -42
  62. package/skills/chart-work/references/elicitation.md +0 -25
  63. package/skills/chart-work/references/map.md +0 -84
  64. package/skills/deliver-work/SKILL.md +0 -12
  65. package/skills/diagnose-before-fix/SKILL.md +0 -24
  66. package/skills/explain-work/SKILL.md +0 -27
  67. package/skills/guide-me/SKILL.md +0 -36
  68. package/skills/init-agent-os/SKILL.md +0 -54
  69. package/skills/init-agent-os/scripts/policy-block.ps1 +0 -87
  70. package/skills/notice-lesson/SKILL.md +0 -20
  71. package/skills/quality-ratchet/SKILL.md +0 -72
  72. package/skills/record-lesson/SKILL.md +0 -31
  73. package/skills/scope-guard/SKILL.md +0 -32
  74. package/skills/shape-work/SKILL.md +0 -48
  75. package/skills/shape-work/references/implementation-issues.md +0 -69
  76. package/skills/shape-work/references/mockups.md +0 -23
  77. package/skills/simplifier/SKILL.md +0 -35
  78. package/skills/simplifier/agents/openai.yaml +0 -2
  79. package/skills/simplifier-audit/SKILL.md +0 -30
  80. package/skills/simplifier-review/SKILL.md +0 -40
  81. package/skills/understand-work/SKILL.md +0 -31
  82. package/skills/understand-work/agents/openai.yaml +0 -2
  83. package/skills/writing-skills/SKILL.md +0 -68
  84. package/skills/writing-skills/agents/openai.yaml +0 -2
  85. /package/{skills/batch-work → plugins/agent-os-core/skills/capture-intent}/agents/openai.yaml +0 -0
  86. /package/{skills/chart-work → plugins/agent-os-core/skills/explain-work}/agents/openai.yaml +0 -0
  87. /package/{skills/deliver-work → plugins/agent-os-core/skills/list-skills}/agents/openai.yaml +0 -0
  88. /package/{skills → plugins/agent-os-core/skills}/plain-voice/references/tells.md +0 -0
  89. /package/{skills/dispatch-next → plugins/agent-os-core/skills/plan-work}/agents/openai.yaml +0 -0
  90. /package/{skills/explain-work → plugins/agent-os-dev/skills/batch-work}/agents/openai.yaml +0 -0
  91. /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/manifest-hash.mjs +0 -0
  92. /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/test-manifest-hash.mjs +0 -0
  93. /package/{skills → plugins/agent-os-dev/skills}/check-work/references/findings.md +0 -0
  94. /package/{skills/guide-me → plugins/agent-os-dev/skills/deliver-work}/agents/openai.yaml +0 -0
  95. /package/{skills/init-agent-os → plugins/agent-os-dev/skills/design-work}/agents/openai.yaml +0 -0
  96. /package/{skills/list-skills → plugins/agent-os-dev/skills/dispatch-next}/agents/openai.yaml +0 -0
  97. /package/{skills/record-lesson → plugins/agent-os-dev/skills/init-agent-os}/agents/openai.yaml +0 -0
  98. /package/{skills → plugins/agent-os-dev/skills}/proportional-testing/references/strategy.md +0 -0
  99. /package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/structure.md +0 -0
  100. /package/{skills → plugins/agent-os-dev/skills}/shape-work/agents/openai.yaml +0 -0
  101. /package/{skills/simplifier-audit → plugins/agent-os-dev/skills/simplify}/agents/openai.yaml +0 -0
package/README.md CHANGED
@@ -1,66 +1,80 @@
1
1
  # agent-os
2
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.
3
+ A lightweight agent operating system: Agent Skills shared between Claude Code and Codex, with
4
+ ceremony proportional to the work. It ships as two packages from one source:
5
+
6
+ - **`agent-os-core`** (`plugins/agent-os-core`) holds intent, planning, explanation, scope, evidence,
7
+ and lesson skills. It is useful for product, documentation, and analysis work as well as code.
8
+ - **`agent-os-dev`** (`plugins/agent-os-dev`) holds delivery, review, testing, simplification, and
9
+ setup skills plus the hooks that enforce them. It requires `agent-os-core`.
5
10
 
6
11
  **Documentation: [sockulags.github.io/agent-os](https://sockulags.github.io/agent-os/)**
7
12
 
8
13
  ## Skills
9
14
 
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 skills.
15
+ Decisions that outlive a session live in versioned files: `intents/<id>/intent.md` for what is needed
16
+ and why, `spec.md` for behavior, boundaries, and ground truth, and `plan.md` for delivery units. A
17
+ small fix needs none of them. See the
18
+ [intent file reference](https://sockulags.github.io/agent-os/reference/intents).
19
+
20
+ ### agent-os-core
13
21
 
14
22
  | Skill | Bucket | Invocation | Purpose |
15
23
  |---|---|---|---|
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 |
24
+ | `capture-intent` | workflow | manual | Capture the need behind a wish as a versioned intent |
25
+ | `plan-work` | workflow | manual | Plan a mission and write it as a versioned spec |
26
+ | `explain-work` | workflow | manual | Explain or shorten work in plain language |
27
+ | `list-skills` | meta | manual | List installed skills and how to invoke them |
28
+ | `scope-guard` | discipline | automatic | Keep work inside the task; flag drift |
29
+ | `verify-before-done` | discipline | automatic | Fresh evidence before any completion claim |
30
+ | `plain-voice` | discipline | automatic | Apply plain voice to documentation, commits, and pull request text |
31
+ | `record-lesson` | discipline | automatic | Notice a correction and record the durable lesson behind it |
32
+
33
+ ### agent-os-dev
34
+
35
+ | Skill | Bucket | Invocation | Purpose |
36
+ |---|---|---|---|
37
+ | `design-work` | workflow | manual | Sketch new and changed screens in the project's chosen medium before delivery |
38
+ | `shape-work` | workflow | manual | Shape a spec into delivery units in plan.md or tracker issues |
39
+ | `deliver-work` | workflow | manual | Deliver one unit against its contract and claim it with a draft pull request |
20
40
  | `batch-work` | workflow | manual | Run isolated ready units and verify the integrated result |
21
41
  | `dispatch-next` | workflow | manual | Pick or dispatch one action according to the request |
42
+ | `simplify` | workflow | manual | Review, audit, or remove unnecessary code and solution layers |
22
43
  | `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
- | `simplifier` | workflow | manual | Remove unnecessary code and solution layers |
25
- | `simplifier-audit` | workflow | manual | Audit a repository for simplification opportunities |
26
44
  | `check-work` | workflow | automatic | Independently review a candidate and report or fix supported findings |
27
- | `understand-work` | workflow | manual | Question out the need behind a stated wish |
28
- | `explain-work` | workflow | manual | Explain the task in plain language for approval |
29
- | `verify-before-done` | discipline | automatic | Fresh evidence before any completion claim |
30
45
  | `diagnose-before-fix` | discipline | automatic | Reproduce and root-cause before patching |
31
46
  | `proportional-testing` | discipline | automatic | Minimum meaningful regression coverage |
32
- | `scope-guard` | discipline | automatic | Keep work inside the task; flag drift |
33
- | `simplifier-review` | discipline | automatic | Review a diff for unnecessary complexity |
34
47
  | `quality-ratchet` | discipline | automatic | Compare exact entry and candidate evidence without score gates |
35
- | `notice-lesson` | discipline | automatic | Treat interruptions as misunderstanding signals |
36
- | `plain-voice` | discipline | automatic | Apply plain voice to every agent-authored text response |
37
- | `list-skills` | meta | manual | List installed skills and how to invoke them |
38
- | `writing-skills` | meta | manual | Doctrine and definition of done for agent-os skills |
39
48
 
40
49
  Manual skills carry `disable-model-invocation: true` (Claude) and `agents/openai.yaml` with
41
50
  `policy.allow_implicit_invocation: false` (Codex). Automatic skills carry neither gate; their
42
- descriptions define when they trigger, and they may still be explicitly named. Retired skills move to root `deprecated/`
43
- (outside the plugin's `skills/`, so they are never distributed).
51
+ descriptions define when they trigger, and they may still be explicitly named. Retired skills move to
52
+ root `deprecated/`, outside both plugin roots, so they are never distributed. The maintainer doctrine
53
+ for writing skills lives in `.agents/skills/writing-skills` and is not distributed either.
44
54
 
45
55
  ## Install
46
56
 
47
57
  ### Guided npm installer
48
58
 
49
- The recommended setup is a guided command that asks which host skill directories to configure and
50
- whether to sync the shared global policy:
59
+ The recommended setup is a guided command that asks which host skill directories to configure,
60
+ which packages to install, and whether to sync the shared global policy:
51
61
 
52
62
  ~~~bash
53
63
  npx @sockulags/agent-os install
54
64
  ~~~
55
65
 
56
66
  It supports Codex, Claude Code, or both without requiring either host CLI. By default it copies the
57
- packaged skills into the selected user-level directories (`~/.codex/skills` and/or
67
+ skills of both packages into the selected user-level directories (`~/.codex/skills` and/or
58
68
  `~/.claude/skills`). For a non-interactive install, make the choices explicit:
59
69
 
60
70
  ~~~bash
61
71
  npx @sockulags/agent-os install --platform both --scope user --yes
72
+ npx @sockulags/agent-os install --platform claude --package core --yes
62
73
  ~~~
63
74
 
75
+ `--package all` (the default) installs core and dev; `--package core` installs only the core skills,
76
+ adds no hooks, and installs the global policy without its development section.
77
+
64
78
  To refresh an existing installation:
65
79
 
66
80
  ~~~bash
@@ -69,44 +83,80 @@ npx @sockulags/agent-os update --platform codex --no-policy
69
83
  ~~~
70
84
 
71
85
  Updates replace only skill directories recorded in `.agent-os-install.json` and preserve unrelated
72
- skills. Use `--scope project` to install into the current project's skill directories. The first
73
- command always downloads the current npm CLI; use `npx @sockulags/agent-os@latest update` to force
74
- the newest published installer.
75
-
76
- Direct Claude skills appear as `/<skill>` and direct Codex skills as `$<skill>`. Direct installation
77
- also merges the managed quality-ratchet `Stop` hook into the selected host configuration without
78
- replacing unrelated hooks. The user and project paths are `~/.claude/settings.json` or
79
- `<project>/.claude/settings.json` for Claude Code, and `~/.codex/hooks.json` or
80
- `<project>/.codex/hooks.json` for Codex. Node must be available to native plugin hooks. The
81
- packaged hook keeps one logical command source: Claude and Unix-like Codex use
86
+ skills. Retired skills recorded there are removed. Use `--scope project` to install into the current
87
+ project's skill directories. The first command always downloads the current npm CLI; use
88
+ `npx @sockulags/agent-os@latest update` to force the newest published installer.
89
+
90
+ Direct Claude skills appear as `/<skill>` and direct Codex skills as `$<skill>`.
91
+
92
+ ### Hooks
93
+
94
+ With agent-os-dev, direct installation merges three managed hooks into the selected host
95
+ configuration without replacing unrelated hooks: the quality-ratchet `Stop` gate and the
96
+ `SessionStart` and `PreToolUse` guard hooks. The user and project paths are
97
+ `~/.claude/settings.json` or `<project>/.claude/settings.json` for Claude Code, and
98
+ `~/.codex/hooks.json` or `<project>/.codex/hooks.json` for Codex. Plugin installs load the same hooks
99
+ from `plugins/agent-os-dev/hooks/hooks.json`. Node must be available to native plugin hooks. The
100
+ packaged hooks keep one logical command source: Claude and Unix-like Codex use
82
101
  `${CLAUDE_PLUGIN_ROOT}`, while Windows Codex uses a quote-free `commandWindows` with a UTF-16LE
83
102
  PowerShell `-EncodedCommand` payload that resolves `$env:PLUGIN_ROOT` at runtime.
84
103
 
104
+ The guard hooks read `.agent-os/guards.json` and do nothing where it is absent. They name the intent
105
+ behind the current branch and any stale spec or plan at session start, and block edits to protected
106
+ paths, edits to accepted intents and specs during delivery, edits to a test locked with
107
+ `guards.mjs lock-test`, and a `git commit` that adds a likely secret. They never run a command the
108
+ repository declares. See the [guard hook reference](https://sockulags.github.io/agent-os/reference/guards).
109
+
85
110
  The ratchet begins an exact worktree- and host-session-local baseline before the first mutation when `deliver-work`
86
- can run it, checks the candidate before `simplifier-review`, and reports source-file/NLOC,
111
+ can run it, checks the candidate before `simplify` review mode, and reports source-file/NLOC,
87
112
  legacy-before/after, dependency, and optional-analyzer evidence. These are signals for semantic
88
- judgment, not score or raw-count thresholds. Missing Lizard or jscpd is reported as unavailable,
89
- never clean. A Stop hook blocks a missing, corrupt, or stale active lifecycle check until the same
90
- host session records a fresh check; `stop_hook_active` does not bypass that requirement. Without a
113
+ judgment, not score or raw-count thresholds. With lizard installed it adds cyclomatic complexity
114
+ before and after for touched functions; missing lizard is reported as unavailable, never clean. A Stop hook blocks a missing, corrupt, or stale active lifecycle check until the same
115
+ host session records a fresh check. Declare the delivery ground truth as a `required` check in
116
+ `.agent-os/quality.json`; it runs only after the developer trusts the repository's controls. A
117
+ passing check lets the turn end and keeps the baseline, so a
118
+ delivery that pauses to ask the developer still compares against the exact entry state; `finish`
119
+ closes the baseline only after a passing check. Every block except corrupt state is bounded: after
120
+ three re-entries on the unchanged candidate the hook releases the stop to the user and keeps delivery
121
+ blocked. Without a
91
122
  baseline for the current host session it is a no-op. Resolve
92
123
  `scripts/quality-delta.mjs` relative to the installed `quality-ratchet/SKILL.md` and run its `clear`
93
124
  command from that same host session to abandon an active attempt. Standalone/manual use without a
94
- host session ID uses a deterministic fallback state. `begin`, `check`, and `clear` read the host ID
125
+ host session ID uses a deterministic fallback state. `begin`, `check`, `finish`, and `clear` read the host ID
95
126
  from `CODEX_THREAD_ID` or `CLAUDE_CODE_SESSION_ID`, with Codex taking precedence when both exist;
96
127
  native Stop resolves the same identity from its `session_id` payload, using non-empty `turn_id` to
97
128
  identify Codex. There is no uninstall command yet.
98
129
 
130
+ ### Doctor and lint-intents
131
+
132
+ `npx @sockulags/agent-os@latest doctor` is a read-only report of every installed version and package,
133
+ retired or missing skills, duplicate direct and plugin installs, an old single `agent-os` plugin that
134
+ must be replaced by `agent-os-core` and `agent-os-dev`, the global policy blocks (each carries an
135
+ `<!-- agent-os version X -->` line), and the hooks, with the command that fixes each difference.
136
+ Team update, migration, governance, and removal steps are in the
137
+ [team setup guide](https://sockulags.github.io/agent-os/guide/team-setup).
138
+
139
+ `npx @sockulags/agent-os lint-intents` checks `intents/<id>/` files: frontmatter, statuses,
140
+ `built_on` revisions, unit lines, and unique ids. Stale specs and plans are warnings, or errors with
141
+ `--strict`. With `--base <ref>` it also fails when an accepted file's text changed without a higher
142
+ `rev`; `--allow-unchanged-rev` accepts a pure wording fix.
143
+
144
+ ### Plugins
145
+
99
146
  Native marketplace installation remains available with `--method plugin`. It requires the selected
100
- host CLI. Claude plugin skills appear as `/agent-os:<skill>`; Codex plugin skills remain
101
- `$<skill>`.
147
+ host CLI and installs `agent-os-core` and `agent-os-dev` (or only core with `--package core`). Claude
148
+ plugin skills appear as `/agent-os-core:<skill>` and `/agent-os-dev:<skill>`; Codex plugin skills
149
+ remain `$<skill>`.
102
150
 
103
- For development against this clone, Claude can still use `claude --plugin-dir .`, and Codex can
104
- register the local `.agents/plugins/marketplace.json` marketplace.
151
+ For development against this clone, Claude can use `claude --plugin-dir plugins/agent-os-core
152
+ --plugin-dir plugins/agent-os-dev`, and Codex can register the local `.agents/plugins/marketplace.json`
153
+ marketplace.
105
154
 
106
155
  ## Release routine
107
156
 
108
- 1. Run `node scripts/validate-agent-os.mjs`, `npm test`, its red-case suite, and the live evals in `evals/`.
109
- 2. Bump `version` in `.claude-plugin/plugin.json`, `.codex-plugin/plugin.json`, and `package.json`.
157
+ 1. Run `node scripts/validate-agent-os.mjs`, `npm test`, its red-case suite, and `npm run test:evals`.
158
+ 2. Bump `version` in both packages' `.claude-plugin/plugin.json` and `.codex-plugin/plugin.json`
159
+ under `plugins/`, and in `package.json`.
110
160
  3. Add a dedicated changelog heading, commit and push, merge the green pull request to `main`, and
111
161
  create the matching tag before publishing. Never publish npm from a dirty worktree.
112
162
  4. Pack the npm artifact and verify a clean direct install for both hosts, then publish it.
@@ -125,7 +175,7 @@ npm --prefix docs-site run dev
125
175
  ```
126
176
 
127
177
  The base path in `docs-site/.vitepress/config.mjs` is `/agent-os/` and must match the repository
128
- name. A skill edit and its documentation page are one change — the pages under `skills/` and
178
+ name. A skill edit and its documentation page are one change: the pages under `skills/` and
129
179
  `reference/` mirror the skill files and go stale first.
130
180
 
131
181
  ## Evals
@@ -152,4 +202,7 @@ installation, and rollback:
152
202
 
153
203
  `policy.md` is the source of truth. The npm installer and `init-agent-os global` install it as a
154
204
  managed block (`<!-- BEGIN/END AGENT OS -->`) in `~/.claude/CLAUDE.md` and
155
- `~/.codex/AGENTS.md`. Edit `policy.md`, never the installed blocks.
205
+ `~/.codex/AGENTS.md`. Edit `policy.md`, never the installed blocks. Everything above its
206
+ `## Development workflows` heading is the core policy; that section is installed only with
207
+ agent-os-dev. `plugins/agent-os-dev/skills/init-agent-os/policy.md` is a copy that the validator keeps
208
+ identical, so a plugin install can find the source.
package/cli/doctor.mjs ADDED
@@ -0,0 +1,307 @@
1
+ // Read-only installation report: which Agent OS versions this machine and project run, whether
2
+ // they match this CLI, and whether the managed policy blocks and hooks are current. It never
3
+ // writes, and a broken or unexpected file becomes a finding instead of a crash.
4
+
5
+ import { spawnSync } from 'node:child_process'
6
+ import fs from 'node:fs'
7
+ import os from 'node:os'
8
+ import path from 'node:path'
9
+ import { composePolicy, planPolicyUpdate, policyBlockVersion } from '../plugins/agent-os-dev/skills/init-agent-os/scripts/policy-block.mjs'
10
+
11
+ const INSTALL_MANIFEST = '.agent-os-install.json'
12
+ const HOOK_MARKER = '--agent-os-hook=quality-ratchet'
13
+ const GUARDS_MARKER = '--agent-os-hook=guards'
14
+ const CORE = 'agent-os-core'
15
+ const DEV = 'agent-os-dev'
16
+ // Before the core/dev split, one plugin named agent-os carried every skill.
17
+ const LEGACY_PLUGIN = 'agent-os'
18
+ const PLUGINS = [CORE, DEV, LEGACY_PLUGIN]
19
+
20
+ export function compareVersions(left, right) {
21
+ const parts = (value) => String(value).split(/[.+-]/).slice(0, 3).map((part) => Number.parseInt(part, 10) || 0)
22
+ const [a, b] = [parts(left), parts(right)]
23
+ for (let index = 0; index < 3; index += 1) {
24
+ if (a[index] !== b[index]) return a[index] - b[index]
25
+ }
26
+ return 0
27
+ }
28
+
29
+ // absent: the path does not exist. invalid: it exists but is not a readable JSON file.
30
+ function readJson(file, fsImpl) {
31
+ if (!fsImpl.existsSync(file)) return { state: 'absent' }
32
+ try {
33
+ return { state: 'ok', value: JSON.parse(fsImpl.readFileSync(file, 'utf8')) }
34
+ } catch (error) {
35
+ return { state: 'invalid', error: error.message }
36
+ }
37
+ }
38
+
39
+ function readText(file, fsImpl) {
40
+ if (!fsImpl.existsSync(file)) return { state: 'absent', text: '' }
41
+ try {
42
+ return { state: 'ok', text: fsImpl.readFileSync(file, 'utf8') }
43
+ } catch (error) {
44
+ return { state: 'invalid', error: error.message, text: '' }
45
+ }
46
+ }
47
+
48
+ function directories(dir, fsImpl) {
49
+ try {
50
+ return fsImpl.readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name)
51
+ } catch {
52
+ return []
53
+ }
54
+ }
55
+
56
+ const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value)
57
+
58
+ function directRoots(homeDir, cwd) {
59
+ return [
60
+ { platform: 'claude', scope: 'user', root: path.join(homeDir, '.claude', 'skills'), hookPath: path.join(homeDir, '.claude', 'settings.json') },
61
+ { platform: 'codex', scope: 'user', root: path.join(homeDir, '.codex', 'skills'), hookPath: path.join(homeDir, '.codex', 'hooks.json') },
62
+ { platform: 'claude', scope: 'project', root: path.join(cwd, '.claude', 'skills'), hookPath: path.join(cwd, '.claude', 'settings.json') },
63
+ { platform: 'codex', scope: 'project', root: path.join(cwd, '.agents', 'skills'), hookPath: path.join(cwd, '.codex', 'hooks.json') }
64
+ ]
65
+ }
66
+
67
+ // Manifests written before the split carry no packages field and held every skill.
68
+ function manifestPackages(manifest) {
69
+ return Array.isArray(manifest.packages) && manifest.packages.length ? manifest.packages : [CORE, DEV]
70
+ }
71
+
72
+ function checkDirectInstall(target, { version, packageName, packagedSkills, packageSkills, fsImpl, report }) {
73
+ const manifestPath = path.join(target.root, INSTALL_MANIFEST)
74
+ const read = readJson(manifestPath, fsImpl)
75
+ if (read.state === 'absent') return false
76
+ const label = `${target.platform} direct ${target.scope} (${target.root})`
77
+ const manifest = read.value
78
+ const packages = isObject(manifest) ? manifestPackages(manifest) : [CORE, DEV]
79
+ const update = `npx ${packageName}@latest update --platform ${target.platform} --scope ${target.scope}` +
80
+ (packages.includes(DEV) ? '' : ' --package core')
81
+ if (read.state === 'invalid' || !isObject(manifest) || manifest.package !== packageName || !Array.isArray(manifest.skills)) {
82
+ report('drift', label, `${manifestPath} is not a readable Agent OS install manifest, so update refuses to use it. ` +
83
+ `Move it aside, then run: ${update}`)
84
+ return { packages: [] }
85
+ }
86
+ if (manifest.version === version) report('ok', label, `version ${version}`)
87
+ else report('drift', label, `installed ${manifest.version ?? 'unknown'}, this CLI is ${version}. Run: ${update}`)
88
+
89
+ const retired = manifest.skills.filter((name) => typeof name === 'string' && !packagedSkills.includes(name) &&
90
+ fsImpl.existsSync(path.join(target.root, name, 'SKILL.md')))
91
+ if (retired.length) report('drift', label, `retired skills still installed: ${retired.join(', ')}. Run: ${update}`)
92
+ const expected = packages.flatMap((name) => packageSkills?.[name] ?? [])
93
+ const missing = expected.filter((name) => !fsImpl.existsSync(path.join(target.root, name, 'SKILL.md')))
94
+ if (missing.length) report('drift', label, `skills missing: ${missing.join(', ')}. Run: ${update}`)
95
+
96
+ if (!packages.includes(DEV)) return { packages }
97
+ const hooks = readText(target.hookPath, fsImpl)
98
+ if (hooks.state === 'invalid') report('warn', label, `cannot read ${target.hookPath}: ${hooks.error}`)
99
+ else if (!hooks.text.includes(HOOK_MARKER)) report('drift', label, `quality-ratchet Stop hook missing from ${target.hookPath}. Run: ${update}`)
100
+ else if (!hooks.text.includes(GUARDS_MARKER)) report('drift', label, `guard hooks missing from ${target.hookPath}. Run: ${update}`)
101
+ else if (target.platform === 'codex') {
102
+ report('info', label, 'Codex runs these hooks only after you trust them in /hooks; trust them again after an update changes them.')
103
+ }
104
+ return { packages }
105
+ }
106
+
107
+ // A marketplace added from a local directory loads the plugin in place, so its recorded version can
108
+ // stay old while the code is current. Read the in-place manifest instead: plugins/<name>/ in a
109
+ // checkout, or the marketplace root for a single-plugin directory.
110
+ function localMarketplaceVersion(homeDir, marketplace, name, fsImpl) {
111
+ const known = readJson(path.join(homeDir, '.claude', 'plugins', 'known_marketplaces.json'), fsImpl)
112
+ const entry = known.state === 'ok' && isObject(known.value) ? known.value[marketplace] : null
113
+ if (!isObject(entry) || !isObject(entry.source) || entry.source.source !== 'directory') return null
114
+ const location = typeof entry.installLocation === 'string' ? entry.installLocation : entry.source.path
115
+ if (typeof location !== 'string') return null
116
+ for (const root of [path.join(location, 'plugins', name), location]) {
117
+ const manifest = readJson(path.join(root, '.claude-plugin', 'plugin.json'), fsImpl)
118
+ if (manifest.state === 'ok' && isObject(manifest.value) && manifest.value.name === name &&
119
+ typeof manifest.value.version === 'string') {
120
+ return { location: root, version: manifest.value.version }
121
+ }
122
+ }
123
+ return null
124
+ }
125
+
126
+ function checkClaudePlugin(homeDir, { version, fsImpl, report }) {
127
+ const file = path.join(homeDir, '.claude', 'plugins', 'installed_plugins.json')
128
+ const installed = readJson(file, fsImpl)
129
+ if (installed.state === 'absent') return { keys: [], unknown: false }
130
+ if (installed.state === 'invalid' || !isObject(installed.value)) {
131
+ report('warn', 'claude plugins', `cannot read ${file}; plugin installs were not checked.`)
132
+ return { keys: [], unknown: true }
133
+ }
134
+ const plugins = isObject(installed.value.plugins) ? installed.value.plugins : {}
135
+ const keys = new Set()
136
+ const names = new Set()
137
+ for (const [key, installs] of Object.entries(plugins)) {
138
+ const separator = key.indexOf('@')
139
+ const name = separator > 0 ? key.slice(0, separator) : key
140
+ if (!PLUGINS.includes(name)) continue
141
+ const marketplace = key.slice(name.length + 1)
142
+ const local = localMarketplaceVersion(homeDir, marketplace, name, fsImpl)
143
+ for (const install of (Array.isArray(installs) ? installs : []).filter(isObject)) {
144
+ keys.add(key)
145
+ names.add(name)
146
+ const scope = typeof install.scope === 'string' ? install.scope : 'user'
147
+ const label = `claude plugin ${key} (${scope})`
148
+ const scopeFlag = scope === 'user' ? '' : ` --scope ${scope}`
149
+ if (name === LEGACY_PLUGIN) {
150
+ report('drift', label, `the single agent-os plugin is replaced by ${CORE} and ${DEV}. ` +
151
+ `Run: claude plugin marketplace update ${marketplace} && claude plugin uninstall ${key}${scopeFlag} && ` +
152
+ `claude plugin install ${CORE}@${marketplace}${scopeFlag} && claude plugin install ${DEV}@${marketplace}${scopeFlag}`)
153
+ continue
154
+ }
155
+ const current = local ? local.version : install.version
156
+ const source = local ? `loaded in place from ${local.location}, version` : 'version'
157
+ if (current === version) report('ok', label, `${source} ${version}`)
158
+ else if (local) report('drift', label, `${source} ${current ?? 'unknown'}, this CLI is ${version}. Pull the latest release into ${local.location}, then run /reload-plugins.`)
159
+ else {
160
+ report('drift', label, `recorded version ${install.version ?? 'unknown'}, this CLI is ${version}. ` +
161
+ `Run: claude plugin marketplace update ${marketplace} && claude plugin update ${key}${scopeFlag}`)
162
+ }
163
+ }
164
+ }
165
+ if (names.has(DEV) && !names.has(CORE)) {
166
+ report('drift', 'claude plugins', `${DEV} is installed without ${CORE}, which it requires. Run: claude plugin install ${CORE}@agent-os-marketplace`)
167
+ }
168
+ return { keys: [...keys], names: [...names], unknown: false }
169
+ }
170
+
171
+ function checkCodexPlugin(homeDir, { version, fsImpl, report }) {
172
+ const cache = path.join(homeDir, '.codex', 'plugins', 'cache')
173
+ const names = new Set()
174
+ for (const marketplace of directories(cache, fsImpl)) {
175
+ for (const name of PLUGINS) {
176
+ for (const installed of directories(path.join(cache, marketplace, name), fsImpl)) {
177
+ names.add(name)
178
+ const label = `codex plugin ${name}@${marketplace}`
179
+ if (name === LEGACY_PLUGIN) {
180
+ report('drift', label, `the single agent-os plugin is replaced by ${CORE} and ${DEV}. Run: codex plugin marketplace upgrade ${marketplace}, ` +
181
+ `remove agent-os in /plugins, then run: codex plugin add ${CORE}@${marketplace} and codex plugin add ${DEV}@${marketplace}`)
182
+ } else if (installed === version || installed === 'local') report('ok', label, `version ${installed}`)
183
+ else report('drift', label, `cached version ${installed}, this CLI is ${version}. Run: codex plugin marketplace upgrade ${marketplace}, then reinstall the plugin.`)
184
+ }
185
+ }
186
+ }
187
+ return [...names]
188
+ }
189
+
190
+ // The CLI's update reinstalls skills, so a plugin-only user syncs the policy through the skill.
191
+ // An unreadable plugin record may hide a plugin install, so it never leads to install advice.
192
+ function policyFix(platform, { packageName, direct, plugin, unknown, dev }) {
193
+ if (direct) return `npx ${packageName}@latest update --platform ${platform} --policy` + (dev ? '' : ' --package core')
194
+ if (plugin && !dev) return `npx ${packageName}@latest install --platform ${platform} --method plugin --package core --policy`
195
+ if (plugin || unknown) return platform === 'claude' ? 'run /agent-os-dev:init-agent-os global in Claude Code' : 'run $init-agent-os global in Codex'
196
+ return `npx ${packageName}@latest install --platform ${platform}`
197
+ }
198
+
199
+ function checkPolicy(homeDir, { version, packageName, policy, installed, fsImpl, report }) {
200
+ for (const [platform, segments] of [['claude', ['.claude', 'CLAUDE.md']], ['codex', ['.codex', 'AGENTS.md']]]) {
201
+ if (!fsImpl.existsSync(path.join(homeDir, segments[0]))) continue
202
+ const target = path.join(homeDir, ...segments)
203
+ const label = `${platform} global policy (${target})`
204
+ const fix = policyFix(platform, { packageName, ...installed[platform] })
205
+ // A host without agent-os-dev gets the core policy; with no record of either, expect the full one.
206
+ const expected = composePolicy(policy, { dev: installed[platform].dev || !installed[platform].core })
207
+ const read = readText(target, fsImpl)
208
+ if (read.state === 'invalid') {
209
+ report('warn', label, `cannot read the file: ${read.error}`)
210
+ continue
211
+ }
212
+ let plan
213
+ try {
214
+ plan = planPolicyUpdate(read.text, expected, version)
215
+ } catch (error) {
216
+ report('drift', label, `${error.message} Fix the markers by hand, then: ${fix}`)
217
+ continue
218
+ }
219
+ if (plan.status === 'ADDED') report('warn', label, `no Agent OS block. To add it: ${fix}`)
220
+ else if (plan.changed) {
221
+ const block = policyBlockVersion(read.text)
222
+ report('drift', label, `${block ? `block is version ${block}` : 'block has no version line, so an older installer wrote it'} ` +
223
+ `and differs from this CLI's ${version}. To update it: ${fix}`)
224
+ } else report('ok', label, `version ${version}`)
225
+ }
226
+ }
227
+
228
+ export function latestPublishedVersion(packageName, { spawn = spawnSync } = {}) {
229
+ if (!/^@?[a-z0-9][a-z0-9._/-]*$/.test(packageName)) return null
230
+ // npm is a .cmd shim on Windows, which needs a shell; one fixed command string avoids argument joining.
231
+ let result
232
+ try {
233
+ result = spawn(`npm view ${packageName} version`, {
234
+ encoding: 'utf8', timeout: 15000, stdio: ['ignore', 'pipe', 'pipe'], shell: true
235
+ })
236
+ } catch {
237
+ return null
238
+ }
239
+ const value = result?.status === 0 ? String(result.stdout ?? '').trim() : ''
240
+ return /^[0-9][0-9A-Za-z.+-]*$/.test(value) ? value : null
241
+ }
242
+
243
+ export function collectDoctorReport({
244
+ version, packageName, packagedSkills, packageSkills, policy, homeDir = os.homedir(), cwd = process.cwd(),
245
+ fsImpl = fs, latest = null
246
+ }) {
247
+ const entries = []
248
+ const report = (level, area, message) => entries.push({ level, area, message })
249
+
250
+ if (!latest) report('info', 'installer', `version ${version}; the latest published version was not checked`)
251
+ else if (compareVersions(latest, version) > 0) {
252
+ report('warn', 'installer', `this CLI is ${version}, the latest published version is ${latest}. Run: npx ${packageName}@latest doctor`)
253
+ } else if (compareVersions(latest, version) < 0) {
254
+ report('info', 'installer', `this CLI is ${version}, newer than the published ${latest}`)
255
+ } else report('ok', 'installer', `version ${version} is the latest published version`)
256
+
257
+ const host = () => ({ direct: false, plugin: false, core: false, dev: false })
258
+ const installed = { claude: host(), codex: host() }
259
+ const mark = (platform, packages) => {
260
+ if (packages.includes(CORE) || packages.includes(LEGACY_PLUGIN)) installed[platform].core = true
261
+ if (packages.includes(DEV) || packages.includes(LEGACY_PLUGIN)) installed[platform].dev = true
262
+ }
263
+ for (const target of directRoots(homeDir, cwd)) {
264
+ const direct = checkDirectInstall(target, { version, packageName, packagedSkills, packageSkills, fsImpl, report })
265
+ if (direct) {
266
+ installed[target.platform].direct = true
267
+ mark(target.platform, direct.packages)
268
+ }
269
+ }
270
+ const claudePlugin = checkClaudePlugin(homeDir, { version, fsImpl, report })
271
+ installed.claude.plugin = claudePlugin.keys.length > 0
272
+ installed.claude.unknown = claudePlugin.unknown
273
+ mark('claude', claudePlugin.names ?? [])
274
+ const codexPlugins = checkCodexPlugin(homeDir, { version, fsImpl, report })
275
+ installed.codex.plugin = codexPlugins.length > 0
276
+ mark('codex', codexPlugins)
277
+
278
+ if (installed.claude.direct && installed.claude.plugin) {
279
+ const uninstall = claudePlugin.keys.map((key) => `claude plugin uninstall ${key}`).join(' and ')
280
+ report('warn', 'claude', 'both the plugin and a direct install are present, so every skill appears twice (/agent-os-core:<skill> or /agent-os-dev:<skill>, and /<skill>). ' +
281
+ `Keep one: ${uninstall}, or delete the directories listed in the direct install manifest.`)
282
+ }
283
+ if (installed.codex.direct && installed.codex.plugin) {
284
+ report('warn', 'codex', 'both the plugin and a direct install are present, so Codex lists every skill twice. ' +
285
+ 'Keep one: uninstall the plugin in /plugins, or delete the directories listed in the direct install manifest.')
286
+ }
287
+ const agentsRoot = path.join(homeDir, '.agents', 'skills')
288
+ const strays = packagedSkills.filter((name) => fsImpl.existsSync(path.join(agentsRoot, name, 'SKILL.md')))
289
+ if (strays.length) {
290
+ report('warn', `codex ${agentsRoot}`, `Agent OS skills outside the managed install: ${strays.join(', ')}. ` +
291
+ `Codex may list them next to the managed copies. Delete these directories from ${agentsRoot} if you did not install them on purpose.`)
292
+ }
293
+ if (!Object.values(installed).some((host) => host.direct || host.plugin || host.unknown)) {
294
+ report('warn', 'install', `no Agent OS installation found. Run: npx ${packageName}@latest install`)
295
+ }
296
+
297
+ checkPolicy(homeDir, { version, packageName, policy, installed, fsImpl, report })
298
+ return { entries, drift: entries.some((entry) => entry.level === 'drift') }
299
+ }
300
+
301
+ export function formatDoctorReport({ entries, drift }) {
302
+ const lines = entries.map((entry) => `${entry.level.toUpperCase().padEnd(6)}${entry.area}: ${entry.message}`)
303
+ lines.push(drift
304
+ ? 'Agent OS installations differ from this CLI. Follow the listed fixes, then start a new host session.'
305
+ : 'No version drift found.')
306
+ return lines.join('\n') + '\n'
307
+ }