@unbrained/pm-cli 2026.8.9 → 2026.8.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 (249) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +142 -80
  3. package/dist/cli/commander-usage.js +94 -17
  4. package/dist/cli/error-guidance.d.ts +10 -0
  5. package/dist/cli/error-guidance.js +76 -25
  6. package/dist/cli/help-json-payload.js +51 -16
  7. package/dist/cli/main.js +11 -6
  8. package/dist/cli/register-assurance.d.ts +8 -0
  9. package/dist/cli/register-assurance.js +52 -0
  10. package/dist/cli/register-files-lookup.js +14 -3
  11. package/dist/cli/register-mutation.js +30 -9
  12. package/dist/cli/register-operations.js +16 -11
  13. package/dist/cli-bundle/bundle-manifest.json +163 -163
  14. package/dist/cli-bundle/chunks/{chunk-RJC7TPF4.js → chunk-2OOU2AFH.js} +2 -2
  15. package/dist/cli-bundle/chunks/chunk-2RA2YTHJ.js +33 -0
  16. package/dist/cli-bundle/chunks/chunk-A2SJGHSI.js +3 -0
  17. package/dist/cli-bundle/chunks/chunk-DSKYD4LG.js +13 -0
  18. package/dist/cli-bundle/chunks/chunk-HC3GM6YY.js +194 -0
  19. package/dist/cli-bundle/chunks/chunk-IUNRVDAI.js +2 -0
  20. package/dist/cli-bundle/chunks/chunk-W7CPZGSB.js +2 -0
  21. package/dist/cli-bundle/chunks/{chunk-YC3UF2IO.js → chunk-WMEZHCFI.js} +66 -60
  22. package/dist/cli-bundle/chunks/{chunk-GMX5YOI3.js → chunk-ZU34C3LH.js} +48 -48
  23. package/dist/cli-bundle/chunks/chunk-ZXOC6HG5.js +5 -0
  24. package/dist/cli-bundle/chunks/{register-list-query-BUE7PTCU.js → register-list-query-HAUXVUPY.js} +8 -8
  25. package/dist/cli-bundle/chunks/register-mutation-7Y5U7ABT.js +20 -0
  26. package/dist/cli-bundle/chunks/register-operations-EQX3DLAZ.js +2 -0
  27. package/dist/cli-bundle/chunks/{register-setup-UQDTNTLJ.js → register-setup-NOCOOWQY.js} +2 -2
  28. package/dist/cli-bundle/focused-chunks/{chunk-KNEHLPBF.js → chunk-23FTGO3W.js} +2 -2
  29. package/dist/cli-bundle/focused-chunks/{chunk-6DO4YQWZ.js → chunk-2DL3MRTD.js} +2 -2
  30. package/dist/cli-bundle/focused-chunks/chunk-3AYKXMYX.js +2 -0
  31. package/dist/cli-bundle/focused-chunks/chunk-4AHEC74N.js +2 -0
  32. package/dist/cli-bundle/focused-chunks/{chunk-MRWVJ3ZG.js → chunk-4H5IA6AV.js} +2 -2
  33. package/dist/cli-bundle/focused-chunks/chunk-4SV3ZKG3.js +16 -0
  34. package/dist/cli-bundle/focused-chunks/chunk-55BIB6DV.js +2 -0
  35. package/dist/cli-bundle/focused-chunks/chunk-6JW6Z2P5.js +8 -0
  36. package/dist/cli-bundle/focused-chunks/chunk-BKPIY34S.js +2 -0
  37. package/dist/cli-bundle/focused-chunks/chunk-D4PIWE6D.js +2 -0
  38. package/dist/cli-bundle/focused-chunks/chunk-DPO7TEFX.js +31 -0
  39. package/dist/cli-bundle/focused-chunks/{chunk-3WVHTUAW.js → chunk-E3KCL7AY.js} +2 -2
  40. package/dist/cli-bundle/focused-chunks/chunk-ERAAFLPS.js +153 -0
  41. package/dist/cli-bundle/focused-chunks/chunk-F6E4JZKG.js +2 -0
  42. package/dist/cli-bundle/focused-chunks/chunk-FPSYO5ZG.js +18 -0
  43. package/dist/cli-bundle/focused-chunks/{chunk-73FIJONU.js → chunk-J5EKAIVD.js} +2 -2
  44. package/dist/cli-bundle/focused-chunks/chunk-KDH5OX3D.js +4 -0
  45. package/dist/cli-bundle/focused-chunks/chunk-OJ3LVVIS.js +2 -0
  46. package/dist/cli-bundle/focused-chunks/chunk-TL5M2PAY.js +3 -0
  47. package/dist/cli-bundle/focused-chunks/chunk-UDAZWT25.js +6 -0
  48. package/dist/cli-bundle/focused-chunks/chunk-VABB4L5Y.js +17 -0
  49. package/dist/cli-bundle/main.js +13 -13
  50. package/dist/cli-bundle/sdk-authoring.js +1 -1
  51. package/dist/cli-bundle/sdk-contracts.js +1 -1
  52. package/dist/cli-bundle/sdk-core.js +41 -39
  53. package/dist/cli-bundle/sdk-governance.js +1 -1
  54. package/dist/cli-bundle/sdk-graph.js +1 -1
  55. package/dist/cli-bundle/sdk-merge.js +1 -1
  56. package/dist/cli-bundle/sdk-query.js +1 -1
  57. package/dist/cli-bundle/sdk-runtime.js +1 -1
  58. package/dist/cli-bundle/sdk-testing.js +1 -1
  59. package/dist/cli-bundle/sdk.js +2 -2
  60. package/dist/core/diagnostics/remediation.js +9 -9
  61. package/dist/core/fs/fs-utils.d.ts +10 -0
  62. package/dist/core/fs/fs-utils.js +16 -4
  63. package/dist/core/item/item-format.js +3 -32
  64. package/dist/core/schema/fields-file.d.ts +1 -2
  65. package/dist/core/schema/fields-file.js +4 -11
  66. package/dist/core/schema/runtime-schema.js +3 -10
  67. package/dist/core/schema/status-defs-file.d.ts +1 -2
  68. package/dist/core/schema/status-defs-file.js +4 -32
  69. package/dist/core/schema/status-token.d.ts +2 -0
  70. package/dist/core/schema/status-token.js +32 -0
  71. package/dist/core/schema/type-workflows.d.ts +1 -2
  72. package/dist/core/schema/type-workflows.js +4 -11
  73. package/dist/core/session/session-state.d.ts +47 -0
  74. package/dist/core/session/session-state.js +207 -6
  75. package/dist/core/shared/author.d.ts +8 -2
  76. package/dist/core/shared/author.js +85 -52
  77. package/dist/core/shared/errors.d.ts +12 -0
  78. package/dist/core/shared/errors.js +2 -2
  79. package/dist/core/shared/text-normalization.d.ts +1 -1
  80. package/dist/core/shared/text-normalization.js +2 -2
  81. package/dist/sdk/agent/command-recovery.d.ts +4 -0
  82. package/dist/sdk/agent/command-recovery.js +52 -0
  83. package/dist/sdk/agent/command-suggestions.d.ts +4 -0
  84. package/dist/sdk/agent/command-suggestions.js +67 -0
  85. package/dist/sdk/agent/create-option-policy.d.ts +12 -0
  86. package/dist/sdk/agent/create-option-policy.js +32 -0
  87. package/dist/sdk/agent/item-addressing.d.ts +19 -0
  88. package/dist/sdk/agent/item-addressing.js +208 -0
  89. package/dist/sdk/agent/refusal-reachability.d.ts +40 -0
  90. package/dist/sdk/agent/refusal-reachability.js +72 -0
  91. package/dist/sdk/agent/subcommand-recovery.d.ts +40 -0
  92. package/dist/sdk/agent/subcommand-recovery.js +84 -0
  93. package/dist/sdk/cli-bootstrap.d.ts +9 -1
  94. package/dist/sdk/cli-bootstrap.js +25 -10
  95. package/dist/sdk/cli-contracts/commander-mutation-options.js +16 -4
  96. package/dist/sdk/cli-contracts/completeness.js +13 -3
  97. package/dist/sdk/cli-contracts/enum-contracts.d.ts +1 -1
  98. package/dist/sdk/cli-contracts/enum-contracts.js +3 -2
  99. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  100. package/dist/sdk/cli-contracts/flag-contracts.js +77 -21
  101. package/dist/sdk/cli-contracts/registration-helpers.js +10 -2
  102. package/dist/sdk/cli-contracts/runtime-contracts.js +6 -3
  103. package/dist/sdk/cli-contracts/schemas/assurance-definition.d.ts +513 -0
  104. package/dist/sdk/cli-contracts/schemas/assurance-definition.js +251 -0
  105. package/dist/sdk/cli-contracts/tool-option-contracts.d.ts +6 -0
  106. package/dist/sdk/cli-contracts/tool-option-contracts.js +4 -2
  107. package/dist/sdk/cli-contracts/tool-parameter-tables.js +96 -4
  108. package/dist/sdk/cli-contracts/tool-schema.d.ts +2 -2
  109. package/dist/sdk/cli-contracts/tool-schema.js +49 -6
  110. package/dist/sdk/cli-contracts.d.ts +1 -1
  111. package/dist/sdk/cli-contracts.js +3 -3
  112. package/dist/sdk/completion.js +9 -3
  113. package/dist/sdk/config.js +9 -3
  114. package/dist/sdk/context/semantic-session-attribution.d.ts +32 -0
  115. package/dist/sdk/context/semantic-session-attribution.js +83 -0
  116. package/dist/sdk/context-intent-runtime.js +8 -5
  117. package/dist/sdk/context-signal-store.d.ts +34 -0
  118. package/dist/sdk/context-signal-store.js +24 -2
  119. package/dist/sdk/core-governance.d.ts +3 -1
  120. package/dist/sdk/core-governance.js +5 -3
  121. package/dist/sdk/core.d.ts +1 -1
  122. package/dist/sdk/core.js +2 -2
  123. package/dist/sdk/dependency-flag-validation.d.ts +15 -1
  124. package/dist/sdk/dependency-flag-validation.js +54 -2
  125. package/dist/sdk/error-code-catalog.d.ts +13 -0
  126. package/dist/sdk/error-code-catalog.js +35 -2
  127. package/dist/sdk/extension.js +18 -17
  128. package/dist/sdk/files.d.ts +11 -0
  129. package/dist/sdk/files.js +82 -24
  130. package/dist/sdk/generated-error-code-catalog.js +104 -13
  131. package/dist/sdk/governance/assurance-action-contracts.d.ts +7 -0
  132. package/dist/sdk/governance/assurance-action-contracts.js +5 -0
  133. package/dist/sdk/governance/assurance-action.d.ts +70 -0
  134. package/dist/sdk/governance/assurance-action.js +198 -0
  135. package/dist/sdk/governance/assurance-limits.d.ts +7 -0
  136. package/dist/sdk/governance/assurance-limits.js +11 -0
  137. package/dist/sdk/governance/assurance-runtime.d.ts +20 -0
  138. package/dist/sdk/governance/assurance-runtime.js +131 -0
  139. package/dist/sdk/governance/assurance.d.ts +432 -0
  140. package/dist/sdk/governance/assurance.js +689 -0
  141. package/dist/sdk/governance/health.js +14 -7
  142. package/dist/sdk/governance/provenance-health.d.ts +13 -0
  143. package/dist/sdk/governance/provenance-health.js +63 -17
  144. package/dist/sdk/governance/validate-item-reader.d.ts +13 -0
  145. package/dist/sdk/governance/validate-item-reader.js +18 -0
  146. package/dist/sdk/governance/validate.d.ts +2 -2
  147. package/dist/sdk/governance/validate.js +15 -6
  148. package/dist/sdk/graph/run.js +8 -3
  149. package/dist/sdk/index.d.ts +10 -1
  150. package/dist/sdk/index.js +12 -3
  151. package/dist/sdk/lifecycle/claim.js +18 -3
  152. package/dist/sdk/lifecycle/close.js +17 -14
  153. package/dist/sdk/lifecycle/create.d.ts +2 -0
  154. package/dist/sdk/lifecycle/create.js +62 -9
  155. package/dist/sdk/lifecycle/focus.js +13 -3
  156. package/dist/sdk/lifecycle/plan.js +8 -3
  157. package/dist/sdk/lifecycle/update-many.js +39 -27
  158. package/dist/sdk/lifecycle/update.d.ts +6 -1
  159. package/dist/sdk/lifecycle/update.js +47 -10
  160. package/dist/sdk/merge/index.d.ts +1 -1
  161. package/dist/sdk/merge/index.js +3 -3
  162. package/dist/sdk/merge/install.d.ts +4 -0
  163. package/dist/sdk/merge/install.js +28 -16
  164. package/dist/sdk/merge/receipts.d.ts +3 -0
  165. package/dist/sdk/merge/receipts.js +81 -17
  166. package/dist/sdk/output-projection.js +24 -4
  167. package/dist/sdk/provenance.d.ts +38 -0
  168. package/dist/sdk/provenance.js +64 -2
  169. package/dist/sdk/query/context.d.ts +2 -0
  170. package/dist/sdk/query/context.js +24 -10
  171. package/dist/sdk/query/light-metadata.d.ts +3 -0
  172. package/dist/sdk/query/light-metadata.js +19 -0
  173. package/dist/sdk/runtime-extended-actions.js +22 -5
  174. package/dist/sdk/runtime-primitives.d.ts +2 -0
  175. package/dist/sdk/runtime-primitives.js +4 -2
  176. package/dist/sdk/runtime.d.ts +8 -1
  177. package/dist/sdk/runtime.js +37 -28
  178. package/dist/sdk/schema-migration.js +7 -9
  179. package/dist/sdk/similarity-scoring.d.ts +1 -2
  180. package/dist/sdk/similarity-scoring.js +4 -16
  181. package/dist/sdk/telemetry.js +7 -4
  182. package/dist/sdk/traceability/runtime-files-lookup.d.ts +8 -0
  183. package/dist/sdk/traceability/runtime-files-lookup.js +33 -0
  184. package/dist/sdk/traceability/source-traceability.d.ts +102 -0
  185. package/dist/sdk/traceability/source-traceability.js +293 -0
  186. package/dist/sdk/workspace-snapshot.d.ts +4 -0
  187. package/dist/sdk/workspace-snapshot.js +24 -11
  188. package/dist/types.d.ts +8 -2
  189. package/dist/types.js +2 -2
  190. package/docs/AGENT_GUIDE.md +3 -1
  191. package/docs/ASSURANCE.md +132 -0
  192. package/docs/COMMANDS.md +8 -5
  193. package/docs/MERGE_SAFETY.md +7 -5
  194. package/docs/README.md +3 -5
  195. package/docs/READ_OUTPUT_CONTRACTS.md +2 -2
  196. package/docs/RELEASING.md +9 -5
  197. package/docs/SDK.md +44 -8
  198. package/docs/SDK_AGENT_SESSION_CONTEXT.md +43 -6
  199. package/docs/SDK_CONTEXT.md +97 -0
  200. package/docs/SDK_CONTEXT_INTEGRITY.md +18 -3
  201. package/docs/SDK_EVIDENCE_TRACEABILITY.md +39 -1
  202. package/docs/SDK_RUNTIME_BOUNDARIES.md +36 -1
  203. package/docs/TESTING.md +12 -9
  204. package/docs/agent-task-token-baseline.json +2 -2
  205. package/docs/generated/AGENT_COMMAND_SURFACE.md +1 -0
  206. package/marketplace.json +2 -2
  207. package/package.json +7 -6
  208. package/packages/pm-beads/package.json +1 -1
  209. package/packages/pm-calendar/package.json +1 -1
  210. package/packages/pm-command-kit/package.json +1 -1
  211. package/packages/pm-digital-twin/package.json +1 -1
  212. package/packages/pm-governance-audit/package.json +1 -1
  213. package/packages/pm-guide-shell/package.json +1 -1
  214. package/packages/pm-kanban/package.json +1 -1
  215. package/packages/pm-lifecycle-hooks/package.json +1 -1
  216. package/packages/pm-linked-test-adapters/package.json +1 -1
  217. package/packages/pm-search-advanced/package.json +1 -1
  218. package/packages/pm-templates/extensions/templates/index.ts +9 -3
  219. package/packages/pm-templates/package.json +1 -1
  220. package/packages/pm-todos/package.json +1 -1
  221. package/packages/pm-vcs/package.json +1 -1
  222. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  223. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  224. package/sdk/public-surface.json +1028 -48
  225. package/dist/cli-bundle/chunks/chunk-2DTCZXSD.js +0 -13
  226. package/dist/cli-bundle/chunks/chunk-5JO6R4BS.js +0 -3
  227. package/dist/cli-bundle/chunks/chunk-5KN4DZYV.js +0 -194
  228. package/dist/cli-bundle/chunks/chunk-EF43KODO.js +0 -2
  229. package/dist/cli-bundle/chunks/chunk-HUV2Z7IS.js +0 -28
  230. package/dist/cli-bundle/chunks/chunk-MHBVCUF2.js +0 -2
  231. package/dist/cli-bundle/chunks/chunk-PYO5GZU6.js +0 -5
  232. package/dist/cli-bundle/chunks/register-mutation-FC3XLVIK.js +0 -20
  233. package/dist/cli-bundle/chunks/register-operations-YH2WAOXU.js +0 -2
  234. package/dist/cli-bundle/focused-chunks/chunk-2VVP5RAA.js +0 -153
  235. package/dist/cli-bundle/focused-chunks/chunk-3GSFUDAI.js +0 -2
  236. package/dist/cli-bundle/focused-chunks/chunk-4H6MVCK3.js +0 -16
  237. package/dist/cli-bundle/focused-chunks/chunk-54TZJ4BM.js +0 -2
  238. package/dist/cli-bundle/focused-chunks/chunk-5NK5TJ5D.js +0 -2
  239. package/dist/cli-bundle/focused-chunks/chunk-C3GCHDSQ.js +0 -31
  240. package/dist/cli-bundle/focused-chunks/chunk-JGRSQZJT.js +0 -18
  241. package/dist/cli-bundle/focused-chunks/chunk-NL57J7BZ.js +0 -4
  242. package/dist/cli-bundle/focused-chunks/chunk-P6BBIQRG.js +0 -6
  243. package/dist/cli-bundle/focused-chunks/chunk-PZAGVQNN.js +0 -3
  244. package/dist/cli-bundle/focused-chunks/chunk-QDAO3XEK.js +0 -14
  245. package/dist/cli-bundle/focused-chunks/chunk-T4IGQCSY.js +0 -2
  246. package/dist/cli-bundle/focused-chunks/chunk-U46GQJNY.js +0 -2
  247. package/dist/cli-bundle/focused-chunks/chunk-VRXJSGIT.js +0 -8
  248. package/dist/cli-bundle/focused-chunks/chunk-XC2ZW3CJ.js +0 -2
  249. package/dist/cli-bundle/focused-chunks/chunk-ZG54B4XG.js +0 -2
