@unbrained/pm-cli 2026.8.10 → 2026.8.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 (243) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +153 -100
  3. package/dist/cli/commander-usage.js +113 -15
  4. package/dist/cli/error-guidance.d.ts +12 -0
  5. package/dist/cli/error-guidance.js +147 -29
  6. package/dist/cli/main.js +38 -19
  7. package/dist/cli/register-annotations.js +56 -3
  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-list-query.js +10 -7
  12. package/dist/cli/register-mutation.js +30 -9
  13. package/dist/cli/register-operations.js +30 -15
  14. package/dist/cli-bundle/bundle-manifest.json +155 -155
  15. package/dist/cli-bundle/chunks/{chunk-TRWXF476.js → chunk-3PS7X6GS.js} +2 -2
  16. package/dist/cli-bundle/chunks/chunk-7KL6KMWF.js +13 -0
  17. package/dist/cli-bundle/chunks/{chunk-EBO7OUUE.js → chunk-BM5YJ2UW.js} +69 -55
  18. package/dist/cli-bundle/chunks/chunk-D55A5AEN.js +33 -0
  19. package/dist/cli-bundle/chunks/chunk-KIKDWECH.js +196 -0
  20. package/dist/cli-bundle/chunks/{chunk-ETML5C6H.js → chunk-KOQMGCTA.js} +47 -47
  21. package/dist/cli-bundle/chunks/chunk-R76342NV.js +2 -0
  22. package/dist/cli-bundle/chunks/chunk-RBTK5EZV.js +5 -0
  23. package/dist/cli-bundle/chunks/chunk-VLUQOIDT.js +2 -0
  24. package/dist/cli-bundle/chunks/chunk-WLAHPSOX.js +3 -0
  25. package/dist/cli-bundle/chunks/register-list-query-XPCJRUUD.js +10 -0
  26. package/dist/cli-bundle/chunks/register-mutation-4RJCBKRS.js +20 -0
  27. package/dist/cli-bundle/chunks/register-operations-2OGISOVR.js +2 -0
  28. package/dist/cli-bundle/chunks/{register-setup-S3KT2LTH.js → register-setup-LLHAKP2V.js} +2 -2
  29. package/dist/cli-bundle/focused-chunks/chunk-2DALMVF7.js +5 -0
  30. package/dist/cli-bundle/focused-chunks/chunk-5OQIMELN.js +155 -0
  31. package/dist/cli-bundle/focused-chunks/chunk-5TAGTDRE.js +2 -0
  32. package/dist/cli-bundle/focused-chunks/chunk-ECADZMVC.js +18 -0
  33. package/dist/cli-bundle/focused-chunks/chunk-EJGXRA6B.js +2 -0
  34. package/dist/cli-bundle/focused-chunks/chunk-FFGSZCPK.js +16 -0
  35. package/dist/cli-bundle/focused-chunks/{chunk-IW43E4XL.js → chunk-GQW4BPUT.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/chunk-ISKOBJCM.js +2 -0
  37. package/dist/cli-bundle/focused-chunks/{chunk-75774JWP.js → chunk-JAFRIWVF.js} +2 -2
  38. package/dist/cli-bundle/focused-chunks/{chunk-2COZ67XT.js → chunk-KHM2CS2C.js} +2 -2
  39. package/dist/cli-bundle/focused-chunks/{chunk-M6RPIXKC.js → chunk-KPSXVBDV.js} +2 -2
  40. package/dist/cli-bundle/focused-chunks/{chunk-34SX654S.js → chunk-KTLOKKCQ.js} +2 -2
  41. package/dist/cli-bundle/focused-chunks/chunk-LGYK3NUF.js +8 -0
  42. package/dist/cli-bundle/focused-chunks/{chunk-2EXI2DKR.js → chunk-NBLUKITQ.js} +2 -2
  43. package/dist/cli-bundle/focused-chunks/chunk-NYLOUPOB.js +2 -0
  44. package/dist/cli-bundle/focused-chunks/chunk-Q4T463SD.js +31 -0
  45. package/dist/cli-bundle/focused-chunks/chunk-QVZVY53N.js +2 -0
  46. package/dist/cli-bundle/focused-chunks/{chunk-DZGAHZZV.js → chunk-RWPAWUOT.js} +2 -2
  47. package/dist/cli-bundle/focused-chunks/chunk-UTEWXDEQ.js +17 -0
  48. package/dist/cli-bundle/focused-chunks/{chunk-7UN6BHHO.js → chunk-YIAXMC3T.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/chunk-ZMGWAYH7.js +2 -0
  50. package/dist/cli-bundle/main.js +13 -13
  51. package/dist/cli-bundle/sdk-authoring.js +1 -1
  52. package/dist/cli-bundle/sdk-contracts.js +1 -1
  53. package/dist/cli-bundle/sdk-core.js +41 -39
  54. package/dist/cli-bundle/sdk-governance.js +1 -1
  55. package/dist/cli-bundle/sdk-graph.js +1 -1
  56. package/dist/cli-bundle/sdk-merge.js +1 -1
  57. package/dist/cli-bundle/sdk-query.js +1 -1
  58. package/dist/cli-bundle/sdk-runtime.js +1 -1
  59. package/dist/cli-bundle/sdk-testing.js +1 -1
  60. package/dist/cli-bundle/sdk.js +2 -2
  61. package/dist/core/extensions/reserved-host-flags.js +3 -2
  62. package/dist/core/history/drift-scan.js +13 -8
  63. package/dist/core/history/history.d.ts +8 -0
  64. package/dist/core/history/history.js +57 -7
  65. package/dist/core/history/replay.d.ts +9 -1
  66. package/dist/core/history/replay.js +48 -13
  67. package/dist/core/output/output.d.ts +2 -0
  68. package/dist/core/output/output.js +46 -14
  69. package/dist/core/session/session-state.d.ts +47 -0
  70. package/dist/core/session/session-state.js +207 -6
  71. package/dist/core/shared/author.d.ts +7 -1
  72. package/dist/core/shared/author.js +66 -46
  73. package/dist/core/shared/command-types.d.ts +2 -0
  74. package/dist/core/shared/command-types.js +2 -2
  75. package/dist/core/shared/errors.d.ts +13 -0
  76. package/dist/core/shared/errors.js +2 -2
  77. package/dist/core/store/item-metadata-cache.d.ts +1 -1
  78. package/dist/core/store/item-metadata-cache.js +14 -7
  79. package/dist/sdk/agent/refusal-reachability.d.ts +40 -0
  80. package/dist/sdk/agent/refusal-reachability.js +72 -0
  81. package/dist/sdk/agent/subcommand-recovery.d.ts +40 -0
  82. package/dist/sdk/agent/subcommand-recovery.js +84 -0
  83. package/dist/sdk/cli-bootstrap.d.ts +10 -0
  84. package/dist/sdk/cli-bootstrap.js +11 -7
  85. package/dist/sdk/cli-contracts/completeness.js +14 -3
  86. package/dist/sdk/cli-contracts/enum-contracts.d.ts +1 -1
  87. package/dist/sdk/cli-contracts/enum-contracts.js +3 -2
  88. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  89. package/dist/sdk/cli-contracts/flag-contracts.js +20 -2
  90. package/dist/sdk/cli-contracts/registration-helpers.d.ts +20 -3
  91. package/dist/sdk/cli-contracts/registration-helpers.js +18 -12
  92. package/dist/sdk/cli-contracts/runtime-contracts.js +4 -3
  93. package/dist/sdk/cli-contracts/schemas/assurance-definition.d.ts +515 -0
  94. package/dist/sdk/cli-contracts/schemas/assurance-definition.js +252 -0
  95. package/dist/sdk/cli-contracts/tool-option-contracts.js +3 -2
  96. package/dist/sdk/cli-contracts/tool-parameter-tables.js +99 -2
  97. package/dist/sdk/cli-contracts/tool-schema.d.ts +3 -3
  98. package/dist/sdk/cli-contracts/tool-schema.js +38 -5
  99. package/dist/sdk/cli-contracts.d.ts +1 -1
  100. package/dist/sdk/cli-contracts.js +3 -3
  101. package/dist/sdk/cli-program.js +3 -2
  102. package/dist/sdk/completion.js +23 -8
  103. package/dist/sdk/config.js +9 -3
  104. package/dist/sdk/context/semantic-session-attribution.d.ts +32 -0
  105. package/dist/sdk/context/semantic-session-attribution.js +83 -0
  106. package/dist/sdk/context-intent-contracts.js +45 -4
  107. package/dist/sdk/core-governance.d.ts +3 -1
  108. package/dist/sdk/core-governance.js +5 -3
  109. package/dist/sdk/core.d.ts +2 -1
  110. package/dist/sdk/core.js +3 -2
  111. package/dist/sdk/error-code-catalog.d.ts +13 -0
  112. package/dist/sdk/error-code-catalog.js +35 -2
  113. package/dist/sdk/extension.js +18 -17
  114. package/dist/sdk/files.d.ts +11 -0
  115. package/dist/sdk/files.js +82 -24
  116. package/dist/sdk/generated/generated-error-code-catalog-part-1.d.ts +8 -0
  117. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1585 -0
  118. package/dist/sdk/generated/generated-error-code-catalog-part-2.d.ts +8 -0
  119. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +1608 -0
  120. package/dist/sdk/generated-error-code-catalog.js +6 -3121
  121. package/dist/sdk/governance/assurance-action-contracts.d.ts +7 -0
  122. package/dist/sdk/governance/assurance-action-contracts.js +5 -0
  123. package/dist/sdk/governance/assurance-action.d.ts +70 -0
  124. package/dist/sdk/governance/assurance-action.js +200 -0
  125. package/dist/sdk/governance/assurance-limits.d.ts +7 -0
  126. package/dist/sdk/governance/assurance-limits.js +11 -0
  127. package/dist/sdk/governance/assurance-mutation-error.d.ts +7 -0
  128. package/dist/sdk/governance/assurance-mutation-error.js +35 -0
  129. package/dist/sdk/governance/assurance-runtime.d.ts +20 -0
  130. package/dist/sdk/governance/assurance-runtime.js +134 -0
  131. package/dist/sdk/governance/assurance.d.ts +438 -0
  132. package/dist/sdk/governance/assurance.js +804 -0
  133. package/dist/sdk/governance/health.d.ts +3 -1
  134. package/dist/sdk/governance/health.js +21 -4
  135. package/dist/sdk/governance/validate-item-reader.js +3 -3
  136. package/dist/sdk/governance/validate.d.ts +2 -0
  137. package/dist/sdk/governance/validate.js +13 -3
  138. package/dist/sdk/graph/durable-cache.d.ts +1 -1
  139. package/dist/sdk/graph/durable-cache.js +98 -29
  140. package/dist/sdk/graph/governance.d.ts +14 -0
  141. package/dist/sdk/graph/governance.js +34 -9
  142. package/dist/sdk/graph/run.js +8 -3
  143. package/dist/sdk/index.d.ts +7 -2
  144. package/dist/sdk/index.js +9 -4
  145. package/dist/sdk/lifecycle/claim.js +26 -4
  146. package/dist/sdk/lifecycle/focus.js +13 -3
  147. package/dist/sdk/lifecycle/plan.js +8 -3
  148. package/dist/sdk/merge/driver.d.ts +2 -2
  149. package/dist/sdk/merge/driver.js +3 -3
  150. package/dist/sdk/merge/receipts.d.ts +6 -4
  151. package/dist/sdk/merge/receipts.js +7 -5
  152. package/dist/sdk/merge/three-way.d.ts +2 -2
  153. package/dist/sdk/merge/three-way.js +3 -3
  154. package/dist/sdk/output-projection.d.ts +9 -1
  155. package/dist/sdk/output-projection.js +45 -9
  156. package/dist/sdk/provenance.d.ts +38 -0
  157. package/dist/sdk/provenance.js +64 -2
  158. package/dist/sdk/query/activity.d.ts +49 -2
  159. package/dist/sdk/query/activity.js +183 -37
  160. package/dist/sdk/query/context.js +19 -8
  161. package/dist/sdk/query/get.js +19 -2
  162. package/dist/sdk/read-output-contracts.d.ts +5 -1
  163. package/dist/sdk/read-output-contracts.js +17 -2
  164. package/dist/sdk/read-output-session.d.ts +2 -0
  165. package/dist/sdk/read-output-session.js +12 -5
  166. package/dist/sdk/runtime-extended-actions.js +22 -5
  167. package/dist/sdk/runtime-primitives.d.ts +5 -3
  168. package/dist/sdk/runtime-primitives.js +7 -5
  169. package/dist/sdk/runtime-stats-options.js +3 -2
  170. package/dist/sdk/runtime.d.ts +4 -0
  171. package/dist/sdk/runtime.js +34 -34
  172. package/dist/sdk/stats.d.ts +36 -3
  173. package/dist/sdk/stats.js +55 -15
  174. package/dist/sdk/telemetry.js +7 -4
  175. package/dist/sdk/test/execution.d.ts +4 -0
  176. package/dist/sdk/test/execution.js +86 -21
  177. package/dist/sdk/traceability/runtime-files-lookup.d.ts +8 -0
  178. package/dist/sdk/traceability/runtime-files-lookup.js +33 -0
  179. package/dist/sdk/traceability/source-traceability.d.ts +102 -0
  180. package/dist/sdk/traceability/source-traceability.js +293 -0
  181. package/dist/types.d.ts +10 -2
  182. package/dist/types.js +2 -2
  183. package/docs/ASSURANCE.md +137 -0
  184. package/docs/COMMANDS.md +29 -8
  185. package/docs/CONFIGURATION.md +7 -0
  186. package/docs/DEPENDENCY_KIND_CONTRACT.md +10 -8
  187. package/docs/MERGE_SAFETY.md +3 -1
  188. package/docs/OUTPUT_PROJECTION_CONTRACTS.md +26 -13
  189. package/docs/README.md +3 -0
  190. package/docs/READ_OUTPUT_CONTRACTS.md +17 -2
  191. package/docs/RELEASING.md +9 -5
  192. package/docs/SDK.md +12 -1
  193. package/docs/SDK_AGENT_SESSION_CONTEXT.md +52 -5
  194. package/docs/SDK_CONTEXT_EVIDENCE_CONTRACTS.md +53 -0
  195. package/docs/SDK_CONTEXT_INTEGRITY.md +28 -1
  196. package/docs/SDK_EVIDENCE_TRACEABILITY.md +39 -1
  197. package/docs/SDK_RUNTIME_BOUNDARIES.md +36 -1
  198. package/docs/TESTING.md +12 -9
  199. package/docs/TRUSTWORTHY_CONTEXT_EVIDENCE.md +106 -0
  200. package/docs/generated/AGENT_COMMAND_SURFACE.md +1 -0
  201. package/docs/performance/sdk-entrypoint-import-costs.md +6 -2
  202. package/marketplace.json +2 -2
  203. package/package.json +7 -7
  204. package/packages/pm-beads/package.json +1 -1
  205. package/packages/pm-calendar/package.json +1 -1
  206. package/packages/pm-command-kit/package.json +1 -1
  207. package/packages/pm-digital-twin/package.json +1 -1
  208. package/packages/pm-governance-audit/package.json +1 -1
  209. package/packages/pm-guide-shell/package.json +1 -1
  210. package/packages/pm-kanban/package.json +1 -1
  211. package/packages/pm-lifecycle-hooks/package.json +1 -1
  212. package/packages/pm-linked-test-adapters/package.json +1 -1
  213. package/packages/pm-search-advanced/package.json +1 -1
  214. package/packages/pm-templates/extensions/templates/index.ts +9 -3
  215. package/packages/pm-templates/package.json +1 -1
  216. package/packages/pm-todos/package.json +1 -1
  217. package/packages/pm-vcs/package.json +1 -1
  218. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  219. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  220. package/sdk/public-surface.json +1030 -67
  221. package/dist/cli-bundle/chunks/chunk-2QYH4QMI.js +0 -30
  222. package/dist/cli-bundle/chunks/chunk-JUDU4RO4.js +0 -194
  223. package/dist/cli-bundle/chunks/chunk-JZSNADRR.js +0 -5
  224. package/dist/cli-bundle/chunks/chunk-MENWVGJW.js +0 -2
  225. package/dist/cli-bundle/chunks/chunk-S4EITGLA.js +0 -3
  226. package/dist/cli-bundle/chunks/chunk-TIGKWVLA.js +0 -13
  227. package/dist/cli-bundle/chunks/chunk-TSLDTJLQ.js +0 -2
  228. package/dist/cli-bundle/chunks/register-list-query-OJ6ZXKV4.js +0 -10
  229. package/dist/cli-bundle/chunks/register-mutation-DKI7QC7O.js +0 -20
  230. package/dist/cli-bundle/chunks/register-operations-P5OGMT6I.js +0 -2
  231. package/dist/cli-bundle/focused-chunks/chunk-36FTZ2NT.js +0 -2
  232. package/dist/cli-bundle/focused-chunks/chunk-3CQECMKR.js +0 -16
  233. package/dist/cli-bundle/focused-chunks/chunk-CHIBMEZR.js +0 -8
  234. package/dist/cli-bundle/focused-chunks/chunk-FF4MNAYB.js +0 -153
  235. package/dist/cli-bundle/focused-chunks/chunk-GHTN2ILR.js +0 -2
  236. package/dist/cli-bundle/focused-chunks/chunk-I4YM2I7S.js +0 -2
  237. package/dist/cli-bundle/focused-chunks/chunk-IMDTEN7K.js +0 -2
  238. package/dist/cli-bundle/focused-chunks/chunk-JMVA4HKR.js +0 -5
  239. package/dist/cli-bundle/focused-chunks/chunk-KR5RVXLQ.js +0 -31
  240. package/dist/cli-bundle/focused-chunks/chunk-KSNJG4KI.js +0 -16
  241. package/dist/cli-bundle/focused-chunks/chunk-MXYSIQ56.js +0 -18
  242. package/dist/cli-bundle/focused-chunks/chunk-RIIN5V4N.js +0 -2
  243. package/dist/cli-bundle/focused-chunks/chunk-RKWSCYYN.js +0 -2
@@ -4,7 +4,7 @@
4
4
  * Implements append-only history and replay behavior for History.
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]="ce2dace3-7c86-5edf-8bda-083a0b3e7f2b")}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]="2fc7f675-3500-5abb-8d5c-9ca9caa803b6")}catch(e){}}();
8
8
  import jsonPatch from "fast-json-patch";
