@sockulags/agent-os 0.15.0 → 0.17.0

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