@@ -4,7 +4,7 @@
4
4
  * Implements the pm extension command surface and its agent-facing runtime behavior.
5
5
  */
6
6
 
7
- !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]="f4b47053-cc05-51f2-b5cb-cc6dba3365c2")}catch(e){}}();
7
+ !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]="8b0fbe09-2221-5b8e-8712-90a83df19306")}catch(e){}}();
8
8
  import fs from "node:fs/promises";
9
9
  import path from "node:path";
10
10
  import { activateExtensions, createSerialQueue, loadExtensions, nextExtensionReloadToken, } from "../core/extensions/index.js";
@@ -20,6 +20,7 @@ import { nowIso } from "../core/shared/time.js";
20
20
  import { resolveGlobalPmRoot, resolvePmRoot } from "../core/store/paths.js";
21
21
  import { readSettings, writeSettings } from "../core/store/settings.js";
22
22
  import { quoteCommandArg, renderPmCommand } from "./command-line.js";
23
+ import { createUnknownSubcommandError } from "./agent/subcommand-recovery.js";
23
24
  import { ensureTypeFolderScaffold } from "./schema.js";
24
25
  // Cohesive helper groups now live in ./extension/* sibling modules. They are
25
26
  // imported for the command wiring that stays here and re-exported below so
@@ -321,21 +322,21 @@ const buildUnknownLifecycleActionError = (target, options) => {
321
322
  return new PmCliError(`One action flag is required. Use one of: ${LIFECYCLE_ACTION_FLAG_HINT}. Bare \`pm package\` and \`pm extension\` default to --explore.`, EXIT_CODE.USAGE);
322
323
  }