9
9
  import { ITEM_METADATA_KEY_ORDER } from "../shared/constants.js";
10
10
  import { runActiveServiceOverride } from "../extensions/index.js";
@@ -20,6 +20,42 @@ const EMPTY_LEGACY_HASH_DOCUMENT = {
20
20
  front_matter: {},
21
21
  body: "",
22
22
  };
23
+ /** Hash epoch that preserves linked-test insertion order in immutable history. */
24
+ export const CURRENT_HISTORY_ITEM_HASH_VERSION = 2;
25
+ /** Hash epochs understood by this runtime. */
26
+ export const SUPPORTED_HISTORY_ITEM_HASH_VERSIONS = [1, 2];
27
+ function compareOptionalStrings(left, right) {
28
+ return (left ?? "").localeCompare(right ?? "");
29
+ }
30
+ function compareOptionalNumbers(left, right) {
31
+ return (left ?? 0) - (right ?? 0);
32
+ }
33
+ function compareJsonValues(left, right, fallback) {
34
+ // Preserve the original v1 comparator byte-for-byte: replacing JSON.stringify
35
+ // with stableStringify would invalidate immutable hashes from legacy streams.
36
+ return JSON.stringify(left ?? fallback).localeCompare(JSON.stringify(right ?? fallback));
37
+ }
38
+ function compareLegacyLinkedTests(left, right) {
39
+ const comparisons = [
40
+ left.scope.localeCompare(right.scope),
41
+ compareOptionalStrings(left.path, right.path),
42
+ compareOptionalStrings(left.command, right.command),
43
+ compareOptionalNumbers(left.timeout_seconds, right.timeout_seconds),
44
+ compareOptionalStrings(left.pm_context_mode, right.pm_context_mode),
45
+ Number(Boolean(left.shared_host_safe)) - Number(Boolean(right.shared_host_safe)),
46
+ compareJsonValues(left.env_clear, right.env_clear, []),
47
+ compareJsonValues(left.env_set, right.env_set, {}),
48
+ compareJsonValues(left.assert_stdout_contains, right.assert_stdout_contains, []),
49
+ compareJsonValues(left.assert_stdout_regex, right.assert_stdout_regex, []),
50
+ compareJsonValues(left.assert_stderr_contains, right.assert_stderr_contains, []),
51
+ compareJsonValues(left.assert_stderr_regex, right.assert_stderr_regex, []),
52
+ compareOptionalNumbers(left.assert_stdout_min_lines, right.assert_stdout_min_lines),
53
+ compareJsonValues(left.assert_json_field_equals, right.assert_json_field_equals, {}),
54
+ compareJsonValues(left.assert_json_field_gte, right.assert_json_field_gte, {}),
55
+ compareOptionalStrings(left.note, right.note),
56
+ ];
57
+ return comparisons.find((comparison) => comparison !== 0) ?? 0;
58
+ }
23
59
  function decodeJsonPointer(path) {
24
60
  if (!path || path === "/") {
25
61
  return [];
@@ -81,7 +117,7 @@ function normalizeHistoryPatchOps(beforeDocument, patch) {
81
117
  }
82
118
  return normalized;
83
119
  }
84
- function canonicalHashDocument(document) {
120
+ function canonicalHashDocument(document, version) {
85
121
  const hasMetadata = document.metadata && Object.keys(document.metadata).length > 0;
86
122
  if (!hasMetadata) {
87
123
  return {
@@ -90,7 +126,13 @@ function canonicalHashDocument(document) {
90
126
  };
91
127
  }
92
128
  const canonical = canonicalDocument(document);
93
- const orderedMetadata = orderObject(toItemRecord(canonical.metadata), ITEM_METADATA_KEY_ORDER);
129
+ const metadata = version === 1 && canonical.metadata.tests
130
+ ? {
131
+ ...canonical.metadata,
132
+ tests: [...canonical.metadata.tests].sort(compareLegacyLinkedTests),
133
+ }
134
+ : canonical.metadata;
135
+ const orderedMetadata = orderObject(toItemRecord(metadata), ITEM_METADATA_KEY_ORDER);
94
136
  return {
95
137
  front_matter: orderedMetadata,
96
138
  body: canonical.body,
@@ -113,7 +155,14 @@ function canonicalPatchDocument(document) {
113
155
  }
114
156
  /** Implements hash document for the public runtime surface of this module. */
115
157
  export function hashDocument(document) {
116
- return sha256Hex(stableStringify(canonicalHashDocument(document)));
158
+ return hashDocumentForVersion(document, CURRENT_HISTORY_ITEM_HASH_VERSION);
159
+ }
160
+ /** Hash an item with an explicit canonicalization epoch for replay compatibility. */
161
+ export function hashDocumentForVersion(document, version) {
162
+ if (!SUPPORTED_HISTORY_ITEM_HASH_VERSIONS.some((supportedVersion) => supportedVersion === version)) {
163
+ throw new TypeError(`unsupported_item_hash_version:${String(version)}`);
164
+ }
165
+ return sha256Hex(stableStringify(canonicalHashDocument(document, version)));
117
166
  }
118
167
  /** Implements hash empty document for the public runtime surface of this module. */
119
168
  export function hashEmptyDocument() {
@@ -121,8 +170,8 @@ export function hashEmptyDocument() {
121
170
  }
122
171
  /** Implements create history entry for the public runtime surface of this module. */
123
172
  export function createHistoryEntry(params) {
124
- const beforeHashCanonical = canonicalHashDocument(params.before);
125
- const afterHashCanonical = canonicalHashDocument(params.after);
173
+ const beforeHashCanonical = canonicalHashDocument(params.before, CURRENT_HISTORY_ITEM_HASH_VERSION);
174
+ const afterHashCanonical = canonicalHashDocument(params.after, CURRENT_HISTORY_ITEM_HASH_VERSION);
126
175
  const beforePatchCanonical = canonicalPatchDocument(params.before);
127
176
  const afterPatchCanonical = canonicalPatchDocument(params.after);
128
177
  const rawPatch = jsonPatch.compare(beforePatchCanonical, afterPatchCanonical);
@@ -159,6 +208,7 @@ export function createHistoryEntry(params) {
159
208
  patch,
160
209
  before_hash: sha256Hex(stableStringify(beforeHashCanonical)),
161
210
  after_hash: sha256Hex(stableStringify(afterHashCanonical)),
211
+ item_hash_version: CURRENT_HISTORY_ITEM_HASH_VERSION,
162
212
  message: params.message === undefined ? undefined : params.message,
163
213
  ...(context === undefined ? {} : { context }),
164
214
  };
@@ -242,4 +292,4 @@ export const _testOnly = {
242
292
  isDefinedPointerPath,
243
293
  };
244
294
  //# sourceMappingURL=history.js.map
245
- //# debugId=ce2dace3-7c86-5edf-8bda-083a0b3e7f2b
295
+ //# debugId=2fc7f675-3500-5abb-8d5c-9ca9caa803b6
@@ -1,4 +1,5 @@
1
1
  import { canonicalDocument } from "../item/item-format.js";
2
+ import { type HistoryItemHashVersion } from "./history.js";
2
3
  import type { HistoryEntry, HistoryPatchOp, ItemDocument } from "../../types/index.js";
3
4
  /**
4
5
  * Shared history replay/patch mechanics single-sourced for the history, restore,
@@ -19,7 +20,7 @@ export declare const EMPTY_REPLAY_DOCUMENT: ReplayDocument;
19
20
  /** Implements clone empty replay document for the public runtime surface of this module. */
20
21
  export declare function cloneEmptyReplayDocument(): ReplayDocument;
21
22
  /** Implements replay hash for the public runtime surface of this module. */
22
- export declare function replayHash(document: ReplayDocument): string;
23
+ export declare function replayHash(document: ReplayDocument, version?: HistoryItemHashVersion): string;
23
24
  /** Implements replay to item document for the public runtime surface of this module. */
24
25
  export declare function replayToItemDocument(document: ReplayDocument): ItemDocument;
25
26
  /** Converts a materialized replay document into a canonical item document. Use this when callers have already rejected the empty/deleted replay state and need restored metadata validated through the normal item-metadata rules. */
@@ -41,6 +42,13 @@ export type ReplayApplyResult = {
41
42
  /** Strictly apply a history patch (front_matter->metadata normalized) to a replay document. Returns a result envelope rather than throwing so each caller can format its own error contract. */
42
43
  export declare function tryApplyReplayPatch(current: ReplayDocument, patch: HistoryPatchOp[]): ReplayApplyResult;
43
44
  /** Deterministically verify a history chain: each entry's before_hash must equal the prior replayed after_hash, the patch must strictly apply, and the recorded after_hash must equal the replayed result. */
45
+ /** Verify a chain and report the explicit or auto-detected item hash epoch. */
46
+ export declare function verifyHistoryChainWithVersion(entries: HistoryEntry[]): {
47
+ ok: boolean;
48
+ errors: string[];
49
+ item_hash_version?: HistoryItemHashVersion;
50
+ };
51
+ /** Deterministically verify a history chain while preserving the legacy result shape. */
44
52
  export declare function verifyHistoryChain(entries: HistoryEntry[]): {
45
53
  ok: boolean;
46
54
  errors: string[];
@@ -4,13 +4,13 @@
4
4
  * Implements append-only history and replay behavior for Replay.
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]="c8668470-7e57-5dee-8e41-298e7c697b77")}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]="a1283470-00c7-5e91-8676-e1c1a667537f")}catch(e){}}();
8
8
  import jsonPatch from "fast-json-patch";
9
9
  import { ITEM_METADATA_KEY_ORDER } from "../shared/constants.js";
10
10
  import { canonicalDocument } from "../item/item-format.js";
11
11
  import { toItemRecord } from "../item/item-record.js";
12
12
  import { orderObject, sha256Hex, stableStringify, } from "../shared/serialization.js";
13
- import { hashDocument } from "./history.js";
13
+ import { CURRENT_HISTORY_ITEM_HASH_VERSION, SUPPORTED_HISTORY_ITEM_HASH_VERSIONS, hashDocumentForVersion, } from "./history.js";
14
14
  /** Public contract for empty replay document, shared by SDK and presentation-layer consumers. */
15
15
  export const EMPTY_REPLAY_DOCUMENT = {
16
16
  metadata: {},
@@ -21,11 +21,11 @@ export function cloneEmptyReplayDocument() {
21
21
  return structuredClone(EMPTY_REPLAY_DOCUMENT);
22
22
  }
23
23
  /** Implements replay hash for the public runtime surface of this module. */
24
- export function replayHash(document) {
24
+ export function replayHash(document, version = CURRENT_HISTORY_ITEM_HASH_VERSION) {
25
25
  if (Object.keys(document.metadata).length === 0 ||
26
26
  Array.isArray(document.metadata.tags)) {
27
27
  try {
28
- return hashDocument(replayToItemDocument(document));
28
+ return hashDocumentForVersion(replayToItemDocument(document), version);
29
29
  }
30
30
  catch {
31
31
  // Fall through when another malformed legacy field cannot be canonicalized.
@@ -124,14 +124,20 @@ export function tryApplyReplayPatch(current, patch) {
124
124
  }
125
125
  }
126
126
  /** Deterministically verify a history chain: each entry's before_hash must equal the prior replayed after_hash, the patch must strictly apply, and the recorded after_hash must equal the replayed result. */
127
- export function verifyHistoryChain(entries) {
127
+ /** Verify a chain and report the explicit or auto-detected item hash epoch. */
128
+ export function verifyHistoryChainWithVersion(entries) {
128
129
  let replay = cloneEmptyReplayDocument();
130
+ let detectedVersion;
129
131
  for (let index = 0; index < entries.length; index += 1) {
130
132
  const entry = entries[index];
131
- if (replayHash(replay) !== entry.before_hash) {
133
+ const explicitVersion = entry.item_hash_version;
134
+ if (explicitVersion !== undefined &&
135
+ !SUPPORTED_HISTORY_ITEM_HASH_VERSIONS.includes(explicitVersion)) {
132
136
  return {
133
137
  ok: false,
134
- errors: [`verify_failed:before_hash_mismatch:entry_${index + 1}`],
138
+ errors: [
139
+ `verify_failed:unsupported_item_hash_version:${String(explicitVersion)}:entry_${index + 1}`,
140
+ ],
135
141
  };
136
142
  }
137
143
  const applied = tryApplyReplayPatch(replay, entry.patch);
@@ -141,15 +147,38 @@ export function verifyHistoryChain(entries) {
141
147
  errors: [`verify_failed:patch_apply_failed:entry_${index + 1}`],
142
148
  };
143
149
  }
144
- replay = applied.document;
145
- if (replayHash(replay) !== entry.after_hash) {
150
+ const candidates = explicitVersion === undefined
151
+ ? [CURRENT_HISTORY_ITEM_HASH_VERSION, 1]
152
+ : [explicitVersion];
153
+ const beforeMatches = candidates.filter((version) => replayHash(replay, version) === entry.before_hash);
154
+ if (beforeMatches.length === 0) {
155
+ return {
156
+ ok: false,
157
+ errors: [`verify_failed:before_hash_mismatch:entry_${index + 1}`],
158
+ };
159
+ }
160
+ const version = beforeMatches.find((candidate) => replayHash(applied.document, candidate) === entry.after_hash);
161
+ if (version === undefined) {
146
162
  return {
147
163
  ok: false,
148
164
  errors: [`verify_failed:after_hash_mismatch:entry_${index + 1}`],
149
165
  };
150
166
  }
167
+ replay = applied.document;
168
+ detectedVersion = version;
151
169
  }
152
- return { ok: true, errors: [] };
170
+ return {
171
+ ok: true,
172
+ errors: [],
173
+ ...(detectedVersion === undefined
174
+ ? {}
175
+ : { item_hash_version: detectedVersion }),
176
+ };
177
+ }
178
+ /** Deterministically verify a history chain while preserving the legacy result shape. */
179
+ export function verifyHistoryChain(entries) {
180
+ const result = verifyHistoryChainWithVersion(entries);
181
+ return { ok: result.ok, errors: result.errors };
153
182
  }
154
183
  function tryApplySingleOp(document, op) {
155
184
  try {
@@ -192,6 +221,11 @@ export function lenientApplyReplayPatch(current, patch) {
192
221
  }
193
222
  /** Re-anchor a drifted history chain: replay every entry from empty, recompute the before/after hashes, and only rewrite a patch when the original op set no longer strictly applies (legacy drift). Clean entries keep their patch verbatim so the on-disk diff stays minimal. The returned chain verifies via verifyHistoryChain. */
194
223
  export function reanchorHistoryEntries(entries) {
224
+ const unsupportedIndex = entries.findIndex((entry) => entry.item_hash_version !== undefined &&
225
+ !SUPPORTED_HISTORY_ITEM_HASH_VERSIONS.includes(entry.item_hash_version));
226
+ if (unsupportedIndex >= 0) {
227
+ throw new TypeError(`unsupported_item_hash_version:${String(entries[unsupportedIndex]?.item_hash_version)}:entry_${unsupportedIndex + 1}`);
228
+ }
195
229
  let replay = cloneEmptyReplayDocument();
196
230
  const rewritten = [];
197
231
  const details = [];
@@ -201,7 +235,7 @@ export function reanchorHistoryEntries(entries) {
201
235
  let skippedOps = 0;
202
236
  for (let index = 0; index < entries.length; index += 1) {
203
237
  const entry = entries[index];
204
- const beforeHash = replayHash(replay);
238
+ const beforeHash = replayHash(replay, CURRENT_HISTORY_ITEM_HASH_VERSION);
205
239
  const strict = tryApplyReplayPatch(replay, entry.patch);
206
240
  let next;
207
241
  let outPatch;
@@ -223,7 +257,7 @@ export function reanchorHistoryEntries(entries) {
223
257
  skippedOps += entrySkipped;
224
258
  entriesPatchRepaired += 1;
225
259
  }
226
- const afterHash = replayHash(next);
260
+ const afterHash = replayHash(next, CURRENT_HISTORY_ITEM_HASH_VERSION);
227
261
  const rehashed = beforeHash !== entry.before_hash || afterHash !== entry.after_hash;
228
262
  if (rehashed) {
229
263
  entriesRehashed += 1;
@@ -233,6 +267,7 @@ export function reanchorHistoryEntries(entries) {
233
267
  patch: outPatch,
234
268
  before_hash: beforeHash,
235
269
  after_hash: afterHash,
270
+ item_hash_version: CURRENT_HISTORY_ITEM_HASH_VERSION,
236
271
  });
237
272
  details.push({
238
273
  index: index + 1,
@@ -261,4 +296,4 @@ export function historyEntriesToRaw(entries) {
261
296
  return `${entries.map((entry) => JSON.stringify(entry)).join("\n")}\n`;
262
297
  }
263
298
  //# sourceMappingURL=replay.js.map
264
- //# debugId=c8668470-7e57-5dee-8e41-298e7c697b77
299
+ //# debugId=a1283470-00c7-5e91-8676-e1c1a667537f
@@ -24,6 +24,8 @@ export interface OutputOptions {
24
24
  outputFormat?: "toon" | "json";
25
25
  /** Caller-carried cross-call budget and served-item state. */
26
26
  outputSession?: string;
27
+ /** Include machine-readable row location and row-encoding metadata. */
28
+ outputRowContract?: boolean;
27
29
  /** Fallback output format used when callers do not provide an override. */
28
30
  defaultOutputFormat?: "toon" | "json";
29
31
  /** Value that configures or reports command for this contract. */
@@ -4,7 +4,7 @@
4
4
  * Formats compact human and machine output for Output.
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]="b52d2756-f640-5f53-981f-05fa23fa1718")}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]="5aaf8b90-5b95-5102-9ea4-b877c696d593")}catch(e){}}();
8
8
  import { getActiveCommandContext, runActiveCommandOverride, runActiveRendererOverride, runActiveServiceOverrideSync, setActiveCommandResult, } from "../extensions/index.js";
9
9
  import { EXIT_CODE } from "../shared/constants.js";
10
10
  import { isHostOutputSuppressed } from "./output-control.js";
@@ -12,6 +12,7 @@ import { projectMutationResult } from "./mutation-projection.js";
12
12
  import { attachReadOutputContracts } from "../../sdk/context-intent-contracts.js";
13
13
  import { attachOutputTokenAccounting } from "../../sdk/output-token-accounting.js";
14
14
  import { resolveReadOutputEncoding } from "../../sdk/read-output-contracts.js";
15
+ import { encode as encodeToon } from "@toon-format/toon";
15
16
  const DECLARED_PROCESS_EXIT_CODES = new Set(Object.values(EXIT_CODE));
16
17
  const NATIVE_OUTPUT_MARKER = "__pm_native_output";
17
18
  let streamErrorHandlersInstalled = false;
@@ -114,6 +115,44 @@ function renderScalar(value) {
114
115
  return "null";
115
116
  return JSON.stringify(value);
116
117
  }
118
+ function isToonPrimitive(value) {
119
+ return (value === null ||
120
+ typeof value === "string" ||
121
+ typeof value === "number" ||
122
+ typeof value === "boolean");
123
+ }
124
+ function tabularObjectArray(value) {
125
+ if (value.length === 0 || !value.every(isPlainObject))
126
+ return false;
127
+ const keys = Object.keys(value[0]);
128
+ return (keys.length > 0 &&
129
+ value.every((entry) => Object.keys(entry).length === keys.length &&
130
+ keys.every((key) => Object.hasOwn(entry, key) && isToonPrimitive(entry[key]))));
131
+ }
132
+ function indentToon(encoded, depth) {
133
+ const indent = " ".repeat(depth);
134
+ return encoded
135
+ .split("\n")
136
+ .map((line) => `${indent}${line}`)
137
+ .join("\n");
138
+ }
139
+ /** Render one object field while preserving nested and tabular TOON structure. */
140
+ function renderToonObjectEntry(key, entry, depth) {
141
+ const indent = " ".repeat(depth);
142
+ if (!isPlainObject(entry) && !Array.isArray(entry)) {
143
+ return `${indent}${key}: ${renderScalar(entry)}`;
144
+ }
145
+ if (Array.isArray(entry) && entry.length === 0) {
146
+ return `${indent}${key}: []`;
147
+ }
148
+ if (Array.isArray(entry) && tabularObjectArray(entry)) {
149
+ return indentToon(encodeToon({ [key]: entry }), depth);
150
+ }
151
+ if (isPlainObject(entry) && Object.keys(entry).length === 0) {
152
+ return `${indent}${key}: {}`;
153
+ }
154
+ return `${indent}${key}:\n${renderToonValue(entry, depth + 1)}`;
155
+ }
117
156
  function compactToonValue(value) {
118
157
  if (value === null || value === undefined) {
119
158
  return undefined;
@@ -147,6 +186,9 @@ function renderToonValue(value, depth) {
147
186
  if (Array.isArray(value)) {
148
187
  if (value.length === 0)
149
188
  return "[]";
189
+ if (tabularObjectArray(value)) {
190
+ return indentToon(encodeToon(value), depth);
191
+ }
150
192
  return value
151
193
  .map((entry) => {
152
194
  if (!isPlainObject(entry) && !Array.isArray(entry)) {
@@ -167,18 +209,7 @@ function renderToonValue(value, depth) {
167
209
  if (entries.length === 0)
168
210
  return "{}";
169
211
  return entries
170
- .map(([key, entry]) => {
171
- if (!isPlainObject(entry) && !Array.isArray(entry)) {
172
- return `${indent}${key}: ${renderScalar(entry)}`;
173
- }
174
- if (Array.isArray(entry) && entry.length === 0) {
175
- return `${indent}${key}: []`;
176
- }
177
- if (isPlainObject(entry) && Object.keys(entry).length === 0) {
178
- return `${indent}${key}: {}`;
179
- }
180
- return `${indent}${key}:\n${renderToonValue(entry, depth + 1)}`;
181
- })
212
+ .map(([key, entry]) => renderToonObjectEntry(key, entry, depth))
182
213
  .join("\n");
183
214
  }
184
215
  return `${indent}${renderScalar(value)}`;
@@ -335,6 +366,7 @@ function formatEffectiveOutput(effectiveResult, nativeOutput, options) {
335
366
  ["outputBudget", options.outputBudget],
336
367
  ["outputFormat", options.outputFormat],
337
368
  ["outputSession", options.outputSession],
369
+ ["outputRowContract", options.outputRowContract],
338
370
  ].filter((entry) => entry[1] !== undefined)),
339
371
  };
340
372
  const format = resolveReadOutputEncoding(command ?? "", commandOptions) ??
@@ -424,4 +456,4 @@ export const outputTestOnly = {
424
456
  renderToonValue,
425
457
  };
426
458
  //# sourceMappingURL=output.js.map
427
- //# debugId=b52d2756-f640-5f53-981f-05fa23fa1718
459
+ //# debugId=5aaf8b90-5b95-5102-9ea4-b877c696d593
@@ -9,11 +9,58 @@
9
9
  export interface SessionState {
10
10
  /** Value that configures or reports focused item for this contract. */
11
11
  focused_item?: string;
12
+ /** Privacy-safe semantic work context partitioned by agent invocation. */
13
+ semantic_attribution?: Record<string, AgentSemanticAttribution>;
14
+ }
15
+ /** Bounded inferred work context consumed by mutation provenance. */
16
+ export interface AgentSemanticAttribution {
17
+ /** Controlled role inferred from the current work lifecycle. */
18
+ role: "implementer" | "planner" | "release-operator";
19
+ /** Stable item or workset identity, never prompt text. */
20
+ topic: string;
21
+ /** Confidence attached to the inferred observation. */
22
+ confidence: "high" | "medium";
23
+ /** Versioned inference rule understood by history consumers. */
24
+ rule_version: "v2";
25
+ /** Bounded item and lineage references supporting the inference. */
26
+ evidence: string[];
27
+ /** Claimed items currently contributing to the workset. */
28
+ active_item_ids: string[];
29
+ /** Explicitly focused item when focus takes precedence over claims. */
30
+ focused_item_id?: string;
12
31
  }
13
32
  /** Implements get session state path for the public runtime surface of this module. */
14
33
  export declare function getSessionStatePath(pmRoot: string): string;
15
34
  /** Implements read session state for the public runtime surface of this module. */
16
35
  export declare function readSessionState(pmRoot: string): Promise<SessionState>;
36
+ /** Derive a non-secret state key from a claim principal. */
37
+ export declare function semanticAttributionKey(principal: string): string;
38
+ /** Record a successful claim as incremental semantic session evidence. */
39
+ export declare function recordClaimedWorkAttribution(params: {
40
+ pmRoot: string;
41
+ principal: string;
42
+ itemId: string;
43
+ lineageIds?: readonly string[];
44
+ }): Promise<void>;
45
+ /** Remove a released item from incremental semantic session evidence. */
46
+ export declare function releaseClaimedWorkAttribution(params: {
47
+ pmRoot: string;
48
+ principal: string;
49
+ itemId: string;
50
+ }): Promise<void>;
51
+ /** Set or clear focus as the highest-confidence semantic topic. */
52
+ export declare function recordFocusedWorkAttribution(params: {
53
+ pmRoot: string;
54
+ principal: string;
55
+ itemId?: string;
56
+ lineageIds?: readonly string[];
57
+ }): Promise<void>;
58
+ /** Read one privacy-bounded inferred attribution without making mutations fail. */
59
+ export declare function readAgentSemanticAttributionSync(params: {
60
+ cwd: string;
61
+ env: Readonly<Record<string, string | undefined>>;
62
+ key: string | undefined;
63
+ }): AgentSemanticAttribution | undefined;
17
64
  /** Implements get focused item for the public runtime surface of this module. */
18
65
  export declare function getFocusedItem(pmRoot: string): Promise<string | undefined>;
19
66
  /** Implements set focused item for the public runtime surface of this module. */