@unbrained/pm-cli 2026.5.10 → 2026.5.12

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 (172) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/AGENTS.md +3 -116
  3. package/CHANGELOG.md +14 -0
  4. package/PRD.md +11 -11
  5. package/README.md +20 -2
  6. package/dist/cli/argv-utils.d.ts +5 -0
  7. package/dist/cli/argv-utils.js +34 -0
  8. package/dist/cli/argv-utils.js.map +1 -0
  9. package/dist/cli/bootstrap-args.d.ts +15 -0
  10. package/dist/cli/bootstrap-args.js +211 -0
  11. package/dist/cli/bootstrap-args.js.map +1 -1
  12. package/dist/cli/commander-usage.js +109 -3
  13. package/dist/cli/commander-usage.js.map +1 -1
  14. package/dist/cli/commands/completion.js +7 -3
  15. package/dist/cli/commands/completion.js.map +1 -1
  16. package/dist/cli/commands/contracts.d.ts +19 -0
  17. package/dist/cli/commands/contracts.js +40 -2
  18. package/dist/cli/commands/contracts.js.map +1 -1
  19. package/dist/cli/commands/create.js +112 -51
  20. package/dist/cli/commands/create.js.map +1 -1
  21. package/dist/cli/commands/docs.js +9 -2
  22. package/dist/cli/commands/docs.js.map +1 -1
  23. package/dist/cli/commands/extension.d.ts +12 -3
  24. package/dist/cli/commands/extension.js +421 -69
  25. package/dist/cli/commands/extension.js.map +1 -1
  26. package/dist/cli/commands/files.js +9 -2
  27. package/dist/cli/commands/files.js.map +1 -1
  28. package/dist/cli/commands/index.d.ts +1 -0
  29. package/dist/cli/commands/index.js +1 -0
  30. package/dist/cli/commands/index.js.map +1 -1
  31. package/dist/cli/commands/init.d.ts +2 -0
  32. package/dist/cli/commands/init.js +21 -1
  33. package/dist/cli/commands/init.js.map +1 -1
  34. package/dist/cli/commands/metadata-normalizers.d.ts +4 -0
  35. package/dist/cli/commands/metadata-normalizers.js +37 -0
  36. package/dist/cli/commands/metadata-normalizers.js.map +1 -0
  37. package/dist/cli/commands/reindex.js +173 -135
  38. package/dist/cli/commands/reindex.js.map +1 -1
  39. package/dist/cli/commands/search.js +16 -6
  40. package/dist/cli/commands/search.js.map +1 -1
  41. package/dist/cli/commands/test.js +23 -8
  42. package/dist/cli/commands/test.js.map +1 -1
  43. package/dist/cli/commands/update.js +70 -39
  44. package/dist/cli/commands/update.js.map +1 -1
  45. package/dist/cli/commands/upgrade.d.ts +63 -0
  46. package/dist/cli/commands/upgrade.js +260 -0
  47. package/dist/cli/commands/upgrade.js.map +1 -0
  48. package/dist/cli/error-guidance.d.ts +9 -1
  49. package/dist/cli/error-guidance.js +147 -6
  50. package/dist/cli/error-guidance.js.map +1 -1
  51. package/dist/cli/guide-topics.js +18 -16
  52. package/dist/cli/guide-topics.js.map +1 -1
  53. package/dist/cli/help-content.js +42 -2
  54. package/dist/cli/help-content.js.map +1 -1
  55. package/dist/cli/help-json-payload.js +11 -1
  56. package/dist/cli/help-json-payload.js.map +1 -1
  57. package/dist/cli/main.js +69 -6
  58. package/dist/cli/main.js.map +1 -1
  59. package/dist/cli/register-setup.js +174 -82
  60. package/dist/cli/register-setup.js.map +1 -1
  61. package/dist/cli/telemetry-flush.d.ts +2 -0
  62. package/dist/cli/telemetry-flush.js +4 -0
  63. package/dist/cli/telemetry-flush.js.map +1 -0
  64. package/dist/cli.js +1 -2
  65. package/dist/cli.js.map +1 -1
  66. package/dist/core/extensions/extension-types.d.ts +72 -0
  67. package/dist/core/extensions/extension-types.js +24 -0
  68. package/dist/core/extensions/extension-types.js.map +1 -1
  69. package/dist/core/extensions/loader.d.ts +1 -0
  70. package/dist/core/extensions/loader.js +766 -7
  71. package/dist/core/extensions/loader.js.map +1 -1
  72. package/dist/core/lock/lock.js +2 -0
  73. package/dist/core/lock/lock.js.map +1 -1
  74. package/dist/core/packages/manifest.d.ts +13 -0
  75. package/dist/core/packages/manifest.js +139 -0
  76. package/dist/core/packages/manifest.js.map +1 -0
  77. package/dist/core/sentry/instrument.d.ts +15 -0
  78. package/dist/core/sentry/instrument.js +35 -3
  79. package/dist/core/sentry/instrument.js.map +1 -1
  80. package/dist/core/shared/constants.js +20 -0
  81. package/dist/core/shared/constants.js.map +1 -1
  82. package/dist/core/shared/errors.d.ts +8 -0
  83. package/dist/core/shared/errors.js.map +1 -1
  84. package/dist/core/shared/levenshtein.d.ts +1 -0
  85. package/dist/core/shared/levenshtein.js +37 -0
  86. package/dist/core/shared/levenshtein.js.map +1 -0
  87. package/dist/core/store/paths.js +34 -1
  88. package/dist/core/store/paths.js.map +1 -1
  89. package/dist/core/store/settings.js +210 -1
  90. package/dist/core/store/settings.js.map +1 -1
  91. package/dist/core/telemetry/runtime.d.ts +1 -0
  92. package/dist/core/telemetry/runtime.js +102 -3
  93. package/dist/core/telemetry/runtime.js.map +1 -1
  94. package/dist/mcp/server.js +11 -2
  95. package/dist/mcp/server.js.map +1 -1
  96. package/dist/sdk/cli-contracts.d.ts +38 -17
  97. package/dist/sdk/cli-contracts.js +387 -35
  98. package/dist/sdk/cli-contracts.js.map +1 -1
  99. package/dist/sdk/index.d.ts +13 -1
  100. package/dist/sdk/index.js +9 -1
  101. package/dist/sdk/index.js.map +1 -1
  102. package/dist/types.d.ts +41 -0
  103. package/dist/types.js.map +1 -1
  104. package/docs/ARCHITECTURE.md +1 -1
  105. package/docs/CLAUDE_CODE_PLUGIN.md +39 -0
  106. package/docs/COMMANDS.md +14 -1
  107. package/docs/EXTENSIONS.md +782 -12
  108. package/docs/MIGRATION_CLI_SIMPLIFICATION.md +64 -0
  109. package/docs/QUICKSTART.md +10 -2
  110. package/docs/README.md +4 -6
  111. package/docs/SDK.md +445 -0
  112. package/docs/examples/ci/github-actions-pm-extension-gate.yml +53 -0
  113. package/docs/examples/ci/gitlab-ci-pm-extension-gate.yml +41 -0
  114. package/docs/examples/ci/jenkins-pm-extension-gate.Jenkinsfile +45 -0
  115. package/docs/examples/policy-restricted-extension/README.md +74 -0
  116. package/docs/examples/policy-restricted-extension/index.js +21 -0
  117. package/docs/examples/policy-restricted-extension/manifest.json +21 -0
  118. package/docs/examples/policy-restricted-extension/package.json +8 -0
  119. package/docs/examples/sdk-app-embedding/README.md +39 -0
  120. package/docs/examples/sdk-app-embedding/package.json +9 -0
  121. package/docs/examples/sdk-app-embedding/run-embedded-pm.mjs +61 -0
  122. package/docs/examples/sdk-contract-consumer/README.md +57 -0
  123. package/docs/examples/sdk-contract-consumer/inspect-contracts.mjs +47 -0
  124. package/docs/examples/sdk-contract-consumer/package.json +10 -0
  125. package/docs/examples/starter-extension/README.md +57 -42
  126. package/docs/examples/starter-extension/manifest.json +15 -0
  127. package/marketplace.json +3 -3
  128. package/package.json +5 -23
  129. package/packages/pm-beads/README.md +10 -0
  130. package/{.agents/pm → packages/pm-beads}/extensions/beads/index.js +24 -9
  131. package/packages/pm-beads/extensions/beads/index.ts +131 -0
  132. package/packages/pm-beads/package.json +17 -0
  133. package/packages/pm-todos/README.md +11 -0
  134. package/{.agents/pm → packages/pm-todos}/extensions/todos/index.js +24 -9
  135. package/packages/pm-todos/extensions/todos/index.ts +149 -0
  136. package/{.agents/pm → packages/pm-todos}/extensions/todos/runtime.js +1 -1
  137. package/{.agents/pm → packages/pm-todos}/extensions/todos/runtime.ts +1 -1
  138. package/packages/pm-todos/package.json +17 -0
  139. package/plugins/pm-cli-claude/.claude-plugin/plugin.json +2 -2
  140. package/plugins/pm-cli-claude/README.md +54 -14
  141. package/plugins/pm-cli-claude/agents/pm-delivery-chain.md +88 -0
  142. package/plugins/pm-cli-claude/agents/pm-triage-agent.md +83 -0
  143. package/plugins/pm-cli-claude/agents/pm-verification-agent.md +88 -0
  144. package/plugins/pm-cli-claude/hooks/session-start.mjs +35 -21
  145. package/.agents/pm/extensions/.managed-extensions.json +0 -42
  146. package/.agents/skills/HARNESS_COMPATIBILITY.md +0 -45
  147. package/.agents/skills/README.md +0 -21
  148. package/.agents/skills/pm-developer/SKILL.md +0 -73
  149. package/.agents/skills/pm-developer/references/COMMAND_PLAYBOOK.md +0 -48
  150. package/.agents/skills/pm-developer/references/PROMPTS.md +0 -17
  151. package/.agents/skills/pm-extensions/SKILL.md +0 -57
  152. package/.agents/skills/pm-extensions/references/LIFECYCLE.md +0 -40
  153. package/.agents/skills/pm-extensions/references/TROUBLESHOOTING.md +0 -25
  154. package/.agents/skills/pm-sdk/SKILL.md +0 -50
  155. package/.agents/skills/pm-sdk/references/INTEGRATION_CHECKLIST.md +0 -31
  156. package/.agents/skills/pm-sdk/references/PROMPTS.md +0 -13
  157. package/.agents/skills/pm-user/SKILL.md +0 -59
  158. package/.agents/skills/pm-user/references/PROMPTS.md +0 -17
  159. package/.agents/skills/pm-user/references/WORKFLOWS.md +0 -35
  160. package/.pi/README.md +0 -26
  161. package/.pi/extensions/pm-cli/index.js +0 -147
  162. package/.pi/prompts/pm-workflow.md +0 -5
  163. package/.pi/skills/pm-native/SKILL.md +0 -40
  164. package/.pi/skills/pm-release/SKILL.md +0 -35
  165. package/dist/pi/native.d.ts +0 -5
  166. package/dist/pi/native.js +0 -183
  167. package/dist/pi/native.js.map +0 -1
  168. package/docs/PI_PACKAGE.md +0 -56
  169. /package/{.agents/pm → packages/pm-beads}/extensions/beads/manifest.json +0 -0
  170. /package/{.agents/pm → packages/pm-beads}/extensions/beads/runtime.js +0 -0
  171. /package/{.agents/pm → packages/pm-beads}/extensions/beads/runtime.ts +0 -0
  172. /package/{.agents/pm → packages/pm-todos}/extensions/todos/manifest.json +0 -0