323
324
  const command = `pm ${noun} ${suggestion.flag}`;
324
- return new PmCliError(`Unknown ${noun} lifecycle action "${target}". Did you mean "${suggestion.flag}"?`, EXIT_CODE.USAGE, {
325
- code: "unknown_lifecycle_action",
326
- required: `Use one of: ${LIFECYCLE_ACTION_FLAG_HINT}.`,
327
- examples: [command, `pm ${noun} --help`],
328
- recovery: {
329
- attempted_command: `pm ${noun} ${target}`,
330
- suggested_retry: command,
331
- fallback_candidates: [
332
- {
333
- source: "lifecycle_action",
334
- command,
335
- reason: `nearest lifecycle action for "${target}"`,
336
- },
337
- ],
338
- },
325
+ return createUnknownSubcommandError({
326
+ command_path: noun,
327
+ display_name: `${noun} lifecycle`,
328
+ token_kind: "action",
329
+ token: target,
330
+ allowed: Object.keys(IMPLICIT_EXTENSION_ACTIONS),
331
+ retry_command: command,
332
+ message_suffix: `. Did you mean "${suggestion.flag}"?`,
333
+ fallback_candidates: [
334
+ {
335
+ source: "lifecycle_action",
336
+ command,
337
+ reason: `nearest lifecycle action for "${target}"`,
338
+ },
339
+ ],
339
340
  });
340
341
  };
341
342
  // Maps each boolean action flag to the lifecycle action it selects. `scaffold`
@@ -2190,4 +2191,4 @@ export const _testOnly = {
2190
2191
  withExtensionInstallLock,
2191
2192
  };
2192
2193
  //# sourceMappingURL=extension.js.map
2193
- //# debugId=f4b47053-cc05-51f2-b5cb-cc6dba3365c2
2194
+ //# debugId=8b0fbe09-2221-5b8e-8712-90a83df19306
@@ -1,6 +1,7 @@
1
1
  import type { GlobalOptions } from "../core/shared/command-types.js";
2
2
  import type { ItemDocument, LinkedFile, LinkScope } from "../types/index.js";
3
3
  import { type LinkedPathValidation } from "./linked-artifacts.js";
4
+ import { type SourceLineRange, type SourceTraceabilityExplanation, type SourceTraceabilityReceipt } from "./traceability/source-traceability.js";
4
5
  /** Documents the files command options payload exchanged by command, SDK, and package integrations. */
5
6
  export interface FilesCommandOptions {
6
7
  /** Value that configures or reports add for this contract. */
@@ -112,6 +113,12 @@ export interface FilesLookupOptions {
112
113
  noTruncate?: boolean;
113
114
  /** Fail when any authoritative item cannot be read. */
114
115
  strictRead?: boolean;
116
+ /** Include rationale, governing-decision paths, and ambiguity receipts. */
117
+ explain?: boolean;
118
+ /** Optional inclusive line range; implies explain and requires one path. */
119
+ lineRange?: SourceLineRange;
120
+ /** Maximum relationship depth searched for a governing decision. */
121
+ decisionDepth?: number;
115
122
  }
116
123
  /** Token-efficient item identity returned by reverse linked-file lookup. */
117
124
  export interface FilesLookupItem {
@@ -134,6 +141,8 @@ export interface FilesLookupMatch {
134
141
  item: FilesLookupItem;
135
142
  /** Matching linked-file evidence. */
136
143
  files: LinkedFile[];
144
+ /** Optional bounded rationale and line-attribution explanation. */
145
+ traceability?: SourceTraceabilityExplanation;
137
146
  }
138
147
  /** Reverse linked-file lookup result with bounded output and read provenance. */
139
148
  export interface FilesLookupResult {
@@ -160,6 +169,8 @@ export interface FilesLookupResult {
160
169
  warnings: string[];
161
170
  /** Ordered reverse-traceability matches. */
162
171
  matches: FilesLookupMatch[];
172
+ /** Aggregate receipt for an explained source query. */
173
+ traceability_receipt?: SourceTraceabilityReceipt;
163
174
  }
164
175
  interface TextReference {
165
176
  field: string;
package/dist/sdk/files.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * Implements the pm files command surface and its agent-facing runtime behavior.
5
5
  */
6
6
 
7
- !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]="5e45d0f1-a1a7-50ea-a9a3-ec6283d3471d")}catch(e){}}();
7
+ !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]="515cd35c-8e0e-51d4-8ad9-1cea5be8a572")}catch(e){}}();
8
8
  import fs from "node:fs/promises";
