@unbrained/pm-cli 2026.5.10 → 2026.5.11

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 (124) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/.pi/README.md +10 -1
  3. package/.pi/agents/pm-triage-agent.md +19 -0
  4. package/.pi/agents/pm-verification-agent.md +21 -0
  5. package/.pi/chains/pm-native-delivery.chain.md +11 -0
  6. package/.pi/extensions/pm-cli/index.js +276 -36
  7. package/.pi/skills/pm-native/SKILL.md +6 -2
  8. package/CHANGELOG.md +7 -0
  9. package/README.md +9 -1
  10. package/dist/cli/argv-utils.d.ts +5 -0
  11. package/dist/cli/argv-utils.js +34 -0
  12. package/dist/cli/argv-utils.js.map +1 -0
  13. package/dist/cli/bootstrap-args.d.ts +15 -0
  14. package/dist/cli/bootstrap-args.js +211 -0
  15. package/dist/cli/bootstrap-args.js.map +1 -1
  16. package/dist/cli/commander-usage.js +109 -3
  17. package/dist/cli/commander-usage.js.map +1 -1
  18. package/dist/cli/commands/completion.js +7 -3
  19. package/dist/cli/commands/completion.js.map +1 -1
  20. package/dist/cli/commands/contracts.d.ts +19 -0
  21. package/dist/cli/commands/contracts.js +33 -1
  22. package/dist/cli/commands/contracts.js.map +1 -1
  23. package/dist/cli/commands/create.js +112 -51
  24. package/dist/cli/commands/create.js.map +1 -1
  25. package/dist/cli/commands/docs.js +9 -2
  26. package/dist/cli/commands/docs.js.map +1 -1
  27. package/dist/cli/commands/extension.d.ts +3 -1
  28. package/dist/cli/commands/extension.js +174 -2
  29. package/dist/cli/commands/extension.js.map +1 -1
  30. package/dist/cli/commands/files.js +9 -2
  31. package/dist/cli/commands/files.js.map +1 -1
  32. package/dist/cli/commands/init.d.ts +2 -0
  33. package/dist/cli/commands/init.js +21 -1
  34. package/dist/cli/commands/init.js.map +1 -1
  35. package/dist/cli/commands/metadata-normalizers.d.ts +4 -0
  36. package/dist/cli/commands/metadata-normalizers.js +37 -0
  37. package/dist/cli/commands/metadata-normalizers.js.map +1 -0
  38. package/dist/cli/commands/reindex.js +173 -135
  39. package/dist/cli/commands/reindex.js.map +1 -1
  40. package/dist/cli/commands/search.js +16 -6
  41. package/dist/cli/commands/search.js.map +1 -1
  42. package/dist/cli/commands/test.js +9 -2
  43. package/dist/cli/commands/test.js.map +1 -1
  44. package/dist/cli/commands/update.js +70 -39
  45. package/dist/cli/commands/update.js.map +1 -1
  46. package/dist/cli/error-guidance.d.ts +9 -1
  47. package/dist/cli/error-guidance.js +147 -6
  48. package/dist/cli/error-guidance.js.map +1 -1
  49. package/dist/cli/help-json-payload.js +11 -1
  50. package/dist/cli/help-json-payload.js.map +1 -1
  51. package/dist/cli/main.js +69 -6
  52. package/dist/cli/main.js.map +1 -1
  53. package/dist/cli/register-setup.js +14 -0
  54. package/dist/cli/register-setup.js.map +1 -1
  55. package/dist/cli/telemetry-flush.d.ts +2 -0
  56. package/dist/cli/telemetry-flush.js +4 -0
  57. package/dist/cli/telemetry-flush.js.map +1 -0
  58. package/dist/cli.js +1 -2
  59. package/dist/cli.js.map +1 -1
  60. package/dist/core/extensions/extension-types.d.ts +72 -0
  61. package/dist/core/extensions/extension-types.js +24 -0
  62. package/dist/core/extensions/extension-types.js.map +1 -1
  63. package/dist/core/extensions/loader.d.ts +1 -0
  64. package/dist/core/extensions/loader.js +766 -7
  65. package/dist/core/extensions/loader.js.map +1 -1
  66. package/dist/core/lock/lock.js +2 -0
  67. package/dist/core/lock/lock.js.map +1 -1
  68. package/dist/core/sentry/instrument.d.ts +15 -0
  69. package/dist/core/sentry/instrument.js +35 -3
  70. package/dist/core/sentry/instrument.js.map +1 -1
  71. package/dist/core/shared/constants.js +20 -0
  72. package/dist/core/shared/constants.js.map +1 -1
  73. package/dist/core/shared/errors.d.ts +8 -0
  74. package/dist/core/shared/errors.js.map +1 -1
  75. package/dist/core/shared/levenshtein.d.ts +1 -0
  76. package/dist/core/shared/levenshtein.js +37 -0
  77. package/dist/core/shared/levenshtein.js.map +1 -0
  78. package/dist/core/store/paths.js +34 -1
  79. package/dist/core/store/paths.js.map +1 -1
  80. package/dist/core/store/settings.js +210 -1
  81. package/dist/core/store/settings.js.map +1 -1
  82. package/dist/core/telemetry/runtime.d.ts +1 -0
  83. package/dist/core/telemetry/runtime.js +102 -3
  84. package/dist/core/telemetry/runtime.js.map +1 -1
  85. package/dist/mcp/server.js +3 -1
  86. package/dist/mcp/server.js.map +1 -1
  87. package/dist/pi/native.js +57 -4
  88. package/dist/pi/native.js.map +1 -1
  89. package/dist/sdk/cli-contracts.d.ts +21 -1
  90. package/dist/sdk/cli-contracts.js +250 -0
  91. package/dist/sdk/cli-contracts.js.map +1 -1
  92. package/dist/sdk/index.d.ts +12 -1
  93. package/dist/sdk/index.js +8 -1
  94. package/dist/sdk/index.js.map +1 -1
  95. package/dist/types.d.ts +41 -0
  96. package/dist/types.js.map +1 -1
  97. package/docs/CLAUDE_CODE_PLUGIN.md +39 -0
  98. package/docs/EXTENSIONS.md +687 -0
  99. package/docs/MIGRATION_CLI_SIMPLIFICATION.md +64 -0
  100. package/docs/PI_PACKAGE.md +95 -10
  101. package/docs/SDK.md +441 -0
  102. package/docs/examples/ci/github-actions-pm-extension-gate.yml +53 -0
  103. package/docs/examples/ci/gitlab-ci-pm-extension-gate.yml +41 -0
  104. package/docs/examples/ci/jenkins-pm-extension-gate.Jenkinsfile +45 -0
  105. package/docs/examples/policy-restricted-extension/README.md +74 -0
  106. package/docs/examples/policy-restricted-extension/index.js +21 -0
  107. package/docs/examples/policy-restricted-extension/manifest.json +21 -0
  108. package/docs/examples/policy-restricted-extension/package.json +8 -0
  109. package/docs/examples/sdk-app-embedding/README.md +39 -0
  110. package/docs/examples/sdk-app-embedding/package.json +9 -0
  111. package/docs/examples/sdk-app-embedding/run-embedded-pm.mjs +61 -0
  112. package/docs/examples/sdk-contract-consumer/README.md +57 -0
  113. package/docs/examples/sdk-contract-consumer/inspect-contracts.mjs +47 -0
  114. package/docs/examples/sdk-contract-consumer/package.json +10 -0
  115. package/docs/examples/starter-extension/README.md +57 -42
  116. package/docs/examples/starter-extension/manifest.json +15 -0
  117. package/marketplace.json +3 -3
  118. package/package.json +1 -1
  119. package/plugins/pm-cli-claude/.claude-plugin/plugin.json +2 -2
  120. package/plugins/pm-cli-claude/README.md +55 -14
  121. package/plugins/pm-cli-claude/agents/pm-delivery-chain.md +88 -0
  122. package/plugins/pm-cli-claude/agents/pm-triage-agent.md +83 -0
  123. package/plugins/pm-cli-claude/agents/pm-verification-agent.md +88 -0
  124. package/plugins/pm-cli-claude/hooks/session-start.mjs +87 -22
