@unbrained/pm-cli 2026.8.17 → 2026.8.19

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 (204) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/AGENTS.md +4 -3
  3. package/CHANGELOG.md +51 -5
  4. package/README.md +3 -3
  5. package/dist/cli/error-guidance.js +8 -4
  6. package/dist/cli/help-content.js +32 -13
  7. package/dist/cli/help-json-payload.d.ts +15 -0
  8. package/dist/cli/help-json-payload.js +101 -23
  9. package/dist/cli/main.js +6 -2
  10. package/dist/cli/register-list-query.js +138 -54
  11. package/dist/cli/register-mutation.js +8 -8
  12. package/dist/cli/register-operations.js +6 -6
  13. package/dist/cli-bundle/bundle-manifest.json +149 -149
  14. package/dist/cli-bundle/chunks/chunk-4NRRH7AM.js +2 -0
  15. package/dist/cli-bundle/chunks/chunk-4THEB6PD.js +13 -0
  16. package/dist/cli-bundle/chunks/{chunk-HBJAS566.js → chunk-BHYMXLAE.js} +2 -2
  17. package/dist/cli-bundle/chunks/chunk-GWMXAQOD.js +197 -0
  18. package/dist/cli-bundle/chunks/chunk-HVFQTLYM.js +35 -0
  19. package/dist/cli-bundle/chunks/chunk-OI4XI562.js +5 -0
  20. package/dist/cli-bundle/chunks/{chunk-3UEGXBMR.js → chunk-OIOKV6NO.js} +58 -54
  21. package/dist/cli-bundle/chunks/chunk-QXSH7BLM.js +3 -0
  22. package/dist/cli-bundle/chunks/chunk-SARFF5H5.js +3 -0
  23. package/dist/cli-bundle/chunks/{chunk-7IBRGCHX.js → chunk-TOXJM4WA.js} +2 -2
  24. package/dist/cli-bundle/chunks/{chunk-JOKATURE.js → chunk-YBMRWW4E.js} +44 -44
  25. package/dist/cli-bundle/chunks/register-list-query-Y56KINDU.js +11 -0
  26. package/dist/cli-bundle/chunks/register-mutation-AUWVCW4M.js +20 -0
  27. package/dist/cli-bundle/chunks/register-operations-PZQPHXW5.js +2 -0
  28. package/dist/cli-bundle/chunks/{register-setup-DOSFBGKE.js → register-setup-I4LUHGVW.js} +2 -2
  29. package/dist/cli-bundle/focused-chunks/chunk-34QBIYZI.js +155 -0
  30. package/dist/cli-bundle/focused-chunks/{chunk-MHPIL773.js → chunk-BJRYFVSH.js} +2 -2
  31. package/dist/cli-bundle/focused-chunks/chunk-DKPLYW3L.js +2 -0
  32. package/dist/cli-bundle/focused-chunks/{chunk-SALH6B6K.js → chunk-EF6ZS5GH.js} +44 -44
  33. package/dist/cli-bundle/focused-chunks/{chunk-XKAMP5OU.js → chunk-ESISGDAY.js} +2 -2
  34. package/dist/cli-bundle/focused-chunks/{chunk-SYZENPIT.js → chunk-EXBCLIBU.js} +2 -2
  35. package/dist/cli-bundle/focused-chunks/chunk-JDOMQ7VQ.js +4 -0
  36. package/dist/cli-bundle/focused-chunks/chunk-L623ZPNK.js +2 -0
  37. package/dist/cli-bundle/focused-chunks/chunk-MCZXYZAF.js +2 -0
  38. package/dist/cli-bundle/focused-chunks/chunk-ODHQEECS.js +2 -0
  39. package/dist/cli-bundle/focused-chunks/{chunk-ZQPGZZWQ.js → chunk-PRHY2IMX.js} +3 -3
  40. package/dist/cli-bundle/focused-chunks/chunk-RZU5U6Q7.js +2 -0
  41. package/dist/cli-bundle/focused-chunks/{chunk-ATEY76SX.js → chunk-US7VEYZG.js} +2 -2
  42. package/dist/cli-bundle/focused-chunks/chunk-VXDSU5MC.js +26 -0
  43. package/dist/cli-bundle/focused-chunks/chunk-YBMGXBFV.js +16 -0
  44. package/dist/cli-bundle/focused-chunks/chunk-YLVBJ6GF.js +2 -0
  45. package/dist/cli-bundle/focused-chunks/{chunk-CYFK5UPB.js → chunk-ZBIQQYMI.js} +2 -2
  46. package/dist/cli-bundle/main.js +13 -13
  47. package/dist/cli-bundle/sdk-authoring.js +1 -1
  48. package/dist/cli-bundle/sdk-contracts.js +2 -1
  49. package/dist/cli-bundle/sdk-core.js +28 -28
  50. package/dist/cli-bundle/sdk-governance.js +1 -1
  51. package/dist/cli-bundle/sdk-graph.js +1 -1
  52. package/dist/cli-bundle/sdk-merge.js +32 -32
  53. package/dist/cli-bundle/sdk-query.js +1 -1
  54. package/dist/cli-bundle/sdk-runtime.js +1 -1
  55. package/dist/cli-bundle/sdk-testing.js +1 -1
  56. package/dist/cli-bundle/sdk.js +5 -4
  57. package/dist/core/config/nested-settings.js +8 -2
  58. package/dist/core/extensions/exporter-output-contract.d.ts +12 -0
  59. package/dist/core/extensions/exporter-output-contract.js +67 -0
  60. package/dist/core/extensions/extension-types.d.ts +36 -1
  61. package/dist/core/extensions/extension-types.js +2 -2
  62. package/dist/core/extensions/loader.js +35 -44
  63. package/dist/core/history/event-index.d.ts +5 -0
  64. package/dist/core/history/event-index.js +133 -27
  65. package/dist/core/sentry/helpers.js +3 -3
  66. package/dist/core/shared/constants.js +5 -2
  67. package/dist/core/shared/errors.d.ts +2 -0
  68. package/dist/core/shared/errors.js +2 -2
  69. package/dist/core/store/settings-validator.d.ts +4 -0
  70. package/dist/core/store/settings-validator.js +3 -2
  71. package/dist/core/store/settings.js +8 -2
  72. package/dist/mcp/tool-definitions.js +12 -7
  73. package/dist/sdk/agent/refusal-closure.d.ts +41 -0
  74. package/dist/sdk/agent/refusal-closure.js +92 -0
  75. package/dist/sdk/agent/refusal-reachability.d.ts +1 -1
  76. package/dist/sdk/agent/refusal-reachability.js +4 -4
  77. package/dist/sdk/agent-capability-contracts.d.ts +13 -0
  78. package/dist/sdk/agent-capability-contracts.js +104 -7
  79. package/dist/sdk/authoring.d.ts +1 -1
  80. package/dist/sdk/authoring.js +2 -2
  81. package/dist/sdk/cli-bootstrap.d.ts +2 -2
  82. package/dist/sdk/cli-bootstrap.js +4 -4
  83. package/dist/sdk/cli-contracts/command-aliases.d.ts +34 -2
  84. package/dist/sdk/cli-contracts/command-aliases.js +80 -13
  85. package/dist/sdk/cli-contracts/commander-mutation-options.js +30 -6
  86. package/dist/sdk/cli-contracts/commander-types.js +5 -4
  87. package/dist/sdk/cli-contracts/enum-contracts.d.ts +4 -0
  88. package/dist/sdk/cli-contracts/enum-contracts.js +9 -2
  89. package/dist/sdk/cli-contracts/flag-contracts.d.ts +5 -0
  90. package/dist/sdk/cli-contracts/flag-contracts.js +84 -13
  91. package/dist/sdk/cli-contracts/flag-lexicon-contracts.d.ts +55 -0
  92. package/dist/sdk/cli-contracts/flag-lexicon-contracts.js +240 -0
  93. package/dist/sdk/cli-contracts/grammar-contracts.d.ts +151 -0
  94. package/dist/sdk/cli-contracts/grammar-contracts.js +958 -0
  95. package/dist/sdk/cli-contracts/runtime-contracts.d.ts +33 -5
  96. package/dist/sdk/cli-contracts/runtime-contracts.js +100 -23
  97. package/dist/sdk/cli-contracts/tool-option-contracts.d.ts +28 -1
  98. package/dist/sdk/cli-contracts/tool-option-contracts.js +38 -3
  99. package/dist/sdk/cli-contracts/tool-parameter-tables.js +7 -2
  100. package/dist/sdk/cli-contracts/tool-schema.d.ts +2 -2
  101. package/dist/sdk/cli-contracts/tool-schema.js +20 -11
  102. package/dist/sdk/cli-contracts.d.ts +5 -4
  103. package/dist/sdk/cli-contracts.js +7 -6
  104. package/dist/sdk/completion.js +13 -15
  105. package/dist/sdk/compose.d.ts +3 -3
  106. package/dist/sdk/compose.js +2 -2
  107. package/dist/sdk/context-intent-contracts.d.ts +2 -2
  108. package/dist/sdk/context-intent-contracts.js +22 -7
  109. package/dist/sdk/contracts.d.ts +3 -0
  110. package/dist/sdk/contracts.js +5 -2
  111. package/dist/sdk/core.d.ts +1 -1
  112. package/dist/sdk/core.js +3 -3
  113. package/dist/sdk/environment/host-environment-errors.js +3 -3
  114. package/dist/sdk/flag-invocation-contracts.d.ts +37 -0
  115. package/dist/sdk/flag-invocation-contracts.js +218 -9
  116. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +186 -14
  117. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +194 -26
  118. package/dist/sdk/guide-topics.js +5 -5
  119. package/dist/sdk/index.d.ts +10 -7
  120. package/dist/sdk/index.js +10 -7
  121. package/dist/sdk/init-agent-guidance.js +3 -3
  122. package/dist/sdk/mutation-events.d.ts +18 -2
  123. package/dist/sdk/mutation-events.js +59 -16
  124. package/dist/sdk/output-projection.d.ts +2 -0
  125. package/dist/sdk/output-projection.js +11 -5
  126. package/dist/sdk/output.d.ts +44 -0
  127. package/dist/sdk/output.js +28 -2
  128. package/dist/sdk/query/complete-list.d.ts +94 -0
  129. package/dist/sdk/query/complete-list.js +173 -0
  130. package/dist/sdk/query/get.js +25 -6
  131. package/dist/sdk/query/list.js +19 -2
  132. package/dist/sdk/query/search-contracts.d.ts +1 -1
  133. package/dist/sdk/query/search-contracts.js +23 -9
  134. package/dist/sdk/query/search.js +3 -3
  135. package/dist/sdk/query.d.ts +1 -0
  136. package/dist/sdk/query.js +3 -2
  137. package/dist/sdk/read-output/continuation.d.ts +1 -1
  138. package/dist/sdk/read-output/continuation.js +7 -24
  139. package/dist/sdk/read-output-contracts.d.ts +2 -2
  140. package/dist/sdk/read-output-contracts.js +89 -13
  141. package/dist/sdk/read-output-rows.d.ts +4 -0
  142. package/dist/sdk/read-output-rows.js +47 -18
  143. package/dist/sdk/runtime-extended-actions.js +10 -2
  144. package/dist/sdk/runtime.d.ts +8 -2
  145. package/dist/sdk/runtime.js +18 -11
  146. package/dist/sdk/workspace-snapshot.d.ts +2 -0
  147. package/dist/sdk/workspace-snapshot.js +10 -2
  148. package/dist/types.d.ts +5 -0
  149. package/dist/types.js +2 -2
  150. package/docs/AGENT_GUIDE.md +25 -9
  151. package/docs/CLI_GRAMMAR.md +106 -0
  152. package/docs/COMMANDS.md +39 -27
  153. package/docs/ONBOARDING.md +4 -4
  154. package/docs/OUTPUT_PROJECTION_CONTRACTS.md +11 -2
  155. package/docs/QUICKSTART.md +1 -1
  156. package/docs/README.md +2 -0
  157. package/docs/READ_OUTPUT_CONTRACTS.md +10 -6
  158. package/docs/RELEASING.md +30 -6
  159. package/docs/SDK.md +42 -2
  160. package/docs/SDK_ARTIFACT_OUTPUT.md +72 -0
  161. package/docs/SDK_CONTEXT_COORDINATION.md +46 -12
  162. package/docs/TESTING.md +14 -1
  163. package/docs/agent-task-token-baseline.json +5 -5
  164. package/docs/generated/AGENT_COMMAND_SURFACE.md +78 -78
  165. package/docs/generated/FLAG_LEXICON_BUDGETS.md +76 -0
  166. package/marketplace.json +2 -2
  167. package/package.json +5 -2
  168. package/packages/pm-beads/package.json +1 -1
  169. package/packages/pm-calendar/package.json +1 -1
  170. package/packages/pm-command-kit/package.json +1 -1
  171. package/packages/pm-digital-twin/package.json +1 -1
  172. package/packages/pm-governance-audit/package.json +1 -1
  173. package/packages/pm-guide-shell/package.json +1 -1
  174. package/packages/pm-kanban/package.json +1 -1
  175. package/packages/pm-lifecycle-hooks/package.json +1 -1
  176. package/packages/pm-linked-test-adapters/package.json +1 -1
  177. package/packages/pm-search-advanced/package.json +1 -1
  178. package/packages/pm-templates/package.json +1 -1
  179. package/packages/pm-todos/package.json +1 -1
  180. package/packages/pm-vcs/package.json +1 -1
  181. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  182. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  183. package/scripts/generate-agent-capability-surfaces.mjs +20 -14
  184. package/sdk/public-surface.json +1245 -60
  185. package/dist/cli-bundle/chunks/chunk-2QLOXC3V.js +0 -3
  186. package/dist/cli-bundle/chunks/chunk-4JPYF536.js +0 -35
  187. package/dist/cli-bundle/chunks/chunk-6VDLG2FC.js +0 -13
  188. package/dist/cli-bundle/chunks/chunk-ION3E43Q.js +0 -197
  189. package/dist/cli-bundle/chunks/chunk-OAC5NIV4.js +0 -3
  190. package/dist/cli-bundle/chunks/chunk-TPXZIBIV.js +0 -5
  191. package/dist/cli-bundle/chunks/chunk-YM2YAMF7.js +0 -2
  192. package/dist/cli-bundle/chunks/register-list-query-Q7KII4G5.js +0 -10
  193. package/dist/cli-bundle/chunks/register-mutation-4WBRPXLV.js +0 -20
  194. package/dist/cli-bundle/chunks/register-operations-SSENDH5B.js +0 -2
  195. package/dist/cli-bundle/focused-chunks/chunk-267MUUS6.js +0 -16
  196. package/dist/cli-bundle/focused-chunks/chunk-2NNFLLNG.js +0 -2
  197. package/dist/cli-bundle/focused-chunks/chunk-2QSAKMIH.js +0 -2
  198. package/dist/cli-bundle/focused-chunks/chunk-BUCG4ZI2.js +0 -2
  199. package/dist/cli-bundle/focused-chunks/chunk-EHXIKD6K.js +0 -2
  200. package/dist/cli-bundle/focused-chunks/chunk-KGEXTMPG.js +0 -2
  201. package/dist/cli-bundle/focused-chunks/chunk-KP2VQQVQ.js +0 -2
  202. package/dist/cli-bundle/focused-chunks/chunk-POEEAD2V.js +0 -4
  203. package/dist/cli-bundle/focused-chunks/chunk-XPIC53VA.js +0 -26
  204. package/dist/cli-bundle/focused-chunks/chunk-ZT2DJS27.js +0 -155