9
9
  import path from "node:path";
10
10
  import { pathExists } from "../core/fs/fs-utils.js";
@@ -20,6 +20,7 @@ import { readSettings } from "../core/store/settings.js";
20
20
  import { resolveAuthor } from "../core/shared/author.js";
21
21
  import { isPathWithinDirectory } from "../core/fs/path-utils.js";
22
22
  import { dedupeLinkedArtifacts, normalizeLinkedPath, renameArtifactsResultKey, runLinkedArtifacts, sortLinkedArtifacts, } from "./linked-artifacts.js";
23
+ import { explainSourceTraceability, } from "./traceability/source-traceability.js";
23
24
  /** Bounds fuzzy relative-path scanning while preserving full absolute-path discovery. */
24
25
  const RELATIVE_REFERENCE_SCAN_MAX_CHARS = 32_768;
25
26
  function normalizeCandidatePathForOutput(value) {
@@ -251,8 +252,51 @@ function projectFilesLookupItem(item) {
251
252
  updated_at: item.updated_at,
252
253
  };
253
254
  }
255
+ function compareFilesLookupCandidates(left, right) {
256
+ const byPriority = left.item.priority - right.item.priority;
257
+ if (byPriority !== 0)
258
+ return byPriority;
259
+ const byUpdated = right.item.updated_at.localeCompare(left.item.updated_at);
260
+ return byUpdated === 0
261
+ ? left.item.id.localeCompare(right.item.id)
262
+ : byUpdated;
263
+ }
264
+ function matchingFilesLookupCandidates(params) {
265
+ return params.metadata
266
+ .map((item) => ({
267
+ item,
268
+ files: (item.files ?? [])
269
+ .filter((file) => params.paths.includes(normalizeLinkedPath(file.path)) &&
270
+ (params.scope === undefined || file.scope === params.scope))
271
+ .sort((left, right) => {
272
+ const byPath = left.path.localeCompare(right.path);
273
+ return byPath === 0 ? left.scope.localeCompare(right.scope) : byPath;
274
+ }),
275
+ }))
276
+ .filter((match) => match.files.length > 0)
277
+ .sort(compareFilesLookupCandidates);
278
+ }
279
+ async function resolveFilesLookupTraceability(params) {
280
+ if (!params.explain)
281
+ return undefined;
282
+ return explainSourceTraceability({
283
+ workspaceRoot: params.workspaceRoot,
284
+ paths: params.paths,
285
+ candidates: params.matching,
286
+ corpus: params.metadata,
287
+ ...(params.lineRange ? { lineRange: params.lineRange } : {}),
288
+ ...(params.decisionDepth === undefined
289
+ ? {}
290
+ : { decisionDepth: params.decisionDepth }),
291
+ });
292
+ }
254
293
  async function queryFilesLookupIndex(params) {
255
- if ([params.strictRead, params.noTruncate, hasActiveOnReadHooks()].includes(true)) {
294
+ if ([
295
+ params.strictRead,
296
+ params.noTruncate,
297
+ params.explain,
298
+ hasActiveOnReadHooks(),
299
+ ].includes(true)) {
256
300
  return null;
257
301
  }
258
302
  const indexState = await readItemMetadataDerivedIndexState(params.pmRoot, [
@@ -272,32 +316,34 @@ async function queryFilesLookupIndex(params) {
272
316
  async function queryFilesLookupSource(params) {
273
317
  const warnings = [];
274
318
  const metadata = await listAllItemMetadata(params.pmRoot, params.settings.item_format, params.typeToFolder, warnings, params.settings.schema);
275
- const matching = metadata
276
- .map((item) => ({
277
- item,
278
- files: (item.files ?? [])
279
- .filter((file) => params.paths.includes(normalizeLinkedPath(file.path)) &&
280
- (params.scope === undefined || file.scope === params.scope))
281
- .sort((left, right) => {
282
- const byPath = left.path.localeCompare(right.path);
283
- return byPath === 0 ? left.scope.localeCompare(right.scope) : byPath;
284
- }),
285
- }))
286
- .filter((match) => match.files.length > 0)
287
- .sort((left, right) => {
288
- const byPriority = left.item.priority - right.item.priority;
289
- if (byPriority !== 0)
290
- return byPriority;
291
- const byUpdated = right.item.updated_at.localeCompare(left.item.updated_at);
292
- return byUpdated === 0
293
- ? left.item.id.localeCompare(right.item.id)
294
- : byUpdated;
319
+ const matching = matchingFilesLookupCandidates({
320
+ metadata,
321
+ paths: params.paths,
322
+ scope: params.scope,
295
323
  });
296
324
  const readWarnings = warnings.filter((warning) => /^item_list_(?:item|directory)_read_failed:/u.test(warning));
297
325
  if (params.strictRead && readWarnings.length > 0) {
298
326
  throw new PmCliError(`Files lookup could not read every item: ${readWarnings.join("; ")}`, EXIT_CODE.GENERIC_FAILURE);
299
327
  }
300
- const page = matching.slice(params.offset, params.limit === undefined ? undefined : params.offset + params.limit);
328
+ const traceability = await resolveFilesLookupTraceability({
329
+ explain: params.explain,
330
+ workspaceRoot: params.workspaceRoot,
331
+ paths: params.paths,
332
+ matching,
333
+ metadata,
334
+ lineRange: params.lineRange,
335
+ decisionDepth: params.decisionDepth,
336
+ });
337
+ const ranked = traceability
338
+ ? [...matching].sort((left, right) => {
339
+ const byScore = traceability.explanations.get(right.item.id).score -
340
+ traceability.explanations.get(left.item.id).score;
341
+ if (byScore !== 0)
342
+ return byScore;
343
+ return compareFilesLookupCandidates(left, right);
344
+ })
345
+ : matching;
346
+ const page = ranked.slice(params.offset, params.limit === undefined ? undefined : params.offset + params.limit);
301
347
  return {
302
348
  paths: params.paths,
303
349
  total: matching.length,
@@ -314,7 +360,11 @@ async function queryFilesLookupSource(params) {
314
360
  matches: page.map((match) => ({
315
361
  item: projectFilesLookupItem(match.item),
316
362
  files: match.files,
363
+ ...(traceability
364
+ ? { traceability: traceability.explanations.get(match.item.id) }
365
+ : {}),
317
366
  })),
367
+ ...(traceability ? { traceability_receipt: traceability.receipt } : {}),
318
368
  };
319
369
  }
320
370
  /** Resolve the pm items that reference one or more source paths. */
@@ -325,6 +375,9 @@ export async function runFilesLookup(options, global) {
325
375
  throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);
326
376
  }
327
377
  const paths = await normalizeFilesLookupPaths(options.paths, workspaceRoot);
378
+ if (options.lineRange && paths.length !== 1) {
379
+ throw new PmCliError("Files lookup line attribution requires exactly one source path.", EXIT_CODE.USAGE);
380
+ }
328
381
  const settings = await readSettings(pmRoot);
329
382
  const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());
330
383
  const { offset, limit } = resolveFilesLookupWindow(options);
@@ -337,6 +390,7 @@ export async function runFilesLookup(options, global) {
337
390
  offset,
338
391
  strictRead: options.strictRead === true,
339
392
  noTruncate: options.noTruncate === true,
393
+ explain: options.explain === true || options.lineRange !== undefined,
340
394
  });
341
395
  if (indexed) {
342
396
  return {
@@ -364,6 +418,10 @@ export async function runFilesLookup(options, global) {
364
418
  limit,
365
419
  offset,
366
420
  strictRead: options.strictRead === true,
421
+ workspaceRoot,
422
+ explain: options.explain === true || options.lineRange !== undefined,
423
+ lineRange: options.lineRange,
424
+ decisionDepth: options.decisionDepth,
367
425
  });
368
426
  }
369
427
  /** Implements run files discover for the public runtime surface of this module. */
@@ -479,4 +537,4 @@ export async function runFilesDiscover(id, options, global) {
479
537
  };
480
538
  }
481
539
  //# sourceMappingURL=files.js.map
482
- //# debugId=5e45d0f1-a1a7-50ea-a9a3-ec6283d3471d
540
+ //# debugId=515cd35c-8e0e-51d4-8ad9-1cea5be8a572
@@ -4,10 +4,34 @@
4
4
  * Generated by scripts/generate-error-code-catalog.mjs. Do not edit manually.
5
5
  */
6
6
 
7
- !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]="bcb7a0a9-268f-5cf8-aefc-766b67e92168")}catch(e){}}();
7
+ !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]="07d93565-d5ef-5c3d-ae8a-214973e6ec20")}catch(e){}}();
8
8
  import { definePmErrorCodeCatalog } from "./error-code-catalog.js";