@@ -0,0 +1,64 @@
1
+ # CLI Simplification Migration (Conservative Full-Surface Pass)
2
+
3
+ This note documents behavioral and output-shape changes introduced in the conservative CLI simplification pass.
4
+
5
+ ## What Changed
6
+
7
+ ### 1) Command invocation normalization before Commander parse
8
+
9
+ `pm` now normalizes invocation tokens before Commander parses them:
10
+
11
+ - long-flag shape normalization (`--foo_bar` / camel variants -> canonical kebab flags)
12
+ - high-confidence typo normalization for long flags
13
+ - `key=value` / `key:value` promotion into canonical `--flag value` tokens when unambiguous
14
+ - legacy `pm extension <action>` shorthand normalization to explicit action flags
15
+
16
+ Normalization runs across command families and preserves a normalization trace for diagnostics and recovery.
17
+
18
+ ### 2) Setup-agnostic PM root discovery
19
+
20
+ `resolvePmRoot()` precedence is now:
21
+
22
+ 1. explicit `--path`
23
+ 2. `PM_PATH`
24
+ 3. upward discovery of initialized `.agents/pm` roots (must contain `settings.json`)
25
+ 4. local default (`<cwd>/.agents/pm`)
26
+
27
+ If you need the old local-only behavior from nested directories, pass an explicit path (`--path .agents/pm`).
28
+
29
+ ### 3) Structured recovery bundles in CLI error output
30
+
31
+ Error payloads now include optional `recovery` metadata in text and JSON guidance surfaces:
32
+
33
+ - `attempted_command`
34
+ - `normalized_args`
35
+ - `provided_fields`
36
+ - `missing`
37
+ - `suggested_retry`
38
+
39
+ Automation should read this bundle for deterministic retries instead of rebuilding retries from free-form error text.
40
+
41
+ ### 4) Legacy `none`/`null` compatibility in create/update
42
+
43
+ For deterministic compatibility:
44
+
45
+ - scalar `none` / `null` values on unset-capable fields are reinterpreted as `--unset <field>`
46
+ - repeatable `none` / `null` values are reinterpreted as their matching `--clear-*` action
47
+ - mixed legacy clear token + concrete repeatable payloads remain rejected (ambiguous input)
48
+
49
+ ## Migration Guidance for Automation
50
+
51
+ - **Prefer contracts first**: keep using `pm contracts --json` and command-scoped flag contracts.
52
+ - **Consume `recovery` directly**: treat `recovery.suggested_retry` as first-choice replay command.
53
+ - **Do not hardcode old error envelopes**: parsers should tolerate additional fields (`recovery`) and richer guidance text.
54
+ - **Avoid relying on local cwd-only root resolution**: pass `--path` explicitly when wrappers need fixed data roots.
55
+ - **Update none/null assumptions**: if your tests expected hard failures for pure `none`/`null` clear intents, update them to expect deterministic clear/unset behavior.
56
+
57
+ ## Verification Checklist
58
+
59
+ - `tests/unit/bootstrap-args.spec.ts`
60
+ - `tests/unit/store-paths.spec.ts`
61
+ - `tests/integration/help-runtime.spec.ts`
62
+ - `tests/unit/create-command.spec.ts`
63
+ - `tests/unit/update-command.spec.ts`
64
+
@@ -1,8 +1,75 @@
1
- # Pi Native Package
1
+ # Pi Native Package & Claude Code Plugin
2
2
 