@@ -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
+
@@ -23,10 +23,10 @@ pm --version
23
23
  For updates, use the registry package again:
24
24
 
25
25
  ```bash
26
- npm install -g @unbrained/pm-cli@latest
26
+ pm upgrade --cli-only
27
27
  ```
28
28
 
29
- Do not use the GitHub git URL as the normal global update path. If a previous git-sourced install left a stale `pm` shim, run `bash scripts/install.sh --repair` from a checkout or uninstall the package before reinstalling from npm.
29
+ `pm upgrade` uses `npm install -g @unbrained/pm-cli@latest` for the CLI/SDK and can also refresh installed pm packages. Do not use the GitHub git URL as the normal global update path. If a previous git-sourced install left a stale `pm` shim, run `pm upgrade --cli-only --repair`, run `bash scripts/install.sh --repair` from a checkout, or uninstall the package before reinstalling from npm.
30
30
 
31
31
  For one-off use:
32
32
 
@@ -34,6 +34,14 @@ For one-off use:
34
34
  npx @unbrained/pm-cli --help
35
35
  ```
36
36
 
37
+ Optional first-party packages are installable on demand:
38
+
39
+ ```bash
40
+ pm install '*' --project
41
+ pm install all --project
42
+ pm package doctor --project --detail summary
43
+ ```
44
+
37
45
  ## Initialize a Repository
38
46
 
39
47
  ```bash