9
9
  /** Exhaustive catalog generated from literal error guidance declarations. */
10
10
  export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
11
+ {
12
+ code: "acceptance_criteria_mutation_conflict",
13
+ meaning: "Acceptance criteria mutation conflict condition.",
14
+ stability: "provisional",
15
+ exit_code: 2,
16
+ class: "usage",
17
+ recovery: "Inspect the structured error guidance and retry the suggested command.",
18
+ sources: ["sdk/lifecycle/update.ts"],
19
+ emitting_commands: ["update", "update-many"],
20
+ canonical_code: "acceptance_criteria_mutation_conflict",
21
+ aliases: [],
22
+ },
23
+ {
24
+ code: "acceptance_criteria_remove_unmatched",
25
+ meaning: "Acceptance criteria remove unmatched condition.",
26
+ stability: "provisional",
27
+ exit_code: 3,
28
+ class: "not_found",
29
+ recovery: "Inspect the structured error guidance and retry the suggested command.",
30
+ sources: ["sdk/lifecycle/update-many.ts", "sdk/lifecycle/update.ts"],
31
+ emitting_commands: ["update", "update-many"],
32
+ canonical_code: "acceptance_criteria_remove_unmatched",
33
+ aliases: [],
34
+ },
11
35
  {
12
36
  code: "acceptance_criteria_semicolon_forbidden",
13
37
  meaning: "Acceptance criteria semicolon forbidden condition.",
@@ -92,6 +116,18 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
92
116
  canonical_code: "append_empty_body",
93
117
  aliases: [],
94
118
  },