@@ -0,0 +1,958 @@
1
+ /** Canonical top-level domains an agent must retain to route pm operations. */
2
+
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="686e65f1-bf69-59f6-8e65-db4c4838008b")}catch(e){}}();
4
+ export const PM_CLI_GRAMMAR_NOUNS = [
5
+ "item",
6
+ "list",
7
+ "context",
8
+ "search",
9
+ "graph",
10
+ "history",
11
+ "workspace",
12
+ "package",
13
+ "ops",
14
+ "plan",
15
+ "contracts",
16
+ "help",
17
+ ];
18
+ /** Shared verbs whose meaning transfers across domain nouns. */
19
+ export const PM_CLI_SHARED_VERBS = [
20
+ "activate",
21
+ "add",
22
+ "adopt",
23
+ "adopt-all",
24
+ "catalog",
25
+ "compact",
26
+ "complete",
27
+ "create",
28
+ "deactivate",
29
+ "delete",
30
+ "describe",
31
+ "doctor",
32
+ "edit",
33
+ "explore",
34
+ "import",
35
+ "init",
36
+ "inspect",
37
+ "install",
38
+ "list",
39
+ "manage",
40
+ "migrate",
41
+ "mutate",
42
+ "read",
43
+ "redact",
44
+ "reload",
45
+ "remove",
46
+ "repair",
47
+ "restore",
48
+ "run",
49
+ "show",
50
+ "uninstall",
51
+ "verify",
52
+ ];
53
+ function positionalSlot(name, valueKind, required, options = {}) {
54
+ return {
55
+ name,
56
+ required,
57
+ variadic: options.variadic === true,
58
+ value_kind: valueKind,
59
+ polymorphic: options.polymorphic === true,
60
+ };
61
+ }
62
+ /** Convert a kebab-case positional action into a sentence-leading verb phrase. */
63
+ function positionalActionVerb(action) {
64
+ const phrase = action.replaceAll("-", " ");
65
+ return `${phrase.charAt(0).toUpperCase()}${phrase.slice(1)}`;
66
+ }
67
+ const ITEM_ID = positionalSlot("id", "item_id", true);
68
+ const OPTIONAL_ITEM_ID = positionalSlot("id", "item_id", false);
69
+ const OPTIONAL_TEXT = positionalSlot("text", "string", false);
70
+ const PLAN_ITEM_ID = positionalSlot("plan-id", "item_id", true);
71
+ const PLAN_STEP = positionalSlot("step", "string", true);
72
+ const PLAN_CREATE_FLAGS = [
73
+ "--acceptance-criteria",
74
+ "--actual-result",
75
+ "--affected-version",
76
+ "--assignee",
77
+ "--blocked-by",
78
+ "--blocked-reason",
79
+ "--blocks",
80
+ "--body",
81
+ "--claim",
82
+ "--comment",
83
+ "--component",
84
+ "--confidence",
85
+ "--create-mode",
86
+ "--customer-impact",
87
+ "--deadline",
88
+ "--definition-of-ready",
89
+ "--description",
90
+ "--doc",
91
+ "--environment",
92
+ "--estimate",
93
+ "--event",
94
+ "--expected-result",
95
+ "--fixed-version",
96
+ "--file",
97
+ "--from-search",
98
+ "--goal",
99
+ "--harness",
100
+ "--impact",
101
+ "--learning",
102
+ "--message",
103
+ "--mode",
104
+ "--note",
105
+ "--objective",
106
+ "--order",
107
+ "--outcome",
108
+ "--parent",
109
+ "--priority",
110
+ "--rank",
111
+ "--related",
112
+ "--release",
113
+ "--reminder",
114
+ "--reporter",
115
+ "--repro-steps",
116
+ "--resolution",
117
+ "--resume-context",
118
+ "--reviewer",
119
+ "--risk",
120
+ "--scope",
121
+ "--severity",
122
+ "--sprint",
123
+ "--status",
124
+ "--step",
125
+ "--step-blocked-reason",
126
+ "--step-body",
127
+ "--step-evidence",
128
+ "--step-owner",
129
+ "--step-replacement",
130
+ "--step-status",
131
+ "--step-title",
132
+ "--tags",
133
+ "--template",
134
+ "--test",
135
+ "--title",
136
+ "--type-option",
137
+ "--unblock-note",
138
+ "--value",
139
+ "--why-now",
140
+ ];
141
+ const PLAN_STEP_FLAGS = [
142
+ "--allow-multiple-active",
143
+ "--depends-on",
144
+ "--file",
145
+ "--force",
146
+ "--message",
147
+ "--step-blocked-reason",
148
+ "--step-body",
149
+ "--step-evidence",
150
+ "--step-owner",
151
+ "--step-status",
152
+ "--step-title",
153
+ "--test",
154
+ ];
155
+ const PLAN_STEP_ACTION_DESCRIPTIONS = {
156
+ "update-step": "Update one declared Plan step.",
157
+ "complete-step": "Complete one declared Plan step.",
158
+ "block-step": "Block one declared Plan step.",
159
+ "remove-step": "Remove one declared Plan step.",
160
+ link: "Link one dependency to a declared Plan step.",
161
+ unlink: "Unlink one dependency from a declared Plan step.",
162
+ };
163
+ /** Virtual action paths dispatched by positional parent commands. */
164
+ export const PM_POSITIONAL_ACTION_CONTRACTS = [
165
+ {
166
+ command: "plan create",
167
+ parent: "plan",
168
+ action: "create",
169
+ slots: [positionalSlot("title", "string", false, { polymorphic: true })],
170
+ accepted_flags: PLAN_CREATE_FLAGS,
171
+ description: "Create a Plan item and optionally seed its ordered steps.",
172
+ example: 'pm plan create --title "Refactor lock retry"',
173
+ },
174
+ {
175
+ command: "plan show",
176
+ parent: "plan",
177
+ action: "show",
178
+ slots: [PLAN_ITEM_ID],
179
+ accepted_flags: ["--depth", "--fields"],
180
+ description: "Read one Plan item with a bounded plan projection.",
181
+ example: "pm plan show pm-a1b2 --depth standard",
182
+ },
183
+ {
184
+ command: "plan add-step",
185
+ parent: "plan",
186
+ action: "add-step",
187
+ slots: [PLAN_ITEM_ID],
188
+ accepted_flags: PLAN_STEP_FLAGS,
189
+ description: "Append one ordered step to a Plan item.",
190
+ example: 'pm plan add-step pm-a1b2 --step-title "Run tests"',
191
+ },
192
+ ...Object.entries(PLAN_STEP_ACTION_DESCRIPTIONS).map(([action, description]) => ({
193
+ command: `plan ${action}`,
194
+ parent: "plan",
195
+ action,
196
+ slots: [PLAN_ITEM_ID, PLAN_STEP],
197
+ accepted_flags: PLAN_STEP_FLAGS,
198
+ description,
199
+ example: `pm plan ${action} pm-a1b2 plan-step-001`,
200
+ })),
201
+ {
202
+ command: "plan reorder-step",
203
+ parent: "plan",
204
+ action: "reorder-step",
205
+ slots: [
206
+ PLAN_ITEM_ID,
207
+ PLAN_STEP,
208
+ positionalSlot("new-order", "integer", true),
209
+ ],
210
+ accepted_flags: ["--force", "--message"],
211
+ description: "Move one Plan step to a declared integer order.",
212
+ example: "pm plan reorder-step pm-a1b2 plan-step-001 2",
213
+ },
214
+ ...[
215
+ "decision",
216
+ "discovery",
217
+ "validation",
218
+ "resume",
219
+ "approve",
220
+ "materialize",
221
+ ].map((action) => ({
222
+ command: `plan ${action}`,
223
+ parent: "plan",
224
+ action,
225
+ slots: [PLAN_ITEM_ID],
226
+ accepted_flags: PLAN_STEP_FLAGS,
227
+ description: `${positionalActionVerb(action)} for one Plan item.`,
228
+ example: `pm plan ${action} pm-a1b2`,
229
+ })),
230
+ ...["list", "show", "put", "remove"].map((action) => ({
231
+ command: `assurance ${action}`,
232
+ parent: "assurance",
233
+ action,
234
+ slots: [
235
+ positionalSlot("kind", "string", true),
236
+ ...(action === "list" ? [] : [positionalSlot("id", "string", true)]),
237
+ ],
238
+ accepted_flags: action === "put"
239
+ ? ["--author", "--definition", "--message"]
240
+ : action === "remove"
241
+ ? ["--author", "--message"]
242
+ : [],
243
+ description: `${positionalActionVerb(action)} assurance declarations by kind.`,
244
+ example: action === "list"
245
+ ? "pm assurance list measurement"
246
+ : `pm assurance ${action} measurement example-id`,
247
+ })),
248
+ {
249
+ command: "assurance run",
250
+ parent: "assurance",
251
+ action: "run",
252
+ slots: [positionalSlot("gate-id", "string", true)],
253
+ accepted_flags: ["--dry-run", "--trigger", "--tree"],
254
+ description: "Evaluate one assurance gate for a lifecycle trigger.",
255
+ example: "pm assurance run tracker-context-quality --trigger ci --dry-run",
256
+ },
257
+ {
258
+ command: "assurance verdicts",
259
+ parent: "assurance",
260
+ action: "verdicts",
261
+ slots: [positionalSlot("gate-id", "string", false)],
262
+ accepted_flags: ["--gate", "--limit"],
263
+ description: "List bounded assurance verdict history.",
264
+ example: "pm assurance verdicts --limit 20",
265
+ },
266
+ ...["presets", "apply"].map((action) => ({
267
+ command: `assurance ${action}`,
268
+ parent: "assurance",
269
+ action,
270
+ slots: [positionalSlot("preset", "string", action === "apply")],
271
+ accepted_flags: ["--author", "--message", "--owner"],
272
+ description: action === "apply"
273
+ ? "Apply one assurance adoption preset."
274
+ : "List available assurance adoption presets.",
275
+ example: action === "apply"
276
+ ? "pm assurance apply software-delivery --owner <pm-item-id>"
277
+ : "pm assurance presets",
278
+ })),
279
+ {
280
+ command: "assurance derive",
281
+ parent: "assurance",
282
+ action: "derive",
283
+ slots: [],
284
+ accepted_flags: ["--apply", "--author", "--message", "--owner"],
285
+ description: "Derive assurance proposals from current project context.",
286
+ example: "pm assurance derive --owner pm-a1b2",
287
+ },
288
+ {
289
+ command: "assurance promote",
290
+ parent: "assurance",
291
+ action: "promote",
292
+ slots: [positionalSlot("assertion-id", "string", true)],
293
+ accepted_flags: ["--author", "--enforcement", "--message"],
294
+ description: "Promote one assertion into a warning or blocking gate.",
295
+ example: "pm assurance promote assertion-id --enforcement warn",
296
+ },
297
+ {
298
+ command: "assurance risk",
299
+ parent: "assurance",
300
+ action: "risk",
301
+ slots: [],
302
+ accepted_flags: ["--definition"],
303
+ description: "Analyze bounded defect-recurrence risk for a proposed change.",
304
+ example: 'pm assurance risk --definition \'{"change":{"files":[]}}\'',
305
+ },
306
+ {
307
+ command: "workspace snapshot create",
308
+ parent: "workspace snapshot",
309
+ action: "create",
310
+ slots: [positionalSlot("name", "string", false)],
311
+ accepted_flags: [],
312
+ description: "Capture authoritative tracker state as an immutable snapshot.",
313
+ example: "pm workspace snapshot create before-migration",
314
+ },
315
+ {
316
+ command: "workspace snapshot list",
317
+ parent: "workspace snapshot",
318
+ action: "list",
319
+ slots: [],
320
+ accepted_flags: [],
321
+ description: "List immutable workspace snapshots and named references.",
322
+ example: "pm workspace snapshot list",
323
+ },
324
+ {
325
+ command: "workspace snapshot inspect",
326
+ parent: "workspace snapshot",
327
+ action: "inspect",
328
+ slots: [positionalSlot("target", "string", true)],
329
+ accepted_flags: [],
330
+ description: "Inspect one workspace snapshot target.",
331
+ example: "pm workspace snapshot inspect before-migration",
332
+ },
333
+ {
334
+ command: "workspace snapshot restore",
335
+ parent: "workspace snapshot",
336
+ action: "restore",
337
+ slots: [positionalSlot("target", "string", true)],
338
+ accepted_flags: ["--author", "--dry-run", "--force", "--message"],
339
+ description: "Restore an immutable workspace snapshot with explicit recovery controls.",
340
+ example: "pm workspace snapshot restore before-migration --dry-run",
341
+ },
342
+ {
343
+ command: "workspace snapshot delete",
344
+ parent: "workspace snapshot",
345
+ action: "delete",
346
+ slots: [positionalSlot("target", "string", true)],
347
+ accepted_flags: [],
348
+ description: "Delete one workspace snapshot target.",
349
+ example: "pm workspace snapshot delete before-migration",
350
+ },
351
+ ];
352
+ const POSITIONAL_ACTION_CONTRACTS_BY_SPECIFICITY = [
353
+ ...PM_POSITIONAL_ACTION_CONTRACTS,
354
+ ].sort((left, right) => right.command.length - left.command.length);
355
+ const EXPLICIT_POSITIONAL_SLOTS = new Map([
356
+ ["append", [ITEM_ID, OPTIONAL_TEXT]],
357
+ [
358
+ "assurance",
359
+ [
360
+ positionalSlot("action", "action", true),
361
+ positionalSlot("kind", "string", false),
362
+ positionalSlot("id", "string", false),
363
+ ],
364
+ ],
365
+ ["beads import", [positionalSlot("file", "string", false)]],
366
+ ["changelog export", [positionalSlot("file", "string", false)]],
367
+ ["claim", [OPTIONAL_ITEM_ID]],
368
+ ["close", [ITEM_ID, OPTIONAL_TEXT]],
369
+ ["close-task", [ITEM_ID, positionalSlot("reason", "string", false)]],
370
+ ["comments", [ITEM_ID, OPTIONAL_TEXT]],
371
+ ["completion", [positionalSlot("shell", "string", false)]],
372
+ [
373
+ "config",
374
+ [
375
+ positionalSlot("scope", "string", false, { polymorphic: true }),
376
+ positionalSlot("action", "action", false),
377
+ positionalSlot("key", "string", false),
378
+ positionalSlot("value", "string", false, { polymorphic: true }),
379
+ ],
380
+ ],
381
+ ["copy", [ITEM_ID]],
382
+ [
383
+ "create",
384
+ [
385
+ positionalSlot("type-or-title", "string", false, { polymorphic: true }),
386
+ positionalSlot("title", "string", false),
387
+ ],
388
+ ],
389
+ ["delete", [ITEM_ID]],
390
+ ["deps", [ITEM_ID]],
391
+ ["docs", [ITEM_ID]],
392
+ ["event", [positionalSlot("title", "string", true)]],
393
+ [
394
+ "extension",
395
+ [positionalSlot("target", "string", false, { polymorphic: true })],
396
+ ],
397
+ ["extension list", []],
398
+ ["extension scaffold", [positionalSlot("target", "string", true)]],
399
+ ["files", [ITEM_ID]],
400
+ ["files discover", [ITEM_ID]],
401
+ [
402
+ "files lookup",
403
+ [positionalSlot("paths", "string", true, { variadic: true })],
404
+ ],
405
+ ["focus", [OPTIONAL_ITEM_ID]],
406
+ ["get", [ITEM_ID]],
407
+ [
408
+ "graph",
409
+ [
410
+ positionalSlot("subcommand", "action", true),
411
+ OPTIONAL_ITEM_ID,
412
+ positionalSlot("target", "item_id", false),
413
+ ],
414
+ ],
415
+ ["guide", [positionalSlot("topic", "string", false)]],
416
+ ["history", [ITEM_ID]],
417
+ ["history-compact", [OPTIONAL_ITEM_ID]],
418
+ ["history-redact", [ITEM_ID]],
419
+ ["history-repair", [OPTIONAL_ITEM_ID]],
420
+ [
421
+ "init",
422
+ [positionalSlot("prefix-or-path", "string", false, { polymorphic: true })],
423
+ ],
424
+ ["install", [positionalSlot("targets", "string", false, { variadic: true })]],
425
+ ["item complete", [ITEM_ID, positionalSlot("reason", "string", false)]],
426
+ ["learnings", [ITEM_ID, OPTIONAL_TEXT]],
427
+ ["meet", [positionalSlot("title", "string", true)]],
428
+ [
429
+ "merge",
430
+ [
431
+ positionalSlot("subcommand", "action", true),
432
+ positionalSlot("artifact", "string", false),
433
+ positionalSlot("base", "string", false),
434
+ positionalSlot("ours", "string", false),
435
+ positionalSlot("theirs", "string", false),
436
+ ],
437
+ ],
438
+ ["notes", [ITEM_ID, OPTIONAL_TEXT]],
439
+ [
440
+ "package",
441
+ [positionalSlot("target", "string", false, { polymorphic: true })],
442
+ ],
443
+ ["package list", []],
444
+ ["package scaffold", [positionalSlot("target", "string", true)]],
445
+ [
446
+ "packages",
447
+ [positionalSlot("target", "string", false, { polymorphic: true })],
448
+ ],
449
+ ["packages list", []],
450
+ ["packages scaffold", [positionalSlot("target", "string", true)]],
451
+ ["pause-task", [ITEM_ID]],
452
+ [
453
+ "plan",
454
+ [
455
+ positionalSlot("subcommand", "action", true),
456
+ positionalSlot("id", "item_id", false, { polymorphic: true }),
457
+ positionalSlot("step", "string", false),
458
+ positionalSlot("new-order", "integer", false),
459
+ ],
460
+ ],
461
+ [
462
+ "profile",
463
+ [
464
+ positionalSlot("subcommand", "action", true),
465
+ positionalSlot("name", "string", false),
466
+ ],
467
+ ],
468
+ ["release", [ITEM_ID]],
469
+ ["remind", [positionalSlot("title", "string", true)]],
470
+ ["restore", [ITEM_ID, positionalSlot("target", "string", true)]],
471
+ [
472
+ "schema",
473
+ [
474
+ positionalSlot("subcommand", "action", true),
475
+ positionalSlot("name", "string", false),
476
+ ],
477
+ ],
478
+ [
479
+ "search-advanced",
480
+ [positionalSlot("keywords", "string", true, { variadic: true })],
481
+ ],
482
+ ["search", [positionalSlot("keywords", "string", true, { variadic: true })]],
483
+ ["start-task", [ITEM_ID]],
484
+ [
485
+ "telemetry",
486
+ [
487
+ positionalSlot("namespace-or-subcommand", "action", false, {
488
+ polymorphic: true,
489
+ }),
490
+ positionalSlot("subcommand", "action", false),
491
+ ],
492
+ ],
493
+ ["test", [ITEM_ID]],
494
+ ["update", [ITEM_ID]],
495
+ ["upgrade", [positionalSlot("target", "string", false)]],
496
+ [
497
+ "workspace snapshot",
498
+ [
499
+ positionalSlot("action", "action", true),
500
+ positionalSlot("target", "string", false),
501
+ ],
502
+ ],
503
+ ...["activate", "adopt", "deactivate", "init", "uninstall"].flatMap((action) => ["extension", "package", "packages"].map((root) => [
504
+ `${root} ${action}`,
505
+ [positionalSlot("target", "string", true)],
506
+ ])),
507
+ ...["describe"].flatMap((action) => ["extension", "package", "packages"].map((root) => [
508
+ `${root} ${action}`,
509
+ [positionalSlot("target", "string", false)],
510
+ ])),
511
+ ...["install"].flatMap((action) => ["extension", "package", "packages"].map((root) => [
512
+ `${root} ${action}`,
513
+ [positionalSlot("targets", "string", false, { variadic: true })],
514
+ ])),
515
+ ["vcs abandon", [ITEM_ID]],
516
+ ["vcs create", [positionalSlot("title", "string", true)]],
517
+ ["vcs merge", [ITEM_ID]],
518
+ ["vcs propose", [ITEM_ID]],
519
+ ["vcs ref-create", [positionalSlot("name", "string", true)]],
520
+ ["vcs show", [ITEM_ID]],
521
+ ]);
522
+ /** Normalize a command path for every positional-contract lookup and identity check. */
523
+ function normalizePositionalCommandPath(command) {
524
+ return command.trim().toLowerCase().replace(/\s+/gu, " ");
525
+ }
526
+ /** Resolve one declared signature without treating arbitrary object keys as commands. */
527
+ export function resolvePmCommandPositionalContract(command) {
528
+ const normalized = normalizePositionalCommandPath(command);
529
+ return PM_COMMAND_POSITIONAL_CONTRACTS.find((contract) => contract.command === normalized);
530
+ }
531
+ /** Resolve one action-specific help/contract view. */
532
+ export function resolvePmPositionalActionContract(command) {
533
+ const normalized = normalizePositionalCommandPath(command);
534
+ return POSITIONAL_ACTION_CONTRACTS_BY_SPECIFICITY.find((contract) => contract.command === normalized ||
535
+ normalized.startsWith(`${contract.command} `));
536
+ }
537
+ /** Format the shared action-flag tip rendered by text and structured help. */
538
+ export function formatPmPositionalActionFlagTip(acceptedFlags) {
539
+ return `Applicable flags: ${acceptedFlags.length > 0 ? acceptedFlags.join(", ") : "none"}.`;
540
+ }
541
+ function destinationRows(noun, target, disposition, owner, commands) {
542
+ return commands.map((command) => ({
543
+ command,
544
+ noun,
545
+ target,
546
+ disposition,
547
+ owner,
548
+ }));
549
+ }
550
+ /** Checked-in exhaustive destination census for core and known package commands. */
551
+ export const PM_COMMAND_DESTINATION_CONTRACTS = [
552
+ ...destinationRows("item", "item", "target_noun", "pm-pbyu", [
553
+ "item",
554
+ "item complete",
555
+ "item mutate",
556
+ ]),
557
+ ...destinationRows("item", "item", "consolidation", "pm-yql1", [
558
+ "append",
559
+ "claim",
560
+ "close",
561
+ "close-many",
562
+ "close-task",
563
+ "comments",
564
+ "copy",
565
+ "create",
566
+ "delete",
567
+ "docs",
568
+ "files",
569
+ "get",
570
+ "learnings",
571
+ "notes",
572
+ "pause-task",
573
+ "release",
574
+ "start-task",
575
+ "test",
576
+ "update",
577
+ "update-many",
578
+ ]),
579
+ ...destinationRows("item", "item files", "consolidation", "pm-ya7x55", [
580
+ "files discover",
581
+ "files lookup",
582
+ ]),
583
+ ...destinationRows("list", "list", "target_noun", "pm-pfqi", ["list"]),
584
+ ...destinationRows("list", "list --group-by", "consolidation", "pm-xkgq", [
585
+ "aggregate",
586
+ ]),
587
+ ...destinationRows("context", "context", "target_noun", "pm-pbyu", [
588
+ "context",
589
+ ]),
590
+ ...destinationRows("context", "context", "consolidation", "pm-kcs4", [
591
+ "ctx",
592
+ "focus",
593
+ "next",
594
+ ]),
595
+ ...destinationRows("search", "search", "target_noun", "pm-pbyu", [
596
+ "search",
597
+ ]),
598
+ ...destinationRows("search", "search", "package_owned", "package:search-advanced", ["reindex", "search-advanced"]),
599
+ ...destinationRows("search", "search duplicates", "consolidation", "pm-3i9q8g", ["duplicates"]),
600
+ ...destinationRows("graph", "graph", "target_noun", "pm-pbyu", ["graph"]),
601
+ ...destinationRows("graph", "graph show", "consolidation", "pm-yql1", [
602
+ "deps",
603
+ ]),
604
+ ...destinationRows("history", "history", "target_noun", "pm-pbyu", [
605
+ "history",
606
+ ]),
607
+ ...destinationRows("history", "history", "consolidation", "pm-tqel", [
608
+ "activity",
609
+ "events",
610
+ "history-author-acknowledge",
611
+ "history-compact",
612
+ "history-redact",
613
+ "history-repair",
614
+ "merge",
615
+ "restore",
616
+ ]),
617
+ ...destinationRows("history", "history", "package_owned", "package:builtin-vcs-exemplar", [
618
+ "vcs abandon",
619
+ "vcs create",
620
+ "vcs log",
621
+ "vcs merge",
622
+ "vcs propose",
623
+ "vcs ref-create",
624
+ "vcs show",
625
+ ]),
626
+ ...destinationRows("workspace", "workspace", "target_noun", "pm-pbyu", [
627
+ "workspace",
628
+ "workspace snapshot",
629
+ "workspace snapshot create",
630
+ "workspace snapshot delete",
631
+ "workspace snapshot inspect",
632
+ "workspace snapshot list",
633
+ "workspace snapshot restore",
634
+ ]),
635
+ ...destinationRows("workspace", "workspace init", "consolidation", "pm-n7rr", ["init"]),
636
+ ...destinationRows("package", "package", "target_noun", "pm-pbyu", [
637
+ "package",
638
+ "package activate",
639
+ "package adopt",
640
+ "package adopt-all",
641
+ "package catalog",
642
+ "package deactivate",
643
+ "package describe",
644
+ "package doctor",
645
+ "package explore",
646
+ "package init",
647
+ "package install",
648
+ "package list",
649
+ "package manage",
650
+ "package migrate",
651
+ "package reload",
652
+ "package scaffold",
653
+ "package uninstall",
654
+ ]),
655
+ ...destinationRows("package", "package", "consolidation", "pm-tnud", [
656
+ "extension",
657
+ "extension activate",
658
+ "extension adopt",
659
+ "extension adopt-all",
660
+ "extension catalog",
661
+ "extension deactivate",
662
+ "extension describe",
663
+ "extension doctor",
664
+ "extension explore",
665
+ "extension init",
666
+ "extension install",
667
+ "extension list",
668
+ "extension manage",
669
+ "extension migrate",
670
+ "extension reload",
671
+ "extension scaffold",
672
+ "extension uninstall",
673
+ "install",
674
+ "packages",
675
+ "packages activate",
676
+ "packages adopt",
677
+ "packages adopt-all",
678
+ "packages catalog",
679
+ "packages deactivate",
680
+ "packages describe",
681
+ "packages doctor",
682
+ "packages explore",
683
+ "packages init",
684
+ "packages install",
685
+ "packages list",
686
+ "packages manage",
687
+ "packages migrate",
688
+ "packages reload",
689
+ "packages scaffold",
690
+ "packages uninstall",
691
+ "upgrade",
692
+ ]),
693
+ ...destinationRows("package", "package", "package_owned", "package:beads", [
694
+ "beads import",
695
+ ]),
696
+ ...destinationRows("package", "package", "package_owned", "package:pm-changelog", ["changelog export", "changelog generate"]),
697
+ ...destinationRows("package", "package calendar", "package_owned", "pm-o3fh", ["event", "meet", "remind"]),
698
+ ...destinationRows("ops", "ops", "consolidation", "pm-6apl", [
699
+ "assurance",
700
+ "config",
701
+ "eval",
702
+ "gc",
703
+ "health",
704
+ "profile",
705
+ "schema",
706
+ "stats",
707
+ "telemetry",
708
+ "test-all",
709
+ "validate",
710
+ ]),
711
+ ...destinationRows("ops", "ops assurance", "consolidation", "pm-2tan", PM_POSITIONAL_ACTION_CONTRACTS.filter(({ parent }) => parent === "assurance").map(({ command }) => command)),
712
+ ...destinationRows("plan", "plan", "target_noun", "pm-pbyu", ["plan"]),
713
+ ...destinationRows("plan", "plan", "target_noun", "pm-2tan", PM_POSITIONAL_ACTION_CONTRACTS.filter(({ parent }) => parent === "plan").map(({ command }) => command)),
714
+ ...destinationRows("contracts", "contracts", "target_noun", "pm-pbyu", [
715
+ "contracts",
716
+ ]),
717
+ ...destinationRows("help", "help", "target_noun", "pm-pbyu", ["help"]),
718
+ ...destinationRows("help", "help", "package_owned", "package:builtin-guide-shell", [
719
+ "completion",
720
+ "completion-statuses",
721
+ "completion-tags",
722
+ "completion-types",
723
+ "guide",
724
+ ]),
725
+ ];
726
+ /** Exhaustive current command and positional-action signature table. */
727
+ export const PM_COMMAND_POSITIONAL_CONTRACTS = [
728
+ ...new Set(PM_COMMAND_DESTINATION_CONTRACTS.map(({ command }) => command)),
729
+ ].map((command) => ({
730
+ command,
731
+ slots: resolvePmPositionalActionContract(command)?.slots ??
732
+ EXPLICIT_POSITIONAL_SLOTS.get(command) ??
733
+ [],
734
+ }));
735
+ /** Immutable grammar policy used by contracts and the CI gate. */
736
+ export const PM_CLI_GRAMMAR_CONTRACT = {
737
+ nouns: PM_CLI_GRAMMAR_NOUNS,
738
+ shared_verbs: PM_CLI_SHARED_VERBS,
739
+ scope_before_verb: true,
740
+ visible_top_level_ceiling: 69,
741
+ ceiling_raise_requires_pm_item: true,
742
+ positional_shape_budget: 21,
743
+ };
744
+ /** Report explicit positional entries that no destination command declares. */
745
+ export function verifyExplicitPositionalSlotCensus(explicitCommands, destinationCommands) {
746
+ const destinations = new Set(destinationCommands);
747
+ return [...new Set(explicitCommands)]
748
+ .filter((command) => !destinations.has(command))
749
+ .map((command) => ({
750
+ code: "positional_signature_mismatch",
751
+ command,
752
+ detail: `Positional signature ${command} has no destination declaration.`,
753
+ }));
754
+ }
755
+ /** Return the semantic shape identity used by the positional-shape budget. */
756
+ export function positionalShapeKey(slots) {
757
+ return slots
758
+ .map(({ required, variadic, value_kind: valueKind, polymorphic }) => `${required ? "r" : "o"}:${variadic ? "v" : "s"}:${valueKind}:${polymorphic ? "p" : "m"}`)
759
+ .join("|");
760
+ }
761
+ /** Return the exact canonical identity of an ordered positional signature. */
762
+ export function positionalSignatureKey(slots) {
763
+ return slots
764
+ .map(({ name, required, variadic, value_kind: valueKind, polymorphic }) => `${name}:${required ? "r" : "o"}:${variadic ? "v" : "s"}:${valueKind}:${polymorphic ? "p" : "m"}`)
765
+ .join("|");
766
+ }
767
+ /** Return one deterministic finding for every repeated command path. */
768
+ function duplicatePositionalSignatureFindings(contracts, surface) {
769
+ const counts = new Map();
770
+ for (const { command } of contracts) {
771
+ const normalized = normalizePositionalCommandPath(command);
772
+ counts.set(normalized, (counts.get(normalized) ?? 0) + 1);
773
+ }
774
+ return [...counts.entries()]
775
+ .filter(([, count]) => count > 1)
776
+ .map(([command, count]) => ({
777
+ code: "positional_signature_mismatch",
778
+ command,
779
+ detail: `${count} ${surface} positional signatures exist for ${command}; exactly one is required.`,
780
+ }));
781
+ }
782
+ /** Compare independently observed Commander signatures with the SDK declaration. */
783
+ export function verifyPmCommandPositionalContracts(observed, options = {}) {
784
+ const declared = options.declared ?? PM_COMMAND_POSITIONAL_CONTRACTS;
785
+ const positionalShapeBudget = options.positionalShapeBudget ??
786
+ PM_CLI_GRAMMAR_CONTRACT.positional_shape_budget;
787
+ const declaredByCommand = new Map(declared.map((contract) => [normalizePositionalCommandPath(contract.command), contract]));
788
+ const observedByCommand = new Map(observed.map((contract) => [normalizePositionalCommandPath(contract.command), contract]));
789
+ const findings = [
790
+ ...duplicatePositionalSignatureFindings(declared, "declared"),
791
+ ...duplicatePositionalSignatureFindings(observed, "observed"),
792
+ ...(options.declared === undefined
793
+ ? [
794
+ ...verifyExplicitPositionalSlotCensus(EXPLICIT_POSITIONAL_SLOTS.keys(), PM_COMMAND_DESTINATION_CONTRACTS.map(({ command }) => command)),
795
+ ...verifyExplicitPositionalSlotCensus(PM_POSITIONAL_ACTION_CONTRACTS.map(({ command }) => command), PM_COMMAND_DESTINATION_CONTRACTS.map(({ command }) => command)),
796
+ ]
797
+ : []),
798
+ ];
799
+ for (const contract of declaredByCommand.values()) {
800
+ const normalizedCommand = normalizePositionalCommandPath(contract.command);
801
+ const actual = observedByCommand.get(normalizedCommand);
802
+ if (!actual) {
803
+ findings.push({
804
+ code: "missing_observed_signature",
805
+ command: contract.command,
806
+ detail: `No observed positional signature exists for ${contract.command}.`,
807
+ });
808
+ }
809
+ else if (positionalSignatureKey(actual.slots) !==
810
+ positionalSignatureKey(contract.slots)) {
811
+ findings.push({
812
+ code: "positional_signature_mismatch",
813
+ command: contract.command,
814
+ detail: `Observed positional signature for ${contract.command} differs from its declared SDK contract: observed=${positionalSignatureKey(actual.slots) || "<none>"}; declared=${positionalSignatureKey(contract.slots) || "<none>"}.`,
815
+ });
816
+ }
817
+ }
818
+ for (const contract of observedByCommand.values()) {
819
+ if (!declaredByCommand.has(normalizePositionalCommandPath(contract.command))) {
820
+ findings.push({
821
+ code: "stale_observed_signature",
822
+ command: contract.command,
823
+ detail: `Observed positional signature ${contract.command} has no declaration.`,
824
+ });
825
+ }
826
+ }
827
+ const positionalShapeCount = new Set(declared.map(({ slots }) => positionalShapeKey(slots))).size;
828
+ if (positionalShapeCount > positionalShapeBudget) {
829
+ findings.push({
830
+ code: "positional_shape_budget_exceeded",
831
+ command: "*",
832
+ detail: `Distinct positional shape count ${positionalShapeCount} exceeds budget ${positionalShapeBudget}.`,
833
+ });
834
+ }
835
+ findings.sort((left, right) => left.command !== right.command
836
+ ? left.command.localeCompare(right.command)
837
+ : left.code.localeCompare(right.code));
838
+ return {
839
+ ok: findings.length === 0,
840
+ declared_command_count: declared.length,
841
+ observed_command_count: observed.length,
842
+ positional_shape_count: positionalShapeCount,
843
+ positional_shape_budget: positionalShapeBudget,
844
+ findings,
845
+ };
846
+ }
847
+ function validateCommandDestinations(commands, destinationsByCommand, nounSet) {
848
+ return commands.flatMap((command) => {
849
+ const destinations = destinationsByCommand.get(command) ?? [];
850
+ if (destinations.length === 0) {
851
+ const separatorIndex = command.indexOf(" ");
852
+ const root = separatorIndex === -1 ? command : command.slice(0, separatorIndex);
853
+ return [
854
+ {
855
+ code: "missing_destination",
856
+ spelling: command,
857
+ message: `Command \`${command}\` has no destination census row.`,
858
+ nearest_target: nounSet.has(root) ? root : `ops ${command}`,
859
+ },
860
+ ];
861
+ }
862
+ const duplicateFinding = destinations.length > 1
863
+ ? [
864
+ {
865
+ code: "duplicate_destination",
866
+ spelling: command,
867
+ message: `Command \`${command}\` has ${destinations.length} destination rows.`,
868
+ nearest_target: destinations[0].target,
869
+ },
870
+ ]
871
+ : [];
872
+ return destinations.reduce((findings, destination) => {
873
+ if (destination.disposition === "keep_as_is" &&
874
+ (destination.reason?.trim().length ?? 0) === 0) {
875
+ findings.push({
876
+ code: "missing_destination",
877
+ spelling: command,
878
+ message: `Command \`${command}\` is kept as-is without a documented reason.`,
879
+ nearest_target: destination.target,
880
+ });
881
+ }
882
+ if (!nounSet.has(destination.noun)) {
883
+ findings.push({
884
+ code: "unknown_noun",
885
+ spelling: command,
886
+ message: `Command \`${command}\` names undeclared noun \`${destination.noun}\`.`,
887
+ nearest_target: destination.target,
888
+ });
889
+ }
890
+ return findings;
891
+ }, duplicateFinding);
892
+ });
893
+ }
894
+ function validateDestinationCensus(commandSet, destinations) {
895
+ return destinations
896
+ .filter((destination) => destination.disposition !== "package_owned" &&
897
+ !commandSet.has(destination.command))
898
+ .map((destination) => ({
899
+ code: "stale_destination",
900
+ spelling: destination.command,
901
+ message: `Destination row \`${destination.command}\` is absent from live contracts.`,
902
+ nearest_target: destination.target,
903
+ }));
904
+ }
905
+ function validateAliasTargets(aliases, commandSet) {
906
+ return aliases
907
+ .filter((alias) => !commandSet.has(alias.canonical))
908
+ .map((alias) => ({
909
+ code: "alias_target_missing",
910
+ spelling: alias.alias,
911
+ message: `Alias \`${alias.alias}\` targets missing canonical command \`${alias.canonical}\`.`,
912
+ nearest_target: alias.canonical_argv.join(" "),
913
+ }));
914
+ }
915
+ /** Implementation seam accepts an injected census for isolated conformance tests. */
916
+ export function verifyPmCliGrammar(commands, aliases = [], destinations = PM_COMMAND_DESTINATION_CONTRACTS) {
917
+ const normalizedCommands = [
918
+ ...new Set(commands.map((command) => command.trim())),
919
+ ]
920
+ .filter((command) => command.length > 0)
921
+ .sort((left, right) => left.localeCompare(right));
922
+ const commandSet = new Set(normalizedCommands);
923
+ const nounSet = new Set(PM_CLI_GRAMMAR_NOUNS);
924
+ const destinationsByCommand = new Map();
925
+ for (const destination of destinations) {
926
+ const entries = destinationsByCommand.get(destination.command) ?? [];
927
+ entries.push(destination);
928
+ destinationsByCommand.set(destination.command, entries);
929
+ }
930
+ const findings = [
931
+ ...validateCommandDestinations(normalizedCommands, destinationsByCommand, nounSet),
932
+ ...validateDestinationCensus(commandSet, destinations),
933
+ ...validateAliasTargets(aliases, commandSet),
934
+ ];
935
+ const hiddenAliasNames = new Set(aliases.filter((alias) => alias.hidden).map((alias) => alias.alias));
936
+ const visibleTopLevelCount = new Set(normalizedCommands.filter((command) => !command.includes(" ") &&
937
+ !hiddenAliasNames.has(command) &&
938
+ !(destinationsByCommand.get(command) ?? []).some((destination) => destination.disposition === "package_owned"))).size;
939
+ if (visibleTopLevelCount > PM_CLI_GRAMMAR_CONTRACT.visible_top_level_ceiling) {
940
+ findings.push({
941
+ code: "visible_surface_ceiling_exceeded",
942
+ spelling: String(visibleTopLevelCount),
943
+ message: `Visible non-package top-level command count ${visibleTopLevelCount} exceeds ceiling ${PM_CLI_GRAMMAR_CONTRACT.visible_top_level_ceiling}.`,
944
+ nearest_target: "Declare the noun placement and tracked waiver before raising the ceiling.",
945
+ });
946
+ }
947
+ return {
948
+ ok: findings.length === 0,
949
+ command_count: normalizedCommands.length,
950
+ destination_count: destinations.length,
951
+ hidden_alias_count: aliases.filter((alias) => alias.hidden).length,
952
+ visible_top_level_count: visibleTopLevelCount,
953
+ visible_top_level_ceiling: PM_CLI_GRAMMAR_CONTRACT.visible_top_level_ceiling,
954
+ findings,
955
+ };
956
+ }
957
+ //# sourceMappingURL=grammar-contracts.js.map
958
+ //# debugId=686e65f1-bf69-59f6-8e65-db4c4838008b