3
- pm-cli ships an official Pi package so Pi can use pm through a native extension instead of shelling out to the `pm` CLI.
3
+ pm-cli ships both an official Pi package and a Claude Code plugin so AI coding agents can use pm through native integrations instead of shelling out to the `pm` CLI.
4
4
 
5
- ## Install
5
+ ## Claude Code Plugin
6
+
7
+ The Claude Code plugin (`plugins/pm-cli-claude/`) provides full native pm integration for Claude Code without any CLI dependency.
8
+
9
+ ### Install
10
+
11
+ ```
12
+ /plugin install pm-cli@pm
13
+ ```
14
+
15
+ Both `pm` and `pm-cli` marketplace IDs work:
16
+
17
+ ```
18
+ /plugin install pm-cli@pm # canonical
19
+ /plugin install pm-cli@pm-cli # legacy alias
20
+ ```
21
+
22
+ To add the marketplace first (local checkout):
23
+
24
+ ```bash
25
+ claude plugin marketplace add /path/to/pm-cli
26
+ ```
27
+
28
+ After npm publish, the marketplace will be available via GitHub:
29
+
30
+ ```bash
31
+ claude plugin marketplace add unbraind/pm-cli
32
+ ```
33
+
34
+ ### Plugin Components
35
+
36
+ | Component | Path | What it provides |
37
+ |-----------|------|-----------------|
38
+ | MCP server | `scripts/pm-mcp-server.mjs` | 18 native MCP tools |
39
+ | Skills | `skills/` | 5 workflow skills auto-loaded in Claude Code |
40
+ | Commands | `commands/` | 14 slash commands |
41
+ | Agents | `agents/` | 3 subagents + 1 delivery chain |
42
+ | Hooks | `hooks/` | Session-start context injection |
43
+
44
+ ### MCP Tools (18)
45
+
46
+ Narrow tools: `pm_context`, `pm_search`, `pm_list`, `pm_get`, `pm_create`, `pm_update`, `pm_claim`, `pm_release`, `pm_close`, `pm_comments`, `pm_files`, `pm_docs`, `pm_test`, `pm_validate`, `pm_health`, `pm_contracts`, `pm_guide`
47
+
48
+ General tool: `pm_run` (with explicit `action` for everything else)
49
+
50
+ ### Subagents (4)
51
+
52
+ | Agent | Description |
53
+ |-------|-------------|
54
+ | `pm-coordinator` | Multi-item batch coordination |
55
+ | `pm-triage-agent` | Duplicate-safe item creation with lineage |
56
+ | `pm-verification-agent` | Evidence collection and close readiness |
57
+ | `pm-delivery-chain` | Full triage → implement → verify orchestration |
58
+
59
+ ### Session Hook
60
+
61
+ The session-start hook runs natively:
62
+ 1. Walks up from plugin root to find `dist/pi/native.js` in a repo checkout
63
+ 2. Falls back to `npx @unbrained/pm-cli` if no local dist
64
+ 3. No `pm` CLI global install required in either path
65
+
66
+ ---
67
+
68
+ ## Pi Native Package
69
+
70
+ The Pi package at `.pi/` exposes pm through Pi's native extension API.
71
+
72
+ ### Install
6
73
 