119
+ {
120
+ code: "assurance_registry_invalid",
121
+ meaning: "Assurance registry invalid condition.",
122
+ stability: "provisional",
123
+ exit_code: 1,
124
+ class: "generic_failure",
125
+ recovery: "Inspect the structured error guidance and retry the suggested command.",
126
+ sources: ["sdk/governance/assurance.ts"],
127
+ emitting_commands: ["*"],
128
+ canonical_code: "assurance_registry_invalid",
129
+ aliases: [],
130
+ },
95
131
  {
96
132
  code: "body_file_conflicts_with_body",
97
133
  meaning: "Body file conflicts with body condition.",
@@ -308,6 +344,42 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
308
344
  canonical_code: "conflicting_lifecycle_owner",
309
345
  aliases: [],
310
346
  },
347
+ {
348
+ code: "context_signal_store_invalid",
349
+ meaning: "Context signal store invalid condition.",
350
+ stability: "provisional",
351
+ exit_code: 2,
352
+ class: "usage",
353
+ recovery: "Inspect the structured error guidance and retry the suggested command.",
354
+ sources: ["sdk/context-signal-store.ts"],
355
+ emitting_commands: ["*"],
356
+ canonical_code: "context_signal_store_invalid",
357
+ aliases: [],
358
+ },
359
+ {
360
+ code: "context_signal_store_stale",
361
+ meaning: "Context signal store stale condition.",
362
+ stability: "provisional",
363
+ exit_code: 1,
364
+ class: "generic_failure",
365
+ recovery: "Inspect the structured error guidance and retry the suggested command.",
366
+ sources: ["sdk/context-signal-store.ts"],
367
+ emitting_commands: ["*"],
368
+ canonical_code: "context_signal_store_stale",
369
+ aliases: [],
370
+ },
371
+ {
372
+ code: "context_signal_store_write_failed",
373
+ meaning: "Context signal store write failed condition.",
374
+ stability: "provisional",
375
+ exit_code: 1,
376
+ class: "generic_failure",
377
+ recovery: "Inspect the structured error guidance and retry the suggested command.",
378
+ sources: ["sdk/context-signal-store.ts"],
379
+ emitting_commands: ["*"],
380
+ canonical_code: "context_signal_store_write_failed",
381
+ aliases: [],
382
+ },
311
383
  {
312
384
  code: "context_takes_no_item_argument",
313
385
  meaning: "Context takes no item argument condition.",
@@ -356,6 +428,18 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
356
428
  canonical_code: "dependency_edge_not_allowed",
357
429
  aliases: [],
358
430
  },