package/docs/README.md CHANGED
@@ -21,8 +21,7 @@ pm guide release --json
21
21
  | New user | [Quickstart](QUICKSTART.md) | [Command Reference](COMMANDS.md) |
22
22
  | Coding agent | [Agent Guide](AGENT_GUIDE.md) | [Configuration](CONFIGURATION.md), then command help |
23
23
  | Maintainer | [Contributing](../CONTRIBUTING.md) | [Testing](TESTING.md), [Releasing](RELEASING.md), [Architecture](ARCHITECTURE.md) |
24
- | Extension author | [Extensions](EXTENSIONS.md) | [SDK](SDK.md), [starter extension](examples/starter-extension/README.md) |
25
- | Pi user | [Pi Package](PI_PACKAGE.md) | [Agent Guide](AGENT_GUIDE.md), then [Command Reference](COMMANDS.md) |
24
+ | Package author | [Packages and Extensions](EXTENSIONS.md) | [SDK](SDK.md), [starter extension](examples/starter-extension/README.md) |
26
25
  | Codex user | [Codex Plugin](CODEX_PLUGIN.md) | [Agent Guide](AGENT_GUIDE.md), then [Command Reference](COMMANDS.md) |
27
26
  | Machine client | `pm guide commands` | [Command Reference](COMMANDS.md#machine-contracts), then `pm contracts --json` |
28
27
 
@@ -34,9 +33,8 @@ pm guide release --json
34
33
  - [Configuration](CONFIGURATION.md) - settings, storage formats, output, search, validation, and environment variables.
35
34
  - [Testing](TESTING.md) - sandbox-safe local tests and linked-test orchestration.
36
35
  - [Architecture](ARCHITECTURE.md) - contributor internals: storage, mutation flow, search, extensions, and command contracts.
37
- - [Extensions](EXTENSIONS.md) - runtime extension lifecycle and API reference.
36
+ - [Packages and Extensions](EXTENSIONS.md) - package install workflows, runtime extension lifecycle, and API reference.
38
37
  - [SDK](SDK.md) - public import surfaces and typed authoring examples.
39
- - [Pi Package](PI_PACKAGE.md) - official Pi package install, native tool, skills, prompts, and workflows.
40
38
  - [Codex Plugin](CODEX_PLUGIN.md) - native MCP plugin install, tools, skills, and safety notes.
41
39
  - [Releasing](RELEASING.md) - maintainer release checklist and failure handling.
42
40
  - [starter extension](examples/starter-extension/README.md) - compact extension scaffold reference.
@@ -49,7 +47,7 @@ pm guide release --json
49
47
  | `commands` | [Command Reference](COMMANDS.md), [Configuration](CONFIGURATION.md) |
50
48
  | `workflows` | [Agent Guide](AGENT_GUIDE.md), [Testing](TESTING.md) |
51
49
  | `sdk` | [SDK](SDK.md), [Architecture](ARCHITECTURE.md) |
52
- | `extensions` | [Extensions](EXTENSIONS.md), [starter extension](examples/starter-extension/README.md) |
50
+ | `extensions`, `packages` | [Packages and Extensions](EXTENSIONS.md), [starter extension](examples/starter-extension/README.md) |
53
51
  | `skills` | [Agent Guide](AGENT_GUIDE.md) plus `.agents/skills/*` |
54
52
  | `harnesses` | [Agent Guide](AGENT_GUIDE.md) plus `.agents/skills/HARNESS_COMPATIBILITY.md` |
55
53
  | `release` | [Releasing](RELEASING.md), [CHANGELOG](../CHANGELOG.md) |
@@ -68,7 +66,7 @@ Community files:
68
66
  2. Use [Command Reference](COMMANDS.md) for command families, not exhaustive flag memory.
69
67
  3. Use `pm <command> --help --json` or `pm contracts --command <name> --flags-only --json` for exact flags.
70
68
  4. Use [Architecture](ARCHITECTURE.md) only when changing internals or debugging behavior.
71
- 5. Use [SDK](SDK.md) and [Extensions](EXTENSIONS.md) only when authoring or troubleshooting extensions.
69
+ 5. Use [SDK](SDK.md) and [Packages and Extensions](EXTENSIONS.md) only when authoring or troubleshooting packages/extensions.
72
70
 
73
71
  ## Tracker References
74
72
 
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_PROVIDER_TOOL_PARAMETERS_SCHEMA`
33
+ - `PM_TOOL_ACTION_PARAMETER_CONTRACTS`
34
+
35
+ `PM_TOOL_ACTIONS` includes the package lifecycle actions and `upgrade`, so agents and apps can discover `pm upgrade` through `pm contracts` instead of hard-coding flags.
36
+
37
+ ### Runtime contract constants
38
+
39
+ - `PM_EXTENSION_CAPABILITY_CONTRACTS`
40
+ - `PM_EXTENSION_SERVICE_NAME_CONTRACTS`
41
+ - `PM_EXTENSION_POLICY_MODE_CONTRACTS`
42
+ - `PM_EXTENSION_POLICY_SURFACE_CONTRACTS`
43
+ - `PM_EXTENSION_TRUST_MODE_CONTRACTS`
44
+ - `PM_EXTENSION_SANDBOX_PROFILE_CONTRACTS`
45
+
46
+ ### Type guards
47
+
48
+ - `isPmToolAction`
49
+ - `isPmExtensionCapabilityContract`
50
+ - `isPmExtensionServiceNameContract`
51
+ - `isPmExtensionPolicyModeContract`
52
+ - `isPmExtensionPolicySurfaceContract`
53
+
54
+ ## Capability Mapping
55
+
56
+ - `commands` -> `registerCommand`
57
+ - `schema` -> `registerFlags`, `registerItemFields`, `registerItemTypes`, `registerMigration`
58
+ - `importers` -> `registerImporter`, `registerExporter`
59
+ - `search` -> `registerSearchProvider`, `registerVectorStoreAdapter`
60
+ - `hooks` -> `api.hooks.*`
61
+ - `parser` -> `registerParser`
62
+ - `preflight` -> `registerPreflight`
63
+ - `services` -> `registerService`
64
+ - `renderers` -> `registerRenderer`
65
+
66
+ ## Extension Example
67
+
68
+ ```ts
69
+ import { defineExtension } from "@unbrained/pm-cli/sdk";
70
+
71
+ export default defineExtension({
72
+ activate(api) {
73
+ api.registerCommand({
74
+ name: "release audit",
75
+ action: "release-audit",
76
+ description: "Collect release-readiness diagnostics.",
77
+ intent: "Produce deterministic gate payloads for CI.",
78
+ flags: [{ long: "--strict", description: "Enable strict gate mode." }],
79
+ run: async (context) => ({
80
+ ok: true,
81
+ command: context.command,
82
+ strict: context.options.strict === true,
83
+ }),
84
+ });
85
+ },
86
+ });
87
+ ```
88
+
89
+ ## Contracts-First Automation
90
+
91
+ Use runtime contracts for extension-aware schemas:
92
+
93
+ ```bash
94
+ pm contracts --json
95
+ pm contracts --schema-only --json
96
+ pm contracts --command package --flags-only --json
97
+ pm contracts --action create --schema-only --json
98
+ ```
99
+
100
+ Minimal script pattern:
101
+
102
+ ```ts
103
+ import { PM_TOOL_ACTION_PARAMETER_CONTRACTS, isPmToolAction } from "@unbrained/pm-cli/sdk";
104
+ import { spawnSync } from "node:child_process";
105
+
106
+ const action = "package-reload";
107
+ if (!isPmToolAction(action)) throw new Error("Unsupported action");
108
+ const contract = PM_TOOL_ACTION_PARAMETER_CONTRACTS[action];
109
+ console.log(contract.required, contract.optional);
110
+
111
+ const result = spawnSync("pm", ["contracts", "--json"], { encoding: "utf8" });
112
+ if (result.status !== 0) throw new Error(result.stderr);
113
+ ```
114
+
115
+ ## Compatibility Metadata
116
+
117
+ `pm contracts --json` includes compatibility metadata for extension integrations:
118
+
119
+ - `extension_contracts.trust_modes`
120
+ - `extension_contracts.sandbox_profiles`
121
+ - `extension_contracts.manifest_versions`
122
+ - `extension_contracts.compatibility`
123
+ - `action_availability[].policy_state`
124
+
125
+ Current compatibility model:
126
+
127
+ - manifest current: `v2`
128
+ - supported previous: `v1`
129
+ - strategy: `versioned_breaking`
130
+
131
+ ## Runnable Examples
132
+
133
+ - `docs/examples/sdk-contract-consumer/`
134
+ - `docs/examples/sdk-app-embedding/`
135
+ - `docs/examples/ci/`
136
+
137
+ ## Related Docs
138
+
139
+ - `docs/EXTENSIONS.md`
140
+ - `docs/CLAUDE_CODE_PLUGIN.md`
141
+ # SDK
142
+
143
+ The supported programmatic surface is `@unbrained/pm-cli/sdk`.
144
+
145
+ Use this for:
146
+
147
+ - extension authoring (`defineExtension`)
148
+ - command/action schema discovery (`PM_TOOL_PARAMETERS_SCHEMA`)
149
+ - runtime action contracts (`PM_TOOL_ACTION_PARAMETER_CONTRACTS`)
150
+ - capability/policy/trust/sandbox contract constants
151
+
152
+ Do not import private `src/core/...` modules from external integrations.
153
+
154
+ ## Install
155
+
156
+ ```bash
157
+ npm install @unbrained/pm-cli
158
+ ```
159
+
160
+ ## Key Exports
161
+
162
+ ### Extension Authoring
163
+
164
+ - `defineExtension`
165
+ - `EXTENSION_CAPABILITIES`
166
+ - `EXTENSION_POLICY_MODES`
167
+ - `EXTENSION_POLICY_SURFACES`
168
+ - `EXTENSION_TRUST_MODES`
169
+ - `EXTENSION_SANDBOX_PROFILES`
170
+ - `EXTENSION_CAPABILITY_CONTRACT`
171
+ - `EXTENSION_CAPABILITY_CONTRACT_VERSION`
172
+ - `EXTENSION_CAPABILITY_LEGACY_ALIASES`
173
+
174
+ ### Command/Action Contracts
175
+
176
+ - `PM_CORE_COMMAND_NAMES`
177
+ - `PM_TOOL_ACTIONS`
178
+ - `PM_TOOL_PARAMETERS_SCHEMA`
179
+ - `PM_PROVIDER_TOOL_PARAMETERS_SCHEMA`
180
+ - `PM_TOOL_ACTION_PARAMETER_CONTRACTS`
181
+
182
+ ### Extension Runtime Contract Constants
183
+
184
+ - `PM_EXTENSION_CAPABILITY_CONTRACTS`
185
+ - `PM_EXTENSION_SERVICE_NAME_CONTRACTS`
186
+ - `PM_EXTENSION_POLICY_MODE_CONTRACTS`
187
+ - `PM_EXTENSION_POLICY_SURFACE_CONTRACTS`
188
+ - `PM_EXTENSION_TRUST_MODE_CONTRACTS`
189
+ - `PM_EXTENSION_SANDBOX_PROFILE_CONTRACTS`
190
+
191
+ ### Type Guards
192
+
193
+ - `isPmToolAction`
194
+ - `isPmExtensionCapabilityContract`
195
+ - `isPmExtensionServiceNameContract`
196
+ - `isPmExtensionPolicyModeContract`
197
+ - `isPmExtensionPolicySurfaceContract`
198
+
199
+ ## Extension Example
200
+
201
+ ```ts
202
+ import { defineExtension } from "@unbrained/pm-cli/sdk";
203
+
204
+ export default defineExtension({
205
+ activate(api) {
206
+ api.registerCommand({
207
+ name: "release audit",
208
+ action: "release-audit",
209
+ description: "Collect release-readiness diagnostics.",
210
+ intent: "Produce deterministic gate payloads for CI.",
211
+ run: async (context) => ({
212
+ ok: true,
213
+ command: context.command,
214
+ }),
215
+ });
216
+ },
217
+ });
218
+ ```
219
+
220
+ ## Contracts-First Automation Pattern
221
+
222
+ ```ts
223
+ import { PM_TOOL_ACTION_PARAMETER_CONTRACTS, isPmToolAction } from "@unbrained/pm-cli/sdk";
224
+ import { spawnSync } from "node:child_process";
225
+
226
+ const action = "extension-reload";
227
+ if (!isPmToolAction(action)) throw new Error("Unsupported action");
228
+ const contract = PM_TOOL_ACTION_PARAMETER_CONTRACTS[action];
229
+ console.log(contract.required, contract.optional);
230
+
231
+ const contracts = spawnSync("pm", ["contracts", "--json"], { encoding: "utf8" });
232
+ if (contracts.status !== 0) throw new Error(contracts.stderr);
233
+ ```
234
+
235
+ ## Runtime Metadata Added For v2
236
+
237
+ `pm contracts --json` now includes richer extension metadata:
238
+
239
+ - `extension_contracts.trust_modes`
240
+ - `extension_contracts.sandbox_profiles`
241
+ - `extension_contracts.manifest_versions`
242
+ - `extension_contracts.compatibility`
243
+ - `action_availability[].policy_state` for extension-backed actions
244
+
245
+ Use these fields to gate CI and to route compatibility behavior in embedded runtimes.
246
+
247
+ ## Versioned-Breaking Compatibility
248
+
249
+ Current contract compatibility model:
250
+
251
+ - `manifest` current: `v2`
252
+ - supported previous: `v1`
253
+ - strategy: `versioned_breaking`
254
+
255
+ Recommended migration flow:
256
+
257
+ 1. read runtime contracts (`pm contracts --json`)
258
+ 2. branch behavior by compatibility metadata
259
+ 3. migrate manifests/policy to v2
260
+ 4. enforce trust/sandbox policy gates in CI
261
+
262
+ ## Runnable Examples
263
+
264
+ - contracts consumer: `docs/examples/sdk-contract-consumer/`
265
+ - app embedding runner: `docs/examples/sdk-app-embedding/`
266
+ - CI gates: `docs/examples/ci/`
267
+
268
+ ## Related Docs
269
+
270
+ - `docs/EXTENSIONS.md`
271
+ - `docs/CLAUDE_CODE_PLUGIN.md`
272
+ # SDK
273
+
274
+ The stable integration surface is `@unbrained/pm-cli/sdk`. Use it for extension authoring, action/flag contract discovery, and deterministic app/CI automation.
275
+
276
+ ## Install
277
+
278
+ ```bash
279
+ npm install @unbrained/pm-cli
280
+ ```
281
+
282
+ ```ts
283
+ import {
284
+ defineExtension,
285
+ EXTENSION_CAPABILITIES,
286
+ EXTENSION_POLICY_MODES,
287
+ EXTENSION_POLICY_SURFACES,
288
+ PM_TOOL_ACTIONS,
289
+ PM_TOOL_PARAMETERS_SCHEMA,
290
+ PM_TOOL_ACTION_PARAMETER_CONTRACTS,
291
+ PM_EXTENSION_CAPABILITY_CONTRACTS,
292
+ PM_EXTENSION_SERVICE_NAME_CONTRACTS,
293
+ PM_EXTENSION_POLICY_MODE_CONTRACTS,
294
+ PM_EXTENSION_POLICY_SURFACE_CONTRACTS,
295
+ isPmToolAction,
296
+ isPmExtensionCapabilityContract,
297
+ } from "@unbrained/pm-cli/sdk";
298
+ ```
299
+
300
+ ## What Is Exported
301
+
302
+ Core authoring exports:
303
+
304
+ - `defineExtension`
305
+ - `EXTENSION_CAPABILITIES`
306
+ - `EXTENSION_CAPABILITY_CONTRACT`
307
+ - `EXTENSION_POLICY_MODES`
308
+ - `EXTENSION_POLICY_SURFACES`
309
+
310
+ Command/action contract exports:
311
+
312
+ - `PM_CORE_COMMAND_NAMES`
313
+ - `PM_TOOL_ACTIONS`
314
+ - `PM_TOOL_PARAMETERS_SCHEMA`
315
+ - `PM_PROVIDER_TOOL_PARAMETERS_SCHEMA`
316
+ - `PM_TOOL_ACTION_PARAMETER_CONTRACTS`
317
+
318
+ Extension runtime contract exports:
319
+
320
+ - `PM_EXTENSION_CAPABILITY_CONTRACTS`
321
+ - `PM_EXTENSION_SERVICE_NAME_CONTRACTS`
322
+ - `PM_EXTENSION_POLICY_MODE_CONTRACTS`
323
+ - `PM_EXTENSION_POLICY_SURFACE_CONTRACTS`
324
+
325
+ Type guards:
326
+
327
+ - `isPmToolAction(value)`
328
+ - `isPmExtensionCapabilityContract(value)`
329
+ - `isPmExtensionServiceNameContract(value)`
330
+ - `isPmExtensionPolicyModeContract(value)`
331
+ - `isPmExtensionPolicySurfaceContract(value)`
332
+
333
+ ## Capability Mapping
334
+
335
+ - `commands` -> `registerCommand`
336
+ - `schema` -> `registerFlags`, `registerItemFields`, `registerItemTypes`, `registerMigration`
337
+ - `importers` -> `registerImporter`, `registerExporter`
338
+ - `search` -> `registerSearchProvider`, `registerVectorStoreAdapter`
339
+ - `hooks` -> `api.hooks.*`
340
+ - `parser` -> `registerParser`
341
+ - `preflight` -> `registerPreflight`
342
+ - `services` -> `registerService`
343
+ - `renderers` -> `registerRenderer`
344
+
345
+ ## Extension Authoring Example
346
+
347
+ ```ts
348
+ import { defineExtension } from "@unbrained/pm-cli/sdk";
349
+
350
+ export default defineExtension({
351
+ activate(api) {
352
+ api.registerCommand({
353
+ name: "release audit",
354
+ action: "release-audit",
355
+ description: "Collect release readiness diagnostics.",
356
+ intent: "provide deterministic audit payloads for CI gates",
357
+ examples: ["pm release audit --strict"],
358
+ failure_hints: ["Run pm package doctor --detail deep --trace on activation failures."],
359
+ flags: [{ long: "--strict", description: "Enable strict gate mode." }],
360
+ run: async (context) => ({
361
+ ok: true,
362
+ command: context.command,
363
+ strict: context.options.strict === true,
364
+ }),
365
+ });
366
+ },
367
+ });
368
+ ```
369
+
370
+ ## Programmatic Contracts (App/Script)
371
+
372
+ Use runtime `pm contracts` for extension-aware schemas:
373
+
374
+ ```bash
375
+ pm contracts --json
376
+ pm contracts --schema-only --json
377
+ pm contracts --command package --flags-only --json
378
+ pm contracts --action create --schema-only --json
379
+ ```
380
+
381
+ The result includes:
382
+
383
+ - `actions`: runtime-invocable action list
384
+ - `action_availability`: invocable/disabled reasons
385
+ - `schema`: strict action-scoped JSON schema
386
+ - `command_flags`: merged core + extension + runtime field flags
387
+ - `extension_contracts`: capabilities/services/policy mode/surface contract metadata
388
+
389
+ ## Robust Script Pattern
390
+
391
+ See runnable example: `docs/examples/sdk-contract-consumer/inspect-contracts.mjs`.
392
+
393
+ Minimal pattern:
394
+
395
+ 1. Read contracts JSON.
396
+ 2. Validate action exists in `actions`.
397
+ 3. Validate required fields with `PM_TOOL_ACTION_PARAMETER_CONTRACTS`.
398
+ 4. Execute the action only after preflight passes.
399
+
400
+ ## CI/CD Pattern
401
+
402
+ Recommended gate sequence:
403
+
404
+ ```bash
405
+ pnpm build
406
+ pm contracts --schema-only --json > /tmp/pm-contracts.json
407
+ pm package doctor --project --detail summary --strict-exit
408
+ node scripts/run-tests.mjs test -- tests/unit/contracts-command.spec.ts
409
+ node scripts/run-tests.mjs coverage
410
+ ```
411
+
412
+ Reference workflow file:
413
+
414
+ - `docs/examples/ci/github-actions-pm-extension-gate.yml`
415
+
416
+ ## Tooling Compatibility
417
+
418
+ For provider-safe schemas, use `PM_PROVIDER_TOOL_PARAMETERS_SCHEMA`. It is flat, non-`oneOf`, and designed for tool providers that reject advanced schema constructs. Agent-specific adapters should consume this SDK export from their own packages instead of adding agent runtime code to the main `pm` CLI.
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
@@ -36,6 +460,10 @@ Common authoring exports:
36
460
  - `EXTENSION_CAPABILITY_CONTRACT`
37
461
  - `EXTENSION_CAPABILITY_CONTRACT_VERSION`
38
462
  - `EXTENSION_CAPABILITY_LEGACY_ALIASES`
463
+ - `PM_PACKAGE_RESOURCE_KINDS`
464
+ - `PM_PACKAGE_CONVENTIONAL_RESOURCE_ROOTS`
465
+ - `readPmPackageManifest`
466
+ - `collectPackageExtensionDirectories`
39
467
  - `PM_CORE_COMMAND_NAMES`
40
468
  - `PM_TOOL_ACTIONS`
41
469
  - `PM_TOOL_PARAMETERS_SCHEMA`
@@ -167,6 +595,22 @@ pm contracts --action create --schema-only --json
167
595
 
168
596
  Use the runtime command because active extensions can add command/action metadata.
169
597
 
598
+ ## CLI Simplification Migration
599
+
600
+ The conservative full-surface simplification pass updated invocation parsing and error envelopes. Integration details are documented in:
601
+
602
+ - [CLI Simplification Migration](MIGRATION_CLI_SIMPLIFICATION.md)
603
+
604
+ For SDK and automation consumers, the key runtime change is the optional `recovery` object in CLI usage/error JSON payloads:
605
+
606
+ - `attempted_command`
607
+ - `normalized_args`
608
+ - `provided_fields`
609
+ - `missing`
610
+ - `suggested_retry`
611
+
612
+ Treat `recovery.suggested_retry` as the first-choice deterministic replay command when present.
613
+
170
614
  ## Authoring Pattern
171
615
 
172
616
  - Keep handlers deterministic and JSON-like.
@@ -179,5 +623,6 @@ Use the runtime command because active extensions can add command/action metadat
179
623
  ## Related Docs
180
624
 
181
625
  - [Extensions](EXTENSIONS.md)
626
+ - [CLI Simplification Migration](MIGRATION_CLI_SIMPLIFICATION.md)
182
627
  - [Architecture](ARCHITECTURE.md)
183
628
  - [starter extension](examples/starter-extension/README.md)
@@ -0,0 +1,53 @@
1
+ name: pm-extension-gate
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - main
8
+
9
+ jobs:
10
+ extension-gate:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v4
15
+
16
+ - name: Setup Node
17
+ uses: actions/setup-node@v4
18
+ with:
19
+ node-version: 22
20
+ cache: pnpm
21
+
22
+ - name: Setup pnpm
23
+ uses: pnpm/action-setup@v4
24
+ with:
25
+ version: 10
26
+
27
+ - name: Install dependencies
28
+ run: pnpm install --frozen-lockfile
29
+
30
+ - name: Build
31
+ run: pnpm build
32
+
33
+ - name: Export contracts (schema + flags)
34
+ run: |
35
+ pm contracts --schema-only --json > contracts-schema.json
36
+ pm contracts --command extension --flags-only --json > contracts-extension-flags.json
37
+ pm contracts --json > contracts-runtime.json
38
+
39
+ - name: Verify extension contract compatibility metadata
40
+ run: |
41
+ node -e 'const fs=require("node:fs");const c=JSON.parse(fs.readFileSync("contracts-runtime.json","utf8"));if(!c.extension_contracts?.compatibility){throw new Error("missing extension compatibility metadata");}'
42
+
43
+ - name: Reload extensions
44
+ run: pm extension --reload --project --json
45
+
46
+ - name: Extension governance diagnostics gate
47
+ run: pm extension --doctor --project --detail summary --strict-exit
48
+
49
+ - name: Unit tests
50
+ run: node scripts/run-tests.mjs test -- tests/unit/contracts-command.spec.ts tests/unit/extension-loader.spec.ts tests/unit/extension-command.spec.ts
51
+
52
+ - name: Coverage
53
+ run: node scripts/run-tests.mjs coverage
@@ -0,0 +1,41 @@
1
+ image: node:22
2
+
3
+ stages:
4
+ - build
5
+ - contracts
6
+ - extension_gate
7
+ - test
8
+
9
+ before_script:
10
+ - corepack enable
11
+ - corepack prepare pnpm@10 --activate
12
+ - pnpm install --frozen-lockfile
13
+
14
+ build:
15
+ stage: build
16
+ script:
17
+ - pnpm build
18
+
19
+ contracts:
20
+ stage: contracts
21
+ script:
22
+ - node dist/cli.js contracts --schema-only --json > contracts-schema.json
23
+ - node dist/cli.js contracts --command extension --flags-only --json > contracts-extension-flags.json
24
+ - node dist/cli.js contracts --json > contracts-runtime.json
25
+ artifacts:
26
+ paths:
27
+ - contracts-schema.json
28
+ - contracts-extension-flags.json
29
+ - contracts-runtime.json
30
+
31
+ extension_gate:
32
+ stage: extension_gate
33
+ script:
34
+ - node dist/cli.js extension --reload --project --json
35
+ - node dist/cli.js extension --doctor --project --detail summary --strict-exit --json
36
+
37
+ test:
38
+ stage: test
39
+ script:
40
+ - node scripts/run-tests.mjs test -- tests/unit/contracts-command.spec.ts tests/unit/extension-loader.spec.ts tests/unit/extension-command.spec.ts
41
+ - node scripts/run-tests.mjs coverage