7
74
  After the package is published:
8
75
 
@@ -10,8 +77,6 @@ After the package is published:
10
77
  pi install npm:@unbrained/pm-cli
11
78
  ```
12
79
 
13
- If you install an unscoped npm alias, use the same Pi syntax, for example `pi install npm:pm-cli`. The published package in this repository is `@unbrained/pm-cli`.
14
-
15
80
  From a local checkout:
16
81
 
17
82
  ```bash
@@ -23,7 +88,7 @@ pi --no-extensions -e .
23
88
 
24
89
  `pnpm build` is required for local checkouts because the Pi extension imports the compiled native integration from `dist/pi/native.js`.
25
90
 
26
- ## Package Resources
91
+ ### Package Resources
27
92
 
28
93
  The root `package.json` declares the Pi manifest:
29
94
 
@@ -34,10 +99,12 @@ The root `package.json` declares the Pi manifest:
34
99
  The extension registers:
35
100
 
36
101
  - native `pm` tool using pm command modules directly, not the `pm` shell command
37
- - `/pm-context`, `/pm-start`, `/pm-close`, and `/pm-actions` helper commands
38
- - status footer entry `pm native`
102
+ - custom TUI rendering for pm tool calls/results (context, list/search, item details, history/activity)
103
+ - `/pm-context`, `/pm-board`, `/pm-item`, `/pm-history`, `/pm-start`, `/pm-close`, `/pm-actions`, and `/pm-workflows` helper commands
104
+ - `@pm-...` item autocomplete layered on top of Pi's editor completion
105
+ - footer status and a small below-editor widget (`pm native ready`) in interactive mode
39
106
 
40
- ## Native Tool Usage
107
+ ### Native Tool Usage
41
108
 
42
109
  Use the Pi `pm` tool with an `action` field. Examples:
43
110
 
@@ -51,6 +118,24 @@ Use the Pi `pm` tool with an `action` field. Examples:
51
118
 
52
119
  For real project tracking, leave `path` unset. For tests, set `path` to a sandbox pm root and isolate `PM_GLOBAL_PATH`.
53
120
 
121
+ ### Pi TUI Commands
122
+
123
+ ```text
124
+ /pm-board [limit] # context dashboard with active items
125
+ /pm-item <pm-id> # item details and recent comments
126
+ /pm-history <pm-id> # item history panel
127
+ /pm-actions # installed native action list
128
+ /pm-workflows # suggested native pm workflows
129
+ ```
130
+
131
+ ### Pi Skills and Subagents
132
+
133
+ - Skills: `pm-native`, `pm-release`
134
+ - Prompt template: `/pm-workflow`
135
+ - Subagent files: `.pi/agents/pm-triage-agent.md`, `.pi/agents/pm-verification-agent.md`, `.pi/chains/pm-native-delivery.chain.md`
136
+
137
+ ---
138
+
54
139
  ## Supported Surface
55
140
 
56
- The native integration covers the core pm action set exposed by the SDK contracts: init/config/extensions, item creation and lifecycle, list/search/context/calendar/activity, files/docs/deps/tests, validation/health/gc/contracts, templates, test-runs, and guide workflows.
141
+ Both integrations cover the core pm action set: init/config/extensions, item creation and lifecycle, list/search/context/calendar/activity, files/docs/deps/tests, validation/health/gc/contracts, templates, test-runs, guide workflows, bundled beads/todos import/export, and lifecycle shortcuts (`start-task`, `pause-task`, `close-task`).
package/docs/SDK.md CHANGED
@@ -1,5 +1,429 @@
1
1
  # SDK
2
2
 