431
+ {
432
+ code: "dependency_target_not_found",
433
+ meaning: "Dependency target not found condition.",
434
+ stability: "provisional",
435
+ exit_code: 3,
436
+ class: "not_found",
437
+ recovery: "Inspect the structured error guidance and retry the suggested command.",
438
+ sources: ["sdk/dependency-flag-validation.ts"],
439
+ emitting_commands: ["*"],
440
+ canonical_code: "dependency_target_not_found",
441
+ aliases: [],
442
+ },
359
443
  {
360
444
  code: "duplicate_command",
361
445
  meaning: "Duplicate command condition.",
@@ -2174,13 +2258,16 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2174
2258
  code: "tracker_not_initialized",
2175
2259
  meaning: "Tracker not initialized condition.",
2176
2260
  stability: "stable",
2177
- exit_code: 1,
2178
- class: "generic_failure",
2261
+ exit_code: 3,
2262
+ class: "not_found",
2179
2263
  recovery: "Inspect the structured error guidance and retry the suggested command.",
2180
2264
  sources: ["cli/error-guidance.ts", "core/telemetry/observability.ts"],
2181
2265
  emitting_commands: ["*"],
2182
2266
  canonical_code: "tracker_not_initialized",
2183
2267
  aliases: [],
2268
+ owned_states: [
2269
+ { state: "selected_tracker_root_is_a_regular_file", probe_id: "tracker-root-regular-file", entrypoints: ["list"], expected_exit_class: "not_found" },
2270
+ ],
2184
2271
  },
2185
2272
  {
2186
2273
  code: "tracker_root_missing",
@@ -2313,9 +2400,9 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2313
2400
  exit_code: 2,
2314
2401
  class: "usage",
2315
2402
  recovery: "Inspect the structured error guidance and retry the suggested command.",
2316
- sources: ["sdk/extension.ts"],
2403
+ sources: ["sdk/agent/subcommand-recovery.ts"],
2317
2404
  emitting_commands: ["*"],
2318
- canonical_code: "unknown_lifecycle_action",
2405
+ canonical_code: "unknown_subcommand",
2319
2406
  aliases: [],
2320
2407
  },
2321
2408
  {
@@ -2329,6 +2416,9 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2329
2416
  emitting_commands: ["*"],
2330
2417
  canonical_code: "unknown_option",
2331
2418
  aliases: [],
2419
+ owned_states: [
2420
+ { state: "declared_option_is_rejected_on_the_selected_command_path", probe_id: "cross-command-unknown-option", entrypoints: ["deps"], expected_exit_class: "usage" },
2421
+ ],
2332
2422
  },