3
+ The supported programmatic surface is `@unbrained/pm-cli/sdk`.
4
+
5
+ Use this package for extension authoring, command/action contract discovery, and deterministic app or CI automation. Do not import private `src/core/...` modules from external integrations.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @unbrained/pm-cli
11
+ ```
12
+
13
+ ## Core Exports
14
+
15
+ ### Extension authoring
16
+
17
+ - `defineExtension`
18
+ - `EXTENSION_CAPABILITIES`
19
+ - `EXTENSION_CAPABILITY_CONTRACT`
20
+ - `EXTENSION_CAPABILITY_CONTRACT_VERSION`
21
+ - `EXTENSION_CAPABILITY_LEGACY_ALIASES`
22
+ - `EXTENSION_POLICY_MODES`
23
+ - `EXTENSION_POLICY_SURFACES`
24
+ - `EXTENSION_TRUST_MODES`
25
+ - `EXTENSION_SANDBOX_PROFILES`
26
+
27
+ ### Command and action contracts
28
+
29
+ - `PM_CORE_COMMAND_NAMES`
30
+ - `PM_TOOL_ACTIONS`
31
+ - `PM_TOOL_PARAMETERS_SCHEMA`
32
+ - `PM_PI_TOOL_PARAMETERS_SCHEMA`
33
+ - `PM_TOOL_ACTION_PARAMETER_CONTRACTS`
34
+
35
+ ### Runtime contract constants
36
+
37
+ - `PM_EXTENSION_CAPABILITY_CONTRACTS`
38
+ - `PM_EXTENSION_SERVICE_NAME_CONTRACTS`
39
+ - `PM_EXTENSION_POLICY_MODE_CONTRACTS`
40
+ - `PM_EXTENSION_POLICY_SURFACE_CONTRACTS`
41
+ - `PM_EXTENSION_TRUST_MODE_CONTRACTS`
42
+ - `PM_EXTENSION_SANDBOX_PROFILE_CONTRACTS`
43
+
44
+ ### Type guards
45
+
46
+ - `isPmToolAction`
47
+ - `isPmExtensionCapabilityContract`
48
+ - `isPmExtensionServiceNameContract`
49
+ - `isPmExtensionPolicyModeContract`
50
+ - `isPmExtensionPolicySurfaceContract`
51
+
52
+ ## Capability Mapping
53
+
54
+ - `commands` -> `registerCommand`
55
+ - `schema` -> `registerFlags`, `registerItemFields`, `registerItemTypes`, `registerMigration`
56
+ - `importers` -> `registerImporter`, `registerExporter`
57
+ - `search` -> `registerSearchProvider`, `registerVectorStoreAdapter`
58
+ - `hooks` -> `api.hooks.*`
59
+ - `parser` -> `registerParser`
60
+ - `preflight` -> `registerPreflight`
61
+ - `services` -> `registerService`
62
+ - `renderers` -> `registerRenderer`
63
+
64
+ ## Extension Example
65
+
66
+ ```ts
67
+ import { defineExtension } from "@unbrained/pm-cli/sdk";
68
+
69
+ export default defineExtension({
70
+ activate(api) {
71
+ api.registerCommand({
72
+ name: "release audit",
73
+ action: "release-audit",
74
+ description: "Collect release-readiness diagnostics.",
75
+ intent: "Produce deterministic gate payloads for CI.",
76
+ flags: [{ long: "--strict", description: "Enable strict gate mode." }],
77
+ run: async (context) => ({
78
+ ok: true,
79
+ command: context.command,
80
+ strict: context.options.strict === true,
81
+ }),
82
+ });
83
+ },
84
+ });
85
+ ```
86
+
87
+ ## Contracts-First Automation
88
+
89
+ Use runtime contracts for extension-aware schemas:
90
+
91
+ ```bash
92
+ pm contracts --json
93
+ pm contracts --schema-only --json
94
+ pm contracts --command extension --flags-only --json
95
+ pm contracts --action create --schema-only --json
96
+ ```
97
+
98
+ Minimal script pattern:
99
+
100
+ ```ts
101
+ import { PM_TOOL_ACTION_PARAMETER_CONTRACTS, isPmToolAction } from "@unbrained/pm-cli/sdk";
102
+ import { spawnSync } from "node:child_process";
103
+
104
+ const action = "extension-reload";
105
+ if (!isPmToolAction(action)) throw new Error("Unsupported action");
106
+ const contract = PM_TOOL_ACTION_PARAMETER_CONTRACTS[action];
107
+ console.log(contract.required, contract.optional);
108
+
109
+ const result = spawnSync("pm", ["contracts", "--json"], { encoding: "utf8" });
110
+ if (result.status !== 0) throw new Error(result.stderr);
111
+ ```
112
+
113
+ ## Compatibility Metadata
114
+
115
+ `pm contracts --json` includes compatibility metadata for extension integrations:
116
+
117
+ - `extension_contracts.trust_modes`
118
+ - `extension_contracts.sandbox_profiles`
119
+ - `extension_contracts.manifest_versions`
120
+ - `extension_contracts.compatibility`
121
+ - `action_availability[].policy_state`
122
+
123
+ Current compatibility model:
124
+
125
+ - manifest current: `v2`
126
+ - supported previous: `v1`
127
+ - strategy: `versioned_breaking`
128
+
129
+ ## Runnable Examples
130
+
131
+ - `docs/examples/sdk-contract-consumer/`
132
+ - `docs/examples/sdk-app-embedding/`
133
+ - `docs/examples/ci/`
134
+
135
+ ## Related Docs
136
+
137
+ - `docs/EXTENSIONS.md`
138
+ - `docs/CLAUDE_CODE_PLUGIN.md`
139
+ # SDK
140
+
141
+ The supported programmatic surface is `@unbrained/pm-cli/sdk`.
142
+
143
+ Use this for:
144
+
145
+ - extension authoring (`defineExtension`)
146
+ - command/action schema discovery (`PM_TOOL_PARAMETERS_SCHEMA`)
147
+ - runtime action contracts (`PM_TOOL_ACTION_PARAMETER_CONTRACTS`)
148
+ - capability/policy/trust/sandbox contract constants
149
+
150
+ Do not import private `src/core/...` modules from external integrations.
151
+
152
+ ## Install
153
+
154
+ ```bash
155
+ npm install @unbrained/pm-cli
156
+ ```
157
+
158
+ ## Key Exports
159
+
160
+ ### Extension Authoring
161
+
162
+ - `defineExtension`
163
+ - `EXTENSION_CAPABILITIES`
164
+ - `EXTENSION_POLICY_MODES`
165
+ - `EXTENSION_POLICY_SURFACES`
166
+ - `EXTENSION_TRUST_MODES`
167
+ - `EXTENSION_SANDBOX_PROFILES`
168
+ - `EXTENSION_CAPABILITY_CONTRACT`
169
+ - `EXTENSION_CAPABILITY_CONTRACT_VERSION`
170
+ - `EXTENSION_CAPABILITY_LEGACY_ALIASES`
171
+
172
+ ### Command/Action Contracts
173
+
174
+ - `PM_CORE_COMMAND_NAMES`
175
+ - `PM_TOOL_ACTIONS`
176
+ - `PM_TOOL_PARAMETERS_SCHEMA`
177
+ - `PM_PI_TOOL_PARAMETERS_SCHEMA`
178
+ - `PM_TOOL_ACTION_PARAMETER_CONTRACTS`
179
+
180
+ ### Extension Runtime Contract Constants
181
+
182
+ - `PM_EXTENSION_CAPABILITY_CONTRACTS`
183
+ - `PM_EXTENSION_SERVICE_NAME_CONTRACTS`
184
+ - `PM_EXTENSION_POLICY_MODE_CONTRACTS`
185
+ - `PM_EXTENSION_POLICY_SURFACE_CONTRACTS`
186
+ - `PM_EXTENSION_TRUST_MODE_CONTRACTS`
187
+ - `PM_EXTENSION_SANDBOX_PROFILE_CONTRACTS`
188
+
189
+ ### Type Guards
190
+
191
+ - `isPmToolAction`
192
+ - `isPmExtensionCapabilityContract`
193
+ - `isPmExtensionServiceNameContract`
194
+ - `isPmExtensionPolicyModeContract`
195
+ - `isPmExtensionPolicySurfaceContract`
196
+
197
+ ## Extension Example
198
+
199
+ ```ts
200
+ import { defineExtension } from "@unbrained/pm-cli/sdk";
201
+
202
+ export default defineExtension({
203
+ activate(api) {
204
+ api.registerCommand({
205
+ name: "release audit",
206
+ action: "release-audit",
207
+ description: "Collect release-readiness diagnostics.",
208
+ intent: "Produce deterministic gate payloads for CI.",
209
+ run: async (context) => ({
210
+ ok: true,
211
+ command: context.command,
212
+ }),
213
+ });
214
+ },
215
+ });
216
+ ```
217
+
218
+ ## Contracts-First Automation Pattern
219
+
220
+ ```ts
221
+ import { PM_TOOL_ACTION_PARAMETER_CONTRACTS, isPmToolAction } from "@unbrained/pm-cli/sdk";
222
+ import { spawnSync } from "node:child_process";
223
+
224
+ const action = "extension-reload";
225
+ if (!isPmToolAction(action)) throw new Error("Unsupported action");
226
+ const contract = PM_TOOL_ACTION_PARAMETER_CONTRACTS[action];
227
+ console.log(contract.required, contract.optional);
228
+
229
+ const contracts = spawnSync("pm", ["contracts", "--json"], { encoding: "utf8" });
230
+ if (contracts.status !== 0) throw new Error(contracts.stderr);
231
+ ```
232
+
233
+ ## Runtime Metadata Added For v2
234
+
235
+ `pm contracts --json` now includes richer extension metadata:
236
+
237
+ - `extension_contracts.trust_modes`
238
+ - `extension_contracts.sandbox_profiles`
239
+ - `extension_contracts.manifest_versions`
240
+ - `extension_contracts.compatibility`
241
+ - `action_availability[].policy_state` for extension-backed actions
242
+
243
+ Use these fields to gate CI and to route compatibility behavior in embedded runtimes.
244
+
245
+ ## Versioned-Breaking Compatibility
246
+
247
+ Current contract compatibility model:
248
+
249
+ - `manifest` current: `v2`
250
+ - supported previous: `v1`
251
+ - strategy: `versioned_breaking`
252
+
253
+ Recommended migration flow:
254
+
255
+ 1. read runtime contracts (`pm contracts --json`)
256
+ 2. branch behavior by compatibility metadata
257
+ 3. migrate manifests/policy to v2
258
+ 4. enforce trust/sandbox policy gates in CI
259
+
260
+ ## Runnable Examples
261
+
262
+ - contracts consumer: `docs/examples/sdk-contract-consumer/`
263
+ - app embedding runner: `docs/examples/sdk-app-embedding/`
264
+ - CI gates: `docs/examples/ci/`
265
+
266
+ ## Related Docs
267
+
268
+ - `docs/EXTENSIONS.md`
269
+ - `docs/CLAUDE_CODE_PLUGIN.md`
270
+ # SDK
271
+
272
+ The stable integration surface is `@unbrained/pm-cli/sdk`. Use it for extension authoring, action/flag contract discovery, and deterministic app/CI automation.
273
+
274
+ ## Install
275
+
276
+ ```bash
277
+ npm install @unbrained/pm-cli
278
+ ```
279
+
280
+ ```ts
281
+ import {
282
+ defineExtension,
283
+ EXTENSION_CAPABILITIES,
284
+ EXTENSION_POLICY_MODES,
285
+ EXTENSION_POLICY_SURFACES,
286
+ PM_TOOL_ACTIONS,
287
+ PM_TOOL_PARAMETERS_SCHEMA,
288
+ PM_TOOL_ACTION_PARAMETER_CONTRACTS,
289
+ PM_EXTENSION_CAPABILITY_CONTRACTS,
290
+ PM_EXTENSION_SERVICE_NAME_CONTRACTS,
291
+ PM_EXTENSION_POLICY_MODE_CONTRACTS,
292
+ PM_EXTENSION_POLICY_SURFACE_CONTRACTS,
293
+ isPmToolAction,
294
+ isPmExtensionCapabilityContract,
295
+ } from "@unbrained/pm-cli/sdk";
296
+ ```
297
+
298
+ ## What Is Exported
299
+
300
+ Core authoring exports:
301
+
302
+ - `defineExtension`
303
+ - `EXTENSION_CAPABILITIES`
304
+ - `EXTENSION_CAPABILITY_CONTRACT`
305
+ - `EXTENSION_POLICY_MODES`
306
+ - `EXTENSION_POLICY_SURFACES`
307
+
308
+ Command/action contract exports:
309
+
310
+ - `PM_CORE_COMMAND_NAMES`
311
+ - `PM_TOOL_ACTIONS`
312
+ - `PM_TOOL_PARAMETERS_SCHEMA`
313
+ - `PM_PI_TOOL_PARAMETERS_SCHEMA`
314
+ - `PM_TOOL_ACTION_PARAMETER_CONTRACTS`
315
+
316
+ Extension runtime contract exports:
317
+
318
+ - `PM_EXTENSION_CAPABILITY_CONTRACTS`
319
+ - `PM_EXTENSION_SERVICE_NAME_CONTRACTS`
320
+ - `PM_EXTENSION_POLICY_MODE_CONTRACTS`
321
+ - `PM_EXTENSION_POLICY_SURFACE_CONTRACTS`
322
+
323
+ Type guards:
324
+
325
+ - `isPmToolAction(value)`
326
+ - `isPmExtensionCapabilityContract(value)`
327
+ - `isPmExtensionServiceNameContract(value)`
328
+ - `isPmExtensionPolicyModeContract(value)`
329
+ - `isPmExtensionPolicySurfaceContract(value)`
330
+
331
+ ## Capability Mapping
332
+
333
+ - `commands` -> `registerCommand`
334
+ - `schema` -> `registerFlags`, `registerItemFields`, `registerItemTypes`, `registerMigration`
335
+ - `importers` -> `registerImporter`, `registerExporter`
336
+ - `search` -> `registerSearchProvider`, `registerVectorStoreAdapter`
337
+ - `hooks` -> `api.hooks.*`
338
+ - `parser` -> `registerParser`
339
+ - `preflight` -> `registerPreflight`
340
+ - `services` -> `registerService`
341
+ - `renderers` -> `registerRenderer`
342
+
343
+ ## Extension Authoring Example
344
+
345
+ ```ts
346
+ import { defineExtension } from "@unbrained/pm-cli/sdk";
347
+
348
+ export default defineExtension({
349
+ activate(api) {
350
+ api.registerCommand({
351
+ name: "release audit",
352
+ action: "release-audit",
353
+ description: "Collect release readiness diagnostics.",
354
+ intent: "provide deterministic audit payloads for CI gates",
355
+ examples: ["pm release audit --strict"],
356
+ failure_hints: ["Run pm extension --doctor --detail deep --trace on activation failures."],
357
+ flags: [{ long: "--strict", description: "Enable strict gate mode." }],
358
+ run: async (context) => ({
359
+ ok: true,
360
+ command: context.command,
361
+ strict: context.options.strict === true,
362
+ }),
363
+ });
364
+ },
365
+ });
366
+ ```
367
+
368
+ ## Programmatic Contracts (App/Script)
369
+
370
+ Use runtime `pm contracts` for extension-aware schemas:
371
+
372
+ ```bash
373
+ pm contracts --json
374
+ pm contracts --schema-only --json
375
+ pm contracts --command extension --flags-only --json
376
+ pm contracts --action create --schema-only --json
377
+ ```
378
+
379
+ The result includes:
380
+
381
+ - `actions`: runtime-invocable action list
382
+ - `action_availability`: invocable/disabled reasons
383
+ - `schema`: strict action-scoped JSON schema
384
+ - `command_flags`: merged core + extension + runtime field flags
385
+ - `extension_contracts`: capabilities/services/policy mode/surface contract metadata
386
+
387
+ ## Robust Script Pattern
388
+
389
+ See runnable example: `docs/examples/sdk-contract-consumer/inspect-contracts.mjs`.
390
+
391
+ Minimal pattern:
392
+
393
+ 1. Read contracts JSON.
394
+ 2. Validate action exists in `actions`.
395
+ 3. Validate required fields with `PM_TOOL_ACTION_PARAMETER_CONTRACTS`.
396
+ 4. Execute the action only after preflight passes.
397
+
398
+ ## CI/CD Pattern
399
+
400
+ Recommended gate sequence:
401
+
402
+ ```bash
403
+ pnpm build
404
+ pm contracts --schema-only --json > /tmp/pm-contracts.json
405
+ pm extension --doctor --project --detail summary --strict-exit
406
+ node scripts/run-tests.mjs test -- tests/unit/contracts-command.spec.ts
407
+ node scripts/run-tests.mjs coverage
408
+ ```
409
+
410
+ Reference workflow file:
411
+
412
+ - `docs/examples/ci/github-actions-pm-extension-gate.yml`
413
+
414
+ ## Pi / Tooling Compatibility
415
+
416
+ For provider-safe schemas, use `PM_PI_TOOL_PARAMETERS_SCHEMA`. It is flat, non-`oneOf`, and designed for tool providers that reject advanced schema constructs.
417
+
418
+ The bundled Pi wrapper (`.pi/extensions/pm-cli/index.js`) consumes this schema directly to reduce contract drift.
419
+
420
+ ## Related Docs
421
+
422
+ - `docs/EXTENSIONS.md`
423
+ - `docs/examples/starter-extension/README.md`
424
+ - `docs/examples/sdk-contract-consumer/README.md`
425
+ # SDK
426
+
3
427
  The public SDK is exported from `@unbrained/pm-cli/sdk`. Use it for extension authoring and command-contract introspection. Do not import internal `src/core/...` modules from extensions.
4
428
 
5
429
  ## Agent Quick Context
@@ -167,6 +591,22 @@ pm contracts --action create --schema-only --json
167
591
 
168
592
  Use the runtime command because active extensions can add command/action metadata.
169
593
 
594
+ ## CLI Simplification Migration
595
+
596
+ The conservative full-surface simplification pass updated invocation parsing and error envelopes. Integration details are documented in:
597
+
598
+ - [CLI Simplification Migration](MIGRATION_CLI_SIMPLIFICATION.md)
599
+
600
+ For SDK and automation consumers, the key runtime change is the optional `recovery` object in CLI usage/error JSON payloads:
601
+
602
+ - `attempted_command`
603
+ - `normalized_args`
604
+ - `provided_fields`
605
+ - `missing`
606
+ - `suggested_retry`
607
+
608
+ Treat `recovery.suggested_retry` as the first-choice deterministic replay command when present.
609
+
170
610
  ## Authoring Pattern
171
611
 
172
612
  - Keep handlers deterministic and JSON-like.
@@ -179,5 +619,6 @@ Use the runtime command because active extensions can add command/action metadat
179
619
  ## Related Docs
180
620
 
181
621
  - [Extensions](EXTENSIONS.md)
622
+ - [CLI Simplification Migration](MIGRATION_CLI_SIMPLIFICATION.md)
182
623
  - [Architecture](ARCHITECTURE.md)
183
624
  - [starter extension](examples/starter-extension/README.md)