2333
2423
  {
2334
2424
  code: "unknown_plan_template",
@@ -2373,15 +2463,16 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
2373
2463
  exit_code: 2,
2374
2464
  class: "usage",
2375
2465
  recovery: "Inspect the structured error guidance and retry the suggested command.",
2376
- sources: [
2377
- "cli/register-mutation.ts",
2378
- "cli/register-operations.ts",
2379
- "sdk/runtime-extended-actions.ts",
2380
- "sdk/telemetry.ts",
2381
- ],
2466
+ sources: ["cli/error-guidance.ts", "sdk/agent/subcommand-recovery.ts"],
2382
2467
  emitting_commands: ["*"],
2383
2468
  canonical_code: "unknown_subcommand",
2384
- aliases: [],
2469
+ aliases: ["unknown_lifecycle_action"],
2470
+ owned_states: [
2471
+ { state: "config_action_token_is_not_declared", probe_id: "config-unknown-action", entrypoints: ["config"], expected_exit_class: "usage" },
2472
+ { state: "graph_command_token_is_not_declared", probe_id: "graph-unknown-subcommand", entrypoints: ["graph"], expected_exit_class: "usage" },
2473
+ { state: "nested_command_token_is_not_declared_by_its_family", probe_id: "schema-unknown-subcommand", entrypoints: ["schema"], expected_exit_class: "usage" },
2474
+ { state: "package_lifecycle_token_is_not_declared", probe_id: "package-unknown-action", entrypoints: ["package"], expected_exit_class: "usage" },
2475
+ ],
2385
2476
  },
2386
2477
  {
2387
2478
  code: "unsupported_update_option",
@@ -3057,4 +3148,4 @@ export const PM_ERROR_CODE_CATALOG = definePmErrorCodeCatalog([
3057
3148
  },
3058
3149
  ]);
3059
3150
  //# sourceMappingURL=generated-error-code-catalog.js.map
3060
- //# debugId=bcb7a0a9-268f-5cf8-aefc-766b67e92168
3151
+ //# debugId=07d93565-d5ef-5c3d-ae8a-214973e6ec20
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module sdk/governance/assurance-action-contracts
3
+ *
4
+ * Exposes assurance action transport types without coupling callers to the
5
+ * governance implementation module.
6
+ */
7
+ export type { AssuranceActionInput, AssuranceActionResult, } from "./assurance-action.js";
@@ -0,0 +1,5 @@
1
+
2
+ !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]="443beddb-37c9-5244-a157-e07624e4a6d2")}catch(e){}}();
3
+ export {};
4
+ //# sourceMappingURL=assurance-action-contracts.js.map
5
+ //# debugId=443beddb-37c9-5244-a157-e07624e4a6d2
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @module sdk/assurance-action
3
+ *
4
+ * Normalizes the assurance action vocabulary once for CLI, SDK, and MCP hosts.
5
+ */
6
+ import type { GlobalOptions } from "../../core/shared/command-types.js";
7
+ import { type AssuranceDeclaration, type AssuranceGateVerdict, type AssuranceMutationReceipt } from "./assurance.js";
8
+ /** Assurance registry and evaluation verbs shared by every transport. */
9
+ export declare const ASSURANCE_ACTIONS: readonly ["list", "show", "put", "remove", "run", "verdicts"];
10
+ /** Assurance declaration kinds shared by every transport. */
11
+ export declare const ASSURANCE_DECLARATION_KINDS: readonly ["measurement", "assertion", "gate"];
12
+ /** Assurance action verb. */
13
+ export type AssuranceAction = (typeof ASSURANCE_ACTIONS)[number];
14
+ /** Transport-neutral assurance action request. */
15
+ export interface AssuranceActionInput {
16
+ /** CRUD, evaluation, or verdict-history action. */
17
+ action: string;
18
+ /** Declaration kind for registry actions. */
19
+ kind?: string;
20
+ /** Declaration id, gate id, or verdict gate filter. */
21
+ id?: string;
22
+ /** JSON object or serialized JSON declaration for put. */
23
+ definition?: unknown;
24
+ /** Lifecycle trigger for gate evaluation. */
25
+ trigger?: string;
26
+ /** Explicit commit, tree, or snapshot identity. */
27
+ tree?: string;
28
+ /** Verdict-history gate filter when id is used by another host field. */
29
+ gate?: string;
30
+ /** Maximum newest durable verdicts returned. */
31
+ limit?: number | string;
32
+ /** Evaluate without appending an immutable verdict. */
33
+ dry_run?: boolean;
34
+ /** Retain the complete mutation receipt; assurance receipts are complete by default. */
35
+ fullChangedFields?: boolean;
36
+ /** Project declaration mutations to their stable id. */
37
+ idOnly?: boolean;
38
+ /** Explicit author override. */
39
+ author?: string;
40
+ /** Audited mutation rationale. */
41
+ message?: string;
42
+ }
43
+ /** Result union returned by transport-neutral assurance execution. */
44
+ export type AssuranceActionResult = AssuranceDeclaration | AssuranceMutationReceipt | AssuranceGateVerdict | {
45
+ id: string;
46
+ } | {
47
+ /** Registry declarations. */
48
+ items: AssuranceDeclaration[];
49
+ /** Number of declarations. */
50
+ count: number;
51
+ /** Stable row-selection contract. */
52
+ row_contract: {
53
+ row_keys: ["items"];
54
+ jq_selector: ".items[]";
55
+ };
56
+ } | {
57
+ /** Durable gate verdicts. */
58
+ items: AssuranceGateVerdict[];
59
+ /** Number of verdicts. */
60
+ count: number;
61
+ /** Stable row-selection contract. */
62
+ row_contract: {
63
+ row_keys: ["items"];
64
+ jq_selector: ".items[]";
65
+ };
66
+ };
67
+ /** Execute one assurance request through the public assurance SDK primitives. */
68
+ export declare function runAssuranceAction(input: AssuranceActionInput, global?: Pick<GlobalOptions, "path">): Promise<AssuranceActionResult>;
69
+ /** Normalize a generic SDK or MCP argument envelope into one assurance request. */
70
+ export declare function runAssuranceDispatch(args: Record<string, unknown>, options: Record<string, unknown>, global: GlobalOptions): Promise<AssuranceActionResult>;